Skip to content

Conversation

@mahkoh
Copy link
Contributor

@mahkoh mahkoh commented May 8, 2025

This patch allows vo_gpu_next to automatically switch to the preferred
primaries and transfer function of the current output without the user
having to specify them on the command line.

Without this patch, libplacebo will always pick an HDR color space that
will require the compositor to perform tone and gamut mapping on SDR
outputs. This will likely be of lower quality than what libplacebo can
achieve when it instead picks an SDR color space.


I've tested this in Jay and KDE with https://4kmedia.org/lg-new-york-hdr-uhd-4k-demo. Jay currently does not do any tone mapping but even the tone mapping on KDE is not as good as libplacebo. At the start of the video, you can see the clouds getting blown out without this patch. With this patch, the clouds look good.

When moving the window between outputs with different color spaces, you should see logs similar to

[vo/gpu-next/wayland] Surface entered output BNQ BenQ GW2480 (0x3b), scale = 1.000000, refresh rate = 60.000000 Hz
[vo/gpu-next/libplacebo] Picked surface configuration 1: VK_FORMAT_R16G16B16A16_UNORM + VK_COLOR_SPACE_SRGB_NONLINEAR_KHR
[vo/gpu-next/wayland] Surface entered output AOC 24G4 (0x37), scale = 1.000000, refresh rate = 120.000000 Hz
[vo/gpu-next/libplacebo] Picked surface configuration 121: VK_FORMAT_R16G16B16A16_UNORM + VK_COLOR_SPACE_HDR10_ST2084_EXT

This implements target_csp in terms of the preferred color description
of the video surface.
: (struct pl_color_space){ .transfer = PL_COLOR_TRC_PQ };
? sw->fns->target_csp(sw, &target_csp_is_preferred)
: DEFAULT_TARGET_CSP;
if (!pl_color_transfer_is_hdr(target_csp.transfer)) {
Copy link
Contributor Author

@mahkoh mahkoh May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this should also be guarded by !target_csp_is_preferred. My concern here is that these values are not accurate for SDR displays.

struct vo_wayland_preferred_description_info *wd = data;
if (!wd->is_parametric)
return;
wd->csp.primaries = map_primaries(primaries);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KDE does not send named primaries so this is ineffective there. Maybe pl_color_space could be enhanced to also support primaries by value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems GNOME also only supports a very limited number of named primaries: https://gitlab.gnome.org/GNOME/mutter/-/blob/main/src/wayland/meta-wayland-color-management.c#L244
I guess support for value-based primaries is a must.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw I think there should be very less cases that we can get monitor's primaries in named format, since monitor's EDID would only provide chromaticity coordinates unless the monitor is pure sRGB.

@mahkoh mahkoh force-pushed the jorth/auto-hdr branch from e9aef92 to 8a8a8b0 Compare May 8, 2025 17:30
bool target_csp_is_preferred = false;
struct pl_color_space target_csp;
// Assume HDR is supported, if query is not available
// TODO: Implement this for all backends
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This basically resolves this TODO

@kasper93
Copy link
Member

kasper93 commented May 8, 2025

Fixes: #16305

@mahkoh mahkoh force-pushed the jorth/auto-hdr branch from 8a8a8b0 to fd1d740 Compare May 8, 2025 19:27
This patch allows vo_gpu_next to automatically switch to the preferred
primaries and transfer function of the current output without the user
having to specify them on the command line.

Without this patch, libplacebo will always pick an HDR color space that
will require the compositor to perform tone and gamut mapping on SDR
outputs.  This will likely be of lower quality than what libplacebo can
achieve when it instead picks an SDR color space.
@mahkoh mahkoh force-pushed the jorth/auto-hdr branch from fd1d740 to 2f929db Compare May 9, 2025 12:27
Comment on lines +1007 to +1012
enum pl_color_primaries primaries = opts->target_prim ? opts->target_prim : target_csp.primaries;
if (primaries)
hint.primaries = primaries;
enum pl_color_transfer transfer = opts->target_trc ? opts->target_trc : target_csp.transfer;
if (transfer)
hint.transfer = transfer;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it also make sense to copy the hdr metadata from the target_csp?

@github-actions
Copy link

github-actions bot commented May 9, 2025

wp_image_description_info_v1_destroy(image_description_info);
if (!wl->icc_file)
MP_VERBOSE(wl, "No ICC profile retrieved from the compositor.\n");
if (wd->is_parametric) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should prefer ICC file first? Do we need the extra information provided by ICC file?

@Dudemanguy Dudemanguy self-requested a review June 21, 2025 21:01
@kasper93
Copy link
Member

kasper93 commented Jul 7, 2025

So sorry for leaving it not merged for so long. I have taken a look at the topic and if you don't mind I follow up on this in #16512. With the new option, some more docs and support for Vulkan on Windows. I've cherry-picked your Wayland changes. Renamed commit message and skipped gpu-next changes, because I did it differently with the new option.

@Dudemanguy
Copy link
Member

Sorry on my end for not ever getting around to looking at it as well...

@kasper93
Copy link
Member

Merged as 39c9d1a and other vo_gpu_next changes. Should be fine now, we target prefered color space by default, if possible, i.e. if there is compatible surface format. Can be controlled with target-colorspace-hint-mode, see documentation for more info.

Thank you for contribution. Hopefully now most of those things work out of the box.

@kasper93 kasper93 closed this Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants