lane-av1sub8rect444: the lossless sub-8 rect leaf reads its 4:4:4 chroma per TX_4X4 unit
Browse files at this commit50b44b49f140e94b4e2838c39451da226fbce474Parent: 10366d73 changed files +216 -0
- crates/ec-av1/examples/decode_probe.rs +4 -0
- crates/ec-av1/src/decode.rs +117 -0
- lanes/av1sub8rect444.report.md +95 -0
crates/ec-av1/examples/decode_probe.rsmodified+4 -0
| @@ -109,6 +109,10 @@ fn main() { | |||
| 109 | "llintra8_chroma_walk: {}", | 109 | "llintra8_chroma_walk: {}", |
| 110 | ec_av1::decode::llintra8_chroma_walk_hits() | 110 | ec_av1::decode::llintra8_chroma_walk_hits() |
| 111 | ); | 111 | ); |
| 112 | + println!( | ||
| 113 | + "sub8rect444_chroma_walk: {}", | ||
| 114 | + ec_av1::decode::llsub8rect444_chroma_walk_hits() | ||
| 115 | + ); | ||
| 112 | let si = ec_av1::stream::sub8_intra_rect_hits(); | 116 | let si = ec_av1::stream::sub8_intra_rect_hits(); |
| 113 | println!( | 117 | println!( |
| 114 | "sub8_intra_rect: horz8x4={} vert4x8={} chroma_ref={} mixed={} split4x4={}", | 118 | "sub8_intra_rect: horz8x4={} vert4x8={} chroma_ref={} mixed={} split4x4={}", |
crates/ec-av1/src/decode.rsmodified+117 -0
| @@ -25841,6 +25841,22 @@ pub fn llintra8_chroma_walk_hits() -> usize { | |||
| 25841 | LLINTRA8_CHROMA_WALK_HITS.with(|c| c.get()) | 25841 | LLINTRA8_CHROMA_WALK_HITS.with(|c| c.get()) |
| 25842 | } | 25842 | } |
| 25843 | 25843 | ||
| 25844 | +thread_local! { | ||
| 25845 | + /// lane-av1sub8rect444: how many of `decode_intra_sub8_leaf`'s 8x4/4x8 | ||
| 25846 | + /// INTRA leaves ran the lossless 4:4:4 per-unit chroma walk (two TX_4X4 | ||
| 25847 | + /// units per plane, plane-major) instead of one TX_8X4/TX_4X8 rect unit | ||
| 25848 | + /// -- the shape whose unit count AND skip ctx the rect read got wrong. | ||
| 25849 | + /// A gate proving the arm fired; CHROMA_SPLIT_TX_HITS cannot attribute | ||
| 25850 | + /// its bumps to THIS leaf. | ||
| 25851 | + pub(crate) static LLSUB8RECT444_CHROMA_WALK_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 25852 | +} | ||
| 25853 | + | ||
| 25854 | +/// [`LLSUB8RECT444_CHROMA_WALK_HITS`]: lossless 4:4:4 chroma walks through a | ||
| 25855 | +/// sub-8 8x4/4x8 INTRA leaf. | ||
| 25856 | +pub fn llsub8rect444_chroma_walk_hits() -> usize { | ||
| 25857 | + LLSUB8RECT444_CHROMA_WALK_HITS.with(|c| c.get()) | ||
| 25858 | +} | ||
| 25859 | + | ||
| 25844 | fn read_sb128_root( | 25860 | fn read_sb128_root( |
| 25845 | dec: &mut SymbolDecoder, | 25861 | dec: &mut SymbolDecoder, |
| 25846 | cdfs: &mut Cdfs, | 25862 | cdfs: &mut Cdfs, |
| @@ -36085,6 +36101,7 @@ fn decode_intra_sub8_leaf( | |||
| 36085 | } | 36101 | } |
| 36086 | 36102 | ||
| 36087 | let ac = alpha.map(|_| if chroma_444 { cfl_src_rect(px, py, bw, bh) } else { cfl_src(gpx, gpy, 8) }); | 36103 | let ac = alpha.map(|_| if chroma_444 { cfl_src_rect(px, py, bw, bh) } else { cfl_src(gpx, gpy, 8) }); |
| 36104 | + let mut chroma_stamped_per_unit = false; | ||
| 36088 | let (u_grid, v_grid): (Grid, Grid) = if skip { | 36105 | let (u_grid, v_grid): (Grid, Grid) = if skip { |
| 36089 | if alpha.is_some() { | 36106 | if alpha.is_some() { |
| 36090 | hit!(CHROMA_SKIP_CFL_HITS); | 36107 | hit!(CHROMA_SKIP_CFL_HITS); |
| @@ -36101,6 +36118,95 @@ fn decode_intra_sub8_leaf( | |||
| 36101 | (Grid::Zero(16), Grid::Zero(16)) | 36118 | (Grid::Zero(16), Grid::Zero(16)) |
| 36102 | } | 36119 | } |
| 36103 | } else if chroma_444 && bw != bh { | 36120 | } else if chroma_444 && bw != bh { |
| 36121 | + if lossless(fctx) { | ||
| 36122 | + // lane-av1sub8rect444: lossless codes TX_4X4 on EVERY plane | ||
| 36123 | + // (`av1_get_tx_size`, blockd.h:1383), so this leaf's 8x4/4x8 | ||
| 36124 | + // chroma plane block is a 1x2/2x1 raster of TX_4X4 units per | ||
| 36125 | + // plane, PLANE-MAJOR -- the same per-unit walk | ||
| 36126 | + // [`read_intra_chroma_lossless`] runs for whole blocks and this | ||
| 36127 | + // leaf's own luma `split` runs above, not one TX_8X4/TX_4X8 | ||
| 36128 | + // rect unit. The rect read was wrong twice over: its unit count | ||
| 36129 | + // left the second unit's coefficients in the bitstream, and its | ||
| 36130 | + // skip ctx fixed at above+left missed `get_txb_ctx`'s | ||
| 36131 | + // plane-block-bigger-than-transform term (libaom ctx 10+above | ||
| 36132 | + // +left, our tables' +3), where the oracle read ctx 11≡4. | ||
| 36133 | + let (mut uo, mut vo) = (Vec::new(), Vec::new()); | ||
| 36134 | + for plane_idx in 1..3 { | ||
| 36135 | + for tu in 0..2usize { | ||
| 36136 | + let (ox, oy) = if vert { (0, tu * 4) } else { (tu * 4, 0) }; | ||
| 36137 | + // libaom's `max_blocks_wide/high` clip: a unit whose | ||
| 36138 | + // origin is past the frame edge is not coded at all | ||
| 36139 | + // (`decode_token_recon_block`). At 4:4:4 the unit's | ||
| 36140 | + // chroma origin is the leaf's own (px, py). | ||
| 36141 | + if px + ox >= u.true_width || py + oy >= u.true_height { | ||
| 36142 | + continue; | ||
| 36143 | + } | ||
| 36144 | + // At 4:4:4 a TX_4X4 chroma unit IS one mi cell. | ||
| 36145 | + let tu_mi = (lmi.0 + oy / MI, lmi.1 + ox / MI); | ||
| 36146 | + let tu_around = neighbours.around_mi(tu_mi, MI); | ||
| 36147 | + let tu_r = tu_reach( | ||
| 36148 | + bw, | ||
| 36149 | + bh, | ||
| 36150 | + ox, | ||
| 36151 | + oy, | ||
| 36152 | + 4, | ||
| 36153 | + reach_c, | ||
| 36154 | + px, | ||
| 36155 | + py, | ||
| 36156 | + y.width, | ||
| 36157 | + y.height, fctx, | ||
| 36158 | + ); | ||
| 36159 | + let buf: &mut PlaneBuf<'static> = | ||
| 36160 | + if plane_idx == 1 { &mut *u } else { &mut *v }; | ||
| 36161 | + // The plane block (8x4/4x8) is bigger than the TX_4X4 | ||
| 36162 | + // transform, so `get_txb_ctx`'s chroma ctx_offset is 10, | ||
| 36163 | + // not 7 -- our chroma tables carry the offset-10 rows at | ||
| 36164 | + // +3, the same `Some(3)` [`read_intra_chroma_lossless`] | ||
| 36165 | + // derives from `blk_w > 4 || blk_h > 4`. | ||
| 36166 | + let tu_grid = read_plane( | ||
| 36167 | + dec, | ||
| 36168 | + cdfs, | ||
| 36169 | + TxbSet::Chroma4, | ||
| 36170 | + scan4, | ||
| 36171 | + plane_idx, | ||
| 36172 | + tu_around[plane_idx], | ||
| 36173 | + mode, | ||
| 36174 | + uv_predict_mode, | ||
| 36175 | + angle_delta_uv, | ||
| 36176 | + tu_r, | ||
| 36177 | + buf, | ||
| 36178 | + px + ox, | ||
| 36179 | + py + oy, | ||
| 36180 | + 4, | ||
| 36181 | + TX4, | ||
| 36182 | + base_q_idx, | ||
| 36183 | + None, | ||
| 36184 | + None, | ||
| 36185 | + Some(3), | ||
| 36186 | + smooth_neighbor_uv, fctx, | ||
| 36187 | + )?; | ||
| 36188 | + // The unit's own coefficient context, stamped per unit | ||
| 36189 | + // (`av1_set_contexts`); the tail's whole-leaf chroma | ||
| 36190 | + // stamp below is skipped for this shape. | ||
| 36191 | + neighbours.record_mi_chroma(tu_mi, 4, 4, plane_idx, &tu_grid); | ||
| 36192 | + hit!(CHROMA_SPLIT_TX_HITS); | ||
| 36193 | + let dst = mu_units( | ||
| 36194 | + if plane_idx == 1 { &mut uo } else { &mut vo }, | ||
| 36195 | + bw * bh, | ||
| 36196 | + ); | ||
| 36197 | + for row in 0..4 { | ||
| 36198 | + let start = (oy + row) * bw + ox; | ||
| 36199 | + dst[start..start + 4].copy_from_slice(&tu_grid[row * 4..][..4]); | ||
| 36200 | + } | ||
| 36201 | + } | ||
| 36202 | + } | ||
| 36203 | + chroma_stamped_per_unit = true; | ||
| 36204 | + hit!(LLSUB8RECT444_CHROMA_WALK_HITS); | ||
| 36205 | + ( | ||
| 36206 | + if uo.is_empty() { Grid::Zero(bw * bh) } else { Grid::Own(uo) }, | ||
| 36207 | + if vo.is_empty() { Grid::Zero(bw * bh) } else { Grid::Own(vo) }, | ||
| 36208 | + ) | ||
| 36209 | + } else { | ||
| 36104 | // The leaf's own TX_8X4/TX_4X8 chroma unit: it IS the chroma plane | 36210 | // The leaf's own TX_8X4/TX_4X8 chroma unit: it IS the chroma plane |
| 36105 | // block, so `get_txb_ctx` fixes the skip context at above+left. | 36211 | // block, so `get_txb_ctx` fixes the skip context at above+left. |
| 36106 | let ca = neighbours.around_mi_rect(lmi, bw, bh); | 36212 | let ca = neighbours.around_mi_rect(lmi, bw, bh); |
| @@ -36139,6 +36245,7 @@ fn decode_intra_sub8_leaf( | |||
| 36139 | let ug = read_chroma(1, ca[1], alpha.zip(ac).map(|((au, _), ac)| (au, ac)))?; | 36245 | let ug = read_chroma(1, ca[1], alpha.zip(ac).map(|((au, _), ac)| (au, ac)))?; |
| 36140 | let vg = read_chroma(2, ca[2], alpha.zip(ac).map(|((_, av), ac)| (av, ac)))?; | 36246 | let vg = read_chroma(2, ca[2], alpha.zip(ac).map(|((_, av), ac)| (av, ac)))?; |
| 36141 | (ug, vg) | 36247 | (ug, vg) |
| 36248 | + } | ||
| 36142 | } else { | 36249 | } else { |
| 36143 | let chroma_around = neighbours.around_mi(if chroma_444 { lmi } else { group_mi }, if chroma_444 { 4 } else { 8 }); | 36250 | let chroma_around = neighbours.around_mi(if chroma_444 { lmi } else { group_mi }, if chroma_444 { 4 } else { 8 }); |
| 36144 | let ug = read_plane( | 36251 | let ug = read_plane( |
| @@ -36153,9 +36260,19 @@ fn decode_intra_sub8_leaf( | |||
| 36153 | )?; | 36260 | )?; |
| 36154 | (ug, vg) | 36261 | (ug, vg) |
| 36155 | }; | 36262 | }; |
| 36263 | + // The 4:4:4 lossless walk above already stamped these bands PER UNIT | ||
| 36264 | + // (raster-order last writer per cell, exactly libaom's per-entry last | ||
| 36265 | + // update); the whole-leaf aggregate would clobber the two units' distinct | ||
| 36266 | + // states with one, so it runs only for the one-unit shapes (the same rule | ||
| 36267 | + // [`decode_leaf8`]'s intrabc arm and the inter 8x8 leaf obey). The walk | ||
| 36268 | + // must skip the 4:2:0 group-tail below too: it spans the GROUP's two mi | ||
| 36269 | + // rows/cols with one composed state, which would overwrite the walk's | ||
| 36270 | + // own stamps with the whole-leaf aggregate. | ||
| 36156 | if chroma_444 { | 36271 | if chroma_444 { |
| 36272 | + if !chroma_stamped_per_unit { | ||
| 36157 | neighbours.record_mi_chroma(lmi, bw, bh, 1, &u_grid); | 36273 | neighbours.record_mi_chroma(lmi, bw, bh, 1, &u_grid); |
| 36158 | neighbours.record_mi_chroma(lmi, bw, bh, 2, &v_grid); | 36274 | neighbours.record_mi_chroma(lmi, bw, bh, 2, &v_grid); |
| 36275 | + } | ||
| 36159 | } else { | 36276 | } else { |
| 36160 | let round_up_even = |n: usize| n.div_ceil(2) * 2; | 36277 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 36161 | let bound_h = round_up_even(neighbours.mi_rows); | 36278 | let bound_h = round_up_even(neighbours.mi_rows); |
lanes/av1sub8rect444.report.mdadded+95 -0
| @@ -0,0 +1,95 @@ | |||
| 1 | +# lane-av1sub8rect444: the lossless sub-8 rect leaf's 4:4:4 chroma per-unit walk | ||
| 2 | + | ||
| 3 | +## Ticket | ||
| 4 | + | ||
| 5 | +`lanes/av1llintercdf.report.md` "Named, not chased" item 1: at the shared state | ||
| 6 | +rng=51429 after the 8x4 leaf's luma, the oracle reads the leaf's chroma as | ||
| 7 | +FOUR TX_4X4 units (plane 1 bc=0,1 ctx=11 then plane 2 bc=0,1) while | ||
| 8 | +`decode_intra_sub8_leaf`'s `chroma_444 && bw != bh` arm read the chroma plane | ||
| 9 | +as ONE `TX_8X4`/`TX_4X8` rect unit per plane (`read_coeffs_rect`, skip ctx | ||
| 10 | +fixed at above+left where the oracle derives 11≡4). Wrong unit count AND wrong | ||
| 11 | +skip ctx. Template: b3f815c8's per-unit 8x8-leaf walk. | ||
| 12 | + | ||
| 13 | +## Change (decode.rs, one arm + one tail guard + counter) | ||
| 14 | + | ||
| 15 | +1. `decode_intra_sub8_leaf`'s rect arm now branches on `lossless(fctx)`: the | ||
| 16 | + walk reads the leaf's 8x4/4x8 chroma plane block as a 1x2/2x1 raster of | ||
| 17 | + `TX_4X4` units per plane, PLANE-MAJOR (`av1_get_tx_size`, blockd.h:1383), | ||
| 18 | + via `read_plane` with `TxbSet::Chroma4`, per-unit `around_mi` (per-unit | ||
| 19 | + `get_txb_ctx`), the plane-block-bigger-than-transform `+3` (libaom's +10 | ||
| 20 | + rows, so above+left=1 reads row 4 ↔ libaom ctx 11 — the named 11≡4), and | ||
| 21 | + the lossless tx_type drop (`read_plane`'s own `coding.tx_type = None` for | ||
| 22 | + lossless + DCT_DCT force). Units anchor at the leaf's own (px, py) at | ||
| 23 | + 4:4:4, clip past the frame edge like `read_intra_chroma_lossless`, stamp | ||
| 24 | + each unit's own coefficient context with per-unit `record_mi_chroma` | ||
| 25 | + (`av1_set_contexts` per unit), and assemble the leaf grid at stride bw. | ||
| 26 | + CFL is impossible here (the uv read upstream already takes the | ||
| 27 | + 13-symbol `uv_mode_no_cfl` row for this shape at lossless), so no alpha | ||
| 28 | + rides along — the same `None` the template walks pass. | ||
| 29 | +2. Tail guard: the whole-leaf `record_mi_chroma(lmi, bw, bh, ...)` is skipped | ||
| 30 | + when the walk stamped per unit — NESTED inside the `chroma_444` branch. | ||
| 31 | + The first cut wrote `if chroma_444 && !stamped { record } else { <4:2:0 | ||
| 32 | + group tail> }`, which let a walked leaf fall into the 4:2:0 group tail: | ||
| 33 | + it spans the GROUP's two mi rows/cols with one composed state and | ||
| 34 | + clobbered the walk's own stamps (measured: `above[3][1]` flipped pos→neg | ||
| 35 | + between the walk's stamp and the next leaf's read — the oracle wants the | ||
| 36 | + per-unit value). The nested form skips BOTH branches for the walk. | ||
| 37 | +3. Non-vacuity counter `LLSUB8RECT444_CHROMA_WALK_HITS` + | ||
| 38 | + `llsub8rect444_chroma_walk_hits()` + a `decode_probe` line, per the lane | ||
| 39 | + convention (`CHROMA_SPLIT_TX_HITS` cannot attribute its bumps to this | ||
| 40 | + leaf). 4:2:0 is arithmetically identical: the branch lives inside | ||
| 41 | + `chroma_444`, and the non-lossless rect path and the 4:2:0 group tail are | ||
| 42 | + byte-preserved. | ||
| 43 | + | ||
| 44 | +## Verification (measured, this tree @ HEAD + this change) | ||
| 45 | + | ||
| 46 | +- Entropy witness, `/tmp/llkf/t6.obu` vs fresh `aomdec` | ||
| 47 | + (`$HOME/.cache/aom-oracle/build`), `EC_ECDUMP_IN` (value,rng) pairing: | ||
| 48 | + pre-change the first mismatching read is #2326 — inside the named leaf's | ||
| 49 | + chroma at mi(0,2). Post-change #2316–#2488 pair 1:1: the named leaf's FOUR | ||
| 50 | + chroma units read exactly the oracle's symbols | ||
| 51 | + ((30281,51429)/(20612,34312)/(33129,58376)/(30377,36104) against oracle | ||
| 52 | + ctx 11≡4), the sibling INTER leaf mi(1,2) and everything after pairs, and | ||
| 53 | + the walk counter fires (15 walks stream-wide, `decode_probe`). | ||
| 54 | + Fail-before: with the rect read in place the leaf desynced at its own | ||
| 55 | + chroma (t6 frame-1 first differing pixel byte 65, 16032 differing bytes). | ||
| 56 | +- The stream still diverges — later and at a DIFFERENT block: first | ||
| 57 | + mismatching read #2489, the U unit (2,8) of the 16x4 INTER strip at | ||
| 58 | + mi(2,8): ours reads `txb_skip` ctx 3 (above[8][1]=0, left[2][1]=0) where | ||
| 59 | + the oracle reads ctx 11 with raw cells `above=[0,] left=[23,]` | ||
| 60 | + (`EC_ECDUMP`, the patched oracle's cell dump) — libaom's left[2][1] holds | ||
| 61 | + level 7 / dc 0 from an earlier row-2 writer, ours holds 0. That cell is | ||
| 62 | + written by the 16x16 intra block (0,4)'s chroma band stamping and the | ||
| 63 | + (1,8) 16x4 strip's own tail — `decode_rect4_16_strip` is llcpred's lane. | ||
| 64 | + With the desync now downstream, our decoder refuses honestly at the strip | ||
| 65 | + (`a Golomb tail longer than this decoder reads`) instead of decoding | ||
| 66 | + garbage, so per-frame byte counts are not claimable this round: **t6 | ||
| 67 | + frames 1..5 are NOT exact — no exactness claimed.** Frame 0 is untouched | ||
| 68 | + by construction (both callers, `decode_inter_sub8_split4` and | ||
| 69 | + `decode_inter_sub8_rect2`, are inter-frame paths; the key frame never | ||
| 70 | + reaches this arm) and was byte-exact before. | ||
| 71 | +- Non-regression: `cargo test -p ec-av1 --lib a_lossless` → 7 passed, 0 | ||
| 72 | + failed (both 4:2:0 lossless libaom gates, the 444 min-partition-64 and | ||
| 73 | + min-partition-8 inter gates, the sb128 pair, the 16x4 pair). | ||
| 74 | +- `cargo check -p ec-av1 --all-targets` (target dir | ||
| 75 | + `$HOME/.cache/cargo-target-av1sub8rect444`): 0 warnings, 0 errors. | ||
| 76 | + `rustfmt --check` reports no hunks inside the edited ranges (the crate's | ||
| 77 | + pre-existing drift is untouched). | ||
| 78 | +- Fixtures are scratch in /tmp/llkf (t6.obu, regenerable per | ||
| 79 | + av1llkf.report.md's recipe) and /tmp/llsub8rect444; nothing committed | ||
| 80 | + from them. | ||
| 81 | + | ||
| 82 | +## Named, not chased (spoken) | ||
| 83 | + | ||
| 84 | +1. The t6 next-site: the 16x4 INTER strip's chroma coefficient-context | ||
| 85 | + stamping at 4:4:4 lossless. Measured above (ctx 3 vs 11 on U (2,8); | ||
| 86 | + oracle cells `above=[0] left=[23]`). The row-2 U band state our tree | ||
| 87 | + drops is written by the 16x16-intra/(0,4) stamping and consumed one | ||
| 88 | + superblock later; `decode_rect4_16_strip` is llcpred's lane — per the | ||
| 89 | + ticket this lane stops at the boundary. | ||
| 90 | + deferred(the 16x4 strip's per-unit chroma context stamping at 4:4:4 | ||
| 91 | + lossless; unblock: llcpred's decode_rect4_16_strip lane, t6.obu as the | ||
| 92 | + ready-made fixture, first divergent read #2489 = U unit (2,8)). | ||
| 93 | +2. Instrument parity: `read_coeffs_rect` still has no `EC_ECDUMP_IN` rung | ||
| 94 | + (av1llintercdf item 2) — this lane's walk bypasses the rect reader | ||
| 95 | + entirely, so the rung was not needed here. | ||