diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 80a9f142..9861b400 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2338,6 +2338,21 @@ pub(crate) fn obmc_pair_filter_hits() -> usize { OBMC_PAIR_FILTER_HITS.with(|c| c.get()) } +// lane-t900 r14: how many OBMC neighbour predictions run PAST the frame edge +// -- libaom's `op_mi_size` is `AOMMIN(xd->width|height, mi_step)`, the block's +// own side, so a block overhanging the bottom/right still predicts the full +// neighbour strip (the destination write is what clips). We used to shrink the +// prediction to the visible part, which at 4 chroma rows/cols also swaps the +// vertical/horizontal kernel to the 4-tap one. The gate's proof the shape fired. +thread_local! { + static OBMC_EDGE_SPAN_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`OBMC_EDGE_SPAN_HITS`]. +pub(crate) fn obmc_edge_span_hits() -> usize { + OBMC_EDGE_SPAN_HITS.with(|c| c.get()) +} + /// Current value of [`OBMC_HITS_8`]. pub(crate) fn obmc_hits_8() -> usize { OBMC_HITS_8.with(|c| c.get()) @@ -18843,7 +18858,13 @@ fn overlappable_above( if src != col { OBMC_PAIR_FILTER_HITS.with(|c| c.set(c.get() + 1)); } - out.push((col - mi_col, step.min(end_col - col), *info, src - mi_col)); + // lane-t900 r14: libaom passes `AOMMIN(xd->width, mi_step)` + // as `op_mi_size` -- the block's OWN width, never the + // frame-edge clamp `end_col` carries. Clamping here shrank the + // neighbour PREDICTION at a frame edge, which picks the + // 4-tap kernel below 8 px (class narrow-block-sharp-kernel); + // the destination clip stays in `obmc_blend`. + out.push((col - mi_col, step.min(bw4), *info, src - mi_col)); } } col += step; @@ -18889,7 +18910,9 @@ fn overlappable_left( if src != row { OBMC_PAIR_FILTER_HITS.with(|c| c.set(c.get() + 1)); } - out.push((row - mi_row, step.min(end_row - row), *info, src - mi_row)); + // lane-t900 r14: `AOMMIN(xd->height, mi_step)` -- see + // `overlappable_above`. + out.push((row - mi_row, step.min(bh4), *info, src - mi_row)); } } row += step; @@ -19355,13 +19378,17 @@ fn interintra_blend( } } -fn obmc_blend_v(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u16]) { +/// `w` is the number of columns actually written (clipped to the block's own +/// buffer at a frame edge); `ts` is `tmp`'s own stride, the neighbour +/// prediction's full width. +#[allow(clippy::too_many_arguments)] +fn obmc_blend_v(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, ts: usize, tmp: &[u16]) { let mask = obmc_mask(h); for row in 0..h { let m = u32::from(mask[row]); for col in 0..w { let d = &mut dst[(oy + row) * stride + ox + col]; - let t = u32::from(tmp[row * w + col]); + let t = u32::from(tmp[row * ts + col]); *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u16; } } @@ -19585,9 +19612,14 @@ fn obmc_blend( ec_obmc_trace("above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind); let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; let nb_scale = mc::scale_factor(ny.width, frame_width); + if mi_col + off4 + span4 > mi_cols { + OBMC_EDGE_SPAN_HITS.with(|c| c.set(c.get() + 1)); + } let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4); + // lane-t900 r14: the prediction is `op_mi_size` wide (kernel choice + // included); only the WRITE is clipped to this block's own buffer. let tmp_y = obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, h_kind, v_kind, nb_scale); - obmc_blend_v(pred_y, side, ox, 0, bw, bh, &tmp_y); + obmc_blend_v(pred_y, side, ox, 0, bw.min(write_w - ox), bh, bw, &tmp_y); if !skip_chroma_above { // lane-t900 r13 (measured, NOT a defect): libaom's min-4 clamp // (`dec_build_prediction_by_above_pred`) sizes only the OBMC @@ -19597,10 +19629,11 @@ fn obmc_blend( // 1920x792 cut that went 36 differing frames -> 266, worst // 13 B -> 11007 B. let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2); + let cw = cbw.min(write_w / 2 - cox); let tmp_u = obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale); - obmc_blend_v(pred_u, chroma_side, cox, 0, cbw, cbh, &tmp_u); + obmc_blend_v(pred_u, chroma_side, cox, 0, cw, cbh, cbw, &tmp_u); let tmp_v = obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale); - obmc_blend_v(pred_v, chroma_side, cox, 0, cbw, cbh, &tmp_v); + obmc_blend_v(pred_v, chroma_side, cox, 0, cw, cbh, cbw, &tmp_v); } } @@ -19615,14 +19648,28 @@ fn obmc_blend( ec_obmc_trace("left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind); let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; let nb_scale = mc::scale_factor(ny.width, frame_width); + if mi_row + off4 + span4 > mi_rows { + OBMC_EDGE_SPAN_HITS.with(|c| c.set(c.get() + 1)); + } let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4); let tmp_y = obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, h_kind, v_kind, nb_scale); - obmc_blend_h(pred_y, side, 0, oy, bw, bh, &tmp_y); + obmc_blend_h(pred_y, side, 0, oy, bw, bh.min(write_h - oy), &tmp_y); let (cbw, cbh, coy) = (overlap_left / 2, bh / 2, oy / 2); let tmp_u = obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale); - obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, cbh, &tmp_u); + if let Some((_, _, idx)) = ec_mcb { + eprintln!( + "OUR_MCB left f={idx} off4={off4} span4={span4} cbw={cbw} cbh={cbh} coy={coy} mv=({},{}) ref0={}", + nb.mv.0, nb.mv.1, nb.ref_frame + ); + for r in 0..cbh { + let row: Vec = (0..cbw).map(|c| tmp_u[r * cbw + c]).collect(); + eprintln!("OUR_MCB lrow{r}: {row:?}"); + } + } + let ch = cbh.min(write_h / 2 - coy); + obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, ch, &tmp_u); let tmp_v = obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale); - obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, cbh, &tmp_v); + obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, ch, &tmp_v); } if let Some((_, _, idx)) = ec_mcb { for r in 0..write_h / 2 { diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index aa935653..9d1c0b80 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -30472,10 +30472,15 @@ mod tests { // lane-t900 r10: the rect warp top-right reach (600 blocks here). let tr_before = crate::decode::tr_reach_longer_side_hits(); let i16_before = crate::decode::intra16x4_in_inter_hits(); + // lane-t900 r14: OBMC neighbour strips that run past the frame edge + // (792 luma rows = 198 mi rows, so every bottom-row 32x32 block + // overhangs) -- the shape whose prediction size used to be clamped. + let edge_before = crate::decode::obmc_edge_span_hits(); let frames = match decode_stream(&stream) { Ok(frames) => frames, Err(e) => panic!("{NAME}: decode_stream refused: {e}"), }; + let obmc_edge_span = crate::decode::obmc_edge_span_hits() - edge_before; let fired = ( crate::decode::warp_plane_suppress_hits() - before.0, crate::decode::cdef_idx_hits() - before.1, @@ -30508,6 +30513,7 @@ mod tests { ("sub8_chroma_tx_from_ref", sub8tx), ("inter_neighbour_not_smooth", notsmooth), ("tr_reach_longer_side", tr), + ("obmc_edge_span", obmc_edge_span), ] { assert!( n > 0, @@ -30534,7 +30540,7 @@ mod tests { cdef_idx={} inter_sb128_vert={} interintra_rect={} non_chroma_ref_ctx_skip={} \ intra_in_inter_txctx={} edge_filter_mi_fix={} intra16x4_in_inter={:?} \ sub8_chroma_tx_from_ref={sub8tx} inter_neighbour_not_smooth={notsmooth} \ - tr_reach_longer_side={tr}", + tr_reach_longer_side={tr} obmc_edge_span={obmc_edge_span}", fired.0, fired.1, fired.2, fired.3, fired.4, fired.5, fired.6, i16 ); } diff --git a/lanes/t900-r14.handoff.md b/lanes/t900-r14.handoff.md new file mode 100644 index 00000000..ea36e4a6 --- /dev/null +++ b/lanes/t900-r14.handoff.md @@ -0,0 +1,35 @@ +# lane-t900 r14 handoff -- 1080p is clean; next frontier is 4K + +Tip `78347fca` on `lane-t900` (base main `a870796b`, merged fast-forward at round start). +Report: `lanes/t900-r14.report.md`. + +## Closed this round (do not re-measure) + +* Root cause: OBMC neighbour `op_mi_size` is `AOMMIN(xd->width|height, mi_step)` + (`obmc.h:52,83`), never the `end_col`/`end_row` frame-edge clamp. Our clamp shrank the + neighbour PREDICTION, which at 4 chroma rows also flipped `mc.rs:418` to the 4-tap + kernel -> 1-off on the last valid chroma row. Fixed in `a6c408b7`; witness counter + `obmc_edge_span_hits` asserted (33 hits) on the 128-SB inter gate in `52a11095`. +* Every 1080p offset probed is byte-exact: head 0-10 s (241 f), 300/900/1200/1800/2100/ + 3000/3900/4800/5400/5700/6300/6600/7500/8100/8400/9300/9900/10200 s. Compare script + `~/.cache/t900-tmp/cmp13.sh `; sweep driver `~/.cache/t900-tmp/sweep14.sh`, + log `~/.cache/t900-tmp/sweep14.log`. +* 4K re-check: `h2700.obu` 107 frames and `h1500.obu` 244 frames, 0 differing. +* Suites (both green, no FAILED): r14 fix 429 passed/0 failed/38 ignored in 861.07s + (`$HOME/.cache/t900-suite-r14.log`); final tip 429/0/38 in 820.42s + (`$HOME/.cache/t900-suite-r14b.log`). + +## Owed + +* The 4K census8 offsets that were not exact before this round (24 of them, `run8.sh`) + were NOT re-swept -- two spot cuts are exact, the rest is unmeasured. Start there: + retarget `run8.sh`'s `PROBE` to `$HOME/.cache/cargo-target-t900b/release/examples/ + decode_probe` and run the 4K offsets, then ladder the first bad frame with + `EC_AV1_FINAL_DUMP` + `EC_MCB`/`EC_OBMC`/`EC_PRED` as in r13/r14. + +## Rungs (all additive, env-gated, on both decoders) + +`EC_MCB="::[:]"` -- aomdec prints every +`dec_build_inter_predictors` call covering that pixel (obmc=1 tmp buffers included); +ours prints the block's chroma rows pre/post blend AND, new in r14, each LEFT-pass +neighbour's tmp rows with `off4/span4/cbw/cbh/coy/mv/ref0`. diff --git a/lanes/t900-r14.report.md b/lanes/t900-r14.report.md new file mode 100644 index 00000000..37e2bc67 --- /dev/null +++ b/lanes/t900-r14.report.md @@ -0,0 +1,98 @@ +# lane-t900 r14 report -- the last 1080p residue class: OBMC neighbour prediction size + +Branch `lane-t900`, base `a870796b` (main, merged fast-forward at round start). + +## Root cause (one, all of TARGET A) + +`overlappable_above` / `overlappable_left` (`crates/ec-av1/src/decode.rs`) clamped the +neighbour span to `end_col`/`end_row`, i.e. to `mi_cols`/`mi_rows`. libaom's +`foreach_overlappable_nb_above`/`_left` (`av1/common/obmc.h:52,83`) pass +`op_mi_size = AOMMIN(xd->width|height, mi_step)` -- the block's OWN side, never the +frame-edge clamp; `end_col`/`end_row` bound only the WALK. `build_obmc_inter_pred_*` +(`reconinter.c:891`) then predicts a strip `op_mi_size * MI_SIZE >> ss` tall/wide, and +the destination write runs off into the frame buffer's own padding. + +Because our span shrank at the frame edge, the neighbour PREDICTION shrank with it, and +at 4 chroma rows `mc::predict_with_filters` picks the 4-tap narrow vertical kernel +(`mc.rs:418`, class `narrow-block-sharp-kernel`) where libaom used the 8-tap one. +Result: a 1-off on the last valid chroma row of the OBMC blend -- 1-13 B on 36 of 267 +frames of the 900 s 1080p cut and similar counts on every other 1080p cut. + +Fix (`a6c408b7`): span is `step.min(bw4)` / `step.min(bh4)`; the prediction is built at +that full size (kernel choice included) and only the WRITE into this block's own +prediction buffer is clipped (`obmc_blend_v` gained the tmp stride, `obmc_blend_h` +takes the clipped row count). + +Witness (`52a11095`): `obmc_edge_span_hits` counts neighbour strips running past +`mi_rows`/`mi_cols`; the 128-SB inter witness gate hard-asserts it (fires 33x). + +## Ladder that produced it (one run each, both decoders) + +* aomdec `EC_MCB=1:353:395:41` on `c900_62.obu`: base pred (obmc=0) 16 rows identical to + ours; ONE `obmc=1` left-neighbour entry covers row 11, `mi_y=784 bw=8 bh=8`, its + row3 = `494 491 490 491 494 492 488 486`. +* ours (`OUR_MCB left`, new tmp dump): same neighbour, `cbh=4` (not 8), row3 + `494 492 490 491 ...` -- col 1 is 492 vs libaom's 491. +* Blend arithmetic confirms the sign: `obmc_mask_8[1] = 42`, + `(42*493 + 22*491 + 32) >> 6 = 492` (aom) vs `(42*493 + 22*492 + 32) >> 6 = 493` (ours). + +## 1080p table (10-bit 1920x792, `cmp13.sh`, aomdec `EC_AV1_FINAL_DUMP` vs ours, all planes) + +| stream | frames | differing | before r14 | +|---|---|---|---| +| head 0-10 s | 241 | 0 | 78 differing (r11) | +| 300 s | 186 | 0 | - | +| 900 s (cut_900) | 267 | 0 | 36 differing, first f41, worst 13 B | +| 1200 s | 199 | 0 | - | +| 1800 s | 193 | 0 | 26 B on f1 (charter) | +| 2100 s | 169 | 0 | - | +| 3000 s | 135 | 0 | - | +| 3900 s | 291 | 0 | - | +| 4800 s | 89 | 0 | - | +| 5400 s | 275 | 0 | 5 differing | +| 5700 s | 134 | 0 | - | +| 6300 s | 125 | 0 | differing | +| 6600 s | 110 | 0 | - | +| 7500 s | 89 | 0 | - | +| 8100 s | 96 | 0 | differing | +| 8400 s | 135 | 0 | - | +| 9300 s | 81 | 0 | - | +| 9900 s | 176 | 0 | charter target | +| 10200 s | 144 | 0 | - | + +Every 1080p offset probed this round is byte-exact on every plane. No 1080p residue left +in this lane's reach. + +## 4K regression check (no 1080p-only fix regressed the 4K path) + +| stream | frames | differing | +|---|---|---| +| 3840x1608 10-bit, 2700 s cut (`h2700.obu`) | 107 | 0 | +| 3840x1608 10-bit, 1500 s cut (`h1500.obu`) | 244 | 0 | + +## Gates / suite + +* `a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_decode_pixel_exact`: + `EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-t900b + cargo test -p ec-av1 --lib -j3 a_10bit_128sb_film_frames_with_warp_cdef_and_interintra -- --nocapture` + -> `ok. 1 passed`, counters `... tr_reach_longer_side=600 obmc_edge_span=33`. +* Full suite (r14 fix, unit `t900-suite-r14-1788394487`): + `test result: ok. 429 passed; 0 failed; 38 ignored; 0 measured; 0 filtered out; + finished in 861.07s` -- `$HOME/.cache/t900-suite-r14.log`. +* Full suite on the FINAL tip (unit `t900-suite-r14b-1788395402`, log + `$HOME/.cache/t900-suite-r14b.log`): `test result: ok. 429 passed; 0 failed; 38 ignored; + 0 measured; 0 filtered out; finished in 820.42s`. + +## EVIDENCE + +EVIDENCE: ~/.cache/t900-tmp/aom_mcb41b.txt + ~/.cache/t900-tmp/our_mcb41.txt | aomdec and ours with EC_MCB=1:353:395:41 on c900_62.obu | left-neighbour tmp row3 col1 = 491 (aom, bh=8) vs 492 (ours, cbh=4) -> post-blend U(353,395) 492 vs 493 +EVIDENCE: ~/.cache/t900-tmp/d_cut900_r14/ | cmp13.sh cut900_r14 cut_900.obu (aomdec EC_AV1_FINAL_DUMP vs our decode_probe, all planes) | frames=267 differing=0 (was 36 differing, worst 13 B) +EVIDENCE: ~/.cache/t900-tmp/sweep14.log | 12 x 2 s 1080p cuts (300..10200 s) + 2 4K cuts, same compare | every offset differing=0 +EVIDENCE: $HOME/.cache/t900-suite-r14.log | full ec-av1 lib suite as a systemd unit | 429 passed; 0 failed; 38 ignored + +## Residue + +* 4K census8's remaining not-exact offsets: not swept this round -- deferred(a 4K census + run costs ~20 min per offset pair on this box while a suite runs); the two 4K cuts I did + re-probe are exact. +* No 1080p residue known: fix-now list empty for this lane's 1080p target.