From 8c379c40892fc0e11cf2d40f4784c6e6aa1a12d7 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 11 Nov 2021 00:35:45 +0200 Subject: [PATCH] Assign the same specialization constant IDs in all stages --- source/glsl/generate.cpp | 16 +++++++++++++--- source/glsl/generate.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) 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: -- 2.45.2