From af53a9bfbc90c82a64739e83d56a4bf1de0cf171 Mon Sep 17 00:00:00 2001 From: Mario Kleiner Date: Sun, 29 Mar 2026 19:21:15 +0200 Subject: [PATCH] dri: Fix "cosmetic" undefined behaviour warning for RGB[A]16_UNORM formats. Ian Romanick reported some "undefined behaviour" warnings during some not specified tests, relating to introduction of RGB[A}16_UNORM formats in merge request https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38588 This due to overflowing the 32-bits masks[], and then during assignment the red/green/blue/alphaMask fields in struct gl_config when using a 16 bpc format. Iow. the red/green/blue/alphaMask would not be usable. Suppress this warning by setting masks[] to zero for unorm16 formats, just as was previously done for is_float16, ie. fp16 formats. 16 bpc formats are only exposed for display on non-X11 WSI target platforms like GBM+DRM, Wayland, surfaceless, and these platforms do not use the info in red/green/blue/alphaMask at all, so the "undefined behaviour" is meaningless. Fixes: f2aaa9ce00ff ("dri,gallium: Add support for RGB[A]16_UNORM display formats.") Reported-by: Ian Romanick @idr Signed-off-by: Mario Kleiner Reviewed-by: Adam Jackson (cherry picked from commit ab94515b0a8d399f9702b7aec1b41aafbdea5edb) Part-of: --- .pick_status.json | 2 +- src/gallium/frontends/dri/dri_screen.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 76933470dcd..12934eeeb55 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -74,7 +74,7 @@ "description": "dri: Fix \"cosmetic\" undefined behaviour warning for RGB[A]16_UNORM formats.", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "f2aaa9ce00ffe7310bddcd5e884f34afb741f460", "notes": null diff --git a/src/gallium/frontends/dri/dri_screen.c b/src/gallium/frontends/dri/dri_screen.c index 1bf46cd31e5..972d210db5d 100644 --- a/src/gallium/frontends/dri/dri_screen.c +++ b/src/gallium/frontends/dri/dri_screen.c @@ -153,9 +153,11 @@ driCreateConfigs(enum pipe_format format, unsigned num_accum_bits = (enable_accum) ? 2 : 1; bool is_srgb; bool is_float; + bool is_unorm16; is_srgb = util_format_is_srgb(format); is_float = util_format_is_float(format); + is_unorm16 = util_format_is_unorm16(util_format_description(format)); for (i = 0; i < 4; i++) { color_bits[i] = @@ -168,7 +170,11 @@ driCreateConfigs(enum pipe_format format, shifts[i] = -1; } - if (is_float || color_bits[i] == 0) + /* is_float and is_unorm16 is only true on non-x11 target platforms, which + * don't actually use redMask, greenMask, ..., so avoid setting masks[] + * to prevent a meaningless "undefined behaviour" build warning. + */ + if (is_float || is_unorm16 || color_bits[i] == 0) masks[i] = 0; else masks[i] = ((1u << color_bits[i]) - 1) << shifts[i];