Skip to content

Commit

Permalink
vulkan: add pl_vulkan_swapchain_params.disable_10bit_sdr
Browse files Browse the repository at this point in the history
To mirror the D3D11 option, and to work around driver-related dithering
bugs.

See-Also: mpv-player/mpv#11862
Supersedes: https://code.videolan.org/videolan/libplacebo/-/merge_requests/494
  • Loading branch information
haasn committed Jul 27, 2023
1 parent d8e5534 commit 4d20c8b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ project('libplacebo', ['c', 'cpp'],
6,
# API version
{
'294': 'add pl_vulkan_swapchain_params.disable_10bit_sdr',
'293': 'add pl_test_pixfmt_caps',
'292': 'add pl_peak_detect_high_quality_params and pl_color_map_high_quality_params',
'291': 'add PL_COLOR_HDR_BLACK, PL_COLOR_SDR_CONTRAST and PL_COLOR_HLG_PEAK',
Expand Down
5 changes: 5 additions & 0 deletions src/include/libplacebo/vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ struct pl_vulkan_swapchain_params {
// calling `pl_swapchain_resize` as appropriate. libplacebo will tolerate
// the "suboptimal" status indefinitely.
bool allow_suboptimal;

// Disable high-bit (10 or more) SDR formats. May help work around buggy
// drivers which don't dither properly when outputting high bit depth
// SDR backbuffers to 8-bit screens.
bool disable_10bit_sdr;
};

#define pl_vulkan_swapchain_params(...) (&(struct pl_vulkan_swapchain_params) { __VA_ARGS__ })
Expand Down
9 changes: 7 additions & 2 deletions src/vulkan/swapchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ static bool pick_surf_format(pl_swapchain sw, const struct pl_color_space *hint)
if (!map_color_space(p->formats.elem[i].colorSpace, &space))
continue;

bool disable10 = !pl_color_transfer_is_hdr(space.transfer) &&
p->params.disable_10bit_sdr;

switch (p->formats.elem[i].format) {
// Only accept floating point formats for linear curves
case VK_FORMAT_R16G16B16_SFLOAT:
Expand All @@ -188,14 +191,16 @@ static bool pick_surf_format(pl_swapchain sw, const struct pl_color_space *hint)
// Only accept 10 bit formats for non-linear curves
case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
if (space.transfer != PL_COLOR_TRC_LINEAR)
if (space.transfer != PL_COLOR_TRC_LINEAR && !disable10)
break; // accept
continue;

// Accept 16-bit formats for everything
case VK_FORMAT_R16G16B16_UNORM:
case VK_FORMAT_R16G16B16A16_UNORM:
break; // accept
if (!disable10)
break; // accept
continue;

default: continue;
}
Expand Down

0 comments on commit 4d20c8b

Please sign in to comment.