Centralize render-graph recording context builders

This commit is contained in:
2026-04-15 01:18:15 +08:00
parent 65b3078c7f
commit d0ce2d7883
7 changed files with 331 additions and 67 deletions

View File

@@ -8,6 +8,7 @@
#include "Rendering/Execution/Internal/CameraFrameRenderGraphStageState.h"
#include "Rendering/Execution/Internal/CameraFrameRenderGraphSurfaceUtils.h"
#include "Rendering/Graph/RenderGraph.h"
#include "Rendering/Internal/RenderGraphRecordingContextBuilders.h"
namespace XCEngine {
namespace Rendering {
@@ -46,7 +47,7 @@ bool TryRecordCameraFrameStageStandaloneRenderGraphPass(
return true;
};
const RenderPassRenderGraphContext standalonePassContext = {
const Internal::RenderGraphRecordingContextCommon commonContext = {
session.graphBuilder,
stageState.stageName,
context.plan.request.context,
@@ -61,10 +62,12 @@ bool TryRecordCameraFrameStageStandaloneRenderGraphPass(
std::vector<RenderGraphTextureHandle>{ stageState.outputColor },
stageState.outputSurface.depthTexture,
&session.stageExecutionSucceeded,
beginStandalonePass,
{},
&session.blackboard
};
const RenderPassRenderGraphContext standalonePassContext =
Internal::BuildRenderPassRenderGraphContext(
commonContext,
beginStandalonePass);
if (!standaloneStagePass->RecordRenderGraph(standalonePassContext)) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,
@@ -89,7 +92,7 @@ bool TryRecordCameraFrameMainSceneGraphPass(
}
handled = true;
const RenderPipelineMainSceneRenderGraphContext mainSceneContext = {
const Internal::RenderGraphRecordingContextCommon commonContext = {
session.graphBuilder,
stageState.stageName,
context.plan.request.context,
@@ -100,11 +103,15 @@ bool TryRecordCameraFrameMainSceneGraphPass(
: nullptr,
stageState.sourceColorView,
stageState.sourceColorState,
GetPrimaryColorTexture(stageState.sourceSurface),
std::vector<RenderGraphTextureHandle>{ stageState.outputColor },
stageState.outputSurface.depthTexture,
&session.stageExecutionSucceeded,
&session.blackboard
};
const RenderPipelineMainSceneRenderGraphContext mainSceneContext =
Internal::BuildRenderPipelineMainSceneRenderGraphContext(
commonContext);
if (!session.executionState.pipeline->RecordMainSceneRenderGraph(mainSceneContext)) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,

View File

@@ -7,6 +7,7 @@
#include "Rendering/Execution/Internal/CameraFrameRenderGraphStageState.h"
#include "Rendering/Execution/Internal/CameraFrameRenderGraphSurfaceUtils.h"
#include "Rendering/Graph/RenderGraph.h"
#include "Rendering/Internal/RenderGraphRecordingContextBuilders.h"
#include "Rendering/Internal/RenderPassGraphUtils.h"
namespace XCEngine {
@@ -103,7 +104,7 @@ bool RecordRegularPassSequenceStage(
stageSequence->GetPassCount() == 1u
? stageName
: BuildRenderGraphSequencePassName(stageName, passIndex);
const RenderPassRenderGraphContext passContext = {
const Internal::RenderGraphRecordingContextCommon commonContext = {
graphBuilder,
passName,
stagePassContext.renderContext,
@@ -116,10 +117,12 @@ bool RecordRegularPassSequenceStage(
outputSurface.colorTextures,
outputSurface.depthTexture,
&stageExecutionSucceeded,
beginSequencePass,
{},
&blackboard
};
const RenderPassRenderGraphContext passContext =
Internal::BuildRenderPassRenderGraphContext(
commonContext,
beginSequencePass);
if (!RecordSequencePass(
*pass,
passContext,
@@ -206,7 +209,7 @@ bool RecordFullscreenPassSequenceStage(
passIndex == 0u
? binding.sourceColorState
: RHI::ResourceStates::PixelShaderResource;
const RenderPassRenderGraphContext passContext = {
const Internal::RenderGraphRecordingContextCommon commonContext = {
graphBuilder,
passName,
stagePassContext.renderContext,
@@ -219,10 +222,12 @@ bool RecordFullscreenPassSequenceStage(
std::vector<RenderGraphTextureHandle>{ passOutputColor },
{},
&stageExecutionSucceeded,
beginSequencePass,
{},
&blackboard
};
const RenderPassRenderGraphContext passContext =
Internal::BuildRenderPassRenderGraphContext(
commonContext,
beginSequencePass);
if (!RecordSequencePass(
*pass,
passContext,

View File

@@ -0,0 +1,118 @@
#pragma once
#include <XCEngine/Rendering/RenderPipeline.h>
#include <XCEngine/Rendering/SceneRenderFeaturePass.h>
namespace XCEngine {
namespace Rendering {
namespace Internal {
struct RenderGraphRecordingContextCommon {
RenderGraphBuilder& graphBuilder;
Containers::String passName = {};
const RenderContext& renderContext;
const RenderSceneData& sceneData;
RenderSurface surface = {};
const RenderSurface* sourceSurface = nullptr;
RHI::RHIResourceView* sourceColorView = nullptr;
RHI::ResourceStates sourceColorState = RHI::ResourceStates::Common;
RenderGraphTextureHandle sourceColorTexture = {};
std::vector<RenderGraphTextureHandle> colorTargets = {};
RenderGraphTextureHandle depthTarget = {};
bool* executionSucceeded = nullptr;
RenderGraphBlackboard* blackboard = nullptr;
};
inline RenderPassRenderGraphContext BuildRenderPassRenderGraphContext(
const RenderGraphRecordingContextCommon& common,
RenderPassGraphBeginCallback beginPassCallback = {},
RenderPassGraphEndCallback endPassCallback = {}) {
return {
common.graphBuilder,
common.passName,
common.renderContext,
common.sceneData,
common.surface,
common.sourceSurface,
common.sourceColorView,
common.sourceColorState,
common.sourceColorTexture,
common.colorTargets,
common.depthTarget,
common.executionSucceeded,
beginPassCallback,
endPassCallback,
common.blackboard
};
}
inline SceneRenderFeaturePassRenderGraphContext BuildSceneRenderFeaturePassRenderGraphContext(
const RenderGraphRecordingContextCommon& common,
bool clearAttachments = false,
SceneRenderFeaturePassBeginCallback beginPassCallback = {},
SceneRenderFeaturePassEndCallback endPassCallback = {}) {
return {
common.graphBuilder,
common.passName,
common.renderContext,
common.sceneData,
common.surface,
common.sourceSurface,
common.sourceColorView,
common.sourceColorState,
common.sourceColorTexture,
common.colorTargets,
common.depthTarget,
clearAttachments,
common.executionSucceeded,
beginPassCallback,
endPassCallback,
common.blackboard
};
}
inline RenderPipelineMainSceneRenderGraphContext BuildRenderPipelineMainSceneRenderGraphContext(
const RenderGraphRecordingContextCommon& common) {
return {
common.graphBuilder,
common.passName,
common.renderContext,
common.sceneData,
common.surface,
common.sourceSurface,
common.sourceColorView,
common.sourceColorState,
common.colorTargets,
common.depthTarget,
common.executionSucceeded,
common.blackboard
};
}
inline SceneRenderFeaturePassRenderGraphContext CloneSceneRenderFeaturePassRenderGraphContext(
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,
clearAttachments,
context.executionSucceeded,
context.beginPassCallback,
context.endPassCallback,
context.blackboard
};
}
} // namespace Internal
} // namespace Rendering
} // namespace XCEngine

View File

@@ -3,6 +3,7 @@
#include "Debug/Logger.h"
#include "Rendering/Graph/RenderGraph.h"
#include "Rendering/Internal/RenderPassGraphUtils.h"
#include "Rendering/Internal/RenderGraphRecordingContextBuilders.h"
#include "Rendering/Pipelines/BuiltinForwardPipeline.h"
#include "Rendering/Pipelines/Internal/BuiltinForwardSceneSetup.h"
#include "Rendering/RenderSurface.h"
@@ -131,28 +132,31 @@ bool BuiltinForwardMainSceneGraphBuilder::Record(
[&pipeline](const RenderPassContext& passContext) {
pipeline.EndForwardScenePass(passContext);
};
const ::XCEngine::Rendering::Internal::RenderGraphRecordingContextCommon commonContext = {
context.graphBuilder,
passName,
renderContext,
*sceneData,
surfaceTemplate,
hasSourceSurface ? &sourceSurface : nullptr,
sourceColorView,
sourceColorState,
{},
colorTargets,
depthTarget,
executionSucceeded,
context.blackboard
};
bool clearAttachments = true;
for (const ForwardSceneStep& step : GetBuiltinForwardSceneSteps()) {
if (step.type == ForwardSceneStepType::InjectionPoint) {
const SceneRenderFeaturePassRenderGraphContext featureContext = {
context.graphBuilder,
passName,
renderContext,
*sceneData,
surfaceTemplate,
hasSourceSurface ? &sourceSurface : nullptr,
sourceColorView,
sourceColorState,
{},
colorTargets,
depthTarget,
clearAttachments,
executionSucceeded,
beginRecordedPass,
endRecordedPass,
context.blackboard
};
const SceneRenderFeaturePassRenderGraphContext featureContext =
::XCEngine::Rendering::Internal::BuildSceneRenderFeaturePassRenderGraphContext(
commonContext,
clearAttachments,
beginRecordedPass,
endRecordedPass);
bool recordedAnyPass = false;
if (!pipeline.m_forwardSceneFeatureHost.Record(
featureContext,
@@ -178,23 +182,13 @@ bool BuiltinForwardMainSceneGraphBuilder::Record(
mainDirectionalShadowTexture.IsValid()
? std::vector<RenderGraphTextureHandle>{ mainDirectionalShadowTexture }
: std::vector<RenderGraphTextureHandle>{};
const RenderPassRenderGraphContext phaseContext = {
context.graphBuilder,
phasePassName,
renderContext,
*sceneData,
surfaceTemplate,
hasSourceSurface ? &sourceSurface : nullptr,
sourceColorView,
sourceColorState,
{},
colorTargets,
depthTarget,
executionSucceeded,
beginPhasePass,
endRecordedPass,
context.blackboard
};
::XCEngine::Rendering::Internal::RenderGraphRecordingContextCommon phaseCommonContext = commonContext;
phaseCommonContext.passName = phasePassName;
const RenderPassRenderGraphContext phaseContext =
::XCEngine::Rendering::Internal::BuildRenderPassRenderGraphContext(
phaseCommonContext,
beginPhasePass,
endRecordedPass);
if (!::XCEngine::Rendering::Internal::RecordCallbackRasterRenderPass(
phaseContext,
{

View File

@@ -1,6 +1,7 @@
#include "Rendering/SceneRenderFeatureHost.h"
#include "Debug/Logger.h"
#include "Rendering/Internal/RenderGraphRecordingContextBuilders.h"
#include <string>
@@ -118,28 +119,15 @@ bool SceneRenderFeatureHost::Record(
continue;
}
const SceneRenderFeaturePassRenderGraphContext featureContext = {
context.graphBuilder,
BuildFeatureGraphPassName(
context.passName,
injectionPoint,
*featurePass,
featureIndex),
context.renderContext,
context.sceneData,
context.surface,
context.sourceSurface,
context.sourceColorView,
context.sourceColorState,
context.sourceColorTexture,
context.colorTargets,
context.depthTarget,
clearAttachments,
context.executionSucceeded,
context.beginPassCallback,
context.endPassCallback,
context.blackboard
};
const SceneRenderFeaturePassRenderGraphContext featureContext =
Internal::CloneSceneRenderFeaturePassRenderGraphContext(
context,
BuildFeatureGraphPassName(
context.passName,
injectionPoint,
*featurePass,
featureIndex),
clearAttachments);
if (!featurePass->RecordRenderGraph(featureContext)) {
Debug::Logger::Get().Error(
Debug::LogCategory::Rendering,