VirtualBox

Changeset 91504 in vbox for trunk/src


Ignore:
Timestamp:
Oct 1, 2021 9:33:32 AM (3 years ago)
Author:
vboxsync
Message:

Devices/Graphics: straighten out code which waits for drawing to finish; wait for shader resources: bugref:9830

File:
1 edited

Legend:

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

    r91484 r91504  
    896896
    897897
     898static int dxSurfaceWait(PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface, uint32_t cidRequesting)
     899{
     900    VMSVGA3DBACKENDSURFACE *pBackendSurface = pSurface->pBackendSurface;
     901    if (!pBackendSurface)
     902        AssertFailedReturn(VERR_INVALID_STATE);
     903
     904    int rc = VINF_SUCCESS;
     905    if (pBackendSurface->cidDrawing != SVGA_ID_INVALID)
     906    {
     907        if (pBackendSurface->cidDrawing != cidRequesting)
     908        {
     909            LogFunc(("sid = %u, assoc cid = %u, drawing cid = %u, req cid = %u\n",
     910                     pSurface->id, pSurface->idAssociatedContext, pBackendSurface->cidDrawing, cidRequesting));
     911            Assert(dxIsSurfaceShareable(pSurface));
     912            rc = dxContextWait(pBackendSurface->cidDrawing, pState);
     913            pBackendSurface->cidDrawing = SVGA_ID_INVALID;
     914        }
     915    }
     916    return rc;
     917}
     918
     919
    898920static ID3D11Resource *dxResource(PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface, VMSVGA3DDXCONTEXT *pDXContext)
    899921{
     
    902924        AssertFailedReturn(NULL);
    903925
     926    ID3D11Resource *pResource;
     927
    904928    uint32_t const cidRequesting = pDXContext ? pDXContext->cid : DX_CID_BACKEND;
    905929    if (cidRequesting == pSurface->idAssociatedContext)
    906         return pBackendSurface->u.pResource;
    907 
    908     AssertReturn(pDXContext, NULL);
    909 
    910     /*
    911      * Another context is requesting.
    912      */
    913     Assert(dxIsSurfaceShareable(pSurface));
    914     Assert(pSurface->idAssociatedContext == DX_CID_BACKEND);
    915 
    916     DXSHAREDTEXTURE *pSharedTexture = (DXSHAREDTEXTURE *)RTAvlU32Get(&pBackendSurface->SharedTextureTree, pDXContext->cid);
    917     if (!pSharedTexture)
    918     {
    919         DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
    920         AssertReturn(pDevice->pDevice, NULL);
    921 
    922         AssertReturn(pBackendSurface->SharedHandle, NULL);
    923 
    924         /* This context has not yet opened the texture. */
    925         pSharedTexture = (DXSHAREDTEXTURE *)RTMemAllocZ(sizeof(DXSHAREDTEXTURE));
    926         AssertReturn(pSharedTexture, NULL);
    927 
    928         pSharedTexture->Core.Key = pDXContext->cid;
    929         bool const fSuccess = RTAvlU32Insert(&pBackendSurface->SharedTextureTree, &pSharedTexture->Core);
    930         AssertReturn(fSuccess, NULL);
    931 
    932         HRESULT hr = pDevice->pDevice->OpenSharedResource(pBackendSurface->SharedHandle, __uuidof(ID3D11Texture2D), (void**)&pSharedTexture->pTexture);
    933         Assert(SUCCEEDED(hr));
    934         if (SUCCEEDED(hr))
    935             pSharedTexture->sid = pSurface->id;
    936         else
     930        pResource = pBackendSurface->u.pResource;
     931    else
     932    {
     933        /*
     934         * Context, which as not created the surface, is requesting.
     935         */
     936        AssertReturn(pDXContext, NULL);
     937
     938        Assert(dxIsSurfaceShareable(pSurface));
     939        Assert(pSurface->idAssociatedContext == DX_CID_BACKEND);
     940
     941        DXSHAREDTEXTURE *pSharedTexture = (DXSHAREDTEXTURE *)RTAvlU32Get(&pBackendSurface->SharedTextureTree, pDXContext->cid);
     942        if (!pSharedTexture)
    937943        {
    938             RTAvlU32Remove(&pBackendSurface->SharedTextureTree, pDXContext->cid);
    939             RTMemFree(pSharedTexture);
    940             return NULL;
     944            DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     945            AssertReturn(pDevice->pDevice, NULL);
     946
     947            AssertReturn(pBackendSurface->SharedHandle, NULL);
     948
     949            /* This context has not yet opened the texture. */
     950            pSharedTexture = (DXSHAREDTEXTURE *)RTMemAllocZ(sizeof(DXSHAREDTEXTURE));
     951            AssertReturn(pSharedTexture, NULL);
     952
     953            pSharedTexture->Core.Key = pDXContext->cid;
     954            bool const fSuccess = RTAvlU32Insert(&pBackendSurface->SharedTextureTree, &pSharedTexture->Core);
     955            AssertReturn(fSuccess, NULL);
     956
     957            HRESULT hr = pDevice->pDevice->OpenSharedResource(pBackendSurface->SharedHandle, __uuidof(ID3D11Texture2D), (void**)&pSharedTexture->pTexture);
     958            Assert(SUCCEEDED(hr));
     959            if (SUCCEEDED(hr))
     960                pSharedTexture->sid = pSurface->id;
     961            else
     962            {
     963                RTAvlU32Remove(&pBackendSurface->SharedTextureTree, pDXContext->cid);
     964                RTMemFree(pSharedTexture);
     965                return NULL;
     966            }
    941967        }
     968
     969        pResource = pSharedTexture->pTexture;
    942970    }
    943971
    944972    /* Wait for drawing to finish. */
    945     if (pBackendSurface->cidDrawing != SVGA_ID_INVALID)
    946     {
    947         if (pBackendSurface->cidDrawing != pDXContext->cid)
    948         {
    949             dxContextWait(pBackendSurface->cidDrawing, pState);
    950             pBackendSurface->cidDrawing = SVGA_ID_INVALID;
    951         }
    952     }
    953 
    954     return pSharedTexture->pTexture;
     973    dxSurfaceWait(pState, pSurface, cidRequesting);
     974
     975    return pResource;
     976}
     977
     978
     979static uint32_t dxGetRenderTargetViewSid(PVMSVGA3DDXCONTEXT pDXContext, uint32_t renderTargetViewId)
     980{
     981    ASSERT_GUEST_RETURN(renderTargetViewId < pDXContext->cot.cRTView, SVGA_ID_INVALID);
     982
     983    SVGACOTableDXRTViewEntry const *pRTViewEntry = &pDXContext->cot.paRTView[renderTargetViewId];
     984    return pRTViewEntry->sid;
     985}
     986
     987
     988static uint32_t dxGetShaderResourceViewSid(PVMSVGA3DDXCONTEXT pDXContext, uint32_t shaderResourceViewId)
     989{
     990    ASSERT_GUEST_RETURN(shaderResourceViewId < pDXContext->cot.cSRView, SVGA_ID_INVALID);
     991
     992    SVGACOTableDXSRViewEntry const *pSRViewEntry = &pDXContext->cot.paSRView[shaderResourceViewId];
     993    return pSRViewEntry->sid;
    955994}
    956995
     
    9671006            continue;
    9681007
    969         AssertContinue(renderTargetViewId < pDXContext->cot.cRTView);
    970 
    971         SVGACOTableDXRTViewEntry const *pRTViewEntry = &pDXContext->cot.paRTView[renderTargetViewId];
     1008        uint32_t const sid = dxGetRenderTargetViewSid(pDXContext, renderTargetViewId);
     1009        LogFunc(("[%u] sid = %u, drawing cid = %u\n", i, sid, pDXContext->cid));
    9721010
    9731011        PVMSVGA3DSURFACE pSurface;
    974         int rc = vmsvga3dSurfaceFromSid(pState, pRTViewEntry->sid, &pSurface);
    975         if (   RT_SUCCESS(rc)
    976             && pSurface->pBackendSurface)
     1012        int rc = vmsvga3dSurfaceFromSid(pState, sid, &pSurface);
     1013        if (RT_SUCCESS(rc))
    9771014        {
     1015            AssertContinue(pSurface->pBackendSurface);
    9781016            pSurface->pBackendSurface->cidDrawing = pDXContext->cid;
    9791017        }
     
    20092047         * Success.
    20102048         */
     2049        LogFunc(("sid = %u\n", pSurface->id));
    20112050        pBackendSurface->enmDxgiFormat = dxgiFormat;
    20122051        pSurface->pBackendSurface = pBackendSurface;
     
    28462885        Assert(pImage->face == 0 && pImage->mipmap == 0);
    28472886
     2887        /* Wait for the surface to finish drawing. */
     2888        dxSurfaceWait(pState, pSurface, pSurface->idAssociatedContext);
     2889
    28482890        ID3D11Texture2D *pMappedTexture;
    28492891        if (enmMapType == VMSVGA3D_SURFACE_MAP_READ)
    28502892        {
    28512893            pMappedTexture = pBackendSurface->pStagingTexture;
    2852 
    2853             /* Wait for the surface to finish drawing. */
    2854             if (pBackendSurface->cidDrawing != SVGA_ID_INVALID)
    2855             {
    2856                 dxContextWait(pBackendSurface->cidDrawing, pState);
    2857                 pBackendSurface->cidDrawing = SVGA_ID_INVALID;
    2858             }
    28592894
    28602895            /* Copy the texture content to the staging texture. */
     
    28982933}
    28992934
     2935        dxSurfaceWait(pState, pSurface, pSurface->idAssociatedContext);
     2936
    29002937        ID3D11Resource *pMappedResource;
    29012938        if (enmMapType == VMSVGA3D_SURFACE_MAP_READ)
     
    29042941                            ? (ID3D11Resource *)pBackendSurface->pStagingTexture3D
    29052942                            : (ID3D11Resource *)pBackendSurface->pStagingTexture;
    2906 
    2907             /* Wait for the surface to finish drawing. */
    2908             if (pBackendSurface->cidDrawing != SVGA_ID_INVALID)
    2909             {
    2910                 dxContextWait(pBackendSurface->cidDrawing, pState);
    2911                 pBackendSurface->cidDrawing = SVGA_ID_INVALID;
    2912             }
    29132943
    29142944            /* Copy the texture content to the staging texture.
     
    32763306
    32773307    /* Wait for the surface to finish drawing. */
    3278     if (pBackendSurface->cidDrawing != SVGA_ID_INVALID)
    3279     {
    3280         dxContextWait(pBackendSurface->cidDrawing, pState);
    3281         pBackendSurface->cidDrawing = SVGA_ID_INVALID;
    3282     }
     3308    dxSurfaceWait(pState, pSurface, DX_CID_BACKEND);
    32833309
    32843310    /* Copy the screen texture to the shared surface. */
     
    39213947
    39223948            /* Wait for the source surface to finish drawing. */
    3923             if (pSrcSurface->pBackendSurface->cidDrawing != SVGA_ID_INVALID)
    3924             {
    3925                 dxContextWait(pSrcSurface->pBackendSurface->cidDrawing, pState);
    3926                 pSrcSurface->pBackendSurface->cidDrawing = SVGA_ID_INVALID;
    3927             }
     3949            dxSurfaceWait(pState, pSrcSurface, DX_CID_BACKEND);
    39283950
    39293951            DXDEVICE *pDXDevice = &pBackend->device;
     
    44164438
    44174439        VMSVGA3D_MAPPED_SURFACE map;
    4418         rc = vmsvga3dBackSurfaceMap(pThisCC, &image, &box, VMSVGA3D_SURFACE_MAP_WRITE, &map);
     4440        rc = vmsvga3dBackSurfaceMap(pThisCC, &image, &box, enmMap, &map);
    44194441        if (RT_SUCCESS(rc))
    44204442        {
     
    48864908
    48874909
     4910static void dxSetupPipeline(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext)
     4911{
     4912    /* Make sure that any draw operations on shader resource views have finished. */
     4913    AssertCompile(RT_ELEMENTS(pDXContext->svgaDXContext.shaderState) == SVGA3D_NUM_SHADERTYPE);
     4914    AssertCompile(RT_ELEMENTS(pDXContext->svgaDXContext.shaderState[0].shaderResources) == SVGA3D_DX_MAX_SRVIEWS);
     4915
     4916    for (uint32_t idxShaderState = 0; idxShaderState < SVGA3D_NUM_SHADERTYPE; ++idxShaderState)
     4917    {
     4918        for (uint32_t idxSR = 0; idxSR < SVGA3D_NUM_SHADERTYPE; ++idxSR)
     4919        {
     4920            SVGA3dShaderResourceViewId const shaderResourceViewId = pDXContext->svgaDXContext.shaderState[idxShaderState].shaderResources[idxSR];
     4921            if (shaderResourceViewId != SVGA3D_INVALID_ID)
     4922            {
     4923                ASSERT_GUEST_RETURN_VOID(shaderResourceViewId < pDXContext->pBackendDXContext->cShaderResourceView);
     4924
     4925                uint32_t const sid = dxGetShaderResourceViewSid(pDXContext, shaderResourceViewId);
     4926
     4927                PVMSVGA3DSURFACE pSurface;
     4928                int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, sid, &pSurface);
     4929                AssertRCReturnVoid(rc);
     4930
     4931                /** @todo The guest might have invalidated the surface. */
     4932                AssertContinue(pSurface->pBackendSurface);
     4933
     4934                /* Wait for the surface to finish drawing. */
     4935                dxSurfaceWait(pThisCC->svga.p3dState, pSurface, pDXContext->cid);
     4936            }
     4937        }
     4938    }
     4939
    48884940#ifdef DX_DEFERRED_SET_RENDER_TARGETS
    4889 static void dxSetupPipeline(PVMSVGA3DDXCONTEXT pDXContext)
    4890 {
    48914941    DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
    48924942    AssertReturnVoid(pDevice->pDevice);
     
    48954945                                                   pDXContext->pBackendDXContext->state.papRenderTargetViews,
    48964946                                                   pDXContext->pBackendDXContext->state.pDepthStencilView);
    4897 }
    48984947#endif
     4948}
    48994949
    49004950
     
    49074957    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    49084958
    4909 #ifdef DX_DEFERRED_SET_RENDER_TARGETS
    4910     dxSetupPipeline(pDXContext);
    4911 #endif
     4959    dxSetupPipeline(pThisCC, pDXContext);
    49124960
    49134961    if (pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN)
     
    51615209    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    51625210
    5163 #ifdef DX_DEFERRED_SET_RENDER_TARGETS
    5164     dxSetupPipeline(pDXContext);
    5165 #endif
     5211    dxSetupPipeline(pThisCC, pDXContext);
    51665212
    51675213    if (pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN)
     
    51885234    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    51895235
    5190 #ifdef DX_DEFERRED_SET_RENDER_TARGETS
    5191     dxSetupPipeline(pDXContext);
    5192 #endif
     5236    dxSetupPipeline(pThisCC, pDXContext);
    51935237
    51945238    Assert(pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN);
     
    52125256    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    52135257
    5214 #ifdef DX_DEFERRED_SET_RENDER_TARGETS
    5215     dxSetupPipeline(pDXContext);
    5216 #endif
     5258    dxSetupPipeline(pThisCC, pDXContext);
    52175259
    52185260    Assert(pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN);
     
    52325274    PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    52335275
    5234 #ifdef DX_DEFERRED_SET_RENDER_TARGETS
    5235     dxSetupPipeline(pDXContext);
    5236 #endif
     5276    dxSetupPipeline(pThisCC, pDXContext);
    52375277
    52385278    RT_NOREF(pBackend, pDXContext);
     
    58865926    ID3D11ShaderResourceView *pShaderResourceView = pDXContext->pBackendDXContext->papShaderResourceView[shaderResourceViewId];
    58875927    AssertReturn(pShaderResourceView, VERR_INVALID_STATE);
     5928
     5929    uint32_t const sid = dxGetShaderResourceViewSid(pDXContext, shaderResourceViewId);
     5930
     5931    PVMSVGA3DSURFACE pSurface;
     5932    int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, sid, &pSurface);
     5933    AssertRCReturn(rc, rc);
     5934    AssertReturn(pSurface->pBackendSurface, VERR_INVALID_STATE);
     5935
    58885936    pDevice->pImmediateContext->GenerateMips(pShaderResourceView);
     5937
     5938    pSurface->pBackendSurface->cidDrawing = pDXContext->cid;
    58895939    return VINF_SUCCESS;
    58905940}
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