From 2595940b0def52f1eb9d3e8aadb88e3e363afe5c Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Fri, 24 Apr 2026 12:15:34 -0400 Subject: [PATCH] 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: 585c25be1e1 ("radv: fix color conversions for normalized uint/sint formats") Reviewed-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/radv_formats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/amd/vulkan/radv_formats.c b/src/amd/vulkan/radv_formats.c index a41c4c8a621..8a07a4c7c9b 100644 --- a/src/amd/vulkan/radv_formats.c +++ b/src/amd/vulkan/radv_formats.c @@ -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) {