From 6407add8887c94b309a29090bdb154f79251231b Mon Sep 17 00:00:00 2001 From: nmzik Date: Tue, 18 Aug 2026 02:32:00 +0200 Subject: [PATCH] renderer: align texture overlap retirement --- .../host_gpu/renderer/cache/textureCache.cpp | 45 ++++--------------- .../host_gpu/renderer/cache/textureCache.h | 25 +++++------ tests/ShaderRecompilerComputeTests.cpp | 2 + 3 files changed, 21 insertions(+), 51 deletions(-) diff --git a/src/graphics/host_gpu/renderer/cache/textureCache.cpp b/src/graphics/host_gpu/renderer/cache/textureCache.cpp index c1888da..93d3399 100644 --- a/src/graphics/host_gpu/renderer/cache/textureCache.cpp +++ b/src/graphics/host_gpu/renderer/cache/textureCache.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include @@ -279,27 +279,6 @@ void TextureCache::FreeImage(ImageId id) { DeleteImage(id); } -void TextureCache::DeleteImages(std::span ids, - std::optional native_source) { - std::set> unique; - for (const auto id: ids) { - if (!id || !unique.emplace(id.index, id.generation).second) { - continue; - } - auto owner = ResolveOwner(id); - if (owner == nullptr) { - continue; - } - if (native_source == id) { - ClearGpuModified(id); - } else if (owner->IsGpuModified()) { - DownloadImage(id); - ClearGpuModified(id); - } - DeleteImage(id); - } -} - void TextureCache::RetainImage(CommandBuffer& command, ImageId id) { auto owner = ResolveOwner(id); if (owner == nullptr) { @@ -729,7 +708,6 @@ ImageId TextureCache::ResolveDepthOverlap(const ImageInfo& requested, BindingTyp if (cached.binding.is_bound || cached.binding.is_target) { cached.binding.needs_rebind = true; } - bool copied = false; if (cached.backing.samples == replacement.backing.samples) { const bool copy_supported = cached.backing.samples == 1 || cached.backing.format == replacement.backing.format || @@ -737,7 +715,6 @@ ImageId TextureCache::ResolveDepthOverlap(const ImageInfo& requested, BindingTyp ImageViewOps::FormatsCompatible(cached.backing.format, replacement.backing.format)); if (copy_supported) { CopyImage(replacement_id, cached_id); - copied = true; } else { LOGF_COLOR(Log::Color::BrightYellow, "TextureCache: unsupported cross-format multisample depth copy\n"); @@ -754,18 +731,12 @@ ImageId TextureCache::ResolveDepthOverlap(const ImageInfo& requested, BindingTyp RetainImage(command, cached_id); RetainImage(command, replacement_id); CommitGpuWrite(replacement); - copied = true; } else { LOGF_COLOR(Log::Color::BrightYellow, "TextureCache: unsupported unequal-sample depth overlap copy (%u -> %u)\n", cached.backing.samples, replacement.backing.samples); } - if (copied) { - DeleteImages(std::array {cached_id}, cached_id); - } else { - ClearGpuModified(cached_id); - DeleteImage(cached_id); - } + FreeImage(cached_id); return replacement_id; } @@ -787,7 +758,7 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques if (requested.BlockExtent() != cached.info.BlockExtent() || requested_block != cached_block) { if (safe_to_delete) { - DeleteImages(std::array {cached_id}, cached_id); + FreeImage(cached_id); } return {merged_id}; } @@ -804,7 +775,7 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques } if (requested.tile_mode != cached.info.tile_mode) { if (safe_to_delete) { - DeleteImages(std::array {cached_id}, cached_id); + FreeImage(cached_id); } return {merged_id}; } @@ -840,7 +811,7 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques } } if (safe_to_delete) { - DeleteImages(std::array {cached_id}, cached_id); + FreeImage(cached_id); } return {}; } @@ -854,13 +825,13 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques if (merged_id) { ResolveImage(merged_id).binding.is_target = true; } - DeleteImages(std::array {cached_id}, cached_id); + FreeImage(cached_id); return {merged_id}; } if (merged_id) { CopyImageMip(merged_id, cached_id, static_cast(mip), static_cast(layer)); - DeleteImages(std::array {cached_id}, cached_id); + FreeImage(cached_id); } } } @@ -879,7 +850,7 @@ ImageId TextureCache::ExpandImage(const ImageInfo& info, ImageId source_id) { InitializeImage(expanded_id, ImageDesc {.info = info, .view_info = {}, .type = UploadBinding(source)}); CopyImage(expanded_id, source_id); - DeleteImages(std::array {source_id}, source_id); + FreeImage(source_id); return expanded_id; } diff --git a/src/graphics/host_gpu/renderer/cache/textureCache.h b/src/graphics/host_gpu/renderer/cache/textureCache.h index 815627b..33042e0 100644 --- a/src/graphics/host_gpu/renderer/cache/textureCache.h +++ b/src/graphics/host_gpu/renderer/cache/textureCache.h @@ -13,9 +13,7 @@ #include #include #include -#include #include -#include #include #include @@ -111,18 +109,17 @@ private: void UnregisterImage(ImageId id); void DeleteImage(ImageId id); void FreeImage(ImageId id); - void DeleteImages(std::span ids, std::optional native_source = {}); - void RetainImage(CommandBuffer& command, ImageId id); - void TouchImage(Image& image); - void TrackImage(ImageId id); - void TrackImageHead(ImageId id); - void TrackImageTail(ImageId id); - void UntrackImage(ImageId id); - void UntrackImageHead(ImageId id); - void UntrackImageTail(ImageId id); - void MarkAsMaybeDirty(ImageId id, Image& image); - void TrackImageDownload(ImageId id); - void TrackImageDownloadLocked(ImageId id, Image& image); + void RetainImage(CommandBuffer& command, ImageId id); + void TouchImage(Image& image); + void TrackImage(ImageId id); + void TrackImageHead(ImageId id); + void TrackImageTail(ImageId id); + void UntrackImage(ImageId id); + void UntrackImageHead(ImageId id); + void UntrackImageTail(ImageId id); + void MarkAsMaybeDirty(ImageId id, Image& image); + void TrackImageDownload(ImageId id); + void TrackImageDownloadLocked(ImageId id, Image& image); [[nodiscard]] static bool SameBacking(const ImageInfo& cached, const ImageInfo& requested, bool exact_format); [[nodiscard]] static BindingType UploadBinding(const Image& image); diff --git a/tests/ShaderRecompilerComputeTests.cpp b/tests/ShaderRecompilerComputeTests.cpp index eedcaad..50dfbd7 100644 --- a/tests/ShaderRecompilerComputeTests.cpp +++ b/tests/ShaderRecompilerComputeTests.cpp @@ -7646,6 +7646,8 @@ public: array_target_view != nullptr && array_target_owner != nullptr && array_target_owner->binding.needs_rebind && expanded_array_id != array_target_id && + !TextureCacheTestAccess::Contains(texture_cache, + array_target_id) && array_binding.resources.images[0].image_view != nullptr && array_binding.resources.images[0].desc.info.type == Prospero::ImageType::kColor2D &&