ec-av1: 12-bit single-ref ROTZOOM global-warp witness
Browse files at this commit0f27d4e44f4306400d2c514cf6047914915cb7aaParent: 38b69193 changed files +258 -0
- crates/ec-av1/src/decode.rs +23 -0
- crates/ec-av1/src/stream.rs +141 -0
- lanes/av1gwarp12.report.md +94 -0
crates/ec-av1/src/decode.rsmodified+23 -0
| @@ -4356,6 +4356,23 @@ pub(crate) fn affine_gm_hits() -> usize { | |||
| 4356 | AFFINE_GM_HITS.with(|c| c.get()) | 4356 | AFFINE_GM_HITS.with(|c| c.get()) |
| 4357 | } | 4357 | } |
| 4358 | 4358 | ||
| 4359 | +// lane-av1gwarp12: how many 16x16+ blocks built their SINGLE-reference | ||
| 4360 | +// prediction through `crate::warp::global_warp_params` with a FOUR-parameter | ||
| 4361 | +// (`ROTZOOM`) model. Vanilla aomenc pins its global-motion search to ROTZOOM | ||
| 4362 | +// (`global_motion_facade.c:24`), so this is the only >TRANSLATION single-ref | ||
| 4363 | +// global-warp arm a real aomenc stream can reach (AFFINE needs the widened | ||
| 4364 | +// side build and its own counter, [`AFFINE_GM_HITS`]). | ||
| 4365 | +thread_local! { | ||
| 4366 | + static ROTZOOM_GM_WARP_HITS: std::cell::Cell<usize> = | ||
| 4367 | + const { std::cell::Cell::new(0) }; | ||
| 4368 | +} | ||
| 4369 | + | ||
| 4370 | +/// Current value of [`ROTZOOM_GM_WARP_HITS`]. | ||
| 4371 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 4372 | +pub(crate) fn rotzoom_gm_warp_hits() -> usize { | ||
| 4373 | + ROTZOOM_GM_WARP_HITS.with(|c| c.get()) | ||
| 4374 | +} | ||
| 4375 | + | ||
| 4359 | // lane-t900 r9: rect blocks whose warp-sample top-right probe answers | 4376 | // lane-t900 r9: rect blocks whose warp-sample top-right probe answers |
| 4360 | // differently at the block's WIDTH than at libaom's | 4377 | // differently at the block's WIDTH than at libaom's |
| 4361 | // `AOMMAX(xd->width, xd->height)` -- each one is a `num_proj_ref` that could | 4378 | // `AOMMAX(xd->width, xd->height)` -- each one is a `num_proj_ref` that could |
| @@ -32449,6 +32466,12 @@ fn decode_inter_block( | |||
| 32449 | if warp_params.is_some() && gm_ref.model == ec_av1_syntax::WarpModel::Affine { | 32466 | if warp_params.is_some() && gm_ref.model == ec_av1_syntax::WarpModel::Affine { |
| 32450 | hit!(AFFINE_GM_HITS); | 32467 | hit!(AFFINE_GM_HITS); |
| 32451 | } | 32468 | } |
| 32469 | + // lane-av1gwarp12: the ROTZOOM sibling -- the only | ||
| 32470 | + // >TRANSLATION model vanilla aomenc can emit for a single-ref | ||
| 32471 | + // global-motion block (encoder search pinned to ROTZOOM). | ||
| 32472 | + if warp_params.is_some() && gm_ref.model == ec_av1_syntax::WarpModel::Rotzoom { | ||
| 32473 | + hit!(ROTZOOM_GM_WARP_HITS); | ||
| 32474 | + } | ||
| 32452 | } | 32475 | } |
| 32453 | // lane-av112bitw: a local `WARPED_CAUSAL` projection (set above) | 32476 | // lane-av112bitw: a local `WARPED_CAUSAL` projection (set above) |
| 32454 | // or a global warp model both land here with `warp_params` set -- | 32477 | // or a global warp model both land here with `warp_params` set -- |
crates/ec-av1/src/stream.rsmodified+141 -0
| @@ -8763,6 +8763,54 @@ pub(crate) mod tests { | |||
| 8763 | y4m | 8763 | y4m |
| 8764 | } | 8764 | } |
| 8765 | 8765 | ||
| 8766 | + /// lane-av1gwarp12 fixture: rotating + uniformly zooming mandelbrot as a | ||
| 8767 | + /// C420p12 y4m. Rotation composed with a UNIFORM scale is a similarity | ||
| 8768 | + /// transform -- exactly the family a 4-parameter ROTZOOM global model | ||
| 8769 | + /// expresses (the affine gate needs the anisotropic stretch to force | ||
| 8770 | + /// 6 parameters; this lane needs the model vanilla aomenc actually | ||
| 8771 | + /// searches, ROTZOOM). | ||
| 8772 | + fn y4m_12bit_rotzoom_gm_source(frames: usize) -> Vec<u8> { | ||
| 8773 | + const W: usize = 128; | ||
| 8774 | + const H: usize = 128; | ||
| 8775 | + let source = format!( | ||
| 8776 | + "mandelbrot=size=192x192:rate=25,rotate=a=0.12*t:c=black,\ | ||
| 8777 | + scale=w='ceil(192*(1+0.04*n)/2)*2':h='ceil(192*(1+0.04*n)/2)*2':eval=frame,\ | ||
| 8778 | + crop={W}:{H}" | ||
| 8779 | + ); | ||
| 8780 | + let duration = (frames as f64 / 25.0).to_string(); | ||
| 8781 | + let ff_args: Vec<&str> = vec![ | ||
| 8782 | + "-v", | ||
| 8783 | + "error", | ||
| 8784 | + "-f", | ||
| 8785 | + "lavfi", | ||
| 8786 | + "-i", | ||
| 8787 | + &source, | ||
| 8788 | + "-pix_fmt", | ||
| 8789 | + "yuv420p12le", | ||
| 8790 | + // y4m has no official 12-bit tag, same as the 10-bit gate. | ||
| 8791 | + "-strict", | ||
| 8792 | + "-1", | ||
| 8793 | + "-t", | ||
| 8794 | + &duration, | ||
| 8795 | + "-f", | ||
| 8796 | + "yuv4mpegpipe", | ||
| 8797 | + "-", | ||
| 8798 | + ]; | ||
| 8799 | + let out = Command::new("ffmpeg") | ||
| 8800 | + .args(&ff_args) | ||
| 8801 | + .stdin(Stdio::null()) | ||
| 8802 | + .stdout(Stdio::piped()) | ||
| 8803 | + .stderr(Stdio::piped()) | ||
| 8804 | + .output() | ||
| 8805 | + .expect("ffmpeg failed to run"); | ||
| 8806 | + assert!( | ||
| 8807 | + out.status.success(), | ||
| 8808 | + "ffmpeg fixture: {}", | ||
| 8809 | + String::from_utf8_lossy(&out.stderr) | ||
| 8810 | + ); | ||
| 8811 | + out.stdout | ||
| 8812 | + } | ||
| 8813 | + | ||
| 8766 | /// The 12-bit coding recipe shared by the witness gates (cpu-used=0 so | 8814 | /// The 12-bit coding recipe shared by the witness gates (cpu-used=0 so |
| 8767 | /// every search runs; explicit CDEF/restoration ON). Warp/global-motion | 8815 | /// every search runs; explicit CDEF/restoration ON). Warp/global-motion |
| 8768 | /// are deliberately NOT spelled here: this aomenc honours the LAST | 8816 | /// are deliberately NOT spelled here: this aomenc honours the LAST |
| @@ -20403,6 +20451,99 @@ pub(crate) mod tests { | |||
| 20403 | } | 20451 | } |
| 20404 | } | 20452 | } |
| 20405 | 20453 | ||
| 20454 | + /// lane-av1gwarp12: the SINGLE-reference GLOBAL-warp witness at 12 bits | ||
| 20455 | + /// -- the open half lane-av112bitw recorded (engagement 0 on every prior | ||
| 20456 | + /// 12-bit content). The decode path is the same `warp_affine` with | ||
| 20457 | + /// `warp_round_0(12)` the local-warp witness proved, fed by | ||
| 20458 | + /// `global_warp_params(gm_ref.params)` at `decode_inter_block`'s | ||
| 20459 | + /// single-ref arm -- but composition had no stream: the travelling-box | ||
| 20460 | + /// source fits only TRANSLATION global models (excluded by | ||
| 20461 | + /// `is_global_mv_block`), and the rotating mandelbrot reached the global | ||
| 20462 | + /// models only on compound blocks. This recipe closes it: rotation + | ||
| 20463 | + /// uniform zoom (a similarity transform, ROTZOOM's exact family), the | ||
| 20464 | + /// compound tools off so a global model can only ride a single-reference | ||
| 20465 | + /// GLOBALMV block, and partitions pinned to 32 so the 8x8 leaf arm is | ||
| 20466 | + /// structurally out of the stream. Vanilla aomenc pins its gm search to | ||
| 20467 | + /// ROTZOOM (`global_motion_facade.c:24`), so every >TRANSLATION model a | ||
| 20468 | + /// real aomenc emits is ROTZOOM; AFFINE needs the widened side build | ||
| 20469 | + /// (`a_real_affine_global_motion_stream_decodes_pixel_exact`). | ||
| 20470 | + /// | ||
| 20471 | + /// Non-vacuous by construction: `rotzoom_gm_warp_hits()` hard-asserts a | ||
| 20472 | + /// 16x16+ block was really predicted through the global warp with a | ||
| 20473 | + /// ROTZOOM model, the zero `compound_warp_hits` delta keeps the | ||
| 20474 | + /// single-reference premise honest, and every plane of every frame | ||
| 20475 | + /// compares against ffmpeg. | ||
| 20476 | + #[test] | ||
| 20477 | + fn a_real_rotzoom_global_warp_12bit_stream_decodes_pixel_exact() { | ||
| 20478 | + const NAME: &str = "a_real_rotzoom_global_warp_12bit_stream_decodes_pixel_exact"; | ||
| 20479 | + let _gate_lock = lock_gate_counters(); | ||
| 20480 | + if !have_ffmpeg() { | ||
| 20481 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 20482 | + return; | ||
| 20483 | + } | ||
| 20484 | + if !have_aomenc() { | ||
| 20485 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 20486 | + return; | ||
| 20487 | + } | ||
| 20488 | + const W: usize = 128; | ||
| 20489 | + const H: usize = 128; | ||
| 20490 | + const FRAMES: usize = 16; | ||
| 20491 | + let y4m = y4m_12bit_rotzoom_gm_source(FRAMES); | ||
| 20492 | + let stream = encode_12bit( | ||
| 20493 | + &y4m, | ||
| 20494 | + FRAMES, | ||
| 20495 | + &[ | ||
| 20496 | + "--enable-global-motion=1", | ||
| 20497 | + "--enable-warped-motion=0", | ||
| 20498 | + "--enable-obmc=0", | ||
| 20499 | + "--enable-masked-comp=0", | ||
| 20500 | + "--enable-interintra-comp=0", | ||
| 20501 | + "--enable-onesided-comp=0", | ||
| 20502 | + "--enable-ref-frame-mvs=0", | ||
| 20503 | + "--min-partition-size=32", | ||
| 20504 | + "--max-partition-size=32", | ||
| 20505 | + ], | ||
| 20506 | + ); | ||
| 20507 | + assert_12bit_sequence_header(&stream, NAME); | ||
| 20508 | + let (before_rotzoom, before_affine, before_selected, before_compound) = ( | ||
| 20509 | + decode::rotzoom_gm_warp_hits(), | ||
| 20510 | + decode::affine_gm_hits(), | ||
| 20511 | + decode::warp_selected_hits(), | ||
| 20512 | + decode::compound_warp_hits(), | ||
| 20513 | + ); | ||
| 20514 | + let frames = decode_stream(&stream).unwrap_or_else(|e| { | ||
| 20515 | + panic!("{NAME}: decode_stream refused a real 12-bit global-warp stream: {e}") | ||
| 20516 | + }); | ||
| 20517 | + assert_eq!(frames.len(), FRAMES); | ||
| 20518 | + let (delta_rotzoom, delta_affine, delta_selected) = ( | ||
| 20519 | + decode::rotzoom_gm_warp_hits() - before_rotzoom, | ||
| 20520 | + decode::affine_gm_hits() - before_affine, | ||
| 20521 | + decode::warp_selected_hits() - before_selected, | ||
| 20522 | + ); | ||
| 20523 | + eprintln!( | ||
| 20524 | + "{NAME}: gm_warp_engagement rotzoom(single-ref global warp)={delta_rotzoom} \ | ||
| 20525 | + affine={delta_affine} selected_local_warp={delta_selected}" | ||
| 20526 | + ); | ||
| 20527 | + assert!( | ||
| 20528 | + delta_rotzoom > 0, | ||
| 20529 | + "{NAME}: decoded but no single-reference ROTZOOM global-warp block fired -- \ | ||
| 20530 | + the 12-bit single-ref global-warp path is unexercised and the pixel \ | ||
| 20531 | + compare would prove nothing" | ||
| 20532 | + ); | ||
| 20533 | + assert_eq!( | ||
| 20534 | + decode::compound_warp_hits() - before_compound, | ||
| 20535 | + 0, | ||
| 20536 | + "{NAME}: a compound warp block ran -- the single-reference premise is gone" | ||
| 20537 | + ); | ||
| 20538 | + let ffmpeg_frames = ffmpeg_decode_sequence_12bit(&stream, W, H, FRAMES); | ||
| 20539 | + for (i, (ours, reference)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 20540 | + assert_eq!(ours.y, reference.y, "{NAME} frame {i} luma vs ffmpeg"); | ||
| 20541 | + assert_eq!(ours.u, reference.u, "{NAME} frame {i} U vs ffmpeg"); | ||
| 20542 | + assert_eq!(ours.v, reference.v, "{NAME} frame {i} V vs ffmpeg"); | ||
| 20543 | + } | ||
| 20544 | + eprintln!("{NAME}: {FRAMES} frames pixel-exact vs ffmpeg, rotzoom_gm_warp_hits={delta_rotzoom}"); | ||
| 20545 | + } | ||
| 20546 | + | ||
| 20406 | /// lane-gmaffine r1: the two 8x8-LEAF motion gates. `decode_inter_block8` | 20547 | /// lane-gmaffine r1: the two 8x8-LEAF motion gates. `decode_inter_block8` |
| 20407 | /// is a separate function from [`decode_inter_block`], and until this | 20548 | /// is a separate function from [`decode_inter_block`], and until this |
| 20408 | /// round it refused both `GLOBALMV` ("GLOBALMV (round 3)") and | 20549 | /// round it refused both `GLOBALMV` ("GLOBALMV (round 3)") and |
lanes/av1gwarp12.report.mdadded+94 -0
| @@ -0,0 +1,94 @@ | |||
| 1 | +# lane-av1-gwarp12 — the single-ref GLOBAL-warp witness at 12 bits | ||
| 2 | + | ||
| 3 | +Base fe3e8418, worktree `edith_codecs-av1gwarp12`, branch `lane-av1-gwarp12`. | ||
| 4 | +The charter: close lane-av112bitw's open half — "single-ref GLOBAL-warp at 12 | ||
| 5 | +bits has no stream of its own" — with a real `aomenc --bit-depth=12` stream | ||
| 6 | +whose single-reference inter blocks are predicted through | ||
| 7 | +`warp::global_warp_params` under a ROTZOOM model, decoded against BOTH pixel | ||
| 8 | +oracles, or an honest miss table. | ||
| 9 | + | ||
| 10 | +## Result: FOUND, first recipe, pixel-exact against both oracles | ||
| 11 | + | ||
| 12 | +Encode attempts aimed at the target: **2** (budget 8). Attempt 1 (the gate | ||
| 13 | +itself) fired and was already byte-exact vs ffmpeg; attempt 2 re-encoded the | ||
| 14 | +same recipe standalone for the aomdec oracle. | ||
| 15 | + | ||
| 16 | +1. `aomdec == ffmpeg` on the probe stream | ||
| 17 | + (`/tmp/gwarp12probe/probe.obu`, sha256 | ||
| 18 | + `3c6102cd0dd9bbccb5d15b2f3605a7dcea9e3189c1efc7d0317b16fc481af5fe`, | ||
| 19 | + 37194 bytes; 16x 128x128 frames, 786432 raw bytes each decoder, | ||
| 20 | + `cmp`-equal payloads). Since the gate proves our decode == ffmpeg on the | ||
| 21 | + live re-encode, all three decoders agree on the firing stream. | ||
| 22 | +2. Engagement: `rotzoom_gm_warp_hits = 152` (16x16+ single-ref blocks | ||
| 23 | + predicted through `global_warp_params` with a ROTZOOM model), affine 0 | ||
| 24 | + (vanilla aomenc cannot emit it, see below), local-warp symbol 0 | ||
| 25 | + (`--enable-warped-motion=0` isolates the global arm), | ||
| 26 | + `compound_warp_hits` delta 0 (hard-asserted; single-ref premise held). | ||
| 27 | + | ||
| 28 | +## Why the recipe works when the prior ones didn't | ||
| 29 | + | ||
| 30 | +Every prior 12-bit content fit TRANSLATION global models (excluded by | ||
| 31 | +`is_global_mv_block`) or reached >TRANSLATION models only on compound blocks. | ||
| 32 | +The lever is composition, not the encoder: | ||
| 33 | + | ||
| 34 | +- **Content**: rotation + UNIFORM zoom — a similarity transform, exactly the | ||
| 35 | + family the 4-parameter ROTZOOM model expresses (`mandelbrot` + | ||
| 36 | + `rotate=a=0.12*t` + symmetric `scale` over `n`, cropped 128x128). | ||
| 37 | +- **Compound tools OFF** (`--enable-masked-comp=0 --enable-interintra-comp=0 | ||
| 38 | + --enable-onesided-comp=0`, plus lag 0 / alt-ref 0 so all refs are | ||
| 39 | + forward): a global model can then only ride a single-reference GLOBALMV | ||
| 40 | + block. | ||
| 41 | +- **`--enable-warped-motion=0`**: no local WARPED_CAUSAL can take | ||
| 42 | + `warp_params` first; the `warp_params.is_none()` guard at the single-ref | ||
| 43 | + arm makes every hit unambiguously a global-warp hit. | ||
| 44 | +- **`--min/--max-partition-size=32`**: every inter leaf is 16x16+, so the | ||
| 45 | + 8x8-leaf arm (`decode_inter_block8`, leaf8 lane's file region) is | ||
| 46 | + structurally out of the stream and my counter proves MY site, not a twin. | ||
| 47 | +- **Model bound is encoder-side**: `global_motion_facade.c:24` pins the gm | ||
| 48 | + search to ROTZOOM, so every >TRANSLATION single-ref model a real aomenc | ||
| 49 | + can emit IS ROTZOOM. (AFFINE needs the widened side build and has its own | ||
| 50 | + gate + `affine_gm_hits` at 8/10 bits.) | ||
| 51 | + | ||
| 52 | +Exact flags: the `encode_12bit` witness base (cq 20, cpu-used 0, sb 64, | ||
| 53 | +profile 2, cdef/restoration ON) plus the extras above and | ||
| 54 | +`--enable-global-motion=1 --enable-obmc=0 --enable-ref-frame-mvs=0`. | ||
| 55 | +Fixture: `y4m_12bit_rotzoom_gm_source` (ffmpeg lavfi, C420p12 y4m, 16 | ||
| 56 | +frames). The gate re-encodes live; engagement reproduced identically across | ||
| 57 | +three runs (152/152/152). | ||
| 58 | + | ||
| 59 | +## What changed | ||
| 60 | + | ||
| 61 | +- **decode.rs** — one new counter pair at the single-ref global-warp arm | ||
| 62 | + (`decode_inter_block`, the lane's own site): `ROTZOOM_GM_WARP_HITS` + | ||
| 63 | + `rotzoom_gm_warp_hits()`, bumped when `global_warp_params` resolves AND | ||
| 64 | + `gm_ref.model == Rotzoom`, mirroring the `AFFINE_GM_HITS` twin. The 8x8 | ||
| 65 | + leaf arm's copy was deliberately NOT touched (leaf8 lane). | ||
| 66 | +- **stream.rs** — `y4m_12bit_rotzoom_gm_source` fixture helper + the gate | ||
| 67 | + `a_real_rotzoom_global_warp_12bit_stream_decodes_pixel_exact`: | ||
| 68 | + `assert_12bit_sequence_header` preflight, hard `delta_rotzoom > 0` (a | ||
| 69 | + warpless stream cannot pass), hard `compound_warp_hits` delta == 0, and | ||
| 70 | + every plane of every frame byte-equal vs ffmpeg | ||
| 71 | + (`ffmpeg_decode_sequence_12bit`). | ||
| 72 | + | ||
| 73 | +No decoder arithmetic changed: the single-ref path was lifted by | ||
| 74 | +lane-av112bitw (parameterised `warp_round_0`) and the composition argument | ||
| 75 | +held — the stream proves it instead of arguing it. Non-vacuity is by | ||
| 76 | +construction (counter assert), and the gate FAILED-category risk (silent | ||
| 77 | +skip) is closed: encode/ffmpeg presence is hard-asserted inside the gate. | ||
| 78 | + | ||
| 79 | +## Verification | ||
| 80 | + | ||
| 81 | +- New gate green (encode attempt 1): 16 frames pixel-exact vs ffmpeg, | ||
| 82 | + 152 rotzoom hits. | ||
| 83 | +- aomdec oracle probe (encode attempt 2): aomdec == ffmpeg, sha256 above. | ||
| 84 | +- Scoped sweep of the 12-bit family the counter addition touches: 9/9 green | ||
| 85 | + (`12bit` filter) including `a_12bit_warped_motion_stream_decodes_pixel_exact` | ||
| 86 | + (engagement still 7/1/0), both compound global-warp 12-bit gates (16x16+ | ||
| 87 | + and 8x8 leaf), grain refusal, screen refusal. | ||
| 88 | +- `cargo check -p ec-av1 --all-targets`: clean, no warnings. | ||
| 89 | + | ||
| 90 | +## Create-list audit | ||
| 91 | + | ||
| 92 | +One new file: this report. Touched: `decode.rs` (counter), `stream.rs` | ||
| 93 | +(helper + gate). No fixture committed (gate encodes live), no junk files; | ||
| 94 | +probe artifacts under /tmp are throwaway. | ||