diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-03-03 03:10:09 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:38:14 +0000 |
| commit | 0606e960bdb3895ce5effba8128b1c4b372a1ba0 (patch) | |
| tree | 3b15c0612c536bcdda6752b34d8bc71bd21764c7 /Graphics/GraphicsEngine | |
| parent | Removed mutable fields from ResourceBindingMap (diff) | |
| download | DiligentCore-0606e960bdb3895ce5effba8128b1c4b372a1ba0.tar.gz DiligentCore-0606e960bdb3895ce5effba8128b1c4b372a1ba0.zip | |
Unified pipeline resource compatibility validation in D3D12 and Vk; added more PRS creation failure tests
Diffstat (limited to 'Graphics/GraphicsEngine')
| -rw-r--r-- | Graphics/GraphicsEngine/include/PipelineStateBase.hpp | 10 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/src/PipelineStateBase.cpp | 54 |
2 files changed, 64 insertions, 0 deletions
diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp index 5d1e65e9..573dca44 100644 --- a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp +++ b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp @@ -51,6 +51,16 @@ void ValidateGraphicsPipelineCreateInfo(const GraphicsPipelineStateCreateInfo& C void ValidateComputePipelineCreateInfo(const ComputePipelineStateCreateInfo& CreateInfo) noexcept(false); void ValidateRayTracingPipelineCreateInfo(IRenderDevice* pDevice, Uint32 MaxRecursion, const RayTracingPipelineStateCreateInfo& CreateInfo) noexcept(false); +/// Validates that pipeline resource description 'ResDesc' is compatible with the actual resource +/// attributes and throws an exception in case of an error. +void ValidatePipelineResourceCompatibility(const PipelineResourceDesc& ResDesc, + SHADER_RESOURCE_TYPE Type, + PIPELINE_RESOURCE_FLAGS ResourceFlags, + Uint32 ArraySize, + const char* ShaderName, + const char* SignatureName) noexcept(false); + + /// Copies ray tracing shader group names and also initializes the mapping from the group name to its index. void CopyRTShaderGroupNames(std::unordered_map<HashMapStringKey, Uint32, HashMapStringKey::Hasher>& NameToGroupIndex, const RayTracingPipelineStateCreateInfo& CreateInfo, diff --git a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp index c1a314a6..4c095669 100644 --- a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp +++ b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp @@ -514,6 +514,60 @@ void CopyRTShaderGroupNames(std::unordered_map<HashMapStringKey, Uint32, HashMap #undef VALIDATE_SHADER_TYPE #undef LOG_PSO_ERROR_AND_THROW +void ValidatePipelineResourceCompatibility(const PipelineResourceDesc& ResDesc, + SHADER_RESOURCE_TYPE Type, + PIPELINE_RESOURCE_FLAGS ResourceFlags, + Uint32 ArraySize, + const char* ShaderName, + const char* SignatureName) noexcept(false) +{ + if (Type != ResDesc.ResourceType) + { + LOG_ERROR_AND_THROW("Shader '", ShaderName, "' contains resource with name '", ResDesc.Name, + "' and type '", GetShaderResourceTypeLiteralName(Type), "' that is not compatible with type '", + GetShaderResourceTypeLiteralName(ResDesc.ResourceType), "' specified in pipeline resource signature '", SignatureName, "'."); + } + + if ((ResourceFlags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) != (ResDesc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER)) + { + LOG_ERROR_AND_THROW("Shader '", ShaderName, "' contains resource '", ResDesc.Name, + "' that is", ((ResourceFlags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) ? "" : " not"), + " labeled as formatted buffer, while the same resource specified by the pipeline resource signature '", + SignatureName, "' is", ((ResDesc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) ? "" : " not"), + " labeled as such."); + } + + VERIFY(ResDesc.ArraySize > 0, "ResDesc.ArraySize can't be zero. This error should've be caught by ValidatePipelineResourceSignatureDesc()."); + + if (ArraySize == 0) + { + // ArraySize == 0 means that the resource is a runtime-sized array and ResDesc.ArraySize from the + // resource signature may have any non-zero value. + if ((ResDesc.Flags & PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY) == 0) + { + LOG_ERROR_AND_THROW("Shader '", ShaderName, "' contains resource '", ResDesc.Name, + "' that is a runtime-sized array, but in the resource signature '", SignatureName, + "' the resource is defined without the PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY flag."); + } + } + else + { + if (ResDesc.ArraySize < ArraySize) + { + LOG_ERROR_AND_THROW("Shader '", ShaderName, "' contains resource '", ResDesc.Name, + "' whose array size (", ArraySize, ") is greater than the array size (", + ResDesc.ArraySize, ") specified by the pipeline resource signature '", SignatureName, "'."); + } + + //if (ResDesc.Flags & PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY) + //{ + // LOG_WARNING_MESSAGE("Shader '", ShaderName, "' contains resource with name '", ResDesc.Name, + // "' that is defined in resource signature '", SignatureName, + // "' with flag PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY, but the resource is not a runtime-sized array."); + //} + } +} + void CorrectGraphicsPipelineDesc(GraphicsPipelineDesc& GraphicsPipeline) noexcept { CorrectBlendStateDesc(GraphicsPipeline); |
