From bf852bf402cf1cc6604816ae958c7dcf2655addc Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 25 Feb 2021 21:15:08 +0200 Subject: [PATCH] Only generate or link interfaces in the correct scope --- source/glsl/generate.cpp | 12 +++++++++--- source/glsl/generate.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index 48de1efc..3ff04eb9 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -258,7 +258,8 @@ void FunctionResolver::visit(FunctionDeclaration &func) InterfaceGenerator::InterfaceGenerator(): - stage(0) + stage(0), + function_scope(false) { } string InterfaceGenerator::get_out_prefix(Stage::Type type) @@ -369,7 +370,9 @@ void InterfaceGenerator::visit(VariableDeclaration &var) { if(var.interface=="out") { - if(current_block!=&stage->content && generate_interface(var, "out", change_prefix(var.name, string()))) + /* For out variables in function scope, generate a global interface and + replace the local declaration with an assignment. */ + if(function_scope && generate_interface(var, "out", var.name)) { nodes_to_remove.insert(&var); if(var.init_expression) @@ -383,7 +386,9 @@ void InterfaceGenerator::visit(VariableDeclaration &var) } else if(var.interface=="in") { - if(!var.linked_declaration && stage->previous) + /* Try to link in variables in global scope with out variables from + previous stage */ + if(current_block==&stage->content && !var.linked_declaration && stage->previous) { const map &prev_vars = stage->previous->content.variables; map::const_iterator i = prev_vars.find(var.name); @@ -400,6 +405,7 @@ void InterfaceGenerator::visit(VariableDeclaration &var) void InterfaceGenerator::visit(FunctionDeclaration &func) { + SetFlag set_scope(function_scope, true); // Skip parameters because they're not useful here func.body.visit(*this); } diff --git a/source/glsl/generate.h b/source/glsl/generate.h index f904021a..72035b2c 100644 --- a/source/glsl/generate.h +++ b/source/glsl/generate.h @@ -84,6 +84,7 @@ private: Stage *stage; std::string in_prefix; std::string out_prefix; + bool function_scope; NodeList::iterator iface_insert_point; NodeList::iterator assignment_insert_point; std::set nodes_to_remove; -- 2.43.0