forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB00c1b3fTahinli2 months ago1999 commits

av1.rs480 lines, 17.4 KiBHistoryRawDownload
1//! AV1 decode parameter buffers (`va_dec_av1.h`).
2
3use std::ffi::c_void;
4
5use ec_va::sys::{VAPictureParameterBufferType, VASliceParameterBufferType, VASurfaceID};
6
7use super::{INVALID_SURFACE, VaParam};
8use crate::va_bits;
9
10va_bits! {
11 /// `VASegmentationStructAV1::segment_info_fields`.
12 SegmentInfoFields: u32 {
13 enabled: 1,
14 update_map: 1,
15 temporal_update: 1,
16 update_data: 1,
17 }
18}
19
20/// `VASegmentationStructAV1`, `va_dec_av1.h:65`.
21#[repr(C)]
22#[derive(Debug, Clone, Copy, Default)]
23pub struct SegmentationStructAV1 {
24 /// Segmentation flags.
25 pub segment_info_fields: SegmentInfoFields,
26 /// `FeatureData[segment][feature]`.
27 pub feature_data: [[i16; 8]; 8],
28 /// `FeatureEnabled[segment]` as a bitmask over features.
29 pub feature_mask: [u8; 8],
30 pub(crate) va_reserved: [u32; 4],
31}
32
33va_bits! {
34 /// `VAFilmGrainStructAV1::film_grain_info_fields`.
35 FilmGrainInfoFields: u32 {
36 apply_grain: 1,
37 chroma_scaling_from_luma: 1,
38 grain_scaling_minus_8: 2,
39 ar_coeff_lag: 2,
40 ar_coeff_shift_minus_6: 2,
41 grain_scale_shift: 2,
42 overlap_flag: 1,
43 clip_to_restricted_range: 1,
44 }
45}
46
47/// `VAFilmGrainStructAV1`, `va_dec_av1.h:100`.
48///
49/// Film grain synthesis is a display-side effect; the decoder fills this so a
50/// driver that applies grain can, and edith's own path leaves `apply_grain`
51/// clear (the frame it wants is the ungrained reconstruction).
52#[repr(C)]
53#[derive(Debug, Clone, Copy, Default)]
54pub struct FilmGrainStructAV1 {
55 /// Film grain flags.
56 pub film_grain_info_fields: FilmGrainInfoFields,
57 /// `grain_seed`.
58 pub grain_seed: u16,
59 /// `num_y_points`.
60 pub num_y_points: u8,
61 /// `point_y_value`.
62 pub point_y_value: [u8; 14],
63 /// `point_y_scaling`.
64 pub point_y_scaling: [u8; 14],
65 /// `num_cb_points`.
66 pub num_cb_points: u8,
67 /// `point_cb_value`.
68 pub point_cb_value: [u8; 10],
69 /// `point_cb_scaling`.
70 pub point_cb_scaling: [u8; 10],
71 /// `num_cr_points`.
72 pub num_cr_points: u8,
73 /// `point_cr_value`.
74 pub point_cr_value: [u8; 10],
75 /// `point_cr_scaling`.
76 pub point_cr_scaling: [u8; 10],
77 /// `ar_coeffs_y_plus_128 - 128`.
78 pub ar_coeffs_y: [i8; 24],
79 /// `ar_coeffs_cb_plus_128 - 128`.
80 pub ar_coeffs_cb: [i8; 25],
81 /// `ar_coeffs_cr_plus_128 - 128`.
82 pub ar_coeffs_cr: [i8; 25],
83 /// `cb_mult`.
84 pub cb_mult: u8,
85 /// `cb_luma_mult`.
86 pub cb_luma_mult: u8,
87 /// `cb_offset`.
88 pub cb_offset: u16,
89 /// `cr_mult`.
90 pub cr_mult: u8,
91 /// `cr_luma_mult`.
92 pub cr_luma_mult: u8,
93 /// `cr_offset`.
94 pub cr_offset: u16,
95 pub(crate) va_reserved: [u32; 4],
96}
97
98/// `VAWarpedMotionParamsAV1`, `va_dec_av1.h:180`.
99#[repr(C)]
100#[derive(Debug, Clone, Copy, Default)]
101pub struct WarpedMotionParamsAV1 {
102 /// `VAAV1Transformation*`: identity, translation, rotzoom or affine.
103 pub wmtype: i32,
104 /// `gm_params`, six meaningful entries.
105 pub wmmat: [i32; 8],
106 /// Set when the model was rejected as non-invertible.
107 pub invalid: u8,
108 pub(crate) va_reserved: [u32; 4],
109}
110
111va_bits! {
112 /// `VADecPictureParameterBufferAV1::seq_info_fields`.
113 SeqInfoFields: u32 {
114 still_picture: 1,
115 use_128x128_superblock: 1,
116 enable_filter_intra: 1,
117 enable_intra_edge_filter: 1,
118 enable_interintra_compound: 1,
119 enable_masked_compound: 1,
120 enable_dual_filter: 1,
121 enable_order_hint: 1,
122 enable_jnt_comp: 1,
123 enable_cdef: 1,
124 mono_chrome: 1,
125 color_range: 1,
126 subsampling_x: 1,
127 subsampling_y: 1,
128 chroma_sample_position: 1,
129 film_grain_params_present: 1,
130 }
131}
132
133va_bits! {
134 /// `VADecPictureParameterBufferAV1::pic_info_fields`.
135 PicInfoFields: u32 {
136 frame_type: 2,
137 show_frame: 1,
138 showable_frame: 1,
139 error_resilient_mode: 1,
140 disable_cdf_update: 1,
141 allow_screen_content_tools: 1,
142 force_integer_mv: 1,
143 allow_intrabc: 1,
144 use_superres: 1,
145 allow_high_precision_mv: 1,
146 is_motion_mode_switchable: 1,
147 use_ref_frame_mvs: 1,
148 disable_frame_end_update_cdf: 1,
149 uniform_tile_spacing_flag: 1,
150 allow_warped_motion: 1,
151 large_scale_tile: 1,
152 }
153}
154
155va_bits! {
156 /// `VADecPictureParameterBufferAV1::loop_filter_info_fields`.
157 LoopFilterInfoFields: u8 {
158 sharpness_level: 3,
159 mode_ref_delta_enabled: 1,
160 mode_ref_delta_update: 1,
161 }
162}
163
164va_bits! {
165 /// `VADecPictureParameterBufferAV1::qmatrix_fields`.
166 QMatrixFields: u16 {
167 using_qmatrix: 1,
168 qm_y: 4,
169 qm_u: 4,
170 qm_v: 4,
171 }
172}
173
174va_bits! {
175 /// `VADecPictureParameterBufferAV1::mode_control_fields`.
176 ModeControlFields: u32 {
177 delta_q_present_flag: 1,
178 log2_delta_q_res: 2,
179 delta_lf_present_flag: 1,
180 log2_delta_lf_res: 2,
181 delta_lf_multi: 1,
182 tx_mode: 2,
183 reference_select: 1,
184 reduced_tx_set_used: 1,
185 skip_mode_present: 1,
186 }
187}
188
189va_bits! {
190 /// `VADecPictureParameterBufferAV1::loop_restoration_fields`.
191 LoopRestorationFields: u16 {
192 yframe_restoration_type: 2,
193 cbframe_restoration_type: 2,
194 crframe_restoration_type: 2,
195 lr_unit_shift: 2,
196 lr_uv_shift: 1,
197 }
198}
199
200/// `VADecPictureParameterBufferAV1`, `va_dec_av1.h:206`.
201#[repr(C)]
202#[derive(Debug, Clone, Copy)]
203pub struct PictureParameterBufferAV1 {
204 /// `seq_profile`.
205 pub profile: u8,
206 /// `OrderHintBits - 1`.
207 pub order_hint_bits_minus_1: u8,
208 /// 0 for 8-bit, 1 for 10-bit, 2 for 12-bit.
209 pub bit_depth_idx: u8,
210 /// `matrix_coefficients` (H.273).
211 pub matrix_coefficients: u8,
212 /// Sequence header flags.
213 pub seq_info_fields: SeqInfoFields,
214 /// Surface being decoded into.
215 pub current_frame: VASurfaceID,
216 /// Surface to display for a `show_existing_frame`, else the current frame.
217 pub current_display_picture: VASurfaceID,
218 /// Large scale tile only; always zero here.
219 pub anchor_frames_num: u8,
220 /// Large scale tile only; always NULL here.
221 pub anchor_frames_list: *mut c_void,
222 /// `FrameWidth - 1`.
223 pub frame_width_minus1: u16,
224 /// `FrameHeight - 1`.
225 pub frame_height_minus1: u16,
226 /// Large scale tile only.
227 pub output_frame_width_in_tiles_minus_1: u16,
228 /// Large scale tile only.
229 pub output_frame_height_in_tiles_minus_1: u16,
230 /// The eight reference slots.
231 pub ref_frame_map: [VASurfaceID; 8],
232 /// `ref_frame_idx`, LAST through ALTREF.
233 pub ref_frame_idx: [u8; 7],
234 /// `primary_ref_frame`.
235 pub primary_ref_frame: u8,
236 /// `OrderHint`.
237 pub order_hint: u8,
238 /// Segmentation parameters.
239 pub seg_info: SegmentationStructAV1,
240 /// Film grain parameters.
241 pub film_grain_info: FilmGrainStructAV1,
242 /// `TileCols`.
243 pub tile_cols: u8,
244 /// `TileRows`.
245 pub tile_rows: u8,
246 /// Per-column widths in superblocks, minus one.
247 pub width_in_sbs_minus_1: [u16; 63],
248 /// Per-row heights in superblocks, minus one.
249 pub height_in_sbs_minus_1: [u16; 63],
250 /// `TileCols * TileRows - 1`.
251 pub tile_count_minus_1: u16,
252 /// `context_update_tile_id`.
253 pub context_update_tile_id: u16,
254 /// Frame header flags.
255 pub pic_info_fields: PicInfoFields,
256 /// `SuperresDenom`.
257 pub superres_scale_denominator: u8,
258 /// `interpolation_filter`.
259 pub interp_filter: u8,
260 /// `loop_filter_level[0..2]`.
261 pub filter_level: [u8; 2],
262 /// `loop_filter_level[2]`.
263 pub filter_level_u: u8,
264 /// `loop_filter_level[3]`.
265 pub filter_level_v: u8,
266 /// Loop filter flags.
267 pub loop_filter_info_fields: LoopFilterInfoFields,
268 /// `loop_filter_ref_deltas`.
269 pub ref_deltas: [i8; 8],
270 /// `loop_filter_mode_deltas`.
271 pub mode_deltas: [i8; 2],
272 /// `base_q_idx`.
273 pub base_qindex: u8,
274 /// `DeltaQYDc`.
275 pub y_dc_delta_q: i8,
276 /// `DeltaQUDc`.
277 pub u_dc_delta_q: i8,
278 /// `DeltaQUAc`.
279 pub u_ac_delta_q: i8,
280 /// `DeltaQVDc`.
281 pub v_dc_delta_q: i8,
282 /// `DeltaQVAc`.
283 pub v_ac_delta_q: i8,
284 /// Quantiser matrix flags.
285 pub qmatrix_fields: QMatrixFields,
286 /// Mode control flags.
287 pub mode_control_fields: ModeControlFields,
288 /// `CdefDamping - 3`.
289 pub cdef_damping_minus_3: u8,
290 /// `cdef_bits`.
291 pub cdef_bits: u8,
292 /// Combined luma primary/secondary strengths, as libva packs them.
293 pub cdef_y_strengths: [u8; 8],
294 /// Combined chroma primary/secondary strengths.
295 pub cdef_uv_strengths: [u8; 8],
296 /// Loop restoration flags.
297 pub loop_restoration_fields: LoopRestorationFields,
298 /// Global motion for LAST..ALTREF.
299 pub wm: [WarpedMotionParamsAV1; 7],
300 pub(crate) va_reserved: [u32; 8],
301}
302
303impl Default for PictureParameterBufferAV1 {
304 fn default() -> Self {
305 PictureParameterBufferAV1 {
306 profile: 0,
307 order_hint_bits_minus_1: 0,
308 bit_depth_idx: 0,
309 matrix_coefficients: 2, // MC_UNSPECIFIED
310 seq_info_fields: SeqInfoFields::default(),
311 current_frame: INVALID_SURFACE,
312 current_display_picture: INVALID_SURFACE,
313 anchor_frames_num: 0,
314 anchor_frames_list: std::ptr::null_mut(),
315 frame_width_minus1: 0,
316 frame_height_minus1: 0,
317 output_frame_width_in_tiles_minus_1: 0,
318 output_frame_height_in_tiles_minus_1: 0,
319 ref_frame_map: [INVALID_SURFACE; 8],
320 ref_frame_idx: [0; 7],
321 primary_ref_frame: 0,
322 order_hint: 0,
323 seg_info: SegmentationStructAV1::default(),
324 film_grain_info: FilmGrainStructAV1::default(),
325 tile_cols: 1,
326 tile_rows: 1,
327 width_in_sbs_minus_1: [0; 63],
328 height_in_sbs_minus_1: [0; 63],
329 tile_count_minus_1: 0,
330 context_update_tile_id: 0,
331 pic_info_fields: PicInfoFields::default(),
332 superres_scale_denominator: 8,
333 interp_filter: 0,
334 filter_level: [0; 2],
335 filter_level_u: 0,
336 filter_level_v: 0,
337 loop_filter_info_fields: LoopFilterInfoFields::default(),
338 ref_deltas: [0; 8],
339 mode_deltas: [0; 2],
340 base_qindex: 0,
341 y_dc_delta_q: 0,
342 u_dc_delta_q: 0,
343 u_ac_delta_q: 0,
344 v_dc_delta_q: 0,
345 v_ac_delta_q: 0,
346 qmatrix_fields: QMatrixFields::default(),
347 mode_control_fields: ModeControlFields::default(),
348 cdef_damping_minus_3: 0,
349 cdef_bits: 0,
350 cdef_y_strengths: [0; 8],
351 cdef_uv_strengths: [0; 8],
352 loop_restoration_fields: LoopRestorationFields::default(),
353 wm: [WarpedMotionParamsAV1::default(); 7],
354 va_reserved: [0; 8],
355 }
356 }
357}
358
359// SAFETY: `#[repr(C)]` transcription of `VADecPictureParameterBufferAV1`,
360// checked by the assertion block below. The one pointer field is the large
361// scale tile anchor list, which this crate always leaves NULL (that mode is out
362// of scope), so no dangling pointer can reach the driver.
363unsafe impl VaParam for PictureParameterBufferAV1 {
364 const TYPE: i32 = VAPictureParameterBufferType;
365}
366
367/// `VASliceParameterBufferAV1`, `va_dec_av1.h:660` — one per tile.
368#[repr(C)]
369#[derive(Debug, Clone, Copy, Default)]
370pub struct SliceParameterBufferAV1 {
371 /// Bytes of tile data.
372 pub slice_data_size: u32,
373 /// Offset of the tile within the data buffer.
374 pub slice_data_offset: u32,
375 /// `VA_SLICE_DATA_FLAG_*`.
376 pub slice_data_flag: u32,
377 /// Tile row.
378 pub tile_row: u16,
379 /// Tile column.
380 pub tile_column: u16,
381 pub(crate) tg_start: u16,
382 pub(crate) tg_end: u16,
383 /// Large scale tile only.
384 pub anchor_frame_idx: u8,
385 /// Large scale tile only.
386 pub tile_idx_in_tile_list: u16,
387 pub(crate) va_reserved: [u32; 4],
388}
389
390// SAFETY: as `PictureParameterBufferAV1`; integers only.
391unsafe impl VaParam for SliceParameterBufferAV1 {
392 const TYPE: i32 = VASliceParameterBufferType;
393}
394
395// ---------------------------------------------------------------------------
396// ABI transcription check — `crates/ec-hw/abi-probe.c`, libva 1.23.0, x86_64:
397//
398// VASegmentationStructAV1 size=156 align=4 feature_data=4
399// feature_mask=132
400// VAFilmGrainStructAV1 size=176 align=4 grain_seed=4
401// ar_coeffs_y=77 cr_offset=158
402// VAWarpedMotionParamsAV1 size=56 align=4 wmmat=4 invalid=36
403// VADecPictureParameterBufferAV1 size=1160 align=8 seq_info_fields=4
404// current_frame=8
405// anchor_frames_num=16
406// anchor_frames_list=24
407// frame_width_minus1=32
408// ref_frame_map=40
409// ref_frame_idx=72
410// seg_info=84
411// film_grain_info=240
412// tile_cols=416
413// width_in_sbs_minus_1=418
414// height_in_sbs_minus_1=544
415// tile_count_minus_1=670
416// pic_info_fields=676
417// superres_scale_denominator=680
418// loop_filter_info_fields=686
419// ref_deltas=687 base_qindex=697
420// qmatrix_fields=704
421// mode_control_fields=708
422// cdef_damping_minus_3=712
423// cdef_y_strengths=714
424// loop_restoration_fields=730
425// wm=732
426// VASliceParameterBufferAV1 size=40 align=4 tile_row=12
427// anchor_frame_idx=20
428// tile_idx_in_tile_list=22
429const _: () = {
430 use std::mem::{align_of, offset_of, size_of};
431
432 assert!(size_of::<SegmentationStructAV1>() == 156 && align_of::<SegmentationStructAV1>() == 4);
433 assert!(offset_of!(SegmentationStructAV1, feature_data) == 4);
434 assert!(offset_of!(SegmentationStructAV1, feature_mask) == 132);
435
436 assert!(size_of::<FilmGrainStructAV1>() == 176 && align_of::<FilmGrainStructAV1>() == 4);
437 assert!(offset_of!(FilmGrainStructAV1, grain_seed) == 4);
438 assert!(offset_of!(FilmGrainStructAV1, ar_coeffs_y) == 77);
439 assert!(offset_of!(FilmGrainStructAV1, cr_offset) == 158);
440
441 assert!(size_of::<WarpedMotionParamsAV1>() == 56 && align_of::<WarpedMotionParamsAV1>() == 4);
442 assert!(offset_of!(WarpedMotionParamsAV1, wmmat) == 4);
443 assert!(offset_of!(WarpedMotionParamsAV1, invalid) == 36);
444
445 assert!(
446 size_of::<PictureParameterBufferAV1>() == 1160
447 && align_of::<PictureParameterBufferAV1>() == 8
448 );
449 assert!(offset_of!(PictureParameterBufferAV1, seq_info_fields) == 4);
450 assert!(offset_of!(PictureParameterBufferAV1, current_frame) == 8);
451 assert!(offset_of!(PictureParameterBufferAV1, anchor_frames_num) == 16);
452 assert!(offset_of!(PictureParameterBufferAV1, anchor_frames_list) == 24);
453 assert!(offset_of!(PictureParameterBufferAV1, frame_width_minus1) == 32);
454 assert!(offset_of!(PictureParameterBufferAV1, ref_frame_map) == 40);
455 assert!(offset_of!(PictureParameterBufferAV1, ref_frame_idx) == 72);
456 assert!(offset_of!(PictureParameterBufferAV1, seg_info) == 84);
457 assert!(offset_of!(PictureParameterBufferAV1, film_grain_info) == 240);
458 assert!(offset_of!(PictureParameterBufferAV1, tile_cols) == 416);
459 assert!(offset_of!(PictureParameterBufferAV1, width_in_sbs_minus_1) == 418);
460 assert!(offset_of!(PictureParameterBufferAV1, height_in_sbs_minus_1) == 544);
461 assert!(offset_of!(PictureParameterBufferAV1, tile_count_minus_1) == 670);
462 assert!(offset_of!(PictureParameterBufferAV1, pic_info_fields) == 676);
463 assert!(offset_of!(PictureParameterBufferAV1, superres_scale_denominator) == 680);
464 assert!(offset_of!(PictureParameterBufferAV1, loop_filter_info_fields) == 686);
465 assert!(offset_of!(PictureParameterBufferAV1, ref_deltas) == 687);
466 assert!(offset_of!(PictureParameterBufferAV1, base_qindex) == 697);
467 assert!(offset_of!(PictureParameterBufferAV1, qmatrix_fields) == 704);
468 assert!(offset_of!(PictureParameterBufferAV1, mode_control_fields) == 708);
469 assert!(offset_of!(PictureParameterBufferAV1, cdef_damping_minus_3) == 712);
470 assert!(offset_of!(PictureParameterBufferAV1, cdef_y_strengths) == 714);
471 assert!(offset_of!(PictureParameterBufferAV1, loop_restoration_fields) == 730);
472 assert!(offset_of!(PictureParameterBufferAV1, wm) == 732);
473
474 assert!(
475 size_of::<SliceParameterBufferAV1>() == 40 && align_of::<SliceParameterBufferAV1>() == 4
476 );
477 assert!(offset_of!(SliceParameterBufferAV1, tile_row) == 12);
478 assert!(offset_of!(SliceParameterBufferAV1, anchor_frame_idx) == 20);
479 assert!(offset_of!(SliceParameterBufferAV1, tile_idx_in_tile_list) == 22);
480};