]> git.tdb.fi Git - libs/gl.git/commitdiff
Assign the same specialization constant IDs in all stages
authorMikko Rasa <tdb@tdb.fi>
Wed, 10 Nov 2021 22:35:45 +0000 (00:35 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 10 Nov 2021 23:39:41 +0000 (01:39 +0200)
source/glsl/generate.cpp
source/glsl/generate.h

index ec51c19cdd9cc90472a0b2471eff915823fae0d7..c82d1c6c58e4a59ef025fa3cf3f13c80b580342c 100644 (file)
@@ -16,9 +16,16 @@ void ConstantIdAssigner::apply(Module &module, const Features &features)
 
        for(VariableDeclaration *v: auto_constants)
        {
-               unsigned id = hash32(v->name)%features.constant_id_range;
-               while(used_ids.count(id))
-                       id = (id+1)%features.constant_id_range;
+               unsigned id;
+               auto j = existing_constants.find(v->name);
+               if(j!=existing_constants.end())
+                       id = j->second;
+               else
+               {
+                       id = hash32(v->name)%features.constant_id_range;
+                       while(used_ids.count(id))
+                               id = (id+1)%features.constant_id_range;
+               }
 
                auto i = find_member(v->layout->qualifiers, string("constant_id"), &Layout::Qualifier::name);
                if(i!=v->layout->qualifiers.end())
@@ -38,7 +45,10 @@ void ConstantIdAssigner::visit(VariableDeclaration &var)
                        if(i->value==-1)
                                auto_constants.push_back(&var);
                        else
+                       {
+                               existing_constants[var.name] = i->value;
                                used_ids.insert(i->value);
+                       }
                }
        }
 }
index fc58b2db16134108cf4e7fa653d6c1a6258b9ce3..d828daa5172716cb6c173e129cd5c8d6126fb452 100644 (file)
@@ -16,6 +16,7 @@ class ConstantIdAssigner: private TraversingVisitor
 {
 private:
        std::set<unsigned> used_ids;
+       std::map<std::string, unsigned> existing_constants;
        std::vector<VariableDeclaration *> auto_constants;
 
 public: