refactor(rendering): formalize native graph recording helpers

This commit is contained in:
2026-04-15 20:46:00 +08:00
parent 7b9e172dbf
commit 8798e63e32
7 changed files with 258 additions and 42 deletions

View File

@@ -3,6 +3,8 @@
#include <XCEngine/Rendering/RenderPipeline.h>
#include <XCEngine/Rendering/SceneRenderFeaturePass.h>
#include <utility>
namespace XCEngine {
namespace Rendering {
@@ -39,6 +41,73 @@ struct RenderGraphRecordingContextOverrides {
RenderGraphTextureHandle depthTarget = {};
};
struct RenderGraphRecordingSourceBinding {
const RenderSurface* sourceSurface = nullptr;
RHI::RHIResourceView* sourceColorView = nullptr;
RHI::ResourceStates sourceColorState = RHI::ResourceStates::Common;
RenderGraphTextureHandle sourceColorTexture = {};
};
inline RenderGraphRecordingSourceBinding MakeRenderGraphRecordingSourceBinding(
const RenderSurface* sourceSurface = nullptr,
RHI::RHIResourceView* sourceColorView = nullptr,
RHI::ResourceStates sourceColorState = RHI::ResourceStates::Common,
RenderGraphTextureHandle sourceColorTexture = {}) {
return {
sourceSurface,
sourceColorView,
sourceColorState,
sourceColorTexture
};
}
inline RenderGraphRecordingSourceBinding BuildRenderGraphRecordingSourceBinding(
const RenderGraphRecordingContext& context) {
return MakeRenderGraphRecordingSourceBinding(
context.sourceSurface,
context.sourceColorView,
context.sourceColorState,
context.sourceColorTexture);
}
inline RenderGraphRecordingSourceBinding ResolveRenderGraphRecordingSourceBinding(
const RenderGraphRecordingContext& context,
const RenderSurface* fallbackSourceSurfaceTemplate,
RenderSurface* resolvedSourceSurfaceStorage = nullptr) {
RenderGraphRecordingSourceBinding binding =
BuildRenderGraphRecordingSourceBinding(context);
if (binding.sourceSurface == nullptr &&
fallbackSourceSurfaceTemplate != nullptr &&
binding.sourceColorTexture.IsValid()) {
if (resolvedSourceSurfaceStorage != nullptr) {
*resolvedSourceSurfaceStorage = *fallbackSourceSurfaceTemplate;
binding.sourceSurface = resolvedSourceSurfaceStorage;
} else {
binding.sourceSurface = fallbackSourceSurfaceTemplate;
}
}
return binding;
}
inline RenderSurface BuildRenderGraphManagedSurfaceTemplate(
const RenderSurface& templateSurface) {
RenderSurface surface = templateSurface;
surface.SetAutoTransitionEnabled(false);
return surface;
}
struct RenderGraphRecordingContextBuildParams {
const Containers::String* passName = nullptr;
const RenderSurface* surface = nullptr;
bool overrideSourceBinding = false;
RenderGraphRecordingSourceBinding sourceBinding = {};
bool overrideColorTargets = false;
std::vector<RenderGraphTextureHandle> colorTargets = {};
bool overrideDepthTarget = false;
RenderGraphTextureHandle depthTarget = {};
};
inline RenderGraphRecordingContext CloneRenderGraphRecordingContext(
const RenderGraphRecordingContext& context,
const RenderGraphRecordingContextOverrides& overrides) {
@@ -71,6 +140,31 @@ inline RenderGraphRecordingContext CloneRenderGraphRecordingContext(
overrides);
}
inline RenderGraphRecordingContext BuildRenderGraphRecordingContext(
const RenderGraphRecordingContext& context,
RenderGraphRecordingContextBuildParams params) {
RenderGraphRecordingContextOverrides overrides = {};
overrides.passName = params.passName;
overrides.surface = params.surface;
if (params.overrideSourceBinding) {
overrides.overrideSourceSurface = true;
overrides.sourceSurface = params.sourceBinding.sourceSurface;
overrides.overrideSourceColorView = true;
overrides.sourceColorView = params.sourceBinding.sourceColorView;
overrides.overrideSourceColorState = true;
overrides.sourceColorState = params.sourceBinding.sourceColorState;
overrides.overrideSourceColorTexture = true;
overrides.sourceColorTexture = params.sourceBinding.sourceColorTexture;
}
overrides.overrideColorTargets = params.overrideColorTargets;
overrides.colorTargets = std::move(params.colorTargets);
overrides.overrideDepthTarget = params.overrideDepthTarget;
overrides.depthTarget = params.depthTarget;
return CloneRenderGraphRecordingContext(
context,
overrides);
}
inline RenderGraphRecordingContext BuildRenderGraphRecordingContext(
const RenderPassRenderGraphContext& context) {
return {