forge
Explore
Log in

Don't you dare go Hollow

lane-av1-llsub8: 444 lossless rect-leaf chroma reads per-4x4 units

Browse files at this commit

f0141f93013eec7b0a977f485e5d962966a4d75dAhmet Kaan GümüşParent: 25a6b5f
Two symbol-level fixes behind the 4:4:4 lossless sub8 chroma miss, both
named against the oracle's EC_COEFF ladder on the regenerated ll444
fixture:

- read_intra_mode_sub8 read uv_mode off the 14-symbol CFL alphabet
  unconditionally; a 4:4:4 lossless BLOCK_8X4/4X8 leaf's plane block is
  the rect itself, so is_cfl_allowed is FALSE and the stream carries the
  13-symbol uv_mode_no_cfl row (wrong-alphabet-same-value).
- the rect leaf's lossless chroma is (bw/4)*(bh/4) TX_4X4 units with
  get_txb_ctx's +10 txb_skip rows, not one TX_8X4 rect unit off
  ChromaRect8x4's [1][0..2] rows; the lossless arm now walks plane-major
  per-4x4 units through read_plane(TxbSet::Chroma4, +3) with immediate
  per-unit entropy stamps (tail stamps per unit too).

Key frame 15001 -> 178 differing bytes, first divergence pushed from
aligned step 12136 to 19228 (named stop in lanes/av1llsub8.report.md:
above-band cell state behind a 16x8 leaf's U bc=2 unit). 4:2:0 lossless
gates stay green; cargo check 0 warnings.
crates/ec-av1/src/decode.rsmodified+113 -20
@@ -18771,7 +18771,21 @@ fn read_intra_mode_sub8(
18771 // desynced the tile at the very next element.18771 // desynced the tile at the very next element.
18772 let angle_delta_y = 0;18772 let angle_delta_y = 0;
18773 let chroma = if has_chroma {18773 let chroma = if has_chroma {
18774- let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]);18774+ // `is_cfl_allowed` (blockd.h): at lossless CfL needs the CHROMA plane
18775+ // block to be a single TX_4X4 (`cfl_allowed_px`). True for this leaf
18776+ // at 4:2:0 (the group's plane block is 4x4) and for a 4:4:4
18777+ // `BLOCK_4X4` split leaf, but FALSE for a 4:4:4 `BLOCK_8X4`/`BLOCK_4X8`
18778+ // rect leaf, whose plane block is the rect itself -- that shape reads
18779+ // the 13-symbol `uv_mode_no_cfl` CDF, and reading the CFL alphabet
18780+ // there desynced the tile at the rect leaf's own uv_mode symbol (measured:
18781+ // ours consumed the 14-symbol interval where the oracle read 13, first
18782+ // divergence at the rect leaf mi (8,16) of `ll444.obu`; class
18783+ // `wrong-alphabet-same-value`, lane-av1-llsub8).
18784+ let uv_mode = if cfl_allowed_px(seg_w_mi * MI, seg_h_mi * MI, fctx) {
18785+ dec.symbol(&mut cdfs.uv_mode_cfl[mode])
18786+ } else {
18787+ dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
18788+ };
18775 if trace {18789 if trace {
18776 eprintln!("TRACE sub8 uv_mode value={uv_mode} rng={}", dec.debug_state().0);18790 eprintln!("TRACE sub8 uv_mode value={uv_mode} rng={}", dec.debug_state().0);
18777 }18791 }
@@ -18839,7 +18853,7 @@ fn sub8_leaf_chroma444(
18839 base_q_idx: u8,18853 base_q_idx: u8,
18840 smooth_neighbor_uv: bool,18854 smooth_neighbor_uv: bool,
18841 fctx: &crate::decode::FrameCtx,18855 fctx: &crate::decode::FrameCtx,
18842-) -> Result<(Grid, Grid)> {18856+) -> Result<(Grid, Grid, usize, usize)> {
18843 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };18857 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
18844 let (w_mi, h_mi) = (bw / MI, bh / MI);18858 let (w_mi, h_mi) = (bw / MI, bh / MI);
18845 neighbours.record_uv_mode_mi(lmi.0, lmi.1, w_mi, h_mi, uv_predict_mode);18859 neighbours.record_uv_mode_mi(lmi.0, lmi.1, w_mi, h_mi, uv_predict_mode);
@@ -18867,7 +18881,7 @@ fn sub8_leaf_chroma444(
18867 hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS);18881 hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS);
18868 fctx.intrabc_chroma_tx.with(|c| c.set(None));18882 fctx.intrabc_chroma_tx.with(|c| c.set(None));
18869 }18883 }
18870- (Grid::Zero(bw * bh), Grid::Zero(bw * bh))18884+ (Grid::Zero(bw * bh), Grid::Zero(bw * bh), 4, 4)
18871 } else if let Some(dv) = intrabc_dv {18885 } else if let Some(dv) = intrabc_dv {
18872 // Frame copy at the DV; the residual still reads the ordinary chroma18886 // Frame copy at the DV; the residual still reads the ordinary chroma
18873 // tables with the inherited luma `tx_type` (see the 4:2:0 tails).18887 // tables with the inherited luma `tx_type` (see the 4:2:0 tails).
@@ -18897,12 +18911,12 @@ fn sub8_leaf_chroma444(
18897 0, reach, v, px, py, 4, TX4, base_q_idx,18911 0, reach, v, px, py, 4, TX4, base_q_idx,
18898 None, None, None, smooth_neighbor_uv, fctx,18912 None, None, None, smooth_neighbor_uv, fctx,
18899 )?;18913 )?;
18900- (ug, vg)18914+ (ug, vg, 4, 4)
18901 } else {18915 } else {
18902 let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 };18916 let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 };
18903 let default_tx =18917 let default_tx =
18904 fctx.intrabc_chroma_tx.with(std::cell::Cell::get).unwrap_or(TxType::DctDct);18918 fctx.intrabc_chroma_tx.with(std::cell::Cell::get).unwrap_or(TxType::DctDct);
18905- let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh));18919+ let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh), bw, bh);
18906 for (plane_idx, buf) in [(1usize, ub), (2usize, vb)] {18920 for (plane_idx, buf) in [(1usize, ub), (2usize, vb)] {
18907 let skip_ctx =18921 let skip_ctx =
18908 usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1);18922 usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1);
@@ -18942,14 +18956,62 @@ fn sub8_leaf_chroma444(
18942 0, reach, v, px, py, 4, TX4, base_q_idx,18956 0, reach, v, px, py, 4, TX4, base_q_idx,
18943 alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx,18957 alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx,
18944 )?;18958 )?;
18945- (ug, vg)18959+ (ug, vg, 4, 4)
18960+ } else if lossless(fctx) {
18961+ // lane-av1-llsub8: `read_tx_size` answers TX_4X4 for EVERY plane of
18962+ // a lossless block, so this rect leaf's chroma is (bw/4)*(bh/4)
18963+ // TX_4X4 units at their own 4x4 origins -- not the single
18964+ // TX_8X4/TX_4X8 rect unit the non-lossless arm below reads (that
18965+ // one is `av1_get_max_uv_txsize(BLOCK_8X4)`'s rect transform, which
18966+ // lossless never reaches). Measured on `ll444.obu`'s HORZ leaf at
18967+ // mi (8,16): the oracle codes U units at bc 0,1 with
18968+ // `get_txb_ctx`'s +10 rows (`txb_skip_cdf[0][10..12]`,
18969+ // plane pels 32 > tx pels 16) where the rect-unit read consumed
18970+ // `txb_skip_cdf[1][0]` -- the tile desynced at that U unit's
18971+ // all_zero symbol. Walk is plane-major like libaom
18972+ // `decode_token_recon_block`'s plane/row/col loop; each unit adds
18973+ // 3 to the chroma context (Chroma4's `big` rows, the same fold
18974+ // [`read_plane`]'s 128x128 caller uses); CFL is never allowed at
18975+ // lossless, so no alpha rides along.
18976+ let mut out_u = Grid::Own(vec![0i32; bw * bh]);
18977+ let mut out_v = Grid::Own(vec![0i32; bw * bh]);
18978+ for (plane_idx, buf) in [(1usize, u), (2usize, v)] {
18979+ for ur in 0..bh / 4usize {
18980+ for uc in 0..bw / 4usize {
18981+ let (umi_r, umi_c) = (lmi.0 + ur, lmi.1 + uc);
18982+ let (upx, upy) = (px + uc * 4, py + ur * 4);
18983+ let unit_around = neighbours.around_mi_rect((umi_r, umi_c), 4, 4);
18984+ let unit_reach = Reach::of(4, upx, upy, y.width, y.height, fctx);
18985+ let grid = read_plane(
18986+ dec, cdfs, TxbSet::Chroma4, scan4, plane_idx, unit_around[plane_idx],
18987+ uv_mode, uv_predict_mode, 0, unit_reach, buf, upx, upy, 4,
18988+ TX4, base_q_idx, None, None, Some(3), smooth_neighbor_uv, fctx,
18989+ )?;
18990+ let cell = grid_unit_state(&grid, 4, 0, 0, 4, 4);
18991+ if umi_r < neighbours.mi_rows {
18992+ neighbours.left[umi_r][plane_idx] = cell;
18993+ }
18994+ if umi_c < neighbours.mi_cols {
18995+ neighbours.above[umi_c][plane_idx] = cell;
18996+ }
18997+ let out = if plane_idx == 1 { &mut out_u } else { &mut out_v };
18998+ if let Grid::Own(v) = out {
18999+ for r in 0..4usize {
19000+ v[(ur * 4 + r) * bw + uc * 4..][..4]
19001+ .copy_from_slice(&grid[r * 4..][..4]);
19002+ }
19003+ }
19004+ }
19005+ }
19006+ }
19007+ (out_u, out_v, 4, 4)
18946 } else {19008 } else {
18947 // `av1_get_max_uv_txsize(BLOCK_4X8/8X4)` at ss 0/0 is the rect19009 // `av1_get_max_uv_txsize(BLOCK_4X8/8X4)` at ss 0/0 is the rect
18948 // transform itself; its `tx_type` is mode-derived with the19010 // transform itself; its `tx_type` is mode-derived with the
18949 // <32 set (`decode_rect_split`'s own rule for this shape).19011 // <32 set (`decode_rect_split`'s own rule for this shape).
18950 let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 };19012 let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 };
18951 let default_tx = default_intra_tx_type(uv_predict_mode as u8);19013 let default_tx = default_intra_tx_type(uv_predict_mode as u8);
18952- let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh));19014+ let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh), bw, bh);
18953 for plane_idx in 1..=2usize {19015 for plane_idx in 1..=2usize {
18954 let skip_ctx =19016 let skip_ctx =
18955 usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1);19017 usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1);
@@ -18977,23 +19039,54 @@ fn sub8_leaf_chroma444(
18977 }19039 }
18978 };19040 };
18979 // libaom `av1_set_entropy_contexts` stamps above/left PER TRANSFORM UNIT:19041 // libaom `av1_set_entropy_contexts` stamps above/left PER TRANSFORM UNIT:
18980- // the leaf's own chroma span, not the 8x8 group's.19042+ // the leaf's own chroma span, not the 8x8 group's. A rect leaf's lossless
18981- let (u_grid, v_grid) = grids;19043+ // units (4x4) each carry their own state -- a 4:2:0-style whole-leaf smear
18982- let u_state = neighbour_state(&u_grid);19044+ // gave one unit's state to its neighbour's cells (lane-av1-llsub8).
18983- let v_state = neighbour_state(&v_grid);19045+ let (u_grid, v_grid, unit_w, unit_h) = grids;
18984- for cell in 0..h_mi {19046+ // One unit covers `unit_w/MI` mi columns and `unit_h/MI` mi rows (a 4x4
18985- if lmi.0 + cell < neighbours.mi_rows {19047+ // unit: one cell each; the non-lossless rect unit: the whole leaf).
18986- neighbours.left[lmi.0 + cell][1] = u_state;19048+ let (uw_cells, uh_cells) = ((unit_w / MI).max(1), (unit_h / MI).max(1));
18987- neighbours.left[lmi.0 + cell][2] = v_state;19049+ for ur in 0..h_mi / uh_cells {
19050+ for uc in 0..w_mi / uw_cells {
19051+ let (x0, y0) = (uc * unit_w, ur * unit_h);
19052+ let us = grid_unit_state(&u_grid, bw, x0, y0, unit_w, unit_h);
19053+ let vs = grid_unit_state(&v_grid, bw, x0, y0, unit_w, unit_h);
19054+ for cell in 0..uh_cells {
19055+ if lmi.0 + ur * uh_cells + cell < neighbours.mi_rows {
19056+ neighbours.left[lmi.0 + ur * uh_cells + cell][1] = us;
19057+ neighbours.left[lmi.0 + ur * uh_cells + cell][2] = vs;
18988 }19058 }
18989 }19059 }
18990- for cell in 0..w_mi {19060+ for cell in 0..uw_cells {
18991- if lmi.1 + cell < neighbours.mi_cols {19061+ if lmi.1 + uc * uw_cells + cell < neighbours.mi_cols {
18992- neighbours.above[lmi.1 + cell][1] = u_state;19062+ neighbours.above[lmi.1 + uc * uw_cells + cell][1] = us;
18993- neighbours.above[lmi.1 + cell][2] = v_state;19063+ neighbours.above[lmi.1 + uc * uw_cells + cell][2] = vs;
19064+ }
18994 }19065 }
18995 }19066 }
18996- Ok((u_grid, v_grid))19067+ }
19068+ Ok((u_grid, v_grid, unit_w, unit_h))
19069+}
19070+
19071+/// [`neighbour_state`] over one `(unit_w x unit_h)` transform unit at offset
19072+/// `(x0, y0)` inside a `bw`-wide assembled chroma grid -- the per-unit stamp
19073+/// the rect arms need when a leaf carries more than one unit.
19074+fn grid_unit_state(grid: &Grid, bw: usize, x0: usize, y0: usize, unit_w: usize, unit_h: usize) -> Neighbour {
19075+ let mut cul = 0u32;
19076+ let mut dc = None;
19077+ for r in 0..unit_h {
19078+ for c in 0..unit_w {
19079+ let v = grid[(y0 + r) * bw + x0 + c];
19080+ cul += v.unsigned_abs();
19081+ if r == 0 && c == 0 && v != 0 {
19082+ dc = Some(v < 0);
19083+ }
19084+ }
19085+ }
19086+ if cul == 0 {
19087+ return Neighbour::default();
19088+ }
19089+ Neighbour { level: cul.min(7) as u8, dc }
18997 }19090 }
18998 19091
18999 19092
lanes/av1llsub8.report.mdadded+84 -0
@@ -0,0 +1,84 @@
1+# lane-av1-llsub8: 4:4:4 lossless sub8 chroma coefficient miss (r1)
2+
3+## Charter
4+
5+Localize the 4:4:4 lossless sub8 chroma coefficient miss. Work in
6+`edith_codecs-av1llsub8` @ 38393554; own `sub8_leaf_chroma444` and the
7+coefficient read it calls. 4:2:0 lossless stays exact.
8+
9+## Repro
10+
11+Fixture regenerated per the llintra report's recipe (raw `--i444` input, same
12+encoder): `testsrc2 128x96` yuv444p, 6 frames, `aomenc --profile=1
13+--lossless=1 --enable-palette=0 --enable-intrabc=0` (`~/ll444.obu`, 26511 B;
14+key-frame cut `~/ll444kf.obu`). Pre-fix key frame: 15001/36864 bytes differ
15+from `aomdec --rawvideo` (first diff byte 4181). Probe exits 101 at frame 1
16+(`reconstruct_mc_rect`, decode.rs:2589 path) — the charter's named inter side,
17+untouched.
18+
19+## Ladder (EC_TRACE_COEFF, symbol-anchored, key frame only)
20+
21+12136 aligned `(tag,rng)` steps, then:
22+
23+1. **uv_mode alphabet (FIXED).** First divergence is *not* a coefficient: at
24+ the first 8x8 `PARTITION_HORZ` leaf (mi (8,16)) the leaf's own `uv_mode`
25+ symbol desyncs. `read_intra_mode_sub8` read `cdfs.uv_mode_cfl[mode]`
26+ (14-symbol) unconditionally; a 4:4:4 lossless `BLOCK_8X4`/`BLOCK_4X8`
27+ leaf's plane block is the rect itself, so `is_cfl_allowed` is FALSE and the
28+ stream carries the 13-symbol `uv_mode_no_cfl` row (class
29+ `wrong-alphabet-same-value`; oracle post-read rng 33082 vs ours 38358 off
30+ the same entry 56906). Fix: gate on `cfl_allowed_px(seg_w_mi*MI,
31+ seg_h_mi*MI)` — true for the 4:2:0 group tail (plane block 4x4) and 4:4:4
32+ split leaves, false for 4:4:4 rect leaves; 4:2:0 unchanged.
33+2. **Rect-leaf lossless chroma unit structure (FIXED).** Next divergence
34+ (step 12138): the rect leaf's chroma. `read_tx_size` answers TX_4X4 for
35+ EVERY plane of a lossless block, so the oracle codes the 8x4 leaf's chroma
36+ as TWO plane-major TX_4X4 units (U bc 0, U bc 1, then V) with
37+ `get_txb_ctx`'s **+10** rows (`plane pels 32 > tx pels 16`,
38+ `txb_skip_cdf[0][10..12]`), while ours read ONE TX_8X4 rect unit off
39+ `ChromaRect8x4` (rows `[1][0..2]`, only reached correctly non-losslessly).
40+ Fix: lossless rect arm reads per-4x4 units via `read_plane(TxbSet::Chroma4,
41+ luma_skip_ctx=Some(3))` (Chroma4's `big` rows = `[0][10..12]`), plane-major
42+ per `decode_token_recon_block`, per-unit ctx from the unit's own
43+ `around_mi_rect`, immediate per-unit `av1_set_entropy_contexts` stamps.
44+ The non-lossless arm (single rect transform, rows `[1][7..9]`) is kept.
45+ Tail now stamps per-unit (`grid_unit_state`) instead of one whole-leaf
46+ smear; 4x4 leaves and the single-unit rect arm are bit-identical to before.
47+
48+After both fixes: divergence moves to step 19228, key frame 178/36864 bytes
49+off (first diff byte 8320).
50+
51+## STOP — named, not fixed (budget)
52+
53+Step 19228: inside a **16x8 leaf** (`PARTITION_HORZ` of a 16x16; U units
54+bc 0..3, br 0..1) the U unit at **bc=2, br=0** reads `txb_skip` base **1**
55+(ours, row `[0][11]` — the same `+3` fold, cdf `[8570,...]`) where the oracle
56+reads base **0** (row `[0][10]`, cdf0=32705): one of ours' above/left entropy
57+cells for that unit is stamped nonzero where the oracle's is clean. bc=0/1 of
58+the same leaf aligned (rng 40879/40628), and ours' `dcctx=2` on the diverging
59+read (vs 0 on bc=1) says the polluted cell carries a DC-sign vote — i.e. an
60+above-band cell written by the block above with a state the oracle doesn't
61+hold. Next step: dump the above-band cell contents (both sides,
62+`EC_DCDUMP`/oracle equivalent) for the units directly above this leaf's
63+bc 2/3 columns and diff the writer — suspect the 16x8-path's per-unit stamp
64+map (which unit owns which above/left cell when a leaf spans >1 mi row) in
65+`decode_leaf_rect`'s chroma loop, NOT `sub8_leaf_chroma444` (16x8 leaves are
66+read by `decode_leaf_rect`, which already had per-unit +3 reads before this
67+lane).
68+
69+## Verification (measured)
70+
71+- `a_lossless_libaom_key_frame_decodes_sample_exact` + `a_lossless_libaom_
72+ inter_frame_decodes_sample_exact` (4:2:0): green.
73+- `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors.
74+- Key frame: 15001 → 178 differing bytes; first diff byte 4181 → 8320.
75+- Consumed-count ladder: 12136 → 12138 → 19228 aligned steps.
76+
77+## Deferred (spoken, not hidden)
78+
79+- 16x8 above-band stamp diff above (fix-now; named cell + writer).
80+- Intrabc rect leaves at lossless 444 still route the rect arm's
81+ `read_coeffs_rect` path with the wrong unit structure — unreachable with
82+ `--enable-intrabc=0` fixtures; same fix shape as the non-intrabc arm
83+ (deferred(fix-now after the inter side is green, with an intrabc 4:4:4
84+ fixture), matching the llintra report's deferral).