forge
Explore
Log in

Don't you dare go Hollow

ec-av1: the lossless OUR_DQW twin, plane-tagged, with the raw levels beside dq

Browse files at this commit

bb7bd46bfd8a9effa323aeb7ab9f7a43a42b26d6Ahmet Kaan GümüşParent: 37631b3
Re-derives lane-av1loss444mm r3/r6/r7 (6dfd827e, 7586358f, c8ed05f3) onto
current main. The open defect it instruments is the 4:4:4 lossless KEY FRAME
reconstruction-only divergence (21 U + 28 V samples off by up to +/-63, luma
exact, entropy bit-identical), named in lanes/av1loss444mm.report.md r10 as
item (a) with a three-file search space.

The oracle's `EC_DQCOEFF` rung printed thousands of lines on a lossless
stream while ours printed NOTHING, because `dequant_and_inverse_typed_wh` is
the LOSSY route -- a lossless 4x4 unit goes to `dequant_and_inverse_wht4x4`.
That silence reads as "no coefficients" rather than "wrong function". The
twin prints the same `pos:value` nonzero form under the same `EC_DQCOEFF`
env var, plus:

- `plane=`, carried on a new `TxParams.plane` set by the reader that OWNS the
  unit. The per-unit census plane could not supply it: the callers that route
  a lossless 4x4 unit into the WHT are not all the ones that stamp the census
  plane (measured: 1663 of 1663 chroma units paired by count, 1660 against an
  empty grid). Without `plane=` a 4x4 chroma grid is indistinguishable from a
  luma one and an order-paired ladder collapses -- equal counts, value ratios
  of exactly 1.0, and only 16 of 2053 units matched.
- `lv=`, the RAW level grid the dequant consumed. If `nz` is empty while `lv`
  is not, `dequant_wh_into` is what zeroed it, and the line now says so
  instead of leaving the next lane to infer it (this is what retracted r6's
  "1650 units dequantized to empty").

Behaviour-free: `plane` reaches nothing but the env-gated eprintln, and it is
threaded through `dequant_and_inverse_wht` (which main has since generalised
to any shape, lane-whtshape) rather than only the 4x4 entry, so the raster
path's tiles carry it too.

`census_plane()` from 7586358f is NOT landed: on the branch's own tip it is
defined and never called, dead weight next to the field that replaced it.
crates/ec-av1/src/decode.rsmodified+13 -0
@@ -3028,6 +3028,14 @@ fn cfl_src_rect(px: usize, py: usize, bw: usize, bh: usize) -> CflSrc {
30283028 /// `reconstruct_mc_rect` reads both of its buffers at.
30293029 #[derive(Clone, Copy)]
30303030 pub(crate) struct TxParams {
3031+ /// The plane this unit belongs to (0 luma, 1 U, 2 V), carried from the
3032+ /// reader that OWNS the unit. `dequant_and_inverse_wht4x4`'s `EC_DQCOEFF`
3033+ /// twin prints it so its ladder pairs with the oracle's: the per-unit
3034+ /// census plane could not, because the callers that route a lossless 4x4
3035+ /// unit into the WHT are not all the ones that stamp the census plane
3036+ /// (measured on `ll444-lossless-key.obu`: 1663 of 1663 chroma units paired
3037+ /// by count, 1660 of them against an empty grid).
3038+ pub(crate) plane: usize,
30313039 pub(crate) w: usize,
30323040 pub(crate) h: usize,
30333041 pub(crate) bit_depth: u8,
@@ -3118,6 +3126,7 @@ impl TxParams {
31183126 }
31193127 crate::transform::dequant_and_inverse_wht(
31203128 grid,
3129+ self.plane,
31213130 self.w,
31223131 self.h,
31233132 self.bit_depth,
@@ -21556,6 +21565,7 @@ fn read_plane(
2155621565 let levels = extend_corner(grid, tx_side, tx_side, side, side);
2155721566 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);
2155821567 let tx = TxParams {
21568+ plane: plane_idx,
2155921569 w: side,
2156021570 h: side,
2156121571 bit_depth: bit_depth(fctx),
@@ -27206,6 +27216,7 @@ fn decode_leaf_rect8(
2720627216 // fixture: the DCT route left ±1..30 sample errors on every
2720727217 // walked leaf's luma.
2720827218 let tx = TxParams {
27219+ plane: 0,
2720927220 w: tw,
2721027221 h: th,
2721127222 bit_depth: crate::decode::bit_depth(fctx),
@@ -30608,6 +30619,7 @@ fn read_inter_plane_rect(
3060830619 // stride, so the dense `w x h` residual is re-laid at that stride
3060930620 // (`TxParams::stride`) after the inverse transform.
3061030621 let tx = TxParams {
30622+ plane: plane_idx,
3061130623 w,
3061230624 h,
3061330625 bit_depth: bit_depth(fctx),
@@ -37712,6 +37724,7 @@ fn read_inter_plane(
3771237724 let grid = extend_corner(grid, tx_side, tx_side, side, side);
3771337725 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);
3771437726 let tx = TxParams {
37727+ plane: plane_idx,
3771537728 w: side,
3771637729 h: side,
3771737730 bit_depth: bit_depth(fctx),
crates/ec-av1/src/transform.rsmodified+50 -8
@@ -1381,6 +1381,15 @@ pub fn dequant_and_inverse_typed_wh(
13811381 // the twin of the oracle's `EC_DQCOEFF` rung (whose own layout is
13821382 // column-major `input[c * h + r]`), so a residual mismatch whose
13831383 // levels already agree is separable into dequant vs transform.
1384+ //
1385+ // LOSSY PATH ONLY (lane-av1loss444mm): a LOSSLESS 4x4 unit never
1386+ // reaches this function -- `decode.rs` routes it to
1387+ // `dequant_and_inverse_wht4x4` -- so on a lossless stream this rung
1388+ // printed NOTHING while the oracle's printed thousands of lines, and
1389+ // that silence reads as "no coefficients" rather than "wrong function".
1390+ // The lossless twin is `OUR_DQW` in `dequant_and_inverse_wht4x4`,
1391+ // below; both carry `plane=` so a chroma grid can be told from a luma
1392+ // one (the oracle's line carries it too).
13841393 if crate::envflags::env_flag!("EC_DQCOEFF") {
13851394 let nz: Vec<String> = dq
13861395 .iter()
@@ -3144,6 +3153,7 @@ pub fn inverse_wht4x4(dq: &[i32]) -> Vec<i32> {
31443153 /// marker contract).
31453154 pub fn dequant_and_inverse_wht4x4(
31463155 levels: &[i32],
3156+ plane: usize,
31473157 bit_depth: u8,
31483158 q_idx: i32,
31493159 dc_delta: i32,
@@ -3160,6 +3170,35 @@ pub fn dequant_and_inverse_wht4x4(
31603170 crate::quant::dequant_wh_into(
31613171 levels, &mut dq, 4, 4, bit_depth, q_idx, dc_delta, ac_delta, None,
31623172 );
3173+ // lane-av1loss444mm: the LOSSLESS half of the oracle's `EC_DQCOEFF`
3174+ // twin. Same env var, same `pos:value` nonzero form, PLUS `plane=`
3175+ // -- which is what makes the two ladders pairable: without it a 4x4
3176+ // chroma grid is indistinguishable from a luma one and an
3177+ // order-paired comparison of the two sides collapses (measured on
3178+ // `ll444-lossless-key.obu`: equal unit counts and value ratios of
3179+ // exactly 1.0, yet 16 of 2053 units matched).
3180+ if crate::envflags::env_flag!("EC_DQCOEFF") {
3181+ let nz: Vec<String> = dq[..16]
3182+ .iter()
3183+ .enumerate()
3184+ .filter(|&(_, &v)| v != 0)
3185+ .map(|(i, &v)| format!("{i}:{v}"))
3186+ .collect();
3187+ // `lv=` is the RAW level grid the dequant consumed: if `nz` is
3188+ // empty while `lv` is not, `dequant_wh_into` is what zeroed it, and
3189+ // this line says so instead of leaving the next lane to infer it.
3190+ let lv: Vec<String> = levels[..16]
3191+ .iter()
3192+ .enumerate()
3193+ .filter(|&(_, &v)| v != 0)
3194+ .map(|(i, &v)| format!("{i}:{v}"))
3195+ .collect();
3196+ eprintln!(
3197+ "OUR_DQW plane={plane} w=4 h=4 q={q_idx} dcd={dc_delta} acd={ac_delta} nz={} lv={}",
3198+ nz.join(","),
3199+ lv.join(",")
3200+ );
3201+ }
31633202 inverse_wht4x4(&dq[..16])
31643203 })
31653204 }
@@ -3200,6 +3239,7 @@ pub fn dequant_and_inverse_wht4x4(
32003239 /// Returns the same empty-grid marker as [`dequant_and_inverse_wht4x4`].
32013240 pub fn dequant_and_inverse_wht(
32023241 levels: &[i32],
3242+ plane: usize,
32033243 w: usize,
32043244 h: usize,
32053245 bit_depth: u8,
@@ -3208,7 +3248,7 @@ pub fn dequant_and_inverse_wht(
32083248 ac_delta: i32,
32093249 ) -> Vec<i32> {
32103250 if w == 4 && h == 4 {
3211- return dequant_and_inverse_wht4x4(levels, bit_depth, q_idx, dc_delta, ac_delta);
3251+ return dequant_and_inverse_wht4x4(levels, plane, bit_depth, q_idx, dc_delta, ac_delta);
32123252 }
32133253 if crate::decode::is_zero_grid(levels) {
32143254 return Vec::new();
@@ -3227,7 +3267,8 @@ pub fn dequant_and_inverse_wht(
32273267 };
32283268 }
32293269 }
3230- let res = dequant_and_inverse_wht4x4(&tile, bit_depth, q_idx, dc_delta, ac_delta);
3270+ let res =
3271+ dequant_and_inverse_wht4x4(&tile, plane, bit_depth, q_idx, dc_delta, ac_delta);
32313272 // An all-zero tile dequantizes to the same empty marker a 4x4
32323273 // caller passes straight through, and `out` is already zero --
32333274 // copying out of it would index an empty slice.
@@ -3342,12 +3383,13 @@ mod lossless_tx_tests {
33423383 };
33433384 for &(w, h) in &[(8usize, 4usize), (4, 8), (8, 8), (16, 4), (4, 16), (16, 16)] {
33443385 let levels: Vec<i32> = (0..w * h).map(|_| next()).collect();
3345- let got = super::dequant_and_inverse_wht(&levels, w, h, 10, 0, 0, 0);
3386+ let got = super::dequant_and_inverse_wht(&levels, 0, w, h, 10, 0, 0, 0);
33463387 let mut want = vec![0i32; w * h];
33473388 for ty in 0..h / 4 {
33483389 for tx in 0..w / 4 {
33493390 let unit = super::dequant_and_inverse_wht4x4(
33503391 &tile_of(&levels, w, tx, ty),
3392+ 0,
33513393 10,
33523394 0,
33533395 0,
@@ -3382,7 +3424,7 @@ mod lossless_tx_tests {
33823424 levels[0] = 400;
33833425 levels[1] = -240;
33843426 levels[2] = 88;
3385- let got = super::dequant_and_inverse_wht(&levels, 8, 4, 10, 0, 0, 0);
3427+ let got = super::dequant_and_inverse_wht(&levels, 0, 8, 4, 10, 0, 0, 0);
33863428 assert_eq!(got.len(), 32, "8x4 residual length");
33873429 let mut want = vec![0i32; 32];
33883430 for (tx, ty) in [(0usize, 0usize), (1, 0)] {
@@ -3392,7 +3434,7 @@ mod lossless_tx_tests {
33923434 t[r * 4 + c] = levels[(ty * 4 + r) * 8 + tx * 4 + c];
33933435 }
33943436 }
3395- let unit = super::dequant_and_inverse_wht4x4(&t, 10, 0, 0, 0);
3437+ let unit = super::dequant_and_inverse_wht4x4(&t, 0, 10, 0, 0, 0);
33963438 if unit.is_empty() {
33973439 continue;
33983440 }
@@ -3422,8 +3464,8 @@ mod lossless_tx_tests {
34223464 })
34233465 .collect();
34243466 assert_eq!(
3425- super::dequant_and_inverse_wht(&levels, 4, 4, 8, 0, 0, 0),
3426- super::dequant_and_inverse_wht4x4(&levels, 8, 0, 0, 0),
3467+ super::dequant_and_inverse_wht(&levels, 0, 4, 4, 8, 0, 0, 0),
3468+ super::dequant_and_inverse_wht4x4(&levels, 0, 8, 0, 0, 0),
34273469 "levels={levels:?}"
34283470 );
34293471 }
@@ -3437,7 +3479,7 @@ mod lossless_tx_tests {
34373479 #[test]
34383480 fn a_non_4x4_all_zero_lossless_unit_keeps_the_empty_marker() {
34393481 assert!(
3440- super::dequant_and_inverse_wht(&[0i32; 32], 8, 4, 10, 0, 0, 0).is_empty(),
3482+ super::dequant_and_inverse_wht(&[0i32; 32], 0, 8, 4, 10, 0, 0, 0).is_empty(),
34413483 "an all-zero 8x4 lossless unit must stay the empty marker"
34423484 );
34433485 }