diff --git a/include/Nazara/Graphics/Graphics.hpp b/include/Nazara/Graphics/Graphics.hpp index 851023603..895cdcefc 100644 --- a/include/Nazara/Graphics/Graphics.hpp +++ b/include/Nazara/Graphics/Graphics.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -38,6 +39,7 @@ namespace Nz inline PixelFormat GetPreferredDepthStencilFormat() const; inline const std::shared_ptr& GetReferencePipelineLayout() const; inline const std::shared_ptr& GetRenderDevice() const; + inline const RenderPassCache& GetRenderPassCache() const; inline TextureSamplerCache& GetSamplerCache(); struct Config @@ -58,6 +60,7 @@ namespace Nz void BuildFullscreenVertexBuffer(); void SelectDepthStencilFormats(); + std::optional m_renderPassCache; std::optional m_samplerCache; std::shared_ptr m_fullscreenVertexBuffer; std::shared_ptr m_renderDevice; diff --git a/include/Nazara/Graphics/Graphics.inl b/include/Nazara/Graphics/Graphics.inl index 80c3348a5..5ebcca7af 100644 --- a/include/Nazara/Graphics/Graphics.inl +++ b/include/Nazara/Graphics/Graphics.inl @@ -42,6 +42,12 @@ namespace Nz return m_renderDevice; } + inline const RenderPassCache& Graphics::GetRenderPassCache() const + { + assert(m_renderPassCache); + return *m_renderPassCache; + } + inline TextureSamplerCache& Graphics::GetSamplerCache() { return *m_samplerCache; diff --git a/src/Nazara/Graphics/FrameGraph.cpp b/src/Nazara/Graphics/FrameGraph.cpp index 46f7b5ce9..d2542cbe5 100644 --- a/src/Nazara/Graphics/FrameGraph.cpp +++ b/src/Nazara/Graphics/FrameGraph.cpp @@ -851,7 +851,8 @@ namespace Nz BuildPhysicalPassDependencies(colorAttachmentCount, depthStencilAttachmentIndex.has_value(), renderPassAttachments, subpassesDesc, subpassesDeps); - m_pending.renderPasses.push_back(renderDevice->InstantiateRenderPass(std::move(renderPassAttachments), std::move(subpassesDesc), std::move(subpassesDeps))); + m_pending.renderPasses.push_back(Graphics::Instance()->GetRenderPassCache().Get(renderPassAttachments, subpassesDesc, subpassesDeps)); + //m_pending.renderPasses.push_back(renderDevice->InstantiateRenderPass(std::move(renderPassAttachments), std::move(subpassesDesc), std::move(subpassesDeps))); physicalPassIndex++; } diff --git a/src/Nazara/Graphics/Graphics.cpp b/src/Nazara/Graphics/Graphics.cpp index 5e9ff0390..dadacfacf 100644 --- a/src/Nazara/Graphics/Graphics.cpp +++ b/src/Nazara/Graphics/Graphics.cpp @@ -60,6 +60,7 @@ namespace Nz if (!m_renderDevice) throw std::runtime_error("failed to instantiate render device"); + m_renderPassCache.emplace(*m_renderDevice); m_samplerCache.emplace(m_renderDevice); MaterialPipeline::Initialize(); @@ -78,6 +79,7 @@ namespace Nz Graphics::~Graphics() { MaterialPipeline::Uninitialize(); + m_renderPassCache.reset(); m_samplerCache.reset(); m_fullscreenVertexBuffer.reset(); m_fullscreenVertexDeclaration.reset();