From af7dfed07daba3df3668ebed0326c8e564a57cb8 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Tue, 6 Jun 2023 20:53:41 -0400 Subject: [PATCH] u_format: Use memcpy to avoid unaligned accesses These functions are used by gl[Get]TexImage, which imposes no alignment restructions on the void *pixels parameter. This fixes an unaligned access in GTK's "gtk:gdk / memorytexture" unit test on SPARC, which causes the test to fail. Fixes: 45ae4434b5b ("util: Use bitshift arithmetic to unpack pixels.") Part-of: (cherry picked from commit 19092576ce3678d090b4a62742b8fc0bc1293ab5) --- .pick_status.json | 2 +- src/util/format/u_format_pack.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 6f91dd9d3ce..3cf28e44e64 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -229,7 +229,7 @@ "description": "u_format: Use memcpy to avoid unaligned accesses", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "45ae4434b5bd779e74d12e5b63fcf91d88f4cb28" }, diff --git a/src/util/format/u_format_pack.py b/src/util/format/u_format_pack.py index 2a8610548fa..b68669f464b 100644 --- a/src/util/format/u_format_pack.py +++ b/src/util/format/u_format_pack.py @@ -441,7 +441,8 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type): def unpack_from_bitmask(channels, swizzles): depth = format.block_size() - print(' uint%u_t value = *(const uint%u_t *)src;' % (depth, depth)) + print(' uint%u_t value;' % (depth)) + print(' memcpy(&value, src, sizeof value);') # Compute the intermediate unshifted values for i in range(format.nr_channels()): @@ -567,7 +568,7 @@ def generate_pack_kernel(format, src_channel, src_native_type): if value is not None: print(' value |= %s;' % (value)) - print(' *(uint%u_t *)dst = value;' % depth) + print(' memcpy(dst, &value, sizeof value);') def pack_into_struct(channels, swizzles): inv_swizzle = inv_swizzles(swizzles)