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 ast_type_qualifier::interpolation_string() const
108 if (this->flags
.q
.smooth
)
110 else if (this->flags
.q
.flat
)
112 else if (this->flags
.q
.noperspective
)
113 return "noperspective";
119 * This function merges both duplicate identifies within a single layout and
120 * multiple layout qualifiers on a single variable declaration. The
121 * is_single_layout_merge param is used differentiate between the two.
124 ast_type_qualifier::merge_qualifier(YYLTYPE
*loc
,
125 _mesa_glsl_parse_state
*state
,
126 const ast_type_qualifier
&q
,
127 bool is_single_layout_merge
)
129 ast_type_qualifier ubo_mat_mask
;
130 ubo_mat_mask
.flags
.i
= 0;
131 ubo_mat_mask
.flags
.q
.row_major
= 1;
132 ubo_mat_mask
.flags
.q
.column_major
= 1;
134 ast_type_qualifier ubo_layout_mask
;
135 ubo_layout_mask
.flags
.i
= 0;
136 ubo_layout_mask
.flags
.q
.std140
= 1;
137 ubo_layout_mask
.flags
.q
.packed
= 1;
138 ubo_layout_mask
.flags
.q
.shared
= 1;
139 ubo_layout_mask
.flags
.q
.std430
= 1;
141 ast_type_qualifier ubo_binding_mask
;
142 ubo_binding_mask
.flags
.i
= 0;
143 ubo_binding_mask
.flags
.q
.explicit_binding
= 1;
144 ubo_binding_mask
.flags
.q
.explicit_offset
= 1;
146 ast_type_qualifier stream_layout_mask
;
147 stream_layout_mask
.flags
.i
= 0;
148 stream_layout_mask
.flags
.q
.stream
= 1;
150 /* Uniform block layout qualifiers get to overwrite each
151 * other (rightmost having priority), while all other
152 * qualifiers currently don't allow duplicates.
154 ast_type_qualifier allowed_duplicates_mask
;
155 allowed_duplicates_mask
.flags
.i
=
156 ubo_mat_mask
.flags
.i
|
157 ubo_layout_mask
.flags
.i
|
158 ubo_binding_mask
.flags
.i
;
160 /* Geometry shaders can have several layout qualifiers
161 * assigning different stream values.
163 if (state
->stage
== MESA_SHADER_GEOMETRY
)
164 allowed_duplicates_mask
.flags
.i
|=
165 stream_layout_mask
.flags
.i
;
167 if (is_single_layout_merge
&& !state
->has_enhanced_layouts() &&
168 (this->flags
.i
& q
.flags
.i
& ~allowed_duplicates_mask
.flags
.i
) != 0) {
169 _mesa_glsl_error(loc
, state
,
170 "duplicate layout qualifiers used");
174 if (q
.flags
.q
.prim_type
) {
175 if (this->flags
.q
.prim_type
&& this->prim_type
!= q
.prim_type
) {
176 _mesa_glsl_error(loc
, state
,
177 "conflicting primitive type qualifiers used");
180 this->prim_type
= q
.prim_type
;
183 if (q
.flags
.q
.max_vertices
) {
184 if (this->max_vertices
) {
185 this->max_vertices
->merge_qualifier(q
.max_vertices
);
187 this->max_vertices
= q
.max_vertices
;
191 if (q
.flags
.q
.subroutine_def
) {
192 if (this->flags
.q
.subroutine_def
) {
193 _mesa_glsl_error(loc
, state
,
194 "conflicting subroutine qualifiers used");
196 this->subroutine_list
= q
.subroutine_list
;
200 if (q
.flags
.q
.invocations
) {
201 if (this->invocations
) {
202 this->invocations
->merge_qualifier(q
.invocations
);
204 this->invocations
= q
.invocations
;
208 if (state
->stage
== MESA_SHADER_GEOMETRY
&&
209 state
->has_explicit_attrib_stream()) {
210 if (!this->flags
.q
.explicit_stream
) {
211 if (q
.flags
.q
.stream
) {
212 this->flags
.q
.stream
= 1;
213 this->stream
= q
.stream
;
214 } else if (!this->flags
.q
.stream
&& this->flags
.q
.out
) {
215 /* Assign default global stream value */
216 this->flags
.q
.stream
= 1;
217 this->stream
= state
->out_qualifier
->stream
;
222 if (q
.flags
.q
.vertices
) {
223 if (this->vertices
) {
224 this->vertices
->merge_qualifier(q
.vertices
);
226 this->vertices
= q
.vertices
;
230 if (q
.flags
.q
.vertex_spacing
) {
231 if (this->flags
.q
.vertex_spacing
&& this->vertex_spacing
!= q
.vertex_spacing
) {
232 _mesa_glsl_error(loc
, state
,
233 "conflicting vertex spacing used");
236 this->vertex_spacing
= q
.vertex_spacing
;
239 if (q
.flags
.q
.ordering
) {
240 if (this->flags
.q
.ordering
&& this->ordering
!= q
.ordering
) {
241 _mesa_glsl_error(loc
, state
,
242 "conflicting ordering used");
245 this->ordering
= q
.ordering
;
248 if (q
.flags
.q
.point_mode
) {
249 if (this->flags
.q
.point_mode
&& this->point_mode
!= q
.point_mode
) {
250 _mesa_glsl_error(loc
, state
,
251 "conflicting point mode used");
254 this->point_mode
= q
.point_mode
;
257 if ((q
.flags
.i
& ubo_mat_mask
.flags
.i
) != 0)
258 this->flags
.i
&= ~ubo_mat_mask
.flags
.i
;
259 if ((q
.flags
.i
& ubo_layout_mask
.flags
.i
) != 0)
260 this->flags
.i
&= ~ubo_layout_mask
.flags
.i
;
262 for (int i
= 0; i
< 3; i
++) {
263 if (q
.flags
.q
.local_size
& (1 << i
)) {
264 if (this->local_size
[i
]) {
265 this->local_size
[i
]->merge_qualifier(q
.local_size
[i
]);
267 this->local_size
[i
] = q
.local_size
[i
];
272 this->flags
.i
|= q
.flags
.i
;
274 if (q
.flags
.q
.explicit_location
)
275 this->location
= q
.location
;
277 if (q
.flags
.q
.explicit_index
)
278 this->index
= q
.index
;
280 if (q
.flags
.q
.explicit_binding
)
281 this->binding
= q
.binding
;
283 if (q
.flags
.q
.explicit_offset
)
284 this->offset
= q
.offset
;
286 if (q
.precision
!= ast_precision_none
)
287 this->precision
= q
.precision
;
289 if (q
.flags
.q
.explicit_image_format
) {
290 this->image_format
= q
.image_format
;
291 this->image_base_type
= q
.image_base_type
;
298 ast_type_qualifier::merge_out_qualifier(YYLTYPE
*loc
,
299 _mesa_glsl_parse_state
*state
,
300 const ast_type_qualifier
&q
,
301 ast_node
* &node
, bool create_node
)
303 void *mem_ctx
= state
;
304 const bool r
= this->merge_qualifier(loc
, state
, q
, false);
306 if (state
->stage
== MESA_SHADER_GEOMETRY
) {
307 if (q
.flags
.q
.prim_type
) {
308 /* Make sure this is a valid output primitive type. */
309 switch (q
.prim_type
) {
312 case GL_TRIANGLE_STRIP
:
315 _mesa_glsl_error(loc
, state
, "invalid geometry shader output "
321 /* Allow future assigments of global out's stream id value */
322 this->flags
.q
.explicit_stream
= 0;
323 } else if (state
->stage
== MESA_SHADER_TESS_CTRL
) {
325 node
= new(mem_ctx
) ast_tcs_output_layout(*loc
);
328 _mesa_glsl_error(loc
, state
, "out layout qualifiers only valid in "
329 "tessellation control or geometry shaders");
336 ast_type_qualifier::merge_in_qualifier(YYLTYPE
*loc
,
337 _mesa_glsl_parse_state
*state
,
338 const ast_type_qualifier
&q
,
339 ast_node
* &node
, bool create_node
)
341 void *mem_ctx
= state
;
342 bool create_gs_ast
= false;
343 bool create_cs_ast
= false;
344 ast_type_qualifier valid_in_mask
;
345 valid_in_mask
.flags
.i
= 0;
347 switch (state
->stage
) {
348 case MESA_SHADER_TESS_EVAL
:
349 if (q
.flags
.q
.prim_type
) {
350 /* Make sure this is a valid input primitive type. */
351 switch (q
.prim_type
) {
357 _mesa_glsl_error(loc
, state
,
358 "invalid tessellation evaluation "
359 "shader input primitive type");
364 valid_in_mask
.flags
.q
.prim_type
= 1;
365 valid_in_mask
.flags
.q
.vertex_spacing
= 1;
366 valid_in_mask
.flags
.q
.ordering
= 1;
367 valid_in_mask
.flags
.q
.point_mode
= 1;
369 case MESA_SHADER_GEOMETRY
:
370 if (q
.flags
.q
.prim_type
) {
371 /* Make sure this is a valid input primitive type. */
372 switch (q
.prim_type
) {
375 case GL_LINES_ADJACENCY
:
377 case GL_TRIANGLES_ADJACENCY
:
380 _mesa_glsl_error(loc
, state
,
381 "invalid geometry shader input primitive type");
387 q
.flags
.q
.prim_type
&&
388 !state
->in_qualifier
->flags
.q
.prim_type
;
390 valid_in_mask
.flags
.q
.prim_type
= 1;
391 valid_in_mask
.flags
.q
.invocations
= 1;
393 case MESA_SHADER_FRAGMENT
:
394 valid_in_mask
.flags
.q
.early_fragment_tests
= 1;
396 case MESA_SHADER_COMPUTE
:
398 q
.flags
.q
.local_size
!= 0 &&
399 state
->in_qualifier
->flags
.q
.local_size
== 0;
401 valid_in_mask
.flags
.q
.local_size
= 7;
404 _mesa_glsl_error(loc
, state
,
405 "input layout qualifiers only valid in "
406 "geometry, fragment and compute shaders");
410 /* Generate an error when invalid input layout qualifiers are used. */
411 if ((q
.flags
.i
& ~valid_in_mask
.flags
.i
) != 0) {
412 _mesa_glsl_error(loc
, state
,
413 "invalid input layout qualifiers used");
417 /* Input layout qualifiers can be specified multiple
418 * times in separate declarations, as long as they match.
420 if (this->flags
.q
.prim_type
) {
421 if (q
.flags
.q
.prim_type
&&
422 this->prim_type
!= q
.prim_type
) {
423 _mesa_glsl_error(loc
, state
,
424 "conflicting input primitive %s specified",
425 state
->stage
== MESA_SHADER_GEOMETRY
?
428 } else if (q
.flags
.q
.prim_type
) {
429 state
->in_qualifier
->flags
.q
.prim_type
= 1;
430 state
->in_qualifier
->prim_type
= q
.prim_type
;
433 if (q
.flags
.q
.invocations
) {
434 this->flags
.q
.invocations
= 1;
435 if (this->invocations
) {
436 this->invocations
->merge_qualifier(q
.invocations
);
438 this->invocations
= q
.invocations
;
442 if (q
.flags
.q
.early_fragment_tests
) {
443 state
->fs_early_fragment_tests
= true;
446 if (this->flags
.q
.vertex_spacing
) {
447 if (q
.flags
.q
.vertex_spacing
&&
448 this->vertex_spacing
!= q
.vertex_spacing
) {
449 _mesa_glsl_error(loc
, state
,
450 "conflicting vertex spacing specified");
452 } else if (q
.flags
.q
.vertex_spacing
) {
453 this->flags
.q
.vertex_spacing
= 1;
454 this->vertex_spacing
= q
.vertex_spacing
;
457 if (this->flags
.q
.ordering
) {
458 if (q
.flags
.q
.ordering
&&
459 this->ordering
!= q
.ordering
) {
460 _mesa_glsl_error(loc
, state
,
461 "conflicting ordering specified");
463 } else if (q
.flags
.q
.ordering
) {
464 this->flags
.q
.ordering
= 1;
465 this->ordering
= q
.ordering
;
468 if (this->flags
.q
.point_mode
) {
469 if (q
.flags
.q
.point_mode
&&
470 this->point_mode
!= q
.point_mode
) {
471 _mesa_glsl_error(loc
, state
,
472 "conflicting point mode specified");
474 } else if (q
.flags
.q
.point_mode
) {
475 this->flags
.q
.point_mode
= 1;
476 this->point_mode
= q
.point_mode
;
481 node
= new(mem_ctx
) ast_gs_input_layout(*loc
, q
.prim_type
);
482 } else if (create_cs_ast
) {
483 node
= new(mem_ctx
) ast_cs_input_layout(*loc
, q
.local_size
);
491 ast_layout_expression::process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
492 const char *qual_indentifier
,
497 bool first_pass
= true;
503 for (exec_node
*node
= layout_const_expressions
.head
;
504 !node
->is_tail_sentinel(); node
= node
->next
) {
506 exec_list dummy_instructions
;
507 ast_node
*const_expression
= exec_node_data(ast_node
, node
, link
);
509 ir_rvalue
*const ir
= const_expression
->hir(&dummy_instructions
, state
);
511 ir_constant
*const const_int
= ir
->constant_expression_value();
512 if (const_int
== NULL
|| !const_int
->type
->is_integer()) {
513 YYLTYPE loc
= const_expression
->get_location();
514 _mesa_glsl_error(&loc
, state
, "%s must be an integral constant "
515 "expression", qual_indentifier
);
519 if (const_int
->value
.i
[0] < min_value
) {
520 YYLTYPE loc
= const_expression
->get_location();
521 _mesa_glsl_error(&loc
, state
, "%s layout qualifier is invalid "
522 "(%d < %d)", qual_indentifier
,
523 const_int
->value
.i
[0], min_value
);
527 if (!first_pass
&& *value
!= const_int
->value
.u
[0]) {
528 YYLTYPE loc
= const_expression
->get_location();
529 _mesa_glsl_error(&loc
, state
, "%s layout qualifier does not "
530 "match previous declaration (%d vs %d)",
531 qual_indentifier
, *value
, const_int
->value
.i
[0]);
535 *value
= const_int
->value
.u
[0];
538 /* If the location is const (and we've verified that
539 * it is) then no instructions should have been emitted
540 * when we converted it to HIR. If they were emitted,
541 * then either the location isn't const after all, or
542 * we are emitting unnecessary instructions.
544 assert(dummy_instructions
.is_empty());