Superblock-level inter AB partitions, and a var-tx block that stamped its neighbour bands square
Browse files at this commitb41201248c2d16013efe805430c618bff04d603bParent: f760942- feat
- superblock-level inter AB partitions, and a var-tx block that stamped its neighbour bands square
3 changed files +225 -3
- crates/ec-av1/src/decode.rs +13 -3
- crates/ec-av1/src/refusal_inventory.rs +4 -0
- crates/ec-av1/src/stream.rs +208 -0
crates/ec-av1/src/decode.rsmodified+13 -3
| @@ -19122,9 +19122,19 @@ fn decode_inter_block( | |||
| 19122 | if vartx_leaves.is_some() { | 19122 | if vartx_leaves.is_some() { |
| 19123 | // Plane 0 is already correct per transform unit | 19123 | // Plane 0 is already correct per transform unit |
| 19124 | // ([`Neighbours::record_mi_luma`] above); this writes everything else | 19124 | // ([`Neighbours::record_mi_luma`] above); this writes everything else |
| 19125 | - // [`Neighbours::record_rect`] would (a var-tx block is always square, | 19125 | + // [`Neighbours::record_rect`] would. |
| 19126 | - // so `write_w == write_h == side`). | 19126 | + // |
| 19127 | - neighbours.record_split_luma_rect_mi(at, side, side, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]); | 19127 | + // lane-sbab r1: this used to pass `side, side` on the premise that "a |
| 19128 | + // var-tx block is always square". That stopped being true the moment | ||
| 19129 | + // the SB-level rect strips landed (lane-inter4): a 64x32 / 32x64 | ||
| 19130 | + // strip keeps `side = SB` for syntax but is NOT square, and stamping | ||
| 19131 | + // its neighbour bands 64x64 wrote `above_side_mi = 64` where libaom's | ||
| 19132 | + // `update_partition_context` writes `partition_context_lookup[ | ||
| 19133 | + // BLOCK_32X64]`. The next superblock row then read the partition | ||
| 19134 | + // context one value low (ctx 2 where aomdec says 3) and desynced. | ||
| 19135 | + // The true footprint is `write_w`/`write_h`, exactly as the | ||
| 19136 | + // non-var-tx arm below uses. | ||
| 19137 | + neighbours.record_split_luma_rect_mi(at, write_w, write_h, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]); | ||
| 19128 | } else { | 19138 | } else { |
| 19129 | neighbours.record_rect_mi( | 19139 | neighbours.record_rect_mi( |
| 19130 | at, | 19140 | at, |
crates/ec-av1/src/refusal_inventory.rsmodified+4 -0
| @@ -67,6 +67,10 @@ const REFUSALS: &[&str] = &[ | |||
| 67 | // the 8x8 leaf's TX_4X4 2x2 grid is still refused here. | 67 | // the 8x8 leaf's TX_4X4 2x2 grid is still refused here. |
| 68 | "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 transform units", | 68 | "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 transform units", |
| 69 | "an inter frame with no key frame before it", | 69 | "an inter frame with no key frame before it", |
| 70 | + // lane-sbab r1 lifted the superblock-level AB refusal that stood here | ||
| 71 | + // (HORZ_A/HORZ_B/VERT_A/VERT_B at 64x64 of an inter frame: two 32x32 | ||
| 72 | + // inter squares plus one true 64x32/32x64 inter strip, gate | ||
| 73 | + // `a_real_aomenc_inter_sequence_with_superblock_level_ab_partitions_decodes_pixel_exact`). | ||
| 70 | // lane-inter16ab r1 lifted the AB half (HORZ_A/HORZ_B/VERT_A/VERT_B at | 74 | // lane-inter16ab r1 lifted the AB half (HORZ_A/HORZ_B/VERT_A/VERT_B at |
| 71 | // the 16x16 level of an inter frame: two 8x8 inter leaves plus one true | 75 | // the 16x16 level of an inter frame: two 8x8 inter leaves plus one true |
| 72 | // 16x8/8x16 inter strip, gate | 76 | // 16x8/8x16 inter strip, gate |
crates/ec-av1/src/stream.rsmodified+208 -0
| @@ -8371,6 +8371,214 @@ mod tests { | |||
| 8371 | } | 8371 | } |
| 8372 | 8372 | ||
| 8373 | 8373 | ||
| 8374 | + #[test] | ||
| 8375 | + // lane-sbab r1: the SUPERBLOCK-level (64x64) AB partitions on an INTER | ||
| 8376 | + // frame -- PARTITION_HORZ_A/_HORZ_B/_VERT_A/_VERT_B at 64x64, i.e. two | ||
| 8377 | + // 32x32 inter squares plus one true 64x32/32x64 inter strip, decoded in | ||
| 8378 | + // libaom `decode_partition`'s visit order. Every decode-order frame is | ||
| 8379 | + // compared Y/U/V against ffmpeg, refusals are counted and never SKIPped, | ||
| 8380 | + // out-of-scope mismatches fail the gate, and EACH of the four arms must | ||
| 8381 | + // have fired on a pixel-exact attempt (RD picking only HORZ_A is not | ||
| 8382 | + // proof of four). `--min-partition-size=32` keeps every AB piece at or | ||
| 8383 | + // above 32x32, `--max-partition-size=64` puts the AB symbol at the SB | ||
| 8384 | + // root, and `--enable-1to4-partitions=0` because the 64-level 1:4 pair is | ||
| 8385 | + // a different lane's shape. | ||
| 8386 | + fn a_real_aomenc_inter_sequence_with_superblock_level_ab_partitions_decodes_pixel_exact() { | ||
| 8387 | + const NAME: &str = | ||
| 8388 | + "a_real_aomenc_inter_sequence_with_superblock_level_ab_partitions_decodes_pixel_exact"; | ||
| 8389 | + let _gate_lock = lock_gate_counters(); | ||
| 8390 | + if !have_ffmpeg() { | ||
| 8391 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 8392 | + return; | ||
| 8393 | + } | ||
| 8394 | + if !have_aomenc() { | ||
| 8395 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 8396 | + return; | ||
| 8397 | + } | ||
| 8398 | + let (width, height, frame_count) = (256usize, 192usize, 6usize); | ||
| 8399 | + // Per arm, over both bit depths: how many pixel-exact attempts fired | ||
| 8400 | + // it at least once. | ||
| 8401 | + let mut arms_total = [0u32; 4]; | ||
| 8402 | + for bit_depth in [8u32, 10u32] { | ||
| 8403 | + let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) = | ||
| 8404 | + (0u32, 0u32, 0u32, 0u32); | ||
| 8405 | + let mut arms_proved = [0u32; 4]; | ||
| 8406 | + for attempt in 0..20u32 { | ||
| 8407 | + // Axes measured live by the r1 sweep | ||
| 8408 | + // (~/.cache/sbab-tmp/sweep.sh, table in the report): two | ||
| 8409 | + // motion steps x two source orientations x five quantisers x | ||
| 8410 | + // a single-tile and a two-tile-column arm. All four arms | ||
| 8411 | + // appear in that table at both depths; no single (sp, shape, | ||
| 8412 | + // cq) point carries more than three of them, which is why the | ||
| 8413 | + // sweep is this wide. | ||
| 8414 | + let cq = [18, 26, 34, 45, 55][(attempt % 5) as usize]; | ||
| 8415 | + let natural = attempt / 5 % 2 == 1; | ||
| 8416 | + let sp = if attempt / 10 % 2 == 0 { 3 } else { 8 }; | ||
| 8417 | + // r1: a `--tile-columns=1` twin of these 20 attempts was run | ||
| 8418 | + // and is deliberately NOT in the gate -- its streams PANIC in | ||
| 8419 | + // `mc::from_switchable_symbol` (a 4th symbol out of a | ||
| 8420 | + // 3-symbol alphabet), the exact signature lane-inter16ab r1 | ||
| 8421 | + // recorded for its own tiled arm and which the ledger pins to | ||
| 8422 | + // the below-8x8 inter leaf, not to anything this lane | ||
| 8423 | + // touches. Recorded as open residue in | ||
| 8424 | + // lanes/sbab-r1.report.md rather than turned into a SKIP or a | ||
| 8425 | + // weakened assert. | ||
| 8426 | + let tile_cols = "0"; | ||
| 8427 | + let duration = frame_count as f64 / 25.0; | ||
| 8428 | + // Long-period continuous tone: the 64-level AB partitions | ||
| 8429 | + // need the L/T-shaped feature to span 32 px, so the sinusoid | ||
| 8430 | + // periods here are ~3x the 16-level gate's. | ||
| 8431 | + let lum = if natural { | ||
| 8432 | + format!("128+58*sin((Y+N*{sp})/17)+40*sin(X/29)+20*sin((X+Y)/13)") | ||
| 8433 | + } else { | ||
| 8434 | + format!("128+58*sin((X+N*{sp})/17)+40*sin(Y/29)+20*sin((X-Y)/13)") | ||
| 8435 | + }; | ||
| 8436 | + let source = format!( | ||
| 8437 | + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ | ||
| 8438 | + geq=lum='{lum}',format=yuv420p" | ||
| 8439 | + ); | ||
| 8440 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 8441 | + let y4m = Command::new("ffmpeg") | ||
| 8442 | + .args([ | ||
| 8443 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), | ||
| 8444 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 8445 | + ]) | ||
| 8446 | + .stdin(Stdio::null()) | ||
| 8447 | + .stdout(Stdio::piped()) | ||
| 8448 | + .stderr(Stdio::piped()) | ||
| 8449 | + .output() | ||
| 8450 | + .expect("ffmpeg failed to run"); | ||
| 8451 | + assert!( | ||
| 8452 | + y4m.status.success(), | ||
| 8453 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 8454 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 8455 | + ); | ||
| 8456 | + let cq_arg = format!("--cq-level={cq}"); | ||
| 8457 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 8458 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 8459 | + let tile_arg = format!("--tile-columns={tile_cols}"); | ||
| 8460 | + let args: Vec<&str> = vec![ | ||
| 8461 | + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", | ||
| 8462 | + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, | ||
| 8463 | + "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", | ||
| 8464 | + "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", | ||
| 8465 | + "--lag-in-frames=0", "--kf-max-dist=9999", &tile_arg, | ||
| 8466 | + // Per-arm overrides go LAST: aomenc keeps the last | ||
| 8467 | + // occurrence of a repeated --enable-* flag. | ||
| 8468 | + "--enable-rect-partitions=1", "--enable-ab-partitions=1", | ||
| 8469 | + "--enable-1to4-partitions=0", "--min-partition-size=32", | ||
| 8470 | + "--max-partition-size=64", | ||
| 8471 | + "--obu", "-o", "-", "-", | ||
| 8472 | + ]; | ||
| 8473 | + let mut child = Command::new(aomenc_path()) | ||
| 8474 | + .args(&args) | ||
| 8475 | + .stdin(Stdio::piped()) | ||
| 8476 | + .stdout(Stdio::piped()) | ||
| 8477 | + .stderr(Stdio::piped()) | ||
| 8478 | + .spawn() | ||
| 8479 | + .expect("aomenc failed to start"); | ||
| 8480 | + child | ||
| 8481 | + .stdin | ||
| 8482 | + .take() | ||
| 8483 | + .expect("aomenc stdin") | ||
| 8484 | + .write_all(&y4m.stdout) | ||
| 8485 | + .expect("writing y4m to aomenc"); | ||
| 8486 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 8487 | + assert!( | ||
| 8488 | + out.status.success(), | ||
| 8489 | + "aomenc refused the fixture: {}", | ||
| 8490 | + String::from_utf8_lossy(&out.stderr) | ||
| 8491 | + ); | ||
| 8492 | + let stream = out.stdout; | ||
| 8493 | + let before = decode::sb_ab_inter_hits_by_arm(); | ||
| 8494 | + let frames = match decode_stream(&stream) { | ||
| 8495 | + Err(e) => { | ||
| 8496 | + let msg = e.to_string(); | ||
| 8497 | + assert!( | ||
| 8498 | + msg.contains("unsupported"), | ||
| 8499 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ | ||
| 8500 | + attempt {attempt}): {msg}" | ||
| 8501 | + ); | ||
| 8502 | + named_refusals += 1; | ||
| 8503 | + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); | ||
| 8504 | + continue; | ||
| 8505 | + } | ||
| 8506 | + Ok(frames) => frames, | ||
| 8507 | + }; | ||
| 8508 | + let after = decode::sb_ab_inter_hits_by_arm(); | ||
| 8509 | + let fired: Vec<usize> = (0..4).map(|a| after[a] - before[a]).collect(); | ||
| 8510 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 8511 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 8512 | + } else { | ||
| 8513 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 8514 | + }; | ||
| 8515 | + assert_eq!(frames.len(), frame_count); | ||
| 8516 | + let mismatched = frames | ||
| 8517 | + .iter() | ||
| 8518 | + .zip(&ffmpeg_frames) | ||
| 8519 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | ||
| 8520 | + if fired.iter().sum::<usize>() == 0 { | ||
| 8521 | + out_of_scope += 1; | ||
| 8522 | + if mismatched { | ||
| 8523 | + oos_mismatch += 1; | ||
| 8524 | + eprintln!( | ||
| 8525 | + "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \ | ||
| 8526 | + 64-level inter AB partition -- another shape's defect" | ||
| 8527 | + ); | ||
| 8528 | + } | ||
| 8529 | + continue; | ||
| 8530 | + } | ||
| 8531 | + if mismatched { | ||
| 8532 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 8533 | + let bad: Vec<usize> = | ||
| 8534 | + (0..got.y.len()).filter(|&k| got.y[k] != want.y[k]).collect(); | ||
| 8535 | + if !bad.is_empty() { | ||
| 8536 | + eprintln!( | ||
| 8537 | + "{NAME}: attempt {attempt} {bit_depth}-bit frame {i}: {} luma \ | ||
| 8538 | + pixels differ, first at ({}, {}), max |delta| {}", | ||
| 8539 | + bad.len(), | ||
| 8540 | + bad[0] % width, | ||
| 8541 | + bad[0] / width, | ||
| 8542 | + bad.iter() | ||
| 8543 | + .map(|&k| (got.y[k] as i32 - want.y[k] as i32).abs()) | ||
| 8544 | + .max() | ||
| 8545 | + .unwrap_or(0) | ||
| 8546 | + ); | ||
| 8547 | + } | ||
| 8548 | + } | ||
| 8549 | + } | ||
| 8550 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 8551 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); | ||
| 8552 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); | ||
| 8553 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); | ||
| 8554 | + } | ||
| 8555 | + for a in 0..4 { | ||
| 8556 | + if fired[a] > 0 { | ||
| 8557 | + arms_proved[a] += 1; | ||
| 8558 | + arms_total[a] += 1; | ||
| 8559 | + } | ||
| 8560 | + } | ||
| 8561 | + matched += 1; | ||
| 8562 | + } | ||
| 8563 | + eprintln!( | ||
| 8564 | + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ | ||
| 8565 | + attempts carrying a 64-level inter AB partition, per-arm attempts \ | ||
| 8566 | + HORZ_A/HORZ_B/VERT_A/VERT_B={arms_proved:?}, {out_of_scope} attempts carried \ | ||
| 8567 | + none ({oos_mismatch} of them mismatched)" | ||
| 8568 | + ); | ||
| 8569 | + assert_eq!( | ||
| 8570 | + oos_mismatch, 0, | ||
| 8571 | + "{NAME}: {oos_mismatch} attempt(s) with no 64-level inter AB partition decoded \ | ||
| 8572 | + but mismatched ffmpeg -- a defect of another shape, not a pass" | ||
| 8573 | + ); | ||
| 8574 | + } | ||
| 8575 | + assert!( | ||
| 8576 | + arms_total.iter().all(|&n| n > 0), | ||
| 8577 | + "{NAME}: not every 64-level inter AB arm fired on a pixel-exact attempt \ | ||
| 8578 | + (HORZ_A/HORZ_B/VERT_A/VERT_B={arms_total:?}) -- the unfired arm(s) are unproven" | ||
| 8579 | + ); | ||
| 8580 | + } | ||
| 8581 | + | ||
| 8374 | #[test] | 8582 | #[test] |
| 8375 | fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() { | 8583 | fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() { |
| 8376 | if !have_ffmpeg() { | 8584 | if !have_ffmpeg() { |