diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 70f27bef..aff6ebb2 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -18699,6 +18699,19 @@ fn decode_leaf8( } } else if resolved != 4 { let around = neighbours.around_mi(leaf_mi, 8); + // lane-av1-422h: the 4:2:2 chroma rect unit's `get_txb_ctx_general` + // reads its above votes over CHROMA 4-px cells -- at ss_x 1 one chroma + // cell spans TWO luma mi columns, so the per-luma-mi sum counts each + // above chroma column twice and `dc_sign_ctx`'s signum flips whenever + // the doubled sum crosses zero (the same class + // [`Neighbours::around_mi_422_chroma`] fixes for the rect readers; + // measured at mi(2,24) plane 2: ours dc_sign row 0, oracle row 2). + // The left extent is unsubsquared at ss_y 0 and stays one-to-one. + let chroma_around = if chroma_422 { + neighbours.around_mi_422_chroma(leaf_mi, 8, 8) + } else { + around + }; if let Some(buf) = &palette_y_buf { set_palette_pred(buf.clone(), fctx); } @@ -18742,14 +18755,14 @@ fn decode_leaf8( // at ss (1,0) == TX_4X8), covering the plane block exactly, off the // leaf's own 8x8-span entropy context (`chroma_tiled`'s convention). u_grid = leaf8_chroma422_unit( - dec, cdfs, around[1], uv_predict_mode, angle_delta_uv, reach, + dec, cdfs, chroma_around[1], uv_predict_mode, angle_delta_uv, reach, 1, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), false, intrabc_bufs.as_ref().map(|(_, ub, _)| ub.clone()) .or_else(|| palette_uv_bufs.as_ref().map(|(ub, _)| ub.clone())), u, cpx, cpy, smooth_neighbor_uv, fctx, )?; v_grid = leaf8_chroma422_unit( - dec, cdfs, around[2], uv_predict_mode, angle_delta_uv, reach, + dec, cdfs, chroma_around[2], uv_predict_mode, angle_delta_uv, reach, 2, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), false, intrabc_bufs.as_ref().map(|(_, _, vb)| vb.clone()) .or_else(|| palette_uv_bufs.as_ref().map(|(_, vb)| vb.clone())), @@ -18920,7 +18933,13 @@ fn decode_leaf8( } } let ac = alpha.map(|_| cfl_src(px, py, 8)); - let chroma_around = neighbours.around_mi(leaf_mi, 8); + // lane-av1-422h: same ss_x-1 dc-vote sampling as the whole-leaf arm + // above -- the doubled above sum crosses zero at mi(2,24) plane 2. + let chroma_around = if chroma_422 { + neighbours.around_mi_422_chroma(leaf_mi, 8, 8) + } else { + neighbours.around_mi(leaf_mi, 8) + }; // lane-av1intrapred: the non-vacuity counter -- armed slot consulted // by this arm's chroma reads means the frame-copy + inherited-type // route ran; zero at gate time means the fixture stopped reaching it. @@ -19529,10 +19548,20 @@ fn sub8_leaf_chroma422( neighbours.record_uv_mode_mi(lmi.0, lmi.1, 1, 1, uv_predict_mode); let (px, py) = (lmi.1 * MI, lmi.0 * MI); let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx)); + // lane-av1-422h: the entropy-context anchor is the unit's FLOOR chroma + // cell (`pd->above_entropy_context + (mi_col >> ss_x)`): an ODD-column + // leaf's 4-px unit starts at a chroma px that is NOT cell aligned, and + // both its ctx read and its ctx write live in the cell containing that + // start -- one luma mi column to the LEFT of the leaf's own. Even-column + // (cell-aligned) leaves keep their own column. The state write spans the + // anchor's two luma mi columns, so the second (odd) leaf of a split group + // overwrites exactly the cell the first one wrote, as libaom's + // `av1_set_entropy_contexts` per-TU writes do. + let ctx_mi = (lmi.0, lmi.1 & !1); // The square unit takes the leaf's own `Reach::of` (its luma's), the way // [`decode_leaf8`]'s 422 arm passes the enclosing block's luma reach. let reach = Reach::of(4, px, py, y.width, y.height, fctx); - let chroma_around = neighbours.around_mi_422_chroma(lmi, 8, 4); + let chroma_around = neighbours.around_mi_422_chroma(ctx_mi, 8, 4); let ac = alpha.map(|_| cfl_src_rect(px, py, 8, 4)); let grids: (Grid, Grid) = if skip { // A skipped chroma-reference leaf still predicts (the CfL contribution @@ -19601,13 +19630,13 @@ fn sub8_leaf_chroma422( let u_state = neighbour_state(&u_grid); let v_state = neighbour_state(&v_grid); if lmi.0 < neighbours.mi_rows { - neighbours.left[lmi.0][1] = u_state; - neighbours.left[lmi.0][2] = v_state; + neighbours.left[ctx_mi.0][1] = u_state; + neighbours.left[ctx_mi.0][2] = v_state; } for cell in 0..2 { - if lmi.1 + cell < neighbours.mi_cols { - neighbours.above[lmi.1 + cell][1] = u_state; - neighbours.above[lmi.1 + cell][2] = v_state; + if ctx_mi.1 + cell < neighbours.mi_cols { + neighbours.above[ctx_mi.1 + cell][1] = u_state; + neighbours.above[ctx_mi.1 + cell][2] = v_state; } } Ok((u_grid, v_grid)) @@ -19699,7 +19728,12 @@ fn decode_leaf_split4( let has_chroma = if chroma_444 { true } else if chroma_422 { - (lmi.1 & 1) == 0 + // lane-av1-422h: `is_chroma_reference`'s column clause at ss_x 1 is + // `(mi_col & 1)` for a BLOCK_4X4 leaf -- the ODD-column leaf is the + // chroma reference (oracle, mi(30,42) split group: uv_mode read at + // mi(30,43) and mi(31,43) only). The even-column rule this + // replaces came from 422f's pre-partition-trace misreading. + (lmi.1 & 1) == 1 } else { i == 3 }; @@ -20107,6 +20141,15 @@ fn decode_leaf_rect8( // full-resolution rect chroma unit right after its luma. let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0; let mut last_uv444 = DC_PRED; + // lane-av1-422h: at ss (1,0) `is_chroma_reference` + // (av1_common_int.h:1459) resolves per strip shape -- + // `((mi_row & 1) || !(bh_mi & 1) || !ss_y) && ((mi_col & 1) || !(bw_mi & 1) || !ss_x)`: + // a HORZ pair is two BLOCK_8X4 strips at the group's even column, so + // BOTH strips are chroma references (`!(bw & 1)`); a VERT pair is two + // BLOCK_4X8 strips, and the column clause keeps only the ODD-column + // strip (i == 1, the same leaf the 4:2:0 rule reads chroma on). + let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0; + let mut last_uv422 = DC_PRED; for i in 0..2usize { let lmi = if vert { (leaf_mi.0, leaf_mi.1 + i) @@ -20125,7 +20168,13 @@ fn decode_leaf_rect8( } else { neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode) }; - let has_chroma = chroma_444 || i == 1; + let has_chroma = if chroma_444 { + true + } else if chroma_422 { + !vert || i == 1 + } else { + i == 1 + }; let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1); let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8( dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, @@ -20312,6 +20361,15 @@ fn decode_leaf_rect8( neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, )?; last_uv444 = DC_PRED; + } else if chroma_422 { + // lane-av1-422h: same at ss (1,0) -- the strip's own square + // TX_4X4 chroma unit at its halved position. + sub8_leaf_chroma422( + dec, cdfs, neighbours, lmi, DC_PRED, 0, None, skip, + Some(dv), y, u, v, scan4, base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, + )?; + last_uv422 = DC_PRED; } else { last_uv = Some((DC_PRED, 0, None)); last_intrabc = Some(dv); @@ -20469,6 +20527,17 @@ fn decode_leaf_rect8( neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, )?; last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + } else if chroma_422 { + // lane-av1-422h: the strip's own square TX_4X4 chroma unit + // per plane right after its split luma (one per ref strip). + let (uv_mode, angle_delta_uv, alpha) = + chroma.expect("4:2:2 chroma references read uv_mode"); + sub8_leaf_chroma422( + dec, cdfs, neighbours, lmi, uv_mode, angle_delta_uv, alpha, + skip, None, y, u, v, scan4, base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, + )?; + last_uv422 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; } else { last_uv = chroma; } @@ -20558,6 +20627,20 @@ fn decode_leaf_rect8( neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, )?; last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + } else if chroma_422 { + // lane-av1-422h: the strip's own square TX_4X4 chroma unit + // per plane right after its luma -- libaom codes each + // BLOCK_8X4 strip's chroma under the strip itself (both + // strips of a HORZ pair are chroma references), not one + // shared group unit. + let (uv_mode, angle_delta_uv, alpha) = + chroma.expect("4:2:2 chroma references read uv_mode"); + sub8_leaf_chroma422( + dec, cdfs, neighbours, lmi, uv_mode, angle_delta_uv, alpha, + skip, None, y, u, v, scan4, base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, + )?; + last_uv422 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; } else { last_uv = chroma; } @@ -20574,6 +20657,15 @@ fn decode_leaf_rect8( neighbours.above_uv_mode[c] = last_uv444; neighbours.left_uv_mode[r] = last_uv444; (Grid::Zero(16), Grid::Zero(16)) + } else if chroma_422 { + // lane-av1-422h: every chroma-reference strip coded and reconstructed + // its own chroma unit in the loop above (and stamped its own entropy + // span), so the 4:2:0 shared group unit below must not run. Only the + // coarse 16x16 slots remain: libaom's `above_uv_mode`/`left_uv_mode` + // end up holding the LAST chroma reference's mode (decode order). + neighbours.above_uv_mode[c] = last_uv422; + neighbours.left_uv_mode[r] = last_uv422; + (Grid::Zero(16), Grid::Zero(16)) } else { let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI); let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx)); @@ -20698,7 +20790,9 @@ fn decode_leaf_rect8( } // lane-av1-444: at 4:4:4 [`sub8_leaf_chroma444`] already stamped each // leaf's own span as it decoded; these placeholder grids carry no state. - if !chroma_444 { + // lane-av1-422h: same at ss (1,0) -- [`sub8_leaf_chroma422`] stamped each + // chroma-reference strip's own span in decode order. + if !(chroma_444 || chroma_422) { let round_up_even = |n: usize| n.div_ceil(2) * 2; let bound_h = round_up_even(neighbours.mi_rows); let bound_w = round_up_even(neighbours.mi_cols); diff --git a/lanes/av1422h.report.md b/lanes/av1422h.report.md new file mode 100644 index 00000000..bdb39b70 --- /dev/null +++ b/lanes/av1422h.report.md @@ -0,0 +1,96 @@ +# lane-av1-422h — 4:2:2 sub-8/rect chroma model proven rng-exact to the bottom-edge SBs; refusal stays + +## Outcome + +The assignment's premise — "ours reads a non-SPLIT partition at mi(8,10)" — was +FALSE, and this round proves it with partition-level oracle traces: at mi(8,10) +both decoders read `bsize=3 ctx=0 rng=37068 → value=1` (PARTITION_HORZ). +`read_partition` in the oracle source already carried an `EC_PART` probe +(patch never enabled by the 422f/g generation recipe), so this round's traces +are the first with the walk checkpointed per partition read; pairing them +(`EC_PART` rng values, tell offset constant +14) shows the true first +divergences and lets every fix below be verified rng-for-rng. + +Four 4:2:2 chroma-model defects found and fixed (all in `decode_leaf_rect8`, +`decode_leaf8`, `decode_leaf_split4`/`sub8_leaf_chroma422`, `decode_block`): + +1. **`decode_leaf_rect8` (BLOCK_8X4/BLOCK_4X8 strips) used the 4:2:0 + `i == 1`-only chroma rule.** `is_chroma_reference` + (av1_common_int.h:1459) at ss (1,0): a HORZ pair's BLOCK_8X4 strips are + BOTH chroma references (`!(bw & 1)`), a VERT pair's BLOCK_4X8 strips keep + the odd-column leaf. Oracle evidence at the mi(8,10) HORZ pair: uv_mode + read at BOTH (8,10) and (9,10), each strip followed by its own one-TX_4X4 + chroma unit per plane. Fixed `has_chroma` to `!vert || i == 1` at 4:2:2 + and decoded each reference strip's chroma right after its luma via + `sub8_leaf_chroma422` (split path, whole-leaf path, intrabc path), with + the 4:2:0 group tail gated off at 4:2:2 and the coarse uv slots filled + from the last reference strip. The mi(8,10) pair now decodes + rng-for-rng (strip mode reads end at oracle's exact rngs 63250/33264). +2. **`decode_leaf_split4`'s 4:2:2 column parity was inverted** (422g's + `(mi_col & 1) == 0` "even-column" rule — derived by 422f from a + pre-partition-trace misreading of the (8,10) HORZ pair as a split + group). Oracle, mi(30,42) split group: uv_mode read at mi(30,43) and + mi(31,43) ONLY — the ODD columns, per the formula's column clause + `(mi_col & 1)`. Fixed to `(lmi.1 & 1) == 1`. +3. **`sub8_leaf_chroma422` anchored the odd-column leaf's ctx read/write at + the leaf's own column.** libaom anchors at the FLOOR chroma cell + (`pd->above_entropy_context + blk_col` with `blk_col = mi_col >> ss_x`): + an odd-column 4x4 leaf's unit starts at chroma px 86, whose containing + cell is luma mi col 42, so the ctx read AND the per-TU state write land + on luma mi 42,43, not 43,44. Added `ctx_mi = (lmi.0, lmi.1 & !1)`. +4. **`decode_leaf8`'s 4:2:2 chroma rect unit read its txb ctx through the + plain `around_mi`** — the 422f-class dc-vote double-count (one chroma + ctx cell spans TWO luma mi columns at ss_x 1) in the leaf8 path. + Oracle evidence at mi(2,24) plane 2: ours dc_sign row 0, oracle row 2. + Both 422 arms now read `around_mi_422_chroma(leaf_mi, 8, 8)`. + +## Measurement + +Fixture `/tmp/t422.obu` reused by hash +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` +(256x144, 22 frames). Oracle +`$HOME/.cache/aom-oracle/build/aomdec EC_TRACE=1 EC_TRACE_MODE_STEP=1 +EC_TRACE_COEFF=1 EC_PALSYN=1` (the `EC_PART` probes ship in the patched +tree's `read_partition`); ours `decode_probe` with a LOCAL +`EC_AV1_ALLOW_422_PROBE` bypass at the stream.rs refusal — REVERTED before +commit, refusal re-proven to fire by name without the env. + +- After fixes 1–3, the frame-0 partition streams pair 1:1 rng-for-rng from + the tile start through oracle #327 — tell offset constant +14 — covering + every HORZ/VERT 8x8 pair, every split4 group, the (28,44) 16x16 square + (one TX_8X16 chroma per plane, ctx row 9 = our 7-base row 2 after fix 1's + stamp anchor) and the (30,42)/(24,56) bodies. +- Fix 4 (leaf8 dc-sign sampling) was located by the same pairing: the + mi(2,24) 8x8 NONE leaf consumed the oracle's exact 13 bits but landed at + rng 53768 vs 61448; the sign phase of its V plane diverged (dcctx 0 vs 2). + +## Next divergence (named stop, for the lane that owns the partial-SB walk) + +Frame 0 now desyncs where the bottom superblock row begins: the 64x64 at +mi(32,0) hangs over the bottom edge (`has_rows=false`), and libaom READS a +gathered two-symbol partition there (`EC_PART mi_row=32 mi_col=0 bsize=12 +ctx=13 tell=19221 rng=54818` → `EC_PART_VAL value=1`, i.e. HORZ from the +`partition_gather_horz_alike` cdf, splitting the SB into two 64x32 +strips). Our walk reads NO partition symbol for that SB and dispatches +straight into a 64x32 strip walk (`EC_RECTCHROMA_GAP luma=64x32 +tx=32x32 chroma=32x32`), one symbol behind from there. Note the strip +reader's 4:2:2 chroma for a 64x32 strip (32x32 square, `ss (1,0)`) rides +the existing square arm. The `decode.rs:14888` closed-shape panic and the +`decode.rs:19169` skip arm were not touched. + +## State + +- Refusal `a chroma format of 4:2:2 (subsampling_x != subsampling_y)...` + byte-identical; `git diff` touches only `decode.rs`; the probe refuses + without `EC_AV1_ALLOW_422_PROBE` (measured this round). +- `cargo check -p ec-av1` (private target dir + `$HOME/.cache/cargo-target-av1422h`): 0 warnings. +- 420 gates green: `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ + whose_tx_split_decodes_pixel_exact` 2/2 (both variants) and + `a_non_420_subsampled_sequence_header_is_refused_by_name` 1/1. Every + changed arm is keyed on ss (1,0); the 4:2:0/4:4:4 paths keep their + proven rows and stamps. +- Temporary EC_RECTDBG/LEAFDBG/CHROMAWALK instrumentation removed before + commit. +- No push. Traces left at /tmp/o_pal.txt (full-probe oracle), + /tmp/o_part.txt, /tmp/u_cur.txt.