Changeset 94146 in vbox
- Timestamp:
- Mar 9, 2022 12:07:30 PM (3 years ago)
- Location:
- trunk/src/VBox/Devices/Graphics
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA-cmd.cpp
r93944 r94146 1506 1506 else 1507 1507 rc = vmsvgaR3GboRead(pSvgaR3State, &pMob->Gbo, offMob, pu8Map, dims.cbRow); 1508 if (RT_FAILURE(rc)) 1509 break; 1508 AssertRCBreak(rc); 1510 1509 1511 1510 pu8Map += map.cbRowPitch; -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx-shader.cpp
r93115 r94146 1937 1937 while (dxbcTokenReaderCanRead(r, 1)) 1938 1938 { 1939 uint32_t const offOpcode = dxbcByteWriterSize(w); 1940 1939 1941 VGPUOpcode opcode; 1940 1942 rc = dxbcParseOpcode(r, &opcode); … … 1946 1948 if (pInfo) 1947 1949 { 1950 /* Remember offsets of DCL_RESOURCE instructions. */ 1951 if ( outctx.programToken.programType == VGPU10_PIXEL_SHADER 1952 && opcode.opcodeType == VGPU10_OPCODE_DCL_RESOURCE) 1953 { 1954 ASSERT_GUEST_STMT_BREAK(pInfo->cDclResource <= SVGA3D_DX_MAX_SRVIEWS, 1955 rc = VERR_NOT_SUPPORTED); 1956 1957 pInfo->aOffDclResource[pInfo->cDclResource++] = offOpcode; 1958 } 1959 1948 1960 /* Fetch signatures. */ 1949 1961 SVGA3dDXSignatureEntry *pSignatureEntry = NULL; … … 2353 2365 } 2354 2366 2367 int DXShaderUpdateResourceTypes(DXShaderInfo const *pInfo, SVGA3dResourceType *paResourceType, uint32_t cResourceType) 2368 { 2369 for (uint32_t i = 0; i < pInfo->cDclResource; ++i) 2370 { 2371 SVGA3dResourceType const resourceType = i < cResourceType ? paResourceType[i] : SVGA3D_RESOURCE_TEXTURE2D; 2372 AssertContinue(resourceType < SVGA3D_RESOURCE_TYPE_MAX); 2373 2374 uint32_t const offToken = pInfo->aOffDclResource[i]; 2375 AssertContinue(offToken < pInfo->cbBytecode); 2376 uint32_t *paToken = (uint32_t *)((uintptr_t)pInfo->pvBytecode + offToken); 2377 2378 uint8_t resourceDimension; 2379 uint32_t returnType; 2380 switch (resourceType) 2381 { 2382 case SVGA3D_RESOURCE_BUFFER: 2383 resourceDimension = VGPU10_RESOURCE_DIMENSION_BUFFER; 2384 returnType = 0x5555; /* float */ 2385 break; 2386 case SVGA3D_RESOURCE_TEXTURE1D: 2387 resourceDimension = VGPU10_RESOURCE_DIMENSION_TEXTURE1D; 2388 returnType = 0x5555; /* float */ 2389 break; 2390 default: 2391 case SVGA3D_RESOURCE_TEXTURE2D: 2392 resourceDimension = VGPU10_RESOURCE_DIMENSION_TEXTURE2D; 2393 returnType = 0x5555; /* float */ 2394 break; 2395 case SVGA3D_RESOURCE_TEXTURE3D: 2396 resourceDimension = VGPU10_RESOURCE_DIMENSION_TEXTURE3D; 2397 returnType = 0x5555; /* float */ 2398 break; 2399 case SVGA3D_RESOURCE_TEXTURECUBE: 2400 resourceDimension = VGPU10_RESOURCE_DIMENSION_TEXTURECUBE; 2401 returnType = 0x5555; /* float */ 2402 break; 2403 case SVGA3D_RESOURCE_BUFFEREX: 2404 resourceDimension = VGPU10_RESOURCE_DIMENSION_BUFFER; 2405 returnType = 0x5555; /* float */ 2406 break; 2407 } 2408 2409 VGPU10OpcodeToken0 *pOpcode = (VGPU10OpcodeToken0 *)&paToken[0]; 2410 pOpcode->resourceDimension = resourceDimension; 2411 // paToken[1] unmodified 2412 // paToken[2] unmodified 2413 paToken[3] = returnType; 2414 } 2415 2416 return VINF_SUCCESS; 2417 } 2355 2418 2356 2419 #ifdef DXBC_STANDALONE_TEST -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx-shader.h
r93115 r94146 43 43 uint32_t cOutputSignature; 44 44 uint32_t cPatchConstantSignature; 45 uint32_t cDclResource; 45 46 SVGA3dDXSignatureEntry aInputSignature[32]; 46 47 SVGA3dDXSignatureEntry aOutputSignature[32]; 47 48 SVGA3dDXSignatureEntry aPatchConstantSignature[32]; 49 uint32_t aOffDclResource[SVGA3D_DX_MAX_SRVIEWS]; 48 50 } DXShaderInfo; 49 51 50 52 int DXShaderParse(void const *pvCode, uint32_t cbCode, DXShaderInfo *pInfo); 51 53 void DXShaderFree(DXShaderInfo *pInfo); 54 int DXShaderUpdateResourceTypes(DXShaderInfo const *pInfo, SVGA3dResourceType *paResourceType, uint32_t cResourceType); 52 55 int DXShaderCreateDXBC(DXShaderInfo const *pInfo, void **ppvDXBC, uint32_t *pcbDXBC); 53 56 char const *DXShaderGetOutputSemanticName(DXShaderInfo const *pInfo, uint32_t idxRegister); -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx.cpp
r94113 r94146 38 38 #include "DevVGA-SVGA3d-internal.h" 39 39 #include "DevVGA-SVGA-internal.h" 40 41 42 /*43 *44 * 3D backend entry points. These functions are used from vmsvga3dDXSwitchContext and command handlers.45 *46 */47 48 static int dxSetShader(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext,49 SVGA3dShaderType shaderType, SVGA3dShaderId shaderId)50 {51 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;52 53 PVMSVGA3DSHADER pShader;54 if (shaderId != SVGA_ID_INVALID)55 {56 SVGACOTableDXShaderEntry *pEntry = &pDXContext->cot.paShader[shaderId];57 ASSERT_GUEST_RETURN(pEntry->type == shaderType, VERR_INVALID_PARAMETER);58 RT_UNTRUSTED_VALIDATED_FENCE();59 60 pShader = &pDXContext->paShader[shaderId];61 }62 else63 pShader = NULL;64 65 return pSvgaR3State->pFuncsDX->pfnDXSetShader(pThisCC, pDXContext, shaderType, pShader);66 }67 40 68 41 … … 158 131 SVGA3dShaderId shaderId = pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId; 159 132 160 rc = dxSetShader(pThisCC, pDXContext, shaderType, shaderId);133 rc = pSvgaR3State->pFuncsDX->pfnDXSetShader(pThisCC, pDXContext, shaderId, shaderType); 161 134 AssertRC(rc); 162 135 } … … 172 145 SVGA3dShaderId shaderId = pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId; 173 146 174 rc = dxSetShader(pThisCC, pDXContext, shaderType, shaderId);147 rc = pSvgaR3State->pFuncsDX->pfnDXSetShader(pThisCC, pDXContext, shaderId, shaderType); 175 148 AssertRC(rc); 176 149 } … … 186 159 SVGA3dShaderId shaderId = pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId; 187 160 188 rc = dxSetShader(pThisCC, pDXContext, shaderType, shaderId);161 rc = pSvgaR3State->pFuncsDX->pfnDXSetShader(pThisCC, pDXContext, shaderId, shaderType); 189 162 AssertRC(rc); 190 163 } … … 605 578 pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId = pCmd->shaderId; 606 579 607 rc = dxSetShader(pThisCC, pDXContext, pCmd->type, pCmd->shaderId);580 rc = pSvgaR3State->pFuncsDX->pfnDXSetShader(pThisCC, pDXContext, pCmd->shaderId, pCmd->type); 608 581 return rc; 609 582 } … … 1172 1145 AssertRCReturn(rc, rc); 1173 1146 1174 ASSERT_GUEST_RETURN(cViewport < SVGA3D_DX_MAX_VIEWPORTS, VERR_INVALID_PARAMETER);1147 ASSERT_GUEST_RETURN(cViewport <= SVGA3D_DX_MAX_VIEWPORTS, VERR_INVALID_PARAMETER); 1175 1148 RT_UNTRUSTED_VALIDATED_FENCE(); 1176 1149 … … 1196 1169 AssertRCReturn(rc, rc); 1197 1170 1198 ASSERT_GUEST_RETURN(cRect < SVGA3D_DX_MAX_SCISSORRECTS, VERR_INVALID_PARAMETER);1171 ASSERT_GUEST_RETURN(cRect <= SVGA3D_DX_MAX_SCISSORRECTS, VERR_INVALID_PARAMETER); 1199 1172 RT_UNTRUSTED_VALIDATED_FENCE(); 1200 1173 … … 1791 1764 AssertRCReturn(rc, rc); 1792 1765 1793 AssertReturn(pDXContext->paShader, VERR_INVALID_STATE);1794 1795 1766 SVGA3dShaderId const shaderId = pCmd->shaderId; 1796 1767 … … 1800 1771 ASSERT_GUEST_RETURN(pCmd->sizeInBytes >= 8, VERR_INVALID_PARAMETER); /* Version Token + Length Token. */ 1801 1772 RT_UNTRUSTED_VALIDATED_FENCE(); 1773 1774 /* Cleanup the current shader. */ 1775 pSvgaR3State->pFuncsDX->pfnDXDestroyShader(pThisCC, pDXContext, shaderId); 1802 1776 1803 1777 SVGACOTableDXShaderEntry *pEntry = &pDXContext->cot.paShader[shaderId]; … … 1807 1781 pEntry->mobid = SVGA_ID_INVALID; 1808 1782 1809 PVMSVGA3DSHADER pShader = &pDXContext->paShader[shaderId];1810 if (pShader->id != SVGA_ID_INVALID)1811 {1812 /* Cleanup the current shader. */1813 pSvgaR3State->pFuncsDX->pfnDXDestroyShader(pThisCC, pDXContext, shaderId);1814 RTMemFree(pShader->pShaderProgram);1815 }1816 1817 pShader->id = shaderId;1818 pShader->cid = idDXContext;1819 pShader->type = pEntry->type;1820 pShader->cbData = pEntry->sizeInBytes;1821 pShader->pShaderProgram = NULL;1822 pShader->u.pvBackendShader = NULL;1823 1824 1783 rc = pSvgaR3State->pFuncsDX->pfnDXDefineShader(pThisCC, pDXContext, shaderId, pEntry); 1825 1784 return rc; … … 1838 1797 rc = vmsvga3dDXContextFromCid(p3dState, idDXContext, &pDXContext); 1839 1798 AssertRCReturn(rc, rc); 1840 1841 AssertReturn(pDXContext->paShader, VERR_INVALID_STATE);1842 1799 1843 1800 SVGA3dShaderId const shaderId = pCmd->shaderId; … … 1847 1804 RT_UNTRUSTED_VALIDATED_FENCE(); 1848 1805 1849 rc =pSvgaR3State->pFuncsDX->pfnDXDestroyShader(pThisCC, pDXContext, shaderId);1806 pSvgaR3State->pFuncsDX->pfnDXDestroyShader(pThisCC, pDXContext, shaderId); 1850 1807 1851 1808 /* Cleanup COTable entries.*/ … … 1857 1814 1858 1815 /** @todo Destroy shaders on context and backend deletion. */ 1859 PVMSVGA3DSHADER pShader = &pDXContext->paShader[shaderId]; 1860 DXShaderFree(&pShader->shaderInfo); 1861 pShader->id = SVGA_ID_INVALID; 1862 pShader->cid = SVGA_ID_INVALID; 1863 pShader->type = SVGA3D_SHADERTYPE_INVALID; 1864 pShader->cbData = 0; 1865 RTMemFree(pShader->pShaderProgram); 1866 pShader->pShaderProgram = NULL; 1867 pShader->u.pvBackendShader = NULL; 1868 1869 return rc; 1870 } 1871 1872 1873 static int dxBindShader(PVMSVGA3DSHADER pShader, PVMSVGAMOB pMob, SVGACOTableDXShaderEntry const *pEntry, void const *pvShaderBytecode) 1816 return rc; 1817 } 1818 1819 1820 static int dxBindShader(DXShaderInfo *pShaderInfo, PVMSVGAMOB pMob, SVGACOTableDXShaderEntry const *pEntry, void const *pvShaderBytecode) 1874 1821 { 1875 1822 /* How many bytes the MOB can hold. */ … … 1878 1825 AssertReturn(pEntry->sizeInBytes >= 8, VERR_INTERNAL_ERROR); /* Host ensures this in DefineShader. */ 1879 1826 1880 int rc = DXShaderParse(pvShaderBytecode, pEntry->sizeInBytes, &pShader->shaderInfo);1827 int rc = DXShaderParse(pvShaderBytecode, pEntry->sizeInBytes, pShaderInfo); 1881 1828 if (RT_SUCCESS(rc)) 1882 1829 { … … 1886 1833 ASSERT_GUEST_RETURN(cToken <= pEntry->sizeInBytes / 4, VERR_INVALID_PARAMETER); 1887 1834 1888 pShader->cbData = cToken * 4;1889 1890 1835 /* Check if the MOB contains SVGA3dDXSignatureHeader and signature entries. 1891 1836 * If they are not there (Linux guest driver does not provide them), then it is fine 1892 1837 * and the signatures generated by DXShaderParse will be used. 1893 1838 */ 1894 uint32_t const cbSignaturesMax = cbMob - pShader->cbData; /* How many bytes for signatures are available. */1839 uint32_t const cbSignaturesMax = cbMob - cToken * 4; /* How many bytes for signatures are available. */ 1895 1840 if (cbSignaturesMax > sizeof(SVGA3dDXSignatureHeader)) 1896 1841 { 1897 SVGA3dDXSignatureHeader const *pSignatureHeader = (SVGA3dDXSignatureHeader *)((uint8_t *)pvShaderBytecode + pShader->cbData);1842 SVGA3dDXSignatureHeader const *pSignatureHeader = (SVGA3dDXSignatureHeader *)((uint8_t *)pvShaderBytecode + cToken * 4); 1898 1843 if (pSignatureHeader->headerVersion == SVGADX_SIGNATURE_HEADER_VERSION_0) 1899 1844 { 1900 1845 DEBUG_BREAKPOINT_TEST(); 1901 ASSERT_GUEST_RETURN( pSignatureHeader->numInputSignatures <= RT_ELEMENTS(pShader ->shaderInfo.aInputSignature)1902 && pSignatureHeader->numOutputSignatures <= RT_ELEMENTS(pShader ->shaderInfo.aOutputSignature)1903 && pSignatureHeader->numPatchConstantSignatures <= RT_ELEMENTS(pShader ->shaderInfo.aPatchConstantSignature),1846 ASSERT_GUEST_RETURN( pSignatureHeader->numInputSignatures <= RT_ELEMENTS(pShaderInfo->aInputSignature) 1847 && pSignatureHeader->numOutputSignatures <= RT_ELEMENTS(pShaderInfo->aOutputSignature) 1848 && pSignatureHeader->numPatchConstantSignatures <= RT_ELEMENTS(pShaderInfo->aPatchConstantSignature), 1904 1849 VERR_INVALID_PARAMETER); 1905 1850 … … 1912 1857 /* Copy to DXShaderInfo. */ 1913 1858 uint8_t const *pu8Signatures = (uint8_t *)&pSignatureHeader[1]; 1914 pShader ->shaderInfo.cInputSignature = pSignatureHeader->numInputSignatures;1915 memcpy(pShader ->shaderInfo.aInputSignature, pu8Signatures, pSignatureHeader->numInputSignatures * sizeof(SVGA3dDXSignatureEntry));1859 pShaderInfo->cInputSignature = pSignatureHeader->numInputSignatures; 1860 memcpy(pShaderInfo->aInputSignature, pu8Signatures, pSignatureHeader->numInputSignatures * sizeof(SVGA3dDXSignatureEntry)); 1916 1861 1917 1862 pu8Signatures += pSignatureHeader->numInputSignatures * sizeof(SVGA3dDXSignatureEntry); 1918 pShader ->shaderInfo.cOutputSignature = pSignatureHeader->numOutputSignatures;1919 memcpy(pShader ->shaderInfo.aOutputSignature, pu8Signatures, pSignatureHeader->numOutputSignatures * sizeof(SVGA3dDXSignatureEntry));1863 pShaderInfo->cOutputSignature = pSignatureHeader->numOutputSignatures; 1864 memcpy(pShaderInfo->aOutputSignature, pu8Signatures, pSignatureHeader->numOutputSignatures * sizeof(SVGA3dDXSignatureEntry)); 1920 1865 1921 1866 pu8Signatures += pSignatureHeader->numOutputSignatures * sizeof(SVGA3dDXSignatureEntry); 1922 pShader ->shaderInfo.cPatchConstantSignature = pSignatureHeader->numPatchConstantSignatures;1923 memcpy(pShader ->shaderInfo.aPatchConstantSignature, pu8Signatures, pSignatureHeader->numPatchConstantSignatures * sizeof(SVGA3dDXSignatureEntry));1867 pShaderInfo->cPatchConstantSignature = pSignatureHeader->numPatchConstantSignatures; 1868 memcpy(pShaderInfo->aPatchConstantSignature, pu8Signatures, pSignatureHeader->numPatchConstantSignatures * sizeof(SVGA3dDXSignatureEntry)); 1924 1869 } 1925 1870 } … … 1945 1890 RT_UNTRUSTED_VALIDATED_FENCE(); 1946 1891 1892 /* 'type' and 'sizeInBytes' has been already initialized by DefineShader. */ 1947 1893 SVGACOTableDXShaderEntry *pEntry = &pDXContext->cot.paShader[pCmd->shid]; 1948 1894 //pEntry->type; … … 1963 1909 ASSERT_GUEST_RETURN(pvShaderBytecode, VERR_INVALID_PARAMETER); 1964 1910 1965 PVMSVGA3DSHADER pShader = &pDXContext->paShader[pCmd->shid];1966 Assert( pShader->id == pCmd->shid1967 && pShader->type == pEntry->type); /* The host ensures this. */1968 1969 1911 /* Get the shader and optional signatures from the MOB. */ 1970 rc = dxBindShader(pShader, pMob, pEntry, pvShaderBytecode); 1912 DXShaderInfo shaderInfo; 1913 RT_ZERO(shaderInfo); 1914 rc = dxBindShader(&shaderInfo, pMob, pEntry, pvShaderBytecode); 1971 1915 if (RT_SUCCESS(rc)) 1972 rc = pSvgaR3State->pFuncsDX->pfnDXBindShader(pThisCC, pDXContext, pShader, pvShaderBytecode); 1973 1916 { 1917 /* pfnDXBindShader makes a copy of shaderInfo on success. */ 1918 rc = pSvgaR3State->pFuncsDX->pfnDXBindShader(pThisCC, pDXContext, pCmd->shid, &shaderInfo); 1919 } 1920 AssertRC(rc); 1921 1922 /** @todo Backing store is not needed anymore in any case? */ 1974 1923 if (RT_FAILURE(rc)) 1975 1924 { 1976 /** @todo Any cleanup? */ 1925 DXShaderFree(&shaderInfo); 1926 1977 1927 vmsvgaR3MobBackingStoreDelete(pSvgaR3State, pMob); 1978 1928 } … … 2193 2143 pDXContext->cot.paShader = (SVGACOTableDXShaderEntry *)pvCOT; 2194 2144 pDXContext->cot.cShader = cEntries; 2195 2196 /* Create host array for information about shaders. */2197 RTMemFree(pDXContext->paShader);2198 pDXContext->paShader = NULL;2199 2200 if (pDXContext->cot.cShader)2201 {2202 pDXContext->paShader = (PVMSVGA3DSHADER)RTMemAllocZ(pDXContext->cot.cShader * sizeof(VMSVGA3DSHADER));2203 AssertReturn(pDXContext->paShader, VERR_NO_MEMORY);2204 for (uint32_t i = 0; i < pDXContext->cot.cShader; ++i)2205 pDXContext->paShader[i].id = SVGA_ID_INVALID;2206 }2207 2145 break; 2208 2146 case SVGA_COTABLE_UAVIEW: -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-internal.h
r93115 r94146 707 707 void *pPixelShader; 708 708 #endif 709 void *pvBackendShader;710 709 } u; 711 #ifdef VMSVGA3D_DX712 DXShaderInfo shaderInfo;713 #endif714 710 } VMSVGA3DSHADER; 715 711 typedef VMSVGA3DSHADER *PVMSVGA3DSHADER; … … 726 722 SSMFIELD_ENTRY( VMSVGA3DSHADER, cbData), 727 723 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, pShaderProgram), 728 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DSHADER, u.pvBackendShader),729 724 SSMFIELD_ENTRY_TERM() 730 725 }; … … 994 989 uint32_t cUAView; 995 990 } cot; 996 /* Shader information. The array has cot.cShader elements. Some data is dublicated in cot.paShader. */997 PVMSVGA3DSHADER paShader;998 991 } VMSVGA3DDXCONTEXT; 999 992 /** Pointer to a VMSVGA3D DX context. */ -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp
r94113 r94146 214 214 215 215 uint32_t soid; /* Stream output declarations for geometry shaders. */ 216 217 DXShaderInfo shaderInfo; 216 218 } DXSHADER; 217 219 … … 280 282 static int dxSetRenderTargets(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext); 281 283 static DECLCALLBACK(void) vmsvga3dBackSurfaceDestroy(PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface); 284 static int dxDestroyShader(DXSHADER *pDXShader); 282 285 283 286 … … 1585 1588 1586 1589 1587 static HRESULT dxShaderCreate(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSHADER pShader,DXSHADER *pDXShader)1590 static HRESULT dxShaderCreate(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, DXSHADER *pDXShader) 1588 1591 { 1589 1592 DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext); … … 1591 1594 HRESULT hr = S_OK; 1592 1595 1593 switch (p Shader->type)1596 switch (pDXShader->enmShaderType) 1594 1597 { 1595 1598 case SVGA3D_SHADERTYPE_VS: … … 1618 1621 D3D11_SO_DECLARATION_ENTRY *p = &pDXStreamOutput->aDeclarationEntry[i]; 1619 1622 SVGA3dStreamOutputDeclarationEntry const *decl = &pEntry->decl[i]; 1620 p->SemanticName = DXShaderGetOutputSemanticName(&p Shader->shaderInfo, decl->registerIndex);1623 p->SemanticName = DXShaderGetOutputSemanticName(&pDXShader->shaderInfo, decl->registerIndex); 1621 1624 } 1622 1625 … … 2852 2855 LogRelMax(1, ("VMSVGA: Single DX device mode: %s\n", pBackend->fSingleDevice ? "enabled" : "disabled")); 2853 2856 2854 //DEBUG_BREAKPOINT_TEST();2857 DEBUG_BREAKPOINT_TEST(); 2855 2858 return rc; 2856 2859 } … … 3233 3236 } 3234 3237 else 3235 rc = VERR_NOT_SUPPORTED;3238 AssertFailedStmt(rc = VERR_NOT_SUPPORTED); 3236 3239 } 3237 3240 else if ( pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_2D … … 3306 3309 } 3307 3310 else 3308 rc = VERR_NOT_SUPPORTED;3311 AssertFailedStmt(rc = VERR_NOT_SUPPORTED); 3309 3312 } 3310 3313 else if (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER) … … 3351 3354 } 3352 3355 else 3353 rc = VERR_NOT_SUPPORTED;3356 AssertFailedStmt(rc = VERR_NOT_SUPPORTED); 3354 3357 } 3355 3358 } … … 5071 5074 { 5072 5075 for (uint32_t i = 0; i < pBackendDXContext->cShader; ++i) 5073 D3D_RELEASE(pBackendDXContext->paShader[i].pShader); /// @todo dxDestroyShader5076 dxDestroyShader(&pBackendDXContext->paShader[i]); 5074 5077 } 5075 5078 if (pBackendDXContext->paStreamOutput) … … 5272 5275 5273 5276 5274 static DECLCALLBACK(int) vmsvga3dBackDXSetShader(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShader Type type, PVMSVGA3DSHADER pShader)5277 static DECLCALLBACK(int) vmsvga3dBackDXSetShader(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderId shaderId, SVGA3dShaderType type) 5275 5278 { 5276 5279 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; … … 5280 5283 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 5281 5284 5282 DXSHADER *pDXShader; 5283 if (pShader) 5284 { 5285 pDXShader = &pDXContext->pBackendDXContext->paShader[pShader->id]; 5286 Assert(pDXShader->pShader); 5287 Assert(pDXShader->enmShaderType >= SVGA3D_SHADERTYPE_MIN && pDXShader->enmShaderType < SVGA3D_SHADERTYPE_MAX); 5288 } 5289 else 5290 pDXShader = NULL; 5291 5292 dxShaderSet(pThisCC, pDXContext, type, pDXShader); 5285 RT_NOREF(shaderId, type); 5286 5293 5287 return VINF_SUCCESS; 5294 5288 } … … 5332 5326 DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext); 5333 5327 pDXDevice->pImmediateContext->OMSetRenderTargets(0, NULL, NULL); 5328 5329 /* 5330 * Shader resources 5331 */ 5334 5332 5335 5333 /* Make sure that the shader resource views exist. */ … … 5376 5374 } 5377 5375 5376 /* 5377 * Render targets 5378 */ 5378 5379 5379 5380 DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext); … … 5433 5434 rc = dxSetRenderTargets(pThisCC, pDXContext); 5434 5435 AssertRC(rc); 5436 5437 /* 5438 * Shaders 5439 */ 5440 5441 for (uint32_t idxShaderState = 0; idxShaderState < SVGA3D_NUM_SHADERTYPE_DX10 /** @todo SVGA3D_NUM_SHADERTYPE*/; ++idxShaderState) 5442 { 5443 DXSHADER *pDXShader; 5444 SVGA3dShaderType const shaderType = (SVGA3dShaderType)(idxShaderState + SVGA3D_SHADERTYPE_MIN); 5445 SVGA3dShaderId const shaderId = pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId; 5446 5447 if (shaderId != SVGA3D_INVALID_ID) 5448 { 5449 pDXShader = &pDXContext->pBackendDXContext->paShader[shaderId]; 5450 if (pDXShader->pShader == NULL) 5451 { 5452 /* Create a new shader. */ 5453 Log(("Shader: cid=%u shid=%u type=%d\n", pDXContext->cid, shaderId, pDXShader->enmShaderType)); 5454 5455 /* Apply resource types to a pixel shader. */ 5456 if (shaderType == SVGA3D_SHADERTYPE_PS) 5457 { 5458 SVGA3dResourceType aResourceType[SVGA3D_DX_MAX_SRVIEWS]; 5459 RT_ZERO(aResourceType); 5460 uint32_t cResourceType = 0; 5461 5462 for (uint32_t idxSR = 0; idxSR < SVGA3D_DX_MAX_SRVIEWS; ++idxSR) 5463 { 5464 SVGA3dShaderResourceViewId const shaderResourceViewId = pDXContext->svgaDXContext.shaderState[idxShaderState].shaderResources[idxSR]; 5465 if (shaderResourceViewId != SVGA3D_INVALID_ID) 5466 { 5467 SVGACOTableDXSRViewEntry const *pSRViewEntry = dxGetShaderResourceViewEntry(pDXContext, shaderResourceViewId); 5468 AssertContinue(pSRViewEntry != NULL); 5469 5470 aResourceType[idxSR] = pSRViewEntry->resourceDimension; 5471 cResourceType = idxSR + 1; 5472 } 5473 } 5474 5475 rc = DXShaderUpdateResourceTypes(&pDXShader->shaderInfo, aResourceType, cResourceType); 5476 AssertRC(rc); /* Ignore rc because the shader will most likely work anyway. */ 5477 } 5478 5479 rc = DXShaderCreateDXBC(&pDXShader->shaderInfo, &pDXShader->pvDXBC, &pDXShader->cbDXBC); 5480 if (RT_SUCCESS(rc)) 5481 { 5482 #ifdef LOG_ENABLED 5483 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 5484 if (pBackend->pfnD3DDisassemble && LogIs6Enabled()) 5485 { 5486 ID3D10Blob *pBlob = 0; 5487 HRESULT hr2 = pBackend->pfnD3DDisassemble(pDXShader->pvDXBC, pDXShader->cbDXBC, 0, NULL, &pBlob); 5488 if (SUCCEEDED(hr2) && pBlob && pBlob->GetBufferSize()) 5489 Log6(("%s\n", pBlob->GetBufferPointer())); 5490 else 5491 AssertFailed(); 5492 D3D_RELEASE(pBlob); 5493 } 5494 #endif 5495 5496 HRESULT hr = dxShaderCreate(pThisCC, pDXContext, pDXShader); 5497 if (FAILED(hr)) 5498 rc = VERR_INVALID_STATE; 5499 } 5500 else 5501 rc = VERR_NO_MEMORY; 5502 } 5503 } 5504 else 5505 pDXShader = NULL; 5506 5507 if (RT_SUCCESS(rc)) 5508 dxShaderSet(pThisCC, pDXContext, shaderType, pDXShader); 5509 5510 AssertRC(rc); 5511 } 5512 5513 /* 5514 * InputLayout 5515 */ 5516 SVGA3dElementLayoutId const elementLayoutId = pDXContext->svgaDXContext.inputAssembly.layoutId; 5517 ID3D11InputLayout *pInputLayout = NULL; 5518 if (elementLayoutId != SVGA3D_INVALID_ID) 5519 { 5520 DXELEMENTLAYOUT *pDXElementLayout = &pDXContext->pBackendDXContext->paElementLayout[elementLayoutId]; 5521 if (!pDXElementLayout->pElementLayout) 5522 { 5523 uint32_t const idxShaderState = SVGA3D_SHADERTYPE_VS - SVGA3D_SHADERTYPE_MIN; 5524 uint32_t const shid = pDXContext->svgaDXContext.shaderState[idxShaderState].shaderId; 5525 if (shid < pDXContext->pBackendDXContext->cShader) 5526 { 5527 DXSHADER *pDXShader = &pDXContext->pBackendDXContext->paShader[shid]; 5528 if (pDXShader->pvDXBC) 5529 { 5530 HRESULT hr = pDevice->pDevice->CreateInputLayout(pDXElementLayout->aElementDesc, 5531 pDXElementLayout->cElementDesc, 5532 pDXShader->pvDXBC, 5533 pDXShader->cbDXBC, 5534 &pDXElementLayout->pElementLayout); 5535 Assert(SUCCEEDED(hr)); 5536 } 5537 else 5538 LogRelMax(16, ("VMSVGA: DX shader bytecode is not available in DXSetInputLayout: shid = %u\n", shid)); 5539 } 5540 else 5541 LogRelMax(16, ("VMSVGA: DX shader is not set in DXSetInputLayout: shid = 0x%x\n", shid)); 5542 } 5543 5544 pInputLayout = pDXElementLayout->pElementLayout; 5545 } 5546 5547 pDevice->pImmediateContext->IASetInputLayout(pInputLayout); 5435 5548 } 5436 5549 … … 5775 5888 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 5776 5889 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); 5890 RT_NOREF(elementLayoutId); 5891 5804 5892 return VINF_SUCCESS; 5805 5893 } … … 6485 6573 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 6486 6574 6575 /** @todo Probably not necessary because SRVs are defined in setupPipeline. */ 6487 6576 return dxDefineShaderResourceView(pThisCC, pDXContext, shaderResourceViewId, pEntry); 6488 6577 } … … 6789 6878 /** @todo A common approach for creation of COTable backend objects: runtime, empty DX COTable, live DX COTable. */ 6790 6879 DXSHADER *pDXShader = &pDXContext->pBackendDXContext->paShader[shaderId]; 6791 if (pDXShader->enmShaderType == SVGA3D_SHADERTYPE_INVALID) 6792 { 6793 /* Init the shader structure. */ 6794 pDXShader->enmShaderType = pEntry->type; 6795 pDXShader->soid = SVGA_ID_INVALID; 6796 } 6797 6798 PVMSVGA3DSHADER pShader = &pDXContext->paShader[shaderId]; 6799 pShader->u.pvBackendShader = pDXShader; 6880 Assert(pDXShader->enmShaderType == SVGA3D_SHADERTYPE_INVALID); 6881 6882 /* Init the backend shader structure, if the shader has not been created yet. */ 6883 pDXShader->enmShaderType = pEntry->type; 6884 pDXShader->pShader = NULL; 6885 pDXShader->soid = SVGA_ID_INVALID; 6800 6886 6801 6887 return VINF_SUCCESS; … … 6820 6906 RT_NOREF(pBackend); 6821 6907 6908 return dxDefineShader(pDXContext, shaderId, pEntry); 6909 } 6910 6911 6912 static DECLCALLBACK(int) vmsvga3dBackDXDestroyShader(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderId shaderId) 6913 { 6914 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 6915 RT_NOREF(pBackend); 6916 6822 6917 DXSHADER *pDXShader = &pDXContext->pBackendDXContext->paShader[shaderId]; 6823 6918 dxDestroyShader(pDXShader); 6824 6919 6825 return dxDefineShader(pDXContext, shaderId, pEntry);6826 }6827 6828 6829 static DECLCALLBACK(int) vmsvga3dBackDXDestroyShader(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderId shaderId)6830 {6831 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;6832 RT_NOREF(pBackend);6833 6834 DXSHADER *pDXShader = &pDXContext->pBackendDXContext->paShader[shaderId];6835 dxDestroyShader(pDXShader);6836 6837 6920 return VINF_SUCCESS; 6838 6921 } 6839 6922 6840 6923 6841 static DECLCALLBACK(int) vmsvga3dBackDXBindShader(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSHADER pShader, void const *pvShaderBytecode)6924 static DECLCALLBACK(int) vmsvga3dBackDXBindShader(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderId shaderId, DXShaderInfo const *pShaderInfo) 6842 6925 { 6843 6926 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; … … 6847 6930 RT_NOREF(pBackend); 6848 6931 6849 int rc = VINF_SUCCESS; 6850 6851 DXSHADER *pDXShader = &pDXContext->pBackendDXContext->paShader[pShader->id]; 6852 Assert(pDXShader->enmShaderType == pShader->type); 6853 6932 DXSHADER *pDXShader = &pDXContext->pBackendDXContext->paShader[shaderId]; 6854 6933 if (pDXShader->pvDXBC) 6855 6934 { 6935 /* New DXBC code and new shader must be created. */ 6936 D3D_RELEASE(pDXShader->pShader); 6856 6937 RTMemFree(pDXShader->pvDXBC); 6857 6938 pDXShader->pvDXBC = NULL; … … 6859 6940 } 6860 6941 6861 if (pvShaderBytecode) 6862 { 6863 Log(("Shader: cid=%u shid=%u type=%d\n", pDXContext->cid, pShader->id, pDXShader->enmShaderType)); 6864 6865 rc = DXShaderCreateDXBC(&pShader->shaderInfo, &pDXShader->pvDXBC, &pDXShader->cbDXBC); 6866 if (RT_SUCCESS(rc)) 6867 { 6868 #ifdef LOG_ENABLED 6869 if (pBackend->pfnD3DDisassemble && LogIs6Enabled()) 6870 { 6871 ID3D10Blob *pBlob = 0; 6872 HRESULT hr2 = pBackend->pfnD3DDisassemble(pDXShader->pvDXBC, pDXShader->cbDXBC, 0, NULL, &pBlob); 6873 if (SUCCEEDED(hr2) && pBlob && pBlob->GetBufferSize()) 6874 Log6(("%s\n", pBlob->GetBufferPointer())); 6875 else 6876 AssertFailed(); 6877 D3D_RELEASE(pBlob); 6878 } 6879 #endif 6880 6881 HRESULT hr = dxShaderCreate(pThisCC, pDXContext, pShader, pDXShader); 6882 if (SUCCEEDED(hr)) 6883 { 6884 } 6885 else 6886 rc = VERR_INVALID_STATE; 6887 } 6888 else 6889 rc = VERR_NO_MEMORY; 6890 } 6891 6892 return rc; 6942 pDXShader->shaderInfo = *pShaderInfo; 6943 6944 return VINF_SUCCESS; 6893 6945 } 6894 6946 … … 7222 7274 continue; /* Skip uninitialized entry. */ 7223 7275 7224 /** @todo this should be in the common DX code (the caller). */ 7225 PVMSVGA3DSHADER pShader = &pDXContext->paShader[i]; 7226 pShader->id = i; 7227 pShader->cid = pDXContext->cid; 7228 pShader->type = pEntry->type; 7229 pShader->cbData = pEntry->sizeInBytes; 7230 pShader->pShaderProgram = NULL; 7231 pShader->u.pvBackendShader = NULL; 7232 7233 dxDefineShader(pDXContext, i, pEntry); 7276 /* Define shaders which were not defined yet in backend. */ 7277 DXSHADER *pDXShader = &pBackendDXContext->paShader[i]; 7278 if ( pEntry->type != SVGA3D_SHADERTYPE_INVALID 7279 && pDXShader->enmShaderType == SVGA3D_SHADERTYPE_INVALID) 7280 dxDefineShader(pDXContext, i, pEntry); 7281 else 7282 Assert(pEntry->type == pDXShader->enmShaderType); 7283 7234 7284 } 7235 7285 break; -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.h
r94106 r94146 390 390 typedef struct VMSVGA3DSHADER *PVMSVGA3DSHADER; 391 391 typedef struct VMSVGA3DDXCONTEXT *PVMSVGA3DDXCONTEXT; 392 struct DXShaderInfo; 392 393 #define VMSVGA3D_BACKEND_INTERFACE_NAME_DX "DX" 393 394 typedef struct … … 401 402 DECLCALLBACKMEMBER(int, pfnDXSetSingleConstantBuffer, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t slot, SVGA3dShaderType type, SVGA3dSurfaceId sid, uint32_t offsetInBytes, uint32_t sizeInBytes)); 402 403 DECLCALLBACKMEMBER(int, pfnDXSetShaderResources, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t startView, SVGA3dShaderType type, uint32_t cShaderResourceViewId, SVGA3dShaderResourceViewId const *paShaderResourceViewId)); 403 DECLCALLBACKMEMBER(int, pfnDXSetShader, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShader Type type, PVMSVGA3DSHADER pShader));404 DECLCALLBACKMEMBER(int, pfnDXSetShader, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderId shaderId, SVGA3dShaderType type)); 404 405 DECLCALLBACKMEMBER(int, pfnDXSetSamplers, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t startSampler, SVGA3dShaderType type, uint32_t cSamplerId, SVGA3dSamplerId const *paSamplerId)); 405 406 DECLCALLBACKMEMBER(int, pfnDXDraw, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t vertexCount, uint32_t startVertexLocation)); … … 451 452 DECLCALLBACKMEMBER(int, pfnDXDefineShader, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderId shaderId, SVGACOTableDXShaderEntry const *pEntry)); 452 453 DECLCALLBACKMEMBER(int, pfnDXDestroyShader, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderId shaderId)); 453 DECLCALLBACKMEMBER(int, pfnDXBindShader, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSHADER pShader, void const *pvShaderBytecode));454 DECLCALLBACKMEMBER(int, pfnDXBindShader, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderId shaderId, DXShaderInfo const *pShaderInfo)); 454 455 DECLCALLBACKMEMBER(int, pfnDXDefineStreamOutput, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dStreamOutputId soid, SVGACOTableDXStreamOutputEntry const *pEntry)); 455 456 DECLCALLBACKMEMBER(int, pfnDXDestroyStreamOutput, (PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dStreamOutputId soid));
Note:
See TracChangeset
for help on using the changeset viewer.