VirtualBox

Changeset 102714 in vbox


Ignore:
Timestamp:
Dec 27, 2023 3:34:25 PM (11 months ago)
Author:
vboxsync
Message:

Devices/Graphics: simplified vertex and index buffers tracking.

Location:
trunk/src/VBox/Devices/Graphics
Files:
3 edited

Legend:

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

    r102626 r102714  
    320320typedef struct DXBOUNDRESOURCES /* Currently bound resources. Mirror SVGADXContextMobFormat structure. */
    321321{
    322     struct
    323     {
    324         DXBOUNDVERTEXBUFFER vertexBuffers[SVGA3D_DX_MAX_VERTEXBUFFERS];
    325         DXBOUNDINDEXBUFFER indexBuffer;
    326     } inputAssembly;
    327322    struct
    328323    {
     
    393388    UINT                       VendorId;
    394389    UINT                       DeviceId;
     390
     391    SVGADXContextMobFormat     svgaDXContext;          /* Current state of pipeline. */
    395392
    396393    DXBOUNDRESOURCES           resources;              /* What is currently applied to the pipeline. */
     
    32813278            bd.Usage = D3D11_USAGE_DYNAMIC;
    32823279        else if (pSurface->f.surfaceFlags & SVGA3D_SURFACE_HINT_STATIC)
    3283             bd.Usage = pInitialData ? D3D11_USAGE_IMMUTABLE : D3D11_USAGE_DEFAULT; /* Guest will update later. */
     3280        {
     3281            /* Use D3D11_USAGE_DEFAULT instead of D3D11_USAGE_IMMUTABLE to let the guest the guest update
     3282             * the buffer later.
     3283             *
     3284             * The guest issues SVGA_3D_CMD_INVALIDATE_GB_IMAGE followed by SVGA_3D_CMD_UPDATE_GB_IMAGE
     3285             * when the data in SVGA3D_SURFACE_HINT_STATIC surface is updated.
     3286             * D3D11_USAGE_IMMUTABLE would work if the device destroys the D3D buffer on INVALIDATE
     3287             * and re-creates it in setupPipeline with initial data from the backing guest MOB.
     3288             * Currently the device does not destroy the buffer on INVALIDATE. So just use D3D11_USAGE_DEFAULT.
     3289             */
     3290            bd.Usage = D3D11_USAGE_DEFAULT;
     3291        }
    32843292        else if (pSurface->f.surfaceFlags & SVGA3D_SURFACE_HINT_INDIRECT_UPDATE)
    32853293            bd.Usage = D3D11_USAGE_DEFAULT;
     
    33833391
    33843392        AssertRCReturn(rc, rc);
     3393        LogFunc(("Created for sid = %u\n", sid));
    33853394    }
    33863395
     
    34743483    LogRelMax(1, ("VMSVGA: Single DX device mode: %s\n", pBackend->fSingleDevice ? "enabled" : "disabled"));
    34753484
     3485    vmsvga3dDXInitContextMobData(&pBackend->svgaDXContext); /** @todo */
    34763486//DEBUG_BREAKPOINT_TEST();
    34773487    return rc;
     
    56165626        }
    56175627
    5618         for (uint32_t i = 0; i < RT_ELEMENTS(pBackendDXContext->resources.inputAssembly.vertexBuffers); ++i)
    5619         {
    5620             D3D_RELEASE(pBackendDXContext->resources.inputAssembly.vertexBuffers[i].pBuffer);
    5621         }
    5622 
    5623         D3D_RELEASE(pBackendDXContext->resources.inputAssembly.indexBuffer.pBuffer);
    5624 
    56255628        if (pBackendDXContext->dxDevice.pImmediateContext)
    56265629            dxDeviceFlush(&pBackendDXContext->dxDevice); /* Make sure that any pending draw calls are finished. */
     
    62546257static void dxSetVertexBuffers(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext)
    62556258{
    6256 //DEBUG_BREAKPOINT_TEST();
    62576259    PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    6258     DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    6259     VMSVGA3DBACKENDDXCONTEXT *pBackendDXContext = pDXContext->pBackendDXContext;
    6260 
    6261     AssertCompile(RT_ELEMENTS(pBackendDXContext->resources.inputAssembly.vertexBuffers) == SVGA3D_DX_MAX_VERTEXBUFFERS);
    62626260
    62636261    ID3D11Buffer *paResources[SVGA3D_DX_MAX_VERTEXBUFFERS];
     
    62656263    UINT paOffset[SVGA3D_DX_MAX_VERTEXBUFFERS];
    62666264
     6265    int32_t idxMinSlot = SVGA3D_DX_MAX_VERTEXBUFFERS;
    62676266    int32_t idxMaxSlot = -1;
    6268     for (uint32_t i = 0; i < SVGA3D_DX_MAX_VERTEXBUFFERS; ++i)
    6269     {
    6270         DXBOUNDVERTEXBUFFER *pBufferContext = &pBackendDXContext->resources.inputAssembly.vertexBuffers[i];
    6271         DXBOUNDVERTEXBUFFER *pBufferPipeline = &pBackend->resources.inputAssembly.vertexBuffers[i];
    6272         if (   pBufferContext->pBuffer != pBufferPipeline->pBuffer
     6267    for (int32_t i = 0; i < SVGA3D_DX_MAX_VERTEXBUFFERS; ++i)
     6268    {
     6269        SVGA3dBufferBinding const *pBufferContext = &pDXContext->svgaDXContext.inputAssembly.vertexBuffers[i];
     6270        SVGA3dBufferBinding *pBufferPipeline = &pBackend->svgaDXContext.inputAssembly.vertexBuffers[i];
     6271
     6272        if (   pBufferContext->bufferId != pBufferPipeline->bufferId
    62736273            || pBufferContext->stride != pBufferPipeline->stride
    62746274            || pBufferContext->offset != pBufferPipeline->offset)
    62756275        {
    6276             LogFunc(("vertex buffer: [%u]: sid = %u, %p (stride %d, off %d) -> %p (stride %d, off %d)\n",
    6277                      i, pDXContext->svgaDXContext.inputAssembly.vertexBuffers[i].bufferId,
    6278                      pBufferPipeline->pBuffer, pBufferPipeline->stride, pBufferPipeline->offset,
    6279                      pBufferContext->pBuffer, pBufferContext->stride, pBufferContext->offset));
    6280 
    6281             if (pBufferContext->pBuffer != pBufferPipeline->pBuffer)
    6282             {
    6283                 if (pBufferContext->pBuffer)
    6284                    pBufferContext->pBuffer->AddRef();
    6285                 D3D_RELEASE(pBufferPipeline->pBuffer);
    6286             }
     6276            /* The slot has a new buffer. */
     6277            LogFunc(("vb[%u]: sid = %u, stride %d, off %d -> sid = %u, stride %d, off %d\n",
     6278                     i, pBufferPipeline->bufferId, pBufferPipeline->stride, pBufferPipeline->offset,
     6279                     pBufferContext->bufferId, pBufferContext->stride, pBufferContext->offset));
     6280
    62876281            *pBufferPipeline = *pBufferContext;
    62886282
    6289             idxMaxSlot = i;
     6283            idxMaxSlot = RT_MAX(idxMaxSlot, i);
     6284            idxMinSlot = RT_MIN(idxMinSlot, i);
    62906285        }
    62916286#ifdef LOG_ENABLED
    6292         else if (pBufferContext->pBuffer)
    6293         {
    6294             LogFunc(("vertex buffer: [%u]: sid = %u, %p (stride %d, off %d)\n",
    6295                      i, pDXContext->svgaDXContext.inputAssembly.vertexBuffers[i].bufferId,
    6296                      pBufferContext->pBuffer, pBufferContext->stride, pBufferContext->offset));
     6287        else if (pBufferPipeline->bufferId != SVGA3D_INVALID_ID)
     6288        {
     6289            LogFunc(("vb[%u]: sid = %u, stride %d, off %d\n",
     6290                     i, pBufferPipeline->bufferId, pBufferPipeline->stride, pBufferPipeline->offset));
    62976291        }
    62986292#endif
    6299 
    6300         paResources[i] = pBufferContext->pBuffer;
    6301         if (pBufferContext->pBuffer)
    6302         {
    6303             paStride[i] = pBufferContext->stride;
    6304             paOffset[i] = pBufferContext->offset;
     6293        ID3D11Buffer *pBuffer = NULL;
     6294        if (pBufferPipeline->bufferId != SVGA3D_INVALID_ID)
     6295        {
     6296            PVMSVGA3DSURFACE pSurface;
     6297            ID3D11Resource *pResource;
     6298            int rc = dxEnsureResource(pThisCC, pDXContext, pBufferPipeline->bufferId, &pSurface, &pResource);
     6299            if (   RT_SUCCESS(rc)
     6300                && pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER)
     6301                pBuffer = (ID3D11Buffer *)pResource;
     6302            else
     6303                AssertMsgFailed(("%Rrc %p %d\n", rc, pSurface->pBackendSurface, pSurface->pBackendSurface ? pSurface->pBackendSurface->enmResType : VMSVGA3D_RESTYPE_NONE));
     6304        }
     6305
     6306        paResources[i] = pBuffer;
     6307        if (pBuffer)
     6308        {
     6309            LogFunc(("vb[%u]: %p\n", i, pBuffer));
     6310            paStride[i] = pBufferPipeline->stride;
     6311            paOffset[i] = pBufferPipeline->offset;
    63056312        }
    63066313        else
     
    63116318    }
    63126319
    6313     LogFunc(("idxMaxSlot = %d\n", idxMaxSlot));
     6320    DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
     6321    LogFunc(("idxMinSlot = %d, idxMaxSlot = %d\n", idxMinSlot, idxMaxSlot));
    63146322    if (idxMaxSlot >= 0)
    6315         pDXDevice->pImmediateContext->IASetVertexBuffers(0, idxMaxSlot + 1, paResources, paStride, paOffset);
     6323        pDXDevice->pImmediateContext->IASetVertexBuffers(idxMinSlot, (idxMaxSlot - idxMinSlot) + 1,
     6324                                                         &paResources[idxMinSlot], &paStride[idxMinSlot], &paOffset[idxMinSlot]);
    63166325}
    63176326
    63186327static void dxSetIndexBuffer(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext)
    63196328{
    6320 //DEBUG_BREAKPOINT_TEST();
    63216329    PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
     6330
     6331    SVGADXContextMobFormat *pPipelineState = &pBackend->svgaDXContext;
     6332    SVGADXContextMobFormat const *pContextState = &pDXContext->svgaDXContext;
     6333
     6334    if (   pPipelineState->inputAssembly.indexBufferSid != pContextState->inputAssembly.indexBufferSid
     6335        || pPipelineState->inputAssembly.indexBufferOffset != pContextState->inputAssembly.indexBufferOffset
     6336        || pPipelineState->inputAssembly.indexBufferFormat != pContextState->inputAssembly.indexBufferFormat)
     6337    {
     6338        LogFunc(("ib: sid = %u, offset %u, fmt %u -> sid = %u, offset %u, fmt %u\n",
     6339                 pPipelineState->inputAssembly.indexBufferSid, pPipelineState->inputAssembly.indexBufferOffset, pPipelineState->inputAssembly.indexBufferFormat,
     6340                 pContextState->inputAssembly.indexBufferSid, pContextState->inputAssembly.indexBufferOffset, pContextState->inputAssembly.indexBufferFormat));
     6341
     6342        pPipelineState->inputAssembly.indexBufferSid = pContextState->inputAssembly.indexBufferSid;
     6343        pPipelineState->inputAssembly.indexBufferOffset = pContextState->inputAssembly.indexBufferOffset;
     6344        pPipelineState->inputAssembly.indexBufferFormat = pContextState->inputAssembly.indexBufferFormat;
     6345    }
     6346#ifdef LOG_ENABLED
     6347    else if (pPipelineState->inputAssembly.indexBufferSid != SVGA3D_INVALID_ID)
     6348    {
     6349        LogFunc(("ib: sid = %u, offset %u, fmt %u\n",
     6350                 pPipelineState->inputAssembly.indexBufferSid, pPipelineState->inputAssembly.indexBufferOffset, pPipelineState->inputAssembly.indexBufferFormat));
     6351    }
     6352#endif
     6353
     6354    ID3D11Buffer *pBuffer = NULL;
     6355    if (pPipelineState->inputAssembly.indexBufferSid != SVGA3D_INVALID_ID)
     6356    {
     6357        PVMSVGA3DSURFACE pSurface;
     6358        ID3D11Resource *pResource;
     6359        int rc = dxEnsureResource(pThisCC, pDXContext, pPipelineState->inputAssembly.indexBufferSid, &pSurface, &pResource);
     6360        if (   RT_SUCCESS(rc)
     6361            && pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER)
     6362            pBuffer = (ID3D11Buffer *)pResource;
     6363        else
     6364            AssertMsgFailed(("%Rrc %p %d\n", rc, pSurface->pBackendSurface, pSurface->pBackendSurface ? pSurface->pBackendSurface->enmResType : VMSVGA3D_RESTYPE_NONE));
     6365    }
     6366
     6367    DXGI_FORMAT enmDxgiFormat;
     6368    UINT Offset;
     6369    if (pBuffer)
     6370    {
     6371        enmDxgiFormat = vmsvgaDXSurfaceFormat2Dxgi((SVGA3dSurfaceFormat)pPipelineState->inputAssembly.indexBufferFormat);
     6372        AssertReturnVoid(enmDxgiFormat == DXGI_FORMAT_R16_UINT || enmDxgiFormat == DXGI_FORMAT_R32_UINT);
     6373        Offset = pPipelineState->inputAssembly.indexBufferOffset;
     6374    }
     6375    else
     6376    {
     6377        enmDxgiFormat = DXGI_FORMAT_UNKNOWN;
     6378        Offset = 0;
     6379    }
     6380
    63226381    DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    6323     VMSVGA3DBACKENDDXCONTEXT *pBackendDXContext = pDXContext->pBackendDXContext;
    6324 
    6325     DXBOUNDINDEXBUFFER *pBufferContext = &pBackendDXContext->resources.inputAssembly.indexBuffer;
    6326     DXBOUNDINDEXBUFFER *pBufferPipeline = &pBackend->resources.inputAssembly.indexBuffer;
    6327     if (   pBufferContext->pBuffer != pBufferPipeline->pBuffer
    6328         || pBufferContext->indexBufferOffset != pBufferPipeline->indexBufferOffset
    6329         || pBufferContext->indexBufferFormat != pBufferPipeline->indexBufferFormat)
    6330     {
    6331         LogFunc(("index_buffer: sid = %u, %p -> %p\n",
    6332                  pDXContext->svgaDXContext.inputAssembly.indexBufferSid, pBufferPipeline->pBuffer, pBufferContext->pBuffer));
    6333 
    6334         if (pBufferContext->pBuffer != pBufferPipeline->pBuffer)
    6335         {
    6336             if (pBufferContext->pBuffer)
    6337                pBufferContext->pBuffer->AddRef();
    6338             D3D_RELEASE(pBufferPipeline->pBuffer);
    6339         }
    6340         *pBufferPipeline = *pBufferContext;
    6341 
    6342         pDXDevice->pImmediateContext->IASetIndexBuffer(pBufferContext->pBuffer, pBufferContext->indexBufferFormat, pBufferContext->indexBufferOffset);
    6343     }
     6382    pDXDevice->pImmediateContext->IASetIndexBuffer(pBuffer, enmDxgiFormat, Offset);
    63446383}
    63456384
     
    65076546static void dxDbgDumpVertexData(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t vertexCount, uint32_t startVertexLocation)
    65086547{
    6509     PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    6510 
    65116548    for (uint32_t iSlot = 0; iSlot < SVGA3D_DX_MAX_VERTEXBUFFERS; ++iSlot)
    65126549    {
    6513         DXBOUNDVERTEXBUFFER *pBufferPipeline = &pBackend->resources.inputAssembly.vertexBuffers[iSlot];
    6514         uint32_t const sid = pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot].bufferId;
    6515         if (sid == SVGA3D_INVALID_ID)
    6516         {
    6517             Assert(pBufferPipeline->pBuffer == 0);
     6550        SVGA3dBufferBinding const *pVBInfo = &pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot];
     6551        if (pVBInfo->bufferId == SVGA3D_INVALID_ID)
    65186552            continue;
    6519         }
    6520 
    6521         Assert(pBufferPipeline->pBuffer);
     6553
     6554        PVMSVGA3DSURFACE pSurface = NULL;
     6555        int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, pVBInfo->bufferId, &pSurface);
     6556        AssertContinue(RT_SUCCESS(rc));
     6557        AssertContinue(pSurface->pBackendSurface->u.pBuffer && pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER);
    65226558
    65236559        SVGA3dSurfaceImageId image;
    6524         image.sid = sid;
     6560        image.sid = pVBInfo->bufferId;
    65256561        image.face = 0;
    65266562        image.mipmap = 0;
    65276563
    65286564        VMSVGA3D_MAPPED_SURFACE map;
    6529         int rc = vmsvga3dBackSurfaceMap(pThisCC, &image, NULL, VMSVGA3D_SURFACE_MAP_READ, &map);
     6565        rc = vmsvga3dBackSurfaceMap(pThisCC, &image, NULL, VMSVGA3D_SURFACE_MAP_READ, &map);
    65306566        AssertRC(rc);
    65316567        if (RT_SUCCESS(rc))
    65326568        {
    65336569            uint8_t const *pu8VertexData = (uint8_t *)map.pvData;
    6534             pu8VertexData += pBufferPipeline->offset;
    6535             pu8VertexData += startVertexLocation * pBufferPipeline->stride;
     6570            pu8VertexData += pVBInfo->offset;
     6571            pu8VertexData += startVertexLocation * pVBInfo->stride;
    65366572
    65376573            SVGA3dElementLayoutId const elementLayoutId = pDXContext->svgaDXContext.inputAssembly.layoutId;
     
    65406576
    65416577            Log8(("Vertex buffer dump: sid = %u, vertexCount %u, startVertexLocation %d, offset = %d, stride = %d:\n",
    6542                   sid, vertexCount, startVertexLocation, pBufferPipeline->offset, pBufferPipeline->stride));
     6578                  pVBInfo->bufferId, vertexCount, startVertexLocation, pVBInfo->offset, pVBInfo->stride));
    65436579
    65446580            for (uint32_t v = 0; v < vertexCount; ++v)
     
    65556591                Log8((" },\n"));
    65566592
    6557                 if (pBufferPipeline->stride == 0)
     6593                if (pVBInfo->stride == 0)
    65586594                    break;
    65596595
    6560                 pu8VertexData += pBufferPipeline->stride;
     6596                pu8VertexData += pVBInfo->stride;
    65616597            }
    65626598
     
    65696605static void dxDbgDumpIndexedVertexData(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t indexCount, uint32_t startIndexLocation, int32_t baseVertexLocation)
    65706606{
    6571     PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    65726607    DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    6573     SVGA3dSurfaceImageId image;
    6574 
    6575     DXBOUNDINDEXBUFFER *pIB = &pBackend->resources.inputAssembly.indexBuffer;
    6576     uint32_t const sidIB = pDXContext->svgaDXContext.inputAssembly.indexBufferSid;
    6577     if (sidIB == SVGA3D_INVALID_ID)
    6578     {
    6579         Assert(pIB->pBuffer == 0);
     6608
     6609    uint32_t const indexBufferSid = pDXContext->svgaDXContext.inputAssembly.indexBufferSid;
     6610    if (indexBufferSid == SVGA3D_INVALID_ID)
    65806611        return;
    6581     }
    6582 
    6583     Assert(pIB->pBuffer);
    6584     UINT const BytesPerIndex = pIB->indexBufferFormat == DXGI_FORMAT_R16_UINT ? 2 : 4;
     6612    uint32_t const indexBufferFormat = pDXContext->svgaDXContext.inputAssembly.indexBufferFormat;
     6613    uint32_t const indexBufferOffset = pDXContext->svgaDXContext.inputAssembly.indexBufferOffset;
     6614
     6615    PVMSVGA3DSURFACE pSurface = NULL;
     6616    int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, indexBufferSid, &pSurface);
     6617    AssertReturnVoid(RT_SUCCESS(rc));
     6618    AssertReturnVoid(pSurface->pBackendSurface->u.pBuffer && pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER);
     6619
     6620    UINT const BytesPerIndex = indexBufferFormat == SVGA3D_R16_UINT ? 2 : 4;
    65856621
    65866622    void *pvIndexBuffer;
    65876623    uint32_t cbIndexBuffer;
    6588     int rc = dxReadBuffer(pDXDevice, pIB->pBuffer, pIB->indexBufferOffset + startIndexLocation * BytesPerIndex, indexCount * BytesPerIndex, &pvIndexBuffer, &cbIndexBuffer);
     6624    rc = dxReadBuffer(pDXDevice, pSurface->pBackendSurface->u.pBuffer,
     6625                      indexBufferOffset + startIndexLocation * BytesPerIndex,
     6626                      indexCount * BytesPerIndex, &pvIndexBuffer, &cbIndexBuffer);
    65896627    AssertRC(rc);
    65906628    if (RT_SUCCESS(rc))
     
    65946632        for (uint32_t iSlot = 0; iSlot < SVGA3D_DX_MAX_VERTEXBUFFERS; ++iSlot)
    65956633        {
    6596             DXBOUNDVERTEXBUFFER *pVB = &pBackend->resources.inputAssembly.vertexBuffers[iSlot];
    6597             uint32_t const sidVB = pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot].bufferId;
    6598             if (sidVB == SVGA3D_INVALID_ID)
    6599             {
    6600                 Assert(pVB->pBuffer == 0);
     6634            SVGA3dBufferBinding const *pVBInfo = &pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot];
     6635            if (pVBInfo->bufferId == SVGA3D_INVALID_ID)
    66016636                continue;
    6602             }
    6603 
    6604             Assert(pVB->pBuffer);
    6605 
    6606             image.sid = sidVB;
     6637
     6638            pSurface = NULL;
     6639            rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, pVBInfo->bufferId, &pSurface);
     6640            AssertContinue(RT_SUCCESS(rc));
     6641            AssertContinue(pSurface->pBackendSurface->u.pBuffer && pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER);
     6642
     6643            SVGA3dSurfaceImageId image;
     6644            image.sid = pVBInfo->bufferId;
    66076645            image.face = 0;
    66086646            image.mipmap = 0;
     
    66146652            {
    66156653                uint8_t const *pu8VertexData = (uint8_t *)mapVB.pvData;
    6616                 pu8VertexData += pVB->offset;
    6617                 pu8VertexData += baseVertexLocation * pVB->stride;
     6654                pu8VertexData += pVBInfo->offset;
     6655                pu8VertexData += baseVertexLocation * pVBInfo->stride;
    66186656
    66196657                SVGA3dElementLayoutId const elementLayoutId = pDXContext->svgaDXContext.inputAssembly.layoutId;
     
    66226660
    66236661                Log8(("Vertex buffer dump: sid = %u, indexCount %u, startIndexLocation %d, baseVertexLocation %d, offset = %d, stride = %d:\n",
    6624                       sidVB, indexCount, startIndexLocation, baseVertexLocation, pVB->offset, pVB->stride));
     6662                      pVBInfo->bufferId, indexCount, startIndexLocation, baseVertexLocation, pVBInfo->offset, pVBInfo->stride));
    66256663
    66266664                for (uint32_t i = 0; i < indexCount; ++i)
     
    66426680                        if (pElement->InputSlot == iSlot)
    66436681                        {
    6644                             uint8_t const *pu8Vertex = pu8VertexData + Index * pVB->stride;
     6682                            uint8_t const *pu8Vertex = pu8VertexData + Index * pVBInfo->stride;
    66456683                            dxDbgLogVertexElement(pElement->Format, pu8Vertex + pElement->AlignedByteOffset);
    66466684                        }
     
    66496687                    Log8((" },\n"));
    66506688
    6651                     if (pVB->stride == 0)
     6689                    if (pVBInfo->stride == 0)
    66526690                        break;
    66536691                }
     
    66646702static void dxDbgDumpInstanceData(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t instanceCount, uint32_t startInstanceLocation)
    66656703{
    6666     PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    6667     SVGA3dSurfaceImageId image;
    6668 
    66696704    /*
    66706705     * Dump per-instance data.
     
    66746709        for (uint32_t iSlot = 0; iSlot < SVGA3D_DX_MAX_VERTEXBUFFERS; ++iSlot)
    66756710        {
    6676             DXBOUNDVERTEXBUFFER *pVB = &pBackend->resources.inputAssembly.vertexBuffers[iSlot];
    6677             uint32_t const sidVB = pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot].bufferId;
    6678             if (sidVB == SVGA3D_INVALID_ID)
    6679             {
    6680                 Assert(pVB->pBuffer == 0);
     6711            SVGA3dBufferBinding const *pVBInfo = &pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot];
     6712            if (pVBInfo->bufferId == SVGA3D_INVALID_ID)
    66816713                continue;
    6682             }
    6683 
    6684             Assert(pVB->pBuffer);
    6685 
    6686             image.sid = sidVB;
     6714
     6715            PVMSVGA3DSURFACE pSurface = NULL;
     6716            int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, pVBInfo->bufferId, &pSurface);
     6717            AssertContinue(RT_SUCCESS(rc));
     6718            AssertContinue(pSurface->pBackendSurface->u.pBuffer && pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER);
     6719
     6720            SVGA3dSurfaceImageId image;
     6721            image.sid = pVBInfo->bufferId;
    66876722            image.face = 0;
    66886723            image.mipmap = 0;
    66896724
    66906725            VMSVGA3D_MAPPED_SURFACE mapVB;
    6691             int rc = vmsvga3dBackSurfaceMap(pThisCC, &image, NULL, VMSVGA3D_SURFACE_MAP_READ, &mapVB);
     6726            rc = vmsvga3dBackSurfaceMap(pThisCC, &image, NULL, VMSVGA3D_SURFACE_MAP_READ, &mapVB);
    66926727            AssertRC(rc);
    66936728            if (RT_SUCCESS(rc))
    66946729            {
    66956730                uint8_t const *pu8VertexData = (uint8_t *)mapVB.pvData;
    6696                 pu8VertexData += pVB->offset;
    6697                 pu8VertexData += startInstanceLocation * pVB->stride;
     6731                pu8VertexData += pVBInfo->offset;
     6732                pu8VertexData += startInstanceLocation * pVBInfo->stride;
    66986733
    66996734                SVGA3dElementLayoutId const elementLayoutId = pDXContext->svgaDXContext.inputAssembly.layoutId;
     
    67026737
    67036738                Log8(("Instance data dump: sid = %u, iInstance %u, startInstanceLocation %d, offset = %d, stride = %d:\n",
    6704                       sidVB, iInstance, startInstanceLocation, pVB->offset, pVB->stride));
     6739                      pVBInfo->bufferId, iInstance, startInstanceLocation, pVBInfo->offset, pVBInfo->stride));
    67056740
    67066741                Log8(("slot[%u] /* i%u */ { ", iSlot, iInstance));
     
    67136748                    if (pElement->InputSlot == iSlot)
    67146749                    {
    6715                         uint8_t const *pu8Vertex = pu8VertexData + iInstance * pVB->stride;
     6750                        uint8_t const *pu8Vertex = pu8VertexData + iInstance * pVBInfo->stride;
    67166751                        dxDbgLogVertexElement(pElement->Format, pu8Vertex + pElement->AlignedByteOffset);
    67176752                    }
     
    76677702static DECLCALLBACK(int) vmsvga3dBackDXSetVertexBuffers(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t startBuffer, uint32_t cVertexBuffer, SVGA3dVertexBuffer const *paVertexBuffer)
    76687703{
    7669     PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    7670     RT_NOREF(pBackend);
    7671 
    7672     DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    7673     AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    7674 
    7675     for (uint32_t i = 0; i < cVertexBuffer; ++i)
    7676     {
    7677         uint32_t const idxVertexBuffer = startBuffer + i;
    7678 
    7679         /* Get corresponding resource. Create the buffer if does not yet exist. */
    7680         if (paVertexBuffer[i].sid != SVGA_ID_INVALID)
    7681         {
    7682             PVMSVGA3DSURFACE pSurface;
    7683             int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, paVertexBuffer[i].sid, &pSurface);
    7684             AssertRCReturn(rc, rc);
    7685 
    7686             if (pSurface->pBackendSurface == NULL)
    7687             {
    7688                 /* Create the resource and initialize it with the current surface data. */
    7689                 rc = vmsvga3dBackSurfaceCreateBuffer(pThisCC, pDXContext, pSurface);
    7690                 AssertRCReturn(rc, rc);
    7691             }
    7692             Assert(pSurface->pBackendSurface->u.pBuffer);
    7693 
    7694             DXBOUNDVERTEXBUFFER *pBoundBuffer = &pDXContext->pBackendDXContext->resources.inputAssembly.vertexBuffers[idxVertexBuffer];
    7695             if (   pBoundBuffer->pBuffer != pSurface->pBackendSurface->u.pBuffer
    7696                 || pBoundBuffer->stride != paVertexBuffer[i].stride
    7697                 || pBoundBuffer->offset != paVertexBuffer[i].offset)
    7698             {
    7699                 LogFunc(("vertex buffer: [%u]: sid = %u, offset %u, stride %u (%p -> %p)\n",
    7700                          idxVertexBuffer, paVertexBuffer[i].sid, paVertexBuffer[i].offset, paVertexBuffer[i].stride, pBoundBuffer->pBuffer, pSurface->pBackendSurface->u.pBuffer));
    7701 
    7702                 if (pBoundBuffer->pBuffer != pSurface->pBackendSurface->u.pBuffer)
    7703                 {
    7704                     D3D_RELEASE(pBoundBuffer->pBuffer);
    7705                     pBoundBuffer->pBuffer = pSurface->pBackendSurface->u.pBuffer;
    7706                     pBoundBuffer->pBuffer->AddRef();
    7707                 }
    7708                 pBoundBuffer->stride = paVertexBuffer[i].stride;
    7709                 pBoundBuffer->offset = paVertexBuffer[i].offset;
    7710             }
    7711         }
    7712         else
    7713         {
    7714             DXBOUNDVERTEXBUFFER *pBoundBuffer = &pDXContext->pBackendDXContext->resources.inputAssembly.vertexBuffers[idxVertexBuffer];
    7715             D3D_RELEASE(pBoundBuffer->pBuffer);
    7716             pBoundBuffer->stride = 0;
    7717             pBoundBuffer->offset = 0;
    7718         }
    7719     }
    7720 
     7704    /* Will be set in setupPipeline. */
     7705    RT_NOREF(pThisCC, pDXContext, startBuffer, cVertexBuffer, paVertexBuffer);
    77217706    return VINF_SUCCESS;
    77227707}
     
    77257710static DECLCALLBACK(int) vmsvga3dBackDXSetIndexBuffer(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dSurfaceId sid, SVGA3dSurfaceFormat format, uint32_t offset)
    77267711{
    7727     PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    7728     RT_NOREF(pBackend);
    7729 
    7730     DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    7731     AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    7732 
    7733     /* Get corresponding resource. Create the buffer if does not yet exist. */
    7734     if (sid != SVGA_ID_INVALID)
    7735     {
    7736         PVMSVGA3DSURFACE pSurface;
    7737         int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, sid, &pSurface);
    7738         AssertRCReturn(rc, rc);
    7739 
    7740         if (pSurface->pBackendSurface == NULL)
    7741         {
    7742             /* Create the resource and initialize it with the current surface data. */
    7743             rc = vmsvga3dBackSurfaceCreateBuffer(pThisCC, pDXContext, pSurface);
    7744             AssertRCReturn(rc, rc);
    7745         }
    7746 
    7747         DXGI_FORMAT const enmDxgiFormat = vmsvgaDXSurfaceFormat2Dxgi(format);
    7748         AssertReturn(enmDxgiFormat == DXGI_FORMAT_R16_UINT || enmDxgiFormat == DXGI_FORMAT_R32_UINT, VERR_INVALID_PARAMETER);
    7749 
    7750         DXBOUNDINDEXBUFFER *pBoundBuffer = &pDXContext->pBackendDXContext->resources.inputAssembly.indexBuffer;
    7751         if (   pBoundBuffer->pBuffer != pSurface->pBackendSurface->u.pBuffer
    7752             || pBoundBuffer->indexBufferOffset != offset
    7753             || pBoundBuffer->indexBufferFormat != enmDxgiFormat)
    7754         {
    7755             LogFunc(("index_buffer: sid = %u, offset %u, (%p -> %p)\n",
    7756                      sid, offset, pBoundBuffer->pBuffer, pSurface->pBackendSurface->u.pBuffer));
    7757 
    7758             if (pBoundBuffer->pBuffer != pSurface->pBackendSurface->u.pBuffer)
    7759             {
    7760                 D3D_RELEASE(pBoundBuffer->pBuffer);
    7761                 pBoundBuffer->pBuffer = pSurface->pBackendSurface->u.pBuffer;
    7762                 pBoundBuffer->pBuffer->AddRef();
    7763             }
    7764             pBoundBuffer->indexBufferOffset = offset;
    7765             pBoundBuffer->indexBufferFormat = enmDxgiFormat;
    7766         }
    7767     }
    7768     else
    7769     {
    7770         DXBOUNDINDEXBUFFER *pBoundBuffer = &pDXContext->pBackendDXContext->resources.inputAssembly.indexBuffer;
    7771         D3D_RELEASE(pBoundBuffer->pBuffer);
    7772         pBoundBuffer->indexBufferOffset = 0;
    7773         pBoundBuffer->indexBufferFormat = DXGI_FORMAT_UNKNOWN;
    7774     }
    7775 
     7712    /* Will be set in setupPipeline. */
     7713    RT_NOREF(pThisCC, pDXContext, sid, format, offset);
    77767714    return VINF_SUCCESS;
    77777715}
     
    1007210010    {
    1007310011        PVMSVGA3DSURFACE pSurface;
    10074         int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, argsBufferSid, &pSurface);
     10012        ID3D11Resource *pResource;
     10013        int rc = dxEnsureResource(pThisCC, pDXContext, argsBufferSid, &pSurface, &pResource);
    1007510014        AssertRCReturn(rc, rc);
    10076 
    10077         if (pSurface->pBackendSurface == NULL)
    10078         {
    10079             /* Create the resource and initialize it with the current surface data. */
    10080             rc = vmsvga3dBackSurfaceCreateResource(pThisCC, pDXContext, pSurface);
    10081             AssertRCReturn(rc, rc);
    10082         }
    10083 
    10084         pBufferForArgs = pSurface->pBackendSurface->u.pBuffer;
     10015        AssertReturn(pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER, VERR_INVALID_STATE);
     10016
     10017        pBufferForArgs = (ID3D11Buffer *)pResource;
    1008510018    }
    1008610019    else
     
    1011710050    {
    1011810051        PVMSVGA3DSURFACE pSurface;
    10119         int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, argsBufferSid, &pSurface);
     10052        ID3D11Resource *pResource;
     10053        int rc = dxEnsureResource(pThisCC, pDXContext, argsBufferSid, &pSurface, &pResource);
    1012010054        AssertRCReturn(rc, rc);
    10121 
    10122         if (pSurface->pBackendSurface == NULL)
    10123         {
    10124             /* Create the resource and initialize it with the current surface data. */
    10125             rc = vmsvga3dBackSurfaceCreateResource(pThisCC, pDXContext, pSurface);
    10126             AssertRCReturn(rc, rc);
    10127         }
    10128 
    10129         pBufferForArgs = pSurface->pBackendSurface->u.pBuffer;
     10055        AssertReturn(pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER, VERR_INVALID_STATE);
     10056
     10057        pBufferForArgs = (ID3D11Buffer *)pResource;
    1013010058    }
    1013110059    else
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx.cpp

    r102632 r102714  
    6262}
    6363
     64void vmsvga3dDXInitContextMobData(SVGADXContextMobFormat *p)
     65{
     66    /* 0xFFFFFFFF (SVGA_ID_INVALID) is a better initial value than 0 for most of svgaDXContext fields. */
     67    memset(p, 0xFF, sizeof(*p));
     68
     69    p->inputAssembly.layoutId = SVGA3D_INVALID_ID;
     70    for (uint32_t i = 0; i < RT_ELEMENTS(p->inputAssembly.vertexBuffers); ++i)
     71    {
     72        p->inputAssembly.vertexBuffers[i].bufferId = SVGA3D_INVALID_ID;
     73        p->inputAssembly.vertexBuffers[i].stride = 0;
     74        p->inputAssembly.vertexBuffers[i].offset = 0;
     75    }
     76    p->inputAssembly.indexBufferSid = SVGA3D_INVALID_ID;
     77    p->inputAssembly.indexBufferOffset = 0;
     78    p->inputAssembly.indexBufferFormat = SVGA3D_FORMAT_INVALID;
     79    p->inputAssembly.topology = SVGA3D_PRIMITIVE_INVALID;
     80
     81    p->renderState.blendStateId = SVGA3D_INVALID_ID;
     82    RT_ZERO(p->renderState.blendFactor);
     83    p->renderState.sampleMask = 0;
     84    p->renderState.depthStencilStateId = SVGA3D_INVALID_ID;
     85    p->renderState.stencilRef = 0;
     86    p->renderState.rasterizerStateId = SVGA3D_INVALID_ID;
     87    p->renderState.depthStencilViewId = SVGA3D_INVALID_ID;
     88    for (uint32_t i = 0; i < RT_ELEMENTS(p->renderState.renderTargetViewIds); ++i)
     89        p->renderState.renderTargetViewIds[i] = SVGA3D_INVALID_ID;
     90
     91    for (uint32_t i = 0; i < RT_ELEMENTS(p->streamOut.targets); ++i)
     92        p->streamOut.targets[i] = SVGA3D_INVALID_ID;
     93    p->streamOut.soid = SVGA3D_INVALID_ID;
     94
     95    p->uavSpliceIndex = 0;
     96    p->numViewports = 0;
     97    p->numScissorRects = 0;
     98
     99    RT_ZERO(p->viewports);
     100    RT_ZERO(p->scissorRects);
     101
     102    p->predication.queryID = SVGA3D_INVALID_ID;
     103    p->predication.value = 0;
     104
     105    p->shaderIfaceMobid = SVGA3D_INVALID_ID;
     106    p->shaderIfaceOffset = 0;
     107
     108    for (uint32_t i = 0; i < RT_ELEMENTS(p->shaderState); ++i)
     109    {
     110        p->shaderState[i].shaderId = SVGA3D_INVALID_ID;
     111        for (uint32_t j = 0; j < RT_ELEMENTS(p->shaderState[0].constantBuffers); ++j)
     112        {
     113            SVGA3dConstantBufferBinding *cbb = &p->shaderState[i].constantBuffers[j];
     114            cbb->sid = SVGA3D_INVALID_ID;
     115            cbb->offsetInBytes = 0;
     116            cbb->sizeInBytes = 0;
     117        }
     118        for (uint32_t j = 0; j < RT_ELEMENTS(p->shaderState[0].shaderResources); ++j)
     119            p->shaderState[i].shaderResources[j] = SVGA3D_INVALID_ID;
     120        for (uint32_t j = 0; j < RT_ELEMENTS(p->shaderState[0].samplers); ++j)
     121            p->shaderState[i].samplers[j] = SVGA3D_INVALID_ID;
     122    }
     123
     124    for (uint32_t i = 0; i < RT_ELEMENTS(p->queryID); ++i)
     125        p->queryID[i] = SVGA3D_INVALID_ID;
     126
     127    for (uint32_t i = 0; i < RT_ELEMENTS(p->cotables); ++i)
     128        p->cotables[i].mobid = SVGA3D_INVALID_ID;
     129
     130    for (uint32_t i = 0; i < RT_ELEMENTS(p->uaViewIds); ++i)
     131        p->uaViewIds[i] = SVGA3D_INVALID_ID;
     132
     133    for (uint32_t i = 0; i < RT_ELEMENTS(p->csuaViewIds); ++i)
     134        p->csuaViewIds[i] = SVGA3D_INVALID_ID;
     135}
    64136
    65137/*
     
    302374    memset(pDXContext, 0, sizeof(*pDXContext));
    303375
    304     /* 0xFFFFFFFF (SVGA_ID_INVALID) is a better initial value than 0 for most of svgaDXContext fields. */
    305     memset(&pDXContext->svgaDXContext, 0xFF, sizeof(pDXContext->svgaDXContext));
    306     pDXContext->svgaDXContext.inputAssembly.topology = SVGA3D_PRIMITIVE_INVALID;
    307     pDXContext->svgaDXContext.numViewports = 0;
    308     pDXContext->svgaDXContext.numScissorRects = 0;
     376    vmsvga3dDXInitContextMobData(&pDXContext->svgaDXContext);
    309377    pDXContext->cid = cid;
    310378
     
    11041172                        || queryId < pDXContext->cot.cQuery, VERR_INVALID_PARAMETER);
    11051173    RT_UNTRUSTED_VALIDATED_FENCE();
     1174
     1175    pDXContext->svgaDXContext.predication.queryID = queryId;
     1176    pDXContext->svgaDXContext.predication.value = pCmd->predicateValue;
    11061177
    11071178    rc = pSvgaR3State->pFuncsDX->pfnDXSetPredication(pThisCC, pDXContext, queryId, pCmd->predicateValue);
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-internal.h

    r102520 r102714  
    13681368    return VERR_INVALID_PARAMETER;
    13691369}
     1370
     1371void vmsvga3dDXInitContextMobData(SVGADXContextMobFormat *p);
    13701372#endif
    13711373
Note: See TracChangeset for help on using the changeset viewer.

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