From fb9f5b0675bd714fd6d6325479f62435aaabc2ee Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 29 Mar 2010 17:16:35 -0700 Subject: [PATCH] Add some checking for vertex shader inputs / attributes This causes the following tests to pass: glslparsertest/shaders/attribute.vert glslparsertest/shaders/attribute1.vert glslparsertest/shaders/attribute2.vert --- ast_to_hir.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp index b03735ecb6c..dd024836a0e 100644 --- a/ast_to_hir.cpp +++ b/ast_to_hir.cpp @@ -1136,6 +1136,61 @@ ast_declarator_list::hir(exec_list *instructions, instructions->push_tail(var); + if (this->type->qualifier.attribute + && (state->current_function != NULL)) { + _mesa_glsl_error(& loc, state, + "attribute variable `%s' must be declared at global " + "scope", + var->name); + } + + if ((var->mode == ir_var_in) && (state->current_function == NULL)) { + if (state->target == vertex_shader) { + bool error_emitted = false; + + /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec: + * + * "Vertex shader inputs can only be float, floating-point + * vectors, matrices, signed and unsigned integers and integer + * vectors. Vertex shader inputs can also form arrays of these + * types, but not structures." + * + * From page 23 (page 29 of the PDF) of the GLSL 1.20 spec: + * + * "The attribute qualifier can be used only with float, + * floating-point vectors, and matrices. Attribute variables + * cannot be declared as arrays or structures." + */ + const glsl_type *check_type = var->type->is_array() + ? var->type->fields.array : var->type; + + switch (check_type->base_type) { + case GLSL_TYPE_FLOAT: + break; + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + if (state->language_version > 120) + break; + /* FALLTHROUGH */ + default: + _mesa_glsl_error(& loc, state, + "vertex shader input / attribute cannot have " + "type %s`%s'", + var->type->is_array() ? "array of " : "", + check_type->name); + error_emitted = true; + } + + if (!error_emitted && (state->language_version <= 120) + && var->type->is_array()) { + _mesa_glsl_error(& loc, state, + "vertex shader input / attribute cannot have " + "array type"); + error_emitted = true; + } + } + } + if (decl->initializer != NULL) { YYLTYPE initializer_loc = decl->initializer->get_location(); -- 2.30.2