From: Mikko Rasa Date: Thu, 11 Nov 2021 10:49:08 +0000 (+0200) Subject: Propagate locations from existing variables before optimization X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=89de98315588ec89ad66e9a4f3f90bf03e1f7733;p=libs%2Fgl.git Propagate locations from existing variables before optimization Uniform location and binding qualifiers should apply to all copies of the variable even if the one originally containing them is optimized out. --- diff --git a/source/glsl/compiler.cpp b/source/glsl/compiler.cpp index e676fcc8..4e9f94d8 100644 --- a/source/glsl/compiler.cpp +++ b/source/glsl/compiler.cpp @@ -75,6 +75,7 @@ void Compiler::compile(Mode mode) for(Stage &s: module->stages) generate(s); ConstantIdAssigner().apply(*module, features); + LocationAllocator().apply(*module, features, false); for(Stage &s: module->stages) validate(s); diff --git a/source/glsl/finalize.cpp b/source/glsl/finalize.cpp index 7eb0165d..cb304aa3 100644 --- a/source/glsl/finalize.cpp +++ b/source/glsl/finalize.cpp @@ -62,8 +62,9 @@ void StructOrganizer::visit(VariableDeclaration &var) } -void LocationAllocator::apply(Module &module, const Features &features) +void LocationAllocator::apply(Module &module, const Features &features, bool a) { + alloc_new = a; for(Stage &s: module.stages) apply(s); @@ -111,6 +112,9 @@ void LocationAllocator::allocate_locations(const string &iface) } } + if(!alloc_new) + continue; + set &used = used_locations[(*i)->interface]; unsigned size = LocationCounter().apply(**i); @@ -142,7 +146,7 @@ void LocationAllocator::bind_uniform(RefPtr &layout, const string &name, auto i = uniforms.find(name); if(i!=uniforms.end() && i->second.bind_point>=0) add_layout_qualifier(layout, Layout::Qualifier("binding", i->second.bind_point)); - else + else if(alloc_new) { set &used = used_bindings[0]; diff --git a/source/glsl/finalize.h b/source/glsl/finalize.h index bde0618a..ab4276f5 100644 --- a/source/glsl/finalize.h +++ b/source/glsl/finalize.h @@ -36,6 +36,7 @@ private: Uniform(): location(-1), desc_set(-1), bind_point(-1) { } }; + bool alloc_new = true; std::map > used_locations; std::map uniforms; std::map > used_bindings; @@ -44,7 +45,7 @@ private: std::vector unbound_blocks; public: - void apply(Module &, const Features &); + void apply(Module &, const Features &, bool = true); private: void apply(Stage &);