VirtualBox

Ignore:
Timestamp:
Apr 12, 2017 7:38:03 AM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114524
Message:

DevVGA-SVGA3d: bugref:8735: added a couple of checks and simplified the loop for buffer allocation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.cpp

    r65381 r66519  
    7070    AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
    7171    AssertReturn(cMipLevels >= 1, VERR_INVALID_PARAMETER);
    72     /* Assuming all faces have the same nr of mipmaps. */
    73     AssertReturn(!(surfaceFlags & SVGA3D_SURFACE_CUBEMAP) || cMipLevels == face[0].numMipLevels * 6, VERR_INVALID_PARAMETER);
    74     AssertReturn((surfaceFlags & SVGA3D_SURFACE_CUBEMAP) || cMipLevels == face[0].numMipLevels, VERR_INVALID_PARAMETER);
     72
     73    /* Number of faces (cFaces) is specified as the number of the first non-zero elements in the 'face' array.
     74     * Since only plain surfaces (cFaces == 1) and cubemaps (cFaces == 6) are supported
     75     * (see also SVGA3dCmdDefineSurface definition in svga3d_reg.h), we ignore anything else.
     76     */
     77    uint32_t cFaces = 0;
     78    for (uint32_t i = 0; i < SVGA3D_MAX_SURFACE_FACES; ++i)
     79    {
     80        if (face[i].numMipLevels == 0)
     81            break;
     82
     83        /* All SVGA3dSurfaceFace structures must have the same value of numMipLevels field */
     84        AssertReturn(face[i].numMipLevels == face[0].numMipLevels, VERR_INVALID_PARAMETER);
     85        ++cFaces;
     86    }
     87    for (uint32_t i = cFaces; i < SVGA3D_MAX_SURFACE_FACES; ++i)
     88        AssertReturn(face[i].numMipLevels == 0, VERR_INVALID_PARAMETER);
     89
     90    /* cFaces must be 6 for a cubemap and 1 otherwise. */
     91    AssertReturn(cFaces == (uint32_t)((surfaceFlags & SVGA3D_SURFACE_CUBEMAP) ? 6 : 1), VERR_INVALID_PARAMETER);
     92    AssertReturn(cMipLevels == cFaces * face[0].numMipLevels, VERR_INVALID_PARAMETER);
    7593
    7694    if (sid >= pState->cSurfaces)
     
    189207    pSurface->format            = format;
    190208    memcpy(pSurface->faces, face, sizeof(pSurface->faces));
    191     pSurface->cFaces            = 1;        /* check for cube maps later */
     209    pSurface->cFaces            = cFaces;
    192210    pSurface->multiSampleCount  = multisampleCount;
    193211    pSurface->autogenFilter     = autogenFilter;
     
    226244    case SVGA3D_SURFACE_CUBEMAP:
    227245        Log(("SVGA3D_SURFACE_CUBEMAP\n"));
    228         pSurface->cFaces = 6;
    229246        break;
    230247
     
    259276
    260277    /* Allocate buffer to hold the surface data until we can move it into a D3D object */
    261     for (uint32_t iFace=0; iFace < pSurface->cFaces; iFace++)
    262     {
    263         for (uint32_t i=0; i < pSurface->faces[iFace].numMipLevels; i++)
    264         {
    265             uint32_t idx = i + iFace * pSurface->faces[0].numMipLevels;
    266 
    267             Log(("vmsvga3dSurfaceDefine: face %d mip level %d (%d,%d,%d)\n", iFace, i, pSurface->pMipmapLevels[idx].size.width, pSurface->pMipmapLevels[idx].size.height, pSurface->pMipmapLevels[idx].size.depth));
    268             Log(("vmsvga3dSurfaceDefine: cbPitch=%x cbBlock=%x \n", pSurface->cbBlock * pSurface->pMipmapLevels[idx].size.width, pSurface->cbBlock));
    269 
    270             pSurface->pMipmapLevels[idx].cbSurfacePitch = pSurface->cbBlock * pSurface->pMipmapLevels[idx].size.width;
    271             pSurface->pMipmapLevels[idx].cbSurface      = pSurface->pMipmapLevels[idx].cbSurfacePitch * pSurface->pMipmapLevels[idx].size.height * pSurface->pMipmapLevels[idx].size.depth;
    272             pSurface->pMipmapLevels[idx].pSurfaceData   = RTMemAllocZ(pSurface->pMipmapLevels[idx].cbSurface);
    273             AssertReturn(pSurface->pMipmapLevels[idx].pSurfaceData, VERR_NO_MEMORY);
    274         }
     278    for (uint32_t i = 0; i < cMipLevels; ++i)
     279    {
     280        PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->pMipmapLevels[i];
     281        LogFunc(("[%d] face %d mip level %d (%d,%d,%d)\n", i, i / pSurface->faces[0].numMipLevels, i % pSurface->faces[0].numMipLevels, pMipmapLevel->size.width, pMipmapLevel->size.height, pMipmapLevel->size.depth));
     282        LogFunc(("cbPitch=0x%x cbBlock=0x%x\n", pSurface->cbBlock * pMipmapLevel->size.width, pSurface->cbBlock));
     283
     284        pMipmapLevel->cbSurfacePitch = pSurface->cbBlock * pMipmapLevel->size.width;
     285        pMipmapLevel->cbSurface      = pMipmapLevel->cbSurfacePitch * pMipmapLevel->size.height * pMipmapLevel->size.depth;
     286        pMipmapLevel->pSurfaceData   = RTMemAllocZ(pMipmapLevel->cbSurface);
     287        AssertReturn(pMipmapLevel->pSurfaceData, VERR_NO_MEMORY);
    275288    }
    276289    return VINF_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette