mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-09 11:08:03 +02:00
compiler/types: fix size of padded OpenCL Structs
In C the size of a struct { uin32_t a; uint8_t b; } is 8, not 5, so we have
to account for the biggest alignment across all struct members.
Funny that the OpenCL CTS doesn't catch that.
Fixes: 44d32e62fb ("glsl: add cl_size and cl_alignment")
Signed-off-by: Karol Herbst <git@karolherbst.de>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23701>
(cherry picked from commit 4431e5a222)
This commit is contained in:
parent
9c599dff88
commit
8bdf4b2b41
2 changed files with 10 additions and 3 deletions
|
|
@ -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"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue