glsl: allow component qualifier on varying inputs
[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_component = 1;
150 input_layout_mask.flags.q.explicit_location = 1;
151 input_layout_mask.flags.q.flat = 1;
152 input_layout_mask.flags.q.in = 1;
153 input_layout_mask.flags.q.invariant = 1;
154 input_layout_mask.flags.q.noperspective = 1;
155 input_layout_mask.flags.q.origin_upper_left = 1;
156 /* Function params 'inout' will set this */
157 input_layout_mask.flags.q.out = 1;
158 input_layout_mask.flags.q.patch = 1;
159 input_layout_mask.flags.q.pixel_center_integer = 1;
160 input_layout_mask.flags.q.precise = 1;
161 input_layout_mask.flags.q.sample = 1;
162 input_layout_mask.flags.q.smooth = 1;
163
164 /* Uniform block layout qualifiers get to overwrite each
165 * other (rightmost having priority), while all other
166 * qualifiers currently don't allow duplicates.
167 */
168 ast_type_qualifier allowed_duplicates_mask;
169 allowed_duplicates_mask.flags.i =
170 ubo_mat_mask.flags.i |
171 ubo_layout_mask.flags.i |
172 ubo_binding_mask.flags.i;
173
174 /* Geometry shaders can have several layout qualifiers
175 * assigning different stream values.
176 */
177 if (state->stage == MESA_SHADER_GEOMETRY)
178 allowed_duplicates_mask.flags.i |=
179 stream_layout_mask.flags.i;
180
181 if (is_single_layout_merge && !state->has_enhanced_layouts() &&
182 (this->flags.i & q.flags.i & ~allowed_duplicates_mask.flags.i) != 0) {
183 _mesa_glsl_error(loc, state,
184 "duplicate layout qualifiers used");
185 return false;
186 }
187
188 if (q.flags.q.prim_type) {
189 if (this->flags.q.prim_type && this->prim_type != q.prim_type) {
190 _mesa_glsl_error(loc, state,
191 "conflicting primitive type qualifiers used");
192 return false;
193 }
194 this->prim_type = q.prim_type;
195 }
196
197 if (q.flags.q.max_vertices) {
198 if (this->max_vertices) {
199 this->max_vertices->merge_qualifier(q.max_vertices);
200 } else {
201 this->max_vertices = q.max_vertices;
202 }
203 }
204
205 if (q.flags.q.subroutine_def) {
206 if (this->flags.q.subroutine_def) {
207 _mesa_glsl_error(loc, state,
208 "conflicting subroutine qualifiers used");
209 } else {
210 this->subroutine_list = q.subroutine_list;
211 }
212 }
213
214 if (q.flags.q.invocations) {
215 if (this->invocations) {
216 this->invocations->merge_qualifier(q.invocations);
217 } else {
218 this->invocations = q.invocations;
219 }
220 }
221
222 if (state->stage == MESA_SHADER_GEOMETRY &&
223 state->has_explicit_attrib_stream()) {
224 if (!this->flags.q.explicit_stream) {
225 if (q.flags.q.stream) {
226 this->flags.q.stream = 1;
227 this->stream = q.stream;
228 } else if (!this->flags.q.stream && this->flags.q.out) {
229 /* Assign default global stream value */
230 this->flags.q.stream = 1;
231 this->stream = state->out_qualifier->stream;
232 }
233 }
234 }
235
236 if (state->has_enhanced_layouts()) {
237 if (!this->flags.q.explicit_xfb_buffer) {
238 if (q.flags.q.xfb_buffer) {
239 this->flags.q.xfb_buffer = 1;
240 this->xfb_buffer = q.xfb_buffer;
241 } else if (!this->flags.q.xfb_buffer && this->flags.q.out) {
242 /* Assign global xfb_buffer value */
243 this->flags.q.xfb_buffer = 1;
244 this->xfb_buffer = state->out_qualifier->xfb_buffer;
245 }
246 }
247
248 if (q.flags.q.explicit_xfb_stride)
249 this->xfb_stride = q.xfb_stride;
250
251 /* Merge all we xfb_stride qualifiers into the global out */
252 if (q.flags.q.explicit_xfb_stride || this->flags.q.xfb_stride) {
253
254 /* Set xfb_stride flag to 0 to avoid adding duplicates every time
255 * there is a merge.
256 */
257 this->flags.q.xfb_stride = 0;
258
259 unsigned buff_idx;
260 if (process_qualifier_constant(state, loc, "xfb_buffer",
261 this->xfb_buffer, &buff_idx)) {
262 if (state->out_qualifier->out_xfb_stride[buff_idx]) {
263 state->out_qualifier->out_xfb_stride[buff_idx]->merge_qualifier(
264 new(state) ast_layout_expression(*loc, this->xfb_stride));
265 } else {
266 state->out_qualifier->out_xfb_stride[buff_idx] =
267 new(state) ast_layout_expression(*loc, this->xfb_stride);
268 }
269 }
270 }
271 }
272
273 if (q.flags.q.vertices) {
274 if (this->vertices) {
275 this->vertices->merge_qualifier(q.vertices);
276 } else {
277 this->vertices = q.vertices;
278 }
279 }
280
281 if (q.flags.q.vertex_spacing) {
282 if (this->flags.q.vertex_spacing && this->vertex_spacing != q.vertex_spacing) {
283 _mesa_glsl_error(loc, state,
284 "conflicting vertex spacing used");
285 return false;
286 }
287 this->vertex_spacing = q.vertex_spacing;
288 }
289
290 if (q.flags.q.ordering) {
291 if (this->flags.q.ordering && this->ordering != q.ordering) {
292 _mesa_glsl_error(loc, state,
293 "conflicting ordering used");
294 return false;
295 }
296 this->ordering = q.ordering;
297 }
298
299 if (q.flags.q.point_mode) {
300 if (this->flags.q.point_mode && this->point_mode != q.point_mode) {
301 _mesa_glsl_error(loc, state,
302 "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,
328 "invalid input layout qualifier used");
329 return false;
330 }
331
332 if (q.flags.q.explicit_align)
333 this->align = q.align;
334
335 if (q.flags.q.explicit_location)
336 this->location = q.location;
337
338 if (q.flags.q.explicit_index)
339 this->index = q.index;
340
341 if (q.flags.q.explicit_component)
342 this->component = q.component;
343
344 if (q.flags.q.explicit_binding)
345 this->binding = q.binding;
346
347 if (q.flags.q.explicit_offset || q.flags.q.explicit_xfb_offset)
348 this->offset = q.offset;
349
350 if (q.precision != ast_precision_none)
351 this->precision = q.precision;
352
353 if (q.flags.q.explicit_image_format) {
354 this->image_format = q.image_format;
355 this->image_base_type = q.image_base_type;
356 }
357
358 return true;
359 }
360
361 bool
362 ast_type_qualifier::merge_out_qualifier(YYLTYPE *loc,
363 _mesa_glsl_parse_state *state,
364 const ast_type_qualifier &q,
365 ast_node* &node, bool create_node)
366 {
367 void *mem_ctx = state;
368 const bool r = this->merge_qualifier(loc, state, q, false);
369 ast_type_qualifier valid_out_mask;
370 valid_out_mask.flags.i = 0;
371
372 if (state->stage == MESA_SHADER_GEOMETRY) {
373 if (q.flags.q.prim_type) {
374 /* Make sure this is a valid output primitive type. */
375 switch (q.prim_type) {
376 case GL_POINTS:
377 case GL_LINE_STRIP:
378 case GL_TRIANGLE_STRIP:
379 break;
380 default:
381 _mesa_glsl_error(loc, state, "invalid geometry shader output "
382 "primitive type");
383 break;
384 }
385 }
386
387 /* Allow future assigments of global out's stream id value */
388 this->flags.q.explicit_stream = 0;
389
390 valid_out_mask.flags.q.stream = 1;
391 valid_out_mask.flags.q.explicit_stream = 1;
392 valid_out_mask.flags.q.explicit_xfb_buffer = 1;
393 valid_out_mask.flags.q.xfb_buffer = 1;
394 valid_out_mask.flags.q.explicit_xfb_stride = 1;
395 valid_out_mask.flags.q.xfb_stride = 1;
396 valid_out_mask.flags.q.max_vertices = 1;
397 valid_out_mask.flags.q.prim_type = 1;
398 } else if (state->stage == MESA_SHADER_TESS_CTRL) {
399 if (create_node) {
400 node = new(mem_ctx) ast_tcs_output_layout(*loc);
401 }
402 valid_out_mask.flags.q.vertices = 1;
403 valid_out_mask.flags.q.explicit_xfb_buffer = 1;
404 valid_out_mask.flags.q.xfb_buffer = 1;
405 valid_out_mask.flags.q.explicit_xfb_stride = 1;
406 valid_out_mask.flags.q.xfb_stride = 1;
407 } else if (state->stage == MESA_SHADER_TESS_EVAL ||
408 state->stage == MESA_SHADER_VERTEX) {
409 valid_out_mask.flags.q.explicit_xfb_buffer = 1;
410 valid_out_mask.flags.q.xfb_buffer = 1;
411 valid_out_mask.flags.q.explicit_xfb_stride = 1;
412 valid_out_mask.flags.q.xfb_stride = 1;
413 } else {
414 _mesa_glsl_error(loc, state, "out layout qualifiers only valid in "
415 "geometry, tessellation and vertex shaders");
416 return false;
417 }
418
419 /* Allow future assigments of global out's */
420 this->flags.q.explicit_xfb_buffer = 0;
421 this->flags.q.explicit_xfb_stride = 0;
422
423 /* Generate an error when invalid input layout qualifiers are used. */
424 if ((q.flags.i & ~valid_out_mask.flags.i) != 0) {
425 _mesa_glsl_error(loc, state,
426 "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,
511 "invalid input layout qualifiers used");
512 return false;
513 }
514
515 /* Input layout qualifiers can be specified multiple
516 * times in separate declarations, as long as they match.
517 */
518 if (this->flags.q.prim_type) {
519 if (q.flags.q.prim_type &&
520 this->prim_type != q.prim_type) {
521 _mesa_glsl_error(loc, state,
522 "conflicting input primitive %s specified",
523 state->stage == MESA_SHADER_GEOMETRY ?
524 "type" : "mode");
525 }
526 } else if (q.flags.q.prim_type) {
527 state->in_qualifier->flags.q.prim_type = 1;
528 state->in_qualifier->prim_type = q.prim_type;
529 }
530
531 if (q.flags.q.invocations) {
532 this->flags.q.invocations = 1;
533 if (this->invocations) {
534 this->invocations->merge_qualifier(q.invocations);
535 } else {
536 this->invocations = q.invocations;
537 }
538 }
539
540 if (q.flags.q.early_fragment_tests) {
541 state->fs_early_fragment_tests = true;
542 }
543
544 if (this->flags.q.vertex_spacing) {
545 if (q.flags.q.vertex_spacing &&
546 this->vertex_spacing != q.vertex_spacing) {
547 _mesa_glsl_error(loc, state,
548 "conflicting vertex spacing specified");
549 }
550 } else if (q.flags.q.vertex_spacing) {
551 this->flags.q.vertex_spacing = 1;
552 this->vertex_spacing = q.vertex_spacing;
553 }
554
555 if (this->flags.q.ordering) {
556 if (q.flags.q.ordering &&
557 this->ordering != q.ordering) {
558 _mesa_glsl_error(loc, state,
559 "conflicting ordering specified");
560 }
561 } else if (q.flags.q.ordering) {
562 this->flags.q.ordering = 1;
563 this->ordering = q.ordering;
564 }
565
566 if (this->flags.q.point_mode) {
567 if (q.flags.q.point_mode &&
568 this->point_mode != q.point_mode) {
569 _mesa_glsl_error(loc, state,
570 "conflicting point mode specified");
571 }
572 } else if (q.flags.q.point_mode) {
573 this->flags.q.point_mode = 1;
574 this->point_mode = q.point_mode;
575 }
576
577 if (create_node) {
578 if (create_gs_ast) {
579 node = new(mem_ctx) ast_gs_input_layout(*loc, q.prim_type);
580 } else if (create_cs_ast) {
581 node = new(mem_ctx) ast_cs_input_layout(*loc, q.local_size);
582 }
583 }
584
585 return true;
586 }
587
588 /**
589 * Check if the current type qualifier has any illegal flags.
590 *
591 * If so, print an error message, followed by a list of illegal flags.
592 *
593 * \param message The error message to print.
594 * \param allowed_flags A list of valid flags.
595 */
596 bool
597 ast_type_qualifier::validate_flags(YYLTYPE *loc,
598 _mesa_glsl_parse_state *state,
599 const char *message,
600 const ast_type_qualifier &allowed_flags)
601 {
602 ast_type_qualifier bad;
603 bad.flags.i = this->flags.i & ~allowed_flags.flags.i;
604 if (bad.flags.i == 0)
605 return true;
606
607 _mesa_glsl_error(loc, state,
608 "%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%s%s%s%s%s%s"
611 "%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
612 message,
613 bad.flags.q.invariant ? " invariant" : "",
614 bad.flags.q.precise ? " precise" : "",
615 bad.flags.q.constant ? " constant" : "",
616 bad.flags.q.attribute ? " attribute" : "",
617 bad.flags.q.varying ? " varying" : "",
618 bad.flags.q.in ? " in" : "",
619 bad.flags.q.out ? " out" : "",
620 bad.flags.q.centroid ? " centroid" : "",
621 bad.flags.q.sample ? " sample" : "",
622 bad.flags.q.patch ? " patch" : "",
623 bad.flags.q.uniform ? " uniform" : "",
624 bad.flags.q.buffer ? " buffer" : "",
625 bad.flags.q.shared_storage ? " shared_storage" : "",
626 bad.flags.q.smooth ? " smooth" : "",
627 bad.flags.q.flat ? " flat" : "",
628 bad.flags.q.noperspective ? " noperspective" : "",
629 bad.flags.q.origin_upper_left ? " origin_upper_left" : "",
630 bad.flags.q.pixel_center_integer ? " pixel_center_integer" : "",
631 bad.flags.q.explicit_align ? " align" : "",
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 {
679 int min_value = 0;
680 bool first_pass = true;
681 *value = 0;
682
683 if (!can_be_zero)
684 min_value = 1;
685
686 for (exec_node *node = layout_const_expressions.head;
687 !node->is_tail_sentinel(); node = node->next) {
688
689 exec_list dummy_instructions;
690 ast_node *const_expression = exec_node_data(ast_node, node, link);
691
692 ir_rvalue *const ir = const_expression->hir(&dummy_instructions, state);
693
694 ir_constant *const const_int = ir->constant_expression_value();
695 if (const_int == NULL || !const_int->type->is_integer()) {
696 YYLTYPE loc = const_expression->get_location();
697 _mesa_glsl_error(&loc, state, "%s must be an integral constant "
698 "expression", qual_indentifier);
699 return false;
700 }
701
702 if (const_int->value.i[0] < min_value) {
703 YYLTYPE loc = const_expression->get_location();
704 _mesa_glsl_error(&loc, state, "%s layout qualifier is invalid "
705 "(%d < %d)", qual_indentifier,
706 const_int->value.i[0], min_value);
707 return false;
708 }
709
710 if (!first_pass && *value != const_int->value.u[0]) {
711 YYLTYPE loc = const_expression->get_location();
712 _mesa_glsl_error(&loc, state, "%s layout qualifier does not "
713 "match previous declaration (%d vs %d)",
714 qual_indentifier, *value, const_int->value.i[0]);
715 return false;
716 } else {
717 first_pass = false;
718 *value = const_int->value.u[0];
719 }
720
721 /* If the location is const (and we've verified that
722 * it is) then no instructions should have been emitted
723 * when we converted it to HIR. If they were emitted,
724 * then either the location isn't const after all, or
725 * we are emitting unnecessary instructions.
726 */
727 assert(dummy_instructions.is_empty());
728 }
729
730 return true;
731 }
732
733 bool
734 process_qualifier_constant(struct _mesa_glsl_parse_state *state,
735 YYLTYPE *loc,
736 const char *qual_indentifier,
737 ast_expression *const_expression,
738 unsigned *value)
739 {
740 exec_list dummy_instructions;
741
742 if (const_expression == NULL) {
743 *value = 0;
744 return true;
745 }
746
747 ir_rvalue *const ir = const_expression->hir(&dummy_instructions, state);
748
749 ir_constant *const const_int = ir->constant_expression_value();
750 if (const_int == NULL || !const_int->type->is_integer()) {
751 _mesa_glsl_error(loc, state, "%s must be an integral constant "
752 "expression", qual_indentifier);
753 return false;
754 }
755
756 if (const_int->value.i[0] < 0) {
757 _mesa_glsl_error(loc, state, "%s layout qualifier is invalid (%d < 0)",
758 qual_indentifier, const_int->value.u[0]);
759 return false;
760 }
761
762 /* If the location is const (and we've verified that
763 * it is) then no instructions should have been emitted
764 * when we converted it to HIR. If they were emitted,
765 * then either the location isn't const after all, or
766 * we are emitting unnecessary instructions.
767 */
768 assert(dummy_instructions.is_empty());
769
770 *value = const_int->value.u[0];
771 return true;
772 }