File: | root/firefox-clang/third_party/rust/glslopt/glsl-optimizer/src/compiler/glsl/ast_to_hir.cpp |
Warning: | line 3888, column 18 Null pointer passed to 1st parameter expecting 'nonnull' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* | |||
2 | * Copyright © 2010 Intel Corporation | |||
3 | * | |||
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |||
5 | * copy of this software and associated documentation files (the "Software"), | |||
6 | * to deal in the Software without restriction, including without limitation | |||
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||
8 | * and/or sell copies of the Software, and to permit persons to whom the | |||
9 | * Software is furnished to do so, subject to the following conditions: | |||
10 | * | |||
11 | * The above copyright notice and this permission notice (including the next | |||
12 | * paragraph) shall be included in all copies or substantial portions of the | |||
13 | * Software. | |||
14 | * | |||
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
21 | * DEALINGS IN THE SOFTWARE. | |||
22 | */ | |||
23 | ||||
24 | /** | |||
25 | * \file ast_to_hir.c | |||
26 | * Convert abstract syntax to to high-level intermediate reprensentation (HIR). | |||
27 | * | |||
28 | * During the conversion to HIR, the majority of the symantic checking is | |||
29 | * preformed on the program. This includes: | |||
30 | * | |||
31 | * * Symbol table management | |||
32 | * * Type checking | |||
33 | * * Function binding | |||
34 | * | |||
35 | * The majority of this work could be done during parsing, and the parser could | |||
36 | * probably generate HIR directly. However, this results in frequent changes | |||
37 | * to the parser code. Since we do not assume that every system this complier | |||
38 | * is built on will have Flex and Bison installed, we have to store the code | |||
39 | * generated by these tools in our version control system. In other parts of | |||
40 | * the system we've seen problems where a parser was changed but the generated | |||
41 | * code was not committed, merge conflicts where created because two developers | |||
42 | * had slightly different versions of Bison installed, etc. | |||
43 | * | |||
44 | * I have also noticed that running Bison generated parsers in GDB is very | |||
45 | * irritating. When you get a segfault on '$$ = $1->foo', you can't very | |||
46 | * well 'print $1' in GDB. | |||
47 | * | |||
48 | * As a result, my preference is to put as little C code as possible in the | |||
49 | * parser (and lexer) sources. | |||
50 | */ | |||
51 | ||||
52 | #include "glsl_symbol_table.h" | |||
53 | #include "glsl_parser_extras.h" | |||
54 | #include "ast.h" | |||
55 | #include "compiler/glsl_types.h" | |||
56 | #include "util/hash_table.h" | |||
57 | #include "main/mtypes.h" | |||
58 | #include "main/macros.h" | |||
59 | #include "main/shaderobj.h" | |||
60 | #include "ir.h" | |||
61 | #include "ir_builder.h" | |||
62 | #include "builtin_functions.h" | |||
63 | ||||
64 | using namespace ir_builder; | |||
65 | ||||
66 | static void | |||
67 | detect_conflicting_assignments(struct _mesa_glsl_parse_state *state, | |||
68 | exec_list *instructions); | |||
69 | static void | |||
70 | verify_subroutine_associated_funcs(struct _mesa_glsl_parse_state *state); | |||
71 | ||||
72 | static void | |||
73 | remove_per_vertex_blocks(exec_list *instructions, | |||
74 | _mesa_glsl_parse_state *state, ir_variable_mode mode); | |||
75 | ||||
76 | /** | |||
77 | * Visitor class that finds the first instance of any write-only variable that | |||
78 | * is ever read, if any | |||
79 | */ | |||
80 | class read_from_write_only_variable_visitor : public ir_hierarchical_visitor | |||
81 | { | |||
82 | public: | |||
83 | read_from_write_only_variable_visitor() : found(NULL__null) | |||
84 | { | |||
85 | } | |||
86 | ||||
87 | virtual ir_visitor_status visit(ir_dereference_variable *ir) | |||
88 | { | |||
89 | if (this->in_assignee) | |||
90 | return visit_continue; | |||
91 | ||||
92 | ir_variable *var = ir->variable_referenced(); | |||
93 | /* We can have memory_write_only set on both images and buffer variables, | |||
94 | * but in the former there is a distinction between reads from | |||
95 | * the variable itself (write_only) and from the memory they point to | |||
96 | * (memory_write_only), while in the case of buffer variables there is | |||
97 | * no such distinction, that is why this check here is limited to | |||
98 | * buffer variables alone. | |||
99 | */ | |||
100 | if (!var || var->data.mode != ir_var_shader_storage) | |||
101 | return visit_continue; | |||
102 | ||||
103 | if (var->data.memory_write_only) { | |||
104 | found = var; | |||
105 | return visit_stop; | |||
106 | } | |||
107 | ||||
108 | return visit_continue; | |||
109 | } | |||
110 | ||||
111 | ir_variable *get_variable() { | |||
112 | return found; | |||
113 | } | |||
114 | ||||
115 | virtual ir_visitor_status visit_enter(ir_expression *ir) | |||
116 | { | |||
117 | /* .length() doesn't actually read anything */ | |||
118 | if (ir->operation == ir_unop_ssbo_unsized_array_length) | |||
119 | return visit_continue_with_parent; | |||
120 | ||||
121 | return visit_continue; | |||
122 | } | |||
123 | ||||
124 | private: | |||
125 | ir_variable *found; | |||
126 | }; | |||
127 | ||||
128 | void | |||
129 | _mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state) | |||
130 | { | |||
131 | _mesa_glsl_initialize_variables(instructions, state); | |||
132 | ||||
133 | state->symbols->separate_function_namespace = state->language_version == 110; | |||
134 | ||||
135 | state->current_function = NULL__null; | |||
136 | ||||
137 | state->toplevel_ir = instructions; | |||
138 | ||||
139 | state->gs_input_prim_type_specified = false; | |||
140 | state->tcs_output_vertices_specified = false; | |||
141 | state->cs_input_local_size_specified = false; | |||
142 | ||||
143 | /* Section 4.2 of the GLSL 1.20 specification states: | |||
144 | * "The built-in functions are scoped in a scope outside the global scope | |||
145 | * users declare global variables in. That is, a shader's global scope, | |||
146 | * available for user-defined functions and global variables, is nested | |||
147 | * inside the scope containing the built-in functions." | |||
148 | * | |||
149 | * Since built-in functions like ftransform() access built-in variables, | |||
150 | * it follows that those must be in the outer scope as well. | |||
151 | * | |||
152 | * We push scope here to create this nesting effect...but don't pop. | |||
153 | * This way, a shader's globals are still in the symbol table for use | |||
154 | * by the linker. | |||
155 | */ | |||
156 | state->symbols->push_scope(); | |||
157 | ||||
158 | foreach_list_typed (ast_node, ast, link, & state->translation_unit)for (ast_node * ast = (!exec_node_is_tail_sentinel((& state ->translation_unit)->head_sentinel.next) ? ((ast_node * ) (((uintptr_t) (& state->translation_unit)->head_sentinel .next) - (((char *) &((ast_node *) (& state->translation_unit )->head_sentinel.next)->link) - ((char *) (& state-> translation_unit)->head_sentinel.next)))) : __null); (ast) != __null; (ast) = (!exec_node_is_tail_sentinel((ast)->link .next) ? ((ast_node *) (((uintptr_t) (ast)->link.next) - ( ((char *) &((ast_node *) (ast)->link.next)->link) - ((char *) (ast)->link.next)))) : __null)) | |||
159 | ast->hir(instructions, state); | |||
160 | ||||
161 | verify_subroutine_associated_funcs(state); | |||
162 | detect_recursion_unlinked(state, instructions); | |||
163 | detect_conflicting_assignments(state, instructions); | |||
164 | ||||
165 | state->toplevel_ir = NULL__null; | |||
166 | ||||
167 | /* Move all of the variable declarations to the front of the IR list, and | |||
168 | * reverse the order. This has the (intended!) side effect that vertex | |||
169 | * shader inputs and fragment shader outputs will appear in the IR in the | |||
170 | * same order that they appeared in the shader code. This results in the | |||
171 | * locations being assigned in the declared order. Many (arguably buggy) | |||
172 | * applications depend on this behavior, and it matches what nearly all | |||
173 | * other drivers do. | |||
174 | * However, do not push the declarations before struct decls or precision | |||
175 | * statements. | |||
176 | */ | |||
177 | ir_instruction* before_node = (ir_instruction*)instructions->get_head(); | |||
178 | ir_instruction* after_node = NULL__null; | |||
179 | while (before_node && (before_node->ir_type == ir_type_precision || before_node->ir_type == ir_type_typedecl)) | |||
180 | { | |||
181 | after_node = before_node; | |||
182 | before_node = (ir_instruction*)before_node->next; | |||
183 | } | |||
184 | ||||
185 | foreach_in_list_safe(ir_instruction, node, instructions)for (ir_instruction *node = (!exec_node_is_tail_sentinel((instructions )->head_sentinel.next) ? (ir_instruction *) ((instructions )->head_sentinel.next) : __null), *__next = (node) ? (!exec_node_is_tail_sentinel ((instructions)->head_sentinel.next->next) ? (ir_instruction *) ((instructions)->head_sentinel.next->next) : __null ) : __null; (node) != __null; (node) = __next, __next = __next ? (!exec_node_is_tail_sentinel(__next->next) ? (ir_instruction *) (__next->next) : __null) : __null) { | |||
186 | ir_variable *const var = node->as_variable(); | |||
187 | ||||
188 | if (var == NULL__null) | |||
189 | continue; | |||
190 | ||||
191 | var->remove(); | |||
192 | if (after_node) | |||
193 | after_node->insert_after(var); | |||
194 | else | |||
195 | instructions->push_head(var); | |||
196 | } | |||
197 | ||||
198 | /* Figure out if gl_FragCoord is actually used in fragment shader */ | |||
199 | ir_variable *const var = state->symbols->get_variable("gl_FragCoord"); | |||
200 | if (var != NULL__null) | |||
201 | state->fs_uses_gl_fragcoord = var->data.used; | |||
202 | ||||
203 | /* From section 7.1 (Built-In Language Variables) of the GLSL 4.10 spec: | |||
204 | * | |||
205 | * If multiple shaders using members of a built-in block belonging to | |||
206 | * the same interface are linked together in the same program, they | |||
207 | * must all redeclare the built-in block in the same way, as described | |||
208 | * in section 4.3.7 "Interface Blocks" for interface block matching, or | |||
209 | * a link error will result. | |||
210 | * | |||
211 | * The phrase "using members of a built-in block" implies that if two | |||
212 | * shaders are linked together and one of them *does not use* any members | |||
213 | * of the built-in block, then that shader does not need to have a matching | |||
214 | * redeclaration of the built-in block. | |||
215 | * | |||
216 | * This appears to be a clarification to the behaviour established for | |||
217 | * gl_PerVertex by GLSL 1.50, therefore implement it regardless of GLSL | |||
218 | * version. | |||
219 | * | |||
220 | * The definition of "interface" in section 4.3.7 that applies here is as | |||
221 | * follows: | |||
222 | * | |||
223 | * The boundary between adjacent programmable pipeline stages: This | |||
224 | * spans all the outputs in all compilation units of the first stage | |||
225 | * and all the inputs in all compilation units of the second stage. | |||
226 | * | |||
227 | * Therefore this rule applies to both inter- and intra-stage linking. | |||
228 | * | |||
229 | * The easiest way to implement this is to check whether the shader uses | |||
230 | * gl_PerVertex right after ast-to-ir conversion, and if it doesn't, simply | |||
231 | * remove all the relevant variable declaration from the IR, so that the | |||
232 | * linker won't see them and complain about mismatches. | |||
233 | */ | |||
234 | remove_per_vertex_blocks(instructions, state, ir_var_shader_in); | |||
235 | remove_per_vertex_blocks(instructions, state, ir_var_shader_out); | |||
236 | ||||
237 | /* Check that we don't have reads from write-only variables */ | |||
238 | read_from_write_only_variable_visitor v; | |||
239 | v.run(instructions); | |||
240 | ir_variable *error_var = v.get_variable(); | |||
241 | if (error_var) { | |||
242 | /* It would be nice to have proper location information, but for that | |||
243 | * we would need to check this as we process each kind of AST node | |||
244 | */ | |||
245 | YYLTYPE loc; | |||
246 | memset(&loc, 0, sizeof(loc)); | |||
247 | _mesa_glsl_error(&loc, state, "Read from write-only variable `%s'", | |||
248 | error_var->name); | |||
249 | } | |||
250 | } | |||
251 | ||||
252 | ||||
253 | static ir_expression_operation | |||
254 | get_implicit_conversion_operation(const glsl_type *to, const glsl_type *from, | |||
255 | struct _mesa_glsl_parse_state *state) | |||
256 | { | |||
257 | switch (to->base_type) { | |||
258 | case GLSL_TYPE_FLOAT: | |||
259 | switch (from->base_type) { | |||
260 | case GLSL_TYPE_INT: return ir_unop_i2f; | |||
261 | case GLSL_TYPE_UINT: return ir_unop_u2f; | |||
262 | default: return (ir_expression_operation)0; | |||
263 | } | |||
264 | ||||
265 | case GLSL_TYPE_UINT: | |||
266 | if (!state->has_implicit_uint_to_int_conversion()) | |||
267 | return (ir_expression_operation)0; | |||
268 | switch (from->base_type) { | |||
269 | case GLSL_TYPE_INT: return ir_unop_i2u; | |||
270 | default: return (ir_expression_operation)0; | |||
271 | } | |||
272 | ||||
273 | case GLSL_TYPE_DOUBLE: | |||
274 | if (!state->has_double()) | |||
275 | return (ir_expression_operation)0; | |||
276 | switch (from->base_type) { | |||
277 | case GLSL_TYPE_INT: return ir_unop_i2d; | |||
278 | case GLSL_TYPE_UINT: return ir_unop_u2d; | |||
279 | case GLSL_TYPE_FLOAT: return ir_unop_f2d; | |||
280 | case GLSL_TYPE_INT64: return ir_unop_i642d; | |||
281 | case GLSL_TYPE_UINT64: return ir_unop_u642d; | |||
282 | default: return (ir_expression_operation)0; | |||
283 | } | |||
284 | ||||
285 | case GLSL_TYPE_UINT64: | |||
286 | if (!state->has_int64()) | |||
287 | return (ir_expression_operation)0; | |||
288 | switch (from->base_type) { | |||
289 | case GLSL_TYPE_INT: return ir_unop_i2u64; | |||
290 | case GLSL_TYPE_UINT: return ir_unop_u2u64; | |||
291 | case GLSL_TYPE_INT64: return ir_unop_i642u64; | |||
292 | default: return (ir_expression_operation)0; | |||
293 | } | |||
294 | ||||
295 | case GLSL_TYPE_INT64: | |||
296 | if (!state->has_int64()) | |||
297 | return (ir_expression_operation)0; | |||
298 | switch (from->base_type) { | |||
299 | case GLSL_TYPE_INT: return ir_unop_i2i64; | |||
300 | default: return (ir_expression_operation)0; | |||
301 | } | |||
302 | ||||
303 | default: return (ir_expression_operation)0; | |||
304 | } | |||
305 | } | |||
306 | ||||
307 | ||||
308 | /** | |||
309 | * If a conversion is available, convert one operand to a different type | |||
310 | * | |||
311 | * The \c from \c ir_rvalue is converted "in place". | |||
312 | * | |||
313 | * \param to Type that the operand it to be converted to | |||
314 | * \param from Operand that is being converted | |||
315 | * \param state GLSL compiler state | |||
316 | * | |||
317 | * \return | |||
318 | * If a conversion is possible (or unnecessary), \c true is returned. | |||
319 | * Otherwise \c false is returned. | |||
320 | */ | |||
321 | static bool | |||
322 | apply_implicit_conversion(const glsl_type *to, ir_rvalue * &from, | |||
323 | struct _mesa_glsl_parse_state *state) | |||
324 | { | |||
325 | void *ctx = state; | |||
326 | if (to->base_type == from->type->base_type) | |||
327 | return true; | |||
328 | ||||
329 | /* Prior to GLSL 1.20, there are no implicit conversions */ | |||
330 | if (!state->has_implicit_conversions()) | |||
331 | return false; | |||
332 | ||||
333 | /* From page 27 (page 33 of the PDF) of the GLSL 1.50 spec: | |||
334 | * | |||
335 | * "There are no implicit array or structure conversions. For | |||
336 | * example, an array of int cannot be implicitly converted to an | |||
337 | * array of float. | |||
338 | */ | |||
339 | if (!to->is_numeric() || !from->type->is_numeric()) | |||
340 | return false; | |||
341 | ||||
342 | /* We don't actually want the specific type `to`, we want a type | |||
343 | * with the same base type as `to`, but the same vector width as | |||
344 | * `from`. | |||
345 | */ | |||
346 | to = glsl_type::get_instance(to->base_type, from->type->vector_elements, | |||
347 | from->type->matrix_columns); | |||
348 | ||||
349 | ir_expression_operation op = get_implicit_conversion_operation(to, from->type, state); | |||
350 | if (op) { | |||
351 | from = new(ctx) ir_expression(op, to, from, NULL__null); | |||
352 | return true; | |||
353 | } else { | |||
354 | return false; | |||
355 | } | |||
356 | } | |||
357 | ||||
358 | ||||
359 | static const struct glsl_type * | |||
360 | arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b, | |||
361 | bool multiply, | |||
362 | struct _mesa_glsl_parse_state *state, YYLTYPE *loc) | |||
363 | { | |||
364 | const glsl_type *type_a = value_a->type; | |||
365 | const glsl_type *type_b = value_b->type; | |||
366 | ||||
367 | /* From GLSL 1.50 spec, page 56: | |||
368 | * | |||
369 | * "The arithmetic binary operators add (+), subtract (-), | |||
370 | * multiply (*), and divide (/) operate on integer and | |||
371 | * floating-point scalars, vectors, and matrices." | |||
372 | */ | |||
373 | if (!type_a->is_numeric() || !type_b->is_numeric()) { | |||
374 | _mesa_glsl_error(loc, state, | |||
375 | "operands to arithmetic operators must be numeric"); | |||
376 | return glsl_type::error_type; | |||
377 | } | |||
378 | ||||
379 | ||||
380 | /* "If one operand is floating-point based and the other is | |||
381 | * not, then the conversions from Section 4.1.10 "Implicit | |||
382 | * Conversions" are applied to the non-floating-point-based operand." | |||
383 | */ | |||
384 | if (!apply_implicit_conversion(type_a, value_b, state) | |||
385 | && !apply_implicit_conversion(type_b, value_a, state)) { | |||
386 | _mesa_glsl_error(loc, state, | |||
387 | "could not implicitly convert operands to " | |||
388 | "arithmetic operator"); | |||
389 | return glsl_type::error_type; | |||
390 | } | |||
391 | type_a = value_a->type; | |||
392 | type_b = value_b->type; | |||
393 | ||||
394 | /* "If the operands are integer types, they must both be signed or | |||
395 | * both be unsigned." | |||
396 | * | |||
397 | * From this rule and the preceeding conversion it can be inferred that | |||
398 | * both types must be GLSL_TYPE_FLOAT, or GLSL_TYPE_UINT, or GLSL_TYPE_INT. | |||
399 | * The is_numeric check above already filtered out the case where either | |||
400 | * type is not one of these, so now the base types need only be tested for | |||
401 | * equality. | |||
402 | */ | |||
403 | if (type_a->base_type != type_b->base_type) { | |||
404 | _mesa_glsl_error(loc, state, | |||
405 | "base type mismatch for arithmetic operator"); | |||
406 | return glsl_type::error_type; | |||
407 | } | |||
408 | ||||
409 | /* "All arithmetic binary operators result in the same fundamental type | |||
410 | * (signed integer, unsigned integer, or floating-point) as the | |||
411 | * operands they operate on, after operand type conversion. After | |||
412 | * conversion, the following cases are valid | |||
413 | * | |||
414 | * * The two operands are scalars. In this case the operation is | |||
415 | * applied, resulting in a scalar." | |||
416 | */ | |||
417 | if (type_a->is_scalar() && type_b->is_scalar()) | |||
418 | return type_a; | |||
419 | ||||
420 | /* "* One operand is a scalar, and the other is a vector or matrix. | |||
421 | * In this case, the scalar operation is applied independently to each | |||
422 | * component of the vector or matrix, resulting in the same size | |||
423 | * vector or matrix." | |||
424 | */ | |||
425 | if (type_a->is_scalar()) { | |||
426 | if (!type_b->is_scalar()) | |||
427 | return type_b; | |||
428 | } else if (type_b->is_scalar()) { | |||
429 | return type_a; | |||
430 | } | |||
431 | ||||
432 | /* All of the combinations of <scalar, scalar>, <vector, scalar>, | |||
433 | * <scalar, vector>, <scalar, matrix>, and <matrix, scalar> have been | |||
434 | * handled. | |||
435 | */ | |||
436 | assert(!type_a->is_scalar())(static_cast <bool> (!type_a->is_scalar()) ? void (0 ) : __assert_fail ("!type_a->is_scalar()", __builtin_FILE ( ), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
437 | assert(!type_b->is_scalar())(static_cast <bool> (!type_b->is_scalar()) ? void (0 ) : __assert_fail ("!type_b->is_scalar()", __builtin_FILE ( ), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
438 | ||||
439 | /* "* The two operands are vectors of the same size. In this case, the | |||
440 | * operation is done component-wise resulting in the same size | |||
441 | * vector." | |||
442 | */ | |||
443 | if (type_a->is_vector() && type_b->is_vector()) { | |||
444 | if (type_a == type_b) { | |||
445 | return type_a; | |||
446 | } else { | |||
447 | _mesa_glsl_error(loc, state, | |||
448 | "vector size mismatch for arithmetic operator"); | |||
449 | return glsl_type::error_type; | |||
450 | } | |||
451 | } | |||
452 | ||||
453 | /* All of the combinations of <scalar, scalar>, <vector, scalar>, | |||
454 | * <scalar, vector>, <scalar, matrix>, <matrix, scalar>, and | |||
455 | * <vector, vector> have been handled. At least one of the operands must | |||
456 | * be matrix. Further, since there are no integer matrix types, the base | |||
457 | * type of both operands must be float. | |||
458 | */ | |||
459 | assert(type_a->is_matrix() || type_b->is_matrix())(static_cast <bool> (type_a->is_matrix() || type_b-> is_matrix()) ? void (0) : __assert_fail ("type_a->is_matrix() || type_b->is_matrix()" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); | |||
460 | assert(type_a->is_float() || type_a->is_double())(static_cast <bool> (type_a->is_float() || type_a-> is_double()) ? void (0) : __assert_fail ("type_a->is_float() || type_a->is_double()" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); | |||
461 | assert(type_b->is_float() || type_b->is_double())(static_cast <bool> (type_b->is_float() || type_b-> is_double()) ? void (0) : __assert_fail ("type_b->is_float() || type_b->is_double()" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); | |||
462 | ||||
463 | /* "* The operator is add (+), subtract (-), or divide (/), and the | |||
464 | * operands are matrices with the same number of rows and the same | |||
465 | * number of columns. In this case, the operation is done component- | |||
466 | * wise resulting in the same size matrix." | |||
467 | * * The operator is multiply (*), where both operands are matrices or | |||
468 | * one operand is a vector and the other a matrix. A right vector | |||
469 | * operand is treated as a column vector and a left vector operand as a | |||
470 | * row vector. In all these cases, it is required that the number of | |||
471 | * columns of the left operand is equal to the number of rows of the | |||
472 | * right operand. Then, the multiply (*) operation does a linear | |||
473 | * algebraic multiply, yielding an object that has the same number of | |||
474 | * rows as the left operand and the same number of columns as the right | |||
475 | * operand. Section 5.10 "Vector and Matrix Operations" explains in | |||
476 | * more detail how vectors and matrices are operated on." | |||
477 | */ | |||
478 | if (! multiply) { | |||
479 | if (type_a == type_b) | |||
480 | return type_a; | |||
481 | } else { | |||
482 | const glsl_type *type = glsl_type::get_mul_type(type_a, type_b); | |||
483 | ||||
484 | if (type == glsl_type::error_type) { | |||
485 | _mesa_glsl_error(loc, state, | |||
486 | "size mismatch for matrix multiplication"); | |||
487 | } | |||
488 | ||||
489 | return type; | |||
490 | } | |||
491 | ||||
492 | ||||
493 | /* "All other cases are illegal." | |||
494 | */ | |||
495 | _mesa_glsl_error(loc, state, "type mismatch"); | |||
496 | return glsl_type::error_type; | |||
497 | } | |||
498 | ||||
499 | ||||
500 | static const struct glsl_type * | |||
501 | unary_arithmetic_result_type(const struct glsl_type *type, | |||
502 | struct _mesa_glsl_parse_state *state, YYLTYPE *loc) | |||
503 | { | |||
504 | /* From GLSL 1.50 spec, page 57: | |||
505 | * | |||
506 | * "The arithmetic unary operators negate (-), post- and pre-increment | |||
507 | * and decrement (-- and ++) operate on integer or floating-point | |||
508 | * values (including vectors and matrices). All unary operators work | |||
509 | * component-wise on their operands. These result with the same type | |||
510 | * they operated on." | |||
511 | */ | |||
512 | if (!type->is_numeric()) { | |||
513 | _mesa_glsl_error(loc, state, | |||
514 | "operands to arithmetic operators must be numeric"); | |||
515 | return glsl_type::error_type; | |||
516 | } | |||
517 | ||||
518 | return type; | |||
519 | } | |||
520 | ||||
521 | /** | |||
522 | * \brief Return the result type of a bit-logic operation. | |||
523 | * | |||
524 | * If the given types to the bit-logic operator are invalid, return | |||
525 | * glsl_type::error_type. | |||
526 | * | |||
527 | * \param value_a LHS of bit-logic op | |||
528 | * \param value_b RHS of bit-logic op | |||
529 | */ | |||
530 | static const struct glsl_type * | |||
531 | bit_logic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b, | |||
532 | ast_operators op, | |||
533 | struct _mesa_glsl_parse_state *state, YYLTYPE *loc) | |||
534 | { | |||
535 | const glsl_type *type_a = value_a->type; | |||
536 | const glsl_type *type_b = value_b->type; | |||
537 | ||||
538 | if (!state->check_bitwise_operations_allowed(loc)) { | |||
539 | return glsl_type::error_type; | |||
540 | } | |||
541 | ||||
542 | /* From page 50 (page 56 of PDF) of GLSL 1.30 spec: | |||
543 | * | |||
544 | * "The bitwise operators and (&), exclusive-or (^), and inclusive-or | |||
545 | * (|). The operands must be of type signed or unsigned integers or | |||
546 | * integer vectors." | |||
547 | */ | |||
548 | if (!type_a->is_integer_32_64()) { | |||
549 | _mesa_glsl_error(loc, state, "LHS of `%s' must be an integer", | |||
550 | ast_expression::operator_string(op)); | |||
551 | return glsl_type::error_type; | |||
552 | } | |||
553 | if (!type_b->is_integer_32_64()) { | |||
554 | _mesa_glsl_error(loc, state, "RHS of `%s' must be an integer", | |||
555 | ast_expression::operator_string(op)); | |||
556 | return glsl_type::error_type; | |||
557 | } | |||
558 | ||||
559 | /* Prior to GLSL 4.0 / GL_ARB_gpu_shader5, implicit conversions didn't | |||
560 | * make sense for bitwise operations, as they don't operate on floats. | |||
561 | * | |||
562 | * GLSL 4.0 added implicit int -> uint conversions, which are relevant | |||
563 | * here. It wasn't clear whether or not we should apply them to bitwise | |||
564 | * operations. However, Khronos has decided that they should in future | |||
565 | * language revisions. Applications also rely on this behavior. We opt | |||
566 | * to apply them in general, but issue a portability warning. | |||
567 | * | |||
568 | * See https://www.khronos.org/bugzilla/show_bug.cgi?id=1405 | |||
569 | */ | |||
570 | if (type_a->base_type != type_b->base_type) { | |||
571 | if (!apply_implicit_conversion(type_a, value_b, state) | |||
572 | && !apply_implicit_conversion(type_b, value_a, state)) { | |||
573 | _mesa_glsl_error(loc, state, | |||
574 | "could not implicitly convert operands to " | |||
575 | "`%s` operator", | |||
576 | ast_expression::operator_string(op)); | |||
577 | return glsl_type::error_type; | |||
578 | } else { | |||
579 | _mesa_glsl_warning(loc, state, | |||
580 | "some implementations may not support implicit " | |||
581 | "int -> uint conversions for `%s' operators; " | |||
582 | "consider casting explicitly for portability", | |||
583 | ast_expression::operator_string(op)); | |||
584 | } | |||
585 | type_a = value_a->type; | |||
586 | type_b = value_b->type; | |||
587 | } | |||
588 | ||||
589 | /* "The fundamental types of the operands (signed or unsigned) must | |||
590 | * match," | |||
591 | */ | |||
592 | if (type_a->base_type != type_b->base_type) { | |||
593 | _mesa_glsl_error(loc, state, "operands of `%s' must have the same " | |||
594 | "base type", ast_expression::operator_string(op)); | |||
595 | return glsl_type::error_type; | |||
596 | } | |||
597 | ||||
598 | /* "The operands cannot be vectors of differing size." */ | |||
599 | if (type_a->is_vector() && | |||
600 | type_b->is_vector() && | |||
601 | type_a->vector_elements != type_b->vector_elements) { | |||
602 | _mesa_glsl_error(loc, state, "operands of `%s' cannot be vectors of " | |||
603 | "different sizes", ast_expression::operator_string(op)); | |||
604 | return glsl_type::error_type; | |||
605 | } | |||
606 | ||||
607 | /* "If one operand is a scalar and the other a vector, the scalar is | |||
608 | * applied component-wise to the vector, resulting in the same type as | |||
609 | * the vector. The fundamental types of the operands [...] will be the | |||
610 | * resulting fundamental type." | |||
611 | */ | |||
612 | if (type_a->is_scalar()) | |||
613 | return type_b; | |||
614 | else | |||
615 | return type_a; | |||
616 | } | |||
617 | ||||
618 | static const struct glsl_type * | |||
619 | modulus_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b, | |||
620 | struct _mesa_glsl_parse_state *state, YYLTYPE *loc) | |||
621 | { | |||
622 | const glsl_type *type_a = value_a->type; | |||
623 | const glsl_type *type_b = value_b->type; | |||
624 | ||||
625 | if (!state->EXT_gpu_shader4_enable && | |||
626 | !state->check_version(130, 300, loc, "operator '%%' is reserved")) { | |||
627 | return glsl_type::error_type; | |||
628 | } | |||
629 | ||||
630 | /* Section 5.9 (Expressions) of the GLSL 4.00 specification says: | |||
631 | * | |||
632 | * "The operator modulus (%) operates on signed or unsigned integers or | |||
633 | * integer vectors." | |||
634 | */ | |||
635 | if (!type_a->is_integer_32_64()) { | |||
636 | _mesa_glsl_error(loc, state, "LHS of operator %% must be an integer"); | |||
637 | return glsl_type::error_type; | |||
638 | } | |||
639 | if (!type_b->is_integer_32_64()) { | |||
640 | _mesa_glsl_error(loc, state, "RHS of operator %% must be an integer"); | |||
641 | return glsl_type::error_type; | |||
642 | } | |||
643 | ||||
644 | /* "If the fundamental types in the operands do not match, then the | |||
645 | * conversions from section 4.1.10 "Implicit Conversions" are applied | |||
646 | * to create matching types." | |||
647 | * | |||
648 | * Note that GLSL 4.00 (and GL_ARB_gpu_shader5) introduced implicit | |||
649 | * int -> uint conversion rules. Prior to that, there were no implicit | |||
650 | * conversions. So it's harmless to apply them universally - no implicit | |||
651 | * conversions will exist. If the types don't match, we'll receive false, | |||
652 | * and raise an error, satisfying the GLSL 1.50 spec, page 56: | |||
653 | * | |||
654 | * "The operand types must both be signed or unsigned." | |||
655 | */ | |||
656 | if (!apply_implicit_conversion(type_a, value_b, state) && | |||
657 | !apply_implicit_conversion(type_b, value_a, state)) { | |||
658 | _mesa_glsl_error(loc, state, | |||
659 | "could not implicitly convert operands to " | |||
660 | "modulus (%%) operator"); | |||
661 | return glsl_type::error_type; | |||
662 | } | |||
663 | type_a = value_a->type; | |||
664 | type_b = value_b->type; | |||
665 | ||||
666 | /* "The operands cannot be vectors of differing size. If one operand is | |||
667 | * a scalar and the other vector, then the scalar is applied component- | |||
668 | * wise to the vector, resulting in the same type as the vector. If both | |||
669 | * are vectors of the same size, the result is computed component-wise." | |||
670 | */ | |||
671 | if (type_a->is_vector()) { | |||
672 | if (!type_b->is_vector() | |||
673 | || (type_a->vector_elements == type_b->vector_elements)) | |||
674 | return type_a; | |||
675 | } else | |||
676 | return type_b; | |||
677 | ||||
678 | /* "The operator modulus (%) is not defined for any other data types | |||
679 | * (non-integer types)." | |||
680 | */ | |||
681 | _mesa_glsl_error(loc, state, "type mismatch"); | |||
682 | return glsl_type::error_type; | |||
683 | } | |||
684 | ||||
685 | ||||
686 | static const struct glsl_type * | |||
687 | relational_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b, | |||
688 | struct _mesa_glsl_parse_state *state, YYLTYPE *loc) | |||
689 | { | |||
690 | const glsl_type *type_a = value_a->type; | |||
691 | const glsl_type *type_b = value_b->type; | |||
692 | ||||
693 | /* From GLSL 1.50 spec, page 56: | |||
694 | * "The relational operators greater than (>), less than (<), greater | |||
695 | * than or equal (>=), and less than or equal (<=) operate only on | |||
696 | * scalar integer and scalar floating-point expressions." | |||
697 | */ | |||
698 | if (!type_a->is_numeric() | |||
699 | || !type_b->is_numeric() | |||
700 | || !type_a->is_scalar() | |||
701 | || !type_b->is_scalar()) { | |||
702 | _mesa_glsl_error(loc, state, | |||
703 | "operands to relational operators must be scalar and " | |||
704 | "numeric"); | |||
705 | return glsl_type::error_type; | |||
706 | } | |||
707 | ||||
708 | /* "Either the operands' types must match, or the conversions from | |||
709 | * Section 4.1.10 "Implicit Conversions" will be applied to the integer | |||
710 | * operand, after which the types must match." | |||
711 | */ | |||
712 | if (!apply_implicit_conversion(type_a, value_b, state) | |||
713 | && !apply_implicit_conversion(type_b, value_a, state)) { | |||
714 | _mesa_glsl_error(loc, state, | |||
715 | "could not implicitly convert operands to " | |||
716 | "relational operator"); | |||
717 | return glsl_type::error_type; | |||
718 | } | |||
719 | type_a = value_a->type; | |||
720 | type_b = value_b->type; | |||
721 | ||||
722 | if (type_a->base_type != type_b->base_type) { | |||
723 | _mesa_glsl_error(loc, state, "base type mismatch"); | |||
724 | return glsl_type::error_type; | |||
725 | } | |||
726 | ||||
727 | /* "The result is scalar Boolean." | |||
728 | */ | |||
729 | return glsl_type::bool_type; | |||
730 | } | |||
731 | ||||
732 | /** | |||
733 | * \brief Return the result type of a bit-shift operation. | |||
734 | * | |||
735 | * If the given types to the bit-shift operator are invalid, return | |||
736 | * glsl_type::error_type. | |||
737 | * | |||
738 | * \param type_a Type of LHS of bit-shift op | |||
739 | * \param type_b Type of RHS of bit-shift op | |||
740 | */ | |||
741 | static const struct glsl_type * | |||
742 | shift_result_type(const struct glsl_type *type_a, | |||
743 | const struct glsl_type *type_b, | |||
744 | ast_operators op, | |||
745 | struct _mesa_glsl_parse_state *state, YYLTYPE *loc) | |||
746 | { | |||
747 | if (!state->check_bitwise_operations_allowed(loc)) { | |||
748 | return glsl_type::error_type; | |||
749 | } | |||
750 | ||||
751 | /* From page 50 (page 56 of the PDF) of the GLSL 1.30 spec: | |||
752 | * | |||
753 | * "The shift operators (<<) and (>>). For both operators, the operands | |||
754 | * must be signed or unsigned integers or integer vectors. One operand | |||
755 | * can be signed while the other is unsigned." | |||
756 | */ | |||
757 | if (!type_a->is_integer_32_64()) { | |||
758 | _mesa_glsl_error(loc, state, "LHS of operator %s must be an integer or " | |||
759 | "integer vector", ast_expression::operator_string(op)); | |||
760 | return glsl_type::error_type; | |||
761 | ||||
762 | } | |||
763 | if (!type_b->is_integer_32()) { | |||
764 | _mesa_glsl_error(loc, state, "RHS of operator %s must be an integer or " | |||
765 | "integer vector", ast_expression::operator_string(op)); | |||
766 | return glsl_type::error_type; | |||
767 | } | |||
768 | ||||
769 | /* "If the first operand is a scalar, the second operand has to be | |||
770 | * a scalar as well." | |||
771 | */ | |||
772 | if (type_a->is_scalar() && !type_b->is_scalar()) { | |||
773 | _mesa_glsl_error(loc, state, "if the first operand of %s is scalar, the " | |||
774 | "second must be scalar as well", | |||
775 | ast_expression::operator_string(op)); | |||
776 | return glsl_type::error_type; | |||
777 | } | |||
778 | ||||
779 | /* If both operands are vectors, check that they have same number of | |||
780 | * elements. | |||
781 | */ | |||
782 | if (type_a->is_vector() && | |||
783 | type_b->is_vector() && | |||
784 | type_a->vector_elements != type_b->vector_elements) { | |||
785 | _mesa_glsl_error(loc, state, "vector operands to operator %s must " | |||
786 | "have same number of elements", | |||
787 | ast_expression::operator_string(op)); | |||
788 | return glsl_type::error_type; | |||
789 | } | |||
790 | ||||
791 | /* "In all cases, the resulting type will be the same type as the left | |||
792 | * operand." | |||
793 | */ | |||
794 | return type_a; | |||
795 | } | |||
796 | ||||
797 | /** | |||
798 | * Returns the innermost array index expression in an rvalue tree. | |||
799 | * This is the largest indexing level -- if an array of blocks, then | |||
800 | * it is the block index rather than an indexing expression for an | |||
801 | * array-typed member of an array of blocks. | |||
802 | */ | |||
803 | static ir_rvalue * | |||
804 | find_innermost_array_index(ir_rvalue *rv) | |||
805 | { | |||
806 | ir_dereference_array *last = NULL__null; | |||
807 | while (rv) { | |||
808 | if (rv->as_dereference_array()) { | |||
809 | last = rv->as_dereference_array(); | |||
810 | rv = last->array; | |||
811 | } else if (rv->as_dereference_record()) | |||
812 | rv = rv->as_dereference_record()->record; | |||
813 | else if (rv->as_swizzle()) | |||
814 | rv = rv->as_swizzle()->val; | |||
815 | else | |||
816 | rv = NULL__null; | |||
817 | } | |||
818 | ||||
819 | if (last) | |||
820 | return last->array_index; | |||
821 | ||||
822 | return NULL__null; | |||
823 | } | |||
824 | ||||
825 | /** | |||
826 | * Validates that a value can be assigned to a location with a specified type | |||
827 | * | |||
828 | * Validates that \c rhs can be assigned to some location. If the types are | |||
829 | * not an exact match but an automatic conversion is possible, \c rhs will be | |||
830 | * converted. | |||
831 | * | |||
832 | * \return | |||
833 | * \c NULL if \c rhs cannot be assigned to a location with type \c lhs_type. | |||
834 | * Otherwise the actual RHS to be assigned will be returned. This may be | |||
835 | * \c rhs, or it may be \c rhs after some type conversion. | |||
836 | * | |||
837 | * \note | |||
838 | * In addition to being used for assignments, this function is used to | |||
839 | * type-check return values. | |||
840 | */ | |||
841 | static ir_rvalue * | |||
842 | validate_assignment(struct _mesa_glsl_parse_state *state, | |||
843 | YYLTYPE loc, ir_rvalue *lhs, | |||
844 | ir_rvalue *rhs, bool is_initializer) | |||
845 | { | |||
846 | /* If there is already some error in the RHS, just return it. Anything | |||
847 | * else will lead to an avalanche of error message back to the user. | |||
848 | */ | |||
849 | if (rhs->type->is_error()) | |||
850 | return rhs; | |||
851 | ||||
852 | /* In the Tessellation Control Shader: | |||
853 | * If a per-vertex output variable is used as an l-value, it is an error | |||
854 | * if the expression indicating the vertex number is not the identifier | |||
855 | * `gl_InvocationID`. | |||
856 | */ | |||
857 | if (state->stage == MESA_SHADER_TESS_CTRL && !lhs->type->is_error()) { | |||
858 | ir_variable *var = lhs->variable_referenced(); | |||
859 | if (var && var->data.mode == ir_var_shader_out && !var->data.patch) { | |||
860 | ir_rvalue *index = find_innermost_array_index(lhs); | |||
861 | ir_variable *index_var = index ? index->variable_referenced() : NULL__null; | |||
862 | if (!index_var || strcmp(index_var->name, "gl_InvocationID") != 0) { | |||
863 | _mesa_glsl_error(&loc, state, | |||
864 | "Tessellation control shader outputs can only " | |||
865 | "be indexed by gl_InvocationID"); | |||
866 | return NULL__null; | |||
867 | } | |||
868 | } | |||
869 | } | |||
870 | ||||
871 | /* If the types are identical, the assignment can trivially proceed. | |||
872 | */ | |||
873 | if (rhs->type == lhs->type) | |||
874 | return rhs; | |||
875 | ||||
876 | /* If the array element types are the same and the LHS is unsized, | |||
877 | * the assignment is okay for initializers embedded in variable | |||
878 | * declarations. | |||
879 | * | |||
880 | * Note: Whole-array assignments are not permitted in GLSL 1.10, but this | |||
881 | * is handled by ir_dereference::is_lvalue. | |||
882 | */ | |||
883 | const glsl_type *lhs_t = lhs->type; | |||
884 | const glsl_type *rhs_t = rhs->type; | |||
885 | bool unsized_array = false; | |||
886 | while(lhs_t->is_array()) { | |||
887 | if (rhs_t == lhs_t) | |||
888 | break; /* the rest of the inner arrays match so break out early */ | |||
889 | if (!rhs_t->is_array()) { | |||
890 | unsized_array = false; | |||
891 | break; /* number of dimensions mismatch */ | |||
892 | } | |||
893 | if (lhs_t->length == rhs_t->length) { | |||
894 | lhs_t = lhs_t->fields.array; | |||
895 | rhs_t = rhs_t->fields.array; | |||
896 | continue; | |||
897 | } else if (lhs_t->is_unsized_array()) { | |||
898 | unsized_array = true; | |||
899 | } else { | |||
900 | unsized_array = false; | |||
901 | break; /* sized array mismatch */ | |||
902 | } | |||
903 | lhs_t = lhs_t->fields.array; | |||
904 | rhs_t = rhs_t->fields.array; | |||
905 | } | |||
906 | if (unsized_array) { | |||
907 | if (is_initializer) { | |||
908 | if (rhs->type->get_scalar_type() == lhs->type->get_scalar_type()) | |||
909 | return rhs; | |||
910 | } else { | |||
911 | _mesa_glsl_error(&loc, state, | |||
912 | "implicitly sized arrays cannot be assigned"); | |||
913 | return NULL__null; | |||
914 | } | |||
915 | } | |||
916 | ||||
917 | /* Check for implicit conversion in GLSL 1.20 */ | |||
918 | if (apply_implicit_conversion(lhs->type, rhs, state)) { | |||
919 | if (rhs->type == lhs->type) | |||
920 | return rhs; | |||
921 | } | |||
922 | ||||
923 | _mesa_glsl_error(&loc, state, | |||
924 | "%s of type %s cannot be assigned to " | |||
925 | "variable of type %s", | |||
926 | is_initializer ? "initializer" : "value", | |||
927 | rhs->type->name, lhs->type->name); | |||
928 | ||||
929 | return NULL__null; | |||
930 | } | |||
931 | ||||
932 | static void | |||
933 | mark_whole_array_access(ir_rvalue *access) | |||
934 | { | |||
935 | ir_dereference_variable *deref = access->as_dereference_variable(); | |||
936 | ||||
937 | if (deref && deref->var) { | |||
938 | deref->var->data.max_array_access = deref->type->length - 1; | |||
939 | } | |||
940 | } | |||
941 | ||||
942 | static bool | |||
943 | do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state, | |||
944 | const char *non_lvalue_description, | |||
945 | ir_rvalue *lhs, ir_rvalue *rhs, | |||
946 | ir_rvalue **out_rvalue, bool needs_rvalue, | |||
947 | bool is_initializer, | |||
948 | YYLTYPE lhs_loc) | |||
949 | { | |||
950 | void *ctx = state; | |||
951 | bool error_emitted = (lhs->type->is_error() || rhs->type->is_error()); | |||
952 | ||||
953 | ir_variable *lhs_var = lhs->variable_referenced(); | |||
954 | if (lhs_var) | |||
955 | lhs_var->data.assigned = true; | |||
956 | ||||
957 | if (!error_emitted) { | |||
958 | if (non_lvalue_description != NULL__null) { | |||
959 | _mesa_glsl_error(&lhs_loc, state, | |||
960 | "assignment to %s", | |||
961 | non_lvalue_description); | |||
962 | error_emitted = true; | |||
963 | } else if (lhs_var != NULL__null && (lhs_var->data.read_only || | |||
964 | (lhs_var->data.mode == ir_var_shader_storage && | |||
965 | lhs_var->data.memory_read_only))) { | |||
966 | /* We can have memory_read_only set on both images and buffer variables, | |||
967 | * but in the former there is a distinction between assignments to | |||
968 | * the variable itself (read_only) and to the memory they point to | |||
969 | * (memory_read_only), while in the case of buffer variables there is | |||
970 | * no such distinction, that is why this check here is limited to | |||
971 | * buffer variables alone. | |||
972 | */ | |||
973 | _mesa_glsl_error(&lhs_loc, state, | |||
974 | "assignment to read-only variable '%s'", | |||
975 | lhs_var->name); | |||
976 | error_emitted = true; | |||
977 | } else if (lhs->type->is_array() && | |||
978 | !state->check_version(120, 300, &lhs_loc, | |||
979 | "whole array assignment forbidden")) { | |||
980 | /* From page 32 (page 38 of the PDF) of the GLSL 1.10 spec: | |||
981 | * | |||
982 | * "Other binary or unary expressions, non-dereferenced | |||
983 | * arrays, function names, swizzles with repeated fields, | |||
984 | * and constants cannot be l-values." | |||
985 | * | |||
986 | * The restriction on arrays is lifted in GLSL 1.20 and GLSL ES 3.00. | |||
987 | */ | |||
988 | error_emitted = true; | |||
989 | } else if (!lhs->is_lvalue(state)) { | |||
990 | _mesa_glsl_error(& lhs_loc, state, "non-lvalue in assignment"); | |||
991 | error_emitted = true; | |||
992 | } | |||
993 | } | |||
994 | ||||
995 | ir_rvalue *new_rhs = | |||
996 | validate_assignment(state, lhs_loc, lhs, rhs, is_initializer); | |||
997 | if (new_rhs != NULL__null) { | |||
998 | rhs = new_rhs; | |||
999 | ||||
1000 | /* If the LHS array was not declared with a size, it takes it size from | |||
1001 | * the RHS. If the LHS is an l-value and a whole array, it must be a | |||
1002 | * dereference of a variable. Any other case would require that the LHS | |||
1003 | * is either not an l-value or not a whole array. | |||
1004 | */ | |||
1005 | if (lhs->type->is_unsized_array()) { | |||
1006 | ir_dereference *const d = lhs->as_dereference(); | |||
1007 | ||||
1008 | assert(d != NULL)(static_cast <bool> (d != __null) ? void (0) : __assert_fail ("d != NULL", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
1009 | ||||
1010 | ir_variable *const var = d->variable_referenced(); | |||
1011 | ||||
1012 | assert(var != NULL)(static_cast <bool> (var != __null) ? void (0) : __assert_fail ("var != NULL", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
1013 | ||||
1014 | if (var->data.max_array_access >= rhs->type->array_size()) { | |||
1015 | /* FINISHME: This should actually log the location of the RHS. */ | |||
1016 | _mesa_glsl_error(& lhs_loc, state, "array size must be > %u due to " | |||
1017 | "previous access", | |||
1018 | var->data.max_array_access); | |||
1019 | } | |||
1020 | ||||
1021 | var->type = glsl_type::get_array_instance(lhs->type->fields.array, | |||
1022 | rhs->type->array_size()); | |||
1023 | d->type = var->type; | |||
1024 | } | |||
1025 | if (lhs->type->is_array()) { | |||
1026 | mark_whole_array_access(rhs); | |||
1027 | mark_whole_array_access(lhs); | |||
1028 | } | |||
1029 | } else { | |||
1030 | error_emitted = true; | |||
1031 | } | |||
1032 | ||||
1033 | /* Most callers of do_assignment (assign, add_assign, pre_inc/dec, | |||
1034 | * but not post_inc) need the converted assigned value as an rvalue | |||
1035 | * to handle things like: | |||
1036 | * | |||
1037 | * i = j += 1; | |||
1038 | */ | |||
1039 | if (needs_rvalue) { | |||
1040 | ir_rvalue *rvalue; | |||
1041 | if (!error_emitted) { | |||
1042 | ir_variable *var = new(ctx) ir_variable(rhs->type, "assignment_tmp", | |||
1043 | ir_var_temporary); | |||
1044 | instructions->push_tail(var); | |||
1045 | instructions->push_tail(assign(var, rhs)); | |||
1046 | ||||
1047 | ir_dereference_variable *deref_var = | |||
1048 | new(ctx) ir_dereference_variable(var); | |||
1049 | instructions->push_tail(new(ctx) ir_assignment(lhs, deref_var)); | |||
1050 | rvalue = new(ctx) ir_dereference_variable(var); | |||
1051 | } else { | |||
1052 | rvalue = ir_rvalue::error_value(ctx); | |||
1053 | } | |||
1054 | *out_rvalue = rvalue; | |||
1055 | } else { | |||
1056 | if (!error_emitted) | |||
1057 | instructions->push_tail(new(ctx) ir_assignment(lhs, rhs)); | |||
1058 | *out_rvalue = NULL__null; | |||
1059 | } | |||
1060 | ||||
1061 | return error_emitted; | |||
1062 | } | |||
1063 | ||||
1064 | static ir_rvalue * | |||
1065 | get_lvalue_copy(exec_list *instructions, ir_rvalue *lvalue) | |||
1066 | { | |||
1067 | void *ctx = ralloc_parent(lvalue); | |||
1068 | ir_variable *var; | |||
1069 | ||||
1070 | var = new(ctx) ir_variable(lvalue->type, "_post_incdec_tmp", | |||
1071 | ir_var_temporary); | |||
1072 | instructions->push_tail(var); | |||
1073 | ||||
1074 | instructions->push_tail(new(ctx) ir_assignment(new(ctx) ir_dereference_variable(var), | |||
1075 | lvalue)); | |||
1076 | ||||
1077 | return new(ctx) ir_dereference_variable(var); | |||
1078 | } | |||
1079 | ||||
1080 | ||||
1081 | ir_rvalue * | |||
1082 | ast_node::hir(exec_list *instructions, struct _mesa_glsl_parse_state *state) | |||
1083 | { | |||
1084 | (void) instructions; | |||
1085 | (void) state; | |||
1086 | ||||
1087 | return NULL__null; | |||
1088 | } | |||
1089 | ||||
1090 | bool | |||
1091 | ast_node::has_sequence_subexpression() const | |||
1092 | { | |||
1093 | return false; | |||
1094 | } | |||
1095 | ||||
1096 | void | |||
1097 | ast_node::set_is_lhs(bool /* new_value */) | |||
1098 | { | |||
1099 | } | |||
1100 | ||||
1101 | void | |||
1102 | ast_function_expression::hir_no_rvalue(exec_list *instructions, | |||
1103 | struct _mesa_glsl_parse_state *state) | |||
1104 | { | |||
1105 | (void)hir(instructions, state); | |||
1106 | } | |||
1107 | ||||
1108 | void | |||
1109 | ast_aggregate_initializer::hir_no_rvalue(exec_list *instructions, | |||
1110 | struct _mesa_glsl_parse_state *state) | |||
1111 | { | |||
1112 | (void)hir(instructions, state); | |||
1113 | } | |||
1114 | ||||
1115 | static ir_rvalue * | |||
1116 | do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1) | |||
1117 | { | |||
1118 | int join_op; | |||
1119 | ir_rvalue *cmp = NULL__null; | |||
1120 | ||||
1121 | if (operation == ir_binop_all_equal) | |||
1122 | join_op = ir_binop_logic_and; | |||
1123 | else | |||
1124 | join_op = ir_binop_logic_or; | |||
1125 | ||||
1126 | switch (op0->type->base_type) { | |||
1127 | case GLSL_TYPE_FLOAT: | |||
1128 | case GLSL_TYPE_FLOAT16: | |||
1129 | case GLSL_TYPE_UINT: | |||
1130 | case GLSL_TYPE_INT: | |||
1131 | case GLSL_TYPE_BOOL: | |||
1132 | case GLSL_TYPE_DOUBLE: | |||
1133 | case GLSL_TYPE_UINT64: | |||
1134 | case GLSL_TYPE_INT64: | |||
1135 | case GLSL_TYPE_UINT16: | |||
1136 | case GLSL_TYPE_INT16: | |||
1137 | case GLSL_TYPE_UINT8: | |||
1138 | case GLSL_TYPE_INT8: | |||
1139 | return new(mem_ctx) ir_expression(operation, op0, op1); | |||
1140 | ||||
1141 | case GLSL_TYPE_ARRAY: { | |||
1142 | for (unsigned int i = 0; i < op0->type->length; i++) { | |||
1143 | ir_rvalue *e0, *e1, *result; | |||
1144 | ||||
1145 | e0 = new(mem_ctx) ir_dereference_array(op0->clone(mem_ctx, NULL__null), | |||
1146 | new(mem_ctx) ir_constant(i)); | |||
1147 | e1 = new(mem_ctx) ir_dereference_array(op1->clone(mem_ctx, NULL__null), | |||
1148 | new(mem_ctx) ir_constant(i)); | |||
1149 | result = do_comparison(mem_ctx, operation, e0, e1); | |||
1150 | ||||
1151 | if (cmp) { | |||
1152 | cmp = new(mem_ctx) ir_expression(join_op, cmp, result); | |||
1153 | } else { | |||
1154 | cmp = result; | |||
1155 | } | |||
1156 | } | |||
1157 | ||||
1158 | mark_whole_array_access(op0); | |||
1159 | mark_whole_array_access(op1); | |||
1160 | break; | |||
1161 | } | |||
1162 | ||||
1163 | case GLSL_TYPE_STRUCT: { | |||
1164 | for (unsigned int i = 0; i < op0->type->length; i++) { | |||
1165 | ir_rvalue *e0, *e1, *result; | |||
1166 | const char *field_name = op0->type->fields.structure[i].name; | |||
1167 | ||||
1168 | e0 = new(mem_ctx) ir_dereference_record(op0->clone(mem_ctx, NULL__null), | |||
1169 | field_name); | |||
1170 | e1 = new(mem_ctx) ir_dereference_record(op1->clone(mem_ctx, NULL__null), | |||
1171 | field_name); | |||
1172 | result = do_comparison(mem_ctx, operation, e0, e1); | |||
1173 | ||||
1174 | if (cmp) { | |||
1175 | cmp = new(mem_ctx) ir_expression(join_op, cmp, result); | |||
1176 | } else { | |||
1177 | cmp = result; | |||
1178 | } | |||
1179 | } | |||
1180 | break; | |||
1181 | } | |||
1182 | ||||
1183 | case GLSL_TYPE_ERROR: | |||
1184 | case GLSL_TYPE_VOID: | |||
1185 | case GLSL_TYPE_SAMPLER: | |||
1186 | case GLSL_TYPE_IMAGE: | |||
1187 | case GLSL_TYPE_INTERFACE: | |||
1188 | case GLSL_TYPE_ATOMIC_UINT: | |||
1189 | case GLSL_TYPE_SUBROUTINE: | |||
1190 | case GLSL_TYPE_FUNCTION: | |||
1191 | /* I assume a comparison of a struct containing a sampler just | |||
1192 | * ignores the sampler present in the type. | |||
1193 | */ | |||
1194 | break; | |||
1195 | } | |||
1196 | ||||
1197 | if (cmp == NULL__null) | |||
1198 | cmp = new(mem_ctx) ir_constant(true); | |||
1199 | ||||
1200 | return cmp; | |||
1201 | } | |||
1202 | ||||
1203 | /* For logical operations, we want to ensure that the operands are | |||
1204 | * scalar booleans. If it isn't, emit an error and return a constant | |||
1205 | * boolean to avoid triggering cascading error messages. | |||
1206 | */ | |||
1207 | static ir_rvalue * | |||
1208 | get_scalar_boolean_operand(exec_list *instructions, | |||
1209 | struct _mesa_glsl_parse_state *state, | |||
1210 | ast_expression *parent_expr, | |||
1211 | int operand, | |||
1212 | const char *operand_name, | |||
1213 | bool *error_emitted) | |||
1214 | { | |||
1215 | ast_expression *expr = parent_expr->subexpressions[operand]; | |||
1216 | void *ctx = state; | |||
1217 | ir_rvalue *val = expr->hir(instructions, state); | |||
1218 | ||||
1219 | if (val->type->is_boolean() && val->type->is_scalar()) | |||
1220 | return val; | |||
1221 | ||||
1222 | if (!*error_emitted) { | |||
1223 | YYLTYPE loc = expr->get_location(); | |||
1224 | _mesa_glsl_error(&loc, state, "%s of `%s' must be scalar boolean", | |||
1225 | operand_name, | |||
1226 | parent_expr->operator_string(parent_expr->oper)); | |||
1227 | *error_emitted = true; | |||
1228 | } | |||
1229 | ||||
1230 | return new(ctx) ir_constant(true); | |||
1231 | } | |||
1232 | ||||
1233 | /** | |||
1234 | * If name refers to a builtin array whose maximum allowed size is less than | |||
1235 | * size, report an error and return true. Otherwise return false. | |||
1236 | */ | |||
1237 | void | |||
1238 | check_builtin_array_max_size(const char *name, unsigned size, | |||
1239 | YYLTYPE loc, struct _mesa_glsl_parse_state *state) | |||
1240 | { | |||
1241 | if ((strcmp("gl_TexCoord", name) == 0) | |||
1242 | && (size > state->Const.MaxTextureCoords)) { | |||
1243 | /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec: | |||
1244 | * | |||
1245 | * "The size [of gl_TexCoord] can be at most | |||
1246 | * gl_MaxTextureCoords." | |||
1247 | */ | |||
1248 | _mesa_glsl_error(&loc, state, "`gl_TexCoord' array size cannot " | |||
1249 | "be larger than gl_MaxTextureCoords (%u)", | |||
1250 | state->Const.MaxTextureCoords); | |||
1251 | } else if (strcmp("gl_ClipDistance", name) == 0) { | |||
1252 | state->clip_dist_size = size; | |||
1253 | if (size + state->cull_dist_size > state->Const.MaxClipPlanes) { | |||
1254 | /* From section 7.1 (Vertex Shader Special Variables) of the | |||
1255 | * GLSL 1.30 spec: | |||
1256 | * | |||
1257 | * "The gl_ClipDistance array is predeclared as unsized and | |||
1258 | * must be sized by the shader either redeclaring it with a | |||
1259 | * size or indexing it only with integral constant | |||
1260 | * expressions. ... The size can be at most | |||
1261 | * gl_MaxClipDistances." | |||
1262 | */ | |||
1263 | _mesa_glsl_error(&loc, state, "`gl_ClipDistance' array size cannot " | |||
1264 | "be larger than gl_MaxClipDistances (%u)", | |||
1265 | state->Const.MaxClipPlanes); | |||
1266 | } | |||
1267 | } else if (strcmp("gl_CullDistance", name) == 0) { | |||
1268 | state->cull_dist_size = size; | |||
1269 | if (size + state->clip_dist_size > state->Const.MaxClipPlanes) { | |||
1270 | /* From the ARB_cull_distance spec: | |||
1271 | * | |||
1272 | * "The gl_CullDistance array is predeclared as unsized and | |||
1273 | * must be sized by the shader either redeclaring it with | |||
1274 | * a size or indexing it only with integral constant | |||
1275 | * expressions. The size determines the number and set of | |||
1276 | * enabled cull distances and can be at most | |||
1277 | * gl_MaxCullDistances." | |||
1278 | */ | |||
1279 | _mesa_glsl_error(&loc, state, "`gl_CullDistance' array size cannot " | |||
1280 | "be larger than gl_MaxCullDistances (%u)", | |||
1281 | state->Const.MaxClipPlanes); | |||
1282 | } | |||
1283 | } | |||
1284 | } | |||
1285 | ||||
1286 | /** | |||
1287 | * Create the constant 1, of a which is appropriate for incrementing and | |||
1288 | * decrementing values of the given GLSL type. For example, if type is vec4, | |||
1289 | * this creates a constant value of 1.0 having type float. | |||
1290 | * | |||
1291 | * If the given type is invalid for increment and decrement operators, return | |||
1292 | * a floating point 1--the error will be detected later. | |||
1293 | */ | |||
1294 | static ir_rvalue * | |||
1295 | constant_one_for_inc_dec(void *ctx, const glsl_type *type) | |||
1296 | { | |||
1297 | switch (type->base_type) { | |||
1298 | case GLSL_TYPE_UINT: | |||
1299 | return new(ctx) ir_constant((unsigned) 1); | |||
1300 | case GLSL_TYPE_INT: | |||
1301 | return new(ctx) ir_constant(1); | |||
1302 | case GLSL_TYPE_UINT64: | |||
1303 | return new(ctx) ir_constant((uint64_t) 1); | |||
1304 | case GLSL_TYPE_INT64: | |||
1305 | return new(ctx) ir_constant((int64_t) 1); | |||
1306 | default: | |||
1307 | case GLSL_TYPE_FLOAT: | |||
1308 | return new(ctx) ir_constant(1.0f); | |||
1309 | } | |||
1310 | } | |||
1311 | ||||
1312 | ir_rvalue * | |||
1313 | ast_expression::hir(exec_list *instructions, | |||
1314 | struct _mesa_glsl_parse_state *state) | |||
1315 | { | |||
1316 | return do_hir(instructions, state, true); | |||
1317 | } | |||
1318 | ||||
1319 | void | |||
1320 | ast_expression::hir_no_rvalue(exec_list *instructions, | |||
1321 | struct _mesa_glsl_parse_state *state) | |||
1322 | { | |||
1323 | do_hir(instructions, state, false); | |||
1324 | } | |||
1325 | ||||
1326 | void | |||
1327 | ast_expression::set_is_lhs(bool new_value) | |||
1328 | { | |||
1329 | /* is_lhs is tracked only to print "variable used uninitialized" warnings, | |||
1330 | * if we lack an identifier we can just skip it. | |||
1331 | */ | |||
1332 | if (this->primary_expression.identifier == NULL__null) | |||
1333 | return; | |||
1334 | ||||
1335 | this->is_lhs = new_value; | |||
1336 | ||||
1337 | /* We need to go through the subexpressions tree to cover cases like | |||
1338 | * ast_field_selection | |||
1339 | */ | |||
1340 | if (this->subexpressions[0] != NULL__null) | |||
1341 | this->subexpressions[0]->set_is_lhs(new_value); | |||
1342 | } | |||
1343 | ||||
1344 | ir_rvalue * | |||
1345 | ast_expression::do_hir(exec_list *instructions, | |||
1346 | struct _mesa_glsl_parse_state *state, | |||
1347 | bool needs_rvalue) | |||
1348 | { | |||
1349 | void *ctx = state; | |||
1350 | static const int operations[AST_NUM_OPERATORS(ast_aggregate + 1)] = { | |||
1351 | -1, /* ast_assign doesn't convert to ir_expression. */ | |||
1352 | -1, /* ast_plus doesn't convert to ir_expression. */ | |||
1353 | ir_unop_neg, | |||
1354 | ir_binop_add, | |||
1355 | ir_binop_sub, | |||
1356 | ir_binop_mul, | |||
1357 | ir_binop_div, | |||
1358 | ir_binop_mod, | |||
1359 | ir_binop_lshift, | |||
1360 | ir_binop_rshift, | |||
1361 | ir_binop_less, | |||
1362 | ir_binop_less, /* This is correct. See the ast_greater case below. */ | |||
1363 | ir_binop_gequal, /* This is correct. See the ast_lequal case below. */ | |||
1364 | ir_binop_gequal, | |||
1365 | ir_binop_all_equal, | |||
1366 | ir_binop_any_nequal, | |||
1367 | ir_binop_bit_and, | |||
1368 | ir_binop_bit_xor, | |||
1369 | ir_binop_bit_or, | |||
1370 | ir_unop_bit_not, | |||
1371 | ir_binop_logic_and, | |||
1372 | ir_binop_logic_xor, | |||
1373 | ir_binop_logic_or, | |||
1374 | ir_unop_logic_not, | |||
1375 | ||||
1376 | /* Note: The following block of expression types actually convert | |||
1377 | * to multiple IR instructions. | |||
1378 | */ | |||
1379 | ir_binop_mul, /* ast_mul_assign */ | |||
1380 | ir_binop_div, /* ast_div_assign */ | |||
1381 | ir_binop_mod, /* ast_mod_assign */ | |||
1382 | ir_binop_add, /* ast_add_assign */ | |||
1383 | ir_binop_sub, /* ast_sub_assign */ | |||
1384 | ir_binop_lshift, /* ast_ls_assign */ | |||
1385 | ir_binop_rshift, /* ast_rs_assign */ | |||
1386 | ir_binop_bit_and, /* ast_and_assign */ | |||
1387 | ir_binop_bit_xor, /* ast_xor_assign */ | |||
1388 | ir_binop_bit_or, /* ast_or_assign */ | |||
1389 | ||||
1390 | -1, /* ast_conditional doesn't convert to ir_expression. */ | |||
1391 | ir_binop_add, /* ast_pre_inc. */ | |||
1392 | ir_binop_sub, /* ast_pre_dec. */ | |||
1393 | ir_binop_add, /* ast_post_inc. */ | |||
1394 | ir_binop_sub, /* ast_post_dec. */ | |||
1395 | -1, /* ast_field_selection doesn't conv to ir_expression. */ | |||
1396 | -1, /* ast_array_index doesn't convert to ir_expression. */ | |||
1397 | -1, /* ast_function_call doesn't conv to ir_expression. */ | |||
1398 | -1, /* ast_identifier doesn't convert to ir_expression. */ | |||
1399 | -1, /* ast_int_constant doesn't convert to ir_expression. */ | |||
1400 | -1, /* ast_uint_constant doesn't conv to ir_expression. */ | |||
1401 | -1, /* ast_float_constant doesn't conv to ir_expression. */ | |||
1402 | -1, /* ast_bool_constant doesn't conv to ir_expression. */ | |||
1403 | -1, /* ast_sequence doesn't convert to ir_expression. */ | |||
1404 | -1, /* ast_aggregate shouldn't ever even get here. */ | |||
1405 | }; | |||
1406 | ir_rvalue *result = NULL__null; | |||
1407 | ir_rvalue *op[3]; | |||
1408 | const struct glsl_type *type, *orig_type; | |||
1409 | bool error_emitted = false; | |||
1410 | YYLTYPE loc; | |||
1411 | ||||
1412 | loc = this->get_location(); | |||
1413 | ||||
1414 | switch (this->oper) { | |||
1415 | case ast_aggregate: | |||
1416 | unreachable("ast_aggregate: Should never get here.")do { (static_cast <bool> (!"ast_aggregate: Should never get here." ) ? void (0) : __assert_fail ("!\"ast_aggregate: Should never get here.\"" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); __builtin_unreachable(); } while (0); | |||
1417 | ||||
1418 | case ast_assign: { | |||
1419 | this->subexpressions[0]->set_is_lhs(true); | |||
1420 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1421 | op[1] = this->subexpressions[1]->hir(instructions, state); | |||
1422 | ||||
1423 | error_emitted = | |||
1424 | do_assignment(instructions, state, | |||
1425 | this->subexpressions[0]->non_lvalue_description, | |||
1426 | op[0], op[1], &result, needs_rvalue, false, | |||
1427 | this->subexpressions[0]->get_location()); | |||
1428 | break; | |||
1429 | } | |||
1430 | ||||
1431 | case ast_plus: | |||
1432 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1433 | ||||
1434 | type = unary_arithmetic_result_type(op[0]->type, state, & loc); | |||
1435 | ||||
1436 | error_emitted = type->is_error(); | |||
1437 | ||||
1438 | result = op[0]; | |||
1439 | break; | |||
1440 | ||||
1441 | case ast_neg: | |||
1442 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1443 | ||||
1444 | type = unary_arithmetic_result_type(op[0]->type, state, & loc); | |||
1445 | ||||
1446 | error_emitted = type->is_error(); | |||
1447 | ||||
1448 | result = new(ctx) ir_expression(operations[this->oper], type, | |||
1449 | op[0], NULL__null); | |||
1450 | break; | |||
1451 | ||||
1452 | case ast_add: | |||
1453 | case ast_sub: | |||
1454 | case ast_mul: | |||
1455 | case ast_div: | |||
1456 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1457 | op[1] = this->subexpressions[1]->hir(instructions, state); | |||
1458 | ||||
1459 | type = arithmetic_result_type(op[0], op[1], | |||
1460 | (this->oper == ast_mul), | |||
1461 | state, & loc); | |||
1462 | error_emitted = type->is_error(); | |||
1463 | ||||
1464 | result = new(ctx) ir_expression(operations[this->oper], type, | |||
1465 | op[0], op[1]); | |||
1466 | break; | |||
1467 | ||||
1468 | case ast_mod: | |||
1469 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1470 | op[1] = this->subexpressions[1]->hir(instructions, state); | |||
1471 | ||||
1472 | type = modulus_result_type(op[0], op[1], state, &loc); | |||
1473 | ||||
1474 | assert(operations[this->oper] == ir_binop_mod)(static_cast <bool> (operations[this->oper] == ir_binop_mod ) ? void (0) : __assert_fail ("operations[this->oper] == ir_binop_mod" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); | |||
1475 | ||||
1476 | result = new(ctx) ir_expression(operations[this->oper], type, | |||
1477 | op[0], op[1]); | |||
1478 | error_emitted = type->is_error(); | |||
1479 | break; | |||
1480 | ||||
1481 | case ast_lshift: | |||
1482 | case ast_rshift: | |||
1483 | if (!state->check_bitwise_operations_allowed(&loc)) { | |||
1484 | error_emitted = true; | |||
1485 | } | |||
1486 | ||||
1487 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1488 | op[1] = this->subexpressions[1]->hir(instructions, state); | |||
1489 | type = shift_result_type(op[0]->type, op[1]->type, this->oper, state, | |||
1490 | &loc); | |||
1491 | result = new(ctx) ir_expression(operations[this->oper], type, | |||
1492 | op[0], op[1]); | |||
1493 | error_emitted = op[0]->type->is_error() || op[1]->type->is_error(); | |||
1494 | break; | |||
1495 | ||||
1496 | case ast_less: | |||
1497 | case ast_greater: | |||
1498 | case ast_lequal: | |||
1499 | case ast_gequal: | |||
1500 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1501 | op[1] = this->subexpressions[1]->hir(instructions, state); | |||
1502 | ||||
1503 | type = relational_result_type(op[0], op[1], state, & loc); | |||
1504 | ||||
1505 | /* The relational operators must either generate an error or result | |||
1506 | * in a scalar boolean. See page 57 of the GLSL 1.50 spec. | |||
1507 | */ | |||
1508 | assert(type->is_error()(static_cast <bool> (type->is_error() || (type->is_boolean () && type->is_scalar())) ? void (0) : __assert_fail ("type->is_error() || (type->is_boolean() && type->is_scalar())" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )) | |||
1509 | || (type->is_boolean() && type->is_scalar()))(static_cast <bool> (type->is_error() || (type->is_boolean () && type->is_scalar())) ? void (0) : __assert_fail ("type->is_error() || (type->is_boolean() && type->is_scalar())" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); | |||
1510 | ||||
1511 | /* Like NIR, GLSL IR does not have opcodes for > or <=. Instead, swap | |||
1512 | * the arguments and use < or >=. | |||
1513 | */ | |||
1514 | if (this->oper == ast_greater || this->oper == ast_lequal) { | |||
1515 | ir_rvalue *const tmp = op[0]; | |||
1516 | op[0] = op[1]; | |||
1517 | op[1] = tmp; | |||
1518 | } | |||
1519 | ||||
1520 | result = new(ctx) ir_expression(operations[this->oper], type, | |||
1521 | op[0], op[1]); | |||
1522 | error_emitted = type->is_error(); | |||
1523 | break; | |||
1524 | ||||
1525 | case ast_nequal: | |||
1526 | case ast_equal: | |||
1527 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1528 | op[1] = this->subexpressions[1]->hir(instructions, state); | |||
1529 | ||||
1530 | /* From page 58 (page 64 of the PDF) of the GLSL 1.50 spec: | |||
1531 | * | |||
1532 | * "The equality operators equal (==), and not equal (!=) | |||
1533 | * operate on all types. They result in a scalar Boolean. If | |||
1534 | * the operand types do not match, then there must be a | |||
1535 | * conversion from Section 4.1.10 "Implicit Conversions" | |||
1536 | * applied to one operand that can make them match, in which | |||
1537 | * case this conversion is done." | |||
1538 | */ | |||
1539 | ||||
1540 | if (op[0]->type == glsl_type::void_type || op[1]->type == glsl_type::void_type) { | |||
1541 | _mesa_glsl_error(& loc, state, "`%s': wrong operand types: " | |||
1542 | "no operation `%1$s' exists that takes a left-hand " | |||
1543 | "operand of type 'void' or a right operand of type " | |||
1544 | "'void'", (this->oper == ast_equal) ? "==" : "!="); | |||
1545 | error_emitted = true; | |||
1546 | } else if ((!apply_implicit_conversion(op[0]->type, op[1], state) | |||
1547 | && !apply_implicit_conversion(op[1]->type, op[0], state)) | |||
1548 | || (op[0]->type != op[1]->type)) { | |||
1549 | _mesa_glsl_error(& loc, state, "operands of `%s' must have the same " | |||
1550 | "type", (this->oper == ast_equal) ? "==" : "!="); | |||
1551 | error_emitted = true; | |||
1552 | } else if ((op[0]->type->is_array() || op[1]->type->is_array()) && | |||
1553 | !state->check_version(120, 300, &loc, | |||
1554 | "array comparisons forbidden")) { | |||
1555 | error_emitted = true; | |||
1556 | } else if ((op[0]->type->contains_subroutine() || | |||
1557 | op[1]->type->contains_subroutine())) { | |||
1558 | _mesa_glsl_error(&loc, state, "subroutine comparisons forbidden"); | |||
1559 | error_emitted = true; | |||
1560 | } else if ((op[0]->type->contains_opaque() || | |||
1561 | op[1]->type->contains_opaque())) { | |||
1562 | _mesa_glsl_error(&loc, state, "opaque type comparisons forbidden"); | |||
1563 | error_emitted = true; | |||
1564 | } | |||
1565 | ||||
1566 | if (error_emitted) { | |||
1567 | result = new(ctx) ir_constant(false); | |||
1568 | } else { | |||
1569 | result = do_comparison(ctx, operations[this->oper], op[0], op[1]); | |||
1570 | assert(result->type == glsl_type::bool_type)(static_cast <bool> (result->type == glsl_type::bool_type ) ? void (0) : __assert_fail ("result->type == glsl_type::bool_type" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); | |||
1571 | } | |||
1572 | break; | |||
1573 | ||||
1574 | case ast_bit_and: | |||
1575 | case ast_bit_xor: | |||
1576 | case ast_bit_or: | |||
1577 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1578 | op[1] = this->subexpressions[1]->hir(instructions, state); | |||
1579 | type = bit_logic_result_type(op[0], op[1], this->oper, state, &loc); | |||
1580 | result = new(ctx) ir_expression(operations[this->oper], type, | |||
1581 | op[0], op[1]); | |||
1582 | error_emitted = op[0]->type->is_error() || op[1]->type->is_error(); | |||
1583 | break; | |||
1584 | ||||
1585 | case ast_bit_not: | |||
1586 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1587 | ||||
1588 | if (!state->check_bitwise_operations_allowed(&loc)) { | |||
1589 | error_emitted = true; | |||
1590 | } | |||
1591 | ||||
1592 | if (!op[0]->type->is_integer_32_64()) { | |||
1593 | _mesa_glsl_error(&loc, state, "operand of `~' must be an integer"); | |||
1594 | error_emitted = true; | |||
1595 | } | |||
1596 | ||||
1597 | type = error_emitted ? glsl_type::error_type : op[0]->type; | |||
1598 | result = new(ctx) ir_expression(ir_unop_bit_not, type, op[0], NULL__null); | |||
1599 | break; | |||
1600 | ||||
1601 | case ast_logic_and: { | |||
1602 | exec_list rhs_instructions; | |||
1603 | op[0] = get_scalar_boolean_operand(instructions, state, this, 0, | |||
1604 | "LHS", &error_emitted); | |||
1605 | op[1] = get_scalar_boolean_operand(&rhs_instructions, state, this, 1, | |||
1606 | "RHS", &error_emitted); | |||
1607 | ||||
1608 | if (rhs_instructions.is_empty()) { | |||
1609 | result = new(ctx) ir_expression(ir_binop_logic_and, op[0], op[1]); | |||
1610 | } else { | |||
1611 | ir_variable *const tmp = new(ctx) ir_variable(glsl_type::bool_type, | |||
1612 | "and_tmp", | |||
1613 | ir_var_temporary); | |||
1614 | instructions->push_tail(tmp); | |||
1615 | ||||
1616 | ir_if *const stmt = new(ctx) ir_if(op[0]); | |||
1617 | instructions->push_tail(stmt); | |||
1618 | ||||
1619 | stmt->then_instructions.append_list(&rhs_instructions); | |||
1620 | ir_dereference *const then_deref = new(ctx) ir_dereference_variable(tmp); | |||
1621 | ir_assignment *const then_assign = | |||
1622 | new(ctx) ir_assignment(then_deref, op[1]); | |||
1623 | stmt->then_instructions.push_tail(then_assign); | |||
1624 | ||||
1625 | ir_dereference *const else_deref = new(ctx) ir_dereference_variable(tmp); | |||
1626 | ir_assignment *const else_assign = | |||
1627 | new(ctx) ir_assignment(else_deref, new(ctx) ir_constant(false)); | |||
1628 | stmt->else_instructions.push_tail(else_assign); | |||
1629 | ||||
1630 | result = new(ctx) ir_dereference_variable(tmp); | |||
1631 | } | |||
1632 | break; | |||
1633 | } | |||
1634 | ||||
1635 | case ast_logic_or: { | |||
1636 | exec_list rhs_instructions; | |||
1637 | op[0] = get_scalar_boolean_operand(instructions, state, this, 0, | |||
1638 | "LHS", &error_emitted); | |||
1639 | op[1] = get_scalar_boolean_operand(&rhs_instructions, state, this, 1, | |||
1640 | "RHS", &error_emitted); | |||
1641 | ||||
1642 | if (rhs_instructions.is_empty()) { | |||
1643 | result = new(ctx) ir_expression(ir_binop_logic_or, op[0], op[1]); | |||
1644 | } else { | |||
1645 | ir_variable *const tmp = new(ctx) ir_variable(glsl_type::bool_type, | |||
1646 | "or_tmp", | |||
1647 | ir_var_temporary); | |||
1648 | instructions->push_tail(tmp); | |||
1649 | ||||
1650 | ir_if *const stmt = new(ctx) ir_if(op[0]); | |||
1651 | instructions->push_tail(stmt); | |||
1652 | ||||
1653 | ir_dereference *const then_deref = new(ctx) ir_dereference_variable(tmp); | |||
1654 | ir_assignment *const then_assign = | |||
1655 | new(ctx) ir_assignment(then_deref, new(ctx) ir_constant(true)); | |||
1656 | stmt->then_instructions.push_tail(then_assign); | |||
1657 | ||||
1658 | stmt->else_instructions.append_list(&rhs_instructions); | |||
1659 | ir_dereference *const else_deref = new(ctx) ir_dereference_variable(tmp); | |||
1660 | ir_assignment *const else_assign = | |||
1661 | new(ctx) ir_assignment(else_deref, op[1]); | |||
1662 | stmt->else_instructions.push_tail(else_assign); | |||
1663 | ||||
1664 | result = new(ctx) ir_dereference_variable(tmp); | |||
1665 | } | |||
1666 | break; | |||
1667 | } | |||
1668 | ||||
1669 | case ast_logic_xor: | |||
1670 | /* From page 33 (page 39 of the PDF) of the GLSL 1.10 spec: | |||
1671 | * | |||
1672 | * "The logical binary operators and (&&), or ( | | ), and | |||
1673 | * exclusive or (^^). They operate only on two Boolean | |||
1674 | * expressions and result in a Boolean expression." | |||
1675 | */ | |||
1676 | op[0] = get_scalar_boolean_operand(instructions, state, this, 0, "LHS", | |||
1677 | &error_emitted); | |||
1678 | op[1] = get_scalar_boolean_operand(instructions, state, this, 1, "RHS", | |||
1679 | &error_emitted); | |||
1680 | ||||
1681 | result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type, | |||
1682 | op[0], op[1]); | |||
1683 | break; | |||
1684 | ||||
1685 | case ast_logic_not: | |||
1686 | op[0] = get_scalar_boolean_operand(instructions, state, this, 0, | |||
1687 | "operand", &error_emitted); | |||
1688 | ||||
1689 | result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type, | |||
1690 | op[0], NULL__null); | |||
1691 | break; | |||
1692 | ||||
1693 | case ast_mul_assign: | |||
1694 | case ast_div_assign: | |||
1695 | case ast_add_assign: | |||
1696 | case ast_sub_assign: { | |||
1697 | this->subexpressions[0]->set_is_lhs(true); | |||
1698 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1699 | op[1] = this->subexpressions[1]->hir(instructions, state); | |||
1700 | ||||
1701 | orig_type = op[0]->type; | |||
1702 | ||||
1703 | /* Break out if operand types were not parsed successfully. */ | |||
1704 | if ((op[0]->type == glsl_type::error_type || | |||
1705 | op[1]->type == glsl_type::error_type)) { | |||
1706 | error_emitted = true; | |||
1707 | break; | |||
1708 | } | |||
1709 | ||||
1710 | type = arithmetic_result_type(op[0], op[1], | |||
1711 | (this->oper == ast_mul_assign), | |||
1712 | state, & loc); | |||
1713 | ||||
1714 | if (type != orig_type) { | |||
1715 | _mesa_glsl_error(& loc, state, | |||
1716 | "could not implicitly convert " | |||
1717 | "%s to %s", type->name, orig_type->name); | |||
1718 | type = glsl_type::error_type; | |||
1719 | } | |||
1720 | ||||
1721 | ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper], type, | |||
1722 | op[0], op[1]); | |||
1723 | ||||
1724 | error_emitted = | |||
1725 | do_assignment(instructions, state, | |||
1726 | this->subexpressions[0]->non_lvalue_description, | |||
1727 | op[0]->clone(ctx, NULL__null), temp_rhs, | |||
1728 | &result, needs_rvalue, false, | |||
1729 | this->subexpressions[0]->get_location()); | |||
1730 | ||||
1731 | /* GLSL 1.10 does not allow array assignment. However, we don't have to | |||
1732 | * explicitly test for this because none of the binary expression | |||
1733 | * operators allow array operands either. | |||
1734 | */ | |||
1735 | ||||
1736 | break; | |||
1737 | } | |||
1738 | ||||
1739 | case ast_mod_assign: { | |||
1740 | this->subexpressions[0]->set_is_lhs(true); | |||
1741 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1742 | op[1] = this->subexpressions[1]->hir(instructions, state); | |||
1743 | ||||
1744 | orig_type = op[0]->type; | |||
1745 | type = modulus_result_type(op[0], op[1], state, &loc); | |||
1746 | ||||
1747 | if (type != orig_type) { | |||
1748 | _mesa_glsl_error(& loc, state, | |||
1749 | "could not implicitly convert " | |||
1750 | "%s to %s", type->name, orig_type->name); | |||
1751 | type = glsl_type::error_type; | |||
1752 | } | |||
1753 | ||||
1754 | assert(operations[this->oper] == ir_binop_mod)(static_cast <bool> (operations[this->oper] == ir_binop_mod ) ? void (0) : __assert_fail ("operations[this->oper] == ir_binop_mod" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); | |||
1755 | ||||
1756 | ir_rvalue *temp_rhs; | |||
1757 | temp_rhs = new(ctx) ir_expression(operations[this->oper], type, | |||
1758 | op[0], op[1]); | |||
1759 | ||||
1760 | error_emitted = | |||
1761 | do_assignment(instructions, state, | |||
1762 | this->subexpressions[0]->non_lvalue_description, | |||
1763 | op[0]->clone(ctx, NULL__null), temp_rhs, | |||
1764 | &result, needs_rvalue, false, | |||
1765 | this->subexpressions[0]->get_location()); | |||
1766 | break; | |||
1767 | } | |||
1768 | ||||
1769 | case ast_ls_assign: | |||
1770 | case ast_rs_assign: { | |||
1771 | this->subexpressions[0]->set_is_lhs(true); | |||
1772 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1773 | op[1] = this->subexpressions[1]->hir(instructions, state); | |||
1774 | type = shift_result_type(op[0]->type, op[1]->type, this->oper, state, | |||
1775 | &loc); | |||
1776 | ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper], | |||
1777 | type, op[0], op[1]); | |||
1778 | error_emitted = | |||
1779 | do_assignment(instructions, state, | |||
1780 | this->subexpressions[0]->non_lvalue_description, | |||
1781 | op[0]->clone(ctx, NULL__null), temp_rhs, | |||
1782 | &result, needs_rvalue, false, | |||
1783 | this->subexpressions[0]->get_location()); | |||
1784 | break; | |||
1785 | } | |||
1786 | ||||
1787 | case ast_and_assign: | |||
1788 | case ast_xor_assign: | |||
1789 | case ast_or_assign: { | |||
1790 | this->subexpressions[0]->set_is_lhs(true); | |||
1791 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1792 | op[1] = this->subexpressions[1]->hir(instructions, state); | |||
1793 | ||||
1794 | orig_type = op[0]->type; | |||
1795 | type = bit_logic_result_type(op[0], op[1], this->oper, state, &loc); | |||
1796 | ||||
1797 | if (type != orig_type) { | |||
1798 | _mesa_glsl_error(& loc, state, | |||
1799 | "could not implicitly convert " | |||
1800 | "%s to %s", type->name, orig_type->name); | |||
1801 | type = glsl_type::error_type; | |||
1802 | } | |||
1803 | ||||
1804 | ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper], | |||
1805 | type, op[0], op[1]); | |||
1806 | error_emitted = | |||
1807 | do_assignment(instructions, state, | |||
1808 | this->subexpressions[0]->non_lvalue_description, | |||
1809 | op[0]->clone(ctx, NULL__null), temp_rhs, | |||
1810 | &result, needs_rvalue, false, | |||
1811 | this->subexpressions[0]->get_location()); | |||
1812 | break; | |||
1813 | } | |||
1814 | ||||
1815 | case ast_conditional: { | |||
1816 | /* From page 59 (page 65 of the PDF) of the GLSL 1.50 spec: | |||
1817 | * | |||
1818 | * "The ternary selection operator (?:). It operates on three | |||
1819 | * expressions (exp1 ? exp2 : exp3). This operator evaluates the | |||
1820 | * first expression, which must result in a scalar Boolean." | |||
1821 | */ | |||
1822 | op[0] = get_scalar_boolean_operand(instructions, state, this, 0, | |||
1823 | "condition", &error_emitted); | |||
1824 | ||||
1825 | /* The :? operator is implemented by generating an anonymous temporary | |||
1826 | * followed by an if-statement. The last instruction in each branch of | |||
1827 | * the if-statement assigns a value to the anonymous temporary. This | |||
1828 | * temporary is the r-value of the expression. | |||
1829 | */ | |||
1830 | exec_list then_instructions; | |||
1831 | exec_list else_instructions; | |||
1832 | ||||
1833 | op[1] = this->subexpressions[1]->hir(&then_instructions, state); | |||
1834 | op[2] = this->subexpressions[2]->hir(&else_instructions, state); | |||
1835 | ||||
1836 | /* From page 59 (page 65 of the PDF) of the GLSL 1.50 spec: | |||
1837 | * | |||
1838 | * "The second and third expressions can be any type, as | |||
1839 | * long their types match, or there is a conversion in | |||
1840 | * Section 4.1.10 "Implicit Conversions" that can be applied | |||
1841 | * to one of the expressions to make their types match. This | |||
1842 | * resulting matching type is the type of the entire | |||
1843 | * expression." | |||
1844 | */ | |||
1845 | if ((!apply_implicit_conversion(op[1]->type, op[2], state) | |||
1846 | && !apply_implicit_conversion(op[2]->type, op[1], state)) | |||
1847 | || (op[1]->type != op[2]->type)) { | |||
1848 | YYLTYPE loc = this->subexpressions[1]->get_location(); | |||
1849 | ||||
1850 | _mesa_glsl_error(& loc, state, "second and third operands of ?: " | |||
1851 | "operator must have matching types"); | |||
1852 | error_emitted = true; | |||
1853 | type = glsl_type::error_type; | |||
1854 | } else { | |||
1855 | type = op[1]->type; | |||
1856 | } | |||
1857 | ||||
1858 | /* From page 33 (page 39 of the PDF) of the GLSL 1.10 spec: | |||
1859 | * | |||
1860 | * "The second and third expressions must be the same type, but can | |||
1861 | * be of any type other than an array." | |||
1862 | */ | |||
1863 | if (type->is_array() && | |||
1864 | !state->check_version(120, 300, &loc, | |||
1865 | "second and third operands of ?: operator " | |||
1866 | "cannot be arrays")) { | |||
1867 | error_emitted = true; | |||
1868 | } | |||
1869 | ||||
1870 | /* From section 4.1.7 of the GLSL 4.50 spec (Opaque Types): | |||
1871 | * | |||
1872 | * "Except for array indexing, structure member selection, and | |||
1873 | * parentheses, opaque variables are not allowed to be operands in | |||
1874 | * expressions; such use results in a compile-time error." | |||
1875 | */ | |||
1876 | if (type->contains_opaque()) { | |||
1877 | if (!(state->has_bindless() && (type->is_image() || type->is_sampler()))) { | |||
1878 | _mesa_glsl_error(&loc, state, "variables of type %s cannot be " | |||
1879 | "operands of the ?: operator", type->name); | |||
1880 | error_emitted = true; | |||
1881 | } | |||
1882 | } | |||
1883 | ||||
1884 | ir_constant *cond_val = op[0]->constant_expression_value(ctx); | |||
1885 | ||||
1886 | if (then_instructions.is_empty() | |||
1887 | && else_instructions.is_empty() | |||
1888 | && cond_val != NULL__null) { | |||
1889 | result = cond_val->value.b[0] ? op[1] : op[2]; | |||
1890 | } else { | |||
1891 | /* The copy to conditional_tmp reads the whole array. */ | |||
1892 | if (type->is_array()) { | |||
1893 | mark_whole_array_access(op[1]); | |||
1894 | mark_whole_array_access(op[2]); | |||
1895 | } | |||
1896 | ||||
1897 | ir_variable *const tmp = | |||
1898 | new(ctx) ir_variable(type, "conditional_tmp", ir_var_temporary); | |||
1899 | instructions->push_tail(tmp); | |||
1900 | ||||
1901 | ir_if *const stmt = new(ctx) ir_if(op[0]); | |||
1902 | instructions->push_tail(stmt); | |||
1903 | ||||
1904 | then_instructions.move_nodes_to(& stmt->then_instructions); | |||
1905 | ir_dereference *const then_deref = | |||
1906 | new(ctx) ir_dereference_variable(tmp); | |||
1907 | ir_assignment *const then_assign = | |||
1908 | new(ctx) ir_assignment(then_deref, op[1]); | |||
1909 | stmt->then_instructions.push_tail(then_assign); | |||
1910 | ||||
1911 | else_instructions.move_nodes_to(& stmt->else_instructions); | |||
1912 | ir_dereference *const else_deref = | |||
1913 | new(ctx) ir_dereference_variable(tmp); | |||
1914 | ir_assignment *const else_assign = | |||
1915 | new(ctx) ir_assignment(else_deref, op[2]); | |||
1916 | stmt->else_instructions.push_tail(else_assign); | |||
1917 | ||||
1918 | result = new(ctx) ir_dereference_variable(tmp); | |||
1919 | } | |||
1920 | break; | |||
1921 | } | |||
1922 | ||||
1923 | case ast_pre_inc: | |||
1924 | case ast_pre_dec: { | |||
1925 | this->non_lvalue_description = (this->oper == ast_pre_inc) | |||
1926 | ? "pre-increment operation" : "pre-decrement operation"; | |||
1927 | ||||
1928 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1929 | op[1] = constant_one_for_inc_dec(ctx, op[0]->type); | |||
1930 | ||||
1931 | type = arithmetic_result_type(op[0], op[1], false, state, & loc); | |||
1932 | ||||
1933 | ir_rvalue *temp_rhs; | |||
1934 | temp_rhs = new(ctx) ir_expression(operations[this->oper], type, | |||
1935 | op[0], op[1]); | |||
1936 | ||||
1937 | error_emitted = | |||
1938 | do_assignment(instructions, state, | |||
1939 | this->subexpressions[0]->non_lvalue_description, | |||
1940 | op[0]->clone(ctx, NULL__null), temp_rhs, | |||
1941 | &result, needs_rvalue, false, | |||
1942 | this->subexpressions[0]->get_location()); | |||
1943 | break; | |||
1944 | } | |||
1945 | ||||
1946 | case ast_post_inc: | |||
1947 | case ast_post_dec: { | |||
1948 | this->non_lvalue_description = (this->oper == ast_post_inc) | |||
1949 | ? "post-increment operation" : "post-decrement operation"; | |||
1950 | op[0] = this->subexpressions[0]->hir(instructions, state); | |||
1951 | op[1] = constant_one_for_inc_dec(ctx, op[0]->type); | |||
1952 | ||||
1953 | error_emitted = op[0]->type->is_error() || op[1]->type->is_error(); | |||
1954 | ||||
1955 | if (error_emitted) { | |||
1956 | result = ir_rvalue::error_value(ctx); | |||
1957 | break; | |||
1958 | } | |||
1959 | ||||
1960 | type = arithmetic_result_type(op[0], op[1], false, state, & loc); | |||
1961 | ||||
1962 | ir_rvalue *temp_rhs; | |||
1963 | temp_rhs = new(ctx) ir_expression(operations[this->oper], type, | |||
1964 | op[0], op[1]); | |||
1965 | ||||
1966 | /* Get a temporary of a copy of the lvalue before it's modified. | |||
1967 | * This may get thrown away later. | |||
1968 | */ | |||
1969 | result = get_lvalue_copy(instructions, op[0]->clone(ctx, NULL__null)); | |||
1970 | ||||
1971 | ir_rvalue *junk_rvalue; | |||
1972 | error_emitted = | |||
1973 | do_assignment(instructions, state, | |||
1974 | this->subexpressions[0]->non_lvalue_description, | |||
1975 | op[0]->clone(ctx, NULL__null), temp_rhs, | |||
1976 | &junk_rvalue, false, false, | |||
1977 | this->subexpressions[0]->get_location()); | |||
1978 | ||||
1979 | break; | |||
1980 | } | |||
1981 | ||||
1982 | case ast_field_selection: | |||
1983 | result = _mesa_ast_field_selection_to_hir(this, instructions, state); | |||
1984 | break; | |||
1985 | ||||
1986 | case ast_array_index: { | |||
1987 | YYLTYPE index_loc = subexpressions[1]->get_location(); | |||
1988 | ||||
1989 | /* Getting if an array is being used uninitialized is beyond what we get | |||
1990 | * from ir_value.data.assigned. Setting is_lhs as true would force to | |||
1991 | * not raise a uninitialized warning when using an array | |||
1992 | */ | |||
1993 | subexpressions[0]->set_is_lhs(true); | |||
1994 | op[0] = subexpressions[0]->hir(instructions, state); | |||
1995 | op[1] = subexpressions[1]->hir(instructions, state); | |||
1996 | ||||
1997 | result = _mesa_ast_array_index_to_hir(ctx, state, op[0], op[1], | |||
1998 | loc, index_loc); | |||
1999 | ||||
2000 | if (result->type->is_error()) | |||
2001 | error_emitted = true; | |||
2002 | ||||
2003 | break; | |||
2004 | } | |||
2005 | ||||
2006 | case ast_unsized_array_dim: | |||
2007 | unreachable("ast_unsized_array_dim: Should never get here.")do { (static_cast <bool> (!"ast_unsized_array_dim: Should never get here." ) ? void (0) : __assert_fail ("!\"ast_unsized_array_dim: Should never get here.\"" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); __builtin_unreachable(); } while (0); | |||
2008 | ||||
2009 | case ast_function_call: | |||
2010 | /* Should *NEVER* get here. ast_function_call should always be handled | |||
2011 | * by ast_function_expression::hir. | |||
2012 | */ | |||
2013 | unreachable("ast_function_call: handled elsewhere ")do { (static_cast <bool> (!"ast_function_call: handled elsewhere " ) ? void (0) : __assert_fail ("!\"ast_function_call: handled elsewhere \"" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); __builtin_unreachable(); } while (0); | |||
2014 | ||||
2015 | case ast_identifier: { | |||
2016 | /* ast_identifier can appear several places in a full abstract syntax | |||
2017 | * tree. This particular use must be at location specified in the grammar | |||
2018 | * as 'variable_identifier'. | |||
2019 | */ | |||
2020 | ir_variable *var = | |||
2021 | state->symbols->get_variable(this->primary_expression.identifier); | |||
2022 | ||||
2023 | if (var == NULL__null) { | |||
2024 | /* the identifier might be a subroutine name */ | |||
2025 | char *sub_name; | |||
2026 | sub_name = ralloc_asprintf(ctx, "%s_%s", _mesa_shader_stage_to_subroutine_prefix(state->stage), this->primary_expression.identifier); | |||
2027 | var = state->symbols->get_variable(sub_name); | |||
2028 | ralloc_free(sub_name); | |||
2029 | } | |||
2030 | ||||
2031 | if (var != NULL__null) { | |||
2032 | var->data.used = true; | |||
2033 | result = new(ctx) ir_dereference_variable(var); | |||
2034 | ||||
2035 | if ((var->data.mode == ir_var_auto || var->data.mode == ir_var_shader_out) | |||
2036 | && !this->is_lhs | |||
2037 | && result->variable_referenced()->data.assigned != true | |||
2038 | && !is_gl_identifier(var->name)) { | |||
2039 | _mesa_glsl_warning(&loc, state, "`%s' used uninitialized", | |||
2040 | this->primary_expression.identifier); | |||
2041 | } | |||
2042 | ||||
2043 | /* From the EXT_shader_framebuffer_fetch spec: | |||
2044 | * | |||
2045 | * "Unless the GL_EXT_shader_framebuffer_fetch extension has been | |||
2046 | * enabled in addition, it's an error to use gl_LastFragData if it | |||
2047 | * hasn't been explicitly redeclared with layout(noncoherent)." | |||
2048 | */ | |||
2049 | if (var->data.fb_fetch_output && var->data.memory_coherent && | |||
2050 | !state->EXT_shader_framebuffer_fetch_enable) { | |||
2051 | _mesa_glsl_error(&loc, state, | |||
2052 | "invalid use of framebuffer fetch output not " | |||
2053 | "qualified with layout(noncoherent)"); | |||
2054 | } | |||
2055 | ||||
2056 | } else { | |||
2057 | _mesa_glsl_error(& loc, state, "`%s' undeclared", | |||
2058 | this->primary_expression.identifier); | |||
2059 | ||||
2060 | result = ir_rvalue::error_value(ctx); | |||
2061 | error_emitted = true; | |||
2062 | } | |||
2063 | break; | |||
2064 | } | |||
2065 | ||||
2066 | case ast_int_constant: | |||
2067 | result = new(ctx) ir_constant(this->primary_expression.int_constant); | |||
2068 | break; | |||
2069 | ||||
2070 | case ast_uint_constant: | |||
2071 | result = new(ctx) ir_constant(this->primary_expression.uint_constant); | |||
2072 | break; | |||
2073 | ||||
2074 | case ast_float_constant: | |||
2075 | result = new(ctx) ir_constant(this->primary_expression.float_constant); | |||
2076 | break; | |||
2077 | ||||
2078 | case ast_bool_constant: | |||
2079 | result = new(ctx) ir_constant(bool(this->primary_expression.bool_constant)); | |||
2080 | break; | |||
2081 | ||||
2082 | case ast_double_constant: | |||
2083 | result = new(ctx) ir_constant(this->primary_expression.double_constant); | |||
2084 | break; | |||
2085 | ||||
2086 | case ast_uint64_constant: | |||
2087 | result = new(ctx) ir_constant(this->primary_expression.uint64_constant); | |||
2088 | break; | |||
2089 | ||||
2090 | case ast_int64_constant: | |||
2091 | result = new(ctx) ir_constant(this->primary_expression.int64_constant); | |||
2092 | break; | |||
2093 | ||||
2094 | case ast_sequence: { | |||
2095 | /* It should not be possible to generate a sequence in the AST without | |||
2096 | * any expressions in it. | |||
2097 | */ | |||
2098 | assert(!this->expressions.is_empty())(static_cast <bool> (!this->expressions.is_empty()) ? void (0) : __assert_fail ("!this->expressions.is_empty()" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); | |||
2099 | ||||
2100 | /* The r-value of a sequence is the last expression in the sequence. If | |||
2101 | * the other expressions in the sequence do not have side-effects (and | |||
2102 | * therefore add instructions to the instruction list), they get dropped | |||
2103 | * on the floor. | |||
2104 | */ | |||
2105 | exec_node *previous_tail = NULL__null; | |||
2106 | YYLTYPE previous_operand_loc = loc; | |||
2107 | ||||
2108 | foreach_list_typed (ast_node, ast, link, &this->expressions)for (ast_node * ast = (!exec_node_is_tail_sentinel((&this ->expressions)->head_sentinel.next) ? ((ast_node *) ((( uintptr_t) (&this->expressions)->head_sentinel.next ) - (((char *) &((ast_node *) (&this->expressions) ->head_sentinel.next)->link) - ((char *) (&this-> expressions)->head_sentinel.next)))) : __null); (ast) != __null ; (ast) = (!exec_node_is_tail_sentinel((ast)->link.next) ? ((ast_node *) (((uintptr_t) (ast)->link.next) - (((char * ) &((ast_node *) (ast)->link.next)->link) - ((char * ) (ast)->link.next)))) : __null)) { | |||
2109 | /* If one of the operands of comma operator does not generate any | |||
2110 | * code, we want to emit a warning. At each pass through the loop | |||
2111 | * previous_tail will point to the last instruction in the stream | |||
2112 | * *before* processing the previous operand. Naturally, | |||
2113 | * instructions->get_tail_raw() will point to the last instruction in | |||
2114 | * the stream *after* processing the previous operand. If the two | |||
2115 | * pointers match, then the previous operand had no effect. | |||
2116 | * | |||
2117 | * The warning behavior here differs slightly from GCC. GCC will | |||
2118 | * only emit a warning if none of the left-hand operands have an | |||
2119 | * effect. However, it will emit a warning for each. I believe that | |||
2120 | * there are some cases in C (especially with GCC extensions) where | |||
2121 | * it is useful to have an intermediate step in a sequence have no | |||
2122 | * effect, but I don't think these cases exist in GLSL. Either way, | |||
2123 | * it would be a giant hassle to replicate that behavior. | |||
2124 | */ | |||
2125 | if (previous_tail == instructions->get_tail_raw()) { | |||
2126 | _mesa_glsl_warning(&previous_operand_loc, state, | |||
2127 | "left-hand operand of comma expression has " | |||
2128 | "no effect"); | |||
2129 | } | |||
2130 | ||||
2131 | /* The tail is directly accessed instead of using the get_tail() | |||
2132 | * method for performance reasons. get_tail() has extra code to | |||
2133 | * return NULL when the list is empty. We don't care about that | |||
2134 | * here, so using get_tail_raw() is fine. | |||
2135 | */ | |||
2136 | previous_tail = instructions->get_tail_raw(); | |||
2137 | previous_operand_loc = ast->get_location(); | |||
2138 | ||||
2139 | result = ast->hir(instructions, state); | |||
2140 | } | |||
2141 | ||||
2142 | /* Any errors should have already been emitted in the loop above. | |||
2143 | */ | |||
2144 | error_emitted = true; | |||
2145 | break; | |||
2146 | } | |||
2147 | } | |||
2148 | type = NULL__null; /* use result->type, not type. */ | |||
2149 | assert(error_emitted || (result != NULL || !needs_rvalue))(static_cast <bool> (error_emitted || (result != __null || !needs_rvalue)) ? void (0) : __assert_fail ("error_emitted || (result != NULL || !needs_rvalue)" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); | |||
2150 | ||||
2151 | if (result && result->type->is_error() && !error_emitted) | |||
2152 | _mesa_glsl_error(& loc, state, "type mismatch"); | |||
2153 | ||||
2154 | return result; | |||
2155 | } | |||
2156 | ||||
2157 | bool | |||
2158 | ast_expression::has_sequence_subexpression() const | |||
2159 | { | |||
2160 | switch (this->oper) { | |||
2161 | case ast_plus: | |||
2162 | case ast_neg: | |||
2163 | case ast_bit_not: | |||
2164 | case ast_logic_not: | |||
2165 | case ast_pre_inc: | |||
2166 | case ast_pre_dec: | |||
2167 | case ast_post_inc: | |||
2168 | case ast_post_dec: | |||
2169 | return this->subexpressions[0]->has_sequence_subexpression(); | |||
2170 | ||||
2171 | case ast_assign: | |||
2172 | case ast_add: | |||
2173 | case ast_sub: | |||
2174 | case ast_mul: | |||
2175 | case ast_div: | |||
2176 | case ast_mod: | |||
2177 | case ast_lshift: | |||
2178 | case ast_rshift: | |||
2179 | case ast_less: | |||
2180 | case ast_greater: | |||
2181 | case ast_lequal: | |||
2182 | case ast_gequal: | |||
2183 | case ast_nequal: | |||
2184 | case ast_equal: | |||
2185 | case ast_bit_and: | |||
2186 | case ast_bit_xor: | |||
2187 | case ast_bit_or: | |||
2188 | case ast_logic_and: | |||
2189 | case ast_logic_or: | |||
2190 | case ast_logic_xor: | |||
2191 | case ast_array_index: | |||
2192 | case ast_mul_assign: | |||
2193 | case ast_div_assign: | |||
2194 | case ast_add_assign: | |||
2195 | case ast_sub_assign: | |||
2196 | case ast_mod_assign: | |||
2197 | case ast_ls_assign: | |||
2198 | case ast_rs_assign: | |||
2199 | case ast_and_assign: | |||
2200 | case ast_xor_assign: | |||
2201 | case ast_or_assign: | |||
2202 | return this->subexpressions[0]->has_sequence_subexpression() || | |||
2203 | this->subexpressions[1]->has_sequence_subexpression(); | |||
2204 | ||||
2205 | case ast_conditional: | |||
2206 | return this->subexpressions[0]->has_sequence_subexpression() || | |||
2207 | this->subexpressions[1]->has_sequence_subexpression() || | |||
2208 | this->subexpressions[2]->has_sequence_subexpression(); | |||
2209 | ||||
2210 | case ast_sequence: | |||
2211 | return true; | |||
2212 | ||||
2213 | case ast_field_selection: | |||
2214 | case ast_identifier: | |||
2215 | case ast_int_constant: | |||
2216 | case ast_uint_constant: | |||
2217 | case ast_float_constant: | |||
2218 | case ast_bool_constant: | |||
2219 | case ast_double_constant: | |||
2220 | case ast_int64_constant: | |||
2221 | case ast_uint64_constant: | |||
2222 | return false; | |||
2223 | ||||
2224 | case ast_aggregate: | |||
2225 | return false; | |||
2226 | ||||
2227 | case ast_function_call: | |||
2228 | unreachable("should be handled by ast_function_expression::hir")do { (static_cast <bool> (!"should be handled by ast_function_expression::hir" ) ? void (0) : __assert_fail ("!\"should be handled by ast_function_expression::hir\"" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); __builtin_unreachable(); } while (0); | |||
2229 | ||||
2230 | case ast_unsized_array_dim: | |||
2231 | unreachable("ast_unsized_array_dim: Should never get here.")do { (static_cast <bool> (!"ast_unsized_array_dim: Should never get here." ) ? void (0) : __assert_fail ("!\"ast_unsized_array_dim: Should never get here.\"" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); __builtin_unreachable(); } while (0); | |||
2232 | } | |||
2233 | ||||
2234 | return false; | |||
2235 | } | |||
2236 | ||||
2237 | ir_rvalue * | |||
2238 | ast_expression_statement::hir(exec_list *instructions, | |||
2239 | struct _mesa_glsl_parse_state *state) | |||
2240 | { | |||
2241 | /* It is possible to have expression statements that don't have an | |||
2242 | * expression. This is the solitary semicolon: | |||
2243 | * | |||
2244 | * for (i = 0; i < 5; i++) | |||
2245 | * ; | |||
2246 | * | |||
2247 | * In this case the expression will be NULL. Test for NULL and don't do | |||
2248 | * anything in that case. | |||
2249 | */ | |||
2250 | if (expression != NULL__null) | |||
2251 | expression->hir_no_rvalue(instructions, state); | |||
2252 | ||||
2253 | /* Statements do not have r-values. | |||
2254 | */ | |||
2255 | return NULL__null; | |||
2256 | } | |||
2257 | ||||
2258 | ||||
2259 | ir_rvalue * | |||
2260 | ast_compound_statement::hir(exec_list *instructions, | |||
2261 | struct _mesa_glsl_parse_state *state) | |||
2262 | { | |||
2263 | if (new_scope) | |||
2264 | state->symbols->push_scope(); | |||
2265 | ||||
2266 | foreach_list_typed (ast_node, ast, link, &this->statements)for (ast_node * ast = (!exec_node_is_tail_sentinel((&this ->statements)->head_sentinel.next) ? ((ast_node *) (((uintptr_t ) (&this->statements)->head_sentinel.next) - (((char *) &((ast_node *) (&this->statements)->head_sentinel .next)->link) - ((char *) (&this->statements)->head_sentinel .next)))) : __null); (ast) != __null; (ast) = (!exec_node_is_tail_sentinel ((ast)->link.next) ? ((ast_node *) (((uintptr_t) (ast)-> link.next) - (((char *) &((ast_node *) (ast)->link.next )->link) - ((char *) (ast)->link.next)))) : __null)) | |||
2267 | ast->hir(instructions, state); | |||
2268 | ||||
2269 | if (new_scope) | |||
2270 | state->symbols->pop_scope(); | |||
2271 | ||||
2272 | /* Compound statements do not have r-values. | |||
2273 | */ | |||
2274 | return NULL__null; | |||
2275 | } | |||
2276 | ||||
2277 | /** | |||
2278 | * Evaluate the given exec_node (which should be an ast_node representing | |||
2279 | * a single array dimension) and return its integer value. | |||
2280 | */ | |||
2281 | static unsigned | |||
2282 | process_array_size(exec_node *node, | |||
2283 | struct _mesa_glsl_parse_state *state) | |||
2284 | { | |||
2285 | void *mem_ctx = state; | |||
2286 | ||||
2287 | exec_list dummy_instructions; | |||
2288 | ||||
2289 | ast_node *array_size = exec_node_data(ast_node, node, link)((ast_node *) (((uintptr_t) node) - (((char *) &((ast_node *) node)->link) - ((char *) node)))); | |||
2290 | ||||
2291 | /** | |||
2292 | * Dimensions other than the outermost dimension can by unsized if they | |||
2293 | * are immediately sized by a constructor or initializer. | |||
2294 | */ | |||
2295 | if (((ast_expression*)array_size)->oper == ast_unsized_array_dim) | |||
2296 | return 0; | |||
2297 | ||||
2298 | ir_rvalue *const ir = array_size->hir(& dummy_instructions, state); | |||
2299 | YYLTYPE loc = array_size->get_location(); | |||
2300 | ||||
2301 | if (ir == NULL__null) { | |||
2302 | _mesa_glsl_error(& loc, state, | |||
2303 | "array size could not be resolved"); | |||
2304 | return 0; | |||
2305 | } | |||
2306 | ||||
2307 | if (!ir->type->is_integer_32()) { | |||
2308 | _mesa_glsl_error(& loc, state, | |||
2309 | "array size must be integer type"); | |||
2310 | return 0; | |||
2311 | } | |||
2312 | ||||
2313 | if (!ir->type->is_scalar()) { | |||
2314 | _mesa_glsl_error(& loc, state, | |||
2315 | "array size must be scalar type"); | |||
2316 | return 0; | |||
2317 | } | |||
2318 | ||||
2319 | ir_constant *const size = ir->constant_expression_value(mem_ctx); | |||
2320 | if (size == NULL__null || | |||
2321 | (state->is_version(120, 300) && | |||
2322 | array_size->has_sequence_subexpression())) { | |||
2323 | _mesa_glsl_error(& loc, state, "array size must be a " | |||
2324 | "constant valued expression"); | |||
2325 | return 0; | |||
2326 | } | |||
2327 | ||||
2328 | if (size->value.i[0] <= 0) { | |||
2329 | _mesa_glsl_error(& loc, state, "array size must be > 0"); | |||
2330 | return 0; | |||
2331 | } | |||
2332 | ||||
2333 | assert(size->type == ir->type)(static_cast <bool> (size->type == ir->type) ? void (0) : __assert_fail ("size->type == ir->type", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2334 | ||||
2335 | /* If the array size is const (and we've verified that | |||
2336 | * it is) then no instructions should have been emitted | |||
2337 | * when we converted it to HIR. If they were emitted, | |||
2338 | * then either the array size isn't const after all, or | |||
2339 | * we are emitting unnecessary instructions. | |||
2340 | */ | |||
2341 | assert(dummy_instructions.is_empty())(static_cast <bool> (dummy_instructions.is_empty()) ? void (0) : __assert_fail ("dummy_instructions.is_empty()", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2342 | ||||
2343 | return size->value.u[0]; | |||
2344 | } | |||
2345 | ||||
2346 | static const glsl_type * | |||
2347 | process_array_type(YYLTYPE *loc, const glsl_type *base, | |||
2348 | ast_array_specifier *array_specifier, | |||
2349 | struct _mesa_glsl_parse_state *state) | |||
2350 | { | |||
2351 | const glsl_type *array_type = base; | |||
2352 | ||||
2353 | if (array_specifier != NULL__null) { | |||
2354 | if (base->is_array()) { | |||
2355 | ||||
2356 | /* From page 19 (page 25) of the GLSL 1.20 spec: | |||
2357 | * | |||
2358 | * "Only one-dimensional arrays may be declared." | |||
2359 | */ | |||
2360 | if (!state->check_arrays_of_arrays_allowed(loc)) { | |||
2361 | return glsl_type::error_type; | |||
2362 | } | |||
2363 | } | |||
2364 | ||||
2365 | for (exec_node *node = array_specifier->array_dimensions.get_tail_raw(); | |||
2366 | !node->is_head_sentinel(); node = node->prev) { | |||
2367 | unsigned array_size = process_array_size(node, state); | |||
2368 | array_type = glsl_type::get_array_instance(array_type, array_size); | |||
2369 | } | |||
2370 | } | |||
2371 | ||||
2372 | return array_type; | |||
2373 | } | |||
2374 | ||||
2375 | static bool | |||
2376 | precision_qualifier_allowed(const glsl_type *type) | |||
2377 | { | |||
2378 | /* Precision qualifiers apply to floating point, integer and opaque | |||
2379 | * types. | |||
2380 | * | |||
2381 | * Section 4.5.2 (Precision Qualifiers) of the GLSL 1.30 spec says: | |||
2382 | * "Any floating point or any integer declaration can have the type | |||
2383 | * preceded by one of these precision qualifiers [...] Literal | |||
2384 | * constants do not have precision qualifiers. Neither do Boolean | |||
2385 | * variables. | |||
2386 | * | |||
2387 | * Section 4.5 (Precision and Precision Qualifiers) of the GLSL 1.30 | |||
2388 | * spec also says: | |||
2389 | * | |||
2390 | * "Precision qualifiers are added for code portability with OpenGL | |||
2391 | * ES, not for functionality. They have the same syntax as in OpenGL | |||
2392 | * ES." | |||
2393 | * | |||
2394 | * Section 8 (Built-In Functions) of the GLSL ES 1.00 spec says: | |||
2395 | * | |||
2396 | * "uniform lowp sampler2D sampler; | |||
2397 | * highp vec2 coord; | |||
2398 | * ... | |||
2399 | * lowp vec4 col = texture2D (sampler, coord); | |||
2400 | * // texture2D returns lowp" | |||
2401 | * | |||
2402 | * From this, we infer that GLSL 1.30 (and later) should allow precision | |||
2403 | * qualifiers on sampler types just like float and integer types. | |||
2404 | */ | |||
2405 | const glsl_type *const t = type->without_array(); | |||
2406 | ||||
2407 | return (t->is_float() || t->is_integer_32() || t->contains_opaque()) && | |||
2408 | !t->is_struct(); | |||
2409 | } | |||
2410 | ||||
2411 | const glsl_type * | |||
2412 | ast_type_specifier::glsl_type(const char **name, | |||
2413 | struct _mesa_glsl_parse_state *state) const | |||
2414 | { | |||
2415 | const struct glsl_type *type; | |||
2416 | ||||
2417 | if (this->type != NULL__null) | |||
2418 | type = this->type; | |||
2419 | else if (structure) | |||
2420 | type = structure->type; | |||
2421 | else | |||
2422 | type = state->symbols->get_type(this->type_name); | |||
2423 | *name = this->type_name; | |||
2424 | ||||
2425 | YYLTYPE loc = this->get_location(); | |||
2426 | type = process_array_type(&loc, type, this->array_specifier, state); | |||
2427 | ||||
2428 | return type; | |||
2429 | } | |||
2430 | ||||
2431 | /** | |||
2432 | * From the OpenGL ES 3.0 spec, 4.5.4 Default Precision Qualifiers: | |||
2433 | * | |||
2434 | * "The precision statement | |||
2435 | * | |||
2436 | * precision precision-qualifier type; | |||
2437 | * | |||
2438 | * can be used to establish a default precision qualifier. The type field can | |||
2439 | * be either int or float or any of the sampler types, (...) If type is float, | |||
2440 | * the directive applies to non-precision-qualified floating point type | |||
2441 | * (scalar, vector, and matrix) declarations. If type is int, the directive | |||
2442 | * applies to all non-precision-qualified integer type (scalar, vector, signed, | |||
2443 | * and unsigned) declarations." | |||
2444 | * | |||
2445 | * We use the symbol table to keep the values of the default precisions for | |||
2446 | * each 'type' in each scope and we use the 'type' string from the precision | |||
2447 | * statement as key in the symbol table. When we want to retrieve the default | |||
2448 | * precision associated with a given glsl_type we need to know the type string | |||
2449 | * associated with it. This is what this function returns. | |||
2450 | */ | |||
2451 | static const char * | |||
2452 | get_type_name_for_precision_qualifier(const glsl_type *type) | |||
2453 | { | |||
2454 | switch (type->base_type) { | |||
2455 | case GLSL_TYPE_FLOAT: | |||
2456 | return "float"; | |||
2457 | case GLSL_TYPE_UINT: | |||
2458 | case GLSL_TYPE_INT: | |||
2459 | return "int"; | |||
2460 | case GLSL_TYPE_ATOMIC_UINT: | |||
2461 | return "atomic_uint"; | |||
2462 | case GLSL_TYPE_IMAGE: | |||
2463 | /* fallthrough */ | |||
2464 | case GLSL_TYPE_SAMPLER: { | |||
2465 | const unsigned type_idx = | |||
2466 | type->sampler_array + 2 * type->sampler_shadow; | |||
2467 | const unsigned offset = type->is_sampler() ? 0 : 4; | |||
2468 | assert(type_idx < 4)(static_cast <bool> (type_idx < 4) ? void (0) : __assert_fail ("type_idx < 4", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2469 | switch (type->sampled_type) { | |||
2470 | case GLSL_TYPE_FLOAT: | |||
2471 | switch (type->sampler_dimensionality) { | |||
2472 | case GLSL_SAMPLER_DIM_1D: { | |||
2473 | assert(type->is_sampler())(static_cast <bool> (type->is_sampler()) ? void (0) : __assert_fail ("type->is_sampler()", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2474 | static const char *const names[4] = { | |||
2475 | "sampler1D", "sampler1DArray", | |||
2476 | "sampler1DShadow", "sampler1DArrayShadow" | |||
2477 | }; | |||
2478 | return names[type_idx]; | |||
2479 | } | |||
2480 | case GLSL_SAMPLER_DIM_2D: { | |||
2481 | static const char *const names[8] = { | |||
2482 | "sampler2D", "sampler2DArray", | |||
2483 | "sampler2DShadow", "sampler2DArrayShadow", | |||
2484 | "image2D", "image2DArray", NULL__null, NULL__null | |||
2485 | }; | |||
2486 | return names[offset + type_idx]; | |||
2487 | } | |||
2488 | case GLSL_SAMPLER_DIM_3D: { | |||
2489 | static const char *const names[8] = { | |||
2490 | "sampler3D", NULL__null, NULL__null, NULL__null, | |||
2491 | "image3D", NULL__null, NULL__null, NULL__null | |||
2492 | }; | |||
2493 | return names[offset + type_idx]; | |||
2494 | } | |||
2495 | case GLSL_SAMPLER_DIM_CUBE: { | |||
2496 | static const char *const names[8] = { | |||
2497 | "samplerCube", "samplerCubeArray", | |||
2498 | "samplerCubeShadow", "samplerCubeArrayShadow", | |||
2499 | "imageCube", NULL__null, NULL__null, NULL__null | |||
2500 | }; | |||
2501 | return names[offset + type_idx]; | |||
2502 | } | |||
2503 | case GLSL_SAMPLER_DIM_MS: { | |||
2504 | assert(type->is_sampler())(static_cast <bool> (type->is_sampler()) ? void (0) : __assert_fail ("type->is_sampler()", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2505 | static const char *const names[4] = { | |||
2506 | "sampler2DMS", "sampler2DMSArray", NULL__null, NULL__null | |||
2507 | }; | |||
2508 | return names[type_idx]; | |||
2509 | } | |||
2510 | case GLSL_SAMPLER_DIM_RECT: { | |||
2511 | assert(type->is_sampler())(static_cast <bool> (type->is_sampler()) ? void (0) : __assert_fail ("type->is_sampler()", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2512 | static const char *const names[4] = { | |||
2513 | "samplerRect", NULL__null, "samplerRectShadow", NULL__null | |||
2514 | }; | |||
2515 | return names[type_idx]; | |||
2516 | } | |||
2517 | case GLSL_SAMPLER_DIM_BUF: { | |||
2518 | static const char *const names[8] = { | |||
2519 | "samplerBuffer", NULL__null, NULL__null, NULL__null, | |||
2520 | "imageBuffer", NULL__null, NULL__null, NULL__null | |||
2521 | }; | |||
2522 | return names[offset + type_idx]; | |||
2523 | } | |||
2524 | case GLSL_SAMPLER_DIM_EXTERNAL: { | |||
2525 | assert(type->is_sampler())(static_cast <bool> (type->is_sampler()) ? void (0) : __assert_fail ("type->is_sampler()", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2526 | static const char *const names[4] = { | |||
2527 | "samplerExternalOES", NULL__null, NULL__null, NULL__null | |||
2528 | }; | |||
2529 | return names[type_idx]; | |||
2530 | } | |||
2531 | default: | |||
2532 | unreachable("Unsupported sampler/image dimensionality")do { (static_cast <bool> (!"Unsupported sampler/image dimensionality" ) ? void (0) : __assert_fail ("!\"Unsupported sampler/image dimensionality\"" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); __builtin_unreachable(); } while (0); | |||
2533 | } /* sampler/image float dimensionality */ | |||
2534 | break; | |||
2535 | case GLSL_TYPE_INT: | |||
2536 | switch (type->sampler_dimensionality) { | |||
2537 | case GLSL_SAMPLER_DIM_1D: { | |||
2538 | assert(type->is_sampler())(static_cast <bool> (type->is_sampler()) ? void (0) : __assert_fail ("type->is_sampler()", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2539 | static const char *const names[4] = { | |||
2540 | "isampler1D", "isampler1DArray", NULL__null, NULL__null | |||
2541 | }; | |||
2542 | return names[type_idx]; | |||
2543 | } | |||
2544 | case GLSL_SAMPLER_DIM_2D: { | |||
2545 | static const char *const names[8] = { | |||
2546 | "isampler2D", "isampler2DArray", NULL__null, NULL__null, | |||
2547 | "iimage2D", "iimage2DArray", NULL__null, NULL__null | |||
2548 | }; | |||
2549 | return names[offset + type_idx]; | |||
2550 | } | |||
2551 | case GLSL_SAMPLER_DIM_3D: { | |||
2552 | static const char *const names[8] = { | |||
2553 | "isampler3D", NULL__null, NULL__null, NULL__null, | |||
2554 | "iimage3D", NULL__null, NULL__null, NULL__null | |||
2555 | }; | |||
2556 | return names[offset + type_idx]; | |||
2557 | } | |||
2558 | case GLSL_SAMPLER_DIM_CUBE: { | |||
2559 | static const char *const names[8] = { | |||
2560 | "isamplerCube", "isamplerCubeArray", NULL__null, NULL__null, | |||
2561 | "iimageCube", NULL__null, NULL__null, NULL__null | |||
2562 | }; | |||
2563 | return names[offset + type_idx]; | |||
2564 | } | |||
2565 | case GLSL_SAMPLER_DIM_MS: { | |||
2566 | assert(type->is_sampler())(static_cast <bool> (type->is_sampler()) ? void (0) : __assert_fail ("type->is_sampler()", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2567 | static const char *const names[4] = { | |||
2568 | "isampler2DMS", "isampler2DMSArray", NULL__null, NULL__null | |||
2569 | }; | |||
2570 | return names[type_idx]; | |||
2571 | } | |||
2572 | case GLSL_SAMPLER_DIM_RECT: { | |||
2573 | assert(type->is_sampler())(static_cast <bool> (type->is_sampler()) ? void (0) : __assert_fail ("type->is_sampler()", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2574 | static const char *const names[4] = { | |||
2575 | "isamplerRect", NULL__null, "isamplerRectShadow", NULL__null | |||
2576 | }; | |||
2577 | return names[type_idx]; | |||
2578 | } | |||
2579 | case GLSL_SAMPLER_DIM_BUF: { | |||
2580 | static const char *const names[8] = { | |||
2581 | "isamplerBuffer", NULL__null, NULL__null, NULL__null, | |||
2582 | "iimageBuffer", NULL__null, NULL__null, NULL__null | |||
2583 | }; | |||
2584 | return names[offset + type_idx]; | |||
2585 | } | |||
2586 | default: | |||
2587 | unreachable("Unsupported isampler/iimage dimensionality")do { (static_cast <bool> (!"Unsupported isampler/iimage dimensionality" ) ? void (0) : __assert_fail ("!\"Unsupported isampler/iimage dimensionality\"" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); __builtin_unreachable(); } while (0); | |||
2588 | } /* sampler/image int dimensionality */ | |||
2589 | break; | |||
2590 | case GLSL_TYPE_UINT: | |||
2591 | switch (type->sampler_dimensionality) { | |||
2592 | case GLSL_SAMPLER_DIM_1D: { | |||
2593 | assert(type->is_sampler())(static_cast <bool> (type->is_sampler()) ? void (0) : __assert_fail ("type->is_sampler()", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2594 | static const char *const names[4] = { | |||
2595 | "usampler1D", "usampler1DArray", NULL__null, NULL__null | |||
2596 | }; | |||
2597 | return names[type_idx]; | |||
2598 | } | |||
2599 | case GLSL_SAMPLER_DIM_2D: { | |||
2600 | static const char *const names[8] = { | |||
2601 | "usampler2D", "usampler2DArray", NULL__null, NULL__null, | |||
2602 | "uimage2D", "uimage2DArray", NULL__null, NULL__null | |||
2603 | }; | |||
2604 | return names[offset + type_idx]; | |||
2605 | } | |||
2606 | case GLSL_SAMPLER_DIM_3D: { | |||
2607 | static const char *const names[8] = { | |||
2608 | "usampler3D", NULL__null, NULL__null, NULL__null, | |||
2609 | "uimage3D", NULL__null, NULL__null, NULL__null | |||
2610 | }; | |||
2611 | return names[offset + type_idx]; | |||
2612 | } | |||
2613 | case GLSL_SAMPLER_DIM_CUBE: { | |||
2614 | static const char *const names[8] = { | |||
2615 | "usamplerCube", "usamplerCubeArray", NULL__null, NULL__null, | |||
2616 | "uimageCube", NULL__null, NULL__null, NULL__null | |||
2617 | }; | |||
2618 | return names[offset + type_idx]; | |||
2619 | } | |||
2620 | case GLSL_SAMPLER_DIM_MS: { | |||
2621 | assert(type->is_sampler())(static_cast <bool> (type->is_sampler()) ? void (0) : __assert_fail ("type->is_sampler()", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2622 | static const char *const names[4] = { | |||
2623 | "usampler2DMS", "usampler2DMSArray", NULL__null, NULL__null | |||
2624 | }; | |||
2625 | return names[type_idx]; | |||
2626 | } | |||
2627 | case GLSL_SAMPLER_DIM_RECT: { | |||
2628 | assert(type->is_sampler())(static_cast <bool> (type->is_sampler()) ? void (0) : __assert_fail ("type->is_sampler()", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2629 | static const char *const names[4] = { | |||
2630 | "usamplerRect", NULL__null, "usamplerRectShadow", NULL__null | |||
2631 | }; | |||
2632 | return names[type_idx]; | |||
2633 | } | |||
2634 | case GLSL_SAMPLER_DIM_BUF: { | |||
2635 | static const char *const names[8] = { | |||
2636 | "usamplerBuffer", NULL__null, NULL__null, NULL__null, | |||
2637 | "uimageBuffer", NULL__null, NULL__null, NULL__null | |||
2638 | }; | |||
2639 | return names[offset + type_idx]; | |||
2640 | } | |||
2641 | default: | |||
2642 | unreachable("Unsupported usampler/uimage dimensionality")do { (static_cast <bool> (!"Unsupported usampler/uimage dimensionality" ) ? void (0) : __assert_fail ("!\"Unsupported usampler/uimage dimensionality\"" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); __builtin_unreachable(); } while (0); | |||
2643 | } /* sampler/image uint dimensionality */ | |||
2644 | break; | |||
2645 | default: | |||
2646 | unreachable("Unsupported sampler/image type")do { (static_cast <bool> (!"Unsupported sampler/image type" ) ? void (0) : __assert_fail ("!\"Unsupported sampler/image type\"" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); __builtin_unreachable(); } while (0); | |||
2647 | } /* sampler/image type */ | |||
2648 | break; | |||
2649 | } /* GLSL_TYPE_SAMPLER/GLSL_TYPE_IMAGE */ | |||
2650 | break; | |||
2651 | default: | |||
2652 | unreachable("Unsupported type")do { (static_cast <bool> (!"Unsupported type") ? void ( 0) : __assert_fail ("!\"Unsupported type\"", __builtin_FILE ( ), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); __builtin_unreachable (); } while (0); | |||
2653 | } /* base type */ | |||
2654 | } | |||
2655 | ||||
2656 | static unsigned | |||
2657 | select_gles_precision(unsigned qual_precision, | |||
2658 | const glsl_type *type, | |||
2659 | struct _mesa_glsl_parse_state *state, YYLTYPE *loc) | |||
2660 | { | |||
2661 | /* Precision qualifiers do not have any meaning in Desktop GLSL. | |||
2662 | * In GLES we take the precision from the type qualifier if present, | |||
2663 | * otherwise, if the type of the variable allows precision qualifiers at | |||
2664 | * all, we look for the default precision qualifier for that type in the | |||
2665 | * current scope. | |||
2666 | */ | |||
2667 | assert(state->es_shader)(static_cast <bool> (state->es_shader) ? void (0) : __assert_fail ("state->es_shader", __builtin_FILE (), __builtin_LINE () , __extension__ __PRETTY_FUNCTION__)); | |||
2668 | ||||
2669 | unsigned precision = GLSL_PRECISION_NONE; | |||
2670 | if (qual_precision) { | |||
2671 | precision = qual_precision; | |||
2672 | } else if (precision_qualifier_allowed(type)) { | |||
2673 | const char *type_name = | |||
2674 | get_type_name_for_precision_qualifier(type->without_array()); | |||
2675 | assert(type_name != NULL)(static_cast <bool> (type_name != __null) ? void (0) : __assert_fail ("type_name != NULL", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
2676 | ||||
2677 | precision = | |||
2678 | state->symbols->get_default_precision_qualifier(type_name); | |||
2679 | if (precision == ast_precision_none) { | |||
2680 | _mesa_glsl_error(loc, state, | |||
2681 | "No precision specified in this scope for type `%s'", | |||
2682 | type->name); | |||
2683 | } | |||
2684 | } | |||
2685 | ||||
2686 | ||||
2687 | /* Section 4.1.7.3 (Atomic Counters) of the GLSL ES 3.10 spec says: | |||
2688 | * | |||
2689 | * "The default precision of all atomic types is highp. It is an error to | |||
2690 | * declare an atomic type with a different precision or to specify the | |||
2691 | * default precision for an atomic type to be lowp or mediump." | |||
2692 | */ | |||
2693 | if (type->is_atomic_uint() && precision != ast_precision_high) { | |||
2694 | _mesa_glsl_error(loc, state, | |||
2695 | "atomic_uint can only have highp precision qualifier"); | |||
2696 | } | |||
2697 | ||||
2698 | return precision; | |||
2699 | } | |||
2700 | ||||
2701 | const glsl_type * | |||
2702 | ast_fully_specified_type::glsl_type(const char **name, | |||
2703 | struct _mesa_glsl_parse_state *state) const | |||
2704 | { | |||
2705 | return this->specifier->glsl_type(name, state); | |||
2706 | } | |||
2707 | ||||
2708 | /** | |||
2709 | * Determine whether a toplevel variable declaration declares a varying. This | |||
2710 | * function operates by examining the variable's mode and the shader target, | |||
2711 | * so it correctly identifies linkage variables regardless of whether they are | |||
2712 | * declared using the deprecated "varying" syntax or the new "in/out" syntax. | |||
2713 | * | |||
2714 | * Passing a non-toplevel variable declaration (e.g. a function parameter) to | |||
2715 | * this function will produce undefined results. | |||
2716 | */ | |||
2717 | static bool | |||
2718 | is_varying_var(ir_variable *var, gl_shader_stage target) | |||
2719 | { | |||
2720 | switch (target) { | |||
2721 | case MESA_SHADER_VERTEX: | |||
2722 | return var->data.mode == ir_var_shader_out; | |||
2723 | case MESA_SHADER_FRAGMENT: | |||
2724 | return var->data.mode == ir_var_shader_in || | |||
2725 | (var->data.mode == ir_var_system_value && | |||
2726 | var->data.location == SYSTEM_VALUE_FRAG_COORD); | |||
2727 | default: | |||
2728 | return var->data.mode == ir_var_shader_out || var->data.mode == ir_var_shader_in; | |||
2729 | } | |||
2730 | } | |||
2731 | ||||
2732 | static bool | |||
2733 | is_allowed_invariant(ir_variable *var, struct _mesa_glsl_parse_state *state) | |||
2734 | { | |||
2735 | if (is_varying_var(var, state->stage)) | |||
2736 | return true; | |||
2737 | ||||
2738 | /* From Section 4.6.1 ("The Invariant Qualifier") GLSL 1.20 spec: | |||
2739 | * "Only variables output from a vertex shader can be candidates | |||
2740 | * for invariance". | |||
2741 | */ | |||
2742 | if (!state->is_version(130, 100)) | |||
2743 | return false; | |||
2744 | ||||
2745 | /* | |||
2746 | * Later specs remove this language - so allowed invariant | |||
2747 | * on fragment shader outputs as well. | |||
2748 | */ | |||
2749 | if (state->stage == MESA_SHADER_FRAGMENT && | |||
2750 | var->data.mode == ir_var_shader_out) | |||
2751 | return true; | |||
2752 | return false; | |||
2753 | } | |||
2754 | ||||
2755 | /** | |||
2756 | * Matrix layout qualifiers are only allowed on certain types | |||
2757 | */ | |||
2758 | static void | |||
2759 | validate_matrix_layout_for_type(struct _mesa_glsl_parse_state *state, | |||
2760 | YYLTYPE *loc, | |||
2761 | const glsl_type *type, | |||
2762 | ir_variable *var) | |||
2763 | { | |||
2764 | if (var && !var->is_in_buffer_block()) { | |||
2765 | /* Layout qualifiers may only apply to interface blocks and fields in | |||
2766 | * them. | |||
2767 | */ | |||
2768 | _mesa_glsl_error(loc, state, | |||
2769 | "uniform block layout qualifiers row_major and " | |||
2770 | "column_major may not be applied to variables " | |||
2771 | "outside of uniform blocks"); | |||
2772 | } else if (!type->without_array()->is_matrix()) { | |||
2773 | /* The OpenGL ES 3.0 conformance tests did not originally allow | |||
2774 | * matrix layout qualifiers on non-matrices. However, the OpenGL | |||
2775 | * 4.4 and OpenGL ES 3.0 (revision TBD) specifications were | |||
2776 | * amended to specifically allow these layouts on all types. Emit | |||
2777 | * a warning so that people know their code may not be portable. | |||
2778 | */ | |||
2779 | _mesa_glsl_warning(loc, state, | |||
2780 | "uniform block layout qualifiers row_major and " | |||
2781 | "column_major applied to non-matrix types may " | |||
2782 | "be rejected by older compilers"); | |||
2783 | } | |||
2784 | } | |||
2785 | ||||
2786 | static bool | |||
2787 | validate_xfb_buffer_qualifier(YYLTYPE *loc, | |||
2788 | struct _mesa_glsl_parse_state *state, | |||
2789 | unsigned xfb_buffer) { | |||
2790 | if (xfb_buffer >= state->Const.MaxTransformFeedbackBuffers) { | |||
2791 | _mesa_glsl_error(loc, state, | |||
2792 | "invalid xfb_buffer specified %d is larger than " | |||
2793 | "MAX_TRANSFORM_FEEDBACK_BUFFERS - 1 (%d).", | |||
2794 | xfb_buffer, | |||
2795 | state->Const.MaxTransformFeedbackBuffers - 1); | |||
2796 | return false; | |||
2797 | } | |||
2798 | ||||
2799 | return true; | |||
2800 | } | |||
2801 | ||||
2802 | /* From the ARB_enhanced_layouts spec: | |||
2803 | * | |||
2804 | * "Variables and block members qualified with *xfb_offset* can be | |||
2805 | * scalars, vectors, matrices, structures, and (sized) arrays of these. | |||
2806 | * The offset must be a multiple of the size of the first component of | |||
2807 | * the first qualified variable or block member, or a compile-time error | |||
2808 | * results. Further, if applied to an aggregate containing a double, | |||
2809 | * the offset must also be a multiple of 8, and the space taken in the | |||
2810 | * buffer will be a multiple of 8. | |||
2811 | */ | |||
2812 | static bool | |||
2813 | validate_xfb_offset_qualifier(YYLTYPE *loc, | |||
2814 | struct _mesa_glsl_parse_state *state, | |||
2815 | int xfb_offset, const glsl_type *type, | |||
2816 | unsigned component_size) { | |||
2817 | const glsl_type *t_without_array = type->without_array(); | |||
2818 | ||||
2819 | if (xfb_offset != -1 && type->is_unsized_array()) { | |||
2820 | _mesa_glsl_error(loc, state, | |||
2821 | "xfb_offset can't be used with unsized arrays."); | |||
2822 | return false; | |||
2823 | } | |||
2824 | ||||
2825 | /* Make sure nested structs don't contain unsized arrays, and validate | |||
2826 | * any xfb_offsets on interface members. | |||
2827 | */ | |||
2828 | if (t_without_array->is_struct() || t_without_array->is_interface()) | |||
2829 | for (unsigned int i = 0; i < t_without_array->length; i++) { | |||
2830 | const glsl_type *member_t = t_without_array->fields.structure[i].type; | |||
2831 | ||||
2832 | /* When the interface block doesn't have an xfb_offset qualifier then | |||
2833 | * we apply the component size rules at the member level. | |||
2834 | */ | |||
2835 | if (xfb_offset == -1) | |||
2836 | component_size = member_t->contains_double() ? 8 : 4; | |||
2837 | ||||
2838 | int xfb_offset = t_without_array->fields.structure[i].offset; | |||
2839 | validate_xfb_offset_qualifier(loc, state, xfb_offset, member_t, | |||
2840 | component_size); | |||
2841 | } | |||
2842 | ||||
2843 | /* Nested structs or interface block without offset may not have had an | |||
2844 | * offset applied yet so return. | |||
2845 | */ | |||
2846 | if (xfb_offset == -1) { | |||
2847 | return true; | |||
2848 | } | |||
2849 | ||||
2850 | if (xfb_offset % component_size) { | |||
2851 | _mesa_glsl_error(loc, state, | |||
2852 | "invalid qualifier xfb_offset=%d must be a multiple " | |||
2853 | "of the first component size of the first qualified " | |||
2854 | "variable or block member. Or double if an aggregate " | |||
2855 | "that contains a double (%d).", | |||
2856 | xfb_offset, component_size); | |||
2857 | return false; | |||
2858 | } | |||
2859 | ||||
2860 | return true; | |||
2861 | } | |||
2862 | ||||
2863 | static bool | |||
2864 | validate_stream_qualifier(YYLTYPE *loc, struct _mesa_glsl_parse_state *state, | |||
2865 | unsigned stream) | |||
2866 | { | |||
2867 | if (stream >= state->ctx->Const.MaxVertexStreams) { | |||
2868 | _mesa_glsl_error(loc, state, | |||
2869 | "invalid stream specified %d is larger than " | |||
2870 | "MAX_VERTEX_STREAMS - 1 (%d).", | |||
2871 | stream, state->ctx->Const.MaxVertexStreams - 1); | |||
2872 | return false; | |||
2873 | } | |||
2874 | ||||
2875 | return true; | |||
2876 | } | |||
2877 | ||||
2878 | static void | |||
2879 | apply_explicit_binding(struct _mesa_glsl_parse_state *state, | |||
2880 | YYLTYPE *loc, | |||
2881 | ir_variable *var, | |||
2882 | const glsl_type *type, | |||
2883 | const ast_type_qualifier *qual) | |||
2884 | { | |||
2885 | if (!qual->flags.q.uniform && !qual->flags.q.buffer) { | |||
2886 | _mesa_glsl_error(loc, state, | |||
2887 | "the \"binding\" qualifier only applies to uniforms and " | |||
2888 | "shader storage buffer objects"); | |||
2889 | return; | |||
2890 | } | |||
2891 | ||||
2892 | unsigned qual_binding; | |||
2893 | if (!process_qualifier_constant(state, loc, "binding", qual->binding, | |||
2894 | &qual_binding)) { | |||
2895 | return; | |||
2896 | } | |||
2897 | ||||
2898 | const struct gl_context *const ctx = state->ctx; | |||
2899 | unsigned elements = type->is_array() ? type->arrays_of_arrays_size() : 1; | |||
2900 | unsigned max_index = qual_binding + elements - 1; | |||
2901 | const glsl_type *base_type = type->without_array(); | |||
2902 | ||||
2903 | if (base_type->is_interface()) { | |||
2904 | /* UBOs. From page 60 of the GLSL 4.20 specification: | |||
2905 | * "If the binding point for any uniform block instance is less than zero, | |||
2906 | * or greater than or equal to the implementation-dependent maximum | |||
2907 | * number of uniform buffer bindings, a compilation error will occur. | |||
2908 | * When the binding identifier is used with a uniform block instanced as | |||
2909 | * an array of size N, all elements of the array from binding through | |||
2910 | * binding + N – 1 must be within this range." | |||
2911 | * | |||
2912 | * The implementation-dependent maximum is GL_MAX_UNIFORM_BUFFER_BINDINGS. | |||
2913 | */ | |||
2914 | if (qual->flags.q.uniform && | |||
2915 | max_index >= ctx->Const.MaxUniformBufferBindings) { | |||
2916 | _mesa_glsl_error(loc, state, "layout(binding = %u) for %d UBOs exceeds " | |||
2917 | "the maximum number of UBO binding points (%d)", | |||
2918 | qual_binding, elements, | |||
2919 | ctx->Const.MaxUniformBufferBindings); | |||
2920 | return; | |||
2921 | } | |||
2922 | ||||
2923 | /* SSBOs. From page 67 of the GLSL 4.30 specification: | |||
2924 | * "If the binding point for any uniform or shader storage block instance | |||
2925 | * is less than zero, or greater than or equal to the | |||
2926 | * implementation-dependent maximum number of uniform buffer bindings, a | |||
2927 | * compile-time error will occur. When the binding identifier is used | |||
2928 | * with a uniform or shader storage block instanced as an array of size | |||
2929 | * N, all elements of the array from binding through binding + N – 1 must | |||
2930 | * be within this range." | |||
2931 | */ | |||
2932 | if (qual->flags.q.buffer && | |||
2933 | max_index >= ctx->Const.MaxShaderStorageBufferBindings) { | |||
2934 | _mesa_glsl_error(loc, state, "layout(binding = %u) for %d SSBOs exceeds " | |||
2935 | "the maximum number of SSBO binding points (%d)", | |||
2936 | qual_binding, elements, | |||
2937 | ctx->Const.MaxShaderStorageBufferBindings); | |||
2938 | return; | |||
2939 | } | |||
2940 | } else if (base_type->is_sampler()) { | |||
2941 | /* Samplers. From page 63 of the GLSL 4.20 specification: | |||
2942 | * "If the binding is less than zero, or greater than or equal to the | |||
2943 | * implementation-dependent maximum supported number of units, a | |||
2944 | * compilation error will occur. When the binding identifier is used | |||
2945 | * with an array of size N, all elements of the array from binding | |||
2946 | * through binding + N - 1 must be within this range." | |||
2947 | */ | |||
2948 | unsigned limit = ctx->Const.MaxCombinedTextureImageUnits; | |||
2949 | ||||
2950 | if (max_index >= limit) { | |||
2951 | _mesa_glsl_error(loc, state, "layout(binding = %d) for %d samplers " | |||
2952 | "exceeds the maximum number of texture image units " | |||
2953 | "(%u)", qual_binding, elements, limit); | |||
2954 | ||||
2955 | return; | |||
2956 | } | |||
2957 | } else if (base_type->contains_atomic()) { | |||
2958 | assert(ctx->Const.MaxAtomicBufferBindings <= MAX_COMBINED_ATOMIC_BUFFERS)(static_cast <bool> (ctx->Const.MaxAtomicBufferBindings <= (15 * 6)) ? void (0) : __assert_fail ("ctx->Const.MaxAtomicBufferBindings <= MAX_COMBINED_ATOMIC_BUFFERS" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); | |||
2959 | if (qual_binding >= ctx->Const.MaxAtomicBufferBindings) { | |||
2960 | _mesa_glsl_error(loc, state, "layout(binding = %d) exceeds the " | |||
2961 | "maximum number of atomic counter buffer bindings " | |||
2962 | "(%u)", qual_binding, | |||
2963 | ctx->Const.MaxAtomicBufferBindings); | |||
2964 | ||||
2965 | return; | |||
2966 | } | |||
2967 | } else if ((state->is_version(420, 310) || | |||
2968 | state->ARB_shading_language_420pack_enable) && | |||
2969 | base_type->is_image()) { | |||
2970 | assert(ctx->Const.MaxImageUnits <= MAX_IMAGE_UNITS)(static_cast <bool> (ctx->Const.MaxImageUnits <= ( 32 * 6)) ? void (0) : __assert_fail ("ctx->Const.MaxImageUnits <= MAX_IMAGE_UNITS" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); | |||
2971 | if (max_index >= ctx->Const.MaxImageUnits) { | |||
2972 | _mesa_glsl_error(loc, state, "Image binding %d exceeds the " | |||
2973 | "maximum number of image units (%d)", max_index, | |||
2974 | ctx->Const.MaxImageUnits); | |||
2975 | return; | |||
2976 | } | |||
2977 | ||||
2978 | } else { | |||
2979 | _mesa_glsl_error(loc, state, | |||
2980 | "the \"binding\" qualifier only applies to uniform " | |||
2981 | "blocks, storage blocks, opaque variables, or arrays " | |||
2982 | "thereof"); | |||
2983 | return; | |||
2984 | } | |||
2985 | ||||
2986 | var->data.explicit_binding = true; | |||
2987 | var->data.binding = qual_binding; | |||
2988 | ||||
2989 | return; | |||
2990 | } | |||
2991 | ||||
2992 | static void | |||
2993 | validate_fragment_flat_interpolation_input(struct _mesa_glsl_parse_state *state, | |||
2994 | YYLTYPE *loc, | |||
2995 | const glsl_interp_mode interpolation, | |||
2996 | const struct glsl_type *var_type, | |||
2997 | ir_variable_mode mode) | |||
2998 | { | |||
2999 | if (state->stage != MESA_SHADER_FRAGMENT || | |||
3000 | interpolation == INTERP_MODE_FLAT || | |||
3001 | mode != ir_var_shader_in) | |||
3002 | return; | |||
3003 | ||||
3004 | /* Integer fragment inputs must be qualified with 'flat'. In GLSL ES, | |||
3005 | * so must integer vertex outputs. | |||
3006 | * | |||
3007 | * From section 4.3.4 ("Inputs") of the GLSL 1.50 spec: | |||
3008 | * "Fragment shader inputs that are signed or unsigned integers or | |||
3009 | * integer vectors must be qualified with the interpolation qualifier | |||
3010 | * flat." | |||
3011 | * | |||
3012 | * From section 4.3.4 ("Input Variables") of the GLSL 3.00 ES spec: | |||
3013 | * "Fragment shader inputs that are, or contain, signed or unsigned | |||
3014 | * integers or integer vectors must be qualified with the | |||
3015 | * interpolation qualifier flat." | |||
3016 | * | |||
3017 | * From section 4.3.6 ("Output Variables") of the GLSL 3.00 ES spec: | |||
3018 | * "Vertex shader outputs that are, or contain, signed or unsigned | |||
3019 | * integers or integer vectors must be qualified with the | |||
3020 | * interpolation qualifier flat." | |||
3021 | * | |||
3022 | * Note that prior to GLSL 1.50, this requirement applied to vertex | |||
3023 | * outputs rather than fragment inputs. That creates problems in the | |||
3024 | * presence of geometry shaders, so we adopt the GLSL 1.50 rule for all | |||
3025 | * desktop GL shaders. For GLSL ES shaders, we follow the spec and | |||
3026 | * apply the restriction to both vertex outputs and fragment inputs. | |||
3027 | * | |||
3028 | * Note also that the desktop GLSL specs are missing the text "or | |||
3029 | * contain"; this is presumably an oversight, since there is no | |||
3030 | * reasonable way to interpolate a fragment shader input that contains | |||
3031 | * an integer. See Khronos bug #15671. | |||
3032 | */ | |||
3033 | if ((state->is_version(130, 300) || state->EXT_gpu_shader4_enable) | |||
3034 | && var_type->contains_integer()) { | |||
3035 | _mesa_glsl_error(loc, state, "if a fragment input is (or contains) " | |||
3036 | "an integer, then it must be qualified with 'flat'"); | |||
3037 | } | |||
3038 | ||||
3039 | /* Double fragment inputs must be qualified with 'flat'. | |||
3040 | * | |||
3041 | * From the "Overview" of the ARB_gpu_shader_fp64 extension spec: | |||
3042 | * "This extension does not support interpolation of double-precision | |||
3043 | * values; doubles used as fragment shader inputs must be qualified as | |||
3044 | * "flat"." | |||
3045 | * | |||
3046 | * From section 4.3.4 ("Inputs") of the GLSL 4.00 spec: | |||
3047 | * "Fragment shader inputs that are signed or unsigned integers, integer | |||
3048 | * vectors, or any double-precision floating-point type must be | |||
3049 | * qualified with the interpolation qualifier flat." | |||
3050 | * | |||
3051 | * Note that the GLSL specs are missing the text "or contain"; this is | |||
3052 | * presumably an oversight. See Khronos bug #15671. | |||
3053 | * | |||
3054 | * The 'double' type does not exist in GLSL ES so far. | |||
3055 | */ | |||
3056 | if (state->has_double() | |||
3057 | && var_type->contains_double()) { | |||
3058 | _mesa_glsl_error(loc, state, "if a fragment input is (or contains) " | |||
3059 | "a double, then it must be qualified with 'flat'"); | |||
3060 | } | |||
3061 | ||||
3062 | /* Bindless sampler/image fragment inputs must be qualified with 'flat'. | |||
3063 | * | |||
3064 | * From section 4.3.4 of the ARB_bindless_texture spec: | |||
3065 | * | |||
3066 | * "(modify last paragraph, p. 35, allowing samplers and images as | |||
3067 | * fragment shader inputs) ... Fragment inputs can only be signed and | |||
3068 | * unsigned integers and integer vectors, floating point scalars, | |||
3069 | * floating-point vectors, matrices, sampler and image types, or arrays | |||
3070 | * or structures of these. Fragment shader inputs that are signed or | |||
3071 | * unsigned integers, integer vectors, or any double-precision floating- | |||
3072 | * point type, or any sampler or image type must be qualified with the | |||
3073 | * interpolation qualifier "flat"." | |||
3074 | */ | |||
3075 | if (state->has_bindless() | |||
3076 | && (var_type->contains_sampler() || var_type->contains_image())) { | |||
3077 | _mesa_glsl_error(loc, state, "if a fragment input is (or contains) " | |||
3078 | "a bindless sampler (or image), then it must be " | |||
3079 | "qualified with 'flat'"); | |||
3080 | } | |||
3081 | } | |||
3082 | ||||
3083 | static void | |||
3084 | validate_interpolation_qualifier(struct _mesa_glsl_parse_state *state, | |||
3085 | YYLTYPE *loc, | |||
3086 | const glsl_interp_mode interpolation, | |||
3087 | const struct ast_type_qualifier *qual, | |||
3088 | const struct glsl_type *var_type, | |||
3089 | ir_variable_mode mode) | |||
3090 | { | |||
3091 | /* Interpolation qualifiers can only apply to shader inputs or outputs, but | |||
3092 | * not to vertex shader inputs nor fragment shader outputs. | |||
3093 | * | |||
3094 | * From section 4.3 ("Storage Qualifiers") of the GLSL 1.30 spec: | |||
3095 | * "Outputs from a vertex shader (out) and inputs to a fragment | |||
3096 | * shader (in) can be further qualified with one or more of these | |||
3097 | * interpolation qualifiers" | |||
3098 | * ... | |||
3099 | * "These interpolation qualifiers may only precede the qualifiers in, | |||
3100 | * centroid in, out, or centroid out in a declaration. They do not apply | |||
3101 | * to the deprecated storage qualifiers varying or centroid | |||
3102 | * varying. They also do not apply to inputs into a vertex shader or | |||
3103 | * outputs from a fragment shader." | |||
3104 | * | |||
3105 | * From section 4.3 ("Storage Qualifiers") of the GLSL ES 3.00 spec: | |||
3106 | * "Outputs from a shader (out) and inputs to a shader (in) can be | |||
3107 | * further qualified with one of these interpolation qualifiers." | |||
3108 | * ... | |||
3109 | * "These interpolation qualifiers may only precede the qualifiers | |||
3110 | * in, centroid in, out, or centroid out in a declaration. They do | |||
3111 | * not apply to inputs into a vertex shader or outputs from a | |||
3112 | * fragment shader." | |||
3113 | */ | |||
3114 | if ((state->is_version(130, 300) || state->EXT_gpu_shader4_enable) | |||
3115 | && interpolation != INTERP_MODE_NONE) { | |||
3116 | const char *i = interpolation_string(interpolation); | |||
3117 | if (mode != ir_var_shader_in && mode != ir_var_shader_out) | |||
3118 | _mesa_glsl_error(loc, state, | |||
3119 | "interpolation qualifier `%s' can only be applied to " | |||
3120 | "shader inputs or outputs.", i); | |||
3121 | ||||
3122 | switch (state->stage) { | |||
3123 | case MESA_SHADER_VERTEX: | |||
3124 | if (mode == ir_var_shader_in) { | |||
3125 | _mesa_glsl_error(loc, state, | |||
3126 | "interpolation qualifier '%s' cannot be applied to " | |||
3127 | "vertex shader inputs", i); | |||
3128 | } | |||
3129 | break; | |||
3130 | case MESA_SHADER_FRAGMENT: | |||
3131 | if (mode == ir_var_shader_out) { | |||
3132 | _mesa_glsl_error(loc, state, | |||
3133 | "interpolation qualifier '%s' cannot be applied to " | |||
3134 | "fragment shader outputs", i); | |||
3135 | } | |||
3136 | break; | |||
3137 | default: | |||
3138 | break; | |||
3139 | } | |||
3140 | } | |||
3141 | ||||
3142 | /* Interpolation qualifiers cannot be applied to 'centroid' and | |||
3143 | * 'centroid varying'. | |||
3144 | * | |||
3145 | * From section 4.3 ("Storage Qualifiers") of the GLSL 1.30 spec: | |||
3146 | * "interpolation qualifiers may only precede the qualifiers in, | |||
3147 | * centroid in, out, or centroid out in a declaration. They do not apply | |||
3148 | * to the deprecated storage qualifiers varying or centroid varying." | |||
3149 | * | |||
3150 | * These deprecated storage qualifiers do not exist in GLSL ES 3.00. | |||
3151 | * | |||
3152 | * GL_EXT_gpu_shader4 allows this. | |||
3153 | */ | |||
3154 | if (state->is_version(130, 0) && !state->EXT_gpu_shader4_enable | |||
3155 | && interpolation != INTERP_MODE_NONE | |||
3156 | && qual->flags.q.varying) { | |||
3157 | ||||
3158 | const char *i = interpolation_string(interpolation); | |||
3159 | const char *s; | |||
3160 | if (qual->flags.q.centroid) | |||
3161 | s = "centroid varying"; | |||
3162 | else | |||
3163 | s = "varying"; | |||
3164 | ||||
3165 | _mesa_glsl_error(loc, state, | |||
3166 | "qualifier '%s' cannot be applied to the " | |||
3167 | "deprecated storage qualifier '%s'", i, s); | |||
3168 | } | |||
3169 | ||||
3170 | validate_fragment_flat_interpolation_input(state, loc, interpolation, | |||
3171 | var_type, mode); | |||
3172 | } | |||
3173 | ||||
3174 | static glsl_interp_mode | |||
3175 | interpret_interpolation_qualifier(const struct ast_type_qualifier *qual, | |||
3176 | const struct glsl_type *var_type, | |||
3177 | ir_variable_mode mode, | |||
3178 | struct _mesa_glsl_parse_state *state, | |||
3179 | YYLTYPE *loc) | |||
3180 | { | |||
3181 | glsl_interp_mode interpolation; | |||
3182 | if (qual->flags.q.flat) | |||
3183 | interpolation = INTERP_MODE_FLAT; | |||
3184 | else if (qual->flags.q.noperspective) | |||
3185 | interpolation = INTERP_MODE_NOPERSPECTIVE; | |||
3186 | else if (qual->flags.q.smooth) | |||
3187 | interpolation = INTERP_MODE_SMOOTH; | |||
3188 | else | |||
3189 | interpolation = INTERP_MODE_NONE; | |||
3190 | ||||
3191 | validate_interpolation_qualifier(state, loc, | |||
3192 | interpolation, | |||
3193 | qual, var_type, mode); | |||
3194 | ||||
3195 | return interpolation; | |||
3196 | } | |||
3197 | ||||
3198 | ||||
3199 | static void | |||
3200 | apply_explicit_location(const struct ast_type_qualifier *qual, | |||
3201 | ir_variable *var, | |||
3202 | struct _mesa_glsl_parse_state *state, | |||
3203 | YYLTYPE *loc) | |||
3204 | { | |||
3205 | bool fail = false; | |||
3206 | ||||
3207 | unsigned qual_location; | |||
3208 | if (!process_qualifier_constant(state, loc, "location", qual->location, | |||
3209 | &qual_location)) { | |||
3210 | return; | |||
3211 | } | |||
3212 | ||||
3213 | /* Checks for GL_ARB_explicit_uniform_location. */ | |||
3214 | if (qual->flags.q.uniform) { | |||
3215 | if (!state->check_explicit_uniform_location_allowed(loc, var)) | |||
3216 | return; | |||
3217 | ||||
3218 | const struct gl_context *const ctx = state->ctx; | |||
3219 | unsigned max_loc = qual_location + var->type->uniform_locations() - 1; | |||
3220 | ||||
3221 | if (max_loc >= ctx->Const.MaxUserAssignableUniformLocations) { | |||
3222 | _mesa_glsl_error(loc, state, "location(s) consumed by uniform %s " | |||
3223 | ">= MAX_UNIFORM_LOCATIONS (%u)", var->name, | |||
3224 | ctx->Const.MaxUserAssignableUniformLocations); | |||
3225 | return; | |||
3226 | } | |||
3227 | ||||
3228 | var->data.explicit_location = true; | |||
3229 | var->data.location = qual_location; | |||
3230 | return; | |||
3231 | } | |||
3232 | ||||
3233 | /* Between GL_ARB_explicit_attrib_location an | |||
3234 | * GL_ARB_separate_shader_objects, the inputs and outputs of any shader | |||
3235 | * stage can be assigned explicit locations. The checking here associates | |||
3236 | * the correct extension with the correct stage's input / output: | |||
3237 | * | |||
3238 | * input output | |||
3239 | * ----- ------ | |||
3240 | * vertex explicit_loc sso | |||
3241 | * tess control sso sso | |||
3242 | * tess eval sso sso | |||
3243 | * geometry sso sso | |||
3244 | * fragment sso explicit_loc | |||
3245 | */ | |||
3246 | switch (state->stage) { | |||
3247 | case MESA_SHADER_VERTEX: | |||
3248 | if (var->data.mode == ir_var_shader_in) { | |||
3249 | if (!state->check_explicit_attrib_location_allowed(loc, var)) | |||
3250 | return; | |||
3251 | ||||
3252 | break; | |||
3253 | } | |||
3254 | ||||
3255 | if (var->data.mode == ir_var_shader_out) { | |||
3256 | if (!state->check_separate_shader_objects_allowed(loc, var)) | |||
3257 | return; | |||
3258 | ||||
3259 | break; | |||
3260 | } | |||
3261 | ||||
3262 | fail = true; | |||
3263 | break; | |||
3264 | ||||
3265 | case MESA_SHADER_TESS_CTRL: | |||
3266 | case MESA_SHADER_TESS_EVAL: | |||
3267 | case MESA_SHADER_GEOMETRY: | |||
3268 | if (var->data.mode == ir_var_shader_in || var->data.mode == ir_var_shader_out) { | |||
3269 | if (!state->check_separate_shader_objects_allowed(loc, var)) | |||
3270 | return; | |||
3271 | ||||
3272 | break; | |||
3273 | } | |||
3274 | ||||
3275 | fail = true; | |||
3276 | break; | |||
3277 | ||||
3278 | case MESA_SHADER_FRAGMENT: | |||
3279 | if (var->data.mode == ir_var_shader_in) { | |||
3280 | if (!state->check_separate_shader_objects_allowed(loc, var)) | |||
3281 | return; | |||
3282 | ||||
3283 | break; | |||
3284 | } | |||
3285 | ||||
3286 | if (var->data.mode == ir_var_shader_out) { | |||
3287 | if (!state->check_explicit_attrib_location_allowed(loc, var)) | |||
3288 | return; | |||
3289 | ||||
3290 | break; | |||
3291 | } | |||
3292 | ||||
3293 | fail = true; | |||
3294 | break; | |||
3295 | ||||
3296 | case MESA_SHADER_COMPUTE: | |||
3297 | _mesa_glsl_error(loc, state, | |||
3298 | "compute shader variables cannot be given " | |||
3299 | "explicit locations"); | |||
3300 | return; | |||
3301 | default: | |||
3302 | fail = true; | |||
3303 | break; | |||
3304 | }; | |||
3305 | ||||
3306 | if (fail) { | |||
3307 | _mesa_glsl_error(loc, state, | |||
3308 | "%s cannot be given an explicit location in %s shader", | |||
3309 | mode_string(var), | |||
3310 | _mesa_shader_stage_to_string(state->stage)); | |||
3311 | } else { | |||
3312 | var->data.explicit_location = true; | |||
3313 | ||||
3314 | switch (state->stage) { | |||
3315 | case MESA_SHADER_VERTEX: | |||
3316 | var->data.location = (var->data.mode == ir_var_shader_in) | |||
3317 | ? (qual_location + VERT_ATTRIB_GENERIC0) | |||
3318 | : (qual_location + VARYING_SLOT_VAR0); | |||
3319 | break; | |||
3320 | ||||
3321 | case MESA_SHADER_TESS_CTRL: | |||
3322 | case MESA_SHADER_TESS_EVAL: | |||
3323 | case MESA_SHADER_GEOMETRY: | |||
3324 | if (var->data.patch) | |||
3325 | var->data.location = qual_location + VARYING_SLOT_PATCH0((VARYING_SLOT_VAR0 + 32)); | |||
3326 | else | |||
3327 | var->data.location = qual_location + VARYING_SLOT_VAR0; | |||
3328 | break; | |||
3329 | ||||
3330 | case MESA_SHADER_FRAGMENT: | |||
3331 | var->data.location = (var->data.mode == ir_var_shader_out) | |||
3332 | ? (qual_location + FRAG_RESULT_DATA0) | |||
3333 | : (qual_location + VARYING_SLOT_VAR0); | |||
3334 | break; | |||
3335 | default: | |||
3336 | assert(!"Unexpected shader type")(static_cast <bool> (!"Unexpected shader type") ? void ( 0) : __assert_fail ("!\"Unexpected shader type\"", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); | |||
3337 | break; | |||
3338 | } | |||
3339 | ||||
3340 | /* Check if index was set for the uniform instead of the function */ | |||
3341 | if (qual->flags.q.explicit_index && qual->is_subroutine_decl()) { | |||
3342 | _mesa_glsl_error(loc, state, "an index qualifier can only be " | |||
3343 | "used with subroutine functions"); | |||
3344 | return; | |||
3345 | } | |||
3346 | ||||
3347 | unsigned qual_index; | |||
3348 | if (qual->flags.q.explicit_index && | |||
3349 | process_qualifier_constant(state, loc, "index", qual->index, | |||
3350 | &qual_index)) { | |||
3351 | /* From the GLSL 4.30 specification, section 4.4.2 (Output | |||
3352 | * Layout Qualifiers): | |||
3353 | * | |||
3354 | * "It is also a compile-time error if a fragment shader | |||
3355 | * sets a layout index to less than 0 or greater than 1." | |||
3356 | * | |||
3357 | * Older specifications don't mandate a behavior; we take | |||
3358 | * this as a clarification and always generate the error. | |||
3359 | */ | |||
3360 | if (qual_index > 1) { | |||
3361 | _mesa_glsl_error(loc, state, | |||
3362 | "explicit index may only be 0 or 1"); | |||
3363 | } else { | |||
3364 | var->data.explicit_index = true; | |||
3365 | var->data.index = qual_index; | |||
3366 | } | |||
3367 | } | |||
3368 | } | |||
3369 | } | |||
3370 | ||||
3371 | static bool | |||
3372 | validate_storage_for_sampler_image_types(ir_variable *var, | |||
3373 | struct _mesa_glsl_parse_state *state, | |||
3374 | YYLTYPE *loc) | |||
3375 | { | |||
3376 | /* From section 4.1.7 of the GLSL 4.40 spec: | |||
3377 | * | |||
3378 | * "[Opaque types] can only be declared as function | |||
3379 | * parameters or uniform-qualified variables." | |||
3380 | * | |||
3381 | * From section 4.1.7 of the ARB_bindless_texture spec: | |||
3382 | * | |||
3383 | * "Samplers may be declared as shader inputs and outputs, as uniform | |||
3384 | * variables, as temporary variables, and as function parameters." | |||
3385 | * | |||
3386 | * From section 4.1.X of the ARB_bindless_texture spec: | |||
3387 | * | |||
3388 | * "Images may be declared as shader inputs and outputs, as uniform | |||
3389 | * variables, as temporary variables, and as function parameters." | |||
3390 | */ | |||
3391 | if (state->has_bindless()) { | |||
3392 | if (var->data.mode != ir_var_auto && | |||
3393 | var->data.mode != ir_var_uniform && | |||
3394 | var->data.mode != ir_var_shader_in && | |||
3395 | var->data.mode != ir_var_shader_out && | |||
3396 | var->data.mode != ir_var_function_in && | |||
3397 | var->data.mode != ir_var_function_out && | |||
3398 | var->data.mode != ir_var_function_inout) { | |||
3399 | _mesa_glsl_error(loc, state, "bindless image/sampler variables may " | |||
3400 | "only be declared as shader inputs and outputs, as " | |||
3401 | "uniform variables, as temporary variables and as " | |||
3402 | "function parameters"); | |||
3403 | return false; | |||
3404 | } | |||
3405 | } else { | |||
3406 | if (var->data.mode != ir_var_uniform && | |||
3407 | var->data.mode != ir_var_function_in) { | |||
3408 | _mesa_glsl_error(loc, state, "image/sampler variables may only be " | |||
3409 | "declared as function parameters or " | |||
3410 | "uniform-qualified global variables"); | |||
3411 | return false; | |||
3412 | } | |||
3413 | } | |||
3414 | return true; | |||
3415 | } | |||
3416 | ||||
3417 | static bool | |||
3418 | validate_memory_qualifier_for_type(struct _mesa_glsl_parse_state *state, | |||
3419 | YYLTYPE *loc, | |||
3420 | const struct ast_type_qualifier *qual, | |||
3421 | const glsl_type *type) | |||
3422 | { | |||
3423 | /* From Section 4.10 (Memory Qualifiers) of the GLSL 4.50 spec: | |||
3424 | * | |||
3425 | * "Memory qualifiers are only supported in the declarations of image | |||
3426 | * variables, buffer variables, and shader storage blocks; it is an error | |||
3427 | * to use such qualifiers in any other declarations. | |||
3428 | */ | |||
3429 | if (!type->is_image() && !qual->flags.q.buffer) { | |||
3430 | if (qual->flags.q.read_only || | |||
3431 | qual->flags.q.write_only || | |||
3432 | qual->flags.q.coherent || | |||
3433 | qual->flags.q._volatile || | |||
3434 | qual->flags.q.restrict_flag) { | |||
3435 | _mesa_glsl_error(loc, state, "memory qualifiers may only be applied " | |||
3436 | "in the declarations of image variables, buffer " | |||
3437 | "variables, and shader storage blocks"); | |||
3438 | return false; | |||
3439 | } | |||
3440 | } | |||
3441 | return true; | |||
3442 | } | |||
3443 | ||||
3444 | static bool | |||
3445 | validate_image_format_qualifier_for_type(struct _mesa_glsl_parse_state *state, | |||
3446 | YYLTYPE *loc, | |||
3447 | const struct ast_type_qualifier *qual, | |||
3448 | const glsl_type *type) | |||
3449 | { | |||
3450 | /* From section 4.4.6.2 (Format Layout Qualifiers) of the GLSL 4.50 spec: | |||
3451 | * | |||
3452 | * "Format layout qualifiers can be used on image variable declarations | |||
3453 | * (those declared with a basic type having “image ” in its keyword)." | |||
3454 | */ | |||
3455 | if (!type->is_image() && qual->flags.q.explicit_image_format) { | |||
3456 | _mesa_glsl_error(loc, state, "format layout qualifiers may only be " | |||
3457 | "applied to images"); | |||
3458 | return false; | |||
3459 | } | |||
3460 | return true; | |||
3461 | } | |||
3462 | ||||
3463 | static void | |||
3464 | apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual, | |||
3465 | ir_variable *var, | |||
3466 | struct _mesa_glsl_parse_state *state, | |||
3467 | YYLTYPE *loc) | |||
3468 | { | |||
3469 | const glsl_type *base_type = var->type->without_array(); | |||
3470 | ||||
3471 | if (!validate_image_format_qualifier_for_type(state, loc, qual, base_type) || | |||
3472 | !validate_memory_qualifier_for_type(state, loc, qual, base_type)) | |||
3473 | return; | |||
3474 | ||||
3475 | if (!base_type->is_image()) | |||
3476 | return; | |||
3477 | ||||
3478 | if (!validate_storage_for_sampler_image_types(var, state, loc)) | |||
3479 | return; | |||
3480 | ||||
3481 | var->data.memory_read_only |= qual->flags.q.read_only; | |||
3482 | var->data.memory_write_only |= qual->flags.q.write_only; | |||
3483 | var->data.memory_coherent |= qual->flags.q.coherent; | |||
3484 | var->data.memory_volatile |= qual->flags.q._volatile; | |||
3485 | var->data.memory_restrict |= qual->flags.q.restrict_flag; | |||
3486 | ||||
3487 | if (qual->flags.q.explicit_image_format) { | |||
3488 | if (var->data.mode == ir_var_function_in) { | |||
3489 | _mesa_glsl_error(loc, state, "format qualifiers cannot be used on " | |||
3490 | "image function parameters"); | |||
3491 | } | |||
3492 | ||||
3493 | if (qual->image_base_type != base_type->sampled_type) { | |||
3494 | _mesa_glsl_error(loc, state, "format qualifier doesn't match the base " | |||
3495 | "data type of the image"); | |||
3496 | } | |||
3497 | ||||
3498 | var->data.image_format = qual->image_format; | |||
3499 | } else if (state->has_image_load_formatted()) { | |||
3500 | if (var->data.mode == ir_var_uniform && | |||
3501 | state->EXT_shader_image_load_formatted_warn) { | |||
3502 | _mesa_glsl_warning(loc, state, "GL_EXT_image_load_formatted used"); | |||
3503 | } | |||
3504 | } else { | |||
3505 | if (var->data.mode == ir_var_uniform) { | |||
3506 | if (state->es_shader || | |||
3507 | !(state->is_version(420, 310) || state->ARB_shader_image_load_store_enable)) { | |||
3508 | _mesa_glsl_error(loc, state, "all image uniforms must have a " | |||
3509 | "format layout qualifier"); | |||
3510 | } else if (!qual->flags.q.write_only) { | |||
3511 | _mesa_glsl_error(loc, state, "image uniforms not qualified with " | |||
3512 | "`writeonly' must have a format layout qualifier"); | |||
3513 | } | |||
3514 | } | |||
3515 | var->data.image_format = PIPE_FORMAT_NONE; | |||
3516 | } | |||
3517 | ||||
3518 | /* From page 70 of the GLSL ES 3.1 specification: | |||
3519 | * | |||
3520 | * "Except for image variables qualified with the format qualifiers r32f, | |||
3521 | * r32i, and r32ui, image variables must specify either memory qualifier | |||
3522 | * readonly or the memory qualifier writeonly." | |||
3523 | */ | |||
3524 | if (state->es_shader && | |||
3525 | var->data.image_format != PIPE_FORMAT_R32_FLOAT && | |||
3526 | var->data.image_format != PIPE_FORMAT_R32_SINT && | |||
3527 | var->data.image_format != PIPE_FORMAT_R32_UINT && | |||
3528 | !var->data.memory_read_only && | |||
3529 | !var->data.memory_write_only) { | |||
3530 | _mesa_glsl_error(loc, state, "image variables of format other than r32f, " | |||
3531 | "r32i or r32ui must be qualified `readonly' or " | |||
3532 | "`writeonly'"); | |||
3533 | } | |||
3534 | } | |||
3535 | ||||
3536 | static inline const char* | |||
3537 | get_layout_qualifier_string(bool origin_upper_left, bool pixel_center_integer) | |||
3538 | { | |||
3539 | if (origin_upper_left && pixel_center_integer) | |||
3540 | return "origin_upper_left, pixel_center_integer"; | |||
3541 | else if (origin_upper_left) | |||
3542 | return "origin_upper_left"; | |||
3543 | else if (pixel_center_integer) | |||
3544 | return "pixel_center_integer"; | |||
3545 | else | |||
3546 | return " "; | |||
3547 | } | |||
3548 | ||||
3549 | static inline bool | |||
3550 | is_conflicting_fragcoord_redeclaration(struct _mesa_glsl_parse_state *state, | |||
3551 | const struct ast_type_qualifier *qual) | |||
3552 | { | |||
3553 | /* If gl_FragCoord was previously declared, and the qualifiers were | |||
3554 | * different in any way, return true. | |||
3555 | */ | |||
3556 | if (state->fs_redeclares_gl_fragcoord) { | |||
3557 | return (state->fs_pixel_center_integer != qual->flags.q.pixel_center_integer | |||
3558 | || state->fs_origin_upper_left != qual->flags.q.origin_upper_left); | |||
3559 | } | |||
3560 | ||||
3561 | return false; | |||
3562 | } | |||
3563 | ||||
3564 | static inline bool | |||
3565 | is_conflicting_layer_redeclaration(struct _mesa_glsl_parse_state *state, | |||
3566 | const struct ast_type_qualifier *qual) | |||
3567 | { | |||
3568 | if (state->redeclares_gl_layer) { | |||
3569 | return state->layer_viewport_relative != qual->flags.q.viewport_relative; | |||
3570 | } | |||
3571 | return false; | |||
3572 | } | |||
3573 | ||||
3574 | static inline void | |||
3575 | validate_array_dimensions(const glsl_type *t, | |||
3576 | struct _mesa_glsl_parse_state *state, | |||
3577 | YYLTYPE *loc) { | |||
3578 | if (t->is_array()) { | |||
3579 | t = t->fields.array; | |||
3580 | while (t->is_array()) { | |||
3581 | if (t->is_unsized_array()) { | |||
3582 | _mesa_glsl_error(loc, state, | |||
3583 | "only the outermost array dimension can " | |||
3584 | "be unsized", | |||
3585 | t->name); | |||
3586 | break; | |||
3587 | } | |||
3588 | t = t->fields.array; | |||
3589 | } | |||
3590 | } | |||
3591 | } | |||
3592 | ||||
3593 | static void | |||
3594 | apply_bindless_qualifier_to_variable(const struct ast_type_qualifier *qual, | |||
3595 | ir_variable *var, | |||
3596 | struct _mesa_glsl_parse_state *state, | |||
3597 | YYLTYPE *loc) | |||
3598 | { | |||
3599 | bool has_local_qualifiers = qual->flags.q.bindless_sampler || | |||
3600 | qual->flags.q.bindless_image || | |||
3601 | qual->flags.q.bound_sampler || | |||
3602 | qual->flags.q.bound_image; | |||
3603 | ||||
3604 | /* The ARB_bindless_texture spec says: | |||
3605 | * | |||
3606 | * "Modify Section 4.4.6 Opaque-Uniform Layout Qualifiers of the GLSL 4.30 | |||
3607 | * spec" | |||
3608 | * | |||
3609 | * "If these layout qualifiers are applied to other types of default block | |||
3610 | * uniforms, or variables with non-uniform storage, a compile-time error | |||
3611 | * will be generated." | |||
3612 | */ | |||
3613 | if (has_local_qualifiers && !qual->flags.q.uniform) { | |||
3614 | _mesa_glsl_error(loc, state, "ARB_bindless_texture layout qualifiers " | |||
3615 | "can only be applied to default block uniforms or " | |||
3616 | "variables with uniform storage"); | |||
3617 | return; | |||
3618 | } | |||
3619 | ||||
3620 | /* The ARB_bindless_texture spec doesn't state anything in this situation, | |||
3621 | * but it makes sense to only allow bindless_sampler/bound_sampler for | |||
3622 | * sampler types, and respectively bindless_image/bound_image for image | |||
3623 | * types. | |||
3624 | */ | |||
3625 | if ((qual->flags.q.bindless_sampler || qual->flags.q.bound_sampler) && | |||
3626 | !var->type->contains_sampler()) { | |||
3627 | _mesa_glsl_error(loc, state, "bindless_sampler or bound_sampler can only " | |||
3628 | "be applied to sampler types"); | |||
3629 | return; | |||
3630 | } | |||
3631 | ||||
3632 | if ((qual->flags.q.bindless_image || qual->flags.q.bound_image) && | |||
3633 | !var->type->contains_image()) { | |||
3634 | _mesa_glsl_error(loc, state, "bindless_image or bound_image can only be " | |||
3635 | "applied to image types"); | |||
3636 | return; | |||
3637 | } | |||
3638 | ||||
3639 | /* The bindless_sampler/bindless_image (and respectively | |||
3640 | * bound_sampler/bound_image) layout qualifiers can be set at global and at | |||
3641 | * local scope. | |||
3642 | */ | |||
3643 | if (var->type->contains_sampler() || var->type->contains_image()) { | |||
3644 | var->data.bindless = qual->flags.q.bindless_sampler || | |||
3645 | qual->flags.q.bindless_image || | |||
3646 | state->bindless_sampler_specified || | |||
3647 | state->bindless_image_specified; | |||
3648 | ||||
3649 | var->data.bound = qual->flags.q.bound_sampler || | |||
3650 | qual->flags.q.bound_image || | |||
3651 | state->bound_sampler_specified || | |||
3652 | state->bound_image_specified; | |||
3653 | } | |||
3654 | } | |||
3655 | ||||
3656 | static void | |||
3657 | apply_layout_qualifier_to_variable(const struct ast_type_qualifier *qual, | |||
3658 | ir_variable *var, | |||
3659 | struct _mesa_glsl_parse_state *state, | |||
3660 | YYLTYPE *loc) | |||
3661 | { | |||
3662 | if (var->name != NULL__null && strcmp(var->name, "gl_FragCoord") == 0) { | |||
| ||||
3663 | ||||
3664 | /* Section 4.3.8.1, page 39 of GLSL 1.50 spec says: | |||
3665 | * | |||
3666 | * "Within any shader, the first redeclarations of gl_FragCoord | |||
3667 | * must appear before any use of gl_FragCoord." | |||
3668 | * | |||
3669 | * Generate a compiler error if above condition is not met by the | |||
3670 | * fragment shader. | |||
3671 | */ | |||
3672 | ir_variable *earlier = state->symbols->get_variable("gl_FragCoord"); | |||
3673 | if (earlier != NULL__null && | |||
3674 | earlier->data.used && | |||
3675 | !state->fs_redeclares_gl_fragcoord) { | |||
3676 | _mesa_glsl_error(loc, state, | |||
3677 | "gl_FragCoord used before its first redeclaration " | |||
3678 | "in fragment shader"); | |||
3679 | } | |||
3680 | ||||
3681 | /* Make sure all gl_FragCoord redeclarations specify the same layout | |||
3682 | * qualifiers. | |||
3683 | */ | |||
3684 | if (is_conflicting_fragcoord_redeclaration(state, qual)) { | |||
3685 | const char *const qual_string = | |||
3686 | get_layout_qualifier_string(qual->flags.q.origin_upper_left, | |||
3687 | qual->flags.q.pixel_center_integer); | |||
3688 | ||||
3689 | const char *const state_string = | |||
3690 | get_layout_qualifier_string(state->fs_origin_upper_left, | |||
3691 | state->fs_pixel_center_integer); | |||
3692 | ||||
3693 | _mesa_glsl_error(loc, state, | |||
3694 | "gl_FragCoord redeclared with different layout " | |||
3695 | "qualifiers (%s) and (%s) ", | |||
3696 | state_string, | |||
3697 | qual_string); | |||
3698 | } | |||
3699 | state->fs_origin_upper_left = qual->flags.q.origin_upper_left; | |||
3700 | state->fs_pixel_center_integer = qual->flags.q.pixel_center_integer; | |||
3701 | state->fs_redeclares_gl_fragcoord_with_no_layout_qualifiers = | |||
3702 | !qual->flags.q.origin_upper_left && !qual->flags.q.pixel_center_integer; | |||
3703 | state->fs_redeclares_gl_fragcoord = | |||
3704 | state->fs_origin_upper_left || | |||
3705 | state->fs_pixel_center_integer || | |||
3706 | state->fs_redeclares_gl_fragcoord_with_no_layout_qualifiers; | |||
3707 | } | |||
3708 | ||||
3709 | if ((qual->flags.q.origin_upper_left || qual->flags.q.pixel_center_integer) | |||
3710 | && (strcmp(var->name, "gl_FragCoord") != 0)) { | |||
3711 | const char *const qual_string = (qual->flags.q.origin_upper_left) | |||
3712 | ? "origin_upper_left" : "pixel_center_integer"; | |||
3713 | ||||
3714 | _mesa_glsl_error(loc, state, | |||
3715 | "layout qualifier `%s' can only be applied to " | |||
3716 | "fragment shader input `gl_FragCoord'", | |||
3717 | qual_string); | |||
3718 | } | |||
3719 | ||||
3720 | if (qual->flags.q.explicit_location) { | |||
3721 | apply_explicit_location(qual, var, state, loc); | |||
3722 | ||||
3723 | if (qual->flags.q.explicit_component) { | |||
3724 | unsigned qual_component; | |||
3725 | if (process_qualifier_constant(state, loc, "component", | |||
3726 | qual->component, &qual_component)) { | |||
3727 | const glsl_type *type = var->type->without_array(); | |||
3728 | unsigned components = type->component_slots(); | |||
3729 | ||||
3730 | if (type->is_matrix() || type->is_struct()) { | |||
3731 | _mesa_glsl_error(loc, state, "component layout qualifier " | |||
3732 | "cannot be applied to a matrix, a structure, " | |||
3733 | "a block, or an array containing any of " | |||
3734 | "these."); | |||
3735 | } else if (components > 4 && type->is_64bit()) { | |||
3736 | _mesa_glsl_error(loc, state, "component layout qualifier " | |||
3737 | "cannot be applied to dvec%u.", | |||
3738 | components / 2); | |||
3739 | } else if (qual_component != 0 && | |||
3740 | (qual_component + components - 1) > 3) { | |||
3741 | _mesa_glsl_error(loc, state, "component overflow (%u > 3)", | |||
3742 | (qual_component + components - 1)); | |||
3743 | } else if (qual_component == 1 && type->is_64bit()) { | |||
3744 | /* We don't bother checking for 3 as it should be caught by the | |||
3745 | * overflow check above. | |||
3746 | */ | |||
3747 | _mesa_glsl_error(loc, state, "doubles cannot begin at " | |||
3748 | "component 1 or 3"); | |||
3749 | } else { | |||
3750 | var->data.explicit_component = true; | |||
3751 | var->data.location_frac = qual_component; | |||
3752 | } | |||
3753 | } | |||
3754 | } | |||
3755 | } else if (qual->flags.q.explicit_index) { | |||
3756 | if (!qual->subroutine_list) | |||
3757 | _mesa_glsl_error(loc, state, | |||
3758 | "explicit index requires explicit location"); | |||
3759 | } else if (qual->flags.q.explicit_component) { | |||
3760 | _mesa_glsl_error(loc, state, | |||
3761 | "explicit component requires explicit location"); | |||
3762 | } | |||
3763 | ||||
3764 | if (qual->flags.q.explicit_binding) { | |||
3765 | apply_explicit_binding(state, loc, var, var->type, qual); | |||
3766 | } | |||
3767 | ||||
3768 | if (state->stage == MESA_SHADER_GEOMETRY && | |||
3769 | qual->flags.q.out && qual->flags.q.stream) { | |||
3770 | unsigned qual_stream; | |||
3771 | if (process_qualifier_constant(state, loc, "stream", qual->stream, | |||
3772 | &qual_stream) && | |||
3773 | validate_stream_qualifier(loc, state, qual_stream)) { | |||
3774 | var->data.stream = qual_stream; | |||
3775 | } | |||
3776 | } | |||
3777 | ||||
3778 | if (qual->flags.q.out && qual->flags.q.xfb_buffer) { | |||
3779 | unsigned qual_xfb_buffer; | |||
3780 | if (process_qualifier_constant(state, loc, "xfb_buffer", | |||
3781 | qual->xfb_buffer, &qual_xfb_buffer) && | |||
3782 | validate_xfb_buffer_qualifier(loc, state, qual_xfb_buffer)) { | |||
3783 | var->data.xfb_buffer = qual_xfb_buffer; | |||
3784 | if (qual->flags.q.explicit_xfb_buffer) | |||
3785 | var->data.explicit_xfb_buffer = true; | |||
3786 | } | |||
3787 | } | |||
3788 | ||||
3789 | if (qual->flags.q.explicit_xfb_offset) { | |||
3790 | unsigned qual_xfb_offset; | |||
3791 | unsigned component_size = var->type->contains_double() ? 8 : 4; | |||
3792 | ||||
3793 | if (process_qualifier_constant(state, loc, "xfb_offset", | |||
3794 | qual->offset, &qual_xfb_offset) && | |||
3795 | validate_xfb_offset_qualifier(loc, state, (int) qual_xfb_offset, | |||
3796 | var->type, component_size)) { | |||
3797 | var->data.offset = qual_xfb_offset; | |||
3798 | var->data.explicit_xfb_offset = true; | |||
3799 | } | |||
3800 | } | |||
3801 | ||||
3802 | if (qual->flags.q.explicit_xfb_stride) { | |||
3803 | unsigned qual_xfb_stride; | |||
3804 | if (process_qualifier_constant(state, loc, "xfb_stride", | |||
3805 | qual->xfb_stride, &qual_xfb_stride)) { | |||
3806 | var->data.xfb_stride = qual_xfb_stride; | |||
3807 | var->data.explicit_xfb_stride = true; | |||
3808 | } | |||
3809 | } | |||
3810 | ||||
3811 | if (var->type->contains_atomic()) { | |||
3812 | if (var->data.mode == ir_var_uniform) { | |||
3813 | if (var->data.explicit_binding) { | |||
3814 | unsigned *offset = | |||
3815 | &state->atomic_counter_offsets[var->data.binding]; | |||
3816 | ||||
3817 | if (*offset % ATOMIC_COUNTER_SIZE4) | |||
3818 | _mesa_glsl_error(loc, state, | |||
3819 | "misaligned atomic counter offset"); | |||
3820 | ||||
3821 | var->data.offset = *offset; | |||
3822 | *offset += var->type->atomic_size(); | |||
3823 | ||||
3824 | } else { | |||
3825 | _mesa_glsl_error(loc, state, | |||
3826 | "atomic counters require explicit binding point"); | |||
3827 | } | |||
3828 | } else if (var->data.mode != ir_var_function_in) { | |||
3829 | _mesa_glsl_error(loc, state, "atomic counters may only be declared as " | |||
3830 | "function parameters or uniform-qualified " | |||
3831 | "global variables"); | |||
3832 | } | |||
3833 | } | |||
3834 | ||||
3835 | if (var->type->contains_sampler() && | |||
3836 | !validate_storage_for_sampler_image_types(var, state, loc)) | |||
3837 | return; | |||
3838 | ||||
3839 | /* Is the 'layout' keyword used with parameters that allow relaxed checking. | |||
3840 | * Many implementations of GL_ARB_fragment_coord_conventions_enable and some | |||
3841 | * implementations (only Mesa?) GL_ARB_explicit_attrib_location_enable | |||
3842 | * allowed the layout qualifier to be used with 'varying' and 'attribute'. | |||
3843 | * These extensions and all following extensions that add the 'layout' | |||
3844 | * keyword have been modified to require the use of 'in' or 'out'. | |||
3845 | * | |||
3846 | * The following extension do not allow the deprecated keywords: | |||
3847 | * | |||
3848 | * GL_AMD_conservative_depth | |||
3849 | * GL_ARB_conservative_depth | |||
3850 | * GL_ARB_gpu_shader5 | |||
3851 | * GL_ARB_separate_shader_objects | |||
3852 | * GL_ARB_tessellation_shader | |||
3853 | * GL_ARB_transform_feedback3 | |||
3854 | * GL_ARB_uniform_buffer_object | |||
3855 | * | |||
3856 | * It is unknown whether GL_EXT_shader_image_load_store or GL_NV_gpu_shader5 | |||
3857 | * allow layout with the deprecated keywords. | |||
3858 | */ | |||
3859 | const bool relaxed_layout_qualifier_checking = | |||
3860 | state->ARB_fragment_coord_conventions_enable; | |||
3861 | ||||
3862 | const bool uses_deprecated_qualifier = qual->flags.q.attribute | |||
3863 | || qual->flags.q.varying; | |||
3864 | if (qual->has_layout() && uses_deprecated_qualifier) { | |||
3865 | if (relaxed_layout_qualifier_checking) { | |||
3866 | _mesa_glsl_warning(loc, state, | |||
3867 | "`layout' qualifier may not be used with " | |||
3868 | "`attribute' or `varying'"); | |||
3869 | } else { | |||
3870 | _mesa_glsl_error(loc, state, | |||
3871 | "`layout' qualifier may not be used with " | |||
3872 | "`attribute' or `varying'"); | |||
3873 | } | |||
3874 | } | |||
3875 | ||||
3876 | /* Layout qualifiers for gl_FragDepth, which are enabled by extension | |||
3877 | * AMD_conservative_depth. | |||
3878 | */ | |||
3879 | if (qual->flags.q.depth_type | |||
3880 | && !state->is_version(420, 0) | |||
3881 | && !state->AMD_conservative_depth_enable | |||
3882 | && !state->ARB_conservative_depth_enable) { | |||
3883 | _mesa_glsl_error(loc, state, | |||
3884 | "extension GL_AMD_conservative_depth or " | |||
3885 | "GL_ARB_conservative_depth must be enabled " | |||
3886 | "to use depth layout qualifiers"); | |||
3887 | } else if (qual->flags.q.depth_type |
20.1 | Field 'depth_type' is not equal to 0 |
21 | Null pointer passed to 1st parameter expecting 'nonnull' |