Add render graph texture transition plans
This commit is contained in:
@@ -36,6 +36,7 @@ void CompiledRenderGraph::Reset() {
|
||||
m_passes.clear();
|
||||
m_textures.clear();
|
||||
m_textureLifetimes.clear();
|
||||
m_textureTransitionPlans.clear();
|
||||
}
|
||||
|
||||
const Containers::String& CompiledRenderGraph::GetPassName(size_t index) const {
|
||||
@@ -76,6 +77,17 @@ bool CompiledRenderGraph::TryGetImportedTextureOptions(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CompiledRenderGraph::TryGetTextureTransitionPlan(
|
||||
RenderGraphTextureHandle handle,
|
||||
RenderGraphTextureTransitionPlan& outPlan) const {
|
||||
if (!handle.IsValid() || handle.index >= m_textureTransitionPlans.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
outPlan = m_textureTransitionPlans[handle.index];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderGraphCompiler::Compile(
|
||||
const RenderGraph& graph,
|
||||
CompiledRenderGraph& outCompiledGraph,
|
||||
@@ -89,6 +101,16 @@ bool RenderGraphCompiler::Compile(
|
||||
outErrorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (texture.kind == RenderGraphTextureKind::Imported &&
|
||||
texture.importedOptions.graphOwnsTransitions &&
|
||||
texture.importedView == nullptr) {
|
||||
WriteError(
|
||||
Containers::String("RenderGraph imported texture requires a valid view when graph owns transitions: ") +
|
||||
texture.name,
|
||||
outErrorMessage);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const size_t passCount = graph.m_passes.size();
|
||||
@@ -197,6 +219,7 @@ bool RenderGraphCompiler::Compile(
|
||||
}
|
||||
|
||||
outCompiledGraph.m_textureLifetimes.resize(textureCount);
|
||||
outCompiledGraph.m_textureTransitionPlans.resize(textureCount);
|
||||
for (size_t textureIndex = 0u; textureIndex < textureCount; ++textureIndex) {
|
||||
CompiledRenderGraph::CompiledTexture compiledTexture = {};
|
||||
compiledTexture.name = graph.m_textures[textureIndex].name;
|
||||
@@ -207,6 +230,19 @@ bool RenderGraphCompiler::Compile(
|
||||
outCompiledGraph.m_textures.push_back(std::move(compiledTexture));
|
||||
|
||||
outCompiledGraph.m_textureLifetimes[textureIndex].kind = graph.m_textures[textureIndex].kind;
|
||||
RenderGraphTextureTransitionPlan& transitionPlan =
|
||||
outCompiledGraph.m_textureTransitionPlans[textureIndex];
|
||||
transitionPlan.graphOwnsTransitions =
|
||||
graph.m_textures[textureIndex].kind == RenderGraphTextureKind::Transient ||
|
||||
graph.m_textures[textureIndex].importedOptions.graphOwnsTransitions;
|
||||
transitionPlan.initialState =
|
||||
graph.m_textures[textureIndex].kind == RenderGraphTextureKind::Imported
|
||||
? graph.m_textures[textureIndex].importedOptions.initialState
|
||||
: RHI::ResourceStates::Common;
|
||||
transitionPlan.finalState =
|
||||
graph.m_textures[textureIndex].kind == RenderGraphTextureKind::Imported
|
||||
? graph.m_textures[textureIndex].importedOptions.finalState
|
||||
: RHI::ResourceStates::Common;
|
||||
}
|
||||
|
||||
outCompiledGraph.m_passes.reserve(passCount);
|
||||
@@ -235,11 +271,25 @@ bool RenderGraphCompiler::Compile(
|
||||
for (const RenderGraph::TextureAccess& access : sourcePass.accesses) {
|
||||
RenderGraphTextureLifetime& lifetime =
|
||||
outCompiledGraph.m_textureLifetimes[access.texture.index];
|
||||
RenderGraphTextureTransitionPlan& transitionPlan =
|
||||
outCompiledGraph.m_textureTransitionPlans[access.texture.index];
|
||||
if (!lifetime.used) {
|
||||
lifetime.used = true;
|
||||
lifetime.firstPassIndex = compiledPassIndex;
|
||||
}
|
||||
lifetime.lastPassIndex = compiledPassIndex;
|
||||
|
||||
const RHI::ResourceStates accessState =
|
||||
ResolveRequiredState(sourcePass.type, access.mode);
|
||||
if (!transitionPlan.hasFirstAccessState) {
|
||||
transitionPlan.hasFirstAccessState = true;
|
||||
transitionPlan.firstAccessState = accessState;
|
||||
}
|
||||
transitionPlan.hasLastAccessState = true;
|
||||
transitionPlan.lastAccessState = accessState;
|
||||
if (graph.m_textures[access.texture.index].kind == RenderGraphTextureKind::Transient) {
|
||||
transitionPlan.finalState = accessState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user