2 * Copyright © 2010 Intel Corporation
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:
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
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.
27 ast_type_specifier::print(void) const
32 printf("%s ", type_name
);
35 if (array_specifier
) {
36 array_specifier
->print();
41 ast_fully_specified_type::has_qualifiers(_mesa_glsl_parse_state
*state
) const
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;
50 return (this->qualifier
.flags
.i
& ~subroutine_only
.flags
.i
) != 0;
53 bool ast_type_qualifier::has_interpolation() const
55 return this->flags
.q
.smooth
57 || this->flags
.q
.noperspective
;
61 ast_type_qualifier::has_layout() const
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
;
86 ast_type_qualifier::has_storage() const
88 return this->flags
.q
.constant
89 || this->flags
.q
.attribute
90 || this->flags
.q
.varying
93 || this->flags
.q
.uniform
94 || this->flags
.q
.buffer
95 || this->flags
.q
.shared_storage
;
99 ast_type_qualifier::has_auxiliary_storage() const
101 return this->flags
.q
.centroid
102 || this->flags
.q
.sample
103 || this->flags
.q
.patch
;
106 bool ast_type_qualifier::has_memory() const
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
;
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
)
121 /* Input layout qualifiers can be specified multiple
122 * times in separate declarations, as long as they match.
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
?
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
)
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");
153 validate_ordering(YYLTYPE
*loc
,
154 _mesa_glsl_parse_state
*state
,
155 const ast_type_qualifier
&qualifier
,
156 const ast_type_qualifier
&new_qualifier
)
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");
169 validate_point_mode(MAYBE_UNUSED
const ast_type_qualifier
&qualifier
,
170 MAYBE_UNUSED
const ast_type_qualifier
&new_qualifier
)
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
));
180 * This function merges duplicate layout identifiers.
182 * It deals with duplicates within a single layout qualifier, among multiple
183 * layout qualifiers on a single declaration and on several declarations for
186 * The is_single_layout_merge and is_multiple_layouts_merge parameters are
187 * used to differentiate among them.
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
)
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;
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;
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;
214 ast_type_qualifier stream_layout_mask
;
215 stream_layout_mask
.flags
.i
= 0;
216 stream_layout_mask
.flags
.q
.stream
= 1;
218 /* FIXME: We should probably do interface and function param validation
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;
241 /* Uniform block layout qualifiers get to overwrite each
242 * other (rightmost having priority), while all other
243 * qualifiers currently don't allow duplicates.
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
;
251 /* Geometry shaders can have several layout qualifiers
252 * assigning different stream values.
254 if (state
->stage
== MESA_SHADER_GEOMETRY
) {
255 allowed_duplicates_mask
.flags
.i
|=
256 stream_layout_mask
.flags
.i
;
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");
265 if (is_multiple_layouts_merge
&& !state
->has_420pack_or_es31()) {
266 _mesa_glsl_error(loc
, state
,
267 "duplicate layout(...) qualifiers");
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
;
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
);
282 this->flags
.q
.max_vertices
= 1;
283 this->max_vertices
= q
.max_vertices
;
287 if (q
.subroutine_list
) {
288 if (this->subroutine_list
) {
289 _mesa_glsl_error(loc
, state
,
290 "conflicting subroutine qualifiers used");
292 this->subroutine_list
= q
.subroutine_list
;
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
);
301 this->flags
.q
.invocations
= 1;
302 this->invocations
= q
.invocations
;
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
&&
314 /* Assign default global stream value */
315 this->flags
.q
.stream
= 1;
316 this->stream
= state
->out_qualifier
->stream
;
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
&&
328 /* Assign global xfb_buffer value */
329 this->flags
.q
.xfb_buffer
= 1;
330 this->xfb_buffer
= state
->out_qualifier
->xfb_buffer
;
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
;
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
);
346 this->flags
.q
.vertices
= 1;
347 this->vertices
= q
.vertices
;
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
;
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
;
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
;
369 if (q
.flags
.q
.early_fragment_tests
)
370 this->flags
.q
.early_fragment_tests
= true;
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
;
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
]);
383 this->local_size
[i
] = q
.local_size
[i
];
388 if (q
.flags
.q
.local_size_variable
)
389 this->flags
.q
.local_size_variable
= true;
391 this->flags
.i
|= q
.flags
.i
;
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");
399 if (q
.flags
.q
.explicit_align
)
400 this->align
= q
.align
;
402 if (q
.flags
.q
.explicit_location
)
403 this->location
= q
.location
;
405 if (q
.flags
.q
.explicit_index
)
406 this->index
= q
.index
;
408 if (q
.flags
.q
.explicit_component
)
409 this->component
= q
.component
;
411 if (q
.flags
.q
.explicit_binding
)
412 this->binding
= q
.binding
;
414 if (q
.flags
.q
.explicit_offset
|| q
.flags
.q
.explicit_xfb_offset
)
415 this->offset
= q
.offset
;
417 if (q
.precision
!= ast_precision_none
)
418 this->precision
= q
.precision
;
420 if (q
.flags
.q
.explicit_image_format
) {
421 this->image_format
= q
.image_format
;
422 this->image_base_type
= q
.image_base_type
;
429 ast_type_qualifier::validate_out_qualifier(YYLTYPE
*loc
,
430 _mesa_glsl_parse_state
*state
)
433 ast_type_qualifier valid_out_mask
;
434 valid_out_mask
.flags
.i
= 0;
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
) {
443 case GL_TRIANGLE_STRIP
:
447 _mesa_glsl_error(loc
, state
, "invalid geometry shader output "
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;
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;
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;
476 case MESA_SHADER_FRAGMENT
:
477 valid_out_mask
.flags
.q
.blend_support
= 1;
481 _mesa_glsl_error(loc
, state
,
482 "out layout qualifiers only valid in "
483 "geometry, tessellation, vertex and fragment shaders");
486 /* Generate an error when invalid output layout qualifiers are used. */
487 if ((this->flags
.i
& ~valid_out_mask
.flags
.i
) != 0) {
489 _mesa_glsl_error(loc
, state
, "invalid output layout qualifiers used");
496 ast_type_qualifier::merge_into_out_qualifier(YYLTYPE
*loc
,
497 _mesa_glsl_parse_state
*state
,
500 const bool r
= state
->out_qualifier
->merge_qualifier(loc
, state
,
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;
508 case MESA_SHADER_TESS_CTRL
:
509 node
= new(state
->linalloc
) ast_tcs_output_layout(*loc
);
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;
523 ast_type_qualifier::validate_in_qualifier(YYLTYPE
*loc
,
524 _mesa_glsl_parse_state
*state
)
527 ast_type_qualifier valid_in_mask
;
528 valid_in_mask
.flags
.i
= 0;
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
) {
541 _mesa_glsl_error(loc
, state
,
542 "invalid tessellation evaluation "
543 "shader input primitive type");
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;
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
) {
559 case GL_LINES_ADJACENCY
:
561 case GL_TRIANGLES_ADJACENCY
:
565 _mesa_glsl_error(loc
, state
,
566 "invalid geometry shader input primitive type");
571 valid_in_mask
.flags
.q
.prim_type
= 1;
572 valid_in_mask
.flags
.q
.invocations
= 1;
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;
579 case MESA_SHADER_COMPUTE
:
580 valid_in_mask
.flags
.q
.local_size
= 7;
581 valid_in_mask
.flags
.q
.local_size_variable
= 1;
585 _mesa_glsl_error(loc
, state
,
586 "input layout qualifiers only valid in "
587 "geometry, tessellation, fragment and compute shaders");
591 /* Generate an error when invalid input layout qualifiers are used. */
592 if ((this->flags
.i
& ~valid_in_mask
.flags
.i
) != 0) {
594 _mesa_glsl_error(loc
, state
, "invalid input layout qualifiers used");
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.
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);
610 ast_type_qualifier::merge_into_in_qualifier(YYLTYPE
*loc
,
611 _mesa_glsl_parse_state
*state
,
615 void *lin_ctx
= state
->linalloc
;
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.
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
);
625 r
= state
->in_qualifier
->merge_qualifier(loc
, state
, *this, false);
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;
632 if (state
->in_qualifier
->flags
.q
.inner_coverage
) {
633 state
->fs_inner_coverage
= true;
634 state
->in_qualifier
->flags
.q
.inner_coverage
= false;
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;
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");
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
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
;
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;
670 ast_type_qualifier::push_to_global(YYLTYPE
*loc
,
671 _mesa_glsl_parse_state
*state
)
673 if (this->flags
.q
.xfb_stride
) {
674 this->flags
.q
.xfb_stride
= 0;
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
,
684 state
->out_qualifier
->out_xfb_stride
[buff_idx
] =
685 new(state
->linalloc
) ast_layout_expression(*loc
,
695 * Check if the current type qualifier has any illegal flags.
697 * If so, print an error message, followed by a list of illegal flags.
699 * \param message The error message to print.
700 * \param allowed_flags A list of valid flags.
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
)
708 ast_type_qualifier bad
;
709 bad
.flags
.i
= this->flags
.i
& ~allowed_flags
.flags
.i
;
710 if (bad
.flags
.i
== 0)
713 _mesa_glsl_error(loc
, state
,
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",
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" : "");
781 ast_layout_expression::process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
782 const char *qual_indentifier
,
787 bool first_pass
= true;
793 for (exec_node
*node
= layout_const_expressions
.get_head_raw();
794 !node
->is_tail_sentinel(); node
= node
->next
) {
796 exec_list dummy_instructions
;
797 ast_node
*const_expression
= exec_node_data(ast_node
, node
, link
);
799 ir_rvalue
*const ir
= const_expression
->hir(&dummy_instructions
, state
);
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
);
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
);
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]);
825 *value
= const_int
->value
.u
[0];
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.
834 assert(dummy_instructions
.is_empty());
841 process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
843 const char *qual_indentifier
,
844 ast_expression
*const_expression
,
847 exec_list dummy_instructions
;
849 if (const_expression
== NULL
) {
854 ir_rvalue
*const ir
= const_expression
->hir(&dummy_instructions
, state
);
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
);
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]);
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.
875 assert(dummy_instructions
.is_empty());
877 *value
= const_int
->value
.u
[0];