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