diff options
Diffstat (limited to 'mesalib/src/glsl')
-rw-r--r-- | mesalib/src/glsl/ast_array_index.cpp | 6 | ||||
-rw-r--r-- | mesalib/src/glsl/glsl_parser.yy | 80 | ||||
-rw-r--r-- | mesalib/src/glsl/opt_algebraic.cpp | 23 |
3 files changed, 91 insertions, 18 deletions
diff --git a/mesalib/src/glsl/ast_array_index.cpp b/mesalib/src/glsl/ast_array_index.cpp index da96cc10e..b457ec899 100644 --- a/mesalib/src/glsl/ast_array_index.cpp +++ b/mesalib/src/glsl/ast_array_index.cpp @@ -69,9 +69,9 @@ update_max_array_access(ir_rvalue *ir, unsigned idx, YYLTYPE *loc, } if (deref_var != NULL) { - const glsl_type *interface_type = - deref_var->var->get_interface_type(); - if (interface_type != NULL) { + if (deref_var->var->is_interface_instance()) { + const glsl_type *interface_type = + deref_var->var->get_interface_type(); unsigned field_index = deref_record->record->type->field_index(deref_record->field); assert(field_index < interface_type->length); diff --git a/mesalib/src/glsl/glsl_parser.yy b/mesalib/src/glsl/glsl_parser.yy index a1d593fab..00589e28e 100644 --- a/mesalib/src/glsl/glsl_parser.yy +++ b/mesalib/src/glsl/glsl_parser.yy @@ -43,6 +43,38 @@ _mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state) { return _mesa_glsl_lexer_lex(val, loc, state->scanner); } + +static bool match_layout_qualifier(const char *s1, const char *s2, + _mesa_glsl_parse_state *state) +{ + /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers): + * + * "The tokens in any layout-qualifier-id-list ... are not case + * sensitive, unless explicitly noted otherwise." + * + * The text "unless explicitly noted otherwise" appears to be + * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes + * otherwise. + * + * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout + * Qualifiers): + * + * "As for other identifiers, they are case sensitive." + * + * So we need to do a case-sensitive or a case-insensitive match, + * depending on whether we are compiling for GLSL ES. + */ + if (state->es_shader) + return strcmp(s1, s2); + else { +#if defined(_MSC_VER) + /* MSVC doesn't have a strcasecmp() function; instead it has _stricmp. */ + return _stricmp(s1, s2); +#else + return strcasecmp(s1, s2); +#endif + } +} %} %expect 0 @@ -1160,9 +1192,10 @@ layout_qualifier_id: /* Layout qualifiers for ARB_fragment_coord_conventions. */ if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable || state->is_version(150, 0))) { - if (strcmp($1, "origin_upper_left") == 0) { + if (match_layout_qualifier($1, "origin_upper_left", state) == 0) { $$.flags.q.origin_upper_left = 1; - } else if (strcmp($1, "pixel_center_integer") == 0) { + } else if (match_layout_qualifier($1, "pixel_center_integer", + state) == 0) { $$.flags.q.pixel_center_integer = 1; } @@ -1177,13 +1210,14 @@ layout_qualifier_id: if (!$$.flags.i && (state->AMD_conservative_depth_enable || state->ARB_conservative_depth_enable)) { - if (strcmp($1, "depth_any") == 0) { + if (match_layout_qualifier($1, "depth_any", state) == 0) { $$.flags.q.depth_any = 1; - } else if (strcmp($1, "depth_greater") == 0) { + } else if (match_layout_qualifier($1, "depth_greater", state) == 0) { $$.flags.q.depth_greater = 1; - } else if (strcmp($1, "depth_less") == 0) { + } else if (match_layout_qualifier($1, "depth_less", state) == 0) { $$.flags.q.depth_less = 1; - } else if (strcmp($1, "depth_unchanged") == 0) { + } else if (match_layout_qualifier($1, "depth_unchanged", + state) == 0) { $$.flags.q.depth_unchanged = 1; } @@ -1201,20 +1235,32 @@ layout_qualifier_id: /* See also interface_block_layout_qualifier. */ if (!$$.flags.i && state->has_uniform_buffer_objects()) { - if (strcmp($1, "std140") == 0) { + if (match_layout_qualifier($1, "std140", state) == 0) { $$.flags.q.std140 = 1; - } else if (strcmp($1, "shared") == 0) { + } else if (match_layout_qualifier($1, "shared", state) == 0) { $$.flags.q.shared = 1; - } else if (strcmp($1, "column_major") == 0) { + } else if (match_layout_qualifier($1, "column_major", state) == 0) { $$.flags.q.column_major = 1; /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed * below in the interface_block_layout_qualifier rule. * * It is not a reserved word in GLSL ES 3.00, so it's handled here as * an identifier. + * + * Also, this takes care of alternate capitalizations of + * "row_major" (which is necessary because layout qualifiers + * are case-insensitive in desktop GLSL). */ - } else if (strcmp($1, "row_major") == 0) { + } else if (match_layout_qualifier($1, "row_major", state) == 0) { $$.flags.q.row_major = 1; + /* "packed" is a reserved word in GLSL, and its token is + * parsed below in the interface_block_layout_qualifier rule. + * However, we must take care of alternate capitalizations of + * "packed", because layout qualifiers are case-insensitive + * in desktop GLSL. + */ + } else if (match_layout_qualifier($1, "packed", state) == 0) { + $$.flags.q.packed = 1; } if ($$.flags.i && state->ARB_uniform_buffer_object_warn) { @@ -1239,7 +1285,7 @@ layout_qualifier_id: { "triangle_strip", GL_TRIANGLE_STRIP }, }; for (unsigned i = 0; i < Elements(map); i++) { - if (strcmp($1, map[i].s) == 0) { + if (match_layout_qualifier($1, map[i].s, state) == 0) { $$.flags.q.prim_type = 1; $$.prim_type = map[i].e; break; @@ -1263,7 +1309,7 @@ layout_qualifier_id: memset(& $$, 0, sizeof($$)); if (state->has_explicit_attrib_location()) { - if (strcmp("location", $1) == 0) { + if (match_layout_qualifier("location", $1, state) == 0) { $$.flags.q.explicit_location = 1; if ($3 >= 0) { @@ -1275,7 +1321,7 @@ layout_qualifier_id: } } - if (strcmp("index", $1) == 0) { + if (match_layout_qualifier("index", $1, state) == 0) { $$.flags.q.explicit_index = 1; if ($3 >= 0) { @@ -1289,12 +1335,12 @@ layout_qualifier_id: } if (state->ARB_shading_language_420pack_enable && - strcmp("binding", $1) == 0) { + match_layout_qualifier("binding", $1, state) == 0) { $$.flags.q.explicit_binding = 1; $$.binding = $3; } - if (strcmp("max_vertices", $1) == 0) { + if (match_layout_qualifier("max_vertices", $1, state) == 0) { $$.flags.q.max_vertices = 1; if ($3 < 0) { @@ -1344,6 +1390,10 @@ layout_qualifier_id: * (due to them being reserved keywords) instead of identifiers like * most qualifiers. See the any_identifier path of * layout_qualifier_id for the others. + * + * Note that since layout qualifiers are case-insensitive in desktop + * GLSL, all of these qualifiers need to be handled as identifiers as + * well (by the any_identifier path of layout_qualifier_id). */ interface_block_layout_qualifier: ROW_MAJOR diff --git a/mesalib/src/glsl/opt_algebraic.cpp b/mesalib/src/glsl/opt_algebraic.cpp index d706a6ad1..3e5802e18 100644 --- a/mesalib/src/glsl/opt_algebraic.cpp +++ b/mesalib/src/glsl/opt_algebraic.cpp @@ -85,6 +85,12 @@ is_vec_one(ir_constant *ir) } static inline bool +is_vec_negative_one(ir_constant *ir) +{ + return (ir == NULL) ? false : ir->is_negative_one(); +} + +static inline bool is_vec_basis(ir_constant *ir) { return (ir == NULL) ? false : ir->is_basis(); @@ -287,6 +293,23 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir) this->progress = true; return ir_constant::zero(ir, ir->type); } + if (is_vec_negative_one(op_const[0])) { + this->progress = true; + temp = new(mem_ctx) ir_expression(ir_unop_neg, + ir->operands[1]->type, + ir->operands[1], + NULL); + return swizzle_if_required(ir, temp); + } + if (is_vec_negative_one(op_const[1])) { + this->progress = true; + temp = new(mem_ctx) ir_expression(ir_unop_neg, + ir->operands[0]->type, + ir->operands[0], + NULL); + return swizzle_if_required(ir, temp); + } + /* Reassociate multiplication of constants so that we can do * constant folding. |