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
;
115 bool ast_type_qualifier::is_subroutine_decl() const
117 return this->flags
.q
.subroutine
&& !this->subroutine_list
;
121 validate_prim_type(YYLTYPE
*loc
,
122 _mesa_glsl_parse_state
*state
,
123 const ast_type_qualifier
&qualifier
,
124 const ast_type_qualifier
&new_qualifier
)
126 /* Input layout qualifiers can be specified multiple
127 * times in separate declarations, as long as they match.
129 if (qualifier
.flags
.q
.prim_type
&& new_qualifier
.flags
.q
.prim_type
130 && qualifier
.prim_type
!= new_qualifier
.prim_type
) {
131 _mesa_glsl_error(loc
, state
,
132 "conflicting input primitive %s specified",
133 state
->stage
== MESA_SHADER_GEOMETRY
?
142 validate_vertex_spacing(YYLTYPE
*loc
,
143 _mesa_glsl_parse_state
*state
,
144 const ast_type_qualifier
&qualifier
,
145 const ast_type_qualifier
&new_qualifier
)
147 if (qualifier
.flags
.q
.vertex_spacing
&& new_qualifier
.flags
.q
.vertex_spacing
148 && qualifier
.vertex_spacing
!= new_qualifier
.vertex_spacing
) {
149 _mesa_glsl_error(loc
, state
,
150 "conflicting vertex spacing specified");
158 validate_ordering(YYLTYPE
*loc
,
159 _mesa_glsl_parse_state
*state
,
160 const ast_type_qualifier
&qualifier
,
161 const ast_type_qualifier
&new_qualifier
)
163 if (qualifier
.flags
.q
.ordering
&& new_qualifier
.flags
.q
.ordering
164 && qualifier
.ordering
!= new_qualifier
.ordering
) {
165 _mesa_glsl_error(loc
, state
,
166 "conflicting ordering specified");
174 validate_point_mode(MAYBE_UNUSED
const ast_type_qualifier
&qualifier
,
175 MAYBE_UNUSED
const ast_type_qualifier
&new_qualifier
)
177 /* Point mode can only be true if the flag is set. */
178 assert (!qualifier
.flags
.q
.point_mode
|| !new_qualifier
.flags
.q
.point_mode
179 || (qualifier
.point_mode
&& new_qualifier
.point_mode
));
185 * This function merges duplicate layout identifiers.
187 * It deals with duplicates within a single layout qualifier, among multiple
188 * layout qualifiers on a single declaration and on several declarations for
191 * The is_single_layout_merge and is_multiple_layouts_merge parameters are
192 * used to differentiate among them.
195 ast_type_qualifier::merge_qualifier(YYLTYPE
*loc
,
196 _mesa_glsl_parse_state
*state
,
197 const ast_type_qualifier
&q
,
198 bool is_single_layout_merge
,
199 bool is_multiple_layouts_merge
)
202 ast_type_qualifier ubo_mat_mask
;
203 ubo_mat_mask
.flags
.i
= 0;
204 ubo_mat_mask
.flags
.q
.row_major
= 1;
205 ubo_mat_mask
.flags
.q
.column_major
= 1;
207 ast_type_qualifier ubo_layout_mask
;
208 ubo_layout_mask
.flags
.i
= 0;
209 ubo_layout_mask
.flags
.q
.std140
= 1;
210 ubo_layout_mask
.flags
.q
.packed
= 1;
211 ubo_layout_mask
.flags
.q
.shared
= 1;
212 ubo_layout_mask
.flags
.q
.std430
= 1;
214 ast_type_qualifier ubo_binding_mask
;
215 ubo_binding_mask
.flags
.i
= 0;
216 ubo_binding_mask
.flags
.q
.explicit_binding
= 1;
217 ubo_binding_mask
.flags
.q
.explicit_offset
= 1;
219 ast_type_qualifier stream_layout_mask
;
220 stream_layout_mask
.flags
.i
= 0;
221 stream_layout_mask
.flags
.q
.stream
= 1;
223 /* FIXME: We should probably do interface and function param validation
226 ast_type_qualifier input_layout_mask
;
227 input_layout_mask
.flags
.i
= 0;
228 input_layout_mask
.flags
.q
.centroid
= 1;
229 /* Function params can have constant */
230 input_layout_mask
.flags
.q
.constant
= 1;
231 input_layout_mask
.flags
.q
.explicit_component
= 1;
232 input_layout_mask
.flags
.q
.explicit_location
= 1;
233 input_layout_mask
.flags
.q
.flat
= 1;
234 input_layout_mask
.flags
.q
.in
= 1;
235 input_layout_mask
.flags
.q
.invariant
= 1;
236 input_layout_mask
.flags
.q
.noperspective
= 1;
237 input_layout_mask
.flags
.q
.origin_upper_left
= 1;
238 /* Function params 'inout' will set this */
239 input_layout_mask
.flags
.q
.out
= 1;
240 input_layout_mask
.flags
.q
.patch
= 1;
241 input_layout_mask
.flags
.q
.pixel_center_integer
= 1;
242 input_layout_mask
.flags
.q
.precise
= 1;
243 input_layout_mask
.flags
.q
.sample
= 1;
244 input_layout_mask
.flags
.q
.smooth
= 1;
246 /* Uniform block layout qualifiers get to overwrite each
247 * other (rightmost having priority), while all other
248 * qualifiers currently don't allow duplicates.
250 ast_type_qualifier allowed_duplicates_mask
;
251 allowed_duplicates_mask
.flags
.i
=
252 ubo_mat_mask
.flags
.i
|
253 ubo_layout_mask
.flags
.i
|
254 ubo_binding_mask
.flags
.i
;
256 /* Geometry shaders can have several layout qualifiers
257 * assigning different stream values.
259 if (state
->stage
== MESA_SHADER_GEOMETRY
) {
260 allowed_duplicates_mask
.flags
.i
|=
261 stream_layout_mask
.flags
.i
;
264 if (is_single_layout_merge
&& !state
->has_enhanced_layouts() &&
265 (this->flags
.i
& q
.flags
.i
& ~allowed_duplicates_mask
.flags
.i
) != 0) {
266 _mesa_glsl_error(loc
, state
, "duplicate layout qualifiers used");
270 if (is_multiple_layouts_merge
&& !state
->has_420pack_or_es31()) {
271 _mesa_glsl_error(loc
, state
,
272 "duplicate layout(...) qualifiers");
276 if (q
.flags
.q
.prim_type
) {
277 r
&= validate_prim_type(loc
, state
, *this, q
);
278 this->flags
.q
.prim_type
= 1;
279 this->prim_type
= q
.prim_type
;
282 if (q
.flags
.q
.max_vertices
) {
283 if (this->flags
.q
.max_vertices
284 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
285 this->max_vertices
->merge_qualifier(q
.max_vertices
);
287 this->flags
.q
.max_vertices
= 1;
288 this->max_vertices
= q
.max_vertices
;
292 if (q
.subroutine_list
) {
293 if (this->subroutine_list
) {
294 _mesa_glsl_error(loc
, state
,
295 "conflicting subroutine qualifiers used");
297 this->subroutine_list
= q
.subroutine_list
;
301 if (q
.flags
.q
.invocations
) {
302 if (this->flags
.q
.invocations
303 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
304 this->invocations
->merge_qualifier(q
.invocations
);
306 this->flags
.q
.invocations
= 1;
307 this->invocations
= q
.invocations
;
311 if (state
->stage
== MESA_SHADER_GEOMETRY
&&
312 state
->has_explicit_attrib_stream()) {
313 if (!this->flags
.q
.explicit_stream
) {
314 if (q
.flags
.q
.stream
) {
315 this->flags
.q
.stream
= 1;
316 this->stream
= q
.stream
;
317 } else if (!this->flags
.q
.stream
&& this->flags
.q
.out
&&
319 /* Assign default global stream value */
320 this->flags
.q
.stream
= 1;
321 this->stream
= state
->out_qualifier
->stream
;
326 if (state
->has_enhanced_layouts()) {
327 if (!this->flags
.q
.explicit_xfb_buffer
) {
328 if (q
.flags
.q
.xfb_buffer
) {
329 this->flags
.q
.xfb_buffer
= 1;
330 this->xfb_buffer
= q
.xfb_buffer
;
331 } else if (!this->flags
.q
.xfb_buffer
&& this->flags
.q
.out
&&
333 /* Assign global xfb_buffer value */
334 this->flags
.q
.xfb_buffer
= 1;
335 this->xfb_buffer
= state
->out_qualifier
->xfb_buffer
;
339 if (q
.flags
.q
.explicit_xfb_stride
) {
340 this->flags
.q
.xfb_stride
= 1;
341 this->flags
.q
.explicit_xfb_stride
= 1;
342 this->xfb_stride
= q
.xfb_stride
;
346 if (q
.flags
.q
.vertices
) {
347 if (this->flags
.q
.vertices
348 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
349 this->vertices
->merge_qualifier(q
.vertices
);
351 this->flags
.q
.vertices
= 1;
352 this->vertices
= q
.vertices
;
356 if (q
.flags
.q
.vertex_spacing
) {
357 r
&= validate_vertex_spacing(loc
, state
, *this, q
);
358 this->flags
.q
.vertex_spacing
= 1;
359 this->vertex_spacing
= q
.vertex_spacing
;
362 if (q
.flags
.q
.ordering
) {
363 r
&= validate_ordering(loc
, state
, *this, q
);
364 this->flags
.q
.ordering
= 1;
365 this->ordering
= q
.ordering
;
368 if (q
.flags
.q
.point_mode
) {
369 r
&= validate_point_mode(*this, q
);
370 this->flags
.q
.point_mode
= 1;
371 this->point_mode
= q
.point_mode
;
374 if (q
.flags
.q
.early_fragment_tests
)
375 this->flags
.q
.early_fragment_tests
= true;
377 if ((q
.flags
.i
& ubo_mat_mask
.flags
.i
) != 0)
378 this->flags
.i
&= ~ubo_mat_mask
.flags
.i
;
379 if ((q
.flags
.i
& ubo_layout_mask
.flags
.i
) != 0)
380 this->flags
.i
&= ~ubo_layout_mask
.flags
.i
;
382 for (int i
= 0; i
< 3; i
++) {
383 if (q
.flags
.q
.local_size
& (1 << i
)) {
384 if (this->local_size
[i
]
385 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
386 this->local_size
[i
]->merge_qualifier(q
.local_size
[i
]);
388 this->local_size
[i
] = q
.local_size
[i
];
393 if (q
.flags
.q
.local_size_variable
)
394 this->flags
.q
.local_size_variable
= true;
396 this->flags
.i
|= q
.flags
.i
;
398 if (this->flags
.q
.in
&&
399 (this->flags
.i
& ~input_layout_mask
.flags
.i
) != 0) {
400 _mesa_glsl_error(loc
, state
, "invalid input layout qualifier used");
404 if (q
.flags
.q
.explicit_align
)
405 this->align
= q
.align
;
407 if (q
.flags
.q
.explicit_location
)
408 this->location
= q
.location
;
410 if (q
.flags
.q
.explicit_index
)
411 this->index
= q
.index
;
413 if (q
.flags
.q
.explicit_component
)
414 this->component
= q
.component
;
416 if (q
.flags
.q
.explicit_binding
)
417 this->binding
= q
.binding
;
419 if (q
.flags
.q
.explicit_offset
|| q
.flags
.q
.explicit_xfb_offset
)
420 this->offset
= q
.offset
;
422 if (q
.precision
!= ast_precision_none
)
423 this->precision
= q
.precision
;
425 if (q
.flags
.q
.explicit_image_format
) {
426 this->image_format
= q
.image_format
;
427 this->image_base_type
= q
.image_base_type
;
434 ast_type_qualifier::validate_out_qualifier(YYLTYPE
*loc
,
435 _mesa_glsl_parse_state
*state
)
438 ast_type_qualifier valid_out_mask
;
439 valid_out_mask
.flags
.i
= 0;
441 switch (state
->stage
) {
442 case MESA_SHADER_GEOMETRY
:
443 if (this->flags
.q
.prim_type
) {
444 /* Make sure this is a valid output primitive type. */
445 switch (this->prim_type
) {
448 case GL_TRIANGLE_STRIP
:
452 _mesa_glsl_error(loc
, state
, "invalid geometry shader output "
458 valid_out_mask
.flags
.q
.stream
= 1;
459 valid_out_mask
.flags
.q
.explicit_stream
= 1;
460 valid_out_mask
.flags
.q
.explicit_xfb_buffer
= 1;
461 valid_out_mask
.flags
.q
.xfb_buffer
= 1;
462 valid_out_mask
.flags
.q
.explicit_xfb_stride
= 1;
463 valid_out_mask
.flags
.q
.xfb_stride
= 1;
464 valid_out_mask
.flags
.q
.max_vertices
= 1;
465 valid_out_mask
.flags
.q
.prim_type
= 1;
467 case MESA_SHADER_TESS_CTRL
:
468 valid_out_mask
.flags
.q
.vertices
= 1;
469 valid_out_mask
.flags
.q
.explicit_xfb_buffer
= 1;
470 valid_out_mask
.flags
.q
.xfb_buffer
= 1;
471 valid_out_mask
.flags
.q
.explicit_xfb_stride
= 1;
472 valid_out_mask
.flags
.q
.xfb_stride
= 1;
474 case MESA_SHADER_TESS_EVAL
:
475 case MESA_SHADER_VERTEX
:
476 valid_out_mask
.flags
.q
.explicit_xfb_buffer
= 1;
477 valid_out_mask
.flags
.q
.xfb_buffer
= 1;
478 valid_out_mask
.flags
.q
.explicit_xfb_stride
= 1;
479 valid_out_mask
.flags
.q
.xfb_stride
= 1;
481 case MESA_SHADER_FRAGMENT
:
482 valid_out_mask
.flags
.q
.blend_support
= 1;
486 _mesa_glsl_error(loc
, state
,
487 "out layout qualifiers only valid in "
488 "geometry, tessellation, vertex and fragment shaders");
491 /* Generate an error when invalid output layout qualifiers are used. */
492 if ((this->flags
.i
& ~valid_out_mask
.flags
.i
) != 0) {
494 _mesa_glsl_error(loc
, state
, "invalid output layout qualifiers used");
501 ast_type_qualifier::merge_into_out_qualifier(YYLTYPE
*loc
,
502 _mesa_glsl_parse_state
*state
,
505 const bool r
= state
->out_qualifier
->merge_qualifier(loc
, state
,
508 switch (state
->stage
) {
509 case MESA_SHADER_GEOMETRY
:
510 /* Allow future assignments of global out's stream id value */
511 state
->out_qualifier
->flags
.q
.explicit_stream
= 0;
513 case MESA_SHADER_TESS_CTRL
:
514 node
= new(state
->linalloc
) ast_tcs_output_layout(*loc
);
520 /* Allow future assignments of global out's */
521 state
->out_qualifier
->flags
.q
.explicit_xfb_buffer
= 0;
522 state
->out_qualifier
->flags
.q
.explicit_xfb_stride
= 0;
528 ast_type_qualifier::validate_in_qualifier(YYLTYPE
*loc
,
529 _mesa_glsl_parse_state
*state
)
532 ast_type_qualifier valid_in_mask
;
533 valid_in_mask
.flags
.i
= 0;
535 switch (state
->stage
) {
536 case MESA_SHADER_TESS_EVAL
:
537 if (this->flags
.q
.prim_type
) {
538 /* Make sure this is a valid input primitive type. */
539 switch (this->prim_type
) {
546 _mesa_glsl_error(loc
, state
,
547 "invalid tessellation evaluation "
548 "shader input primitive type");
553 valid_in_mask
.flags
.q
.prim_type
= 1;
554 valid_in_mask
.flags
.q
.vertex_spacing
= 1;
555 valid_in_mask
.flags
.q
.ordering
= 1;
556 valid_in_mask
.flags
.q
.point_mode
= 1;
558 case MESA_SHADER_GEOMETRY
:
559 if (this->flags
.q
.prim_type
) {
560 /* Make sure this is a valid input primitive type. */
561 switch (this->prim_type
) {
564 case GL_LINES_ADJACENCY
:
566 case GL_TRIANGLES_ADJACENCY
:
570 _mesa_glsl_error(loc
, state
,
571 "invalid geometry shader input primitive type");
576 valid_in_mask
.flags
.q
.prim_type
= 1;
577 valid_in_mask
.flags
.q
.invocations
= 1;
579 case MESA_SHADER_FRAGMENT
:
580 valid_in_mask
.flags
.q
.early_fragment_tests
= 1;
581 valid_in_mask
.flags
.q
.inner_coverage
= 1;
582 valid_in_mask
.flags
.q
.post_depth_coverage
= 1;
584 case MESA_SHADER_COMPUTE
:
585 valid_in_mask
.flags
.q
.local_size
= 7;
586 valid_in_mask
.flags
.q
.local_size_variable
= 1;
590 _mesa_glsl_error(loc
, state
,
591 "input layout qualifiers only valid in "
592 "geometry, tessellation, fragment and compute shaders");
596 /* Generate an error when invalid input layout qualifiers are used. */
597 if ((this->flags
.i
& ~valid_in_mask
.flags
.i
) != 0) {
599 _mesa_glsl_error(loc
, state
, "invalid input layout qualifiers used");
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.
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(*state
->in_qualifier
, *this);
615 ast_type_qualifier::merge_into_in_qualifier(YYLTYPE
*loc
,
616 _mesa_glsl_parse_state
*state
,
620 void *lin_ctx
= state
->linalloc
;
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.
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
);
630 r
= state
->in_qualifier
->merge_qualifier(loc
, state
, *this, false);
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;
637 if (state
->in_qualifier
->flags
.q
.inner_coverage
) {
638 state
->fs_inner_coverage
= true;
639 state
->in_qualifier
->flags
.q
.inner_coverage
= false;
642 if (state
->in_qualifier
->flags
.q
.post_depth_coverage
) {
643 state
->fs_post_depth_coverage
= true;
644 state
->in_qualifier
->flags
.q
.post_depth_coverage
= false;
647 if (state
->fs_inner_coverage
&& state
->fs_post_depth_coverage
) {
648 _mesa_glsl_error(loc
, state
,
649 "inner_coverage & post_depth_coverage layout qualifiers "
650 "are mutally exclusives");
654 /* We allow the creation of multiple cs_input_layout nodes. Coherence among
655 * all existing nodes is checked later, when the AST node is transformed
658 if (state
->in_qualifier
->flags
.q
.local_size
) {
659 node
= new(lin_ctx
) ast_cs_input_layout(*loc
,
660 state
->in_qualifier
->local_size
);
661 state
->in_qualifier
->flags
.q
.local_size
= 0;
662 for (int i
= 0; i
< 3; i
++)
663 state
->in_qualifier
->local_size
[i
] = NULL
;
666 if (state
->in_qualifier
->flags
.q
.local_size_variable
) {
667 state
->cs_input_local_size_variable_specified
= true;
668 state
->in_qualifier
->flags
.q
.local_size_variable
= false;
675 ast_type_qualifier::push_to_global(YYLTYPE
*loc
,
676 _mesa_glsl_parse_state
*state
)
678 if (this->flags
.q
.xfb_stride
) {
679 this->flags
.q
.xfb_stride
= 0;
682 if (process_qualifier_constant(state
, loc
, "xfb_buffer",
683 this->xfb_buffer
, &buff_idx
)) {
684 if (state
->out_qualifier
->out_xfb_stride
[buff_idx
]) {
685 state
->out_qualifier
->out_xfb_stride
[buff_idx
]->merge_qualifier(
686 new(state
->linalloc
) ast_layout_expression(*loc
,
689 state
->out_qualifier
->out_xfb_stride
[buff_idx
] =
690 new(state
->linalloc
) ast_layout_expression(*loc
,
700 * Check if the current type qualifier has any illegal flags.
702 * If so, print an error message, followed by a list of illegal flags.
704 * \param message The error message to print.
705 * \param allowed_flags A list of valid flags.
708 ast_type_qualifier::validate_flags(YYLTYPE
*loc
,
709 _mesa_glsl_parse_state
*state
,
710 const ast_type_qualifier
&allowed_flags
,
711 const char *message
, const char *name
)
713 ast_type_qualifier bad
;
714 bad
.flags
.i
= this->flags
.i
& ~allowed_flags
.flags
.i
;
715 if (bad
.flags
.i
== 0)
718 _mesa_glsl_error(loc
, state
,
720 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
721 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
722 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
724 bad
.flags
.q
.invariant
? " invariant" : "",
725 bad
.flags
.q
.precise
? " precise" : "",
726 bad
.flags
.q
.constant
? " constant" : "",
727 bad
.flags
.q
.attribute
? " attribute" : "",
728 bad
.flags
.q
.varying
? " varying" : "",
729 bad
.flags
.q
.in
? " in" : "",
730 bad
.flags
.q
.out
? " out" : "",
731 bad
.flags
.q
.centroid
? " centroid" : "",
732 bad
.flags
.q
.sample
? " sample" : "",
733 bad
.flags
.q
.patch
? " patch" : "",
734 bad
.flags
.q
.uniform
? " uniform" : "",
735 bad
.flags
.q
.buffer
? " buffer" : "",
736 bad
.flags
.q
.shared_storage
? " shared_storage" : "",
737 bad
.flags
.q
.smooth
? " smooth" : "",
738 bad
.flags
.q
.flat
? " flat" : "",
739 bad
.flags
.q
.noperspective
? " noperspective" : "",
740 bad
.flags
.q
.origin_upper_left
? " origin_upper_left" : "",
741 bad
.flags
.q
.pixel_center_integer
? " pixel_center_integer" : "",
742 bad
.flags
.q
.explicit_align
? " align" : "",
743 bad
.flags
.q
.explicit_component
? " component" : "",
744 bad
.flags
.q
.explicit_location
? " location" : "",
745 bad
.flags
.q
.explicit_index
? " index" : "",
746 bad
.flags
.q
.explicit_binding
? " binding" : "",
747 bad
.flags
.q
.explicit_offset
? " offset" : "",
748 bad
.flags
.q
.depth_type
? " depth_type" : "",
749 bad
.flags
.q
.std140
? " std140" : "",
750 bad
.flags
.q
.std430
? " std430" : "",
751 bad
.flags
.q
.shared
? " shared" : "",
752 bad
.flags
.q
.packed
? " packed" : "",
753 bad
.flags
.q
.column_major
? " column_major" : "",
754 bad
.flags
.q
.row_major
? " row_major" : "",
755 bad
.flags
.q
.prim_type
? " prim_type" : "",
756 bad
.flags
.q
.max_vertices
? " max_vertices" : "",
757 bad
.flags
.q
.local_size
? " local_size" : "",
758 bad
.flags
.q
.local_size_variable
? " local_size_variable" : "",
759 bad
.flags
.q
.early_fragment_tests
? " early_fragment_tests" : "",
760 bad
.flags
.q
.explicit_image_format
? " image_format" : "",
761 bad
.flags
.q
.coherent
? " coherent" : "",
762 bad
.flags
.q
._volatile
? " _volatile" : "",
763 bad
.flags
.q
.restrict_flag
? " restrict_flag" : "",
764 bad
.flags
.q
.read_only
? " read_only" : "",
765 bad
.flags
.q
.write_only
? " write_only" : "",
766 bad
.flags
.q
.invocations
? " invocations" : "",
767 bad
.flags
.q
.stream
? " stream" : "",
768 bad
.flags
.q
.explicit_stream
? " stream" : "",
769 bad
.flags
.q
.explicit_xfb_offset
? " xfb_offset" : "",
770 bad
.flags
.q
.xfb_buffer
? " xfb_buffer" : "",
771 bad
.flags
.q
.explicit_xfb_buffer
? " xfb_buffer" : "",
772 bad
.flags
.q
.xfb_stride
? " xfb_stride" : "",
773 bad
.flags
.q
.explicit_xfb_stride
? " xfb_stride" : "",
774 bad
.flags
.q
.vertex_spacing
? " vertex_spacing" : "",
775 bad
.flags
.q
.ordering
? " ordering" : "",
776 bad
.flags
.q
.point_mode
? " point_mode" : "",
777 bad
.flags
.q
.vertices
? " vertices" : "",
778 bad
.flags
.q
.subroutine
? " subroutine" : "",
779 bad
.flags
.q
.blend_support
? " blend_support" : "",
780 bad
.flags
.q
.inner_coverage
? " inner_coverage" : "",
781 bad
.flags
.q
.post_depth_coverage
? " post_depth_coverage" : "");
786 ast_layout_expression::process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
787 const char *qual_indentifier
,
792 bool first_pass
= true;
798 for (exec_node
*node
= layout_const_expressions
.get_head_raw();
799 !node
->is_tail_sentinel(); node
= node
->next
) {
801 exec_list dummy_instructions
;
802 ast_node
*const_expression
= exec_node_data(ast_node
, node
, link
);
804 ir_rvalue
*const ir
= const_expression
->hir(&dummy_instructions
, state
);
806 ir_constant
*const const_int
= ir
->constant_expression_value();
807 if (const_int
== NULL
|| !const_int
->type
->is_integer()) {
808 YYLTYPE loc
= const_expression
->get_location();
809 _mesa_glsl_error(&loc
, state
, "%s must be an integral constant "
810 "expression", qual_indentifier
);
814 if (const_int
->value
.i
[0] < min_value
) {
815 YYLTYPE loc
= const_expression
->get_location();
816 _mesa_glsl_error(&loc
, state
, "%s layout qualifier is invalid "
817 "(%d < %d)", qual_indentifier
,
818 const_int
->value
.i
[0], min_value
);
822 if (!first_pass
&& *value
!= const_int
->value
.u
[0]) {
823 YYLTYPE loc
= const_expression
->get_location();
824 _mesa_glsl_error(&loc
, state
, "%s layout qualifier does not "
825 "match previous declaration (%d vs %d)",
826 qual_indentifier
, *value
, const_int
->value
.i
[0]);
830 *value
= const_int
->value
.u
[0];
833 /* If the location is const (and we've verified that
834 * it is) then no instructions should have been emitted
835 * when we converted it to HIR. If they were emitted,
836 * then either the location isn't const after all, or
837 * we are emitting unnecessary instructions.
839 assert(dummy_instructions
.is_empty());
846 process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
848 const char *qual_indentifier
,
849 ast_expression
*const_expression
,
852 exec_list dummy_instructions
;
854 if (const_expression
== NULL
) {
859 ir_rvalue
*const ir
= const_expression
->hir(&dummy_instructions
, state
);
861 ir_constant
*const const_int
= ir
->constant_expression_value();
862 if (const_int
== NULL
|| !const_int
->type
->is_integer()) {
863 _mesa_glsl_error(loc
, state
, "%s must be an integral constant "
864 "expression", qual_indentifier
);
868 if (const_int
->value
.i
[0] < 0) {
869 _mesa_glsl_error(loc
, state
, "%s layout qualifier is invalid (%d < 0)",
870 qual_indentifier
, const_int
->value
.u
[0]);
874 /* If the location is const (and we've verified that
875 * it is) then no instructions should have been emitted
876 * when we converted it to HIR. If they were emitted,
877 * then either the location isn't const after all, or
878 * we are emitting unnecessary instructions.
880 assert(dummy_instructions
.is_empty());
882 *value
= const_int
->value
.u
[0];