diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-01-25 06:06:01 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-01-25 06:06:01 +0000 |
| commit | 6abf2a9082f55588671351db1c38851a2bcde25f (patch) | |
| tree | 718360aeb031f89999ce6d8aa3bcf61ea4d18901 /Graphics/GraphicsEngine | |
| parent | Few updates to resource signature VK implementation (diff) | |
| download | DiligentCore-6abf2a9082f55588671351db1c38851a2bcde25f.tar.gz DiligentCore-6abf2a9082f55588671351db1c38851a2bcde25f.zip | |
Added first couple of pipeline resource signature tests
Diffstat (limited to 'Graphics/GraphicsEngine')
7 files changed, 72 insertions, 29 deletions
diff --git a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp index 0e14162a..62c534c5 100644 --- a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp +++ b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp @@ -29,6 +29,7 @@ /// \file /// Implementation of the Diligent::PipelineResourceSignatureBase template class + #include <array> #include <limits> #include <algorithm> @@ -141,6 +142,7 @@ protected: ++m_ResourceOffsets[Dst.VarType + 1]; } + // Sort resources by variable type std::sort(pResources, pResources + Desc.NumResources, [](const PipelineResourceDesc& lhs, const PipelineResourceDesc& rhs) { return lhs.VarType < rhs.VarType; @@ -149,7 +151,15 @@ protected: for (size_t i = 1; i < m_ResourceOffsets.size(); ++i) m_ResourceOffsets[i] += m_ResourceOffsets[i - 1]; +#ifdef DILIGENT_DEBUG VERIFY_EXPR(m_ResourceOffsets[SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES] == Desc.NumResources); + for (Uint32 VarType = 0; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++VarType) + { + auto IdxRange = GetResourceIndexRange(static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType)); + for (Uint32 idx = IdxRange.first; idx < IdxRange.second; ++idx) + VERIFY(pResources[idx].VarType == VarType, "Unexpected resource var type"); + } +#endif for (Uint32 i = 0; i < Desc.NumImmutableSamplers; ++i) { diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp index 4f95bae8..2c4a0729 100644 --- a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp +++ b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp @@ -240,7 +240,11 @@ public: *ppShaderResourceBinding = nullptr; if (this->GetResourceSignatureCount() != 1) + { + LOG_ERROR_MESSAGE("PipelineState::CreateShaderResourceBinding is only allowed for pipelines that use a single " + "resource signature. Use IPipelineResourceSignature::CreateShaderResourceBinding instead."); return; + } return this->GetResourceSignature(0)->CreateShaderResourceBinding(ppShaderResourceBinding, InitStaticResources); } @@ -249,7 +253,11 @@ public: const Char* Name) override final { if (this->GetResourceSignatureCount() != 1) + { + LOG_ERROR_MESSAGE("PipelineState::CreateShaderResourceBinding is only allowed for pipelines that use a single " + "resource signature. Use IPipelineResourceSignature::GetStaticVariableByName instead."); return nullptr; + } return this->GetResourceSignature(0)->GetStaticVariableByName(ShaderType, Name); } @@ -258,7 +266,11 @@ public: Uint32 Index) override final { if (this->GetResourceSignatureCount() != 1) + { + LOG_ERROR_MESSAGE("PipelineState::GetStaticVariableByIndex is only allowed for pipelines that use a single " + "resource signature. Use IPipelineResourceSignature::GetStaticVariableByIndex instead."); return nullptr; + } return this->GetResourceSignature(0)->GetStaticVariableByIndex(ShaderType, Index); } @@ -266,7 +278,11 @@ public: virtual Uint32 DILIGENT_CALL_TYPE GetStaticVariableCount(SHADER_TYPE ShaderType) const override final { if (this->GetResourceSignatureCount() != 1) + { + LOG_ERROR_MESSAGE("PipelineState::GetStaticVariableCount is only allowed for pipelines that use a single " + "resource signature. Use IPipelineResourceSignature::GetStaticVariableCount instead."); return 0; + } return this->GetResourceSignature(0)->GetStaticVariableCount(ShaderType); } @@ -274,7 +290,11 @@ public: virtual void DILIGENT_CALL_TYPE BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags) override final { if (this->GetResourceSignatureCount() != 1) + { + LOG_ERROR_MESSAGE("PipelineState::BindStaticResources is only allowed for pipelines that use a single " + "resource signature. Use IPipelineResourceSignature::BindStaticResources instead."); return; + } return this->GetResourceSignature(0)->BindStaticResources(ShaderFlags, pResourceMapping, Flags); } diff --git a/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h b/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h index 414add12..84074250 100644 --- a/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h +++ b/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h @@ -139,10 +139,10 @@ struct PipelineResourceDesc #if DILIGENT_CPP_INTERFACE PipelineResourceDesc()noexcept{} - PipelineResourceDesc(const char* _Name, + PipelineResourceDesc(SHADER_TYPE _ShaderStages, + const char* _Name, Uint32 _ArraySize, SHADER_RESOURCE_TYPE _ResourceType, - SHADER_TYPE _ShaderStages, SHADER_RESOURCE_VARIABLE_TYPE _VarType, PIPELINE_RESOURCE_FLAGS _Flags = PIPELINE_RESOURCE_FLAG_UNKNOWN)noexcept : Name {_Name }, diff --git a/Graphics/GraphicsEngine/interface/RenderDevice.h b/Graphics/GraphicsEngine/interface/RenderDevice.h index b9fba033..1c4e0493 100644 --- a/Graphics/GraphicsEngine/interface/RenderDevice.h +++ b/Graphics/GraphicsEngine/interface/RenderDevice.h @@ -82,7 +82,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// Immutable buffers (USAGE_IMMUTABLE) must be initialized at creation time. /// \param [out] ppBuffer - Address of the memory location where the pointer to the /// buffer interface will be stored. The function calls AddRef(), - /// so that the new buffer will contain one reference and must be + /// so that the new buffer will have one reference and must be /// released by a call to Release(). /// /// \remarks @@ -99,7 +99,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// \param [in] ShaderCI - Shader create info, see Diligent::ShaderCreateInfo for details. /// \param [out] ppShader - Address of the memory location where the pointer to the /// shader interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. VIRTUAL void METHOD(CreateShader)(THIS_ const ShaderCreateInfo REF ShaderCI, @@ -114,7 +114,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// /// \param [out] ppTexture - Address of the memory location where the pointer to the /// texture interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. /// \remarks /// To create all mip levels, set the TexDesc.MipLevels to zero.\n @@ -137,7 +137,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// \param [in] SamDesc - Sampler description, see Diligent::SamplerDesc for details. /// \param [out] ppSampler - Address of the memory location where the pointer to the /// sampler interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. /// \remark If an application attempts to create a sampler interface with the same attributes /// as an existing interface, the same interface will be returned. @@ -151,7 +151,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// \param [in] MappingDesc - Resource mapping description, see Diligent::ResourceMappingDesc for details. /// \param [out] ppMapping - Address of the memory location where the pointer to the /// resource mapping interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. VIRTUAL void METHOD(CreateResourceMapping)(THIS_ const ResourceMappingDesc REF MappingDesc, @@ -162,7 +162,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// \param [in] PSOCreateInfo - Graphics pipeline state create info, see Diligent::GraphicsPipelineStateCreateInfo for details. /// \param [out] ppPipelineState - Address of the memory location where the pointer to the /// pipeline state interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. VIRTUAL void METHOD(CreateGraphicsPipelineState)(THIS_ const GraphicsPipelineStateCreateInfo REF PSOCreateInfo, @@ -173,7 +173,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// \param [in] PSOCreateInfo - Compute pipeline state create info, see Diligent::ComputePipelineStateCreateInfo for details. /// \param [out] ppPipelineState - Address of the memory location where the pointer to the /// pipeline state interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. VIRTUAL void METHOD(CreateComputePipelineState)(THIS_ const ComputePipelineStateCreateInfo REF PSOCreateInfo, @@ -184,7 +184,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// \param [in] PSOCreateInfo - Ray tracing pipeline state create info, see Diligent::RayTracingPipelineStateCreateInfo for details. /// \param [out] ppPipelineState - Address of the memory location where the pointer to the /// pipeline state interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. VIRTUAL void METHOD(CreateRayTracingPipelineState)(THIS_ const RayTracingPipelineStateCreateInfo REF PSOCreateInfo, @@ -195,7 +195,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// \param [in] Desc - Fence description, see Diligent::FenceDesc for details. /// \param [out] ppFence - Address of the memory location where the pointer to the /// fence interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. VIRTUAL void METHOD(CreateFence)(THIS_ const FenceDesc REF Desc, @@ -207,7 +207,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// \param [in] Desc - Query description, see Diligent::QueryDesc for details. /// \param [out] ppQuery - Address of the memory location where the pointer to the /// query interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. VIRTUAL void METHOD(CreateQuery)(THIS_ const QueryDesc REF Desc, @@ -219,7 +219,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// \param [in] Desc - Render pass description, see Diligent::RenderPassDesc for details. /// \param [out] ppRenderPass - Address of the memory location where the pointer to the /// render pass interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. VIRTUAL void METHOD(CreateRenderPass)(THIS_ const RenderPassDesc REF Desc, @@ -232,7 +232,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// \param [in] Desc - Framebuffer description, see Diligent::FramebufferDesc for details. /// \param [out] ppFramebuffer - Address of the memory location where the pointer to the /// framebuffer interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. VIRTUAL void METHOD(CreateFramebuffer)(THIS_ const FramebufferDesc REF Desc, @@ -244,7 +244,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// \param [in] Desc - BLAS description, see Diligent::BottomLevelASDesc for details. /// \param [out] ppBLAS - Address of the memory location where the pointer to the /// BLAS interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. VIRTUAL void METHOD(CreateBLAS)(THIS_ const BottomLevelASDesc REF Desc, @@ -256,7 +256,7 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// \param [in] Desc - TLAS description, see Diligent::TopLevelASDesc for details. /// \param [out] ppTLAS - Address of the memory location where the pointer to the /// TLAS interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. VIRTUAL void METHOD(CreateTLAS)(THIS_ const TopLevelASDesc REF Desc, @@ -268,13 +268,19 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// \param [in] Desc - SBT description, see Diligent::ShaderBindingTableDesc for details. /// \param [out] ppSBT - Address of the memory location where the pointer to the /// SBT interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// The function calls AddRef(), so that the new object will have /// one reference. VIRTUAL void METHOD(CreateSBT)(THIS_ const ShaderBindingTableDesc REF Desc, IShaderBindingTable** ppSBT) PURE; - /// AZ TODO: comment + /// Creates a pipeline resource signature object. + + /// \param [in] Desc - Resource signature description, see Diligent::PipelineResourceSignatureDesc for details. + /// \param [out] ppSignature - Address of the memory location where the pointer to the + /// pipeline resource signature interface will be stored. + /// The function calls AddRef(), so that the new object will have + /// one reference. VIRTUAL void METHOD(CreatePipelineResourceSignature)(THIS_ const PipelineResourceSignatureDesc REF Desc, IPipelineResourceSignature** ppSignature) PURE; diff --git a/Graphics/GraphicsEngine/interface/Shader.h b/Graphics/GraphicsEngine/interface/Shader.h index de267e14..e7694ca4 100644 --- a/Graphics/GraphicsEngine/interface/Shader.h +++ b/Graphics/GraphicsEngine/interface/Shader.h @@ -285,7 +285,7 @@ struct ShaderCreateInfo /// the sampler assigned to the shader resource view is automatically set when /// the view is bound. Otherwise samplers need to be explicitly set similar to other /// shader variables. - /// Has no effect if used pipeline resource signature. + /// This member has no effect if the shader is used in the PSO that uses pipeline resource signature(s). bool UseCombinedTextureSamplers DEFAULT_INITIALIZER(false); /// If UseCombinedTextureSamplers is true, defines the suffix added to the @@ -293,7 +293,7 @@ struct ShaderCreateInfo /// for default value "_sampler", a texture named "tex" will be combined /// with sampler named "tex_sampler". /// If UseCombinedTextureSamplers is false, this member is ignored. - /// Has no effect if used pipeline resource signature. + /// This member has no effect if the shader is used in the PSO that uses pipeline resource signature(s). const Char* CombinedSamplerSuffix DEFAULT_INITIALIZER("_sampler"); /// Shader description. See Diligent::ShaderDesc. diff --git a/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp b/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp index 9e51a93f..167296c5 100644 --- a/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp +++ b/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp @@ -39,7 +39,7 @@ namespace Diligent void ValidatePipelineResourceSignatureDesc(const PipelineResourceSignatureDesc& Desc) noexcept(false) { if (Desc.BindingIndex >= MAX_RESOURCE_SIGNATURES) - LOG_PRS_ERROR_AND_THROW("Desc.BindingIndex (", Desc.BindingIndex, ") exceeds the maximum allowed value (", MAX_RESOURCE_SIGNATURES - 1, ")."); + LOG_PRS_ERROR_AND_THROW("Desc.BindingIndex (", Uint32{Desc.BindingIndex}, ") exceeds the maximum allowed value (", MAX_RESOURCE_SIGNATURES - 1, ")."); std::unordered_map<HashMapStringKey, SHADER_TYPE, HashMapStringKey::Hasher> ResourceShaderStages; @@ -69,16 +69,16 @@ void ValidatePipelineResourceSignatureDesc(const PipelineResourceSignatureDesc& (Res.ResourceType != SHADER_RESOURCE_TYPE_CONSTANT_BUFFER && Res.ResourceType != SHADER_RESOURCE_TYPE_BUFFER_UAV && Res.ResourceType != SHADER_RESOURCE_TYPE_TEXTURE_SRV)) - LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].Flags must not contains PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS if ResourceType is not buffer"); + LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].Flags must not contain PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS if ResourceType is not buffer"); if ((Res.Flags & PIPELINE_RESOURCE_FLAG_COMBINED_IMAGE) && Res.ResourceType != SHADER_RESOURCE_TYPE_TEXTURE_SRV) - LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].Flags must not contains PIPELINE_RESOURCE_FLAG_COMBINED_IMAGE if ResourceType is not SHADER_RESOURCE_TYPE_TEXTURE_SRV"); + LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].Flags must not contain PIPELINE_RESOURCE_FLAG_COMBINED_IMAGE if ResourceType is not SHADER_RESOURCE_TYPE_TEXTURE_SRV"); if ((Res.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) && (Res.ResourceType != SHADER_RESOURCE_TYPE_BUFFER_UAV && Res.ResourceType != SHADER_RESOURCE_TYPE_BUFFER_SRV)) - LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].Flags must not contains PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER if ResourceType is not buffer"); + LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].Flags must not contain PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER if ResourceType is not buffer"); } for (Uint32 i = 0; i < Desc.NumImmutableSamplers; ++i) diff --git a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp index 4f36ee6f..5cdf60f1 100644 --- a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp +++ b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp @@ -30,6 +30,7 @@ #include <unordered_set> #include <unordered_map> #include <array> +#include <vector> #include "HashUtils.hpp" @@ -188,7 +189,8 @@ void ValidatePipelineResourceSignatures(const PipelineStateCreateInfo& CreateInf ") must be zero when resource signatures are used."); } - std::unordered_map<HashMapStringKey, const IPipelineResourceSignature*, HashMapStringKey::Hasher> AllResources; + + std::unordered_map<HashMapStringKey, std::vector<std::pair<SHADER_TYPE, const IPipelineResourceSignature*>>, HashMapStringKey::Hasher> AllResources; std::array<const IPipelineResourceSignature*, MAX_RESOURCE_SIGNATURES> ppSignatures = {}; for (Uint32 i = 0; i < CreateInfo.ResourceSignaturesCount; ++i) @@ -207,17 +209,22 @@ void ValidatePipelineResourceSignatures(const PipelineStateCreateInfo& CreateInf " conflicts with another resource signature '", ppSignatures[SignDesc.BindingIndex]->GetDesc().Name, "' that uses the same index."); } + ppSignatures[SignDesc.BindingIndex] = pSignature; for (Uint32 res = 0; res < SignDesc.NumResources; ++res) { const auto& ResDesc = SignDesc.Resources[res]; - auto insert_res = AllResources.emplace(ResDesc.Name, pSignature); - if (!insert_res.second) + auto& StageSignatures = AllResources[ResDesc.Name]; + for (auto& StageSig : StageSignatures) { - LOG_PSO_ERROR_AND_THROW("Shader resource '", ResDesc.Name, "' is found in more than one resource signature ('", SignDesc.Name, - "' and '", insert_res.first->second->GetDesc().Name, "'). Every shader resource in PSO must be unambiguously defined by only resource signature."); + if ((StageSig.first & ResDesc.ShaderStages) != 0) + { + LOG_PSO_ERROR_AND_THROW("Shader resource '", ResDesc.Name, "' is found in more than one resource signature in the same stage ('", SignDesc.Name, + "' and '", StageSig.second->GetDesc().Name, "'). Every shader resource in PSO must be unambiguously defined by only one resource signature."); + } } + StageSignatures.emplace_back(ResDesc.ShaderStages, pSignature); } } } |
