forge
Explore
Log in

Don't you dare go Hollow

merge: lane-rectchroma2 48216c2 into lane-intra14 -- rect inter chroma narrow kernel, keep the staged dump naming

Browse files at this commit

c3abafeba7f75b09ac5103f9b1be7bc402b58e2bAhmet Kaan GümüşParent: b6c20ebcd6e06e
crates/ec-av1/src/decode.rsmodified+36 -12
@@ -18399,7 +18399,7 @@ fn decode_inter_block(
1839918399 }
1840018400
1840118401 let mut inter0_y = vec![0i32; side * side];
18402- mc::predict_compound_intermediate(
18402+ mc::predict_compound_intermediate_kern(
1840318403 &py0.data,
1840418404 py0.width,
1840518405 py0.true_width,
@@ -18409,6 +18409,8 @@ fn decode_inter_block(
1840918409 scale0,
1841018410 side,
1841118411 side,
18412+ write_w,
18413+ write_h,
1841218414 h_filter,
1841318415 v_filter,
1841418416 &mut inter0_y,
@@ -18424,7 +18426,7 @@ fn decode_inter_block(
1842418426 );
1842518427 }
1842618428 let mut inter1_y = vec![0i32; side * side];
18427- mc::predict_compound_intermediate(
18429+ mc::predict_compound_intermediate_kern(
1842818430 &py1.data,
1842918431 py1.width,
1843018432 py1.true_width,
@@ -18434,6 +18436,8 @@ fn decode_inter_block(
1843418436 scale1,
1843518437 side,
1843618438 side,
18439+ write_w,
18440+ write_h,
1843718441 h_filter,
1843818442 v_filter,
1843918443 &mut inter1_y,
@@ -18471,7 +18475,7 @@ fn decode_inter_block(
1847118475 }
1847218476
1847318477 let mut inter0_u = vec![0i32; chroma_side * chroma_side];
18474- mc::predict_compound_intermediate(
18478+ mc::predict_compound_intermediate_kern(
1847518479 &pu0.data,
1847618480 pu0.width,
1847718481 pu0.true_width,
@@ -18481,6 +18485,8 @@ fn decode_inter_block(
1848118485 scale0,
1848218486 chroma_side,
1848318487 chroma_side,
18488+ write_chroma_w,
18489+ write_chroma_h,
1848418490 h_filter,
1848518491 v_filter,
1848618492 &mut inter0_u,
@@ -18498,7 +18504,7 @@ fn decode_inter_block(
1849818504 }
1849918505 }
1850018506 let mut inter1_u = vec![0i32; chroma_side * chroma_side];
18501- mc::predict_compound_intermediate(
18507+ mc::predict_compound_intermediate_kern(
1850218508 &pu1.data,
1850318509 pu1.width,
1850418510 pu1.true_width,
@@ -18508,6 +18514,8 @@ fn decode_inter_block(
1850818514 scale1,
1850918515 chroma_side,
1851018516 chroma_side,
18517+ write_chroma_w,
18518+ write_chroma_h,
1851118519 h_filter,
1851218520 v_filter,
1851318521 &mut inter1_u,
@@ -18541,7 +18549,7 @@ fn decode_inter_block(
1854118549 }
1854218550
1854318551 let mut inter0_v = vec![0i32; chroma_side * chroma_side];
18544- mc::predict_compound_intermediate(
18552+ mc::predict_compound_intermediate_kern(
1854518553 &pv0.data,
1854618554 pv0.width,
1854718555 pv0.true_width,
@@ -18551,6 +18559,8 @@ fn decode_inter_block(
1855118559 scale0,
1855218560 chroma_side,
1855318561 chroma_side,
18562+ write_chroma_w,
18563+ write_chroma_h,
1855418564 h_filter,
1855518565 v_filter,
1855618566 &mut inter0_v,
@@ -18568,7 +18578,7 @@ fn decode_inter_block(
1856818578 }
1856918579 }
1857018580 let mut inter1_v = vec![0i32; chroma_side * chroma_side];
18571- mc::predict_compound_intermediate(
18581+ mc::predict_compound_intermediate_kern(
1857218582 &pv1.data,
1857318583 pv1.width,
1857418584 pv1.true_width,
@@ -18578,6 +18588,8 @@ fn decode_inter_block(
1857818588 scale1,
1857918589 chroma_side,
1858018590 chroma_side,
18591+ write_chroma_w,
18592+ write_chroma_h,
1858118593 h_filter,
1858218594 v_filter,
1858318595 &mut inter1_v,
@@ -19489,7 +19501,7 @@ fn decode_inter_block(
1948919501 let mut pred_u = vec![0u16; chroma_side * chroma_side];
1949019502 let mut pred_v = vec![0u16; chroma_side * chroma_side];
1949119503 if luma_scale == mc::REF_NO_SCALE {
19492- mc::predict_with_filters(
19504+ mc::predict_with_filters_kern(
1949319505 &py_ref.data,
1949419506 py_ref.width,
1949519507 py_ref.true_width,
@@ -19498,11 +19510,13 @@ fn decode_inter_block(
1949819510 mv_to_q4(py, mv.0, true),
1949919511 side,
1950019512 side,
19513+ write_w,
19514+ write_h,
1950119515 h_filter,
1950219516 v_filter,
1950319517 &mut pred_y,
1950419518 );
19505- mc::predict_with_filters(
19519+ mc::predict_with_filters_kern(
1950619520 &pu_ref.data,
1950719521 pu_ref.width,
1950819522 pu_ref.true_width,
@@ -19511,11 +19525,13 @@ fn decode_inter_block(
1951119525 mv_to_q4(cpy, mv.0, false),
1951219526 chroma_side,
1951319527 chroma_side,
19528+ write_chroma_w,
19529+ write_chroma_h,
1951419530 h_filter,
1951519531 v_filter,
1951619532 &mut pred_u,
1951719533 );
19518- mc::predict_with_filters(
19534+ mc::predict_with_filters_kern(
1951919535 &pv_ref.data,
1952019536 pv_ref.width,
1952119537 pv_ref.true_width,
@@ -19524,12 +19540,14 @@ fn decode_inter_block(
1952419540 mv_to_q4(cpy, mv.0, false),
1952519541 chroma_side,
1952619542 chroma_side,
19543+ write_chroma_w,
19544+ write_chroma_h,
1952719545 h_filter,
1952819546 v_filter,
1952919547 &mut pred_v,
1953019548 );
1953119549 } else {
19532- mc::predict_scaled(
19550+ mc::predict_scaled_kern(
1953319551 &py_ref.data,
1953419552 py_ref.width,
1953519553 py_ref.true_width,
@@ -19539,11 +19557,13 @@ fn decode_inter_block(
1953919557 luma_scale,
1954019558 side,
1954119559 side,
19560+ write_w,
19561+ write_h,
1954219562 h_filter,
1954319563 v_filter,
1954419564 &mut pred_y,
1954519565 );
19546- mc::predict_scaled(
19566+ mc::predict_scaled_kern(
1954719567 &pu_ref.data,
1954819568 pu_ref.width,
1954919569 pu_ref.true_width,
@@ -19553,11 +19573,13 @@ fn decode_inter_block(
1955319573 luma_scale,
1955419574 chroma_side,
1955519575 chroma_side,
19576+ write_chroma_w,
19577+ write_chroma_h,
1955619578 h_filter,
1955719579 v_filter,
1955819580 &mut pred_u,
1955919581 );
19560- mc::predict_scaled(
19582+ mc::predict_scaled_kern(
1956119583 &pv_ref.data,
1956219584 pv_ref.width,
1956319585 pv_ref.true_width,
@@ -19567,6 +19589,8 @@ fn decode_inter_block(
1956719589 luma_scale,
1956819590 chroma_side,
1956919591 chroma_side,
19592+ write_chroma_w,
19593+ write_chroma_h,
1957019594 h_filter,
1957119595 v_filter,
1957219596 &mut pred_v,
crates/ec-av1/src/mc.rsmodified+117 -5
@@ -333,6 +333,36 @@ pub fn predict_with_filters(
333333 h_kind: InterpFilterKind,
334334 v_kind: InterpFilterKind,
335335 dst: &mut [u16],
336+) {
337+ predict_with_filters_kern(
338+ reference, stride, true_width, true_height, x_q4, y_q4, block_w,
339+ block_h, block_w, block_h, h_kind, v_kind, dst,
340+ );
341+}
342+
343+/// [`predict_with_filters`] with the 4-tap decision taken from the block's
344+/// TRUE width/height (`kern_w`/`kern_h`) rather than the destination buffer's.
345+/// libaom's `av1_get_interp_filter_params_with_block_size` (reconinter.h,
346+/// called per axis from `inter_predictor` with `w` then `h`) picks the narrow
347+/// kernel from the PREDICTION block's own dimensions; our inter path predicts
348+/// a rectangular block over its enclosing square buffer, so a rect block whose
349+/// chroma is 4 wide or 4 tall (luma 8x16 / 16x8 and taller kin) must still ask
350+/// for the 4-tap kernel on that axis -- lane-rectchroma2 r1.
351+#[allow(clippy::too_many_arguments)]
352+pub fn predict_with_filters_kern(
353+ reference: &[u16],
354+ stride: usize,
355+ true_width: usize,
356+ true_height: usize,
357+ x_q4: i32,
358+ y_q4: i32,
359+ block_w: usize,
360+ block_h: usize,
361+ kern_w: usize,
362+ kern_h: usize,
363+ h_kind: InterpFilterKind,
364+ v_kind: InterpFilterKind,
365+ dst: &mut [u16],
336366 ) {
337367 assert_eq!(dst.len(), block_w * block_h, "the destination is the block");
338368 assert!(!reference.is_empty(), "a reference plane has samples");
@@ -374,12 +404,13 @@ pub fn predict_with_filters(
374404
375405 let (h_wide, h_narrow) = h_kind.tables();
376406 let (v_wide, v_narrow) = v_kind.tables();
377- let h_filter = if block_w <= 4 {
407+ note_narrow_kern(block_w, block_h, kern_w, kern_h);
408+ let h_filter = if kern_w <= 4 {
378409 &h_narrow[xfrac]
379410 } else {
380411 &h_wide[xfrac]
381412 };
382- let v_filter = if block_h <= 4 {
413+ let v_filter = if kern_h <= 4 {
383414 &v_narrow[yfrac]
384415 } else {
385416 &v_wide[yfrac]
@@ -452,6 +483,32 @@ thread_local! {
452483 /// only intra blocks cannot pass it by construction (class
453484 /// `gate-blind-to-feature`).
454485 static INTER_PRED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
486+
487+ /// lane-rectchroma2 r1: how often the 4-tap decision came out DIFFERENT
488+ /// from what the destination buffer's own dimensions would have given --
489+ /// i.e. how often a rectangular block predicted over its enclosing square
490+ /// buffer asked for libaom's narrow kernel on an axis. Zero means a gate
491+ /// never exercised the rect-chroma shape at all.
492+ static RECT_NARROW_KERN_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
493+}
494+
495+/// Current value of [`RECT_NARROW_KERN_HITS`].
496+pub fn rect_narrow_kern_hits() -> usize {
497+ RECT_NARROW_KERN_HITS.with(|c| c.get())
498+}
499+
500+/// Resets [`RECT_NARROW_KERN_HITS`] (per-attempt counting, class
501+/// `counter-from-refused-stream`).
502+pub fn reset_rect_narrow_kern_hits() {
503+ RECT_NARROW_KERN_HITS.with(|c| c.set(0));
504+}
505+
506+/// Bumps [`RECT_NARROW_KERN_HITS`] when the block's true dims pick a kernel
507+/// the destination buffer's dims would not have.
508+fn note_narrow_kern(block_w: usize, block_h: usize, kern_w: usize, kern_h: usize) {
509+ if (kern_w <= 4) != (block_w <= 4) || (kern_h <= 4) != (block_h <= 4) {
510+ RECT_NARROW_KERN_HITS.with(|c| c.set(c.get() + 1));
511+ }
455512 }
456513
457514 /// Current value of [`INTER_PRED_HITS`].
@@ -498,6 +555,7 @@ fn horizontal_scaled_pass(
498555 y0: i32,
499556 x_scale_fp: i64,
500557 block_w: usize,
558+ kern_w: usize,
501559 rows: usize,
502560 h_kind: InterpFilterKind,
503561 intermediate: &mut [i32],
@@ -510,7 +568,7 @@ fn horizontal_scaled_pass(
510568 let x_qn = pos_x_q10 + c as i64 * x_step_qn;
511569 let int_pel = (x_qn >> 10) as i32;
512570 let filter_idx = ((x_qn & 1023) >> 6) as usize;
513- let h_filter = if block_w <= 4 {
571+ let h_filter = if kern_w <= 4 {
514572 &h_narrow[filter_idx]
515573 } else {
516574 &h_wide[filter_idx]
@@ -555,6 +613,31 @@ pub fn predict_scaled(
555613 h_kind: InterpFilterKind,
556614 v_kind: InterpFilterKind,
557615 dst: &mut [u16],
616+) {
617+ predict_scaled_kern(
618+ reference, stride, true_width, true_height, x_q4, y_q4, x_scale_fp,
619+ block_w, block_h, block_w, block_h, h_kind, v_kind, dst,
620+ );
621+}
622+
623+/// [`predict_scaled`] with the 4-tap decision from the block's true dims
624+/// (see [`predict_with_filters_kern`]).
625+#[allow(clippy::too_many_arguments)]
626+pub fn predict_scaled_kern(
627+ reference: &[u16],
628+ stride: usize,
629+ true_width: usize,
630+ true_height: usize,
631+ x_q4: i32,
632+ y_q4: i32,
633+ x_scale_fp: i64,
634+ block_w: usize,
635+ block_h: usize,
636+ kern_w: usize,
637+ kern_h: usize,
638+ h_kind: InterpFilterKind,
639+ v_kind: InterpFilterKind,
640+ dst: &mut [u16],
558641 ) {
559642 assert_eq!(dst.len(), block_w * block_h, "the destination is the block");
560643 assert!(!reference.is_empty(), "a reference plane has samples");
@@ -568,7 +651,8 @@ pub fn predict_scaled(
568651 // Q10; off/pos_x_q10 fold the block's own x_q4 (Q4) into that same Q10
569652 // grid (spec 7.11.3.3's `dec_calc_subpel_params`).
570653 let (v_wide, v_narrow) = v_kind.tables();
571- let v_filter = if block_h <= 4 {
654+ note_narrow_kern(block_w, block_h, kern_w, kern_h);
655+ let v_filter = if kern_h <= 4 {
572656 &v_narrow[yfrac]
573657 } else {
574658 &v_wide[yfrac]
@@ -585,6 +669,7 @@ pub fn predict_scaled(
585669 y0,
586670 x_scale_fp,
587671 block_w,
672+ kern_w,
588673 rows,
589674 h_kind,
590675 &mut intermediate,
@@ -648,6 +733,31 @@ pub fn predict_compound_intermediate(
648733 h_kind: InterpFilterKind,
649734 v_kind: InterpFilterKind,
650735 dst: &mut [i32],
736+) {
737+ predict_compound_intermediate_kern(
738+ reference, stride, true_width, true_height, x_q4, y_q4, x_scale_fp,
739+ block_w, block_h, block_w, block_h, h_kind, v_kind, dst,
740+ );
741+}
742+
743+/// [`predict_compound_intermediate`] with the 4-tap decision from the block's
744+/// true dims (see [`predict_with_filters_kern`]).
745+#[allow(clippy::too_many_arguments)]
746+pub fn predict_compound_intermediate_kern(
747+ reference: &[u16],
748+ stride: usize,
749+ true_width: usize,
750+ true_height: usize,
751+ x_q4: i32,
752+ y_q4: i32,
753+ x_scale_fp: i64,
754+ block_w: usize,
755+ block_h: usize,
756+ kern_w: usize,
757+ kern_h: usize,
758+ h_kind: InterpFilterKind,
759+ v_kind: InterpFilterKind,
760+ dst: &mut [i32],
651761 ) {
652762 assert_eq!(dst.len(), block_w * block_h, "the destination is the block");
653763 assert!(!reference.is_empty(), "a reference plane has samples");
@@ -661,7 +771,8 @@ pub fn predict_compound_intermediate(
661771 let yfrac = y_q4.rem_euclid(16) as usize;
662772
663773 let (v_wide, v_narrow) = v_kind.tables();
664- let v_filter = if block_h <= 4 {
774+ note_narrow_kern(block_w, block_h, kern_w, kern_h);
775+ let v_filter = if kern_h <= 4 {
665776 &v_narrow[yfrac]
666777 } else {
667778 &v_wide[yfrac]
@@ -678,6 +789,7 @@ pub fn predict_compound_intermediate(
678789 y0,
679790 x_scale_fp,
680791 block_w,
792+ kern_w,
681793 rows,
682794 h_kind,
683795 &mut intermediate,
crates/ec-av1/src/stream.rsmodified+198 -0
@@ -26618,4 +26618,202 @@ mod tests {
2661826618 // instead; this counter is reported, not gated.
2661926619 eprintln!("{NAME}: {skip_split_tx_total} skipped 8x8 TX_4X4 leaves across compared attempts");
2662026620 }
26621+
26622+ /// lane-rectchroma2 r1, the defect this gate exists for: our inter path
26623+ /// predicts a RECTANGULAR block over its enclosing SQUARE buffer
26624+ /// (`side`x`side`, `chroma_side`x`chroma_side` -- see
26625+ /// [`crate::decode`]'s `write_w`/`write_h` corner-cut), and
26626+ /// [`crate::mc::predict_with_filters`] took libaom's narrow-block 4-tap
26627+ /// decision from that buffer's dimensions. libaom
26628+ /// (`av1_get_interp_filter_params_with_block_size`, called per axis from
26629+ /// `inter_predictor` with `w` then `h`) takes it from the PREDICTION
26630+ /// block's own dimensions, so an 8x16 / 16x8 inter block -- whose chroma
26631+ /// is 4x8 / 8x4 -- must use the 4-tap kernel on the short axis. Luma is
26632+ /// never <= 4 wide here, which is exactly why every such stream decoded
26633+ /// LUMA EXACT and differed by +-1 on scattered chroma samples of those
26634+ /// blocks (lane-interedge r1's 192x128 control, a size with no frame-edge
26635+ /// node at all).
26636+ ///
26637+ /// Full-plane (Y+U+V) compare of EVERY decode-order frame
26638+ /// (`--lag-in-frames=0`), both orientations (192x128 and its transposed
26639+ /// twin, so the 4x8 and 8x4 chroma shapes both fire -- class
26640+ /// `scan-weights-cross-axis`), 8 AND 10 bit (his films are yuv420p10le),
26641+ /// cq 20/32/45, CDEF and loop restoration left ON. The counter is reset
26642+ /// per attempt and read only on an attempt that decoded and compared
26643+ /// (class `counter-from-refused-stream`); it counts predictions whose
26644+ /// kernel choice DIFFERS from what the square buffer would have given, so
26645+ /// a zero means the recipe lost the shape this gate pins.
26646+ #[test]
26647+ fn a_real_aomenc_rect_inter_block_predicts_chroma_with_the_narrow_kernel_pixel_exact() {
26648+ const NAME: &str =
26649+ "a_real_aomenc_rect_inter_block_predicts_chroma_with_the_narrow_kernel_pixel_exact";
26650+ let _gate_lock = lock_gate_counters();
26651+ if !have_ffmpeg() {
26652+ eprintln!("SKIP {NAME}: no ffmpeg");
26653+ return;
26654+ }
26655+ if !have_aomenc() {
26656+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
26657+ return;
26658+ }
26659+ const FRAMES: usize = 6;
26660+ let mut compared = 0usize;
26661+ let mut narrow_by_depth = [0usize; 2];
26662+ let mut narrow_by_shape = [0usize; 2];
26663+ for (si, (width, height)) in [(192usize, 128usize), (128usize, 192usize)]
26664+ .into_iter()
26665+ .enumerate()
26666+ {
26667+ for (di, depth) in [8usize, 10].into_iter().enumerate() {
26668+ let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" };
26669+ let y4m = Command::new("ffmpeg")
26670+ .args([
26671+ "-v", "error", "-f", "lavfi", "-i",
26672+ &format!("mandelbrot=size={width}x{height}:rate=25"),
26673+ "-pix_fmt", pix, "-strict", "-1", "-vframes", &FRAMES.to_string(),
26674+ "-f", "yuv4mpegpipe", "-",
26675+ ])
26676+ .stdin(Stdio::null())
26677+ .stdout(Stdio::piped())
26678+ .stderr(Stdio::piped())
26679+ .output()
26680+ .expect("ffmpeg failed to run");
26681+ assert!(
26682+ y4m.status.success(),
26683+ "{NAME}: ffmpeg fixture ({width}x{height}, depth={depth}): {}",
26684+ String::from_utf8_lossy(&y4m.stderr)
26685+ );
26686+ for cq in [20usize, 32, 45] {
26687+ let encode = || {
26688+ let mut child = Command::new(aomenc_path())
26689+ .args([
26690+ "--codec=av1", "--passes=1", "--end-usage=q",
26691+ &format!("--cq-level={cq}"),
26692+ "--cpu-used=4", "--threads=1", "--row-mt=0",
26693+ "--kf-max-dist=9999", &format!("--limit={FRAMES}"),
26694+ "--lag-in-frames=0",
26695+ &format!("--bit-depth={depth}"),
26696+ &format!("--input-bit-depth={depth}"),
26697+ // Rect partitions ON is the whole point; every
26698+ // other tool below is another lane's open gap
26699+ // that would refuse before a pixel compare.
26700+ "--enable-rect-partitions=1", "--enable-ab-partitions=0",
26701+ "--enable-1to4-partitions=0", "--min-partition-size=8",
26702+ "--max-partition-size=64", "--enable-palette=0",
26703+ "--enable-intrabc=0", "--enable-warped-motion=0",
26704+ "--enable-obmc=0", "--enable-masked-comp=0",
26705+ "--enable-interintra-comp=0", "--enable-onesided-comp=0",
26706+ "--enable-interintra-wedge=0", "--enable-smooth-interintra=0",
26707+ "--enable-ref-frame-mvs=0", "--enable-angle-delta=0",
26708+ "--enable-cfl-intra=0", "--enable-directional-intra=0",
26709+ "--enable-smooth-intra=0", "--enable-paeth-intra=0",
26710+ "--enable-filter-intra=0", "--enable-tx-size-search=0",
26711+ "--obu", "-o", "-", "-",
26712+ ])
26713+ .stdin(Stdio::piped())
26714+ .stdout(Stdio::piped())
26715+ .stderr(Stdio::piped())
26716+ .spawn()
26717+ .expect("aomenc failed to start");
26718+ child
26719+ .stdin
26720+ .take()
26721+ .expect("aomenc stdin")
26722+ .write_all(&y4m.stdout)
26723+ .expect("writing y4m to aomenc");
26724+ let out = child.wait_with_output().expect("aomenc failed to run");
26725+ assert!(
26726+ out.status.success(),
26727+ "aomenc refused the fixture ({width}x{height}, depth={depth}, \
26728+ cq={cq}): {}",
26729+ String::from_utf8_lossy(&out.stderr)
26730+ );
26731+ out.stdout
26732+ };
26733+ let stream = encode();
26734+ assert_eq!(
26735+ stream,
26736+ encode(),
26737+ "{NAME}: aomenc output is not reproducible ({width}x{height}, \
26738+ depth={depth}, cq={cq})"
26739+ );
26740+ crate::mc::reset_rect_narrow_kern_hits();
26741+ let frames = match decode_stream(&stream) {
26742+ Ok(frames) => frames,
26743+ Err(e) => {
26744+ let msg = e.to_string();
26745+ assert!(
26746+ msg.contains("unsupported"),
26747+ "{NAME}: decode failed ({width}x{height}, depth={depth}, \
26748+ cq={cq}): {msg}"
26749+ );
26750+ eprintln!(
26751+ "{NAME}: {width}x{height} depth={depth} cq={cq} arm refused \
26752+ (not compared): {msg}"
26753+ );
26754+ continue;
26755+ }
26756+ };
26757+ let narrow = crate::mc::rect_narrow_kern_hits();
26758+ let ffmpeg_frames = if depth == 10 {
26759+ ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len())
26760+ } else {
26761+ ffmpeg_decode_sequence(&stream, width, height, frames.len())
26762+ };
26763+ assert_eq!(
26764+ ffmpeg_frames.len(),
26765+ frames.len(),
26766+ "{NAME}: ffmpeg frame count ({width}x{height}, depth={depth}, cq={cq})"
26767+ );
26768+ assert_eq!(
26769+ frames.len(),
26770+ FRAMES,
26771+ "{NAME}: not every coded frame was decoded ({width}x{height}, \
26772+ depth={depth}, cq={cq})"
26773+ );
26774+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
26775+ assert_eq!(
26776+ got.y, want.y,
26777+ "{NAME} frame {i} luma vs ffmpeg ({width}x{height}, depth={depth}, \
26778+ cq={cq}, narrow-kernel hits {narrow})"
26779+ );
26780+ assert_eq!(
26781+ got.u, want.u,
26782+ "{NAME} frame {i} U vs ffmpeg ({width}x{height}, depth={depth}, \
26783+ cq={cq}, narrow-kernel hits {narrow})"
26784+ );
26785+ assert_eq!(
26786+ got.v, want.v,
26787+ "{NAME} frame {i} V vs ffmpeg ({width}x{height}, depth={depth}, \
26788+ cq={cq}, narrow-kernel hits {narrow})"
26789+ );
26790+ }
26791+ compared += 1;
26792+ narrow_by_depth[di] += narrow;
26793+ narrow_by_shape[si] += narrow;
26794+ eprintln!(
26795+ "{NAME}: {width}x{height} depth={depth} cq={cq} {} frames full-plane \
26796+ exact, narrow-kernel hits {narrow}",
26797+ frames.len()
26798+ );
26799+ }
26800+ }
26801+ }
26802+ assert_eq!(
26803+ compared, 12,
26804+ "{NAME}: only {compared} of 12 arms were pixel-compared -- a refusal makes this \
26805+ gate vacuous"
26806+ );
26807+ assert!(
26808+ narrow_by_depth[0] > 0 && narrow_by_depth[1] > 0,
26809+ "{NAME}: no rect-chroma narrow kernel fired at 8-bit ({}) or 10-bit ({}) -- the \
26810+ recipe lost the shape this gate pins",
26811+ narrow_by_depth[0], narrow_by_depth[1]
26812+ );
26813+ assert!(
26814+ narrow_by_shape[0] > 0 && narrow_by_shape[1] > 0,
26815+ "{NAME}: the shape fired in only one orientation (192x128 {}, 128x192 {})",
26816+ narrow_by_shape[0], narrow_by_shape[1]
26817+ );
26818+ }
2662126819 }
lanes/rectchroma2-r1.report.mdadded+87 -0
@@ -0,0 +1,87 @@
1+# lane-rectchroma2 r1 -- rect INTER blocks predicted chroma with the WIDE kernel
2+
3+## Premise re-measured first
4+
5+lane-interedge r1's residue reproduced on this tree (main 2c04819 + lane-cdef + lane-golomb
6+173b793): mandelbrot 192x128 (the CONTROL size -- zero frame-edge nodes), 6 frames,
7+`--enable-rect-partitions=1 --min-partition-size=8 --enable-tx-size-search=0 --lag-in-frames=0`,
8+intra tools off, cq 20/32/45, 8- and 10-bit: **luma exact, chroma differs on frames 2..5 in all
9+six arms**. Streams hashed twice, identical.
10+
11+EVIDENCE: `~/.cache/rectchroma2-tmp/c192-128-{8,10}-{20,32,45}.obu` (each sha256 twice, equal)
12+| `decode_probe` with `EC_AV1_FINAL_DUMP` vs `ffmpeg -pix_fmt yuv420p[10le]`, every decode-order
13+frame, per plane | e.g. cq32 8-bit: `[(2,'chroma (0,32)..(1,40) n=17'), (4,...), (5,...)]`, luma
14+exact in all 6 arms.
15+
16+## Stage bisect
17+
18+Regenerated the same recipe with `--loopfilter-control=0` (deblock off; CDEF/LR already off in
19+that recipe): **the chroma mismatch survives unchanged** -> not a filter-stage defect, so the
20+charter's suspect (d) (chroma deblock levels / uv tx grid for rect inter blocks) is exonerated.
21+The surviving diffs are +-1 on scattered samples inside 4-wide-by-8-tall and 8-wide-by-4-tall
22+CHROMA regions (e.g. frame 4: chroma x32..35 rows 26..39, and x48..55 rows 16..19) -- i.e. the
23+chroma halves of 8x16 and 16x8 LUMA blocks.
24+
25+EVIDENCE: `~/.cache/rectchroma2-tmp/n192-128-8-32.obu` (`gen_nolf.sh`) | decode + full-plane
26+compare | `MISMATCH [(2,'chroma ... n=15'), (4,...n=36), (5,...n=45)]`, luma exact.
27+
28+## Root cause (charter suspect (a), confirmed)
29+
30+`crates/ec-av1/src/decode.rs` `decode_inter_block` predicts a RECTANGULAR block over its
31+enclosing SQUARE buffer (`side`x`side`, chroma `chroma_side`x`chroma_side`; `write_w`/`write_h`
32+govern only the pixel write -- the lane-partitions r1 corner-cut). The 4-tap decision lived
33+inside `mc::predict_with_filters` and read that BUFFER's dimensions. libaom
34+`av1_get_interp_filter_params_with_block_size` (reconinter.h, called per axis from
35+`inter_predictor` with `w` then `h`) reads the PREDICTION BLOCK's dimensions: `w <= 4` ->
36+`av1_interp_4tap[0]` (SHARP and REGULAR both) / `[1]` (SMOOTH). Luma is never <= 4 wide on this
37+path, so only chroma of a rect block (4x8 / 8x4 / 4x16 ...) was affected -- exactly the
38+"luma exact, chroma wrong" signature.
39+
40+- `crates/ec-av1/src/mc.rs`: `predict_with_filters_kern` / `predict_scaled_kern` /
41+ `predict_compound_intermediate_kern` -- the existing three entry points keep their signatures
42+ and delegate with `kern = block dims`; `horizontal_scaled_pass` takes `kern_w`.
43+- `crates/ec-av1/src/mc.rs`: `RECT_NARROW_KERN_HITS` + `rect_narrow_kern_hits()` /
44+ `reset_rect_narrow_kern_hits()` / `note_narrow_kern()` -- counts predictions whose kernel
45+ choice DIFFERS from what the square buffer would have given (one bump per prediction).
46+- `crates/ec-av1/src/decode.rs`: the 12 prediction calls inside `decode_inter_block` now pass
47+ `write_w/write_h` (luma) and `write_chroma_w/write_chroma_h` (chroma) as the kernel dims.
48+
49+Class sweep: every other `mc::predict*` call site passes a buffer whose dims ARE the block's
50+(`obmc_neighbour_pred` takes the neighbour's true w/h; the 8x8 leaf path is square, chroma 4x4;
51+the CfL bilinear path is unrelated), so no sibling site needed the change.
52+
53+## Gate (GREEN)
54+
55+```
56+CARGO_TARGET_DIR=$HOME/.cache/cargo-target-rectchroma2 EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 \
57+PATH="$HOME/.cache/aom-oracle/build:$PATH" cargo test -p ec-av1 --lib narrow_kernel -- --nocapture
58+```
59+`a_real_aomenc_rect_inter_block_predicts_chroma_with_the_narrow_kernel_pixel_exact`
60+(`crates/ec-av1/src/stream.rs`): real aomenc, mandelbrot 192x128 AND its transposed twin
61+128x192 (so 4x8 and 8x4 chroma both fire), 8- and 10-bit, cq 20/32/45, 6 frames,
62+`--lag-in-frames=0` so decode order == display order and EVERY frame is compared on Y, U AND V
63+against ffmpeg. CDEF and loop restoration left ON. Streams encoded twice and asserted equal.
64+`compared == 12` is a hard assert (a refusal fails the gate, never SKIPs), and the narrow-kernel
65+counter -- reset per attempt, read only on compared attempts -- must be nonzero at BOTH depths
66+and in BOTH orientations.
67+
68+EVIDENCE: gate stdout | 12 aomenc -> ec-av1 -> ffmpeg attempts, 6 frames each, all three planes
69+| `12/12 arms 6 frames full-plane exact; narrow-kernel hits 24/4/16 (192x128 8-bit cq20/32/45),
70+18/26/36 (10-bit), 42/20/18 and 36/36/34 for 128x192` -- 0 refusals, 0 out-of-scope mismatches.
71+
72+Before the fix the SAME recipe mismatched chroma in every arm (the premise sweep above), so the
73+gate is not vacuous.
74+
75+## Refusals
76+None lifted (no inventory string covers this defect -- it was a wrong-pixels defect behind an
77+already-accepted path). `refusal_inventory.rs`/`gate_coverage.rs` untouched by intent, both green
78+in the suite below.
79+
80+## Suite
81+`$HOME/.cache/rectchroma2-suite-r1.log`: **388 passed, 0 failed, 35 ignored** (1668s), including the new gate. Baseline before this round on the same tree shape was 387/0/35 (this round adds one gate).
82+
83+## Residue
84+- accepted: `predict_scaled_kern` (scaled reference / superres) got the same fix by construction
85+ but is not exercised by this gate -- superres rect-chroma has no aomenc recipe on this lane.
86+- deferred(lane-interedge merge): that lane's frame-edge gate can now become a FULL-PLANE arm;
87+ its luma-only compare was a workaround for exactly this defect.