From cb077780085bf245bd0dc2431caee035e023ba35 Mon Sep 17 00:00:00 2001 From: psucien Date: Thu, 6 Jun 2024 23:22:10 +0200 Subject: [PATCH] renderer_vulkan: proper barriers --- .../renderer_vulkan/vk_graphics_pipeline.cpp | 2 +- src/video_core/texture_cache/image.cpp | 9 +++++---- src/video_core/texture_cache/texture_cache.cpp | 10 ++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp index 23cca386..d73d2c9f 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp @@ -379,7 +379,7 @@ void GraphicsPipeline::BindResources(Core::MemoryManager* memory, StreamBuffer& const auto tsharp = stage.ReadUd(image.sgpr_base, image.dword_offset); const auto& image_view = texture_cache.FindImageView(tsharp); image_infos.emplace_back(VK_NULL_HANDLE, *image_view.image_view, - vk::ImageLayout::eGeneral); + vk::ImageLayout::eShaderReadOnlyOptimal); set_writes.push_back({ .dstSet = VK_NULL_HANDLE, .dstBinding = binding++, diff --git a/src/video_core/texture_cache/image.cpp b/src/video_core/texture_cache/image.cpp index 7aa3062b..99475124 100644 --- a/src/video_core/texture_cache/image.cpp +++ b/src/video_core/texture_cache/image.cpp @@ -214,10 +214,11 @@ void Image::Transit(vk::ImageLayout dst_layout, vk::Flags ds }}; // Adjust pipieline stage - vk::PipelineStageFlagBits dst_pl_stage = (dst_mask == vk::AccessFlagBits::eTransferRead || - dst_mask == vk::AccessFlagBits::eTransferWrite) - ? vk::PipelineStageFlagBits::eTransfer - : vk::PipelineStageFlagBits::eAllGraphics; + vk::PipelineStageFlags dst_pl_stage = + (dst_mask == vk::AccessFlagBits::eTransferRead || + dst_mask == vk::AccessFlagBits::eTransferWrite) + ? vk::PipelineStageFlagBits::eTransfer + : vk::PipelineStageFlagBits::eAllGraphics | vk::PipelineStageFlagBits::eComputeShader; const auto cmdbuf = scheduler->CommandBuffer(); cmdbuf.pipelineBarrier(pl_stage, dst_pl_stage, vk::DependencyFlagBits::eByRegion, {}, {}, barrier); diff --git a/src/video_core/texture_cache/texture_cache.cpp b/src/video_core/texture_cache/texture_cache.cpp index 39f89878..998723c0 100644 --- a/src/video_core/texture_cache/texture_cache.cpp +++ b/src/video_core/texture_cache/texture_cache.cpp @@ -163,6 +163,12 @@ ImageView& TextureCache::RegisterImageView(Image& image, const ImageViewInfo& vi ImageView& TextureCache::FindImageView(const AmdGpu::Image& desc) { Image& image = FindImage(ImageInfo{desc}, desc.Address()); + if (image.info.is_storage) { + image.Transit(vk::ImageLayout::eGeneral, vk::AccessFlagBits::eShaderWrite); + } else { + image.Transit(vk::ImageLayout::eShaderReadOnlyOptimal, vk::AccessFlagBits::eShaderRead); + } + const ImageViewInfo view_info{desc}; return RegisterImageView(image, view_info); } @@ -172,6 +178,10 @@ ImageView& TextureCache::RenderTarget(const AmdGpu::Liverpool::ColorBuffer& buff const ImageInfo info{buffer, hint}; auto& image = FindImage(info, buffer.Address()); + image.Transit(vk::ImageLayout::eColorAttachmentOptimal, + vk::AccessFlagBits::eColorAttachmentWrite | + vk::AccessFlagBits::eColorAttachmentRead); + ImageViewInfo view_info; view_info.format = info.pixel_format; return RegisterImageView(image, view_info);