From f9406b325e8bcbd567645e895b5822be864dbcb9 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:51:39 -0800 Subject: [PATCH] renderer_vulkan: Require exact image format for resolve pass. (#1742) --- src/video_core/renderer_vulkan/vk_rasterizer.cpp | 6 ++++-- src/video_core/texture_cache/texture_cache.cpp | 13 ++++++++++--- src/video_core/texture_cache/texture_cache.h | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 5fd0d99a4..bfcdc9538 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -790,8 +790,10 @@ void Rasterizer::Resolve() { mrt0_hint}; VideoCore::TextureCache::RenderTargetDesc mrt1_desc{liverpool->regs.color_buffers[1], mrt1_hint}; - auto& mrt0_image = texture_cache.GetImage(texture_cache.FindImage(mrt0_desc)); - auto& mrt1_image = texture_cache.GetImage(texture_cache.FindImage(mrt1_desc)); + auto& mrt0_image = + texture_cache.GetImage(texture_cache.FindImage(mrt0_desc, VideoCore::FindFlags::ExactFmt)); + auto& mrt1_image = + texture_cache.GetImage(texture_cache.FindImage(mrt1_desc, VideoCore::FindFlags::ExactFmt)); VideoCore::SubresourceRange mrt0_range; mrt0_range.base.layer = liverpool->regs.color_buffers[0].view.slice_start; diff --git a/src/video_core/texture_cache/texture_cache.cpp b/src/video_core/texture_cache/texture_cache.cpp index 66132753d..153314d2b 100644 --- a/src/video_core/texture_cache/texture_cache.cpp +++ b/src/video_core/texture_cache/texture_cache.cpp @@ -324,6 +324,10 @@ ImageId TextureCache::FindImage(BaseDesc& desc, FindFlags flags) { !IsVulkanFormatCompatible(info.pixel_format, cache_image.info.pixel_format)) { continue; } + if (True(flags & FindFlags::ExactFmt) && + info.pixel_format != cache_image.info.pixel_format) { + continue; + } ASSERT((cache_image.info.type == info.type || info.size == Extent3D{1, 1, 1} || True(flags & FindFlags::RelaxFmt))); image_id = cache_id; @@ -348,9 +352,12 @@ ImageId TextureCache::FindImage(BaseDesc& desc, FindFlags flags) { } if (image_id) { - Image& image_resoved = slot_images[image_id]; - - if (image_resoved.info.resources < info.resources) { + Image& image_resolved = slot_images[image_id]; + if (True(flags & FindFlags::ExactFmt) && + info.pixel_format != image_resolved.info.pixel_format) { + // Cannot reuse this image as we need the exact requested format. + image_id = {}; + } else if (image_resolved.info.resources < info.resources) { // The image was clearly picked up wrong. FreeImage(image_id); image_id = {}; diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 3ef81a699..430415ed2 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h @@ -28,6 +28,7 @@ enum class FindFlags { RelaxDim = 1 << 1, ///< Do not check the dimentions of image, only address. RelaxSize = 1 << 2, ///< Do not check that the size matches exactly. RelaxFmt = 1 << 3, ///< Do not check that format is compatible. + ExactFmt = 1 << 4, ///< Require the format to be exactly the same. }; DECLARE_ENUM_FLAG_OPERATORS(FindFlags)