forge
Explore
Log in

Don't you dare go Hollow

Cherry-pick lane-mergefix (3b96a3a): reset the var-tx above/left txfm contexts per tile and per superblock row

Browse files at this commit

703bfad572efd4d28bef0d5639d39f729a07f6faAhmet Kaan GümüşParent: b995924
crates/ec-av1/src/decode.rsmodified+17 -0
@@ -4614,6 +4614,14 @@ impl Neighbours {
4614 self.sub8_mode_col[i] = (usize::MAX, 0);4614 self.sub8_mode_col[i] = (usize::MAX, 0);
4615 self.uv_mode_col[i] = (usize::MAX, 0);4615 self.uv_mode_col[i] = (usize::MAX, 0);
4616 }4616 }
4617+ // lane-mergefix r2: `av1_zero_above_context` also memsets the txfm row
4618+ // over the tile's own column span (to `tx_size_wide[TX_SIZES_LARGEST]`,
4619+ // not zero) -- without it a second tile column reads the first one's
4620+ // resolved transform sizes as its own above context.
4621+ let tend = col1_mi.min(self.above_txfm.len());
4622+ for i in col0_mi.min(tend)..tend {
4623+ self.above_txfm[i] = TXFM_CTX_INIT;
4624+ }
4617 }4625 }
4618 4626
4619 /// Writes a just-decoded block's own palette-Y size/colours (`size == 0`4627 /// Writes a just-decoded block's own palette-Y size/colours (`size == 0`
@@ -5041,6 +5049,12 @@ impl Neighbours {
5041 self.left_palette_colors.iter_mut().for_each(|c| *c = [0u16; 8]);5049 self.left_palette_colors.iter_mut().for_each(|c| *c = [0u16; 8]);
5042 self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0);5050 self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0);
5043 self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]);5051 self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]);
5052+ // lane-mergefix r2: `av1_zero_left_context` memsets
5053+ // `left_txfm_context_buffer` to `tx_size_high[TX_SIZES_LARGEST]` at
5054+ // every superblock row of every tile -- the var-tx left context does
5055+ // NOT carry over a tile boundary (its `txfm_partition` ctx read the
5056+ // previous tile column's last block otherwise).
5057+ self.left_txfm.iter_mut().for_each(|t| *t = TXFM_CTX_INIT);
5044 }5058 }
5045 5059
5046 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next5060 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next
@@ -25486,6 +25500,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
25486 // lane-golomb r1 (class `parsed-then-discarded`): the gathered25500 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
25487 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT25501 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
25488 // (libaom `ec_read_partition_impl`).25502 // (libaom `ec_read_partition_impl`).
25503+ if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PARTG mi_row={} mi_col={} bsize=12 ctx={} rng={}", sb_r as usize * SB_MI as usize, sb_c as usize * SB_MI as usize, sb_ctx, dec.debug_state().0); }
25489 if bump_edge32_bit(25504 if bump_edge32_bit(
25490 4,25505 4,
25491 dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)),25506 dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)),
@@ -25812,6 +25827,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
25812 // lane-golomb r1 (class `parsed-then-discarded`): the gathered25827 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
25813 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT25828 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
25814 // (libaom `ec_read_partition_impl`).25829 // (libaom `ec_read_partition_impl`).
25830+ if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PARTG mi_row={} mi_col={} bsize=9 ctx={} rng={}", r32 as usize * BLOCK_MI as usize, c32 as usize * BLOCK_MI as usize, ctx32, dec.debug_state().0); }
25815 if {25831 if {
25816 let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE));25832 let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE));
25817 bump_edge32(b.min(1) as usize);25833 bump_edge32(b.min(1) as usize);
@@ -25937,6 +25953,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
25937 // lane-golomb r1 (class `parsed-then-discarded`): the gathered25953 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
25938 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT25954 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
25939 // (libaom `ec_read_partition_impl`).25955 // (libaom `ec_read_partition_impl`).
25956+ if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PARTG mi_row={} mi_col={} bsize=6 ctx={} rng={}", sr as usize * SUB_MI as usize, sc as usize * SUB_MI as usize, ctx16, dec.debug_state().0); }
25940 if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], VERT_ALIKE)) == 1 {25957 if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], VERT_ALIKE)) == 1 {
25941 PARTITION_SPLIT25958 PARTITION_SPLIT
25942 } else {25959 } else {
lanes/mergefix-r2.handoff.mdadded+43 -0
@@ -0,0 +1,43 @@
1+# lane-mergefix r2 handoff
2+
3+Tip: lane-mergefix, commit "var-tx above/left txfm contexts were never reset at a tile
4+boundary". Read `lanes/mergefix-r2.report.md` first -- it has the full ladder.
5+
6+## Fixed this round (do not re-hunt)
7+`Neighbours::start_tile` now resets `above_txfm` over the tile's column span and
8+`Neighbours::start_row` resets `left_txfm`, both to `TXFM_CTX_INIT` (64). All 14
9+`txfm_partition` symbols of the pinned stream now match the instrumented oracle in ctx and
10+range. Oracle instrumentation: `EC_VARTX=1` on `~/.cache/mergefix-tmp/aom-build/aomdec`
11+(additive fprintf in `read_tx_size_vartx`, shared oracle build untouched).
12+
13+## The remaining defect (gate still RED, 3622 px, first at frame 1 row 0 col 64)
14+
15+Stream `~/.cache/mergefix-tmp/str61.obu` (md5 a14892ed0ba88b6ad2b566e251ea2d33,
16+`~/.cache/mergefix-tmp/mkstr.sh`), 192x68 cq61 tile_cols=1, frame 1.
17+
18+FIRST DIVERGING SYMBOL: the 64x64 partition of superblock mi(16,32) (last SB row, only 1 mi
19+row inside the frame; second tile column). Both decoders enter at rng=51641.
20+
21+ aomdec: EC_PART mi_row=16 mi_col=32 bsize=12 ctx=13 rng=51641 -> value=3 (SPLIT), rng 38495
22+ ours : EC_PARTG mi_row=16 mi_col=32 bsize=12 ctx=0 rng=51641 -> gathered bit 0 -> HORZ
23+
24+aomdec's ctx is printed as `bsl*4 + ctx` => its real ctx is 1 (above=1, left=0); ours is 0.
25+`Neighbours::partition_ctx_mi` (decode.rs ~4985) reads `above_side_mi[mi_c] * 2 <= side`, so
26+`above_side_mi[32]` is 64 in ours and must be 32: the block above is the 32x64 strip of the
27+SB-level PARTITION_VERT at mi(0,32). Find the SB-level (64x64) PARTITION_VERT arm of the
28+INTER tile path and make its two 32x64 strips record their own width/height into
29+`above_side_mi`/`left_side_mi` (`record_rect_mi`, w=32 h=64), not the parent's 64.
30+The 32-level and 16-level gathered reads at that SB already have the right ctx (0/0).
31+
32+Reproduce the ladder:
33+ ours : `EC_TRACE_PART=1 EC_TRACE_MODE=1 <target>/debug/examples/decode_probe str61.obu`
34+ aom : `EC_TRACE_MODE=1 EC_TRACE_COEFF=1 EC_VARTX=1 ~/.cache/mergefix-tmp/aom-build/aomdec --rawvideo -o /dev/null str61.obu`
35+
36+Also open (class `equal-range-means-unread`, may be the same defect): after the fix ours
37+reads ONE txfm_partition symbol the oracle never reads --
38+`EC_ISTEP mi_row=16 mi_col=36 name=txfm_split_rect val=0 ctx=12 rng=37790` -- at the same
39+bottom-edge SB row. Expect it to disappear once the partition above is right.
40+
41+Sibling gates NOT re-run: split-transform gate, sb128c intra_rect_block +
42+gathered_edge_horz, uv8/intersub8/inter16ab/rectchroma2. Run them in ONE
43+`cargo test -p ec-av1 --lib -- <names>` before merging.
lanes/mergefix-r2.report.mdadded+79 -0
@@ -0,0 +1,79 @@
1+# lane-mergefix r2 report
2+
3+## Root cause found and fixed: the var-tx neighbour contexts were never reset at a tile boundary
4+
5+Instrumented the oracle: added an `EC_VARTX`-gated `fprintf` in libaom
6+`read_tx_size_vartx` (`av1/decoder/decodeframe.c`, right after the
7+`txfm_partition_cdf[ctx]` read) printing `mi_row/mi_col/bsize/depth/blk_row/blk_col/
8+tx_size/ctx/above/left/val/rng`. Built into a PRIVATE tree
9+(`~/.cache/mergefix-tmp/aom-build`, cmake + ninja, `CONFIG_AV1_ENCODER=0`); the shared
10+`~/.cache/aom-oracle/build` was not touched. The edit in the oracle source is additive and
11+env-gated, so no other lane's trace changes.
12+
13+Ladder at the r1 first-divergence element (frame 1, mi(0,32), 32x64 VERT inter strip):
14+
15+ aomdec: depth0 tx=TX_32X64 ctx=0 above=64 left=64 val=1 rng=48128
16+ depth1 tx=TX_32X32 ctx=3 above=64 left=64 val=1 rng=49648
17+ depth1 blk_row=8 ctx=4 above=16 left=64 val=1 rng=43818
18+ ours : ctx=1 rng=51444 / ctx=4 rng=45408 / ctx=4 rng=43372 (BEFORE)
19+
20+`ctx` is off by exactly the `left` term while `above` agrees: our `left_txfm` at mi row 0
21+still held `16`, written by the block at mi(0,24) -- which lives in the PREVIOUS TILE COLUMN
22+(the stream is `--tile-columns=1`, i.e. 2 tile columns, boundary at mi_col 32).
23+
24+libaom resets both bands and we reset neither:
25+- `av1_zero_left_context` memsets `left_txfm_context_buffer` to
26+ `tx_size_high[TX_SIZES_LARGEST]` (64) at every superblock row of every tile
27+ (`decodeframe.c:2796` / `:3238`, inside the per-tile `mi_row` loop).
28+- `av1_zero_above_context` memsets `above_contexts.txfm[tile_row] + mi_col_start` to
29+ `tx_size_wide[TX_SIZES_LARGEST]` over the tile's own column span (`:2789` / `:3231`).
30+
31+### Hunks (by function name, for porting onto main) -- `crates/ec-av1/src/decode.rs`
32+
33+- `Neighbours::start_tile` (end of the function, after the `sub8_mode_col`/`uv_mode_col`
34+ loop): reset `self.above_txfm[i] = TXFM_CTX_INIT` over `col0_mi..col1_mi` (clamped).
35+- `Neighbours::start_row` (end of the function, after the palette bands):
36+ `self.left_txfm.iter_mut().for_each(|t| *t = TXFM_CTX_INIT);`
37+- (diagnostic, env-gated, keep or drop) `EC_PARTG` eprintln in the three gathered
38+ edge-partition branches of the inter tile path (64/32/16), printing `ctx` + `rng`.
39+
40+Class: `new-map-ignores-tile-edge` -- COMMON's NEIGHBOUR MAPS rule ("reset in start_tile AND
41+start_row") had never been applied to the two txfm bands.
42+
43+EVIDENCE: ~/.cache/mergefix-tmp/vartx.log + o.vartx | instrumented aomdec EC_VARTX vs our
44+EC_TRACE_MODE_STEP name=txfm_split on the pinned 192x68 cq61 tile_cols=1 stream (md5
45+a14892ed0ba88b6ad2b566e251ea2d33) | all 14 txfm_partition symbols now agree in ctx AND range
46+(48128/49648/43818), 0 of 14 before at mi(0,32)
47+
48+EVIDENCE: gate output | `cargo test -p ec-av1 --lib -- a_frame_edge_straddling_band_decodes_pixel_exact`
49+| frame 1 plane Y differing pixels 6859 -> 3622 (still RED, second defect below)
50+
51+## Still RED: `a_frame_edge_straddling_band_decodes_pixel_exact`
52+
53+A SECOND, independent defect owns the residue. Full cross-decoder range ladder
54+(EC_MODE/EC_ISTEP/EC_COEFF_STEP, `tag=br|sign|golomb|tx_type` and the two decoders'
55+differently-named var-tx lines dropped) is element-identical until the LAST superblock row
56+of frame 1 in the SECOND tile column: SB mi(16,32), where only 1 of 16 mi rows is inside the
57+frame (`mi_rows == 17`).
58+
59+ aomdec: EC_PART bsize=12 ctx=13 rng=51641 -> SPLIT
60+ EC_PART bsize=9 ctx=8 rng=38495 -> SPLIT
61+ EC_PART bsize=6 ctx=4 rng=45016 -> SPLIT
62+ EC_PART bsize=3 ctx=0 rng=51116 -> NONE (8x8 inter leaves)
63+ ours : EC_PARTG bsize=12 ctx=0 rng=51641 -> (gathered bit 0) HORZ
64+ ... a 16x16-wide block at mi(16,32), EC_MODE rng=40004 vs aomdec 42754
65+
66+aomdec's ctx print is `bsl * 4 + ctx`, so its 64-level ctx is 1 (above=1, left=0) and ours
67+is 0. `Neighbours::partition_ctx_mi` computes `above = above_side_mi[mi_c] * 2 <= side`, so
68+ours says the block above is 64 wide -- but the block above IS the 32x64 VERT strip at
69+mi(0,32). The SB-level PARTITION_VERT inter strip publishes the PARENT's 64 into
70+`above_side_mi` instead of its own 32 (class `tx-grid-published-block-side`). The 32-level
71+and 16-level ctx (0/0) already agree with aomdec, so this is a single-site defect.
72+
73+fix-now (handed off): see `lanes/mergefix-r2.handoff.md`.
74+
75+## Test totals
76+Not run to completion this round (hard 50-minute deadline). The one gate above was run by
77+name. Sibling gates (split-transform, sb128c intra_rect_block/gathered_edge_horz,
78+uv8/intersub8/inter16ab/rectchroma2) are NOT yet re-run --
79+deferred(one `cargo test -p ec-av1 --lib` invocation with those names).