d3d11va: don't use the external pool for NVIDIA hardware with too many slices
[vlc.git] / modules / video_chroma / dxgi_fmt.h
1 /*****************************************************************************
2  * dxgi_fmt.h : DXGI helper calls
3  *****************************************************************************
4  * Copyright © 2015 VLC authors, VideoLAN and VideoLabs
5  *
6  * Authors: Steve Lhomme <robux4@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 #ifndef VLC_VIDEOCHROMA_DXGI_FMT_H_
24 #define VLC_VIDEOCHROMA_DXGI_FMT_H_
25
26 #include <dxgi.h>
27 #include <dxgiformat.h>
28
29 #include <vlc_common.h>
30 #include <vlc_fourcc.h>
31
32 #define D3D11_MAX_SHADER_VIEW  2
33
34 typedef struct
35 {
36     const char   *name;
37     DXGI_FORMAT  formatTexture;
38     vlc_fourcc_t fourcc;
39     uint8_t      bitsPerChannel;
40     uint8_t      widthDenominator;
41     uint8_t      heightDenominator;
42     DXGI_FORMAT  resourceFormat[D3D11_MAX_SHADER_VIEW];
43 } d3d_format_t;
44
45 extern const char *DxgiFormatToStr(DXGI_FORMAT format);
46 extern vlc_fourcc_t DxgiFormatFourcc(DXGI_FORMAT format);
47 extern const d3d_format_t *GetRenderFormatList(void);
48 extern void DxgiFormatMask(DXGI_FORMAT format, video_format_t *);
49
50 typedef struct ID3D11Device ID3D11Device;
51 bool isXboxHardware(ID3D11Device *d3ddev);
52 bool isNvidiaHardware(ID3D11Device *d3ddev);
53 IDXGIAdapter *D3D11DeviceAdapter(ID3D11Device *d3ddev);
54
55 static inline bool DeviceSupportsFormat(ID3D11Device *d3ddevice,
56                                         DXGI_FORMAT format, UINT supportFlags)
57 {
58     UINT i_formatSupport;
59     return SUCCEEDED( ID3D11Device_CheckFormatSupport(d3ddevice, format,
60                                                       &i_formatSupport) )
61             && ( i_formatSupport & supportFlags ) == supportFlags;
62 }
63
64 static inline const d3d_format_t *FindD3D11Format(ID3D11Device *d3ddevice,
65                                                   vlc_fourcc_t i_src_chroma,
66                                                   uint8_t bits_per_channel,
67                                                   bool allow_opaque,
68                                                   UINT supportFlags)
69 {
70     supportFlags |= D3D11_FORMAT_SUPPORT_TEXTURE2D;
71     for (const d3d_format_t *output_format = GetRenderFormatList();
72          output_format->name != NULL; ++output_format)
73     {
74         if (i_src_chroma && i_src_chroma != output_format->fourcc)
75             continue;
76         if (bits_per_channel && bits_per_channel > output_format->bitsPerChannel)
77             continue;
78         if (!allow_opaque && (output_format->fourcc == VLC_CODEC_D3D11_OPAQUE ||
79                               output_format->fourcc == VLC_CODEC_D3D11_OPAQUE_10B))
80             continue;
81
82         if( DeviceSupportsFormat( d3ddevice, output_format->formatTexture,
83                                   supportFlags ) )
84             return output_format;
85     }
86     return NULL;
87 }
88
89 #endif /* include-guard */