From 28ca4a48d60f498fe0c86f0315efeb2a4c90b17c Mon Sep 17 00:00:00 2001 From: Mario Kleiner Date: Sat, 8 Nov 2025 04:32:24 +0000 Subject: [PATCH] wsi/wayland: Zero min_luminance, max_luminance HDR light levels are valid. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CTA-861-G section 6.9.1 Static Metadata Type 1 declares that zero values for different groups of HDR Metadata properties are allowed, including zero nits values for max display mastering luminance, max content light level, max frame-average light level and min display mastering luminance. A zero value is meant to be treated by the video sink as "undefined" / "unknown", and handled accordingly. This is common for dynamically generated visual content. The is_hdr_metadata_legal() function in the Vulkan/WSI/Wayland HDR backend currently declares HDR light level metadata as invalid if the mastering display min_luminance and max_luminance light levels are set to the legal level of zero nits. This causes valid HDR metadata as set by the client via vkSetHdrMetadata() to be not sent to the compositor. Fix this by skipping checks that don't apply if min_luminance or max_luminance are zero. If max_luminance is zero then we skip sending of mastering display min/max luminance to Wayland, as sending a a max_luminance <= min_luminance would trigger a protocol error. All other valid data is still send, ie. color primaries, white-point, content light levels. Fixes: cb7726bb2cf ("vulkan/wsi: validate HDR metadata to not cause protocol errors") Signed-off-by: Mario Kleiner Co-authored-by: Michel Dänzer Reviewed-by: Xaver Hugl (cherry picked from commit 490f05f82ced94d0a2893946aad96083447cac38) Part-of: --- .pick_status.json | 2 +- src/vulkan/wsi/wsi_common_wayland.c | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 78fa2dfc86d..2516800c491 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -34,7 +34,7 @@ "description": "wsi/wayland: Zero min_luminance, max_luminance HDR light levels are valid.", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "cb7726bb2cf7e25661c1401dbef2a6a597748ecd", "notes": null diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index ae9aa257bf6..cf3749be6d4 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -1192,18 +1192,26 @@ is_hdr_metadata_legal(struct wayland_hdr_metadata *l) if (l->max_cll != 0) { if (l->max_cll * MIN_LUM_FACTOR < l->min_luminance) return false; - if (l->max_cll > l->max_luminance) + if (l->max_luminance != 0 && l->max_cll > l->max_luminance) return false; } if (l->max_fall != 0) { if (l->max_fall * MIN_LUM_FACTOR < l->min_luminance) return false; - if (l->max_fall > l->max_luminance) + if (l->max_luminance != 0 && l->max_fall > l->max_luminance) return false; if (l->max_cll != 0 && l->max_fall > l->max_cll) { return false; } } + + /* Be lenient here for a zero (=undefined) max_luminance and handle + * this in the calling code instead, by not sending min/max mastering + * luminance data to Wayland, thereby avoiding protocol errors. + */ + if (l->max_luminance == 0) + return true; + return l->max_luminance * MIN_LUM_FACTOR > l->min_luminance; } @@ -1321,9 +1329,15 @@ wsi_wl_swapchain_update_colorspace(struct wsi_wl_swapchain *chain) green_x, green_y, blue_x, blue_y, white_x, white_y); - wp_image_description_creator_params_v1_set_mastering_luminance(creator, - wayland_hdr_metadata.min_luminance, - wayland_hdr_metadata.max_luminance); + + /* A max_luminance of 0 is legal by spec and means "undefined", but would cause a + * Wayland protocol error, so skip setting mastering luminance for zero value. + */ + if (wayland_hdr_metadata.max_luminance != 0) { + wp_image_description_creator_params_v1_set_mastering_luminance(creator, + wayland_hdr_metadata.min_luminance, + wayland_hdr_metadata.max_luminance); + } } }