Move fullscreen graph ownership out of pass transitions
This commit is contained in:
@@ -98,7 +98,8 @@ RenderGraphTextureDesc BuildImportedTextureDesc(
|
||||
RenderGraphImportedTextureOptions BuildImportedTextureOptions(
|
||||
const RenderSurface& surface,
|
||||
bool isDepth,
|
||||
RenderGraphSurfaceImportUsage usage) {
|
||||
RenderGraphSurfaceImportUsage usage,
|
||||
bool graphOwnsTransitions) {
|
||||
const RHI::ResourceStates beforeState =
|
||||
isDepth ? surface.GetDepthStateBefore() : surface.GetColorStateBefore();
|
||||
const RHI::ResourceStates afterState =
|
||||
@@ -113,7 +114,7 @@ RenderGraphImportedTextureOptions BuildImportedTextureOptions(
|
||||
usage == RenderGraphSurfaceImportUsage::Output
|
||||
? afterState
|
||||
: options.initialState;
|
||||
options.graphOwnsTransitions = false;
|
||||
options.graphOwnsTransitions = graphOwnsTransitions;
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -130,6 +131,7 @@ RenderGraphTextureHandle ImportRenderGraphTexture(
|
||||
|
||||
const auto existing = registry.find(view);
|
||||
if (existing != registry.end()) {
|
||||
builder.MergeImportedTextureOptions(existing->second, importedOptions);
|
||||
return existing->second;
|
||||
}
|
||||
|
||||
@@ -144,7 +146,8 @@ RenderGraphImportedSurface ImportRenderGraphSurface(
|
||||
RenderGraphImportedTextureRegistry& registry,
|
||||
const Containers::String& surfaceName,
|
||||
const RenderSurface* surface,
|
||||
RenderGraphSurfaceImportUsage usage) {
|
||||
RenderGraphSurfaceImportUsage usage,
|
||||
bool graphOwnsColorTransitions = false) {
|
||||
RenderGraphImportedSurface importedSurface = {};
|
||||
if (surface == nullptr) {
|
||||
return importedSurface;
|
||||
@@ -170,7 +173,8 @@ RenderGraphImportedSurface ImportRenderGraphSurface(
|
||||
BuildImportedTextureOptions(
|
||||
*surface,
|
||||
false,
|
||||
usage)));
|
||||
usage,
|
||||
graphOwnsColorTransitions)));
|
||||
}
|
||||
|
||||
if (RHI::RHIResourceView* depthAttachment = surface->GetDepthAttachment();
|
||||
@@ -185,7 +189,8 @@ RenderGraphImportedSurface ImportRenderGraphSurface(
|
||||
BuildImportedTextureOptions(
|
||||
*surface,
|
||||
true,
|
||||
usage));
|
||||
usage,
|
||||
false));
|
||||
}
|
||||
|
||||
return importedSurface;
|
||||
@@ -565,6 +570,17 @@ bool TryBuildRenderGraphTransientSurface(
|
||||
return true;
|
||||
}
|
||||
|
||||
RenderSurface BuildGraphManagedImportedSurface(
|
||||
const RenderSurface& templateSurface,
|
||||
RHI::ResourceStates stateBefore,
|
||||
RHI::ResourceStates stateAfter) {
|
||||
RenderSurface surface = templateSurface;
|
||||
surface.SetAutoTransitionEnabled(false);
|
||||
surface.SetColorStateBefore(stateBefore);
|
||||
surface.SetColorStateAfter(stateAfter);
|
||||
return surface;
|
||||
}
|
||||
|
||||
bool ExecuteFullscreenPassSequencePass(
|
||||
RenderPassSequence* sequence,
|
||||
size_t passIndex,
|
||||
@@ -694,14 +710,16 @@ bool ExecuteRenderGraphPlan(
|
||||
importedTextures,
|
||||
stageName + ".Source",
|
||||
stagePassContext.sourceSurface,
|
||||
RenderGraphSurfaceImportUsage::Source);
|
||||
RenderGraphSurfaceImportUsage::Source,
|
||||
true);
|
||||
const RenderGraphImportedSurface outputSurface =
|
||||
ImportRenderGraphSurface(
|
||||
graphBuilder,
|
||||
importedTextures,
|
||||
stageName + ".Output",
|
||||
&stagePassContext.surface,
|
||||
RenderGraphSurfaceImportUsage::Output);
|
||||
RenderGraphSurfaceImportUsage::Output,
|
||||
true);
|
||||
RenderGraphTextureHandle currentSourceColor = GetPrimaryColorTexture(sourceSurface);
|
||||
const RenderGraphTextureHandle finalOutputColor =
|
||||
GetPrimaryColorTexture(outputSurface);
|
||||
@@ -1017,7 +1035,9 @@ bool ExecuteFullscreenPassSequencePass(
|
||||
RHI::RHIResourceView* currentSourceColorView = passContext.sourceColorView;
|
||||
RHI::ResourceStates currentSourceColorState = passContext.sourceColorState;
|
||||
RenderSurface transientSourceSurface = {};
|
||||
RenderSurface graphManagedImportedSourceSurface = {};
|
||||
if (sourceColorHandle.IsValid() &&
|
||||
graphContext.OwnsTextureTransitions(sourceColorHandle) &&
|
||||
graphContext.IsTransientTexture(sourceColorHandle)) {
|
||||
if (!TryBuildRenderGraphTransientSurface(
|
||||
passContext.surface,
|
||||
@@ -1036,11 +1056,23 @@ bool ExecuteFullscreenPassSequencePass(
|
||||
return false;
|
||||
}
|
||||
currentSourceColorState = RHI::ResourceStates::PixelShaderResource;
|
||||
} else if (sourceColorHandle.IsValid() &&
|
||||
graphContext.OwnsTextureTransitions(sourceColorHandle) &&
|
||||
currentSourceSurface != nullptr) {
|
||||
graphManagedImportedSourceSurface =
|
||||
BuildGraphManagedImportedSurface(
|
||||
*currentSourceSurface,
|
||||
RHI::ResourceStates::PixelShaderResource,
|
||||
RHI::ResourceStates::PixelShaderResource);
|
||||
currentSourceSurface = &graphManagedImportedSourceSurface;
|
||||
currentSourceColorState = RHI::ResourceStates::PixelShaderResource;
|
||||
}
|
||||
|
||||
const RenderSurface* outputSurface = &passContext.surface;
|
||||
RenderSurface transientOutputSurface = {};
|
||||
RenderSurface graphManagedImportedOutputSurface = {};
|
||||
if (outputColorHandle.IsValid() &&
|
||||
graphContext.OwnsTextureTransitions(outputColorHandle) &&
|
||||
graphContext.IsTransientTexture(outputColorHandle)) {
|
||||
if (!TryBuildRenderGraphTransientSurface(
|
||||
passContext.surface,
|
||||
@@ -1051,6 +1083,14 @@ bool ExecuteFullscreenPassSequencePass(
|
||||
}
|
||||
|
||||
outputSurface = &transientOutputSurface;
|
||||
} else if (outputColorHandle.IsValid() &&
|
||||
graphContext.OwnsTextureTransitions(outputColorHandle)) {
|
||||
graphManagedImportedOutputSurface =
|
||||
BuildGraphManagedImportedSurface(
|
||||
passContext.surface,
|
||||
RHI::ResourceStates::RenderTarget,
|
||||
RHI::ResourceStates::PixelShaderResource);
|
||||
outputSurface = &graphManagedImportedOutputSurface;
|
||||
}
|
||||
|
||||
const RenderPassContext chainedContext = {
|
||||
|
||||
@@ -84,6 +84,24 @@ RenderGraphTextureHandle RenderGraphBuilder::CreateTransientTexture(
|
||||
return handle;
|
||||
}
|
||||
|
||||
void RenderGraphBuilder::MergeImportedTextureOptions(
|
||||
RenderGraphTextureHandle handle,
|
||||
const RenderGraphImportedTextureOptions& importedOptions) {
|
||||
if (!handle.IsValid() || handle.index >= m_graph.m_textures.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RenderGraph::TextureResource& resource = m_graph.m_textures[handle.index];
|
||||
if (resource.kind != RenderGraphTextureKind::Imported) {
|
||||
return;
|
||||
}
|
||||
|
||||
resource.importedOptions.graphOwnsTransitions =
|
||||
resource.importedOptions.graphOwnsTransitions ||
|
||||
importedOptions.graphOwnsTransitions;
|
||||
resource.importedOptions.finalState = importedOptions.finalState;
|
||||
}
|
||||
|
||||
RenderGraphPassHandle RenderGraphBuilder::AddRasterPass(
|
||||
const Containers::String& name,
|
||||
const std::function<void(RenderGraphPassBuilder&)>& setup) {
|
||||
|
||||
@@ -116,6 +116,10 @@ public:
|
||||
m_graph.m_textures[handle.index].kind == RenderGraphTextureKind::Transient;
|
||||
}
|
||||
|
||||
bool OwnsTextureTransitions(RenderGraphTextureHandle handle) const {
|
||||
return ShouldGraphManageTransitions(handle);
|
||||
}
|
||||
|
||||
bool TransitionGraphOwnedImportsToFinalStates(
|
||||
const RenderContext& renderContext,
|
||||
Containers::String* outErrorMessage) {
|
||||
@@ -317,6 +321,11 @@ bool RenderGraphExecutionContext::IsTransientTexture(RenderGraphTextureHandle ha
|
||||
runtimeResources->IsTransientTexture(handle);
|
||||
}
|
||||
|
||||
bool RenderGraphExecutionContext::OwnsTextureTransitions(RenderGraphTextureHandle handle) const {
|
||||
return runtimeResources != nullptr &&
|
||||
runtimeResources->OwnsTextureTransitions(handle);
|
||||
}
|
||||
|
||||
bool RenderGraphExecutor::Execute(
|
||||
const CompiledRenderGraph& graph,
|
||||
const RenderContext& renderContext,
|
||||
|
||||
Reference in New Issue
Block a user