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() 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 subroutine_only
.flags
.q
.subroutine_def
= 1;
48 return (this->qualifier
.flags
.i
& ~subroutine_only
.flags
.i
) != 0;
51 bool ast_type_qualifier::has_interpolation() const
53 return this->flags
.q
.smooth
55 || this->flags
.q
.noperspective
;
59 ast_type_qualifier::has_layout() const
61 return this->flags
.q
.origin_upper_left
62 || this->flags
.q
.pixel_center_integer
63 || this->flags
.q
.depth_any
64 || this->flags
.q
.depth_greater
65 || this->flags
.q
.depth_less
66 || this->flags
.q
.depth_unchanged
67 || this->flags
.q
.std140
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_location
73 || this->flags
.q
.explicit_index
74 || this->flags
.q
.explicit_binding
75 || this->flags
.q
.explicit_offset
;
79 ast_type_qualifier::has_storage() const
81 return this->flags
.q
.constant
82 || this->flags
.q
.attribute
83 || this->flags
.q
.varying
86 || this->flags
.q
.uniform
87 || this->flags
.q
.buffer
;
91 ast_type_qualifier::has_auxiliary_storage() const
93 return this->flags
.q
.centroid
94 || this->flags
.q
.sample
95 || this->flags
.q
.patch
;
99 ast_type_qualifier::interpolation_string() const
101 if (this->flags
.q
.smooth
)
103 else if (this->flags
.q
.flat
)
105 else if (this->flags
.q
.noperspective
)
106 return "noperspective";
112 ast_type_qualifier::merge_qualifier(YYLTYPE
*loc
,
113 _mesa_glsl_parse_state
*state
,
114 ast_type_qualifier q
)
116 ast_type_qualifier ubo_mat_mask
;
117 ubo_mat_mask
.flags
.i
= 0;
118 ubo_mat_mask
.flags
.q
.row_major
= 1;
119 ubo_mat_mask
.flags
.q
.column_major
= 1;
121 ast_type_qualifier ubo_layout_mask
;
122 ubo_layout_mask
.flags
.i
= 0;
123 ubo_layout_mask
.flags
.q
.std140
= 1;
124 ubo_layout_mask
.flags
.q
.packed
= 1;
125 ubo_layout_mask
.flags
.q
.shared
= 1;
127 ast_type_qualifier ubo_binding_mask
;
128 ubo_binding_mask
.flags
.i
= 0;
129 ubo_binding_mask
.flags
.q
.explicit_binding
= 1;
130 ubo_binding_mask
.flags
.q
.explicit_offset
= 1;
132 ast_type_qualifier stream_layout_mask
;
133 stream_layout_mask
.flags
.i
= 0;
134 stream_layout_mask
.flags
.q
.stream
= 1;
136 /* Uniform block layout qualifiers get to overwrite each
137 * other (rightmost having priority), while all other
138 * qualifiers currently don't allow duplicates.
140 ast_type_qualifier allowed_duplicates_mask
;
141 allowed_duplicates_mask
.flags
.i
=
142 ubo_mat_mask
.flags
.i
|
143 ubo_layout_mask
.flags
.i
|
144 ubo_binding_mask
.flags
.i
;
146 /* Geometry shaders can have several layout qualifiers
147 * assigning different stream values.
149 if (state
->stage
== MESA_SHADER_GEOMETRY
)
150 allowed_duplicates_mask
.flags
.i
|=
151 stream_layout_mask
.flags
.i
;
153 if ((this->flags
.i
& q
.flags
.i
& ~allowed_duplicates_mask
.flags
.i
) != 0) {
154 _mesa_glsl_error(loc
, state
,
155 "duplicate layout qualifiers used");
159 if (q
.flags
.q
.prim_type
) {
160 if (this->flags
.q
.prim_type
&& this->prim_type
!= q
.prim_type
) {
161 _mesa_glsl_error(loc
, state
,
162 "conflicting primitive type qualifiers used");
165 this->prim_type
= q
.prim_type
;
168 if (q
.flags
.q
.max_vertices
) {
169 if (this->flags
.q
.max_vertices
&& this->max_vertices
!= q
.max_vertices
) {
170 _mesa_glsl_error(loc
, state
,
171 "geometry shader set conflicting max_vertices "
172 "(%d and %d)", this->max_vertices
, q
.max_vertices
);
175 this->max_vertices
= q
.max_vertices
;
178 if (q
.flags
.q
.invocations
) {
179 if (this->flags
.q
.invocations
&& this->invocations
!= q
.invocations
) {
180 _mesa_glsl_error(loc
, state
,
181 "geometry shader set conflicting invocations "
182 "(%d and %d)", this->invocations
, q
.invocations
);
185 this->invocations
= q
.invocations
;
188 if (state
->stage
== MESA_SHADER_GEOMETRY
&&
189 state
->has_explicit_attrib_stream()) {
190 if (q
.flags
.q
.stream
&& q
.stream
>= state
->ctx
->Const
.MaxVertexStreams
) {
191 _mesa_glsl_error(loc
, state
,
192 "`stream' value is larger than MAX_VERTEX_STREAMS - 1 "
194 q
.stream
, state
->ctx
->Const
.MaxVertexStreams
- 1);
196 if (this->flags
.q
.explicit_stream
&&
197 this->stream
>= state
->ctx
->Const
.MaxVertexStreams
) {
198 _mesa_glsl_error(loc
, state
,
199 "`stream' value is larger than MAX_VERTEX_STREAMS - 1 "
201 this->stream
, state
->ctx
->Const
.MaxVertexStreams
- 1);
204 if (!this->flags
.q
.explicit_stream
) {
205 if (q
.flags
.q
.stream
) {
206 this->flags
.q
.stream
= 1;
207 this->stream
= q
.stream
;
208 } else if (!this->flags
.q
.stream
&& this->flags
.q
.out
) {
209 /* Assign default global stream value */
210 this->flags
.q
.stream
= 1;
211 this->stream
= state
->out_qualifier
->stream
;
214 if (q
.flags
.q
.explicit_stream
) {
215 _mesa_glsl_error(loc
, state
,
216 "duplicate layout `stream' qualifier");
221 if (q
.flags
.q
.vertices
) {
222 if (this->flags
.q
.vertices
&& this->vertices
!= q
.vertices
) {
223 _mesa_glsl_error(loc
, state
,
224 "tessellation control shader set conflicting "
225 "vertices (%d and %d)",
226 this->vertices
, q
.vertices
);
229 this->vertices
= q
.vertices
;
232 if (q
.flags
.q
.vertex_spacing
) {
233 if (this->flags
.q
.vertex_spacing
&& this->vertex_spacing
!= q
.vertex_spacing
) {
234 _mesa_glsl_error(loc
, state
,
235 "conflicting vertex spacing used");
238 this->vertex_spacing
= q
.vertex_spacing
;
241 if (q
.flags
.q
.ordering
) {
242 if (this->flags
.q
.ordering
&& this->ordering
!= q
.ordering
) {
243 _mesa_glsl_error(loc
, state
,
244 "conflicting ordering used");
247 this->ordering
= q
.ordering
;
250 if (q
.flags
.q
.point_mode
) {
251 if (this->flags
.q
.point_mode
&& this->point_mode
!= q
.point_mode
) {
252 _mesa_glsl_error(loc
, state
,
253 "conflicting point mode used");
256 this->point_mode
= q
.point_mode
;
259 if ((q
.flags
.i
& ubo_mat_mask
.flags
.i
) != 0)
260 this->flags
.i
&= ~ubo_mat_mask
.flags
.i
;
261 if ((q
.flags
.i
& ubo_layout_mask
.flags
.i
) != 0)
262 this->flags
.i
&= ~ubo_layout_mask
.flags
.i
;
264 for (int i
= 0; i
< 3; i
++) {
265 if (q
.flags
.q
.local_size
& (1 << i
)) {
266 if ((this->flags
.q
.local_size
& (1 << i
)) &&
267 this->local_size
[i
] != q
.local_size
[i
]) {
268 _mesa_glsl_error(loc
, state
,
269 "compute shader set conflicting values for "
270 "local_size_%c (%d and %d)", 'x' + i
,
271 this->local_size
[i
], q
.local_size
[i
]);
274 this->local_size
[i
] = q
.local_size
[i
];
278 this->flags
.i
|= q
.flags
.i
;
280 if (q
.flags
.q
.explicit_location
)
281 this->location
= q
.location
;
283 if (q
.flags
.q
.explicit_index
)
284 this->index
= q
.index
;
286 if (q
.flags
.q
.explicit_binding
)
287 this->binding
= q
.binding
;
289 if (q
.flags
.q
.explicit_offset
)
290 this->offset
= q
.offset
;
292 if (q
.precision
!= ast_precision_none
)
293 this->precision
= q
.precision
;
295 if (q
.flags
.q
.explicit_image_format
) {
296 this->image_format
= q
.image_format
;
297 this->image_base_type
= q
.image_base_type
;
300 if (q
.flags
.q
.vk_set
) {
302 this->binding
= q
.binding
;
309 ast_type_qualifier::merge_out_qualifier(YYLTYPE
*loc
,
310 _mesa_glsl_parse_state
*state
,
311 ast_type_qualifier q
,
314 void *mem_ctx
= state
;
315 const bool r
= this->merge_qualifier(loc
, state
, q
);
317 if (state
->stage
== MESA_SHADER_TESS_CTRL
) {
318 node
= new(mem_ctx
) ast_tcs_output_layout(*loc
, q
.vertices
);
325 ast_type_qualifier::merge_in_qualifier(YYLTYPE
*loc
,
326 _mesa_glsl_parse_state
*state
,
327 ast_type_qualifier q
,
330 void *mem_ctx
= state
;
331 bool create_gs_ast
= false;
332 bool create_cs_ast
= false;
333 ast_type_qualifier valid_in_mask
;
334 valid_in_mask
.flags
.i
= 0;
336 switch (state
->stage
) {
337 case MESA_SHADER_TESS_EVAL
:
338 if (q
.flags
.q
.prim_type
) {
339 /* Make sure this is a valid input primitive type. */
340 switch (q
.prim_type
) {
346 _mesa_glsl_error(loc
, state
,
347 "invalid tessellation evaluation "
348 "shader input primitive type");
353 valid_in_mask
.flags
.q
.prim_type
= 1;
354 valid_in_mask
.flags
.q
.vertex_spacing
= 1;
355 valid_in_mask
.flags
.q
.ordering
= 1;
356 valid_in_mask
.flags
.q
.point_mode
= 1;
358 case MESA_SHADER_GEOMETRY
:
359 if (q
.flags
.q
.prim_type
) {
360 /* Make sure this is a valid input primitive type. */
361 switch (q
.prim_type
) {
364 case GL_LINES_ADJACENCY
:
366 case GL_TRIANGLES_ADJACENCY
:
369 _mesa_glsl_error(loc
, state
,
370 "invalid geometry shader input primitive type");
376 q
.flags
.q
.prim_type
&&
377 !state
->in_qualifier
->flags
.q
.prim_type
;
379 valid_in_mask
.flags
.q
.prim_type
= 1;
380 valid_in_mask
.flags
.q
.invocations
= 1;
382 case MESA_SHADER_FRAGMENT
:
383 valid_in_mask
.flags
.q
.early_fragment_tests
= 1;
385 case MESA_SHADER_COMPUTE
:
387 q
.flags
.q
.local_size
!= 0 &&
388 state
->in_qualifier
->flags
.q
.local_size
== 0;
390 valid_in_mask
.flags
.q
.local_size
= 7;
393 _mesa_glsl_error(loc
, state
,
394 "input layout qualifiers only valid in "
395 "geometry, fragment and compute shaders");
399 /* Generate an error when invalid input layout qualifiers are used. */
400 if ((q
.flags
.i
& ~valid_in_mask
.flags
.i
) != 0) {
401 _mesa_glsl_error(loc
, state
,
402 "invalid input layout qualifiers used");
406 /* Input layout qualifiers can be specified multiple
407 * times in separate declarations, as long as they match.
409 if (this->flags
.q
.prim_type
) {
410 if (q
.flags
.q
.prim_type
&&
411 this->prim_type
!= q
.prim_type
) {
412 _mesa_glsl_error(loc
, state
,
413 "conflicting input primitive %s specified",
414 state
->stage
== MESA_SHADER_GEOMETRY
?
417 } else if (q
.flags
.q
.prim_type
) {
418 state
->in_qualifier
->flags
.q
.prim_type
= 1;
419 state
->in_qualifier
->prim_type
= q
.prim_type
;
422 if (this->flags
.q
.invocations
&&
423 q
.flags
.q
.invocations
&&
424 this->invocations
!= q
.invocations
) {
425 _mesa_glsl_error(loc
, state
,
426 "conflicting invocations counts specified");
428 } else if (q
.flags
.q
.invocations
) {
429 this->flags
.q
.invocations
= 1;
430 this->invocations
= q
.invocations
;
433 if (q
.flags
.q
.early_fragment_tests
) {
434 state
->fs_early_fragment_tests
= true;
437 if (this->flags
.q
.vertex_spacing
) {
438 if (q
.flags
.q
.vertex_spacing
&&
439 this->vertex_spacing
!= q
.vertex_spacing
) {
440 _mesa_glsl_error(loc
, state
,
441 "conflicting vertex spacing specified");
443 } else if (q
.flags
.q
.vertex_spacing
) {
444 this->flags
.q
.vertex_spacing
= 1;
445 this->vertex_spacing
= q
.vertex_spacing
;
448 if (this->flags
.q
.ordering
) {
449 if (q
.flags
.q
.ordering
&&
450 this->ordering
!= q
.ordering
) {
451 _mesa_glsl_error(loc
, state
,
452 "conflicting ordering specified");
454 } else if (q
.flags
.q
.ordering
) {
455 this->flags
.q
.ordering
= 1;
456 this->ordering
= q
.ordering
;
459 if (this->flags
.q
.point_mode
) {
460 if (q
.flags
.q
.point_mode
&&
461 this->point_mode
!= q
.point_mode
) {
462 _mesa_glsl_error(loc
, state
,
463 "conflicting point mode specified");
465 } else if (q
.flags
.q
.point_mode
) {
466 this->flags
.q
.point_mode
= 1;
467 this->point_mode
= q
.point_mode
;
471 node
= new(mem_ctx
) ast_gs_input_layout(*loc
, q
.prim_type
);
472 } else if (create_cs_ast
) {
473 /* Infer a local_size of 1 for every unspecified dimension */
474 unsigned local_size
[3];
475 for (int i
= 0; i
< 3; i
++) {
476 if (q
.flags
.q
.local_size
& (1 << i
))
477 local_size
[i
] = q
.local_size
[i
];
481 node
= new(mem_ctx
) ast_cs_input_layout(*loc
, local_size
);