Debian Codegraph @

src/nouveau/headers/nvidia/video/nvenc_drv.h

raw
1 /*
2 * SPDX-FileCopyrightText: Copyright (c) 1993-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: MIT
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #ifndef NVENC_DRV_H
25 #define NVENC_DRV_H
26 //
27 // CLASS NV_C9B7_NVENC
28 // ===================
29 //
30 //
31 // 1 - INTRODUCTION
32 //
33 // The NVENC is a video encoder engine. Currently only H.264 baseline, main
34 // and high profile are supported. For baseline, only 1 slicegroup is allowed.
35 // NVENC has built-in motion estimation that enables it to do encode on its own
36 // but also has the ability to work with external hints that could be produced
37 // by another motion search implementation such as CEA.<br>
38 // NVENC motion search is divided into a simple integer search module and a high
39 // perf subpel refinement module. The integer search capability of NVENC is
40 // limited (perf wise) so for higher perf the CEA approach should be used.
41 // Motion search/estimation (ME) results in a set of vectors with scores
42 // which it will evaluate for encoding cost and eligibility. It also searches
43 // intra encoding modes for the lowest cost encoding, picks a final winner
44 // from all inter and intra modes that have been evaluated and encodes the
45 // macroblock according to that mode. Skip and direct modes are also checked.
46 // Search and encoding involve forward dct and quantization, inverse dct and
47 // quantization, reconstruction, and optionally deblocking. Entropy encode can
48 // do either CAVLC or CABAC.
49 //
50 //
51 // 1.4. CLASS OPERATION
52 // ------------------------
53 //
54 // *** TBD ***
55 //
56 // If MVC is enabled, HW need to write the prefix NAL unit(14) when current view is a base view.
57 // As SVC is not supported in nvenc, so svc_extension_flag should be always false. Then, in the prefix NAL unit,
58 // only the syntax elements(H.7.3.1.1 NAL unit header MVC extension syntax) in the prefix NAL unit should be written:
59 // nal_unit_header_mvc_extension( ) {
60 // non_idr_flag
61 // priority_id
62 // view_id
63 // temporal_id
64 // anchor_pic_flag
65 // inter_view_flag
66 // reserved_one_bit
67 // }
68 //
69 // 1.5. RESTRICTIONS
70 // ------------------------
71 //
72 // (1) Reference pictures to be accessed by NVENC must be in tiled 16x16 format
73 // (2) Input pictures are either all in BL format or all in tiled 16x16 format
74 // (3) Input pictures and reference pictures must be of the kind specified by
75 // 'pic_struct' (either fields or frames). NVENC cannot encode an interlaced
76 // input picture (2 fields) as a frame or vice versa, and cannot use frame
77 // reference pictures when encoding a field picture, or field reference
78 // pictures when encoding a frame.
79 //
80 //
81 //
82 // 2 - APPLICATION MEMORY STRUCTURES
83 //
84 // 2.1. DRV PICTURE SETUP BUFFER
85 // -----------------------------
86 //
87 // DrvPictureSetupBuffer contains sequence, picture, and slice level control
88 // data required for encoding.
89 //
90 // Input pictures (to be encoded) can be any size (HxV) but the encoded output
91 // is always an integer number of macroblocks high and wide, which means that
92 // H and V are rounded up to the next multiple of 16 (H'xV') and all pixels
93 // within this range are used to encode the macroblocks. NVENC does not clear,
94 // pad, duplicate or otherwise modify any pixels values within the H'xV' sized
95 // input picture contained in the input surface.
96 // The values for frame/pic_width_minus1 and frame/pic_height_minus1 contained
97 // in the config structures are the original width and height (display size)
98 // of the pictures, and from this the nvenc app will derive the cropping
99 // information. Cropping will only be done on the right and bottom side of the
100 // picture.
101
102 typedef struct
103 {
104 unsigned int luma_log2_weight_denom : 3; // the base 2 logarithm of the denominator for all luma weighting factors. The value of luma_log2_weight_denom shall be in the range of 0 to 7, inclusive
105 unsigned int chroma_log2_weight_denom : 3; // the base 2 logarithm of the denominator for all chroma weighting factors. The value of chroma_log2_weight_denom shall be in the range of 0 to 7, inclusive.
106 unsigned int reversed : 26;
107
108 unsigned char luma_weight_l0_flag[16]; // equal to 1 specifies that weighting factors for the luma component of list 0 prediction are present, luma_weight_l0_flag[8~15] not used now
109 unsigned char chroma_weight_l0_flag[16]; // equal to 1 specifies that weighting factors for the chroma prediction values of list 0 prediction are present, chroma_weight_l0_flag[8~15] not used now
110
111 unsigned char luma_weight_l1_flag[16]; // have the same semantics as luma_weight_l0_flag, chroma_weight_l0_flag, not used now
112 unsigned char chroma_weight_l1_flag[16]; // not used now
113
114 short luma_weight_l0[16]; // is the weighting factor applied to the luma prediction value for list 0 prediction using RefPicList0[ i ]. When luma_weight_l0_flag is equal to 1, the value of luma_weight_l0[ i ] shall be in the range of -128 to 127, inclusive. -128 to 255 for H265
115 short luma_offset_l0[16]; // is the additive offset applied to the luma prediction value for list 0 prediction using RefPicList0[ i ]. The value of luma_offset_l0[ i ] shall be in the range of -128 to 127, inclusive. -2^9 to 2^9-1 for h265
116 short luma_weight_l1[16]; // is the weighting factor applied to the luma prediction value for list 0 prediction using RefPicList0[ i ]. When luma_weight_l0_flag is equal to 1, the value of luma_weight_l0[ i ] shall be in the range of -128 to 127, inclusive. -128 to 255 for H265
117 short luma_offset_l1[16]; // is the additive offset applied to the luma prediction value for list 0 prediction using RefPicList0[ i ]. The value of luma_offset_l0[ i ] shall be in the range of -128 to 127, inclusive. -2^9 to 2^9-1 for h265
118 short chroma_weight_l0[2][16]; // has the similar meaning with luma_weight/offset
119 short chroma_offset_l0[2][16]; // has the similar meaning with luma_weight/offset
120 short chroma_weight_l1[2][16]; // has the similar meaning with luma_weight/offset
121 short chroma_offset_l1[2][16]; // has the similar meaning with luma_weight/offset
122
123 } nvenc_pred_weight_table_s; // 452 bytes
124
125 typedef struct
126 {
127 unsigned short frame_width_minus1; // frame width in pixels minus 1, range 0-4095
128 unsigned short frame_height_minus1; // frame height in pixels minus 1, range 0-4095
129 unsigned short sfc_pitch; // pitch of luma plane
130 unsigned short sfc_pitch_chroma; // pitch of chroma plane
131 unsigned short sfc_trans_mode; // least 3 significient bits are used to stand for 8 modes, normal, xflip, yflip etc.
132 unsigned short reserved2; // pad to int
133
134 // do not use offset from cmod trace as golden, cmod behavior is different.
135 unsigned int luma_top_frm_offset; // offset of luma top field or frame in units of 256
136 unsigned int luma_bot_offset; // offset of luma bottom field in units of 256. Not used if frame format.
137 unsigned int chroma_top_frm_offset; // offset of chroma top field or frame, or offset of chroma U(Cb) plane in planar mode, both in units of 256
138 unsigned int chroma_bot_offset; // offset of chroma bottom field, not used if frame format. Or offset of chroma V(Cr) plane in planar mode. Both in units of 256.
139 unsigned int block_height : 7; // BL mapping block height setting
140 unsigned int tiled_16x16 : 1; // Surface is 16x16 tiled instead of BL mapped (must be 1 for refpics)
141 unsigned int memory_mode : 2; // 0: semi-planar, 1: planar
142 unsigned int nv21_enable : 1; // the surface format is yuv or yvu
143 unsigned int input_bl_mode : 2; // the input block linear mode: 0~gpu bl; 1~tegra bl; 2~naive bl this is only for cmod and cmod/plugin
144 unsigned int reserved : 19; // pad to NvU32
145 } nvenc_h264_surface_cfg_s; // 32 bytes
146
147 typedef struct
148 {
149 unsigned int profile_idc : 8; // seq_parameters(_ext) regs
150 unsigned int level_idc : 8;
151 unsigned int chroma_format_idc : 2; // 0=monochrome, 1=yuv4:2:0, 2-3=not supported
152 unsigned int pic_order_cnt_type : 2; // only support values 0 and 2
153 unsigned int log2_max_frame_num_minus4 : 4;
154 unsigned int log2_max_pic_order_cnt_lsb_minus4 : 4;
155 unsigned int frame_mbs_only : 1;
156 //mvc
157 unsigned int stereo_mvc_enable : 1; //if this bit is enabled, the profile_idc should be 128
158 unsigned int separate_colour_plane_flag : 1; //if this bit is enabled, the chroma_format_idc should be 3
159 unsigned int lossless_qpprime_flag : 1; //if this bit is enabled and QP=0, bypass trans/q and encoded as lossless MB (hori or vert)
160 } nvenc_h264_sps_data_s; // 4 bytes
161
162 typedef struct
163 {
164 unsigned int pic_param_set_id : 8; // picture parameter set identification
165 unsigned int entropy_coding_mode_flag : 1; // select entropy copding mode: cabac, cavlc
166 unsigned int num_ref_idx_l0_active_minus1 : 5; // number of currently active reference pictures in list 0 minus 1, range 0..30
167 unsigned int num_ref_idx_l1_active_minus1 : 5; // number of currently active reference pictures in list 1 minus 1, range 0..30
168 unsigned int weighted_bipred_idc : 2; // weighted prediction mode for B: only 0 (default) and 2 (implicit) are supported
169 int pic_init_qp_minus26 : 6; // initial QP value, range -26..+25
170 int chroma_qp_index_offset : 5; // offset to add to chroma QPy for QPc table indexing for Cb, range -12..+12
171
172 int second_chroma_qp_index_offset : 5; // offset to add to chroma QPy for QPc table indexing for Cr, range -12..+12
173 unsigned int constrained_intra_pred_flag : 1; // if set, intra prediction can only use pixels from macroblocks that are also intra coded
174 unsigned int deblocking_filter_control_present_flag : 1;// if set, deblock filter controls syntax elements will be present/encoded in the stream
175 unsigned int transform_8x8_mode_flag : 1; // if set, enables the use of transform size 8x8 (flags will be encoded in stream per macroblock)
176 unsigned int pic_order_present_flag : 1; // if set, pic_order control info is encoded in the stream
177 unsigned int weighted_pred_flag : 1;
178 unsigned int reserved0 : 22; // pad to full int
179 } nvenc_h264_pps_data_s; // 8 bytes
180
181 typedef struct
182 {
183 unsigned int self_temporal_stamp_l0 : 3; // stamp to use for L0 integer search in stamp based mode
184 unsigned int self_temporal_stamp_l1 : 3; // stamp to use for L1 integer search in stamp based mode
185 unsigned int self_temporal_explicit : 1; // explicitly evaluate these vectors
186 unsigned int self_temporal_search : 1; // integer search enable for this hint
187 unsigned int self_temporal_refine : 1; // subpel search enable for this hint
188 unsigned int self_temporal_enable : 1; // hint enable (enables processing + fetching of data) (only changeable at first slice in picture)
189
190 unsigned int coloc_stamp_l0 : 3; // stamp to use for L0 integer search in stamp based mode
191 unsigned int coloc_stamp_l1 : 3; // stamp to use for L1 integer search in stamp based mode
192 unsigned int coloc_explicit : 1; // explicitly evaluate these vectors
193 unsigned int coloc_search : 1; // integer search enable for this hint
194 unsigned int coloc_refine : 1; // subpel search enable for this hint
195 unsigned int coloc_enable : 1; // hint enable (enables processing + fetching of data) (only changeable at first slice in picture)
196
197 unsigned int self_spatial_stamp_l0 : 3; // stamp to use for L0 integer search in stamp based mode
198 unsigned int self_spatial_stamp_l1 : 3; // stamp to use for L1 integer search in stamp based mode
199 unsigned int self_spatial_explicit : 1; // explicitly evaluate these vectors
200 unsigned int self_spatial_search : 1; // integer search enable for this hint
201 unsigned int self_spatial_refine : 1; // subpel search enable for this hint
202 unsigned int self_spatial_enable : 1; // hint enable (enables processing + fetching of data) (only changeable at first slice in picture)
203 unsigned int reserved0 : 2; // pad to full int
204
205 unsigned int external_stamp_l0_refidx0_stamp : 3; // Stamp to use for external L0 hint with refidx = 0
206 unsigned int external_stamp_l0_refidx1_stamp : 3; // Stamp to use for external L0 hint with refidx = 1
207 unsigned int external_stamp_l0_refidx2_stamp : 3; // Stamp to use for external L0 hint with refidx = 2
208 unsigned int external_stamp_l0_refidx3_stamp : 3; // Stamp to use for external L0 hint with refidx = 3
209 unsigned int external_stamp_l0_refidx4_stamp : 3; // Stamp to use for external L0 hint with refidx = 4
210 unsigned int external_stamp_l0_refidx5_stamp : 3; // Stamp to use for external L0 hint with refidx = 5
211 unsigned int external_stamp_l0_refidx6_stamp : 3; // Stamp to use for external L0 hint with refidx = 6
212 unsigned int external_stamp_l0_refidx7_stamp : 3; // Stamp to use for external L0 hint with refidx = 7
213 unsigned int external_stamp_l1_refidx0_stamp : 3; // Stamp to use for external L1 hint with refidx = 0
214 unsigned int external_stamp_l1_refidx1_stamp : 3; // Stamp to use for external L1 hint with refidx = 1
215 unsigned int reserved1 : 2; // pad to full int
216
217
218 unsigned int external_stamp_l1_refidx2_stamp : 3; // Stamp to use for external L1 hint with refidx = 2
219 unsigned int external_stamp_l1_refidx3_stamp : 3; // Stamp to use for external L1 hint with refidx = 3
220 unsigned int external_stamp_l1_refidx4_stamp : 3; // Stamp to use for external L1 hint with refidx = 4
221 unsigned int external_stamp_l1_refidx5_stamp : 3; // Stamp to use for external L1 hint with refidx = 5
222 unsigned int external_stamp_l1_refidx6_stamp : 3; // Stamp to use for external L1 hint with refidx = 6
223 unsigned int external_stamp_l1_refidx7_stamp : 3; // Stamp to use for external L1 hint with refidx = 7
224
225
226 unsigned int external_explicit : 1; // explicitly evaluate these vectors
227 unsigned int external_search : 1; // integer search enable for this hint
228 unsigned int external_refine : 1; // subpel search enable for this hint
229 unsigned int external_enable : 1; // hint enable (enables processing + fetching of data) (only changeable at first slice in picture)
230
231 unsigned int const_mv_stamp_l0 : 3; // stamp to use for L0 integer search in stamp based mode
232 unsigned int const_mv_stamp_l1 : 3; // stamp to use for L1 integer search in stamp based mode
233 unsigned int const_mv_explicit : 1; // explicitly evaluate these vectors
234 unsigned int const_mv_search : 1; // integer search enable for this hint
235 unsigned int const_mv_refine : 1; // subpel search enable for this hint
236 unsigned int const_mv_enable : 1; // hint enable (enables processing + fetching of data)
237
238 unsigned int stamp_refidx1_stamp : 3; // Stamp to use for multi-ref hint with refidx = 1
239 unsigned int stamp_refidx2_stamp : 3; // Stamp to use for multi-ref hint with refidx = 2
240 unsigned int stamp_refidx3_stamp : 3; // Stamp to use for multi-ref hint with refidx = 3
241 unsigned int stamp_refidx4_stamp : 3; // Stamp to use for multi-ref hint with refidx = 4
242 unsigned int stamp_refidx5_stamp : 3; // Stamp to use for multi-ref hint with refidx = 5
243 unsigned int stamp_refidx6_stamp : 3; // Stamp to use for multi-ref hint with refidx = 6
244 unsigned int stamp_refidx7_stamp : 3; // Stamp to use for multi-ref hint with refidx = 7
245 unsigned int reserved2 : 11; // pad to full int
246
247 } nvenc_h264_me_hint_cfg_s; //16 bytes
248
249 typedef struct
250 {
251 unsigned int mvx_frac : 2; // vector X component fraction
252 int mvx_int : 12; // vector X component integer portion
253 unsigned int reserved_x : 2; // padding X to 16 bit
254 unsigned int mvy_frac : 2; // vector Y component fraction
255 int mvy_int : 10; // vector Y component integer portion
256 unsigned int reserved_y : 4; // padding Y to 16 bit
257 } nvenc_h264_me_const_vec_s; // 4 bytes
258
259 typedef struct
260 {
261 unsigned int bitmask[2] ; // 8x8 search point pattern bitmask
262 unsigned int hor_adjust : 1; // shift hor based on lsb of pred
263 unsigned int ver_adjust : 1; // shift ver based on lsb of pred
264 unsigned int reserved : 30;
265 } nvenc_h264_me_stamp_s; // 12 bytes
266
267 typedef struct
268 {
269 unsigned int mv_limit_enable : 1; // 0=disable, 1=enable set the absolute MV range (Cisco flip camera request)
270 unsigned int left_mvx_frac : 2; // vector X component fraction
271 int left_mvx_int : 12; // vector X component integer portion
272 unsigned int reserved1 : 1; // padding X to 16 bit
273 unsigned int top_mvy_frac : 2; // vector Y component fraction
274 int top_mvy_int : 10; // vector Y component integer portion
275 unsigned int reserved2 : 4; // padding Y to 16 bit
276
277 unsigned int right_mvx_frac : 2; // vector X component fraction
278 int right_mvx_int : 12; // vector X component integer portion
279 unsigned int reserved3 : 2; // padding X to 16 bit
280 unsigned int bottom_mvy_frac : 2; // vector Y component fraction
281 int bottom_mvy_int : 10; // vector Y component integer portion
282 unsigned int reserved4 : 4; // padding Y to 16 bit
283 } nvenc_h264_me_limit_mv_s; // 8 bytes
284
285 typedef struct
286 {
287 unsigned char teb_K ; // TEB K
288 unsigned char teb_N ; // TEB N
289 unsigned char teb_P ; // TEB P
290 unsigned char teb_S : 4; // TEB S
291 unsigned char teb_mode : 4; // TEB mode
292 } nvenc_me_tebif_s;
293
294 typedef struct
295 {
296 unsigned int me_predictor_mode : 1; // 0=MDP, 1=const
297 unsigned int refinement_mode : 1; // 0=hpel, 1=qpel
298 unsigned int lambda_mode : 1; // 0=MDP, 1=const
299 unsigned int const_lambda : 11; // U8.3 format lambda, used if lambda_mode=1
300 unsigned int refine_on_search_enable : 1; // 0=disable, 1=enable subpel refine for search candidates
301 unsigned int me_only_mode : 1;
302 unsigned int fps_mvcost : 1;
303 unsigned int sps_mvcost : 1;
304 unsigned int sps_cost_func : 1;
305 unsigned int me_icc_mode_mad : 1;
306
307 unsigned int sps_filter : 3;
308 unsigned int mc_filter : 3;
309 unsigned int vc1_fastuv_mc : 1;
310 unsigned int vc1_mc_rnd : 1;
311 unsigned int mbc_ctrl_arbitor : 2;
312 unsigned int mv_only_enable : 1;
313 unsigned int average_mvhint_enable : 1;
314
315 nvenc_h264_me_limit_mv_s limit_mv;
316 nvenc_h264_me_hint_cfg_s predsrc; // predictor sources
317 nvenc_h264_me_const_vec_s l0_hint; // constant MV used as L0 hint
318 nvenc_h264_me_const_vec_s l1_hint; // constant MV used as L1 hint
319 nvenc_h264_me_const_vec_s l0_pred; // constant MV used as L0 predictor
320 nvenc_h264_me_const_vec_s l1_pred; // constant MV used as L1 predictor
321 nvenc_h264_me_stamp_s shape0; // priority 0 stamping pattern
322 nvenc_h264_me_stamp_s shape1; // priority 1 stamping pattern
323 nvenc_h264_me_stamp_s shape2; // priority 2 stamping pattern
324 nvenc_h264_me_stamp_s shape3; // priority 3 stamping pattern
325 nvenc_h264_me_stamp_s shape4; // priority 4 stamping pattern
326 nvenc_h264_me_stamp_s shape5; // priority 5 stamping pattern
327 nvenc_h264_me_stamp_s shape6; // priority 6 stamping pattern
328 nvenc_h264_me_stamp_s shape7; // priority 7 stamping pattern
329 nvenc_me_tebif_s teb_para; // TEB parameter
330 unsigned int mbc_mb_size : 9; // MBC size in MB
331 unsigned int rmvp_source_half_scaled : 1; // only support picture size half scale down in horz&vert
332 unsigned int partDecisionMadeByFPP : 1; // enable CU32 FPP;
333 unsigned int penalty_factor_FPP : 6; // MV with cost no larger than min_cost + ((min_cost * factor) >> 8) will go to SPS, not used from nvenc7
334 unsigned int spatial_hint_pattern : 4;
335 unsigned int temporal_hint_pattern : 6;
336 unsigned int Cu16partDecisionMadeByFPP : 1; // enable CU16 making part decision
337 unsigned int sps_mvp_from_fbm : 1; //1:sps use fbm'MVP and lambda;0:based on me_predictor_mode and lambda_mode to set the mvp and lambda for sps
338 unsigned int fbm_select_best_cu16_parttype_num : 3; // #winner partitions selected for cu16x16. valid range is 0~7;
339 unsigned int fbm_op_winner_num_p_frame : 3; // FBM output number of integer winners for each PU. when fbm_op_winner_num_p_frame_cu8 has non-zero value, this field means the PU winners for CU64~CU16, i.e. w/o CU8
340 unsigned int fbm_op_winner_num_b_frame_l0 : 3; // FBM output number of integer winners for each PU
341 unsigned int fbm_op_winner_num_b_frame_l1 : 3; // FBM output number of integer winners for each PU
342 unsigned int fbm_select_best_cu32_parttype_num : 3; // cu32 select best parttype num
343 unsigned int sps_evaluate_merge_cand_num : 3; // number of merg candidate for sps to explicit evaluate
344 unsigned int fps_quad_thresh_hold : 10;
345 unsigned int external_hint_order : 1; //0:Insert external hint at first ref; 1:insert external hint at last ref;
346 unsigned int coloc_hint_order : 1; //0:Insert coloc hint at first ref; 1: insert coloc hint at last ref.
347 unsigned int reserved1 : 5;
348 short ct_threshold ; // for OFS only, threshold in Census Transform calculation
349 //(1<<hint_type0)|(1<<hint_type1)|(1<<hint_type2)|(1<<hint_type3)|(1<<hint_type4) should be equal to 0x1f
350 unsigned short hint_type0 : 3; //0:const hint; 1:spatial hint; 2:temporal hint; 3:coloc hint; 4:external hint
351 unsigned short hint_type1 : 3; //the same as hint_type0
352 unsigned short hint_type2 : 3; //the same as hint_type0
353 unsigned short hint_type3 : 3; //the same as hint_type0
354 unsigned short hint_type4 : 3; //the same as hint_type0
355 unsigned short pyramidal_hint_order : 1; // for OFS only, used when do pyramidal ME, 1: enable, the hint order will be: if one MB has external hint, use exhint, otherwise use spatial/temproal/const hints. 0: disable.
356 unsigned char left_hint_delay_N : 4; // for OFS only, specify left hint delay MB number(1~8), used for high-perf mode (left_hint_delay_N need to set to 8 to achieve 4K@120FPS). set 0 for using default value, ie 3 for ofs/H265, 8 for H264
357 unsigned char reserved3 : 4;
358
359 unsigned char cu8partDecisionMadeByFPP : 1; //enable CU8x8 partition selection in FBM
360 unsigned char fbm_select_best_cu8_parttype_num : 3; //#winner partitions selected for cu8x8. valid range is 0~7;
361 unsigned char fbm_op_winner_num_p_frame_cu8 : 3; // FBM output number of integer winners for each PU of CU size 8.
362 unsigned char reserved4 : 1;
363
364 unsigned char cu64partDecisionMadeByFPP : 1; //enable CU64x64 partition selection in FBM
365 unsigned char fbm_select_best_cu64_parttype_num : 3; //#winner partitions selected for cu64x64. valid range is 0~7;
366 unsigned char reserved5 : 4;
367
368 unsigned char reserved[33]; // padding to make me_control=192 to allow 3 reads of 64 in ucode
369 // this is optimal size as 160=5 reads of 32 will exceed dma queue
370 } nvenc_h264_me_control_s; // 192 bytes
371
372 typedef struct
373 {
374 unsigned short intra_refresh_cnt; // distance between forced-intra MBs in slice; 0 means OFF
375 unsigned short intra_refresh_offs; // first forced-intra MB in slice
376
377 unsigned int intra_luma4x4_mode_enable : 9; // bitmask indicating which intra luma 4x4 modes to enable
378 unsigned int intra_luma8x8_mode_enable : 9; // bitmask indicating which intra luma 8x8 modes to enable
379 unsigned int intra_luma16x16_mode_enable : 4; // bitmask indicating which intra luma 16x16 modes to enable
380 unsigned int intra_chroma_mode_enable : 4; // bitmask indicating which intra chroma modes to enable
381 unsigned int inter_penalty_factor_for_ip1 : 6; // early teminate ip1 intra search if intra cost is larger than inter_cost + ((inter_cost * factor) >> 8)
382
383 unsigned int l0_part_16x16_enable : 1; // enable L0 prediction for 16x16
384 unsigned int l0_part_16x8_enable : 1; // enable L0 prediction for 16x8
385 unsigned int l0_part_8x16_enable : 1; // enable L0 prediction for 8x16
386 unsigned int l0_part_8x8_enable : 1; // enable L0 prediction for 8x8
387 unsigned int l0_part_8x4_enable : 1; // enable L0 prediction for 8x4
388 unsigned int l0_part_4x8_enable : 1; // enable L0 prediction for 4x8
389 unsigned int l0_part_4x4_enable : 1; // enable L0 prediction for 4x4
390 unsigned int l0_part_reserved : 1; // reserved for future L0 prediction extensions
391 unsigned int l1_part_16x16_enable : 1; // enable L1 prediction for 16x16
392 unsigned int l1_part_16x8_enable : 1; // enable L1 prediction for 16x8
393 unsigned int l1_part_8x16_enable : 1; // enable L1 prediction for 8x16
394 unsigned int l1_part_8x8_enable : 1; // enable L1 prediction for 8x8
395 unsigned int l1_part_reserved : 4; // reserved for future L1 prediction extensions
396 unsigned int bi_part_16x16_enable : 1; // enable Bi prediction for 16x16
397 unsigned int bi_part_16x8_enable : 1; // enable Bi prediction for 16x8
398 unsigned int bi_part_8x16_enable : 1; // enable Bi prediction for 8x16
399 unsigned int bi_part_8x8_enable : 1; // enable Bi prediction for 8x8
400 unsigned int bi_part_reserved : 4; // reserved for future Bi prediction extensions
401 unsigned int bdirect_mode : 2; // 0: disable, 1: spatial, 2: temporal
402 unsigned int bskip_enable : 1; // enable b_skip encoding (requires b_direct encoding)
403 unsigned int pskip_enable : 1; // enable p_skip encoding
404 unsigned int special_reserved : 4; // reserved for future special prediction extensions
405
406 short bias_inter_16x16; // bias for inter 16x16 (subtracts from inter 16x16 cost)
407 short bias_inter_16x8; // bias for inter 16x8 (subtracts from inter 16x8 cost)
408
409 short bias_inter_8x16; // bias for inter 8x16 (subtracts from inter 8x16 cost)
410 short bias_inter_8x8; // bias for inter 8x8 (subtracts from inter 8x8 cost)
411
412 short bias_pskip; // bias for skip (subtracts from skip cost)
413 short bias_bdir; // bias for bdirect (subtracts from bdirect cost)
414
415 short bias_intra_over_inter; // bias for any intra (subtracts from intra cost)
416 short bias_intra_16x16; // bias for intra 16x16 (subtracts from intra 16x16 cost)
417
418 short bias_intra_8x8; // bias for intra 8x8 (subtracts from intra 8x8 cost)
419 short bias_intra_4x4; // bias for intra 4x4 (subtracts from intra 4x4 cost)
420
421 short bias_intra_most_prob; // bias for intra most probable mode
422 unsigned short mv_cost_bias; // bias applied to internal motion vector cost calculation
423
424 unsigned short intra_nxn_bias_multiplier; // 0..255 range; used for internal bias calculation
425 unsigned short intra_most_prob_bias_multiplier; // 0..31 range; used for internal bias calculation
426
427 short pskip_bias_multiplier; // S16 range; used for internal bias calculation
428 short bdirect_bias_multiplier; // S16 range; used for internal bias calculation
429
430 unsigned short pskip_esc_threshold; // if pskip cost is below this, disable full search & attempt pskip encode
431 unsigned short bdirect_esc_threshold; // if bdirect cost is below this, disable full search & attempt bdirect encode
432
433 unsigned short early_intra_disable_mpeb_threshold; // if early intra cost is below this, disable full search & select intra
434 unsigned short tempmv_wt_spread_threshold; // The threshold for the sum of differences between 8x8s and 16x16 mvs. Used for temporal mv weight
435 unsigned int tempmv_wt_distort_threshold : 16; // The threshold for the cost of the 16x16 mv. Used for temporal mv weight
436 unsigned int mv_cost_predictor_control : 1; // 0=use 16x16 predictor only; 1=use accurate predictor (slower but better)
437 unsigned int mv_cost_enable : 1; // enable mv cost calculations in mode decision
438 unsigned int intra_most_prob_force_on : 1; // always evaluate most probably 4x4 or 8x8 intra mode during full search
439 unsigned int early_intra_mode_control : 2; // 0=inter; 1=eval_intra; 2=ext_hint; 3=none (low perf,best qual)
440 unsigned int early_intra_mode_type_16x16dc : 1; // evaluate 16x16dc if early_intra_mode_control==1
441 unsigned int early_intra_mode_type_16x16h : 1; // evaluate 16x16h if early_intra_mode_control==1
442 unsigned int early_intra_mode_type_16x16v : 1; // evaluate 16x16v if early_intra_mode_control==1
443 unsigned int early_ip_is_final : 1; // if set, result of early intra is final (disable full intra search)
444 unsigned int chroma_eval_mode : 1; // for intra chroma search 0 = U and V; 1 = U only
445 unsigned int ip_search_mode : 3; // which intra sizes to search before making IP decision b0=4x4,b1=8x8,b2=16x16
446 unsigned int multiply_bias_with_lambda : 1; // setting this to 1 will result in bias being multiplied by lambda
447 unsigned int force_ipcm : 1; // 0=normal encode; 1=force mpeb/mpec encode as IPCM
448 unsigned int early_termination_ip1 : 1; // enable IP1 early termination
449 short bias_favor_intra_16x16_early; // S16 range; used for internal bias calculation
450 unsigned short priority_ipred_type_ip1 : 3; // which intra type search first for early termination, must be a subset of ip_search_mode
451 unsigned short intra_ssd_cnt_4x4 : 4; // SSD cost evaluation between N top intra modes selected by satd
452 unsigned short intra_ssd_cnt_8x8 : 4; // SSD cost evaluation between N top intra modes selected by satd
453 unsigned short intra_ssd_cnt_16x16 : 4; // SSD cost evaluation between N top intra modes selected by satd
454 unsigned short skip_evaluate_enable : 1; // 0: not check skip ssd cost; 1, evaluate skip ssd cost
455 unsigned int rdo_level : 3; // 0:mode decision by satd 1:mode decision by ssd
456 unsigned int tu_search_num : 3; // tu search part num per MB
457 unsigned int luma_residual_zero_eval : 2; // luma residual zero cost evaluate, bit0:intra; bit1:inter
458 unsigned int num_1div8_lambda_ssd : 7; // number of 1/8 lambda ssd for lambda_coef delta. lambda_coef = (1+num_1div8_lambda_ssd*1/8)*lambda_ssd
459 unsigned int ofs_mvx_range : 2; // control mvx precision/range, 0: ouptput format: S10.5, range[-1024, 1023]; 1: output format: S11.4, range[-2048, 2047]; 2: output format: S12.3, range[-4096, 4095]; 3: output format: S12.2, range[-4096, 4095]
460 unsigned int reserved4 : 15; // pad to 32 bytes
461 short bias_tu_4x4; // bias for TU 4x4
462 short bias_tu_8x8; // bias for TU 8x8
463 unsigned int ssim_rdo : 2; // SSIM-RDO: 0 disable, 1: enable SW SSIM-RDO, 2: enable HW SSIM-RDO,
464 unsigned int calc_ssim : 1; // Calculate SSIM distortion: 0 disable, 1: enable. ssim_rdo = 1 => calc_ssim = 1
465 unsigned int reserved5 : 29; // reserved
466 unsigned int ssd_over_ssim_factor; // distortion ssd/ssim ratio, in U24.8 format
467 unsigned int reserved6[13]; // reserved
468 } nvenc_h264_md_control_s; // 128 bytes
469
470 typedef struct
471 {
472 unsigned short qpp_run_vector_4x4; // cost values for 4x4 transform (16 bit total vector)
473 unsigned short qpp_run_vector_8x8[3]; // cost values for 8x8 transform (48 bit total vector)
474 // 2 bits each for first 12 coefs, then 1 bit each for next 24
475 unsigned char qpp_luma8x8_cost; // luma 8x8 cost threshold, 0 = throw out all coefs, range 0-15
476 unsigned char qpp_luma16x16_cost; // luma 16x16 cost threshold, 0 = throw out all coefs, range 0-15
477 unsigned char qpp_chroma_cost; // chroma cost threshold, 0 = throw out all coefs, range 0-15
478 unsigned char qpp_mode : 2; // 0 = OFF, 1 = 8x8, 2 = 16x16_8x8
479 unsigned char reserved1 : 4; // padding
480 //add by cl
481 unsigned char quant_intra_sat_flag : 1; // 0: no saturation is applied; 1: saturation is applied
482 unsigned char quant_inter_sat_flag : 1; // 0: no saturation is applied; 1: saturation is applied
483 unsigned int quant_intra_sat_limit : 16; // quantization saturation limit for intra MB
484 unsigned int quant_inter_sat_limit : 16; // quantization saturation limit for inter MB
485 //~
486 unsigned short dz_4x4_YI[16]; // deadzone for 4x4 transform of Luma Intra
487 unsigned short dz_4x4_YP[16]; // deadzone for 4x4 transform of Luma Inter
488 unsigned short dz_4x4_CI; // deadzone for 4x4 transform of Chroma Intra
489 unsigned short dz_4x4_CP; // deadzone for 4x4 transform of Chroma Inter
490 unsigned short dz_8x8_YI[16]; // deadzone for 8x8 transform of Luma Intra, 16 values are mapped to 64 coefs
491 unsigned short dz_8x8_YP[16]; // deadzone for 8x8 transform of Luma Inter, 16 values are mapped to 64 coefs
492 unsigned int reserved2[11]; // pad to 192 bytes to allow 3 reads of 64 bytes in ucode
493 // this is optimal size as 160=5 reads of 32 will exceed dma queue
494 } nvenc_h264_quant_control_s; // 192 bytes
495
496 typedef struct
497 {
498 unsigned int reorder_l0_cmd_count : 4;
499 unsigned int reorder_l1_cmd_count : 4;
500 unsigned int mmco_cmd_count : 4;
501 unsigned int no_output_of_prior_pic_flag : 1;
502 unsigned int long_term_ref_flag : 1;
503 unsigned int reserved :18;
504 } nvenc_h264_refpic_cmd_s; // 4 bytes
505
506 typedef struct
507 {
508 // ref_pic_list_reorder_cmd includes both opcode and op arguments
509 unsigned int reordering_of_pic_nums_idc : 3; // Bit 31-29 (0-5 (Table 7-7)
510 unsigned int abs_diff_pic_num_minus1 :17; // (opcode=0/1)
511 unsigned int long_term_pic_num : 4; // (opcode=2):
512 unsigned int abs_diff_view_idx_minus1 : 4; // (opcode=4/5):
513 unsigned int reserved : 4;
514 } nvenc_h264_ref_pic_reorder_s; // 4 bytes
515
516 typedef struct
517 {
518 unsigned int mmco_cmd_id : 3; // totally 6 commands
519
520 unsigned int difference_of_pic_nums_minus1 :17; // 1) mark a short_term ref as long (mmco=3); 2) mark a short_term as un-used (mmco=1)
521 unsigned int long_term_pic_num : 3; // [0 to MaxLongTermFrameIdx ]; mark a long as "unused for ref" (mmco=2);
522 unsigned int long_term_frame_idx : 3; // [0 to MaxLongTermFrameIdx] 1) mark a picture to long (mmco=3, mmco=6)
523 unsigned int max_long_term_frame_idx_plus1 : 4; // [0, num_ref_frames] max long term frm indexes allowed for long term pictures.
524 // max_long_term_frame_idx_plus1=0 -> MaxLongTermFrameIdx="no-long-term"
525 // max_long_term_frame_idx_plus1>0 -> MaxLongTermFrameIdx= max_long_term_frame_idx_plus1-1
526 unsigned int reserved : 2;
527 } nvenc_h264_mmco_s; // 4 bytes
528
529 typedef struct
530 {
531 // int0
532 unsigned int num_mb : 19; // number of macroblocks in this slice, support upto 8kx8k
533 unsigned int qp_avr : 8; // 6bit value used by hw. Other bits can be used for rounding.
534 unsigned int reserved : 5;
535 // int1
536 unsigned int slice_tgt_rate; // target bit rate (size) (if RC mode == slice)
537
538 // int2
539 char slice_alpha_c0_offset_div2 : 4;
540 char slice_beta_offset_div2 : 4;
541 unsigned char qp_slice_min; // min slice qp value
542 unsigned short qp_slice_max : 8; // max slice qp value
543 unsigned short force_intra : 1; // force entire slice to be intra
544 unsigned short disable_deblocking_filter_idc : 2;
545 unsigned short cabac_init_idc : 2;
546 unsigned short disable_slice_header : 1; // if set to 1, disables HW slice header output
547 unsigned short reserved0 : 2;
548
549 // int3
550 unsigned int num_ref_idx_active_override_flag : 1;
551 unsigned int num_ref_idx_l0_active_minus1 : 5; // [0.31]
552 unsigned int num_ref_idx_l1_active_minus1 : 5; // [0,31]
553 unsigned int reserved1 : 9; // padding
554 unsigned int me_control_idx : 4; // index in array of nvenc_h264_me_control_s to use for this slice
555 unsigned int md_control_idx : 4; // index in array of nvenc_h264_md_control_s to use for this slice
556 unsigned int q_control_idx : 4; // index in array of nvenc_h264_quant_control_s to use for this slice
557
558 // int 4
559 unsigned int limit_slice_top_boundary : 1; // limit ME to slice boundaries
560 unsigned int limit_slice_bot_boundary : 1; // limit ME to slice boundaries
561 unsigned int limit_slice_left_boundary : 1; // limit ME to slice boundaries
562 unsigned int limit_slice_right_boundary : 1; // limit ME to slice boundaries
563 unsigned int ROI_enable : 1; // Enable region of interest processing
564 unsigned int ROI_me_control_idx : 4;
565 unsigned int ROI_md_control_idx : 4;
566 unsigned int ROI_q_control_idx : 4;
567 unsigned int ROI_qp_delta : 8; // QP delta in ROI relative to picture outside ROI
568 unsigned int wp_control_idx : 4; // index in array of nvenc_pred_weight_table_s to use for this slice
569 unsigned int reserved2 : 3; // reserved for alignment
570
571 // int 5
572 unsigned int ROI_top_mbx : 8; // top left mbx of the ROI
573 unsigned int ROI_top_mby : 8;
574 unsigned int ROI_bot_mbx : 8; // bottom right mbx of the ROI
575 unsigned int ROI_bot_mby : 8;
576
577 // int 6: ref_pic_cmd_cfg
578 nvenc_h264_refpic_cmd_s ref_pic_cmd_cfg;
579
580 // int 7-22: RefPicListReorder/Modification: Defined in Section 7.4.3.1
581 nvenc_h264_ref_pic_reorder_s ref_pic_list_reorder_cmd[2][8]; // size shall not exceed num_ref_idx_lx_active_minus1 + 1 (8+8=16)
582
583 //int 23-30: MMCO: Defined in Section: 7.4.3.3
584 nvenc_h264_mmco_s mmco_cmd[8] ;
585
586 // int 31
587 unsigned int reserved3;
588
589 } nvenc_h264_slice_control_s; // 128 bytes
590
591
592 // Quarter-resolution modifier flags for first_pass_source_half_scaled
593 #define NVENC_QRES_FLAG_ENABLE 0x1 // Set if quarter-resolution is enabled
594 #define NVENC_QRES_FLAG_DECIMATED 0x10 // Set to indicate that subsampling was performed with decimation rather than low-pass
595 #define NVENC_QRES_FLAG_PASS2REFS 0x20 // Set to indicate that 1st-pass uses subsampled 2nd pass references instead of self-generated references
596
597 // Lookahead macros for ab_beta(INFO1) and prev_act(INFO2)
598 #define NVENC_LOOKAHEAD_INFO1(Wp2Wi) ((unsigned char)(Wp2Wi)) // clamp((int)(Wp*256.0/Wi), 0, 255) -> ratio of inter over intra complexity, 0=no lookahead
599 // Lookahead INFO2: (depth<<8)|(nextI)
600 // nextI: 1..255=distance to next scene change, 0=unknown or greater than lookahead depth;
601 // depth: 1..255=max lookahead depth (0=no lookahead)
602 #define NVENC_LOOKAHEAD_INFO2(nextI,depth) (((unsigned short)(nextI)) | (((unsigned short)(depth))<<8))
603
604 // HRD conformance and misc RC flags
605 #define NVENC_RC_HRD_VCL 0x1 // vcl_cpb_size and vcl_bitrate
606 #define NVENC_RC_HRD_NAL 0x2 // nal_cpb_size and nal_bitrate
607 #define NVENC_RC_HRD_STRICTGOPTARGET 0x4 // Strict GOP target (minimizes GOP-to-GOP rate fluctuations)
608 #define NVENC_RC_FIXED_PBRATIO 0x8U // Disable dynamic B-frame rhopbi adjustments
609
610 // needed only if picture level RC is enabled; as part of picture level RC, it will also perform HRD verification
611 // The contents of this file is produced by the driver during sequence level operations and should not be modified.
612 typedef struct
613 {
614 unsigned char hrd_type; // nal (=2) and vcl (=1) type
615 unsigned char QP[3]; // QP for 0:P picture, ,1:B picture 2; I picture
616 unsigned char minQP[3]; // min QP for 0:P picture, ,1:B picture 2; I picture
617 unsigned char maxQP[3]; // max QP for 0:P picture, ,1:B picture 2; I picture
618 unsigned char maxQPD; // max QP delta between two consecutive QP updates
619 unsigned char baseQPD; // initial QP delta between two consecutive QP updates
620 int rhopbi[3]; // 23.8 signed fixed point quant ratios P/I, B/I, I/I(=1)
621
622 int framerate; // fps
623 unsigned int buffersize; // total buffer size
624
625 int nal_cpb_size; // size in bits
626 int nal_bitrate; // rate in bps
627 int vcl_cpb_size; // size in bits
628 int vcl_bitrate; // rate in bps
629
630 unsigned int gop_length; // I period, gop_length == 0xffffffff is used for infinite gop length
631 int Np; // 27.4 signed fixed (gop_length + num_b_frames -1)/(num_b_frames + 1)
632 int Bmin; // 23.8 signed fixed point min buffer level, updated by driver at sequence level only.
633 int Ravg; // 23.8 signed fixed point average rate, updated by driver at sequence level only.
634 int R; // 23.8 signed fixed point rate
635
636 unsigned char ab_alpha; // VBR/CBR: min/target quality level (1..51); rcmode4: weight of prev frame activity compared to part of the current picture
637 unsigned char ab_beta; // lookahead info1: ratio of inter over intra complexity (fix8); rcmode4: weight of current activity compared to neighbors
638 unsigned short prev_act; // lookahead info2: nextI, depth and valid flag; rcmode4: average activity level of the first reference (L0)
639
640 unsigned char aqMode : 3; // 0: disable adaptive quantization, 1: AQ mode fast, 2: AQ mode full
641 unsigned char dump_aq_stats : 1; // 1: reads aq stats
642 unsigned char is_emphasis_level : 1; // 1: enables emphasis level map, treats QP map as level map
643 unsigned char reserve0 : 3; // Reserved for alignment
644 unsigned char single_frame_VBV; // 1: VBV buffer size is set to average frame size; 0: otherwise
645 unsigned char two_pass_rc; // 0: single pass rc , 1: first pass of 2 pass rc 2: second pass of 2 pass rc
646 unsigned char rc_class; // reserved
647
648 unsigned char first_pass_source_half_scaled; // 0 : first pass on half resolution 1: first pass on full resolution (along with NVENC_QRES_FLAG_XXX)
649 unsigned char iSizeRatioX; // ratio between I picture target size over average picture size numerator
650 unsigned char iSizeRatioY; // ratio between I picture target size over average picture size denominator
651 unsigned char ext_scene_change_flag; // Scene change flag set as hint by external preprocessing unit. 0: No scene change, 1: Current picture is first in scene
652 unsigned int ext_intra_satd; // If non zero this represents the intra SATD for current picture computed by external preprocessing unit
653 unsigned char ext_picture_rc_hints; // picture rc hints are set by external source. 0: no hints, 1: hints are avaialble for current picture
654 unsigned char session_max_qp; // Current frame qp will never exceed this value when ext_picture_rc_hints is set
655 unsigned char reserve[2];
656 } nvenc_h264_rc_s; // 88 bytes
657
658 typedef struct
659 {
660 unsigned int var_min;
661 unsigned int var_max;
662 unsigned int var_avg;
663 unsigned char reserved[4];
664 } nvenc_aq_stat_s; // 16 bytes
665
666 typedef struct
667 {
668 char l0[8]; // reference picture list 0
669 char l1[8]; // reference picture list 1
670 char temp_dist_l0[8]; // temporal distance of each ref pic in list 0 DiffPicOrderCnt( currPicOrField, pic0) )
671 char temp_dist_l1[8]; // temporal distance of each ref pic in list 1 DiffPicOrderCnt( currPicOrField, pic1) )
672 short dist_scale_factor[8][8]; // (h264 spec eq 8-203) array [refidx1][refidx0] signed 11 bit values
673 unsigned int diff_pic_order_cnt_zero[2]; // This is a 2-dimensional array of booleans (1 bit flags) indicating that DiffPicOrderCnt(refidx1, refidx0) == 0
674 unsigned int max_slice_size; // for use in slice_mode 1 only: dynamic insertion at/before this boundary (#bytes)
675 unsigned int max_byte_count_before_resid_zero; // Maximum byte count before micrcode forces the residuals to zero.
676 int delta_pic_order_cnt_bottom; // direct value of syntax element to be put in every slice of the picture
677 unsigned short frame_num; // value for slice header syntax element
678 unsigned short pic_order_cnt_lsb; // value of the corresponding syntax element
679 unsigned short idr_pic_id;
680 unsigned short colour_plane_id;
681 unsigned int longTermFlag; // Bits 7:0 for pictures in RefPicList0 and bits 23:16 for pictures in RefPicList1
682 unsigned char num_forced_slices_minus1; // number of forced slice boundary locations minus1(number of entries in h264_slice_control_s)
683 unsigned char num_me_controls_minus1; // number of nvenc_h264_me_control_s entries in array minus1
684 unsigned char num_md_controls_minus1; // number of nvenc_h264_md_control_s entries in array minus1
685 unsigned char num_q_controls_minus1; // number of nvenc_h264_quant_control_s entries in array minus1
686 unsigned int slice_control_offset; // offset from start of top level "nvenc_h264_drv_pic_setup_s" structure
687 // to start of array of "nvenc_h264_slice_control_s" structures
688 unsigned int me_control_offset; // offset from start of top level "nvenc_h264_drv_pic_setup_s" structure
689 // to start of array of "nvenc_h264_me_control_s" structures
690 unsigned int md_control_offset; // offset from start of top level "nvenc_h264_drv_pic_setup_s" structure
691 // to start of array of "nvenc_h264_md_control_s" structures
692 unsigned int q_control_offset; // offset from start of top level "nvenc_h264_drv_pic_setup_s" structure
693 // to start of array of "nvenc_h264_quant_control_s" structures
694 unsigned int hist_buf_size; // size in bytes of the buffer allocated for history
695 unsigned int bitstream_buf_size; // size in bytes of the buffer allocated for bitstream slice/mb data
696 unsigned int bitstream_start_pos; // start position in bitstream buffer where data should be written (byte offset)
697 unsigned int pic_struct : 2; // 0 = frame, 1 = top/first field, 2 = bot/second field
698 unsigned int pic_type : 2; // 0 = P, 1 = B, 2 = I, 3 = IDR
699 unsigned int ref_pic_flag : 1; // reference picture (0 = no, 1 = yes)
700 unsigned int slice_mode : 1; // 0 = dynamic slice insertion based on slice size
701 // 1 = static slice insertion based on slice control array
702 // (insert slices as defined in array, if all array elements used
703 // before end of picture is reached, start over with entry 0)
704 unsigned int ipcm_rewind_enable : 1;
705 unsigned int cabac_zero_word_enable : 1;
706
707 //mvc
708 unsigned int base_view : 1; // 1: current view component is a base view; 0: non-base view
709 unsigned int priority_id : 6; // priority identifier for the NAL unit
710 unsigned int view_id : 10; // view identifier for the NAL unit
711 unsigned int temporal_id : 3; // temporal identifier for the NAL unit
712 unsigned int anchor_pic_flag : 1; // equal to 1 specifies that the current access unit is an anchor access unit
713 unsigned int inter_view_flag : 1; // equal to 1 specifies that the current view component may be used for inter-view prediction by other view components in the current access unit
714 unsigned int opm_enable : 1; // check with OPM if encryption needed
715 unsigned int temporal_hint8x8_enable : 1; // 8x8 hint enable
716 char cur_interview_ref_pic; //current interview ref pic
717 char prev_interview_ref_pic; //previous interview ref pic to replace current interview ref pic when write the regs ME_MBC_REFLIST0_DPBLUT and ME_MBC_REFLIST1_DPBLUT
718 unsigned char codec : 3;
719 unsigned char e4byteStartCode : 1; // if enable to 1, all the slices in a picture will use 4 byte start code 00000001(used in rtp mode), original is 000001
720 unsigned char qpfifo : 1; // 0 = Polling mode, 1 = Interrupt mode.
721 unsigned int me_candidates_output_struct : 1; // 0 = me-only mode, 1 = MV & cost for all blocks (hybrid format)
722 unsigned int me_candidates_output_enable : 1; // hybrid mode results configuration (see me_candidates_output_struct). 0 = results disabled. 1 = results enabled (for fullscale image).
723 unsigned char medma_output_cost_mode : 1; // 0 = residual cost only. 1 = residual cost + mv cost
724 unsigned char intraRefreshCount; // Set to number of pictures over which intra refresh will happen. Set to 0 for non intra refresh picture
725 unsigned int mpec_threshold : 30; // collect mpec stats after threshold mbs
726 // when mpec_stat_on is enabled and mpec_threshold is not equal to picWidthInMbs,
727 // rc mode 0 will be used to collect stats
728 unsigned int me_lambda_fifo_enable : 1; // lambda map fifo enable. 1: enable. 0: disable
729 unsigned int me_candidates_rdo_mode : 1; // me candidates rdo mode enable. 1: enable. 0: disable.
730 unsigned int slice_stat_offset; // offset from start of top level "nvenc_stat_data_s" structure
731 // to start of array of "nvenc_slice_stat_s" structure
732 unsigned int mpec_stat_offset; // offset from start of top level "nvenc_stat_data_s" structure
733 // to start of array of "nvenc_mpec_stat_s" structure
734 unsigned int wp_control_offset; // offset from start of top level "nvenc_h264_drv_pic_setup_s" structure
735 // to start of array of "nvenc_pred_weight_table_s" structure
736 // to start of array of "nvenc_mpec_stat_s" structure
737
738 unsigned char num_wp_controls_minus1; // number of nvenc_pred_weight_table_s entries in array minus 1
739 unsigned char b_as_ref : 1; // use b frame as reference
740 unsigned char ofs_mode : 2; // ofs mode. 0: OFF; 1: Optical Flow; 2: Stereo (output mvx only), 3: Stereo (output mvx/mvy)
741 unsigned char new_subframe : 1;
742 unsigned char bit_depth_minus_8 : 4;
743 unsigned char stripID;
744 unsigned char strips_in_frame;
745 unsigned short slice_encoding_row_start; // start mb row for slice encoding
746 unsigned short slice_encoding_row_num; // num of mb row for slice encoding
747
748 unsigned char segment_enable : 1; // used by ofs mode only for segment map enable flag, 0: (default) disable/ 1: enable
749 unsigned char background_seg : 5; // used by ofs mode only when segment map is enabled, to specify the segment id of background
750 unsigned char input_sub_sampling : 1; // used by PDMA 2x2 sub-sampling
751 unsigned char output_sub_sampling : 1; // used by MPEB 2x2 sub-sampling output
752 unsigned char segment_P2 ;
753 unsigned char segment_thr ;
754 unsigned char accurate_skip_mv : 1;
755 unsigned char intra_sel_4x4_enable : 1; // seletive intra4x4 , 0:disable(always do intra4x4 serach), 1:enable(enable or disable intra4x4 search based on pixel variance)
756 unsigned int enable_source_image_padding : 1; // enable/disable HW source image padding
757 unsigned int luma_padding_mode : 2; // HW souce padding mode for luma: 0: copy frame boundary, 1: zero padding, 2: half value, i.e 1<<(bitdepth-1)
758 unsigned int chroma_padding_mode : 2; // HW souce padding mode for chroma: 0: copy frame boundary, 1: zero padding, 2: half value, i.e 1<<(bitdepth-1)
759 unsigned int stats_fifo_enable : 1; // enable per-mb short stats fifo
760 unsigned int chroma_skip_threshold_4x4 : 16; // low 3 bits is the factional, to check if chroma residual is big in skip mb, can't simply set chroma residual to 0 even though luma has been decided to skip
761 unsigned int intra_sel_4x4_threshold : 16; // disable intra4x4 search when intra_sel_4x4_enable=true and max variance of 8x8 blocks in current MB is less than intra_sel_4x4_threshold
762 unsigned int aq_stat_offset; // start of array of "nvenc_aq_stat_s" structure
763 unsigned int act_stat_offset; // offset from start of "nvenc_rc_pic_stat_s" structure,
764 // in the RC stats buffer. This field points to the start
765 // of data for external (delta-)QP map.
766 unsigned int stats_fifo_offset; // offset from start of top level "nvenc_stat_data_s" structure
767 } nvenc_h264_pic_control_s; // 276 bytes
768
769
770 // This is the top level config structure passed by driver to nvenc. It must be aligned
771 // to a 256B boundary. The first integer in this struct is a 'magic' number which driver
772 // must set to a specific value, and which the main Falcon app must check to see if it
773 // matches the expected value. This prevents running wrong combinations of traces/drvr
774 // code and falcon code. Encoding is as follows:
775 // Bit 31..16 = 0xc9b7
776 // Bit 15..8 = Version number
777 // Bit 7..0 = Revision number
778 // This number changes whenever there is a change to the class. If the change is small and
779 // backward compatible, only the revision number is incremented. If the change is major or
780 // not backward compatible, the revision number is reset to zero and the version number
781 // incremented. Falcon app should check if the upper 24 bits match the expected value, and
782 // terminate with error code "NvC9B7EncErrorH264BadMagic" if there is a mismatch. The value
783 // for the current class is defined as:
784
785 #ifdef NV_NVENC_8_2
786 #define NV_NVENC_DRV_MAGIC_VALUE 0xC9B70006
787 #elif NV_NVENC_8_0
788 #define NV_NVENC_DRV_MAGIC_VALUE 0xC8B70006
789 #elif NV_NVENC_7_3
790 #define NV_NVENC_DRV_MAGIC_VALUE 0xC7B70006
791 #elif NV_NVENC_7_2
792 #define NV_NVENC_DRV_MAGIC_VALUE 0xC4B70006
793 #elif NV_NVENC_7_0
794 #define NV_NVENC_DRV_MAGIC_VALUE 0xC5B70006
795 #elif NV_NVENC_6_8
796 #define NV_NVENC_DRV_MAGIC_VALUE 0xB6B70006
797 #elif NV_NVENC_6_6
798 #define NV_NVENC_DRV_MAGIC_VALUE 0xB4B70006
799 #elif NV_NVENC_6_4
800 #define NV_NVENC_DRV_MAGIC_VALUE 0xC3B70006
801 #elif NV_NVENC_6_2
802 #define NV_NVENC_DRV_MAGIC_VALUE 0xC2B70006
803 #elif NV_NVENC_6_0
804 #define NV_NVENC_DRV_MAGIC_VALUE 0xc1b70006
805 #elif NV_NVENC_5_0
806 #define NV_NVENC_DRV_MAGIC_VALUE 0xd0b70006
807 #elif NV_NVENC_1_0
808 #define NV_NVENC_DRV_MAGIC_VALUE 0xc0b70006
809 #elif NV_MSENC_2_0
810 #define NV_MSENC_DRV_MAGIC_VALUE 0xa0b70006
811 #else
812 #define NV_MSENC_DRV_MAGIC_VALUE 0x90b70006
813 #endif
814
815 #define HIST_BLOCK_SIZE 192
816 // Move all local define of these values to this file
817 //align to current AV1HIST MAS
818 const static int AV1_HIST_PIXEL_FRAME_SIZE = (8 * 8192);
819 const static int AV1_HIST_MV_SB_SIZE = (256 * 4);
820
821 typedef struct
822 {
823 // 256 aligned
824 unsigned int magic; // magic number, see text above 4 bytes
825 nvenc_h264_surface_cfg_s refpic_cfg; // defines layout of reference pictures 32 bytes
826 nvenc_h264_surface_cfg_s input_cfg; // defines layout of input pictures 32 bytes
827 nvenc_h264_surface_cfg_s outputpic_cfg; // defines layout of reconstructed pictures 32 bytes
828 nvenc_h264_sps_data_s sps_data; // 4 bytes
829 nvenc_h264_pps_data_s pps_data; // 8 bytes
830 nvenc_h264_rc_s rate_control; // Rate Control information 88 bytes
831 nvenc_h264_pic_control_s pic_control; // 276 bytes
832 nvenc_h264_surface_cfg_s half_scaled_outputpic_cfg; // defines layout of 2x2 subsampled reconstructed picture 32 bytes
833 unsigned int gpTimer_timeout_val; // GPTimer cycle count set from driver 4 bytes
834
835 } nvenc_h264_drv_pic_setup_s; // 512 bytes
836
837
838 // ****************************************************************************
839 // ****************************************************************************
840 // H265
841 // ****************************************************************************
842 // ****************************************************************************
843 typedef struct
844 {
845 unsigned short frame_width_minus1; // frame width in pixels minus 1, range 0-4095
846 unsigned short frame_height_minus1; // frame height in pixels minus 1, range 0-4095
847 unsigned short sfc_pitch; // pitch of luma plane
848 unsigned short sfc_pitch_chroma; // pitch of chroma plane
849 unsigned short sfc_trans_mode; // least 3 significient bits are used to stand for 8 modes, normal, xflip, yflip etc.
850 unsigned short reserved2; // pad to int
851
852 unsigned int luma_top_frm_offset; // offset of luma top field or frame in units of 256
853 unsigned int luma_bot_offset; // offset of luma bottom field in units of 256. Not used if frame format.
854 unsigned int chroma_top_frm_offset; // offset of chroma top field or frame, or offset of chroma U(Cb) plane in planar mode, both in units of 256
855 unsigned int chroma_bot_offset; // offset of chroma bottom field, not used if frame format. Or offset of chroma V(Cr) plane in planar mode. Both in units of 256.
856 unsigned int block_height : 7; // BL mapping block height setting
857 unsigned int tiled_16x16 : 1; // Surface is 16x16 tiled instead of BL mapped (must be 1 for refpics)
858 unsigned int memory_mode : 2; // 0: semi-planar, 1: planar
859 unsigned int nv21_enable : 1; // the surface format is yuv or yvu
860 unsigned int input_bl_mode : 2; // the input block linear mode: 0~gpu bl; 1~tegra bl; 2~naive bl this is only for cmod and cmod/plugin
861 unsigned int reserved : 19; // pad to NvU32
862 } nvenc_h265_surface_cfg_s; // 32 bytes
863
864 typedef struct
865 {
866 unsigned int chroma_format_idc : 2; // 0=monochrome, 1=yuv4:2:0, 3=yuv4:4:4, 2=not supported
867 unsigned int separate_colour_plane_flag : 1; //if this bit is enabled, the chroma_format_idc should be 3
868 unsigned int log2_max_pic_order_cnt_lsb_minus4 : 4;
869 unsigned int min_cu_size : 2; //0-8x8, 1-16x16, 2-32x32, 3-64x64
870 unsigned int max_cu_size : 2; //0-8x8, 1-16x16, 2-32x32, 3-64x64
871 unsigned int min_tu_size : 2; //0-4x4, 1-8x8, 2-16x16, 3-32x32
872 unsigned int max_tu_size : 2; //0-4x4, 1-8x8, 2-16x16, 3-32x32
873 unsigned int reserved0 : 1; // pad to full short
874
875 unsigned int max_transform_depth_inter : 2; // max_transform_hierarchy_depth_inter
876 unsigned int max_transform_depth_intra : 2; // max_transform_hierarchy_depth_intra
877 unsigned int pcm_enabled_flag : 1; // if this bit is 1 , PCM data is present is the sequence
878 unsigned int pcm_loop_filter_disable_flag : 1; // Disable loop filter and SAO for CU with pcm_flag to 1
879 unsigned int long_term_ref_pics_present_flag : 1; // if set to 1 , it indicates long term pictures are used for inter prediction.
880 unsigned int amp_enabled_flag : 1; // if set asymmetric motion partitions can be used for inter predictions.
881 unsigned int strong_intra_smoothing_enabled_flag : 1; // if set , bilinear interpolation is conditionally used filtering process for intra prediction.
882 unsigned int num_short_term_ref_pic_sets : 7; // max value is 64
883 unsigned int num_long_term_ref_pics_sps : 5;
884 unsigned int bit_depth_minus_8 : 4; // luma/chroma should have the same value
885 unsigned int sample_adaptive_offset_enabled_flag : 1; // set 1 specifies that the sample adaptive offset process is applied to the reconstructed picture after the deblocking filter process
886 unsigned int sps_temporal_mvp_enabled_flag : 1; // if set, slice_temporal_mvp_enabled_flag is present in slice header
887 unsigned int reserved1 : 21;
888 } nvenc_h265_sps_data_s; // 8 bytes
889
890 typedef struct
891 {
892 unsigned int pic_param_set_id : 8; // picture parameter set identification
893 unsigned int num_ref_idx_l0_active_minus1 : 5; // number of currently active reference pictures in list 0 minus 1, range 0..30
894 unsigned int num_ref_idx_l1_active_minus1 : 5; // number of currently active reference pictures in list 1 minus 1, range 0..30
895 unsigned int constrained_intra_pred_flag : 1; // if set, intra prediction can only use pixels from macroblocks that are also intra coded
896 unsigned int transquant_bypass_enabled_flag : 1; // if set, transform ,scaling and inloop filtering is bypassed.
897 unsigned int transform_skip_enabled_flag : 1; // if set , it enables transform bypass during residual coding.
898 unsigned int deblocking_filter_override_enabled_flag : 1; // it set, the deblocking_filter_override_flag is encoded in slice segment header
899 unsigned int pps_loop_filter_across_slices_enabled_flag : 1; // if set, it enables loop filter across slice boundary.
900 unsigned int cu_qp_delta_enabled_flag : 1; // if set , it enables cu_qp_delta_abs is encoded at coding unit layer.
901 unsigned int lists_modification_present_flag : 1; // if set , it indicates reference picture list modification command might be present is slice segment header.
902 unsigned int output_flag_present_flag : 1; // if set, pic_output syntax element is added to slice syntax header
903 unsigned int cabac_init_present_flag : 1; // if set, cabac_init_flag is present in slice segment header.
904 unsigned int pps_slice_chroma_qp_offsets_present : 1; // if set to 1, cb_qp_offset and cr_qp_offset is signalled in the slice segment header.
905 unsigned int weighted_pred_flag : 1; // weighted_pred_flag equal to 1 specifies that weighted prediction is applied to P slices
906 unsigned int weighted_bipred_flag : 1; // weighted_bipred_flag equal to 1 specifies that weighted prediction is applied to B slices
907 unsigned int reserved : 2;
908
909 int pic_init_qp_minus26 : 6; // initial QP value, range -26..+25. -38...+25 for 10bit, -74...+25 for 16bits. TODO: eable this syntex for pps
910 int pps_cb_qp_offset : 5;
911 int pps_cr_qp_offset : 5;
912 unsigned int dependent_slice_segments_enabled_flag : 1;
913 unsigned int sign_data_hiding_enabled_flag : 1;
914 unsigned int diff_cu_qp_delta_depth : 2;
915 unsigned int log2_parallel_merge_level_minus2 : 3;
916 unsigned int num_extra_slice_header_bits : 3;
917
918 int reserved1 : 6;
919 } nvenc_h265_pps_data_s; // 8 bytes
920
921 // needed only if picture level RC is enabled; as part of picture level RC, it will also perform HRD verification
922 // The contents of this file is produced by the driver during sequence level operations and should not be modified.
923 typedef struct
924 {
925 unsigned char hrd_type; // nal (=2) and vcl (=1) type
926 unsigned char QP[3]; // QP for 0:P picture, ,1:B picture 2; I picture
927 unsigned char minQP[3]; // min QP for 0:P picture, ,1:B picture 2; I picture
928 unsigned char maxQP[3]; // max QP for 0:P picture, ,1:B picture 2; I picture
929 unsigned char maxQPD; // max QP delta between two consecutive QP updates
930 unsigned char baseQPD; // initial QP delta between two consecutive QP updates
931 int rhopbi[3]; // 23.8 signed fixed point quant ratios P/I, B/I, I/I(=1)
932
933 int framerate; // fps
934 unsigned int buffersize; // total buffer size
935
936 int nal_cpb_size; // size in bits
937 int nal_bitrate; // rate in bps
938 int vcl_cpb_size; // size in bits
939 int vcl_bitrate; // rate in bps
940
941 unsigned int gop_length; // I period, gop_length == 0xffffffff is used for infinite gop length
942 int Np; // 27.4 signed fixed (gop_length + num_b_frames -1)/(num_b_frames + 1)
943 int Bmin; // 23.8 signed fixed point min buffer level, updated by driver at sequence level only.
944 int Ravg; // 23.8 signed fixed point average rate, updated by driver at sequence level only.
945 int R; // 23.8 signed fixed point rate
946
947 unsigned char ab_alpha; // VBR/CBR: min/target quality level (1..51); rcmode4: weight of prev frame activity compared to part of the current picture
948 unsigned char ab_beta; // lookahead info1: ratio of inter over intra complexity (fix8); rcmode4: weight of current activity compared to neighbors
949 unsigned short prev_act; // lookahead info2: NVENC_LOOKAHEAD_INFO2; rcmode4: average activity level of the first reference (L0)
950
951 unsigned char reserved0;
952 unsigned char single_frame_vbv; // 1: VBV buffer size is set to average frame size; 0: otherwise
953 unsigned char two_pass_rc; // 0: single pass rc , 1: first pass of 2 pass rc 2: second pass of 2 pass rc
954 unsigned char rc_class; // reserved
955 unsigned char first_pass_source_half_scaled; // 0 : first pass on half resolution 1: first pass on full resolution (along with NVENC_QRES_FLAG_XXX)
956 unsigned char i_size_ratio_x; // ratio between I picture target size over average picture size numerator
957 unsigned char i_size_ratio_y; // ratio between I picture target size over average picture size denominator
958 unsigned char aqMode; // 0: disable adaptive quantization 1: AQ mode fast (unimplemented) 2: AQ mode full (unimplemented) 3: External qp delta map
959 unsigned char dump_aq_stats; // 1: dump aq stats
960 unsigned char ext_scene_change_flag; // Scene change flag set as hint by external preprocessing unit. 0: No scene change, 1: Current picture is first in scene
961 unsigned char ext_picture_rc_hints; // picture rc hints are set by external source. 0: no hints, 1: hints are avaialble for current picture
962 unsigned char session_max_qp; // Current frame qp will never exceed this value when ext_picture_rc_hints is set
963 unsigned int ext_intra_satd; // If non zero this represents the intra SATD for current picture computed by external preprocessing unit
964 unsigned char reserved2[8];
965 } nvenc_h265_rc_s; // 96 bytes
966
967 typedef struct
968 {
969 int inter_ref_pic_set_prediction_flag : 1;
970 int delta_idx_minus1 : 6;
971 int delta_rps_sign : 1;
972 int abs_delta_rps_minus1 : 16;
973 int reserved : 8;
974 unsigned short used_by_curr_pic_flag;
975 unsigned short use_delta_flag;
976 short num_negative_pics;
977 short num_positive_pics;
978 short delta_poc_s0_minus1[16];
979 unsigned short used_by_curr_pic_s0_flag;
980 short delta_poc_s1_minus1[16];
981 unsigned short used_by_curr_pic_s1_flag;
982 }nvenc_h265_strps_s; // 80bytes multiple of 4
983
984 typedef struct
985 {
986 int num_long_term_sps : 5;
987 int num_long_term_pics : 5;
988 int reserved0 : 22;
989 unsigned char lt_idx_sps[16];
990 unsigned short poc_lsb_lt[16];
991 unsigned short used_by_curr_pic_lt_flag;
992 unsigned short delta_poc_msb_present_flag;
993 int delta_poc_msb_cycle_lt[16];
994 }nvenc_h265_ltrps_s; // 120bytes multiple of 4
995
996 typedef struct
997 {
998 int NumPocTotalCurr : 5;
999 int ref_pic_list_mod_flag_l0 : 1;
1000 int ref_pic_list_mod_flag_l1 : 1;
1001 int reserved0 : 25;
1002 unsigned char list_entry_l0[16];
1003 unsigned char list_entry_l1[16];
1004 }nvenc_h265_ref_pic_list_modification_s; //36bytes multiple of 4
1005
1006 typedef struct
1007 {
1008 unsigned int vps_poc_lsb_not_present_flag : 1;
1009 unsigned int vps_default_ref_layers_active_flag : 1;
1010 unsigned int vps_max_one_active_ref_layer_flag : 1;
1011 unsigned int vps_num_direct_ref_layers : 6;
1012 unsigned int slh_discardable_flag : 1; // mv_hevc, equal to 1 specifies that the coded picture is not used as a reference picture
1013 unsigned int slh_cross_layer_bla_flag : 1; // mv_hevc
1014 unsigned int slh_num_active_ref_layer_pics : 6; // active ref layer pics of current picture
1015 unsigned int slh_inter_layer_pred_enabled_flag : 1;
1016 unsigned int slh_num_inter_layer_ref_pics_minus1 : 6;
1017 unsigned int reserved0 : 8;
1018 unsigned char slh_inter_layer_pred_layer_idc[8]; //NumPicTotalCurr <= 8
1019 }nvenc_mv_hevc_cfg_s; //12bytes multiple of 4
1020
1021 typedef struct
1022 {
1023 char l0[8]; // reference picture list 0
1024 char l1[8]; // reference picture list 1
1025 char temp_dist_l0[8]; // temporal distance of each ref pic in list 0 DiffPicOrderCnt( currPicOrField, pic0) )
1026 char temp_dist_l1[8]; // temporal distance of each ref pic in list 1 DiffPicOrderCnt( currPicOrField, pic1) )
1027 short dist_scale_factor[8][8]; // (h264 spec eq 8-203) array [refidx1][refidx0] signed 11 bit values
1028 unsigned int diff_pic_order_cnt_zero[2]; // This is a 2-dimensional array of booleans (1 bit flags) indicating that DiffPicOrderCnt(refidx1, refidx0) == 0
1029 unsigned int max_slice_size; // for use in slice_mode 1 only: dynamic insertion at/before this boundary (#bytes)
1030 unsigned int max_byte_count_before_resid_zero; // Maximum byte count before micrcode forces the residuals to zero.
1031
1032 unsigned short no_output_of_prior_pics_flag : 1; // used to modify the DPB after decoding a IDR or BLA picture
1033 unsigned short pic_output_flag : 1; // affects the decoded picture output and removal processes as specified in Annex C
1034 unsigned short mode_decision_only_flag : 1; // only output h265 mode and mocomp result, no recon and bitstream output
1035 unsigned short cu_early_terminatiom_enable : 1; // 0: disable CU early termination, 1: enable CU early termination
1036 unsigned short input_sub_sampling : 1; // used by PDMA 2x2 sub-sampling
1037 unsigned short output_sub_sampling : 1; // used by MPEB 2x2 sub-sampling output
1038 unsigned short reserved0 : 10;
1039 unsigned short pic_order_cnt_lsb; // value of the corresponding syntax element
1040
1041 unsigned char num_forced_slices_minus1; // number of forced slice boundary locations minus1(number of entries in h264_slice_control_s)
1042 unsigned char num_me_controls_minus1; // number of nvenc_h264_me_control_s entries in array minus1
1043 unsigned char num_md_controls_minus1; // number of nvenc_h264_md_control_s entries in array minus1
1044 unsigned char num_q_controls_minus1; // number of nvenc_h264_quant_control_s entries in array minus1
1045 unsigned int slice_control_offset; // offset from start of top level "nvenc_h264_drv_pic_setup_s" structure
1046 // to start of array of "nvenc_h264_slice_control_s" structures
1047 unsigned int me_control_offset; // offset from start of top level "nvenc_h264_drv_pic_setup_s" structure
1048 // to start of array of "nvenc_h264_me_control_s" structures
1049 unsigned int md_control_offset; // offset from start of top level "nvenc_h264_drv_pic_setup_s" structure
1050 // to start of array of "nvenc_h264_md_control_s" structures
1051 unsigned int q_control_offset; // offset from start of top level "nvenc_h264_drv_pic_setup_s" structure
1052 // to start of array of "nvenc_h264_quant_control_s" structures
1053 unsigned int hist_buf_size; // size in bytes of the buffer allocated for history
1054 unsigned int bitstream_buf_size; // size in bytes of the buffer allocated for bitstream slice/mb data
1055 unsigned int bitstream_start_pos; // start position in bitstream buffer where data should be written (byte offset)
1056 unsigned int pic_type : 2; // 0 = P, 1 = B, 2 = I, 3 = IDR
1057 unsigned int ref_pic_flag : 1; // reference picture (0 = no, 1 = yes)
1058 unsigned int slice_mode : 1; // 0 = dynamic slice insertion based on slice size
1059 // 1 = static slice insertion based on slice control array
1060 // (insert slices as defined in array, if all array elements used
1061 // before end of picture is reached, start over with entry 0)
1062 unsigned int cabac_zero_word_enable : 1;
1063 unsigned int codec : 3;
1064 unsigned int ceil_log2_pic_size_in_ctbs : 6; // ceillog2(picSizeInCtbs) for HW needs too much area/time for 16kx16k case
1065 unsigned int sao_luma_mode : 5;
1066 unsigned int sao_chroma_mode : 5;
1067 unsigned int reserved1 : 8;
1068
1069 unsigned int mpec_threshold; // collect mpec stats after threshold mbs
1070 // when mpec_stat_on is enabled and mpec_threshold is not equal to picWidthInMbs,
1071 // rc mode 0 will be used to collect stats
1072 unsigned int slice_stat_offset; // offset from start of top level "nvenc_h265_stat_data_s" structure
1073 // to start of array of "nvenc_h265_slice_stat_s" structure
1074 unsigned int mpec_stat_offset; // offset from start of top level "nvenc_h265_stat_data_s" structure
1075 // to start of array of "nvenc_h265_mpec_stat_s" structure
1076 unsigned int aq_stat_offset; // to start of array of "nvenc_h265_aq_stat_s" structure
1077 unsigned int short_term_ref_pic_set_sps_flag : 1; // if set to 1 ,the short term RPS is signalled using SPS, if set to 0 the short term RPS is encoded in the current slice header
1078 unsigned int short_term_ref_pic_set_idx : 6; // used to signal index into the list of the short term RPS in the SPS.
1079 unsigned int e4byteStartCode : 1; // if enable to 1, all the slices in a picture will use 4 byte start code 00000001(used in rtp mode), original is 000001
1080 unsigned int nal_unit_type : 6; // specifies the type of RBSP data structure contained in the NAL unit
1081 unsigned int nuh_layer_id : 6; // reserved and shall be equal to 0.
1082 unsigned int nuh_temporal_id_plus1 : 3; // specifies the temporal_ip_plus1 of RBSP data structure contained in the NAL unit
1083 unsigned int qpfifo : 1; // 0 = Polling mode, 1 = Interrupt mode.
1084 unsigned int enable_source_image_padding : 1; // enable/disable HW source image padding
1085 unsigned int luma_padding_mode : 2; // HW souce padding mode for luma: 0: copy frame boundary, 1: zero padding, 2: half value, i.e 1<<(bitdepth-1)
1086 unsigned int chroma_padding_mode : 2; // HW souce padding mode for chroma: 0: copy frame boundary, 1: zero padding, 2: half value, i.e 1<<(bitdepth-1)
1087 unsigned int stats_fifo_enable : 1; // enable per-ctb short stats fifo
1088 unsigned int reserved2 : 2;
1089
1090 nvenc_h265_strps_s short_term_rps; // if short_term_ref_pic_set_sps_flag is set to 0, the nvenc_h265_strps_s structure is signalled in the slice segment segment header.
1091 nvenc_h265_ltrps_s long_term_rps; // if long_term_ref_pics_present_flag is set to 1 in SPS , nvenc_h265_ltrps_s structure is signalled in the slice segment segment header
1092 nvenc_h265_ref_pic_list_modification_s ref_pic_list_modification; // if lists_modification_present_flag is set to 1, then nvenc_h265_ref_pic_list_modification_s structure is encoded in slice segment header.
1093 unsigned int rc_pass2_offset;
1094
1095 unsigned int wp_control_offset; // offset from start of top level "nvenc_h265_drv_pic_setup_s" structure
1096 // to start of array of "nvenc_pred_weight_table_s" structure
1097
1098 unsigned char num_wp_controls_minus1; // number of nvenc_pred_weight_table_s entries in array minus 1
1099 unsigned char stripID;
1100 unsigned char strips_in_frame;
1101 unsigned char slice_idx_start;
1102 unsigned short slice_encoding_row_start; // start ctb row for slice encoding
1103 unsigned short slice_encoding_row_num; // num of ctb row for slice encoding
1104
1105 nvenc_mv_hevc_cfg_s mv_hevc_cfg;
1106 unsigned int chroma_skip_threshold_4x4 : 16; // low 3 bits is the factional, to check if chroma residual is big in skip mb, can't simply set chroma residual to 0 even though luma has been decided to skip
1107 unsigned int longTermFlag : 16; // Bits 7:0 for pictures in RefPicList0 and bits 15:8 for pictures in RefPicList1
1108
1109 char poc_entry_l0[8]; // ref pic list to ref pic entry map
1110 char poc_entry_l1[8]; // ref pic list to ref pic entry map
1111 unsigned int same_poc[2]; // set to 1 when the poc of cur ref pic and neighbor ref pic are same, otherwise set it to 0.
1112 unsigned int act_stat_offset; // offset from start of "nvenc_rc_pic_stat_s" structure, points to data for external QP map
1113 unsigned int stats_fifo_offset; // offset from start of top level "nvenc_stat_data_s" structure
1114 } nvenc_h265_pic_control_s; // 536 bytes
1115
1116 typedef struct
1117 {
1118 // 256 aligned
1119 unsigned int magic; // magic number, see text above // 4 bytes
1120 nvenc_h265_surface_cfg_s refpic_cfg; // defines layout of reference pictures // 32 bytes
1121 nvenc_h265_surface_cfg_s input_cfg; // defines layout of input pictures // 32 bytes
1122 nvenc_h265_surface_cfg_s outputpic_cfg; // defines layout of reconstructed pictures // 32 bytes
1123 nvenc_h265_sps_data_s sps_data; // 8 bytes
1124 nvenc_h265_pps_data_s pps_data; // 8 bytes
1125 nvenc_h265_rc_s rate_control; // Rate Control information // 96 bytes
1126 nvenc_h265_pic_control_s pic_control; //536 bytes
1127 nvenc_h265_surface_cfg_s half_scaled_outputpic_cfg; // defines layout of 2x2 subsampled reconstructed picture // 32 bytes
1128 unsigned int gpTimer_timeout_val; // GPTimer cycle count set from driver 4 bytes
1129 unsigned char reserved[240]; // Pad to 1024 bytes
1130
1131 } nvenc_h265_drv_pic_setup_s;
1132
1133 typedef struct
1134 {
1135 unsigned short intra_refresh_cnt; // distance between forced-intra MBs in slice; 0 means OFF
1136 unsigned short intra_refresh_offs; // first forced-intra MB in slice
1137
1138 unsigned int h265_intra_luma4x4_mode_enable; //bitmask indicate which intra luma 4x4 modes to enable in ip1 intra search
1139 unsigned int h265_intra_luma8x8_mode_enable; //bitmask indicate which intra luma 8x8 modes to enable in ip1 intra search
1140 unsigned int h265_intra_luma16x16_mode_enable; //bitmask indicate which intra luma 16x16 modes to enable in ip1 intra search
1141 unsigned int h265_intra_luma32x32_mode_enable; //bitmask indicate which intra luma 32x32 modes to enable in ip1 intra search
1142 unsigned int h265_intra_luma64x64_mode_enable; //bitmask indicate which intra luma 64x64 modes to enable in ip1 intra search
1143 unsigned int h265_intra_luma_mode_enable_leftbits : 30; //bitmask indicate intra luma left modes(32~34) from ip1 luma4x4 to ip2 luma64x64.
1144 unsigned int reserved0 : 2;
1145
1146
1147 unsigned char cu16x16_part_2Nx2N_enable : 1; // enable prediction for 2Nx2N
1148 unsigned char cu16x16_part_2NxN_enable : 1; // enable prediction for 2NxN
1149 unsigned char cu16x16_part_Nx2N_enable : 1; // enable prediction for Nx2N
1150 unsigned char cu16x16_part_NxN_enable : 1; // enable prediction for NxN
1151 unsigned char cu16x16_part_2NxnU_enable : 1; // enable prediction for 2NxnU
1152 unsigned char cu16x16_part_2NxnD_enable : 1; // enable prediction for 2NxnD
1153 unsigned char cu16x16_part_nLx2N_enable : 1; // enable prediction for nLx2N
1154 unsigned char cu16x16_part_nRx2N_enable : 1; // enable prediction for nRx2N
1155
1156 unsigned char cu32x32_part_2Nx2N_enable : 1; // enable prediction for 2Nx2N
1157 unsigned char cu32x32_part_2NxN_enable : 1; // enable prediction for 2NxN
1158 unsigned char cu32x32_part_Nx2N_enable : 1; // enable prediction for Nx2N
1159 unsigned char cu32x32_part_NxN_enable : 1; // enable prediction for NxN
1160 unsigned char cu32x32_part_2NxnU_enable : 1; // enable prediction for 2NxnU
1161 unsigned char cu32x32_part_2NxnD_enable : 1; // enable prediction for 2NxnD
1162 unsigned char cu32x32_part_nLx2N_enable : 1; // enable prediction for nLx2N
1163 unsigned char cu32x32_part_nRx2N_enable : 1; // enable prediction for nRx2N
1164
1165 unsigned char cu64x64_part_2Nx2N_enable : 1; // enable prediction for 2Nx2N
1166 unsigned char cu64x64_part_2NxN_enable : 1; // enable prediction for 2NxN
1167 unsigned char cu64x64_part_Nx2N_enable : 1; // enable prediction for Nx2N
1168 unsigned char cu64x64_part_NxN_enable : 1; // enable prediction for NxN
1169 unsigned char cu64x64_part_2NxnU_enable : 1; // enable prediction for 2NxnU
1170 unsigned char cu64x64_part_2NxnD_enable : 1; // enable prediction for 2NxnD
1171 unsigned char cu64x64_part_nLx2N_enable : 1; // enable prediction for nLx2N
1172 unsigned char cu64x64_part_nRx2N_enable : 1; // enable prediction for nRx2N
1173
1174 unsigned char intra_mode_4x4_enable : 1; // enable intra prediction in mdp for 4x4
1175 unsigned char intra_mode_8x8_enable : 1; // enable intra prediction in mdp for 8x8
1176 unsigned char intra_mode_16x16_enable : 1; // enable intra prediction in mdp for 16x16
1177 unsigned char intra_mode_32x32_enable : 1; // enable intra prediction in mdp for 32x32
1178 unsigned char intra_mode_64x64_enable : 1; // enable intra prediction in mdp for 32x32
1179 unsigned char priority_ipred_type_ip1 : 3; // which intra type search first for early termination, must be a subset of ip_search_mode. reserved, not implemented in HW
1180
1181 unsigned int h265_intra_chroma_mode_enable : 5; //bitmask indicate which intra_chroma_pred_mode to enable
1182 unsigned int inter_penalty_factor_for_ip1 : 6; // early teminate ip1 intra search if intra cost is larger than inter_cost + ((inter_cost * factor) >> 8)
1183 unsigned int tusize_4x4_enable : 1; //enable 4x4 transform
1184 unsigned int tusize_8x8_enable : 1; //enable 8x8 transform
1185 unsigned int tusize_16x16_enable : 1; //enable 16x16 transform
1186 unsigned int tusize_32x32_enable : 1; //enable 32x32 transform
1187 unsigned int intra_tusize_decision : 1; //enable intra tu size decision, reserved, not implemented in HW
1188 unsigned int pskip_enable : 1; //enable p_skip encoding
1189 unsigned int tu_search_basedon_pusize : 1; //enable tu search based on pu size
1190 unsigned int reserved1 : 14; // reserved for future special prediction extensions
1191
1192 short bias_part_2Nx2N; //bias for 2Nx2N PU
1193 short bias_part_2NxN; //bias for 2NxN PU
1194 short bias_part_Nx2N; //bias for Nx2N PU
1195 short bias_part_NxN; //bias for NxN PU
1196 short bias_part_2NxnU; //bias for 2NxnU PU
1197 short bias_part_2NxnD; //bias for 2NxnD PU
1198 short bias_part_nLx2N; //bias for nLx2N PU
1199 short bias_part_nRxN; //bias for nRxN PU
1200
1201 short bias_cusize_8x8; //bias for 8x8 CU
1202 short bias_cusize_16x16; //bias for 16x16 CU
1203 short bias_cusize_32x32; //bias for 32x32 CU
1204 short bias_cusize_64x64; //bias for 64x64 CU
1205 short bias_pskip; // bias for pskip (subtracts from pskip cost)
1206
1207 short bias_intra_over_inter; // bias for any intra (subtracts from intra cost)
1208 short bias_intra_most_prob; // bias for intra most probable mode
1209 short bias_qpp;
1210 short bias_transform_skip; // bias for transform skip mode
1211
1212 unsigned short mv_cost_bias; // bias applied to internal motion vector cost calculation
1213 unsigned short pskip_esc_threshold; // if pskip cost is below this, disable full search & attempt pskip encode
1214
1215 unsigned short tempmv_wt_spread_threshold; // The threshold for the sum of differences between 8x8s and 16x16 mvs. Used for temporal mv weight
1216 unsigned int tempmv_wt_distort_threshold : 16; // The threshold for the cost of the 16x16 mv. Used for temporal mv weight
1217 unsigned int mv_cost_predictor_control : 1; // 0=use 16x16 predictor only; 1=use accurate predictor (slower but better)
1218 unsigned int mv_cost_enable : 1; // enable mv cost calculations in mode decision
1219 unsigned int chroma_eval_mode : 1; // for intra chroma search 0 = U and V; 1 = U only
1220 unsigned int ip_search_mode : 4; // which intra sizes to search before making IP decision b0=4x4,b1=8x8,b2=16x16,b3=32x32
1221 unsigned int multiply_bias_with_lambda : 1; // setting this to 1 will result in bias being multiplied by lambda
1222 unsigned int force_ipcm : 1; // 0=normal encode; 1=force mpeb/mpec encode as IPCM
1223 unsigned int early_termination_ip1 : 1; // enable IP1 early termination
1224 unsigned int tu_search_num_cu16 : 3; // tu search part num in cu16
1225 unsigned int tu_search_num_cu32 : 3; // tu search part num in cu32
1226 unsigned int early_termination_mode_ip1; //enable intra mode search for early termination, 32 bits for the 35 modes other than H, V and DC, these 3 modes enabled as default
1227 short bias_tu_4x4; // bias for TU 4x4
1228 short bias_tu_8x8; // bias for TU 8x8
1229 short bias_tu_16x16; // bias for TU 16x16
1230 short bias_tu_32x32; // bias for TU 32x32
1231 short num_1div8_lambda_ssd : 7; // number of 1/8 lambda ssd for lambda_coef delta. lambda_coef = (1+num_1div8_lambda_ssd*1/8)*lambda_ssd
1232 short skip_evaluate_enable_cu8 : 1; // 0: not check skip ssd cost; 1, evaluate skip ssd cost
1233 short skip_evaluate_enable_cu16 : 1; // 0: not check skip ssd cost; 1, evaluate skip ssd cost
1234 short skip_evaluate_enable_cu32 : 1; // 0: not check skip ssd cost; 1, evaluate skip ssd cost
1235 short skip_evaluate_enable_cu64 : 1; // 0: not check skip ssd cost; 1, evaluate skip ssd cost
1236 short reserved2 : 1;
1237 short intra_ssd_cnt_4x4 : 4; // SSD cost evaluation between N top intra modes selected by satd
1238 short intra_ssd_cnt_8x8 : 4; // SSD cost evaluation between N top intra modes selected by satd
1239 short intra_ssd_cnt_16x16 : 4; // SSD cost evaluation between N top intra modes selected by satd
1240 short intra_ssd_cnt_32x32 : 4; // SSD cost evaluation between N top intra modes selected by satd
1241 short rdo_level : 3; // 0:cu size decided by satd in P frame 1:cu size decided by ssd
1242 short reserved3 : 1; // pad to short
1243
1244 short bias_skip; // bias for skip mv's ssd (subtracts from skip mv's ssd cost)
1245 short bias_intra_32x32; // bias for intra 32x32 (subtracts from intra 32x32 cost)
1246 short bias_intra_16x16; // bias for intra 16x16 (subtracts from intra 16x16 cost)
1247 short bias_intra_8x8; // bias for intra 8x8 (subtracts from intra 8x8 cost)
1248 short bias_intra_4x4; // bias for intra 4x4 (subtracts from intra 4x4 cost)
1249 unsigned char reserved[22];
1250 } nvenc_h265_md_control_s; // 128 bytes
1251
1252 typedef struct
1253 {
1254 unsigned int num_ctus : 19; // number of ctus in this slice, support upto 8kx8k
1255 unsigned int qp_avr : 8; // 6bit value used by hw. Other bits can be used for rounding.
1256 unsigned int reserved0 : 5;
1257
1258 unsigned int dependent_slice_segment_flag : 1; // slice segment header syntax element present or not
1259 unsigned int slice_type : 2; // 0 = B, 1 = P, 2 = I
1260 unsigned int five_minus_max_num_merge_cand : 3; // specifies the maximum number of merging MVP candidates supported
1261 unsigned int cabac_init_flag : 1;
1262 unsigned int deblocking_filter_override_flag : 1; // specifies the deblocking control params is preset in slice header.
1263 unsigned int slice_deblocking_filter_disabled_flag : 1; // if set to 1 , it disables deblcoking for the current slice.
1264 // If deblocking_filter_override_flag is 0, this is set to pps_deblocking_filter_disabled_flag
1265 unsigned int slice_loop_filter_across_slices_enabled_flag : 1; // if set to 1, it enables loop filter accross slice boundary.
1266 unsigned int qp_slice_min : 8; // min slice qp value
1267 unsigned int qp_slice_max : 8; // max slice qp value
1268 unsigned int force_intra : 1;
1269 unsigned int slice_sao_luma_flag : 1; // equal to 1 specifies that SAO is enabled for the luma component in the current slice
1270 unsigned int slice_sao_chroma_flag : 1; // equal to 1 specifies that SAO is enabled for the chroma component in the current slice
1271 unsigned int reserved1 : 3;
1272
1273 int slice_beta_offset_div2 : 4; // if deblocking_filter_override_flag = 1 , then slice_beta_offset_div2 is signalled in slice segment header
1274 int slice_tc_offset_div2 : 4; // if deblocking_filter_override_flag = 1 , then slice_tc_offset_div2 is signalled in slice segment header.
1275 int slice_cb_qp_offset : 5; // offset added to pps_cb_qp_offset. It shall be in the range -12 to +12.
1276 int slice_cr_qp_offset : 5; // offset added to pps_cr_qp_offset. It shall be in the range -12 to +12.
1277 unsigned int slice_temporal_mvp_enabled_flag : 1; // set 1, temporal motion vector predictors may be used
1278 unsigned int collocated_from_l0_flag : 1; // set 1, the collocated picture for tmvp is derived from ref. pic. list 0
1279 unsigned int collocated_ref_idx : 5; // specifies ref. index of the collocated picture for tmvp
1280 int reserved2 : 7;
1281
1282 unsigned int num_ref_idx_active_override_flag : 1;
1283 unsigned int num_ref_idx_l0_active_minus1 : 5; // [0.31]
1284 unsigned int num_ref_idx_l1_active_minus1 : 5; // [0,31]
1285 unsigned int me_control_idx : 4; // index in array of nvenc_h264_me_control_s to use for this slice
1286 unsigned int md_control_idx : 4; // index in array of nvenc_h264_md_control_s to use for this slice
1287 unsigned int q_control_idx : 4; // index in array of nvenc_h264_quant_control_s to use for this slice
1288 unsigned int wp_control_idx : 4; // index in array of nvenc_pred_weight_table_s to use for this slice
1289 unsigned int reserved3 : 5;
1290
1291 unsigned int limit_slice_top_boundary : 1; // limit ME to slice boundaries
1292 unsigned int limit_slice_bot_boundary : 1; // limit ME to slice boundaries
1293 unsigned int limit_slice_left_boundary : 1; // limit ME to slice boundaries
1294 unsigned int limit_slice_right_boundary : 1; // limit ME to slice boundaries
1295 unsigned int ROI_enable : 1; // Enable region of interest processing
1296 unsigned int ROI_me_control_idx : 4;
1297 unsigned int ROI_md_control_idx : 4;
1298 unsigned int ROI_q_control_idx : 4;
1299 unsigned int ROI_qp_delta : 8; // QP delta in ROI relative to picture outside ROI
1300 unsigned int reserved4 : 7; // reserved for alignment
1301
1302 unsigned int ROI_top_mbx : 16; // top left mbx of the ROI
1303 unsigned int ROI_top_mby : 16; // top left mby of the ROI
1304 unsigned int ROI_bot_mbx : 16; // bottom right mbx of the ROI
1305 unsigned int ROI_bot_mby : 16; // bottom right mby of the ROI
1306
1307 unsigned char reserved5[36]; // padding to 64 bytes
1308 } nvenc_h265_slice_control_s; // 64 bytes
1309
1310 // h265 not support QPP, reserved it but not used
1311 typedef struct
1312 {
1313 // QPP has not been defined for H265
1314 unsigned short qpp_run_vector_4x4; // cost values for 4x4 transform (16 bit total vector)
1315 unsigned short qpp_run_vector_8x8[3]; // cost values for 8x8 transform (48 bit total vector)
1316 // 2 bits each for first 12 coefs, then 1 bit each for next 24
1317 unsigned char qpp_luma8x8_cost; // luma 8x8 cost threshold, 0 = throw out all coefs, range 0-15
1318 unsigned char qpp_luma16x16_cost; // luma 16x16 cost threshold, 0 = throw out all coefs, range 0-15
1319 unsigned char qpp_chroma_cost; // chroma cost threshold, 0 = throw out all coefs, range 0-15
1320 unsigned char qpp_mode : 2; // 0 = OFF, 1 = 8x8, 2 = 16x16_8x8
1321 unsigned char reserved0 : 4; // padding
1322
1323 unsigned int reserved1; // padding to 16 bytes
1324 } nvenc_h265_quant_control_s; // 16 bytes
1325
1326 //*****************************************************************************
1327 // VP9
1328 //*****************************************************************************
1329
1330 //vp9 filter config
1331 typedef struct
1332 {
1333 unsigned char filter_level[8]; // loop filter strength for each segment.
1334 char ref_delta[4]; // Loop filter strength adjustments based on frame type (intra, inter)
1335 char mode_delta[2]; // Loop filter strength adjustments based on mode (zero, new mv)
1336 unsigned char disable : 1; // disable loop-filter
1337 unsigned char sharpness : 3; // sharpness level
1338 unsigned char baselevel_gt32 : 1; // filter base level greater than 32 flag
1339 unsigned char reserved : 3;
1340 unsigned char reserved2;
1341 }nvenc_vp9_filter_cfg_s; //16 bytes
1342
1343 typedef struct
1344 {
1345 unsigned int round_chroma_ac : 3; // round for chroma AC
1346 unsigned int round_chroma_dc : 3; // round for chroma DC
1347 unsigned int round_luma_ac : 3; // round for luma AC
1348 unsigned int round_luma_dc : 3; // round for luma DC
1349 unsigned int round_delta_inter : 3; // round delta for inter
1350 unsigned int reserved : 17;
1351 }vp9_round_cfg_s;
1352
1353 //vp9 quant config
1354 typedef struct
1355 {
1356 unsigned char qindex_seg[8]; // Base frame qindex (index in quant lookup table) for each segment 0...255
1357 int delta_y_dc : 5; // explicit qindex adjustment for y dccoefficient, -15...15
1358 int delta_uv_dc : 5; // qindex adjustment for uv accoefficient, -15...15
1359 int delta_uv_ac : 5; // qindex adjustment for uv dccoefficient, -15...15
1360 int reserved : 17;
1361 //round parameters
1362 vp9_round_cfg_s round_seg[8]; // round config for each segment
1363 }nvenc_vp9_quant_cfg_s; //44 bytes
1364
1365 // vp9 dma config for each tile
1366 typedef struct
1367 {
1368 unsigned int tile_width : 6; // tile width in super blocks(64x64)
1369 unsigned int tile_height : 6; // tile height in super blocks(64x64)
1370 unsigned int tile_pos_x : 6; // tile x-position in super blocks unit
1371 unsigned int reserved : 14;
1372 }nvenc_vp9_modedma_cfg_s;
1373
1374 //vp9 smalle config
1375 typedef struct
1376 {
1377 unsigned int high_prec_mv_enable : 1; // high precision mv enable
1378 unsigned int temporal_mv_enable : 1; // temporal mv enable
1379 unsigned int transform_mode : 3; // transform mode: 0: only4x4, 1: allow_8x8, 2: allow_16x16, 3: allow_32x32, 4:transform_mode_select
1380 unsigned int lossless_enable : 1; // lossless encoding enable
1381 unsigned int mocomp_filter_type : 3; // mocomp filter type:0 eight-tap smooth, 1: eight-tap, 2:eight-tap sharp, 3: bilinear, 4:switchable
1382 unsigned int tile_enable : 1; // enable tile encoding
1383 unsigned int segment_enable : 1; // enable segment
1384 unsigned int segment_upd_enable : 1; // enable explicit map update for current frame. If true, then segment_temp_enable says how to update
1385 unsigned int segment_temp_enable : 1; // Type of map update
1386 unsigned int reserved : 19;
1387 }nvenc_vp9_smalle_config_s;
1388
1389 //vp9 frame-level parameters
1390 typedef struct
1391 {
1392 unsigned int pic_width : 13; // picture width in pixels
1393 unsigned int pic_height : 13; // picture height in pixels
1394 unsigned int rec_disable : 1; // disable recon output
1395 unsigned int type : 1; // picture type: 0 Intra/1 Inter
1396 unsigned int refframe : 2; // reference frame type used 1 = last 2= golden 3= alt-ref
1397 unsigned int reserved : 2;
1398
1399 //ref-frame param
1400 unsigned char ref_index[8]; // ref-frame index for each segment
1401 //skip param
1402 unsigned char skip_mode[8]; // skip-mode enable for each segment: skip mode implies both the use of a (0,0) motion vector and that no residual will be coded
1403 //filter param
1404 nvenc_vp9_filter_cfg_s filter_cfg; // filter config
1405 //quant param
1406 nvenc_vp9_quant_cfg_s quant_cfg; // quant & round config
1407
1408 nvenc_vp9_smalle_config_s smalle_cfg; // small-e config
1409 unsigned int num_tile_controls_minus1; // number of nvenc_vp9_tile_control_s entries in array minus1
1410 unsigned int tile_controls_offset; // offset from start of top level "nvenc_vp9_pic_control_s" structure
1411 // to start of array of "nvenc_vp9_tile_control_s" structures
1412
1413 unsigned int bitstream_buf_start_pos; // bitstream buffer offset start position byte offset
1414 unsigned int bitstream_buf_size; // bitstream buffer size in bytes
1415
1416 unsigned int combined_linebuf_size; // combined line buffer size in bytes
1417
1418 unsigned int filterline_linebuf_size; // filter line line-buffer size in bytes
1419
1420 unsigned int filtercol_linebuf_size; // filter column line-buffer size in bytes
1421 }nvenc_vp9_pic_control_s; //112 bytes
1422
1423 typedef struct
1424 {
1425 unsigned int col_pos : 6; // tile position in Super Block of Y axis
1426 unsigned int bs_size : 24; // tile size in Super Block
1427 unsigned int reserved : 2;
1428 nvenc_vp9_modedma_cfg_s mode_dma_cfg; // mode-dma config for this tile
1429 unsigned char tile_idx; // tile index in the picture
1430 unsigned char reserved2[55];
1431 }nvenc_vp9_tile_control_s; //64bytes
1432
1433 typedef struct
1434 {
1435 unsigned char QP[3]; // QP for 0:P picture, ,1:B picture 2; I picture
1436 unsigned char minQP[3]; // min QP for 0:P picture, ,1:B picture 2; I picture
1437 unsigned char maxQP[3]; // max QP for 0:P picture, ,1:B picture 2; I picture
1438 unsigned char reserved[3];
1439 int rhopbi[3]; // 23.8 signed fixed point quant ratios P/I, B/I, I/I(=1)
1440
1441 int framerate; // fps
1442 unsigned int buffersize; // total buffer size
1443
1444 int nal_cpb_size; // size in bits
1445 int nal_bitrate; // rate in bps
1446
1447 int gop_length; // I period
1448 int Bmin; // 23.8 signed fixed point min buffer level, updated by driver at sequence level only.
1449 int Ravg; // 23.8 signed fixed point average rate, updated by driver at sequence level only.
1450 int R; // 23.8 signed fixed point rate
1451
1452
1453 } nvenc_vp9_rc_s; // 56 bytes, currently keep the same as vp8
1454
1455
1456 typedef struct
1457 {
1458 unsigned int picture_index; // value received from SetPictureIndex method
1459 unsigned int error_status : 2; // report error if any
1460 unsigned int ucode_error_status : 30; // report error status from ucode to driver
1461 unsigned int total_byte_count; // total bitstream size in bytes
1462 unsigned int bitstream_start_pos; // byte_offset where VP9 BS DMA start writing bitstream
1463 unsigned short pic_type; // inter/key frame type
1464 unsigned short avgQP; // average QP
1465 unsigned int cycle_count; // total cycles taked for execute. Written out only when DumpCycleCount in SetControlParams is set
1466 unsigned int intra_cu32x32_count; // number of intra 32x32 CUs.
1467 unsigned int inter_cu32x32_count; // number of inter 32x32 CUs.
1468 unsigned int intra_cu16x16_count; // number of intra 16x16 CUs.
1469 unsigned int inter_cu16x16_count; // number of inter 16x16 CUs.
1470 unsigned int intra_cu8x8_count; // number of intra 8x8 CUs.
1471 unsigned int inter_cu8x8_count; // number of inter 8x8 CUs.
1472 unsigned int cumulative_intra_cost; // sum of all intra SA(T)Ds
1473 unsigned int cumulative_inter_cost; // sum of all inter SA(T)Ds
1474 unsigned int total_intra_cost; // sum of all intra best mode's SATDs, each mb has one intra SATD.
1475 unsigned int total_inter_cost; // sum of all inter best mode's SATDs, each mb has one inter SATD.
1476
1477 } nvenc_vp9_pic_stat_s; // 64 bytes
1478
1479 // ****************************************************************************
1480 // ****************************************************************************
1481 // VP8
1482 // ****************************************************************************
1483 // ****************************************************************************
1484
1485 // TO DO: Find out if we should define # maxSegments as 4
1486 #define MAXSEGMENTS 4
1487
1488 typedef struct
1489 {
1490 unsigned short frame_width_minus1; // frame width in pixels minus 1, range 0-4095
1491 unsigned short frame_height_minus1; // frame height in pixels minus 1, range 0-4095
1492
1493 unsigned int sfc_pitch : 10; // pitch of luma plane in macorblock units( i.e stride >>4)
1494 unsigned int sfc_pitch_chroma : 10; // pitch of chroma plane in macroblock units
1495 unsigned int reserved2 : 12;
1496
1497 unsigned int sfc_trans_mode : 4; // least 3 significient bits are used to stand for 8 modes, normal, xflip, yflip etc.
1498 unsigned int block_height : 7; // BL mapping block height setting
1499 unsigned int tiled_16x16 : 1; // Surface is 16x16 tiled instead of BL mapped (must be 1 for refpics)
1500 unsigned int memory_mode : 2; // 0: semi-planar, 1: planar
1501 unsigned int input_bl_mode : 2; // the input block linear mode: 0~gpu bl; 1~tegra bl; 2~naive bl this is only for cmod and cmod/plugin
1502 unsigned int reserved : 16; // pad to int
1503
1504 unsigned int luma_top_frm_offset; // offset of luma top field or frame in units of 256
1505 unsigned int luma_bot_offset; // offset of luma bottom field in units of 256. Not used if frame format.
1506 unsigned int chroma_top_frm_offset; // offset of chroma top field or frame, or offset of chroma U(Cb) plane in planar mode, both in units of 256
1507 unsigned int chroma_bot_offset; // offset of chroma bottom field, not used if frame format. Or offset of chroma V(Cr) plane in planar mode. Both in units of 256.
1508
1509 } nvenc_vp8_surface_cfg_s; // 28 bytes
1510
1511 typedef struct
1512 {
1513 //unsigned int coeff_partitioning_enabled : 1; // 0: coefficient partitioning disabled 1: coeffient partitioning enabled (SE: redundant, same as multi_token_partition!=0)
1514 //unsigned int num_segments_minus_one : 2; // number of segments
1515 unsigned int horiz_scale : 2; // 0=1, 1=5/4, 2=5/3, 3=2
1516 unsigned int vert_scale : 2; // 0=1, 1=5/4, 2=5/3, 3=2
1517 //unsigned int golden_frame_enable : 1; // 0: golden frame disabled, 1: golden frame enabled
1518 //unsigned int alt_ref_frame_enable : 1; // 0: alt_ref_frame_disabled, 1: alt_ref_frame_enabled
1519 //unsigned int adaptive_golden_frame_selection : 1; // 0: fixed distance between golden frames 1: adaptive golden frame selection
1520 //unsigned int adaptive_altref_frame_selection : 1; // 0: fixed distance between alt ref frames 1: adaptive alt ref frame selection
1521 unsigned int reserved : 28; // Align to word boundary
1522
1523 //unsigned int golden_frame_interval : 16; // golden frame interval if adaptive_golden_frame_selection is fixed
1524 //unsigned int altref_frame_interval : 16; // altref frame interval if adaptive_altref_frame_selection is fixed
1525
1526 } nvenc_vp8_sequence_data_s; // 4 bytes
1527
1528 typedef struct
1529 {
1530 unsigned int frame_type : 1; // 0=key frame, 1=interframe
1531 unsigned int version : 3; // VP8 version, also affects luma/chroma mocomp: 0=bicubic/bicubic, 1,2=bilinear/bilinear, 3..7=bilinear/fullpel (SE: perhaps separate flags for bilinear/fullpel?)
1532 unsigned int show_frame : 1; // 0=don't display, 1=display
1533 unsigned int clr_type : 1; // color space: 0=ITU-R BT.601, 1=reserved (multiplier free)
1534 unsigned int clamp_type : 1; // 0=clamping of reconstructed samples required, 1=no clamping necessary (SE: not supported by NVENC?)
1535 // <loop filter parameters>
1536 unsigned int filter_type : 2; // 0=normal, 1=simple 2: disable (SE: filter_type==2 is redundant, same as filter_level==0)
1537 unsigned int filter_level : 6; // loop filter strength (1..63), 0=disabled
1538 unsigned int sharpness_level : 3; // loop filter sharpness (0..7)
1539 unsigned int mode_ref_lf_delta_enabled : 1; // apply mb param dependent loop filter level deltas: 0=disabled, 1=enabled; if disabled the following parameters are not used
1540 unsigned int mode_ref_lf_delta_update : 1; // update ref_lf_deltas and mode_lf_deltas: 0=keep previous, 1=update
1541 unsigned int ref_lf_deltas_update_0 : 1; // update ref_lf_deltas[0]: 0=keep previous, 1=update
1542 unsigned int ref_lf_deltas_update_1 : 1; // update ref_lf_deltas[1]: 0=keep previous, 1=update
1543 unsigned int ref_lf_deltas_update_2 : 1; // update ref_lf_deltas[2]: 0=keep previous, 1=update
1544 unsigned int ref_lf_deltas_update_3 : 1; // update ref_lf_deltas[3]: 0=keep previous, 1=update
1545 unsigned int mode_lf_deltas_update_0 : 1; // update mode_lf_deltas[0]: 0=keep previous, 1=update
1546 unsigned int mode_lf_deltas_update_1 : 1; // update mode_lf_deltas[1]: 0=keep previous, 1=update
1547 unsigned int mode_lf_deltas_update_2 : 1; // update mode_lf_deltas[2]: 0=keep previous, 1=update
1548 unsigned int mode_lf_deltas_update_3 : 1; // update mode_lf_deltas[3]: 0=keep previous, 1=update
1549 unsigned int reserved0 : 4; // Align to word boundary
1550 signed char ref_lf_deltas[4]; // reference frame dependent loop filter level delta (-63..+63)
1551 // Index 0: macroblock is INTRA
1552 // 1: macroblock is INTER and reference frame is LAST
1553 // 2: macroblock is INTER and reference frame is GOLDEN
1554 // 3: macroblock is INTER and reference frame is ALTREF
1555 // lower 7 bits of each entry used as a signed value -63..+63, MS Bit is ignored by HW (SE: invalid values should be rejected?)
1556 signed char mode_lf_deltas[4]; // macroblock mode dependent loop filter level delta (-63..+63)
1557 // Index 0: B_PRED (macroblock is INTRA 4x4)
1558 // 1: ZEROMV (macroblock is INTER and mode is ZEROMV)
1559 // 2: MV (macroblock is INTER and mode is neither ZEROMV nor SPLITMV)
1560 // 3: SPLITMV (macroblock is INTER and mode is SPLITMV (not 16x16))
1561 // lower 7 bits of each entry used as a signed value -63..+63, MS Bit is ignored by HW (SE: invalid values should be rejected?)
1562 // Other frame header parameters
1563 unsigned int multi_token_partition : 2; // number of tcoeff token partitions (0,1,2,3 -> 1,2,4,8): num_part = 1 << multi_token_partition
1564 unsigned int refresh_entropy_probs : 1; // 0=restore previous probs at end of frame, 1=keep updated probs for next frame
1565 unsigned int mb_no_coeff_skip : 1; // per-mb skip flag, 0=disable 1:enable (misnomer?)
1566 unsigned int update_ymode_prob : 1; // update ymode probs, 0=no, 1=yes
1567 unsigned int update_uvmode_prob : 1; // update uvmode probs, 0=no, 1=yes
1568 //unsigned int coef_update_probs : 1; // update tcoeff token probs, 0=no, 1=yes (SE: isnt't this redundant with coef_probs_update array?)
1569
1570 unsigned int base_qindex : 7; // quantizer index (0..127)
1571
1572 unsigned int refresh_last_frame : 1; // use decoded frame as last reference frame
1573 unsigned int refresh_golden_frame : 1; // use decoded frame as golden reference frame
1574 unsigned int refresh_alt_ref_frame : 1; // use decoded frame as alt_ref reference frame
1575 unsigned int copy_buffer_to_gf : 2; // update golden frame from: 0=none (keep), 1=last_frame, 2=alt_ref_frame
1576 unsigned int copy_buffer_to_arf : 2; // update alt_ref frame from: 0=none (keep), 1=last_frame, 2=golden_frame
1577 unsigned int ref_frame_sign_bias_gf : 1; // golden frame is future frame (invert mv sign)
1578 unsigned int ref_frame_sign_bias_arf : 1; // alt_ref frame is future frame (invert mv sign)
1579 unsigned int fixed_ref_frame_probs : 1; //use fixed ref frame probability
1580 unsigned int reserved1 : 9; // Align to word boundary
1581
1582
1583 signed int y1dc_delta_q : 5; // quantizer delta for luma DC (-15..+15)
1584 signed int y2dc_delta_q : 5; // quantizer delta for WHT DC (-15..+15)
1585 signed int y2ac_delta_q : 5; // quantizer delta for WHT AC (-15..+15)
1586 signed int uvdc_delta_q : 5; // quantizer delta for chroma DC (-15..+15)
1587 signed int uvac_delta_q : 5; // quantizer delta for chroma AC (-15..+15)
1588
1589 // <segmentation parameters>
1590 unsigned int segmentation_enabled : 1; // 0=disabled, 1=enabled; if disabled the following parameters are not used
1591 unsigned int update_mb_segmentation_map : 1; // per-mb segment ID map update: 0=keep previous, 1=update (SE: have to provide the actual map)
1592 unsigned int update_mb_segmentation_data : 1; // mb_segment_abs_delta, seg_filter_level, and seg_qindex update: 0=keep previous, 1=update
1593 unsigned int mb_segment_abs_delta : 1; // seg_filter_level and seg_qindex are: 0=delta values, 1=absolute values
1594 unsigned int reserved2 : 3; // Align to word boundary
1595 signed char seg_filter_level[MAXSEGMENTS]; // per-segment loop filter levels
1596 // if mb_segment_abs_delta==0: relative to filter_level (-63..+63)
1597 // if mb_segment_abs_delta==1: absolute value (0..63)
1598 signed char seg_qindex[MAXSEGMENTS]; // per-segment qindex values
1599 // if mb_segment_abs_delta==0: relative to base_qindex (-127..+127)
1600 // if mb_segment_abs_delta==1: absolute value (0..127)
1601
1602 } nvenc_vp8_picture_data_s; // 32 bytes
1603
1604 typedef struct
1605 {
1606 unsigned int early_intra_mode_control : 2; // 0=inter; 1=eval_intra; 2=ext_hint; 3=none (low perf,best qual)
1607 unsigned int early_intra_mode_type_16x16dc : 1; // evaluate 16x16dc if early_intra_mode_control==1
1608 unsigned int early_intra_mode_type_16x16h : 1; // evaluate 16x16h if early_intra_mode_control==1
1609 unsigned int early_intra_mode_type_16x16v : 1; // evaluate 16x16v if early_intra_mode_control==1
1610 unsigned int early_ip_is_final : 1; // if set, result of early intra is final (disable full intra search)
1611 unsigned int chroma_eval_mode : 1; // for intra chroma search 0 = U and V; 1 = U only
1612 unsigned int nearest_mv_enable : 1; // enable nearest mv mode for 16x16
1613 unsigned int near_mv_enable : 1; // enable near mv mode for 16x16
1614 unsigned int zero_mv_enable : 1; // enable zero mv mode 16x16
1615 unsigned int new_mv_enable : 1; // enable new mv mode 16x16
1616 unsigned int above4x4_mv_enable : 1; // enable above4x4 mv mode for VP8 SPLITMV modes
1617 unsigned int left4x4_mv_enable : 1; // enable left4x4 mv mode for VP8 SPLITMV modes
1618 unsigned int zero4x4_mv_enable : 1; // enable zero4x4 mv mode for VP8 SPLITMV modes
1619 unsigned int new4x4_mv_enable : 1; // enable new4x4 mv mode for VP8 SPLITMV modes
1620 unsigned int l0_part_16x16_enable : 1; // enable L0 prediction for 16x16
1621 unsigned int l0_part_16x8_enable : 1; // enable L0 prediction for 16x8
1622 unsigned int l0_part_8x16_enable : 1; // enable L0 prediction for 8x16
1623 unsigned int l0_part_8x8_enable : 1; // enable L0 prediction for 8x8
1624 unsigned int pskip_enable : 1; // enable p_skip encoding (still used by ME for special modes, can this be removed?)
1625 //unsigned int use_variance : 1; // to decide between inter and intra (Most likely wont be used)
1626 unsigned int explicit_eval_nearestmv : 1; // enable explicit search vp8 nearest mv
1627 unsigned int explicit_eval_nearmv : 1; // enable explicit search vp8 near mv
1628 unsigned int explicit_eval_left_topmv : 1; // enable explicit search vp8 8x8 left_top mv
1629 unsigned int explicit_eval_left_bottommv : 1; // enable explicit search vp8 8x8 left_bottom mv
1630 unsigned int explicit_eval_top_leftmv : 1; // enable explicit search vp8 8x8 top_left mv
1631 unsigned int explicit_eval_top_rightmv : 1; // enable explicit search vp8 8x8 top_right mv
1632 unsigned int explicit_eval_zeromv : 1; // enable explicit search vp8 zero mv
1633 unsigned int refframe_pic : 2; // reference frame type used 1 = last 2= golden 3= alt-ref
1634 unsigned int reserved0 : 3; // Pad to int
1635
1636 unsigned int intra_luma4x4_mode_enable : 9; // bitmask indicating which intra luma 4x4 modes to enable
1637 unsigned int intra_luma16x16_mode_enable : 4; // bitmask indicating which intra luma 16x16 modes to enable
1638 unsigned int intra_chroma_mode_enable : 4; // bitmask indicating which intra chroma modes to enable
1639 unsigned int intra_tm_mode_enable : 1; // bitmask indicating intra 4x4 true motion mode enable
1640 unsigned int ip_search_mode : 3; // which intra sizes to search before making IP decision b0=4x4,b2=16x16 // We dont need a bit for 8x8 for VP8 but it might be simpler for reg field to keep it?
1641 unsigned int mv_cost_enable : 1; // enable mv cost calculations in mode decision
1642 unsigned int reserved1 : 10; // pad to full int
1643
1644 unsigned short early_intra_disable_mpeb_threshold; // if early intra cost is below this, disable full search & select intra
1645 //unsigned short lambda_multiplier_mvcost; // used for mv cost calculation
1646 short bias_favor_intra_16x16_early; // bias for early intra (subtracts from early intra 16x16 cost)
1647
1648 unsigned short lambda_multiplier_intra[4]; // used for intra mode cost calculation [segment_id]
1649
1650 unsigned int mdpLambdaCoefMd :16;
1651 unsigned int mdpLambdaCoefMv :16;
1652
1653 short bias_intra_16x16; // bias for intra 16x16 (subtracts from intra 16x16 cost)
1654 short bias_intra_4x4; // bias for intra 4x4 (subtracts from intra 4x4 cost)
1655
1656 short bias_inter_16x16; // bias for inter 16x16 (subtracts from inter 16x16 cost)
1657 short bias_inter_16x8; // bias for inter 16x8 (subtracts from inter 16x8 cost)
1658
1659 short bias_inter_8x16; // bias for inter 8x16 (subtracts from inter 8x16 cost)
1660 short bias_inter_8x8; // bias for inter 8x8 (subtracts from inter 8x8 cost)
1661
1662 short bias_nearmv; // bias for nearmv (subtracts from nearmv cost) for 16x16
1663 short bias_nearestmv; // bias for nearestmv (subtracts from nearestmv cost) for 16x16
1664
1665 short bias_zeromv; // bias for zeromv (subtracts from zeromv cost) for 16x16
1666 short bias_newmv; // bias for newmv (subtracts from newmv cost) for 16x16
1667
1668 short bias_above4x4mv; // bias for above4x4mv (subtracts from above4x4 cost) for VP8 SPLITMV modes
1669 short bias_left4x4mv; // bias for left4x4mv (subtracts from left4x4 cost) for VP8 SPLITMV modes
1670
1671 short bias_zero4x4mv; // bias for zero4x4mv (subtracts from zero4x4 cost) for VP8 SPLITMV modes
1672 short bias_new4x4mv; // bias for new4x4mv (subtracts from new4x4 cost) for VP8 SPLITMV modes
1673
1674 short mv_cost_bias; // bias applied to internal motion vector cost calculation
1675 short bias_intra_over_inter; // bias for any intra (subtracts from intra cost)
1676 unsigned short intra_refresh_cnt; // distance between forced-intra MBs; 0 means OFF
1677 unsigned short intra_refresh_offs; // first forced-intra MB
1678
1679 unsigned short tempmv_wt_spread_threshold; // The threshold for the sum of difference between 8x8 and 16x16 mvs. Used for temporal mv weight.
1680 unsigned short tempmv_wt_distort_threshold; // The threshold for cost of the 16x16 mv. Used for temporal mv weight.
1681 } nvenc_vp8_md_control_s; // 64 bytes
1682
1683 typedef struct
1684 {
1685 unsigned int self_temporal_stamp_l0 : 3; // stamp to use for L0 integer search in stamp based mode
1686 //unsigned int self_temporal_stamp_l1 : 3; // stamp to use for L1 integer search in stamp based mode
1687 unsigned int self_temporal_explicit : 1; // explicitly evaluate these vectors
1688 unsigned int self_temporal_search : 1; // integer search enable for this hint
1689 unsigned int self_temporal_refine : 1; // subpel search enable for this hint
1690 unsigned int self_temporal_enable : 1; // hint enable (enables processing + fetching of data) (only changeable at first slice in picture)
1691
1692 unsigned int coloc_stamp_l0 : 3; // stamp to use for L0 integer search in stamp based mode
1693 //unsigned int coloc_stamp_l1 : 3; // stamp to use for L1 integer search in stamp based mode
1694 unsigned int coloc_explicit : 1; // explicitly evaluate these vectors
1695 unsigned int coloc_search : 1; // integer search enable for this hint
1696 unsigned int coloc_refine : 1; // subpel search enable for this hint
1697 unsigned int coloc_enable : 1; // hint enable (enables processing + fetching of data) (only changeable at first slice in picture)
1698
1699 unsigned int self_spatial_stamp_l0 : 3; // stamp to use for L0 integer search in stamp based mode
1700 //unsigned int self_spatial_stamp_l1 : 3; // stamp to use for L1 integer search in stamp based mode
1701 unsigned int self_spatial_explicit : 1; // explicitly evaluate these vectors
1702 unsigned int self_spatial_search : 1; // integer search enable for this hint
1703 unsigned int self_spatial_refine : 1; // subpel search enable for this hint
1704 unsigned int self_spatial_enable : 1; // hint enable (enables processing + fetching of data) (only changeable at first slice in picture)
1705
1706 unsigned int reserved0 : 11; // Pad to int
1707
1708 unsigned int external_stamp_lastref_stamp : 3; // Stamp to use for external L0 hint with refidx = 0
1709 unsigned int external_stamp_goldref_stamp : 3; // Stamp to use for external L0 hint with refidx = 1
1710 unsigned int external_stamp_altref_stamp : 3; // Stamp to use for external L0 hint with refidx = 2
1711 unsigned int external_explicit : 1; // explicitly evaluate these vectors
1712 unsigned int external_search : 1; // integer search enable for this hint
1713 unsigned int external_refine : 1; // subpel search enable for this hint
1714 unsigned int external_enable : 1; // hint enable (enables processing + fetching of data) (only changeable at first slice in picture)
1715
1716 unsigned int const_mv_stamp_l0 : 3; // stamp to use for L0 integer search in stamp based mode
1717 //unsigned int const_mv_stamp_l1 : 3; // stamp to use for L1 integer search in stamp based mode
1718 unsigned int const_mv_explicit : 1; // explicitly evaluate these vectors
1719 unsigned int const_mv_search : 1; // integer search enable for this hint
1720 unsigned int const_mv_refine : 1; // subpel search enable for this hint
1721 unsigned int const_mv_enable : 1; // hint enable (enables processing + fetching of data)
1722
1723 unsigned int reserved1 : 12; // pad to int
1724
1725 } nvenc_vp8_me_hint_cfg_s; // 8 bytes
1726
1727 // Same as H264 me_limit_mv struct
1728 typedef struct
1729 {
1730 unsigned int mv_limit_enable : 1; // 0=disable, 1=enable set the absolute MV range (Cisco flip camera request)
1731 unsigned int left_mvx_frac : 2; // vector X component fraction
1732 int left_mvx_int : 12; // vector X component integer portion
1733 unsigned int reserved1 : 1; // padding X to 16 bit
1734 unsigned int top_mvy_frac : 2; // vector Y component fraction
1735 int top_mvy_int : 10; // vector Y component integer portion
1736 unsigned int reserved2 : 4; // padding Y to 16 bit
1737
1738 unsigned int right_mvx_frac : 2; // vector X component fraction
1739 int right_mvx_int : 12; // vector X component integer portion
1740 unsigned int reserved3 : 2; // padding X to 16 bit
1741 unsigned int bottom_mvy_frac : 2; // vector Y component fraction
1742 int bottom_mvy_int : 10; // vector Y component integer portion
1743 unsigned int reserved4 : 4; // padding Y to 16 bit
1744
1745 } nvenc_vp8_me_limit_mv_s; // 8 bytes
1746
1747 typedef struct
1748 {
1749 unsigned int mvx_frac : 2; // vector X component fraction
1750 int mvx_int : 12; // vector X component integer portion
1751 unsigned int reserved_x : 2; // padding X to 16 bit
1752 unsigned int mvy_frac : 2; // vector Y component fraction
1753 int mvy_int : 10; // vector Y component integer portion
1754 unsigned int reserved_y : 4; // padding Y to 16 bit
1755
1756 } nvenc_vp8_me_const_vec_s; // 4 bytes
1757
1758 // TO DO: We are wasting ~7 ints here we can combine this to pack hor_adjust and ver_adjust in diff int
1759 // but dont do it if we are going to throw it away in padding anyways
1760 typedef struct
1761 {
1762 unsigned int bitmask[2] ; // 8x8 search point pattern bitmask
1763 unsigned int hor_adjust : 1; // shift hor based on lsb of pred
1764 unsigned int ver_adjust : 1; // shift ver based on lsb of pred
1765 unsigned int reserved : 30;
1766
1767 } nvenc_vp8_me_stamp_s; // 12 bytes
1768
1769 typedef struct
1770 {
1771 unsigned int me_predictor_mode : 1; // 0=MDP, 1=const
1772 unsigned int refinement_mode : 1; // 0=hpel, 1=qpel
1773 unsigned int lambda_mode : 1; // 0=MDP, 1=const
1774 unsigned int const_lambda : 11; // U8.3 format lambda, used if lambda_mode=1
1775 unsigned int refine_on_search_enable : 1; // 0=disable, 1=enable subpel refine for search candidates
1776 unsigned int me_only_mode : 1;
1777 unsigned int fps_mvcost : 1;
1778 unsigned int sps_mvcost : 1;
1779 unsigned int sps_cost_func : 1;
1780 unsigned int me_icc_mode_mad : 1;
1781 unsigned int sps_filter : 3;
1782 unsigned int mc_filter : 3;
1783 unsigned int mbc_ctrl_arbitor : 2;
1784 unsigned int average_mvhint_enable : 1;
1785 unsigned int rmvp_source_half_scaled : 1; // only support picture size half scale down in horz&vert
1786 unsigned int reserved : 2;
1787
1788 nvenc_vp8_me_limit_mv_s limit_mv;
1789 nvenc_vp8_me_hint_cfg_s predsrc; // predictor sources
1790 nvenc_vp8_me_const_vec_s l0_hint; // constant MV used as L0 hint
1791 nvenc_vp8_me_const_vec_s l1_hint; // constant MV used as L1 hint
1792 nvenc_vp8_me_const_vec_s l0_pred; // constant MV used as L0 predictor
1793 // should this be made an array?
1794 nvenc_vp8_me_stamp_s shape0; // priority 0 stamping pattern
1795 nvenc_vp8_me_stamp_s shape1; // priority 1 stamping pattern
1796 nvenc_vp8_me_stamp_s shape2; // priority 2 stamping pattern
1797 nvenc_vp8_me_stamp_s shape3; // priority 3 stamping pattern
1798 nvenc_vp8_me_stamp_s shape4; // priority 4 stamping pattern
1799 nvenc_vp8_me_stamp_s shape5; // priority 5 stamping pattern
1800 nvenc_vp8_me_stamp_s shape6; // priority 6 stamping pattern
1801 nvenc_vp8_me_stamp_s shape7; // priority 7 stamping pattern
1802
1803 nvenc_me_tebif_s teb_para; // teb parameters
1804 unsigned char mbc_mb_size; // MBC size in MB
1805 unsigned char tempmv_scale; // temporal mv scale
1806 unsigned char reserved1[2];
1807
1808 } nvenc_vp8_me_control_s; // 136 bytes
1809
1810 typedef struct
1811 {
1812 unsigned int qpp_run_vector_4x4 : 16; // cost values for 4x4 transform (16 bit total vector)
1813 unsigned int qpp_luma8x8_cost : 4; // luma 8x8 cost threshold, 0 = throw out all coefs, range 0-15
1814 unsigned int qpp_luma16x16_cost : 4; // luma 16x16 cost threshold, 0 = throw out all coefs, range 0-15
1815 unsigned int qpp_chroma_cost : 4; // chroma cost threshold, 0 = throw out all coefs, range 0-15
1816 unsigned int qpp_mode : 2; // 0 = OFF, 1 = 8x8, 2 = 16x16_8x8
1817 //unsigned int quant_intra_sat_flag : 1; // 0: no saturation is applied; 1: saturation is applied
1818 //unsigned int quant_inter_sat_flag : 1; // 0: no saturation is applied; 1: saturation is applied
1819 unsigned int reserved : 2;
1820
1821 //unsigned int quant_intra_sat_limit : 16; // quantization saturation limit for intra MB
1822 //unsigned int quant_inter_sat_limit : 16; // quantization saturation limit for inter MB
1823
1824 unsigned short dz_4x4_YI[16]; // deadzone for 4x4 transform of Luma Intra
1825 unsigned short dz_4x4_YP[16]; // deadzone for 4x4 transform of Luma Inter
1826 unsigned short dz_4x4_CI; // deadzone for 4x4 transform of Chroma Intra
1827 unsigned short dz_4x4_CP; // deadzone for 4x4 transform of Chroma Inter
1828
1829 } nvenc_vp8_quant_control_s; // 72 bytes
1830
1831 typedef struct
1832 {
1833 //char temp_dist_l0[3]; // temporal distance of each ref pic (last, gold, altref)
1834 //char reserved;
1835 unsigned int hist_buf_size; // size in bytes of the buffer allocated for history
1836 unsigned int bitstream_buf_size; // size in bytes of the buffer allocated for bitstream slice/mb data
1837 unsigned int bitstream_start_pos; // start position in bitstream buffer where data should be written (byte offset)
1838 unsigned int bitstream_residual_buf_size; // size in bytes of the buffer allocated for residual partition bitstream slice/mb data
1839 unsigned int bitstream_residual_start_pos[8]; // start position in residual partition bitstream buffer where data for residual partitions should be written (byte offset)
1840
1841 } nvenc_vp8_pic_control_s; // 48 bytes
1842
1843 typedef struct
1844 {
1845 //unsigned char hrd_type; // nal (=2) and vcl (=1) type
1846 unsigned char QP[3]; // QP for 0:P picture, ,1:B picture 2; I picture
1847 unsigned char minQP[3]; // min QP for 0:P picture, ,1:B picture 2; I picture
1848 unsigned char maxQP[3]; // max QP for 0:P picture, ,1:B picture 2; I picture
1849 //unsigned char maxQPD; // max QP delta between two consecutive QP updates
1850 //unsigned char baseQPD; // initial QP delta between two consecutive QP updates
1851 unsigned char reserved[3];
1852 int rhopbi[3]; // 23.8 signed fixed point quant ratios P/I, B/I, I/I(=1)
1853
1854 int framerate; // fps
1855 unsigned int buffersize; // total buffer size
1856
1857 int nal_cpb_size; // size in bits
1858 int nal_bitrate; // rate in bps
1859 //int vcl_cpb_size; // size in bits
1860 //int vcl_bitrate; // rate in bps
1861
1862 int gop_length; // I period
1863 //int Np; // 27.4 signed fixed (gop_length + num_b_frames -1)/(num_b_frames + 1)
1864 int Bmin; // 23.8 signed fixed point min buffer level, updated by driver at sequence level only.
1865 int Ravg; // 23.8 signed fixed point average rate, updated by driver at sequence level only.
1866 int R; // 23.8 signed fixed point rate
1867
1868 //unsigned char ab_alpha; // weight of prev frame activity compared to part of the current picture
1869 //unsigned char ab_beta; // weight of current activity compared to neighbors
1870 //unsigned short prev_act; // average activity level of the first reference (L0)
1871 } nvenc_vp8_rc_s; // 56 bytes
1872
1873 typedef struct
1874 {
1875 // 256 aligned
1876 unsigned int magic; // magic number
1877 nvenc_vp8_surface_cfg_s refpic_cfg; // 28 bytes
1878 nvenc_vp8_surface_cfg_s input_cfg; // 28 bytes
1879 nvenc_vp8_surface_cfg_s outputpic_cfg; // 28 bytes
1880 nvenc_vp8_sequence_data_s sequence_data; // 4 bytes
1881 nvenc_vp8_picture_data_s picture_data; // 32 bytes
1882 nvenc_vp8_pic_control_s pic_control; // 48 bytes
1883 nvenc_vp8_me_control_s me_control; // 136 bytes
1884 nvenc_vp8_md_control_s md_control; // 64 bytes
1885 nvenc_vp8_quant_control_s quant_control; // 72 bytes
1886 nvenc_vp8_rc_s rate_control; // 56 bytes
1887 unsigned char reserved[16]; // pad to 512 bytes
1888
1889 } nvenc_vp8_drv_pic_setup_s; // 512 bytes
1890
1891
1892 // 2.2. Colocated Motion Data Buffer
1893 // ---------------------------------
1894 //
1895 // This buffer will be used to store co-located motion data. This data is produced for
1896 // pictures that are marked as reference pictures. The buffer is not needed for non-
1897 // reference pictures and in such case the corresponding method may be skipped. The
1898 // data in this buffer will be needed for future pictures encoded by both CEA and NVENC.
1899 // There are two of these buffers: one output, written only if the current picture is a
1900 // reference picture, and one input, read if the current picture is being encoded
1901 // as a B picture, and possible also during P picture to serve as hints for motion search.
1902 // Each buffer holds coloc data for all macroblocks in the picture. This
1903 // data is packed into an array of 16 entries of 4 bytes. Each entry holds one motion
1904 // vector and 6 bits of additional data, which is formatted as follows:
1905 //
1906 // coldata array entry N: contents of 'e':
1907 // 0, 4, 8, 12 0 = bottom field flag for ref picture
1908 // 4..1 = reference picture number (index in DPB)
1909 // 5 = zero
1910 // 1, 5, 9, 13 3..0 = ColZero flag for blocks N+2 .. N-1
1911 // 5..4 = subpartition size for 8x8 block (N-1)/4
1912 // (0=8x8, 1=8x4, 2=4x8, 3=4x4)
1913 // 15 0 = field mode flag
1914 // 1 = intra coded
1915 // 3..2 = partition size for macroblock
1916 // (0=16x16, 1=16x8, 2=8x16, 3=8x8)
1917 // 5..4 = zero
1918 // all others 5..0 = zero
1919 //
1920 // Note that motion vectors are duplicated for each 4x4 index from the top-left 4x4 block
1921 // of each (sub)partition. Note also that since NVENC does not currently support sub-8x8
1922 // inter partitioning, the 4 vectors within an 8x8 are replicated values.
1923
1924 typedef struct
1925 {
1926 unsigned int mvx : 14; // bit 0..13: x component of MV
1927 unsigned int mvy : 12; // bit 14..25: y component of MV
1928 unsigned int e : 6; // bit 26..31: extra data, different per entry
1929 } nvenc_h264_coloc_entry_s;
1930
1931 typedef struct // 64 byte aligned block
1932 {
1933 nvenc_h264_coloc_entry_s coldata[16]; // col data for 1 macroblock = array of 16 entries
1934 } nvenc_h264_coloc_mb_s;
1935
1936
1937 // 2.3. History Buffer
1938 // -------------------
1939 //
1940 // This buffer will be used to keep history data (data produced for one macroblock that
1941 // must be kept until the macroblock in the row directly below is processed). This buffer
1942 // should be at least as large as (((frame_width_minus1+16) / 16) + 16)*128 bytes.
1943 //
1944 // After the execute completes, the data in this buffer is no longer needed and the
1945 // buffer can be discarded/deallocated.
1946 //
1947 // The internal structure of the history record is implementation specific and therefore
1948 // subject to change. The data is produced and consumed by NVENC only and should never be
1949 // interpreted by any other engine or by software. The current structure is defined in
1950 // the following visio document in the HW development tree:
1951 //
1952 // doc/nvenc/arch/hist_layout.vsd
1953 //
1954 // 2.4. Reference and Input Picture Buffer
1955 // ---------------------------------------
1956 //
1957 // Reference Picture Buffer contains reference pictures produced by NVENC during
1958 // encode opeations of previous pictures. The Input Picture Buffer contains the
1959 // current picture that needs to be encoded into a bitstream.
1960 //
1961 // Each picture is actually a separate buffer with its own surface offset method.
1962 // Relative position of luma, chroma fields are defined in the picture setup buffer
1963 // and shown in the figure below.
1964 //
1965 // Driver needs to send SetRefPicOffset#() method for only the used reference pictures
1966 // for the current execute.
1967 //
1968 // Pictures are by default stored in NV24 field or NV12 frame format. NVENC will
1969 // always output in the same format as the current picture that is being encoded
1970 // (frame or field). True picaff (using frame refs to encode a field or using field
1971 // refs to encode a frame) is NOT supported.
1972 //
1973 // The input picture must contain fields if the picture is to be encoded as fields,
1974 // and must contain frames if the picture is to be encoded as a frame.
1975 //
1976 //
1977 // +---------------+ <-- RefPicOffset (start of buffer)
1978 // |XXXXXXXXXXXXXXX|
1979 // +---------------+ <-- luma_top_frm_offset (in picture setup buffer, in units of 256 bytes)
1980 // |TOP/FRM luma |
1981 // | |
1982 // +XXXXXXXXXXXXXXX+
1983 // +---------------+ <-- luma_bot_offset
1984 // |BOTTOM luma |
1985 // | |
1986 // +XXXXXXXXXXXXXXX+
1987 // +---------------+ <-- chroma_top_frm_offset
1988 // |TOP/FRM chroma |
1989 // +XXXXXXXXXXXXXXX+
1990 // +---------------+ <-- chroma_bot_offset
1991 // |BOTTOM chroma |
1992 // +XXXXXXXXXXXXXXX+
1993 // +---------------+ <-- end of buffer
1994 //
1995 //
1996 // 2.5. CEA Hints Data Buffer
1997 // ---------------------------
1998 //
1999 // CEA (a CUDA based integer motion search kernel) can provide hints to NVENC.
2000 // These hints can either be taken as explicit vectors to evaluate or as guides
2001 // for NVENC's built-in integer search.
2002 // In this mode of operation, CEA and NVENC typically work on the same frame,
2003 // with CEA slightly leading (by a few macroblock rows). NVENC would then read
2004 // in the data already produced by CEA for the current picture and use it. CEA
2005 // has to provide information on how many macroblocks worth of data it has
2006 // already completed and written out into this buffer, so that NVENC can read
2007 // up to that point. The buffer must be big enough to contain all data for the
2008 // entire frame.
2009 //
2010 // This buffer consists of 2 sections: a header and a data section. One such
2011 // buffer must be provided/allocated by driver for each picture that needs to
2012 // be encoded. The header section must be prefilled with zeroes by driver. The
2013 // data section can remain uninitialized.
2014 //
2015 // The data section contains the motion vector candidates for each macroblock.
2016 // It is written by CEA and read by NVENC.
2017 //
2018 // The header section contains flow control and status information produced by
2019 // CEA for this picture, and contains an offset to the start of the data
2020 // section. The header section begins at offset 0 in this buffer.
2021
2022
2023 typedef struct
2024 {
2025 unsigned int cand_cnt_blk_16x16 : 4; // 3:0 Number of candidates per block types
2026 unsigned int cand_cnt_blk_16x8 : 4; // 7:4
2027 unsigned int cand_cnt_blk_8x16 : 4; // 11:8
2028 unsigned int cand_cnt_blk_8x8 : 4; // 15:12
2029 unsigned int cand_cnt_blk_8x4 : 4; // 19:16
2030 unsigned int cand_cnt_blk_4x8 : 4; // 23:20
2031 unsigned int cand_cnt_blk_4x4 : 4; // 27:24
2032 unsigned int cand_bdirect_spatial_zmv : 1; // 28 enable Spatial direct enable ZMV 4x4 scores
2033 unsigned int cand_bdirect_spatial_nzmv : 1; // 29 enable Spatial direct enable non-zero MV 4x4 scores
2034 unsigned int cand_bdirect_temporal : 1; // 30 enable Temporal direct mode. Only valid for Bi-type.
2035 unsigned int cand_pskip : 1; // 31 enable p-skip mode. Only valid for L0 controls.
2036 } cea_cand_count_blktype_s;
2037
2038 typedef struct
2039 {
2040 // 64 aligned
2041 unsigned int picture_index; // picture index given by driver (via method)
2042 unsigned int data_start; // start offset in buffer of data section which must be 256B aligned
2043 // the following fields are only there right now to make it easier to implement the cmodel plugin mode
2044 // they might be removed at a later stage
2045 unsigned int cea_lambda;
2046 cea_cand_count_blktype_s blk_counts[3];
2047 int reserved[10]; //padded by 8 bytes to align the end of the structure to 32 bytes for dmread operations
2048 } cea_hints_header_s;
2049
2050
2051 // Please refer to the document named "nvenc_cea_mvinfo_format.doc" for more information.
2052 // This document can be found in the nvenc HW development tree under doc/nvenc/arch
2053
2054 typedef struct
2055 {
2056 int mvx : 12; // 11:00 x component of integer pixel MV (relative to current MB) S12.0
2057 int mvy : 10; // 21:12 y component of integer pixel MV (relative to current MB) S10.0
2058 int refidx : 5; // 26:22 reference index (31=invalid)
2059 int dir : 1; // 27:27 0=L0 1=L1
2060 int part_type : 2; // 29:28 0=16x16 1=16x8 2=8x16 3=8x8 (blocks in partition must be consecutive)
2061 int last_of_part: 1; // 30:30 last MV of (sub) partition
2062 int last_of_mb : 1; // 31:31 last MV of macroblock
2063 } cea_hint_s;
2064
2065 // External hint data structure for Orin AV1
2066 typedef struct
2067 {
2068 short refidx : 5; // 4:0 reference index (31=invalid)
2069 short direction : 1; // 5:5 0=L0 1=L1
2070 short bi : 1; // 6:6 0=single mv, 1=compound mv
2071 short partition_type : 3; // 9:7 parition type: 0: 2NX2N, 1:2NxN, 2:Nx2N. reserved 3bits for modes in later projects
2072 short x8 : 3; // 12:10 x8: current parition's top left x position in 8 pixel unit
2073 short last_of_cu : 1; // 13:13 last mv of current CU
2074 short last_of_sb : 1; // 14:14 last mv of current SB
2075 short reserved0 : 1;
2076
2077 short mvx : 14; // 13:0 mvx, in S12.2 format
2078 short cu_size : 2; // 15:14 CU size: 0: 8x8, 1: 16x16, 2:32x32, 3:64x64
2079
2080 short mvy : 12; // 11:0 mvy, in S10.2 format
2081 short y8 : 3; // 14:12 y8: current parition's top left y position in 8 pixel unit
2082 short reserved1 : 1;
2083 } av1_hint_data; //6 bytes
2084
2085
2086 typedef struct
2087 {
2088 unsigned int segID[4]; //segment ID for one MB. each 4x4 block has a segID which is 8 bits, total is 8bitx16 = 128 bits. maximun segments supported is 32
2089 } cea_segment_s;
2090
2091
2092
2093 // 2.6. Encoder Status Buffer
2094 // ---------------------------
2095 //
2096 // This buffer provides some additional data about the encoded bit stream that can
2097 // be used for rate control and multi-pass encoding as well as status information
2098 // that can be used for debug.
2099
2100 typedef struct
2101 {
2102 unsigned int picture_index; // value received from SetPictureIndex method
2103 unsigned int error_status : 2; // report error if any
2104 unsigned int ucode_error_status : 30; // report error status from ucode to driver
2105 unsigned int total_bit_count; // picture size in bits
2106 unsigned int type1_bit_count; // type1 bit count for the entire picture
2107 unsigned short pic_type; // copied from pic_type in nvenc_h264_pic_control_s
2108 unsigned short num_slices; // number of slices produced
2109 unsigned short ave_activity; // report average activity if activity based RC enabled
2110 unsigned short avgQP; // average QP
2111 unsigned int cycle_count; // total cycles taked for execute. Written out only when DumpCycleCount in SetControlParams is set
2112 int hrdFullness;
2113 unsigned int bitstream_start_pos; // byte_offset where mpec will start writing slice header
2114 unsigned int last_valid_byte_offset; // greatest offset in output buffer which is assured to have valid compressed data
2115 unsigned short intra_mb_count; // number of intra MBs.
2116 unsigned short inter_mb_count; // number of inter MBs.
2117 unsigned int cumulative_intra_cost; // sum of all intra SA(T)Ds
2118 unsigned int cumulative_inter_cost; // sum of all inter SA(T)Ds
2119 unsigned int total_intra_cost; // sum of all intra best mode's SATDs, each mb has one intra SATD.
2120 unsigned int total_inter_cost; // sum of all inter best mode's SATDs, each mb has one inter SATD.
2121 unsigned int complexity; // sum of mbRowBitcount * current QS
2122 short average_mvx; // average mvx info, can be used for ME hint
2123 short average_mvy; // average mvy info, can be used for ME hint
2124 unsigned short actual_min_qp_used; // actual minimum qp used in the frame
2125 unsigned short actual_max_qp_used; // actual maximum qp used in the frame
2126 unsigned int hw_perf_me_sps; // me slice per second
2127 unsigned int hw_perf_me_fps; // me frame per second
2128 unsigned int hw_perf_mpec_active_cnt; // mpec active count
2129 unsigned int hw_perf_mpeb_active_cnt; // mpeb active count
2130 unsigned long long int total_dist_ssd; // sum of all ssd distortion of the MB best mode
2131 unsigned int total_dist_ssim; // sum of all ssim distortion of the MB best mode
2132 unsigned int best_satd_l0; // sum of all best satd cost of L0
2133 unsigned int best_satd_l1; // sum of all best satd cost of L1
2134 unsigned int reserved[5]; // align to 128 bytes
2135
2136 } nvenc_pic_stat_s; // 128 bytes
2137
2138
2139 typedef struct
2140 {
2141 unsigned int slice_offset; // slice offset in bytes
2142 unsigned int slice_size; // slice size in bytes
2143 unsigned int slh_bit_count; // slice header size in bits
2144 unsigned char reserved[4];
2145 } nvenc_slice_stat_s; // 16 bytes per status
2146
2147
2148 typedef struct
2149 {
2150 unsigned int intra_res_bit_count; // #bits spent on intra residuals
2151 unsigned int inter_res_bit_count; // #bits spent on inter residuals
2152 unsigned int intra_mode_bit_count; // #bits spent on intra modes (mbtype, pred mode)
2153 unsigned int inter_mode_bit_count; // #bits spent on inter modes (mbtype, submbtype, refidx, mv)
2154 unsigned int ipcm_bit_count; // # bits spent on MB mode that caused IPCM rewind.
2155 unsigned int type1_bit_count; // count of bits in type I bitstream (excludes leading_zero_8bits,
2156 // start_codeprefix_one_3bytes and trailing_zero_8bits)
2157 unsigned int total_bit_count; // total number of bits produced
2158
2159 unsigned int total_bin_count; // total number of bins produced by cabac
2160 unsigned int cumulative_intra_cost; // sum of all intra SA(T)Ds
2161 unsigned int cumulative_inter_cost; // sum of all inter SA(T)Ds
2162 unsigned int cumulative_ipcm_cost; // sum of all inter SA(T)Ds for the MBs that caused IPCM rewind
2163 unsigned int cumulative_skip_cost; // sum of all P and B skip MB SA(T)Ds
2164
2165 unsigned short intra_mb_count; // number of intra MBs.
2166 unsigned short inter_mb_count; // number of inter MBs.
2167 unsigned short skip_mb_count; // number of skip MBs.
2168 unsigned short ipcm_mb_count; // number of ipcm MBs.
2169
2170 unsigned int total_intra_cost; // sum of all intra best mode's SATDs, each ctb has one intra SATD.
2171 unsigned int total_inter_cost; // sum of all inter best mode's SATDs, each ctb has one inter SATD.
2172 } nvenc_mpec_stat_s; // 64 bytes per status
2173
2174 typedef struct
2175 {
2176 unsigned int qp_val : 8 ; // qp used for encoding this block
2177 unsigned int total_bit_count : 24 ; // total number of bits produced
2178 unsigned int res_cost : 24 ; // satd cost of residual error
2179 unsigned int flags : 8 ; // flags
2180 } nvenc_stats_fifo_s; // 8 bytes per stat
2181
2182 typedef struct
2183 {
2184 nvenc_pic_stat_s pic_stat; // 64Bytes
2185 nvenc_slice_stat_s slice_stat[((4096/16)*(4096/16)) + 3]; // To account for 1mb/slice and 4kx4k, plus 3 for alignment
2186 nvenc_mpec_stat_s mpec_stat[((4096/16)*(4096/16)) + 3]; // To account for stat/1mb and 4kx4k, plus 3 for alignment
2187 nvenc_aq_stat_s aq_stats[((4096/16)*(4096/16)) + 3]; // AQ stats from PDMA
2188 nvenc_stats_fifo_s stats_fifo[((4096/16)*(4096/16)) + 3];
2189 } nvenc_stat_data_s;
2190
2191 typedef struct
2192 {
2193 unsigned int picture_index; // value received from SetPictureIndex method
2194 unsigned int error_status : 2; // report error if any
2195 unsigned int ucode_error_status : 30; // report error status from ucode to driver
2196 unsigned int total_bit_count; // picture size in bits
2197 unsigned int type1_bit_count; // type1 bit count for the entire picture
2198 unsigned short pic_type; // copied from pic_type in nvenc_h264_pic_control_s
2199 unsigned short num_slices; // number of slices produced, maxinum slice number is 65535
2200 unsigned short ave_activity; // report average activity if activity based RC enabled
2201 unsigned short avgQP; // average QP
2202 unsigned int cycle_count; // total cycles taked for execute. Written out only when DumpCycleCount in SetControlParams is set
2203 int hrdFullness;
2204 unsigned int bitstream_start_pos; // byte_offset where mpec will start writing slice header
2205 unsigned int last_valid_byte_offset; // greatest offset in output buffer which is assured to have valid compressed data
2206 unsigned int intra_cu32x32_count; // number of intra 32x32 CUs.
2207 unsigned int inter_cu32x32_count; // number of inter 32x32 CUs.
2208 unsigned int intra_cu16x16_count; // number of intra 16x16 CUs.
2209 unsigned int inter_cu16x16_count; // number of inter 16x16 CUs.
2210 unsigned int intra_cu8x8_count; // number of intra 8x8 CUs.
2211 unsigned int inter_cu8x8_count; // number of inter 8x8 CUs.
2212 unsigned int cumulative_intra_cost; // sum of all intra SA(T)Ds
2213 unsigned int cumulative_inter_cost; // sum of all inter SA(T)Ds
2214 unsigned int total_intra_cost; // sum of all intra best mode's SATDs, each mb has one intra SATD.
2215 unsigned int total_inter_cost; // sum of all inter best mode's SATDs, each mb has one inter SATD.
2216 short average_mvx; // average mvx info, can be used for ME hint
2217 short average_mvy; // average mvy info, can be used for ME hint
2218 unsigned short actual_min_qp_used; // actual minimum qp used in the frame
2219 unsigned short actual_max_qp_used; // actual maximum qp used in the frame
2220 unsigned int hw_perf_me_sps; // me slice per second
2221 unsigned int hw_perf_me_fps; // me frame per second
2222 unsigned int hw_perf_mpec_active_cnt; // mpec active count
2223 unsigned int hw_perf_mpeb_active_cnt; // mpeb active count
2224 unsigned char reserved[24];
2225 } nvenc_h265_pic_stat_s; // 128 bytes
2226
2227 typedef struct
2228 {
2229 unsigned int slice_offset; // slice offset in bytes
2230 unsigned int slice_size; // slice size in bytes
2231 unsigned int slh_bit_count; // slice header size in bits
2232 unsigned int slice_size_ctbs; // slice size in ctbs
2233 }nvenc_h265_slice_stat_s; // 16 bytes per status
2234
2235 typedef struct
2236 {
2237 unsigned int intra_res_bit_count; // #bits spent on intra residuals
2238 unsigned int inter_res_bit_count; // #bits spent on inter residuals
2239 unsigned int intra_mode_bit_count; // #bits spent on intra modes (mbtype, pred mode)
2240 unsigned int inter_mode_bit_count; // #bits spent on inter modes (mbtype, submbtype, refidx, mv)
2241 unsigned int ipcm_bit_count; // # bits spent on MB mode that caused IPCM rewind.
2242 unsigned int type1_bit_count; // count of bits in type I bitstream (excludes leading_zero_8bits,
2243 // start_codeprefix_one_3bytes and trailing_zero_8bits)
2244 unsigned int total_bit_count; // total number of bits produced
2245
2246 unsigned int total_bin_count; // total number of bins produced by cabac
2247 unsigned int cumulative_intra_cost; // sum of all intra SA(T)Ds
2248 unsigned int cumulative_inter_cost; // sum of all inter SA(T)Ds
2249 unsigned int cumulative_ipcm_cost; // sum of all inter SA(T)Ds for the MBs that caused IPCM rewind
2250 unsigned int cumulative_skip_cost; // sum of all P and B skip MB SA(T)Ds
2251 unsigned int total_intra_cost; // sum of all intra best mode's SATDs, each ctb has one intra SATD.
2252 unsigned int total_inter_cost; // sum of all inter best mode's SATDs, each ctb has one inter SATD.
2253
2254 unsigned int intra_cu32x32_count; // number of intra 32x32 CUs.
2255 unsigned int inter_cu32x32_count; // number of inter 32x32 CUs.
2256 unsigned int skip_cu32x32_count; // number of skip 32x32 CUs.
2257 unsigned int ipcm_cu32x32_count; // number of ipcm 32x32 CUs.
2258 unsigned int intra_cu16x16_count; // number of intra 16x16 CUs.
2259 unsigned int inter_cu16x16_count; // number of inter 16x16 CUs.
2260 unsigned int skip_cu16x16_count; // number of skip 16x16 CUs.
2261 unsigned int ipcm_cu16x16_count; // number of ipcm 16x16 CUs.
2262 unsigned int intra_cu8x8_count; // number of intra 8x8 CUs.
2263 unsigned int inter_cu8x8_count; // number of inter 8x8 CUs.
2264 unsigned int skip_cu8x8_count; // number of skip 8x8 CUs.
2265 unsigned int ipcm_cu8x8_count; // number of ipcm 8x8 CUs.
2266
2267 unsigned int total_emulated_bit_count; // total number of emulated bits in total_bit_count
2268 unsigned char reserved[20];
2269 } nvenc_h265_mpec_stat_s; // 128 bytes per status
2270
2271 typedef struct
2272 {
2273 unsigned int var_min;
2274 unsigned int var_max;
2275 unsigned int var_avg;
2276 unsigned char reserved[4];
2277 } nvenc_h265_aq_stat_s; // 16 bytes
2278
2279 typedef struct
2280 {
2281 unsigned int qp_val : 8 ; // qp used for encoding this block
2282 unsigned int total_bit_count : 24 ; // total number of bits produced
2283 unsigned int res_cost : 24 ; // satd cost of residual error
2284 unsigned int flags : 8 ; // flags
2285 } nvenc_h265_stats_fifo_s; // 8 bytes per stat
2286
2287 typedef struct
2288 {
2289 nvenc_h265_pic_stat_s pic_stat; // 64Bytes
2290 nvenc_h265_slice_stat_s slice_stat[((4096/16)*(4096/16)) + 3]; // To account for 1mb/slice and 4kx4k, plus 3 for alignment. support upto 65535 slices
2291 nvenc_h265_mpec_stat_s mpec_stat[((4096/16)*(4096/16)) + 3]; // To account for stat/1mb and 4kx4k, plus 3 for alignment. support upto 65535 slices
2292 nvenc_h265_aq_stat_s aq_stats [((4096/16)*(4096/16)) + 3]; // AQ stats from pdma. support upto 65535 slices
2293 nvenc_h265_stats_fifo_s stats_fifo[((4096/16)*(4096/16)) + 3];
2294 } nvenc_h265_stat_data_s;
2295
2296 typedef struct
2297 {
2298 unsigned int picture_index; // value received from SetPictureIndex method
2299 unsigned int error_status : 2; // report error if any
2300 unsigned int ucode_error_status : 30; // report error status from ucode to driver
2301 unsigned int total_bit_count; // picture size in bits
2302 unsigned int type1_bit_count; // type1 bit count for the entire picture
2303 unsigned short num_tiles; // number of tiles produced
2304 unsigned char av1_start_QP; // AV1 QP value at frame encoding start (to be inserted into frame header by driver)
2305 unsigned char loop_filter_level; // loop filer value computed by ucode (to be inserted into frame header by driver)
2306 unsigned int pic_type : 14; // copied from pic_type in nvenc_h264_pic_control_s
2307 unsigned int cdef_damping_minus_3 : 2; // CDEF damping value computed by ucode (to be inserted into frame header by driver)
2308 int avgQP : 16; // average QP
2309 unsigned int cycle_count; // total cycles taked for execute. Written out only when DumpCycleCount in SetControlParams is set
2310 unsigned int hrdFullness;
2311 unsigned int bitstream_start_pos; // byte_offset where mpec will start writing slice header
2312 unsigned int intra_cu64x64_count; // number of intra 64x64 CUs.
2313 unsigned int inter_cu64x64_count; // number of inter 64x64 CUs.
2314 unsigned int intra_cu32x32_count; // number of intra 32x32 CUs.
2315 unsigned int inter_cu32x32_count; // number of inter 32x32 CUs.
2316 unsigned int intra_cu16x16_count; // number of intra 16x16 CUs.
2317 unsigned int inter_cu16x16_count; // number of inter 16x16 CUs.
2318 unsigned int intra_cu8x8_count; // number of intra 8x8 CUs.
2319 unsigned int inter_cu8x8_count; // number of inter 8x8 CUs.
2320 unsigned int cumulative_intra_cost; // sum of all intra SA(T)Ds
2321 unsigned int cumulative_inter_cost; // sum of all inter SA(T)Ds
2322 unsigned int total_intra_cost; // sum of all intra best mode's SATDs, each mb has one intra SATD.
2323 unsigned int total_inter_cost; // sum of all inter best mode's SATDs, each mb has one inter SATD.
2324 short average_mvx; // average mvx info, can be used for ME hint
2325 short average_mvy; // average mvy info, can be used for ME hint
2326 short actual_min_qp_used; // actual minimum qp used in the frame
2327 short actual_max_qp_used; // actual maximum qp used in the frame
2328 unsigned int hw_perf_me_sps; // me slice per second
2329 unsigned int hw_perf_me_fps; // me frame per second
2330 unsigned int hw_perf_entropy_active_cnt; // Entropy active count
2331 unsigned int hw_perf_rdo_active_cnt; // RDO active count
2332 unsigned short ave_activity; // report average activity if activity based RC enabled
2333 unsigned char reserved[18];
2334 } nvenc_av1_pic_stat_s; // 128 bytes
2335
2336 typedef struct
2337 {
2338 unsigned int tile_offset; // tile offset in bytes
2339 unsigned int tile_size; // tile size in bytes
2340 unsigned short tile_bitstream_idx; // Index of bistream base address the tile offset refers to (for multi entropy cores use - set to 0 otherwise)
2341 unsigned short tile_idx; // Tile index at strip level
2342 unsigned int tile_size_sbs; // tile size in sbs
2343 }nvenc_av1_tile_stat_s; // 16 bytes per status
2344
2345 typedef struct
2346 {
2347 unsigned int res_bit_count; // #bits spent on residuals
2348 unsigned int mode_bit_count; // #bits spent on modes (mbtype, pred mode)
2349 unsigned int type1_bit_count; // count of bits in type I bitstream (excludes leading_zero_8bits,
2350 // start_codeprefix_one_3bytes and trailing_zero_8bits)
2351 unsigned int total_bit_count; // total number of bits produced
2352
2353 unsigned int total_bin_count; // total number of bins produced by arithmetic coder
2354 unsigned int cumulative_intra_cost; // sum of all intra SA(T)Ds
2355 unsigned int cumulative_inter_cost; // sum of all inter SA(T)Ds
2356 unsigned int total_intra_cost; // sum of all intra best mode's SATDs, each ctb has one intra SATD.
2357 unsigned int total_inter_cost; // sum of all inter best mode's SATDs, each ctb has one inter SATD.
2358
2359 unsigned int intra_cu64x64_count; // number of intra 64x64 CUs.
2360 unsigned int inter_cu64x64_count; // number of inter 64x64 CUs.
2361 unsigned int intra_cu32x32_count; // number of intra 32x32 CUs.
2362 unsigned int inter_cu32x32_count; // number of inter 32x32 CUs.
2363 unsigned int intra_cu16x16_count; // number of intra 16x16 CUs.
2364 unsigned int inter_cu16x16_count; // number of inter 16x16 CUs.
2365 unsigned int intra_cu8x8_count; // number of intra 8x8 CUs.
2366 unsigned int inter_cu8x8_count; // number of inter 8x8 CUs.
2367
2368
2369 unsigned int total_emulated_bit_count; // total number of emulated bits in total_bit_count
2370 unsigned char reserved[56];
2371 } nvenc_av1_mpec_stat_s; // 128 bytes per status
2372
2373 typedef struct
2374 {
2375 unsigned int var_min;
2376 unsigned int var_max;
2377 unsigned int var_avg;
2378 unsigned char reserved[4];
2379 } nvenc_av1_aq_stat_s; // 16 bytes
2380
2381 typedef struct
2382 {
2383 unsigned int qp_val : 8 ; // qp used for encoding this block
2384 unsigned int total_bit_count : 24 ; // total number of bits produced
2385 unsigned int res_cost : 24 ; // satd cost of residual error
2386 unsigned int flags : 8 ; // flags
2387 } nvenc_av1_stats_fifo_s; // 8 bytes per stat
2388
2389 typedef struct
2390 {
2391 nvenc_av1_pic_stat_s pic_stat; // 64Bytes
2392 nvenc_av1_tile_stat_s tile_stat[128]; // maximum tile number is 128 per AV1 spec
2393 nvenc_av1_mpec_stat_s mpec_stat[((8192 / 64)*(8192 / 64)) ]; // To account for stat/1SB and 8kx8k, plus 3 for alignment?
2394 nvenc_av1_aq_stat_s aq_stats[((8192 / 64)*(8192 / 64)) ]; // AQ stats from pdma
2395 nvenc_av1_stats_fifo_s stats_fifo[((8192 / 64)*(8192 / 64)) ];
2396 } nvenc_av1_stat_data_s;
2397
2398
2399 typedef struct
2400 {
2401 unsigned int intra_res_bit_count; // #bits spent on intra residuals
2402 unsigned int inter_res_bit_count; // #bits spent on inter residuals
2403 unsigned int intra_mode_bit_count; // #bits spent on intra modes
2404 unsigned int inter_mode_bit_count; // #bits spent on inter modes
2405 unsigned int total_bit_count; // total number of bits produced
2406 unsigned int total_bin_count; // total number of bins produced by bac
2407 unsigned int cumulative_intra_cost; // sum of all intra SA(T)Ds
2408 unsigned int cumulative_inter_cost; // sum of all inter SA(T)Ds
2409 unsigned int cumulative_skip_cost; // sum of all P skip MB SA(T)Ds
2410 unsigned short intra_mb_count; // number of intra MBs.
2411 unsigned short inter_mb_count; // number of inter MBs.
2412 unsigned short skip_mb_count; // number of skip MBs.
2413 unsigned short reserved0; // align to a word boundary
2414 } nvenc_vp8_segment_stat_s; // 44 Bytes
2415
2416 typedef struct
2417 {
2418 unsigned int bitstream_byte_count; // output bytes in main partition bitstream buffer
2419 unsigned int bitstream_res_byte_count[8]; // output bytes in residual partition bitstream buffers
2420 unsigned int cycle_count; // total cycles taked for execute. Written out only when DumpCycleCount in SetControlParams is set
2421 unsigned int picture_index; // value received from SetPictureIndex method
2422 unsigned int error_status; // report error if any
2423 unsigned int total_bit_count; // picture size in bits /*(sum of header's & all the partition's bits. actually redundant)*/
2424 unsigned short pic_type; // copied from pic_type in nvenc_h264_pic_control_s
2425 unsigned short ave_activity; // report average activity if activity based RC enabled
2426 unsigned short num_segments; // number of segments produced
2427 unsigned short base_qindex; // base_qindex used for the frame
2428 nvenc_vp8_segment_stat_s segment_stat[4];
2429 unsigned int total_intra_cost; // sum of all intra best mode's SATDs, each mb has one intra SATD.
2430 unsigned int total_inter_cost; // sum of all inter best mode's SATDs, each mb has one inter SATD.
2431 unsigned int reserved1[3];
2432 } nvenc_vp8_stat_data_s; // 256 Bytes
2433
2434 // Stats stored in HW format.
2435 typedef struct
2436 {
2437 unsigned int coef_token_cnt[3][3][4][8][4]; // [value/4][ctx][value%4][band][type] 4608 bytes (4096 + 512)
2438 unsigned int mv_stats[20][4];
2439 } nvenc_vp8_token_data_s;
2440
2441 // 8 bytes
2442
2443
2444 //////////////////////////////////////////////////////////////////
2445 // ****************************************************************************
2446 // ****************************************************************************
2447 // AV1
2448 // ****************************************************************************
2449 // ****************************************************************************
2450 //AV1 loop filter config
2451 typedef struct
2452 {
2453 unsigned char filter_level[4]; // loop filter strength based on edge direction and component - vertical/horizontal edge luma (0,1) and chroma (2,3)
2454 char ref_delta[8]; // Loop filter level adjustments based on reference frame type - 0 = Intra, Last, Last2+Last3, GF, BRF, ARF2, AR
2455 int mode_delta_0 : 8; // Loop filter level adjustments based on mode type - 0 = ZERO_MV, MV
2456 int mode_delta_1 : 8; // Loop filter level adjustments based on mode type - 0 = ZERO_MV, MV
2457 unsigned int update_ref_delta_flag : 8; // update delta for reference i if bit i is set
2458 unsigned int update_mode_delta0 : 1;
2459 unsigned int update_mode_delta1 : 1;
2460 unsigned int delta_enabled : 1; // disable loop-filter
2461 unsigned int sharpness : 3; // sharpness level
2462 unsigned int reserved : 2;
2463 }nvenc_av1_loop_filter_cfg_s; //16 bytes
2464
2465 //AV1 CDEF config
2466 // NOTE: the following is mandated by the current HW implementation:
2467 // y_strength_0 and uv_strength_0 must always be set to 0
2468 // Luma/chroma strength combination 0 must always be (y_strength_0, uv_strength_0) i.e. (0,0)
2469 typedef struct
2470 {
2471 unsigned int cdef_damping_minus_3 : 2; // controls the amount of damping in the deringing filter
2472 unsigned int y_strength_0 : 6; // specify (strength primary filter 0 << 2) | strength secondary filter 0 (luma)
2473 unsigned int y_strength_1 : 6; // specify (strength primary filter 1 << 2) | strength secondary filter 1 (luma)
2474 unsigned int y_strength_2 : 6; // specify (strength primary filter 2 << 2) | strength secondary filter 2 (luma)
2475 unsigned int y_strength_3 : 6; // specify (strength primary filter 3 << 2) | strength secondary filter 3 (luma)
2476 unsigned int y_strength_4 : 6; // specify (strength primary filter 4 << 2) | strength secondary filter 4 (luma). Not supported.
2477 unsigned int y_strength_5 : 6; // specify (strength primary filter 5 << 2) | strength secondary filter 5 (luma). Not supported.
2478 unsigned int y_strength_6 : 6; // specify (strength primary filter 6 << 2) | strength secondary filter 6 (luma). Not supported.
2479 unsigned int y_strength_7 : 6; // specify (strength primary filter 7 << 2) | strength secondary filter 7 (luma). Not supported.
2480 unsigned int cdef_bits : 2; // support up to 3. the number of bits needed to specify w2ich CDEF filter to apply
2481 unsigned int uv_strength_0 : 6; // specify (strength primary filter 0 << 2) | strength secondary filter 0 (chroma)
2482 unsigned int uv_strength_1 : 6; // specify (strength primary filter 1 << 2) | strength secondary filter 1 (chroma)
2483 unsigned int uv_strength_2 : 6; // specify (strength primary filter 2 << 2) | strength secondary filter 2 (chroma)
2484 unsigned int uv_strength_3 : 6; // specify (strength primary filter 3 << 2) | strength secondary filter 3 (chroma)
2485 unsigned int uv_strength_4 : 6; // specify (strength primary filter 4 << 2) | strength secondary filter 4 (chroma). Not supported.
2486 unsigned int uv_strength_5 : 6; // specify (strength primary filter 5 << 2) | strength secondary filter 5 (chroma). Not supported.
2487 unsigned int uv_strength_6 : 6; // specify (strength primary filter 6 << 2) | strength secondary filter 6 (chroma). Not supported.
2488 unsigned int reserved0 : 2; // Reserved bits
2489 unsigned int uv_strength_7 : 6; // specify (strength primary filter 7 << 2) | strength secondary filter 7 (chroma). Not supported.
2490 unsigned int cdef_y_strength_num_minus_1 : 3; // HW will only considers y strength values from index 0 to cdef_y_strength_num_minus_1 (from 0 to 7)
2491 unsigned int cdef_uv_strength_num_minus_1 : 3; // HW will only considers uv strength values from index 0 to cdef_uv_strength_num_minus_1 (from 0 to 7)
2492 unsigned int cdef_combined_idx_minus_1 : 3; // Specify max number of unique (y_strength_x, uv_strength_y) combinations for HW to consider (from 0 to 7)
2493 // bits[2:0] must be set to 0
2494 unsigned int reserved1 : 17; // Reserved bits
2495 unsigned int cdef_combined_luma_idx : 24; // List of (cdef_combined_idx_minus_1 + 1) y strength indexes, each index using 3 bits and bits[3(n+1)-1:3n] corresponding to index of y_strength in combination n
2496 unsigned int reserved2 : 8; // Reserved bits
2497 unsigned int cdef_combined_chroma_idx : 24; // List of (cdef_combined_idx_minus_1 + 1) uv strength indexes, each index using 3 bits and bits[3(n+1)-1:3n] corresponding to index of uv_strength in combination n
2498 // bits[2:0] must be set to 0
2499 unsigned int reserved3 : 8; // Reserved bits
2500 }nvenc_av1_cdef_cfg_s; //24 bytes
2501
2502 //AV1 Loop Restoration Filter config
2503 typedef struct
2504 {
2505 unsigned int y_lr_type : 2; // luma restoration type
2506 unsigned int uv_lr_type : 2; // chroma restoration type
2507 unsigned int y_lr_unit_size : 2; // luma restoration unit size 0:32x32, 1:64x64, 2:128x128,3:256x256;
2508 unsigned int uv_lr_unit_size : 2; // chroma restoration unit size 0:32x32, 1:64x64, 2:128x128,3:256x256;
2509 unsigned int lr_codebook_enable : 16; // bit enable for up to 16 codebooks
2510 unsigned int lr_pe_on_edge_enable : 1; // enable bit for LR parameter estimation on picture boundary SBs
2511 unsigned int reserved : 7; // Reserved bits
2512 }nvenc_av1_lr_filter_cfg_s; // 4 bytes
2513
2514 //AV1 quant config
2515 typedef struct
2516 {
2517 unsigned char base_q_idx; // Base frame qindex (index in quant lookup table) 0...255
2518 char delta_y_dc; // explicit qindex adjustment for y dccoefficient, -63...63
2519 char delta_uv_dc; // qindex adjustment for uv accoefficient, -63...63
2520 char delta_uv_ac; // qindex adjustment for uv dccoefficient, -63...63
2521 }nvenc_av1_quant_cfg_s; //4 bytes
2522
2523 typedef struct
2524 {
2525 unsigned short frame_width_minus1; // frame width in pixels minus 1, range 191-8191
2526 unsigned short frame_height_minus1; // frame height in pixels minus 1, range 127-8191
2527 unsigned short sfc_pitch; // pitch of luma plane
2528 unsigned short sfc_pitch_chroma; // pitch of chroma plane
2529 unsigned short sfc_trans_mode; // least 3 significient bits are used to stand for 8 modes, normal, xflip, yflip etc.
2530 unsigned short reserved2; // pad to NvS32
2531
2532 unsigned int luma_top_frm_offset; // offset of luma top field or frame in units of 256
2533 unsigned int luma_bot_offset; // (deprecated) offset of luma bottom field in units of 256. Not used if frame format.
2534 unsigned int chroma_top_frm_offset; // offset of chroma top field or frame, or offset of chroma U(Cb) plane in planar mode, both in units of 256
2535 unsigned int chroma_bot_offset; // (deprecated) offset of chroma bottom field, not used if frame format. Or offset of chroma V(Cr) plane in planar mode. Both in units of 256.
2536 unsigned int block_height : 7; // BL mapping block height setting
2537 unsigned int tiled_16x16 : 1; // (deprecated) Surface is 16x16 tiled instead of BL mapped (must be 1 for refpics) (deprecated)
2538 unsigned int memory_mode : 2; // (deprecated) 0: semi-planar, 1: planar
2539 unsigned int nv21_enable : 1; // (deprecated) the surface format is yuv or yvu
2540 unsigned int input_bl_mode : 2; // the input block linear mode: 0~gpu bl; 1~tegra bl; 2~naive bl this is only for cmod and cmod/plugin. TBL only for Orin.
2541 unsigned int src_in_lsb : 1; // pixel is LSB aligned in 16bit container, only valid for high-bitdepth
2542 unsigned int reserved : 18; // pad to NvU32
2543 } nvenc_av1_surface_cfg_s; // 32 bytes
2544
2545 typedef struct
2546 {
2547 //sequence header
2548 unsigned int min_cu_size : 2; //0-8x8, 1-16x16, 2-32x32, 3-64x64. Orin AV1 supports 1~3
2549 unsigned int max_cu_size : 2; //0-8x8, 1-16x16, 2-32x32, 3-64x64 Orin AV1 supports 1~3
2550
2551 unsigned int chroma_format_idc : 2; // 0=not supported, 1=yuv4:2:0, 2=yuv4:2:2, 3=yuv4:4:4. Only support YUV420
2552 unsigned int monochrome_flag : 1; // only luma component if flag is set. Not supported.
2553 unsigned int bit_depth_minus_8 : 4; // luma/chroma should have the same value. support 0 (8bit), 2(10bit), 4(12bit) for Orin AV1
2554 unsigned int input_bit_depth_minus8 : 4; // Internal high-bitdepth support in HW
2555 // the field is to specify the bit-depth of source yuv. the decoded yuv bitdepth is specified nvenc_av1_seq_hdr_data_s::bit_depth_minus_8; HW will do the bitdepth conversion from source yuv-> recon yuv
2556 //
2557 unsigned int enable_filter_intra : 1; // enables/disables filterintra. Not supported
2558 unsigned int enable_intra_edge_filter : 1; // enables/disables corner/edge/upsampling. Not supported
2559 unsigned int enable_interintra_compound : 1; // enables/disables interintra_compound. Not supported
2560 unsigned int enable_masked_compound : 1; // enables/disables masked compound. Not supported
2561 unsigned int enable_dual_filter : 1; // enable or disable vertical and horiz filter selection. Not supported
2562 unsigned int force_screen_content_tools : 2; // 0 - force off. Not supported.
2563 // 1 - force on
2564 // 2 - adaptive
2565 unsigned int force_integer_mv : 2; // Not supported.0 - Not to force. MV can be in 1/4 or 1/8
2566 // 1 - force to integer
2567 // 2 - adaptive
2568 unsigned int enable_jnt_comp : 1; // enables/disables joint compound modes. not supported. Not supported.
2569 unsigned int enable_ref_frame_mvs : 1; // enables/disables ref frame mvs. not supported. Not supported.
2570 unsigned int enable_warped_motion : 1; // enables/disables warped motion for sequence. Not supported.
2571 unsigned int enable_superres : 1; // enables/disables superres for sequence. Not supported.
2572 unsigned int enable_cdef : 1; // enables/disables CDEF
2573 unsigned int enable_restoration : 1; // enables/disables restoration filter, only support self-guided filter
2574 unsigned int reserved0 : 2; // reserved bits
2575 } nvenc_av1_seq_hdr_data_s; // 4 bytes
2576
2577 //frame header
2578 typedef struct
2579 {
2580 unsigned int frame_type : 2; // 0:Key frame, 1:Inter frame, 2:intra only, 3:s-frame
2581 unsigned int disable_cdf_update : 1; // disable CDF update during symbol decoding
2582 unsigned int allow_screen_content_tools : 1; // screen content tool enable. Not supported.
2583 unsigned int force_integer_mv : 1; // AMVR enable. Not supported.
2584 unsigned int allow_high_precision_mv : 1; // 1/8 precision mv enabl. Not supported.
2585 unsigned int switchable_motion_mode : 1; // 0: simple motion mode, 1: SIMPLE, OBMC, LOCAL WARP. Not supported, fixed to 0.
2586 unsigned int is_filter_switchable : 1; // 1: filter selection is signaled at block level
2587 unsigned int use_ref_frame_mvs : 1; // Not supported. enable/disable use of motion vector info from previous frame
2588 unsigned int frame_end_update_cdf : 1; // enable/disable CDF update at end of frame
2589 unsigned int interp_filter : 3; // interpolation filter : EIGHTTAP,...., SWITCHABLE. Only support EIGHTTAP &EIGHTTAP_SMOOTH.
2590 unsigned int delta_q_present_flag : 1; // quantizer index delta values are present in the block level
2591 unsigned int delta_q_res : 2; // left shift will apply to decoded quantizer index delta values. Not supported.
2592 unsigned int allow_intrabc : 1; // IBC enable. Not supported.
2593 unsigned int delta_lf_present_flag : 1; // specify whether loop filter delta values are present in the block level. Not supported.
2594 unsigned int delta_lf_res : 2; // specify the left shift will apply to decoded loop filter values. Not supported.
2595 unsigned int delta_lf_multi : 1; // seperate loop filter deltas for Hy,Vy,U,V edges. Not supported.
2596 unsigned int using_qmatrix : 1; // enable quant matrix. Not supported.
2597 unsigned int frame_tx_mode : 2; // 0:LARGEST (32x32), 1:SELECT, 2: ONLY4x4 (lossless only)
2598 unsigned int frame_reference_mode : 2; // 0: single, 1: select, 2: compound
2599 unsigned int skip_mode_flag : 1; // skip mode present flag. Not supported.
2600 unsigned int allow_warped_motion : 1; // frame level warped motion enable. Not supported.
2601 unsigned int reduced_tx_set_flag : 1; // whether the frame is restricted to a reduced subset of the full set of transform types. Not supported.
2602 unsigned int coded_lossless : 1; // whether lossless coding is used for frame or not
2603 unsigned int reserved0 : 2; // reserved bits
2604
2605 unsigned int ssim_rdo_enable : 1; //enable variance based SSIM-RDO
2606 unsigned int ssim_rdo_alt_frame_scale : 8; //frame level scaling factor for altref frame
2607 unsigned int bicompound_enable : 1; //enable bi-compound for B-frames.
2608 unsigned int unicompound_enable : 1; //enable uni-compound for P/B-frames. (only support in Pframes)
2609 unsigned int mc_hfilter : 4; //bitmask for horizontal filters enabled 0: EIGHTTAP, 1: EIGHTTAP_SMOOTH,
2610 unsigned int mc_vfilter : 4; //bitmask for vertical filters enabled 0: EIGHTTAP, 1: EIGHTTAP_SMOOTH,
2611
2612 unsigned int segmentation_enable : 1; //enable segmentation
2613 unsigned int segmentation_update_map : 1; //enable segmentation update map ,force 1
2614 unsigned int segment_temporal_update : 1; //enable segmentation temporal update,force 0
2615 unsigned int segIdPreSkip : 1; //segment id pre skip encoding ,force 1
2616 unsigned int LastActiveSegId : 3; //highest number of active segment . force 2
2617
2618 unsigned int reserved1 : 6;
2619
2620
2621
2622 unsigned char ref_frame_sign_bias[8]; //Used by AV1 MVP. A sign bias equal to 0 indicates that the reference frame is a forwards reference (
2623 nvenc_av1_loop_filter_cfg_s lf_cfg; // loop filter configuration
2624 nvenc_av1_cdef_cfg_s cdef_cfg; // CDEF configuration
2625 nvenc_av1_quant_cfg_s quant_cfg; // quantizer configuration
2626 nvenc_av1_lr_filter_cfg_s lrf_cfg; // loop restoration filter configuration
2627 } nvenc_av1_frame_hdr_data_s; // 64 bytes
2628
2629 // needed only if picture level RC is enabled; as part of picture level RC, it will also perform HRD verification
2630 // The contents of this file is produced by the driver during sequence level operations and should not be modified.
2631 typedef struct
2632 {
2633 unsigned char hrd_type; // nal (=2) and vcl (=1) type
2634 unsigned char QP[3]; // QP for 0:P picture, ,1:B picture 2; I picture
2635 unsigned char minQP[3]; // min QP for 0:P picture, ,1:B picture 2; I picture
2636 unsigned char maxQP[3]; // max QP for 0:P picture, ,1:B picture 2; I picture
2637 char maxQPD; // max QP delta between two consecutive QP updates
2638 char baseQPD; // initial QP delta between two consecutive QP updates
2639 unsigned int rhopbi[3]; // 23.8 unsigned fixed point quant ratios P/I, B/I, I/I(=1)
2640
2641 unsigned int framerate; // fps
2642 unsigned int buffersize; // total buffer size
2643
2644 unsigned int nal_cpb_size; // size in bits
2645 unsigned int nal_bitrate; // rate in bps
2646 unsigned int vcl_cpb_size; // size in bits
2647 unsigned int vcl_bitrate; // rate in bps
2648
2649 unsigned int gop_length; // I period, gop_length == 0xffffffff is used for infinite gop length
2650 unsigned int Np; // 27.4 unsigned fixed (gop_length + num_b_frames -1)/(num_b_frames + 1)
2651 unsigned int Bmin; // 23.8 unsigned fixed point min buffer level, updated by driver at sequence level only.
2652 unsigned int Ravg; // 23.8 unsigned fixed point average rate, updated by driver at sequence level only.
2653 unsigned int R; // 23.8 unsigned fixed point rate
2654
2655 unsigned char ab_alpha; // VBR/CBR: min/target quality level (1..51); rcmode4: weight of prev frame activity compared to part of the current picture
2656 unsigned char ab_beta; // lookahead info1: ratio of inter over intra complexity (fix8); rcmode4: weight of current activity compared to neighbors
2657 unsigned short prev_act; // lookahead info2: NVENC_LOOKAHEAD_INFO2; rcmode4: average activity level of the first reference (L0)
2658
2659 unsigned char reserved0;
2660 unsigned char single_frame_vbv; // 1: VBV buffer size is set to average frame size; 0: otherwise
2661 unsigned char two_pass_rc; // 0: single pass rc , 1: first pass of 2 pass rc 2: second pass of 2 pass rc
2662 unsigned char rc_class; // reserved
2663 unsigned char first_pass_source_half_scaled; // 0 : first pass on half resolution 1: first pass on full resolution (along with NVENC_QRES_FLAG_XXX)
2664 unsigned char i_size_ratio_x; // ratio between I picture target size over average picture size numerator
2665 unsigned char i_size_ratio_y; // ratio between I picture target size over average picture size denominator
2666 unsigned char aqMode; // 0: disable adaptive quantization 1: AQ mode fast (unimplemented) 2: AQ mode full (unimplemented) 3: External qp delta map
2667 unsigned char dump_aq_stats; // 1: dump aq stats
2668 unsigned char ext_scene_change_flag; // Scene change flag set as hint by external preprocessing unit. 0: No scene change, 1: Current picture is first in scene
2669 unsigned char ext_picture_rc_hints; // picture rc hints are set by external source. 0: no hints, 1: hints are avaialble for current picture
2670 unsigned char session_max_qp; // Current frame qp will never exceed this value when ext_picture_rc_hints is set
2671 unsigned int ext_intra_satd; // If non zero this represents the intra SATD for current picture computed by external preprocessing unit
2672 unsigned char reserved2[8];
2673 } nvenc_av1_rc_s; // 96 bytes
2674 //////////////////////////////////////////////////////////////////
2675
2676
2677 typedef struct
2678 {
2679 char l0[4]; // reference picture list 0, maximum 4 forward reference frame
2680 char l1[3]; // reference picture list 1, maximum 3 backward reference frame
2681 char temp_dist_l0[4]; // temporal distance of each ref pic in list 0 DiffPicOrderCnt( currPicOrField, pic0) )
2682 char temp_dist_l1[3]; // temporal distance of each ref pic in list 1 DiffPicOrderCnt( currPicOrField, pic1) )
2683 char poc_entry_l0[4]; // ref pic list to ref pic entry map
2684 char poc_entry_l1[3]; // ref pic list to ref pic entry map
2685 char reserved0[3];
2686
2687 unsigned int max_byte_count_before_resid_zero; // Maximum byte count before microcode forces the residuals to zero.
2688
2689 unsigned int mode_decision_only_flag : 1; // only output av1 mode and mocomp result, no recon and bitstream output. Not supported.
2690 unsigned int cu_early_terminatiom_enable : 1; // 0: disable CU early termination, 1: enable CU early termination. Not supported.
2691 unsigned int pic_output_flag : 1; // enable recon picture output
2692 unsigned int input_sub_sampling : 1; // used by PDMA 2x2 sub-sampling. Not supported.
2693 unsigned int output_sub_sampling : 1; // used by MPEB 2x2 sub-sampling output. Not supported.
2694 unsigned int num_ref_idx_l0_active : 3; // [0..4]
2695 unsigned int num_ref_idx_l1_active : 3; // [0..3]
2696 unsigned int tile_idx_start : 8; // index of entry in av1_tile_control_s corresponding to first tile in strip
2697 unsigned int num_strip_tiles_minus1 : 8; // number of tiles in strip (= num_tiles_minus1 if single strip)
2698 unsigned int force_lf_on_flag : 1; // minimum level of loop filter is set to 1 instead of 0 when flag is set
2699 unsigned int force_lf_off_flag : 1; // maximum level of loop filter is set to 0 when flag is set (i.e. filtering off)
2700 unsigned int vp9_skip_chroma : 1; // HW will only process luma and skip chroma. used for vp9 autoprofile TODO: temporary add here, need to move to VP9 dedicated structrue.
2701 unsigned int reserved1 : 2;
2702
2703 unsigned int max_tu_depth_inter : 2; // max_transform_hierarchy_depth_inter. Orin AV1 supports 0~2
2704 unsigned int max_tu_depth_intra : 2; // max_transform_hierarchy_depth_intra. Orin AV1 supports 0
2705 unsigned int num_tiles_minus1 : 8; // number of entries in av1_tile_control_s
2706 unsigned int enable_source_image_padding : 1; // enable/disable HW source image padding
2707 unsigned int luma_padding_mode : 2; // HW souce padding mode for luma: 0: copy frame boundary, 1: zero padding, 2: half value, i.e 1<<(bitdepth-1)
2708 unsigned int chroma_padding_mode : 2; // HW souce padding mode for chroma: 0: copy frame boundary, 1: zero padding, 2: half value, i.e 1<<(bitdepth-1)
2709 unsigned int reserved2 : 15;
2710 unsigned int prob_tables_offset; // When non-zero, ucode will adjust the base address of the probability tables surfaces based on picture QP value as follows
2711 unsigned int tile_control_offset; // offset from start of top level "nvenc_av1_drv_pic_setup_s" structure
2712 unsigned int hist_buf_size; // size in bytes of the buffer allocated for history
2713 unsigned int bitstream_buf_size; // size in bytes of the buffer allocated for bitstream slice/mb data
2714 unsigned int bitstream_start_pos; //start position in bitstream buffer where data should be written (byte offset)
2715 unsigned int pic_type : 2; // 0 = P, 1 = B, 2 = I, 3 = IDR
2716 unsigned int ref_pic_flag : 1; // reference picture (0 = no, 1 = yes)
2717 unsigned int codec : 3;
2718 unsigned int qpfifo : 1; // 0 = Polling mode, 1 = Interrupt mode.
2719 unsigned int num_tile_cols : 8; // Number of tile columns in picture
2720 unsigned int num_tile_rows : 8; // Number of tile rows in picture
2721 unsigned int ctx_update_tile_id : 8; // update cdf for the specified tile id. value 255 is reserved to enable HW auto update CDF from tile with maximun tile data length
2722 unsigned int stats_fifo_enable : 1; // enable per-sb short stats fifo
2723
2724 // 1 = static slice insertion based on slice control array
2725 // (insert slices as defined in array, if all array elements used
2726 // before end of picture is reached, start over with entry 0)
2727
2728 unsigned int mpec_threshold; // collect mpec stats after threshold mbs
2729 // when mpec_stat_on is enabled and mpec_threshold is not equal to picWidthInMbs,
2730 unsigned int tile_stat_offset; // offset from start of top level "nvenc_av1_stat_data_s" structure
2731 // rc mode 0 will be used to collect stats
2732 unsigned int mpec_stat_offset; // offset from start of top level "nvenc_stat_data_s" structure
2733 // to start of array of "nvenc_mpec_stat_s" structure
2734 unsigned int aq_stat_offset; // to start of array of "nvenc_av1_aq_stat_s" structure
2735
2736 unsigned int rc_pass2_offset;
2737
2738 unsigned int act_stat_offset; // offset from start of "nvenc_rc_pic_stat_s" structure, points to data for external QP map
2739 unsigned int external_hint_number; // total external hint number for current frame, maximun external hints per SB: 128.
2740
2741 unsigned char stripID; // strip index (from 0 to strips_in_frame-1)
2742 unsigned char strips_in_frame; // total number of strips in frame
2743 unsigned short strip_width_in_sbs; // strip width in SB unit,must be frame_width
2744 unsigned short strip_height_in_sbs; // strip height in SB unit
2745 unsigned short strip_width_offset_in_sbs; // Column index of first SB in strip ,must be 0
2746 unsigned short strip_height_offset_in_sbs; // Row index of first SB in strip
2747 unsigned short reserved5;
2748
2749 unsigned int stats_fifo_offset; // offset from start of top level "nvenc_stat_data_s" structure
2750 unsigned char reserved6[8];
2751 } nvenc_av1_pic_control_s; // 112 bytes
2752
2753 typedef struct
2754 {
2755 unsigned int cu8x8_part_2Nx2N_enable : 1; // enable prediction for Inter CU8x8 2Nx2N
2756 unsigned int cu16x16_part_2Nx2N_enable : 1; // enable prediction for Inter CU16x16 2Nx2N
2757 unsigned int cu16x16_part_2NxN_enable : 1; // enable prediction for Inter CU16x16 2NxN
2758 unsigned int cu16x16_part_Nx2N_enable : 1; // enable prediction for Inter CU16x16 Nx2N
2759 unsigned int cu32x32_part_2Nx2N_enable : 1; // enable prediction for Inter CU32x32 2Nx2N
2760 unsigned int cu32x32_part_2NxN_enable : 1; // enable prediction for Inter CU32x32 2NxN
2761 unsigned int cu32x32_part_Nx2N_enable : 1; // enable prediction for Inter CU32x32 Nx2N
2762 unsigned int cu64x64_part_2Nx2N_enable : 1; // enable prediction for Inter CU64x64 2Nx2N
2763 unsigned int cu64x64_part_2NxN_enable : 1; // enable prediction for Inter CU64x64 2NxN
2764 unsigned int cu64x64_part_Nx2N_enable : 1; // enable prediction for Inter CU64x64 Nx2N
2765 unsigned int tusize_4x4_enable : 1; //enable 4x4 transform
2766 unsigned int tusize_8x8_enable : 1; //enable 8x8/8x4/4x8 transform
2767 unsigned int tusize_16x16_enable : 1; //enable 16x16/16x8/8x16 transform
2768 unsigned int tusize_32x32_enable : 1; //enable 32x32/32x16/16x32 transform
2769 unsigned int tusize_64x64_enable : 1; //enable 64x64/64x32/32x16 transform
2770 unsigned int intra_tusize_decision : 1; //enable intra tu size decision, reserved, not implemented in HW
2771 unsigned int pskip_enable : 1; //enable p_skip encoding. Not supported
2772 unsigned int tu_search_basedon_pusize : 1; //enable tu search based on pu size. Not supported
2773 unsigned int multiply_bias_with_lambda : 1; // setting this to 1 will result in bias being multiplied by lambda
2774 unsigned int skip_evaluate_enable_cu8 : 1; // 0: not check skip ssd cost; 1, evaluate skip ssd cost. Not supported
2775 unsigned int skip_evaluate_enable_cu16 : 1; // 0: not check skip ssd cost; 1, evaluate skip ssd cost. Not supported
2776 unsigned int skip_evaluate_enable_cu32 : 1; // 0: not check skip ssd cost; 1, evaluate skip ssd cost. Not supported
2777 unsigned int skip_evaluate_enable_cu64 : 1; // 0: not check skip ssd cost; 1, evaluate skip ssd cost. Not supported
2778 unsigned int inter_rdo_cnt_8x8 : 3; // #RD cost evaluation for inter top N SATD winner partitions of CU8x8. support 0~4
2779 unsigned int inter_rdo_cnt_16x16 : 3; // #RD cost evaluation for inter top N SATD winner partitions of CU16x16. support 0~4
2780 unsigned int inter_rdo_cnt_32x32 : 3; // #RD cost evaluation for inter top N SATD winner partitions of CU32x32. support 0~4
2781
2782 unsigned int inter_rdo_cnt_64x64 : 3; // #RD cost evaluation for inter top N SATD winner partitions of Cu64x64. support 0~4
2783 unsigned int intra_rdo_cnt_4x4 : 3; // RD cost evaluation for N top satd winner modes of intra 4x4. Not supported
2784 unsigned int intra_rdo_cnt_8x8 : 3; // RD cost evaluation for N top satd winner modes of intra 8x8. support 0~4
2785 unsigned int intra_rdo_cnt_8x4 : 3; // RD cost evaluation for N top satd winner modes of intra 8x4. support 0~4
2786 unsigned int intra_rdo_cnt_4x8 : 3; // RD cost evaluation for N top satd winner modes of intra 4x8. support 0~4
2787 unsigned int intra_rdo_cnt_16x16 : 3; // RD cost evaluation for N top satd winner modes of intra 16x16. support 0~4
2788 unsigned int intra_rdo_cnt_16x8 : 3; // RD cost evaluation for N top satd winner modes of intra 16x8. support 0~4
2789 unsigned int intra_rdo_cnt_8x16 : 3; // RD cost evaluation for N top satd winner modes of intra 8x16. support 0~4
2790 unsigned int intra_rdo_cnt_32x32 : 3; // RD cost evaluation for N top satd winner modes of intra 32x32. support 0~4
2791 unsigned int intra_rdo_cnt_32x16 : 3; // RD cost evaluation for N top satd winner modes of intra 32x16. support 0~4
2792 unsigned int luma_all_zero_check : 1; // enable TU level luma coefficient all zero check
2793 unsigned int chroma_all_zero_check : 1; // enable TU level chroma coefficient all zero check. Not supported
2794
2795 unsigned int intra_rdo_cnt_16x32 : 3; // RD cost evaluation for N top satd winner modes of intra 16x32. support 0~4
2796 unsigned int intra_rdo_cnt_64x64 : 3; // RD cost evaluation for N top satd winner modes of intra 64x64. support 0~4
2797 unsigned int intra_rdo_cnt_64x32 : 3; // RD cost evaluation for N top satd winner modes of intra 64x32. support 0~4
2798 unsigned int intra_rdo_cnt_32x64 : 3; // RD cost evaluation for N top satd winner modes of intra 32x64. support 0~4
2799 unsigned int num_1div8_lambda_ssd : 7; // number of 1/8 lambda ssd for lambda_coef delta. lambda_coef = (1+num_1div8_lambda_ssd*1/8)*lambda_ssd
2800 unsigned int mv_cost_enable : 1; // enable mv cost calculations in mode decision
2801 unsigned int reserved0 : 12;
2802
2803 //Intra Luma angular delta mode controls: begin
2804 unsigned int intra_luma_dir_delta_64x64_enable_0; // bit mask for enabling angular delta modes: {D135, D45, H, V} * {-3,-2,-1,0,1,2,3}
2805 unsigned int intra_luma_dir_delta_64x64_enable_1; // bit mask for enabling angular delta modes: {D67, D203, D157, D113} * {-3,-2,-1,0,1,2,3}
2806 unsigned int intra_luma_dir_delta_64x32_enable_0;
2807 unsigned int intra_luma_dir_delta_64x32_enable_1; // for 64x32 and 32x64
2808
2809 unsigned int intra_luma_dir_delta_32x32_enable_0; // bit mask for enabling angular delta modes: {D135, D45, H, V} * {-3,-2,-1,0,1,2,3}
2810 unsigned int intra_luma_dir_delta_32x32_enable_1; // bit mask for enabling angular delta modes: {D67, D203, D157, D113} * {-3,-2,-1,0,1,2,3}
2811 unsigned int intra_luma_dir_delta_32x16_enable_0; // for 32x16 and 16x32
2812 unsigned int intra_luma_dir_delta_32x16_enable_1;
2813
2814 unsigned int intra_luma_dir_delta_16x16_enable_0; // bit mask for enabling angular delta modes: {D135, D45, H, V} * {-3,-2,-1,0,1,2,3}
2815 unsigned int intra_luma_dir_delta_16x16_enable_1; // bit mask for enabling angular delta modes: {D67, D203, D157, D113} * {-3,-2,-1,0,1,2,3}
2816 unsigned int intra_luma_dir_delta_16x8_enable_0; // for 8x16 and 16x8
2817 unsigned int intra_luma_dir_delta_16x8_enable_1;
2818
2819 unsigned int intra_luma_dir_delta_8x8_enable_0; // bit mask for enabling angular delta modes: {D135, D45, H, V} * {-3,-2,-1,0,1,2,3}
2820 unsigned int intra_luma_dir_delta_8x8_enable_1; // bit mask for enabling angular delta modes: {D67, D203, D157, D113} * {-3,-2,-1,0,1,2,3}
2821 //Intra Luma angular delta mode controls: end
2822
2823 // 0:DC_PRED, 1: V_PRED, 2: H_PRED, 3:D45_PRED,
2824 // 4:D135_PRED, 5:D113_PRED, 6:D157_PRED, 7: D203_PRED,
2825 // 8: D67_PRED, 9:SMOOTH_PRED, 10:SMOOTH_V_PRED, 11:SMOOTH_H_PRED
2826 // 12: PAETH
2827 unsigned short intra_luma_base_mode_4x4_enable; //bit mask of intra luma base 4x4 mode:
2828 unsigned short intra_luma_base_mode_8x8_enable; //bit mask of intra luma base 8x8/8x4/4x8 mode
2829 unsigned short intra_luma_base_mode_16x16_enable; //bit mask of intra luma base 16x16/16x8/8x16 modes
2830 unsigned short intra_luma_base_mode_32x32_enable; //bit mask of intra luma base 32x32/32x16/16x32 modes
2831 unsigned short intra_luma_base_mode_64x64_enable; //bit mask of intra luma base 64x64/32x64/64x32 modes
2832
2833 short bias_intra_over_inter; // bias for any intra (subtracts from intra cost)
2834 unsigned short mv_cost_bias; // bias applied to internal motion vector cost calculation
2835
2836 short bias_tu_4x4; // bias for TU 4x4
2837 short bias_tu_8x8; // bias for TU 8x8
2838 short bias_tu_16x16; // bias for TU 16x16
2839 short bias_tu_32x32; // bias for TU 32x32
2840 short bias_tu_64x64; // bias for TU 64x64
2841 short bias_tu_8x4; // bias for TU 8x4
2842 short bias_tu_4x8; // bias for TU 4x8
2843 short bias_tu_16x8; // bias for TU 16x8
2844 short bias_tu_8x16; // bias for TU 8x16
2845 short bias_tu_32x16; // bias for TU 32x16
2846 short bias_tu_16x32; // bias for TU 16x32
2847
2848 short bias_skip; // bias for skip mv's ssd (subtracts from skip mv's ssd cost). Not supported.
2849 short bias_inter_64x64; // bias for inter 64x64 (subtracts from inter 64x64 cost)
2850 short bias_inter_64x32; // bias for inter 64x32 (subtracts from inter 64x32 cost)
2851 short bias_inter_32x64; // bias for inter 32x64 (subtracts from inter 32x64 cost)
2852 short bias_inter_32x32; // bias for inter 32x32 (subtracts from inter 32x32 cost)
2853 short bias_inter_32x16; // bias for inter 32x16 (subtracts from inter 32x16 cost)
2854 short bias_inter_16x32; // bias for inter 16x32 (subtracts from inter 16x32 cost)
2855 short bias_inter_16x16; // bias for inter 16x16 (subtracts from inter 16x16 cost)
2856 short bias_inter_16x8; // bias for inter 16x8 (subtracts from inter 16x8 cost)
2857 short bias_inter_8x16; // bias for inter 8x16 (subtracts from inter 8x16 cost)
2858 short bias_inter_8x8; // bias for inter 8x8 (subtracts from inter 8x8 cost)
2859 short bias_intra_64x64; // bias for intra 64x64 (subtracts from intra 64x64 cost)
2860 short bias_intra_64x32; // bias for intra 64x32 (subtracts from intra 64x32 cost)
2861 short bias_intra_32x64; // bias for intra 32x64 (subtracts from intra 32x64 cost)
2862 short bias_intra_32x32; // bias for intra 32x32 (subtracts from intra 32x32 cost)
2863 short bias_intra_32x16; // bias for intra 32x16 (subtracts from intra 32x16 cost)
2864 short bias_intra_16x32; // bias for intra 16x32 (subtracts from intra 16x32 cost)
2865 short bias_intra_16x16; // bias for intra 16x16 (subtracts from intra 16x16 cost)
2866 short bias_intra_16x8; // bias for intra 16x8 (subtracts from intra 16x8 cost)
2867 short bias_intra_8x16; // bias for intra 8x16 (subtracts from intra 8x16 cost)
2868 short bias_intra_8x8; // bias for intra 8x8 (subtracts from intra 8x8 cost)
2869 short bias_intra_8x4; // bias for intra 8x4 (subtracts from intra 8x4 cost)
2870 short bias_intra_4x8; // bias for intra 4x8 (subtracts from intra 4x8 cost)
2871 short bias_intra_4x4; // bias for intra 4x4 (subtracts from intra 4x4 cost)
2872
2873 unsigned short tx_type_search_mask[2]; // bit mask of tx type enabled. bit 0~15, corresponding to:
2874 // tx type DCT_DCT, ADST_DCT, DCT_ADST, ADST_ADST, FLIPADST_DCT,
2875 // DCT_FLIPADST, FLIPADST_FLIPADST, ADST_FLIPADST, FLIPADST_ADST,
2876 // IDTX, V_DCT, H_DCT, V_ADST, H_ADST, V_FLIPADST, H_FLIPADST,
2877 // 0: control for RDO stage. 1: control for RECON stage
2878
2879 unsigned int zbin_factor_lt_148 : 8; //Aggresive DZ control for zbin factor when quant value < 148. in 1/128 unit
2880 unsigned int zbin_factor_gt_148 : 8; //Aggresive DZ control for zbin factor when quant value >= 148. in 1/128 unit
2881 unsigned int round_factor_eq_0 : 8; // TBD
2882 unsigned int round_factor_ne_0 : 8; // TBD
2883 } nvenc_av1_md_control_s; // 160 bytes
2884
2885 typedef nvenc_h264_me_control_s nvenc_me_control_s;
2886
2887 typedef struct
2888 {
2889 // 256 aligned
2890 unsigned int magic; // magic number, see text above // 4 bytes
2891 nvenc_av1_surface_cfg_s refpic_cfg; // defines layout of reference pictures // 32 bytes
2892 nvenc_av1_surface_cfg_s input_cfg; // defines layout of input pictures // 32 bytes
2893 nvenc_av1_surface_cfg_s outputpic_cfg; // defines layout of reconstructed pictures // 32 bytes
2894
2895 nvenc_av1_seq_hdr_data_s seqhdr_data; // 4 bytes
2896 nvenc_av1_frame_hdr_data_s framehdr_data; // 64 bytes
2897 nvenc_av1_rc_s rate_control; // Rate Control information // 96 bytes
2898 nvenc_av1_pic_control_s pic_control; // 112 bytes
2899 nvenc_av1_surface_cfg_s half_scaled_outputpic_cfg; // defines layout of 2x2 subsampled reconstructed picture // 32 bytes
2900 nvenc_av1_md_control_s md_control; // 160 bytes
2901 nvenc_me_control_s me_control; // 192 bytes
2902 unsigned int gpTimer_timeout_val; // GPTimer cycle count set from driver
2903 unsigned char reserved0[4];
2904 } nvenc_av1_drv_pic_setup_s; //768 bytes
2905
2906 typedef nvenc_av1_drv_pic_setup_s nvenc_vp9_drv_pic_setup_s; //TODO: Orin VP9 will share the same class as AV1. Define new one for Hopper VP9
2907
2908 typedef struct
2909 {
2910 unsigned int tile_top_sbx : 16; // top left sbx of the tile
2911 unsigned int tile_top_sby : 16; // top left sby of the tile
2912 unsigned int tile_bot_sbx : 16; // bottom right sbx of the tile
2913 unsigned int tile_bot_sby : 16; // bottom right sby of the tile
2914
2915 unsigned int qp_tile_min : 8; // min slice qp value
2916 unsigned int qp_tile_max : 8; // max slice qp value
2917 unsigned int qp_avr : 8; // 8bit value used by hw
2918 unsigned int tile_type : 2; // 0 = B, 1 = P, 2 = I
2919 unsigned int force_intra : 1;
2920 unsigned int tile_end_update_cdf : 1; // enable/disable CDF update at end of tile
2921 unsigned int limit_tile_top_boundary : 1; // limit ME to tile boundaries
2922 unsigned int limit_tile_bot_boundary : 1; // limit ME to tile boundaries
2923 unsigned int limit_tile_left_boundary : 1; // limit ME to tile boundaries
2924 unsigned int limit_tile_right_boundary : 1; // limit ME to tile boundaries
2925
2926 unsigned int tile_idx : 8; // tile index at picture level (potentially different from index in array of nvenc_av1_tile_control_s when doing strip encoding)
2927 unsigned int disable_tile_top_filters : 1; //disable filters at tile top boundary
2928 unsigned int disable_tile_bottom_filters : 1; //disable filters at tile bottom boundary
2929 unsigned int disable_next_tile_top_filters : 1; //disable filters at next tile top boundary
2930 unsigned int disable_next_tile_bottom_filters : 1; //disable filters at next tile bottom boundary
2931 unsigned int reserved0 : 20;
2932
2933 unsigned int next_tile_top_sbx : 16; // top left sbx of next tile
2934 unsigned int next_tile_top_sby : 16; // top left sby of next tile
2935 unsigned int next_tile_bot_sbx : 16; // bottom right sbx of next tile
2936 unsigned int next_tile_bot_sby : 16; // bottom right sby of next tile
2937
2938 unsigned short intra_refresh_cnt; // distance between forced-intra SBs in slice; 0 means OFF
2939 unsigned short intra_refresh_offs; // first forced-intra SB in slice
2940
2941 unsigned char reserved2[4]; // padding to 32 bytes
2942 } nvenc_av1_tile_control_s; // 32 bytes
2943
2944 // AV1 not support QPP, reserved it but not used
2945 typedef struct
2946 {
2947 // QPP has not been defined for AV1
2948 unsigned short qpp_run_vector_4x4; // cost values for 4x4 transform (16 bit total vector)
2949 unsigned short qpp_run_vector_8x8[3]; // cost values for 8x8 transform (48 bit total vector)
2950 // 2 bits each for first 12 coefs, then 1 bit each for next 24
2951 unsigned int qpp_luma8x8_cost : 8; // luma 8x8 cost threshold, 0 = throw out all coefs, range 0-15
2952 unsigned int qpp_luma16x16_cost : 8; // luma 16x16 cost threshold, 0 = throw out all coefs, range 0-15
2953 unsigned int qpp_chroma_cost : 8; // chroma cost threshold, 0 = throw out all coefs, range 0-15
2954 unsigned int qpp_mode : 2; // 0 = OFF, 1 = 8x8, 2 = 16x16_8x8
2955 unsigned int reserved0 : 6; // padding
2956
2957 unsigned int reserved1; // padding to 16 bytes
2958 } nvenc_av1_quant_control_s; // 16 bytes
2959
2960 // Status buffer holds for debug related information
2961 //
2962 // General guideline for using CRC interface debug feature:
2963 // 1. Generate the golden CRC (e.g. using cmodel) for for all interfaces
2964 // 2. program the golden crc to NV_CNVENC_SAFETY_CRC_GOLDEN_PART_[X]_INTERFACE_NAME, and config the SAFETY_CRC_CFG register (with values from dbg_crc_init_enable/comp_enable/addr_comp/mem_wr_dis), set SAFETY_CRC_CTRL_EN = 1 (TZ)
2965 // 3. kick off HW and trigger HW to compare width golden by writing SAFETY_CRC_CFG_COMP_EN when finish processing the frame; compare result could read from NV_CNVENC_SAFETY_CRC_STATUS_PART_[X]
2966 // 4. raw HW CRC values could be read from NV_CNVENC_SAFETY_CRC_HW_PART_[X]_INTERFACE_NAME
2967 typedef struct
2968 {
2969 unsigned int dbg_crc_enable : 1; //Global enable flag for enable/disable interface crc calculation in NVENC HW
2970 unsigned int dbg_crc_init_enable: 1; //Enable crc initialization
2971 unsigned int dbg_crc_comp_enable: 1; //Enable crc golden comparision
2972 unsigned int dbg_crc_addr_comp : 1; //Enable crc calculation for fbif address
2973 unsigned int dbg_crc_mem_wr_dis : 1; //Disable fb memory write
2974 unsigned int reserved0 : 27;
2975
2976 //Golden CRC values for each partition
2977 unsigned int dbg_crc_partb_golden[32];
2978 unsigned int dbg_crc_partf_golden[32];
2979 unsigned int dbg_crc_partg_golden[32];
2980 unsigned int dbg_crc_parth_golden[32];
2981 unsigned int dbg_crc_parti_golden[32];
2982 unsigned int dbg_crc_partj_golden[32];
2983 unsigned int dbg_crc_partk_golden[32];
2984 unsigned int dbg_crc_partl_golden[35];
2985
2986 //Compare status register for each partition.
2987 //each bit corresponding to the compare status for one interface (0: pass; 1: fail)
2988 //The number of valid bits for each partition shall equal to the number of golden crcs for that partition
2989 unsigned int dbg_crc_comp_partb;
2990 unsigned int dbg_crc_comp_partf;
2991 unsigned int dbg_crc_comp_partg;
2992 unsigned int dbg_crc_comp_parth;
2993 unsigned int dbg_crc_comp_parti;
2994 unsigned int dbg_crc_comp_partj;
2995 unsigned int dbg_crc_comp_partk;
2996 unsigned int dbg_crc_comp_partl[2]; //split into two compare status registers
2997
2998
2999 //HW CRC values generated from each partition. the number shall match with golden CRC number
3000 unsigned int dbg_crc_partb_crc[32];
3001 unsigned int dbg_crc_partf_crc[32];
3002 unsigned int dbg_crc_partg_crc[32];
3003 unsigned int dbg_crc_parth_crc[32];
3004 unsigned int dbg_crc_parti_crc[32];
3005 unsigned int dbg_crc_partj_crc[32];
3006 unsigned int dbg_crc_partk_crc[32];
3007 unsigned int dbg_crc_partl_crc[35];
3008
3009
3010 //HW verification purpose control fields
3011 unsigned int lambda_ssd; //lambda for SSD cost
3012 unsigned int lambda_satd; //lambda for SATD cost
3013 unsigned int lambda_ld; //lambda for laplacian cost
3014 unsigned char reserved1[180];
3015 } nvenc_debug_status_s; //2304 bytes
3016
3017 // 2.7. Bit Stream Output Data Buffer
3018 // ----------------------------------
3019 //
3020 // This buffer is used to store the encoded bit stream data at slice header
3021 // level and below.
3022 // The driver must ensure that there is enough free space in this buffer to
3023 // contain the entire output produced for the current execute, including any
3024 // headers that will be produced. Output will be written incrementally
3025 // from the starting position relative to the 256 byte aligned start location
3026 // specified for this buffer.
3027 //
3028 // 2.8. Motion Estimation Predictor Data Buffer
3029 // --------------------------------------------
3030 //
3031 // This buffer is used to store by the motion estimation unit to store vector
3032 // hints that can be used as explicit candidates or as guides for motion
3033 // search in future pictures.
3034 // During encode one such surface can be written and another can be read.
3035 //
3036 // 2.9. Rate Control Process Buffer
3037 // --------------------------------
3038 //
3039 // This buffer is used to store persistent rate control information. The same
3040 // buffer will be shared in all executes of a particular stream.
3041 //
3042 // This buffer is used only if picture level rate control is enabled ((rc_mode & 3) != 0)
3043
3044 // Macro to initialize Bavg in VBR mode
3045 #define NVENC_VBR_INIT_BAVG(framerate, ravg) (0) // zero-centered vbr fullness
3046 // Macro to initialize Whist and Wpbi
3047 #define NVENC_RC_INIT_COMPLEXITY(bpp_at_qs1) ((int)((bpp_at_qs1)*16)) // use this macro to decouple from implementation-dependent precision
3048
3049 typedef struct
3050 {
3051
3052 int nal_cpb_fullness; // 28.4 fixed point
3053 int vcl_cpb_fullness; // 28.4 fixed point
3054
3055 int Wpbi[3]; // 27.4 signed fixed point
3056 int Whist[3][3]; // 27.4 signed fixed point [pbi][t]
3057 int np; // 27.4 signed fixed point
3058 int nb; // 27.4 signed fixed point
3059 int t; // 27.4 signed fixed point
3060
3061 int Rmean; // 23.8 signed fixed point peak bitrate (bits/pixel)
3062 int Bavg; // 23.8 signed fixed point
3063
3064 short average_mvx; // average mvx info, can be used for ME hint
3065 short average_mvy; // average mvy info, can be used for ME hint
3066
3067 int prevQS; // previous second pass Qs derived from rate
3068 short prevQP; // previous 2nd pass qp
3069 short fwdQP; // QP of forward reference
3070
3071 unsigned char refQPcol[48]; // co-located mbrow qp of the most recently coded reference
3072 unsigned char Rcol[48]; // co-located rate (5.3 precision, relative to avg rate)
3073 unsigned char ref1QP[48]; // first-pass reference qp (when 1st pass is using its own reference frames)
3074
3075 unsigned int ext_intra_satd_Hist[2]; // external satd History
3076 unsigned char ext_scd_Hist; // scene change flag History
3077 unsigned char scene_change; // last coded frame was a scene change
3078 unsigned char qpp_modifier; // current qpp adjustment (subtracted from qpp thresholds)
3079 unsigned char Ksatd; // pass1 satd to pass2 complexity measure
3080 signed char Werr; // model deviation: Wpass2 / Wpass1 - 1.0, .8 signed fixed-point [0.5x..1.5x]
3081 signed char WerrI; // same as above for I-frames
3082 unsigned char avgBf; // 3.5 fixed point, average number of consecutive B-frames
3083 unsigned char reserved;
3084 unsigned int printf_offset; // Using for ucode print
3085 unsigned char reserved2[4];
3086
3087 } nvenc_persistent_state_s; // 256Bytes
3088
3089 // 2.a. Ucode Probability State
3090 // --------------------------------
3091 //
3092 // This buffer is used to store probability state computed and used during the last picture.
3093 // This is used to compute the probability updates for current picture
3094 //
3095
3096 // DO NOT rearrange this structure. The alignment is crucial for dmreads
3097 typedef struct
3098 {
3099 unsigned char coef_probs[4][8][3][11+5]; // 1536 bytes = 4*(3*128)
3100 // Padding cause this has to be read in parts
3101 unsigned char ymode_prob[4]; // 4 bytes
3102 unsigned char uvmode_prob[3]; // 3 bytes
3103 unsigned char reserved0; // Pad to word boundary
3104 unsigned char mv_context[2][19]; // 38 bytes
3105 unsigned char reserved1[18]; // Align to 32 byte boundary
3106
3107 }nvenc_vp8_prob_state_s;
3108
3109
3110 // 2.b. Rate Control stat buffer used for 2 pass encoding
3111 // ------------------------------------------------------
3112 //
3113 // This buffer is used to store rate control information for 2 pass encoding.
3114 // The same buffer will be shared in both the passes of the encoding.
3115 // The first pass will write MPEC stats to the buffer and 2nd pass will read
3116 // the stats from the same buffer for QP calculation. The layout of buffer is
3117 // msenc_rc_pic_stat_s followed by msenc_mbrow_stat_s for each mb row.
3118 //
3119
3120 typedef struct
3121 {
3122 unsigned int intra_mb_count; // number of intra MBs.
3123 unsigned int inter_mb_count; // number of inter MBs.
3124 unsigned int cumulative_intra_cost; // sum of all intra SA(T)Ds
3125 unsigned int cumulative_inter_cost; // sum of all inter SA(T)Ds
3126 unsigned int total_bit_count;
3127 unsigned int avgQP;
3128 unsigned int complexity;
3129 //split encoding
3130 unsigned int strip_complexity;
3131 unsigned int strip_intra_mb_count;
3132 unsigned char reserved[220];
3133 }nvenc_rc_pic_stat_s; //256 bytes
3134
3135 typedef struct
3136 {
3137 unsigned int mbrow_intra_mb_count : 12; // number of intra MBs
3138 unsigned int mbrow_inter_mb_count : 12; // number of inter MBs
3139 unsigned int mbrow_avgQP : 8; // average QP
3140 unsigned int mbrow_cumulative_intra_cost; // sum of all intra SA(T)Ds
3141 unsigned int mbrow_cumulative_inter_cost; // sum of all inter SA(T)Ds
3142 unsigned int mbrow_bits_per_row;
3143 }nvenc_mbrow_stat_s;
3144
3145 typedef struct
3146 {
3147 signed char act_qp_buf[4096]; // Buffer to store qp modifier based on avg activity for a MB row
3148 }nvenc_act_stat_s;
3149
3150 // 2.b. Generic Map Buffer
3151 // --------------------------------
3152 //
3153 // This buffer is used to store qp map when rcmode==4 & lambda_map when enabled. the structure is in run/level, run==0 means end.
3154 //
3155 typedef struct
3156 {
3157 unsigned short run; // number of blocks with the same value
3158 unsigned short level; // value
3159 } nvenc_generic_map_s;
3160
3161 typedef nvenc_generic_map_s nvenc_qp_map_s;
3162 typedef nvenc_generic_map_s nvenc_lambda_map_s;
3163
3164
3165 // 2.d. Encrypt Params buffer
3166 // --------------------------------
3167 //
3168 // This buffer is used by SEC / TSEC engine which will encrypt the encoded stream
3169 // MSENC will output the # of 16 byte blocks present in the encoded bitstream to noOfInputBlocks field.
3170 // MSENC ucode does not use any other field besides noOfInputBlocks.
3171 // These will be populated by driver / TSEC ucode
3172 // Currently used only for MSENC 2.0 for T114
3173 typedef struct _hdcp_encrypt_param_s
3174 {
3175 unsigned int sessionId; // <<in
3176 unsigned int noOfInputBlocks; // <<in
3177 unsigned int streamId; // <<in
3178 unsigned int encOffset; // <<in
3179 unsigned int streamCtr; // >>out
3180 unsigned int crcOffset; // >>out
3181 unsigned long long inputCtr; // >>out
3182 unsigned long long pesPriv[2]; // >>out
3183 unsigned int retCode; // >>out
3184 unsigned char reserved2[4];
3185 } hdcp_encrypt_param_s;
3186
3187 // Error codes used across all codecs
3188 typedef enum
3189 {
3190 E_NONE = 0U,
3191 E_GPTMR_TIMEOUT,
3192 E_MAGIC_NUMBER_MISMATCH,
3193 E_PICSETUP_OFFSET,
3194 E_ENC_STATUS_OUTPUT_OFFSET,
3195 E_OUTPUT_BITSTREAM_OFFSET,
3196 E_INSUFFICIENT_WRDMA_BUF,
3197 E_MDP_ERROR,
3198 E_RDO_ERROR,
3199 E_ME_PROGRAMMING,
3200 E_ME_HW,
3201 E_TFBIF_TIMEOUT,
3202 E_SKIP_ENCODING,
3203 E_INPUT_BITSTREAM_OFFSET,
3204 E_INPUT_HISTORY_OFFSET,
3205 E_MEPRED_OFFSET,
3206 E_EXTHINT_OFFSET,
3207 E_REFPIC_OFFSET,
3208 E_QPMAP_OFFSET,
3209 E_COLLOC_OFFSET,
3210 E_PROB_OFFSET,
3211 E_ENTROPY_OFFSET,
3212 E_FILTER_OFFSET,
3213 E_SSIM_RDO_OFFSET,
3214 E_RC_ERROR,
3215 E_SMALLE_BS_OVERFLOW,
3216 E_SMALLE_METHODSERROR,
3217 E_ENTROPY_ERR,
3218 E_RECON_OVERFLOW,
3219 TOTAL_ERR_CODES
3220 } ERROR_CODES;
3221
3222 // 3 - APPLICATION SPECIFIC METHOD REGISTERS
3223 //
3224 // The NVENC application method registers are accessed directly by the driver.
3225 // The range assignment is 0x400 - 0x7FC:
3226 //
3227 //
3228 // 3.1 - Common Methods
3229 // --------------------
3230 //
3231 // SetControlParams()
3232 // ------------------
3233 // This method sets the control parameters that are used in this execution
3234 // of the encode subclass.
3235 //
3236 // CODEC_TYPE field should be set as
3237 // 3: H.264 // same codec enum as for msdec
3238 //
3239 // FORCE_OUTPIC indicates that the encoded picture (after deblocking if that is enabled)
3240 // must be written out to the buffer specified by SetOutRefPic(), even if the
3241 // current picture is not marked as a reference picture.
3242 //
3243 // FORCE_OUTCOL indicates that the colocated vector data must be written out to the
3244 // buffer specified by SetOutColocData(), even if the current picture is
3245 // not marked as a reference picture.
3246 //
3247 // GPTIMER_ON, this flag is used in activating an app based timer with a timeout value
3248 // less than watchdog timer. When this app level timer expires, various hardware
3249 // submodules in NVENC will be reset, the status will be informed in flowControl
3250 // buffer if DEBUG_MODE is OFF (0) and app will return.
3251 //
3252 // ME_ONLY, indicates whether to run in normal mode of operation or activate only
3253 // motion estimation and write out search vector results
3254 // 0 = encode bitstream
3255 // 1 = only ME, do not run mode decision/recon/entropy encode
3256 //
3257 // SLICE_STAT_ON indicates if slice level statistics dumping is enabled. If enabled,
3258 // following the persistent state information, slice level statistics will be
3259 // output in the Encoder Status buffer. It is assumed that the number of slices
3260 // will be limited to picture height in units of MBs. If there are more slices in the
3261 // picture, driver should turn off slice stat output, by resetting this flag to 0.
3262 //
3263 // MPEC_STAT_ON indicates if nMB level mpec statistics dumping is enabled. If SLICE_STAT_ON
3264 // is enabled, MPEC_STAT_ON will be automatically get disabled and all the slice level
3265 // mpec statistics will be dumped to nvenc_mpec_stat_s.
3266 //
3267 // DEBUG_MODE indicates whether the app will return non-zero error codes to OS in case
3268 // of an error detected by the app.
3269 //
3270 // If the value is set to 1, upon detecting an error the app will NOT do a
3271 // soft reset of hw, the app will return appropriate error code to OS. This
3272 // shall be used during debugging phase.
3273 //
3274 // If the value is set to 0, upon detecting an error the app will do a soft
3275 // reset of hw and return with zero to OS. This shall be used for product.
3276 //
3277 // SUBFRAME_MODE used in low latency applications where client need to read the bitstream
3278 // data at slice boundary before frame done.
3279 // 0: disable
3280 // 1: flush at slice end and report last_valid_byte_offset
3281 // 2: report slice offsets without flushing
3282 // 3: report slice offsets with flush at slice end
3283 //
3284 // RC_MODE contains the rate control mode.
3285 // 0: Constant QP
3286 // 1: picture level VBR
3287 // 2: picture level CBR
3288 // 3: picture level VBR with const QP
3289 // 4: QP Map
3290 // 16: (same as 0)
3291 // 17: mbrow level VBR
3292 // 18: mbrow level CBR (QP is updated every macroblock row)
3293 // 19: mbrow level VBR with const QP
3294 // 32: macroblock level activity based rate control algorithm
3295 //
3296 //
3297 // 31 24 20 16 15 12 8 4 0
3298 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3299 // | |D| |G|S|M|C|P| | CODEC | SetControlParams
3300 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3301 //
3302 // #define NV_C9B7_NVENC_SET_CTRL_PARAM 0x00000700 /* -W-4R */
3303 // #define NV_C9B7_NVENC_SET_CTRL_PARAM_CODEC_TYPE 3:0 /* -W-UF */
3304 // #define NV_C9B7_NVENC_SET_CTRL_PARAM_CODEC_TYPE_H264 0x00000003
3305 // #define NV_C9B7_NVENC_SET_CTRL_PARAM_FORCE_OUTPIC 8:8 /* -W-UF */
3306 // #define NV_C9B7_NVENC_SET_CTRL_PARAM_FORCE_OUTCOL 9:9 /* -W-UF */
3307 // #define NV_C9B7_NVENC_SET_CTRL_PARAM_ME_ONLY 10:10 /* -W-UF */
3308 // #define NV_C9B7_NVENC_SET_CTRL_PARAM_SLICE_STAT_ON 11:11 /* -W-UF */
3309 // #define NV_C9B7_NVENC_SET_CTRL_PARAM_GPTIMER_ON 12:12 /* -W-UF */
3310 // #define NV_C9B7_NVENC_SET_CTRL_PARAM_MPEC_STAT_ON 15:15 /* -W-UF */
3311 // #define NV_C9B7_NVENC_SET_CTRL_PARAM_DEBUG_MODE 16:16 /* -W-UF */
3312 // #define NV_C9B7_NVENC_SET_CTRL_PARAM_SUBFRAME_MODE 18:17 /* -W-UF */
3313 // #define NV_C9B7_NVENC_SET_CTRL_PARAM_RC_MODE 31:24 /* -W-UF */
3314 //
3315 //
3316 // SetPictureIndex()
3317 // -----------------
3318 //
3319 // This method sets the picture index to NVENC. For the same picture, CEA and NVENC
3320 // should receive the same picture index. Picture index should be incremented by 1
3321 // in each new execute. CEA will put this in the CEA Hints data buffer.
3322 //
3323 // 31 24 23 16 15 8 7 0
3324 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3325 // | INDEX | SetPictureIndex
3326 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3327 //
3328 // #define NV_C9B7_NVENC_SET_PICTURE_INDEX 0x00000704 /* -W-4R */
3329 // #define NV_C9B7_NVENC_SET_PICTURE_INDEX_INDEX 31:0 /* -W-UF */
3330 //
3331 //
3332 // SetInRcData()
3333 // ------------------
3334 // This method sets the location of the RCDataBuffer. It sets the
3335 // upper bits (32 most significant bits) of the 40-bit offset where the buffer
3336 // is located. This buffer will have RC configuration data from CEA or an app.
3337 //
3338 // The values of OFFSET is defined and initialized to zero during the
3339 // instance's creation.
3340 //
3341 // 31 16 0
3342 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3343 // | OFFSET | SetInDrvPicSetup
3344 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3345 //
3346 // #define NV_C9B7_NVENC_SETIN_RC_DATA 0x0000070c /* -W-4R */
3347 // #define NV_C9B7_NVENC_SETIN_RC_DATA_OFFSET 31:0 /* -W-UF */
3348 //
3349 // SetInDrvPicSetup()
3350 // ------------------
3351 // This method sets the location of the DrvPictureSetupBuffer. It sets the
3352 // upper bits (32 most significant bits) of the 40-bit offset where the buffer
3353 // is located.
3354 //
3355 // The values of OFFSET is defined and initialized to zero during the
3356 // instance's creation.
3357 //
3358 // 31 16 0
3359 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3360 // | OFFSET | SetInDrvPicSetup
3361 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3362 //
3363 // #define NV_C9B7_NVENC_SETIN_DRV_PIC_SETUP 0x00000710 /* -W-4R */
3364 // #define NV_C9B7_NVENC_SETIN_DRV_PIC_SETUP_OFFSET 31:0 /* -W-UF */
3365 //
3366 //
3367 // SetInCEAHintsData()
3368 // -------------------
3369 // This method sets the CEA hints data buffer offset. It sets the upper bits (32
3370 // most significant bits) of the 40-bit offset where the buffer is located.
3371 //
3372 //
3373 // 31 16 0
3374 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3375 // | OFFSET | SetInCEAHintsData
3376 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3377 //
3378 // #define NV_C9B7_NVENC_SETIN_CEA_HINTS_DATA 0x00000714 /* -W-4R */
3379 // #define NV_C9B7_NVENC_SETIN_CEA_HINTS_DATA_OFFSET 31:0 /* -W-UF */
3380 //
3381 //
3382 // SetOutEncStatus()
3383 // -----------------
3384 // This method sets the encoder status buffer offset. It sets the upper bits
3385 // (32 most significant bits) of the 40-bit offset where the buffer is located.
3386 //
3387 // 31 16 0
3388 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3389 // | OFFSET | SetOutEncStatus
3390 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3391 //
3392 // #define NV_C9B7_NVENC_SETOUT_ENC_STATUS 0x00000718 /* -W-4R */
3393 // #define NV_C9B7_NVENC_SETOUT_ENC_STATUS_OFFSET 31:0 /* -W-UF */
3394 //
3395 //
3396 // SetOutBitstream()
3397 // -----------------
3398 // This method sets the bitstream output data buffer offset. It sets the upper
3399 // bits (32 most significant bits) of the 40-bit offset where the buffer is located.
3400 //
3401 // 31 16 0
3402 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3403 // | OFFSET | SetOutBitstream
3404 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3405 //
3406 // #define NV_C9B7_NVENC_SETOUT_BITSTREAM 0x0000071c /* -W-4R */
3407 // #define NV_C9B7_NVENC_SETOUT_BITSTREAM_OFFSET 31:0 /* -W-UF */
3408 //
3409 //
3410 // SetIOHistory()
3411 // --------------
3412 // This method sets the history buffer offset. It sets the upper bits (32
3413 // most significant bits) of the 40-bit offset where the buffer is located.
3414 //
3415 //
3416 // 31 16 0
3417 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3418 // | OFFSET | SetIOHistory
3419 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3420 //
3421 // #define NV_C9B7_NVENC_SETIO_HISTORY 0x00000720 /* -W-4R */
3422 // #define NV_C9B7_NVENC_SETIO_HISTORY_OFFSET 31:0 /* -W-UF */
3423 //
3424 //
3425 // SetIORCProcess()
3426 // ----------------
3427 // This method sets the RC Process buffer offset. It sets the upper bits
3428 // (32 most significant bits) of the 40-bit offset where the buffer is located.
3429 //
3430 // 31 16 0
3431 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3432 // | OFFSET | SetIORCProcess
3433 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3434 //
3435 // #define NV_C9B7_NVENC_SETIO_RC_PROCESS 0x00000724 /* -W-4R */
3436 // #define NV_C9B7_NVENC_SETIO_PROCESS_OFFSET 31:0 /* -W-UF */
3437 //
3438 //
3439 // SetInColocData()
3440 // ----------------
3441 // This method sets the input colocated motion data buffer offset. It sets the upper
3442 // bits (32 most significant bits) of the 40-bit offset where the buffer is located.
3443 // This is used only for encoding of B pictures. If the current picture is an I or P
3444 // picture, this method can be omitted.
3445 //
3446 //
3447 // 31 16 0
3448 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3449 // | OFFSET | SetInColocData
3450 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3451 //
3452 // #define NV_C9B7_NVENC_SETIN_COLOC_DATA 0x00000728 /* -W-4R */
3453 // #define NV_C9B7_NVENC_SETIN_COLOC_DATA_OFFSET 31:0 /* -W-UF */
3454 //
3455 //
3456 // SetOutColocData()
3457 // -----------------
3458 // This method sets the output colocated motion data buffer offset. It sets the upper
3459 // bits (32 most significant bits) of the 40-bit offset where the buffer is located.
3460 // This is used only for encoding of pictures that are marked as reference pictures.
3461 // If the current picture is not marked as a reference picture, this method can be omitted.
3462 //
3463 //
3464 // 31 16 0
3465 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3466 // | OFFSET | SetOutColocData
3467 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3468 //
3469 // #define NV_C9B7_NVENC_SETOUT_COLOC_DATA 0x0000072c /* -W-4R */
3470 // #define NV_C9B7_NVENC_SETOUT_COLOC_DATA_OFFSET 31:0 /* -W-UF */
3471 //
3472 //
3473 // SetOutRefPic()
3474 // --------------
3475 // This method sets the offset for the tiled 16x16 output reference picture produced by
3476 // the encode of the current picture. It sets the upper bits (32 most significant bits)
3477 // of the 40-bit offset where the buffer is located. This method must be sent if the
3478 // current picture is marked as a reference picture, or the FORCE_OUTPIC bit is set in
3479 // the SetControlParams().
3480 //
3481 // 31 16 0
3482 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3483 // | OFFSET | SetOutRefPic
3484 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3485 //
3486 // #define NV_C9B7_NVENC_SETOUT_REFPIC 0x00000730 /* -W-4R */
3487 // #define NV_C9B7_NVENC_SETOUT_REFPIC_OFFSET 31:0 /* -W-UF */
3488 //
3489 //
3490 // SetInCurPic()
3491 // -------------
3492 // This method sets the offset for current input picture to be encoded. It sets the upper
3493 // bits (32 most significant bits) of the 40-bit offset where the buffer is located.
3494 //
3495 // 31 16 0
3496 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3497 // | OFFSET | SetInCurPic
3498 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3499 //
3500 // #define NV_C9B7_NVENC_SETIN_CURPIC 0x00000734 /* -W-4R */
3501 // #define NV_C9B7_NVENC_SETIN_CURPIC_OFFSET 31:0 /* -W-UF */
3502 //
3503 //
3504 // SetInMEPredData()
3505 // -----------------
3506 // This method sets the offset for motion estimation predictor input data buffer.
3507 // This is the buffer containing vector hints produced by an earlier execute of NVENC.
3508 // The method sets the upper bits (32 most significant bits) of the 40-bit offset where
3509 // the buffer is located.
3510 //
3511 // 31 16 0
3512 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3513 // | OFFSET | SetInMEPredData
3514 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3515 //
3516 // #define NV_C9B7_NVENC_SETIN_MEPRED_DATA 0x00000738 /* -W-4R */
3517 // #define NV_C9B7_NVENC_SETIN_MEPRED_DATA_OFFSET 31:0 /* -W-UF */
3518 //
3519 //
3520 // SetOutMEPredData()
3521 // ------------------
3522 // This method sets the offset for motion estimation predictor output data Buffer.
3523 // It sets the upper bits (32 most significant bits) of the 40-bit offset where the
3524 // buffer is located.
3525 //
3526 // 31 16 0
3527 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3528 // | OFFSET | SetOutMEPredData
3529 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3530 //
3531 // #define NV_C9B7_NVENC_SETOUT_MEPRED_DATA 0x0000073c /* -W-4R */
3532 // #define NV_C9B7_NVENC_SETOUT_MEPRED_DATA_OFFSET 31:0 /* -W-UF */
3533 //
3534 //
3535 // SetInRefPic0()
3536 // --------------
3537 // This method sets the offset for reference picture 0. It sets the upper bits (32
3538 // most significant bits) of the 40-bit offset where the buffer is located.
3539 //
3540 // 31 16 0
3541 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3542 // | OFFSET | SetInRefPic0
3543 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3544 //
3545 // #define NV_C9B7_NVENC_SETIN_REFPIC0 0x00000400 /* -W-4R */
3546 // #define NV_C9B7_NVENC_SETIN_REFPIC0_OFFSET 31:0 /* -W-UF */
3547 //
3548 //
3549 // SetInRefPic1()
3550 // --------------
3551 // This method sets the offset for reference picture 1. It sets the upper bits (32
3552 // most significant bits) of the 40-bit offset where the buffer is located.
3553 //
3554 // 31 16 0
3555 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3556 // | OFFSET | SetInRefPic1
3557 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3558 //
3559 // #define NV_C9B7_NVENC_SETIN_REFPIC1 0x00000404 /* -W-4R */
3560 // #define NV_C9B7_NVENC_SETIN_REFPIC1_OFFSET 31:0 /* -W-UF */
3561 //
3562 //
3563 // SetInRefPic2()
3564 // --------------
3565 // This method sets the offset for reference picture 2. It sets the upper bits (32
3566 // most significant bits) of the 40-bit offset where the buffer is located.
3567 //
3568 // 31 16 0
3569 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3570 // | OFFSET | SetInRefPic2
3571 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3572 //
3573 // #define NV_C9B7_NVENC_SETIN_REFPIC2 0x00000408 /* -W-4R */
3574 // #define NV_C9B7_NVENC_SETIN_REFPIC2_OFFSET 31:0 /* -W-UF */
3575 //
3576 //
3577 // SetInRefPic3()
3578 // --------------
3579 // This method sets the offset for reference picture 3. It sets the upper bits (32
3580 // most significant bits) of the 40-bit offset where the buffer is located.
3581 //
3582 // 31 16 0
3583 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3584 // | OFFSET | SetInRefPic3
3585 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3586 //
3587 // #define NV_C9B7_NVENC_SETIN_REFPIC3 0x0000040c /* -W-4R */
3588 // #define NV_C9B7_NVENC_SETIN_REFPIC3_OFFSET 31:0 /* -W-UF */
3589 //
3590 //
3591 // SetInRefPic4()
3592 // --------------
3593 // This method sets the offset for reference picture 4. It sets the upper bits (32
3594 // most significant bits) of the 40-bit offset where the buffer is located.
3595 //
3596 // 31 16 0
3597 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3598 // | OFFSET | SetInRefPic4
3599 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3600 //
3601 // #define NV_C9B7_NVENC_SETIN_REFPIC4 0x00000410 /* -W-4R */
3602 // #define NV_C9B7_NVENC_SETIN_REFPIC4_OFFSET 31:0 /* -W-UF */
3603 //
3604 //
3605 // SetInRefPic5()
3606 // --------------
3607 // This method sets the offset for reference picture 5. It sets the upper bits (32
3608 // most significant bits) of the 40-bit offset where the buffer is located.
3609 //
3610 // 31 16 0
3611 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3612 // | OFFSET | SetInRefPic5
3613 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3614 //
3615 // #define NV_C9B7_NVENC_SETIN_REFPIC5 0x00000414 /* -W-4R */
3616 // #define NV_C9B7_NVENC_SETIN_REFPIC5_OFFSET 31:0 /* -W-UF */
3617 //
3618 //
3619 // SetInRefPic6()
3620 // --------------
3621 // This method sets the offset for reference picture 6. It sets the upper bits (32
3622 // most significant bits) of the 40-bit offset where the buffer is located.
3623 //
3624 // 31 16 0
3625 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3626 // | OFFSET | SetInRefPic6
3627 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3628 //
3629 // #define NV_C9B7_NVENC_SETIN_REFPIC6 0x00000418 /* -W-4R */
3630 // #define NV_C9B7_NVENC_SETIN_REFPIC6_OFFSET 31:0 /* -W-UF */
3631 //
3632 //
3633 // SetInRefPic7()
3634 // --------------
3635 // This method sets the offset for reference picture 7. It sets the upper bits (32
3636 // most significant bits) of the 40-bit offset where the buffer is located.
3637 //
3638 // 31 16 0
3639 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3640 // | OFFSET | SetInRefPic7
3641 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3642 //
3643 // #define NV_C9B7_NVENC_SETIN_REFPIC7 0x0000041c /* -W-4R */
3644 // #define NV_C9B7_NVENC_SETIN_REFPIC7_OFFSET 31:0 /* -W-UF */
3645 //
3646 //
3647 // SetInRefPic8()
3648 // --------------
3649 // This method sets the offset for reference picture 8. It sets the upper bits (32
3650 // most significant bits) of the 40-bit offset where the buffer is located.
3651 //
3652 // 31 16 0
3653 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3654 // | OFFSET | SetInRefPic8
3655 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3656 //
3657 // #define NV_C9B7_NVENC_SETIN_REFPIC8 0x00000420 /* -W-4R */
3658 // #define NV_C9B7_NVENC_SETIN_REFPIC8_OFFSET 31:0 /* -W-UF */
3659 //
3660 //
3661 // SetInRefPic9()
3662 // --------------
3663 // This method sets the offset for reference picture 9. It sets the upper bits (32
3664 // most significant bits) of the 40-bit offset where the buffer is located.
3665 //
3666 // 31 16 0
3667 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3668 // | OFFSET | SetInRefPic9
3669 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3670 //
3671 // #define NV_C9B7_NVENC_SETIN_REFPIC9 0x00000424 /* -W-4R */
3672 // #define NV_C9B7_NVENC_SETIN_REFPIC9_OFFSET 31:0 /* -W-UF */
3673 //
3674 //
3675 // SetInRefPic10()
3676 // ---------------
3677 // This method sets the offset for reference picture 10. It sets the upper bits (32
3678 // most significant bits) of the 40-bit offset where the buffer is located.
3679 //
3680 // 31 16 0
3681 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3682 // | OFFSET | SetInRefPic10
3683 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3684 //
3685 // #define NV_C9B7_NVENC_SETIN_REFPIC10 0x00000428 /* -W-4R */
3686 // #define NV_C9B7_NVENC_SETIN_REFPIC10_OFFSET 31:0 /* -W-UF */
3687 //
3688 //
3689 // SetInRefPic11()
3690 // ---------------
3691 // This method sets the offset for reference picture 11. It sets the upper bits (32
3692 // most significant bits) of the 40-bit offset where the buffer is located.
3693 //
3694 // 31 16 0
3695 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3696 // | OFFSET | SetInRefPic11
3697 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3698 //
3699 // #define NV_C9B7_NVENC_SETIN_REFPIC11 0x0000042c /* -W-4R */
3700 // #define NV_C9B7_NVENC_SETIN_REFPIC11_OFFSET 31:0 /* -W-UF */
3701 //
3702 //
3703 // SetInRefPic12()
3704 // ---------------
3705 // This method sets the offset for reference picture 12. It sets the upper bits (32
3706 // most significant bits) of the 40-bit offset where the buffer is located.
3707 //
3708 // 31 16 0
3709 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3710 // | OFFSET | SetInRefPic12
3711 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3712 //
3713 // #define NV_C9B7_NVENC_SETIN_REFPIC12 0x00000430 /* -W-4R */
3714 // #define NV_C9B7_NVENC_SETIN_REFPIC12_OFFSET 31:0 /* -W-UF */
3715 //
3716 //
3717 // SetInRefPic13()
3718 // ---------------
3719 // This method sets the offset for reference picture 13. It sets the upper bits (32
3720 // most significant bits) of the 40-bit offset where the buffer is located.
3721 //
3722 // 31 16 0
3723 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3724 // | OFFSET | SetInRefPic13
3725 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3726 //
3727 // #define NV_C9B7_NVENC_SETIN_REFPIC13 0x00000434 /* -W-4R */
3728 // #define NV_C9B7_NVENC_SETIN_REFPIC13_OFFSET 31:0 /* -W-UF */
3729 //
3730 //
3731 // SetInRefPic14()
3732 // ---------------
3733 // This method sets the offset for reference picture 14. It sets the upper bits (32
3734 // most significant bits) of the 40-bit offset where the buffer is located.
3735 //
3736 // 31 16 0
3737 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3738 // | OFFSET | SetInRefPic14
3739 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3740 //
3741 // #define NV_C9B7_NVENC_SETIN_REFPIC14 0x00000438 /* -W-4R */
3742 // #define NV_C9B7_NVENC_SETIN_REFPIC14_OFFSET 31:0 /* -W-UF */
3743 //
3744 //
3745 // SetInRefPic15()
3746 // ---------------
3747 // This method sets the offset for reference picture 15. It sets the upper bits (32
3748 // most significant bits) of the 40-bit offset where the buffer is located.
3749 //
3750 // 31 16 0
3751 // .-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
3752 // | OFFSET | SetInRefPic15
3753 // `-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
3754 //
3755 // #define NV_C9B7_NVENC_SETIN_REFPIC15 0x0000043c /* -W-4R */
3756 // #define NV_C9B7_NVENC_SETIN_REFPIC15_OFFSET 31:0 /* -W-UF */
3757 //
3758 //
3759 //
3760 //
3761 // 4 - APPLICATION SPECIFIC ERROR CODES
3762 //
3763 // The upper 4 bit indicate the codec type. The lower 28 bit are the error code.
3764 //
3765 // 5 - Some shared defines
3766 #define TEB_BUF_SIZE (256 * 1024)
3767 #define HIST_BLOCK_SIZE 192
3768
3769 #define H264_HIST_BLOCK_SIZE 224
3770 #define H265_HIST_BLOCK_SIZE H264_HIST_BLOCK_SIZE
3771 #define VP9_HIST_BLOCK_SIZE H265_HIST_BLOCK_SIZE
3772
3773 //HIST BLOCK structre has not been finalized, subject to change.
3774 #define AV1_HIST_BLOCK_SIZE VP9_HIST_BLOCK_SIZE
3775
3776 // Errors
3777 #define NvC9B7EncErrorH264ApptimerExpired 0x30000001
3778 #define NvC9B7EncErrorH264InvalidInput 0x30000002
3779 #define NvC9B7EncErrorH264HwerrInterrupt 0x30000003
3780 #define NvC9B7EncErrorH264BadMagic 0x30000004
3781
3782 // Appendix A - KEY
3783 //
3784 // Read
3785 // ' ' = Other Information
3786 // '-' = Field is part of a write-only register
3787 // 'C' = Value read is always the same, constant value line follows (C)
3788 // 'R' = Value is read
3789 //
3790 // Write
3791 // ' ' = Other Information
3792 // '-' = Must not be written (D), value ignored when written (R,A,F)
3793 // 'W' = Can be written
3794 //
3795 // Internal State
3796 // ' ' = Other Information
3797 // '-' = No internal state
3798 // 'X' = Internal state, initial value is unknown
3799 // 'I' = Internal state, initial value is known and follows (I)
3800 // 'V' = Internal state, initialize at volatile reset
3801 // 'N' = Internal state, initial value and initialize at volatile reset
3802 // 'C' = Internal state, initial value at object creation
3803 //
3804 // Declaration/Size
3805 // ' ' = Other Information
3806 // '-' = Does Not Apply
3807 // 'V' = Type is void
3808 // 'U' = Type is unsigned integer
3809 // 'S' = Type is signed integer
3810 // 'F' = Type is IEEE floating point
3811 // '1' = Byte size (008)
3812 // '2' = Short size (016)
3813 // '3' = Three byte size (024)
3814 // '4' = Word size (032)
3815 // '8' = Double size (064)
3816 //
3817 // Define Indicator
3818 // ' ' = Other Information
3819 // 'D' = Device
3820 // 'M' = Memory
3821 // 'R' = Register
3822 // 'A' = Array of Registers
3823 // 'F' = Field
3824 // 'V' = Value
3825 // 'C' = Clear value
3826 // 'S' = Set value
3827 // 'T' = Call task function
3828
3829
3830 #endif