From d9f9bbfaa6b3400a4f33e342e6c290afe796123a Mon Sep 17 00:00:00 2001 From: Isaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com> Date: Sat, 23 Sep 2023 18:32:36 -0400 Subject: [PATCH] Vulkan: Fix barriers on macOS (#5700) * Use old method on macOS * gdk suggestions * Update src/Ryujinx.Graphics.Vulkan/TextureStorage.cs Co-authored-by: gdkchan * Update src/Ryujinx.Graphics.Vulkan/TextureStorage.cs Co-authored-by: gdkchan --------- Co-authored-by: gdkchan --- src/Ryujinx.Graphics.Vulkan/TextureStorage.cs | 74 +++++++++++++++---- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/src/Ryujinx.Graphics.Vulkan/TextureStorage.cs b/src/Ryujinx.Graphics.Vulkan/TextureStorage.cs index e9c2bf1ec..5a6216c22 100644 --- a/src/Ryujinx.Graphics.Vulkan/TextureStorage.cs +++ b/src/Ryujinx.Graphics.Vulkan/TextureStorage.cs @@ -454,13 +454,36 @@ namespace Ryujinx.Graphics.Vulkan if (lastReadStage != PipelineStageFlags.None) { - TextureView.InsertMemoryBarrier( - _gd.Api, - cbs.CommandBuffer, - _lastReadAccess, - dstAccessFlags, - lastReadStage, - dstStageFlags); + // This would result in a validation error, but is + // required on MoltenVK as the generic barrier results in + // severe texture flickering in some scenarios. + if (_gd.IsMoltenVk) + { + ImageAspectFlags aspectFlags = Info.Format.ConvertAspectFlags(); + TextureView.InsertImageBarrier( + _gd.Api, + cbs.CommandBuffer, + _imageAuto.Get(cbs).Value, + _lastReadAccess, + dstAccessFlags, + _lastReadStage, + dstStageFlags, + aspectFlags, + 0, + 0, + _info.GetLayers(), + _info.Levels); + } + else + { + TextureView.InsertMemoryBarrier( + _gd.Api, + cbs.CommandBuffer, + _lastReadAccess, + dstAccessFlags, + lastReadStage, + dstStageFlags); + } _lastReadAccess = AccessFlags.None; _lastReadStage = PipelineStageFlags.None; @@ -474,13 +497,36 @@ namespace Ryujinx.Graphics.Vulkan if (_lastModificationAccess != AccessFlags.None) { - TextureView.InsertMemoryBarrier( - _gd.Api, - cbs.CommandBuffer, - _lastModificationAccess, - dstAccessFlags, - _lastModificationStage, - dstStageFlags); + // This would result in a validation error, but is + // required on MoltenVK as the generic barrier results in + // severe texture flickering in some scenarios. + if (_gd.IsMoltenVk) + { + ImageAspectFlags aspectFlags = Info.Format.ConvertAspectFlags(); + TextureView.InsertImageBarrier( + _gd.Api, + cbs.CommandBuffer, + _imageAuto.Get(cbs).Value, + _lastModificationAccess, + dstAccessFlags, + _lastModificationStage, + dstStageFlags, + aspectFlags, + 0, + 0, + _info.GetLayers(), + _info.Levels); + } + else + { + TextureView.InsertMemoryBarrier( + _gd.Api, + cbs.CommandBuffer, + _lastModificationAccess, + dstAccessFlags, + _lastModificationStage, + dstStageFlags); + } _lastModificationAccess = AccessFlags.None; }