glsl: remove remaining tabs from ast_type.cpp
[mesa.git] / src / compiler / glsl / ast_type.cpp
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 #include "ast.h"
25
26 void
27 ast_type_specifier::print(void) const
28 {
29 if (structure) {
30 structure->print();
31 } else {
32 printf("%s ", type_name);
33 }
34
35 if (array_specifier) {
36 array_specifier->print();
37 }
38 }
39
40 bool
41 ast_fully_specified_type::has_qualifiers(_mesa_glsl_parse_state *state) const
42 {
43 /* 'subroutine' isnt a real qualifier. */
44 ast_type_qualifier subroutine_only;
45 subroutine_only.flags.i = 0;
46 subroutine_only.flags.q.subroutine = 1;
47 subroutine_only.flags.q.subroutine_def = 1;
48 if (state->has_explicit_uniform_location()) {
49 subroutine_only.flags.q.explicit_index = 1;
50 }
51 return (this->qualifier.flags.i & ~subroutine_only.flags.i) != 0;
52 }
53
54 bool ast_type_qualifier::has_interpolation() const
55 {
56 return this->flags.q.smooth
57 || this->flags.q.flat
58 || this->flags.q.noperspective;
59 }
60
61 bool
62 ast_type_qualifier::has_layout() const
63 {
64 return this->flags.q.origin_upper_left
65 || this->flags.q.pixel_center_integer
66 || this->flags.q.depth_any
67 || this->flags.q.depth_greater
68 || this->flags.q.depth_less
69 || this->flags.q.depth_unchanged
70 || this->flags.q.std140
71 || this->flags.q.std430
72 || this->flags.q.shared
73 || this->flags.q.column_major
74 || this->flags.q.row_major
75 || this->flags.q.packed
76 || this->flags.q.explicit_align
77 || this->flags.q.explicit_component
78 || this->flags.q.explicit_location
79 || this->flags.q.explicit_image_format
80 || this->flags.q.explicit_index
81 || this->flags.q.explicit_binding
82 || this->flags.q.explicit_offset
83 || this->flags.q.explicit_stream
84 || this->flags.q.explicit_xfb_buffer
85 || this->flags.q.explicit_xfb_offset
86 || this->flags.q.explicit_xfb_stride;
87 }
88
89 bool
90 ast_type_qualifier::has_storage() const
91 {
92 return this->flags.q.constant
93 || this->flags.q.attribute
94 || this->flags.q.varying
95 || this->flags.q.in
96 || this->flags.q.out
97 || this->flags.q.uniform
98 || this->flags.q.buffer
99 || this->flags.q.shared_storage;
100 }
101
102 bool
103 ast_type_qualifier::has_auxiliary_storage() const
104 {
105 return this->flags.q.centroid
106 || this->flags.q.sample
107 || this->flags.q.patch;
108 }
109
110 /**
111 * This function merges both duplicate identifies within a single layout and
112 * multiple layout qualifiers on a single variable declaration. The
113 * is_single_layout_merge param is used differentiate between the two.
114 */
115 bool
116 ast_type_qualifier::merge_qualifier(YYLTYPE *loc,
117 _mesa_glsl_parse_state *state,
118 const ast_type_qualifier &q,
119 bool is_single_layout_merge)
120 {
121 ast_type_qualifier ubo_mat_mask;
122 ubo_mat_mask.flags.i = 0;
123 ubo_mat_mask.flags.q.row_major = 1;
124 ubo_mat_mask.flags.q.column_major = 1;
125
126 ast_type_qualifier ubo_layout_mask;
127 ubo_layout_mask.flags.i = 0;
128 ubo_layout_mask.flags.q.std140 = 1;
129 ubo_layout_mask.flags.q.packed = 1;
130 ubo_layout_mask.flags.q.shared = 1;
131 ubo_layout_mask.flags.q.std430 = 1;
132
133 ast_type_qualifier ubo_binding_mask;
134 ubo_binding_mask.flags.i = 0;
135 ubo_binding_mask.flags.q.explicit_binding = 1;
136 ubo_binding_mask.flags.q.explicit_offset = 1;
137
138 ast_type_qualifier stream_layout_mask;
139 stream_layout_mask.flags.i = 0;
140 stream_layout_mask.flags.q.stream = 1;
141
142 /* FIXME: We should probably do interface and function param validation
143 * separately.
144 */
145 ast_type_qualifier input_layout_mask;
146 input_layout_mask.flags.i = 0;
147 input_layout_mask.flags.q.centroid = 1;
148 /* Function params can have constant */
149 input_layout_mask.flags.q.constant = 1;
150 input_layout_mask.flags.q.explicit_component = 1;
151 input_layout_mask.flags.q.explicit_location = 1;
152 input_layout_mask.flags.q.flat = 1;
153 input_layout_mask.flags.q.in = 1;
154 input_layout_mask.flags.q.invariant = 1;
155 input_layout_mask.flags.q.noperspective = 1;
156 input_layout_mask.flags.q.origin_upper_left = 1;
157 /* Function params 'inout' will set this */
158 input_layout_mask.flags.q.out = 1;
159 input_layout_mask.flags.q.patch = 1;
160 input_layout_mask.flags.q.pixel_center_integer = 1;
161 input_layout_mask.flags.q.precise = 1;
162 input_layout_mask.flags.q.sample = 1;
163 input_layout_mask.flags.q.smooth = 1;
164
165 /* Uniform block layout qualifiers get to overwrite each
166 * other (rightmost having priority), while all other
167 * qualifiers currently don't allow duplicates.
168 */
169 ast_type_qualifier allowed_duplicates_mask;
170 allowed_duplicates_mask.flags.i =
171 ubo_mat_mask.flags.i |
172 ubo_layout_mask.flags.i |
173 ubo_binding_mask.flags.i;
174
175 /* Geometry shaders can have several layout qualifiers
176 * assigning different stream values.
177 */
178 if (state->stage == MESA_SHADER_GEOMETRY) {
179 allowed_duplicates_mask.flags.i |=
180 stream_layout_mask.flags.i;
181 }
182
183 if (is_single_layout_merge && !state->has_enhanced_layouts() &&
184 (this->flags.i & q.flags.i & ~allowed_duplicates_mask.flags.i) != 0) {
185 _mesa_glsl_error(loc, state, "duplicate layout qualifiers used");
186 return false;
187 }
188
189 if (q.flags.q.prim_type) {
190 if (this->flags.q.prim_type && this->prim_type != q.prim_type) {
191 _mesa_glsl_error(loc, state,
192 "conflicting primitive type qualifiers used");
193 return false;
194 }
195 this->prim_type = q.prim_type;
196 }
197
198 if (q.flags.q.max_vertices) {
199 if (this->max_vertices) {
200 this->max_vertices->merge_qualifier(q.max_vertices);
201 } else {
202 this->max_vertices = q.max_vertices;
203 }
204 }
205
206 if (q.flags.q.subroutine_def) {
207 if (this->flags.q.subroutine_def) {
208 _mesa_glsl_error(loc, state,
209 "conflicting subroutine qualifiers used");
210 } else {
211 this->subroutine_list = q.subroutine_list;
212 }
213 }
214
215 if (q.flags.q.invocations) {
216 if (this->invocations) {
217 this->invocations->merge_qualifier(q.invocations);
218 } else {
219 this->invocations = q.invocations;
220 }
221 }
222
223 if (state->stage == MESA_SHADER_GEOMETRY &&
224 state->has_explicit_attrib_stream()) {
225 if (!this->flags.q.explicit_stream) {
226 if (q.flags.q.stream) {
227 this->flags.q.stream = 1;
228 this->stream = q.stream;
229 } else if (!this->flags.q.stream && this->flags.q.out &&
230 !this->flags.q.in) {
231 /* Assign default global stream value */
232 this->flags.q.stream = 1;
233 this->stream = state->out_qualifier->stream;
234 }
235 }
236 }
237
238 if (state->has_enhanced_layouts()) {
239 if (!this->flags.q.explicit_xfb_buffer) {
240 if (q.flags.q.xfb_buffer) {
241 this->flags.q.xfb_buffer = 1;
242 this->xfb_buffer = q.xfb_buffer;
243 } else if (!this->flags.q.xfb_buffer && this->flags.q.out &&
244 !this->flags.q.in) {
245 /* Assign global xfb_buffer value */
246 this->flags.q.xfb_buffer = 1;
247 this->xfb_buffer = state->out_qualifier->xfb_buffer;
248 }
249 }
250
251 if (q.flags.q.explicit_xfb_stride)
252 this->xfb_stride = q.xfb_stride;
253
254 /* Merge all we xfb_stride qualifiers into the global out */
255 if (q.flags.q.explicit_xfb_stride || this->flags.q.xfb_stride) {
256
257 /* Set xfb_stride flag to 0 to avoid adding duplicates every time
258 * there is a merge.
259 */
260 this->flags.q.xfb_stride = 0;
261
262 unsigned buff_idx;
263 if (process_qualifier_constant(state, loc, "xfb_buffer",
264 this->xfb_buffer, &buff_idx)) {
265 if (state->out_qualifier->out_xfb_stride[buff_idx]) {
266 state->out_qualifier->out_xfb_stride[buff_idx]->merge_qualifier(
267 new(state) ast_layout_expression(*loc, this->xfb_stride));
268 } else {
269 state->out_qualifier->out_xfb_stride[buff_idx] =
270 new(state) ast_layout_expression(*loc, this->xfb_stride);
271 }
272 }
273 }
274 }
275
276 if (q.flags.q.vertices) {
277 if (this->vertices) {
278 this->vertices->merge_qualifier(q.vertices);
279 } else {
280 this->vertices = q.vertices;
281 }
282 }
283
284 if (q.flags.q.vertex_spacing) {
285 if (this->flags.q.vertex_spacing && this->vertex_spacing != q.vertex_spacing) {
286 _mesa_glsl_error(loc, state, "conflicting vertex spacing used");
287 return false;
288 }
289 this->vertex_spacing = q.vertex_spacing;
290 }
291
292 if (q.flags.q.ordering) {
293 if (this->flags.q.ordering && this->ordering != q.ordering) {
294 _mesa_glsl_error(loc, state, "conflicting ordering used");
295 return false;
296 }
297 this->ordering = q.ordering;
298 }
299
300 if (q.flags.q.point_mode) {
301 if (this->flags.q.point_mode && this->point_mode != q.point_mode) {
302 _mesa_glsl_error(loc, state, "conflicting point mode used");
303 return false;
304 }
305 this->point_mode = q.point_mode;
306 }
307
308 if ((q.flags.i & ubo_mat_mask.flags.i) != 0)
309 this->flags.i &= ~ubo_mat_mask.flags.i;
310 if ((q.flags.i & ubo_layout_mask.flags.i) != 0)
311 this->flags.i &= ~ubo_layout_mask.flags.i;
312
313 for (int i = 0; i < 3; i++) {
314 if (q.flags.q.local_size & (1 << i)) {
315 if (this->local_size[i]) {
316 this->local_size[i]->merge_qualifier(q.local_size[i]);
317 } else {
318 this->local_size[i] = q.local_size[i];
319 }
320 }
321 }
322
323 this->flags.i |= q.flags.i;
324
325 if (this->flags.q.in &&
326 (this->flags.i & ~input_layout_mask.flags.i) != 0) {
327 _mesa_glsl_error(loc, state, "invalid input layout qualifier used");
328 return false;
329 }
330
331 if (q.flags.q.explicit_align)
332 this->align = q.align;
333
334 if (q.flags.q.explicit_location)
335 this->location = q.location;
336
337 if (q.flags.q.explicit_index)
338 this->index = q.index;
339
340 if (q.flags.q.explicit_component)
341 this->component = q.component;
342
343 if (q.flags.q.explicit_binding)
344 this->binding = q.binding;
345
346 if (q.flags.q.explicit_offset || q.flags.q.explicit_xfb_offset)
347 this->offset = q.offset;
348
349 if (q.precision != ast_precision_none)
350 this->precision = q.precision;
351
352 if (q.flags.q.explicit_image_format) {
353 this->image_format = q.image_format;
354 this->image_base_type = q.image_base_type;
355 }
356
357 return true;
358 }
359
360 bool
361 ast_type_qualifier::merge_out_qualifier(YYLTYPE *loc,
362 _mesa_glsl_parse_state *state,
363 const ast_type_qualifier &q,
364 ast_node* &node, bool create_node)
365 {
366 void *mem_ctx = state;
367 const bool r = this->merge_qualifier(loc, state, q, false);
368 ast_type_qualifier valid_out_mask;
369 valid_out_mask.flags.i = 0;
370
371 if (state->stage == MESA_SHADER_GEOMETRY) {
372 if (q.flags.q.prim_type) {
373 /* Make sure this is a valid output primitive type. */
374 switch (q.prim_type) {
375 case GL_POINTS:
376 case GL_LINE_STRIP:
377 case GL_TRIANGLE_STRIP:
378 break;
379 default:
380 _mesa_glsl_error(loc, state, "invalid geometry shader output "
381 "primitive type");
382 break;
383 }
384 }
385
386 /* Allow future assigments of global out's stream id value */
387 this->flags.q.explicit_stream = 0;
388
389 valid_out_mask.flags.q.stream = 1;
390 valid_out_mask.flags.q.explicit_stream = 1;
391 valid_out_mask.flags.q.explicit_xfb_buffer = 1;
392 valid_out_mask.flags.q.xfb_buffer = 1;
393 valid_out_mask.flags.q.explicit_xfb_stride = 1;
394 valid_out_mask.flags.q.xfb_stride = 1;
395 valid_out_mask.flags.q.max_vertices = 1;
396 valid_out_mask.flags.q.prim_type = 1;
397 } else if (state->stage == MESA_SHADER_TESS_CTRL) {
398 if (create_node) {
399 node = new(mem_ctx) ast_tcs_output_layout(*loc);
400 }
401 valid_out_mask.flags.q.vertices = 1;
402 valid_out_mask.flags.q.explicit_xfb_buffer = 1;
403 valid_out_mask.flags.q.xfb_buffer = 1;
404 valid_out_mask.flags.q.explicit_xfb_stride = 1;
405 valid_out_mask.flags.q.xfb_stride = 1;
406 } else if (state->stage == MESA_SHADER_TESS_EVAL ||
407 state->stage == MESA_SHADER_VERTEX) {
408 valid_out_mask.flags.q.explicit_xfb_buffer = 1;
409 valid_out_mask.flags.q.xfb_buffer = 1;
410 valid_out_mask.flags.q.explicit_xfb_stride = 1;
411 valid_out_mask.flags.q.xfb_stride = 1;
412 } else if (state->stage == MESA_SHADER_FRAGMENT) {
413 valid_out_mask.flags.q.blend_support = 1;
414 } else {
415 _mesa_glsl_error(loc, state, "out layout qualifiers only valid in "
416 "geometry, tessellation and vertex shaders");
417 return false;
418 }
419
420 /* Allow future assigments of global out's */
421 this->flags.q.explicit_xfb_buffer = 0;
422 this->flags.q.explicit_xfb_stride = 0;
423
424 /* Generate an error when invalid input layout qualifiers are used. */
425 if ((q.flags.i & ~valid_out_mask.flags.i) != 0) {
426 _mesa_glsl_error(loc, state, "invalid output layout qualifiers used");
427 return false;
428 }
429
430 return r;
431 }
432
433 bool
434 ast_type_qualifier::merge_in_qualifier(YYLTYPE *loc,
435 _mesa_glsl_parse_state *state,
436 const ast_type_qualifier &q,
437 ast_node* &node, bool create_node)
438 {
439 void *mem_ctx = state;
440 bool create_gs_ast = false;
441 bool create_cs_ast = false;
442 ast_type_qualifier valid_in_mask;
443 valid_in_mask.flags.i = 0;
444
445 switch (state->stage) {
446 case MESA_SHADER_TESS_EVAL:
447 if (q.flags.q.prim_type) {
448 /* Make sure this is a valid input primitive type. */
449 switch (q.prim_type) {
450 case GL_TRIANGLES:
451 case GL_QUADS:
452 case GL_ISOLINES:
453 break;
454 default:
455 _mesa_glsl_error(loc, state,
456 "invalid tessellation evaluation "
457 "shader input primitive type");
458 break;
459 }
460 }
461
462 valid_in_mask.flags.q.prim_type = 1;
463 valid_in_mask.flags.q.vertex_spacing = 1;
464 valid_in_mask.flags.q.ordering = 1;
465 valid_in_mask.flags.q.point_mode = 1;
466 break;
467 case MESA_SHADER_GEOMETRY:
468 if (q.flags.q.prim_type) {
469 /* Make sure this is a valid input primitive type. */
470 switch (q.prim_type) {
471 case GL_POINTS:
472 case GL_LINES:
473 case GL_LINES_ADJACENCY:
474 case GL_TRIANGLES:
475 case GL_TRIANGLES_ADJACENCY:
476 break;
477 default:
478 _mesa_glsl_error(loc, state,
479 "invalid geometry shader input primitive type");
480 break;
481 }
482 }
483
484 create_gs_ast |=
485 q.flags.q.prim_type &&
486 !state->in_qualifier->flags.q.prim_type;
487
488 valid_in_mask.flags.q.prim_type = 1;
489 valid_in_mask.flags.q.invocations = 1;
490 break;
491 case MESA_SHADER_FRAGMENT:
492 valid_in_mask.flags.q.early_fragment_tests = 1;
493 break;
494 case MESA_SHADER_COMPUTE:
495 create_cs_ast |=
496 q.flags.q.local_size != 0 &&
497 state->in_qualifier->flags.q.local_size == 0;
498
499 valid_in_mask.flags.q.local_size = 7;
500 break;
501 default:
502 _mesa_glsl_error(loc, state,
503 "input layout qualifiers only valid in "
504 "geometry, fragment and compute shaders");
505 break;
506 }
507
508 /* Generate an error when invalid input layout qualifiers are used. */
509 if ((q.flags.i & ~valid_in_mask.flags.i) != 0) {
510 _mesa_glsl_error(loc, state, "invalid input layout qualifiers used");
511 return false;
512 }
513
514 /* Input layout qualifiers can be specified multiple
515 * times in separate declarations, as long as they match.
516 */
517 if (this->flags.q.prim_type) {
518 if (q.flags.q.prim_type &&
519 this->prim_type != q.prim_type) {
520 _mesa_glsl_error(loc, state,
521 "conflicting input primitive %s specified",
522 state->stage == MESA_SHADER_GEOMETRY ?
523 "type" : "mode");
524 }
525 } else if (q.flags.q.prim_type) {
526 state->in_qualifier->flags.q.prim_type = 1;
527 state->in_qualifier->prim_type = q.prim_type;
528 }
529
530 if (q.flags.q.invocations) {
531 this->flags.q.invocations = 1;
532 if (this->invocations) {
533 this->invocations->merge_qualifier(q.invocations);
534 } else {
535 this->invocations = q.invocations;
536 }
537 }
538
539 if (q.flags.q.early_fragment_tests) {
540 state->fs_early_fragment_tests = true;
541 }
542
543 if (this->flags.q.vertex_spacing) {
544 if (q.flags.q.vertex_spacing &&
545 this->vertex_spacing != q.vertex_spacing) {
546 _mesa_glsl_error(loc, state,
547 "conflicting vertex spacing specified");
548 }
549 } else if (q.flags.q.vertex_spacing) {
550 this->flags.q.vertex_spacing = 1;
551 this->vertex_spacing = q.vertex_spacing;
552 }
553
554 if (this->flags.q.ordering) {
555 if (q.flags.q.ordering &&
556 this->ordering != q.ordering) {
557 _mesa_glsl_error(loc, state,
558 "conflicting ordering specified");
559 }
560 } else if (q.flags.q.ordering) {
561 this->flags.q.ordering = 1;
562 this->ordering = q.ordering;
563 }
564
565 if (this->flags.q.point_mode) {
566 if (q.flags.q.point_mode &&
567 this->point_mode != q.point_mode) {
568 _mesa_glsl_error(loc, state,
569 "conflicting point mode specified");
570 }
571 } else if (q.flags.q.point_mode) {
572 this->flags.q.point_mode = 1;
573 this->point_mode = q.point_mode;
574 }
575
576 if (create_node) {
577 if (create_gs_ast) {
578 node = new(mem_ctx) ast_gs_input_layout(*loc, q.prim_type);
579 } else if (create_cs_ast) {
580 node = new(mem_ctx) ast_cs_input_layout(*loc, q.local_size);
581 }
582 }
583
584 return true;
585 }
586
587 /**
588 * Check if the current type qualifier has any illegal flags.
589 *
590 * If so, print an error message, followed by a list of illegal flags.
591 *
592 * \param message The error message to print.
593 * \param allowed_flags A list of valid flags.
594 */
595 bool
596 ast_type_qualifier::validate_flags(YYLTYPE *loc,
597 _mesa_glsl_parse_state *state,
598 const ast_type_qualifier &allowed_flags,
599 const char *message, const char *name)
600 {
601 ast_type_qualifier bad;
602 bad.flags.i = this->flags.i & ~allowed_flags.flags.i;
603 if (bad.flags.i == 0)
604 return true;
605
606 _mesa_glsl_error(loc, state,
607 "%s '%s':"
608 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
609 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
610 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
611 message, name,
612 bad.flags.q.invariant ? " invariant" : "",
613 bad.flags.q.precise ? " precise" : "",
614 bad.flags.q.constant ? " constant" : "",
615 bad.flags.q.attribute ? " attribute" : "",
616 bad.flags.q.varying ? " varying" : "",
617 bad.flags.q.in ? " in" : "",
618 bad.flags.q.out ? " out" : "",
619 bad.flags.q.centroid ? " centroid" : "",
620 bad.flags.q.sample ? " sample" : "",
621 bad.flags.q.patch ? " patch" : "",
622 bad.flags.q.uniform ? " uniform" : "",
623 bad.flags.q.buffer ? " buffer" : "",
624 bad.flags.q.shared_storage ? " shared_storage" : "",
625 bad.flags.q.smooth ? " smooth" : "",
626 bad.flags.q.flat ? " flat" : "",
627 bad.flags.q.noperspective ? " noperspective" : "",
628 bad.flags.q.origin_upper_left ? " origin_upper_left" : "",
629 bad.flags.q.pixel_center_integer ? " pixel_center_integer" : "",
630 bad.flags.q.explicit_align ? " align" : "",
631 bad.flags.q.explicit_component ? " component" : "",
632 bad.flags.q.explicit_location ? " location" : "",
633 bad.flags.q.explicit_index ? " index" : "",
634 bad.flags.q.explicit_binding ? " binding" : "",
635 bad.flags.q.explicit_offset ? " offset" : "",
636 bad.flags.q.depth_any ? " depth_any" : "",
637 bad.flags.q.depth_greater ? " depth_greater" : "",
638 bad.flags.q.depth_less ? " depth_less" : "",
639 bad.flags.q.depth_unchanged ? " depth_unchanged" : "",
640 bad.flags.q.std140 ? " std140" : "",
641 bad.flags.q.std430 ? " std430" : "",
642 bad.flags.q.shared ? " shared" : "",
643 bad.flags.q.packed ? " packed" : "",
644 bad.flags.q.column_major ? " column_major" : "",
645 bad.flags.q.row_major ? " row_major" : "",
646 bad.flags.q.prim_type ? " prim_type" : "",
647 bad.flags.q.max_vertices ? " max_vertices" : "",
648 bad.flags.q.local_size ? " local_size" : "",
649 bad.flags.q.early_fragment_tests ? " early_fragment_tests" : "",
650 bad.flags.q.explicit_image_format ? " image_format" : "",
651 bad.flags.q.coherent ? " coherent" : "",
652 bad.flags.q._volatile ? " _volatile" : "",
653 bad.flags.q.restrict_flag ? " restrict_flag" : "",
654 bad.flags.q.read_only ? " read_only" : "",
655 bad.flags.q.write_only ? " write_only" : "",
656 bad.flags.q.invocations ? " invocations" : "",
657 bad.flags.q.stream ? " stream" : "",
658 bad.flags.q.explicit_stream ? " stream" : "",
659 bad.flags.q.explicit_xfb_offset ? " xfb_offset" : "",
660 bad.flags.q.xfb_buffer ? " xfb_buffer" : "",
661 bad.flags.q.explicit_xfb_buffer ? " xfb_buffer" : "",
662 bad.flags.q.xfb_stride ? " xfb_stride" : "",
663 bad.flags.q.explicit_xfb_stride ? " xfb_stride" : "",
664 bad.flags.q.vertex_spacing ? " vertex_spacing" : "",
665 bad.flags.q.ordering ? " ordering" : "",
666 bad.flags.q.point_mode ? " point_mode" : "",
667 bad.flags.q.vertices ? " vertices" : "",
668 bad.flags.q.subroutine ? " subroutine" : "",
669 bad.flags.q.subroutine_def ? " subroutine_def" : "");
670 return false;
671 }
672
673 bool
674 ast_layout_expression::process_qualifier_constant(struct _mesa_glsl_parse_state *state,
675 const char *qual_indentifier,
676 unsigned *value,
677 bool can_be_zero,
678 bool must_match)
679 {
680 int min_value = 0;
681 bool first_pass = true;
682 *value = 0;
683
684 if (!can_be_zero)
685 min_value = 1;
686
687 for (exec_node *node = layout_const_expressions.get_head_raw();
688 !node->is_tail_sentinel(); node = node->next) {
689
690 exec_list dummy_instructions;
691 ast_node *const_expression = exec_node_data(ast_node, node, link);
692
693 ir_rvalue *const ir = const_expression->hir(&dummy_instructions, state);
694
695 ir_constant *const const_int = ir->constant_expression_value();
696 if (const_int == NULL || !const_int->type->is_integer()) {
697 YYLTYPE loc = const_expression->get_location();
698 _mesa_glsl_error(&loc, state, "%s must be an integral constant "
699 "expression", qual_indentifier);
700 return false;
701 }
702
703 if (const_int->value.i[0] < min_value) {
704 YYLTYPE loc = const_expression->get_location();
705 _mesa_glsl_error(&loc, state, "%s layout qualifier is invalid "
706 "(%d < %d)", qual_indentifier,
707 const_int->value.i[0], min_value);
708 return false;
709 }
710
711 /* From section 4.4 "Layout Qualifiers" of the GLSL 4.50 spec:
712 * "When the same layout-qualifier-name occurs multiple times,
713 * in a single declaration, the last occurrence overrides the
714 * former occurrence(s)."
715 */
716 if (!first_pass) {
717 if ((must_match || !state->has_420pack()) && *value != const_int->value.u[0]) {
718 YYLTYPE loc = const_expression->get_location();
719 _mesa_glsl_error(&loc, state, "%s layout qualifier does not "
720 "match previous declaration (%d vs %d)",
721 qual_indentifier, *value, const_int->value.i[0]);
722 return false;
723 }
724 } else {
725 first_pass = false;
726 *value = const_int->value.u[0];
727 }
728
729 /* If the location is const (and we've verified that
730 * it is) then no instructions should have been emitted
731 * when we converted it to HIR. If they were emitted,
732 * then either the location isn't const after all, or
733 * we are emitting unnecessary instructions.
734 */
735 assert(dummy_instructions.is_empty());
736 }
737
738 return true;
739 }
740
741 bool
742 process_qualifier_constant(struct _mesa_glsl_parse_state *state,
743 YYLTYPE *loc,
744 const char *qual_indentifier,
745 ast_expression *const_expression,
746 unsigned *value)
747 {
748 exec_list dummy_instructions;
749
750 if (const_expression == NULL) {
751 *value = 0;
752 return true;
753 }
754
755 ir_rvalue *const ir = const_expression->hir(&dummy_instructions, state);
756
757 ir_constant *const const_int = ir->constant_expression_value();
758 if (const_int == NULL || !const_int->type->is_integer()) {
759 _mesa_glsl_error(loc, state, "%s must be an integral constant "
760 "expression", qual_indentifier);
761 return false;
762 }
763
764 if (const_int->value.i[0] < 0) {
765 _mesa_glsl_error(loc, state, "%s layout qualifier is invalid (%d < 0)",
766 qual_indentifier, const_int->value.u[0]);
767 return false;
768 }
769
770 /* If the location is const (and we've verified that
771 * it is) then no instructions should have been emitted
772 * when we converted it to HIR. If they were emitted,
773 * then either the location isn't const after all, or
774 * we are emitting unnecessary instructions.
775 */
776 assert(dummy_instructions.is_empty());
777
778 *value = const_int->value.u[0];
779 return true;
780 }