forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-t900' (90b9480d): OBMC neighbour span is the block's own side, never clamped at the frame edge; every sampled cut of both 10-bit films decodes byte-exact

Browse files at this commit

8506f63963b7a431bd1852418994b900960bd2afAhmet Kaan GümüşParent: deea6ff7f87c74
crates/ec-av1/src/decode.rsmodified+57 -10
@@ -2338,6 +2338,21 @@ pub(crate) fn obmc_pair_filter_hits() -> usize {
23382338 OBMC_PAIR_FILTER_HITS.with(|c| c.get())
23392339 }
23402340
2341+// lane-t900 r14: how many OBMC neighbour predictions run PAST the frame edge
2342+// -- libaom's `op_mi_size` is `AOMMIN(xd->width|height, mi_step)`, the block's
2343+// own side, so a block overhanging the bottom/right still predicts the full
2344+// neighbour strip (the destination write is what clips). We used to shrink the
2345+// prediction to the visible part, which at 4 chroma rows/cols also swaps the
2346+// vertical/horizontal kernel to the 4-tap one. The gate's proof the shape fired.
2347+thread_local! {
2348+ static OBMC_EDGE_SPAN_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2349+}
2350+
2351+/// Current value of [`OBMC_EDGE_SPAN_HITS`].
2352+pub(crate) fn obmc_edge_span_hits() -> usize {
2353+ OBMC_EDGE_SPAN_HITS.with(|c| c.get())
2354+}
2355+
23412356 /// Current value of [`OBMC_HITS_8`].
23422357 pub(crate) fn obmc_hits_8() -> usize {
23432358 OBMC_HITS_8.with(|c| c.get())
@@ -18843,7 +18858,13 @@ fn overlappable_above(
1884318858 if src != col {
1884418859 OBMC_PAIR_FILTER_HITS.with(|c| c.set(c.get() + 1));
1884518860 }
18846- out.push((col - mi_col, step.min(end_col - col), *info, src - mi_col));
18861+ // lane-t900 r14: libaom passes `AOMMIN(xd->width, mi_step)`
18862+ // as `op_mi_size` -- the block's OWN width, never the
18863+ // frame-edge clamp `end_col` carries. Clamping here shrank the
18864+ // neighbour PREDICTION at a frame edge, which picks the
18865+ // 4-tap kernel below 8 px (class narrow-block-sharp-kernel);
18866+ // the destination clip stays in `obmc_blend`.
18867+ out.push((col - mi_col, step.min(bw4), *info, src - mi_col));
1884718868 }
1884818869 }
1884918870 col += step;
@@ -18889,7 +18910,9 @@ fn overlappable_left(
1888918910 if src != row {
1889018911 OBMC_PAIR_FILTER_HITS.with(|c| c.set(c.get() + 1));
1889118912 }
18892- out.push((row - mi_row, step.min(end_row - row), *info, src - mi_row));
18913+ // lane-t900 r14: `AOMMIN(xd->height, mi_step)` -- see
18914+ // `overlappable_above`.
18915+ out.push((row - mi_row, step.min(bh4), *info, src - mi_row));
1889318916 }
1889418917 }
1889518918 row += step;
@@ -19355,13 +19378,17 @@ fn interintra_blend(
1935519378 }
1935619379 }
1935719380
19358-fn obmc_blend_v(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u16]) {
19381+/// `w` is the number of columns actually written (clipped to the block's own
19382+/// buffer at a frame edge); `ts` is `tmp`'s own stride, the neighbour
19383+/// prediction's full width.
19384+#[allow(clippy::too_many_arguments)]
19385+fn obmc_blend_v(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, ts: usize, tmp: &[u16]) {
1935919386 let mask = obmc_mask(h);
1936019387 for row in 0..h {
1936119388 let m = u32::from(mask[row]);
1936219389 for col in 0..w {
1936319390 let d = &mut dst[(oy + row) * stride + ox + col];
19364- let t = u32::from(tmp[row * w + col]);
19391+ let t = u32::from(tmp[row * ts + col]);
1936519392 *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u16;
1936619393 }
1936719394 }
@@ -19585,9 +19612,14 @@ fn obmc_blend(
1958519612 ec_obmc_trace("above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind);
1958619613 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
1958719614 let nb_scale = mc::scale_factor(ny.width, frame_width);
19615+ if mi_col + off4 + span4 > mi_cols {
19616+ OBMC_EDGE_SPAN_HITS.with(|c| c.set(c.get() + 1));
19617+ }
1958819618 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);
19619+ // lane-t900 r14: the prediction is `op_mi_size` wide (kernel choice
19620+ // included); only the WRITE is clipped to this block's own buffer.
1958919621 let tmp_y = obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, h_kind, v_kind, nb_scale);
19590- obmc_blend_v(pred_y, side, ox, 0, bw, bh, &tmp_y);
19622+ obmc_blend_v(pred_y, side, ox, 0, bw.min(write_w - ox), bh, bw, &tmp_y);
1959119623 if !skip_chroma_above {
1959219624 // lane-t900 r13 (measured, NOT a defect): libaom's min-4 clamp
1959319625 // (`dec_build_prediction_by_above_pred`) sizes only the OBMC
@@ -19597,10 +19629,11 @@ fn obmc_blend(
1959719629 // 1920x792 cut that went 36 differing frames -> 266, worst
1959819630 // 13 B -> 11007 B.
1959919631 let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2);
19632+ let cw = cbw.min(write_w / 2 - cox);
1960019633 let tmp_u = obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);
19601- obmc_blend_v(pred_u, chroma_side, cox, 0, cbw, cbh, &tmp_u);
19634+ obmc_blend_v(pred_u, chroma_side, cox, 0, cw, cbh, cbw, &tmp_u);
1960219635 let tmp_v = obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);
19603- obmc_blend_v(pred_v, chroma_side, cox, 0, cbw, cbh, &tmp_v);
19636+ obmc_blend_v(pred_v, chroma_side, cox, 0, cw, cbh, cbw, &tmp_v);
1960419637 }
1960519638 }
1960619639
@@ -19615,14 +19648,28 @@ fn obmc_blend(
1961519648 ec_obmc_trace("left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind);
1961619649 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
1961719650 let nb_scale = mc::scale_factor(ny.width, frame_width);
19651+ if mi_row + off4 + span4 > mi_rows {
19652+ OBMC_EDGE_SPAN_HITS.with(|c| c.set(c.get() + 1));
19653+ }
1961819654 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);
1961919655 let tmp_y = obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, h_kind, v_kind, nb_scale);
19620- obmc_blend_h(pred_y, side, 0, oy, bw, bh, &tmp_y);
19656+ obmc_blend_h(pred_y, side, 0, oy, bw, bh.min(write_h - oy), &tmp_y);
1962119657 let (cbw, cbh, coy) = (overlap_left / 2, bh / 2, oy / 2);
1962219658 let tmp_u = obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);
19623- obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, cbh, &tmp_u);
19659+ if let Some((_, _, idx)) = ec_mcb {
19660+ eprintln!(
19661+ "OUR_MCB left f={idx} off4={off4} span4={span4} cbw={cbw} cbh={cbh} coy={coy} mv=({},{}) ref0={}",
19662+ nb.mv.0, nb.mv.1, nb.ref_frame
19663+ );
19664+ for r in 0..cbh {
19665+ let row: Vec<u16> = (0..cbw).map(|c| tmp_u[r * cbw + c]).collect();
19666+ eprintln!("OUR_MCB lrow{r}: {row:?}");
19667+ }
19668+ }
19669+ let ch = cbh.min(write_h / 2 - coy);
19670+ obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, ch, &tmp_u);
1962419671 let tmp_v = obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);
19625- obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, cbh, &tmp_v);
19672+ obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, ch, &tmp_v);
1962619673 }
1962719674 if let Some((_, _, idx)) = ec_mcb {
1962819675 for r in 0..write_h / 2 {
crates/ec-av1/src/stream.rsmodified+7 -1
@@ -30472,10 +30472,15 @@ mod tests {
3047230472 // lane-t900 r10: the rect warp top-right reach (600 blocks here).
3047330473 let tr_before = crate::decode::tr_reach_longer_side_hits();
3047430474 let i16_before = crate::decode::intra16x4_in_inter_hits();
30475+ // lane-t900 r14: OBMC neighbour strips that run past the frame edge
30476+ // (792 luma rows = 198 mi rows, so every bottom-row 32x32 block
30477+ // overhangs) -- the shape whose prediction size used to be clamped.
30478+ let edge_before = crate::decode::obmc_edge_span_hits();
3047530479 let frames = match decode_stream(&stream) {
3047630480 Ok(frames) => frames,
3047730481 Err(e) => panic!("{NAME}: decode_stream refused: {e}"),
3047830482 };
30483+ let obmc_edge_span = crate::decode::obmc_edge_span_hits() - edge_before;
3047930484 let fired = (
3048030485 crate::decode::warp_plane_suppress_hits() - before.0,
3048130486 crate::decode::cdef_idx_hits() - before.1,
@@ -30508,6 +30513,7 @@ mod tests {
3050830513 ("sub8_chroma_tx_from_ref", sub8tx),
3050930514 ("inter_neighbour_not_smooth", notsmooth),
3051030515 ("tr_reach_longer_side", tr),
30516+ ("obmc_edge_span", obmc_edge_span),
3051130517 ] {
3051230518 assert!(
3051330519 n > 0,
@@ -30534,7 +30540,7 @@ mod tests {
3053430540 cdef_idx={} inter_sb128_vert={} interintra_rect={} non_chroma_ref_ctx_skip={} \
3053530541 intra_in_inter_txctx={} edge_filter_mi_fix={} intra16x4_in_inter={:?} \
3053630542 sub8_chroma_tx_from_ref={sub8tx} inter_neighbour_not_smooth={notsmooth} \
30537- tr_reach_longer_side={tr}",
30543+ tr_reach_longer_side={tr} obmc_edge_span={obmc_edge_span}",
3053830544 fired.0, fired.1, fired.2, fired.3, fired.4, fired.5, fired.6, i16
3053930545 );
3054030546 }
lanes/t900-r14.handoff.mdadded+35 -0
@@ -0,0 +1,35 @@
1+# lane-t900 r14 handoff -- 1080p is clean; next frontier is 4K
2+
3+Tip `78347fca` on `lane-t900` (base main `a870796b`, merged fast-forward at round start).
4+Report: `lanes/t900-r14.report.md`.
5+
6+## Closed this round (do not re-measure)
7+
8+* Root cause: OBMC neighbour `op_mi_size` is `AOMMIN(xd->width|height, mi_step)`
9+ (`obmc.h:52,83`), never the `end_col`/`end_row` frame-edge clamp. Our clamp shrank the
10+ neighbour PREDICTION, which at 4 chroma rows also flipped `mc.rs:418` to the 4-tap
11+ kernel -> 1-off on the last valid chroma row. Fixed in `a6c408b7`; witness counter
12+ `obmc_edge_span_hits` asserted (33 hits) on the 128-SB inter gate in `52a11095`.
13+* Every 1080p offset probed is byte-exact: head 0-10 s (241 f), 300/900/1200/1800/2100/
14+ 3000/3900/4800/5400/5700/6300/6600/7500/8100/8400/9300/9900/10200 s. Compare script
15+ `~/.cache/t900-tmp/cmp13.sh <name> <obu>`; sweep driver `~/.cache/t900-tmp/sweep14.sh`,
16+ log `~/.cache/t900-tmp/sweep14.log`.
17+* 4K re-check: `h2700.obu` 107 frames and `h1500.obu` 244 frames, 0 differing.
18+* Suites (both green, no FAILED): r14 fix 429 passed/0 failed/38 ignored in 861.07s
19+ (`$HOME/.cache/t900-suite-r14.log`); final tip 429/0/38 in 820.42s
20+ (`$HOME/.cache/t900-suite-r14b.log`).
21+
22+## Owed
23+
24+* The 4K census8 offsets that were not exact before this round (24 of them, `run8.sh`)
25+ were NOT re-swept -- two spot cuts are exact, the rest is unmeasured. Start there:
26+ retarget `run8.sh`'s `PROBE` to `$HOME/.cache/cargo-target-t900b/release/examples/
27+ decode_probe` and run the 4K offsets, then ladder the first bad frame with
28+ `EC_AV1_FINAL_DUMP` + `EC_MCB`/`EC_OBMC`/`EC_PRED` as in r13/r14.
29+
30+## Rungs (all additive, env-gated, on both decoders)
31+
32+`EC_MCB="<plane>:<px>:<py>[:<frame>]"` -- aomdec prints every
33+`dec_build_inter_predictors` call covering that pixel (obmc=1 tmp buffers included);
34+ours prints the block's chroma rows pre/post blend AND, new in r14, each LEFT-pass
35+neighbour's tmp rows with `off4/span4/cbw/cbh/coy/mv/ref0`.
lanes/t900-r14.report.mdadded+98 -0
@@ -0,0 +1,98 @@
1+# lane-t900 r14 report -- the last 1080p residue class: OBMC neighbour prediction size
2+
3+Branch `lane-t900`, base `a870796b` (main, merged fast-forward at round start).
4+
5+## Root cause (one, all of TARGET A)
6+
7+`overlappable_above` / `overlappable_left` (`crates/ec-av1/src/decode.rs`) clamped the
8+neighbour span to `end_col`/`end_row`, i.e. to `mi_cols`/`mi_rows`. libaom's
9+`foreach_overlappable_nb_above`/`_left` (`av1/common/obmc.h:52,83`) pass
10+`op_mi_size = AOMMIN(xd->width|height, mi_step)` -- the block's OWN side, never the
11+frame-edge clamp; `end_col`/`end_row` bound only the WALK. `build_obmc_inter_pred_*`
12+(`reconinter.c:891`) then predicts a strip `op_mi_size * MI_SIZE >> ss` tall/wide, and
13+the destination write runs off into the frame buffer's own padding.
14+
15+Because our span shrank at the frame edge, the neighbour PREDICTION shrank with it, and
16+at 4 chroma rows `mc::predict_with_filters` picks the 4-tap narrow vertical kernel
17+(`mc.rs:418`, class `narrow-block-sharp-kernel`) where libaom used the 8-tap one.
18+Result: a 1-off on the last valid chroma row of the OBMC blend -- 1-13 B on 36 of 267
19+frames of the 900 s 1080p cut and similar counts on every other 1080p cut.
20+
21+Fix (`a6c408b7`): span is `step.min(bw4)` / `step.min(bh4)`; the prediction is built at
22+that full size (kernel choice included) and only the WRITE into this block's own
23+prediction buffer is clipped (`obmc_blend_v` gained the tmp stride, `obmc_blend_h`
24+takes the clipped row count).
25+
26+Witness (`52a11095`): `obmc_edge_span_hits` counts neighbour strips running past
27+`mi_rows`/`mi_cols`; the 128-SB inter witness gate hard-asserts it (fires 33x).
28+
29+## Ladder that produced it (one run each, both decoders)
30+
31+* aomdec `EC_MCB=1:353:395:41` on `c900_62.obu`: base pred (obmc=0) 16 rows identical to
32+ ours; ONE `obmc=1` left-neighbour entry covers row 11, `mi_y=784 bw=8 bh=8`, its
33+ row3 = `494 491 490 491 494 492 488 486`.
34+* ours (`OUR_MCB left`, new tmp dump): same neighbour, `cbh=4` (not 8), row3
35+ `494 492 490 491 ...` -- col 1 is 492 vs libaom's 491.
36+* Blend arithmetic confirms the sign: `obmc_mask_8[1] = 42`,
37+ `(42*493 + 22*491 + 32) >> 6 = 492` (aom) vs `(42*493 + 22*492 + 32) >> 6 = 493` (ours).
38+
39+## 1080p table (10-bit 1920x792, `cmp13.sh`, aomdec `EC_AV1_FINAL_DUMP` vs ours, all planes)
40+
41+| stream | frames | differing | before r14 |
42+|---|---|---|---|
43+| head 0-10 s | 241 | 0 | 78 differing (r11) |
44+| 300 s | 186 | 0 | - |
45+| 900 s (cut_900) | 267 | 0 | 36 differing, first f41, worst 13 B |
46+| 1200 s | 199 | 0 | - |
47+| 1800 s | 193 | 0 | 26 B on f1 (charter) |
48+| 2100 s | 169 | 0 | - |
49+| 3000 s | 135 | 0 | - |
50+| 3900 s | 291 | 0 | - |
51+| 4800 s | 89 | 0 | - |
52+| 5400 s | 275 | 0 | 5 differing |
53+| 5700 s | 134 | 0 | - |
54+| 6300 s | 125 | 0 | differing |
55+| 6600 s | 110 | 0 | - |
56+| 7500 s | 89 | 0 | - |
57+| 8100 s | 96 | 0 | differing |
58+| 8400 s | 135 | 0 | - |
59+| 9300 s | 81 | 0 | - |
60+| 9900 s | 176 | 0 | charter target |
61+| 10200 s | 144 | 0 | - |
62+
63+Every 1080p offset probed this round is byte-exact on every plane. No 1080p residue left
64+in this lane's reach.
65+
66+## 4K regression check (no 1080p-only fix regressed the 4K path)
67+
68+| stream | frames | differing |
69+|---|---|---|
70+| 3840x1608 10-bit, 2700 s cut (`h2700.obu`) | 107 | 0 |
71+| 3840x1608 10-bit, 1500 s cut (`h1500.obu`) | 244 | 0 |
72+
73+## Gates / suite
74+
75+* `a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_decode_pixel_exact`:
76+ `EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-t900b
77+ cargo test -p ec-av1 --lib -j3 a_10bit_128sb_film_frames_with_warp_cdef_and_interintra -- --nocapture`
78+ -> `ok. 1 passed`, counters `... tr_reach_longer_side=600 obmc_edge_span=33`.
79+* Full suite (r14 fix, unit `t900-suite-r14-1788394487`):
80+ `test result: ok. 429 passed; 0 failed; 38 ignored; 0 measured; 0 filtered out;
81+ finished in 861.07s` -- `$HOME/.cache/t900-suite-r14.log`.
82+* Full suite on the FINAL tip (unit `t900-suite-r14b-1788395402`, log
83+ `$HOME/.cache/t900-suite-r14b.log`): `test result: ok. 429 passed; 0 failed; 38 ignored;
84+ 0 measured; 0 filtered out; finished in 820.42s`.
85+
86+## EVIDENCE
87+
88+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
89+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)
90+EVIDENCE: ~/.cache/t900-tmp/sweep14.log | 12 x 2 s 1080p cuts (300..10200 s) + 2 4K cuts, same compare | every offset differing=0
91+EVIDENCE: $HOME/.cache/t900-suite-r14.log | full ec-av1 lib suite as a systemd unit | 429 passed; 0 failed; 38 ignored
92+
93+## Residue
94+
95+* 4K census8's remaining not-exact offsets: not swept this round -- deferred(a 4K census
96+ run costs ~20 min per offset pair on this box while a suite runs); the two 4K cuts I did
97+ re-probe are exact.
98+* No 1080p residue known: fix-now list empty for this lane's 1080p target.