nir: add glsl_type_is_64bit() to nir_types
[mesa.git] / src / compiler / nir_types.cpp
1 /*
2 * Copyright © 2014 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 DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Connor Abbott (cwabbott0@gmail.com)
25 *
26 */
27
28 #include "nir_types.h"
29 #include "compiler/glsl/ir.h"
30
31 const char *
32 glsl_get_type_name(const glsl_type *type)
33 {
34 return type->name;
35 }
36
37 const glsl_type *
38 glsl_get_array_element(const glsl_type* type)
39 {
40 if (type->is_matrix())
41 return type->column_type();
42 return type->fields.array;
43 }
44
45 const glsl_type *
46 glsl_without_array(const glsl_type *type)
47 {
48 return type->without_array();
49 }
50
51 const glsl_type *
52 glsl_get_array_instance(const glsl_type *type,
53 unsigned array_size)
54 {
55 return glsl_type::get_array_instance(type, array_size);
56 }
57
58 const glsl_type *
59 glsl_get_struct_field(const glsl_type *type, unsigned index)
60 {
61 return type->fields.structure[index].type;
62 }
63
64 const glsl_type *
65 glsl_get_function_return_type(const glsl_type *type)
66 {
67 return type->fields.parameters[0].type;
68 }
69
70 const glsl_function_param *
71 glsl_get_function_param(const glsl_type *type, unsigned index)
72 {
73 return &type->fields.parameters[index + 1];
74 }
75
76 const struct glsl_type *
77 glsl_get_column_type(const struct glsl_type *type)
78 {
79 return type->column_type();
80 }
81
82 enum glsl_base_type
83 glsl_get_base_type(const struct glsl_type *type)
84 {
85 return type->base_type;
86 }
87
88 unsigned
89 glsl_get_vector_elements(const struct glsl_type *type)
90 {
91 return type->vector_elements;
92 }
93
94 unsigned
95 glsl_get_components(const struct glsl_type *type)
96 {
97 return type->components();
98 }
99
100 unsigned
101 glsl_get_matrix_columns(const struct glsl_type *type)
102 {
103 return type->matrix_columns;
104 }
105
106 unsigned
107 glsl_get_length(const struct glsl_type *type)
108 {
109 return type->is_matrix() ? type->matrix_columns : type->length;
110 }
111
112 unsigned
113 glsl_get_aoa_size(const struct glsl_type *type)
114 {
115 return type->arrays_of_arrays_size();
116 }
117
118 unsigned
119 glsl_count_attribute_slots(const struct glsl_type *type,
120 bool is_vertex_input)
121 {
122 return type->count_attribute_slots(is_vertex_input);
123 }
124
125 const char *
126 glsl_get_struct_elem_name(const struct glsl_type *type, unsigned index)
127 {
128 return type->fields.structure[index].name;
129 }
130
131 glsl_sampler_dim
132 glsl_get_sampler_dim(const struct glsl_type *type)
133 {
134 assert(glsl_type_is_sampler(type) || glsl_type_is_image(type));
135 return (glsl_sampler_dim)type->sampler_dimensionality;
136 }
137
138 glsl_base_type
139 glsl_get_sampler_result_type(const struct glsl_type *type)
140 {
141 assert(glsl_type_is_sampler(type) || glsl_type_is_image(type));
142 return (glsl_base_type)type->sampled_type;
143 }
144
145 unsigned
146 glsl_get_record_location_offset(const struct glsl_type *type,
147 unsigned length)
148 {
149 return type->record_location_offset(length);
150 }
151
152 bool
153 glsl_type_is_64bit(const glsl_type *type)
154 {
155 return type->is_64bit();
156 }
157
158 bool
159 glsl_type_is_void(const glsl_type *type)
160 {
161 return type->is_void();
162 }
163
164 bool
165 glsl_type_is_error(const glsl_type *type)
166 {
167 return type->is_error();
168 }
169
170 bool
171 glsl_type_is_vector(const struct glsl_type *type)
172 {
173 return type->is_vector();
174 }
175
176 bool
177 glsl_type_is_scalar(const struct glsl_type *type)
178 {
179 return type->is_scalar();
180 }
181
182 bool
183 glsl_type_is_vector_or_scalar(const struct glsl_type *type)
184 {
185 return type->is_vector() || type->is_scalar();
186 }
187
188 bool
189 glsl_type_is_matrix(const struct glsl_type *type)
190 {
191 return type->is_matrix();
192 }
193
194 bool
195 glsl_type_is_array(const struct glsl_type *type)
196 {
197 return type->is_array();
198 }
199
200 bool
201 glsl_type_is_array_of_arrays(const struct glsl_type *type)
202 {
203 return type->is_array_of_arrays();
204 }
205
206 bool
207 glsl_type_is_struct(const struct glsl_type *type)
208 {
209 return type->is_record() || type->is_interface();
210 }
211
212 bool
213 glsl_type_is_sampler(const struct glsl_type *type)
214 {
215 return type->is_sampler();
216 }
217
218 bool
219 glsl_type_is_image(const struct glsl_type *type)
220 {
221 return type->is_image();
222 }
223
224 bool
225 glsl_sampler_type_is_shadow(const struct glsl_type *type)
226 {
227 assert(glsl_type_is_sampler(type));
228 return type->sampler_shadow;
229 }
230
231 bool
232 glsl_sampler_type_is_array(const struct glsl_type *type)
233 {
234 assert(glsl_type_is_sampler(type) || glsl_type_is_image(type));
235 return type->sampler_array;
236 }
237
238 bool
239 glsl_type_is_dual_slot(const struct glsl_type *type)
240 {
241 return type->is_dual_slot();
242 }
243
244 bool
245 glsl_type_is_numeric(const struct glsl_type *type)
246 {
247 return type->is_numeric();
248 }
249
250 bool
251 glsl_type_is_boolean(const struct glsl_type *type)
252 {
253 return type->is_boolean();
254 }
255
256 const glsl_type *
257 glsl_void_type(void)
258 {
259 return glsl_type::void_type;
260 }
261
262 const glsl_type *
263 glsl_float_type(void)
264 {
265 return glsl_type::float_type;
266 }
267
268 const glsl_type *
269 glsl_double_type(void)
270 {
271 return glsl_type::double_type;
272 }
273
274 const glsl_type *
275 glsl_vec_type(unsigned n)
276 {
277 return glsl_type::vec(n);
278 }
279
280 const glsl_type *
281 glsl_dvec_type(unsigned n)
282 {
283 return glsl_type::dvec(n);
284 }
285
286 const glsl_type *
287 glsl_vec4_type(void)
288 {
289 return glsl_type::vec4_type;
290 }
291
292 const glsl_type *
293 glsl_int_type(void)
294 {
295 return glsl_type::int_type;
296 }
297
298 const glsl_type *
299 glsl_uint_type(void)
300 {
301 return glsl_type::uint_type;
302 }
303
304 const glsl_type *
305 glsl_int64_t_type(void)
306 {
307 return glsl_type::int64_t_type;
308 }
309
310 const glsl_type *
311 glsl_uint64_t_type(void)
312 {
313 return glsl_type::uint64_t_type;
314 }
315
316 const glsl_type *
317 glsl_bool_type(void)
318 {
319 return glsl_type::bool_type;
320 }
321
322 const glsl_type *
323 glsl_scalar_type(enum glsl_base_type base_type)
324 {
325 return glsl_type::get_instance(base_type, 1, 1);
326 }
327
328 const glsl_type *
329 glsl_vector_type(enum glsl_base_type base_type, unsigned components)
330 {
331 assert(components > 1 && components <= 4);
332 return glsl_type::get_instance(base_type, components, 1);
333 }
334
335 const glsl_type *
336 glsl_matrix_type(enum glsl_base_type base_type, unsigned rows, unsigned columns)
337 {
338 assert(rows > 1 && rows <= 4 && columns >= 1 && columns <= 4);
339 return glsl_type::get_instance(base_type, rows, columns);
340 }
341
342 const glsl_type *
343 glsl_array_type(const glsl_type *base, unsigned elements)
344 {
345 return glsl_type::get_array_instance(base, elements);
346 }
347
348 const glsl_type *
349 glsl_struct_type(const glsl_struct_field *fields,
350 unsigned num_fields, const char *name)
351 {
352 return glsl_type::get_record_instance(fields, num_fields, name);
353 }
354
355 const glsl_type *
356 glsl_interface_type(const glsl_struct_field *fields,
357 unsigned num_fields,
358 enum glsl_interface_packing packing,
359 bool row_major,
360 const char *block_name)
361 {
362 return glsl_type::get_interface_instance(fields, num_fields, packing,
363 row_major, block_name);
364 }
365
366 const struct glsl_type *
367 glsl_sampler_type(enum glsl_sampler_dim dim, bool is_shadow, bool is_array,
368 enum glsl_base_type base_type)
369 {
370 return glsl_type::get_sampler_instance(dim, is_shadow, is_array, base_type);
371 }
372
373 const struct glsl_type *
374 glsl_bare_sampler_type()
375 {
376 return glsl_type::sampler_type;
377 }
378
379 const struct glsl_type *
380 glsl_image_type(enum glsl_sampler_dim dim, bool is_array,
381 enum glsl_base_type base_type)
382 {
383 return glsl_type::get_image_instance(dim, is_array, base_type);
384 }
385
386 const glsl_type *
387 glsl_function_type(const glsl_type *return_type,
388 const glsl_function_param *params, unsigned num_params)
389 {
390 return glsl_type::get_function_instance(return_type, params, num_params);
391 }
392
393 const glsl_type *
394 glsl_transposed_type(const struct glsl_type *type)
395 {
396 assert(glsl_type_is_matrix(type));
397 return glsl_type::get_instance(type->base_type, type->matrix_columns,
398 type->vector_elements);
399 }