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(YYLTYPE
*loc
,
190 _mesa_glsl_parse_state
*state
,
191 const ast_type_qualifier
&qualifier
,
192 const ast_type_qualifier
&new_qualifier
)
194 if (state
->default_uniform_qualifier
->flags
.q
.bindless_sampler
) {
195 state
->bindless_sampler_specified
= true;
196 state
->default_uniform_qualifier
->flags
.q
.bindless_sampler
= false;
199 if (state
->default_uniform_qualifier
->flags
.q
.bindless_image
) {
200 state
->bindless_image_specified
= true;
201 state
->default_uniform_qualifier
->flags
.q
.bindless_image
= false;
204 if (state
->default_uniform_qualifier
->flags
.q
.bound_sampler
) {
205 state
->bound_sampler_specified
= true;
206 state
->default_uniform_qualifier
->flags
.q
.bound_sampler
= false;
209 if (state
->default_uniform_qualifier
->flags
.q
.bound_image
) {
210 state
->bound_image_specified
= true;
211 state
->default_uniform_qualifier
->flags
.q
.bound_image
= false;
216 * This function merges duplicate layout identifiers.
218 * It deals with duplicates within a single layout qualifier, among multiple
219 * layout qualifiers on a single declaration and on several declarations for
222 * The is_single_layout_merge and is_multiple_layouts_merge parameters are
223 * used to differentiate among them.
226 ast_type_qualifier::merge_qualifier(YYLTYPE
*loc
,
227 _mesa_glsl_parse_state
*state
,
228 const ast_type_qualifier
&q
,
229 bool is_single_layout_merge
,
230 bool is_multiple_layouts_merge
)
233 ast_type_qualifier ubo_mat_mask
;
234 ubo_mat_mask
.flags
.i
= 0;
235 ubo_mat_mask
.flags
.q
.row_major
= 1;
236 ubo_mat_mask
.flags
.q
.column_major
= 1;
238 ast_type_qualifier ubo_layout_mask
;
239 ubo_layout_mask
.flags
.i
= 0;
240 ubo_layout_mask
.flags
.q
.std140
= 1;
241 ubo_layout_mask
.flags
.q
.packed
= 1;
242 ubo_layout_mask
.flags
.q
.shared
= 1;
243 ubo_layout_mask
.flags
.q
.std430
= 1;
245 ast_type_qualifier ubo_binding_mask
;
246 ubo_binding_mask
.flags
.i
= 0;
247 ubo_binding_mask
.flags
.q
.explicit_binding
= 1;
248 ubo_binding_mask
.flags
.q
.explicit_offset
= 1;
250 ast_type_qualifier stream_layout_mask
;
251 stream_layout_mask
.flags
.i
= 0;
252 stream_layout_mask
.flags
.q
.stream
= 1;
254 /* FIXME: We should probably do interface and function param validation
257 ast_type_qualifier input_layout_mask
;
258 input_layout_mask
.flags
.i
= 0;
259 input_layout_mask
.flags
.q
.centroid
= 1;
260 /* Function params can have constant */
261 input_layout_mask
.flags
.q
.constant
= 1;
262 input_layout_mask
.flags
.q
.explicit_component
= 1;
263 input_layout_mask
.flags
.q
.explicit_location
= 1;
264 input_layout_mask
.flags
.q
.flat
= 1;
265 input_layout_mask
.flags
.q
.in
= 1;
266 input_layout_mask
.flags
.q
.invariant
= 1;
267 input_layout_mask
.flags
.q
.noperspective
= 1;
268 input_layout_mask
.flags
.q
.origin_upper_left
= 1;
269 /* Function params 'inout' will set this */
270 input_layout_mask
.flags
.q
.out
= 1;
271 input_layout_mask
.flags
.q
.patch
= 1;
272 input_layout_mask
.flags
.q
.pixel_center_integer
= 1;
273 input_layout_mask
.flags
.q
.precise
= 1;
274 input_layout_mask
.flags
.q
.sample
= 1;
275 input_layout_mask
.flags
.q
.smooth
= 1;
277 if (state
->has_bindless()) {
278 /* Allow to use image qualifiers with shader inputs/outputs. */
279 input_layout_mask
.flags
.q
.coherent
= 1;
280 input_layout_mask
.flags
.q
._volatile
= 1;
281 input_layout_mask
.flags
.q
.restrict_flag
= 1;
282 input_layout_mask
.flags
.q
.read_only
= 1;
283 input_layout_mask
.flags
.q
.write_only
= 1;
284 input_layout_mask
.flags
.q
.explicit_image_format
= 1;
287 /* Uniform block layout qualifiers get to overwrite each
288 * other (rightmost having priority), while all other
289 * qualifiers currently don't allow duplicates.
291 ast_type_qualifier allowed_duplicates_mask
;
292 allowed_duplicates_mask
.flags
.i
=
293 ubo_mat_mask
.flags
.i
|
294 ubo_layout_mask
.flags
.i
|
295 ubo_binding_mask
.flags
.i
;
297 /* Geometry shaders can have several layout qualifiers
298 * assigning different stream values.
300 if (state
->stage
== MESA_SHADER_GEOMETRY
) {
301 allowed_duplicates_mask
.flags
.i
|=
302 stream_layout_mask
.flags
.i
;
305 if (is_single_layout_merge
&& !state
->has_enhanced_layouts() &&
306 (this->flags
.i
& q
.flags
.i
& ~allowed_duplicates_mask
.flags
.i
) != 0) {
307 _mesa_glsl_error(loc
, state
, "duplicate layout qualifiers used");
311 if (is_multiple_layouts_merge
&& !state
->has_420pack_or_es31()) {
312 _mesa_glsl_error(loc
, state
,
313 "duplicate layout(...) qualifiers");
317 if (q
.flags
.q
.prim_type
) {
318 r
&= validate_prim_type(loc
, state
, *this, q
);
319 this->flags
.q
.prim_type
= 1;
320 this->prim_type
= q
.prim_type
;
323 if (q
.flags
.q
.max_vertices
) {
324 if (this->flags
.q
.max_vertices
325 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
326 this->max_vertices
->merge_qualifier(q
.max_vertices
);
328 this->flags
.q
.max_vertices
= 1;
329 this->max_vertices
= q
.max_vertices
;
333 if (q
.subroutine_list
) {
334 if (this->subroutine_list
) {
335 _mesa_glsl_error(loc
, state
,
336 "conflicting subroutine qualifiers used");
338 this->subroutine_list
= q
.subroutine_list
;
342 if (q
.flags
.q
.invocations
) {
343 if (this->flags
.q
.invocations
344 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
345 this->invocations
->merge_qualifier(q
.invocations
);
347 this->flags
.q
.invocations
= 1;
348 this->invocations
= q
.invocations
;
352 if (state
->stage
== MESA_SHADER_GEOMETRY
&&
353 state
->has_explicit_attrib_stream()) {
354 if (!this->flags
.q
.explicit_stream
) {
355 if (q
.flags
.q
.stream
) {
356 this->flags
.q
.stream
= 1;
357 this->stream
= q
.stream
;
358 } else if (!this->flags
.q
.stream
&& this->flags
.q
.out
&&
360 /* Assign default global stream value */
361 this->flags
.q
.stream
= 1;
362 this->stream
= state
->out_qualifier
->stream
;
367 if (state
->has_enhanced_layouts()) {
368 if (!this->flags
.q
.explicit_xfb_buffer
) {
369 if (q
.flags
.q
.xfb_buffer
) {
370 this->flags
.q
.xfb_buffer
= 1;
371 this->xfb_buffer
= q
.xfb_buffer
;
372 } else if (!this->flags
.q
.xfb_buffer
&& this->flags
.q
.out
&&
374 /* Assign global xfb_buffer value */
375 this->flags
.q
.xfb_buffer
= 1;
376 this->xfb_buffer
= state
->out_qualifier
->xfb_buffer
;
380 if (q
.flags
.q
.explicit_xfb_stride
) {
381 this->flags
.q
.xfb_stride
= 1;
382 this->flags
.q
.explicit_xfb_stride
= 1;
383 this->xfb_stride
= q
.xfb_stride
;
387 if (q
.flags
.q
.vertices
) {
388 if (this->flags
.q
.vertices
389 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
390 this->vertices
->merge_qualifier(q
.vertices
);
392 this->flags
.q
.vertices
= 1;
393 this->vertices
= q
.vertices
;
397 if (q
.flags
.q
.vertex_spacing
) {
398 r
&= validate_vertex_spacing(loc
, state
, *this, q
);
399 this->flags
.q
.vertex_spacing
= 1;
400 this->vertex_spacing
= q
.vertex_spacing
;
403 if (q
.flags
.q
.ordering
) {
404 r
&= validate_ordering(loc
, state
, *this, q
);
405 this->flags
.q
.ordering
= 1;
406 this->ordering
= q
.ordering
;
409 if (q
.flags
.q
.point_mode
) {
410 r
&= validate_point_mode(*this, q
);
411 this->flags
.q
.point_mode
= 1;
412 this->point_mode
= q
.point_mode
;
415 if (q
.flags
.q
.early_fragment_tests
)
416 this->flags
.q
.early_fragment_tests
= true;
418 if ((q
.flags
.i
& ubo_mat_mask
.flags
.i
) != 0)
419 this->flags
.i
&= ~ubo_mat_mask
.flags
.i
;
420 if ((q
.flags
.i
& ubo_layout_mask
.flags
.i
) != 0)
421 this->flags
.i
&= ~ubo_layout_mask
.flags
.i
;
423 for (int i
= 0; i
< 3; i
++) {
424 if (q
.flags
.q
.local_size
& (1 << i
)) {
425 if (this->local_size
[i
]
426 && !is_single_layout_merge
&& !is_multiple_layouts_merge
) {
427 this->local_size
[i
]->merge_qualifier(q
.local_size
[i
]);
429 this->local_size
[i
] = q
.local_size
[i
];
434 if (q
.flags
.q
.local_size_variable
)
435 this->flags
.q
.local_size_variable
= true;
437 if (q
.flags
.q
.bindless_sampler
)
438 this->flags
.q
.bindless_sampler
= true;
440 if (q
.flags
.q
.bindless_image
)
441 this->flags
.q
.bindless_image
= true;
443 if (q
.flags
.q
.bound_sampler
)
444 this->flags
.q
.bound_sampler
= true;
446 if (q
.flags
.q
.bound_image
)
447 this->flags
.q
.bound_image
= true;
449 this->flags
.i
|= q
.flags
.i
;
451 if (this->flags
.q
.in
&&
452 (this->flags
.i
& ~input_layout_mask
.flags
.i
) != 0) {
453 _mesa_glsl_error(loc
, state
, "invalid input layout qualifier used");
457 if (q
.flags
.q
.explicit_align
)
458 this->align
= q
.align
;
460 if (q
.flags
.q
.explicit_location
)
461 this->location
= q
.location
;
463 if (q
.flags
.q
.explicit_index
)
464 this->index
= q
.index
;
466 if (q
.flags
.q
.explicit_component
)
467 this->component
= q
.component
;
469 if (q
.flags
.q
.explicit_binding
)
470 this->binding
= q
.binding
;
472 if (q
.flags
.q
.explicit_offset
|| q
.flags
.q
.explicit_xfb_offset
)
473 this->offset
= q
.offset
;
475 if (q
.precision
!= ast_precision_none
)
476 this->precision
= q
.precision
;
478 if (q
.flags
.q
.explicit_image_format
) {
479 this->image_format
= q
.image_format
;
480 this->image_base_type
= q
.image_base_type
;
483 if (q
.flags
.q
.bindless_sampler
||
484 q
.flags
.q
.bindless_image
||
485 q
.flags
.q
.bound_sampler
||
486 q
.flags
.q
.bound_image
)
487 merge_bindless_qualifier(loc
, state
, *this, q
);
493 ast_type_qualifier::validate_out_qualifier(YYLTYPE
*loc
,
494 _mesa_glsl_parse_state
*state
)
497 ast_type_qualifier valid_out_mask
;
498 valid_out_mask
.flags
.i
= 0;
500 switch (state
->stage
) {
501 case MESA_SHADER_GEOMETRY
:
502 if (this->flags
.q
.prim_type
) {
503 /* Make sure this is a valid output primitive type. */
504 switch (this->prim_type
) {
507 case GL_TRIANGLE_STRIP
:
511 _mesa_glsl_error(loc
, state
, "invalid geometry shader output "
517 valid_out_mask
.flags
.q
.stream
= 1;
518 valid_out_mask
.flags
.q
.explicit_stream
= 1;
519 valid_out_mask
.flags
.q
.explicit_xfb_buffer
= 1;
520 valid_out_mask
.flags
.q
.xfb_buffer
= 1;
521 valid_out_mask
.flags
.q
.explicit_xfb_stride
= 1;
522 valid_out_mask
.flags
.q
.xfb_stride
= 1;
523 valid_out_mask
.flags
.q
.max_vertices
= 1;
524 valid_out_mask
.flags
.q
.prim_type
= 1;
526 case MESA_SHADER_TESS_CTRL
:
527 valid_out_mask
.flags
.q
.vertices
= 1;
528 valid_out_mask
.flags
.q
.explicit_xfb_buffer
= 1;
529 valid_out_mask
.flags
.q
.xfb_buffer
= 1;
530 valid_out_mask
.flags
.q
.explicit_xfb_stride
= 1;
531 valid_out_mask
.flags
.q
.xfb_stride
= 1;
533 case MESA_SHADER_TESS_EVAL
:
534 case MESA_SHADER_VERTEX
:
535 valid_out_mask
.flags
.q
.explicit_xfb_buffer
= 1;
536 valid_out_mask
.flags
.q
.xfb_buffer
= 1;
537 valid_out_mask
.flags
.q
.explicit_xfb_stride
= 1;
538 valid_out_mask
.flags
.q
.xfb_stride
= 1;
540 case MESA_SHADER_FRAGMENT
:
541 valid_out_mask
.flags
.q
.blend_support
= 1;
545 _mesa_glsl_error(loc
, state
,
546 "out layout qualifiers only valid in "
547 "geometry, tessellation, vertex and fragment shaders");
550 /* Generate an error when invalid output layout qualifiers are used. */
551 if ((this->flags
.i
& ~valid_out_mask
.flags
.i
) != 0) {
553 _mesa_glsl_error(loc
, state
, "invalid output layout qualifiers used");
560 ast_type_qualifier::merge_into_out_qualifier(YYLTYPE
*loc
,
561 _mesa_glsl_parse_state
*state
,
564 const bool r
= state
->out_qualifier
->merge_qualifier(loc
, state
,
567 switch (state
->stage
) {
568 case MESA_SHADER_GEOMETRY
:
569 /* Allow future assignments of global out's stream id value */
570 state
->out_qualifier
->flags
.q
.explicit_stream
= 0;
572 case MESA_SHADER_TESS_CTRL
:
573 node
= new(state
->linalloc
) ast_tcs_output_layout(*loc
);
579 /* Allow future assignments of global out's */
580 state
->out_qualifier
->flags
.q
.explicit_xfb_buffer
= 0;
581 state
->out_qualifier
->flags
.q
.explicit_xfb_stride
= 0;
587 ast_type_qualifier::validate_in_qualifier(YYLTYPE
*loc
,
588 _mesa_glsl_parse_state
*state
)
591 ast_type_qualifier valid_in_mask
;
592 valid_in_mask
.flags
.i
= 0;
594 switch (state
->stage
) {
595 case MESA_SHADER_TESS_EVAL
:
596 if (this->flags
.q
.prim_type
) {
597 /* Make sure this is a valid input primitive type. */
598 switch (this->prim_type
) {
605 _mesa_glsl_error(loc
, state
,
606 "invalid tessellation evaluation "
607 "shader input primitive type");
612 valid_in_mask
.flags
.q
.prim_type
= 1;
613 valid_in_mask
.flags
.q
.vertex_spacing
= 1;
614 valid_in_mask
.flags
.q
.ordering
= 1;
615 valid_in_mask
.flags
.q
.point_mode
= 1;
617 case MESA_SHADER_GEOMETRY
:
618 if (this->flags
.q
.prim_type
) {
619 /* Make sure this is a valid input primitive type. */
620 switch (this->prim_type
) {
623 case GL_LINES_ADJACENCY
:
625 case GL_TRIANGLES_ADJACENCY
:
629 _mesa_glsl_error(loc
, state
,
630 "invalid geometry shader input primitive type");
635 valid_in_mask
.flags
.q
.prim_type
= 1;
636 valid_in_mask
.flags
.q
.invocations
= 1;
638 case MESA_SHADER_FRAGMENT
:
639 valid_in_mask
.flags
.q
.early_fragment_tests
= 1;
640 valid_in_mask
.flags
.q
.inner_coverage
= 1;
641 valid_in_mask
.flags
.q
.post_depth_coverage
= 1;
643 case MESA_SHADER_COMPUTE
:
644 valid_in_mask
.flags
.q
.local_size
= 7;
645 valid_in_mask
.flags
.q
.local_size_variable
= 1;
649 _mesa_glsl_error(loc
, state
,
650 "input layout qualifiers only valid in "
651 "geometry, tessellation, fragment and compute shaders");
655 /* Generate an error when invalid input layout qualifiers are used. */
656 if ((this->flags
.i
& ~valid_in_mask
.flags
.i
) != 0) {
658 _mesa_glsl_error(loc
, state
, "invalid input layout qualifiers used");
661 /* The checks below are also performed when merging but we want to spit an
662 * error against the default global input qualifier as soon as we can, with
663 * the closest error location in the shader.
665 r
&= validate_prim_type(loc
, state
, *state
->in_qualifier
, *this);
666 r
&= validate_vertex_spacing(loc
, state
, *state
->in_qualifier
, *this);
667 r
&= validate_ordering(loc
, state
, *state
->in_qualifier
, *this);
668 r
&= validate_point_mode(*state
->in_qualifier
, *this);
674 ast_type_qualifier::merge_into_in_qualifier(YYLTYPE
*loc
,
675 _mesa_glsl_parse_state
*state
,
679 void *lin_ctx
= state
->linalloc
;
681 /* We create the gs_input_layout node before merging so, in the future, no
682 * more repeated nodes will be created as we will have the flag set.
684 if (state
->stage
== MESA_SHADER_GEOMETRY
685 && this->flags
.q
.prim_type
&& !state
->in_qualifier
->flags
.q
.prim_type
) {
686 node
= new(lin_ctx
) ast_gs_input_layout(*loc
, this->prim_type
);
689 r
= state
->in_qualifier
->merge_qualifier(loc
, state
, *this, false);
691 if (state
->in_qualifier
->flags
.q
.early_fragment_tests
) {
692 state
->fs_early_fragment_tests
= true;
693 state
->in_qualifier
->flags
.q
.early_fragment_tests
= false;
696 if (state
->in_qualifier
->flags
.q
.inner_coverage
) {
697 state
->fs_inner_coverage
= true;
698 state
->in_qualifier
->flags
.q
.inner_coverage
= false;
701 if (state
->in_qualifier
->flags
.q
.post_depth_coverage
) {
702 state
->fs_post_depth_coverage
= true;
703 state
->in_qualifier
->flags
.q
.post_depth_coverage
= false;
706 if (state
->fs_inner_coverage
&& state
->fs_post_depth_coverage
) {
707 _mesa_glsl_error(loc
, state
,
708 "inner_coverage & post_depth_coverage layout qualifiers "
709 "are mutally exclusives");
713 /* We allow the creation of multiple cs_input_layout nodes. Coherence among
714 * all existing nodes is checked later, when the AST node is transformed
717 if (state
->in_qualifier
->flags
.q
.local_size
) {
718 node
= new(lin_ctx
) ast_cs_input_layout(*loc
,
719 state
->in_qualifier
->local_size
);
720 state
->in_qualifier
->flags
.q
.local_size
= 0;
721 for (int i
= 0; i
< 3; i
++)
722 state
->in_qualifier
->local_size
[i
] = NULL
;
725 if (state
->in_qualifier
->flags
.q
.local_size_variable
) {
726 state
->cs_input_local_size_variable_specified
= true;
727 state
->in_qualifier
->flags
.q
.local_size_variable
= false;
734 ast_type_qualifier::push_to_global(YYLTYPE
*loc
,
735 _mesa_glsl_parse_state
*state
)
737 if (this->flags
.q
.xfb_stride
) {
738 this->flags
.q
.xfb_stride
= 0;
741 if (process_qualifier_constant(state
, loc
, "xfb_buffer",
742 this->xfb_buffer
, &buff_idx
)) {
743 if (state
->out_qualifier
->out_xfb_stride
[buff_idx
]) {
744 state
->out_qualifier
->out_xfb_stride
[buff_idx
]->merge_qualifier(
745 new(state
->linalloc
) ast_layout_expression(*loc
,
748 state
->out_qualifier
->out_xfb_stride
[buff_idx
] =
749 new(state
->linalloc
) ast_layout_expression(*loc
,
759 * Check if the current type qualifier has any illegal flags.
761 * If so, print an error message, followed by a list of illegal flags.
763 * \param message The error message to print.
764 * \param allowed_flags A list of valid flags.
767 ast_type_qualifier::validate_flags(YYLTYPE
*loc
,
768 _mesa_glsl_parse_state
*state
,
769 const ast_type_qualifier
&allowed_flags
,
770 const char *message
, const char *name
)
772 ast_type_qualifier bad
;
773 bad
.flags
.i
= this->flags
.i
& ~allowed_flags
.flags
.i
;
774 if (bad
.flags
.i
== 0)
777 _mesa_glsl_error(loc
, state
,
779 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
780 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
781 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
783 bad
.flags
.q
.invariant
? " invariant" : "",
784 bad
.flags
.q
.precise
? " precise" : "",
785 bad
.flags
.q
.constant
? " constant" : "",
786 bad
.flags
.q
.attribute
? " attribute" : "",
787 bad
.flags
.q
.varying
? " varying" : "",
788 bad
.flags
.q
.in
? " in" : "",
789 bad
.flags
.q
.out
? " out" : "",
790 bad
.flags
.q
.centroid
? " centroid" : "",
791 bad
.flags
.q
.sample
? " sample" : "",
792 bad
.flags
.q
.patch
? " patch" : "",
793 bad
.flags
.q
.uniform
? " uniform" : "",
794 bad
.flags
.q
.buffer
? " buffer" : "",
795 bad
.flags
.q
.shared_storage
? " shared_storage" : "",
796 bad
.flags
.q
.smooth
? " smooth" : "",
797 bad
.flags
.q
.flat
? " flat" : "",
798 bad
.flags
.q
.noperspective
? " noperspective" : "",
799 bad
.flags
.q
.origin_upper_left
? " origin_upper_left" : "",
800 bad
.flags
.q
.pixel_center_integer
? " pixel_center_integer" : "",
801 bad
.flags
.q
.explicit_align
? " align" : "",
802 bad
.flags
.q
.explicit_component
? " component" : "",
803 bad
.flags
.q
.explicit_location
? " location" : "",
804 bad
.flags
.q
.explicit_index
? " index" : "",
805 bad
.flags
.q
.explicit_binding
? " binding" : "",
806 bad
.flags
.q
.explicit_offset
? " offset" : "",
807 bad
.flags
.q
.depth_type
? " depth_type" : "",
808 bad
.flags
.q
.std140
? " std140" : "",
809 bad
.flags
.q
.std430
? " std430" : "",
810 bad
.flags
.q
.shared
? " shared" : "",
811 bad
.flags
.q
.packed
? " packed" : "",
812 bad
.flags
.q
.column_major
? " column_major" : "",
813 bad
.flags
.q
.row_major
? " row_major" : "",
814 bad
.flags
.q
.prim_type
? " prim_type" : "",
815 bad
.flags
.q
.max_vertices
? " max_vertices" : "",
816 bad
.flags
.q
.local_size
? " local_size" : "",
817 bad
.flags
.q
.local_size_variable
? " local_size_variable" : "",
818 bad
.flags
.q
.early_fragment_tests
? " early_fragment_tests" : "",
819 bad
.flags
.q
.explicit_image_format
? " image_format" : "",
820 bad
.flags
.q
.coherent
? " coherent" : "",
821 bad
.flags
.q
._volatile
? " _volatile" : "",
822 bad
.flags
.q
.restrict_flag
? " restrict_flag" : "",
823 bad
.flags
.q
.read_only
? " read_only" : "",
824 bad
.flags
.q
.write_only
? " write_only" : "",
825 bad
.flags
.q
.invocations
? " invocations" : "",
826 bad
.flags
.q
.stream
? " stream" : "",
827 bad
.flags
.q
.explicit_stream
? " stream" : "",
828 bad
.flags
.q
.explicit_xfb_offset
? " xfb_offset" : "",
829 bad
.flags
.q
.xfb_buffer
? " xfb_buffer" : "",
830 bad
.flags
.q
.explicit_xfb_buffer
? " xfb_buffer" : "",
831 bad
.flags
.q
.xfb_stride
? " xfb_stride" : "",
832 bad
.flags
.q
.explicit_xfb_stride
? " xfb_stride" : "",
833 bad
.flags
.q
.vertex_spacing
? " vertex_spacing" : "",
834 bad
.flags
.q
.ordering
? " ordering" : "",
835 bad
.flags
.q
.point_mode
? " point_mode" : "",
836 bad
.flags
.q
.vertices
? " vertices" : "",
837 bad
.flags
.q
.subroutine
? " subroutine" : "",
838 bad
.flags
.q
.blend_support
? " blend_support" : "",
839 bad
.flags
.q
.inner_coverage
? " inner_coverage" : "",
840 bad
.flags
.q
.bindless_sampler
? " bindless_sampler" : "",
841 bad
.flags
.q
.bindless_image
? " bindless_image" : "",
842 bad
.flags
.q
.bound_sampler
? " bound_sampler" : "",
843 bad
.flags
.q
.bound_image
? " bound_image" : "",
844 bad
.flags
.q
.post_depth_coverage
? " post_depth_coverage" : "");
849 ast_layout_expression::process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
850 const char *qual_indentifier
,
855 bool first_pass
= true;
861 for (exec_node
*node
= layout_const_expressions
.get_head_raw();
862 !node
->is_tail_sentinel(); node
= node
->next
) {
864 exec_list dummy_instructions
;
865 ast_node
*const_expression
= exec_node_data(ast_node
, node
, link
);
867 ir_rvalue
*const ir
= const_expression
->hir(&dummy_instructions
, state
);
869 ir_constant
*const const_int
=
870 ir
->constant_expression_value(ralloc_parent(ir
));
872 if (const_int
== NULL
|| !const_int
->type
->is_integer()) {
873 YYLTYPE loc
= const_expression
->get_location();
874 _mesa_glsl_error(&loc
, state
, "%s must be an integral constant "
875 "expression", qual_indentifier
);
879 if (const_int
->value
.i
[0] < min_value
) {
880 YYLTYPE loc
= const_expression
->get_location();
881 _mesa_glsl_error(&loc
, state
, "%s layout qualifier is invalid "
882 "(%d < %d)", qual_indentifier
,
883 const_int
->value
.i
[0], min_value
);
887 if (!first_pass
&& *value
!= const_int
->value
.u
[0]) {
888 YYLTYPE loc
= const_expression
->get_location();
889 _mesa_glsl_error(&loc
, state
, "%s layout qualifier does not "
890 "match previous declaration (%d vs %d)",
891 qual_indentifier
, *value
, const_int
->value
.i
[0]);
895 *value
= const_int
->value
.u
[0];
898 /* If the location is const (and we've verified that
899 * it is) then no instructions should have been emitted
900 * when we converted it to HIR. If they were emitted,
901 * then either the location isn't const after all, or
902 * we are emitting unnecessary instructions.
904 assert(dummy_instructions
.is_empty());
911 process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
913 const char *qual_indentifier
,
914 ast_expression
*const_expression
,
917 exec_list dummy_instructions
;
919 if (const_expression
== NULL
) {
924 ir_rvalue
*const ir
= const_expression
->hir(&dummy_instructions
, state
);
926 ir_constant
*const const_int
=
927 ir
->constant_expression_value(ralloc_parent(ir
));
928 if (const_int
== NULL
|| !const_int
->type
->is_integer()) {
929 _mesa_glsl_error(loc
, state
, "%s must be an integral constant "
930 "expression", qual_indentifier
);
934 if (const_int
->value
.i
[0] < 0) {
935 _mesa_glsl_error(loc
, state
, "%s layout qualifier is invalid (%d < 0)",
936 qual_indentifier
, const_int
->value
.u
[0]);
940 /* If the location is const (and we've verified that
941 * it is) then no instructions should have been emitted
942 * when we converted it to HIR. If they were emitted,
943 * then either the location isn't const after all, or
944 * we are emitting unnecessary instructions.
946 assert(dummy_instructions
.is_empty());
948 *value
= const_int
->value
.u
[0];