From 1fdbe569e4e637986148f82d296b1cdccafde980 Mon Sep 17 00:00:00 2001 From: bomabomabomaboma <69987043+goldislead@users.noreply.github.com> Date: Sat, 1 Aug 2026 00:49:31 +0000 Subject: [PATCH] [Vulkan] Barrier consecutive uploads to the same image Avoids a TRANSFER_WRITE -> TRANSFER_WRITE hazard identified by the Vulkan validation layer when a texture is reuploaded (after guest memory invalidation) without having been used for drawing in between, leaving it in the transfer destination usage with no layout transition to order the copies. Co-authored-by: Herman S. <429230+has207@users.noreply.github.com> --- src/xenia/gpu/vulkan/vulkan_texture_cache.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/xenia/gpu/vulkan/vulkan_texture_cache.cc b/src/xenia/gpu/vulkan/vulkan_texture_cache.cc index 1ad7ab2e0..435507000 100644 --- a/src/xenia/gpu/vulkan/vulkan_texture_cache.cc +++ b/src/xenia/gpu/vulkan/vulkan_texture_cache.cc @@ -1642,6 +1642,16 @@ bool VulkanTextureCache::LoadTextureDataFromResidentMemoryImpl(Texture& texture, vulkan_texture.image(), ui::vulkan::util::InitializeSubresourceRange(), texture_src_stage_mask, texture_dst_stage_mask, texture_src_access_mask, texture_dst_access_mask, texture_old_layout, texture_new_layout); + } else { + // Same layout/usage but another upload may have written the image earlier + // in this submission - emit a TRANSFER_WRITE -> TRANSFER_WRITE barrier so + // the next CmdCopyBufferToImage is ordered after any prior copy. + command_processor_.PushImageMemoryBarrier( + vulkan_texture.image(), ui::vulkan::util::InitializeSubresourceRange(), + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); } command_processor_.SubmitBarriers(true); VkBufferImageCopy* copy_regions = command_buffer.CmdCopyBufferToImageEmplace(