summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-02-19 23:22:37 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:09 +0000
commit095e4961a0d3c88d459af7d48550dfff220cbada (patch)
tree33143f1bdf4f61937fcbeb73f987d4988ff5908a /Graphics
parentPipelineResourceSignatureD3D12Impl: some refactoring (diff)
downloadDiligentCore-095e4961a0d3c88d459af7d48550dfff220cbada.tar.gz
DiligentCore-095e4961a0d3c88d459af7d48550dfff220cbada.zip
Moved duplicate static resources logic from PipelineResourceSignatureD3D12Impl and PipelineResourceSignatureVkImpl to PipelineResourceSignatureBase
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp68
-rw-r--r--Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp15
-rw-r--r--Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp54
-rw-r--r--Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp5
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp64
5 files changed, 95 insertions, 111 deletions
diff --git a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
index 50a52dad..dc86093c 100644
--- a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
+++ b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
@@ -41,6 +41,7 @@
#include "FixedLinearAllocator.hpp"
#include "BasicMath.hpp"
#include "StringTools.hpp"
+#include "PlatformMisc.hpp"
namespace Diligent
{
@@ -99,6 +100,34 @@ public:
this->m_Desc.CombinedSamplerSuffix = nullptr;
ValidatePipelineResourceSignatureDesc(Desc);
+
+ // Determine shader stages that have any resources as well as
+ // shader stages that have static resources.
+ for (Uint32 i = 0; i < Desc.NumResources; ++i)
+ {
+ const auto& ResDesc = Desc.Resources[i];
+
+ m_ShaderStages |= ResDesc.ShaderStages;
+ if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
+ m_StaticResShaderStages |= ResDesc.ShaderStages;
+ }
+
+ if (m_ShaderStages != SHADER_TYPE_UNKNOWN)
+ {
+ m_PipelineType = PipelineTypeFromShaderStages(m_ShaderStages);
+ DEV_CHECK_ERR(m_PipelineType != PIPELINE_TYPE_INVALID, "Failed to deduce pipeline type from shader stages");
+ }
+
+ {
+ Uint32 StaticVarStageIdx = 0;
+ for (auto StaticResStages = m_StaticResShaderStages; StaticResStages != SHADER_TYPE_UNKNOWN; ++StaticVarStageIdx)
+ {
+ const auto StageBit = ExtractLSB(StaticResStages);
+ const auto ShaderTypeInd = GetShaderTypePipelineIndex(StageBit, m_PipelineType);
+ m_StaticResStageIndex[ShaderTypeInd] = static_cast<Int8>(StaticVarStageIdx);
+ }
+ VERIFY_EXPR(StaticVarStageIdx == GetNumStaticResStages());
+ }
}
~PipelineResourceSignatureBase()
@@ -126,12 +155,21 @@ public:
}
// Returns the number of shader stages that have resources.
- Uint32 GetNumActiveShaderStages() const { return m_NumShaderStages; }
+ Uint32 GetNumActiveShaderStages() const
+ {
+ return PlatformMisc::CountOneBits(Uint32{m_ShaderStages});
+ }
+
+ // Returns the number of shader stages that have static resources.
+ Uint32 GetNumStaticResStages() const
+ {
+ return PlatformMisc::CountOneBits(Uint32{m_StaticResShaderStages});
+ }
// Returns the type of the active shader stage with the given index.
SHADER_TYPE GetActiveShaderStageType(Uint32 StageIndex) const
{
- VERIFY_EXPR(StageIndex < m_NumShaderStages);
+ VERIFY_EXPR(StageIndex < GetNumActiveShaderStages());
SHADER_TYPE Stages = m_ShaderStages;
for (Uint32 Index = 0; Stages != SHADER_TYPE_UNKNOWN; ++Index)
@@ -237,12 +275,14 @@ protected:
this->m_Desc.ImmutableSamplers = nullptr;
this->m_Desc.CombinedSamplerSuffix = nullptr;
+ m_StaticResStageIndex.fill(-1);
+
#if DILIGENT_DEBUG
m_IsDestructed = true;
#endif
}
- Int8 GetStaticVariableCountHelper(SHADER_TYPE ShaderType, const std::array<Int8, MAX_SHADERS_IN_PIPELINE>& StaticVarIndex) const
+ Int8 GetStaticVariableCountHelper(SHADER_TYPE ShaderType) const
{
if (!IsConsistentShaderType(ShaderType, m_PipelineType))
{
@@ -252,17 +292,18 @@ protected:
}
const auto ShaderTypeInd = GetShaderTypePipelineIndex(ShaderType, m_PipelineType);
- const auto VarMngrInd = StaticVarIndex[ShaderTypeInd];
+ const auto VarMngrInd = m_StaticResStageIndex[ShaderTypeInd];
if (VarMngrInd < 0)
{
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, "'.");
}
+ VERIFY_EXPR(VarMngrInd < 0 || static_cast<Uint32>(VarMngrInd) < GetNumStaticResStages());
return VarMngrInd;
}
- Int8 GetStaticVariableByNameHelper(SHADER_TYPE ShaderType, const Char* Name, const std::array<Int8, MAX_SHADERS_IN_PIPELINE>& StaticVarIndex) const
+ Int8 GetStaticVariableByNameHelper(SHADER_TYPE ShaderType, const Char* Name) const
{
if (!IsConsistentShaderType(ShaderType, m_PipelineType))
{
@@ -272,17 +313,18 @@ protected:
}
const auto ShaderTypeInd = GetShaderTypePipelineIndex(ShaderType, m_PipelineType);
- const auto VarMngrInd = StaticVarIndex[ShaderTypeInd];
+ const auto VarMngrInd = m_StaticResStageIndex[ShaderTypeInd];
if (VarMngrInd < 0)
{
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, "'.");
}
+ VERIFY_EXPR(VarMngrInd < 0 || static_cast<Uint32>(VarMngrInd) < GetNumStaticResStages());
return VarMngrInd;
}
- Int8 GetStaticVariableByIndexHelper(SHADER_TYPE ShaderType, Uint32 Index, const std::array<Int8, MAX_SHADERS_IN_PIPELINE>& StaticVarIndex) const
+ Int8 GetStaticVariableByIndexHelper(SHADER_TYPE ShaderType, Uint32 Index) const
{
if (!IsConsistentShaderType(ShaderType, m_PipelineType))
{
@@ -292,13 +334,14 @@ protected:
}
const auto ShaderTypeInd = GetShaderTypePipelineIndex(ShaderType, m_PipelineType);
- const auto VarMngrInd = StaticVarIndex[ShaderTypeInd];
+ const auto VarMngrInd = m_StaticResStageIndex[ShaderTypeInd];
if (VarMngrInd < 0)
{
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, "'.");
}
+ VERIFY_EXPR(VarMngrInd < 0 || static_cast<Uint32>(VarMngrInd) < GetNumStaticResStages());
return VarMngrInd;
}
@@ -340,10 +383,15 @@ protected:
// Shader stages that have resources.
SHADER_TYPE m_ShaderStages = SHADER_TYPE_UNKNOWN;
+ // Shader stages that have static resources.
+ SHADER_TYPE m_StaticResShaderStages = SHADER_TYPE_UNKNOWN;
+
PIPELINE_TYPE m_PipelineType = PIPELINE_TYPE_INVALID;
- // The number of shader stages that have resources.
- Uint8 m_NumShaderStages = 0;
+ // Index of the shader stage that has static resources, for every shader
+ // type in the pipeline (given by GetShaderTypePipelineIndex(ShaderType, m_PipelineType)).
+ std::array<Int8, MAX_SHADERS_IN_PIPELINE> m_StaticResStageIndex = {-1, -1, -1, -1, -1, -1};
+ static_assert(MAX_SHADERS_IN_PIPELINE == 6, "Please update the initializer list above");
#ifdef DILIGENT_DEBUG
bool m_IsDestructed = false;
diff --git a/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp
index 116529b5..11c9f123 100644
--- a/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp
@@ -291,17 +291,10 @@ private:
std::vector<Uint32, STDAllocatorRawMem<Uint32>> GetCacheTableSizes() const;
private:
- ResourceAttribs* m_pResourceAttribs = nullptr; // [m_Desc.NumResources]
-
- // Index of the static variable manager in m_StaticVarsMgrs array, for
- // every shader type in the pipeline (given by GetShaderTypePipelineIndex()).
- std::array<Int8, MAX_SHADERS_IN_PIPELINE> m_StaticVarIndex = {-1, -1, -1, -1, -1, -1};
- static_assert(MAX_SHADERS_IN_PIPELINE == 6, "Please update the initializer list above");
-
- ShaderResourceCacheD3D12* m_pStaticResCache = nullptr;
- ShaderVariableManagerD3D12* m_StaticVarsMgrs = nullptr; // [m_NumShaderStages]
-
- ImmutableSamplerAttribs* m_ImmutableSamplers = nullptr; // [m_Desc.NumImmutableSamplers]
+ ResourceAttribs* m_pResourceAttribs = nullptr; // [m_Desc.NumResources]
+ ShaderResourceCacheD3D12* m_pStaticResCache = nullptr;
+ ShaderVariableManagerD3D12* m_StaticVarsMgrs = nullptr; // [m_NumShaderStages]
+ ImmutableSamplerAttribs* m_ImmutableSamplers = nullptr; // [m_Desc.NumImmutableSamplers]
RootParamsManager m_RootParams;
diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
index 940ed4d7..4eb6bc1e 100644
--- a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
@@ -79,35 +79,11 @@ PipelineResourceSignatureD3D12Impl::PipelineResourceSignatureD3D12Impl(IReferenc
ReserveSpaceForDescription(MemPool, Desc);
- SHADER_TYPE StaticResStages = SHADER_TYPE_UNKNOWN; // Shader stages that have static resources
- for (Uint32 i = 0; i < Desc.NumResources; ++i)
- {
- const auto& ResDesc = Desc.Resources[i];
-
- m_ShaderStages |= ResDesc.ShaderStages;
-
- if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
- StaticResStages |= ResDesc.ShaderStages;
- }
-
- m_NumShaderStages = static_cast<Uint8>(PlatformMisc::CountOneBits(static_cast<Uint32>(m_ShaderStages)));
- if (m_ShaderStages != SHADER_TYPE_UNKNOWN)
- {
- m_PipelineType = PipelineTypeFromShaderStages(m_ShaderStages);
- DEV_CHECK_ERR(m_PipelineType != PIPELINE_TYPE_INVALID, "Failed to deduce pipeline type from shader stages");
- }
-
- int StaticVarStageCount = 0; // The number of shader stages that have static variables
- for (; StaticResStages != SHADER_TYPE_UNKNOWN; ++StaticVarStageCount)
- {
- const auto StageBit = ExtractLSB(StaticResStages);
- const auto ShaderTypeInd = GetShaderTypePipelineIndex(StageBit, m_PipelineType);
- m_StaticVarIndex[ShaderTypeInd] = static_cast<Int8>(StaticVarStageCount);
- }
- if (StaticVarStageCount > 0)
+ const auto NumStaticResStages = GetNumStaticResStages();
+ if (NumStaticResStages > 0)
{
MemPool.AddSpace<ShaderResourceCacheD3D12>(1);
- MemPool.AddSpace<ShaderVariableManagerD3D12>(StaticVarStageCount);
+ MemPool.AddSpace<ShaderVariableManagerD3D12>(NumStaticResStages);
}
MemPool.Reserve();
@@ -127,12 +103,12 @@ PipelineResourceSignatureD3D12Impl::PipelineResourceSignatureD3D12Impl(IReferenc
StaticResCacheTblSizesArrayType StaticResCacheTblSizes = {};
AllocateRootParameters(StaticResCacheTblSizes);
- if (StaticVarStageCount > 0)
+ if (NumStaticResStages > 0)
{
m_pStaticResCache = MemPool.Construct<ShaderResourceCacheD3D12>(CacheContentType::Signature);
// Constructor of ShaderVariableManagerD3D12 is noexcept, so we can safely construct all manager objects.
// Moreover, all objects must be constructed if an exception is thrown for Destruct() method to work properly.
- m_StaticVarsMgrs = MemPool.ConstructArray<ShaderVariableManagerD3D12>(StaticVarStageCount, std::ref(*this), std::ref(*m_pStaticResCache));
+ m_StaticVarsMgrs = MemPool.ConstructArray<ShaderVariableManagerD3D12>(NumStaticResStages, std::ref(*this), std::ref(*m_pStaticResCache));
m_pStaticResCache->Initialize(GetRawAllocator(), static_cast<Uint32>(StaticResCacheTblSizes.size()), StaticResCacheTblSizes.data());
#ifdef DILIGENT_DEBUG
@@ -143,12 +119,12 @@ PipelineResourceSignatureD3D12Impl::PipelineResourceSignatureD3D12Impl(IReferenc
#endif
constexpr SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC};
- for (Uint32 i = 0; i < m_StaticVarIndex.size(); ++i)
+ for (Uint32 i = 0; i < m_StaticResStageIndex.size(); ++i)
{
- Int8 Idx = m_StaticVarIndex[i];
+ Int8 Idx = m_StaticResStageIndex[i];
if (Idx >= 0)
{
- VERIFY_EXPR(Idx < StaticVarStageCount);
+ VERIFY_EXPR(static_cast<Uint32>(Idx) < NumStaticResStages);
const auto ShaderType = GetShaderTypeFromPipelineIndex(i, GetPipelineType());
m_StaticVarsMgrs[Idx].Initialize(*this, GetRawAllocator(), AllowedVarTypes, _countof(AllowedVarTypes), ShaderType);
}
@@ -362,16 +338,14 @@ void PipelineResourceSignatureD3D12Impl::Destruct()
if (m_StaticVarsMgrs != nullptr)
{
- for (size_t i = 0; i < m_StaticVarIndex.size(); ++i)
+ for (auto Idx : m_StaticResStageIndex)
{
- auto Idx = m_StaticVarIndex[i];
if (Idx >= 0)
{
m_StaticVarsMgrs[Idx].Destroy(RawAllocator);
m_StaticVarsMgrs[Idx].~ShaderVariableManagerD3D12();
}
}
- m_StaticVarIndex.fill(-1);
m_StaticVarsMgrs = nullptr;
}
@@ -454,7 +428,7 @@ void PipelineResourceSignatureD3D12Impl::CreateShaderResourceBinding(IShaderReso
Uint32 PipelineResourceSignatureD3D12Impl::GetStaticVariableCount(SHADER_TYPE ShaderType) const
{
- const auto VarMngrInd = GetStaticVariableCountHelper(ShaderType, m_StaticVarIndex);
+ const auto VarMngrInd = GetStaticVariableCountHelper(ShaderType);
if (VarMngrInd < 0)
return 0;
@@ -464,7 +438,7 @@ Uint32 PipelineResourceSignatureD3D12Impl::GetStaticVariableCount(SHADER_TYPE Sh
IShaderResourceVariable* PipelineResourceSignatureD3D12Impl::GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name)
{
- const auto VarMngrInd = GetStaticVariableByNameHelper(ShaderType, Name, m_StaticVarIndex);
+ const auto VarMngrInd = GetStaticVariableByNameHelper(ShaderType, Name);
if (VarMngrInd < 0)
return nullptr;
@@ -474,7 +448,7 @@ IShaderResourceVariable* PipelineResourceSignatureD3D12Impl::GetStaticVariableBy
IShaderResourceVariable* PipelineResourceSignatureD3D12Impl::GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index)
{
- const auto VarMngrInd = GetStaticVariableByIndexHelper(ShaderType, Index, m_StaticVarIndex);
+ const auto VarMngrInd = GetStaticVariableByIndexHelper(ShaderType, Index);
if (VarMngrInd < 0)
return nullptr;
@@ -487,9 +461,9 @@ void PipelineResourceSignatureD3D12Impl::BindStaticResources(Uint32 S
Uint32 Flags)
{
const auto PipelineType = GetPipelineType();
- for (Uint32 ShaderInd = 0; ShaderInd < m_StaticVarIndex.size(); ++ShaderInd)
+ for (Uint32 ShaderInd = 0; ShaderInd < m_StaticResStageIndex.size(); ++ShaderInd)
{
- const auto VarMngrInd = m_StaticVarIndex[ShaderInd];
+ const auto VarMngrInd = m_StaticResStageIndex[ShaderInd];
if (VarMngrInd >= 0)
{
// ShaderInd is the shader type pipeline index here
diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp
index 4236f7c1..b873d828 100644
--- a/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp
@@ -334,11 +334,6 @@ private:
// accounting for array size.
Uint16 m_DynamicStorageBufferCount = 0;
- // Mapping from shader type index given by GetShaderTypePipelineIndex() to
- // static variable manager index in m_StaticVarsMgrs array.
- std::array<Int8, MAX_SHADERS_IN_PIPELINE> m_StaticVarIndex = {-1, -1, -1, -1, -1, -1};
- static_assert(MAX_SHADERS_IN_PIPELINE == 6, "Please update the initializer list above");
-
// Static resource cache for all static resources
ShaderResourceCacheVk* m_pStaticResCache = nullptr;
// Static variables manager for every shader stage
diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp
index 38fa6670..2489ee10 100644
--- a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp
@@ -275,8 +275,6 @@ PipelineResourceSignatureVkImpl::PipelineResourceSignatureVkImpl(IReferenceCount
TPipelineResourceSignatureBase{pRefCounters, pDevice, Desc, bIsDeviceInternal},
m_SRBMemAllocator{GetRawAllocator()}
{
- m_StaticVarIndex.fill(-1);
-
try
{
FixedLinearAllocator MemPool{GetRawAllocator()};
@@ -293,43 +291,24 @@ PipelineResourceSignatureVkImpl::PipelineResourceSignatureVkImpl(IReferenceCount
CacheOffsetsType CacheGroupSizes = {}; // Required cache size for each cache group
BindingCountType BindingCount = {}; // Binding count in each cache group
- SHADER_TYPE StaticResStages = SHADER_TYPE_UNKNOWN; // Shader stages that have static resources
for (Uint32 i = 0; i < Desc.NumResources; ++i)
{
const auto& ResDesc = Desc.Resources[i];
const auto CacheGroup = GetResourceCacheGroup(ResDesc);
- m_ShaderStages |= ResDesc.ShaderStages;
-
if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
- {
- StaticResStages |= ResDesc.ShaderStages;
StaticResourceCount += ResDesc.ArraySize;
- }
BindingCount[CacheGroup] += 1;
// Note that we may reserve space for separate immutable samplers, which will never be used, but this is OK.
CacheGroupSizes[CacheGroup] += ResDesc.ArraySize;
}
- m_NumShaderStages = static_cast<Uint8>(PlatformMisc::CountOneBits(static_cast<Uint32>(m_ShaderStages)));
- if (m_ShaderStages != SHADER_TYPE_UNKNOWN)
- {
- m_PipelineType = PipelineTypeFromShaderStages(m_ShaderStages);
- DEV_CHECK_ERR(m_PipelineType != PIPELINE_TYPE_INVALID, "Failed to deduce pipeline type from shader stages");
- }
-
- int StaticVarStageCount = 0; // The number of shader stages that have static variables
- for (; StaticResStages != SHADER_TYPE_UNKNOWN; ++StaticVarStageCount)
- {
- const auto StageBit = ExtractLSB(StaticResStages);
- const auto ShaderTypeInd = GetShaderTypePipelineIndex(StageBit, m_PipelineType);
- m_StaticVarIndex[ShaderTypeInd] = static_cast<Int8>(StaticVarStageCount);
- }
- if (StaticVarStageCount > 0)
+ const auto NumStaticResStages = GetNumStaticResStages();
+ if (NumStaticResStages > 0)
{
MemPool.AddSpace<ShaderResourceCacheVk>(1);
- MemPool.AddSpace<ShaderVariableManagerVk>(StaticVarStageCount);
+ MemPool.AddSpace<ShaderVariableManagerVk>(NumStaticResStages);
}
MemPool.Reserve();
@@ -344,28 +323,26 @@ PipelineResourceSignatureVkImpl::PipelineResourceSignatureVkImpl(IReferenceCount
CopyDescription(MemPool, Desc);
- if (StaticVarStageCount > 0)
+ if (NumStaticResStages > 0)
{
m_pStaticResCache = MemPool.Construct<ShaderResourceCacheVk>(CacheContentType::Signature);
- m_StaticVarsMgrs = MemPool.Allocate<ShaderVariableManagerVk>(StaticVarStageCount);
+ m_StaticVarsMgrs = MemPool.ConstructArray<ShaderVariableManagerVk>(NumStaticResStages, std::ref(*this), std::ref(*m_pStaticResCache));
m_pStaticResCache->InitializeSets(GetRawAllocator(), 1, &StaticResourceCount);
}
CreateSetLayouts(CacheGroupSizes, BindingCount);
- if (StaticVarStageCount > 0)
+ if (NumStaticResStages > 0)
{
- const SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC};
-
- for (Uint32 i = 0; i < m_StaticVarIndex.size(); ++i)
+ constexpr SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC};
+ for (Uint32 i = 0; i < m_StaticResStageIndex.size(); ++i)
{
- Int8 Idx = m_StaticVarIndex[i];
+ Int8 Idx = m_StaticResStageIndex[i];
if (Idx >= 0)
{
- VERIFY_EXPR(Idx < StaticVarStageCount);
+ VERIFY_EXPR(static_cast<Uint32>(Idx) < NumStaticResStages);
const auto ShaderType = GetShaderTypeFromPipelineIndex(i, GetPipelineType());
- new (m_StaticVarsMgrs + Idx) ShaderVariableManagerVk{*this, *m_pStaticResCache};
m_StaticVarsMgrs[Idx].Initialize(*this, GetRawAllocator(), AllowedVarTypes, _countof(AllowedVarTypes), ShaderType);
}
}
@@ -610,7 +587,7 @@ void PipelineResourceSignatureVkImpl::CreateSetLayouts(const CacheOffsetsType& C
std::array<size_t, MAX_SHADERS_IN_PIPELINE> ShaderVariableDataSizes = {};
for (Uint32 s = 0; s < GetNumActiveShaderStages(); ++s)
{
- const SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC};
+ constexpr SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC};
Uint32 UnusedNumVars = 0;
ShaderVariableDataSizes[s] = ShaderVariableManagerVk::GetRequiredMemorySize(*this, AllowedVarTypes, _countof(AllowedVarTypes), GetActiveShaderStageType(s), UnusedNumVars);
@@ -683,16 +660,14 @@ void PipelineResourceSignatureVkImpl::Destruct()
if (m_StaticVarsMgrs != nullptr)
{
- for (size_t i = 0; i < m_StaticVarIndex.size(); ++i)
+ for (auto Idx : m_StaticResStageIndex)
{
- auto Idx = m_StaticVarIndex[i];
if (Idx >= 0)
{
m_StaticVarsMgrs[Idx].DestroyVariables(RawAllocator);
m_StaticVarsMgrs[Idx].~ShaderVariableManagerVk();
}
}
- m_StaticVarIndex.fill(-1);
m_StaticVarsMgrs = nullptr;
}
@@ -772,7 +747,7 @@ void PipelineResourceSignatureVkImpl::CreateShaderResourceBinding(IShaderResourc
Uint32 PipelineResourceSignatureVkImpl::GetStaticVariableCount(SHADER_TYPE ShaderType) const
{
- const auto VarMngrInd = GetStaticVariableCountHelper(ShaderType, m_StaticVarIndex);
+ const auto VarMngrInd = GetStaticVariableCountHelper(ShaderType);
if (VarMngrInd < 0)
return 0;
@@ -782,7 +757,7 @@ Uint32 PipelineResourceSignatureVkImpl::GetStaticVariableCount(SHADER_TYPE Shade
IShaderResourceVariable* PipelineResourceSignatureVkImpl::GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name)
{
- const auto VarMngrInd = GetStaticVariableByNameHelper(ShaderType, Name, m_StaticVarIndex);
+ const auto VarMngrInd = GetStaticVariableByNameHelper(ShaderType, Name);
if (VarMngrInd < 0)
return nullptr;
@@ -792,7 +767,7 @@ IShaderResourceVariable* PipelineResourceSignatureVkImpl::GetStaticVariableByNam
IShaderResourceVariable* PipelineResourceSignatureVkImpl::GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index)
{
- const auto VarMngrInd = GetStaticVariableByIndexHelper(ShaderType, Index, m_StaticVarIndex);
+ const auto VarMngrInd = GetStaticVariableByIndexHelper(ShaderType, Index);
if (VarMngrInd < 0)
return nullptr;
@@ -805,16 +780,15 @@ void PipelineResourceSignatureVkImpl::BindStaticResources(Uint32 Shad
Uint32 Flags)
{
const auto PipelineType = GetPipelineType();
- for (Uint32 ShaderInd = 0; ShaderInd < m_StaticVarIndex.size(); ++ShaderInd)
+ for (auto StaticResStageIdx : m_StaticResStageIndex)
{
- const auto VarMngrInd = m_StaticVarIndex[ShaderInd];
- if (VarMngrInd >= 0)
+ if (StaticResStageIdx >= 0)
{
// ShaderInd is the shader type pipeline index here
- const auto ShaderType = GetShaderTypeFromPipelineIndex(ShaderInd, PipelineType);
+ const auto ShaderType = GetShaderTypeFromPipelineIndex(StaticResStageIdx, PipelineType);
if (ShaderFlags & ShaderType)
{
- m_StaticVarsMgrs[VarMngrInd].BindResources(pResMapping, Flags);
+ m_StaticVarsMgrs[StaticResStageIdx].BindResources(pResMapping, Flags);
}
}
}