diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index ff4f685e..6881c96b 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -15686,6 +15686,40 @@ mod tests { /// side, so the stream stays legal; here the pricer's own offer set is /// enumerated, class `enumerate-table-domain`). /// + /// **This is the coverage claim for the drl-clamp cell** (lane-av1recipehunt + /// r2, 2026-09-29). It replaces the clip gate + /// `a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact`, + /// deleted in `3e8c65e6`+r2: that gate asserted `drl_clamp_hits() > 0` on a + /// real 1280x768 sb128 clip, but `DRL_CLAMP_HITS` is provably unreachable + /// while the invariant above holds, so no recipe could ever satisfy it. + /// Deletion loses no coverage on either half: + /// * the clamp half -- this test IS the coverage, and it is strictly + /// stronger than any clip gate: it enumerates the pricer's whole offer + /// set against the writer's rule for every stack size 0..=4, and larger + /// stacks add entries the pricers never offer (`best_new_mv_syntax` + /// breaks at `entries.len() <= idx` for `idx > 0`, so indices 3/4 are + /// unreachable at ANY stack size), which is why 0..=4 bounds the + /// domain rather than sampling it; + /// * the pixel half -- the deleted gate's own decode-vs-encoder- + /// reconstruction compare on a 1280x768 sb128 sequence is already made + /// four times over, by `a_128_superblock_clip_whose_root_search_codes_ + /// 128x128_blocks_decodes_exact`, + /// `a_128_root_block_with_a_real_residual_decodes_exact_through_both_decoders`, + /// `a_128_root_residual_block_under_a_per_unit_cdef_list_decodes_exact` + /// and `a_rect128_half_with_a_real_residual_decodes_exact_through_both_decoders` + /// (same geometry, same `force_sb128(true)`, same own-reconstruction AND + /// ffmpeg compare). + /// MEASURED before deleting (153 clip x size x frame-count x q combinations, + /// `enc_probe`): `tile::drl_clamp_hits()` = 0 on every one. MUTATION PROOF + /// the clip was never the variable: widening `best_new_mv_syntax`'s offer + /// set to `0..5` fires the counter immediately (9/2/2/1 on + /// mandelbrot 640x384x8, mandelbrot 320x192x8, mosaic 320x192x8, + /// testsrc2 640x384x8) and the same clips read 0 on revert. `note_drl_clamp` + /// and `DRL_CLAMP_HITS` are KEPT as the tripwire for the owning fix + /// (`deferred(unblock: the DRL owner widens the pricer past the writer's + /// `start + 2` ceiling, or retires the counter)`) -- this test will go red + /// the moment either happens, which is the signal to re-open the cell. + /// /// cargo test -p ec-av1 --lib -- every_drl_index_the_new_mv_pricer #[test] fn every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal() { @@ -19446,125 +19480,6 @@ mod tests { ); } - /// lane-av1recipehunt (2026-09-29): this gate is NOT closeable by any - /// recipe, and the reason is structural, so do not spend another sweep on - /// it. `DRL_CLAMP_HITS` is bumped by `tile::write_inter_mode` (and the two - /// compound walks) only when the search chose a `ref_mv_idx` the write-time - /// stack could not signal -- and on this tree the search's offer set is - /// provably INSIDE the signalable range in every mode: - /// * `NEWMV`: `best_new_mv_syntax` enumerates `for idx in 0..3` (0, 1, 2), - /// and `tile::write_drl_idx`'s ceiling from `start = 0` is - /// `start + 2` = 2. The search's ceiling IS the writer's ceiling. - /// * `NEARMV`: the search's own candidate loop is `for idx in 1..=2` and - /// the writer's ceiling from `start = 1` is 3, but the walk also stops - /// at `entries.len() > idx + 1` and the search only offers an index the - /// stack really holds (`entries.get(idx).is_some()`), so the two - /// bounds coincide. - /// * the compound arms: every compound `InterInfo` the search builds - /// hardcodes `ref_mv_idx: 0`, which is inside the walk's range. - /// This is not an inference -- the tree already ASSERTS it, over stack - /// sizes 0..=4, in - /// [`tests::every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal`] - /// (`signalled_drl_idx(entries, start, idx) == idx` for every index either - /// pricer offers). That test and this gate are two readings of one - /// invariant; the counter this gate waits on can never leave zero. - /// - /// MEASURED (lane-av1recipehunt), 153 clip x size x frame-count x q - /// combinations through `enc_probe` (mandelbrot / testsrc2 / white noise / - /// scrolling bands / a 4x4 mosaic / 4-px luminance bands / a panning field - /// with a faster band / diagonal bands / alternating hard tiles / three - /// independently moving bands; 320x192, 640x384, 1280x768; 8..16 frames; - /// q 60..220): `tile::drl_clamp_hits()` = 0 on EVERY one. A trace on - /// `best_new_mv_syntax` shows the search DOES pick `idx = 2` often (163 - /// times on mandelbrot 640x384x8) -- index 2 is exactly what the writer - /// signals, so it is a legal pick, not a clamp. - /// - /// MUTATION PROOF that the recipe was never the problem: widening the - /// pricer's offer set (`for idx in 0..3` -> `0..5`, i.e. letting the - /// search ask for index 3/4 that the 2-step walk cannot signal) makes the - /// counter fire on the very first clips tried -- mandelbrot 640x384x8 - /// = 9, mandelbrot 320x192x8 = 2, mosaic 320x192x8 = 2, testsrc2 640x384x8 - /// = 1 -- and the same clips read 0 again the moment the mutation is - /// reverted. The binding constraint is the pricer's offer ceiling, which - /// no clip can move. - /// - /// OWNING FIX (not this lane's to make -- the DRL code is another lane's - /// surface, and the DRL index range is the spec's, not ours): either widen - /// the search's offer set to the spec's own DRL range so the clamp becomes - /// reachable and this gate can witness it, or delete the three dead - /// `note_drl_clamp` sites and this gate with them. Until one of those - /// lands, `#[ignore]` is the honest state and the ignore string below - /// stands. - #[test] - #[ignore = "sets the process-global superblock size: run it alone"] - fn a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact() { - let _knobs = crate::speed::knob_write(); - if !have_ffmpeg() { - eprintln!("SKIP: no ffmpeg"); - return; - } - force_sb128(true); - let dir = std::env::temp_dir().join(format!("ec-av1-sb128b-{}", std::process::id())); - std::fs::create_dir_all(&dir).unwrap(); - let clip = dir.join("mandelbrot-1280x768.y4m"); - let ok = Command::new("ffmpeg") - .args([ - "-v", - "error", - "-y", - "-f", - "lavfi", - "-i", - "mandelbrot=size=1280x768:rate=24", - ]) - .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) - .arg(&clip) - .status() - .expect("ffmpeg failed to run") - .success(); - assert!(ok, "ffmpeg could not write the synthetic clip"); - let path = clip.to_str().unwrap(); - let (width, height) = (1280usize, 768usize); - let pictures = crate::probe::source(path, "0", "null", width, height, 12); - - let _ = crate::tile::take_drl_clamp_hits(); - let encoded = encode_sequence(&pictures, 150, 0.5).unwrap(); - let clamps = crate::tile::take_drl_clamp_hits(); - assert!( - clamps > 0, - "this clip never asked for a drl index the write-time stack could not carry, \ - so it cannot witness the defect" - ); - eprintln!("clamped drl indices: {clamps}"); - - let decoded = crate::stream::decode_stream(&encoded.stream).expect("our decoder"); - assert_eq!(decoded.len(), encoded.frames.len(), "frame count"); - for (i, (frame, dec)) in encoded.frames.iter().zip(&decoded).enumerate() { - let recon = &frame.reconstruction; - for (plane, got, want) in [ - ("luma", &dec.y, &recon.y), - ("U", &dec.u, &recon.u), - ("V", &dec.v, &recon.v), - ] { - let differ = got.iter().zip(want).filter(|(a, b)| a != b).count(); - assert_eq!( - differ, - 0, - "frame {i}: {plane} -- {differ} of {} samples differ from the encoder's \ - own reconstruction", - got.len() - ); - assert_eq!( - got.len(), - want.len(), - "frame {i}: {plane} is {} samples, the reconstruction's is {}", - got.len(), - want.len() - ); - } - } - } - #[test] fn every_frame_of_a_sequence_decodes_through_our_own_decoder() { let _knobs = crate::speed::knob_read(); diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index d4cd5f1f..dd3e942d 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -7195,15 +7195,13 @@ fn note_drl_clamp(target: usize, signalled: usize, entries: usize) { } } -/// Takes and clears [`DRL_CLAMP_HITS`], for a gate's own before/after delta. -#[cfg(test)] -pub(crate) fn take_drl_clamp_hits() -> usize { - DRL_CLAMP_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) -} - -/// Reads [`DRL_CLAMP_HITS`] WITHOUT clearing it -- the before/after delta is -/// `take_drl_clamp_hits`, but a recipe sweep that arms one encode and reads the -/// total (lane-av1recipehunt's `enc_probe` driver) wants a non-destructive read. +/// Reads [`DRL_CLAMP_HITS`] -- the tripwire for the DRL owner's fix. It is +/// provably zero while `every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal` +/// (encode.rs) holds: the pricer never offers an index this walk cannot signal, +/// so no clip can move it (lane-av1recipehunt, 153 attempts, plus a mutation +/// proof that widening the pricer's offer set does). The clip gate that used +/// to wait on it is deleted; this counter stays so that widening the pricer +/// is loud instead of silent. `EC_AV1_TRACE=1` prints each hit. pub fn drl_clamp_hits() -> usize { DRL_CLAMP_HITS.load(std::sync::atomic::Ordering::Relaxed) }