From c315e77b7791fe92d42e1566b5adaddf2699a758 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 18 Mar 2021 01:06:08 +0200 Subject: [PATCH] Support layout qualifiers on GLSL interface blocks --- source/glsl/debug.cpp | 11 ++++++----- source/glsl/output.cpp | 5 +++++ source/glsl/parser.cpp | 6 ++++++ source/glsl/syntax.h | 1 + source/glsl/visitor.cpp | 2 ++ 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/source/glsl/debug.cpp b/source/glsl/debug.cpp index 99d6edaa..810ac742 100644 --- a/source/glsl/debug.cpp +++ b/source/glsl/debug.cpp @@ -388,13 +388,14 @@ void DumpTree::visit(InterfaceBlock &iface) head += " (linked)"; append(head); - begin_sub(); - last_branch(); + vector branches; if(iface.type_declaration) append(format("Type: %%%d %s", get_label(*iface.type_declaration), iface.type_declaration->name)); - else if(iface.members) - iface.members->visit(*this); - end_sub(); + if(iface.layout) + branches.push_back(Branch("Layout", iface.layout.get())); + if(iface.members) + branches.push_back(Branch("Members", iface.members.get())); + append_subtree(branches); } void DumpTree::visit(FunctionDeclaration &func) diff --git a/source/glsl/output.cpp b/source/glsl/output.cpp index 52026c4d..928b4250 100644 --- a/source/glsl/output.cpp +++ b/source/glsl/output.cpp @@ -306,6 +306,11 @@ void Formatter::visit(VariableDeclaration &var) void Formatter::visit(InterfaceBlock &iface) { + if(iface.layout) + { + iface.layout->visit(*this); + append(' '); + } append(format("%s %s\n", iface.interface, iface.block_name)); if(iface.struct_declaration) iface.struct_declaration->members.visit(*this); diff --git a/source/glsl/parser.cpp b/source/glsl/parser.cpp index 9e1f1913..ac35216a 100644 --- a/source/glsl/parser.cpp +++ b/source/glsl/parser.cpp @@ -273,6 +273,12 @@ RefPtr Parser::parse_global_declaration() tokenizer.expect(";"); return iface_lo; } + else if(is_interface_qualifier(token) && tokenizer.peek_token(2)=="{") + { + RefPtr iface = parse_interface_block(); + iface->layout = layout; + return iface; + } else { RefPtr var = parse_variable_declaration(); diff --git a/source/glsl/syntax.h b/source/glsl/syntax.h index f7c8ed29..1caf4d95 100644 --- a/source/glsl/syntax.h +++ b/source/glsl/syntax.h @@ -429,6 +429,7 @@ struct VariableDeclaration: Statement struct InterfaceBlock: Statement { + NodePtr layout; std::string interface; std::string block_name; NodePtr members; diff --git a/source/glsl/visitor.cpp b/source/glsl/visitor.cpp index cc030eab..808bcfa5 100644 --- a/source/glsl/visitor.cpp +++ b/source/glsl/visitor.cpp @@ -88,6 +88,8 @@ void TraversingVisitor::visit(VariableDeclaration &var) void TraversingVisitor::visit(InterfaceBlock &iface) { + if(iface.layout) + iface.layout->visit(*this); if(iface.members) iface.members->visit(*this); } -- 2.43.0