From 7a148ffcd6569ad21dc112c1823feb7b7477cb10 Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 15 Feb 2021 19:06:56 -0800 Subject: Removed duplicates of FindAssignedSampler and FindImmutableSampler functions --- .../include/PipelineResourceSignatureBase.hpp | 40 ++++++++++++++++++++++ .../include/ShaderResourceVariableBase.hpp | 24 ------------- .../src/PipelineResourceSignatureBase.cpp | 24 +++++++++++++ 3 files changed, 64 insertions(+), 24 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp index e76f38fc..8b6b5a34 100644 --- a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp +++ b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp @@ -40,12 +40,23 @@ #include "RenderDeviceBase.hpp" #include "FixedLinearAllocator.hpp" #include "BasicMath.hpp" +#include "StringTools.hpp" namespace Diligent { +/// Validates pipeline resource signature description and throws an exception in case of an error. void ValidatePipelineResourceSignatureDesc(const PipelineResourceSignatureDesc& Desc) noexcept(false); +/// Finds an immutable sampler for the resource name 'ResourceName' that is defined in shader stages 'ShaderStages'. +/// If 'SamplerSuffix' is not null, it will be appended to the 'ResourceName'. +/// Returns an index of the sampler in ImtblSamplers array, or -1 if there is no suitable sampler. +Int32 FindImmutableSampler(const ImmutableSamplerDesc* ImtblSamplers, + Uint32 NumImtblSamplers, + SHADER_TYPE ShaderStages, + const char* ResourceName, + const char* SamplerSuffix); + /// Template class implementing base functionality of the pipeline resource signature object. /// \tparam BaseInterface - Base interface that this class will inheret @@ -276,6 +287,35 @@ protected: return VarMngrInd; } + // Finds a sampler that is assigned to texture Tex, when combined texture samplers are used. + // Returns an index of the sampler in m_Desc.Resources array, or InvalidSamplerValue if there is + // no such sampler, or if combined samplers are not used. + Uint32 FindAssignedSampler(const PipelineResourceDesc& Tex, Uint32 InvalidSamplerValue) const + { + VERIFY_EXPR(Tex.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV); + Uint32 SamplerInd = InvalidSamplerValue; + if (IsUsingCombinedSamplers()) + { + const auto IdxRange = GetResourceIndexRange(Tex.VarType); + + for (Uint32 i = IdxRange.first; i < IdxRange.second; ++i) + { + const auto& Res = m_Desc.Resources[i]; + VERIFY_EXPR(Tex.VarType == Res.VarType); + + if (Res.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && + (Tex.ShaderStages & Res.ShaderStages) != 0 && + StreqSuff(Res.Name, Tex.Name, GetCombinedSamplerSuffix())) + { + VERIFY_EXPR((Res.ShaderStages & Tex.ShaderStages) == Tex.ShaderStages); + SamplerInd = i; + break; + } + } + } + return SamplerInd; + } + protected: size_t m_Hash = 0; diff --git a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp index eada5264..edd850d1 100644 --- a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp +++ b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp @@ -120,30 +120,6 @@ inline Uint32 GetAllowedTypeBits(const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVar return AllowedTypeBits; } -inline Int32 FindImmutableSampler(const ImmutableSamplerDesc* ImtblSamplers, - Uint32 NumImtblSamplers, - SHADER_TYPE ShaderStages, - const char* ResourceName, - const char* SamplerSuffix) -{ - for (Uint32 s = 0; s < NumImtblSamplers; ++s) - { - const auto& Sam = ImtblSamplers[s]; - if (((Sam.ShaderStages & ShaderStages) != 0) && StreqSuff(ResourceName, Sam.SamplerOrTextureName, SamplerSuffix)) - { - DEV_CHECK_ERR((Sam.ShaderStages & ShaderStages) == ShaderStages, - "Resource '", ResourceName, "' is defined for the following shader stages: ", GetShaderStagesString(ShaderStages), - ", but immutable sampler '", Sam.SamplerOrTextureName, "' specifes only some of these stages: ", GetShaderStagesString(Sam.ShaderStages), - ". A resource that is present in multiple shader stages can't use different immutable samples in different stages. " - "Either use separate resources for different stages, or define the immutable sample for all stages that the resource uses."); - return s; - } - } - - return -1; -} - - template bool VerifyConstantBufferBinding(const char* ResName, Uint32 ArraySize, diff --git a/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp b/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp index 2c2abbe3..cd7e048c 100644 --- a/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp +++ b/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp @@ -222,4 +222,28 @@ void ValidatePipelineResourceSignatureDesc(const PipelineResourceSignatureDesc& #undef LOG_PRS_ERROR_AND_THROW +Int32 FindImmutableSampler(const ImmutableSamplerDesc* ImtblSamplers, + Uint32 NumImtblSamplers, + SHADER_TYPE ShaderStages, + const char* ResourceName, + const char* SamplerSuffix) +{ + for (Uint32 s = 0; s < NumImtblSamplers; ++s) + { + const auto& Sam = ImtblSamplers[s]; + if (((Sam.ShaderStages & ShaderStages) != 0) && StreqSuff(ResourceName, Sam.SamplerOrTextureName, SamplerSuffix)) + { + DEV_CHECK_ERR((Sam.ShaderStages & ShaderStages) == ShaderStages, + "Resource '", ResourceName, "' is defined for the following shader stages: ", GetShaderStagesString(ShaderStages), + ", but immutable sampler '", Sam.SamplerOrTextureName, "' specifes only some of these stages: ", GetShaderStagesString(Sam.ShaderStages), + ". A resource that is present in multiple shader stages can't use different immutable samples in different stages. " + "Either use separate resources for different stages, or define the immutable sample for all stages that the resource uses."); + return s; + } + } + + return -1; +} + + } // namespace Diligent -- cgit v1.2.3