Commit 13362019 authored by Jason Ekstrand's avatar Jason Ekstrand Committed by Marge Bot
Browse files

compiler/types: Don't place members in the previous substruct's end padding

With the following structures :

  struct StructA
     uint64_t value0;
     uint8_t  value1;

  struct TopStruct
     struct StructA a;
     uint8_t value3;

Currently offsetof(struct TopStruct, value3) = 9. While the same code
on the CPU gives offsetof(struct TopStruct, value3) = 16.

This is impacting OpenCL kernels we're trying to use to build
acceleration structures.

v2: Add comment/link to some description of the alignment/size

Cc: mesa-stable
Signed-off-by: Lionel Landwerlin's avatarLionel Landwerlin <>
Reviewed-by: Jason Ekstrand's avatarJason Ekstrand <>
Part-of: <!16940>
parent 2aeb8311
Pipeline #609076 waiting for manual action with stages
......@@ -2761,6 +2761,16 @@ glsl_type::get_explicit_type_for_size_align(glsl_type_size_align_func type_info,
*size = fields[i].offset + field_size;
*alignment = MAX2(*alignment, field_align);
* "The alignment of the struct is the alignment of the most-aligned
* field in it."
* "Finally, the size of the struct is the current offset rounded up to
* the nearest multiple of the struct's alignment."
*size = align(*size, *alignment);
const glsl_type *type;
if (this->is_struct()) {
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment