Home | History | Annotate | Download | only in compiler
      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 (at) 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_struct_field(const glsl_type *type, unsigned index)
     53 {
     54    return type->fields.structure[index].type;
     55 }
     56 
     57 const glsl_type *
     58 glsl_get_function_return_type(const glsl_type *type)
     59 {
     60    return type->fields.parameters[0].type;
     61 }
     62 
     63 const glsl_function_param *
     64 glsl_get_function_param(const glsl_type *type, unsigned index)
     65 {
     66    return &type->fields.parameters[index + 1];
     67 }
     68 
     69 const struct glsl_type *
     70 glsl_get_column_type(const struct glsl_type *type)
     71 {
     72    return type->column_type();
     73 }
     74 
     75 enum glsl_base_type
     76 glsl_get_base_type(const struct glsl_type *type)
     77 {
     78    return type->base_type;
     79 }
     80 
     81 unsigned
     82 glsl_get_vector_elements(const struct glsl_type *type)
     83 {
     84    return type->vector_elements;
     85 }
     86 
     87 unsigned
     88 glsl_get_components(const struct glsl_type *type)
     89 {
     90    return type->components();
     91 }
     92 
     93 unsigned
     94 glsl_get_matrix_columns(const struct glsl_type *type)
     95 {
     96    return type->matrix_columns;
     97 }
     98 
     99 unsigned
    100 glsl_get_length(const struct glsl_type *type)
    101 {
    102    return type->is_matrix() ? type->matrix_columns : type->length;
    103 }
    104 
    105 unsigned
    106 glsl_get_aoa_size(const struct glsl_type *type)
    107 {
    108    return type->arrays_of_arrays_size();
    109 }
    110 
    111 unsigned
    112 glsl_count_attribute_slots(const struct glsl_type *type,
    113                            bool is_vertex_input)
    114 {
    115    return type->count_attribute_slots(is_vertex_input);
    116 }
    117 
    118 const char *
    119 glsl_get_struct_elem_name(const struct glsl_type *type, unsigned index)
    120 {
    121    return type->fields.structure[index].name;
    122 }
    123 
    124 glsl_sampler_dim
    125 glsl_get_sampler_dim(const struct glsl_type *type)
    126 {
    127    assert(glsl_type_is_sampler(type) || glsl_type_is_image(type));
    128    return (glsl_sampler_dim)type->sampler_dimensionality;
    129 }
    130 
    131 glsl_base_type
    132 glsl_get_sampler_result_type(const struct glsl_type *type)
    133 {
    134    assert(glsl_type_is_sampler(type) || glsl_type_is_image(type));
    135    return (glsl_base_type)type->sampled_type;
    136 }
    137 
    138 unsigned
    139 glsl_get_record_location_offset(const struct glsl_type *type,
    140                                 unsigned length)
    141 {
    142    return type->record_location_offset(length);
    143 }
    144 
    145 bool
    146 glsl_type_is_void(const glsl_type *type)
    147 {
    148    return type->is_void();
    149 }
    150 
    151 bool
    152 glsl_type_is_error(const glsl_type *type)
    153 {
    154    return type->is_error();
    155 }
    156 
    157 bool
    158 glsl_type_is_vector(const struct glsl_type *type)
    159 {
    160    return type->is_vector();
    161 }
    162 
    163 bool
    164 glsl_type_is_scalar(const struct glsl_type *type)
    165 {
    166    return type->is_scalar();
    167 }
    168 
    169 bool
    170 glsl_type_is_vector_or_scalar(const struct glsl_type *type)
    171 {
    172    return type->is_vector() || type->is_scalar();
    173 }
    174 
    175 bool
    176 glsl_type_is_matrix(const struct glsl_type *type)
    177 {
    178    return type->is_matrix();
    179 }
    180 
    181 bool
    182 glsl_type_is_array(const struct glsl_type *type)
    183 {
    184    return type->is_array();
    185 }
    186 
    187 bool
    188 glsl_type_is_array_of_arrays(const struct glsl_type *type)
    189 {
    190    return type->is_array_of_arrays();
    191 }
    192 
    193 bool
    194 glsl_type_is_struct(const struct glsl_type *type)
    195 {
    196    return type->is_record() || type->is_interface();
    197 }
    198 
    199 bool
    200 glsl_type_is_sampler(const struct glsl_type *type)
    201 {
    202    return type->is_sampler();
    203 }
    204 
    205 bool
    206 glsl_type_is_image(const struct glsl_type *type)
    207 {
    208    return type->is_image();
    209 }
    210 
    211 bool
    212 glsl_sampler_type_is_shadow(const struct glsl_type *type)
    213 {
    214    assert(glsl_type_is_sampler(type));
    215    return type->sampler_shadow;
    216 }
    217 
    218 bool
    219 glsl_sampler_type_is_array(const struct glsl_type *type)
    220 {
    221    assert(glsl_type_is_sampler(type) || glsl_type_is_image(type));
    222    return type->sampler_array;
    223 }
    224 
    225 bool
    226 glsl_type_is_dual_slot(const struct glsl_type *type)
    227 {
    228    return type->is_dual_slot();
    229 }
    230 
    231 bool
    232 glsl_type_is_numeric(const struct glsl_type *type)
    233 {
    234    return type->is_numeric();
    235 }
    236 
    237 bool
    238 glsl_type_is_boolean(const struct glsl_type *type)
    239 {
    240    return type->is_boolean();
    241 }
    242 
    243 const glsl_type *
    244 glsl_void_type(void)
    245 {
    246    return glsl_type::void_type;
    247 }
    248 
    249 const glsl_type *
    250 glsl_float_type(void)
    251 {
    252    return glsl_type::float_type;
    253 }
    254 
    255 const glsl_type *
    256 glsl_double_type(void)
    257 {
    258    return glsl_type::double_type;
    259 }
    260 
    261 const glsl_type *
    262 glsl_vec_type(unsigned n)
    263 {
    264    return glsl_type::vec(n);
    265 }
    266 
    267 const glsl_type *
    268 glsl_dvec_type(unsigned n)
    269 {
    270    return glsl_type::dvec(n);
    271 }
    272 
    273 const glsl_type *
    274 glsl_vec4_type(void)
    275 {
    276    return glsl_type::vec4_type;
    277 }
    278 
    279 const glsl_type *
    280 glsl_int_type(void)
    281 {
    282    return glsl_type::int_type;
    283 }
    284 
    285 const glsl_type *
    286 glsl_uint_type(void)
    287 {
    288    return glsl_type::uint_type;
    289 }
    290 
    291 const glsl_type *
    292 glsl_bool_type(void)
    293 {
    294    return glsl_type::bool_type;
    295 }
    296 
    297 const glsl_type *
    298 glsl_scalar_type(enum glsl_base_type base_type)
    299 {
    300    return glsl_type::get_instance(base_type, 1, 1);
    301 }
    302 
    303 const glsl_type *
    304 glsl_vector_type(enum glsl_base_type base_type, unsigned components)
    305 {
    306    assert(components > 1 && components <= 4);
    307    return glsl_type::get_instance(base_type, components, 1);
    308 }
    309 
    310 const glsl_type *
    311 glsl_matrix_type(enum glsl_base_type base_type, unsigned rows, unsigned columns)
    312 {
    313    assert(rows > 1 && rows <= 4 && columns >= 1 && columns <= 4);
    314    return glsl_type::get_instance(base_type, rows, columns);
    315 }
    316 
    317 const glsl_type *
    318 glsl_array_type(const glsl_type *base, unsigned elements)
    319 {
    320    return glsl_type::get_array_instance(base, elements);
    321 }
    322 
    323 const glsl_type *
    324 glsl_struct_type(const glsl_struct_field *fields,
    325                  unsigned num_fields, const char *name)
    326 {
    327    return glsl_type::get_record_instance(fields, num_fields, name);
    328 }
    329 
    330 const struct glsl_type *
    331 glsl_sampler_type(enum glsl_sampler_dim dim, bool is_shadow, bool is_array,
    332                   enum glsl_base_type base_type)
    333 {
    334    return glsl_type::get_sampler_instance(dim, is_shadow, is_array, base_type);
    335 }
    336 
    337 const struct glsl_type *
    338 glsl_bare_sampler_type()
    339 {
    340    return glsl_type::sampler_type;
    341 }
    342 
    343 const struct glsl_type *
    344 glsl_image_type(enum glsl_sampler_dim dim, bool is_array,
    345                 enum glsl_base_type base_type)
    346 {
    347    return glsl_type::get_image_instance(dim, is_array, base_type);
    348 }
    349 
    350 const glsl_type *
    351 glsl_function_type(const glsl_type *return_type,
    352                    const glsl_function_param *params, unsigned num_params)
    353 {
    354    return glsl_type::get_function_instance(return_type, params, num_params);
    355 }
    356 
    357 const glsl_type *
    358 glsl_transposed_type(const struct glsl_type *type)
    359 {
    360    assert(glsl_type_is_matrix(type));
    361    return glsl_type::get_instance(type->base_type, type->matrix_columns,
    362                                   type->vector_elements);
    363 }
    364