diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-09-18 05:00:26 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-09-18 05:00:26 +0000 |
| commit | ce496ba73a61fe88db3d5c233dd920c2689d9e9b (patch) | |
| tree | 107347e11c1a5a26199d1f8eb59bcec99763e703 /Graphics/GraphicsEngineD3D11 | |
| parent | Merge branch 'mesh_shader_fix' of https://github.com/azhirnov/DiligentCore in... (diff) | |
| download | DiligentCore-ce496ba73a61fe88db3d5c233dd920c2689d9e9b.tar.gz DiligentCore-ce496ba73a61fe88db3d5c233dd920c2689d9e9b.zip | |
Refactored internal shader resouce variable indexing
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
5 files changed, 38 insertions, 56 deletions
diff --git a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp index 10921348..6040dc31 100644 --- a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp +++ b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp @@ -142,7 +142,7 @@ private: // SRB memory allocator must be defined before the default shader res binding SRBMemoryAllocator m_SRBMemAllocator; - std::array<Int8, NUM_SHADER_TYPES> m_ResourceLayoutIndex; + std::array<Int8, MAX_SHADERS_IN_PIPELINE> m_ResourceLayoutIndex; std::array<Uint16, MAX_SHADERS_IN_PIPELINE + 1> m_StaticSamplerOffsets = {}; struct StaticSamplerInfo diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp index 86daad77..219386fc 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp @@ -30,13 +30,14 @@ /// \file /// Declaration of Diligent::ShaderResourceBindingD3D11Impl class +#include <array> + #include "ShaderResourceBindingD3D11.h" #include "RenderDeviceD3D11.h" #include "ShaderResourceBindingBase.hpp" #include "ShaderResourceCacheD3D11.hpp" #include "ShaderResourceLayoutD3D11.hpp" #include "STDAllocator.hpp" -#include <array> namespace Diligent { @@ -85,25 +86,29 @@ public: return m_pResourceLayouts[Ind]; } - inline bool IsStaticResourcesBound() { return m_bIsStaticResourcesBound; } + inline bool IsStaticResourcesBound() const { return m_bIsStaticResourcesBound; } - Uint32 GetNumActiveShaders() + Uint32 GetNumActiveShaders() const { return static_cast<Uint32>(m_NumActiveShaders); } - Int32 GetActiveShaderTypeIndex(Uint32 s) { return m_ShaderTypeIndex[s]; } + SHADER_TYPE GetActiveShaderType(Uint32 s) const + { + VERIFY_EXPR(s < m_NumActiveShaders); + return m_ShaderTypes[s]; + } private: // The caches are indexed by the shader order in the PSO, not shader index ShaderResourceCacheD3D11* m_pBoundResourceCaches = nullptr; ShaderResourceLayoutD3D11* m_pResourceLayouts = nullptr; - std::array<Int8, NUM_SHADER_TYPES> m_ShaderTypeIndex = {}; + std::array<SHADER_TYPE, MAX_SHADERS_IN_PIPELINE> m_ShaderTypes = {}; // Resource layout index in m_ResourceLayouts[] array for every shader stage - std::array<Int8, NUM_SHADER_TYPES> m_ResourceLayoutIndex; - Uint8 m_NumActiveShaders = 0; + std::array<Int8, MAX_SHADERS_IN_PIPELINE> m_ResourceLayoutIndex; + Uint8 m_NumActiveShaders = 0; bool m_bIsStaticResourcesBound = false; }; diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index 536a2df0..6af8b502 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -229,11 +229,12 @@ void DeviceContextD3D11Impl::TransitionAndCommitShaderResources(IPipelineState* // First, commit all UAVs for all shader stages. This will unbind them from input for (Uint32 s = 0; s < NumShaders; ++s) { - auto ShaderTypeInd = pShaderResBindingD3D11->GetActiveShaderTypeIndex(s); + const auto ShaderType = pShaderResBindingD3D11->GetActiveShaderType(s); + const auto ShaderTypeInd = GetShaderTypeIndex(ShaderType); #ifdef DILIGENT_DEVELOPMENT auto* pShaderD3D11 = pPipelineStateD3D11->GetShader<ShaderD3D11Impl>(s); - VERIFY_EXPR(ShaderTypeInd == static_cast<Int32>(GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType))); + VERIFY_EXPR(ShaderType == pShaderD3D11->GetDesc().ShaderType); #endif auto& Cache = pShaderResBindingD3D11->GetResourceCache(s); @@ -375,11 +376,12 @@ void DeviceContextD3D11Impl::TransitionAndCommitShaderResources(IPipelineState* // Commit input resources (CBs, SRVs and Samplers) for (Uint32 s = 0; s < NumShaders; ++s) { - auto ShaderTypeInd = pShaderResBindingD3D11->GetActiveShaderTypeIndex(s); + const auto ShaderType = pShaderResBindingD3D11->GetActiveShaderType(s); + const auto ShaderTypeInd = GetShaderTypeIndex(ShaderType); #ifdef DILIGENT_DEVELOPMENT auto* pShaderD3D11 = pPipelineStateD3D11->GetShader<ShaderD3D11Impl>(s); - VERIFY_EXPR(ShaderTypeInd == static_cast<Int32>(GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType))); + VERIFY_EXPR(ShaderType == pShaderD3D11->GetDesc().ShaderType); #endif auto& Cache = pShaderResBindingD3D11->GetResourceCache(s); diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp index 87294ce1..f4b7268b 100644 --- a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp @@ -202,7 +202,7 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pR ShaderResCacheDataSizes[s] = ShaderResourceCacheD3D11::GetRequriedMemorySize(ShaderResources); } - auto ShaderInd = GetShaderTypeIndex(pShader->GetDesc().ShaderType); + auto ShaderInd = GetShaderTypePipelineIndex(pShader->GetDesc().ShaderType, m_Desc.PipelineType); m_ResourceLayoutIndex[ShaderInd] = static_cast<Int8>(s); } @@ -356,28 +356,31 @@ void PipelineStateD3D11Impl::BindStaticResources(Uint32 ShaderFlags, IResourceMa Uint32 PipelineStateD3D11Impl::GetStaticVariableCount(SHADER_TYPE ShaderType) const { - const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)]; + const auto LayoutInd = GetStaticVariableCountHelper(ShaderType, m_ResourceLayoutIndex); if (LayoutInd < 0) return 0; + VERIFY_EXPR(static_cast<Uint32>(LayoutInd) <= m_NumShaders); return m_pStaticResourceLayouts[LayoutInd].GetTotalResourceCount(); } IShaderResourceVariable* PipelineStateD3D11Impl::GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name) { - const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)]; + const auto LayoutInd = GetStaticVariableByNameHelper(ShaderType, Name, m_ResourceLayoutIndex); if (LayoutInd < 0) return nullptr; + VERIFY_EXPR(static_cast<Uint32>(LayoutInd) <= m_NumShaders); return m_pStaticResourceLayouts[LayoutInd].GetShaderVariable(Name); } IShaderResourceVariable* PipelineStateD3D11Impl::GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) { - const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)]; + const auto LayoutInd = GetStaticVariableByIndexHelper(ShaderType, Index, m_ResourceLayoutIndex); if (LayoutInd < 0) return nullptr; + VERIFY_EXPR(static_cast<Uint32>(LayoutInd) <= m_NumShaders); return m_pStaticResourceLayouts[LayoutInd].GetShaderVariable(Index); } diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp index 5769d949..521e3504 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp @@ -63,7 +63,6 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl(IReferenceCounter for (Uint8 s = 0; s < m_NumActiveShaders; ++s) { auto* pShaderD3D11 = pPSO->GetShader<ShaderD3D11Impl>(s); - auto ShaderInd = GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType); auto& SRBMemAllocator = pPSO->GetSRBMemoryAllocator(); auto& ResCacheDataAllocator = SRBMemAllocator.GetResourceCacheDataAllocator(s); @@ -93,8 +92,11 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl(IReferenceCounter }; // clang-format on - m_ResourceLayoutIndex[ShaderInd] = s; - m_ShaderTypeIndex[s] = static_cast<Int8>(ShaderInd); + const auto ShaderType = pShaderD3D11->GetDesc().ShaderType; + const auto ResLayoutInd = GetShaderTypePipelineIndex(ShaderType, PSODesc.PipelineType); + m_ShaderTypes[s] = ShaderType; + + m_ResourceLayoutIndex[ResLayoutInd] = s; } } @@ -169,7 +171,7 @@ void ShaderResourceBindingD3D11Impl::InitializeStaticResources(const IPipelineSt #ifdef DILIGENT_DEBUG { - auto ShaderTypeInd = GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType); + auto ShaderTypeInd = GetShaderTypePipelineIndex(pShaderD3D11->GetDesc().ShaderType, pPSOD3D11->GetDesc().PipelineType); auto ResourceLayoutInd = m_ResourceLayoutIndex[ShaderTypeInd]; VERIFY_EXPR(ResourceLayoutInd == static_cast<Int8>(shader)); } @@ -183,50 +185,20 @@ void ShaderResourceBindingD3D11Impl::InitializeStaticResources(const IPipelineSt IShaderResourceVariable* ShaderResourceBindingD3D11Impl::GetVariableByName(SHADER_TYPE ShaderType, const char* Name) { - auto Ind = GetShaderTypeIndex(ShaderType); - VERIFY_EXPR(Ind >= 0 && Ind < m_ResourceLayoutIndex.size()); - auto ResLayoutIndex = m_ResourceLayoutIndex[Ind]; - if (ResLayoutIndex < 0) - { - LOG_WARNING_MESSAGE("Unable to find mutable/dynamic variable '", Name, "': shader stage ", - GetShaderTypeLiteralName(ShaderType), " is inactive in Pipeline State '", - m_pPSO->GetDesc().Name, "'"); - return nullptr; - } - - return m_pResourceLayouts[ResLayoutIndex].GetShaderVariable(Name); + auto ResLayoutInd = GetVariableByNameHelper(ShaderType, Name, m_ResourceLayoutIndex); + return ResLayoutInd >= 0 ? m_pResourceLayouts[ResLayoutInd].GetShaderVariable(Name) : nullptr; } Uint32 ShaderResourceBindingD3D11Impl::GetVariableCount(SHADER_TYPE ShaderType) const { - auto Ind = GetShaderTypeIndex(ShaderType); - VERIFY_EXPR(Ind >= 0 && Ind < m_ResourceLayoutIndex.size()); - auto ResLayoutIndex = m_ResourceLayoutIndex[Ind]; - if (ResLayoutIndex < 0) - { - LOG_WARNING_MESSAGE("Unable to get the number of mutable/dynamic variables: shader stage ", - GetShaderTypeLiteralName(ShaderType), " is inactive in Pipeline State '", - m_pPSO->GetDesc().Name, "'"); - return 0; - } - - return m_pResourceLayouts[ResLayoutIndex].GetTotalResourceCount(); + auto ResLayoutInd = GetVariableCountHelper(ShaderType, m_ResourceLayoutIndex); + return ResLayoutInd >= 0 ? m_pResourceLayouts[ResLayoutInd].GetTotalResourceCount() : 0; } IShaderResourceVariable* ShaderResourceBindingD3D11Impl::GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) { - auto Ind = GetShaderTypeIndex(ShaderType); - VERIFY_EXPR(Ind >= 0 && Ind < m_ResourceLayoutIndex.size()); - auto ResLayoutIndex = m_ResourceLayoutIndex[Ind]; - if (ResLayoutIndex < 0) - { - LOG_WARNING_MESSAGE("Unable to get mutable/dynamic variable at index ", Index, ": shader stage ", - GetShaderTypeLiteralName(ShaderType), " is inactive in Pipeline State '", - m_pPSO->GetDesc().Name, "'"); - return nullptr; - } - - return m_pResourceLayouts[ResLayoutIndex].GetShaderVariable(Index); + auto ResLayoutInd = GetVariableByIndexHelper(ShaderType, Index, m_ResourceLayoutIndex); + return ResLayoutInd >= 0 ? m_pResourceLayouts[ResLayoutInd].GetShaderVariable(Index) : nullptr; } } // namespace Diligent |
