glsl: fix the type of ir_constant_data::u16
[mesa.git] / src / compiler / glsl / lower_buffer_access.cpp
index 219e03e550dd972c16a715d60cc5f0be565d70cc..a6e2f741ebe66e925a55d359d00cc5df206b8061 100644 (file)
@@ -63,7 +63,7 @@ lower_buffer_access::emit_access(void *mem_ctx,
                                  enum glsl_interface_packing packing,
                                  unsigned int write_mask)
 {
-   if (deref->type->is_record()) {
+   if (deref->type->is_struct()) {
       unsigned int field_offset = 0;
 
       for (unsigned i = 0; i < deref->type->length; i++) {
@@ -73,16 +73,22 @@ lower_buffer_access::emit_access(void *mem_ctx,
             new(mem_ctx) ir_dereference_record(deref->clone(mem_ctx, NULL),
                                                field->name);
 
-         field_offset =
-            glsl_align(field_offset,
-                       field->type->std140_base_alignment(row_major));
+         unsigned field_align;
+         if (packing == GLSL_INTERFACE_PACKING_STD430)
+            field_align = field->type->std430_base_alignment(row_major);
+         else
+            field_align = field->type->std140_base_alignment(row_major);
+         field_offset = glsl_align(field_offset, field_align);
 
          emit_access(mem_ctx, is_write, field_deref, base_offset,
                      deref_offset + field_offset,
                      row_major, NULL, packing,
                      writemask_for_size(field_deref->type->vector_elements));
 
-         field_offset += field->type->std140_size(row_major);
+         if (packing == GLSL_INTERFACE_PACKING_STD430)
+            field_offset += field->type->std430_size(row_major);
+         else
+            field_offset += field->type->std140_size(row_major);
       }
       return;
    }
@@ -111,42 +117,17 @@ lower_buffer_access::emit_access(void *mem_ctx,
          ir_dereference *col_deref =
             new(mem_ctx) ir_dereference_array(deref->clone(mem_ctx, NULL), col);
 
-         if (row_major) {
-            /* For a row-major matrix, the next column starts at the next
-             * element.
-             */
-            int size_mul = deref->type->is_64bit() ? 8 : 4;
-            emit_access(mem_ctx, is_write, col_deref, base_offset,
-                        deref_offset + i * size_mul,
-                        row_major, deref->type, packing,
-                        writemask_for_size(col_deref->type->vector_elements));
-         } else {
-            int size_mul;
-
-            /* std430 doesn't round up vec2 size to a vec4 size */
-            if (packing == GLSL_INTERFACE_PACKING_STD430 &&
-                deref->type->vector_elements == 2 &&
-                !deref->type->is_64bit()) {
-               size_mul = 8;
-            } else {
-               /* std140 always rounds the stride of arrays (and matrices) to a
-                * vec4, so matrices are always 16 between columns/rows. With
-                * doubles, they will be 32 apart when there are more than 2 rows.
-                *
-                * For both std140 and std430, if the member is a
-                * three-'component vector with components consuming N basic
-                * machine units, the base alignment is 4N. For vec4, base
-                * alignment is 4N.
-                */
-               size_mul = (deref->type->is_64bit() &&
-                           deref->type->vector_elements > 2) ? 32 : 16;
-            }
-
-            emit_access(mem_ctx, is_write, col_deref, base_offset,
-                        deref_offset + i * size_mul,
-                        row_major, deref->type, packing,
-                        writemask_for_size(col_deref->type->vector_elements));
-         }
+         /* For a row-major matrix, the next column starts at the next
+          * element.  Otherwise it is offset by the matrix stride.
+          */
+         const unsigned size_mul = row_major
+            ? (deref->type->is_double() ? 8 : 4)
+            : link_calculate_matrix_stride(deref->type, row_major, packing);
+
+         emit_access(mem_ctx, is_write, col_deref, base_offset,
+                     deref_offset + i * size_mul,
+                     row_major, deref->type, packing,
+                     writemask_for_size(col_deref->type->vector_elements));
       }
       return;
    }
@@ -169,8 +150,7 @@ lower_buffer_access::emit_access(void *mem_ctx,
       const unsigned matrix_stride =
          link_calculate_matrix_stride(matrix_type, row_major, packing);
 
-      const glsl_type *deref_type = deref->type->is_float() ?
-         glsl_type::float_type : glsl_type::double_type;
+      const glsl_type *deref_type = deref->type->get_scalar_type();
 
       for (unsigned i = 0; i < deref->type->vector_elements; i++) {
          ir_rvalue *chan_offset =
@@ -234,7 +214,7 @@ lower_buffer_access::is_dereferenced_thing_row_major(const ir_rvalue *deref)
          case GLSL_MATRIX_LAYOUT_COLUMN_MAJOR:
             return false;
          case GLSL_MATRIX_LAYOUT_ROW_MAJOR:
-            return matrix || deref->type->without_array()->is_record();
+            return matrix || deref->type->without_array()->is_struct();
          }
 
          break;
@@ -253,7 +233,7 @@ lower_buffer_access::is_dereferenced_thing_row_major(const ir_rvalue *deref)
              * layouts at HIR generation time, but we don't do that for shared
              * variables, which are always column-major
              */
-            MAYBE_UNUSED ir_variable *var = deref->variable_referenced();
+            ASSERTED ir_variable *var = deref->variable_referenced();
             assert((var->is_in_buffer_block() && !matrix) ||
                    var->data.mode == ir_var_shader_shared);
             return false;
@@ -261,7 +241,7 @@ lower_buffer_access::is_dereferenced_thing_row_major(const ir_rvalue *deref)
          case GLSL_MATRIX_LAYOUT_COLUMN_MAJOR:
             return false;
          case GLSL_MATRIX_LAYOUT_ROW_MAJOR:
-            return matrix || deref->type->without_array()->is_record();
+            return matrix || deref->type->without_array()->is_struct();
          }
 
          unreachable("invalid matrix layout");
@@ -434,7 +414,7 @@ lower_buffer_access::setup_buffer_access(void *mem_ctx,
              *     of the member following the sub-structure is rounded up to
              *     the next multiple of the base alignment of the structure."
              */
-            if (type->without_array()->is_record()) {
+            if (type->without_array()->is_struct()) {
                intra_struct_offset = glsl_align(intra_struct_offset,
                                                 field_align);