]> git.tdb.fi Git - libs/gl.git/commitdiff
Propagate locations from existing variables before optimization
authorMikko Rasa <tdb@tdb.fi>
Thu, 11 Nov 2021 10:49:08 +0000 (12:49 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 11 Nov 2021 10:49:08 +0000 (12:49 +0200)
Uniform location and binding qualifiers should apply to all copies of the
variable even if the one originally containing them is optimized out.

source/glsl/compiler.cpp
source/glsl/finalize.cpp
source/glsl/finalize.h

index e676fcc87233764cc529fe98203bc5d8b666df0f..4e9f94d86b51e0044786927f7bc77c6d8e32c720 100644 (file)
@@ -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);
index 7eb0165dc5b82156d6a71caca7953508ad74aa33..cb304aa31d6b979efab1d9e3f63659be10334e3d 100644 (file)
@@ -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<unsigned> &used = used_locations[(*i)->interface];
 
                unsigned size = LocationCounter().apply(**i);
@@ -142,7 +146,7 @@ void LocationAllocator::bind_uniform(RefPtr<Layout> &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<unsigned> &used = used_bindings[0];
 
index bde0618abf2bc3dc5d73f57209486f575fa1e1b6..ab4276f560420b3e289cd7d1a912efa1a83c22b4 100644 (file)
@@ -36,6 +36,7 @@ private:
                Uniform(): location(-1), desc_set(-1), bind_point(-1) { }
        };
 
+       bool alloc_new = true;
        std::map<std::string, std::set<unsigned> > used_locations;
        std::map<std::string, Uniform> uniforms;
        std::map<unsigned, std::set<unsigned> > used_bindings;
@@ -44,7 +45,7 @@ private:
        std::vector<InterfaceBlock *> unbound_blocks;
 
 public:
-       void apply(Module &, const Features &);
+       void apply(Module &, const Features &, bool = true);
 private:
        void apply(Stage &);