From 90ab0e9438b0a547e8e9b932cbd8d3c145102255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Mon, 13 Dec 2021 23:44:34 +0100 Subject: [PATCH] Graphics/FramePass: Add SetReadInput method --- examples/DeferredShading/main.cpp | 12 +++--------- include/Nazara/Graphics/FramePass.hpp | 5 +++-- include/Nazara/Graphics/FramePass.inl | 6 ++++++ src/Nazara/Graphics/FrameGraph.cpp | 7 +++++-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/examples/DeferredShading/main.cpp b/examples/DeferredShading/main.cpp index 5a70d7913..9e843ca9e 100644 --- a/examples/DeferredShading/main.cpp +++ b/examples/DeferredShading/main.cpp @@ -672,10 +672,7 @@ int main() Nz::PixelFormat::RGBA16F }); - bloomOutput = graph.AddAttachment({ - "Backbuffer", - Nz::PixelFormat::RGBA16F - }); + bloomOutput = graph.AddAttachmentProxy("Bloom output", lightOutput); unsigned int bloomSize = 50'000; bloomBrightOutput = graph.AddAttachment({ @@ -889,11 +886,6 @@ int main() builder.SetViewport(renderArea); builder.BindVertexBuffer(0, *fullscreenVertexBuffer); - // Blit light output - builder.BindPipeline(*Nz::Graphics::Instance()->GetBlitPipeline(false)); - builder.BindShaderBinding(0, *bloomBlitBinding); - builder.Draw(3); - // Blend bloom builder.BindPipeline(*bloomBlendPipeline); for (std::size_t i = 0; i < BloomSubdivisionCount; ++i) @@ -909,6 +901,8 @@ int main() }); bloomBlendPass.AddInput(lightOutput); + bloomBlendPass.SetReadInput(0, false); + for (std::size_t i = 0; i < BloomSubdivisionCount; ++i) bloomBlendPass.AddInput(bloomTextures[i * 2 + 1]); diff --git a/include/Nazara/Graphics/FramePass.hpp b/include/Nazara/Graphics/FramePass.hpp index bf9b81fb7..06cf6a521 100644 --- a/include/Nazara/Graphics/FramePass.hpp +++ b/include/Nazara/Graphics/FramePass.hpp @@ -61,10 +61,10 @@ namespace Nz inline void SetCommandCallback(CommandCallback callback); inline void SetClearColor(std::size_t outputIndex, const std::optional& color); inline void SetDepthStencilClear(float depth, UInt32 stencil); - inline void SetExecutionCallback(ExecutionCallback callback); - inline void SetDepthStencilInput(std::size_t attachmentId); inline void SetDepthStencilOutput(std::size_t attachmentId); + inline void SetExecutionCallback(ExecutionCallback callback); + inline void SetReadInput(std::size_t inputIndex, bool doesRead); FramePass& operator=(const FramePass&) = delete; FramePass& operator=(FramePass&&) noexcept = default; @@ -80,6 +80,7 @@ namespace Nz struct Input { std::size_t attachmentId; + bool doesRead = true; }; struct Output diff --git a/include/Nazara/Graphics/FramePass.inl b/include/Nazara/Graphics/FramePass.inl index 8a27e0f11..3a38bfab2 100644 --- a/include/Nazara/Graphics/FramePass.inl +++ b/include/Nazara/Graphics/FramePass.inl @@ -126,6 +126,12 @@ namespace Nz m_executionCallback = std::move(callback); } + inline void FramePass::SetReadInput(std::size_t inputIndex, bool doesRead) + { + assert(inputIndex < m_inputs.size()); + m_inputs[inputIndex].doesRead = doesRead; + } + inline void FramePass::SetDepthStencilInput(std::size_t attachmentId) { m_depthStencilInput = attachmentId; diff --git a/src/Nazara/Graphics/FrameGraph.cpp b/src/Nazara/Graphics/FrameGraph.cpp index 0ebb3887d..8cc1a4fc2 100644 --- a/src/Nazara/Graphics/FrameGraph.cpp +++ b/src/Nazara/Graphics/FrameGraph.cpp @@ -658,7 +658,7 @@ namespace Nz std::vector subpassesDesc; std::vector subpassesDeps; - auto RegisterColorInput = [&](const FramePass::Input& input, PhysicalPassData::Subpass& subpass) + auto RegisterColorInputRead = [&](const FramePass::Input& input, PhysicalPassData::Subpass& subpass) { std::size_t textureId = Retrieve(m_pending.attachmentToTextures, input.attachmentId); @@ -769,7 +769,10 @@ namespace Nz colorAttachments.reserve(subpassOutputs.size()); for (const auto& input : subpassInputs) - RegisterColorInput(input, subpass); + { + if (input.doesRead) + RegisterColorInputRead(input, subpass); + } for (const auto& output : subpassOutputs) {