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 {
3028 /// `reconstruct_mc_rect` reads both of its buffers at.3028 /// `reconstruct_mc_rect` reads both of its buffers at.
3029 #[derive(Clone, Copy)]3029 #[derive(Clone, Copy)]
3030 pub(crate) struct TxParams {3030 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,
3031 pub(crate) w: usize,3039 pub(crate) w: usize,
3032 pub(crate) h: usize,3040 pub(crate) h: usize,
3033 pub(crate) bit_depth: u8,3041 pub(crate) bit_depth: u8,
@@ -3118,6 +3126,7 @@ impl TxParams {
3118 }3126 }
3119 crate::transform::dequant_and_inverse_wht(3127 crate::transform::dequant_and_inverse_wht(
3120 grid,3128 grid,
3129+ self.plane,
3121 self.w,3130 self.w,
3122 self.h,3131 self.h,
3123 self.bit_depth,3132 self.bit_depth,
@@ -21556,6 +21565,7 @@ fn read_plane(
21556 let levels = extend_corner(grid, tx_side, tx_side, side, side);21565 let levels = extend_corner(grid, tx_side, tx_side, side, side);
21557 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);21566 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);
21558 let tx = TxParams {21567 let tx = TxParams {
21568+ plane: plane_idx,
21559 w: side,21569 w: side,
21560 h: side,21570 h: side,
21561 bit_depth: bit_depth(fctx),21571 bit_depth: bit_depth(fctx),
@@ -27206,6 +27216,7 @@ fn decode_leaf_rect8(
27206 // fixture: the DCT route left ±1..30 sample errors on every27216 // fixture: the DCT route left ±1..30 sample errors on every
27207 // walked leaf's luma.27217 // walked leaf's luma.
27208 let tx = TxParams {27218 let tx = TxParams {
27219+ plane: 0,
27209 w: tw,27220 w: tw,
27210 h: th,27221 h: th,
27211 bit_depth: crate::decode::bit_depth(fctx),27222 bit_depth: crate::decode::bit_depth(fctx),
@@ -30608,6 +30619,7 @@ fn read_inter_plane_rect(
30608 // stride, so the dense `w x h` residual is re-laid at that stride30619 // stride, so the dense `w x h` residual is re-laid at that stride
30609 // (`TxParams::stride`) after the inverse transform.30620 // (`TxParams::stride`) after the inverse transform.
30610 let tx = TxParams {30621 let tx = TxParams {
30622+ plane: plane_idx,
30611 w,30623 w,
30612 h,30624 h,
30613 bit_depth: bit_depth(fctx),30625 bit_depth: bit_depth(fctx),
@@ -37712,6 +37724,7 @@ fn read_inter_plane(
37712 let grid = extend_corner(grid, tx_side, tx_side, side, side);37724 let grid = extend_corner(grid, tx_side, tx_side, side, side);
37713 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);37725 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);
37714 let tx = TxParams {37726 let tx = TxParams {
37727+ plane: plane_idx,
37715 w: side,37728 w: side,
37716 h: side,37729 h: side,
37717 bit_depth: bit_depth(fctx),37730 bit_depth: bit_depth(fctx),
crates/ec-av1/src/transform.rsmodified+50 -8
@@ -1381,6 +1381,15 @@ pub fn dequant_and_inverse_typed_wh(
1381 // the twin of the oracle's `EC_DQCOEFF` rung (whose own layout is1381 // the twin of the oracle's `EC_DQCOEFF` rung (whose own layout is
1382 // column-major `input[c * h + r]`), so a residual mismatch whose1382 // column-major `input[c * h + r]`), so a residual mismatch whose
1383 // levels already agree is separable into dequant vs transform.1383 // 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).
1384 if crate::envflags::env_flag!("EC_DQCOEFF") {1393 if crate::envflags::env_flag!("EC_DQCOEFF") {
1385 let nz: Vec<String> = dq1394 let nz: Vec<String> = dq
1386 .iter()1395 .iter()
@@ -3144,6 +3153,7 @@ pub fn inverse_wht4x4(dq: &[i32]) -> Vec<i32> {
3144 /// marker contract).3153 /// marker contract).
3145 pub fn dequant_and_inverse_wht4x4(3154 pub fn dequant_and_inverse_wht4x4(
3146 levels: &[i32],3155 levels: &[i32],
3156+ plane: usize,
3147 bit_depth: u8,3157 bit_depth: u8,
3148 q_idx: i32,3158 q_idx: i32,
3149 dc_delta: i32,3159 dc_delta: i32,
@@ -3160,6 +3170,35 @@ pub fn dequant_and_inverse_wht4x4(
3160 crate::quant::dequant_wh_into(3170 crate::quant::dequant_wh_into(
3161 levels, &mut dq, 4, 4, bit_depth, q_idx, dc_delta, ac_delta, None,3171 levels, &mut dq, 4, 4, bit_depth, q_idx, dc_delta, ac_delta, None,
3162 );3172 );
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+ }
3163 inverse_wht4x4(&dq[..16])3202 inverse_wht4x4(&dq[..16])
3164 })3203 })
3165 }3204 }
@@ -3200,6 +3239,7 @@ pub fn dequant_and_inverse_wht4x4(
3200 /// Returns the same empty-grid marker as [`dequant_and_inverse_wht4x4`].3239 /// Returns the same empty-grid marker as [`dequant_and_inverse_wht4x4`].
3201 pub fn dequant_and_inverse_wht(3240 pub fn dequant_and_inverse_wht(
3202 levels: &[i32],3241 levels: &[i32],
3242+ plane: usize,
3203 w: usize,3243 w: usize,
3204 h: usize,3244 h: usize,
3205 bit_depth: u8,3245 bit_depth: u8,
@@ -3208,7 +3248,7 @@ pub fn dequant_and_inverse_wht(
3208 ac_delta: i32,3248 ac_delta: i32,
3209 ) -> Vec<i32> {3249 ) -> Vec<i32> {
3210 if w == 4 && h == 4 {3250 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);
3212 }3252 }
3213 if crate::decode::is_zero_grid(levels) {3253 if crate::decode::is_zero_grid(levels) {
3214 return Vec::new();3254 return Vec::new();
@@ -3227,7 +3267,8 @@ pub fn dequant_and_inverse_wht(
3227 };3267 };
3228 }3268 }
3229 }3269 }
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);
3231 // An all-zero tile dequantizes to the same empty marker a 4x43272 // An all-zero tile dequantizes to the same empty marker a 4x4
3232 // caller passes straight through, and `out` is already zero --3273 // caller passes straight through, and `out` is already zero --
3233 // copying out of it would index an empty slice.3274 // copying out of it would index an empty slice.
@@ -3342,12 +3383,13 @@ mod lossless_tx_tests {
3342 };3383 };
3343 for &(w, h) in &[(8usize, 4usize), (4, 8), (8, 8), (16, 4), (4, 16), (16, 16)] {3384 for &(w, h) in &[(8usize, 4usize), (4, 8), (8, 8), (16, 4), (4, 16), (16, 16)] {
3344 let levels: Vec<i32> = (0..w * h).map(|_| next()).collect();3385 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);
3346 let mut want = vec![0i32; w * h];3387 let mut want = vec![0i32; w * h];
3347 for ty in 0..h / 4 {3388 for ty in 0..h / 4 {
3348 for tx in 0..w / 4 {3389 for tx in 0..w / 4 {
3349 let unit = super::dequant_and_inverse_wht4x4(3390 let unit = super::dequant_and_inverse_wht4x4(
3350 &tile_of(&levels, w, tx, ty),3391 &tile_of(&levels, w, tx, ty),
3392+ 0,
3351 10,3393 10,
3352 0,3394 0,
3353 0,3395 0,
@@ -3382,7 +3424,7 @@ mod lossless_tx_tests {
3382 levels[0] = 400;3424 levels[0] = 400;
3383 levels[1] = -240;3425 levels[1] = -240;
3384 levels[2] = 88;3426 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);
3386 assert_eq!(got.len(), 32, "8x4 residual length");3428 assert_eq!(got.len(), 32, "8x4 residual length");
3387 let mut want = vec![0i32; 32];3429 let mut want = vec![0i32; 32];
3388 for (tx, ty) in [(0usize, 0usize), (1, 0)] {3430 for (tx, ty) in [(0usize, 0usize), (1, 0)] {
@@ -3392,7 +3434,7 @@ mod lossless_tx_tests {
3392 t[r * 4 + c] = levels[(ty * 4 + r) * 8 + tx * 4 + c];3434 t[r * 4 + c] = levels[(ty * 4 + r) * 8 + tx * 4 + c];
3393 }3435 }
3394 }3436 }
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);
3396 if unit.is_empty() {3438 if unit.is_empty() {
3397 continue;3439 continue;
3398 }3440 }
@@ -3422,8 +3464,8 @@ mod lossless_tx_tests {
3422 })3464 })
3423 .collect();3465 .collect();
3424 assert_eq!(3466 assert_eq!(
3425- super::dequant_and_inverse_wht(&levels, 4, 4, 8, 0, 0, 0),3467+ super::dequant_and_inverse_wht(&levels, 0, 4, 4, 8, 0, 0, 0),
3426- super::dequant_and_inverse_wht4x4(&levels, 8, 0, 0, 0),3468+ super::dequant_and_inverse_wht4x4(&levels, 0, 8, 0, 0, 0),
3427 "levels={levels:?}"3469 "levels={levels:?}"
3428 );3470 );
3429 }3471 }
@@ -3437,7 +3479,7 @@ mod lossless_tx_tests {
3437 #[test]3479 #[test]
3438 fn a_non_4x4_all_zero_lossless_unit_keeps_the_empty_marker() {3480 fn a_non_4x4_all_zero_lossless_unit_keeps_the_empty_marker() {
3439 assert!(3481 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(),
3441 "an all-zero 8x4 lossless unit must stay the empty marker"3483 "an all-zero 8x4 lossless unit must stay the empty marker"
3442 );3484 );
3443 }3485 }