3 #include <msp/core/raii.h>
4 #include <msp/strings/format.h>
5 #include <msp/strings/utils.h>
15 Validator::Validator():
20 void Validator::diagnose(Node &node, Node &provoking_node, Diagnostic::Severity severity, const string &message)
23 diag.severity = severity;
24 diag.source = node.source;
25 diag.line = node.line;
26 diag.provoking_source = provoking_node.source;
27 diag.provoking_line = provoking_node.line;
28 diag.message = message;
29 stage->diagnostics.push_back(diag);
31 last_provoker = &provoking_node;
34 void Validator::add_info(Node &node, const string &message)
37 throw logic_error("Tried to add info without a previous provoker");
38 diagnose(node, *last_provoker, Diagnostic::INFO, message);
42 DeclarationValidator::DeclarationValidator():
49 const char *DeclarationValidator::describe_variable(ScopeType scope)
53 case GLOBAL: return "global variable";
54 case STRUCT: return "struct member";
55 case INTERFACE_BLOCK: return "interface block member";
56 case FUNCTION_PARAM: return "function parameter";
57 case FUNCTION: return "local variable";
58 default: return "variable";
62 void DeclarationValidator::visit(Layout &layout)
64 for(vector<Layout::Qualifier>::const_iterator i=layout.qualifiers.begin(); i!=layout.qualifiers.end(); ++i)
69 if(i->name=="location")
70 allowed = (variable && scope==GLOBAL);
71 else if(i->name=="binding" || i->name=="set")
75 TypeDeclaration *type = variable->type_declaration;
76 while(BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(type))
77 type = basic->base_type;
78 allowed = (scope==GLOBAL && dynamic_cast<ImageTypeDeclaration *>(type));
79 err_descr = "variable of non-opaque type";
84 else if(i->name=="constant_id")
86 allowed = (variable && scope==GLOBAL);
89 if(!variable->constant)
92 err_descr = "non-constant variable";
96 BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(variable->type_declaration);
97 if(!basic || basic->kind<BasicTypeDeclaration::BOOL || basic->kind>BasicTypeDeclaration::INT)
100 err_descr = format("variable of type '%s'",
101 (variable->type_declaration ? variable->type_declaration->name : variable->type));
106 else if(i->name=="offset")
107 allowed = (variable && scope==INTERFACE_BLOCK);
108 else if(i->name=="points")
110 allowed = (stage->type==Stage::GEOMETRY && iface_layout && (iface_layout->interface=="in" || iface_layout->interface=="out"));
113 else if(i->name=="lines" || i->name=="lines_adjacency" || i->name=="triangles" || i->name=="triangles_adjacency")
115 allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="in");
118 else if(i->name=="line_strip" || i->name=="triangle_strip")
120 allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="out");
123 else if(i->name=="invocations")
124 allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="in");
125 else if(i->name=="max_vertices")
126 allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="out");
127 else if(i->name=="std140" || i->name=="std430")
129 allowed = (iface_block && !variable && iface_block->interface=="uniform");
135 if(err_descr.empty())
138 err_descr = describe_variable(scope);
140 err_descr = "interface block";
141 else if(iface_layout)
142 err_descr = format("interface '%s'", iface_layout->interface);
144 err_descr = "unknown declaration";
146 error(layout, format("Layout qualifier '%s' not allowed on %s", i->name, err_descr));
148 else if(value && !i->has_value)
149 error(layout, format("Layout qualifier '%s' requires a value", i->name));
150 else if(!value && i->has_value)
151 error(layout, format("Layout qualifier '%s' does not allow a value", i->name));
155 void DeclarationValidator::visit(InterfaceLayout &layout)
157 SetForScope<InterfaceLayout *> set_layout(iface_layout, &layout);
158 TraversingVisitor::visit(layout);
161 void DeclarationValidator::visit(BasicTypeDeclaration &type)
163 BasicTypeDeclaration *basic_base = dynamic_cast<BasicTypeDeclaration *>(type.base_type);
164 BasicTypeDeclaration::Kind base_kind = (basic_base ? basic_base->kind : BasicTypeDeclaration::VOID);
166 if(type.kind==BasicTypeDeclaration::VECTOR && (base_kind<BasicTypeDeclaration::BOOL || base_kind>BasicTypeDeclaration::FLOAT))
167 error(type, format("Invalid base type '%s' for vector type '%s'", type.base, type.name));
168 else if(type.kind==BasicTypeDeclaration::MATRIX && base_kind!=BasicTypeDeclaration::VECTOR)
169 error(type, format("Invalid base type '%s' for matrix type '%s'", type.base, type.name));
170 else if(type.kind==BasicTypeDeclaration::ARRAY && basic_base && base_kind==BasicTypeDeclaration::VOID)
171 error(type, format("Invalid base type '%s' for array type '%s'", type.base, type.name));
174 void DeclarationValidator::visit(ImageTypeDeclaration &type)
176 BasicTypeDeclaration::Kind base_kind = BasicTypeDeclaration::VOID;
177 if(BasicTypeDeclaration *basic_base = dynamic_cast<BasicTypeDeclaration *>(type.base_type))
178 base_kind = basic_base->kind;
179 if(base_kind!=BasicTypeDeclaration::INT && base_kind!=BasicTypeDeclaration::FLOAT)
180 error(type, format("Invalid base type '%s' for image type '%s'", type.base, type.name));
183 void DeclarationValidator::visit(StructDeclaration &strct)
185 SetForScope<ScopeType> set_scope(scope, (scope!=INTERFACE_BLOCK ? STRUCT : scope));
186 TraversingVisitor::visit(strct);
189 void DeclarationValidator::visit(VariableDeclaration &var)
191 SetForScope<VariableDeclaration *> set_var(variable, &var);
193 const char *descr = describe_variable(scope);
197 if(scope!=GLOBAL && scope!=INTERFACE_BLOCK)
198 error(var, format("Layout qualifier not allowed on %s", descr));
200 var.layout->visit(*this);
205 if(scope==STRUCT || scope==INTERFACE_BLOCK)
206 error(var, format("Constant qualifier not allowed on %s", descr));
209 if(!var.interpolation.empty() || !var.sampling.empty())
211 if(var.interface!="in" && stage->type==Stage::VERTEX)
212 error(var, "Interpolation qualifier not allowed on vertex input");
213 else if(var.interface!="out" && stage->type==Stage::FRAGMENT)
214 error(var, "Interpolation qualifier not allowed on fragment output");
215 else if((var.interface!="in" && var.interface!="out") || (scope==FUNCTION_PARAM || scope==FUNCTION))
216 error(var, "Interpolation qualifier not allowed on non-interpolated variable");
219 if(!var.interface.empty())
221 if(iface_block && var.interface!=iface_block->interface)
222 error(var, format("Mismatched interface qualifier '%s' inside '%s' block", var.interface, iface_block->interface));
223 else if(scope==STRUCT || scope==FUNCTION)
224 error(var, format("Interface qualifier not allowed on %s", descr));
227 TypeDeclaration *type = var.type_declaration;
228 while(BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(type))
229 type = basic->base_type;
230 if(dynamic_cast<ImageTypeDeclaration *>(type))
232 if(scope!=GLOBAL && scope!=FUNCTION_PARAM)
233 error(var, format("Type '%s' not allowed on %s", type->name, descr));
234 else if(scope==GLOBAL && var.interface!="uniform")
235 error(var, format("Type '%s' only allowed with uniform interface", type->name));
238 if(var.init_expression)
240 if(scope==GLOBAL && !var.constant)
241 error(var, format("Initializer not allowed on non-constant %s", descr));
242 else if(scope!=GLOBAL && scope!=FUNCTION)
243 error(var, format("Initializer not allowed on %s", descr));
245 var.init_expression->visit(*this);
249 void DeclarationValidator::visit(InterfaceBlock &iface)
251 SetForScope<ScopeType> set_scope(scope, INTERFACE_BLOCK);
252 SetForScope<InterfaceBlock *> set_iface(iface_block, &iface);
254 if(stage->type==Stage::VERTEX && iface.interface=="in")
255 error(iface, "Interface block not allowed on vertex shader input");
256 else if(stage->type==Stage::FRAGMENT && iface.interface=="out")
257 error(iface, "Interface block not allowed on fragment shader output");
259 TraversingVisitor::visit(iface);
260 if(iface.struct_declaration)
261 iface.struct_declaration->visit(*this);
264 void DeclarationValidator::visit(FunctionDeclaration &func)
266 SetForScope<ScopeType> set_scope(scope, FUNCTION_PARAM);
267 for(NodeArray<VariableDeclaration>::const_iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
270 func.body.visit(*this);
274 IdentifierValidator::IdentifierValidator():
275 anonymous_block(false)
278 void IdentifierValidator::multiple_definition(const string &name, Statement &statement, Statement &previous)
280 error(statement, format("Multiple definition of %s", name));
281 add_info(previous, "Previous definition is here");
284 Statement *IdentifierValidator::find_definition(const string &name)
286 BlockDeclarationMap *decls = &declarations[current_block];
287 BlockDeclarationMap::const_iterator i = decls->find(name);
288 if(i==decls->end() && anonymous_block)
290 decls = &declarations[current_block->parent];
291 i = decls->find(name);
293 return (i!=decls->end() ? i->second : 0);
296 void IdentifierValidator::check_definition(const string &name, Statement &statement)
298 if(Statement *previous = find_definition(name))
299 multiple_definition(format("'%s'", name), statement, *previous);
301 record_definition(name, statement);
304 void IdentifierValidator::record_definition(const string &name, Statement &statement)
306 declarations[current_block].insert(make_pair(name, &statement));
308 declarations[current_block->parent].insert(make_pair(name, &statement));
311 void IdentifierValidator::visit(TypeDeclaration &type)
313 check_definition(type.name, type);
316 void IdentifierValidator::visit(StructDeclaration &strct)
318 check_definition(strct.name, strct);
319 TraversingVisitor::visit(strct);
322 void IdentifierValidator::visit(VariableDeclaration &var)
324 check_definition(var.name, var);
325 TraversingVisitor::visit(var);
328 void IdentifierValidator::visit(InterfaceBlock &iface)
330 string key = iface.interface+iface.block_name;
331 map<string, InterfaceBlock *>::const_iterator i = interface_blocks.find(key);
332 if(i!=interface_blocks.end())
333 multiple_definition(format("interface block '%s %s'", iface.interface, iface.block_name), iface, *i->second);
335 interface_blocks.insert(make_pair(key, &iface));
337 if(Statement *previous = find_definition(iface.block_name))
339 if(!dynamic_cast<InterfaceBlock *>(previous))
340 multiple_definition(format("'%s'", iface.block_name), iface, *previous);
343 record_definition(iface.block_name, iface);
345 if(!iface.instance_name.empty())
346 check_definition(iface.instance_name, iface);
348 if(iface.instance_name.empty() && iface.struct_declaration)
350 // Inject anonymous interface block members into the global scope
351 const map<string, VariableDeclaration *> &iface_vars = iface.struct_declaration->members.variables;
352 for(map<string, VariableDeclaration *>::const_iterator j=iface_vars.begin(); j!=iface_vars.end(); ++j)
353 check_definition(j->first, *j->second);
357 void IdentifierValidator::visit(FunctionDeclaration &func)
359 string key = func.name+func.signature;
360 map<string, FunctionDeclaration *>::const_iterator i = overloaded_functions.find(key);
361 if(i==overloaded_functions.end())
362 overloaded_functions.insert(make_pair(key, &func));
363 else if(func.return_type_declaration && i->second->return_type_declaration!=func.return_type_declaration)
365 error(func, format("Conflicting return type '%s' for function '%s'", func.return_type_declaration->name, func.name));
366 if(i->second->return_type_declaration)
367 add_info(*i->second, format("Previously declared as returning '%s'", i->second->return_type_declaration->name));
370 if(Statement *previous = find_definition(func.name))
372 if(!dynamic_cast<FunctionDeclaration *>(previous))
373 multiple_definition(format("'%s'", func.name), func, *previous);
376 record_definition(func.name, func);
378 if(func.definition==&func)
379 check_definition(func.name+func.signature, func);
381 TraversingVisitor::visit(func);
385 void ReferenceValidator::visit(BasicTypeDeclaration &type)
387 if(!type.base.empty() && !type.base_type)
388 error(type, format("Use of undeclared type '%s'", type.base));
391 void ReferenceValidator::visit(ImageTypeDeclaration &type)
393 if(!type.base.empty() && !type.base_type)
394 error(type, format("Use of undeclared type '%s'", type.base));
397 void ReferenceValidator::visit(VariableReference &var)
400 error(var, format("Use of undeclared variable '%s'", var.name));
401 else if(stage->type!=Stage::VERTEX && var.declaration->interface=="in" && var.name.compare(0, 3, "gl_") && !var.declaration->linked_declaration)
402 error(var, format("Use of unlinked input variable '%s'", var.name));
405 void ReferenceValidator::visit(MemberAccess &memacc)
407 if(memacc.left->type && !memacc.declaration)
408 error(memacc, format("Use of undeclared member '%s'", memacc.member));
409 TraversingVisitor::visit(memacc);
412 void ReferenceValidator::visit(InterfaceBlockReference &iface)
414 /* An interface block reference without a declaration should be impossible
415 since references are generated based on existing declarations. */
416 if(!iface.declaration)
417 error(iface, format("Use of undeclared interface block '%s'", iface.name));
418 else if(stage->type!=Stage::VERTEX && iface.declaration->interface=="in" && !iface.declaration->linked_block)
419 error(iface, format("Use of unlinked input block '%s'", iface.name));
422 void ReferenceValidator::visit(FunctionCall &call)
424 if((!call.constructor && !call.declaration) || (call.constructor && !call.type))
426 bool have_declaration = call.constructor;
427 if(!call.constructor)
429 map<string, FunctionDeclaration *>::iterator i = stage->functions.lower_bound(call.name);
430 have_declaration = (i!=stage->functions.end() && i->second->name==call.name);
435 bool valid_types = true;
437 for(NodeArray<Expression>::const_iterator j=call.arguments.begin(); (valid_types && j!=call.arguments.end()); ++j)
440 append(signature, ", ", (*j)->type->name);
446 error(call, format("No matching %s found for '%s(%s)'", (call.constructor ? "constructor" : "overload"), call.name, signature));
449 error(call, format("Call to undeclared function '%s'", call.name));
451 TraversingVisitor::visit(call);
454 void ReferenceValidator::visit(VariableDeclaration &var)
456 if(!var.type_declaration)
457 error(var, format("Use of undeclared type '%s'", var.type));
458 TraversingVisitor::visit(var);
461 void ReferenceValidator::visit(InterfaceBlock &iface)
463 if(!iface.struct_declaration)
464 error(iface, format("Interface block '%s %s' lacks a struct declaration", iface.interface, iface.block_name));
465 TraversingVisitor::visit(iface);
468 void ReferenceValidator::visit(FunctionDeclaration &func)
470 if(!func.return_type_declaration)
471 error(func, format("Use of undeclared type '%s'", func.return_type));
472 TraversingVisitor::visit(func);
476 ExpressionValidator::ExpressionValidator():
480 void ExpressionValidator::visit(Swizzle &swizzle)
483 if(BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(swizzle.left->type))
485 if(basic->kind==BasicTypeDeclaration::INT || basic->kind==BasicTypeDeclaration::FLOAT)
487 else if(basic->kind==BasicTypeDeclaration::VECTOR)
493 static const char component_names[] = { 'x', 'y', 'z', 'w', 'r', 'g', 'b', 'a', 's', 't', 'p', 'q' };
495 for(unsigned i=0; i<swizzle.count; ++i)
497 unsigned component_flavour = (find(component_names, component_names+12, swizzle.component_group[i])-component_names)/4;
499 flavour = component_flavour;
500 else if(flavour>=0 && component_flavour!=static_cast<unsigned>(flavour))
502 error(swizzle, format("Flavour of swizzle component '%c' is inconsistent with '%c'",
503 swizzle.component_group[i], swizzle.component_group[0]));
507 if(swizzle.components[i]>=size)
508 error(swizzle, format("Access to component '%c' which is not present in '%s'",
509 swizzle.component_group[i], swizzle.left->type->name));
512 else if(swizzle.left->type)
513 error(swizzle, format("Swizzle applied to '%s' which is neither a scalar nor a vector", swizzle.left->type->name));
515 TraversingVisitor::visit(swizzle);
518 void ExpressionValidator::visit(UnaryExpression &unary)
520 if(unary.expression->type)
523 error(unary, format("No matching operator '%s' found for '%s'", unary.oper->token, unary.expression->type->name));
524 else if((unary.oper->token[1]=='+' || unary.oper->token[1]=='-') && !unary.expression->lvalue)
525 error(unary, format("Operand of '%s' is not an lvalue", unary.oper->token));
527 TraversingVisitor::visit(unary);
530 void ExpressionValidator::visit(BinaryExpression &binary)
532 if(!binary.type && binary.left->type && binary.right->type)
534 if(binary.oper->token[0]=='[')
535 error(binary, format("Can't index element of '%s' with '%s'",
536 binary.left->type->name, binary.right->type->name));
538 error(binary, format("No matching operator '%s' found for '%s' and '%s'",
539 binary.oper->token, binary.left->type->name, binary.right->type->name));
541 TraversingVisitor::visit(binary);
544 void ExpressionValidator::visit(Assignment &assign)
546 if(assign.left->type)
548 if(!assign.left->lvalue)
549 error(assign, "Target of assignment is not an lvalue");
550 if(assign.right->type)
552 if(assign.oper->token[0]!='=')
555 error(assign, format("No matching operator '%s' found for '%s' and '%s'",
556 string(assign.oper->token, strlen(assign.oper->token)-1), assign.left->type->name, assign.right->type->name));
558 else if(assign.left->type!=assign.right->type)
559 error(assign, format("Assignment to variable of type '%s' from expression of incompatible type '%s'",
560 assign.left->type->name, assign.right->type->name));
563 TraversingVisitor::visit(assign);
566 void ExpressionValidator::visit(TernaryExpression &ternary)
568 if(ternary.condition->type)
570 BasicTypeDeclaration *basic_cond = dynamic_cast<BasicTypeDeclaration *>(ternary.condition->type);
571 if(!basic_cond || basic_cond->kind!=BasicTypeDeclaration::BOOL)
572 error(ternary, "Ternary operator condition is not a boolean");
573 else if(!ternary.type && ternary.true_expr->type && ternary.false_expr->type)
574 error(ternary, format("Ternary operator has incompatible types '%s' and '%s'",
575 ternary.true_expr->type->name, ternary.false_expr->type->name));
577 TraversingVisitor::visit(ternary);
580 void ExpressionValidator::visit(VariableDeclaration &var)
582 if(var.init_expression && var.init_expression->type && var.type_declaration && var.init_expression->type!=var.type_declaration)
583 error(var, format("Initializing a variable of type '%s' with an expression of incompatible type '%s'",
584 var.type_declaration->name, var.init_expression->type->name));
585 TraversingVisitor::visit(var);
588 void ExpressionValidator::visit(FunctionDeclaration &func)
590 SetForScope<FunctionDeclaration *> set_func(current_function, &func);
591 TraversingVisitor::visit(func);
594 void ExpressionValidator::visit(Return &ret)
596 if(current_function && current_function->return_type_declaration)
598 TypeDeclaration *return_type = current_function->return_type_declaration;
599 BasicTypeDeclaration *basic_return = dynamic_cast<BasicTypeDeclaration *>(return_type);
602 if(ret.expression->type && ret.expression->type!=return_type)
603 error(ret, format("Return expression type '%s' is incompatible with declared return type '%s'",
604 ret.expression->type->name, return_type->name));
606 else if(!basic_return || basic_return->kind!=BasicTypeDeclaration::VOID)
607 error(ret, "Return statement without an expression in a function not returning 'void'");
610 TraversingVisitor::visit(ret);
614 int StageInterfaceValidator::get_location(const Layout &layout)
616 for(vector<Layout::Qualifier>::const_iterator i=layout.qualifiers.begin(); i!=layout.qualifiers.end(); ++i)
617 if(i->name=="location")
622 void StageInterfaceValidator::visit(VariableDeclaration &var)
624 int location = (var.layout ? get_location(*var.layout) : -1);
625 if(var.interface=="in" && var.linked_declaration)
627 const Layout *linked_layout = var.linked_declaration->layout.get();
628 int linked_location = (linked_layout ? get_location(*linked_layout) : -1);
629 if(linked_location!=location)
631 error(var, format("Mismatched location %d for 'in %s'", location, var.name));
632 add_info(*var.linked_declaration, format("Linked to 'out %s' with location %d",
633 var.linked_declaration->name, linked_location));
635 if(var.type_declaration && var.linked_declaration->type_declaration)
637 const TypeDeclaration *type = var.type_declaration;
638 if(stage->type==Stage::GEOMETRY)
640 if(const BasicTypeDeclaration *basic = dynamic_cast<const BasicTypeDeclaration *>(type))
641 if(basic->kind==BasicTypeDeclaration::ARRAY && basic->base_type)
642 type = basic->base_type;
644 if(!is_same_type(*type, *var.linked_declaration->type_declaration))
646 error(var, format("Mismatched type '%s' for 'in %s'", type->name, var.name));
647 add_info(*var.linked_declaration, format("Linked to 'out %s' with type '%s'",
648 var.linked_declaration->name, var.linked_declaration->type_declaration->name));
653 if(location>=0 && !var.interface.empty())
655 map<unsigned, VariableDeclaration *> &used = used_locations[var.interface];
657 unsigned loc_count = LocationCounter().apply(var);
658 for(unsigned i=0; i<loc_count; ++i)
660 map<unsigned, VariableDeclaration *>::const_iterator j = used.find(location+i);
663 error(var, format("Overlapping location %d for '%s %s'", location+i, var.interface, var.name));
664 add_info(*j->second, format("Previously used here for '%s %s'", j->second->interface, j->second->name));
667 used[location+i] = &var;
673 void GlobalInterfaceValidator::apply(Module &module)
675 for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
678 i->content.visit(*this);
682 void GlobalInterfaceValidator::check_uniform(const Uniform &uni)
684 map<std::string, const Uniform *>::const_iterator i = used_names.find(uni.name);
685 if(i!=used_names.end())
687 if(uni.location>=0 && i->second->location>=0 && i->second->location!=uni.location)
689 error(*uni.node, format("Mismatched location %d for uniform '%s'", uni.location, uni.name));
690 add_info(*i->second->node, format("Previously declared here with location %d", i->second->location));
692 if(uni.bind_point>=0 && i->second->bind_point>=0 && i->second->bind_point!=uni.bind_point)
694 error(*uni.node, format("Mismatched binding %d for uniform '%s'", uni.bind_point, uni.name));
695 add_info(*i->second->node, format("Previously declared here with binding %d", i->second->bind_point));
697 if(uni.type && i->second->type && !is_same_type(*uni.type, *i->second->type))
699 string type_name = (dynamic_cast<const StructDeclaration *>(uni.type) ?
700 "structure" : format("type '%s'", uni.type->name));
701 error(*uni.node, format("Mismatched %s for uniform '%s'", type_name, uni.name));
703 string message = "Previously declared here";
704 if(!dynamic_cast<const StructDeclaration *>(i->second->type))
705 message += format(" with type '%s'", i->second->type->name);
706 add_info(*i->second->node, message);
710 used_names.insert(make_pair(uni.name, &uni));
714 map<unsigned, const Uniform *>::const_iterator j = used_locations.find(uni.location);
715 if(j!=used_locations.end())
717 if(j->second->name!=uni.name)
719 error(*uni.node, format("Overlapping location %d for '%s'", uni.location, uni.name));
720 add_info(*j->second->node, format("Previously used here for '%s'", j->second->name));
725 for(unsigned k=0; k<uni.loc_count; ++k)
726 used_locations.insert(make_pair(uni.location+k, &uni));
730 if(uni.bind_point>=0)
732 map<unsigned, const Uniform *> &used = used_bindings[uni.desc_set];
733 map<unsigned, const Uniform *>::const_iterator j = used.find(uni.bind_point);
736 if(j->second->name!=uni.name)
738 error(*uni.node, format("Overlapping binding %d for '%s'", uni.bind_point, uni.name));
739 add_info(*j->second->node, format("Previously used here for '%s'", j->second->name));
743 used.insert(make_pair(uni.bind_point, &uni));
747 void GlobalInterfaceValidator::visit(VariableDeclaration &var)
749 if(var.interface=="uniform")
753 uni.type = var.type_declaration;
757 uni.location = get_layout_value(*var.layout, "location");
758 uni.loc_count = LocationCounter().apply(var);
759 uni.desc_set = get_layout_value(*var.layout, "set", 0);
760 uni.bind_point = get_layout_value(*var.layout, "binding");
763 uniforms.push_back(uni);
764 check_uniform(uniforms.back());
768 void GlobalInterfaceValidator::visit(InterfaceBlock &iface)
770 if(iface.interface=="uniform")
774 uni.type = iface.struct_declaration;
775 uni.name = iface.block_name;
778 uni.desc_set = get_layout_value(*iface.layout, "set", 0);
779 uni.bind_point = get_layout_value(*iface.layout, "binding");
782 uniforms.push_back(uni);
783 check_uniform(uniforms.back());