From 3e8dfede1c4d4b9dec778e9a199fc24ab402e222 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sat, 26 Oct 2019 01:06:10 +0300 Subject: [PATCH] vk: Modify sampler cache to uniquely identify all the input parameters - Avoids iteration when variable mipmap counts or lod bias parameters change --- rpcs3/Emu/RSX/VK/VKResourceManager.h | 53 ++++++++++++++++++---------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/rpcs3/Emu/RSX/VK/VKResourceManager.h b/rpcs3/Emu/RSX/VK/VKResourceManager.h index fbd2f196b5..b2ae0364f0 100644 --- a/rpcs3/Emu/RSX/VK/VKResourceManager.h +++ b/rpcs3/Emu/RSX/VK/VKResourceManager.h @@ -42,7 +42,7 @@ namespace vk class resource_manager { private: - std::unordered_multimap> m_sampler_pool; + std::unordered_map> m_sampler_pool; std::deque m_eid_map; eid_scope_t& get_current_eid_scope() @@ -61,6 +61,28 @@ namespace vk return m_eid_map.back(); } + template + u16 encode_fxp(f32 value) + { + u16 raw = u16(std::abs(value) * 256.); + + if constexpr (!_signed) + { + return raw; + } + else + { + if (LIKELY(value >= 0.f)) + { + return raw; + } + else + { + return u16(0 - raw) & 0x1fff; + } + } + } + public: resource_manager() = default; @@ -78,26 +100,21 @@ namespace vk VkBool32 depth_compare = VK_FALSE, VkCompareOp depth_compare_mode = VK_COMPARE_OP_NEVER) { u64 key = u16(clamp_u) | u64(clamp_v) << 3 | u64(clamp_w) << 6; - key |= u64(unnormalized_coordinates) << 9; // 1 bit + key |= u64(unnormalized_coordinates) << 9; // 1 bit key |= u64(min_filter) << 10 | u64(mag_filter) << 11; // 1 bit each - key |= u64(mipmap_mode) << 12; // 1 bit - key |= u64(border_color) << 13; // 3 bits + key |= u64(mipmap_mode) << 12; // 1 bit + key |= u64(border_color) << 13; // 3 bits key |= u64(depth_compare) << 16; // 1 bit - key |= u64(depth_compare_mode) << 17; // 3 bits + key |= u64(depth_compare_mode) << 17; // 3 bits + key |= u64(encode_fxp(min_lod)) << 20; // 12 bits + key |= u64(encode_fxp(max_lod)) << 32; // 12 bits + key |= u64(encode_fxp(mipLodBias)) << 44; // 13 bits + key |= u64(max_anisotropy) << 57; // 4 bits - const auto found = m_sampler_pool.equal_range(key); - for (auto It = found.first; It != found.second; ++It) + if (const auto found = m_sampler_pool.find(key); + found != m_sampler_pool.end()) { - const auto& info = It->second->info; - if (!rsx::fcmp(info.maxLod, max_lod) || - !rsx::fcmp(info.mipLodBias, mipLodBias) || - !rsx::fcmp(info.minLod, min_lod) || - !rsx::fcmp(info.maxAnisotropy, max_anisotropy)) - { - continue; - } - - return It->second.get(); + return found->second.get(); } auto result = std::make_unique( @@ -107,7 +124,7 @@ namespace vk depth_compare, depth_compare_mode); auto It = m_sampler_pool.emplace(key, std::move(result)); - return It->second.get(); + return It.first->second.get(); } void dispose(std::unique_ptr& buf)