From a615dcf84ce573e784e56a50bc8c2809f69c7ea7 Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 9 Mar 2021 16:37:37 -0800 Subject: Moved ProcessSignatureResources method to PipelineResourceSignatureBase --- .../include/ShaderVariableManagerGL.hpp | 66 +++++++--------------- .../src/ShaderVariableManagerGL.cpp | 54 +++++------------- 2 files changed, 33 insertions(+), 87 deletions(-) (limited to 'Graphics/GraphicsEngineOpenGL') 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 @@ -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 - 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 -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(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)) { -- cgit v1.2.3