From 722191184b92160bbdb2e4114c7f6930963fe55d Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 8 Jun 2023 17:02:46 +0100 Subject: [PATCH] Handle degenerate case on D3D12 of indexed draw with no index buffer --- renderdoc/driver/d3d12/d3d12_postvs.cpp | 5 ++ renderdoc/driver/d3d12/d3d12_rendermesh.cpp | 51 +++++++++++++-------- renderdoc/driver/d3d12/d3d12_replay.cpp | 9 +++- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_postvs.cpp b/renderdoc/driver/d3d12/d3d12_postvs.cpp index f33e55b7e..a7b115fd8 100644 --- a/renderdoc/driver/d3d12/d3d12_postvs.cpp +++ b/renderdoc/driver/d3d12/d3d12_postvs.cpp @@ -1495,6 +1495,11 @@ MeshFormat D3D12Replay::GetPostVSBuffers(uint32_t eventId, uint32_t instID, uint ret.indexByteStride = s.idxFmt == DXGI_FORMAT_R16_UINT ? 2 : 4; ret.indexByteSize = ~0ULL; } + else if(s.useIndices) + { + // indicate that an index buffer is still needed + ret.indexByteStride = 4; + } else { ret.indexResourceId = ResourceId(); diff --git a/renderdoc/driver/d3d12/d3d12_rendermesh.cpp b/renderdoc/driver/d3d12/d3d12_rendermesh.cpp index 6a7da81b8..5c2f77cf6 100644 --- a/renderdoc/driver/d3d12/d3d12_rendermesh.cpp +++ b/renderdoc/driver/d3d12/d3d12_rendermesh.cpp @@ -358,19 +358,23 @@ void D3D12Replay::RenderMesh(uint32_t eventId, const rdcarray &secon if(fmt.indexByteStride) { - if(fmt.indexResourceId != ResourceId()) - { - ID3D12Resource *ib = - m_pDevice->GetResourceManager()->GetCurrentAs(fmt.indexResourceId); + ID3D12Resource *ib = + m_pDevice->GetResourceManager()->GetCurrentAs(fmt.indexResourceId); + if(ib) + { D3D12_INDEX_BUFFER_VIEW iview; iview.BufferLocation = ib->GetGPUVirtualAddress() + fmt.indexByteOffset; iview.SizeInBytes = (UINT)fmt.indexByteSize; iview.Format = fmt.indexByteStride == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT; list->IASetIndexBuffer(&iview); - - list->DrawIndexedInstanced(fmt.numIndices, 1, 0, fmt.baseVertex, 0); } + else + { + list->IASetIndexBuffer(NULL); + } + + list->DrawIndexedInstanced(fmt.numIndices, 1, 0, fmt.baseVertex, 0); } else { @@ -486,19 +490,23 @@ void D3D12Replay::RenderMesh(uint32_t eventId, const rdcarray &secon if(cfg.position.indexByteStride) { - if(cfg.position.indexResourceId != ResourceId()) - { - ID3D12Resource *ib = m_pDevice->GetResourceManager()->GetCurrentAs( - cfg.position.indexResourceId); + ID3D12Resource *ib = + m_pDevice->GetResourceManager()->GetCurrentAs(cfg.position.indexResourceId); + if(ib) + { D3D12_INDEX_BUFFER_VIEW view; view.BufferLocation = ib->GetGPUVirtualAddress() + cfg.position.indexByteOffset; view.SizeInBytes = (UINT)cfg.position.indexByteSize; view.Format = cfg.position.indexByteStride == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT; list->IASetIndexBuffer(&view); - - list->DrawIndexedInstanced(cfg.position.numIndices, 1, 0, cfg.position.baseVertex, 0); } + else + { + list->IASetIndexBuffer(NULL); + } + + list->DrawIndexedInstanced(cfg.position.numIndices, 1, 0, cfg.position.baseVertex, 0); } else { @@ -529,16 +537,23 @@ void D3D12Replay::RenderMesh(uint32_t eventId, const rdcarray &secon list->SetGraphicsRoot32BitConstants(2, 4, &pixelData, 0); - if(cfg.position.indexByteStride && cfg.position.indexResourceId != ResourceId()) + if(cfg.position.indexByteStride) { ID3D12Resource *ib = m_pDevice->GetResourceManager()->GetCurrentAs(cfg.position.indexResourceId); - D3D12_INDEX_BUFFER_VIEW view; - view.BufferLocation = ib->GetGPUVirtualAddress() + cfg.position.indexByteOffset; - view.SizeInBytes = (UINT)cfg.position.indexByteSize; - view.Format = cfg.position.indexByteStride == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT; - list->IASetIndexBuffer(&view); + if(ib) + { + D3D12_INDEX_BUFFER_VIEW view; + view.BufferLocation = ib->GetGPUVirtualAddress() + cfg.position.indexByteOffset; + view.SizeInBytes = (UINT)cfg.position.indexByteSize; + view.Format = cfg.position.indexByteStride == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT; + list->IASetIndexBuffer(&view); + } + else + { + list->IASetIndexBuffer(NULL); + } list->DrawIndexedInstanced(cfg.position.numIndices, 1, 0, cfg.position.baseVertex, 0); } diff --git a/renderdoc/driver/d3d12/d3d12_replay.cpp b/renderdoc/driver/d3d12/d3d12_replay.cpp index 148efc0d7..733385b50 100644 --- a/renderdoc/driver/d3d12/d3d12_replay.cpp +++ b/renderdoc/driver/d3d12/d3d12_replay.cpp @@ -2138,7 +2138,7 @@ uint32_t D3D12Replay::PickVertex(uint32_t eventId, int32_t width, int32_t height cbuf.PickCoords = Vec2f((float)x, (float)y); cbuf.PickViewport = Vec2f((float)width, (float)height); - cbuf.PickIdx = cfg.position.indexByteStride ? 1 : 0; + cbuf.PickIdx = cfg.position.indexByteStride && cfg.position.indexResourceId != ResourceId() ? 1 : 0; cbuf.PickNumVerts = cfg.position.numIndices; cbuf.PickUnproject = cfg.position.unproject ? 1 : 0; cbuf.PickFlipY = cfg.position.flipY; @@ -2489,6 +2489,13 @@ uint32_t D3D12Replay::PickVertex(uint32_t eventId, int32_t width, int32_t height } else { + if(cfg.position.indexByteStride) + { + maxIndex = 0; + if(cfg.position.baseVertex > 0) + minIndex = maxIndex = (uint32_t)cfg.position.baseVertex; + } + sdesc.Buffer.NumElements = 4; m_pDevice->CreateShaderResourceView(NULL, &sdesc, GetDebugManager()->GetCPUHandle(PICK_IB_SRV)); }