From f487a7ac7a69310b51c4c92769300f0bbb381d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 25 Sep 2026 19:25:26 +0300 Subject: [PATCH] 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 --- .../fixtures/444_sb128rect_lr_witness.obu | Bin 0 -> 794 bytes crates/ec-av1/src/decode.rs | 30 ++++-- lanes/av1444sb.report.md | 87 ++++++++++++++++++ 3 files changed, 108 insertions(+), 9 deletions(-) create mode 100644 crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu create mode 100644 lanes/av1444sb.report.md diff --git a/crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu b/crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu new file mode 100644 index 0000000000000000000000000000000000000000..daaf7c390403b24a0f429616cd75f8cf2a5ddd26 GIT binary patch literal 794 zcmV+#1Lgb@0165q000BM{QLj&1TxbD5CDV#004vlz%$H>DK2Qo4+3BhKlfi^z}gF% z!}VW`2(ut$4!j4(oUD4z+wEe1MM>bxirx&8ARl_a9?PoA9HC<($6=pf>qPcKim}aBrT0$RIat1VieS@8AitwU7fZ| zt)X*(Q3JX|6yQvTBNC1Bb8&0R#0~F**l!9U$I>d_WkIV~&`=Kbj98Z5bZv%>r}YYW zaEmt+JLMw$UzvV3BV;L^b##ER3Fd#1wQms5|Mei)sWvAGUMgFv8jN+fOd*rEvAO^yi@F@l5Ux0m4q2 zgK=8G;(d-}=8q!qiMMb-R%zyT+76Hs05XmNFav;q002gcAOHZAF~bx60H++~MC9g1 ztinHYq@S^hSNf$0M?=U38loD|oH7&vacaROMxoI451S!i*Xc4SF$4;hA)MVIx4f02 z*}2#G6p=A`2~9dRA@|>oFM8L+x9s3gaM{a`rjMFP2Kr_(=E01|hcEx3cHihd~0QJSvM& zzM@kQN|UV}OXojZdBN(6u9zTFct4&CVO<`zH9t4=*qtFW@@6qzl;qmGS~*4U-Oo$! z9Qh9Q(mk3?fdx_vH`L$nL}Z>9lB^U@mHk!We>}tqQMXT<&TuZGSz-5Pl(g2+r8bWH YHr5r-6x3L($&{_ki@hu^WUx5$XEuj_{r~^~ literal 0 HcmV?d00001 diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 2c8bbd6b..43eb62c3 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -17712,8 +17712,16 @@ fn decode_block_128rect( let mi_rows = 2 * y.true_height.div_ceil(8); let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(mi_c)); let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(mi_r)); - // Non-lossless: one 32x32 chroma unit per mu chunk, per plane. - debug_assert!(lossless_frame || (chroma_w / chroma_tx, chroma_h / chroma_tx) == (nch_x, nch_y)); + // Non-lossless: per mu chunk, `(64 >> ss) / chroma_tx` chroma units per + // axis (one 32x32 at 4:2:0, four 32x32 at 4:4:4 — lane-av1-444sb). + debug_assert!( + lossless_frame + || (chroma_w / chroma_tx, chroma_h / chroma_tx) + == ( + nch_x * ((64 >> ss_x(fctx)) / chroma_tx), + nch_y * ((64 >> ss_y(fctx)) / chroma_tx) + ) + ); let tpc = 64 / logical_tx; let zero_tu = vec![0i32; logical_tx * logical_tx]; let zero_cu = vec![0i32; chroma_tx * chroma_tx]; @@ -17791,9 +17799,13 @@ fn decode_block_128rect( neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid); } } - // Transform units per axis inside this mu chunk's 32x32 chroma - // span: one 32x32 unit normally, 8x8 TX_4X4 units when lossless. - let cn = (32 / chroma_tx).max(1); + // Transform units per axis inside this mu chunk's chroma span: + // a 64x64 luma chunk covers `64 >> ss` chroma pixels per axis, so + // it holds `(64 >> ss) / chroma_tx` units — one 32x32 at 4:2:0, + // four at 4:4:4 (lane-av1-444sb: the hardcoded 4:2:0 span read + // one unit per chunk there, left six of a 128x64 block's eight + // 32x32 units unread and desynced the tile from that block on). + let cn = ((64 >> ss_x(fctx)) / chroma_tx).max(1); // libaom's per-chunk `unit_width/height` (plane-mi units of the // luma mi grid): `min(mu_blocks + col, max_blocks) >> ss`. let unit_w = ((ch_col + 1) * 16).min(max_w_mi) >> ss_x(fctx); @@ -17807,13 +17819,13 @@ fn decode_block_128rect( for plane_pass in 1..=2usize { for ci_row in 0..cn { for ci_col in 0..cn { - if ch_col * 8 + ci_col * stepc >= unit_w - || ch_row * 8 + ci_row * stepc >= unit_h + if ch_col * (16 >> ss_x(fctx)) + ci_col * stepc >= unit_w + || ch_row * (16 >> ss_y(fctx)) + ci_row * stepc >= unit_h { continue; } - let cu_x = cpx + ch_col * 32 + ci_col * chroma_tx; - let cu_y = cpy + ch_row * 32 + ci_row * chroma_tx; + let cu_x = cpx + ch_col * (64 >> ss_x(fctx)) + ci_col * chroma_tx; + let cu_y = cpy + ch_row * (64 >> ss_y(fctx)) + ci_row * chroma_tx; let cu_mi = ( mi_r + ch_row * 16 + ci_row * ((chroma_tx << ss_y(fctx)) / 4), mi_c + ch_col * 16 + ci_col * ((chroma_tx << ss_x(fctx)) / 4), diff --git a/lanes/av1444sb.report.md b/lanes/av1444sb.report.md new file mode 100644 index 00000000..b7562b93 --- /dev/null +++ b/lanes/av1444sb.report.md @@ -0,0 +1,87 @@ +# lane-av1-444sb — the 128-rect 4:4:4 chroma-span desync: NAMED and FIXED + +## Outcome + +1. REMEASURED first (pinned fixture + `crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu`, sha256 + `27825e14633a4b23e37d48a2acdc7f5d814ca4fadd0b8797d72a1ffb34061e80`, + generated per the report recipe: `ffmpeg -i bands444.y4m -frames:v 3 -vf + scale=192:160 -pix_fmt yuv444p -f yuv4mpegpipe` piped to + `aomenc --codec=av1 --profile=1 --passes=1 --end-usage=q --cq-level=32 + --cpu-used=0 --threads=1 --row-mt=0 --sb-size=128 --lag-in-frames=0 + --auto-alt-ref=0 --kf-max-dist=1000 --i444 --enable-restoration=1 --obu + --limit=3`): at 76f8c3fe frame 0 diverges at EC_AV1_PREFILT_DUMP with + Y 9700 @ (128,64), U 12272 @ (160,0), V 13175 @ (128,0) — the ticket's + class (first diffs on the 64/128 grid, chroma columns 160/128 matching + the finding). The synthetic-content variants tried first (testsrc2, + testsrc, smptebars, mandelbrot, gradients × cpu-used × cq) all decode + frame 0 exact — the damage needs an edge-forced 128-root rect, which + real content provides. +2. DEFECT — **`decode_block_128rect`'s chroma unit walk is hardcoded to the + 4:2:0 mu-chunk span**. One 32x32 chroma unit per 64x64 mu chunk per plane + (`cn = 32 / chroma_tx` = 1), chunk offsets `ch_col * 32` / + `ch_row * 32`, and a per-chunk clip step of `ch_col * 8`: all three are + the 4:2:0 numbers. At 4:4:4 a 64x64 luma chunk covers 64 chroma pixels and + needs TWO 32x32 units per axis. The units never pushed (measured by + env-gated per-unit exec tracing): (160,0),(160,32) of the 64x128 PART_VERT + block at (128,0), all four units of its second chunk, (64,128),(96,128) of + the bottom-row 128x64 — exactly the PREFILT damage cells. Because the + missing units' coefficients are still in the bitstream, the entropy + decoder desyncs from the first 128-rect intra block on: SB(0,0) decodes + byte-exact and every later superblock of frames 0/1 carries damage. +3. FIX (one site, decode.rs `decode_block_128rect`): per-chunk unit count + `(64 >> ss) / chroma_tx`, chunk chroma offsets `64 >> ss`, clip step + `16 >> ss` — every expression reduces to the old constant at ss=1, so + 4:2:0 is bit-identical by construction; the stale + `debug_assert!` (which stated the 4:2:0 invariant and would fire on 444 + in debug builds) now states the ss-aware one. +4. MEASURED after the fix, same fixture, same instrumented aomdec: + frame 0 PREFILT 0/0/0 and FINAL 0; frame 1 PREFILT 0/0/0 and FINAL 0; + frame 2 FINAL 0 — the whole 3-frame stream is byte-exact. +5. Stage-dump hazard worth recording: on frame 2 (pipelined last frame) the + PREFILT/POSTDEBLOCK/POSTCDEF dumps showed ~7-14k phantom per-plane diffs + while FINAL was byte-exact — the in-place filters have already touched + bands the mid-stage dump reads, so for a pipelined frame the mid-stage + dumps are not a clean stage ladder (class: stage-dump-on-pipelined-frame; + FINAL is the authoritative byte-exactness rung there). The frame-2 + "divergence" first seen mid-investigation was this artifact plus a stale + rebuild, not a residual defect; libaom-side confirmation is + `av1_get_adjusted_tx_size` (blockd.h:1361) capping TX_64X64 chroma at + TX_32X32, which is what the fixed walk now implements. + +## Verification + +- `cargo check -p ec-av1`: 0 warnings, 0 errors + (target `$HOME/.cache/cargo-target-av1444sb`). +- Gates green with the fix (EC_AV1_REQUIRE_AOMENC=1): + `a_real_aomenc_stream_with_restoration_reads_lr_symbols_correctly`, + `a_superres_key_frame_with_cdef_and_loop_restoration_decodes_pixel_exact`, + `a_non_420_subsampled_sequence_header_is_refused_by_name`, + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_ + decodes_pixel_exact` — 4 passed. +- Byte-exactness method: our `decode_probe` stage dumps vs the instrumented + `$HOME/.cache/aom-oracle/build` aomdec rungs, per-frame plane-cropped + numpy compare; binary identity to the current source proven by a fresh + target-dir rebuild with matching sha256 after the incrementals went + suspicious (0.7s "Finished"). + +## Decision + +- One site, fixed. `decode_block_128rect` serves the kf PART128 HORZ/VERT + and AB arms plus the intra-in-inter 128 path (`in_inter` flag) — one walk, + all callers covered. +- NOT touched: `sub8_leaf_chroma444`'s rect arm (sibling lane, distinct + open defect: one TX_8X4/4X8 unit where the oracle codes four TX_4X4 at + ctx 1 vs 11), `decode_leaf8` OOB (leaf8oob's), the 4:2:0 group-tail + chroma SKIP arm (reserved), `read_coeffs_rect`. +- The lane-av1-422filter ss_y snapshot fix is NOT in this branch's ancestry + and was NOT needed here (444 is exact without it); applying it locally as + an experiment changed nothing on this stream and was reverted + byte-identically. +- Temp EC_TRACE_444SB / EREAD_RECT instrumentation removed before commit; + the diff carries only the fix, the assert, and comments. + +## State + +- Commit on lane-av1-444sb (no push): the ss-aware 128rect chroma walk + + the witness fixture + this report.