rsx: Refactor texture cache utils

- Also lays groundwork for optional hashed sections
This commit is contained in:
kd-11
2021-01-25 19:31:00 +03:00
committed by kd-11
parent 8d6504d6e3
commit 1bad9a939f
10 changed files with 465 additions and 395 deletions
+13 -3
View File
@@ -4,23 +4,33 @@
namespace rpcs3
{
constexpr usz fnv_seed = 14695981039346656037ull;
constexpr usz fnv_prime = 1099511628211ull;
template<typename T>
static usz hash_base(T value)
{
return static_cast<usz>(value);
}
template<typename T, typename = std::enable_if_t<std::is_integral<T>::value, bool>>
static inline usz hash64(usz hash_value, const T data)
{
hash_value ^= data;
hash_value *= fnv_prime;
return hash_value;
}
template<typename T, typename U>
static usz hash_struct_base(const T& value)
{
// FNV 64-bit
usz result = 14695981039346656037ull;
usz result = fnv_seed;
const U *bits = reinterpret_cast<const U*>(&value);
for (usz n = 0; n < (sizeof(T) / sizeof(U)); ++n)
{
result ^= bits[n];
result *= 1099511628211ull;
result = hash64(result, bits[n]);
}
return result;