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