1 /*
2 * Direct3D 12 HW acceleration video encoder
3 *
4 * Copyright (c) 2024 Intel Corporation
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg 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 GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #ifndef AVCODEC_D3D12VA_ENCODE_H
24 #define AVCODEC_D3D12VA_ENCODE_H
25
34
36
38
39 #define MAX_PARAM_BUFFER_SIZE 4096
40 #define D3D12VA_VIDEO_ENC_ASYNC_DEPTH 8
41
45
48
51
54
55 D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA
pic_ctl;
56
59
61 /**
62 * lavc profile value (AV_PROFILE_*).
63 */
65
66 /**
67 * Supported bit depth.
68 */
70
71 /**
72 * Number of components.
73 */
75
76 /**
77 * Chroma subsampling in width dimension.
78 */
80
81 /**
82 * Chroma subsampling in height dimension.
83 */
85
86 /**
87 * D3D12 profile value.
88 */
91
92 enum {
99 };
100
101
103 /**
104 * Mode from above enum (RC_MODE_*).
105 */
107
108 /**
109 * Name.
110 *
111 */
113
114 /**
115 * Uses bitrate parameters.
116 *
117 */
119
120 /**
121 * Supports maxrate distinct from bitrate.
122 *
123 */
125
126 /**
127 * Uses quality value.
128 *
129 */
131
132 /**
133 * Supports HRD/VBV parameters.
134 *
135 */
137
138 /**
139 * D3D12 mode value.
140 */
143
146
147 /**
148 * Codec-specific hooks.
149 */
151
152 /**
153 * Explicitly set RC mode (otherwise attempt to pick from
154 * available modes).
155 */
157
158 /**
159 * Explicitly-set QP, for use with the "qp" options.
160 * (Forces CQP mode when set, overriding everything else.)
161 */
163
164 /**
165 * RC quality level - meaning depends on codec and RC mode.
166 * In CQP mode this sets the fixed quantiser value.
167 */
169
170 /**
171 * Chosen encoding profile details.
172 */
174
176
177 /**
178 * ID3D12Device3 interface.
179 */
181
182 /**
183 * ID3D12VideoDevice3 interface.
184 */
186
187 /**
188 * Pool of (reusable) bitstream output buffers.
189 */
191
192 /**
193 * D3D12 video encoder.
194 */
196
198
199 /**
200 * D3D12 video encoder heap.
201 */
203
204 /**
205 * A cached queue for reusing the D3D12 command allocators.
206 *
207 * @see https://learn.microsoft.com/en-us/windows/win32/direct3d12/recording-command-lists-and-bundles#id3d12commandallocator
208 */
210
211 /**
212 * D3D12 command queue.
213 */
215
216 /**
217 * D3D12 video encode command list.
218 */
220
221 /**
222 * The sync context used to sync command queue.
223 */
225
226 /**
227 * The bi_not_empty feature.
228 */
230
231 /**
232 * D3D12_FEATURE structures.
233 */
234 D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOURCE_REQUIREMENTS
req;
235
236 D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOLUTION_SUPPORT_LIMITS
res_limits;
237
238 /**
239 * D3D12_VIDEO_ENCODER structures.
240 */
242
244
245 D3D12_VIDEO_ENCODER_RATE_CONTROL
rc;
246
247 D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE
gop;
248
249 D3D12_VIDEO_ENCODER_LEVEL_SETTING
level;
251
253 /**
254 * List of supported profiles.
255 */
257
258 /**
259 * D3D12 codec name.
260 */
262
263 /**
264 * Codec feature flags.
265 */
267
268 /**
269 * Default quality for this codec - used as quantiser or RC quality
270 * factor depending on RC mode.
271 */
273
274 /**
275 * Query codec configuration and determine encode parameters like
276 * block sizes for surface alignment and slices. If not set, assume
277 * that all blocks are 16x16 and that surfaces should be aligned to match
278 * this.
279 */
281
282 /**
283 * Perform any extra codec-specific configuration.
284 */
286
287 /**
288 * Set codec-specific level setting.
289 */
291
292 /**
293 * The size of any private data structure associated with each
294 * picture (can be zero if not required).
295 */
297
298 /**
299 * Fill the corresponding parameters.
300 */
302
305
307
308 /**
309 * Write the packed header data to the provided buffer.
310 */
312 char *
data,
size_t *data_len);
314
316
319
320 #define D3D12VA_ENCODE_RC_MODE(name, desc) \
321 { #name, desc, 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_ ## name }, \
322 0, 0, FLAGS, .unit = "rc_mode" }
323 #define D3D12VA_ENCODE_RC_OPTIONS \
324 { "rc_mode",\
325 "Set rate control mode", \
326 OFFSET(common.explicit_rc_mode), AV_OPT_TYPE_INT, \
327 { .i64 = RC_MODE_AUTO }, RC_MODE_AUTO, RC_MODE_MAX, FLAGS, .unit = "rc_mode" }, \
328 { "auto", "Choose mode automatically based on other parameters", \
329 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_AUTO }, 0, 0, FLAGS, .unit = "rc_mode" }, \
330 D3D12VA_ENCODE_RC_MODE(CQP, "Constant-quality"), \
331 D3D12VA_ENCODE_RC_MODE(CBR, "Constant-bitrate"), \
332 D3D12VA_ENCODE_RC_MODE(VBR, "Variable-bitrate"), \
333 D3D12VA_ENCODE_RC_MODE(QVBR, "Quality-defined variable-bitrate")
334
335 #endif /* AVCODEC_D3D12VA_ENCODE_H */