diff --git a/engine/include/XCEngine/Rendering/RenderPassGraphContract.h b/engine/include/XCEngine/Rendering/RenderPassGraphContract.h index edbea7e6..94980ec9 100644 --- a/engine/include/XCEngine/Rendering/RenderPassGraphContract.h +++ b/engine/include/XCEngine/Rendering/RenderPassGraphContract.h @@ -2,6 +2,8 @@ #include +#include + namespace XCEngine { namespace Rendering { @@ -27,6 +29,22 @@ inline RenderPassGraphIO BuildColorDepthRasterPassGraphIO() { }; } +inline RenderPassGraphIO BuildDeclaredRasterPassGraphIO( + const RenderPassRenderGraphContext& context) { + const bool writesColor = + std::any_of( + context.colorTargets.begin(), + context.colorTargets.end(), + [](RenderGraphTextureHandle handle) { + return handle.IsValid(); + }); + return { + context.sourceSurface != nullptr || context.sourceColorTexture.IsValid(), + writesColor, + context.depthTarget.IsValid() + }; +} + using RenderPassGraphExecutePassCallback = std::function; @@ -59,6 +77,15 @@ inline bool RecordColorDepthRasterPass( BuildColorDepthRasterPassGraphIO()); } +inline bool RecordDeclaredRasterPass( + RenderPass& pass, + const RenderPassRenderGraphContext& context) { + return RecordRasterRenderPass( + pass, + context, + BuildDeclaredRasterPassGraphIO(context)); +} + inline bool RecordSourceColorFullscreenCallbackRasterPass( const RenderPassRenderGraphContext& context, RenderPassGraphExecutePassCallback executePassCallback, diff --git a/engine/src/Rendering/SceneRenderFeaturePass.cpp b/engine/src/Rendering/SceneRenderFeaturePass.cpp index 8bbeee1b..6ffcb37c 100644 --- a/engine/src/Rendering/SceneRenderFeaturePass.cpp +++ b/engine/src/Rendering/SceneRenderFeaturePass.cpp @@ -11,13 +11,6 @@ namespace Rendering { bool SceneRenderFeaturePass::RecordRenderGraph( const SceneRenderFeaturePassRenderGraphContext& context) { const bool usesSourceColor = context.sourceColorTexture.IsValid(); - const bool writesColor = - std::any_of( - context.colorTargets.begin(), - context.colorTargets.end(), - [](RenderGraphTextureHandle handle) { - return handle.IsValid(); - }); const RenderGraphRecordingContext baseRecordingContext = BuildRenderGraphRecordingContext(context); const RenderSurface sourceSurfaceTemplate = @@ -51,11 +44,7 @@ bool SceneRenderFeaturePass::RecordRenderGraph( return RecordRasterRenderPass( *this, passContext, - { - usesSourceColor, - writesColor, - context.depthTarget.IsValid() - }); + BuildDeclaredRasterPassGraphIO(passContext)); } } // namespace Rendering diff --git a/tests/Rendering/unit/test_camera_scene_renderer.cpp b/tests/Rendering/unit/test_camera_scene_renderer.cpp index e9eb1b1e..26e98ec5 100644 --- a/tests/Rendering/unit/test_camera_scene_renderer.cpp +++ b/tests/Rendering/unit/test_camera_scene_renderer.cpp @@ -779,17 +779,9 @@ public: lastRecordedBlackboardMainSceneColorValid = false; lastRecordedBlackboardPostProcessColorValid = false; } - const bool writesColor = - context.sourceSurface != nullptr || - !context.colorTargets.empty(); - return RecordRasterRenderPass( + return RecordDeclaredRasterPass( *this, - context, - { - context.sourceSurface != nullptr, - writesColor, - context.depthTarget.IsValid() - }); + context); } bool Initialize(const RenderContext&) override { diff --git a/tests/Rendering/unit/test_render_graph_recording_context.cpp b/tests/Rendering/unit/test_render_graph_recording_context.cpp index 047de7f6..2acf8387 100644 --- a/tests/Rendering/unit/test_render_graph_recording_context.cpp +++ b/tests/Rendering/unit/test_render_graph_recording_context.cpp @@ -69,6 +69,35 @@ TEST(RenderPassGraphContract_Test, BuildsColorDepthRasterPassGraphIO) { EXPECT_TRUE(io.writeDepth); } +TEST(RenderPassGraphContract_Test, BuildsDeclaredRasterPassGraphIOFromContextResources) { + RenderGraph graph = {}; + RenderGraphBuilder builder(graph); + RenderGraphBlackboard blackboard = {}; + RenderContext renderContext = {}; + RenderSceneData sceneData = {}; + RenderSurface surface(1280u, 720u); + RenderSurface sourceSurface(640u, 360u); + bool executionSucceeded = true; + const RenderGraphRecordingContext commonContext = + BuildCommonContext( + builder, + blackboard, + renderContext, + sceneData, + surface, + sourceSurface, + executionSucceeded); + const RenderPassRenderGraphContext passContext = + BuildRenderPassRenderGraphContext(commonContext); + + const RenderPassGraphIO io = + BuildDeclaredRasterPassGraphIO(passContext); + + EXPECT_TRUE(io.readSourceColor); + EXPECT_TRUE(io.writeColor); + EXPECT_TRUE(io.writeDepth); +} + TEST(RenderGraphRecordingContext_Test, BuildsRenderPassContextFromSharedRecordingData) { RenderGraph graph = {}; RenderGraphBuilder builder(graph);