[vlc-commits] direct3d11: pick the output format based on chroma subsampling
Steve Lhomme
git at videolan.org
Mon Oct 15 14:29:17 CEST 2018
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Oct 15 14:22:40 2018 +0200| [f6a25bd66d88eaad77e90e16de08f1fc8f9aec72] | committer: Steve Lhomme
direct3d11: pick the output format based on chroma subsampling
Don't subsample if we don't have to.
In any case we can display in YUVA or RGBA that have no subsampling.
Fixes #20421
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f6a25bd66d88eaad77e90e16de08f1fc8f9aec72
---
modules/hw/d3d11/d3d11_surface.c | 2 +-
modules/video_chroma/d3d11_fmt.c | 6 ++++
modules/video_chroma/d3d11_fmt.h | 5 ++-
modules/video_output/win32/direct3d11.c | 55 ++++++++++++++++++++++++++-------
4 files changed, 55 insertions(+), 13 deletions(-)
diff --git a/modules/hw/d3d11/d3d11_surface.c b/modules/hw/d3d11/d3d11_surface.c
index 1a468cb726..14266ba458 100644
--- a/modules/hw/d3d11/d3d11_surface.c
+++ b/modules/hw/d3d11/d3d11_surface.c
@@ -181,7 +181,7 @@ static int assert_staging(filter_t *p_filter, picture_sys_t *p_sys)
/* failed with the this format, try a different one */
UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD | D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT;
const d3d_format_t *new_fmt =
- FindD3D11Format( p_filter, &d3d_dev, 0, false, 0, false, supportFlags );
+ FindD3D11Format( p_filter, &d3d_dev, 0, false, 0, 0, 0, false, supportFlags );
if (new_fmt && texDesc.Format != new_fmt->formatTexture)
{
DXGI_FORMAT srcFormat = texDesc.Format;
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index 432f1d8632..07ee9ae261 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -491,6 +491,8 @@ const d3d_format_t *FindD3D11Format(vlc_object_t *o,
vlc_fourcc_t i_src_chroma,
bool rgb_only,
uint8_t bits_per_channel,
+ uint8_t widthDenominator,
+ uint8_t heightDenominator,
bool allow_opaque,
UINT supportFlags)
{
@@ -506,6 +508,10 @@ const d3d_format_t *FindD3D11Format(vlc_object_t *o,
continue;
if (rgb_only && vlc_fourcc_IsYUV(output_format->fourcc))
continue;
+ if (widthDenominator && widthDenominator < output_format->widthDenominator)
+ continue;
+ if (heightDenominator && heightDenominator < output_format->heightDenominator)
+ continue;
DXGI_FORMAT textureFormat;
if (output_format->formatTexture == DXGI_FORMAT_UNKNOWN)
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index 251a81a88d..115ce48406 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -138,9 +138,12 @@ const d3d_format_t *FindD3D11Format(vlc_object_t *,
vlc_fourcc_t i_src_chroma,
bool rgb_only,
uint8_t bits_per_channel,
+ uint8_t widthDenominator,
+ uint8_t heightDenominator,
bool allow_opaque,
UINT supportFlags);
-#define FindD3D11Format(a,b,c,d,e,f,g) FindD3D11Format(VLC_OBJECT(a),b,c,d,e,f,g)
+#define FindD3D11Format(a,b,c,d,e,f,g,h,i) \
+ FindD3D11Format(VLC_OBJECT(a),b,c,d,e,f,g,h,i)
int AllocateTextures(vlc_object_t *, d3d11_device_t *, const d3d_format_t *,
const video_format_t *, unsigned pool_size, ID3D11Texture2D *textures[]);
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 19013eae60..dcd8def224 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -1174,27 +1174,33 @@ static const d3d_format_t *GetDirectRenderingFormat(vout_display_t *vd, vlc_four
UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD;
if (is_d3d11_opaque(i_src_chroma))
supportFlags |= D3D11_FORMAT_SUPPORT_DECODER_OUTPUT;
- return FindD3D11Format( vd, &vd->sys->d3d_dev, i_src_chroma, false, 0, is_d3d11_opaque(i_src_chroma), supportFlags );
+ return FindD3D11Format( vd, &vd->sys->d3d_dev, i_src_chroma, false, 0, 0, 0, is_d3d11_opaque(i_src_chroma), supportFlags );
}
static const d3d_format_t *GetDirectDecoderFormat(vout_display_t *vd, vlc_fourcc_t i_src_chroma)
{
UINT supportFlags = D3D11_FORMAT_SUPPORT_DECODER_OUTPUT;
- return FindD3D11Format( vd, &vd->sys->d3d_dev, i_src_chroma, false, 0, is_d3d11_opaque(i_src_chroma), supportFlags );
+ return FindD3D11Format( vd, &vd->sys->d3d_dev, i_src_chroma, false, 0, 0, 0, is_d3d11_opaque(i_src_chroma), supportFlags );
}
-static const d3d_format_t *GetDisplayFormatByDepth(vout_display_t *vd, uint8_t bit_depth, bool from_processor, bool rgb_only)
+static const d3d_format_t *GetDisplayFormatByDepth(vout_display_t *vd, uint8_t bit_depth,
+ uint8_t widthDenominator,
+ uint8_t heightDenominator,
+ bool from_processor,
+ bool rgb_only)
{
UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD;
if (from_processor)
supportFlags |= D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT;
- return FindD3D11Format( vd, &vd->sys->d3d_dev, 0, rgb_only, bit_depth, false, supportFlags );
+ return FindD3D11Format( vd, &vd->sys->d3d_dev, 0, rgb_only,
+ bit_depth, widthDenominator, heightDenominator,
+ false, supportFlags );
}
static const d3d_format_t *GetBlendableFormat(vout_display_t *vd, vlc_fourcc_t i_src_chroma)
{
UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD | D3D11_FORMAT_SUPPORT_BLENDABLE;
- return FindD3D11Format( vd, &vd->sys->d3d_dev, i_src_chroma, false, 0, false, supportFlags );
+ return FindD3D11Format( vd, &vd->sys->d3d_dev, i_src_chroma, false, 0, 0, 0, false, supportFlags );
}
static int Direct3D11Open(vout_display_t *vd)
@@ -1230,10 +1236,12 @@ static int Direct3D11Open(vout_display_t *vd)
sys->display.pixelFormat = FindD3D11Format( vd, &sys->d3d_dev, 0, true,
vd->source.i_chroma==VLC_CODEC_D3D11_OPAQUE_10B ? 10 : 8,
+ 0, 0,
false, D3D11_FORMAT_SUPPORT_DISPLAY );
if (unlikely(sys->display.pixelFormat == NULL))
sys->display.pixelFormat = FindD3D11Format( vd, &sys->d3d_dev, 0, false,
vd->source.i_chroma==VLC_CODEC_D3D11_OPAQUE_10B ? 10 : 8,
+ 0, 0,
false, D3D11_FORMAT_SUPPORT_DISPLAY );
if (unlikely(sys->display.pixelFormat == NULL)) {
msg_Err(vd, "Could not get the SwapChain format.");
@@ -1312,22 +1320,43 @@ static int SetupOutputFormat(vout_display_t *vd, video_format_t *fmt)
if ( !sys->picQuad.textureFormat )
{
uint8_t bits_per_channel;
+ uint8_t widthDenominator, heightDenominator;
switch (fmt->i_chroma)
{
case VLC_CODEC_D3D11_OPAQUE:
+ bits_per_channel = 8;
+ widthDenominator = heightDenominator = 2;
+ break;
case VLC_CODEC_D3D11_OPAQUE_RGBA:
case VLC_CODEC_D3D11_OPAQUE_BGRA:
bits_per_channel = 8;
+ widthDenominator = heightDenominator = 1;
break;
case VLC_CODEC_D3D11_OPAQUE_10B:
bits_per_channel = 10;
+ widthDenominator = heightDenominator = 2;
break;
default:
{
const vlc_chroma_description_t *p_format = vlc_fourcc_GetChromaDescription(fmt->i_chroma);
- bits_per_channel = p_format == NULL ||
- p_format->pixel_bits == 0 ? 8 : p_format->pixel_bits /
- (p_format->plane_count==1 ? p_format->pixel_size : 1);
+ if (p_format == NULL)
+ {
+ bits_per_channel = 8;
+ widthDenominator = heightDenominator = 2;
+ }
+ else
+ {
+ bits_per_channel = p_format->pixel_bits == 0 ? 8 : p_format->pixel_bits /
+ (p_format->plane_count==1 ? p_format->pixel_size : 1);
+ widthDenominator = heightDenominator = 1;
+ for (size_t i=0; i<p_format->plane_count; i++)
+ {
+ if (widthDenominator < p_format->p[i].w.den)
+ widthDenominator = p_format->p[i].w.den;
+ if (heightDenominator < p_format->p[i].h.den)
+ heightDenominator = p_format->p[1].h.den;
+ }
+ }
}
break;
}
@@ -1339,14 +1368,18 @@ static int SetupOutputFormat(vout_display_t *vd, video_format_t *fmt)
decoder_format = sys->picQuad.textureFormat;
bool is_rgb = !vlc_fourcc_IsYUV(fmt->i_chroma);
- sys->picQuad.textureFormat = GetDisplayFormatByDepth(vd, bits_per_channel, decoder_format!=NULL, is_rgb);
+ sys->picQuad.textureFormat = GetDisplayFormatByDepth(vd, bits_per_channel,
+ widthDenominator, heightDenominator,
+ decoder_format!=NULL, is_rgb);
if (!sys->picQuad.textureFormat && is_rgb)
- sys->picQuad.textureFormat = GetDisplayFormatByDepth(vd, bits_per_channel, decoder_format!=NULL, false);
+ sys->picQuad.textureFormat = GetDisplayFormatByDepth(vd, bits_per_channel,
+ widthDenominator, heightDenominator,
+ decoder_format!=NULL, false);
}
// look for any pixel format that we can handle
if ( !sys->picQuad.textureFormat )
- sys->picQuad.textureFormat = GetDisplayFormatByDepth(vd, 0, false, false);
+ sys->picQuad.textureFormat = GetDisplayFormatByDepth(vd, 0, 0, 0, false, false);
if ( !sys->picQuad.textureFormat )
{
More information about the vlc-commits
mailing list