From ea191fc2603b94e9f85fff5028bb19412c709559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Fri, 13 Nov 2026 18:06:11 +0100 Subject: [PATCH 01/20] wayland: set the linear mastering luminance only when supported set_mastering_luminance belongs to the set_mastering_display_primaries feature. --- video/out/wayland_common.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 0d7b13df92c5d..431f5230007a0 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -3782,10 +3782,12 @@ static void set_color_management(struct vo_wayland_state *wl, struct pl_color_sp 0 * WAYLAND_MIN_LUM_FACTOR, hdr.max_luma, PL_COLOR_SDR_WHITE); MP_VERBOSE(wl, "Setting linear luminance range: min=0, max=%.5f, ref=%.2f\n", hdr.max_luma, PL_COLOR_SDR_WHITE); - wp_image_description_creator_params_v1_set_mastering_luminance(image_creator_params, - lrintf(hdr.min_luma * WAYLAND_MIN_LUM_FACTOR), lrintf(hdr.max_luma)); - MP_VERBOSE(wl, "Setting linear luminance mastering range: min=%.5f, max=%.2f\n", - hdr.min_luma, hdr.max_luma); + if (wl->supports_display_primaries) { + wp_image_description_creator_params_v1_set_mastering_luminance(image_creator_params, + lrintf(hdr.min_luma * WAYLAND_MIN_LUM_FACTOR), lrintf(hdr.max_luma)); + MP_VERBOSE(wl, "Setting linear luminance mastering range: min=%.5f, max=%.2f\n", + hdr.min_luma, hdr.max_luma); + } } break; case PL_COLOR_TRC_HLG: From d53179e45d5aeab32c1016f24ba073c8b320a736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Fri, 13 Nov 2026 18:07:55 +0100 Subject: [PATCH 02/20] wayland: don't set an unknown max_cll or max_fall Both are optional and stay undefined unless they are set. A 0 is a set value, and version 1 of the protocol requires a set value to be above the minimum of the mastering luminance range. --- video/out/wayland_common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 431f5230007a0..0a5563285e69d 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -3830,8 +3830,10 @@ static void set_color_management(struct vo_wayland_state *wl, struct pl_color_sp lrintf(hdr.min_luma * WAYLAND_MIN_LUM_FACTOR), lrintf(hdr.max_luma)); } MP_VERBOSE(wl, "max_cll: %f, max_fall: %f\n", hdr.max_cll, hdr.max_fall); - wp_image_description_creator_params_v1_set_max_cll(image_creator_params, lrintf(hdr.max_cll)); - wp_image_description_creator_params_v1_set_max_fall(image_creator_params, lrintf(hdr.max_fall)); + if (hdr.max_cll) + wp_image_description_creator_params_v1_set_max_cll(image_creator_params, lrintf(hdr.max_cll)); + if (hdr.max_fall) + wp_image_description_creator_params_v1_set_max_fall(image_creator_params, lrintf(hdr.max_fall)); } image_description = wp_image_description_creator_params_v1_create(image_creator_params); cm_dispatch_color_queue(wl, image_description); From 5bacd8a2e15a99aaa932cfe6a89b3d2ab42176da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Fri, 13 Nov 2026 18:39:46 +0100 Subject: [PATCH 03/20] wayland: round the luminances of the image description So it matches mastering luminance which is also rounded. --- video/out/wayland_common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 0a5563285e69d..dc0f187baaced 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -3779,7 +3779,7 @@ static void set_color_management(struct vo_wayland_state *wl, struct pl_color_sp // black, similar to PQ transfer. Configure it in the same way as PQ. if (use_metadata) { wp_image_description_creator_params_v1_set_luminances(image_creator_params, - 0 * WAYLAND_MIN_LUM_FACTOR, hdr.max_luma, PL_COLOR_SDR_WHITE); + 0 * WAYLAND_MIN_LUM_FACTOR, lrintf(hdr.max_luma), PL_COLOR_SDR_WHITE); MP_VERBOSE(wl, "Setting linear luminance range: min=0, max=%.5f, ref=%.2f\n", hdr.max_luma, PL_COLOR_SDR_WHITE); if (wl->supports_display_primaries) { @@ -3797,7 +3797,8 @@ static void set_color_management(struct vo_wayland_state *wl, struct pl_color_sp // Set SDR luminance range for all relative transfers if (use_metadata) { wp_image_description_creator_params_v1_set_luminances(image_creator_params, - hdr.min_luma * WAYLAND_MIN_LUM_FACTOR, hdr.max_luma, PL_COLOR_SDR_WHITE); + lrintf(hdr.min_luma * WAYLAND_MIN_LUM_FACTOR), lrintf(hdr.max_luma), + PL_COLOR_SDR_WHITE); MP_VERBOSE(wl, "Setting relative luminance range: min=%.5f, max=%.2f, ref=%.2f\n", hdr.min_luma, hdr.max_luma, PL_COLOR_SDR_WHITE); } From 69e721ea2b3313d4fe5920c80b044553aaac63dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Fri, 13 Nov 2026 18:33:50 +0100 Subject: [PATCH 04/20] wayland: redraw when the preferred image description changes --- video/out/wayland_common.c | 1 + 1 file changed, 1 insertion(+) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index dc0f187baaced..01255d667c030 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -2296,6 +2296,7 @@ static void info_done(void *data, struct wp_image_description_info_v1 *image_des wd->csp.hdr.max_fall = MPMIN(wd->csp.hdr.max_fall, wd->csp.hdr.max_luma); } wl->preferred_csp = wd->csp; + wl->pending_vo_events |= VO_EVENT_EXPOSE; talloc_free(wd); } From 0eff511495fd311ebe29e5e7739e3fa19dd11b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Fri, 13 Nov 2026 18:09:57 +0100 Subject: [PATCH 05/20] opengl/context: implement target_ref_luma --- video/out/opengl/context.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/video/out/opengl/context.c b/video/out/opengl/context.c index 9b8cabfe8c1af..e5798a60b0d88 100644 --- a/video/out/opengl/context.c +++ b/video/out/opengl/context.c @@ -331,10 +331,19 @@ static pl_color_space_t ra_gl_ctx_target_csp(struct ra_swapchain *sw) return (pl_color_space_t){0}; } +static float ra_gl_ctx_target_ref_luma(struct ra_swapchain *sw) +{ + struct priv *p = sw->priv; + if (p->params.preferred_ref_luma) + return p->params.preferred_ref_luma(sw->ctx); + return 0; +} + static const struct ra_swapchain_fns ra_gl_swapchain_fns = { .color_depth = ra_gl_ctx_color_depth, .set_color = ra_gl_ctx_set_color, .target_csp = ra_gl_ctx_target_csp, + .target_ref_luma = ra_gl_ctx_target_ref_luma, .start_frame = ra_gl_ctx_start_frame, .submit_frame = ra_gl_ctx_submit_frame, .swap_buffers = ra_gl_ctx_swap_buffers, From 93fa1e75fe02b8fd0a8a686a9d586c24a720f3e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Fri, 13 Nov 2026 21:30:48 +0100 Subject: [PATCH 06/20] vo_gpu_next: limit the SDR contrast relative to the reference white Use effective reference white, instead of hardcoded one. --- video/out/gpu_next/video.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/video/out/gpu_next/video.c b/video/out/gpu_next/video.c index 1f07c0e5d4e45..0e99a0a78533f 100644 --- a/video/out/gpu_next/video.c +++ b/video/out/gpu_next/video.c @@ -1410,7 +1410,9 @@ static struct pl_color_space get_target_csp(struct mppl_video *p, bool *unknown, target_csp.primaries = mp_get_best_prim_container(&target_csp.hdr.prim); if (!pl_color_transfer_is_hdr(target_csp.transfer)) { // limit min_luma to 1000:1 contrast ratio in SDR mode - if (target_csp.hdr.min_luma > PL_COLOR_SDR_WHITE / PL_COLOR_SDR_CONTRAST) + float ref = get_ref_luma(p); + float white = ref ? ref : PL_COLOR_SDR_WHITE; + if (target_csp.hdr.min_luma > white / PL_COLOR_SDR_CONTRAST) target_csp.hdr.min_luma = 0; } // maxFALL in display metadata is in fact MaxFullFrameLuminance. Wayland From a66e5a6d11fd93b576ff6322ffdafebd6fa3c2a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 14 Nov 2026 11:00:30 +0100 Subject: [PATCH 07/20] vo/gpu/context: add target parameter to set_color It tells if the params are made for the target device or are those of the source. The distinction is unfortunatelly needed, becasue Wayland has HDR10 reference white scaling, which we have to undo. --- video/out/gpu/context.h | 6 ++++-- video/out/gpu_next/video.c | 5 +++++ video/out/gpu_next/video.h | 1 + video/out/opengl/context.c | 5 +++-- video/out/opengl/context_drm_egl.c | 2 +- video/out/opengl/context_wayland.c | 2 +- video/out/vo_gpu_next.c | 3 ++- video/out/vulkan/context.c | 4 ++-- video/out/vulkan/context_wayland.c | 2 +- 9 files changed, 20 insertions(+), 10 deletions(-) diff --git a/video/out/gpu/context.h b/video/out/gpu/context.h index 68a3621c0fc74..51ea97a9e5b18 100644 --- a/video/out/gpu/context.h +++ b/video/out/gpu/context.h @@ -81,7 +81,7 @@ struct ra_ctx_params { float (*preferred_ref_luma)(struct ra_ctx *ctx); // See ra_swapchain_fns.set_color. Optional. - bool (*set_color)(struct ra_ctx *ctx, struct mp_image_params *params); + bool (*set_color)(struct ra_ctx *ctx, struct mp_image_params *params, bool target); // See ra_swapchain_fns.get_vsync. void (*get_vsync)(struct ra_ctx *ctx, struct vo_vsync_info *info); @@ -124,7 +124,9 @@ struct ra_swapchain_fns { // Call into backends so they can use the appropriate platform-specific // functions to configure color spaces. Returns true if request was handled. - bool (*set_color)(struct ra_swapchain *sw, struct mp_image_params *params); + // target is set if params are made for the target device, and unset if + // they are those of the source. + bool (*set_color)(struct ra_swapchain *sw, struct mp_image_params *params, bool target); // Called when rendering starts. Returns NULL on failure. This must be // followed by submit_frame, to submit the rendered frame. This function diff --git a/video/out/gpu_next/video.c b/video/out/gpu_next/video.c index 0e99a0a78533f..5b4fbf7f8cf9b 100644 --- a/video/out/gpu_next/video.c +++ b/video/out/gpu_next/video.c @@ -1257,6 +1257,11 @@ enum pl_color_levels mppl_video_get_output_levels(struct mppl_video *p) return p->output_levels ? p->output_levels : PL_COLOR_LEVELS_FULL; } +bool mppl_video_hint_is_target(struct mppl_video *p) +{ + return p->next_opts->target_hint_mode == 0; +} + static void update_tm_viz(struct pl_color_map_params *params, const struct pl_frame *target) { diff --git a/video/out/gpu_next/video.h b/video/out/gpu_next/video.h index 2dd9b4135ae6a..f385d52cfae90 100644 --- a/video/out/gpu_next/video.h +++ b/video/out/gpu_next/video.h @@ -76,6 +76,7 @@ bool mppl_video_render_frame(struct mppl_video *p, struct vo_frame *frame, struct mp_image_params *target_params); bool mppl_video_get_hdr_metadata(struct mppl_video *p, struct pl_hdr_metadata *out); enum pl_color_levels mppl_video_get_output_levels(struct mppl_video *p); +bool mppl_video_hint_is_target(struct mppl_video *p); void mppl_video_set_paused(struct mppl_video *p, bool paused); bool mppl_video_showing_interpolated_frame(struct mppl_video *p); void mppl_video_reset(struct mppl_video *p); diff --git a/video/out/opengl/context.c b/video/out/opengl/context.c index e5798a60b0d88..cb22283615b27 100644 --- a/video/out/opengl/context.c +++ b/video/out/opengl/context.c @@ -315,11 +315,12 @@ static void ra_gl_ctx_get_vsync(struct ra_swapchain *sw, p->params.get_vsync(sw->ctx, info); } -static bool ra_gl_ctx_set_color(struct ra_swapchain *sw, struct mp_image_params *params) +static bool ra_gl_ctx_set_color(struct ra_swapchain *sw, struct mp_image_params *params, + bool target) { struct priv *p = sw->priv; if (p->params.set_color) - return p->params.set_color(sw->ctx, params); + return p->params.set_color(sw->ctx, params, target); return false; } diff --git a/video/out/opengl/context_drm_egl.c b/video/out/opengl/context_drm_egl.c index f1b8b830b3a7e..48e1f745e86b5 100644 --- a/video/out/opengl/context_drm_egl.c +++ b/video/out/opengl/context_drm_egl.c @@ -567,7 +567,7 @@ static pl_color_space_t drm_egl_preferred_csp(struct ra_ctx *ctx) return pl_color_space_srgb; } -static bool drm_egl_set_color(struct ra_ctx *ctx, struct mp_image_params *params) +static bool drm_egl_set_color(struct ra_ctx *ctx, struct mp_image_params *params, bool target) { struct pl_color_space sdr = pl_color_space_srgb; vo_drm_set_color(ctx->vo, params ? ¶ms->color : &sdr); diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c index c8189ff36b751..ed2b04a891fa5 100644 --- a/video/out/opengl/context_wayland.c +++ b/video/out/opengl/context_wayland.c @@ -67,7 +67,7 @@ static pl_color_space_t wayland_egl_preferred_csp(struct ra_ctx *ctx) return vo_wayland_preferred_csp(ctx->vo); } -static bool wayland_egl_set_color(struct ra_ctx *ctx, struct mp_image_params *params) +static bool wayland_egl_set_color(struct ra_ctx *ctx, struct mp_image_params *params, bool target) { vo_wayland_handle_color(ctx->vo->wl, params); return true; diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c index adff8aac74da1..9e6514f414838 100644 --- a/video/out/vo_gpu_next.c +++ b/video/out/vo_gpu_next.c @@ -55,7 +55,8 @@ static bool set_colorspace_hint(struct priv *p, struct pl_color_space *hint) }, }; - if (sw->fns->set_color && sw->fns->set_color(sw, hint ? ¶ms : NULL)) { + bool target = mppl_video_hint_is_target(p->renderer); + if (sw->fns->set_color && sw->fns->set_color(sw, hint ? ¶ms : NULL, target)) { if (hint) { *hint = params.color; return true; diff --git a/video/out/vulkan/context.c b/video/out/vulkan/context.c index 892396f7d613f..ae23eac1492d0 100644 --- a/video/out/vulkan/context.c +++ b/video/out/vulkan/context.c @@ -627,7 +627,7 @@ static void get_vsync(struct ra_swapchain *sw, p->params.get_vsync(sw->ctx, info); } -static bool set_color(struct ra_swapchain *sw, struct mp_image_params *params) +static bool set_color(struct ra_swapchain *sw, struct mp_image_params *params, bool target) { struct priv *p = sw->priv; @@ -642,7 +642,7 @@ static bool set_color(struct ra_swapchain *sw, struct mp_image_params *params) pl_swapchain_colorspace_hint(p->vk->swapchain, &(struct pl_color_space){0}); } - bool ret = p->params.set_color(sw->ctx, params); + bool ret = p->params.set_color(sw->ctx, params, target); // To avoid ping-pong between VK_COLOR_SPACE_PASS_THROUGH_EXT and others, // we assume that internal Wayland set_color always work, and update // params to fallback values if needed. diff --git a/video/out/vulkan/context_wayland.c b/video/out/vulkan/context_wayland.c index 65b2263c12880..51212ad9cda97 100644 --- a/video/out/vulkan/context_wayland.c +++ b/video/out/vulkan/context_wayland.c @@ -41,7 +41,7 @@ static bool wayland_vk_check_visible(struct ra_ctx *ctx) return vo_wayland_check_visible(ctx->vo); } -static bool wayland_vk_set_color(struct ra_ctx *ctx, struct mp_image_params *params) +static bool wayland_vk_set_color(struct ra_ctx *ctx, struct mp_image_params *params, bool target) { vo_wayland_handle_color(ctx->vo->wl, params); return true; From 29c8629c178924b26085295734e323afffca5a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 28 Nov 2026 00:37:49 +0100 Subject: [PATCH 08/20] wayland: add target parameter to vo_wayland_handle_color It tells if the params are made for the output or are those of the source, as for set_color. vo_dmabuf_wayland and vo_wlshm pass the params of the source through. --- video/out/opengl/context_wayland.c | 2 +- video/out/vo_dmabuf_wayland.c | 2 +- video/out/vo_wlshm.c | 2 +- video/out/vulkan/context_wayland.c | 2 +- video/out/wayland_common.c | 3 ++- video/out/wayland_common.h | 3 ++- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c index ed2b04a891fa5..f4cf1ed6a8a7f 100644 --- a/video/out/opengl/context_wayland.c +++ b/video/out/opengl/context_wayland.c @@ -69,7 +69,7 @@ static pl_color_space_t wayland_egl_preferred_csp(struct ra_ctx *ctx) static bool wayland_egl_set_color(struct ra_ctx *ctx, struct mp_image_params *params, bool target) { - vo_wayland_handle_color(ctx->vo->wl, params); + vo_wayland_handle_color(ctx->vo->wl, params, target); return true; } diff --git a/video/out/vo_dmabuf_wayland.c b/video/out/vo_dmabuf_wayland.c index ed82fe5ce46ee..0175ed279b88a 100644 --- a/video/out/vo_dmabuf_wayland.c +++ b/video/out/vo_dmabuf_wayland.c @@ -650,7 +650,7 @@ static bool draw_frame(struct vo *vo, struct vo_frame *frame) pts = frame->current ? frame->current->pts : 0; if (frame->current) { buf = buffer_get(vo, frame); - vo_wayland_handle_color(wl, &p->target_params); + vo_wayland_handle_color(wl, &p->target_params, false); if (buf && buf->frame) { struct mp_image *image = buf->frame->current; diff --git a/video/out/vo_wlshm.c b/video/out/vo_wlshm.c index 0ff3cba6c8064..9e18077594d89 100644 --- a/video/out/vo_wlshm.c +++ b/video/out/vo_wlshm.c @@ -259,7 +259,7 @@ static bool draw_frame(struct vo *vo, struct vo_frame *frame) } } if (src) { - vo_wayland_handle_color(wl, &p->sws->dst); + vo_wayland_handle_color(wl, &p->sws->dst, false); struct mp_image dst = buf->mpi; struct mp_rect src_rc; struct mp_rect dst_rc; diff --git a/video/out/vulkan/context_wayland.c b/video/out/vulkan/context_wayland.c index 51212ad9cda97..31b5c366b5245 100644 --- a/video/out/vulkan/context_wayland.c +++ b/video/out/vulkan/context_wayland.c @@ -43,7 +43,7 @@ static bool wayland_vk_check_visible(struct ra_ctx *ctx) static bool wayland_vk_set_color(struct ra_ctx *ctx, struct mp_image_params *params, bool target) { - vo_wayland_handle_color(ctx->vo->wl, params); + vo_wayland_handle_color(ctx->vo->wl, params, target); return true; } diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 01255d667c030..5c76523af1084 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -4501,7 +4501,8 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg) return VO_NOTIMPL; } -void vo_wayland_handle_color(struct vo_wayland_state *wl, struct mp_image_params *params) +void vo_wayland_handle_color(struct vo_wayland_state *wl, struct mp_image_params *params, + bool target) { #if HAVE_WAYLAND_PROTOCOLS_1_41 if (!params) { diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h index a61e550b90e94..3b6cba1942b0a 100644 --- a/video/out/wayland_common.h +++ b/video/out/wayland_common.h @@ -236,7 +236,8 @@ bool vo_wayland_reconfig(struct vo *vo); int vo_wayland_allocate_memfd(struct vo *vo, size_t size); int vo_wayland_control(struct vo *vo, int *events, int request, void *arg); -void vo_wayland_handle_color(struct vo_wayland_state *wl, struct mp_image_params *params); +void vo_wayland_handle_color(struct vo_wayland_state *wl, struct mp_image_params *params, + bool target); void vo_wayland_handle_scale(struct vo_wayland_state *wl); void vo_wayland_set_opaque_region(struct vo_wayland_state *wl, bool alpha); void vo_wayland_sync_swap(struct vo_wayland_state *wl); From 85b451290e9d764de117184bb4602cee17a4a2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 28 Nov 2026 00:38:10 +0100 Subject: [PATCH 09/20] wayland: factor out the scaling of the preferred luminances So that it can be made optional. --- video/out/wayland_common.c | 63 ++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 5c76523af1084..9dd27961b4871 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -2234,6 +2234,39 @@ static const struct wp_image_description_v1_listener image_description_listener #endif }; +static void scale_to_sdr_white(struct vo_wayland_preferred_description_info *wd) +{ + // Wayland luminances are always in reference to the reference luminance. That is, + // if max_luma == 2*ref_luma, then there is 2x headroom above paper white. On the + // other hand, libplacebo hardcodes PL_COLOR_SDR_WHITE as the reference luminance. + // We must scale all wayland values to correspond to the libplacebo scale, + // otherwise libplacebo will assume that there is too little or too much headroom + // when ref_luma != PL_COLOR_SDR_WHITE. + float a = wd->min_luma; + // Wayland treats all transfers as display referred, don't scale min + // luminance, and hope compositors will do the right thing mapping it, + // or to be specific, not mapping it, because we set the same value. + float c = wd->min_luma; + float b = (PL_COLOR_SDR_WHITE - c) / (wd->ref_luma - a); + wd->csp.hdr.min_luma = (wd->csp.hdr.min_luma - a) * b + c; + wd->csp.hdr.max_luma = (wd->csp.hdr.max_luma - a) * b + c; + if (wd->csp.hdr.max_cll != 0) + wd->csp.hdr.max_cll = (wd->csp.hdr.max_cll - a) * b + c; + if (wd->csp.hdr.max_fall != 0) + wd->csp.hdr.max_fall = (wd->csp.hdr.max_fall - a) * b + c; + // Ensure that min_luma doesn't become negative. + wd->csp.hdr.min_luma = MPMAX(wd->csp.hdr.min_luma, 0.0); + // Since we want to do some exact comparisons of max_luma with PL_COLOR_SDR_WHITE, + // we need to round it. + if (fabsf(wd->csp.hdr.max_luma - PL_COLOR_SDR_WHITE) < 1e-2f) { + wd->csp.hdr.max_luma = PL_COLOR_SDR_WHITE; + if (wd->csp.hdr.max_cll != 0) + wd->csp.hdr.max_cll = MPMIN(wd->csp.hdr.max_cll, wd->csp.hdr.max_luma); + if (wd->csp.hdr.max_fall != 0) + wd->csp.hdr.max_fall = MPMIN(wd->csp.hdr.max_fall, wd->csp.hdr.max_luma); + } +} + static void info_done(void *data, struct wp_image_description_info_v1 *image_description_info) { struct vo_wayland_preferred_description_info *wd = data; @@ -2266,35 +2299,7 @@ static void info_done(void *data, struct wp_image_description_info_v1 *image_des MP_VERBOSE(wl, "Setting preferred transfer to PQ for HDR output.\n"); wd->csp.transfer = PL_COLOR_TRC_PQ; } - // Wayland luminances are always in reference to the reference luminance. That is, - // if max_luma == 2*ref_luma, then there is 2x headroom above paper white. On the - // other hand, libplacebo hardcodes PL_COLOR_SDR_WHITE as the reference luminance. - // We must scale all wayland values to correspond to the libplacebo scale, - // otherwise libplacebo will assume that there is too little or too much headroom - // when ref_luma != PL_COLOR_SDR_WHITE. - float a = wd->min_luma; - // Wayland treats all transfers as display referred, don't scale min - // luminance, and hope compositors will do the right thing mapping it, - // or to be specific, not mapping it, because we set the same value. - float c = wd->min_luma; - float b = (PL_COLOR_SDR_WHITE - c) / (wd->ref_luma - a); - wd->csp.hdr.min_luma = (wd->csp.hdr.min_luma - a) * b + c; - wd->csp.hdr.max_luma = (wd->csp.hdr.max_luma - a) * b + c; - if (wd->csp.hdr.max_cll != 0) - wd->csp.hdr.max_cll = (wd->csp.hdr.max_cll - a) * b + c; - if (wd->csp.hdr.max_fall != 0) - wd->csp.hdr.max_fall = (wd->csp.hdr.max_fall - a) * b + c; - // Ensure that min_luma doesn't become negative. - wd->csp.hdr.min_luma = MPMAX(wd->csp.hdr.min_luma, 0.0); - // Since we want to do some exact comparisons of max_luma with PL_COLOR_SDR_WHITE, - // we need to round it. - if (fabsf(wd->csp.hdr.max_luma - PL_COLOR_SDR_WHITE) < 1e-2f) { - wd->csp.hdr.max_luma = PL_COLOR_SDR_WHITE; - if (wd->csp.hdr.max_cll != 0) - wd->csp.hdr.max_cll = MPMIN(wd->csp.hdr.max_cll, wd->csp.hdr.max_luma); - if (wd->csp.hdr.max_fall != 0) - wd->csp.hdr.max_fall = MPMIN(wd->csp.hdr.max_fall, wd->csp.hdr.max_luma); - } + scale_to_sdr_white(wd); wl->preferred_csp = wd->csp; wl->pending_vo_events |= VO_EVENT_EXPOSE; talloc_free(wd); From 6559b323f03647b7fdac804a855d6ef75c8b4350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 28 Nov 2026 00:38:49 +0100 Subject: [PATCH 10/20] wayland: don't declare a reference white above the peak of an SDR signal An SDR or linear signal was declared with 203 nits as its reference white, also where it peaks below that, as with --target-peak=100. By the protocol a reference white above the maximum needs the extended_target_volume feature, and Mutter raises a protocol error for it. The white of such a signal is at its peak. --- video/out/wayland_common.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 9dd27961b4871..7162871c42577 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -3728,7 +3728,17 @@ static void seat_create_text_input(struct vo_wayland_seat *seat) } #if HAVE_WAYLAND_PROTOCOLS_1_41 -static void set_color_management(struct vo_wayland_state *wl, struct pl_color_space *color) +// The reference white that the image description of a signal declares. +static float image_ref_luma(const struct pl_color_space *color) +{ + if (pl_color_transfer_is_hdr(color->transfer)) + return PL_COLOR_SDR_WHITE; + // The white of an SDR or linear signal is at most its peak. + return MPMIN(PL_COLOR_SDR_WHITE, color->hdr.max_luma); +} + +static void set_color_management(struct vo_wayland_state *wl, struct pl_color_space *color, + float ref_luma) { if (!wl->color_surface || !wl->color_queue || !wl->supports_parametric) goto nosupport; @@ -3775,9 +3785,9 @@ static void set_color_management(struct vo_wayland_state *wl, struct pl_color_sp case PL_COLOR_TRC_PQ: // Set min luminance to 0 for PQ as per SMPTE ST 2084 wp_image_description_creator_params_v1_set_luminances(image_creator_params, - 0 * WAYLAND_MIN_LUM_FACTOR, 10000, PL_COLOR_SDR_WHITE); + 0 * WAYLAND_MIN_LUM_FACTOR, 10000, ref_luma); MP_VERBOSE(wl, "Setting PQ luminance range: min=0, max=10000, ref=%.2f\n", - PL_COLOR_SDR_WHITE); + ref_luma); // Mastering luminances will be set below break; case PL_COLOR_TRC_LINEAR: @@ -3785,9 +3795,9 @@ static void set_color_management(struct vo_wayland_state *wl, struct pl_color_sp // black, similar to PQ transfer. Configure it in the same way as PQ. if (use_metadata) { wp_image_description_creator_params_v1_set_luminances(image_creator_params, - 0 * WAYLAND_MIN_LUM_FACTOR, lrintf(hdr.max_luma), PL_COLOR_SDR_WHITE); + 0 * WAYLAND_MIN_LUM_FACTOR, lrintf(hdr.max_luma), lrintf(ref_luma)); MP_VERBOSE(wl, "Setting linear luminance range: min=0, max=%.5f, ref=%.2f\n", - hdr.max_luma, PL_COLOR_SDR_WHITE); + hdr.max_luma, ref_luma); if (wl->supports_display_primaries) { wp_image_description_creator_params_v1_set_mastering_luminance(image_creator_params, lrintf(hdr.min_luma * WAYLAND_MIN_LUM_FACTOR), lrintf(hdr.max_luma)); @@ -3804,9 +3814,9 @@ static void set_color_management(struct vo_wayland_state *wl, struct pl_color_sp if (use_metadata) { wp_image_description_creator_params_v1_set_luminances(image_creator_params, lrintf(hdr.min_luma * WAYLAND_MIN_LUM_FACTOR), lrintf(hdr.max_luma), - PL_COLOR_SDR_WHITE); + lrintf(ref_luma)); MP_VERBOSE(wl, "Setting relative luminance range: min=%.5f, max=%.2f, ref=%.2f\n", - hdr.min_luma, hdr.max_luma, PL_COLOR_SDR_WHITE); + hdr.min_luma, hdr.max_luma, ref_luma); } break; } @@ -4537,7 +4547,7 @@ void vo_wayland_handle_color(struct vo_wayland_state *wl, struct mp_image_params } wl->last_hint_params = *params; if (color_space_changed) { - set_color_management(wl, ¶ms->color); + set_color_management(wl, ¶ms->color, image_ref_luma(¶ms->color)); } else { params->color = wl->current_params.color; } From 4343ba8a6961fae0835eeea1244b4d0ef576f924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 28 Nov 2026 01:11:01 +0100 Subject: [PATCH 11/20] wayland: add --wayland-respect-pq-scale The luminances of the preferred image description are converted to the scale of 203 nits and the surface declares 203 as its reference white. The compositor then shows all of it brighter or darker by the ratio of its own reference white to 203, which is the model of the protocol and stays the default. With the option the luminances of the output are used as they are, and the surface declares the reference white of the compositor, which shows it as it is. HDR content keeps its luminance. SDR content, the OSD and subtitles are at the reference white of the compositor in both cases. A signal of the source, as with vo_dmabuf_wayland or --target-colorspace-hint-mode=source, stays in the scale of 203 nits. --- .../wayland-respect-pq-scale.txt | 1 + DOCS/man/options.rst | 14 +++++- options/options.c | 1 + options/options.h | 1 + video/out/opengl/context_wayland.c | 6 +++ video/out/vulkan/context_wayland.c | 6 +++ video/out/wayland_common.c | 43 +++++++++++++++---- video/out/wayland_common.h | 3 ++ 8 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 DOCS/interface-changes/wayland-respect-pq-scale.txt diff --git a/DOCS/interface-changes/wayland-respect-pq-scale.txt b/DOCS/interface-changes/wayland-respect-pq-scale.txt new file mode 100644 index 0000000000000..5e96ac8928995 --- /dev/null +++ b/DOCS/interface-changes/wayland-respect-pq-scale.txt @@ -0,0 +1 @@ +add `--wayland-respect-pq-scale` option diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index bc357b5a28813..954f76bb4f90c 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -6622,6 +6622,18 @@ them. frame presentation if it is supported by the compositor (default: ``yes``). This only has an effect if ``--video-sync=display-...`` is being used. +``--wayland-respect-pq-scale=`` + Render to the absolute PQ luminances as mastered (default: ``no``). HDR + video then keeps the luminance it was mastered with, while SDR video, the + OSD and subtitles are drawn at the reference white of the compositor (see + ``--hdr-reference-white``). + + By default all luminances are relative to the reference white of the + compositor. HDR video gets brighter or darker relative to 203 cd/m². + + With ``--target-colorspace-hint-mode=source`` and ``--vo=dmabuf-wayland`` + the compositor scales and tone maps the video in either case. + ``--wayland-session=`` Set the wayland session name for window restoration (default: unset). Not setting this or setting it to the empty string disables session @@ -7709,7 +7721,7 @@ them. (Only for ``--vo=gpu-next``) In ``auto`` mode (default), the reference white luminance is queried from - the system. This is currently only supported on Windows. If the system does + the system. This is supported on Windows and Wayland. If the system does not provide a value, 203 cd/m² is assumed. .. note:: diff --git a/options/options.c b/options/options.c index 89eef562bc0a0..5ce9a37dc768b 100644 --- a/options/options.c +++ b/options/options.c @@ -222,6 +222,7 @@ static const m_option_t mp_vo_opt_list[] = { {"wayland-edge-pixels-touch", OPT_INT(wl_edge_pixels_touch), M_RANGE(0, INT_MAX)}, {"wayland-present", OPT_BOOL(wl_present)}, + {"wayland-respect-pq-scale", OPT_BOOL(wl_respect_pq_scale)}, {"wayland-session", OPT_STRING(wayland_session)}, #endif #if HAVE_WIN32_DESKTOP diff --git a/options/options.h b/options/options.h index 063fef833c85b..24f11f2434394 100644 --- a/options/options.h +++ b/options/options.h @@ -44,6 +44,7 @@ typedef struct mp_vo_opts { int wl_edge_pixels_pointer; int wl_edge_pixels_touch; bool wl_present; + bool wl_respect_pq_scale; float panscan; float zoom; diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c index f4cf1ed6a8a7f..b24b2945a336e 100644 --- a/video/out/opengl/context_wayland.c +++ b/video/out/opengl/context_wayland.c @@ -67,6 +67,11 @@ static pl_color_space_t wayland_egl_preferred_csp(struct ra_ctx *ctx) return vo_wayland_preferred_csp(ctx->vo); } +static float wayland_egl_preferred_ref_luma(struct ra_ctx *ctx) +{ + return vo_wayland_preferred_ref_luma(ctx->vo); +} + static bool wayland_egl_set_color(struct ra_ctx *ctx, struct mp_image_params *params, bool target) { vo_wayland_handle_color(ctx->vo->wl, params, target); @@ -118,6 +123,7 @@ static bool egl_create_context(struct ra_ctx *ctx) struct ra_ctx_params params = { .check_visible = wayland_egl_check_visible, .preferred_csp = wayland_egl_preferred_csp, + .preferred_ref_luma = wayland_egl_preferred_ref_luma, .set_color = wayland_egl_set_color, .swap_buffers = wayland_egl_swap_buffers, .get_vsync = wayland_egl_get_vsync, diff --git a/video/out/vulkan/context_wayland.c b/video/out/vulkan/context_wayland.c index 31b5c366b5245..36f0c6f6f451d 100644 --- a/video/out/vulkan/context_wayland.c +++ b/video/out/vulkan/context_wayland.c @@ -52,6 +52,11 @@ static pl_color_space_t wayland_vk_preferred_csp(struct ra_ctx *ctx) return vo_wayland_preferred_csp(ctx->vo); } +static float wayland_vk_preferred_ref_luma(struct ra_ctx *ctx) +{ + return vo_wayland_preferred_ref_luma(ctx->vo); +} + static void wayland_vk_swap_buffers(struct ra_ctx *ctx) { struct vo_wayland_state *wl = ctx->vo->wl; @@ -102,6 +107,7 @@ static bool wayland_vk_init(struct ra_ctx *ctx) .color_depth = wayland_vk_color_depth, .check_visible = wayland_vk_check_visible, .preferred_csp = wayland_vk_preferred_csp, + .preferred_ref_luma = wayland_vk_preferred_ref_luma, .set_color = wayland_vk_set_color, .swap_buffers = wayland_vk_swap_buffers, .get_vsync = wayland_vk_get_vsync, diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 7162871c42577..b663c09a1a172 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -2299,8 +2299,13 @@ static void info_done(void *data, struct wp_image_description_info_v1 *image_des MP_VERBOSE(wl, "Setting preferred transfer to PQ for HDR output.\n"); wd->csp.transfer = PL_COLOR_TRC_PQ; } - scale_to_sdr_white(wd); + // The luminances are in the scale of PL_COLOR_SDR_WHITE, unless those of + // the output are used as they are, with its reference white. + bool absolute = wl->opts->wl_respect_pq_scale; + if (!absolute) + scale_to_sdr_white(wd); wl->preferred_csp = wd->csp; + wl->preferred_ref_luma = absolute ? wd->ref_luma : 0; wl->pending_vo_events |= VO_EVENT_EXPOSE; talloc_free(wd); } @@ -3729,12 +3734,21 @@ static void seat_create_text_input(struct vo_wayland_seat *seat) #if HAVE_WAYLAND_PROTOCOLS_1_41 // The reference white that the image description of a signal declares. -static float image_ref_luma(const struct pl_color_space *color) -{ +static float image_ref_luma(struct vo_wayland_state *wl, const struct pl_color_space *color, + bool target) +{ + // A signal that is made for an output whose luminances are used as they + // are has the reference white of that output and is shown as it is. Any + // other signal is in the scale of PL_COLOR_SDR_WHITE. + bool output_ref = target && wl->preferred_ref_luma; + float ref_luma = output_ref ? wl->preferred_ref_luma : PL_COLOR_SDR_WHITE; if (pl_color_transfer_is_hdr(color->transfer)) - return PL_COLOR_SDR_WHITE; - // The white of an SDR or linear signal is at most its peak. - return MPMIN(PL_COLOR_SDR_WHITE, color->hdr.max_luma); + return ref_luma; + // The renderer matches an SDR or linear signal at the reference white of + // the output, so that is the peak. In the scale of PL_COLOR_SDR_WHITE the + // white of such a signal is at most its peak. + float white = color->hdr.max_luma; + return output_ref ? white : MPMIN(ref_luma, white); } static void set_color_management(struct vo_wayland_state *wl, struct pl_color_space *color, @@ -3857,7 +3871,10 @@ static void set_color_management(struct vo_wayland_state *wl, struct pl_color_sp return; nosupport: + // Without an image description the surface is taken as sRGB, with its + // peak where a declared signal has its reference white. *color = pl_color_space_srgb; + color->hdr.max_luma = ref_luma; pl_color_space_infer(color); return; } @@ -4323,6 +4340,11 @@ struct pl_color_space vo_wayland_preferred_csp(struct vo *vo) return wl->preferred_csp; } +float vo_wayland_preferred_ref_luma(struct vo *vo) +{ + return vo->wl->preferred_ref_luma; +} + int vo_wayland_control(struct vo *vo, int *events, int request, void *arg) { struct vo_wayland_state *wl = vo->wl; @@ -4372,6 +4394,8 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg) &wl->opts->border); } } + if (opt == &opts->wl_respect_pq_scale) + get_compositor_preferred_description(wl); if (opt == &opts->wl_content_type) set_content_type(wl); if (opt == &opts->cursor_passthrough) @@ -4537,7 +4561,9 @@ void vo_wayland_handle_color(struct vo_wayland_state *wl, struct mp_image_params wl->color_surface = wp_color_manager_v1_get_surface(wl->color_manager, wl->callback_surface); } - bool color_space_changed = !pl_color_space_equal(&wl->last_hint_params.color, ¶ms->color); + float ref_luma = image_ref_luma(wl, ¶ms->color, target); + bool color_space_changed = !pl_color_space_equal(&wl->last_hint_params.color, ¶ms->color) || + wl->last_hint_ref_luma != ref_luma; bool color_repr_changed = !pl_color_repr_equal(&wl->last_hint_params.repr, ¶ms->repr) || wl->last_hint_params.chroma_location != params->chroma_location; @@ -4546,8 +4572,9 @@ void vo_wayland_handle_color(struct vo_wayland_state *wl, struct mp_image_params return; } wl->last_hint_params = *params; + wl->last_hint_ref_luma = ref_luma; if (color_space_changed) { - set_color_management(wl, ¶ms->color, image_ref_luma(¶ms->color)); + set_color_management(wl, ¶ms->color, ref_luma); } else { params->color = wl->current_params.color; } diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h index 3b6cba1942b0a..59b6c3bc03b3f 100644 --- a/video/out/wayland_common.h +++ b/video/out/wayland_common.h @@ -122,6 +122,7 @@ struct vo_wayland_state { struct wp_color_management_surface_feedback_v1 *color_surface_feedback; struct wp_image_description_creator_icc_v1 *icc_creator; struct mp_image_params last_hint_params; + float last_hint_ref_luma; struct mp_image_params current_params; bool supports_parametric; bool supports_display_primaries; @@ -132,6 +133,7 @@ struct vo_wayland_state { void *icc_file; uint32_t icc_size; struct pl_color_space preferred_csp; + float preferred_ref_luma; bool image_description_info_done; bool image_description_pending; @@ -229,6 +231,7 @@ struct vo_wayland_state { bool vo_wayland_check_visible(struct vo *vo); struct pl_color_space vo_wayland_preferred_csp(struct vo *vo); +float vo_wayland_preferred_ref_luma(struct vo *vo); bool vo_wayland_valid_format(struct vo_wayland_state *wl, uint32_t drm_format, uint64_t modifier); bool vo_wayland_init(struct vo *vo); bool vo_wayland_reconfig(struct vo *vo); From 70272f91c74d7fc9a50494d510a8bfc37da52239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Tue, 17 Nov 2026 13:16:20 +0100 Subject: [PATCH 12/20] wayland: declare the luminances of HLG that is made for the output vo_gpu_next encodes HLG for the black and the peak of its target, while an image description without luminances stands for a display of 1000 nits with the reference white at 203. Declare the range of the signal with its reference white, as for PQ. HLG of the source keeps the defaults. --- video/out/wayland_common.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index b663c09a1a172..dbab1051107ba 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -3752,7 +3752,7 @@ static float image_ref_luma(struct vo_wayland_state *wl, const struct pl_color_s } static void set_color_management(struct vo_wayland_state *wl, struct pl_color_space *color, - float ref_luma) + float ref_luma, bool target) { if (!wl->color_surface || !wl->color_queue || !wl->supports_parametric) goto nosupport; @@ -3821,7 +3821,14 @@ static void set_color_management(struct vo_wayland_state *wl, struct pl_color_sp } break; case PL_COLOR_TRC_HLG: - // Leave default for HLG, we wouldn't output it directly, except for pass-through + // HLG that is made for the output is encoded for its black and + // peak. HLG of the source keeps the defaults. + if (target && use_metadata) { + wp_image_description_creator_params_v1_set_luminances(image_creator_params, + lrintf(hdr.min_luma * WAYLAND_MIN_LUM_FACTOR), lrintf(hdr.max_luma), ref_luma); + MP_VERBOSE(wl, "Setting HLG luminance range: min=%.5f, max=%.2f, ref=%.2f\n", + hdr.min_luma, hdr.max_luma, ref_luma); + } break; default: // Set SDR luminance range for all relative transfers @@ -4574,7 +4581,7 @@ void vo_wayland_handle_color(struct vo_wayland_state *wl, struct mp_image_params wl->last_hint_params = *params; wl->last_hint_ref_luma = ref_luma; if (color_space_changed) { - set_color_management(wl, ¶ms->color, ref_luma); + set_color_management(wl, ¶ms->color, ref_luma, target); } else { params->color = wl->current_params.color; } From 490aa7a829c1d904766dcd38a5772cbfbbacd617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 14 Nov 2026 01:47:01 +0100 Subject: [PATCH 13/20] vo_gpu_next: tell an HDR target by its peak as well Two places take the target as HDR by its transfer function. scRGB ends at the reference white on a target that is not HDR, and inverse tone mapping takes the transfer function and the luminances of one that is. A Wayland compositor can prefer an SDR transfer function with a peak above the reference white for an HDR output, KWin does. That was hidden as long as such a transfer function is replaced by PQ. --- video/out/gpu_next/video.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/video/out/gpu_next/video.c b/video/out/gpu_next/video.c index 5b4fbf7f8cf9b..084dd4f9bcdf1 100644 --- a/video/out/gpu_next/video.c +++ b/video/out/gpu_next/video.c @@ -887,7 +887,7 @@ static bool use_ref_luma(const struct pl_color_space *csp, const struct pl_color { if (!pl_color_transfer_is_hdr(csp->transfer)) return true; - if (csp->transfer == PL_COLOR_TRC_SCRGB && target_csp && !pl_color_transfer_is_hdr(target_csp->transfer)) + if (csp->transfer == PL_COLOR_TRC_SCRGB && target_csp && !pl_color_space_is_hdr(target_csp)) return true; return false; } @@ -1499,7 +1499,7 @@ enum mppl_video_hint mppl_video_get_target_hint(struct mppl_video *p, struct vo_ bool min_luma_known = hint.hdr.min_luma > 0; pl_color_space_infer_map(&source_csp, &hint); // Always prefer target luminance and transfer for inverse tone mapping - if (pl_color_transfer_is_hdr(target->transfer) && opts->tone_map.inverse) { + if (pl_color_space_is_hdr(target) && opts->tone_map.inverse) { hint.transfer = target->transfer; hint.hdr.max_luma = target->hdr.max_luma; hint.hdr.min_luma = target->hdr.min_luma; From 3f1aafa1de27b46c567a49cca1042027460d4c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 14 Nov 2026 01:47:02 +0100 Subject: [PATCH 14/20] vo/gpu/context: add sdr_above_ref_luma function --- video/out/gpu/context.h | 8 ++++++++ video/out/opengl/context.c | 7 +++++++ video/out/vulkan/context.c | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/video/out/gpu/context.h b/video/out/gpu/context.h index 51ea97a9e5b18..14f7e2de78f35 100644 --- a/video/out/gpu/context.h +++ b/video/out/gpu/context.h @@ -80,6 +80,9 @@ struct ra_ctx_params { // See ra_swapchain_fns.target_ref_luma. Optional. float (*preferred_ref_luma)(struct ra_ctx *ctx); + // See ra_swapchain_fns.sdr_above_ref_luma. Optional. + bool (*sdr_above_ref_luma)(struct ra_ctx *ctx); + // See ra_swapchain_fns.set_color. Optional. bool (*set_color)(struct ra_ctx *ctx, struct mp_image_params *params, bool target); @@ -122,6 +125,11 @@ struct ra_swapchain_fns { // the system displays diffuse (SDR) white. Returns 0 if unknown. Optional. float (*target_ref_luma)(struct ra_swapchain *sw); + // Whether the system shows an SDR signal set with set_color above the + // reference white. If not, it shows the peak of such a signal as the + // reference white. Optional. + bool (*sdr_above_ref_luma)(struct ra_swapchain *sw); + // Call into backends so they can use the appropriate platform-specific // functions to configure color spaces. Returns true if request was handled. // target is set if params are made for the target device, and unset if diff --git a/video/out/opengl/context.c b/video/out/opengl/context.c index cb22283615b27..59fa80edf74a7 100644 --- a/video/out/opengl/context.c +++ b/video/out/opengl/context.c @@ -340,11 +340,18 @@ static float ra_gl_ctx_target_ref_luma(struct ra_swapchain *sw) return 0; } +static bool ra_gl_ctx_sdr_above_ref_luma(struct ra_swapchain *sw) +{ + struct priv *p = sw->priv; + return p->params.sdr_above_ref_luma && p->params.sdr_above_ref_luma(sw->ctx); +} + static const struct ra_swapchain_fns ra_gl_swapchain_fns = { .color_depth = ra_gl_ctx_color_depth, .set_color = ra_gl_ctx_set_color, .target_csp = ra_gl_ctx_target_csp, .target_ref_luma = ra_gl_ctx_target_ref_luma, + .sdr_above_ref_luma = ra_gl_ctx_sdr_above_ref_luma, .start_frame = ra_gl_ctx_start_frame, .submit_frame = ra_gl_ctx_submit_frame, .swap_buffers = ra_gl_ctx_swap_buffers, diff --git a/video/out/vulkan/context.c b/video/out/vulkan/context.c index ae23eac1492d0..8d1533aa5c536 100644 --- a/video/out/vulkan/context.c +++ b/video/out/vulkan/context.c @@ -670,11 +670,18 @@ static float target_ref_luma(struct ra_swapchain *sw) return 0; } +static bool sdr_above_ref_luma(struct ra_swapchain *sw) +{ + struct priv *p = sw->priv; + return p->params.sdr_above_ref_luma && p->params.sdr_above_ref_luma(sw->ctx); +} + static const struct ra_swapchain_fns vulkan_swapchain = { .color_depth = color_depth, .set_color = set_color, .target_csp = target_csp, .target_ref_luma = target_ref_luma, + .sdr_above_ref_luma = sdr_above_ref_luma, .start_frame = start_frame, .submit_frame = submit_frame, .swap_buffers = swap_buffers, From ca7e8dc45d7adc816a78071fe8d5941021dc55ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 14 Nov 2026 01:47:02 +0100 Subject: [PATCH 15/20] wayland: declare the reference white of an SDR signal that goes higher With --wayland-respect-pq-scale an SDR or linear signal was declared with its reference white at the peak, which is where vo_gpu_next matches. An HDR output also shows such a signal above its reference white. Gamma 2.2 with the white at 400 nits and the peak at 1000 nits is the description that KWin prefers there. Report that through sdr_above_ref_luma and declare the reference white of the output for such a signal, capped at its peak. Note that I don't endorse using Gamma 2.2 transfer for HDR signals, but this is what Wayland forces on us, and undoing it causes more pain that it's worth. --- video/out/opengl/context_wayland.c | 6 ++++++ video/out/vulkan/context_wayland.c | 6 ++++++ video/out/wayland_common.c | 13 ++++++++++--- video/out/wayland_common.h | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c index b24b2945a336e..ac596564ffbc9 100644 --- a/video/out/opengl/context_wayland.c +++ b/video/out/opengl/context_wayland.c @@ -72,6 +72,11 @@ static float wayland_egl_preferred_ref_luma(struct ra_ctx *ctx) return vo_wayland_preferred_ref_luma(ctx->vo); } +static bool wayland_egl_sdr_above_ref_luma(struct ra_ctx *ctx) +{ + return vo_wayland_sdr_above_ref_luma(ctx->vo); +} + static bool wayland_egl_set_color(struct ra_ctx *ctx, struct mp_image_params *params, bool target) { vo_wayland_handle_color(ctx->vo->wl, params, target); @@ -124,6 +129,7 @@ static bool egl_create_context(struct ra_ctx *ctx) .check_visible = wayland_egl_check_visible, .preferred_csp = wayland_egl_preferred_csp, .preferred_ref_luma = wayland_egl_preferred_ref_luma, + .sdr_above_ref_luma = wayland_egl_sdr_above_ref_luma, .set_color = wayland_egl_set_color, .swap_buffers = wayland_egl_swap_buffers, .get_vsync = wayland_egl_get_vsync, diff --git a/video/out/vulkan/context_wayland.c b/video/out/vulkan/context_wayland.c index 36f0c6f6f451d..cc8c1c5c3d7c5 100644 --- a/video/out/vulkan/context_wayland.c +++ b/video/out/vulkan/context_wayland.c @@ -57,6 +57,11 @@ static float wayland_vk_preferred_ref_luma(struct ra_ctx *ctx) return vo_wayland_preferred_ref_luma(ctx->vo); } +static bool wayland_vk_sdr_above_ref_luma(struct ra_ctx *ctx) +{ + return vo_wayland_sdr_above_ref_luma(ctx->vo); +} + static void wayland_vk_swap_buffers(struct ra_ctx *ctx) { struct vo_wayland_state *wl = ctx->vo->wl; @@ -108,6 +113,7 @@ static bool wayland_vk_init(struct ra_ctx *ctx) .check_visible = wayland_vk_check_visible, .preferred_csp = wayland_vk_preferred_csp, .preferred_ref_luma = wayland_vk_preferred_ref_luma, + .sdr_above_ref_luma = wayland_vk_sdr_above_ref_luma, .set_color = wayland_vk_set_color, .swap_buffers = wayland_vk_swap_buffers, .get_vsync = wayland_vk_get_vsync, diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index dbab1051107ba..c4b4c23d1025d 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -3745,10 +3745,11 @@ static float image_ref_luma(struct vo_wayland_state *wl, const struct pl_color_s if (pl_color_transfer_is_hdr(color->transfer)) return ref_luma; // The renderer matches an SDR or linear signal at the reference white of - // the output, so that is the peak. In the scale of PL_COLOR_SDR_WHITE the - // white of such a signal is at most its peak. + // the output, so that is the peak, unless the output shows such a signal + // above its reference white. In the scale of PL_COLOR_SDR_WHITE the white + // of such a signal is at most its peak. float white = color->hdr.max_luma; - return output_ref ? white : MPMIN(ref_luma, white); + return output_ref && !vo_wayland_sdr_above_ref_luma(wl->vo) ? white : MPMIN(ref_luma, white); } static void set_color_management(struct vo_wayland_state *wl, struct pl_color_space *color, @@ -4352,6 +4353,12 @@ float vo_wayland_preferred_ref_luma(struct vo *vo) return vo->wl->preferred_ref_luma; } +bool vo_wayland_sdr_above_ref_luma(struct vo *vo) +{ + struct vo_wayland_state *wl = vo->wl; + return wl->preferred_csp.hdr.max_luma > wl->preferred_ref_luma && wl->supports_set_luminances; +} + int vo_wayland_control(struct vo *vo, int *events, int request, void *arg) { struct vo_wayland_state *wl = vo->wl; diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h index 59b6c3bc03b3f..fe3952733d53d 100644 --- a/video/out/wayland_common.h +++ b/video/out/wayland_common.h @@ -232,6 +232,7 @@ struct vo_wayland_state { bool vo_wayland_check_visible(struct vo *vo); struct pl_color_space vo_wayland_preferred_csp(struct vo *vo); float vo_wayland_preferred_ref_luma(struct vo *vo); +bool vo_wayland_sdr_above_ref_luma(struct vo *vo); bool vo_wayland_valid_format(struct vo_wayland_state *wl, uint32_t drm_format, uint64_t modifier); bool vo_wayland_init(struct vo *vo); bool vo_wayland_reconfig(struct vo *vo); From b0a2da58be5292b6874ea5d1bc47f4a68252ac24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 14 Nov 2026 01:47:02 +0100 Subject: [PATCH 16/20] vo_gpu_next: keep the peak of an SDR target above the reference white The peak of an SDR target is set to the reference white once the system reports one. Windows needs that, it shows the peak of an SDR swapchain at its SDR white level. A Wayland compositor shows an SDR signal with the white where the image description has it, so --target-trc=gamma2.2 on an HDR output can go up to the peak of the output, as it did before the reference white was reported there. --- DOCS/man/options.rst | 3 ++- video/out/gpu_next/libmpv_gpu_next.c | 2 +- video/out/gpu_next/video.c | 22 ++++++++++++++-------- video/out/gpu_next/video.h | 3 ++- video/out/vo_gpu_next.c | 3 ++- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 954f76bb4f90c..203906dc581ea 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -7728,7 +7728,8 @@ them. This option overrides the ``--target-peak`` if is set and the target transfer function is SDR. This way you can control SDR output separately - from HDR output. + from HDR output. A Wayland HDR output keeps a peak above 203 cd/m² for + an SDR transfer function, with SDR content at the reference white. ``--sdr-adjust-gamma=`` SDR transfer functions are often ambiguous or mismatched. Even if files are diff --git a/video/out/gpu_next/libmpv_gpu_next.c b/video/out/gpu_next/libmpv_gpu_next.c index 6914278bd45b6..4ca74449dc636 100644 --- a/video/out/gpu_next/libmpv_gpu_next.c +++ b/video/out/gpu_next/libmpv_gpu_next.c @@ -179,7 +179,7 @@ static int render(struct render_backend *ctx, mpv_render_param *params, }; // There is no display to take a color space from and none to hint one to. - mppl_video_begin_frame(p->renderer, frame, (struct pl_color_space){0}, 0); + mppl_video_begin_frame(p->renderer, frame, (struct pl_color_space){0}, 0, false); struct mp_image_params target_params; mppl_video_render_frame(p->renderer, frame, &target, depth, NULL, &target_params); diff --git a/video/out/gpu_next/video.c b/video/out/gpu_next/video.c index 084dd4f9bcdf1..07f103b61db38 100644 --- a/video/out/gpu_next/video.c +++ b/video/out/gpu_next/video.c @@ -173,6 +173,7 @@ struct mppl_video { // Color space and reference white of the display, from mppl_video_begin_frame() struct pl_color_space display_csp; float display_ref_luma; + bool display_sdr_above_ref_luma; // Bits per channel of the framebuffer, 0 if unknown int fb_depth; @@ -883,10 +884,11 @@ static float get_ref_luma(struct mppl_video *p) return p->display_ref_luma; } -static bool use_ref_luma(const struct pl_color_space *csp, const struct pl_color_space *target_csp) +static bool use_ref_luma(const struct pl_color_space *csp, const struct pl_color_space *target_csp, + bool sdr_above_ref_luma) { if (!pl_color_transfer_is_hdr(csp->transfer)) - return true; + return !(sdr_above_ref_luma && pl_color_space_is_hdr(csp)); if (csp->transfer == PL_COLOR_TRC_SCRGB && target_csp && !pl_color_space_is_hdr(target_csp)) return true; return false; @@ -1177,7 +1179,7 @@ static void apply_target_contrast(struct mppl_video *p, struct pl_color_space *c static void apply_target_options(struct mppl_video *p, struct pl_frame *target, float min_luma, bool hint, float target_ref_luma, - const struct pl_color_space *target_csp) + const struct pl_color_space *target_csp, bool sdr_above_ref_luma) { update_lut(p, &p->next_opts->target_lut); target->lut = p->next_opts->target_lut.lut; @@ -1195,7 +1197,7 @@ static void apply_target_options(struct mppl_video *p, struct pl_frame *target, if (opts->target_peak && (!target->color.hdr.max_luma || !hint)) target->color.hdr.max_luma = opts->target_peak; if (target_ref_luma && (!target->color.hdr.max_luma || !hint) && - use_ref_luma(&target->color, target_csp)) { + use_ref_luma(&target->color, target_csp, sdr_above_ref_luma)) { target->color.hdr.max_luma = target_ref_luma; } if ((!target->color.hdr.min_luma || !hint)) @@ -1331,11 +1333,13 @@ static void reset_queue(struct mppl_video *p) } void mppl_video_begin_frame(struct mppl_video *p, struct vo_frame *frame, - struct pl_color_space display_csp, float display_ref_luma) + struct pl_color_space display_csp, float display_ref_luma, + bool display_sdr_above_ref_luma) { update_options(p); p->display_csp = display_csp; p->display_ref_luma = display_ref_luma; + p->display_sdr_above_ref_luma = display_sdr_above_ref_luma; struct frame_params fpar = get_frame_params(p, frame); bool can_interpolate = fpar.can_interpolate; @@ -1451,6 +1455,7 @@ enum mppl_video_hint mppl_video_get_target_hint(struct mppl_video *p, struct vo_ struct pl_color_space hint = {0}; bool target_hint = p->next_opts->target_hint == 1 || (p->next_opts->target_hint == -1 && !target_unknown); + bool sdr_above_ref_luma = target_hint && p->display_sdr_above_ref_luma; if (target_hint && frame->current) { const struct pl_color_space *source = &frame->current->params.color; const struct pl_color_space *target = &target_csp; @@ -1514,7 +1519,7 @@ enum mppl_video_hint mppl_video_get_target_hint(struct mppl_video *p, struct vo_ hint.transfer = opts->target_trc; if (opts->target_peak) hint.hdr.max_luma = opts->target_peak; - if (target_ref_luma && use_ref_luma(&hint, &target_csp)) + if (target_ref_luma && use_ref_luma(&hint, &target_csp, sdr_above_ref_luma)) hint.hdr.max_luma = target_ref_luma; // The SDR black point was inferred from the peak known before the // overrides above, keep the assumed contrast relative to the final @@ -1606,8 +1611,9 @@ bool mppl_video_render_frame(struct mppl_video *p, struct vo_frame *frame, struct pl_frame target; pl_frame_from_swapchain(&target, swframe); bool strict_sw_params = hint && p->next_opts->target_hint_strict; + bool sdr_above_ref_luma = hint && p->display_sdr_above_ref_luma; apply_target_options(p, &target, hint ? hint->hdr.min_luma : target_csp.hdr.min_luma, - strict_sw_params, target_ref_luma, &target_csp); + strict_sw_params, target_ref_luma, &target_csp, sdr_above_ref_luma); bool clip_gamut = pl_primaries_valid(&target.color.hdr.prim); clip_gamut = clip_gamut && target.color.transfer != PL_COLOR_TRC_SCRGB; if (clip_gamut) { @@ -1968,7 +1974,7 @@ void mppl_video_screenshot(struct mppl_video *p, struct voctrl_screenshot *args) const struct gl_video_opts *opts = p->opts_cache->opts; if (args->scaled) { // Apply target LUT, ICC profile and CSP override only in window mode - apply_target_options(p, &target, 0, false, 0, NULL); + apply_target_options(p, &target, 0, false, 0, NULL, false); } else if (args->native_csp) { target.color = image.color; } else { diff --git a/video/out/gpu_next/video.h b/video/out/gpu_next/video.h index f385d52cfae90..6366019331271 100644 --- a/video/out/gpu_next/video.h +++ b/video/out/gpu_next/video.h @@ -66,7 +66,8 @@ bool mppl_video_opts_want_alpha(struct mpv_global *global); bool mppl_video_icc_auto_enabled(struct mppl_video *p); bool mppl_video_set_icc_profile(struct mppl_video *p, struct bstr icc); void mppl_video_begin_frame(struct mppl_video *p, struct vo_frame *frame, - struct pl_color_space display_csp, float display_ref_luma); + struct pl_color_space display_csp, float display_ref_luma, + bool display_sdr_above_ref_luma); enum mppl_video_hint mppl_video_get_target_hint(struct mppl_video *p, struct vo_frame *frame, struct pl_color_space *out_hint); void mppl_video_skip_frame(struct mppl_video *p, struct vo_frame *frame); diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c index 9e6514f414838..5995d86653da3 100644 --- a/video/out/vo_gpu_next.c +++ b/video/out/vo_gpu_next.c @@ -76,7 +76,8 @@ static bool draw_frame(struct vo *vo, struct vo_frame *frame) if (sw->fns->target_csp) display_csp = sw->fns->target_csp(sw); float display_ref_luma = sw->fns->target_ref_luma ? sw->fns->target_ref_luma(sw) : 0; - mppl_video_begin_frame(p->renderer, frame, display_csp, display_ref_luma); + bool sdr_above_ref_luma = sw->fns->sdr_above_ref_luma && sw->fns->sdr_above_ref_luma(sw); + mppl_video_begin_frame(p->renderer, frame, display_csp, display_ref_luma, sdr_above_ref_luma); struct pl_color_space hint = {0}; bool external_params = false; From f2c27d1a8b635f695df13b819fd179bdbd2f4247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 14 Nov 2026 01:47:02 +0100 Subject: [PATCH 17/20] wayland: don't replace the preferred transfer function by PQ Now that we plug the reference white into the SDR transfers, we can try to match the descriptors directly. For better or for worse. It's on Wayland then to provide sane luminance ranges. They say everything is relative, but the HDR10 metadata is not. We just follow what the compositor says, let's see how it ends up. --- video/out/wayland_common.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index c4b4c23d1025d..05d811a754850 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -2292,13 +2292,6 @@ static void info_done(void *data, struct wp_image_description_info_v1 *image_des MP_VERBOSE(wl, "Setting best primary container from raw primaries: %s\n", m_opt_choice_str(pl_csp_prim_names, wd->csp.primaries)); } - // We don't support extended ranges output where luminance exceeds - // maximum nominal luminance range (1.0), so switch to PQ. - if (fabsf(wd->csp.hdr.max_luma / wd->ref_luma - 1.0f) > 1e-4f && - !pl_color_transfer_is_hdr(wd->csp.transfer)) { - MP_VERBOSE(wl, "Setting preferred transfer to PQ for HDR output.\n"); - wd->csp.transfer = PL_COLOR_TRC_PQ; - } // The luminances are in the scale of PL_COLOR_SDR_WHITE, unless those of // the output are used as they are, with its reference white. bool absolute = wl->opts->wl_respect_pq_scale; From 437df4b955c55169d01bc726b80aa959745a2748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Tue, 17 Nov 2026 15:11:30 +0100 Subject: [PATCH 18/20] vo_gpu_next: don't take a frame without a hint as one of the source With the hint off the hint mode has no meaning, the frame is rendered for the target in every mode. --- video/out/gpu_next/video.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/video/out/gpu_next/video.c b/video/out/gpu_next/video.c index 07f103b61db38..86cd9bd47d780 100644 --- a/video/out/gpu_next/video.c +++ b/video/out/gpu_next/video.c @@ -1261,7 +1261,8 @@ enum pl_color_levels mppl_video_get_output_levels(struct mppl_video *p) bool mppl_video_hint_is_target(struct mppl_video *p) { - return p->next_opts->target_hint_mode == 0; + // Without a hint the frame is rendered for the target in every mode. + return !p->next_opts->target_hint || p->next_opts->target_hint_mode == 0; } static void update_tm_viz(struct pl_color_map_params *params, From 69bb564096a82752a88a136c2c672ef1b6bb5220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Tue, 17 Nov 2026 14:02:24 +0100 Subject: [PATCH 19/20] vo/gpu/context: add target parameter to target_ref_luma It tells if the signal is made for the target device or is the one of the source, as for set_color. Wayland anchors a signal of the source at its own reference white, so the one of the output doesn't apply to it. --- video/out/d3d11/context.c | 2 +- video/out/gpu/context.h | 6 ++++-- video/out/opengl/context.c | 4 ++-- video/out/opengl/context_wayland.c | 2 +- video/out/vo_gpu_next.c | 3 ++- video/out/vulkan/context.c | 4 ++-- video/out/vulkan/context_wayland.c | 2 +- video/out/vulkan/context_win.c | 2 +- 8 files changed, 14 insertions(+), 11 deletions(-) diff --git a/video/out/d3d11/context.c b/video/out/d3d11/context.c index 8f6ee01598eca..ee5dc5dda447d 100644 --- a/video/out/d3d11/context.c +++ b/video/out/d3d11/context.c @@ -224,7 +224,7 @@ static struct pl_color_space d3d11_target_color_space(struct ra_swapchain *sw) return (struct pl_color_space){0}; } -static float d3d11_target_ref_luma(struct ra_swapchain *sw) +static float d3d11_target_ref_luma(struct ra_swapchain *sw, bool target) { if (sw->ctx->opts.composition) return 0; diff --git a/video/out/gpu/context.h b/video/out/gpu/context.h index 14f7e2de78f35..bb15f129e8a5a 100644 --- a/video/out/gpu/context.h +++ b/video/out/gpu/context.h @@ -78,7 +78,7 @@ struct ra_ctx_params { pl_color_space_t (*preferred_csp)(struct ra_ctx *ctx); // See ra_swapchain_fns.target_ref_luma. Optional. - float (*preferred_ref_luma)(struct ra_ctx *ctx); + float (*preferred_ref_luma)(struct ra_ctx *ctx, bool target); // See ra_swapchain_fns.sdr_above_ref_luma. Optional. bool (*sdr_above_ref_luma)(struct ra_ctx *ctx); @@ -123,7 +123,9 @@ struct ra_swapchain_fns { // Target device reference luminance in nits, i.e. the luminance at which // the system displays diffuse (SDR) white. Returns 0 if unknown. Optional. - float (*target_ref_luma)(struct ra_swapchain *sw); + // target is set if the signal is made for the target device, and unset if + // it is the one of the source. + float (*target_ref_luma)(struct ra_swapchain *sw, bool target); // Whether the system shows an SDR signal set with set_color above the // reference white. If not, it shows the peak of such a signal as the diff --git a/video/out/opengl/context.c b/video/out/opengl/context.c index 59fa80edf74a7..f52e4248a501f 100644 --- a/video/out/opengl/context.c +++ b/video/out/opengl/context.c @@ -332,11 +332,11 @@ static pl_color_space_t ra_gl_ctx_target_csp(struct ra_swapchain *sw) return (pl_color_space_t){0}; } -static float ra_gl_ctx_target_ref_luma(struct ra_swapchain *sw) +static float ra_gl_ctx_target_ref_luma(struct ra_swapchain *sw, bool target) { struct priv *p = sw->priv; if (p->params.preferred_ref_luma) - return p->params.preferred_ref_luma(sw->ctx); + return p->params.preferred_ref_luma(sw->ctx, target); return 0; } diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c index ac596564ffbc9..701607577ed99 100644 --- a/video/out/opengl/context_wayland.c +++ b/video/out/opengl/context_wayland.c @@ -67,7 +67,7 @@ static pl_color_space_t wayland_egl_preferred_csp(struct ra_ctx *ctx) return vo_wayland_preferred_csp(ctx->vo); } -static float wayland_egl_preferred_ref_luma(struct ra_ctx *ctx) +static float wayland_egl_preferred_ref_luma(struct ra_ctx *ctx, bool target) { return vo_wayland_preferred_ref_luma(ctx->vo); } diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c index 5995d86653da3..bc0e29de6fbfe 100644 --- a/video/out/vo_gpu_next.c +++ b/video/out/vo_gpu_next.c @@ -75,7 +75,8 @@ static bool draw_frame(struct vo *vo, struct vo_frame *frame) // TODO: Implement this for all backends if (sw->fns->target_csp) display_csp = sw->fns->target_csp(sw); - float display_ref_luma = sw->fns->target_ref_luma ? sw->fns->target_ref_luma(sw) : 0; + bool target = mppl_video_hint_is_target(p->renderer); + float display_ref_luma = sw->fns->target_ref_luma ? sw->fns->target_ref_luma(sw, target) : 0; bool sdr_above_ref_luma = sw->fns->sdr_above_ref_luma && sw->fns->sdr_above_ref_luma(sw); mppl_video_begin_frame(p->renderer, frame, display_csp, display_ref_luma, sdr_above_ref_luma); diff --git a/video/out/vulkan/context.c b/video/out/vulkan/context.c index 8d1533aa5c536..bc44ac101fe52 100644 --- a/video/out/vulkan/context.c +++ b/video/out/vulkan/context.c @@ -662,11 +662,11 @@ static pl_color_space_t target_csp(struct ra_swapchain *sw) return (pl_color_space_t){0}; } -static float target_ref_luma(struct ra_swapchain *sw) +static float target_ref_luma(struct ra_swapchain *sw, bool target) { struct priv *p = sw->priv; if (p->params.preferred_ref_luma) - return p->params.preferred_ref_luma(sw->ctx); + return p->params.preferred_ref_luma(sw->ctx, target); return 0; } diff --git a/video/out/vulkan/context_wayland.c b/video/out/vulkan/context_wayland.c index cc8c1c5c3d7c5..ef84d953f7616 100644 --- a/video/out/vulkan/context_wayland.c +++ b/video/out/vulkan/context_wayland.c @@ -52,7 +52,7 @@ static pl_color_space_t wayland_vk_preferred_csp(struct ra_ctx *ctx) return vo_wayland_preferred_csp(ctx->vo); } -static float wayland_vk_preferred_ref_luma(struct ra_ctx *ctx) +static float wayland_vk_preferred_ref_luma(struct ra_ctx *ctx, bool target) { return vo_wayland_preferred_ref_luma(ctx->vo); } diff --git a/video/out/vulkan/context_win.c b/video/out/vulkan/context_win.c index a68a3ef51e807..96b32b844aa33 100644 --- a/video/out/vulkan/context_win.c +++ b/video/out/vulkan/context_win.c @@ -63,7 +63,7 @@ static struct pl_color_space preferred_csp(struct ra_ctx *ctx) return (struct pl_color_space){0}; } -static float preferred_ref_luma(struct ra_ctx *ctx) +static float preferred_ref_luma(struct ra_ctx *ctx, bool target) { struct priv *p = ctx->priv; return mp_dxgi_sdr_white_level_from_hwnd(&p->dxgi_ctx, vo_w32_hwnd(ctx->vo)); From 1f3d7bc73997e8fb6255a6be077a6aa31e17e63f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Tue, 17 Nov 2026 14:03:19 +0100 Subject: [PATCH 20/20] wayland: report no reference white for a signal of the source The compositor anchors a signal of the source at its own reference white, so the one of the output doesn't apply to what the renderer draws into it. With --wayland-respect-pq-scale the OSD and subtitles on a passed through HDR video were off by the ratio of the two. --- video/out/opengl/context_wayland.c | 2 +- video/out/vulkan/context_wayland.c | 2 +- video/out/wayland_common.c | 5 +++-- video/out/wayland_common.h | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c index 701607577ed99..66c50a3201b16 100644 --- a/video/out/opengl/context_wayland.c +++ b/video/out/opengl/context_wayland.c @@ -69,7 +69,7 @@ static pl_color_space_t wayland_egl_preferred_csp(struct ra_ctx *ctx) static float wayland_egl_preferred_ref_luma(struct ra_ctx *ctx, bool target) { - return vo_wayland_preferred_ref_luma(ctx->vo); + return vo_wayland_preferred_ref_luma(ctx->vo, target); } static bool wayland_egl_sdr_above_ref_luma(struct ra_ctx *ctx) diff --git a/video/out/vulkan/context_wayland.c b/video/out/vulkan/context_wayland.c index ef84d953f7616..d8c21a30d1f04 100644 --- a/video/out/vulkan/context_wayland.c +++ b/video/out/vulkan/context_wayland.c @@ -54,7 +54,7 @@ static pl_color_space_t wayland_vk_preferred_csp(struct ra_ctx *ctx) static float wayland_vk_preferred_ref_luma(struct ra_ctx *ctx, bool target) { - return vo_wayland_preferred_ref_luma(ctx->vo); + return vo_wayland_preferred_ref_luma(ctx->vo, target); } static bool wayland_vk_sdr_above_ref_luma(struct ra_ctx *ctx) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 05d811a754850..7fc7477430584 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -4341,9 +4341,10 @@ struct pl_color_space vo_wayland_preferred_csp(struct vo *vo) return wl->preferred_csp; } -float vo_wayland_preferred_ref_luma(struct vo *vo) +float vo_wayland_preferred_ref_luma(struct vo *vo, bool target) { - return vo->wl->preferred_ref_luma; + // The compositor anchors a signal of the source at its own reference white. + return target ? vo->wl->preferred_ref_luma : 0; } bool vo_wayland_sdr_above_ref_luma(struct vo *vo) diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h index fe3952733d53d..e636b211e46de 100644 --- a/video/out/wayland_common.h +++ b/video/out/wayland_common.h @@ -231,7 +231,7 @@ struct vo_wayland_state { bool vo_wayland_check_visible(struct vo *vo); struct pl_color_space vo_wayland_preferred_csp(struct vo *vo); -float vo_wayland_preferred_ref_luma(struct vo *vo); +float vo_wayland_preferred_ref_luma(struct vo *vo, bool target); bool vo_wayland_sdr_above_ref_luma(struct vo *vo); bool vo_wayland_valid_format(struct vo_wayland_state *wl, uint32_t drm_format, uint64_t modifier); bool vo_wayland_init(struct vo *vo);