[vlc-commits] d3d11: factorize the code to find an appropriate texture format
Steve Lhomme
git at videolan.org
Tue May 2 10:14:21 CEST 2017
vlc | branch: master | Steve Lhomme <robux4 at videolabs.io> | Fri Apr 28 17:46:21 2017 +0200| [87625c5291a24986db4c0a25fa2ee77f64804440] | committer: Jean-Baptiste Kempf
d3d11: factorize the code to find an appropriate texture format
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=87625c5291a24986db4c0a25fa2ee77f64804440
---
modules/codec/avcodec/d3d11va.c | 24 ++++--------------
modules/video_chroma/dxgi_fmt.h | 26 ++++++++++++++++++++
modules/video_output/win32/direct3d11.c | 43 ++++++++-------------------------
3 files changed, 41 insertions(+), 52 deletions(-)
diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index e6ee332f11..1f96940e4a 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -834,25 +834,11 @@ static bool SetupProcessor(vlc_va_t *va, const video_format_t *fmt)
{
// check if we can create render texture of that format
// check the decoder can output to that format
- for (const d3d_format_t *output = GetRenderFormatList();
- output->name != NULL; ++output)
- {
- if( DeviceSupportsFormat((ID3D11Device*) dx_sys->d3ddev, output->formatTexture,
- D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_SHADER_LOAD))
- {
- msg_Dbg(va, "Render pixel format %s supported", DxgiFormatToStr(output->formatTexture) );
-
- hr = ID3D11VideoProcessorEnumerator_CheckVideoProcessorFormat(processorEnumerator,
- output->formatTexture, &flags);
- if (FAILED(hr) || !(flags & D3D11_VIDEO_PROCESSOR_FORMAT_SUPPORT_OUTPUT))
- msg_Dbg(va, "Processor format %s not supported for output", DxgiFormatToStr(output->formatTexture));
- else
- {
- processorOutput = output->formatTexture;
- break;
- }
- }
- }
+ const d3d_format_t *found;
+ found = FindD3D11Format( (ID3D11Device*) dx_sys->d3ddev, 0, 0, true,
+ D3D11_FORMAT_SUPPORT_SHADER_LOAD | D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT);
+ if (found)
+ processorOutput = found->formatTexture;
}
if (processorOutput != DXGI_FORMAT_UNKNOWN)
diff --git a/modules/video_chroma/dxgi_fmt.h b/modules/video_chroma/dxgi_fmt.h
index 343154e8ab..f20e4888eb 100644
--- a/modules/video_chroma/dxgi_fmt.h
+++ b/modules/video_chroma/dxgi_fmt.h
@@ -59,4 +59,30 @@ static inline bool DeviceSupportsFormat(ID3D11Device *d3ddevice,
&i_formatSupport) )
&& ( i_formatSupport & supportFlags ) == supportFlags;
}
+
+static inline const d3d_format_t *FindD3D11Format(ID3D11Device *d3ddevice,
+ vlc_fourcc_t i_src_chroma,
+ uint8_t bits_per_channel,
+ bool allow_opaque,
+ UINT supportFlags)
+{
+ supportFlags |= D3D11_FORMAT_SUPPORT_TEXTURE2D;
+ for (const d3d_format_t *output_format = GetRenderFormatList();
+ output_format->name != NULL; ++output_format)
+ {
+ if (i_src_chroma && i_src_chroma != output_format->fourcc)
+ continue;
+ if (bits_per_channel && bits_per_channel > output_format->bitsPerChannel)
+ continue;
+ if (!allow_opaque && (output_format->fourcc == VLC_CODEC_D3D11_OPAQUE ||
+ output_format->fourcc == VLC_CODEC_D3D11_OPAQUE_10B))
+ continue;
+
+ if( DeviceSupportsFormat( d3ddevice, output_format->formatTexture,
+ supportFlags ) )
+ return output_format;
+ }
+ return NULL;
+}
+
#endif /* include-guard */
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 22f350fd19..6db1769ce3 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -573,34 +573,6 @@ static void Close(vlc_object_t *object)
free(vd->sys);
}
-static const d3d_format_t *GetOutputFormat(vout_display_t *vd, vlc_fourcc_t i_src_chroma,
- uint8_t bits_per_channel, bool b_allow_opaque,
- bool blendable)
-{
- vout_display_sys_t *sys = vd->sys;
- UINT supportFlags = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_SHADER_LOAD;
- if (blendable)
- supportFlags |= D3D11_FORMAT_SUPPORT_BLENDABLE;
- if (b_allow_opaque && is_d3d11_opaque(i_src_chroma))
- supportFlags |= D3D11_FORMAT_SUPPORT_DECODER_OUTPUT;
-
- for (const d3d_format_t *output_format = GetRenderFormatList();
- output_format->name != NULL; ++output_format)
- {
- if (i_src_chroma && i_src_chroma != output_format->fourcc)
- continue;
- if (bits_per_channel && bits_per_channel > output_format->bitsPerChannel)
- continue;
- if (!b_allow_opaque && is_d3d11_opaque(output_format->fourcc))
- continue;
-
- if( DeviceSupportsFormat( sys->d3ddevice, output_format->formatTexture,
- supportFlags ) )
- return output_format;
- }
- return NULL;
-}
-
/* map texture planes to resource views */
static int AllocateShaderView(vout_display_t *vd, const d3d_format_t *format,
int slice_index, picture_sys_t *picsys)
@@ -1592,7 +1564,10 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
D3D11SetColorSpace(vd);
// look for the requested pixel format first
- sys->picQuadConfig = GetOutputFormat(vd, fmt->i_chroma, 0, true, false);
+ UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD;
+ if (is_d3d11_opaque(fmt->i_chroma))
+ supportFlags |= D3D11_FORMAT_SUPPORT_DECODER_OUTPUT;
+ sys->picQuadConfig = FindD3D11Format(sys->d3ddevice, fmt->i_chroma, 0, true, supportFlags);
// look for any pixel format that we can handle with enough pixels per channel
if ( !sys->picQuadConfig )
@@ -1614,12 +1589,12 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
break;
}
- sys->picQuadConfig = GetOutputFormat(vd, 0, bits_per_channel, false, false);
+ sys->picQuadConfig = FindD3D11Format(sys->d3ddevice, 0, bits_per_channel, false, D3D11_FORMAT_SUPPORT_SHADER_LOAD);
}
// look for any pixel format that we can handle
if ( !sys->picQuadConfig )
- sys->picQuadConfig = GetOutputFormat(vd, 0, 0, false, false);
+ sys->picQuadConfig = FindD3D11Format(sys->d3ddevice, 0, 0, false, D3D11_FORMAT_SUPPORT_SHADER_LOAD);
if ( !sys->picQuadConfig )
{
@@ -1632,9 +1607,11 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
DxgiFormatMask( sys->picQuadConfig->formatTexture, fmt );
/* check the region pixel format */
- sys->d3dregion_format = GetOutputFormat(vd, VLC_CODEC_RGBA, 0, false, true);
+ sys->d3dregion_format = FindD3D11Format(sys->d3ddevice, VLC_CODEC_RGBA, 0, false,
+ D3D11_FORMAT_SUPPORT_SHADER_LOAD | D3D11_FORMAT_SUPPORT_BLENDABLE);
if (!sys->d3dregion_format)
- sys->d3dregion_format = GetOutputFormat(vd, VLC_CODEC_BGRA, 0, false, true);
+ sys->d3dregion_format = FindD3D11Format(sys->d3ddevice, VLC_CODEC_BGRA, 0, false,
+ D3D11_FORMAT_SUPPORT_SHADER_LOAD | D3D11_FORMAT_SUPPORT_BLENDABLE);
UpdateRects(vd, NULL, NULL, true);
More information about the vlc-commits
mailing list