X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fvalidate.cpp;h=e11f181e0b42d1140b67b313cfe449ff8bad52d7;hb=3fe1aab63922eec99d8bf6fd4fd60bec10df173c;hp=f12177db4a4236109f4060ffc72c13098f66093f;hpb=2e9d0beaafa8220d8a917749c8a12beaf4718729;p=libs%2Fgl.git diff --git a/source/glsl/validate.cpp b/source/glsl/validate.cpp index f12177db..e11f181e 100644 --- a/source/glsl/validate.cpp +++ b/source/glsl/validate.cpp @@ -34,6 +34,13 @@ void Validator::add_info(Node &node, const string &message) } +void DeclarationValidator::apply(Stage &s, const Features &f) +{ + stage = &s; + features = f; + s.content.visit(*this); +} + const char *DeclarationValidator::describe_variable(ScopeType scope) { switch(scope) @@ -49,6 +56,8 @@ const char *DeclarationValidator::describe_variable(ScopeType scope) void DeclarationValidator::visit(Layout &layout) { + bool push_constant = false; + bool binding = false; for(const Layout::Qualifier &q: layout.qualifiers) { bool allowed = false; @@ -58,7 +67,9 @@ void DeclarationValidator::visit(Layout &layout) allowed = (variable && scope==GLOBAL); else if(q.name=="binding" || q.name=="set") { - if(q.name=="set") + binding = true; + + if(q.name=="set" && features.target_api!=VULKAN) { error(layout, "Layout qualifier 'set' not allowed when targeting OpenGL"); continue; @@ -141,6 +152,12 @@ void DeclarationValidator::visit(Layout &layout) err_descr = "non-matrix variable"; } } + else if(q.name=="push_constant") + { + push_constant = true; + allowed = (iface_block && !variable && iface_block->interface=="uniform"); + value = false; + } if(!allowed) { @@ -162,6 +179,9 @@ void DeclarationValidator::visit(Layout &layout) else if(!value && q.has_value) error(layout, format("Layout qualifier '%s' does not allow a value", q.name)); } + + if(push_constant && binding) + error(layout, "Layout qualifier 'push_constant' not allowed together with 'binding' or 'set'"); } void DeclarationValidator::visit(InterfaceLayout &layout) @@ -236,6 +256,14 @@ void DeclarationValidator::visit(VariableDeclaration &var) error(var, format("Mismatched interface qualifier '%s' inside '%s' block", var.interface, iface_block->interface)); else if(scope==STRUCT || scope==FUNCTION) error(var, format("Interface qualifier not allowed on %s", descr)); + else if(scope==GLOBAL && variable->interface=="uniform" && features.target_api==VULKAN) + { + TypeDeclaration *type = variable->type_declaration; + while(BasicTypeDeclaration *basic = dynamic_cast(type)) + type = basic->base_type; + if(!dynamic_cast(type)) + error(var, "Interface qualifier 'uniform' not allowed on non-opaque variable in global scope"); + } } TypeDeclaration *type = var.type_declaration;