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