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;
273 input_layout_mask
.flags
.q
.non_coherent
= 1;
275 if (state
->has_bindless()) {
276 /* Allow to use image qualifiers with shader inputs/outputs. */
277 input_layout_mask
.flags
.q
.coherent
= 1;
278 input_layout_mask
.flags
.q
._volatile
= 1;
279 input_layout_mask
.flags
.q
.restrict_flag
= 1;
280 input_layout_mask
.flags
.q
.read_only
= 1;
281 input_layout_mask
.flags
.q
.write_only
= 1;
282 input_layout_mask
.flags
.q
.explicit_image_format
= 1;
285 /* Uniform block layout qualifiers get to overwrite each
286 * other (rightmost having priority), while all other
287 * qualifiers currently don't allow duplicates.
289 ast_type_qualifier allowed_duplicates_mask
;
290 allowed_duplicates_mask
.flags
.i
=
291 ubo_mat_mask
.flags
.i
|
292 ubo_layout_mask
.flags
.i
|
293 ubo_binding_mask
.flags
.i
;
295 /* Geometry shaders can have several layout qualifiers
296 * assigning different stream values.
298 if (state
->stage
== MESA_SHADER_GEOMETRY
) {
299 allowed_duplicates_mask
.flags
.i
|=
300 stream_layout_mask
.flags
.i
;
303 if (is_single_layout_merge
&& !state
->has_enhanced_layouts() &&
304 (this->flags
.i
& q
.flags
.i
& ~allowed_duplicates_mask
.flags
.i
) != 0) {
305 _mesa_glsl_error(loc
, state
, "duplicate layout qualifiers used");
309 if (is_multiple_layouts_merge
&& !state
->has_420pack_or_es31()) {
310 _mesa_glsl_error(loc
, state
,
311 "duplicate layout(...) qualifiers");
315 if (q
.flags
.q
.prim_type
) {
316 r
&= validate_prim_type(loc
, state
, *this, q
);
317 this->flags
.q
.prim_type
= 1;
318 this->prim_type
= q
.prim_type
;
321 if (q
.flags
.q
.max_vertices
) {
322 if (this->flags
.q
.max_vertices
323 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
324 this->max_vertices
->merge_qualifier(q
.max_vertices
);
326 this->flags
.q
.max_vertices
= 1;
327 this->max_vertices
= q
.max_vertices
;
331 if (q
.subroutine_list
) {
332 if (this->subroutine_list
) {
333 _mesa_glsl_error(loc
, state
,
334 "conflicting subroutine qualifiers used");
336 this->subroutine_list
= q
.subroutine_list
;
340 if (q
.flags
.q
.invocations
) {
341 if (this->flags
.q
.invocations
342 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
343 this->invocations
->merge_qualifier(q
.invocations
);
345 this->flags
.q
.invocations
= 1;
346 this->invocations
= q
.invocations
;
350 if (state
->stage
== MESA_SHADER_GEOMETRY
&&
351 state
->has_explicit_attrib_stream()) {
352 if (!this->flags
.q
.explicit_stream
) {
353 if (q
.flags
.q
.stream
) {
354 this->flags
.q
.stream
= 1;
355 this->stream
= q
.stream
;
356 } else if (!this->flags
.q
.stream
&& this->flags
.q
.out
&&
358 /* Assign default global stream value */
359 this->flags
.q
.stream
= 1;
360 this->stream
= state
->out_qualifier
->stream
;
365 if (state
->has_enhanced_layouts()) {
366 if (!this->flags
.q
.explicit_xfb_buffer
) {
367 if (q
.flags
.q
.xfb_buffer
) {
368 this->flags
.q
.xfb_buffer
= 1;
369 this->xfb_buffer
= q
.xfb_buffer
;
370 } else if (!this->flags
.q
.xfb_buffer
&& this->flags
.q
.out
&&
372 /* Assign global xfb_buffer value */
373 this->flags
.q
.xfb_buffer
= 1;
374 this->xfb_buffer
= state
->out_qualifier
->xfb_buffer
;
378 if (q
.flags
.q
.explicit_xfb_stride
) {
379 this->flags
.q
.xfb_stride
= 1;
380 this->flags
.q
.explicit_xfb_stride
= 1;
381 this->xfb_stride
= q
.xfb_stride
;
385 if (q
.flags
.q
.vertices
) {
386 if (this->flags
.q
.vertices
387 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
388 this->vertices
->merge_qualifier(q
.vertices
);
390 this->flags
.q
.vertices
= 1;
391 this->vertices
= q
.vertices
;
395 if (q
.flags
.q
.vertex_spacing
) {
396 r
&= validate_vertex_spacing(loc
, state
, *this, q
);
397 this->flags
.q
.vertex_spacing
= 1;
398 this->vertex_spacing
= q
.vertex_spacing
;
401 if (q
.flags
.q
.ordering
) {
402 r
&= validate_ordering(loc
, state
, *this, q
);
403 this->flags
.q
.ordering
= 1;
404 this->ordering
= q
.ordering
;
407 if (q
.flags
.q
.point_mode
) {
408 r
&= validate_point_mode(*this, q
);
409 this->flags
.q
.point_mode
= 1;
410 this->point_mode
= q
.point_mode
;
413 if (q
.flags
.q
.early_fragment_tests
)
414 this->flags
.q
.early_fragment_tests
= true;
416 if ((q
.flags
.i
& ubo_mat_mask
.flags
.i
) != 0)
417 this->flags
.i
&= ~ubo_mat_mask
.flags
.i
;
418 if ((q
.flags
.i
& ubo_layout_mask
.flags
.i
) != 0)
419 this->flags
.i
&= ~ubo_layout_mask
.flags
.i
;
421 for (int i
= 0; i
< 3; i
++) {
422 if (q
.flags
.q
.local_size
& (1 << i
)) {
423 if (this->local_size
[i
]
424 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
425 this->local_size
[i
]->merge_qualifier(q
.local_size
[i
]);
427 this->local_size
[i
] = q
.local_size
[i
];
432 if (q
.flags
.q
.local_size_variable
)
433 this->flags
.q
.local_size_variable
= true;
435 if (q
.flags
.q
.bindless_sampler
)
436 this->flags
.q
.bindless_sampler
= true;
438 if (q
.flags
.q
.bindless_image
)
439 this->flags
.q
.bindless_image
= true;
441 if (q
.flags
.q
.bound_sampler
)
442 this->flags
.q
.bound_sampler
= true;
444 if (q
.flags
.q
.bound_image
)
445 this->flags
.q
.bound_image
= true;
447 this->flags
.i
|= q
.flags
.i
;
449 if (this->flags
.q
.in
&&
450 (this->flags
.i
& ~input_layout_mask
.flags
.i
) != 0) {
451 _mesa_glsl_error(loc
, state
, "invalid input layout qualifier used");
455 if (q
.flags
.q
.explicit_align
)
456 this->align
= q
.align
;
458 if (q
.flags
.q
.explicit_location
)
459 this->location
= q
.location
;
461 if (q
.flags
.q
.explicit_index
)
462 this->index
= q
.index
;
464 if (q
.flags
.q
.explicit_component
)
465 this->component
= q
.component
;
467 if (q
.flags
.q
.explicit_binding
)
468 this->binding
= q
.binding
;
470 if (q
.flags
.q
.explicit_offset
|| q
.flags
.q
.explicit_xfb_offset
)
471 this->offset
= q
.offset
;
473 if (q
.precision
!= ast_precision_none
)
474 this->precision
= q
.precision
;
476 if (q
.flags
.q
.explicit_image_format
) {
477 this->image_format
= q
.image_format
;
478 this->image_base_type
= q
.image_base_type
;
481 if (q
.flags
.q
.bindless_sampler
||
482 q
.flags
.q
.bindless_image
||
483 q
.flags
.q
.bound_sampler
||
484 q
.flags
.q
.bound_image
)
485 merge_bindless_qualifier(state
);
491 ast_type_qualifier::validate_out_qualifier(YYLTYPE
*loc
,
492 _mesa_glsl_parse_state
*state
)
495 ast_type_qualifier valid_out_mask
;
496 valid_out_mask
.flags
.i
= 0;
498 switch (state
->stage
) {
499 case MESA_SHADER_GEOMETRY
:
500 if (this->flags
.q
.prim_type
) {
501 /* Make sure this is a valid output primitive type. */
502 switch (this->prim_type
) {
505 case GL_TRIANGLE_STRIP
:
509 _mesa_glsl_error(loc
, state
, "invalid geometry shader output "
515 valid_out_mask
.flags
.q
.stream
= 1;
516 valid_out_mask
.flags
.q
.explicit_stream
= 1;
517 valid_out_mask
.flags
.q
.explicit_xfb_buffer
= 1;
518 valid_out_mask
.flags
.q
.xfb_buffer
= 1;
519 valid_out_mask
.flags
.q
.explicit_xfb_stride
= 1;
520 valid_out_mask
.flags
.q
.xfb_stride
= 1;
521 valid_out_mask
.flags
.q
.max_vertices
= 1;
522 valid_out_mask
.flags
.q
.prim_type
= 1;
524 case MESA_SHADER_TESS_CTRL
:
525 valid_out_mask
.flags
.q
.vertices
= 1;
526 valid_out_mask
.flags
.q
.explicit_xfb_buffer
= 1;
527 valid_out_mask
.flags
.q
.xfb_buffer
= 1;
528 valid_out_mask
.flags
.q
.explicit_xfb_stride
= 1;
529 valid_out_mask
.flags
.q
.xfb_stride
= 1;
531 case MESA_SHADER_TESS_EVAL
:
532 case MESA_SHADER_VERTEX
:
533 valid_out_mask
.flags
.q
.explicit_xfb_buffer
= 1;
534 valid_out_mask
.flags
.q
.xfb_buffer
= 1;
535 valid_out_mask
.flags
.q
.explicit_xfb_stride
= 1;
536 valid_out_mask
.flags
.q
.xfb_stride
= 1;
538 case MESA_SHADER_FRAGMENT
:
539 valid_out_mask
.flags
.q
.blend_support
= 1;
543 _mesa_glsl_error(loc
, state
,
544 "out layout qualifiers only valid in "
545 "geometry, tessellation, vertex and fragment shaders");
548 /* Generate an error when invalid output layout qualifiers are used. */
549 if ((this->flags
.i
& ~valid_out_mask
.flags
.i
) != 0) {
551 _mesa_glsl_error(loc
, state
, "invalid output layout qualifiers used");
558 ast_type_qualifier::merge_into_out_qualifier(YYLTYPE
*loc
,
559 _mesa_glsl_parse_state
*state
,
562 const bool r
= state
->out_qualifier
->merge_qualifier(loc
, state
,
565 switch (state
->stage
) {
566 case MESA_SHADER_GEOMETRY
:
567 /* Allow future assignments of global out's stream id value */
568 state
->out_qualifier
->flags
.q
.explicit_stream
= 0;
570 case MESA_SHADER_TESS_CTRL
:
571 node
= new(state
->linalloc
) ast_tcs_output_layout(*loc
);
577 /* Allow future assignments of global out's */
578 state
->out_qualifier
->flags
.q
.explicit_xfb_buffer
= 0;
579 state
->out_qualifier
->flags
.q
.explicit_xfb_stride
= 0;
585 ast_type_qualifier::validate_in_qualifier(YYLTYPE
*loc
,
586 _mesa_glsl_parse_state
*state
)
589 ast_type_qualifier valid_in_mask
;
590 valid_in_mask
.flags
.i
= 0;
592 switch (state
->stage
) {
593 case MESA_SHADER_TESS_EVAL
:
594 if (this->flags
.q
.prim_type
) {
595 /* Make sure this is a valid input primitive type. */
596 switch (this->prim_type
) {
603 _mesa_glsl_error(loc
, state
,
604 "invalid tessellation evaluation "
605 "shader input primitive type");
610 valid_in_mask
.flags
.q
.prim_type
= 1;
611 valid_in_mask
.flags
.q
.vertex_spacing
= 1;
612 valid_in_mask
.flags
.q
.ordering
= 1;
613 valid_in_mask
.flags
.q
.point_mode
= 1;
615 case MESA_SHADER_GEOMETRY
:
616 if (this->flags
.q
.prim_type
) {
617 /* Make sure this is a valid input primitive type. */
618 switch (this->prim_type
) {
621 case GL_LINES_ADJACENCY
:
623 case GL_TRIANGLES_ADJACENCY
:
627 _mesa_glsl_error(loc
, state
,
628 "invalid geometry shader input primitive type");
633 valid_in_mask
.flags
.q
.prim_type
= 1;
634 valid_in_mask
.flags
.q
.invocations
= 1;
636 case MESA_SHADER_FRAGMENT
:
637 valid_in_mask
.flags
.q
.early_fragment_tests
= 1;
638 valid_in_mask
.flags
.q
.inner_coverage
= 1;
639 valid_in_mask
.flags
.q
.post_depth_coverage
= 1;
640 valid_in_mask
.flags
.q
.pixel_interlock_ordered
= 1;
641 valid_in_mask
.flags
.q
.pixel_interlock_unordered
= 1;
642 valid_in_mask
.flags
.q
.sample_interlock_ordered
= 1;
643 valid_in_mask
.flags
.q
.sample_interlock_unordered
= 1;
645 case MESA_SHADER_COMPUTE
:
646 valid_in_mask
.flags
.q
.local_size
= 7;
647 valid_in_mask
.flags
.q
.local_size_variable
= 1;
651 _mesa_glsl_error(loc
, state
,
652 "input layout qualifiers only valid in "
653 "geometry, tessellation, fragment and compute shaders");
657 /* Generate an error when invalid input layout qualifiers are used. */
658 if ((this->flags
.i
& ~valid_in_mask
.flags
.i
) != 0) {
660 _mesa_glsl_error(loc
, state
, "invalid input layout qualifiers used");
663 /* The checks below are also performed when merging but we want to spit an
664 * error against the default global input qualifier as soon as we can, with
665 * the closest error location in the shader.
667 r
&= validate_prim_type(loc
, state
, *state
->in_qualifier
, *this);
668 r
&= validate_vertex_spacing(loc
, state
, *state
->in_qualifier
, *this);
669 r
&= validate_ordering(loc
, state
, *state
->in_qualifier
, *this);
670 r
&= validate_point_mode(*state
->in_qualifier
, *this);
676 ast_type_qualifier::merge_into_in_qualifier(YYLTYPE
*loc
,
677 _mesa_glsl_parse_state
*state
,
681 void *lin_ctx
= state
->linalloc
;
683 /* We create the gs_input_layout node before merging so, in the future, no
684 * more repeated nodes will be created as we will have the flag set.
686 if (state
->stage
== MESA_SHADER_GEOMETRY
687 && this->flags
.q
.prim_type
&& !state
->in_qualifier
->flags
.q
.prim_type
) {
688 node
= new(lin_ctx
) ast_gs_input_layout(*loc
, this->prim_type
);
691 r
= state
->in_qualifier
->merge_qualifier(loc
, state
, *this, false);
693 if (state
->in_qualifier
->flags
.q
.early_fragment_tests
) {
694 state
->fs_early_fragment_tests
= true;
695 state
->in_qualifier
->flags
.q
.early_fragment_tests
= false;
698 if (state
->in_qualifier
->flags
.q
.inner_coverage
) {
699 state
->fs_inner_coverage
= true;
700 state
->in_qualifier
->flags
.q
.inner_coverage
= false;
703 if (state
->in_qualifier
->flags
.q
.post_depth_coverage
) {
704 state
->fs_post_depth_coverage
= true;
705 state
->in_qualifier
->flags
.q
.post_depth_coverage
= false;
708 if (state
->fs_inner_coverage
&& state
->fs_post_depth_coverage
) {
709 _mesa_glsl_error(loc
, state
,
710 "inner_coverage & post_depth_coverage layout qualifiers "
711 "are mutally exclusives");
715 if (state
->in_qualifier
->flags
.q
.pixel_interlock_ordered
) {
716 state
->fs_pixel_interlock_ordered
= true;
717 state
->in_qualifier
->flags
.q
.pixel_interlock_ordered
= false;
720 if (state
->in_qualifier
->flags
.q
.pixel_interlock_unordered
) {
721 state
->fs_pixel_interlock_unordered
= true;
722 state
->in_qualifier
->flags
.q
.pixel_interlock_unordered
= false;
725 if (state
->in_qualifier
->flags
.q
.sample_interlock_ordered
) {
726 state
->fs_sample_interlock_ordered
= true;
727 state
->in_qualifier
->flags
.q
.sample_interlock_ordered
= false;
730 if (state
->in_qualifier
->flags
.q
.sample_interlock_unordered
) {
731 state
->fs_sample_interlock_unordered
= true;
732 state
->in_qualifier
->flags
.q
.sample_interlock_unordered
= false;
735 if (state
->fs_pixel_interlock_ordered
+
736 state
->fs_pixel_interlock_unordered
+
737 state
->fs_sample_interlock_ordered
+
738 state
->fs_sample_interlock_unordered
> 1) {
739 _mesa_glsl_error(loc
, state
,
740 "only one interlock mode can be used at any time.");
744 /* We allow the creation of multiple cs_input_layout nodes. Coherence among
745 * all existing nodes is checked later, when the AST node is transformed
748 if (state
->in_qualifier
->flags
.q
.local_size
) {
749 node
= new(lin_ctx
) ast_cs_input_layout(*loc
,
750 state
->in_qualifier
->local_size
);
751 state
->in_qualifier
->flags
.q
.local_size
= 0;
752 for (int i
= 0; i
< 3; i
++)
753 state
->in_qualifier
->local_size
[i
] = NULL
;
756 if (state
->in_qualifier
->flags
.q
.local_size_variable
) {
757 state
->cs_input_local_size_variable_specified
= true;
758 state
->in_qualifier
->flags
.q
.local_size_variable
= false;
765 ast_type_qualifier::push_to_global(YYLTYPE
*loc
,
766 _mesa_glsl_parse_state
*state
)
768 if (this->flags
.q
.xfb_stride
) {
769 this->flags
.q
.xfb_stride
= 0;
772 if (process_qualifier_constant(state
, loc
, "xfb_buffer",
773 this->xfb_buffer
, &buff_idx
)) {
774 if (state
->out_qualifier
->out_xfb_stride
[buff_idx
]) {
775 state
->out_qualifier
->out_xfb_stride
[buff_idx
]->merge_qualifier(
776 new(state
->linalloc
) ast_layout_expression(*loc
,
779 state
->out_qualifier
->out_xfb_stride
[buff_idx
] =
780 new(state
->linalloc
) ast_layout_expression(*loc
,
790 * Check if the current type qualifier has any illegal flags.
792 * If so, print an error message, followed by a list of illegal flags.
794 * \param message The error message to print.
795 * \param allowed_flags A list of valid flags.
798 ast_type_qualifier::validate_flags(YYLTYPE
*loc
,
799 _mesa_glsl_parse_state
*state
,
800 const ast_type_qualifier
&allowed_flags
,
801 const char *message
, const char *name
)
803 ast_type_qualifier bad
;
804 bad
.flags
.i
= this->flags
.i
& ~allowed_flags
.flags
.i
;
805 if (bad
.flags
.i
== 0)
808 _mesa_glsl_error(loc
, state
,
810 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
811 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
812 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
814 bad
.flags
.q
.invariant
? " invariant" : "",
815 bad
.flags
.q
.precise
? " precise" : "",
816 bad
.flags
.q
.constant
? " constant" : "",
817 bad
.flags
.q
.attribute
? " attribute" : "",
818 bad
.flags
.q
.varying
? " varying" : "",
819 bad
.flags
.q
.in
? " in" : "",
820 bad
.flags
.q
.out
? " out" : "",
821 bad
.flags
.q
.centroid
? " centroid" : "",
822 bad
.flags
.q
.sample
? " sample" : "",
823 bad
.flags
.q
.patch
? " patch" : "",
824 bad
.flags
.q
.uniform
? " uniform" : "",
825 bad
.flags
.q
.buffer
? " buffer" : "",
826 bad
.flags
.q
.shared_storage
? " shared_storage" : "",
827 bad
.flags
.q
.smooth
? " smooth" : "",
828 bad
.flags
.q
.flat
? " flat" : "",
829 bad
.flags
.q
.noperspective
? " noperspective" : "",
830 bad
.flags
.q
.origin_upper_left
? " origin_upper_left" : "",
831 bad
.flags
.q
.pixel_center_integer
? " pixel_center_integer" : "",
832 bad
.flags
.q
.explicit_align
? " align" : "",
833 bad
.flags
.q
.explicit_component
? " component" : "",
834 bad
.flags
.q
.explicit_location
? " location" : "",
835 bad
.flags
.q
.explicit_index
? " index" : "",
836 bad
.flags
.q
.explicit_binding
? " binding" : "",
837 bad
.flags
.q
.explicit_offset
? " offset" : "",
838 bad
.flags
.q
.depth_type
? " depth_type" : "",
839 bad
.flags
.q
.std140
? " std140" : "",
840 bad
.flags
.q
.std430
? " std430" : "",
841 bad
.flags
.q
.shared
? " shared" : "",
842 bad
.flags
.q
.packed
? " packed" : "",
843 bad
.flags
.q
.column_major
? " column_major" : "",
844 bad
.flags
.q
.row_major
? " row_major" : "",
845 bad
.flags
.q
.prim_type
? " prim_type" : "",
846 bad
.flags
.q
.max_vertices
? " max_vertices" : "",
847 bad
.flags
.q
.local_size
? " local_size" : "",
848 bad
.flags
.q
.local_size_variable
? " local_size_variable" : "",
849 bad
.flags
.q
.early_fragment_tests
? " early_fragment_tests" : "",
850 bad
.flags
.q
.explicit_image_format
? " image_format" : "",
851 bad
.flags
.q
.coherent
? " coherent" : "",
852 bad
.flags
.q
._volatile
? " _volatile" : "",
853 bad
.flags
.q
.restrict_flag
? " restrict_flag" : "",
854 bad
.flags
.q
.read_only
? " read_only" : "",
855 bad
.flags
.q
.write_only
? " write_only" : "",
856 bad
.flags
.q
.invocations
? " invocations" : "",
857 bad
.flags
.q
.stream
? " stream" : "",
858 bad
.flags
.q
.explicit_stream
? " stream" : "",
859 bad
.flags
.q
.explicit_xfb_offset
? " xfb_offset" : "",
860 bad
.flags
.q
.xfb_buffer
? " xfb_buffer" : "",
861 bad
.flags
.q
.explicit_xfb_buffer
? " xfb_buffer" : "",
862 bad
.flags
.q
.xfb_stride
? " xfb_stride" : "",
863 bad
.flags
.q
.explicit_xfb_stride
? " xfb_stride" : "",
864 bad
.flags
.q
.vertex_spacing
? " vertex_spacing" : "",
865 bad
.flags
.q
.ordering
? " ordering" : "",
866 bad
.flags
.q
.point_mode
? " point_mode" : "",
867 bad
.flags
.q
.vertices
? " vertices" : "",
868 bad
.flags
.q
.subroutine
? " subroutine" : "",
869 bad
.flags
.q
.blend_support
? " blend_support" : "",
870 bad
.flags
.q
.inner_coverage
? " inner_coverage" : "",
871 bad
.flags
.q
.bindless_sampler
? " bindless_sampler" : "",
872 bad
.flags
.q
.bindless_image
? " bindless_image" : "",
873 bad
.flags
.q
.bound_sampler
? " bound_sampler" : "",
874 bad
.flags
.q
.bound_image
? " bound_image" : "",
875 bad
.flags
.q
.post_depth_coverage
? " post_depth_coverage" : "",
876 bad
.flags
.q
.pixel_interlock_ordered
? " pixel_interlock_ordered" : "",
877 bad
.flags
.q
.pixel_interlock_unordered
? " pixel_interlock_unordered": "",
878 bad
.flags
.q
.sample_interlock_ordered
? " sample_interlock_ordered": "",
879 bad
.flags
.q
.sample_interlock_unordered
? " sample_interlock_unordered": "",
880 bad
.flags
.q
.non_coherent
? " noncoherent" : "");
885 ast_layout_expression::process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
886 const char *qual_indentifier
,
891 bool first_pass
= true;
897 for (exec_node
*node
= layout_const_expressions
.get_head_raw();
898 !node
->is_tail_sentinel(); node
= node
->next
) {
900 exec_list dummy_instructions
;
901 ast_node
*const_expression
= exec_node_data(ast_node
, node
, link
);
903 ir_rvalue
*const ir
= const_expression
->hir(&dummy_instructions
, state
);
905 ir_constant
*const const_int
=
906 ir
->constant_expression_value(ralloc_parent(ir
));
908 if (const_int
== NULL
|| !const_int
->type
->is_integer()) {
909 YYLTYPE loc
= const_expression
->get_location();
910 _mesa_glsl_error(&loc
, state
, "%s must be an integral constant "
911 "expression", qual_indentifier
);
915 if (const_int
->value
.i
[0] < min_value
) {
916 YYLTYPE loc
= const_expression
->get_location();
917 _mesa_glsl_error(&loc
, state
, "%s layout qualifier is invalid "
918 "(%d < %d)", qual_indentifier
,
919 const_int
->value
.i
[0], min_value
);
923 if (!first_pass
&& *value
!= const_int
->value
.u
[0]) {
924 YYLTYPE loc
= const_expression
->get_location();
925 _mesa_glsl_error(&loc
, state
, "%s layout qualifier does not "
926 "match previous declaration (%d vs %d)",
927 qual_indentifier
, *value
, const_int
->value
.i
[0]);
931 *value
= const_int
->value
.u
[0];
934 /* If the location is const (and we've verified that
935 * it is) then no instructions should have been emitted
936 * when we converted it to HIR. If they were emitted,
937 * then either the location isn't const after all, or
938 * we are emitting unnecessary instructions.
940 assert(dummy_instructions
.is_empty());
947 process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
949 const char *qual_indentifier
,
950 ast_expression
*const_expression
,
953 exec_list dummy_instructions
;
955 if (const_expression
== NULL
) {
960 ir_rvalue
*const ir
= const_expression
->hir(&dummy_instructions
, state
);
962 ir_constant
*const const_int
=
963 ir
->constant_expression_value(ralloc_parent(ir
));
964 if (const_int
== NULL
|| !const_int
->type
->is_integer()) {
965 _mesa_glsl_error(loc
, state
, "%s must be an integral constant "
966 "expression", qual_indentifier
);
970 if (const_int
->value
.i
[0] < 0) {
971 _mesa_glsl_error(loc
, state
, "%s layout qualifier is invalid (%d < 0)",
972 qual_indentifier
, const_int
->value
.u
[0]);
976 /* If the location is const (and we've verified that
977 * it is) then no instructions should have been emitted
978 * when we converted it to HIR. If they were emitted,
979 * then either the location isn't const after all, or
980 * we are emitting unnecessary instructions.
982 assert(dummy_instructions
.is_empty());
984 *value
= const_int
->value
.u
[0];