mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-10 08:51:28 +12: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:
parent
ad2add9574
commit
3e8dfede1c
1 changed files with 35 additions and 18 deletions
|
@ -42,7 +42,7 @@ namespace vk
|
||||||
class resource_manager
|
class resource_manager
|
||||||
{
|
{
|
||||||
private:
|
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;
|
std::deque<eid_scope_t> m_eid_map;
|
||||||
|
|
||||||
eid_scope_t& get_current_eid_scope()
|
eid_scope_t& get_current_eid_scope()
|
||||||
|
@ -61,6 +61,28 @@ namespace vk
|
||||||
return m_eid_map.back();
|
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:
|
public:
|
||||||
|
|
||||||
resource_manager() = default;
|
resource_manager() = default;
|
||||||
|
@ -78,26 +100,21 @@ namespace vk
|
||||||
VkBool32 depth_compare = VK_FALSE, VkCompareOp depth_compare_mode = VK_COMPARE_OP_NEVER)
|
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;
|
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(min_filter) << 10 | u64(mag_filter) << 11; // 1 bit each
|
||||||
key |= u64(mipmap_mode) << 12; // 1 bit
|
key |= u64(mipmap_mode) << 12; // 1 bit
|
||||||
key |= u64(border_color) << 13; // 3 bits
|
key |= u64(border_color) << 13; // 3 bits
|
||||||
key |= u64(depth_compare) << 16; // 1 bit
|
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<true>(mipLodBias)) << 44; // 13 bits
|
||||||
|
key |= u64(max_anisotropy) << 57; // 4 bits
|
||||||
|
|
||||||
const auto found = m_sampler_pool.equal_range(key);
|
if (const auto found = m_sampler_pool.find(key);
|
||||||
for (auto It = found.first; It != found.second; ++It)
|
found != m_sampler_pool.end())
|
||||||
{
|
{
|
||||||
const auto& info = It->second->info;
|
return found->second.get();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = std::make_unique<vk::sampler>(
|
auto result = std::make_unique<vk::sampler>(
|
||||||
|
@ -107,7 +124,7 @@ namespace vk
|
||||||
depth_compare, depth_compare_mode);
|
depth_compare, depth_compare_mode);
|
||||||
|
|
||||||
auto It = m_sampler_pool.emplace(key, std::move(result));
|
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)
|
void dispose(std::unique_ptr<vk::buffer>& buf)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue