From: Mikko Rasa Date: Mon, 8 Nov 2021 16:15:39 +0000 (+0200) Subject: Fix flattening of GLSL interface blocks X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d03f6d46d0646c53ec3dcd00ddfd6c718ad18720;p=libs%2Fgl.git Fix flattening of GLSL interface blocks Anonymous interface blocks are treated as nameless variables since dfcf8eb, so the member accesses need to be converted to plain variable references when the block is flattened. --- diff --git a/source/glsl/finalize.cpp b/source/glsl/finalize.cpp index 27c35209..f005d87d 100644 --- a/source/glsl/finalize.cpp +++ b/source/glsl/finalize.cpp @@ -336,6 +336,15 @@ void LegacyConverter::visit(Block &block) } } +void LegacyConverter::visit(RefPtr &expr) +{ + r_replaced_reference = 0; + expr->visit(*this); + if(r_replaced_reference) + expr = r_replaced_reference; + r_replaced_reference = 0; +} + bool LegacyConverter::check_version(const Version &feature_version) const { if(features.glsl_versionname = memacc.member; + r_replaced_reference = var; + } +} + void LegacyConverter::visit(Assignment &assign) { TraversingVisitor::visit(assign); @@ -635,6 +661,9 @@ void LegacyConverter::visit(InterfaceBlock &iface) unsupported("ARB_uniform_buffer_object required for interface block instances"); else if(iface.struct_declaration) { + for(const RefPtr &s: iface.struct_declaration->members.body) + if(VariableDeclaration *var = dynamic_cast(s.get())) + var->interface = iface.interface; stage->content.body.splice(uniform_insert_point, iface.struct_declaration->members.body); nodes_to_remove.insert(&iface); nodes_to_remove.insert(iface.struct_declaration); diff --git a/source/glsl/finalize.h b/source/glsl/finalize.h index 1fe5fa45..4f6ee419 100644 --- a/source/glsl/finalize.h +++ b/source/glsl/finalize.h @@ -86,6 +86,8 @@ private: VariableDeclaration *frag_out = 0; NodeList::iterator uniform_insert_point; std::set nodes_to_remove; + RefPtr r_replaced_reference; + bool r_flattened_interface = false; public: virtual void apply(Stage &, const Features &); @@ -94,11 +96,14 @@ private: void unsupported(const std::string &); virtual void visit(Block &); + virtual void visit(RefPtr &); bool check_version(const Version &) const; bool check_extension(bool Features::*) const; bool supports_stage(Stage::Type) const; bool supports_unified_interface_syntax() const; virtual void visit(VariableReference &); + virtual void visit(InterfaceBlockReference &); + virtual void visit(MemberAccess &); virtual void visit(Assignment &); bool supports_unified_sampling_functions() const; virtual void visit(FunctionCall &);