]> git.tdb.fi Git - libs/gl.git/commitdiff
Update usage of hash functions
authorMikko Rasa <tdb@tdb.fi>
Wed, 17 Nov 2021 12:45:15 +0000 (14:45 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 17 Nov 2021 12:45:15 +0000 (14:45 +0200)
Calculating hashes directly from the binary values is faster than first
creating a string.

source/core/reflectdata.cpp
source/core/tag.cpp
source/glsl/finalize.cpp
source/glsl/generate.cpp
source/materials/material.cpp

index db6798730cd4c9c9097e86735beeabed8e8114c3..8ecb9abe08fe11eac8e7fd845ebc9dc0fabaf9df 100644 (file)
@@ -10,10 +10,12 @@ namespace GL {
 
 void ReflectData::update_layout_hash()
 {
-       string layout_descriptor;
+       layout_hash = hash<32>(uniform_blocks.size());
        for(const UniformBlockInfo &b: uniform_blocks)
-               layout_descriptor += format("%d:%x\n", b.bind_point, b.layout_hash);
-       layout_hash = hash32(layout_descriptor);
+       {
+               layout_hash = hash_update<32>(layout_hash, b.bind_point);
+               layout_hash = hash_update<32>(layout_hash, b.layout_hash);
+       }
 }
 
 
@@ -24,10 +26,14 @@ void ReflectData::UniformBlockInfo::sort_uniforms()
 
 void ReflectData::UniformBlockInfo::update_layout_hash()
 {
-       string layout_descriptor;
+       layout_hash = hash<32>(uniforms.size());
        for(const UniformInfo *u: uniforms)
-               layout_descriptor += format("%d:%s:%x:%d\n", u->location, u->name, u->type, u->array_size);
-       layout_hash = hash32(layout_descriptor);
+       {
+               layout_hash = hash_update<32>(layout_hash, u->location);
+               layout_hash = hash_update<32>(layout_hash, u->name);
+               layout_hash = hash_update<32>(layout_hash, u->type);
+               layout_hash = hash_update<32>(layout_hash, u->array_size);
+       }
 }
 
 } // namespace GL
index 56236c19554931c87794b7e02e1973437a715d19..84eb074a4361c9d9a4888d861266f802ba778b78 100644 (file)
@@ -22,7 +22,7 @@ namespace Msp {
 namespace GL {
 
 Tag::Tag(const char *s):
-       id((s && *s) ? hash32(s, strlen(s)) : 0)
+       id((s && *s) ? hash<32>(s, strlen(s)) : 0)
 {
 #ifdef DEBUG
        if(s)
@@ -31,7 +31,7 @@ Tag::Tag(const char *s):
 }
 
 Tag::Tag(const string &s):
-       id(s.empty() ? 0 : hash32(s))
+       id(s.empty() ? 0 : hash<32>(s))
 {
 #ifdef DEBUG
        if(!s.empty())
index 60312be8adf8fc09cdb6a55ed76de342b9f3da46..52cf95804245767ec1e487619313e87d66ee17dc 100644 (file)
@@ -156,7 +156,7 @@ void LocationAllocator::bind_uniform(RefPtr<Layout> &layout, const string &name,
        {
                set<unsigned> &used = used_bindings[desc_set];
 
-               unsigned bind_point = fold32(hash64(name))%range;
+               unsigned bind_point = hash_fold<32>(hash<64>(name))%range;
                while(used.count(bind_point))
                        bind_point = (bind_point+1)%range;
 
index c82d1c6c58e4a59ef025fa3cf3f13c80b580342c..85c3009bc312e6426b570d4f85451aad7a146752 100644 (file)
@@ -22,7 +22,7 @@ void ConstantIdAssigner::apply(Module &module, const Features &features)
                        id = j->second;
                else
                {
-                       id = hash32(v->name)%features.constant_id_range;
+                       id = hash<32>(v->name)%features.constant_id_range;
                        while(used_ids.count(id))
                                id = (id+1)%features.constant_id_range;
                }
index 6d9c0571f429f37e8c2ce265ca8c88e92bfaf70c..a34c0457384025f2af87f91ed45fac78dd042835 100644 (file)
@@ -20,12 +20,15 @@ const Program *Material::create_compatible_shader(const map<string, int> &extra_
        for(const auto &kvp: extra_spec)
                spec_values[kvp.first] = kvp.second;
 
-       string info = module_name;
+       uint64_t info_hash = hash<64>(module_name);
        for(const auto &kvp: spec_values)
-               info += format(",%s:%d", kvp.first, kvp.second);
+       {
+               info_hash = hash_update<64>(info_hash, kvp.first);
+               info_hash = hash_update<64>(info_hash, kvp.second);
+       }
 
        Resources &res = Resources::get_global();
-       string name = format("_material_%016x.shader", hash64(info));
+       string name = format("_material_%016x.shader", info_hash);
        Program *shprog = res.find<Program>(name);
        if(shprog)
                return shprog;