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 return this->qualifier
.flags
.i
!= 0;
46 bool ast_type_qualifier::has_interpolation() const
48 return this->flags
.q
.smooth
50 || this->flags
.q
.noperspective
;
54 ast_type_qualifier::has_layout() const
56 return this->flags
.q
.origin_upper_left
57 || this->flags
.q
.pixel_center_integer
58 || this->flags
.q
.depth_any
59 || this->flags
.q
.depth_greater
60 || this->flags
.q
.depth_less
61 || this->flags
.q
.depth_unchanged
62 || this->flags
.q
.std140
63 || this->flags
.q
.shared
64 || this->flags
.q
.column_major
65 || this->flags
.q
.row_major
66 || this->flags
.q
.packed
67 || this->flags
.q
.explicit_location
68 || this->flags
.q
.explicit_index
69 || this->flags
.q
.explicit_binding
70 || this->flags
.q
.explicit_offset
;
74 ast_type_qualifier::has_storage() const
76 return this->flags
.q
.constant
77 || this->flags
.q
.attribute
78 || this->flags
.q
.varying
81 || this->flags
.q
.uniform
82 || this->flags
.q
.buffer
;
86 ast_type_qualifier::has_auxiliary_storage() const
88 return this->flags
.q
.centroid
89 || this->flags
.q
.sample
;
93 ast_type_qualifier::interpolation_string() const
95 if (this->flags
.q
.smooth
)
97 else if (this->flags
.q
.flat
)
99 else if (this->flags
.q
.noperspective
)
100 return "noperspective";
106 ast_type_qualifier::merge_qualifier(YYLTYPE
*loc
,
107 _mesa_glsl_parse_state
*state
,
108 ast_type_qualifier q
)
110 ast_type_qualifier ubo_mat_mask
;
111 ubo_mat_mask
.flags
.i
= 0;
112 ubo_mat_mask
.flags
.q
.row_major
= 1;
113 ubo_mat_mask
.flags
.q
.column_major
= 1;
115 ast_type_qualifier ubo_layout_mask
;
116 ubo_layout_mask
.flags
.i
= 0;
117 ubo_layout_mask
.flags
.q
.std140
= 1;
118 ubo_layout_mask
.flags
.q
.packed
= 1;
119 ubo_layout_mask
.flags
.q
.shared
= 1;
121 ast_type_qualifier ubo_binding_mask
;
122 ubo_binding_mask
.flags
.i
= 0;
123 ubo_binding_mask
.flags
.q
.explicit_binding
= 1;
124 ubo_binding_mask
.flags
.q
.explicit_offset
= 1;
126 ast_type_qualifier stream_layout_mask
;
127 stream_layout_mask
.flags
.i
= 0;
128 stream_layout_mask
.flags
.q
.stream
= 1;
130 /* Uniform block layout qualifiers get to overwrite each
131 * other (rightmost having priority), while all other
132 * qualifiers currently don't allow duplicates.
134 ast_type_qualifier allowed_duplicates_mask
;
135 allowed_duplicates_mask
.flags
.i
=
136 ubo_mat_mask
.flags
.i
|
137 ubo_layout_mask
.flags
.i
|
138 ubo_binding_mask
.flags
.i
;
140 /* Geometry shaders can have several layout qualifiers
141 * assigning different stream values.
143 if (state
->stage
== MESA_SHADER_GEOMETRY
)
144 allowed_duplicates_mask
.flags
.i
|=
145 stream_layout_mask
.flags
.i
;
147 if ((this->flags
.i
& q
.flags
.i
& ~allowed_duplicates_mask
.flags
.i
) != 0) {
148 _mesa_glsl_error(loc
, state
,
149 "duplicate layout qualifiers used");
153 if (q
.flags
.q
.prim_type
) {
154 if (this->flags
.q
.prim_type
&& this->prim_type
!= q
.prim_type
) {
155 _mesa_glsl_error(loc
, state
,
156 "conflicting primitive type qualifiers used");
159 this->prim_type
= q
.prim_type
;
162 if (q
.flags
.q
.max_vertices
) {
163 if (this->flags
.q
.max_vertices
&& this->max_vertices
!= q
.max_vertices
) {
164 _mesa_glsl_error(loc
, state
,
165 "geometry shader set conflicting max_vertices "
166 "(%d and %d)", this->max_vertices
, q
.max_vertices
);
169 this->max_vertices
= q
.max_vertices
;
172 if (q
.flags
.q
.invocations
) {
173 if (this->flags
.q
.invocations
&& this->invocations
!= q
.invocations
) {
174 _mesa_glsl_error(loc
, state
,
175 "geometry shader set conflicting invocations "
176 "(%d and %d)", this->invocations
, q
.invocations
);
179 this->invocations
= q
.invocations
;
182 if (state
->stage
== MESA_SHADER_GEOMETRY
&&
183 state
->has_explicit_attrib_stream()) {
184 if (q
.flags
.q
.stream
&& q
.stream
>= state
->ctx
->Const
.MaxVertexStreams
) {
185 _mesa_glsl_error(loc
, state
,
186 "`stream' value is larger than MAX_VERTEX_STREAMS - 1 "
188 q
.stream
, state
->ctx
->Const
.MaxVertexStreams
- 1);
190 if (this->flags
.q
.explicit_stream
&&
191 this->stream
>= state
->ctx
->Const
.MaxVertexStreams
) {
192 _mesa_glsl_error(loc
, state
,
193 "`stream' value is larger than MAX_VERTEX_STREAMS - 1 "
195 this->stream
, state
->ctx
->Const
.MaxVertexStreams
- 1);
198 if (!this->flags
.q
.explicit_stream
) {
199 if (q
.flags
.q
.stream
) {
200 this->flags
.q
.stream
= 1;
201 this->stream
= q
.stream
;
202 } else if (!this->flags
.q
.stream
&& this->flags
.q
.out
) {
203 /* Assign default global stream value */
204 this->flags
.q
.stream
= 1;
205 this->stream
= state
->out_qualifier
->stream
;
208 if (q
.flags
.q
.explicit_stream
) {
209 _mesa_glsl_error(loc
, state
,
210 "duplicate layout `stream' qualifier");
215 if ((q
.flags
.i
& ubo_mat_mask
.flags
.i
) != 0)
216 this->flags
.i
&= ~ubo_mat_mask
.flags
.i
;
217 if ((q
.flags
.i
& ubo_layout_mask
.flags
.i
) != 0)
218 this->flags
.i
&= ~ubo_layout_mask
.flags
.i
;
220 for (int i
= 0; i
< 3; i
++) {
221 if (q
.flags
.q
.local_size
& (1 << i
)) {
222 if ((this->flags
.q
.local_size
& (1 << i
)) &&
223 this->local_size
[i
] != q
.local_size
[i
]) {
224 _mesa_glsl_error(loc
, state
,
225 "compute shader set conflicting values for "
226 "local_size_%c (%d and %d)", 'x' + i
,
227 this->local_size
[i
], q
.local_size
[i
]);
230 this->local_size
[i
] = q
.local_size
[i
];
234 this->flags
.i
|= q
.flags
.i
;
236 if (q
.flags
.q
.explicit_location
)
237 this->location
= q
.location
;
239 if (q
.flags
.q
.explicit_index
)
240 this->index
= q
.index
;
242 if (q
.flags
.q
.explicit_binding
)
243 this->binding
= q
.binding
;
245 if (q
.flags
.q
.explicit_offset
)
246 this->offset
= q
.offset
;
248 if (q
.precision
!= ast_precision_none
)
249 this->precision
= q
.precision
;
251 if (q
.flags
.q
.explicit_image_format
) {
252 this->image_format
= q
.image_format
;
253 this->image_base_type
= q
.image_base_type
;
260 ast_type_qualifier::merge_in_qualifier(YYLTYPE
*loc
,
261 _mesa_glsl_parse_state
*state
,
262 ast_type_qualifier q
,
265 void *mem_ctx
= state
;
266 bool create_gs_ast
= false;
267 bool create_cs_ast
= false;
268 ast_type_qualifier valid_in_mask
;
269 valid_in_mask
.flags
.i
= 0;
271 switch (state
->stage
) {
272 case MESA_SHADER_GEOMETRY
:
273 if (q
.flags
.q
.prim_type
) {
274 /* Make sure this is a valid input primitive type. */
275 switch (q
.prim_type
) {
278 case GL_LINES_ADJACENCY
:
280 case GL_TRIANGLES_ADJACENCY
:
283 _mesa_glsl_error(loc
, state
,
284 "invalid geometry shader input primitive type");
290 q
.flags
.q
.prim_type
&&
291 !state
->in_qualifier
->flags
.q
.prim_type
;
293 valid_in_mask
.flags
.q
.prim_type
= 1;
294 valid_in_mask
.flags
.q
.invocations
= 1;
296 case MESA_SHADER_FRAGMENT
:
297 valid_in_mask
.flags
.q
.early_fragment_tests
= 1;
299 case MESA_SHADER_COMPUTE
:
301 q
.flags
.q
.local_size
!= 0 &&
302 state
->in_qualifier
->flags
.q
.local_size
== 0;
304 valid_in_mask
.flags
.q
.local_size
= 7;
307 _mesa_glsl_error(loc
, state
,
308 "input layout qualifiers only valid in "
309 "geometry, fragment and compute shaders");
313 /* Generate an error when invalid input layout qualifiers are used. */
314 if ((q
.flags
.i
& ~valid_in_mask
.flags
.i
) != 0) {
315 _mesa_glsl_error(loc
, state
,
316 "invalid input layout qualifiers used");
320 /* Input layout qualifiers can be specified multiple
321 * times in separate declarations, as long as they match.
323 if (this->flags
.q
.prim_type
) {
324 if (q
.flags
.q
.prim_type
&&
325 this->prim_type
!= q
.prim_type
) {
326 _mesa_glsl_error(loc
, state
,
327 "conflicting input primitive types specified");
329 } else if (q
.flags
.q
.prim_type
) {
330 state
->in_qualifier
->flags
.q
.prim_type
= 1;
331 state
->in_qualifier
->prim_type
= q
.prim_type
;
334 if (this->flags
.q
.invocations
&&
335 q
.flags
.q
.invocations
&&
336 this->invocations
!= q
.invocations
) {
337 _mesa_glsl_error(loc
, state
,
338 "conflicting invocations counts specified");
340 } else if (q
.flags
.q
.invocations
) {
341 this->flags
.q
.invocations
= 1;
342 this->invocations
= q
.invocations
;
345 if (q
.flags
.q
.early_fragment_tests
) {
346 state
->fs_early_fragment_tests
= true;
350 node
= new(mem_ctx
) ast_gs_input_layout(*loc
, q
.prim_type
);
351 } else if (create_cs_ast
) {
352 /* Infer a local_size of 1 for every unspecified dimension */
353 unsigned local_size
[3];
354 for (int i
= 0; i
< 3; i
++) {
355 if (q
.flags
.q
.local_size
& (1 << i
))
356 local_size
[i
] = q
.local_size
[i
];
360 node
= new(mem_ctx
) ast_cs_input_layout(*loc
, local_size
);