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 error(layout, "Layout qualifier 'set' not allowed when targeting OpenGL");
81 TypeDeclaration *type = variable->type_declaration;
82 while(BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(type))
83 type = basic->base_type;
84 allowed = (scope==GLOBAL && dynamic_cast<ImageTypeDeclaration *>(type));
85 err_descr = "variable of non-opaque type";
90 else if(i->name=="constant_id")
92 allowed = (variable && scope==GLOBAL);
95 if(!variable->constant)
98 err_descr = "non-constant variable";
102 BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(variable->type_declaration);
103 if(!basic || basic->kind<BasicTypeDeclaration::BOOL || basic->kind>BasicTypeDeclaration::INT)
106 err_descr = format("variable of type '%s'",
107 (variable->type_declaration ? variable->type_declaration->name : variable->type));
112 else if(i->name=="offset")
113 allowed = (variable && scope==INTERFACE_BLOCK);
114 else if(i->name=="points")
116 allowed = (stage->type==Stage::GEOMETRY && iface_layout && (iface_layout->interface=="in" || iface_layout->interface=="out"));
119 else if(i->name=="lines" || i->name=="lines_adjacency" || i->name=="triangles" || i->name=="triangles_adjacency")
121 allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="in");
124 else if(i->name=="line_strip" || i->name=="triangle_strip")
126 allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="out");
129 else if(i->name=="invocations")
130 allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="in");
131 else if(i->name=="max_vertices")
132 allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="out");
133 else if(i->name=="std140" || i->name=="std430")
135 allowed = (iface_block && !variable && iface_block->interface=="uniform");
141 if(err_descr.empty())
144 err_descr = describe_variable(scope);
146 err_descr = "interface block";
147 else if(iface_layout)
148 err_descr = format("interface '%s'", iface_layout->interface);
150 err_descr = "unknown declaration";
152 error(layout, format("Layout qualifier '%s' not allowed on %s", i->name, err_descr));
154 else if(value && !i->has_value)
155 error(layout, format("Layout qualifier '%s' requires a value", i->name));
156 else if(!value && i->has_value)
157 error(layout, format("Layout qualifier '%s' does not allow a value", i->name));
161 void DeclarationValidator::visit(InterfaceLayout &layout)
163 SetForScope<InterfaceLayout *> set_layout(iface_layout, &layout);
164 TraversingVisitor::visit(layout);
167 void DeclarationValidator::visit(BasicTypeDeclaration &type)
169 BasicTypeDeclaration *basic_base = dynamic_cast<BasicTypeDeclaration *>(type.base_type);
170 BasicTypeDeclaration::Kind base_kind = (basic_base ? basic_base->kind : BasicTypeDeclaration::VOID);
172 if(type.kind==BasicTypeDeclaration::VECTOR && (base_kind<BasicTypeDeclaration::BOOL || base_kind>BasicTypeDeclaration::FLOAT))
173 error(type, format("Invalid base type '%s' for vector type '%s'", type.base, type.name));
174 else if(type.kind==BasicTypeDeclaration::MATRIX && base_kind!=BasicTypeDeclaration::VECTOR)
175 error(type, format("Invalid base type '%s' for matrix type '%s'", type.base, type.name));
176 else if(type.kind==BasicTypeDeclaration::ARRAY && basic_base && base_kind==BasicTypeDeclaration::VOID)
177 error(type, format("Invalid base type '%s' for array type '%s'", type.base, type.name));
180 void DeclarationValidator::visit(ImageTypeDeclaration &type)
182 BasicTypeDeclaration::Kind base_kind = BasicTypeDeclaration::VOID;
183 if(BasicTypeDeclaration *basic_base = dynamic_cast<BasicTypeDeclaration *>(type.base_type))
184 base_kind = basic_base->kind;
185 if(base_kind!=BasicTypeDeclaration::INT && base_kind!=BasicTypeDeclaration::FLOAT)
186 error(type, format("Invalid base type '%s' for image type '%s'", type.base, type.name));
189 void DeclarationValidator::visit(StructDeclaration &strct)
191 SetForScope<ScopeType> set_scope(scope, (scope!=INTERFACE_BLOCK ? STRUCT : scope));
192 TraversingVisitor::visit(strct);
195 void DeclarationValidator::visit(VariableDeclaration &var)
197 SetForScope<VariableDeclaration *> set_var(variable, &var);
199 const char *descr = describe_variable(scope);
203 if(scope!=GLOBAL && scope!=INTERFACE_BLOCK)
204 error(var, format("Layout qualifier not allowed on %s", descr));
206 var.layout->visit(*this);
211 if(scope==STRUCT || scope==INTERFACE_BLOCK)
212 error(var, format("Constant qualifier not allowed on %s", descr));
215 if(!var.interpolation.empty() || !var.sampling.empty())
217 if(var.interface!="in" && stage->type==Stage::VERTEX)
218 error(var, "Interpolation qualifier not allowed on vertex input");
219 else if(var.interface!="out" && stage->type==Stage::FRAGMENT)
220 error(var, "Interpolation qualifier not allowed on fragment output");
221 else if((var.interface!="in" && var.interface!="out") || (scope==FUNCTION_PARAM || scope==FUNCTION))
222 error(var, "Interpolation qualifier not allowed on non-interpolated variable");
225 if(!var.interface.empty())
227 if(iface_block && var.interface!=iface_block->interface)
228 error(var, format("Mismatched interface qualifier '%s' inside '%s' block", var.interface, iface_block->interface));
229 else if(scope==STRUCT || scope==FUNCTION)
230 error(var, format("Interface qualifier not allowed on %s", descr));
233 TypeDeclaration *type = var.type_declaration;
234 while(BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(type))
235 type = basic->base_type;
236 if(dynamic_cast<ImageTypeDeclaration *>(type))
238 if(scope!=GLOBAL && scope!=FUNCTION_PARAM)
239 error(var, format("Type '%s' not allowed on %s", type->name, descr));
240 else if(scope==GLOBAL && var.interface!="uniform")
241 error(var, format("Type '%s' only allowed with uniform interface", type->name));
244 if(var.init_expression)
246 if(scope==GLOBAL && !var.constant)
247 error(var, format("Initializer not allowed on non-constant %s", descr));
248 else if(scope!=GLOBAL && scope!=FUNCTION)
249 error(var, format("Initializer not allowed on %s", descr));
251 var.init_expression->visit(*this);
255 void DeclarationValidator::visit(InterfaceBlock &iface)
257 SetForScope<ScopeType> set_scope(scope, INTERFACE_BLOCK);
258 SetForScope<InterfaceBlock *> set_iface(iface_block, &iface);
260 if(stage->type==Stage::VERTEX && iface.interface=="in")
261 error(iface, "Interface block not allowed on vertex shader input");
262 else if(stage->type==Stage::FRAGMENT && iface.interface=="out")
263 error(iface, "Interface block not allowed on fragment shader output");
265 TraversingVisitor::visit(iface);
266 if(iface.struct_declaration)
267 iface.struct_declaration->visit(*this);
270 void DeclarationValidator::visit(FunctionDeclaration &func)
272 SetForScope<ScopeType> set_scope(scope, FUNCTION_PARAM);
273 for(NodeArray<VariableDeclaration>::const_iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
276 func.body.visit(*this);
280 IdentifierValidator::IdentifierValidator():
281 anonymous_block(false)
284 void IdentifierValidator::multiple_definition(const string &name, Statement &statement, Statement &previous)
286 error(statement, format("Multiple definition of %s", name));
287 add_info(previous, "Previous definition is here");
290 Statement *IdentifierValidator::find_definition(const string &name)
292 BlockDeclarationMap *decls = &declarations[current_block];
293 BlockDeclarationMap::const_iterator i = decls->find(name);
294 if(i==decls->end() && anonymous_block)
296 decls = &declarations[current_block->parent];
297 i = decls->find(name);
299 return (i!=decls->end() ? i->second : 0);
302 void IdentifierValidator::check_definition(const string &name, Statement &statement)
304 if(Statement *previous = find_definition(name))
305 multiple_definition(format("'%s'", name), statement, *previous);
307 record_definition(name, statement);
310 void IdentifierValidator::record_definition(const string &name, Statement &statement)
312 declarations[current_block].insert(make_pair(name, &statement));
314 declarations[current_block->parent].insert(make_pair(name, &statement));
317 void IdentifierValidator::visit(TypeDeclaration &type)
319 check_definition(type.name, type);
322 void IdentifierValidator::visit(StructDeclaration &strct)
324 check_definition(strct.name, strct);
325 TraversingVisitor::visit(strct);
328 void IdentifierValidator::visit(VariableDeclaration &var)
330 check_definition(var.name, var);
331 TraversingVisitor::visit(var);
334 void IdentifierValidator::visit(InterfaceBlock &iface)
336 string key = iface.interface+iface.block_name;
337 map<string, InterfaceBlock *>::const_iterator i = interface_blocks.find(key);
338 if(i!=interface_blocks.end())
339 multiple_definition(format("interface block '%s %s'", iface.interface, iface.block_name), iface, *i->second);
341 interface_blocks.insert(make_pair(key, &iface));
343 if(Statement *previous = find_definition(iface.block_name))
345 if(!dynamic_cast<InterfaceBlock *>(previous))
346 multiple_definition(format("'%s'", iface.block_name), iface, *previous);
349 record_definition(iface.block_name, iface);
351 if(!iface.instance_name.empty())
352 check_definition(iface.instance_name, iface);
354 if(iface.instance_name.empty() && iface.struct_declaration)
356 // Inject anonymous interface block members into the global scope
357 const map<string, VariableDeclaration *> &iface_vars = iface.struct_declaration->members.variables;
358 for(map<string, VariableDeclaration *>::const_iterator j=iface_vars.begin(); j!=iface_vars.end(); ++j)
359 check_definition(j->first, *j->second);
363 void IdentifierValidator::visit(FunctionDeclaration &func)
365 string key = func.name+func.signature;
366 map<string, FunctionDeclaration *>::const_iterator i = overloaded_functions.find(key);
367 if(i==overloaded_functions.end())
368 overloaded_functions.insert(make_pair(key, &func));
369 else if(func.return_type_declaration && i->second->return_type_declaration!=func.return_type_declaration)
371 error(func, format("Conflicting return type '%s' for function '%s'", func.return_type_declaration->name, func.name));
372 if(i->second->return_type_declaration)
373 add_info(*i->second, format("Previously declared as returning '%s'", i->second->return_type_declaration->name));
376 if(Statement *previous = find_definition(func.name))
378 if(!dynamic_cast<FunctionDeclaration *>(previous))
379 multiple_definition(format("'%s'", func.name), func, *previous);
382 record_definition(func.name, func);
384 if(func.definition==&func)
385 check_definition(func.name+func.signature, func);
387 TraversingVisitor::visit(func);
391 void ReferenceValidator::visit(BasicTypeDeclaration &type)
393 if(!type.base.empty() && !type.base_type)
394 error(type, format("Use of undeclared type '%s'", type.base));
397 void ReferenceValidator::visit(ImageTypeDeclaration &type)
399 if(!type.base.empty() && !type.base_type)
400 error(type, format("Use of undeclared type '%s'", type.base));
403 void ReferenceValidator::visit(VariableReference &var)
406 error(var, format("Use of undeclared variable '%s'", var.name));
407 else if(stage->type!=Stage::VERTEX && var.declaration->interface=="in" && var.name.compare(0, 3, "gl_") && !var.declaration->linked_declaration)
408 error(var, format("Use of unlinked input variable '%s'", var.name));
411 void ReferenceValidator::visit(MemberAccess &memacc)
413 if(memacc.left->type && !memacc.declaration)
414 error(memacc, format("Use of undeclared member '%s'", memacc.member));
415 TraversingVisitor::visit(memacc);
418 void ReferenceValidator::visit(InterfaceBlockReference &iface)
420 /* An interface block reference without a declaration should be impossible
421 since references are generated based on existing declarations. */
422 if(!iface.declaration)
423 error(iface, format("Use of undeclared interface block '%s'", iface.name));
424 else if(stage->type!=Stage::VERTEX && iface.declaration->interface=="in" && !iface.declaration->linked_block)
425 error(iface, format("Use of unlinked input block '%s'", iface.name));
428 void ReferenceValidator::visit(FunctionCall &call)
430 if((!call.constructor && !call.declaration) || (call.constructor && !call.type))
432 bool have_declaration = call.constructor;
433 if(!call.constructor)
435 map<string, FunctionDeclaration *>::iterator i = stage->functions.lower_bound(call.name);
436 have_declaration = (i!=stage->functions.end() && i->second->name==call.name);
441 bool valid_types = true;
443 for(NodeArray<Expression>::const_iterator j=call.arguments.begin(); (valid_types && j!=call.arguments.end()); ++j)
446 append(signature, ", ", (*j)->type->name);
452 error(call, format("No matching %s found for '%s(%s)'", (call.constructor ? "constructor" : "overload"), call.name, signature));
455 error(call, format("Call to undeclared function '%s'", call.name));
457 TraversingVisitor::visit(call);
460 void ReferenceValidator::visit(VariableDeclaration &var)
462 if(!var.type_declaration)
463 error(var, format("Use of undeclared type '%s'", var.type));
464 TraversingVisitor::visit(var);
467 void ReferenceValidator::visit(InterfaceBlock &iface)
469 if(!iface.struct_declaration)
470 error(iface, format("Interface block '%s %s' lacks a struct declaration", iface.interface, iface.block_name));
471 TraversingVisitor::visit(iface);
474 void ReferenceValidator::visit(FunctionDeclaration &func)
476 if(!func.return_type_declaration)
477 error(func, format("Use of undeclared type '%s'", func.return_type));
478 TraversingVisitor::visit(func);
482 ExpressionValidator::ExpressionValidator():
486 void ExpressionValidator::visit(Swizzle &swizzle)
489 if(BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(swizzle.left->type))
491 if(basic->kind==BasicTypeDeclaration::INT || basic->kind==BasicTypeDeclaration::FLOAT)
493 else if(basic->kind==BasicTypeDeclaration::VECTOR)
499 static const char component_names[] = { 'x', 'y', 'z', 'w', 'r', 'g', 'b', 'a', 's', 't', 'p', 'q' };
501 for(unsigned i=0; i<swizzle.count; ++i)
503 unsigned component_flavour = (find(component_names, component_names+12, swizzle.component_group[i])-component_names)/4;
505 flavour = component_flavour;
506 else if(flavour>=0 && component_flavour!=static_cast<unsigned>(flavour))
508 error(swizzle, format("Flavour of swizzle component '%c' is inconsistent with '%c'",
509 swizzle.component_group[i], swizzle.component_group[0]));
513 if(swizzle.components[i]>=size)
514 error(swizzle, format("Access to component '%c' which is not present in '%s'",
515 swizzle.component_group[i], swizzle.left->type->name));
518 else if(swizzle.left->type)
519 error(swizzle, format("Swizzle applied to '%s' which is neither a scalar nor a vector", swizzle.left->type->name));
521 TraversingVisitor::visit(swizzle);
524 void ExpressionValidator::visit(UnaryExpression &unary)
526 if(unary.expression->type)
529 error(unary, format("No matching operator '%s' found for '%s'", unary.oper->token, unary.expression->type->name));
530 else if((unary.oper->token[1]=='+' || unary.oper->token[1]=='-') && !unary.expression->lvalue)
531 error(unary, format("Operand of '%s' is not an lvalue", unary.oper->token));
533 TraversingVisitor::visit(unary);
536 void ExpressionValidator::visit(BinaryExpression &binary)
538 if(!binary.type && binary.left->type && binary.right->type)
540 if(binary.oper->token[0]=='[')
541 error(binary, format("Can't index element of '%s' with '%s'",
542 binary.left->type->name, binary.right->type->name));
544 error(binary, format("No matching operator '%s' found for '%s' and '%s'",
545 binary.oper->token, binary.left->type->name, binary.right->type->name));
547 TraversingVisitor::visit(binary);
550 void ExpressionValidator::visit(Assignment &assign)
552 if(assign.left->type)
554 if(!assign.left->lvalue)
555 error(assign, "Target of assignment is not an lvalue");
556 if(assign.right->type)
558 if(assign.oper->token[0]!='=')
561 error(assign, format("No matching operator '%s' found for '%s' and '%s'",
562 string(assign.oper->token, strlen(assign.oper->token)-1), assign.left->type->name, assign.right->type->name));
564 else if(assign.left->type!=assign.right->type)
565 error(assign, format("Assignment to variable of type '%s' from expression of incompatible type '%s'",
566 assign.left->type->name, assign.right->type->name));
569 TraversingVisitor::visit(assign);
572 void ExpressionValidator::visit(TernaryExpression &ternary)
574 if(ternary.condition->type)
576 BasicTypeDeclaration *basic_cond = dynamic_cast<BasicTypeDeclaration *>(ternary.condition->type);
577 if(!basic_cond || basic_cond->kind!=BasicTypeDeclaration::BOOL)
578 error(ternary, "Ternary operator condition is not a boolean");
579 else if(!ternary.type && ternary.true_expr->type && ternary.false_expr->type)
580 error(ternary, format("Ternary operator has incompatible types '%s' and '%s'",
581 ternary.true_expr->type->name, ternary.false_expr->type->name));
583 TraversingVisitor::visit(ternary);
586 void ExpressionValidator::visit(VariableDeclaration &var)
588 if(var.init_expression && var.init_expression->type && var.type_declaration && var.init_expression->type!=var.type_declaration)
589 error(var, format("Initializing a variable of type '%s' with an expression of incompatible type '%s'",
590 var.type_declaration->name, var.init_expression->type->name));
591 TraversingVisitor::visit(var);
594 void ExpressionValidator::visit(FunctionDeclaration &func)
596 SetForScope<FunctionDeclaration *> set_func(current_function, &func);
597 TraversingVisitor::visit(func);
600 void ExpressionValidator::visit(Return &ret)
602 if(current_function && current_function->return_type_declaration)
604 TypeDeclaration *return_type = current_function->return_type_declaration;
605 BasicTypeDeclaration *basic_return = dynamic_cast<BasicTypeDeclaration *>(return_type);
608 if(ret.expression->type && ret.expression->type!=return_type)
609 error(ret, format("Return expression type '%s' is incompatible with declared return type '%s'",
610 ret.expression->type->name, return_type->name));
612 else if(!basic_return || basic_return->kind!=BasicTypeDeclaration::VOID)
613 error(ret, "Return statement without an expression in a function not returning 'void'");
616 TraversingVisitor::visit(ret);
620 int StageInterfaceValidator::get_location(const Layout &layout)
622 for(vector<Layout::Qualifier>::const_iterator i=layout.qualifiers.begin(); i!=layout.qualifiers.end(); ++i)
623 if(i->name=="location")
628 void StageInterfaceValidator::visit(VariableDeclaration &var)
630 int location = (var.layout ? get_location(*var.layout) : -1);
631 if(var.interface=="in" && var.linked_declaration)
633 const Layout *linked_layout = var.linked_declaration->layout.get();
634 int linked_location = (linked_layout ? get_location(*linked_layout) : -1);
635 if(linked_location!=location)
637 error(var, format("Mismatched location %d for 'in %s'", location, var.name));
638 add_info(*var.linked_declaration, format("Linked to 'out %s' with location %d",
639 var.linked_declaration->name, linked_location));
641 if(var.type_declaration && var.linked_declaration->type_declaration)
643 const TypeDeclaration *type = var.type_declaration;
644 if(stage->type==Stage::GEOMETRY)
646 if(const BasicTypeDeclaration *basic = dynamic_cast<const BasicTypeDeclaration *>(type))
647 if(basic->kind==BasicTypeDeclaration::ARRAY && basic->base_type)
648 type = basic->base_type;
650 if(!is_same_type(*type, *var.linked_declaration->type_declaration))
652 error(var, format("Mismatched type '%s' for 'in %s'", type->name, var.name));
653 add_info(*var.linked_declaration, format("Linked to 'out %s' with type '%s'",
654 var.linked_declaration->name, var.linked_declaration->type_declaration->name));
659 if(location>=0 && !var.interface.empty())
661 map<unsigned, VariableDeclaration *> &used = used_locations[var.interface];
663 unsigned loc_count = LocationCounter().apply(var);
664 for(unsigned i=0; i<loc_count; ++i)
666 map<unsigned, VariableDeclaration *>::const_iterator j = used.find(location+i);
669 error(var, format("Overlapping location %d for '%s %s'", location+i, var.interface, var.name));
670 add_info(*j->second, format("Previously used here for '%s %s'", j->second->interface, j->second->name));
673 used[location+i] = &var;
679 void GlobalInterfaceValidator::apply(Module &module)
681 for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
684 i->content.visit(*this);
688 void GlobalInterfaceValidator::check_uniform(const Uniform &uni)
690 map<std::string, const Uniform *>::const_iterator i = used_names.find(uni.name);
691 if(i!=used_names.end())
693 if(uni.location>=0 && i->second->location>=0 && i->second->location!=uni.location)
695 error(*uni.node, format("Mismatched location %d for uniform '%s'", uni.location, uni.name));
696 add_info(*i->second->node, format("Previously declared here with location %d", i->second->location));
698 if(uni.bind_point>=0 && i->second->bind_point>=0 && i->second->bind_point!=uni.bind_point)
700 error(*uni.node, format("Mismatched binding %d for uniform '%s'", uni.bind_point, uni.name));
701 add_info(*i->second->node, format("Previously declared here with binding %d", i->second->bind_point));
703 if(uni.type && i->second->type && !is_same_type(*uni.type, *i->second->type))
705 string type_name = (dynamic_cast<const StructDeclaration *>(uni.type) ?
706 "structure" : format("type '%s'", uni.type->name));
707 error(*uni.node, format("Mismatched %s for uniform '%s'", type_name, uni.name));
709 string message = "Previously declared here";
710 if(!dynamic_cast<const StructDeclaration *>(i->second->type))
711 message += format(" with type '%s'", i->second->type->name);
712 add_info(*i->second->node, message);
716 used_names.insert(make_pair(uni.name, &uni));
720 map<unsigned, const Uniform *>::const_iterator j = used_locations.find(uni.location);
721 if(j!=used_locations.end())
723 if(j->second->name!=uni.name)
725 error(*uni.node, format("Overlapping location %d for '%s'", uni.location, uni.name));
726 add_info(*j->second->node, format("Previously used here for '%s'", j->second->name));
731 for(unsigned k=0; k<uni.loc_count; ++k)
732 used_locations.insert(make_pair(uni.location+k, &uni));
736 if(uni.bind_point>=0)
738 map<unsigned, const Uniform *> &used = used_bindings[uni.desc_set];
739 map<unsigned, const Uniform *>::const_iterator j = used.find(uni.bind_point);
742 if(j->second->name!=uni.name)
744 error(*uni.node, format("Overlapping binding %d for '%s'", uni.bind_point, uni.name));
745 add_info(*j->second->node, format("Previously used here for '%s'", j->second->name));
749 used.insert(make_pair(uni.bind_point, &uni));
753 void GlobalInterfaceValidator::visit(VariableDeclaration &var)
755 if(var.interface=="uniform")
759 uni.type = var.type_declaration;
763 uni.location = get_layout_value(*var.layout, "location");
764 uni.loc_count = LocationCounter().apply(var);
765 uni.desc_set = get_layout_value(*var.layout, "set", 0);
766 uni.bind_point = get_layout_value(*var.layout, "binding");
769 uniforms.push_back(uni);
770 check_uniform(uniforms.back());
774 void GlobalInterfaceValidator::visit(InterfaceBlock &iface)
776 if(iface.interface=="uniform")
780 uni.type = iface.struct_declaration;
781 uni.name = iface.block_name;
784 uni.desc_set = get_layout_value(*iface.layout, "set", 0);
785 uni.bind_point = get_layout_value(*iface.layout, "binding");
788 uniforms.push_back(uni);
789 check_uniform(uniforms.back());