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
.bindless_sampler
73 || this->flags
.q
.bindless_image
74 || this->flags
.q
.bound_sampler
75 || this->flags
.q
.bound_image
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
;
90 ast_type_qualifier::has_storage() const
92 return this->flags
.q
.constant
93 || this->flags
.q
.attribute
94 || this->flags
.q
.varying
97 || this->flags
.q
.uniform
98 || this->flags
.q
.buffer
99 || this->flags
.q
.shared_storage
;
103 ast_type_qualifier::has_auxiliary_storage() const
105 return this->flags
.q
.centroid
106 || this->flags
.q
.sample
107 || this->flags
.q
.patch
;
110 bool ast_type_qualifier::has_memory() const
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
;
119 bool ast_type_qualifier::is_subroutine_decl() const
121 return this->flags
.q
.subroutine
&& !this->subroutine_list
;
125 validate_prim_type(YYLTYPE
*loc
,
126 _mesa_glsl_parse_state
*state
,
127 const ast_type_qualifier
&qualifier
,
128 const ast_type_qualifier
&new_qualifier
)
130 /* Input layout qualifiers can be specified multiple
131 * times in separate declarations, as long as they match.
133 if (qualifier
.flags
.q
.prim_type
&& new_qualifier
.flags
.q
.prim_type
134 && qualifier
.prim_type
!= new_qualifier
.prim_type
) {
135 _mesa_glsl_error(loc
, state
,
136 "conflicting input primitive %s specified",
137 state
->stage
== MESA_SHADER_GEOMETRY
?
146 validate_vertex_spacing(YYLTYPE
*loc
,
147 _mesa_glsl_parse_state
*state
,
148 const ast_type_qualifier
&qualifier
,
149 const ast_type_qualifier
&new_qualifier
)
151 if (qualifier
.flags
.q
.vertex_spacing
&& new_qualifier
.flags
.q
.vertex_spacing
152 && qualifier
.vertex_spacing
!= new_qualifier
.vertex_spacing
) {
153 _mesa_glsl_error(loc
, state
,
154 "conflicting vertex spacing specified");
162 validate_ordering(YYLTYPE
*loc
,
163 _mesa_glsl_parse_state
*state
,
164 const ast_type_qualifier
&qualifier
,
165 const ast_type_qualifier
&new_qualifier
)
167 if (qualifier
.flags
.q
.ordering
&& new_qualifier
.flags
.q
.ordering
168 && qualifier
.ordering
!= new_qualifier
.ordering
) {
169 _mesa_glsl_error(loc
, state
,
170 "conflicting ordering specified");
178 validate_point_mode(MAYBE_UNUSED
const ast_type_qualifier
&qualifier
,
179 MAYBE_UNUSED
const ast_type_qualifier
&new_qualifier
)
181 /* Point mode can only be true if the flag is set. */
182 assert (!qualifier
.flags
.q
.point_mode
|| !new_qualifier
.flags
.q
.point_mode
183 || (qualifier
.point_mode
&& new_qualifier
.point_mode
));
189 merge_bindless_qualifier(_mesa_glsl_parse_state
*state
)
191 if (state
->default_uniform_qualifier
->flags
.q
.bindless_sampler
) {
192 state
->bindless_sampler_specified
= true;
193 state
->default_uniform_qualifier
->flags
.q
.bindless_sampler
= false;
196 if (state
->default_uniform_qualifier
->flags
.q
.bindless_image
) {
197 state
->bindless_image_specified
= true;
198 state
->default_uniform_qualifier
->flags
.q
.bindless_image
= false;
201 if (state
->default_uniform_qualifier
->flags
.q
.bound_sampler
) {
202 state
->bound_sampler_specified
= true;
203 state
->default_uniform_qualifier
->flags
.q
.bound_sampler
= false;
206 if (state
->default_uniform_qualifier
->flags
.q
.bound_image
) {
207 state
->bound_image_specified
= true;
208 state
->default_uniform_qualifier
->flags
.q
.bound_image
= false;
213 * This function merges duplicate layout identifiers.
215 * It deals with duplicates within a single layout qualifier, among multiple
216 * layout qualifiers on a single declaration and on several declarations for
219 * The is_single_layout_merge and is_multiple_layouts_merge parameters are
220 * used to differentiate among them.
223 ast_type_qualifier::merge_qualifier(YYLTYPE
*loc
,
224 _mesa_glsl_parse_state
*state
,
225 const ast_type_qualifier
&q
,
226 bool is_single_layout_merge
,
227 bool is_multiple_layouts_merge
)
230 ast_type_qualifier ubo_mat_mask
;
231 ubo_mat_mask
.flags
.i
= 0;
232 ubo_mat_mask
.flags
.q
.row_major
= 1;
233 ubo_mat_mask
.flags
.q
.column_major
= 1;
235 ast_type_qualifier ubo_layout_mask
;
236 ubo_layout_mask
.flags
.i
= 0;
237 ubo_layout_mask
.flags
.q
.std140
= 1;
238 ubo_layout_mask
.flags
.q
.packed
= 1;
239 ubo_layout_mask
.flags
.q
.shared
= 1;
240 ubo_layout_mask
.flags
.q
.std430
= 1;
242 ast_type_qualifier ubo_binding_mask
;
243 ubo_binding_mask
.flags
.i
= 0;
244 ubo_binding_mask
.flags
.q
.explicit_binding
= 1;
245 ubo_binding_mask
.flags
.q
.explicit_offset
= 1;
247 ast_type_qualifier stream_layout_mask
;
248 stream_layout_mask
.flags
.i
= 0;
249 stream_layout_mask
.flags
.q
.stream
= 1;
251 /* FIXME: We should probably do interface and function param validation
254 ast_type_qualifier input_layout_mask
;
255 input_layout_mask
.flags
.i
= 0;
256 input_layout_mask
.flags
.q
.centroid
= 1;
257 /* Function params can have constant */
258 input_layout_mask
.flags
.q
.constant
= 1;
259 input_layout_mask
.flags
.q
.explicit_component
= 1;
260 input_layout_mask
.flags
.q
.explicit_location
= 1;
261 input_layout_mask
.flags
.q
.flat
= 1;
262 input_layout_mask
.flags
.q
.in
= 1;
263 input_layout_mask
.flags
.q
.invariant
= 1;
264 input_layout_mask
.flags
.q
.noperspective
= 1;
265 input_layout_mask
.flags
.q
.origin_upper_left
= 1;
266 /* Function params 'inout' will set this */
267 input_layout_mask
.flags
.q
.out
= 1;
268 input_layout_mask
.flags
.q
.patch
= 1;
269 input_layout_mask
.flags
.q
.pixel_center_integer
= 1;
270 input_layout_mask
.flags
.q
.precise
= 1;
271 input_layout_mask
.flags
.q
.sample
= 1;
272 input_layout_mask
.flags
.q
.smooth
= 1;
274 if (state
->has_bindless()) {
275 /* Allow to use image qualifiers with shader inputs/outputs. */
276 input_layout_mask
.flags
.q
.coherent
= 1;
277 input_layout_mask
.flags
.q
._volatile
= 1;
278 input_layout_mask
.flags
.q
.restrict_flag
= 1;
279 input_layout_mask
.flags
.q
.read_only
= 1;
280 input_layout_mask
.flags
.q
.write_only
= 1;
281 input_layout_mask
.flags
.q
.explicit_image_format
= 1;
284 /* Uniform block layout qualifiers get to overwrite each
285 * other (rightmost having priority), while all other
286 * qualifiers currently don't allow duplicates.
288 ast_type_qualifier allowed_duplicates_mask
;
289 allowed_duplicates_mask
.flags
.i
=
290 ubo_mat_mask
.flags
.i
|
291 ubo_layout_mask
.flags
.i
|
292 ubo_binding_mask
.flags
.i
;
294 /* Geometry shaders can have several layout qualifiers
295 * assigning different stream values.
297 if (state
->stage
== MESA_SHADER_GEOMETRY
) {
298 allowed_duplicates_mask
.flags
.i
|=
299 stream_layout_mask
.flags
.i
;
302 if (is_single_layout_merge
&& !state
->has_enhanced_layouts() &&
303 (this->flags
.i
& q
.flags
.i
& ~allowed_duplicates_mask
.flags
.i
) != 0) {
304 _mesa_glsl_error(loc
, state
, "duplicate layout qualifiers used");
308 if (is_multiple_layouts_merge
&& !state
->has_420pack_or_es31()) {
309 _mesa_glsl_error(loc
, state
,
310 "duplicate layout(...) qualifiers");
314 if (q
.flags
.q
.prim_type
) {
315 r
&= validate_prim_type(loc
, state
, *this, q
);
316 this->flags
.q
.prim_type
= 1;
317 this->prim_type
= q
.prim_type
;
320 if (q
.flags
.q
.max_vertices
) {
321 if (this->flags
.q
.max_vertices
322 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
323 this->max_vertices
->merge_qualifier(q
.max_vertices
);
325 this->flags
.q
.max_vertices
= 1;
326 this->max_vertices
= q
.max_vertices
;
330 if (q
.subroutine_list
) {
331 if (this->subroutine_list
) {
332 _mesa_glsl_error(loc
, state
,
333 "conflicting subroutine qualifiers used");
335 this->subroutine_list
= q
.subroutine_list
;
339 if (q
.flags
.q
.invocations
) {
340 if (this->flags
.q
.invocations
341 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
342 this->invocations
->merge_qualifier(q
.invocations
);
344 this->flags
.q
.invocations
= 1;
345 this->invocations
= q
.invocations
;
349 if (state
->stage
== MESA_SHADER_GEOMETRY
&&
350 state
->has_explicit_attrib_stream()) {
351 if (!this->flags
.q
.explicit_stream
) {
352 if (q
.flags
.q
.stream
) {
353 this->flags
.q
.stream
= 1;
354 this->stream
= q
.stream
;
355 } else if (!this->flags
.q
.stream
&& this->flags
.q
.out
&&
357 /* Assign default global stream value */
358 this->flags
.q
.stream
= 1;
359 this->stream
= state
->out_qualifier
->stream
;
364 if (state
->has_enhanced_layouts()) {
365 if (!this->flags
.q
.explicit_xfb_buffer
) {
366 if (q
.flags
.q
.xfb_buffer
) {
367 this->flags
.q
.xfb_buffer
= 1;
368 this->xfb_buffer
= q
.xfb_buffer
;
369 } else if (!this->flags
.q
.xfb_buffer
&& this->flags
.q
.out
&&
371 /* Assign global xfb_buffer value */
372 this->flags
.q
.xfb_buffer
= 1;
373 this->xfb_buffer
= state
->out_qualifier
->xfb_buffer
;
377 if (q
.flags
.q
.explicit_xfb_stride
) {
378 this->flags
.q
.xfb_stride
= 1;
379 this->flags
.q
.explicit_xfb_stride
= 1;
380 this->xfb_stride
= q
.xfb_stride
;
384 if (q
.flags
.q
.vertices
) {
385 if (this->flags
.q
.vertices
386 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
387 this->vertices
->merge_qualifier(q
.vertices
);
389 this->flags
.q
.vertices
= 1;
390 this->vertices
= q
.vertices
;
394 if (q
.flags
.q
.vertex_spacing
) {
395 r
&= validate_vertex_spacing(loc
, state
, *this, q
);
396 this->flags
.q
.vertex_spacing
= 1;
397 this->vertex_spacing
= q
.vertex_spacing
;
400 if (q
.flags
.q
.ordering
) {
401 r
&= validate_ordering(loc
, state
, *this, q
);
402 this->flags
.q
.ordering
= 1;
403 this->ordering
= q
.ordering
;
406 if (q
.flags
.q
.point_mode
) {
407 r
&= validate_point_mode(*this, q
);
408 this->flags
.q
.point_mode
= 1;
409 this->point_mode
= q
.point_mode
;
412 if (q
.flags
.q
.early_fragment_tests
)
413 this->flags
.q
.early_fragment_tests
= true;
415 if ((q
.flags
.i
& ubo_mat_mask
.flags
.i
) != 0)
416 this->flags
.i
&= ~ubo_mat_mask
.flags
.i
;
417 if ((q
.flags
.i
& ubo_layout_mask
.flags
.i
) != 0)
418 this->flags
.i
&= ~ubo_layout_mask
.flags
.i
;
420 for (int i
= 0; i
< 3; i
++) {
421 if (q
.flags
.q
.local_size
& (1 << i
)) {
422 if (this->local_size
[i
]
423 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
424 this->local_size
[i
]->merge_qualifier(q
.local_size
[i
]);
426 this->local_size
[i
] = q
.local_size
[i
];
431 if (q
.flags
.q
.local_size_variable
)
432 this->flags
.q
.local_size_variable
= true;
434 if (q
.flags
.q
.bindless_sampler
)
435 this->flags
.q
.bindless_sampler
= true;
437 if (q
.flags
.q
.bindless_image
)
438 this->flags
.q
.bindless_image
= true;
440 if (q
.flags
.q
.bound_sampler
)
441 this->flags
.q
.bound_sampler
= true;
443 if (q
.flags
.q
.bound_image
)
444 this->flags
.q
.bound_image
= true;
446 this->flags
.i
|= q
.flags
.i
;
448 if (this->flags
.q
.in
&&
449 (this->flags
.i
& ~input_layout_mask
.flags
.i
) != 0) {
450 _mesa_glsl_error(loc
, state
, "invalid input layout qualifier used");
454 if (q
.flags
.q
.explicit_align
)
455 this->align
= q
.align
;
457 if (q
.flags
.q
.explicit_location
)
458 this->location
= q
.location
;
460 if (q
.flags
.q
.explicit_index
)
461 this->index
= q
.index
;
463 if (q
.flags
.q
.explicit_component
)
464 this->component
= q
.component
;
466 if (q
.flags
.q
.explicit_binding
)
467 this->binding
= q
.binding
;
469 if (q
.flags
.q
.explicit_offset
|| q
.flags
.q
.explicit_xfb_offset
)
470 this->offset
= q
.offset
;
472 if (q
.precision
!= ast_precision_none
)
473 this->precision
= q
.precision
;
475 if (q
.flags
.q
.explicit_image_format
) {
476 this->image_format
= q
.image_format
;
477 this->image_base_type
= q
.image_base_type
;
480 if (q
.flags
.q
.bindless_sampler
||
481 q
.flags
.q
.bindless_image
||
482 q
.flags
.q
.bound_sampler
||
483 q
.flags
.q
.bound_image
)
484 merge_bindless_qualifier(state
);
490 ast_type_qualifier::validate_out_qualifier(YYLTYPE
*loc
,
491 _mesa_glsl_parse_state
*state
)
494 ast_type_qualifier valid_out_mask
;
495 valid_out_mask
.flags
.i
= 0;
497 switch (state
->stage
) {
498 case MESA_SHADER_GEOMETRY
:
499 if (this->flags
.q
.prim_type
) {
500 /* Make sure this is a valid output primitive type. */
501 switch (this->prim_type
) {
504 case GL_TRIANGLE_STRIP
:
508 _mesa_glsl_error(loc
, state
, "invalid geometry shader output "
514 valid_out_mask
.flags
.q
.stream
= 1;
515 valid_out_mask
.flags
.q
.explicit_stream
= 1;
516 valid_out_mask
.flags
.q
.explicit_xfb_buffer
= 1;
517 valid_out_mask
.flags
.q
.xfb_buffer
= 1;
518 valid_out_mask
.flags
.q
.explicit_xfb_stride
= 1;
519 valid_out_mask
.flags
.q
.xfb_stride
= 1;
520 valid_out_mask
.flags
.q
.max_vertices
= 1;
521 valid_out_mask
.flags
.q
.prim_type
= 1;
523 case MESA_SHADER_TESS_CTRL
:
524 valid_out_mask
.flags
.q
.vertices
= 1;
525 valid_out_mask
.flags
.q
.explicit_xfb_buffer
= 1;
526 valid_out_mask
.flags
.q
.xfb_buffer
= 1;
527 valid_out_mask
.flags
.q
.explicit_xfb_stride
= 1;
528 valid_out_mask
.flags
.q
.xfb_stride
= 1;
530 case MESA_SHADER_TESS_EVAL
:
531 case MESA_SHADER_VERTEX
:
532 valid_out_mask
.flags
.q
.explicit_xfb_buffer
= 1;
533 valid_out_mask
.flags
.q
.xfb_buffer
= 1;
534 valid_out_mask
.flags
.q
.explicit_xfb_stride
= 1;
535 valid_out_mask
.flags
.q
.xfb_stride
= 1;
537 case MESA_SHADER_FRAGMENT
:
538 valid_out_mask
.flags
.q
.blend_support
= 1;
542 _mesa_glsl_error(loc
, state
,
543 "out layout qualifiers only valid in "
544 "geometry, tessellation, vertex and fragment shaders");
547 /* Generate an error when invalid output layout qualifiers are used. */
548 if ((this->flags
.i
& ~valid_out_mask
.flags
.i
) != 0) {
550 _mesa_glsl_error(loc
, state
, "invalid output layout qualifiers used");
557 ast_type_qualifier::merge_into_out_qualifier(YYLTYPE
*loc
,
558 _mesa_glsl_parse_state
*state
,
561 const bool r
= state
->out_qualifier
->merge_qualifier(loc
, state
,
564 switch (state
->stage
) {
565 case MESA_SHADER_GEOMETRY
:
566 /* Allow future assignments of global out's stream id value */
567 state
->out_qualifier
->flags
.q
.explicit_stream
= 0;
569 case MESA_SHADER_TESS_CTRL
:
570 node
= new(state
->linalloc
) ast_tcs_output_layout(*loc
);
576 /* Allow future assignments of global out's */
577 state
->out_qualifier
->flags
.q
.explicit_xfb_buffer
= 0;
578 state
->out_qualifier
->flags
.q
.explicit_xfb_stride
= 0;
584 ast_type_qualifier::validate_in_qualifier(YYLTYPE
*loc
,
585 _mesa_glsl_parse_state
*state
)
588 ast_type_qualifier valid_in_mask
;
589 valid_in_mask
.flags
.i
= 0;
591 switch (state
->stage
) {
592 case MESA_SHADER_TESS_EVAL
:
593 if (this->flags
.q
.prim_type
) {
594 /* Make sure this is a valid input primitive type. */
595 switch (this->prim_type
) {
602 _mesa_glsl_error(loc
, state
,
603 "invalid tessellation evaluation "
604 "shader input primitive type");
609 valid_in_mask
.flags
.q
.prim_type
= 1;
610 valid_in_mask
.flags
.q
.vertex_spacing
= 1;
611 valid_in_mask
.flags
.q
.ordering
= 1;
612 valid_in_mask
.flags
.q
.point_mode
= 1;
614 case MESA_SHADER_GEOMETRY
:
615 if (this->flags
.q
.prim_type
) {
616 /* Make sure this is a valid input primitive type. */
617 switch (this->prim_type
) {
620 case GL_LINES_ADJACENCY
:
622 case GL_TRIANGLES_ADJACENCY
:
626 _mesa_glsl_error(loc
, state
,
627 "invalid geometry shader input primitive type");
632 valid_in_mask
.flags
.q
.prim_type
= 1;
633 valid_in_mask
.flags
.q
.invocations
= 1;
635 case MESA_SHADER_FRAGMENT
:
636 valid_in_mask
.flags
.q
.early_fragment_tests
= 1;
637 valid_in_mask
.flags
.q
.inner_coverage
= 1;
638 valid_in_mask
.flags
.q
.post_depth_coverage
= 1;
640 case MESA_SHADER_COMPUTE
:
641 valid_in_mask
.flags
.q
.local_size
= 7;
642 valid_in_mask
.flags
.q
.local_size_variable
= 1;
646 _mesa_glsl_error(loc
, state
,
647 "input layout qualifiers only valid in "
648 "geometry, tessellation, fragment and compute shaders");
652 /* Generate an error when invalid input layout qualifiers are used. */
653 if ((this->flags
.i
& ~valid_in_mask
.flags
.i
) != 0) {
655 _mesa_glsl_error(loc
, state
, "invalid input layout qualifiers used");
658 /* The checks below are also performed when merging but we want to spit an
659 * error against the default global input qualifier as soon as we can, with
660 * the closest error location in the shader.
662 r
&= validate_prim_type(loc
, state
, *state
->in_qualifier
, *this);
663 r
&= validate_vertex_spacing(loc
, state
, *state
->in_qualifier
, *this);
664 r
&= validate_ordering(loc
, state
, *state
->in_qualifier
, *this);
665 r
&= validate_point_mode(*state
->in_qualifier
, *this);
671 ast_type_qualifier::merge_into_in_qualifier(YYLTYPE
*loc
,
672 _mesa_glsl_parse_state
*state
,
676 void *lin_ctx
= state
->linalloc
;
678 /* We create the gs_input_layout node before merging so, in the future, no
679 * more repeated nodes will be created as we will have the flag set.
681 if (state
->stage
== MESA_SHADER_GEOMETRY
682 && this->flags
.q
.prim_type
&& !state
->in_qualifier
->flags
.q
.prim_type
) {
683 node
= new(lin_ctx
) ast_gs_input_layout(*loc
, this->prim_type
);
686 r
= state
->in_qualifier
->merge_qualifier(loc
, state
, *this, false);
688 if (state
->in_qualifier
->flags
.q
.early_fragment_tests
) {
689 state
->fs_early_fragment_tests
= true;
690 state
->in_qualifier
->flags
.q
.early_fragment_tests
= false;
693 if (state
->in_qualifier
->flags
.q
.inner_coverage
) {
694 state
->fs_inner_coverage
= true;
695 state
->in_qualifier
->flags
.q
.inner_coverage
= false;
698 if (state
->in_qualifier
->flags
.q
.post_depth_coverage
) {
699 state
->fs_post_depth_coverage
= true;
700 state
->in_qualifier
->flags
.q
.post_depth_coverage
= false;
703 if (state
->fs_inner_coverage
&& state
->fs_post_depth_coverage
) {
704 _mesa_glsl_error(loc
, state
,
705 "inner_coverage & post_depth_coverage layout qualifiers "
706 "are mutally exclusives");
710 /* We allow the creation of multiple cs_input_layout nodes. Coherence among
711 * all existing nodes is checked later, when the AST node is transformed
714 if (state
->in_qualifier
->flags
.q
.local_size
) {
715 node
= new(lin_ctx
) ast_cs_input_layout(*loc
,
716 state
->in_qualifier
->local_size
);
717 state
->in_qualifier
->flags
.q
.local_size
= 0;
718 for (int i
= 0; i
< 3; i
++)
719 state
->in_qualifier
->local_size
[i
] = NULL
;
722 if (state
->in_qualifier
->flags
.q
.local_size_variable
) {
723 state
->cs_input_local_size_variable_specified
= true;
724 state
->in_qualifier
->flags
.q
.local_size_variable
= false;
731 ast_type_qualifier::push_to_global(YYLTYPE
*loc
,
732 _mesa_glsl_parse_state
*state
)
734 if (this->flags
.q
.xfb_stride
) {
735 this->flags
.q
.xfb_stride
= 0;
738 if (process_qualifier_constant(state
, loc
, "xfb_buffer",
739 this->xfb_buffer
, &buff_idx
)) {
740 if (state
->out_qualifier
->out_xfb_stride
[buff_idx
]) {
741 state
->out_qualifier
->out_xfb_stride
[buff_idx
]->merge_qualifier(
742 new(state
->linalloc
) ast_layout_expression(*loc
,
745 state
->out_qualifier
->out_xfb_stride
[buff_idx
] =
746 new(state
->linalloc
) ast_layout_expression(*loc
,
756 * Check if the current type qualifier has any illegal flags.
758 * If so, print an error message, followed by a list of illegal flags.
760 * \param message The error message to print.
761 * \param allowed_flags A list of valid flags.
764 ast_type_qualifier::validate_flags(YYLTYPE
*loc
,
765 _mesa_glsl_parse_state
*state
,
766 const ast_type_qualifier
&allowed_flags
,
767 const char *message
, const char *name
)
769 ast_type_qualifier bad
;
770 bad
.flags
.i
= this->flags
.i
& ~allowed_flags
.flags
.i
;
771 if (bad
.flags
.i
== 0)
774 _mesa_glsl_error(loc
, state
,
776 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
777 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
778 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
780 bad
.flags
.q
.invariant
? " invariant" : "",
781 bad
.flags
.q
.precise
? " precise" : "",
782 bad
.flags
.q
.constant
? " constant" : "",
783 bad
.flags
.q
.attribute
? " attribute" : "",
784 bad
.flags
.q
.varying
? " varying" : "",
785 bad
.flags
.q
.in
? " in" : "",
786 bad
.flags
.q
.out
? " out" : "",
787 bad
.flags
.q
.centroid
? " centroid" : "",
788 bad
.flags
.q
.sample
? " sample" : "",
789 bad
.flags
.q
.patch
? " patch" : "",
790 bad
.flags
.q
.uniform
? " uniform" : "",
791 bad
.flags
.q
.buffer
? " buffer" : "",
792 bad
.flags
.q
.shared_storage
? " shared_storage" : "",
793 bad
.flags
.q
.smooth
? " smooth" : "",
794 bad
.flags
.q
.flat
? " flat" : "",
795 bad
.flags
.q
.noperspective
? " noperspective" : "",
796 bad
.flags
.q
.origin_upper_left
? " origin_upper_left" : "",
797 bad
.flags
.q
.pixel_center_integer
? " pixel_center_integer" : "",
798 bad
.flags
.q
.explicit_align
? " align" : "",
799 bad
.flags
.q
.explicit_component
? " component" : "",
800 bad
.flags
.q
.explicit_location
? " location" : "",
801 bad
.flags
.q
.explicit_index
? " index" : "",
802 bad
.flags
.q
.explicit_binding
? " binding" : "",
803 bad
.flags
.q
.explicit_offset
? " offset" : "",
804 bad
.flags
.q
.depth_type
? " depth_type" : "",
805 bad
.flags
.q
.std140
? " std140" : "",
806 bad
.flags
.q
.std430
? " std430" : "",
807 bad
.flags
.q
.shared
? " shared" : "",
808 bad
.flags
.q
.packed
? " packed" : "",
809 bad
.flags
.q
.column_major
? " column_major" : "",
810 bad
.flags
.q
.row_major
? " row_major" : "",
811 bad
.flags
.q
.prim_type
? " prim_type" : "",
812 bad
.flags
.q
.max_vertices
? " max_vertices" : "",
813 bad
.flags
.q
.local_size
? " local_size" : "",
814 bad
.flags
.q
.local_size_variable
? " local_size_variable" : "",
815 bad
.flags
.q
.early_fragment_tests
? " early_fragment_tests" : "",
816 bad
.flags
.q
.explicit_image_format
? " image_format" : "",
817 bad
.flags
.q
.coherent
? " coherent" : "",
818 bad
.flags
.q
._volatile
? " _volatile" : "",
819 bad
.flags
.q
.restrict_flag
? " restrict_flag" : "",
820 bad
.flags
.q
.read_only
? " read_only" : "",
821 bad
.flags
.q
.write_only
? " write_only" : "",
822 bad
.flags
.q
.invocations
? " invocations" : "",
823 bad
.flags
.q
.stream
? " stream" : "",
824 bad
.flags
.q
.explicit_stream
? " stream" : "",
825 bad
.flags
.q
.explicit_xfb_offset
? " xfb_offset" : "",
826 bad
.flags
.q
.xfb_buffer
? " xfb_buffer" : "",
827 bad
.flags
.q
.explicit_xfb_buffer
? " xfb_buffer" : "",
828 bad
.flags
.q
.xfb_stride
? " xfb_stride" : "",
829 bad
.flags
.q
.explicit_xfb_stride
? " xfb_stride" : "",
830 bad
.flags
.q
.vertex_spacing
? " vertex_spacing" : "",
831 bad
.flags
.q
.ordering
? " ordering" : "",
832 bad
.flags
.q
.point_mode
? " point_mode" : "",
833 bad
.flags
.q
.vertices
? " vertices" : "",
834 bad
.flags
.q
.subroutine
? " subroutine" : "",
835 bad
.flags
.q
.blend_support
? " blend_support" : "",
836 bad
.flags
.q
.inner_coverage
? " inner_coverage" : "",
837 bad
.flags
.q
.bindless_sampler
? " bindless_sampler" : "",
838 bad
.flags
.q
.bindless_image
? " bindless_image" : "",
839 bad
.flags
.q
.bound_sampler
? " bound_sampler" : "",
840 bad
.flags
.q
.bound_image
? " bound_image" : "",
841 bad
.flags
.q
.post_depth_coverage
? " post_depth_coverage" : "");
846 ast_layout_expression::process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
847 const char *qual_indentifier
,
852 bool first_pass
= true;
858 for (exec_node
*node
= layout_const_expressions
.get_head_raw();
859 !node
->is_tail_sentinel(); node
= node
->next
) {
861 exec_list dummy_instructions
;
862 ast_node
*const_expression
= exec_node_data(ast_node
, node
, link
);
864 ir_rvalue
*const ir
= const_expression
->hir(&dummy_instructions
, state
);
866 ir_constant
*const const_int
=
867 ir
->constant_expression_value(ralloc_parent(ir
));
869 if (const_int
== NULL
|| !const_int
->type
->is_integer()) {
870 YYLTYPE loc
= const_expression
->get_location();
871 _mesa_glsl_error(&loc
, state
, "%s must be an integral constant "
872 "expression", qual_indentifier
);
876 if (const_int
->value
.i
[0] < min_value
) {
877 YYLTYPE loc
= const_expression
->get_location();
878 _mesa_glsl_error(&loc
, state
, "%s layout qualifier is invalid "
879 "(%d < %d)", qual_indentifier
,
880 const_int
->value
.i
[0], min_value
);
884 if (!first_pass
&& *value
!= const_int
->value
.u
[0]) {
885 YYLTYPE loc
= const_expression
->get_location();
886 _mesa_glsl_error(&loc
, state
, "%s layout qualifier does not "
887 "match previous declaration (%d vs %d)",
888 qual_indentifier
, *value
, const_int
->value
.i
[0]);
892 *value
= const_int
->value
.u
[0];
895 /* If the location is const (and we've verified that
896 * it is) then no instructions should have been emitted
897 * when we converted it to HIR. If they were emitted,
898 * then either the location isn't const after all, or
899 * we are emitting unnecessary instructions.
901 assert(dummy_instructions
.is_empty());
908 process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
910 const char *qual_indentifier
,
911 ast_expression
*const_expression
,
914 exec_list dummy_instructions
;
916 if (const_expression
== NULL
) {
921 ir_rvalue
*const ir
= const_expression
->hir(&dummy_instructions
, state
);
923 ir_constant
*const const_int
=
924 ir
->constant_expression_value(ralloc_parent(ir
));
925 if (const_int
== NULL
|| !const_int
->type
->is_integer()) {
926 _mesa_glsl_error(loc
, state
, "%s must be an integral constant "
927 "expression", qual_indentifier
);
931 if (const_int
->value
.i
[0] < 0) {
932 _mesa_glsl_error(loc
, state
, "%s layout qualifier is invalid (%d < 0)",
933 qual_indentifier
, const_int
->value
.u
[0]);
937 /* If the location is const (and we've verified that
938 * it is) then no instructions should have been emitted
939 * when we converted it to HIR. If they were emitted,
940 * then either the location isn't const after all, or
941 * we are emitting unnecessary instructions.
943 assert(dummy_instructions
.is_empty());
945 *value
= const_int
->value
.u
[0];