Add render graph depth access semantics
This commit is contained in:
@@ -217,7 +217,7 @@ void ReadRenderGraphSurface(
|
||||
}
|
||||
|
||||
if (surface.depthTexture.IsValid()) {
|
||||
passBuilder.ReadTexture(surface.depthTexture);
|
||||
passBuilder.ReadDepthTexture(surface.depthTexture);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ void WriteRenderGraphSurface(
|
||||
}
|
||||
|
||||
if (surface.depthTexture.IsValid()) {
|
||||
passBuilder.WriteTexture(surface.depthTexture);
|
||||
passBuilder.WriteDepthTexture(surface.depthTexture);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ void RenderGraphPassBuilder::ReadTexture(RenderGraphTextureHandle texture) {
|
||||
RenderGraph::TextureAccess access = {};
|
||||
access.texture = texture;
|
||||
access.mode = RenderGraphAccessMode::Read;
|
||||
access.aspect = RenderGraphTextureAspect::Color;
|
||||
m_graph->m_passes[m_passHandle.index].accesses.push_back(access);
|
||||
}
|
||||
|
||||
@@ -36,6 +37,31 @@ void RenderGraphPassBuilder::WriteTexture(RenderGraphTextureHandle texture) {
|
||||
RenderGraph::TextureAccess access = {};
|
||||
access.texture = texture;
|
||||
access.mode = RenderGraphAccessMode::Write;
|
||||
access.aspect = RenderGraphTextureAspect::Color;
|
||||
m_graph->m_passes[m_passHandle.index].accesses.push_back(access);
|
||||
}
|
||||
|
||||
void RenderGraphPassBuilder::ReadDepthTexture(RenderGraphTextureHandle texture) {
|
||||
if (m_graph == nullptr || !m_passHandle.IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RenderGraph::TextureAccess access = {};
|
||||
access.texture = texture;
|
||||
access.mode = RenderGraphAccessMode::Read;
|
||||
access.aspect = RenderGraphTextureAspect::Depth;
|
||||
m_graph->m_passes[m_passHandle.index].accesses.push_back(access);
|
||||
}
|
||||
|
||||
void RenderGraphPassBuilder::WriteDepthTexture(RenderGraphTextureHandle texture) {
|
||||
if (m_graph == nullptr || !m_passHandle.IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RenderGraph::TextureAccess access = {};
|
||||
access.texture = texture;
|
||||
access.mode = RenderGraphAccessMode::Write;
|
||||
access.aspect = RenderGraphTextureAspect::Depth;
|
||||
m_graph->m_passes[m_passHandle.index].accesses.push_back(access);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,13 +10,24 @@ namespace {
|
||||
|
||||
RHI::ResourceStates ResolveRequiredState(
|
||||
RenderGraphPassType passType,
|
||||
RenderGraphAccessMode accessMode) {
|
||||
RenderGraphAccessMode accessMode,
|
||||
RenderGraphTextureAspect aspect) {
|
||||
if (accessMode == RenderGraphAccessMode::Write) {
|
||||
if (passType == RenderGraphPassType::Raster &&
|
||||
aspect == RenderGraphTextureAspect::Depth) {
|
||||
return RHI::ResourceStates::DepthWrite;
|
||||
}
|
||||
|
||||
return passType == RenderGraphPassType::Compute
|
||||
? RHI::ResourceStates::UnorderedAccess
|
||||
: RHI::ResourceStates::RenderTarget;
|
||||
}
|
||||
|
||||
if (passType == RenderGraphPassType::Raster &&
|
||||
aspect == RenderGraphTextureAspect::Depth) {
|
||||
return RHI::ResourceStates::DepthRead;
|
||||
}
|
||||
|
||||
return passType == RenderGraphPassType::Compute
|
||||
? RHI::ResourceStates::GenericRead
|
||||
: RHI::ResourceStates::PixelShaderResource;
|
||||
@@ -261,8 +272,9 @@ bool RenderGraphCompiler::Compile(
|
||||
CompiledRenderGraph::CompiledTextureAccess compiledAccess = {};
|
||||
compiledAccess.texture = access.texture;
|
||||
compiledAccess.mode = access.mode;
|
||||
compiledAccess.aspect = access.aspect;
|
||||
compiledAccess.requiredState =
|
||||
ResolveRequiredState(sourcePass.type, access.mode);
|
||||
ResolveRequiredState(sourcePass.type, access.mode, access.aspect);
|
||||
compiledPass.accesses.push_back(compiledAccess);
|
||||
}
|
||||
compiledPass.executeCallback = sourcePass.executeCallback;
|
||||
@@ -280,7 +292,7 @@ bool RenderGraphCompiler::Compile(
|
||||
lifetime.lastPassIndex = compiledPassIndex;
|
||||
|
||||
const RHI::ResourceStates accessState =
|
||||
ResolveRequiredState(sourcePass.type, access.mode);
|
||||
ResolveRequiredState(sourcePass.type, access.mode, access.aspect);
|
||||
if (!transitionPlan.hasFirstAccessState) {
|
||||
transitionPlan.hasFirstAccessState = true;
|
||||
transitionPlan.firstAccessState = accessState;
|
||||
|
||||
Reference in New Issue
Block a user