From 43c3821993cb3d6ec3025fa7156da8544d2a1dac Mon Sep 17 00:00:00 2001 From: azhirnov Date: Mon, 16 Nov 2020 20:30:23 +0300 Subject: D3D12 resource binding refactoring, rename LinearAllocator to FixedLinearAllocator. --- .../src/PipelineStateVkImpl.cpp | 46 +++++++++++----------- .../src/ShaderResourceBindingVkImpl.cpp | 4 +- .../src/ShaderResourceLayoutVk.cpp | 2 +- 3 files changed, 26 insertions(+), 26 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index cfde6479..5609d397 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -382,16 +382,13 @@ static void CreateRayTracingPipeline(RenderDeviceVkImpl* template void BuildRTPipelineDescription(const RayTracingPipelineStateCreateInfo& CreateInfo, - TNameToGroupIndexMap& NameToGroupIndex, + const TNameToGroupIndexMap& NameToGroupIndex, std::vector& ShaderGroups, - const ShaderResourceLayoutVk::TShaderStages& ShaderStages, - LinearAllocator& MemPool) + const ShaderResourceLayoutVk::TShaderStages& ShaderStages) { #define LOG_PSO_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Description of ray tracing PSO '", CreateInfo.PSODesc.Name, "' is invalid: ", ##__VA_ARGS__) ShaderGroups.reserve(CreateInfo.GeneralShaderCount + CreateInfo.TriangleHitShaderCount + CreateInfo.ProceduralHitShaderCount); - Uint32 GroupIndex = 0; - std::array ShaderIndices = {}; std::unordered_map UniqueShaders; @@ -429,9 +426,11 @@ void BuildRTPipelineDescription(const RayTracingPipelineStateCreateInfo& Group.anyHitShader = VK_SHADER_UNUSED_KHR; Group.intersectionShader = VK_SHADER_UNUSED_KHR; - bool IsUniqueName = NameToGroupIndex.emplace(HashMapStringKey{MemPool.CopyString(GeneralShader.Name)}, GroupIndex++).second; - if (!IsUniqueName) - LOG_PSO_ERROR_AND_THROW("pGeneralShaders[", i, "].Name must be unique"); +#ifdef DILIGENT_DEVELOPMENT + auto Iter = NameToGroupIndex.find(GeneralShader.Name); + CHECK_THROW(Iter != NameToGroupIndex.end()); + CHECK_THROW(Iter->second == ShaderGroups.size()); +#endif ShaderGroups.push_back(Group); } @@ -449,9 +448,11 @@ void BuildRTPipelineDescription(const RayTracingPipelineStateCreateInfo& Group.anyHitShader = ShaderToIndex(TriHitShader.pAnyHitShader); Group.intersectionShader = VK_SHADER_UNUSED_KHR; - bool IsUniqueName = NameToGroupIndex.emplace(HashMapStringKey{MemPool.CopyString(TriHitShader.Name)}, GroupIndex++).second; - if (!IsUniqueName) - LOG_PSO_ERROR_AND_THROW("pTriangleHitShaders[", i, "].Name must be unique"); +#ifdef DILIGENT_DEVELOPMENT + auto Iter = NameToGroupIndex.find(TriHitShader.Name); + CHECK_THROW(Iter != NameToGroupIndex.end()); + CHECK_THROW(Iter->second == ShaderGroups.size()); +#endif ShaderGroups.push_back(Group); } @@ -469,15 +470,15 @@ void BuildRTPipelineDescription(const RayTracingPipelineStateCreateInfo& Group.closestHitShader = ShaderToIndex(ProcHitShader.pClosestHitShader); Group.anyHitShader = ShaderToIndex(ProcHitShader.pAnyHitShader); - bool IsUniqueName = NameToGroupIndex.emplace(HashMapStringKey{MemPool.CopyString(ProcHitShader.Name)}, GroupIndex++).second; - if (!IsUniqueName) - LOG_PSO_ERROR_AND_THROW("pProceduralHitShaders[", i, "].Name must be unique"); +#ifdef DILIGENT_DEVELOPMENT + auto Iter = NameToGroupIndex.find(ProcHitShader.Name); + CHECK_THROW(Iter != NameToGroupIndex.end()); + CHECK_THROW(Iter->second == ShaderGroups.size()); +#endif ShaderGroups.push_back(Group); } - VERIFY_EXPR(Uint32{CreateInfo.GeneralShaderCount} + Uint32{CreateInfo.TriangleHitShaderCount} + Uint32{CreateInfo.ProceduralHitShaderCount} == GroupIndex); - #ifdef DILIGENT_DEVELOPMENT Uint32 ShaderIndex2 = 0; for (auto& Stage : ShaderStages) @@ -655,7 +656,7 @@ void PipelineStateVkImpl::InitInternalObjects(const PSOCreateInfoType& TShaderStages ShaderStages; ExtractShaders(CreateInfo, ShaderStages); - LinearAllocator MemPool{GetRawAllocator()}; + FixedLinearAllocator MemPool{GetRawAllocator()}; const auto NumShaderStages = GetNumShaderStages(); VERIFY_EXPR(NumShaderStages > 0 && NumShaderStages == ShaderStages.size()); @@ -707,7 +708,7 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* std::vector ShaderModules; InitInternalObjects(CreateInfo, vkShaderStages, ShaderModules, - [this](const GraphicsPipelineStateCreateInfo& CreateInfo, LinearAllocator& MemPool, TShaderStages /*ShaderStages*/) // + [this](const GraphicsPipelineStateCreateInfo& CreateInfo, FixedLinearAllocator& MemPool, TShaderStages /*ShaderStages*/) // { InitializePipelineDesc(CreateInfo, MemPool); } // @@ -735,7 +736,7 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* p std::vector ShaderModules; InitInternalObjects(CreateInfo, vkShaderStages, ShaderModules, - [this](const ComputePipelineStateCreateInfo& CreateInfo, LinearAllocator& MemPool, TShaderStages /*ShaderStages*/) // + [this](const ComputePipelineStateCreateInfo& CreateInfo, FixedLinearAllocator& MemPool, TShaderStages /*ShaderStages*/) // { InitializePipelineDesc(CreateInfo, MemPool); } // @@ -766,11 +767,10 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* std::vector ShaderGroups; InitInternalObjects(CreateInfo, vkShaderStages, ShaderModules, - [&](const RayTracingPipelineStateCreateInfo& CreateInfo, LinearAllocator& MemPool, TShaderStages& ShaderStages) // + [&](const RayTracingPipelineStateCreateInfo& CreateInfo, FixedLinearAllocator& MemPool, TShaderStages& ShaderStages) // { - TNameToGroupIndexMap NameToGroupIndex; - BuildRTPipelineDescription(CreateInfo, NameToGroupIndex, ShaderGroups, ShaderStages, MemPool); - InitializePipelineDesc(CreateInfo, std::move(NameToGroupIndex), MemPool); + InitializePipelineDesc(CreateInfo, MemPool); + BuildRTPipelineDescription(CreateInfo, m_pRayTracingPipelineData->NameToGroupIndex, ShaderGroups, ShaderStages); } // ); diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp index 3e4a65cf..d81fb675 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp @@ -30,7 +30,7 @@ #include "PipelineStateVkImpl.hpp" #include "ShaderVkImpl.hpp" #include "RenderDeviceVkImpl.hpp" -#include "LinearAllocator.hpp" +#include "FixedLinearAllocator.hpp" namespace Diligent { @@ -54,7 +54,7 @@ ShaderResourceBindingVkImpl::ShaderResourceBindingVkImpl(IReferenceCounters* pR m_NumShaders = static_cast(pPSO->GetNumShaderStages()); - LinearAllocator MemPool{GetRawAllocator()}; + FixedLinearAllocator MemPool{GetRawAllocator()}; MemPool.AddSpace(m_NumShaders); MemPool.Reserve(); m_pShaderVarMgrs = MemPool.ConstructArray(m_NumShaders, std::ref(*this), std::ref(m_ShaderResourceCache)); diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp index 9a4caec8..e2ea6cb5 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp @@ -193,7 +193,7 @@ StringPool ShaderResourceLayoutVk::AllocateMemory(const std::vector(TotalResources); MemPool.AddSpace(m_NumImmutableSamplers); -- cgit v1.2.3