Changeset 94101 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Mar 6, 2022 5:43:23 PM (3 years ago)
- Location:
- trunk/src/VBox/Devices/Graphics
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA-internal.h
r93635 r94101 143 143 144 144 # ifdef VBOX_WITH_VMSVGA3D 145 # ifdef VMSVGA3D_DX 146 /** DX context of the currently processed command buffer */ 147 uint32_t idDXContextCurrent; 148 uint32_t u32Reserved; 149 # endif 145 150 VMSVGA3DBACKENDFUNCS3D *pFuncs3D; 146 151 VMSVGA3DBACKENDFUNCSVGPU9 *pFuncsVGPU9; -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA.cpp
r93944 r94101 3442 3442 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State; 3443 3443 3444 # ifdef VBOX_WITH_VMSVGA3D 3445 # ifdef VMSVGA3D_DX 3446 /* Commands submitted for the SVGA3D_INVALID_ID context do not affect pipeline. So ignore them. */ 3447 if (idDXContext != SVGA3D_INVALID_ID) 3448 { 3449 if (pSvgaR3State->idDXContextCurrent != idDXContext) 3450 { 3451 LogFlow(("DXCTX: buffer %d->%d\n", pSvgaR3State->idDXContextCurrent, idDXContext)); 3452 vmsvga3dDXSwitchContext(pThisCC, idDXContext); 3453 pSvgaR3State->idDXContextCurrent = idDXContext; 3454 } 3455 } 3456 # endif 3457 # endif 3458 3444 3459 uint32_t RT_UNTRUSTED_VOLATILE_GUEST * const pFIFO = pThisCC->svga.pau32FIFO; 3445 3460 … … 5812 5827 5813 5828 RTListInit(&pSVGAState->MOBLRUList); 5829 # ifdef VBOX_WITH_VMSVGA3D 5830 # ifdef VMSVGA3D_DX 5831 pSVGAState->idDXContextCurrent = SVGA3D_INVALID_ID; 5832 # endif 5833 # endif 5814 5834 return rc; 5815 5835 } -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx.cpp
r94063 r94101 54 54 /* Copy the host structure back to the guest memory. */ 55 55 memcpy(pSvgaDXContext, &pDXContext->svgaDXContext, sizeof(*pSvgaDXContext)); 56 57 return rc; 58 } 59 60 61 int vmsvga3dDXSwitchContext(PVGASTATECC pThisCC, uint32_t cidNew) 62 { 63 int rc; 64 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State; 65 AssertReturn(pSvgaR3State->pFuncsDX && pSvgaR3State->pFuncsDX->pfnDXSwitchContext, VERR_INVALID_STATE); 66 PVMSVGA3DSTATE p3dState = pThisCC->svga.p3dState; 67 AssertReturn(p3dState, VERR_INVALID_STATE); 68 69 PVMSVGA3DDXCONTEXT pDXContextNew; 70 rc = vmsvga3dDXContextFromCid(p3dState, cidNew, &pDXContextNew); 71 AssertRCReturn(rc, rc); 72 73 /* Notify the host backend that context is about to be switched. */ 74 rc = pSvgaR3State->pFuncsDX->pfnDXSwitchContext(pThisCC, pDXContextNew); 75 if (rc == VINF_NOT_IMPLEMENTED || RT_FAILURE(rc)) 76 return rc; 77 78 /** @todo Keep track of changes in the pipeline and apply only modified state. */ 79 #define DX_STATE_VS 0x00000001 80 #define DX_STATE_PS 0x00000002 81 #define DX_STATE_SAMPLERS 0x00000004 82 #define DX_STATE_INPUTLAYOUT 0x00000008 83 uint32_t u32TrackedState = 0 84 | DX_STATE_VS 85 | DX_STATE_PS 86 | DX_STATE_SAMPLERS 87 | DX_STATE_INPUTLAYOUT 88 ; 89 90 if (u32TrackedState & DX_STATE_VS) 91 { 92 u32TrackedState &= ~DX_STATE_VS; 93 94 SVGA3dShaderType const shaderType = SVGA3D_SHADERTYPE_VS; 95 96 uint32_t const idxShaderState = shaderType - SVGA3D_SHADERTYPE_MIN; 97 SVGA3dShaderId shaderId = pDXContextNew->svgaDXContext.shaderState[idxShaderState].shaderId; 98 99 /** @todo Same code as in DXSetShader, move to a static function with type and id as parms. */ 100 PVMSVGA3DSHADER pShader; 101 if (shaderId != SVGA_ID_INVALID) 102 { 103 SVGACOTableDXShaderEntry *pEntry = &pDXContextNew->cot.paShader[shaderId]; 104 ASSERT_GUEST_RETURN(pEntry->type == shaderType, VERR_INVALID_PARAMETER); 105 RT_UNTRUSTED_VALIDATED_FENCE(); 106 107 pShader = &pDXContextNew->paShader[shaderId]; 108 } 109 else 110 pShader = NULL; 111 112 rc = pSvgaR3State->pFuncsDX->pfnDXSetShader(pThisCC, pDXContextNew, shaderType, pShader); 113 AssertRC(rc); 114 } 115 116 if (u32TrackedState & DX_STATE_PS) 117 { 118 u32TrackedState &= ~DX_STATE_PS; 119 120 SVGA3dShaderType const shaderType = SVGA3D_SHADERTYPE_PS; 121 122 uint32_t const idxShaderState = shaderType - SVGA3D_SHADERTYPE_MIN; 123 SVGA3dShaderId shaderId = pDXContextNew->svgaDXContext.shaderState[idxShaderState].shaderId; 124 125 /** @todo Same code as in DXSetShader, move to a static function with type and id as parms. */ 126 PVMSVGA3DSHADER pShader; 127 if (shaderId != SVGA_ID_INVALID) 128 { 129 SVGACOTableDXShaderEntry *pEntry = &pDXContextNew->cot.paShader[shaderId]; 130 ASSERT_GUEST_RETURN(pEntry->type == shaderType, VERR_INVALID_PARAMETER); 131 RT_UNTRUSTED_VALIDATED_FENCE(); 132 133 pShader = &pDXContextNew->paShader[shaderId]; 134 } 135 else 136 pShader = NULL; 137 138 rc = pSvgaR3State->pFuncsDX->pfnDXSetShader(pThisCC, pDXContextNew, shaderType, pShader); 139 AssertRC(rc); 140 } 141 142 if (u32TrackedState & DX_STATE_SAMPLERS) 143 { 144 u32TrackedState &= ~DX_STATE_SAMPLERS; 145 146 for (int i = SVGA3D_SHADERTYPE_MIN; i < SVGA3D_SHADERTYPE_DX10_MAX; ++i) /** SVGA3D_SHADERTYPE_MAX */ 147 { 148 SVGA3dShaderType const shaderType = (SVGA3dShaderType)i; 149 uint32_t const idxShaderState = shaderType - SVGA3D_SHADERTYPE_MIN; 150 151 uint32_t startSampler = 0; 152 uint32_t cSamplerId = SVGA3D_DX_MAX_SAMPLERS; 153 SVGA3dSamplerId *paSamplerId = &pDXContextNew->svgaDXContext.shaderState[idxShaderState].samplers[0]; 154 155 rc = pSvgaR3State->pFuncsDX->pfnDXSetSamplers(pThisCC, pDXContextNew, startSampler, shaderType, cSamplerId, paSamplerId); 156 AssertRC(rc); 157 } 158 } 159 160 161 if (u32TrackedState & DX_STATE_INPUTLAYOUT) 162 { 163 u32TrackedState &= ~DX_STATE_INPUTLAYOUT; 164 165 SVGA3dElementLayoutId const elementLayoutId = pDXContextNew->svgaDXContext.inputAssembly.layoutId; 166 167 rc = pSvgaR3State->pFuncsDX->pfnDXSetInputLayout(pThisCC, pDXContextNew, elementLayoutId); 168 AssertRC(rc); 169 } 170 171 Assert(u32TrackedState == 0); 56 172 57 173 return rc; … … 263 379 ASSERT_GUEST_RETURN( pCmd->shaderId < pDXContext->cot.cShader 264 380 || pCmd->shaderId == SVGA_ID_INVALID, VERR_INVALID_PARAMETER); 265 RT_UNTRUSTED_VALIDATED_FENCE(); 381 ASSERT_GUEST_RETURN(pCmd->type >= SVGA3D_SHADERTYPE_MIN && pCmd->type < SVGA3D_SHADERTYPE_MAX, VERR_INVALID_PARAMETER); 382 RT_UNTRUSTED_VALIDATED_FENCE(); 383 384 uint32_t const idxShaderState = pCmd->type - SVGA3D_SHADERTYPE_MIN; 385 pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId = pCmd->shaderId; 266 386 267 387 PVMSVGA3DSHADER pShader; … … 298 418 ASSERT_GUEST_RETURN(pCmd->type >= SVGA3D_SHADERTYPE_MIN && pCmd->type < SVGA3D_SHADERTYPE_MAX, VERR_INVALID_PARAMETER); 299 419 ASSERT_GUEST_RETURN(pDXContext->cot.paSampler, VERR_INVALID_STATE); 420 RT_UNTRUSTED_VALIDATED_FENCE(); 421 422 uint32_t const idxShaderState = pCmd->type - SVGA3D_SHADERTYPE_MIN; 300 423 for (uint32_t i = 0; i < cSamplerId; ++i) 301 424 { … … 303 426 ASSERT_GUEST_RETURN( samplerId < pDXContext->cot.cSampler 304 427 || samplerId == SVGA_ID_INVALID, VERR_INVALID_PARAMETER); 428 pDXContext->svgaDXContext.shaderState[idxShaderState].samplers[pCmd->startSampler + i] = samplerId; 305 429 } 306 430 RT_UNTRUSTED_VALIDATED_FENCE(); … … 483 607 ASSERT_GUEST_RETURN(elementLayoutId < pDXContext->cot.cElementLayout, VERR_INVALID_PARAMETER); 484 608 RT_UNTRUSTED_VALIDATED_FENCE(); 609 610 pDXContext->svgaDXContext.inputAssembly.layoutId = elementLayoutId; 485 611 486 612 rc = pSvgaR3State->pFuncsDX->pfnDXSetInputLayout(pThisCC, pDXContext, elementLayoutId); -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp
r94063 r94101 50 50 # define VBOX_D3D11_LIBRARY_NAME "VBoxDxVk" 51 51 #endif 52 53 //#define DX_FORCE_SINGLE_DEVICE 52 54 53 55 /* This is not available on non Windows hosts. */ … … 263 265 PFN_D3D_DISASSEMBLE pfnD3DDisassemble; 264 266 265 /** @todo This device will be used for all rendering for "single DX device" mode. */266 267 DXDEVICE dxDevice; /* Device for the VMSVGA3D context independent operation. */ 268 269 bool fSingleDevice; /* Whether to use one DX device for all guest contexts. */ 270 271 /** @todo Here a set of functions which do different job in single and multiple device modes. */ 267 272 } VMSVGA3DBACKEND; 268 273 … … 787 792 int rc = VINF_SUCCESS; 788 793 794 if (pBackend->fSingleDevice && pBackend->dxDevice.pDevice) 795 { 796 pDevice->pDevice = pBackend->dxDevice.pDevice; 797 pDevice->pDevice->AddRef(); 798 799 pDevice->pImmediateContext = pBackend->dxDevice.pImmediateContext; 800 pDevice->pImmediateContext->AddRef(); 801 802 pDevice->pDxgiFactory = pBackend->dxDevice.pDxgiFactory; 803 pDevice->pDxgiFactory->AddRef(); 804 805 pDevice->FeatureLevel = pBackend->dxDevice.FeatureLevel; 806 807 pDevice->pStagingBuffer = 0; 808 pDevice->cbStagingBuffer = 0; 809 810 return rc; 811 } 812 789 813 IDXGIAdapter *pAdapter = NULL; /* Default adapter. */ 790 814 static D3D_FEATURE_LEVEL const s_aFeatureLevels[] = … … 988 1012 if (cid != DX_CID_BACKEND) 989 1013 { 1014 if (pState->pBackend->fSingleDevice) 1015 return &pState->pBackend->dxDevice; 1016 990 1017 VMSVGA3DDXCONTEXT *pDXContext; 991 1018 int rc = vmsvga3dDXContextFromCid(pState, cid, &pDXContext); … … 1003 1030 static DXDEVICE *dxDeviceFromContext(PVMSVGA3DSTATE p3dState, VMSVGA3DDXCONTEXT *pDXContext) 1004 1031 { 1005 if (pDXContext )1032 if (pDXContext && !p3dState->pBackend->fSingleDevice) 1006 1033 return &pDXContext->pBackendDXContext->dxDevice; 1007 1034 … … 1036 1063 static int dxContextWait(uint32_t cidDrawing, PVMSVGA3DSTATE pState) 1037 1064 { 1065 if (pState->pBackend->fSingleDevice) 1066 return VINF_SUCCESS; 1067 1038 1068 /* Flush cidDrawing context and issue a query. */ 1039 1069 DXDEVICE *pDXDevice = dxDeviceFromCid(cidDrawing, pState); … … 1047 1077 static int dxSurfaceWait(PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface, uint32_t cidRequesting) 1048 1078 { 1079 if (pState->pBackend->fSingleDevice) 1080 return VINF_SUCCESS; 1081 1049 1082 VMSVGA3DBACKENDSURFACE *pBackendSurface = pSurface->pBackendSurface; 1050 1083 if (!pBackendSurface) … … 1076 1109 1077 1110 uint32_t const cidRequesting = pDXContext ? pDXContext->cid : DX_CID_BACKEND; 1078 if (cidRequesting == pSurface->idAssociatedContext )1111 if (cidRequesting == pSurface->idAssociatedContext || pState->pBackend->fSingleDevice) 1079 1112 pResource = pBackendSurface->u.pResource; 1080 1113 else … … 1832 1865 static DXDEVICE *dxSurfaceDevice(PVMSVGA3DSTATE p3dState, PVMSVGA3DSURFACE pSurface, PVMSVGA3DDXCONTEXT pDXContext, UINT *pMiscFlags) 1833 1866 { 1867 if (p3dState->pBackend->fSingleDevice) 1868 { 1869 *pMiscFlags = 0; 1870 return &p3dState->pBackend->dxDevice; 1871 } 1872 1834 1873 if (dxIsSurfaceShareable(pSurface)) 1835 1874 { … … 2220 2259 pBackendSurface->enmDxgiFormat = dxgiFormat; 2221 2260 pSurface->pBackendSurface = pBackendSurface; 2222 if ( RT_BOOL(MiscFlags & D3D11_RESOURCE_MISC_SHARED))2261 if (p3dState->pBackend->fSingleDevice || RT_BOOL(MiscFlags & D3D11_RESOURCE_MISC_SHARED)) 2223 2262 pSurface->idAssociatedContext = DX_CID_BACKEND; 2224 2263 else … … 2806 2845 Log6Func(("Load D3DDisassemble: %Rrc\n", rc2)); 2807 2846 } 2847 2848 #if !defined(RT_OS_WINDOWS) || defined(DX_FORCE_SINGLE_DEVICE) 2849 pBackend->fSingleDevice = true; 2850 #endif 2851 2852 LogRelMax(1, ("VMSVGA: Single DX device mode: %s\n", pBackend->fSingleDevice ? "enabled" : "disabled")); 2853 2808 2854 //DEBUG_BREAKPOINT_TEST(); 2809 2855 return rc; … … 4203 4249 { 4204 4250 /* Create the target if it can be used as a device context shared resource (render or screen target). */ 4205 if ( dxIsSurfaceShareable(pDstSurface))4251 if (pBackend->fSingleDevice || dxIsSurfaceShareable(pDstSurface)) 4206 4252 { 4207 4253 rc = vmsvga3dBackSurfaceCreateTexture(pThisCC, NULL, pDstSurface); … … 5091 5137 5092 5138 5139 static DECLCALLBACK(int) vmsvga3dBackDXSwitchContext(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContextNew) 5140 { 5141 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 5142 if (!pBackend->fSingleDevice) 5143 return VINF_NOT_IMPLEMENTED; /* Not required. */ 5144 5145 /* The new context state will be applied by the generic DX code. */ 5146 RT_NOREF(pDXContextNew); 5147 return VINF_SUCCESS; 5148 } 5149 5150 5093 5151 static DECLCALLBACK(int) vmsvga3dBackDXReadbackContext(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext) 5094 5152 { … … 5228 5286 Assert(pDXShader->pShader); 5229 5287 Assert(pDXShader->enmShaderType >= SVGA3D_SHADERTYPE_MIN && pDXShader->enmShaderType < SVGA3D_SHADERTYPE_MAX); 5230 uint32_t const idxShaderState = pDXShader->enmShaderType - SVGA3D_SHADERTYPE_MIN;5231 pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId = pShader->id;5232 5288 } 5233 5289 else … … 5247 5303 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 5248 5304 5249 uint32_t const idxShaderState = type - SVGA3D_SHADERTYPE_MIN;5250 5305 ID3D11SamplerState *papSamplerState[SVGA3D_DX_MAX_SAMPLERS]; 5251 5306 for (uint32_t i = 0; i < cSamplerId; ++i) … … 5259 5314 else 5260 5315 papSamplerState[i] = NULL; 5261 5262 pDXContext->svgaDXContext.shaderState[idxShaderState].samplers[startSampler + i] = samplerId;5263 5316 } 5264 5317 … … 5722 5775 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 5723 5776 5724 pDXContext->svgaDXContext.inputAssembly.layoutId = elementLayoutId; 5725 5726 DXELEMENTLAYOUT *pDXElementLayout = &pDXContext->pBackendDXContext->paElementLayout[elementLayoutId]; 5727 if (!pDXElementLayout->pElementLayout) 5728 { 5729 uint32_t const idxShaderState = SVGA3D_SHADERTYPE_VS - SVGA3D_SHADERTYPE_MIN; 5730 uint32_t const shid = pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId; 5731 AssertReturnStmt(shid < pDXContext->pBackendDXContext->cShader, 5732 LogRelMax(16, ("VMSVGA: DX shader is not set in DXSetInputLayout: shid = 0x%x\n", shid)), 5733 VERR_INVALID_STATE); 5734 DXSHADER *pDXShader = &pDXContext->pBackendDXContext->paShader[shid]; 5735 AssertReturnStmt(pDXShader->pvDXBC, 5736 LogRelMax(16, ("VMSVGA: DX shader bytecode is not available in DXSetInputLayout: shid = %u\n", shid)), 5737 VERR_INVALID_STATE); 5738 HRESULT hr = pDevice->pDevice->CreateInputLayout(pDXElementLayout->aElementDesc, 5739 pDXElementLayout->cElementDesc, 5740 pDXShader->pvDXBC, 5741 pDXShader->cbDXBC, 5742 &pDXElementLayout->pElementLayout); 5743 AssertReturn(SUCCEEDED(hr), VERR_NO_MEMORY); 5744 } 5745 5746 pDevice->pImmediateContext->IASetInputLayout(pDXElementLayout->pElementLayout); 5777 ID3D11InputLayout *pInputLayout = NULL; 5778 if (elementLayoutId != SVGA3D_INVALID_ID) 5779 { 5780 DXELEMENTLAYOUT *pDXElementLayout = &pDXContext->pBackendDXContext->paElementLayout[elementLayoutId]; 5781 if (!pDXElementLayout->pElementLayout) 5782 { 5783 uint32_t const idxShaderState = SVGA3D_SHADERTYPE_VS - SVGA3D_SHADERTYPE_MIN; 5784 uint32_t const shid = pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId; 5785 AssertReturnStmt(shid < pDXContext->pBackendDXContext->cShader, 5786 LogRelMax(16, ("VMSVGA: DX shader is not set in DXSetInputLayout: shid = 0x%x\n", shid)), 5787 VERR_INVALID_STATE); 5788 DXSHADER *pDXShader = &pDXContext->pBackendDXContext->paShader[shid]; 5789 AssertReturnStmt(pDXShader->pvDXBC, 5790 LogRelMax(16, ("VMSVGA: DX shader bytecode is not available in DXSetInputLayout: shid = %u\n", shid)), 5791 VERR_INVALID_STATE); 5792 HRESULT hr = pDevice->pDevice->CreateInputLayout(pDXElementLayout->aElementDesc, 5793 pDXElementLayout->cElementDesc, 5794 pDXShader->pvDXBC, 5795 pDXShader->cbDXBC, 5796 &pDXElementLayout->pElementLayout); 5797 AssertReturn(SUCCEEDED(hr), VERR_NO_MEMORY); 5798 } 5799 5800 pInputLayout = pDXElementLayout->pElementLayout; 5801 } 5802 5803 pDevice->pImmediateContext->IASetInputLayout(pInputLayout); 5747 5804 return VINF_SUCCESS; 5748 5805 } … … 7748 7805 p->pfnDXDestroyContext = vmsvga3dBackDXDestroyContext; 7749 7806 p->pfnDXBindContext = vmsvga3dBackDXBindContext; 7807 p->pfnDXSwitchContext = vmsvga3dBackDXSwitchContext; 7750 7808 p->pfnDXReadbackContext = vmsvga3dBackDXReadbackContext; 7751 7809 p->pfnDXInvalidateContext = vmsvga3dBackDXInvalidateContext; -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.h
r94063 r94101 396 396 DECLCALLBACKMEMBER(int, pfnDXDestroyContext, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext)); 397 397 DECLCALLBACKMEMBER(int, pfnDXBindContext, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext)); 398 DECLCALLBACKMEMBER(int, pfnDXSwitchContext, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContextNew)); 398 399 DECLCALLBACKMEMBER(int, pfnDXReadbackContext, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext)); 399 400 DECLCALLBACKMEMBER(int, pfnDXInvalidateContext, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext)); … … 520 521 /* Helpers. */ 521 522 int vmsvga3dDXUnbindContext(PVGASTATECC pThisCC, uint32_t cid, SVGADXContextMobFormat *pSvgaDXContext); 523 int vmsvga3dDXSwitchContext(PVGASTATECC pThisCC, uint32_t cidNew); 522 524 523 525 /* Command handlers. */
Note:
See TracChangeset
for help on using the changeset viewer.