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 bool uniform = (variable->interface=="uniform");
85 allowed = (scope==GLOBAL && uniform && dynamic_cast<ImageTypeDeclaration *>(type));
86 err_descr = (uniform ? "variable of non-opaque type" : "non-uniform variable");
90 allowed = (iface_block->interface=="uniform");
91 err_descr = "non-uniform interface block";
94 else if(i->name=="constant_id")
96 allowed = (variable && scope==GLOBAL);
99 if(!variable->constant)
102 err_descr = "non-constant variable";
106 BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(variable->type_declaration);
107 if(!basic || basic->kind<BasicTypeDeclaration::BOOL || basic->kind>BasicTypeDeclaration::INT)
110 err_descr = format("variable of type '%s'",
111 (variable->type_declaration ? variable->type_declaration->name : variable->type));
116 else if(i->name=="offset")
117 allowed = (variable && scope==INTERFACE_BLOCK && iface_block->interface=="uniform");
118 else if(i->name=="align")
119 allowed = (scope==INTERFACE_BLOCK && iface_block->interface=="uniform");
120 else if(i->name=="points")
122 allowed = (stage->type==Stage::GEOMETRY && iface_layout && (iface_layout->interface=="in" || iface_layout->interface=="out"));
125 else if(i->name=="lines" || i->name=="lines_adjacency" || i->name=="triangles" || i->name=="triangles_adjacency")
127 allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="in");
130 else if(i->name=="line_strip" || i->name=="triangle_strip")
132 allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="out");
135 else if(i->name=="invocations")
136 allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="in");
137 else if(i->name=="max_vertices")
138 allowed = (stage->type==Stage::GEOMETRY && iface_layout && iface_layout->interface=="out");
139 else if(i->name=="std140" || i->name=="std430")
141 allowed = (iface_block && !variable && iface_block->interface=="uniform");
147 if(err_descr.empty())
150 err_descr = describe_variable(scope);
152 err_descr = "interface block";
153 else if(iface_layout)
154 err_descr = format("interface '%s'", iface_layout->interface);
156 err_descr = "unknown declaration";
158 error(layout, format("Layout qualifier '%s' not allowed on %s", i->name, err_descr));
160 else if(value && !i->has_value)
161 error(layout, format("Layout qualifier '%s' requires a value", i->name));
162 else if(!value && i->has_value)
163 error(layout, format("Layout qualifier '%s' does not allow a value", i->name));
167 void DeclarationValidator::visit(InterfaceLayout &layout)
169 SetForScope<InterfaceLayout *> set_layout(iface_layout, &layout);
170 TraversingVisitor::visit(layout);
173 void DeclarationValidator::visit(BasicTypeDeclaration &type)
175 BasicTypeDeclaration *basic_base = dynamic_cast<BasicTypeDeclaration *>(type.base_type);
176 BasicTypeDeclaration::Kind base_kind = (basic_base ? basic_base->kind : BasicTypeDeclaration::VOID);
178 if(type.kind==BasicTypeDeclaration::VECTOR && (base_kind<BasicTypeDeclaration::BOOL || base_kind>BasicTypeDeclaration::FLOAT))
179 error(type, format("Invalid base type '%s' for vector type '%s'", type.base, type.name));
180 else if(type.kind==BasicTypeDeclaration::MATRIX && base_kind!=BasicTypeDeclaration::VECTOR)
181 error(type, format("Invalid base type '%s' for matrix type '%s'", type.base, type.name));
182 else if(type.kind==BasicTypeDeclaration::ARRAY && basic_base && base_kind==BasicTypeDeclaration::VOID)
183 error(type, format("Invalid base type '%s' for array type '%s'", type.base, type.name));
186 void DeclarationValidator::visit(ImageTypeDeclaration &type)
188 BasicTypeDeclaration::Kind base_kind = BasicTypeDeclaration::VOID;
189 if(BasicTypeDeclaration *basic_base = dynamic_cast<BasicTypeDeclaration *>(type.base_type))
190 base_kind = basic_base->kind;
191 if(base_kind!=BasicTypeDeclaration::INT && base_kind!=BasicTypeDeclaration::FLOAT)
192 error(type, format("Invalid base type '%s' for image type '%s'", type.base, type.name));
195 void DeclarationValidator::visit(StructDeclaration &strct)
197 SetForScope<ScopeType> set_scope(scope, (scope!=INTERFACE_BLOCK ? STRUCT : scope));
198 TraversingVisitor::visit(strct);
201 void DeclarationValidator::visit(VariableDeclaration &var)
203 SetForScope<VariableDeclaration *> set_var(variable, &var);
205 const char *descr = describe_variable(scope);
209 if(scope!=GLOBAL && scope!=INTERFACE_BLOCK)
210 error(var, format("Layout qualifier not allowed on %s", descr));
212 var.layout->visit(*this);
217 if(scope==STRUCT || scope==INTERFACE_BLOCK)
218 error(var, format("Constant qualifier not allowed on %s", descr));
219 if(!var.init_expression)
220 error(var, "Constant variable must have an initializer");
223 if(!var.interpolation.empty() || !var.sampling.empty())
225 if(var.interface!="in" && stage->type==Stage::VERTEX)
226 error(var, "Interpolation qualifier not allowed on vertex input");
227 else if(var.interface!="out" && stage->type==Stage::FRAGMENT)
228 error(var, "Interpolation qualifier not allowed on fragment output");
229 else if((var.interface!="in" && var.interface!="out") || (scope==FUNCTION_PARAM || scope==FUNCTION))
230 error(var, "Interpolation qualifier not allowed on non-interpolated variable");
233 if(!var.interface.empty())
235 if(iface_block && var.interface!=iface_block->interface)
236 error(var, format("Mismatched interface qualifier '%s' inside '%s' block", var.interface, iface_block->interface));
237 else if(scope==STRUCT || scope==FUNCTION)
238 error(var, format("Interface qualifier not allowed on %s", descr));
241 TypeDeclaration *type = var.type_declaration;
242 while(BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(type))
243 type = basic->base_type;
244 if(dynamic_cast<ImageTypeDeclaration *>(type))
246 if(scope!=GLOBAL && scope!=FUNCTION_PARAM)
247 error(var, format("Type '%s' not allowed on %s", type->name, descr));
248 else if(scope==GLOBAL && var.interface!="uniform")
249 error(var, format("Type '%s' only allowed with uniform interface", type->name));
252 if(var.init_expression)
254 if(scope==GLOBAL && !var.constant)
255 error(var, format("Initializer not allowed on non-constant %s", descr));
256 else if(scope!=GLOBAL && scope!=FUNCTION)
257 error(var, format("Initializer not allowed on %s", descr));
259 var.init_expression->visit(*this);
263 void DeclarationValidator::visit(InterfaceBlock &iface)
265 SetForScope<ScopeType> set_scope(scope, INTERFACE_BLOCK);
266 SetForScope<InterfaceBlock *> set_iface(iface_block, &iface);
268 if(stage->type==Stage::VERTEX && iface.interface=="in")
269 error(iface, "Interface block not allowed on vertex shader input");
270 else if(stage->type==Stage::FRAGMENT && iface.interface=="out")
271 error(iface, "Interface block not allowed on fragment shader output");
273 TraversingVisitor::visit(iface);
274 if(iface.struct_declaration)
275 iface.struct_declaration->visit(*this);
278 void DeclarationValidator::visit(FunctionDeclaration &func)
280 SetForScope<ScopeType> set_scope(scope, FUNCTION_PARAM);
281 for(NodeArray<VariableDeclaration>::const_iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
284 func.body.visit(*this);
288 IdentifierValidator::IdentifierValidator():
289 anonymous_block(false)
292 void IdentifierValidator::multiple_definition(const string &name, Statement &statement, Statement &previous)
294 error(statement, format("Multiple definition of %s", name));
295 add_info(previous, "Previous definition is here");
298 Statement *IdentifierValidator::find_definition(const string &name)
300 BlockDeclarationMap *decls = &declarations[current_block];
301 BlockDeclarationMap::const_iterator i = decls->find(name);
302 if(i==decls->end() && anonymous_block)
304 decls = &declarations[current_block->parent];
305 i = decls->find(name);
307 return (i!=decls->end() ? i->second : 0);
310 void IdentifierValidator::check_definition(const string &name, Statement &statement)
312 if(Statement *previous = find_definition(name))
313 multiple_definition(format("'%s'", name), statement, *previous);
315 record_definition(name, statement);
318 void IdentifierValidator::record_definition(const string &name, Statement &statement)
320 declarations[current_block].insert(make_pair(name, &statement));
322 declarations[current_block->parent].insert(make_pair(name, &statement));
325 void IdentifierValidator::visit(TypeDeclaration &type)
327 check_definition(type.name, type);
330 void IdentifierValidator::visit(StructDeclaration &strct)
332 check_definition(strct.name, strct);
333 TraversingVisitor::visit(strct);
336 void IdentifierValidator::visit(VariableDeclaration &var)
338 check_definition(var.name, var);
339 TraversingVisitor::visit(var);
342 void IdentifierValidator::visit(InterfaceBlock &iface)
344 string key = iface.interface+iface.block_name;
345 map<string, InterfaceBlock *>::const_iterator i = interface_blocks.find(key);
346 if(i!=interface_blocks.end())
347 multiple_definition(format("interface block '%s %s'", iface.interface, iface.block_name), iface, *i->second);
349 interface_blocks.insert(make_pair(key, &iface));
351 if(Statement *previous = find_definition(iface.block_name))
353 if(!dynamic_cast<InterfaceBlock *>(previous))
354 multiple_definition(format("'%s'", iface.block_name), iface, *previous);
357 record_definition(iface.block_name, iface);
359 if(!iface.instance_name.empty())
360 check_definition(iface.instance_name, iface);
362 if(iface.instance_name.empty() && iface.struct_declaration)
364 // Inject anonymous interface block members into the global scope
365 const map<string, VariableDeclaration *> &iface_vars = iface.struct_declaration->members.variables;
366 for(map<string, VariableDeclaration *>::const_iterator j=iface_vars.begin(); j!=iface_vars.end(); ++j)
367 check_definition(j->first, *j->second);
371 void IdentifierValidator::visit(FunctionDeclaration &func)
373 string key = func.name+func.signature;
374 map<string, FunctionDeclaration *>::const_iterator i = overloaded_functions.find(key);
375 if(i==overloaded_functions.end())
376 overloaded_functions.insert(make_pair(key, &func));
377 else if(func.return_type_declaration && i->second->return_type_declaration!=func.return_type_declaration)
379 error(func, format("Conflicting return type '%s' for function '%s'", func.return_type_declaration->name, func.name));
380 if(i->second->return_type_declaration)
381 add_info(*i->second, format("Previously declared as returning '%s'", i->second->return_type_declaration->name));
384 if(Statement *previous = find_definition(func.name))
386 if(!dynamic_cast<FunctionDeclaration *>(previous))
387 multiple_definition(format("'%s'", func.name), func, *previous);
390 record_definition(func.name, func);
392 if(func.definition==&func)
393 check_definition(func.name+func.signature, func);
395 TraversingVisitor::visit(func);
399 void ReferenceValidator::visit(BasicTypeDeclaration &type)
401 if(!type.base.empty() && !type.base_type)
402 error(type, format("Use of undeclared type '%s'", type.base));
405 void ReferenceValidator::visit(ImageTypeDeclaration &type)
407 if(!type.base.empty() && !type.base_type)
408 error(type, format("Use of undeclared type '%s'", type.base));
411 void ReferenceValidator::visit(VariableReference &var)
414 error(var, format("Use of undeclared variable '%s'", var.name));
415 else if(stage->type!=Stage::VERTEX && var.declaration->interface=="in" && var.name.compare(0, 3, "gl_") && !var.declaration->linked_declaration)
416 error(var, format("Use of unlinked input variable '%s'", var.name));
419 void ReferenceValidator::visit(MemberAccess &memacc)
421 if(memacc.left->type && !memacc.declaration)
422 error(memacc, format("Use of undeclared member '%s'", memacc.member));
423 TraversingVisitor::visit(memacc);
426 void ReferenceValidator::visit(InterfaceBlockReference &iface)
428 /* An interface block reference without a declaration should be impossible
429 since references are generated based on existing declarations. */
430 if(!iface.declaration)
431 error(iface, format("Use of undeclared interface block '%s'", iface.name));
432 else if(stage->type!=Stage::VERTEX && iface.declaration->interface=="in" && !iface.declaration->linked_block)
433 error(iface, format("Use of unlinked input block '%s'", iface.name));
436 void ReferenceValidator::visit(FunctionCall &call)
438 if((!call.constructor && !call.declaration) || (call.constructor && !call.type))
440 bool have_declaration = call.constructor;
441 if(!call.constructor)
443 map<string, FunctionDeclaration *>::iterator i = stage->functions.lower_bound(call.name);
444 have_declaration = (i!=stage->functions.end() && i->second->name==call.name);
449 bool valid_types = true;
451 for(NodeArray<Expression>::const_iterator j=call.arguments.begin(); (valid_types && j!=call.arguments.end()); ++j)
454 append(signature, ", ", (*j)->type->name);
460 error(call, format("No matching %s found for '%s(%s)'", (call.constructor ? "constructor" : "overload"), call.name, signature));
463 error(call, format("Call to undeclared function '%s'", call.name));
465 TraversingVisitor::visit(call);
468 void ReferenceValidator::visit(VariableDeclaration &var)
470 if(!var.type_declaration)
471 error(var, format("Use of undeclared type '%s'", var.type));
472 TraversingVisitor::visit(var);
475 void ReferenceValidator::visit(InterfaceBlock &iface)
477 if(!iface.struct_declaration)
478 error(iface, format("Interface block '%s %s' lacks a struct declaration", iface.interface, iface.block_name));
479 TraversingVisitor::visit(iface);
482 void ReferenceValidator::visit(FunctionDeclaration &func)
484 if(!func.return_type_declaration)
485 error(func, format("Use of undeclared type '%s'", func.return_type));
486 TraversingVisitor::visit(func);
490 ExpressionValidator::ExpressionValidator():
494 void ExpressionValidator::visit(Swizzle &swizzle)
497 if(BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(swizzle.left->type))
499 if(basic->kind==BasicTypeDeclaration::INT || basic->kind==BasicTypeDeclaration::FLOAT)
501 else if(basic->kind==BasicTypeDeclaration::VECTOR)
507 static const char component_names[] = { 'x', 'y', 'z', 'w', 'r', 'g', 'b', 'a', 's', 't', 'p', 'q' };
509 for(unsigned i=0; i<swizzle.count; ++i)
511 unsigned component_flavour = (find(component_names, component_names+12, swizzle.component_group[i])-component_names)/4;
513 flavour = component_flavour;
514 else if(flavour>=0 && component_flavour!=static_cast<unsigned>(flavour))
516 error(swizzle, format("Flavour of swizzle component '%c' is inconsistent with '%c'",
517 swizzle.component_group[i], swizzle.component_group[0]));
521 if(swizzle.components[i]>=size)
522 error(swizzle, format("Access to component '%c' which is not present in '%s'",
523 swizzle.component_group[i], swizzle.left->type->name));
526 else if(swizzle.left->type)
527 error(swizzle, format("Swizzle applied to '%s' which is neither a scalar nor a vector", swizzle.left->type->name));
529 TraversingVisitor::visit(swizzle);
532 void ExpressionValidator::visit(UnaryExpression &unary)
534 if(unary.expression->type)
537 error(unary, format("No matching operator '%s' found for '%s'", unary.oper->token, unary.expression->type->name));
538 else if((unary.oper->token[1]=='+' || unary.oper->token[1]=='-') && !unary.expression->lvalue)
539 error(unary, format("Operand of '%s' is not an lvalue", unary.oper->token));
541 TraversingVisitor::visit(unary);
544 void ExpressionValidator::visit(BinaryExpression &binary)
546 if(!binary.type && binary.left->type && binary.right->type)
548 if(binary.oper->token[0]=='[')
549 error(binary, format("Can't index element of '%s' with '%s'",
550 binary.left->type->name, binary.right->type->name));
552 error(binary, format("No matching operator '%s' found for '%s' and '%s'",
553 binary.oper->token, binary.left->type->name, binary.right->type->name));
555 TraversingVisitor::visit(binary);
558 void ExpressionValidator::visit(Assignment &assign)
560 if(assign.left->type)
562 if(!assign.left->lvalue)
563 error(assign, "Target of assignment is not an lvalue");
564 if(assign.right->type)
566 if(assign.oper->token[0]!='=')
569 error(assign, format("No matching operator '%s' found for '%s' and '%s'",
570 string(assign.oper->token, strlen(assign.oper->token)-1), assign.left->type->name, assign.right->type->name));
572 else if(assign.left->type!=assign.right->type)
573 error(assign, format("Assignment to variable of type '%s' from expression of incompatible type '%s'",
574 assign.left->type->name, assign.right->type->name));
577 TraversingVisitor::visit(assign);
580 void ExpressionValidator::visit(TernaryExpression &ternary)
582 if(ternary.condition->type)
584 BasicTypeDeclaration *basic_cond = dynamic_cast<BasicTypeDeclaration *>(ternary.condition->type);
585 if(!basic_cond || basic_cond->kind!=BasicTypeDeclaration::BOOL)
586 error(ternary, "Ternary operator condition is not a boolean");
587 else if(!ternary.type && ternary.true_expr->type && ternary.false_expr->type)
588 error(ternary, format("Ternary operator has incompatible types '%s' and '%s'",
589 ternary.true_expr->type->name, ternary.false_expr->type->name));
591 TraversingVisitor::visit(ternary);
594 void ExpressionValidator::visit(VariableDeclaration &var)
596 if(var.init_expression && var.init_expression->type && var.type_declaration && var.init_expression->type!=var.type_declaration)
597 error(var, format("Initializing a variable of type '%s' with an expression of incompatible type '%s'",
598 var.type_declaration->name, var.init_expression->type->name));
599 TraversingVisitor::visit(var);
602 void ExpressionValidator::visit(FunctionDeclaration &func)
604 SetForScope<FunctionDeclaration *> set_func(current_function, &func);
605 TraversingVisitor::visit(func);
608 void ExpressionValidator::visit(Return &ret)
610 if(current_function && current_function->return_type_declaration)
612 TypeDeclaration *return_type = current_function->return_type_declaration;
613 BasicTypeDeclaration *basic_return = dynamic_cast<BasicTypeDeclaration *>(return_type);
616 if(ret.expression->type && ret.expression->type!=return_type)
617 error(ret, format("Return expression type '%s' is incompatible with declared return type '%s'",
618 ret.expression->type->name, return_type->name));
620 else if(!basic_return || basic_return->kind!=BasicTypeDeclaration::VOID)
621 error(ret, "Return statement without an expression in a function not returning 'void'");
624 TraversingVisitor::visit(ret);
628 int StageInterfaceValidator::get_location(const Layout &layout)
630 for(vector<Layout::Qualifier>::const_iterator i=layout.qualifiers.begin(); i!=layout.qualifiers.end(); ++i)
631 if(i->name=="location")
636 void StageInterfaceValidator::visit(VariableDeclaration &var)
638 int location = (var.layout ? get_location(*var.layout) : -1);
639 if(var.interface=="in" && var.linked_declaration)
641 const Layout *linked_layout = var.linked_declaration->layout.get();
642 int linked_location = (linked_layout ? get_location(*linked_layout) : -1);
643 if(linked_location!=location)
645 error(var, format("Mismatched location %d for 'in %s'", location, var.name));
646 add_info(*var.linked_declaration, format("Linked to 'out %s' with location %d",
647 var.linked_declaration->name, linked_location));
649 if(var.type_declaration && var.linked_declaration->type_declaration)
651 const TypeDeclaration *type = var.type_declaration;
652 if(stage->type==Stage::GEOMETRY)
654 if(const BasicTypeDeclaration *basic = dynamic_cast<const BasicTypeDeclaration *>(type))
655 if(basic->kind==BasicTypeDeclaration::ARRAY && basic->base_type)
656 type = basic->base_type;
658 if(!is_same_type(*type, *var.linked_declaration->type_declaration))
660 error(var, format("Mismatched type '%s' for 'in %s'", type->name, var.name));
661 add_info(*var.linked_declaration, format("Linked to 'out %s' with type '%s'",
662 var.linked_declaration->name, var.linked_declaration->type_declaration->name));
667 if(location>=0 && !var.interface.empty())
669 map<unsigned, VariableDeclaration *> &used = used_locations[var.interface];
671 unsigned loc_count = LocationCounter().apply(var);
672 for(unsigned i=0; i<loc_count; ++i)
674 map<unsigned, VariableDeclaration *>::const_iterator j = used.find(location+i);
677 error(var, format("Overlapping location %d for '%s %s'", location+i, var.interface, var.name));
678 add_info(*j->second, format("Previously used here for '%s %s'", j->second->interface, j->second->name));
681 used[location+i] = &var;
687 void GlobalInterfaceValidator::apply(Module &module)
689 for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
692 i->content.visit(*this);
696 void GlobalInterfaceValidator::check_uniform(const Uniform &uni)
698 map<std::string, const Uniform *>::const_iterator i = used_names.find(uni.name);
699 if(i!=used_names.end())
701 if(uni.location>=0 && i->second->location>=0 && i->second->location!=uni.location)
703 error(*uni.node, format("Mismatched location %d for uniform '%s'", uni.location, uni.name));
704 add_info(*i->second->node, format("Previously declared here with location %d", i->second->location));
706 if(uni.bind_point>=0 && i->second->bind_point>=0 && i->second->bind_point!=uni.bind_point)
708 error(*uni.node, format("Mismatched binding %d for uniform '%s'", uni.bind_point, uni.name));
709 add_info(*i->second->node, format("Previously declared here with binding %d", i->second->bind_point));
711 if(uni.type && i->second->type && !is_same_type(*uni.type, *i->second->type))
713 string type_name = (dynamic_cast<const StructDeclaration *>(uni.type) ?
714 "structure" : format("type '%s'", uni.type->name));
715 error(*uni.node, format("Mismatched %s for uniform '%s'", type_name, uni.name));
717 string message = "Previously declared here";
718 if(!dynamic_cast<const StructDeclaration *>(i->second->type))
719 message += format(" with type '%s'", i->second->type->name);
720 add_info(*i->second->node, message);
724 used_names.insert(make_pair(uni.name, &uni));
728 map<unsigned, const Uniform *>::const_iterator j = used_locations.find(uni.location);
729 if(j!=used_locations.end())
731 if(j->second->name!=uni.name)
733 error(*uni.node, format("Overlapping location %d for '%s'", uni.location, uni.name));
734 add_info(*j->second->node, format("Previously used here for '%s'", j->second->name));
739 for(unsigned k=0; k<uni.loc_count; ++k)
740 used_locations.insert(make_pair(uni.location+k, &uni));
744 if(uni.bind_point>=0)
746 map<unsigned, const Uniform *> &used = used_bindings[uni.desc_set];
747 map<unsigned, const Uniform *>::const_iterator j = used.find(uni.bind_point);
750 if(j->second->name!=uni.name)
752 error(*uni.node, format("Overlapping binding %d for '%s'", uni.bind_point, uni.name));
753 add_info(*j->second->node, format("Previously used here for '%s'", j->second->name));
757 used.insert(make_pair(uni.bind_point, &uni));
761 void GlobalInterfaceValidator::visit(VariableDeclaration &var)
763 if(var.interface=="uniform")
767 uni.type = var.type_declaration;
771 uni.location = get_layout_value(*var.layout, "location");
772 uni.loc_count = LocationCounter().apply(var);
773 uni.desc_set = get_layout_value(*var.layout, "set", 0);
774 uni.bind_point = get_layout_value(*var.layout, "binding");
777 uniforms.push_back(uni);
778 check_uniform(uniforms.back());
782 void GlobalInterfaceValidator::visit(InterfaceBlock &iface)
784 if(iface.interface=="uniform")
788 uni.type = iface.struct_declaration;
789 uni.name = iface.block_name;
792 uni.desc_set = get_layout_value(*iface.layout, "set", 0);
793 uni.bind_point = get_layout_value(*iface.layout, "binding");
796 uniforms.push_back(uni);
797 check_uniform(uniforms.back());