summaryrefslogtreecommitdiff
path: root/servers/rendering/renderer_rd
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2022-06-18 16:20:55 +0200
committerreduz <reduzio@gmail.com>2022-06-20 12:54:19 +0200
commit141c3755814cea60888c7ee548c7ce709550b784 (patch)
treecc5045d98995b754097d1dde100f0138033fc735 /servers/rendering/renderer_rd
parent8e3d9a23aa0a724d3dd25fcf0e8085b5a438c233 (diff)
Clean up Hash Functions
Clean up and do fixes to hash functions and newly introduced murmur3 hashes in #61934 * Clean up usage of murmur3 * Fixed usages of binary murmur3 on floats (this is invalid) * Changed DJB2 to use xor (which seems to be better)
Diffstat (limited to 'servers/rendering/renderer_rd')
-rw-r--r--servers/rendering/renderer_rd/uniform_set_cache_rd.h18
1 files changed, 10 insertions, 8 deletions
diff --git a/servers/rendering/renderer_rd/uniform_set_cache_rd.h b/servers/rendering/renderer_rd/uniform_set_cache_rd.h
index e49cf4dafa..af22a48716 100644
--- a/servers/rendering/renderer_rd/uniform_set_cache_rd.h
+++ b/servers/rendering/renderer_rd/uniform_set_cache_rd.h
@@ -57,13 +57,13 @@ class UniformSetCacheRD : public Object {
Cache *hash_table[HASH_TABLE_SIZE] = {};
static _FORCE_INLINE_ uint32_t _hash_uniform(const RD::Uniform &u, uint32_t h) {
- h = hash_djb2_one_32(u.uniform_type, h);
- h = hash_djb2_one_32(u.binding, h);
+ h = hash_murmur3_one_32(u.uniform_type, h);
+ h = hash_murmur3_one_32(u.binding, h);
uint32_t rsize = u.get_id_count();
for (uint32_t j = 0; j < rsize; j++) {
- h = hash_djb2_one_64(u.get_id(j).get_id(), h);
+ h = hash_murmur3_one_64(u.get_id(j).get_id(), h);
}
- return h;
+ return hash_fmix32(h);
}
static _FORCE_INLINE_ bool _compare_uniform(const RD::Uniform &a, const RD::Uniform &b) {
@@ -154,8 +154,8 @@ class UniformSetCacheRD : public Object {
public:
template <typename... Args>
RID get_cache(RID p_shader, uint32_t p_set, Args... args) {
- uint32_t h = hash_djb2_one_64(p_shader.get_id());
- h = hash_djb2_one_32(p_set, h);
+ uint32_t h = hash_murmur3_one_64(p_shader.get_id());
+ h = hash_murmur3_one_32(p_set, h);
h = _hash_args(h, args...);
uint32_t table_idx = h % HASH_TABLE_SIZE;
@@ -180,12 +180,14 @@ public:
template <typename... Args>
RID get_cache_vec(RID p_shader, uint32_t p_set, const Vector<RD::Uniform> &p_uniforms) {
- uint32_t h = hash_djb2_one_64(p_shader.get_id());
- h = hash_djb2_one_32(p_set, h);
+ uint32_t h = hash_murmur3_one_64(p_shader.get_id());
+ h = hash_murmur3_one_32(p_set, h);
for (int i = 0; i < p_uniforms.size(); i++) {
h = _hash_uniform(p_uniforms[i], h);
}
+ h = hash_fmix32(h);
+
uint32_t table_idx = h % HASH_TABLE_SIZE;
{
const Cache *c = hash_table[table_idx];