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

@@ -181,7 +181,8 @@ bool CameraRenderer::Render(
return false;
}
if (plan.UsesGraphManagedOutputColor(CameraFrameStage::MainScene) &&
(m_pipeline == nullptr || !m_pipeline->SupportsMainSceneRenderGraph())) {
(m_pipeline == nullptr ||
!m_pipeline->SupportsStageRenderGraph(CameraFrameStage::MainScene))) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"CameraRenderer::Render failed: graph-managed main scene color requires pipeline main-scene render-graph support");

View File

@@ -48,26 +48,27 @@ bool TryRecordCameraFrameStageStandaloneRenderGraphPass(
return true;
}
bool TryRecordCameraFrameMainSceneGraphPass(
bool TryRecordCameraFramePipelineStageGraphPass(
const CameraFrameStageGraphBuildState& stageState,
const CameraFrameRenderGraphStageContext& context,
bool& handled) {
CameraFrameRenderGraphBuilderContext& builder = context.builder;
if (!SupportsCameraFramePipelineGraphRecording(stageState.stage) ||
builder.executionState.pipeline == nullptr ||
!builder.executionState.pipeline->SupportsMainSceneRenderGraph()) {
!builder.executionState.pipeline->SupportsStageRenderGraph(
stageState.stage)) {
handled = false;
return true;
}
handled = true;
if (!RecordCameraFrameMainSceneGraphPass(
if (!RecordCameraFramePipelineStageGraphPass(
context,
stageState,
*builder.executionState.pipeline)) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"CameraRenderer::Render failed: RenderPipeline::RecordMainSceneRenderGraph returned false");
"CameraRenderer::Render failed: RenderPipeline::RecordStageRenderGraph returned false");
return false;
}

View File

@@ -11,7 +11,7 @@ bool TryRecordCameraFrameStageStandaloneRenderGraphPass(
const CameraFrameRenderGraphStageContext& context,
bool& handled);
bool TryRecordCameraFrameMainSceneGraphPass(
bool TryRecordCameraFramePipelineStageGraphPass(
const CameraFrameStageGraphBuildState& stageState,
const CameraFrameRenderGraphStageContext& context,
bool& handled);

View File

@@ -554,22 +554,23 @@ RenderPassContext BuildCameraFrameStageFallbackPassContext(
};
}
RenderPipelineMainSceneRenderGraphContext BuildCameraFrameMainSceneStageRenderGraphContext(
RenderPipelineStageRenderGraphContext BuildCameraFramePipelineStageRenderGraphContext(
const CameraFrameRenderGraphStageContext& context,
const CameraFrameStageGraphBuildState& stageState) {
return BuildRenderPipelineMainSceneRenderGraphContext(
return BuildRenderPipelineStageRenderGraphContext(
BuildCameraFrameStageGraphRecordingContext(
context,
stageState,
context.sceneData));
context.sceneData),
stageState.stage);
}
bool RecordCameraFrameMainSceneGraphPass(
bool RecordCameraFramePipelineStageGraphPass(
const CameraFrameRenderGraphStageContext& context,
const CameraFrameStageGraphBuildState& stageState,
RenderPipelineRenderer& pipeline) {
return pipeline.RecordMainSceneRenderGraph(
BuildCameraFrameMainSceneStageRenderGraphContext(
return pipeline.RecordStageRenderGraph(
BuildCameraFramePipelineStageRenderGraphContext(
context,
stageState));
}

View File

@@ -146,11 +146,11 @@ RenderPassContext BuildCameraFrameStageFallbackPassContext(
const RenderContext& renderContext,
const RenderSceneData& sceneData);
RenderPipelineMainSceneRenderGraphContext BuildCameraFrameMainSceneStageRenderGraphContext(
RenderPipelineStageRenderGraphContext BuildCameraFramePipelineStageRenderGraphContext(
const CameraFrameRenderGraphStageContext& context,
const CameraFrameStageGraphBuildState& stageState);
bool RecordCameraFrameMainSceneGraphPass(
bool RecordCameraFramePipelineStageGraphPass(
const CameraFrameRenderGraphStageContext& context,
const CameraFrameStageGraphBuildState& stageState,
RenderPipelineRenderer& pipeline);

View File

@@ -20,7 +20,7 @@ using CameraFrameStageRecordHandler = bool (*)(
constexpr std::array<CameraFrameStageRecordHandler, 3u> kCameraFrameStageRecordHandlers = {
&TryRecordCameraFrameStageSequence,
&TryRecordCameraFrameStageStandaloneRenderGraphPass,
&TryRecordCameraFrameMainSceneGraphPass
&TryRecordCameraFramePipelineStageGraphPass
};
} // namespace

View File

@@ -36,7 +36,7 @@ bool ScenePhaseSamplesMainDirectionalShadow(ScenePhase scenePhase) {
bool BuiltinForwardMainSceneGraphBuilder::Record(
BuiltinForwardPipeline& pipeline,
const RenderPipelineMainSceneRenderGraphContext& context) {
const RenderPipelineStageRenderGraphContext& context) {
const RenderSurface graphManagedSurface =
BuildGraphManagedForwardSceneSurface(context.surfaceTemplate);
const bool hasSourceSurface = context.sourceSurface != nullptr;
@@ -58,8 +58,10 @@ bool BuiltinForwardMainSceneGraphBuilder::Record(
? frameResources->mainDirectionalShadow
: RenderGraphTextureHandle{};
bool* const executionSucceeded = recordingContext.executionSucceeded;
const RenderPipelineMainSceneRenderGraphContext graphContext =
BuildRenderPipelineMainSceneRenderGraphContext(recordingContext);
const RenderPipelineStageRenderGraphContext graphContext =
BuildRenderPipelineStageRenderGraphContext(
recordingContext,
CameraFrameStage::MainScene);
const std::shared_ptr<ForwardSceneGraphExecutionState> graphExecutionState =
std::make_shared<ForwardSceneGraphExecutionState>();
const SceneRenderFeaturePassBeginCallback beginRecordedPass =
@@ -76,7 +78,7 @@ bool BuiltinForwardMainSceneGraphBuilder::Record(
if (!pipeline.Initialize(passContext.renderContext)) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"BuiltinForwardPipeline::RecordMainSceneRenderGraph failed during execution: Initialize returned false");
"BuiltinForwardPipeline::RecordStageRenderGraph failed during execution: Initialize returned false");
if (executionSucceeded != nullptr) {
*executionSucceeded = false;
}
@@ -93,7 +95,7 @@ bool BuiltinForwardMainSceneGraphBuilder::Record(
if (!pipeline.m_forwardSceneFeatureHost.Prepare(executionContext)) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"BuiltinForwardPipeline::RecordMainSceneRenderGraph failed during execution: SceneRenderFeatureHost::Prepare returned false");
"BuiltinForwardPipeline::RecordStageRenderGraph failed during execution: SceneRenderFeatureHost::Prepare returned false");
if (executionSucceeded != nullptr) {
*executionSucceeded = false;
}
@@ -106,7 +108,7 @@ bool BuiltinForwardMainSceneGraphBuilder::Record(
if (!pipeline.BeginForwardScenePass(passContext, clearAttachments)) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
"BuiltinForwardPipeline::RecordMainSceneRenderGraph failed during execution: BeginForwardScenePass returned false");
"BuiltinForwardPipeline::RecordStageRenderGraph failed during execution: BeginForwardScenePass returned false");
if (executionSucceeded != nullptr) {
*executionSucceeded = false;
}
@@ -124,7 +126,7 @@ bool BuiltinForwardMainSceneGraphBuilder::Record(
for (const ForwardSceneStep& step : GetBuiltinForwardSceneSteps()) {
if (step.type == ForwardSceneStepType::InjectionPoint) {
bool recordedAnyPass = false;
if (!::XCEngine::Rendering::RecordRenderPipelineMainSceneFeaturePasses(
if (!::XCEngine::Rendering::RecordRenderPipelineStageFeaturePasses(
graphContext,
pipeline.m_forwardSceneFeatureHost,
step.injectionPoint,
@@ -150,7 +152,7 @@ bool BuiltinForwardMainSceneGraphBuilder::Record(
mainDirectionalShadowTexture.IsValid()
? std::vector<RenderGraphTextureHandle>{ mainDirectionalShadowTexture }
: std::vector<RenderGraphTextureHandle>{};
if (!::XCEngine::Rendering::RecordRenderPipelineMainScenePhasePass(
if (!::XCEngine::Rendering::RecordRenderPipelineStagePhasePass(
graphContext,
step.scenePhase,
[&pipeline, scenePhase = step.scenePhase](const RenderPassContext& passContext) {

View File

@@ -3,7 +3,7 @@
namespace XCEngine {
namespace Rendering {
struct RenderPipelineMainSceneRenderGraphContext;
struct RenderPipelineStageRenderGraphContext;
namespace Pipelines {
@@ -14,7 +14,7 @@ namespace Internal {
struct BuiltinForwardMainSceneGraphBuilder {
static bool Record(
BuiltinForwardPipeline& pipeline,
const RenderPipelineMainSceneRenderGraphContext& context);
const RenderPipelineStageRenderGraphContext& context);
};
} // namespace Internal

View File

@@ -59,13 +59,15 @@ bool BuiltinForwardPipeline::ShouldSampleMainDirectionalShadowMap(const RenderSc
IsDepthFormat(sceneData.lighting.mainDirectionalShadow.shadowMap->GetFormat());
}
bool BuiltinForwardPipeline::SupportsMainSceneRenderGraph() const {
return true;
bool BuiltinForwardPipeline::SupportsStageRenderGraph(
CameraFrameStage stage) const {
return SupportsCameraFramePipelineGraphRecording(stage);
}
bool BuiltinForwardPipeline::RecordMainSceneRenderGraph(
const RenderPipelineMainSceneRenderGraphContext& context) {
return Internal::BuiltinForwardMainSceneGraphBuilder::Record(*this, context);
bool BuiltinForwardPipeline::RecordStageRenderGraph(
const RenderPipelineStageRenderGraphContext& context) {
return context.stage == CameraFrameStage::MainScene &&
Internal::BuiltinForwardMainSceneGraphBuilder::Record(*this, context);
}
bool BuiltinForwardPipeline::Render(

View File

@@ -99,15 +99,16 @@ void ScriptableRenderPipelineHost::Shutdown() {
ShutdownCameraFrameStandalonePasses();
}
bool ScriptableRenderPipelineHost::SupportsMainSceneRenderGraph() const {
bool ScriptableRenderPipelineHost::SupportsStageRenderGraph(
CameraFrameStage stage) const {
return m_mainSceneRenderer != nullptr &&
m_mainSceneRenderer->SupportsMainSceneRenderGraph();
m_mainSceneRenderer->SupportsStageRenderGraph(stage);
}
bool ScriptableRenderPipelineHost::RecordMainSceneRenderGraph(
const RenderPipelineMainSceneRenderGraphContext& context) {
bool ScriptableRenderPipelineHost::RecordStageRenderGraph(
const RenderPipelineStageRenderGraphContext& context) {
return m_mainSceneRenderer != nullptr &&
m_mainSceneRenderer->RecordMainSceneRenderGraph(context);
m_mainSceneRenderer->RecordStageRenderGraph(context);
}
bool ScriptableRenderPipelineHost::Render(

View File

@@ -9,7 +9,7 @@
namespace XCEngine {
namespace Rendering {
Containers::String BuildRenderPipelineMainScenePhasePassName(
Containers::String BuildRenderPipelineStagePhasePassName(
const Containers::String& baseName,
ScenePhase scenePhase) {
std::string name = baseName.CStr();
@@ -21,8 +21,8 @@ Containers::String BuildRenderPipelineMainScenePhasePassName(
return Containers::String(name.c_str());
}
bool RecordRenderPipelineMainSceneFeaturePasses(
const RenderPipelineMainSceneRenderGraphContext& context,
bool RecordRenderPipelineStageFeaturePasses(
const RenderPipelineStageRenderGraphContext& context,
SceneRenderFeatureHost& featureHost,
SceneRenderInjectionPoint injectionPoint,
bool clearAttachments,
@@ -41,8 +41,8 @@ bool RecordRenderPipelineMainSceneFeaturePasses(
recordedAnyPass);
}
bool RecordRenderPipelineMainScenePhasePass(
const RenderPipelineMainSceneRenderGraphContext& context,
bool RecordRenderPipelineStagePhasePass(
const RenderPipelineStageRenderGraphContext& context,
ScenePhase scenePhase,
RenderPassGraphExecutePassCallback executePassCallback,
RenderPassGraphBeginCallback beginPassCallback,
@@ -52,7 +52,7 @@ bool RecordRenderPipelineMainScenePhasePass(
BuildRenderPassRenderGraphContext(
CloneRenderGraphRecordingContext(
BuildRenderGraphRecordingContext(context),
BuildRenderPipelineMainScenePhasePassName(
BuildRenderPipelineStagePhasePassName(
context.passName,
scenePhase)),
beginPassCallback,