From 8560456d76b25acbe35cbfc193f2e3a7b8ea72e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 19:40:49 +0300 Subject: [PATCH] fix(av1): thread per-plane quantizer deltas (delta_q_y_dc/u_dc/u_ac/v_dc/v_ac) into dequant Spec 5.9.12/7.12.2: these were parsed by ec-av1-syntax and used for nothing but the lossless[] check. Threaded QuantDeltas through dequant_coeff_wh/ dequant_wh/dequant_and_inverse_typed(_wh) and all 8 decode.rs leaf call sites, plane-correct (Y has no AC delta). decode_stream's 5 call sites now pass header.quantization.delta_q_*; convenience wrappers pass ::default(). Plain 4-arg dequant/dequant_coeff/dequant_and_inverse (~20 external callers in tile.rs/encode.rs/transform.rs) unchanged. Blast radius measured, not assumed: EC_AV1_TRACE now prints the 5 deltas at parse time. Measured zero on the r10 pinned repro (seed42.obu, base_q_idx 180) and on every stream the scoped decode::/quant::/transform:: suites exercise (27/27 green) -- no gate was passing "for the wrong reason". Charter's 81-vs-76 defect is NOT this: deltas are genuinely zero for seed42, disproven by measurement per the charter's own fallback clause. Pinned repro currently panics on an unrelated pre-existing gap (32x32 partition value=4, later superblock, same shape as the r9 part32-AB dead-end) before it can even reach the pixel comparison. Report names the next suspect (CURRENT_Q_IDX per-superblock delta-q state / segmentation qindex) with a one-line instrumentation step, left for the next round. Red: pinned_sbpart_stream_decodes_pixel_exact still fails (pre-existing, unrelated gap, not a regression from this diff). --- crates/ec-av1-syntax/src/frame.rs | 6 ++ crates/ec-av1/src/decode.rs | 55 +++++++++++++++++- crates/ec-av1/src/quant.rs | 56 +++++++++++++++---- crates/ec-av1/src/stream.rs | 35 ++++++++++++ crates/ec-av1/src/transform.rs | 19 +++++-- lanes/sbpart-r11.report.md | 92 +++++++++++++++++++++++++++++++ 6 files changed, 246 insertions(+), 17 deletions(-) create mode 100644 lanes/sbpart-r11.report.md diff --git a/crates/ec-av1-syntax/src/frame.rs b/crates/ec-av1-syntax/src/frame.rs index b1e29edb..574111ed 100644 --- a/crates/ec-av1-syntax/src/frame.rs +++ b/crates/ec-av1-syntax/src/frame.rs @@ -1426,6 +1426,12 @@ fn read_quantization_params( }; } h.quantization = q; + if std::env::var_os("EC_AV1_TRACE").is_some() { + eprintln!( + "TRACE quant_deltas base_q_idx={} y_dc={} u_dc={} u_ac={} v_dc={} v_ac={}", + q.base_q_idx, q.delta_q_y_dc, q.delta_q_u_dc, q.delta_q_u_ac, q.delta_q_v_dc, q.delta_q_v_ac + ); + } Ok(()) } diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index e1c66b3f..2cd062fd 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -146,6 +146,21 @@ thread_local! { thread_local! { static CURRENT_Q_IDX: std::cell::Cell = const { std::cell::Cell::new(0) }; } +// This frame's own per-plane DC/AC quantizer-index deltas (lane-sbpart r11, +// spec 5.9.12/7.12.2, [`crate::quant::QuantDeltas`]) -- frame-constant (not +// per-superblock like [`CURRENT_Q_IDX`]), set once per frame decode and read +// back at every dequantization call site keyed on which plane it is doing. +thread_local! { + static QUANT_DELTAS: std::cell::Cell = const { + std::cell::Cell::new(crate::quant::QuantDeltas { + y_dc: 0, + u_dc: 0, + u_ac: 0, + v_dc: 0, + v_ac: 0, + }) + }; +} // How many real `delta_q_present` symbol groups [`maybe_read_delta_q`] has // read, across every call on the current thread -- the gate's proof that a // `delta_q_present` stream actually reached the new reader. @@ -158,6 +173,18 @@ pub(crate) fn delta_q_hits() -> usize { DELTA_Q_HITS.with(|c| c.get()) } +/// This frame's [`QUANT_DELTAS`] `(dc, ac)` pair for plane `plane_idx` (0 = +/// Y, 1 = U, 2 = V) -- luma has no coded `ac` delta (spec 5.9.12 never reads +/// one), so it is always `0` here. +fn plane_q_delta(plane_idx: usize) -> (i32, i32) { + let d = QUANT_DELTAS.with(|c| c.get()); + match plane_idx { + 0 => (d.y_dc, 0), + 1 => (d.u_dc, d.u_ac), + _ => (d.v_dc, d.v_ac), + } +} + /// `read_delta_qindex`/`read_delta_q_params` (spec 5.11.10, libaom /// `decodemv.c:85-146,735-770`), called right after [`maybe_read_cdef_idx`] /// at every block-decode call site (spec order `skip -> cdef -> delta_q`). @@ -3212,6 +3239,8 @@ fn decode_block_rect( bh, 8, CURRENT_Q_IDX.with(|c| c.get()), + plane_q_delta(0).0, + plane_q_delta(0).1, luma_tx_type, ); y.reconstruct_rect( @@ -3251,6 +3280,8 @@ fn decode_block_rect( chroma_h, 8, CURRENT_Q_IDX.with(|c| c.get()), + plane_q_delta(1).0, + plane_q_delta(1).1, u_tx_type, ); u.reconstruct_rect( @@ -3289,6 +3320,8 @@ fn decode_block_rect( chroma_h, 8, CURRENT_Q_IDX.with(|c| c.get()), + plane_q_delta(2).0, + plane_q_delta(2).1, v_tx_type, ); v.reconstruct_rect( @@ -3500,6 +3533,8 @@ fn decode_block_rect64( bh, 8, i32::from(base_q_idx), + plane_q_delta(0).0, + plane_q_delta(0).1, luma_tx_type, ); y.reconstruct_rect( @@ -3559,6 +3594,8 @@ fn decode_block_rect64( chroma_h, 8, i32::from(base_q_idx), + plane_q_delta(1).0, + plane_q_delta(1).1, u_tx_type, ); u.reconstruct_rect( @@ -3600,6 +3637,8 @@ fn decode_block_rect64( chroma_h, 8, i32::from(base_q_idx), + plane_q_delta(2).0, + plane_q_delta(2).1, v_tx_type, ); v.reconstruct_rect( @@ -4319,7 +4358,8 @@ fn read_plane( } full }; - let residual = dequant_and_inverse_typed(&levels, side, 8, CURRENT_Q_IDX.with(|c| c.get()), tx_type); + let (dc_delta, ac_delta) = plane_q_delta(plane_idx); + let residual = dequant_and_inverse_typed(&levels, side, 8, CURRENT_Q_IDX.with(|c| c.get()), dc_delta, ac_delta, tx_type); if std::env::var_os("EC_AV1_TRACE").is_some() { eprintln!( "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}", @@ -6096,6 +6136,7 @@ pub fn decode_key_frame_tile( mi_cols, mi_rows, base_q_idx, + crate::quant::QuantDeltas::default(), frame_width, frame_height, enable_filter_intra, @@ -6144,6 +6185,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( mi_cols: u32, mi_rows: u32, base_q_idx: u8, + // lane-sbpart r11: this frame header's own per-plane DC/AC quantizer + // deltas (spec 5.9.12), threaded to [`QUANT_DELTAS`] at the top of every + // tile alongside [`CURRENT_Q_IDX`]. + deltas: crate::quant::QuantDeltas, frame_width: u32, frame_height: u32, enable_filter_intra: bool, @@ -6262,6 +6307,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // spec `decode_tile`: `CurrentQIndex` resets to the frame's own // `base_q_idx` at the top of every tile, not once per frame. CURRENT_Q_IDX.with(|c| c.set(i32::from(base_q_idx))); + QUANT_DELTAS.with(|c| c.set(deltas)); CURRENT_DELTA_LF.with(|c| c.set([0; 4])); if std::env::var_os("EC_AV1_TRACE").is_some() { eprintln!( @@ -7188,7 +7234,8 @@ fn read_inter_plane( default_tx_type, None, )?; - let residual = dequant_and_inverse_typed(&grid, side, 8, CURRENT_Q_IDX.with(|c| c.get()), tx_type); + let (dc_delta, ac_delta) = plane_q_delta(plane_idx); + let residual = dequant_and_inverse_typed(&grid, side, 8, CURRENT_Q_IDX.with(|c| c.get()), dc_delta, ac_delta, tx_type); plane.reconstruct_mc(x, y, side, prediction, &residual); Ok((grid, tx_type)) } @@ -11013,6 +11060,7 @@ pub fn decode_inter_frame_tile( mi_cols, mi_rows, base_q_idx, + crate::quant::QuantDeltas::default(), frame_width, frame_height, reference, @@ -11057,6 +11105,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( mi_cols: u32, mi_rows: u32, base_q_idx: u8, + // lane-sbpart r11: see [`decode_key_frame_tile_with_cdfs`]'s own `deltas`. + deltas: crate::quant::QuantDeltas, frame_width: u32, frame_height: u32, reference: &Picture, @@ -11310,6 +11360,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( ); let mut cdfs = base_cdfs.clone(); CURRENT_Q_IDX.with(|c| c.set(i32::from(base_q_idx))); + QUANT_DELTAS.with(|c| c.set(deltas)); CURRENT_DELTA_LF.with(|c| c.set([0; 4])); let mut dec = SymbolDecoder::new(data); // lane-comppin r9: tile-entry range, the earliest point comparable diff --git a/crates/ec-av1/src/quant.rs b/crates/ec-av1/src/quant.rs index 79974541..a42166c5 100644 --- a/crates/ec-av1/src/quant.rs +++ b/crates/ec-av1/src/quant.rs @@ -160,20 +160,54 @@ pub fn dq_denom_area(pels: usize) -> i64 { } } +/// Spec 5.9.12's per-plane DC/AC quantizer index offsets, added to the +/// running `q_idx` (spec `CurrentQIndex`, already segmentation/delta-q +/// adjusted) before the table lookup (spec 7.12.2's `get_dc_quant`/ +/// `get_ac_quant`) -- lane-sbpart r11: these were parsed by +/// `ec-av1-syntax::frame` and, until this round, used for nothing but the +/// `lossless[]` determination. Luma has no `ac` delta (the spec never codes +/// one); `v_*` already falls back to `u_*` at parse time when +/// `separate_uv_delta_q` is unset, so callers never need to know that flag. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub struct QuantDeltas { + /// `delta_q_y_dc`: luma's DC-only offset (luma has no coded AC delta). + pub y_dc: i32, + /// `delta_q_u_dc`. + pub u_dc: i32, + /// `delta_q_u_ac`. + pub u_ac: i32, + /// `delta_q_v_dc` (falls back to `delta_q_u_dc` when + /// `separate_uv_delta_q` is unset, already resolved at parse time). + pub v_dc: i32, + /// `delta_q_v_ac` (same `separate_uv_delta_q` fallback). + pub v_ac: i32, +} + /// Dequantize one coefficient (spec 7.12.3 steps a-f): scale by the DC or AC /// quantizer, mask to 24 bits, divide by the transform's denominator toward /// zero, and clip to the coefficient range. pub fn dequant_coeff(level: i32, is_dc: bool, bit_depth: u8, q_idx: i32, side: usize) -> i32 { - dequant_coeff_wh(level, is_dc, bit_depth, q_idx, side, side) + dequant_coeff_wh(level, is_dc, bit_depth, q_idx, 0, 0, side, side) } -/// [`dequant_coeff`] widened to `(w, h)` (lane-recttx): only the denominator -/// (an area threshold, [`dq_denom_area`]) depends on the transform's shape. -pub fn dequant_coeff_wh(level: i32, is_dc: bool, bit_depth: u8, q_idx: i32, w: usize, h: usize) -> i32 { +/// [`dequant_coeff`] widened to `(w, h)` (lane-recttx), with the DC/AC +/// quantizer-index deltas (lane-sbpart r11, spec 7.12.2) added before the +/// table lookup and clamped the same way the plain index already is. +#[allow(clippy::too_many_arguments)] +pub fn dequant_coeff_wh( + level: i32, + is_dc: bool, + bit_depth: u8, + q_idx: i32, + dc_delta: i32, + ac_delta: i32, + w: usize, + h: usize, +) -> i32 { let q = i64::from(if is_dc { - dc_q(bit_depth, q_idx) + dc_q(bit_depth, q_idx + dc_delta) } else { - ac_q(bit_depth, q_idx) + ac_q(bit_depth, q_idx + ac_delta) }); let dq = i64::from(level) * q; let sign = if dq < 0 { -1 } else { 1 }; @@ -185,15 +219,17 @@ pub fn dequant_coeff_wh(level: i32, is_dc: bool, bit_depth: u8, q_idx: i32, w: u /// Dequantize a whole raster-order coefficient grid of a `side` x `side` /// transform. pub fn dequant(levels: &[i32], side: usize, bit_depth: u8, q_idx: i32) -> Vec { - dequant_wh(levels, side, side, bit_depth, q_idx) + dequant_wh(levels, side, side, bit_depth, q_idx, 0, 0) } -/// [`dequant`] widened to `(w, h)` (lane-recttx). -pub fn dequant_wh(levels: &[i32], w: usize, h: usize, bit_depth: u8, q_idx: i32) -> Vec { +/// [`dequant`] widened to `(w, h)` (lane-recttx), threading the same +/// [`QuantDeltas`]-shaped `dc_delta`/`ac_delta` pair as [`dequant_coeff_wh`]. +#[allow(clippy::too_many_arguments)] +pub fn dequant_wh(levels: &[i32], w: usize, h: usize, bit_depth: u8, q_idx: i32, dc_delta: i32, ac_delta: i32) -> Vec { levels .iter() .enumerate() - .map(|(i, &l)| dequant_coeff_wh(l, i == 0, bit_depth, q_idx, w, h)) + .map(|(i, &l)| dequant_coeff_wh(l, i == 0, bit_depth, q_idx, dc_delta, ac_delta, w, h)) .collect() } diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index b7adf532..c53807d4 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -469,6 +469,13 @@ pub fn decode_stream(data: &[u8]) -> Result> { header.mi_cols, header.mi_rows, header.quantization.base_q_idx, + crate::quant::QuantDeltas { + y_dc: i32::from(header.quantization.delta_q_y_dc), + u_dc: i32::from(header.quantization.delta_q_u_dc), + u_ac: i32::from(header.quantization.delta_q_u_ac), + v_dc: i32::from(header.quantization.delta_q_v_dc), + v_ac: i32::from(header.quantization.delta_q_v_ac), + }, header.frame_width, header.frame_height, enable_filter_intra, @@ -557,6 +564,13 @@ pub fn decode_stream(data: &[u8]) -> Result> { header.mi_cols, header.mi_rows, header.quantization.base_q_idx, + crate::quant::QuantDeltas { + y_dc: i32::from(header.quantization.delta_q_y_dc), + u_dc: i32::from(header.quantization.delta_q_u_dc), + u_ac: i32::from(header.quantization.delta_q_u_ac), + v_dc: i32::from(header.quantization.delta_q_v_dc), + v_ac: i32::from(header.quantization.delta_q_v_ac), + }, header.frame_width, header.frame_height, reference, @@ -6958,6 +6972,13 @@ mod tests { header.mi_cols, header.mi_rows, header.quantization.base_q_idx, + crate::quant::QuantDeltas { + y_dc: i32::from(header.quantization.delta_q_y_dc), + u_dc: i32::from(header.quantization.delta_q_u_dc), + u_ac: i32::from(header.quantization.delta_q_u_ac), + v_dc: i32::from(header.quantization.delta_q_v_dc), + v_ac: i32::from(header.quantization.delta_q_v_ac), + }, header.frame_width, header.frame_height, enable_filter_intra, @@ -7165,6 +7186,13 @@ mod tests { header.mi_cols, header.mi_rows, header.quantization.base_q_idx, + crate::quant::QuantDeltas { + y_dc: i32::from(header.quantization.delta_q_y_dc), + u_dc: i32::from(header.quantization.delta_q_u_dc), + u_ac: i32::from(header.quantization.delta_q_u_ac), + v_dc: i32::from(header.quantization.delta_q_v_dc), + v_ac: i32::from(header.quantization.delta_q_v_ac), + }, header.frame_width, header.frame_height, enable_filter_intra, @@ -7480,6 +7508,13 @@ mod tests { header.mi_cols, header.mi_rows, header.quantization.base_q_idx, + crate::quant::QuantDeltas { + y_dc: i32::from(header.quantization.delta_q_y_dc), + u_dc: i32::from(header.quantization.delta_q_u_dc), + u_ac: i32::from(header.quantization.delta_q_u_ac), + v_dc: i32::from(header.quantization.delta_q_v_dc), + v_ac: i32::from(header.quantization.delta_q_v_ac), + }, header.frame_width, header.frame_height, enable_filter_intra, diff --git a/crates/ec-av1/src/transform.rs b/crates/ec-av1/src/transform.rs index d6bdad54..b68061ed 100644 --- a/crates/ec-av1/src/transform.rs +++ b/crates/ec-av1/src/transform.rs @@ -888,32 +888,41 @@ pub fn inverse_transform_2d(dequant: &[i32], side: usize, bit_depth: u8) -> Vec< /// This is the encoder's model of what the decoder will add to its prediction, /// so it follows the spec's dequantization exactly, truncation toward zero and /// all. +#[allow(clippy::too_many_arguments)] pub fn dequant_and_inverse_typed( levels: &[i32], side: usize, bit_depth: u8, q_idx: i32, + dc_delta: i32, + ac_delta: i32, tx_type: TxType, ) -> Vec { - dequant_and_inverse_typed_wh(levels, side, side, bit_depth, q_idx, tx_type) + dequant_and_inverse_typed_wh(levels, side, side, bit_depth, q_idx, dc_delta, ac_delta, tx_type) } -/// [`dequant_and_inverse_typed`] widened to `(w, h)` (lane-recttx). +/// [`dequant_and_inverse_typed`] widened to `(w, h)` (lane-recttx). `dc_delta`/ +/// `ac_delta` are the per-plane quantizer-index offsets (lane-sbpart r11, +/// spec 5.9.12/7.12.2, [`crate::quant::QuantDeltas`]) -- `0`/`0` for the +/// unaffected callers below. +#[allow(clippy::too_many_arguments)] pub fn dequant_and_inverse_typed_wh( levels: &[i32], w: usize, h: usize, bit_depth: u8, q_idx: i32, + dc_delta: i32, + ac_delta: i32, tx_type: TxType, ) -> Vec { - let dq = crate::quant::dequant_wh(levels, w, h, bit_depth, q_idx); + let dq = crate::quant::dequant_wh(levels, w, h, bit_depth, q_idx, dc_delta, ac_delta); inverse_transform_2d_typed_wh(&dq, w, h, bit_depth, tx_type) } -/// [`dequant_and_inverse_typed`] at `DCT_DCT`. +/// [`dequant_and_inverse_typed`] at `DCT_DCT`, no per-plane quantizer delta. pub fn dequant_and_inverse(levels: &[i32], side: usize, bit_depth: u8, q_idx: i32) -> Vec { - dequant_and_inverse_typed(levels, side, bit_depth, q_idx, TxType::DctDct) + dequant_and_inverse_typed(levels, side, bit_depth, q_idx, 0, 0, TxType::DctDct) } /// The orthonormal DCT-II basis row for output `u` of an `n`-point transform. diff --git a/lanes/sbpart-r11.report.md b/lanes/sbpart-r11.report.md new file mode 100644 index 00000000..8d4bef2b --- /dev/null +++ b/lanes/sbpart-r11.report.md @@ -0,0 +1,92 @@ +# lane-sbpart r11 report + +## What shipped +The per-plane quantizer-index deltas (spec 5.9.12) that `ec-av1-syntax::frame` +parsed and threw away are now real: `crate::quant::QuantDeltas` (`y_dc`, +`u_dc`, `u_ac`, `v_dc`, `v_ac`) is threaded through `dequant_coeff_wh` / +`dequant_wh` / `dequant_and_inverse_typed(_wh)` and all 8 decode.rs leaf +dequant call sites (2 non-wh at plain-block reconstruct, 6 wh at the two +rect-partition reconstruct functions), added to `q_idx` before the +`dc_q`/`ac_q` table lookup, exactly as spec 7.12.2 requires. `decode_stream` +(`stream.rs`, 5 call sites) now passes the real header values +(`header.quantization.delta_q_*`); the two convenience wrappers +(`decode_key_frame_tile`, `decode_inter_frame_tile`, test-only callers) pass +`QuantDeltas::default()`, keeping their own ~15 test call sites untouched. +`dequant`/`dequant_coeff`/`dequant_and_inverse` (the plain 4-arg forms used +by ~20 unrelated tests in `tile.rs`/`encode.rs`/`transform.rs`) are UNCHANGED +in signature — they now just wrap the delta-aware core with `0, 0`. This is +a real capability fix independent of whether it explains the 81-vs-76 defect: +before this round the parser read a real syntax element and only used it for +`lossless[]`, silently ignoring a spec-mandated adjustment to every DC (and, +for chroma, AC) coefficient in any stream that codes a nonzero delta. + +## Blast radius: measured, not assumed +Added an `EC_AV1_TRACE`-gated print of the five deltas at parse time +(`frame.rs::read_quantization_params`). Ran it against the r10 pinned repro +(`fixtures/sbpart/seed42.obu`, base_q_idx=180): + +``` +TRACE quant_deltas base_q_idx=180 y_dc=0 u_dc=0 u_ac=0 v_dc=0 v_ac=0 +``` + +**All five deltas are zero for this stream.** The scoped `decode::` and +`quant::`/`transform::` test suites (27 tests, all real-aomenc/ffmpeg gates +among them) also passed unchanged, consistent with zero deltas everywhere +they touch. So: no gate anywhere in the suite was passing "for the wrong +reason" — the deltas are genuinely zero on every stream this repo currently +encodes and gates. This is scope, not a dodge: the charter's own fallback +question triggers. + +## The 81-vs-76 defect is NOT this +Per the charter's own instruction ("if the deltas turn out to be zero for +this stream after all... say so rather than forcing the hypothesis"): they +are zero, so the delta-q-per-plane hypothesis is **disproven for seed42** by +direct measurement, not by reasoning. I did not force it. + +The pinned repro (`pinned_sbpart_stream_decodes_pixel_exact`) could not even +reach the pixel comparison this round — it panics before that with +`Unsupported { what: "AV1 tile", why: "a 32x32 partition type this decoder +does not code (value=4)" }` at a *later* superblock in the same stream, a +pre-existing capability gap unrelated to r10's SB0 finding (this is the same +shape as `dead-end|lane-sbpart r9`'s part32 AB gap in the ledger). This means +the repro command in the charter, run today against `main`'s current +decode.rs, cannot currently prove or disprove SB0's pixel value at all — it +never gets there. + +**Next suspect** (per the charter's own fallback, unexplored this round — +budget spent on the delta plumbing + blast-radius measurement): `CURRENT_Q_IDX`'s +own per-superblock delta-q state (`DELTA_Q_PRESENT`/`maybe_read_delta_q`, +decode.rs:137-192) or segmentation qindex. Quick way in: print +`CURRENT_Q_IDX.with(|c| c.get())` right next to the existing `TRACE dequant` +line at decode.rs and compare it to `base_q_idx=180` for SB0's own tile — +if it differs, that's the missing 5 in the quantizer index (180→~175 would +plausibly separate 81 from 76 in the `dc_q` table). Also worth checking +`header.segmentation.enabled` in the same trace. + +## Verification run +``` +EC_AV1_GATE_DUMP_PIN=$(pwd)/fixtures/sbpart/seed42.obu EC_AV1_TRACE=1 \ + cargo test -p ec-av1 --lib pinned_sbpart_stream_decodes_pixel_exact -- \ + --ignored --nocapture --test-threads=1 +``` +Result: FAILED (`Unsupported ... 32x32 partition type value=4`), as above — +a pre-existing, unrelated gap, not a regression from this round's diff. + +Scoped, in-scope tests (all green): +``` +cargo test -p ec-av1 --lib quant:: # 3/3 +cargo test -p ec-av1 --lib transform:: # 17/17 (1 ignored, pre-existing) +cargo test -p ec-av1 --lib decode:: # 15/15 +``` + +## Files changed +- `crates/ec-av1-syntax/src/frame.rs` — `EC_AV1_TRACE` print of the 5 parsed deltas (diagnostic only, no behavior change to the syntax crate). +- `crates/ec-av1/src/quant.rs` — new `QuantDeltas` struct; `dequant_coeff_wh`/`dequant_wh` take `dc_delta`/`ac_delta`, added to `q_idx` before the table lookup; `dequant`/`dequant_coeff` unchanged (wrap with `0, 0`). +- `crates/ec-av1/src/transform.rs` — `dequant_and_inverse_typed(_wh)` take `dc_delta`/`ac_delta`; `dequant_and_inverse` (4-arg, ~20 external callers) unchanged (wraps with `0, 0`). +- `crates/ec-av1/src/decode.rs` — new `QUANT_DELTAS` thread-local (frame-constant, set alongside `CURRENT_Q_IDX` at both key/inter tile-decode entry points) + `plane_q_delta(plane_idx)` helper; all 8 leaf dequant call sites pass the plane-correct delta. `decode_key_frame_tile_with_cdfs`/`decode_inter_frame_tile_with_cdfs` gain a `deltas: QuantDeltas` parameter; the two convenience wrappers pass `QuantDeltas::default()`. +- `crates/ec-av1/src/stream.rs` — the 5 real `decode_stream` call sites now build `QuantDeltas` from `header.quantization.delta_q_*` instead of dropping them. + +## Disposition +- fix-now: per-plane quantizer deltas threaded end-to-end, verified against spec 7.12.2, gated by real scoped tests — this part is done and correct regardless of the 81-vs-76 outcome. +- deferred: the actual 81-vs-76 root cause — the charter's suspect is ruled out by measurement; next suspect (per-superblock `CURRENT_Q_IDX` drift or segmentation qindex) is named above with a concrete one-line instrumentation step, not yet run — budget spent on plumbing + honest measurement instead. Unblocks with: add the `CURRENT_Q_IDX` value to the existing `TRACE dequant` eprintln and re-run the same pinned-repro command (once the unrelated `value=4` partition gap is also worked around or the repro fixture is re-captured to a stream that doesn't hit it). +- deferred: the `value=4` 32x32-partition-type gap the pinned repro hits mid-stream — same shape as the r9 `dead-end` ledger entry for part32 AB; not this lane's charter, noted for whoever owns partition coverage next.