glsl/cs: Handle compute shader local_size_{x,y,z} declaration.
[mesa.git] / src / glsl / ast_type.cpp
1 /*
2 * Copyright © 2010 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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.
22 */
23
24 #include "ast.h"
25
26 void
27 ast_type_specifier::print(void) const
28 {
29 if (structure) {
30 structure->print();
31 } else {
32 printf("%s ", type_name);
33 }
34
35 if (array_specifier) {
36 array_specifier->print();
37 }
38 }
39
40 bool
41 ast_fully_specified_type::has_qualifiers() const
42 {
43 return this->qualifier.flags.i != 0;
44 }
45
46 bool ast_type_qualifier::has_interpolation() const
47 {
48 return this->flags.q.smooth
49 || this->flags.q.flat
50 || this->flags.q.noperspective;
51 }
52
53 bool
54 ast_type_qualifier::has_layout() const
55 {
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;
71 }
72
73 bool
74 ast_type_qualifier::has_storage() const
75 {
76 return this->flags.q.constant
77 || this->flags.q.attribute
78 || this->flags.q.varying
79 || this->flags.q.in
80 || this->flags.q.out
81 || this->flags.q.uniform;
82 }
83
84 bool
85 ast_type_qualifier::has_auxiliary_storage() const
86 {
87 return this->flags.q.centroid
88 || this->flags.q.sample;
89 }
90
91 const char*
92 ast_type_qualifier::interpolation_string() const
93 {
94 if (this->flags.q.smooth)
95 return "smooth";
96 else if (this->flags.q.flat)
97 return "flat";
98 else if (this->flags.q.noperspective)
99 return "noperspective";
100 else
101 return NULL;
102 }
103
104 bool
105 ast_type_qualifier::merge_qualifier(YYLTYPE *loc,
106 _mesa_glsl_parse_state *state,
107 ast_type_qualifier q)
108 {
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;
113
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;
119
120 ast_type_qualifier ubo_binding_mask;
121 ubo_binding_mask.flags.q.explicit_binding = 1;
122 ubo_binding_mask.flags.q.explicit_offset = 1;
123
124 /* Uniform block layout qualifiers get to overwrite each
125 * other (rightmost having priority), while all other
126 * qualifiers currently don't allow duplicates.
127 */
128
129 if ((this->flags.i & q.flags.i & ~(ubo_mat_mask.flags.i |
130 ubo_layout_mask.flags.i |
131 ubo_binding_mask.flags.i)) != 0) {
132 _mesa_glsl_error(loc, state,
133 "duplicate layout qualifiers used");
134 return false;
135 }
136
137 if (q.flags.q.prim_type) {
138 if (this->flags.q.prim_type && this->prim_type != q.prim_type) {
139 _mesa_glsl_error(loc, state,
140 "conflicting primitive type qualifiers used");
141 return false;
142 }
143 this->prim_type = q.prim_type;
144 }
145
146 if (q.flags.q.max_vertices) {
147 if (this->flags.q.max_vertices && this->max_vertices != q.max_vertices) {
148 _mesa_glsl_error(loc, state,
149 "geometry shader set conflicting max_vertices "
150 "(%d and %d)", this->max_vertices, q.max_vertices);
151 return false;
152 }
153 this->max_vertices = q.max_vertices;
154 }
155
156 if ((q.flags.i & ubo_mat_mask.flags.i) != 0)
157 this->flags.i &= ~ubo_mat_mask.flags.i;
158 if ((q.flags.i & ubo_layout_mask.flags.i) != 0)
159 this->flags.i &= ~ubo_layout_mask.flags.i;
160
161 for (int i = 0; i < 3; i++) {
162 if (q.flags.q.local_size & (1 << i)) {
163 if ((this->flags.q.local_size & (1 << i)) &&
164 this->local_size[i] != q.local_size[i]) {
165 _mesa_glsl_error(loc, state,
166 "compute shader set conflicting values for "
167 "local_size_%c (%d and %d)", 'x' + i,
168 this->local_size[i], q.local_size[i]);
169 return false;
170 }
171 this->local_size[i] = q.local_size[i];
172 }
173 }
174
175 this->flags.i |= q.flags.i;
176
177 if (q.flags.q.explicit_location)
178 this->location = q.location;
179
180 if (q.flags.q.explicit_index)
181 this->index = q.index;
182
183 if (q.flags.q.explicit_binding)
184 this->binding = q.binding;
185
186 if (q.flags.q.explicit_offset)
187 this->offset = q.offset;
188
189 if (q.precision != ast_precision_none)
190 this->precision = q.precision;
191
192 return true;
193 }
194