summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-02-20 00:08:39 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:09 +0000
commitabb6f8c12bdb7639ee4a200fa1243b1e6fb96dac (patch)
treef6dd312a1840b1955d2581cf1190092b5db76840 /Graphics
parentMoved duplicate static resources logic from PipelineResourceSignatureD3D12Imp... (diff)
downloadDiligentCore-abb6f8c12bdb7639ee4a200fa1243b1e6fb96dac.tar.gz
DiligentCore-abb6f8c12bdb7639ee4a200fa1243b1e6fb96dac.zip
Unified static resource methods in PipelineResourceSignatureVkImpl and PipelineResourceSignatureD3D12Impl
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp53
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp4
-rw-r--r--Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp36
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp4
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp35
5 files changed, 53 insertions, 79 deletions
diff --git a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
index dc86093c..416533b2 100644
--- a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
+++ b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
@@ -282,13 +282,14 @@ protected:
#endif
}
- Int8 GetStaticVariableCountHelper(SHADER_TYPE ShaderType) const
+ template <typename ShaderVarManagerType>
+ Uint32 GetStaticVariableCountImpl(SHADER_TYPE ShaderType, const ShaderVarManagerType StaticVarMgrs[]) const
{
if (!IsConsistentShaderType(ShaderType, m_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_PipelineType), " pipeline resource signature '", this->m_Desc.Name, "'.");
- return -1;
+ return 0;
}
const auto ShaderTypeInd = GetShaderTypePipelineIndex(ShaderType, m_PipelineType);
@@ -297,19 +298,21 @@ protected:
{
LOG_WARNING_MESSAGE("Unable to get the number of static variables in shader stage ", GetShaderTypeLiteralName(ShaderType),
" as the stage is inactive in PSO '", this->m_Desc.Name, "'.");
+ return 0;
}
- VERIFY_EXPR(VarMngrInd < 0 || static_cast<Uint32>(VarMngrInd) < GetNumStaticResStages());
- return VarMngrInd;
+ VERIFY_EXPR(static_cast<Uint32>(VarMngrInd) < GetNumStaticResStages());
+ return StaticVarMgrs[VarMngrInd].GetVariableCount();
}
- Int8 GetStaticVariableByNameHelper(SHADER_TYPE ShaderType, const Char* Name) const
+ template <typename ShaderVarManagerType>
+ IShaderResourceVariable* GetStaticVariableByNameImpl(SHADER_TYPE ShaderType, const Char* Name, const ShaderVarManagerType StaticVarMgrs[]) const
{
if (!IsConsistentShaderType(ShaderType, m_PipelineType))
{
LOG_WARNING_MESSAGE("Unable to find static variable '", Name, "' in shader stage ", GetShaderTypeLiteralName(ShaderType),
" as the stage is invalid for ", GetPipelineTypeString(m_PipelineType), " pipeline resource signature '", this->m_Desc.Name, "'.");
- return -1;
+ return nullptr;
}
const auto ShaderTypeInd = GetShaderTypePipelineIndex(ShaderType, m_PipelineType);
@@ -318,19 +321,21 @@ protected:
{
LOG_WARNING_MESSAGE("Unable to find static variable '", Name, "' in shader stage ", GetShaderTypeLiteralName(ShaderType),
" as the stage is inactive in PSO '", this->m_Desc.Name, "'.");
+ return nullptr;
}
- VERIFY_EXPR(VarMngrInd < 0 || static_cast<Uint32>(VarMngrInd) < GetNumStaticResStages());
- return VarMngrInd;
+ VERIFY_EXPR(static_cast<Uint32>(VarMngrInd) < GetNumStaticResStages());
+ return StaticVarMgrs[VarMngrInd].GetVariable(Name);
}
- Int8 GetStaticVariableByIndexHelper(SHADER_TYPE ShaderType, Uint32 Index) const
+ template <typename ShaderVarManagerType>
+ IShaderResourceVariable* GetStaticVariableByIndexImpl(SHADER_TYPE ShaderType, Uint32 Index, const ShaderVarManagerType StaticVarMgrs[]) const
{
if (!IsConsistentShaderType(ShaderType, m_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_PipelineType), " pipeline resource signature '", this->m_Desc.Name, "'.");
- return -1;
+ return nullptr;
}
const auto ShaderTypeInd = GetShaderTypePipelineIndex(ShaderType, m_PipelineType);
@@ -339,10 +344,34 @@ protected:
{
LOG_WARNING_MESSAGE("Unable to get static variable at index ", Index, " in shader stage ", GetShaderTypeLiteralName(ShaderType),
" as the stage is inactive in PSO '", this->m_Desc.Name, "'.");
+ return nullptr;
}
- VERIFY_EXPR(VarMngrInd < 0 || static_cast<Uint32>(VarMngrInd) < GetNumStaticResStages());
- return VarMngrInd;
+ VERIFY_EXPR(static_cast<Uint32>(VarMngrInd) < GetNumStaticResStages());
+ return StaticVarMgrs[VarMngrInd].GetVariable(Index);
+ }
+
+ template <typename ShaderVarManagerType>
+ void BindStaticResourcesImpl(Uint32 ShaderFlags,
+ IResourceMapping* pResMapping,
+ Uint32 Flags,
+ ShaderVarManagerType StaticVarMgrs[])
+ {
+ const auto PipelineType = GetPipelineType();
+ for (Uint32 ShaderInd = 0; ShaderInd < m_StaticResStageIndex.size(); ++ShaderInd)
+ {
+ const auto VarMngrInd = m_StaticResStageIndex[ShaderInd];
+ if (VarMngrInd >= 0)
+ {
+ VERIFY_EXPR(static_cast<Uint32>(VarMngrInd) < GetNumStaticResStages());
+ // ShaderInd is the shader type pipeline index here
+ const auto ShaderType = GetShaderTypeFromPipelineIndex(ShaderInd, PipelineType);
+ if (ShaderFlags & ShaderType)
+ {
+ StaticVarMgrs[VarMngrInd].BindResources(pResMapping, Flags);
+ }
+ }
+ }
}
// Finds a sampler that is assigned to texture Tex, when combined texture samplers are used.
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp
index 3e6428af..9c0b3ad0 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp
@@ -99,8 +99,8 @@ public:
void Destroy(IMemoryAllocator& Allocator);
- ShaderVariableD3D12Impl* GetVariable(const Char* Name);
- ShaderVariableD3D12Impl* GetVariable(Uint32 Index);
+ ShaderVariableD3D12Impl* GetVariable(const Char* Name) const;
+ ShaderVariableD3D12Impl* GetVariable(Uint32 Index) const;
void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags);
diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
index 4eb6bc1e..e61dd9fd 100644
--- a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
@@ -428,52 +428,24 @@ void PipelineResourceSignatureD3D12Impl::CreateShaderResourceBinding(IShaderReso
Uint32 PipelineResourceSignatureD3D12Impl::GetStaticVariableCount(SHADER_TYPE ShaderType) const
{
- const auto VarMngrInd = GetStaticVariableCountHelper(ShaderType);
- if (VarMngrInd < 0)
- return 0;
-
- auto& StaticVarMgr = m_StaticVarsMgrs[VarMngrInd];
- return StaticVarMgr.GetVariableCount();
+ return GetStaticVariableCountImpl(ShaderType, m_StaticVarsMgrs);
}
IShaderResourceVariable* PipelineResourceSignatureD3D12Impl::GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name)
{
- const auto VarMngrInd = GetStaticVariableByNameHelper(ShaderType, Name);
- if (VarMngrInd < 0)
- return nullptr;
-
- auto& StaticVarMgr = m_StaticVarsMgrs[VarMngrInd];
- return StaticVarMgr.GetVariable(Name);
+ return GetStaticVariableByNameImpl(ShaderType, Name, m_StaticVarsMgrs);
}
IShaderResourceVariable* PipelineResourceSignatureD3D12Impl::GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index)
{
- const auto VarMngrInd = GetStaticVariableByIndexHelper(ShaderType, Index);
- if (VarMngrInd < 0)
- return nullptr;
-
- auto& StaticVarMgr = m_StaticVarsMgrs[VarMngrInd];
- return StaticVarMgr.GetVariable(Index);
+ return GetStaticVariableByIndexImpl(ShaderType, Index, m_StaticVarsMgrs);
}
void PipelineResourceSignatureD3D12Impl::BindStaticResources(Uint32 ShaderFlags,
IResourceMapping* pResMapping,
Uint32 Flags)
{
- const auto PipelineType = GetPipelineType();
- for (Uint32 ShaderInd = 0; ShaderInd < m_StaticResStageIndex.size(); ++ShaderInd)
- {
- const auto VarMngrInd = m_StaticResStageIndex[ShaderInd];
- if (VarMngrInd >= 0)
- {
- // ShaderInd is the shader type pipeline index here
- const auto ShaderType = GetShaderTypeFromPipelineIndex(ShaderInd, PipelineType);
- if (ShaderFlags & ShaderType)
- {
- m_StaticVarsMgrs[VarMngrInd].BindResources(pResMapping, Flags);
- }
- }
- }
+ BindStaticResourcesImpl(ShaderFlags, pResMapping, Flags, m_StaticVarsMgrs);
}
size_t PipelineResourceSignatureD3D12Impl::CalculateHash() const
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp
index fb71679d..08000a6e 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp
@@ -135,7 +135,7 @@ void ShaderVariableManagerD3D12::Destroy(IMemoryAllocator& Allocator)
}
}
-ShaderVariableD3D12Impl* ShaderVariableManagerD3D12::GetVariable(const Char* Name)
+ShaderVariableD3D12Impl* ShaderVariableManagerD3D12::GetVariable(const Char* Name) const
{
ShaderVariableD3D12Impl* pVar = nullptr;
for (Uint32 v = 0; v < m_NumVariables; ++v)
@@ -152,7 +152,7 @@ ShaderVariableD3D12Impl* ShaderVariableManagerD3D12::GetVariable(const Char* Nam
}
-ShaderVariableD3D12Impl* ShaderVariableManagerD3D12::GetVariable(Uint32 Index)
+ShaderVariableD3D12Impl* ShaderVariableManagerD3D12::GetVariable(Uint32 Index) const
{
if (Index >= m_NumVariables)
{
diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp
index 2489ee10..9bff0621 100644
--- a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp
@@ -747,51 +747,24 @@ void PipelineResourceSignatureVkImpl::CreateShaderResourceBinding(IShaderResourc
Uint32 PipelineResourceSignatureVkImpl::GetStaticVariableCount(SHADER_TYPE ShaderType) const
{
- const auto VarMngrInd = GetStaticVariableCountHelper(ShaderType);
- if (VarMngrInd < 0)
- return 0;
-
- auto& StaticVarMgr = m_StaticVarsMgrs[VarMngrInd];
- return StaticVarMgr.GetVariableCount();
+ return GetStaticVariableCountImpl(ShaderType, m_StaticVarsMgrs);
}
IShaderResourceVariable* PipelineResourceSignatureVkImpl::GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name)
{
- const auto VarMngrInd = GetStaticVariableByNameHelper(ShaderType, Name);
- if (VarMngrInd < 0)
- return nullptr;
-
- auto& StaticVarMgr = m_StaticVarsMgrs[VarMngrInd];
- return StaticVarMgr.GetVariable(Name);
+ return GetStaticVariableByNameImpl(ShaderType, Name, m_StaticVarsMgrs);
}
IShaderResourceVariable* PipelineResourceSignatureVkImpl::GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index)
{
- const auto VarMngrInd = GetStaticVariableByIndexHelper(ShaderType, Index);
- if (VarMngrInd < 0)
- return nullptr;
-
- const auto& StaticVarMgr = m_StaticVarsMgrs[VarMngrInd];
- return StaticVarMgr.GetVariable(Index);
+ return GetStaticVariableByIndexImpl(ShaderType, Index, m_StaticVarsMgrs);
}
void PipelineResourceSignatureVkImpl::BindStaticResources(Uint32 ShaderFlags,
IResourceMapping* pResMapping,
Uint32 Flags)
{
- const auto PipelineType = GetPipelineType();
- for (auto StaticResStageIdx : m_StaticResStageIndex)
- {
- if (StaticResStageIdx >= 0)
- {
- // ShaderInd is the shader type pipeline index here
- const auto ShaderType = GetShaderTypeFromPipelineIndex(StaticResStageIdx, PipelineType);
- if (ShaderFlags & ShaderType)
- {
- m_StaticVarsMgrs[StaticResStageIdx].BindResources(pResMapping, Flags);
- }
- }
- }
+ BindStaticResourcesImpl(ShaderFlags, pResMapping, Flags, m_StaticVarsMgrs);
}
void PipelineResourceSignatureVkImpl::InitSRBResourceCache(ShaderResourceCacheVk& ResourceCache,