diff --git a/.pick_status.json b/.pick_status.json index 7aab705a7f1..d9a965d1d5b 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -211,7 +211,7 @@ "description": "compiler/types: fix size of padded OpenCL Structs", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "44d32e62fb8d1fa9bf22c136aa41114d19b2d874" }, diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp index 2bc7d1d7445..df11bf08ece 100644 --- a/src/compiler/glsl_types.cpp +++ b/src/compiler/glsl_types.cpp @@ -3360,13 +3360,20 @@ glsl_type::cl_size() const return size * this->length; } else if (this->is_struct()) { unsigned size = 0; + unsigned max_alignment = 1; for (unsigned i = 0; i < this->length; ++i) { struct glsl_struct_field &field = this->fields.structure[i]; /* if a struct is packed, members don't get aligned */ - if (!this->packed) - size = align(size, field.type->cl_alignment()); + if (!this->packed) { + unsigned alignment = field.type->cl_alignment(); + max_alignment = MAX2(max_alignment, alignment); + size = align(size, alignment); + } size += field.type->cl_size(); } + + /* Size of C structs are aligned to the biggest alignment of its fields */ + size = align(size, max_alignment); return size; } return 1;