From 0da2a58b84bdef01488c90c7a477dbd8a4d2c8ff Mon Sep 17 00:00:00 2001 From: Stephen Miller <56742918+StevenMiller123@users.noreply.github.com> Date: Fri, 17 Jul 2026 09:25:50 -0500 Subject: [PATCH] Remove image ids from download_images on TextureCache::DeleteImage calls (#4719) Also adds synchronization since erasing images will invalidate iterators (and trying to emplace mid-downloads could result in image downloads getting skipped) --- src/video_core/texture_cache/texture_cache.cpp | 10 ++++++++++ src/video_core/texture_cache/texture_cache.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/video_core/texture_cache/texture_cache.cpp b/src/video_core/texture_cache/texture_cache.cpp index 7e6af0cc8..4ba69d09c 100644 --- a/src/video_core/texture_cache/texture_cache.cpp +++ b/src/video_core/texture_cache/texture_cache.cpp @@ -61,6 +61,7 @@ TextureCache::TextureCache(const Vulkan::Instance& instance_, Vulkan::Scheduler& TextureCache::~TextureCache() = default; void TextureCache::ProcessDownloadImages() { + std::unique_lock lk{download_images_mutex}; for (const ImageId image_id : download_images) { DownloadImageMemory(image_id, true); } @@ -622,6 +623,7 @@ ImageView& TextureCache::FindTexture(ImageId image_id, const ImageDesc& desc) { if (desc.type == BindingType::Storage) { image.flags |= ImageFlagBits::GpuModified; if (readback_linear_images && !image.info.props.is_tiled && image.info.guest_address != 0) { + std::unique_lock lk{download_images_mutex}; download_images.emplace(image_id); } } @@ -633,6 +635,7 @@ ImageView& TextureCache::FindRenderTarget(ImageId image_id, const ImageDesc& des Image& image = slot_images[image_id]; image.flags |= ImageFlagBits::GpuModified; if (readback_linear_images && !image.info.props.is_tiled) { + std::unique_lock lk{download_images_mutex}; download_images.emplace(image_id); } image.usage.render_target = 1u; @@ -1080,6 +1083,13 @@ void TextureCache::DeleteImage(ImageId image_id) { surface_metas.erase(meta_info.htile_addr); } + { + std::unique_lock lk{download_images_mutex}; + if (download_images.contains(image_id)) { + download_images.erase(image_id); + } + } + // Reclaim image and any image views it references. scheduler.DeferOperation([this, image_id] { Image& image = slot_images[image_id]; diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 3b2d65d2a..63dd84405 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h @@ -337,6 +337,7 @@ private: PageTable page_table; std::mutex mutex; std::mutex samplers_mutex; + std::mutex download_images_mutex; struct MetaDataInfo { enum class Type { CMask,