diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 4688f147c..244ee11f2 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -1373,9 +1373,7 @@ namespace dxvk { D3D10DeviceLock lock = LockContext(); SetSamplers( - m_state.vs.samplers, - StartSlot, NumSamplers, - ppSamplers); + StartSlot, NumSamplers, ppSamplers); } @@ -1441,7 +1439,7 @@ namespace dxvk { ID3D11SamplerState** ppSamplers) { D3D10DeviceLock lock = LockContext(); - GetSamplers(m_state.vs.samplers, + GetSamplers( StartSlot, NumSamplers, ppSamplers); } @@ -1513,9 +1511,7 @@ namespace dxvk { D3D10DeviceLock lock = LockContext(); SetSamplers( - m_state.hs.samplers, - StartSlot, NumSamplers, - ppSamplers); + StartSlot, NumSamplers, ppSamplers); } @@ -1581,7 +1577,7 @@ namespace dxvk { ID3D11SamplerState** ppSamplers) { D3D10DeviceLock lock = LockContext(); - GetSamplers(m_state.hs.samplers, + GetSamplers( StartSlot, NumSamplers, ppSamplers); } @@ -1653,9 +1649,7 @@ namespace dxvk { D3D10DeviceLock lock = LockContext(); SetSamplers( - m_state.ds.samplers, - StartSlot, NumSamplers, - ppSamplers); + StartSlot, NumSamplers, ppSamplers); } @@ -1721,7 +1715,7 @@ namespace dxvk { ID3D11SamplerState** ppSamplers) { D3D10DeviceLock lock = LockContext(); - GetSamplers(m_state.ds.samplers, + GetSamplers( StartSlot, NumSamplers, ppSamplers); } @@ -1793,9 +1787,7 @@ namespace dxvk { D3D10DeviceLock lock = LockContext(); SetSamplers( - m_state.gs.samplers, - StartSlot, NumSamplers, - ppSamplers); + StartSlot, NumSamplers, ppSamplers); } @@ -1861,7 +1853,7 @@ namespace dxvk { ID3D11SamplerState** ppSamplers) { D3D10DeviceLock lock = LockContext(); - GetSamplers(m_state.gs.samplers, + GetSamplers( StartSlot, NumSamplers, ppSamplers); } @@ -1933,9 +1925,7 @@ namespace dxvk { D3D10DeviceLock lock = LockContext(); SetSamplers( - m_state.ps.samplers, - StartSlot, NumSamplers, - ppSamplers); + StartSlot, NumSamplers, ppSamplers); } @@ -2001,7 +1991,7 @@ namespace dxvk { ID3D11SamplerState** ppSamplers) { D3D10DeviceLock lock = LockContext(); - GetSamplers(m_state.ps.samplers, + GetSamplers( StartSlot, NumSamplers, ppSamplers); } @@ -2073,9 +2063,7 @@ namespace dxvk { D3D10DeviceLock lock = LockContext(); SetSamplers( - m_state.cs.samplers, - StartSlot, NumSamplers, - ppSamplers); + StartSlot, NumSamplers, ppSamplers); } @@ -2198,7 +2186,7 @@ namespace dxvk { ID3D11SamplerState** ppSamplers) { D3D10DeviceLock lock = LockContext(); - GetSamplers(m_state.cs.samplers, + GetSamplers( StartSlot, NumSamplers, ppSamplers); } @@ -3773,14 +3761,16 @@ namespace dxvk { template + template void D3D11CommonContext::GetSamplers( - const D3D11SamplerBindings& Bindings, UINT StartSlot, UINT NumSamplers, ID3D11SamplerState** ppSamplers) { + const auto& bindings = m_state.samplers[ShaderStage]; + for (uint32_t i = 0; i < NumSamplers; i++) { - ppSamplers[i] = StartSlot + i < Bindings.size() - ? ref(Bindings[StartSlot + i]) + ppSamplers[i] = StartSlot + i < bindings.samplers.size() + ? ref(bindings.samplers[StartSlot + i]) : nullptr; } } @@ -3905,16 +3895,7 @@ namespace dxvk { // Reset resource bindings m_state.cbv.reset(); m_state.srv.reset(); - - // Default samplers - for (uint32_t i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; i++) { - m_state.vs.samplers[i] = nullptr; - m_state.hs.samplers[i] = nullptr; - m_state.ds.samplers[i] = nullptr; - m_state.gs.samplers[i] = nullptr; - m_state.ps.samplers[i] = nullptr; - m_state.cs.samplers[i] = nullptr; - } + m_state.samplers.reset(); // Default UAVs for (uint32_t i = 0; i < D3D11_1_UAV_SLOT_COUNT; i++) { @@ -4132,13 +4113,6 @@ namespace dxvk { RestoreConstantBuffers(); RestoreConstantBuffers(); - RestoreSamplers (m_state.vs.samplers); - RestoreSamplers (m_state.hs.samplers); - RestoreSamplers (m_state.ds.samplers); - RestoreSamplers(m_state.gs.samplers); - RestoreSamplers (m_state.ps.samplers); - RestoreSamplers (m_state.cs.samplers); - RestoreShaderResources(); RestoreShaderResources(); RestoreShaderResources(); @@ -4148,6 +4122,13 @@ namespace dxvk { RestoreUnorderedAccessViews (m_state.ps.unorderedAccessViews); RestoreUnorderedAccessViews (m_state.cs.unorderedAccessViews); + + RestoreSamplers(); + RestoreSamplers(); + RestoreSamplers(); + RestoreSamplers(); + RestoreSamplers(); + RestoreSamplers(); } @@ -4166,12 +4147,12 @@ namespace dxvk { template template - void D3D11CommonContext::RestoreSamplers( - D3D11SamplerBindings& Bindings) { + void D3D11CommonContext::RestoreSamplers() { + const auto& bindings = m_state.samplers[Stage]; uint32_t slotId = computeSamplerBinding(Stage, 0); - for (uint32_t i = 0; i < Bindings.size(); i++) - BindSampler(slotId + i, Bindings[i]); + for (uint32_t i = 0; i < bindings.samplers.size(); i++) + BindSampler(slotId + i, bindings.samplers[i]); } @@ -4337,17 +4318,17 @@ namespace dxvk { template template void D3D11CommonContext::SetSamplers( - D3D11SamplerBindings& Bindings, UINT StartSlot, UINT NumSamplers, ID3D11SamplerState* const* ppSamplers) { + auto& bindings = m_state.samplers[ShaderStage]; uint32_t slotId = computeSamplerBinding(ShaderStage, StartSlot); for (uint32_t i = 0; i < NumSamplers; i++) { auto sampler = static_cast(ppSamplers[i]); - if (Bindings[StartSlot + i] != sampler) { - Bindings[StartSlot + i] = sampler; + if (bindings.samplers[StartSlot + i] != sampler) { + bindings.samplers[StartSlot + i] = sampler; BindSampler(slotId + i, sampler); } } diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 5c47ab553..41df199e8 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -900,8 +900,8 @@ namespace dxvk { UINT NumViews, ID3D11ShaderResourceView** ppShaderResourceViews); + template void GetSamplers( - const D3D11SamplerBindings& Bindings, UINT StartSlot, UINT NumSamplers, ID3D11SamplerState** ppSamplers); @@ -936,8 +936,7 @@ namespace dxvk { void RestoreConstantBuffers(); template - void RestoreSamplers( - D3D11SamplerBindings& Bindings); + void RestoreSamplers(); template void RestoreShaderResources(); @@ -968,7 +967,6 @@ namespace dxvk { template void SetSamplers( - D3D11SamplerBindings& Bindings, UINT StartSlot, UINT NumSamplers, ID3D11SamplerState* const* ppSamplers); diff --git a/src/d3d11/d3d11_context_state.h b/src/d3d11/d3d11_context_state.h index 260e8c005..7135990d5 100644 --- a/src/d3d11/d3d11_context_state.h +++ b/src/d3d11/d3d11_context_state.h @@ -87,10 +87,22 @@ namespace dxvk { }; using D3D11SrvBindings = D3D11ShaderStageState; + + /** + * \brief Sampler bindings + * + * Stores bound samplers. + */ + struct D3D11ShaderStageSamplerBinding { + std::array samplers = { }; + + void reset() { + for (uint32_t i = 0; i < samplers.size(); i++) + samplers[i] = nullptr; + } + }; - using D3D11SamplerBindings = std::array< - D3D11SamplerState*, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT>; - + using D3D11SamplerBindings = D3D11ShaderStageState; using D3D11UnorderedAccessBindings = std::array< Com, D3D11_1_UAV_SLOT_COUNT>; @@ -98,38 +110,32 @@ namespace dxvk { struct D3D11ContextStateVS { Com shader = nullptr; - D3D11SamplerBindings samplers = { }; }; struct D3D11ContextStateHS { Com shader = nullptr; - D3D11SamplerBindings samplers = { }; }; struct D3D11ContextStateDS { Com shader = nullptr; - D3D11SamplerBindings samplers = { }; }; struct D3D11ContextStateGS { Com shader = nullptr; - D3D11SamplerBindings samplers = { }; }; struct D3D11ContextStatePS { Com shader = nullptr; - D3D11SamplerBindings samplers = { }; D3D11UnorderedAccessBindings unorderedAccessViews = { }; }; struct D3D11ContextStateCS { Com shader = nullptr; - D3D11SamplerBindings samplers = { }; D3D11UnorderedAccessBindings unorderedAccessViews = { }; DxvkBindingSet uavMask = { }; @@ -231,6 +237,7 @@ namespace dxvk { D3D11CbvBindings cbv; D3D11SrvBindings srv; + D3D11SamplerBindings samplers; }; } \ No newline at end of file