Changeset 99521 in vbox
- Timestamp:
- Apr 24, 2023 10:59:22 AM (19 months ago)
- Location:
- trunk/src/VBox/Devices/Graphics
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA.cpp
r98103 r99521 12 12 * - Log6 for DX shaders. 13 13 * - Log7 for SVGA command dump. 14 * - Log8 for content of constant and vertex buffers. 14 15 * - LogRel for the usual important stuff. 15 16 * - LogRel2 for cursor. -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx-dx11.cpp
r99274 r99521 65 65 #endif 66 66 67 /* One ID3D11Device object is used for all VMSVGA contexts. */ 68 /** @todo This should be the only option because VGPU freely uses surfaces from different VMSVGA contexts 69 * and synchronization of access to shared surfaces kills performance. 70 */ 67 71 #define DX_FORCE_SINGLE_DEVICE 72 /* A single staging ID3D11Buffer is used for uploading data to other buffers. */ 73 #define DX_COMMON_STAGING_BUFFER 74 /* Always flush after submitting a draw call for debugging. */ 75 //#define DX_FLUSH_AFTER_DRAW 68 76 69 77 /* This is not available on non Windows hosts. */ … … 99 107 D3D_FEATURE_LEVEL FeatureLevel; 100 108 109 #ifdef DX_COMMON_STAGING_BUFFER 101 110 /* Staging buffer for transfer to surface buffers. */ 102 111 ID3D11Buffer *pStagingBuffer; /* The staging buffer resource. */ 103 112 uint32_t cbStagingBuffer; /* Current size of the staging buffer resource. */ 113 #endif 104 114 105 115 D3D11BLITTER Blitter; /* Blits one texture to another. */ … … 180 190 ID3D11Texture2D *pTexture2D; 181 191 ID3D11Texture3D *pTexture3D; 192 #ifndef DX_COMMON_STAGING_BUFFER 193 ID3D11Buffer *pBuffer; 194 #endif 182 195 } dynamic; 183 196 … … 189 202 ID3D11Texture2D *pTexture2D; 190 203 ID3D11Texture3D *pTexture3D; 204 #ifndef DX_COMMON_STAGING_BUFFER 205 ID3D11Buffer *pBuffer; 206 #endif 191 207 } staging; 192 208 … … 366 382 static int dxDestroyShader(DXSHADER *pDXShader); 367 383 static int dxDestroyQuery(DXQUERY *pDXQuery); 384 static int dxReadBuffer(DXDEVICE *pDevice, ID3D11Buffer *pBuffer, UINT Offset, UINT Bytes, void **ppvData, uint32_t *pcbData); 368 385 369 386 static HRESULT BlitInit(D3D11BLITTER *pBlitter, ID3D11Device *pDevice, ID3D11DeviceContext *pImmediateContext); … … 897 914 pDXDevice->FeatureLevel = pBackend->dxDevice.FeatureLevel; 898 915 916 #ifdef DX_COMMON_STAGING_BUFFER 899 917 pDXDevice->pStagingBuffer = 0; 900 918 pDXDevice->cbStagingBuffer = 0; 919 #endif 901 920 902 921 BlitInit(&pDXDevice->Blitter, pDXDevice->pDevice, pDXDevice->pImmediateContext); … … 1033 1052 BlitRelease(&pDevice->Blitter); 1034 1053 1054 #ifdef DX_COMMON_STAGING_BUFFER 1035 1055 D3D_RELEASE(pDevice->pStagingBuffer); 1056 #endif 1036 1057 1037 1058 D3D_RELEASE(pDevice->pDxgiFactory); … … 2856 2877 2857 2878 HRESULT hr = pDevice->pDevice->CreateBuffer(&bd, pInitialData, &pBackendSurface->u.pBuffer); 2879 Assert(SUCCEEDED(hr)); 2880 #ifndef DX_COMMON_STAGING_BUFFER 2881 if (SUCCEEDED(hr)) 2882 { 2883 /* Map-able Buffer. */ 2884 bd.Usage = D3D11_USAGE_DYNAMIC; 2885 bd.BindFlags = D3D11_BIND_SHADER_RESOURCE; /* Have to specify a supported flag, otherwise E_INVALIDARG will be returned. */ 2886 bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 2887 hr = pDevice->pDevice->CreateBuffer(&bd, pInitialData, &pBackendSurface->dynamic.pBuffer); 2888 Assert(SUCCEEDED(hr)); 2889 } 2890 2891 if (SUCCEEDED(hr)) 2892 { 2893 /* Staging texture. */ 2894 bd.Usage = D3D11_USAGE_STAGING; 2895 bd.BindFlags = 0; /* No flags allowed. */ 2896 bd.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; 2897 hr = pDevice->pDevice->CreateBuffer(&bd, pInitialData, &pBackendSurface->staging.pBuffer); 2898 Assert(SUCCEEDED(hr)); 2899 } 2900 #endif 2901 2858 2902 if (SUCCEEDED(hr)) 2859 2903 { … … 2870 2914 /* Failure. */ 2871 2915 D3D_RELEASE(pBackendSurface->u.pBuffer); 2916 #ifndef DX_COMMON_STAGING_BUFFER 2917 D3D_RELEASE(pBackendSurface->dynamic.pBuffer); 2918 D3D_RELEASE(pBackendSurface->staging.pBuffer); 2919 #endif 2872 2920 RTMemFree(pBackendSurface); 2873 2921 return VERR_NO_MEMORY; … … 2903 2951 2904 2952 HRESULT hr = pDevice->pDevice->CreateBuffer(&bd, 0, &pBackendSurface->u.pBuffer); 2953 #ifndef DX_COMMON_STAGING_BUFFER 2954 if (SUCCEEDED(hr)) 2955 { 2956 /* Map-able Buffer. */ 2957 bd.Usage = D3D11_USAGE_DYNAMIC; 2958 bd.BindFlags = D3D11_BIND_SHADER_RESOURCE; /* Have to specify a supported flag, otherwise E_INVALIDARG will be returned. */ 2959 bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 2960 hr = pDevice->pDevice->CreateBuffer(&bd, 0, &pBackendSurface->dynamic.pBuffer); 2961 Assert(SUCCEEDED(hr)); 2962 } 2963 2964 if (SUCCEEDED(hr)) 2965 { 2966 /* Staging texture. */ 2967 bd.Usage = D3D11_USAGE_STAGING; 2968 bd.BindFlags = 0; /* No flags allowed. */ 2969 bd.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; 2970 hr = pDevice->pDevice->CreateBuffer(&bd, 0, &pBackendSurface->staging.pBuffer); 2971 Assert(SUCCEEDED(hr)); 2972 } 2973 #endif 2974 2905 2975 if (SUCCEEDED(hr)) 2906 2976 { … … 2917 2987 /* Failure. */ 2918 2988 D3D_RELEASE(pBackendSurface->u.pBuffer); 2989 #ifndef DX_COMMON_STAGING_BUFFER 2990 D3D_RELEASE(pBackendSurface->dynamic.pBuffer); 2991 D3D_RELEASE(pBackendSurface->staging.pBuffer); 2992 #endif 2919 2993 RTMemFree(pBackendSurface); 2920 2994 return VERR_NO_MEMORY; … … 3068 3142 hr = pDevice->pDevice->CreateBuffer(&bd, pInitialData, &pBackendSurface->u.pBuffer); 3069 3143 Assert(SUCCEEDED(hr)); 3144 #ifndef DX_COMMON_STAGING_BUFFER 3145 if (SUCCEEDED(hr)) 3146 { 3147 /* Map-able Buffer. */ 3148 bd.Usage = D3D11_USAGE_DYNAMIC; 3149 bd.BindFlags = D3D11_BIND_SHADER_RESOURCE; /* Have to specify a supported flag, otherwise E_INVALIDARG will be returned. */ 3150 bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 3151 hr = pDevice->pDevice->CreateBuffer(&bd, pInitialData, &pBackendSurface->dynamic.pBuffer); 3152 Assert(SUCCEEDED(hr)); 3153 } 3154 3155 if (SUCCEEDED(hr)) 3156 { 3157 /* Staging texture. */ 3158 bd.Usage = D3D11_USAGE_STAGING; 3159 bd.BindFlags = 0; /* No flags allowed. */ 3160 bd.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; 3161 hr = pDevice->pDevice->CreateBuffer(&bd, pInitialData, &pBackendSurface->staging.pBuffer); 3162 Assert(SUCCEEDED(hr)); 3163 } 3164 #endif 3070 3165 if (SUCCEEDED(hr)) 3071 3166 { … … 3092 3187 3093 3188 /* Failure. */ 3189 D3D_RELEASE(pBackendSurface->u.pResource); 3190 D3D_RELEASE(pBackendSurface->dynamic.pResource); 3191 D3D_RELEASE(pBackendSurface->staging.pResource); 3094 3192 RTMemFree(pBackendSurface); 3095 3193 return VERR_NO_MEMORY; … … 3097 3195 3098 3196 3197 #ifdef DX_COMMON_STAGING_BUFFER 3099 3198 static int dxStagingBufferRealloc(DXDEVICE *pDXDevice, uint32_t cbRequiredSize) 3100 3199 { … … 3132 3231 return rc; 3133 3232 } 3233 #endif 3134 3234 3135 3235 … … 3623 3723 else if (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER) 3624 3724 { 3725 #ifdef DX_COMMON_STAGING_BUFFER 3625 3726 /* Map the staging buffer. */ 3626 3727 rc = dxStagingBufferRealloc(pDevice, pMipLevel->cbSurface); … … 3661 3762 AssertFailedStmt(rc = VERR_NOT_SUPPORTED); 3662 3763 } 3764 #else 3765 ID3D11Resource *pMappedResource; 3766 if (enmMapType == VMSVGA3D_SURFACE_MAP_READ) 3767 { 3768 pMappedResource = pBackendSurface->staging.pResource; 3769 3770 /* Copy the resource content to the staging resource. */ 3771 ID3D11Resource *pDstResource = pMappedResource; 3772 UINT DstSubresource = 0; 3773 UINT DstX = clipBox.x; 3774 UINT DstY = clipBox.y; 3775 UINT DstZ = clipBox.z; 3776 ID3D11Resource *pSrcResource = pBackendSurface->u.pResource; 3777 UINT SrcSubresource = 0; 3778 D3D11_BOX SrcBox; 3779 SrcBox.left = clipBox.x; 3780 SrcBox.top = clipBox.y; 3781 SrcBox.front = clipBox.z; 3782 SrcBox.right = clipBox.w; 3783 SrcBox.bottom = clipBox.h; 3784 SrcBox.back = clipBox.d; 3785 pDevice->pImmediateContext->CopySubresourceRegion(pDstResource, DstSubresource, DstX, DstY, DstZ, 3786 pSrcResource, SrcSubresource, &SrcBox); 3787 } 3788 else if (enmMapType == VMSVGA3D_SURFACE_MAP_WRITE) 3789 pMappedResource = pBackendSurface->staging.pResource; 3790 else 3791 pMappedResource = pBackendSurface->dynamic.pResource; 3792 3793 UINT const Subresource = 0; /* Dynamic or staging textures have one subresource. */ 3794 HRESULT hr = pDevice->pImmediateContext->Map(pMappedResource, Subresource, 3795 d3d11MapType, /* MapFlags = */ 0, &mappedResource); 3796 if (SUCCEEDED(hr)) 3797 vmsvga3dSurfaceMapInit(pMap, enmMapType, &clipBox, pSurface, 3798 mappedResource.pData, mappedResource.RowPitch, mappedResource.DepthPitch); 3799 else 3800 AssertFailedStmt(rc = VERR_NOT_SUPPORTED); 3801 #endif 3663 3802 } 3664 3803 else … … 3803 3942 Log4(("Unmap buffer sid = %u:\n%.*Rhxd\n", pSurface->id, pMap->cbRow, pMap->pvData)); 3804 3943 3944 #ifdef DX_COMMON_STAGING_BUFFER 3805 3945 /* Unmap the staging buffer. */ 3806 3946 UINT const Subresource = 0; /* Buffers have only one subresource. */ … … 3835 3975 pSrcResource, SrcSubresource, &SrcBox); 3836 3976 } 3977 #else 3978 ID3D11Resource *pMappedResource; 3979 if (pMap->enmMapType == VMSVGA3D_SURFACE_MAP_READ) 3980 pMappedResource = pBackendSurface->staging.pResource; 3981 else if (pMap->enmMapType == VMSVGA3D_SURFACE_MAP_WRITE) 3982 pMappedResource = pBackendSurface->staging.pResource; 3983 else 3984 pMappedResource = pBackendSurface->dynamic.pResource; 3985 3986 UINT const Subresource = 0; /* Staging or dynamic textures have one subresource. */ 3987 pDevice->pImmediateContext->Unmap(pMappedResource, Subresource); 3988 3989 if ( fWritten 3990 && ( pMap->enmMapType == VMSVGA3D_SURFACE_MAP_WRITE 3991 || pMap->enmMapType == VMSVGA3D_SURFACE_MAP_READ_WRITE 3992 || pMap->enmMapType == VMSVGA3D_SURFACE_MAP_WRITE_DISCARD)) 3993 { 3994 ID3D11Resource *pDstResource = pBackendSurface->u.pResource; 3995 UINT DstSubresource = 0; 3996 UINT DstX = pMap->box.x; 3997 UINT DstY = pMap->box.y; 3998 UINT DstZ = pMap->box.z; 3999 ID3D11Resource *pSrcResource = pMappedResource; 4000 UINT SrcSubresource = 0; 4001 D3D11_BOX SrcBox; 4002 SrcBox.left = DstX; 4003 SrcBox.top = DstY; 4004 SrcBox.front = DstZ; 4005 SrcBox.right = DstX + pMap->box.w; 4006 SrcBox.bottom = DstY + pMap->box.h; 4007 SrcBox.back = DstZ + pMap->box.d; 4008 pDevice->pImmediateContext->CopySubresourceRegion(pDstResource, DstSubresource, DstX, DstY, DstZ, 4009 pSrcResource, SrcSubresource, &SrcBox); 4010 4011 pBackendSurface->cidDrawing = pSurface->idAssociatedContext; 4012 } 4013 #endif 3837 4014 } 3838 4015 else … … 5031 5208 else if (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER) 5032 5209 { 5210 #ifndef DX_COMMON_STAGING_BUFFER 5211 D3D_RELEASE(pBackendSurface->staging.pBuffer); 5212 D3D_RELEASE(pBackendSurface->dynamic.pBuffer); 5213 #endif 5033 5214 D3D_RELEASE(pBackendSurface->u.pBuffer); 5034 5215 } … … 5567 5748 pInitialData = &initialData; 5568 5749 5569 // Log(("%.*Rhxd\n", sizeInBytes, initialData.pSysMem)); 5750 #ifdef LOG_ENABLED 5751 if (LogIs8Enabled()) 5752 { 5753 float *pValuesF = (float *)initialData.pSysMem; 5754 for (unsigned i = 0; i < sizeInBytes / sizeof(float) / 4; ++i) 5755 { 5756 Log(("ConstantF[%d]: " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR "\n", 5757 i, FLOAT_FMT_ARGS(pValuesF[i*4 + 0]), FLOAT_FMT_ARGS(pValuesF[i*4 + 1]), FLOAT_FMT_ARGS(pValuesF[i*4 + 2]), FLOAT_FMT_ARGS(pValuesF[i*4 + 3]))); 5758 } 5759 } 5760 #endif 5570 5761 } 5571 5762 … … 6067 6258 } 6068 6259 } 6260 6261 #ifdef LOG_ENABLED 6262 static void dxDbgLogVertexElement(DXGI_FORMAT Format, void const *pvElementData) 6263 { 6264 switch (Format) 6265 { 6266 case DXGI_FORMAT_R32G32B32A32_FLOAT: 6267 { 6268 float const *pValues = (float const *)pvElementData; 6269 Log8(("{ " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR " },", 6270 FLOAT_FMT_ARGS(pValues[0]), FLOAT_FMT_ARGS(pValues[1]), FLOAT_FMT_ARGS(pValues[2]), FLOAT_FMT_ARGS(pValues[3]))); 6271 break; 6272 } 6273 case DXGI_FORMAT_R32G32B32_FLOAT: 6274 { 6275 float const *pValues = (float const *)pvElementData; 6276 Log8(("{ " FLOAT_FMT_STR ", " FLOAT_FMT_STR ", " FLOAT_FMT_STR " },", 6277 FLOAT_FMT_ARGS(pValues[0]), FLOAT_FMT_ARGS(pValues[1]), FLOAT_FMT_ARGS(pValues[2]))); 6278 break; 6279 } 6280 case DXGI_FORMAT_R32G32_FLOAT: 6281 { 6282 float const *pValues = (float const *)pvElementData; 6283 Log8(("{ " FLOAT_FMT_STR ", " FLOAT_FMT_STR " },", 6284 FLOAT_FMT_ARGS(pValues[0]), FLOAT_FMT_ARGS(pValues[1]))); 6285 break; 6286 } 6287 case DXGI_FORMAT_R16G16_FLOAT: 6288 { 6289 uint16_t const *pValues = (uint16_t const *)pvElementData; 6290 Log8(("{ f16 " FLOAT_FMT_STR ", " FLOAT_FMT_STR " },", 6291 FLOAT_FMT_ARGS(float16ToFloat(pValues[0])), FLOAT_FMT_ARGS(float16ToFloat(pValues[1])))); 6292 break; 6293 } 6294 case DXGI_FORMAT_R16G16_SINT: 6295 { 6296 int16_t const *pValues = (int16_t const *)pvElementData; 6297 Log8(("{ s %d, %d },", 6298 pValues[0], pValues[1])); 6299 break; 6300 } 6301 case DXGI_FORMAT_R16G16_UINT: 6302 { 6303 uint16_t const *pValues = (uint16_t const *)pvElementData; 6304 Log8(("{ u %u, %u },", 6305 pValues[0], pValues[1])); 6306 break; 6307 } 6308 case DXGI_FORMAT_R8G8B8A8_UNORM: 6309 { 6310 uint8_t const *pValues = (uint8_t const *)pvElementData; 6311 Log8(("{ 8unorm %u, %u, %u, %u },", 6312 pValues[0], pValues[1], pValues[2], pValues[3])); 6313 break; 6314 } 6315 default: 6316 Log8(("{ ??? DXGI_FORMAT %d },", 6317 Format)); 6318 AssertFailed(); 6319 } 6320 } 6321 6322 6323 static void dxDbgDumpVertices_Draw(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t vertexCount, uint32_t startVertexLocation) 6324 { 6325 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 6326 6327 for (uint32_t iSlot = 0; iSlot < SVGA3D_DX_MAX_VERTEXBUFFERS; ++iSlot) 6328 { 6329 DXBOUNDVERTEXBUFFER *pBufferPipeline = &pBackend->resources.inputAssembly.vertexBuffers[iSlot]; 6330 uint32_t const sid = pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot].bufferId; 6331 if (sid == SVGA3D_INVALID_ID) 6332 { 6333 Assert(pBufferPipeline->pBuffer == 0); 6334 continue; 6335 } 6336 6337 Assert(pBufferPipeline->pBuffer); 6338 6339 SVGA3dSurfaceImageId image; 6340 image.sid = sid; 6341 image.face = 0; 6342 image.mipmap = 0; 6343 6344 VMSVGA3D_MAPPED_SURFACE map; 6345 int rc = vmsvga3dBackSurfaceMap(pThisCC, &image, NULL, VMSVGA3D_SURFACE_MAP_READ, &map); 6346 AssertRC(rc); 6347 if (RT_SUCCESS(rc)) 6348 { 6349 uint8_t const *pu8VertexData = (uint8_t *)map.pvData; 6350 pu8VertexData += pBufferPipeline->offset; 6351 pu8VertexData += startVertexLocation * pBufferPipeline->stride; 6352 6353 SVGA3dElementLayoutId const elementLayoutId = pDXContext->svgaDXContext.inputAssembly.layoutId; 6354 DXELEMENTLAYOUT *pDXElementLayout = &pDXContext->pBackendDXContext->paElementLayout[elementLayoutId]; 6355 Assert(pDXElementLayout->cElementDesc > 0); 6356 6357 Log8(("Vertex buffer dump: sid = %u, vertexCount %u, startVertexLocation %d, offset = %d, stride = %d:\n", 6358 sid, vertexCount, startVertexLocation, pBufferPipeline->offset, pBufferPipeline->stride)); 6359 6360 for (uint32_t v = 0; v < vertexCount; ++v) 6361 { 6362 Log8(("slot[%u] v%u { ", iSlot, startVertexLocation + v)); 6363 6364 for (uint32_t iElement = 0; iElement < pDXElementLayout->cElementDesc; ++iElement) 6365 { 6366 D3D11_INPUT_ELEMENT_DESC *pElement = &pDXElementLayout->aElementDesc[iElement]; 6367 if (pElement->InputSlot == iSlot) 6368 dxDbgLogVertexElement(pElement->Format, pu8VertexData + pElement->AlignedByteOffset); 6369 } 6370 6371 Log8((" }\n")); 6372 6373 if (pBufferPipeline->stride == 0) 6374 break; 6375 6376 pu8VertexData += pBufferPipeline->stride; 6377 } 6378 6379 vmsvga3dBackSurfaceUnmap(pThisCC, &image, &map, /* fWritten = */ false); 6380 } 6381 } 6382 } 6383 6384 6385 static void dxDbgDumpVertices_DrawIndexed(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t indexCount, uint32_t startIndexLocation, int32_t baseVertexLocation) 6386 { 6387 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 6388 DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext); 6389 SVGA3dSurfaceImageId image; 6390 //DEBUG_BREAKPOINT_TEST(); 6391 DXBOUNDINDEXBUFFER *pIB = &pBackend->resources.inputAssembly.indexBuffer; 6392 uint32_t const sidIB = pDXContext->svgaDXContext.inputAssembly.indexBufferSid; 6393 if (sidIB == SVGA3D_INVALID_ID) 6394 { 6395 Assert(pIB->pBuffer == 0); 6396 return; 6397 } 6398 6399 Assert(pIB->pBuffer); 6400 UINT const BytesPerIndex = pIB->indexBufferFormat == DXGI_FORMAT_R16_UINT ? 2 : 4; 6401 6402 void *pvIndexBuffer; 6403 uint32_t cbIndexBuffer; 6404 int rc = dxReadBuffer(pDXDevice, pIB->pBuffer, pIB->indexBufferOffset + startIndexLocation, indexCount * BytesPerIndex, &pvIndexBuffer, &cbIndexBuffer); 6405 AssertRC(rc); 6406 if (RT_SUCCESS(rc)) 6407 { 6408 uint8_t const *pu8IndexData = (uint8_t *)pvIndexBuffer; 6409 6410 for (uint32_t iSlot = 0; iSlot < SVGA3D_DX_MAX_VERTEXBUFFERS; ++iSlot) 6411 { 6412 DXBOUNDVERTEXBUFFER *pVB = &pBackend->resources.inputAssembly.vertexBuffers[iSlot]; 6413 uint32_t const sidVB = pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot].bufferId; 6414 if (sidVB == SVGA3D_INVALID_ID) 6415 { 6416 Assert(pVB->pBuffer == 0); 6417 continue; 6418 } 6419 6420 Assert(pVB->pBuffer); 6421 6422 image.sid = sidVB; 6423 image.face = 0; 6424 image.mipmap = 0; 6425 6426 VMSVGA3D_MAPPED_SURFACE mapVB; 6427 rc = vmsvga3dBackSurfaceMap(pThisCC, &image, NULL, VMSVGA3D_SURFACE_MAP_READ, &mapVB); 6428 AssertRC(rc); 6429 if (RT_SUCCESS(rc)) 6430 { 6431 uint8_t const *pu8VertexData = (uint8_t *)mapVB.pvData; 6432 pu8VertexData += pVB->offset; 6433 pu8VertexData += baseVertexLocation * pVB->stride; 6434 6435 SVGA3dElementLayoutId const elementLayoutId = pDXContext->svgaDXContext.inputAssembly.layoutId; 6436 DXELEMENTLAYOUT *pDXElementLayout = &pDXContext->pBackendDXContext->paElementLayout[elementLayoutId]; 6437 Assert(pDXElementLayout->cElementDesc > 0); 6438 6439 Log8(("Vertex buffer dump: sid = %u, indexCount %u, startIndexLocation %d, baseVertexLocation %d, offset = %d, stride = %d:\n", 6440 sidVB, indexCount, startIndexLocation, baseVertexLocation, pVB->offset, pVB->stride)); 6441 6442 for (uint32_t i = 0; i < indexCount; ++i) 6443 { 6444 uint32_t Index; 6445 if (BytesPerIndex == 2) 6446 Index = ((uint16_t *)pu8IndexData)[i]; 6447 else 6448 Index = ((uint32_t *)pu8IndexData)[i]; 6449 6450 Log8(("slot[%u] v%u { ", iSlot, Index)); 6451 6452 for (uint32_t iElement = 0; iElement < pDXElementLayout->cElementDesc; ++iElement) 6453 { 6454 D3D11_INPUT_ELEMENT_DESC *pElement = &pDXElementLayout->aElementDesc[iElement]; 6455 if (pElement->InputSlot == iSlot) 6456 { 6457 uint8_t const *pu8Vertex = pu8VertexData + Index * pVB->stride; 6458 dxDbgLogVertexElement(pElement->Format, pu8Vertex + pElement->AlignedByteOffset); 6459 } 6460 } 6461 6462 Log8((" }\n")); 6463 6464 if (pVB->stride == 0) 6465 break; 6466 } 6467 6468 vmsvga3dBackSurfaceUnmap(pThisCC, &image, &mapVB, /* fWritten = */ false); 6469 } 6470 } 6471 6472 RTMemFree(pvIndexBuffer); 6473 } 6474 } 6475 #endif 6476 6069 6477 6070 6478 static void dxSetupPipeline(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext) … … 6478 6886 dxSetupPipeline(pThisCC, pDXContext); 6479 6887 6888 #ifdef LOG_ENABLED 6889 if (LogIs8Enabled()) 6890 dxDbgDumpVertices_Draw(pThisCC, pDXContext, vertexCount, startVertexLocation); 6891 #endif 6892 6480 6893 if (pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN) 6481 6894 pDevice->pImmediateContext->Draw(vertexCount, startVertexLocation); … … 6552 6965 dxTrackRenderTargets(pThisCC, pDXContext); 6553 6966 6967 #ifdef DX_FLUSH_AFTER_DRAW 6968 dxDeviceFlush(pDevice); 6969 #endif 6970 6554 6971 return VINF_SUCCESS; 6555 6972 } … … 6571 6988 *pcbData = Bytes; 6572 6989 6990 #ifdef DX_COMMON_STAGING_BUFFER 6573 6991 int rc = dxStagingBufferRealloc(pDevice, Bytes); 6574 6992 if (RT_SUCCESS(rc)) … … 6607 7025 6608 7026 } 7027 #else 7028 uint32_t const cbAlloc = Bytes; 7029 7030 D3D11_SUBRESOURCE_DATA *pInitialData = NULL; 7031 D3D11_BUFFER_DESC bd; 7032 RT_ZERO(bd); 7033 bd.ByteWidth = Bytes; 7034 bd.Usage = D3D11_USAGE_STAGING; 7035 //bd.BindFlags = 0; /* No bind flags are allowed for staging resources. */ 7036 bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ; 7037 7038 int rc = VINF_SUCCESS; 7039 ID3D11Buffer *pStagingBuffer; 7040 HRESULT hr = pDevice->pDevice->CreateBuffer(&bd, pInitialData, &pStagingBuffer); 7041 if (SUCCEEDED(hr)) 7042 { 7043 /* Copy from the buffer to the staging buffer. */ 7044 ID3D11Resource *pDstResource = pStagingBuffer; 7045 UINT DstSubresource = 0; 7046 UINT DstX = 0; 7047 UINT DstY = 0; 7048 UINT DstZ = 0; 7049 ID3D11Resource *pSrcResource = pBuffer; 7050 UINT SrcSubresource = 0; 7051 D3D11_BOX SrcBox; 7052 SrcBox.left = Offset; 7053 SrcBox.top = 0; 7054 SrcBox.front = 0; 7055 SrcBox.right = Offset + Bytes; 7056 SrcBox.bottom = 1; 7057 SrcBox.back = 1; 7058 pDevice->pImmediateContext->CopySubresourceRegion(pDstResource, DstSubresource, DstX, DstY, DstZ, 7059 pSrcResource, SrcSubresource, &SrcBox); 7060 7061 D3D11_MAPPED_SUBRESOURCE mappedResource; 7062 UINT const Subresource = 0; /* Buffers have only one subresource. */ 7063 hr = pDevice->pImmediateContext->Map(pStagingBuffer, Subresource, 7064 D3D11_MAP_READ, /* MapFlags = */ 0, &mappedResource); 7065 if (SUCCEEDED(hr)) 7066 { 7067 memcpy(pvData, mappedResource.pData, Bytes); 7068 7069 /* Unmap the staging buffer. */ 7070 pDevice->pImmediateContext->Unmap(pStagingBuffer, Subresource); 7071 } 7072 else 7073 AssertFailedStmt(rc = VERR_NOT_SUPPORTED); 7074 7075 D3D_RELEASE(pStagingBuffer); 7076 } 7077 else 7078 { 7079 rc = VERR_NO_MEMORY; 7080 } 7081 #endif 6609 7082 6610 7083 if (RT_FAILURE(rc)) … … 6736 7209 dxSetupPipeline(pThisCC, pDXContext); 6737 7210 7211 #ifdef LOG_ENABLED 7212 if (LogIs8Enabled()) 7213 dxDbgDumpVertices_DrawIndexed(pThisCC, pDXContext, indexCount, startIndexLocation, baseVertexLocation); 7214 #endif 7215 6738 7216 if (pDXContext->svgaDXContext.inputAssembly.topology != SVGA3D_PRIMITIVE_TRIANGLEFAN) 6739 7217 pDevice->pImmediateContext->DrawIndexed(indexCount, startIndexLocation, baseVertexLocation); … … 6746 7224 dxTrackRenderTargets(pThisCC, pDXContext); 6747 7225 7226 #ifdef DX_FLUSH_AFTER_DRAW 7227 dxDeviceFlush(pDevice); 7228 #endif 7229 6748 7230 return VINF_SUCCESS; 6749 7231 } … … 6768 7250 dxTrackRenderTargets(pThisCC, pDXContext); 6769 7251 7252 #ifdef DX_FLUSH_AFTER_DRAW 7253 dxDeviceFlush(pDevice); 7254 #endif 7255 6770 7256 return VINF_SUCCESS; 6771 7257 } … … 6790 7276 dxTrackRenderTargets(pThisCC, pDXContext); 6791 7277 7278 #ifdef DX_FLUSH_AFTER_DRAW 7279 dxDeviceFlush(pDevice); 7280 #endif 7281 6792 7282 return VINF_SUCCESS; 6793 7283 } … … 6810 7300 /* Note which surfaces are being drawn. */ 6811 7301 dxTrackRenderTargets(pThisCC, pDXContext); 7302 7303 #ifdef DX_FLUSH_AFTER_DRAW 7304 dxDeviceFlush(pDevice); 7305 #endif 6812 7306 6813 7307 return VINF_SUCCESS; … … 9292 9786 dxTrackRenderTargets(pThisCC, pDXContext); 9293 9787 9788 #ifdef DX_FLUSH_AFTER_DRAW 9789 dxDeviceFlush(pDevice); 9790 #endif 9791 9294 9792 return VINF_SUCCESS; 9295 9793 } … … 9333 9831 dxTrackRenderTargets(pThisCC, pDXContext); 9334 9832 9833 #ifdef DX_FLUSH_AFTER_DRAW 9834 dxDeviceFlush(pDevice); 9835 #endif 9836 9335 9837 return VINF_SUCCESS; 9336 9838 } … … 9348 9850 9349 9851 pDevice->pImmediateContext->Dispatch(threadGroupCountX, threadGroupCountY, threadGroupCountZ); 9852 9853 #ifdef DX_FLUSH_AFTER_DRAW 9854 dxDeviceFlush(pDevice); 9855 #endif 9350 9856 9351 9857 return VINF_SUCCESS; -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.h
r98103 r99521 686 686 687 687 688 float float16ToFloat(uint16_t f16); 689 690 688 691 #endif /* !VBOX_INCLUDED_SRC_Graphics_DevVGA_SVGA3d_h */ 689 692
Note:
See TracChangeset
for help on using the changeset viewer.