diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-02-16 03:06:56 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:31:38 +0000 |
| commit | 7a148ffcd6569ad21dc112c1823feb7b7477cb10 (patch) | |
| tree | 0627fc491cf9a8f4424c74d67aa1fb1053d16b17 /Graphics | |
| parent | optimize root view updates (diff) | |
| download | DiligentCore-7a148ffcd6569ad21dc112c1823feb7b7477cb10.tar.gz DiligentCore-7a148ffcd6569ad21dc112c1823feb7b7477cb10.zip | |
Removed duplicates of FindAssignedSampler and FindImmutableSampler functions
Diffstat (limited to 'Graphics')
8 files changed, 71 insertions, 85 deletions
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 <typename BufferImplType> 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 diff --git a/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp index c747dda2..386aeb84 100644 --- a/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp @@ -289,8 +289,6 @@ private: std::vector<Uint32, STDAllocatorRawMem<Uint32>> GetCacheTableSizes() const; - Uint32 FindAssignedSampler(const PipelineResourceDesc& SepImg) const; - private: ResourceAttribs* m_pResourceAttribs = nullptr; // [m_Desc.NumResources] diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp index 243cf9c0..6a1adb64 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp @@ -193,7 +193,7 @@ void PipelineResourceSignatureD3D12Impl::CreateLayout() // Index of the assigned sampler, for every texture SRV in m_Desc.Resources, or InvalidSamplerInd. std::vector<Uint32> TextureSrvToAssignedSamplerInd(m_Desc.NumResources, ResourceAttribs::InvalidSamplerInd); // Index of the immutable sampler for every sampler in m_Desc.Resources, or -1. - std::vector<int> ResourceToImmutableSamplerInd(m_Desc.NumResources, -1); + std::vector<Int32> ResourceToImmutableSamplerInd(m_Desc.NumResources, -1); for (Uint32 i = 0; i < m_Desc.NumResources; ++i) { const auto& ResDesc = m_Desc.Resources[i]; @@ -222,7 +222,7 @@ void PipelineResourceSignatureD3D12Impl::CreateLayout() if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV) { - TextureSrvToAssignedSamplerInd[i] = FindAssignedSampler(ResDesc); + TextureSrvToAssignedSamplerInd[i] = FindAssignedSampler(ResDesc, ResourceAttribs::InvalidSamplerInd); } } @@ -367,32 +367,6 @@ void PipelineResourceSignatureD3D12Impl::CreateLayout() } } -Uint32 PipelineResourceSignatureD3D12Impl::FindAssignedSampler(const PipelineResourceDesc& SepImg) const -{ - Uint32 SamplerInd = ResourceAttribs::InvalidSamplerInd; - if (IsUsingCombinedSamplers()) - { - const auto IdxRange = GetResourceIndexRange(SepImg.VarType); - - for (Uint32 i = IdxRange.first; i < IdxRange.second; ++i) - { - const auto& Res = m_Desc.Resources[i]; - VERIFY_EXPR(SepImg.VarType == Res.VarType); - - if (Res.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && - (SepImg.ShaderStages & Res.ShaderStages) && - StreqSuff(Res.Name, SepImg.Name, GetCombinedSamplerSuffix())) - { - VERIFY_EXPR((Res.ShaderStages & SepImg.ShaderStages) == SepImg.ShaderStages); - SamplerInd = i; - break; - } - } - } - return SamplerInd; -} - - PipelineResourceSignatureD3D12Impl::~PipelineResourceSignatureD3D12Impl() { Destruct(); diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index 908965f8..a4c8769c 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -692,7 +692,9 @@ void PipelineStateD3D12Impl::InitRootSignature(const PipelineStateCreateInfo& Cr if (m_RootSig->GetTotalSpaces() > 1 && !IsSM51orAbove) { - LOG_ERROR_AND_THROW("Shader '", pShader->GetDesc().Name, "' compiled with shader model 5.0 or below that is not compatible with register spaces that is used in DirectX 12."); + LOG_ERROR_AND_THROW("Shader '", pShader->GetDesc().Name, + "' is compiled using SM5.0 or below that only supports single register space. " + "Compile the shader using SM5.1+ or change the resource layout to use only one space."); } if (IsDXILBytecode(pBytecode->GetBufferPointer(), pBytecode->GetBufferSize())) diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp index ea20151b..4236f7c1 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp @@ -316,9 +316,6 @@ private: size_t CalculateHash() const; - // Finds a separate sampler assigned to the image SepImg and returns its index in m_Desc.Resources. - Uint32 FindAssignedSampler(const PipelineResourceDesc& SepImg) const; - static inline CACHE_GROUP GetResourceCacheGroup(const PipelineResourceDesc& Res); static inline DESCRIPTOR_SET_ID VarTypeToDescriptorSetId(SHADER_RESOURCE_VARIABLE_TYPE VarType); diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp index 000d3458..a4928130 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp @@ -468,7 +468,7 @@ void PipelineResourceSignatureVkImpl::CreateSetLayouts(const CacheOffsetsType& C // The sampler may not be yet initialized, but this is OK as all resources are initialized // in the same order as in m_Desc.Resources const auto AssignedSamplerInd = DescrType == DescriptorType::SeparateImage ? - FindAssignedSampler(ResDesc) : + FindAssignedSampler(ResDesc, ResourceAttribs::InvalidSamplerInd) : ResourceAttribs::InvalidSamplerInd; VkSampler* pVkImmutableSamplers = nullptr; @@ -478,7 +478,7 @@ void PipelineResourceSignatureVkImpl::CreateSetLayouts(const CacheOffsetsType& C // Only search for immutable sampler for combined image samplers and separate samplers. // Note that for DescriptorType::SeparateImage with immutable sampler, we will initialize // a separate immutable sampler below. It will not be assigned to the image variable. - Int32 SrcImmutableSamplerInd = FindImmutableSampler(ResDesc, DescrType, m_Desc, GetCombinedSamplerSuffix()); + const auto SrcImmutableSamplerInd = FindImmutableSampler(ResDesc, DescrType, m_Desc, GetCombinedSamplerSuffix()); if (SrcImmutableSamplerInd >= 0) { auto& ImmutableSampler = m_ImmutableSamplers[SrcImmutableSamplerInd]; @@ -654,31 +654,6 @@ void PipelineResourceSignatureVkImpl::CreateSetLayouts(const CacheOffsetsType& C VERIFY_EXPR(NumSets == GetNumDescriptorSets()); } -Uint32 PipelineResourceSignatureVkImpl::FindAssignedSampler(const PipelineResourceDesc& SepImg) const -{ - Uint32 SamplerInd = ResourceAttribs::InvalidSamplerInd; - if (IsUsingCombinedSamplers()) - { - const auto IdxRange = GetResourceIndexRange(SepImg.VarType); - - for (Uint32 i = IdxRange.first; i < IdxRange.second; ++i) - { - const auto& Res = m_Desc.Resources[i]; - VERIFY_EXPR(SepImg.VarType == Res.VarType); - - if (Res.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && - (SepImg.ShaderStages & Res.ShaderStages) && - StreqSuff(Res.Name, SepImg.Name, GetCombinedSamplerSuffix())) - { - VERIFY_EXPR((Res.ShaderStages & SepImg.ShaderStages) == SepImg.ShaderStages); - SamplerInd = i; - break; - } - } - } - return SamplerInd; -} - size_t PipelineResourceSignatureVkImpl::CalculateHash() const { if (m_Desc.NumResources == 0 && m_Desc.NumImmutableSamplers == 0) |
