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
;
304 ast_type_qualifier::merge_out_qualifier(YYLTYPE
*loc
,
305 _mesa_glsl_parse_state
*state
,
306 ast_type_qualifier q
,
309 void *mem_ctx
= state
;
310 const bool r
= this->merge_qualifier(loc
, state
, q
);
312 if (state
->stage
== MESA_SHADER_TESS_CTRL
) {
313 node
= new(mem_ctx
) ast_tcs_output_layout(*loc
, q
.vertices
);
320 ast_type_qualifier::merge_in_qualifier(YYLTYPE
*loc
,
321 _mesa_glsl_parse_state
*state
,
322 ast_type_qualifier q
,
325 void *mem_ctx
= state
;
326 bool create_gs_ast
= false;
327 bool create_cs_ast
= false;
328 ast_type_qualifier valid_in_mask
;
329 valid_in_mask
.flags
.i
= 0;
331 switch (state
->stage
) {
332 case MESA_SHADER_TESS_EVAL
:
333 if (q
.flags
.q
.prim_type
) {
334 /* Make sure this is a valid input primitive type. */
335 switch (q
.prim_type
) {
341 _mesa_glsl_error(loc
, state
,
342 "invalid tessellation evaluation "
343 "shader input primitive type");
348 valid_in_mask
.flags
.q
.prim_type
= 1;
349 valid_in_mask
.flags
.q
.vertex_spacing
= 1;
350 valid_in_mask
.flags
.q
.ordering
= 1;
351 valid_in_mask
.flags
.q
.point_mode
= 1;
353 case MESA_SHADER_GEOMETRY
:
354 if (q
.flags
.q
.prim_type
) {
355 /* Make sure this is a valid input primitive type. */
356 switch (q
.prim_type
) {
359 case GL_LINES_ADJACENCY
:
361 case GL_TRIANGLES_ADJACENCY
:
364 _mesa_glsl_error(loc
, state
,
365 "invalid geometry shader input primitive type");
371 q
.flags
.q
.prim_type
&&
372 !state
->in_qualifier
->flags
.q
.prim_type
;
374 valid_in_mask
.flags
.q
.prim_type
= 1;
375 valid_in_mask
.flags
.q
.invocations
= 1;
377 case MESA_SHADER_FRAGMENT
:
378 valid_in_mask
.flags
.q
.early_fragment_tests
= 1;
380 case MESA_SHADER_COMPUTE
:
382 q
.flags
.q
.local_size
!= 0 &&
383 state
->in_qualifier
->flags
.q
.local_size
== 0;
385 valid_in_mask
.flags
.q
.local_size
= 7;
388 _mesa_glsl_error(loc
, state
,
389 "input layout qualifiers only valid in "
390 "geometry, fragment and compute shaders");
394 /* Generate an error when invalid input layout qualifiers are used. */
395 if ((q
.flags
.i
& ~valid_in_mask
.flags
.i
) != 0) {
396 _mesa_glsl_error(loc
, state
,
397 "invalid input layout qualifiers used");
401 /* Input layout qualifiers can be specified multiple
402 * times in separate declarations, as long as they match.
404 if (this->flags
.q
.prim_type
) {
405 if (q
.flags
.q
.prim_type
&&
406 this->prim_type
!= q
.prim_type
) {
407 _mesa_glsl_error(loc
, state
,
408 "conflicting input primitive %s specified",
409 state
->stage
== MESA_SHADER_GEOMETRY
?
412 } else if (q
.flags
.q
.prim_type
) {
413 state
->in_qualifier
->flags
.q
.prim_type
= 1;
414 state
->in_qualifier
->prim_type
= q
.prim_type
;
417 if (this->flags
.q
.invocations
&&
418 q
.flags
.q
.invocations
&&
419 this->invocations
!= q
.invocations
) {
420 _mesa_glsl_error(loc
, state
,
421 "conflicting invocations counts specified");
423 } else if (q
.flags
.q
.invocations
) {
424 this->flags
.q
.invocations
= 1;
425 this->invocations
= q
.invocations
;
428 if (q
.flags
.q
.early_fragment_tests
) {
429 state
->fs_early_fragment_tests
= true;
432 if (this->flags
.q
.vertex_spacing
) {
433 if (q
.flags
.q
.vertex_spacing
&&
434 this->vertex_spacing
!= q
.vertex_spacing
) {
435 _mesa_glsl_error(loc
, state
,
436 "conflicting vertex spacing specified");
438 } else if (q
.flags
.q
.vertex_spacing
) {
439 this->flags
.q
.vertex_spacing
= 1;
440 this->vertex_spacing
= q
.vertex_spacing
;
443 if (this->flags
.q
.ordering
) {
444 if (q
.flags
.q
.ordering
&&
445 this->ordering
!= q
.ordering
) {
446 _mesa_glsl_error(loc
, state
,
447 "conflicting ordering specified");
449 } else if (q
.flags
.q
.ordering
) {
450 this->flags
.q
.ordering
= 1;
451 this->ordering
= q
.ordering
;
454 if (this->flags
.q
.point_mode
) {
455 if (q
.flags
.q
.point_mode
&&
456 this->point_mode
!= q
.point_mode
) {
457 _mesa_glsl_error(loc
, state
,
458 "conflicting point mode specified");
460 } else if (q
.flags
.q
.point_mode
) {
461 this->flags
.q
.point_mode
= 1;
462 this->point_mode
= q
.point_mode
;
466 node
= new(mem_ctx
) ast_gs_input_layout(*loc
, q
.prim_type
);
467 } else if (create_cs_ast
) {
468 /* Infer a local_size of 1 for every unspecified dimension */
469 unsigned local_size
[3];
470 for (int i
= 0; i
< 3; i
++) {
471 if (q
.flags
.q
.local_size
& (1 << i
))
472 local_size
[i
] = q
.local_size
[i
];
476 node
= new(mem_ctx
) ast_cs_input_layout(*loc
, local_size
);