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 /* Uniform block layout qualifiers get to overwrite each
126 * other (rightmost having priority), while all other
127 * qualifiers currently don't allow duplicates.
130 if ((this->flags
.i
& q
.flags
.i
& ~(ubo_mat_mask
.flags
.i
|
131 ubo_layout_mask
.flags
.i
|
132 ubo_binding_mask
.flags
.i
)) != 0) {
133 _mesa_glsl_error(loc
, state
,
134 "duplicate layout qualifiers used");
138 if (q
.flags
.q
.prim_type
) {
139 if (this->flags
.q
.prim_type
&& this->prim_type
!= q
.prim_type
) {
140 _mesa_glsl_error(loc
, state
,
141 "conflicting primitive type qualifiers used");
144 this->prim_type
= q
.prim_type
;
147 if (q
.flags
.q
.max_vertices
) {
148 if (this->flags
.q
.max_vertices
&& this->max_vertices
!= q
.max_vertices
) {
149 _mesa_glsl_error(loc
, state
,
150 "geometry shader set conflicting max_vertices "
151 "(%d and %d)", this->max_vertices
, q
.max_vertices
);
154 this->max_vertices
= q
.max_vertices
;
157 if ((q
.flags
.i
& ubo_mat_mask
.flags
.i
) != 0)
158 this->flags
.i
&= ~ubo_mat_mask
.flags
.i
;
159 if ((q
.flags
.i
& ubo_layout_mask
.flags
.i
) != 0)
160 this->flags
.i
&= ~ubo_layout_mask
.flags
.i
;
162 for (int i
= 0; i
< 3; i
++) {
163 if (q
.flags
.q
.local_size
& (1 << i
)) {
164 if ((this->flags
.q
.local_size
& (1 << i
)) &&
165 this->local_size
[i
] != q
.local_size
[i
]) {
166 _mesa_glsl_error(loc
, state
,
167 "compute shader set conflicting values for "
168 "local_size_%c (%d and %d)", 'x' + i
,
169 this->local_size
[i
], q
.local_size
[i
]);
172 this->local_size
[i
] = q
.local_size
[i
];
176 this->flags
.i
|= q
.flags
.i
;
178 if (q
.flags
.q
.explicit_location
)
179 this->location
= q
.location
;
181 if (q
.flags
.q
.explicit_index
)
182 this->index
= q
.index
;
184 if (q
.flags
.q
.explicit_binding
)
185 this->binding
= q
.binding
;
187 if (q
.flags
.q
.explicit_offset
)
188 this->offset
= q
.offset
;
190 if (q
.precision
!= ast_precision_none
)
191 this->precision
= q
.precision
;
193 if (q
.flags
.q
.explicit_image_format
) {
194 this->image_format
= q
.image_format
;
195 this->image_base_type
= q
.image_base_type
;
202 ast_type_qualifier::merge_in_qualifier(YYLTYPE
*loc
,
203 _mesa_glsl_parse_state
*state
,
204 ast_type_qualifier q
,
207 void *mem_ctx
= state
;
208 bool create_gs_ast
= false;
209 bool create_cs_ast
= false;
211 switch (state
->stage
) {
212 case MESA_SHADER_GEOMETRY
:
213 if (q
.flags
.q
.prim_type
) {
214 /* Make sure this is a valid input primitive type. */
215 switch (q
.prim_type
) {
218 case GL_LINES_ADJACENCY
:
220 case GL_TRIANGLES_ADJACENCY
:
223 _mesa_glsl_error(loc
, state
,
224 "invalid geometry shader input primitive type");
230 q
.flags
.q
.prim_type
&&
231 !state
->in_qualifier
->flags
.q
.prim_type
;
233 case MESA_SHADER_FRAGMENT
:
234 if (q
.flags
.q
.early_fragment_tests
) {
235 state
->early_fragment_tests
= true;
237 _mesa_glsl_error(loc
, state
, "invalid input layout qualifier");
240 case MESA_SHADER_COMPUTE
:
242 q
.flags
.q
.local_size
!= 0 &&
243 state
->in_qualifier
->flags
.q
.local_size
== 0;
246 _mesa_glsl_error(loc
, state
,
247 "input layout qualifiers only valid in "
248 "geometry, fragment and compute shaders");
252 /* Input layout qualifiers can be specified multiple
253 * times in separate declarations, as long as they match.
255 if (this->flags
.q
.prim_type
) {
256 if (q
.flags
.q
.prim_type
&&
257 this->prim_type
!= q
.prim_type
) {
258 _mesa_glsl_error(loc
, state
,
259 "conflicting input primitive types specified");
261 } else if (q
.flags
.q
.prim_type
) {
262 state
->in_qualifier
->flags
.q
.prim_type
= 1;
263 state
->in_qualifier
->prim_type
= q
.prim_type
;
267 node
= new(mem_ctx
) ast_gs_input_layout(*loc
, q
.prim_type
);
268 } else if (create_cs_ast
) {
269 /* Infer a local_size of 1 for every unspecified dimension */
270 unsigned local_size
[3];
271 for (int i
= 0; i
< 3; i
++) {
272 if (q
.flags
.q
.local_size
& (1 << i
))
273 local_size
[i
] = q
.local_size
[i
];
277 node
= new(mem_ctx
) ast_cs_input_layout(*loc
, local_size
);