forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-d792' (2fb5e976): six rectangular dequant sites used the frame q index instead of the block's (segment ALT_Q); all 27 dequant sites take the block index now

Browse files at this commit

df5d11d7bd0a1c01fcb469851725dcdde8bfd03eAhmet Kaan GümüşParent: 46b5c0f7da7734
Class: parsed then discarded. Only frame edges force rectangular
partitions in the references' streams, so it read as a bottom-straddle
defect; the 1920x792 reference ladder decodes 8/8 exact.
crates/ec-av1/src/decode.rsmodified+47 -7
@@ -937,10 +937,17 @@ fn seg_feature(segment_id: usize, feature: usize, fctx: &crate::decode::FrameCtx
937 fn block_q_idx(fctx: &crate::decode::FrameCtx) -> i32 {937 fn block_q_idx(fctx: &crate::decode::FrameCtx) -> i32 {
938 let base = fctx.current_q_idx.with(|c| c.get());938 let base = fctx.current_q_idx.with(|c| c.get());
939 let seg_id = fctx.cur_segment_id.with(|c| c.get()) as usize;939 let seg_id = fctx.cur_segment_id.with(|c| c.get()) as usize;
940- match seg_feature(seg_id, SEG_LVL_ALT_Q, fctx) {940+ let q = match seg_feature(seg_id, SEG_LVL_ALT_Q, fctx) {
941 Some(data) => (base + data).clamp(0, 255),941 Some(data) => (base + data).clamp(0, 255),
942 None => base,942 None => base,
943+ };
944+ // lane-d792: which SEGMENT a block's quantizer came out of, beside the
945+ // `EC_DQCOEFF` grid rung -- a dequant that is too low with the levels
946+ // already proven equal is a segment-id defect, not a quantizer one.
947+ if crate::envflags::env_flag!("EC_DQCOEFF") {
948+ eprintln!("OUR_Q base={base} seg={seg_id} q={q}");
943 }949 }
950+ q
944 }951 }
945 952
946 /// The segment id recorded for one mi cell of the current frame's map.953 /// The segment id recorded for one mi cell of the current frame's map.
@@ -6652,6 +6659,19 @@ fn read_coeffs_rect(
6652 };6659 };
6653 grid[pos] = if negative { -level } else { level };6660 grid[pos] = if negative { -level } else { level };
6654 }6661 }
6662+ // lane-d792: the rect unit's LEVEL grid in row-major (w) order, the
6663+ // twin of the oracle's `EC_DQCOEFF` rung -- a residual mismatch whose
6664+ // grids differ is a reader defect, one whose grids agree is a transform
6665+ // defect.
6666+ if crate::envflags::env_flag!("EC_DQCOEFF") {
6667+ let nz: Vec<String> = grid
6668+ .iter()
6669+ .enumerate()
6670+ .filter(|&(_, &v)| v != 0)
6671+ .map(|(i, &v)| format!("{}/{}:{v}", i / w, i % w))
6672+ .collect();
6673+ eprintln!("OUR_LEVELS w={w} h={h} eob={eob} tx={tx_type:?} nz={}", nz.join(","));
6674+ }
6655 Ok((Grid::Own(grid), tx_type))6675 Ok((Grid::Own(grid), tx_type))
6656 }6676 }
6657 6677
@@ -9712,7 +9732,12 @@ fn decode_rect_split(
9712 chroma_w,9732 chroma_w,
9713 chroma_h,9733 chroma_h,
9714 crate::decode::bit_depth(fctx),9734 crate::decode::bit_depth(fctx),
9715- fctx.current_q_idx.with(|c| c.get()),9735+ // lane-d792: the BLOCK's quantizer index, i.e. the frame's
9736+ // own index PLUS this block's segment `SEG_LVL_ALT_Q` --
9737+ // reading `current_q_idx` here dropped the segment feature
9738+ // that every other dequant site applies (class
9739+ // `parsed-then-discarded`).
9740+ block_q_idx(fctx),
9716 plane_q_delta(plane_idx, fctx).0,9741 plane_q_delta(plane_idx, fctx).0,
9717 plane_q_delta(plane_idx, fctx).1,9742 plane_q_delta(plane_idx, fctx).1,
9718 tx_type,9743 tx_type,
@@ -11219,7 +11244,7 @@ fn decode_leaf_rect(
11219 luma_levels = l_levels;11244 luma_levels = l_levels;
11220 let luma_residual = dequant_and_inverse_typed_wh(11245 let luma_residual = dequant_and_inverse_typed_wh(
11221 &luma_levels, bw, bh, crate::decode::bit_depth(fctx),11246 &luma_levels, bw, bh, crate::decode::bit_depth(fctx),
11222- fctx.current_q_idx.with(|c| c.get()), plane_q_delta(0, fctx).0, plane_q_delta(0, fctx).1, luma_tx_type,11247+ block_q_idx(fctx), plane_q_delta(0, fctx).0, plane_q_delta(0, fctx).1, luma_tx_type,
11223 );11248 );
11224 if let Some(b) = &palette_y_buf {11249 if let Some(b) = &palette_y_buf {
11225 set_palette_pred(b.clone(), fctx);11250 set_palette_pred(b.clone(), fctx);
@@ -11239,7 +11264,7 @@ fn decode_leaf_rect(
11239 u_levels = u_l;11264 u_levels = u_l;
11240 let u_residual = dequant_and_inverse_typed_wh(11265 let u_residual = dequant_and_inverse_typed_wh(
11241 &u_levels, chroma_w, chroma_h, crate::decode::bit_depth(fctx),11266 &u_levels, chroma_w, chroma_h, crate::decode::bit_depth(fctx),
11242- fctx.current_q_idx.with(|c| c.get()), plane_q_delta(1, fctx).0, plane_q_delta(1, fctx).1, u_tx_type,11267+ block_q_idx(fctx), plane_q_delta(1, fctx).0, plane_q_delta(1, fctx).1, u_tx_type,
11243 );11268 );
11244 if let Some((ub, _)) = &palette_uv_bufs {11269 if let Some((ub, _)) = &palette_uv_bufs {
11245 set_palette_pred(ub.clone(), fctx);11270 set_palette_pred(ub.clone(), fctx);
@@ -11258,7 +11283,7 @@ fn decode_leaf_rect(
11258 v_levels = v_l;11283 v_levels = v_l;
11259 let v_residual = dequant_and_inverse_typed_wh(11284 let v_residual = dequant_and_inverse_typed_wh(
11260 &v_levels, chroma_w, chroma_h, crate::decode::bit_depth(fctx),11285 &v_levels, chroma_w, chroma_h, crate::decode::bit_depth(fctx),
11261- fctx.current_q_idx.with(|c| c.get()), plane_q_delta(2, fctx).0, plane_q_delta(2, fctx).1, v_tx_type,11286+ block_q_idx(fctx), plane_q_delta(2, fctx).0, plane_q_delta(2, fctx).1, v_tx_type,
11262 );11287 );
11263 if let Some((_, vb)) = &palette_uv_bufs {11288 if let Some((_, vb)) = &palette_uv_bufs {
11264 set_palette_pred(vb.clone(), fctx);11289 set_palette_pred(vb.clone(), fctx);
@@ -13658,6 +13683,17 @@ impl PlaneBuf<'_> {
13658 self.data.to_mut()[(y + row) * self.width + x + col] = sample;13683 self.data.to_mut()[(y + row) * self.width + x + col] = sample;
13659 }13684 }
13660 }13685 }
13686+ // lane-d792: the RECONSTRUCTION rung beside `EC_PRED`'s prediction one
13687+ // -- a block whose prediction matches the oracle's but whose written
13688+ // samples do not is either a residual defect or a later overwrite, and
13689+ // only this print separates the two.
13690+ if crate::envflags::env_flag!("EC_PRED") {
13691+ let row0: Vec<u16> =
13692+ (0..bw.min(8)).map(|c| self.data[y * self.width + x + c]).collect();
13693+ let col0: Vec<u16> =
13694+ (0..bh.min(8)).map(|r| self.data[(y + r) * self.width + x]).collect();
13695+ eprintln!("OUR_RECON x={x} y={y} bw={bw} bh={bh} row0={row0:?} col0={col0:?}");
13696+ }
13661 }13697 }
13662 13698
13663 /// Predicts under `mode` then adds `residual` (side*side, raster),13699 /// Predicts under `mode` then adds `residual` (side*side, raster),
@@ -16211,7 +16247,9 @@ fn decode_leaf_rect8(
16211 bw,16247 bw,
16212 bh,16248 bh,
16213 crate::decode::bit_depth(fctx),16249 crate::decode::bit_depth(fctx),
16214- fctx.current_q_idx.with(|q| q.get()),16250+ // lane-d792 sweep: the block's segment `SEG_LVL_ALT_Q`, as at
16251+ // every other dequant site (class `parsed-then-discarded`).
16252+ block_q_idx(fctx),
16215 plane_q_delta(0, fctx).0,16253 plane_q_delta(0, fctx).0,
16216 plane_q_delta(0, fctx).1,16254 plane_q_delta(0, fctx).1,
16217 tx_type,16255 tx_type,
@@ -31123,7 +31161,9 @@ fn decode_intra_sub8_leaf(
31123 bw,31161 bw,
31124 bh,31162 bh,
31125 crate::decode::bit_depth(fctx),31163 crate::decode::bit_depth(fctx),
31126- fctx.current_q_idx.with(|q| q.get()),31164+ // lane-d792 sweep: the block's segment `SEG_LVL_ALT_Q`, as at
31165+ // every other dequant site (class `parsed-then-discarded`).
31166+ block_q_idx(fctx),
31127 plane_q_delta(0, fctx).0,31167 plane_q_delta(0, fctx).0,
31128 plane_q_delta(0, fctx).1,31168 plane_q_delta(0, fctx).1,
31129 tx_type,31169 tx_type,
crates/ec-av1/src/stream.rsmodified+176 -0
@@ -35173,4 +35173,180 @@ pub(crate) mod tests {
35173 );35173 );
35174 }35174 }
35175 35175
35176+
35177+ /// lane-d792: a frame whose height the superblock grid CUTS, decoded
35178+ /// against ffmpeg on every ladder point of BOTH reference encoders.
35179+ ///
35180+ /// WHY IT EXISTS: the reference encoders answer a straddling frame with
35181+ /// rectangular partitions in the cut superblock row -- the only place
35182+ /// these streams code a 16x8/8x4 transform unit at all -- and the rect
35183+ /// intra dequant path was reading the FRAME's quantizer index where every
35184+ /// square path reads the block's segment-adjusted one
35185+ /// (`SEG_LVL_ALT_Q`, class `parsed-then-discarded`). Every gate size
35186+ /// before this one was a whole number of superblocks, so no gate ever
35187+ /// decoded such a unit: the 1920x792 native BD arm's reference-decode
35188+ /// assertion was red on all four rav1e points and this is its small,
35189+ /// fast, encoder-independent form.
35190+ ///
35191+ /// 384x152 is 2 superblocks + 24 px (the 1920x792 straddle, film A's own
35192+ /// coded size) and 384x184 is 2 + 56 px (the 1920x1080 straddle), so both
35193+ /// the "less than half inside" and the "more than half inside" edge
35194+ /// superblock shapes are covered.
35195+ #[test]
35196+ fn a_straddling_frame_decodes_exactly_on_both_reference_encoders_ladders() {
35197+ const NAME: &str = "a_straddling_frame_decodes_exactly_on_both_reference_encoders_ladders";
35198+ if !have_ffmpeg() {
35199+ eprintln!("SKIP {NAME}: no ffmpeg");
35200+ return;
35201+ }
35202+ const FRAMES: usize = 4;
35203+ let mut checked = 0usize;
35204+ // The PINNED half of this gate. The generated rows below are the
35205+ // general regression; these two files are rav1e's own answer to a
35206+ // 384x152 crop of a REAL film (`speed=6`, quantizer 100 and 150,
35207+ // `-g 4`), which is the only recipe measured to turn on the
35208+ // activity segmentation whose `SEG_LVL_ALT_Q` the rect dequant path
35209+ // dropped -- a `testsrc2` or repo-fixture source codes one segment
35210+ // and passes this gate with the defect still in (both verified by
35211+ // reverting the fix under it). Bytes live in the shared `fixtures`
35212+ // directory, which is gitignored, so a missing file SKIPs.
35213+ for name in [
35214+ "d792_straddle_rav1e_384x152_q100.obu",
35215+ "d792_straddle_rav1e_384x152_q150.obu",
35216+ ] {
35217+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
35218+ .join("../../fixtures")
35219+ .join(name);
35220+ let Ok(stream) = std::fs::read(&path) else {
35221+ eprintln!("SKIP {NAME}: {name} missing");
35222+ continue;
35223+ };
35224+ let (w, h) = (384usize, 152usize);
35225+ let want = ffmpeg_decode_sequence(&stream, w, h, FRAMES);
35226+ let got = decode_stream(&stream)
35227+ .unwrap_or_else(|e| panic!("{NAME}: {name} refused: {e}"));
35228+ assert_eq!(got.len(), want.len(), "{NAME}: {name} frame count");
35229+ for (f, (o, r)) in got.iter().zip(&want).enumerate() {
35230+ for (plane, a, b) in [("Y", &o.y, &r.y), ("U", &o.u, &r.u), ("V", &o.v, &r.v)] {
35231+ if let Some(i) = a.iter().zip(b.iter()).position(|(x, y)| x != y) {
35232+ let stride = if plane == "Y" { w } else { w / 2 };
35233+ panic!(
35234+ "{NAME}: {name}, frame {f} plane {plane} sample ({}, {}): ours {} \
35235+ vs ffmpeg {}",
35236+ i % stride,
35237+ i / stride,
35238+ a[i],
35239+ b[i],
35240+ );
35241+ }
35242+ }
35243+ }
35244+ checked += 1;
35245+ }
35246+ for (w, h) in [(384usize, 152usize), (384, 184)] {
35247+ // REAL content, not colour bars (class `gate film rows are colour
35248+ // bars`): both encoders only turn segmentation on -- the feature
35249+ // this gate is about -- when the picture's activity varies, and
35250+ // `testsrc2` codes one segment, so a bars source passes this gate
35251+ // with the defect still in (verified by reverting the fix under
35252+ // it).
35253+ let clip = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
35254+ .join("../../fixtures/video/h264-1080p-23.976-8bit.mp4");
35255+ if !clip.exists() {
35256+ eprintln!("SKIP {NAME}: {} missing", clip.display());
35257+ return;
35258+ }
35259+ for (encoder, points) in [
35260+ ("librav1e", ["50", "100", "150", "200"]),
35261+ ("libaom-av1", ["5", "20", "35", "45"]),
35262+ ] {
35263+ for point in points {
35264+ let mut args: Vec<String> =
35265+ ["-v", "error", "-i", clip.to_str().expect("fixture path")]
35266+ .iter()
35267+ .map(|s| (*s).to_string())
35268+ .collect();
35269+ args.extend(
35270+ [
35271+ "-frames:v",
35272+ &FRAMES.to_string(),
35273+ "-vf",
35274+ &format!("crop={w}:{h}:768:400"),
35275+ "-pix_fmt",
35276+ "yuv420p",
35277+ "-an",
35278+ ]
35279+ .iter()
35280+ .map(|s| (*s).to_string()),
35281+ );
35282+ args.extend(
35283+ ["-threads", "1", "-g", &FRAMES.to_string(), "-c:v", encoder]
35284+ .iter()
35285+ .map(|s| (*s).to_string()),
35286+ );
35287+ if encoder == "librav1e" {
35288+ args.push("-rav1e-params".into());
35289+ args.push(format!(
35290+ "speed=6:quantizer={point}:tile_cols=1:tile_rows=1:threads=1"
35291+ ));
35292+ } else {
35293+ args.extend(
35294+ // `-aq-mode 1`: libaom's activity segmentation,
35295+ // i.e. `SEG_LVL_ALT_Q` -- the feature the rect
35296+ // dequant path used to drop.
35297+ ["-cpu-used", "6", "-b:v", "0", "-crf", point, "-aq-mode", "1"]
35298+ .iter()
35299+ .map(|s| (*s).to_string()),
35300+ );
35301+ }
35302+ args.extend(["-f", "obu", "-"].iter().map(|s| (*s).to_string()));
35303+ let out = Command::new("ffmpeg")
35304+ .args(&args)
35305+ .stdin(Stdio::null())
35306+ .stdout(Stdio::piped())
35307+ .stderr(Stdio::piped())
35308+ .output()
35309+ .expect("ffmpeg failed to run");
35310+ if !out.status.success() {
35311+ eprintln!(
35312+ "SKIP {NAME}: ffmpeg cannot encode {w}x{h} with {encoder} ({})",
35313+ String::from_utf8_lossy(&out.stderr).lines().last().unwrap_or("")
35314+ );
35315+ continue;
35316+ }
35317+ let stream = out.stdout;
35318+ let want = ffmpeg_decode_sequence(&stream, w, h, FRAMES);
35319+ let got = decode_stream(&stream).unwrap_or_else(|e| {
35320+ panic!("{NAME}: {encoder} {point} at {w}x{h} refused: {e}")
35321+ });
35322+ assert_eq!(
35323+ got.len(),
35324+ want.len(),
35325+ "{NAME}: {encoder} {point} at {w}x{h} frame count"
35326+ );
35327+ for (f, (o, r)) in got.iter().zip(&want).enumerate() {
35328+ for (plane, a, b) in
35329+ [("Y", &o.y, &r.y), ("U", &o.u, &r.u), ("V", &o.v, &r.v)]
35330+ {
35331+ if let Some(i) = a.iter().zip(b.iter()).position(|(x, y)| x != y) {
35332+ let stride = if plane == "Y" { w } else { w / 2 };
35333+ panic!(
35334+ "{NAME}: {encoder} {point} at {w}x{h}, frame {f} plane \
35335+ {plane} sample ({}, {}): ours {} vs ffmpeg {}",
35336+ i % stride,
35337+ i / stride,
35338+ a[i],
35339+ b[i],
35340+ );
35341+ }
35342+ }
35343+ }
35344+ checked += 1;
35345+ }
35346+ }
35347+ }
35348+ assert!(checked > 0, "{NAME}: neither reference encoder was available");
35349+ eprintln!("{NAME}: {checked} straddling reference points decoded sample-exact");
35350+ }
35351+
35176 }35352 }
crates/ec-av1/src/transform.rsmodified+51 -0
@@ -1346,6 +1346,22 @@ pub fn dequant_and_inverse_typed_wh(
1346 DQ_SCRATCH.with(|cell| {1346 DQ_SCRATCH.with(|cell| {
1347 let mut dq = cell.borrow_mut();1347 let mut dq = cell.borrow_mut();
1348 crate::quant::dequant_wh_into(levels, &mut dq, w, h, bit_depth, q_idx, dc_delta, ac_delta);1348 crate::quant::dequant_wh_into(levels, &mut dq, w, h, bit_depth, q_idx, dc_delta, ac_delta);
1349+ // lane-d792: the DEQUANTIZED grid, in row-major `(row/col)` pairs --
1350+ // the twin of the oracle's `EC_DQCOEFF` rung (whose own layout is
1351+ // column-major `input[c * h + r]`), so a residual mismatch whose
1352+ // levels already agree is separable into dequant vs transform.
1353+ if crate::envflags::env_flag!("EC_DQCOEFF") {
1354+ let nz: Vec<String> = dq
1355+ .iter()
1356+ .enumerate()
1357+ .filter(|&(_, &v)| v != 0)
1358+ .map(|(i, &v)| format!("{}/{}:{v}", i / w, i % w))
1359+ .collect();
1360+ eprintln!(
1361+ "OUR_DQ w={w} h={h} q={q_idx} dcd={dc_delta} acd={ac_delta} tx={tx_type:?} nz={}",
1362+ nz.join(",")
1363+ );
1364+ }
1349 inverse_transform_2d_typed_wh(&dq, w, h, bit_depth, tx_type)1365 inverse_transform_2d_typed_wh(&dq, w, h, bit_depth, tx_type)
1350 })1366 })
1351 }1367 }
@@ -3105,3 +3121,38 @@ mod lossless_tx_tests {
3105 }3121 }
3106 }3122 }
3107 }3123 }
3124+
3125+#[cfg(test)]
3126+mod d792_tests {
3127+ /// lane-d792: ONE 16x8 DCT_DCT inverse against libaom's own numbers.
3128+ ///
3129+ /// The dequantized grid below is `EC_DQCOEFF`'s dump of the first
3130+ /// TX_16X8 unit of `$HOME/.cache/d792/small/f100.obu` (a rav1e
3131+ /// `speed=6 quantizer=100` encode of a 384x152 crop, whose bottom
3132+ /// straddle is where the reference-ladder decode failures live), in
3133+ /// libaom's own column-major `input[c * h + r]` order; the expected
3134+ /// residual is `aomdec`'s reconstruction of that block minus its
3135+ /// prediction (the two decoders' predictions are byte-identical there,
3136+ /// checked with the oracle's `EC_PREDOUT8` rung).
3137+ #[test]
3138+ fn a_16x8_inverse_matches_libaoms_own_dqcoeff_and_residual() {
3139+ const H: usize = 8;
3140+ const W: usize = 16;
3141+ // (libaom index, dequantized value).
3142+ const NZ: [(usize, i32); 17] = [
3143+ (0, 1554), (1, -1768), (2, 624), (3, -104), (9, 104), (10, -520), (11, 312),
3144+ (16, -104), (17, 104), (18, -104), (24, -104), (25, 104), (27, -104), (32, 208),
3145+ (33, -104), (35, -104), (40, 104),
3146+ ];
3147+ let mut grid = vec![0i32; W * H];
3148+ for (i, v) in NZ {
3149+ let (r, c) = (i % H, i / H);
3150+ grid[r * W + c] = v;
3151+ }
3152+ let out = super::inverse_transform_2d_typed_wh(&grid, W, H, 8, super::TxType::DctDct);
3153+ let col0: Vec<i32> = (0..H).map(|r| out[r * W]).collect();
3154+ let row0: Vec<i32> = out[..8].to_vec();
3155+ assert_eq!(col0, vec![-7, -2, 6, 17, 27, 34, 36, 37], "column 0");
3156+ assert_eq!(row0, vec![-7, -7, -6, -5, -2, 0, 1, -1], "row 0");
3157+ }
3158+}
lanes/d792.report.mdadded+228 -0
@@ -0,0 +1,228 @@
1+# lane-d792 — the reference-ladder decode failures on the 1920x792 (straddling) crop
2+
3+Working notes, kept current from the first commit. Streams and logs under
4+`$HOME/.cache/d792/` (`streams/`, `small/`, `stage/`).
5+
6+## Reproduction (standalone, without the 7-minute BD gate)
7+
8+12 frames of film A from `00:35:00`, `crop=1920:792:0:0` (film A IS coded
9+1920x792, so the gate's `EC_AV1_NATIVE_CROP=1920x792` is its whole frame),
10+encoded with the gate's own ladder recipes and decoded through
11+`examples/dump_yuv` vs `ffmpeg -pix_fmt yuv420p`:
12+
13+| point | our decode vs ffmpeg |
14+|---|---|
15+| libaom `-cpu-used 6 -crf 5/20/35/45` | **EXACT, all 4** |
16+| rav1e `speed=6 quantizer=50/100/150/200` | **DIFFERS, all 4, every frame** (4-6 k samples/frame, max abs 24) |
17+
18+So the chartered "libaom crf-5 Golomb refusal" does NOT reproduce at
19+046dbe0e on this source/recipe; only the rav1e ±1 class does. (Charter
20+premise re-checked, not assumed.)
21+
22+## Where the rav1e divergence lives
23+
24+All diffs sit in the LAST rows of the frame: luma rows 760..791 of 792,
25+chroma 382..395 of 396 — the bottom straddle (792 = 12*64 + 24).
26+
27+Stage bisect (our `EC_AV1_*_DUMP` vs the instrumented aomdec's twin dumps,
28+`$HOME/.cache/d792/stage/`), rav1e q150 frame 0:
29+
30+| stage | first differing row (luma) |
31+|---|---|
32+| pre-filter reconstruction | **769** |
33+| post-deblock | 766 |
34+| post-CDEF | 760 |
35+| final (post-LR) | 760 |
36+
37+So the loop filters only SPREAD it: the defect is in **reconstruction**, in
38+mi rows 192..197 — the 24 px the frame edge cuts off the last superblock row.
39+
40+## Small repro (fast iteration)
41+
42+`$HOME/.cache/d792/small/f100.obu`: 4 frames of film A cropped to
43+**384x152** (= 2*64 + 24 straddle), rav1e `speed=6 quantizer=100`. Our
44+pre-filter reconstruction differs from aomdec's in rows **144..151** only
45+(the last 8 rows), all columns; ~1800 luma samples on frame 0.
46+
47+## What is ruled OUT so far
48+
49+* **Parse (block level) is in sync**: `EC_TRACE_MODE_STEP` on both decoders
50+ gives identical `mode`/`skip`/`uv_mode`/`angle_y`/`angle_uv` sequences for
51+ the 1518 blocks of the 1920x792 key frame (the only surplus lines in ours
52+ are intra-in-inter `y_mode` rungs aomdec names differently).
53+* **Intra prediction is byte-exact** at the first differing block. The
54+ oracle was patched this round with an `EC_PREDOUT8` rung (8-bit predicted
55+ block; the existing one was high-bitdepth only) and the block at
56+ `mi_row=36 mi_col=0` of the small repro gives `sum=6959
57+ row0=82,74,65,56,50,47,46,45 col0=82,85,85,85,85,85,85,85` on BOTH sides.
58+ Edge lengths agree too (`n_left = 8` for a 16-tall TU with 8 rows inside,
59+ i.e. libaom's `AOMMIN(txhpx, yd + txhpx)` clip is already ours).
60+* Loop restoration's last-stripe substitution matches libaom's
61+ `get_stripe_boundary_info` (`copy_below = 0` at the frame bottom).
62+
63+## Where it IS (open, in progress)
64+
65+The residual. `EC_TRACE_COEFF` on both decoders over the small repro:
66+`eob` sequences are IDENTICAL (514 transform units) but the symbol streams
67+below them are not — ours reads **extra `br` (base-range) symbols** and
68+fewer `sign`/`base` ones (aom 23085 base / 7966 sign / 3338 br; ours 23634 /
69+7715 / 3351). First divergence is an extra `br` at trace line ~22951 of
70+44647. Next: resolve that line to its transform unit and read the rule that
71+differs there.
72+
73+## Elimination chain (all measured on the 384x152 small repro, frame 0)
74+
75+The first differing sample is inside the luma block at `x=0 y=144`, a 16x8
76+intra block in the bottom straddle (PARTITION_HORZ is forced there by the
77+frame edge). For that block:
78+
79+1. **Prediction: identical.** `OUR_PRED sum=6959 row0=[82,74,65,56,50,47,46,45]
80+ col0=[82,85,85,85,85,85,85,85]` == the oracle's new `EC_PREDOUT8` line for
81+ `mi_row=36 mi_col=4`(sic: `mi_col=0`), to the sample.
82+2. **Coefficient bitstream: in sync.** `EC_TRACE_COEFF`'s `all_zero` range
83+ value agrees at ALL 750 transform units; `eob` agrees at all 514.
84+3. **Transform type: identical.** The oracle now prints the resolved
85+ `txtype`/`txsize`; the 514-long sequence matches ours entry for entry.
86+ All 19 TX_16X8 units are DCT_DCT.
87+4. **Transform unit shapes: identical.** Both decoders code 19 16x8, 27 8x4
88+ and 1 32x16 rectangular units (the oracle's new `EC_DQCOEFF` rung vs our
89+ new `OUR_LEVELS` rung).
90+5. **Level grids: identical.** The first three 16x8 units' non-zero
91+ (row/col, level) sets match the oracle's `EC_DQCOEFF` dump converted out
92+ of libaom's column-major `input[c * h + r]` layout -- which also
93+ re-verifies `SCAN_16X8` against `av1_default_scan_16x8`.
94+6. **The 16x8 inverse transform is correct.** New pin
95+ `transform::d792_tests::a_16x8_inverse_matches_libaoms_own_dqcoeff_and_residual`
96+ feeds our `inverse_transform_2d_typed_wh` libaom's own dequantized grid
97+ and asserts libaom's own residual (`aomdec` reconstruction minus the
98+ identical prediction): PASSES.
99+7. **The q index is frame-constant.** `aomdec`'s `current_base_qindex` is 127
100+ for all 1518 blocks of the 1920x792 key frame; no delta-q is in play.
101+
102+So the residual our decoder ADDS differs (ours `col0 = [-6,-3,4,13,21,26,28,
103+28]`, libaom's `[-7,-2,6,17,27,34,36,37]`, roughly a 0.77 factor) while the
104+levels, the shape, the type and the transform kernel all agree. The
105+remaining link is the DEQUANT step between them -- `dequant_and_inverse_typed_wh`
106+at the intra rect call sites (`decode.rs:9487/9543/9713/10826...`), where the
107+suspects are the `(w, h)` argument order (class `adjacent same-typed args`;
108+a transposed grid would weaken exactly the vertical response we see) and the
109+q index / DC-AC delta that site passes.
110+
111+## Instruments added this round
112+
113+* Oracle (`~/.cache/aom-oracle/src`, build2): `EC_PREDOUT8` on both 8-bit
114+ prediction paths, `txtype=`/`txsize=` on the `tag=tx_type` rung, and
115+ `EC_DQCOEFF` (the dequantized grid the inverse transform runs on).
116+* Ours: `OUR_RECON` (reconstructed row0/col0 beside `EC_PRED`'s prediction)
117+ and `OUR_LEVELS` (a rect unit's level grid, `EC_DQCOEFF=1`).
118+
119+## NOT done this round (budget)
120+
121+* `deferred: the root cause and its fix -- the dequant link above is the one
122+ unchecked step -- unblocked by dumping the dequantized grid at the rect
123+ intra call site and diffing it against the oracle's EC_DQCOEFF line`
124+* `deferred: the libaom crf-5 "Golomb tail" refusal -- it does NOT reproduce
125+ standalone at 046dbe0e (all four libaom points decode exact), so it needs
126+ the gate arm itself re-run to confirm it is stale`
127+* `deferred: the synthetic straddling fixtures (384x152 / 384x184 gates), the
128+ 1920x792 green arm, the suite and the workspace check -- they gate a fix
129+ that does not exist yet`
130+
131+## ROOT CAUSE (round 2) — the rect intra dequant dropped the block's segment quantizer
132+
133+`OUR_DQ` (our new dequantized-grid rung) against the oracle's `EC_DQCOEFF`
134+for the same 16x8 unit: the level grids agree, but ours dequantizes with
135+`q = 75` where libaom uses the quantizer of q-index ~96 (dc 111 / ac 104 vs
136+our 82 / 82) -- the 0.77 residual factor exactly.
137+
138+`OUR_Q` (the segment rung) named it: frame 0 of the small repro has THREE
139+segments (`base = 75`; seg 0 -> 67, seg 1 -> 81, seg 2 -> 96 through
140+`SEG_LVL_ALT_Q`), and the rect intra path was dequantizing with
141+`fctx.current_q_idx` -- the FRAME's index -- instead of
142+[`block_q_idx`], which adds the block's own segment feature. Every square
143+path already used `block_q_idx`, which is why the defect was invisible until
144+a frame edge forced rectangular partitions: only the cut superblock row codes
145+16x8 / 8x4 units in these streams.
146+
147+**Class**: `parsed-then-discarded` -- the segmentation ALT_Q is parsed,
148+applied at 21 dequant sites, and dropped at 6 of them. (Sibling shape to
149+`override slot on one arm`: the rect ARM of a two-arm path missed the
150+adjustment its square twin had.)
151+
152+**Fix**: `block_q_idx(fctx)` at all six, in `crates/ec-av1/src/decode.rs`
153+(the split rect path's chroma, the 16x8/8x16 luma+chroma trio, and two
154+8x4/rect leaf sites at 16240 / 31147).
155+
156+**Sweep**: every `dequant_and_inverse*` call site in the decoder (27) now
157+takes either `block_q_idx` or a `TxParams::q_idx` that was itself built from
158+`block_q_idx`; `grep -n "current_q_idx" decode.rs` leaves only the frame-level
159+cell itself, `block_q_idx`'s own read of it and a `RECT64_QIDX_DRIFT_HITS`
160+counter.
161+
162+## Result
163+
164+* small repro `384x152` rav1e q100 and q150: **EXACT vs ffmpeg**, all frames.
165+* the whole 1920x792 reference ladder -- libaom crf 5/20/35/45 AND rav1e
166+ quantizer 50/100/150/200, 12 frames each: **EXACT vs ffmpeg on every
167+ point** (`$HOME/.cache/d792/streams`, decoded with `examples/dump_yuv`).
168+
169+## The gate, and what it took to make it see the defect
170+
171+`stream::tests::a_straddling_frame_decodes_exactly_on_both_reference_encoders_ladders`
172+(2.7 s) has two halves:
173+
174+* **Generated rows** -- 4 frames at 384x152 (2 SB + 24 px, the 1920x792
175+ straddle) and 384x184 (2 SB + 56 px, the 1080p straddle), through librav1e
176+ (quantizer 50/100/150/200) and libaom (`-cpu-used 6 -crf 5/20/35/45
177+ -aq-mode 1`), each decoded by ffmpeg and by us and compared sample by
178+ sample.
179+* **Pinned rows** -- `fixtures/d792_straddle_rav1e_384x152_q100.obu` and
180+ `..._q150.obu`, rav1e's own answer to a 384x152 crop of a real film.
181+
182+That split is not decoration. **The generated rows alone do NOT catch this
183+defect**: with the fix reverted under them, first a `testsrc2` source and then
184+the repo's own `h264-1080p-23.976-8bit.mp4` fixture (which is colour bars,
185+per the standing note) both PASSED at all 16 points, because neither codes
186+more than one segment, and the defect only exists where `SEG_LVL_ALT_Q` does
187+(class `gate-blind-to-feature`). The pinned rows fail pre-fix at
188+`frame 0 plane Y sample (17, 140): ours 41 vs ffmpeg 42` and pass after, so
189+the gate's defect-catching power is measured, not assumed.
190+
191+## Verification
192+
193+| check | result |
194+|---|---|
195+| `cargo test -p ec-av1 --release --lib a_straddling_frame` | 18 straddling reference points sample-exact, 2.7 s |
196+| the same gate with the fix reverted | FAILED at `(17, 140)` of the pinned q100 row |
197+| the 1920x792 ladder, 12 frames, decoded standalone (`examples/dump_yuv` vs ffmpeg) | libaom crf 5/20/35/45 **EXACT**, rav1e quantizer 50/100/150/200 **EXACT** -- all 8 points, i.e. what `external_ladder`'s reference-decode assertion checks |
198+| `cargo check --workspace --all-targets -j4` | 0 errors; 0 `ec-av1` warnings (the 21 `ec-opus` missing-doc + 1 `ec-vorbis` dead-code ones are pre-existing) |
199+
200+## The 1920x792 arm itself (`EC_AV1_NATIVE_CROP=1920x792`, film A row)
201+
202+`cargo test -p ec-av1 --release --lib -- --ignored --exact
203+encode::tests::bd_rate_screen_native`, 494 s, log `$HOME/.cache/d792/native.log`:
204+
205+* **8 of the 9 failures are gone.** All four rav1e points now decode exactly;
206+ the BD row itself is unchanged (`+22.5%` vs libaom, `-2.3%` vs rav1e,
207+ 44.03/45.60/46.92/48.20 dB at 68847/109557/178345/426318 B -- lane-corner's
208+ post-lift numbers to the digit).
209+* **One remains**, and it is NOT a straddle defect:
210+ `libaom-av1 ["-cpu-used","6","-b:v","0","-crf","5"]: our decoder refused the
211+ stream (a Golomb tail longer than this decoder reads)`. The same recipe run
212+ standalone this round decoded EXACT, so libaom's crf-5 output is not
213+ reproducible run-to-run here and the refusal is hit by some of its streams:
214+ a coefficient-magnitude limit at the very lowest quantizer, not an edge
215+ case of the frame geometry.
216+ `deferred: the crf-5 Golomb-tail refusal -- read the refusal site's own
217+ bound against libaom's read_golomb (which reads up to 20 bits + the level
218+ bound), reproduce by looping the crf-5 encode until a refusing stream is
219+ captured, pin that stream as a fixture -- it is lane-dgolomb's standing
220+ debt and needs its own round`
221+
222+## Suite
223+
224+`cargo test -p ec-av1 --release` (detached, 893 s): **572 passed, 0 failed,
225+46 ignored**, RC=0 -- 570 before plus this lane's two (the 16x8 transform pin
226+and the straddle gate). The pin test
227+`the_encoders_own_streams_are_byte_identical_to_their_pins` is inside it, so
228+the 8562 / 33357 byte pins are unchanged.