summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-10-18 20:06:48 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-10-18 20:06:48 +0000
commit645ef7e425d6ff4ee64b782d27767e0a5732be50 (patch)
tree8502aea9ba6100af3a0908c5975a75debc5fd7de /Graphics/GraphicsEngineVulkan
parentRefactored LinearAllocator (diff)
downloadDiligentCore-645ef7e425d6ff4ee64b782d27767e0a5732be50.tar.gz
DiligentCore-645ef7e425d6ff4ee64b782d27767e0a5732be50.zip
A number of fixes for PSO creation refactoring (API240075)
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp9
-rw-r--r--Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp3
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp77
-rw-r--r--Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp18
4 files changed, 50 insertions, 57 deletions
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 <typename PSOCreateInfoType>
+ LinearAllocator InitInternalObjects(const PSOCreateInfoType& CreateInfo,
+ std::vector<VkPipelineShaderStageCreateInfo>& vkShaderStages,
+ std::vector<VulkanUtilities::ShaderModuleWrapper>& 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 <typename PSOCreateInfoType>
+ 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 <typename PSOCreateInfoType>
+LinearAllocator PipelineStateVkImpl::InitInternalObjects(const PSOCreateInfoType& CreateInfo,
+ std::vector<VkPipelineShaderStageCreateInfo>& vkShaderStages,
+ std::vector<VulkanUtilities::ShaderModuleWrapper>& ShaderModules)
{
m_ResourceLayoutIndex.fill(-1);
- ShaderResourceLayoutVk::TShaderStages ShaderStages;
+ TShaderStages ShaderStages;
ExtractShaders<ShaderVkImpl>(CreateInfo, ShaderStages);
// Memory must be released if an exception is thrown.
LinearAllocator MemPool{GetRawAllocator()};
- MemPool.AddRequiredSize<ShaderResourceLayoutVk>(GetNumShaderStages() * 2);
- MemPool.AddRequiredSize<ShaderResourceCacheVk>(GetNumShaderStages());
- MemPool.AddRequiredSize<ShaderVariableManagerVk>(GetNumShaderStages());
+ MemPool.AddSpace<ShaderResourceLayoutVk>(GetNumShaderStages() * 2);
+ MemPool.AddSpace<ShaderResourceCacheVk>(GetNumShaderStages());
+ MemPool.AddSpace<ShaderVariableManagerVk>(GetNumShaderStages());
- ValidateAndReserveSpace(CreateInfo, MemPool);
+ ReserveSpaceForPipelineDesc(CreateInfo, MemPool);
MemPool.Reserve();
@@ -490,15 +488,27 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters*
m_StaticResCaches = MemPool.Allocate<ShaderResourceCacheVk>(GetNumShaderStages());
m_StaticVarsMgrs = MemPool.Allocate<ShaderVariableManagerVk>(GetNumShaderStages());
- InitGraphicsPipeline(CreateInfo, MemPool);
- InitResourceLayouts(pDeviceVk, CreateInfo, ShaderStages);
+ InitializePipelineDesc(CreateInfo, MemPool);
+ InitResourceLayouts(CreateInfo, ShaderStages);
// Create shader modules and initialize shader stages
- std::vector<VkPipelineShaderStageCreateInfo> 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<VkPipelineShaderStageCreateInfo> vkShaderStages;
std::vector<VulkanUtilities::ShaderModuleWrapper> 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<ShaderVkImpl>(CreateInfo, ShaderStages);
-
- // Memory must be released if an exception is thrown.
- LinearAllocator MemPool{GetRawAllocator()};
-
- MemPool.AddRequiredSize<ShaderResourceLayoutVk>(GetNumShaderStages() * 2);
- MemPool.AddRequiredSize<ShaderResourceCacheVk>(GetNumShaderStages());
- MemPool.AddRequiredSize<ShaderVariableManagerVk>(GetNumShaderStages());
-
- ValidateAndReserveSpace(CreateInfo, MemPool);
-
- MemPool.Reserve();
-
- m_ShaderResourceLayouts = MemPool.Allocate<ShaderResourceLayoutVk>(GetNumShaderStages() * 2);
- m_StaticResCaches = MemPool.Allocate<ShaderResourceCacheVk>(GetNumShaderStages());
- m_StaticVarsMgrs = MemPool.Allocate<ShaderVariableManagerVk>(GetNumShaderStages());
-
- InitComputePipeline(CreateInfo, MemPool);
- InitResourceLayouts(pDeviceVk, CreateInfo, ShaderStages);
-
- // Create shader modules and initialize shader stages
- std::vector<VkPipelineShaderStageCreateInfo> VkShaderStages;
+ std::vector<VkPipelineShaderStageCreateInfo> vkShaderStages;
std::vector<VulkanUtilities::ShaderModuleWrapper> 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 <typename PSOCreateInfoType>
+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<IObject**>(ppPipelineState));
- OnCreateDeviceObject(pPipelineStateVk);
- } //
- );
+ CreatePipelineState(PSOCreateInfo, ppPipelineState);
}