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 subroutine_only
.flags
.q
.subroutine_def
= 1;
48 if (state
->has_explicit_uniform_location()) {
49 subroutine_only
.flags
.q
.explicit_index
= 1;
51 return (this->qualifier
.flags
.i
& ~subroutine_only
.flags
.i
) != 0;
54 bool ast_type_qualifier::has_interpolation() const
56 return this->flags
.q
.smooth
58 || this->flags
.q
.noperspective
;
62 ast_type_qualifier::has_layout() const
64 return this->flags
.q
.origin_upper_left
65 || this->flags
.q
.pixel_center_integer
66 || this->flags
.q
.depth_any
67 || this->flags
.q
.depth_greater
68 || this->flags
.q
.depth_less
69 || this->flags
.q
.depth_unchanged
70 || this->flags
.q
.std140
71 || this->flags
.q
.std430
72 || this->flags
.q
.shared
73 || this->flags
.q
.column_major
74 || this->flags
.q
.row_major
75 || this->flags
.q
.packed
76 || this->flags
.q
.explicit_location
77 || this->flags
.q
.explicit_image_format
78 || this->flags
.q
.explicit_index
79 || this->flags
.q
.explicit_binding
80 || this->flags
.q
.explicit_offset
81 || this->flags
.q
.explicit_stream
;
85 ast_type_qualifier::has_storage() const
87 return this->flags
.q
.constant
88 || this->flags
.q
.attribute
89 || this->flags
.q
.varying
92 || this->flags
.q
.uniform
93 || this->flags
.q
.buffer
94 || this->flags
.q
.shared_storage
;
98 ast_type_qualifier::has_auxiliary_storage() const
100 return this->flags
.q
.centroid
101 || this->flags
.q
.sample
102 || this->flags
.q
.patch
;
106 * This function merges both duplicate identifies within a single layout and
107 * multiple layout qualifiers on a single variable declaration. The
108 * is_single_layout_merge param is used differentiate between the two.
111 ast_type_qualifier::merge_qualifier(YYLTYPE
*loc
,
112 _mesa_glsl_parse_state
*state
,
113 const ast_type_qualifier
&q
,
114 bool is_single_layout_merge
)
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;
126 ubo_layout_mask
.flags
.q
.std430
= 1;
128 ast_type_qualifier ubo_binding_mask
;
129 ubo_binding_mask
.flags
.i
= 0;
130 ubo_binding_mask
.flags
.q
.explicit_binding
= 1;
131 ubo_binding_mask
.flags
.q
.explicit_offset
= 1;
133 ast_type_qualifier stream_layout_mask
;
134 stream_layout_mask
.flags
.i
= 0;
135 stream_layout_mask
.flags
.q
.stream
= 1;
137 /* Uniform block layout qualifiers get to overwrite each
138 * other (rightmost having priority), while all other
139 * qualifiers currently don't allow duplicates.
141 ast_type_qualifier allowed_duplicates_mask
;
142 allowed_duplicates_mask
.flags
.i
=
143 ubo_mat_mask
.flags
.i
|
144 ubo_layout_mask
.flags
.i
|
145 ubo_binding_mask
.flags
.i
;
147 /* Geometry shaders can have several layout qualifiers
148 * assigning different stream values.
150 if (state
->stage
== MESA_SHADER_GEOMETRY
)
151 allowed_duplicates_mask
.flags
.i
|=
152 stream_layout_mask
.flags
.i
;
154 if (is_single_layout_merge
&& !state
->has_enhanced_layouts() &&
155 (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->max_vertices
) {
172 this->max_vertices
->merge_qualifier(q
.max_vertices
);
174 this->max_vertices
= q
.max_vertices
;
178 if (q
.flags
.q
.subroutine_def
) {
179 if (this->flags
.q
.subroutine_def
) {
180 _mesa_glsl_error(loc
, state
,
181 "conflicting subroutine qualifiers used");
183 this->subroutine_list
= q
.subroutine_list
;
187 if (q
.flags
.q
.invocations
) {
188 if (this->invocations
) {
189 this->invocations
->merge_qualifier(q
.invocations
);
191 this->invocations
= q
.invocations
;
195 if (state
->stage
== MESA_SHADER_GEOMETRY
&&
196 state
->has_explicit_attrib_stream()) {
197 if (!this->flags
.q
.explicit_stream
) {
198 if (q
.flags
.q
.stream
) {
199 this->flags
.q
.stream
= 1;
200 this->stream
= q
.stream
;
201 } else if (!this->flags
.q
.stream
&& this->flags
.q
.out
) {
202 /* Assign default global stream value */
203 this->flags
.q
.stream
= 1;
204 this->stream
= state
->out_qualifier
->stream
;
209 if (q
.flags
.q
.vertices
) {
210 if (this->vertices
) {
211 this->vertices
->merge_qualifier(q
.vertices
);
213 this->vertices
= q
.vertices
;
217 if (q
.flags
.q
.vertex_spacing
) {
218 if (this->flags
.q
.vertex_spacing
&& this->vertex_spacing
!= q
.vertex_spacing
) {
219 _mesa_glsl_error(loc
, state
,
220 "conflicting vertex spacing used");
223 this->vertex_spacing
= q
.vertex_spacing
;
226 if (q
.flags
.q
.ordering
) {
227 if (this->flags
.q
.ordering
&& this->ordering
!= q
.ordering
) {
228 _mesa_glsl_error(loc
, state
,
229 "conflicting ordering used");
232 this->ordering
= q
.ordering
;
235 if (q
.flags
.q
.point_mode
) {
236 if (this->flags
.q
.point_mode
&& this->point_mode
!= q
.point_mode
) {
237 _mesa_glsl_error(loc
, state
,
238 "conflicting point mode used");
241 this->point_mode
= q
.point_mode
;
244 if ((q
.flags
.i
& ubo_mat_mask
.flags
.i
) != 0)
245 this->flags
.i
&= ~ubo_mat_mask
.flags
.i
;
246 if ((q
.flags
.i
& ubo_layout_mask
.flags
.i
) != 0)
247 this->flags
.i
&= ~ubo_layout_mask
.flags
.i
;
249 for (int i
= 0; i
< 3; i
++) {
250 if (q
.flags
.q
.local_size
& (1 << i
)) {
251 if (this->local_size
[i
]) {
252 this->local_size
[i
]->merge_qualifier(q
.local_size
[i
]);
254 this->local_size
[i
] = q
.local_size
[i
];
259 this->flags
.i
|= q
.flags
.i
;
261 if (q
.flags
.q
.explicit_location
)
262 this->location
= q
.location
;
264 if (q
.flags
.q
.explicit_index
)
265 this->index
= q
.index
;
267 if (q
.flags
.q
.explicit_binding
)
268 this->binding
= q
.binding
;
270 if (q
.flags
.q
.explicit_offset
)
271 this->offset
= q
.offset
;
273 if (q
.precision
!= ast_precision_none
)
274 this->precision
= q
.precision
;
276 if (q
.flags
.q
.explicit_image_format
) {
277 this->image_format
= q
.image_format
;
278 this->image_base_type
= q
.image_base_type
;
285 ast_type_qualifier::merge_out_qualifier(YYLTYPE
*loc
,
286 _mesa_glsl_parse_state
*state
,
287 const ast_type_qualifier
&q
,
288 ast_node
* &node
, bool create_node
)
290 void *mem_ctx
= state
;
291 const bool r
= this->merge_qualifier(loc
, state
, q
, false);
293 if (state
->stage
== MESA_SHADER_GEOMETRY
) {
294 if (q
.flags
.q
.prim_type
) {
295 /* Make sure this is a valid output primitive type. */
296 switch (q
.prim_type
) {
299 case GL_TRIANGLE_STRIP
:
302 _mesa_glsl_error(loc
, state
, "invalid geometry shader output "
308 /* Allow future assigments of global out's stream id value */
309 this->flags
.q
.explicit_stream
= 0;
310 } else if (state
->stage
== MESA_SHADER_TESS_CTRL
) {
312 node
= new(mem_ctx
) ast_tcs_output_layout(*loc
);
315 _mesa_glsl_error(loc
, state
, "out layout qualifiers only valid in "
316 "tessellation control or geometry shaders");
323 ast_type_qualifier::merge_in_qualifier(YYLTYPE
*loc
,
324 _mesa_glsl_parse_state
*state
,
325 const ast_type_qualifier
&q
,
326 ast_node
* &node
, bool create_node
)
328 void *mem_ctx
= state
;
329 bool create_gs_ast
= false;
330 bool create_cs_ast
= false;
331 ast_type_qualifier valid_in_mask
;
332 valid_in_mask
.flags
.i
= 0;
334 switch (state
->stage
) {
335 case MESA_SHADER_TESS_EVAL
:
336 if (q
.flags
.q
.prim_type
) {
337 /* Make sure this is a valid input primitive type. */
338 switch (q
.prim_type
) {
344 _mesa_glsl_error(loc
, state
,
345 "invalid tessellation evaluation "
346 "shader input primitive type");
351 valid_in_mask
.flags
.q
.prim_type
= 1;
352 valid_in_mask
.flags
.q
.vertex_spacing
= 1;
353 valid_in_mask
.flags
.q
.ordering
= 1;
354 valid_in_mask
.flags
.q
.point_mode
= 1;
356 case MESA_SHADER_GEOMETRY
:
357 if (q
.flags
.q
.prim_type
) {
358 /* Make sure this is a valid input primitive type. */
359 switch (q
.prim_type
) {
362 case GL_LINES_ADJACENCY
:
364 case GL_TRIANGLES_ADJACENCY
:
367 _mesa_glsl_error(loc
, state
,
368 "invalid geometry shader input primitive type");
374 q
.flags
.q
.prim_type
&&
375 !state
->in_qualifier
->flags
.q
.prim_type
;
377 valid_in_mask
.flags
.q
.prim_type
= 1;
378 valid_in_mask
.flags
.q
.invocations
= 1;
380 case MESA_SHADER_FRAGMENT
:
381 valid_in_mask
.flags
.q
.early_fragment_tests
= 1;
383 case MESA_SHADER_COMPUTE
:
385 q
.flags
.q
.local_size
!= 0 &&
386 state
->in_qualifier
->flags
.q
.local_size
== 0;
388 valid_in_mask
.flags
.q
.local_size
= 7;
391 _mesa_glsl_error(loc
, state
,
392 "input layout qualifiers only valid in "
393 "geometry, fragment and compute shaders");
397 /* Generate an error when invalid input layout qualifiers are used. */
398 if ((q
.flags
.i
& ~valid_in_mask
.flags
.i
) != 0) {
399 _mesa_glsl_error(loc
, state
,
400 "invalid input layout qualifiers used");
404 /* Input layout qualifiers can be specified multiple
405 * times in separate declarations, as long as they match.
407 if (this->flags
.q
.prim_type
) {
408 if (q
.flags
.q
.prim_type
&&
409 this->prim_type
!= q
.prim_type
) {
410 _mesa_glsl_error(loc
, state
,
411 "conflicting input primitive %s specified",
412 state
->stage
== MESA_SHADER_GEOMETRY
?
415 } else if (q
.flags
.q
.prim_type
) {
416 state
->in_qualifier
->flags
.q
.prim_type
= 1;
417 state
->in_qualifier
->prim_type
= q
.prim_type
;
420 if (q
.flags
.q
.invocations
) {
421 this->flags
.q
.invocations
= 1;
422 if (this->invocations
) {
423 this->invocations
->merge_qualifier(q
.invocations
);
425 this->invocations
= q
.invocations
;
429 if (q
.flags
.q
.early_fragment_tests
) {
430 state
->fs_early_fragment_tests
= true;
433 if (this->flags
.q
.vertex_spacing
) {
434 if (q
.flags
.q
.vertex_spacing
&&
435 this->vertex_spacing
!= q
.vertex_spacing
) {
436 _mesa_glsl_error(loc
, state
,
437 "conflicting vertex spacing specified");
439 } else if (q
.flags
.q
.vertex_spacing
) {
440 this->flags
.q
.vertex_spacing
= 1;
441 this->vertex_spacing
= q
.vertex_spacing
;
444 if (this->flags
.q
.ordering
) {
445 if (q
.flags
.q
.ordering
&&
446 this->ordering
!= q
.ordering
) {
447 _mesa_glsl_error(loc
, state
,
448 "conflicting ordering specified");
450 } else if (q
.flags
.q
.ordering
) {
451 this->flags
.q
.ordering
= 1;
452 this->ordering
= q
.ordering
;
455 if (this->flags
.q
.point_mode
) {
456 if (q
.flags
.q
.point_mode
&&
457 this->point_mode
!= q
.point_mode
) {
458 _mesa_glsl_error(loc
, state
,
459 "conflicting point mode specified");
461 } else if (q
.flags
.q
.point_mode
) {
462 this->flags
.q
.point_mode
= 1;
463 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 node
= new(mem_ctx
) ast_cs_input_layout(*loc
, q
.local_size
);
478 ast_layout_expression::process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
479 const char *qual_indentifier
,
484 bool first_pass
= true;
490 for (exec_node
*node
= layout_const_expressions
.head
;
491 !node
->is_tail_sentinel(); node
= node
->next
) {
493 exec_list dummy_instructions
;
494 ast_node
*const_expression
= exec_node_data(ast_node
, node
, link
);
496 ir_rvalue
*const ir
= const_expression
->hir(&dummy_instructions
, state
);
498 ir_constant
*const const_int
= ir
->constant_expression_value();
499 if (const_int
== NULL
|| !const_int
->type
->is_integer()) {
500 YYLTYPE loc
= const_expression
->get_location();
501 _mesa_glsl_error(&loc
, state
, "%s must be an integral constant "
502 "expression", qual_indentifier
);
506 if (const_int
->value
.i
[0] < min_value
) {
507 YYLTYPE loc
= const_expression
->get_location();
508 _mesa_glsl_error(&loc
, state
, "%s layout qualifier is invalid "
509 "(%d < %d)", qual_indentifier
,
510 const_int
->value
.i
[0], min_value
);
514 if (!first_pass
&& *value
!= const_int
->value
.u
[0]) {
515 YYLTYPE loc
= const_expression
->get_location();
516 _mesa_glsl_error(&loc
, state
, "%s layout qualifier does not "
517 "match previous declaration (%d vs %d)",
518 qual_indentifier
, *value
, const_int
->value
.i
[0]);
522 *value
= const_int
->value
.u
[0];
525 /* If the location is const (and we've verified that
526 * it is) then no instructions should have been emitted
527 * when we converted it to HIR. If they were emitted,
528 * then either the location isn't const after all, or
529 * we are emitting unnecessary instructions.
531 assert(dummy_instructions
.is_empty());