mux: mp4: rework fast start
[vlc.git] / modules / video_chroma / d3d11_fmt.h
blob115ce4840610fbb662f138070b34b67cadcff21a
1 /*****************************************************************************
2 * d3d11_fmt.h : D3D11 helper calls
3 *****************************************************************************
4 * Copyright © 2017 VLC authors, VideoLAN and VideoLabs
6 * Authors: Steve Lhomme <robux4@gmail.com>
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.
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.
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 *****************************************************************************/
23 #ifndef VLC_VIDEOCHROMA_D3D11_FMT_H_
24 #define VLC_VIDEOCHROMA_D3D11_FMT_H_
26 #include <d3d11.h>
27 #include <d3dcompiler.h>
29 #include "dxgi_fmt.h"
31 DEFINE_GUID(GUID_CONTEXT_MUTEX, 0x472e8835, 0x3f8e, 0x4f93, 0xa0, 0xcb, 0x25, 0x79, 0x77, 0x6c, 0xed, 0x86);
33 /* see https://msdn.microsoft.com/windows/hardware/commercialize/design/compatibility/device-graphics */
34 struct wddm_version
36 int wddm, d3d_features, revision, build;
39 typedef struct
41 ID3D11Device *d3ddevice; /* D3D device */
42 ID3D11DeviceContext *d3dcontext; /* D3D context */
43 bool owner;
44 HANDLE context_mutex;
45 struct wddm_version WDDM;
46 D3D_FEATURE_LEVEL feature_level;
47 } d3d11_device_t;
49 typedef struct
51 #if !VLC_WINSTORE_APP
52 HINSTANCE hdll; /* handle of the opened d3d11 dll */
53 HINSTANCE compiler_dll; /* handle of the opened d3dcompiler dll */
54 pD3DCompile OurD3DCompile;
55 #if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
56 HINSTANCE dxgidebug_dll;
57 #endif
58 #endif
59 } d3d11_handle_t;
61 /* owned by the vout for VLC_CODEC_D3D11_OPAQUE */
62 typedef struct
64 ID3D11VideoDecoderOutputView *decoder; /* may be NULL for pictures from the pool */
65 union {
66 ID3D11Texture2D *texture[D3D11_MAX_SHADER_VIEW];
67 ID3D11Resource *resource[D3D11_MAX_SHADER_VIEW];
69 ID3D11DeviceContext *context;
70 unsigned slice_index;
71 ID3D11VideoProcessorInputView *processorInput; /* when used as processor input */
72 ID3D11VideoProcessorOutputView *processorOutput; /* when used as processor output */
73 ID3D11ShaderResourceView *renderSrc[D3D11_MAX_SHADER_VIEW];
74 DXGI_FORMAT formatTexture;
75 } picture_sys_t;
77 #include "../codec/avcodec/va_surface.h"
79 static inline picture_sys_t *ActivePictureSys(picture_t *p_pic)
81 struct va_pic_context *pic_ctx = (struct va_pic_context*)p_pic->context;
82 return pic_ctx ? &pic_ctx->picsys : p_pic->p_sys;
85 /* index to use for texture/resource that use a known DXGI format
86 * (ie not DXGI_FORMAT_UNKNWON) */
87 #define KNOWN_DXGI_INDEX 0
89 static inline bool is_d3d11_opaque(vlc_fourcc_t chroma)
91 return chroma == VLC_CODEC_D3D11_OPAQUE ||
92 chroma == VLC_CODEC_D3D11_OPAQUE_10B ||
93 chroma == VLC_CODEC_D3D11_OPAQUE_RGBA ||
94 chroma == VLC_CODEC_D3D11_OPAQUE_BGRA;
97 void AcquirePictureSys(picture_sys_t *p_sys);
99 void ReleasePictureSys(picture_sys_t *p_sys);
101 /* map texture planes to resource views */
102 int D3D11_AllocateResourceView(vlc_object_t *obj, ID3D11Device *d3ddevice,
103 const d3d_format_t *format,
104 ID3D11Texture2D *p_texture[D3D11_MAX_SHADER_VIEW], UINT slice_index,
105 ID3D11ShaderResourceView *output[D3D11_MAX_SHADER_VIEW]);
106 #define D3D11_AllocateResourceView(a,b,c,d,e,f) D3D11_AllocateResourceView(VLC_OBJECT(a),b,c,d,e,f)
108 HRESULT D3D11_CreateDevice(vlc_object_t *obj, d3d11_handle_t *,
109 bool hw_decoding, d3d11_device_t *out);
110 #define D3D11_CreateDevice(a,b,c,d) D3D11_CreateDevice( VLC_OBJECT(a), b, c, d )
112 void D3D11_ReleaseDevice(d3d11_device_t *);
114 int D3D11_Create(vlc_object_t *, d3d11_handle_t *, bool with_shaders);
115 #define D3D11_Create(a,b,c) D3D11_Create( VLC_OBJECT(a), b, c )
117 void D3D11_Destroy(d3d11_handle_t *);
119 bool isXboxHardware(ID3D11Device *d3ddev);
120 bool CanUseVoutPool(d3d11_device_t *, UINT slices);
121 IDXGIAdapter *D3D11DeviceAdapter(ID3D11Device *d3ddev);
122 int D3D11CheckDriverVersion(d3d11_device_t *, UINT vendorId,
123 const struct wddm_version *min_ver);
124 void D3D11_GetDriverVersion(vlc_object_t *, d3d11_device_t *);
125 #define D3D11_GetDriverVersion(a,b) D3D11_GetDriverVersion(VLC_OBJECT(a),b)
127 static inline bool DeviceSupportsFormat(ID3D11Device *d3ddevice,
128 DXGI_FORMAT format, UINT supportFlags)
130 UINT i_formatSupport;
131 return SUCCEEDED( ID3D11Device_CheckFormatSupport(d3ddevice, format,
132 &i_formatSupport) )
133 && ( i_formatSupport & supportFlags ) == supportFlags;
136 const d3d_format_t *FindD3D11Format(vlc_object_t *,
137 d3d11_device_t*,
138 vlc_fourcc_t i_src_chroma,
139 bool rgb_only,
140 uint8_t bits_per_channel,
141 uint8_t widthDenominator,
142 uint8_t heightDenominator,
143 bool allow_opaque,
144 UINT supportFlags);
145 #define FindD3D11Format(a,b,c,d,e,f,g,h,i) \
146 FindD3D11Format(VLC_OBJECT(a),b,c,d,e,f,g,h,i)
148 int AllocateTextures(vlc_object_t *, d3d11_device_t *, const d3d_format_t *,
149 const video_format_t *, unsigned pool_size, ID3D11Texture2D *textures[]);
150 #define AllocateTextures(a,b,c,d,e,f) AllocateTextures(VLC_OBJECT(a),b,c,d,e,f)
152 static inline void d3d11_device_lock(d3d11_device_t *d3d_dev)
154 if( d3d_dev->context_mutex != INVALID_HANDLE_VALUE )
155 WaitForSingleObjectEx( d3d_dev->context_mutex, INFINITE, FALSE );
158 static inline void d3d11_device_unlock(d3d11_device_t *d3d_dev)
160 if( d3d_dev->context_mutex != INVALID_HANDLE_VALUE )
161 ReleaseMutex( d3d_dev->context_mutex );
164 #endif /* include-guard */