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/GraphicsEngineOpenGL | |
| 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/GraphicsEngineOpenGL')
4 files changed, 65 insertions, 10 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLPipelineResourceLayout.hpp b/Graphics/GraphicsEngineOpenGL/include/GLPipelineResourceLayout.hpp index d3b11a18..80f622c9 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLPipelineResourceLayout.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/GLPipelineResourceLayout.hpp @@ -98,6 +98,7 @@ public: void Initialize(GLProgramResources* ProgramResources, Uint32 NumPrograms, + PIPELINE_TYPE PipelineType, const PipelineResourceLayoutDesc& ResourceLayout, const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes, @@ -331,9 +332,11 @@ private: /*34*/ OffsetType m_ImageOffset = 0; /*36*/ OffsetType m_StorageBufferOffset = 0; /*38*/ OffsetType m_VariableEndOffset = 0; -/*40*/ std::array<Int8, NUM_SHADER_TYPES> m_ProgramIndex; -/*48*/ Uint8 m_NumPrograms = 0; -/*49*/ +/*40*/ std::array<Int8, MAX_SHADERS_IN_PIPELINE> m_ProgramIndex = {}; +/*45*/ Uint8 m_NumPrograms = 0; +/*46*/ Uint8 m_PipelineType = 255u; +/*47*/ +/*48*/ // End of structure // clang-format on template <typename ResourceType> OffsetType GetResourceOffset() const; diff --git a/Graphics/GraphicsEngineOpenGL/src/GLPipelineResourceLayout.cpp b/Graphics/GraphicsEngineOpenGL/src/GLPipelineResourceLayout.cpp index 16940bda..0955a54f 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLPipelineResourceLayout.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLPipelineResourceLayout.cpp @@ -60,6 +60,7 @@ size_t GLPipelineResourceLayout::GetRequiredMemorySize(GLProgramResources* void GLPipelineResourceLayout::Initialize(GLProgramResources* ProgramResources, Uint32 NumPrograms, + PIPELINE_TYPE PipelineType, const PipelineResourceLayoutDesc& ResourceLayout, const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes, @@ -97,6 +98,8 @@ void GLPipelineResourceLayout::Initialize(GLProgramResources* P auto TotalMemorySize = m_VariableEndOffset + m_NumPrograms * sizeof(GLProgramResources::ResourceCounters); VERIFY_EXPR(TotalMemorySize == GetRequiredMemorySize(ProgramResources, NumPrograms, ResourceLayout, AllowedVarTypes, NumAllowedTypes)); + m_PipelineType = PipelineType; + auto& ResLayoutDataAllocator = GetRawAllocator(); if (TotalMemorySize) { @@ -195,7 +198,7 @@ void GLPipelineResourceLayout::Initialize(GLProgramResources* P while (ShaderStages != SHADER_TYPE_UNKNOWN) { auto Stage = static_cast<SHADER_TYPE>(Uint32{ShaderStages} & ~(Uint32{ShaderStages} - 1)); - auto ShaderInd = GetShaderTypeIndex(Stage); + auto ShaderInd = GetShaderTypePipelineIndex(Stage, PipelineType); m_ProgramIndex[ShaderInd] = static_cast<Int8>(prog); ShaderStages = static_cast<SHADER_TYPE>(Uint32{ShaderStages} & ~Stage); } @@ -487,6 +490,8 @@ IShaderResourceVariable* GLPipelineResourceLayout::GetResourceByName(SHADER_TYPE IShaderResourceVariable* GLPipelineResourceLayout::GetShaderVariable(SHADER_TYPE ShaderStage, const Char* Name) { + VERIFY_EXPR(IsConsistentShaderType(ShaderStage, static_cast<PIPELINE_TYPE>(m_PipelineType))); + if (auto* pUB = GetResourceByName<UniformBuffBindInfo>(ShaderStage, Name)) return pUB; @@ -504,12 +509,17 @@ IShaderResourceVariable* GLPipelineResourceLayout::GetShaderVariable(SHADER_TYPE Uint32 GLPipelineResourceLayout::GetNumVariables(SHADER_TYPE ShaderStage) const { + VERIFY_EXPR(IsConsistentShaderType(ShaderStage, static_cast<PIPELINE_TYPE>(m_PipelineType))); VERIFY(IsPowerOfTwo(Uint32{ShaderStage}), "Only one shader stage must be specified"); - auto ShaderInd = GetShaderTypeIndex(ShaderStage); + auto ShaderInd = GetShaderTypePipelineIndex(ShaderStage, static_cast<PIPELINE_TYPE>(m_PipelineType)); auto ProgIdx = m_ProgramIndex[ShaderInd]; if (ProgIdx < 0) + { + LOG_WARNING_MESSAGE("Unable to get the number of variables in shader stage ", GetShaderTypeLiteralName(ShaderStage), + " as the stage is inactive"); return 0; + } const auto& VariableEndOffset = GetProgramVarEndOffsets(ProgIdx); const auto& VariableStartOffset = ProgIdx > 0 ? GetProgramVarEndOffsets(ProgIdx - 1) : GLProgramResources::ResourceCounters{}; @@ -569,7 +579,7 @@ private: IShaderResourceVariable* GLPipelineResourceLayout::GetShaderVariable(SHADER_TYPE ShaderStage, Uint32 Index) { VERIFY(IsPowerOfTwo(Uint32{ShaderStage}), "Only one shader stage must be specified"); - auto ShaderInd = GetShaderTypeIndex(ShaderStage); + auto ShaderInd = GetShaderTypePipelineIndex(ShaderStage, static_cast<PIPELINE_TYPE>(m_PipelineType)); auto ProgIdx = m_ProgramIndex[ShaderInd]; if (ProgIdx < 0) @@ -647,7 +657,7 @@ Uint32 GLPipelineResourceLayout::GetVariableIndex(const GLVariableBase& Var) con } auto FirstStage = static_cast<SHADER_TYPE>(Uint32{Var.m_Attribs.ShaderStages} & ~(Uint32{Var.m_Attribs.ShaderStages} - 1)); - auto ProgIdx = m_ProgramIndex[GetShaderTypeIndex(FirstStage)]; + auto ProgIdx = m_ProgramIndex[GetShaderTypePipelineIndex(FirstStage, static_cast<PIPELINE_TYPE>(m_PipelineType))]; VERIFY(ProgIdx >= 0, "This shader stage is not initialized in the resource layout"); const auto& VariableEndOffset = GetProgramVarEndOffsets(ProgIdx); diff --git a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp index 1cc0a1ef..399983c9 100644 --- a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp @@ -120,7 +120,7 @@ PipelineStateGLImpl::PipelineStateGLImpl(IReferenceCounters* pRefCoun } // Initialize master resource layout that keeps all variable types and does not reference a resource cache - m_ResourceLayout.Initialize(m_ProgramResources.data(), static_cast<Uint32>(m_GLPrograms.size()), m_Desc.ResourceLayout, nullptr, 0, nullptr); + m_ResourceLayout.Initialize(m_ProgramResources.data(), static_cast<Uint32>(m_GLPrograms.size()), m_Desc.PipelineType, m_Desc.ResourceLayout, nullptr, 0, nullptr); } m_StaticSamplers.resize(m_Desc.ResourceLayout.NumStaticSamplers); @@ -132,7 +132,7 @@ PipelineStateGLImpl::PipelineStateGLImpl(IReferenceCounters* pRefCoun { // Clone only static variables into static resource layout, assign and initialize static resource cache const SHADER_RESOURCE_VARIABLE_TYPE StaticVars[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC}; - m_StaticResourceLayout.Initialize(m_ProgramResources.data(), static_cast<Uint32>(m_GLPrograms.size()), m_Desc.ResourceLayout, StaticVars, _countof(StaticVars), &m_StaticResourceCache); + m_StaticResourceLayout.Initialize(m_ProgramResources.data(), static_cast<Uint32>(m_GLPrograms.size()), m_Desc.PipelineType, m_Desc.ResourceLayout, StaticVars, _countof(StaticVars), &m_StaticResourceCache); InitStaticSamplersInResourceCache(m_StaticResourceLayout, m_StaticResourceCache); } } @@ -254,16 +254,37 @@ void PipelineStateGLImpl::BindStaticResources(Uint32 ShaderFlags, IResourceMappi Uint32 PipelineStateGLImpl::GetStaticVariableCount(SHADER_TYPE ShaderType) const { + if (!IsConsistentShaderType(ShaderType, m_Desc.PipelineType)) + { + LOG_WARNING_MESSAGE("Unable to get the number of static variables in shader stage ", GetShaderTypeLiteralName(ShaderType), + " as the stage is invalid for ", GetPipelineTypeString(m_Desc.PipelineType), " pipeline '", m_Desc.Name, "'"); + return 0; + } + return m_StaticResourceLayout.GetNumVariables(ShaderType); } IShaderResourceVariable* PipelineStateGLImpl::GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name) { + if (!IsConsistentShaderType(ShaderType, m_Desc.PipelineType)) + { + LOG_WARNING_MESSAGE("Unable to find static variable '", Name, "' in shader stage ", GetShaderTypeLiteralName(ShaderType), + " as the stage is invalid for ", GetPipelineTypeString(m_Desc.PipelineType), " pipeline '", m_Desc.Name, "'"); + return nullptr; + } + return m_StaticResourceLayout.GetShaderVariable(ShaderType, Name); } IShaderResourceVariable* PipelineStateGLImpl::GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) { + if (!IsConsistentShaderType(ShaderType, m_Desc.PipelineType)) + { + LOG_WARNING_MESSAGE("Unable to get static variable at index ", Index, " in shader stage ", GetShaderTypeLiteralName(ShaderType), + " as the stage is invalid for ", GetPipelineTypeString(m_Desc.PipelineType), " pipeline '", m_Desc.Name, "'"); + return nullptr; + } + return m_StaticResourceLayout.GetShaderVariable(ShaderType, Index); } diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp index c9639956..f3e6182b 100644 --- a/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp @@ -53,7 +53,7 @@ ShaderResourceBindingGLImpl::ShaderResourceBindingGLImpl(IReferenceCounters* pR const SHADER_RESOURCE_VARIABLE_TYPE SRBVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC}; const auto& ResourceLayout = pPSO->GetDesc().ResourceLayout; - m_ResourceLayout.Initialize(ProgramResources, NumPrograms, ResourceLayout, SRBVarTypes, _countof(SRBVarTypes), &m_ResourceCache); + m_ResourceLayout.Initialize(ProgramResources, NumPrograms, pPSO->GetDesc().PipelineType, ResourceLayout, SRBVarTypes, _countof(SRBVarTypes), &m_ResourceCache); } ShaderResourceBindingGLImpl::~ShaderResourceBindingGLImpl() @@ -70,16 +70,37 @@ void ShaderResourceBindingGLImpl::BindResources(Uint32 ShaderFlags, IResourceMap IShaderResourceVariable* ShaderResourceBindingGLImpl::GetVariableByName(SHADER_TYPE ShaderType, const char* Name) { + if (!IsConsistentShaderType(ShaderType, m_pPSO->GetDesc().PipelineType)) + { + LOG_WARNING_MESSAGE("Unable to find mutable/dynamic variable '", Name, "' in shader stage ", GetShaderTypeLiteralName(ShaderType), + " as the stage is invalid for ", GetPipelineTypeString(m_pPSO->GetDesc().PipelineType), " pipeline '", m_pPSO->GetDesc().Name, "'"); + return nullptr; + } + return m_ResourceLayout.GetShaderVariable(ShaderType, Name); } Uint32 ShaderResourceBindingGLImpl::GetVariableCount(SHADER_TYPE ShaderType) const { + if (!IsConsistentShaderType(ShaderType, m_pPSO->GetDesc().PipelineType)) + { + LOG_WARNING_MESSAGE("Unable to get the number of mutable/dynamic variables in shader stage ", GetShaderTypeLiteralName(ShaderType), + " as the stage is invalid for ", GetPipelineTypeString(m_pPSO->GetDesc().PipelineType), " pipeline '", m_pPSO->GetDesc().Name, "'"); + return 0; + } + return m_ResourceLayout.GetNumVariables(ShaderType); } IShaderResourceVariable* ShaderResourceBindingGLImpl::GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) { + if (!IsConsistentShaderType(ShaderType, m_pPSO->GetDesc().PipelineType)) + { + LOG_WARNING_MESSAGE("Unable to get mutable/dynamic variable at index ", Index, " in shader stage ", GetShaderTypeLiteralName(ShaderType), + " as the stage is invalid for ", GetPipelineTypeString(m_pPSO->GetDesc().PipelineType), " pipeline '", m_pPSO->GetDesc().Name, "'"); + return nullptr; + } + return m_ResourceLayout.GetShaderVariable(ShaderType, Index); } |
