Skip to content

Commit fd1d740

Browse files
committed
vo_gpu_next: retrieve the preferred PRIM and TRF from the swapchain
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.
1 parent 2951826 commit fd1d740

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

video/out/d3d11/context.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ static int d3d11_color_depth(struct ra_swapchain *sw)
189189
return MPMIN(ra_fmt->component_depth[0], desc1.BitsPerColor);
190190
}
191191

192-
static struct pl_color_space d3d11_target_color_space(struct ra_swapchain *sw)
192+
static struct pl_color_space d3d11_target_color_space(struct ra_swapchain *sw,
193+
bool *target_is_preferred)
193194
{
194195
struct priv *p = sw->priv;
195196

video/out/gpu/context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct ra_swapchain_fns {
115115
int (*color_depth)(struct ra_swapchain *sw);
116116

117117
// Target device color space. Optional.
118-
pl_color_space_t (*target_csp)(struct ra_swapchain *sw);
118+
pl_color_space_t (*target_csp)(struct ra_swapchain *sw, bool *target_is_preferred);
119119

120120
// Called when rendering starts. Returns NULL on failure. This must be
121121
// followed by submit_frame, to submit the rendered frame. This function

video/out/opengl/context.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,14 @@ static void ra_gl_ctx_get_vsync(struct ra_swapchain *sw,
305305
p->params.get_vsync(sw->ctx, info);
306306
}
307307

308-
static pl_color_space_t ra_gl_ctx_target_csp(struct ra_swapchain *sw)
308+
static pl_color_space_t ra_gl_ctx_target_csp(struct ra_swapchain *sw,
309+
bool *target_is_preferred)
309310
{
310311
struct priv *p = sw->priv;
311-
if (p->params.preferred_csp)
312+
if (p->params.preferred_csp) {
313+
*target_is_preferred = true;
312314
return p->params.preferred_csp(sw->ctx);
315+
}
313316
return DEFAULT_TARGET_CSP;
314317
}
315318

video/out/vo_gpu_next.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -984,11 +984,12 @@ static bool draw_frame(struct vo *vo, struct vo_frame *frame)
984984
struct ra_swapchain *sw = p->ra_ctx->swapchain;
985985

986986
bool pass_colorspace = false;
987+
bool target_csp_is_preferred = false;
987988
struct pl_color_space target_csp;
988989
// Assume HDR is supported, if query is not available
989990
// TODO: Implement this for all backends
990991
target_csp = sw->fns->target_csp
991-
? sw->fns->target_csp(sw)
992+
? sw->fns->target_csp(sw, &target_csp_is_preferred)
992993
: DEFAULT_TARGET_CSP;
993994
if (!pl_color_transfer_is_hdr(target_csp.transfer)) {
994995
target_csp.hdr.max_luma = 0;
@@ -1001,13 +1002,21 @@ static bool draw_frame(struct vo *vo, struct vo_frame *frame)
10011002
(p->next_opts->target_hint == -1 &&
10021003
pl_color_transfer_is_hdr(target_csp.transfer));
10031004
if (target_hint && frame->current) {
1005+
enum pl_color_primaries primaries = opts->target_prim;
1006+
enum pl_color_transfer transfer = opts->target_trc;
1007+
if (target_csp_is_preferred) {
1008+
if (!primaries)
1009+
primaries = target_csp.primaries;
1010+
if (!transfer)
1011+
transfer = target_csp.transfer;
1012+
}
10041013
hint = frame->current->params.color;
10051014
if (p->ra_ctx->fns->pass_colorspace && p->ra_ctx->fns->pass_colorspace(p->ra_ctx))
10061015
pass_colorspace = true;
1007-
if (opts->target_prim)
1008-
hint.primaries = opts->target_prim;
1009-
if (opts->target_trc)
1010-
hint.transfer = opts->target_trc;
1016+
if (primaries)
1017+
hint.primaries = primaries;
1018+
if (transfer)
1019+
hint.transfer = transfer;
10111020
if (target_peak)
10121021
hint.hdr.max_luma = target_peak;
10131022
apply_target_contrast(p, &hint, target_csp.hdr.min_luma);

video/out/vulkan/context.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,13 @@ static void get_vsync(struct ra_swapchain *sw,
375375
p->params.get_vsync(sw->ctx, info);
376376
}
377377

378-
static pl_color_space_t target_csp(struct ra_swapchain *sw)
378+
static pl_color_space_t target_csp(struct ra_swapchain *sw, bool *target_is_preferred)
379379
{
380380
struct priv *p = sw->priv;
381-
if (p->params.preferred_csp)
381+
if (p->params.preferred_csp) {
382+
*target_is_preferred = true;
382383
return p->params.preferred_csp(sw->ctx);
384+
}
383385
return DEFAULT_TARGET_CSP;
384386
}
385387

0 commit comments

Comments
 (0)