Changeset 102714 in vbox
- Timestamp:
- Dec 27, 2023 3:34:25 PM (11 months ago)
- Location:
- trunk/src/VBox/Devices/Graphics
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx-dx11.cpp
r102626 r102714 320 320 typedef struct DXBOUNDRESOURCES /* Currently bound resources. Mirror SVGADXContextMobFormat structure. */ 321 321 { 322 struct323 {324 DXBOUNDVERTEXBUFFER vertexBuffers[SVGA3D_DX_MAX_VERTEXBUFFERS];325 DXBOUNDINDEXBUFFER indexBuffer;326 } inputAssembly;327 322 struct 328 323 { … … 393 388 UINT VendorId; 394 389 UINT DeviceId; 390 391 SVGADXContextMobFormat svgaDXContext; /* Current state of pipeline. */ 395 392 396 393 DXBOUNDRESOURCES resources; /* What is currently applied to the pipeline. */ … … 3281 3278 bd.Usage = D3D11_USAGE_DYNAMIC; 3282 3279 else if (pSurface->f.surfaceFlags & SVGA3D_SURFACE_HINT_STATIC) 3283 bd.Usage = pInitialData ? D3D11_USAGE_IMMUTABLE : D3D11_USAGE_DEFAULT; /* Guest will update later. */ 3280 { 3281 /* Use D3D11_USAGE_DEFAULT instead of D3D11_USAGE_IMMUTABLE to let the guest the guest update 3282 * the buffer later. 3283 * 3284 * The guest issues SVGA_3D_CMD_INVALIDATE_GB_IMAGE followed by SVGA_3D_CMD_UPDATE_GB_IMAGE 3285 * when the data in SVGA3D_SURFACE_HINT_STATIC surface is updated. 3286 * D3D11_USAGE_IMMUTABLE would work if the device destroys the D3D buffer on INVALIDATE 3287 * and re-creates it in setupPipeline with initial data from the backing guest MOB. 3288 * Currently the device does not destroy the buffer on INVALIDATE. So just use D3D11_USAGE_DEFAULT. 3289 */ 3290 bd.Usage = D3D11_USAGE_DEFAULT; 3291 } 3284 3292 else if (pSurface->f.surfaceFlags & SVGA3D_SURFACE_HINT_INDIRECT_UPDATE) 3285 3293 bd.Usage = D3D11_USAGE_DEFAULT; … … 3383 3391 3384 3392 AssertRCReturn(rc, rc); 3393 LogFunc(("Created for sid = %u\n", sid)); 3385 3394 } 3386 3395 … … 3474 3483 LogRelMax(1, ("VMSVGA: Single DX device mode: %s\n", pBackend->fSingleDevice ? "enabled" : "disabled")); 3475 3484 3485 vmsvga3dDXInitContextMobData(&pBackend->svgaDXContext); /** @todo */ 3476 3486 //DEBUG_BREAKPOINT_TEST(); 3477 3487 return rc; … … 5616 5626 } 5617 5627 5618 for (uint32_t i = 0; i < RT_ELEMENTS(pBackendDXContext->resources.inputAssembly.vertexBuffers); ++i)5619 {5620 D3D_RELEASE(pBackendDXContext->resources.inputAssembly.vertexBuffers[i].pBuffer);5621 }5622 5623 D3D_RELEASE(pBackendDXContext->resources.inputAssembly.indexBuffer.pBuffer);5624 5625 5628 if (pBackendDXContext->dxDevice.pImmediateContext) 5626 5629 dxDeviceFlush(&pBackendDXContext->dxDevice); /* Make sure that any pending draw calls are finished. */ … … 6254 6257 static void dxSetVertexBuffers(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext) 6255 6258 { 6256 //DEBUG_BREAKPOINT_TEST();6257 6259 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 6258 DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);6259 VMSVGA3DBACKENDDXCONTEXT *pBackendDXContext = pDXContext->pBackendDXContext;6260 6261 AssertCompile(RT_ELEMENTS(pBackendDXContext->resources.inputAssembly.vertexBuffers) == SVGA3D_DX_MAX_VERTEXBUFFERS);6262 6260 6263 6261 ID3D11Buffer *paResources[SVGA3D_DX_MAX_VERTEXBUFFERS]; … … 6265 6263 UINT paOffset[SVGA3D_DX_MAX_VERTEXBUFFERS]; 6266 6264 6265 int32_t idxMinSlot = SVGA3D_DX_MAX_VERTEXBUFFERS; 6267 6266 int32_t idxMaxSlot = -1; 6268 for (uint32_t i = 0; i < SVGA3D_DX_MAX_VERTEXBUFFERS; ++i) 6269 { 6270 DXBOUNDVERTEXBUFFER *pBufferContext = &pBackendDXContext->resources.inputAssembly.vertexBuffers[i]; 6271 DXBOUNDVERTEXBUFFER *pBufferPipeline = &pBackend->resources.inputAssembly.vertexBuffers[i]; 6272 if ( pBufferContext->pBuffer != pBufferPipeline->pBuffer 6267 for (int32_t i = 0; i < SVGA3D_DX_MAX_VERTEXBUFFERS; ++i) 6268 { 6269 SVGA3dBufferBinding const *pBufferContext = &pDXContext->svgaDXContext.inputAssembly.vertexBuffers[i]; 6270 SVGA3dBufferBinding *pBufferPipeline = &pBackend->svgaDXContext.inputAssembly.vertexBuffers[i]; 6271 6272 if ( pBufferContext->bufferId != pBufferPipeline->bufferId 6273 6273 || pBufferContext->stride != pBufferPipeline->stride 6274 6274 || pBufferContext->offset != pBufferPipeline->offset) 6275 6275 { 6276 LogFunc(("vertex buffer: [%u]: sid = %u, %p (stride %d, off %d) -> %p (stride %d, off %d)\n", 6277 i, pDXContext->svgaDXContext.inputAssembly.vertexBuffers[i].bufferId, 6278 pBufferPipeline->pBuffer, pBufferPipeline->stride, pBufferPipeline->offset, 6279 pBufferContext->pBuffer, pBufferContext->stride, pBufferContext->offset)); 6280 6281 if (pBufferContext->pBuffer != pBufferPipeline->pBuffer) 6282 { 6283 if (pBufferContext->pBuffer) 6284 pBufferContext->pBuffer->AddRef(); 6285 D3D_RELEASE(pBufferPipeline->pBuffer); 6286 } 6276 /* The slot has a new buffer. */ 6277 LogFunc(("vb[%u]: sid = %u, stride %d, off %d -> sid = %u, stride %d, off %d\n", 6278 i, pBufferPipeline->bufferId, pBufferPipeline->stride, pBufferPipeline->offset, 6279 pBufferContext->bufferId, pBufferContext->stride, pBufferContext->offset)); 6280 6287 6281 *pBufferPipeline = *pBufferContext; 6288 6282 6289 idxMaxSlot = i; 6283 idxMaxSlot = RT_MAX(idxMaxSlot, i); 6284 idxMinSlot = RT_MIN(idxMinSlot, i); 6290 6285 } 6291 6286 #ifdef LOG_ENABLED 6292 else if (pBufferContext->pBuffer) 6293 { 6294 LogFunc(("vertex buffer: [%u]: sid = %u, %p (stride %d, off %d)\n", 6295 i, pDXContext->svgaDXContext.inputAssembly.vertexBuffers[i].bufferId, 6296 pBufferContext->pBuffer, pBufferContext->stride, pBufferContext->offset)); 6287 else if (pBufferPipeline->bufferId != SVGA3D_INVALID_ID) 6288 { 6289 LogFunc(("vb[%u]: sid = %u, stride %d, off %d\n", 6290 i, pBufferPipeline->bufferId, pBufferPipeline->stride, pBufferPipeline->offset)); 6297 6291 } 6298 6292 #endif 6299 6300 paResources[i] = pBufferContext->pBuffer; 6301 if (pBufferContext->pBuffer) 6302 { 6303 paStride[i] = pBufferContext->stride; 6304 paOffset[i] = pBufferContext->offset; 6293 ID3D11Buffer *pBuffer = NULL; 6294 if (pBufferPipeline->bufferId != SVGA3D_INVALID_ID) 6295 { 6296 PVMSVGA3DSURFACE pSurface; 6297 ID3D11Resource *pResource; 6298 int rc = dxEnsureResource(pThisCC, pDXContext, pBufferPipeline->bufferId, &pSurface, &pResource); 6299 if ( RT_SUCCESS(rc) 6300 && pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER) 6301 pBuffer = (ID3D11Buffer *)pResource; 6302 else 6303 AssertMsgFailed(("%Rrc %p %d\n", rc, pSurface->pBackendSurface, pSurface->pBackendSurface ? pSurface->pBackendSurface->enmResType : VMSVGA3D_RESTYPE_NONE)); 6304 } 6305 6306 paResources[i] = pBuffer; 6307 if (pBuffer) 6308 { 6309 LogFunc(("vb[%u]: %p\n", i, pBuffer)); 6310 paStride[i] = pBufferPipeline->stride; 6311 paOffset[i] = pBufferPipeline->offset; 6305 6312 } 6306 6313 else … … 6311 6318 } 6312 6319 6313 LogFunc(("idxMaxSlot = %d\n", idxMaxSlot)); 6320 DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext); 6321 LogFunc(("idxMinSlot = %d, idxMaxSlot = %d\n", idxMinSlot, idxMaxSlot)); 6314 6322 if (idxMaxSlot >= 0) 6315 pDXDevice->pImmediateContext->IASetVertexBuffers(0, idxMaxSlot + 1, paResources, paStride, paOffset); 6323 pDXDevice->pImmediateContext->IASetVertexBuffers(idxMinSlot, (idxMaxSlot - idxMinSlot) + 1, 6324 &paResources[idxMinSlot], &paStride[idxMinSlot], &paOffset[idxMinSlot]); 6316 6325 } 6317 6326 6318 6327 static void dxSetIndexBuffer(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext) 6319 6328 { 6320 //DEBUG_BREAKPOINT_TEST();6321 6329 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 6330 6331 SVGADXContextMobFormat *pPipelineState = &pBackend->svgaDXContext; 6332 SVGADXContextMobFormat const *pContextState = &pDXContext->svgaDXContext; 6333 6334 if ( pPipelineState->inputAssembly.indexBufferSid != pContextState->inputAssembly.indexBufferSid 6335 || pPipelineState->inputAssembly.indexBufferOffset != pContextState->inputAssembly.indexBufferOffset 6336 || pPipelineState->inputAssembly.indexBufferFormat != pContextState->inputAssembly.indexBufferFormat) 6337 { 6338 LogFunc(("ib: sid = %u, offset %u, fmt %u -> sid = %u, offset %u, fmt %u\n", 6339 pPipelineState->inputAssembly.indexBufferSid, pPipelineState->inputAssembly.indexBufferOffset, pPipelineState->inputAssembly.indexBufferFormat, 6340 pContextState->inputAssembly.indexBufferSid, pContextState->inputAssembly.indexBufferOffset, pContextState->inputAssembly.indexBufferFormat)); 6341 6342 pPipelineState->inputAssembly.indexBufferSid = pContextState->inputAssembly.indexBufferSid; 6343 pPipelineState->inputAssembly.indexBufferOffset = pContextState->inputAssembly.indexBufferOffset; 6344 pPipelineState->inputAssembly.indexBufferFormat = pContextState->inputAssembly.indexBufferFormat; 6345 } 6346 #ifdef LOG_ENABLED 6347 else if (pPipelineState->inputAssembly.indexBufferSid != SVGA3D_INVALID_ID) 6348 { 6349 LogFunc(("ib: sid = %u, offset %u, fmt %u\n", 6350 pPipelineState->inputAssembly.indexBufferSid, pPipelineState->inputAssembly.indexBufferOffset, pPipelineState->inputAssembly.indexBufferFormat)); 6351 } 6352 #endif 6353 6354 ID3D11Buffer *pBuffer = NULL; 6355 if (pPipelineState->inputAssembly.indexBufferSid != SVGA3D_INVALID_ID) 6356 { 6357 PVMSVGA3DSURFACE pSurface; 6358 ID3D11Resource *pResource; 6359 int rc = dxEnsureResource(pThisCC, pDXContext, pPipelineState->inputAssembly.indexBufferSid, &pSurface, &pResource); 6360 if ( RT_SUCCESS(rc) 6361 && pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER) 6362 pBuffer = (ID3D11Buffer *)pResource; 6363 else 6364 AssertMsgFailed(("%Rrc %p %d\n", rc, pSurface->pBackendSurface, pSurface->pBackendSurface ? pSurface->pBackendSurface->enmResType : VMSVGA3D_RESTYPE_NONE)); 6365 } 6366 6367 DXGI_FORMAT enmDxgiFormat; 6368 UINT Offset; 6369 if (pBuffer) 6370 { 6371 enmDxgiFormat = vmsvgaDXSurfaceFormat2Dxgi((SVGA3dSurfaceFormat)pPipelineState->inputAssembly.indexBufferFormat); 6372 AssertReturnVoid(enmDxgiFormat == DXGI_FORMAT_R16_UINT || enmDxgiFormat == DXGI_FORMAT_R32_UINT); 6373 Offset = pPipelineState->inputAssembly.indexBufferOffset; 6374 } 6375 else 6376 { 6377 enmDxgiFormat = DXGI_FORMAT_UNKNOWN; 6378 Offset = 0; 6379 } 6380 6322 6381 DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext); 6323 VMSVGA3DBACKENDDXCONTEXT *pBackendDXContext = pDXContext->pBackendDXContext; 6324 6325 DXBOUNDINDEXBUFFER *pBufferContext = &pBackendDXContext->resources.inputAssembly.indexBuffer; 6326 DXBOUNDINDEXBUFFER *pBufferPipeline = &pBackend->resources.inputAssembly.indexBuffer; 6327 if ( pBufferContext->pBuffer != pBufferPipeline->pBuffer 6328 || pBufferContext->indexBufferOffset != pBufferPipeline->indexBufferOffset 6329 || pBufferContext->indexBufferFormat != pBufferPipeline->indexBufferFormat) 6330 { 6331 LogFunc(("index_buffer: sid = %u, %p -> %p\n", 6332 pDXContext->svgaDXContext.inputAssembly.indexBufferSid, pBufferPipeline->pBuffer, pBufferContext->pBuffer)); 6333 6334 if (pBufferContext->pBuffer != pBufferPipeline->pBuffer) 6335 { 6336 if (pBufferContext->pBuffer) 6337 pBufferContext->pBuffer->AddRef(); 6338 D3D_RELEASE(pBufferPipeline->pBuffer); 6339 } 6340 *pBufferPipeline = *pBufferContext; 6341 6342 pDXDevice->pImmediateContext->IASetIndexBuffer(pBufferContext->pBuffer, pBufferContext->indexBufferFormat, pBufferContext->indexBufferOffset); 6343 } 6382 pDXDevice->pImmediateContext->IASetIndexBuffer(pBuffer, enmDxgiFormat, Offset); 6344 6383 } 6345 6384 … … 6507 6546 static void dxDbgDumpVertexData(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t vertexCount, uint32_t startVertexLocation) 6508 6547 { 6509 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;6510 6511 6548 for (uint32_t iSlot = 0; iSlot < SVGA3D_DX_MAX_VERTEXBUFFERS; ++iSlot) 6512 6549 { 6513 DXBOUNDVERTEXBUFFER *pBufferPipeline = &pBackend->resources.inputAssembly.vertexBuffers[iSlot]; 6514 uint32_t const sid = pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot].bufferId; 6515 if (sid == SVGA3D_INVALID_ID) 6516 { 6517 Assert(pBufferPipeline->pBuffer == 0); 6550 SVGA3dBufferBinding const *pVBInfo = &pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot]; 6551 if (pVBInfo->bufferId == SVGA3D_INVALID_ID) 6518 6552 continue; 6519 } 6520 6521 Assert(pBufferPipeline->pBuffer); 6553 6554 PVMSVGA3DSURFACE pSurface = NULL; 6555 int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, pVBInfo->bufferId, &pSurface); 6556 AssertContinue(RT_SUCCESS(rc)); 6557 AssertContinue(pSurface->pBackendSurface->u.pBuffer && pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER); 6522 6558 6523 6559 SVGA3dSurfaceImageId image; 6524 image.sid = sid;6560 image.sid = pVBInfo->bufferId; 6525 6561 image.face = 0; 6526 6562 image.mipmap = 0; 6527 6563 6528 6564 VMSVGA3D_MAPPED_SURFACE map; 6529 intrc = vmsvga3dBackSurfaceMap(pThisCC, &image, NULL, VMSVGA3D_SURFACE_MAP_READ, &map);6565 rc = vmsvga3dBackSurfaceMap(pThisCC, &image, NULL, VMSVGA3D_SURFACE_MAP_READ, &map); 6530 6566 AssertRC(rc); 6531 6567 if (RT_SUCCESS(rc)) 6532 6568 { 6533 6569 uint8_t const *pu8VertexData = (uint8_t *)map.pvData; 6534 pu8VertexData += p BufferPipeline->offset;6535 pu8VertexData += startVertexLocation * p BufferPipeline->stride;6570 pu8VertexData += pVBInfo->offset; 6571 pu8VertexData += startVertexLocation * pVBInfo->stride; 6536 6572 6537 6573 SVGA3dElementLayoutId const elementLayoutId = pDXContext->svgaDXContext.inputAssembly.layoutId; … … 6540 6576 6541 6577 Log8(("Vertex buffer dump: sid = %u, vertexCount %u, startVertexLocation %d, offset = %d, stride = %d:\n", 6542 sid, vertexCount, startVertexLocation, pBufferPipeline->offset, pBufferPipeline->stride));6578 pVBInfo->bufferId, vertexCount, startVertexLocation, pVBInfo->offset, pVBInfo->stride)); 6543 6579 6544 6580 for (uint32_t v = 0; v < vertexCount; ++v) … … 6555 6591 Log8((" },\n")); 6556 6592 6557 if (p BufferPipeline->stride == 0)6593 if (pVBInfo->stride == 0) 6558 6594 break; 6559 6595 6560 pu8VertexData += p BufferPipeline->stride;6596 pu8VertexData += pVBInfo->stride; 6561 6597 } 6562 6598 … … 6569 6605 static void dxDbgDumpIndexedVertexData(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t indexCount, uint32_t startIndexLocation, int32_t baseVertexLocation) 6570 6606 { 6571 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;6572 6607 DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext); 6573 SVGA3dSurfaceImageId image; 6574 6575 DXBOUNDINDEXBUFFER *pIB = &pBackend->resources.inputAssembly.indexBuffer; 6576 uint32_t const sidIB = pDXContext->svgaDXContext.inputAssembly.indexBufferSid; 6577 if (sidIB == SVGA3D_INVALID_ID) 6578 { 6579 Assert(pIB->pBuffer == 0); 6608 6609 uint32_t const indexBufferSid = pDXContext->svgaDXContext.inputAssembly.indexBufferSid; 6610 if (indexBufferSid == SVGA3D_INVALID_ID) 6580 6611 return; 6581 } 6582 6583 Assert(pIB->pBuffer); 6584 UINT const BytesPerIndex = pIB->indexBufferFormat == DXGI_FORMAT_R16_UINT ? 2 : 4; 6612 uint32_t const indexBufferFormat = pDXContext->svgaDXContext.inputAssembly.indexBufferFormat; 6613 uint32_t const indexBufferOffset = pDXContext->svgaDXContext.inputAssembly.indexBufferOffset; 6614 6615 PVMSVGA3DSURFACE pSurface = NULL; 6616 int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, indexBufferSid, &pSurface); 6617 AssertReturnVoid(RT_SUCCESS(rc)); 6618 AssertReturnVoid(pSurface->pBackendSurface->u.pBuffer && pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER); 6619 6620 UINT const BytesPerIndex = indexBufferFormat == SVGA3D_R16_UINT ? 2 : 4; 6585 6621 6586 6622 void *pvIndexBuffer; 6587 6623 uint32_t cbIndexBuffer; 6588 int rc = dxReadBuffer(pDXDevice, pIB->pBuffer, pIB->indexBufferOffset + startIndexLocation * BytesPerIndex, indexCount * BytesPerIndex, &pvIndexBuffer, &cbIndexBuffer); 6624 rc = dxReadBuffer(pDXDevice, pSurface->pBackendSurface->u.pBuffer, 6625 indexBufferOffset + startIndexLocation * BytesPerIndex, 6626 indexCount * BytesPerIndex, &pvIndexBuffer, &cbIndexBuffer); 6589 6627 AssertRC(rc); 6590 6628 if (RT_SUCCESS(rc)) … … 6594 6632 for (uint32_t iSlot = 0; iSlot < SVGA3D_DX_MAX_VERTEXBUFFERS; ++iSlot) 6595 6633 { 6596 DXBOUNDVERTEXBUFFER *pVB = &pBackend->resources.inputAssembly.vertexBuffers[iSlot]; 6597 uint32_t const sidVB = pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot].bufferId; 6598 if (sidVB == SVGA3D_INVALID_ID) 6599 { 6600 Assert(pVB->pBuffer == 0); 6634 SVGA3dBufferBinding const *pVBInfo = &pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot]; 6635 if (pVBInfo->bufferId == SVGA3D_INVALID_ID) 6601 6636 continue; 6602 } 6603 6604 Assert(pVB->pBuffer); 6605 6606 image.sid = sidVB; 6637 6638 pSurface = NULL; 6639 rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, pVBInfo->bufferId, &pSurface); 6640 AssertContinue(RT_SUCCESS(rc)); 6641 AssertContinue(pSurface->pBackendSurface->u.pBuffer && pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER); 6642 6643 SVGA3dSurfaceImageId image; 6644 image.sid = pVBInfo->bufferId; 6607 6645 image.face = 0; 6608 6646 image.mipmap = 0; … … 6614 6652 { 6615 6653 uint8_t const *pu8VertexData = (uint8_t *)mapVB.pvData; 6616 pu8VertexData += pVB ->offset;6617 pu8VertexData += baseVertexLocation * pVB ->stride;6654 pu8VertexData += pVBInfo->offset; 6655 pu8VertexData += baseVertexLocation * pVBInfo->stride; 6618 6656 6619 6657 SVGA3dElementLayoutId const elementLayoutId = pDXContext->svgaDXContext.inputAssembly.layoutId; … … 6622 6660 6623 6661 Log8(("Vertex buffer dump: sid = %u, indexCount %u, startIndexLocation %d, baseVertexLocation %d, offset = %d, stride = %d:\n", 6624 sidVB, indexCount, startIndexLocation, baseVertexLocation, pVB->offset, pVB->stride));6662 pVBInfo->bufferId, indexCount, startIndexLocation, baseVertexLocation, pVBInfo->offset, pVBInfo->stride)); 6625 6663 6626 6664 for (uint32_t i = 0; i < indexCount; ++i) … … 6642 6680 if (pElement->InputSlot == iSlot) 6643 6681 { 6644 uint8_t const *pu8Vertex = pu8VertexData + Index * pVB ->stride;6682 uint8_t const *pu8Vertex = pu8VertexData + Index * pVBInfo->stride; 6645 6683 dxDbgLogVertexElement(pElement->Format, pu8Vertex + pElement->AlignedByteOffset); 6646 6684 } … … 6649 6687 Log8((" },\n")); 6650 6688 6651 if (pVB ->stride == 0)6689 if (pVBInfo->stride == 0) 6652 6690 break; 6653 6691 } … … 6664 6702 static void dxDbgDumpInstanceData(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t instanceCount, uint32_t startInstanceLocation) 6665 6703 { 6666 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;6667 SVGA3dSurfaceImageId image;6668 6669 6704 /* 6670 6705 * Dump per-instance data. … … 6674 6709 for (uint32_t iSlot = 0; iSlot < SVGA3D_DX_MAX_VERTEXBUFFERS; ++iSlot) 6675 6710 { 6676 DXBOUNDVERTEXBUFFER *pVB = &pBackend->resources.inputAssembly.vertexBuffers[iSlot]; 6677 uint32_t const sidVB = pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot].bufferId; 6678 if (sidVB == SVGA3D_INVALID_ID) 6679 { 6680 Assert(pVB->pBuffer == 0); 6711 SVGA3dBufferBinding const *pVBInfo = &pDXContext->svgaDXContext.inputAssembly.vertexBuffers[iSlot]; 6712 if (pVBInfo->bufferId == SVGA3D_INVALID_ID) 6681 6713 continue; 6682 } 6683 6684 Assert(pVB->pBuffer); 6685 6686 image.sid = sidVB; 6714 6715 PVMSVGA3DSURFACE pSurface = NULL; 6716 int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, pVBInfo->bufferId, &pSurface); 6717 AssertContinue(RT_SUCCESS(rc)); 6718 AssertContinue(pSurface->pBackendSurface->u.pBuffer && pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER); 6719 6720 SVGA3dSurfaceImageId image; 6721 image.sid = pVBInfo->bufferId; 6687 6722 image.face = 0; 6688 6723 image.mipmap = 0; 6689 6724 6690 6725 VMSVGA3D_MAPPED_SURFACE mapVB; 6691 intrc = vmsvga3dBackSurfaceMap(pThisCC, &image, NULL, VMSVGA3D_SURFACE_MAP_READ, &mapVB);6726 rc = vmsvga3dBackSurfaceMap(pThisCC, &image, NULL, VMSVGA3D_SURFACE_MAP_READ, &mapVB); 6692 6727 AssertRC(rc); 6693 6728 if (RT_SUCCESS(rc)) 6694 6729 { 6695 6730 uint8_t const *pu8VertexData = (uint8_t *)mapVB.pvData; 6696 pu8VertexData += pVB ->offset;6697 pu8VertexData += startInstanceLocation * pVB ->stride;6731 pu8VertexData += pVBInfo->offset; 6732 pu8VertexData += startInstanceLocation * pVBInfo->stride; 6698 6733 6699 6734 SVGA3dElementLayoutId const elementLayoutId = pDXContext->svgaDXContext.inputAssembly.layoutId; … … 6702 6737 6703 6738 Log8(("Instance data dump: sid = %u, iInstance %u, startInstanceLocation %d, offset = %d, stride = %d:\n", 6704 sidVB, iInstance, startInstanceLocation, pVB->offset, pVB->stride));6739 pVBInfo->bufferId, iInstance, startInstanceLocation, pVBInfo->offset, pVBInfo->stride)); 6705 6740 6706 6741 Log8(("slot[%u] /* i%u */ { ", iSlot, iInstance)); … … 6713 6748 if (pElement->InputSlot == iSlot) 6714 6749 { 6715 uint8_t const *pu8Vertex = pu8VertexData + iInstance * pVB ->stride;6750 uint8_t const *pu8Vertex = pu8VertexData + iInstance * pVBInfo->stride; 6716 6751 dxDbgLogVertexElement(pElement->Format, pu8Vertex + pElement->AlignedByteOffset); 6717 6752 } … … 7667 7702 static DECLCALLBACK(int) vmsvga3dBackDXSetVertexBuffers(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t startBuffer, uint32_t cVertexBuffer, SVGA3dVertexBuffer const *paVertexBuffer) 7668 7703 { 7669 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 7670 RT_NOREF(pBackend); 7671 7672 DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext); 7673 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 7674 7675 for (uint32_t i = 0; i < cVertexBuffer; ++i) 7676 { 7677 uint32_t const idxVertexBuffer = startBuffer + i; 7678 7679 /* Get corresponding resource. Create the buffer if does not yet exist. */ 7680 if (paVertexBuffer[i].sid != SVGA_ID_INVALID) 7681 { 7682 PVMSVGA3DSURFACE pSurface; 7683 int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, paVertexBuffer[i].sid, &pSurface); 7684 AssertRCReturn(rc, rc); 7685 7686 if (pSurface->pBackendSurface == NULL) 7687 { 7688 /* Create the resource and initialize it with the current surface data. */ 7689 rc = vmsvga3dBackSurfaceCreateBuffer(pThisCC, pDXContext, pSurface); 7690 AssertRCReturn(rc, rc); 7691 } 7692 Assert(pSurface->pBackendSurface->u.pBuffer); 7693 7694 DXBOUNDVERTEXBUFFER *pBoundBuffer = &pDXContext->pBackendDXContext->resources.inputAssembly.vertexBuffers[idxVertexBuffer]; 7695 if ( pBoundBuffer->pBuffer != pSurface->pBackendSurface->u.pBuffer 7696 || pBoundBuffer->stride != paVertexBuffer[i].stride 7697 || pBoundBuffer->offset != paVertexBuffer[i].offset) 7698 { 7699 LogFunc(("vertex buffer: [%u]: sid = %u, offset %u, stride %u (%p -> %p)\n", 7700 idxVertexBuffer, paVertexBuffer[i].sid, paVertexBuffer[i].offset, paVertexBuffer[i].stride, pBoundBuffer->pBuffer, pSurface->pBackendSurface->u.pBuffer)); 7701 7702 if (pBoundBuffer->pBuffer != pSurface->pBackendSurface->u.pBuffer) 7703 { 7704 D3D_RELEASE(pBoundBuffer->pBuffer); 7705 pBoundBuffer->pBuffer = pSurface->pBackendSurface->u.pBuffer; 7706 pBoundBuffer->pBuffer->AddRef(); 7707 } 7708 pBoundBuffer->stride = paVertexBuffer[i].stride; 7709 pBoundBuffer->offset = paVertexBuffer[i].offset; 7710 } 7711 } 7712 else 7713 { 7714 DXBOUNDVERTEXBUFFER *pBoundBuffer = &pDXContext->pBackendDXContext->resources.inputAssembly.vertexBuffers[idxVertexBuffer]; 7715 D3D_RELEASE(pBoundBuffer->pBuffer); 7716 pBoundBuffer->stride = 0; 7717 pBoundBuffer->offset = 0; 7718 } 7719 } 7720 7704 /* Will be set in setupPipeline. */ 7705 RT_NOREF(pThisCC, pDXContext, startBuffer, cVertexBuffer, paVertexBuffer); 7721 7706 return VINF_SUCCESS; 7722 7707 } … … 7725 7710 static DECLCALLBACK(int) vmsvga3dBackDXSetIndexBuffer(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dSurfaceId sid, SVGA3dSurfaceFormat format, uint32_t offset) 7726 7711 { 7727 PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend; 7728 RT_NOREF(pBackend); 7729 7730 DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext); 7731 AssertReturn(pDevice->pDevice, VERR_INVALID_STATE); 7732 7733 /* Get corresponding resource. Create the buffer if does not yet exist. */ 7734 if (sid != SVGA_ID_INVALID) 7735 { 7736 PVMSVGA3DSURFACE pSurface; 7737 int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, sid, &pSurface); 7738 AssertRCReturn(rc, rc); 7739 7740 if (pSurface->pBackendSurface == NULL) 7741 { 7742 /* Create the resource and initialize it with the current surface data. */ 7743 rc = vmsvga3dBackSurfaceCreateBuffer(pThisCC, pDXContext, pSurface); 7744 AssertRCReturn(rc, rc); 7745 } 7746 7747 DXGI_FORMAT const enmDxgiFormat = vmsvgaDXSurfaceFormat2Dxgi(format); 7748 AssertReturn(enmDxgiFormat == DXGI_FORMAT_R16_UINT || enmDxgiFormat == DXGI_FORMAT_R32_UINT, VERR_INVALID_PARAMETER); 7749 7750 DXBOUNDINDEXBUFFER *pBoundBuffer = &pDXContext->pBackendDXContext->resources.inputAssembly.indexBuffer; 7751 if ( pBoundBuffer->pBuffer != pSurface->pBackendSurface->u.pBuffer 7752 || pBoundBuffer->indexBufferOffset != offset 7753 || pBoundBuffer->indexBufferFormat != enmDxgiFormat) 7754 { 7755 LogFunc(("index_buffer: sid = %u, offset %u, (%p -> %p)\n", 7756 sid, offset, pBoundBuffer->pBuffer, pSurface->pBackendSurface->u.pBuffer)); 7757 7758 if (pBoundBuffer->pBuffer != pSurface->pBackendSurface->u.pBuffer) 7759 { 7760 D3D_RELEASE(pBoundBuffer->pBuffer); 7761 pBoundBuffer->pBuffer = pSurface->pBackendSurface->u.pBuffer; 7762 pBoundBuffer->pBuffer->AddRef(); 7763 } 7764 pBoundBuffer->indexBufferOffset = offset; 7765 pBoundBuffer->indexBufferFormat = enmDxgiFormat; 7766 } 7767 } 7768 else 7769 { 7770 DXBOUNDINDEXBUFFER *pBoundBuffer = &pDXContext->pBackendDXContext->resources.inputAssembly.indexBuffer; 7771 D3D_RELEASE(pBoundBuffer->pBuffer); 7772 pBoundBuffer->indexBufferOffset = 0; 7773 pBoundBuffer->indexBufferFormat = DXGI_FORMAT_UNKNOWN; 7774 } 7775 7712 /* Will be set in setupPipeline. */ 7713 RT_NOREF(pThisCC, pDXContext, sid, format, offset); 7776 7714 return VINF_SUCCESS; 7777 7715 } … … 10072 10010 { 10073 10011 PVMSVGA3DSURFACE pSurface; 10074 int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, argsBufferSid, &pSurface); 10012 ID3D11Resource *pResource; 10013 int rc = dxEnsureResource(pThisCC, pDXContext, argsBufferSid, &pSurface, &pResource); 10075 10014 AssertRCReturn(rc, rc); 10076 10077 if (pSurface->pBackendSurface == NULL) 10078 { 10079 /* Create the resource and initialize it with the current surface data. */ 10080 rc = vmsvga3dBackSurfaceCreateResource(pThisCC, pDXContext, pSurface); 10081 AssertRCReturn(rc, rc); 10082 } 10083 10084 pBufferForArgs = pSurface->pBackendSurface->u.pBuffer; 10015 AssertReturn(pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER, VERR_INVALID_STATE); 10016 10017 pBufferForArgs = (ID3D11Buffer *)pResource; 10085 10018 } 10086 10019 else … … 10117 10050 { 10118 10051 PVMSVGA3DSURFACE pSurface; 10119 int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, argsBufferSid, &pSurface); 10052 ID3D11Resource *pResource; 10053 int rc = dxEnsureResource(pThisCC, pDXContext, argsBufferSid, &pSurface, &pResource); 10120 10054 AssertRCReturn(rc, rc); 10121 10122 if (pSurface->pBackendSurface == NULL) 10123 { 10124 /* Create the resource and initialize it with the current surface data. */ 10125 rc = vmsvga3dBackSurfaceCreateResource(pThisCC, pDXContext, pSurface); 10126 AssertRCReturn(rc, rc); 10127 } 10128 10129 pBufferForArgs = pSurface->pBackendSurface->u.pBuffer; 10055 AssertReturn(pSurface->pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER, VERR_INVALID_STATE); 10056 10057 pBufferForArgs = (ID3D11Buffer *)pResource; 10130 10058 } 10131 10059 else -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx.cpp
r102632 r102714 62 62 } 63 63 64 void vmsvga3dDXInitContextMobData(SVGADXContextMobFormat *p) 65 { 66 /* 0xFFFFFFFF (SVGA_ID_INVALID) is a better initial value than 0 for most of svgaDXContext fields. */ 67 memset(p, 0xFF, sizeof(*p)); 68 69 p->inputAssembly.layoutId = SVGA3D_INVALID_ID; 70 for (uint32_t i = 0; i < RT_ELEMENTS(p->inputAssembly.vertexBuffers); ++i) 71 { 72 p->inputAssembly.vertexBuffers[i].bufferId = SVGA3D_INVALID_ID; 73 p->inputAssembly.vertexBuffers[i].stride = 0; 74 p->inputAssembly.vertexBuffers[i].offset = 0; 75 } 76 p->inputAssembly.indexBufferSid = SVGA3D_INVALID_ID; 77 p->inputAssembly.indexBufferOffset = 0; 78 p->inputAssembly.indexBufferFormat = SVGA3D_FORMAT_INVALID; 79 p->inputAssembly.topology = SVGA3D_PRIMITIVE_INVALID; 80 81 p->renderState.blendStateId = SVGA3D_INVALID_ID; 82 RT_ZERO(p->renderState.blendFactor); 83 p->renderState.sampleMask = 0; 84 p->renderState.depthStencilStateId = SVGA3D_INVALID_ID; 85 p->renderState.stencilRef = 0; 86 p->renderState.rasterizerStateId = SVGA3D_INVALID_ID; 87 p->renderState.depthStencilViewId = SVGA3D_INVALID_ID; 88 for (uint32_t i = 0; i < RT_ELEMENTS(p->renderState.renderTargetViewIds); ++i) 89 p->renderState.renderTargetViewIds[i] = SVGA3D_INVALID_ID; 90 91 for (uint32_t i = 0; i < RT_ELEMENTS(p->streamOut.targets); ++i) 92 p->streamOut.targets[i] = SVGA3D_INVALID_ID; 93 p->streamOut.soid = SVGA3D_INVALID_ID; 94 95 p->uavSpliceIndex = 0; 96 p->numViewports = 0; 97 p->numScissorRects = 0; 98 99 RT_ZERO(p->viewports); 100 RT_ZERO(p->scissorRects); 101 102 p->predication.queryID = SVGA3D_INVALID_ID; 103 p->predication.value = 0; 104 105 p->shaderIfaceMobid = SVGA3D_INVALID_ID; 106 p->shaderIfaceOffset = 0; 107 108 for (uint32_t i = 0; i < RT_ELEMENTS(p->shaderState); ++i) 109 { 110 p->shaderState[i].shaderId = SVGA3D_INVALID_ID; 111 for (uint32_t j = 0; j < RT_ELEMENTS(p->shaderState[0].constantBuffers); ++j) 112 { 113 SVGA3dConstantBufferBinding *cbb = &p->shaderState[i].constantBuffers[j]; 114 cbb->sid = SVGA3D_INVALID_ID; 115 cbb->offsetInBytes = 0; 116 cbb->sizeInBytes = 0; 117 } 118 for (uint32_t j = 0; j < RT_ELEMENTS(p->shaderState[0].shaderResources); ++j) 119 p->shaderState[i].shaderResources[j] = SVGA3D_INVALID_ID; 120 for (uint32_t j = 0; j < RT_ELEMENTS(p->shaderState[0].samplers); ++j) 121 p->shaderState[i].samplers[j] = SVGA3D_INVALID_ID; 122 } 123 124 for (uint32_t i = 0; i < RT_ELEMENTS(p->queryID); ++i) 125 p->queryID[i] = SVGA3D_INVALID_ID; 126 127 for (uint32_t i = 0; i < RT_ELEMENTS(p->cotables); ++i) 128 p->cotables[i].mobid = SVGA3D_INVALID_ID; 129 130 for (uint32_t i = 0; i < RT_ELEMENTS(p->uaViewIds); ++i) 131 p->uaViewIds[i] = SVGA3D_INVALID_ID; 132 133 for (uint32_t i = 0; i < RT_ELEMENTS(p->csuaViewIds); ++i) 134 p->csuaViewIds[i] = SVGA3D_INVALID_ID; 135 } 64 136 65 137 /* … … 302 374 memset(pDXContext, 0, sizeof(*pDXContext)); 303 375 304 /* 0xFFFFFFFF (SVGA_ID_INVALID) is a better initial value than 0 for most of svgaDXContext fields. */ 305 memset(&pDXContext->svgaDXContext, 0xFF, sizeof(pDXContext->svgaDXContext)); 306 pDXContext->svgaDXContext.inputAssembly.topology = SVGA3D_PRIMITIVE_INVALID; 307 pDXContext->svgaDXContext.numViewports = 0; 308 pDXContext->svgaDXContext.numScissorRects = 0; 376 vmsvga3dDXInitContextMobData(&pDXContext->svgaDXContext); 309 377 pDXContext->cid = cid; 310 378 … … 1104 1172 || queryId < pDXContext->cot.cQuery, VERR_INVALID_PARAMETER); 1105 1173 RT_UNTRUSTED_VALIDATED_FENCE(); 1174 1175 pDXContext->svgaDXContext.predication.queryID = queryId; 1176 pDXContext->svgaDXContext.predication.value = pCmd->predicateValue; 1106 1177 1107 1178 rc = pSvgaR3State->pFuncsDX->pfnDXSetPredication(pThisCC, pDXContext, queryId, pCmd->predicateValue); -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-internal.h
r102520 r102714 1368 1368 return VERR_INVALID_PARAMETER; 1369 1369 } 1370 1371 void vmsvga3dDXInitContextMobData(SVGADXContextMobFormat *p); 1370 1372 #endif 1371 1373
Note:
See TracChangeset
for help on using the changeset viewer.