From 629c20a0bc5cbae12056eb14261770bba09ac882 Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 21 Jan 2021 21:39:34 -0800 Subject: PipelineStateBase: added more resource signature parameter validation --- Graphics/GraphicsEngine/src/PipelineStateBase.cpp | 47 +++++++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp index e08a5a11..ea9ca7e1 100644 --- a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp +++ b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp @@ -160,32 +160,63 @@ void CorrectBlendStateDesc(GraphicsPipelineDesc& GraphicsPipeline) noexcept void ValidatePipelineResourceSignatures(const PipelineStateCreateInfo& CreateInfo) noexcept(false) { + const auto& PSODesc = CreateInfo.PSODesc; + + if (CreateInfo.ResourceSignaturesCount != 0 && CreateInfo.ppResourceSignatures == nullptr) + LOG_PSO_ERROR_AND_THROW("ppResourceSignatures is null, but ResourceSignaturesCount (", CreateInfo.ResourceSignaturesCount, ") is not zero."); + + if (CreateInfo.ppResourceSignatures != nullptr && CreateInfo.ResourceSignaturesCount == 0) + LOG_PSO_ERROR_AND_THROW("ppResourceSignatures is not null, but ResourceSignaturesCount is zero."); + if (CreateInfo.ppResourceSignatures == nullptr) return; - const auto& PSODesc = CreateInfo.PSODesc; + if (CreateInfo.PSODesc.ResourceLayout.NumVariables != 0) + { + LOG_PSO_ERROR_AND_THROW("The number of variables defined through resource layout (", CreateInfo.PSODesc.ResourceLayout.NumVariables, + ") must be zero when resource signatures are used."); + } + + if (CreateInfo.PSODesc.ResourceLayout.NumImmutableSamplers != 0) + { + LOG_PSO_ERROR_AND_THROW("The number of immutable samplers defined through resource layout (", CreateInfo.PSODesc.ResourceLayout.NumImmutableSamplers, + ") must be zero when resource signatures are used."); + } + + std::unordered_map AllResources; std::array ppSignatures = {}; for (Uint32 i = 0; i < CreateInfo.ResourceSignaturesCount; ++i) { - auto* pSignature = CreateInfo.ppResourceSignatures[i]; + const auto* const pSignature = CreateInfo.ppResourceSignatures[i]; if (pSignature == nullptr) LOG_PSO_ERROR_AND_THROW("Pipeline resource signature at index ", i, " is null"); - const auto& SigDesc = pSignature->GetDesc(); - VERIFY(SigDesc.BindingIndex < MAX_RESOURCE_SIGNATURES, + const auto& SignDesc = pSignature->GetDesc(); + VERIFY(SignDesc.BindingIndex < MAX_RESOURCE_SIGNATURES, "Resource signature binding index exceeds the limit. This error should've been caught by ValidatePipelineResourceSignatureDesc."); - if (ppSignatures[SigDesc.BindingIndex] != nullptr) + if (ppSignatures[SignDesc.BindingIndex] != nullptr) { - LOG_PSO_ERROR_AND_THROW("Pipeline resource signature '", pSignature->GetDesc().Name, "' at binding index ", Uint32{SigDesc.BindingIndex}, - " conflicts with another resource signature '", ppSignatures[SigDesc.BindingIndex]->GetDesc().Name, + LOG_PSO_ERROR_AND_THROW("Pipeline resource signature '", pSignature->GetDesc().Name, "' at binding index ", Uint32{SignDesc.BindingIndex}, + " conflicts with another resource signature '", ppSignatures[SignDesc.BindingIndex]->GetDesc().Name, "' that uses the same index."); } + + 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) + { + 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."); + } + } } } - } // namespace #define VALIDATE_SHADER_TYPE(Shader, ExpectedType, ShaderName) \ -- cgit v1.2.3