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 return type
->fields
.array
;
46 glsl_without_array(const glsl_type
*type
)
48 return type
->without_array();
52 glsl_get_struct_field(const glsl_type
*type
, unsigned index
)
54 return type
->fields
.structure
[index
].type
;
58 glsl_get_function_return_type(const glsl_type
*type
)
60 return type
->fields
.parameters
[0].type
;
63 const glsl_function_param
*
64 glsl_get_function_param(const glsl_type
*type
, unsigned index
)
66 return &type
->fields
.parameters
[index
+ 1];
69 const struct glsl_type
*
70 glsl_get_column_type(const struct glsl_type
*type
)
72 return type
->column_type();
76 glsl_get_base_type(const struct glsl_type
*type
)
78 return type
->base_type
;
82 glsl_get_vector_elements(const struct glsl_type
*type
)
84 return type
->vector_elements
;
88 glsl_get_components(const struct glsl_type
*type
)
90 return type
->components();
94 glsl_get_matrix_columns(const struct glsl_type
*type
)
96 return type
->matrix_columns
;
100 glsl_get_length(const struct glsl_type
*type
)
102 return type
->is_matrix() ? type
->matrix_columns
: type
->length
;
106 glsl_get_aoa_size(const struct glsl_type
*type
)
108 return type
->arrays_of_arrays_size();
112 glsl_count_attribute_slots(const struct glsl_type
*type
,
113 bool is_vertex_input
)
115 return type
->count_attribute_slots(is_vertex_input
);
119 glsl_get_struct_elem_name(const struct glsl_type
*type
, unsigned index
)
121 return type
->fields
.structure
[index
].name
;
125 glsl_get_sampler_dim(const struct glsl_type
*type
)
127 assert(glsl_type_is_sampler(type
) || glsl_type_is_image(type
));
128 return (glsl_sampler_dim
)type
->sampler_dimensionality
;
132 glsl_get_sampler_result_type(const struct glsl_type
*type
)
134 assert(glsl_type_is_sampler(type
) || glsl_type_is_image(type
));
135 return (glsl_base_type
)type
->sampled_type
;
139 glsl_get_record_location_offset(const struct glsl_type
*type
,
142 return type
->record_location_offset(length
);
146 glsl_type_is_void(const glsl_type
*type
)
148 return type
->is_void();
152 glsl_type_is_error(const glsl_type
*type
)
154 return type
->is_error();
158 glsl_type_is_vector(const struct glsl_type
*type
)
160 return type
->is_vector();
164 glsl_type_is_scalar(const struct glsl_type
*type
)
166 return type
->is_scalar();
170 glsl_type_is_vector_or_scalar(const struct glsl_type
*type
)
172 return type
->is_vector() || type
->is_scalar();
176 glsl_type_is_matrix(const struct glsl_type
*type
)
178 return type
->is_matrix();
182 glsl_type_is_array(const struct glsl_type
*type
)
184 return type
->is_array();
188 glsl_type_is_array_of_arrays(const struct glsl_type
*type
)
190 return type
->is_array_of_arrays();
194 glsl_type_is_struct(const struct glsl_type
*type
)
196 return type
->is_record() || type
->is_interface();
200 glsl_type_is_sampler(const struct glsl_type
*type
)
202 return type
->is_sampler();
206 glsl_type_is_image(const struct glsl_type
*type
)
208 return type
->is_image();
212 glsl_sampler_type_is_shadow(const struct glsl_type
*type
)
214 assert(glsl_type_is_sampler(type
));
215 return type
->sampler_shadow
;
219 glsl_sampler_type_is_array(const struct glsl_type
*type
)
221 assert(glsl_type_is_sampler(type
) || glsl_type_is_image(type
));
222 return type
->sampler_array
;
226 glsl_type_is_dual_slot(const struct glsl_type
*type
)
228 return type
->is_dual_slot();
232 glsl_type_is_numeric(const struct glsl_type
*type
)
234 return type
->is_numeric();
238 glsl_type_is_boolean(const struct glsl_type
*type
)
240 return type
->is_boolean();
246 return glsl_type::void_type
;
250 glsl_float_type(void)
252 return glsl_type::float_type
;
256 glsl_double_type(void)
258 return glsl_type::double_type
;
262 glsl_vec_type(unsigned n
)
264 return glsl_type::vec(n
);
268 glsl_dvec_type(unsigned n
)
270 return glsl_type::dvec(n
);
276 return glsl_type::vec4_type
;
282 return glsl_type::int_type
;
288 return glsl_type::uint_type
;
292 glsl_int64_t_type(void)
294 return glsl_type::int64_t_type
;
298 glsl_uint64_t_type(void)
300 return glsl_type::uint64_t_type
;
306 return glsl_type::bool_type
;
310 glsl_scalar_type(enum glsl_base_type base_type
)
312 return glsl_type::get_instance(base_type
, 1, 1);
316 glsl_vector_type(enum glsl_base_type base_type
, unsigned components
)
318 assert(components
> 1 && components
<= 4);
319 return glsl_type::get_instance(base_type
, components
, 1);
323 glsl_matrix_type(enum glsl_base_type base_type
, unsigned rows
, unsigned columns
)
325 assert(rows
> 1 && rows
<= 4 && columns
>= 1 && columns
<= 4);
326 return glsl_type::get_instance(base_type
, rows
, columns
);
330 glsl_array_type(const glsl_type
*base
, unsigned elements
)
332 return glsl_type::get_array_instance(base
, elements
);
336 glsl_struct_type(const glsl_struct_field
*fields
,
337 unsigned num_fields
, const char *name
)
339 return glsl_type::get_record_instance(fields
, num_fields
, name
);
342 const struct glsl_type
*
343 glsl_sampler_type(enum glsl_sampler_dim dim
, bool is_shadow
, bool is_array
,
344 enum glsl_base_type base_type
)
346 return glsl_type::get_sampler_instance(dim
, is_shadow
, is_array
, base_type
);
349 const struct glsl_type
*
350 glsl_bare_sampler_type()
352 return glsl_type::sampler_type
;
355 const struct glsl_type
*
356 glsl_image_type(enum glsl_sampler_dim dim
, bool is_array
,
357 enum glsl_base_type base_type
)
359 return glsl_type::get_image_instance(dim
, is_array
, base_type
);
363 glsl_function_type(const glsl_type
*return_type
,
364 const glsl_function_param
*params
, unsigned num_params
)
366 return glsl_type::get_function_instance(return_type
, params
, num_params
);
370 glsl_transposed_type(const struct glsl_type
*type
)
372 assert(glsl_type_is_matrix(type
));
373 return glsl_type::get_instance(type
->base_type
, type
->matrix_columns
,
374 type
->vector_elements
);