]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/finalize.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / glsl / finalize.cpp
index eee8a5198efa8b2037848bcc7a34bd8cd0d333ff..469cb92daba088493168f82f55e47a4b5938dccd 100644 (file)
@@ -12,10 +12,6 @@ namespace Msp {
 namespace GL {
 namespace SL {
 
-StructOrganizer::StructOrganizer():
-       offset(-1)
-{ }
-
 void StructOrganizer::visit(StructDeclaration &strct)
 {
        SetForScope<int> set_offset(offset, 0);
@@ -50,12 +46,7 @@ void StructOrganizer::visit(VariableDeclaration &var)
                if(layout_offset)
                        *layout_offset = offset;
                else
-               {
-                       if(!var.layout)
-                               var.layout = new Layout;
-
-                       var.layout->qualifiers.push_back(Layout::Qualifier("offset", offset));
-               }
+                       add_layout_qualifier(var.layout, Layout::Qualifier("offset", offset));
 
                if(!has_matrix_order)
                {
@@ -63,7 +54,7 @@ void StructOrganizer::visit(VariableDeclaration &var)
                        while(basic && basic->kind==BasicTypeDeclaration::ARRAY)
                                basic = dynamic_cast<const BasicTypeDeclaration *>(basic->base_type);
                        if(basic && basic->kind==BasicTypeDeclaration::MATRIX)
-                               var.layout->qualifiers.push_back(Layout::Qualifier("column_major"));
+                               add_layout_qualifier(var.layout, Layout::Qualifier("column_major"));
                }
 
                offset += mem_reqs.size;
@@ -71,16 +62,25 @@ 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);
-       allocate_locations("uniform");
 
-       for(InterfaceBlock *b: unbound_blocks)
-               bind_uniform(b->layout, b->block_name, features.uniform_binding_range);
+       if(features.target_api!=VULKAN)
+               allocate_locations("uniform");
+
+       for(VariableDeclaration *b: unbound_blocks)
+               bind_uniform(b->layout, b->block_declaration->block_name, features.uniform_binding_range);
        for(VariableDeclaration *t: unbound_textures)
-               bind_uniform(t->layout, t->name, features.texture_binding_range);
+       {
+               const TypeDeclaration *base_type = get_ultimate_base_type(t->type_declaration);
+               unsigned range = (static_cast<const ImageTypeDeclaration *>(base_type)->sampled ?
+                       features.texture_binding_range : features.storage_texture_binding_range);
+               bind_uniform(t->layout, t->name, range);
+       }
 }
 
 void LocationAllocator::apply(Stage &stage)
@@ -91,6 +91,8 @@ void LocationAllocator::apply(Stage &stage)
        stage.content.visit(*this);
 
        allocate_locations("in");
+       if(stage.type==Stage::VERTEX)
+               swap(used_locations["in"], used_vertex_attribs);
        allocate_locations("out");
 }
 
@@ -113,11 +115,16 @@ void LocationAllocator::allocate_locations(const string &iface)
                        auto j = uniforms.find((*i)->name);
                        if(j!=uniforms.end() && j->second.location>=0)
                        {
-                               add_layout_value((*i)->layout, "location", j->second.location);
+                               add_layout_qualifier((*i)->layout, Layout::Qualifier("location", j->second.location));
                                continue;
                        }
                }
 
+               if(!alloc_new)
+                       continue;
+
+               bool flat = ((*i)->interpolation=="flat" || ((*i)->linked_declaration && (*i)->linked_declaration->interpolation=="flat"));
+
                set<unsigned> &used = used_locations[(*i)->interface];
 
                unsigned size = LocationCounter().apply(**i);
@@ -125,14 +132,14 @@ void LocationAllocator::allocate_locations(const string &iface)
                {
                        int blocking = -1;
                        for(unsigned j=0; j<size; ++j)
-                               if(used.count(next+j))
+                               if(used.count(next+j) || (flat && used_vertex_attribs.count(next+j)))
                                        blocking = next+j;
                        if(blocking<0)
                                break;
                        next = blocking+1;
                }
 
-               add_layout_value((*i)->layout, "location", next);
+               add_layout_qualifier((*i)->layout, Layout::Qualifier("location", next));
                if((*i)->interface=="uniform")
                        uniforms[(*i)->name].location = next;
 
@@ -147,28 +154,56 @@ void LocationAllocator::allocate_locations(const string &iface)
 void LocationAllocator::bind_uniform(RefPtr<Layout> &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_value(layout, "binding", i->second.bind_point);
-       else
+               add_layout_qualifier(layout, Layout::Qualifier("binding", i->second.bind_point));
+       else if(alloc_new)
        {
-               set<unsigned> &used = used_bindings[0];
+               set<unsigned> &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;
 
-               add_layout_value(layout, "binding", bind_point);
+               add_layout_qualifier(layout, Layout::Qualifier("binding", bind_point));
                uniforms[name].bind_point = bind_point;
                used.insert(bind_point);
        }
 }
 
-void LocationAllocator::add_layout_value(RefPtr<Layout> &layout, const string &name, unsigned value)
+bool LocationAllocator::visit_uniform(const string &name, RefPtr<Layout> &layout)
 {
-       if(!layout)
-               layout = new Layout;
+       int desc_set = get_layout_value(layout.get(), "set");
+       int bind_point = get_layout_value(layout.get(), "binding");
 
-       layout->qualifiers.push_back(Layout::Qualifier(name, value));
+       if(features.target_api==VULKAN)
+       {
+               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;
+       }
+       else if(desc_set>=0 && bind_point<0)
+       {
+               auto i = find_member(layout->qualifiers, string("set"), &Layout::Qualifier::name);
+               layout->qualifiers.erase(i);
+       }
+
+       if(bind_point>=0)
+       {
+               used_bindings[desc_set].insert(bind_point);
+               uniforms[name].bind_point = bind_point;
+       }
+
+       return bind_point>=0;
 }
 
 void LocationAllocator::visit(VariableDeclaration &var)
@@ -176,15 +211,15 @@ void LocationAllocator::visit(VariableDeclaration &var)
        if(!var.name.compare(0, 3, "gl_"))
                return;
 
-       if(!var.interface.empty())
+       if(!var.interface.empty() && !var.block_declaration)
        {
-               int location = (var.layout ? get_layout_value(*var.layout, "location") : -1);
+               int location = get_layout_value(var.layout.get(), "location");
 
                if(location<0 && var.linked_declaration && var.linked_declaration->layout)
                {
-                       location = get_layout_value(*var.linked_declaration->layout, "location");
+                       location = get_layout_value(var.linked_declaration->layout.get(), "location");
                        if(location>=0)
-                               add_layout_value(var.layout, "location", location);
+                               add_layout_qualifier(var.layout, Layout::Qualifier("location", location));
                }
 
                if(location>=0)
@@ -201,46 +236,104 @@ void LocationAllocator::visit(VariableDeclaration &var)
 
        if(var.interface=="uniform")
        {
-               const TypeDeclaration *type = var.type_declaration;
-               while(const BasicTypeDeclaration *basic = dynamic_cast<const BasicTypeDeclaration *>(type))
-                       type = basic->base_type;
-               if(dynamic_cast<const ImageTypeDeclaration *>(type))
+               if(var.block_declaration)
                {
-                       int bind_point = (var.layout ? get_layout_value(*var.layout, "binding") : -1);
-                       if(bind_point>=0)
-                       {
-                               used_bindings[0].insert(bind_point);
-                               uniforms[var.name].bind_point = bind_point;
-                       }
-                       else
+                       bool push_constant = has_layout_qualifier(var.layout.get(), "push_constant");
+                       if(!push_constant && !visit_uniform(var.block_declaration->block_name, var.layout))
+                               unbound_blocks.push_back(&var);
+               }
+               else
+               {
+                       const TypeDeclaration *base_type = get_ultimate_base_type(var.type_declaration);
+                       if(dynamic_cast<const ImageTypeDeclaration *>(base_type) && !visit_uniform(var.name, var.layout))
                                unbound_textures.push_back(&var);
                }
        }
 }
 
-void LocationAllocator::visit(InterfaceBlock &iface)
+
+void DepthRangeConverter::apply(Stage &stage, const Features &features)
 {
-       if(!iface.instance_name.compare(0, 3, "gl_"))
+       if(stage.type!=Stage::VERTEX || features.target_api==VULKAN)
                return;
 
-       if(iface.interface=="uniform")
-       {
-               int bind_point = (iface.layout ? get_layout_value(*iface.layout, "binding") : -1);
+       stage.content.visit(*this);
+}
 
-               if(bind_point>=0)
-               {
-                       used_bindings[0].insert(bind_point);
-                       uniforms[iface.block_name].bind_point = bind_point;
-               }
-               else
-                       unbound_blocks.push_back(&iface);
+void DepthRangeConverter::visit(VariableReference &var)
+{
+       const StructDeclaration *strct = dynamic_cast<const StructDeclaration *>(var.type);
+       r_gl_pervertex = (strct && strct->block_name=="gl_PerVertex");
+}
+
+void DepthRangeConverter::visit(MemberAccess &memacc)
+{
+       r_gl_pervertex = false;
+       memacc.left->visit(*this);
+       r_gl_position = (r_gl_pervertex && memacc.member=="gl_Position");
+}
+
+void DepthRangeConverter::visit(Swizzle &swiz)
+{
+       r_gl_position = false;
+       swiz.left->visit(*this);
+       if(assignment_target && r_gl_position && swiz.count==1 && swiz.components[0]==2)
+               r_position_z_assigned = true;
+}
+
+void DepthRangeConverter::visit(Assignment &assign)
+{
+       {
+               SetFlag set_target(assignment_target);
+               assign.left->visit(*this);
        }
+       assign.right->visit(*this);
 }
 
+void DepthRangeConverter::visit(FunctionDeclaration &func)
+{
+       r_position_z_assigned = false;
+       TraversingVisitor::visit(func);
+
+       if(func.definition==&func && func.name=="main" && !r_position_z_assigned)
+       {
+               VariableReference *position = new VariableReference;
+               position->name = "gl_Position";
+
+               MemberAccess *z = new MemberAccess;
+               z->left = position;
+               z->member = "z";
+
+               Literal *scale = new Literal;
+               scale->token = "2.0";
+               scale->value = 2.0f;
+
+               BinaryExpression *multiply = new BinaryExpression;
+               multiply->oper = &Operator::get_operator("*", Operator::BINARY);
+               multiply->left = z;
+               multiply->right = scale;
+
+               MemberAccess *w = new MemberAccess;
+               w->left = position->clone();
+               w->member = "w";
+
+               BinaryExpression *subtract = new BinaryExpression;
+               subtract->oper = &Operator::get_operator("-", Operator::BINARY);
+               subtract->left = multiply;
+               subtract->right = w;
+
+               Assignment *assign = new Assignment;
+               assign->oper = &Operator::get_operator("=", Operator::BINARY);
+               assign->left = z->clone();
+               assign->right = subtract;
+
+               ExpressionStatement *statement = new ExpressionStatement;
+               statement->expression = assign;
+
+               func.body.body.push_back(statement);
+       }
+}
 
-PrecisionConverter::PrecisionConverter():
-       stage(0)
-{ }
 
 void PrecisionConverter::apply(Stage &s)
 {
@@ -261,7 +354,7 @@ void PrecisionConverter::visit(Block &block)
 
 void PrecisionConverter::visit(Precision &prec)
 {
-       if(stage->required_features.gl_api==OPENGL_ES2)
+       if(stage->required_features.target_api==OPENGL_ES)
                have_default.insert(prec.type);
        else
                nodes_to_remove.insert(&prec);
@@ -269,7 +362,7 @@ void PrecisionConverter::visit(Precision &prec)
 
 void PrecisionConverter::visit(VariableDeclaration &var)
 {
-       if(stage->required_features.gl_api!=OPENGL_ES2)
+       if(stage->required_features.target_api!=OPENGL_ES)
        {
                var.precision.clear();
                return;
@@ -308,27 +401,18 @@ void PrecisionConverter::visit(VariableDeclaration &var)
 }
 
 
-LegacyConverter::LegacyConverter():
-       frag_out(0)
-{ }
-
-void LegacyConverter::apply(Stage &s, const Features &feat)
+void FeatureConverter::apply(Stage &s, const Features &feat)
 {
        stage = &s;
        features = feat;
-       if(supports_stage(s.type))
-       {
-               s.content.visit(*this);
-               NodeRemover().apply(s, nodes_to_remove);
 
-               if(!stage->required_features.glsl_version)
-                       stage->required_features.glsl_version = Version(1, (stage->required_features.gl_api==OPENGL_ES2 ? 0 : 10));
-       }
-       else
-               unsupported(format("Stage %s is not supported", Stage::get_stage_name(s.type)));
+       if(!stage->required_features.glsl_version)
+               stage->required_features.glsl_version = Version(1, (stage->required_features.target_api==OPENGL_ES ? 0 : 10));
+
+       apply();
 }
 
-void LegacyConverter::unsupported(const string &reason)
+void FeatureConverter::unsupported(const string &reason)
 {
        Diagnostic diagnostic;
        diagnostic.severity = Diagnostic::ERR;
@@ -338,17 +422,7 @@ void LegacyConverter::unsupported(const string &reason)
        stage->diagnostics.push_back(diagnostic);
 }
 
-void LegacyConverter::visit(Block &block)
-{
-       for(auto i=block.body.begin(); i!=block.body.end(); ++i)
-       {
-               if(&block==&stage->content)
-                       uniform_insert_point = i;
-               (*i)->visit(*this);
-       }
-}
-
-bool LegacyConverter::check_version(const Version &feature_version) const
+bool FeatureConverter::check_version(const Version &feature_version) const
 {
        if(features.glsl_version<feature_version)
                return false;
@@ -358,7 +432,7 @@ bool LegacyConverter::check_version(const Version &feature_version) const
        return true;
 }
 
-bool LegacyConverter::check_extension(bool Features::*extension) const
+bool FeatureConverter::check_extension(bool Features::*extension) const
 {
        if(!(features.*extension))
                return false;
@@ -368,52 +442,111 @@ bool LegacyConverter::check_extension(bool Features::*extension) const
        return true;
 }
 
-bool LegacyConverter::supports_stage(Stage::Type st) const
+
+void StructuralFeatureConverter::apply()
 {
-       if(st==Stage::GEOMETRY)
+       if(supports_stage(stage->type))
        {
-               if(features.gl_api==OPENGL_ES2)
+               stage->content.visit(*this);
+               NodeRemover().apply(*stage, nodes_to_remove);
+       }
+       else
+               unsupported(format("Stage %s is not supported", Stage::get_stage_name(stage->type)));
+}
+
+void StructuralFeatureConverter::visit(Block &block)
+{
+       for(auto i=block.body.begin(); i!=block.body.end(); ++i)
+       {
+               if(&block==&stage->content)
+                       uniform_insert_point = i;
+               (*i)->visit(*this);
+       }
+}
+
+void StructuralFeatureConverter::visit(RefPtr<Expression> &expr)
+{
+       r_replaced_reference = 0;
+       expr->visit(*this);
+       if(r_replaced_reference)
+               expr = r_replaced_reference;
+       r_replaced_reference = 0;
+}
+
+bool StructuralFeatureConverter::supports_stage(Stage::Type st) const
+{
+       if(st==Stage::TESS_CONTROL || st==Stage::TESS_EVAL)
+       {
+               if(features.target_api==OPENGL_ES)
+                       return check_version(Version(3, 20));
+               else
+                       return check_version(Version(4, 0));
+       }
+       else if(st==Stage::GEOMETRY)
+       {
+               if(features.target_api==OPENGL_ES)
                        return check_version(Version(3, 20));
                else
                        return check_version(Version(1, 50));
        }
+       else if(st==Stage::COMPUTE)
+       {
+               if(features.target_api==OPENGL_ES)
+                       return check_version(Version(3, 10));
+               else
+                       return check_version(Version(4, 30));
+       }
        else
                return true;
 }
 
-bool LegacyConverter::supports_unified_interface_syntax() const
+bool StructuralFeatureConverter::supports_unified_interface_syntax() const
 {
-       if(features.gl_api==OPENGL_ES2)
+       if(features.target_api==OPENGL_ES)
                return check_version(Version(3, 0));
        else
                return check_version(Version(1, 30));
 }
 
-void LegacyConverter::visit(VariableReference &var)
+void StructuralFeatureConverter::visit(VariableReference &var)
 {
        if(var.declaration==frag_out && !supports_unified_interface_syntax())
        {
                var.name = "gl_FragColor";
                var.declaration = 0;
        }
+
+       r_flattened_interface = nodes_to_remove.count(var.declaration);
+}
+
+void StructuralFeatureConverter::visit(MemberAccess &memacc)
+{
+       r_flattened_interface = false;
+       visit(memacc.left);
+       if(r_flattened_interface)
+       {
+               VariableReference *var = new VariableReference;
+               var->name = memacc.member;
+               r_replaced_reference = var;
+       }
 }
 
-void LegacyConverter::visit(Assignment &assign)
+void StructuralFeatureConverter::visit(Assignment &assign)
 {
        TraversingVisitor::visit(assign);
        if(assign.target.declaration==frag_out && !supports_unified_interface_syntax())
                assign.target.declaration = 0;
 }
 
-bool LegacyConverter::supports_unified_sampling_functions() const
+bool StructuralFeatureConverter::supports_unified_sampling_functions() const
 {
-       if(features.gl_api==OPENGL_ES2)
+       if(features.target_api==OPENGL_ES)
                return check_version(Version(3, 0));
        else
                return check_version(Version(1, 30));
 }
 
-void LegacyConverter::visit(FunctionCall &call)
+void StructuralFeatureConverter::visit(FunctionCall &call)
 {
        if(call.declaration && call.declaration->source==BUILTIN_SOURCE)
        {
@@ -450,9 +583,63 @@ void LegacyConverter::visit(FunctionCall &call)
        TraversingVisitor::visit(call);
 }
 
-bool LegacyConverter::supports_interface_layouts() const
+bool StructuralFeatureConverter::supports_interface_blocks(const string &iface) const
+{
+       if(features.target_api==OPENGL_ES)
+       {
+               if(iface=="uniform")
+                       return check_version(Version(3, 0));
+               else
+                       return check_version(Version(3, 20));
+       }
+       else if(check_version(Version(1, 50)))
+               return true;
+       else if(iface=="uniform")
+               return check_extension(&Features::arb_uniform_buffer_object);
+       else
+               return false;
+}
+
+void StructuralFeatureConverter::visit(VariableDeclaration &var)
+{
+       if(var.block_declaration)
+       {
+               bool push_constant = has_layout_qualifier(var.layout.get(), "push_constant");
+               if(!supports_interface_blocks(var.interface) || (push_constant && features.target_api!=VULKAN))
+               {
+                       if(var.name.find(' ')==string::npos)
+                               unsupported("ARB_uniform_buffer_object required for interface block instances");
+                       else
+                       {
+                               for(const RefPtr<Statement> &s: var.block_declaration->members.body)
+                                       if(VariableDeclaration *mem = dynamic_cast<VariableDeclaration *>(s.get()))
+                                               mem->interface = var.interface;
+                               stage->content.body.splice(uniform_insert_point, var.block_declaration->members.body);
+                               nodes_to_remove.insert(&var);
+                               nodes_to_remove.insert(var.block_declaration);
+                       }
+               }
+       }
+
+       if((var.interface=="in" || var.interface=="out") && !supports_unified_interface_syntax())
+               if(stage->type==Stage::FRAGMENT && var.interface=="out")
+               {
+                       frag_out = &var;
+                       nodes_to_remove.insert(&var);
+               }
+
+       TraversingVisitor::visit(var);
+}
+
+
+void QualifierConverter::apply()
 {
-       if(features.gl_api==OPENGL_ES2)
+       stage->content.visit(*this);
+}
+
+bool QualifierConverter::supports_interface_layouts() const
+{
+       if(features.target_api==OPENGL_ES)
                return check_version(Version(3, 0));
        else if(check_version(Version(3, 30)))
                return true;
@@ -462,9 +649,9 @@ bool LegacyConverter::supports_interface_layouts() const
                return false;
 }
 
-bool LegacyConverter::supports_stage_interface_layouts() const
+bool QualifierConverter::supports_stage_interface_layouts() const
 {
-       if(features.gl_api==OPENGL_ES2)
+       if(features.target_api==OPENGL_ES)
                return check_version(Version(3, 10));
        else if(check_version(Version(4, 10)))
                return true;
@@ -472,9 +659,9 @@ bool LegacyConverter::supports_stage_interface_layouts() const
                return check_extension(&Features::arb_separate_shader_objects);
 }
 
-bool LegacyConverter::supports_centroid_sampling() const
+bool QualifierConverter::supports_centroid_sampling() const
 {
-       if(features.gl_api==OPENGL_ES2)
+       if(features.target_api==OPENGL_ES)
                return check_version(Version(3, 0));
        else if(check_version(Version(1, 20)))
                return true;
@@ -482,9 +669,9 @@ bool LegacyConverter::supports_centroid_sampling() const
                return check_extension(&Features::ext_gpu_shader4);
 }
 
-bool LegacyConverter::supports_sample_sampling() const
+bool QualifierConverter::supports_sample_sampling() const
 {
-       if(features.gl_api==OPENGL_ES2)
+       if(features.target_api==OPENGL_ES)
                return check_version(Version(3, 20));
        else if(check_version(Version(4, 0)))
                return true;
@@ -492,9 +679,9 @@ bool LegacyConverter::supports_sample_sampling() const
                return check_extension(&Features::arb_gpu_shader5);
 }
 
-bool LegacyConverter::supports_uniform_location() const
+bool QualifierConverter::supports_uniform_location() const
 {
-       if(features.gl_api==OPENGL_ES2)
+       if(features.target_api==OPENGL_ES)
                return check_version(Version(3, 10));
        else if(check_version(Version(4, 30)))
                return true;
@@ -502,15 +689,25 @@ bool LegacyConverter::supports_uniform_location() const
                return check_extension(&Features::arb_explicit_uniform_location);
 }
 
-bool LegacyConverter::supports_binding() const
+bool QualifierConverter::supports_binding() const
 {
-       if(features.gl_api==OPENGL_ES2)
+       if(features.target_api==OPENGL_ES)
                return check_version(Version(3, 10));
        else
                return check_version(Version(4, 20));
 }
 
-void LegacyConverter::visit(VariableDeclaration &var)
+bool QualifierConverter::supports_interface_block_location() const
+{
+       if(features.target_api==OPENGL_ES)
+               return check_version(Version(3, 20));
+       else if(check_version(Version(4, 40)))
+               return true;
+       else
+               return check_extension(&Features::arb_enhanced_layouts);
+}
+
+void QualifierConverter::visit(VariableDeclaration &var)
 {
        if(var.layout)
        {
@@ -520,7 +717,9 @@ void LegacyConverter::visit(VariableDeclaration &var)
                        {
                                bool supported = true;
                                bool external = false;
-                               if(var.interface=="in")
+                               if(var.block_declaration)
+                                       supported = supports_interface_block_location();
+                               else if(var.interface=="in")
                                {
                                        external = (stage->type==Stage::VERTEX);
                                        supported = (external ? supports_interface_layouts() : supports_stage_interface_layouts());
@@ -550,10 +749,9 @@ void LegacyConverter::visit(VariableDeclaration &var)
                        }
                        else if(i->name=="binding" && !supports_binding())
                        {
-                               const TypeDeclaration *type = var.type_declaration;
-                               while(const BasicTypeDeclaration *basic = dynamic_cast<const BasicTypeDeclaration *>(type))
-                                       type = basic->base_type;
-                               if(dynamic_cast<const ImageTypeDeclaration *>(type))
+                               if(var.block_declaration)
+                                       stage->uniform_block_bindings[var.block_declaration->block_name] = i->value;
+                               else if(dynamic_cast<const ImageTypeDeclaration *>(get_ultimate_base_type(var.type_declaration)))
                                        stage->texture_bindings[var.name] = i->value;
 
                                i = var.layout->qualifiers.erase(i);
@@ -577,83 +775,13 @@ void LegacyConverter::visit(VariableDeclaration &var)
                        var.sampling = string();
        }
 
-       if((var.interface=="in" || var.interface=="out") && !supports_unified_interface_syntax())
-       {
-               if(stage->type==Stage::FRAGMENT && var.interface=="out")
-               {
-                       frag_out = &var;
-                       nodes_to_remove.insert(&var);
-               }
-       }
+       if(var.name=="gl_ClipDistance")
+               if(const Literal *literal_size = dynamic_cast<const Literal *>(var.array_size.get()))
+                       stage->n_clip_distances = literal_size->value.value<int>();
 
        TraversingVisitor::visit(var);
 }
 
-bool LegacyConverter::supports_interface_blocks(const string &iface) const
-{
-       if(features.gl_api==OPENGL_ES2)
-       {
-               if(iface=="uniform")
-                       return check_version(Version(3, 0));
-               else
-                       return check_version(Version(3, 20));
-       }
-       else if(check_version(Version(1, 50)))
-               return true;
-       else if(iface=="uniform")
-               return check_extension(&Features::arb_uniform_buffer_object);
-       else
-               return false;
-}
-
-bool LegacyConverter::supports_interface_block_location() const
-{
-       if(features.gl_api==OPENGL_ES2)
-               return check_version(Version(3, 20));
-       else if(check_version(Version(4, 40)))
-               return true;
-       else
-               return check_extension(&Features::arb_enhanced_layouts);
-}
-
-void LegacyConverter::visit(InterfaceBlock &iface)
-{
-       if(iface.layout)
-       {
-               for(auto i=iface.layout->qualifiers.begin(); i!=iface.layout->qualifiers.end(); )
-               {
-                       if(i->name=="location" && !supports_interface_block_location())
-                               i = iface.layout->qualifiers.erase(i);
-                       else if(i->name=="binding" && !supports_binding())
-                       {
-                               stage->uniform_block_bindings[iface.block_name] = i->value;
-                               i = iface.layout->qualifiers.erase(i);
-                       }
-                       else
-                               ++i;
-               }
-
-               if(iface.layout->qualifiers.empty())
-                       iface.layout = 0;
-       }
-
-       if(!supports_interface_blocks(iface.interface) && iface.type_declaration)
-       {
-               if(!iface.instance_name.empty())
-                       unsupported("ARB_uniform_buffer_object required for interface block instances");
-               else if(iface.struct_declaration)
-               {
-                       stage->content.body.splice(uniform_insert_point, iface.struct_declaration->members.body);
-                       nodes_to_remove.insert(&iface);
-                       nodes_to_remove.insert(iface.struct_declaration);
-               }
-               else
-                       /* If the interface block is an array, it should have an instance
-                       name too, so this should never be reached */
-                       throw logic_error("Unexpected interface block configuration");
-       }
-}
-
 } // namespace SL
 } // namespace GL
 } // namespace Msp