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
;
85 ast_type_qualifier::has_auxiliary_storage() const
87 return this->flags
.q
.centroid
88 || this->flags
.q
.sample
;
92 ast_type_qualifier::interpolation_string() const
94 if (this->flags
.q
.smooth
)
96 else if (this->flags
.q
.flat
)
98 else if (this->flags
.q
.noperspective
)
99 return "noperspective";
105 ast_type_qualifier::merge_qualifier(YYLTYPE
*loc
,
106 _mesa_glsl_parse_state
*state
,
107 ast_type_qualifier q
)
109 ast_type_qualifier ubo_mat_mask
;
110 ubo_mat_mask
.flags
.i
= 0;
111 ubo_mat_mask
.flags
.q
.row_major
= 1;
112 ubo_mat_mask
.flags
.q
.column_major
= 1;
114 ast_type_qualifier ubo_layout_mask
;
115 ubo_layout_mask
.flags
.i
= 0;
116 ubo_layout_mask
.flags
.q
.std140
= 1;
117 ubo_layout_mask
.flags
.q
.packed
= 1;
118 ubo_layout_mask
.flags
.q
.shared
= 1;
120 ast_type_qualifier ubo_binding_mask
;
121 ubo_binding_mask
.flags
.i
= 0;
122 ubo_binding_mask
.flags
.q
.explicit_binding
= 1;
123 ubo_binding_mask
.flags
.q
.explicit_offset
= 1;
125 ast_type_qualifier stream_layout_mask
;
126 stream_layout_mask
.flags
.i
= 0;
127 stream_layout_mask
.flags
.q
.stream
= 1;
129 /* Uniform block layout qualifiers get to overwrite each
130 * other (rightmost having priority), while all other
131 * qualifiers currently don't allow duplicates.
133 ast_type_qualifier allowed_duplicates_mask
;
134 allowed_duplicates_mask
.flags
.i
=
135 ubo_mat_mask
.flags
.i
|
136 ubo_layout_mask
.flags
.i
|
137 ubo_binding_mask
.flags
.i
;
139 /* Geometry shaders can have several layout qualifiers
140 * assigning different stream values.
142 if (state
->stage
== MESA_SHADER_GEOMETRY
)
143 allowed_duplicates_mask
.flags
.i
|=
144 stream_layout_mask
.flags
.i
;
146 if ((this->flags
.i
& q
.flags
.i
& ~allowed_duplicates_mask
.flags
.i
) != 0) {
147 _mesa_glsl_error(loc
, state
,
148 "duplicate layout qualifiers used");
152 if (q
.flags
.q
.prim_type
) {
153 if (this->flags
.q
.prim_type
&& this->prim_type
!= q
.prim_type
) {
154 _mesa_glsl_error(loc
, state
,
155 "conflicting primitive type qualifiers used");
158 this->prim_type
= q
.prim_type
;
161 if (q
.flags
.q
.max_vertices
) {
162 if (this->flags
.q
.max_vertices
&& this->max_vertices
!= q
.max_vertices
) {
163 _mesa_glsl_error(loc
, state
,
164 "geometry shader set conflicting max_vertices "
165 "(%d and %d)", this->max_vertices
, q
.max_vertices
);
168 this->max_vertices
= q
.max_vertices
;
171 if (state
->stage
== MESA_SHADER_GEOMETRY
&&
172 state
->has_explicit_attrib_stream()) {
173 if (q
.flags
.q
.stream
&& q
.stream
>= state
->ctx
->Const
.MaxVertexStreams
) {
174 _mesa_glsl_error(loc
, state
,
175 "`stream' value is larger than MAX_VERTEX_STREAMS - 1 "
177 q
.stream
, state
->ctx
->Const
.MaxVertexStreams
- 1);
179 if (this->flags
.q
.explicit_stream
&&
180 this->stream
>= state
->ctx
->Const
.MaxVertexStreams
) {
181 _mesa_glsl_error(loc
, state
,
182 "`stream' value is larger than MAX_VERTEX_STREAMS - 1 "
184 this->stream
, state
->ctx
->Const
.MaxVertexStreams
- 1);
187 if (!this->flags
.q
.explicit_stream
) {
188 if (q
.flags
.q
.stream
) {
189 this->flags
.q
.stream
= 1;
190 this->stream
= q
.stream
;
191 } else if (!this->flags
.q
.stream
&& this->flags
.q
.out
) {
192 /* Assign default global stream value */
193 this->flags
.q
.stream
= 1;
194 this->stream
= state
->out_qualifier
->stream
;
197 if (q
.flags
.q
.explicit_stream
) {
198 _mesa_glsl_error(loc
, state
,
199 "duplicate layout `stream' qualifier");
204 if ((q
.flags
.i
& ubo_mat_mask
.flags
.i
) != 0)
205 this->flags
.i
&= ~ubo_mat_mask
.flags
.i
;
206 if ((q
.flags
.i
& ubo_layout_mask
.flags
.i
) != 0)
207 this->flags
.i
&= ~ubo_layout_mask
.flags
.i
;
209 for (int i
= 0; i
< 3; i
++) {
210 if (q
.flags
.q
.local_size
& (1 << i
)) {
211 if ((this->flags
.q
.local_size
& (1 << i
)) &&
212 this->local_size
[i
] != q
.local_size
[i
]) {
213 _mesa_glsl_error(loc
, state
,
214 "compute shader set conflicting values for "
215 "local_size_%c (%d and %d)", 'x' + i
,
216 this->local_size
[i
], q
.local_size
[i
]);
219 this->local_size
[i
] = q
.local_size
[i
];
223 this->flags
.i
|= q
.flags
.i
;
225 if (q
.flags
.q
.explicit_location
)
226 this->location
= q
.location
;
228 if (q
.flags
.q
.explicit_index
)
229 this->index
= q
.index
;
231 if (q
.flags
.q
.explicit_binding
)
232 this->binding
= q
.binding
;
234 if (q
.flags
.q
.explicit_offset
)
235 this->offset
= q
.offset
;
237 if (q
.precision
!= ast_precision_none
)
238 this->precision
= q
.precision
;
240 if (q
.flags
.q
.explicit_image_format
) {
241 this->image_format
= q
.image_format
;
242 this->image_base_type
= q
.image_base_type
;
249 ast_type_qualifier::merge_in_qualifier(YYLTYPE
*loc
,
250 _mesa_glsl_parse_state
*state
,
251 ast_type_qualifier q
,
254 void *mem_ctx
= state
;
255 bool create_gs_ast
= false;
256 bool create_cs_ast
= false;
257 ast_type_qualifier valid_in_mask
;
258 valid_in_mask
.flags
.i
= 0;
260 switch (state
->stage
) {
261 case MESA_SHADER_GEOMETRY
:
262 if (q
.flags
.q
.prim_type
) {
263 /* Make sure this is a valid input primitive type. */
264 switch (q
.prim_type
) {
267 case GL_LINES_ADJACENCY
:
269 case GL_TRIANGLES_ADJACENCY
:
272 _mesa_glsl_error(loc
, state
,
273 "invalid geometry shader input primitive type");
279 q
.flags
.q
.prim_type
&&
280 !state
->in_qualifier
->flags
.q
.prim_type
;
282 valid_in_mask
.flags
.q
.prim_type
= 1;
283 valid_in_mask
.flags
.q
.invocations
= 1;
285 case MESA_SHADER_FRAGMENT
:
286 if (q
.flags
.q
.early_fragment_tests
) {
287 state
->early_fragment_tests
= true;
289 _mesa_glsl_error(loc
, state
, "invalid input layout qualifier");
292 case MESA_SHADER_COMPUTE
:
294 q
.flags
.q
.local_size
!= 0 &&
295 state
->in_qualifier
->flags
.q
.local_size
== 0;
297 valid_in_mask
.flags
.q
.local_size
= 7;
300 _mesa_glsl_error(loc
, state
,
301 "input layout qualifiers only valid in "
302 "geometry, fragment and compute shaders");
306 /* Generate an error when invalid input layout qualifiers are used. */
307 if ((q
.flags
.i
& ~valid_in_mask
.flags
.i
) != 0) {
308 _mesa_glsl_error(loc
, state
,
309 "invalid input layout qualifiers used");
313 /* Input layout qualifiers can be specified multiple
314 * times in separate declarations, as long as they match.
316 if (this->flags
.q
.prim_type
) {
317 if (q
.flags
.q
.prim_type
&&
318 this->prim_type
!= q
.prim_type
) {
319 _mesa_glsl_error(loc
, state
,
320 "conflicting input primitive types specified");
322 } else if (q
.flags
.q
.prim_type
) {
323 state
->in_qualifier
->flags
.q
.prim_type
= 1;
324 state
->in_qualifier
->prim_type
= q
.prim_type
;
327 if (this->flags
.q
.invocations
&&
328 q
.flags
.q
.invocations
&&
329 this->invocations
!= q
.invocations
) {
330 _mesa_glsl_error(loc
, state
,
331 "conflicting invocations counts specified");
333 } else if (q
.flags
.q
.invocations
) {
334 this->flags
.q
.invocations
= 1;
335 this->invocations
= q
.invocations
;
339 node
= new(mem_ctx
) ast_gs_input_layout(*loc
, q
.prim_type
);
340 } else if (create_cs_ast
) {
341 /* Infer a local_size of 1 for every unspecified dimension */
342 unsigned local_size
[3];
343 for (int i
= 0; i
< 3; i
++) {
344 if (q
.flags
.q
.local_size
& (1 << i
))
345 local_size
[i
] = q
.local_size
[i
];
349 node
= new(mem_ctx
) ast_cs_input_layout(*loc
, local_size
);