Harden render graph pass capture and feature source-color contract
This commit is contained in:
@@ -172,11 +172,13 @@ bool RecordRasterRenderPass(
|
||||
const RenderPassGraphIO& io) {
|
||||
RenderPass* const renderPass = &pass;
|
||||
const Containers::String passName = context.passName;
|
||||
const RenderContext* const renderContext = &context.renderContext;
|
||||
const RenderContext renderContext = context.renderContext;
|
||||
const std::shared_ptr<const RenderSceneData> sceneData =
|
||||
std::make_shared<RenderSceneData>(context.sceneData);
|
||||
const RenderSurface surface = context.surface;
|
||||
const RenderSurface* const sourceSurface = context.sourceSurface;
|
||||
const bool hasSourceSurface = context.sourceSurface != nullptr;
|
||||
const RenderSurface sourceSurface =
|
||||
hasSourceSurface ? *context.sourceSurface : RenderSurface();
|
||||
RHI::RHIResourceView* const sourceColorView = context.sourceColorView;
|
||||
const RHI::ResourceStates sourceColorState = context.sourceColorState;
|
||||
const RenderGraphTextureHandle sourceColorTexture = context.sourceColorTexture;
|
||||
@@ -192,6 +194,7 @@ bool RecordRasterRenderPass(
|
||||
renderContext,
|
||||
sceneData,
|
||||
surface,
|
||||
hasSourceSurface,
|
||||
sourceSurface,
|
||||
sourceColorView,
|
||||
sourceColorState,
|
||||
@@ -224,6 +227,7 @@ bool RecordRasterRenderPass(
|
||||
renderContext,
|
||||
sceneData,
|
||||
surface,
|
||||
hasSourceSurface,
|
||||
sourceSurface,
|
||||
sourceColorView,
|
||||
sourceColorState,
|
||||
@@ -239,12 +243,13 @@ bool RecordRasterRenderPass(
|
||||
return;
|
||||
}
|
||||
|
||||
const RenderSurface* resolvedSourceSurface = sourceSurface;
|
||||
const RenderSurface* resolvedSourceSurface =
|
||||
hasSourceSurface ? &sourceSurface : nullptr;
|
||||
RHI::RHIResourceView* resolvedSourceColorView = sourceColorView;
|
||||
RHI::ResourceStates resolvedSourceColorState = sourceColorState;
|
||||
RenderSurface graphManagedSourceSurface = {};
|
||||
if (!ResolveGraphManagedSourceSurface(
|
||||
sourceSurface,
|
||||
hasSourceSurface ? &sourceSurface : nullptr,
|
||||
sourceColorView,
|
||||
sourceColorState,
|
||||
sourceColorTexture,
|
||||
@@ -277,7 +282,7 @@ bool RecordRasterRenderPass(
|
||||
}
|
||||
|
||||
const RenderPassContext passContext = {
|
||||
*renderContext,
|
||||
renderContext,
|
||||
*resolvedSurface,
|
||||
*sceneData,
|
||||
resolvedSourceSurface,
|
||||
|
||||
@@ -94,11 +94,14 @@ bool BuiltinForwardPipeline::SupportsMainSceneRenderGraph() const {
|
||||
bool BuiltinForwardPipeline::RecordMainSceneRenderGraph(
|
||||
const RenderPipelineMainSceneRenderGraphContext& context) {
|
||||
const Containers::String passName = context.passName;
|
||||
const RenderContext* const renderContext = &context.renderContext;
|
||||
const RenderSceneData* const sceneData = &context.sceneData;
|
||||
const RenderContext renderContext = context.renderContext;
|
||||
const std::shared_ptr<const RenderSceneData> sceneData =
|
||||
std::make_shared<RenderSceneData>(context.sceneData);
|
||||
const RenderSurface surfaceTemplate =
|
||||
BuildGraphManagedForwardSceneSurface(context.surfaceTemplate);
|
||||
const RenderSurface* const sourceSurface = context.sourceSurface;
|
||||
const bool hasSourceSurface = context.sourceSurface != nullptr;
|
||||
const RenderSurface sourceSurface =
|
||||
hasSourceSurface ? *context.sourceSurface : RenderSurface();
|
||||
RHI::RHIResourceView* const sourceColorView = context.sourceColorView;
|
||||
const RHI::ResourceStates sourceColorState = context.sourceColorState;
|
||||
const std::vector<RenderGraphTextureHandle> colorTargets = context.colorTargets;
|
||||
@@ -113,6 +116,7 @@ bool BuiltinForwardPipeline::RecordMainSceneRenderGraph(
|
||||
graphExecutionState,
|
||||
renderContext,
|
||||
sceneData,
|
||||
hasSourceSurface,
|
||||
sourceSurface,
|
||||
sourceColorView,
|
||||
sourceColorState,
|
||||
@@ -124,7 +128,7 @@ bool BuiltinForwardPipeline::RecordMainSceneRenderGraph(
|
||||
}
|
||||
|
||||
if (!graphExecutionState->initialized) {
|
||||
if (!Initialize(*renderContext)) {
|
||||
if (!Initialize(renderContext)) {
|
||||
Debug::Logger::Get().Error(
|
||||
Debug::LogCategory::Rendering,
|
||||
"BuiltinForwardPipeline::RecordMainSceneRenderGraph failed during execution: Initialize returned false");
|
||||
@@ -135,10 +139,10 @@ bool BuiltinForwardPipeline::RecordMainSceneRenderGraph(
|
||||
}
|
||||
|
||||
const FrameExecutionContext executionContext(
|
||||
*renderContext,
|
||||
renderContext,
|
||||
passContext.surface,
|
||||
*sceneData,
|
||||
sourceSurface,
|
||||
hasSourceSurface ? &sourceSurface : nullptr,
|
||||
sourceColorView,
|
||||
sourceColorState);
|
||||
if (!m_forwardSceneFeatureHost.Prepare(executionContext)) {
|
||||
@@ -177,12 +181,13 @@ bool BuiltinForwardPipeline::RecordMainSceneRenderGraph(
|
||||
const SceneRenderFeaturePassRenderGraphContext featureContext = {
|
||||
context.graphBuilder,
|
||||
passName,
|
||||
*renderContext,
|
||||
renderContext,
|
||||
*sceneData,
|
||||
surfaceTemplate,
|
||||
sourceSurface,
|
||||
hasSourceSurface ? &sourceSurface : nullptr,
|
||||
sourceColorView,
|
||||
sourceColorState,
|
||||
{},
|
||||
colorTargets,
|
||||
depthTarget,
|
||||
mainDirectionalShadowTexture,
|
||||
@@ -214,6 +219,7 @@ bool BuiltinForwardPipeline::RecordMainSceneRenderGraph(
|
||||
surfaceTemplate,
|
||||
renderContext,
|
||||
sceneData,
|
||||
hasSourceSurface,
|
||||
sourceSurface,
|
||||
sourceColorView,
|
||||
sourceColorState,
|
||||
@@ -245,6 +251,7 @@ bool BuiltinForwardPipeline::RecordMainSceneRenderGraph(
|
||||
surfaceTemplate,
|
||||
renderContext,
|
||||
sceneData,
|
||||
hasSourceSurface,
|
||||
sourceSurface,
|
||||
sourceColorView,
|
||||
sourceColorState,
|
||||
@@ -259,10 +266,10 @@ bool BuiltinForwardPipeline::RecordMainSceneRenderGraph(
|
||||
}
|
||||
|
||||
const FrameExecutionContext executionContext(
|
||||
*renderContext,
|
||||
renderContext,
|
||||
surfaceTemplate,
|
||||
*sceneData,
|
||||
sourceSurface,
|
||||
hasSourceSurface ? &sourceSurface : nullptr,
|
||||
sourceColorView,
|
||||
sourceColorState);
|
||||
const RenderPassContext passContext =
|
||||
|
||||
@@ -131,6 +131,7 @@ bool SceneRenderFeatureHost::Record(
|
||||
context.sourceSurface,
|
||||
context.sourceColorView,
|
||||
context.sourceColorState,
|
||||
context.sourceColorTexture,
|
||||
context.colorTargets,
|
||||
context.depthTarget,
|
||||
context.mainDirectionalShadowTexture,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user