Harden render graph pass capture and feature source-color contract

This commit is contained in:
2026-04-14 21:11:04 +08:00
parent 1d171ea61c
commit 9980aa9be5
6 changed files with 204 additions and 102 deletions

View File

@@ -1,98 +1,62 @@
#include "Rendering/SceneRenderFeaturePass.h"
#include "Rendering/Graph/RenderGraph.h"
#include "Rendering/Internal/RenderPassGraphUtils.h"
#include <algorithm>
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;
}
});
const bool usesSourceColor = context.sourceColorTexture.IsValid();
const bool hasSourceSurfaceTemplate =
context.sourceSurface != nullptr || usesSourceColor;
const RenderSurface sourceSurfaceTemplate =
context.sourceSurface != nullptr
? *context.sourceSurface
: (usesSourceColor ? context.surface : RenderSurface());
const bool writesColor =
std::any_of(
context.colorTargets.begin(),
context.colorTargets.end(),
[](RenderGraphTextureHandle handle) {
return handle.IsValid();
});
const RenderPassGraphBeginCallback beginPassCallback =
context.beginPassCallback
? RenderPassGraphBeginCallback(
[beginPass = context.beginPassCallback,
clearAttachments = context.clearAttachments](
const RenderPassContext& passContext) {
return beginPass(passContext, clearAttachments);
})
: RenderPassGraphBeginCallback();
const RenderPassRenderGraphContext passContext = {
context.graphBuilder,
context.passName,
context.renderContext,
context.sceneData,
context.surface,
hasSourceSurfaceTemplate ? &sourceSurfaceTemplate : nullptr,
context.sourceColorView,
context.sourceColorState,
context.sourceColorTexture,
context.colorTargets,
context.depthTarget,
context.executionSucceeded,
beginPassCallback,
context.endPassCallback,
context.blackboard
};
return Internal::RecordRasterRenderPass(
*this,
passContext,
{
usesSourceColor,
writesColor,
context.depthTarget.IsValid()
});
return true;
}
} // namespace Rendering