diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 4b5d999b..94d57b41 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -4614,6 +4614,14 @@ impl Neighbours { self.sub8_mode_col[i] = (usize::MAX, 0); self.uv_mode_col[i] = (usize::MAX, 0); } + // lane-mergefix r2: `av1_zero_above_context` also memsets the txfm row + // over the tile's own column span (to `tx_size_wide[TX_SIZES_LARGEST]`, + // not zero) -- without it a second tile column reads the first one's + // resolved transform sizes as its own above context. + let tend = col1_mi.min(self.above_txfm.len()); + for i in col0_mi.min(tend)..tend { + self.above_txfm[i] = TXFM_CTX_INIT; + } } /// Writes a just-decoded block's own palette-Y size/colours (`size == 0` @@ -5041,6 +5049,12 @@ impl Neighbours { self.left_palette_colors.iter_mut().for_each(|c| *c = [0u16; 8]); self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0); self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]); + // lane-mergefix r2: `av1_zero_left_context` memsets + // `left_txfm_context_buffer` to `tx_size_high[TX_SIZES_LARGEST]` at + // every superblock row of every tile -- the var-tx left context does + // NOT carry over a tile boundary (its `txfm_partition` ctx read the + // previous tile column's last block otherwise). + self.left_txfm.iter_mut().for_each(|t| *t = TXFM_CTX_INIT); } /// 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( // lane-golomb r1 (class `parsed-then-discarded`): the gathered // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT // (libaom `ec_read_partition_impl`). + 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); } if bump_edge32_bit( 4, dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)), @@ -25812,6 +25827,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // lane-golomb r1 (class `parsed-then-discarded`): the gathered // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT // (libaom `ec_read_partition_impl`). + 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); } if { let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)); bump_edge32(b.min(1) as usize); @@ -25937,6 +25953,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // lane-golomb r1 (class `parsed-then-discarded`): the gathered // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT // (libaom `ec_read_partition_impl`). + 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); } if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], VERT_ALIKE)) == 1 { PARTITION_SPLIT } else { diff --git a/lanes/mergefix-r2.handoff.md b/lanes/mergefix-r2.handoff.md new file mode 100644 index 00000000..1cb70346 --- /dev/null +++ b/lanes/mergefix-r2.handoff.md @@ -0,0 +1,43 @@ +# lane-mergefix r2 handoff + +Tip: lane-mergefix, commit "var-tx above/left txfm contexts were never reset at a tile +boundary". Read `lanes/mergefix-r2.report.md` first -- it has the full ladder. + +## Fixed this round (do not re-hunt) +`Neighbours::start_tile` now resets `above_txfm` over the tile's column span and +`Neighbours::start_row` resets `left_txfm`, both to `TXFM_CTX_INIT` (64). All 14 +`txfm_partition` symbols of the pinned stream now match the instrumented oracle in ctx and +range. Oracle instrumentation: `EC_VARTX=1` on `~/.cache/mergefix-tmp/aom-build/aomdec` +(additive fprintf in `read_tx_size_vartx`, shared oracle build untouched). + +## The remaining defect (gate still RED, 3622 px, first at frame 1 row 0 col 64) + +Stream `~/.cache/mergefix-tmp/str61.obu` (md5 a14892ed0ba88b6ad2b566e251ea2d33, +`~/.cache/mergefix-tmp/mkstr.sh`), 192x68 cq61 tile_cols=1, frame 1. + +FIRST DIVERGING SYMBOL: the 64x64 partition of superblock mi(16,32) (last SB row, only 1 mi +row inside the frame; second tile column). Both decoders enter at rng=51641. + + aomdec: EC_PART mi_row=16 mi_col=32 bsize=12 ctx=13 rng=51641 -> value=3 (SPLIT), rng 38495 + ours : EC_PARTG mi_row=16 mi_col=32 bsize=12 ctx=0 rng=51641 -> gathered bit 0 -> HORZ + +aomdec's ctx is printed as `bsl*4 + ctx` => its real ctx is 1 (above=1, left=0); ours is 0. +`Neighbours::partition_ctx_mi` (decode.rs ~4985) reads `above_side_mi[mi_c] * 2 <= side`, so +`above_side_mi[32]` is 64 in ours and must be 32: the block above is the 32x64 strip of the +SB-level PARTITION_VERT at mi(0,32). Find the SB-level (64x64) PARTITION_VERT arm of the +INTER tile path and make its two 32x64 strips record their own width/height into +`above_side_mi`/`left_side_mi` (`record_rect_mi`, w=32 h=64), not the parent's 64. +The 32-level and 16-level gathered reads at that SB already have the right ctx (0/0). + +Reproduce the ladder: + ours : `EC_TRACE_PART=1 EC_TRACE_MODE=1 /debug/examples/decode_probe str61.obu` + aom : `EC_TRACE_MODE=1 EC_TRACE_COEFF=1 EC_VARTX=1 ~/.cache/mergefix-tmp/aom-build/aomdec --rawvideo -o /dev/null str61.obu` + +Also open (class `equal-range-means-unread`, may be the same defect): after the fix ours +reads ONE txfm_partition symbol the oracle never reads -- +`EC_ISTEP mi_row=16 mi_col=36 name=txfm_split_rect val=0 ctx=12 rng=37790` -- at the same +bottom-edge SB row. Expect it to disappear once the partition above is right. + +Sibling gates NOT re-run: split-transform gate, sb128c intra_rect_block + +gathered_edge_horz, uv8/intersub8/inter16ab/rectchroma2. Run them in ONE +`cargo test -p ec-av1 --lib -- ` before merging. diff --git a/lanes/mergefix-r2.report.md b/lanes/mergefix-r2.report.md new file mode 100644 index 00000000..7c909403 --- /dev/null +++ b/lanes/mergefix-r2.report.md @@ -0,0 +1,79 @@ +# lane-mergefix r2 report + +## Root cause found and fixed: the var-tx neighbour contexts were never reset at a tile boundary + +Instrumented the oracle: added an `EC_VARTX`-gated `fprintf` in libaom +`read_tx_size_vartx` (`av1/decoder/decodeframe.c`, right after the +`txfm_partition_cdf[ctx]` read) printing `mi_row/mi_col/bsize/depth/blk_row/blk_col/ +tx_size/ctx/above/left/val/rng`. Built into a PRIVATE tree +(`~/.cache/mergefix-tmp/aom-build`, cmake + ninja, `CONFIG_AV1_ENCODER=0`); the shared +`~/.cache/aom-oracle/build` was not touched. The edit in the oracle source is additive and +env-gated, so no other lane's trace changes. + +Ladder at the r1 first-divergence element (frame 1, mi(0,32), 32x64 VERT inter strip): + + aomdec: depth0 tx=TX_32X64 ctx=0 above=64 left=64 val=1 rng=48128 + depth1 tx=TX_32X32 ctx=3 above=64 left=64 val=1 rng=49648 + depth1 blk_row=8 ctx=4 above=16 left=64 val=1 rng=43818 + ours : ctx=1 rng=51444 / ctx=4 rng=45408 / ctx=4 rng=43372 (BEFORE) + +`ctx` is off by exactly the `left` term while `above` agrees: our `left_txfm` at mi row 0 +still held `16`, written by the block at mi(0,24) -- which lives in the PREVIOUS TILE COLUMN +(the stream is `--tile-columns=1`, i.e. 2 tile columns, boundary at mi_col 32). + +libaom resets both bands and we reset neither: +- `av1_zero_left_context` memsets `left_txfm_context_buffer` to + `tx_size_high[TX_SIZES_LARGEST]` (64) at every superblock row of every tile + (`decodeframe.c:2796` / `:3238`, inside the per-tile `mi_row` loop). +- `av1_zero_above_context` memsets `above_contexts.txfm[tile_row] + mi_col_start` to + `tx_size_wide[TX_SIZES_LARGEST]` over the tile's own column span (`:2789` / `:3231`). + +### Hunks (by function name, for porting onto main) -- `crates/ec-av1/src/decode.rs` + +- `Neighbours::start_tile` (end of the function, after the `sub8_mode_col`/`uv_mode_col` + loop): reset `self.above_txfm[i] = TXFM_CTX_INIT` over `col0_mi..col1_mi` (clamped). +- `Neighbours::start_row` (end of the function, after the palette bands): + `self.left_txfm.iter_mut().for_each(|t| *t = TXFM_CTX_INIT);` +- (diagnostic, env-gated, keep or drop) `EC_PARTG` eprintln in the three gathered + edge-partition branches of the inter tile path (64/32/16), printing `ctx` + `rng`. + +Class: `new-map-ignores-tile-edge` -- COMMON's NEIGHBOUR MAPS rule ("reset in start_tile AND +start_row") had never been applied to the two txfm bands. + +EVIDENCE: ~/.cache/mergefix-tmp/vartx.log + o.vartx | instrumented aomdec EC_VARTX vs our +EC_TRACE_MODE_STEP name=txfm_split on the pinned 192x68 cq61 tile_cols=1 stream (md5 +a14892ed0ba88b6ad2b566e251ea2d33) | all 14 txfm_partition symbols now agree in ctx AND range +(48128/49648/43818), 0 of 14 before at mi(0,32) + +EVIDENCE: gate output | `cargo test -p ec-av1 --lib -- a_frame_edge_straddling_band_decodes_pixel_exact` +| frame 1 plane Y differing pixels 6859 -> 3622 (still RED, second defect below) + +## Still RED: `a_frame_edge_straddling_band_decodes_pixel_exact` + +A SECOND, independent defect owns the residue. Full cross-decoder range ladder +(EC_MODE/EC_ISTEP/EC_COEFF_STEP, `tag=br|sign|golomb|tx_type` and the two decoders' +differently-named var-tx lines dropped) is element-identical until the LAST superblock row +of frame 1 in the SECOND tile column: SB mi(16,32), where only 1 of 16 mi rows is inside the +frame (`mi_rows == 17`). + + aomdec: EC_PART bsize=12 ctx=13 rng=51641 -> SPLIT + EC_PART bsize=9 ctx=8 rng=38495 -> SPLIT + EC_PART bsize=6 ctx=4 rng=45016 -> SPLIT + EC_PART bsize=3 ctx=0 rng=51116 -> NONE (8x8 inter leaves) + ours : EC_PARTG bsize=12 ctx=0 rng=51641 -> (gathered bit 0) HORZ + ... a 16x16-wide block at mi(16,32), EC_MODE rng=40004 vs aomdec 42754 + +aomdec's ctx print is `bsl * 4 + ctx`, so its 64-level ctx is 1 (above=1, left=0) and ours +is 0. `Neighbours::partition_ctx_mi` computes `above = above_side_mi[mi_c] * 2 <= side`, so +ours says the block above is 64 wide -- but the block above IS the 32x64 VERT strip at +mi(0,32). The SB-level PARTITION_VERT inter strip publishes the PARENT's 64 into +`above_side_mi` instead of its own 32 (class `tx-grid-published-block-side`). The 32-level +and 16-level ctx (0/0) already agree with aomdec, so this is a single-site defect. + +fix-now (handed off): see `lanes/mergefix-r2.handoff.md`. + +## Test totals +Not run to completion this round (hard 50-minute deadline). The one gate above was run by +name. Sibling gates (split-transform, sb128c intra_rect_block/gathered_edge_horz, +uv8/intersub8/inter16ab/rectchroma2) are NOT yet re-run -- +deferred(one `cargo test -p ec-av1 --lib` invocation with those names).