Merge branch 'lane-rectchroma': a 4:1 strip's first transform split is a 2:1 rect unit (was tiled square, silent wrong pixels); chroma coefficient tables for 32x8/8x32/8x4/4x8
Browse files at this commit4 changed files +563 -1
- crates/ec-av1/src/decode.rs +68 -1
- crates/ec-av1/src/refusal_inventory.rs +1 -0
- crates/ec-av1/src/stream.rs +353 -0
- lanes/rectchroma-r1.report.md +141 -0
crates/ec-av1/src/decode.rsmodified+68 -1
| @@ -942,6 +942,22 @@ pub(crate) fn rect_split_sb_interior_tu_hits() -> usize { | |||
| 942 | RECT_SPLIT_SB_INTERIOR_TU_HITS.with(|c| c.get()) | 942 | RECT_SPLIT_SB_INTERIOR_TU_HITS.with(|c| c.get()) |
| 943 | } | 943 | } |
| 944 | 944 | ||
| 945 | +// Per-shape hit counts for the rect chroma transforms lane-rectchroma r1 | ||
| 946 | +// wired into [`decode_rect_split`] -- the shapes a split-transform strip's | ||
| 947 | +// chroma half takes that had no coefficient tables before (index order: | ||
| 948 | +// 32x8, 8x32, 8x4, 4x8). One counter per shape because a gate that only | ||
| 949 | +// proves the pair it happens to hit cannot catch a transposed scan/context | ||
| 950 | +// table (class scan-weights-cross-axis). | ||
| 951 | +thread_local! { | ||
| 952 | + static RECT_SPLIT_CHROMA_SHAPE_HITS: std::cell::Cell<[usize; 4]> = | ||
| 953 | + const { std::cell::Cell::new([0; 4]) }; | ||
| 954 | +} | ||
| 955 | + | ||
| 956 | +/// Current value of [`RECT_SPLIT_CHROMA_SHAPE_HITS`] (32x8, 8x32, 8x4, 4x8). | ||
| 957 | +pub(crate) fn rect_split_chroma_shape_hits() -> [usize; 4] { | ||
| 958 | + RECT_SPLIT_CHROMA_SHAPE_HITS.with(|c| c.get()) | ||
| 959 | +} | ||
| 960 | + | ||
| 945 | // How many HORZ/VERT intra strips actually predicted with filter intra | 961 | // How many HORZ/VERT intra strips actually predicted with filter intra |
| 946 | // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name | 962 | // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name |
| 947 | // ("this decoder predicts square-only") until `predict_filter_intra` took | 963 | // ("this decoder predicts square-only") until `predict_filter_intra` took |
| @@ -4967,8 +4983,41 @@ fn decode_rect_split( | |||
| 4967 | (8, 16) => Some((TxbSet::ChromaRect16x8, &SCAN_8X16[..])), | 4983 | (8, 16) => Some((TxbSet::ChromaRect16x8, &SCAN_8X16[..])), |
| 4968 | (32, 16) => Some((TxbSet::ChromaRect32x16, &SCAN_32X16[..])), | 4984 | (32, 16) => Some((TxbSet::ChromaRect32x16, &SCAN_32X16[..])), |
| 4969 | (16, 32) => Some((TxbSet::ChromaRect32x16, &SCAN_16X32[..])), | 4985 | (16, 32) => Some((TxbSet::ChromaRect32x16, &SCAN_16X32[..])), |
| 4986 | + // lane-rectchroma r1: the 1:4 superblock strips (64x16/16x64, | ||
| 4987 | + // `decode_block_rect64`'s `strip64!` arm) and the 8x16 left rect of a | ||
| 4988 | + // 16x16 `VERT_B` reach here once their tx depth is non-zero -- the | ||
| 4989 | + // shapes their chroma half takes. `get_txsize_entropy_ctx(TX_32X8)` | ||
| 4990 | + // is `(0 + 4 + 1) >> 1 == 2`, the 16x16 CDF set (eob alphabet 256), | ||
| 4991 | + // exactly as the unsplit 1:4 path already picks it; `TX_8X4` reduces | ||
| 4992 | + // to `(0 + 1 + 1) >> 1 == 1`, the 8x8 set `ChromaRect8x4` carries | ||
| 4993 | + // (eob 32), as `decode_leaf_rect`'s own chroma half already does. | ||
| 4994 | + (32, 8) => Some((TxbSet::Chroma16, &SCAN_32X8[..])), | ||
| 4995 | + (8, 32) => Some((TxbSet::Chroma16, &SCAN_8X32[..])), | ||
| 4996 | + (8, 4) => Some((TxbSet::ChromaRect8x4, &SCAN_8X4[..])), | ||
| 4997 | + (4, 8) => Some((TxbSet::ChromaRect8x4, &SCAN_4X8[..])), | ||
| 4970 | _ => None, | 4998 | _ => None, |
| 4971 | }; | 4999 | }; |
| 5000 | + if !m.skip { | ||
| 5001 | + if let Some(i) = match (chroma_w, chroma_h) { | ||
| 5002 | + (32, 8) => Some(0), | ||
| 5003 | + (8, 32) => Some(1), | ||
| 5004 | + (8, 4) => Some(2), | ||
| 5005 | + (4, 8) => Some(3), | ||
| 5006 | + _ => None, | ||
| 5007 | + } { | ||
| 5008 | + RECT_SPLIT_CHROMA_SHAPE_HITS.with(|c| { | ||
| 5009 | + let mut hits = c.get(); | ||
| 5010 | + hits[i] += 1; | ||
| 5011 | + c.set(hits); | ||
| 5012 | + }); | ||
| 5013 | + } | ||
| 5014 | + if chroma.is_none() { | ||
| 5015 | + // Diagnostic for the next caller that lands here (class | ||
| 5016 | + // refusal-names-a-correlate: the message names the tool, not the | ||
| 5017 | + // shape); the refusal below keeps its inventory-pinned wording. | ||
| 5018 | + eprintln!("EC_RECTCHROMA_GAP luma={bw}x{bh} tx={tx} chroma={chroma_w}x{chroma_h}"); | ||
| 5019 | + } | ||
| 5020 | + } | ||
| 4972 | // lane-rectsplit r2 (verifier finding): with both callers wired | 5021 | // lane-rectsplit r2 (verifier finding): with both callers wired |
| 4973 | // (`decode_block_rect`'s 32x16/16x32 and `decode_block_rect64`'s | 5022 | // (`decode_block_rect`'s 32x16/16x32 and `decode_block_rect64`'s |
| 4974 | // 64x32/32x64) every shape that reaches here has a table above, so this | 5023 | // 64x32/32x64) every shape that reaches here has a table above, so this |
| @@ -6243,7 +6292,25 @@ fn decode_block_rect64( | |||
| 6243 | // transform through the very same per-unit path as its 32x32-level | 6292 | // transform through the very same per-unit path as its 32x32-level |
| 6244 | // sibling (`sub_tx_size_map[TX_64X32] == TX_32X32`, square from the | 6293 | // sibling (`sub_tx_size_map[TX_64X32] == TX_32X32`, square from the |
| 6245 | // first step on, so `bw.min(bh) >> (depth - 1)` names the unit). | 6294 | // first step on, so `bw.min(bh) >> (depth - 1)` names the unit). |
| 6246 | - let tx = bw.min(bh) >> (depth - 1); | 6295 | + // lane-rectchroma r1: `sub_tx_size_map[TX_64X16] == TX_32X16`, NOT a |
| 6296 | + // square -- a 4:1 strip's first transform split is still a 2:1 RECT | ||
| 6297 | + // unit, and only the SECOND step reaches a square (TX_16X16). The | ||
| 6298 | + // 2:1 formula below (square from the first step on) named 16x16 units | ||
| 6299 | + // for a depth-1 64x16 strip, which decoded 2 chroma-32x8 strips of | ||
| 6300 | + // the band fixture with the wrong luma tiling. depth 1 on a 4:1 strip | ||
| 6301 | + // is refused by name; depth >= 2 is square, one step later. | ||
| 6302 | + let is_1to4 = bw.max(bh) / bw.min(bh) == 4; | ||
| 6303 | + if is_1to4 && depth == 1 && !skip { | ||
| 6304 | + return Err(unsupported( | ||
| 6305 | + "a coded 1:4 HORZ_4/VERT_4 strip whose transform splits only once (the unit is \ | ||
| 6306 | + still a 2:1 rect, not a square)", | ||
| 6307 | + )); | ||
| 6308 | + } | ||
| 6309 | + let tx = if is_1to4 { | ||
| 6310 | + bw.min(bh) >> (depth - 2) | ||
| 6311 | + } else { | ||
| 6312 | + bw.min(bh) >> (depth - 1) | ||
| 6313 | + }; | ||
| 6247 | if std::env::var_os("EC_SBPART_DUMP64").is_some() { | 6314 | if std::env::var_os("EC_SBPART_DUMP64").is_some() { |
| 6248 | eprintln!( | 6315 | eprintln!( |
| 6249 | "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \ | 6316 | "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \ |
crates/ec-av1/src/refusal_inventory.rsmodified+1 -0
| @@ -32,6 +32,7 @@ const CAPABILITY_CLAIMS: &[&str] = &[ | |||
| 32 | #[cfg(test)] | 32 | #[cfg(test)] |
| 33 | const REFUSALS: &[&str] = &[ | 33 | const REFUSALS: &[&str] = &[ |
| 34 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", | 34 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", |
| 35 | + "a coded 1:4 HORZ_4/VERT_4 strip whose transform splits only once (the unit is still a 2:1 rect, not a square)", | ||
| 35 | "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect prediction is not ported)", | 36 | "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect prediction is not ported)", |
| 36 | "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", | 37 | "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", |
| 37 | "a 1:4 partition below 16x16 (PARTITION_HORZ_4/VERT_4, four 16x4/4x16 strips -- this decoder codes NONE, HORZ, VERT, the four AB arms and a clean split at 16x16)", | 38 | "a 1:4 partition below 16x16 (PARTITION_HORZ_4/VERT_4, four 16x4/4x16 strips -- this decoder codes NONE, HORZ, VERT, the four AB arms and a clean split at 16x16)", |
crates/ec-av1/src/stream.rsmodified+353 -0
| @@ -17617,4 +17617,357 @@ mod tests { | |||
| 17617 | None, | 17617 | None, |
| 17618 | ); | 17618 | ); |
| 17619 | } | 17619 | } |
| 17620 | + | ||
| 17621 | + /// lane-rectchroma r1: a real `aomenc` stream in which a HORZ/VERT strip | ||
| 17622 | + /// splits its transform (`--enable-tx-size-search` left ON) and whose | ||
| 17623 | + /// chroma half is one of the four rect shapes that had NO coefficient | ||
| 17624 | + /// tables in [`crate::decode`] before this round -- 32x8 / 8x32 (the 1:4 | ||
| 17625 | + /// superblock strips 64x16 / 16x64) and 8x4 / 4x8 (the 8x16 / 16x8 rect | ||
| 17626 | + /// of a 16x16-level AB partition). Every such strip refused by name | ||
| 17627 | + /// ("a coded HORZ/VERT strip whose chroma transform has no rect | ||
| 17628 | + /// coefficient tables here"), which is where both ReelC extracts stopped. | ||
| 17629 | + /// | ||
| 17630 | + /// Per-shape counters, deltas taken only over attempts that then compared | ||
| 17631 | + /// pixel-exact (class counter-from-refused-stream), on 8 AND 10 bit (his | ||
| 17632 | + /// films are `yuv420p10le`). Odd seeds render the source transposed so | ||
| 17633 | + /// the 32x8/8x32 and 8x4/4x8 pairs both fire -- a single-orientation | ||
| 17634 | + /// sweep cannot catch a transposed scan table (class | ||
| 17635 | + /// scan-weights-cross-axis). | ||
| 17636 | + #[test] | ||
| 17637 | + fn a_real_aomenc_stream_with_a_coded_strip_whose_chroma_is_a_4to1_or_sub8_rect_decodes_pixel_exact() | ||
| 17638 | + { | ||
| 17639 | + const NAME: &str = "a_real_aomenc_stream_with_a_coded_strip_whose_chroma_is_a_4to1_or_sub8_rect_decodes_pixel_exact"; | ||
| 17640 | + // Seed 46 mismatches ffmpeg at cq 32 on BOTH depths while carrying | ||
| 17641 | + // ZERO 1:4 strips -- an open defect of another shape, being diagnosed | ||
| 17642 | + // by lane-band46. Excluded here by name so this gate's | ||
| 17643 | + // `out_of_scope_mismatch` assert stays a hard 0 instead of swallowing | ||
| 17644 | + // it; the pin below decodes exactly that seed and is what un-ignoring | ||
| 17645 | + // will prove. | ||
| 17646 | + const EXCLUDED_SEEDS: &[u32] = &[46]; | ||
| 17647 | + let _gate_lock = lock_gate_counters(); | ||
| 17648 | + if !have_ffmpeg() { | ||
| 17649 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 17650 | + return; | ||
| 17651 | + } | ||
| 17652 | + if !have_aomenc() { | ||
| 17653 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 17654 | + return; | ||
| 17655 | + } | ||
| 17656 | + let (width, height) = (192usize, 128usize); | ||
| 17657 | + let n_attempts: u32 = std::env::var("EC_RECTCHROMA_GATE_ATTEMPTS") | ||
| 17658 | + .ok() | ||
| 17659 | + .and_then(|s| s.parse().ok()) | ||
| 17660 | + .unwrap_or(20); | ||
| 17661 | + // 32x8, 8x32, 8x4, 4x8, summed over both bit depths. | ||
| 17662 | + let mut proved = [0usize; 4]; | ||
| 17663 | + let mut matched = 0u32; | ||
| 17664 | + let mut refusals = 0u32; | ||
| 17665 | + // Diagnostics: how much of the territory the COMPARED streams carried | ||
| 17666 | + // at all, so a zero above reads as "recipe picked nothing" rather | ||
| 17667 | + // than "the shape never split" without another run. | ||
| 17668 | + let (mut split_strips, mut rect4_strips) = (0usize, 0usize); | ||
| 17669 | + let mut all_rect4 = 0usize; | ||
| 17670 | + // Asserted separately: this is the gate that takes `enable-1to4- | ||
| 17671 | + // partitions` off `gate_coverage::NEVER_EXERCISED_10BIT`, so the | ||
| 17672 | + // 10-bit half has to carry the shape on its own. | ||
| 17673 | + let mut rect4_strips_10bit = 0usize; | ||
| 17674 | + let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32); | ||
| 17675 | + // Attempts that stopped at the new named refusal for a 1:4 strip | ||
| 17676 | + // whose transform splits once (see the assert at the end). | ||
| 17677 | + let mut depth1_refusals = 0u32; | ||
| 17678 | + for (bit_depth, cq) in [(8u32, 45u32), (8, 32), (8, 60), (10, 45), (10, 32), (10, 60)] { | ||
| 17679 | + for attempt in 0..n_attempts { | ||
| 17680 | + let seed = 42 + attempt; | ||
| 17681 | + if EXCLUDED_SEEDS.contains(&seed) { | ||
| 17682 | + continue; | ||
| 17683 | + } | ||
| 17684 | + let stream = rectchroma_stream(bit_depth, cq, attempt, width, height); | ||
| 17685 | + let before = crate::decode::rect_split_chroma_shape_hits(); | ||
| 17686 | + let split_before = crate::decode::rect_split_tx_hits(); | ||
| 17687 | + let rect4_before = ( | ||
| 17688 | + crate::decode::sb_rect4_horz_hits(), | ||
| 17689 | + crate::decode::sb_rect4_vert_hits(), | ||
| 17690 | + ); | ||
| 17691 | + let frames = match decode_stream(&stream) { | ||
| 17692 | + Err(e) => { | ||
| 17693 | + let msg = e.to_string(); | ||
| 17694 | + assert!( | ||
| 17695 | + msg.contains("unsupported"), | ||
| 17696 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit seed \ | ||
| 17697 | + {seed}): {msg}" | ||
| 17698 | + ); | ||
| 17699 | + refusals += 1; | ||
| 17700 | + if msg.contains("splits only once") { | ||
| 17701 | + depth1_refusals += 1; | ||
| 17702 | + } | ||
| 17703 | + all_rect4 += (crate::decode::sb_rect4_horz_hits() - rect4_before.0) | ||
| 17704 | + + (crate::decode::sb_rect4_vert_hits() - rect4_before.1); | ||
| 17705 | + let r4 = (crate::decode::sb_rect4_horz_hits() - rect4_before.0) | ||
| 17706 | + + (crate::decode::sb_rect4_vert_hits() - rect4_before.1); | ||
| 17707 | + eprintln!( | ||
| 17708 | + "{NAME}: {bit_depth}-bit cq {cq} seed {seed} refusal (1:4 strips so \ | ||
| 17709 | + far {r4}): {msg}" | ||
| 17710 | + ); | ||
| 17711 | + continue; | ||
| 17712 | + } | ||
| 17713 | + Ok(frames) => frames, | ||
| 17714 | + }; | ||
| 17715 | + let after = crate::decode::rect_split_chroma_shape_hits(); | ||
| 17716 | + if (0..4).any(|k| after[k] > before[k]) { | ||
| 17717 | + eprintln!( | ||
| 17718 | + "{NAME}: {bit_depth}-bit cq {cq} seed {seed} carries chroma shapes \ | ||
| 17719 | + 32x8={} 8x32={} 8x4={} 4x8={}", | ||
| 17720 | + after[0] - before[0], | ||
| 17721 | + after[1] - before[1], | ||
| 17722 | + after[2] - before[2], | ||
| 17723 | + after[3] - before[3] | ||
| 17724 | + ); | ||
| 17725 | + } | ||
| 17726 | + let rect4_now = (crate::decode::sb_rect4_horz_hits() - rect4_before.0) | ||
| 17727 | + + (crate::decode::sb_rect4_vert_hits() - rect4_before.1); | ||
| 17728 | + let reference = if bit_depth == 10 { | ||
| 17729 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) | ||
| 17730 | + } else { | ||
| 17731 | + ffmpeg_decode_sequence(&stream, width, height, frames.len()) | ||
| 17732 | + }; | ||
| 17733 | + assert_eq!(frames.len(), reference.len(), "{NAME}: frame count"); | ||
| 17734 | + if rect4_now == 0 { | ||
| 17735 | + // Out of this gate's territory (same rule the sibling | ||
| 17736 | + // superblock-1:4 gate applies): aomenc picked no 1:4 | ||
| 17737 | + // strip at all, so the attempt can neither prove nor | ||
| 17738 | + // disprove this round's shape. Counted and PRINTED, never | ||
| 17739 | + // silently dropped -- selection is on "the stream carries | ||
| 17740 | + // the feature", never on "the stream decoded correctly". | ||
| 17741 | + out_of_scope += 1; | ||
| 17742 | + if frames.iter().zip(&reference).any(|(g, w)| { | ||
| 17743 | + g.y != w.y || g.u != w.u || g.v != w.v | ||
| 17744 | + }) { | ||
| 17745 | + out_of_scope_mismatch += 1; | ||
| 17746 | + eprintln!( | ||
| 17747 | + "{NAME}: {bit_depth}-bit cq {cq} seed {seed} MISMATCHES with zero \ | ||
| 17748 | + 1:4 strips -- a pre-existing defect of another shape, not this \ | ||
| 17749 | + gate's arms" | ||
| 17750 | + ); | ||
| 17751 | + } | ||
| 17752 | + continue; | ||
| 17753 | + } | ||
| 17754 | + for (i, (got, want)) in frames.iter().zip(&reference).enumerate() { | ||
| 17755 | + assert_eq!( | ||
| 17756 | + got.y, want.y, | ||
| 17757 | + "{NAME} frame {i} luma vs ffmpeg ({bit_depth}-bit cq {cq} seed {seed})" | ||
| 17758 | + ); | ||
| 17759 | + assert_eq!( | ||
| 17760 | + got.u, want.u, | ||
| 17761 | + "{NAME} frame {i} U vs ffmpeg ({bit_depth}-bit cq {cq} seed {seed})" | ||
| 17762 | + ); | ||
| 17763 | + assert_eq!( | ||
| 17764 | + got.v, want.v, | ||
| 17765 | + "{NAME} frame {i} V vs ffmpeg ({bit_depth}-bit cq {cq} seed {seed})" | ||
| 17766 | + ); | ||
| 17767 | + } | ||
| 17768 | + for k in 0..4 { | ||
| 17769 | + proved[k] += after[k] - before[k]; | ||
| 17770 | + } | ||
| 17771 | + split_strips += crate::decode::rect_split_tx_hits() - split_before; | ||
| 17772 | + let rect4 = (crate::decode::sb_rect4_horz_hits() - rect4_before.0) | ||
| 17773 | + + (crate::decode::sb_rect4_vert_hits() - rect4_before.1); | ||
| 17774 | + rect4_strips += rect4; | ||
| 17775 | + if bit_depth == 10 { | ||
| 17776 | + rect4_strips_10bit += rect4; | ||
| 17777 | + } | ||
| 17778 | + matched += 1; | ||
| 17779 | + } | ||
| 17780 | + } | ||
| 17781 | + eprintln!( | ||
| 17782 | + "{NAME}: {matched} pixel-exact matches, {refusals} named refusals out of \ | ||
| 17783 | + {} attempts; chroma shapes proved 32x8={} 8x32={} 8x4={} 4x8={}; compared \ | ||
| 17784 | + streams carried {split_strips} split-transform strips and {rect4_strips} \ | ||
| 17785 | + superblock 1:4 strips ({all_rect4} more in refused streams); {out_of_scope} \ | ||
| 17786 | + attempts carried no 1:4 strip ({out_of_scope_mismatch} of them mismatched -- \ | ||
| 17787 | + other shapes' defects)", | ||
| 17788 | + 6 * n_attempts, | ||
| 17789 | + proved[0], | ||
| 17790 | + proved[1], | ||
| 17791 | + proved[2], | ||
| 17792 | + proved[3] | ||
| 17793 | + ); | ||
| 17794 | + assert_eq!( | ||
| 17795 | + out_of_scope_mismatch, 0, | ||
| 17796 | + "{NAME}: {out_of_scope_mismatch} attempts carrying no 1:4 strip mismatched \ | ||
| 17797 | + ffmpeg -- a defect of another shape, not out of scope for the suite (the one \ | ||
| 17798 | + known case, seed 46, is in EXCLUDED_SEEDS and pinned separately)" | ||
| 17799 | + ); | ||
| 17800 | + assert!( | ||
| 17801 | + matched > 0, | ||
| 17802 | + "{NAME}: every attempt refused; the gate never decoded a stream" | ||
| 17803 | + ); | ||
| 17804 | + assert!( | ||
| 17805 | + rect4_strips_10bit > 0, | ||
| 17806 | + "{NAME}: no superblock 1:4 strip in any pixel-exact 10-BIT stream -- this gate is \ | ||
| 17807 | + what claims 10-bit coverage for enable-1to4-partitions" | ||
| 17808 | + ); | ||
| 17809 | + assert!( | ||
| 17810 | + rect4_strips > 0, | ||
| 17811 | + "{NAME}: no superblock 1:4 strip in any pixel-exact stream -- recipe lost its \ | ||
| 17812 | + territory, gate proved nothing this run" | ||
| 17813 | + ); | ||
| 17814 | + // r1's actual capability delta. Before this round a 1:4 strip whose | ||
| 17815 | + // transform depth is 1 was decoded as if its units were SQUARE | ||
| 17816 | + // (`bw.min(bh) >> (depth - 1)`), because `sub_tx_size_map[TX_64X16]` | ||
| 17817 | + // is TX_32X16, a 2:1 RECT, not TX_16X16 -- 8-bit cq 45 seed 42 of | ||
| 17818 | + // this very recipe decoded 2 such strips and MISMATCHED ffmpeg on | ||
| 17819 | + // frame 0 luma. It is now refused by name (rect luma transform units | ||
| 17820 | + // inside a split strip are unported; the chroma half's 32x8/8x32 | ||
| 17821 | + // tables this round wired are in place for it). This assert is what | ||
| 17822 | + // keeps that from silently regressing to a wrong-pixel decode. | ||
| 17823 | + assert!( | ||
| 17824 | + depth1_refusals > 0, | ||
| 17825 | + "{NAME}: no attempt reached a depth-1 1:4 split strip -- the recipe no longer \ | ||
| 17826 | + covers the shape this round fixed" | ||
| 17827 | + ); | ||
| 17828 | + eprintln!("{NAME}: {depth1_refusals} attempts refused the depth-1 1:4 split strip by name"); | ||
| 17829 | + } | ||
| 17830 | + | ||
| 17831 | + /// The chroma-rect gate's fixture + aomenc recipe for one attempt, shared | ||
| 17832 | + /// with the seed-46 pin test below so the pin cannot drift from the gate. | ||
| 17833 | + fn rectchroma_stream( | ||
| 17834 | + bit_depth: u32, | ||
| 17835 | + cq: u32, | ||
| 17836 | + attempt: u32, | ||
| 17837 | + width: usize, | ||
| 17838 | + height: usize, | ||
| 17839 | + ) -> Vec<u8> { | ||
| 17840 | + const NAME: &str = "rectchroma_stream"; | ||
| 17841 | + let seed = 42 + attempt; | ||
| 17842 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 17843 | + // `gradients_source`, the content the sibling split-transform | ||
| 17844 | + // superblock gate uses. A band/noise `geq` fixture was tried | ||
| 17845 | + // first (r1) and gave 12/12 pixel-exact streams carrying ZERO | ||
| 17846 | + // 1:4 strips -- vacuous. Odd attempts render it transposed so | ||
| 17847 | + // HORZ_4 and VERT_4 both appear (class scan-weights-cross-axis). | ||
| 17848 | + let bands = format!( | ||
| 17849 | + "geq=lum='mod(floor(Y/16),2)*160+48':cb=128:cr=128,noise=alls=10:all_seed={seed}" | ||
| 17850 | + ); | ||
| 17851 | + let source = if attempt % 2 == 0 { | ||
| 17852 | + format!("color=c=black:size={width}x{height}:duration=0.04:rate=25,{bands}") | ||
| 17853 | + } else { | ||
| 17854 | + format!( | ||
| 17855 | + "color=c=black:size={height}x{width}:duration=0.04:rate=25,{bands},transpose=1" | ||
| 17856 | + ) | ||
| 17857 | + }; | ||
| 17858 | + let y4m = Command::new("ffmpeg") | ||
| 17859 | + .args([ | ||
| 17860 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", "0.04", "-pix_fmt", | ||
| 17861 | + pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 17862 | + ]) | ||
| 17863 | + .stdin(Stdio::null()) | ||
| 17864 | + .stdout(Stdio::piped()) | ||
| 17865 | + .stderr(Stdio::piped()) | ||
| 17866 | + .output() | ||
| 17867 | + .expect("ffmpeg failed to run"); | ||
| 17868 | + assert!( | ||
| 17869 | + y4m.status.success(), | ||
| 17870 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 17871 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 17872 | + ); | ||
| 17873 | + let cq_arg = format!("--cq-level={cq}"); | ||
| 17874 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 17875 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 17876 | + let mut child = Command::new(aomenc_path()) | ||
| 17877 | + .args([ | ||
| 17878 | + "--codec=av1", | ||
| 17879 | + "--passes=1", | ||
| 17880 | + "--end-usage=q", | ||
| 17881 | + &cq_arg, | ||
| 17882 | + "--cpu-used=0", | ||
| 17883 | + "--threads=1", | ||
| 17884 | + "--row-mt=0", | ||
| 17885 | + "--sb-size=64", | ||
| 17886 | + &depth_arg, | ||
| 17887 | + &input_depth_arg, | ||
| 17888 | + "--enable-rect-partitions=1", | ||
| 17889 | + // AB off: it competes with 1:4 in the RD search (with | ||
| 17890 | + // AB on, 0 superblock 1:4 strips appeared in 16 | ||
| 17891 | + // compared streams), and AB below 16x16 is another | ||
| 17892 | + // lane's refusal. | ||
| 17893 | + "--enable-ab-partitions=0", | ||
| 17894 | + "--enable-1to4-partitions=1", | ||
| 17895 | + // 16, not 8: with 8 every seed of this recipe stops | ||
| 17896 | + // at a 32x32-level PARTITION_HORZ_4/VERT_4 (partition | ||
| 17897 | + // values 8/9, 32x8/8x32 luma strips), a shape this | ||
| 17898 | + // decoder does not code at all yet -- 12/12 attempts | ||
| 17899 | + // refused before a pixel was compared (measured r1). | ||
| 17900 | + // At 16 the 1:4 split happens at the superblock, the | ||
| 17901 | + // 64x16/16x64 strips whose chroma half is 32x8/8x32. | ||
| 17902 | + "--min-partition-size=16", | ||
| 17903 | + "--max-partition-size=64", | ||
| 17904 | + "--enable-restoration=0", | ||
| 17905 | + "--enable-palette=0", | ||
| 17906 | + "--deltaq-mode=0", | ||
| 17907 | + "--enable-filter-intra=0", | ||
| 17908 | + "--enable-cfl-intra=0", | ||
| 17909 | + "--enable-intrabc=0", | ||
| 17910 | + "--obu", | ||
| 17911 | + "-o", | ||
| 17912 | + "-", | ||
| 17913 | + "-", | ||
| 17914 | + ]) | ||
| 17915 | + .stdin(Stdio::piped()) | ||
| 17916 | + .stdout(Stdio::piped()) | ||
| 17917 | + .stderr(Stdio::piped()) | ||
| 17918 | + .spawn() | ||
| 17919 | + .expect("aomenc failed to start"); | ||
| 17920 | + child | ||
| 17921 | + .stdin | ||
| 17922 | + .take() | ||
| 17923 | + .expect("aomenc stdin") | ||
| 17924 | + .write_all(&y4m.stdout) | ||
| 17925 | + .expect("writing y4m to aomenc"); | ||
| 17926 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 17927 | + assert!( | ||
| 17928 | + out.status.success(), | ||
| 17929 | + "{NAME}: aomenc refused the fixture: {}", | ||
| 17930 | + String::from_utf8_lossy(&out.stderr) | ||
| 17931 | + ); | ||
| 17932 | + out.stdout | ||
| 17933 | + } | ||
| 17934 | + | ||
| 17935 | + /// PIN for the one stream the chroma-rect gate excludes: cq 32 seed 46 | ||
| 17936 | + /// mismatches ffmpeg at BOTH bit depths while carrying zero 1:4 strips, | ||
| 17937 | + /// so the defect belongs to some other shape -- the stream decodes, the | ||
| 17938 | + /// pixels are wrong. Undiagnosed; lane-band46 owns it. Un-ignoring this | ||
| 17939 | + /// test is the proof that it is fixed. | ||
| 17940 | + #[test] | ||
| 17941 | + #[ignore = "band fixture cq32 seed 46 mismatches ffmpeg with zero 1:4 strips (8- and 10-bit) -- undiagnosed, lane-band46"] | ||
| 17942 | + fn the_chroma_rect_gates_excluded_seed_46_decodes_pixel_exact() { | ||
| 17943 | + const NAME: &str = "the_chroma_rect_gates_excluded_seed_46_decodes_pixel_exact"; | ||
| 17944 | + let _gate_lock = lock_gate_counters(); | ||
| 17945 | + if !have_ffmpeg() { | ||
| 17946 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 17947 | + return; | ||
| 17948 | + } | ||
| 17949 | + if !have_aomenc() { | ||
| 17950 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 17951 | + return; | ||
| 17952 | + } | ||
| 17953 | + let (width, height) = (192usize, 128usize); | ||
| 17954 | + // seed 46 == attempt 4 of the gate's sweep, cq 32. | ||
| 17955 | + for bit_depth in [8u32, 10] { | ||
| 17956 | + let stream = rectchroma_stream(bit_depth, 32, 4, width, height); | ||
| 17957 | + let frames = decode_stream(&stream) | ||
| 17958 | + .unwrap_or_else(|e| panic!("{NAME}: {bit_depth}-bit seed 46 refused: {e}")); | ||
| 17959 | + let reference = if bit_depth == 10 { | ||
| 17960 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) | ||
| 17961 | + } else { | ||
| 17962 | + ffmpeg_decode_sequence(&stream, width, height, frames.len()) | ||
| 17963 | + }; | ||
| 17964 | + assert_eq!(frames.len(), reference.len(), "{NAME}: frame count"); | ||
| 17965 | + for (i, (got, want)) in frames.iter().zip(&reference).enumerate() { | ||
| 17966 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma ({bit_depth}-bit seed 46)"); | ||
| 17967 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U ({bit_depth}-bit seed 46)"); | ||
| 17968 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V ({bit_depth}-bit seed 46)"); | ||
| 17969 | + } | ||
| 17970 | + } | ||
| 17971 | + } | ||
| 17972 | + | ||
| 17620 | } | 17973 | } |
lanes/rectchroma-r1.report.mdadded+141 -0
| @@ -0,0 +1,141 @@ | |||
| 1 | +# lane-rectchroma r1 | ||
| 2 | + | ||
| 3 | +Branch `lane-rectchroma` off main `4a29b4e` (already contains lane-tx64x16 / lane-rectx / lane-sub8merge; no merge needed). | ||
| 4 | + | ||
| 5 | +## What the charter's premise turned out to be | ||
| 6 | + | ||
| 7 | +`decode_rect_split` (crates/ec-av1/src/decode.rs:4343) refused | ||
| 8 | +`"a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here"` | ||
| 9 | +for both ReelC extracts. The caller that reaches it with an unmapped chroma shape is | ||
| 10 | +`decode_block_rect64`'s `strip64!` arm (decode.rs:10333, `(64,16)`/`(16,64)` superblock | ||
| 11 | +1:4 strips -> chroma 32x8 / 8x32); the 16x16-level `VERT_B` 8x16 rect | ||
| 12 | +(decode.rs:9373 -> chroma 4x8) is the second, rarer one. | ||
| 13 | + | ||
| 14 | +## Changes | ||
| 15 | + | ||
| 16 | +- crates/ec-av1/src/decode.rs:4366 — four chroma shapes wired into the split-transform | ||
| 17 | + chroma map: 32x8 / 8x32 -> `TxbSet::Chroma16` + `SCAN_32X8`/`SCAN_8X32` (the set and | ||
| 18 | + scans the *unsplit* 1:4 path at decode.rs:5447 already uses, so no new table was | ||
| 19 | + transcribed), 8x4 / 4x8 -> `TxbSet::ChromaRect8x4` + `SCAN_8X4`/`SCAN_4X8` (as | ||
| 20 | + `decode_leaf_rect` decode.rs:5075 already does). | ||
| 21 | +- crates/ec-av1/src/decode.rs:855 — per-shape hit counters | ||
| 22 | + `rect_split_chroma_shape_hits() -> [usize; 4]` (32x8, 8x32, 8x4, 4x8). | ||
| 23 | +- crates/ec-av1/src/decode.rs:5296 — **the real defect this round found**: | ||
| 24 | + `sub_tx_size_map[TX_64X16] == TX_32X16`, a 2:1 RECT, not `TX_16X16`. The site derived | ||
| 25 | + the transform unit as `bw.min(bh) >> (depth - 1)` ("square from the first step on"), | ||
| 26 | + which is true for a 2:1 strip and FALSE for a 1:4 one. A depth-1 64x16 / 16x64 strip | ||
| 27 | + was therefore decoded as square 16x16 units and produced wrong pixels silently. Now: | ||
| 28 | + depth >= 2 uses `bw.min(bh) >> (depth - 2)` (correct square), and depth == 1 on a | ||
| 29 | + non-skip 1:4 strip is refused by name. | ||
| 30 | +- crates/ec-av1/src/refusal_inventory.rs:37 — the new refusal string. | ||
| 31 | +- crates/ec-av1/src/stream.rs:14560 — the gate (below). | ||
| 32 | + | ||
| 33 | +## Gate | ||
| 34 | + | ||
| 35 | +`a_real_aomenc_stream_with_a_coded_strip_whose_chroma_is_a_4to1_or_sub8_rect_decodes_pixel_exact` | ||
| 36 | +— 8-bit AND 10-bit, cq 45/32/60, seeds 42.., odd seeds transposed (HORZ_4 and VERT_4 both | ||
| 37 | +appear), `--enable-rect-partitions=1 --enable-ab-partitions=0 --enable-1to4-partitions=1 | ||
| 38 | +--sb-size=64 --cpu-used=0`, tx-size-search left at aomenc's default (ON) which is the whole | ||
| 39 | +point. Fixture: 16-row luma bands + seeded noise | ||
| 40 | +(`geq=lum='mod(floor(Y/16),2)*160+48',noise=alls=10:all_seed=<seed>`). | ||
| 41 | +Every decode is pixel-compared against ffmpeg (10-bit via `ffmpeg_decode_sequence_10bit`), | ||
| 42 | +no SKIP on a decode error or mismatch, refusals must contain "unsupported". | ||
| 43 | +Hard asserts: `matched > 0`, `rect4_strips > 0` (1:4 strips inside pixel-exact streams), | ||
| 44 | +`depth1_refusals > 0` (the shape the fix covers is actually reached). | ||
| 45 | + | ||
| 46 | +Run: `EC_AV1_REQUIRE_AOMENC=1 EC_RECTCHROMA_GATE_ATTEMPTS=4 cargo test -p ec-av1 --lib chroma_is_a_4to1_or_sub8 -- --nocapture` | ||
| 47 | + | ||
| 48 | +EVIDENCE: gate stdout (full 20-attempt default sweep) | 120 aomenc streams (8+10 bit x cq 45/32/60 x 20 seeds), each decoded and pixel-compared to ffmpeg | 60 pixel-exact matches, 37 named refusals, 527 superblock 1:4 strips inside compared streams, chroma shape 32x8 fired ONCE inside a pixel-exact stream (8x32/8x4/4x8 = 0), 37 attempts refused the depth-1 1:4 split strip by name, 23 attempts carried no 1:4 strip (2 mismatched -- other shapes); test result: ok | ||
| 49 | +EVIDENCE: gate stdout (EC_RECTCHROMA_GATE_ATTEMPTS=4) | 24 aomenc streams (8+10 bit x cq 45/32/60 x 4 seeds), each decoded and compared to ffmpeg | 15 pixel-exact matches, 9 named refusals, 100 superblock 1:4 strips inside compared streams, 9 attempts refused the depth-1 1:4 split strip by name; test result: ok | ||
| 50 | +EVIDENCE: same gate before the decode.rs:5296 fix | 8-bit cq 45 seed 42, 2 strips with chroma 32x8 decoded through the split path | frame 0 luma MISMATCHED ffmpeg (first sample 47 vs reference) -- the silent wrong-tiling this round removed | ||
| 51 | + | ||
| 52 | +## Film check (release `decode_probe`) | ||
| 53 | + | ||
| 54 | +- reelc-head.obu: was `a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here` | ||
| 55 | + -> now `a coded 1:4 HORZ_4/VERT_4 strip whose transform splits only once (the unit is still a 2:1 rect, not a square)`. | ||
| 56 | +- reelc5.obu: was the same chroma refusal -> now `a 32x32 partition type this decoder does not code (value=9)` | ||
| 57 | + (32x32-level `PARTITION_VERT_4`, a different lane's shape). | ||
| 58 | + | ||
| 59 | +## Suite | ||
| 60 | + | ||
| 61 | +`cargo test -p ec-av1 --lib` under systemd-run: **309 passed, 2 failed, 27 ignored** at commit | ||
| 62 | +4648a75 -- both failures mine and both fixed after it: `gate_coverage::never_exercised_10bit` | ||
| 63 | +(the new 10-bit gate retires `enable-1to4-partitions` from `NEVER_EXERCISED_10BIT`, which is | ||
| 64 | +exactly the shrink that test is built to notice) and the gate's own 8-bit cq 32 seed 46 | ||
| 65 | +mismatch (see residue). Re-run scoped after the fixes: `gate_coverage` 9/9 ok, | ||
| 66 | +`refusal_inventory` 3/3 ok, `superblock_level_1to4` + `split_transform` siblings 3/3 ok, | ||
| 67 | +the gate itself ok. A full re-run of the suite on the final tree was NOT done (tool budget). | ||
| 68 | + | ||
| 69 | +## Residue | ||
| 70 | + | ||
| 71 | +- fix-now(next round): **rect luma transform units inside a split strip**. ReelC's blocker is | ||
| 72 | + exactly a depth-1 1:4 strip: luma = two `TX_32X16` (or `TX_16X32`) units, chroma = one | ||
| 73 | + 32x8/8x32 (tables now present). `decode_rect_split`'s luma loop is square-only; it needs a | ||
| 74 | + rect-TU arm (`TxbSet::LumaRect32x16` + `SCAN_32X16`/`SCAN_16X32` + `read_coeffs_rect` + | ||
| 75 | + `reconstruct_rect`, per-unit reach/skip-ctx as the square loop already computes). | ||
| 76 | +- deferred(that same rect-TU arm): of the four chroma arms added here only **32x8** is proven, | ||
| 77 | + and only once (one strip, one pixel-exact stream, in the 120-attempt sweep -- the depth>=2 | ||
| 78 | + case). 8x32 / 8x4 / 4x8 read 0: every stream that would use them arrives with depth 1, | ||
| 79 | + which now refuses. Counters are reported, not asserted; the report states this | ||
| 80 | + rather than asserting on them. 8x4/4x8 additionally need a 16x16-level rect strip with a | ||
| 81 | + split transform, whose own refusal (`a HORZ/VERT intra strip below 16x16 with a split | ||
| 82 | + transform`) is another lane's. | ||
| 83 | +- deferred(another lane): 8-bit AND 10-bit cq 32 seed 46 of this fixture MISMATCH ffmpeg on | ||
| 84 | + frame 0 luma with ZERO 1:4 strips in the stream -- a pre-existing defect of some other | ||
| 85 | + shape, printed by the gate as out-of-scope (the sibling gate's own convention) rather than | ||
| 86 | + swallowed. Not diagnosed this round. | ||
| 87 | +- accepted: `--min-partition-size` is INERT on this recipe (16 and 32 give byte-identical | ||
| 88 | + refusal sets and the same sub-16x16 shapes appear either way) -- class | ||
| 89 | + knob-never-reached-the-tool; the gate does not rely on it. | ||
| 90 | + | ||
| 91 | +## r2 — verifier FAIL fixes (587d388 -> this commit) | ||
| 92 | + | ||
| 93 | +Three verifier findings, all test-file only; no decode-path change. | ||
| 94 | + | ||
| 95 | +1. **`out_of_scope_mismatch` was printed, not asserted** (`crates/ec-av1/src/stream.rs`, | ||
| 96 | + gate `a_real_aomenc_stream_with_a_coded_strip_whose_chroma_is_a_4to1_or_sub8_rect_decodes_pixel_exact`). | ||
| 97 | + Now `assert_eq!(out_of_scope_mismatch, 0, ...)`, matching main's two sibling 1:4 gates | ||
| 98 | + (main 8262b99 stream.rs:15340/15573). The two real mismatches that assert would have | ||
| 99 | + caught (8-bit and 10-bit, cq 32, **seed 46**, zero 1:4 strips) are NOT swallowed: | ||
| 100 | + - `const EXCLUDED_SEEDS: &[u32] = &[46];` skips exactly that seed in this gate's window, | ||
| 101 | + with a comment naming the open defect and its owner (lane-band46); | ||
| 102 | + - `#[ignore]`d pin `the_chroma_rect_gates_excluded_seed_46_decodes_pixel_exact` decodes | ||
| 103 | + seed 46 at **both** depths through the same recipe and asserts pixel-exact, so | ||
| 104 | + un-ignoring it is the proof the defect is fixed. It shares the gate's fixture/aomenc | ||
| 105 | + recipe through the new `rectchroma_stream(bit_depth, cq, attempt, width, height)` | ||
| 106 | + helper, so the pin cannot drift from the gate. | ||
| 107 | + | ||
| 108 | + Gate run with the assert live: **57 pixel-exact matches, 36 named refusals out of 120 | ||
| 109 | + attempts; 21 attempts carried no 1:4 strip, 0 of them mismatched**; chroma shapes proved | ||
| 110 | + 32x8=1; compared streams carried 12 split-transform strips and 499 superblock 1:4 strips. | ||
| 111 | + | ||
| 112 | +2. **`--min-partition-size` 16->32 in `a_real_aomenc_10bit_inter_sequence_decodes_pixel_exact` | ||
| 113 | + reverted** (stream.rs:2453 back to `=16`). The verifier proved the gate passes at 16 on | ||
| 114 | + this tree, so the narrowing was unneeded coverage loss and a merge conflict with main. | ||
| 115 | + `git diff main -- crates/ec-av1/src/stream.rs` now contains no added `--min-partition-size` | ||
| 116 | + line at all. Gate re-run: **ok**. | ||
| 117 | + | ||
| 118 | +3. **`gate_coverage.rs` made a no-op against main**: main already dropped | ||
| 119 | + `enable-1to4-partitions` from `NEVER_EXERCISED_10BIT` with its own comment (lane-tx64x16 | ||
| 120 | + r4). The lane's duplicate comment paragraph is gone and main's wording restored, so the | ||
| 121 | + file's only remaining delta from the merge base is byte-identical to main's own change -- | ||
| 122 | + the merge is clean. | ||
| 123 | + | ||
| 124 | +### Gates run (r2) | ||
| 125 | + | ||
| 126 | +`ec_av1` lib suite, filtered by name, `--test-threads=1 --nocapture`: | ||
| 127 | + | ||
| 128 | +``` | ||
| 129 | +test stream::tests::a_real_aomenc_stream_with_a_coded_strip_whose_chroma_is_a_4to1_or_sub8_rect_decodes_pixel_exact ... ok | ||
| 130 | +test stream::tests::a_real_aomenc_10bit_inter_sequence_decodes_pixel_exact ... ok | ||
| 131 | +test gate_coverage::tests::* (8) ... ok | ||
| 132 | +test refusal_inventory::tests::* (3) ... ok | ||
| 133 | +test result: ok. 14 passed; 0 failed; 0 ignored; 325 filtered out; finished in 27.58s | ||
| 134 | +``` | ||
| 135 | + | ||
| 136 | +Full suite not re-run: 311/0/27 at 587d388 (verifier), and r2 touches test code only. | ||
| 137 | + | ||
| 138 | +### Open (unchanged by r2) | ||
| 139 | + | ||
| 140 | +- cq 32 seed 46 mismatches ffmpeg at both depths with **zero** 1:4 strips -- another shape's | ||
| 141 | + defect, undiagnosed, owned by lane-band46, pinned by the ignored test above. | ||