radv: fix UB in radv_format_pack_clear_color for snorm formats

Casting a negative float to uint64_t is undefined behavior. GCC 15 with
-O2 produces 0xFFFFFFFFFFFFFFFF for (uint64_t)(-32767.5f), causing snorm
clear values to be packed incorrectly (e.g. 0xFFFF instead of 0x8001 for
snorm16 -1.0). This results in wrong DCC comp-to-single clear colors and
~966 CTS snorm multisample_resolve test failures.

Fix by casting through int64_t first, which is well-defined (truncation
toward zero) and preserves the two's complement bit pattern.

Fixes: 585c25be1e ("radv: fix color conversions for normalized uint/sint formats")
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41164>
This commit is contained in:
Matt Turner 2026-04-24 12:15:34 -04:00 committed by Marge Bot
parent 12f43d048e
commit 2595940b0d

View file

@ -615,7 +615,7 @@ radv_format_pack_clear_color(VkFormat format, uint32_t clear_vals[2], VkClearCol
else
f -= 0.5f;
v = (uint64_t)f;
v = (uint64_t)(int64_t)f;
}
} else if (channel->type == UTIL_FORMAT_TYPE_FLOAT) {
if (channel->size == 32) {