refactor(rendering): infer raster pass graph io from declared context
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <XCEngine/Rendering/RenderPass.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Rendering {
|
||||
|
||||
@@ -27,6 +29,22 @@ inline RenderPassGraphIO BuildColorDepthRasterPassGraphIO() {
|
||||
};
|
||||
}
|
||||
|
||||
inline RenderPassGraphIO BuildDeclaredRasterPassGraphIO(
|
||||
const RenderPassRenderGraphContext& context) {
|
||||
const bool writesColor =
|
||||
std::any_of(
|
||||
context.colorTargets.begin(),
|
||||
context.colorTargets.end(),
|
||||
[](RenderGraphTextureHandle handle) {
|
||||
return handle.IsValid();
|
||||
});
|
||||
return {
|
||||
context.sourceSurface != nullptr || context.sourceColorTexture.IsValid(),
|
||||
writesColor,
|
||||
context.depthTarget.IsValid()
|
||||
};
|
||||
}
|
||||
|
||||
using RenderPassGraphExecutePassCallback =
|
||||
std::function<bool(const RenderPassContext&)>;
|
||||
|
||||
@@ -59,6 +77,15 @@ inline bool RecordColorDepthRasterPass(
|
||||
BuildColorDepthRasterPassGraphIO());
|
||||
}
|
||||
|
||||
inline bool RecordDeclaredRasterPass(
|
||||
RenderPass& pass,
|
||||
const RenderPassRenderGraphContext& context) {
|
||||
return RecordRasterRenderPass(
|
||||
pass,
|
||||
context,
|
||||
BuildDeclaredRasterPassGraphIO(context));
|
||||
}
|
||||
|
||||
inline bool RecordSourceColorFullscreenCallbackRasterPass(
|
||||
const RenderPassRenderGraphContext& context,
|
||||
RenderPassGraphExecutePassCallback executePassCallback,
|
||||
|
||||
@@ -11,13 +11,6 @@ namespace Rendering {
|
||||
bool SceneRenderFeaturePass::RecordRenderGraph(
|
||||
const SceneRenderFeaturePassRenderGraphContext& context) {
|
||||
const bool usesSourceColor = context.sourceColorTexture.IsValid();
|
||||
const bool writesColor =
|
||||
std::any_of(
|
||||
context.colorTargets.begin(),
|
||||
context.colorTargets.end(),
|
||||
[](RenderGraphTextureHandle handle) {
|
||||
return handle.IsValid();
|
||||
});
|
||||
const RenderGraphRecordingContext baseRecordingContext =
|
||||
BuildRenderGraphRecordingContext(context);
|
||||
const RenderSurface sourceSurfaceTemplate =
|
||||
@@ -51,11 +44,7 @@ bool SceneRenderFeaturePass::RecordRenderGraph(
|
||||
return RecordRasterRenderPass(
|
||||
*this,
|
||||
passContext,
|
||||
{
|
||||
usesSourceColor,
|
||||
writesColor,
|
||||
context.depthTarget.IsValid()
|
||||
});
|
||||
BuildDeclaredRasterPassGraphIO(passContext));
|
||||
}
|
||||
|
||||
} // namespace Rendering
|
||||
|
||||
@@ -779,17 +779,9 @@ public:
|
||||
lastRecordedBlackboardMainSceneColorValid = false;
|
||||
lastRecordedBlackboardPostProcessColorValid = false;
|
||||
}
|
||||
const bool writesColor =
|
||||
context.sourceSurface != nullptr ||
|
||||
!context.colorTargets.empty();
|
||||
return RecordRasterRenderPass(
|
||||
return RecordDeclaredRasterPass(
|
||||
*this,
|
||||
context,
|
||||
{
|
||||
context.sourceSurface != nullptr,
|
||||
writesColor,
|
||||
context.depthTarget.IsValid()
|
||||
});
|
||||
context);
|
||||
}
|
||||
|
||||
bool Initialize(const RenderContext&) override {
|
||||
|
||||
@@ -69,6 +69,35 @@ TEST(RenderPassGraphContract_Test, BuildsColorDepthRasterPassGraphIO) {
|
||||
EXPECT_TRUE(io.writeDepth);
|
||||
}
|
||||
|
||||
TEST(RenderPassGraphContract_Test, BuildsDeclaredRasterPassGraphIOFromContextResources) {
|
||||
RenderGraph graph = {};
|
||||
RenderGraphBuilder builder(graph);
|
||||
RenderGraphBlackboard blackboard = {};
|
||||
RenderContext renderContext = {};
|
||||
RenderSceneData sceneData = {};
|
||||
RenderSurface surface(1280u, 720u);
|
||||
RenderSurface sourceSurface(640u, 360u);
|
||||
bool executionSucceeded = true;
|
||||
const RenderGraphRecordingContext commonContext =
|
||||
BuildCommonContext(
|
||||
builder,
|
||||
blackboard,
|
||||
renderContext,
|
||||
sceneData,
|
||||
surface,
|
||||
sourceSurface,
|
||||
executionSucceeded);
|
||||
const RenderPassRenderGraphContext passContext =
|
||||
BuildRenderPassRenderGraphContext(commonContext);
|
||||
|
||||
const RenderPassGraphIO io =
|
||||
BuildDeclaredRasterPassGraphIO(passContext);
|
||||
|
||||
EXPECT_TRUE(io.readSourceColor);
|
||||
EXPECT_TRUE(io.writeColor);
|
||||
EXPECT_TRUE(io.writeDepth);
|
||||
}
|
||||
|
||||
TEST(RenderGraphRecordingContext_Test, BuildsRenderPassContextFromSharedRecordingData) {
|
||||
RenderGraph graph = {};
|
||||
RenderGraphBuilder builder(graph);
|
||||
|
||||
Reference in New Issue
Block a user