- Timestamp:
- Oct 1, 2021 9:33:32 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp
r91484 r91504 896 896 897 897 898 static 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 898 920 static ID3D11Resource *dxResource(PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface, VMSVGA3DDXCONTEXT *pDXContext) 899 921 { … … 902 924 AssertFailedReturn(NULL); 903 925 926 ID3D11Resource *pResource; 927 904 928 uint32_t const cidRequesting = pDXContext ? pDXContext->cid : DX_CID_BACKEND; 905 929 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) 937 943 { 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 } 941 967 } 968 969 pResource = pSharedTexture->pTexture; 942 970 } 943 971 944 972 /* 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 979 static 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 988 static 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; 955 994 } 956 995 … … 967 1006 continue; 968 1007 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)); 972 1010 973 1011 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)) 977 1014 { 1015 AssertContinue(pSurface->pBackendSurface); 978 1016 pSurface->pBackendSurface->cidDrawing = pDXContext->cid; 979 1017 } … … 2009 2047 * Success. 2010 2048 */ 2049 LogFunc(("sid = %u\n", pSurface->id)); 2011 2050 pBackendSurface->enmDxgiFormat = dxgiFormat; 2012 2051 pSurface->pBackendSurface = pBackendSurface; … … 2846 2885 Assert(pImage->face == 0 && pImage->mipmap == 0); 2847 2886 2887 /* Wait for the surface to finish drawing. */ 2888 dxSurfaceWait(pState, pSurface, pSurface->idAssociatedContext); 2889 2848 2890 ID3D11Texture2D *pMappedTexture; 2849 2891 if (enmMapType == VMSVGA3D_SURFACE_MAP_READ) 2850 2892 { 2851 2893 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 }2859 2894 2860 2895 /* Copy the texture content to the staging texture. */ … … 2898 2933 } 2899 2934 2935 dxSurfaceWait(pState, pSurface, pSurface->idAssociatedContext); 2936 2900 2937 ID3D11Resource *pMappedResource; 2901 2938 if (enmMapType == VMSVGA3D_SURFACE_MAP_READ) … … 2904 2941 ? (ID3D11Resource *)pBackendSurface->pStagingTexture3D 2905 2942 : (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 }2913 2943 2914 2944 /* Copy the texture content to the staging texture. … … 3276 3306 3277 3307 /* 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); 3283 3309 3284 3310 /* Copy the screen texture to the shared surface. */ … … 3921 3947 3922 3948 /* 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); 3928 3950 3929 3951 DXDEVICE *pDXDevice = &pBackend->device; … … 4416 4438 4417 4439 VMSVGA3D_MAPPED_SURFACE map; 4418 rc = vmsvga3dBackSurfaceMap(pThisCC, &image, &box, VMSVGA3D_SURFACE_MAP_WRITE, &map);4440 rc = vmsvga3dBackSurfaceMap(pThisCC, &image, &box, enmMap, &map); 4419 4441 if (RT_SUCCESS(rc)) 4420 4442 { … … 4886 4908 4887 4909 4910 static 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 4888 4940 #ifdef DX_DEFERRED_SET_RENDER_TARGETS 4889 static void dxSetupPipeline(PVMSVGA3DDXCONTEXT pDXContext)4890 {4891 4941 DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device; 4892 4942 AssertReturnVoid(pDevice->pDevice); … … 4895 4945 pDXContext->pBackendDXContext->state.papRenderTargetViews, 4896 4946 pDXContext->pBackendDXContext->state.pDepthStencilView); 4897 }4898 4947 #endif 4948 } 4899 4949 4900 4950 … … 4907 4957 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 4908 4958 4909 #ifdef DX_DEFERRED_SET_RENDER_TARGETS 4910 dxSetupPipeline(pDXContext); 4911 #endif 4959 dxSetupPipeline(pThisCC, pDXContext); 4912 4960 4913 4961 if (pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN) … … 5161 5209 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 5162 5210 5163 #ifdef DX_DEFERRED_SET_RENDER_TARGETS 5164 dxSetupPipeline(pDXContext); 5165 #endif 5211 dxSetupPipeline(pThisCC, pDXContext); 5166 5212 5167 5213 if (pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN) … … 5188 5234 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 5189 5235 5190 #ifdef DX_DEFERRED_SET_RENDER_TARGETS 5191 dxSetupPipeline(pDXContext); 5192 #endif 5236 dxSetupPipeline(pThisCC, pDXContext); 5193 5237 5194 5238 Assert(pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN); … … 5212 5256 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 5213 5257 5214 #ifdef DX_DEFERRED_SET_RENDER_TARGETS 5215 dxSetupPipeline(pDXContext); 5216 #endif 5258 dxSetupPipeline(pThisCC, pDXContext); 5217 5259 5218 5260 Assert(pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN); … … 5232 5274 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 5233 5275 5234 #ifdef DX_DEFERRED_SET_RENDER_TARGETS 5235 dxSetupPipeline(pDXContext); 5236 #endif 5276 dxSetupPipeline(pThisCC, pDXContext); 5237 5277 5238 5278 RT_NOREF(pBackend, pDXContext); … … 5886 5926 ID3D11ShaderResourceView *pShaderResourceView = pDXContext->pBackendDXContext->papShaderResourceView[shaderResourceViewId]; 5887 5927 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 5888 5936 pDevice->pImmediateContext->GenerateMips(pShaderResourceView); 5937 5938 pSurface->pBackendSurface->cidDrawing = pDXContext->cid; 5889 5939 return VINF_SUCCESS; 5890 5940 }
Note:
See TracChangeset
for help on using the changeset viewer.