Graph-manage camera fullscreen stage routing
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
#include "Rendering/Caches/FullscreenPassSurfaceCache.h"
|
||||
|
||||
// This translation unit remains intentionally light. The cache is implemented
|
||||
// inline in the header so existing generated build files do not require a
|
||||
// CMake regeneration just to pick up method definitions.
|
||||
@@ -1,187 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Rendering/RenderSurface.h"
|
||||
#include "Rendering/RenderContext.h"
|
||||
#include "RHI/RHIDevice.h"
|
||||
#include "RHI/RHIEnums.h"
|
||||
#include "RHI/RHIResourceView.h"
|
||||
#include "RHI/RHITexture.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
class RHIDevice;
|
||||
class RHIResourceView;
|
||||
class RHITexture;
|
||||
} // namespace RHI
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
struct RenderContext;
|
||||
|
||||
class FullscreenPassSurfaceCache {
|
||||
public:
|
||||
struct SurfaceEntry {
|
||||
RenderSurface surface = {};
|
||||
RHI::RHITexture* texture = nullptr;
|
||||
RHI::RHIResourceView* renderTargetView = nullptr;
|
||||
RHI::RHIResourceView* shaderResourceView = nullptr;
|
||||
RHI::ResourceStates currentColorState = RHI::ResourceStates::Common;
|
||||
};
|
||||
|
||||
FullscreenPassSurfaceCache() = default;
|
||||
FullscreenPassSurfaceCache(const FullscreenPassSurfaceCache&) = delete;
|
||||
FullscreenPassSurfaceCache& operator=(const FullscreenPassSurfaceCache&) = delete;
|
||||
~FullscreenPassSurfaceCache() {
|
||||
Reset();
|
||||
}
|
||||
|
||||
bool EnsureSurfaces(
|
||||
const RenderContext& context,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
RHI::Format format,
|
||||
size_t surfaceCount) {
|
||||
if (!context.IsValid() ||
|
||||
width == 0 ||
|
||||
height == 0 ||
|
||||
format == RHI::Format::Unknown ||
|
||||
surfaceCount == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Matches(context, width, height, format, surfaceCount)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<SurfaceEntry> newEntries(surfaceCount);
|
||||
for (size_t index = 0; index < surfaceCount; ++index) {
|
||||
SurfaceEntry& entry = newEntries[index];
|
||||
|
||||
RHI::TextureDesc textureDesc = {};
|
||||
textureDesc.width = width;
|
||||
textureDesc.height = height;
|
||||
textureDesc.depth = 1;
|
||||
textureDesc.mipLevels = 1;
|
||||
textureDesc.arraySize = 1;
|
||||
textureDesc.format = static_cast<uint32_t>(format);
|
||||
textureDesc.textureType = static_cast<uint32_t>(RHI::TextureType::Texture2D);
|
||||
textureDesc.sampleCount = 1;
|
||||
textureDesc.sampleQuality = 0;
|
||||
textureDesc.flags = 0;
|
||||
|
||||
entry.texture = context.device->CreateTexture(textureDesc);
|
||||
if (entry.texture == nullptr) {
|
||||
for (SurfaceEntry& createdEntry : newEntries) {
|
||||
DestroySurfaceEntry(createdEntry);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RHI::ResourceViewDesc viewDesc = {};
|
||||
viewDesc.format = static_cast<uint32_t>(format);
|
||||
viewDesc.dimension = RHI::ResourceViewDimension::Texture2D;
|
||||
viewDesc.mipLevel = 0;
|
||||
|
||||
entry.renderTargetView = context.device->CreateRenderTargetView(entry.texture, viewDesc);
|
||||
if (entry.renderTargetView == nullptr) {
|
||||
for (SurfaceEntry& createdEntry : newEntries) {
|
||||
DestroySurfaceEntry(createdEntry);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
entry.shaderResourceView = context.device->CreateShaderResourceView(entry.texture, viewDesc);
|
||||
if (entry.shaderResourceView == nullptr) {
|
||||
for (SurfaceEntry& createdEntry : newEntries) {
|
||||
DestroySurfaceEntry(createdEntry);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
entry.surface = RenderSurface(width, height);
|
||||
entry.surface.SetColorAttachment(entry.renderTargetView);
|
||||
entry.surface.SetSampleDesc(1u, 0u);
|
||||
entry.surface.SetAutoTransitionEnabled(true);
|
||||
entry.surface.SetColorStateBefore(RHI::ResourceStates::Common);
|
||||
entry.surface.SetColorStateAfter(RHI::ResourceStates::PixelShaderResource);
|
||||
entry.currentColorState = RHI::ResourceStates::Common;
|
||||
}
|
||||
|
||||
Reset();
|
||||
m_device = context.device;
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_format = format;
|
||||
m_entries = std::move(newEntries);
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t GetSurfaceCount() const { return m_entries.size(); }
|
||||
SurfaceEntry* GetSurfaceEntry(size_t index) {
|
||||
return index < m_entries.size() ? &m_entries[index] : nullptr;
|
||||
}
|
||||
const SurfaceEntry* GetSurfaceEntry(size_t index) const {
|
||||
return index < m_entries.size() ? &m_entries[index] : nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
static void DestroySurfaceEntry(SurfaceEntry& entry) {
|
||||
if (entry.renderTargetView != nullptr) {
|
||||
entry.renderTargetView->Shutdown();
|
||||
delete entry.renderTargetView;
|
||||
entry.renderTargetView = nullptr;
|
||||
}
|
||||
|
||||
if (entry.shaderResourceView != nullptr) {
|
||||
entry.shaderResourceView->Shutdown();
|
||||
delete entry.shaderResourceView;
|
||||
entry.shaderResourceView = nullptr;
|
||||
}
|
||||
|
||||
if (entry.texture != nullptr) {
|
||||
entry.texture->Shutdown();
|
||||
delete entry.texture;
|
||||
entry.texture = nullptr;
|
||||
}
|
||||
|
||||
entry.surface = RenderSurface();
|
||||
entry.currentColorState = RHI::ResourceStates::Common;
|
||||
}
|
||||
|
||||
bool Matches(
|
||||
const RenderContext& context,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
RHI::Format format,
|
||||
size_t surfaceCount) const {
|
||||
return m_device == context.device &&
|
||||
m_width == width &&
|
||||
m_height == height &&
|
||||
m_format == format &&
|
||||
m_entries.size() == surfaceCount;
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
for (SurfaceEntry& entry : m_entries) {
|
||||
DestroySurfaceEntry(entry);
|
||||
}
|
||||
|
||||
m_entries.clear();
|
||||
m_device = nullptr;
|
||||
m_width = 0;
|
||||
m_height = 0;
|
||||
m_format = RHI::Format::Unknown;
|
||||
}
|
||||
|
||||
RHI::RHIDevice* m_device = nullptr;
|
||||
uint32_t m_width = 0;
|
||||
uint32_t m_height = 0;
|
||||
RHI::Format m_format = RHI::Format::Unknown;
|
||||
std::vector<SurfaceEntry> m_entries;
|
||||
};
|
||||
|
||||
} // namespace Rendering
|
||||
} // namespace XCEngine
|
||||
@@ -530,6 +530,14 @@ RenderSurface BuildGraphManagedPassSurface(
|
||||
return surface;
|
||||
}
|
||||
|
||||
struct FullscreenStageGraphBinding {
|
||||
const RenderSurface* sourceSurfaceTemplate = nullptr;
|
||||
RHI::RHIResourceView* sourceColorView = nullptr;
|
||||
RHI::ResourceStates sourceColorState = RHI::ResourceStates::Common;
|
||||
RenderGraphTextureHandle sourceColor = {};
|
||||
RenderGraphTextureHandle outputColor = {};
|
||||
};
|
||||
|
||||
const RenderSurface* ResolveFrameStageOutputSurface(
|
||||
CameraFrameStage stage,
|
||||
const CameraFramePlan& plan,
|
||||
@@ -594,6 +602,79 @@ bool CanUseGraphManagedImportedSurface(
|
||||
return hasAnyTexture;
|
||||
}
|
||||
|
||||
RenderGraphTextureHandle ResolveStageOutputColorHandle(
|
||||
CameraFrameStage stage,
|
||||
const CameraFramePlan& plan,
|
||||
const Containers::String& stageName,
|
||||
const RenderPassContext& stagePassContext,
|
||||
const RenderGraphImportedSurface& outputSurface,
|
||||
RenderGraphBuilder& graphBuilder,
|
||||
CameraFrameRenderGraphResources& frameResources) {
|
||||
if (stage == CameraFrameStage::MainScene &&
|
||||
plan.usesGraphManagedMainSceneColor) {
|
||||
return graphBuilder.CreateTransientTexture(
|
||||
stageName + ".Color",
|
||||
BuildImportedTextureDesc(
|
||||
stagePassContext.surface,
|
||||
kRenderGraphImportedColorFormat));
|
||||
}
|
||||
|
||||
if (stage == CameraFrameStage::PostProcess &&
|
||||
plan.usesGraphManagedPostProcessColor) {
|
||||
frameResources.postProcessColor =
|
||||
graphBuilder.CreateTransientTexture(
|
||||
stageName + ".Color",
|
||||
BuildFullscreenTransientTextureDesc(stagePassContext.surface));
|
||||
return frameResources.postProcessColor;
|
||||
}
|
||||
|
||||
return GetPrimaryColorTexture(outputSurface);
|
||||
}
|
||||
|
||||
FullscreenStageGraphBinding ResolveFullscreenStageGraphBinding(
|
||||
CameraFrameStage stage,
|
||||
const CameraFramePlan& plan,
|
||||
const RenderPassContext& stagePassContext,
|
||||
const RenderGraphImportedSurface& sourceSurface,
|
||||
RenderGraphTextureHandle outputColor,
|
||||
CameraFrameRenderGraphResources& frameResources) {
|
||||
FullscreenStageGraphBinding binding = {};
|
||||
binding.sourceSurfaceTemplate = stagePassContext.sourceSurface;
|
||||
binding.sourceColorView = stagePassContext.sourceColorView;
|
||||
binding.sourceColorState = stagePassContext.sourceColorState;
|
||||
binding.sourceColor = GetPrimaryColorTexture(sourceSurface);
|
||||
binding.outputColor = outputColor;
|
||||
|
||||
if (stage == CameraFrameStage::PostProcess &&
|
||||
plan.postProcessSource == CameraFrameColorSource::MainSceneColor) {
|
||||
binding.sourceSurfaceTemplate = &stagePassContext.surface;
|
||||
binding.sourceColorView = nullptr;
|
||||
binding.sourceColorState = RHI::ResourceStates::PixelShaderResource;
|
||||
binding.sourceColor = frameResources.mainSceneColor;
|
||||
}
|
||||
|
||||
if (stage == CameraFrameStage::FinalOutput) {
|
||||
if (plan.finalOutputSource == CameraFrameColorSource::MainSceneColor) {
|
||||
binding.sourceSurfaceTemplate = &stagePassContext.surface;
|
||||
binding.sourceColorView = nullptr;
|
||||
binding.sourceColorState = RHI::ResourceStates::PixelShaderResource;
|
||||
binding.sourceColor = frameResources.mainSceneColor;
|
||||
} else if (plan.finalOutputSource == CameraFrameColorSource::PostProcessColor) {
|
||||
binding.sourceSurfaceTemplate = &stagePassContext.surface;
|
||||
binding.sourceColorView = nullptr;
|
||||
binding.sourceColorState = RHI::ResourceStates::PixelShaderResource;
|
||||
binding.sourceColor = frameResources.postProcessColor;
|
||||
}
|
||||
}
|
||||
|
||||
if (binding.sourceSurfaceTemplate == nullptr &&
|
||||
binding.sourceColor.IsValid()) {
|
||||
binding.sourceSurfaceTemplate = &stagePassContext.surface;
|
||||
}
|
||||
|
||||
return binding;
|
||||
}
|
||||
|
||||
RenderPassContext BuildFrameStagePassContext(
|
||||
CameraFrameStage stage,
|
||||
const CameraFramePlan& plan,
|
||||
@@ -736,8 +817,7 @@ bool RecordFullscreenPassSequenceStage(
|
||||
CameraFrameStage stage,
|
||||
const Containers::String& stageName,
|
||||
const RenderPassContext& stagePassContext,
|
||||
const RenderGraphImportedSurface& sourceSurface,
|
||||
const RenderGraphImportedSurface& outputSurface,
|
||||
const FullscreenStageGraphBinding& binding,
|
||||
const RenderSceneData& sceneData,
|
||||
RenderPassSequence* stageSequence,
|
||||
CameraFrameExecutionState& executionState,
|
||||
@@ -766,10 +846,8 @@ bool RecordFullscreenPassSequenceStage(
|
||||
return true;
|
||||
};
|
||||
|
||||
RenderGraphTextureHandle currentSourceColor =
|
||||
GetPrimaryColorTexture(sourceSurface);
|
||||
const RenderGraphTextureHandle finalOutputColor =
|
||||
GetPrimaryColorTexture(outputSurface);
|
||||
RenderGraphTextureHandle currentSourceColor = binding.sourceColor;
|
||||
const RenderGraphTextureHandle finalOutputColor = binding.outputColor;
|
||||
const RenderGraphTextureDesc transientDesc =
|
||||
BuildFullscreenTransientTextureDesc(stagePassContext.surface);
|
||||
|
||||
@@ -792,15 +870,15 @@ bool RecordFullscreenPassSequenceStage(
|
||||
transientDesc);
|
||||
const RenderSurface* const sourceSurfaceTemplate =
|
||||
passIndex == 0u
|
||||
? stagePassContext.sourceSurface
|
||||
? binding.sourceSurfaceTemplate
|
||||
: &stagePassContext.surface;
|
||||
RHI::RHIResourceView* const sourceColorView =
|
||||
passIndex == 0u
|
||||
? stagePassContext.sourceColorView
|
||||
? binding.sourceColorView
|
||||
: nullptr;
|
||||
const RHI::ResourceStates sourceColorState =
|
||||
passIndex == 0u
|
||||
? stagePassContext.sourceColorState
|
||||
? binding.sourceColorState
|
||||
: RHI::ResourceStates::PixelShaderResource;
|
||||
const RenderPassRenderGraphContext passContext = {
|
||||
graphBuilder,
|
||||
@@ -879,6 +957,15 @@ bool ExecuteRenderGraphPlan(
|
||||
RenderGraphSurfaceImportUsage::Output,
|
||||
ShouldGraphOwnStageColorTransitions(stage),
|
||||
ShouldGraphOwnStageDepthTransitions(stage));
|
||||
const RenderGraphTextureHandle stageOutputColor =
|
||||
ResolveStageOutputColorHandle(
|
||||
stage,
|
||||
plan,
|
||||
stageName,
|
||||
stagePassContext,
|
||||
outputSurface,
|
||||
graphBuilder,
|
||||
frameResources);
|
||||
if (stage == CameraFrameStage::ShadowCaster &&
|
||||
shadowState.HasShadowSampling() &&
|
||||
outputSurface.depthTexture.IsValid()) {
|
||||
@@ -886,11 +973,11 @@ bool ExecuteRenderGraphPlan(
|
||||
frameResources.mainDirectionalShadow = outputSurface.depthTexture;
|
||||
}
|
||||
if (stage == CameraFrameStage::MainScene) {
|
||||
frameResources.mainSceneColor = GetPrimaryColorTexture(outputSurface);
|
||||
frameResources.mainSceneColor = stageOutputColor;
|
||||
frameResources.mainSceneDepth = outputSurface.depthTexture;
|
||||
}
|
||||
if (stage == CameraFrameStage::ObjectId) {
|
||||
frameResources.objectIdColor = GetPrimaryColorTexture(outputSurface);
|
||||
frameResources.objectIdColor = stageOutputColor;
|
||||
}
|
||||
const RenderSurface stageSurfaceTemplate = stagePassContext.surface;
|
||||
const bool hasStageSourceSurface = stagePassContext.sourceSurface != nullptr;
|
||||
@@ -908,8 +995,13 @@ bool ExecuteRenderGraphPlan(
|
||||
stage,
|
||||
stageName,
|
||||
stagePassContext,
|
||||
sourceSurface,
|
||||
outputSurface,
|
||||
ResolveFullscreenStageGraphBinding(
|
||||
stage,
|
||||
plan,
|
||||
stagePassContext,
|
||||
sourceSurface,
|
||||
stageOutputColor,
|
||||
frameResources),
|
||||
sceneData,
|
||||
stageSequence,
|
||||
executionState,
|
||||
@@ -960,7 +1052,7 @@ bool ExecuteRenderGraphPlan(
|
||||
|
||||
return true;
|
||||
};
|
||||
const RenderPassRenderGraphContext standalonePassContext = {
|
||||
const RenderPassRenderGraphContext standalonePassContext = {
|
||||
graphBuilder,
|
||||
stageName,
|
||||
plan.request.context,
|
||||
@@ -970,7 +1062,7 @@ bool ExecuteRenderGraphPlan(
|
||||
const_cast<RHI::RHIResourceView*>(stageSourceColorView),
|
||||
stageSourceColorState,
|
||||
GetPrimaryColorTexture(sourceSurface),
|
||||
outputSurface.colorTextures,
|
||||
std::vector<RenderGraphTextureHandle>{ stageOutputColor },
|
||||
outputSurface.depthTexture,
|
||||
&stageExecutionSucceeded,
|
||||
beginStandalonePass,
|
||||
@@ -999,7 +1091,7 @@ bool ExecuteRenderGraphPlan(
|
||||
hasStageSourceSurface ? &stageSourceSurfaceTemplate : nullptr,
|
||||
const_cast<RHI::RHIResourceView*>(stageSourceColorView),
|
||||
stageSourceColorState,
|
||||
outputSurface.colorTextures,
|
||||
std::vector<RenderGraphTextureHandle>{ stageOutputColor },
|
||||
outputSurface.depthTexture,
|
||||
mainDirectionalShadowTexture,
|
||||
&stageExecutionSucceeded,
|
||||
@@ -1302,14 +1394,21 @@ bool CameraRenderer::Render(
|
||||
return false;
|
||||
}
|
||||
if (plan.postProcess.IsRequested() &&
|
||||
!plan.postProcess.IsValid()) {
|
||||
!plan.IsPostProcessStageValid()) {
|
||||
Debug::Logger::Get().Error(
|
||||
Debug::LogCategory::Rendering,
|
||||
"CameraRenderer::Render failed: post-process request invalid");
|
||||
return false;
|
||||
}
|
||||
if (plan.usesGraphManagedMainSceneColor &&
|
||||
(m_pipeline == nullptr || !m_pipeline->SupportsMainSceneRenderGraph())) {
|
||||
Debug::Logger::Get().Error(
|
||||
Debug::LogCategory::Rendering,
|
||||
"CameraRenderer::Render failed: graph-managed main scene color requires pipeline main-scene render-graph support");
|
||||
return false;
|
||||
}
|
||||
if (plan.finalOutput.IsRequested() &&
|
||||
!plan.finalOutput.IsValid()) {
|
||||
!plan.IsFinalOutputStageValid()) {
|
||||
Debug::Logger::Get().Error(
|
||||
Debug::LogCategory::Rendering,
|
||||
"CameraRenderer::Render failed: final-output request invalid");
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "Rendering/Execution/SceneRenderer.h"
|
||||
|
||||
#include "Components/CameraComponent.h"
|
||||
#include "Rendering/Caches/FullscreenPassSurfaceCache.h"
|
||||
#include "Rendering/Planning/CameraFramePlanBuilder.h"
|
||||
#include "Rendering/Planning/SceneRenderRequestUtils.h"
|
||||
|
||||
@@ -83,15 +82,6 @@ bool SceneRenderer::Render(const std::vector<CameraFramePlan>& plans) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_framePlanBuilder != nullptr) {
|
||||
m_framePlanBuilder->UpdateTrackedSurfaceState(&plan.GetMainSceneSurface());
|
||||
}
|
||||
if (plan.postProcess.IsRequested()) {
|
||||
if (m_framePlanBuilder != nullptr) {
|
||||
m_framePlanBuilder->UpdateTrackedSurfaceState(&plan.postProcess.destinationSurface);
|
||||
}
|
||||
}
|
||||
|
||||
rendered = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "Components/CameraComponent.h"
|
||||
#include "Debug/Logger.h"
|
||||
#include "Rendering/Caches/FullscreenPassSurfaceCache.h"
|
||||
#include "Rendering/Planning/CameraPostProcessPassFactory.h"
|
||||
#include "Rendering/Planning/FinalColorPassFactory.h"
|
||||
#include "Rendering/RenderPipelineAsset.h"
|
||||
@@ -10,35 +9,6 @@
|
||||
namespace XCEngine {
|
||||
namespace Rendering {
|
||||
|
||||
namespace {
|
||||
|
||||
RenderSurface ConfigureFullscreenStageSurface(
|
||||
const FullscreenPassSurfaceCache::SurfaceEntry& entry,
|
||||
const RenderSurface& templateSurface,
|
||||
bool copyDepthAttachment) {
|
||||
RenderSurface surface = entry.surface;
|
||||
if (copyDepthAttachment) {
|
||||
surface.SetDepthAttachment(templateSurface.GetDepthAttachment());
|
||||
surface.SetDepthStateBefore(templateSurface.GetDepthStateBefore());
|
||||
surface.SetDepthStateAfter(templateSurface.GetDepthStateAfter());
|
||||
if (templateSurface.HasClearColorOverride()) {
|
||||
surface.SetClearColorOverride(templateSurface.GetClearColorOverride());
|
||||
}
|
||||
}
|
||||
|
||||
if (templateSurface.HasCustomRenderArea()) {
|
||||
surface.SetRenderArea(templateSurface.GetRenderArea());
|
||||
} else {
|
||||
surface.ResetRenderArea();
|
||||
}
|
||||
|
||||
surface.SetColorStateBefore(entry.currentColorState);
|
||||
surface.SetColorStateAfter(RHI::ResourceStates::PixelShaderResource);
|
||||
return surface;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::vector<CameraFramePlan> CameraFramePlanBuilder::BuildPlans(
|
||||
const std::vector<CameraRenderRequest>& requests,
|
||||
const RenderPipelineAsset* pipelineAsset) {
|
||||
@@ -48,33 +18,6 @@ std::vector<CameraFramePlan> CameraFramePlanBuilder::BuildPlans(
|
||||
return plans;
|
||||
}
|
||||
|
||||
void CameraFramePlanBuilder::UpdateTrackedSurfaceState(const RenderSurface* surface) {
|
||||
if (surface == nullptr || surface->GetColorAttachments().empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RHI::RHIResourceView* colorAttachment = surface->GetColorAttachments()[0];
|
||||
if (colorAttachment == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const std::unique_ptr<FullscreenPassSurfaceCache>& cache : m_ownedFullscreenStageSurfaces) {
|
||||
if (cache == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (size_t entryIndex = 0; entryIndex < cache->GetSurfaceCount(); ++entryIndex) {
|
||||
FullscreenPassSurfaceCache::SurfaceEntry* entry = cache->GetSurfaceEntry(entryIndex);
|
||||
if (entry == nullptr || entry->renderTargetView != colorAttachment) {
|
||||
continue;
|
||||
}
|
||||
|
||||
entry->currentColorState = surface->GetColorStateAfter();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<CameraFramePlan> CameraFramePlanBuilder::CreatePlansFromRequests(
|
||||
const std::vector<CameraRenderRequest>& requests) const {
|
||||
std::vector<CameraFramePlan> plans = {};
|
||||
@@ -86,23 +29,6 @@ std::vector<CameraFramePlan> CameraFramePlanBuilder::CreatePlansFromRequests(
|
||||
return plans;
|
||||
}
|
||||
|
||||
void CameraFramePlanBuilder::PrepareOwnedFullscreenStageState(size_t planCount) {
|
||||
m_ownedPostProcessSequences.clear();
|
||||
m_ownedPostProcessSequences.resize(planCount);
|
||||
m_ownedFinalOutputSequences.clear();
|
||||
m_ownedFinalOutputSequences.resize(planCount);
|
||||
|
||||
if (m_ownedFullscreenStageSurfaces.size() < planCount) {
|
||||
m_ownedFullscreenStageSurfaces.resize(planCount);
|
||||
}
|
||||
|
||||
for (size_t index = 0; index < planCount; ++index) {
|
||||
if (m_ownedFullscreenStageSurfaces[index] == nullptr) {
|
||||
m_ownedFullscreenStageSurfaces[index] = std::make_unique<FullscreenPassSurfaceCache>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CameraFramePlanBuilder::ResolveCameraFinalColorPolicies(
|
||||
std::vector<CameraFramePlan>& plans,
|
||||
const RenderPipelineAsset* pipelineAsset) const {
|
||||
@@ -122,7 +48,10 @@ void CameraFramePlanBuilder::ResolveCameraFinalColorPolicies(
|
||||
|
||||
void CameraFramePlanBuilder::AttachFullscreenStageRequests(
|
||||
std::vector<CameraFramePlan>& plans) {
|
||||
PrepareOwnedFullscreenStageState(plans.size());
|
||||
m_ownedPostProcessSequences.clear();
|
||||
m_ownedPostProcessSequences.resize(plans.size());
|
||||
m_ownedFinalOutputSequences.clear();
|
||||
m_ownedFinalOutputSequences.resize(plans.size());
|
||||
|
||||
for (size_t index = 0; index < plans.size(); ++index) {
|
||||
CameraFramePlan& plan = plans[index];
|
||||
@@ -152,63 +81,30 @@ void CameraFramePlanBuilder::AttachFullscreenStageRequests(
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::vector<RHI::RHIResourceView*>& colorAttachments =
|
||||
plan.request.surface.GetColorAttachments();
|
||||
const RHI::Format colorFormat = colorAttachments[0]->GetFormat();
|
||||
if (colorFormat == RHI::Format::Unknown) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const size_t fullscreenSurfaceCount = hasPostProcess && hasFinalOutput ? 2u : 1u;
|
||||
FullscreenPassSurfaceCache* surfaceCache = m_ownedFullscreenStageSurfaces[index].get();
|
||||
if (surfaceCache == nullptr ||
|
||||
!surfaceCache->EnsureSurfaces(
|
||||
plan.request.context,
|
||||
plan.request.surface.GetWidth(),
|
||||
plan.request.surface.GetHeight(),
|
||||
colorFormat,
|
||||
fullscreenSurfaceCount)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const FullscreenPassSurfaceCache::SurfaceEntry* sceneColorEntry =
|
||||
surfaceCache->GetSurfaceEntry(0u);
|
||||
if (sceneColorEntry == nullptr || sceneColorEntry->shaderResourceView == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const FullscreenPassSurfaceCache::SurfaceEntry* postProcessOutputEntry =
|
||||
hasPostProcess && hasFinalOutput ? surfaceCache->GetSurfaceEntry(1u) : nullptr;
|
||||
if (hasPostProcess && hasFinalOutput &&
|
||||
(postProcessOutputEntry == nullptr || postProcessOutputEntry->shaderResourceView == nullptr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hasPostProcess) {
|
||||
plan.postProcess.sourceSurface =
|
||||
ConfigureFullscreenStageSurface(*sceneColorEntry, plan.request.surface, true);
|
||||
plan.postProcess.sourceColorView = sceneColorEntry->shaderResourceView;
|
||||
plan.postProcess.sourceColorState = plan.postProcess.sourceSurface.GetColorStateAfter();
|
||||
plan.postProcess.destinationSurface =
|
||||
hasFinalOutput
|
||||
? ConfigureFullscreenStageSurface(*postProcessOutputEntry, plan.request.surface, false)
|
||||
: plan.request.surface;
|
||||
m_ownedPostProcessSequences[index] = std::move(postProcessSequence);
|
||||
plan.postProcess.passes = m_ownedPostProcessSequences[index].get();
|
||||
plan.usesGraphManagedMainSceneColor = true;
|
||||
plan.postProcessSource = CameraFrameColorSource::MainSceneColor;
|
||||
plan.usesGraphManagedPostProcessColor = hasFinalOutput;
|
||||
if (!hasFinalOutput) {
|
||||
plan.postProcess.destinationSurface = plan.request.surface;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasFinalOutput) {
|
||||
const FullscreenPassSurfaceCache::SurfaceEntry* finalOutputSourceEntry =
|
||||
hasPostProcess ? postProcessOutputEntry : sceneColorEntry;
|
||||
plan.finalOutput.sourceSurface =
|
||||
hasPostProcess
|
||||
? plan.postProcess.destinationSurface
|
||||
: ConfigureFullscreenStageSurface(*sceneColorEntry, plan.request.surface, true);
|
||||
plan.finalOutput.sourceColorView = finalOutputSourceEntry->shaderResourceView;
|
||||
plan.finalOutput.sourceColorState = plan.finalOutput.sourceSurface.GetColorStateAfter();
|
||||
plan.finalOutput.destinationSurface = plan.request.surface;
|
||||
m_ownedFinalOutputSequences[index] = std::move(finalOutputSequence);
|
||||
plan.finalOutput.passes = m_ownedFinalOutputSequences[index].get();
|
||||
plan.usesGraphManagedMainSceneColor = true;
|
||||
plan.finalOutputSource =
|
||||
hasPostProcess
|
||||
? CameraFrameColorSource::PostProcessColor
|
||||
: CameraFrameColorSource::MainSceneColor;
|
||||
plan.finalOutput.destinationSurface = plan.request.surface;
|
||||
}
|
||||
|
||||
if (plan.usesGraphManagedMainSceneColor) {
|
||||
plan.ConfigureGraphManagedMainSceneSurface();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
namespace XCEngine {
|
||||
namespace Rendering {
|
||||
|
||||
class FullscreenPassSurfaceCache;
|
||||
class RenderPipelineAsset;
|
||||
|
||||
class CameraFramePlanBuilder {
|
||||
@@ -21,12 +20,10 @@ public:
|
||||
std::vector<CameraFramePlan> BuildPlans(
|
||||
const std::vector<CameraRenderRequest>& requests,
|
||||
const RenderPipelineAsset* pipelineAsset);
|
||||
void UpdateTrackedSurfaceState(const RenderSurface* surface);
|
||||
|
||||
private:
|
||||
std::vector<CameraFramePlan> CreatePlansFromRequests(
|
||||
const std::vector<CameraRenderRequest>& requests) const;
|
||||
void PrepareOwnedFullscreenStageState(size_t planCount);
|
||||
void ResolveCameraFinalColorPolicies(
|
||||
std::vector<CameraFramePlan>& plans,
|
||||
const RenderPipelineAsset* pipelineAsset) const;
|
||||
@@ -34,7 +31,6 @@ private:
|
||||
|
||||
std::vector<std::unique_ptr<RenderPassSequence>> m_ownedPostProcessSequences;
|
||||
std::vector<std::unique_ptr<RenderPassSequence>> m_ownedFinalOutputSequences;
|
||||
std::vector<std::unique_ptr<FullscreenPassSurfaceCache>> m_ownedFullscreenStageSurfaces;
|
||||
};
|
||||
|
||||
} // namespace Rendering
|
||||
|
||||
Reference in New Issue
Block a user