Merge branch 'lane-lossless3' (99ff3441): a skipped 8x8 leaf restored the previous block's luma band on lossless frames; rect sub-8x8 leaves split to 4x4 under lossless
Browse files at this commit3 changed files +121 -8
- crates/ec-av1/src/decode.rs +23 -5
- crates/ec-av1/src/stream.rs +8 -3
- lanes/lossless3.report.md +90 -0
crates/ec-av1/src/decode.rsmodified+23 -5
| @@ -11944,7 +11944,7 @@ fn decode_rect4_16_strip( | ||
| 11944 | 11944 | let (px, py) = (lmi.1 * MI, lmi.0 * MI); |
| 11945 | 11945 | let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx); |
| 11946 | 11946 | neighbours.record_mode_mi(lmi.0, lmi.1, mi_w, mi_h, mode); |
| 11947 | - if depth != 0 { | |
| 11947 | + if depth != 0 || lossless(fctx) { | |
| 11948 | 11948 | // [`decode_rect_split`]'s per-unit walk, inlined because the |
| 11949 | 11949 | // CHROMA of this shape belongs to the strip's 4:2:0 pair, not to |
| 11950 | 11950 | // the strip (that function codes one chroma transform per block). |
| @@ -16049,7 +16049,7 @@ fn decode_leaf_rect8( | ||
| 16049 | 16049 | // context -- `decode_leaf8`'s own depth-1 loop, two units instead of |
| 16050 | 16050 | // four. The per-TU path writes its own neighbour state, so the |
| 16051 | 16051 | // block-level write below is skipped for it. |
| 16052 | - let split = depth != 0; | |
| 16052 | + let split = depth != 0 || lossless(fctx); | |
| 16053 | 16053 | if split { |
| 16054 | 16054 | let mut done = 0usize; |
| 16055 | 16055 | for tu in 0..2usize { |
| @@ -30934,7 +30934,7 @@ fn decode_intra_sub8_leaf( | ||
| 30934 | 30934 | hit!(TX_DEPTH_HITS); |
| 30935 | 30935 | hit!(RECT8_SPLIT_TX_HITS); |
| 30936 | 30936 | } |
| 30937 | - let split = depth != 0; | |
| 30937 | + let split = depth != 0 || (lossless(fctx) && bw != bh); | |
| 30938 | 30938 | let (px, py) = (lmi.1 * MI, lmi.0 * MI); |
| 30939 | 30939 | let reach = if bw == bh { |
| 30940 | 30940 | Reach::of(bw, px, py, y.width, y.height, fctx) |
| @@ -32787,7 +32787,16 @@ fn decode_inter_block8( | ||
| 32787 | 32787 | // leaf published level 0 to its right/below neighbours: the next |
| 32788 | 32788 | // block's first TU read `skip_contexts[4][0] = 3` where aomdec |
| 32789 | 32789 | // reads `[4][4] = 6` (class early-return-skips-tail). |
| 32790 | - let saved_luma_ctx = split8.then(|| { | |
| 32790 | + // lane-lossless3: `!skip` too. A SKIP block codes no coefficients and so | |
| 32791 | + // publishes nothing per transform unit, and on a LOSSLESS frame | |
| 32792 | + // `read_block_tx_size` hands back 4x4 leaves for a skip block as well | |
| 32793 | + // (libaom's `read_tx_size` returns TX_4X4 before it reads anything), so | |
| 32794 | + // `split8` is true over an UNTOUCHED band -- the restore then put the | |
| 32795 | + // previous block's levels back over the zeros `record_mi` had just | |
| 32796 | + // written, where libaom runs `av1_reset_entropy_context`. Class | |
| 32797 | + // [[override-slot-on-one-arm]]: a save/restore is only valid on the arm | |
| 32798 | + // that actually wrote the per-TU state. | |
| 32799 | + let saved_luma_ctx = (split8 && !skip).then(|| { | |
| 32791 | 32800 | ( |
| 32792 | 32801 | [ |
| 32793 | 32802 | neighbours.left[leaf_mi.0][0], |
| @@ -33969,7 +33978,16 @@ fn decode_inter_block8( | ||
| 33969 | 33978 | // but `record_mi` rewrites all three planes of these cells at once -- so |
| 33970 | 33979 | // save plane 0 across it, exactly as `record_split_luma` leaves plane 0 |
| 33971 | 33980 | // alone at the bigger block sizes. |
| 33972 | - let saved_luma_ctx = split8.then(|| { | |
| 33981 | +// lane-lossless3: `!skip` too. A SKIP block codes no coefficients and so | |
| 33982 | + // publishes nothing per transform unit, and on a LOSSLESS frame | |
| 33983 | + // `read_block_tx_size` hands back 4x4 leaves for a skip block as well | |
| 33984 | + // (libaom's `read_tx_size` returns TX_4X4 before it reads anything), so | |
| 33985 | + // `split8` is true over an UNTOUCHED band -- the restore then put the | |
| 33986 | + // previous block's levels back over the zeros `record_mi` had just | |
| 33987 | + // written, where libaom runs `av1_reset_entropy_context`. Class | |
| 33988 | + // [[override-slot-on-one-arm]]: a save/restore is only valid on the arm | |
| 33989 | + // that actually wrote the per-TU state. | |
| 33990 | + let saved_luma_ctx = (split8 && !skip).then(|| { | |
| 33973 | 33991 | ( |
| 33974 | 33992 | [ |
| 33975 | 33993 | neighbours.left[leaf_mi.0][0], |
crates/ec-av1/src/stream.rsmodified+8 -3
| @@ -4117,15 +4117,20 @@ pub(crate) mod tests { | ||
| 4117 | 4117 | // (w, h, frames, gop, bit depth, 128-superblock, screen content) |
| 4118 | 4118 | // lane-lossless2: the SCREEN rows carry palette blocks, which is what |
| 4119 | 4119 | // caught the whole-block palette prediction being handed to a 4x4 |
| 4120 | - // chroma unit; they are KEY-only, see the lane report's deferred | |
| 4121 | - // screen-inter desync. | |
| 4122 | - let cases: [(usize, usize, usize, &str, u32, bool, bool); 6] = [ | |
| 4120 | + // chroma unit. | |
| 4121 | + // lane-lossless3: the last row is a screen source with INTER frames -- | |
| 4122 | + // the row that caught both of this lane's defects (a skip 8x8 leaf | |
| 4123 | + // restoring the previous block's luma level band over the zeros | |
| 4124 | + // `av1_reset_entropy_context` writes, and a rect sub-8x8 INTRA leaf | |
| 4125 | + // reading one TX_4X8 unit where a lossless frame codes two TX_4X4). | |
| 4126 | + let cases: [(usize, usize, usize, &str, u32, bool, bool); 7] = [ | |
| 4123 | 4127 | (256, 128, 8, "4", 8, false, false), |
| 4124 | 4128 | (192, 96, 6, "3", 10, false, false), |
| 4125 | 4129 | (320, 192, 6, "3", 8, false, false), |
| 4126 | 4130 | (256, 256, 4, "2", 8, true, false), |
| 4127 | 4131 | (320, 192, 2, "1", 8, false, true), |
| 4128 | 4132 | (640, 384, 2, "1", 8, false, true), |
| 4133 | + (640, 384, 6, "3", 8, false, true), | |
| 4129 | 4134 | ]; |
| 4130 | 4135 | for &(w, h, frames, gop, depth, sb128, screen) in &cases { |
| 4131 | 4136 | let tag = format!( |
lanes/lossless3.report.mdadded+90 -0
| @@ -0,0 +1,90 @@ | ||
| 1 | +# lane-lossless3 — AV1 lossless decode: the two screen-content residues | |
| 2 | + | |
| 3 | +Branch `lane-lossless3`, base `c40432fc` (the lane-lossless2 merge). Fix commit | |
| 4 | +`6c9c36d3`. | |
| 5 | + | |
| 6 | +Both residues lane-lossless2 deferred are ONE finding: the crf-5 screen KEY | |
| 7 | +point of `bd_rate_screen_native` and the 640x384 `tune-content=screen -crf 0 | |
| 8 | +-g 3` inter desync are the same two defects. The gate reports only the FIRST | |
| 9 | +differing sample, which is why "frame 0 plane Y sample 625: ours 41, ffmpeg 40" | |
| 10 | +read like a ±1 prediction-edge rule; reproduced on the gate's own stream it is a | |
| 11 | +2.8-million-sample entropy desync in every one of the 12 frames (class | |
| 12 | +[[last-block-desync-reads-as-reconstruction]] inverted: a FIRST-sample report | |
| 13 | +hides the size of the desync behind it). | |
| 14 | + | |
| 15 | +## Defect 1 — a skipped 8x8 leaf restored the previous block's luma level band | |
| 16 | +`decode_inter_block8` / `decode_leaf8` save plane 0 across the whole-block | |
| 17 | +`record_mi` write (`saved_luma_ctx`), because a var-tx split leaf has already | |
| 18 | +published its per-transform-unit levels and `record_mi` would flatten them. | |
| 19 | + | |
| 20 | +- **First divergence**: 640x384 screen `-g 3`, `all_zero` symbol #26551, block | |
| 21 | + mi (2,158): our `txb_skip_ctx` 3, aomdec's 1. `EC_ECDUMP` showed `left[2]=7` | |
| 22 | + where the block at mi (2,156) had just published 0. | |
| 23 | +- **Root cause**: the save/restore is predicated on `split8` alone. A SKIP block | |
| 24 | + publishes nothing per unit — and on a LOSSLESS frame `read_block_tx_size` | |
| 25 | + returns 4x4 leaves for a skip block too (libaom `read_tx_size` returns TX_4X4 | |
| 26 | + before it looks at anything), so `split8` is true over an UNTOUCHED band. The | |
| 27 | + restore then put the PREVIOUS block's levels back over the zeros `record_mi` | |
| 28 | + had just written, where libaom runs `av1_reset_entropy_context`. | |
| 29 | +- **Class**: [[override-slot-on-one-arm]] — a save/restore is only valid on the | |
| 30 | + arm that actually wrote the state it saves. | |
| 31 | +- **Fix**: `(split8 && !skip).then(..)` at both sites (the compound early-return | |
| 32 | + arm and the shared fall-through/intra tail). | |
| 33 | +- **Sweep**: those are the only two `saved_luma_ctx` sites. The fix also closes | |
| 34 | + the same latent shape on a NON-lossless intra 8x8 leaf whose `tx_depth` split | |
| 35 | + and whose `skip` is set (`read_block_tx_size`'s `!is_inter && tx != side` arm | |
| 36 | + returns leaves regardless of `skip`); the non-lossless INTER path was never | |
| 37 | + exposed because its var-tx tree is gated on `is_inter && !skip`. | |
| 38 | + | |
| 39 | +## Defect 2 — a rect sub-8x8 leaf read one TX_4X8 where lossless codes two TX_4X4 | |
| 40 | +- **First divergence** (after defect 1 was fixed): `all_zero` #26912, a 4x8 leaf | |
| 41 | + at mi (22,10): we read ONE rect unit with `txb_skip_ctx` 0 (the lone-TU rule), | |
| 42 | + aomdec read a TX_4X4 with ctx 1. | |
| 43 | +- **Root cause**: these readers split only when the `tx_depth` symbol is | |
| 44 | + nonzero, and a lossless frame codes no `tx_depth` symbol at all (`tx_select` | |
| 45 | + is off, `tx_mode == ONLY_4X4`), so `split` stayed false and the leaf was read | |
| 46 | + as one TX_4X8/TX_8X4. | |
| 47 | +- **Class**: the ledger's own `constraint|lane-lossless` — "the rect strip | |
| 48 | + readers only call `depth_to_tx_wh` when the tx_depth symbol is nonzero, so | |
| 49 | + forcing TX_4X4 also needs their `if depth != 0` guards widened". Five sites | |
| 50 | + already carried `|| lossless(fctx)`; three did not. | |
| 51 | +- **Fix + sweep** (every remaining `depth != 0` split guard in `decode.rs`): | |
| 52 | + `decode_intra_sub8_leaf` (`|| (lossless && bw != bh)` — a BLOCK_4X4 leaf must | |
| 53 | + stay unsplit), `decode_leaf_rect8`, and the 16x4/4x16 rect4 reader's | |
| 54 | + `if depth != 0` unit walk. The other `depth != 0` occurrences are hit | |
| 55 | + counters and `EC_ISTEP` prints, not split decisions. | |
| 56 | + | |
| 57 | +## Fixtures | |
| 58 | +- The inter gate `a_lossless_libaom_inter_frame_decodes_sample_exact` grows a | |
| 59 | + seventh row: **640x384, 6 frames, `-g 3`, `tune-content=screen`, `-crf 0`** — | |
| 60 | + the recipe that reproduces both defects. Before the fix frames 1/2/4/5 differ | |
| 61 | + in 228k–333k samples (keys 0/3 exact); after, all six frames are exact. | |
| 62 | +- The gate's own crf-5 screen stream (OBS capture, `crop=1920:1024:320:208`, | |
| 63 | + 12 frames, `-cpu-used 6 -b:v 0 -crf 5`) decodes sample-exact in all 12 frames; | |
| 64 | + with the fix reverted it is 2.80M/2.81M samples wrong per frame. | |
| 65 | + | |
| 66 | +## Results | |
| 67 | +| gate | result | | |
| 68 | +|---|---| | |
| 69 | +| `a_lossless_libaom_inter_frame_decodes_sample_exact` (7 rows, new screen-inter row) | PASS | | |
| 70 | +| `a_lossless_libaom_key_frame_decodes_sample_exact` | PASS | | |
| 71 | +| DECIDING `bd_rate_screen_native` | **GREEN**, 424.9 s, every reference point decodes (no `LADDER DECODE FAILURE`) | | |
| 72 | +| crate suite `-p ec-av1 --release --lib --test-threads=1` | 558 passed / 0 failed / 44 ignored, 1000.6 s | | |
| 73 | +| `the_encoders_own_streams_are_byte_identical_to_their_pins` | PASS, pins 9835 / 35798 untouched (no encoder change this lane) | | |
| 74 | +| `cargo check --workspace --all-targets -j4` | RC=0, 0 errors, 0 ec-av1 warnings (22 pre-existing: 21 ec-opus, 1 ec-vorbis test) | | |
| 75 | + | |
| 76 | +### `bd_rate_screen_native` table (baseline knobs, 12 frames, gop 12, 1 tile) | |
| 77 | +| clip | ours PSNR/bytes per point | BD vs libaom | BD vs rav1e | wall ours:libaom:rav1e | | |
| 78 | +|---|---|---|---|---| | |
| 79 | +| bars 1080p 1920x1024 | 44.10 dB/218144 B, 47.66/318010, 51.05/439435, 54.25/587007 | +1.7% | -14.5% | 47.6s:8.2s:18.6s | | |
| 80 | +| bars 2160p 1920x1024 | 43.70 dB/228646 B, 47.60/341309, 51.18/452951, 54.52/582847 | +12.2% | -10.2% | 33.5s:6.6s:18.8s | | |
| 81 | +| film A (1080p source) 1920x768 | 44.23 dB/75096 B, 45.82/125659, 47.05/217532, 48.31/518999 | +37.5% | +7.6% | 68.3s:10.6s:15.4s | | |
| 82 | +| film B (2160p HDR source) 1920x1024 | 46.69 dB/34137 B, 48.03/69950, 49.15/149378, 50.29/399139 | +54.1% | +23.9% | 67.4s:22.1s:17.4s | | |
| 83 | +| screen capture 1920x1024 | 45.87 dB/40155 B, 48.55/51325, 50.86/63998, 53.07/80203 | +33.4% | -23.8% | 43.7s:9.6s:12.9s | | |
| 84 | + | |
| 85 | +The BD numbers are unchanged from lane-lossless2's run (this lane touches the | |
| 86 | +DECODER only); what changed is that the crf-5 screen reference point now | |
| 87 | +decodes, so the gate exits 0 instead of failing `assert_ladder_decodes`. | |
| 88 | + | |
| 89 | +## Deferred | |
| 90 | +- `deferred: a frame mixing lossless and lossy segments — still refused by name; unchanged from lane-lossless2 (no libaom recipe found that emits one).` |