forge
Explore
Log in

Don't you dare go Hollow

The 1:4 intra strip readers never published the TXFM_CONTEXT bands

Browse files at this commit

a43f3c74f16933e4b24ea11a174b0fa3c371c2e1Ahmet Kaan GümüşParent: c249957
  • fix
    • the 1:4 intra strip readers never published the TXFM_CONTEXT bands
Show full message
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.rsmodified+66 -0
@@ -142,6 +142,72 @@ fn main() {
142 _ => continue,142 _ => continue,
143 };143 };
144 frames_seen += 1;144 frames_seen += 1;
145+ // lane-frame36: `EC_PROBE_HDR=1` prints one line per frame header, so a
146+ // silent wall can be triaged by "which header field is new at frame N"
147+ // before any pixel work (class: a header field parsed then never consumed).
148+ if std::env::var("EC_PROBE_HDR").is_ok() {
149+ let h = header;
150+ let gm: Vec<String> = h
151+ .global_motion
152+ .iter()
153+ .map(|w| format!("{:?}", w.model))
154+ .collect();
155+ println!(
156+ "HDR {}: type={:?} show={} showable={} show_existing={}({}) intra={} \
157+ size={}x{} up={} superres={}/{} order_hint={} primary_ref={} refresh={:#04x} \
158+ refs={:?} order_hints={:?} sign_bias={:?} err_res={} disable_cdf={} \
159+ screen_tools={} int_mv={} intrabc={} hp_mv={} interp={:?} switchable_motion={} \
160+ ref_mvs={} base_q={} seg={} deltaq={} deltalf={} lf_level={:?} lf_deltas={:?}/{:?} \
161+ cdef_bits={} lr={:?} tx_mode={:?} ref_sel={} skip_mode={}({:?}) warp={} \
162+ reduced_tx={} gm={:?} grain={}/seed={} lossless={}",
163+ frames_seen - 1,
164+ h.frame_type,
165+ h.show_frame,
166+ h.showable_frame,
167+ h.show_existing_frame,
168+ h.frame_to_show_map_idx,
169+ h.frame_is_intra,
170+ h.frame_width,
171+ h.frame_height,
172+ h.upscaled_width,
173+ h.use_superres,
174+ h.superres_denom,
175+ h.order_hint,
176+ h.primary_ref_frame,
177+ h.refresh_frame_flags,
178+ h.ref_frame_idx,
179+ h.order_hints,
180+ h.ref_frame_sign_bias,
181+ h.error_resilient_mode,
182+ h.disable_cdf_update,
183+ h.allow_screen_content_tools,
184+ h.force_integer_mv,
185+ h.allow_intrabc,
186+ h.allow_high_precision_mv,
187+ h.interpolation_filter,
188+ h.is_motion_mode_switchable,
189+ h.use_ref_frame_mvs,
190+ h.quantization.base_q_idx,
191+ h.segmentation.enabled,
192+ h.delta.q_present,
193+ h.delta.lf_present,
194+ h.loop_filter.level,
195+ h.loop_filter.ref_deltas,
196+ h.loop_filter.mode_deltas,
197+ h.cdef.bits,
198+ h.loop_restoration.frame_restoration_type,
199+ h.tx_mode,
200+ h.reference_select,
201+ h.skip_mode_present,
202+ h.skip_mode_frame,
203+ h.allow_warped_motion,
204+ h.reduced_tx_set,
205+ gm,
206+ h.film_grain.apply_grain,
207+ h.film_grain.grain_seed,
208+ h.coded_lossless,
209+ );
210+ }
145 let t = &header.tile_info;211 let t = &header.tile_info;
146 let entry = (t.cols, t.rows, t.uniform_spacing, t.context_update_tile_id);212 let entry = (t.cols, t.rows, t.uniform_spacing, t.context_update_tile_id);
147 if !seen.contains(&entry) {213 if !seen.contains(&entry) {
crates/ec-av1/src/decode.rsmodified+35 -0
@@ -9379,6 +9379,17 @@ fn decode_rect4_16_strip(
9379 record_strip_palette(9379 record_strip_palette(
9380 neighbours, lmi, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors,9380 neighbours, lmi, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors,
9381 );9381 );
9382+ // `set_txfm_ctxs(mbmi->tx_size, n4_w, n4_h, skip && is_inter, xd)`
9383+ // (libaom `decode_token_recon_block`, run for EVERY block of an inter
9384+ // frame): the above row records `tx_size_wide` over the block's width and
9385+ // the left column `tx_size_high` over its height. This 1:4 strip reader is
9386+ // also the INTER frame's reader for the shape ([`decode_intra_rect4_in_inter`]),
9387+ // and it published neither band -- so the block after a 64x16 strip read
9388+ // the row's init value 64 as its left transform height and took
9389+ // `tx_size_cat3` row 1 where libaom takes row 0 (lane-frame36 r1: the
9390+ // 3840x1608 10-bit stream's first silent wall, decode-order frame 33 at
9391+ // mi(16,480)). Same write as [`set_txfm_ctxs`], rect-aware.
9392+ txfm_partition_update_rect(neighbours, lmi, (tx_w, tx_h), (bw, bh));
9382 Ok((mode, last_uv_mode, (tx_w, tx_h)))9393 Ok((mode, last_uv_mode, (tx_w, tx_h)))
9383 }9394 }
9384 9395
@@ -9890,6 +9901,17 @@ fn decode_block_rect64(
9890 neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors);9901 neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors);
9891 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);9902 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);
9892 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0);9903 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0);
9904+ // `set_txfm_ctxs(mbmi->tx_size, n4_w, n4_h, skip && is_inter, xd)`
9905+ // (libaom `decode_token_recon_block`, run for EVERY block of an inter
9906+ // frame): the above row records `tx_size_wide` over the block's width and
9907+ // the left column `tx_size_high` over its height. This 1:4 strip reader is
9908+ // also the INTER frame's reader for the shape ([`decode_intra_rect4_in_inter`]),
9909+ // and it published neither band -- so the block after a 64x16 strip read
9910+ // the row's init value 64 as its left transform height and took
9911+ // `tx_size_cat3` row 1 where libaom takes row 0 (lane-frame36 r1: the
9912+ // 3840x1608 10-bit stream's first silent wall, decode-order frame 33 at
9913+ // mi(16,480)). Same write as [`set_txfm_ctxs`], rect-aware.
9914+ txfm_partition_update_rect(neighbours, (mi_r, mi_c), (tx_w, tx_h), (bw, bh));
9893 SB_RECT_HITS.with(|c| c.set(c.get() + 1));9915 SB_RECT_HITS.with(|c| c.set(c.get() + 1));
9894 match (bw, bh) {9916 match (bw, bh) {
9895 (64, 16) => SB_RECT4_HORZ_HITS.with(|c| c.set(c.get() + 1)),9917 (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
13387 if has_left && n.left_inter[mi_r] {13409 if has_left && n.left_inter[mi_r] {
13388 left = n.left_side_mi[mi_r] >= side;13410 left = n.left_side_mi[mi_r] >= side;
13389 }13411 }
13412+ if std::env::var_os("EC_TXCTX").is_some() {
13413+ eprintln!(
13414+ "EC_TXCTX mi={mi_r},{mi_c} own={side} ha={has_above} hl={has_left} \
13415+ above_txfm={} left_txfm={} above_inter={} left_inter={} above_side={} left_side={} \
13416+ above={above} left={left}",
13417+ n.above_txfm[mi_c],
13418+ n.left_txfm[mi_r],
13419+ n.above_inter[mi_c],
13420+ n.left_inter[mi_r],
13421+ n.above_side_mi[mi_c],
13422+ n.left_side_mi[mi_r],
13423+ );
13424+ }
13390 match (has_above, has_left) {13425 match (has_above, has_left) {
13391 (true, true) => usize::from(above) + usize::from(left),13426 (true, true) => usize::from(above) + usize::from(left),
13392 (true, false) => usize::from(above),13427 (true, false) => usize::from(above),
lanes/frame36-r1.handoff.mdadded+76 -0
@@ -0,0 +1,76 @@
1+# lane-frame36 r1 HANDOFF (branch `lane-frame36`)
2+
3+## Working stream (pinned prefix, not yet a repo fixture)
4+`~/.cache/frame36-tmp/n58.obu` -- `python3 <scratch>/census4/trunc.py ~/.cache/hg-0.obu 58 <out>`
5+of the 2 s head cut of the 10-bit 3840x1608 stream. 32126 bytes,
6+sha256 `7f3b060da5aa9c537633e760c4af71316237db7692f6ae0d459bd2c2dd867d37`,
7+md5 `1e93c12f622cd1fb0c1cd9485cd8932e`. 58 frame headers, 40 decoded frames,
8+37 output frames. `ffmpeg -i n58.obu -pix_fmt yuv420p10le -f rawvideo` = 685393920 B.
9+
10+## What output frame 36 IS (EC_PROBE_HDR=1, a NEW rung added this round to decode_probe)
11+The charter's `EC_PROBE_HDR` did not exist; it does now (`decode_probe.rs`, one line per
12+frame header: type/show/showable/show_existing/refresh/refs/order hints/primary_ref/
13+q/seg/delta q,lf/lf levels+deltas/cdef bits/LR types/tx mode/ref_select/skip mode/warp/
14+reduced_tx/gm models/grain seed/lossless).
15+
16+* OUTPUT frame 36 = header **57**, a `show_existing_frame` of slot 6, whose content is the
17+ hidden frame coded at header **52** (`show=false showable=true`, order_hint 36,
18+ primary_ref=1, refresh 0x40, base_q 61, lf_level [1,1,4,0]).
19+* The real first wrong frame is **decode-order frame 33 = header 49**: `show=false`,
20+ order_hint 64 (the next ARF), primary_ref=0, refresh 0x02, base_q 34,
21+ refs=[0,2,0,0,0,3,0], order_hints=[32,0,32,32,32,16,32], skip_mode_frame [1,6]
22+ (every other frame uses [1,5]). Fields NEW at this frame vs 0..48:
23+ **cdef_bits 0 -> 1** and **loop_restoration [None,None,None] -> [Switchable,Sgrproj,Switchable]**
24+ (both revert at header 50). First non-zero `lf_level` in the whole stream is header 47
25+ ([4,4,0,0], luma only); first non-zero CHROMA lf level is header 50 ([3,3,1,1]).
26+ size/superres/seg/intrabc/hp_mv/reduced_tx/gm/tx_mode never change; gm is Identity throughout.
27+* Decode-order frames 33,34,35,36 map to headers 49,50,51,52; the whole wall is
28+ "hidden ARF wrong -> everything that references it wrong" (class `gate-blind-to-hidden-frames`).
29+
30+## Stage narrowing (all on n58.obu, both sides run under systemd-run MemoryMax=6G)
31+`EC_AV1_PREFILT_DUMP16` (ours) vs aomdec `EC_AV1_PREFILT_DUMP16` (the 8-bit
32+`EC_AV1_PREFILT_DUMP` **segfaults on this 10-bit stream** -- use the 16 variants;
33+aomdec has no POSTCDEF rung) at decode frame 33: prefilt already differs
34+(12222910 B of 18524160), i.e. **prediction/residual, not deblock/CDEF/LR/film grain**.
35+
36+## First wrong pixel (BEFORE the fix)
37+Prefilt frame 33: Y (x=1920, y=64) ours 173 vs aomdec 170; U/V first at (960,32).
38+That is superblock (mi_row 16, mi_col 480), 64x64, PARTITION_NONE, intra, in an inter frame.
39+
40+## Ladder result (EC_TRACE_PART/EC_TRACE_MODE_STEP ours vs aomdec EC_TRACE=1+EC_TRACE_MODE_STEP=1)
41+SB entry rng matches (36104 both). First diverging element:
42+`tx_depth` at mi(16,480) -- ours `val=0 ctx=1 rng=56472`, aomdec `val=0 ctx=0 cat=3 rng=34964`
43+(same value, wrong CDF ROW -> different range -> desync; class `wrong-alphabet-same-value`).
44+`EC_TXCTX` (print added to `tx_size_context_txfm` this round) shows why:
45+`left_txfm[16]=64` where libaom has the 64x16 strip's tx HEIGHT 16.
46+The preceding SB (16,464) is PARTITION_HORZ_4 = four 64x16 INTRA strips inside an inter frame.
47+
48+## Root cause + fix (committed)
49+`decode_block_rect64` / `decode_block_rect4` (the 1:4 strip readers, which are ALSO the inter
50+frame's readers via `decode_intra_rect4_in_inter`, decode.rs ~7455) never published libaom's
51+`set_txfm_ctxs` bands, so the next block read `TXFM_CTX_INIT` (64) as the left transform height.
52+Fix = one call each to the existing `txfm_partition_update_rect(neighbours, at_mi, (tx_w,tx_h), (bw,bh))`
53+at their tails (decode.rs:9389 area and :9911 area).
54+Result on n58.obu: output frame 36 differing bytes **1992768 -> 765464**; decode-order
55+prefilt f33 12222910 -> 6446616, f34 4549085 -> 1005614, f35 -> 759498, f36 -> 763799.
56+Frames 0..32 and 37,38,39 stay byte-exact vs aomdec's own FINAL dump.
57+
58+## EXACT NEXT STEP
59+The wall is NOT closed -- decode frame 33 (header 49) still differs. Redo the same ladder on the
60+NEW binary: `EC_TRACE_PART=1 EC_TRACE_MODE_STEP=1` ours vs `EC_TRACE=1 EC_TRACE_MODE_STEP=1`
61+aomdec, group lines into frames by the `EC_PART mi_row=0 mi_col=0 bsize=12` marker (ours now
62+emits 40 groups, aomdec 40; our SB-root print skips the last partial SB row -- compare by
63+`(mi_row,mi_col) -> rng`, our `ctx=` field is NOT aomdec's), find the first SB whose ENTRY rng
64+differs in frame 33 and dump every line of the SB BEFORE it. Then: pin the prefix as
65+`crates/ec-av1/fixtures/reelb_frame36_witness.obu` (`git add -f`) with a gate over every plane of
66+every decode-order frame + a hard assert on `intra_rect4_in_inter` (this stream: 64x16=8 16x64=9),
67+update gate_coverage, run the suite as a systemd unit, and re-probe the full `hg-0.obu`.
68+
69+## Artifacts (all under ~/.cache/frame36-tmp)
70+`n58.obu`, `hdr58.txt` (58 EC_PROBE_HDR lines), `ours/` + `aom/` (FINAL dumps, 40 frames each),
71+`opre/` + `apre/` (PREFILT16), `opd/` + `apd/` (POSTDEBLOCK16), `opart.txt`/`apart.txt`,
72+`omode.txt`/`amode.txt`, `osb464.txt`/`asb464.txt`, `otx.txt`.
73+
74+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
75+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
76+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