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
.std430
69 || this->flags
.q
.shared
70 || this->flags
.q
.column_major
71 || this->flags
.q
.row_major
72 || this->flags
.q
.packed
73 || this->flags
.q
.explicit_location
74 || this->flags
.q
.explicit_index
75 || this->flags
.q
.explicit_binding
76 || this->flags
.q
.explicit_offset
;
80 ast_type_qualifier::has_storage() const
82 return this->flags
.q
.constant
83 || this->flags
.q
.attribute
84 || this->flags
.q
.varying
87 || this->flags
.q
.uniform
88 || this->flags
.q
.buffer
;
92 ast_type_qualifier::has_auxiliary_storage() const
94 return this->flags
.q
.centroid
95 || this->flags
.q
.sample
96 || this->flags
.q
.patch
;
100 ast_type_qualifier::interpolation_string() const
102 if (this->flags
.q
.smooth
)
104 else if (this->flags
.q
.flat
)
106 else if (this->flags
.q
.noperspective
)
107 return "noperspective";
113 ast_type_qualifier::merge_qualifier(YYLTYPE
*loc
,
114 _mesa_glsl_parse_state
*state
,
115 ast_type_qualifier q
)
117 ast_type_qualifier ubo_mat_mask
;
118 ubo_mat_mask
.flags
.i
= 0;
119 ubo_mat_mask
.flags
.q
.row_major
= 1;
120 ubo_mat_mask
.flags
.q
.column_major
= 1;
122 ast_type_qualifier ubo_layout_mask
;
123 ubo_layout_mask
.flags
.i
= 0;
124 ubo_layout_mask
.flags
.q
.std140
= 1;
125 ubo_layout_mask
.flags
.q
.packed
= 1;
126 ubo_layout_mask
.flags
.q
.shared
= 1;
127 ubo_layout_mask
.flags
.q
.std430
= 1;
129 ast_type_qualifier ubo_binding_mask
;
130 ubo_binding_mask
.flags
.i
= 0;
131 ubo_binding_mask
.flags
.q
.explicit_binding
= 1;
132 ubo_binding_mask
.flags
.q
.explicit_offset
= 1;
134 ast_type_qualifier stream_layout_mask
;
135 stream_layout_mask
.flags
.i
= 0;
136 stream_layout_mask
.flags
.q
.stream
= 1;
138 /* Uniform block layout qualifiers get to overwrite each
139 * other (rightmost having priority), while all other
140 * qualifiers currently don't allow duplicates.
142 ast_type_qualifier allowed_duplicates_mask
;
143 allowed_duplicates_mask
.flags
.i
=
144 ubo_mat_mask
.flags
.i
|
145 ubo_layout_mask
.flags
.i
|
146 ubo_binding_mask
.flags
.i
;
148 /* Geometry shaders can have several layout qualifiers
149 * assigning different stream values.
151 if (state
->stage
== MESA_SHADER_GEOMETRY
)
152 allowed_duplicates_mask
.flags
.i
|=
153 stream_layout_mask
.flags
.i
;
155 if ((this->flags
.i
& q
.flags
.i
& ~allowed_duplicates_mask
.flags
.i
) != 0) {
156 _mesa_glsl_error(loc
, state
,
157 "duplicate layout qualifiers used");
161 if (q
.flags
.q
.prim_type
) {
162 if (this->flags
.q
.prim_type
&& this->prim_type
!= q
.prim_type
) {
163 _mesa_glsl_error(loc
, state
,
164 "conflicting primitive type qualifiers used");
167 this->prim_type
= q
.prim_type
;
170 if (q
.flags
.q
.max_vertices
) {
171 if (this->flags
.q
.max_vertices
&& this->max_vertices
!= q
.max_vertices
) {
172 _mesa_glsl_error(loc
, state
,
173 "geometry shader set conflicting max_vertices "
174 "(%d and %d)", this->max_vertices
, q
.max_vertices
);
177 this->max_vertices
= q
.max_vertices
;
180 if (q
.flags
.q
.invocations
) {
181 if (this->flags
.q
.invocations
&& this->invocations
!= q
.invocations
) {
182 _mesa_glsl_error(loc
, state
,
183 "geometry shader set conflicting invocations "
184 "(%d and %d)", this->invocations
, q
.invocations
);
187 this->invocations
= q
.invocations
;
190 if (state
->stage
== MESA_SHADER_GEOMETRY
&&
191 state
->has_explicit_attrib_stream()) {
192 if (q
.flags
.q
.stream
&& q
.stream
>= state
->ctx
->Const
.MaxVertexStreams
) {
193 _mesa_glsl_error(loc
, state
,
194 "`stream' value is larger than MAX_VERTEX_STREAMS - 1 "
196 q
.stream
, state
->ctx
->Const
.MaxVertexStreams
- 1);
198 if (this->flags
.q
.explicit_stream
&&
199 this->stream
>= state
->ctx
->Const
.MaxVertexStreams
) {
200 _mesa_glsl_error(loc
, state
,
201 "`stream' value is larger than MAX_VERTEX_STREAMS - 1 "
203 this->stream
, state
->ctx
->Const
.MaxVertexStreams
- 1);
206 if (!this->flags
.q
.explicit_stream
) {
207 if (q
.flags
.q
.stream
) {
208 this->flags
.q
.stream
= 1;
209 this->stream
= q
.stream
;
210 } else if (!this->flags
.q
.stream
&& this->flags
.q
.out
) {
211 /* Assign default global stream value */
212 this->flags
.q
.stream
= 1;
213 this->stream
= state
->out_qualifier
->stream
;
216 if (q
.flags
.q
.explicit_stream
) {
217 _mesa_glsl_error(loc
, state
,
218 "duplicate layout `stream' qualifier");
223 if (q
.flags
.q
.vertices
) {
224 if (this->flags
.q
.vertices
&& this->vertices
!= q
.vertices
) {
225 _mesa_glsl_error(loc
, state
,
226 "tessellation control shader set conflicting "
227 "vertices (%d and %d)",
228 this->vertices
, q
.vertices
);
231 this->vertices
= q
.vertices
;
234 if (q
.flags
.q
.vertex_spacing
) {
235 if (this->flags
.q
.vertex_spacing
&& this->vertex_spacing
!= q
.vertex_spacing
) {
236 _mesa_glsl_error(loc
, state
,
237 "conflicting vertex spacing used");
240 this->vertex_spacing
= q
.vertex_spacing
;
243 if (q
.flags
.q
.ordering
) {
244 if (this->flags
.q
.ordering
&& this->ordering
!= q
.ordering
) {
245 _mesa_glsl_error(loc
, state
,
246 "conflicting ordering used");
249 this->ordering
= q
.ordering
;
252 if (q
.flags
.q
.point_mode
) {
253 if (this->flags
.q
.point_mode
&& this->point_mode
!= q
.point_mode
) {
254 _mesa_glsl_error(loc
, state
,
255 "conflicting point mode used");
258 this->point_mode
= q
.point_mode
;
261 if ((q
.flags
.i
& ubo_mat_mask
.flags
.i
) != 0)
262 this->flags
.i
&= ~ubo_mat_mask
.flags
.i
;
263 if ((q
.flags
.i
& ubo_layout_mask
.flags
.i
) != 0)
264 this->flags
.i
&= ~ubo_layout_mask
.flags
.i
;
266 for (int i
= 0; i
< 3; i
++) {
267 if (q
.flags
.q
.local_size
& (1 << i
)) {
268 if ((this->flags
.q
.local_size
& (1 << i
)) &&
269 this->local_size
[i
] != q
.local_size
[i
]) {
270 _mesa_glsl_error(loc
, state
,
271 "compute shader set conflicting values for "
272 "local_size_%c (%d and %d)", 'x' + i
,
273 this->local_size
[i
], q
.local_size
[i
]);
276 this->local_size
[i
] = q
.local_size
[i
];
280 this->flags
.i
|= q
.flags
.i
;
282 if (q
.flags
.q
.explicit_location
)
283 this->location
= q
.location
;
285 if (q
.flags
.q
.explicit_index
)
286 this->index
= q
.index
;
288 if (q
.flags
.q
.explicit_binding
)
289 this->binding
= q
.binding
;
291 if (q
.flags
.q
.explicit_offset
)
292 this->offset
= q
.offset
;
294 if (q
.precision
!= ast_precision_none
)
295 this->precision
= q
.precision
;
297 if (q
.flags
.q
.explicit_image_format
) {
298 this->image_format
= q
.image_format
;
299 this->image_base_type
= q
.image_base_type
;
306 ast_type_qualifier::merge_out_qualifier(YYLTYPE
*loc
,
307 _mesa_glsl_parse_state
*state
,
308 ast_type_qualifier q
,
311 void *mem_ctx
= state
;
312 const bool r
= this->merge_qualifier(loc
, state
, q
);
314 if (state
->stage
== MESA_SHADER_TESS_CTRL
) {
315 node
= new(mem_ctx
) ast_tcs_output_layout(*loc
, q
.vertices
);
322 ast_type_qualifier::merge_in_qualifier(YYLTYPE
*loc
,
323 _mesa_glsl_parse_state
*state
,
324 ast_type_qualifier q
,
327 void *mem_ctx
= state
;
328 bool create_gs_ast
= false;
329 bool create_cs_ast
= false;
330 ast_type_qualifier valid_in_mask
;
331 valid_in_mask
.flags
.i
= 0;
333 switch (state
->stage
) {
334 case MESA_SHADER_TESS_EVAL
:
335 if (q
.flags
.q
.prim_type
) {
336 /* Make sure this is a valid input primitive type. */
337 switch (q
.prim_type
) {
343 _mesa_glsl_error(loc
, state
,
344 "invalid tessellation evaluation "
345 "shader input primitive type");
350 valid_in_mask
.flags
.q
.prim_type
= 1;
351 valid_in_mask
.flags
.q
.vertex_spacing
= 1;
352 valid_in_mask
.flags
.q
.ordering
= 1;
353 valid_in_mask
.flags
.q
.point_mode
= 1;
355 case MESA_SHADER_GEOMETRY
:
356 if (q
.flags
.q
.prim_type
) {
357 /* Make sure this is a valid input primitive type. */
358 switch (q
.prim_type
) {
361 case GL_LINES_ADJACENCY
:
363 case GL_TRIANGLES_ADJACENCY
:
366 _mesa_glsl_error(loc
, state
,
367 "invalid geometry shader input primitive type");
373 q
.flags
.q
.prim_type
&&
374 !state
->in_qualifier
->flags
.q
.prim_type
;
376 valid_in_mask
.flags
.q
.prim_type
= 1;
377 valid_in_mask
.flags
.q
.invocations
= 1;
379 case MESA_SHADER_FRAGMENT
:
380 valid_in_mask
.flags
.q
.early_fragment_tests
= 1;
382 case MESA_SHADER_COMPUTE
:
384 q
.flags
.q
.local_size
!= 0 &&
385 state
->in_qualifier
->flags
.q
.local_size
== 0;
387 valid_in_mask
.flags
.q
.local_size
= 7;
390 _mesa_glsl_error(loc
, state
,
391 "input layout qualifiers only valid in "
392 "geometry, fragment and compute shaders");
396 /* Generate an error when invalid input layout qualifiers are used. */
397 if ((q
.flags
.i
& ~valid_in_mask
.flags
.i
) != 0) {
398 _mesa_glsl_error(loc
, state
,
399 "invalid input layout qualifiers used");
403 /* Input layout qualifiers can be specified multiple
404 * times in separate declarations, as long as they match.
406 if (this->flags
.q
.prim_type
) {
407 if (q
.flags
.q
.prim_type
&&
408 this->prim_type
!= q
.prim_type
) {
409 _mesa_glsl_error(loc
, state
,
410 "conflicting input primitive %s specified",
411 state
->stage
== MESA_SHADER_GEOMETRY
?
414 } else if (q
.flags
.q
.prim_type
) {
415 state
->in_qualifier
->flags
.q
.prim_type
= 1;
416 state
->in_qualifier
->prim_type
= q
.prim_type
;
419 if (this->flags
.q
.invocations
&&
420 q
.flags
.q
.invocations
&&
421 this->invocations
!= q
.invocations
) {
422 _mesa_glsl_error(loc
, state
,
423 "conflicting invocations counts specified");
425 } else if (q
.flags
.q
.invocations
) {
426 this->flags
.q
.invocations
= 1;
427 this->invocations
= q
.invocations
;
430 if (q
.flags
.q
.early_fragment_tests
) {
431 state
->fs_early_fragment_tests
= true;
434 if (this->flags
.q
.vertex_spacing
) {
435 if (q
.flags
.q
.vertex_spacing
&&
436 this->vertex_spacing
!= q
.vertex_spacing
) {
437 _mesa_glsl_error(loc
, state
,
438 "conflicting vertex spacing specified");
440 } else if (q
.flags
.q
.vertex_spacing
) {
441 this->flags
.q
.vertex_spacing
= 1;
442 this->vertex_spacing
= q
.vertex_spacing
;
445 if (this->flags
.q
.ordering
) {
446 if (q
.flags
.q
.ordering
&&
447 this->ordering
!= q
.ordering
) {
448 _mesa_glsl_error(loc
, state
,
449 "conflicting ordering specified");
451 } else if (q
.flags
.q
.ordering
) {
452 this->flags
.q
.ordering
= 1;
453 this->ordering
= q
.ordering
;
456 if (this->flags
.q
.point_mode
) {
457 if (q
.flags
.q
.point_mode
&&
458 this->point_mode
!= q
.point_mode
) {
459 _mesa_glsl_error(loc
, state
,
460 "conflicting point mode specified");
462 } else if (q
.flags
.q
.point_mode
) {
463 this->flags
.q
.point_mode
= 1;
464 this->point_mode
= q
.point_mode
;
468 node
= new(mem_ctx
) ast_gs_input_layout(*loc
, q
.prim_type
);
469 } else if (create_cs_ast
) {
470 /* Infer a local_size of 1 for every unspecified dimension */
471 unsigned local_size
[3];
472 for (int i
= 0; i
< 3; i
++) {
473 if (q
.flags
.q
.local_size
& (1 << i
))
474 local_size
[i
] = q
.local_size
[i
];
478 node
= new(mem_ctx
) ast_cs_input_layout(*loc
, local_size
);