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