ec-av1: lane-av1-444sb -- the 128-rect chroma unit walk was hardcoded to the 4:2:0 mu-chunk span (one 32x32 unit per chunk, chunk offsets 32, clip step 8), so at 4:4:4 a 128-root HORZ/VERT intra block coded half its chroma units, left the remaining units' coefficients unread and desynced the tile from the first 128-rect block on; the walk is now ss-aware ((64 >> ss) / chroma_tx units per chunk, 64 >> ss chunk offsets, 16 >> ss clip step -- every expression reduces to the old constant at 4:2:0) and the stale debug_assert states the ss-aware invariant; a 192x160 3-frame aomenc --profile=1 --enable-restoration=1 --sb-size=128 witness (bands444, fixture sha 27825e14...) that diverged at PREFILT with Y 9700 at (128,64), U 12272 at (160,0), V 13175 at (128,0) decodes byte-exact vs the instrumented aomdec on all three frames at FINAL (frames 0/1 also byte-exact at PREFILT/POSTDEBLOCK/POSTCDEF); the LR-snapshot ss_y, sub8 rect chroma, leaf8 OOB and group-tail arms are untouched
Browse files at this commitf487a7ac7a69310b51c4c92769300f0bbb381d3cParent: 97a90383 changed files +108 -9
- crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu +0 -0
- crates/ec-av1/src/decode.rs +21 -9
- lanes/av1444sb.report.md +87 -0
crates/ec-av1/fixtures/444_sb128rect_lr_witness.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+21 -9
| @@ -17712,8 +17712,16 @@ fn decode_block_128rect( | ||
| 17712 | 17712 | let mi_rows = 2 * y.true_height.div_ceil(8); |
| 17713 | 17713 | let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(mi_c)); |
| 17714 | 17714 | let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(mi_r)); |
| 17715 | - // Non-lossless: one 32x32 chroma unit per mu chunk, per plane. | |
| 17716 | - debug_assert!(lossless_frame || (chroma_w / chroma_tx, chroma_h / chroma_tx) == (nch_x, nch_y)); | |
| 17715 | + // Non-lossless: per mu chunk, `(64 >> ss) / chroma_tx` chroma units per | |
| 17716 | + // axis (one 32x32 at 4:2:0, four 32x32 at 4:4:4 — lane-av1-444sb). | |
| 17717 | + debug_assert!( | |
| 17718 | + lossless_frame | |
| 17719 | + || (chroma_w / chroma_tx, chroma_h / chroma_tx) | |
| 17720 | + == ( | |
| 17721 | + nch_x * ((64 >> ss_x(fctx)) / chroma_tx), | |
| 17722 | + nch_y * ((64 >> ss_y(fctx)) / chroma_tx) | |
| 17723 | + ) | |
| 17724 | + ); | |
| 17717 | 17725 | let tpc = 64 / logical_tx; |
| 17718 | 17726 | let zero_tu = vec![0i32; logical_tx * logical_tx]; |
| 17719 | 17727 | let zero_cu = vec![0i32; chroma_tx * chroma_tx]; |
| @@ -17791,9 +17799,13 @@ fn decode_block_128rect( | ||
| 17791 | 17799 | neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid); |
| 17792 | 17800 | } |
| 17793 | 17801 | } |
| 17794 | - // Transform units per axis inside this mu chunk's 32x32 chroma | |
| 17795 | - // span: one 32x32 unit normally, 8x8 TX_4X4 units when lossless. | |
| 17796 | - let cn = (32 / chroma_tx).max(1); | |
| 17802 | + // Transform units per axis inside this mu chunk's chroma span: | |
| 17803 | + // a 64x64 luma chunk covers `64 >> ss` chroma pixels per axis, so | |
| 17804 | + // it holds `(64 >> ss) / chroma_tx` units — one 32x32 at 4:2:0, | |
| 17805 | + // four at 4:4:4 (lane-av1-444sb: the hardcoded 4:2:0 span read | |
| 17806 | + // one unit per chunk there, left six of a 128x64 block's eight | |
| 17807 | + // 32x32 units unread and desynced the tile from that block on). | |
| 17808 | + let cn = ((64 >> ss_x(fctx)) / chroma_tx).max(1); | |
| 17797 | 17809 | // libaom's per-chunk `unit_width/height` (plane-mi units of the |
| 17798 | 17810 | // luma mi grid): `min(mu_blocks + col, max_blocks) >> ss`. |
| 17799 | 17811 | let unit_w = ((ch_col + 1) * 16).min(max_w_mi) >> ss_x(fctx); |
| @@ -17807,13 +17819,13 @@ fn decode_block_128rect( | ||
| 17807 | 17819 | for plane_pass in 1..=2usize { |
| 17808 | 17820 | for ci_row in 0..cn { |
| 17809 | 17821 | for ci_col in 0..cn { |
| 17810 | - if ch_col * 8 + ci_col * stepc >= unit_w | |
| 17811 | - || ch_row * 8 + ci_row * stepc >= unit_h | |
| 17822 | + if ch_col * (16 >> ss_x(fctx)) + ci_col * stepc >= unit_w | |
| 17823 | + || ch_row * (16 >> ss_y(fctx)) + ci_row * stepc >= unit_h | |
| 17812 | 17824 | { |
| 17813 | 17825 | continue; |
| 17814 | 17826 | } |
| 17815 | - let cu_x = cpx + ch_col * 32 + ci_col * chroma_tx; | |
| 17816 | - let cu_y = cpy + ch_row * 32 + ci_row * chroma_tx; | |
| 17827 | + let cu_x = cpx + ch_col * (64 >> ss_x(fctx)) + ci_col * chroma_tx; | |
| 17828 | + let cu_y = cpy + ch_row * (64 >> ss_y(fctx)) + ci_row * chroma_tx; | |
| 17817 | 17829 | let cu_mi = ( |
| 17818 | 17830 | mi_r + ch_row * 16 + ci_row * ((chroma_tx << ss_y(fctx)) / 4), |
| 17819 | 17831 | mi_c + ch_col * 16 + ci_col * ((chroma_tx << ss_x(fctx)) / 4), |
lanes/av1444sb.report.mdadded+87 -0
| @@ -0,0 +1,87 @@ | ||
| 1 | +# lane-av1-444sb — the 128-rect 4:4:4 chroma-span desync: NAMED and FIXED | |
| 2 | + | |
| 3 | +## Outcome | |
| 4 | + | |
| 5 | +1. REMEASURED first (pinned fixture | |
| 6 | + `crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu`, sha256 | |
| 7 | + `27825e14633a4b23e37d48a2acdc7f5d814ca4fadd0b8797d72a1ffb34061e80`, | |
| 8 | + generated per the report recipe: `ffmpeg -i bands444.y4m -frames:v 3 -vf | |
| 9 | + scale=192:160 -pix_fmt yuv444p -f yuv4mpegpipe` piped to | |
| 10 | + `aomenc --codec=av1 --profile=1 --passes=1 --end-usage=q --cq-level=32 | |
| 11 | + --cpu-used=0 --threads=1 --row-mt=0 --sb-size=128 --lag-in-frames=0 | |
| 12 | + --auto-alt-ref=0 --kf-max-dist=1000 --i444 --enable-restoration=1 --obu | |
| 13 | + --limit=3`): at 76f8c3fe frame 0 diverges at EC_AV1_PREFILT_DUMP with | |
| 14 | + Y 9700 @ (128,64), U 12272 @ (160,0), V 13175 @ (128,0) — the ticket's | |
| 15 | + class (first diffs on the 64/128 grid, chroma columns 160/128 matching | |
| 16 | + the finding). The synthetic-content variants tried first (testsrc2, | |
| 17 | + testsrc, smptebars, mandelbrot, gradients × cpu-used × cq) all decode | |
| 18 | + frame 0 exact — the damage needs an edge-forced 128-root rect, which | |
| 19 | + real content provides. | |
| 20 | +2. DEFECT — **`decode_block_128rect`'s chroma unit walk is hardcoded to the | |
| 21 | + 4:2:0 mu-chunk span**. One 32x32 chroma unit per 64x64 mu chunk per plane | |
| 22 | + (`cn = 32 / chroma_tx` = 1), chunk offsets `ch_col * 32` / | |
| 23 | + `ch_row * 32`, and a per-chunk clip step of `ch_col * 8`: all three are | |
| 24 | + the 4:2:0 numbers. At 4:4:4 a 64x64 luma chunk covers 64 chroma pixels and | |
| 25 | + needs TWO 32x32 units per axis. The units never pushed (measured by | |
| 26 | + env-gated per-unit exec tracing): (160,0),(160,32) of the 64x128 PART_VERT | |
| 27 | + block at (128,0), all four units of its second chunk, (64,128),(96,128) of | |
| 28 | + the bottom-row 128x64 — exactly the PREFILT damage cells. Because the | |
| 29 | + missing units' coefficients are still in the bitstream, the entropy | |
| 30 | + decoder desyncs from the first 128-rect intra block on: SB(0,0) decodes | |
| 31 | + byte-exact and every later superblock of frames 0/1 carries damage. | |
| 32 | +3. FIX (one site, decode.rs `decode_block_128rect`): per-chunk unit count | |
| 33 | + `(64 >> ss) / chroma_tx`, chunk chroma offsets `64 >> ss`, clip step | |
| 34 | + `16 >> ss` — every expression reduces to the old constant at ss=1, so | |
| 35 | + 4:2:0 is bit-identical by construction; the stale | |
| 36 | + `debug_assert!` (which stated the 4:2:0 invariant and would fire on 444 | |
| 37 | + in debug builds) now states the ss-aware one. | |
| 38 | +4. MEASURED after the fix, same fixture, same instrumented aomdec: | |
| 39 | + frame 0 PREFILT 0/0/0 and FINAL 0; frame 1 PREFILT 0/0/0 and FINAL 0; | |
| 40 | + frame 2 FINAL 0 — the whole 3-frame stream is byte-exact. | |
| 41 | +5. Stage-dump hazard worth recording: on frame 2 (pipelined last frame) the | |
| 42 | + PREFILT/POSTDEBLOCK/POSTCDEF dumps showed ~7-14k phantom per-plane diffs | |
| 43 | + while FINAL was byte-exact — the in-place filters have already touched | |
| 44 | + bands the mid-stage dump reads, so for a pipelined frame the mid-stage | |
| 45 | + dumps are not a clean stage ladder (class: stage-dump-on-pipelined-frame; | |
| 46 | + FINAL is the authoritative byte-exactness rung there). The frame-2 | |
| 47 | + "divergence" first seen mid-investigation was this artifact plus a stale | |
| 48 | + rebuild, not a residual defect; libaom-side confirmation is | |
| 49 | + `av1_get_adjusted_tx_size` (blockd.h:1361) capping TX_64X64 chroma at | |
| 50 | + TX_32X32, which is what the fixed walk now implements. | |
| 51 | + | |
| 52 | +## Verification | |
| 53 | + | |
| 54 | +- `cargo check -p ec-av1`: 0 warnings, 0 errors | |
| 55 | + (target `$HOME/.cache/cargo-target-av1444sb`). | |
| 56 | +- Gates green with the fix (EC_AV1_REQUIRE_AOMENC=1): | |
| 57 | + `a_real_aomenc_stream_with_restoration_reads_lr_symbols_correctly`, | |
| 58 | + `a_superres_key_frame_with_cdef_and_loop_restoration_decodes_pixel_exact`, | |
| 59 | + `a_non_420_subsampled_sequence_header_is_refused_by_name`, | |
| 60 | + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_ | |
| 61 | + decodes_pixel_exact` — 4 passed. | |
| 62 | +- Byte-exactness method: our `decode_probe` stage dumps vs the instrumented | |
| 63 | + `$HOME/.cache/aom-oracle/build` aomdec rungs, per-frame plane-cropped | |
| 64 | + numpy compare; binary identity to the current source proven by a fresh | |
| 65 | + target-dir rebuild with matching sha256 after the incrementals went | |
| 66 | + suspicious (0.7s "Finished"). | |
| 67 | + | |
| 68 | +## Decision | |
| 69 | + | |
| 70 | +- One site, fixed. `decode_block_128rect` serves the kf PART128 HORZ/VERT | |
| 71 | + and AB arms plus the intra-in-inter 128 path (`in_inter` flag) — one walk, | |
| 72 | + all callers covered. | |
| 73 | +- NOT touched: `sub8_leaf_chroma444`'s rect arm (sibling lane, distinct | |
| 74 | + open defect: one TX_8X4/4X8 unit where the oracle codes four TX_4X4 at | |
| 75 | + ctx 1 vs 11), `decode_leaf8` OOB (leaf8oob's), the 4:2:0 group-tail | |
| 76 | + chroma SKIP arm (reserved), `read_coeffs_rect`. | |
| 77 | +- The lane-av1-422filter ss_y snapshot fix is NOT in this branch's ancestry | |
| 78 | + and was NOT needed here (444 is exact without it); applying it locally as | |
| 79 | + an experiment changed nothing on this stream and was reverted | |
| 80 | + byte-identically. | |
| 81 | +- Temp EC_TRACE_444SB / EREAD_RECT instrumentation removed before commit; | |
| 82 | + the diff carries only the fix, the assert, and comments. | |
| 83 | + | |
| 84 | +## State | |
| 85 | + | |
| 86 | +- Commit on lane-av1-444sb (no push): the ss-aware 128rect chroma walk + | |
| 87 | + the witness fixture + this report. |