glsl: Respect std430 layout in lower_buffer_access
authorFlorian Will <florian.will@gmail.com>
Fri, 5 Jan 2018 14:33:31 +0000 (15:33 +0100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Mon, 8 Jan 2018 02:42:09 +0000 (13:42 +1100)
Respect the std430 rules for determining offset and size of struct
members when using a std430 buffer. std140 rules lead to wrong buffer
offsets in that case.

Fixes my test case attached in Bugzilla. No piglit changes.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=104492
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/compiler/glsl/lower_buffer_access.cpp

index db6e8e367b7f2363d8c296266c315604b4f6e7b2..ff6f9c1fcfe4cffa582a0e7df0191b382b29dc77 100644 (file)
@@ -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;
    }