Skip to content

Commit

Permalink
[Vk] Keep MSAA vulkan texture in predictable state to avoid layout va…
Browse files Browse the repository at this point in the history
…lidation errors when resolved texture of VulkanTextureGpuRenderTarget was used as shader resource. Can we skip this barrier if MSAA subtexture is already in required state?
  • Loading branch information
eugenegff committed Sep 16, 2024
1 parent 9e3fc3c commit 4a30feb
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3292,20 +3292,28 @@ namespace Ogre
if( texture->isMultisample() && !texture->hasMsaaExplicitResolves() )
{
// Rare case where we render to an implicit resolve without resolving
// (otherwise newLayout = ResolveDest)
//
// Or more common case if we need to copy to/from an MSAA texture
// (otherwise newLayout = ResolveDest), or more common case if we need
// to copy to/from an MSAA texture. We can also try to sample from texture.
// In all these cases keep MSAA texture in predictable layout.
//
// This cannot catch all use cases, but if you fall into something this
// doesn't catch, then you should probably be using explicit resolves
if( itor->newLayout == ResourceLayout::RenderTarget ||
itor->newLayout == ResourceLayout::ResolveDest ||
itor->newLayout == ResourceLayout::CopySrc ||
itor->newLayout == ResourceLayout::CopyDst )
{
imageBarrier.image = texture->getMsaaFramebufferName();
mImageBarriers.push_back( imageBarrier );
}
bool useNewLayoutForMsaa =
itor->newLayout == ResourceLayout::RenderTarget ||
itor->newLayout == ResourceLayout::ResolveDest ||
itor->newLayout == ResourceLayout::CopySrc ||
itor->newLayout == ResourceLayout::CopyDst;
bool useOldLayoutForMsaa =
itor->oldLayout == ResourceLayout::RenderTarget ||
itor->oldLayout == ResourceLayout::ResolveDest ||
itor->oldLayout == ResourceLayout::CopySrc ||
itor->oldLayout == ResourceLayout::CopyDst;
if( !useNewLayoutForMsaa )
imageBarrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
if( !useOldLayoutForMsaa )
imageBarrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
imageBarrier.image = texture->getMsaaFramebufferName();
mImageBarriers.push_back( imageBarrier );
}
}
else
Expand Down

0 comments on commit 4a30feb

Please sign in to comment.