Skip to content

vo_gpu_next: implement target_csp for wayland and automatic color space switching #16321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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.
? sw->fns->target_csp(sw)
: (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.

@mahkoh mahkoh force-pushed the jorth/auto-hdr branch from e9aef92 to 8a8a8b0 Compare May 8, 2025 17:30
@@ -984,12 +984,13 @@ static bool draw_frame(struct vo *vo, struct vo_frame *frame)
struct ra_swapchain *sw = p->ra_ctx->swapchain;

bool pass_colorspace = false;
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?

Copy link

github-actions bot commented May 9, 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.

2 participants