From 76a183bf0780c70191de2fca31526280e78211e9 Mon Sep 17 00:00:00 2001 From: assiduous Date: Wed, 23 Dec 2020 09:26:16 -0800 Subject: Few minor improvements to RT pipeline initialization --- .../GraphicsEngine/include/PipelineStateBase.hpp | 24 ++++++++++++++-------- Graphics/GraphicsEngine/src/PipelineStateBase.cpp | 8 ++++---- 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp index 2c46f314..79033337 100644 --- a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp +++ b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp @@ -51,9 +51,9 @@ void ValidateComputePipelineCreateInfo(const ComputePipelineStateCreateInfo& Cre void ValidateRayTracingPipelineCreateInfo(IRenderDevice* pDevice, Uint32 MaxRecursion, const RayTracingPipelineStateCreateInfo& CreateInfo) noexcept(false); /// Copies ray tracing shader group names and also initializes the mapping from the group name to its index. -void CopyRayTracingShaderGroups(std::unordered_map& NameToGroupIndex, - const RayTracingPipelineStateCreateInfo& CreateInfo, - FixedLinearAllocator& MemPool) noexcept; +void CopyRTShaderGroupNames(std::unordered_map& NameToGroupIndex, + const RayTracingPipelineStateCreateInfo& CreateInfo, + FixedLinearAllocator& MemPool) noexcept; void CorrectGraphicsPipelineDesc(GraphicsPipelineDesc& GraphicsPipeline) noexcept; @@ -246,7 +246,7 @@ public: VERIFY_EXPR(m_pRayTracingPipelineData != nullptr); const auto ShaderHandleSize = m_pRayTracingPipelineData->ShaderHandleSize; - VERIFY_EXPR(ShaderHandleSize <= DataSize); + VERIFY(ShaderHandleSize <= DataSize, "DataSize (", DataSize, ") must be at least as large as the shader handle size (", ShaderHandleSize, ")."); if (Name == nullptr || Name[0] == '\0') { @@ -262,7 +262,7 @@ public: std::memcpy(pData, &m_pRayTracingPipelineData->ShaderHandles[ShaderHandleSize * iter->second], ShaderHandleSize); return; } - UNEXPECTED("Can't find shader group with the specified name"); + UNEXPECTED("Can't find shader group '", Name, "'."); } protected: @@ -657,7 +657,7 @@ protected: FixedLinearAllocator& MemPool) noexcept { TNameToGroupIndexMap NameToGroupIndex; - CopyRayTracingShaderGroups(NameToGroupIndex, CreateInfo, MemPool); + CopyRTShaderGroupNames(NameToGroupIndex, CreateInfo, MemPool); CopyResourceLayout(CreateInfo.PSODesc.ResourceLayout, this->m_Desc.ResourceLayout, MemPool); @@ -761,12 +761,20 @@ protected: struct RayTracingPipelineData { RayTracingPipelineDesc Desc; - TNameToGroupIndexMap NameToGroupIndex; + + // Mapping from the shader group name to its index in the pipeline. + // It is used to find the shader handle in ShaderHandles array. + TNameToGroupIndexMap NameToGroupIndex; Uint32 ShaderHandleSize = 0; Uint32 ShaderDataSize = 0; - Uint8 ShaderHandles[sizeof(void*)] = {}; // The actual array size will be ShaderDataSize + // Array of shader handles for every group in the pipeline. + // The handles will be copied to the SBT using NameToGroupIndex to find + // handles by group name. + // The actual array size will be determined at run time and will be stored + // in ShaderDataSize. + Uint8 ShaderHandles[sizeof(void*)] = {}; }; static_assert(offsetof(RayTracingPipelineData, ShaderHandles) % sizeof(void*) == 0, "ShaderHandles member is expected to be sizeof(void*)-aligned"); diff --git a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp index f99b3a0f..2f0297bf 100644 --- a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp +++ b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp @@ -278,7 +278,7 @@ void ValidateRayTracingPipelineCreateInfo(IRenderDevice* pDevice, Uint32 MaxRecu if (GroupName == nullptr) LOG_PSO_ERROR_AND_THROW(MemberName, "[", GroupInd, "].Name must not be null."); - if (*GroupName == 0) + if (GroupName[0] == '\0') LOG_PSO_ERROR_AND_THROW(MemberName, "[", GroupInd, "].Name must not be empty."); const bool IsNewName = GroupNames.emplace(HashMapStringKey{GroupName}).second; @@ -335,9 +335,9 @@ void ValidateRayTracingPipelineCreateInfo(IRenderDevice* pDevice, Uint32 MaxRecu } } -void CopyRayTracingShaderGroups(std::unordered_map& NameToGroupIndex, - const RayTracingPipelineStateCreateInfo& CreateInfo, - FixedLinearAllocator& MemPool) noexcept +void CopyRTShaderGroupNames(std::unordered_map& NameToGroupIndex, + const RayTracingPipelineStateCreateInfo& CreateInfo, + FixedLinearAllocator& MemPool) noexcept { Uint32 GroupIndex = 0; -- cgit v1.2.3