From 645ef7e425d6ff4ee64b782d27767e0a5732be50 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 18 Oct 2020 13:06:48 -0700 Subject: A number of fixes for PSO creation refactoring (API240075) --- .../include/PipelineStateVkImpl.hpp | 9 ++- .../include/RenderDeviceVkImpl.hpp | 3 + .../src/PipelineStateVkImpl.cpp | 77 +++++++++------------- .../src/RenderDeviceVkImpl.cpp | 18 +++-- 4 files changed, 50 insertions(+), 57 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp index 1773e743..96b34008 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp @@ -127,8 +127,13 @@ public: private: using TShaderStages = ShaderResourceLayoutVk::TShaderStages; - void InitResourceLayouts(RenderDeviceVkImpl* pDeviceVk, - const PipelineStateCreateInfo& CreateInfo, + + template + LinearAllocator InitInternalObjects(const PSOCreateInfoType& CreateInfo, + std::vector& vkShaderStages, + std::vector& ShaderModules); + + void InitResourceLayouts(const PipelineStateCreateInfo& CreateInfo, TShaderStages& ShaderStages); const ShaderResourceLayoutVk& GetStaticShaderResLayout(Uint32 ShaderInd) const diff --git a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp index 24f3345c..469e8119 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp @@ -183,6 +183,9 @@ public: IDXCompiler* GetDxCompiler() const { return m_pDxCompiler.get(); } private: + template + void CreatePipelineState(const PSOCreateInfoType& PSOCreateInfo, IPipelineState** ppPipelineState); + virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) override final; // Submits command buffer for execution to the command queue diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 3e4154be..dfa270cc 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -401,10 +401,10 @@ static void CreateGraphicsPipeline(RenderDeviceVkImpl* Pipeline = LogicalDevice.CreateGraphicsPipeline(PipelineCI, VK_NULL_HANDLE, PSODesc.Name); } -void PipelineStateVkImpl::InitResourceLayouts(RenderDeviceVkImpl* pDeviceVk, - const PipelineStateCreateInfo& CreateInfo, +void PipelineStateVkImpl::InitResourceLayouts(const PipelineStateCreateInfo& CreateInfo, TShaderStages& ShaderStages) { + auto* const pDeviceVk = GetDevice(); const auto& LogicalDevice = pDeviceVk->GetLogicalDevice(); for (size_t s = 0; s < ShaderStages.size(); ++s) @@ -463,26 +463,24 @@ void PipelineStateVkImpl::InitResourceLayouts(RenderDeviceVkImpl* pDe m_ShaderResourceLayoutHash = m_PipelineLayout.GetHash(); } - -PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCounters, - RenderDeviceVkImpl* pDeviceVk, - const GraphicsPipelineStateCreateInfo& CreateInfo) : - TPipelineStateBase{pRefCounters, pDeviceVk, CreateInfo.PSODesc}, - m_SRBMemAllocator{GetRawAllocator()} +template +LinearAllocator PipelineStateVkImpl::InitInternalObjects(const PSOCreateInfoType& CreateInfo, + std::vector& vkShaderStages, + std::vector& ShaderModules) { m_ResourceLayoutIndex.fill(-1); - ShaderResourceLayoutVk::TShaderStages ShaderStages; + TShaderStages ShaderStages; ExtractShaders(CreateInfo, ShaderStages); // Memory must be released if an exception is thrown. LinearAllocator MemPool{GetRawAllocator()}; - MemPool.AddRequiredSize(GetNumShaderStages() * 2); - MemPool.AddRequiredSize(GetNumShaderStages()); - MemPool.AddRequiredSize(GetNumShaderStages()); + MemPool.AddSpace(GetNumShaderStages() * 2); + MemPool.AddSpace(GetNumShaderStages()); + MemPool.AddSpace(GetNumShaderStages()); - ValidateAndReserveSpace(CreateInfo, MemPool); + ReserveSpaceForPipelineDesc(CreateInfo, MemPool); MemPool.Reserve(); @@ -490,15 +488,27 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* m_StaticResCaches = MemPool.Allocate(GetNumShaderStages()); m_StaticVarsMgrs = MemPool.Allocate(GetNumShaderStages()); - InitGraphicsPipeline(CreateInfo, MemPool); - InitResourceLayouts(pDeviceVk, CreateInfo, ShaderStages); + InitializePipelineDesc(CreateInfo, MemPool); + InitResourceLayouts(CreateInfo, ShaderStages); // Create shader modules and initialize shader stages - std::vector VkShaderStages; + InitPipelineShaderStages(GetDevice()->GetLogicalDevice(), ShaderStages, ShaderModules, vkShaderStages); + + return MemPool; +} + +PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCounters, + RenderDeviceVkImpl* pDeviceVk, + const GraphicsPipelineStateCreateInfo& CreateInfo) : + TPipelineStateBase{pRefCounters, pDeviceVk, CreateInfo.PSODesc}, + m_SRBMemAllocator{GetRawAllocator()} +{ + std::vector vkShaderStages; std::vector ShaderModules; - InitPipelineShaderStages(pDeviceVk->GetLogicalDevice(), ShaderStages, ShaderModules, VkShaderStages); - CreateGraphicsPipeline(pDeviceVk, VkShaderStages, m_PipelineLayout, m_Desc, GetGraphicsPipelineDesc(), m_Pipeline, m_pRenderPass); + auto MemPool = InitInternalObjects(CreateInfo, vkShaderStages, ShaderModules); + + CreateGraphicsPipeline(pDeviceVk, vkShaderStages, m_PipelineLayout, m_Desc, GetGraphicsPipelineDesc(), m_Pipeline, m_pRenderPass); void* Ptr = MemPool.Release(); VERIFY_EXPR(Ptr == m_ShaderResourceLayouts); @@ -511,35 +521,12 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* p TPipelineStateBase{pRefCounters, pDeviceVk, CreateInfo.PSODesc}, m_SRBMemAllocator{GetRawAllocator()} { - m_ResourceLayoutIndex.fill(-1); - - ShaderResourceLayoutVk::TShaderStages ShaderStages; - ExtractShaders(CreateInfo, ShaderStages); - - // Memory must be released if an exception is thrown. - LinearAllocator MemPool{GetRawAllocator()}; - - MemPool.AddRequiredSize(GetNumShaderStages() * 2); - MemPool.AddRequiredSize(GetNumShaderStages()); - MemPool.AddRequiredSize(GetNumShaderStages()); - - ValidateAndReserveSpace(CreateInfo, MemPool); - - MemPool.Reserve(); - - m_ShaderResourceLayouts = MemPool.Allocate(GetNumShaderStages() * 2); - m_StaticResCaches = MemPool.Allocate(GetNumShaderStages()); - m_StaticVarsMgrs = MemPool.Allocate(GetNumShaderStages()); - - InitComputePipeline(CreateInfo, MemPool); - InitResourceLayouts(pDeviceVk, CreateInfo, ShaderStages); - - // Create shader modules and initialize shader stages - std::vector VkShaderStages; + std::vector vkShaderStages; std::vector ShaderModules; - InitPipelineShaderStages(pDeviceVk->GetLogicalDevice(), ShaderStages, ShaderModules, VkShaderStages); - CreateComputePipeline(pDeviceVk, VkShaderStages, m_PipelineLayout, m_Desc, m_Pipeline); + auto MemPool = InitInternalObjects(CreateInfo, vkShaderStages, ShaderModules); + + CreateComputePipeline(pDeviceVk, vkShaderStages, m_PipelineLayout, m_Desc, m_Pipeline); void* Ptr = MemPool.Release(); VERIFY_EXPR(Ptr == m_ShaderResourceLayouts); diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index ca729479..1441569e 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -541,7 +541,8 @@ void RenderDeviceVkImpl::TestTextureFormat(TEXTURE_FORMAT TexFormat) IMPLEMENT_QUERY_INTERFACE(RenderDeviceVkImpl, IID_RenderDeviceVk, TRenderDeviceBase) -void RenderDeviceVkImpl::CreateGraphicsPipelineState(const GraphicsPipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState) +template +void RenderDeviceVkImpl::CreatePipelineState(const PSOCreateInfoType& PSOCreateInfo, IPipelineState** ppPipelineState) { CreateDeviceObject( "Pipeline State", PSOCreateInfo.PSODesc, ppPipelineState, @@ -554,18 +555,15 @@ void RenderDeviceVkImpl::CreateGraphicsPipelineState(const GraphicsPipelineState ); } +void RenderDeviceVkImpl::CreateGraphicsPipelineState(const GraphicsPipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState) +{ + CreatePipelineState(PSOCreateInfo, ppPipelineState); +} + void RenderDeviceVkImpl::CreateComputePipelineState(const ComputePipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState) { - CreateDeviceObject( - "Pipeline State", PSOCreateInfo.PSODesc, ppPipelineState, - [&]() // - { - PipelineStateVkImpl* pPipelineStateVk(NEW_RC_OBJ(m_PSOAllocator, "PipelineStateVkImpl instance", PipelineStateVkImpl)(this, PSOCreateInfo)); - pPipelineStateVk->QueryInterface(IID_PipelineState, reinterpret_cast(ppPipelineState)); - OnCreateDeviceObject(pPipelineStateVk); - } // - ); + CreatePipelineState(PSOCreateInfo, ppPipelineState); } -- cgit v1.2.3