From 5dd2b2094071e82ad6dce36fcded7b819ba17ba4 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 4 Aug 2022 17:37:10 +0200 Subject: [PATCH] [d3d11] Track highest bound constant buffer --- src/d3d11/d3d11_context.cpp | 14 ++++++++++++-- src/d3d11/d3d11_context_state.h | 6 +++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 471c9a07..949bc489 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -1,3 +1,5 @@ +#include + #include "d3d11_context.h" #include "d3d11_context_def.h" #include "d3d11_context_imm.h" @@ -3781,7 +3783,9 @@ namespace dxvk { D3D11MaxUsedBindings result; for (uint32_t i = 0; i < result.stages.size(); i++) { - result.stages[i].cbvCount = D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; + auto stage = DxbcProgramType(i); + + result.stages[i].cbvCount = m_state.cbv[stage].maxCount; result.stages[i].srvCount = D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; result.stages[i].uavCount = 0; result.stages[i].samplerCount = D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; @@ -4108,7 +4112,7 @@ namespace dxvk { const auto& bindings = m_state.cbv[Stage]; uint32_t slotId = computeConstantBufferBinding(Stage, 0); - for (uint32_t i = 0; i < bindings.buffers.size(); i++) { + for (uint32_t i = 0; i < bindings.maxCount; i++) { BindConstantBuffer(slotId + i, bindings.buffers[i].buffer.ptr(), bindings.buffers[i].constantOffset, bindings.buffers[i].constantBound); } @@ -4182,6 +4186,9 @@ namespace dxvk { BindConstantBuffer(slotId + i, newBuffer, 0, constantCount); } } + + bindings.maxCount = std::clamp(StartSlot + NumBuffers, + bindings.maxCount, uint32_t(bindings.buffers.size())); } @@ -4254,6 +4261,9 @@ namespace dxvk { BindConstantBufferRange(slotId + i, constantOffset, constantBound); } } + + bindings.maxCount = std::clamp(StartSlot + NumBuffers, + bindings.maxCount, uint32_t(bindings.buffers.size())); } diff --git a/src/d3d11/d3d11_context_state.h b/src/d3d11/d3d11_context_state.h index 66944d12..846eb646 100644 --- a/src/d3d11/d3d11_context_state.h +++ b/src/d3d11/d3d11_context_state.h @@ -60,9 +60,13 @@ namespace dxvk { struct D3D11ShaderStageCbvBinding { std::array buffers = { }; + uint32_t maxCount = 0; + void reset() { - for (uint32_t i = 0; i < buffers.size(); i++) + for (uint32_t i = 0; i < maxCount; i++) buffers[i] = D3D11ConstantBufferBinding(); + + maxCount = 0; } };