edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching·0 forks·Rust·370.3 MiB·9b67700·Tahinli·3 days ago·4021 commits
| 1 | //! Decoder for one inter-frame tile payload: the tile walk that drives the |
| 2 | //! `decode_inter_block` family over a whole tile, with and without loop-restoration |
| 3 | //! units. Moved out of `decode/mod.rs` (av1split D5); the items are unchanged. |
| 4 | |
| 5 | use super::*; |
| 6 | |
| 7 | /// Decodes the payload [`crate::tile::sb_coeff_inter_frame_tile`] writes, |
| 8 | /// against `reference` (the previous frame's own decoded picture, at this |
| 9 | /// frame's true size -- a decoder's single-slot DPB, matching what this |
| 10 | /// crate's encoder always predicts from), returning the picture it |
| 11 | /// reconstructs to. Mirrors [`decode_key_frame_tile`]'s own contract |
| 12 | /// (`mi_cols`/`mi_rows`/`base_q_idx` from the frame header, |
| 13 | /// `frame_width`/`frame_height` its true render size). |
| 14 | /// |
| 15 | /// # Errors |
| 16 | /// Returns an error under the same conditions [`decode_inter_block`] does, |
| 17 | /// or when `reference` is not this frame's own true size, or when the tile |
| 18 | /// codes a 16x16 leaf whose own true edge cuts through it (round 2, same |
| 19 | /// refusal [`crate::tile`]'s writer gives its encoder). |
| 20 | #[allow(dead_code)] |
| 21 | // read only from the `#[cfg(test)]` gates |
| 22 | // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. |
| 23 | #[allow(clippy::too_many_arguments)] |
| 24 | pub(crate) fn decode_inter_frame_tile( |
| 25 | data: &[u8], |
| 26 | mi_cols: u32, |
| 27 | mi_rows: u32, |
| 28 | base_q_idx: u8, |
| 29 | frame_width: u32, |
| 30 | frame_height: u32, |
| 31 | refpix: &RefPix<'_>, |
| 32 | cdef: &CdefParams, |
| 33 | loop_filter: &LoopFilterParams, |
| 34 | allow_high_precision_mv: bool, |
| 35 | force_integer_mv: bool, |
| 36 | interp_fixed: Option<mc::InterpFilterKind>, |
| 37 | enable_dual_filter: bool, |
| 38 | reference_select: bool, |
| 39 | // lane-intertx: this frame header's own `reduced_tx_set` (spec 5.9.2) -- |
| 40 | // see [`decode_inter_frame_tile_lr`]'s parameter. Same stale-header |
| 41 | // class as `tx_select` below. |
| 42 | reduced_tx_set: bool, |
| 43 | // This frame header's `tx_mode == TxMode::Select`: `Encoded::tx_select`. |
| 44 | // Hard-coding `false` here desynced at the first `tx_depth` symbol once |
| 45 | // inter frames coded Select by default (class: test asserts against a |
| 46 | // stale header, second instance). |
| 47 | tx_select: bool, |
| 48 | // The CDF state this frame's tile was WRITTEN from (`Encoded::start_cdfs`): |
| 49 | // an inter frame whose header leaves `disable_frame_end_update_cdf` off |
| 50 | // starts from what the previous frame stored, not from the defaults. Same |
| 51 | // class as `tx_select` above, third instance. |
| 52 | initial_cdfs: Option<Cdfs>, |
| 53 | // lane-av1obmc: this frame header's own `is_motion_mode_switchable` |
| 54 | // (spec 5.9.2). Hard-coding `false` here desynced every stream this |
| 55 | // crate's own encoder writes once inter blocks started carrying a |
| 56 | // `motion_mode` symbol (class: test asserts against a stale header). |
| 57 | switchable_motion_mode: bool, |
| 58 | fctx: &crate::decode::FrameCtx, |
| 59 | ) -> Result<Picture> { |
| 60 | decode_inter_frame_tile_lr( |
| 61 | data, |
| 62 | mi_cols, |
| 63 | mi_rows, |
| 64 | base_q_idx, |
| 65 | frame_width, |
| 66 | frame_height, |
| 67 | refpix, |
| 68 | cdef, |
| 69 | loop_filter, |
| 70 | allow_high_precision_mv, |
| 71 | force_integer_mv, |
| 72 | interp_fixed, |
| 73 | enable_dual_filter, |
| 74 | reference_select, |
| 75 | reduced_tx_set, |
| 76 | tx_select, |
| 77 | &LoopRestorationParams::default(), |
| 78 | initial_cdfs, |
| 79 | NO_SIGN_BIAS, |
| 80 | false, |
| 81 | // `enable_filter_intra`: as the `false`s beside it, this convenience |
| 82 | // entry names a stream written without the sequence bit (lane-fintra). |
| 83 | switchable_motion_mode, |
| 84 | false, |
| 85 | false, |
| 86 | DeltaParams::default(), |
| 87 | fctx, |
| 88 | ) |
| 89 | } |
| 90 | |
| 91 | /// [`decode_inter_frame_tile`] with this frame header's own `lr_params`, the |
| 92 | /// inter sibling of [`decode_key_frame_tile_lr`]. |
| 93 | #[allow(clippy::too_many_arguments)] |
| 94 | pub(crate) fn decode_inter_frame_tile_lr( |
| 95 | data: &[u8], |
| 96 | mi_cols: u32, |
| 97 | mi_rows: u32, |
| 98 | base_q_idx: u8, |
| 99 | frame_width: u32, |
| 100 | frame_height: u32, |
| 101 | refpix: &RefPix<'_>, |
| 102 | cdef: &CdefParams, |
| 103 | loop_filter: &LoopFilterParams, |
| 104 | allow_high_precision_mv: bool, |
| 105 | force_integer_mv: bool, |
| 106 | interp_fixed: Option<mc::InterpFilterKind>, |
| 107 | enable_dual_filter: bool, |
| 108 | reference_select: bool, |
| 109 | // lane-intertx: this frame header's own `reduced_tx_set` (spec 5.9.2). |
| 110 | // The wrapper used to hard-code `true` ("the tests all code the reduced |
| 111 | // sets") -- true until the widened inter search put 1-D/DTT types on |
| 112 | // `reduced_tx_set = 0` frames' inter luma, whose CHROMA then inherits |
| 113 | // the type against this very bit |
| 114 | // ([`reduce_inherited_chroma_tx_type`]): guessing `true` mis-derives |
| 115 | // every inherited chroma type and desyncs the tile (class: test asserts |
| 116 | // against a stale header, next instance). |
| 117 | reduced_tx_set: bool, |
| 118 | tx_select: bool, |
| 119 | lr: &LoopRestorationParams, |
| 120 | initial_cdfs: Option<Cdfs>, |
| 121 | // spec 5.9.2's `ref_frame_sign_bias`, derived by a real decoder from the |
| 122 | // order hints its DPB slots hold. A raw tile decode cannot derive it (it |
| 123 | // is handed planes, not slots), and hard-coding `NO_SIGN_BIAS` here |
| 124 | // desyncs the encoder's own filter-search re-decode of any frame with a |
| 125 | // BACKWARD reference -- a pyramid leaf reading its group's hidden |
| 126 | // `ALTREF_FRAME` -- since the writer's MV-stack scans flip borrowed |
| 127 | // candidates across the bias boundary and this one's did not. Same class |
| 128 | // as `tx_select`/`initial_cdfs` above: a header-derived value a raw tile |
| 129 | // decode has to be told. |
| 130 | sign_bias: crate::mvstack::SignBiasTable, |
| 131 | // This frame header's own `allow_screen_content_tools`: its intra blocks |
| 132 | // then carry the palette syntax (spec 5.11.46), which a raw tile decode |
| 133 | // that guessed `false` reads one symbol short of. Placed after |
| 134 | // `sign_bias` rather than beside the other bools on purpose (the |
| 135 | // `adjacent-same-typed-args` class). |
| 136 | allow_screen_content_tools: bool, |
| 137 | // lane-av1obmc: this frame header's own `is_motion_mode_switchable` |
| 138 | // (spec 5.9.2). Hard-coding `false` here desynced every stream this |
| 139 | // crate's own encoder writes once inter blocks started carrying a |
| 140 | // `motion_mode` symbol (class: test asserts against a stale header). |
| 141 | switchable_motion_mode: bool, |
| 142 | // lane-av1obmc2: this frame header's own `allow_warped_motion` (spec |
| 143 | // 5.9.2) -- what picks the 3-symbol `motion_mode_cdf` alphabet over the |
| 144 | // 2-symbol `obmc_cdf` one at a block with a warp sample. Hard-coding |
| 145 | // `false` here desynced every stream this crate's encoder writes with the |
| 146 | // warp knob on: the same stale-header class as the parameter above. |
| 147 | allow_warped_motion: bool, |
| 148 | // lane-fintra: see [`decode_inter_frame_tiles_lr`]'s own parameter. |
| 149 | enable_filter_intra: bool, |
| 150 | // lane-deltaq: see [`decode_inter_frame_tiles_lr`]'s own parameter. |
| 151 | delta: DeltaParams, |
| 152 | fctx: &crate::decode::FrameCtx, |
| 153 | ) -> Result<Picture> { |
| 154 | let single_tile = TileInfo { |
| 155 | mi_col_starts: vec![0, mi_cols], |
| 156 | mi_row_starts: vec![0, mi_rows], |
| 157 | ..TileInfo::default() |
| 158 | }; |
| 159 | decode_inter_frame_tiles_lr( |
| 160 | &[data], |
| 161 | &single_tile, |
| 162 | mi_cols, |
| 163 | mi_rows, |
| 164 | base_q_idx, |
| 165 | frame_width, |
| 166 | frame_height, |
| 167 | refpix, |
| 168 | cdef, |
| 169 | loop_filter, |
| 170 | allow_high_precision_mv, |
| 171 | force_integer_mv, |
| 172 | interp_fixed, |
| 173 | enable_dual_filter, |
| 174 | reference_select, |
| 175 | // lane-intertx: this frame's own bit, not the hardcoded `true` -- |
| 176 | // see the parameter's note above. |
| 177 | reduced_tx_set, |
| 178 | tx_select, |
| 179 | lr, |
| 180 | initial_cdfs, |
| 181 | sign_bias, |
| 182 | allow_screen_content_tools, |
| 183 | switchable_motion_mode, |
| 184 | allow_warped_motion, |
| 185 | enable_filter_intra, |
| 186 | delta, |
| 187 | fctx, |
| 188 | ) |
| 189 | } |
| 190 | |
| 191 | /// [`decode_inter_frame_tile_lr`] for a frame coded as SEVERAL tiles; see |
| 192 | /// [`decode_key_frame_tiles_lr`]. |
| 193 | #[allow(clippy::too_many_arguments)] |
| 194 | pub(crate) fn decode_inter_frame_tiles_lr( |
| 195 | tiles: &[&[u8]], |
| 196 | tile_info: &TileInfo, |
| 197 | mi_cols: u32, |
| 198 | mi_rows: u32, |
| 199 | base_q_idx: u8, |
| 200 | frame_width: u32, |
| 201 | frame_height: u32, |
| 202 | refpix: &RefPix<'_>, |
| 203 | cdef: &CdefParams, |
| 204 | loop_filter: &LoopFilterParams, |
| 205 | allow_high_precision_mv: bool, |
| 206 | force_integer_mv: bool, |
| 207 | interp_fixed: Option<mc::InterpFilterKind>, |
| 208 | enable_dual_filter: bool, |
| 209 | reference_select: bool, |
| 210 | // lane-txi: this frame header's own `reduced_tx_set` bit. It used to be |
| 211 | // hardcoded `true` at the call below -- the encoder's own trial decode of |
| 212 | // the tile it just wrote then read every luma `tx_type` out of the |
| 213 | // reduced alphabet whatever the header said (class: a header bit a raw |
| 214 | // tile decode cannot guess, the same one `tx_select` carries). |
| 215 | reduced_tx_set: bool, |
| 216 | tx_select: bool, |
| 217 | lr: &LoopRestorationParams, |
| 218 | initial_cdfs: Option<Cdfs>, |
| 219 | sign_bias: crate::mvstack::SignBiasTable, |
| 220 | // This frame header's own `allow_screen_content_tools` (see the |
| 221 | // single-tile wrapper): the palette syntax its intra blocks carry. |
| 222 | allow_screen_content_tools: bool, |
| 223 | // lane-av1obmc: this frame header's own `is_motion_mode_switchable` |
| 224 | // (spec 5.9.2). Hard-coding `false` here desynced every stream this |
| 225 | // crate's own encoder writes once inter blocks started carrying a |
| 226 | // `motion_mode` symbol (class: test asserts against a stale header). |
| 227 | switchable_motion_mode: bool, |
| 228 | // lane-av1obmc2: this frame header's own `allow_warped_motion` (spec |
| 229 | // 5.9.2) -- what picks the 3-symbol `motion_mode_cdf` alphabet over the |
| 230 | // 2-symbol `obmc_cdf` one at a block with a warp sample. Hard-coding |
| 231 | // `false` here desynced every stream this crate's encoder writes with the |
| 232 | // warp knob on: the same stale-header class as the parameter above. |
| 233 | allow_warped_motion: bool, |
| 234 | // lane-fintra: this sequence header's own `enable_filter_intra` bit (spec |
| 235 | // 5.5.2). Hard-coded `false` here until this lane -- the same stale-header |
| 236 | // class as `switchable_motion_mode`/`allow_warped_motion` above: the |
| 237 | // encoder's own trial decode desyncs at the first intra-in-inter DC_PRED |
| 238 | // block the moment its sequence header sets the bit. |
| 239 | enable_filter_intra: bool, |
| 240 | // lane-deltaq: this frame header's own `delta_q_params`/`delta_lf_params` |
| 241 | // (spec 5.9.17/5.9.18) -- the same stale-header class as the three |
| 242 | // parameters above. Hard-coded `DeltaParams::default()` here until this |
| 243 | // lane, which desyncs the encoder's own trial decode at the first |
| 244 | // superblock the moment its header sets `delta_q_present`. |
| 245 | delta: DeltaParams, |
| 246 | fctx: &crate::decode::FrameCtx, |
| 247 | ) -> Result<Picture> { |
| 248 | decode_inter_frame_tile_with_cdfs( |
| 249 | tiles, |
| 250 | tile_info, |
| 251 | mi_cols, |
| 252 | mi_rows, |
| 253 | base_q_idx, |
| 254 | crate::quant::QuantDeltas::default(), |
| 255 | frame_width, |
| 256 | frame_height, |
| 257 | refpix, |
| 258 | cdef, |
| 259 | loop_filter, |
| 260 | lr, |
| 261 | initial_cdfs, |
| 262 | allow_high_precision_mv, |
| 263 | force_integer_mv, |
| 264 | sign_bias, |
| 265 | [ec_av1_syntax::WarpParams::default(); 7], |
| 266 | interp_fixed, |
| 267 | enable_dual_filter, |
| 268 | 0, |
| 269 | 0, |
| 270 | [0; 7], |
| 271 | None, |
| 272 | reference_select, |
| 273 | false, |
| 274 | false, |
| 275 | false, |
| 276 | false, |
| 277 | [0; 2], |
| 278 | reduced_tx_set, |
| 279 | tx_select, |
| 280 | switchable_motion_mode, |
| 281 | allow_warped_motion, |
| 282 | allow_screen_content_tools, |
| 283 | delta, |
| 284 | enable_filter_intra, |
| 285 | None, |
| 286 | fctx, |
| 287 | ) |
| 288 | .map(|(picture, _, _)| picture) |
| 289 | } |
| 290 | |
| 291 | /// [`decode_inter_frame_tile`], threading a cross-frame CDF forward -- see |
| 292 | /// [`decode_key_frame_tile_with_cdfs`]'s doc for `initial_cdfs`/the returned |
| 293 | /// end-of-tile table. An inter frame's own header can name |
| 294 | /// `primary_ref_frame == PRIMARY_REF_NONE` too (an error-resilient stream), |
| 295 | /// so `None` is a real case here, not only a convenience default. |
| 296 | // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. |
| 297 | #[allow(clippy::too_many_arguments)] |
| 298 | pub(crate) fn decode_inter_frame_tile_with_cdfs( |
| 299 | tiles: &[&[u8]], |
| 300 | tile_info: &TileInfo, |
| 301 | mi_cols: u32, |
| 302 | mi_rows: u32, |
| 303 | base_q_idx: u8, |
| 304 | // lane-sbpart r11: see [`decode_key_frame_tile_with_cdfs`]'s own `deltas`. |
| 305 | deltas: crate::quant::QuantDeltas, |
| 306 | frame_width: u32, |
| 307 | frame_height: u32, |
| 308 | refpix: &RefPix<'_>, |
| 309 | cdef: &CdefParams, |
| 310 | loop_filter: &LoopFilterParams, |
| 311 | lr: &LoopRestorationParams, |
| 312 | initial_cdfs: Option<Cdfs>, |
| 313 | allow_high_precision_mv: bool, |
| 314 | force_integer_mv: bool, |
| 315 | sign_bias_table: SignBiasTable, |
| 316 | // lane-gm r2: this frame header's own `global_motion` table (spec |
| 317 | // 5.9.24), threaded to every `decode_inter_block` call below. |
| 318 | global_motion: [ec_av1_syntax::WarpParams; 7], |
| 319 | interp_fixed: Option<mc::InterpFilterKind>, |
| 320 | enable_dual_filter: bool, |
| 321 | // lane-av1tmvp: `order_hint`/`order_hint_bits`/`ref_order_hints` are |
| 322 | // always needed (this frame's own saved [`crate::motion_field::MotionField`] |
| 323 | // carries them for a *later* frame's projection, spec 7.9); `tpl_field` |
| 324 | // is `Some` only when this frame's own header set `use_ref_frame_mvs` |
| 325 | // and the caller ([`crate::stream::decode_stream`]) projected one. |
| 326 | order_hint_bits: u32, |
| 327 | order_hint: u32, |
| 328 | ref_order_hints: [u32; 7], |
| 329 | tpl_field: Option<&crate::motion_field::TplField>, |
| 330 | // lane-av1comp: this frame header's own `reference_select` bit, threaded |
| 331 | // to every `decode_inter_block`/`decode_inter_block8` call below. |
| 332 | reference_select: bool, |
| 333 | // lane-av1comp: `seq_params`' own compound-blend enable bits. |
| 334 | enable_masked_compound: bool, |
| 335 | enable_jnt_comp: bool, |
| 336 | // lane-sb128 r3: this sequence header's own `enable_interintra_compound` |
| 337 | // bit, threaded to every `decode_inter_block`/`decode_inter_block8` call |
| 338 | // below (spec 5.11.24's `interintra` read). |
| 339 | enable_interintra_compound: bool, |
| 340 | // lane-av1comp round 14: this frame header's own `skip_mode_present`/ |
| 341 | // `skip_mode_frame` (spec 5.9.22), threaded to every `decode_inter_block`/ |
| 342 | // `decode_inter_block8` call below. |
| 343 | skip_mode_present: bool, |
| 344 | skip_mode_frame: [u8; 2], |
| 345 | // lane-cdffwd2: this frame header's own `reduced_tx_set` bit, threaded to |
| 346 | // every inter `tx_type` read below (`false` needs the 12-/16-symbol |
| 347 | // `Set1` coefficient tables at 16x16/8x8 rather than the reduced |
| 348 | // 2-symbol ones -- see [`TxbSet::Luma16InterSet1`]/[`TxbSet::Luma8InterSet1`]). |
| 349 | reduced_tx_set: bool, |
| 350 | // lane-txselect: this frame header's own `tx_mode == TxMode::Select` |
| 351 | // bit (spec 5.9.14). Together with `reduced_tx_set` it is stashed in a |
| 352 | // thread-local by [`set_inter_tx_mode`] rather than threaded through |
| 353 | // `decode_inter_block`'s forty parameters -- both are frame-constant, and |
| 354 | // only [`read_block_tx_size`]/the var-tx residual loop read them. |
| 355 | tx_select: bool, |
| 356 | // lane-motionmode round 1/3: this frame header's own `is_motion_mode_switchable`/ |
| 357 | // `allow_warped_motion` bits, threaded to every `decode_inter_block`/ |
| 358 | // `decode_inter_block8` call below (spec 5.11.24's `read_motion_mode`). |
| 359 | switchable_motion_mode: bool, |
| 360 | allow_warped_motion: bool, |
| 361 | // lane-screen r2: this frame header's own `allow_screen_content_tools` |
| 362 | // bit, threaded to every `decode_inter_block`/`decode_inter_block8` |
| 363 | // call below -- consumes (never reconstructs) the intra-sub-block |
| 364 | // palette syntax libaom's `read_intra_block_mode_info` reads under the |
| 365 | // same `av1_allow_palette` gate as the key-frame path. |
| 366 | allow_screen_content_tools: bool, |
| 367 | // lane-realworld r5: this frame header's own `delta` (spec 5.9.17/5.9.18), |
| 368 | // same contract as [`decode_key_frame_tile_with_cdfs`]'s own `delta` |
| 369 | // param -- only `q_present`/`q_res` are read. |
| 370 | delta: DeltaParams, |
| 371 | // lane-fiinter r1: this sequence header's own `enable_filter_intra` bit |
| 372 | // (spec 5.5.2), stashed in a thread-local with `tx_select` rather than |
| 373 | // threaded through `decode_inter_block`'s fifty parameters -- read by the |
| 374 | // intra-in-inter arms' `read_filter_intra_mode_info`. |
| 375 | enable_filter_intra: bool, |
| 376 | // lane-twostage: called with this frame's own end-of-tile CDFs, motion |
| 377 | // field and picture size the moment its last tile symbol is read -- |
| 378 | // BEFORE its filters run, so a frame that references this one can start |
| 379 | // parsing while this one is still being deblocked/CDEF'd/restored (it |
| 380 | // waits for the pixels themselves at its first prediction). `None`, and |
| 381 | // the motion field comes back in the return tuple as it always did: |
| 382 | // the single-threaded path, and a superres frame (whose final width is |
| 383 | // only known after the upscale). |
| 384 | stage1: Option<&dyn Fn(Cdfs, crate::motion_field::MotionField, usize, usize)>, |
| 385 | fctx: &crate::decode::FrameCtx, |
| 386 | ) -> Result<(Picture, Cdfs, Option<crate::motion_field::MotionField>)> { |
| 387 | set_inter_tx_mode(tx_select, reduced_tx_set, enable_filter_intra, fctx); |
| 388 | let tpl_frame = tpl_field.map(|field| TplFrameArgs { |
| 389 | field, |
| 390 | order_hint_bits, |
| 391 | order_hint, |
| 392 | ref_order_hints, |
| 393 | }); |
| 394 | if mi_cols == 0 || mi_rows == 0 { |
| 395 | return Err(unsupported("a frame with no mode-info grid")); |
| 396 | } |
| 397 | let (true_width, true_height) = ((mi_cols * 4) as usize, (mi_rows * 4) as usize); |
| 398 | // spec 7.11.3.3: a reference may differ in size from this frame on either |
| 399 | // axis (a scaled reference, `mc::RefScale`), within the conformance |
| 400 | // limits: at most 2x down and 16x up. Outside them is a named refusal. |
| 401 | for rf in 1..=7i8 { |
| 402 | if let Some((rw, rh)) = refpix.dims(rf) |
| 403 | && mc::RefScale::out_of_limits(rw, rh, frame_width as usize, frame_height as usize) |
| 404 | { |
| 405 | return Err(unsupported( |
| 406 | "a reference picture outside the 2x down / 16x up scaling limits", |
| 407 | )); |
| 408 | } |
| 409 | } |
| 410 | let (cols, rows) = block_grid(mi_cols, mi_rows); |
| 411 | let sb128 = sb128(fctx); |
| 412 | let (sb_cols, sb_rows) = (cols.div_ceil(2), rows.div_ceil(2)); |
| 413 | fctx.cdef_bits.with(|c| c.set(cdef.bits)); |
| 414 | fctx.cdef_sb_cols.with(|c| c.set(sb_cols as usize)); |
| 415 | fctx.cdef_idx_grid |
| 416 | .with(|g| *g.borrow_mut() = vec![0u8; sb_cols as usize * sb_rows as usize]); |
| 417 | let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK); |
| 418 | |
| 419 | let mut y = PlaneBuf { |
| 420 | data: std::borrow::Cow::Owned(fresh_plane( |
| 421 | width * height, |
| 422 | true_width, |
| 423 | true_height, |
| 424 | width, |
| 425 | height, |
| 426 | )), |
| 427 | width, |
| 428 | height, |
| 429 | true_width, |
| 430 | true_height, |
| 431 | tile_x0: 0, |
| 432 | tile_y0: 0, |
| 433 | tile_x1: width, |
| 434 | tile_y1: height, |
| 435 | plane: 0, |
| 436 | }; |
| 437 | let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx)); |
| 438 | note_frame_chroma_alloc((width, height), (cw, ch), (ss_x(fctx), ss_y(fctx))); |
| 439 | let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx)); |
| 440 | let mut u = PlaneBuf { |
| 441 | data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)), |
| 442 | width: cw, |
| 443 | height: ch, |
| 444 | true_width: ctw, |
| 445 | true_height: cth, |
| 446 | tile_x0: 0, |
| 447 | tile_y0: 0, |
| 448 | tile_x1: cw, |
| 449 | tile_y1: ch, |
| 450 | plane: 1, |
| 451 | }; |
| 452 | let mut v = PlaneBuf { |
| 453 | data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)), |
| 454 | width: cw, |
| 455 | height: ch, |
| 456 | true_width: ctw, |
| 457 | true_height: cth, |
| 458 | tile_x0: 0, |
| 459 | tile_y0: 0, |
| 460 | tile_x1: cw, |
| 461 | tile_y1: ch, |
| 462 | plane: 2, |
| 463 | }; |
| 464 | |
| 465 | let scan32 = default_scan(TX32); |
| 466 | let scan16 = default_scan(TX16); |
| 467 | let scan8 = default_scan(TX8); |
| 468 | let scan4 = default_scan(TX4); |
| 469 | |
| 470 | let base_cdfs = initial_cdfs.unwrap_or_else(|| Cdfs::new(q_ctx_of(base_q_idx))); |
| 471 | let mut result_cdfs = base_cdfs.clone(); |
| 472 | // spec `decode_tile`: `CurrentQIndex`/`DeltaLF` reset to the frame's own |
| 473 | // `base_q_idx`/zero at the top of every tile, not once per frame (mirrors |
| 474 | // `decode_key_frame_tile_with_cdfs`'s per-tile reset below); the |
| 475 | // delta_q/delta_lf presence/resolution flags themselves are frame-level |
| 476 | // and set once here. |
| 477 | fctx.delta_q_present.with(|c| c.set(delta.q_present)); |
| 478 | fctx.delta_q_res.with(|c| c.set(1i32 << delta.q_res)); |
| 479 | fctx.delta_lf_present.with(|c| c.set(delta.lf_present)); |
| 480 | fctx.delta_lf_res.with(|c| c.set(1i32 << delta.lf_res)); |
| 481 | fctx.delta_lf_multi.with(|c| c.set(delta.lf_multi)); |
| 482 | let mut neighbours = Neighbours::new( |
| 483 | cols as usize * 2, |
| 484 | rows as usize * 2, |
| 485 | mi_cols as usize, |
| 486 | mi_rows as usize, |
| 487 | fctx, |
| 488 | ); |
| 489 | let mut grid = MiGrid::new(mi_cols as usize, mi_rows as usize); |
| 490 | // spec 7.16/libaom `av1_alloc_restoration_struct`: the unit grid is |
| 491 | // sized from `av1_get_upsampled_plane_size`, i.e. the UPSCALED width -- |
| 492 | // loop restoration runs after the superres upscale. |
| 493 | let mut lr_grid = crate::restoration::RestorationGrid::with_ss( |
| 494 | lr, |
| 495 | superres(fctx).map_or(frame_width, |(w, _)| w), |
| 496 | frame_height, |
| 497 | fctx.subsampling_x.get(), |
| 498 | fctx.subsampling_y.get(), |
| 499 | ); |
| 500 | |
| 501 | let lr_active = (0..3).any(|p| { |
| 502 | lr.frame_restoration_type[p] != ec_av1_syntax::RestorationType::None |
| 503 | && lr.loop_restoration_size[p] != 0 |
| 504 | }); |
| 505 | |
| 506 | // lane-tiles r6: mirrors decode_key_frame_tile_with_cdfs's own per-tile |
| 507 | // loop (spec 5.11.2 decode_tile / 7.20 exit_symbol) -- each tile gets |
| 508 | // its own fresh SymbolDecoder over its own byte range and its own fresh |
| 509 | // copy of the frame's initial CDFs; only context_update_tile_id's own |
| 510 | // end-of-tile adapted table becomes the frame's own output. |
| 511 | for (tile_idx, &data) in tiles.iter().enumerate() { |
| 512 | let tile_num = tile_idx as u32; |
| 513 | let (trow, tcol) = (tile_num / tile_info.cols, tile_num % tile_info.cols); |
| 514 | let mi_row0 = tile_info.mi_row_starts[trow as usize]; |
| 515 | let mi_row1 = tile_info.mi_row_starts[trow as usize + 1]; |
| 516 | let mi_col0 = tile_info.mi_col_starts[tcol as usize]; |
| 517 | let mi_col1 = tile_info.mi_col_starts[tcol as usize + 1]; |
| 518 | let (sb_r0, sb_r1) = ( |
| 519 | (mi_row0 / SB_MI).min(sb_rows), |
| 520 | mi_row1.div_ceil(SB_MI).min(sb_rows), |
| 521 | ); |
| 522 | let (sb_c0, sb_c1) = ( |
| 523 | (mi_col0 / SB_MI).min(sb_cols), |
| 524 | mi_col1.div_ceil(SB_MI).min(sb_cols), |
| 525 | ); |
| 526 | // lane-t900 r19: spec 5.11.2 `decode_tile` resets `RefLrWiener` / |
| 527 | // `RefSgrXqd` to the midpoint filter at the top of EVERY tile, not |
| 528 | // once per frame. Carried across a tile boundary, the loop-restoration |
| 529 | // coefficients of the next tile decode off the previous tile's |
| 530 | // reference -- same symbol count, so entropy and reconstruction stay |
| 531 | // exact and only the filtered pixels of every tile after the first |
| 532 | // are wrong. |
| 533 | let mut lr_reference = [( |
| 534 | crate::restoration::WienerInfo::default(), |
| 535 | crate::restoration::SgrprojInfo::default(), |
| 536 | ); 3]; |
| 537 | let mut cdfs = base_cdfs.clone(); |
| 538 | fctx.current_q_idx.with(|c| c.set(i32::from(base_q_idx))); |
| 539 | fctx.quant_deltas.with(|c| c.set(deltas)); |
| 540 | fctx.current_delta_lf.with(|c| c.set([0; 4])); |
| 541 | let mut dec = SymbolDecoder::new(data); |
| 542 | // lane-av1txr: spec 5.9.2's `disable_cdf_update` -- a frame that sets |
| 543 | // it codes every symbol against the tables it started with. |
| 544 | dec.set_cdf_update(!cdf_update_disabled(fctx)); |
| 545 | crate::census::register_cdfs(&cdfs); |
| 546 | // lane-comppin r9: tile-entry range, the earliest point comparable |
| 547 | // against aomdec's own `r->ec.rng` right after `aom_reader_init` -- the |
| 548 | // first ladder rung before any symbol (partition or otherwise) is read. |
| 549 | if crate::envflags::env_flag!("EC_AV1_TELL") { |
| 550 | eprintln!( |
| 551 | "TELL label=tile_init tell={} range={}", |
| 552 | dec.debug_bitpos(), |
| 553 | dec.debug_state().0 |
| 554 | ); |
| 555 | } |
| 556 | neighbours.start_tile(mi_row0 as usize, mi_col0 as usize, mi_col1 as usize, fctx); |
| 557 | y.set_tile_origin( |
| 558 | mi_col0 as usize * 4, |
| 559 | mi_row0 as usize * 4, |
| 560 | (mi_col1 as usize * 4).min(y.width), |
| 561 | (mi_row1 as usize * 4).min(y.height), |
| 562 | ); |
| 563 | u.set_tile_origin( |
| 564 | (mi_col0 as usize * 4) >> ss_x(fctx), |
| 565 | (mi_row0 as usize * 4) >> ss_y(fctx), |
| 566 | ((mi_col1 as usize * 4) >> ss_x(fctx)).min(u.width), |
| 567 | ((mi_row1 as usize * 4) >> ss_y(fctx)).min(u.height), |
| 568 | ); |
| 569 | v.set_tile_origin( |
| 570 | (mi_col0 as usize * 4) >> ss_x(fctx), |
| 571 | (mi_row0 as usize * 4) >> ss_y(fctx), |
| 572 | ((mi_col1 as usize * 4) >> ss_x(fctx)).min(v.width), |
| 573 | ((mi_row1 as usize * 4) >> ss_y(fctx)).min(v.height), |
| 574 | ); |
| 575 | // lane-tiles r6: an MV candidate scan (mvstack.rs's grid.get) must |
| 576 | // not reach across a tile boundary any more than intra prediction's |
| 577 | // PlaneBuf reach does -- bounding the shared grid's own read window |
| 578 | // per tile is equivalent to threading tile bounds through every |
| 579 | // find_mv_stack* call site (all four read through this one grid). |
| 580 | grid.set_tile_bounds( |
| 581 | mi_row0 as usize, |
| 582 | mi_col0 as usize, |
| 583 | mi_row1 as usize, |
| 584 | mi_col1 as usize, |
| 585 | ); |
| 586 | hit!(TILE_HITS); |
| 587 | |
| 588 | // lane-sb128 r2: at `sb_size == 128` the tile walks each 128x128 |
| 589 | // superblock's four 64x64 quadrants in libaom `decode_partition` order |
| 590 | // (TL, TR, BL, BR) and reads the 128 root's own loop-restoration units and |
| 591 | // partition symbol once per superblock -- exactly what the key-frame tile |
| 592 | // loop does; the 64-level body below is unchanged, `read_cdef`'s |
| 593 | // per-64x64-quadrant reset (`CDEF_TRANSMITTED`) already matches libaom's |
| 594 | // `cdef_idx[(mi_row & 16) >> 4 * 2 + (mi_col & 16) >> 4]` slot per quadrant. |
| 595 | // lane-sb128c r1: set when the 128 root resolved to `PARTITION_NONE` -- its |
| 596 | // one 128x128 inter block covers all four 64x64 quadrants, so the remaining |
| 597 | // three items of this superblock carry no syntax at all (same skip the |
| 598 | // key-frame tile loop runs). |
| 599 | let mut sb128_none = false; |
| 600 | // Superblock-row wavefront: one job per superblock (per 128x128 when |
| 601 | // `sb128`, since a 128 block writes across its four 64x64 visits). |
| 602 | // Intrabc frames read the frame being reconstructed, so they stay inline. |
| 603 | let wave_shift = u32::from(sb128); |
| 604 | let (wave_r0, wave_c0) = ( |
| 605 | (sb_r0 >> wave_shift) as usize, |
| 606 | (sb_c0 >> wave_shift) as usize, |
| 607 | ); |
| 608 | let (wave_rows, wave_cols) = if sb_r1 > sb_r0 && sb_c1 > sb_c0 { |
| 609 | ( |
| 610 | ((sb_r1 - 1) >> wave_shift) as usize - wave_r0 + 1, |
| 611 | ((sb_c1 - 1) >> wave_shift) as usize - wave_c0 + 1, |
| 612 | ) |
| 613 | } else { |
| 614 | (0, 0) |
| 615 | }; |
| 616 | // Ends any wavefront this tile leaves running on an error return. |
| 617 | let _wave_tile = wave::TileScope; |
| 618 | if !allow_intrabc_frame(fctx) { |
| 619 | wave::install( |
| 620 | fctx, |
| 621 | refpix, |
| 622 | [&y, &u, &v], |
| 623 | 64 << wave_shift, |
| 624 | (wave_r0, wave_rows, wave_c0, wave_cols), |
| 625 | ); |
| 626 | } |
| 627 | for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) { |
| 628 | // The previous superblock's queued writes go to its worker now. |
| 629 | if sb_start { |
| 630 | wave::begin_sb( |
| 631 | (sb_r >> wave_shift) as usize - wave_r0, |
| 632 | (sb_c >> wave_shift) as usize - wave_c0, |
| 633 | ); |
| 634 | } |
| 635 | if row_start { |
| 636 | neighbours.start_row(); |
| 637 | } |
| 638 | if sb_start { |
| 639 | sb128_none = false; |
| 640 | } |
| 641 | if sb128_none { |
| 642 | continue; |
| 643 | } |
| 644 | { |
| 645 | let mut sb128_rect = None; |
| 646 | let mut sb128_ab = None; |
| 647 | if sb128 && sb_start { |
| 648 | let part128 = read_sb128_root( |
| 649 | &mut dec, |
| 650 | &mut cdfs, |
| 651 | &neighbours, |
| 652 | lr, |
| 653 | &mut lr_grid, |
| 654 | &mut lr_reference, |
| 655 | sb_r, |
| 656 | sb_c, |
| 657 | mi_cols, |
| 658 | mi_rows, |
| 659 | fctx, |
| 660 | )?; |
| 661 | if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part128) { |
| 662 | // lane-sb128c r9: an AB shape at the 128 root -- one |
| 663 | // 128x64/64x128 half plus two 64x64 quadrants, same visit |
| 664 | // order as the key-frame path. |
| 665 | sb128_none = true; |
| 666 | sb128_ab = Some(part128); |
| 667 | } |
| 668 | if matches!(part128, PARTITION_HORZ | PARTITION_VERT) { |
| 669 | // Two 128x64 (HORZ) or two 64x128 (VERT) inter blocks; the |
| 670 | // whole 128x128 root is consumed here, so the remaining |
| 671 | // three 64-quadrant visits of this superblock carry no |
| 672 | // syntax (same skip the NONE arm runs). |
| 673 | sb128_none = true; |
| 674 | sb128_rect = Some(part128); |
| 675 | fctx.cdef_transmitted.with(|c| c.set(false)); |
| 676 | } |
| 677 | if part128 == PARTITION_NONE { |
| 678 | // One 128x128 inter block. Its luma transform is |
| 679 | // `max_txsize_rect_lookup[BLOCK_128X128]` = TX_64X64 (four |
| 680 | // units, read as var-tx leaves), its uv plane block is |
| 681 | // 64x64 with TX_32X32 units (`av1_get_max_uv_txsize`), and |
| 682 | // `size_group_lookup[BLOCK_128X128]` is 3, same as 64x64. |
| 683 | sb128_none = true; |
| 684 | fctx.cdef_transmitted.with(|c| c.set(false)); |
| 685 | } |
| 686 | } |
| 687 | if !sb128 { |
| 688 | crate::restoration::read_lr( |
| 689 | &mut dec, |
| 690 | &mut cdfs, |
| 691 | lr, |
| 692 | &mut lr_grid, |
| 693 | &mut lr_reference, |
| 694 | // True mode-info units: a 64px superblock is 8, and `SB_MI` is 16. |
| 695 | // `read_lr` divides by the restoration-unit size (a real pixel count), |
| 696 | // so it is the one consumer that needs the absolute origin in real mi. |
| 697 | // The half-mi convention these arguments used to carry only worked |
| 698 | // while `read_lr` also counted in half-mi -- the two cancelled. |
| 699 | sb_r * (SB_MI / 2), |
| 700 | sb_c * (SB_MI / 2), |
| 701 | SB_MI / 2, |
| 702 | fctx, |
| 703 | ); |
| 704 | } |
| 705 | fctx.cdef_transmitted.with(|c| c.set(false)); |
| 706 | let sb_at = (sb_r as usize * 4, sb_c as usize * 4); |
| 707 | // lane-inter4 r1: every rect inter piece below is the same |
| 708 | // `decode_inter_block` call with only position / true footprint / |
| 709 | // transform-set differing; the macro keeps the new arms readable |
| 710 | // instead of six more 60-line copies of the argument list. |
| 711 | macro_rules! inter_piece { |
| 712 | ($at_mi:expr, $side:expr, $li:expr, $lt:expr, $ch:expr, $ltx:expr, |
| 713 | $ctx:expr, $sl:expr, $sc:expr, $sg:expr, $ww:expr, $wh:expr) => { |
| 714 | decode_inter_block( |
| 715 | &mut dec, |
| 716 | &mut cdfs, |
| 717 | &mut neighbours, |
| 718 | &mut grid, |
| 719 | $at_mi, |
| 720 | $side, |
| 721 | mi_cols, |
| 722 | mi_rows, |
| 723 | &mut y, |
| 724 | &mut u, |
| 725 | &mut v, |
| 726 | refpix, |
| 727 | &sign_bias_table, |
| 728 | &global_motion, |
| 729 | base_q_idx, |
| 730 | $li, |
| 731 | $lt, |
| 732 | $ch, |
| 733 | $ltx, |
| 734 | $ctx, |
| 735 | $sl, |
| 736 | $sc, |
| 737 | $sg, |
| 738 | allow_high_precision_mv, |
| 739 | force_integer_mv, |
| 740 | interp_fixed, |
| 741 | enable_dual_filter, |
| 742 | tpl_frame.as_ref(), |
| 743 | reference_select, |
| 744 | enable_masked_compound, |
| 745 | enable_interintra_compound, |
| 746 | enable_jnt_comp, |
| 747 | order_hint_bits, |
| 748 | order_hint, |
| 749 | ref_order_hints, |
| 750 | skip_mode_present, |
| 751 | skip_mode_frame, |
| 752 | switchable_motion_mode, |
| 753 | allow_warped_motion, |
| 754 | // lane-sb128c r3: `reject_residual` is about a |
| 755 | // RECTANGULAR strip decoded with square dimensions -- |
| 756 | // the 128x128 NONE root is square, and a hardcoded |
| 757 | // `true` refused every one of them at its first |
| 758 | // non-skip block. |
| 759 | $ww != $side || $wh != $side, |
| 760 | $ww, |
| 761 | $wh, |
| 762 | allow_screen_content_tools, |
| 763 | (frame_width as usize, frame_height as usize), |
| 764 | fctx, |
| 765 | )? |
| 766 | }; |
| 767 | } |
| 768 | // lane-inter16ab r1: one 8x8 inter leaf of a 16x16-level AB |
| 769 | // partition (libaom `decode_partition` PARTITION_HORZ_A/_B/ |
| 770 | // VERT_A/_B at BLOCK_16X16 code `bsize2` = BLOCK_8X8 for two of |
| 771 | // their three pieces, decodeframe.c ~1900). Same body the |
| 772 | // PARTITION_SPLIT arm runs per leaf, minus its own partition |
| 773 | // symbol (an AB piece carries none) and its `prev_leaves` |
| 774 | // bookkeeping. |
| 775 | macro_rules! inter_leaf8 { |
| 776 | ($outer:expr, $leaf:expr) => {{ |
| 777 | let leaf_mi = $leaf; |
| 778 | let ( |
| 779 | skip, |
| 780 | is_inter, |
| 781 | skip_mode_leaf, |
| 782 | compound_ctx8, |
| 783 | leaf_filter, |
| 784 | leaf_refs, |
| 785 | ) = decode_inter_block8( |
| 786 | &mut dec, |
| 787 | &mut cdfs, |
| 788 | &mut neighbours, |
| 789 | &mut grid, |
| 790 | mi_cols, |
| 791 | mi_rows, |
| 792 | $outer, |
| 793 | leaf_mi, |
| 794 | &mut y, |
| 795 | &mut u, |
| 796 | &mut v, |
| 797 | refpix, |
| 798 | base_q_idx, |
| 799 | &scan8, |
| 800 | &scan4, |
| 801 | allow_high_precision_mv, |
| 802 | force_integer_mv, |
| 803 | &global_motion, |
| 804 | enable_dual_filter, |
| 805 | reference_select, |
| 806 | enable_masked_compound, |
| 807 | enable_interintra_compound, |
| 808 | enable_jnt_comp, |
| 809 | order_hint_bits, |
| 810 | order_hint, |
| 811 | ref_order_hints, |
| 812 | skip_mode_present, |
| 813 | skip_mode_frame, |
| 814 | reduced_tx_set, |
| 815 | interp_fixed, |
| 816 | switchable_motion_mode, |
| 817 | allow_warped_motion, |
| 818 | allow_screen_content_tools, |
| 819 | &sign_bias_table, |
| 820 | tpl_frame.as_ref(), |
| 821 | (frame_width as usize, frame_height as usize), fctx, |
| 822 | )?; |
| 823 | neighbours.record_inter_rect_mi( |
| 824 | leaf_mi, |
| 825 | 2, |
| 826 | 2, |
| 827 | skip, |
| 828 | is_inter, |
| 829 | leaf_refs.0, |
| 830 | leaf_filter, |
| 831 | skip_mode_leaf, |
| 832 | ); |
| 833 | if let Some(ref1) = leaf_refs.1 |
| 834 | && let Some((_, _, group_idx, idx)) = compound_ctx8 |
| 835 | { |
| 836 | neighbours.record_compound_ctx_rect_mi( |
| 837 | leaf_mi, 2, 2, ref1, group_idx, idx, |
| 838 | ); |
| 839 | } |
| 840 | }}; |
| 841 | } |
| 842 | if let Some(part128) = sb128_ab { |
| 843 | // libaom `decode_partition` (decodeframe.c): HORZ_A = TL, TR, |
| 844 | // bottom half; HORZ_B = top half, BL, BR; VERT_A = TL, BL, |
| 845 | // right half; VERT_B = left half, TR, BR. AB only comes from |
| 846 | // the full alphabet symbol (both halves in frame), so there is |
| 847 | // no `i > 0` edge break to mirror. |
| 848 | let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); |
| 849 | let base_mi = sub16_to_mi(at128); |
| 850 | let (br_mi, bc_mi) = (base_mi.0 + 16, base_mi.1 + 16); |
| 851 | let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); |
| 852 | let _vert_ab = (part128 == PARTITION_VERT_A || part128 == PARTITION_VERT_B) |
| 853 | .then(crate::encode::Reach::vert_ab_partition); |
| 854 | let cdef_copy = |src: (usize, usize), dst: (usize, usize)| { |
| 855 | fctx.cdef_idx_grid.with(|g| { |
| 856 | let mut g = g.borrow_mut(); |
| 857 | let cols = fctx.cdef_sb_cols.with(|c| c.get()); |
| 858 | if cols == 0 { |
| 859 | return; |
| 860 | } |
| 861 | let (si, di) = ( |
| 862 | (q_r + src.0) * cols + q_c + src.1, |
| 863 | (q_r + dst.0) * cols + q_c + dst.1, |
| 864 | ); |
| 865 | if q_c + src.1 < cols |
| 866 | && q_c + dst.1 < cols |
| 867 | && si < g.len() |
| 868 | && di < g.len() |
| 869 | { |
| 870 | g[di] = g[si]; |
| 871 | } |
| 872 | }); |
| 873 | }; |
| 874 | macro_rules! square64_inter { |
| 875 | ($at_mi:expr) => {{ |
| 876 | fctx.cdef_transmitted.with(|c| c.set(false)); |
| 877 | inter_piece!( |
| 878 | $at_mi, |
| 879 | SB, |
| 880 | TxbSet::Luma64, |
| 881 | TxbSet::Luma64, |
| 882 | TxbSet::Chroma32, |
| 883 | TX32, |
| 884 | TX32, |
| 885 | &scan32, |
| 886 | &scan32, |
| 887 | 3, |
| 888 | SB, |
| 889 | SB |
| 890 | ); |
| 891 | }}; |
| 892 | } |
| 893 | macro_rules! half128_inter { |
| 894 | ($at_mi:expr, $bw:expr, $bh:expr, $src:expr, $dst:expr) => {{ |
| 895 | fctx.cdef_transmitted.with(|c| c.set(false)); |
| 896 | inter_piece!( |
| 897 | $at_mi, |
| 898 | SB * 2, |
| 899 | TxbSet::Luma64, |
| 900 | TxbSet::Luma64, |
| 901 | TxbSet::Chroma32, |
| 902 | TX32, |
| 903 | TX32, |
| 904 | &scan32, |
| 905 | &scan32, |
| 906 | 3, |
| 907 | $bw, |
| 908 | $bh |
| 909 | ); |
| 910 | cdef_copy($src, $dst); |
| 911 | }}; |
| 912 | } |
| 913 | // lane-av1unwritten r5: the partition symbol is RESOLVED (a full CDF read or |
| 914 | // an edge `gather`) and about to be dispatched. `partition_subsize_dims` is |
| 915 | // libaom's `get_partition_subsize` (common_data.h:71-90) reduced to |
| 916 | // dimensions, so this is `decode_partition`'s pre-descend check |
| 917 | // (decodeframe.c:1449-1458) applied to EVERY arm at once -- VERT, |
| 918 | // VERT_A / VERT_B, HORZ_4 and VERT_4 included. The HORZ siblings keep |
| 919 | // decoding because the helper is exact, not a heuristic. (inter-frame duplicate) |
| 920 | refuse_invalid_subsize((128, 128), part128, fctx)?; |
| 921 | match part128 { |
| 922 | PARTITION_HORZ_A => { |
| 923 | square64_inter!(base_mi); |
| 924 | square64_inter!((base_mi.0, bc_mi)); |
| 925 | half128_inter!((br_mi, base_mi.1), 128, 64, (1, 0), (1, 1)); |
| 926 | } |
| 927 | PARTITION_HORZ_B => { |
| 928 | half128_inter!(base_mi, 128, 64, (0, 0), (0, 1)); |
| 929 | square64_inter!((br_mi, base_mi.1)); |
| 930 | square64_inter!((br_mi, bc_mi)); |
| 931 | } |
| 932 | PARTITION_VERT_A => { |
| 933 | square64_inter!(base_mi); |
| 934 | square64_inter!((br_mi, base_mi.1)); |
| 935 | half128_inter!((base_mi.0, bc_mi), 64, 128, (0, 1), (1, 1)); |
| 936 | } |
| 937 | _ => { |
| 938 | half128_inter!(base_mi, 64, 128, (0, 0), (1, 0)); |
| 939 | square64_inter!((base_mi.0, bc_mi)); |
| 940 | square64_inter!((br_mi, bc_mi)); |
| 941 | } |
| 942 | } |
| 943 | continue; |
| 944 | } |
| 945 | if let Some(part128) = sb128_rect { |
| 946 | // lane-sb128c r7: libaom `decode_partition` (decodeframe.c:1554) |
| 947 | // codes PARTITION_HORZ at the 128 root as `subsize = |
| 948 | // BLOCK_128X64` at (mi_row, mi_col) and a second one at |
| 949 | // (mi_row + hbs, mi_col) only `if (mi_row + hbs < mi_rows)`; |
| 950 | // PARTITION_VERT mirrors it on the column. `hbs` here is |
| 951 | // `mi_size_high[BLOCK_128X128] / 2` = 16 mi. |
| 952 | let horz = part128 == PARTITION_HORZ; |
| 953 | let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); |
| 954 | let base_mi = sub16_to_mi(at128); |
| 955 | let (bw, bh) = if horz { (128usize, 64usize) } else { (64, 128) }; |
| 956 | for i in 0..2 { |
| 957 | let at_mi = if horz { |
| 958 | (base_mi.0 + i * 16, base_mi.1) |
| 959 | } else { |
| 960 | (base_mi.0, base_mi.1 + i * 16) |
| 961 | }; |
| 962 | if i > 0 && (at_mi.0 >= mi_rows as usize || at_mi.1 >= mi_cols as usize) { |
| 963 | break; |
| 964 | } |
| 965 | // Each half reads its OWN `cdef_idx` literal: libaom keeps |
| 966 | // `cdef_transmitted[4]`, one flag per 64x64 CDEF unit of a |
| 967 | // 128x128 superblock (`read_cdef`, decodemv.c:50-81), and |
| 968 | // the two halves of a 128-root HORZ/VERT sit in different |
| 969 | // units (index `col_in_sb != 0` + 2 * `row_in_sb != 0`). |
| 970 | // The key-frame 128 loop already resets here; without it |
| 971 | // the second half skipped a `cdef_bits`-wide literal that |
| 972 | // libaom reads, desyncing the tile at that block. |
| 973 | fctx.cdef_transmitted.with(|c| c.set(false)); |
| 974 | inter_piece!( |
| 975 | at_mi, |
| 976 | SB * 2, |
| 977 | TxbSet::Luma64, |
| 978 | TxbSet::Luma64, |
| 979 | TxbSet::Chroma32, |
| 980 | TX32, |
| 981 | TX32, |
| 982 | &scan32, |
| 983 | &scan32, |
| 984 | 3, |
| 985 | bw, |
| 986 | bh |
| 987 | ); |
| 988 | if horz { |
| 989 | hit!(INTER_SB128_HORZ_HITS); |
| 990 | } else { |
| 991 | hit!(INTER_SB128_VERT_HITS); |
| 992 | } |
| 993 | } |
| 994 | // One `cdef_idx` per BLOCK, copied to every 64x64 CDEF unit it |
| 995 | // covers -- both halves of the root read their own, and the |
| 996 | // first one's read lands in the top-left unit while the |
| 997 | // second's lands in the bottom-left (HORZ) / top-right (VERT). |
| 998 | let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); |
| 999 | fctx.cdef_idx_grid.with(|g| { |
| 1000 | let mut g = g.borrow_mut(); |
| 1001 | let cols = fctx.cdef_sb_cols.with(|c| c.get()); |
| 1002 | if cols == 0 { |
| 1003 | return; |
| 1004 | } |
| 1005 | for (src, dst) in if horz { |
| 1006 | [((0, 0), (0, 1)), ((1, 0), (1, 1))] |
| 1007 | } else { |
| 1008 | [((0, 0), (1, 0)), ((0, 1), (1, 1))] |
| 1009 | } { |
| 1010 | let (si, di) = ( |
| 1011 | (q_r + src.0) * cols + q_c + src.1, |
| 1012 | (q_r + dst.0) * cols + q_c + dst.1, |
| 1013 | ); |
| 1014 | if q_c + src.1 < cols |
| 1015 | && q_c + dst.1 < cols |
| 1016 | && si < g.len() |
| 1017 | && di < g.len() |
| 1018 | { |
| 1019 | g[di] = g[si]; |
| 1020 | } |
| 1021 | } |
| 1022 | }); |
| 1023 | continue; |
| 1024 | } |
| 1025 | if sb128_none { |
| 1026 | hit!(INTER_SB128_NONE_HITS); |
| 1027 | let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); |
| 1028 | // lane-sb128c r3: `at128` is in SUB16 units like `sb_at`; |
| 1029 | // `decode_inter_block` takes MI. Unconverted it was (0,0) for |
| 1030 | // the first 128 root and a quarter-position for every other |
| 1031 | // one -- the whole-frame gate never got past superblock 1. |
| 1032 | inter_piece!( |
| 1033 | sub16_to_mi(at128), |
| 1034 | SB * 2, |
| 1035 | TxbSet::Luma64, |
| 1036 | TxbSet::Luma64, |
| 1037 | TxbSet::Chroma32, |
| 1038 | TX32, |
| 1039 | TX32, |
| 1040 | &scan32, |
| 1041 | &scan32, |
| 1042 | 3, |
| 1043 | SB * 2, |
| 1044 | SB * 2 |
| 1045 | ); |
| 1046 | // libaom writes one `cdef_strength` into the block's own |
| 1047 | // `MB_MODE_INFO`, which all four 64x64 CDEF units point at |
| 1048 | // (mirrors the key-frame 128 NONE block). |
| 1049 | let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); |
| 1050 | fctx.cdef_idx_grid.with(|g| { |
| 1051 | let mut g = g.borrow_mut(); |
| 1052 | let cols = fctx.cdef_sb_cols.with(|c| c.get()); |
| 1053 | if cols > 0 && q_r * cols + q_c < g.len() { |
| 1054 | let idx = g[q_r * cols + q_c]; |
| 1055 | for (dr, dc) in [(0, 1), (1, 0), (1, 1)] { |
| 1056 | let i = (q_r + dr) * cols + q_c + dc; |
| 1057 | if q_c + dc < cols && i < g.len() { |
| 1058 | g[i] = idx; |
| 1059 | } |
| 1060 | } |
| 1061 | } |
| 1062 | }); |
| 1063 | continue; |
| 1064 | } |
| 1065 | let sb_ctx = neighbours.partition_ctx(sb_at, SB); |
| 1066 | let (has_cols, has_rows) = ( |
| 1067 | sb_c * SB_MI + SB_MI / 2 < mi_cols, |
| 1068 | sb_r * SB_MI + SB_MI / 2 < mi_rows, |
| 1069 | ); |
| 1070 | // The straddle cases (one or both halves outside the true |
| 1071 | // frame) never carry a real alphabet symbol -- spec forces |
| 1072 | // SPLIT there (mirrors the intra key-frame tile's own |
| 1073 | // three-way write above). Only the (true, true) case can name |
| 1074 | // a non-SPLIT value, and this loop below only ever recurses as |
| 1075 | // SPLIT -- so a real non-SPLIT part64 here must refuse by name |
| 1076 | // instead of silently decoding as SPLIT and desyncing. |
| 1077 | let part64 = match (has_cols, has_rows) { |
| 1078 | (true, true) => { |
| 1079 | let pre_rng = dec.debug_state().0; |
| 1080 | if crate::envflags::env_flag!("EC_TRACE_PART") { |
| 1081 | eprintln!( |
| 1082 | "EC_PART mi_row={} mi_col={} bsize=12 ctx={} rng={}", |
| 1083 | sb_r as usize * SB_MI as usize, |
| 1084 | sb_c as usize * SB_MI as usize, |
| 1085 | sb_ctx, |
| 1086 | dec.debug_state().0 |
| 1087 | ); |
| 1088 | } |
| 1089 | let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); |
| 1090 | // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be |
| 1091 | // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize` |
| 1092 | // (common_data.h:71-90) reduced to dimensions, so this is |
| 1093 | // `decode_partition`'s pre-descend check (decodeframe.c:1451-1460) on EVERY |
| 1094 | // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings |
| 1095 | // keep decoding because the helper is exact, not a heuristic. inter-frame 64x64 level; `p` is the symbol. |
| 1096 | |
| 1097 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| 1098 | eprintln!( |
| 1099 | "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}", |
| 1100 | sb_r * SB_MI, |
| 1101 | sb_c * SB_MI |
| 1102 | ); |
| 1103 | } |
| 1104 | p |
| 1105 | } |
| 1106 | (true, false) => { |
| 1107 | // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 1108 | // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT |
| 1109 | // (libaom `ec_read_partition_impl`). |
| 1110 | if crate::envflags::env_flag!("EC_TRACE_PART") { |
| 1111 | eprintln!( |
| 1112 | "EC_PARTG mi_row={} mi_col={} bsize=12 ctx={} rng={}", |
| 1113 | sb_r as usize * SB_MI as usize, |
| 1114 | sb_c as usize * SB_MI as usize, |
| 1115 | sb_ctx, |
| 1116 | dec.debug_state().0 |
| 1117 | ); |
| 1118 | } |
| 1119 | if bump_edge32_bit( |
| 1120 | 4, |
| 1121 | dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)), |
| 1122 | ) == 1 |
| 1123 | { |
| 1124 | PARTITION_SPLIT |
| 1125 | } else { |
| 1126 | PARTITION_HORZ |
| 1127 | } |
| 1128 | } |
| 1129 | (false, true) => { |
| 1130 | // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 1131 | // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT |
| 1132 | // (libaom `ec_read_partition_impl`). |
| 1133 | if bump_edge32_bit( |
| 1134 | 4, |
| 1135 | dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)), |
| 1136 | ) == 1 |
| 1137 | { |
| 1138 | PARTITION_SPLIT |
| 1139 | } else { |
| 1140 | PARTITION_VERT |
| 1141 | } |
| 1142 | } |
| 1143 | (false, false) => { |
| 1144 | bump_edge_both_cut(2); |
| 1145 | PARTITION_SPLIT |
| 1146 | } |
| 1147 | }; |
| 1148 | // lane-av1unwritten r7: the symbol is RESOLVED (a full CDF |
| 1149 | // read or an edge `gather`) and about to be dispatched, so the |
| 1150 | // check sits HERE rather than inside the (true, true) arm: the |
| 1151 | // edge arms return without passing it, and (false, true) |
| 1152 | // resolves to PARTITION_VERT, which on a 64x64 root selects |
| 1153 | // BLOCK_32X64 -- INVALID at (1,0) and unreachable from the |
| 1154 | // corpus (measured: 50 reaches corpus-wide, 0 in any 4:2:2 cell). |
| 1155 | // r6 had this inside the (true, true) arm, where it could not |
| 1156 | // see it. |
| 1157 | refuse_invalid_subsize((64, 64), part64, fctx)?; |
| 1158 | if part64 == PARTITION_NONE { |
| 1159 | // lane-inter8 r1: the whole superblock as one 64x64 inter |
| 1160 | // block. `SB`-sized syntax throughout (size_group 3, same as |
| 1161 | // 32x32 -- `size_group_lookup[BLOCK_64X64] == 3`), luma |
| 1162 | // coefficients through `TxbSet::Luma64` with the 32-point |
| 1163 | // scan (TX_64X64 codes only its top-left corner, spec |
| 1164 | // 5.11.40 -- `read_inter_plane` widens the corner back to |
| 1165 | // 64x64 before the inverse transform), chroma as a plain |
| 1166 | // 32x32 `TxbSet::Chroma32`. TX_64X64 carries no `tx_type` |
| 1167 | // symbol at all, so the intra/inter luma sets coincide. |
| 1168 | hit!(INTER_SB_NONE_HITS); |
| 1169 | decode_inter_block( |
| 1170 | &mut dec, |
| 1171 | &mut cdfs, |
| 1172 | &mut neighbours, |
| 1173 | &mut grid, |
| 1174 | sub16_to_mi(sb_at), |
| 1175 | SB, |
| 1176 | mi_cols, |
| 1177 | mi_rows, |
| 1178 | &mut y, |
| 1179 | &mut u, |
| 1180 | &mut v, |
| 1181 | refpix, |
| 1182 | &sign_bias_table, |
| 1183 | &global_motion, |
| 1184 | base_q_idx, |
| 1185 | TxbSet::Luma64, |
| 1186 | TxbSet::Luma64, |
| 1187 | TxbSet::Chroma32, |
| 1188 | TX32, |
| 1189 | TX32, |
| 1190 | scan32, |
| 1191 | scan32, |
| 1192 | 3, |
| 1193 | allow_high_precision_mv, |
| 1194 | force_integer_mv, |
| 1195 | interp_fixed, |
| 1196 | enable_dual_filter, |
| 1197 | tpl_frame.as_ref(), |
| 1198 | reference_select, |
| 1199 | enable_masked_compound, |
| 1200 | enable_interintra_compound, |
| 1201 | enable_jnt_comp, |
| 1202 | order_hint_bits, |
| 1203 | order_hint, |
| 1204 | ref_order_hints, |
| 1205 | skip_mode_present, |
| 1206 | skip_mode_frame, |
| 1207 | switchable_motion_mode, |
| 1208 | allow_warped_motion, |
| 1209 | false, |
| 1210 | SB, |
| 1211 | SB, |
| 1212 | allow_screen_content_tools, |
| 1213 | (frame_width as usize, frame_height as usize), |
| 1214 | fctx, |
| 1215 | )?; |
| 1216 | continue; |
| 1217 | } |
| 1218 | if matches!( |
| 1219 | part64, |
| 1220 | PARTITION_HORZ | PARTITION_VERT | PARTITION_HORZ_4 | PARTITION_VERT_4 |
| 1221 | ) { |
| 1222 | // lane-av1unwritten r6: arm census. |
| 1223 | note_subsize_arm( |
| 1224 | part64, |
| 1225 | chroma_plane_block_codable( |
| 1226 | partition_subsize_dims((64, 64), part64).0, |
| 1227 | partition_subsize_dims((64, 64), part64).1, |
| 1228 | ss_x(fctx), |
| 1229 | ss_y(fctx), |
| 1230 | ), |
| 1231 | ); |
| 1232 | // lane-inter4 r1: the superblock-level rect + 1:4 pairs as |
| 1233 | // inter blocks -- two 64x32 / 32x64 strips, or four 64x16 / |
| 1234 | // 16x64 ones. Each piece keeps `side = SB` for every |
| 1235 | // syntax/CDF/prediction-buffer decision (the square-context |
| 1236 | // corner-cut PARTITION_HORZ already ships at the 32 level) |
| 1237 | // but names its own true footprint through `write_w`/ |
| 1238 | // `write_h`, which is what `motion_mode`'s bsize row, the |
| 1239 | // mv-stack's bw4/bh4, the delta-q `bSize == sbSize` test and |
| 1240 | // every neighbour stamp read. `reject_residual = true`: a |
| 1241 | // non-skip strip refuses by name rather than over-read a |
| 1242 | // square residual (rectangular inter residual coding is not |
| 1243 | // ported -- see lanes/inter4-r1.report.md). |
| 1244 | let horz = matches!(part64, PARTITION_HORZ | PARTITION_HORZ_4); |
| 1245 | let four = matches!(part64, PARTITION_HORZ_4 | PARTITION_VERT_4); |
| 1246 | let base_mi = ( |
| 1247 | sb_r as usize * SB_MI as usize, |
| 1248 | sb_c as usize * SB_MI as usize, |
| 1249 | ); |
| 1250 | let (n_pieces, step_mi) = if four { |
| 1251 | (4usize, 4usize) |
| 1252 | } else { |
| 1253 | (2usize, 8usize) |
| 1254 | }; |
| 1255 | let (bw, bh) = match (horz, four) { |
| 1256 | (true, false) => (64usize, 32usize), |
| 1257 | (false, false) => (32, 64), |
| 1258 | (true, true) => (64, 16), |
| 1259 | (false, true) => (16, 64), |
| 1260 | }; |
| 1261 | for i in 0..n_pieces { |
| 1262 | let at_mi = if horz { |
| 1263 | (base_mi.0 + i * step_mi, base_mi.1) |
| 1264 | } else { |
| 1265 | (base_mi.0, base_mi.1 + i * step_mi) |
| 1266 | }; |
| 1267 | // libaom `decode_partition`'s own `i > 0` frame-edge break. |
| 1268 | if i > 0 && (at_mi.0 >= mi_rows as usize || at_mi.1 >= mi_cols as usize) { |
| 1269 | break; |
| 1270 | } |
| 1271 | inter_piece!( |
| 1272 | at_mi, |
| 1273 | SB, |
| 1274 | TxbSet::Luma64, |
| 1275 | TxbSet::Luma64, |
| 1276 | TxbSet::Chroma32, |
| 1277 | TX32, |
| 1278 | TX32, |
| 1279 | &scan32, |
| 1280 | &scan32, |
| 1281 | 3, |
| 1282 | bw, |
| 1283 | bh |
| 1284 | ); |
| 1285 | if !four && i == 0 && ((horz && !has_rows) || (!horz && !has_cols)) { |
| 1286 | bump_inter_edge_strip(if horz { 0 } else { 1 }); |
| 1287 | } |
| 1288 | match (horz, four) { |
| 1289 | (true, false) => hit!(INTER_SB_HORZ_HITS), |
| 1290 | (false, false) => hit!(INTER_SB_VERT_HITS), |
| 1291 | (true, true) => hit!(INTER_SB_HORZ4_HITS), |
| 1292 | (false, true) => hit!(INTER_SB_VERT4_HITS), |
| 1293 | } |
| 1294 | } |
| 1295 | continue; |
| 1296 | } |
| 1297 | if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part64) { |
| 1298 | // lane-sbab r1: the four superblock-level AB arms on the |
| 1299 | // INTER path -- two 32x32 inter squares plus one true |
| 1300 | // 64x32/32x64 inter strip, in libaom `decode_partition`'s own |
| 1301 | // order (decodeframe.c: HORZ_A = TL, TR, bottom strip; |
| 1302 | // HORZ_B = top strip, BL, BR; VERT_A = TL, BL, right strip; |
| 1303 | // VERT_B = left strip, TR, BR). Every piece is one this |
| 1304 | // decoder already proves elsewhere: the 32x32 square is the |
| 1305 | // `PARTITION_NONE`-under-SPLIT block below, the strip is the |
| 1306 | // `PARTITION_HORZ`/`VERT` piece above (`inter_piece!`, which |
| 1307 | // keeps `side = SB` for syntax/CDF and names its true |
| 1308 | // footprint through `write_w`/`write_h`). The intra-frame |
| 1309 | // twin of this arm is lane-part32 r4's `SB_AB_HITS` block. |
| 1310 | hit_do! { |
| 1311 | SB_AB_INTER_HITS.with(|c| { |
| 1312 | let mut h = c.get(); |
| 1313 | h[part64 - PARTITION_HORZ_A] += 1; |
| 1314 | c.set(h); |
| 1315 | }); |
| 1316 | } |
| 1317 | // lane-part32 r5 / class visit-order-changes-availability: |
| 1318 | // only the two VERTICAL arms visit TL, BL, TR, BR, so only |
| 1319 | // they switch libaom's `has_tr`/`has_bl` tables. |
| 1320 | let _vert_guard = (part64 == PARTITION_VERT_A || part64 == PARTITION_VERT_B) |
| 1321 | .then(crate::encode::Reach::vert_ab_partition); |
| 1322 | let (mi_row0, mi_col0) = ( |
| 1323 | sb_r as usize * SB_MI as usize, |
| 1324 | sb_c as usize * SB_MI as usize, |
| 1325 | ); |
| 1326 | // 32 px = 8 MI units. |
| 1327 | let tl = (mi_row0, mi_col0); |
| 1328 | let tr = (mi_row0, mi_col0 + 8); |
| 1329 | let bl = (mi_row0 + 8, mi_col0); |
| 1330 | let br = (mi_row0 + 8, mi_col0 + 8); |
| 1331 | macro_rules! ab_strip64 { |
| 1332 | ($mi:expr, $ww:expr, $wh:expr) => { |
| 1333 | inter_piece!( |
| 1334 | $mi, |
| 1335 | SB, |
| 1336 | TxbSet::Luma64, |
| 1337 | TxbSet::Luma64, |
| 1338 | TxbSet::Chroma32, |
| 1339 | TX32, |
| 1340 | TX32, |
| 1341 | &scan32, |
| 1342 | &scan32, |
| 1343 | 3, |
| 1344 | $ww, |
| 1345 | $wh |
| 1346 | ) |
| 1347 | }; |
| 1348 | } |
| 1349 | // The 32x32 squares carry a full square residual, so unlike |
| 1350 | // `inter_piece!` (which hardcodes `reject_residual = true` |
| 1351 | // for its strips) they pass `false`. |
| 1352 | macro_rules! ab_square32 { |
| 1353 | ($mi:expr) => { |
| 1354 | decode_inter_block( |
| 1355 | &mut dec, |
| 1356 | &mut cdfs, |
| 1357 | &mut neighbours, |
| 1358 | &mut grid, |
| 1359 | $mi, |
| 1360 | BLOCK, |
| 1361 | mi_cols, |
| 1362 | mi_rows, |
| 1363 | &mut y, |
| 1364 | &mut u, |
| 1365 | &mut v, |
| 1366 | refpix, |
| 1367 | &sign_bias_table, |
| 1368 | &global_motion, |
| 1369 | base_q_idx, |
| 1370 | TxbSet::Luma32, |
| 1371 | TxbSet::Luma32Inter, |
| 1372 | TxbSet::Chroma16, |
| 1373 | TX32, |
| 1374 | TX16, |
| 1375 | &scan32, |
| 1376 | &scan16, |
| 1377 | 3, |
| 1378 | allow_high_precision_mv, |
| 1379 | force_integer_mv, |
| 1380 | interp_fixed, |
| 1381 | enable_dual_filter, |
| 1382 | tpl_frame.as_ref(), |
| 1383 | reference_select, |
| 1384 | enable_masked_compound, |
| 1385 | enable_interintra_compound, |
| 1386 | enable_jnt_comp, |
| 1387 | order_hint_bits, |
| 1388 | order_hint, |
| 1389 | ref_order_hints, |
| 1390 | skip_mode_present, |
| 1391 | skip_mode_frame, |
| 1392 | switchable_motion_mode, |
| 1393 | allow_warped_motion, |
| 1394 | false, |
| 1395 | BLOCK, |
| 1396 | BLOCK, |
| 1397 | allow_screen_content_tools, |
| 1398 | (frame_width as usize, frame_height as usize), |
| 1399 | fctx, |
| 1400 | )? |
| 1401 | }; |
| 1402 | } |
| 1403 | match part64 { |
| 1404 | PARTITION_HORZ_A => { |
| 1405 | ab_square32!(tl); |
| 1406 | ab_square32!(tr); |
| 1407 | ab_strip64!(bl, 64, 32); |
| 1408 | } |
| 1409 | PARTITION_HORZ_B => { |
| 1410 | ab_strip64!(tl, 64, 32); |
| 1411 | ab_square32!(bl); |
| 1412 | ab_square32!(br); |
| 1413 | } |
| 1414 | PARTITION_VERT_A => { |
| 1415 | ab_square32!(tl); |
| 1416 | ab_square32!(bl); |
| 1417 | ab_strip64!(tr, 32, 64); |
| 1418 | } |
| 1419 | _ => { |
| 1420 | ab_strip64!(tl, 32, 64); |
| 1421 | ab_square32!(tr); |
| 1422 | ab_square32!(br); |
| 1423 | } |
| 1424 | } |
| 1425 | continue; |
| 1426 | } |
| 1427 | // Every value of the 10-symbol `partition_w64` alphabet is now |
| 1428 | // handled above except SPLIT, which falls through to the quadrant |
| 1429 | // loop below (lane-sbab r1 took the AB four; the rect/1:4 arms |
| 1430 | // and NONE `continue` earlier). |
| 1431 | debug_assert_eq!(part64, PARTITION_SPLIT); |
| 1432 | |
| 1433 | for quadrant in 0..4 { |
| 1434 | let (r32, c32) = (sb_r * 2 + quadrant / 2, sb_c * 2 + quadrant % 2); |
| 1435 | if r32 >= rows || c32 >= cols { |
| 1436 | continue; |
| 1437 | } |
| 1438 | let at = (r32 as usize * 2, c32 as usize * 2); |
| 1439 | let ctx32 = neighbours.partition_ctx(at, BLOCK); |
| 1440 | let (has_cols32, has_rows32) = ( |
| 1441 | has_half(c32 * BLOCK_MI, BLOCK_MI, mi_cols), |
| 1442 | has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), |
| 1443 | ); |
| 1444 | let part32 = if has_cols32 && has_rows32 { |
| 1445 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| 1446 | eprintln!( |
| 1447 | "TRACE part32_pre mi=({},{}) rng={}", |
| 1448 | r32 * BLOCK_MI, |
| 1449 | c32 * BLOCK_MI, |
| 1450 | dec.debug_state().0 |
| 1451 | ); |
| 1452 | } |
| 1453 | // lane-av1tilerows: this rung printed the RAW 32-grid |
| 1454 | // index (`r32`, `c32`) into its `mi_row=`/`mi_col=` |
| 1455 | // fields — a factor of `BLOCK_MI` (8) off — while the |
| 1456 | // `TRACE part32_pre` line immediately above and the |
| 1457 | // `EC_AV1_TRACE` line immediately below both print |
| 1458 | // `r32 * BLOCK_MI` correctly. A rung whose coordinates |
| 1459 | // are wrong is worse than no rung: it cannot be paired |
| 1460 | // against libaom's per-level `EC_PART_VAL` dump, which |
| 1461 | // is the only way to locate a partition-walk |
| 1462 | // divergence. Behaviour-free: env-gated print only. |
| 1463 | if crate::envflags::env_flag!("EC_TRACE_PART") { |
| 1464 | eprintln!( |
| 1465 | "EC_PART mi_row={} mi_col={} bsize=9 ctx={} rng={}", |
| 1466 | r32 * BLOCK_MI, |
| 1467 | c32 * BLOCK_MI, |
| 1468 | ctx32, |
| 1469 | dec.debug_state().0 |
| 1470 | ); |
| 1471 | } |
| 1472 | let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); |
| 1473 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| 1474 | eprintln!( |
| 1475 | "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p}", |
| 1476 | r32 * BLOCK_MI, |
| 1477 | c32 * BLOCK_MI |
| 1478 | ); |
| 1479 | } |
| 1480 | p |
| 1481 | } else { |
| 1482 | match (has_cols32, has_rows32) { |
| 1483 | (true, false) => { |
| 1484 | // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 1485 | // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT |
| 1486 | // (libaom `ec_read_partition_impl`). |
| 1487 | if crate::envflags::env_flag!("EC_TRACE_PART") { |
| 1488 | eprintln!( |
| 1489 | "EC_PARTG mi_row={} mi_col={} bsize=9 ctx={} rng={}", |
| 1490 | r32 as usize * BLOCK_MI as usize, |
| 1491 | c32 as usize * BLOCK_MI as usize, |
| 1492 | ctx32, |
| 1493 | dec.debug_state().0 |
| 1494 | ); |
| 1495 | } |
| 1496 | if { |
| 1497 | let b = dec.symbol_fixed(&gather( |
| 1498 | &cdfs.partition_w32[ctx32], |
| 1499 | VERT_ALIKE, |
| 1500 | )); |
| 1501 | bump_edge32(b.min(1)); |
| 1502 | b |
| 1503 | } == 1 |
| 1504 | { |
| 1505 | PARTITION_SPLIT |
| 1506 | } else { |
| 1507 | PARTITION_HORZ |
| 1508 | } |
| 1509 | } |
| 1510 | (false, true) => { |
| 1511 | // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 1512 | // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT |
| 1513 | // (libaom `ec_read_partition_impl`). |
| 1514 | if { |
| 1515 | let b = dec.symbol_fixed(&gather( |
| 1516 | &cdfs.partition_w32[ctx32], |
| 1517 | HORZ_ALIKE, |
| 1518 | )); |
| 1519 | bump_edge32(b.min(1)); |
| 1520 | b |
| 1521 | } == 1 |
| 1522 | { |
| 1523 | PARTITION_SPLIT |
| 1524 | } else { |
| 1525 | PARTITION_VERT |
| 1526 | } |
| 1527 | } |
| 1528 | _ => { |
| 1529 | bump_edge_both_cut(1); |
| 1530 | PARTITION_SPLIT |
| 1531 | } |
| 1532 | } |
| 1533 | }; |
| 1534 | // lane-av1unwritten r5: the partition symbol is RESOLVED (a full CDF read or |
| 1535 | // an edge `gather`) and about to be dispatched. `partition_subsize_dims` is |
| 1536 | // libaom's `get_partition_subsize` (common_data.h:71-90) reduced to |
| 1537 | // dimensions, so this is `decode_partition`'s pre-descend check |
| 1538 | // (decodeframe.c:1449-1458) applied to EVERY arm at once -- VERT, |
| 1539 | // VERT_A / VERT_B, HORZ_4 and VERT_4 included. The HORZ siblings keep |
| 1540 | // decoding because the helper is exact, not a heuristic. (inter-frame duplicate) |
| 1541 | refuse_invalid_subsize((32, 32), part32, fctx)?; |
| 1542 | match part32 { |
| 1543 | PARTITION_NONE => { |
| 1544 | decode_inter_block( |
| 1545 | &mut dec, |
| 1546 | &mut cdfs, |
| 1547 | &mut neighbours, |
| 1548 | &mut grid, |
| 1549 | sub16_to_mi(at), |
| 1550 | BLOCK, |
| 1551 | mi_cols, |
| 1552 | mi_rows, |
| 1553 | &mut y, |
| 1554 | &mut u, |
| 1555 | &mut v, |
| 1556 | refpix, |
| 1557 | &sign_bias_table, |
| 1558 | &global_motion, |
| 1559 | base_q_idx, |
| 1560 | TxbSet::Luma32, |
| 1561 | TxbSet::Luma32Inter, |
| 1562 | TxbSet::Chroma16, |
| 1563 | TX32, |
| 1564 | TX16, |
| 1565 | scan32, |
| 1566 | scan16, |
| 1567 | 3, |
| 1568 | allow_high_precision_mv, |
| 1569 | force_integer_mv, |
| 1570 | interp_fixed, |
| 1571 | enable_dual_filter, |
| 1572 | tpl_frame.as_ref(), |
| 1573 | reference_select, |
| 1574 | enable_masked_compound, |
| 1575 | enable_interintra_compound, |
| 1576 | enable_jnt_comp, |
| 1577 | order_hint_bits, |
| 1578 | order_hint, |
| 1579 | ref_order_hints, |
| 1580 | skip_mode_present, |
| 1581 | skip_mode_frame, |
| 1582 | switchable_motion_mode, |
| 1583 | allow_warped_motion, |
| 1584 | false, |
| 1585 | BLOCK, |
| 1586 | BLOCK, |
| 1587 | allow_screen_content_tools, |
| 1588 | (frame_width as usize, frame_height as usize), |
| 1589 | fctx, |
| 1590 | )?; |
| 1591 | } |
| 1592 | PARTITION_SPLIT => { |
| 1593 | for sub in 0..4 { |
| 1594 | let (sr, sc) = |
| 1595 | (r32 as usize * 2 + sub / 2, c32 as usize * 2 + sub % 2); |
| 1596 | if (sr as u32) * SUB_MI >= mi_rows |
| 1597 | || (sc as u32) * SUB_MI >= mi_cols |
| 1598 | { |
| 1599 | continue; |
| 1600 | } |
| 1601 | let (has_cols16, has_rows16) = ( |
| 1602 | has_half(sc as u32 * SUB_MI, SUB_MI, mi_cols), |
| 1603 | has_half(sr as u32 * SUB_MI, SUB_MI, mi_rows), |
| 1604 | ); |
| 1605 | let at16 = (sr, sc); |
| 1606 | let ctx16 = neighbours.partition_ctx(at16, SUB); |
| 1607 | // lane-inter8 r1: a straddling 16x16 cannot name a |
| 1608 | // value (spec forces SPLIT, one gathered bit); an |
| 1609 | // interior one reads the real alphabet, and |
| 1610 | // `PARTITION_SPLIT` now recurses into four 8x8 |
| 1611 | // inter leaves through the very same loop the |
| 1612 | // straddling case has always used. |
| 1613 | let part16 = if has_cols16 && has_rows16 { |
| 1614 | if crate::envflags::env_flag!("EC_TRACE_PART") { |
| 1615 | eprintln!( |
| 1616 | "EC_PART mi_row={} mi_col={} bsize=6 ctx={} rng={}", |
| 1617 | (sr * SUB_MI as usize), |
| 1618 | (sc * SUB_MI as usize), |
| 1619 | ctx16, |
| 1620 | dec.debug_state().0 |
| 1621 | ); |
| 1622 | } |
| 1623 | let p = dec.symbol(&mut cdfs.partition_w16[ctx16]); |
| 1624 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| 1625 | let (rng, _) = dec.debug_state(); |
| 1626 | eprintln!( |
| 1627 | "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={p} rng={rng}", |
| 1628 | sr as u32 * SUB_MI, |
| 1629 | sc as u32 * SUB_MI |
| 1630 | ); |
| 1631 | } |
| 1632 | p |
| 1633 | } else if !has_cols16 && !has_rows16 { |
| 1634 | // lane-edgeboth r1: both axes cut by the true |
| 1635 | // frame edge -- libaom `decode_partition` |
| 1636 | // forces PARTITION_SPLIT and reads NO symbol; |
| 1637 | // the leaf loop below already drops the |
| 1638 | // out-of-frame quadrants. |
| 1639 | bump_edge_both_cut(0); |
| 1640 | PARTITION_SPLIT |
| 1641 | } else { |
| 1642 | if has_cols16 { |
| 1643 | // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 1644 | // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT |
| 1645 | // (libaom `ec_read_partition_impl`). |
| 1646 | if crate::envflags::env_flag!("EC_TRACE_PART") { |
| 1647 | eprintln!( |
| 1648 | "EC_PARTG mi_row={} mi_col={} bsize=6 ctx={} rng={}", |
| 1649 | sr * SUB_MI as usize, |
| 1650 | sc * SUB_MI as usize, |
| 1651 | ctx16, |
| 1652 | dec.debug_state().0 |
| 1653 | ); |
| 1654 | } |
| 1655 | if dec.symbol_fixed(&gather( |
| 1656 | &cdfs.partition_w16[ctx16], |
| 1657 | VERT_ALIKE, |
| 1658 | )) == 1 |
| 1659 | { |
| 1660 | PARTITION_SPLIT |
| 1661 | } else { |
| 1662 | PARTITION_HORZ |
| 1663 | } |
| 1664 | } else { |
| 1665 | // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 1666 | // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT |
| 1667 | // (libaom `ec_read_partition_impl`). |
| 1668 | if dec.symbol_fixed(&gather( |
| 1669 | &cdfs.partition_w16[ctx16], |
| 1670 | HORZ_ALIKE, |
| 1671 | )) == 1 |
| 1672 | { |
| 1673 | PARTITION_SPLIT |
| 1674 | } else { |
| 1675 | PARTITION_VERT |
| 1676 | } |
| 1677 | } |
| 1678 | }; |
| 1679 | // lane-av1unwritten r7: the inter-frame 16x16 |
| 1680 | // level had NO guard at all -- r6 dropped r5's |
| 1681 | // misplaced one without replacing it, and all three |
| 1682 | // dispatch arms below (NONE/HORZ/VERT, the four AB |
| 1683 | // arms, and the 1:4 arms) select BLOCK_8X16 and |
| 1684 | // BLOCK_4X16, two of the eight (1,0)-INVALID shapes. |
| 1685 | // The check goes where the symbol is RESOLVED, so |
| 1686 | // every arm is covered by construction. |
| 1687 | refuse_invalid_subsize((16, 16), part16, fctx)?; |
| 1688 | if part16 == PARTITION_NONE { |
| 1689 | decode_inter_block( |
| 1690 | &mut dec, |
| 1691 | &mut cdfs, |
| 1692 | &mut neighbours, |
| 1693 | &mut grid, |
| 1694 | sub16_to_mi(at16), |
| 1695 | SUB, |
| 1696 | mi_cols, |
| 1697 | mi_rows, |
| 1698 | &mut y, |
| 1699 | &mut u, |
| 1700 | &mut v, |
| 1701 | refpix, |
| 1702 | &sign_bias_table, |
| 1703 | &global_motion, |
| 1704 | base_q_idx, |
| 1705 | TxbSet::Luma16, |
| 1706 | if reduced_tx_set { |
| 1707 | TxbSet::Luma16Inter |
| 1708 | } else { |
| 1709 | TxbSet::Luma16InterSet1 |
| 1710 | }, |
| 1711 | TxbSet::Chroma8, |
| 1712 | TX16, |
| 1713 | TX8, |
| 1714 | scan16, |
| 1715 | scan8, |
| 1716 | 2, |
| 1717 | allow_high_precision_mv, |
| 1718 | force_integer_mv, |
| 1719 | interp_fixed, |
| 1720 | enable_dual_filter, |
| 1721 | tpl_frame.as_ref(), |
| 1722 | reference_select, |
| 1723 | enable_masked_compound, |
| 1724 | enable_interintra_compound, |
| 1725 | enable_jnt_comp, |
| 1726 | order_hint_bits, |
| 1727 | order_hint, |
| 1728 | ref_order_hints, |
| 1729 | skip_mode_present, |
| 1730 | skip_mode_frame, |
| 1731 | switchable_motion_mode, |
| 1732 | allow_warped_motion, |
| 1733 | false, |
| 1734 | SUB, |
| 1735 | SUB, |
| 1736 | allow_screen_content_tools, |
| 1737 | (frame_width as usize, frame_height as usize), |
| 1738 | fctx, |
| 1739 | )?; |
| 1740 | } else if part16 == PARTITION_HORZ || part16 == PARTITION_VERT { |
| 1741 | // lane-inter4 r3: the 16x16-level rect inter |
| 1742 | // leaves -- two true 16x8 (HORZ) or 8x16 |
| 1743 | // (VERT) inter blocks. Same shape as the |
| 1744 | // 32-level HORZ/VERT arm above: `side = SUB` |
| 1745 | // keeps every CDF/prediction-buffer decision |
| 1746 | // square, `write_w`/`write_h` carry the true |
| 1747 | // footprint into the mv stack, the motion-mode |
| 1748 | // row, the neighbour stamps and the rectangular |
| 1749 | // residual path (`rect_inter_residual_supported` |
| 1750 | // covers 16x8/8x16 since this round). |
| 1751 | let horz = part16 == PARTITION_HORZ; |
| 1752 | if horz { |
| 1753 | hit!(INTER_LEAF16_HORZ_HITS); |
| 1754 | } else { |
| 1755 | hit!(INTER_LEAF16_VERT_HITS); |
| 1756 | } |
| 1757 | let base_mi = sub16_to_mi(at16); |
| 1758 | let (ww, wh) = if horz { (16, 8) } else { (8, 16) }; |
| 1759 | for piece in 0..2 { |
| 1760 | let piece_mi = if horz { |
| 1761 | (base_mi.0 + piece * 2, base_mi.1) |
| 1762 | } else { |
| 1763 | (base_mi.0, base_mi.1 + piece * 2) |
| 1764 | }; |
| 1765 | // libaom `decode_partition`'s own second- |
| 1766 | // half frame-edge break. |
| 1767 | if piece > 0 |
| 1768 | && (piece_mi.0 >= mi_rows as usize |
| 1769 | || piece_mi.1 >= mi_cols as usize) |
| 1770 | { |
| 1771 | bump_inter_edge_strip(if horz { 4 } else { 5 }); |
| 1772 | break; |
| 1773 | } |
| 1774 | decode_inter_block( |
| 1775 | &mut dec, |
| 1776 | &mut cdfs, |
| 1777 | &mut neighbours, |
| 1778 | &mut grid, |
| 1779 | piece_mi, |
| 1780 | SUB, |
| 1781 | mi_cols, |
| 1782 | mi_rows, |
| 1783 | &mut y, |
| 1784 | &mut u, |
| 1785 | &mut v, |
| 1786 | refpix, |
| 1787 | &sign_bias_table, |
| 1788 | &global_motion, |
| 1789 | base_q_idx, |
| 1790 | TxbSet::Luma16, |
| 1791 | if reduced_tx_set { |
| 1792 | TxbSet::Luma16Inter |
| 1793 | } else { |
| 1794 | TxbSet::Luma16InterSet1 |
| 1795 | }, |
| 1796 | TxbSet::Chroma8, |
| 1797 | TX16, |
| 1798 | TX8, |
| 1799 | scan16, |
| 1800 | scan8, |
| 1801 | 1, |
| 1802 | allow_high_precision_mv, |
| 1803 | force_integer_mv, |
| 1804 | interp_fixed, |
| 1805 | enable_dual_filter, |
| 1806 | tpl_frame.as_ref(), |
| 1807 | reference_select, |
| 1808 | enable_masked_compound, |
| 1809 | enable_interintra_compound, |
| 1810 | enable_jnt_comp, |
| 1811 | order_hint_bits, |
| 1812 | order_hint, |
| 1813 | ref_order_hints, |
| 1814 | skip_mode_present, |
| 1815 | skip_mode_frame, |
| 1816 | switchable_motion_mode, |
| 1817 | allow_warped_motion, |
| 1818 | true, |
| 1819 | ww, |
| 1820 | wh, |
| 1821 | allow_screen_content_tools, |
| 1822 | (frame_width as usize, frame_height as usize), |
| 1823 | fctx, |
| 1824 | )?; |
| 1825 | } |
| 1826 | } else if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part16) { |
| 1827 | // lane-inter16ab r1: the four AB (T-shaped) |
| 1828 | // partitions at the 16x16 level of an INTER |
| 1829 | // frame -- two 8x8 inter leaves plus one true |
| 1830 | // 16x8/8x16 inter strip. libaom |
| 1831 | // `decode_partition` (decodeframe.c ~5040, |
| 1832 | // `bsize2 = get_partition_subsize(bsize, |
| 1833 | // PARTITION_SPLIT)` = BLOCK_8X8 here) visits: |
| 1834 | // HORZ_A: TL 8x8, TR 8x8, bottom 16x8 |
| 1835 | // HORZ_B: top 16x8, BL 8x8, BR 8x8 |
| 1836 | // VERT_A: TL 8x8, BL 8x8, right 8x16 |
| 1837 | // VERT_B: left 8x16, TR 8x8, BR 8x8 |
| 1838 | // Every piece is inside the frame by |
| 1839 | // construction: an AB value can only be read |
| 1840 | // from the (has_cols16 && has_rows16) branch |
| 1841 | // above, i.e. mi_row+2 < mi_rows and |
| 1842 | // mi_col+2 < mi_cols, which is exactly |
| 1843 | // libaom's own `has_rows`/`has_cols`. |
| 1844 | // |
| 1845 | // VERT_A/VERT_B visit TL,BL,TR,BR, so a |
| 1846 | // bottom-left square's top-right neighbour is |
| 1847 | // the partition's own not-yet-decoded |
| 1848 | // rectangle: libaom switches those squares |
| 1849 | // onto `has_tr_vert_*`/`has_bl_vert_*` |
| 1850 | // (`reconintra.c get_has_tr_table`) -- |
| 1851 | // `Reach::vert_ab_partition()`, the same |
| 1852 | // guard the intra 16-level arm and the |
| 1853 | // 32-level inter AB arms take (class |
| 1854 | // `visit-order-changes-availability`). |
| 1855 | // |
| 1856 | // OBMC/warp and compound stay legal here: |
| 1857 | // every piece is >= 8x8, so libaom's |
| 1858 | // `is_motion_variation_allowed_bsize` |
| 1859 | // (min(bw,bh) >= 8, blockd.h) and |
| 1860 | // `is_comp_ref_allowed` (block_size_wide + |
| 1861 | // block_size_high >= 16, blockd.h) both hold |
| 1862 | // and the leaf/strip decoders' own gates |
| 1863 | // apply unchanged. |
| 1864 | bump_ab16_inter(part16 - PARTITION_HORZ_A); |
| 1865 | let _vert_guard = if part16 == PARTITION_VERT_A |
| 1866 | || part16 == PARTITION_VERT_B |
| 1867 | { |
| 1868 | Some(crate::encode::Reach::vert_ab_partition()) |
| 1869 | } else { |
| 1870 | None |
| 1871 | }; |
| 1872 | let (mi_row0, mi_col0) = sub16_to_mi(at16); |
| 1873 | let tl = (mi_row0, mi_col0); |
| 1874 | let tr = (mi_row0, mi_col0 + 2); |
| 1875 | let bl = (mi_row0 + 2, mi_col0); |
| 1876 | let br = (mi_row0 + 2, mi_col0 + 2); |
| 1877 | macro_rules! ab_strip16 { |
| 1878 | ($mi:expr, $ww:expr, $wh:expr) => { |
| 1879 | inter_piece!( |
| 1880 | $mi, |
| 1881 | SUB, |
| 1882 | TxbSet::Luma16, |
| 1883 | if reduced_tx_set { |
| 1884 | TxbSet::Luma16Inter |
| 1885 | } else { |
| 1886 | TxbSet::Luma16InterSet1 |
| 1887 | }, |
| 1888 | TxbSet::Chroma8, |
| 1889 | TX16, |
| 1890 | TX8, |
| 1891 | &scan16, |
| 1892 | &scan8, |
| 1893 | 1, |
| 1894 | $ww, |
| 1895 | $wh |
| 1896 | ) |
| 1897 | }; |
| 1898 | } |
| 1899 | match part16 { |
| 1900 | PARTITION_HORZ_A => { |
| 1901 | inter_leaf8!(at16, tl); |
| 1902 | inter_leaf8!(at16, tr); |
| 1903 | ab_strip16!(bl, 16, 8); |
| 1904 | } |
| 1905 | PARTITION_HORZ_B => { |
| 1906 | ab_strip16!(tl, 16, 8); |
| 1907 | inter_leaf8!(at16, bl); |
| 1908 | inter_leaf8!(at16, br); |
| 1909 | } |
| 1910 | PARTITION_VERT_A => { |
| 1911 | inter_leaf8!(at16, tl); |
| 1912 | inter_leaf8!(at16, bl); |
| 1913 | ab_strip16!(tr, 8, 16); |
| 1914 | } |
| 1915 | _ => { |
| 1916 | ab_strip16!(tl, 8, 16); |
| 1917 | inter_leaf8!(at16, tr); |
| 1918 | inter_leaf8!(at16, br); |
| 1919 | } |
| 1920 | } |
| 1921 | } else if part16 == PARTITION_HORZ_4 || part16 == PARTITION_VERT_4 { |
| 1922 | // lane-inter16ab r2: four 16x4 (4x16) INTER |
| 1923 | // strips. libaom `decode_partition` |
| 1924 | // (decodeframe.c, PARTITION_HORZ_4/VERT_4) |
| 1925 | // walks them top to bottom (left to right) |
| 1926 | // with its own `i > 0` frame-edge break. |
| 1927 | // |
| 1928 | // Each strip is >= 8 in one dimension only, |
| 1929 | // so `is_comp_ref_allowed`, |
| 1930 | // `is_motion_variation_allowed_bsize` |
| 1931 | // (blockd.h:65/1455, min(bw, bh) >= 8) and |
| 1932 | // `is_interintra_allowed_bsize` (BLOCK_8X8.. |
| 1933 | // BLOCK_32X32 in enum order, which excludes |
| 1934 | // BLOCK_16X4 = 17) are all false: no |
| 1935 | // skip_mode, no comp_mode, no OBMC/warp and |
| 1936 | // no interintra symbol is read -- gated in |
| 1937 | // `decode_inter_block` off `write_w`/ |
| 1938 | // `write_h`. |
| 1939 | // |
| 1940 | // CHROMA is the pair's: |
| 1941 | // `is_chroma_reference` |
| 1942 | // (av1_common_int.h:1454) is false on the |
| 1943 | // even strips, and the odd one codes one 8x4 |
| 1944 | // (4x8) chroma transform at the pair's |
| 1945 | // origin, built from BOTH strips' motion |
| 1946 | // (`is_sub8x8_inter`). |
| 1947 | let horz = part16 == PARTITION_HORZ_4; |
| 1948 | let (mi_row0, mi_col0) = sub16_to_mi(at16); |
| 1949 | let (bw, bh) = if horz { |
| 1950 | (16usize, 4usize) |
| 1951 | } else { |
| 1952 | (4usize, 16usize) |
| 1953 | }; |
| 1954 | for i in 0..4usize { |
| 1955 | let at_mi = if horz { |
| 1956 | (mi_row0 + i, mi_col0) |
| 1957 | } else { |
| 1958 | (mi_row0, mi_col0 + i) |
| 1959 | }; |
| 1960 | if i > 0 |
| 1961 | && (at_mi.0 >= mi_rows as usize |
| 1962 | || at_mi.1 >= mi_cols as usize) |
| 1963 | { |
| 1964 | break; |
| 1965 | } |
| 1966 | // lane-av1-444: at 4:4:4 every strip is |
| 1967 | // its own chroma reference |
| 1968 | // (`is_chroma_reference`: no mi parity |
| 1969 | // test at ss 0/0 and the strip's 16x4 / |
| 1970 | // 4x16 chroma block is already >= 4x4), |
| 1971 | // so there is no pair: each strip codes |
| 1972 | // and predicts its own chroma from its |
| 1973 | // own motion (`prev` = None). |
| 1974 | // lane-av1-422l: a strip pairs along its |
| 1975 | // OWN subsampled axis -- horz strips pair |
| 1976 | // on rows (no pair once ss_y == 0: chroma |
| 1977 | // has no row parity, every 16x4 strip is |
| 1978 | // its own reference, exactly the intra |
| 1979 | // strip arm's `else if ss_y(fctx) == 0`); |
| 1980 | // vert strips pair on columns (ss_x == 0 |
| 1981 | // => every strip self-pairs, 4:2:2 keeps |
| 1982 | // the 4:2:0 column pairing -- a VERT_4 |
| 1983 | // 4x16 strip's `ss_size_lookup` chroma |
| 1984 | // at ss (1,0) is BLOCK_INVALID, so only |
| 1985 | // the pair shape can ever be coded). |
| 1986 | let strip_has_chroma = if horz { |
| 1987 | i % 2 == 1 || ss_y(fctx) == 0 |
| 1988 | } else { |
| 1989 | i % 2 == 1 || ss_x(fctx) == 0 |
| 1990 | }; |
| 1991 | let pair_mi = if !strip_has_chroma |
| 1992 | || (if horz { |
| 1993 | ss_y(fctx) == 0 |
| 1994 | } else { |
| 1995 | ss_x(fctx) == 0 |
| 1996 | }) { |
| 1997 | at_mi |
| 1998 | } else if horz { |
| 1999 | (at_mi.0 - 1, at_mi.1) |
| 2000 | } else { |
| 2001 | (at_mi.0, at_mi.1 - 1) |
| 2002 | }; |
| 2003 | fctx.inter_strip_chroma.with(|c| { |
| 2004 | c.set(Some(InterStripChroma { |
| 2005 | has_chroma: strip_has_chroma, |
| 2006 | horz, |
| 2007 | pair_mi, |
| 2008 | prev: if strip_has_chroma |
| 2009 | && (if horz { |
| 2010 | ss_y(fctx) == 1 |
| 2011 | } else { |
| 2012 | ss_x(fctx) == 1 |
| 2013 | }) { |
| 2014 | fctx.inter_last_mc.with(std::cell::Cell::get) |
| 2015 | } else { |
| 2016 | None |
| 2017 | }, |
| 2018 | })) |
| 2019 | }); |
| 2020 | inter_piece!( |
| 2021 | at_mi, |
| 2022 | SUB, |
| 2023 | TxbSet::Luma16, |
| 2024 | if reduced_tx_set { |
| 2025 | TxbSet::Luma16Inter |
| 2026 | } else { |
| 2027 | TxbSet::Luma16InterSet1 |
| 2028 | }, |
| 2029 | TxbSet::Chroma8, |
| 2030 | TX16, |
| 2031 | TX8, |
| 2032 | &scan16, |
| 2033 | &scan8, |
| 2034 | 1, |
| 2035 | bw, |
| 2036 | bh |
| 2037 | ); |
| 2038 | if horz { |
| 2039 | hit!(INTER16_HORZ4_HITS); |
| 2040 | } else { |
| 2041 | hit!(INTER16_VERT4_HITS); |
| 2042 | } |
| 2043 | } |
| 2044 | } else if part16 != PARTITION_SPLIT { |
| 2045 | return Err(unsupported( |
| 2046 | "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4", |
| 2047 | )); |
| 2048 | } else { |
| 2049 | if has_cols16 && has_rows16 { |
| 2050 | hit!(INTER_SUB16_SPLIT_HITS); |
| 2051 | } |
| 2052 | let (mi_row0, mi_col0) = |
| 2053 | (sr as u32 * SUB_MI, sc as u32 * SUB_MI); |
| 2054 | let leaf_positions: Vec<(u32, u32)> = (0..4) |
| 2055 | .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) |
| 2056 | .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) |
| 2057 | .collect(); |
| 2058 | // lane-t900 r28: the 8x8-leaf refusal under a |
| 2059 | // scaled reference is LIFTED -- |
| 2060 | // `decode_inter_block8`'s single-ref, |
| 2061 | // compound and OBMC MC all take spec |
| 2062 | // 7.11.3.3's scaled walk. The counter is what |
| 2063 | // proves a gate actually reached a scaled |
| 2064 | // leaf rather than a same-size reference. |
| 2065 | if (1..8).any(|rf| { |
| 2066 | refpix |
| 2067 | .dims(rf) |
| 2068 | .is_some_and(|(w, _)| w != frame_width as usize) |
| 2069 | }) { |
| 2070 | hit!(SCALED_LEAF8_HITS); |
| 2071 | } |
| 2072 | let mut prev_leaves: Vec<( |
| 2073 | (usize, usize), |
| 2074 | bool, |
| 2075 | bool, |
| 2076 | i8, |
| 2077 | Option<i8>, |
| 2078 | )> = Vec::new(); |
| 2079 | for (mr, mc) in leaf_positions { |
| 2080 | let leaf_mi = (mr as usize, mc as usize); |
| 2081 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); |
| 2082 | if crate::envflags::env_flag!("EC_TRACE_PART") { |
| 2083 | eprintln!( |
| 2084 | "EC_PART mi_row={} mi_col={} bsize=3 ctx={} rng={}", |
| 2085 | leaf_mi.0, |
| 2086 | leaf_mi.1, |
| 2087 | leaf_ctx, |
| 2088 | dec.debug_state().0 |
| 2089 | ); |
| 2090 | } |
| 2091 | let ec_dbg_pre = dec.debug_state().0; |
| 2092 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| 2093 | // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be |
| 2094 | // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize` |
| 2095 | // (common_data.h:71-90) reduced to dimensions, so this is |
| 2096 | // `decode_partition`'s pre-descend check (decodeframe.c:1451-1460) on EVERY |
| 2097 | // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings |
| 2098 | // keep decoding because the helper is exact, not a heuristic. inter-frame 8x8 level. |
| 2099 | refuse_invalid_subsize((8, 8), part8, fctx)?; |
| 2100 | |
| 2101 | if std::env::var_os("EC_DBG_SUB8").is_some() { |
| 2102 | let ec_dbg_post = dec.debug_state().0; |
| 2103 | eprintln!( |
| 2104 | "EC_DBG b8 mi=({},{}) ctx={leaf_ctx} val={part8} pre={ec_dbg_pre} post={ec_dbg_post}", |
| 2105 | leaf_mi.0, leaf_mi.1 |
| 2106 | ); |
| 2107 | } |
| 2108 | if part8 == PARTITION_SPLIT { |
| 2109 | // lane-intersub8: four BLOCK_4X4 inter |
| 2110 | // sub-blocks, chroma once per 8x8. |
| 2111 | decode_inter_sub8_split4( |
| 2112 | &mut dec, |
| 2113 | &mut cdfs, |
| 2114 | &mut neighbours, |
| 2115 | &mut grid, |
| 2116 | leaf_mi, |
| 2117 | mi_cols, |
| 2118 | mi_rows, |
| 2119 | &mut y, |
| 2120 | &mut u, |
| 2121 | &mut v, |
| 2122 | refpix, |
| 2123 | &sign_bias_table, |
| 2124 | &global_motion, |
| 2125 | base_q_idx, |
| 2126 | scan4, |
| 2127 | allow_high_precision_mv, |
| 2128 | force_integer_mv, |
| 2129 | interp_fixed, |
| 2130 | enable_dual_filter, |
| 2131 | tpl_frame.as_ref(), |
| 2132 | reduced_tx_set, |
| 2133 | (frame_width as usize, frame_height as usize), |
| 2134 | fctx, |
| 2135 | )?; |
| 2136 | continue; |
| 2137 | } |
| 2138 | // lane-av1unwritten r6: arm census -- an |
| 2139 | // 8x8-level VERT selects BLOCK_4X8, which |
| 2140 | // is INVALID at 4:2:2. |
| 2141 | note_subsize_arm( |
| 2142 | part8, |
| 2143 | chroma_plane_block_codable( |
| 2144 | partition_subsize_dims((8, 8), part8).0, |
| 2145 | partition_subsize_dims((8, 8), part8).1, |
| 2146 | ss_x(fctx), |
| 2147 | ss_y(fctx), |
| 2148 | ), |
| 2149 | ); |
| 2150 | if part8 == PARTITION_VERT || part8 == PARTITION_HORZ { |
| 2151 | // lane-intersub8 r3/r4/r5: two |
| 2152 | // BLOCK_8X4 (HORZ) / BLOCK_4X8 (VERT) |
| 2153 | // inter leaves, chroma once per 8x8 on |
| 2154 | // the second of them. HORZ was refused |
| 2155 | // by name through r4 over a |d| <= 2 |
| 2156 | // luma band; r5 merged lane-cdef |
| 2157 | // 8c6065e, whose `decode_inter_block8` |
| 2158 | // skip-band write is that band's root |
| 2159 | // cause, and the 56-arm sweep went 3 |
| 2160 | // mismatching arms -> 0. |
| 2161 | decode_inter_sub8_rect2( |
| 2162 | &mut dec, |
| 2163 | &mut cdfs, |
| 2164 | &mut neighbours, |
| 2165 | &mut grid, |
| 2166 | leaf_mi, |
| 2167 | part8 == PARTITION_VERT, |
| 2168 | mi_cols, |
| 2169 | mi_rows, |
| 2170 | &mut y, |
| 2171 | &mut u, |
| 2172 | &mut v, |
| 2173 | refpix, |
| 2174 | &sign_bias_table, |
| 2175 | &global_motion, |
| 2176 | base_q_idx, |
| 2177 | scan4, |
| 2178 | allow_high_precision_mv, |
| 2179 | force_integer_mv, |
| 2180 | interp_fixed, |
| 2181 | enable_dual_filter, |
| 2182 | tpl_frame.as_ref(), |
| 2183 | reduced_tx_set, |
| 2184 | (frame_width as usize, frame_height as usize), |
| 2185 | fctx, |
| 2186 | )?; |
| 2187 | continue; |
| 2188 | } |
| 2189 | // `partition_w8` is a 4-symbol alphabet |
| 2190 | // (NONE/HORZ/VERT/SPLIT), all four handled. |
| 2191 | let ( |
| 2192 | skip, |
| 2193 | is_inter, |
| 2194 | skip_mode_leaf, |
| 2195 | compound_ctx8, |
| 2196 | leaf_filter, |
| 2197 | leaf_refs, |
| 2198 | ) = decode_inter_block8( |
| 2199 | &mut dec, |
| 2200 | &mut cdfs, |
| 2201 | &mut neighbours, |
| 2202 | &mut grid, |
| 2203 | mi_cols, |
| 2204 | mi_rows, |
| 2205 | at16, |
| 2206 | leaf_mi, |
| 2207 | &mut y, |
| 2208 | &mut u, |
| 2209 | &mut v, |
| 2210 | refpix, |
| 2211 | base_q_idx, |
| 2212 | scan8, |
| 2213 | scan4, |
| 2214 | allow_high_precision_mv, |
| 2215 | force_integer_mv, |
| 2216 | &global_motion, |
| 2217 | enable_dual_filter, |
| 2218 | reference_select, |
| 2219 | enable_masked_compound, |
| 2220 | enable_interintra_compound, |
| 2221 | enable_jnt_comp, |
| 2222 | order_hint_bits, |
| 2223 | order_hint, |
| 2224 | ref_order_hints, |
| 2225 | skip_mode_present, |
| 2226 | skip_mode_frame, |
| 2227 | reduced_tx_set, |
| 2228 | interp_fixed, |
| 2229 | switchable_motion_mode, |
| 2230 | allow_warped_motion, |
| 2231 | allow_screen_content_tools, |
| 2232 | &sign_bias_table, |
| 2233 | tpl_frame.as_ref(), |
| 2234 | (frame_width as usize, frame_height as usize), |
| 2235 | fctx, |
| 2236 | )?; |
| 2237 | prev_leaves.push(( |
| 2238 | leaf_mi, |
| 2239 | skip, |
| 2240 | is_inter, |
| 2241 | leaf_refs.0, |
| 2242 | leaf_refs.1, |
| 2243 | )); |
| 2244 | // lane-inter8 r2: stamp THIS leaf's own |
| 2245 | // 2x2-mi span before the next leaf reads |
| 2246 | // it as a neighbour -- the whole-16x16 |
| 2247 | // stamp below only ever described the |
| 2248 | // last leaf, so three quarters of the |
| 2249 | // block carried the wrong skip/ref/inter |
| 2250 | // state into the next block's contexts |
| 2251 | // (class context-read-from-one-cell). |
| 2252 | // lane-gmaffine r3: with the mi-granular |
| 2253 | // band, the leaf's OWN switchable-filter |
| 2254 | // symbols go in here -- the `[3, 3]` |
| 2255 | // ("intra, no filter") sentinel this used |
| 2256 | // to stamp made `obmc_blend`'s |
| 2257 | // `neighbour_filter` PANIC as soon as a |
| 2258 | // sibling leaf blended one of these. |
| 2259 | neighbours.record_inter_rect_mi( |
| 2260 | leaf_mi, |
| 2261 | 2, |
| 2262 | 2, |
| 2263 | skip, |
| 2264 | is_inter, |
| 2265 | leaf_refs.0, |
| 2266 | leaf_filter, |
| 2267 | skip_mode_leaf, |
| 2268 | ); |
| 2269 | if let Some(ref1) = leaf_refs.1 |
| 2270 | && let Some((_, _, group_idx, idx)) = compound_ctx8 |
| 2271 | { |
| 2272 | neighbours.record_compound_ctx_rect_mi( |
| 2273 | leaf_mi, 2, 2, ref1, group_idx, idx, |
| 2274 | ); |
| 2275 | } |
| 2276 | } |
| 2277 | // lane-inter8 r2: the four per-leaf |
| 2278 | // `record_inter_rect_mi` stamps above replace |
| 2279 | // the single whole-16x16 one that used to run |
| 2280 | // here with the LAST leaf's state. |
| 2281 | } |
| 2282 | } |
| 2283 | } |
| 2284 | PARTITION_HORZ_B => { |
| 2285 | // lane-warp r5: PARTITION_HORZ_B = 32x32 top strip + |
| 2286 | // 16x16 bottom-left + 16x16 bottom-right. aomenc |
| 2287 | // carves static regions into it; the strip is |
| 2288 | // decoded as a square 32x32 block: for a `skip` |
| 2289 | // block the symbol stream is identical to the true |
| 2290 | // 32x16 coding (no residual, no motion_mode/warp |
| 2291 | // symbol), and the square stamps it leaves over the |
| 2292 | // bottom half (neighbour arrays, skip/lf grids) are |
| 2293 | // re-stamped by the C/D leaves right after. The |
| 2294 | // mi-granular `left_side_mi` rows of a last-block-in- |
| 2295 | // tile strip leak 32-vs-16 only until the per-tile |
| 2296 | // `Neighbours::new` reset. |
| 2297 | hit!(EXTENDED_PARTITION_HITS); |
| 2298 | let at32 = at; |
| 2299 | decode_inter_block( |
| 2300 | &mut dec, |
| 2301 | &mut cdfs, |
| 2302 | &mut neighbours, |
| 2303 | &mut grid, |
| 2304 | sub16_to_mi(at32), |
| 2305 | BLOCK, |
| 2306 | mi_cols, |
| 2307 | mi_rows, |
| 2308 | &mut y, |
| 2309 | &mut u, |
| 2310 | &mut v, |
| 2311 | refpix, |
| 2312 | &sign_bias_table, |
| 2313 | &global_motion, |
| 2314 | base_q_idx, |
| 2315 | TxbSet::Luma32, |
| 2316 | TxbSet::Luma32Inter, |
| 2317 | TxbSet::Chroma16, |
| 2318 | TX32, |
| 2319 | TX16, |
| 2320 | scan32, |
| 2321 | scan16, |
| 2322 | 3, |
| 2323 | allow_high_precision_mv, |
| 2324 | force_integer_mv, |
| 2325 | interp_fixed, |
| 2326 | enable_dual_filter, |
| 2327 | tpl_frame.as_ref(), |
| 2328 | reference_select, |
| 2329 | enable_masked_compound, |
| 2330 | enable_interintra_compound, |
| 2331 | enable_jnt_comp, |
| 2332 | order_hint_bits, |
| 2333 | order_hint, |
| 2334 | ref_order_hints, |
| 2335 | skip_mode_present, |
| 2336 | skip_mode_frame, |
| 2337 | switchable_motion_mode, |
| 2338 | allow_warped_motion, |
| 2339 | true, |
| 2340 | // lane-rect r2: the top strip's TRUE 32x16 |
| 2341 | // footprint (was BLOCK,BLOCK -- the same square |
| 2342 | // corner-cut rect-flake-1 exposed on HORZ). |
| 2343 | BLOCK, |
| 2344 | SUB, |
| 2345 | allow_screen_content_tools, |
| 2346 | (frame_width as usize, frame_height as usize), |
| 2347 | fctx, |
| 2348 | )?; |
| 2349 | if (r32 * 2 + 1) * SUB_MI < mi_rows { |
| 2350 | decode_inter_block( |
| 2351 | &mut dec, |
| 2352 | &mut cdfs, |
| 2353 | &mut neighbours, |
| 2354 | &mut grid, |
| 2355 | sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), |
| 2356 | SUB, |
| 2357 | mi_cols, |
| 2358 | mi_rows, |
| 2359 | &mut y, |
| 2360 | &mut u, |
| 2361 | &mut v, |
| 2362 | refpix, |
| 2363 | &sign_bias_table, |
| 2364 | &global_motion, |
| 2365 | base_q_idx, |
| 2366 | TxbSet::Luma16, |
| 2367 | if reduced_tx_set { |
| 2368 | TxbSet::Luma16Inter |
| 2369 | } else { |
| 2370 | TxbSet::Luma16InterSet1 |
| 2371 | }, |
| 2372 | TxbSet::Chroma8, |
| 2373 | TX16, |
| 2374 | TX8, |
| 2375 | scan16, |
| 2376 | scan8, |
| 2377 | 2, |
| 2378 | allow_high_precision_mv, |
| 2379 | force_integer_mv, |
| 2380 | interp_fixed, |
| 2381 | enable_dual_filter, |
| 2382 | tpl_frame.as_ref(), |
| 2383 | reference_select, |
| 2384 | enable_masked_compound, |
| 2385 | enable_interintra_compound, |
| 2386 | enable_jnt_comp, |
| 2387 | order_hint_bits, |
| 2388 | order_hint, |
| 2389 | ref_order_hints, |
| 2390 | skip_mode_present, |
| 2391 | skip_mode_frame, |
| 2392 | switchable_motion_mode, |
| 2393 | allow_warped_motion, |
| 2394 | false, |
| 2395 | SUB, |
| 2396 | SUB, |
| 2397 | allow_screen_content_tools, |
| 2398 | (frame_width as usize, frame_height as usize), |
| 2399 | fctx, |
| 2400 | )?; |
| 2401 | if (c32 * 2 + 1) * SUB_MI < mi_cols { |
| 2402 | decode_inter_block( |
| 2403 | &mut dec, |
| 2404 | &mut cdfs, |
| 2405 | &mut neighbours, |
| 2406 | &mut grid, |
| 2407 | sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2 + 1)), |
| 2408 | SUB, |
| 2409 | mi_cols, |
| 2410 | mi_rows, |
| 2411 | &mut y, |
| 2412 | &mut u, |
| 2413 | &mut v, |
| 2414 | refpix, |
| 2415 | &sign_bias_table, |
| 2416 | &global_motion, |
| 2417 | base_q_idx, |
| 2418 | TxbSet::Luma16, |
| 2419 | if reduced_tx_set { |
| 2420 | TxbSet::Luma16Inter |
| 2421 | } else { |
| 2422 | TxbSet::Luma16InterSet1 |
| 2423 | }, |
| 2424 | TxbSet::Chroma8, |
| 2425 | TX16, |
| 2426 | TX8, |
| 2427 | scan16, |
| 2428 | scan8, |
| 2429 | 2, |
| 2430 | allow_high_precision_mv, |
| 2431 | force_integer_mv, |
| 2432 | interp_fixed, |
| 2433 | enable_dual_filter, |
| 2434 | tpl_frame.as_ref(), |
| 2435 | reference_select, |
| 2436 | enable_masked_compound, |
| 2437 | enable_interintra_compound, |
| 2438 | enable_jnt_comp, |
| 2439 | order_hint_bits, |
| 2440 | order_hint, |
| 2441 | ref_order_hints, |
| 2442 | skip_mode_present, |
| 2443 | skip_mode_frame, |
| 2444 | switchable_motion_mode, |
| 2445 | allow_warped_motion, |
| 2446 | false, |
| 2447 | SUB, |
| 2448 | SUB, |
| 2449 | allow_screen_content_tools, |
| 2450 | (frame_width as usize, frame_height as usize), |
| 2451 | fctx, |
| 2452 | )?; |
| 2453 | } |
| 2454 | } |
| 2455 | } |
| 2456 | PARTITION_HORZ => { |
| 2457 | // lane-rect r2: two true 32x16 strips. Both read at |
| 2458 | // `side=BLOCK` (CDF/size-class selection stays square, |
| 2459 | // matching HORZ_B's accepted corner-cut) but bw4/bh4 |
| 2460 | // (mvstack.rs, `motion_mode_eligible`) now derive from |
| 2461 | // `write_w`/`write_h`'s true 32x16 footprint -- the |
| 2462 | // pin's fix (r1's finding). |
| 2463 | hit!(RECT_PARTITION_HITS); |
| 2464 | decode_inter_block( |
| 2465 | &mut dec, |
| 2466 | &mut cdfs, |
| 2467 | &mut neighbours, |
| 2468 | &mut grid, |
| 2469 | sub16_to_mi(at), |
| 2470 | BLOCK, |
| 2471 | mi_cols, |
| 2472 | mi_rows, |
| 2473 | &mut y, |
| 2474 | &mut u, |
| 2475 | &mut v, |
| 2476 | refpix, |
| 2477 | &sign_bias_table, |
| 2478 | &global_motion, |
| 2479 | base_q_idx, |
| 2480 | TxbSet::Luma32, |
| 2481 | TxbSet::Luma32Inter, |
| 2482 | TxbSet::Chroma16, |
| 2483 | TX32, |
| 2484 | TX16, |
| 2485 | scan32, |
| 2486 | scan16, |
| 2487 | 3, |
| 2488 | allow_high_precision_mv, |
| 2489 | force_integer_mv, |
| 2490 | interp_fixed, |
| 2491 | enable_dual_filter, |
| 2492 | tpl_frame.as_ref(), |
| 2493 | reference_select, |
| 2494 | enable_masked_compound, |
| 2495 | enable_interintra_compound, |
| 2496 | enable_jnt_comp, |
| 2497 | order_hint_bits, |
| 2498 | order_hint, |
| 2499 | ref_order_hints, |
| 2500 | skip_mode_present, |
| 2501 | skip_mode_frame, |
| 2502 | switchable_motion_mode, |
| 2503 | allow_warped_motion, |
| 2504 | true, |
| 2505 | BLOCK, |
| 2506 | SUB, |
| 2507 | allow_screen_content_tools, |
| 2508 | (frame_width as usize, frame_height as usize), |
| 2509 | fctx, |
| 2510 | )?; |
| 2511 | if !has_rows32 { |
| 2512 | bump_edge32(2); |
| 2513 | } |
| 2514 | // lane-golomb r2: at the frame edge only the first half of the |
| 2515 | // strip is coded (libaom `decode_partition` guards the second |
| 2516 | // with the same has_rows32 test that made this partition non-square). |
| 2517 | if has_rows32 { |
| 2518 | decode_inter_block( |
| 2519 | &mut dec, |
| 2520 | &mut cdfs, |
| 2521 | &mut neighbours, |
| 2522 | &mut grid, |
| 2523 | sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), |
| 2524 | BLOCK, |
| 2525 | mi_cols, |
| 2526 | mi_rows, |
| 2527 | &mut y, |
| 2528 | &mut u, |
| 2529 | &mut v, |
| 2530 | refpix, |
| 2531 | &sign_bias_table, |
| 2532 | &global_motion, |
| 2533 | base_q_idx, |
| 2534 | TxbSet::Luma32, |
| 2535 | TxbSet::Luma32Inter, |
| 2536 | TxbSet::Chroma16, |
| 2537 | TX32, |
| 2538 | TX16, |
| 2539 | scan32, |
| 2540 | scan16, |
| 2541 | 3, |
| 2542 | allow_high_precision_mv, |
| 2543 | force_integer_mv, |
| 2544 | interp_fixed, |
| 2545 | enable_dual_filter, |
| 2546 | tpl_frame.as_ref(), |
| 2547 | reference_select, |
| 2548 | enable_masked_compound, |
| 2549 | enable_interintra_compound, |
| 2550 | enable_jnt_comp, |
| 2551 | order_hint_bits, |
| 2552 | order_hint, |
| 2553 | ref_order_hints, |
| 2554 | skip_mode_present, |
| 2555 | skip_mode_frame, |
| 2556 | switchable_motion_mode, |
| 2557 | allow_warped_motion, |
| 2558 | true, |
| 2559 | BLOCK, |
| 2560 | SUB, |
| 2561 | allow_screen_content_tools, |
| 2562 | (frame_width as usize, frame_height as usize), |
| 2563 | fctx, |
| 2564 | )?; |
| 2565 | } else { |
| 2566 | bump_inter_edge_strip(2); |
| 2567 | } |
| 2568 | } |
| 2569 | PARTITION_VERT => { |
| 2570 | // lane-rect r2: mirror of PARTITION_HORZ above with |
| 2571 | // width/height swapped. |
| 2572 | hit!(RECT_PARTITION_HITS); |
| 2573 | decode_inter_block( |
| 2574 | &mut dec, |
| 2575 | &mut cdfs, |
| 2576 | &mut neighbours, |
| 2577 | &mut grid, |
| 2578 | sub16_to_mi(at), |
| 2579 | BLOCK, |
| 2580 | mi_cols, |
| 2581 | mi_rows, |
| 2582 | &mut y, |
| 2583 | &mut u, |
| 2584 | &mut v, |
| 2585 | refpix, |
| 2586 | &sign_bias_table, |
| 2587 | &global_motion, |
| 2588 | base_q_idx, |
| 2589 | TxbSet::Luma32, |
| 2590 | TxbSet::Luma32Inter, |
| 2591 | TxbSet::Chroma16, |
| 2592 | TX32, |
| 2593 | TX16, |
| 2594 | scan32, |
| 2595 | scan16, |
| 2596 | 3, |
| 2597 | allow_high_precision_mv, |
| 2598 | force_integer_mv, |
| 2599 | interp_fixed, |
| 2600 | enable_dual_filter, |
| 2601 | tpl_frame.as_ref(), |
| 2602 | reference_select, |
| 2603 | enable_masked_compound, |
| 2604 | enable_interintra_compound, |
| 2605 | enable_jnt_comp, |
| 2606 | order_hint_bits, |
| 2607 | order_hint, |
| 2608 | ref_order_hints, |
| 2609 | skip_mode_present, |
| 2610 | skip_mode_frame, |
| 2611 | switchable_motion_mode, |
| 2612 | allow_warped_motion, |
| 2613 | true, |
| 2614 | SUB, |
| 2615 | BLOCK, |
| 2616 | allow_screen_content_tools, |
| 2617 | (frame_width as usize, frame_height as usize), |
| 2618 | fctx, |
| 2619 | )?; |
| 2620 | if !has_cols32 { |
| 2621 | bump_edge32(3); |
| 2622 | } |
| 2623 | // lane-golomb r2: at the frame edge only the first half of the |
| 2624 | // strip is coded (libaom `decode_partition` guards the second |
| 2625 | // with the same has_cols32 test that made this partition non-square). |
| 2626 | if has_cols32 { |
| 2627 | decode_inter_block( |
| 2628 | &mut dec, |
| 2629 | &mut cdfs, |
| 2630 | &mut neighbours, |
| 2631 | &mut grid, |
| 2632 | sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), |
| 2633 | BLOCK, |
| 2634 | mi_cols, |
| 2635 | mi_rows, |
| 2636 | &mut y, |
| 2637 | &mut u, |
| 2638 | &mut v, |
| 2639 | refpix, |
| 2640 | &sign_bias_table, |
| 2641 | &global_motion, |
| 2642 | base_q_idx, |
| 2643 | TxbSet::Luma32, |
| 2644 | TxbSet::Luma32Inter, |
| 2645 | TxbSet::Chroma16, |
| 2646 | TX32, |
| 2647 | TX16, |
| 2648 | scan32, |
| 2649 | scan16, |
| 2650 | 3, |
| 2651 | allow_high_precision_mv, |
| 2652 | force_integer_mv, |
| 2653 | interp_fixed, |
| 2654 | enable_dual_filter, |
| 2655 | tpl_frame.as_ref(), |
| 2656 | reference_select, |
| 2657 | enable_masked_compound, |
| 2658 | enable_interintra_compound, |
| 2659 | enable_jnt_comp, |
| 2660 | order_hint_bits, |
| 2661 | order_hint, |
| 2662 | ref_order_hints, |
| 2663 | skip_mode_present, |
| 2664 | skip_mode_frame, |
| 2665 | switchable_motion_mode, |
| 2666 | allow_warped_motion, |
| 2667 | true, |
| 2668 | SUB, |
| 2669 | BLOCK, |
| 2670 | allow_screen_content_tools, |
| 2671 | (frame_width as usize, frame_height as usize), |
| 2672 | fctx, |
| 2673 | )?; |
| 2674 | } else { |
| 2675 | bump_inter_edge_strip(3); |
| 2676 | } |
| 2677 | } |
| 2678 | PARTITION_HORZ_A => { |
| 2679 | // lane-partab r1: two 16x16 squares on top + a true |
| 2680 | // 32x16 strip below (libaom decode_partition |
| 2681 | // PARTITION_HORZ_A: TL, TR, bottom strip). |
| 2682 | hit!(PARTAB_HITS); |
| 2683 | decode_inter_block( |
| 2684 | &mut dec, |
| 2685 | &mut cdfs, |
| 2686 | &mut neighbours, |
| 2687 | &mut grid, |
| 2688 | sub16_to_mi(at), |
| 2689 | SUB, |
| 2690 | mi_cols, |
| 2691 | mi_rows, |
| 2692 | &mut y, |
| 2693 | &mut u, |
| 2694 | &mut v, |
| 2695 | refpix, |
| 2696 | &sign_bias_table, |
| 2697 | &global_motion, |
| 2698 | base_q_idx, |
| 2699 | TxbSet::Luma16, |
| 2700 | if reduced_tx_set { |
| 2701 | TxbSet::Luma16Inter |
| 2702 | } else { |
| 2703 | TxbSet::Luma16InterSet1 |
| 2704 | }, |
| 2705 | TxbSet::Chroma8, |
| 2706 | TX16, |
| 2707 | TX8, |
| 2708 | scan16, |
| 2709 | scan8, |
| 2710 | 2, |
| 2711 | allow_high_precision_mv, |
| 2712 | force_integer_mv, |
| 2713 | interp_fixed, |
| 2714 | enable_dual_filter, |
| 2715 | tpl_frame.as_ref(), |
| 2716 | reference_select, |
| 2717 | enable_masked_compound, |
| 2718 | enable_interintra_compound, |
| 2719 | enable_jnt_comp, |
| 2720 | order_hint_bits, |
| 2721 | order_hint, |
| 2722 | ref_order_hints, |
| 2723 | skip_mode_present, |
| 2724 | skip_mode_frame, |
| 2725 | switchable_motion_mode, |
| 2726 | allow_warped_motion, |
| 2727 | false, |
| 2728 | SUB, |
| 2729 | SUB, |
| 2730 | allow_screen_content_tools, |
| 2731 | (frame_width as usize, frame_height as usize), |
| 2732 | fctx, |
| 2733 | )?; |
| 2734 | decode_inter_block( |
| 2735 | &mut dec, |
| 2736 | &mut cdfs, |
| 2737 | &mut neighbours, |
| 2738 | &mut grid, |
| 2739 | sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), |
| 2740 | SUB, |
| 2741 | mi_cols, |
| 2742 | mi_rows, |
| 2743 | &mut y, |
| 2744 | &mut u, |
| 2745 | &mut v, |
| 2746 | refpix, |
| 2747 | &sign_bias_table, |
| 2748 | &global_motion, |
| 2749 | base_q_idx, |
| 2750 | TxbSet::Luma16, |
| 2751 | if reduced_tx_set { |
| 2752 | TxbSet::Luma16Inter |
| 2753 | } else { |
| 2754 | TxbSet::Luma16InterSet1 |
| 2755 | }, |
| 2756 | TxbSet::Chroma8, |
| 2757 | TX16, |
| 2758 | TX8, |
| 2759 | scan16, |
| 2760 | scan8, |
| 2761 | 2, |
| 2762 | allow_high_precision_mv, |
| 2763 | force_integer_mv, |
| 2764 | interp_fixed, |
| 2765 | enable_dual_filter, |
| 2766 | tpl_frame.as_ref(), |
| 2767 | reference_select, |
| 2768 | enable_masked_compound, |
| 2769 | enable_interintra_compound, |
| 2770 | enable_jnt_comp, |
| 2771 | order_hint_bits, |
| 2772 | order_hint, |
| 2773 | ref_order_hints, |
| 2774 | skip_mode_present, |
| 2775 | skip_mode_frame, |
| 2776 | switchable_motion_mode, |
| 2777 | allow_warped_motion, |
| 2778 | false, |
| 2779 | SUB, |
| 2780 | SUB, |
| 2781 | allow_screen_content_tools, |
| 2782 | (frame_width as usize, frame_height as usize), |
| 2783 | fctx, |
| 2784 | )?; |
| 2785 | decode_inter_block( |
| 2786 | &mut dec, |
| 2787 | &mut cdfs, |
| 2788 | &mut neighbours, |
| 2789 | &mut grid, |
| 2790 | sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), |
| 2791 | BLOCK, |
| 2792 | mi_cols, |
| 2793 | mi_rows, |
| 2794 | &mut y, |
| 2795 | &mut u, |
| 2796 | &mut v, |
| 2797 | refpix, |
| 2798 | &sign_bias_table, |
| 2799 | &global_motion, |
| 2800 | base_q_idx, |
| 2801 | TxbSet::Luma32, |
| 2802 | TxbSet::Luma32Inter, |
| 2803 | TxbSet::Chroma16, |
| 2804 | TX32, |
| 2805 | TX16, |
| 2806 | scan32, |
| 2807 | scan16, |
| 2808 | 3, |
| 2809 | allow_high_precision_mv, |
| 2810 | force_integer_mv, |
| 2811 | interp_fixed, |
| 2812 | enable_dual_filter, |
| 2813 | tpl_frame.as_ref(), |
| 2814 | reference_select, |
| 2815 | enable_masked_compound, |
| 2816 | enable_interintra_compound, |
| 2817 | enable_jnt_comp, |
| 2818 | order_hint_bits, |
| 2819 | order_hint, |
| 2820 | ref_order_hints, |
| 2821 | skip_mode_present, |
| 2822 | skip_mode_frame, |
| 2823 | switchable_motion_mode, |
| 2824 | allow_warped_motion, |
| 2825 | true, |
| 2826 | BLOCK, |
| 2827 | SUB, |
| 2828 | allow_screen_content_tools, |
| 2829 | (frame_width as usize, frame_height as usize), |
| 2830 | fctx, |
| 2831 | )?; |
| 2832 | } |
| 2833 | PARTITION_VERT_A => { |
| 2834 | // lane-partab r1: mirror of PARTITION_HORZ_A with |
| 2835 | // width/height swapped (TL, BL, right 16x32 strip). |
| 2836 | hit!(PARTAB_HITS); |
| 2837 | let _vert_ab = crate::encode::Reach::vert_ab_partition(); |
| 2838 | decode_inter_block( |
| 2839 | &mut dec, |
| 2840 | &mut cdfs, |
| 2841 | &mut neighbours, |
| 2842 | &mut grid, |
| 2843 | sub16_to_mi(at), |
| 2844 | SUB, |
| 2845 | mi_cols, |
| 2846 | mi_rows, |
| 2847 | &mut y, |
| 2848 | &mut u, |
| 2849 | &mut v, |
| 2850 | refpix, |
| 2851 | &sign_bias_table, |
| 2852 | &global_motion, |
| 2853 | base_q_idx, |
| 2854 | TxbSet::Luma16, |
| 2855 | if reduced_tx_set { |
| 2856 | TxbSet::Luma16Inter |
| 2857 | } else { |
| 2858 | TxbSet::Luma16InterSet1 |
| 2859 | }, |
| 2860 | TxbSet::Chroma8, |
| 2861 | TX16, |
| 2862 | TX8, |
| 2863 | scan16, |
| 2864 | scan8, |
| 2865 | 2, |
| 2866 | allow_high_precision_mv, |
| 2867 | force_integer_mv, |
| 2868 | interp_fixed, |
| 2869 | enable_dual_filter, |
| 2870 | tpl_frame.as_ref(), |
| 2871 | reference_select, |
| 2872 | enable_masked_compound, |
| 2873 | enable_interintra_compound, |
| 2874 | enable_jnt_comp, |
| 2875 | order_hint_bits, |
| 2876 | order_hint, |
| 2877 | ref_order_hints, |
| 2878 | skip_mode_present, |
| 2879 | skip_mode_frame, |
| 2880 | switchable_motion_mode, |
| 2881 | allow_warped_motion, |
| 2882 | false, |
| 2883 | SUB, |
| 2884 | SUB, |
| 2885 | allow_screen_content_tools, |
| 2886 | (frame_width as usize, frame_height as usize), |
| 2887 | fctx, |
| 2888 | )?; |
| 2889 | decode_inter_block( |
| 2890 | &mut dec, |
| 2891 | &mut cdfs, |
| 2892 | &mut neighbours, |
| 2893 | &mut grid, |
| 2894 | sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), |
| 2895 | SUB, |
| 2896 | mi_cols, |
| 2897 | mi_rows, |
| 2898 | &mut y, |
| 2899 | &mut u, |
| 2900 | &mut v, |
| 2901 | refpix, |
| 2902 | &sign_bias_table, |
| 2903 | &global_motion, |
| 2904 | base_q_idx, |
| 2905 | TxbSet::Luma16, |
| 2906 | if reduced_tx_set { |
| 2907 | TxbSet::Luma16Inter |
| 2908 | } else { |
| 2909 | TxbSet::Luma16InterSet1 |
| 2910 | }, |
| 2911 | TxbSet::Chroma8, |
| 2912 | TX16, |
| 2913 | TX8, |
| 2914 | scan16, |
| 2915 | scan8, |
| 2916 | 2, |
| 2917 | allow_high_precision_mv, |
| 2918 | force_integer_mv, |
| 2919 | interp_fixed, |
| 2920 | enable_dual_filter, |
| 2921 | tpl_frame.as_ref(), |
| 2922 | reference_select, |
| 2923 | enable_masked_compound, |
| 2924 | enable_interintra_compound, |
| 2925 | enable_jnt_comp, |
| 2926 | order_hint_bits, |
| 2927 | order_hint, |
| 2928 | ref_order_hints, |
| 2929 | skip_mode_present, |
| 2930 | skip_mode_frame, |
| 2931 | switchable_motion_mode, |
| 2932 | allow_warped_motion, |
| 2933 | false, |
| 2934 | SUB, |
| 2935 | SUB, |
| 2936 | allow_screen_content_tools, |
| 2937 | (frame_width as usize, frame_height as usize), |
| 2938 | fctx, |
| 2939 | )?; |
| 2940 | decode_inter_block( |
| 2941 | &mut dec, |
| 2942 | &mut cdfs, |
| 2943 | &mut neighbours, |
| 2944 | &mut grid, |
| 2945 | sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), |
| 2946 | BLOCK, |
| 2947 | mi_cols, |
| 2948 | mi_rows, |
| 2949 | &mut y, |
| 2950 | &mut u, |
| 2951 | &mut v, |
| 2952 | refpix, |
| 2953 | &sign_bias_table, |
| 2954 | &global_motion, |
| 2955 | base_q_idx, |
| 2956 | TxbSet::Luma32, |
| 2957 | TxbSet::Luma32Inter, |
| 2958 | TxbSet::Chroma16, |
| 2959 | TX32, |
| 2960 | TX16, |
| 2961 | scan32, |
| 2962 | scan16, |
| 2963 | 3, |
| 2964 | allow_high_precision_mv, |
| 2965 | force_integer_mv, |
| 2966 | interp_fixed, |
| 2967 | enable_dual_filter, |
| 2968 | tpl_frame.as_ref(), |
| 2969 | reference_select, |
| 2970 | enable_masked_compound, |
| 2971 | enable_interintra_compound, |
| 2972 | enable_jnt_comp, |
| 2973 | order_hint_bits, |
| 2974 | order_hint, |
| 2975 | ref_order_hints, |
| 2976 | skip_mode_present, |
| 2977 | skip_mode_frame, |
| 2978 | switchable_motion_mode, |
| 2979 | allow_warped_motion, |
| 2980 | true, |
| 2981 | SUB, |
| 2982 | BLOCK, |
| 2983 | allow_screen_content_tools, |
| 2984 | (frame_width as usize, frame_height as usize), |
| 2985 | fctx, |
| 2986 | )?; |
| 2987 | } |
| 2988 | PARTITION_VERT_B => { |
| 2989 | // lane-partab r1: true 16x32 strip on the left + two |
| 2990 | // 16x16 squares on the right (libaom decode_partition |
| 2991 | // PARTITION_VERT_B: left strip, TR, BR). |
| 2992 | hit!(PARTAB_HITS); |
| 2993 | let _vert_ab = crate::encode::Reach::vert_ab_partition(); |
| 2994 | decode_inter_block( |
| 2995 | &mut dec, |
| 2996 | &mut cdfs, |
| 2997 | &mut neighbours, |
| 2998 | &mut grid, |
| 2999 | sub16_to_mi(at), |
| 3000 | BLOCK, |
| 3001 | mi_cols, |
| 3002 | mi_rows, |
| 3003 | &mut y, |
| 3004 | &mut u, |
| 3005 | &mut v, |
| 3006 | refpix, |
| 3007 | &sign_bias_table, |
| 3008 | &global_motion, |
| 3009 | base_q_idx, |
| 3010 | TxbSet::Luma32, |
| 3011 | TxbSet::Luma32Inter, |
| 3012 | TxbSet::Chroma16, |
| 3013 | TX32, |
| 3014 | TX16, |
| 3015 | scan32, |
| 3016 | scan16, |
| 3017 | 3, |
| 3018 | allow_high_precision_mv, |
| 3019 | force_integer_mv, |
| 3020 | interp_fixed, |
| 3021 | enable_dual_filter, |
| 3022 | tpl_frame.as_ref(), |
| 3023 | reference_select, |
| 3024 | enable_masked_compound, |
| 3025 | enable_interintra_compound, |
| 3026 | enable_jnt_comp, |
| 3027 | order_hint_bits, |
| 3028 | order_hint, |
| 3029 | ref_order_hints, |
| 3030 | skip_mode_present, |
| 3031 | skip_mode_frame, |
| 3032 | switchable_motion_mode, |
| 3033 | allow_warped_motion, |
| 3034 | true, |
| 3035 | SUB, |
| 3036 | BLOCK, |
| 3037 | allow_screen_content_tools, |
| 3038 | (frame_width as usize, frame_height as usize), |
| 3039 | fctx, |
| 3040 | )?; |
| 3041 | decode_inter_block( |
| 3042 | &mut dec, |
| 3043 | &mut cdfs, |
| 3044 | &mut neighbours, |
| 3045 | &mut grid, |
| 3046 | sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), |
| 3047 | SUB, |
| 3048 | mi_cols, |
| 3049 | mi_rows, |
| 3050 | &mut y, |
| 3051 | &mut u, |
| 3052 | &mut v, |
| 3053 | refpix, |
| 3054 | &sign_bias_table, |
| 3055 | &global_motion, |
| 3056 | base_q_idx, |
| 3057 | TxbSet::Luma16, |
| 3058 | if reduced_tx_set { |
| 3059 | TxbSet::Luma16Inter |
| 3060 | } else { |
| 3061 | TxbSet::Luma16InterSet1 |
| 3062 | }, |
| 3063 | TxbSet::Chroma8, |
| 3064 | TX16, |
| 3065 | TX8, |
| 3066 | scan16, |
| 3067 | scan8, |
| 3068 | 2, |
| 3069 | allow_high_precision_mv, |
| 3070 | force_integer_mv, |
| 3071 | interp_fixed, |
| 3072 | enable_dual_filter, |
| 3073 | tpl_frame.as_ref(), |
| 3074 | reference_select, |
| 3075 | enable_masked_compound, |
| 3076 | enable_interintra_compound, |
| 3077 | enable_jnt_comp, |
| 3078 | order_hint_bits, |
| 3079 | order_hint, |
| 3080 | ref_order_hints, |
| 3081 | skip_mode_present, |
| 3082 | skip_mode_frame, |
| 3083 | switchable_motion_mode, |
| 3084 | allow_warped_motion, |
| 3085 | false, |
| 3086 | SUB, |
| 3087 | SUB, |
| 3088 | allow_screen_content_tools, |
| 3089 | (frame_width as usize, frame_height as usize), |
| 3090 | fctx, |
| 3091 | )?; |
| 3092 | decode_inter_block( |
| 3093 | &mut dec, |
| 3094 | &mut cdfs, |
| 3095 | &mut neighbours, |
| 3096 | &mut grid, |
| 3097 | sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2 + 1)), |
| 3098 | SUB, |
| 3099 | mi_cols, |
| 3100 | mi_rows, |
| 3101 | &mut y, |
| 3102 | &mut u, |
| 3103 | &mut v, |
| 3104 | refpix, |
| 3105 | &sign_bias_table, |
| 3106 | &global_motion, |
| 3107 | base_q_idx, |
| 3108 | TxbSet::Luma16, |
| 3109 | if reduced_tx_set { |
| 3110 | TxbSet::Luma16Inter |
| 3111 | } else { |
| 3112 | TxbSet::Luma16InterSet1 |
| 3113 | }, |
| 3114 | TxbSet::Chroma8, |
| 3115 | TX16, |
| 3116 | TX8, |
| 3117 | scan16, |
| 3118 | scan8, |
| 3119 | 2, |
| 3120 | allow_high_precision_mv, |
| 3121 | force_integer_mv, |
| 3122 | interp_fixed, |
| 3123 | enable_dual_filter, |
| 3124 | tpl_frame.as_ref(), |
| 3125 | reference_select, |
| 3126 | enable_masked_compound, |
| 3127 | enable_interintra_compound, |
| 3128 | enable_jnt_comp, |
| 3129 | order_hint_bits, |
| 3130 | order_hint, |
| 3131 | ref_order_hints, |
| 3132 | skip_mode_present, |
| 3133 | skip_mode_frame, |
| 3134 | switchable_motion_mode, |
| 3135 | allow_warped_motion, |
| 3136 | false, |
| 3137 | SUB, |
| 3138 | SUB, |
| 3139 | allow_screen_content_tools, |
| 3140 | (frame_width as usize, frame_height as usize), |
| 3141 | fctx, |
| 3142 | )?; |
| 3143 | } |
| 3144 | PARTITION_HORZ_4 | PARTITION_VERT_4 => { |
| 3145 | // lane-inter4 r1: four 32x8 / 8x32 inter strips, |
| 3146 | // `quarter_step` = 2 mi -- the arm ReelC's first inter |
| 3147 | // frame stops at (`value=9` = PARTITION_VERT_4). |
| 3148 | // `at` is in 16-px cells and cannot name an 8-px |
| 3149 | // offset, which is why `decode_inter_block` takes mi |
| 3150 | // coordinates now. |
| 3151 | let horz = part32 == PARTITION_HORZ_4; |
| 3152 | let base_mi = (at.0 * (SUB / MI), at.1 * (SUB / MI)); |
| 3153 | let (bw, bh) = if horz { (32usize, 8usize) } else { (8, 32) }; |
| 3154 | for i in 0..4 { |
| 3155 | let strip_mi = if horz { |
| 3156 | (base_mi.0 + i * 2, base_mi.1) |
| 3157 | } else { |
| 3158 | (base_mi.0, base_mi.1 + i * 2) |
| 3159 | }; |
| 3160 | if i > 0 |
| 3161 | && (strip_mi.0 >= mi_rows as usize |
| 3162 | || strip_mi.1 >= mi_cols as usize) |
| 3163 | { |
| 3164 | break; |
| 3165 | } |
| 3166 | inter_piece!( |
| 3167 | strip_mi, |
| 3168 | BLOCK, |
| 3169 | TxbSet::Luma32, |
| 3170 | TxbSet::Luma32Inter, |
| 3171 | TxbSet::Chroma16, |
| 3172 | TX32, |
| 3173 | TX16, |
| 3174 | &scan32, |
| 3175 | &scan16, |
| 3176 | 3, |
| 3177 | bw, |
| 3178 | bh |
| 3179 | ); |
| 3180 | if horz { |
| 3181 | hit!(RECT4_32_HORZ_INTER_HITS); |
| 3182 | } else { |
| 3183 | hit!(RECT4_32_VERT_INTER_HITS); |
| 3184 | } |
| 3185 | } |
| 3186 | } |
| 3187 | _ => { |
| 3188 | return Err(unsupported(format!( |
| 3189 | "an INTER 32x32 partition type this decoder does not code (value={part32})" |
| 3190 | ))); |
| 3191 | } |
| 3192 | } |
| 3193 | } |
| 3194 | } |
| 3195 | } |
| 3196 | wave::finish_tile(fctx, refpix, [&mut y, &mut u, &mut v]); |
| 3197 | // lane-timeline: this tile's last symbol is read here. |
| 3198 | crate::timeline::tile_done(); |
| 3199 | |
| 3200 | if tile_num == tile_info.context_update_tile_id { |
| 3201 | result_cdfs = cdfs; |
| 3202 | } |
| 3203 | } |
| 3204 | refpix.take_err()?; |
| 3205 | crate::timeline::recon_done(); |
| 3206 | // lane-twostage: the motion field is built from the mode-info grid alone |
| 3207 | // (no pixel), so it moves up here with the CDFs -- everything a |
| 3208 | // consuming frame's SETUP needs, published before this frame's filters. |
| 3209 | let mut motion_field = Some(build_motion_field( |
| 3210 | &grid, |
| 3211 | mi_cols as usize, |
| 3212 | mi_rows as usize, |
| 3213 | order_hint, |
| 3214 | order_hint_bits, |
| 3215 | ref_order_hints, |
| 3216 | fctx, |
| 3217 | )); |
| 3218 | if let Some(stage1) = stage1 |
| 3219 | && superres(fctx).is_none() |
| 3220 | { |
| 3221 | stage1( |
| 3222 | result_cdfs.clone(), |
| 3223 | motion_field |
| 3224 | .take() |
| 3225 | .expect("the motion field was just built"), |
| 3226 | frame_width as usize, |
| 3227 | frame_height as usize, |
| 3228 | ); |
| 3229 | } |
| 3230 | |
| 3231 | // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's |
| 3232 | // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against |
| 3233 | // that isolate whether a decode-order frame's mismatch already exists |
| 3234 | // in reconstruction (this dump) vs is introduced by the loop filter |
| 3235 | // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump). |
| 3236 | // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders. |
| 3237 | if crate::envflags::env_flag!("EC_OBMC") |
| 3238 | || crate::envflags::env_flag!("EC_TRACE_MODE") |
| 3239 | || crate::envflags::env_flag!("EC_PRED") |
| 3240 | { |
| 3241 | eprintln!( |
| 3242 | "EC_PICT idx={}", |
| 3243 | PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst) |
| 3244 | ); |
| 3245 | } |
| 3246 | dump_stage16( |
| 3247 | "EC_AV1_PREFILT_DUMP16", |
| 3248 | &y, |
| 3249 | &u, |
| 3250 | &v, |
| 3251 | frame_width as usize, |
| 3252 | frame_height as usize, |
| 3253 | ss_x(fctx), |
| 3254 | ss_y(fctx), |
| 3255 | ); |
| 3256 | census_unwritten(&y, &u, &v); |
| 3257 | if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { |
| 3258 | // lane-av1dumploud: loud on a short write (see the key-frame twin |
| 3259 | // above -- same file, same shape, same three planes). |
| 3260 | let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| 3261 | let narrow = |p: &PlaneBuf<'_>| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() }; |
| 3262 | crate::dumpio::write_planes( |
| 3263 | "EC_AV1_PREFILT_DUMP", |
| 3264 | format!("{path}.f{idx}"), |
| 3265 | &[&narrow(&y), &narrow(&u), &narrow(&v)], |
| 3266 | ); |
| 3267 | } else { |
| 3268 | PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| 3269 | } |
| 3270 | // lane-av1444edge: the inter-frame path's mi-aligned pre-loop-filter |
| 3271 | // dump, the rung the key-frame path has always had (see |
| 3272 | // `dump_prefilter_wide`). Placed beside the padded `EC_AV1_PREFILT_DUMP` |
| 3273 | // above, i.e. before the loop filters run, so the two agree on the point |
| 3274 | // in the sequence they sample. |
| 3275 | dump_prefilter_wide(&y, &u, &v); |
| 3276 | // lane-av1fwd: the encoder scores ~25 filter candidates against this |
| 3277 | // same coded tile ([`FilterReplay`]). Capture the reconstruction here, |
| 3278 | // before either filter has touched it -- but only on the shape whose |
| 3279 | // tail is exactly `apply_deblock` + `apply_cdef` and nothing else. |
| 3280 | if !lr_active && superres(fctx).is_none() { |
| 3281 | capture_filter_replay( |
| 3282 | &y, |
| 3283 | &u, |
| 3284 | &v, |
| 3285 | &neighbours, |
| 3286 | frame_width as usize, |
| 3287 | frame_height as usize, |
| 3288 | width, |
| 3289 | height, |
| 3290 | true_width, |
| 3291 | true_height, |
| 3292 | ); |
| 3293 | } |
| 3294 | apply_deblock( |
| 3295 | &mut y, |
| 3296 | &mut u, |
| 3297 | &mut v, |
| 3298 | loop_filter, |
| 3299 | &neighbours, |
| 3300 | frame_width as usize, |
| 3301 | frame_height as usize, |
| 3302 | fctx, |
| 3303 | ); |
| 3304 | // lane-perf4: loop restoration is the only reader of the pre-CDEF planes, |
| 3305 | // and a frame that restores nothing copied every plane twice for nothing |
| 3306 | // (three `PlaneBuf` clones here plus the `cdef.to_vec()` inside |
| 3307 | // [`crate::restoration::apply_loop_restoration_plane`], which returns its |
| 3308 | // input unchanged when the plane's type is `None`). Clone only when some |
| 3309 | // plane actually restores. |
| 3310 | let deblocked = lr_active.then(|| { |
| 3311 | ( |
| 3312 | plane_snapshot(&y, 0), |
| 3313 | plane_snapshot(&u, ss_y(fctx) as u32), |
| 3314 | plane_snapshot(&v, ss_y(fctx) as u32), |
| 3315 | ) |
| 3316 | }); |
| 3317 | // lane-tiny r4: post-deblock / post-CDEF dumps mirroring aomdec's own |
| 3318 | // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter |
| 3319 | // dump above these bisect WHICH filter stage introduced a mismatch. |
| 3320 | dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v); |
| 3321 | dump_stage16( |
| 3322 | "EC_AV1_POSTDEBLOCK_DUMP16", |
| 3323 | &y, |
| 3324 | &u, |
| 3325 | &v, |
| 3326 | frame_width as usize, |
| 3327 | frame_height as usize, |
| 3328 | ss_x(fctx), |
| 3329 | ss_y(fctx), |
| 3330 | ); |
| 3331 | apply_cdef( |
| 3332 | &mut y, |
| 3333 | &mut u, |
| 3334 | &mut v, |
| 3335 | cdef, |
| 3336 | &neighbours, |
| 3337 | (frame_width as usize, frame_height as usize), |
| 3338 | fctx, |
| 3339 | None, |
| 3340 | None, |
| 3341 | ); |
| 3342 | dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); |
| 3343 | dump_stage16( |
| 3344 | "EC_AV1_POSTCDEF_DUMP16", |
| 3345 | &y, |
| 3346 | &u, |
| 3347 | &v, |
| 3348 | frame_width as usize, |
| 3349 | frame_height as usize, |
| 3350 | ss_x(fctx), |
| 3351 | ss_y(fctx), |
| 3352 | ); |
| 3353 | capture_stages(&y, &u, &v, deblocked.as_ref(), fctx); |
| 3354 | // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called |
| 3355 | // between `av1_cdef_frame` and `av1_loop_restoration_filter_frame`): |
| 3356 | // the horizontal upscale runs HERE -- after CDEF, before loop |
| 3357 | // restoration, not after the whole filter chain. Both the post-CDEF |
| 3358 | // frame and the post-deblock frame that LR substitutes at its stripe |
| 3359 | // boundaries are upscaled (`save_deblock_boundary_lines` runs |
| 3360 | // `av1_upscale_normative_rows` over its saved rows when the frame is |
| 3361 | // scaled), so every LR coordinate from here on is in upscaled space. |
| 3362 | let mut deblocked = deblocked; |
| 3363 | let mut lr_w = frame_width as usize; |
| 3364 | if let Some((upscaled_w, _)) = superres(fctx) { |
| 3365 | let bd = u32::from(bit_depth(fctx)); |
| 3366 | let (uw, fw, fh) = ( |
| 3367 | upscaled_w as usize, |
| 3368 | frame_width as usize, |
| 3369 | frame_height as usize, |
| 3370 | ); |
| 3371 | let up = |p: &PlaneBuf<'_>, in_w: usize, in_h: usize, out_w: usize| PlaneBuf { |
| 3372 | data: std::borrow::Cow::Owned(crate::superres::upscale_plane_strided( |
| 3373 | &p.data, |
| 3374 | p.width, |
| 3375 | in_w, |
| 3376 | in_h, |
| 3377 | p.true_width, |
| 3378 | out_w, |
| 3379 | bd, |
| 3380 | )), |
| 3381 | width: out_w, |
| 3382 | height: in_h, |
| 3383 | true_width: out_w, |
| 3384 | true_height: in_h, |
| 3385 | tile_x0: 0, |
| 3386 | tile_y0: 0, |
| 3387 | tile_x1: out_w, |
| 3388 | tile_y1: in_h, |
| 3389 | plane: p.plane, |
| 3390 | }; |
| 3391 | let (cw, ch, cuw) = ( |
| 3392 | round_ss(fw, ss_x(fctx)), |
| 3393 | round_ss(fh, ss_y(fctx)), |
| 3394 | round_ss(uw, ss_x(fctx)), |
| 3395 | ); |
| 3396 | y = up(&y, fw, fh, uw); |
| 3397 | u = up(&u, cw, ch, cuw); |
| 3398 | v = up(&v, cw, ch, cuw); |
| 3399 | if let Some((dy, du, dv)) = deblocked.take() { |
| 3400 | deblocked = Some(( |
| 3401 | up(&dy, fw, fh, uw), |
| 3402 | up(&du, cw, ch, cuw), |
| 3403 | up(&dv, cw, ch, cuw), |
| 3404 | )); |
| 3405 | } |
| 3406 | lr_w = uw; |
| 3407 | crate::superres::note_upscaled_picture(); |
| 3408 | } |
| 3409 | if let Some((deblocked_y, deblocked_u, deblocked_v)) = &deblocked { |
| 3410 | apply_loop_restoration( |
| 3411 | &mut y, |
| 3412 | &mut u, |
| 3413 | &mut v, |
| 3414 | deblocked_y, |
| 3415 | deblocked_u, |
| 3416 | deblocked_v, |
| 3417 | lr, |
| 3418 | &lr_grid, |
| 3419 | (lr_w, frame_height as usize), |
| 3420 | fctx, |
| 3421 | ); |
| 3422 | } |
| 3423 | if let Some((db_y, db_u, db_v)) = deblocked { |
| 3424 | // LIFO pool: return in reverse so the next frame's `y`/`u`/`v` |
| 3425 | // snapshots pop buffers of their own size and never resize. |
| 3426 | scratch_return(db_v.data.into_owned()); |
| 3427 | scratch_return(db_u.data.into_owned()); |
| 3428 | scratch_return(db_y.data.into_owned()); |
| 3429 | } |
| 3430 | |
| 3431 | crate::timeline::filters_done(); |
| 3432 | |
| 3433 | let (fw, fh) = (lr_w, frame_height as usize); |
| 3434 | // An upscaled frame is already at its final size with no mi-aligned |
| 3435 | // margin beyond it (the upscale consumed those columns), so the |
| 3436 | // wide-margin stash below has nothing left to hand out. |
| 3437 | let (true_width, true_height) = if superres(fctx).is_some() { |
| 3438 | (fw, fh) |
| 3439 | } else { |
| 3440 | (true_width, true_height) |
| 3441 | }; |
| 3442 | if fw == width && fh == height { |
| 3443 | fctx.last_frame_wide_margin.with(|m| *m.borrow_mut() = None); |
| 3444 | return Ok(( |
| 3445 | Picture { |
| 3446 | width, |
| 3447 | height, |
| 3448 | y: y.data.into_owned(), |
| 3449 | u: u.data.into_owned(), |
| 3450 | v: v.data.into_owned(), |
| 3451 | }, |
| 3452 | result_cdfs, |
| 3453 | motion_field, |
| 3454 | )); |
| 3455 | } |
| 3456 | let crop = |plane: &PlaneBuf<'_>, w: usize, h: usize| -> Vec<u16> { |
| 3457 | let mut out = Vec::with_capacity(w * h); |
| 3458 | for row in 0..h { |
| 3459 | out.extend(plane.data[row * plane.width..][..w].iter().copied()); |
| 3460 | } |
| 3461 | out |
| 3462 | }; |
| 3463 | // lane-superres r10 (fixed r9): same real-margin stash as |
| 3464 | // `decode_key_frame_tile_with_cdfs` (see that function's comment) -- the |
| 3465 | // real reconstructed extent is the mi-aligned `true_width`/`true_height` |
| 3466 | // (`mi_cols`/`mi_rows` * 4), NOT the superblock-padded `width`/`height` |
| 3467 | // this branch was reading before: columns `[true_width, width)` were |
| 3468 | // never actually coded (the last partial superblock stops at |
| 3469 | // `true_width`), so stashing out to `width` handed the chroma upscale's |
| 3470 | // right-edge replicate a slice of uninitialized/stale buffer one column |
| 3471 | // early -- the same shorten-vs-replicate shape as `av1-truesize`. The |
| 3472 | // key-frame branch above already used `true_width`/`true_height`; this |
| 3473 | // just matches it. |
| 3474 | fctx.last_frame_wide_margin.with(|m| { |
| 3475 | *m.borrow_mut() = if true_width > fw || true_height > fh { |
| 3476 | Some(Picture { |
| 3477 | width: true_width, |
| 3478 | height: true_height, |
| 3479 | y: crop(&y, true_width, true_height), |
| 3480 | u: crop( |
| 3481 | &u, |
| 3482 | round_ss(true_width, ss_x(fctx)), |
| 3483 | round_ss(true_height, ss_y(fctx)), |
| 3484 | ), |
| 3485 | v: crop( |
| 3486 | &v, |
| 3487 | round_ss(true_width, ss_x(fctx)), |
| 3488 | round_ss(true_height, ss_y(fctx)), |
| 3489 | ), |
| 3490 | }) |
| 3491 | } else { |
| 3492 | None |
| 3493 | } |
| 3494 | }); |
| 3495 | Ok(( |
| 3496 | Picture { |
| 3497 | width: fw, |
| 3498 | height: fh, |
| 3499 | y: crop_owned(y, fw, fh), |
| 3500 | u: crop_owned(u, round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx))), |
| 3501 | v: crop_owned(v, round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx))), |
| 3502 | }, |
| 3503 | result_cdfs, |
| 3504 | motion_field, |
| 3505 | )) |
| 3506 | } |