From: Mikko Rasa Date: Wed, 10 Nov 2021 22:35:45 +0000 (+0200) Subject: Assign the same specialization constant IDs in all stages X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=8c379c40892fc0e11cf2d40f4784c6e6aa1a12d7;p=libs%2Fgl.git Assign the same specialization constant IDs in all stages --- diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index ec51c19c..c82d1c6c 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -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); + } } } } diff --git a/source/glsl/generate.h b/source/glsl/generate.h index fc58b2db..d828daa5 100644 --- a/source/glsl/generate.h +++ b/source/glsl/generate.h @@ -16,6 +16,7 @@ class ConstantIdAssigner: private TraversingVisitor { private: std::set used_ids; + std::map existing_constants; std::vector auto_constants; public: