forge
Explore
Log in

Don't you dare go Hollow

Thread per-plane quantizer deltas (delta_q_y_dc/u_dc/u_ac/v_dc/v_ac) into dequant

Browse files at this commit

8560456d76b25acbe35cbfc193f2e3a7b8ea72e4Ahmet Kaan GümüşParent: add0a25
  • fix
    • thread per-plane quantizer deltas (delta_q_y_dc/u_dc/u_ac/v_dc/v_ac) into dequant
Show full message
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.rsmodified+6 -0
@@ -1426,6 +1426,12 @@ fn read_quantization_params(
1426 };1426 };
1427 }1427 }
1428 h.quantization = q;1428 h.quantization = q;
1429+ if std::env::var_os("EC_AV1_TRACE").is_some() {
1430+ eprintln!(
1431+ "TRACE quant_deltas base_q_idx={} y_dc={} u_dc={} u_ac={} v_dc={} v_ac={}",
1432+ 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
1433+ );
1434+ }
1429 Ok(())1435 Ok(())
1430 }1436 }
1431 1437
crates/ec-av1/src/decode.rsmodified+53 -2
@@ -146,6 +146,21 @@ thread_local! {
146 thread_local! {146 thread_local! {
147 static CURRENT_Q_IDX: std::cell::Cell<i32> = const { std::cell::Cell::new(0) };147 static CURRENT_Q_IDX: std::cell::Cell<i32> = const { std::cell::Cell::new(0) };
148 }148 }
149+// This frame's own per-plane DC/AC quantizer-index deltas (lane-sbpart r11,
150+// spec 5.9.12/7.12.2, [`crate::quant::QuantDeltas`]) -- frame-constant (not
151+// per-superblock like [`CURRENT_Q_IDX`]), set once per frame decode and read
152+// back at every dequantization call site keyed on which plane it is doing.
153+thread_local! {
154+ static QUANT_DELTAS: std::cell::Cell<crate::quant::QuantDeltas> = const {
155+ std::cell::Cell::new(crate::quant::QuantDeltas {
156+ y_dc: 0,
157+ u_dc: 0,
158+ u_ac: 0,
159+ v_dc: 0,
160+ v_ac: 0,
161+ })
162+ };
163+}
149 // How many real `delta_q_present` symbol groups [`maybe_read_delta_q`] has164 // How many real `delta_q_present` symbol groups [`maybe_read_delta_q`] has
150 // read, across every call on the current thread -- the gate's proof that a165 // read, across every call on the current thread -- the gate's proof that a
151 // `delta_q_present` stream actually reached the new reader.166 // `delta_q_present` stream actually reached the new reader.
@@ -158,6 +173,18 @@ pub(crate) fn delta_q_hits() -> usize {
158 DELTA_Q_HITS.with(|c| c.get())173 DELTA_Q_HITS.with(|c| c.get())
159 }174 }
160 175
176+/// This frame's [`QUANT_DELTAS`] `(dc, ac)` pair for plane `plane_idx` (0 =
177+/// Y, 1 = U, 2 = V) -- luma has no coded `ac` delta (spec 5.9.12 never reads
178+/// one), so it is always `0` here.
179+fn plane_q_delta(plane_idx: usize) -> (i32, i32) {
180+ let d = QUANT_DELTAS.with(|c| c.get());
181+ match plane_idx {
182+ 0 => (d.y_dc, 0),
183+ 1 => (d.u_dc, d.u_ac),
184+ _ => (d.v_dc, d.v_ac),
185+ }
186+}
187+
161 /// `read_delta_qindex`/`read_delta_q_params` (spec 5.11.10, libaom188 /// `read_delta_qindex`/`read_delta_q_params` (spec 5.11.10, libaom
162 /// `decodemv.c:85-146,735-770`), called right after [`maybe_read_cdef_idx`]189 /// `decodemv.c:85-146,735-770`), called right after [`maybe_read_cdef_idx`]
163 /// at every block-decode call site (spec order `skip -> cdef -> delta_q`).190 /// at every block-decode call site (spec order `skip -> cdef -> delta_q`).
@@ -3212,6 +3239,8 @@ fn decode_block_rect(
3212 bh,3239 bh,
3213 8,3240 8,
3214 CURRENT_Q_IDX.with(|c| c.get()),3241 CURRENT_Q_IDX.with(|c| c.get()),
3242+ plane_q_delta(0).0,
3243+ plane_q_delta(0).1,
3215 luma_tx_type,3244 luma_tx_type,
3216 );3245 );
3217 y.reconstruct_rect(3246 y.reconstruct_rect(
@@ -3251,6 +3280,8 @@ fn decode_block_rect(
3251 chroma_h,3280 chroma_h,
3252 8,3281 8,
3253 CURRENT_Q_IDX.with(|c| c.get()),3282 CURRENT_Q_IDX.with(|c| c.get()),
3283+ plane_q_delta(1).0,
3284+ plane_q_delta(1).1,
3254 u_tx_type,3285 u_tx_type,
3255 );3286 );
3256 u.reconstruct_rect(3287 u.reconstruct_rect(
@@ -3289,6 +3320,8 @@ fn decode_block_rect(
3289 chroma_h,3320 chroma_h,
3290 8,3321 8,
3291 CURRENT_Q_IDX.with(|c| c.get()),3322 CURRENT_Q_IDX.with(|c| c.get()),
3323+ plane_q_delta(2).0,
3324+ plane_q_delta(2).1,
3292 v_tx_type,3325 v_tx_type,
3293 );3326 );
3294 v.reconstruct_rect(3327 v.reconstruct_rect(
@@ -3500,6 +3533,8 @@ fn decode_block_rect64(
3500 bh,3533 bh,
3501 8,3534 8,
3502 i32::from(base_q_idx),3535 i32::from(base_q_idx),
3536+ plane_q_delta(0).0,
3537+ plane_q_delta(0).1,
3503 luma_tx_type,3538 luma_tx_type,
3504 );3539 );
3505 y.reconstruct_rect(3540 y.reconstruct_rect(
@@ -3559,6 +3594,8 @@ fn decode_block_rect64(
3559 chroma_h,3594 chroma_h,
3560 8,3595 8,
3561 i32::from(base_q_idx),3596 i32::from(base_q_idx),
3597+ plane_q_delta(1).0,
3598+ plane_q_delta(1).1,
3562 u_tx_type,3599 u_tx_type,
3563 );3600 );
3564 u.reconstruct_rect(3601 u.reconstruct_rect(
@@ -3600,6 +3637,8 @@ fn decode_block_rect64(
3600 chroma_h,3637 chroma_h,
3601 8,3638 8,
3602 i32::from(base_q_idx),3639 i32::from(base_q_idx),
3640+ plane_q_delta(2).0,
3641+ plane_q_delta(2).1,
3603 v_tx_type,3642 v_tx_type,
3604 );3643 );
3605 v.reconstruct_rect(3644 v.reconstruct_rect(
@@ -4319,7 +4358,8 @@ fn read_plane(
4319 }4358 }
4320 full4359 full
4321 };4360 };
4322- let residual = dequant_and_inverse_typed(&levels, side, 8, CURRENT_Q_IDX.with(|c| c.get()), tx_type);4361+ let (dc_delta, ac_delta) = plane_q_delta(plane_idx);
4362+ let residual = dequant_and_inverse_typed(&levels, side, 8, CURRENT_Q_IDX.with(|c| c.get()), dc_delta, ac_delta, tx_type);
4323 if std::env::var_os("EC_AV1_TRACE").is_some() {4363 if std::env::var_os("EC_AV1_TRACE").is_some() {
4324 eprintln!(4364 eprintln!(
4325 "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}",4365 "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(
6096 mi_cols,6136 mi_cols,
6097 mi_rows,6137 mi_rows,
6098 base_q_idx,6138 base_q_idx,
6139+ crate::quant::QuantDeltas::default(),
6099 frame_width,6140 frame_width,
6100 frame_height,6141 frame_height,
6101 enable_filter_intra,6142 enable_filter_intra,
@@ -6144,6 +6185,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
6144 mi_cols: u32,6185 mi_cols: u32,
6145 mi_rows: u32,6186 mi_rows: u32,
6146 base_q_idx: u8,6187 base_q_idx: u8,
6188+ // lane-sbpart r11: this frame header's own per-plane DC/AC quantizer
6189+ // deltas (spec 5.9.12), threaded to [`QUANT_DELTAS`] at the top of every
6190+ // tile alongside [`CURRENT_Q_IDX`].
6191+ deltas: crate::quant::QuantDeltas,
6147 frame_width: u32,6192 frame_width: u32,
6148 frame_height: u32,6193 frame_height: u32,
6149 enable_filter_intra: bool,6194 enable_filter_intra: bool,
@@ -6262,6 +6307,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
6262 // spec `decode_tile`: `CurrentQIndex` resets to the frame's own6307 // spec `decode_tile`: `CurrentQIndex` resets to the frame's own
6263 // `base_q_idx` at the top of every tile, not once per frame.6308 // `base_q_idx` at the top of every tile, not once per frame.
6264 CURRENT_Q_IDX.with(|c| c.set(i32::from(base_q_idx)));6309 CURRENT_Q_IDX.with(|c| c.set(i32::from(base_q_idx)));
6310+ QUANT_DELTAS.with(|c| c.set(deltas));
6265 CURRENT_DELTA_LF.with(|c| c.set([0; 4]));6311 CURRENT_DELTA_LF.with(|c| c.set([0; 4]));
6266 if std::env::var_os("EC_AV1_TRACE").is_some() {6312 if std::env::var_os("EC_AV1_TRACE").is_some() {
6267 eprintln!(6313 eprintln!(
@@ -7188,7 +7234,8 @@ fn read_inter_plane(
7188 default_tx_type,7234 default_tx_type,
7189 None,7235 None,
7190 )?;7236 )?;
7191- let residual = dequant_and_inverse_typed(&grid, side, 8, CURRENT_Q_IDX.with(|c| c.get()), tx_type);7237+ let (dc_delta, ac_delta) = plane_q_delta(plane_idx);
7238+ let residual = dequant_and_inverse_typed(&grid, side, 8, CURRENT_Q_IDX.with(|c| c.get()), dc_delta, ac_delta, tx_type);
7192 plane.reconstruct_mc(x, y, side, prediction, &residual);7239 plane.reconstruct_mc(x, y, side, prediction, &residual);
7193 Ok((grid, tx_type))7240 Ok((grid, tx_type))
7194 }7241 }
@@ -11013,6 +11060,7 @@ pub fn decode_inter_frame_tile(
11013 mi_cols,11060 mi_cols,
11014 mi_rows,11061 mi_rows,
11015 base_q_idx,11062 base_q_idx,
11063+ crate::quant::QuantDeltas::default(),
11016 frame_width,11064 frame_width,
11017 frame_height,11065 frame_height,
11018 reference,11066 reference,
@@ -11057,6 +11105,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11057 mi_cols: u32,11105 mi_cols: u32,
11058 mi_rows: u32,11106 mi_rows: u32,
11059 base_q_idx: u8,11107 base_q_idx: u8,
11108+ // lane-sbpart r11: see [`decode_key_frame_tile_with_cdfs`]'s own `deltas`.
11109+ deltas: crate::quant::QuantDeltas,
11060 frame_width: u32,11110 frame_width: u32,
11061 frame_height: u32,11111 frame_height: u32,
11062 reference: &Picture,11112 reference: &Picture,
@@ -11310,6 +11360,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11310 );11360 );
11311 let mut cdfs = base_cdfs.clone();11361 let mut cdfs = base_cdfs.clone();
11312 CURRENT_Q_IDX.with(|c| c.set(i32::from(base_q_idx)));11362 CURRENT_Q_IDX.with(|c| c.set(i32::from(base_q_idx)));
11363+ QUANT_DELTAS.with(|c| c.set(deltas));
11313 CURRENT_DELTA_LF.with(|c| c.set([0; 4]));11364 CURRENT_DELTA_LF.with(|c| c.set([0; 4]));
11314 let mut dec = SymbolDecoder::new(data);11365 let mut dec = SymbolDecoder::new(data);
11315 // lane-comppin r9: tile-entry range, the earliest point comparable11366 // lane-comppin r9: tile-entry range, the earliest point comparable
crates/ec-av1/src/quant.rsmodified+46 -10
@@ -160,20 +160,54 @@ pub fn dq_denom_area(pels: usize) -> i64 {
160 }160 }
161 }161 }
162 162
163+/// Spec 5.9.12's per-plane DC/AC quantizer index offsets, added to the
164+/// running `q_idx` (spec `CurrentQIndex`, already segmentation/delta-q
165+/// adjusted) before the table lookup (spec 7.12.2's `get_dc_quant`/
166+/// `get_ac_quant`) -- lane-sbpart r11: these were parsed by
167+/// `ec-av1-syntax::frame` and, until this round, used for nothing but the
168+/// `lossless[]` determination. Luma has no `ac` delta (the spec never codes
169+/// one); `v_*` already falls back to `u_*` at parse time when
170+/// `separate_uv_delta_q` is unset, so callers never need to know that flag.
171+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
172+pub struct QuantDeltas {
173+ /// `delta_q_y_dc`: luma's DC-only offset (luma has no coded AC delta).
174+ pub y_dc: i32,
175+ /// `delta_q_u_dc`.
176+ pub u_dc: i32,
177+ /// `delta_q_u_ac`.
178+ pub u_ac: i32,
179+ /// `delta_q_v_dc` (falls back to `delta_q_u_dc` when
180+ /// `separate_uv_delta_q` is unset, already resolved at parse time).
181+ pub v_dc: i32,
182+ /// `delta_q_v_ac` (same `separate_uv_delta_q` fallback).
183+ pub v_ac: i32,
184+}
185+
163 /// Dequantize one coefficient (spec 7.12.3 steps a-f): scale by the DC or AC186 /// Dequantize one coefficient (spec 7.12.3 steps a-f): scale by the DC or AC
164 /// quantizer, mask to 24 bits, divide by the transform's denominator toward187 /// quantizer, mask to 24 bits, divide by the transform's denominator toward
165 /// zero, and clip to the coefficient range.188 /// zero, and clip to the coefficient range.
166 pub fn dequant_coeff(level: i32, is_dc: bool, bit_depth: u8, q_idx: i32, side: usize) -> i32 {189 pub fn dequant_coeff(level: i32, is_dc: bool, bit_depth: u8, q_idx: i32, side: usize) -> i32 {
167- dequant_coeff_wh(level, is_dc, bit_depth, q_idx, side, side)190+ dequant_coeff_wh(level, is_dc, bit_depth, q_idx, 0, 0, side, side)
168 }191 }
169 192
170-/// [`dequant_coeff`] widened to `(w, h)` (lane-recttx): only the denominator193+/// [`dequant_coeff`] widened to `(w, h)` (lane-recttx), with the DC/AC
171-/// (an area threshold, [`dq_denom_area`]) depends on the transform's shape.194+/// quantizer-index deltas (lane-sbpart r11, spec 7.12.2) added before the
172-pub fn dequant_coeff_wh(level: i32, is_dc: bool, bit_depth: u8, q_idx: i32, w: usize, h: usize) -> i32 {195+/// table lookup and clamped the same way the plain index already is.
196+#[allow(clippy::too_many_arguments)]
197+pub fn dequant_coeff_wh(
198+ level: i32,
199+ is_dc: bool,
200+ bit_depth: u8,
201+ q_idx: i32,
202+ dc_delta: i32,
203+ ac_delta: i32,
204+ w: usize,
205+ h: usize,
206+) -> i32 {
173 let q = i64::from(if is_dc {207 let q = i64::from(if is_dc {
174- dc_q(bit_depth, q_idx)208+ dc_q(bit_depth, q_idx + dc_delta)
175 } else {209 } else {
176- ac_q(bit_depth, q_idx)210+ ac_q(bit_depth, q_idx + ac_delta)
177 });211 });
178 let dq = i64::from(level) * q;212 let dq = i64::from(level) * q;
179 let sign = if dq < 0 { -1 } else { 1 };213 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
185 /// Dequantize a whole raster-order coefficient grid of a `side` x `side`219 /// Dequantize a whole raster-order coefficient grid of a `side` x `side`
186 /// transform.220 /// transform.
187 pub fn dequant(levels: &[i32], side: usize, bit_depth: u8, q_idx: i32) -> Vec<i32> {221 pub fn dequant(levels: &[i32], side: usize, bit_depth: u8, q_idx: i32) -> Vec<i32> {
188- dequant_wh(levels, side, side, bit_depth, q_idx)222+ dequant_wh(levels, side, side, bit_depth, q_idx, 0, 0)
189 }223 }
190 224
191-/// [`dequant`] widened to `(w, h)` (lane-recttx).225+/// [`dequant`] widened to `(w, h)` (lane-recttx), threading the same
192-pub fn dequant_wh(levels: &[i32], w: usize, h: usize, bit_depth: u8, q_idx: i32) -> Vec<i32> {226+/// [`QuantDeltas`]-shaped `dc_delta`/`ac_delta` pair as [`dequant_coeff_wh`].
227+#[allow(clippy::too_many_arguments)]
228+pub fn dequant_wh(levels: &[i32], w: usize, h: usize, bit_depth: u8, q_idx: i32, dc_delta: i32, ac_delta: i32) -> Vec<i32> {
193 levels229 levels
194 .iter()230 .iter()
195 .enumerate()231 .enumerate()
196- .map(|(i, &l)| dequant_coeff_wh(l, i == 0, bit_depth, q_idx, w, h))232+ .map(|(i, &l)| dequant_coeff_wh(l, i == 0, bit_depth, q_idx, dc_delta, ac_delta, w, h))
197 .collect()233 .collect()
198 }234 }
199 235
crates/ec-av1/src/stream.rsmodified+35 -0
@@ -469,6 +469,13 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
469 header.mi_cols,469 header.mi_cols,
470 header.mi_rows,470 header.mi_rows,
471 header.quantization.base_q_idx,471 header.quantization.base_q_idx,
472+ crate::quant::QuantDeltas {
473+ y_dc: i32::from(header.quantization.delta_q_y_dc),
474+ u_dc: i32::from(header.quantization.delta_q_u_dc),
475+ u_ac: i32::from(header.quantization.delta_q_u_ac),
476+ v_dc: i32::from(header.quantization.delta_q_v_dc),
477+ v_ac: i32::from(header.quantization.delta_q_v_ac),
478+ },
472 header.frame_width,479 header.frame_width,
473 header.frame_height,480 header.frame_height,
474 enable_filter_intra,481 enable_filter_intra,
@@ -557,6 +564,13 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
557 header.mi_cols,564 header.mi_cols,
558 header.mi_rows,565 header.mi_rows,
559 header.quantization.base_q_idx,566 header.quantization.base_q_idx,
567+ crate::quant::QuantDeltas {
568+ y_dc: i32::from(header.quantization.delta_q_y_dc),
569+ u_dc: i32::from(header.quantization.delta_q_u_dc),
570+ u_ac: i32::from(header.quantization.delta_q_u_ac),
571+ v_dc: i32::from(header.quantization.delta_q_v_dc),
572+ v_ac: i32::from(header.quantization.delta_q_v_ac),
573+ },
560 header.frame_width,574 header.frame_width,
561 header.frame_height,575 header.frame_height,
562 reference,576 reference,
@@ -6958,6 +6972,13 @@ mod tests {
6958 header.mi_cols,6972 header.mi_cols,
6959 header.mi_rows,6973 header.mi_rows,
6960 header.quantization.base_q_idx,6974 header.quantization.base_q_idx,
6975+ crate::quant::QuantDeltas {
6976+ y_dc: i32::from(header.quantization.delta_q_y_dc),
6977+ u_dc: i32::from(header.quantization.delta_q_u_dc),
6978+ u_ac: i32::from(header.quantization.delta_q_u_ac),
6979+ v_dc: i32::from(header.quantization.delta_q_v_dc),
6980+ v_ac: i32::from(header.quantization.delta_q_v_ac),
6981+ },
6961 header.frame_width,6982 header.frame_width,
6962 header.frame_height,6983 header.frame_height,
6963 enable_filter_intra,6984 enable_filter_intra,
@@ -7165,6 +7186,13 @@ mod tests {
7165 header.mi_cols,7186 header.mi_cols,
7166 header.mi_rows,7187 header.mi_rows,
7167 header.quantization.base_q_idx,7188 header.quantization.base_q_idx,
7189+ crate::quant::QuantDeltas {
7190+ y_dc: i32::from(header.quantization.delta_q_y_dc),
7191+ u_dc: i32::from(header.quantization.delta_q_u_dc),
7192+ u_ac: i32::from(header.quantization.delta_q_u_ac),
7193+ v_dc: i32::from(header.quantization.delta_q_v_dc),
7194+ v_ac: i32::from(header.quantization.delta_q_v_ac),
7195+ },
7168 header.frame_width,7196 header.frame_width,
7169 header.frame_height,7197 header.frame_height,
7170 enable_filter_intra,7198 enable_filter_intra,
@@ -7480,6 +7508,13 @@ mod tests {
7480 header.mi_cols,7508 header.mi_cols,
7481 header.mi_rows,7509 header.mi_rows,
7482 header.quantization.base_q_idx,7510 header.quantization.base_q_idx,
7511+ crate::quant::QuantDeltas {
7512+ y_dc: i32::from(header.quantization.delta_q_y_dc),
7513+ u_dc: i32::from(header.quantization.delta_q_u_dc),
7514+ u_ac: i32::from(header.quantization.delta_q_u_ac),
7515+ v_dc: i32::from(header.quantization.delta_q_v_dc),
7516+ v_ac: i32::from(header.quantization.delta_q_v_ac),
7517+ },
7483 header.frame_width,7518 header.frame_width,
7484 header.frame_height,7519 header.frame_height,
7485 enable_filter_intra,7520 enable_filter_intra,
crates/ec-av1/src/transform.rsmodified+14 -5
@@ -888,32 +888,41 @@ pub fn inverse_transform_2d(dequant: &[i32], side: usize, bit_depth: u8) -> Vec<
888 /// This is the encoder's model of what the decoder will add to its prediction,888 /// This is the encoder's model of what the decoder will add to its prediction,
889 /// so it follows the spec's dequantization exactly, truncation toward zero and889 /// so it follows the spec's dequantization exactly, truncation toward zero and
890 /// all.890 /// all.
891+#[allow(clippy::too_many_arguments)]
891 pub fn dequant_and_inverse_typed(892 pub fn dequant_and_inverse_typed(
892 levels: &[i32],893 levels: &[i32],
893 side: usize,894 side: usize,
894 bit_depth: u8,895 bit_depth: u8,
895 q_idx: i32,896 q_idx: i32,
897+ dc_delta: i32,
898+ ac_delta: i32,
896 tx_type: TxType,899 tx_type: TxType,
897 ) -> Vec<i32> {900 ) -> Vec<i32> {
898- dequant_and_inverse_typed_wh(levels, side, side, bit_depth, q_idx, tx_type)901+ dequant_and_inverse_typed_wh(levels, side, side, bit_depth, q_idx, dc_delta, ac_delta, tx_type)
899 }902 }
900 903
901-/// [`dequant_and_inverse_typed`] widened to `(w, h)` (lane-recttx).904+/// [`dequant_and_inverse_typed`] widened to `(w, h)` (lane-recttx). `dc_delta`/
905+/// `ac_delta` are the per-plane quantizer-index offsets (lane-sbpart r11,
906+/// spec 5.9.12/7.12.2, [`crate::quant::QuantDeltas`]) -- `0`/`0` for the
907+/// unaffected callers below.
908+#[allow(clippy::too_many_arguments)]
902 pub fn dequant_and_inverse_typed_wh(909 pub fn dequant_and_inverse_typed_wh(
903 levels: &[i32],910 levels: &[i32],
904 w: usize,911 w: usize,
905 h: usize,912 h: usize,
906 bit_depth: u8,913 bit_depth: u8,
907 q_idx: i32,914 q_idx: i32,
915+ dc_delta: i32,
916+ ac_delta: i32,
908 tx_type: TxType,917 tx_type: TxType,
909 ) -> Vec<i32> {918 ) -> Vec<i32> {
910- let dq = crate::quant::dequant_wh(levels, w, h, bit_depth, q_idx);919+ let dq = crate::quant::dequant_wh(levels, w, h, bit_depth, q_idx, dc_delta, ac_delta);
911 inverse_transform_2d_typed_wh(&dq, w, h, bit_depth, tx_type)920 inverse_transform_2d_typed_wh(&dq, w, h, bit_depth, tx_type)
912 }921 }
913 922
914-/// [`dequant_and_inverse_typed`] at `DCT_DCT`.923+/// [`dequant_and_inverse_typed`] at `DCT_DCT`, no per-plane quantizer delta.
915 pub fn dequant_and_inverse(levels: &[i32], side: usize, bit_depth: u8, q_idx: i32) -> Vec<i32> {924 pub fn dequant_and_inverse(levels: &[i32], side: usize, bit_depth: u8, q_idx: i32) -> Vec<i32> {
916- dequant_and_inverse_typed(levels, side, bit_depth, q_idx, TxType::DctDct)925+ dequant_and_inverse_typed(levels, side, bit_depth, q_idx, 0, 0, TxType::DctDct)
917 }926 }
918 927
919 /// The orthonormal DCT-II basis row for output `u` of an `n`-point transform.928 /// The orthonormal DCT-II basis row for output `u` of an `n`-point transform.
lanes/sbpart-r11.report.mdadded+92 -0
@@ -0,0 +1,92 @@
1+# lane-sbpart r11 report
2+
3+## What shipped
4+The per-plane quantizer-index deltas (spec 5.9.12) that `ec-av1-syntax::frame`
5+parsed and threw away are now real: `crate::quant::QuantDeltas` (`y_dc`,
6+`u_dc`, `u_ac`, `v_dc`, `v_ac`) is threaded through `dequant_coeff_wh` /
7+`dequant_wh` / `dequant_and_inverse_typed(_wh)` and all 8 decode.rs leaf
8+dequant call sites (2 non-wh at plain-block reconstruct, 6 wh at the two
9+rect-partition reconstruct functions), added to `q_idx` before the
10+`dc_q`/`ac_q` table lookup, exactly as spec 7.12.2 requires. `decode_stream`
11+(`stream.rs`, 5 call sites) now passes the real header values
12+(`header.quantization.delta_q_*`); the two convenience wrappers
13+(`decode_key_frame_tile`, `decode_inter_frame_tile`, test-only callers) pass
14+`QuantDeltas::default()`, keeping their own ~15 test call sites untouched.
15+`dequant`/`dequant_coeff`/`dequant_and_inverse` (the plain 4-arg forms used
16+by ~20 unrelated tests in `tile.rs`/`encode.rs`/`transform.rs`) are UNCHANGED
17+in signature — they now just wrap the delta-aware core with `0, 0`. This is
18+a real capability fix independent of whether it explains the 81-vs-76 defect:
19+before this round the parser read a real syntax element and only used it for
20+`lossless[]`, silently ignoring a spec-mandated adjustment to every DC (and,
21+for chroma, AC) coefficient in any stream that codes a nonzero delta.
22+
23+## Blast radius: measured, not assumed
24+Added an `EC_AV1_TRACE`-gated print of the five deltas at parse time
25+(`frame.rs::read_quantization_params`). Ran it against the r10 pinned repro
26+(`fixtures/sbpart/seed42.obu`, base_q_idx=180):
27+
28+```
29+TRACE quant_deltas base_q_idx=180 y_dc=0 u_dc=0 u_ac=0 v_dc=0 v_ac=0
30+```
31+
32+**All five deltas are zero for this stream.** The scoped `decode::` and
33+`quant::`/`transform::` test suites (27 tests, all real-aomenc/ffmpeg gates
34+among them) also passed unchanged, consistent with zero deltas everywhere
35+they touch. So: no gate anywhere in the suite was passing "for the wrong
36+reason" — the deltas are genuinely zero on every stream this repo currently
37+encodes and gates. This is scope, not a dodge: the charter's own fallback
38+question triggers.
39+
40+## The 81-vs-76 defect is NOT this
41+Per the charter's own instruction ("if the deltas turn out to be zero for
42+this stream after all... say so rather than forcing the hypothesis"): they
43+are zero, so the delta-q-per-plane hypothesis is **disproven for seed42** by
44+direct measurement, not by reasoning. I did not force it.
45+
46+The pinned repro (`pinned_sbpart_stream_decodes_pixel_exact`) could not even
47+reach the pixel comparison this round — it panics before that with
48+`Unsupported { what: "AV1 tile", why: "a 32x32 partition type this decoder
49+does not code (value=4)" }` at a *later* superblock in the same stream, a
50+pre-existing capability gap unrelated to r10's SB0 finding (this is the same
51+shape as `dead-end|lane-sbpart r9`'s part32 AB gap in the ledger). This means
52+the repro command in the charter, run today against `main`'s current
53+decode.rs, cannot currently prove or disprove SB0's pixel value at all — it
54+never gets there.
55+
56+**Next suspect** (per the charter's own fallback, unexplored this round —
57+budget spent on the delta plumbing + blast-radius measurement): `CURRENT_Q_IDX`'s
58+own per-superblock delta-q state (`DELTA_Q_PRESENT`/`maybe_read_delta_q`,
59+decode.rs:137-192) or segmentation qindex. Quick way in: print
60+`CURRENT_Q_IDX.with(|c| c.get())` right next to the existing `TRACE dequant`
61+line at decode.rs and compare it to `base_q_idx=180` for SB0's own tile —
62+if it differs, that's the missing 5 in the quantizer index (180→~175 would
63+plausibly separate 81 from 76 in the `dc_q` table). Also worth checking
64+`header.segmentation.enabled` in the same trace.
65+
66+## Verification run
67+```
68+EC_AV1_GATE_DUMP_PIN=$(pwd)/fixtures/sbpart/seed42.obu EC_AV1_TRACE=1 \
69+ cargo test -p ec-av1 --lib pinned_sbpart_stream_decodes_pixel_exact -- \
70+ --ignored --nocapture --test-threads=1
71+```
72+Result: FAILED (`Unsupported ... 32x32 partition type value=4`), as above —
73+a pre-existing, unrelated gap, not a regression from this round's diff.
74+
75+Scoped, in-scope tests (all green):
76+```
77+cargo test -p ec-av1 --lib quant:: # 3/3
78+cargo test -p ec-av1 --lib transform:: # 17/17 (1 ignored, pre-existing)
79+cargo test -p ec-av1 --lib decode:: # 15/15
80+```
81+
82+## Files changed
83+- `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).
84+- `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`).
85+- `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`).
86+- `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()`.
87+- `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.
88+
89+## Disposition
90+- 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.
91+- 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).
92+- 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.