From 9f07bc6532fafe10f3a2cdc5abd2c287517f7389 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 4 Aug 2022 16:37:23 +0200 Subject: [PATCH] [d3d11] Refactor shader state --- src/d3d11/d3d11_context.cpp | 62 ++++++++++++++++----------------- src/d3d11/d3d11_context_state.h | 44 ++++------------------- 2 files changed, 38 insertions(+), 68 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index fe7bf4d9..ac4ec633 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -1318,8 +1318,8 @@ namespace dxvk { if (NumClassInstances) Logger::err("D3D11: Class instances not supported"); - if (m_state.vs.shader != shader) { - m_state.vs.shader = shader; + if (m_state.vs != shader) { + m_state.vs = shader; BindShader(GetCommonShader(shader)); } @@ -1385,7 +1385,7 @@ namespace dxvk { D3D10DeviceLock lock = LockContext(); if (ppVertexShader) - *ppVertexShader = m_state.vs.shader.ref(); + *ppVertexShader = m_state.vs.ref(); if (pNumClassInstances) *pNumClassInstances = 0; @@ -1456,8 +1456,8 @@ namespace dxvk { if (NumClassInstances) Logger::err("D3D11: Class instances not supported"); - if (m_state.hs.shader != shader) { - m_state.hs.shader = shader; + if (m_state.hs != shader) { + m_state.hs = shader; BindShader(GetCommonShader(shader)); } @@ -1523,7 +1523,7 @@ namespace dxvk { D3D10DeviceLock lock = LockContext(); if (ppHullShader) - *ppHullShader = m_state.hs.shader.ref(); + *ppHullShader = m_state.hs.ref(); if (pNumClassInstances) *pNumClassInstances = 0; @@ -1594,8 +1594,8 @@ namespace dxvk { if (NumClassInstances) Logger::err("D3D11: Class instances not supported"); - if (m_state.ds.shader != shader) { - m_state.ds.shader = shader; + if (m_state.ds != shader) { + m_state.ds = shader; BindShader(GetCommonShader(shader)); } @@ -1661,7 +1661,7 @@ namespace dxvk { D3D10DeviceLock lock = LockContext(); if (ppDomainShader) - *ppDomainShader = m_state.ds.shader.ref(); + *ppDomainShader = m_state.ds.ref(); if (pNumClassInstances) *pNumClassInstances = 0; @@ -1732,8 +1732,8 @@ namespace dxvk { if (NumClassInstances) Logger::err("D3D11: Class instances not supported"); - if (m_state.gs.shader != shader) { - m_state.gs.shader = shader; + if (m_state.gs != shader) { + m_state.gs = shader; BindShader(GetCommonShader(shader)); } @@ -1799,7 +1799,7 @@ namespace dxvk { D3D10DeviceLock lock = LockContext(); if (ppGeometryShader) - *ppGeometryShader = m_state.gs.shader.ref(); + *ppGeometryShader = m_state.gs.ref(); if (pNumClassInstances) *pNumClassInstances = 0; @@ -1870,8 +1870,8 @@ namespace dxvk { if (NumClassInstances) Logger::err("D3D11: Class instances not supported"); - if (m_state.ps.shader != shader) { - m_state.ps.shader = shader; + if (m_state.ps != shader) { + m_state.ps = shader; BindShader(GetCommonShader(shader)); } @@ -1937,7 +1937,7 @@ namespace dxvk { D3D10DeviceLock lock = LockContext(); if (ppPixelShader) - *ppPixelShader = m_state.ps.shader.ref(); + *ppPixelShader = m_state.ps.ref(); if (pNumClassInstances) *pNumClassInstances = 0; @@ -2008,8 +2008,8 @@ namespace dxvk { if (NumClassInstances) Logger::err("D3D11: Class instances not supported"); - if (m_state.cs.shader != shader) { - m_state.cs.shader = shader; + if (m_state.cs != shader) { + m_state.cs = shader; BindShader(GetCommonShader(shader)); } @@ -2132,7 +2132,7 @@ namespace dxvk { D3D10DeviceLock lock = LockContext(); if (ppComputeShader) - *ppComputeShader = m_state.cs.shader.ref(); + *ppComputeShader = m_state.cs.ref(); if (pNumClassInstances) *pNumClassInstances = 0; @@ -3884,13 +3884,13 @@ namespace dxvk { template void D3D11CommonContext::ResetContextState() { - // Default shaders - m_state.vs.shader = nullptr; - m_state.hs.shader = nullptr; - m_state.ds.shader = nullptr; - m_state.gs.shader = nullptr; - m_state.ps.shader = nullptr; - m_state.cs.shader = nullptr; + // Reset shaders + m_state.vs = nullptr; + m_state.hs = nullptr; + m_state.ds = nullptr; + m_state.gs = nullptr; + m_state.ps = nullptr; + m_state.cs = nullptr; // Reset render state m_state.id.reset(); @@ -4016,12 +4016,12 @@ namespace dxvk { void D3D11CommonContext::RestoreCommandListState() { BindFramebuffer(); - BindShader (GetCommonShader(m_state.vs.shader.ptr())); - BindShader (GetCommonShader(m_state.hs.shader.ptr())); - BindShader (GetCommonShader(m_state.ds.shader.ptr())); - BindShader (GetCommonShader(m_state.gs.shader.ptr())); - BindShader (GetCommonShader(m_state.ps.shader.ptr())); - BindShader (GetCommonShader(m_state.cs.shader.ptr())); + BindShader(GetCommonShader(m_state.vs.ptr())); + BindShader(GetCommonShader(m_state.hs.ptr())); + BindShader(GetCommonShader(m_state.ds.ptr())); + BindShader(GetCommonShader(m_state.gs.ptr())); + BindShader(GetCommonShader(m_state.ps.ptr())); + BindShader(GetCommonShader(m_state.cs.ptr())); ApplyInputLayout(); ApplyPrimitiveTopology(); diff --git a/src/d3d11/d3d11_context_state.h b/src/d3d11/d3d11_context_state.h index 46ffd287..e011cf38 100644 --- a/src/d3d11/d3d11_context_state.h +++ b/src/d3d11/d3d11_context_state.h @@ -124,36 +124,6 @@ namespace dxvk { } }; - - struct D3D11ContextStateVS { - Com shader = nullptr; - }; - - - struct D3D11ContextStateHS { - Com shader = nullptr; - }; - - - struct D3D11ContextStateDS { - Com shader = nullptr; - }; - - - struct D3D11ContextStateGS { - Com shader = nullptr; - }; - - - struct D3D11ContextStatePS { - Com shader = nullptr; - }; - - - struct D3D11ContextStateCS { - Com shader = nullptr; - }; - /** * \brief Input assembly state * @@ -321,13 +291,13 @@ namespace dxvk { * \brief Context state */ struct D3D11ContextState { - D3D11ContextStateCS cs; - D3D11ContextStateDS ds; - D3D11ContextStateGS gs; - D3D11ContextStateHS hs; - D3D11ContextStatePS ps; - D3D11ContextStateVS vs; - + Com vs; + Com hs; + Com ds; + Com gs; + Com ps; + Com cs; + D3D11ContextStateID id; D3D11ContextStateIA ia; D3D11ContextStateOM om;