From b5e1a27a7e779a05ffb1cdfbf144e203fc774691 Mon Sep 17 00:00:00 2001 From: GPUCode <47210458+GPUCode@users.noreply.github.com> Date: Fri, 21 Jul 2023 01:55:19 +0300 Subject: [PATCH] rasterizer_cache: Handle texture cubes with duplicate faces (#6710) --- .../rasterizer_cache/rasterizer_cache.h | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/video_core/rasterizer_cache/rasterizer_cache.h b/src/video_core/rasterizer_cache/rasterizer_cache.h index 1133e90b01..512f216c01 100644 --- a/src/video_core/rasterizer_cache/rasterizer_cache.h +++ b/src/video_core/rasterizer_cache/rasterizer_cache.h @@ -10,6 +10,7 @@ #include "common/alignment.h" #include "common/logging/log.h" #include "common/microprofile.h" +#include "common/scope_exit.h" #include "common/settings.h" #include "core/memory.h" #include "video_core/custom_textures/custom_tex_manager.h" @@ -1367,24 +1368,26 @@ void RasterizerCache::UnregisterSurface(SurfaceId surface_id) { surfaces.erase(vector_it); }); - if (True(surface.flags & SurfaceFlagBits::Tracked)) { - auto it = texture_cube_cache.begin(); - while (it != texture_cube_cache.end()) { - std::array& face_ids = it->second.face_ids; - const auto array_it = std::find(face_ids.begin(), face_ids.end(), surface_id); - if (array_it != face_ids.end()) { - *array_it = SurfaceId{}; - } - if (std::none_of(face_ids.begin(), face_ids.end(), [](SurfaceId id) { return id; })) { - slot_surfaces.erase(it->second.surface_id); - it = texture_cube_cache.erase(it); - continue; - } - it++; - } + SCOPE_EXIT({ slot_surfaces.erase(surface_id); }); + + if (False(surface.flags & SurfaceFlagBits::Tracked)) { + return; } - slot_surfaces.erase(surface_id); + std::erase_if(texture_cube_cache, [&](auto& pair) { + TextureCube& cube = pair.second; + for (SurfaceId& face_id : cube.face_ids) { + if (face_id == surface_id) { + face_id = SurfaceId{}; + } + } + if (std::none_of(cube.face_ids.begin(), cube.face_ids.end(), + [](SurfaceId id) { return id; })) { + slot_surfaces.erase(cube.surface_id); + return true; + } + return false; + }); } template