forge
Explore
Log in

Don't you dare go Hollow

The var-tx above/left txfm contexts were never reset at a tile boundary -- libaom re-inits above_txfm per tile (av1_zero_above_context) and left_txfm per superblock row (av1_zero_left_context) to 64, so at the first block of a second tile column our txfm_partition ctx read the previous tile's resolved transform size and picked the wrong CDF row

Browse files at this commit

7bbea7cb0f2edf79406443ce0ddd119db1d16991Ahmet Kaan GümüşParent: 9c6d151
  • fix
    • the var-tx above/left txfm contexts were never reset at a tile boundary -- libaom re-inits above_txfm per tile (av1_zero_above_context) and left_txfm per superblock row (av1_zero_left_context) to 64, so at the first block of a second tile column our txfm_partition ctx read the previous tile's resolved transform size and picked the wrong CDF row
    • all 14 txfm_partition symbols of the 192x68 8-bit 2-tile-column gate stream now match the instrumented oracle in ctx and range, edge-straddling gate 6859 -> 3622 differing pixels (second defect open, see lanes/mergefix-r2.handoff.md)
Show full message
fix(av1): the var-tx above/left txfm contexts were never reset at a tile boundary -- libaom re-inits above_txfm per tile (av1_zero_above_context) and left_txfm per superblock row (av1_zero_left_context) to 64, so at the first block of a second tile column our txfm_partition ctx read the previous tile's resolved transform size and picked the wrong CDF row; all 14 txfm_partition symbols of the 192x68 8-bit 2-tile-column gate stream now match the instrumented oracle in ctx and range, edge-straddling gate 6859 -> 3622 differing pixels (second defect open, see lanes/mergefix-r2.handoff.md)
crates/ec-av1/src/decode.rsmodified+17 -0
@@ -4373,6 +4373,14 @@ impl Neighbours {
4373 self.sub8_mode_col[i] = (usize::MAX, 0);4373 self.sub8_mode_col[i] = (usize::MAX, 0);
4374 self.uv_mode_col[i] = (usize::MAX, 0);4374 self.uv_mode_col[i] = (usize::MAX, 0);
4375 }4375 }
4376+ // lane-mergefix r2: `av1_zero_above_context` also memsets the txfm row
4377+ // over the tile's own column span (to `tx_size_wide[TX_SIZES_LARGEST]`,
4378+ // not zero) -- without it a second tile column reads the first one's
4379+ // resolved transform sizes as its own above context.
4380+ let tend = col1_mi.min(self.above_txfm.len());
4381+ for i in col0_mi.min(tend)..tend {
4382+ self.above_txfm[i] = TXFM_CTX_INIT;
4383+ }
4376 }4384 }
4377 4385
4378 /// Writes a just-decoded block's own palette-Y size/colours (`size == 0`4386 /// Writes a just-decoded block's own palette-Y size/colours (`size == 0`
@@ -4785,6 +4793,12 @@ impl Neighbours {
4785 self.left_palette_colors.iter_mut().for_each(|c| *c = [0u16; 8]);4793 self.left_palette_colors.iter_mut().for_each(|c| *c = [0u16; 8]);
4786 self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0);4794 self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0);
4787 self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]);4795 self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]);
4796+ // lane-mergefix r2: `av1_zero_left_context` memsets
4797+ // `left_txfm_context_buffer` to `tx_size_high[TX_SIZES_LARGEST]` at
4798+ // every superblock row of every tile -- the var-tx left context does
4799+ // NOT carry over a tile boundary (its `txfm_partition` ctx read the
4800+ // previous tile column's last block otherwise).
4801+ self.left_txfm.iter_mut().for_each(|t| *t = TXFM_CTX_INIT);
4788 }4802 }
4789 4803
4790 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next4804 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next
@@ -24336,6 +24350,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
24336 // lane-golomb r1 (class `parsed-then-discarded`): the gathered24350 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
24337 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT24351 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
24338 // (libaom `ec_read_partition_impl`).24352 // (libaom `ec_read_partition_impl`).
24353+ 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); }
24339 if bump_edge32_bit(24354 if bump_edge32_bit(
24340 4,24355 4,
24341 dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)),24356 dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)),
@@ -24528,6 +24543,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
24528 // lane-golomb r1 (class `parsed-then-discarded`): the gathered24543 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
24529 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT24544 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
24530 // (libaom `ec_read_partition_impl`).24545 // (libaom `ec_read_partition_impl`).
24546+ 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); }
24531 if {24547 if {
24532 let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE));24548 let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE));
24533 bump_edge32(b.min(1) as usize);24549 bump_edge32(b.min(1) as usize);
@@ -24649,6 +24665,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
24649 // lane-golomb r1 (class `parsed-then-discarded`): the gathered24665 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
24650 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT24666 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
24651 // (libaom `ec_read_partition_impl`).24667 // (libaom `ec_read_partition_impl`).
24668+ 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); }
24652 if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], VERT_ALIKE)) == 1 {24669 if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], VERT_ALIKE)) == 1 {
24653 PARTITION_SPLIT24670 PARTITION_SPLIT
24654 } else {24671 } 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).