Changeset 102622 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Dec 15, 2023 7:24:16 PM (14 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx-dx11.cpp
r102616 r102622 404 404 /* Static function prototypes. */ 405 405 static int dxDeviceFlush(DXDEVICE *pDevice); 406 static int dxDefineShaderResourceView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderResourceViewId shaderResourceViewId, SVGACOTableDXSRViewEntry const *pEntry);407 406 static int dxDefineUnorderedAccessView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dUAViewId uaViewId, SVGACOTableDXUAViewEntry const *pEntry); 408 407 static int dxDefineRenderTargetView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dRenderTargetViewId renderTargetViewId, SVGACOTableDXRTViewEntry const *pEntry); … … 5918 5917 static int dxSetShaderResources(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderType type) 5919 5918 { 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 5924 5922 AssertReturn(type >= SVGA3D_SHADERTYPE_MIN && type < SVGA3D_SHADERTYPE_MAX, VERR_INVALID_PARAMETER); 5923 5925 5924 uint32_t const idxShaderState = type - SVGA3D_SHADERTYPE_MIN; 5926 5925 uint32_t const *pSRIds = &pDXContext->svgaDXContext.shaderState[idxShaderState].shaderResources[0]; … … 5928 5927 for (uint32_t i = 0; i < SVGA3D_DX_MAX_SRVIEWS; ++i) 5929 5928 { 5930 SVGA3dShaderResourceViewId shaderResourceViewId = pSRIds[i];5929 SVGA3dShaderResourceViewId const shaderResourceViewId = pSRIds[i]; 5931 5930 if (shaderResourceViewId != SVGA3D_INVALID_ID) 5932 5931 { … … 5941 5940 } 5942 5941 5943 dxShaderResourceViewSet(pD evice, type, 0, SVGA3D_DX_MAX_SRVIEWS, papShaderResourceView);5942 dxShaderResourceViewSet(pDXDevice, type, 0, SVGA3D_DX_MAX_SRVIEWS, papShaderResourceView); 5944 5943 return VINF_SUCCESS; 5945 5944 } … … 5948 5947 static DECLCALLBACK(int) vmsvga3dBackDXSetShaderResources(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t startView, SVGA3dShaderType type, uint32_t cShaderResourceViewId, SVGA3dShaderResourceViewId const *paShaderResourceViewId) 5949 5948 { 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); 5958 5951 return VINF_SUCCESS; 5959 5952 } … … 6416 6409 break; 6417 6410 } 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 } 6418 6426 case DXGI_FORMAT_R16G16_FLOAT: 6419 6427 { … … 6449 6457 Log8(("{ %u },", 6450 6458 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])); 6451 6466 break; 6452 6467 } … … 6767 6782 6768 6783 6784 static 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 6802 static 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 6769 6817 static void dxSetupPipeline(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext) 6770 6818 { … … 6800 6848 if (shaderResourceViewId != SVGA3D_INVALID_ID) 6801 6849 { 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 6804 6855 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); 6834 6858 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, 6836 6860 pSurface->paMipmapLevels[0].cBlocksX * pSurface->cxBlock, pSurface->paMipmapLevels[0].cBlocksY * pSurface->cyBlock)); 6861 #endif 6837 6862 6838 6863 #ifdef DUMP_BITMAPS 6839 6864 SVGA3dSurfaceImageId image; 6840 image.sid = sid;6865 image.sid = pDXView->sid; 6841 6866 image.face = 0; 6842 6867 image.mipmap = 0; … … 6849 6874 } 6850 6875 else 6851 Log (("Map failed %Rrc\n", rc));6876 LogFunc(("Map failed %Rrc\n", rc)); 6852 6877 #endif 6853 6878 } 6854 6879 } 6855 6880 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)); 6859 6882 } 6860 6883 … … 8891 8914 static DECLCALLBACK(int) vmsvga3dBackDXGenMips(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderResourceViewId shaderResourceViewId) 8892 8915 { 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 8928 static 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 8936 static DECLCALLBACK(int) vmsvga3dBackDXDestroyShaderResourceView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderResourceViewId shaderResourceViewId) 8937 { 8893 8938 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 8894 8939 RT_NOREF(pBackend); 8895 8940 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); 8968 8943 } 8969 8944 … … 9463 9438 for (uint32_t i = 0; i < pBackendDXContext->cShaderResourceView; ++i) 9464 9439 { 9440 /* Destroy the no longer used entries. */ 9465 9441 DXVIEW *pDXView = &pBackendDXContext->paShaderResourceView[i]; 9466 9442 if (i < cValidEntries) … … 9481 9457 continue; /* Skip uninitialized entry. */ 9482 9458 9483 /* Define views which were not defined yet in backend. */9484 9459 DXVIEW *pDXView = &pBackendDXContext->paShaderResourceView[i]; 9485 9460 /** @todo Verify that the pEntry content still corresponds to the view. */ 9486 9461 if (pDXView->u.pView) 9487 9462 dxViewAddToList(pThisCC, pDXView); 9488 else if (pDXView->enmViewType == VMSVGA3D_VIEWTYPE_NONE)9489 dxDefineShaderResourceView(pThisCC, pDXContext, i, pEntry);9490 9463 } 9491 9464 break;
Note:
See TracChangeset
for help on using the changeset viewer.