Mesa (main): compiler/types: Don't place members in the previous substruct's end padding
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Jun 9 23:24:18 UTC 2022
Module: Mesa
Branch: main
Commit: 133620196d57cc1c6874c806095fc3cf1f054274
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=133620196d57cc1c6874c806095fc3cf1f054274
Author: Jason Ekstrand <jason at jlekstrand.net>
Date: Sat Oct 24 13:28:39 2020 -0500
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
computation
Cc: mesa-stable
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16940>
---
src/compiler/glsl_types.cpp | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
index 538ff49765e..c890928ab1b 100644
--- a/src/compiler/glsl_types.cpp
+++ b/src/compiler/glsl_types.cpp
@@ -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."
+ *
+ * https://doc.rust-lang.org/reference/type-layout.html#reprc-structs
+ */
+ *size = align(*size, *alignment);
const glsl_type *type;
if (this->is_struct()) {
More information about the mesa-commit
mailing list