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