r_assignment(0),
assignment_target(false),
r_side_effects(false),
+ in_struct(false),
composite_reference(false)
{ }
unused_nodes.insert(&expr);
}
+void UnusedVariableRemover::visit(StructDeclaration &strct)
+{
+ SetFlag set_struct(in_struct);
+ TraversingVisitor::visit(strct);
+}
+
void UnusedVariableRemover::visit(VariableDeclaration &var)
{
+ TraversingVisitor::visit(var);
+
+ if(in_struct)
+ return;
+
VariableInfo &var_info = variables[&var];
var_info.interface_block = interface_block;
var_info.initialized = true;
record_assignment(&var, *var.init_expression);
}
- TraversingVisitor::visit(var);
}
void UnusedVariableRemover::visit(InterfaceBlock &iface)
Assignment *r_assignment;
bool assignment_target;
bool r_side_effects;
+ bool in_struct;
bool composite_reference;
Assignment::Target r_reference;
std::set<Node *> unused_nodes;
virtual void visit(FunctionCall &);
void record_assignment(const Assignment::Target &, Node &);
virtual void visit(ExpressionStatement &);
- // Ignore structs because their members can't be accessed directly.
- virtual void visit(StructDeclaration &) { }
+ virtual void visit(StructDeclaration &);
virtual void visit(VariableDeclaration &);
virtual void visit(InterfaceBlock &);
void merge_variables(const BlockVariableMap &);
--- /dev/null
+layout(constant_id=auto) const int max_colors = 2;
+struct ColorInfo
+{
+ vec4 color;
+};
+uniform Colors
+{
+ ColorInfo colors[max_colors];
+};
+
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+void main()
+{
+ gl_Position = position;
+}
+
+#pragma MSP stage(fragment)
+layout(location=0) out vec4 frag_color;
+void main()
+{
+ frag_color = colors[0].color;
+}
+
+// Compile mode: module
+
+/* Expected output: vertex
+layout(location=0) in vec4 position;
+void main()
+{
+ gl_Position = position;
+}
+*/
+
+/* Expected output: fragment
+layout(constant_id=953017667) const int max_colors = 2;
+struct ColorInfo
+{
+ vec4 color;
+};
+layout(binding=23) uniform Colors
+{
+ ColorInfo colors[max_colors];
+};
+layout(location=0) out vec4 frag_color;
+void main()
+{
+ frag_color = colors[0].color;
+}
+*/