glsl_type: Add a C wrapper to get struct field offsets
[mesa.git] / src / compiler / nir_types.cpp
index 1fae6aa81801bb5f43bb304aabaf25790d5ef035..6995a897d60e9ce1825701b88e603384e146fdbb 100644 (file)
@@ -60,16 +60,16 @@ glsl_without_array_or_matrix(const glsl_type *type)
 }
 
 const glsl_type *
-glsl_get_array_instance(const glsl_type *type,
-                        unsigned array_size)
+glsl_get_struct_field(const glsl_type *type, unsigned index)
 {
-   return glsl_type::get_array_instance(type, array_size);
+   return type->fields.structure[index].type;
 }
 
-const glsl_type *
-glsl_get_struct_field(const glsl_type *type, unsigned index)
+const int
+glsl_get_struct_field_offset(const struct glsl_type *type,
+                             unsigned index)
 {
-   return type->fields.structure[index].type;
+   return type->fields.structure[index].offset;
 }
 
 const glsl_type *
@@ -172,6 +172,13 @@ glsl_get_sampler_target(const struct glsl_type *type)
    return type->sampler_index();
 }
 
+int
+glsl_get_sampler_coordinate_components(const struct glsl_type *type)
+{
+   assert(glsl_type_is_sampler(type) || glsl_type_is_image(type));
+   return type->coordinate_components();
+}
+
 unsigned
 glsl_get_record_location_offset(const struct glsl_type *type,
                                 unsigned length)
@@ -294,6 +301,11 @@ glsl_type_is_boolean(const struct glsl_type *type)
 {
    return type->is_boolean();
 }
+bool
+glsl_type_is_integer(const struct glsl_type *type)
+{
+   return type->is_integer();
+}
 
 const glsl_type *
 glsl_void_type(void)
@@ -516,6 +528,14 @@ glsl_get_natural_size_align_bytes(const struct glsl_type *type,
                                   unsigned *size, unsigned *align)
 {
    switch (type->base_type) {
+   case GLSL_TYPE_BOOL:
+      /* We special-case Booleans to 32 bits to not cause heartburn for
+       * drivers that suddenly get an 8-bit load.
+       */
+      *size = 4 * type->components();
+      *align = 4;
+      break;
+
    case GLSL_TYPE_UINT8:
    case GLSL_TYPE_INT8:
    case GLSL_TYPE_UINT16:
@@ -524,7 +544,6 @@ glsl_get_natural_size_align_bytes(const struct glsl_type *type,
    case GLSL_TYPE_UINT:
    case GLSL_TYPE_INT:
    case GLSL_TYPE_FLOAT:
-   case GLSL_TYPE_BOOL:
    case GLSL_TYPE_DOUBLE:
    case GLSL_TYPE_UINT64:
    case GLSL_TYPE_INT64: {