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 <vlc_codec.h>
32 DEFINE_GUID(GUID_CONTEXT_MUTEX
, 0x472e8835, 0x3f8e, 0x4f93, 0xa0, 0xcb, 0x25, 0x79, 0x77, 0x6c, 0xed, 0x86);
34 /* see https://msdn.microsoft.com/windows/hardware/commercialize/design/compatibility/device-graphics
35 * https://docs.microsoft.com/en-us/windows-hardware/drivers/display/wddm-2-1-features#driver-versioning
36 * https://www.intel.com/content/www/us/en/support/articles/000005654/graphics-drivers.html
40 int wddm
, d3d_features
, revision
, build
;
45 ID3D11Device
*d3ddevice
; /* D3D device */
46 ID3D11DeviceContext
*d3dcontext
; /* D3D context */
49 struct wddm_version WDDM
;
50 D3D_FEATURE_LEVEL feature_level
;
51 DXGI_ADAPTER_DESC adapterDesc
;
54 /* owned by the vout for VLC_CODEC_D3D11_OPAQUE */
58 ID3D11Texture2D
*texture
[DXGI_MAX_SHADER_VIEW
];
59 ID3D11Resource
*resource
[DXGI_MAX_SHADER_VIEW
];
62 ID3D11VideoProcessorInputView
*processorInput
; /* when used as processor input */
63 ID3D11VideoProcessorOutputView
*processorOutput
; /* when used as processor output */
64 ID3D11ShaderResourceView
*renderSrc
[DXGI_MAX_SHADER_VIEW
];
65 } picture_sys_d3d11_t
;
67 struct d3d11_pic_context
70 picture_sys_d3d11_t picsys
;
75 d3d11_device_t d3d_dev
;
76 } d3d11_decoder_device_t
;
81 } d3d11_video_context_t
;
83 /* index to use for texture/resource that use a known DXGI format
84 * (ie not DXGI_FORMAT_UNKNWON) */
85 #define KNOWN_DXGI_INDEX 0
87 static inline bool is_d3d11_opaque(vlc_fourcc_t chroma
)
89 return chroma
== VLC_CODEC_D3D11_OPAQUE
||
90 chroma
== VLC_CODEC_D3D11_OPAQUE_10B
||
91 chroma
== VLC_CODEC_D3D11_OPAQUE_RGBA
||
92 chroma
== VLC_CODEC_D3D11_OPAQUE_BGRA
;
95 extern const struct vlc_video_context_operations d3d11_vctx_ops
;
97 picture_sys_d3d11_t
*ActiveD3D11PictureSys(picture_t
*);
99 static inline d3d11_decoder_device_t
*GetD3D11OpaqueDevice(vlc_decoder_device
*device
)
101 if (device
== NULL
|| device
->type
!= VLC_DECODER_DEVICE_D3D11VA
)
103 return device
->opaque
;
106 static inline d3d11_decoder_device_t
*GetD3D11OpaqueContext(vlc_video_context
*vctx
)
108 vlc_decoder_device
*device
= vctx
? vlc_video_context_HoldDevice(vctx
) : NULL
;
109 if (unlikely(device
== NULL
))
111 d3d11_decoder_device_t
*res
= NULL
;
112 if (device
->type
== VLC_DECODER_DEVICE_D3D11VA
)
114 assert(device
->opaque
!= NULL
);
115 res
= GetD3D11OpaqueDevice(device
);
117 vlc_decoder_device_Release(device
);
121 static inline d3d11_video_context_t
*GetD3D11ContextPrivate(vlc_video_context
*vctx
)
123 return (d3d11_video_context_t
*) vlc_video_context_GetPrivate( vctx
, VLC_VIDEO_CONTEXT_D3D11VA
);
126 vlc_video_context
*D3D11CreateVideoContext(vlc_decoder_device
*, DXGI_FORMAT
);
128 void AcquireD3D11PictureSys(picture_sys_d3d11_t
*p_sys
);
130 void ReleaseD3D11PictureSys(picture_sys_d3d11_t
*p_sys
);
132 /* map texture planes to resource views */
133 int D3D11_AllocateResourceView(vlc_object_t
*obj
, ID3D11Device
*d3ddevice
,
134 const d3d_format_t
*format
,
135 ID3D11Texture2D
*p_texture
[DXGI_MAX_SHADER_VIEW
], UINT slice_index
,
136 ID3D11ShaderResourceView
*output
[DXGI_MAX_SHADER_VIEW
]);
137 #define D3D11_AllocateResourceView(a,b,c,d,e,f) D3D11_AllocateResourceView(VLC_OBJECT(a),b,c,d,e,f)
139 d3d11_decoder_device_t
*D3D11_CreateDevice(vlc_object_t
*obj
, IDXGIAdapter
*,
140 bool hw_decoding
, bool forced
);
141 #define D3D11_CreateDevice(a,b,c,d) D3D11_CreateDevice( VLC_OBJECT(a), b, c, d )
143 void D3D11_ReleaseDevice(d3d11_decoder_device_t
*);
145 void D3D11_LogResources(d3d11_decoder_device_t
*);
147 bool isXboxHardware(const d3d11_device_t
*);
148 IDXGIAdapter
*D3D11DeviceAdapter(ID3D11Device
*d3ddev
);
149 int D3D11CheckDriverVersion(const d3d11_device_t
*, UINT vendorId
,
150 const struct wddm_version
*min_ver
);
152 bool D3D11_DeviceSupportsFormat(d3d11_device_t
*, DXGI_FORMAT
, UINT supportFlags
);
154 const d3d_format_t
*FindD3D11Format(vlc_object_t
*,
156 vlc_fourcc_t i_src_chroma
,
158 uint8_t bits_per_channel
,
159 uint8_t widthDenominator
,
160 uint8_t heightDenominator
,
163 #define FindD3D11Format(a,b,c,d,e,f,g,h,i) \
164 FindD3D11Format(VLC_OBJECT(a),b,c,d,e,f,g,h,i)
166 int AllocateTextures(vlc_object_t
*, d3d11_device_t
*, const d3d_format_t
*,
167 const video_format_t
*, ID3D11Texture2D
*textures
[],
169 #define AllocateTextures(a,b,c,d,e,f) AllocateTextures(VLC_OBJECT(a),b,c,d,e,f)
171 static inline void d3d11_device_lock(d3d11_device_t
*d3d_dev
)
173 if( d3d_dev
->context_mutex
!= INVALID_HANDLE_VALUE
)
174 WaitForSingleObjectEx( d3d_dev
->context_mutex
, INFINITE
, FALSE
);
177 static inline void d3d11_device_unlock(d3d11_device_t
*d3d_dev
)
179 if( d3d_dev
->context_mutex
!= INVALID_HANDLE_VALUE
)
180 ReleaseMutex( d3d_dev
->context_mutex
);
183 void d3d11_pic_context_destroy(picture_context_t
*);
184 picture_context_t
*d3d11_pic_context_copy(picture_context_t
*);
186 picture_t
*D3D11_AllocPicture(vlc_object_t
*,
187 const video_format_t
*, vlc_video_context
*, const d3d_format_t
*);
189 #endif /* include-guard */