1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-23 03:02:53 +01:00

vk: Modify sampler cache to uniquely identify all the input parameters

- Avoids iteration when variable mipmap counts or lod bias parameters change
This commit is contained in:
kd-11 2019-10-26 01:06:10 +03:00 committed by kd-11
parent ad2add9574
commit 3e8dfede1c

View File

@ -42,7 +42,7 @@ namespace vk
class resource_manager
{
private:
std::unordered_multimap<u64, std::unique_ptr<vk::sampler>> m_sampler_pool;
std::unordered_map<u64, std::unique_ptr<vk::sampler>> m_sampler_pool;
std::deque<eid_scope_t> m_eid_map;
eid_scope_t& get_current_eid_scope()
@ -61,6 +61,28 @@ namespace vk
return m_eid_map.back();
}
template<bool _signed = false>
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;
@ -84,20 +106,15 @@ namespace vk
key |= u64(border_color) << 13; // 3 bits
key |= u64(depth_compare) << 16; // 1 bit
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<true>(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<vk::sampler>(
@ -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<vk::buffer>& buf)