From 8fe6a51dbcbb50593a91712d7fac5c5cb96679d9 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 18 Nov 2016 12:33:12 +0100 Subject: [PATCH] Add utility for setting only root elements, instead of the whole state --- renderdoc/driver/d3d12/d3d12_state.cpp | 70 +++++++++++++++----------- renderdoc/driver/d3d12/d3d12_state.h | 8 +-- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_state.cpp b/renderdoc/driver/d3d12/d3d12_state.cpp index d33a7cdb9..fc5b6f426 100644 --- a/renderdoc/driver/d3d12/d3d12_state.cpp +++ b/renderdoc/driver/d3d12/d3d12_state.cpp @@ -129,7 +129,7 @@ ResourceId D3D12RenderState::GetDSVID() const return ResourceId(); } -void D3D12RenderState::ApplyState(ID3D12GraphicsCommandList *cmd) +void D3D12RenderState::ApplyState(ID3D12GraphicsCommandList *cmd) const { if(pipe != ResourceId()) cmd->SetPipelineState(GetResourceManager()->GetCurrentAs(pipe)); @@ -207,21 +207,7 @@ void D3D12RenderState::ApplyState(ID3D12GraphicsCommandList *cmd) cmd->SetGraphicsRootSignature( GetResourceManager()->GetCurrentAs(graphics.rootsig)); - for(size_t i = 0; i < graphics.sigelems.size(); i++) - { - // just don't set tables that aren't in the descriptor heaps, since it's invalid and can crash - // and is probably just from stale bindings that aren't going to be used - if(graphics.sigelems[i].type != eRootTable || - std::find(heaps.begin(), heaps.end(), graphics.sigelems[i].id) != heaps.end()) - { - graphics.sigelems[i].SetToGraphics(GetResourceManager(), cmd, (UINT)i); - } - else - { - RDCDEBUG("Skipping setting possibly stale graphics root table referring to heap %llu", - graphics.sigelems[i].id); - } - } + ApplyGraphicsRootElements(cmd); } if(compute.rootsig != ResourceId()) @@ -229,20 +215,44 @@ void D3D12RenderState::ApplyState(ID3D12GraphicsCommandList *cmd) cmd->SetComputeRootSignature( GetResourceManager()->GetCurrentAs(compute.rootsig)); - for(size_t i = 0; i < compute.sigelems.size(); i++) + ApplyComputeRootElements(cmd); + } +} + +void D3D12RenderState::ApplyComputeRootElements(ID3D12GraphicsCommandList *cmd) const +{ + for(size_t i = 0; i < compute.sigelems.size(); i++) + { + // just don't set tables that aren't in the descriptor heaps, since it's invalid and can crash + // and is probably just from stale bindings that aren't going to be used + if(compute.sigelems[i].type != eRootTable || + std::find(heaps.begin(), heaps.end(), compute.sigelems[i].id) != heaps.end()) { - // just don't set tables that aren't in the descriptor heaps, since it's invalid and can crash - // and is probably just from stale bindings that aren't going to be used - if(compute.sigelems[i].type != eRootTable || - std::find(heaps.begin(), heaps.end(), compute.sigelems[i].id) != heaps.end()) - { - compute.sigelems[i].SetToCompute(GetResourceManager(), cmd, (UINT)i); - } - else - { - RDCDEBUG("Skipping setting possibly stale compute root table referring to heap %llu", - compute.sigelems[i].id); - } + compute.sigelems[i].SetToCompute(GetResourceManager(), cmd, (UINT)i); + } + else + { + RDCDEBUG("Skipping setting possibly stale compute root table referring to heap %llu", + compute.sigelems[i].id); } } -} \ No newline at end of file +} + +void D3D12RenderState::ApplyGraphicsRootElements(ID3D12GraphicsCommandList *cmd) const +{ + for(size_t i = 0; i < graphics.sigelems.size(); i++) + { + // just don't set tables that aren't in the descriptor heaps, since it's invalid and can crash + // and is probably just from stale bindings that aren't going to be used + if(graphics.sigelems[i].type != eRootTable || + std::find(heaps.begin(), heaps.end(), graphics.sigelems[i].id) != heaps.end()) + { + graphics.sigelems[i].SetToGraphics(GetResourceManager(), cmd, (UINT)i); + } + else + { + RDCDEBUG("Skipping setting possibly stale graphics root table referring to heap %llu", + graphics.sigelems[i].id); + } + } +} diff --git a/renderdoc/driver/d3d12/d3d12_state.h b/renderdoc/driver/d3d12/d3d12_state.h index 811b8e104..88f3a537f 100644 --- a/renderdoc/driver/d3d12/d3d12_state.h +++ b/renderdoc/driver/d3d12/d3d12_state.h @@ -45,7 +45,9 @@ struct D3D12RenderState D3D12RenderState(); D3D12RenderState &operator=(const D3D12RenderState &o); - void ApplyState(ID3D12GraphicsCommandList *list); + void ApplyState(ID3D12GraphicsCommandList *list) const; + void ApplyComputeRootElements(ID3D12GraphicsCommandList *cmd) const; + void ApplyGraphicsRootElements(ID3D12GraphicsCommandList *cmd) const; vector views; vector scissors; @@ -72,7 +74,7 @@ struct D3D12RenderState memcpy(&constants[offs], vals, numVals * sizeof(UINT)); } - void SetToGraphics(D3D12ResourceManager *rm, ID3D12GraphicsCommandList *cmd, UINT slot) + void SetToGraphics(D3D12ResourceManager *rm, ID3D12GraphicsCommandList *cmd, UINT slot) const { if(type == eRootConst) { @@ -102,7 +104,7 @@ struct D3D12RenderState } } - void SetToCompute(D3D12ResourceManager *rm, ID3D12GraphicsCommandList *cmd, UINT slot) + void SetToCompute(D3D12ResourceManager *rm, ID3D12GraphicsCommandList *cmd, UINT slot) const { if(type == eRootConst) {