From a43f3c74f16933e4b24ea11a174b0fa3c371c2e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 19:22:59 +0300 Subject: [PATCH] fix(av1): the 1:4 intra strip readers never published the TXFM_CONTEXT bands decode_block_rect64/decode_block_rect4 are also the INTER frame's readers for a 64x16/16x64 (and 32x8/8x32) intra strip, but unlike every other intra-in-inter path they skipped libaom's set_txfm_ctxs write, so the block after a strip read the row's init value 64 as its left transform height and took the tx_size_cat3 CDF row 1 where libaom takes row 0 -- a same-value/wrong-row desync. Measured on a 58-OBU prefix of the 10-bit 3840x1608 stream (40 decoded frames): the first silent wall is decode-order frame 33, first wrong pixel Y(1920,64), first diverging element tx_depth at mi(16,480) (ours ctx=1 rng=56472, aomdec ctx=0 cat=3 rng=34964). Output frame 36 differing bytes 1992768 -> 765464; the wall is narrowed, not closed (see lanes/frame36-r1.handoff.md). Also adds two triage rungs: EC_PROBE_HDR=1 prints one line per frame header from decode_probe, and EC_TXCTX now also dumps tx_size_context_txfm's inputs. --- crates/ec-av1/examples/decode_probe.rs | 66 ++++++++++++++++++++++ crates/ec-av1/src/decode.rs | 35 ++++++++++++ lanes/frame36-r1.handoff.md | 76 ++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 lanes/frame36-r1.handoff.md diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index b10e749b..055fb939 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -142,6 +142,72 @@ fn main() { _ => continue, }; frames_seen += 1; + // lane-frame36: `EC_PROBE_HDR=1` prints one line per frame header, so a + // silent wall can be triaged by "which header field is new at frame N" + // before any pixel work (class: a header field parsed then never consumed). + if std::env::var("EC_PROBE_HDR").is_ok() { + let h = header; + let gm: Vec = h + .global_motion + .iter() + .map(|w| format!("{:?}", w.model)) + .collect(); + println!( + "HDR {}: type={:?} show={} showable={} show_existing={}({}) intra={} \ + size={}x{} up={} superres={}/{} order_hint={} primary_ref={} refresh={:#04x} \ + refs={:?} order_hints={:?} sign_bias={:?} err_res={} disable_cdf={} \ + screen_tools={} int_mv={} intrabc={} hp_mv={} interp={:?} switchable_motion={} \ + ref_mvs={} base_q={} seg={} deltaq={} deltalf={} lf_level={:?} lf_deltas={:?}/{:?} \ + cdef_bits={} lr={:?} tx_mode={:?} ref_sel={} skip_mode={}({:?}) warp={} \ + reduced_tx={} gm={:?} grain={}/seed={} lossless={}", + frames_seen - 1, + h.frame_type, + h.show_frame, + h.showable_frame, + h.show_existing_frame, + h.frame_to_show_map_idx, + h.frame_is_intra, + h.frame_width, + h.frame_height, + h.upscaled_width, + h.use_superres, + h.superres_denom, + h.order_hint, + h.primary_ref_frame, + h.refresh_frame_flags, + h.ref_frame_idx, + h.order_hints, + h.ref_frame_sign_bias, + h.error_resilient_mode, + h.disable_cdf_update, + h.allow_screen_content_tools, + h.force_integer_mv, + h.allow_intrabc, + h.allow_high_precision_mv, + h.interpolation_filter, + h.is_motion_mode_switchable, + h.use_ref_frame_mvs, + h.quantization.base_q_idx, + h.segmentation.enabled, + h.delta.q_present, + h.delta.lf_present, + h.loop_filter.level, + h.loop_filter.ref_deltas, + h.loop_filter.mode_deltas, + h.cdef.bits, + h.loop_restoration.frame_restoration_type, + h.tx_mode, + h.reference_select, + h.skip_mode_present, + h.skip_mode_frame, + h.allow_warped_motion, + h.reduced_tx_set, + gm, + h.film_grain.apply_grain, + h.film_grain.grain_seed, + h.coded_lossless, + ); + } let t = &header.tile_info; let entry = (t.cols, t.rows, t.uniform_spacing, t.context_update_tile_id); if !seen.contains(&entry) { diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index a0208ee7..4ec83b8e 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -9379,6 +9379,17 @@ fn decode_rect4_16_strip( record_strip_palette( neighbours, lmi, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, ); + // `set_txfm_ctxs(mbmi->tx_size, n4_w, n4_h, skip && is_inter, xd)` + // (libaom `decode_token_recon_block`, run for EVERY block of an inter + // frame): the above row records `tx_size_wide` over the block's width and + // the left column `tx_size_high` over its height. This 1:4 strip reader is + // also the INTER frame's reader for the shape ([`decode_intra_rect4_in_inter`]), + // and it published neither band -- so the block after a 64x16 strip read + // the row's init value 64 as its left transform height and took + // `tx_size_cat3` row 1 where libaom takes row 0 (lane-frame36 r1: the + // 3840x1608 10-bit stream's first silent wall, decode-order frame 33 at + // mi(16,480)). Same write as [`set_txfm_ctxs`], rect-aware. + txfm_partition_update_rect(neighbours, lmi, (tx_w, tx_h), (bw, bh)); Ok((mode, last_uv_mode, (tx_w, tx_h))) } @@ -9890,6 +9901,17 @@ fn decode_block_rect64( neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors); neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); + // `set_txfm_ctxs(mbmi->tx_size, n4_w, n4_h, skip && is_inter, xd)` + // (libaom `decode_token_recon_block`, run for EVERY block of an inter + // frame): the above row records `tx_size_wide` over the block's width and + // the left column `tx_size_high` over its height. This 1:4 strip reader is + // also the INTER frame's reader for the shape ([`decode_intra_rect4_in_inter`]), + // and it published neither band -- so the block after a 64x16 strip read + // the row's init value 64 as its left transform height and took + // `tx_size_cat3` row 1 where libaom takes row 0 (lane-frame36 r1: the + // 3840x1608 10-bit stream's first silent wall, decode-order frame 33 at + // mi(16,480)). Same write as [`set_txfm_ctxs`], rect-aware. + txfm_partition_update_rect(neighbours, (mi_r, mi_c), (tx_w, tx_h), (bw, bh)); SB_RECT_HITS.with(|c| c.set(c.get() + 1)); match (bw, bh) { (64, 16) => SB_RECT4_HORZ_HITS.with(|c| c.set(c.get() + 1)), @@ -13387,6 +13409,19 @@ fn tx_size_context_txfm(n: &Neighbours, (mi_r, mi_c): (usize, usize), side: usiz if has_left && n.left_inter[mi_r] { left = n.left_side_mi[mi_r] >= side; } + if std::env::var_os("EC_TXCTX").is_some() { + eprintln!( + "EC_TXCTX mi={mi_r},{mi_c} own={side} ha={has_above} hl={has_left} \ + above_txfm={} left_txfm={} above_inter={} left_inter={} above_side={} left_side={} \ + above={above} left={left}", + n.above_txfm[mi_c], + n.left_txfm[mi_r], + n.above_inter[mi_c], + n.left_inter[mi_r], + n.above_side_mi[mi_c], + n.left_side_mi[mi_r], + ); + } match (has_above, has_left) { (true, true) => usize::from(above) + usize::from(left), (true, false) => usize::from(above), diff --git a/lanes/frame36-r1.handoff.md b/lanes/frame36-r1.handoff.md new file mode 100644 index 00000000..360507fd --- /dev/null +++ b/lanes/frame36-r1.handoff.md @@ -0,0 +1,76 @@ +# lane-frame36 r1 HANDOFF (branch `lane-frame36`) + +## Working stream (pinned prefix, not yet a repo fixture) +`~/.cache/frame36-tmp/n58.obu` -- `python3 /census4/trunc.py ~/.cache/hg-0.obu 58 ` +of the 2 s head cut of the 10-bit 3840x1608 stream. 32126 bytes, +sha256 `7f3b060da5aa9c537633e760c4af71316237db7692f6ae0d459bd2c2dd867d37`, +md5 `1e93c12f622cd1fb0c1cd9485cd8932e`. 58 frame headers, 40 decoded frames, +37 output frames. `ffmpeg -i n58.obu -pix_fmt yuv420p10le -f rawvideo` = 685393920 B. + +## What output frame 36 IS (EC_PROBE_HDR=1, a NEW rung added this round to decode_probe) +The charter's `EC_PROBE_HDR` did not exist; it does now (`decode_probe.rs`, one line per +frame header: type/show/showable/show_existing/refresh/refs/order hints/primary_ref/ +q/seg/delta q,lf/lf levels+deltas/cdef bits/LR types/tx mode/ref_select/skip mode/warp/ +reduced_tx/gm models/grain seed/lossless). + +* OUTPUT frame 36 = header **57**, a `show_existing_frame` of slot 6, whose content is the + hidden frame coded at header **52** (`show=false showable=true`, order_hint 36, + primary_ref=1, refresh 0x40, base_q 61, lf_level [1,1,4,0]). +* The real first wrong frame is **decode-order frame 33 = header 49**: `show=false`, + order_hint 64 (the next ARF), primary_ref=0, refresh 0x02, base_q 34, + refs=[0,2,0,0,0,3,0], order_hints=[32,0,32,32,32,16,32], skip_mode_frame [1,6] + (every other frame uses [1,5]). Fields NEW at this frame vs 0..48: + **cdef_bits 0 -> 1** and **loop_restoration [None,None,None] -> [Switchable,Sgrproj,Switchable]** + (both revert at header 50). First non-zero `lf_level` in the whole stream is header 47 + ([4,4,0,0], luma only); first non-zero CHROMA lf level is header 50 ([3,3,1,1]). + size/superres/seg/intrabc/hp_mv/reduced_tx/gm/tx_mode never change; gm is Identity throughout. +* Decode-order frames 33,34,35,36 map to headers 49,50,51,52; the whole wall is + "hidden ARF wrong -> everything that references it wrong" (class `gate-blind-to-hidden-frames`). + +## Stage narrowing (all on n58.obu, both sides run under systemd-run MemoryMax=6G) +`EC_AV1_PREFILT_DUMP16` (ours) vs aomdec `EC_AV1_PREFILT_DUMP16` (the 8-bit +`EC_AV1_PREFILT_DUMP` **segfaults on this 10-bit stream** -- use the 16 variants; +aomdec has no POSTCDEF rung) at decode frame 33: prefilt already differs +(12222910 B of 18524160), i.e. **prediction/residual, not deblock/CDEF/LR/film grain**. + +## First wrong pixel (BEFORE the fix) +Prefilt frame 33: Y (x=1920, y=64) ours 173 vs aomdec 170; U/V first at (960,32). +That is superblock (mi_row 16, mi_col 480), 64x64, PARTITION_NONE, intra, in an inter frame. + +## Ladder result (EC_TRACE_PART/EC_TRACE_MODE_STEP ours vs aomdec EC_TRACE=1+EC_TRACE_MODE_STEP=1) +SB entry rng matches (36104 both). First diverging element: +`tx_depth` at mi(16,480) -- ours `val=0 ctx=1 rng=56472`, aomdec `val=0 ctx=0 cat=3 rng=34964` +(same value, wrong CDF ROW -> different range -> desync; class `wrong-alphabet-same-value`). +`EC_TXCTX` (print added to `tx_size_context_txfm` this round) shows why: +`left_txfm[16]=64` where libaom has the 64x16 strip's tx HEIGHT 16. +The preceding SB (16,464) is PARTITION_HORZ_4 = four 64x16 INTRA strips inside an inter frame. + +## Root cause + fix (committed) +`decode_block_rect64` / `decode_block_rect4` (the 1:4 strip readers, which are ALSO the inter +frame's readers via `decode_intra_rect4_in_inter`, decode.rs ~7455) never published libaom's +`set_txfm_ctxs` bands, so the next block read `TXFM_CTX_INIT` (64) as the left transform height. +Fix = one call each to the existing `txfm_partition_update_rect(neighbours, at_mi, (tx_w,tx_h), (bw,bh))` +at their tails (decode.rs:9389 area and :9911 area). +Result on n58.obu: output frame 36 differing bytes **1992768 -> 765464**; decode-order +prefilt f33 12222910 -> 6446616, f34 4549085 -> 1005614, f35 -> 759498, f36 -> 763799. +Frames 0..32 and 37,38,39 stay byte-exact vs aomdec's own FINAL dump. + +## EXACT NEXT STEP +The wall is NOT closed -- decode frame 33 (header 49) still differs. Redo the same ladder on the +NEW binary: `EC_TRACE_PART=1 EC_TRACE_MODE_STEP=1` ours vs `EC_TRACE=1 EC_TRACE_MODE_STEP=1` +aomdec, group lines into frames by the `EC_PART mi_row=0 mi_col=0 bsize=12` marker (ours now +emits 40 groups, aomdec 40; our SB-root print skips the last partial SB row -- compare by +`(mi_row,mi_col) -> rng`, our `ctx=` field is NOT aomdec's), find the first SB whose ENTRY rng +differs in frame 33 and dump every line of the SB BEFORE it. Then: pin the prefix as +`crates/ec-av1/fixtures/reelb_frame36_witness.obu` (`git add -f`) with a gate over every plane of +every decode-order frame + a hard assert on `intra_rect4_in_inter` (this stream: 64x16=8 16x64=9), +update gate_coverage, run the suite as a systemd unit, and re-probe the full `hg-0.obu`. + +## Artifacts (all under ~/.cache/frame36-tmp) +`n58.obu`, `hdr58.txt` (58 EC_PROBE_HDR lines), `ours/` + `aom/` (FINAL dumps, 40 frames each), +`opre/` + `apre/` (PREFILT16), `opd/` + `apd/` (POSTDEBLOCK16), `opart.txt`/`apart.txt`, +`omode.txt`/`amode.txt`, `osb464.txt`/`asb464.txt`, `otx.txt`. + +EVIDENCE: ~/.cache/frame36-tmp/{o,r}.raw | release decode_probe + ffmpeg on the pinned 58-OBU prefix, diff16.py 3840x1608 | frames 0-35 0 bytes, frame 36 1992768 -> 765464 after the fix +EVIDENCE: ~/.cache/frame36-tmp/{opre,apre}/p.f33 | ours EC_AV1_PREFILT_DUMP16 vs aomdec EC_AV1_PREFILT_DUMP16 | 12222910 differing bytes pre-filter => not a post-filter defect +EVIDENCE: ~/.cache/frame36-tmp/{omode,amode}.txt | EC_TRACE_PART+EC_TRACE_MODE_STEP vs aomdec EC_TRACE+EC_TRACE_MODE_STEP | first diverging element tx_depth mi(16,480) ctx 1 vs 0, rng 56472 vs 34964