Graph-manage camera fullscreen stage routing

This commit is contained in:
2026-04-14 19:32:27 +08:00
parent c4fe643427
commit c710063d92
10 changed files with 337 additions and 440 deletions

View File

@@ -6,7 +6,23 @@
namespace XCEngine {
namespace Rendering {
enum class CameraFrameColorSource {
ExplicitSurface = 0,
MainSceneColor,
PostProcessColor
};
struct CameraFramePlan {
static RenderSurface BuildGraphManagedIntermediateSurfaceTemplate(
const RenderSurface& surface) {
RenderSurface graphManagedSurface = surface;
graphManagedSurface.SetColorAttachments({});
graphManagedSurface.SetAutoTransitionEnabled(false);
graphManagedSurface.SetColorStateBefore(RHI::ResourceStates::Common);
graphManagedSurface.SetColorStateAfter(RHI::ResourceStates::Common);
return graphManagedSurface;
}
CameraRenderRequest request = {};
ShadowCasterRenderRequest shadowCaster = {};
DirectionalShadowRenderPlan directionalShadow = {};
@@ -16,6 +32,11 @@ struct CameraFramePlan {
RenderPassSequence* preScenePasses = nullptr;
RenderPassSequence* postScenePasses = nullptr;
RenderPassSequence* overlayPasses = nullptr;
bool usesGraphManagedMainSceneColor = false;
bool usesGraphManagedPostProcessColor = false;
CameraFrameColorSource postProcessSource = CameraFrameColorSource::ExplicitSurface;
CameraFrameColorSource finalOutputSource = CameraFrameColorSource::ExplicitSurface;
RenderSurface graphManagedMainSceneSurface = {};
static CameraFramePlan FromRequest(const CameraRenderRequest& request) {
CameraFramePlan plan = {};
@@ -35,6 +56,49 @@ struct CameraFramePlan {
return request.IsValid();
}
void ConfigureGraphManagedMainSceneSurface() {
graphManagedMainSceneSurface =
BuildGraphManagedIntermediateSurfaceTemplate(request.surface);
}
bool IsPostProcessStageValid() const {
if (!postProcess.IsRequested()) {
return true;
}
if (postProcessSource == CameraFrameColorSource::ExplicitSurface) {
return postProcess.IsValid();
}
const bool hasUsableDestination =
usesGraphManagedPostProcessColor ||
(HasValidColorTarget(postProcess.destinationSurface) &&
HasValidSurfaceSampleDescription(postProcess.destinationSurface));
return usesGraphManagedMainSceneColor &&
postProcess.passes != nullptr &&
HasValidSingleSampleColorSource(request.surface) &&
hasUsableDestination;
}
bool IsFinalOutputStageValid() const {
if (!finalOutput.IsRequested()) {
return true;
}
if (finalOutputSource == CameraFrameColorSource::ExplicitSurface) {
return finalOutput.IsValid();
}
const bool hasUsableSource =
finalOutputSource == CameraFrameColorSource::MainSceneColor
? usesGraphManagedMainSceneColor
: usesGraphManagedPostProcessColor;
return hasUsableSource &&
finalOutput.passes != nullptr &&
HasValidColorTarget(finalOutput.destinationSurface) &&
HasValidSurfaceSampleDescription(finalOutput.destinationSurface);
}
bool HasFrameStage(CameraFrameStage stage) const {
switch (stage) {
case CameraFrameStage::PreScenePasses:
@@ -93,11 +157,19 @@ struct CameraFramePlan {
}
const RenderSurface& GetMainSceneSurface() const {
if (postProcess.IsRequested()) {
if (usesGraphManagedMainSceneColor &&
graphManagedMainSceneSurface.GetWidth() > 0u &&
graphManagedMainSceneSurface.GetHeight() > 0u) {
return graphManagedMainSceneSurface;
}
if (postProcess.IsRequested() &&
HasValidColorTarget(postProcess.sourceSurface)) {
return postProcess.sourceSurface;
}
if (finalOutput.IsRequested()) {
if (finalOutput.IsRequested() &&
HasValidColorTarget(finalOutput.sourceSurface)) {
return finalOutput.sourceSurface;
}
@@ -105,11 +177,13 @@ struct CameraFramePlan {
}
const RenderSurface& GetFinalCompositedSurface() const {
if (finalOutput.IsRequested()) {
if (finalOutput.IsRequested() &&
HasValidColorTarget(finalOutput.destinationSurface)) {
return finalOutput.destinationSurface;
}
if (postProcess.IsRequested()) {
if (postProcess.IsRequested() &&
HasValidColorTarget(postProcess.destinationSurface)) {
return postProcess.destinationSurface;
}
@@ -126,9 +200,15 @@ struct CameraFramePlan {
case CameraFrameStage::DepthOnly:
return request.depthOnly.IsRequested() ? &request.depthOnly.surface : nullptr;
case CameraFrameStage::PostProcess:
return postProcess.IsRequested() ? &postProcess.destinationSurface : nullptr;
return postProcess.IsRequested() &&
HasValidColorTarget(postProcess.destinationSurface)
? &postProcess.destinationSurface
: nullptr;
case CameraFrameStage::FinalOutput:
return finalOutput.IsRequested() ? &finalOutput.destinationSurface : nullptr;
return finalOutput.IsRequested() &&
HasValidColorTarget(finalOutput.destinationSurface)
? &finalOutput.destinationSurface
: nullptr;
case CameraFrameStage::ObjectId:
return request.objectId.IsRequested() ? &request.objectId.surface : nullptr;
case CameraFrameStage::PostScenePasses:
@@ -142,9 +222,15 @@ struct CameraFramePlan {
const RenderSurface* GetSourceSurface(CameraFrameStage stage) const {
switch (stage) {
case CameraFrameStage::PostProcess:
return postProcess.IsRequested() ? &postProcess.sourceSurface : nullptr;
return postProcess.IsRequested() &&
postProcessSource == CameraFrameColorSource::ExplicitSurface
? &postProcess.sourceSurface
: nullptr;
case CameraFrameStage::FinalOutput:
return finalOutput.IsRequested() ? &finalOutput.sourceSurface : nullptr;
return finalOutput.IsRequested() &&
finalOutputSource == CameraFrameColorSource::ExplicitSurface
? &finalOutput.sourceSurface
: nullptr;
default:
return nullptr;
}
@@ -153,9 +239,15 @@ struct CameraFramePlan {
RHI::RHIResourceView* GetSourceColorView(CameraFrameStage stage) const {
switch (stage) {
case CameraFrameStage::PostProcess:
return postProcess.IsRequested() ? postProcess.sourceColorView : nullptr;
return postProcess.IsRequested() &&
postProcessSource == CameraFrameColorSource::ExplicitSurface
? postProcess.sourceColorView
: nullptr;
case CameraFrameStage::FinalOutput:
return finalOutput.IsRequested() ? finalOutput.sourceColorView : nullptr;
return finalOutput.IsRequested() &&
finalOutputSource == CameraFrameColorSource::ExplicitSurface
? finalOutput.sourceColorView
: nullptr;
default:
return nullptr;
}
@@ -164,9 +256,15 @@ struct CameraFramePlan {
RHI::ResourceStates GetSourceColorState(CameraFrameStage stage) const {
switch (stage) {
case CameraFrameStage::PostProcess:
return postProcess.IsRequested() ? postProcess.sourceColorState : RHI::ResourceStates::Common;
return postProcess.IsRequested() &&
postProcessSource == CameraFrameColorSource::ExplicitSurface
? postProcess.sourceColorState
: RHI::ResourceStates::Common;
case CameraFrameStage::FinalOutput:
return finalOutput.IsRequested() ? finalOutput.sourceColorState : RHI::ResourceStates::Common;
return finalOutput.IsRequested() &&
finalOutputSource == CameraFrameColorSource::ExplicitSurface
? finalOutput.sourceColorState
: RHI::ResourceStates::Common;
default:
return RHI::ResourceStates::Common;
}

View File

@@ -18,6 +18,7 @@ class RenderGraphBuilder;
struct CameraFrameRenderGraphResources {
RenderGraphTextureHandle mainSceneColor = {};
RenderGraphTextureHandle mainSceneDepth = {};
RenderGraphTextureHandle postProcessColor = {};
RenderGraphTextureHandle mainDirectionalShadow = {};
RenderGraphTextureHandle objectIdColor = {};
};