2 * Copyright © 2014 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 DEALINGS
24 * Connor Abbott (cwabbott0@gmail.com)
28 #include "nir_types.h"
29 #include "compiler/glsl/ir.h"
32 glsl_get_type_name(const glsl_type
*type
)
38 glsl_get_array_element(const glsl_type
* type
)
40 if (type
->is_matrix())
41 return type
->column_type();
42 else if (type
->is_vector())
43 return type
->get_scalar_type();
44 return type
->fields
.array
;
48 glsl_without_array(const glsl_type
*type
)
50 return type
->without_array();
54 glsl_get_array_instance(const glsl_type
*type
,
57 return glsl_type::get_array_instance(type
, array_size
);
61 glsl_get_struct_field(const glsl_type
*type
, unsigned index
)
63 return type
->fields
.structure
[index
].type
;
67 glsl_get_function_return_type(const glsl_type
*type
)
69 return type
->fields
.parameters
[0].type
;
72 const glsl_function_param
*
73 glsl_get_function_param(const glsl_type
*type
, unsigned index
)
75 return &type
->fields
.parameters
[index
+ 1];
78 const struct glsl_type
*
79 glsl_get_column_type(const struct glsl_type
*type
)
81 return type
->column_type();
85 glsl_get_base_type(const struct glsl_type
*type
)
87 return type
->base_type
;
91 glsl_get_vector_elements(const struct glsl_type
*type
)
93 return type
->vector_elements
;
97 glsl_get_components(const struct glsl_type
*type
)
99 return type
->components();
103 glsl_get_matrix_columns(const struct glsl_type
*type
)
105 return type
->matrix_columns
;
109 glsl_get_length(const struct glsl_type
*type
)
111 return type
->is_matrix() ? type
->matrix_columns
: type
->length
;
115 glsl_get_aoa_size(const struct glsl_type
*type
)
117 return type
->arrays_of_arrays_size();
121 glsl_count_attribute_slots(const struct glsl_type
*type
,
122 bool is_vertex_input
)
124 return type
->count_attribute_slots(is_vertex_input
);
128 glsl_get_struct_elem_name(const struct glsl_type
*type
, unsigned index
)
130 return type
->fields
.structure
[index
].name
;
134 glsl_get_sampler_dim(const struct glsl_type
*type
)
136 assert(glsl_type_is_sampler(type
) || glsl_type_is_image(type
));
137 return (glsl_sampler_dim
)type
->sampler_dimensionality
;
141 glsl_get_sampler_result_type(const struct glsl_type
*type
)
143 assert(glsl_type_is_sampler(type
) || glsl_type_is_image(type
));
144 return (glsl_base_type
)type
->sampled_type
;
148 glsl_get_record_location_offset(const struct glsl_type
*type
,
151 return type
->record_location_offset(length
);
155 glsl_type_is_64bit(const glsl_type
*type
)
157 return type
->is_64bit();
161 glsl_type_is_void(const glsl_type
*type
)
163 return type
->is_void();
167 glsl_type_is_error(const glsl_type
*type
)
169 return type
->is_error();
173 glsl_type_is_vector(const struct glsl_type
*type
)
175 return type
->is_vector();
179 glsl_type_is_scalar(const struct glsl_type
*type
)
181 return type
->is_scalar();
185 glsl_type_is_vector_or_scalar(const struct glsl_type
*type
)
187 return type
->is_vector() || type
->is_scalar();
191 glsl_type_is_matrix(const struct glsl_type
*type
)
193 return type
->is_matrix();
197 glsl_type_is_array(const struct glsl_type
*type
)
199 return type
->is_array();
203 glsl_type_is_array_of_arrays(const struct glsl_type
*type
)
205 return type
->is_array_of_arrays();
209 glsl_type_is_struct(const struct glsl_type
*type
)
211 return type
->is_record() || type
->is_interface();
215 glsl_type_is_sampler(const struct glsl_type
*type
)
217 return type
->is_sampler();
221 glsl_type_is_image(const struct glsl_type
*type
)
223 return type
->is_image();
227 glsl_sampler_type_is_shadow(const struct glsl_type
*type
)
229 assert(glsl_type_is_sampler(type
));
230 return type
->sampler_shadow
;
234 glsl_sampler_type_is_array(const struct glsl_type
*type
)
236 assert(glsl_type_is_sampler(type
) || glsl_type_is_image(type
));
237 return type
->sampler_array
;
241 glsl_type_is_dual_slot(const struct glsl_type
*type
)
243 return type
->is_dual_slot();
247 glsl_type_is_numeric(const struct glsl_type
*type
)
249 return type
->is_numeric();
253 glsl_type_is_boolean(const struct glsl_type
*type
)
255 return type
->is_boolean();
261 return glsl_type::void_type
;
265 glsl_float_type(void)
267 return glsl_type::float_type
;
271 glsl_double_type(void)
273 return glsl_type::double_type
;
277 glsl_float16_t_type(void)
279 return glsl_type::float16_t_type
;
283 glsl_vec_type(unsigned n
)
285 return glsl_type::vec(n
);
289 glsl_dvec_type(unsigned n
)
291 return glsl_type::dvec(n
);
297 return glsl_type::vec4_type
;
301 glsl_uvec4_type(void)
303 return glsl_type::uvec4_type
;
309 return glsl_type::int_type
;
315 return glsl_type::uint_type
;
319 glsl_int64_t_type(void)
321 return glsl_type::int64_t_type
;
325 glsl_uint64_t_type(void)
327 return glsl_type::uint64_t_type
;
331 glsl_int16_t_type(void)
333 return glsl_type::int16_t_type
;
337 glsl_uint16_t_type(void)
339 return glsl_type::uint16_t_type
;
343 glsl_int8_t_type(void)
345 return glsl_type::int8_t_type
;
349 glsl_uint8_t_type(void)
351 return glsl_type::uint8_t_type
;
357 return glsl_type::bool_type
;
361 glsl_scalar_type(enum glsl_base_type base_type
)
363 return glsl_type::get_instance(base_type
, 1, 1);
367 glsl_vector_type(enum glsl_base_type base_type
, unsigned components
)
369 assert(components
> 1 && components
<= 4);
370 return glsl_type::get_instance(base_type
, components
, 1);
374 glsl_matrix_type(enum glsl_base_type base_type
, unsigned rows
, unsigned columns
)
376 assert(rows
> 1 && rows
<= 4 && columns
>= 1 && columns
<= 4);
377 return glsl_type::get_instance(base_type
, rows
, columns
);
381 glsl_array_type(const glsl_type
*base
, unsigned elements
)
383 return glsl_type::get_array_instance(base
, elements
);
387 glsl_struct_type(const glsl_struct_field
*fields
,
388 unsigned num_fields
, const char *name
)
390 return glsl_type::get_record_instance(fields
, num_fields
, name
);
394 glsl_interface_type(const glsl_struct_field
*fields
,
396 enum glsl_interface_packing packing
,
398 const char *block_name
)
400 return glsl_type::get_interface_instance(fields
, num_fields
, packing
,
401 row_major
, block_name
);
404 const struct glsl_type
*
405 glsl_sampler_type(enum glsl_sampler_dim dim
, bool is_shadow
, bool is_array
,
406 enum glsl_base_type base_type
)
408 return glsl_type::get_sampler_instance(dim
, is_shadow
, is_array
, base_type
);
411 const struct glsl_type
*
412 glsl_bare_sampler_type()
414 return glsl_type::sampler_type
;
417 const struct glsl_type
*
418 glsl_image_type(enum glsl_sampler_dim dim
, bool is_array
,
419 enum glsl_base_type base_type
)
421 return glsl_type::get_image_instance(dim
, is_array
, base_type
);
425 glsl_function_type(const glsl_type
*return_type
,
426 const glsl_function_param
*params
, unsigned num_params
)
428 return glsl_type::get_function_instance(return_type
, params
, num_params
);
432 glsl_transposed_type(const struct glsl_type
*type
)
434 assert(glsl_type_is_matrix(type
));
435 return glsl_type::get_instance(type
->base_type
, type
->matrix_columns
,
436 type
->vector_elements
);
440 glsl_channel_type(const glsl_type
*t
)
442 switch (glsl_get_base_type(t
)) {
443 case GLSL_TYPE_ARRAY
: {
444 const glsl_type
*base
= glsl_channel_type(glsl_get_array_element(t
));
445 return glsl_array_type(base
, glsl_get_length(t
));
448 return glsl_uint_type();
450 return glsl_int_type();
451 case GLSL_TYPE_FLOAT
:
452 return glsl_float_type();
454 return glsl_bool_type();
455 case GLSL_TYPE_DOUBLE
:
456 return glsl_double_type();
457 case GLSL_TYPE_UINT64
:
458 return glsl_uint64_t_type();
459 case GLSL_TYPE_INT64
:
460 return glsl_int64_t_type();
462 unreachable("Unhandled base type glsl_channel_type()");