From 39c0f8418b5fb500fd919bd57c38879bffd19b16 Mon Sep 17 00:00:00 2001 From: BearOso Date: Thu, 17 Oct 2024 13:48:46 -0500 Subject: [PATCH] Vulkan: Use recommended access flags for image layout transitions. --- common/video/vulkan/vulkan_pipeline_image.cpp | 10 +++++----- common/video/vulkan/vulkan_shader_chain.cpp | 15 +++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/common/video/vulkan/vulkan_pipeline_image.cpp b/common/video/vulkan/vulkan_pipeline_image.cpp index 3affca16..19fa8818 100644 --- a/common/video/vulkan/vulkan_pipeline_image.cpp +++ b/common/video/vulkan/vulkan_pipeline_image.cpp @@ -74,11 +74,11 @@ void PipelineImage::generate_mipmaps(vk::CommandBuffer cmd) .setImage(image) .setOldLayout(vk::ImageLayout::eShaderReadOnlyOptimal) .setNewLayout(vk::ImageLayout::eTransferSrcOptimal) - .setSrcAccessMask(vk::AccessFlagBits::eColorAttachmentWrite) + .setSrcAccessMask(vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eInputAttachmentRead) .setDstAccessMask(vk::AccessFlagBits::eTransferRead) .setSubresourceRange(srr(0)); - cmd.pipelineBarrier(vk::PipelineStageFlagBits::eAllGraphics, + cmd.pipelineBarrier(vk::PipelineStageFlagBits::eVertexShader | vk::PipelineStageFlagBits::eFragmentShader, vk::PipelineStageFlagBits::eTransfer, {}, {}, {}, image_memory_barrier); @@ -139,7 +139,7 @@ void PipelineImage::generate_mipmaps(vk::CommandBuffer cmd) image_memory_barrier .setOldLayout(vk::ImageLayout::eTransferSrcOptimal) .setNewLayout(vk::ImageLayout::eShaderReadOnlyOptimal) - .setSrcAccessMask(vk::AccessFlagBits::eTransferWrite) + .setSrcAccessMask(vk::AccessFlagBits::eTransferRead) .setDstAccessMask(vk::AccessFlagBits::eShaderRead) .setSubresourceRange(srr(base_level)); @@ -163,7 +163,7 @@ void PipelineImage::generate_mipmaps(vk::CommandBuffer cmd) void PipelineImage::barrier(vk::CommandBuffer cmd) { - cmd.pipelineBarrier(vk::PipelineStageFlagBits::eAllGraphics, + cmd.pipelineBarrier(vk::PipelineStageFlagBits::eBottomOfPipe, vk::PipelineStageFlagBits::eFragmentShader, {}, {}, {}, {}); } @@ -178,7 +178,7 @@ void PipelineImage::clear(vk::CommandBuffer cmd) .setOldLayout(vk::ImageLayout::eUndefined) .setNewLayout(vk::ImageLayout::eTransferDstOptimal) .setSrcAccessMask(vk::AccessFlagBits::eShaderRead) - .setDstAccessMask(vk::AccessFlagBits::eTransferWrite | vk::AccessFlagBits::eTransferRead); + .setDstAccessMask(vk::AccessFlagBits::eTransferWrite); cmd.pipelineBarrier(vk::PipelineStageFlagBits::eFragmentShader, vk::PipelineStageFlagBits::eTransfer, diff --git a/common/video/vulkan/vulkan_shader_chain.cpp b/common/video/vulkan/vulkan_shader_chain.cpp index 1040d26e..fc9c2a33 100644 --- a/common/video/vulkan/vulkan_shader_chain.cpp +++ b/common/video/vulkan/vulkan_shader_chain.cpp @@ -476,7 +476,7 @@ bool ShaderChain::do_frame_without_swap(uint8_t *data, int width, int height, in .setImage(context->swapchain->get_image()) .setOldLayout(vk::ImageLayout::ePresentSrcKHR) .setNewLayout(vk::ImageLayout::eTransferSrcOptimal) - .setSrcAccessMask(vk::AccessFlagBits::eColorAttachmentWrite) + .setSrcAccessMask(vk::AccessFlagBits::eNone) .setDstAccessMask(vk::AccessFlagBits::eTransferRead) .setSubresourceRange(vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1)); @@ -498,16 +498,19 @@ bool ShaderChain::do_frame_without_swap(uint8_t *data, int width, int height, in .setSrcAccessMask(vk::AccessFlagBits::eTransferWrite) .setDstAccessMask(vk::AccessFlagBits::eShaderRead) .setSubresourceRange(vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1)); + cmd.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eVertexShader | vk::PipelineStageFlagBits::eFragmentShader, + {}, {}, {}, image_memory_barrier[0]); + image_memory_barrier[1] .setOldLayout(vk::ImageLayout::eTransferSrcOptimal) .setNewLayout(vk::ImageLayout::ePresentSrcKHR) - .setSrcAccessMask(vk::AccessFlagBits::eTransferWrite) - .setDstAccessMask(vk::AccessFlagBits::eMemoryRead) + .setSrcAccessMask(vk::AccessFlagBits::eTransferRead) + .setDstAccessMask(vk::AccessFlagBits::eNone) .setSubresourceRange(vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1)); - cmd.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer, - vk::PipelineStageFlagBits::eAllGraphics, - {}, {}, {}, image_memory_barrier); + vk::PipelineStageFlagBits::eBottomOfPipe, + {}, {}, {}, image_memory_barrier[1]); frame.image.current_layout = vk::ImageLayout::eTransferDstOptimal; }