Skip to content

Commit 6149d18

Browse files
committed
d3d11/swapchain: add pl_d3d11_swapchain_params.{alpha,color}_bits
1 parent 7076262 commit 6149d18

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ project('libplacebo', ['c', 'cpp'],
1212
7,
1313
# API version
1414
{
15+
'360': 'add pl_d3d11_swapchain_params.{alpha,color}_bits',
1516
'359': 'add pl_vulkan_swapchain_params.{alpha,color}_bits',
1617
'358': 'add PL_COLOR_SYSTEM_YCGCO_{RE,RO}',
1718
'357': 'add pl_daylight_from_temp, pl_blackbody_from_temp, and generalize pl_white_from_temp',

src/d3d11/swapchain.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,26 @@ static enum DXGI_FORMAT pick_format(pl_swapchain sw,
338338
struct priv *p = PL_PRIV(sw);
339339
struct d3d11_ctx *ctx = p->ctx;
340340

341+
// Allow 16-bit, which is scRGB in practice, only if explicitly requested.
342+
// Shouldn't be used as it's not fully supported in libplacebo yet.
343+
bool use_16_bits = p->params.alpha_bits > 8 || p->params.color_bits > 10;
344+
345+
// TODO: add proper support for scRGB (DXGI_FORMAT_R16G16B16A16_FLOAT)
346+
if (use_16_bits && d3d11_format_supported(ctx, DXGI_FORMAT_R16G16B16A16_FLOAT))
347+
return DXGI_FORMAT_R16G16B16A16_FLOAT;
348+
341349
bool use_10_bits = pl_color_space_is_hdr(hint) ||
342350
pl_color_primaries_is_wide_gamut(hint->primaries) ||
343351
!p->params.disable_10bit_sdr;
352+
// If >2 alpha bits are requested, don't use rgb10a2, drop to rgba8 instead.
353+
// This will most likely disable HDR output as well, but without scRGB support
354+
// there's no better alternative.
355+
if (p->params.alpha_bits > 2)
356+
use_10_bits = false;
344357

345358
if (use_10_bits && d3d11_format_supported(ctx, DXGI_FORMAT_R10G10B10A2_UNORM))
346359
return DXGI_FORMAT_R10G10B10A2_UNORM;
347360

348-
// TODO: add support for scRGB (DXGI_FORMAT_R16G16B16A16_FLOAT)
349-
350361
return DXGI_FORMAT_R8G8B8A8_UNORM;
351362
}
352363

src/include/libplacebo/d3d11.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ struct pl_d3d11_swapchain_params {
197197

198198
// Disable using a 10-bit swapchain format for SDR output
199199
bool disable_10bit_sdr;
200+
201+
// Minimum number of alpha bits requested in the swapchain format. In
202+
// practice, this can be used to prefer formats with higher alpha bit depth
203+
// (e.g. rgba8/rgba16 over rgb10a2), potentially trading 2 bits per color
204+
// channel for increased alpha precision. This is a hint, if no matching
205+
// format is found, lower bit depths will be accepted.
206+
uint8_t alpha_bits;
207+
208+
// Minimum number of color bits requested in the swapchain format. This can
209+
// be used to prefer formats with higher color bit depth. This is a hint,
210+
// if no matching format is found, lower bit depths will be accepted.
211+
uint8_t color_bits;
200212
};
201213

202214
#define pl_d3d11_swapchain_params(...) (&(struct pl_d3d11_swapchain_params) { __VA_ARGS__ })

0 commit comments

Comments
 (0)