diff --git a/engine/include/XCEngine/Rendering/Graph/RenderGraphRecordingContext.h b/engine/include/XCEngine/Rendering/Graph/RenderGraphRecordingContext.h index f11409dc..9a2c54c3 100644 --- a/engine/include/XCEngine/Rendering/Graph/RenderGraphRecordingContext.h +++ b/engine/include/XCEngine/Rendering/Graph/RenderGraphRecordingContext.h @@ -22,6 +22,83 @@ struct RenderGraphRecordingContext { RenderGraphBlackboard* blackboard = nullptr; }; +inline RenderGraphRecordingContext CloneRenderGraphRecordingContext( + const RenderGraphRecordingContext& context, + const Containers::String& passName) { + return { + context.graphBuilder, + passName, + context.renderContext, + context.sceneData, + context.surface, + context.sourceSurface, + context.sourceColorView, + context.sourceColorState, + context.sourceColorTexture, + context.colorTargets, + context.depthTarget, + context.executionSucceeded, + context.blackboard + }; +} + +inline RenderGraphRecordingContext BuildRenderGraphRecordingContext( + const RenderPassRenderGraphContext& context) { + return { + context.graphBuilder, + context.passName, + context.renderContext, + context.sceneData, + context.surface, + context.sourceSurface, + context.sourceColorView, + context.sourceColorState, + context.sourceColorTexture, + context.colorTargets, + context.depthTarget, + context.executionSucceeded, + context.blackboard + }; +} + +inline RenderGraphRecordingContext BuildRenderGraphRecordingContext( + const SceneRenderFeaturePassRenderGraphContext& context) { + return { + context.graphBuilder, + context.passName, + context.renderContext, + context.sceneData, + context.surface, + context.sourceSurface, + context.sourceColorView, + context.sourceColorState, + context.sourceColorTexture, + context.colorTargets, + context.depthTarget, + context.executionSucceeded, + context.blackboard + }; +} + +inline RenderGraphRecordingContext BuildRenderGraphRecordingContext( + const RenderPipelineMainSceneRenderGraphContext& context) { + return { + context.graphBuilder, + context.passName, + context.renderContext, + context.sceneData, + context.surfaceTemplate, + context.sourceSurface, + context.sourceColorView, + context.sourceColorState, + context.sourceColorTexture, + context.colorTargets, + context.depthTarget, + context.executionSucceeded, + context.blackboard + }; +} + inline RenderPassRenderGraphContext BuildRenderPassRenderGraphContext( const RenderGraphRecordingContext& common, RenderPassGraphBeginCallback beginPassCallback = {}, @@ -93,24 +170,13 @@ inline SceneRenderFeaturePassRenderGraphContext CloneSceneRenderFeaturePassRende const SceneRenderFeaturePassRenderGraphContext& context, const Containers::String& passName, bool clearAttachments) { - return { - context.graphBuilder, - passName, - context.renderContext, - context.sceneData, - context.surface, - context.sourceSurface, - context.sourceColorView, - context.sourceColorState, - context.sourceColorTexture, - context.colorTargets, - context.depthTarget, + return BuildSceneRenderFeaturePassRenderGraphContext( + CloneRenderGraphRecordingContext( + BuildRenderGraphRecordingContext(context), + passName), clearAttachments, - context.executionSucceeded, context.beginPassCallback, - context.endPassCallback, - context.blackboard - }; + context.endPassCallback); } } // namespace Rendering diff --git a/engine/src/Rendering/RenderPipelineMainSceneGraphContract.cpp b/engine/src/Rendering/RenderPipelineMainSceneGraphContract.cpp index 0618e9af..35941ea5 100644 --- a/engine/src/Rendering/RenderPipelineMainSceneGraphContract.cpp +++ b/engine/src/Rendering/RenderPipelineMainSceneGraphContract.cpp @@ -8,29 +8,6 @@ namespace XCEngine { namespace Rendering { -namespace { - -RenderGraphRecordingContext BuildCommonContext( - const RenderPipelineMainSceneRenderGraphContext& context, - Containers::String passName) { - return { - context.graphBuilder, - passName, - context.renderContext, - context.sceneData, - context.surfaceTemplate, - context.sourceSurface, - context.sourceColorView, - context.sourceColorState, - context.sourceColorTexture, - context.colorTargets, - context.depthTarget, - context.executionSucceeded, - context.blackboard - }; -} - -} // namespace Containers::String BuildRenderPipelineMainScenePhasePassName( const Containers::String& baseName, @@ -54,7 +31,7 @@ bool RecordRenderPipelineMainSceneFeaturePasses( bool* recordedAnyPass) { const SceneRenderFeaturePassRenderGraphContext featureContext = BuildSceneRenderFeaturePassRenderGraphContext( - BuildCommonContext(context, context.passName), + BuildRenderGraphRecordingContext(context), clearAttachments, beginPassCallback, endPassCallback); @@ -73,8 +50,8 @@ bool RecordRenderPipelineMainScenePhasePass( std::vector additionalReadTextures) { const RenderPassRenderGraphContext passContext = BuildRenderPassRenderGraphContext( - BuildCommonContext( - context, + CloneRenderGraphRecordingContext( + BuildRenderGraphRecordingContext(context), BuildRenderPipelineMainScenePhasePassName( context.passName, scenePhase)), diff --git a/tests/Rendering/unit/test_render_graph_recording_context.cpp b/tests/Rendering/unit/test_render_graph_recording_context.cpp index 8e799fb3..b4c77e3a 100644 --- a/tests/Rendering/unit/test_render_graph_recording_context.cpp +++ b/tests/Rendering/unit/test_render_graph_recording_context.cpp @@ -205,3 +205,103 @@ TEST(RenderGraphRecordingContext_Test, BuildsPipelineMainSceneContextFromSharedR EXPECT_EQ(pipelineContext.executionSucceeded, &executionSucceeded); EXPECT_EQ(pipelineContext.blackboard, &blackboard); } + +TEST(RenderGraphRecordingContext_Test, BuildsSharedRecordingDataFromPipelineMainSceneContext) { + RenderGraph graph = {}; + RenderGraphBuilder builder(graph); + RenderGraphBlackboard blackboard = {}; + RenderContext renderContext = {}; + RenderSceneData sceneData = {}; + RenderSurface surface(800u, 600u); + RenderSurface sourceSurface(400u, 300u); + bool executionSucceeded = false; + const RenderGraphRecordingContext commonContext = + BuildCommonContext( + builder, + blackboard, + renderContext, + sceneData, + surface, + sourceSurface, + executionSucceeded); + const RenderPipelineMainSceneRenderGraphContext pipelineContext = + BuildRenderPipelineMainSceneRenderGraphContext(commonContext); + + const RenderGraphRecordingContext rebuiltCommonContext = + BuildRenderGraphRecordingContext(pipelineContext); + const RenderGraphRecordingContext clonedCommonContext = + CloneRenderGraphRecordingContext( + rebuiltCommonContext, + XCEngine::Containers::String("Recording.Cloned")); + + EXPECT_EQ(&rebuiltCommonContext.graphBuilder, &builder); + EXPECT_EQ(rebuiltCommonContext.passName, XCEngine::Containers::String("Recording.Pass")); + EXPECT_EQ(&rebuiltCommonContext.renderContext, &renderContext); + EXPECT_EQ(&rebuiltCommonContext.sceneData, &sceneData); + EXPECT_EQ(rebuiltCommonContext.surface.GetWidth(), 800u); + ASSERT_NE(rebuiltCommonContext.sourceSurface, nullptr); + EXPECT_EQ(rebuiltCommonContext.sourceSurface->GetWidth(), 400u); + EXPECT_EQ(rebuiltCommonContext.sourceColorTexture.index, 3u); + ASSERT_EQ(rebuiltCommonContext.colorTargets.size(), 2u); + EXPECT_EQ(rebuiltCommonContext.colorTargets[0].index, 4u); + EXPECT_EQ(rebuiltCommonContext.depthTarget.index, 6u); + EXPECT_EQ(rebuiltCommonContext.executionSucceeded, &executionSucceeded); + EXPECT_EQ(rebuiltCommonContext.blackboard, &blackboard); + + EXPECT_EQ(clonedCommonContext.passName, XCEngine::Containers::String("Recording.Cloned")); + EXPECT_EQ(clonedCommonContext.sourceColorTexture.index, rebuiltCommonContext.sourceColorTexture.index); + EXPECT_EQ(clonedCommonContext.depthTarget.index, rebuiltCommonContext.depthTarget.index); + EXPECT_EQ(clonedCommonContext.blackboard, rebuiltCommonContext.blackboard); +} + +TEST(RenderGraphRecordingContext_Test, BuildsSharedRecordingDataFromPassAndFeatureContexts) { + 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 RenderGraphRecordingContext fromPassContext = + BuildRenderGraphRecordingContext(passContext); + + const SceneRenderFeaturePassRenderGraphContext featureContext = + BuildSceneRenderFeaturePassRenderGraphContext( + commonContext, + true); + const RenderGraphRecordingContext fromFeatureContext = + BuildRenderGraphRecordingContext(featureContext); + const SceneRenderFeaturePassRenderGraphContext clonedFeatureContext = + CloneSceneRenderFeaturePassRenderGraphContext( + featureContext, + XCEngine::Containers::String("Feature.Cloned"), + false); + + EXPECT_EQ(fromPassContext.passName, commonContext.passName); + EXPECT_EQ(fromPassContext.sourceColorTexture.index, commonContext.sourceColorTexture.index); + EXPECT_EQ(fromPassContext.depthTarget.index, commonContext.depthTarget.index); + EXPECT_EQ(fromPassContext.blackboard, commonContext.blackboard); + + EXPECT_EQ(fromFeatureContext.passName, commonContext.passName); + EXPECT_EQ(fromFeatureContext.sourceColorTexture.index, commonContext.sourceColorTexture.index); + EXPECT_EQ(fromFeatureContext.depthTarget.index, commonContext.depthTarget.index); + EXPECT_EQ(fromFeatureContext.blackboard, commonContext.blackboard); + + EXPECT_EQ(clonedFeatureContext.passName, XCEngine::Containers::String("Feature.Cloned")); + EXPECT_FALSE(clonedFeatureContext.clearAttachments); + EXPECT_EQ(clonedFeatureContext.sourceColorTexture.index, featureContext.sourceColorTexture.index); + EXPECT_EQ(clonedFeatureContext.blackboard, featureContext.blackboard); +}