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_print_type(const glsl_type
*type
, FILE *fp
)
34 if (type
->base_type
== GLSL_TYPE_ARRAY
) {
35 glsl_print_type(type
->fields
.array
, fp
);
36 fprintf(fp
, "[%u]", type
->length
);
37 } else if ((type
->base_type
== GLSL_TYPE_STRUCT
)
38 && !is_gl_identifier(type
->name
)) {
39 fprintf(fp
, "%s@%p", type
->name
, (void *) type
);
41 fprintf(fp
, "%s", type
->name
);
46 glsl_print_struct(const glsl_type
*type
, FILE *fp
)
48 assert(type
->base_type
== GLSL_TYPE_STRUCT
);
50 fprintf(fp
, "struct {\n");
51 for (unsigned i
= 0; i
< type
->length
; i
++) {
53 glsl_print_type(type
->fields
.structure
[i
].type
, fp
);
54 fprintf(fp
, " %s;\n", type
->fields
.structure
[i
].name
);
60 glsl_get_array_element(const glsl_type
* type
)
62 if (type
->is_matrix())
63 return type
->column_type();
64 return type
->fields
.array
;
68 glsl_without_array(const glsl_type
*type
)
70 return type
->without_array();
74 glsl_get_struct_field(const glsl_type
*type
, unsigned index
)
76 return type
->fields
.structure
[index
].type
;
80 glsl_get_function_return_type(const glsl_type
*type
)
82 return type
->fields
.parameters
[0].type
;
85 const glsl_function_param
*
86 glsl_get_function_param(const glsl_type
*type
, unsigned index
)
88 return &type
->fields
.parameters
[index
+ 1];
91 const struct glsl_type
*
92 glsl_get_column_type(const struct glsl_type
*type
)
94 return type
->column_type();
98 glsl_get_base_type(const struct glsl_type
*type
)
100 return type
->base_type
;
104 glsl_get_vector_elements(const struct glsl_type
*type
)
106 return type
->vector_elements
;
110 glsl_get_components(const struct glsl_type
*type
)
112 return type
->components();
116 glsl_get_matrix_columns(const struct glsl_type
*type
)
118 return type
->matrix_columns
;
122 glsl_get_length(const struct glsl_type
*type
)
124 return type
->is_matrix() ? type
->matrix_columns
: type
->length
;
128 glsl_get_aoa_size(const struct glsl_type
*type
)
130 return type
->arrays_of_arrays_size();
134 glsl_count_attribute_slots(const struct glsl_type
*type
,
135 bool is_vertex_input
)
137 return type
->count_attribute_slots(is_vertex_input
);
141 glsl_get_struct_elem_name(const struct glsl_type
*type
, unsigned index
)
143 return type
->fields
.structure
[index
].name
;
147 glsl_get_sampler_dim(const struct glsl_type
*type
)
149 assert(glsl_type_is_sampler(type
) || glsl_type_is_image(type
));
150 return (glsl_sampler_dim
)type
->sampler_dimensionality
;
154 glsl_get_sampler_result_type(const struct glsl_type
*type
)
156 assert(glsl_type_is_sampler(type
) || glsl_type_is_image(type
));
157 return (glsl_base_type
)type
->sampled_type
;
161 glsl_get_record_location_offset(const struct glsl_type
*type
,
164 return type
->record_location_offset(length
);
168 glsl_type_is_void(const glsl_type
*type
)
170 return type
->is_void();
174 glsl_type_is_error(const glsl_type
*type
)
176 return type
->is_error();
180 glsl_type_is_vector(const struct glsl_type
*type
)
182 return type
->is_vector();
186 glsl_type_is_scalar(const struct glsl_type
*type
)
188 return type
->is_scalar();
192 glsl_type_is_vector_or_scalar(const struct glsl_type
*type
)
194 return type
->is_vector() || type
->is_scalar();
198 glsl_type_is_matrix(const struct glsl_type
*type
)
200 return type
->is_matrix();
204 glsl_type_is_array(const struct glsl_type
*type
)
206 return type
->is_array();
210 glsl_type_is_struct(const struct glsl_type
*type
)
212 return type
->is_record() || type
->is_interface();
216 glsl_type_is_sampler(const struct glsl_type
*type
)
218 return type
->is_sampler();
222 glsl_type_is_image(const struct glsl_type
*type
)
224 return type
->is_image();
228 glsl_sampler_type_is_shadow(const struct glsl_type
*type
)
230 assert(glsl_type_is_sampler(type
));
231 return type
->sampler_shadow
;
235 glsl_sampler_type_is_array(const struct glsl_type
*type
)
237 assert(glsl_type_is_sampler(type
) || glsl_type_is_image(type
));
238 return type
->sampler_array
;
244 return glsl_type::void_type
;
248 glsl_float_type(void)
250 return glsl_type::float_type
;
254 glsl_double_type(void)
256 return glsl_type::double_type
;
260 glsl_vec_type(unsigned n
)
262 return glsl_type::vec(n
);
266 glsl_dvec_type(unsigned n
)
268 return glsl_type::dvec(n
);
274 return glsl_type::vec4_type
;
280 return glsl_type::int_type
;
286 return glsl_type::uint_type
;
292 return glsl_type::bool_type
;
296 glsl_scalar_type(enum glsl_base_type base_type
)
298 return glsl_type::get_instance(base_type
, 1, 1);
302 glsl_vector_type(enum glsl_base_type base_type
, unsigned components
)
304 assert(components
> 1 && components
<= 4);
305 return glsl_type::get_instance(base_type
, components
, 1);
309 glsl_matrix_type(enum glsl_base_type base_type
, unsigned rows
, unsigned columns
)
311 assert(rows
> 1 && rows
<= 4 && columns
>= 1 && columns
<= 4);
312 return glsl_type::get_instance(base_type
, rows
, columns
);
316 glsl_array_type(const glsl_type
*base
, unsigned elements
)
318 return glsl_type::get_array_instance(base
, elements
);
322 glsl_struct_type(const glsl_struct_field
*fields
,
323 unsigned num_fields
, const char *name
)
325 return glsl_type::get_record_instance(fields
, num_fields
, name
);
328 const struct glsl_type
*
329 glsl_sampler_type(enum glsl_sampler_dim dim
, bool is_shadow
, bool is_array
,
330 enum glsl_base_type base_type
)
332 return glsl_type::get_sampler_instance(dim
, is_shadow
, is_array
, base_type
);
335 const struct glsl_type
*
336 glsl_bare_sampler_type()
338 return glsl_type::sampler_type
;
341 const struct glsl_type
*
342 glsl_image_type(enum glsl_sampler_dim dim
, bool is_array
,
343 enum glsl_base_type base_type
)
345 return glsl_type::get_image_instance(dim
, is_array
, base_type
);
349 glsl_function_type(const glsl_type
*return_type
,
350 const glsl_function_param
*params
, unsigned num_params
)
352 return glsl_type::get_function_instance(return_type
, params
, num_params
);
356 glsl_transposed_type(const struct glsl_type
*type
)
358 assert(glsl_type_is_matrix(type
));
359 return glsl_type::get_instance(type
->base_type
, type
->matrix_columns
,
360 type
->vector_elements
);