Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ea191fc
wayland: set the linear mastering luminance only when supported
kasper93 Nov 13, 2026
d53179e
wayland: don't set an unknown max_cll or max_fall
kasper93 Nov 13, 2026
5bacd8a
wayland: round the luminances of the image description
kasper93 Nov 13, 2026
69e721e
wayland: redraw when the preferred image description changes
kasper93 Nov 13, 2026
0eff511
opengl/context: implement target_ref_luma
kasper93 Nov 13, 2026
93fa1e7
vo_gpu_next: limit the SDR contrast relative to the reference white
kasper93 Nov 13, 2026
a66e5a6
vo/gpu/context: add target parameter to set_color
kasper93 Nov 14, 2026
29c8629
wayland: add target parameter to vo_wayland_handle_color
kasper93 Nov 27, 2026
85b4512
wayland: factor out the scaling of the preferred luminances
kasper93 Nov 27, 2026
6559b32
wayland: don't declare a reference white above the peak of an SDR signal
kasper93 Nov 27, 2026
4343ba8
wayland: add --wayland-respect-pq-scale
kasper93 Nov 28, 2026
70272f9
wayland: declare the luminances of HLG that is made for the output
kasper93 Nov 17, 2026
490aa7a
vo_gpu_next: tell an HDR target by its peak as well
kasper93 Nov 14, 2026
3f1aafa
vo/gpu/context: add sdr_above_ref_luma function
kasper93 Nov 14, 2026
ca7e8dc
wayland: declare the reference white of an SDR signal that goes higher
kasper93 Nov 14, 2026
b0a2da5
vo_gpu_next: keep the peak of an SDR target above the reference white
kasper93 Nov 14, 2026
f2c27d1
wayland: don't replace the preferred transfer function by PQ
kasper93 Nov 14, 2026
437df4b
vo_gpu_next: don't take a frame without a hint as one of the source
kasper93 Nov 17, 2026
69bb564
vo/gpu/context: add target parameter to target_ref_luma
kasper93 Nov 17, 2026
1f3d7bc
wayland: report no reference white for a signal of the source
kasper93 Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/wayland-respect-pq-scale.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add `--wayland-respect-pq-scale` option
17 changes: 15 additions & 2 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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=<yes|no>``
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=<string>``
Set the wayland session name for window restoration (default: unset).
Not setting this or setting it to the empty string disables session
Expand Down Expand Up @@ -7709,14 +7721,15 @@ 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::

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=<auto|yes|no>``
SDR transfer functions are often ambiguous or mismatched. Even if files are
Expand Down
1 change: 1 addition & 0 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion video/out/d3d11/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 16 additions & 4 deletions video/out/gpu/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ 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);

// 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);
Expand Down Expand Up @@ -120,11 +123,20 @@ 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
// 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.
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
Expand Down
2 changes: 1 addition & 1 deletion video/out/gpu_next/libmpv_gpu_next.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
36 changes: 25 additions & 11 deletions video/out/gpu_next/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -883,11 +884,12 @@ 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;
if (csp->transfer == PL_COLOR_TRC_SCRGB && target_csp && !pl_color_transfer_is_hdr(target_csp->transfer))
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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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))
Expand Down Expand Up @@ -1257,6 +1259,12 @@ 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)
{
// 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,
const struct pl_frame *target)
{
Expand Down Expand Up @@ -1326,11 +1334,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;
Expand Down Expand Up @@ -1410,7 +1420,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
Expand Down Expand Up @@ -1444,6 +1456,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;
Expand Down Expand Up @@ -1492,7 +1505,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;
Expand All @@ -1507,7 +1520,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
Expand Down Expand Up @@ -1599,8 +1612,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) {
Expand Down Expand Up @@ -1961,7 +1975,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 {
Expand Down
4 changes: 3 additions & 1 deletion video/out/gpu_next/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -76,6 +77,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);
Expand Down
21 changes: 19 additions & 2 deletions video/out/opengl/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -331,10 +332,26 @@ 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, bool target)
{
struct priv *p = sw->priv;
if (p->params.preferred_ref_luma)
return p->params.preferred_ref_luma(sw->ctx, target);
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,
Expand Down
2 changes: 1 addition & 1 deletion video/out/opengl/context_drm_egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? &params->color : &sdr);
Expand Down
16 changes: 14 additions & 2 deletions video/out/opengl/context_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,19 @@ 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 float wayland_egl_preferred_ref_luma(struct ra_ctx *ctx, bool target)
{
vo_wayland_handle_color(ctx->vo->wl, params);
return vo_wayland_preferred_ref_luma(ctx->vo, target);
}

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);
return true;
}

Expand Down Expand Up @@ -118,6 +128,8 @@ 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,
.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,
Expand Down
2 changes: 1 addition & 1 deletion video/out/vo_dmabuf_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions video/out/vo_gpu_next.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? &params : NULL)) {
bool target = mppl_video_hint_is_target(p->renderer);
if (sw->fns->set_color && sw->fns->set_color(sw, hint ? &params : NULL, target)) {
if (hint) {
*hint = params.color;
return true;
Expand All @@ -74,8 +75,10 @@ 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;
mppl_video_begin_frame(p->renderer, frame, display_csp, display_ref_luma);
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);

struct pl_color_space hint = {0};
bool external_params = false;
Expand Down
2 changes: 1 addition & 1 deletion video/out/vo_wlshm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading