forge
Explore
Log in

Don't you dare go Hollow

SGR_X_BY_XPLUS1 mistranscription (av1_x_by_xplus1[101] and [165..=169])

Browse files at this commit

09e8afabbad8a692dd552c71f3fc45727654bdccAhmet Kaan GümüşParent: 0698b04
  • fix
    • SGR_X_BY_XPLUS1 mistranscription (av1_x_by_xplus1[101] and [165..=169])
Show full message
fix(av1): SGR_X_BY_XPLUS1 mistranscription (av1_x_by_xplus1[101] and [165..=169])

Call-unique debug dump (gated on the pinned stream's own decoded xqd ==
[-16,-32], not a reused coordinate) traced r6's 3110-vs-3109 divergence to
the dense-arm "u" tap's A value: our compute_ab produced (254,303) for
z=101 where libaom's real table gives (253,454). The 9-byte input window
was already correct (r7); the bug was in the const table itself, off by
one at index 101 and short 5 entries in the 254 run at 165..=169.
Regenerated both SGR tables straight from
~/.cache/aom-oracle/src/av1/common/restoration.c to rule out any other
slip (SGR_ONE_BY_X already matched exactly). Pinned stream
fixtures/lr-sgr-r7.obu now decodes pixel-exact on all three planes.
crates/ec-av1/src/restoration.rsmodified+71 -12
@@ -560,19 +560,32 @@ fn apply_wiener_stripe(
560560 /// `[0,255]`, saturating the `z==0` case to `1` instead of `0` (see the
561561 /// libaom source comment this ports -- keeps `256-A[k]` inside a `u8` and
562562 /// avoids a later overflow, without visibly affecting a near-flat block).
563+// r8: this table was transcribed with two errors -- index 101 (253 written
564+// as 254) and indices 165..=169 (254 written as 255) -- traced by comparing
565+// a call-unique dump (gated on the pinned stream's `xqd == [-16,-32]`, not a
566+// reused coordinate) against libaom's real `av1_x_by_xplus1` at the same
567+// `z=101`; both tables now generated straight from
568+// `~/.cache/aom-oracle/src/av1/common/restoration.c` to rule out any other
569+// transcription slip.
563570 const SGR_X_BY_XPLUS1: [i32; 256] = [
564- 1, 128, 171, 192, 205, 213, 219, 224, 228, 230, 233, 235, 236, 238, 239, 240, 241, 242, 243, 243, 244, 244, 245,
565- 245, 246, 246, 247, 247, 247, 247, 248, 248, 248, 248, 249, 249, 249, 249, 249, 250, 250, 250, 250, 250, 250,
566- 250, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
567- 252, 252, 252, 252, 252, 252, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253,
568- 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
569- 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
570- 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
571- 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
572- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
573- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
574- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
575- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 256,
571+ 1, 128, 171, 192, 205, 213, 219, 224, 228, 230, 233, 235, 236, 238, 239,
572+ 240, 241, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 247, 247, 247,
573+ 248, 248, 248, 248, 249, 249, 249, 249, 249, 250, 250, 250, 250, 250, 250,
574+ 250, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 252, 252, 252, 252,
575+ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253,
576+ 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253,
577+ 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 254, 254, 254,
578+ 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
579+ 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
580+ 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
581+ 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
582+ 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
583+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
584+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
585+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
586+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
587+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
588+ 256,
576589 ];
577590
578591 /// `av1_one_by_x` (`restoration.c`): `round(4096/n)` for `n` in `1..=25`
@@ -640,6 +653,16 @@ fn compute_ab(
640653 (256 - a_val) as i64 * b * SGR_ONE_BY_X[(n - 1) as usize] as i64,
641654 SGRPROJ_RECIP_BITS,
642655 );
656+ if std::env::var("EC_LR_CALL_DUMP").is_ok()
657+ && v_start as i64 + i == 60
658+ && h_start as i64 + j == 6
659+ && r == 1
660+ {
661+ eprintln!(
662+ "EC_LR_CALL_DUMP compute_ab u_tap: r={r} s={s} n={n} box_a={a} box_b={b} \
663+ p={p} z={z} a_val={a_val} b_val={b_val}"
664+ );
665+ }
643666 ab[gi * gw + gj] = (a_val, b_val);
644667 }
645668 }
@@ -677,6 +700,28 @@ fn apply_sgrproj_stripe(
677700 let ab0 = (r0 > 0).then(|| compute_ab(cdef, deblocked, stride, plane_w, plane_h, h_start, v_start, v_end, w, h, r0, s0));
678701 let ab1 = (r1 > 0).then(|| compute_ab(cdef, deblocked, stride, plane_w, plane_h, h_start, v_start, v_end, w, h, r1, s1));
679702
703+ // r8: call-unique debug dump -- r6's coordinate-only gate (`v_start==60`)
704+ // matched several unrelated calls across the gate's attempt sweep, so its
705+ // captured bytes were never provably from the failing call. `info.xqd`
706+ // is this restoration unit's own decoded weights, unique to the one call
707+ // r7 traced (`[-16,-32]`); dump the real 9-byte dense-arm (r1) "u"-tap
708+ // window (physical rows 59..=61, cols 5..=7 -- r7's traced tap) straight
709+ // from `lr_sample` for this exact call, no coordinate matching involved.
710+ if std::env::var("EC_LR_CALL_DUMP").is_ok() && r1 > 0 && info.xqd == [-16, -32] {
711+ let bytes: Vec<i32> = (59..=61)
712+ .flat_map(|row| {
713+ (5..=7).map(move |col| {
714+ lr_sample(cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row, col)
715+ })
716+ })
717+ .collect();
718+ eprintln!(
719+ "EC_LR_CALL_DUMP: xqd={:?} v_start={v_start} v_end={v_end} h_start={h_start} \
720+ u-tap 9-byte window (rows 59..=61, cols 5..=7) = {bytes:?}",
721+ info.xqd
722+ );
723+ }
724+
680725 let mut xq = [0i32; 2];
681726 if r0 == 0 {
682727 xq[0] = 0;
@@ -747,6 +792,20 @@ fn apply_sgrproj_stripe(
747792 let b = (b_c + b_u + b_d + b_l + b_r) * 4 + (b_ul + b_ur + b_dl + b_dr) * 3;
748793 let flt1 = round2(a * dgd + b, SGRPROJ_SGR_BITS + 5 - SGRPROJ_RST_BITS);
749794 v += xq[1] as i64 * (flt1 - u);
795+ if std::env::var("EC_LR_CALL_DUMP").is_ok()
796+ && info.xqd == [-16, -32]
797+ && v_start as i64 + i == 61
798+ && h_start as i64 + j == 6
799+ {
800+ eprintln!(
801+ "EC_LR_CALL_DUMP combine: c={:?} u_tap(row60)={:?} d={:?} l={:?} r={:?} \
802+ ul={:?} ur={:?} dl={:?} dr={:?} dense a={a} b={b} dgd={dgd} \
803+ u={u} flt1={flt1} xq={xq:?} v_before_final_round={v}",
804+ ab[idx(i, j)], ab[idx(i - 1, j)], ab[idx(i + 1, j)], ab[idx(i, j - 1)],
805+ ab[idx(i, j + 1)], ab[idx(i - 1, j - 1)], ab[idx(i - 1, j + 1)],
806+ ab[idx(i + 1, j - 1)], ab[idx(i + 1, j + 1)]
807+ );
808+ }
750809 }
751810 let out_v = round2(v, SGRPROJ_PRJ_BITS as u32 + SGRPROJ_RST_BITS).clamp(0, 255) as u8;
752811 out[(v_start as i64 + i) as usize * stride + (h_start as i64 + j) as usize] = out_v;
crates/ec-av1/src/stream.rsmodified+38 -0
@@ -4841,6 +4841,44 @@ mod tests {
48414841 );
48424842 }
48434843
4844+ /// r8: decode the ONE pinned stream `EC_AV1_GATE_DUMP` captured in r7
4845+ /// (`fixtures/lr-sgr-r7.obu`, seed 46) directly -- not the live
4846+ /// 40-attempt sweep, which reuses `v_start` coordinates across unrelated
4847+ /// seeds/frames and made r6's captured 9 bytes unprovable. Run with
4848+ /// `EC_LR_CALL_DUMP=1` set (see `restoration.rs`'s `apply_sgrproj_stripe`)
4849+ /// to get the real window on stderr, call-uniquely keyed to `xqd ==
4850+ /// [-16,-32]` rather than any coordinate.
4851+ #[test]
4852+ #[ignore = "reads a pinned fixture under the gitignored fixtures dir; run manually with EC_LR_CALL_DUMP=1"]
4853+ fn pinned_lr_sgr_stream_call_unique_dump() {
4854+ let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/lr-sgr-r7.obu");
4855+ let stream = std::fs::read(path).expect("reading pinned lr-sgr-r7.obu");
4856+ let pics = decode_stream(&stream).expect("pinned lr-sgr-r7.obu must decode");
4857+ if have_ffmpeg() {
4858+ let reference = ffmpeg_decode_sequence(&stream, 192, 128, pics.len());
4859+ for (i, (got, want)) in pics.iter().zip(&reference).enumerate() {
4860+ let y_mismatch = got.y != want.y;
4861+ let u_mismatch = got.u != want.u;
4862+ let v_mismatch = got.v != want.v;
4863+ eprintln!(
4864+ "frame {i}: y_mismatch={y_mismatch} u_mismatch={u_mismatch} v_mismatch={v_mismatch}"
4865+ );
4866+ if y_mismatch {
4867+ let n = got.y.iter().zip(&want.y).filter(|(a, b)| a != b).count();
4868+ eprintln!(" {n} luma bytes differ / {}", got.y.len());
4869+ }
4870+ if v_mismatch {
4871+ let w = 96usize; // chroma plane width (192/2)
4872+ for (idx, (a, b)) in got.v.iter().zip(&want.v).enumerate() {
4873+ if a != b {
4874+ eprintln!(" V[{},{}] got={a} want={b}", idx / w, idx % w);
4875+ }
4876+ }
4877+ }
4878+ }
4879+ }
4880+ }
4881+
48444882 /// Pinned streams captured by `EC_AV1_GATE_DUMP` off
48454883 /// `a_real_aomenc_stream_with_warped_motion_refuses_or_matches` -- each
48464884 /// one is a former mismatch, kept as a regression pin (warp-mismatch: