summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-03-10 00:37:37 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:18 +0000
commita615dcf84ce573e784e56a50bc8c2809f69c7ea7 (patch)
treeb57378ad5beac728138cfd5b51fd96b926168a87 /Graphics
parentRemoved unused ShaderVariableManagerGL::dvpVerifyBindings (diff)
downloadDiligentCore-a615dcf84ce573e784e56a50bc8c2809f69c7ea7.tar.gz
DiligentCore-a615dcf84ce573e784e56a50bc8c2809f69c7ea7.zip
Moved ProcessSignatureResources method to PipelineResourceSignatureBase
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp29
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderVariableManagerD3D12.hpp7
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp51
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/ShaderVariableManagerGL.hpp66
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp54
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp7
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp52
7 files changed, 99 insertions, 167 deletions
diff --git a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
index db5cb061..c2f3e2bc 100644
--- a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
+++ b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
@@ -376,6 +376,35 @@ public:
return m_SRBMemAllocator;
}
+ // Processes resources with the allowed variable types in the allowed shader stages
+ // and calls user-provided handler for each resource.
+ template <typename HandlerType>
+ void ProcessResources(const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
+ Uint32 NumAllowedTypes,
+ SHADER_TYPE AllowedStages,
+ HandlerType Handler) const
+ {
+ if (AllowedVarTypes == nullptr)
+ NumAllowedTypes = 1;
+
+ for (Uint32 TypeIdx = 0; TypeIdx < NumAllowedTypes; ++TypeIdx)
+ {
+ const auto IdxRange = AllowedVarTypes != nullptr ?
+ GetResourceIndexRange(AllowedVarTypes[TypeIdx]) :
+ std::make_pair<Uint32, Uint32>(0, GetTotalResourceCount());
+ for (Uint32 ResIdx = IdxRange.first; ResIdx < IdxRange.second; ++ResIdx)
+ {
+ const auto& ResDesc = GetResourceDesc(ResIdx);
+ VERIFY_EXPR(AllowedVarTypes == nullptr || ResDesc.VarType == AllowedVarTypes[TypeIdx]);
+
+ if ((ResDesc.ShaderStages & AllowedStages) != 0)
+ {
+ Handler(ResDesc, ResIdx);
+ }
+ }
+ }
+ }
+
protected:
template <typename TReserveCustomData>
FixedLinearAllocator AllocateInternalObjects(IMemoryAllocator& RawAllocator,
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderVariableManagerD3D12.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderVariableManagerD3D12.hpp
index a67b977c..7fc3c6dc 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderVariableManagerD3D12.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderVariableManagerD3D12.hpp
@@ -120,13 +120,6 @@ private:
const PipelineResourceDesc& GetResourceDesc(Uint32 Index) const;
const ResourceAttribs& GetResourceAttribs(Uint32 Index) const;
- template <typename HandlerType>
- static void ProcessSignatureResources(const PipelineResourceSignatureD3D12Impl& Signature,
- const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- SHADER_TYPE ShaderStages,
- HandlerType Handler);
-
private:
PipelineResourceSignatureD3D12Impl const* m_pSignature = nullptr;
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp
index 9078debb..b8e33cb0 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp
@@ -37,40 +37,25 @@ namespace Diligent
{
template <typename HandlerType>
-void ShaderVariableManagerD3D12::ProcessSignatureResources(const PipelineResourceSignatureD3D12Impl& Signature,
- const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- SHADER_TYPE ShaderStages,
- HandlerType Handler)
+void ProcessSignatureResources(const PipelineResourceSignatureD3D12Impl& Signature,
+ const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
+ Uint32 NumAllowedTypes,
+ SHADER_TYPE ShaderStages,
+ HandlerType Handler)
{
- const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
- const bool UsingCombinedSamplers = Signature.IsUsingCombinedSamplers();
-
- for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType + 1))
- {
- if (IsAllowedType(VarType, AllowedTypeBits))
- {
- const auto ResIdxRange = Signature.GetResourceIndexRange(VarType);
- for (Uint32 r = ResIdxRange.first; r < ResIdxRange.second; ++r)
- {
- const auto& Res = Signature.GetResourceDesc(r);
- const auto& Attr = Signature.GetResourceAttribs(r);
- VERIFY_EXPR(Res.VarType == VarType);
-
- if (!(Res.ShaderStages & ShaderStages))
- continue;
-
- if (Res.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER &&
- (UsingCombinedSamplers || Attr.IsImmutableSamplerAssigned()))
- {
- // Skip samplers combined with textures and immutable samplers
- continue;
- }
-
- Handler(r);
- }
- }
- }
+ const bool UsingCombinedSamplers = Signature.IsUsingCombinedSamplers();
+ Signature.ProcessResources(AllowedVarTypes, NumAllowedTypes, ShaderStages,
+ [&](const PipelineResourceDesc& ResDesc, Uint32 Index) //
+ {
+ const auto& ResAttr = Signature.GetResourceAttribs(Index);
+
+ // Skip samplers combined with textures and immutable samplers
+ if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER &&
+ (UsingCombinedSamplers || ResAttr.IsImmutableSamplerAssigned()))
+ return;
+
+ Handler(Index);
+ });
}
size_t ShaderVariableManagerD3D12::GetRequiredMemorySize(const PipelineResourceSignatureD3D12Impl& Signature,
diff --git a/Graphics/GraphicsEngineOpenGL/include/ShaderVariableManagerGL.hpp b/Graphics/GraphicsEngineOpenGL/include/ShaderVariableManagerGL.hpp
index 282aadd3..78e5d195 100644
--- a/Graphics/GraphicsEngineOpenGL/include/ShaderVariableManagerGL.hpp
+++ b/Graphics/GraphicsEngineOpenGL/include/ShaderVariableManagerGL.hpp
@@ -27,45 +27,29 @@
#pragma once
-// ShaderVariableManagerGL class manages resource bindings for all stages in a pipeline
+// ShaderVariableManagerGL class manages static resources of a pipeline resource signature, and
+// all types of resources for an SRB.
//
+// .-==========================-. _______________________________________________________________________________________________________________
+// || || | | | | | | | | | | |
+// __|| ShaderVariableManagerGL ||------------>| UBInfo[0] | UBInfo[1] | ... | TexInfo[0] | TexInfo[1] | ... | ImgInfo[0] | ... | SSBO[0] | ... |
+// | || || |___________|___________|_______|____________|____________|_______|____________|_________|___________|__________|
+// | '-==========================-' / \ |
+// | | m_ResIndex m_ResIndex m_ResIndex
+// | m_pSignature / \ |
+// | _____________V___________________ ________V________________________________V___________________________V__________________________________________
+// | | | | | | | | | | | | | | | |
+// | | PipelineResourceSignatureGLImpl |------>| UB[0] | UB[1] | ... | Tex[0] | Tex[1] | ... | Img[0] | Img[1] | ... | SSBOs[0] | SSBOs[1] | ... |
+// | |_________________________________| |__________|__________|_______|________|________|_______|________|________|_______|__________|__________|_______|
+// | | | | | | | | |
+// m_ResourceCache Binding Binding Binding Binding Binding Binding Binding Binding
+// | | | | | | | | |
+// | _______________________ ____V___________V________________V_________V________________V________V________________V___________V_____________
+// | | | | | | | |
+// '-->| ShaderResourceCacheGL |-------- --->| Uinform Buffers | Textures | Images | Storge Buffers |
+// |_______________________| |___________________________|___________________________|___________________________|___________________________|
//
-// To program resource cache
-//
-// A A A A A A A A
-// | | | | | | | |
-// Binding Binding Binding Binding Binding Binding Binding Binding
-// ___________________ ____|__________|__________________|________|______________|___________|______________|____________|____________
-// | | | | | | | | | | | | | | |
-// | ShaderResourcesGL |--------------->| UB[0] | UB[1] | ... | Sam[0] | Sam[1] | ... | Img[0] | Img[1] | ... | SSBOs[0] | SSBOs[1] | ... |
-// |___________________| |__________|__________|_______|________|________|_______|________|________|_______|__________|__________|_______|
-// A A A A
-// | | | |
-// Ref Ref Ref Ref
-// .-==========================-. _____|____________________________________|________________________|____________________________|______________
-// || || | | | | | | | | | | |
-// __|| ShaderVariableManagerGL ||------->| UBInfo[0] | UBInfo[1] | ... | SamInfo[0] | SamInfo[1] | ... | ImgInfo[0] | ... | SSBO[0] | ... |
-// | || || |___________|___________|_______|____________|____________|_______|____________|_________|___________|__________|
-// | '-==========================-' / \
-// | Ref Ref
-// | / \
-// | ___________________ ________V________________________________________________V_____________________________________________________
-// | | | | | | | | | | | | | | | |
-// | | ShaderResourcesGL |--------------->| UB[0] | UB[1] | ... | Sam[0] | Sam[1] | ... | Img[0] | Img[1] | ... | SSBOs[0] | SSBOs[1] | ... |
-// | |___________________| |__________|__________|_______|________|________|_______|________|________|_______|__________|__________|_______|
-// | | | | | | | | |
-// | Binding Binding Binding Binding Binding Binding Binding Binding
-// | | | | | | | | |
-// | _______________________ ____V___________V________________V_________V________________V________V________________V___________V_____________
-// | | | | | | | |
-// '-->| ShaderResourceCacheGL |----------->| Uinform Buffers | Textures | Images | Storge Buffers |
-// |_______________________| |___________________________|___________________________|___________________________|___________________________|
-//
-//
-// Note that ShaderResourcesGL are kept by PipelineStateGLImpl. ShaderVariableManagerGL class is either part of the same PSO class,
-// or part of ShaderResourceBindingGLImpl object that keeps a strong reference to the pipeline. So all references from GLVariableBase
-// are always valid.
#include <array>
@@ -284,9 +268,6 @@ public:
}
};
-
- // dbgResourceCache is only used for sanity check and as a remainder that the resource cache must be alive
- // while Layout is alive
void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags);
IShaderResourceVariable* GetVariable(const Char* Name) const;
@@ -329,13 +310,6 @@ private:
SHADER_TYPE ShaderType,
ResourceCounters& Counters);
- template <typename HandlerType>
- static void ProcessSignatureResources(const PipelineResourceSignatureGLImpl& Signature,
- const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- SHADER_TYPE ShaderType,
- HandlerType Handler);
-
// Offsets in bytes
using OffsetType = Uint16;
diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp
index 8d9a0e91..29786c30 100644
--- a/Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp
@@ -45,11 +45,13 @@ void ShaderVariableManagerGL::CountResources(const PipelineResourceSignatureGLIm
const SHADER_TYPE ShaderType,
ResourceCounters& Counters)
{
- ProcessSignatureResources(
- Signature, AllowedVarTypes, NumAllowedTypes, ShaderType,
- [&](Uint32 Index) //
+ Signature.ProcessResources(
+ AllowedVarTypes, NumAllowedTypes, ShaderType,
+ [&](const PipelineResourceDesc& ResDesc, Uint32) //
{
- const auto& ResDesc = Signature.GetResourceDesc(Index);
+ if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER)
+ return;
+
static_assert(BINDING_RANGE_COUNT == 4, "Please update the switch below to handle the new shader resource range");
switch (PipelineResourceToBindingRange(ResDesc))
{
@@ -58,45 +60,13 @@ void ShaderVariableManagerGL::CountResources(const PipelineResourceSignatureGLIm
case BINDING_RANGE_TEXTURE: ++Counters.NumTextures; break;
case BINDING_RANGE_IMAGE: ++Counters.NumImages; break;
case BINDING_RANGE_STORAGE_BUFFER: ++Counters.NumStorageBlocks; break;
- // clang-format on
+ // clang-format on
default:
UNEXPECTED("Unsupported resource type.");
}
});
}
-template <typename HandlerType>
-void ShaderVariableManagerGL::ProcessSignatureResources(const PipelineResourceSignatureGLImpl& Signature,
- const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- SHADER_TYPE ShaderType,
- HandlerType Handler)
-{
- const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
-
- for (Uint32 var_type = 0; var_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++var_type)
- {
- const auto VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(var_type);
- if (IsAllowedType(VarType, AllowedTypeBits))
- {
- const auto ResIdxRange = Signature.GetResourceIndexRange(VarType);
- for (Uint32 r = ResIdxRange.first; r < ResIdxRange.second; ++r)
- {
- const auto& Res = Signature.GetResourceDesc(r);
- VERIFY_EXPR(Res.VarType == VarType);
-
- if ((Res.ShaderStages & ShaderType) == 0)
- continue;
-
- if (Res.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER)
- continue;
-
- Handler(r);
- }
- }
- }
-}
-
size_t ShaderVariableManagerGL::GetRequiredMemorySize(const PipelineResourceSignatureGLImpl& Signature,
const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
Uint32 NumAllowedTypes,
@@ -167,11 +137,13 @@ void ShaderVariableManagerGL::Initialize(const PipelineResourceSignatureGLImpl&
// Current resource index for every resource type
ResourceCounters VarCounters = {};
- ProcessSignatureResources(
- Signature, AllowedVarTypes, NumAllowedTypes, ShaderType,
- [&](Uint32 Index) //
+ Signature.ProcessResources(
+ AllowedVarTypes, NumAllowedTypes, ShaderType,
+ [&](const PipelineResourceDesc& ResDesc, Uint32 Index) //
{
- const auto& ResDesc = Signature.GetResourceDesc(Index);
+ if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER)
+ return;
+
static_assert(BINDING_RANGE_COUNT == 4, "Please update the switch below to handle the new shader resource range");
switch (PipelineResourceToBindingRange(ResDesc))
{
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp
index b5d0c687..b2980659 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp
@@ -115,13 +115,6 @@ private:
const PipelineResourceDesc& GetResourceDesc(Uint32 Index) const;
const ResourceAttribs& GetAttribs(Uint32 Index) const;
- template <typename HandlerType>
- static void ProcessSignatureResources(const PipelineResourceSignatureVkImpl& Signature,
- const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- SHADER_TYPE ShaderStages,
- HandlerType Handler);
-
private:
PipelineResourceSignatureVkImpl const* m_pSignature = nullptr;
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp
index 71d2811a..58b16b90 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp
@@ -35,40 +35,26 @@ namespace Diligent
{
template <typename HandlerType>
-void ShaderVariableManagerVk::ProcessSignatureResources(const PipelineResourceSignatureVkImpl& Signature,
- const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- SHADER_TYPE ShaderStages,
- HandlerType Handler)
+void ProcessSignatureResources(const PipelineResourceSignatureVkImpl& Signature,
+ const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
+ Uint32 NumAllowedTypes,
+ SHADER_TYPE ShaderStages,
+ HandlerType Handler)
{
- const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
- const bool UsingSeparateSamplers = Signature.IsUsingSeparateSamplers();
-
- for (Uint32 var_type = 0; var_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++var_type)
- {
- const auto VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(var_type);
- if (IsAllowedType(VarType, AllowedTypeBits))
- {
- const auto ResIdxRange = Signature.GetResourceIndexRange(VarType);
- for (Uint32 r = ResIdxRange.first; r < ResIdxRange.second; ++r)
- {
- const auto& Res = Signature.GetResourceDesc(r);
- const auto& Attr = Signature.GetResourceAttribs(r);
- VERIFY_EXPR(Res.VarType == VarType);
-
- if ((Res.ShaderStages & ShaderStages) == 0)
- continue;
-
- // When using HLSL-style combined image samplers, we need to skip separate samplers.
- // Also always skip immutable separate samplers.
- if (Res.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER &&
- (!UsingSeparateSamplers || Attr.IsImmutableSamplerAssigned()))
- continue;
-
- Handler(r);
- }
- }
- }
+ const bool UsingSeparateSamplers = Signature.IsUsingSeparateSamplers();
+ Signature.ProcessResources(AllowedVarTypes, NumAllowedTypes, ShaderStages,
+ [&](const PipelineResourceDesc& ResDesc, Uint32 Index) //
+ {
+ const auto& ResAttr = Signature.GetResourceAttribs(Index);
+
+ // When using HLSL-style combined image samplers, we need to skip separate samplers.
+ // Also always skip immutable separate samplers.
+ if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER &&
+ (!UsingSeparateSamplers || ResAttr.IsImmutableSamplerAssigned()))
+ return;
+
+ Handler(Index);
+ });
}
size_t ShaderVariableManagerVk::GetRequiredMemorySize(const PipelineResourceSignatureVkImpl& Signature,