glsl: parse component layout qualifier
[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_location
78 || this->flags.q.explicit_image_format
79 || this->flags.q.explicit_index
80 || this->flags.q.explicit_binding
81 || this->flags.q.explicit_offset
82 || this->flags.q.explicit_stream
83 || this->flags.q.explicit_xfb_buffer
84 || this->flags.q.explicit_xfb_offset
85 || this->flags.q.explicit_xfb_stride;
86 }
87
88 bool
89 ast_type_qualifier::has_storage() const
90 {
91 return this->flags.q.constant
92 || this->flags.q.attribute
93 || this->flags.q.varying
94 || this->flags.q.in
95 || this->flags.q.out
96 || this->flags.q.uniform
97 || this->flags.q.buffer
98 || this->flags.q.shared_storage;
99 }
100
101 bool
102 ast_type_qualifier::has_auxiliary_storage() const
103 {
104 return this->flags.q.centroid
105 || this->flags.q.sample
106 || this->flags.q.patch;
107 }
108
109 /**
110 * This function merges both duplicate identifies within a single layout and
111 * multiple layout qualifiers on a single variable declaration. The
112 * is_single_layout_merge param is used differentiate between the two.
113 */
114 bool
115 ast_type_qualifier::merge_qualifier(YYLTYPE *loc,
116 _mesa_glsl_parse_state *state,
117 const ast_type_qualifier &q,
118 bool is_single_layout_merge)
119 {
120 ast_type_qualifier ubo_mat_mask;
121 ubo_mat_mask.flags.i = 0;
122 ubo_mat_mask.flags.q.row_major = 1;
123 ubo_mat_mask.flags.q.column_major = 1;
124
125 ast_type_qualifier ubo_layout_mask;
126 ubo_layout_mask.flags.i = 0;
127 ubo_layout_mask.flags.q.std140 = 1;
128 ubo_layout_mask.flags.q.packed = 1;
129 ubo_layout_mask.flags.q.shared = 1;
130 ubo_layout_mask.flags.q.std430 = 1;
131
132 ast_type_qualifier ubo_binding_mask;
133 ubo_binding_mask.flags.i = 0;
134 ubo_binding_mask.flags.q.explicit_binding = 1;
135 ubo_binding_mask.flags.q.explicit_offset = 1;
136
137 ast_type_qualifier stream_layout_mask;
138 stream_layout_mask.flags.i = 0;
139 stream_layout_mask.flags.q.stream = 1;
140
141 /* FIXME: We should probably do interface and function param validation
142 * separately.
143 */
144 ast_type_qualifier input_layout_mask;
145 input_layout_mask.flags.i = 0;
146 input_layout_mask.flags.q.centroid = 1;
147 /* Function params can have constant */
148 input_layout_mask.flags.q.constant = 1;
149 input_layout_mask.flags.q.explicit_location = 1;
150 input_layout_mask.flags.q.flat = 1;
151 input_layout_mask.flags.q.in = 1;
152 input_layout_mask.flags.q.invariant = 1;
153 input_layout_mask.flags.q.noperspective = 1;
154 input_layout_mask.flags.q.origin_upper_left = 1;
155 /* Function params 'inout' will set this */
156 input_layout_mask.flags.q.out = 1;
157 input_layout_mask.flags.q.patch = 1;
158 input_layout_mask.flags.q.pixel_center_integer = 1;
159 input_layout_mask.flags.q.precise = 1;
160 input_layout_mask.flags.q.sample = 1;
161 input_layout_mask.flags.q.smooth = 1;
162
163 /* Uniform block layout qualifiers get to overwrite each
164 * other (rightmost having priority), while all other
165 * qualifiers currently don't allow duplicates.
166 */
167 ast_type_qualifier allowed_duplicates_mask;
168 allowed_duplicates_mask.flags.i =
169 ubo_mat_mask.flags.i |
170 ubo_layout_mask.flags.i |
171 ubo_binding_mask.flags.i;
172
173 /* Geometry shaders can have several layout qualifiers
174 * assigning different stream values.
175 */
176 if (state->stage == MESA_SHADER_GEOMETRY)
177 allowed_duplicates_mask.flags.i |=
178 stream_layout_mask.flags.i;
179
180 if (is_single_layout_merge && !state->has_enhanced_layouts() &&
181 (this->flags.i & q.flags.i & ~allowed_duplicates_mask.flags.i) != 0) {
182 _mesa_glsl_error(loc, state,
183 "duplicate layout qualifiers used");
184 return false;
185 }
186
187 if (q.flags.q.prim_type) {
188 if (this->flags.q.prim_type && this->prim_type != q.prim_type) {
189 _mesa_glsl_error(loc, state,
190 "conflicting primitive type qualifiers used");
191 return false;
192 }
193 this->prim_type = q.prim_type;
194 }
195
196 if (q.flags.q.max_vertices) {
197 if (this->max_vertices) {
198 this->max_vertices->merge_qualifier(q.max_vertices);
199 } else {
200 this->max_vertices = q.max_vertices;
201 }
202 }
203
204 if (q.flags.q.subroutine_def) {
205 if (this->flags.q.subroutine_def) {
206 _mesa_glsl_error(loc, state,
207 "conflicting subroutine qualifiers used");
208 } else {
209 this->subroutine_list = q.subroutine_list;
210 }
211 }
212
213 if (q.flags.q.invocations) {
214 if (this->invocations) {
215 this->invocations->merge_qualifier(q.invocations);
216 } else {
217 this->invocations = q.invocations;
218 }
219 }
220
221 if (state->stage == MESA_SHADER_GEOMETRY &&
222 state->has_explicit_attrib_stream()) {
223 if (!this->flags.q.explicit_stream) {
224 if (q.flags.q.stream) {
225 this->flags.q.stream = 1;
226 this->stream = q.stream;
227 } else if (!this->flags.q.stream && this->flags.q.out) {
228 /* Assign default global stream value */
229 this->flags.q.stream = 1;
230 this->stream = state->out_qualifier->stream;
231 }
232 }
233 }
234
235 if (state->has_enhanced_layouts()) {
236 if (!this->flags.q.explicit_xfb_buffer) {
237 if (q.flags.q.xfb_buffer) {
238 this->flags.q.xfb_buffer = 1;
239 this->xfb_buffer = q.xfb_buffer;
240 } else if (!this->flags.q.xfb_buffer && this->flags.q.out) {
241 /* Assign global xfb_buffer value */
242 this->flags.q.xfb_buffer = 1;
243 this->xfb_buffer = state->out_qualifier->xfb_buffer;
244 }
245 }
246
247 if (q.flags.q.explicit_xfb_stride)
248 this->xfb_stride = q.xfb_stride;
249
250 /* Merge all we xfb_stride qualifiers into the global out */
251 if (q.flags.q.explicit_xfb_stride || this->flags.q.xfb_stride) {
252
253 /* Set xfb_stride flag to 0 to avoid adding duplicates every time
254 * there is a merge.
255 */
256 this->flags.q.xfb_stride = 0;
257
258 unsigned buff_idx;
259 if (process_qualifier_constant(state, loc, "xfb_buffer",
260 this->xfb_buffer, &buff_idx)) {
261 if (state->out_qualifier->out_xfb_stride[buff_idx]) {
262 state->out_qualifier->out_xfb_stride[buff_idx]->merge_qualifier(
263 new(state) ast_layout_expression(*loc, this->xfb_stride));
264 } else {
265 state->out_qualifier->out_xfb_stride[buff_idx] =
266 new(state) ast_layout_expression(*loc, this->xfb_stride);
267 }
268 }
269 }
270 }
271
272 if (q.flags.q.vertices) {
273 if (this->vertices) {
274 this->vertices->merge_qualifier(q.vertices);
275 } else {
276 this->vertices = q.vertices;
277 }
278 }
279
280 if (q.flags.q.vertex_spacing) {
281 if (this->flags.q.vertex_spacing && this->vertex_spacing != q.vertex_spacing) {
282 _mesa_glsl_error(loc, state,
283 "conflicting vertex spacing used");
284 return false;
285 }
286 this->vertex_spacing = q.vertex_spacing;
287 }
288
289 if (q.flags.q.ordering) {
290 if (this->flags.q.ordering && this->ordering != q.ordering) {
291 _mesa_glsl_error(loc, state,
292 "conflicting ordering used");
293 return false;
294 }
295 this->ordering = q.ordering;
296 }
297
298 if (q.flags.q.point_mode) {
299 if (this->flags.q.point_mode && this->point_mode != q.point_mode) {
300 _mesa_glsl_error(loc, state,
301 "conflicting point mode used");
302 return false;
303 }
304 this->point_mode = q.point_mode;
305 }
306
307 if ((q.flags.i & ubo_mat_mask.flags.i) != 0)
308 this->flags.i &= ~ubo_mat_mask.flags.i;
309 if ((q.flags.i & ubo_layout_mask.flags.i) != 0)
310 this->flags.i &= ~ubo_layout_mask.flags.i;
311
312 for (int i = 0; i < 3; i++) {
313 if (q.flags.q.local_size & (1 << i)) {
314 if (this->local_size[i]) {
315 this->local_size[i]->merge_qualifier(q.local_size[i]);
316 } else {
317 this->local_size[i] = q.local_size[i];
318 }
319 }
320 }
321
322 this->flags.i |= q.flags.i;
323
324 if (this->flags.q.in &&
325 (this->flags.i & ~input_layout_mask.flags.i) != 0) {
326 _mesa_glsl_error(loc, state,
327 "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 {
413 _mesa_glsl_error(loc, state, "out layout qualifiers only valid in "
414 "geometry, tessellation and vertex shaders");
415 return false;
416 }
417
418 /* Allow future assigments of global out's */
419 this->flags.q.explicit_xfb_buffer = 0;
420 this->flags.q.explicit_xfb_stride = 0;
421
422 /* Generate an error when invalid input layout qualifiers are used. */
423 if ((q.flags.i & ~valid_out_mask.flags.i) != 0) {
424 _mesa_glsl_error(loc, state,
425 "invalid output layout qualifiers used");
426 return false;
427 }
428
429 return r;
430 }
431
432 bool
433 ast_type_qualifier::merge_in_qualifier(YYLTYPE *loc,
434 _mesa_glsl_parse_state *state,
435 const ast_type_qualifier &q,
436 ast_node* &node, bool create_node)
437 {
438 void *mem_ctx = state;
439 bool create_gs_ast = false;
440 bool create_cs_ast = false;
441 ast_type_qualifier valid_in_mask;
442 valid_in_mask.flags.i = 0;
443
444 switch (state->stage) {
445 case MESA_SHADER_TESS_EVAL:
446 if (q.flags.q.prim_type) {
447 /* Make sure this is a valid input primitive type. */
448 switch (q.prim_type) {
449 case GL_TRIANGLES:
450 case GL_QUADS:
451 case GL_ISOLINES:
452 break;
453 default:
454 _mesa_glsl_error(loc, state,
455 "invalid tessellation evaluation "
456 "shader input primitive type");
457 break;
458 }
459 }
460
461 valid_in_mask.flags.q.prim_type = 1;
462 valid_in_mask.flags.q.vertex_spacing = 1;
463 valid_in_mask.flags.q.ordering = 1;
464 valid_in_mask.flags.q.point_mode = 1;
465 break;
466 case MESA_SHADER_GEOMETRY:
467 if (q.flags.q.prim_type) {
468 /* Make sure this is a valid input primitive type. */
469 switch (q.prim_type) {
470 case GL_POINTS:
471 case GL_LINES:
472 case GL_LINES_ADJACENCY:
473 case GL_TRIANGLES:
474 case GL_TRIANGLES_ADJACENCY:
475 break;
476 default:
477 _mesa_glsl_error(loc, state,
478 "invalid geometry shader input primitive type");
479 break;
480 }
481 }
482
483 create_gs_ast |=
484 q.flags.q.prim_type &&
485 !state->in_qualifier->flags.q.prim_type;
486
487 valid_in_mask.flags.q.prim_type = 1;
488 valid_in_mask.flags.q.invocations = 1;
489 break;
490 case MESA_SHADER_FRAGMENT:
491 valid_in_mask.flags.q.early_fragment_tests = 1;
492 break;
493 case MESA_SHADER_COMPUTE:
494 create_cs_ast |=
495 q.flags.q.local_size != 0 &&
496 state->in_qualifier->flags.q.local_size == 0;
497
498 valid_in_mask.flags.q.local_size = 7;
499 break;
500 default:
501 _mesa_glsl_error(loc, state,
502 "input layout qualifiers only valid in "
503 "geometry, fragment and compute shaders");
504 break;
505 }
506
507 /* Generate an error when invalid input layout qualifiers are used. */
508 if ((q.flags.i & ~valid_in_mask.flags.i) != 0) {
509 _mesa_glsl_error(loc, state,
510 "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 char *message,
599 const ast_type_qualifier &allowed_flags)
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:"
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\n",
611 message,
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_location ? " location" : "",
632 bad.flags.q.explicit_index ? " index" : "",
633 bad.flags.q.explicit_binding ? " binding" : "",
634 bad.flags.q.explicit_offset ? " offset" : "",
635 bad.flags.q.depth_any ? " depth_any" : "",
636 bad.flags.q.depth_greater ? " depth_greater" : "",
637 bad.flags.q.depth_less ? " depth_less" : "",
638 bad.flags.q.depth_unchanged ? " depth_unchanged" : "",
639 bad.flags.q.std140 ? " std140" : "",
640 bad.flags.q.std430 ? " std430" : "",
641 bad.flags.q.shared ? " shared" : "",
642 bad.flags.q.packed ? " packed" : "",
643 bad.flags.q.column_major ? " column_major" : "",
644 bad.flags.q.row_major ? " row_major" : "",
645 bad.flags.q.prim_type ? " prim_type" : "",
646 bad.flags.q.max_vertices ? " max_vertices" : "",
647 bad.flags.q.local_size ? " local_size" : "",
648 bad.flags.q.early_fragment_tests ? " early_fragment_tests" : "",
649 bad.flags.q.explicit_image_format ? " image_format" : "",
650 bad.flags.q.coherent ? " coherent" : "",
651 bad.flags.q._volatile ? " _volatile" : "",
652 bad.flags.q.restrict_flag ? " restrict_flag" : "",
653 bad.flags.q.read_only ? " read_only" : "",
654 bad.flags.q.write_only ? " write_only" : "",
655 bad.flags.q.invocations ? " invocations" : "",
656 bad.flags.q.stream ? " stream" : "",
657 bad.flags.q.explicit_stream ? " stream" : "",
658 bad.flags.q.explicit_xfb_offset ? " xfb_offset" : "",
659 bad.flags.q.xfb_buffer ? " xfb_buffer" : "",
660 bad.flags.q.explicit_xfb_buffer ? " xfb_buffer" : "",
661 bad.flags.q.xfb_stride ? " xfb_stride" : "",
662 bad.flags.q.explicit_xfb_stride ? " xfb_stride" : "",
663 bad.flags.q.vertex_spacing ? " vertex_spacing" : "",
664 bad.flags.q.ordering ? " ordering" : "",
665 bad.flags.q.point_mode ? " point_mode" : "",
666 bad.flags.q.vertices ? " vertices" : "",
667 bad.flags.q.subroutine ? " subroutine" : "",
668 bad.flags.q.subroutine_def ? " subroutine_def" : "");
669 return false;
670 }
671
672 bool
673 ast_layout_expression::process_qualifier_constant(struct _mesa_glsl_parse_state *state,
674 const char *qual_indentifier,
675 unsigned *value,
676 bool can_be_zero)
677 {
678 int min_value = 0;
679 bool first_pass = true;
680 *value = 0;
681
682 if (!can_be_zero)
683 min_value = 1;
684
685 for (exec_node *node = layout_const_expressions.head;
686 !node->is_tail_sentinel(); node = node->next) {
687
688 exec_list dummy_instructions;
689 ast_node *const_expression = exec_node_data(ast_node, node, link);
690
691 ir_rvalue *const ir = const_expression->hir(&dummy_instructions, state);
692
693 ir_constant *const const_int = ir->constant_expression_value();
694 if (const_int == NULL || !const_int->type->is_integer()) {
695 YYLTYPE loc = const_expression->get_location();
696 _mesa_glsl_error(&loc, state, "%s must be an integral constant "
697 "expression", qual_indentifier);
698 return false;
699 }
700
701 if (const_int->value.i[0] < min_value) {
702 YYLTYPE loc = const_expression->get_location();
703 _mesa_glsl_error(&loc, state, "%s layout qualifier is invalid "
704 "(%d < %d)", qual_indentifier,
705 const_int->value.i[0], min_value);
706 return false;
707 }
708
709 if (!first_pass && *value != const_int->value.u[0]) {
710 YYLTYPE loc = const_expression->get_location();
711 _mesa_glsl_error(&loc, state, "%s layout qualifier does not "
712 "match previous declaration (%d vs %d)",
713 qual_indentifier, *value, const_int->value.i[0]);
714 return false;
715 } else {
716 first_pass = false;
717 *value = const_int->value.u[0];
718 }
719
720 /* If the location is const (and we've verified that
721 * it is) then no instructions should have been emitted
722 * when we converted it to HIR. If they were emitted,
723 * then either the location isn't const after all, or
724 * we are emitting unnecessary instructions.
725 */
726 assert(dummy_instructions.is_empty());
727 }
728
729 return true;
730 }
731
732 bool
733 process_qualifier_constant(struct _mesa_glsl_parse_state *state,
734 YYLTYPE *loc,
735 const char *qual_indentifier,
736 ast_expression *const_expression,
737 unsigned *value)
738 {
739 exec_list dummy_instructions;
740
741 if (const_expression == NULL) {
742 *value = 0;
743 return true;
744 }
745
746 ir_rvalue *const ir = const_expression->hir(&dummy_instructions, state);
747
748 ir_constant *const const_int = ir->constant_expression_value();
749 if (const_int == NULL || !const_int->type->is_integer()) {
750 _mesa_glsl_error(loc, state, "%s must be an integral constant "
751 "expression", qual_indentifier);
752 return false;
753 }
754
755 if (const_int->value.i[0] < 0) {
756 _mesa_glsl_error(loc, state, "%s layout qualifier is invalid (%d < 0)",
757 qual_indentifier, const_int->value.u[0]);
758 return false;
759 }
760
761 /* If the location is const (and we've verified that
762 * it is) then no instructions should have been emitted
763 * when we converted it to HIR. If they were emitted,
764 * then either the location isn't const after all, or
765 * we are emitting unnecessary instructions.
766 */
767 assert(dummy_instructions.is_empty());
768
769 *value = const_int->value.u[0];
770 return true;
771 }