refactor(rendering): generalize pipeline stage render graph boundary

This commit is contained in:
2026-04-15 19:31:52 +08:00
parent df8f433fbb
commit 7671663b12
20 changed files with 108 additions and 84 deletions

View File

@@ -577,7 +577,7 @@ TEST(BuiltinForwardPipeline_Test, UsesFloat3PositionInputLayoutForStaticMeshVert
TEST(BuiltinForwardPipeline_Test, RecordsMainSceneGraphPassWithSampledShadowDependency) {
BuiltinForwardPipeline pipeline;
EXPECT_TRUE(pipeline.SupportsMainSceneRenderGraph());
EXPECT_TRUE(pipeline.SupportsStageRenderGraph(CameraFrameStage::MainScene));
RenderGraph graph = {};
RenderGraphBuilder graphBuilder(graph);
@@ -634,9 +634,10 @@ TEST(BuiltinForwardPipeline_Test, RecordsMainSceneGraphPassWithSampledShadowDepe
frameResources.mainScene.depth = depthTarget;
frameResources.mainDirectionalShadow = shadowTarget;
bool executionSucceeded = true;
const RenderPipelineMainSceneRenderGraphContext context = {
const RenderPipelineStageRenderGraphContext context = {
graphBuilder,
"MainScene",
CameraFrameStage::MainScene,
renderContext,
sceneData,
surface,
@@ -650,7 +651,7 @@ TEST(BuiltinForwardPipeline_Test, RecordsMainSceneGraphPassWithSampledShadowDepe
&blackboard
};
ASSERT_TRUE(pipeline.RecordMainSceneRenderGraph(context));
ASSERT_TRUE(pipeline.RecordStageRenderGraph(context));
CompiledRenderGraph compiledGraph = {};
String errorMessage;
@@ -1173,9 +1174,10 @@ TEST(BuiltinForwardPipeline_Test, RecordsActiveFeatureInjectionPassesIntoMainSce
frameResources.mainScene.color = colorTarget;
frameResources.mainScene.depth = depthTarget;
bool executionSucceeded = true;
const RenderPipelineMainSceneRenderGraphContext context = {
const RenderPipelineStageRenderGraphContext context = {
graphBuilder,
"MainScene",
CameraFrameStage::MainScene,
renderContext,
sceneData,
surface,
@@ -1189,7 +1191,7 @@ TEST(BuiltinForwardPipeline_Test, RecordsActiveFeatureInjectionPassesIntoMainSce
&blackboard
};
ASSERT_TRUE(pipeline.RecordMainSceneRenderGraph(context));
ASSERT_TRUE(pipeline.RecordStageRenderGraph(context));
CompiledRenderGraph compiledGraph = {};
String errorMessage;
@@ -1272,9 +1274,10 @@ TEST(BuiltinForwardPipeline_Test, ForwardsSourceColorTextureIntoFeatureInjection
RenderSceneData sceneData = {};
RenderGraphBlackboard blackboard = {};
bool executionSucceeded = true;
const RenderPipelineMainSceneRenderGraphContext context = {
const RenderPipelineStageRenderGraphContext context = {
graphBuilder,
"MainScene",
CameraFrameStage::MainScene,
renderContext,
sceneData,
surface,
@@ -1288,7 +1291,7 @@ TEST(BuiltinForwardPipeline_Test, ForwardsSourceColorTextureIntoFeatureInjection
&blackboard
};
ASSERT_TRUE(pipeline.RecordMainSceneRenderGraph(context));
ASSERT_TRUE(pipeline.RecordStageRenderGraph(context));
EXPECT_EQ(featureRaw->recordGraphCallCount, 1u);
EXPECT_TRUE(featureRaw->lastReceivedSourceColorTextureValid);

View File

@@ -100,14 +100,15 @@ public:
ShutdownCameraFrameStandalonePasses();
}
bool SupportsMainSceneRenderGraph() const override {
return true;
bool SupportsStageRenderGraph(CameraFrameStage stage) const override {
return SupportsCameraFramePipelineGraphRecording(stage);
}
bool RecordMainSceneRenderGraph(
const RenderPipelineMainSceneRenderGraphContext& context) override {
bool RecordStageRenderGraph(
const RenderPipelineStageRenderGraphContext& context) override {
++recordCalls;
lastPassName = context.passName.CStr();
lastStage = context.stage;
lastColorTargets = context.colorTargets;
lastDepthTarget = context.depthTarget;
lastExecutionSucceeded = context.executionSucceeded;
@@ -139,6 +140,7 @@ public:
int recordCalls = 0;
int renderCalls = 0;
std::string lastPassName = {};
CameraFrameStage lastStage = CameraFrameStage::PreScenePasses;
std::vector<RenderGraphTextureHandle> lastColorTargets = {};
RenderGraphTextureHandle lastDepthTarget = {};
bool* lastExecutionSucceeded = nullptr;
@@ -813,12 +815,13 @@ TEST(CameraFrameRenderGraphStageContract_Test, RecordsMainSceneGraphPassFromStag
stageState.outputSurface.depthTexture = RenderGraphTextureHandle{ 43u };
RecordingPipeline pipeline = {};
ASSERT_TRUE(RecordCameraFrameMainSceneGraphPass(
ASSERT_TRUE(RecordCameraFramePipelineStageGraphPass(
context,
stageState,
pipeline));
ASSERT_EQ(pipeline.recordCalls, 1);
EXPECT_STREQ(pipeline.lastPassName.c_str(), "MainScene");
EXPECT_EQ(pipeline.lastStage, CameraFrameStage::MainScene);
ASSERT_EQ(pipeline.lastColorTargets.size(), 1u);
EXPECT_EQ(pipeline.lastColorTargets[0].index, 41u);
EXPECT_EQ(pipeline.lastDepthTarget.index, 43u);

View File

@@ -432,12 +432,13 @@ public:
ShutdownCameraFrameStandalonePasses();
}
bool SupportsMainSceneRenderGraph() const override {
return m_state->supportsMainSceneRenderGraph;
bool SupportsStageRenderGraph(CameraFrameStage stage) const override {
return SupportsCameraFramePipelineGraphRecording(stage) &&
m_state->supportsMainSceneRenderGraph;
}
bool RecordMainSceneRenderGraph(
const RenderPipelineMainSceneRenderGraphContext& context) override {
bool RecordStageRenderGraph(
const RenderPipelineStageRenderGraphContext& context) override {
++m_state->recordMainSceneCalls;
m_state->lastReceivedRenderGraphBlackboard = context.blackboard != nullptr;
if (const CameraFrameRenderGraphResources* frameResources =
@@ -3729,9 +3730,10 @@ TEST(ScriptableRenderPipelineHost_Test, ForwardsRendererLifetimeAndFrameRenderin
bool executionSucceeded = true;
RenderSceneData graphSceneData =
CreateSceneDataForCamera(scene, *camera, request.surface);
const RenderPipelineMainSceneRenderGraphContext graphContext = {
const RenderPipelineStageRenderGraphContext graphContext = {
graphBuilder,
"MainScene",
CameraFrameStage::MainScene,
request.context,
graphSceneData,
request.surface,
@@ -3744,8 +3746,8 @@ TEST(ScriptableRenderPipelineHost_Test, ForwardsRendererLifetimeAndFrameRenderin
&executionSucceeded,
&blackboard
};
EXPECT_TRUE(host.SupportsMainSceneRenderGraph());
EXPECT_TRUE(host.RecordMainSceneRenderGraph(graphContext));
EXPECT_TRUE(host.SupportsStageRenderGraph(CameraFrameStage::MainScene));
EXPECT_TRUE(host.RecordStageRenderGraph(graphContext));
EXPECT_EQ(replacementState->recordMainSceneCalls, 1);
}

View File

@@ -295,7 +295,7 @@ TEST(RenderGraphRecordingContext_Test, BuildsFeaturePassContextAndCloneOverrides
EXPECT_TRUE(endCalled);
}
TEST(RenderGraphRecordingContext_Test, BuildsPipelineMainSceneContextFromSharedRecordingData) {
TEST(RenderGraphRecordingContext_Test, BuildsPipelineStageContextFromSharedRecordingData) {
RenderGraph graph = {};
RenderGraphBuilder builder(graph);
RenderGraphBlackboard blackboard = {};
@@ -314,11 +314,14 @@ TEST(RenderGraphRecordingContext_Test, BuildsPipelineMainSceneContextFromSharedR
sourceSurface,
executionSucceeded);
const RenderPipelineMainSceneRenderGraphContext pipelineContext =
BuildRenderPipelineMainSceneRenderGraphContext(commonContext);
const RenderPipelineStageRenderGraphContext pipelineContext =
BuildRenderPipelineStageRenderGraphContext(
commonContext,
CameraFrameStage::MainScene);
EXPECT_EQ(&pipelineContext.graphBuilder, &builder);
EXPECT_EQ(pipelineContext.passName, XCEngine::Containers::String("Recording.Pass"));
EXPECT_EQ(pipelineContext.stage, CameraFrameStage::MainScene);
EXPECT_EQ(&pipelineContext.renderContext, &renderContext);
EXPECT_EQ(&pipelineContext.sceneData, &sceneData);
EXPECT_EQ(pipelineContext.surfaceTemplate.GetWidth(), 800u);
@@ -390,7 +393,7 @@ TEST(RenderGraphRecordingContext_Test, CloneOverridesSelectedRecordingContextFie
EXPECT_EQ(overriddenContext.blackboard, &blackboard);
}
TEST(RenderGraphRecordingContext_Test, BuildsSharedRecordingDataFromPipelineMainSceneContext) {
TEST(RenderGraphRecordingContext_Test, BuildsSharedRecordingDataFromPipelineStageContext) {
RenderGraph graph = {};
RenderGraphBuilder builder(graph);
RenderGraphBlackboard blackboard = {};
@@ -408,8 +411,10 @@ TEST(RenderGraphRecordingContext_Test, BuildsSharedRecordingDataFromPipelineMain
surface,
sourceSurface,
executionSucceeded);
const RenderPipelineMainSceneRenderGraphContext pipelineContext =
BuildRenderPipelineMainSceneRenderGraphContext(commonContext);
const RenderPipelineStageRenderGraphContext pipelineContext =
BuildRenderPipelineStageRenderGraphContext(
commonContext,
CameraFrameStage::MainScene);
const RenderGraphRecordingContext rebuiltCommonContext =
BuildRenderGraphRecordingContext(pipelineContext);