[Mesa-dev] [PATCH 16/16] glsl: Do not add extra padding to structures

Ian Romanick idr at freedesktop.org
Mon Jul 21 14:04:32 PDT 2014


From: Ian Romanick <ian.d.romanick at intel.com>

This code was attemping to align the base of the structure to the required
alignment of the structure.  However, it had two problems:

1. It was aligning the target structure member, not the base of the
structure.

2. It was calculating the alignment based on the members previous to the
target member instead of all the members of the structure.

Fixes gles3conform failures in:

ES3-CTS.shaders.uniform_block.random.nested_structs.6
ES3-CTS.shaders.uniform_block.random.nested_structs_arrays_instance_arrays.2
ES3-CTS.shaders.uniform_block.random.nested_structs_arrays_instance_arrays.6
ES3-CTS.shaders.uniform_block.random.all_per_block_buffers.5
ES3-CTS.shaders.uniform_block.random.all_per_block_buffers.19
ES3-CTS.shaders.uniform_block.random.all_shared_buffer.0
ES3-CTS.shaders.uniform_block.random.all_shared_buffer.2
ES3-CTS.shaders.uniform_block.random.all_shared_buffer.6
ES3-CTS.shaders.uniform_block.random.all_shared_buffer.12

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/lower_ubo_reference.cpp | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/src/glsl/lower_ubo_reference.cpp b/src/glsl/lower_ubo_reference.cpp
index 0ee4e8a..54e67d9 100644
--- a/src/glsl/lower_ubo_reference.cpp
+++ b/src/glsl/lower_ubo_reference.cpp
@@ -62,9 +62,7 @@ is_dereferenced_thing_row_major(const ir_dereference *deref)
    const ir_rvalue *ir = deref;
 
    while (true) {
-      if (ir->type->is_matrix()
-          || (ir->type->is_array() && ir->type->fields.array->is_matrix()))
-         matrix = true;
+      matrix = matrix || ir->type->is_matrix_or_array_of();
 
       switch (ir->ir_type) {
       case ir_type_dereference_array: {
@@ -93,7 +91,7 @@ is_dereferenced_thing_row_major(const ir_dereference *deref)
          case GLSL_MATRIX_LAYOUT_COLUMN_MAJOR:
             return false;
          case GLSL_MATRIX_LAYOUT_ROW_MAJOR:
-            return matrix || deref->type->is_record();
+            return matrix || deref->type->is_record_or_array_of();
          }
 
          break;
@@ -308,7 +306,6 @@ lower_ubo_reference_visitor::handle_rvalue(ir_rvalue **rvalue)
 	 const glsl_type *struct_type = deref_record->record->type;
 	 unsigned intra_struct_offset = 0;
 
-	 unsigned max_field_align = 16;
 	 for (unsigned int i = 0; i < struct_type->length; i++) {
 	    const glsl_type *type = struct_type->fields.structure[i].type;
 
@@ -322,7 +319,6 @@ lower_ubo_reference_visitor::handle_rvalue(ir_rvalue **rvalue)
 
             unsigned field_align = type->std140_base_alignment(field_row_major);
 
-	    max_field_align = MAX2(field_align, max_field_align);
 	    intra_struct_offset = glsl_align(intra_struct_offset, field_align);
 
 	    if (strcmp(struct_type->fields.structure[i].name,
@@ -331,7 +327,6 @@ lower_ubo_reference_visitor::handle_rvalue(ir_rvalue **rvalue)
             intra_struct_offset += type->std140_size(field_row_major);
 	 }
 
-	 const_offset = glsl_align(const_offset, max_field_align);
 	 const_offset += intra_struct_offset;
 
 	 deref = deref_record->record->as_dereference();
-- 
1.8.1.4



More information about the mesa-dev mailing list