- Timestamp:
- Sep 30, 2021 7:18:32 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 147168
- Location:
- trunk/src/VBox/Devices/Graphics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx-shader.cpp
r91441 r91484 1639 1639 pSignatureEntry->semanticName = SVGADX_SIGNATURE_SEMANTIC_NAME_PRIMITIVE_ID; 1640 1640 } 1641 else if (opcode.aValOperand[0].operandType == VGPU10_OPERAND_TYPE_OUTPUT_DEPTH) 1642 { 1643 /* oDepth is always last in the signature. Register index is equal to 0xFFFFFFFF. */ 1644 pSignatureEntry->registerIndex = 0xFFFFFFFF; 1645 pSignatureEntry->semanticName = SVGADX_SIGNATURE_SEMANTIC_NAME_UNDEFINED; 1646 } 1641 1647 else 1642 1648 ASSERT_GUEST_FAILED_RETURN(VERR_NOT_SUPPORTED); … … 1791 1797 { 1792 1798 SVGA3dDXSignatureEntry const *src = &paSignature[i]; 1799 if (src->registerIndex == 0xFFFFFFFF) 1800 { 1801 /* oDepth for PS output. */ 1802 ASSERT_GUEST_RETURN(pInfo->enmProgramType == VGPU10_PIXEL_SHADER, VERR_INVALID_PARAMETER); 1803 1804 /* Must be placed last in the signature. */ 1805 ASSERT_GUEST_RETURN(aIdxSignature[cSignature - 1] == 0xFFFFFFFF, VERR_INVALID_PARAMETER); 1806 aIdxSignature[cSignature - 1] = i; 1807 continue; 1808 } 1809 1793 1810 ASSERT_GUEST_RETURN(src->registerIndex < RT_ELEMENTS(aIdxSignature), VERR_INVALID_PARAMETER); 1794 1811 ASSERT_GUEST_RETURN(aIdxSignature[src->registerIndex] == 0xFFFFFFFF, VERR_INVALID_PARAMETER); -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp
r91441 r91484 215 215 216 216 217 static int dxDeviceFlush(DXDEVICE *pDevice); 217 218 static DECLCALLBACK(void) vmsvga3dBackSurfaceDestroy(PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface); 218 219 … … 805 806 RT_NOREF(pBackend); 806 807 808 if (pDevice->pImmediateContext) 809 { 810 dxDeviceFlush(pDevice); /* Make sure that any pending draw calls are finished. */ 811 pDevice->pImmediateContext->ClearState(); 812 } 813 807 814 D3D_RELEASE(pDevice->pStagingBuffer); 808 809 if (pDevice->pImmediateContext)810 pDevice->pImmediateContext->ClearState();811 815 812 816 D3D_RELEASE(pDevice->pDxgiFactory); … … 885 889 /* Flush cidDrawing context and issue a query. */ 886 890 DXDEVICE *pDXDevice = dxDeviceFromCid(cidDrawing, pState); 887 return dxDeviceFlush(pDXDevice); 891 if (pDXDevice) 892 return dxDeviceFlush(pDXDevice); 893 /* cidDrawing does not exist anymore. */ 894 return VINF_SUCCESS; 888 895 } 889 896 … … 2011 2018 } 2012 2019 2013 /* Failure. */2020 /** @todo different enmResType Failure. */ 2014 2021 D3D_RELEASE(pBackendSurface->pStagingTexture); 2015 2022 D3D_RELEASE(pBackendSurface->pDynamicTexture); … … 2020 2027 2021 2028 2029 /** @todo This is practically the same code as vmsvga3dBackSurfaceCreateTexture */ 2022 2030 static int vmsvga3dBackSurfaceCreateDepthStencilTexture(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSURFACE pSurface) 2023 2031 { … … 2037 2045 uint32_t const cWidth = pSurface->paMipmapLevels[0].mipmapSize.width; 2038 2046 uint32_t const cHeight = pSurface->paMipmapLevels[0].mipmapSize.height; 2047 uint32_t const cDepth = pSurface->paMipmapLevels[0].mipmapSize.depth; 2039 2048 uint32_t const numMipLevels = pSurface->cLevels; 2040 2049 2041 D3D11_SUBRESOURCE_DATA *paInitialData = NULL; 2042 D3D11_SUBRESOURCE_DATA aInitialData[SVGA3D_MAX_MIP_LEVELS]; 2043 if (pSurface->paMipmapLevels[0].pSurfaceData) 2044 { 2045 /** @todo Can happen for a non GBO surface or if GBO texture was updated prior to creation if the hardware resource. Test this. */ 2046 for (uint32_t i = 0; i < numMipLevels; ++i) 2050 DXGI_FORMAT dxgiFormat = vmsvgaDXSurfaceFormat2Dxgi(pSurface->format); 2051 AssertReturn(dxgiFormat != DXGI_FORMAT_UNKNOWN, E_FAIL); 2052 2053 /* 2054 * Create D3D11 texture object. 2055 */ 2056 HRESULT hr = S_OK; 2057 if (pSurface->surfaceFlags & SVGA3D_SURFACE_CUBEMAP) 2058 { 2059 AssertFailed(); /** @todo implement */ 2060 hr = E_FAIL; 2061 } 2062 else if (pSurface->surfaceFlags & SVGA3D_SURFACE_1D) 2063 { 2064 AssertFailed(); /** @todo implement */ 2065 hr = E_FAIL; 2066 } 2067 else 2068 { 2069 if (cDepth > 1) 2047 2070 { 2048 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[i]; 2049 D3D11_SUBRESOURCE_DATA *p = &aInitialData[i]; 2050 p->pSysMem = pMipmapLevel->pSurfaceData; 2051 p->SysMemPitch = pMipmapLevel->cbSurfacePitch; 2052 p->SysMemSlicePitch = pMipmapLevel->cbSurfacePlane; 2071 AssertFailed(); /** @todo implement */ 2072 hr = E_FAIL; 2053 2073 } 2054 paInitialData = &aInitialData[0]; 2055 } 2056 2057 D3D11_TEXTURE2D_DESC td; 2058 RT_ZERO(td); 2059 td.Width = cWidth; 2060 td.Height = cHeight; 2061 Assert(pSurface->cLevels == 1); 2062 td.MipLevels = 1; 2063 td.ArraySize = 1; 2064 td.Format = vmsvgaDXSurfaceFormat2Dxgi(pSurface->format); 2065 AssertReturn(td.Format != DXGI_FORMAT_UNKNOWN, E_FAIL); 2066 td.SampleDesc.Count = 1; 2067 td.SampleDesc.Quality = 0; 2068 td.Usage = D3D11_USAGE_DEFAULT; 2069 td.BindFlags = dxBindFlags(pSurface->surfaceFlags); 2070 td.CPUAccessFlags = 0; 2071 td.MiscFlags = 0; 2072 2073 HRESULT hr = pDXDevice->pDevice->CreateTexture2D(&td, 0, &pBackendSurface->u.pTexture2D); 2074 Assert(SUCCEEDED(hr)); 2075 if (SUCCEEDED(hr)) 2076 { 2077 /* Map-able texture. */ 2078 td.MipLevels = 1; /* Must be for D3D11_USAGE_DYNAMIC. */ 2079 td.Usage = D3D11_USAGE_DYNAMIC; 2080 td.BindFlags = D3D11_BIND_SHADER_RESOURCE; /* Have to specify a supported flag, otherwise E_INVALIDARG will be returned. */ 2081 td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 2082 td.MiscFlags = 0; 2083 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pDynamicTexture); 2084 Assert(SUCCEEDED(hr)); 2085 } 2086 2087 if (SUCCEEDED(hr)) 2088 { 2089 /* Staging texture. */ 2090 td.Usage = D3D11_USAGE_STAGING; 2091 td.BindFlags = 0; /* No flags allowed. */ 2092 td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; 2093 td.MiscFlags = 0; 2094 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pStagingTexture); 2095 Assert(SUCCEEDED(hr)); 2074 else 2075 { 2076 /* 2077 * 2D texture. 2078 */ 2079 Assert(pSurface->cFaces == 1); 2080 2081 D3D11_SUBRESOURCE_DATA *paInitialData = NULL; 2082 D3D11_SUBRESOURCE_DATA aInitialData[SVGA3D_MAX_MIP_LEVELS]; 2083 if (pSurface->paMipmapLevels[0].pSurfaceData) 2084 { 2085 /** @todo Can happen for a non GBO surface or if GBO texture was updated prior to creation if the hardware resource. Test this. */ 2086 for (uint32_t i = 0; i < numMipLevels; ++i) 2087 { 2088 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[i]; 2089 D3D11_SUBRESOURCE_DATA *p = &aInitialData[i]; 2090 p->pSysMem = pMipmapLevel->pSurfaceData; 2091 p->SysMemPitch = pMipmapLevel->cbSurfacePitch; 2092 p->SysMemSlicePitch = pMipmapLevel->cbSurfacePlane; 2093 } 2094 paInitialData = &aInitialData[0]; 2095 } 2096 2097 D3D11_TEXTURE2D_DESC td; 2098 RT_ZERO(td); 2099 td.Width = cWidth; 2100 td.Height = cHeight; 2101 Assert(pSurface->cLevels == 1); 2102 td.MipLevels = 1; 2103 td.ArraySize = 1; 2104 td.Format = dxgiFormat; 2105 td.SampleDesc.Count = 1; 2106 td.SampleDesc.Quality = 0; 2107 td.Usage = D3D11_USAGE_DEFAULT; 2108 td.BindFlags = dxBindFlags(pSurface->surfaceFlags); 2109 td.CPUAccessFlags = 0; 2110 td.MiscFlags = 0; 2111 2112 hr = pDXDevice->pDevice->CreateTexture2D(&td, 0, &pBackendSurface->u.pTexture2D); 2113 Assert(SUCCEEDED(hr)); 2114 if (SUCCEEDED(hr)) 2115 { 2116 /* Map-able texture. */ 2117 td.MipLevels = 1; /* Must be for D3D11_USAGE_DYNAMIC. */ 2118 td.Usage = D3D11_USAGE_DYNAMIC; 2119 td.BindFlags = D3D11_BIND_SHADER_RESOURCE; /* Have to specify a supported flag, otherwise E_INVALIDARG will be returned. */ 2120 td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 2121 td.MiscFlags = 0; 2122 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pDynamicTexture); 2123 Assert(SUCCEEDED(hr)); 2124 } 2125 2126 if (SUCCEEDED(hr)) 2127 { 2128 /* Staging texture. */ 2129 td.Usage = D3D11_USAGE_STAGING; 2130 td.BindFlags = 0; /* No flags allowed. */ 2131 td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; 2132 td.MiscFlags = 0; 2133 hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pStagingTexture); 2134 Assert(SUCCEEDED(hr)); 2135 } 2136 2137 if (SUCCEEDED(hr)) 2138 { 2139 pBackendSurface->enmResType = VMSVGA3D_RESTYPE_TEXTURE; 2140 } 2141 } 2096 2142 } 2097 2143 … … 2101 2147 * Success. 2102 2148 */ 2103 pBackendSurface->enmResType = VMSVGA3D_RESTYPE_TEXTURE; 2104 pBackendSurface->enmDxgiFormat = td.Format; 2149 pBackendSurface->enmDxgiFormat = dxgiFormat; 2105 2150 pSurface->pBackendSurface = pBackendSurface; 2106 2151 pSurface->idAssociatedContext = pDXContext->cid; 2107 //pSurface->fDirty = true;2108 2152 return VINF_SUCCESS; 2109 2153 } 2110 2154 2111 /* Failure. */2155 /** @todo different enmResType Failure. */ 2112 2156 D3D_RELEASE(pBackendSurface->pStagingTexture); 2113 2157 D3D_RELEASE(pBackendSurface->pDynamicTexture); … … 4338 4382 /** @todo This is generic code and should be in DevVGA-SVGA3d.cpp for backends which support Map/Unmap. */ 4339 4383 AssertReturn(uHostFace == 0 && uHostMipmap == 0, VERR_INVALID_PARAMETER); 4340 AssertReturn(transfer == SVGA3D_WRITE_HOST_VRAM, VERR_NOT_IMPLEMENTED); /** @todo Implement */4341 4384 4342 4385 uint32_t const u32GuestBlockX = pBox->srcx / pSurface->cxBlock; … … 4367 4410 box.h = pBox->h; 4368 4411 box.d = 1; 4412 4413 VMSVGA3D_SURFACE_MAP const enmMap = transfer == SVGA3D_WRITE_HOST_VRAM 4414 ? VMSVGA3D_SURFACE_MAP_WRITE 4415 : VMSVGA3D_SURFACE_MAP_READ; 4369 4416 4370 4417 VMSVGA3D_MAPPED_SURFACE map; … … 4937 4984 } 4938 4985 4986 static int dxReadBuffer(DXDEVICE *pDevice, ID3D11Buffer *pBuffer, UINT Offset, UINT Bytes, void **ppvData, uint32_t *pcbData) 4987 { 4988 D3D11_BUFFER_DESC desc; 4989 RT_ZERO(desc); 4990 pBuffer->GetDesc(&desc); 4991 4992 AssertReturn( Offset < desc.ByteWidth 4993 && Bytes <= desc.ByteWidth - Offset, VERR_INVALID_STATE); 4994 4995 void *pvData = RTMemAlloc(Bytes); 4996 if (!pvData) 4997 return VERR_NO_MEMORY; 4998 4999 int rc = dxStagingBufferRealloc(pDevice, Bytes); 5000 if (RT_SUCCESS(rc)) 5001 { 5002 /* Copy from the buffer to the staging buffer. */ 5003 ID3D11Resource *pDstResource = pDevice->pStagingBuffer; 5004 UINT DstSubresource = 0; 5005 UINT DstX = Offset; 5006 UINT DstY = 0; 5007 UINT DstZ = 0; 5008 ID3D11Resource *pSrcResource = pBuffer; 5009 UINT SrcSubresource = 0; 5010 D3D11_BOX SrcBox; 5011 SrcBox.left = 0; 5012 SrcBox.top = 0; 5013 SrcBox.front = 0; 5014 SrcBox.right = Bytes; 5015 SrcBox.bottom = 1; 5016 SrcBox.back = 1; 5017 pDevice->pImmediateContext->CopySubresourceRegion(pDstResource, DstSubresource, DstX, DstY, DstZ, 5018 pSrcResource, SrcSubresource, &SrcBox); 5019 5020 D3D11_MAPPED_SUBRESOURCE mappedResource; 5021 UINT const Subresource = 0; /* Buffers have only one subresource. */ 5022 HRESULT hr = pDevice->pImmediateContext->Map(pDevice->pStagingBuffer, Subresource, 5023 D3D11_MAP_READ, /* MapFlags = */ 0, &mappedResource); 5024 if (SUCCEEDED(hr)) 5025 { 5026 memcpy(pvData, mappedResource.pData, Bytes); 5027 5028 /* Unmap the staging buffer. */ 5029 pDevice->pImmediateContext->Unmap(pDevice->pStagingBuffer, Subresource); 5030 } 5031 else 5032 AssertFailedStmt(rc = VERR_NOT_SUPPORTED); 5033 5034 } 5035 5036 if (RT_SUCCESS(rc)) 5037 { 5038 *ppvData = pvData; 5039 *pcbData = Bytes; 5040 } 5041 else 5042 { 5043 RTMemFree(*ppvData); 5044 *ppvData = NULL; 5045 *pcbData = 0; 5046 } 5047 5048 return rc; 5049 } 5050 5051 5052 static int dxDrawIndexedTriangleFan(DXDEVICE *pDevice, uint32_t IndexCountTF, uint32_t StartIndexLocationTF, int32_t BaseVertexLocationTF) 5053 { 5054 /* 5055 * Emulate an indexed SVGA3D_PRIMITIVE_TRIANGLEFAN using an indexed draw of triangle list. 5056 */ 5057 5058 /* Make sure that 16 bit indices are enough. 20000 ~= 65536 / 3 */ 5059 AssertReturn(IndexCountTF <= 20000, VERR_NOT_SUPPORTED); 5060 5061 /* Save the current index buffer. */ 5062 ID3D11Buffer *pSavedIndexBuffer = 0; 5063 DXGI_FORMAT SavedFormat = DXGI_FORMAT_UNKNOWN; 5064 UINT SavedOffset = 0; 5065 pDevice->pImmediateContext->IAGetIndexBuffer(&pSavedIndexBuffer, &SavedFormat, &SavedOffset); 5066 5067 AssertReturn( SavedFormat == DXGI_FORMAT_R16_UINT 5068 || SavedFormat == DXGI_FORMAT_R32_UINT, VERR_NOT_SUPPORTED); 5069 5070 /* How many bytes are used by triangle fan indices. */ 5071 UINT const BytesPerIndexTF = SavedFormat == DXGI_FORMAT_R16_UINT ? 2 : 4; 5072 UINT const BytesTF = BytesPerIndexTF * IndexCountTF; 5073 5074 /* Read the current index buffer content to obtain indices. */ 5075 void *pvDataTF; 5076 uint32_t cbDataTF; 5077 int rc = dxReadBuffer(pDevice, pSavedIndexBuffer, StartIndexLocationTF, BytesTF, &pvDataTF, &cbDataTF); 5078 AssertRCReturn(rc, rc); 5079 AssertReturnStmt(cbDataTF >= BytesPerIndexTF, RTMemFree(pvDataTF), VERR_INVALID_STATE); 5080 5081 /* Generate indices for triangle list. */ 5082 UINT const IndexCount = 3 * (IndexCountTF - 2); /* 3_per_triangle * num_triangles */ 5083 UINT const cbAlloc = IndexCount * sizeof(USHORT); 5084 USHORT *paIndices = (USHORT *)RTMemAlloc(cbAlloc); 5085 AssertReturnStmt(paIndices, RTMemFree(pvDataTF), VERR_NO_MEMORY); 5086 5087 USHORT iVertex = 1; 5088 if (BytesPerIndexTF == 2) 5089 { 5090 USHORT *paIndicesTF = (USHORT *)pvDataTF; 5091 for (UINT i = 0; i < IndexCount; i+= 3) 5092 { 5093 paIndices[i] = paIndicesTF[0]; 5094 AssertBreakStmt(iVertex < IndexCountTF, rc = VERR_INVALID_STATE); 5095 paIndices[i + 1] = paIndicesTF[iVertex]; 5096 ++iVertex; 5097 AssertBreakStmt(iVertex < IndexCountTF, rc = VERR_INVALID_STATE); 5098 paIndices[i + 2] = paIndicesTF[iVertex]; 5099 } 5100 } 5101 else 5102 { 5103 UINT *paIndicesTF = (UINT *)pvDataTF; 5104 for (UINT i = 0; i < IndexCount; i+= 3) 5105 { 5106 paIndices[i] = paIndicesTF[0]; 5107 AssertBreakStmt(iVertex < IndexCountTF, rc = VERR_INVALID_STATE); 5108 paIndices[i + 1] = paIndicesTF[iVertex]; 5109 ++iVertex; 5110 AssertBreakStmt(iVertex < IndexCountTF, rc = VERR_INVALID_STATE); 5111 paIndices[i + 2] = paIndicesTF[iVertex]; 5112 } 5113 } 5114 5115 D3D11_SUBRESOURCE_DATA InitData; 5116 InitData.pSysMem = paIndices; 5117 InitData.SysMemPitch = cbAlloc; 5118 InitData.SysMemSlicePitch = cbAlloc; 5119 5120 D3D11_BUFFER_DESC bd; 5121 RT_ZERO(bd); 5122 bd.ByteWidth = cbAlloc; 5123 bd.Usage = D3D11_USAGE_IMMUTABLE; 5124 bd.BindFlags = D3D11_BIND_INDEX_BUFFER; 5125 //bd.CPUAccessFlags = 0; 5126 //bd.MiscFlags = 0; 5127 //bd.StructureByteStride = 0; 5128 5129 ID3D11Buffer *pIndexBuffer = 0; 5130 HRESULT hr = pDevice->pDevice->CreateBuffer(&bd, &InitData, &pIndexBuffer); 5131 Assert(SUCCEEDED(hr));RT_NOREF(hr); 5132 5133 /* Set up the device state. */ 5134 pDevice->pImmediateContext->IASetIndexBuffer(pIndexBuffer, DXGI_FORMAT_R16_UINT, 0); 5135 pDevice->pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); 5136 5137 UINT const StartIndexLocation = 0; 5138 INT const BaseVertexLocation = BaseVertexLocationTF; 5139 pDevice->pImmediateContext->DrawIndexed(IndexCount, StartIndexLocation, BaseVertexLocation); 5140 5141 /* Restore the device state. */ 5142 pDevice->pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); 5143 pDevice->pImmediateContext->IASetIndexBuffer(pSavedIndexBuffer, SavedFormat, SavedOffset); 5144 D3D_RELEASE(pSavedIndexBuffer); 5145 5146 /* Cleanup. */ 5147 D3D_RELEASE(pIndexBuffer); 5148 RTMemFree(paIndices); 5149 RTMemFree(pvDataTF); 5150 5151 return VINF_SUCCESS; 5152 } 5153 4939 5154 4940 5155 static DECLCALLBACK(int) vmsvga3dBackDXDrawIndexed(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t indexCount, uint32_t startIndexLocation, int32_t baseVertexLocation) … … 4950 5165 #endif 4951 5166 4952 Assert(pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN); 4953 4954 pDevice->pImmediateContext->DrawIndexed(indexCount, startIndexLocation, baseVertexLocation); 5167 if (pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN) 5168 pDevice->pImmediateContext->DrawIndexed(indexCount, startIndexLocation, baseVertexLocation); 5169 else 5170 { 5171 dxDrawIndexedTriangleFan(pDevice, indexCount, startIndexLocation, baseVertexLocation); 5172 } 4955 5173 4956 5174 /* Note which surfaces are being drawn. */
Note:
See TracChangeset
for help on using the changeset viewer.