Files
XCEngine/engine/include/XCEngine/Rendering/Graph/RenderGraphRecordingContext.h

309 lines
11 KiB
C++

#pragma once
#include <XCEngine/Rendering/RenderPipeline.h>
#include <XCEngine/Rendering/SceneRenderFeaturePass.h>
#include <utility>
namespace XCEngine {
namespace Rendering {
struct RenderGraphRecordingContext {
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;
};
struct RenderGraphRecordingContextOverrides {
const Containers::String* passName = nullptr;
const RenderSurface* surface = nullptr;
bool overrideSourceSurface = false;
const RenderSurface* sourceSurface = nullptr;
bool overrideSourceColorView = false;
RHI::RHIResourceView* sourceColorView = nullptr;
bool overrideSourceColorState = false;
RHI::ResourceStates sourceColorState = RHI::ResourceStates::Common;
bool overrideSourceColorTexture = false;
RenderGraphTextureHandle sourceColorTexture = {};
bool overrideColorTargets = false;
std::vector<RenderGraphTextureHandle> colorTargets = {};
bool overrideDepthTarget = false;
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) {
RenderGraphRecordingContext clone = {
context.graphBuilder,
overrides.passName != nullptr ? *overrides.passName : context.passName,
context.renderContext,
context.sceneData,
overrides.surface != nullptr ? *overrides.surface : context.surface,
overrides.overrideSourceSurface ? overrides.sourceSurface : context.sourceSurface,
overrides.overrideSourceColorView ? overrides.sourceColorView : context.sourceColorView,
overrides.overrideSourceColorState ? overrides.sourceColorState : context.sourceColorState,
overrides.overrideSourceColorTexture ? overrides.sourceColorTexture : context.sourceColorTexture,
overrides.overrideColorTargets ? overrides.colorTargets : context.colorTargets,
overrides.overrideDepthTarget ? overrides.depthTarget : context.depthTarget,
context.executionSucceeded,
context.blackboard
};
return clone;
}
inline RenderGraphRecordingContext CloneRenderGraphRecordingContext(
const RenderGraphRecordingContext& context,
const Containers::String& passName) {
const RenderGraphRecordingContextOverrides overrides = {
&passName
};
return CloneRenderGraphRecordingContext(
context,
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 {
context.graphBuilder,
context.passName,
context.renderContext,
context.sceneData,
context.surface,
context.sourceSurface,
context.sourceColorView,
context.sourceColorState,
context.sourceColorTexture,
context.colorTargets,
context.depthTarget,
context.executionSucceeded,
context.blackboard
};
}
inline RenderGraphRecordingContext BuildRenderGraphRecordingContext(
const SceneRenderFeaturePassRenderGraphContext& context) {
return {
context.graphBuilder,
context.passName,
context.renderContext,
context.sceneData,
context.surface,
context.sourceSurface,
context.sourceColorView,
context.sourceColorState,
context.sourceColorTexture,
context.colorTargets,
context.depthTarget,
context.executionSucceeded,
context.blackboard
};
}
inline RenderGraphRecordingContext BuildRenderGraphRecordingContext(
const RenderPipelineStageRenderGraphContext& context) {
return {
context.graphBuilder,
context.passName,
context.renderContext,
context.sceneData,
context.surfaceTemplate,
context.sourceSurface,
context.sourceColorView,
context.sourceColorState,
context.sourceColorTexture,
context.colorTargets,
context.depthTarget,
context.executionSucceeded,
context.blackboard
};
}
inline RenderPassRenderGraphContext BuildRenderPassRenderGraphContext(
const RenderGraphRecordingContext& 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 RenderGraphRecordingContext& 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 RenderPipelineStageRenderGraphContext BuildRenderPipelineStageRenderGraphContext(
const RenderGraphRecordingContext& common,
CameraFrameStage stage) {
return {
common.graphBuilder,
common.passName,
stage,
common.renderContext,
common.sceneData,
common.surface,
common.sourceSurface,
common.sourceColorView,
common.sourceColorState,
common.sourceColorTexture,
common.colorTargets,
common.depthTarget,
common.executionSucceeded,
common.blackboard
};
}
inline SceneRenderFeaturePassRenderGraphContext CloneSceneRenderFeaturePassRenderGraphContext(
const SceneRenderFeaturePassRenderGraphContext& context,
const Containers::String& passName,
bool clearAttachments) {
return BuildSceneRenderFeaturePassRenderGraphContext(
CloneRenderGraphRecordingContext(
BuildRenderGraphRecordingContext(context),
passName),
clearAttachments,
context.beginPassCallback,
context.endPassCallback);
}
} // namespace Rendering
} // namespace XCEngine