forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

inter_block8.rs3024 lines, 131.8 KiBHistoryRawDownload
1//! Inter-block helpers for the 8x8-leaf and sub-8x8 stamping paths: the grid stamp
2//! for a rect sub-8x8 leaf and the 8x8 inter leaf decoder. Moved out of `decode/mod.rs`
3//! (av1split D6); the items are unchanged apart from `pub(super)` visibility.
4
5use super::*;
6
7/// Stamps one sub-8x8 inter leaf into every mi cell of its true `w_mi`x`h_mi`
8/// footprint (class: a rect block's grid span is its own, never a square guess).
9// Signature mirrors the spec's per-call inputs; a parameter struct would only move them.
10#[allow(clippy::too_many_arguments)]
11pub(super) fn grid_stamp_rect(
12 grid: &mut MiGrid,
13 mi_row: usize,
14 mi_col: usize,
15 w_mi: usize,
16 h_mi: usize,
17 ref_frame: i8,
18 mv: (i32, i32),
19 is_new_mv: bool,
20) {
21 grid.fill_rect(
22 mi_row,
23 mi_col,
24 h_mi,
25 w_mi,
26 MiInfo {
27 is_inter: true,
28 ref_frame,
29 ref_frame1: NO_REF1,
30 mv1: (0, 0),
31 mv: mv16(mv),
32 is_new_mv,
33 size: w_mi as u8,
34 size_h: h_mi as u8,
35 is_global_mv0: false,
36 is_global_mv1: false,
37 },
38 );
39}
40
41/// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block
42/// (lane-av1inter8), mirroring [`crate::tile::write_inter_frame_leaf8`]'s
43/// exact symbol order: its own skip flag, intra/inter choice and (when
44/// inter) `NEARESTMV`/`NEWMV` chain against this leaf's own 2x2-mi mv-stack
45/// window, or (when intra) `Y_MODE`, then its own luma and two chroma
46/// transform blocks through [`TxbSet::Luma8Inter`]/[`TxbSet::Chroma4`],
47/// same as [`decode_leaf8`]'s coefficient layer but with
48/// motion-compensated prediction instead of intra prediction when inter.
49/// `outer_at` (in [`SUB`]-grid units) is the enclosing 16x16 slot's
50/// skip/intra-inter context, overridden by `prev_leaf` exactly as
51/// [`decode_leaf8`] overrides mode context: `Neighbours`' above/left arrays
52/// only resolve to [`SUB`] granularity. Hands back this leaf's own skip flag
53/// and intra/inter choice, for the next leaf or the caller's final
54/// write-back.
55#[allow(clippy::too_many_arguments)]
56pub(super) fn decode_inter_block8(
57 dec: &mut SymbolDecoder,
58 cdfs: &mut Cdfs,
59 neighbours: &mut Neighbours,
60 grid: &mut MiGrid,
61 mi_cols: u32,
62 mi_rows: u32,
63 outer_at: (usize, usize),
64 leaf_mi: (usize, usize),
65 y: &mut PlaneBuf<'static>,
66 u: &mut PlaneBuf<'static>,
67 v: &mut PlaneBuf<'static>,
68 refpix: &RefPix<'_>,
69 base_q_idx: u8,
70 scan8: &[u16],
71 scan4: &[u16],
72 allow_high_precision_mv: bool,
73 force_integer_mv: bool,
74 // lane-gmaffine r1: this frame header's own `global_motion` table (spec
75 // 5.9.24), indexed `[ref_frame - LAST_FRAME]` -- same table
76 // [`decode_inter_block`] takes, threaded here so the 8x8 leaf can code
77 // `GLOBALMV` (`gm_get_motion_vector`), fill its mv stack's missing
78 // candidates with the gm mv (gm r6's root cause) and build a global
79 // warp prediction.
80 global_motion: &[ec_av1_syntax::WarpParams; 7],
81 // lane-gmaffine r1: this sequence header's own `enable_dual_filter` bit,
82 // for the leaf's own `read_mb_interp_filter` below.
83 enable_dual_filter: bool,
84 // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path
85 // only ever tracks a coarse `LAST_FRAME`-or-intra neighbour shape (no
86 // per-leaf `above_ref`/`left_ref` array exists here), so `comp_mode`'s
87 // context uses that same approximation.
88 reference_select: bool,
89 enable_masked_compound: bool,
90 // lane-sb128 r4: see [`decode_inter_block`]'s own doc -- `BLOCK_8X8` is
91 // always `is_interintra_allowed_bsize`-eligible, so this leaf's own gate
92 // drops the `side` check entirely.
93 enable_interintra_compound: bool,
94 enable_jnt_comp: bool,
95 order_hint_bits: u32,
96 order_hint: u32,
97 ref_order_hints: [u32; 7],
98 // lane-av1comp round 14: see [`decode_inter_block`]'s own doc -- this
99 // leaf has no per-leaf `above_skip_mode`/`left_skip_mode` array either,
100 // so its `skip_mode` context reuses the same [`SUB`]-grid
101 // `above_skip_mode[cmi]`/`left_skip_mode[rmi]` the enclosing 16x16 slot
102 // tracks (mirroring `above_skip`/`left_skip`'s own leaf approximation
103 // just above).
104 skip_mode_present: bool,
105 skip_mode_frame: [u8; 2],
106 // lane-cdffwd2: this frame header's own `reduced_tx_set` bit -- see
107 // [`decode_inter_frame_tile_with_cdfs`]'s own doc.
108 reduced_tx_set: bool,
109 // lane-motionmode round 3: this frame header's own `is_motion_mode_switchable`/
110 // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`), plus
111 // the fixed/switchable interp filter kind `obmc_blend`'s own neighbour
112 // reads need (see [`decode_inter_block`]'s own doc) -- this leaf's own
113 // prediction is always `Regular` (documented corner-cut, `mc::predict`
114 // has no filter param), but an OBMC neighbour can be a real 16x16+
115 // block that DID resolve a switchable filter.
116 interp_fixed: Option<mc::InterpFilterKind>,
117 switchable_motion_mode: bool,
118 allow_warped_motion: bool,
119 // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a
120 // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16
121 // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own
122 // `compound_ctx` local, just handed back instead of applied here (this
123 // fn's `neighbours` recording happens once for the whole straddling
124 // 16x16 block, after every leaf).
125 // lane-screen r2: see [`decode_inter_block`]'s own copy of this param --
126 // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`-
127 // eligible (`bsize >= BLOCK_8X8`).
128 allow_screen_content_tools: bool,
129 // lane-inter8 r1: the leaf's mv stacks used to be built without the
130 // frame's sign-bias table (`NO_SIGN_BIAS`), while [`decode_inter_block`]
131 // one level up passed it -- it changes the candidate list and with it
132 // `new_mv_ctx`/`ref_mv_ctx`, `drl_ctx` and the number of symbols read.
133 // Measured: an 8x8 compound NEAR_NEWMV leaf desynced against aomdec's
134 // EC_MODE ladder at exactly this block (mi 4,14 of the mandelbrot
135 // 8x8-split gate).
136 sign_bias_table: &SignBiasTable,
137 // lane-inter8 r2: the frame's temporal mv field (spec 7.10.2.8), which
138 // [`decode_inter_block`] one level up has always passed and this leaf
139 // passed `None` for -- a `use_ref_frame_mvs` frame's stack then holds
140 // fewer candidates here than in the reference decoder, which changes the
141 // mode contexts AND the number of `drl_mode` bits read (class parsed
142 // then discarded).
143 tpl_frame: Option<&TplFrameArgs>,
144 // lane-scaledref r1: this frame's own coded luma width (spec 7.11.3.3),
145 // for the scaled-reference MC this leaf's own single-ref/compound/OBMC
146 // predictions take when a stored reference was coded at another width
147 // (`use_superres`) -- mirrors [`decode_inter_block`]'s own param.
148 frame_size: (usize, usize),
149 fctx: &crate::decode::FrameCtx,
150) -> Result<(
151 bool,
152 bool,
153 bool,
154 Option<(i8, i8, u8, u8)>,
155 [u8; 2],
156 (i8, Option<i8>),
157)> {
158 // Round 27: this is the function whose mode read carries the block's real
159 // mi (the `EC_MODE_VAL8` rung prints it). The `decode_inter_block`
160 // entry sets the same label from ITS `at`, which is a different block --
161 // publishing from here is what makes the EC_SYMR mi trustworthy on the
162 // inter path, which is what round 22 got wrong by assuming it was not.
163 crate::msac::SymbolDecoder::set_symr_phase("inter8");
164 crate::msac::SymbolDecoder::set_symr_mi(leaf_mi.0 as i64, leaf_mi.1 as i64);
165 const LAST_FRAME: i8 = 1;
166 // lane-gmaffine r2: the leaf's OWN switchable-filter symbols, handed back
167 // so the caller stamps them into `Neighbours` instead of the `[3, 3]`
168 // placeholder. `[3, 3]` is the "intra neighbour, no filter" sentinel: an
169 // OBMC blend that picks such a neighbour up feeds it to
170 // `neighbour_filter`, which PANICS on it (`from_switchable_symbol`) --
171 // that was the warp gate's crash, not an entropy desync. Stays `[3, 3]`
172 // on the intra and compound paths.
173 let mut leaf_filter_syms = [3u8; 2];
174 // lane-gmaffine r1: this leaf's GLOBALMV vector AND the mv stack's
175 // missing-candidate fallback both come from the frame's global motion
176 // evaluated at THIS block's centre (gm r6's root cause).
177 let gm_table = build_gm_mv_table(
178 global_motion,
179 leaf_mi.0,
180 leaf_mi.1,
181 2,
182 2,
183 allow_high_precision_mv,
184 force_integer_mv,
185 );
186 /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`).
187 const SIZE_GROUP_8: usize = 1;
188
189 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
190 let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
191 // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took
192 // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) --
193 // read back by the luma residual read and the tail's neighbour/loop-filter
194 // bookkeeping. Always `false` outside a `TxMode::Select` inter frame.
195 let split8;
196 const SIDE: usize = 8;
197 // lane-av1-444 / lane-av1-422sub8rect: this 8x8 leaf's chroma plane block
198 // is `ss_size_lookup[BLOCK_8X8][ss_x][ss_y]` -- 4:2:0 BLOCK_4X4 (one
199 // TX_4X4 unit), 4:4:4 BLOCK_8X8 (ONE TX_8X8 unit, `av1_get_max_uv_txsize`
200 // at ss 0/0, measured against aomdec's EC_COEFF on `av1-profile1-444.ivf`
201 // frame 1), and 4:2:2 BLOCK_4X8 (ONE TX_4X8 RECT unit per plane, measured
202 // on the pinned t422 fixture: frame 1 mi(0,0) reads plane 1 tx_size 5 ==
203 // TX_4X8 at rng 55168 right after the agreed luma TX_8X8 txb_skip -- the
204 // old `SIDE >> ss_x` square read was the first-divergence defect this
205 // port fixes).
206 let chroma_w: usize = SIDE >> ss_x(fctx);
207 let chroma_h: usize = SIDE >> ss_y(fctx);
208 let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0;
209 let (chroma_set, chroma_scan): (TxbSet, &[u16]) = if chroma_422 {
210 // `get_txsize_entropy_ctx(TX_4X8)`: the rect fills its plane block,
211 // so the tables are the rect set and the SCAN_4X8 walk, exactly the
212 // pairing the key-frame BLOCK_4X8 arm (`decode_block`'s lane-av1-422f
213 // table) reads byte-exact.
214 (TxbSet::ChromaRect8x4, &SCAN_4X8[..])
215 } else if chroma_w == 8 {
216 (TxbSet::Chroma8, scan8)
217 } else {
218 (TxbSet::Chroma4, scan4)
219 };
220 let chroma_tx = if chroma_w == 8 { TX8 } else { TX4 };
221
222 let (r, c) = outer_at;
223 // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's --
224 // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the
225 // left column of a 16x16's second leaf ROW is the previous 16x16 block's
226 // bottom leaf, neither of which a SUB-grid slot can name.
227 let (rmi, cmi) = leaf_mi;
228 // lane-inter8 r2: no sibling-leaf override any more -- each leaf stamps
229 // its own 2x2-mi span into the bands right after it decodes (the caller's
230 // `record_inter_rect_mi`), so a plain mi read already names the correct
231 // neighbour, including one belonging to the previous 16x16 block.
232 let above_skip = neighbours.above_skip[cmi];
233 let left_skip = neighbours.left_skip[rmi];
234 let above_inter = neighbours.above_inter[cmi];
235 let left_inter = neighbours.left_inter[rmi];
236 let above_ref0 = neighbours.above_ref[cmi];
237 let above_ref1 = neighbours.above_ref1[cmi];
238 let left_ref0 = neighbours.left_ref[rmi];
239 let left_ref1 = neighbours.left_ref1[rmi];
240 let skip_mode_ctx =
241 usize::from(neighbours.above_skip_mode[cmi]) + usize::from(neighbours.left_skip_mode[rmi]);
242 // Same two `inter_segment_id` positions as [`decode_inter_block`]; this
243 // leaf is always `BLOCK_8X8`, i.e. 2x2 mi.
244 inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, false, true, fctx);
245 let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
246 if skip_mode {
247 hit!(SKIP_MODE_HITS);
248 }
249
250 let skip_ctx = usize::from(above_skip) + usize::from(left_skip);
251 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
252 inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, skip, false, fctx);
253 maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, (2, 2), skip, fctx);
254 // Always a `BLOCK_8X8` leaf here, never the whole superblock.
255 maybe_read_delta_q(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip, fctx);
256 maybe_read_delta_lf(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip, fctx);
257
258 let (has_above, has_left) = (
259 leaf_mi.0 > neighbours.tile_row0_mi,
260 leaf_mi.1 > neighbours.tile_col0_mi,
261 );
262 let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
263 let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
264 // lane-inter8 r1: mirrors the oracle's `EC_MODE` (instrument rung 4,
265 // `read_inter_block_mode_info`) so an 8x8 leaf's mode-info range ladder
266 // diffs line for line against a real aomdec.
267 if crate::envflags::env_flag!("EC_TRACE_MODE") {
268 eprintln!(
269 "EC_MODE mi_row={} mi_col={} rng={}",
270 leaf_mi.0,
271 leaf_mi.1,
272 dec.debug_state().0
273 );
274 }
275
276 let mode_for_tx;
277 // lane-uv8 r1: this leaf's chroma prediction mode (`get_uv_mode` of the
278 // coded `uv_mode`), for the neighbour bands at the tail. An INTER leaf
279 // stores `UV_DC_PRED`, exactly as [`decode_inter_block`] one level up.
280 let mut uv_predict_mode = DC_PRED;
281 let (luma_grid, u_grid, v_grid);
282 // lane-av1-llinter: set when a lossless 4:4:4 leaf's chroma went through
283 // the per-unit walk (`read_inter_chroma_lossless`) -- the walk stamps each
284 // TX_4X4 unit's own coefficient context, so the tail's whole-block
285 // `record_mi` gets its chroma half saved/restored around, exactly like
286 // `saved_luma_ctx` does for a `split8` luma.
287 let mut chroma_stamped_per_unit = false;
288 let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None;
289 // lane-inter8 r1: this leaf's own resolved references, handed back so the
290 // NEXT leaf of the same 16x16 can use them as its real above/left
291 // neighbour (`Neighbours`' arrays only move once per 16x16 block).
292 // `(0, None)` is intra.
293 let mut leaf_refs: (i8, Option<i8>) = (0, None);
294 // lane-t900 r23: this leaf's own palette state for the neighbour bands
295 // (`(y_size, y_colors, uv_size, uv_colors)`), all-zero for an inter leaf
296 // and for an intra one that codes no palette -- same publication the
297 // >=16 intra-in-inter block makes through [`record_strip_palette`].
298 let mut palette_record8: (usize, [u16; 8], usize, [u16; 8]) = (0, [0u16; 8], 0, [0u16; 8]);
299 if is_inter {
300 if reference_select || skip_mode {
301 // lane-inter8 r1: the REAL neighbour references, not a
302 // `LAST_FRAME`-or-intra stand-in. `av1_get_reference_mode_context`
303 // and `read_compound_ref_frames`' own contexts both ask whether a
304 // neighbour is COMPOUND, so pretending every inter neighbour is
305 // single-ref LAST picked the wrong `comp_mode` CDF row -- measured
306 // as an 8x8 leaf reading single-ref where aomdec read compound
307 // NEAR_NEWMV (mi 4,14).
308 let above_nbr = has_above.then(|| NeighbourRef {
309 is_inter: above_inter,
310 ref0: if above_inter { above_ref0 } else { 0 },
311 ref1: above_ref1,
312 uni: above_ref1.is_some_and(|r1| is_uni_comp_ref(above_ref0, r1)),
313 });
314 let left_nbr = has_left.then(|| NeighbourRef {
315 is_inter: left_inter,
316 ref0: if left_inter { left_ref0 } else { 0 },
317 ref1: left_ref1,
318 uni: left_ref1.is_some_and(|r1| is_uni_comp_ref(left_ref0, r1)),
319 });
320 if skip_mode || read_comp_mode(dec, cdfs, above_nbr, left_nbr) {
321 let (ref0, ref1) = if skip_mode {
322 (skip_mode_frame[0] as i8, skip_mode_frame[1] as i8)
323 } else {
324 // lane-interp3 r2 (class twin-functions-drift): this leaf
325 // passed a hard-coded `LAST_FRAME` for every inter
326 // neighbour -- the old "coarse LAST_FRAME-or-intra"
327 // approximation -- while the side bands have carried the
328 // neighbour's REAL reference per mi since lane-inter8 r2.
329 // Every `av1_collect_neighbors_ref_counts` vote below
330 // (`uni_comp_ref_p1`, `comp_ref`, `comp_bwdref`, ...) was
331 // therefore taken off the wrong CDF row. Same two args
332 // [`decode_inter_block`]'s own compound arm passes
333 // (`-1` when the band is unavailable is start_tile's /
334 // start_row's own reset value, so no `has_above` guard).
335 read_compound_ref_frames(dec, cdfs, above_nbr, left_nbr, above_ref0, left_ref0)
336 };
337 leaf_refs = (ref0, Some(ref1));
338 let (mi_row, mi_col) = leaf_mi;
339 // spec 7.10.2.8, mirroring [`decode_inter_block`]'s own
340 // `comp_tpl` build (`use_ref_frame_mvs` frames only).
341 let comp_tpl = tpl_frame.map(|t| crate::mvstack::CompoundTplArgs {
342 field: t.field,
343 cur_offset_0: crate::motion_field::get_relative_dist(
344 t.order_hint_bits,
345 t.order_hint,
346 t.ref_order_hints[(ref0 - LAST_FRAME) as usize],
347 ),
348 cur_offset_1: crate::motion_field::get_relative_dist(
349 t.order_hint_bits,
350 t.order_hint,
351 t.ref_order_hints[(ref1 - LAST_FRAME) as usize],
352 ),
353 allow_high_precision_mv,
354 force_integer_mv,
355 });
356 // lane-av1comp: this leaf path has neither a real sign-bias
357 // table nor `tpl_frame` (see this function's own doc on the
358 // coarse `LAST_FRAME`-or-intra neighbour approximation
359 // already in force above), matching the plain `find_mv_stack`
360 // (no bias, no tpl) the leaf's single-ref arm below already
361 // uses.
362 let comp_stack = crate::mvstack::find_mv_stack_compound(
363 grid,
364 mi_row,
365 mi_col,
366 2,
367 2,
368 (ref0, ref1),
369 mi_cols as usize,
370 mi_rows as usize,
371 sign_bias_table,
372 &gm_table,
373 comp_tpl,
374 );
375 let compound_mode = if skip_mode {
376 0 // NEAREST_NEARESTMV, forced -- no mode symbol read
377 } else {
378 read_inter_compound_mode(
379 dec,
380 cdfs,
381 comp_stack.new_mv_ctx,
382 comp_stack.ref_mv_ctx,
383 )
384 };
385 if crate::envflags::env_flag!("EC_TRACE_MODE") {
386 eprintln!(
387 "EC_LEAFMODE mi_row={} mi_col={} cmode={} stack={} newmv_ctx={} refmv_ctx={} rng={}",
388 leaf_mi.0,
389 leaf_mi.1,
390 compound_mode + 17,
391 comp_stack.entries.len(),
392 comp_stack.new_mv_ctx,
393 comp_stack.ref_mv_ctx,
394 dec.debug_state().0
395 );
396 }
397 let (mv0, mv1) = assign_compound_mv(
398 dec,
399 cdfs,
400 &comp_stack,
401 compound_mode,
402 allow_high_precision_mv,
403 force_integer_mv,
404 // lane-inter8 r1: the real per-ref gm mvs, same as
405 // [`decode_inter_block`]'s own compound arm.
406 (
407 gm_table[(ref0 - LAST_FRAME) as usize],
408 gm_table[(ref1 - LAST_FRAME) as usize],
409 ),
410 fctx,
411 );
412 // lane-inter8 r3: byte-format-identical to the oracle's
413 // rung-4 `EC_MODE_VAL`, so the leaf's mode+mv VALUE ladder
414 // diffs line for line against a real aomdec.
415 if crate::envflags::env_flag!("EC_TRACE_MODE") {
416 eprintln!(
417 "EC_MODE_VAL mi_row={} mi_col={} mode={} ref0={} ref1={} mv0=({},{}) rng={}",
418 leaf_mi.0,
419 leaf_mi.1,
420 compound_mode + 17,
421 ref0,
422 ref1,
423 mv0.0,
424 mv0.1,
425 dec.debug_state().0
426 );
427 }
428
429 // spec 5.11.25: same gating [`decode_inter_block`]'s own
430 // compound arm uses, keyed off `outer_at`'s [`SUB`]-grid
431 // slot -- the only granularity `Neighbours`' comp_group_idx/
432 // compound_idx arrays track.
433 let group_ctx = get_comp_group_idx_context(neighbours, leaf_mi, SIDE);
434 let comp_group_idx = if !skip_mode
435 && enable_masked_compound
436 && is_any_masked_compound_used_here(SIDE, SIDE)
437 {
438 crate::msac::SymbolDecoder::set_symr_cdf("comp_group_idx");
439 dec.symbol(&mut cdfs.comp_group_idx[group_ctx])
440 } else {
441 0
442 };
443 // lane-maskcomp r2 / lane-wedge r3: see the 16x16/32x32
444 // leaf's own comment.
445 let mut diffwtd_mask_type: Option<u8> = None;
446 let mut wedge_mask: Option<&'static [u8]> = None;
447 if comp_group_idx == 1 {
448 // lane-maskcomp r1: see the 16x16 leaf's own comment
449 // above -- SIDE==8 here, `wedge_bsize` index 3
450 // (BLOCK_8X8, `wedge_types > 0`).
451 let compound_type = dec.symbol(&mut cdfs.compound_type[3]);
452 if compound_type == 0 {
453 // COMPOUND_WEDGE: lane-wedge r3, see the 16x16/32x32
454 // leaf's own comment.
455 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]);
456 let wedge_sign = dec.literal(1);
457 hit!(WEDGE_HITS);
458 wedge_mask = Some(
459 crate::wedge::wedge_masks()
460 .codebook(SIDE, SIDE)
461 .mask(wedge_sign as usize, wedge_index),
462 );
463 } else {
464 let mask_type = dec.literal(1);
465 diffwtd_mask_type = Some(mask_type as u8);
466 }
467 hit!(MASKED_COMPOUND_HITS);
468 }
469 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same
470 // reference-slot defect as the 16x16 leaf's own mask above
471 // (r1: falsified as an MC/blend math bug, isolated to a DPB
472 // slot/refresh_frame_flags issue around BWDREF_FRAME) -- see
473 // that comment.
474 // r3: same defect as the 16x16 leaf's own mask above -- see
475 // that comment (compound_idx's decoded value, not the blend
476 // math or reference-slot bookkeeping). r6/r7: same re-mask
477 // as the 16x16 leaf above -- one real bug found and fixed
478 // (mvstack.rs ref_ctx family), a second, still-unfound
479 // compound_idx defect surfaces on the wide gate sweep.
480 // lane-av1idx r1: same re-mask as the 16x16 leaf above --
481 // see that comment.
482 let (fwd_offset, bck_offset, compound_idx) =
483 if comp_group_idx == 0 && !skip_mode && enable_jnt_comp {
484 let idx_ctx = get_comp_index_context(
485 neighbours,
486 leaf_mi,
487 SIDE,
488 order_hint_bits,
489 order_hint,
490 ref_order_hints[(ref0 - LAST_FRAME) as usize],
491 ref_order_hints[(ref1 - LAST_FRAME) as usize],
492 );
493 crate::msac::SymbolDecoder::set_symr_cdf("compound_idx");
494 let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]);
495 if idx == 1 {
496 (8, 8, 1u8)
497 } else {
498 // lane-av1distwtd: the 8x8 leaf's own
499 // distance-weighted arm, same counter as the
500 // 16x16+ site above.
501 hit!(DIST_WTD_COMP_HITS);
502 let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign(
503 order_hint_bits,
504 order_hint,
505 ref_order_hints[(ref0 - LAST_FRAME) as usize],
506 ref_order_hints[(ref1 - LAST_FRAME) as usize],
507 );
508 (fwd, bck, 0u8)
509 }
510 } else {
511 (8, 8, 1u8)
512 };
513 compound_ctx8 = Some((ref0, ref1, comp_group_idx as u8, compound_idx));
514 if crate::envflags::env_flag!("EC_AV1_COMPIDX_DUMP") {
515 eprintln!(
516 "EC_COMPIDX mi_row={mi_row} mi_col={mi_col} bsize=8 mode={compound_mode} mv0=({},{}) mv1=({},{}) ref0={ref0} ref1={ref1} comp_group_idx={comp_group_idx} compound_idx={compound_idx} tell={}",
517 mv0.0,
518 mv0.1,
519 mv1.0,
520 mv1.1,
521 dec.debug_bitpos()
522 );
523 }
524
525 // lane-interp3 r1: `read_mb_interp_filter` (libaom
526 // `decodemv.c` 1575, the tail of
527 // `read_inter_block_mode_info`) runs for EVERY inter block,
528 // compound included, right AFTER `read_compound_type` -- this
529 // leaf read no filter symbol at all, so a SWITCHABLE-filter
530 // stream lost one symbol (two under `enable_dual_filter`) at
531 // every compound 8x8 leaf, and the leaf recorded the `[3, 3]`
532 // "no filter" sentinel, which made a neighbouring OBMC block's
533 // `neighbour_filter` PANIC instead of blending.
534 // `av1_is_interp_needed` suppression terms for this arm:
535 // `skip_mode`, and `is_nontrans_global_motion` (mode
536 // GLOBAL_GLOBALMV with BOTH refs' models non-TRANSLATION) --
537 // WARPED_CAUSAL cannot occur on a compound block.
538 let gm_nontrans_c = compound_mode == 6
539 && global_motion[(ref0 - LAST_FRAME) as usize].model
540 != ec_av1_syntax::WarpModel::Translation
541 && global_motion[(ref1 - LAST_FRAME) as usize].model
542 != ec_av1_syntax::WarpModel::Translation;
543 // spec `get_ref_filter_type`, keyed on this block's ref0 and
544 // matching EITHER of the neighbour's references -- same shape
545 // as [`decode_inter_block`]'s compound arm. Same corner-cut as
546 // this leaf's single-ref arm below: the context comes from the
547 // enclosing 16x16's coarse slot.
548 let above_filter_ctx = if neighbours.above_ref[cmi] == ref0
549 || neighbours.above_ref1[cmi] == Some(ref0)
550 {
551 neighbours.above_filter[cmi]
552 } else {
553 [3, 3]
554 };
555 let left_filter_ctx = if neighbours.left_ref[rmi] == ref0
556 || neighbours.left_ref1[rmi] == Some(ref0)
557 {
558 neighbours.left_filter[rmi]
559 } else {
560 [3, 3]
561 };
562 let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
563 dec,
564 cdfs,
565 interp_fixed,
566 enable_dual_filter,
567 gm_nontrans_c || skip_mode,
568 above_filter_ctx,
569 left_filter_ctx,
570 true,
571 );
572 leaf_filter_syms = resolved_filter;
573 if interp_fixed.is_none() && !(gm_nontrans_c || skip_mode) {
574 hit!(COMPOUND8_FILTER_HITS);
575 }
576
577 // lane-defer8: both slots' SIZES at parse, pictures in the closure.
578 let scale0 = scale_of(ref_dims(ref0, refpix)?, frame_size);
579 let scale1 = scale_of(ref_dims(ref1, refpix)?, frame_size);
580 if !scale0.is_unscaled() || !scale1.is_unscaled() {
581 hit!(SCALED_COMPOUND_HITS);
582 hit!(SCALED_BLOCK8_HITS);
583 }
584
585 // lane-interp3 r2 (class twin-functions-drift): both slots
586 // used to be stamped `false`, while [`decode_inter_block`]'s
587 // compound arm computes libaom's PER-SLOT `is_global_mv_block`
588 // (blockd.h:421-429 -- mode GLOBAL_GLOBALMV, block >= 8x8
589 // (always true for this leaf) and THAT slot's own gm model >
590 // TRANSLATION). A neighbour carrying the flag makes
591 // `setup_ref_mv_list` substitute the READER's global mv for
592 // the neighbour's stored one, so a cleared flag fed the next
593 // block's stack a stored mv where libaom has the global
594 // candidate -- a wrong mv stack, wrong mode contexts, and a
595 // desync one block later.
596 let is_globalmv_c = compound_mode == 6;
597 let is_global_mv0_c =
598 is_globalmv_c && global_motion[(ref0 - LAST_FRAME) as usize].model as u8 > 1;
599 let is_global_mv1_c =
600 is_globalmv_c && global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1;
601 // lane-interp3 r3 (class twin-functions-drift, second
602 // instance): libaom applies `allow_warp`'s GLOBAL branch
603 // (`reconinter.c:33-55`, reached from `av1_init_warp_params`
604 // inside `build_inter_predictors_8x8_and_bigger`'s per-`ref`
605 // loop) to EVERY `is_global_mv_block` slot, compound
606 // included and independently of `motion_mode` -- the 16x16+
607 // compound arm has done this since lane-cwarp r1, this leaf
608 // predicted both taps translationally, so a GLOBAL_GLOBALMV
609 // 8x8 compound leaf under a non-TRANSLATION model drifted by
610 // a few luma levels, growing away from the block origin.
611 // `force_integer_mv` short-circuits `av1_init_warp_params`
612 // before `allow_warp`; chroma is 4x4 here, below
613 // `av1_init_warp_params`'s own 8px per-plane bound, so only
614 // luma warps (same rule as this leaf's single-ref arm).
615 let leaf_compound_warp = |ref_frame: i8, eligible: bool| {
616 if eligible
617 && !force_integer_mv
618 && !global_motion[(ref_frame - LAST_FRAME) as usize].invalid
619 {
620 crate::warp::global_warp_params(
621 global_motion[(ref_frame - LAST_FRAME) as usize].params,
622 )
623 } else {
624 None
625 }
626 };
627 // lane-t900 r28: same per-slot `allow_warp` scale bail-out as
628 // the 16x16-and-bigger compound path above.
629 let leaf_ref_unscaled = |rf: i8| {
630 refpix
631 .dims(rf)
632 .is_some_and(|d| scale_of(d, frame_size).is_unscaled())
633 };
634 let warp0_c =
635 leaf_compound_warp(ref0, is_global_mv0_c).filter(|_| leaf_ref_unscaled(ref0));
636 let warp1_c =
637 leaf_compound_warp(ref1, is_global_mv1_c).filter(|_| leaf_ref_unscaled(ref1));
638 if warp0_c.is_some() || warp1_c.is_some() {
639 hit!(COMPOUND_WARP_HITS);
640 hit!(COMPOUND_WARP_HITS_8);
641 }
642 grid.fill_rect(
643 mi_row,
644 mi_col,
645 2,
646 2,
647 MiInfo {
648 is_inter: true,
649 ref_frame: ref0,
650 ref_frame1: ref1,
651 mv1: mv16(mv1),
652 mv: mv16(mv0),
653 is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7),
654 size: 2,
655 size_h: 2,
656 is_global_mv0: is_global_mv0_c,
657 is_global_mv1: is_global_mv1_c,
658 },
659 );
660 mode_for_tx = 0;
661
662 // lane-defer8: this leaf's whole prediction as a closure, run at the
663 // push site like [`decode_inter_block`]'s.
664 let build = move |_y: &mut PlaneBuf<'static>,
665 _u: &mut PlaneBuf<'static>,
666 _v: &mut PlaneBuf<'static>,
667 refpix: &RefPix<'_>,
668 fctx: &crate::decode::FrameCtx,
669 out: &mut [Vec<u16>; 3]| {
670 let (Some((py0, pu0, pv0)), Some((py1, pu1, pv1))) = (
671 ref_planes_deferred(ref0, refpix),
672 ref_planes_deferred(ref1, refpix),
673 ) else {
674 return;
675 };
676 let mut inter0_y = vec![0i32; SIDE * SIDE];
677 mc::predict_compound_intermediate(
678 &py0.data,
679 py0.width,
680 py0.true_width,
681 py0.true_height,
682 mv_to_q4(px, mv0.1, 0),
683 mv_to_q4(py, mv0.0, 0),
684 scale0,
685 SIDE,
686 SIDE,
687 h_filter,
688 v_filter,
689 &mut inter0_y,
690 fctx,
691 );
692 if let Some(wp) = &warp0_c {
693 crate::warp::warp_affine_compound(
694 wp,
695 &py0.data,
696 py0.true_width as i32,
697 py0.true_height as i32,
698 py0.width as i32,
699 &mut inter0_y,
700 px as i32,
701 py as i32,
702 SIDE as i32,
703 SIDE as i32,
704 SIDE as i32,
705 0,
706 0,
707 fctx,
708 );
709 }
710 let mut inter1_y = vec![0i32; SIDE * SIDE];
711 mc::predict_compound_intermediate(
712 &py1.data,
713 py1.width,
714 py1.true_width,
715 py1.true_height,
716 mv_to_q4(px, mv1.1, 0),
717 mv_to_q4(py, mv1.0, 0),
718 scale1,
719 SIDE,
720 SIDE,
721 h_filter,
722 v_filter,
723 &mut inter1_y,
724 fctx,
725 );
726 if let Some(wp) = &warp1_c {
727 crate::warp::warp_affine_compound(
728 wp,
729 &py1.data,
730 py1.true_width as i32,
731 py1.true_height as i32,
732 py1.width as i32,
733 &mut inter1_y,
734 px as i32,
735 py as i32,
736 SIDE as i32,
737 SIDE as i32,
738 SIDE as i32,
739 0,
740 0,
741 fctx,
742 );
743 }
744 let mut pred_y = refill(std::mem::take(&mut out[0]), SIDE * SIDE);
745 let mut diffwtd_mask_y;
746 let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type {
747 diffwtd_mask_y = vec![0u8; SIDE * SIDE];
748 hit!(DIFFWTD_HITS);
749 mc::diffwtd_mask(
750 &inter0_y,
751 &inter1_y,
752 mask_type == 1,
753 &mut diffwtd_mask_y,
754 fctx,
755 );
756 Some(diffwtd_mask_y.as_slice())
757 } else {
758 wedge_mask
759 };
760 if let Some(mask_y) = mask_y {
761 mc::blend_masked_compound(
762 &inter0_y,
763 &inter1_y,
764 mask_y,
765 SIDE,
766 SIDE,
767 SIDE,
768 0,
769 0,
770 &mut pred_y,
771 fctx,
772 );
773 } else {
774 mc::combine_compound(
775 &inter0_y,
776 &inter1_y,
777 fwd_offset,
778 bck_offset,
779 &mut pred_y,
780 fctx,
781 );
782 }
783
784 let mut inter0_u = vec![0i32; chroma_w * chroma_h];
785 mc::predict_compound_intermediate(
786 &pu0.data,
787 pu0.width,
788 pu0.true_width,
789 pu0.true_height,
790 mv_to_q4(cpx, mv0.1, ss_x(fctx)),
791 mv_to_q4(cpy, mv0.0, ss_y(fctx)),
792 scale0,
793 chroma_w,
794 chroma_h,
795 h_filter,
796 v_filter,
797 &mut inter0_u,
798 fctx,
799 );
800 // lane-av1444altref r3: this leaf warped its LUMA
801 // intermediates (`warp0_c`/`warp1_c` above) but left both
802 // CHROMA arms translational. libaom warps per PLANE:
803 // `build_inter_predictors_8x8_and_bigger`
804 // (reconinter_template.inc:230) runs the whole
805 // `av1_init_warp_params` + `av1_warp_plane` pair for every
806 // plane of the block, chroma included, with
807 // `pd->subsampling_x/y` and the plane's own origin/extent.
808 // A global-motion (warp) 8x8 leaf at 4:4:4 therefore had
809 // its chroma predicted from the block's top-left
810 // translation instead of the affine map -- the MV is the
811 // affine's local derivative, so the two agree at the
812 // block's top-left corner and drift apart toward its
813 // bottom-right, which is exactly the measured signature
814 // (a bottom-right-biased +/-1 gradient in 8x8 chroma
815 // cells of the 4:4:4 altref cell `ll444_c`, luma exact).
816 // `warp_plane_allowed` mirrors `av1_init_warp_params`'s
817 // `block_width < 8 || block_height < 8` bail, so a
818 // subsampled plane's sub-8 chroma block stays
819 // translational exactly as the 16x16+ arm above does.
820 if let Some(wp) = &warp0_c
821 && warp_plane_allowed(chroma_w, chroma_h)
822 {
823 crate::warp::warp_affine_compound(
824 wp,
825 &pu0.data,
826 pu0.true_width as i32,
827 pu0.true_height as i32,
828 pu0.width as i32,
829 &mut inter0_u,
830 cpx as i32,
831 cpy as i32,
832 chroma_w as i32,
833 chroma_h as i32,
834 chroma_w as i32,
835 ss_x(fctx) as i32,
836 ss_y(fctx) as i32,
837 fctx,
838 );
839 }
840 let mut inter1_u = vec![0i32; chroma_w * chroma_h];
841 mc::predict_compound_intermediate(
842 &pu1.data,
843 pu1.width,
844 pu1.true_width,
845 pu1.true_height,
846 mv_to_q4(cpx, mv1.1, ss_x(fctx)),
847 mv_to_q4(cpy, mv1.0, ss_y(fctx)),
848 scale1,
849 chroma_w,
850 chroma_h,
851 h_filter,
852 v_filter,
853 &mut inter1_u,
854 fctx,
855 );
856 if let Some(wp) = &warp1_c
857 && warp_plane_allowed(chroma_w, chroma_h)
858 {
859 crate::warp::warp_affine_compound(
860 wp,
861 &pu1.data,
862 pu1.true_width as i32,
863 pu1.true_height as i32,
864 pu1.width as i32,
865 &mut inter1_u,
866 cpx as i32,
867 cpy as i32,
868 chroma_w as i32,
869 chroma_h as i32,
870 chroma_w as i32,
871 ss_x(fctx) as i32,
872 ss_y(fctx) as i32,
873 fctx,
874 );
875 }
876 let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_w * chroma_h);
877 if let Some(mask_y) = mask_y {
878 mc::blend_masked_compound(
879 &inter0_u,
880 &inter1_u,
881 mask_y,
882 SIDE,
883 chroma_w,
884 chroma_h,
885 ss_x(fctx),
886 ss_y(fctx),
887 &mut pred_u,
888 fctx,
889 );
890 } else {
891 mc::combine_compound(
892 &inter0_u,
893 &inter1_u,
894 fwd_offset,
895 bck_offset,
896 &mut pred_u,
897 fctx,
898 );
899 }
900
901 let mut inter0_v = vec![0i32; chroma_w * chroma_h];
902 mc::predict_compound_intermediate(
903 &pv0.data,
904 pv0.width,
905 pv0.true_width,
906 pv0.true_height,
907 mv_to_q4(cpx, mv0.1, ss_x(fctx)),
908 mv_to_q4(cpy, mv0.0, ss_y(fctx)),
909 scale0,
910 chroma_w,
911 chroma_h,
912 h_filter,
913 v_filter,
914 &mut inter0_v,
915 fctx,
916 );
917 // lane-av1444altref r3: the V arm's missing per-plane warp,
918 // same defect and same fix as U above.
919 if let Some(wp) = &warp0_c
920 && warp_plane_allowed(chroma_w, chroma_h)
921 {
922 crate::warp::warp_affine_compound(
923 wp,
924 &pv0.data,
925 pv0.true_width as i32,
926 pv0.true_height as i32,
927 pv0.width as i32,
928 &mut inter0_v,
929 cpx as i32,
930 cpy as i32,
931 chroma_w as i32,
932 chroma_h as i32,
933 chroma_w as i32,
934 ss_x(fctx) as i32,
935 ss_y(fctx) as i32,
936 fctx,
937 );
938 }
939 let mut inter1_v = vec![0i32; chroma_w * chroma_h];
940 mc::predict_compound_intermediate(
941 &pv1.data,
942 pv1.width,
943 pv1.true_width,
944 pv1.true_height,
945 mv_to_q4(cpx, mv1.1, ss_x(fctx)),
946 mv_to_q4(cpy, mv1.0, ss_y(fctx)),
947 scale1,
948 chroma_w,
949 chroma_h,
950 h_filter,
951 v_filter,
952 &mut inter1_v,
953 fctx,
954 );
955 if let Some(wp) = &warp1_c
956 && warp_plane_allowed(chroma_w, chroma_h)
957 {
958 crate::warp::warp_affine_compound(
959 wp,
960 &pv1.data,
961 pv1.true_width as i32,
962 pv1.true_height as i32,
963 pv1.width as i32,
964 &mut inter1_v,
965 cpx as i32,
966 cpy as i32,
967 chroma_w as i32,
968 chroma_h as i32,
969 chroma_w as i32,
970 ss_x(fctx) as i32,
971 ss_y(fctx) as i32,
972 fctx,
973 );
974 }
975 let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_w * chroma_h);
976 if let Some(mask_y) = mask_y {
977 mc::blend_masked_compound(
978 &inter0_v,
979 &inter1_v,
980 mask_y,
981 SIDE,
982 chroma_w,
983 chroma_h,
984 ss_x(fctx),
985 ss_y(fctx),
986 &mut pred_v,
987 fctx,
988 );
989 } else {
990 mc::combine_compound(
991 &inter0_v,
992 &inter1_v,
993 fwd_offset,
994 bck_offset,
995 &mut pred_v,
996 fctx,
997 );
998 }
999
1000 *out = [pred_y, pred_u, pred_v];
1001 };
1002 let (pred_y, pred_u, pred_v): (Vec<u16>, Vec<u16>, Vec<u16>);
1003 let (sy, su, sv) = if pred_deferred(refpix) {
1004 push_pred(build);
1005 (Pred::Cur { plane: 0, stride: SIDE, off: 0 }, Pred::Cur { plane: 1, stride: chroma_w, off: 0 }, Pred::Cur { plane: 2, stride: chroma_w, off: 0 })
1006 } else {
1007 let mut built: [Vec<u16>; 3] = Default::default();
1008 build(y, u, v, refpix, fctx, &mut built);
1009 let [by, bu, bv] = built;
1010 (pred_y, pred_u, pred_v) = (by, bu, bv);
1011 (
1012 Pred::Inline(&pred_y, SIDE),
1013 Pred::Inline(&pred_u, chroma_w),
1014 Pred::Inline(&pred_v, chroma_w),
1015 )
1016 };
1017 split8 = read_block_tx_size(
1018 dec,
1019 cdfs,
1020 neighbours,
1021 leaf_mi,
1022 SIDE,
1023 (mi_cols as usize, mi_rows as usize),
1024 true,
1025 skip,
1026 fctx,
1027 )?
1028 .1
1029 .is_some();
1030 if skip {
1031 push_mc(
1032 y,
1033 u,
1034 v,
1035 0,
1036 px,
1037 py,
1038 SIDE,
1039 sy,
1040 &ZERO_RESIDUAL[..SIDE * SIDE],
1041 fctx,
1042 );
1043 // lane-av1-422sub8rect: the plane block is the (chroma_w,
1044 // chroma_h) rect at 4:2:2 -- the recorded write is
1045 // stride `chroma_w`, full `chroma_h` rows.
1046 push_mc_rect(
1047 y,
1048 u,
1049 v,
1050 1,
1051 cpx,
1052 cpy,
1053 chroma_w,
1054 chroma_w,
1055 chroma_h,
1056 su,
1057 &ZERO_RESIDUAL[..chroma_w * chroma_h],
1058 fctx,
1059 );
1060 push_mc_rect(
1061 y,
1062 u,
1063 v,
1064 2,
1065 cpx,
1066 cpy,
1067 chroma_w,
1068 chroma_w,
1069 chroma_h,
1070 sv,
1071 &ZERO_RESIDUAL[..chroma_w * chroma_h],
1072 fctx,
1073 );
1074 luma_grid = Grid::Zero(SIDE * SIDE);
1075 u_grid = Grid::Zero(chroma_w * chroma_h);
1076 v_grid = Grid::Zero(chroma_w * chroma_h);
1077 } else {
1078 let around = neighbours.around_mi(leaf_mi, 8);
1079 // lane-av1-422sub8rect: the 4:2:2 chroma unit is the
1080 // TX_4X8 rect -- its `txb_skip_ctx` reads per chroma
1081 // 4-px cell ([`Neighbours::around_mi_422_chroma`], the
1082 // key-frame BLOCK_4X8 arm's own context walk), and the
1083 // coefficients go through the inter rect reader with the
1084 // inherited luma tx type.
1085 let chroma_around = if chroma_422 {
1086 neighbours.around_mi_422_chroma(leaf_mi, 8, 8)
1087 } else {
1088 around
1089 };
1090 let (grid8, luma_tx_type) = read_inter_luma8(
1091 y,
1092 u,
1093 v,
1094 dec,
1095 cdfs,
1096 neighbours,
1097 leaf_mi,
1098 px,
1099 py,
1100 sy,
1101 mode_for_tx,
1102 base_q_idx,
1103 scan8,
1104 scan4,
1105 reduced_tx_set,
1106 split8,
1107 fctx,
1108 )?;
1109 luma_grid = grid8;
1110 // Lossless 8x8 inter leaf: `av1_get_tx_size` returns
1111 // TX_4X4 for EVERY plane of a lossless block
1112 // (`decodeframe.c:1197`), so the chroma plane block is a
1113 // raster of TX_4X4 units whenever it is BIGGER than one --
1114 // 4:4:4's 8x8 (2x2) and 4:2:2's 4x8 (1x2). Only 4:2:0's
1115 // 4x4 keeps the single-unit read, where
1116 // `plane_bsize == txsize_to_bsize[tx_size]` puts
1117 // `get_txb_ctx`'s ctx_offset at 7.
1118 if lossless(fctx) && (chroma_w > 4 || chroma_h > 4) && !mono(fctx) {
1119 let (ug, vg) = leaf8_inter_chroma_lossless(
1120 y,
1121 u,
1122 v,
1123 dec,
1124 cdfs,
1125 neighbours,
1126 su,
1127 sv,
1128 leaf_mi,
1129 (cpx, cpy),
1130 (chroma_w, chroma_h),
1131 chroma_w,
1132 base_q_idx,
1133 fctx,
1134 )?;
1135 u_grid = ug;
1136 v_grid = vg;
1137 chroma_stamped_per_unit = true;
1138 } else {
1139 u_grid = if chroma_422 {
1140 read_inter_plane_rect(
1141 dec,
1142 cdfs,
1143 chroma_set,
1144 (chroma_w, chroma_h),
1145 chroma_w,
1146 1,
1147 chroma_around[1],
1148 mode_for_tx,
1149 y,
1150 u,
1151 v,
1152 cpx,
1153 cpy,
1154 su,
1155 Some(luma_tx_type),
1156 None,
1157 fctx,
1158 )?
1159 .0
1160 } else {
1161 read_inter_plane(
1162 dec,
1163 cdfs,
1164 chroma_set,
1165 chroma_scan,
1166 1,
1167 chroma_around[1],
1168 mode_for_tx,
1169 y,
1170 u,
1171 v,
1172 cpx,
1173 cpy,
1174 chroma_w,
1175 base_q_idx,
1176 su,
1177 Some(luma_tx_type),
1178 None,
1179 fctx,
1180 )?
1181 .0
1182 };
1183 v_grid = if chroma_422 {
1184 read_inter_plane_rect(
1185 dec,
1186 cdfs,
1187 chroma_set,
1188 (chroma_w, chroma_h),
1189 chroma_w,
1190 2,
1191 chroma_around[2],
1192 mode_for_tx,
1193 y,
1194 u,
1195 v,
1196 cpx,
1197 cpy,
1198 sv,
1199 Some(luma_tx_type),
1200 None,
1201 fctx,
1202 )?
1203 .0
1204 } else {
1205 read_inter_plane(
1206 dec,
1207 cdfs,
1208 chroma_set,
1209 chroma_scan,
1210 2,
1211 chroma_around[2],
1212 mode_for_tx,
1213 y,
1214 u,
1215 v,
1216 cpx,
1217 cpy,
1218 chroma_w,
1219 base_q_idx,
1220 sv,
1221 Some(luma_tx_type),
1222 None,
1223 fctx,
1224 )?
1225 .0
1226 };
1227 }
1228 }
1229 // lane-inter8 r2: the COMPOUND leaf used to return here
1230 // WITHOUT the end-of-function `record_mi`/`fill_lf_grid` the
1231 // single-ref path falls through to -- so a compound 8x8 leaf
1232 // left `above_side_mi`/`left_side_mi` (the next block's
1233 // partition context), the per-plane coefficient level state
1234 // and the loop-filter grid describing whatever block was
1235 // there before. Every leaf of the gate's stream is compound,
1236 // so the 16x16 below a split block read partition ctx 0
1237 // instead of 1 and mis-read PARTITION_SPLIT as NONE.
1238 // lane-sub8x4 r1: the same plane-0 save/restore the fall-through
1239 // (single-ref) path runs below -- a `split8` leaf's plane-0
1240 // neighbour context is per 4x4 transform unit (written by
1241 // `record_mi_luma` inside `read_inter_luma8`), and `record_mi`
1242 // rewrites all three planes from the whole-block grid, which is
1243 // all-zero in the split case. Missing here, a compound var-tx 8x8
1244 // leaf published level 0 to its right/below neighbours: the next
1245 // block's first TU read `skip_contexts[4][0] = 3` where aomdec
1246 // reads `[4][4] = 6` (class early-return-skips-tail).
1247 // lane-lossless3: `!skip` too. A SKIP block codes no coefficients and so
1248 // publishes nothing per transform unit, and on a LOSSLESS frame
1249 // `read_block_tx_size` hands back 4x4 leaves for a skip block as well
1250 // (libaom's `read_tx_size` returns TX_4X4 before it reads anything), so
1251 // `split8` is true over an UNTOUCHED band -- the restore then put the
1252 // previous block's levels back over the zeros `record_mi` had just
1253 // written, where libaom runs `av1_reset_entropy_context`. Class
1254 // [[override-slot-on-one-arm]]: a save/restore is only valid on the arm
1255 // that actually wrote the per-TU state.
1256 let saved_luma_ctx = (split8 && !skip).then(|| {
1257 (
1258 [
1259 neighbours.left[leaf_mi.0][0],
1260 neighbours.left[leaf_mi.0 + 1][0],
1261 ],
1262 [
1263 neighbours.above[leaf_mi.1][0],
1264 neighbours.above[leaf_mi.1 + 1][0],
1265 ],
1266 )
1267 });
1268 // lane-t900 r23: every leaf stamps its palette state (all-zero for an
1269 // inter leaf or a non-palette intra one, real for a palette block) into
1270 // the mi-granular neighbour bands, so the next intra block's
1271 // `av1_get_palette_mode_ctx` and colour cache see exactly what libaom's
1272 // mode-info grid holds.
1273 record_strip_palette(
1274 neighbours,
1275 leaf_mi,
1276 8,
1277 8,
1278 palette_record8.0,
1279 palette_record8.1,
1280 palette_record8.2,
1281 palette_record8.3,
1282 );
1283 let saved_chroma_ctx = chroma_stamped_per_unit.then(|| {
1284 (
1285 [
1286 [neighbours.left[leaf_mi.0][1], neighbours.left[leaf_mi.0][2]],
1287 [
1288 neighbours.left[leaf_mi.0 + 1][1],
1289 neighbours.left[leaf_mi.0 + 1][2],
1290 ],
1291 ],
1292 [
1293 [
1294 neighbours.above[leaf_mi.1][1],
1295 neighbours.above[leaf_mi.1][2],
1296 ],
1297 [
1298 neighbours.above[leaf_mi.1 + 1][1],
1299 neighbours.above[leaf_mi.1 + 1][2],
1300 ],
1301 ],
1302 )
1303 });
1304 neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);
1305 if let Some((left, above)) = saved_chroma_ctx {
1306 // The walk's per-unit stamps are the block's real chroma
1307 // coefficient contexts (`av1_set_contexts` per TX_4X4
1308 // unit); put them back over `record_mi`'s composed state.
1309 for (cell, uv) in left.into_iter().enumerate() {
1310 neighbours.left[leaf_mi.0 + cell][1] = uv[0];
1311 neighbours.left[leaf_mi.0 + cell][2] = uv[1];
1312 }
1313 for (cell, uv) in above.into_iter().enumerate() {
1314 neighbours.above[leaf_mi.1 + cell][1] = uv[0];
1315 neighbours.above[leaf_mi.1 + cell][2] = uv[1];
1316 }
1317 }
1318 if let Some((left, above)) = saved_luma_ctx {
1319 for (cell, state) in left.into_iter().enumerate() {
1320 neighbours.left[leaf_mi.0 + cell][0] = state;
1321 }
1322 for (cell, state) in above.into_iter().enumerate() {
1323 neighbours.above[leaf_mi.1 + cell][0] = state;
1324 }
1325 }
1326 // lane-cdef r1: ... and the CDEF skip band too. `apply_cdef`'s
1327 // `is_8x8_block_skip` (libaom `cdef.c:29-38`) reads all four mi
1328 // cells of the 8x8; this leaf wrote none of them, so a 64x64
1329 // whose bottom-right 16x16 is an all-skip 8x8-leaf group kept
1330 // the PREVIOUS frame's flags and got filtered where libaom's
1331 // dlist excludes it (3 luma samples on a 192x128 inter frame).
1332 hit!(INTER8_SKIP_BAND_HITS);
1333 neighbours.fill_skip_grid(leaf_mi, 2, skip);
1334 // lane-sub8x4 r2: `split8` is this leaf's OWN var-tx split, so
1335 // the deblock grid must publish the TX_4X4 leaves' width the
1336 // same way the fall-through arm below does (libaom
1337 // `get_transform_size`, av1_loopfilter.c:207, reads the per-TU
1338 // `inter_tx_size` for a non-skip inter luma block). Hardcoding
1339 // 8 here left a compound var-tx 8x8 leaf's interior vertical
1340 // edge at x % 8 == 4 unfiltered -- class early-return-skips-tail,
1341 // third instance in this same arm.
1342 neighbours.fill_lf_grid(
1343 leaf_mi,
1344 2,
1345 if split8 { 4 } else { 8 },
1346 if is_inter {
1347 leaf_refs.0.max(LAST_FRAME)
1348 } else {
1349 0
1350 },
1351 fctx,
1352 );
1353 return Ok((
1354 skip,
1355 is_inter,
1356 skip_mode,
1357 compound_ctx8,
1358 leaf_filter_syms,
1359 leaf_refs,
1360 ));
1361 }
1362 }
1363 // lane-gmaffine r1: the leaf reads the FULL `single_ref` tree
1364 // ([`read_single_ref`], the same one the 16x16+ leaf uses, with the
1365 // real per-neighbour p1..p6 contexts) instead of the old three-symbol
1366 // LAST-only probe plus a refusal -- aomenc picks GOLDEN/ALTREF for
1367 // 8x8 leaves constantly, so that refusal was what every 8x8 gate
1368 // actually stopped at.
1369 let ref_frame = read_single_ref(
1370 dec,
1371 cdfs,
1372 neighbours.above_ref[cmi],
1373 neighbours.above_ref1[cmi],
1374 neighbours.left_ref[rmi],
1375 neighbours.left_ref1[rmi],
1376 );
1377 leaf_refs = (ref_frame, None);
1378 // lane-defer8: this leaf's reference SIZE at parse, its pictures
1379 // inside the prediction closure below.
1380 let (ref_width, ref_height) = ref_dims(ref_frame, refpix)?;
1381
1382 let (mi_row, mi_col) = leaf_mi;
1383 // lane-inter8 r2: the frame's temporal mv candidates, keyed on THIS
1384 // leaf's own reference (lane-gmaffine r1 taught it non-LAST refs).
1385 let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs {
1386 field: t.field,
1387 cur_offset_0: crate::motion_field::get_relative_dist(
1388 t.order_hint_bits,
1389 t.order_hint,
1390 t.ref_order_hints[(ref_frame - LAST_FRAME) as usize],
1391 ),
1392 allow_high_precision_mv,
1393 force_integer_mv,
1394 });
1395 let stack = crate::mvstack::find_mv_stack_with_sign_bias(
1396 grid,
1397 mi_row,
1398 mi_col,
1399 2,
1400 2,
1401 ref_frame,
1402 mi_cols as usize,
1403 mi_rows as usize,
1404 sign_bias_table,
1405 &gm_table,
1406 tpl,
1407 );
1408 // lane-interp3 r2: same per-entry EC_STACK ladder
1409 // [`decode_inter_block`]'s single-ref arm prints, so this leaf's stack
1410 // diffs line for line against the oracle's.
1411 if crate::envflags::env_flag!("EC_TRACE_MODE") {
1412 for (i, e) in stack.entries.iter().enumerate() {
1413 eprintln!(
1414 "EC_STACK mi_row={mi_row} mi_col={mi_col} ref={ref_frame} i={i} this=({},{}) comp=(0,0) w={}",
1415 e.mv.0, e.mv.1, e.weight
1416 );
1417 }
1418 }
1419
1420 let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
1421 if !not_new {
1422 crate::census::mode(0);
1423 }
1424 let mut is_globalmv = false;
1425 let (mv, is_new_mv) = if !not_new {
1426 // NEWMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting at 0):
1427 // read at most two `drl_mode` bits, one per stack entry past the
1428 // first, stopping at the first `0`. The chosen index selects
1429 // which stack entry `read_mv`'s base predictor comes from
1430 // (spec 7.10.2.10 `assign_mv`'s `PredMv = RefStackMv[RefMvIdx]`)
1431 // -- entry 0 (`stack.pred_mv`) only when the loop never advances.
1432 let mut idx = 0usize;
1433 while idx < 2 && stack.entries.len() > idx + 1 {
1434 if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
1435 break;
1436 }
1437 idx += 1;
1438 }
1439 let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv);
1440 (
1441 read_mv(
1442 dec,
1443 &mut cdfs.mv_comp,
1444 &mut cdfs.mv_joint,
1445 base_mv,
1446 allow_high_precision_mv,
1447 force_integer_mv,
1448 fctx,
1449 ),
1450 true,
1451 )
1452 } else {
1453 let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;
1454 if !not_zero {
1455 crate::census::mode(1);
1456 }
1457 is_globalmv = !not_zero;
1458 let mv = if !not_zero {
1459 // lane-gmaffine r1: GLOBALMV (spec 7.10.2.1) -- the same
1460 // `gm_get_motion_vector` value the 16x16+ leaf reads out of
1461 // its own `gm_table`, computed at this block's centre.
1462 hit!(GLOBALMV_HITS_8);
1463 gm_table[(ref_frame - LAST_FRAME) as usize]
1464 } else {
1465 let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
1466 crate::census::mode(if nearest { 2 } else { 3 });
1467 if nearest {
1468 stack.nearest_mv
1469 } else {
1470 let mut idx = 1usize;
1471 while idx < 3 && stack.entries.len() > idx + 1 {
1472 if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
1473 break;
1474 }
1475 idx += 1;
1476 }
1477 stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv)
1478 }
1479 };
1480 (mv, false)
1481 };
1482 // lane-sb128 r4: `interintra` (spec 5.11.24) at the 8x8 leaf too --
1483 // see [`decode_inter_block`]'s own doc; `BLOCK_8X8` is always
1484 // `is_interintra_allowed_bsize`-eligible, single-ref-only branch
1485 // (compound already returned above), GLOBALMV already refused
1486 // (round 3), so the only real gate left is the header enable bit.
1487 let mut interintra_mode: Option<u8> = None;
1488 let mut wedge_mask: Option<(&'static [u8], usize)> = None;
1489 if enable_interintra_compound && !skip_mode {
1490 crate::msac::SymbolDecoder::set_symr_cdf("interintra");
1491 let interintra = dec.symbol(&mut cdfs.interintra[SIZE_GROUP_8]) == 1;
1492 if interintra {
1493 // lane-interintra r1: same read pair as the 16/32 site;
1494 // wedge cdf row = BLOCK_8X8 (index 3), read on block size
1495 // alone, never the `enable_interintra_wedge` seq bit.
1496 let ii = dec.symbol(&mut cdfs.interintra_mode[SIZE_GROUP_8]) as u8;
1497 let wedge = dec.symbol(&mut cdfs.wedge_interintra[3]) == 1;
1498 if wedge {
1499 // lane-wii r2: same adapting `wedge_index` symbol as the
1500 // 16/32 leaf, fixed sign 0 -- see that site's comment.
1501 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]);
1502 hit!(WII_HITS);
1503 wedge_mask = Some((
1504 crate::wedge::wedge_masks()
1505 .codebook(SIDE, SIDE)
1506 .mask(0, wedge_index),
1507 SIDE,
1508 ));
1509 } else {
1510 hit!(INTERINTRA_HITS);
1511 }
1512 interintra_mode = Some(ii);
1513 // The inter-intra predictor reads this block's neighbours as already
1514 // reconstructed: a deferred wavefront must finish first.
1515 super::wave::finish_tile(fctx, refpix, [&mut *y, &mut *u, &mut *v]);
1516 }
1517 }
1518 // lane-motionmode round 3: `read_motion_mode` (spec 5.11.24) at the
1519 // 8x8 leaf too -- `motion_mode_allowed` still holds here (BLOCK_8X8
1520 // is the spec's own minimum eligible size, single-ref-only branch,
1521 // no interintra reader, `IDENTITY`-only global motion). Mirrors the
1522 // 16x16 leaf's own `decode_inter_block` read (see its doc above) --
1523 // same 2-symbol `obmc_cdf` alphabet, same `allow_warped_motion=1`
1524 // refusal (warp needs `av1_findSamples`, not ported at either leaf).
1525 // lane-gmaffine r1: the two libaom predicates, exactly as the
1526 // 16x16+ leaf resolves them (see [`decode_inter_block`]'s own doc):
1527 // `is_global_mv_block` (mode GLOBAL*, model > TRANSLATION, block
1528 // >= 8x8 -- BLOCK_8X8 IS the 8px minimum, so the size predicate is
1529 // always true here) suppresses the motion_mode read entirely and
1530 // turns on the global warp below.
1531 let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize];
1532 let is_global_mv_block = is_globalmv && gm_ref.model as u8 > 1;
1533 let motion_mode_eligible = switchable_motion_mode
1534 && !skip_mode
1535 && interintra_mode.is_none()
1536 && !(is_global_mv_block && !force_integer_mv)
1537 && has_overlappable_neighbour(
1538 grid,
1539 mi_row,
1540 mi_col,
1541 2,
1542 2,
1543 mi_cols as usize,
1544 mi_rows as usize,
1545 );
1546 let mut warp_params: Option<crate::warp::WarpParams> = None;
1547 let mut warped_selected = false;
1548 let mut obmc_selected = false;
1549 if motion_mode_eligible {
1550 // lane-warp round 1: same 3-vs-2-symbol split as the 16x16+ leaf
1551 // (see its own doc) -- this leaf is always `LAST_FRAME`-only
1552 // (grid.set below hardcodes it).
1553 // lane-scaledref r2 sibling of the 16x16+ leaf's fix: libaom
1554 // drops WARPED_CAUSAL eligibility (so this reads `obmc_cdf`)
1555 // when the reference is scaled. Not gated here because an 8x8
1556 // leaf under a scaled reference is refused before this function
1557 // runs (see the block8 refusal below, ~12500) -- whoever lifts
1558 // that refusal must add `&& !ref_is_scaled` here too.
1559 // lane-fimv r1: libaom `motion_mode_allowed` also requires
1560 // `!xd->cur_frame_force_integer_mv`, so a screen-content frame
1561 // that set `force_integer_mv` reads the 2-symbol `obmc_cdf` here
1562 // (class wrong-alphabet-same-value).
1563 let proj_ok = num_proj_ref(
1564 grid,
1565 mi_row,
1566 mi_col,
1567 2,
1568 2,
1569 mi_cols as usize,
1570 mi_rows as usize,
1571 ref_frame,
1572 fctx,
1573 ) >= 1;
1574 // lane-t900 r28: the `&& !ref_is_scaled` the note above asked the
1575 // lifter of the 8x8-leaf refusal to add. libaom
1576 // `motion_mode_allowed` (blockd.h) makes WARPED_CAUSAL eligible
1577 // only `if (mbmi->num_proj_ref >= 1 && (allow_warped_motion &&
1578 // !av1_is_scaled(xd->block_ref_scale_factors[0])))`, so under a
1579 // scaled reference the ALPHABET shrinks to the 2-symbol obmc one
1580 // -- and with OBMC off no symbol is read at all (class
1581 // wrong-alphabet-same-value: reading the 3-symbol row here
1582 // desynced every warped-motion superres stream at its first
1583 // eligible 8x8 leaf).
1584 let ref_is_scaled = !scale_of((ref_width, ref_height), frame_size).is_unscaled();
1585 let warp_eligible =
1586 allow_warped_motion && !ref_is_scaled && !force_integer_mv && proj_ok;
1587 if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
1588 eprintln!(
1589 "EC_MM8 mi_row={mi_row} mi_col={mi_col} proj={} warp_elig={} awm={}",
1590 proj_ok as u8, warp_eligible as u8, allow_warped_motion as u8
1591 );
1592 }
1593 if allow_warped_motion && proj_ok && ref_is_scaled {
1594 hit!(SCALED_WARP_SUPPRESSED_HITS);
1595 }
1596 if allow_warped_motion && proj_ok && !ref_is_scaled && force_integer_mv {
1597 hit!(FIMV_ALPHABET_HITS);
1598 }
1599 if warp_eligible {
1600 crate::msac::SymbolDecoder::set_symr_cdf("motion_mode");
1601 let mode = dec.symbol(&mut cdfs.motion_mode[0]);
1602 match mode {
1603 0 => {}
1604 1 => {
1605 obmc_selected = true;
1606 hit!(OBMC_HITS);
1607 hit!(OBMC_HITS_8);
1608 }
1609 _ => {
1610 // lane-gmaffine r1: WARPED_CAUSAL at the 8x8 leaf --
1611 // the same findSamples -> select_samples ->
1612 // av1_find_projection chain the 16x16+ leaf runs,
1613 // with BLOCK_8X8's own 8x8 model centre; an
1614 // unusable projection falls back to the block's
1615 // translational mv (libaom `av1_find_projection`
1616 // returning 1 leaves `wm_params` invalid and
1617 // `build_inter_predictors` skips the warp).
1618 hit!(WARP_SELECTED_HITS);
1619 let mut samples = find_samples(
1620 grid,
1621 mi_row,
1622 mi_col,
1623 2,
1624 2,
1625 mi_cols as usize,
1626 mi_rows as usize,
1627 ref_frame,
1628 fctx,
1629 );
1630 if samples.len() > 1 {
1631 crate::warp::select_samples(mv, &mut samples, SIDE as i32, SIDE as i32);
1632 }
1633 warp_params = crate::warp::find_projection(
1634 &samples,
1635 SIDE as i32,
1636 SIDE as i32,
1637 mv.1,
1638 mv.0,
1639 mi_row as i32,
1640 mi_col as i32,
1641 );
1642 warped_selected = true;
1643 if warp_params.is_some() {
1644 hit!(WARP_HITS_8);
1645 }
1646 }
1647 }
1648 } else {
1649 // `default_obmc_cdf`'s own index: square bsize 8/16/32/64 -> 0/1/2/3.
1650 obmc_selected = dec.symbol(&mut cdfs.obmc[0]) == 1;
1651 if obmc_selected {
1652 hit!(OBMC_HITS);
1653 hit!(OBMC_HITS_8);
1654 }
1655 }
1656 }
1657 // lane-gmaffine r1: `read_mb_interp_filter` (spec 5.11.26) at the 8x8
1658 // leaf, in libaom's own order (interintra, motion_mode, THEN the
1659 // filter). Until this round the leaf read no filter symbol at all and
1660 // predicted Regular unconditionally -- correct only for a frame with a
1661 // fixed `interp_filter`, and a silent entropy DESYNC for every
1662 // SWITCHABLE-filter stream that reaches an 8x8 leaf (which is what
1663 // made the interior-split wiring above unusable at first).
1664 // corner-cut: the neighbour filter context is the enclosing 16x16
1665 // block's own coarse `above_filter`/`left_filter` entry (this leaf
1666 // path keeps no per-leaf neighbour array), so all four siblings read
1667 // the same context row. Ceiling: a stream whose 8x8 siblings pick
1668 // DIFFERENT filters decodes the second..fourth leaf's symbol from the
1669 // wrong CDF row. Upgrade: give `Neighbours` a real 8x8-granular
1670 // filter array, same shape as the `[3, 3]` approximation the caller
1671 // records after the leaf loop.
1672 let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame
1673 || neighbours.above_ref1[cmi] == Some(ref_frame)
1674 {
1675 neighbours.above_filter[cmi]
1676 } else {
1677 [3, 3]
1678 };
1679 let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame
1680 || neighbours.left_ref1[rmi] == Some(ref_frame)
1681 {
1682 neighbours.left_filter[rmi]
1683 } else {
1684 [3, 3]
1685 };
1686 let gm_nontrans = is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation;
1687 let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
1688 dec,
1689 cdfs,
1690 interp_fixed,
1691 enable_dual_filter,
1692 gm_nontrans || warped_selected || skip_mode,
1693 above_filter_ctx,
1694 left_filter_ctx,
1695 false,
1696 );
1697 leaf_filter_syms = resolved_filter;
1698 if crate::envflags::env_flag!("EC_TRACE_MODE") {
1699 eprintln!(
1700 "EC_MODE_VAL8 mi_row={} mi_col={} newmv={is_new_mv} globalmv={is_globalmv} ref0={ref_frame} mv0=({},{}) stack={} rng={}",
1701 leaf_mi.0,
1702 leaf_mi.1,
1703 mv.0,
1704 mv.1,
1705 stack.entries.len(),
1706 dec.debug_state().0
1707 );
1708 }
1709 // lane-gmaffine r1: `allow_warp`'s `global_warp_allowed` branch
1710 // (`reconinter.c:33-55`), gated INDEPENDENTLY of `motion_mode` --
1711 // see [`decode_inter_block`]'s own copy. A local WARPED_CAUSAL model
1712 // wins (`is_none()` guard); BLOCK_8X8 already satisfies the >=8px
1713 // size predicate baked into `is_global_mv_block`.
1714 if warp_params.is_none() && is_global_mv_block && !force_integer_mv && !gm_ref.invalid {
1715 warp_params = crate::warp::global_warp_params(gm_ref.params);
1716 if warp_params.is_some() && gm_ref.model == ec_av1_syntax::WarpModel::Affine {
1717 hit!(AFFINE_GM_HITS);
1718 }
1719 }
1720 // lane-av112bitw: same lift as the 16x16+ leaf -- a local
1721 // `WARPED_CAUSAL` projection or a global model both leave
1722 // `warp_params` set here; the 12-bit refusal that stood here is
1723 // lifted with the same witness (`warp::warp_round_0` moved the
1724 // filter's shifts; the same stream decodes byte-exact vs ffmpeg).
1725 if crate::envflags::env_flag!("EC_TRACE_MODE") {
1726 eprintln!(
1727 "EC_WARP8 mi_row={} mi_col={} warp={} globalblk={is_global_mv_block}",
1728 leaf_mi.0,
1729 leaf_mi.1,
1730 warp_params.is_some(),
1731 );
1732 }
1733 grid.fill_rect(
1734 mi_row,
1735 mi_col,
1736 2,
1737 2,
1738 MiInfo {
1739 is_inter: true,
1740 ref_frame,
1741 // INTRA_FRAME marker for interintra blocks -- keeps
1742 // them out of warp-sample gathering (see 16/32 site).
1743 ref_frame1: if interintra_mode.is_some() {
1744 0
1745 } else {
1746 NO_REF1
1747 },
1748 mv1: (0, 0),
1749 mv: mv16(mv),
1750 is_new_mv,
1751 size: 2,
1752 size_h: 2,
1753 is_global_mv0: is_global_mv_block,
1754 is_global_mv1: false,
1755 },
1756 );
1757 mode_for_tx = 0;
1758
1759 // lane-scaledref r1: this leaf's own prediction is always `Regular`
1760 // (documented corner-cut above); under a scaled reference the same
1761 // fixed kernel runs through spec 7.11.3.3's scaled walk instead.
1762 let luma_scale = scale_of((ref_width, ref_height), frame_size);
1763 if !luma_scale.is_unscaled() {
1764 hit!(SCALED_BLOCK8_HITS);
1765 }
1766 let obmc = if obmc_selected {
1767 Some(obmc_plan(
1768 grid,
1769 &neighbours.above_filter,
1770 &neighbours.left_filter,
1771 mi_row,
1772 mi_col,
1773 2,
1774 2,
1775 mi_rows as usize,
1776 mi_cols as usize,
1777 SIDE,
1778 SIDE,
1779 SIDE,
1780 ss_x(fctx),
1781 ss_y(fctx),
1782 chroma_w,
1783 px,
1784 py,
1785 cpx,
1786 cpy,
1787 refpix,
1788 interp_fixed,
1789 frame_size,
1790 )?)
1791 } else {
1792 None
1793 };
1794 // lane-defer8: this leaf's whole prediction as a closure, run at the
1795 // push site like [`decode_inter_block`]'s.
1796 let build = move |y: &mut PlaneBuf<'static>,
1797 u: &mut PlaneBuf<'static>,
1798 v: &mut PlaneBuf<'static>,
1799 refpix: &RefPix<'_>,
1800 fctx: &crate::decode::FrameCtx,
1801 out: &mut [Vec<u16>; 3]| {
1802 let Some((sref_y, sref_u, sref_v)) = ref_planes_deferred(ref_frame, refpix) else {
1803 return;
1804 };
1805 let mut pred_y = refill(std::mem::take(&mut out[0]), SIDE * SIDE);
1806 let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_w * chroma_h);
1807 let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_w * chroma_h);
1808 // Merge of lane-gmaffine (this leaf's own switchable filters) with
1809 // lane-scaledref (spec 7.11.3.3's scaled walk): same kernels either
1810 // way, only the sample walk differs.
1811 for (plane, x, y, (dim_w, dim_h), dst) in [
1812 (sref_y, px, py, (SIDE, SIDE), &mut pred_y),
1813 (sref_u, cpx, cpy, (chroma_w, chroma_h), &mut pred_u),
1814 (sref_v, cpx, cpy, (chroma_w, chroma_h), &mut pred_v),
1815 ] {
1816 let luma = std::ptr::eq(plane, sref_y);
1817 if luma_scale.is_unscaled() {
1818 mc::predict_with_filters(
1819 &plane.data,
1820 plane.width,
1821 plane.true_width,
1822 plane.true_height,
1823 mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }),
1824 mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }),
1825 dim_w,
1826 dim_h,
1827 h_filter,
1828 v_filter,
1829 dst,
1830 fctx,
1831 );
1832 } else {
1833 mc::predict_scaled(
1834 &plane.data,
1835 plane.width,
1836 plane.true_width,
1837 plane.true_height,
1838 mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }),
1839 mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }),
1840 luma_scale,
1841 dim_w,
1842 dim_h,
1843 h_filter,
1844 v_filter,
1845 dst,
1846 fctx,
1847 );
1848 }
1849 }
1850
1851 // lane-gmaffine r1: the warp filter REPLACES the translational
1852 // prediction just built (libaom builds one or the other), same as
1853 // the 16x16+ leaf's own call trio.
1854 // lane-t900 r28: `allow_warp`'s scaled-reference bail-out, which this
1855 // leaf was missing -- it is the defect the 8x8-leaf refusal hid (a
1856 // warped 8x8 leaf over a superres reference; libaom predicts it
1857 // translationally, every symbol still read).
1858 if let Some(params) = warp_params.as_ref().filter(|_| luma_scale.is_unscaled()) {
1859 crate::warp::warp_affine(
1860 params,
1861 &sref_y.data,
1862 sref_y.true_width as i32,
1863 sref_y.true_height as i32,
1864 sref_y.width as i32,
1865 &mut pred_y,
1866 px as i32,
1867 py as i32,
1868 SIDE as i32,
1869 SIDE as i32,
1870 SIDE as i32,
1871 0,
1872 0,
1873 fctx,
1874 );
1875 // `av1_init_warp_params`'s per-plane bail-out is on BOTH
1876 // extents (`block_height < 8 || block_width < 8`,
1877 // reconinter.c:61): an 8x8 leaf's chroma plane block is under 8
1878 // at any subsampled format (4:2:0 4x4, 4:2:2 4x8), so it is
1879 // predicted translationally even when the luma warps; 4:4:4's
1880 // 8x8 chroma warps with the luma, and a rect chroma block 8 wide
1881 // but under 8 high (4:2:2 BLOCK_8X4) stays translational too.
1882 // lane-av1444altref r3: this arm tested only the width.
1883 if warp_plane_allowed(chroma_w, chroma_h) {
1884 crate::warp::warp_affine(
1885 params,
1886 &sref_u.data,
1887 sref_u.true_width as i32,
1888 sref_u.true_height as i32,
1889 sref_u.width as i32,
1890 &mut pred_u,
1891 cpx as i32,
1892 cpy as i32,
1893 chroma_w as i32,
1894 chroma_h as i32,
1895 chroma_w as i32,
1896 ss_x(fctx) as i32,
1897 ss_y(fctx) as i32,
1898 fctx,
1899 );
1900 crate::warp::warp_affine(
1901 params,
1902 &sref_v.data,
1903 sref_v.true_width as i32,
1904 sref_v.true_height as i32,
1905 sref_v.width as i32,
1906 &mut pred_v,
1907 cpx as i32,
1908 cpy as i32,
1909 chroma_w as i32,
1910 chroma_h as i32,
1911 chroma_w as i32,
1912 ss_x(fctx) as i32,
1913 ss_y(fctx) as i32,
1914 fctx,
1915 );
1916 }
1917 }
1918
1919 if let Some(plan) = &obmc {
1920 obmc_run(plan, refpix, &mut pred_y, &mut pred_u, &mut pred_v, fctx);
1921 }
1922
1923 // Non-wedge interintra blend, mutually exclusive with OBMC (the
1924 // motion_mode symbol is not read for an interintra block).
1925 if let Some(ii) = interintra_mode {
1926 interintra_blend(
1927 y,
1928 px,
1929 py,
1930 SIDE,
1931 SIDE,
1932 SIDE,
1933 0,
1934 0,
1935 ii,
1936 wedge_mask,
1937 &mut pred_y,
1938 fctx,
1939 );
1940 interintra_blend(
1941 u,
1942 cpx,
1943 cpy,
1944 chroma_w,
1945 chroma_h,
1946 chroma_w,
1947 ss_x(fctx),
1948 ss_y(fctx),
1949 ii,
1950 wedge_mask,
1951 &mut pred_u,
1952 fctx,
1953 );
1954 interintra_blend(
1955 v,
1956 cpx,
1957 cpy,
1958 chroma_w,
1959 chroma_h,
1960 chroma_w,
1961 ss_x(fctx),
1962 ss_y(fctx),
1963 ii,
1964 wedge_mask,
1965 &mut pred_v,
1966 fctx,
1967 );
1968 }
1969
1970 *out = [pred_y, pred_u, pred_v];
1971 };
1972 let (pred_y, pred_u, pred_v): (Vec<u16>, Vec<u16>, Vec<u16>);
1973 let (sy, su, sv) = if pred_deferred(refpix) {
1974 push_pred(build);
1975 (Pred::Cur { plane: 0, stride: SIDE, off: 0 }, Pred::Cur { plane: 1, stride: chroma_w, off: 0 }, Pred::Cur { plane: 2, stride: chroma_w, off: 0 })
1976 } else {
1977 // The interintra predictor reads this block's own above/left
1978 // edges, which are already written at this point.
1979 let mut built: [Vec<u16>; 3] = Default::default();
1980 build(y, u, v, refpix, fctx, &mut built);
1981 let [by, bu, bv] = built;
1982 (pred_y, pred_u, pred_v) = (by, bu, bv);
1983 (
1984 Pred::Inline(&pred_y, SIDE),
1985 Pred::Inline(&pred_u, chroma_w),
1986 Pred::Inline(&pred_v, chroma_w),
1987 )
1988 };
1989 split8 = read_block_tx_size(
1990 dec,
1991 cdfs,
1992 neighbours,
1993 leaf_mi,
1994 SIDE,
1995 (mi_cols as usize, mi_rows as usize),
1996 true,
1997 skip,
1998 fctx,
1999 )?
2000 .1
2001 .is_some();
2002 if skip {
2003 push_mc(
2004 y,
2005 u,
2006 v,
2007 0,
2008 px,
2009 py,
2010 SIDE,
2011 sy,
2012 &ZERO_RESIDUAL[..SIDE * SIDE],
2013 fctx,
2014 );
2015 // lane-av1-422sub8rect: the plane block is the (chroma_w,
2016 // chroma_h) rect at 4:2:2 -- the recorded write is stride
2017 // `chroma_w`, full `chroma_h` rows.
2018 push_mc_rect(
2019 y,
2020 u,
2021 v,
2022 1,
2023 cpx,
2024 cpy,
2025 chroma_w,
2026 chroma_w,
2027 chroma_h,
2028 su,
2029 &ZERO_RESIDUAL[..chroma_w * chroma_h],
2030 fctx,
2031 );
2032 push_mc_rect(
2033 y,
2034 u,
2035 v,
2036 2,
2037 cpx,
2038 cpy,
2039 chroma_w,
2040 chroma_w,
2041 chroma_h,
2042 sv,
2043 &ZERO_RESIDUAL[..chroma_w * chroma_h],
2044 fctx,
2045 );
2046 luma_grid = Grid::Zero(SIDE * SIDE);
2047 u_grid = Grid::Zero(chroma_w * chroma_h);
2048 v_grid = Grid::Zero(chroma_w * chroma_h);
2049 } else {
2050 let around = neighbours.around_mi(leaf_mi, 8);
2051 // lane-av1-422sub8rect: the 4:2:2 chroma unit is the TX_4X8
2052 // rect -- its `txb_skip_ctx` reads per chroma 4-px cell
2053 // ([`Neighbours::around_mi_422_chroma`], the key-frame
2054 // BLOCK_4X8 arm's own context walk), and the coefficients go
2055 // through the inter rect reader with the inherited luma tx
2056 // type.
2057 let chroma_around = if chroma_422 {
2058 neighbours.around_mi_422_chroma(leaf_mi, 8, 8)
2059 } else {
2060 around
2061 };
2062 let (grid8, luma_tx_type) = read_inter_luma8(
2063 y,
2064 u,
2065 v,
2066 dec,
2067 cdfs,
2068 neighbours,
2069 leaf_mi,
2070 px,
2071 py,
2072 sy,
2073 mode_for_tx,
2074 base_q_idx,
2075 scan8,
2076 scan4,
2077 reduced_tx_set,
2078 split8,
2079 fctx,
2080 )?;
2081 luma_grid = grid8;
2082 // Lossless 8x8 inter leaf, compound twin of the single-ref arm
2083 // above -- same per-axis plane block (4:4:4 8x8, 4:2:2 4x8) and
2084 // the same "bigger than one TX_4X4" gate.
2085 if lossless(fctx) && (chroma_w > 4 || chroma_h > 4) && !mono(fctx) {
2086 let (ug, vg) = leaf8_inter_chroma_lossless(
2087 y,
2088 u,
2089 v,
2090 dec,
2091 cdfs,
2092 neighbours,
2093 su,
2094 sv,
2095 leaf_mi,
2096 (cpx, cpy),
2097 (chroma_w, chroma_h),
2098 chroma_w,
2099 base_q_idx,
2100 fctx,
2101 )?;
2102 u_grid = ug;
2103 v_grid = vg;
2104 chroma_stamped_per_unit = true;
2105 } else {
2106 u_grid = if chroma_422 {
2107 read_inter_plane_rect(
2108 dec,
2109 cdfs,
2110 chroma_set,
2111 (chroma_w, chroma_h),
2112 chroma_w,
2113 1,
2114 chroma_around[1],
2115 mode_for_tx,
2116 y,
2117 u,
2118 v,
2119 cpx,
2120 cpy,
2121 su,
2122 Some(luma_tx_type),
2123 None,
2124 fctx,
2125 )?
2126 .0
2127 } else {
2128 read_inter_plane(
2129 dec,
2130 cdfs,
2131 chroma_set,
2132 chroma_scan,
2133 1,
2134 chroma_around[1],
2135 mode_for_tx,
2136 y,
2137 u,
2138 v,
2139 cpx,
2140 cpy,
2141 chroma_w,
2142 base_q_idx,
2143 su,
2144 Some(luma_tx_type),
2145 None,
2146 fctx,
2147 )?
2148 .0
2149 };
2150 v_grid = if chroma_422 {
2151 read_inter_plane_rect(
2152 dec,
2153 cdfs,
2154 chroma_set,
2155 (chroma_w, chroma_h),
2156 chroma_w,
2157 2,
2158 chroma_around[2],
2159 mode_for_tx,
2160 y,
2161 u,
2162 v,
2163 cpx,
2164 cpy,
2165 sv,
2166 Some(luma_tx_type),
2167 None,
2168 fctx,
2169 )?
2170 .0
2171 } else {
2172 read_inter_plane(
2173 dec,
2174 cdfs,
2175 chroma_set,
2176 chroma_scan,
2177 2,
2178 chroma_around[2],
2179 mode_for_tx,
2180 y,
2181 u,
2182 v,
2183 cpx,
2184 cpy,
2185 chroma_w,
2186 base_q_idx,
2187 sv,
2188 Some(luma_tx_type),
2189 None,
2190 fctx,
2191 )?
2192 .0
2193 };
2194 }
2195 }
2196 } else {
2197 crate::msac::SymbolDecoder::set_symr_cdf("y_mode");
2198 let mode = dec.symbol(&mut cdfs.y_mode[SIZE_GROUP_8]);
2199 if mode >= 13 {
2200 return Err(unsupported(
2201 "an intra mode this decoder does not code (round 2)",
2202 ));
2203 }
2204 // lane-angleinter r1: `read_intra_angle_info` (libaom `decodemv.c`,
2205 // inside `read_intra_block_mode_info`) -- an intra block in an inter
2206 // frame reads `angle_delta_y` off the same
2207 // `angle_delta_cdf[mode - V_PRED]` row a key-frame block does, and
2208 // the delta feeds the directional predictor (and the edge
2209 // filter/upsample decision derived from the delta'd angle) unchanged.
2210 // The symbol was read and then refused before this round even though
2211 // aomenc enables `--enable-angle-delta` by default.
2212 let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) {
2213 read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED])
2214 } else {
2215 0
2216 };
2217 if angle_delta_y != 0 {
2218 hit!(INTRA_IN_INTER_ANGLE_DELTA_Y_HITS);
2219 // lane-leaf8tx r1: `av1_use_angle_delta(BLOCK_8X8)` is true
2220 // (`bsize >= BLOCK_8X8`), so this leaf codes `angle_delta_y` off
2221 // `angle_delta_cdf[mode - V_PRED]` exactly as a key-frame block
2222 // does (libaom `read_intra_angle_info` inside
2223 // `read_intra_block_mode_info`, decodemv.c), and the delta feeds
2224 // the directional predictor + the edge filter/upsample decision
2225 // through the same `reconstruct` argument below. Counted
2226 // separately from the >=16x16 arm so the gate cannot be satisfied
2227 // by a bigger block.
2228 hit!(INTRA_IN_INTER8_ANGLE_DELTA_Y_HITS);
2229 }
2230 // lane-uv8 r1: the delta'd angle decides the intra edge filter, and a
2231 // directional luma mode is already legal on this leaf -- the arm
2232 // passed a hardcoded `false` where [`decode_leaf8`] reads the
2233 // mi-exact neighbour modes (`get_intra_edge_filter_type`, spec
2234 // 7.11.2).
2235 let (above_mode, left_mode) =
2236 neighbours.modes_above_left_mi(leaf_mi.0, leaf_mi.1, neighbours.modes_above_left(r, c));
2237 let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode);
2238 // lane-uv8 r1: libaom `read_intra_block_mode_info` (decodemv.c:1198-1207)
2239 // -- `uv_mode` over the CFL-allowed alphabet (`is_cfl_allowed`: a
2240 // BLOCK_8X8 leaf is inside the 32x32 bound), then `read_cfl_alphas`
2241 // for `UV_CFL_PRED`, then `angle_delta_uv` off the MAPPED uv mode's
2242 // row (`get_uv_mode`, identity over `V_PRED..=D67_PRED`). Every value
2243 // but `DC_PRED` was refused here, which is what blocked the low-cq
2244 // CDEF arms and the 10-bit gates.
2245 let has_chroma = !mono(fctx);
2246 // lane-av1-llintra8: `read_intra_mode_uv` (decodemv.c:145) picks the
2247 // uv CDF row by `is_cfl_allowed` (cfl.h:23) -- at LOSSLESS that is
2248 // "the chroma plane block is BLOCK_4X4" (cfl.h:29), for this
2249 // BLOCK_8X8 leaf only at 4:2:0. The 4:4:4 lossless leaf reads the
2250 // 13-symbol `uv_mode_no_cfl` alphabet; the unconditional CFL row
2251 // consumed a different partition than aomdec at the leaf's own
2252 // uv_mode symbol (class wrong-alphabet-same-value) and desynced
2253 // every stream that reached the leaf's lossless chroma walk below.
2254 // 4:2:0 and every non-lossless partition keep the CFL row
2255 // (`cfl_allowed_px` answers true exactly as before).
2256 let uv_mode = if !has_chroma {
2257 DC_PRED
2258 } else if cfl_allowed_px(SIDE, SIDE, fctx) {
2259 crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
2260 dec.symbol(&mut cdfs.uv_mode_cfl[mode])
2261 } else {
2262 crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
2263 dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
2264 };
2265 if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
2266 eprintln!(
2267 "EC_ISTEP8 mi_row={} mi_col={} name=modes y={mode} uv={uv_mode} fi_enabled={} rng={}",
2268 leaf_mi.0,
2269 leaf_mi.1,
2270 fctx.enable_filter_intra_inter.with(std::cell::Cell::get),
2271 dec.debug_state().0
2272 );
2273 }
2274 if (9..=12).contains(&uv_mode) {
2275 hit!(SMOOTH_UV_HITS);
2276 hit!(INTRA_IN_INTER8_UV_SMOOTH_HITS);
2277 }
2278 let alpha = if has_chroma && uv_mode == UV_CFL_PRED {
2279 hit!(INTRA_IN_INTER8_UV_CFL_HITS);
2280 Some(read_cfl_alphas(dec, cdfs))
2281 } else {
2282 None
2283 };
2284 let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
2285 hit!(DIRECTIONAL_UV_HITS);
2286 hit!(INTRA_IN_INTER8_UV_DIR_HITS);
2287 read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])
2288 } else {
2289 0
2290 };
2291 if angle_delta_uv != 0 {
2292 hit!(UV_ANGLE_DELTA_HITS);
2293 hit!(INTRA_IN_INTER_ANGLE_DELTA_UV_HITS);
2294 }
2295 // `get_uv_mode` (spec 9.3): `UV_CFL_PRED` predicts as `DC_PRED`.
2296 uv_predict_mode = if uv_mode == UV_CFL_PRED {
2297 DC_PRED
2298 } else {
2299 uv_mode
2300 };
2301 // The CHROMA neighbour's own `uv_mode` decides the chroma edge filter
2302 // strength (`get_intra_edge_filter_type`, reconintra.c:974), never the
2303 // luma one -- same read [`decode_leaf8`] does.
2304 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c, fctx);
2305 // lane-screen r2: see [`decode_inter_block`]'s own copy -- `mode`/
2306 // `uv_mode` are both effectively `DC_PRED`-gated already on this
2307 // leaf (a nonzero `mode` still passes, but `uv_mode` is forced
2308 // `DC_PRED` by the refusal just above), same order as libaom's
2309 // `read_palette_mode_info` call right after `xd->cfl.store_y`.
2310 // lane-t900 r23: reconstructed, not refused. Same syntax, same
2311 // deferral of the colour-index maps past `use_filter_intra`
2312 // (`av1_visit_palette` runs from `parse_decode_block`, after the whole
2313 // mode-info read) as the >=16 intra-in-inter block's own copy in
2314 // [`decode_inter_block`]; the mode context, the colour cache and the
2315 // `palette_uv_mode` context are this leaf's REAL ones, not the
2316 // hardcoded 0/empty pair the refusal could get away with while no
2317 // neighbour could ever be a palette (class
2318 // [[cdf-row-held-constant]]). `av1_get_palette_bsize_ctx(BLOCK_8X8)`
2319 // = `num_pels_log2_lookup[BLOCK_8X8] - 6` = row 0.
2320 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(leaf_mi);
2321 let palette_uv_cache = neighbours.palette_uv_cache_mi(leaf_mi);
2322 let mut palette_y_pending: Option<(usize, [u16; 8])> = None;
2323 let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None;
2324 if allow_screen_content_tools && let Some(bsize_ctx) = palette_bsize_ctx(SIDE) {
2325 let use_palette_y = mode == DC_PRED
2326 && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][palette_ctx]) != 0;
2327 if use_palette_y {
2328 let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]);
2329 palette_y_pending = Some((n, read_palette_colors_y(dec, n, &palette_cache, fctx)));
2330 }
2331 // lane-uv8 r1: `read_palette_mode_info` reads the UV symbol only
2332 // when `uv_mode == UV_DC_PRED` (decodemv.c).
2333 let use_palette_uv = has_chroma
2334 && uv_mode == DC_PRED
2335 && dec.symbol(&mut cdfs.palette_uv_mode[usize::from(use_palette_y)]) != 0;
2336 if crate::envflags::env_flag!("EC_PALSYN") {
2337 eprintln!(
2338 "EC_PALSYN leaf8 mi={},{} bw=8 bh=8 mode={mode} uv={uv_mode} ctx={palette_ctx} y={} uv={} rng={}",
2339 leaf_mi.0,
2340 leaf_mi.1,
2341 palette_y_pending.map_or(0, |(n, _)| n),
2342 u8::from(use_palette_uv),
2343 dec.debug_state().0
2344 );
2345 }
2346 if use_palette_uv {
2347 let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]);
2348 let (u_colors, v_colors) = read_palette_colors_uv(dec, n, &palette_uv_cache, fctx);
2349 palette_uv_pending = Some((n, u_colors, v_colors));
2350 }
2351 }
2352 // lane-fiinter r1: `read_filter_intra_mode_info` (libaom `decodemv.c`,
2353 // the tail of `read_intra_block_mode_info`) -- an intra block inside
2354 // an INTER frame reads `use_filter_intra` in exactly the same place a
2355 // key-frame block does, right after the palette syntax. Nothing read
2356 // it here before this round, and aomenc enables filter intra by
2357 // default, so every inter frame carrying one desynced at this symbol.
2358 // `av1_filter_intra_allowed`'s `palette_size[0] == 0` term is implied:
2359 // a real palette-Y block already returned above.
2360 let mut filter_intra = None;
2361 // lane-uv8 r2: the oracle's `EC_ISTEP` ladder (`EC_TRACE_MODE_STEP`)
2362 // prints `use_filter_intra` for an intra block inside an INTER frame
2363 // and nothing else, so this leaf needs the same two lines for a
2364 // range-ladder diff against it.
2365 let ec_istep8 = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");
2366 if mode == DC_PRED
2367 && fctx.enable_filter_intra_inter.with(std::cell::Cell::get)
2368 // `av1_filter_intra_allowed` (reconintra.h:77) excludes a
2369 // palette-Y block, so no `use_filter_intra` symbol exists there.
2370 && palette_y_pending.is_none()
2371 && let Some(class) = filter_intra_size_class(SIDE)
2372 {
2373 let use_fi = dec.symbol(&mut cdfs.filter_intra[class]) != 0;
2374 if ec_istep8 {
2375 eprintln!(
2376 "EC_ISTEP mi_row={} mi_col={} name=use_filter_intra val={} rng={}",
2377 leaf_mi.0,
2378 leaf_mi.1,
2379 u8::from(use_fi),
2380 dec.debug_state().0
2381 );
2382 }
2383 if use_fi {
2384 hit!(FILTER_INTRA_HITS);
2385 hit!(INTRA_IN_INTER_FILTER_INTRA_HITS);
2386 let fi = dec.symbol(&mut cdfs.filter_intra_mode);
2387 if ec_istep8 {
2388 eprintln!(
2389 "EC_ISTEP mi_row={} mi_col={} name=filter_intra_mode val={fi} rng={}",
2390 leaf_mi.0,
2391 leaf_mi.1,
2392 dec.debug_state().0
2393 );
2394 }
2395 filter_intra = Some(fi);
2396 }
2397 }
2398 // lane-t900 r23: `av1_visit_palette` -- the two colour-index maps, Y
2399 // then the shared chroma one, after the WHOLE mode-info read.
2400 let palette_y = palette_y_pending.map(|(n, colors)| {
2401 let map = decode_color_index_map_wh(
2402 dec,
2403 cdfs,
2404 n,
2405 SIDE,
2406 SIDE,
2407 palette_onscreen(rmi, cmi, SIDE, SIDE, fctx),
2408 false,
2409 );
2410 hit!(PALETTE_HITS);
2411 hit!(INTRA_IN_INTER_PALETTE_Y_HITS);
2412 hit_do! {
2413 INTER8_PALETTE_HITS.with(|c| {
2414 let mut v = c.get();
2415 v.0 += 1;
2416 c.set(v);
2417 });
2418 }
2419 PaletteY {
2420 size: n,
2421 colors,
2422 map,
2423 }
2424 });
2425 let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| {
2426 // `av1_get_plane_block_size(BLOCK_8X8, ss)` at the sequence's own
2427 // subsampling: BLOCK_4X4 at 4:2:0, BLOCK_8X8 at 4:4:4, and at
2428 // 4:2:2 the BLOCK_4X8 plane block (lane-av1-422sub8rect).
2429 let on = palette_onscreen_uv(
2430 (SIDE, SIDE),
2431 palette_onscreen(rmi, cmi, SIDE, SIDE, fctx),
2432 (chroma_w, chroma_h),
2433 (ss_x(fctx), ss_y(fctx)),
2434 );
2435 let map = decode_color_index_map_wh(dec, cdfs, n, chroma_w, chroma_h, on, true);
2436 hit!(PALETTE_UV_HITS);
2437 hit!(INTRA_IN_INTER_PALETTE_UV_HITS);
2438 hit_do! {
2439 INTER8_PALETTE_HITS.with(|c| {
2440 let mut v = c.get();
2441 v.1 += 1;
2442 c.set(v);
2443 });
2444 }
2445 PaletteUv {
2446 size: n,
2447 u_colors,
2448 v_colors,
2449 map,
2450 }
2451 });
2452 palette_record8 = (
2453 palette_y.as_ref().map_or(0, |p| p.size),
2454 palette_y.as_ref().map_or([0u16; 8], |p| p.colors),
2455 palette_uv.as_ref().map_or(0, |p| p.size),
2456 palette_uv.as_ref().map_or([0u16; 8], |p| p.u_colors),
2457 );
2458 // A palette block predicts from its own colour-index map, never from
2459 // the block edge (spec 7.11.2/7.11.4) -- these ride the
2460 // [`PALETTE_PRED`] slot into each `reconstruct`/`read_plane` call
2461 // below, exactly as the key-frame and >=16 intra-in-inter paths do.
2462 let palette_y_buf: Option<Vec<u16>> = palette_y
2463 .as_ref()
2464 .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect());
2465 let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|p| {
2466 (
2467 p.map.iter().map(|&i| p.u_colors[i as usize]).collect(),
2468 p.map.iter().map(|&i| p.v_colors[i as usize]).collect(),
2469 )
2470 });
2471 mode_for_tx = mode;
2472 let (mi_row, mi_col) = leaf_mi;
2473 grid.fill_rect(
2474 mi_row,
2475 mi_col,
2476 2,
2477 2,
2478 MiInfo {
2479 is_inter: false,
2480 ref_frame: -1,
2481 ref_frame1: NO_REF1,
2482 mv1: (0, 0),
2483 mv: (0, 0),
2484 is_new_mv: false,
2485 size: 2,
2486 size_h: 2,
2487 is_global_mv0: false,
2488 is_global_mv1: false,
2489 },
2490 );
2491
2492 // lane-leaf8tx r1: the 8x8 leaf's own intra `tx_depth` (libaom
2493 // `read_tx_size` -> `read_selected_tx_size`, max depth 1 at
2494 // BLOCK_8X8) resolves to TX_4X4, and `decode_block`
2495 // (`decodeframe.c`) then codes one intra prediction + one
2496 // coefficient set PER 4x4 transform unit in raster order, each unit
2497 // predicting off the units reconstructed before it -- the same loop
2498 // the >=16x16 intra-in-inter arm runs. Chroma stays one 4x4 unit
2499 // (`av1_get_max_uv_txsize`).
2500 let intra_leaves = read_block_tx_size(
2501 dec,
2502 cdfs,
2503 neighbours,
2504 leaf_mi,
2505 SIDE,
2506 (mi_cols as usize, mi_rows as usize),
2507 false,
2508 skip,
2509 fctx,
2510 )?
2511 .1;
2512 // lane-leaf8tx r4: the per-TU loop below is entropy- and pixel-exact
2513 // against aomdec once `tx_size_context_txfm` stopped reading
2514 // `above_inter`/`left_inter` four mi away (r3), so the refusal that
2515 // used to sit here is lifted; gate
2516 // `a_real_aomenc_{,10bit_}inter_sequence_with_an_angle_delta_8x8_intra_leaf_decodes_pixel_exact`.
2517 split8 = intra_leaves.is_some();
2518 let reach = Reach::of(SIDE, px, py, y.width, y.height, fctx);
2519 if let Some(leaves) = intra_leaves {
2520 for &(row, col, tx_px, _) in &leaves {
2521 let tu_mi = (leaf_mi.0 + row, leaf_mi.1 + col);
2522 let (tu_px, tu_py) = (px + col * MI, py + row * MI);
2523 // A transform unit inside a block is not a block at that
2524 // position: top-right / bottom-left availability is the
2525 // block's, narrowed by the unit's offset inside it.
2526 let tu_reach = Reach::of_tu(SIDE, SIDE, col * MI, row * MI, tx_px, tx_px, reach);
2527 // This unit's own window on the block's palette prediction
2528 // (the whole-block buffer would be indexed at the wrong
2529 // stride by the first unit).
2530 if let Some(buf) = &palette_y_buf {
2531 hit!(PALETTE_SPLIT_TX_HITS);
2532 let window: Vec<u16> = (0..tx_px)
2533 .flat_map(|i| {
2534 let base = (row * MI + i) * SIDE + col * MI;
2535 buf[base..base + tx_px].iter().copied()
2536 })
2537 .collect();
2538 set_palette_pred(window, fctx);
2539 }
2540 let tu_grid = if skip {
2541 push_intra(
2542 y,
2543 u,
2544 v,
2545 0,
2546 tu_px,
2547 tu_py,
2548 tx_px,
2549 mode,
2550 angle_delta_y,
2551 tu_reach,
2552 &ZERO_RESIDUAL[..tx_px * tx_px],
2553 None,
2554 filter_intra,
2555 smooth_neighbor,
2556 fctx,
2557 );
2558 Grid::Zero(tx_px * tx_px)
2559 } else {
2560 // The unit is smaller than the block it sits in, so
2561 // `txb_skip_ctx` is the neighbour-magnitude table, not
2562 // the lone-TU 0 (`get_txb_ctx_general`).
2563 let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI);
2564 read_plane(
2565 dec,
2566 cdfs,
2567 // Intra 4x4 luma: seven-type
2568 // `EXT_TX_SET_DTT4_IDTX_1DDCT` unless reduced, whose
2569 // CDF row is the intra dir (`fi_tx_row` inside
2570 // `read_plane` maps a filter-intra block's).
2571 txbset_for(tx_px, reduced_tx_set),
2572 default_scan(tx_px),
2573 0,
2574 neighbours.around_mi(tu_mi, tx_px)[0],
2575 mode,
2576 mode,
2577 angle_delta_y,
2578 tu_reach,
2579 y,
2580 u,
2581 v,
2582 tu_px,
2583 tu_py,
2584 tx_px,
2585 tx_px,
2586 base_q_idx,
2587 None,
2588 filter_intra,
2589 Some(tu_skip_ctx),
2590 smooth_neighbor,
2591 fctx,
2592 )?
2593 };
2594 neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid);
2595 }
2596 }
2597 if skip {
2598 if !split8 {
2599 if let Some(buf) = &palette_y_buf {
2600 set_palette_pred(buf.clone(), fctx);
2601 }
2602 push_intra(
2603 y,
2604 u,
2605 v,
2606 0,
2607 px,
2608 py,
2609 SIDE,
2610 mode,
2611 angle_delta_y,
2612 reach,
2613 &ZERO_RESIDUAL[..SIDE * SIDE],
2614 None,
2615 filter_intra,
2616 smooth_neighbor,
2617 fctx,
2618 );
2619 }
2620 // CfL's AC contribution is the luma this leaf just reconstructed,
2621 // averaged over the 4x4 chroma block (`cfl_ac_q3`, spec 7.11.5).
2622 let ac = alpha.map(|_| cfl_src(px, py, SIDE));
2623 if let Some((ub, _)) = &palette_uv_bufs {
2624 set_palette_pred(ub.clone(), fctx);
2625 }
2626 // lane-av1-422sub8rect: the plane block is the (chroma_w,
2627 // chroma_h) rect at 4:2:2 -- the recorded prediction/write uses
2628 // the rect push.
2629 push_intra_rect(
2630 y,
2631 u,
2632 v,
2633 1,
2634 cpx,
2635 cpy,
2636 chroma_w,
2637 chroma_h,
2638 uv_predict_mode,
2639 angle_delta_uv,
2640 reach,
2641 &ZERO_RESIDUAL[..chroma_w * chroma_h],
2642 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
2643 None,
2644 smooth_neighbor_uv,
2645 fctx,
2646 );
2647 if let Some((_, vb)) = &palette_uv_bufs {
2648 set_palette_pred(vb.clone(), fctx);
2649 }
2650 push_intra_rect(
2651 y,
2652 u,
2653 v,
2654 2,
2655 cpx,
2656 cpy,
2657 chroma_w,
2658 chroma_h,
2659 uv_predict_mode,
2660 angle_delta_uv,
2661 reach,
2662 &ZERO_RESIDUAL[..chroma_w * chroma_h],
2663 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
2664 None,
2665 smooth_neighbor_uv,
2666 fctx,
2667 );
2668 luma_grid = Grid::Zero(SIDE * SIDE);
2669 u_grid = Grid::Zero(chroma_w * chroma_h);
2670 v_grid = Grid::Zero(chroma_w * chroma_h);
2671 } else {
2672 let around = neighbours.around_mi(leaf_mi, 8);
2673 luma_grid = if split8 {
2674 // Already coded and reconstructed unit by unit above; the
2675 // block-level grid only feeds the neighbour write-back,
2676 // which the `saved_luma_ctx` restore below keeps per-TU.
2677 Grid::Zero(SIDE * SIDE)
2678 } else {
2679 if let Some(buf) = &palette_y_buf {
2680 set_palette_pred(buf.clone(), fctx);
2681 }
2682 read_plane(
2683 dec,
2684 cdfs,
2685 // lane-uv8 r3: an intra leaf inside an inter frame is
2686 // `is_inter == 0` in `av1_get_ext_tx_set_type`, so its 8x8
2687 // luma reads the INTRA set -- seven-type
2688 // `EXT_TX_SET_DTT4_IDTX_1DDCT` when `reduced_tx_set == 0`,
2689 // five-type `EXT_TX_SET_DTT4_IDTX` when it is 1. Hardcoding
2690 // the reduced set read the wrong ALPHABET (class
2691 // [[wrong-alphabet-same-value]]) and desynced at the leaf's
2692 // first `tx_type`.
2693 txbset_for(8, reduced_tx_set),
2694 scan8,
2695 0,
2696 around[0],
2697 mode,
2698 mode,
2699 angle_delta_y,
2700 reach,
2701 y,
2702 u,
2703 v,
2704 px,
2705 py,
2706 SIDE,
2707 TX8,
2708 base_q_idx,
2709 None,
2710 filter_intra,
2711 None,
2712 smooth_neighbor,
2713 fctx,
2714 )?
2715 };
2716 let ac = alpha.map(|_| cfl_src(px, py, SIDE));
2717 // lane-av1-422sub8rect: at 4:2:2 the plane block is the BLOCK_4X8
2718 // rect and the key-frame arm's own reader applies -- one
2719 // TX_4X8 `ChromaRect8x4` unit per plane through
2720 // [`read_rect_chroma_unit`] with the per-chroma-cell context
2721 // walk ([`Neighbours::around_mi_422_chroma`], the
2722 // lane-av1-422f model this leaf's key-frame twin proves
2723 // byte-exact). 4:2:0/4:4:4 keep the square [`read_plane`] read.
2724 let (chroma_around_u, chroma_around_v) = if chroma_422 {
2725 let ca = neighbours.around_mi_422_chroma(leaf_mi, 8, 8);
2726 (ca[1], ca[2])
2727 } else {
2728 (around[1], around[2])
2729 };
2730 // lane-av1-llintra8: lossless codes TX_4X4 on EVERY plane
2731 // (`av1_get_tx_size`, blockd.h:1383), so this intra leaf's chroma
2732 // plane block is a raster of TX_4X4 units per plane, plane-major
2733 // -- the same per-unit walk the >=16x16 intra-in-inter block
2734 // runs, not one TX_8X8 unit (whose WHT hits `TxParams::run`'s
2735 // `(8, 8) != (4, 4)` lossless assert). The plane block is
2736 // PER-AXIS, `av1_ss_size_lookup[BLOCK_8X8][ss_x][ss_y]`: 8x8 at
2737 // 4:4:4 (2x2 units) and 4x8 at 4:2:2 (1x2), so both walk here and
2738 // only 4:2:0's 4x4 keeps the single-unit read in the `else`
2739 // below (`plane_bsize == txsize_to_bsize[tx_size]`, ctx_offset 7).
2740 // The walk stamps each unit's own coefficient context
2741 // (`record_mi_chroma` inside it), so the tail's whole-block
2742 // `record_mi` gets its chroma half saved/restored around --
2743 // the same rule the INTER arms'
2744 // `leaf8_inter_chroma_lossless` obeys.
2745 if lossless(fctx) && (chroma_w > 4 || chroma_h > 4) && !mono(fctx) {
2746 let (mut uo, mut vo) = (Vec::new(), Vec::new());
2747 read_intra_chroma_lossless(
2748 y,
2749 u,
2750 v,
2751 dec,
2752 cdfs,
2753 neighbours,
2754 leaf_mi,
2755 (px, py),
2756 (cpx, cpy),
2757 SIDE,
2758 (chroma_w, chroma_h),
2759 (0, 0),
2760 (chroma_w, chroma_h),
2761 chroma_w,
2762 reach,
2763 (y.width, y.height),
2764 mode,
2765 uv_predict_mode,
2766 angle_delta_uv,
2767 palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])),
2768 smooth_neighbor_uv,
2769 base_q_idx,
2770 &mut uo,
2771 &mut vo,
2772 fctx,
2773 )?;
2774 u_grid = if uo.is_empty() {
2775 Grid::Zero(chroma_w * chroma_h)
2776 } else {
2777 Grid::Own(uo)
2778 };
2779 v_grid = if vo.is_empty() {
2780 Grid::Zero(chroma_w * chroma_h)
2781 } else {
2782 Grid::Own(vo)
2783 };
2784 chroma_stamped_per_unit = true;
2785 hit!(LLINTRA8_CHROMA_WALK_HITS);
2786 } else {
2787 if let Some((ub, _)) = &palette_uv_bufs {
2788 set_palette_pred(ub.clone(), fctx);
2789 }
2790 u_grid = if chroma_422 {
2791 read_rect_chroma_unit(
2792 dec,
2793 cdfs,
2794 chroma_set,
2795 chroma_scan,
2796 chroma_w,
2797 chroma_h,
2798 1,
2799 chroma_around_u,
2800 uv_predict_mode,
2801 angle_delta_uv,
2802 reach,
2803 y,
2804 u,
2805 v,
2806 cpx,
2807 cpy,
2808 base_q_idx,
2809 None,
2810 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
2811 smooth_neighbor_uv,
2812 fctx,
2813 )?
2814 } else {
2815 read_plane(
2816 dec,
2817 cdfs,
2818 chroma_set,
2819 chroma_scan,
2820 1,
2821 chroma_around_u,
2822 mode,
2823 uv_predict_mode,
2824 angle_delta_uv,
2825 reach,
2826 y,
2827 u,
2828 v,
2829 cpx,
2830 cpy,
2831 chroma_w,
2832 chroma_tx,
2833 base_q_idx,
2834 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
2835 None,
2836 None,
2837 smooth_neighbor_uv,
2838 fctx,
2839 )?
2840 };
2841 if let Some((_, vb)) = &palette_uv_bufs {
2842 set_palette_pred(vb.clone(), fctx);
2843 }
2844 v_grid = if chroma_422 {
2845 read_rect_chroma_unit(
2846 dec,
2847 cdfs,
2848 chroma_set,
2849 chroma_scan,
2850 chroma_w,
2851 chroma_h,
2852 2,
2853 chroma_around_v,
2854 uv_predict_mode,
2855 angle_delta_uv,
2856 reach,
2857 y,
2858 u,
2859 v,
2860 cpx,
2861 cpy,
2862 base_q_idx,
2863 None,
2864 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
2865 smooth_neighbor_uv,
2866 fctx,
2867 )?
2868 } else {
2869 read_plane(
2870 dec,
2871 cdfs,
2872 chroma_set,
2873 chroma_scan,
2874 2,
2875 chroma_around_v,
2876 mode,
2877 uv_predict_mode,
2878 angle_delta_uv,
2879 reach,
2880 y,
2881 u,
2882 v,
2883 cpx,
2884 cpy,
2885 chroma_w,
2886 chroma_tx,
2887 base_q_idx,
2888 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
2889 None,
2890 None,
2891 smooth_neighbor_uv,
2892 fctx,
2893 )?
2894 };
2895 }
2896 }
2897 }
2898 // lane-txselect: a split leaf's plane-0 neighbour context is per 4x4
2899 // transform unit (written by `record_mi_luma` inside `read_inter_luma8`),
2900 // but `record_mi` rewrites all three planes of these cells at once -- so
2901 // save plane 0 across it, exactly as `record_split_luma` leaves plane 0
2902 // alone at the bigger block sizes.
2903 // lane-lossless3: `!skip` too. A SKIP block codes no coefficients and so
2904 // publishes nothing per transform unit, and on a LOSSLESS frame
2905 // `read_block_tx_size` hands back 4x4 leaves for a skip block as well
2906 // (libaom's `read_tx_size` returns TX_4X4 before it reads anything), so
2907 // `split8` is true over an UNTOUCHED band -- the restore then put the
2908 // previous block's levels back over the zeros `record_mi` had just
2909 // written, where libaom runs `av1_reset_entropy_context`. Class
2910 // [[override-slot-on-one-arm]]: a save/restore is only valid on the arm
2911 // that actually wrote the per-TU state.
2912 let saved_luma_ctx = (split8 && !skip).then(|| {
2913 (
2914 [
2915 neighbours.left[leaf_mi.0][0],
2916 neighbours.left[leaf_mi.0 + 1][0],
2917 ],
2918 [
2919 neighbours.above[leaf_mi.1][0],
2920 neighbours.above[leaf_mi.1 + 1][0],
2921 ],
2922 )
2923 });
2924 // lane-t900 r23: every leaf stamps its palette state (all-zero for an
2925 // inter leaf or a non-palette intra one, real for a palette block) into
2926 // the mi-granular neighbour bands, so the next intra block's
2927 // `av1_get_palette_mode_ctx` and colour cache see exactly what libaom's
2928 // mode-info grid holds.
2929 record_strip_palette(
2930 neighbours,
2931 leaf_mi,
2932 8,
2933 8,
2934 palette_record8.0,
2935 palette_record8.1,
2936 palette_record8.2,
2937 palette_record8.3,
2938 );
2939 let saved_chroma_ctx = chroma_stamped_per_unit.then(|| {
2940 (
2941 [
2942 [neighbours.left[leaf_mi.0][1], neighbours.left[leaf_mi.0][2]],
2943 [
2944 neighbours.left[leaf_mi.0 + 1][1],
2945 neighbours.left[leaf_mi.0 + 1][2],
2946 ],
2947 ],
2948 [
2949 [
2950 neighbours.above[leaf_mi.1][1],
2951 neighbours.above[leaf_mi.1][2],
2952 ],
2953 [
2954 neighbours.above[leaf_mi.1 + 1][1],
2955 neighbours.above[leaf_mi.1 + 1][2],
2956 ],
2957 ],
2958 )
2959 });
2960 neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);
2961 if let Some((left, above)) = saved_chroma_ctx {
2962 // The walk's per-unit stamps are the block's real chroma coefficient
2963 // contexts (`av1_set_contexts` per TX_4X4 unit); put them back over
2964 // `record_mi`'s one composed state.
2965 for (cell, uv) in left.into_iter().enumerate() {
2966 neighbours.left[leaf_mi.0 + cell][1] = uv[0];
2967 neighbours.left[leaf_mi.0 + cell][2] = uv[1];
2968 }
2969 for (cell, uv) in above.into_iter().enumerate() {
2970 neighbours.above[leaf_mi.1 + cell][1] = uv[0];
2971 neighbours.above[leaf_mi.1 + cell][2] = uv[1];
2972 }
2973 }
2974 // lane-uv8 r1: this leaf never stamped a mode band at all, so the block
2975 // below/right of it read whatever block last wrote the coarse [`SUB`]
2976 // slot -- now that an intra leaf here can code a smooth/directional
2977 // `uv_mode`, its chroma neighbours must see it (and an inter leaf must
2978 // stamp `DC_PRED`, what libaom stores for a non-intra block). Same pair
2979 // [`decode_leaf8`] writes, plus the coarse fallback slots.
2980 neighbours.above_uv_mode[c] = uv_predict_mode;
2981 neighbours.left_uv_mode[r] = uv_predict_mode;
2982 neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode_for_tx);
2983 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);
2984 if let Some((left, above)) = saved_luma_ctx {
2985 for (cell, state) in left.into_iter().enumerate() {
2986 neighbours.left[leaf_mi.0 + cell][0] = state;
2987 }
2988 for (cell, state) in above.into_iter().enumerate() {
2989 neighbours.above[leaf_mi.1 + cell][0] = state;
2990 }
2991 }
2992 // lane-gmaffine r2: the deblock grid's ref id is the leaf's OWN reference
2993 // (r1 taught this leaf non-LAST refs; the hardcoded LAST_FRAME made every
2994 // GOLDEN/ALTREF leaf read as LAST at the loop-filter's ref/mv edge test).
2995 // lane-cdef r1: the fall-through twin of the compound arm's skip-band
2996 // write above -- `skip` is one flag for the whole 8x8 leaf (read at
2997 // `decode.rs`'s `skip_ctx` site), `split8` only splits its transform.
2998 // lane-intersub8 r5: ... and it counts too. r1 incremented the counter in
2999 // the COMPOUND early-return arm only, so the gate's assert really read
3000 // "a COMPOUND 8x8 leaf wrote the band"; once main's inter16ab/r14 routing
3001 // landed, the 10-bit cq12 arm's leaves come through here instead and the
3002 // gate failed on an instrumentation gap, with the band written either way.
3003 hit!(INTER8_SKIP_BAND_HITS);
3004 neighbours.fill_skip_grid(leaf_mi, 2, skip);
3005 neighbours.fill_lf_grid(
3006 leaf_mi,
3007 2,
3008 if split8 { 4 } else { 8 },
3009 if is_inter {
3010 leaf_refs.0.max(LAST_FRAME)
3011 } else {
3012 0
3013 },
3014 fctx,
3015 );
3016 Ok((
3017 skip,
3018 is_inter,
3019 skip_mode,
3020 compound_ctx8,
3021 leaf_filter_syms,
3022 leaf_refs,
3023 ))
3024}