X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Ffinalize.cpp;h=52cf95804245767ec1e487619313e87d66ee17dc;hb=5871764de7aa23d2c40cac03ad9d07088fb57e06;hp=7eb0165dc5b82156d6a71caca7953508ad74aa33;hpb=efbce87192ce73ba577684369f759693dccec67c;p=libs%2Fgl.git diff --git a/source/glsl/finalize.cpp b/source/glsl/finalize.cpp index 7eb0165d..52cf9580 100644 --- a/source/glsl/finalize.cpp +++ b/source/glsl/finalize.cpp @@ -62,8 +62,10 @@ void StructOrganizer::visit(VariableDeclaration &var) } -void LocationAllocator::apply(Module &module, const Features &features) +void LocationAllocator::apply(Module &module, const Features &f, bool a) { + features = f; + alloc_new = a; for(Stage &s: module.stages) apply(s); @@ -111,6 +113,9 @@ void LocationAllocator::allocate_locations(const string &iface) } } + if(!alloc_new) + continue; + set &used = used_locations[(*i)->interface]; unsigned size = LocationCounter().apply(**i); @@ -140,13 +145,18 @@ void LocationAllocator::allocate_locations(const string &iface) void LocationAllocator::bind_uniform(RefPtr &layout, const string &name, unsigned range) { auto i = uniforms.find(name); + + int desc_set = (i!=uniforms.end() ? i->second.desc_set : 0); + if(features.target_api==VULKAN && get_layout_value(layout.get(), "set")<0) + add_layout_qualifier(layout, Layout::Qualifier("set", desc_set)); + 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]; + set &used = used_bindings[desc_set]; - unsigned bind_point = fold32(hash64(name))%range; + unsigned bind_point = hash_fold<32>(hash<64>(name))%range; while(used.count(bind_point)) bind_point = (bind_point+1)%range; @@ -158,12 +168,28 @@ void LocationAllocator::bind_uniform(RefPtr &layout, const string &name, bool LocationAllocator::visit_uniform(const string &name, RefPtr &layout) { + int desc_set = 0; int bind_point = get_layout_value(layout.get(), "binding"); + + if(features.target_api==VULKAN) + { + desc_set = get_layout_value(layout.get(), "set"); + if(desc_set<0 && bind_point>=0) + { + desc_set = 0; + add_layout_qualifier(layout, Layout::Qualifier("set", desc_set)); + } + + if(desc_set>=0) + uniforms[name].desc_set = desc_set; + } + if(bind_point>=0) { - used_bindings[0].insert(bind_point); + used_bindings[desc_set].insert(bind_point); uniforms[name].bind_point = bind_point; } + return bind_point>=0; }