glsl: merge layouts into the default one as the last step in interface blocks
[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::merge_out_qualifier(YYLTYPE *loc,
372 _mesa_glsl_parse_state *state,
373 const ast_type_qualifier &q,
374 ast_node* &node, bool create_node)
375 {
376 const bool r = this->merge_qualifier(loc, state, q, false);
377 ast_type_qualifier valid_out_mask;
378 valid_out_mask.flags.i = 0;
379
380 if (state->stage == MESA_SHADER_GEOMETRY) {
381 if (q.flags.q.prim_type) {
382 /* Make sure this is a valid output primitive type. */
383 switch (q.prim_type) {
384 case GL_POINTS:
385 case GL_LINE_STRIP:
386 case GL_TRIANGLE_STRIP:
387 break;
388 default:
389 _mesa_glsl_error(loc, state, "invalid geometry shader output "
390 "primitive type");
391 break;
392 }
393 }
394
395 /* Allow future assigments of global out's stream id value */
396 this->flags.q.explicit_stream = 0;
397
398 valid_out_mask.flags.q.stream = 1;
399 valid_out_mask.flags.q.explicit_stream = 1;
400 valid_out_mask.flags.q.explicit_xfb_buffer = 1;
401 valid_out_mask.flags.q.xfb_buffer = 1;
402 valid_out_mask.flags.q.explicit_xfb_stride = 1;
403 valid_out_mask.flags.q.xfb_stride = 1;
404 valid_out_mask.flags.q.max_vertices = 1;
405 valid_out_mask.flags.q.prim_type = 1;
406 } else if (state->stage == MESA_SHADER_TESS_CTRL) {
407 if (create_node) {
408 node = new(state->linalloc) ast_tcs_output_layout(*loc);
409 }
410 valid_out_mask.flags.q.vertices = 1;
411 valid_out_mask.flags.q.explicit_xfb_buffer = 1;
412 valid_out_mask.flags.q.xfb_buffer = 1;
413 valid_out_mask.flags.q.explicit_xfb_stride = 1;
414 valid_out_mask.flags.q.xfb_stride = 1;
415 } else if (state->stage == MESA_SHADER_TESS_EVAL ||
416 state->stage == MESA_SHADER_VERTEX) {
417 valid_out_mask.flags.q.explicit_xfb_buffer = 1;
418 valid_out_mask.flags.q.xfb_buffer = 1;
419 valid_out_mask.flags.q.explicit_xfb_stride = 1;
420 valid_out_mask.flags.q.xfb_stride = 1;
421 } else if (state->stage == MESA_SHADER_FRAGMENT) {
422 valid_out_mask.flags.q.blend_support = 1;
423 } else {
424 _mesa_glsl_error(loc, state, "out layout qualifiers only valid in "
425 "geometry, tessellation and vertex shaders");
426 return false;
427 }
428
429 /* Allow future assigments of global out's */
430 this->flags.q.explicit_xfb_buffer = 0;
431 this->flags.q.explicit_xfb_stride = 0;
432
433 /* Generate an error when invalid input layout qualifiers are used. */
434 if ((q.flags.i & ~valid_out_mask.flags.i) != 0) {
435 _mesa_glsl_error(loc, state, "invalid output layout qualifiers used");
436 return false;
437 }
438
439 return r;
440 }
441
442 bool
443 ast_type_qualifier::merge_in_qualifier(YYLTYPE *loc,
444 _mesa_glsl_parse_state *state,
445 const ast_type_qualifier &q,
446 ast_node* &node, bool create_node)
447 {
448 void *lin_ctx = state->linalloc;
449 bool create_gs_ast = false;
450 bool create_cs_ast = false;
451 ast_type_qualifier valid_in_mask;
452 valid_in_mask.flags.i = 0;
453
454 switch (state->stage) {
455 case MESA_SHADER_TESS_EVAL:
456 if (q.flags.q.prim_type) {
457 /* Make sure this is a valid input primitive type. */
458 switch (q.prim_type) {
459 case GL_TRIANGLES:
460 case GL_QUADS:
461 case GL_ISOLINES:
462 break;
463 default:
464 _mesa_glsl_error(loc, state,
465 "invalid tessellation evaluation "
466 "shader input primitive type");
467 break;
468 }
469 }
470
471 valid_in_mask.flags.q.prim_type = 1;
472 valid_in_mask.flags.q.vertex_spacing = 1;
473 valid_in_mask.flags.q.ordering = 1;
474 valid_in_mask.flags.q.point_mode = 1;
475 break;
476 case MESA_SHADER_GEOMETRY:
477 if (q.flags.q.prim_type) {
478 /* Make sure this is a valid input primitive type. */
479 switch (q.prim_type) {
480 case GL_POINTS:
481 case GL_LINES:
482 case GL_LINES_ADJACENCY:
483 case GL_TRIANGLES:
484 case GL_TRIANGLES_ADJACENCY:
485 break;
486 default:
487 _mesa_glsl_error(loc, state,
488 "invalid geometry shader input primitive type");
489 break;
490 }
491 }
492
493 create_gs_ast |=
494 q.flags.q.prim_type &&
495 !state->in_qualifier->flags.q.prim_type;
496
497 valid_in_mask.flags.q.prim_type = 1;
498 valid_in_mask.flags.q.invocations = 1;
499 break;
500 case MESA_SHADER_FRAGMENT:
501 valid_in_mask.flags.q.early_fragment_tests = 1;
502 break;
503 case MESA_SHADER_COMPUTE:
504 create_cs_ast |=
505 q.flags.q.local_size != 0 &&
506 state->in_qualifier->flags.q.local_size == 0;
507
508 valid_in_mask.flags.q.local_size = 7;
509 valid_in_mask.flags.q.local_size_variable = 1;
510 break;
511 default:
512 _mesa_glsl_error(loc, state,
513 "input layout qualifiers only valid in "
514 "geometry, fragment and compute shaders");
515 break;
516 }
517
518 /* Generate an error when invalid input layout qualifiers are used. */
519 if ((q.flags.i & ~valid_in_mask.flags.i) != 0) {
520 _mesa_glsl_error(loc, state, "invalid input layout qualifiers used");
521 return false;
522 }
523
524 /* Input layout qualifiers can be specified multiple
525 * times in separate declarations, as long as they match.
526 */
527 if (this->flags.q.prim_type) {
528 if (q.flags.q.prim_type &&
529 this->prim_type != q.prim_type) {
530 _mesa_glsl_error(loc, state,
531 "conflicting input primitive %s specified",
532 state->stage == MESA_SHADER_GEOMETRY ?
533 "type" : "mode");
534 }
535 } else if (q.flags.q.prim_type) {
536 state->in_qualifier->flags.q.prim_type = 1;
537 state->in_qualifier->prim_type = q.prim_type;
538 }
539
540 if (q.flags.q.invocations) {
541 this->flags.q.invocations = 1;
542 if (this->invocations) {
543 this->invocations->merge_qualifier(q.invocations);
544 } else {
545 this->invocations = q.invocations;
546 }
547 }
548
549 if (q.flags.q.early_fragment_tests) {
550 state->fs_early_fragment_tests = true;
551 }
552
553 if (this->flags.q.vertex_spacing) {
554 if (q.flags.q.vertex_spacing &&
555 this->vertex_spacing != q.vertex_spacing) {
556 _mesa_glsl_error(loc, state,
557 "conflicting vertex spacing specified");
558 }
559 } else if (q.flags.q.vertex_spacing) {
560 this->flags.q.vertex_spacing = 1;
561 this->vertex_spacing = q.vertex_spacing;
562 }
563
564 if (this->flags.q.ordering) {
565 if (q.flags.q.ordering &&
566 this->ordering != q.ordering) {
567 _mesa_glsl_error(loc, state,
568 "conflicting ordering specified");
569 }
570 } else if (q.flags.q.ordering) {
571 this->flags.q.ordering = 1;
572 this->ordering = q.ordering;
573 }
574
575 if (this->flags.q.point_mode) {
576 if (q.flags.q.point_mode &&
577 this->point_mode != q.point_mode) {
578 _mesa_glsl_error(loc, state,
579 "conflicting point mode specified");
580 }
581 } else if (q.flags.q.point_mode) {
582 this->flags.q.point_mode = 1;
583 this->point_mode = q.point_mode;
584 }
585
586 if (q.flags.q.local_size_variable) {
587 state->cs_input_local_size_variable_specified = true;
588 }
589
590 if (create_node) {
591 if (create_gs_ast) {
592 node = new(lin_ctx) ast_gs_input_layout(*loc, q.prim_type);
593 } else if (create_cs_ast) {
594 node = new(lin_ctx) ast_cs_input_layout(*loc, q.local_size);
595 }
596 }
597
598 return true;
599 }
600
601 /**
602 * Check if the current type qualifier has any illegal flags.
603 *
604 * If so, print an error message, followed by a list of illegal flags.
605 *
606 * \param message The error message to print.
607 * \param allowed_flags A list of valid flags.
608 */
609 bool
610 ast_type_qualifier::validate_flags(YYLTYPE *loc,
611 _mesa_glsl_parse_state *state,
612 const ast_type_qualifier &allowed_flags,
613 const char *message, const char *name)
614 {
615 ast_type_qualifier bad;
616 bad.flags.i = this->flags.i & ~allowed_flags.flags.i;
617 if (bad.flags.i == 0)
618 return true;
619
620 _mesa_glsl_error(loc, state,
621 "%s '%s':"
622 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
623 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
624 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
625 message, name,
626 bad.flags.q.invariant ? " invariant" : "",
627 bad.flags.q.precise ? " precise" : "",
628 bad.flags.q.constant ? " constant" : "",
629 bad.flags.q.attribute ? " attribute" : "",
630 bad.flags.q.varying ? " varying" : "",
631 bad.flags.q.in ? " in" : "",
632 bad.flags.q.out ? " out" : "",
633 bad.flags.q.centroid ? " centroid" : "",
634 bad.flags.q.sample ? " sample" : "",
635 bad.flags.q.patch ? " patch" : "",
636 bad.flags.q.uniform ? " uniform" : "",
637 bad.flags.q.buffer ? " buffer" : "",
638 bad.flags.q.shared_storage ? " shared_storage" : "",
639 bad.flags.q.smooth ? " smooth" : "",
640 bad.flags.q.flat ? " flat" : "",
641 bad.flags.q.noperspective ? " noperspective" : "",
642 bad.flags.q.origin_upper_left ? " origin_upper_left" : "",
643 bad.flags.q.pixel_center_integer ? " pixel_center_integer" : "",
644 bad.flags.q.explicit_align ? " align" : "",
645 bad.flags.q.explicit_component ? " component" : "",
646 bad.flags.q.explicit_location ? " location" : "",
647 bad.flags.q.explicit_index ? " index" : "",
648 bad.flags.q.explicit_binding ? " binding" : "",
649 bad.flags.q.explicit_offset ? " offset" : "",
650 bad.flags.q.depth_any ? " depth_any" : "",
651 bad.flags.q.depth_greater ? " depth_greater" : "",
652 bad.flags.q.depth_less ? " depth_less" : "",
653 bad.flags.q.depth_unchanged ? " depth_unchanged" : "",
654 bad.flags.q.std140 ? " std140" : "",
655 bad.flags.q.std430 ? " std430" : "",
656 bad.flags.q.shared ? " shared" : "",
657 bad.flags.q.packed ? " packed" : "",
658 bad.flags.q.column_major ? " column_major" : "",
659 bad.flags.q.row_major ? " row_major" : "",
660 bad.flags.q.prim_type ? " prim_type" : "",
661 bad.flags.q.max_vertices ? " max_vertices" : "",
662 bad.flags.q.local_size ? " local_size" : "",
663 bad.flags.q.local_size_variable ? " local_size_variable" : "",
664 bad.flags.q.early_fragment_tests ? " early_fragment_tests" : "",
665 bad.flags.q.explicit_image_format ? " image_format" : "",
666 bad.flags.q.coherent ? " coherent" : "",
667 bad.flags.q._volatile ? " _volatile" : "",
668 bad.flags.q.restrict_flag ? " restrict_flag" : "",
669 bad.flags.q.read_only ? " read_only" : "",
670 bad.flags.q.write_only ? " write_only" : "",
671 bad.flags.q.invocations ? " invocations" : "",
672 bad.flags.q.stream ? " stream" : "",
673 bad.flags.q.explicit_stream ? " stream" : "",
674 bad.flags.q.explicit_xfb_offset ? " xfb_offset" : "",
675 bad.flags.q.xfb_buffer ? " xfb_buffer" : "",
676 bad.flags.q.explicit_xfb_buffer ? " xfb_buffer" : "",
677 bad.flags.q.xfb_stride ? " xfb_stride" : "",
678 bad.flags.q.explicit_xfb_stride ? " xfb_stride" : "",
679 bad.flags.q.vertex_spacing ? " vertex_spacing" : "",
680 bad.flags.q.ordering ? " ordering" : "",
681 bad.flags.q.point_mode ? " point_mode" : "",
682 bad.flags.q.vertices ? " vertices" : "",
683 bad.flags.q.subroutine ? " subroutine" : "",
684 bad.flags.q.subroutine_def ? " subroutine_def" : "");
685 return false;
686 }
687
688 bool
689 ast_layout_expression::process_qualifier_constant(struct _mesa_glsl_parse_state *state,
690 const char *qual_indentifier,
691 unsigned *value,
692 bool can_be_zero,
693 bool must_match)
694 {
695 int min_value = 0;
696 bool first_pass = true;
697 *value = 0;
698
699 if (!can_be_zero)
700 min_value = 1;
701
702 for (exec_node *node = layout_const_expressions.get_head_raw();
703 !node->is_tail_sentinel(); node = node->next) {
704
705 exec_list dummy_instructions;
706 ast_node *const_expression = exec_node_data(ast_node, node, link);
707
708 ir_rvalue *const ir = const_expression->hir(&dummy_instructions, state);
709
710 ir_constant *const const_int = ir->constant_expression_value();
711 if (const_int == NULL || !const_int->type->is_integer()) {
712 YYLTYPE loc = const_expression->get_location();
713 _mesa_glsl_error(&loc, state, "%s must be an integral constant "
714 "expression", qual_indentifier);
715 return false;
716 }
717
718 if (const_int->value.i[0] < min_value) {
719 YYLTYPE loc = const_expression->get_location();
720 _mesa_glsl_error(&loc, state, "%s layout qualifier is invalid "
721 "(%d < %d)", qual_indentifier,
722 const_int->value.i[0], min_value);
723 return false;
724 }
725
726 /* From section 4.4 "Layout Qualifiers" of the GLSL 4.50 spec:
727 * "When the same layout-qualifier-name occurs multiple times,
728 * in a single declaration, the last occurrence overrides the
729 * former occurrence(s)."
730 */
731 if (!first_pass) {
732 if ((must_match || !state->has_420pack()) && *value != const_int->value.u[0]) {
733 YYLTYPE loc = const_expression->get_location();
734 _mesa_glsl_error(&loc, state, "%s layout qualifier does not "
735 "match previous declaration (%d vs %d)",
736 qual_indentifier, *value, const_int->value.i[0]);
737 return false;
738 }
739 } else {
740 first_pass = false;
741 *value = const_int->value.u[0];
742 }
743
744 /* If the location is const (and we've verified that
745 * it is) then no instructions should have been emitted
746 * when we converted it to HIR. If they were emitted,
747 * then either the location isn't const after all, or
748 * we are emitting unnecessary instructions.
749 */
750 assert(dummy_instructions.is_empty());
751 }
752
753 return true;
754 }
755
756 bool
757 process_qualifier_constant(struct _mesa_glsl_parse_state *state,
758 YYLTYPE *loc,
759 const char *qual_indentifier,
760 ast_expression *const_expression,
761 unsigned *value)
762 {
763 exec_list dummy_instructions;
764
765 if (const_expression == NULL) {
766 *value = 0;
767 return true;
768 }
769
770 ir_rvalue *const ir = const_expression->hir(&dummy_instructions, state);
771
772 ir_constant *const const_int = ir->constant_expression_value();
773 if (const_int == NULL || !const_int->type->is_integer()) {
774 _mesa_glsl_error(loc, state, "%s must be an integral constant "
775 "expression", qual_indentifier);
776 return false;
777 }
778
779 if (const_int->value.i[0] < 0) {
780 _mesa_glsl_error(loc, state, "%s layout qualifier is invalid (%d < 0)",
781 qual_indentifier, const_int->value.u[0]);
782 return false;
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 *value = const_int->value.u[0];
794 return true;
795 }