VirtualBox

Changeset 102622 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Dec 15, 2023 7:24:16 PM (14 months ago)
Author:
vboxsync
Message:

Devices/Graphics: create shader resource views on demand.

File:
1 edited

Legend:

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

    r102616 r102622  
    404404/* Static function prototypes. */
    405405static int dxDeviceFlush(DXDEVICE *pDevice);
    406 static int dxDefineShaderResourceView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderResourceViewId shaderResourceViewId, SVGACOTableDXSRViewEntry const *pEntry);
    407406static int dxDefineUnorderedAccessView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dUAViewId uaViewId, SVGACOTableDXUAViewEntry const *pEntry);
    408407static int dxDefineRenderTargetView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dRenderTargetViewId renderTargetViewId, SVGACOTableDXRTViewEntry const *pEntry);
     
    59185917static int dxSetShaderResources(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderType type)
    59195918{
    5920     DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    5921     AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    5922 
    5923 //DEBUG_BREAKPOINT_TEST();
     5919    DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
     5920    AssertReturn(pDXDevice->pDevice, VERR_INVALID_STATE);
     5921
    59245922    AssertReturn(type >= SVGA3D_SHADERTYPE_MIN && type < SVGA3D_SHADERTYPE_MAX, VERR_INVALID_PARAMETER);
     5923
    59255924    uint32_t const idxShaderState = type - SVGA3D_SHADERTYPE_MIN;
    59265925    uint32_t const *pSRIds = &pDXContext->svgaDXContext.shaderState[idxShaderState].shaderResources[0];
     
    59285927    for (uint32_t i = 0; i < SVGA3D_DX_MAX_SRVIEWS; ++i)
    59295928    {
    5930         SVGA3dShaderResourceViewId shaderResourceViewId = pSRIds[i];
     5929        SVGA3dShaderResourceViewId const shaderResourceViewId = pSRIds[i];
    59315930        if (shaderResourceViewId != SVGA3D_INVALID_ID)
    59325931        {
     
    59415940    }
    59425941
    5943     dxShaderResourceViewSet(pDevice, type, 0, SVGA3D_DX_MAX_SRVIEWS, papShaderResourceView);
     5942    dxShaderResourceViewSet(pDXDevice, type, 0, SVGA3D_DX_MAX_SRVIEWS, papShaderResourceView);
    59445943    return VINF_SUCCESS;
    59455944}
     
    59485947static DECLCALLBACK(int) vmsvga3dBackDXSetShaderResources(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t startView, SVGA3dShaderType type, uint32_t cShaderResourceViewId, SVGA3dShaderResourceViewId const *paShaderResourceViewId)
    59495948{
    5950     PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    5951     RT_NOREF(pBackend);
    5952 
    5953     DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    5954     AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    5955 
    5956     RT_NOREF(startView, type, cShaderResourceViewId, paShaderResourceViewId);
    5957 
     5949    /* Shader resources will be set in setupPipeline. */
     5950    RT_NOREF(pThisCC, pDXContext, startView, type, cShaderResourceViewId, paShaderResourceViewId);
    59585951    return VINF_SUCCESS;
    59595952}
     
    64166409            break;
    64176410        }
     6411        case DXGI_FORMAT_R32_FLOAT:
     6412        {
     6413            float const *pValues = (float const *)pvElementData;
     6414            Log8(("{ " FLOAT_FMT_STR " },",
     6415                 FLOAT_FMT_ARGS(pValues[0])));
     6416            break;
     6417        }
     6418        case DXGI_FORMAT_R16G16B16A16_FLOAT:
     6419        {
     6420            uint16_t const *pValues = (uint16_t const *)pvElementData;
     6421            Log8(("{ /*f16*/ " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR " },",
     6422                 FLOAT_FMT_ARGS(float16ToFloat(pValues[0])), FLOAT_FMT_ARGS(float16ToFloat(pValues[1])),
     6423                 FLOAT_FMT_ARGS(float16ToFloat(pValues[2])), FLOAT_FMT_ARGS(float16ToFloat(pValues[3]))));
     6424            break;
     6425        }
    64186426        case DXGI_FORMAT_R16G16_FLOAT:
    64196427        {
     
    64496457            Log8(("{ %u },",
    64506458                 pValues[0]));
     6459            break;
     6460        }
     6461        case DXGI_FORMAT_R16G16B16A16_SINT:
     6462        {
     6463            int16_t const *pValues = (int16_t const *)pvElementData;
     6464            Log8(("{ /*s16*/ %d, %d, %d, %d },",
     6465                 pValues[0], pValues[1], pValues[2], pValues[3]));
    64516466            break;
    64526467        }
     
    67676782
    67686783
     6784static int dxCreateShaderResourceView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderResourceViewId shaderResourceViewId, SVGACOTableDXSRViewEntry const *pEntry)
     6785{
     6786    PVMSVGA3DSURFACE pSurface;
     6787    ID3D11Resource *pResource;
     6788    int rc = dxEnsureResource(pThisCC, pDXContext, pEntry->sid, &pSurface, &pResource);
     6789    AssertRCReturn(rc, rc);
     6790
     6791    DXVIEW *pView = &pDXContext->pBackendDXContext->paShaderResourceView[shaderResourceViewId];
     6792    Assert(pView->u.pView == NULL);
     6793
     6794    ID3D11ShaderResourceView *pShaderResourceView;
     6795    HRESULT hr = dxShaderResourceViewCreate(pThisCC, pDXContext, pEntry, pSurface, &pShaderResourceView);
     6796    AssertReturn(SUCCEEDED(hr), VERR_INVALID_STATE);
     6797
     6798    return dxViewInit(pView, pSurface, pDXContext, shaderResourceViewId, VMSVGA3D_VIEWTYPE_SHADERRESOURCE, pShaderResourceView);
     6799}
     6800
     6801
     6802static int dxEnsureShaderResourceView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderResourceViewId viewId, DXVIEW **ppResult)
     6803{
     6804    ASSERT_GUEST_RETURN(viewId < pDXContext->cot.cSRView, VERR_INVALID_PARAMETER);
     6805
     6806    DXVIEW *pDXView = &pDXContext->pBackendDXContext->paShaderResourceView[viewId];
     6807    if (!pDXView->u.pView)
     6808    {
     6809        SVGACOTableDXSRViewEntry const *pEntry = &pDXContext->cot.paSRView[viewId];
     6810        int rc = dxCreateShaderResourceView(pThisCC, pDXContext, viewId, pEntry);
     6811        AssertRCReturn(rc, rc);
     6812    }
     6813    *ppResult = pDXView;
     6814    return VINF_SUCCESS;
     6815}
     6816
    67696817static void dxSetupPipeline(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext)
    67706818{
     
    68006848            if (shaderResourceViewId != SVGA3D_INVALID_ID)
    68016849            {
    6802                 ASSERT_GUEST_RETURN_VOID(shaderResourceViewId < pDXContext->pBackendDXContext->cShaderResourceView);
    6803 
     6850                DXVIEW *pDXView;
     6851                rc = dxEnsureShaderResourceView(pThisCC, pDXContext, shaderResourceViewId, &pDXView);
     6852                AssertContinue(RT_SUCCESS(rc));
     6853
     6854#ifdef LOG_ENABLED
    68046855                SVGACOTableDXSRViewEntry const *pSRViewEntry = dxGetShaderResourceViewEntry(pDXContext, shaderResourceViewId);
    6805                 AssertContinue(pSRViewEntry != NULL);
    6806 
    6807                 uint32_t const sid = pSRViewEntry->sid;
    6808 
    6809                 PVMSVGA3DSURFACE pSurface;
    6810                 rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, sid, &pSurface);
    6811                 if (RT_FAILURE(rc))
    6812                 {
    6813                     AssertMsgFailed(("sid = %u, rc = %Rrc\n", sid, rc));
    6814                     continue;
    6815                 }
    6816 
    6817                 /* The guest might have invalidated the surface in which case pSurface->pBackendSurface is NULL. */
    6818                 /** @todo This is not needed for "single DX device" mode. */
    6819                 if (pSurface->pBackendSurface)
    6820                 {
    6821                     /* Wait for the surface to finish drawing. */
    6822                     dxSurfaceWait(pThisCC->svga.p3dState, pSurface, pDXContext->cid);
    6823                 }
    6824 
    6825                 /* If a view has not been created yet, do it now. */
    6826                 if (!pDXContext->pBackendDXContext->paShaderResourceView[shaderResourceViewId].u.pView)
    6827                 {
    6828 //DEBUG_BREAKPOINT_TEST();
    6829                     LogFunc(("Re-creating SRV: sid=%u srvid = %u\n", sid, shaderResourceViewId));
    6830                     rc = dxDefineShaderResourceView(pThisCC, pDXContext, shaderResourceViewId, pSRViewEntry);
    6831                     AssertContinue(RT_SUCCESS(rc));
    6832                 }
    6833 
     6856                PVMSVGA3DSURFACE pSurface = NULL;
     6857                vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, pDXView->sid, &pSurface);
    68346858                LogFunc(("srv[%d][%d] sid = %u, srvid = %u, format = %s(%d), %dx%d\n",
    6835                          idxShaderState, idxSR, sid, shaderResourceViewId, vmsvgaLookupEnum((int)pSRViewEntry->format, &g_SVGA3dSurfaceFormat2String), pSRViewEntry->format,
     6859                         idxShaderState, idxSR, pDXView->sid, shaderResourceViewId, vmsvgaLookupEnum((int)pSRViewEntry->format, &g_SVGA3dSurfaceFormat2String), pSRViewEntry->format,
    68366860                         pSurface->paMipmapLevels[0].cBlocksX * pSurface->cxBlock, pSurface->paMipmapLevels[0].cBlocksY * pSurface->cyBlock));
     6861#endif
    68376862
    68386863#ifdef DUMP_BITMAPS
    68396864                SVGA3dSurfaceImageId image;
    6840                 image.sid = sid;
     6865                image.sid = pDXView->sid;
    68416866                image.face = 0;
    68426867                image.mipmap = 0;
     
    68496874                }
    68506875                else
    6851                     Log(("Map failed %Rrc\n", rc));
     6876                    LogFunc(("Map failed %Rrc\n", rc));
    68526877#endif
    68536878            }
    68546879        }
    68556880
    6856         /* Set shader resources. */
    6857         rc = dxSetShaderResources(pThisCC, pDXContext, (SVGA3dShaderType)(idxShaderState + SVGA3D_SHADERTYPE_MIN));
    6858         AssertRC(rc);
     6881        dxSetShaderResources(pThisCC, pDXContext, (SVGA3dShaderType)(idxShaderState + SVGA3D_SHADERTYPE_MIN));
    68596882    }
    68606883
     
    88918914static DECLCALLBACK(int) vmsvga3dBackDXGenMips(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderResourceViewId shaderResourceViewId)
    88928915{
     8916    DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
     8917    AssertReturn(pDXDevice->pDevice, VERR_INVALID_STATE);
     8918
     8919    DXVIEW *pDXView;
     8920    int rc = dxEnsureShaderResourceView(pThisCC, pDXContext, shaderResourceViewId, &pDXView);
     8921    AssertRCReturn(rc, rc);
     8922
     8923    pDXDevice->pImmediateContext->GenerateMips(pDXView->u.pShaderResourceView);
     8924    return VINF_SUCCESS;
     8925}
     8926
     8927
     8928static DECLCALLBACK(int) vmsvga3dBackDXDefineShaderResourceView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderResourceViewId shaderResourceViewId, SVGACOTableDXSRViewEntry const *pEntry)
     8929{
     8930    /* The view is created when it is used in setupPipeline. */
     8931    RT_NOREF(pThisCC, pDXContext, shaderResourceViewId, pEntry);
     8932    return VINF_SUCCESS;
     8933}
     8934
     8935
     8936static DECLCALLBACK(int) vmsvga3dBackDXDestroyShaderResourceView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderResourceViewId shaderResourceViewId)
     8937{
    88938938    PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    88948939    RT_NOREF(pBackend);
    88958940
    8896     DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    8897     AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    8898 
    8899     ID3D11ShaderResourceView *pShaderResourceView = pDXContext->pBackendDXContext->paShaderResourceView[shaderResourceViewId].u.pShaderResourceView;
    8900     AssertReturn(pShaderResourceView, VERR_INVALID_STATE);
    8901 
    8902     SVGACOTableDXSRViewEntry const *pSRViewEntry = dxGetShaderResourceViewEntry(pDXContext, shaderResourceViewId);
    8903     AssertReturn(pSRViewEntry, VERR_INVALID_STATE);
    8904 
    8905     uint32_t const sid = pSRViewEntry->sid;
    8906 
    8907     PVMSVGA3DSURFACE pSurface;
    8908     int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, sid, &pSurface);
    8909     AssertRCReturn(rc, rc);
    8910     AssertReturn(pSurface->pBackendSurface, VERR_INVALID_STATE);
    8911 
    8912     pDevice->pImmediateContext->GenerateMips(pShaderResourceView);
    8913 
    8914     pSurface->pBackendSurface->cidDrawing = pDXContext->cid;
    8915     return VINF_SUCCESS;
    8916 }
    8917 
    8918 
    8919 static int dxDefineShaderResourceView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderResourceViewId shaderResourceViewId, SVGACOTableDXSRViewEntry const *pEntry)
    8920 {
    8921     /* Get corresponding resource for pEntry->sid. Create the surface if does not yet exist. */
    8922     PVMSVGA3DSURFACE pSurface;
    8923     int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, pEntry->sid, &pSurface);
    8924     AssertRCReturn(rc, rc);
    8925 
    8926     ID3D11ShaderResourceView *pShaderResourceView;
    8927     DXVIEW *pView = &pDXContext->pBackendDXContext->paShaderResourceView[shaderResourceViewId];
    8928     Assert(pView->u.pView == NULL);
    8929 
    8930     if (pSurface->pBackendSurface == NULL)
    8931     {
    8932         /* Create the actual texture or buffer. */
    8933         /** @todo One function to create all resources from surfaces. */
    8934         if (pSurface->format != SVGA3D_BUFFER)
    8935             rc = vmsvga3dBackSurfaceCreateTexture(pThisCC, pDXContext, pSurface);
    8936         else
    8937             rc = vmsvga3dBackSurfaceCreateResource(pThisCC, pDXContext, pSurface);
    8938 
    8939         AssertRCReturn(rc, rc);
    8940     }
    8941 
    8942     HRESULT hr = dxShaderResourceViewCreate(pThisCC, pDXContext, pEntry, pSurface, &pShaderResourceView);
    8943     AssertReturn(SUCCEEDED(hr), VERR_INVALID_STATE);
    8944 
    8945     return dxViewInit(pView, pSurface, pDXContext, shaderResourceViewId, VMSVGA3D_VIEWTYPE_SHADERRESOURCE, pShaderResourceView);
    8946 }
    8947 
    8948 
    8949 static DECLCALLBACK(int) vmsvga3dBackDXDefineShaderResourceView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderResourceViewId shaderResourceViewId, SVGACOTableDXSRViewEntry const *pEntry)
    8950 {
    8951     PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    8952     RT_NOREF(pBackend);
    8953 
    8954     DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    8955     AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    8956 
    8957     /** @todo Probably not necessary because SRVs are defined in setupPipeline. */
    8958     return dxDefineShaderResourceView(pThisCC, pDXContext, shaderResourceViewId, pEntry);
    8959 }
    8960 
    8961 
    8962 static DECLCALLBACK(int) vmsvga3dBackDXDestroyShaderResourceView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderResourceViewId shaderResourceViewId)
    8963 {
    8964     PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    8965     RT_NOREF(pBackend);
    8966 
    8967     return dxViewDestroy(&pDXContext->pBackendDXContext->paShaderResourceView[shaderResourceViewId]);
     8941    DXVIEW *pDXView = &pDXContext->pBackendDXContext->paShaderResourceView[shaderResourceViewId];
     8942    return dxViewDestroy(pDXView);
    89688943}
    89698944
     
    94639438                for (uint32_t i = 0; i < pBackendDXContext->cShaderResourceView; ++i)
    94649439                {
     9440                    /* Destroy the no longer used entries. */
    94659441                    DXVIEW *pDXView = &pBackendDXContext->paShaderResourceView[i];
    94669442                    if (i < cValidEntries)
     
    94819457                    continue; /* Skip uninitialized entry. */
    94829458
    9483                 /* Define views which were not defined yet in backend. */
    94849459                DXVIEW *pDXView = &pBackendDXContext->paShaderResourceView[i];
    94859460                /** @todo Verify that the pEntry content still corresponds to the view. */
    94869461                if (pDXView->u.pView)
    94879462                    dxViewAddToList(pThisCC, pDXView);
    9488                 else if (pDXView->enmViewType == VMSVGA3D_VIEWTYPE_NONE)
    9489                     dxDefineShaderResourceView(pThisCC, pDXContext, i, pEntry);
    94909463            }
    94919464            break;
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