Extract camera frame render-graph stage policy helpers

This commit is contained in:
2026-04-14 22:17:12 +08:00
parent a02ff65651
commit a67f8597ba
4 changed files with 257 additions and 103 deletions

View File

@@ -1,6 +1,7 @@
#include "Rendering/Execution/CameraRenderer.h"
#include "Components/CameraComponent.h"
#include "Rendering/Execution/CameraFrameRenderGraphStagePolicy.h"
#include "Rendering/Execution/DirectionalShadowExecutionState.h"
#include "Rendering/Graph/RenderGraph.h"
#include "Rendering/Graph/RenderGraphCompiler.h"
@@ -256,12 +257,6 @@ void WriteRenderGraphColorSurface(
}
}
bool IsFullscreenSequenceStage(
CameraFrameStage stage) {
return stage == CameraFrameStage::PostProcess ||
stage == CameraFrameStage::FinalOutput;
}
Containers::String BuildRenderGraphSequencePassName(
const Containers::String& stageName,
size_t passIndex) {
@@ -530,14 +525,6 @@ RenderSurface BuildGraphManagedPassSurface(
return surface;
}
struct FullscreenStageGraphBinding {
const RenderSurface* sourceSurfaceTemplate = nullptr;
RHI::RHIResourceView* sourceColorView = nullptr;
RHI::ResourceStates sourceColorState = RHI::ResourceStates::Common;
RenderGraphTextureHandle sourceColor = {};
RenderGraphTextureHandle outputColor = {};
};
const RenderSurface* ResolveFrameStageOutputSurface(
CameraFrameStage stage,
const CameraFramePlan& plan,
@@ -560,22 +547,6 @@ const RenderSurface* ResolveFrameStageOutputSurface(
}
}
bool ShouldGraphOwnStageColorTransitions(
CameraFrameStage stage) {
return stage == CameraFrameStage::MainScene ||
stage == CameraFrameStage::PostProcess ||
stage == CameraFrameStage::FinalOutput ||
stage == CameraFrameStage::ObjectId;
}
bool ShouldGraphOwnStageDepthTransitions(
CameraFrameStage stage) {
return stage == CameraFrameStage::ShadowCaster ||
stage == CameraFrameStage::DepthOnly ||
stage == CameraFrameStage::MainScene ||
stage == CameraFrameStage::ObjectId;
}
bool CanUseGraphManagedImportedSurface(
const RenderGraphImportedSurface& surface,
const RenderGraphExecutionContext& graphContext) {
@@ -609,69 +580,24 @@ RenderGraphTextureHandle ResolveStageOutputColorHandle(
const RenderPassContext& stagePassContext,
const RenderGraphImportedSurface& outputSurface,
RenderGraphBuilder& graphBuilder) {
if (stage == CameraFrameStage::MainScene &&
plan.usesGraphManagedMainSceneColor) {
return graphBuilder.CreateTransientTexture(
stageName + ".Color",
BuildImportedTextureDesc(
stagePassContext.surface,
kRenderGraphImportedColorFormat));
}
if (stage == CameraFrameStage::PostProcess &&
plan.usesGraphManagedPostProcessColor) {
return graphBuilder.CreateTransientTexture(
stageName + ".Color",
BuildFullscreenTransientTextureDesc(stagePassContext.surface));
}
return GetPrimaryColorTexture(outputSurface);
}
FullscreenStageGraphBinding ResolveFullscreenStageGraphBinding(
CameraFrameStage stage,
const CameraFramePlan& plan,
const RenderPassContext& stagePassContext,
const RenderGraphImportedSurface& sourceSurface,
RenderGraphTextureHandle outputColor,
const RenderGraphBlackboard* blackboard) {
FullscreenStageGraphBinding binding = {};
binding.sourceSurfaceTemplate = stagePassContext.sourceSurface;
binding.sourceColorView = stagePassContext.sourceColorView;
binding.sourceColorState = stagePassContext.sourceColorState;
binding.sourceColor = GetPrimaryColorTexture(sourceSurface);
binding.outputColor = outputColor;
if (stage == CameraFrameStage::PostProcess &&
plan.postProcessSource == CameraFrameColorSource::MainSceneColor) {
binding.sourceSurfaceTemplate = &stagePassContext.surface;
binding.sourceColorView = nullptr;
binding.sourceColorState = RHI::ResourceStates::PixelShaderResource;
binding.sourceColor =
ResolveCameraFrameRenderGraphColorSource(
blackboard,
plan.postProcessSource);
}
if (stage == CameraFrameStage::FinalOutput) {
if (plan.finalOutputSource == CameraFrameColorSource::MainSceneColor ||
plan.finalOutputSource == CameraFrameColorSource::PostProcessColor) {
binding.sourceSurfaceTemplate = &stagePassContext.surface;
binding.sourceColorView = nullptr;
binding.sourceColorState = RHI::ResourceStates::PixelShaderResource;
binding.sourceColor =
ResolveCameraFrameRenderGraphColorSource(
blackboard,
plan.finalOutputSource);
if (UsesCameraFrameStageGraphManagedOutputColor(plan, stage)) {
switch (stage) {
case CameraFrameStage::MainScene:
return graphBuilder.CreateTransientTexture(
stageName + ".Color",
BuildImportedTextureDesc(
stagePassContext.surface,
kRenderGraphImportedColorFormat));
case CameraFrameStage::PostProcess:
return graphBuilder.CreateTransientTexture(
stageName + ".Color",
BuildFullscreenTransientTextureDesc(stagePassContext.surface));
default:
break;
}
}
if (binding.sourceSurfaceTemplate == nullptr &&
binding.sourceColor.IsValid()) {
binding.sourceSurfaceTemplate = &stagePassContext.surface;
}
return binding;
return GetPrimaryColorTexture(outputSurface);
}
RenderPassContext BuildFrameStagePassContext(
@@ -816,7 +742,8 @@ bool RecordFullscreenPassSequenceStage(
CameraFrameStage stage,
const Containers::String& stageName,
const RenderPassContext& stagePassContext,
const FullscreenStageGraphBinding& binding,
const CameraFrameRenderGraphSourceBinding& binding,
RenderGraphTextureHandle finalOutputColor,
const RenderSceneData& sceneData,
RenderPassSequence* stageSequence,
CameraFrameExecutionState& executionState,
@@ -846,7 +773,6 @@ bool RecordFullscreenPassSequenceStage(
};
RenderGraphTextureHandle currentSourceColor = binding.sourceColor;
const RenderGraphTextureHandle finalOutputColor = binding.outputColor;
const RenderGraphTextureDesc transientDesc =
BuildFullscreenTransientTextureDesc(stagePassContext.surface);
@@ -945,7 +871,7 @@ bool ExecuteRenderGraphPlan(
stageName + ".Source",
stagePassContext.sourceSurface,
RenderGraphSurfaceImportUsage::Source,
IsFullscreenSequenceStage(stage));
IsCameraFrameFullscreenSequenceStage(stage));
const RenderGraphImportedSurface outputSurface =
ImportRenderGraphSurface(
graphBuilder,
@@ -953,8 +879,8 @@ bool ExecuteRenderGraphPlan(
stageName + ".Output",
&stagePassContext.surface,
RenderGraphSurfaceImportUsage::Output,
ShouldGraphOwnStageColorTransitions(stage),
ShouldGraphOwnStageDepthTransitions(stage));
DoesCameraFrameStageGraphOwnColorTransitions(stage),
DoesCameraFrameStageGraphOwnDepthTransitions(stage));
const RenderGraphTextureHandle stageOutputColor =
ResolveStageOutputColorHandle(
stage,
@@ -984,18 +910,21 @@ bool ExecuteRenderGraphPlan(
if (stageSequence != nullptr) {
const bool recordResult =
IsFullscreenSequenceStage(stage)
IsCameraFrameFullscreenSequenceStage(stage)
? RecordFullscreenPassSequenceStage(
stage,
stageName,
stagePassContext,
ResolveFullscreenStageGraphBinding(
stage,
ResolveCameraFrameFullscreenStageGraphSourceBinding(
plan,
stagePassContext,
sourceSurface,
stageOutputColor,
stage,
stagePassContext.surface,
stagePassContext.sourceSurface,
stagePassContext.sourceColorView,
stagePassContext.sourceColorState,
GetPrimaryColorTexture(sourceSurface),
&blackboard),
stageOutputColor,
sceneData,
stageSequence,
executionState,
@@ -1103,7 +1032,7 @@ bool ExecuteRenderGraphPlan(
stageName,
[&, sourceSurface, outputSurface, stage, stageSurfaceTemplate, hasStageSourceSurface, stageSourceSurfaceTemplate, stageSourceColorView, stageSourceColorState](
RenderGraphPassBuilder& passBuilder) {
if (IsFullscreenSequenceStage(stage)) {
if (IsCameraFrameFullscreenSequenceStage(stage)) {
ReadRenderGraphColorSurface(passBuilder, sourceSurface);
WriteRenderGraphColorSurface(passBuilder, outputSurface);
} else {
@@ -1125,7 +1054,7 @@ bool ExecuteRenderGraphPlan(
const_cast<RHI::RHIResourceView*>(stageSourceColorView);
RHI::ResourceStates resolvedSourceColorState = stageSourceColorState;
RenderSurface graphManagedSourceSurface = {};
if (IsFullscreenSequenceStage(stage) &&
if (IsCameraFrameFullscreenSequenceStage(stage) &&
hasStageSourceSurface &&
CanUseGraphManagedImportedSurface(sourceSurface, executionContext)) {
graphManagedSourceSurface =