Merge lane-av1-12bit-grain: 12-bit film grain pixel-exact
Browse files at this commit3 changed files +190 -52
- crates/ec-av1/src/refusal_inventory.rs +7 -5
- crates/ec-av1/src/stream.rs +93 -47
- lanes/av112bitg.report.md +90 -0
crates/ec-av1/src/refusal_inventory.rsmodified+7 -5
| @@ -94,8 +94,11 @@ const REFUSALS: &[&str] = &[ | |||
| 94 | // lane-av112bitc: compound joined the witnessed set (six-frame 12-bit | 94 | // lane-av112bitc: compound joined the witnessed set (six-frame 12-bit |
| 95 | // compound stream byte-exact vs ffmpeg; the combines already absorbed | 95 | // compound stream byte-exact vs ffmpeg; the combines already absorbed |
| 96 | // the CONV_BUF gain drop through `INTER_POST_ROUND - delta`). | 96 | // the CONV_BUF gain drop through `INTER_POST_ROUND - delta`). |
| 97 | + // lane-av112bitg: film grain joined the witnessed set (two-frame | ||
| 98 | + // `--film-grain-test=5` stream byte-exact vs ffmpeg; the gate that | ||
| 99 | + // replaced the refusal is | ||
| 100 | + // `a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact`). | ||
| 97 | "warped motion at 12 bits (warp's reduce bits inherit the 12-bit round_0 and no 12-bit warp witness exists)", | 101 | "warped motion at 12 bits (warp's reduce bits inherit the 12-bit round_0 and no 12-bit warp witness exists)", |
| 98 | - "film grain synthesis at 12 bits (no byte-exact 12-bit grain witness exists: the 12-bit gates encode with grain off)", | ||
| 99 | "a 12-bit frame with screen content tools (allow_screen_content_tools=1: neither palette nor intrabc has a 12-bit witness)", | 102 | "a 12-bit frame with screen content tools (allow_screen_content_tools=1: neither palette nor intrabc has a 12-bit witness)", |
| 100 | // lane-av1txr: the silent-garbage guard. A 4:4:4/4:2:2 stream used to | 103 | // lane-av1txr: the silent-garbage guard. A 4:4:4/4:2:2 stream used to |
| 101 | // decode with no refusal and wrong pixels (every chroma extent is | 104 | // decode with no refusal and wrong pixels (every chroma extent is |
| @@ -377,14 +380,13 @@ const PROVEN: &[(&str, &str)] = &[ | |||
| 377 | // lane-av112bitc: the compound pair left with its refusal -- the | 380 | // lane-av112bitc: the compound pair left with its refusal -- the |
| 378 | // six-frame compound stream now DECODES byte-exact | 381 | // six-frame compound stream now DECODES byte-exact |
| 379 | // (`a_real_aomenc_12bit_compound_inter_sequence_decodes_pixel_exact`). | 382 | // (`a_real_aomenc_12bit_compound_inter_sequence_decodes_pixel_exact`). |
| 383 | + // lane-av112bitg: the grain refusal left with its witness -- the | ||
| 384 | + // two-frame 12-bit grain stream now DECODES byte-exact | ||
| 385 | + // (`a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact`). | ||
| 380 | ( | 386 | ( |
| 381 | "warped motion at 12 bits (warp's reduce bits inherit the 12-bit round_0 and no 12-bit warp witness exists)", | 387 | "warped motion at 12 bits (warp's reduce bits inherit the 12-bit round_0 and no 12-bit warp witness exists)", |
| 382 | "a_12bit_warped_motion_stream_is_refused_by_name", | 388 | "a_12bit_warped_motion_stream_is_refused_by_name", |
| 383 | ), | 389 | ), |
| 384 | - ( | ||
| 385 | - "film grain synthesis at 12 bits (no byte-exact 12-bit grain witness exists: the 12-bit gates encode with grain off)", | ||
| 386 | - "a_12bit_film_grain_stream_is_refused_by_name", | ||
| 387 | - ), | ||
| 388 | ( | 390 | ( |
| 389 | "a 12-bit frame with screen content tools (allow_screen_content_tools=1: neither palette nor intrabc has a 12-bit witness)", | 391 | "a 12-bit frame with screen content tools (allow_screen_content_tools=1: neither palette nor intrabc has a 12-bit witness)", |
| 390 | "a_12bit_screen_content_stream_is_refused_by_name", | 392 | "a_12bit_screen_content_stream_is_refused_by_name", |
crates/ec-av1/src/stream.rsmodified+93 -47
| @@ -43,21 +43,6 @@ fn no_grain() -> bool { | |||
| 43 | std::env::var_os("EC_AV1_NO_GRAIN").is_some() | 43 | std::env::var_os("EC_AV1_NO_GRAIN").is_some() |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | -/// lane-av112bit: film grain synthesis has no 12-bit byte-exact witness (the | ||
| 47 | -/// lane's witnesses encode with grain off), so a 12-bit frame that would | ||
| 48 | -/// synthesise grain is refused by name at output rather than trusted -- | ||
| 49 | -/// `film_grain.rs` is bit-depth generic since lane-hbd10, but generic is not | ||
| 50 | -/// proven until a real 12-bit grain stream compares exact. | ||
| 51 | -fn grain_refusal(bit_depth: u32) -> Result<()> { | ||
| 52 | - if bit_depth == 12 { | ||
| 53 | - return Err(Error::unsupported( | ||
| 54 | - "AV1 decode_stream", | ||
| 55 | - "film grain synthesis at 12 bits (no byte-exact 12-bit grain witness exists: the 12-bit gates encode with grain off)", | ||
| 56 | - )); | ||
| 57 | - } | ||
| 58 | - Ok(()) | ||
| 59 | -} | ||
| 60 | - | ||
| 61 | // lane-hidden r1: where `EC_AV1_FINAL_DUMP`'s per-frame dump goes for the | 46 | // lane-hidden r1: where `EC_AV1_FINAL_DUMP`'s per-frame dump goes for the |
| 62 | // current thread, overriding the environment variable. Every ffmpeg/aomdec | 47 | // current thread, overriding the environment variable. Every ffmpeg/aomdec |
| 63 | // pixel gate in this repo compares SHOWN frames only (class | 48 | // pixel gate in this repo compares SHOWN frames only (class |
| @@ -728,7 +713,6 @@ pub fn decode_stream_with_threads( | |||
| 728 | pictures_shown += 1; | 713 | pictures_shown += 1; |
| 729 | let grain = header.film_grain; | 714 | let grain = header.film_grain; |
| 730 | let seq = SeqFlags::read(&parser); | 715 | let seq = SeqFlags::read(&parser); |
| 731 | - grain_refusal(u32::from(seq.bit_depth))?; | ||
| 732 | let tx = tx.clone(); | 716 | let tx = tx.clone(); |
| 733 | jobs.submit(move || { | 717 | jobs.submit(move || { |
| 734 | let reply = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { | 718 | let reply = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { |
| @@ -780,13 +764,6 @@ pub fn decode_stream_with_threads( | |||
| 780 | } | 764 | } |
| 781 | picture | 765 | picture |
| 782 | }; | 766 | }; |
| 783 | - if header.film_grain.apply_grain { | ||
| 784 | - grain_refusal( | ||
| 785 | - parser | ||
| 786 | - .sequence_header() | ||
| 787 | - .map_or(8, |seq| u32::from(seq.color_config.bit_depth)), | ||
| 788 | - )?; | ||
| 789 | - } | ||
| 790 | let output = if header.film_grain.apply_grain && !no_grain() { | 767 | let output = if header.film_grain.apply_grain && !no_grain() { |
| 791 | // lane-hbd10 r1: grain synthesis is bit-depth generic | 768 | // lane-hbd10 r1: grain synthesis is bit-depth generic |
| 792 | // (`film_grain.rs`'s `grain_range`/`scale_lut`, spec 7.18.3). | 769 | // (`film_grain.rs`'s `grain_range`/`scale_lut`, spec 7.18.3). |
| @@ -1128,9 +1105,6 @@ pub fn decode_stream_with_threads( | |||
| 1128 | // Grain is synthesised for OUTPUT only: a hidden frame is | 1105 | // Grain is synthesised for OUTPUT only: a hidden frame is |
| 1129 | // reported to the sink clean, exactly as the inline path | 1106 | // reported to the sink clean, exactly as the inline path |
| 1130 | // below reports it (spec 7.18.3.1). | 1107 | // below reports it (spec 7.18.3.1). |
| 1131 | - if header.film_grain.apply_grain { | ||
| 1132 | - grain_refusal(u32::from(seq.bit_depth))?; | ||
| 1133 | - } | ||
| 1134 | let output = if shown && header.film_grain.apply_grain && !no_grain() { | 1108 | let output = if shown && header.film_grain.apply_grain && !no_grain() { |
| 1135 | std::sync::Arc::new(crate::film_grain::apply_grain( | 1109 | std::sync::Arc::new(crate::film_grain::apply_grain( |
| 1136 | &picture, | 1110 | &picture, |
| @@ -1265,9 +1239,6 @@ pub fn decode_stream_with_threads( | |||
| 1265 | decode::note_fwd_kf(); | 1239 | decode::note_fwd_kf(); |
| 1266 | } | 1240 | } |
| 1267 | if header.show_frame { | 1241 | if header.show_frame { |
| 1268 | - if header.film_grain.apply_grain { | ||
| 1269 | - grain_refusal(u32::from(seq.bit_depth))?; | ||
| 1270 | - } | ||
| 1271 | let output = if header.film_grain.apply_grain && !no_grain() { | 1242 | let output = if header.film_grain.apply_grain && !no_grain() { |
| 1272 | let mc_identity = seq.mc_identity; | 1243 | let mc_identity = seq.mc_identity; |
| 1273 | std::sync::Arc::new(crate::film_grain::apply_grain( | 1244 | std::sync::Arc::new(crate::film_grain::apply_grain( |
| @@ -1713,10 +1684,12 @@ fn decode_frame( | |||
| 1713 | // the CONV_BUF gain), and CDEF/deblock/quant tables/SGR/palette reads/ | 1684 | // the CONV_BUF gain), and CDEF/deblock/quant tables/SGR/palette reads/ |
| 1714 | // superres upscale were already bit-depth generic (10-bit-proven). | 1685 | // superres upscale were already bit-depth generic (10-bit-proven). |
| 1715 | // Everything no 12-bit witness reached stays refused BY NAME at its own | 1686 | // Everything no 12-bit witness reached stays refused BY NAME at its own |
| 1716 | - // site: warp (decode.rs, warp's reduce bits inherit the 12-bit round_0), | 1687 | + // site: warp (decode.rs, warp's reduce bits inherit the 12-bit round_0) |
| 1717 | - // film grain (`grain_refusal`, the witnesses run with grain off), and | 1688 | + // and any per-feature gap the witnesses' counters prove unreached -- see |
| 1718 | - // any per-feature gap the witnesses' counters prove unreached -- see the | 1689 | + // the 12-bit refusals in decode.rs and `refusal_inventory.rs`. |
| 1719 | - // 12-bit refusals in decode.rs and `refusal_inventory.rs`. | 1690 | + // lane-av112bitg: film grain joined the witnessed set (`grain_refusal` |
| 1691 | + // deleted; the two-arm witness is | ||
| 1692 | + // `a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact`). | ||
| 1720 | // lane-av1txr: `color_config.subsampling_x/y` (spec 5.5.2) are parsed by | 1693 | // lane-av1txr: `color_config.subsampling_x/y` (spec 5.5.2) are parsed by |
| 1721 | // `ec-av1-syntax` -- profile 1 forces 4:4:4, profile 2 below 12-bit forces | 1694 | // `ec-av1-syntax` -- profile 1 forces 4:4:4, profile 2 below 12-bit forces |
| 1722 | // 4:2:2, and the sRGB identity description forces full-range 4:4:4 -- but | 1695 | // 4:2:2, and the sRGB identity description forces full-range 4:4:4 -- but |
| @@ -8400,9 +8373,12 @@ pub(crate) mod tests { | |||
| 8400 | // restoration (Wiener AND SGR), and translational subpel motion | 8373 | // restoration (Wiener AND SGR), and translational subpel motion |
| 8401 | // compensation through the bit-depth-parameterised `round_0`/`round_1` | 8374 | // compensation through the bit-depth-parameterised `round_0`/`round_1` |
| 8402 | // (libaom `convolve.h:81..86`). Everything else stays refused by name: | 8375 | // (libaom `convolve.h:81..86`). Everything else stays refused by name: |
| 8403 | - // warp, film grain, screen content tools (palette/intrabc) at the frame | 8376 | + // warp and screen content tools (palette/intrabc) at the frame level, |
| 8404 | - // level, compound inter blocks at the mode read, each with its own | 8377 | + // each with its own real-stream refusal gate below. |
| 8405 | - // real-stream refusal gate below. | 8378 | + // lane-av112bitc: compound joined the witnessed set (refusal gate became |
| 8379 | + // the six-frame compound witness). | ||
| 8380 | + // lane-av112bitg: film grain joined the witnessed set (refusal gate became | ||
| 8381 | + // `a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact`). | ||
| 8406 | // ------------------------------------------------------------------- | 8382 | // ------------------------------------------------------------------- |
| 8407 | 8383 | ||
| 8408 | /// The 12-bit witness source, byte-identical to the lane's committed | 8384 | /// The 12-bit witness source, byte-identical to the lane's committed |
| @@ -8729,25 +8705,95 @@ pub(crate) mod tests { | |||
| 8729 | } | 8705 | } |
| 8730 | } | 8706 | } |
| 8731 | 8707 | ||
| 8732 | - /// The 12-bit film grain refusal: a real `--film-grain-test=1` stream | 8708 | + /// lane-av112bitg: the 12-bit film grain witness. A real |
| 8733 | - /// (grain params present AND applied) is refused by name at output. | 8709 | + /// `aomenc --bit-depth=12 --profile=2 --film-grain-test=5` stream -- grain |
| 8710 | + /// params present AND applied (2 luma + 9 cb + 9 cr scaling points, | ||
| 8711 | + /// overlap blending on, clip-to-restricted-range on; the second frame is | ||
| 8712 | + /// an INTER frame that inherits the params via `update_grain = 0`) -- | ||
| 8713 | + /// decoded byte-exact against ffmpeg's own 12-bit decode of the identical | ||
| 8714 | + /// bytes (ffmpeg synthesizes grain by default; no grain-disable flag is | ||
| 8715 | + /// passed anywhere in this file). Proves the bit-depth-generic grain path | ||
| 8716 | + /// at 12 bits: `grain_range`'s ±(128 << 4) AR clamp and overlap-blend | ||
| 8717 | + /// clamp, the `gauss_sec_shift = 12 - bd` Gaussian shift, the 4096-entry | ||
| 8718 | + /// expanded scaling-LUT interpolation, and the `<< (bit_depth - 8)` | ||
| 8719 | + /// chroma offsets and legal-range clamps. HARD-asserts the parsed headers | ||
| 8720 | + /// really carry that coverage and `film_grain::grain_hits()` fired, so | ||
| 8721 | + /// neither a params-without-apply stream nor a silently-skipped synthesis | ||
| 8722 | + /// can pass vacuously. | ||
| 8734 | #[test] | 8723 | #[test] |
| 8735 | - fn a_12bit_film_grain_stream_is_refused_by_name() { | 8724 | + fn a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact() { |
| 8736 | - const NAME: &str = "a_12bit_film_grain_stream_is_refused_by_name"; | 8725 | + const NAME: &str = "a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact"; |
| 8737 | let _gate_lock = lock_gate_counters(); | 8726 | let _gate_lock = lock_gate_counters(); |
| 8727 | + if !have_ffmpeg() { | ||
| 8728 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 8729 | + return; | ||
| 8730 | + } | ||
| 8738 | if !have_aomenc() { | 8731 | if !have_aomenc() { |
| 8739 | eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | 8732 | eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); |
| 8740 | return; | 8733 | return; |
| 8741 | } | 8734 | } |
| 8742 | - let y4m = y4m_12bit_subpel_source(1); | 8735 | + let y4m = y4m_12bit_subpel_source(2); |
| 8743 | - let stream = encode_12bit(&y4m, 1, &["--film-grain-test=1"]); | 8736 | + // Warp stays refused at 12 bits (lane-av112bitg lifts GRAIN only), so |
| 8744 | - let err = decode_stream(&stream).unwrap_err().to_string(); | 8737 | + // the arm pins both motion tools off exactly once each -- aomenc |
| 8738 | + // otherwise picks warped motion on this fixture's sub-pel motion. | ||
| 8739 | + let stream = encode_12bit( | ||
| 8740 | + &y4m, | ||
| 8741 | + 2, | ||
| 8742 | + &[ | ||
| 8743 | + "--film-grain-test=5", | ||
| 8744 | + "--enable-warped-motion=0", | ||
| 8745 | + "--enable-global-motion=0", | ||
| 8746 | + ], | ||
| 8747 | + ); | ||
| 8748 | + assert_12bit_sequence_header(&stream, NAME); | ||
| 8749 | + // The arm is only honest if the stream itself carries the coverage: | ||
| 8750 | + // grain applied on every frame, scaling points on all three planes, | ||
| 8751 | + // overlap blending and restricted-range clipping on. | ||
| 8752 | + let mut probe = Av1Parser::new(); | ||
| 8753 | + let mut pos = 0usize; | ||
| 8754 | + let mut grain_frames = 0usize; | ||
| 8755 | + while pos < stream.len() { | ||
| 8756 | + let obu = probe.parse_obu(&stream[pos..]).unwrap(); | ||
| 8757 | + pos += obu.total_size; | ||
| 8758 | + if let ObuKind::Frame(header, _) = obu.kind { | ||
| 8759 | + let fg = &header.film_grain; | ||
| 8760 | + assert!( | ||
| 8761 | + fg.apply_grain, | ||
| 8762 | + "{NAME}: frame without apply_grain -- aomenc emitted params it does not apply" | ||
| 8763 | + ); | ||
| 8764 | + assert!( | ||
| 8765 | + fg.num_y_points > 0 && fg.num_cb_points > 0 && fg.num_cr_points > 0, | ||
| 8766 | + "{NAME}: grain without all three planes' scaling points -- the bit-depth \ | ||
| 8767 | + LUT math would not be exercised" | ||
| 8768 | + ); | ||
| 8769 | + assert!( | ||
| 8770 | + fg.overlap_flag, | ||
| 8771 | + "{NAME}: overlap off -- the grain_min/grain_max blend clamp is not exercised" | ||
| 8772 | + ); | ||
| 8773 | + assert!( | ||
| 8774 | + fg.clip_to_restricted_range, | ||
| 8775 | + "{NAME}: clip_to_restricted_range off -- the << (bd - 8) legal-range clamps \ | ||
| 8776 | + are not exercised" | ||
| 8777 | + ); | ||
| 8778 | + grain_frames += 1; | ||
| 8779 | + } | ||
| 8780 | + } | ||
| 8781 | + assert_eq!(grain_frames, 2, "{NAME}: expected grain on both frames"); | ||
| 8782 | + let before = crate::film_grain::grain_hits(); | ||
| 8783 | + let frames = decode_stream(&stream) | ||
| 8784 | + .unwrap_or_else(|e| panic!("{NAME}: decode_stream refused a real 12-bit grain stream: {e}")); | ||
| 8785 | + assert_eq!(frames.len(), 2); | ||
| 8745 | assert!( | 8786 | assert!( |
| 8746 | - err.contains( | 8787 | + crate::film_grain::grain_hits() > before, |
| 8747 | - "film grain synthesis at 12 bits (no byte-exact 12-bit grain witness exists: the 12-bit gates encode with grain off)" | 8788 | + "{NAME}: matched but zero grain_hits -- grain synthesis never ran" |
| 8748 | - ), | ||
| 8749 | - "{NAME}: expected the 12-bit grain refusal, got: {err}" | ||
| 8750 | ); | 8789 | ); |
| 8790 | + let ffmpeg_frames = ffmpeg_decode_sequence_12bit(&stream, 160, 128, 2); | ||
| 8791 | + for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 8792 | + assert_eq!(ours.y, theirs.y, "{NAME}: luma vs ffmpeg (12-bit grain, frame {i})"); | ||
| 8793 | + assert_eq!(ours.u, theirs.u, "{NAME}: U vs ffmpeg (12-bit grain, frame {i})"); | ||
| 8794 | + assert_eq!(ours.v, theirs.v, "{NAME}: V vs ffmpeg (12-bit grain, frame {i})"); | ||
| 8795 | + } | ||
| 8796 | + eprintln!("{NAME}: byte-exact, grain_hits={}", crate::film_grain::grain_hits()); | ||
| 8751 | } | 8797 | } |
| 8752 | 8798 | ||
| 8753 | /// The 12-bit screen-content refusal: a real `--tune-content=screen | 8799 | /// The 12-bit screen-content refusal: a real `--tune-content=screen |
lanes/av112bitg.report.mdadded+90 -0
| @@ -0,0 +1,90 @@ | |||
| 1 | +# lane-av112bitg — 12-bit film grain joins the witnessed set | ||
| 2 | + | ||
| 3 | +Base 786c15b6 (lane-av112bitc), worktree `edith_codecs-av112bg`. The charter: | ||
| 4 | +lift the `film grain synthesis at 12 bits` refusal exactly as far as a real | ||
| 5 | +`aomenc --bit-depth=12` grain stream proves byte-exactness against ffmpeg, and | ||
| 6 | +leave warp and screen content refused. Sibling lane av112bitw owns warp; | ||
| 7 | +`film_grain.rs` needed no arithmetic change, so the two lanes share no code | ||
| 8 | +except the refusal inventory rows (grain rows only here). | ||
| 9 | + | ||
| 10 | +## Emission (charter gate 1: passed on try 1) | ||
| 11 | + | ||
| 12 | +`--film-grain-test=N` maps to libaom's `film_grain_test_vectors[N-1]` | ||
| 13 | +(`av1/encoder/grain_test_vectors.h`); `av1_update_film_grain_parameters` | ||
| 14 | +overwrites the vector's static `bit_depth: 8` with the sequence's | ||
| 15 | +(`encoder_utils.c:792`), and `av1_update_film_grain_parameters_seq` turns on | ||
| 16 | +`film_grain_params_present`. Probed all of vectors 1..8 on the lane's 12-bit | ||
| 17 | +sub-pel fixture: every one emits `apply_grain=1` on BOTH the key and the inter | ||
| 18 | +frame header (vectors 1..8, 2-frame streams, all parsed and printed by a | ||
| 19 | +scratch gate before the lift). No try failed, so the "8 tries" stop condition | ||
| 20 | +never came close. | ||
| 21 | + | ||
| 22 | +## The bit-depth audit (no assumptions) | ||
| 23 | + | ||
| 24 | +Every bit-depth-sensitive site of `film_grain.rs` re-diffed against the oracle | ||
| 25 | +`~/.cache/aom-oracle/src/av1/decoder/grain_synthesis.c` (v3.13.3 @ 92d4c37): | ||
| 26 | + | ||
| 27 | +| site | oracle | ours | | ||
| 28 | +|---|---|---| | ||
| 29 | +| `grain_min/max = ±(128 << (bd-8))` AR + blend clamp | `:1043-1045` | `grain_range` | | ||
| 30 | +| `gauss_sec_shift = 12 - bd + grain_scale_shift` | `:468`, `:503` | both `generate_*_grain_block`s | | ||
| 31 | +| `scale_LUT` shift-4 interpolation, `x == 255` short-circuit | `:616-626` | `scale_lut` | | ||
| 32 | +| expanded LUT (4096 entries at 12-bit) | per-call `scale_LUT` | `expand_scaling_lut` (same function tabulated) | | ||
| 33 | +| chroma index combine `((avg*luma_mult + mult*chroma) >> 6) + offset`, clamp `0..(256 << (bd-8)) - 1` | `:815-819`, `:830-834` | `chroma_noise_row_scalar` + ChromaNoise | | ||
| 34 | +| `cb/cr_offset = (x << (bd-8)) - (1 << bd)` | `:752`, `:757` | `add_noise_to_block` | | ||
| 35 | +| legal-range clamps `16/235/240 << (bd-8)`, `mc_identity` chroma quirk | `:781-795` | `add_noise_to_block` | | ||
| 36 | +| 4:2:0 chroma luma average `(l0 + l1 + 1) >> 1` (horizontal PAIR, not a quad) | `:801-806` | `chroma_noise_row_scalar` | | ||
| 37 | +| ver/hor overlap blends clamped to `grain_min/grain_max` | `:912-970` | `ver_overlap_inplace`/`hor_overlap_inplace` | | ||
| 38 | + | ||
| 39 | +The AVX2 kernels are parameter-shaped (`index_max`, min/max, LUT length all | ||
| 40 | +inputs; the `vpmaddwd` luma pair sum stays exact at 12-bit since | ||
| 41 | +`2 * 4095 < 2^15`) and this machine's decode path runs them (chroma blocks are | ||
| 42 | +15 wide -> 8+4+3 tails; luma 30 wide -> 8+8+8+4+2), so the witness exercised | ||
| 43 | +SIMD and scalar alike. `apply_grain` call sites already thread the parsed | ||
| 44 | +sequence `bit_depth` (the `map_or(8, ...)` site included). | ||
| 45 | + | ||
| 46 | +## The witness | ||
| 47 | + | ||
| 48 | +`stream.rs`: `grain_refusal` and its four call sites deleted; the refusal gate | ||
| 49 | +became `a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact`: | ||
| 50 | + | ||
| 51 | +- `aomenc --profile=2 --bit-depth=12 --film-grain-test=5 | ||
| 52 | + --enable-warped-motion=0 --enable-global-motion=0`, 2 frames over the lane's | ||
| 53 | + 160x128 C420p12 sub-pel fixture. Vector 5 carries 2 luma + 9 cb + 9 cr | ||
| 54 | + scaling points, `overlap_flag=1`, `clip_to_restricted_range=1`; the inter | ||
| 55 | + frame codes `update_grain=0` (params inherited from the ref slot, new seed | ||
| 56 | + only), so the gate also exercises the spec 5.9.30 persistence path and grain | ||
| 57 | + on a non-key output. | ||
| 58 | +- Warp is pinned OFF by name: the unpinned first run tripped the (sibling's, | ||
| 59 | + intact) `warped motion at 12 bits` refusal — this lane lifts GRAIN only, so | ||
| 60 | + the arm stays inside the witnessed set. Each flag spelled exactly once | ||
| 61 | + (aomenc LAST-occurrence precedence). | ||
| 62 | +- Non-vacuity: parsed-header asserts demand `apply_grain`, all three planes' | ||
| 63 | + scaling points, overlap and restricted-range clipping on BOTH frames; | ||
| 64 | + `film_grain::grain_hits()` must advance; ffmpeg decodes with grain ON by | ||
| 65 | + default and must produce exactly 2 yuv420p12le frames. | ||
| 66 | +- Result: **byte-exact on every plane of both frames** (grain_hits=2). ffmpeg | ||
| 67 | + synthesized the identical grain from the identical reconstruction. | ||
| 68 | + | ||
| 69 | +## Inventory | ||
| 70 | + | ||
| 71 | +`refusal_inventory.rs`: grain REFUSALS string and PROVEN row deleted (37 -> 36 | ||
| 72 | +refusals), lane-av112bitg notes added next to the lane-av112bitc ones. | ||
| 73 | +`the_decode_path_refuses_exactly_the_listed_cases` and | ||
| 74 | +`every_proven_refusal_names_a_test_that_exists` both green. | ||
| 75 | + | ||
| 76 | +## Regression (all green, same run) | ||
| 77 | + | ||
| 78 | +- `a_real_aomenc_12bit_stream_decodes_pixel_exact` — parent 12-bit KEY fixture, grain off, byte-exact. | ||
| 79 | +- `a_real_aomenc_12bit_inter_sequence_decodes_pixel_exact`, | ||
| 80 | + `a_real_aomenc_12bit_compound_inter_sequence_decodes_pixel_exact` — 12-bit inter/compound witnesses. | ||
| 81 | +- `a_real_aomenc_10bit_film_grain_stream_decodes_pixel_exact` + the other four `10bit_film` gates. | ||
| 82 | +- `a_12bit_warped_motion_stream_is_refused_by_name`, | ||
| 83 | + `a_12bit_screen_content_stream_is_refused_by_name` — sibling refusals intact. | ||
| 84 | +- Full `refusal_inventory` module. 26/26 tests, 0 warnings on | ||
| 85 | + `cargo check --all-targets -p ec-av1`. | ||
| 86 | + | ||
| 87 | +## Open | ||
| 88 | + | ||
| 89 | +None for grain. Warp (`a_12bit_warped_motion_stream_is_refused_by_name`, | ||
| 90 | +sibling lane av112bitw) and screen content tools stay refused by name. | ||