From ab39d204547aa051f811ade9b89ea8df9ce97ca7 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 (cherry picked from commit 2595940b0def52f1eb9d3e8aadb88e3e363afe5c) Part-of: --- .pick_status.json | 2 +- src/amd/vulkan/radv_formats.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 50e697be3e3..2809b5641e1 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1114,7 +1114,7 @@ "description": "radv: fix UB in radv_format_pack_clear_color for snorm formats", "nominated": false, "nomination_type": 2, - "resolution": 4, + "resolution": 1, "main_sha": null, "because_sha": "585c25be1e1a96568829542f2765e97c63d79939", "notes": null diff --git a/src/amd/vulkan/radv_formats.c b/src/amd/vulkan/radv_formats.c index 2b37f79336f..90d31608298 100644 --- a/src/amd/vulkan/radv_formats.c +++ b/src/amd/vulkan/radv_formats.c @@ -592,7 +592,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) {