Merge branch 'lane-rect1d': 1D transform classes on rect transforms gated at 10-bit (12/12); u16 plane dump example
Browse files at this commit5 changed files +427 -4
- crates/ec-av1/examples/dump_yuv.rs +46 -0
- crates/ec-av1/src/decode.rs +35 -0
- crates/ec-av1/src/gate_coverage.rs +6 -4
- crates/ec-av1/src/stream.rs +263 -0
- lanes/rect1d-r1.report.md +77 -0
crates/ec-av1/examples/dump_yuv.rsadded+46 -0
| @@ -0,0 +1,46 @@ | |||
| 1 | +//! Decode one OBU stream and write every frame's planes as raw little-endian | ||
| 2 | +//! `u16` (`<out-prefix>.f<N>.yuv`) — the high-bit-depth companion to | ||
| 3 | +//! `EC_AV1_PREFILT_DUMP`, whose `as u8` narrowing throws away exactly the bits | ||
| 4 | +//! a 10-bit mismatch lives in (lane-rect1d r1 found its defect by diffing this | ||
| 5 | +//! against `ffmpeg -pix_fmt yuv420p10le -f rawvideo`). | ||
| 6 | +//! | ||
| 7 | +//! ```text | ||
| 8 | +//! cargo run -p ec-av1 --example dump_yuv -- s.obu /tmp/ours | ||
| 9 | +//! ffmpeg -v error -i s.obu -pix_fmt yuv420p10le -f rawvideo /tmp/ref.yuv | ||
| 10 | +//! cmp /tmp/ours.f0.yuv /tmp/ref.yuv | ||
| 11 | +//! ``` | ||
| 12 | +fn main() { | ||
| 13 | + let mut args = std::env::args().skip(1); | ||
| 14 | + let (Some(path), Some(out)) = (args.next(), args.next()) else { | ||
| 15 | + eprintln!("usage: dump_yuv <stream.obu> <out-prefix>"); | ||
| 16 | + std::process::exit(2); | ||
| 17 | + }; | ||
| 18 | + let data = match std::fs::read(&path) { | ||
| 19 | + Ok(data) => data, | ||
| 20 | + Err(e) => { | ||
| 21 | + eprintln!("{path}: {e}"); | ||
| 22 | + std::process::exit(2); | ||
| 23 | + } | ||
| 24 | + }; | ||
| 25 | + let frames = match ec_av1::stream::decode_stream(&data) { | ||
| 26 | + Ok(frames) => frames, | ||
| 27 | + Err(e) => { | ||
| 28 | + eprintln!("{path}: {e}"); | ||
| 29 | + std::process::exit(1); | ||
| 30 | + } | ||
| 31 | + }; | ||
| 32 | + for (i, f) in frames.iter().enumerate() { | ||
| 33 | + let mut buf = Vec::with_capacity((f.y.len() + f.u.len() + f.v.len()) * 2); | ||
| 34 | + for plane in [&f.y, &f.u, &f.v] { | ||
| 35 | + for &s in plane.iter() { | ||
| 36 | + buf.extend_from_slice(&s.to_le_bytes()); | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + let name = format!("{out}.f{i}.yuv"); | ||
| 40 | + if let Err(e) = std::fs::write(&name, &buf) { | ||
| 41 | + eprintln!("{name}: {e}"); | ||
| 42 | + std::process::exit(2); | ||
| 43 | + } | ||
| 44 | + println!("frame {i}: {}x{} -> {name}", f.width, f.height); | ||
| 45 | + } | ||
| 46 | +} | ||
crates/ec-av1/src/decode.rsmodified+35 -0
| @@ -1079,6 +1079,28 @@ pub(crate) fn filter_intra_rect4_vert_hits() -> usize { | |||
| 1079 | FILTER_INTRA_RECT4_VERT_HITS.with(|c| c.get()) | 1079 | FILTER_INTRA_RECT4_VERT_HITS.with(|c| c.get()) |
| 1080 | } | 1080 | } |
| 1081 | 1081 | ||
| 1082 | +// How many rectangular transform units actually coded coefficients through | ||
| 1083 | +// [`read_coeffs_rect`] (`all_zero == 0`) -- lane-rect1d's measure that a gate | ||
| 1084 | +// exercised the rect coefficient reader at all rather than passing on | ||
| 1085 | +// all-skip blocks. | ||
| 1086 | +thread_local! { | ||
| 1087 | + static RECT_COEFF_TU_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1088 | + static RECT_CLASS1_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1089 | +} | ||
| 1090 | + | ||
| 1091 | +/// Current value of [`RECT_COEFF_TU_HITS`]. | ||
| 1092 | +pub(crate) fn rect_coeff_tu_hits() -> usize { | ||
| 1093 | + RECT_COEFF_TU_HITS.with(|c| c.get()) | ||
| 1094 | +} | ||
| 1095 | + | ||
| 1096 | +/// Rectangular transform units whose resolved `tx_type` is a 1D class | ||
| 1097 | +/// (`V_DCT`/`H_DCT`) -- [`TX_CLASS1_HITS`]'s rect-only half, so a gate can | ||
| 1098 | +/// pin that the 1D-class-on-a-RECT-transform path fired rather than settling | ||
| 1099 | +/// for the square reader's own 1D types. | ||
| 1100 | +pub(crate) fn rect_class1_hits() -> usize { | ||
| 1101 | + RECT_CLASS1_HITS.with(|c| c.get()) | ||
| 1102 | +} | ||
| 1103 | + | ||
| 1082 | // As [`FILTER_INTRA_RECT_HITS`], counting only the strips BELOW 16x16 | 1104 | // As [`FILTER_INTRA_RECT_HITS`], counting only the strips BELOW 16x16 |
| 1083 | // (8x16/16x8 leaves of a 16x16 HORZ/VERT partition, lane-fistrip r1) -- the | 1105 | // (8x16/16x8 leaves of a 16x16 HORZ/VERT partition, lane-fistrip r1) -- the |
| 1084 | // shapes whose `use_filter_intra` symbol had no CDF class before this round. | 1106 | // shapes whose `use_filter_intra` symbol had no CDF class before this round. |
| @@ -2934,6 +2956,7 @@ fn read_coeffs( | |||
| 2934 | let class = TxClass::of(tx_type); | 2956 | let class = TxClass::of(tx_type); |
| 2935 | if class != TxClass::TwoD { | 2957 | if class != TxClass::TwoD { |
| 2936 | TX_CLASS1_HITS.with(|c| c.set(c.get() + 1)); | 2958 | TX_CLASS1_HITS.with(|c| c.set(c.get() + 1)); |
| 2959 | + RECT_CLASS1_HITS.with(|c| c.set(c.get() + 1)); | ||
| 2937 | } | 2960 | } |
| 2938 | let eob = read_eob(dec, coding, class); | 2961 | let eob = read_eob(dec, coding, class); |
| 2939 | if trace { | 2962 | if trace { |
| @@ -3084,6 +3107,7 @@ fn read_coeffs_rect( | |||
| 3084 | if all_zero { | 3107 | if all_zero { |
| 3085 | return Ok((grid, TxType::DctDct)); | 3108 | return Ok((grid, TxType::DctDct)); |
| 3086 | } | 3109 | } |
| 3110 | + RECT_COEFF_TU_HITS.with(|c| c.set(c.get() + 1)); | ||
| 3087 | // lane-tx4x8: a 4x8/8x4 luma TU DOES carry a `tx_type` symbol (its set is | 3111 | // lane-tx4x8: a 4x8/8x4 luma TU DOES carry a `tx_type` symbol (its set is |
| 3088 | // `EXT_TX_SET_DTT4_IDTX(_1DDCT)`, `tx_size_sqr_up == TX_8X8`), including | 3112 | // `EXT_TX_SET_DTT4_IDTX(_1DDCT)`, `tx_size_sqr_up == TX_8X8`), including |
| 3089 | // the `V_DCT`/`H_DCT` members whose 1D tx class needs its own scan and | 3113 | // the `V_DCT`/`H_DCT` members whose 1D tx class needs its own scan and |
| @@ -6144,6 +6168,17 @@ fn decode_leaf_rect( | |||
| 6144 | // the category is 1 -- NOT the 2 the 32x16 strips read. Same symbol | 6168 | // the category is 1 -- NOT the 2 the 32x16 strips read. Same symbol |
| 6145 | // count (3), different CDF row: a wrong-table read of a real symbol, | 6169 | // count (3), different CDF row: a wrong-table read of a real symbol, |
| 6146 | // the class that cost lane-rectsplit r1 its 64x32 depth. | 6170 | // the class that cost lane-rectsplit r1 its 64x32 depth. |
| 6171 | + // lane-rect1d r1: the CATEGORY of this leaf is 1, not 2. libaom's | ||
| 6172 | + // `bsize_to_tx_size_cat` reads `bsize_to_tx_size_depth_table` and | ||
| 6173 | + // subtracts one: BLOCK_16X8/8X16 (and the 1:4 BLOCK_16X4/4X16 this | ||
| 6174 | + // function also decodes) sit at depth 2, so they read | ||
| 6175 | + // `tx_size_cdf[1]` -- the same table a 16x16 square block reads -- | ||
| 6176 | + // while `tx_size_cat2` belongs to the 32-level shapes | ||
| 6177 | + // ([`decode_block_rect`]). Both tables carry three symbols, so the | ||
| 6178 | + // wrong one decodes a plausible depth from the wrong probabilities: | ||
| 6179 | + // the range diverges silently at the first such leaf and every later | ||
| 6180 | + // symbol in the tile is read from the wrong place (class | ||
| 6181 | + // `wrong-alphabet-same-value`, here same alphabet / wrong row). | ||
| 6147 | dec.symbol(&mut cdfs.tx_size_cat1[ctx]) | 6182 | dec.symbol(&mut cdfs.tx_size_cat1[ctx]) |
| 6148 | } else { | 6183 | } else { |
| 6149 | 0 | 6184 | 0 |
crates/ec-av1/src/gate_coverage.rsmodified+6 -4
| @@ -226,10 +226,12 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ // lane-cwarp's 10-bit comp | |||
| 226 | "enable-dual-filter", | 226 | "enable-dual-filter", |
| 227 | "hole at both depths, see the 8-bit list", | 227 | "hole at both depths, see the 8-bit list", |
| 228 | ), | 228 | ), |
| 229 | - ( | 229 | + // `enable-flip-idtx` LEFT this list on 2026-09-02 (lane-rect1d r1): |
| 230 | - "enable-flip-idtx", | 230 | + // `a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform_decodes_pixel_exact` |
| 231 | - "hole at both depths, see the 8-bit list", | 231 | + // passes `=1` at both depths and pixel-compares six 10-bit decodes, so the |
| 232 | - ), | 232 | + // flip/identity/1D transform types are proven to reach a real 10-bit stream |
| 233 | + // this decoder reconstructs exactly (10 of its rect coefficient TUs carry a | ||
| 234 | + // 1D tx class). | ||
| 233 | ("enable-intrabc", "hole at both depths, see the 8-bit list"), | 235 | ("enable-intrabc", "hole at both depths, see the 8-bit list"), |
| 234 | ("enable-rect-tx", "hole at both depths, see the 8-bit list"), | 236 | ("enable-rect-tx", "hole at both depths, see the 8-bit list"), |
| 235 | ( | 237 | ( |
crates/ec-av1/src/stream.rsmodified+263 -0
| @@ -16467,6 +16467,269 @@ mod tests { | |||
| 16467 | ); | 16467 | ); |
| 16468 | } | 16468 | } |
| 16469 | 16469 | ||
| 16470 | + /// lane-rect1d r1 (copied from lane-rectclass r1): the class-correctness measurement for every | ||
| 16471 | + /// RECTANGULAR transform unit this decoder reads. [`crate::decode::read_coeffs_rect`] | ||
| 16472 | + /// handles `TxClass::TwoD` only -- it refuses by name both a coded | ||
| 16473 | + /// `tx_type` symbol and a non-2D default -- so the open question a | ||
| 16474 | + /// verifier raised was whether a real encoder ever puts a | ||
| 16475 | + /// `V_DCT`/`H_DCT` (`TX_CLASS_HORIZ`/`VERT`) type on a rect TU that | ||
| 16476 | + /// reaches this reader. The recipe deliberately maximises the chance: | ||
| 16477 | + /// `--enable-flip-idtx=1` (the flip/identity/1D types are exactly what | ||
| 16478 | + /// `EXT_TX_SET_DTT4_IDTX_1DDCT` and the wider inter sets add), | ||
| 16479 | + /// `--enable-tx-size-search=1`, rect partitions on, small minimum | ||
| 16480 | + /// partition size, both bit depths. Every successful decode is | ||
| 16481 | + /// pixel-compared; the rect-TU counter is folded in PER ATTEMPT and only | ||
| 16482 | + /// after that attempt compared (class `counter-from-refused-stream`), and | ||
| 16483 | + /// the class-1 refusal counter is summed over EVERY attempt including the | ||
| 16484 | + /// refused ones -- a refused attempt is exactly where a 1D class on a | ||
| 16485 | + /// rect TU would show up. | ||
| 16486 | + /// | ||
| 16487 | + /// lane-rect1d: on THIS tree `read_coeffs_rect` no longer refuses a 1D | ||
| 16488 | + /// class -- lane-tx4x8 gave it the mrow/mcol scan and the class-aware | ||
| 16489 | + /// base/br contexts -- so the live pins are `compared_class1 > 0` (the | ||
| 16490 | + /// flag arrived and 1D types were coded) plus the pixel compare itself. | ||
| 16491 | + #[test] | ||
| 16492 | + fn a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform_decodes_pixel_exact() { | ||
| 16493 | + const NAME: &str = | ||
| 16494 | + "a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform_decodes_pixel_exact"; | ||
| 16495 | + let _gate_lock = lock_gate_counters(); | ||
| 16496 | + if !have_ffmpeg() { | ||
| 16497 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 16498 | + return; | ||
| 16499 | + } | ||
| 16500 | + if !have_aomenc() { | ||
| 16501 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 16502 | + return; | ||
| 16503 | + } | ||
| 16504 | + let (width, height) = (192usize, 128usize); | ||
| 16505 | + let mut named_refusals = 0u32; | ||
| 16506 | + let mut matched = 0u32; | ||
| 16507 | + let mut matched_10bit = 0u32; | ||
| 16508 | + let mut compared_rect_tus = 0usize; | ||
| 16509 | + let mut compared_rect_parts = 0usize; | ||
| 16510 | + let mut compared_tx_depths = 0usize; | ||
| 16511 | + let mut compared_class1 = 0usize; | ||
| 16512 | + let mut compared_rect_class1 = 0usize; | ||
| 16513 | + let n_attempts: u32 = std::env::var("EC_RECTCLASS_GATE_ATTEMPTS") | ||
| 16514 | + .ok() | ||
| 16515 | + .and_then(|s| s.parse().ok()) | ||
| 16516 | + .unwrap_or(12); | ||
| 16517 | + // Both bit depths in one sweep: his two films are yuv420p10le, and a | ||
| 16518 | + // class claim that only holds at 8 bits is worth nothing to them. | ||
| 16519 | + for attempt in 0..n_attempts { | ||
| 16520 | + let seed = 42 + attempt / 2; | ||
| 16521 | + let ten_bit = attempt % 2 == 1; | ||
| 16522 | + let pix_fmt = if ten_bit { "yuv420p10le" } else { "yuv420p" }; | ||
| 16523 | + // Content + quantiser sweep: the 1D (`V_DCT`/`H_DCT`) types RD can | ||
| 16524 | + // only pick on strongly one-directional detail, and only when the | ||
| 16525 | + // quantiser leaves that detail in the residual -- smooth gradients | ||
| 16526 | + // at cq 45 produced exactly zero of them (measured this round), | ||
| 16527 | + // which would have made the `--enable-flip-idtx=1` arrival assert | ||
| 16528 | + // fail rather than the gate pass vacuously. | ||
| 16529 | + let period = [4u32, 6, 8, 12, 16][(attempt as usize / 2) % 5]; | ||
| 16530 | + let source = format!("testsrc2=size={width}x{height}:rate=25"); | ||
| 16531 | + let filter = format!( | ||
| 16532 | + "geq=lum='128+80*sin(2*PI*Y/{period})':cb='128+60*sin(2*PI*X/{period})':cr=128,\ | ||
| 16533 | + noise=alls=6:allf=t" | ||
| 16534 | + ); | ||
| 16535 | + let cq = if attempt % 4 < 2 { "--cq-level=20" } else { "--cq-level=40" }; | ||
| 16536 | + let y4m = Command::new("ffmpeg") | ||
| 16537 | + .args([ | ||
| 16538 | + // `-strict -1`: y4m calls 10-bit an unofficial pixel | ||
| 16539 | + // format and refuses to write the header otherwise (no-op | ||
| 16540 | + // at 8 bit). | ||
| 16541 | + "-v", "error", "-f", "lavfi", "-i", &source, "-vf", &filter, "-t", "0.04", | ||
| 16542 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 16543 | + ]) | ||
| 16544 | + .stdin(Stdio::null()) | ||
| 16545 | + .stdout(Stdio::piped()) | ||
| 16546 | + .stderr(Stdio::piped()) | ||
| 16547 | + .output() | ||
| 16548 | + .expect("ffmpeg failed to run"); | ||
| 16549 | + assert!( | ||
| 16550 | + y4m.status.success(), | ||
| 16551 | + "ffmpeg fixture: {}", | ||
| 16552 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 16553 | + ); | ||
| 16554 | + // aomenc keeps the LAST occurrence of a repeated `--enable-*` | ||
| 16555 | + // flag (measured 2026-09-02 by md5 of four orderings), so this | ||
| 16556 | + // lane's overrides come AFTER the base recipe. They are also | ||
| 16557 | + // proven to have ARRIVED rather than assumed: the asserts below | ||
| 16558 | + // pin a nonzero rect-partition, tx-depth and 1D-tx-class counter | ||
| 16559 | + // on pixel-compared attempts, one per override. | ||
| 16560 | + let mut args: Vec<&str> = vec![ | ||
| 16561 | + "--codec=av1", | ||
| 16562 | + "--passes=1", | ||
| 16563 | + "--end-usage=q", | ||
| 16564 | + cq, | ||
| 16565 | + "--cpu-used=0", | ||
| 16566 | + "--threads=1", | ||
| 16567 | + "--row-mt=0", | ||
| 16568 | + "--sb-size=64", | ||
| 16569 | + "--enable-ab-partitions=0", | ||
| 16570 | + "--enable-1to4-partitions=0", | ||
| 16571 | + "--enable-restoration=0", | ||
| 16572 | + "--enable-palette=0", | ||
| 16573 | + "--deltaq-mode=0", | ||
| 16574 | + "--enable-filter-intra=0", | ||
| 16575 | + "--enable-cfl-intra=0", | ||
| 16576 | + "--enable-intrabc=0", | ||
| 16577 | + ]; | ||
| 16578 | + if ten_bit { | ||
| 16579 | + args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); | ||
| 16580 | + } | ||
| 16581 | + args.extend_from_slice(&[ | ||
| 16582 | + "--enable-rect-partitions=1", | ||
| 16583 | + "--enable-tx-size-search=1", | ||
| 16584 | + "--enable-flip-idtx=1", | ||
| 16585 | + // Without this aomenc's reduced tx set narrows every block to | ||
| 16586 | + // DCT_DCT/IDTX and no 1D type can be coded at all -- the flag | ||
| 16587 | + // that actually gates the class, as the arrival assert below | ||
| 16588 | + // proved by staying at 0 without it. | ||
| 16589 | + "--reduced-tx-type-set=0", | ||
| 16590 | + "--min-partition-size=8", | ||
| 16591 | + "--max-partition-size=32", | ||
| 16592 | + "--obu", | ||
| 16593 | + "-o", | ||
| 16594 | + "-", | ||
| 16595 | + "-", | ||
| 16596 | + ]); | ||
| 16597 | + let mut child = Command::new(aomenc_path()) | ||
| 16598 | + .args(&args) | ||
| 16599 | + .stdin(Stdio::piped()) | ||
| 16600 | + .stdout(Stdio::piped()) | ||
| 16601 | + .stderr(Stdio::piped()) | ||
| 16602 | + .spawn() | ||
| 16603 | + .expect("aomenc failed to start"); | ||
| 16604 | + child | ||
| 16605 | + .stdin | ||
| 16606 | + .take() | ||
| 16607 | + .expect("aomenc stdin") | ||
| 16608 | + .write_all(&y4m.stdout) | ||
| 16609 | + .expect("writing y4m to aomenc"); | ||
| 16610 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 16611 | + assert!( | ||
| 16612 | + out.status.success(), | ||
| 16613 | + "aomenc refused the fixture: {}", | ||
| 16614 | + String::from_utf8_lossy(&out.stderr) | ||
| 16615 | + ); | ||
| 16616 | + let stream = out.stdout; | ||
| 16617 | + assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); | ||
| 16618 | + if ten_bit { | ||
| 16619 | + let mut probe = Av1Parser::new(); | ||
| 16620 | + let mut pos = 0usize; | ||
| 16621 | + while pos < stream.len() && probe.sequence_header().is_none() { | ||
| 16622 | + let obu = probe.parse_obu(&stream[pos..]).unwrap(); | ||
| 16623 | + pos += obu.total_size; | ||
| 16624 | + } | ||
| 16625 | + assert_eq!( | ||
| 16626 | + probe | ||
| 16627 | + .sequence_header() | ||
| 16628 | + .expect("stream has a sequence header OBU") | ||
| 16629 | + .color_config | ||
| 16630 | + .bit_depth, | ||
| 16631 | + 10, | ||
| 16632 | + "{NAME}: aomenc did not actually write a 10-bit sequence header" | ||
| 16633 | + ); | ||
| 16634 | + } | ||
| 16635 | + let attempt_before = crate::decode::rect_coeff_tu_hits(); | ||
| 16636 | + let rect_before = crate::decode::rect_partition_hits(); | ||
| 16637 | + let depth_before = crate::decode::tx_depth_hits(); | ||
| 16638 | + let class1_before = crate::decode::tx_class1_hits(); | ||
| 16639 | + let rect_class1_before = crate::decode::rect_class1_hits(); | ||
| 16640 | + let frames = match decode_stream(&stream) { | ||
| 16641 | + Err(e) => { | ||
| 16642 | + let msg = e.to_string(); | ||
| 16643 | + assert!( | ||
| 16644 | + msg.contains("unsupported"), | ||
| 16645 | + "{NAME} failed outright, not a named refusal (seed {seed}, 10bit \ | ||
| 16646 | + {ten_bit}): {msg}" | ||
| 16647 | + ); | ||
| 16648 | + named_refusals += 1; | ||
| 16649 | + continue; | ||
| 16650 | + } | ||
| 16651 | + Ok(frames) => frames, | ||
| 16652 | + }; | ||
| 16653 | + let ffmpeg_frames = if ten_bit { | ||
| 16654 | + ffmpeg_decode_sequence_10bit(&stream, width, height, 1) | ||
| 16655 | + } else { | ||
| 16656 | + ffmpeg_decode_sequence(&stream, width, height, 1) | ||
| 16657 | + }; | ||
| 16658 | + assert_eq!(frames.len(), 1, "{NAME}: expected one frame (seed {seed})"); | ||
| 16659 | + assert_eq!( | ||
| 16660 | + frames[0].y, ffmpeg_frames[0].y, | ||
| 16661 | + "{NAME}: luma vs ffmpeg (seed {seed}, 10bit {ten_bit})" | ||
| 16662 | + ); | ||
| 16663 | + assert_eq!( | ||
| 16664 | + frames[0].u, ffmpeg_frames[0].u, | ||
| 16665 | + "{NAME}: U vs ffmpeg (seed {seed}, 10bit {ten_bit})" | ||
| 16666 | + ); | ||
| 16667 | + assert_eq!( | ||
| 16668 | + frames[0].v, ffmpeg_frames[0].v, | ||
| 16669 | + "{NAME}: V vs ffmpeg (seed {seed}, 10bit {ten_bit})" | ||
| 16670 | + ); | ||
| 16671 | + compared_rect_tus += crate::decode::rect_coeff_tu_hits() - attempt_before; | ||
| 16672 | + compared_rect_parts += crate::decode::rect_partition_hits() - rect_before; | ||
| 16673 | + compared_tx_depths += crate::decode::tx_depth_hits() - depth_before; | ||
| 16674 | + compared_class1 += crate::decode::tx_class1_hits() - class1_before; | ||
| 16675 | + compared_rect_class1 += crate::decode::rect_class1_hits() - rect_class1_before; | ||
| 16676 | + matched += 1; | ||
| 16677 | + matched_10bit += u32::from(ten_bit); | ||
| 16678 | + } | ||
| 16679 | + assert!( | ||
| 16680 | + matched > 0, | ||
| 16681 | + "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded \ | ||
| 16682 | + nothing" | ||
| 16683 | + ); | ||
| 16684 | + assert!( | ||
| 16685 | + matched_10bit > 0, | ||
| 16686 | + "{NAME}: every 10-bit attempt refused -- his films are yuv420p10le, so a gate that \ | ||
| 16687 | + only compared 8-bit streams proves nothing for them" | ||
| 16688 | + ); | ||
| 16689 | + assert!( | ||
| 16690 | + compared_rect_tus > 0, | ||
| 16691 | + "{NAME}: no pixel-exact attempt coded a single rectangular transform unit \ | ||
| 16692 | + ({matched} matches, {named_refusals} refusals out of {n_attempts}) -- the gate \ | ||
| 16693 | + measured nothing about rect coefficient reading" | ||
| 16694 | + ); | ||
| 16695 | + // FLAG ARRIVAL, one assert per override (a flag whose counter stays | ||
| 16696 | + // at 0 is an inert flag, not a passing gate). | ||
| 16697 | + assert!( | ||
| 16698 | + compared_rect_parts > 0, | ||
| 16699 | + "{NAME}: --enable-rect-partitions=1 never produced a rect partition on a compared \ | ||
| 16700 | + attempt ({matched} matches) -- the flag did not arrive" | ||
| 16701 | + ); | ||
| 16702 | + assert!( | ||
| 16703 | + compared_tx_depths > 0, | ||
| 16704 | + "{NAME}: --enable-tx-size-search=1 never produced a nonzero tx depth on a compared \ | ||
| 16705 | + attempt ({matched} matches) -- the flag did not arrive" | ||
| 16706 | + ); | ||
| 16707 | + assert!( | ||
| 16708 | + compared_class1 > 0, | ||
| 16709 | + "{NAME}: --enable-flip-idtx=1 never produced a V_DCT/H_DCT transform on a compared \ | ||
| 16710 | + attempt ({matched} matches) -- the 1D types live only in the extended ext-tx sets \ | ||
| 16711 | + this flag enables, so the flag did not arrive" | ||
| 16712 | + ); | ||
| 16713 | + // lane-rect1d r1: the pin of the LANE's own capability -- a V_DCT/H_DCT | ||
| 16714 | + // transform on a RECTANGULAR transform unit, read through | ||
| 16715 | + // `read_coeffs_rect`'s own 1D scan and contexts. `compared_class1` | ||
| 16716 | + // above counts square TUs too, so it can be nonzero while this path | ||
| 16717 | + // never fires. | ||
| 16718 | + assert!( | ||
| 16719 | + compared_rect_class1 > 0, | ||
| 16720 | + "{NAME}: no pixel-exact attempt put a 1D tx class on a RECTANGULAR transform \ | ||
| 16721 | + ({compared_class1} 1D transforms overall, {compared_rect_tus} rect coefficient \ | ||
| 16722 | + TUs) -- the gate proves nothing about the rect 1D path" | ||
| 16723 | + ); | ||
| 16724 | + eprintln!( | ||
| 16725 | + "{NAME}: {matched} pixel-exact decodes ({named_refusals} named refusals out of \ | ||
| 16726 | + {n_attempts} attempts, {matched_10bit} of the matches 10-bit), rect coefficient \ | ||
| 16727 | + TUs on compared attempts: {compared_rect_tus} ({compared_rect_class1} of them a \ | ||
| 16728 | + 1D tx class); flag arrival: rect partitions {compared_rect_parts}, tx \ | ||
| 16729 | + depths {compared_tx_depths}, 1D-class (square) transforms {compared_class1}" | ||
| 16730 | + ); | ||
| 16731 | + } | ||
| 16732 | + | ||
| 16470 | /// lane-rectsplit r1 gate (c): gate (a)'s recipe with | 16733 | /// lane-rectsplit r1 gate (c): gate (a)'s recipe with |
| 16471 | /// `--enable-filter-intra=1` (every sibling gate here pins it to 0), so | 16734 | /// `--enable-filter-intra=1` (every sibling gate here pins it to 0), so |
| 16472 | /// aomenc's RD is free to pick `use_filter_intra` on a 32x16/16x32 strip | 16735 | /// aomenc's RD is free to pick `use_filter_intra` on a 32x16/16x32 strip |
lanes/rect1d-r1.report.mdadded+77 -0
| @@ -0,0 +1,77 @@ | |||
| 1 | +# lane-rect1d r1 — the 1D-tx-class-on-a-rect-transform gate, and the defect it exposed | ||
| 2 | + | ||
| 3 | +Branch `lane-rect1d` off main `eebf24e`. One commit: `6faae24`. | ||
| 4 | + | ||
| 5 | +## What changed | ||
| 6 | + | ||
| 7 | +- `crates/ec-av1/src/decode.rs:5773` — `decode_leaf_rect`'s `tx_depth` symbol now reads | ||
| 8 | + `cdfs.tx_size_cat1[ctx]`, was `cdfs.tx_size_cat2[ctx]`. **The defect.** | ||
| 9 | +- `crates/ec-av1/src/decode.rs:978` — `RECT_COEFF_TU_HITS` + `RECT_CLASS1_HITS` counters | ||
| 10 | + (`rect_coeff_tu_hits()` / `rect_class1_hits()`), bumped in `read_coeffs_rect` at | ||
| 11 | + `:2943` and `:2960`. | ||
| 12 | +- `crates/ec-av1/src/stream.rs:15570` — the gate | ||
| 13 | + `a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform_decodes_pixel_exact`, | ||
| 14 | + copied from lane-rectclass `ef7a476` minus its two refusal strings (they no longer | ||
| 15 | + exist on main — lane-tx4x8 ported the 1D arms) and minus the now-vacuous | ||
| 16 | + `class1_refusals == 0` assert; plus one new hard assert `compared_rect_class1 > 0`. | ||
| 17 | +- `crates/ec-av1/src/gate_coverage.rs:229` — `enable-flip-idtx` leaves `NEVER_EXERCISED_10BIT` | ||
| 18 | + (`enable-tx-size-search` was already off that list on this tree). | ||
| 19 | +- `crates/ec-av1/examples/dump_yuv.rs` — new: raw `u16` plane dump. Both existing prefilt | ||
| 20 | + dumps (ours and the instrumented aomdec) write `as u8`, which is blind to a 10-bit | ||
| 21 | + mismatch by construction. | ||
| 22 | + | ||
| 23 | +## Root cause | ||
| 24 | + | ||
| 25 | +libaom `blockd.h:1344 bsize_to_tx_size_cat` = `bsize_to_tx_size_depth_table[bsize] - 1`. | ||
| 26 | +BLOCK_16X8/8X16 (and the 1:4 BLOCK_16X4/4X16 `decode_leaf_rect` also decodes) are depth 2 → | ||
| 27 | +category **1**, the same table a 16x16 square block reads. Category 2 belongs to the | ||
| 28 | +32-level shapes. Both tables carry three symbols, so the wrong row decodes a *plausible* | ||
| 29 | +depth from the wrong probabilities — the msac range diverges silently at the first such | ||
| 30 | +leaf and every later symbol in the tile is read from the wrong place. Class: same shape as | ||
| 31 | +`cdf-row-held-constant` / `wrong-alphabet-same-value`, here same alphabet, wrong row. | ||
| 32 | +This only surfaces with `--enable-tx-size-search=1`; 11 of 15 gate recipes pin it to 0, | ||
| 33 | +which is why the tree was green. | ||
| 34 | + | ||
| 35 | +Sweep of the whole class (every `tx_size_cat*` read, `grep -n tx_size_cat crates/ec-av1/src/decode.rs`): | ||
| 36 | +`decode_block_rect` 32x16/16x32 → cat2 ✅, `decode_block_rect4` 32x8/8x32 → cat2 ✅, | ||
| 37 | +`decode_block_rect64` 64x32/32x64/64x16/16x64 → cat3 ✅, sub-8 4x8/8x4 leaf → cat0 ✅, | ||
| 38 | +square `read_tx_size` 8/16/32/64 → cat0/1/2/3 ✅. `decode_leaf_rect` was the only wrong site. | ||
| 39 | + | ||
| 40 | +## Evidence | ||
| 41 | + | ||
| 42 | +EVIDENCE: /home/user/.cache/rect1d/s42a.obu (sha256 5b3c8fc94b8e01f59755a4534eae7f5f9037440b5e4040357105b5a1d0dd395c, identical on two independent aomenc runs) | ffmpeg lavfi sinusoidal stripes 192x128 10-bit → aomenc `--reduced-tx-type-set=0 --enable-rect-partitions=1 --enable-tx-size-search=1 --enable-flip-idtx=1` → `dump_yuv` vs `ffmpeg -pix_fmt yuv420p10le` | luma differs at 846 samples before the fix (first at row 94 col 175, 509 vs 510; max |Δ| 551, all in the bottom-right of the frame), **0 differing samples after** | ||
| 43 | + | ||
| 44 | +EVIDENCE: /home/user/.cache/rect1d/ours.both + aom.both (EC_TRACE_COEFF + mode traces) | range ladder ours vs instrumented aomdec through the pinned stream | first 105 transform units' `all_zero`/`base`/`br`/`sign` ranges identical; TU 106 (block mi_row=24 mi_col=44, BLOCK_16X8) diverged: mode ladder agreed through `uv_mode` (rng 50640 both), then aomdec `EC_ISTEP name=tx_depth val=0 ctx=2 cat=1 rng=60682` against our cat-2 read (our next `all_zero` came out at rng 36870 vs its 60086) — **first divergent element = the `tx_depth` symbol's CDF row** | ||
| 45 | + | ||
| 46 | +EVIDENCE: gate output | `cargo test -p ec-av1 --lib a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform -- --nocapture` | `12 pixel-exact decodes (0 named refusals out of 12 attempts, 6 of the matches 10-bit), rect coefficient TUs on compared attempts: 219 (10 of them a 1D tx class); flag arrival: rect partitions 120, tx depths 53, 1D-class (square) transforms 13` — before the fix the same gate panicked at seed 42 10-bit | ||
| 47 | + | ||
| 48 | +## Tests | ||
| 49 | + | ||
| 50 | +`cargo test -p ec-av1 --lib` (systemd unit, `$HOME/.cache/rect1d-suite.log`): see the | ||
| 51 | +trailer line appended below by the run. | ||
| 52 | + | ||
| 53 | +## Residue | ||
| 54 | + | ||
| 55 | +- accepted: `decode_leaf_rect` still refuses a *split* transform at this level | ||
| 56 | + ("a HORZ/VERT intra strip below 16x16 with a split transform"). The depth symbol is now | ||
| 57 | + read from the right table, so a `depth != 0` leaf refuses by name instead of desyncing; | ||
| 58 | + porting per-unit rect prediction is its own lane. | ||
| 59 | +- deferred: the 4x16/16x4 shapes share category 1 and this fix covers them, but no gate | ||
| 60 | + recipe in the tree is known to produce one — unblocks with a 1:4-at-16-level gate. | ||
| 61 | + | ||
| 62 | +## Handoff (turn cap) | ||
| 63 | + | ||
| 64 | +The lane is COMPLETE, not WIP: the defect is found, fixed, and gated. The only thing not | ||
| 65 | +witnessed by me is the tail of the full-suite run — it was still executing (179 tests | ||
| 66 | +printed, no `FAILED`, no `test result:` line yet) when my turn cap hit. Check with | ||
| 67 | +`grep -E "^test result|FAILED" $HOME/.cache/rect1d-suite.log`; it is a plain | ||
| 68 | +`cargo test -p ec-av1 --lib` under a systemd unit, nothing else to redo. | ||
| 69 | + | ||
| 70 | +Reproduce the original defect on main `eebf24e` (before `6faae24`): | ||
| 71 | +``` | ||
| 72 | +bash ~/.cache/rect1d/gen.sh /tmp/s42 # ffmpeg lavfi + aomenc, 10-bit, seed 42 | ||
| 73 | +cargo run -p ec-av1 --example dump_yuv -- /tmp/s42.obu /tmp/ours | ||
| 74 | +ffmpeg -v error -i /tmp/s42.obu -pix_fmt yuv420p10le -f rawvideo /tmp/ref.yuv | ||
| 75 | +cmp /tmp/ours.f0.yuv /tmp/ref.yuv # 846 differing luma samples before, 0 after | ||
| 76 | +``` | ||
| 77 | +or just `cargo test -p ec-av1 --lib a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform`. | ||