glsl: Propagate packed info in get_explicit_type_for_size_align()
authorBoris Brezillon <boris.brezillon@collabora.com>
Fri, 26 Jun 2020 08:27:16 +0000 (10:27 +0200)
committerMarge Bot <eric+marge@anholt.net>
Thu, 3 Sep 2020 18:02:50 +0000 (18:02 +0000)
Right now, when calling get_explicit_type_for_size_align() on a packed
struct, the packed attribute is lost and field offsets are wrong.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6472>

src/compiler/glsl_types.cpp

index a5f5f5854e4c8742d8baaec27526791769458501..ab4c2954864cd3a9fe04720f28674c355b295022 100644 (file)
@@ -2465,6 +2465,7 @@ glsl_type::get_explicit_type_for_size_align(glsl_type_size_align_func type_info,
          unsigned field_size, field_align;
          fields[i].type =
             fields[i].type->get_explicit_type_for_size_align(type_info, &field_size, &field_align);
+         field_align = this->packed ? 1 : field_align;
          fields[i].offset = align(*size, field_align);
 
          *size = fields[i].offset + field_size;
@@ -2473,8 +2474,10 @@ glsl_type::get_explicit_type_for_size_align(glsl_type_size_align_func type_info,
 
       const glsl_type *type;
       if (this->is_struct()) {
-         type = get_struct_instance(fields, this->length, this->name, false);
+         type = get_struct_instance(fields, this->length, this->name,
+                                    this->packed);
       } else {
+         assert(!this->packed);
          type = get_interface_instance(fields, this->length,
                                        (enum glsl_interface_packing)this->interface_packing,
                                        this->interface_row_major,