Graph-ify forward feature injection points

This commit is contained in:
2026-04-14 16:49:06 +08:00
parent a4c48c1b3f
commit 2a9264cfe4
9 changed files with 861 additions and 119 deletions

View File

@@ -0,0 +1,99 @@
#include "Rendering/SceneRenderFeaturePass.h"
#include "Rendering/Graph/RenderGraph.h"
namespace XCEngine {
namespace Rendering {
bool SceneRenderFeaturePass::RecordRenderGraph(
const SceneRenderFeaturePassRenderGraphContext& context) {
SceneRenderFeaturePass* const featurePass = this;
const Containers::String passName = context.passName;
const RenderContext* const renderContext = &context.renderContext;
const RenderSceneData* const sceneData = &context.sceneData;
const RenderSurface surface = context.surface;
const RenderSurface* const sourceSurface = context.sourceSurface;
RHI::RHIResourceView* const sourceColorView = context.sourceColorView;
const RHI::ResourceStates sourceColorState = context.sourceColorState;
const std::vector<RenderGraphTextureHandle> colorTargets = context.colorTargets;
const RenderGraphTextureHandle depthTarget = context.depthTarget;
const bool clearAttachments = context.clearAttachments;
bool* const executionSucceeded = context.executionSucceeded;
const SceneRenderFeaturePassBeginCallback beginPassCallback = context.beginPassCallback;
const SceneRenderFeaturePassEndCallback endPassCallback = context.endPassCallback;
context.graphBuilder.AddRasterPass(
passName,
[featurePass,
renderContext,
sceneData,
surface,
sourceSurface,
sourceColorView,
sourceColorState,
colorTargets,
depthTarget,
clearAttachments,
executionSucceeded,
beginPassCallback,
endPassCallback](
RenderGraphPassBuilder& passBuilder) {
for (RenderGraphTextureHandle colorTarget : colorTargets) {
if (colorTarget.IsValid()) {
passBuilder.WriteTexture(colorTarget);
}
}
if (depthTarget.IsValid()) {
passBuilder.WriteDepthTexture(depthTarget);
}
passBuilder.SetExecuteCallback(
[featurePass,
renderContext,
sceneData,
surface,
sourceSurface,
sourceColorView,
sourceColorState,
clearAttachments,
executionSucceeded,
beginPassCallback,
endPassCallback](
const RenderGraphExecutionContext&) {
if (executionSucceeded != nullptr && !(*executionSucceeded)) {
return;
}
const FrameExecutionContext executionContext(
*renderContext,
surface,
*sceneData,
sourceSurface,
sourceColorView,
sourceColorState);
const RenderPassContext passContext =
BuildRenderPassContext(executionContext);
if (beginPassCallback &&
!beginPassCallback(passContext, clearAttachments)) {
if (executionSucceeded != nullptr) {
*executionSucceeded = false;
}
return;
}
const bool executeResult = featurePass->Execute(passContext);
if (endPassCallback) {
endPassCallback(passContext);
}
if (executionSucceeded != nullptr) {
*executionSucceeded = executeResult;
}
});
});
return true;
}
} // namespace Rendering
} // namespace XCEngine