forge
Explore
Log in

Don't you dare go Hollow

gate 1: delete the unreachable drl-clamp clip gate; the invariant test is the coverage claim

Browse files at this commit

a7e1d4c2a137ca49bdbbcbd82bed574d0477ef4bAhmet Kaan GümüşParent: 4359ea0
The gate asserted drl_clamp_hits() > 0 on a real 1280x768 sb128 clip, but
DRL_CLAMP_HITS is provably unreachable while
every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal holds, so
no recipe could ever satisfy it (153 attempts, 0; widening the pricer's offer
set to 0..5 fires the counter immediately and reverting silences it again).

Deletion loses no coverage on either half. The clamp half is this invariant
test, and it is strictly stronger than a clip gate: it enumerates the pricer's
whole offer set against the writer's rule, and 0..=4 bounds the DOMAIN rather
than sampling it (best_new_mv_syntax breaks at entries.len() <= idx for
idx > 0, so indices 3/4 are unreachable at any stack size). The pixel half --
the deleted gate's decode-vs-encoder-reconstruction compare on a 1280x768 sb128
sequence -- is already made four times over by the sibling sb128 gates at the
same geometry with the same force_sb128(true).

The coverage claim now lives on that invariant test's doc comment, which names
the deleted gate and both substitutes. note_drl_clamp and DRL_CLAMP_HITS are
KEPT as the tripwire for the owning fix, and the now-unused
take_drl_clamp_hits is dropped in favour of the non-destructive
tile::drl_clamp_hits() the enc_probe hunt reads.
crates/ec-av1/src/encode.rsmodified+34 -119
@@ -15686,6 +15686,40 @@ mod tests {
1568615686 /// side, so the stream stays legal; here the pricer's own offer set is
1568715687 /// enumerated, class `enumerate-table-domain`).
1568815688 ///
15689+ /// **This is the coverage claim for the drl-clamp cell** (lane-av1recipehunt
15690+ /// r2, 2026-09-29). It replaces the clip gate
15691+ /// `a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact`,
15692+ /// deleted in `3e8c65e6`+r2: that gate asserted `drl_clamp_hits() > 0` on a
15693+ /// real 1280x768 sb128 clip, but `DRL_CLAMP_HITS` is provably unreachable
15694+ /// while the invariant above holds, so no recipe could ever satisfy it.
15695+ /// Deletion loses no coverage on either half:
15696+ /// * the clamp half -- this test IS the coverage, and it is strictly
15697+ /// stronger than any clip gate: it enumerates the pricer's whole offer
15698+ /// set against the writer's rule for every stack size 0..=4, and larger
15699+ /// stacks add entries the pricers never offer (`best_new_mv_syntax`
15700+ /// breaks at `entries.len() <= idx` for `idx > 0`, so indices 3/4 are
15701+ /// unreachable at ANY stack size), which is why 0..=4 bounds the
15702+ /// domain rather than sampling it;
15703+ /// * the pixel half -- the deleted gate's own decode-vs-encoder-
15704+ /// reconstruction compare on a 1280x768 sb128 sequence is already made
15705+ /// four times over, by `a_128_superblock_clip_whose_root_search_codes_
15706+ /// 128x128_blocks_decodes_exact`,
15707+ /// `a_128_root_block_with_a_real_residual_decodes_exact_through_both_decoders`,
15708+ /// `a_128_root_residual_block_under_a_per_unit_cdef_list_decodes_exact`
15709+ /// and `a_rect128_half_with_a_real_residual_decodes_exact_through_both_decoders`
15710+ /// (same geometry, same `force_sb128(true)`, same own-reconstruction AND
15711+ /// ffmpeg compare).
15712+ /// MEASURED before deleting (153 clip x size x frame-count x q combinations,
15713+ /// `enc_probe`): `tile::drl_clamp_hits()` = 0 on every one. MUTATION PROOF
15714+ /// the clip was never the variable: widening `best_new_mv_syntax`'s offer
15715+ /// set to `0..5` fires the counter immediately (9/2/2/1 on
15716+ /// mandelbrot 640x384x8, mandelbrot 320x192x8, mosaic 320x192x8,
15717+ /// testsrc2 640x384x8) and the same clips read 0 on revert. `note_drl_clamp`
15718+ /// and `DRL_CLAMP_HITS` are KEPT as the tripwire for the owning fix
15719+ /// (`deferred(unblock: the DRL owner widens the pricer past the writer's
15720+ /// `start + 2` ceiling, or retires the counter)`) -- this test will go red
15721+ /// the moment either happens, which is the signal to re-open the cell.
15722+ ///
1568915723 /// cargo test -p ec-av1 --lib -- every_drl_index_the_new_mv_pricer
1569015724 #[test]
1569115725 fn every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal() {
@@ -19446,125 +19480,6 @@ mod tests {
1944619480 );
1944719481 }
1944819482
19449- /// lane-av1recipehunt (2026-09-29): this gate is NOT closeable by any
19450- /// recipe, and the reason is structural, so do not spend another sweep on
19451- /// it. `DRL_CLAMP_HITS` is bumped by `tile::write_inter_mode` (and the two
19452- /// compound walks) only when the search chose a `ref_mv_idx` the write-time
19453- /// stack could not signal -- and on this tree the search's offer set is
19454- /// provably INSIDE the signalable range in every mode:
19455- /// * `NEWMV`: `best_new_mv_syntax` enumerates `for idx in 0..3` (0, 1, 2),
19456- /// and `tile::write_drl_idx`'s ceiling from `start = 0` is
19457- /// `start + 2` = 2. The search's ceiling IS the writer's ceiling.
19458- /// * `NEARMV`: the search's own candidate loop is `for idx in 1..=2` and
19459- /// the writer's ceiling from `start = 1` is 3, but the walk also stops
19460- /// at `entries.len() > idx + 1` and the search only offers an index the
19461- /// stack really holds (`entries.get(idx).is_some()`), so the two
19462- /// bounds coincide.
19463- /// * the compound arms: every compound `InterInfo` the search builds
19464- /// hardcodes `ref_mv_idx: 0`, which is inside the walk's range.
19465- /// This is not an inference -- the tree already ASSERTS it, over stack
19466- /// sizes 0..=4, in
19467- /// [`tests::every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal`]
19468- /// (`signalled_drl_idx(entries, start, idx) == idx` for every index either
19469- /// pricer offers). That test and this gate are two readings of one
19470- /// invariant; the counter this gate waits on can never leave zero.
19471- ///
19472- /// MEASURED (lane-av1recipehunt), 153 clip x size x frame-count x q
19473- /// combinations through `enc_probe` (mandelbrot / testsrc2 / white noise /
19474- /// scrolling bands / a 4x4 mosaic / 4-px luminance bands / a panning field
19475- /// with a faster band / diagonal bands / alternating hard tiles / three
19476- /// independently moving bands; 320x192, 640x384, 1280x768; 8..16 frames;
19477- /// q 60..220): `tile::drl_clamp_hits()` = 0 on EVERY one. A trace on
19478- /// `best_new_mv_syntax` shows the search DOES pick `idx = 2` often (163
19479- /// times on mandelbrot 640x384x8) -- index 2 is exactly what the writer
19480- /// signals, so it is a legal pick, not a clamp.
19481- ///
19482- /// MUTATION PROOF that the recipe was never the problem: widening the
19483- /// pricer's offer set (`for idx in 0..3` -> `0..5`, i.e. letting the
19484- /// search ask for index 3/4 that the 2-step walk cannot signal) makes the
19485- /// counter fire on the very first clips tried -- mandelbrot 640x384x8
19486- /// = 9, mandelbrot 320x192x8 = 2, mosaic 320x192x8 = 2, testsrc2 640x384x8
19487- /// = 1 -- and the same clips read 0 again the moment the mutation is
19488- /// reverted. The binding constraint is the pricer's offer ceiling, which
19489- /// no clip can move.
19490- ///
19491- /// OWNING FIX (not this lane's to make -- the DRL code is another lane's
19492- /// surface, and the DRL index range is the spec's, not ours): either widen
19493- /// the search's offer set to the spec's own DRL range so the clamp becomes
19494- /// reachable and this gate can witness it, or delete the three dead
19495- /// `note_drl_clamp` sites and this gate with them. Until one of those
19496- /// lands, `#[ignore]` is the honest state and the ignore string below
19497- /// stands.
19498- #[test]
19499- #[ignore = "sets the process-global superblock size: run it alone"]
19500- fn a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact() {
19501- let _knobs = crate::speed::knob_write();
19502- if !have_ffmpeg() {
19503- eprintln!("SKIP: no ffmpeg");
19504- return;
19505- }
19506- force_sb128(true);
19507- let dir = std::env::temp_dir().join(format!("ec-av1-sb128b-{}", std::process::id()));
19508- std::fs::create_dir_all(&dir).unwrap();
19509- let clip = dir.join("mandelbrot-1280x768.y4m");
19510- let ok = Command::new("ffmpeg")
19511- .args([
19512- "-v",
19513- "error",
19514- "-y",
19515- "-f",
19516- "lavfi",
19517- "-i",
19518- "mandelbrot=size=1280x768:rate=24",
19519- ])
19520- .args(["-frames:v", "12", "-pix_fmt", "yuv420p"])
19521- .arg(&clip)
19522- .status()
19523- .expect("ffmpeg failed to run")
19524- .success();
19525- assert!(ok, "ffmpeg could not write the synthetic clip");
19526- let path = clip.to_str().unwrap();
19527- let (width, height) = (1280usize, 768usize);
19528- let pictures = crate::probe::source(path, "0", "null", width, height, 12);
19529-
19530- let _ = crate::tile::take_drl_clamp_hits();
19531- let encoded = encode_sequence(&pictures, 150, 0.5).unwrap();
19532- let clamps = crate::tile::take_drl_clamp_hits();
19533- assert!(
19534- clamps > 0,
19535- "this clip never asked for a drl index the write-time stack could not carry, \
19536- so it cannot witness the defect"
19537- );
19538- eprintln!("clamped drl indices: {clamps}");
19539-
19540- let decoded = crate::stream::decode_stream(&encoded.stream).expect("our decoder");
19541- assert_eq!(decoded.len(), encoded.frames.len(), "frame count");
19542- for (i, (frame, dec)) in encoded.frames.iter().zip(&decoded).enumerate() {
19543- let recon = &frame.reconstruction;
19544- for (plane, got, want) in [
19545- ("luma", &dec.y, &recon.y),
19546- ("U", &dec.u, &recon.u),
19547- ("V", &dec.v, &recon.v),
19548- ] {
19549- let differ = got.iter().zip(want).filter(|(a, b)| a != b).count();
19550- assert_eq!(
19551- differ,
19552- 0,
19553- "frame {i}: {plane} -- {differ} of {} samples differ from the encoder's \
19554- own reconstruction",
19555- got.len()
19556- );
19557- assert_eq!(
19558- got.len(),
19559- want.len(),
19560- "frame {i}: {plane} is {} samples, the reconstruction's is {}",
19561- got.len(),
19562- want.len()
19563- );
19564- }
19565- }
19566- }
19567-
1956819483 #[test]
1956919484 fn every_frame_of_a_sequence_decodes_through_our_own_decoder() {
1957019485 let _knobs = crate::speed::knob_read();
crates/ec-av1/src/tile.rsmodified+7 -9
@@ -7195,15 +7195,13 @@ fn note_drl_clamp(target: usize, signalled: usize, entries: usize) {
71957195 }
71967196 }
71977197
7198-/// Takes and clears [`DRL_CLAMP_HITS`], for a gate's own before/after delta.
7199-#[cfg(test)]
7200-pub(crate) fn take_drl_clamp_hits() -> usize {
7201- DRL_CLAMP_HITS.swap(0, std::sync::atomic::Ordering::Relaxed)
7202-}
7203-
7204-/// Reads [`DRL_CLAMP_HITS`] WITHOUT clearing it -- the before/after delta is
7205-/// `take_drl_clamp_hits`, but a recipe sweep that arms one encode and reads the
7206-/// total (lane-av1recipehunt's `enc_probe` driver) wants a non-destructive read.
7198+/// Reads [`DRL_CLAMP_HITS`] -- the tripwire for the DRL owner's fix. It is
7199+/// provably zero while `every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal`
7200+/// (encode.rs) holds: the pricer never offers an index this walk cannot signal,
7201+/// so no clip can move it (lane-av1recipehunt, 153 attempts, plus a mutation
7202+/// proof that widening the pricer's offer set does). The clip gate that used
7203+/// to wait on it is deleted; this counter stays so that widening the pricer
7204+/// is loud instead of silent. `EC_AV1_TRACE=1` prints each hit.
72077205 pub fn drl_clamp_hits() -> usize {
72087206 DRL_CLAMP_HITS.load(std::sync::atomic::Ordering::Relaxed)
72097207 }