diff --git a/rpcs3/Emu/RSX/VK/VKResourceManager.cpp b/rpcs3/Emu/RSX/VK/VKResourceManager.cpp index 5142b0ce6f..02c4573bcd 100644 --- a/rpcs3/Emu/RSX/VK/VKResourceManager.cpp +++ b/rpcs3/Emu/RSX/VK/VKResourceManager.cpp @@ -54,19 +54,16 @@ namespace vk ensure(max_allowed_samplers); rsx_log.warning("Trimming allocated samplers. Allocated = %u, Max = %u", allocated_sampler_count, limits.maxSamplerAllocationCount); -#if 0 - for (auto It = m_sampler_pool.begin(); It != m_sampler_pool.end();) + auto filter_expr = [](const cached_sampler_object_t& sampler) { - if (!It->second->has_refs()) - { - dispose(It->second); - It = m_sampler_pool.erase(It); - continue; - } + // Pick only where we have no ref + return !sampler.has_refs(); + }; - ++It; + for (auto& object : m_sampler_pool.collect(filter_expr)) + { + dispose(object); } -#endif } } diff --git a/rpcs3/Emu/RSX/VK/vkutils/sampler.cpp b/rpcs3/Emu/RSX/VK/vkutils/sampler.cpp index 2e4d5f77c4..f5e957329f 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/sampler.cpp +++ b/rpcs3/Emu/RSX/VK/vkutils/sampler.cpp @@ -186,4 +186,29 @@ namespace vk m_custom_color_sampler_pool.emplace (key.base_key, std::move(object)); } + + std::vector> sampler_pool_t::collect(std::function predicate) + { + std::vector> result; + + const auto collect_fn = [&](auto& container) + { + for (auto It = container.begin(); It != container.end();) + { + if (!predicate(*It->second)) + { + It++; + continue; + } + + result.emplace_back(std::move(It->second)); + It = container.erase(It); + } + }; + + collect_fn(m_generic_sampler_pool); + collect_fn(m_custom_color_sampler_pool); + + return result; + } } diff --git a/rpcs3/Emu/RSX/VK/vkutils/sampler.h b/rpcs3/Emu/RSX/VK/vkutils/sampler.h index 3faaa66414..f231350b43 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/sampler.h +++ b/rpcs3/Emu/RSX/VK/vkutils/sampler.h @@ -83,5 +83,7 @@ namespace vk vk::sampler* find(const sampler_pool_key_t& key) const; void emplace(const sampler_pool_key_t& key, std::unique_ptr& object); + + std::vector> collect(std::function predicate); }; }