forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'simplify/u3' into simplify/w1b

Browse files at this commit

531c916c41f4169e7ad078670fa3f4e840d2e258Ahmet Kaan GümüşParent: be2d31f30f025c

56 changed files +6851 -25200

Cargo.lockmodified+0 -8
@@ -423,8 +423,6 @@ dependencies = [
423423 "ec-av1-syntax",
424424 "ec-core",
425425 "ec-testkit",
426- "stats_alloc",
427- "tracking-allocator",
428426 ]
429427
430428 [[package]]
@@ -1731,12 +1729,6 @@ version = "1.2.1"
17311729 source = "registry+https://github.com/rust-lang/crates.io-index"
17321730 checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
17331731
1734-[[package]]
1735-name = "stats_alloc"
1736-version = "0.1.10"
1737-source = "registry+https://github.com/rust-lang/crates.io-index"
1738-checksum = "5c0e04424e733e69714ca1bbb9204c1a57f09f5493439520f9f68c132ad25eec"
1739-
17401732 [[package]]
17411733 name = "strength_reduce"
17421734 version = "0.2.4"
crates/ec-av1/Cargo.tomlmodified+0 -11
@@ -12,16 +12,5 @@ ec-av1-syntax.workspace = true
1212 archmage = "=0.9.31-beta.1"
1313 bytemuck = "1"
1414
15-[features]
16-default = ["gate-counters"]
17-# Compiles the ~550 `*_HITS` gate counters (see `src/hits.rs`). ON by default so
18-# every test gate and the probe's census see the same numbers they always have;
19-# a shipped decoder can build `--no-default-features` to drop the TLS bump on
20-# each counted path -- the `*_hits()` accessors still compile and return 0.
21-gate-counters = []
22-
2315 [dev-dependencies]
2416 ec-testkit.workspace = true
25-# `nightly` only makes StatsAlloc::new const, so it can be a #[global_allocator] static.
26-stats_alloc = { version = "0.1.10", features = ["nightly"] }
27-tracking-allocator = "0.4.0"
crates/ec-av1/examples/alloc_probe.rsdeleted+0 -96
@@ -1,96 +0,0 @@
1-//! Temporary lane-alloc instrument: count allocations and sample backtraces.
2-//!
3-//! Allocation totals come from `stats_alloc`. The per-size histogram and the
4-//! sampled backtraces come from `tracking-allocator`, which calls back into a
5-//! tracker on every allocation. Neither crate needs `unsafe` in this file.
6-//! Reallocs are excluded from totals and histogram, as the old hand-written
7-//! allocator did.
8-use std::alloc::System;
9-use std::collections::HashMap;
10-use std::sync::Mutex;
11-use std::sync::atomic::{AtomicUsize, Ordering};
12-
13-use stats_alloc::StatsAlloc;
14-use tracking_allocator::{AllocationGroupId, AllocationRegistry, AllocationTracker, Allocator};
15-
16-static SIZES: [AtomicUsize; 24] = [const { AtomicUsize::new(0) }; 24];
17-static TRACES: Mutex<Option<HashMap<String, usize>>> = Mutex::new(None);
18-/// `reallocations` as of the last tracked allocation. A realloc bumps that counter
19-/// and then reaches the tracker as an allocation, so a bump means "not a new alloc".
20-static SEEN_REALLOCS: AtomicUsize = AtomicUsize::new(0);
21-
22-struct Track;
23-impl AllocationTracker for Track {
24- fn allocated(&self, _addr: usize, object_size: usize, _wrapped: usize, _g: AllocationGroupId) {
25- let st = A.stats();
26- if st.reallocations != SEEN_REALLOCS.swap(st.reallocations, Ordering::Relaxed) {
27- return;
28- }
29- // `allocations` already includes this allocation; index it from 0 like the old counter.
30- let n = st.allocations - 1;
31- let cls = (usize::BITS - object_size.leading_zeros()) as usize;
32- SIZES[cls.min(23)].fetch_add(1, Ordering::Relaxed);
33- if n.is_multiple_of(512) {
34- let bt = format!("{}", std::backtrace::Backtrace::force_capture());
35- let mut key: Vec<String> = Vec::new();
36- let lines: Vec<&str> = bt.lines().collect();
37- for (i, l) in lines.iter().enumerate() {
38- if l.contains("ec_av1::") && key.len() < 6 {
39- let at = lines
40- .get(i + 1)
41- .filter(|n| n.trim_start().starts_with("at "))
42- .map(|n| n.trim().to_string())
43- .unwrap_or_default();
44- key.push(format!("{} {}", l.trim(), at));
45- }
46- }
47- let mut g = TRACES.lock().unwrap();
48- *g.get_or_insert_with(HashMap::new).entry(key.join(" <- ")).or_insert(0) += 1;
49- // The capture's own reallocs were not tracked; skip them too.
50- SEEN_REALLOCS.store(A.stats().reallocations, Ordering::Relaxed);
51- }
52- }
53- fn deallocated(
54- &self,
55- _addr: usize,
56- _object_size: usize,
57- _wrapped: usize,
58- _source: AllocationGroupId,
59- _current: AllocationGroupId,
60- ) {
61- }
62-}
63-
64-#[global_allocator]
65-static A: StatsAlloc<Allocator<System>> = StatsAlloc::new(Allocator::system());
66-
67-fn main() {
68- AllocationRegistry::set_global_tracker(Track).expect("tracker");
69- AllocationRegistry::enable_tracking();
70- let path = std::env::args().nth(1).expect("usage: alloc_probe <stream.obu>");
71- let data = std::fs::read(&path).expect("read");
72- let mut shown = 0usize;
73- let r = ec_av1::stream::decode_stream_with(&data, |_f, _i, s| {
74- if s {
75- shown += 1;
76- }
77- Ok(())
78- });
79- println!("shown={shown} result={:?}", r.is_ok());
80- let st = A.stats();
81- println!("allocs={} bytes={}", st.allocations, st.bytes_allocated);
82- for (i, c) in SIZES.iter().enumerate() {
83- let v = c.load(Ordering::Relaxed);
84- if v > 0 {
85- println!("size 2^{i} : {v}");
86- }
87- }
88- let g = TRACES.lock().unwrap();
89- if let Some(m) = g.as_ref() {
90- let mut v: Vec<_> = m.iter().collect();
91- v.sort_by_key(|(_, c)| std::cmp::Reverse(**c));
92- for (k, c) in v.into_iter().take(30) {
93- println!("{c:6} {k}");
94- }
95- }
96-}
crates/ec-av1/examples/decode_probe.rsdeleted+0 -532
@@ -1,532 +0,0 @@
1-//! Where does a real stream stop? Decode one AV1 file and print the answer.
2-//!
3-//! The gates in [`ec_av1::stream`] each pin one capability against one encoder
4-//! recipe. This asks the complementary question -- given a stream someone
5-//! actually produced, which refusal comes first -- and it is how the refusal
6-//! distribution in commit 2be815f was measured rather than reasoned about:
7-//!
8-//! ```text
9-//! aomenc --codec=av1 --obu -o s.obu --passes=1 --cpu-used=4 --limit=4 in.y4m
10-//! cargo run -p ec-av1 --example decode_probe -- s.obu
11-//! ```
12-//!
13-//! Note `--obu`: [`ec_av1::stream::decode_stream`] takes a raw OBU stream, and
14-//! an IVF file decodes as zero frames rather than as an error.
15-//!
16-//! That run is also what disproved three refusal strings claiming an encoder
17-//! never writes a case it demonstrably writes, so this is a first-class
18-//! instrument, not a scratch file.
19-fn main() {
20- let Some(path) = std::env::args().nth(1) else {
21- eprintln!("usage: decode_probe <stream.obu>");
22- std::process::exit(2);
23- };
24- let data = match std::fs::read(&path) {
25- Ok(data) => data,
26- Err(e) => {
27- eprintln!("{path}: {e}");
28- std::process::exit(2);
29- }
30- };
31- let report = || {
32- // lane-av1unwritten r6: the subsize-guard coverage table (per call
33- // site, per partition value, reached vs fired). Env-gated
34- // (`EC_AV1_SUBSIZE_GUARD_TRACE`), so it is empty unless asked for.
35- ec_av1::decode::dump_subsize_guard_scan();
36- ec_av1::decode::dump_subsize_arm_scan();
37- // The census below reads ec-av1's gate counters; without the crate's
38- // `gate-counters` feature every one of them is compiled out and reads 0.
39- if !cfg!(feature = "gate-counters") {
40- println!("counters disabled (built without the gate-counters feature)");
41- }
42- let [a444, a422, s420, r420] = ec_av1::decode::cfl_ac_arm_hits();
43- println!(
44- "cfl_ac: 444={a444} 422={a422} 420sq={s420} 420rect={r420} q3_at={}",
45- ec_av1::decode::cfl_ac_q3_at_hits()
46- );
47- let (sc, dp) = ec_av1::decode::reelc_chroma_counters();
48- println!("reelc_chroma: skip_cfl={sc} dir_1to4_pairs={dp}");
49- println!(
50- "ibc128: mu_chroma={} intra128={}",
51- ec_av1::decode::intra_128_in_inter_mu_chroma_hits(),
52- ec_av1::decode::intra_128_in_inter_hits()
53- );
54- println!(
55- "chroma422_square: {}",
56- ec_av1::decode::chroma422_square_hits()
57- );
58- println!("chroma422_rect: {}", ec_av1::decode::chroma422_rect_hits());
59- println!("chroma422_sub8: {}", ec_av1::decode::chroma422_sub8_hits());
60- println!(
61- "chroma422_chunk: {}",
62- ec_av1::decode::chroma422_chunk_hits()
63- );
64- println!(
65- "chroma422_pair_wide: {}",
66- ec_av1::decode::chroma422_pair_wide_hits()
67- );
68- println!(
69- "uv_left_ss_y: reads={} mode_diff={} smooth_diff={} split1mi={}",
70- ec_av1::decode::uv_left_ss_y_reads(),
71- ec_av1::decode::uv_left_ss_y_mode_diff_hits(),
72- ec_av1::decode::uv_left_ss_y_smooth_diff_hits(),
73- ec_av1::decode::uv_left_1mi_split_hits(),
74- );
75- let (h, v, c) = ec_av1::stream::rect4_32_counters();
76- println!(
77- "rect4_16_uv_pair_filt: {}",
78- ec_av1::decode::rect4_16_uv_pair_filt_hits()
79- );
80- println!("rect4_32: horz={h} vert={v} coded={c}");
81- println!(
82- "rect_intrabc_reads: {}",
83- ec_av1::stream::rect_intrabc_reads()
84- );
85- let (pal_y, pal_uv) = ec_av1::stream::intra_in_inter_palette_hits();
86- println!("intra_in_inter_palette: y={pal_y} uv={pal_uv}");
87- println!(
88- "palette_422_unit_window: {}",
89- ec_av1::decode::palette_422_unit_window_hits()
90- );
91- println!(
92- "rect64_corner_tu: 64x32={} 32x64={}",
93- ec_av1::stream::rect64_corner_tu_hits(0),
94- ec_av1::stream::rect64_corner_tu_hits(1)
95- );
96- println!(
97- "leaf8_intrabc_hits: {}",
98- ec_av1::stream::leaf8_intrabc_hits()
99- );
100- println!("intrabc_hits: {}", ec_av1::stream::intrabc_hits());
101- println!(
102- "intrabc_vartx_trees: {}",
103- ec_av1::decode::intrabc_vartx_hits()
104- );
105- println!(
106- "intrabc_vartx_mixed_leaves: {}",
107- ec_av1::decode::intrabc_vartx_mixed_leaves_hits()
108- );
109- println!(
110- "skipped_intrabc_chroma_arm_hits: {}",
111- ec_av1::stream::skipped_intrabc_chroma_arm_hits()
112- );
113- println!(
114- "intrabc_rect: {} (var-tx tree: {})",
115- ec_av1::decode::intrabc_rect_hits(),
116- ec_av1::decode::intrabc_rect_vartx_hits()
117- );
118- // lane-av1-ibcrect: `use_intrabc` on a 128-root HORZ/VERT strip --
119- // the shape `decode_block_128rect` used to refuse.
120- println!(
121- "intrabc_128rect: {}",
122- ec_av1::stream::intrabc_128rect_hits()
123- );
124- // lane-av1-ibc128chunk: the 128-root intrabc strip's per-axis chroma
125- // mu-chunk walk -- unit count and the `(64>>ss_x)|(64>>ss_y)` extent.
126- println!(
127- "intrabc_128rect_chroma_chunk: units={} shape=0x{:x}",
128- ec_av1::stream::intrabc_128rect_chroma_chunk_hits(),
129- ec_av1::stream::intrabc_128rect_chunk_shape()
130- );
131- let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();
132- println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}");
133- println!(
134- "sub8_inter_split: groups={}",
135- ec_av1::decode::sub8_inter_split_hits()
136- );
137- println!(
138- "skip_split_tx_override: {}",
139- ec_av1::decode::skip_split_tx_override_hits()
140- );
141- println!(
142- "interintra_rect: {}",
143- ec_av1::decode::interintra_rect_hits()
144- );
145- println!(
146- "gm_nontrans_small_side: {}",
147- ec_av1::decode::gm_nontrans_small_side_hits()
148- );
149- println!(
150- "tr_reach_longer_side: {}",
151- ec_av1::decode::tr_reach_longer_side_hits()
152- );
153- println!(
154- "mv_clamp_edge_overhang: {}",
155- ec_av1::mvstack::mv_clamp_edge_overhang_hits()
156- );
157- let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits();
158- println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}");
159- println!(
160- "llintra8_chroma_walk: {}",
161- ec_av1::decode::llintra8_chroma_walk_hits()
162- );
163- println!(
164- "sub8rect444_chroma_walk: {}",
165- ec_av1::decode::llsub8rect444_chroma_walk_hits()
166- );
167- let si = ec_av1::stream::sub8_intra_rect_hits();
168- println!(
169- "sub8_intra_rect: horz8x4={} vert4x8={} chroma_ref={} mixed={} split4x4={}",
170- si.0, si.1, si.2, si.3, si.4
171- );
172- let leaf = ec_av1::stream::vartx_rect_leaf_hits();
173- println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]);
174- // lane-inter16ab r1: the 16x16-level inter AB arms, so a recipe sweep
175- // can tell "aomenc never picked one" from "it did and we decoded it".
176- let ab = ec_av1::decode::ab16_inter_hits_by_arm();
177- println!(
178- "inter_ab16: horz_a={} horz_b={} vert_a={} vert_b={}",
179- ab[0], ab[1], ab[2], ab[3]
180- );
181- // lane-kf900 r1: the counter the skipped-8x8-split-transform gate
182- // asserts -- printed here so a recipe sweep can see it fire without a
183- // test-binary rebuild.
184- println!("skip_split_tx: {}", ec_av1::decode::skip_split_tx_hits());
185- let es = ec_av1::decode::inter_edge_strip_hits();
186- println!(
187- "inter_edge_strip: h64={} v64={} h32={} v32={} h16={} v16={}",
188- es[0], es[1], es[2], es[3], es[4], es[5]
189- );
190- let (h4, v4, pairs, sub8) = ec_av1::decode::inter16_rect4_counters();
191- println!("inter16_1to4: horz4={h4} vert4={v4} chroma_pairs={pairs} sub8_pieces={sub8}");
192- let leaf4 = ec_av1::stream::vartx_rect_leaf4_hits();
193- println!("vartx_rect_leaf4: 8x4={} 4x8={}", leaf4[0], leaf4[1]);
194- // lane-av1txr: intrabc 4x8/8x4 leaves that read the inter var-tx tree
195- // (the symbol whose absence desynced `warped.obu`).
196- println!(
197- "rect_intrabc_vartx: {}",
198- ec_av1::decode::rect_intrabc_vartx_hits()
199- );
200- let rw = ec_av1::stream::rect_wedge_hits();
201- let rwi = ec_av1::stream::rect_wii_hits();
202- println!("rect_wedge(8x16,16x8,16x32,32x16,8x32,32x8): compound={rw:?} interintra={rwi:?}");
203- // lane-inter128intra r1: the 128 root's HORZ/VERT half coded INTRA in
204- // an INTER frame -- the arm this round implemented.
205- let i128 = ec_av1::stream::intra128_in_inter_counters();
206- println!("intra128_in_inter: 128x64={} 64x128={}", i128[0], i128[1]);
207- // lane-lossless128: intra 128-axis blocks on a LOSSLESS frame (every
208- // plane TX_4X4) -- the shape whose reconstruction used to panic.
209- println!(
210- "intra128_lossless: {}",
211- ec_av1::stream::intra128_lossless_counters()
212- );
213- let sb = ec_av1::stream::sb128_rect_counters();
214- println!(
215- "sb128_rect: edge_horz={} edge_vert={} inter_128x64={} inter_64x128={}",
216- sb.0, sb.1, sb.2, sb.3
217- );
218- // lane-av1-ibcrect: the interior 128-root partition arms and the key
219- // frame's intra 128-axis blocks, so a recipe sweep can tell "the
220- // encoder never chose HORZ/VERT at the 128 root" from "it did".
221- let p128 = ec_av1::stream::part128_census();
222- println!(
223- "part128: split={} none={} horz={} vert={} ab={:?} intra_horz={} intra_vert={}",
224- p128.0, p128.1, p128.2, p128.3, p128.4, p128.5, p128.6
225- );
226- // lane-sbab r1: the superblock-level inter AB arms.
227- let sbab = ec_av1::decode::sb_ab_inter_hits_by_arm();
228- println!(
229- "inter_ab64: horz_a={} horz_b={} vert_a={} vert_b={}",
230- sbab[0], sbab[1], sbab[2], sbab[3]
231- );
232- let i4 = ec_av1::stream::intra_rect4_in_inter_counters();
233- println!(
234- "intra_rect4_in_inter: 64x16={} 16x64={} 32x8={} 8x32={}",
235- i4.0, i4.1, i4.2, i4.3
236- );
237- // lane-cdefstrip r1: 8x8 CDEF units whose skip band no coded block
238- // wrote this frame -- non-zero means a decode arm forgot
239- // `fill_skip_grid_rect`, and CDEF filtered a unit libaom may skip.
240- println!(
241- "cdef_unwritten_skip_units: {}",
242- ec_av1::decode::cdef_unwritten_skip_units()
243- );
244- println!(
245- "cdef_band: rect_skip_writes={} mixed_skip_units={}",
246- ec_av1::decode::rect_skip_band_hits(),
247- ec_av1::decode::cdef_mixed_skip_units()
248- );
249- let ir = ec_av1::stream::inter_rect_counters();
250- println!(
251- "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}",
252- ir.0, ir.1, ir.2, ir.3, ir.4, ir.5
253- );
254- // lane-rectres r1: how many of those 32x8/8x32 strips coded a real
255- // rectangular residual transform unit (a skipped one codes none).
256- println!(
257- "sub8_chroma_tx_from_ref: {}",
258- ec_av1::stream::sub8_chroma_tx_from_ref_hits()
259- );
260- let r328 = ec_av1::stream::rect32x8_inter_tu_hits();
261- println!("rect32x8_inter_tu: 32x8={} 8x32={}", r328[0], r328[1]);
262- // lane-intra16x4: INTRA strips of an inter 16x16-level 1:4 partition.
263- let i164 = ec_av1::stream::intra16x4_in_inter_hits();
264- println!(
265- "intra16x4_in_inter: 16x4={} 4x16={} chroma_ref={}",
266- i164.0, i164.1, i164.2
267- );
268- println!(
269- "rect4_16_pair: lossless_chroma={} intrabc={}",
270- ec_av1::decode::rect4_16_lossless_chroma_hits(),
271- ec_av1::decode::rect4_16_intrabc_hits(),
272- );
273- println!(
274- "loss64: chroma_edge_tu_clip={} skip_lossless_band_reset={}",
275- ec_av1::decode::chroma_edge_tu_clip_hits(),
276- ec_av1::decode::skip_lossless_band_reset_hits(),
277- );
278- println!(
279- "llband: rect_split_lossless_chroma444={}",
280- ec_av1::decode::rect_split_lossless_chroma444_hits()
281- );
282- // lane-t900 r12: chroma edge-filter neighbour answered from the mi-granular
283- // uv_mode grid instead of the coarse one-slot-per-column map.
284- println!(
285- "scaled: leaf8={} sub8={} warpfb={} predict_scaled={}",
286- ec_av1::decode::scaled_leaf8_hits(),
287- ec_av1::decode::scaled_sub8_hits(),
288- ec_av1::decode::scaled_warp_fallback_hits(),
289- ec_av1::mc::predict_scaled_hits()
290- );
291- println!(
292- "uv_mode_grid_override: {}",
293- ec_av1::decode::uv_mode_grid_override_hits()
294- );
295- // lane-thread2: proof the frame-parallel path actually fired (0 at
296- // the default EC_AV1_THREADS=1).
297- println!("frames_dispatched: {}", ec_av1::stream::frames_dispatched());
298- // lane-av1recipehunt: `intra_rect4_in_inter` above already reports the
299- // 1:4-in-inter shapes; this is the `delta_q` half of the same story --
300- // how many delta_q groups the stream really carried, and how many of
301- // them landed inside a rect64 dequant.
302- let (dq, dq_drift) = ec_av1::stream::rect64_qidx_drift_counters();
303- println!("delta_q: groups_read={dq} rect64_qidx_drift={dq_drift}");
304- // lane-av1422census422: the per-plane coefficient-unit census, armed
305- // for 4:4:4 and 4:2:2 (4:2:0 arms nothing, so a 4:2:0 recipe sweep
306- // reads `luma=0 u=0 v=0` BY DESIGN and must not read that as "the
307- // walk was empty" -- `units_total` is the UNCONDITIONAL per-frame
308- // total, so the two together say whether the census was armed at
309- // all). This is what makes a 4:2:2 non-vacuity requirement
310- // writable: before the widening every per-plane field read zero on a
311- // 4:2:2 cell BY CONSTRUCTION, so a byte-exact 4:2:2 gate could
312- // assert it and prove nothing about the stream it had decoded.
313- let cu = ec_av1::decode::census_nonsub_units();
314- let cc = ec_av1::decode::census_nonsub_coded();
315- println!(
316- "census_units: luma={} u={} v={} | coded: luma={} u={} v={} | units_total={}",
317- cu[0],
318- cu[1],
319- cu[2],
320- cc[0],
321- cc[1],
322- cc[2],
323- ec_av1::decode::census_unit_n(),
324- );
325- };
326- // lane-tiles: the tiling a real stream actually uses is a decision input
327- // (every gate in `stream.rs` picks its own `--tile-columns`), so report it
328- // from the frame headers before saying anything about pixels.
329- let mut parser = ec_av1_syntax::Av1Parser::new();
330- let mut seen: Vec<(u32, u32, bool, u32)> = Vec::new();
331- let mut pos = 0usize;
332- let mut frames_seen = 0usize;
333- // OBU at a time, so one unparseable OBU late in the stream still leaves
334- // every earlier frame header's tiling reported.
335- while pos < data.len() {
336- let Ok(obu) = parser.parse_obu(&data[pos..]) else {
337- break;
338- };
339- pos += obu.total_size.max(1);
340- let header = match &obu.kind {
341- ec_av1_syntax::ObuKind::FrameHeader(h) => h,
342- ec_av1_syntax::ObuKind::Frame(h, _) => h,
343- _ => continue,
344- };
345- frames_seen += 1;
346- // lane-frame36: `EC_PROBE_HDR=1` prints one line per frame header, so a
347- // silent wall can be triaged by "which header field is new at frame N"
348- // before any pixel work (class: a header field parsed then never consumed).
349- if std::env::var("EC_PROBE_HDR").is_ok() {
350- let h = header;
351- let gm: Vec<String> = h
352- .global_motion
353- .iter()
354- .map(|w| format!("{:?}", w.model))
355- .collect();
356- println!(
357- "HDR {}: type={:?} show={} showable={} show_existing={}({}) intra={} \
358- size={}x{} up={} superres={}/{} order_hint={} primary_ref={} refresh={:#04x} \
359- refs={:?} order_hints={:?} sign_bias={:?} err_res={} disable_cdf={} \
360- screen_tools={} int_mv={} intrabc={} hp_mv={} interp={:?} switchable_motion={} \
361- ref_mvs={} base_q={} seg={} deltaq={} deltalf={} lf_level={:?} lf_deltas={:?}/{:?} \
362- cdef_bits={} lr={:?} tx_mode={:?} ref_sel={} skip_mode={}({:?}) warp={} \
363- reduced_tx={} gm={:?} grain={}/seed={} lossless={}",
364- frames_seen - 1,
365- h.frame_type,
366- h.show_frame,
367- h.showable_frame,
368- h.show_existing_frame,
369- h.frame_to_show_map_idx,
370- h.frame_is_intra,
371- h.frame_width,
372- h.frame_height,
373- h.upscaled_width,
374- h.use_superres,
375- h.superres_denom,
376- h.order_hint,
377- h.primary_ref_frame,
378- h.refresh_frame_flags,
379- h.ref_frame_idx,
380- h.order_hints,
381- h.ref_frame_sign_bias,
382- h.error_resilient_mode,
383- h.disable_cdf_update,
384- h.allow_screen_content_tools,
385- h.force_integer_mv,
386- h.allow_intrabc,
387- h.allow_high_precision_mv,
388- h.interpolation_filter,
389- h.is_motion_mode_switchable,
390- h.use_ref_frame_mvs,
391- h.quantization.base_q_idx,
392- h.segmentation.enabled,
393- h.delta.q_present,
394- h.delta.lf_present,
395- h.loop_filter.level,
396- h.loop_filter.ref_deltas,
397- h.loop_filter.mode_deltas,
398- h.cdef.bits,
399- h.loop_restoration.frame_restoration_type,
400- h.tx_mode,
401- h.reference_select,
402- h.skip_mode_present,
403- h.skip_mode_frame,
404- h.allow_warped_motion,
405- h.reduced_tx_set,
406- gm,
407- h.film_grain.apply_grain,
408- h.film_grain.grain_seed,
409- h.coded_lossless,
410- );
411- }
412- let t = &header.tile_info;
413- let entry = (t.cols, t.rows, t.uniform_spacing, t.context_update_tile_id);
414- if !seen.contains(&entry) {
415- seen.push(entry);
416- }
417- }
418- println!("TILING: {frames_seen} frame headers parsed");
419- // lane-sb128 r4: the superblock size decides the whole partition tree, so
420- // report it next to the tiling -- it is the first thing a film blocker
421- // triage needs.
422- if let Some(seq) = parser.sequence_header() {
423- println!(
424- "SEQ: use_128x128_superblock={} bit_depth={} mono_chrome={} max_frame={}x{}",
425- seq.use_128x128_superblock,
426- seq.color_config.bit_depth,
427- seq.color_config.mono_chrome,
428- seq.max_frame_width,
429- seq.max_frame_height
430- );
431- }
432- for (cols, rows, uniform, ctx_id) in &seen {
433- println!(
434- "TILING: cols={cols} rows={rows} uniform_spacing={uniform} context_update_tile_id={ctx_id}"
435- );
436- }
437- if seen.is_empty() {
438- println!("TILING: no frame header parsed");
439- }
440-
441- // lane-streamsink r1: decode through the streaming entry point and write
442- // each shown frame out as it completes. The old path collected every
443- // picture in a Vec and then built a second full copy of the raw dump
444- // before one `fs::write`, so peak RSS was 2x the whole decoded segment (a
445- // 4K 8 s window needed >20 GiB, a whole film terabytes). Here at most one
446- // frame is held beyond the decoder's own DPB, and the printed lines are
447- // byte-identical to the old ones.
448- // `EC_PROBE_OUT16` is yuv420p10le (u16 LE); `EC_PROBE_OUT` / argv[2] is
449- // 8-bit (planes are u16, low byte taken). Either target may be a FIFO.
450- use std::io::Write;
451- let open = |path: &str| {
452- std::fs::OpenOptions::new()
453- .write(true)
454- .create(true)
455- .truncate(true)
456- .open(path)
457- .unwrap_or_else(|e| panic!("opening {path}: {e}"))
458- };
459- let out16 = std::env::var("EC_PROBE_OUT16").ok();
460- let out8 = std::env::args()
461- .nth(2)
462- .or_else(|| std::env::var("EC_PROBE_OUT").ok());
463- let null16 = out16.as_deref() == Some("/dev/null");
464- let mut f16 = out16.as_deref().map(open);
465- let mut f8 = out8.as_deref().map(open);
466- let mut written16 = 0usize;
467- let mut written8 = 0usize;
468- let mut shown = 0usize;
469- let mut dims = (0usize, 0usize);
470- let mut buf: Vec<u8> = Vec::new();
471- // lane-av1mono: a monochrome stream is luma only, so the raw dump is a
472- // single plane -- exactly what `ffmpeg -pix_fmt gray -f rawvideo` writes.
473- let mono = parser
474- .sequence_header()
475- .is_some_and(|s| s.color_config.mono_chrome);
476- let result = ec_av1::stream::decode_stream_with(&data, |f, _idx, is_shown| {
477- if !is_shown {
478- return Ok(());
479- }
480- shown += 1;
481- if shown == 1 {
482- dims = (f.width, f.height);
483- }
484- let planes: &[&Vec<u16>] = if mono { &[&f.y] } else { &[&f.y, &f.u, &f.v] };
485- if let Some(w) = f16.as_mut() {
486- let n = 2 * planes.iter().map(|p| p.len()).sum::<usize>();
487- if null16 {
488- // Timing runs point EC_PROBE_OUT16 at /dev/null; the u16->LE
489- // conversion was ~2% of the main thread for bytes nobody reads.
490- written16 += n;
491- } else {
492- buf.clear();
493- buf.resize(n, 0);
494- let mut off = 0;
495- for p in planes {
496- let end = off + 2 * p.len();
497- for (d, &s) in buf[off..end].as_chunks_mut::<2>().0.iter_mut().zip(p.iter()) {
498- d.copy_from_slice(&s.to_le_bytes());
499- }
500- off = end;
501- }
502- w.write_all(&buf).expect("writing raw planes");
503- written16 += buf.len();
504- }
505- }
506- if let Some(w) = f8.as_mut() {
507- buf.clear();
508- for p in planes {
509- buf.extend(p.iter().map(|&s| s as u8));
510- }
511- w.write_all(&buf).expect("writing raw planes");
512- written8 += buf.len();
513- }
514- Ok(())
515- });
516- match result {
517- Ok(()) if shown == 0 => {
518- println!("OK but EMPTY: no frames -- is {path} an IVF rather than a raw OBU stream?");
519- }
520- Ok(()) => {
521- if let Some(out) = &out16 {
522- println!("wrote {written16} bytes of yuv420p10le to {out}");
523- }
524- if let Some(out) = &out8 {
525- println!("wrote {written8} bytes of yuv420p to {out}");
526- }
527- println!("OK: {shown} frames decoded, {}x{}", dims.0, dims.1);
528- }
529- Err(e) => println!("REFUSED: {e}"),
530- }
531- report();
532-}
crates/ec-av1/examples/syntax_census.rsdeleted+0 -375
@@ -1,375 +0,0 @@
1-//! Syntax census of one AV1 stream: what it actually codes, per frame type.
2-//!
3-//! `EC_AV1_BITCENSUS=1 cargo run --release -p ec-av1 --example syntax_census \
4-//! -- stream.obu [source.yuv]`
5-//!
6-//! The stream may be a raw OBU stream or an IVF file (unwrapped here). The
7-//! optional second argument is the ENCODER'S INPUT as planar 8-bit yuv420p at
8-//! the coded size, and turns on a per-displayed-frame PSNR -- computed here,
9-//! against the decoded pictures, because ffmpeg's own PSNR of an OBU stream
10-//! reads a constant ~28.8 dB (no timing in an OBU stream; ledger dead-end).
11-//!
12-//! Every number comes from `ec_av1::census`, i.e. from the decoder, so our
13-//! stream and any other encoder's stream are measured by the same reader.
14-
15-use ec_av1::census::Frame;
16-use std::collections::BTreeMap;
17-
18-/// The payloads of an IVF file's frames concatenated, or the data unchanged
19-/// when it is already a raw OBU stream.
20-fn unwrap_ivf(data: &[u8]) -> Vec<u8> {
21- if data.len() < 32 || &data[..4] != b"DKIF" {
22- return data.to_vec();
23- }
24- let header = u16::from_le_bytes([data[6], data[7]]) as usize;
25- let (mut pos, mut out) = (header, Vec::new());
26- while pos + 12 <= data.len() {
27- let len = u32::from_le_bytes([data[pos], data[pos + 1], data[pos + 2], data[pos + 3]])
28- as usize;
29- pos += 12;
30- if pos + len > data.len() {
31- break;
32- }
33- out.extend_from_slice(&data[pos..pos + len]);
34- pos += len;
35- }
36- out
37-}
38-
39-fn psnr(a: &[u16], b: &[u16]) -> f64 {
40- let se: f64 = a
41- .iter()
42- .zip(b)
43- .map(|(&x, &y)| {
44- let d = f64::from(x) - f64::from(y);
45- d * d
46- })
47- .sum();
48- match se {
49- 0.0 => 99.0,
50- _ => 10.0 * (255.0 * 255.0 * a.len() as f64 / se).log10(),
51- }
52-}
53-
54-/// Which broad syntax family a CDF table belongs to.
55-fn family_group(name: &str) -> &'static str {
56- const COEFF: [&str; 7] =
57- ["txb_skip", "eob_pt", "eob_extra", "base_", "base_eob", "br_", "dc_sign"];
58- if name.contains("tx_type") {
59- return "txtype";
60- }
61- if COEFF.iter().any(|p| name.starts_with(p)) {
62- return "coeff";
63- }
64- if name.starts_with("mv_") || name.starts_with("dv_") {
65- return "mv";
66- }
67- if name.starts_with("partition") || name.starts_with("txfm_partition") {
68- return "partition";
69- }
70- if name.starts_with("tx_size") {
71- return "txsize";
72- }
73- if name == "literal" || name == "unregistered" {
74- return "literal";
75- }
76- "mode"
77-}
78-
79-/// Sums a set of frames into one row's worth of census.
80-fn merge(frames: &[&Frame]) -> Frame {
81- let mut out = Frame::default();
82- for f in frames {
83- out.bytes += f.bytes;
84- for (k, v) in &f.blocks {
85- *out.blocks.entry(*k).or_default() += v;
86- }
87- for (k, v) in &f.tx {
88- *out.tx.entry(*k).or_default() += v;
89- }
90- for (k, v) in &f.tx_type {
91- *out.tx_type.entry(*k).or_default() += v;
92- }
93- for (k, v) in &f.families {
94- let e = out.families.entry(k).or_default();
95- e.0 += v.0;
96- e.1 += v.1;
97- }
98- for i in 0..3 {
99- out.area[i] += f.area[i];
100- }
101- for i in 0..8 {
102- out.refs[i] += f.refs[i];
103- }
104- for i in 0..4 {
105- out.modes[i] += f.modes[i];
106- }
107- for i in 0..6 {
108- out.mv[i] += f.mv[i];
109- }
110- out.skip_area += f.skip_area;
111- }
112- out
113-}
114-
115-fn pct(n: u64, total: u64) -> String {
116- format!("{:.1}%", 100.0 * n as f64 / total.max(1) as f64)
117-}
118-
119-const REFS: [&str; 8] =
120- ["INTRA", "LAST", "LAST2", "LAST3", "GOLDEN", "BWDREF", "ALTREF2", "ALTREF"];
121-
122-fn report(label: &str, f: &Frame, frames: usize) {
123- let area = f.area.iter().sum::<u64>().max(1);
124- println!("\n== {label} ({frames} frames, {} bytes) ==", f.bytes);
125- println!(
126- " area: intra {} single-ref {} compound {} | skip {}",
127- pct(f.area[0], area),
128- pct(f.area[1], area),
129- pct(f.area[2], area),
130- pct(f.skip_area, area),
131- );
132- println!(
133- " refs (area): {}",
134- REFS.iter()
135- .enumerate()
136- .filter(|(i, _)| f.refs[*i] > 0)
137- .map(|(i, n)| format!("{n} {}", pct(f.refs[i], area)))
138- .collect::<Vec<_>>()
139- .join(" "),
140- );
141- let modes = f.modes.iter().sum::<u64>();
142- println!(
143- " single-ref modes: NEW {} GLOBAL {} NEAREST {} NEAR {} (of {modes})",
144- pct(f.modes[0], modes),
145- pct(f.modes[1], modes),
146- pct(f.modes[2], modes),
147- pct(f.modes[3], modes),
148- );
149- let mvs = f.mv.iter().sum::<u64>();
150- println!(
151- " coded mv |max| (1/8 pel): 0 {} <=8 {} <=32 {} <=128 {} <=512 {} >512 {} (of {mvs})",
152- pct(f.mv[0], mvs),
153- pct(f.mv[1], mvs),
154- pct(f.mv[2], mvs),
155- pct(f.mv[3], mvs),
156- pct(f.mv[4], mvs),
157- pct(f.mv[5], mvs),
158- );
159- let blocks: u64 = f.blocks.values().sum();
160- let mut by_size: Vec<_> = f.blocks.iter().collect();
161- by_size.sort_by_key(|(_, n)| std::cmp::Reverse(**n));
162- println!(
163- " blocks ({blocks} total): {}",
164- by_size
165- .iter()
166- .take(10)
167- .map(|((w, h), n)| format!("{w}x{h} {}", pct(**n, blocks)))
168- .collect::<Vec<_>>()
169- .join(" "),
170- );
171- let txs: u64 = f.tx.values().sum();
172- let mut by_tx: Vec<_> = f.tx.iter().collect();
173- by_tx.sort_by_key(|(_, n)| std::cmp::Reverse(**n));
174- println!(
175- " published luma tx ({txs}): {}",
176- by_tx
177- .iter()
178- .take(8)
179- .map(|((w, h), n)| format!("{w}x{h} {}", pct(**n, txs)))
180- .collect::<Vec<_>>()
181- .join(" "),
182- );
183- let tts: u64 = f.tx_type.values().sum();
184- println!(
185- " tx_type symbols ({tts}): {}",
186- f.tx_type
187- .iter()
188- .map(|((len, sym), n)| format!("set{len}/{sym} {}", pct(*n, tts)))
189- .collect::<Vec<_>>()
190- .join(" "),
191- );
192- // lane-libcen: the coding TOOLS, by name, so a level row says which of
193- // them the stream codes at all -- a table absent here is a tool this
194- // encoder never wrote (class `gate-blind-to-feature`).
195- const TOOLS: [&str; 16] = [
196- "motion_mode",
197- "obmc",
198- "interintra",
199- "wedge_interintra",
200- "wedge_idx",
201- "compound_type",
202- "comp_group_idx",
203- "compound_idx",
204- "switchable_interp",
205- "palette_y_mode",
206- "palette_uv_mode",
207- "intrabc",
208- "filter_intra",
209- "cfl_alpha",
210- "delta_q",
211- "segment_id",
212- ];
213- println!(
214- " tools (symbols/bits): {}",
215- TOOLS
216- .iter()
217- .map(|t| {
218- let (n, bits) = f.families.get(t).copied().unwrap_or((0, 0.0));
219- format!("{t} {n}/{bits:.0}")
220- })
221- .collect::<Vec<_>>()
222- .join(" "),
223- );
224-
225- // Bits by family group, then the ten biggest tables inside them.
226- let mut groups: BTreeMap<&str, (u64, f64)> = BTreeMap::new();
227- for (name, (n, bits)) in &f.families {
228- let e = groups.entry(family_group(name)).or_default();
229- e.0 += n;
230- e.1 += bits;
231- }
232- let total_bits: f64 = groups.values().map(|g| g.1).sum();
233- println!(" bits by family (census total {:.0} bits vs {} payload bits):", total_bits, f.bytes * 8);
234- for (g, (n, bits)) in &groups {
235- println!(
236- " {g:<10} {:>12.0} bits {:>6} ({n} symbols)",
237- bits,
238- format!("{:.1}%", 100.0 * bits / total_bits.max(1.0))
239- );
240- }
241- let mut tables: Vec<_> = f.families.iter().collect();
242- tables.sort_by(|a, b| b.1 .1.total_cmp(&a.1 .1));
243- // lane-cen3: how many tables the row names. The default 8 hides the
244- // mode family's own split (a level can spend 40% of its bits on `mode`
245- // with no mode table in its top 8), so a census that has to rank
246- // per-table gaps between two encoders sets `EC_CENSUS_TABLES`.
247- let top = std::env::var("EC_CENSUS_TABLES")
248- .ok()
249- .and_then(|v| v.parse().ok())
250- .unwrap_or(8usize);
251- println!(
252- " top tables: {}",
253- tables
254- .iter()
255- .take(top)
256- .map(|(name, (_, bits))| format!("{name} {:.1}%", 100.0 * bits / total_bits.max(1.0)))
257- .collect::<Vec<_>>()
258- .join(" "),
259- );
260-}
261-
262-fn main() {
263- let args: Vec<String> = std::env::args().skip(1).collect();
264- let Some(path) = args.first() else {
265- eprintln!("usage: syntax_census <stream.obu|stream.ivf> [source.yuv]");
266- std::process::exit(2);
267- };
268- assert!(ec_av1::census::on(), "set EC_AV1_BITCENSUS=1");
269- let data = unwrap_ivf(&std::fs::read(path).expect("stream"));
270- let pictures = ec_av1::stream::decode_stream(&data).expect("decode");
271- let frames = ec_av1::census::take();
272-
273- println!("# syntax census of {path} ({} bytes)", data.len());
274- println!("\n| frame | kind | q | bytes | lf | cdef bits/y/uv | lr | dq | seg |");
275- println!("|---|---|---|---|---|---|---|---|---|");
276- for f in &frames {
277- println!(
278- "| {} | {} | {} | {} | {}/{} | {}/{}/{} | {:?} | {} | {} |",
279- f.idx,
280- f.kind,
281- f.qindex,
282- f.bytes,
283- f.lf[0],
284- f.lf[1],
285- f.cdef[0],
286- f.cdef[1],
287- f.cdef[2],
288- f.lr,
289- u8::from(f.delta_q),
290- u8::from(f.segmentation),
291- );
292- }
293- // PSNR is per DISPLAYED picture, in display order, which is not the order
294- // the frames above are coded in (a pyramid codes a hidden ARF ahead of the
295- // leaves that predict from it, and re-outputs it later with
296- // `show_existing_frame`) -- so it is its own table rather than a column.
297- let mut psnrs: Vec<(f64, f64, f64)> = Vec::new();
298- if let Some(src) = args.get(1).map(|p| std::fs::read(p).expect("source")) {
299- let mut sum = 0.0;
300- let mut rows = Vec::new();
301- for (i, pic) in pictures.iter().enumerate() {
302- let (luma, chroma) = (pic.width * pic.height, pic.width * pic.height / 4);
303- let frame_len = luma + 2 * chroma;
304- let Some(b) = src.get(i * frame_len..(i + 1) * frame_len) else { break };
305- let want: Vec<u16> = b[..luma].iter().map(|&v| u16::from(v)).collect();
306- // lane-arfpred: the chroma planes too -- an anchor's byte gap can
307- // sit in a plane the luma-only line cannot see (class
308- // `metric blind to a plane`).
309- let wu: Vec<u16> = b[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect();
310- let wv: Vec<u16> = b[luma + chroma..frame_len].iter().map(|&v| u16::from(v)).collect();
311- let p = psnr(&pic.y, &want);
312- psnrs.push((p, psnr(&pic.u, &wu), psnr(&pic.v, &wv)));
313- sum += p;
314- rows.push(format!("{i}:{p:.2}"));
315- }
316- println!(
317- "\nPSNR-Y display order ({} pictures): {}\nPSNR-Y mean {:.3} dB over {} pictures",
318- pictures.len(),
319- rows.join(" "),
320- sum / rows.len() as f64,
321- rows.len(),
322- );
323- }
324-
325- // lane-arfcen: one full report PER CODED FRAME, so an ARF of ours can be
326- // put next to the reference encoder's ARF at the same display position.
327- if std::env::var("EC_CENSUS_PERFRAME").as_deref() == Ok("1") {
328- for f in &frames {
329- let (p, pu, pv) =
330- psnrs.get(f.order_hint as usize).copied().unwrap_or((f64::NAN, f64::NAN, f64::NAN));
331- let refs: Vec<String> = (0..7)
332- .filter(|i| f.refs[i + 1] > 0)
333- .map(|i| {
334- format!(
335- "{}@{:+}",
336- REFS[i + 1],
337- i64::from(f.ref_hints[i]) - i64::from(f.order_hint),
338- )
339- })
340- .collect();
341- report(
342- &format!(
343- "frame {} {} hint {} q {} PSNR-Y {p:.2} U {pu:.2} V {pv:.2} dB refs [{}]",
344- f.idx,
345- f.kind,
346- f.order_hint,
347- f.qindex,
348- refs.join(" "),
349- ),
350- f,
351- 1,
352- );
353- }
354- }
355-
356- for kind in ["key", "arf", "leaf"] {
357- let set: Vec<&Frame> = frames.iter().filter(|f| f.kind == kind).collect();
358- if !set.is_empty() {
359- report(kind, &merge(&set), set.len());
360- }
361- }
362- report("ALL", &merge(&frames.iter().collect::<Vec<_>>()), frames.len());
363- // The self-check: every coded block is published exactly once, so the
364- // censused area must be the frame's own mi area (a funnel that misses a
365- // block class would silently under-count every share above).
366- if let Some(pic) = pictures.first() {
367- let all = merge(&frames.iter().collect::<Vec<_>>());
368- let want = (pic.width.div_ceil(4) * pic.height.div_ceil(4) * frames.len()) as u64;
369- let got = all.area.iter().sum::<u64>();
370- println!(
371- "\ncoverage: censused block area {got} of {want} mi ({:.2}%)",
372- 100.0 * got as f64 / want as f64
373- );
374- }
375-}
crates/ec-av1/src/census.rsdeleted+0 -314
@@ -1,314 +0,0 @@
1-//! Syntax census: what a stream actually codes, per frame, read off the
2-//! decoder itself (`EC_AV1_BITCENSUS=1`).
3-//!
4-//! Every number here is a decode-side observation, so OUR stream and any
5-//! other encoder's stream are measured by the same reader -- which is the
6-//! whole point: a BD-rate gap says our stream is bigger, it never says which
7-//! syntax it is bigger in. The accountant is off by default and costs one
8-//! relaxed atomic load per symbol when off.
9-//!
10-//! Bits are charged per CDF TABLE, not per hand-labelled call site: a tile
11-//! registers the address range of every field of its `Cdfs` (see
12-//! [`register_cdfs`]), and [`charge`] maps the table a symbol read to that
13-//! field's name. So a new coding tool joins the census the day its CDF joins
14-//! the struct, with no call-site edits (class `gate-blind-to-feature`).
15-//!
16-//! Run it through `examples/syntax_census.rs`; `EC_AV1_THREADS` must be 1
17-//! (the default) so the frame the counters attribute to is the frame being
18-//! parsed.
19-
20-use std::collections::BTreeMap;
21-use std::sync::atomic::{AtomicBool, Ordering};
22-use std::sync::{Mutex, OnceLock};
23-
24-static ON: AtomicBool = AtomicBool::new(false);
25-
26-/// Whether the accountant is armed (`EC_AV1_BITCENSUS=1`, read once).
27-#[inline]
28-pub fn on() -> bool {
29- static INIT: OnceLock<bool> = OnceLock::new();
30-
31- *INIT.get_or_init(|| {
32- let armed = crate::envflags::var("EC_AV1_BITCENSUS").ok().as_deref() == Some("1");
33- ON.store(armed, Ordering::Relaxed);
34- armed
35- })
36-}
37-
38-/// The per-symbol fast path: one relaxed load, nothing else, when off.
39-#[inline]
40-pub(crate) fn armed() -> bool {
41- ON.load(Ordering::Relaxed)
42-}
43-
44-/// One coded frame's census.
45-#[derive(Default, Debug, Clone)]
46-pub struct Frame {
47- /// Decode-order index.
48- pub idx: usize,
49- /// `key` (intra), `arf` (coded but not shown) or `leaf` (coded and shown).
50- pub kind: &'static str,
51- /// `base_q_idx`.
52- pub qindex: u8,
53- /// `OrderHint` of this frame, i.e. its display position (lane-arfcen).
54- pub order_hint: u32,
55- /// `OrderHints[LAST..=ALTREF]`, so a row can name its references' display
56- /// distance rather than only which slot it read (lane-arfcen).
57- pub ref_hints: [u32; 7],
58- /// Tile payload bytes of this frame.
59- pub bytes: usize,
60- /// `delta_q_present`.
61- pub delta_q: bool,
62- /// `segmentation_enabled`.
63- pub segmentation: bool,
64- /// `loop_filter_level[0..2]`.
65- pub lf: [u8; 2],
66- /// `cdef_bits`, `cdef_y_pri_strength[0]`, `cdef_uv_pri_strength[0]`.
67- pub cdef: [u8; 3],
68- /// `FrameRestorationType` per plane.
69- pub lr: [u8; 3],
70- /// Coded block shapes: (width, height) in pixels -> block count.
71- pub blocks: BTreeMap<(u16, u16), u64>,
72- /// Luma area (in 4x4 units) coded intra / single-ref inter / compound.
73- pub area: [u64; 3],
74- /// Luma area per reference frame slot (index 0 = intra, 1..=7 =
75- /// LAST..ALTREF as `ref_frame` names them).
76- pub refs: [u64; 8],
77- /// Luma area with `skip` set.
78- pub skip_area: u64,
79- /// NEWMV / GLOBALMV / NEARESTMV / NEARMV blocks (single-ref reads).
80- pub modes: [u64; 4],
81- /// Coded motion vectors bucketed by max(|x|,|y|) in eighth-pel:
82- /// 0, <=8 (1px), <=32, <=128, <=512, >512.
83- pub mv: [u64; 6],
84- /// Published luma transform shapes: (width, height) in pixels -> count.
85- pub tx: BTreeMap<(u16, u16), u64>,
86- /// Coded `tx_type` symbols: (CDF row length, symbol) -> count. The row
87- /// length names the transform SET (17 = all 16 types, 13, 8, 6 = the
88- /// reduced sets); symbol 0 is that set's first inverse-table entry.
89- pub tx_type: BTreeMap<(u8, u8), u64>,
90- /// Per-CDF-table (symbol count, bits).
91- pub families: BTreeMap<&'static str, (u64, f64)>,
92-}
93-
94-#[derive(Default)]
95-struct State {
96- frames: Vec<Frame>,
97- /// Sorted (start address, end address, field name) of the live tile's
98- /// `Cdfs`.
99- tables: Vec<(usize, usize, &'static str)>,
100- /// Area of the block most recently published, so `compound` can move it.
101- last_block_area: u64,
102-}
103-
104-fn state() -> &'static Mutex<State> {
105- static S: OnceLock<Mutex<State>> = OnceLock::new();
106- S.get_or_init(|| Mutex::new(State::default()))
107-}
108-
109-fn with<R>(f: impl FnOnce(&mut State) -> R) -> R {
110- f(&mut state().lock().unwrap_or_else(std::sync::PoisonError::into_inner))
111-}
112-
113-fn cur(s: &mut State) -> &mut Frame {
114- if s.frames.is_empty() {
115- s.frames.push(Frame::default());
116- }
117- s.frames.last_mut().expect("pushed above")
118-}
119-
120-/// Every frame censused since the last call, and clears the record.
121-pub fn take() -> Vec<Frame> {
122- with(|s| std::mem::take(&mut s.frames))
123-}
124-
125-/// Opens a new frame's row -- called once per coded frame, before its tiles.
126-pub(crate) fn frame_start(header: &ec_av1_syntax::FrameHeader, bytes: usize, idx: usize) {
127- if !armed() {
128- return;
129- }
130- let kind = match (header.frame_is_intra, header.show_frame) {
131- (true, _) => "key",
132- (false, false) => "arf",
133- (false, true) => "leaf",
134- };
135- with(|s| {
136- s.frames.push(Frame {
137- idx,
138- kind,
139- qindex: header.quantization.base_q_idx,
140- order_hint: header.order_hint,
141- ref_hints: header.order_hints,
142- bytes,
143- delta_q: header.delta.q_present,
144- segmentation: header.segmentation.enabled,
145- lf: [header.loop_filter.level[0], header.loop_filter.level[1]],
146- cdef: [
147- header.cdef.bits,
148- header.cdef.y_pri_strength[0],
149- header.cdef.uv_pri_strength[0],
150- ],
151- lr: [
152- header.loop_restoration.frame_restoration_type[0] as u8,
153- header.loop_restoration.frame_restoration_type[1] as u8,
154- header.loop_restoration.frame_restoration_type[2] as u8,
155- ],
156- ..Frame::default()
157- });
158- });
159-}
160-
161-/// Registers the address range of every CDF table of the tile's own `Cdfs`,
162-/// so [`charge`] can name the family a symbol was read with. Called once per
163-/// tile, right where the tile's symbol decoder is built.
164-pub(crate) fn register_cdfs(c: &crate::cdf_state::Cdfs) {
165- if !armed() {
166- return;
167- }
168- macro_rules! ranges {
169- ($($name:ident),* $(,)?) => {
170- vec![$({
171- let start = std::ptr::addr_of!(c.$name) as usize;
172- (start, start + std::mem::size_of_val(&c.$name), stringify!($name))
173- }),*]
174- };
175- }
176- let mut tables: Vec<(usize, usize, &'static str)> = ranges![
177- partition_w128, partition_w64, partition_w32, txfm_partition, skip, kf_y_mode,
178- uv_mode_no_cfl, uv_mode_cfl, cfl_sign, cfl_alpha, angle_delta, txb_skip_luma_16,
179- txb_skip_luma_8, txb_skip_luma_4, txb_skip_chroma_8, txb_skip_chroma_4, eob_pt_256_luma, eob_pt_64_luma,
180- eob_pt_64_chroma, eob_pt_16_chroma, eob_pt_16_luma, eob_pt_16_luma_class1, eob_pt_64_luma_class1, eob_pt_16_chroma_class1,
181- eob_pt_64_chroma_class1, eob_pt_128_chroma_class1, eob_pt_128_luma_class1, eob_pt_32_chroma_class1, eob_pt_256_luma_class1, eob_pt_256_chroma_class1,
182- eob_pt_512_luma_class1, eob_pt_512_chroma_class1, eob_pt_1024_luma_class1, eob_pt_1024_chroma_class1, eob_pt_32_luma, eob_pt_32_luma_class1,
183- eob_extra_luma_16, eob_extra_luma_8, eob_extra_luma_4, eob_extra_chroma_8, eob_extra_chroma_4, base_luma_16,
184- base_luma_8, base_luma_4, base_chroma_8, base_chroma_4, base_eob_luma_16, base_eob_luma_8,
185- base_eob_luma_4, base_eob_chroma_8, base_eob_chroma_4, br_luma_16, br_luma_8, br_luma_4,
186- br_chroma_8, br_chroma_4, partition_w16, partition_w8, txb_skip_luma_32, txb_skip_luma_64,
187- txb_skip_chroma_16, txb_skip_chroma_32, eob_pt_1024_luma, eob_pt_1024_chroma, eob_pt_256_chroma, eob_pt_512_luma,
188- eob_pt_128_chroma, eob_pt_512_chroma, eob_pt_128_luma, eob_pt_32_chroma, eob_extra_luma_32, eob_extra_luma_64,
189- eob_extra_chroma_16, eob_extra_chroma_32, base_luma_32, base_luma_64, base_chroma_16, base_chroma_32,
190- base_eob_luma_32, base_eob_luma_64, base_eob_chroma_16, base_eob_chroma_32, br_luma_32, br_chroma_16,
191- br_chroma_32, dc_sign_luma, intra_tx_type_16, intra_tx_type_8, intra_tx_type_8_set1, intra_tx_type_4,
192- intra_tx_type_4_set1, inter_tx_type_32, inter_tx_type_16, inter_tx_type_8, inter_tx_type_16_set2, inter_tx_type_8_set1,
193- inter_tx_type_4, inter_tx_type_4_set1, dc_sign_chroma, intra_inter, single_ref, comp_mode,
194- skip_mode, obmc, motion_mode, interintra, interintra_mode, wedge_interintra,
195- compound_type, wedge_idx, inter_compound_mode, comp_ref_type, uni_comp_ref, comp_ref,
196- comp_bwdref, comp_group_idx, compound_idx, y_mode, new_mv, zero_mv,
197- ref_mv, drl_mode, mv_joint, mv_comp, dv_joint, dv_comp,
198- filter_intra, filter_intra_mode, tx_size_cat0, tx_size_cat1, tx_size_cat2, tx_size_cat3,
199- switchable_interp, palette_y_mode, palette_y_size, palette_uv_mode, palette_uv_size, palette_y_color_index,
200- palette_uv_color_index, intrabc, restore_wiener, restore_sgrproj, restore_switchable, segment_id,
201- segment_pred, delta_q, delta_lf, delta_lf_multi
202- ];
203- tables.sort_unstable();
204- with(|s| s.tables = tables);
205-}
206-
207-/// Charges `bits` to whichever CDF table `addr` falls inside.
208-pub(crate) fn charge(addr: usize, bits: f64) {
209- with(|s| {
210- let name = match s.tables.partition_point(|t| t.0 <= addr) {
211- 0 => "unregistered",
212- i if s.tables[i - 1].1 > addr => s.tables[i - 1].2,
213- _ => "unregistered",
214- };
215- let e = cur(s).families.entry(name).or_default();
216- e.0 += 1;
217- e.1 += bits;
218- });
219-}
220-
221-/// Charges raw (equiprobable) bits, which no CDF names.
222-pub(crate) fn charge_literal(bits: u32) {
223- with(|s| {
224- let e = cur(s).families.entry("literal").or_default();
225- e.0 += u64::from(bits);
226- e.1 += f64::from(bits);
227- });
228-}
229-
230-/// One coded block, from the neighbour publisher every block routes through.
231-pub(crate) fn block(w_mi: usize, h_mi: usize, is_inter: bool, ref_frame: i8, skip: bool) {
232- if !armed() {
233- return;
234- }
235- let area = (w_mi * h_mi) as u64;
236- with(|s| {
237- s.last_block_area = area;
238- let f = cur(s);
239- *f.blocks.entry(((w_mi * 4) as u16, (h_mi * 4) as u16)).or_default() += 1;
240- f.area[usize::from(is_inter)] += area;
241- f.refs[(ref_frame.max(0) as usize).min(7)] += area;
242- if skip {
243- f.skip_area += area;
244- }
245- });
246-}
247-
248-/// The block just published is compound (two references) -- called from the
249-/// compound-context publisher, which runs right after [`block`].
250-pub(crate) fn compound() {
251- if !armed() {
252- return;
253- }
254- with(|s| {
255- let area = s.last_block_area;
256- let f = cur(s);
257- f.area[1] = f.area[1].saturating_sub(area);
258- f.area[2] += area;
259- });
260-}
261-
262-/// One block's published luma transform shape.
263-pub(crate) fn tx(w_px: u8, h_px: u8) {
264- if !armed() {
265- return;
266- }
267- with(|s| *cur(s).tx.entry((u16::from(w_px), u16::from(h_px))).or_default() += 1);
268-}
269-
270-/// One coded motion vector (a NEWMV read).
271-pub(crate) fn mv(x: i32, y: i32) {
272- if !armed() {
273- return;
274- }
275- let m = x.abs().max(y.abs());
276- let bucket = match m {
277- 0 => 0,
278- 1..=8 => 1,
279- 9..=32 => 2,
280- 33..=128 => 3,
281- 129..=512 => 4,
282- _ => 5,
283- };
284- with(|s| cur(s).mv[bucket] += 1);
285-}
286-
287-/// One single-ref inter mode decision: 0 NEWMV, 1 GLOBALMV, 2 NEARESTMV,
288-/// 3 NEARMV.
289-pub(crate) fn mode(which: usize) {
290- if !armed() {
291- return;
292- }
293- with(|s| cur(s).modes[which] += 1);
294-}
295-
296-/// One coded `tx_type` symbol, with the CDF row length that names its set.
297-pub(crate) fn tx_type(len: usize, symbol: usize) {
298- if !armed() {
299- return;
300- }
301- with(|s| *cur(s).tx_type.entry((len as u8, symbol as u8)).or_default() += 1);
302-}
303-
304-/// One coded block of an INTRA frame, from the `blk_grid` publisher every
305-/// block writes -- a no-op on an inter frame, where [`block`] (the inter
306-/// neighbour publisher, which knows the reference) counts instead.
307-pub(crate) fn block_intra_frame(w_mi: usize, h_mi: usize, skip: bool) {
308- if !armed() {
309- return;
310- }
311- if with(|s| cur(s).kind == "key") {
312- block(w_mi, h_mi, false, 0, skip);
313- }
314-}
crates/ec-av1/src/decode/block.rsmodified+4 -862
@@ -41,42 +41,16 @@ pub(super) fn read_intra_mode(
4141 Option<PaletteY>,
4242 Option<PaletteUv>,
4343 )> {
44- let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
4544 // lane-tiny r2: EC_ISTEP-format trace (same "name=... val=... rng=..."
4645 // shape the oracle's own `ec_read_intra_frame_mode_info_impl` prints
4746 // under `EC_TRACE_MODE_STEP`) so a range ladder can be diffed line for
4847 // line against the instrumented aomdec, not just `tell()`.
49- crate::msac::SymbolDecoder::set_symr_mi(mi_r as i64, mi_c as i64);
50- let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");
51- if ec_istep {
52- // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line
53- // (decodemv.c:818), printed at the same point: before the first
54- // mode-info symbol of the block, so a cross-decoder range ladder can
55- // be keyed on the BLOCK, not just on the symbol sequence.
56- eprintln!(
57- "EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sq side={side} rng={}",
58- dec.debug_state().0
59- );
60- }
6148 macro_rules! istep {
62- ($name:literal, $val:expr) => {
63- if ec_istep {
64- let (rng, _) = dec.debug_state();
65- eprintln!(
66- "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name={} val={} rng={rng}",
67- $name, $val
68- );
69- }
70- };
49+ ($name:literal, $val:expr) => {};
7150 }
7251 // lane-sbrect10 r1: `is_cfl_allowed`'s <=32 bound, enforced at the single
7352 // point every square caller routes through (see `read_intra_mode_rect`).
74- let cfl = if cfl && side > 32 {
75- hit!(NOCFL_UV_MODE_HITS);
76- false
77- } else {
78- cfl
79- };
53+ let cfl = if cfl && side > 32 { false } else { cfl };
8054 // spec 5.11.6 `intra_frame_mode_info`: `intra_segment_id` is read BEFORE
8155 // `skip` when `SegIdPreSkip`, and after it otherwise.
8256 let (seg_w_mi, seg_h_mi) = (side / 4, side / 4);
@@ -84,13 +58,6 @@ pub(super) fn read_intra_mode(
8458 intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, false, fctx);
8559 }
8660 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
87- if trace {
88- eprintln!(
89- "TRACE skip value={} rng={}",
90- skip as i32,
91- dec.debug_state().0
92- );
93- }
9461 istep!("skip", skip as i32);
9562 if !seg_id_pre_skip(fctx) {
9663 intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, skip, fctx);
@@ -117,23 +84,9 @@ pub(super) fn read_intra_mode(
11784 // that merely allows (but never uses) intrabc.
11885 if allow_intrabc {
11986 let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0;
120- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
121- eprintln!(
122- "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=intrabc val={} rng={}",
123- u8::from(use_intrabc),
124- dec.debug_state().0
125- );
126- }
127- if trace {
128- eprintln!("TRACE use_intrabc value={}", use_intrabc as i32);
129- }
13087 if use_intrabc {
13188 let dv = read_intrabc_dv(dec, cdfs, mi_r, mi_c, (side / MI, side / MI), fctx);
132- if trace {
133- eprintln!("TRACE intrabc dv={dv:?}");
134- }
13589 fctx.intrabc_dv.with(|c| c.set(Some(dv)));
136- hit!(INTRABC_HITS);
13790 // spec 5.11.13 / libaom `read_intra_frame_mode_info` returns the
13891 // moment `is_intrabc_block`: no y/uv mode, angle delta, palette,
13992 // CFL or filter-intra syntax follows. `YMode`/`UVMode` are forced
@@ -145,21 +98,9 @@ pub(super) fn read_intra_mode(
14598 let above_ctx = INTRA_MODE_CTX[above_mode];
14699 let left_ctx = INTRA_MODE_CTX[left_mode];
147100 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
148- if trace {
149- eprintln!(
150- "TRACE y_mode ctx=({above_ctx},{left_ctx}) value={mode} rng={}",
151- dec.debug_state().0
152- );
153- }
154101 istep!("mode", mode as i32);
155102 let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) {
156103 let delta = read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED]);
157- if trace {
158- eprintln!(
159- "TRACE angle_delta value={}",
160- delta + ANGLE_DELTA_ZERO as i32
161- );
162- }
163104 delta
164105 } else {
165106 0
@@ -174,18 +115,10 @@ pub(super) fn read_intra_mode(
174115 let uv_mode = if !has_chroma {
175116 DC_PRED
176117 } else if cfl {
177- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
178118 dec.symbol(&mut cdfs.uv_mode_cfl[mode])
179119 } else {
180- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
181120 dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
182121 };
183- if trace {
184- eprintln!(
185- "TRACE uv_mode cfl={cfl} y_mode={mode} value={uv_mode} rng={}",
186- dec.debug_state().0
187- );
188- }
189122 istep!("uv_mode", uv_mode as i32);
190123 let alpha = if cfl && uv_mode == UV_CFL_PRED {
191124 Some(read_cfl_alphas(dec, cdfs))
@@ -199,24 +132,17 @@ pub(super) fn read_intra_mode(
199132 // 78 against ffmpeg, traced 2026-08-27) -- an existing, un-lane-touched
200133 // bug in that fallback this lane's own scope does not cover. Keep it
201134 // refused here rather than ship a silently-wrong decode.
202- if (9..=12).contains(&uv_mode) {
203- hit!(SMOOTH_UV_HITS);
204- }
205135 // `get_uv_mode` (spec 9.3): `UV_CFL_PRED` predicts as `DC_PRED` for the
206136 // angle-delta question -- libaom's own `read_intra_frame_mode_info` reads
207137 // `angle_delta_uv` off `get_uv_mode(uv_mode)`, never off `uv_mode` raw,
208138 // so a CFL block (uv_mode==13, outside `V_PRED..=D67_PRED`) already takes
209139 // the `else` branch below and never reads one either way.
210140 let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
211- hit!(DIRECTIONAL_UV_HITS);
212141 read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])
213142 } else {
214143 0
215144 };
216145 istep!("angle_uv", angle_delta_uv);
217- if angle_delta_uv != 0 {
218- hit!(UV_ANGLE_DELTA_HITS);
219- }
220146 // `read_palette_mode_info` (spec 5.11.13, libaom decodemv.c:567, called
221147 // at :840 right after `xd->cfl.store_y` and before `read_filter_intra_mode_info`):
222148 // gated by `av1_allow_palette` (blockd.h -- size bound only,
@@ -244,32 +170,11 @@ pub(super) fn read_intra_mode(
244170 let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None;
245171 if allow_screen_content_tools && let Some(bsize_ctx) = palette_bsize_ctx(side) {
246172 let (mode_ctx, cache) = palette.unwrap_or((0, &[]));
247- if mode == DC_PRED && trace {
248- let (rng, _) = dec.debug_state();
249- eprintln!(
250- "TRACE pre_palette_y_mode bsize_ctx={bsize_ctx} mode_ctx={mode_ctx} rng={rng}"
251- );
252- }
253173 let use_palette_y =
254174 mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][mode_ctx]) != 0;
255- if mode == DC_PRED && trace {
256- let (rng, _) = dec.debug_state();
257- eprintln!(
258- "TRACE palette_y_mode value={} rng={rng}",
259- use_palette_y as i32
260- );
261- }
262175 if use_palette_y {
263176 let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]);
264- if trace {
265- let (rng, _) = dec.debug_state();
266- eprintln!("TRACE palette_y_size n={n} rng={rng}");
267- }
268177 let colors = read_palette_colors_y(dec, n, cache, fctx);
269- if trace {
270- let (rng, _) = dec.debug_state();
271- eprintln!("TRACE palette_y_colors colors={:?} rng={rng}", &colors[..n]);
272- }
273178 palette_y_pending = Some((n, colors));
274179 }
275180 // `read_palette_mode_info`'s UV half (decodemv.c:588): read
@@ -313,20 +218,9 @@ pub(super) fn read_intra_mode(
313218 && let Some(class) = filter_intra_size_class(side)
314219 {
315220 let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0;
316- if trace {
317- eprintln!(
318- "TRACE use_filter_intra side={side} rng={} value={}",
319- dec.debug_state().0,
320- use_filter_intra as i32
321- );
322- }
323221 istep!("use_filter_intra", use_filter_intra as i32);
324222 if use_filter_intra {
325- hit!(FILTER_INTRA_HITS);
326223 let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode);
327- if trace {
328- eprintln!("TRACE filter_intra_mode value={fi_mode}");
329- }
330224 istep!("filter_intra_mode", fi_mode as i32);
331225 filter_intra = Some(fi_mode);
332226 }
@@ -342,10 +236,6 @@ pub(super) fn read_intra_mode(
342236 palette_onscreen(mi_r, mi_c, side, side, fctx),
343237 false,
344238 );
345- hit!(PALETTE_HITS);
346- if trace {
347- eprintln!("TRACE palette_y size={n} colors={:?}", &colors[..n]);
348- }
349239 PaletteY {
350240 size: n,
351241 colors,
@@ -372,14 +262,6 @@ pub(super) fn read_intra_mode(
372262 on,
373263 true,
374264 );
375- hit!(PALETTE_UV_HITS);
376- if trace {
377- eprintln!(
378- "TRACE palette_uv size={n} u_colors={:?} v_colors={:?}",
379- &u_colors[..n],
380- &v_colors[..n]
381- );
382- }
383265 PaletteUv {
384266 size: n,
385267 u_colors,
@@ -412,7 +294,6 @@ pub(super) const UV_CFL_PRED: usize = 13;
412294 /// joint sign the same way. Returns each plane's final signed `alpha_q3`
413295 /// (`cfl_idx_to_alpha`, cfl.c): magnitude `idx + 1`, sign-zero collapsing to 0.
414296 pub(super) fn read_cfl_alphas(dec: &mut SymbolDecoder, cdfs: &mut Cdfs) -> (i32, i32) {
415- hit!(CFL_BLOCK_HITS);
416297 let joint_sign = dec.symbol(&mut cdfs.cfl_sign) as i32;
417298 let sign_u = ((joint_sign + 1) * 11) >> 5;
418299 let sign_v = (joint_sign + 1) - 3 * sign_u;
@@ -461,7 +342,6 @@ pub(super) fn cfl_ac_ss(
461342 ss_y: usize,
462343 ) -> Vec<i32> {
463344 if ss_x == 0 && ss_y == 0 {
464- hit!(CFL_AC_444_HITS);
465345 let mut ac = vec![0i32; bw * bh];
466346 let mut sum = 0i32;
467347 for row in 0..bh {
@@ -476,12 +356,6 @@ pub(super) fn cfl_ac_ss(
476356 ac.iter_mut().for_each(|v| *v -= avg);
477357 ac
478358 } else if ss_x == 1 && ss_y == 0 {
479- // lane-av1-422: `cfl_luma_subsampling_422_lbd_c` -- each chroma sample
480- // averages the HORIZONTAL luma pair above it, at full chroma height
481- // (`(a + b) >> 1` in Q3 is `(a + b) << 2`). A rect luma strip's chroma
482- // is square here, and the 4:2:0 rect/square helpers below would halve
483- // the height it must keep.
484- hit!(CFL_AC_422_HITS);
485359 let (cw, ch) = (bw >> 1, bh);
486360 let mut ac = vec![0i32; cw * ch];
487361 let mut sum = 0i32;
@@ -500,10 +374,8 @@ pub(super) fn cfl_ac_ss(
500374 ac.iter_mut().for_each(|v| *v -= avg);
501375 ac
502376 } else if bw == bh {
503- hit!(CFL_AC_420_SQ_HITS);
504377 cfl_ac_q3(y, px, py, bw)
505378 } else {
506- hit!(CFL_AC_420_RECT_HITS);
507379 cfl_ac_q3_rect(y, px, py, bw, bh)
508380 }
509381 }
@@ -515,10 +387,6 @@ pub(crate) fn cfl_ac_q3_at(
515387 bh: usize,
516388 sample: impl Fn(usize, usize) -> i32,
517389 ) -> Vec<i32> {
518- hit!(CFL_AC_Q3_AT_HITS);
519- if crate::envflags::env_flag!("EC_HALVSWEEP") {
520- eprintln!("EC_HALV cfl_ac_q3_at px={px} py={py} bw={bw} bh={bh}");
521- }
522390 let (cw, ch) = (bw / 2, bh / 2);
523391 let mut ac = vec![0i32; cw * ch];
524392 let mut sum = 0i32;
@@ -550,275 +418,6 @@ pub(crate) fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 {
550418 }
551419 }
552420
553-/// One plane's reconstruction buffer, `width * height` samples, and the
554-/// prediction/residual reads and writes into it — the decode-side twin of
555-/// [`crate::encode`]'s private `Plane`, whose `edges` this mirrors exactly
556-/// (own-edge and reach clamps both), passing what it gathers straight to
557-/// [`crate::intra::predict`] instead of hand-rolling `DC_PRED` alone.
558-/// lane-tiny r4: raw padded-plane dump for filter-stage bisection, written
559-/// only when `var` names a path. Same byte shape as `EC_AV1_PREFILT_DUMP`.
560-/// lane-hgkf r2: 16-bit cropped stage dump, the high-bitdepth twin of
561-/// [`dump_stage`] (whose `as u8` truncation hides |delta| <= 2 defects).
562-/// lane-unwritten-dep: this doc previously said the dump "matches aomdec's own
563-/// `ec_dump16` rung byte for byte (crop dims, u16 LE)", which was true only of
564-/// the 4:2:0 crop it then used. The crop is now PER-AXIS, which is what the
565-/// oracle's rung 1 actually does -- it writes `y_crop_width` x `y_crop_height`,
566-/// `uv_crop_width` x `uv_crop_height`, `uv_crop_width` x `uv_crop_height` (the
567-/// libaom `YV12_BUFFER_CONFIG` fields, each already per-axis). Byte shape per
568-/// subsampling, `fw x fh` luma then both chroma planes, u16 LE, so:
569-///
570-/// ```text
571-/// ss_x ss_y format luma chroma (each)
572-/// 0 0 4:4:4 fw x fh fw x fh fw*fh*3 samples
573-/// 1 1 4:2:0 fw x fh fw/2 x fh/2 fw*fh*3/2 samples
574-/// 1 0 4:2:2 fw x fh fw/2 x fh fw*fh*2 samples
575-/// 0 1 4:4:0 fw x fh fw x fh/2 fw*fh*3/2 samples
576-/// ```
577-///
578-/// (`round_ss` is the rounding the decoder's own plane extents use; at ss = 1 it
579-/// is `div_ceil(2)`, so every 4:2:0 dump is byte-for-byte unchanged by this.)
580-/// lane-mc64 r1: the file name is keyed on [`dump_stage_idx`], a per-var
581-/// decode-order counter -- both dumps used to write `.f0` unconditionally, so
582-/// every frame overwrote the previous one and only the LAST frame survived,
583-/// which silently defeats any per-frame filter-stage bisection (ledger, class
584-/// stale-output-faked-measurement). A sibling accessor `stage_dump_idx()`, which
585-/// derived the same number from `PREFILT_PICTURE_IDX`, had no caller and was
586-/// deleted: `PREFILT_PICTURE_IDX` is bumped after this point, not before it, so
587-/// the counter that names these files is the per-var map.
588-// Signature mirrors the spec's per-call inputs; a parameter struct would only move them.
589-#[allow(clippy::too_many_arguments)]
590-pub(super) fn dump_stage16(
591- var: &str,
592- y: &PlaneBuf<'_>,
593- u: &PlaneBuf<'_>,
594- v: &PlaneBuf<'_>,
595- fw: usize,
596- fh: usize,
597- ss_x: usize,
598- ss_y: usize,
599-) {
600- // lane-sbrect10 r2 / lane-cdef r1 (one shared helper): index the dump by
601- // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed
602- // `.f0` name kept only the LAST frame, so a mid-sequence divergence could
603- // not be read at all.
604- //
605- // lane-unwritten-dep: the chroma extent is PER-AXIS subsampling, not
606- // `div_ceil(2)` on both. The hardcoded pair was a 4:2:0 assumption and it
607- // was load-bearing: on a 64x64 4:2:2 frame (ss_x = 1, ss_y = 0) it wrote
608- // 32x32 chroma per plane where the frame carries 32x64, so HALF of each
609- // chroma plane appeared in NO stage dump at all. A stage bisect that reads
610- // "identical pre-deblock, differs post-deblock" off these dumps is then
611- // measuring the dump's blind spot, not the pipeline's: the samples it could
612- // not see are exactly the region where the 4:2:2 witness's output diverges
613- // (chroma rows 32..63 -- the old `fh.div_ceil(2)` crop wrote 32 of 64 rows,
614- // so everything from row 32 up was invisible; 2048 samples). `round_ss` is
615- // the same rounding the
616- // decoder's own plane extents use, and it matches the oracle's
617- // `uv_crop_width` / `uv_crop_height` per axis.
618- //
619- // ONE file per frame: `dump_stage_idx` advances on every call, so creating
620- // the file inside the plane loop would write three files per frame and
621- // shift every later frame's index.
622- //
623- // lane-av1dumploud: this used to be `let _ = f.write_all(&bytes)` per row, so
624- // a full filesystem left a SHORT file that no reader could tell from a
625- // complete one. `LoudDump` is given the exact expected length this function
626- // knows -- `(fw*fh + 2*cw*ch) * 2`, u16 LE -- and checks it against the file
627- // on disk; a shortfall aborts the decode instead of leaving a plausible
628- // artefact behind.
629- if let Ok(path) = crate::envflags::var(var) {
630- let cw = round_ss(fw, ss_x);
631- let ch = round_ss(fh, ss_y);
632- let expected = (fw * fh + 2 * cw * ch) * 2;
633- let mut d = crate::dumpio::LoudDump::create(
634- var,
635- format!("{path}.f{}", dump_stage_idx(var)),
636- expected,
637- );
638- for (p, w, h) in [(y, fw, fh), (u, cw, ch), (v, cw, ch)] {
639- for row in 0..h {
640- let mut bytes = Vec::with_capacity(w * 2);
641- for &s in &p.data[row * p.width..][..w] {
642- bytes.extend_from_slice(&s.to_le_bytes());
643- }
644- d.write(&bytes);
645- }
646- }
647- d.finish();
648- }
649-}
650-
651-/// Decode-order index of the next [`dump_stage`]/[`dump_stage16`] file for a
652-/// given env var -- lane-cdef r1: both used to write `.f0` unconditionally, so
653-/// every frame overwrote the previous one and only the LAST frame survived,
654-/// which silently defeats any per-frame filter-stage bisection.
655-fn dump_stage_idx(var: &str) -> usize {
656- use std::collections::HashMap;
657- use std::sync::{Mutex, OnceLock};
658- static IDX: OnceLock<Mutex<HashMap<String, usize>>> = OnceLock::new();
659- let mut m = IDX
660- .get_or_init(|| Mutex::new(HashMap::new()))
661- .lock()
662- .unwrap();
663- let e = m.entry(var.to_string()).or_insert(0);
664- let i = *e;
665- *e += 1;
666- i
667-}
668-
669-pub(super) fn dump_stage(var: &str, y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) {
670- // lane-av1dumploud: loud on a short write (see [`crate::dumpio::LoudDump`]).
671- // The expected length is the three planes' own data lengths -- the writer
672- // iterates exactly `p.data`, so this is the same extent, not a re-derivation
673- // that could disagree with it.
674- if let Ok(path) = crate::envflags::var(var) {
675- let narrow = |p: &PlaneBuf<'_>| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };
676- crate::dumpio::write_planes(
677- var,
678- format!("{path}.f{}", dump_stage_idx(var)),
679- &[&narrow(y), &narrow(u), &narrow(v)],
680- );
681- }
682-}
683-
684-/// `EC_AV1_PREFILT_WIDE_DUMP=<prefix>` -> `<prefix>.f<N>`, the pre-loop-filter
685-/// reconstruction cropped to each plane's mi-ALIGNED true extent, byte for
686-/// byte the shape aomdec's own rung 7 writes (`y_width`/`y_height`,
687-/// `uv_width`/`uv_height`), so the two can be diffed directly.
688-///
689-/// lane-av1444edge: this used to be an inline block in the KEY-frame tile path
690-/// only, with a FUNCTION-LOCAL `static IDX2` as its counter. Both facts were
691-/// measurement traps, and the second one is why the first went unnoticed:
692-/// the inter-frame path (`decode_inter_frame_tile_with_cdfs`) had no wide
693-/// prefilter dump at all, so every 4:4:4 lossy divergence localized to an
694-/// inter frame had no pre-filter rung to compare against and got attributed to
695-/// reconstruction when the oracle could not see it. The `static` also restarted
696-/// per monomorphisation, so every frame after the first overwrote `.f0` -- a
697-/// per-frame bisection silently compared the LAST decoded frame. The counter
698-/// is now the shared per-var [`dump_stage_idx`] map, and the call also sits on
699-/// the inter path (skipped when the filter pipeline is active, which has
700-/// already deblocked by the time the tile tail runs -- same condition
701-/// `capture_filter_replay` guards itself with).
702-pub(super) fn dump_prefilter_wide(y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) {
703- let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_WIDE_DUMP") else {
704- return;
705- };
706- // lane-av1dumploud: loud on a short write. Expected length is
707- // `sum(true_width * true_height)` over the three planes -- the crop the
708- // writer itself builds, so the check cannot disagree with the bytes.
709- let idx = dump_stage_idx("EC_AV1_PREFILT_WIDE_DUMP");
710- let crop = |plane: &PlaneBuf<'_>| -> Vec<u8> {
711- let mut out = Vec::with_capacity(plane.true_width * plane.true_height);
712- for row in 0..plane.true_height {
713- out.extend(
714- plane.data[row * plane.width..][..plane.true_width]
715- .iter()
716- .map(|&s| s as u8),
717- );
718- }
719- out
720- };
721- let (cy, cu, cv) = (crop(y), crop(u), crop(v));
722- crate::dumpio::write_planes(
723- "EC_AV1_PREFILT_WIDE_DUMP",
724- format!("{path}.f{idx}"),
725- &[&cy, &cu, &cv],
726- );
727-}
728-
729-/// Unwritten samples [`census_unwritten`] has counted since the last
730-/// [`take_unwritten_samples`] -- process-global (not thread-local) because the
731-/// gate reads it after the decode, from a different thread than the one that
732-/// scanned the plane.
733-pub(super) static UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize =
734- std::sync::atomic::AtomicUsize::new(0);
735-
736-/// Turns [`PLANE_SENTINEL`] filling on for the CALLING thread, independently
737-/// of `EC_AV1_PLANE_SENTINEL`. A gate cannot set a process-constant env var
738-/// (see [`crate::envflags`]), and the census is the only honest way to ask
739-/// "did the tile walk write every sample it was handed" -- a wrong-sample diff
740-/// cannot tell an unwritten sample from a mis-predicted one.
741-pub fn set_plane_sentinel(on: bool) {
742- PLANE_SENTINEL_ON.with(|c| c.set(on));
743-}
744-
745-/// Reads and clears [`UNWRITTEN_SAMPLES`]: the number of samples the decode
746-/// just handed to the tile walk never wrote, summed over every frame and
747-/// plane. Zero is the only acceptable answer for a decoder whose output must
748-/// not depend on its allocator.
749-pub fn take_unwritten_samples() -> usize {
750- UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst)
751-}
752-
753-/// Samples in the PADDED TAIL -- every sample of each plane outside its own
754-/// `true_width` x `true_height` extent -- that still holds [`plane_poison`] at
755-/// the pre-deblock point. [`census_unwritten`] scans that region too, because
756-/// "past the true extent nothing is ever read" was an ASSUMPTION the tail's
757-/// census was built to avoid checking; this counter is the measurement.
758-pub(super) static PAD_UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize =
759- std::sync::atomic::AtomicUsize::new(0);
760-
761-/// Reads and clears [`PAD_UNWRITTEN_SAMPLES`].
762-pub fn take_pad_unwritten_samples() -> usize {
763- PAD_UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst)
764-}
765-
766-/// The largest value reconstruction can produce, `(1 << 12) - 1`: the highest
767-/// bit depth this decoder carries is 12. A sentinel at or below this could be
768-/// a LEGAL sample, which would make the whole census vacuous -- every
769-/// unwritten sample would look like an ordinary one.
770-pub(super) const MAX_LEGAL_SAMPLE: u16 = 4095;
771-
772-/// The value [`fresh_plane`] fills with when the sentinel is on.
773-///
774-/// [`PLANE_SENTINEL`] unless `EC_AV1_PLANE_SENTINEL` names a different one in
775-/// hex. Two different poisons are what turns the sentinel from "did a hole
776-/// survive into the output" into "did the output depend on the buffer's
777-/// initial content": a hole whose value reaches the picture changes the hash
778-/// when the poison changes, and one that does not cannot have influenced
779-/// anything. A value at or below [`MAX_LEGAL_SAMPLE`] is REFUSED (falls back
780-/// to [`PLANE_SENTINEL`]) because the census's soundness rests on the sentinel
781-/// being impossible. `EC_AV1_PLANE_SENTINEL=1` -- the spelling every existing
782-/// caller and gate uses, and `env_flag!`'s mere presence test -- keeps
783-/// [`PLANE_SENTINEL`].
784-/// `pub(crate)` for lane-av1graincensus: `film_grain::uninit_plane` fills its
785-/// destination with the SAME poison `fresh_plane` does, and
786-/// [`census_unwritten_grained`] counts the same value. The fill and the census
787-/// must agree on both the value and the predicate, or a "0" means nothing.
788-pub(crate) fn plane_poison() -> u16 {
789- static V: std::sync::LazyLock<u16> = std::sync::LazyLock::new(|| {
790- let Ok(raw) = crate::envflags::var("EC_AV1_PLANE_SENTINEL") else {
791- return PLANE_SENTINEL;
792- };
793- let t = raw.trim();
794- if t.is_empty() || t == "1" {
795- return PLANE_SENTINEL;
796- }
797- let hex = t
798- .strip_prefix("0x")
799- .or_else(|| t.strip_prefix("0X"))
800- .unwrap_or(t);
801- match u16::from_str_radix(hex, 16) {
802- Ok(v) if v > MAX_LEGAL_SAMPLE => v,
803- _ => PLANE_SENTINEL,
804- }
805- });
806- *V
807-}
808-
809-thread_local! {
810- /// The [`set_plane_sentinel`] override; `EC_AV1_PLANE_SENTINEL` is the
811- /// process-wide default.
812- static PLANE_SENTINEL_ON: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
813-}
814-
815-/// Whether freshly allocated planes are [`PLANE_SENTINEL`]-filled.
816-/// `pub(crate)` for the same reason as [`plane_poison`].
817-pub(crate) fn plane_sentinel_on() -> bool {
818- crate::envflags::env_flag!("EC_AV1_PLANE_SENTINEL")
819- || PLANE_SENTINEL_ON.with(std::cell::Cell::get)
820-}
821-
822421 /// lane-av1unwritten: whether a subsize has a chroma PLANE BLOCK at this
823422 /// frame's subsampling -- libaom `av1_ss_size_lookup[bsize][ss_x][ss_y] !=
824423 /// BLOCK_INVALID` (`common_data.c`), which `decode_partition` checks on every
@@ -990,26 +589,6 @@ pub(super) fn refuse_invalid_subsize(
990589 part: usize,
991590 fctx: &crate::decode::FrameCtx,
992591 ) -> Result<()> {
993- // lane-av1unwritten r6: the coverage artefact. A guard that sits INSIDE a
994- // `PARTITION_HORZ_A..=PARTITION_VERT_B` arm can only ever observe 4..=7, so
995- // "the guard is present" is not evidence that an offending value is caught --
996- // which is exactly how r5's three misplaced guards read as coverage. This
997- // records, per CALL SITE and per partition value, how often the guard was
998- // reached and how often it fired, so a site that never sees an offending
999- // value is visible instead of assumed covered.
1000- if crate::envflags::env_flag!("EC_AV1_SUBSIZE_GUARD_TRACE") {
1001- note_subsize_guard(
1002- std::panic::Location::caller(),
1003- bsize,
1004- part,
1005- chroma_plane_block_codable(
1006- partition_subsize_dims(bsize, part).0,
1007- partition_subsize_dims(bsize, part).1,
1008- ss_x(fctx),
1009- ss_y(fctx),
1010- ),
1011- );
1012- }
1013592 let (bw, bh) = partition_subsize_dims(bsize, part);
1014593 if chroma_plane_block_codable(bw, bh, ss_x(fctx), ss_y(fctx)) {
1015594 Ok(())
@@ -1018,88 +597,6 @@ pub(super) fn refuse_invalid_subsize(
1018597 }
1019598 }
1020599
1021-/// lane-av1unwritten r6: the OTHER half of the coverage artefact. The guard
1022-/// table says what the guards see; this says what each DISPATCH ARM sees, so a
1023-/// dispatch reached with an offending partition value and no guard above it is a
1024-/// visible hole rather than an absence nobody noticed. `decode_probe` calls
1025-/// [`dump_subsize_arm_scan`] at exit under `EC_AV1_SUBSIZE_ARM_TRACE`.
1026-pub(super) static SUBSIZE_ARM: std::sync::LazyLock<
1027- std::sync::Mutex<std::collections::BTreeMap<(&'static str, usize), usize>>,
1028-> = std::sync::LazyLock::new(|| std::sync::Mutex::new(Default::default()));
1029-
1030-#[track_caller]
1031-pub(crate) fn note_subsize_arm(part: usize, codable: bool) {
1032- if !crate::envflags::env_flag!("EC_AV1_SUBSIZE_ARM_TRACE") {
1033- return;
1034- }
1035- let site = std::panic::Location::caller();
1036- let key = (
1037- format!("{}:{}", site.file(), site.line()).leak() as &'static str,
1038- part * 2 + usize::from(codable),
1039- );
1040- if let Ok(mut m) = SUBSIZE_ARM.lock() {
1041- *m.entry(key).or_insert(0) += 1;
1042- }
1043-}
1044-
1045-/// Prints and clears the [`note_subsize_arm`] table.
1046-pub fn dump_subsize_arm_scan() {
1047- let Ok(mut m) = SUBSIZE_ARM.lock() else {
1048- return;
1049- };
1050- for ((site, k), n) in m.iter() {
1051- eprintln!(
1052- "SUBSIZE_ARM site={site} part={} codable={} reached={n}",
1053- k / 2,
1054- if k % 2 == 1 { "true" } else { "false" },
1055- );
1056- }
1057- m.clear();
1058-}
1059-
1060-/// Per-site, per-value counters for [`refuse_invalid_subsize`], plus the dump
1061-/// that makes the reach/guard split readable. `EC_AV1_SUBSIZE_GUARD_TRACE`
1062-/// records; `dump_subsize_guard_scan` prints (and clears) the table.
1063-pub(super) static SUBSIZE_GUARD: std::sync::LazyLock<
1064- std::sync::Mutex<std::collections::BTreeMap<(&'static str, usize, usize, bool), usize>>,
1065-> = std::sync::LazyLock::new(|| std::sync::Mutex::new(Default::default()));
1066-
1067-fn note_subsize_guard(
1068- site: &'static std::panic::Location<'static>,
1069- bsize: (usize, usize),
1070- part: usize,
1071- codable: bool,
1072-) {
1073- let key = (
1074- format!("{}:{}", site.file(), site.line()).leak() as &'static str,
1075- bsize.0 * 256 + bsize.1,
1076- part,
1077- codable,
1078- );
1079- if let Ok(mut m) = SUBSIZE_GUARD.lock() {
1080- *m.entry(key).or_insert(0) += 1;
1081- }
1082-}
1083-
1084-/// Prints and clears the [`refuse_invalid_subsize`] table: one line per
1085-/// (site, block, partition value) with the times reached and whether the guard
1086-/// fired. `decode_probe` calls this at exit.
1087-pub fn dump_subsize_guard_scan() {
1088- let Ok(mut m) = SUBSIZE_GUARD.lock() else {
1089- return;
1090- };
1091- for ((site, bsize, part, codable), n) in m.iter() {
1092- eprintln!(
1093- "SUBSIZE_GUARD site={site} bsize={}x{} part={part} codable={codable} \
1094- reached={n}{}",
1095- bsize / 256,
1096- bsize % 256,
1097- if *codable { "" } else { " FIRED" },
1098- );
1099- }
1100- m.clear();
1101-}
1102-
1103600 /// [`chroma_plane_block_codable`] as libaom's refusal: a returned error naming
1104601 /// the shape and the subsampling mode, never an `assert!` -- a partition symbol
1105602 /// is stream data, so a hostile file can reach it.
@@ -1115,84 +612,8 @@ pub(super) fn refuse_invalid_plane_block(
1115612 )
1116613 }
1117614
1118-/// The value [`fresh_plane`] fills with under `EC_AV1_PLANE_SENTINEL`: no
1119-/// legal sample can equal it (reconstruction clamps to `(1 << bit_depth) - 1`,
1120-/// at most 4095), so a decode that hashes identically under the flag proves
1121-/// the output does not depend on the plane buffer's initial content.
1122-pub(super) const PLANE_SENTINEL: u16 = 0xDEAD;
1123-
1124-/// lane-unwritten-dep: the census count at the LAST point of the pipeline, on the
1125-/// exact bytes `EC_AV1_FINAL_DUMP` writes.
1126-///
1127-/// WHY A SECOND COUNT, and what it is actually for -- the justification this
1128-/// comment originally carried was WRONG and is corrected here, because a reader
1129-/// would otherwise re-derive the wrong conclusion. An earlier revision of this
1130-/// lane claimed the pre-deblock plane was byte-identical plain-vs-sentinel and
1131-/// that "deblock creates the dependence". That reading came from
1132-/// [`dump_stage16`], which cropped chroma as `(fw/2, fh/2)` -- a 4:2:0
1133-/// assumption. On a 64x64 4:2:2 frame (ss_x=1, ss_y=0) that wrote 32x32 chroma
1134-/// where the frame carries 32x64, so 2048 chroma samples appeared in NO stage
1135-/// dump, and they are exactly the region where the difference lives.
1136-///
1137-/// With per-axis extents the corrected measurement on `440_request_is_422` is:
1138-/// the PRE-DEBLOCK dump already DIFFERS by 2158 bytes plain-vs-sentinel, and an
1139-/// exact u16 whole-plane census finds 224 unwritten samples (U 112, V 112,
1140-/// rows 36..63, whole 4x4 groups) -- the same number
1141-/// `lanes/av1unwritten.report.md` reports. **The hole is present before any
1142-/// filter runs, and the pre-deblock census sees it.** This comment previously
1143-/// said the opposite; that was the instrument's blind spot read as a property of
1144-/// the pipeline.
1145-///
1146-/// So what this second count is FOR, stated honestly: it is not there because the
1147-/// pre-deblock census misses holes. It is there because it is the measurement
1148-/// taken where the OUTPUT is taken -- the bytes stored into the reference slots
1149-/// and handed to the caller. A hole can be created after reconstruction (a
1150-/// filter stage, a superres step, a second pass) and be invisible to a scan taken
1151-/// before it; this one cannot. It is a check on the whole span from the tile walk
1152-/// to the caller's frame, not a claim that the pre-deblock scan is insufficient.
1153-pub(super) static FINAL_UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize =
1154- std::sync::atomic::AtomicUsize::new(0);
1155-
1156-/// lane-unwritten-dep: reads and clears [`FINAL_UNWRITTEN_SAMPLES`] -- unwritten
1157-/// samples still present in the frame as handed to the caller, summed over every
1158-/// frame and plane. Process-global, like the pre-deblock census's counter, so a
1159-/// gate can read it after the decode from a different thread than the one that
1160-/// scanned.
1161-pub fn take_final_unwritten_samples() -> usize {
1162- FINAL_UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst)
1163-}
1164-
1165-/// lane-av1graincensus: samples still holding the poison after film grain, over
1166-/// the picture [`crate::film_grain::apply_grain`] RETURNS -- i.e. the picture the
1167-/// caller receives on a grained frame.
1168-pub(super) static GRAINED_UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize =
1169- std::sync::atomic::AtomicUsize::new(0);
1170-
1171-/// Reads and clears [`GRAINED_UNWRITTEN_SAMPLES`].
1172-pub fn take_grained_unwritten_samples() -> usize {
1173- GRAINED_UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst)
1174-}
1175-
1176615 /// A frame plane's own backing store, `n` samples, zero-filled.
1177-///
1178-/// The `true_width`/`true_height`/`width`/`height` arguments are kept for the
1179-/// call sites' shape and the sentinel's poison fill; the zero fill itself reads
1180-/// none of them. The former `EC_AV1_PLANE_ALLOC=uninit|padzero|extzero` arms
1181-/// (uninitialised allocation for memcheck census) are gone: they needed
1182-/// `set_len` over uninitialised memory, which the crate no longer contains. The
1183-/// shipped default was already the zeroed arm (`lanes/av1uballoc.report.md` §1);
1184-/// the poison sentinel (`EC_AV1_PLANE_SENTINEL`) still catches any read of the
1185-/// initial content.
1186-pub(super) fn fresh_plane(
1187- n: usize,
1188- _true_width: usize,
1189- _true_height: usize,
1190- _width: usize,
1191- _height: usize,
1192-) -> Vec<u16> {
1193- if plane_sentinel_on() {
1194- return vec![plane_poison(); n];
1195- }
616+pub(super) fn fresh_plane(n: usize) -> Vec<u16> {
1196617 vec![0u16; n]
1197618 }
1198619
@@ -1227,52 +648,6 @@ pub(super) struct PlaneBuf<'a> {
1227648 pub(super) plane: u8,
1228649 }
1229650
1230-/// One entry per `MV_REFERENCE_FRAME` (index 0/1 unused -- `NONE`/
1231-/// `INTRA_FRAME`/`LAST_FRAME` all resolve elsewhere), `Some` when this
1232-/// frame's own `ref_frame_idx` names a DPB slot that has a picture in it
1233-/// (lane-av1refs: the same "empty slot" case `GOLDEN_FRAME` already
1234-/// refused by name, now generic across `LAST2`/`LAST3`/`GOLDEN`/`BWDREF`/
1235-/// `ALTREF2`/`ALTREF`).
1236-// lane-av1pixprobe: env-gated one-sample write probe -- `EC_AV1_PIXPROBE=x,y`
1237-// prints one PIXWRITE line per reconstruction store landing on that sample,
1238-// naming the store site, the value it replaces and the one it leaves. Re-anchored
1239-// from `lane-av1-ibcwrite` @ 25f5c729 onto the main-shape sites (the two mc stores
1240-// now live in `reconstruct_mc_rect`).
1241-pub(super) static PIXPROBE_ON: std::sync::LazyLock<bool> =
1242- std::sync::LazyLock::new(|| std::env::var_os("EC_AV1_PIXPROBE").is_some());
1243-
1244-pub(super) static PIXPROBE: std::sync::LazyLock<Option<(usize, usize)>> =
1245- std::sync::LazyLock::new(|| {
1246- crate::envflags::var("EC_AV1_PIXPROBE").ok().and_then(|v| {
1247- let (x, y) = v.split_once(',')?;
1248- Some((
1249- x.trim().parse::<usize>().ok()?,
1250- y.trim().parse::<usize>().ok()?,
1251- ))
1252- })
1253- });
1254-
1255-#[inline]
1256-// Signature mirrors the spec's per-call inputs; a parameter struct would only move them.
1257-#[allow(clippy::too_many_arguments)]
1258-pub(super) fn pix_write(
1259- site: &str,
1260- bx: usize,
1261- by: usize,
1262- bside: usize,
1263- x: usize,
1264- y: usize,
1265- prev: u16,
1266- val: u16,
1267-) {
1268- if *PIXPROBE_ON && Some((x, y)) == *PIXPROBE {
1269- eprintln!(
1270- "PIXWRITE {site} block=({bx},{by})+{bside} px=({x},{y}) prev={prev} val={val} at {}",
1271- std::panic::Location::caller()
1272- );
1273- }
1274-}
1275-
1276651 impl PlaneBuf<'_> {
1277652 /// Sets this plane's own tile pixel origin ([`Self::tile_x0`]/
1278653 /// [`Self::tile_y0`]) before that tile's own superblock walk. `x0`/`y0`
@@ -1356,12 +731,6 @@ impl PlaneBuf<'_> {
1356731 });
1357732 let corner =
1358733 (x > self.tile_x0 && y > self.tile_y0).then(|| self.data[(y - 1) * self.width + x - 1]);
1359- if matches!((bw, bh), (16, 8) | (8, 16)) {
1360- hit!(RECT_STRIP_PRED_HITS);
1361- if across > own_across || down > own_down {
1362- hit!(RECT_STRIP_REACH_HITS);
1363- }
1364- }
1365734 (above, left, corner)
1366735 }
1367736
@@ -1398,18 +767,6 @@ impl PlaneBuf<'_> {
1398767 buf
1399768 } else {
1400769 let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);
1401- if crate::envflags::env_flag!("EC_DEBUG_EDGES") {
1402- eprintln!(
1403- "EDGES x={x} y={y} bw={bw} bh={bh} mode={mode} above={:?} left_len={:?} left0={:?} corner={corner:?} tx0={} ty0={} truew={} trueh={}",
1404- above.as_ref().map(|a| (a.len(), a[0])),
1405- left.as_ref().map(|l| l.len()),
1406- left.as_ref().map(|l| l[0]),
1407- self.tile_x0,
1408- self.tile_y0,
1409- self.true_width,
1410- self.true_height
1411- );
1412- }
1413770 let mut prediction = vec![0u16; bw * bh];
1414771 if let Some(fi_mode) = filter_intra {
1415772 crate::intra::predict_filter_intra(
@@ -1442,25 +799,7 @@ impl PlaneBuf<'_> {
1442799 };
1443800 // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's
1444801 // EC_PRED/EC_PREDND rungs (x/y are this plane's pixel origin).
1445- if crate::envflags::env_flag!("EC_PRED") {
1446- let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum();
1447- let row0: Vec<u16> = prediction[..bw.min(8)].to_vec();
1448- let col0: Vec<u16> = (0..bh.min(8)).map(|r| prediction[r * bw]).collect();
1449- eprintln!(
1450- "@{} OUR_PRED x={x} y={y} plane={} bw={bw} bh={bh} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}",
1451- std::panic::Location::caller(),
1452- recon_plane(),
1453- i32::from(smooth_neighbor)
1454- );
1455- }
1456802 let residual = dense_residual(residual, bw * bh);
1457- if crate::envflags::env_flag!("EC_DBG192") && y == 168 && (x == 224 || x == 232) {
1458- let res0: Vec<i32> = residual[..bw.min(8)].to_vec();
1459- let pred0: Vec<u16> = prediction[..bw.min(8)].to_vec();
1460- eprintln!(
1461- "DBG192 rect x={x} y={y} bw={bw} bh={bh} mode={mode} pred0={pred0:?} res0={res0:?}"
1462- );
1463- }
1464803 for row in 0..bh {
1465804 // Same bottom/right frame-edge clip as [`Self::reconstruct`]'s
1466805 // (lane-sb128c r8) -- a 64x128 block at the right edge of a frame
@@ -1481,16 +820,6 @@ impl PlaneBuf<'_> {
1481820 base = (base + cfl_scaled(alpha_q3, ac)).clamp(0, sample_max(fctx));
1482821 }
1483822 let sample = (base + residual[idx]).clamp(0, sample_max(fctx)) as u16;
1484- pix_write(
1485- "reconstruct_rect",
1486- x,
1487- y,
1488- bw,
1489- x + col,
1490- y + row,
1491- self.data[(y + row) * self.width + x + col],
1492- sample,
1493- );
1494823 self.data.to_mut()[(y + row) * self.width + x + col] = sample;
1495824 }
1496825 }
@@ -1498,15 +827,6 @@ impl PlaneBuf<'_> {
1498827 // -- a block whose prediction matches the oracle's but whose written
1499828 // samples do not is either a residual defect or a later overwrite, and
1500829 // only this print separates the two.
1501- if crate::envflags::env_flag!("EC_PRED") {
1502- let row0: Vec<u16> = (0..bw.min(8))
1503- .map(|c| self.data[y * self.width + x + c])
1504- .collect();
1505- let col0: Vec<u16> = (0..bh.min(8))
1506- .map(|r| self.data[(y + r) * self.width + x])
1507- .collect();
1508- eprintln!("OUR_RECON x={x} y={y} bw={bw} bh={bh} row0={row0:?} col0={col0:?}");
1509- }
1510830 }
1511831
1512832 /// Predicts under `mode` then adds `residual` (side*side, raster),
@@ -1553,13 +873,6 @@ impl PlaneBuf<'_> {
1553873 buf
1554874 } else {
1555875 let (above, left, corner) = self.edges(x, y, side, reach);
1556- if crate::envflags::env_flag!("EC_DEBUG_EDGES") {
1557- eprintln!(
1558- "EDGES_SQ x={x} y={y} side={side} mode={mode} above={:?} left={:?} corner={corner:?}",
1559- above.as_deref(),
1560- left.as_deref(),
1561- );
1562- }
1563876 let mut prediction = vec![0u16; side * side];
1564877 if let Some(fi_mode) = filter_intra {
1565878 crate::intra::predict_filter_intra(
@@ -1599,26 +912,7 @@ impl PlaneBuf<'_> {
1599912 };
1600913 // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's
1601914 // EC_PRED/EC_PREDND rungs (x/y are this plane's pixel origin).
1602- if crate::envflags::env_flag!("EC_PRED") {
1603- let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum();
1604- let row0: Vec<u16> = prediction[..side.min(8)].to_vec();
1605- let col0: Vec<u16> = (0..side.min(8)).map(|r| prediction[r * side]).collect();
1606- eprintln!(
1607- "@{} OUR_PRED x={x} y={y} plane={} side={side} side={side} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}",
1608- std::panic::Location::caller(),
1609- recon_plane(),
1610- i32::from(smooth_neighbor)
1611- );
1612- }
1613915 let residual = dense_residual(residual, side * side);
1614- if crate::envflags::env_flag!("EC_DBG192") && y == 168 && (x == 224 || x == 232) {
1615- let res0: Vec<i32> = residual[..side.min(8)].to_vec();
1616- let pred0: Vec<u16> = prediction[..side.min(8)].to_vec();
1617- eprintln!(
1618- "DBG192 sq x={x} y={y} side={side} mode={mode} cfl={} pred0={pred0:?} res0={res0:?}",
1619- cfl.is_some()
1620- );
1621- }
1622916 for row in 0..side {
1623917 // lane-sb128c r8: libaom's frame buffer is superblock
1624918 // aligned; ours is padded to 32 (`block_grid`), so a 64x64
@@ -1644,16 +938,6 @@ impl PlaneBuf<'_> {
1644938 base = (base + cfl_scaled(alpha_q3, ac)).clamp(0, sample_max(fctx));
1645939 }
1646940 let sample = (base + residual[idx]).clamp(0, sample_max(fctx)) as u16;
1647- pix_write(
1648- "reconstruct",
1649- x,
1650- y,
1651- side,
1652- x + col,
1653- y + row,
1654- self.data[(y + row) * self.width + x + col],
1655- sample,
1656- );
1657941 self.data.to_mut()[(y + row) * self.width + x + col] = sample;
1658942 }
1659943 }
@@ -1670,9 +954,6 @@ pub(super) fn read_plane(
1670954 scan: &[u16],
1671955 plane_idx: usize,
1672956 around: (bool, bool, i32),
1673- // The block's own luma mode — [`crate::tile::write_block_planes`] passes
1674- // it for every plane's `txb` lookup (it is what an intra transform type's
1675- // CDF is indexed by, spec 9.3), never the plane's own predicted mode.
1676957 tx_mode: usize,
1677958 predict_mode: usize,
1678959 angle_delta: i32,
@@ -1684,17 +965,9 @@ pub(super) fn read_plane(
1684965 cy: usize,
1685966 side: usize,
1686967 tx_side: usize,
1687- base_q_idx: u8,
1688968 cfl: Option<(i32, CflSrc)>,
1689969 filter_intra: Option<usize>,
1690- // Only meaningful for `plane_idx == 0`: `Some` when this transform unit is
1691- // smaller than its own block (spec `get_txb_ctx_general`'s
1692- // `plane_bsize != tx_size` branch), carrying the already-looked-up
1693- // `SKIP_CONTEXTS` value; `None` everywhere else (a lone luma TU, or any
1694- // chroma plane), where `txb_skip_ctx` is 0 or the usual OR-of-neighbours
1695- // formula below.
1696970 luma_skip_ctx: Option<usize>,
1697- // See [`PlaneBuf::reconstruct`]'s own doc: caller's neighbour-smooth check.
1698971 smooth_neighbor: bool,
1699972 fctx: &crate::decode::FrameCtx,
1700973 ) -> Result<Grid> {
@@ -1706,8 +979,6 @@ pub(super) fn read_plane(
1706979 if plane_idx > 0 && mono(fctx) {
1707980 return Ok(Grid::Zero(side * side));
1708981 }
1709- // lane-av1readcensus: the units read from here on are this plane's.
1710- set_census_plane(plane_idx);
1711982 let skip_ctx = if plane_idx == 0 {
1712983 luma_skip_ctx.unwrap_or(0)
1713984 } else {
@@ -1733,12 +1004,6 @@ pub(super) fn read_plane(
17331004 // labelling its unit `plane=0`, and a sweep reading a second-luma-unit
17341005 // phantom out of that label (class `rung-mislabels-plane`). Diagnostic
17351006 // only: no gate asserts decode behaviour off this line.
1736- if crate::envflags::env_flag!("EC_TRACE_MODE") {
1737- eprintln!(
1738- "OUR_MODE plane={plane_idx} x={x} y={cy} side={side} mode={predict_mode} \
1739- ad={angle_delta} fi={filter_intra:?} reach={reach:?}"
1740- );
1741- }
17421007 let tx_mode = if plane_idx == 0 {
17431008 fi_tx_row(tx_mode, filter_intra)
17441009 } else {
@@ -1813,7 +1078,6 @@ pub(super) fn read_plane(
18131078 default_tx_type,
18141079 None,
18151080 )?;
1816- note_chroma_class1(plane_idx, tx_type);
18171081 if plane_idx == 0 {
18181082 fctx.luma_tx_type.with(|c| c.set(tx_type));
18191083 }
@@ -1840,13 +1104,6 @@ pub(super) fn read_plane(
18401104 stride: 0,
18411105 lossless: lossless(fctx),
18421106 };
1843- if crate::envflags::env_flag!("EC_AV1_TRACE") {
1844- let residual = tx.run(&levels);
1845- eprintln!(
1846- "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={:?} residual={residual:?}",
1847- &*levels,
1848- );
1849- }
18501107 push_intra_tx(
18511108 y,
18521109 u,
@@ -1988,9 +1245,6 @@ pub(super) fn read_rect_chroma_unit(
19881245 smooth_neighbor_uv: bool,
19891246 fctx: &crate::decode::FrameCtx,
19901247 ) -> Result<Grid> {
1991- if ss_x(fctx) == 1 && ss_y(fctx) == 0 && w != h {
1992- hit!(CHROMA422_RECT_HITS);
1993- }
19941248 // The same three cases as [`read_plane`], for the same reason: at 32 points
19951249 // an INTER chroma unit's transform set is `EXT_TX_SET_DCT_IDTX` (the luma's
19961250 // coded `IDTX` survives) where the intra set is `EXT_TX_SET_DCTONLY`, and
@@ -2016,7 +1270,6 @@ pub(super) fn read_rect_chroma_unit(
20161270 usize::from(around.0) + usize::from(around.1) + chroma_skip_offset.unwrap_or(0),
20171271 dc_sign_ctx(around.2),
20181272 default_tx,
2019- plane_idx,
20201273 )?;
20211274 let residual = dequant_and_inverse_typed_wh(
20221275 &levels,
@@ -2086,7 +1339,6 @@ pub(super) fn decode_block(
20861339 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at);
20871340 let palette_uv_cache = neighbours.palette_uv_cache(at);
20881341 let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
2089- let at_tile_left = c == neighbours.tile_col0_mi / (SUB / MI);
20901342 let (
20911343 skip,
20921344 mode,
@@ -2114,9 +1366,6 @@ pub(super) fn decode_block(
21141366 c * (SUB / MI),
21151367 fctx,
21161368 )?;
2117- if at_tile_left && palette_y.is_some() {
2118- hit!(PALETTE_TILE_LEFT_HITS);
2119- }
21201369 // lane-lossless: a lossless BLOCK's transform is TX_4X4 on every plane
21211370 // (libaom `read_tx_size`, `decodeframe.c`), so the caller's per-size
21221371 // tables/scans are replaced by the 4x4 ones and the block always takes the
@@ -2185,17 +1434,8 @@ pub(super) fn decode_block(
21851434 uv_mode
21861435 };
21871436 let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
2188- if smooth_neighbor {
2189- hit!(SMOOTH_LUMA_HITS);
2190- }
21911437 let smooth_neighbor_uv =
21921438 neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c, fctx);
2193- if crate::envflags::env_flag!("EC_AV1_TRACE") {
2194- eprintln!(
2195- "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \
2196- angle_delta_uv={angle_delta_uv}"
2197- );
2198- }
21991439 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
22001440 // `TxMode::Select`'s `tx_depth` (spec 5.11.16): read for every intra
22011441 // block, skipped or not. `logical_tx` is what the loop filter's edge
@@ -2252,29 +1492,12 @@ pub(super) fn decode_block(
22521492 );
22531493 }
22541494 }
2255- hit!(INTRABC_VARTX_HITS);
22561495 // lane-t900 r33 census: the t900 recipes resolved every tree UNIFORM.
22571496 // lane-av1-ibcvtx: a tree that resolved to mixed leaf sizes is no
22581497 // longer refused -- the luma reconstruct below walks the tree's own
22591498 // leaf list per leaf (libaom `decode_token_recon_block`, whose token
22601499 // loop reconstructs whatever `read_tx_size_vartx` resolved, per
22611500 // transform unit), so mixed sizes reconstruct at their own stride.
2262- // The counter marks the shape so a gate can prove a witness actually
2263- // carries a mixed tree and not merely another uniform one.
2264- let uniform = leaves.first().is_some_and(|f| {
2265- leaves
2266- .iter()
2267- .all(|l| (l.2, l.3) == (f.2, f.3) && l.2 == l.3)
2268- });
2269- if !uniform {
2270- hit!(INTRABC_VARTX_MIXED_LEAVES_HITS);
2271- if crate::envflags::env_flag!("EC_AV1_IBCVTX_DEBUG") {
2272- eprintln!(
2273- "IBCVTX mixed intrabc tree mi=({mi_r},{mi_c}) side={side} \
2274- dv={intrabc_dv:?} leaves={leaves:?}"
2275- );
2276- }
2277- }
22781501 Some(leaves)
22791502 } else {
22801503 None
@@ -2291,9 +1514,6 @@ pub(super) fn decode_block(
22911514 // single-unit path.
22921515 (lossless_tx(side.min(64), fctx), luma_tx)
22931516 };
2294- if tx_select && logical_tx < side && uv_mode != DC_PRED {
2295- hit!(SQ_CHROMA_TX_HITS);
2296- }
22971517 let luma_set = if tx_select {
22981518 txbset_for(logical_tx, reduced_tx_set)
22991519 } else {
@@ -2400,9 +1620,6 @@ pub(super) fn decode_block(
24001620 // Counted on the SHAPE, not on the arm below, so a gate can tell a stream
24011621 // that reaches this block apart from one that never does (class
24021622 // gate-blind-to-feature).
2403- if palette_y_buf.is_some() && skip && logical_tx < side {
2404- hit!(SKIP_SPLIT_TX_OVERRIDE_HITS);
2405- }
24061623 if let Some(buf) = &palette_y_buf
24071624 && (logical_tx == side || skip)
24081625 {
@@ -2453,9 +1670,6 @@ pub(super) fn decode_block(
24531670 // narrower meaning (a READ split tx depth).
24541671 let split_tx_skip = logical_tx < side && palette_y_buf.is_none() && intrabc_bufs.is_none();
24551672 if split_tx_skip {
2456- if tx_select {
2457- hit!(SKIP_SPLIT_TX_HITS);
2458- }
24591673 let n_axis = side / logical_tx;
24601674 for tu_row in 0..n_axis {
24611675 for tu_col in 0..n_axis {
@@ -2471,11 +1685,6 @@ pub(super) fn decode_block(
24711685 tu_row * logical_tx,
24721686 logical_tx,
24731687 reach,
2474- px,
2475- py,
2476- y.width,
2477- y.height,
2478- fctx,
24791688 );
24801689 push_intra(
24811690 y,
@@ -2540,11 +1749,6 @@ pub(super) fn decode_block(
25401749 luma_span_x,
25411750 luma_span_y,
25421751 reach,
2543- px,
2544- py,
2545- y.width,
2546- y.height,
2547- fctx,
25481752 )
25491753 };
25501754 let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h);
@@ -2580,9 +1784,6 @@ pub(super) fn decode_block(
25801784 window
25811785 };
25821786 if let Some((ub, _)) = &palette_uv_bufs {
2583- if cn_cols * cn_rows > 1 {
2584- hit!(SKIP_CHROMA_OVERRIDE_WINDOW_HITS);
2585- }
25861787 set_palette_pred(chroma_window(ub), fctx);
25871788 }
25881789 push_intra_unit(
@@ -2645,18 +1846,6 @@ pub(super) fn decode_block(
26451846 // side`, so only 4:2:2 changes.
26461847 let u_grid = vec![0i32; chroma_side * chroma_height];
26471848 let v_grid = vec![0i32; chroma_side * chroma_height];
2648- // The measured arm, not a proxy: how many samples this block's
2649- // chroma bookkeeping grid is SHORT of its own plane block. The
2650- // square form this lane removed is `chroma_side * chroma_side`,
2651- // which at 4:2:2 is half the plane block; restoring it makes this
2652- // non-zero on every 4:2:2 skip block, and the witness gate asserts
2653- // the total stayed 0.
2654- let plane_block = chroma_side * chroma_height;
2655- let short = plane_block.saturating_sub(u_grid.len());
2656- hit_do!(SKIP_ARM_CHROMA_SHORT_SAMPLES.with(|c| c.set(c.get() + short)));
2657- if chroma_side != chroma_height {
2658- hit!(SKIP_ARM_CHROMA_RECT_SHAPES);
2659- }
26601849 neighbours.record(
26611850 at,
26621851 side,
@@ -2692,7 +1881,6 @@ pub(super) fn decode_block(
26921881 py,
26931882 side,
26941883 coeff_tx_side,
2695- base_q_idx,
26961884 None,
26971885 filter_intra,
26981886 None,
@@ -2745,19 +1933,12 @@ pub(super) fn decode_block(
27451933 cpy,
27461934 chroma_side,
27471935 chroma_tx,
2748- base_q_idx,
27491936 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
27501937 None,
27511938 None,
27521939 smooth_neighbor_uv,
27531940 fctx,
27541941 )?;
2755- if crate::envflags::env_flag!("EC_AV1_TRACE") {
2756- eprintln!(
2757- "TRACE u-write cpx={cpx} cpy={cpy} chroma_side={chroma_side} row0={:?}",
2758- &u.data[cpy * u.width + cpx..][..chroma_side]
2759- );
2760- }
27611942 if let Some((_, vb)) = &palette_uv_bufs {
27621943 set_palette_pred(vb.clone(), fctx);
27631944 }
@@ -2779,7 +1960,6 @@ pub(super) fn decode_block(
27791960 cpy,
27801961 chroma_side,
27811962 chroma_tx,
2782- base_q_idx,
27831963 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
27841964 None,
27851965 None,
@@ -2877,11 +2057,6 @@ pub(super) fn decode_block(
28772057 luma_span_x,
28782058 luma_span_y,
28792059 reach,
2880- px,
2881- py,
2882- y.width,
2883- y.height,
2884- fctx,
28852060 );
28862061 let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h);
28872062 if let Some((ub, vb)) = &palette_uv_bufs {
@@ -2916,7 +2091,6 @@ pub(super) fn decode_block(
29162091 cu_y,
29172092 chroma_tx,
29182093 chroma_tx,
2919- base_q_idx,
29202094 alpha
29212095 .zip(ac)
29222096 .map(|((au, av), ac)| (if plane_pass == 1 { au } else { av }, ac)),
@@ -2925,10 +2099,6 @@ pub(super) fn decode_block(
29252099 smooth_neighbor_uv,
29262100 fctx,
29272101 )?;
2928- hit!(CHROMA_SPLIT_TX_HITS);
2929- if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
2930- hit!(CHROMA422_SQUARE_HITS);
2931- }
29322102 // Immediately, so the next unit of this block reads this
29332103 // one's coefficient context. `record` below stamps one
29342104 // chroma state across the whole block; the replay after
@@ -3054,10 +2224,7 @@ pub(super) fn decode_block(
30542224 // top-right 8x8 unit of a 16x16 D203 block bottom-left
30552225 // pixels libaom refuses outright (`col_off > 0`), which is
30562226 // the diagonal wedge seed 46 reconstructed wrong.
3057- let tu_reach = tu_reach(
3058- side, side, tu_off_x, tu_off_y, tu_tx, reach, px, py, y.width, y.height,
3059- fctx,
3060- );
2227+ let tu_reach = tu_reach(side, side, tu_off_x, tu_off_y, tu_tx, reach);
30612228 // This transform unit's own bsize (`tu_tx`) is smaller
30622229 // than the block it sits in (`side`), so `txb_skip_ctx` is
30632230 // the neighbour-magnitude table, not the lone-TU 0 (spec
@@ -3083,7 +2250,6 @@ pub(super) fn decode_block(
30832250 (luma_set, luma_scan)
30842251 };
30852252 if let Some(buf) = &palette_y_buf {
3086- hit!(PALETTE_SPLIT_TX_HITS);
30872253 let mut window = vec![0u16; tu_tx * tu_tx];
30882254 for row in 0..tu_tx {
30892255 let src = (tu_off_y + row) * side + tu_off_x;
@@ -3108,26 +2274,13 @@ pub(super) fn decode_block(
31082274 tu_px,
31092275 tu_py,
31102276 tu_tx,
3111- // The unit's own COEFFICIENT grid, half its side at
3112- // TX_64X64 (a 64-point transform codes nothing past 32);
3113- // identical to `tu_tx` at every smaller size
3114- // (lane-sb128b r1).
31152277 if tu_tx == 64 { 32 } else { tu_tx },
3116- base_q_idx,
31172278 None,
31182279 filter_intra,
31192280 Some(tu_skip_ctx),
31202281 smooth_neighbor,
31212282 fctx,
31222283 )?;
3123- if crate::envflags::env_flag!("EC_AV1_TRACE") {
3124- eprintln!(
3125- "TRACE tu_bitpos mi=({},{}) tell={}",
3126- tu_mi.0,
3127- tu_mi.1,
3128- dec.debug_bitpos()
3129- );
3130- }
31312284 neighbours.record_mi_luma(tu_mi, tu_tx, &tu_grid);
31322285 if first_leaf_tx.is_none() {
31332286 first_leaf_tx = Some(fctx.luma_tx_type.with(std::cell::Cell::get));
@@ -3210,7 +2363,6 @@ pub(super) fn decode_block(
32102363 };
32112364 let (unit_w, unit_h) = (chroma_tx / 4, chroma_tx_h / 4);
32122365 if cu_col * unit_w >= max_units_w || cu_row * unit_h >= max_units_h {
3213- hit!(CHROMA_EDGE_TU_CLIP_HITS);
32142366 continue;
32152367 }
32162368 // The chroma context arrays are indexed in LUMA mi, so this
@@ -3240,11 +2392,6 @@ pub(super) fn decode_block(
32402392 luma_span_x,
32412393 luma_span_y,
32422394 reach,
3243- px,
3244- py,
3245- y.width,
3246- y.height,
3247- fctx,
32482395 )
32492396 };
32502397 let (cu_x, cu_y) =
@@ -3282,7 +2429,6 @@ pub(super) fn decode_block(
32822429 cu_y,
32832430 chroma_tx,
32842431 chroma_tx,
3285- base_q_idx,
32862432 alpha.zip(ac).map(|((au, av), ac)| {
32872433 (if plane_pass == 1 { au } else { av }, ac)
32882434 }),
@@ -3322,10 +2468,6 @@ pub(super) fn decode_block(
33222468 )?
33232469 };
33242470 if cn_rows * cn_cols > 1 {
3325- hit!(CHROMA_SPLIT_TX_HITS);
3326- if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
3327- hit!(CHROMA422_SQUARE_HITS);
3328- }
33292471 // Immediately, so the NEXT unit of this same block reads
33302472 // this one's coefficient context (libaom's chroma
33312473 // `txb_skip_ctx` for the second quadrant is 11, i.e. base
crates/ec-av1/src/decode/coeffs.rsmodified+68 -729
@@ -2,70 +2,6 @@
22
33 use super::*;
44
5-/// lane-coefread: the per-coefficient trace sites, one `#[cold]` call each.
6-/// `eprintln!` builds its `fmt::Arguments` on the stack AT THE CALL SITE, so
7-/// nine of them inside the base/sign loops pinned nine sets of values in the
8-/// hot loop's frame (the annotated profile was full of `mov ...(%rsp)` spill
9-/// traffic). Out of line, the loop keeps its values in registers and the
10-/// trace output is character-for-character what it was.
11-#[cold]
12-#[inline(never)]
13-fn trace_base_eob(scan_idx: usize, pos: usize, row: usize, col: usize, ctx: usize, v: i32) {
14- eprintln!(
15- "TRACE base_eob scan_idx={scan_idx} pos={pos} row={row} col={col} ctx={ctx} value={v}"
16- );
17-}
18-
19-#[cold]
20-#[inline(never)]
21-fn trace_base(scan_idx: usize, pos: usize, row: usize, col: usize, ctx: usize, v: i32) {
22- eprintln!("TRACE base scan_idx={scan_idx} pos={pos} row={row} col={col} ctx={ctx} value={v}");
23-}
24-
25-#[cold]
26-#[inline(never)]
27-fn trace_br(scan_idx: usize, pos: usize, row: usize, col: usize, ctx: usize, k: i32) {
28- eprintln!("TRACE br scan_idx={scan_idx} pos={pos} row={row} col={col} ctx={ctx} value={k}");
29-}
30-
31-#[cold]
32-#[inline(never)]
33-fn coeff_step_base(dec: &SymbolDecoder, scan_idx: usize, apos: usize, ctx: usize, v: i32) {
34- let (rng, _) = dec.debug_state();
35- eprintln!("EC_COEFF_STEP tag=base c={scan_idx} pos={apos} ctx={ctx} level={v} rng={rng}");
36-}
37-
38-#[cold]
39-#[inline(never)]
40-fn coeff_step_br(dec: &SymbolDecoder, scan_idx: usize, apos: usize, ctx: usize, k: i32) {
41- let (rng, _) = dec.debug_state();
42- eprintln!("EC_COEFF_STEP tag=br c={scan_idx} pos={apos} ctx={ctx} k={k} rng={rng}");
43-}
44-
45-#[cold]
46-#[inline(never)]
47-fn coeff_step_sign(dec: &SymbolDecoder, c: usize, negative: bool) {
48- let (rng, _) = dec.debug_state();
49- eprintln!(
50- "EC_COEFF_STEP tag=sign c={c} sign={} rng={rng}",
51- negative as i32
52- );
53-}
54-
55-#[cold]
56-#[inline(never)]
57-fn coeff_step_post_golomb(dec: &SymbolDecoder, c: usize, level: i32) {
58- let (rng, _) = dec.debug_state();
59- eprintln!("EC_COEFF_STEP tag=post_golomb c={c} level={level} rng={rng}");
60-}
61-
62-#[cold]
63-#[inline(never)]
64-fn coeff_step_base_eob_level(dec: &SymbolDecoder, level: i32) {
65- let (rng, _) = dec.debug_state();
66- eprintln!("EC_COEFF_STEP tag=base_eob level={level} rng={rng}");
67-}
68-
695 // lane-ibc444c: see `read_coeffs_rect`'s `#[track_caller]`.
706 #[track_caller]
717 pub(super) fn read_coeffs(
@@ -88,91 +24,12 @@ pub(super) fn read_coeffs(
8824 // caller's block genuinely is `side` x `side`.
8925 rect_shape: Option<(usize, usize)>,
9026 ) -> Result<(Grid, TxType)> {
91- let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
9227 let side = coding.side;
93- // lane-av1readcensus: this unit's own entry state, so the census line
94- // carries the pre-read rng and pairs against the oracle's `EC_COEFF`
95- // (which prints `r->ec.rng` before the same `txb_skip` read).
96- let census_entry_rng = dec.debug_state().0;
97- let (census_w, census_h) = rect_shape.unwrap_or((side, side));
98- // lane-av1ibcfork: the per-unit BIT INTERVAL, the twin of the oracle's
99- // `EC_ECDUMP_IN` / `_OUT` / `_END`. The census plane, not a fresh label:
100- // it is the same source `census_unit` reads, so the interval line and the
101- // census line can never disagree about which plane a unit is on.
102- let iv_plane = CENSUS_PLANE.with(|c| c.get()).min(2);
103- let iv_bit = unit_iv_in(iv_plane, census_w, census_h, skip_ctx, dec);
104- if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") {
105- let (range, value) = dec.debug_state();
106- eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}");
107- }
108- if crate::envflags::env_flag!("EC_ECDUMP_IN") {
109- let (range, value) = dec.debug_state();
110- let bit = dec.debug_bitpos();
111- eprintln!(
112- "EC_ECDUMP_IN side={side} ctx={skip_ctx} dcctx={sign_ctx} ECIN=({value},{range},{bit})"
113- );
114- }
115- let dbg_txbskip = if coeff_trace_on() {
116- coding.txb_skip[skip_ctx]
117- } else {
118- [0; 3]
119- };
120- let sq_bit = if coeff_trace_on() {
121- dec.debug_bitpos()
122- } else {
123- 0
124- };
12528 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;
126- unit_iv_skip(
127- dec, iv_bit, iv_plane, census_w, census_h, skip_ctx, all_zero,
128- );
12929 // lane-ibc444c: this reader logs an `all_zero` step even for a read that
13030 // consumes ZERO bits, so `post_bit == bit` means "no symbol was read" --
13131 // filter on it before pairing anything against the oracle.
132- if crate::envflags::env_flag!("EC_IBCTX") {
133- eprintln!(
134- "EC_IBCTX2 side={} skip_ctx={skip_ctx} sign_ctx={sign_ctx} bit={sq_bit} at {}",
135- coding.side,
136- std::panic::Location::caller(),
137- );
138- }
139- if coeff_trace_on() {
140- let (rng, _) = dec.debug_state();
141- eprintln!(
142- "EC_COEFF_STEP tag=all_zero side={} ctx={skip_ctx} dcctx={sign_ctx} cdf={dbg_txbskip:?} all_zero={} rng={rng} bit={sq_bit} post_bit={}",
143- coding.side,
144- all_zero as i32,
145- dec.debug_bitpos()
146- );
147- }
148- if crate::envflags::env_flag!("EC_AV1_TELL") {
149- eprintln!(
150- "TELL label=post_txb_skip ctx={skip_ctx} all_zero={} tell={} range={}",
151- all_zero as u8,
152- dec.debug_bitpos(),
153- dec.debug_state().0
154- );
155- }
156- if trace {
157- eprintln!("TRACE all_zero ctx={skip_ctx} value={}", all_zero as i32);
158- }
159- if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") {
160- let (range, value) = dec.debug_state();
161- eprintln!("EC_AV1_STATE_AFTER_TXBSKIP range={range} value={value}");
162- }
16332 if all_zero {
164- // lane-coefgrid: the all-zero unit (60% of the 4K segment's) names the
165- // shared zero grid instead of allocating and zeroing its own.
166- census_unit(
167- census_w,
168- census_h,
169- TxType::DctDct,
170- 0,
171- true,
172- census_entry_rng,
173- dec,
174- );
175- unit_iv_end(dec, iv_plane, census_w, census_h, skip_ctx);
17633 return Ok((Grid::Zero(side * side), TxType::DctDct));
17734 }
17835 let mut grid = vec![0i32; side * side];
@@ -187,47 +44,14 @@ pub(super) fn read_coeffs(
18744 // share their symbol order with (`Tx_Type_Inter_Inv_Set3`'s two
18845 // members are a prefix of `Tx_Type_Intra_Inv_Set2`'s five).
18946 let len = tx_type_cdf.len();
190- if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") && len == 3 {
191- eprintln!("EC_AV1_TXTYPE32_CDF {tx_type_cdf:?}");
192- }
193- crate::msac::SymbolDecoder::set_symr_cdf("tx_type");
19447 let t = dec.symbol(tx_type_cdf);
195- crate::census::tx_type(len, t);
196- if coeff_trace_on() {
197- let (rng, _) = dec.debug_state();
198- eprintln!("EC_COEFF_STEP tag=tx_type len={len} rng={rng}");
199- }
200- if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") {
201- let (range, value) = dec.debug_state();
202- eprintln!("EC_AV1_STATE_AFTER_TXTYPE range={range} value={value}");
203- }
204- if trace {
205- eprintln!("TRACE tx_type value={t} len={len}");
206- }
20748 tx_type = tx_type_from_symbol(len, t).ok_or_else(|| {
20849 unsupported(format!("a tx_type symbol outside its CDF's own set: {t}"))
20950 })?;
21051 }
21152
21253 let class = TxClass::of(tx_type);
213- if class != TxClass::TwoD {
214- hit!(TX_CLASS1_HITS);
215- hit!(RECT_CLASS1_HITS);
216- }
21754 let eob = read_eob(dec, coding, class);
218- if trace {
219- eprintln!("TRACE eob value={eob}");
220- }
221- let ec_trace_coeff = coeff_trace_on();
222- if ec_trace_coeff {
223- let (rng, _) = dec.debug_state();
224- let cls = match class {
225- TxClass::TwoD => "2d",
226- TxClass::Horiz => "horiz",
227- TxClass::Vert => "vert",
228- };
229- eprintln!("EC_COEFF_STEP tag=eob eob={eob} tx={tx_type:?} class={cls} rng={rng}");
230- }
23155 let class_scan;
23256 let scan: &[u16] = if class == TxClass::TwoD {
23357 scan
@@ -268,9 +92,6 @@ pub(super) fn read_coeffs(
26892 let level = if scan_idx == eob - 1 {
26993 let ctx = eob_coeff_ctx(scan_idx, side * side);
27094 let v = dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1;
271- if trace {
272- trace_base_eob(scan_idx, pos, row, col, ctx, v);
273- }
27495 v
27596 } else {
27697 let ctx = if class == TxClass::TwoD && rect_shape.is_none() {
@@ -284,14 +105,6 @@ pub(super) fn read_coeffs(
284105 base_ctx(levels, stride, row, col, class, rect_shape)
285106 };
286107 let v = dec.symbol(&mut coding.base[ctx]) as i32;
287- if ec_trace_coeff {
288- // `pos` in libaom's column-major `coeff_idx` convention, so
289- // the ladder lines up with instrumented `aomdec`.
290- coeff_step_base(dec, scan_idx, col * side + row, ctx, v);
291- }
292- if trace {
293- trace_base(scan_idx, pos, row, col, ctx, v);
294- }
295108 v
296109 };
297110 let level = if level > NUM_BASE_LEVELS {
@@ -312,16 +125,6 @@ pub(super) fn read_coeffs(
312125 let mut sent = 0;
313126 loop {
314127 let k = dec.symbol(&mut coding.br[ctx]) as i32;
315- if ec_trace_coeff {
316- // lane-leaf8tx r3: the `br` rung was missing from THIS
317- // path's trace, so the cross-decoder range ladder was
318- // blind to every base-range symbol and mis-reported the
319- // first divergence (class [[gate-blind-to-feature]]).
320- coeff_step_br(dec, scan_idx, col * side + row, ctx, k);
321- }
322- if trace {
323- trace_br(scan_idx, pos, row, col, ctx, k);
324- }
325128 level += k;
326129 sent += BR_STEP;
327130 if k < BR_STEP || sent >= COEFF_BASE_RANGE {
@@ -332,9 +135,6 @@ pub(super) fn read_coeffs(
332135 } else {
333136 level
334137 };
335- if ec_trace_coeff && scan_idx == eob - 1 {
336- coeff_step_base_eob_level(dec, level);
337- }
338138 // Every coded level here is a magnitude in `0..=15` (base <= 3 plus
339139 // at most `COEFF_BASE_RANGE` from the `br` loop; the Golomb tail is
340140 // added in the sign pass below, straight into `grid`), so the context
@@ -347,10 +147,6 @@ pub(super) fn read_coeffs(
347147 nz_n += 1;
348148 }
349149 }
350- if ec_trace_coeff {
351- let (rng, _) = dec.debug_state();
352- eprintln!("EC_COEFF_STEP tag=after_bases rng={rng}");
353- }
354150
355151 for &packed in nz_buf[..nz_n].iter().rev() {
356152 let c = (packed >> 4) as usize;
@@ -358,40 +154,18 @@ pub(super) fn read_coeffs(
358154 let level = (packed & 15) as i32;
359155 let negative = if pos == 0 {
360156 let v = dec.symbol(&mut coding.dc_sign[sign_ctx]) == 1;
361- if trace {
362- eprintln!("TRACE dc_sign ctx={sign_ctx} value={}", v as i32);
363- }
364157 v
365158 } else {
366159 dec.literal(1) == 1
367160 };
368- if ec_trace_coeff {
369- coeff_step_sign(dec, c, negative);
370- }
371161 let level = if level > MAX_BR_LEVEL {
372162 let g = read_golomb(dec)?;
373- if trace {
374- eprintln!("TRACE golomb pos={pos} value={g}");
375- }
376163 level + g as i32
377164 } else {
378165 level
379166 };
380- if ec_trace_coeff {
381- coeff_step_post_golomb(dec, c, level);
382- }
383167 grid[pos] = if negative { -level } else { level };
384168 }
385- census_unit(
386- census_w,
387- census_h,
388- tx_type,
389- eob,
390- false,
391- census_entry_rng,
392- dec,
393- );
394- unit_iv_end(dec, iv_plane, census_w, census_h, skip_ctx);
395169 Ok((Grid::Own(grid), tx_type))
396170 }
397171
@@ -419,54 +193,12 @@ pub(super) fn read_coeffs_rect(
419193 skip_ctx: usize,
420194 sign_ctx: usize,
421195 default_tx_type: TxType,
422- // lane-av1chrtx: the plane this unit belongs to (0 luma, 1 U, 2 V) --
423- // printed by the two `EC_COEFF_STEP` traces below, which hardcoded
424- // `plane=0` and so mis-attributed a CHROMA read as a luma one in two
425- // independent lane reports.
426- plane: usize,
427196 ) -> Result<(Grid, TxType)> {
428- let rect_trace = coeff_trace_on();
429- let entry_rng = dec.debug_state().0;
430- // lane-av1readcensus: this reader is handed the real plane (lane-av1chrtx
431- // threaded it in for the `EC_COEFF_STEP` traces), so it stamps the census
432- // plane itself rather than inheriting whichever reader did last. The
433- // luma-only readers (`decode_rect_split`, `decode_block_rect64`,
434- // `read_inter_plane_rect`'s corner) are all plane 0 -- the stamp's initial
435- // value -- and the other plane-owning readers stamp on entry.
436- set_census_plane(plane);
437- let ibctx_on = crate::envflags::env_flag!("EC_IBCTX");
438- let entry_bit = if ibctx_on { dec.debug_bitpos() } else { 0 };
439- let iv_bit = unit_iv_in(plane, w, h, skip_ctx, dec);
440197 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;
441- unit_iv_skip(dec, iv_bit, plane, w, h, skip_ctx, all_zero);
442- if rect_trace {
443- eprintln!(
444- "EC_COEFF_STEP tag=all_zero plane={plane} ctx={skip_ctx} entry={entry_rng} all_zero={} rng={} bit={entry_bit} post_bit={}",
445- all_zero as i32,
446- dec.debug_state().0,
447- dec.debug_bitpos()
448- );
449- }
450- if ibctx_on {
451- // lane-ibc444c. `bit`/`post_bit` are the STREAM POSITION, not the coder
452- // range: the only collision-free key for pairing this unit against the
453- // oracle's `EC_ECDUMP_IN`. And `post_bit != bit` is how a caller tells
454- // a real symbol read from a 0-bit one -- the SQUARE reader logs a step
455- // either way, which is exactly the artifact that made an earlier
456- // round of this lane claim a false exactness.
457- eprintln!(
458- "EC_IBCTX w={w} h={h} skip_ctx={skip_ctx} sign_ctx={sign_ctx} bit={entry_bit} post_bit={} at {}",
459- dec.debug_bitpos(),
460- std::panic::Location::caller(),
461- );
462- }
463198 if all_zero {
464- census_unit(w, h, TxType::DctDct, 0, true, entry_rng, dec);
465- unit_iv_end(dec, plane, w, h, skip_ctx);
466199 return Ok((Grid::Zero(w * h), TxType::DctDct));
467200 }
468201 let mut grid = vec![0i32; w * h];
469- hit!(RECT_COEFF_TU_HITS);
470202 // lane-tx4x8: a 4x8/8x4 luma TU DOES carry a `tx_type` symbol (its set is
471203 // `EXT_TX_SET_DTT4_IDTX(_1DDCT)`, `tx_size_sqr_up == TX_8X8`), including
472204 // the `V_DCT`/`H_DCT` members whose 1D tx class needs its own scan and
@@ -477,28 +209,12 @@ pub(super) fn read_coeffs_rect(
477209 if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() {
478210 let len = tx_type_cdf.len();
479211 let t = dec.symbol(tx_type_cdf);
480- crate::census::tx_type(len, t);
481212 tx_type = tx_type_from_symbol(len, t).ok_or_else(|| {
482213 unsupported(format!("a tx_type symbol outside its CDF's own set: {t}"))
483214 })?;
484- if rect_trace {
485- eprintln!(
486- "EC_COEFF_STEP tag=tx_type plane={plane} rng={}",
487- dec.debug_state().0
488- );
489- }
490215 }
491216 let class = TxClass::of(tx_type);
492- if class != TxClass::TwoD {
493- hit!(TX_CLASS1_HITS);
494- }
495217 let eob = read_eob(dec, coding, class);
496- if rect_trace {
497- eprintln!(
498- "EC_COEFF_STEP tag=eob eob={eob} rng={}",
499- dec.debug_state().0
500- );
501- }
502218 let class_scan;
503219 let scan: &[u16] = if class == TxClass::TwoD {
504220 scan
@@ -570,12 +286,6 @@ pub(super) fn read_coeffs_rect(
570286 base_ctx_rect(levels, stride, w, h, row, col, class)
571287 };
572288 let v = dec.symbol(&mut coding.base[ctx]) as i32;
573- if rect_trace {
574- eprintln!(
575- "EC_COEFF_STEP tag=base c={scan_idx} pos={pos} ctx={ctx} level={v} rng={}",
576- dec.debug_state().0
577- );
578- }
579289 v
580290 };
581291 let level = if level > NUM_BASE_LEVELS {
@@ -596,12 +306,6 @@ pub(super) fn read_coeffs_rect(
596306 let mut sent = 0;
597307 loop {
598308 let k = dec.symbol(&mut coding.br[ctx]) as i32;
599- if rect_trace {
600- eprintln!(
601- "EC_COEFF_STEP tag=br c={scan_idx} pos={pos} ctx={ctx} k={k} rng={}",
602- dec.debug_state().0
603- );
604- }
605309 level += k;
606310 sent += BR_STEP;
607311 if k < BR_STEP || sent >= COEFF_BASE_RANGE {
@@ -618,19 +322,6 @@ pub(super) fn read_coeffs_rect(
618322 nz_buf[nz_n] = ((scan_idx as u16) << 4) | level as u16;
619323 nz_n += 1;
620324 }
621- if rect_trace && scan_idx == eob - 1 {
622- // the oracle's `tag=base_eob`: POST-br level, POST-br rng, with the
623- // same `get_lower_levels_ctx_eob` ctx (the same `eob_coeff_ctx`).
624- let ctx = eob_coeff_ctx(scan_idx, w * h);
625- let (rng, _) = dec.debug_state();
626- eprintln!(
627- "EC_COEFF_STEP tag=base_eob c={scan_idx} pos={pos} ctx={ctx} level={level} rng={rng}"
628- );
629- }
630- }
631- if rect_trace {
632- let (rng, _) = dec.debug_state();
633- eprintln!("EC_COEFF_STEP tag=after_bases rng={rng}");
634325 }
635326 for &packed in nz_buf[..nz_n].iter().rev() {
636327 let pos = scan[(packed >> 4) as usize] as usize;
@@ -640,53 +331,18 @@ pub(super) fn read_coeffs_rect(
640331 } else {
641332 dec.literal(1) == 1
642333 };
643- if rect_trace {
644- let (rng, _) = dec.debug_state();
645- eprintln!(
646- "EC_COEFF_STEP tag=sign_rect pos={pos} sign={} dcctx={sign_ctx} rng={rng}",
647- u8::from(negative)
648- );
649- }
650334 let level = if level > MAX_BR_LEVEL {
651335 let g = read_golomb(dec)?;
652336 level + g as i32
653337 } else {
654338 level
655339 };
656- if rect_trace {
657- // lane-av1oddheightfork2: the twin of the square reader's
658- // `coeff_step_post_golomb`. The oracle's `EC_COEFF_STEP
659- // tag=post_golomb` (decodetxb.c, after read_golomb) fires for a RECT
660- // unit exactly as it does for a square one, but this reader had no
661- // rung for it, so every rect unit's ladder was one step short and
662- // the pairing had to guess whether a golomb had been read. This
663- // rung reads no bits: it prints the state after the read it labels.
664- let (rng, _) = dec.debug_state();
665- eprintln!(
666- "EC_COEFF_STEP tag=post_golomb c={} pos={pos} level={level} rng={rng}",
667- (packed >> 4)
668- );
669- }
670340 grid[pos] = if negative { -level } else { level };
671341 }
672342 // lane-d792: the rect unit's LEVEL grid in row-major (w) order, the
673343 // twin of the oracle's `EC_DQCOEFF` rung -- a residual mismatch whose
674344 // grids differ is a reader defect, one whose grids agree is a transform
675345 // defect.
676- if crate::envflags::env_flag!("EC_DQCOEFF") {
677- let nz: Vec<String> = grid
678- .iter()
679- .enumerate()
680- .filter(|&(_, &v)| v != 0)
681- .map(|(i, &v)| format!("{}/{}:{v}", i / w, i % w))
682- .collect();
683- eprintln!(
684- "OUR_LEVELS w={w} h={h} eob={eob} tx={tx_type:?} nz={}",
685- nz.join(",")
686- );
687- }
688- census_unit(w, h, tx_type, eob, false, entry_rng, dec);
689- unit_iv_end(dec, plane, w, h, skip_ctx);
690346 Ok((Grid::Own(grid), tx_type))
691347 }
692348
@@ -718,25 +374,11 @@ pub(super) fn read_chroma_coeffs_rect(
718374 sign_ctx: usize,
719375 default_tx_type: TxType,
720376 fctx: &crate::decode::FrameCtx,
721- // lane-av1chrtx: the plane index, threaded to `read_coeffs_rect`'s
722- // `EC_COEFF_STEP` traces (they used to print a hardcoded `plane=0`, so a
723- // V-plane read was indistinguishable from a luma one in the log).
724- plane: usize,
725377 ) -> Result<(Grid, TxType)> {
726378 if mono(fctx) {
727379 return Ok((Grid::Zero(w * h), TxType::DctDct));
728380 }
729- read_coeffs_rect(
730- dec,
731- coding,
732- scan,
733- w,
734- h,
735- skip_ctx,
736- sign_ctx,
737- default_tx_type,
738- plane,
739- )
381+ read_coeffs_rect(dec, coding, scan, w, h, skip_ctx, sign_ctx, default_tx_type)
740382 }
741383
742384 /// What one coded block leaves behind for the blocks that read it as a
@@ -1233,7 +875,13 @@ impl Neighbours {
1233875 /// [`SUB`]-grid cell it covers on both the above and left edges --
1234876 /// mirrors [`Self::record_rect`]'s loop shape, square-only (this lane's
1235877 /// call sites are all square blocks).
1236- pub(super) fn record_palette_y(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) {
878+ pub(super) fn record_palette_y(
879+ &mut self,
880+ at: (usize, usize),
881+ side: usize,
882+ size: usize,
883+ colors: [u16; 8],
884+ ) {
1237885 self.record_palette_y_rect(
1238886 (at.0 * (SUB / MI), at.1 * (SUB / MI)),
1239887 side,
@@ -1256,9 +904,6 @@ impl Neighbours {
1256904 colors: [u16; 8],
1257905 ) {
1258906 let (r, c) = mi;
1259- if crate::envflags::env_flag!("EC_PALPUB") {
1260- eprintln!("EC_PALPUB yrect mi={r},{c} bw={w} bh={h} y={size}");
1261- }
1262907 // lane-kf900 r6: mi (4px) granularity, libaom's own -- `palette_size`
1263908 // lives per mi cell in `MB_MODE_INFO`, and `xd->left_mbmi` is the mi
1264909 // cell immediately left of the block, not its 16px [`SUB`] cell. The
@@ -1633,12 +1278,6 @@ impl Neighbours {
16331278 // TX_32X32 -- independent of this block's luma `tx_depth`.
16341279 let uv_tx_w = ((w_mi * MI) >> ss_x(fctx)).clamp(4, 32) as u8;
16351280 let uv_tx_h = ((h_mi * MI) >> ss_y(fctx)).clamp(4, 32) as u8;
1636- if crate::envflags::env_flag!("EC_TXGRID_TRACE") {
1637- eprintln!(
1638- "EC_LFGRID mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}"
1639- );
1640- }
1641- crate::census::tx(tx_px, tx_h_px);
16421281 let cur = fctx.current_delta_lf.with(|c| c.get());
16431282 let snapshot: [i8; 4] = if fctx.delta_lf_multi.with(|c| c.get()) {
16441283 std::array::from_fn(|i| cur[i].clamp(-63, 63) as i8)
@@ -1727,11 +1366,6 @@ impl Neighbours {
17271366 tx_h_px: u8,
17281367 ) {
17291368 let (mi_r, mi_c) = at_mi;
1730- if crate::envflags::env_flag!("EC_TXGRID_TRACE") {
1731- eprintln!(
1732- "EC_LFLEAF mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}"
1733- );
1734- }
17351369 for rr in 0..h_mi {
17361370 let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c;
17371371 fill_span(&mut self.tx_grid, start, w_mi, tx_px);
@@ -1748,14 +1382,14 @@ impl Neighbours {
17481382 }
17491383
17501384 /// [`Self::fill_skip_grid`] with independent row/col extents (lane-partitions r1).
1751- pub(super) fn fill_skip_grid_rect(&mut self, at_mi: (usize, usize), w_mi: usize, h_mi: usize, skip: bool) {
1385+ pub(super) fn fill_skip_grid_rect(
1386+ &mut self,
1387+ at_mi: (usize, usize),
1388+ w_mi: usize,
1389+ h_mi: usize,
1390+ skip: bool,
1391+ ) {
17521392 let (mi_r, mi_c) = at_mi;
1753- if skip && w_mi != h_mi {
1754- hit!(RECT_SKIP_BAND_HITS);
1755- }
1756- // lane-census: an INTRA frame's blocks never reach the inter
1757- // publisher, and this one is what every coded block writes.
1758- crate::census::block_intra_frame(w_mi, h_mi, skip);
17591393 for rr in 0..h_mi {
17601394 let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c;
17611395 fill_span(
@@ -1907,7 +1541,8 @@ impl Neighbours {
19071541 /// "no neighbour"). `ref_frame` is `-1` for an intra block, else the
19081542 /// `1..=7` reference it coded (lane-av1refs's `single_ref_p*_ctx` needs
19091543 /// the real value, not just `is_inter`).
1910- #[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1544+ #[allow(dead_code)]
1545+ // read only from the `#[cfg(test)]` gates
19111546 // Signature mirrors the spec's per-call inputs; a parameter struct would only move them.
19121547 #[allow(clippy::too_many_arguments)]
19131548 pub(super) fn record_inter(
@@ -1971,7 +1606,6 @@ impl Neighbours {
19711606 skip_mode: bool,
19721607 ) {
19731608 let (r, c) = at_mi;
1974- crate::census::block(w_mi, h_mi, is_inter, ref_frame, skip);
19751609 // lane-t900 r8 (class new-map-ignores-tile-edge's twin: a map NOBODY
19761610 // writes for a whole block class): an INTER block left the luma mode
19771611 // map untouched, so a later intra block's `get_intra_edge_filter_type`
@@ -2077,7 +1711,6 @@ impl Neighbours {
20771711 compound_idx: u8,
20781712 ) {
20791713 let (r, c) = at_mi;
2080- crate::census::compound();
20811714 for cell in 0..w_mi {
20821715 self.above_ref1[c + cell] = Some(ref1);
20831716 self.above_comp_group_idx[c + cell] = comp_group_idx;
@@ -2118,7 +1751,11 @@ impl Neighbours {
21181751
21191752 /// [`Self::around`] taking the block's position directly in 4x4 mode-info
21201753 /// units, for the same reason [`Self::record_mi`] does.
2121- pub(super) fn around_mi(&self, (mi_r, mi_c): (usize, usize), side: usize) -> [(bool, bool, i32); 3] {
1754+ pub(super) fn around_mi(
1755+ &self,
1756+ (mi_r, mi_c): (usize, usize),
1757+ side: usize,
1758+ ) -> [(bool, bool, i32); 3] {
21221759 let side_mi = side / MI;
21231760 // One pass over the cells accumulating all three planes, not one pass
21241761 // per plane: the three planes of a cell live in the same
@@ -2183,45 +1820,18 @@ impl Neighbours {
21831820 o.2 += dc_vote(left[plane].dc);
21841821 }
21851822 }
2186- if crate::envflags::env_flag!("EC_DCDUMP") {
2187- // lane-av1422mi24: same dump [`Self::around_mi_rect`] prints, so
2188- // a rerouted 4:2:2 chroma gather stays visible under EC_DCDUMP=1.
2189- // The above rows are the SAMPLED (every-second) cells.
2190- for (plane, o) in out.iter().enumerate() {
2191- let vote = o.2;
2192- let ab: Vec<String> = (0..above_mi)
2193- .step_by(2)
2194- .map(|k| {
2195- format!(
2196- "{:?}/{}",
2197- self.above[mi_c + k][plane].dc,
2198- self.above[mi_c + k][plane].level
2199- )
2200- })
2201- .collect();
2202- let lf: Vec<String> = (0..left_mi)
2203- .map(|k| {
2204- format!(
2205- "{:?}/{}",
2206- self.left[mi_r + k][plane].dc,
2207- self.left[mi_r + k][plane].level
2208- )
2209- })
2210- .collect();
2211- eprintln!(
2212- "EC_DCDUMP422 mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]",
2213- ab.join(","),
2214- lf.join(",")
2215- );
2216- }
2217- }
22181823 out
22191824 }
22201825
22211826 /// [`Self::around`] with independent above (`w`)/left (`h`) extents, in
22221827 /// pixels -- lane-rectwire, mirrors [`Self::record_rect`]'s asymmetric
22231828 /// extent pattern for a true rectangular strip's own coefficient context.
2224- pub(super) fn around_rect(&self, (r, c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] {
1829+ pub(super) fn around_rect(
1830+ &self,
1831+ (r, c): (usize, usize),
1832+ w: usize,
1833+ h: usize,
1834+ ) -> [(bool, bool, i32); 3] {
22251835 self.around_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h)
22261836 }
22271837
@@ -2252,34 +1862,6 @@ impl Neighbours {
22521862 o.2 += dc_vote(left[plane].dc);
22531863 }
22541864 }
2255- if crate::envflags::env_flag!("EC_DCDUMP") {
2256- for (plane, o) in out.iter().enumerate() {
2257- let vote = o.2;
2258- let ab: Vec<String> = (0..above_mi)
2259- .map(|k| {
2260- format!(
2261- "{:?}/{}",
2262- self.above[mi_c + k][plane].dc,
2263- self.above[mi_c + k][plane].level
2264- )
2265- })
2266- .collect();
2267- let lf: Vec<String> = (0..left_mi)
2268- .map(|k| {
2269- format!(
2270- "{:?}/{}",
2271- self.left[mi_r + k][plane].dc,
2272- self.left[mi_r + k][plane].level
2273- )
2274- })
2275- .collect();
2276- eprintln!(
2277- "EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]",
2278- ab.join(","),
2279- lf.join(",")
2280- );
2281- }
2282- }
22831865 out
22841866 }
22851867
@@ -2297,8 +1879,12 @@ impl Neighbours {
22971879 /// [`Self::luma_skip_ctx`] with the unit's own width and height in mi
22981880 /// units (lane-rectsplitx r1) -- `get_txb_ctx_general` ORs the above
22991881 /// context over `tx_size_wide` and the left one over `tx_size_high`.
2300- pub(super) fn luma_skip_ctx_rect(&self, (mi_r, mi_c): (usize, usize), w_mi: usize, h_mi: usize) -> usize {
2301- let side_mi = w_mi;
1882+ pub(super) fn luma_skip_ctx_rect(
1883+ &self,
1884+ (mi_r, mi_c): (usize, usize),
1885+ w_mi: usize,
1886+ h_mi: usize,
1887+ ) -> usize {
23021888 let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c));
23031889 let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r));
23041890 let mut top = 0u8;
@@ -2310,35 +1896,6 @@ impl Neighbours {
23101896 left |= self.left[mi_r + cell][0].level;
23111897 }
23121898 let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)];
2313- if crate::envflags::env_flag!("EC_ECDUMP") {
2314- let ab: Vec<String> = (0..above_mi)
2315- .map(|k| self.above[mi_c + k][0].level.to_string())
2316- .collect();
2317- let lf: Vec<String> = (0..left_mi)
2318- .map(|k| self.left[mi_r + k][0].level.to_string())
2319- .collect();
2320- // lane-av1mix: the last few msac register states, so the
2321- // byte-position of the `all_zero` read can be matched against
2322- // aomdec's `EC=(value,rng,bytepos)` dump (decodetxb.c) without a
2323- // second run.
2324- let recent = crate::msac::symtrace::ecdump_recent(4)
2325- .iter()
2326- .map(|(_low, value, rng, bytepos)| format!("({value},{rng},{bytepos})"))
2327- .collect::<Vec<_>>()
2328- .join(" ");
2329- eprintln!(
2330- "EC_ECDUMP plane=0 mi=({mi_r},{mi_c}) wh=({w_mi},{h_mi}) ctx={ctx} above=[{},] left=[{},] recentEC=[{}]",
2331- ab.join(","),
2332- lf.join(","),
2333- recent
2334- );
2335- }
2336- if crate::envflags::env_flag!("EC_AV1_TRACE") {
2337- eprintln!(
2338- "TRACE luma_skip_ctx mi=({mi_r},{mi_c}) side_mi={side_mi} top={top} left={left} ctx={ctx} band={:?}",
2339- self.left.iter().map(|e| e[0].level).collect::<Vec<_>>()
2340- );
2341- }
23421899 ctx
23431900 }
23441901
@@ -2373,7 +1930,14 @@ impl Neighbours {
23731930 /// block to the right reads via `mi(row, col-1)`). Only sub-8x8 leaves
23741931 /// read these back, and only when the recorded position is exactly their
23751932 /// own neighbour -- see [`Self::sub8_mode_col`]'s doc.
2376- pub(super) fn record_mode_mi(&mut self, mi_r: usize, mi_c: usize, mi_w: usize, mi_h: usize, mode: usize) {
1933+ pub(super) fn record_mode_mi(
1934+ &mut self,
1935+ mi_r: usize,
1936+ mi_c: usize,
1937+ mi_w: usize,
1938+ mi_h: usize,
1939+ mode: usize,
1940+ ) {
23771941 let (last_r, last_c) = ((mi_r + mi_h - 1) as u16, (mi_c + mi_w - 1) as u16);
23781942 let mode = mode as u8;
23791943 for cell in 0..mi_w {
@@ -2451,9 +2015,6 @@ impl Neighbours {
24512015 for row in mi_r..=last_r {
24522016 fill_span(&mut self.uv_owner, row * stride + mi_c, n, owner);
24532017 }
2454- if crate::envflags::env_flag!("EC_LEFTSSY") {
2455- eprintln!("EC_LEAF mi=({mi_r},{mi_c}) wh=({mi_w},{mi_h}) uv_mode={uv_mode}");
2456- }
24572018 }
24582019
24592020 /// Whether either mi-exact chroma neighbour of the block at `(mi_r, mi_c)`
@@ -2503,7 +2064,6 @@ impl Neighbours {
25032064 c,
25042065 ss_x(fctx),
25052066 ss_y(fctx),
2506- true,
25072067 )
25082068 }
25092069
@@ -2512,18 +2072,6 @@ impl Neighbours {
25122072 /// counter wants this: it measures how often the snap CHANGES the answer,
25132073 /// which is what the lane-kf1200/kf900 chroma-reference fix buys. Every
25142074 /// decode path uses the snapping form.
2515- /// `decode_path` is `true` only for the snapping form every decode call
2516- /// site uses; the 16x4/4x16 pair witness's mirror passes `false`, so the
2517- /// `+ss_y` counters measure a read that actually filters a chroma edge and
2518- /// not the counter-only one.
2519- ///
2520- /// lane-av1leftwit: the mirror's justification used to be "no committed
2521- /// fixture reaches the shape on the decode path", and that was false --
2522- /// `UV_LEFT_1MI_SPLIT_HITS` fires on five of them. The flag stays (a
2523- /// counter-only mirror at an ODD mi row is still not a decode-path read,
2524- /// and its result feeds only `RECT4_16_UV_PAIR_FILT_HITS`), but it is no
2525- /// longer evidence about the `+ss_y` term, and nothing may cite it as such.
2526- /// The decode path's own reach is `uv_left_1mi_split_hits()`.
25272075 // Signature mirrors the spec's per-call inputs; a parameter struct would only move them.
25282076 #[allow(clippy::too_many_arguments)]
25292077 pub(super) fn smooth_uv_neighbour_unsnapped(
@@ -2534,7 +2082,6 @@ impl Neighbours {
25342082 c: usize,
25352083 ss_x: usize,
25362084 ss_y: usize,
2537- decode_path: bool,
25382085 ) -> bool {
25392086 // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the
25402087 // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid
@@ -2545,11 +2092,6 @@ impl Neighbours {
25452092 // at chroma (120, 32), the top-right tile's first block).
25462093 let have_above = mi_r > self.tile_row0_mi;
25472094 let have_left = mi_c > self.tile_col0_mi;
2548- if self.tile_row0_mi > 0 && !have_above && self.above_uv_mode[c] != DC_PRED
2549- || self.tile_col0_mi > 0 && !have_left && self.left_uv_mode[r] != DC_PRED
2550- {
2551- hit!(UV_TILE_EDGE_SUPPRESSED_HITS);
2552- }
25532095 // The mi grid is libaom's own read; the two maps below stay as the
25542096 // fallback for cells no block has written (see [`Self::uv_mode_grid`]).
25552097 let cell = |grid: &Vec<u8>, row: usize, col: usize| -> Option<usize> {
@@ -2637,67 +2179,6 @@ impl Neighbours {
26372179 // every committed fixture and every one of the ~1000 encodes swept in
26382180 // `lanes/av1leftref.report.md`, which is what makes the read change a
26392181 // proven no-op on today's material rather than an unmeasured guess.
2640- if decode_path && have_left && ss_y > 0 {
2641- hit!(UV_LEFT_SS_Y_READS);
2642- // The pre-lane read, kept as the counter's own-row arm: it is what
2643- // this decoder answered before the `+ss_y` term landed, and
2644- // comparing against it is what proves the term is load-bearing.
2645- let own_row = read_left(mi_r);
2646- if own_row != left {
2647- hit!(UV_LEFT_SS_Y_MODE_DIFF_HITS);
2648- }
2649- if is_smooth_mode(own_row) != is_smooth_mode(left) {
2650- hit!(UV_LEFT_SS_Y_SMOOTH_DIFF_HITS);
2651- }
2652- // lane-av1leftwit: the geometry the `+ss_y` term needs. The two
2653- // cells are one left mi column apart, so they are two different
2654- // blocks exactly when the left neighbour is 1 mi tall or shorter.
2655- let col = left_mi.1;
2656- let epoch = UV_OWNER_EPOCH.with(|c| c.get()) & 0xff00_0000;
2657- let own = (col < self.uv_grid_cols)
2658- .then(|| self.uv_owner.get(mi_r * self.uv_grid_cols + col).copied())
2659- .flatten()
2660- .filter(|o| o & 0xff00_0000 == epoch)
2661- .unwrap_or(0);
2662- let down = self
2663- .uv_owner
2664- .get((mi_r + ss_y) * self.uv_grid_cols + col)
2665- .copied()
2666- .filter(|o| o & 0xff00_0000 == epoch)
2667- .unwrap_or(0);
2668- if own != 0 && down != 0 && own != down {
2669- hit!(UV_LEFT_1MI_SPLIT_HITS);
2670- if crate::envflags::env_flag!("EC_LEFTSSY") {
2671- eprintln!(
2672- "EC_LEFTSSY epoch={} mi=({mi_r},{mi_c}) left_col={col} \
2673- owners=({},{})->({},{}) modes={own_row}/{left}",
2674- epoch >> 24,
2675- own >> 12 & 0xfff,
2676- own & 0xfff,
2677- down >> 12 & 0xfff,
2678- down & 0xfff,
2679- );
2680- }
2681- }
2682- }
2683- if have_above && cell(&self.uv_mode_grid, mi_r - 1, mi_c).is_some_and(|m| {
2684- !matches!(self.uv_mode_col.get(mi_c), Some(&(row, cm)) if usize::from(row) == mi_r - 1 && usize::from(cm) == m)
2685- }) || have_left && cell(&self.uv_mode_grid, left_mi.0, left_mi.1).is_some_and(|m| {
2686- !matches!(self.uv_mode_row.get(left_mi.0), Some(&(col, cm)) if usize::from(col) == left_mi.1 && usize::from(cm) == m)
2687- }) {
2688- hit!(UV_MODE_GRID_OVERRIDE_HITS);
2689- }
2690- // lane-cfl r1 counter: how often the mi-exact chroma neighbour differs
2691- // from the coarse [`SUB`] slot -- i.e. how often a chroma edge would
2692- // have been filtered at the wrong strength by the coarse map alone.
2693- if above != self.above_uv_mode[c] || left != self.left_uv_mode[r] {
2694- hit!(UV_MODE_MI_OVERRIDE_HITS);
2695- }
2696- if (is_smooth_mode(self.above_uv_mode[c]) && !is_smooth_mode(above))
2697- || (is_smooth_mode(self.left_uv_mode[r]) && !is_smooth_mode(left))
2698- {
2699- hit!(INTER_NEIGHBOUR_NOT_SMOOTH_HITS);
2700- }
27012182 is_smooth_mode(above) || is_smooth_mode(left)
27022183 }
27032184
@@ -2750,21 +2231,6 @@ impl Neighbours {
27502231 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
27512232 let (above, left) =
27522233 self.modes_above_left_mi(mi_r, mi_c, (self.above_mode[c], self.left_mode[r]));
2753- if above != self.above_mode[c] || left != self.left_mode[r] {
2754- hit!(MODE_MI_OVERRIDE_HITS);
2755- }
2756- if (is_smooth_mode(self.above_mode[c]) && !is_smooth_mode(above))
2757- || (is_smooth_mode(self.left_mode[r]) && !is_smooth_mode(left))
2758- {
2759- hit!(INTER_NEIGHBOUR_NOT_SMOOTH_HITS);
2760- }
2761- // A neighbour the coarse band offered where the tile edge makes it
2762- // unavailable -- must never happen (see `MODE_TILE_EDGE_COARSE_LEAKS`).
2763- if (mi_r <= self.tile_row0_mi && self.above_mode[c] != DC_PRED)
2764- || (mi_c <= self.tile_col0_mi && self.left_mode[r] != DC_PRED)
2765- {
2766- hit!(MODE_TILE_EDGE_COARSE_LEAKS);
2767- }
27682234 (above, left)
27692235 }
27702236
@@ -2864,16 +2330,16 @@ impl Neighbours {
28642330
28652331 /// [`Self::record_mi`] with independent above (`w`)/left (`h`) extents,
28662332 /// in pixels (lane-partitions r1, mirroring [`Self::record_rect`]).
2867- pub(super) fn record_mi_rect(&mut self, at_mi: (usize, usize), w: usize, h: usize, grids: &[&[i32]; 3]) {
2333+ pub(super) fn record_mi_rect(
2334+ &mut self,
2335+ at_mi: (usize, usize),
2336+ w: usize,
2337+ h: usize,
2338+ grids: &[&[i32]; 3],
2339+ ) {
28682340 let (mi_r, mi_c) = at_mi;
28692341 let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(grids[plane]));
28702342 let (w_mi, h_mi) = (w / MI, h / MI);
2871- if crate::envflags::env_flag!("EC_ECPUB") {
2872- eprintln!(
2873- "EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}",
2874- states[0].level
2875- );
2876- }
28772343 fill_span(&mut self.left_side_mi, mi_r, h_mi, h as u8);
28782344 fill_span(&mut self.above_side_mi, mi_c, w_mi, w as u8);
28792345 // A chroma 4x4 unit straddling the true luma edge is still whole in
@@ -2964,27 +2430,10 @@ impl Neighbours {
29642430 // units rather than in luma mi.
29652431 let (step_x, step_y) = (w_px / MI, h_px / MI);
29662432 // the flags read the CALLER's origin, before the shadowing align below
2967- let (row_mid, col_mid) = (mi_r & (step_y - 1) != 0, mi_c & (step_x - 1) != 0);
2968- if row_mid || col_mid {
2969- CHROMA_MIDCELL_PUB_HITS.with(|c| {
2970- let mut v = c.get();
2971- v[0] += usize::from(row_mid);
2972- v[1] += usize::from(col_mid);
2973- v[2] += usize::from(row_mid && col_mid);
2974- c.set(v);
2975- });
2976- }
29772433 let (mi_r, mi_c) = (mi_r & !(step_y - 1), mi_c & !(step_x - 1));
29782434 let round_up_even = |n: usize| n.div_ceil(2) * 2;
29792435 let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols));
29802436 let state = neighbour_state(grid);
2981- if crate::envflags::env_flag!("EC_CHROMA_PUB") {
2982- eprintln!(
2983- "EC_CHROMA_PUB plane={plane} mi=({mi_r},{mi_c}) wh=({w_px},{h_px}) lvl={} dc={}",
2984- state.level,
2985- state.dc.map_or(-1, i32::from)
2986- );
2987- }
29882437 for cell in 0..(h_px / MI).min(bound_h.saturating_sub(mi_r)) {
29892438 self.left[mi_r + cell][plane] = state;
29902439 }
@@ -3004,12 +2453,6 @@ impl Neighbours {
30042453 grid: &[i32],
30052454 ) {
30062455 let state = neighbour_state(grid);
3007- if crate::envflags::env_flag!("EC_ECPUB") {
3008- eprintln!(
3009- "EC_ECPUB tu mi=({mi_r},{mi_c}) wh=({w_px},{h_px}) lvl={}",
3010- state.level
3011- );
3012- }
30132456 for cell in 0..h_px / MI {
30142457 if mi_r + cell < self.mi_rows {
30152458 self.left[mi_r + cell][0] = state;
@@ -3600,21 +3043,9 @@ pub(super) fn decode_color_index_map_wh(
36003043 on: (usize, usize),
36013044 uv: bool,
36023045 ) -> Vec<u8> {
3603- let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
36043046 let (on_bw, on_bh) = (on.0.clamp(1, bw), on.1.clamp(1, bh));
3605- if on_bw < bw || on_bh < bh {
3606- hit!(PALETTE_ONSCREEN_CUT_HITS);
3607- }
36083047 let mut map = vec![0u8; bw * bh];
3609- if trace {
3610- let (rng, _) = dec.debug_state();
3611- eprintln!("EC_PAL row=0 col=0 ctx=-1 n={n} rng={rng}");
3612- }
36133048 map[0] = read_uniform(dec, n) as u8;
3614- if trace {
3615- let (rng, _) = dec.debug_state();
3616- eprintln!("EC_PAL_VAL row=0 col=0 color_idx={} rng={rng}", map[0]);
3617- }
36183049 for i in 1..(on_bw + on_bh - 1) {
36193050 let j_hi = i.min(on_bw - 1);
36203051 let j_lo = i.saturating_sub(on_bh - 1);
@@ -3622,28 +3053,12 @@ pub(super) fn decode_color_index_map_wh(
36223053 let row = i - j;
36233054 let col = j;
36243055 let (ctx, color_order) = palette_color_index_context(&map, bw, row, col, n);
3625- if trace {
3626- let (rng, _) = dec.debug_state();
3627- let row_cdf = if uv {
3628- &cdfs.palette_uv_color_index[n - 2][ctx]
3629- } else {
3630- &cdfs.palette_y_color_index[n - 2][ctx]
3631- };
3632- eprintln!(
3633- "EC_PAL row={row} col={col} ctx={ctx} n={n} cdf0={} cnt={} rng={rng}",
3634- row_cdf[0], row_cdf[n]
3635- );
3636- }
36373056 let symbol = if uv {
36383057 dec.symbol(&mut cdfs.palette_uv_color_index[n - 2][ctx][..=n])
36393058 } else {
36403059 dec.symbol(&mut cdfs.palette_y_color_index[n - 2][ctx][..=n])
36413060 };
36423061 map[row * bw + col] = color_order[symbol];
3643- if trace {
3644- let (rng, _) = dec.debug_state();
3645- eprintln!("EC_PAL_VAL row={row} col={col} color_idx={symbol} rng={rng}");
3646- }
36473062 }
36483063 }
36493064 palette_replicate(&mut map, bw, bh, on);
@@ -3673,9 +3088,6 @@ pub(crate) fn palette_replicate(map: &mut [u8], bw: usize, bh: usize, on: (usize
36733088 /// it lands away from zero, for gate tests to prove a real stream fired one.
36743089 pub(super) fn read_angle_delta(dec: &mut SymbolDecoder, cdf: &mut [u16]) -> i32 {
36753090 let symbol = dec.symbol(cdf);
3676- if symbol != ANGLE_DELTA_ZERO {
3677- hit!(ANGLE_DELTA_HITS);
3678- }
36793091 symbol as i32 - ANGLE_DELTA_ZERO as i32
36803092 }
36813093
@@ -3714,9 +3126,6 @@ pub(super) fn apply_deblock(
37143126 ) {
37153127 // lane-part32 r2 debug rung, env-gated: bisecting a widespread pixel
37163128 // mismatch between the raw reconstruction and post-filter output.
3717- if crate::envflags::env_flag!("EC_AV1_DEBUG_SKIP_DEBLOCK") {
3718- return;
3719- }
37203129 if lf.level[0] != 0 || lf.level[1] != 0 {
37213130 deblock_plane(y, 0, lf, n, frame_width, frame_height, fctx);
37223131 }
@@ -3806,9 +3215,7 @@ pub(super) fn tx_size_context_txfm_rect(
38063215 (mi_r, mi_c): (usize, usize),
38073216 own_w: usize,
38083217 own_h: usize,
3809- fctx: &crate::decode::FrameCtx,
38103218 ) -> usize {
3811- hit!(INTRA_IN_INTER_TXCTX_HITS);
38123219 // `max_txsize_rect_lookup[bsize]` tops out at TX_64X64: no transform is
38133220 // wider or taller than 64, so a block with a 128 side resolves against 64
38143221 // (lane-sb128b r1).
@@ -3857,31 +3264,7 @@ pub(super) fn tx_size_context_txfm_rect(
38573264 };
38583265 if band_above != (has_above && usize::from(above) != 0)
38593266 || band_left != (has_left && usize::from(left) != 0)
3860- {
3861- hit!(TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS);
3862- }
3863- }
3864- if crate::envflags::env_flag!("EC_TXCTX") {
3865- eprintln!(
3866- "EC_TXCTX mi={mi_r},{mi_c} own={own_w}x{own_h} ha={has_above} hl={has_left} \
3867- intra_only={} above_txfm={} left_txfm={} above_inter={} left_inter={} \
3868- above_side={} left_side={} above={above} left={left} \
3869- | cell_inter ab={} lb={} ab_side={} lb_side={}",
3870- fctx.intra_only.with(std::cell::Cell::get),
3871- n.above_txfm[mi_c],
3872- n.left_txfm[mi_r],
3873- n.above_inter[mi_c],
3874- n.left_inter[mi_r],
3875- n.above_side_mi[mi_c],
3876- n.left_side_mi[mi_r],
3877- // lane-av1txctxband: the per-CELL terms this read now uses, next to
3878- // the per-column bands it used to use, so a divergence names which
3879- // of the two disagreed.
3880- if has_above { n.inter_at(mi_r - 1, mi_c) } else { false },
3881- if has_left { n.inter_at(mi_r, mi_c - 1) } else { false },
3882- if has_above { n.blk_side_at(mi_r - 1, mi_c).0 } else { 0 },
3883- if has_left { n.blk_side_at(mi_r, mi_c - 1).1 } else { 0 },
3884- );
3267+ {}
38853268 }
38863269 let ctx = match (has_above, has_left) {
38873270 (true, true) => usize::from(above) + usize::from(left),
@@ -3889,13 +3272,6 @@ pub(super) fn tx_size_context_txfm_rect(
38893272 (false, true) => usize::from(left),
38903273 (false, false) => 0,
38913274 };
3892- {
3893- let stale = usize::from(has_above && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w)
3894- + usize::from(has_left && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h);
3895- if ctx != stale {
3896- hit!(TXCTX_DEBLOCK_DIVERGENCE_HITS);
3897- }
3898- }
38993275 ctx
39003276 }
39013277
@@ -3905,7 +3281,11 @@ pub(super) fn tx_size_context_txfm_rect(
39053281 /// override above fired on the wrong neighbour -- the first divergence of the
39063282 /// 10-bit gate's stream was exactly this (`tx_depth` ctx 0 where libaom has 1,
39073283 /// at the intra block right of an inter one).
3908-pub(super) fn tx_size_context_txfm(n: &Neighbours, (mi_r, mi_c): (usize, usize), side: usize) -> usize {
3284+pub(super) fn tx_size_context_txfm(
3285+ n: &Neighbours,
3286+ (mi_r, mi_c): (usize, usize),
3287+ side: usize,
3288+) -> usize {
39093289 let has_above = mi_r > n.tile_row0_mi;
39103290 let has_left = mi_c > n.tile_col0_mi;
39113291 let mut above = usize::from(n.above_txfm[mi_c]) >= side;
@@ -3948,26 +3328,7 @@ pub(super) fn tx_size_context_txfm(n: &Neighbours, (mi_r, mi_c): (usize, usize),
39483328 };
39493329 if band_above != (has_above && usize::from(above) != 0)
39503330 || band_left != (has_left && usize::from(left) != 0)
3951- {
3952- hit!(TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS);
3953- }
3954- }
3955- if crate::envflags::env_flag!("EC_TXCTX") {
3956- eprintln!(
3957- "EC_TXCTX mi={mi_r},{mi_c} own={side} ha={has_above} hl={has_left} \
3958- above_txfm={} left_txfm={} above_inter={} left_inter={} above_side={} left_side={} \
3959- above={above} left={left} | cell_inter ab={} lb={} ab_side={} lb_side={}",
3960- n.above_txfm[mi_c],
3961- n.left_txfm[mi_r],
3962- n.above_inter[mi_c],
3963- n.left_inter[mi_r],
3964- n.above_side_mi[mi_c],
3965- n.left_side_mi[mi_r],
3966- if has_above { n.inter_at(mi_r - 1, mi_c) } else { false },
3967- if has_left { n.inter_at(mi_r, mi_c - 1) } else { false },
3968- if has_above { n.blk_side_at(mi_r - 1, mi_c).0 } else { 0 },
3969- if has_left { n.blk_side_at(mi_r, mi_c - 1).1 } else { 0 },
3970- );
3331+ {}
39713332 }
39723333 match (has_above, has_left) {
39733334 (true, true) => usize::from(above) + usize::from(left),
@@ -4014,16 +3375,6 @@ pub(super) fn read_tx_size(
40143375 64 => dec.symbol(&mut cdfs.tx_size_cat3[ctx]),
40153376 _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64/128"),
40163377 };
4017- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
4018- let (rng, _) = dec.debug_state();
4019- let (mi_r, mi_c) = at_mi;
4020- eprintln!(
4021- "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={depth} ctx={ctx} rng={rng}"
4022- );
4023- }
4024- if depth != 0 {
4025- hit!(TX_DEPTH_HITS);
4026- }
40273378 max_tx >> depth
40283379 }
40293380
@@ -4033,7 +3384,12 @@ pub(super) fn read_tx_size(
40333384 /// the two neighbour terms (whether the transform last written above/left of
40343385 /// this unit is narrower/shorter than the unit itself).
40353386 #[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4036-pub(super) fn txfm_partition_ctx(above_px: u8, left_px: u8, blk_max_px: usize, tx_px: usize) -> usize {
3387+pub(super) fn txfm_partition_ctx(
3388+ above_px: u8,
3389+ left_px: u8,
3390+ blk_max_px: usize,
3391+ tx_px: usize,
3392+) -> usize {
40373393 txfm_partition_ctx_rect(above_px, left_px, blk_max_px, tx_px, tx_px)
40383394 }
40393395
@@ -4066,7 +3422,12 @@ pub(crate) fn txfm_partition_ctx_rect(
40663422 /// resolves, every mi cell its *parent* unit (`txb_px`) spans records the
40673423 /// resolved transform's own size.
40683424 #[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4069-pub(super) fn txfm_partition_update(n: &mut Neighbours, at_mi: (usize, usize), tx_px: usize, txb_px: usize) {
3425+pub(super) fn txfm_partition_update(
3426+ n: &mut Neighbours,
3427+ at_mi: (usize, usize),
3428+ tx_px: usize,
3429+ txb_px: usize,
3430+) {
40703431 txfm_partition_update_rect(n, at_mi, (tx_px, tx_px), (txb_px, txb_px));
40713432 }
40723433
@@ -4136,12 +3497,6 @@ pub(super) fn txfm_partition_update_rect(
41363497 (tx_w, tx_h): (usize, usize),
41373498 (txb_w, txb_h): (usize, usize),
41383499 ) {
4139- if crate::envflags::env_flag!("EC_TXUPD") {
4140- eprintln!(
4141- "EC_TXUPD rect mi=({},{}) tx=({tx_w},{tx_h}) txb=({txb_w},{txb_h})",
4142- mi_r, mi_c
4143- );
4144- }
41453500 for i in 0..txb_h / MI {
41463501 if let Some(cell) = n.left_txfm.get_mut(mi_r + i) {
41473502 *cell = tx_h as u8;
@@ -4165,11 +3520,6 @@ pub(super) fn set_txfm_ctxs(
41653520 h_mi: usize,
41663521 skip_inter: bool,
41673522 ) {
4168- if crate::envflags::env_flag!("EC_TXUPD") {
4169- eprintln!(
4170- "EC_TXUPD ctxs mi=({mi_r},{mi_c}) tx={tx_px} wh=({w_mi},{h_mi}) skip_inter={skip_inter}"
4171- );
4172- }
41733523 let bw = if skip_inter { w_mi * MI } else { tx_px };
41743524 let bh = if skip_inter { h_mi * MI } else { tx_px };
41753525 for i in 0..w_mi {
@@ -4439,22 +3789,11 @@ pub(super) fn read_var_tx_size(
44393789 tx_h,
44403790 );
44413791 let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1;
4442- hit!(TXFM_SPLIT_READS);
4443- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
4444- let (rng, _) = dec.debug_state();
4445- eprintln!(
4446- "EC_ISTEP mi_row={} mi_col={} name=txfm_split val={} ctx={ctx} rng={rng}",
4447- unit.0,
4448- unit.1,
4449- u8::from(split)
4450- );
4451- }
44523792 if !split {
44533793 out.push((blk_row, blk_col, tx_w, tx_h));
44543794 txfm_partition_update_rect(n, unit, (tx_w, tx_h), (tx_w, tx_h));
44553795 return;
44563796 }
4457- hit!(TXFM_SPLIT_HITS);
44583797 let (sub_w, sub_h) = sub_tx_size_map(tx_w, tx_h);
44593798 if (sub_w, sub_h) == (4, 4) {
44603799 // libaom's `sub_txs == TX_4X4` early return: every mi cell of the
crates/ec-av1/src/decode/counters.rsdeleted+0 -4459

Diff too large; view file

@@ -1,4459 +0,0 @@
1-//! Hit and census counters of the decode path: thread-local tallies bumped by the
2-//! `hit!` instrumentation and read back by the gate tests. Moved out of `decode/mod.rs`
3-//! by name (av1split D3); the items are unchanged except for `pub(super)` visibility.
4-
5-use super::*;
6-
7-// How many real 128-level partition symbols this decoder has read, and how
8-// many superblocks resolved to `PARTITION_SPLIT` (coded or forced) -- the
9-// gate's proof a `--sb-size=128` stream exercised the 128 partition root.
10-thread_local! {
11- pub(super) static PART128_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
12-}
13-
14-/// Current value of [`PART128_SPLIT_HITS`].
15-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
16-pub(crate) fn part128_split_hits() -> usize {
17- PART128_SPLIT_HITS.with(|c| c.get())
18-}
19-
20-// How many `use_filter_intra` symbols this decoder has read as `1`, across
21-// every call on the current thread -- the cheap counter [`filter_intra_hits`] gate
22-// tests read (before/after, not the absolute value) to prove a stream
23-// actually exercised the filter-intra predictor rather than silently
24-// skipping it.
25-thread_local! {
26- pub(super) static FILTER_INTRA_HITS: std::cell::Cell<usize> =
27- const { std::cell::Cell::new(0) };
28-}
29-
30-/// Current value of [`FILTER_INTRA_HITS`].
31-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
32-pub(crate) fn filter_intra_hits() -> usize {
33- FILTER_INTRA_HITS.with(|c| c.get())
34-}
35-
36-// lane-fiinter r1: how many of those `use_filter_intra == 1` symbols belonged
37-// to an INTRA block inside an INTER frame (`read_intra_block_mode_info`'s own
38-// `read_filter_intra_mode_info` call), which no gate exercised before this
39-// round -- every inter gate recipe passed `--enable-filter-intra=0`.
40-thread_local! {
41- pub(super) static INTRA_IN_INTER_FILTER_INTRA_HITS: std::cell::Cell<usize> =
42- const { std::cell::Cell::new(0) };
43-}
44-
45-/// Current value of [`INTRA_IN_INTER_FILTER_INTRA_HITS`].
46-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
47-pub(crate) fn intra_in_inter_filter_intra_hits() -> usize {
48- INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.get())
49-}
50-
51-// lane-angleinter r1: how many INTRA blocks inside an INTER frame carried a
52-// nonzero `angle_delta_y` / `angle_delta_uv` (`read_intra_angle_info`). Both
53-// arms refused a nonzero luma delta before this round, and no inter gate
54-// enabled `--enable-angle-delta` (aomenc's own default is 1).
55-thread_local! {
56- pub(super) static INTRA_IN_INTER_ANGLE_DELTA_Y_HITS: std::cell::Cell<usize> =
57- const { std::cell::Cell::new(0) };
58- pub(super) static INTRA_IN_INTER_ANGLE_DELTA_UV_HITS: std::cell::Cell<usize> =
59- const { std::cell::Cell::new(0) };
60-}
61-
62-/// Current value of [`INTRA_IN_INTER_ANGLE_DELTA_Y_HITS`].
63-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
64-pub(crate) fn intra_in_inter_angle_delta_y_hits() -> usize {
65- INTRA_IN_INTER_ANGLE_DELTA_Y_HITS.with(|c| c.get())
66-}
67-
68-/// Current value of [`INTRA_IN_INTER_ANGLE_DELTA_UV_HITS`].
69-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
70-pub(crate) fn intra_in_inter_angle_delta_uv_hits() -> usize {
71- INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|c| c.get())
72-}
73-
74-// lane-uv8 r1: the three non-DC chroma mode classes an INTRA 8x8 leaf inside
75-// an INTER frame ([`decode_inter_block8`]'s intra arm) can carry -- the arm
76-// read `uv_mode` and then refused everything but `DC_PRED`. Counted here and
77-// nowhere else so the gate's assert cannot be satisfied by a >=16x16 block.
78-thread_local! {
79- pub(super) static INTRA_IN_INTER8_UV_DIR_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
80- pub(super) static INTRA_IN_INTER8_UV_SMOOTH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
81- pub(super) static INTRA_IN_INTER8_UV_CFL_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
82-}
83-
84-thread_local! {
85- pub(super) static INTRA_IN_INTER8_ANGLE_DELTA_Y_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
86-}
87-
88-/// Nonzero luma angle deltas coded by an intra 8x8 leaf inside an inter frame
89-/// (lane-leaf8tx r1) -- counted only in [`decode_inter_block8`]'s intra arm.
90-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
91-pub(crate) fn intra_in_inter8_angle_delta_y_hits() -> usize {
92- INTRA_IN_INTER8_ANGLE_DELTA_Y_HITS.with(|c| c.get())
93-}
94-
95-/// `(directional, smooth/paeth, CfL)` chroma modes coded by an intra 8x8 leaf
96-/// inside an inter frame -- see [`INTRA_IN_INTER8_UV_DIR_HITS`].
97-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
98-pub(crate) fn intra_in_inter8_uv_hits() -> (usize, usize, usize) {
99- (
100- INTRA_IN_INTER8_UV_DIR_HITS.with(|c| c.get()),
101- INTRA_IN_INTER8_UV_SMOOTH_HITS.with(|c| c.get()),
102- INTRA_IN_INTER8_UV_CFL_HITS.with(|c| c.get()),
103- )
104-}
105-
106-// Whether this superblock's single CDEF unit (this decoder has no 128x128
107-// SB, so the SB IS the CDEF unit) has already had its `cdef_idx` literal
108-// read -- reset to `false` at the top of each superblock in the two tile
109-// loops, spec `read_cdef`'s `cdef_transmitted[index]`.
110-// Number of superblock columns in the current tile's grid, so
111-// [`maybe_read_cdef_idx`] can turn an `(mi_r, mi_c)` into a flat index into
112-// [`CDEF_IDX_GRID`].
113-// One resolved `cdef_idx` per superblock, read by [`apply_cdef`] to select
114-// which of the header's `1 << cdef.bits` strength pairs applies to that
115-// superblock's samples.
116-// How many real (`cdef.bits > 0`) `cdef_idx` literals [`maybe_read_cdef_idx`]
117-// has read, across every call on the current thread -- the gate's proof that a
118-// `cdef_bits > 0` stream actually reached the new reader rather than every
119-// superblock coincidentally being all-skip.
120-thread_local! {
121- pub(super) static CDEF_IDX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
122-}
123-
124-// How many times a warp was suppressed for one PLANE because that plane's own
125-// block is narrower or shorter than 8 (`av1_init_warp_params`'s own bail-out,
126-// reconinter.c) -- the gate's proof that a stream really carries the shape,
127-// since the square `side`/`chroma_side` can be 8 or more while the plane's
128-// true block is 4 wide (an 8x16 luma block's 4x8 chroma).
129-thread_local! {
130- pub(super) static WARP_PLANE_SUPPRESS_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
131-}
132-
133-/// Current value of [`WARP_PLANE_SUPPRESS_HITS`].
134-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
135-pub(crate) fn warp_plane_suppress_hits() -> usize {
136- WARP_PLANE_SUPPRESS_HITS.with(|c| c.get())
137-}
138-
139-/// Current value of [`CDEF_IDX_HITS`].
140-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
141-pub(crate) fn cdef_idx_hits() -> usize {
142- CDEF_IDX_HITS.with(|c| c.get())
143-}
144-
145-// lane-t900 r6: gate proof for the three r2-r4 root causes that shipped with no
146-// counter -- the in-inter tx-depth context (`tx_size_context_txfm_rect`), the
147-// non-chroma-reference block that must LEAVE its neighbours' chroma coefficient
148-// contexts alone, and the intra-edge filter neighbour pair taken mi-exact
149-// instead of from the coarse 16x16 cell.
150-thread_local! {
151- pub(super) static INTRA_IN_INTER_TXCTX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
152- pub(super) static NON_CHROMA_REF_CTX_SKIP_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
153- pub(super) static EDGE_FILTER_MI_FIX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
154-}
155-
156-/// Current value of [`INTRA_IN_INTER_TXCTX_HITS`].
157-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
158-pub(crate) fn intra_in_inter_txctx_hits() -> usize {
159- INTRA_IN_INTER_TXCTX_HITS.with(|c| c.get())
160-}
161-
162-/// Current value of [`NON_CHROMA_REF_CTX_SKIP_HITS`].
163-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
164-pub(crate) fn non_chroma_ref_ctx_skip_hits() -> usize {
165- NON_CHROMA_REF_CTX_SKIP_HITS.with(|c| c.get())
166-}
167-
168-/// Current value of [`EDGE_FILTER_MI_FIX_HITS`].
169-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
170-pub(crate) fn edge_filter_mi_fix_hits() -> usize {
171- EDGE_FILTER_MI_FIX_HITS.with(|c| c.get())
172-}
173-
174-// lane-realworld r4: this frame's `delta.q_present` (spec 5.9.17) and its
175-// actual step (`1 << delta.q_res`, already the real multiplier, not the raw
176-// 2-bit field). `false`/`1` (the defaults) make [`maybe_read_delta_q`] a
177-// true no-op, matching every existing gate stream's `delta_q_present == 0`
178-// behaviour exactly, the same corner-cut [`CDEF_BITS`] takes above.
179-// The running quantizer index (spec `CurrentQIndex`, libaom
180-// `xd->current_base_qindex`) -- reset to the frame's own `base_q_idx` at the
181-// top of every tile (spec `decode_tile`), carried across superblocks within
182-// that tile, and mutated only by [`maybe_read_delta_q`]. Read back at the
183-// dequantization call sites instead of the frame-constant `base_q_idx`.
184-// This frame's own per-plane DC/AC quantizer-index deltas (lane-sbpart r11,
185-// spec 5.9.12/7.12.2, [`crate::quant::QuantDeltas`]) -- frame-constant (not
186-// per-superblock like [`CURRENT_Q_IDX`]), set once per frame decode and read
187-// back at every dequantization call site keyed on which plane it is doing.
188-// How many real `delta_q_present` symbol groups [`maybe_read_delta_q`] has
189-// read, across every call on the current thread -- the gate's proof that a
190-// `delta_q_present` stream actually reached the new reader.
191-thread_local! {
192- pub(super) static DELTA_Q_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
193-}
194-
195-/// Current value of [`DELTA_Q_HITS`].
196-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
197-pub(crate) fn delta_q_hits() -> usize {
198- DELTA_Q_HITS.with(|c| c.get())
199-}
200-
201-// lane-realworld r5: this frame's `delta.lf_present`/`lf_res`/`lf_multi`
202-// (spec 5.9.18) -- same no-op-by-default corner-cut as `DELTA_Q_PRESENT`.
203-// The running per-plane/direction loop-filter delta (spec `DeltaLF[i]`,
204-// `i` in `0..FRAME_LF_COUNT`) -- reset to `[0; 4]` at the top of every tile,
205-// mutated only by [`maybe_read_delta_lf`]. `!delta_lf_multi` mode only ever
206-// updates index 0 and every reader treats that as the value for all 4
207-// indices (spec `read_delta_lf_params`'s own single-cdf branch).
208-// How many real `delta_lf_present` symbol groups [`maybe_read_delta_lf`] has
209-// read -- the gate's proof the reader fired, mirroring [`DELTA_Q_HITS`].
210-thread_local! {
211- pub(super) static DELTA_LF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
212-}
213-
214-/// Current value of [`DELTA_LF_HITS`].
215-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
216-pub(crate) fn delta_lf_hits() -> usize {
217- DELTA_LF_HITS.with(|c| c.get())
218-}
219-
220-// ---------------------------------------------------------------------------
221-// lane-seg: segmentation. Header (spec 5.9.14) is parsed by `ec-av1-syntax`;
222-// this block is the per-block `segment_id` reader (spec 5.11.7-5.11.9) plus
223-// the two consumers a real stream exercises: the per-segment quantizer index
224-// (spec 7.12.2 `get_qindex`) and the per-segment loop-filter level
225-// (spec 7.14.4). Shapes follow libaom `decodemv.c:read_segment_id`/
226-// `read_intra_segment_id`/`read_inter_segment_id` and
227-// `pred_common.h:av1_get_spatial_seg_pred` -- note libaom returns the SPATIAL
228-// PREDICTION (not 0) from `read_segment_id` when the block is `skip`, which
229-// is what the oracle every gate here compares against actually does.
230-thread_local! {
231- /// `CurrentSegmentIds`: this frame's own map, `mi_rows * mi_cols` entries
232- /// with stride `mi_cols` (NOT the padded `Neighbours` grid stride).
233- /// `PrevSegmentIds`: the primary reference frame's saved map, empty when
234- /// this frame has no primary reference (spec `load_previous_segment_ids`).
235- /// `(mi_rows, mi_cols)` for both maps above.
236- /// `AboveSegPredContext` (per mi column) / `LeftSegPredContext` (per mi
237- /// row) -- spec 5.11.9's own `seg_id_predicted` neighbour state, which
238- /// libaom keeps on the neighbouring `mbmi->seg_id_predicted` instead.
239- /// The block currently being decoded -- read back by [`block_q_idx`].
240- /// The tile's own top-left mi position, for `AvailU`/`AvailL`.
241- /// How many real `segment_id` symbols were read, and the set of segment
242- /// ids any block ended up with -- the gate's proof the feature fired.
243- pub(super) static SEG_ID_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
244- /// How many `seg_id_predicted` symbols were read (temporal update).
245- pub(super) static SEG_PRED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
246-}
247-
248-/// How many `segment_id` symbols have been read (never reset per frame).
249-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
250-pub(crate) fn segment_id_hits() -> usize {
251- SEG_ID_HITS.with(|c| c.get())
252-}
253-
254-/// How many `seg_id_predicted` symbols have been read (temporal update).
255-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
256-pub(crate) fn segment_pred_hits() -> usize {
257- SEG_PRED_HITS.with(|c| c.get())
258-}
259-
260-/// Resets the segmentation hit counters (gate setup).
261-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
262-pub(crate) fn reset_segment_hits() {
263- SEG_ID_HITS.with(|c| c.set(0));
264- SEG_IDS_SEEN.with(|c| c.set(0));
265- SEG_PRED_HITS.with(|c| c.set(0));
266- BLOCK_Q_SPAN.with(|c| c.set((i32::MAX, i32::MIN)));
267-}
268-
269-// How many key-frame luma blocks resolved `smooth_neighbor` (spec
270-// `get_intra_edge_filter_type`) to `true` -- lane-chroma r2's own before/after
271-// counter, proving a stream actually put a directional block next to a
272-// smooth-predicted neighbour rather than every block reading the (previously
273-// hardcoded `false`) edge-filter strength bucket unchanged.
274-thread_local! {
275- pub(super) static SMOOTH_LUMA_HITS: std::cell::Cell<usize> =
276- const { std::cell::Cell::new(0) };
277-}
278-
279-/// Current value of [`SMOOTH_LUMA_HITS`].
280-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
281-pub(crate) fn smooth_luma_hits() -> usize {
282- SMOOTH_LUMA_HITS.with(|c| c.get())
283-}
284-
285-thread_local! {
286- /// lane-band46 r1: how many split-transform units answered their intra
287- /// reach DIFFERENTLY under libaom's per-unit rules ([`Reach::of_tu`], the
288- /// palette2 r12 fix) than the standalone-block lookup this decoder used to
289- /// apply to them (class reach-is-per-transform-unit). Every hit is a
290- /// transform unit whose above-right / below-left reference samples would
291- /// be wrong without that fix.
292- pub(super) static SPLIT_TU_REACH_FIX_HITS: std::cell::Cell<usize> =
293- const { std::cell::Cell::new(0) };
294-}
295-
296-/// Current value of [`SPLIT_TU_REACH_FIX_HITS`].
297-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
298-pub(crate) fn split_tu_reach_fix_hits() -> usize {
299- SPLIT_TU_REACH_FIX_HITS.with(|c| c.get())
300-}
301-
302-// How many `uv_mode` reads resolved to `SMOOTH_PRED..=PAETH_PRED` (9..=12),
303-// across every call on the current thread -- lane-chroma r3's own before/after
304-// counter, proving a stream actually exercised chroma's smooth/paeth
305-// predictor (the previously-refused round-2 gap) rather than every block
306-// landing on DC/CFL/directional.
307-thread_local! {
308- pub(super) static SMOOTH_UV_HITS: std::cell::Cell<usize> =
309- const { std::cell::Cell::new(0) };
310-}
311-
312-/// Current value of [`SMOOTH_UV_HITS`].
313-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
314-pub(crate) fn smooth_uv_hits() -> usize {
315- SMOOTH_UV_HITS.with(|c| c.get())
316-}
317-
318-// How many tiles [`decode_key_frame_tile_with_cdfs`] has actually decoded a
319-// full superblock walk over, across every call on the current thread --
320-// lane-tiles r2's own gate-blind-to-feature guard: a gate over a
321-// multi-tile stream must prove more than one tile actually fired, not just
322-// that the stream carried tile_info.cols > 1.
323-thread_local! {
324- pub(super) static TILE_HITS: std::cell::Cell<usize> =
325- const { std::cell::Cell::new(0) };
326-}
327-
328-/// Current value of [`TILE_HITS`].
329-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
330-pub(crate) fn tile_hits() -> usize {
331- TILE_HITS.with(|c| c.get())
332-}
333-
334-// How many 4-pixel deblocking edge groups [`edge_params`] has actually
335-// selected for filtering, across every call on the current thread -- the same
336-// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream
337-// exercised `apply_deblock` rather than every edge landing on level 0.
338-thread_local! {
339- pub(super) static DEBLOCK_HITS: std::cell::Cell<usize> =
340- const { std::cell::Cell::new(0) };
341-}
342-
343-/// Current value of [`DEBLOCK_HITS`].
344-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
345-pub(crate) fn deblock_hits() -> usize {
346- DEBLOCK_HITS.with(|c| c.get())
347-}
348-
349-// lane-defon r1: how many COMPOUND_REFERENCE blocks read a
350-// `UNIDIR_COMP_REFERENCE` pair (both references on the same temporal side,
351-// spec 5.11.25 `comp_reference_type == 0`) -- the gate's proof that a
352-// stream built with `--enable-onesided-comp=1` really exercised the
353-// `uni_comp_ref` alphabet rather than only bidirectional pairs.
354-thread_local! {
355- pub(super) static UNI_COMP_HITS: std::cell::Cell<usize> =
356- const { std::cell::Cell::new(0) };
357-}
358-
359-/// Current value of [`UNI_COMP_HITS`].
360-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
361-pub(crate) fn uni_comp_hits() -> usize {
362- UNI_COMP_HITS.with(|c| c.get())
363-}
364-
365-// lane-defon r1: how many blocks blended through a `COMPOUND_DIFFWTD` mask
366-// (`mc::diffwtd_mask`) -- the narrower half of `MASKED_COMPOUND_HITS`, the
367-// gate's proof that `--enable-diff-wtd-comp=1` reached the difference-weighted
368-// blend and not only the wedge arm.
369-thread_local! {
370- pub(super) static DIFFWTD_HITS: std::cell::Cell<usize> =
371- const { std::cell::Cell::new(0) };
372-}
373-
374-/// Current value of [`DIFFWTD_HITS`].
375-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
376-pub(crate) fn diffwtd_hits() -> usize {
377- DIFFWTD_HITS.with(|c| c.get())
378-}
379-
380-// lane-mcomp64 r1: how many blocks took the INFERRED `COMPOUND_DIFFWTD` arm --
381-// a block size where `av1_is_wedge_used` is false (64x64 is the only such size
382-// this decoder's square inter path reaches), so no `compound_type` symbol is
383-// coded at all. Strictly narrower than `DIFFWTD_HITS`, which also counts the
384-// coded-symbol DIFFWTD blocks at 8x8/16x16/32x32.
385-thread_local! {
386- pub(super) static DIFFWTD_INFERRED_HITS: std::cell::Cell<usize> =
387- const { std::cell::Cell::new(0) };
388-}
389-
390-/// Current value of [`DIFFWTD_INFERRED_HITS`].
391-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
392-pub(crate) fn diffwtd_inferred_hits() -> usize {
393- DIFFWTD_INFERRED_HITS.with(|c| c.get())
394-}
395-
396-// lane-defon r1: how many FORWARD KEYFRAMES were decoded -- a KEY frame coded
397-// with `show_frame == 0`, output later by a `show_existing_frame` header
398-// (aomenc `--enable-fwd-kf=1 --fwd-kf-dist=N`). Counted from
399-// `stream::decode_stream`, which is where the frame header is consumed; the
400-// gate's proof that the on-value really reached the bitstream rather than
401-// being dropped by the rate control.
402-thread_local! {
403- pub(super) static FWD_KF_HITS: std::cell::Cell<usize> =
404- const { std::cell::Cell::new(0) };
405-}
406-
407-/// Current value of [`FWD_KF_HITS`].
408-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
409-pub(crate) fn fwd_kf_hits() -> usize {
410- FWD_KF_HITS.with(|c| c.get())
411-}
412-
413-// How many [`read_tx_size`] reads resolved a `tx_depth` strictly less than
414-// the block's own side, across every call on the current thread -- the same
415-// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream
416-// actually exercised a *split* transform under `TxMode::Select` rather than
417-// every block coincidentally resolving `depth=0` (indistinguishable from
418-// `TxMode::Largest` pixel-wise).
419-thread_local! {
420- pub(super) static TX_DEPTH_HITS: std::cell::Cell<usize> =
421- const { std::cell::Cell::new(0) };
422-}
423-
424-// How many plain SQUARE intra blocks (lane-sqchroma r1) resolved a luma
425-// transform smaller than their own side (`tx_depth != 0`) while coding a
426-// chroma prediction other than `DC_PRED` -- the pair the square path's chroma
427-// only exercises with aomenc's tx-size search left ON (its default), which
428-// every older recipe in this file pins off. Counted at the block, so a stream
429-// where RD happened to give every split-transform block a DC chroma mode
430-// reads as zero rather than silently passing for free.
431-thread_local! {
432- pub(super) static SQ_CHROMA_TX_HITS: std::cell::Cell<usize> =
433- const { std::cell::Cell::new(0) };
434-}
435-
436-/// Current value of [`SQ_CHROMA_TX_HITS`].
437-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
438-pub(crate) fn sq_chroma_tx_hits() -> usize {
439- SQ_CHROMA_TX_HITS.with(|c| c.get())
440-}
441-
442-/// Current value of [`TX_DEPTH_HITS`].
443-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
444-pub(crate) fn tx_depth_hits() -> usize {
445- TX_DEPTH_HITS.with(|c| c.get())
446-}
447-
448-// lane-txselect: how many `txfm_split` symbols an inter frame's var-tx tree
449-// read, and how many of those actually took the split, on the current thread
450-// -- the same before/after counter pattern as [`TX_DEPTH_HITS`], proving a
451-// stream exercised spec 5.11.17's `read_var_tx_size` rather than every block
452-// coincidentally coding one whole-block transform.
453-thread_local! {
454- pub(super) static TXFM_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
455- // lane-inter4 r2: rectangular INTER residual coding -- how many rect
456- // strips coded one whole-block rect transform unit, and how many split
457- // their rect max transform into square sub-transforms.
458- pub(super) static RECT_INTER_TU_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
459- pub(super) static RECT_INTER_TXSPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
460- // lane-r14 r2: luma transform units of an inter strip with a 64-px axis
461- // (64x32/32x64/64x16/16x64), whose coefficients are coded as the
462- // truncated low-32 corner.
463- pub(super) static RECT64_INTER_TU_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
464- // lane-rectres r1: whole-block luma transform units of a 32x32-level 1:4
465- // inter strip, `[32x8, 8x32]`.
466- pub(super) static RECT32X8_INTER_TU_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };
467- // lane-r14 r3: rectangular var-tx LEAVES, [32x16, 16x32].
468- pub(super) static VARTX_RECT_LEAF_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };
469- // lane-inter16ab r4: rectangular var-tx leaves with a 4-px axis, [8x4, 4x8]
470- // -- the `sub_tx_size_map[TX_16X4]` split leaves of a 16x16-level 1:4 strip.
471- pub(super) static VARTX_RECT_LEAF4_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };
472- // lane-inter4 r3: 16x16-level PARTITION_HORZ / PARTITION_VERT on an inter
473- // frame -- 16x8 and 8x16 inter leaves.
474- pub(super) static INTER_LEAF16_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
475- pub(super) static INTER_LEAF16_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
476- // This frame's own `tx_mode == TxMode::Select` and `reduced_tx_set` bits,
477- // set once per inter tile by [`decode_inter_frame_tile_with_cdfs`] --
478- // `decode_inter_block` already carries forty parameters and both are
479- // frame-constant.
480- // lane-fiinter r1: this sequence header's own `enable_filter_intra` bit,
481- // frame-constant like the two above and stashed the same way -- an intra
482- // block inside an inter frame reads `use_filter_intra` under it.
483-}
484-
485-/// Current value of [`TXFM_SPLIT_HITS`].
486-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
487-pub(crate) fn txfm_split_hits() -> usize {
488- TXFM_SPLIT_HITS.with(|c| c.get())
489-}
490-
491-/// Current value of [`INTER_LEAF16_HORZ_HITS`] (lane-inter4 r3).
492-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
493-pub(crate) fn inter_leaf16_horz_hits() -> usize {
494- INTER_LEAF16_HORZ_HITS.with(|c| c.get())
495-}
496-
497-/// Current value of [`INTER_LEAF16_VERT_HITS`] (lane-inter4 r3).
498-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
499-pub(crate) fn inter_leaf16_vert_hits() -> usize {
500- INTER_LEAF16_VERT_HITS.with(|c| c.get())
501-}
502-
503-/// Current value of [`RECT_INTER_TU_HITS`] (lane-inter4 r2).
504-pub(crate) fn rect_inter_tu_hits() -> usize {
505- RECT_INTER_TU_HITS.with(|c| c.get())
506-}
507-
508-/// Current value of [`RECT_INTER_TXSPLIT_HITS`] (lane-inter4 r2).
509-pub(crate) fn rect_inter_txsplit_hits() -> usize {
510- RECT_INTER_TXSPLIT_HITS.with(|c| c.get())
511-}
512-
513-/// Current value of [`RECT64_INTER_TU_HITS`] (lane-r14 r2).
514-pub(crate) fn rect64_inter_tu_hits() -> usize {
515- RECT64_INTER_TU_HITS.with(|c| c.get())
516-}
517-
518-/// Current value of [`RECT32X8_INTER_TU_HITS`] (lane-rectres r1): `[32x8, 8x32]`
519-/// whole-block luma units of a 32x32-level 1:4 inter strip.
520-pub(crate) fn rect32x8_inter_tu_hits() -> [usize; 2] {
521- RECT32X8_INTER_TU_HITS.with(|c| c.get())
522-}
523-
524-/// Current value of [`VARTX_RECT_LEAF_HITS`] (lane-r14 r3): how many
525-/// rectangular var-tx leaf transform units were coded, `[32x16, 16x32]`.
526-pub(crate) fn vartx_rect_leaf_hits() -> [usize; 2] {
527- VARTX_RECT_LEAF_HITS.with(|c| c.get())
528-}
529-
530-/// Current value of [`VARTX_RECT_LEAF4_HITS`] (lane-inter16ab r4): 8x4/4x8
531-/// split leaves of a 16x4/4x16 strip, `[8x4, 4x8]`.
532-pub(crate) fn vartx_rect_leaf4_hits() -> [usize; 2] {
533- VARTX_RECT_LEAF4_HITS.with(|c| c.get())
534-}
535-
536-/// Records one rectangular var-tx leaf.
537-pub(super) fn vartx_rect_leaf_hit(tw: usize, th: usize) {
538- if crate::envflags::env_flag!("EC_VARTXLEAF") {
539- eprintln!("EC_VARTXLEAF tw={tw} th={th}");
540- }
541- let cell = if tw.min(th) == 4 {
542- &VARTX_RECT_LEAF4_HITS
543- } else {
544- &VARTX_RECT_LEAF_HITS
545- };
546- cell.with(|c| {
547- let mut h = c.get();
548- h[usize::from(th > tw)] += 1;
549- c.set(h);
550- });
551-}
552-
553-// How many `partition_w16` reads (a 16x16 block's own partition symbol, key
554-// intra-frame path) resolved to `PARTITION_VERT_B` -- lane-rect16 r1: a
555-// plain default-settings aomenc run over lavfi mandelbrot hits this arm on
556-// frame 0's very first non-NONE/SPLIT `partition_w16` symbol (mi=(3,2)), not
557-// the plain HORZ/VERT this lane's charter assumed. Left rect (8x16, real
558-// `decode_block_rect`) + two 8x8 leaves stacked on the right (`decode_leaf8`,
559-// chained via `prev_leaf` exactly like the existing 16x16-SPLIT-into-4x8x8
560-// path above).
561-thread_local! {
562- pub(super) static VERT_B_INTRA_HITS: std::cell::Cell<usize> =
563- const { std::cell::Cell::new(0) };
564-}
565-
566-/// Current value of [`VERT_B_INTRA_HITS`].
567-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
568-pub(crate) fn vert_b_intra_hits() -> usize {
569- VERT_B_INTRA_HITS.with(|c| c.get())
570-}
571-
572-// lane-ab16 r1: how many 16x16-level AB partitions fired, per arm, in
573-// `PARTITION_HORZ_A`, `_HORZ_B`, `_VERT_A`, `_VERT_B` order. Each arm is two
574-// 8x8 squares (`decode_leaf8`) plus one 16x8/8x16 strip (`decode_leaf_rect`,
575-// the non-skip coefficient path lane-rectx proved); the gate hard-asserts
576-// every arm separately so a run where aomenc's RD only picked one cannot
577-// pass as proof of four.
578-thread_local! {
579- pub(super) static AB16_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) };
580-}
581-
582-// [`AB16_HITS`] per arm (HORZ_A, HORZ_B, VERT_A, VERT_B at 16x16).
583-thread_local! {
584- /// 4x4 transform units decoded inside an 8x8 square of a
585- /// `PARTITION_VERT_A`/`_B` -- the exact call that panicked before
586- /// [`crate::encode::Reach::of_tu`] (lane-ab16 r2), so the gate can prove
587- /// a real `--enable-tx-size-search=1` stream reaches it.
588- pub(super) static VERT_AB_TX4_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
589-}
590-
591-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
592-pub(crate) fn vert_ab_tx4_hits() -> usize {
593- VERT_AB_TX4_HITS.with(std::cell::Cell::get)
594-}
595-
596-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
597-pub(crate) fn ab16_hits_by_arm() -> [usize; 4] {
598- AB16_HITS.with(std::cell::Cell::get)
599-}
600-
601-// How many `partition_w16` reads resolved to a plain `PARTITION_HORZ`/
602-// `PARTITION_VERT` (lane-rect16 r2): re-measuring after the VERT_B fix above
603-// showed mandelbrot's real first-hit blocker is this plain arm at mi=(0,7),
604-// not VERT_B (`refusal-names-a-correlate`; the VERT_B write-up's "frame 0's
605-// very first non-NONE/SPLIT symbol" claim was about decode ORDER within one
606-// superblock's z-order recursion, not raster mi position).
607-thread_local! {
608- pub(super) static HORZ_VERT_INTRA_HITS: std::cell::Cell<usize> =
609- const { std::cell::Cell::new(0) };
610-}
611-
612-/// Current value of [`HORZ_VERT_INTRA_HITS`].
613-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
614-pub(crate) fn horz_vert_intra_hits() -> usize {
615- HORZ_VERT_INTRA_HITS.with(|c| c.get())
616-}
617-
618-// How many blocks were decoded as a frame-edge rect strip -- the single
619-// coded half of a `PARTITION_HORZ`/`PARTITION_VERT` at the true frame edge
620-// (lane-oddh r1), i.e. a block living inside the 8px band of a frame whose
621-// height or width is 8 mod 16 (the user's 3840x1608 film). Intra and inter
622-// paths share the counter.
623-thread_local! {
624- pub(super) static EDGE_RECT_STRIP_HITS: std::cell::Cell<usize> =
625- const { std::cell::Cell::new(0) };
626-}
627-
628-/// Current value of [`EDGE_RECT_STRIP_HITS`].
629-#[allow(dead_code)] // gate counter accessor with no reader yet; the counter itself is live
630-pub(crate) fn edge_rect_strip_hits() -> usize {
631- EDGE_RECT_STRIP_HITS.with(|c| c.get())
632-}
633-
634-// lane-interedge r1: frame-edge half strips on the INTER path, per partition
635-// level (64/32/16) x axis (HORZ at a bottom edge, VERT at a right edge). The
636-// index is `level_idx * 2 + axis` with `level_idx` 0=64, 1=32, 2=16 and
637-// `axis` 0=HORZ (`!has_rows`), 1=VERT (`!has_cols`). Both of the user's films
638-// are height mod 16 == 8, so every inter frame crosses these nodes.
639-thread_local! {
640- pub(super) static INTER_EDGE_STRIP_HITS: std::cell::Cell<[usize; 6]> =
641- const { std::cell::Cell::new([0; 6]) };
642-}
643-
644-// lane-edgeboth r1: how many partition nodes were coded as the BOTH-AXES-CUT
645-// forced split -- libaom `decode_partition` (decodeframe.c):
646-// `else if (!has_rows && !has_cols) partition = PARTITION_SPLIT;`, the one
647-// straddle case that reads NO symbol at all. Indexed by level:
648-// 0 = 16x16, 1 = 32x32, 2 = 64x64, 3 = 128x128; intra and inter share it.
649-thread_local! {
650- pub(super) static EDGE_BOTH_CUT_HITS: std::cell::Cell<[usize; 4]> =
651- const { std::cell::Cell::new([0; 4]) };
652-}
653-
654-/// Current value of [`INTER_EDGE_STRIP_HITS`] (`[h64, v64, h32, v32, h16, v16]`).
655-pub fn inter_edge_strip_hits() -> [usize; 6] {
656- INTER_EDGE_STRIP_HITS.with(|c| c.get())
657-}
658-
659-/// Resets [`INTER_EDGE_STRIP_HITS`] -- a refused attempt must not carry hits
660-/// into the next one (class `counter-from-refused-stream`).
661-pub fn reset_inter_edge_strip_hits() {
662- INTER_EDGE_STRIP_HITS.with(|c| c.set([0; 6]));
663-}
664-
665-/// Current value of [`EDGE_BOTH_CUT_HITS`] (`[16, 32, 64, 128]` levels).
666-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
667-pub(crate) fn edge_both_cut_hits() -> [usize; 4] {
668- EDGE_BOTH_CUT_HITS.with(|c| c.get())
669-}
670-
671-/// Zeroes [`EDGE_BOTH_CUT_HITS`] so a gate can measure a per-attempt delta.
672-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
673-pub(crate) fn reset_edge_both_cut_hits() {
674- EDGE_BOTH_CUT_HITS.with(|c| c.set([0; 4]));
675-}
676-
677-// How many HORZ/VERT intra strips resolved a SPLIT luma transform
678-// (`tx_depth != 0`) and decoded it per transform unit (lane-rectsplit r1) --
679-// the case every rect path here refused by name before, and the first
680-// refusal the user's ReelB extract (600s in) stops at.
681-thread_local! {
682- pub(super) static RECT_SPLIT_TX_HITS: std::cell::Cell<usize> =
683- const { std::cell::Cell::new(0) };
684-}
685-
686-/// Current value of [`RECT_SPLIT_TX_HITS`].
687-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
688-pub(crate) fn rect_split_tx_hits() -> usize {
689- RECT_SPLIT_TX_HITS.with(|c| c.get())
690-}
691-
692-// The subset of [`RECT_SPLIT_TX_HITS`] that is BOTH superblock-level (one
693-// side 64) AND split past the first depth, i.e. tiled more than one unit in
694-// each axis -- the only shape with a transform unit that has neighbours on
695-// two sides inside its own strip (`row_off > 0 && col_off > 0`), and the one
696-// no gate fired before lane-rectsplit r2 (the shared counter above also
697-// counts 32x32-level and depth-1 strips, so it cannot prove this case).
698-thread_local! {
699- pub(super) static RECT_SPLIT_SB_INTERIOR_TU_HITS: std::cell::Cell<usize> =
700- const { std::cell::Cell::new(0) };
701-}
702-
703-/// Current value of [`RECT_SPLIT_SB_INTERIOR_TU_HITS`].
704-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
705-pub(crate) fn rect_split_sb_interior_tu_hits() -> usize {
706- RECT_SPLIT_SB_INTERIOR_TU_HITS.with(|c| c.get())
707-}
708-
709-// Per-shape hit counts for the rect chroma transforms lane-rectchroma r1
710-// wired into [`decode_rect_split`] -- the shapes a split-transform strip's
711-// chroma half takes that had no coefficient tables before (index order:
712-// 32x8, 8x32, 8x4, 4x8). One counter per shape because a gate that only
713-// proves the pair it happens to hit cannot catch a transposed scan/context
714-// table (class scan-weights-cross-axis).
715-thread_local! {
716- pub(super) static RECT_SPLIT_CHROMA_SHAPE_HITS: std::cell::Cell<[usize; 4]> =
717- const { std::cell::Cell::new([0; 4]) };
718-}
719-
720-/// Current value of [`RECT_SPLIT_CHROMA_SHAPE_HITS`] (32x8, 8x32, 8x4, 4x8).
721-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
722-pub(crate) fn rect_split_chroma_shape_hits() -> [usize; 4] {
723- RECT_SPLIT_CHROMA_SHAPE_HITS.with(|c| c.get())
724-}
725-
726-// lane-av1-422: how many SQUARE chroma coefficient units the strip path read
727-// on a 4:2:2 frame (ss 1,0) -- the half-width, unhalved-height shape whose
728-// tables only exist because of the square rows in the chroma_tiled arm. A
729-// 4:2:0 or 4:4:4 frame can never increment it (their rect strips' chroma is
730-// itself rect), and a restored `/2 chroma height` diverts 4:2:2 squares onto
731-// the rect rows, so the witness gate reads 0 there and fails.
732-thread_local! {
733- pub(super) static CHROMA422_SQUARE_HITS: std::cell::Cell<usize> =
734- const { std::cell::Cell::new(0) };
735-}
736-
737-/// Current value of [`CHROMA422_SQUARE_HITS`].
738-// lane-av1-422b: `pub` so `examples/decode_probe.rs` can census it the way
739-// it does every other capability counter.
740-pub fn chroma422_square_hits() -> usize {
741- CHROMA422_SQUARE_HITS.with(|c| c.get())
742-}
743-
744-// lane-av1422tailskip: how many 4:2:2 (ss 1,0) intra-in-inter chroma TRANSFORM
745-// UNITS took their own window on the block-sized chroma palette prediction --
746-// `decode_inter_block`'s `side == 64` TX_32X32 walk, where the plane block is
747-// 32x64 but codes two stacked square units per plane. Zero on a 4:2:0 or 4:4:4
748-// frame (their chroma unit is the whole plane block, one window), and zero on
749-// a 4:2:2 block with no palette, so a witness gate reading 0 proves the arm
750-// never ran.
751-thread_local! {
752- pub(super) static PALETTE_422_UNIT_WINDOW_HITS: std::cell::Cell<usize> =
753- const { std::cell::Cell::new(0) };
754-}
755-
756-/// Current value of [`PALETTE_422_UNIT_WINDOW_HITS`].
757-// lane-av1422tailskip: `pub` so `examples/decode_probe.rs` can census it the
758-// way it does every other capability counter.
759-pub fn palette_422_unit_window_hits() -> usize {
760- PALETTE_422_UNIT_WINDOW_HITS.with(|c| c.get())
761-}
762-
763-// lane-av1-422f: how many RECT chroma coefficient units the square-block
764-// path read on a 4:2:2 frame (ss 1,0) -- TX_4X8 / TX_8X16 / TX_16X32, the
765-// plane block's own half-width, unhalved-height shape. A 4:2:0 or 4:4:4
766-// frame never takes the rect branch (their units are square
767-// `chroma_tx == chroma_tx_h`), so a witness gate reading 0 here proves the
768-// model reverted to squares.
769-thread_local! {
770- pub(super) static CHROMA422_RECT_HITS: std::cell::Cell<usize> =
771- const { std::cell::Cell::new(0) };
772-}
773-
774-/// Current value of [`CHROMA422_RECT_HITS`].
775-pub fn chroma422_rect_hits() -> usize {
776- CHROMA422_RECT_HITS.with(|c| c.get())
777-}
778-
779-// lane-av1-422g: how many PER-LEAF TX_4X4 chroma coefficient units the
780-// sub-8x8 split4 path read on a 4:2:2 frame (ss 1,0) -- one per even-column
781-// leaf per plane (`is_chroma_reference`'s `!(mi_col & ss_x)`). A 4:2:0 frame
782-// codes no sub-8 chroma at all and 4:4:4 goes through `sub8_leaf_chroma444`,
783-// so a witness gate reading 0 here proves the per-leaf 4:2:2 arm never ran.
784-thread_local! {
785- pub(super) static CHROMA422_SUB8_HITS: std::cell::Cell<usize> =
786- const { std::cell::Cell::new(0) };
787-}
788-
789-/// Current value of [`CHROMA422_SUB8_HITS`].
790-pub fn chroma422_sub8_hits() -> usize {
791- CHROMA422_SUB8_HITS.with(|c| c.get())
792-}
793-
794-// lane-av1422llintra: how many 4:2:2 LOSSLESS chroma plane blocks
795-// (`decode_leaf8`) were walked as 4x4 units rather than as the one
796-// `av1_get_max_uv_txsize` rect that rule only reaches OUTSIDE a lossless
797-// frame. A 4:2:0 or 4:4:4 frame never takes the arm (its own lossless walk
798-// was already there), so a witness gate reading 0 here proves the model
799-// reverted to the rect unit.
800-thread_local! {
801- pub(super) static CHROMA422_LOSSLESS_4X4_HITS: std::cell::Cell<usize> =
802- const { std::cell::Cell::new(0) };
803-}
804-
805-/// Current value of [`CHROMA422_LOSSLESS_4X4_HITS`].
806-pub fn chroma422_lossless_4x4_hits() -> usize {
807- CHROMA422_LOSSLESS_4X4_HITS.with(|c| c.get())
808-}
809-
810-// lane-av1-422sub8rect: how many PER-PIECE TX_4X4 chroma coefficient units
811-// the INTER sub-8x8 split4 path read on a 4:2:2 frame (ss 1,0) -- one per
812-// non-skipped odd-column piece per plane (`is_chroma_reference`'s
813-// `mi_col & 0x01` at ss_x 1). 4:2:0 goes through the shared group unit and
814-// 4:4:4 through [`sub8_leaf_chroma444`]'s own per-piece twin, so a witness
815-// gate reading 0 here proves the inter 4:2:2 per-piece arm never ran.
816-thread_local! {
817- pub(super) static CHROMA422_INTER_SUB8_HITS: std::cell::Cell<usize> =
818- const { std::cell::Cell::new(0) };
819-}
820-
821-/// Current value of [`CHROMA422_INTER_SUB8_HITS`].
822-pub fn chroma422_inter_sub8_hits() -> usize {
823- CHROMA422_INTER_SUB8_HITS.with(|c| c.get())
824-}
825-
826-// lane-av1-422m: how many TX_4X4 chunk units the invalid-ss-size chroma arm
827-// read (the 8x32 luma block whose 4:2:2 plane has no `ss_size_lookup` block).
828-// A 4:2:0 or 4:4:4 frame cannot increment it, so a non-zero read proves the
829-// chunked 4:2:2 chroma really decoded.
830-thread_local! {
831- pub(super) static CHROMA422_CHUNK_HITS: std::cell::Cell<usize> =
832- const { std::cell::Cell::new(0) };
833-}
834-
835-/// Current value of [`CHROMA422_CHUNK_HITS`].
836-pub fn chroma422_chunk_hits() -> usize {
837- CHROMA422_CHUNK_HITS.with(|c| c.get())
838-}
839-
840-// lane-av1-422stripanchor: how many 4-wide-strip PAIR chroma units
841-// ([`decode_rect_split`]'s ported floored-pair anchor) decoded. A 4:2:0 or
842-// 4:4:4 frame cannot increment it (the arm is keyed to a 2-px-wide chroma
843-// block, which only a 1-mi-wide strip at ss (1, 0) produces), so a non-zero
844-// read proves a stream routed a 4-wide strip through the split path.
845-thread_local! {
846- pub(super) static CHROMA422_PAIR_WIDE_HITS: std::cell::Cell<usize> =
847- const { std::cell::Cell::new(0) };
848-}
849-
850-/// Current value of [`CHROMA422_PAIR_WIDE_HITS`].
851-pub fn chroma422_pair_wide_hits() -> usize {
852- CHROMA422_PAIR_WIDE_HITS.with(|c| c.get())
853-}
854-
855-// How many HORZ/VERT intra strips actually predicted with filter intra
856-// (lane-rectsplit r1) -- the case `decode_block_rect` refused by name
857-// ("this decoder predicts square-only") until `predict_filter_intra` took
858-// `bw`x`bh`.
859-thread_local! {
860- pub(super) static FILTER_INTRA_RECT_HITS: std::cell::Cell<usize> =
861- const { std::cell::Cell::new(0) };
862-}
863-
864-/// Current value of [`FILTER_INTRA_RECT_HITS`].
865-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
866-pub(crate) fn filter_intra_rect_hits() -> usize {
867- FILTER_INTRA_RECT_HITS.with(|c| c.get())
868-}
869-
870-// As [`FILTER_INTRA_RECT_HITS`], counting only the 32x32-level 1:4 strips
871-// (32x8/8x32, lane-fi32x8 r1) -- the shapes whose `use_filter_intra` symbol
872-// was never read at all before that round, so a gate needs to prove the flag
873-// fired at THAT shape and not at a 16x8 one somewhere else in the frame.
874-// Split by ORIENTATION: rows 8 (32x8) and 9 (8x32) of `cdf::FILTER_INTRA`
875-// carry different probabilities (18101 vs 20229), so a transposed pair is
876-// only caught by a gate that sees the flag fire on BOTH shapes (class
877-// scan-weights-cross-axis).
878-thread_local! {
879- pub(super) static FILTER_INTRA_RECT4_HORZ_HITS: std::cell::Cell<usize> =
880- const { std::cell::Cell::new(0) };
881- pub(super) static FILTER_INTRA_RECT4_VERT_HITS: std::cell::Cell<usize> =
882- const { std::cell::Cell::new(0) };
883-}
884-
885-/// Current value of [`FILTER_INTRA_RECT4_HORZ_HITS`] (32x8 strips).
886-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
887-pub(crate) fn filter_intra_rect4_horz_hits() -> usize {
888- FILTER_INTRA_RECT4_HORZ_HITS.with(|c| c.get())
889-}
890-
891-/// Current value of [`FILTER_INTRA_RECT4_VERT_HITS`] (8x32 strips).
892-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
893-pub(crate) fn filter_intra_rect4_vert_hits() -> usize {
894- FILTER_INTRA_RECT4_VERT_HITS.with(|c| c.get())
895-}
896-
897-// How many rectangular transform units actually coded coefficients through
898-// [`read_coeffs_rect`] (`all_zero == 0`) -- lane-rect1d's measure that a gate
899-// exercised the rect coefficient reader at all rather than passing on
900-// all-skip blocks.
901-thread_local! {
902- pub(super) static RECT_COEFF_TU_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
903- pub(super) static RECT_CLASS1_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
904-}
905-
906-/// Current value of [`RECT_COEFF_TU_HITS`].
907-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
908-pub(crate) fn rect_coeff_tu_hits() -> usize {
909- RECT_COEFF_TU_HITS.with(|c| c.get())
910-}
911-
912-/// Rectangular transform units whose resolved `tx_type` is a 1D class
913-/// (`V_DCT`/`H_DCT`) -- [`TX_CLASS1_HITS`]'s rect-only half, so a gate can
914-/// pin that the 1D-class-on-a-RECT-transform path fired rather than settling
915-/// for the square reader's own 1D types.
916-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
917-pub(crate) fn rect_class1_hits() -> usize {
918- RECT_CLASS1_HITS.with(|c| c.get())
919-}
920-
921-// lane-av1readcensus: the PER-UNIT coefficient census -- one unit counted
922-// per `read_coeffs`/`read_coeffs_rect` call, i.e. per object this decoder
923-// actually walks, which is the unit the round-4 `av1444rect` count measured
924-// (636 square chroma reads against the oracle's 1086).
925-//
926-// lane-av1422census422 widened the arming. The counters used to be
927-// 4:4:4-ONLY (`CENSUS_444`), so at 4:2:2 -- a chroma format an AV1
928-// `color_config` can carry and libaom's writer emits -- every
929-// `census_444_units()` / `census_444_coded()` read zero BY CONSTRUCTION: a
930-// byte-exact 4:2:2 gate asserting those counters would be asserting a
931-// literal, and would be green while proving nothing about that stream. The
932-// census is now armed for every chroma format that leaves at least one luma
933-// axis unsubsampled -- (0,0) 4:4:4 and (1,0) 4:2:2 -- and 4:2:0 (1,1) stays
934-// off, so the existing 4:4:4 exact counts and the 4:2:0 zero control are
935-// unmoved by the widening. The counters are per-PLANE, not per-format, so a
936-// 4:2:2 cell's `[luma, u, v]` split is directly comparable with a 4:4:4
937-// cell's on the same walk shape.
938-thread_local! {
939- /// Per-plane unit counts, `[luma, u, v]`, at 4:4:4 and 4:2:2.
940- pub(super) static CENSUS_NONSUB_UNITS: std::cell::Cell<[usize; 3]> = const { std::cell::Cell::new([0; 3]) };
941- /// Of [`CENSUS_NONSUB_UNITS`], the units that coded at least one
942- /// coefficient (`txb_skip == 0`) -- the per-plane split is only
943- /// comparable against the oracle's when both sides count all-zero units
944- /// the same way.
945- pub(super) static CENSUS_NONSUB_CODED: std::cell::Cell<[usize; 3]> = const { std::cell::Cell::new([0; 3]) };
946- /// Sequential unit index, so a trace line names its own position in the
947- /// frame's walk rather than relying on line order alone.
948- pub(super) static CENSUS_UNIT_N: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
949- /// The plane the units read from here on belong to. A thread-local rather
950- /// than a `read_coeffs` parameter because the three luma call sites
951- /// (`decode_rect_split`, `decode_block_rect64`, `read_inter_plane_rect`)
952- /// are not this lane's to edit and would each grow an argument; the
953- /// plane-owning readers stamp it once on entry instead.
954- pub(super) static CENSUS_PLANE: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
955- /// At least one luma axis unsubsampled -- (0,0) 4:4:4 or (1,0) 4:2:2 --
956- /// for the frame being decoded, set per frame from [`crate::stream`].
957- /// 4:2:0 (1,1) arms nothing.
958- pub(super) static CENSUS_NONSUB: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
959-}
960-
961-/// Current `[luma, u, v]` coefficient-unit counts, per plane. Zero at 4:2:0
962-/// by design ([`set_census_nonsub`] arms nothing there).
963-pub fn census_nonsub_units() -> [usize; 3] {
964- CENSUS_NONSUB_UNITS.with(|c| c.get())
965-}
966-
967-/// Current `[luma, u, v]` counts of units that coded coefficients.
968-pub fn census_nonsub_coded() -> [usize; 3] {
969- CENSUS_NONSUB_CODED.with(|c| c.get())
970-}
971-
972-/// lane-av1readcensus: arms the coefficient-unit census for the frame about
973-/// to decode, called once per frame from [`crate::stream`]'s decode loop
974-/// beside [`set_subsampling`]. Armed for every chroma format with an
975-/// unsubsampled luma axis -- 4:4:4 (0,0) and 4:2:2 (1,0) -- and NOT for
976-/// 4:2:0 (1,1), where the walk-shape question this census answers does not
977-/// arise, so a 4:2:0 control can still assert exactly zero.
978-///
979-/// lane-av1422census422 widened this from `(ss_x == 0 && ss_y == 0)`. The
980-/// old condition made 4:2:2 silently UNCUNTABLE rather than uncounted. The
981-/// two format pairs keep disjoint conditions, so neither the 4:4:4 exact
982-/// counts nor the 4:2:0 zero control can move because of this.
983-pub(crate) fn set_census_nonsub(ss_x: u8, ss_y: u8) {
984- CENSUS_NONSUB.with(|c| c.set(ss_x == 0 || ss_y == 0));
985-}
986-
987-/// lane-av1readcensus: the plane the units read from here on belong to,
988-/// stamped by the plane-owning readers ([`read_plane`], [`read_inter_plane`],
989-/// [`read_inter_plane_rect`]) on entry.
990-pub(crate) fn set_census_plane(plane: usize) {
991- CENSUS_PLANE.with(|c| c.set(plane));
992-}
993-
994-/// lane-av1readcensus: is the per-unit census trace on? Shares
995-/// [`coeff_trace_on`]'s per-frame narrowing so one frame's walk can be
996-/// dumped without the rest of the stream.
997-fn census_trace_on() -> bool {
998- if !crate::envflags::env_flag!("EC_CENSUS_UNIT") {
999- return false;
1000- }
1001- match COEFF_TRACE_FRAME.with(|c| c.get()) {
1002- None => true,
1003- Some(w) if w >= usize::MAX - 1 => true,
1004- Some(w) => COEFF_TRACE_CUR.with(|c| c.get()) == w,
1005- }
1006-}
1007-
1008-/// lane-av1readcensus: one line per coefficient unit this decoder walks, the
1009-/// twin of the oracle's `EC_COEFF` / `EC_COEFF_VAL` bracket around each
1010-/// `av1_read_coeffs_txb` call. Pair the two sides by `post_rng` (or by `n`),
1011-/// never by plane label or by walk position -- the walk order is exactly what
1012-/// the census is measuring.
1013-pub(super) fn census_unit(
1014- w: usize,
1015- h: usize,
1016- tx_type: TxType,
1017- eob: usize,
1018- all_zero: bool,
1019- entry_rng: u32,
1020- dec: &SymbolDecoder,
1021-) {
1022- let plane = CENSUS_PLANE.with(|c| c.get()).min(2);
1023- let coded = usize::from(!all_zero);
1024- CENSUS_UNIT_N.with(|c| c.set(c.get() + 1));
1025- hit_do! {
1026- CENSUS_NONSUB_UNITS.with(|c| {
1027- if CENSUS_NONSUB.with(|on| on.get()) {
1028- let mut v = c.get();
1029- v[plane] += 1;
1030- c.set(v);
1031- }
1032- });
1033- CENSUS_NONSUB_CODED.with(|c| {
1034- if CENSUS_NONSUB.with(|on| on.get()) {
1035- let mut v = c.get();
1036- v[plane] += coded;
1037- c.set(v);
1038- }
1039- });
1040- }
1041- if !census_trace_on() {
1042- return;
1043- }
1044- let n = CENSUS_UNIT_N.with(|c| c.get()) - 1;
1045- let post_rng = dec.debug_state().0;
1046- eprintln!(
1047- "EC_CENSUS_UNIT side=ours n={n} plane={plane} w={w} h={h} tx={tx_type:?} eob={eob} \
1048- all_zero={all_zero} entry_rng={entry_rng} post_rng={post_rng}"
1049- );
1050-}
1051-
1052-/// How many transform units this thread has read since the last
1053-/// [`reset_census_unit_n`] (lane-av1offtile). The per-unit oracle twin is
1054-/// `EC_ECDUMP_IN`, one line per `read_coeffs_txb` call, so this count IS
1055-/// directly comparable with an oracle `EC_ECDUMP_IN` census -- which is what
1056-/// makes "we walk N units where libaom walks M" a gated claim rather than an
1057-/// inference from the desync's position.
1058-pub fn census_unit_n() -> usize {
1059- CENSUS_UNIT_N.with(|c| c.get())
1060-}
1061-
1062-/// Reset [`census_unit_n`] to zero (lane-av1offtile).
1063-pub fn reset_census_unit_n() {
1064- CENSUS_UNIT_N.with(|c| c.set(0));
1065-}
1066-
1067-// As [`FILTER_INTRA_RECT_HITS`], counting only the strips BELOW 16x16
1068-// (8x16/16x8 leaves of a 16x16 HORZ/VERT partition, lane-fistrip r1) -- the
1069-// shapes whose `use_filter_intra` symbol had no CDF class before this round.
1070-// A gate asserting the wider counter would be satisfied by a 32x16 strip and
1071-// prove nothing about the new shapes.
1072-thread_local! {
1073- pub(super) static FILTER_INTRA_RECT_SUB16_HITS: std::cell::Cell<usize> =
1074- const { std::cell::Cell::new(0) };
1075-}
1076-
1077-/// Current value of [`FILTER_INTRA_RECT_SUB16_HITS`].
1078-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1079-pub(crate) fn filter_intra_rect_sub16_hits() -> usize {
1080- FILTER_INTRA_RECT_SUB16_HITS.with(|c| c.get())
1081-}
1082-
1083-// As [`FILTER_INTRA_RECT_SUB16_HITS`], one partition level further down:
1084-// 4x8/8x4 leaves of an 8x8 HORZ/VERT (lane-fi8 r1). A gate on the sub16
1085-// counter would be satisfied by a 16x8 strip and prove nothing here.
1086-thread_local! {
1087- pub(super) static FILTER_INTRA_RECT_SUB8_HITS: std::cell::Cell<usize> =
1088- const { std::cell::Cell::new(0) };
1089-}
1090-
1091-/// Current value of [`FILTER_INTRA_RECT_SUB8_HITS`].
1092-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1093-pub(crate) fn filter_intra_rect_sub8_hits() -> usize {
1094- FILTER_INTRA_RECT_SUB8_HITS.with(|c| c.get())
1095-}
1096-
1097-// How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D`
1098-// (`V_DCT`/`H_DCT`, spec 5.11.39's `TxClass::Horiz`/`Vert`), across every
1099-// call on the current thread -- the same before/after counter pattern as
1100-// [`TX_DEPTH_HITS`], proving a stream actually exercised the class-split
1101-// `eob_pt`/1D-neighbour context path rather than every block coincidentally
1102-// landing on `DCT_DCT`.
1103-thread_local! {
1104- pub(super) static TX_CLASS1_HITS: std::cell::Cell<usize> =
1105- const { std::cell::Cell::new(0) };
1106-}
1107-
1108-// How many `uv_mode` reads resolved to a directional chroma mode (neither
1109-// `DC_PRED` nor `UV_CFL_PRED`), across every call on the current thread -- the same
1110-// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream
1111-// actually exercised chroma's own directional predictor.
1112-thread_local! {
1113- pub(super) static DIRECTIONAL_UV_HITS: std::cell::Cell<usize> =
1114- const { std::cell::Cell::new(0) };
1115-}
1116-
1117-/// Current value of [`DIRECTIONAL_UV_HITS`].
1118-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1119-pub(crate) fn directional_uv_hits() -> usize {
1120- DIRECTIONAL_UV_HITS.with(|c| c.get())
1121-}
1122-
1123-// How many `angle_delta`/`angle_delta_uv` symbols this decoder has read as
1124-// something other than [`ANGLE_DELTA_ZERO`], across every call in the
1125-// process -- the same before/after counter pattern as [`FILTER_INTRA_HITS`],
1126-// proving a stream actually exercised a nonzero angle delta.
1127-thread_local! {
1128- pub(super) static ANGLE_DELTA_HITS: std::cell::Cell<usize> =
1129- const { std::cell::Cell::new(0) };
1130-}
1131-
1132-// How many [`read_single_ref`] reads resolved to a reference other than
1133-// `LAST_FRAME`, across every call on the current thread -- the same before/after
1134-// counter pattern as [`FILTER_INTRA_HITS`], proving a stream actually
1135-// exercised a non-`LAST_FRAME` reference (`GOLDEN_FRAME`, this decoder's
1136-// only other supported one so far) rather than every block coincidentally
1137-// resolving `LAST_FRAME`.
1138-thread_local! {
1139- pub(super) static NON_LAST_REF_HITS: std::cell::Cell<usize> =
1140- const { std::cell::Cell::new(0) };
1141-}
1142-
1143-/// Current value of [`NON_LAST_REF_HITS`].
1144-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1145-pub(crate) fn non_last_ref_hits() -> usize {
1146- NON_LAST_REF_HITS.with(|c| c.get())
1147-}
1148-
1149-// Per-reference [`NON_LAST_REF_HITS`] breakdown (lane-av1refs): one counter
1150-// per `MV_REFERENCE_FRAME` past `LAST_FRAME`, so a gate targeting one
1151-// specific reference (`LAST2`/`LAST3`/`GOLDEN`/`BWDREF`/`ALTREF2`/`ALTREF`)
1152-// can prove THAT reference fired rather than any non-`LAST_FRAME` one --
1153-// `NON_LAST_REF_HITS` alone cannot tell a `LAST2_FRAME` gate from a
1154-// `GOLDEN_FRAME` draw it did not ask for.
1155-thread_local! {
1156- pub(super) static LAST2_HITS: std::cell::Cell<usize> =
1157- const { std::cell::Cell::new(0) };
1158-}
1159-
1160-thread_local! {
1161- pub(super) static LAST3_HITS: std::cell::Cell<usize> =
1162- const { std::cell::Cell::new(0) };
1163-}
1164-
1165-thread_local! {
1166- pub(super) static GOLDEN_HITS: std::cell::Cell<usize> =
1167- const { std::cell::Cell::new(0) };
1168-}
1169-
1170-thread_local! {
1171- pub(super) static BWDREF_HITS: std::cell::Cell<usize> =
1172- const { std::cell::Cell::new(0) };
1173-}
1174-
1175-thread_local! {
1176- pub(super) static ALTREF2_HITS: std::cell::Cell<usize> =
1177- const { std::cell::Cell::new(0) };
1178-}
1179-
1180-thread_local! {
1181- pub(super) static ALTREF_HITS: std::cell::Cell<usize> =
1182- const { std::cell::Cell::new(0) };
1183-}
1184-
1185-// How many [`read_comp_mode`] reads resolved `COMPOUND_REFERENCE` (lane-av1comp)
1186-// -- proves a `reference_select` stream actually reached a block that picked
1187-// compound, not just that the header bit was set. Every such block is
1188-// refused after this fires ([`decode_inter_block`]/[`decode_inter_block8`]),
1189-// so this only ever counts attempted reads, never a completed decode.
1190-thread_local! {
1191- pub(super) static COMP_MODE_HITS: std::cell::Cell<usize> =
1192- const { std::cell::Cell::new(0) };
1193-}
1194-
1195-/// Current value of [`COMP_MODE_HITS`].
1196-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1197-pub(crate) fn comp_mode_hits() -> usize {
1198- COMP_MODE_HITS.with(|c| c.get())
1199-}
1200-
1201-// How many blocks [`read_intra_mode`] decoded a real (nonzero-size) palette-Y
1202-// use for, across every call on the current thread -- the same before/after
1203-// counter pattern as [`FILTER_INTRA_HITS`], proving a stream actually
1204-// exercised palette reconstruction rather than only reading and refusing the
1205-// `palette_y_mode` symbol.
1206-thread_local! {
1207- pub(super) static PALETTE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1208-}
1209-
1210-/// Current value of [`PALETTE_HITS`].
1211-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1212-pub(crate) fn palette_hits() -> usize {
1213- PALETTE_HITS.with(|c| c.get())
1214-}
1215-
1216-// lane-tiles r12: of those, how many sat at their own TILE's left column --
1217-// exactly the blocks whose palette cache/ctx must NOT see the previous tile's
1218-// colours (`av1_get_palette_cache`'s `xd->left_mbmi == NULL`). A multi-tile
1219-// palette gate that never hits one proves nothing about the tile guard.
1220-thread_local! {
1221- pub(super) static PALETTE_TILE_LEFT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1222-}
1223-
1224-/// Current value of [`PALETTE_TILE_LEFT_HITS`].
1225-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1226-pub(crate) fn palette_tile_left_hits() -> usize {
1227- PALETTE_TILE_LEFT_HITS.with(|c| c.get())
1228-}
1229-
1230-// lane-palette2 r1: as [`PALETTE_HITS`], for a real (nonzero-size) chroma
1231-// palette use -- proves a stream actually reconstructed UV palette pixels,
1232-// not just read and refused the `palette_uv_mode` symbol.
1233-thread_local! {
1234- pub(super) static PALETTE_UV_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1235-}
1236-
1237-/// Current value of [`PALETTE_UV_HITS`].
1238-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1239-pub(crate) fn palette_uv_hits() -> usize {
1240- PALETTE_UV_HITS.with(|c| c.get())
1241-}
1242-
1243-// lane-palette2 r1: how many HORZ/VERT rect intra strips ([`read_intra_mode_rect`])
1244-// decoded a real palette-Y use -- proves the rect strip's own palette syntax
1245-// (not just the square path's) actually fired.
1246-thread_local! {
1247- pub(super) static PALETTE_RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1248-}
1249-
1250-/// Current value of [`PALETTE_RECT_HITS`].
1251-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1252-pub(crate) fn palette_rect_hits() -> usize {
1253- PALETTE_RECT_HITS.with(|c| c.get())
1254-}
1255-
1256-// lane-palette2 r6: how many HORZ/VERT rect intra strips ran the
1257-// [`palette_bsize_ctx_wh`]-gated code path in [`read_intra_mode_rect`] --
1258-// i.e. `allow_screen_content_tools` was set and the strip's `bw`x`bh` was in
1259-// range, so `palette_y_mode`/`palette_uv_mode` were actually read (and, per
1260-// RD, almost always refused-on-use because the block doesn't end up USING a
1261-// palette -- see r5's report). This is the site the removed refusal
1262-// ("a HORZ/VERT intra strip in a screen-content frame") used to guard: it
1263-// fired here whether or not the block picked a palette, so this is the
1264-// counter that proves the case r5's narrower [`PALETTE_RECT_HITS`] almost
1265-// never observes.
1266-thread_local! {
1267- pub(super) static RECT_SCREEN_CONTENT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1268-}
1269-
1270-/// Current value of [`RECT_SCREEN_CONTENT_HITS`].
1271-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1272-pub(crate) fn rect_screen_content_hits() -> usize {
1273- RECT_SCREEN_CONTENT_HITS.with(|c| c.get())
1274-}
1275-
1276-// lane-palette2 r1: how many palette-Y luma transform UNITS decoded under a
1277-// split luma transform (`logical_tx != side`) -- proves the per-TU index-map
1278-// windowing actually ran, not just that the whole-block path stayed exact.
1279-// Counts units, not blocks (a 64x64 palette block split to 16x16 TUs adds 16);
1280-// first actually incremented in r7, when the refusal it guarded was lifted.
1281-thread_local! {
1282- pub(super) static PALETTE_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1283-}
1284-
1285-thread_local! {
1286- /// lane-kf900 r4: rect intra strips that ACTUALLY use a palette -- the
1287- /// 1:4 shapes (32x8/8x32, 16x4/4x16) and the sub-16x16 2:1 leaves
1288- /// (16x8/8x16), the two shapes the lifted refusals named.
1289- pub(super) static RECT4_PALETTE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1290-}
1291-
1292-/// Current value of [`RECT4_PALETTE_HITS`].
1293-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1294-pub(crate) fn rect4_palette_hits() -> usize {
1295- RECT4_PALETTE_HITS.with(|c| c.get())
1296-}
1297-
1298-/// Current value of [`PALETTE_SPLIT_TX_HITS`].
1299-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1300-pub(crate) fn palette_split_tx_hits() -> usize {
1301- PALETTE_SPLIT_TX_HITS.with(|c| c.get())
1302-}
1303-
1304-thread_local! {
1305- /// lane-av1444d10: chroma PREDICTION units on the 32-capped tiled chroma
1306- /// walk (`decode_block_rect`'s `uw/uh = min(chroma, 32)` units) that were
1307- /// handed a STRICT sub-slice of their block's palette buffer -- i.e. the
1308- /// units of a block the 32-cap actually TILED (`nw * nh > 1`).
1309- ///
1310- /// CORRECTED 2026-09-30 after the refutation pass `lanes/refute-av1444d10`
1311- /// read the numbers back: the previous comment claimed it counted "the
1312- /// units that are NOT the block's top-left corner", which is not what the
1313- /// code did -- the hit was unconditional, so a block's corner unit fired it
1314- /// too AND a single-unit block (whose window is a pure re-stride copy of
1315- /// the whole buffer) fired it as well. That made a hit prove only that some
1316- /// palette chroma block existed, not that the tiled arm ran. The `bigger`
1317- /// guard now makes the counter discriminate. On the pinned fixture the
1318- /// measured value is unchanged at 4 (one block with nw = 1, nh = 2 x two
1319- /// planes x two unit rows); a stream whose palette chroma blocks are all
1320- /// single-unit now leaves it at zero.
1321- ///
1322- /// FURTHER CORRECTED the same day by the palette lane's refutation
1323- /// (`lanes/av1444palw.report.md` + the arm-isolated mutation): the guard is
1324- /// about TILING, not about `nw > 1` specifically. Isolating the two window
1325- /// sites shows the RECT-unit arm alone reds the 10-bit cell, and the
1326- /// SQUARE-unit arm alone reds the 12-bit cell *and* the 10-bit one -- so
1327- /// windowing is load-bearing for every tiled block, and `nw > 1` is merely
1328- /// the case the corpus could not reach. Do not read this counter as
1329- /// evidence that only the horizontal term matters.
1330- pub(super) static CHROMA_PALETTE_WINDOW_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1331-}
1332-
1333-/// Current value of [`CHROMA_PALETTE_WINDOW_HITS`].
1334-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1335-pub(crate) fn chroma_palette_window_hits() -> usize {
1336- CHROMA_PALETTE_WINDOW_HITS.with(|c| c.get())
1337-}
1338-
1339-/// Zeroes [`CHROMA_PALETTE_WINDOW_HITS`] so a gate can read it as a DELTA
1340-/// (it is process-wide, like every counter here).
1341-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1342-pub(crate) fn reset_chroma_palette_window_hits() {
1343- CHROMA_PALETTE_WINDOW_HITS.with(|c| c.set(0));
1344-}
1345-
1346-thread_local! {
1347- /// lane-pal8 r1: square 8x8 LEAVES ([`decode_leaf8`]) that actually use a
1348- /// palette (Y or UV) -- the shape every 8-bit `--tune-content=screen`
1349- /// stream stopped on, since aomenc palettes square blocks at 8 bit and
1350- /// `--min-partition-size=8` puts them on this leaf path.
1351- pub(super) static PALETTE_LEAF8_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1352-}
1353-
1354-/// Current value of [`PALETTE_LEAF8_HITS`].
1355-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1356-pub(crate) fn palette_leaf8_hits() -> usize {
1357- PALETTE_LEAF8_HITS.with(|c| c.get())
1358-}
1359-
1360-/// Zeroes [`PALETTE_LEAF8_HITS`] (per-attempt gate counting).
1361-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1362-pub(crate) fn reset_palette_leaf8_hits() {
1363- PALETTE_LEAF8_HITS.with(|c| c.set(0));
1364-}
1365-
1366-thread_local! {
1367- /// lane-pal8 r1: NON-SKIP palette blocks on a superblock-level (64-level)
1368- /// HORZ/VERT or 1:4 strip ([`decode_block_rect64`]) -- i.e. a palette
1369- /// block that also carries a real, corner-cropped luma transform.
1370- pub(super) static PALETTE_SB_STRIP_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1371-}
1372-
1373-/// Current value of [`PALETTE_SB_STRIP_HITS`].
1374-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1375-pub(crate) fn palette_sb_strip_hits() -> usize {
1376- PALETTE_SB_STRIP_HITS.with(|c| c.get())
1377-}
1378-
1379-/// Zeroes [`PALETTE_SB_STRIP_HITS`] (per-attempt gate counting).
1380-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1381-pub(crate) fn reset_palette_sb_strip_hits() {
1382- PALETTE_SB_STRIP_HITS.with(|c| c.set(0));
1383-}
1384-
1385-thread_local! {
1386- /// lane-av1rectreach: units of `decode_rect_split`'s `chroma_tiled` walk
1387- /// whose PER-UNIT reach ([`tu_reach_rect`], libaom's per-unit
1388- /// `has_top_right` / `has_bottom_left`) DIFFERS from the block-level
1389- /// `reach` this walk used to hand every unit -- i.e. units for which the
1390- /// two answers are not interchangeable. This is what a gate needs before
1391- /// it compares the walk byte-exactly: if the two agreed everywhere, the
1392- /// substitution could not change a single predicted sample and the
1393- /// exactness assert would be measuring a witness the fix cannot touch.
1394- ///
1395- /// What it does NOT prove is that the argument handed to the unit reader
1396- /// is the per-unit one -- the count is taken from the same expression
1397- /// either way, so deleting the substitution reds the exactness assert
1398- /// rather than this counter. That is the right way round: the assert is
1399- /// the claim, this is only the floor under it.
1400- pub(super) static RECT_TILED_CHROMA_UNIT_REACH_HITS: std::cell::Cell<usize> =
1401- const { std::cell::Cell::new(0) };
1402- /// Chroma units of the same walk whose grid is exactly 2x1 (a 4:4:4
1403- /// 64x32 chroma plane block as two 32x32 units).
1404- pub(super) static RECT_TILED_CHROMA_2X1_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1405- /// Chroma units of the same walk whose grid is exactly 1x2 (4:4:4 32x64,
1406- /// or 16x64 as two 16x32s).
1407- pub(super) static RECT_TILED_CHROMA_1X2_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1408- /// Chroma units of the same walk in any other multi-unit grid (2x2 and
1409- /// up). lane-av1422lift: this used to say "only reachable at 4:2:2, which
1410- /// is refused, so this stays 0 on every admitted stream", and that was
1411- /// true. 4:2:2 is decoded now, so the "cannot happen" is gone -- but the
1412- /// arm is still UNWITNESSED: measured on this branch's tip over all 21
1413- /// committed 4:2:2 cells and over the 4:2:0 / 4:4:4 cells probed, it
1414- /// reads 0 on every one of them. No committed gate reads it either (the
1415- /// only readers of `rect_tiled_chroma_grid_hits()` are two 4:4:4 strip
1416- /// gates, where `nxn` is interpolated into a failure message and never
1417- /// asserted). Kept so the match above is exhaustive.
1418- pub(super) static RECT_TILED_CHROMA_NXN_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1419-}
1420-
1421-/// Current values of the four `RECT_TILED_CHROMA_*` counters, in the order
1422-/// `(unit_reach_differs, 2x1, 1x2, other multi-unit)`.
1423-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1424-pub(crate) fn rect_tiled_chroma_grid_hits() -> (usize, usize, usize, usize) {
1425- (
1426- RECT_TILED_CHROMA_UNIT_REACH_HITS.with(|c| c.get()),
1427- RECT_TILED_CHROMA_2X1_HITS.with(|c| c.get()),
1428- RECT_TILED_CHROMA_1X2_HITS.with(|c| c.get()),
1429- RECT_TILED_CHROMA_NXN_HITS.with(|c| c.get()),
1430- )
1431-}
1432-
1433-/// Zeroes the four `RECT_TILED_CHROMA_*` counters (gate tests call this
1434-/// before their own decode).
1435-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1436-pub(crate) fn reset_rect_tiled_chroma_grid_hits() {
1437- RECT_TILED_CHROMA_UNIT_REACH_HITS.with(|c| c.set(0));
1438- RECT_TILED_CHROMA_2X1_HITS.with(|c| c.set(0));
1439- RECT_TILED_CHROMA_1X2_HITS.with(|c| c.set(0));
1440- RECT_TILED_CHROMA_NXN_HITS.with(|c| c.set(0));
1441-}
1442-
1443-// lane-t900 r22: palette blocks reconstructed inside an INTER frame (the
1444-// intra-in-inter path, `decode_inter_block`/`decode_inter_block8`) -- counted
1445-// apart from [`PALETTE_HITS`] so a witness gate can prove the INTER-frame
1446-// capability rather than the key frame's, which every screen stream also
1447-// carries.
1448-thread_local! {
1449- pub(super) static INTRA_IN_INTER_PALETTE_Y_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1450- pub(super) static INTRA_IN_INTER_PALETTE_UV_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1451-}
1452-
1453-// lane-t900 r23: as [`INTRA_IN_INTER_PALETTE_Y_HITS`], narrowed to the 8x8
1454-// LEAF site ([`decode_inter_block8`]'s intra arm) -- the >=16 site fires the
1455-// shared counter too, so only this one proves a gate really reached the leaf
1456-// where the refusal used to sit.
1457-thread_local! {
1458- pub(super) static INTER8_PALETTE_HITS: std::cell::Cell<(usize, usize)> =
1459- const { std::cell::Cell::new((0, 0)) };
1460-}
1461-
1462-/// Current values of the 8x8-leaf intra-in-inter palette counters, `(y, uv)`.
1463-pub(crate) fn inter8_palette_hits() -> (usize, usize) {
1464- INTER8_PALETTE_HITS.with(std::cell::Cell::get)
1465-}
1466-
1467-/// Current values of the two intra-in-inter palette counters, `(y, uv)`.
1468-pub(crate) fn intra_in_inter_palette_hits() -> (usize, usize) {
1469- (
1470- INTRA_IN_INTER_PALETTE_Y_HITS.with(|c| c.get()),
1471- INTRA_IN_INTER_PALETTE_UV_HITS.with(|c| c.get()),
1472- )
1473-}
1474-
1475-// lane-hgkf r2: SKIPPED intra blocks whose `tx_depth` split the luma transform
1476-// and which are therefore predicted one transform unit at a time (a skipped
1477-// block codes no coefficients, so nothing else in the stream witnesses this
1478-// path -- only the pixels do).
1479-thread_local! {
1480- pub(super) static SKIP_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1481-}
1482-
1483-/// Current value of [`SKIP_SPLIT_TX_HITS`] (blocks, not units).
1484-pub fn skip_split_tx_hits() -> usize {
1485- SKIP_SPLIT_TX_HITS.with(|c| c.get())
1486-}
1487-
1488-// lane-svt1: SKIPPED square blocks carrying a palette/intrabc prediction whose
1489-// `tx_depth` split the luma transform -- the arm that predicted DC off the
1490-// block edges before the fix. Like [`SKIP_SPLIT_TX_HITS`] only the pixels
1491-// witness this path, so a gate that wants it needs the counter.
1492-thread_local! {
1493- pub(super) static SKIP_SPLIT_TX_OVERRIDE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1494- /// lane-av1chromadc: chroma units of a skipped block whose intra-BC /
1495- /// UV-palette override had to be WINDOWED to the unit's own extent --
1496- /// i.e. `cn_cols * cn_rows > 1`, which at 4:2:0 never happens (the chroma
1497- /// plane block is one 32x32 unit) and at 4:4:4 is every block of 64 and
1498- /// above. Counts UNITS, not blocks. EXCLUSIVE to this walk: the other two
1499- /// override sites (the luma slot and `decode_intrabc_owned_rect`) have
1500- /// their own windows.
1501- pub(super) static SKIP_CHROMA_OVERRIDE_WINDOW_HITS: std::cell::Cell<usize> =
1502- const { std::cell::Cell::new(0) };
1503-}
1504-
1505-/// Current value of [`SKIP_SPLIT_TX_OVERRIDE_HITS`] (blocks).
1506-pub fn skip_split_tx_override_hits() -> usize {
1507- SKIP_SPLIT_TX_OVERRIDE_HITS.with(|c| c.get())
1508-}
1509-
1510-/// lane-av1chromadc: [`SKIP_CHROMA_OVERRIDE_WINDOW_HITS`].
1511-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1512-pub fn skip_chroma_override_window_hits() -> usize {
1513- SKIP_CHROMA_OVERRIDE_WINDOW_HITS.with(|c| c.get())
1514-}
1515-
1516-/// Zeroes [`SKIP_CHROMA_OVERRIDE_WINDOW_HITS`] before a gate's own decode.
1517-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1518-pub fn reset_skip_chroma_override_window_hits() {
1519- SKIP_CHROMA_OVERRIDE_WINDOW_HITS.with(|c| c.set(0));
1520-}
1521-
1522-/// Zeroes [`SKIP_SPLIT_TX_OVERRIDE_HITS`] before a gate's own decode attempt.
1523-pub fn reset_skip_split_tx_override_hits() {
1524- SKIP_SPLIT_TX_OVERRIDE_HITS.with(|c| c.set(0));
1525-}
1526-
1527-// lane-svtinter: palette colour-index maps whose block is cut by the frame's
1528-// bottom/right mi edge, so spec 5.11.50's `onscreenWidth`/`onscreenHeight`
1529-// really are smaller than the block and FEWER symbols are read than the
1530-// block has cells (class map-read-past-frame-edge).
1531-thread_local! {
1532- pub(super) static PALETTE_ONSCREEN_CUT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1533-}
1534-
1535-/// Current value of [`PALETTE_ONSCREEN_CUT_HITS`] (colour-index maps).
1536-pub fn palette_onscreen_cut_hits() -> usize {
1537- PALETTE_ONSCREEN_CUT_HITS.with(|c| c.get())
1538-}
1539-
1540-/// Zeroes [`PALETTE_ONSCREEN_CUT_HITS`] before a gate's own decode attempt.
1541-pub fn reset_palette_onscreen_cut_hits() {
1542- PALETTE_ONSCREEN_CUT_HITS.with(|c| c.set(0));
1543-}
1544-
1545-/// Zeroes [`SKIP_SPLIT_TX_HITS`] before a gate's own decode attempt.
1546-pub fn reset_skip_split_tx_hits() {
1547- SKIP_SPLIT_TX_HITS.with(|c| c.set(0));
1548-}
1549-
1550-// lane-intrainter r1: intra blocks inside an INTER frame whose `tx_depth`
1551-// symbol split their luma transform, bucketed by block side (8, 16, 32, 64) --
1552-// the gate's proof that the lifted path actually ran, per size.
1553-thread_local! {
1554- pub(super) static INTRA_IN_INTER_SPLIT_TX_HITS: std::cell::Cell<[usize; 4]> =
1555- const { std::cell::Cell::new([0; 4]) };
1556-}
1557-
1558-/// Current value of [`INTRA_IN_INTER_SPLIT_TX_HITS`], indexed 8/16/32/64.
1559-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1560-pub(crate) fn intra_in_inter_split_tx_hits() -> [usize; 4] {
1561- INTRA_IN_INTER_SPLIT_TX_HITS.with(std::cell::Cell::get)
1562-}
1563-
1564-thread_local! {
1565- /// The current frame's `mi` grid, kept only while a frame header set
1566- /// `allow_intrabc` -- an intrabc block's DV predictor is the ordinary
1567- /// MV stack ([`crate::mvstack::find_mv_stack`]) built against
1568- /// `INTRA_FRAME`, which needs the neighbour state a key frame otherwise
1569- /// never keeps. `(grid, mi_cols, mi_rows)`; `None` on every frame that
1570- /// does not allow intrabc (so nothing is paid for it).
1571- ///
1572- /// corner-cut: only [`decode_block`] (the square path) records into it,
1573- /// so a frame mixing intrabc with rect/sub-8x8 leaves would predict off
1574- /// an incomplete grid. Ceiling: the DV *value* (never the parse) would
1575- /// be wrong there; upgrade = record from the rect/leaf paths too.
1576- /// The block vector [`read_intra_mode`] just decoded, handed to
1577- /// [`decode_block`] off the call stack (same idiom as [`PALETTE_PRED`],
1578- /// which the alternative -- a tenth tuple member through every caller --
1579- /// already avoids). Always `.take()`n by the block that reads it.
1580- /// How many blocks read `use_intrabc == 1` and took the DV path -- the
1581- /// gate's hit counter. Bumped on the READ, before the rect-strip refusal
1582- /// returns too, so it counts reads, not reconstructions (a refused block
1583- /// is never reconstructed).
1584- pub(super) static INTRABC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1585-}
1586-
1587-/// Zeroes [`RECT_INTRABC_READS`] (gate tests call this before a decode).
1588-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1589-pub(crate) fn reset_rect_intrabc_reads() {
1590- RECT_INTRABC_READS.with(|c| c.set(0));
1591-}
1592-
1593-thread_local! {
1594- /// Blocks that USED intrabc at an 8x8 LEAF (`decode_leaf8`) specifically
1595- /// -- the shape lane-kf900 r7 fixed; [`INTRABC_HITS`] counts every shape.
1596- pub(super) static LEAF8_INTRABC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1597-}
1598-
1599-thread_local! {
1600- /// Chroma reads of an intrabc TX4-split leaf that consulted an ARMED
1601- /// [`INTRABC_CHROMA_TX`] slot -- proof that the arm's frame-copy +
1602- /// inherited-type route actually ran (lane-av1intrapred r2's non-vacuity
1603- /// counter: zero means the gate's fixture no longer reaches the route).
1604- pub(super) static INTRABC_TX4_CHROMA_COPY_HITS: std::cell::Cell<usize> =
1605- const { std::cell::Cell::new(0) };
1606-}
1607-
1608-/// Current value of [`INTRABC_TX4_CHROMA_COPY_HITS`].
1609-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1610-pub(crate) fn intrabc_tx4_chroma_copy_hits() -> usize {
1611- INTRABC_TX4_CHROMA_COPY_HITS.with(|c| c.get())
1612-}
1613-
1614-/// Zeroes [`INTRABC_TX4_CHROMA_COPY_HITS`] (gate tests call this before a decode).
1615-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1616-pub(crate) fn reset_intrabc_tx4_chroma_copy_hits() {
1617- INTRABC_TX4_CHROMA_COPY_HITS.with(|c| c.set(0));
1618-}
1619-
1620-/// Current value of [`LEAF8_INTRABC_HITS`].
1621-pub(crate) fn leaf8_intrabc_hits() -> usize {
1622- LEAF8_INTRABC_HITS.with(|c| c.get())
1623-}
1624-
1625-/// Zeroes [`LEAF8_INTRABC_HITS`] (gate tests call this before a decode).
1626-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1627-pub(crate) fn reset_leaf8_intrabc_hits() {
1628- LEAF8_INTRABC_HITS.with(|c| c.set(0));
1629-}
1630-
1631-/// Current value of [`INTRABC_HITS`].
1632-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1633-pub(crate) fn intrabc_hits() -> usize {
1634- INTRABC_HITS.with(|c| c.get())
1635-}
1636-
1637-thread_local! {
1638- /// An intrabc block that IS a sub-8x8 group's CHROMA REFERENCE and is
1639- /// SKIPPED: the route that arms [`INTRABC_CHROMA_TX`] and then reads no
1640- /// chroma coefficient at all, so the slot used to stay armed into the NEXT
1641- /// block's chroma read. Both group shapes (4x4 split, 4x8/8x4 rect) count
1642- /// here. A non-zero value is what makes the disarm below load-bearing.
1643- pub(super) static SKIPPED_INTRABC_CHROMA_ARM_HITS: std::cell::Cell<usize> =
1644- const { std::cell::Cell::new(0) };
1645-}
1646-
1647-/// Current value of [`SKIPPED_INTRABC_CHROMA_ARM_HITS`].
1648-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates and the probe
1649-pub(crate) fn skipped_intrabc_chroma_arm_hits() -> usize {
1650- SKIPPED_INTRABC_CHROMA_ARM_HITS.with(|c| c.get())
1651-}
1652-
1653-/// Zeroes [`SKIPPED_INTRABC_CHROMA_ARM_HITS`] (gate tests call this before a
1654-/// decode).
1655-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1656-pub(crate) fn reset_skipped_intrabc_chroma_arm_hits() {
1657- SKIPPED_INTRABC_CHROMA_ARM_HITS.with(|c| c.set(0));
1658-}
1659-
1660-thread_local! {
1661- /// lane-av1-ibcskip2: a sub-8x8 4:4:4 leaf that is BOTH intrabc AND
1662- /// `skip` -- the arm whose chroma is the bare frame copy at the DV
1663- /// (libaom `av1_build_inter_predictors_sb` runs regardless of `skip`).
1664- /// Before the fix this route predicted intra-DC and every one of this
1665- /// fixture's 150 such cells differed from the oracle on both chroma
1666- /// planes.
1667- pub(super) static SKIPPED_INTRABC_DV_COPY_HITS: std::cell::Cell<usize> =
1668- const { std::cell::Cell::new(0) };
1669-}
1670-
1671-/// Current value of [`SKIPPED_INTRABC_DV_COPY_HITS`].
1672-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1673-pub(crate) fn skipped_intrabc_dv_copy_hits() -> usize {
1674- SKIPPED_INTRABC_DV_COPY_HITS.with(|c| c.get())
1675-}
1676-
1677-/// Zeroes [`SKIPPED_INTRABC_DV_COPY_HITS`] (gate tests call this before a
1678-/// decode).
1679-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1680-pub(crate) fn reset_skipped_intrabc_dv_copy_hits() {
1681- SKIPPED_INTRABC_DV_COPY_HITS.with(|c| c.set(0));
1682-}
1683-
1684-/// Zeroes [`INTRABC_HITS`] (gate tests call this before a decode).
1685-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1686-pub(crate) fn reset_intrabc_hits() {
1687- INTRABC_HITS.with(|c| c.set(0));
1688-}
1689-
1690-thread_local! {
1691- /// lane-t900 r32: intrabc blocks whose transform size came off the INTER
1692- /// var-tx partition tree (unskipped, `TX_MODE_SELECT`) -- the capability
1693- /// that replaced the refusal "an intrabc block under TxMode::Select".
1694- pub(super) static INTRABC_VARTX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1695- /// lane-av1-ibcvtx: intrabc var-tx trees that resolved to MIXED leaf
1696- /// sizes (not one square size across every leaf) -- the engagement
1697- /// counter proving a witness actually exercises the per-leaf reconstruct.
1698- pub(super) static INTRABC_VARTX_MIXED_LEAVES_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1699- /// lane-av1txr: as above for a `BLOCK_4X8`/`BLOCK_8X4` intrabc leaf --
1700- /// libaom's `block_signals_txsize` is `bsize > BLOCK_4X4`, so these leaves
1701- /// signal a transform size where a plain `BLOCK_4X4` does not. Reading no
1702- /// symbol here desynced `warped.obu` at the very next block.
1703- pub(super) static RECT_INTRABC_VARTX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1704- /// lane-av1-intrabc: rect INTRABC blocks whose reconstruction
1705- /// [`decode_intrabc_rect`] ran -- the engagement counter the rect-strip
1706- /// gates assert on (a refused block bumps [`INTRABC_HITS`] but never
1707- /// this one).
1708- pub(super) static INTRABC_RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1709- /// Of those, how many read the INTER var-tx tree (unskipped, TX_MODE_SELECT).
1710- pub(super) static INTRABC_RECT_VARTX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1711- /// lane-av1-intrabc r4: rect INTRABC blocks whose reconstruction
1712- /// [`decode_intrabc_rect`] ran with `skip == 0` (a real residual read),
1713- /// split by the strip's orientation -- `bw > bh` is a HORZ strip,
1714- /// `bh > bw` a VERT one. The reviewer's unblock condition needs a CODED
1715- /// witness in BOTH orientations, and the existing `INTRABC_RECT_HITS`
1716- /// counts neither orientation nor the skip flag, so an arm that flipped
1717- /// to an all-skip stream (no residual reader at all) would stay green.
1718- pub(super) static INTRABC_RECT_CODED_HITS: std::cell::Cell<[usize; 2]> =
1719- const { std::cell::Cell::new([0, 0]) };
1720- /// lane-av1-intrabc r5: the `skip == 1` twin of [`INTRABC_RECT_CODED_HITS`]
1721- /// -- rect INTRABC blocks reconstructed as a bare prediction copy, split
1722- /// by orientation. The r5 panic (residual stride `bw * bh` underrunning
1723- /// `reconstruct_mc_rect`'s `row * side + w` index on a VERT strip) was
1724- /// invisible to every gate because they only counted CODED strips.
1725- pub(super) static INTRABC_RECT_SKIPPED_HITS: std::cell::Cell<[usize; 2]> =
1726- const { std::cell::Cell::new([0, 0]) };
1727- /// lane-ibc444c: rect intra-BC blocks whose chroma plane block was sized
1728- /// `bw >> ss_x` by `bh >> ss_y` -- the 4:4:4 and 4:4:0 cells, where
1729- /// `av1_get_max_uv_txsize` (`ss_size_lookup[bsize]`, blockd.h) applies no
1730- /// halving of its own. At 4:2:0 this is the same arithmetic as the halving,
1731- /// so a `>= 1` witness can only come from a stream that is not 4:2:0.
1732- /// EXCLUSIVE to this arm: no other caller sizes an intrabc rect block's
1733- /// chroma plane block.
1734- pub(super) static IBC_RECT_CHROMA_FOOTPRINT_444_HITS: std::cell::Cell<usize> =
1735- const { std::cell::Cell::new(0) };
1736- /// lane-whtshape: LOSSLESS rect intrabc blocks whose chroma plane block
1737- /// [`decode_intrabc_rect`] walked as a `(cw/4) * (ch/4)` PLANE-MAJOR
1738- /// raster of TX_4X4 units -- the shape libaom's lossless geometry codes
1739- /// (`read_tx_size` returns `TX_4X4` for EVERY plane of a lossless block,
1740- /// `get_vartx_max_txsize` likewise, and `read_tx_mode` forced the frame's
1741- /// `ONLY_4X4`) -- instead of the single rect unit, which is what put a
1742- /// non-4x4 unit on the lossless Walsh-Hadamard path. EXCLUSIVE to this arm:
1743- /// no other caller walks a rect intrabc block's chroma, so `>= 1` cannot
1744- /// be satisfied by any older route.
1745- pub(super) static INTRABC_RECT_LOSSLESS_CHROMA4_HITS: std::cell::Cell<usize> =
1746- const { std::cell::Cell::new(0) };
1747- /// lane-av1chromarect: 128-root intra-BC HORZ/VERT strips
1748- /// ([`decode_intrabc_owned_rect`]) whose chroma plane block was sized
1749- /// `bw >> ss_x` by `bh >> ss_y` -- the 4:4:4 and 4:4:0 cells, where
1750- /// `av1_get_max_uv_txsize` (`ss_size_lookup[bsize]`, blockd.h:1372) applies
1751- /// no halving of its own. At 4:2:0 the two forms are the same arithmetic,
1752- /// so a `>= 1` witness can only come from a stream that is not 4:2:0.
1753- /// EXCLUSIVE to this arm: no other caller sizes a 128-root intra-BC
1754- /// strip's chroma plane block.
1755- pub(super) static IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS: std::cell::Cell<usize> =
1756- const { std::cell::Cell::new(0) };
1757- /// lane-av1422ibctxsel: `decode_intrabc_owned_rect`'s NON-SPLIT chroma
1758- /// gather taken through the 4:2:2 pair rule (`around_mi_422_chroma`)
1759- /// under the ss (1, 0) guard -- both residual branches (the var-tx tree
1760- /// and the no-leaves twin). `>= 1` can only come from a 4:2:2 stream
1761- /// that reaches this function's non-split chroma arm; the 4:2:0/4:4:4
1762- /// arms keep the plain `around_mi_rect` gather (`ss_y != 0` / `ss_x == 0`
1763- /// take the else), so the counter stays 0 for them.
1764- pub(super) static IBC_OWNED_RECT_422_PAIR_HITS: std::cell::Cell<usize> =
1765- const { std::cell::Cell::new(0) };
1766-}
1767-
1768-/// lane-av1-intrabc r4: coded (`skip == 0`) rect intrabc blocks reconstructed,
1769-/// as `[horz, vert]` -- see [`INTRABC_RECT_CODED_HITS`].
1770-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1771-pub fn intrabc_rect_coded_hits() -> [usize; 2] {
1772- INTRABC_RECT_CODED_HITS.with(std::cell::Cell::get)
1773-}
1774-
1775-/// lane-av1-intrabc r5: skipped (`skip == 1`) rect intrabc blocks
1776-/// reconstructed, as `[horz, vert]` -- see [`INTRABC_RECT_SKIPPED_HITS`].
1777-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1778-pub fn intrabc_rect_skipped_hits() -> [usize; 2] {
1779- INTRABC_RECT_SKIPPED_HITS.with(std::cell::Cell::get)
1780-}
1781-
1782-/// Current value of [`INTRABC_RECT_HITS`].
1783-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1784-pub fn intrabc_rect_hits() -> usize {
1785- INTRABC_RECT_HITS.with(|c| c.get())
1786-}
1787-
1788-/// Zeroes [`INTRABC_RECT_HITS`]/[`INTRABC_RECT_VARTX_HITS`].
1789-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1790-pub(crate) fn reset_intrabc_rect_hits() {
1791- INTRABC_RECT_HITS.with(|c| c.set(0));
1792- INTRABC_RECT_VARTX_HITS.with(|c| c.set(0));
1793- INTRABC_RECT_CODED_HITS.with(|c| c.set([0, 0]));
1794- INTRABC_RECT_SKIPPED_HITS.with(|c| c.set([0, 0]));
1795-}
1796-
1797-/// lane-ibc444c: [`IBC_RECT_CHROMA_FOOTPRINT_444_HITS`].
1798-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1799-pub fn ibc_rect_chroma_footprint_444_hits() -> usize {
1800- IBC_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.get())
1801-}
1802-
1803-/// lane-ibc444c: zeroes [`IBC_RECT_CHROMA_FOOTPRINT_444_HITS`].
1804-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1805-pub(crate) fn reset_ibc_rect_chroma_footprint_444_hits() {
1806- IBC_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0));
1807-}
1808-
1809-/// lane-av1chromarect: [`IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS`].
1810-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1811-pub fn ibc_owned_rect_chroma_footprint_444_hits() -> usize {
1812- IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.get())
1813-}
1814-
1815-/// lane-av1chromarect: zeroes [`IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS`].
1816-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1817-pub(crate) fn reset_ibc_owned_rect_chroma_footprint_444_hits() {
1818- IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0));
1819-}
1820-
1821-/// lane-av1422ibctxsel: [`IBC_OWNED_RECT_422_PAIR_HITS`].
1822-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1823-pub fn ibc_owned_rect_422_pair_hits() -> usize {
1824- IBC_OWNED_RECT_422_PAIR_HITS.with(|c| c.get())
1825-}
1826-
1827-/// lane-av1422ibctxsel: zeroes [`IBC_OWNED_RECT_422_PAIR_HITS`].
1828-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1829-pub(crate) fn reset_ibc_owned_rect_422_pair_hits() {
1830- IBC_OWNED_RECT_422_PAIR_HITS.with(|c| c.set(0));
1831-}
1832-
1833-/// lane-whtshape: [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`].
1834-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1835-pub fn intrabc_rect_lossless_chroma4_hits() -> usize {
1836- INTRABC_RECT_LOSSLESS_CHROMA4_HITS.with(|c| c.get())
1837-}
1838-
1839-/// lane-whtshape: zeroes [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`].
1840-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1841-pub(crate) fn reset_intrabc_rect_lossless_chroma4_hits() {
1842- INTRABC_RECT_LOSSLESS_CHROMA4_HITS.with(|c| c.set(0));
1843-}
1844-
1845-/// Current value of [`INTRABC_RECT_VARTX_HITS`].
1846-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1847-pub fn intrabc_rect_vartx_hits() -> usize {
1848- INTRABC_RECT_VARTX_HITS.with(|c| c.get())
1849-}
1850-
1851-thread_local! {
1852- /// lane-av1-ibcrect: `use_intrabc` blocks on a 128-root HORZ/VERT strip
1853- /// (BLOCK_128X64 / BLOCK_64X128) whose reconstruction
1854- /// [`decode_intrabc_128rect`] ran -- the shape the named refusal used to
1855- /// guard (`decode_block_128rect`). A refused block bumps
1856- /// [`INTRABC_HITS`] but never this one.
1857- pub(super) static INTRABC_128RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1858- /// lane-av1-ibc128chunk: chroma transform units the 128-root intrabc
1859- /// strip's mu-chunk walk read, one per `read_inter_plane` chroma call.
1860- /// At 4:2:0 a 64x64 mu chunk's chroma plane block is 32x32, so one
1861- /// TX_32X32 per plane per chunk; at 4:2:2 it is 32x64 and holds TWO
1862- /// STACKED units per plane. The square-cut `chunk_chroma = cside * 64 /
1863- /// side` model walked the 4:2:0 count on every axis, so this counter is
1864- /// the reach/arm witness for the per-axis walk.
1865- pub(super) static INTRABC_128RECT_CHROMA_CHUNK_HITS: std::cell::Cell<usize> =
1866- const { std::cell::Cell::new(0) };
1867-}
1868-
1869-/// Current value of [`INTRABC_128RECT_HITS`].
1870-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1871-pub fn intrabc_128rect_hits() -> usize {
1872- INTRABC_128RECT_HITS.with(|c| c.get())
1873-}
1874-
1875-/// Zeroes [`INTRABC_128RECT_HITS`].
1876-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1877-pub(crate) fn reset_intrabc_128rect_hits() {
1878- INTRABC_128RECT_HITS.with(|c| c.set(0));
1879-}
1880-
1881-/// Current value of [`INTRABC_128RECT_CHROMA_CHUNK_HITS`].
1882-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1883-pub fn intrabc_128rect_chroma_chunk_hits() -> usize {
1884- INTRABC_128RECT_CHROMA_CHUNK_HITS.with(|c| c.get())
1885-}
1886-
1887-/// Zeroes [`INTRABC_128RECT_CHROMA_CHUNK_HITS`] and
1888-/// [`INTRABC_128RECT_CHUNK_SHAPE`].
1889-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1890-pub(crate) fn reset_intrabc_128rect_chroma_chunk_hits() {
1891- INTRABC_128RECT_CHROMA_CHUNK_HITS.with(|c| c.set(0));
1892- INTRABC_128RECT_CHUNK_SHAPE.with(|c| c.set(0));
1893-}
1894-
1895-/// Current value of [`INTRABC_VARTX_HITS`].
1896-pub fn intrabc_vartx_hits() -> usize {
1897- INTRABC_VARTX_HITS.with(|c| c.get())
1898-}
1899-
1900-/// Current value of [`INTRABC_VARTX_MIXED_LEAVES_HITS`].
1901-pub fn intrabc_vartx_mixed_leaves_hits() -> usize {
1902- INTRABC_VARTX_MIXED_LEAVES_HITS.with(|c| c.get())
1903-}
1904-
1905-/// Zeroes [`INTRABC_VARTX_HITS`] (gate tests call this before a decode).
1906-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1907-pub(crate) fn reset_intrabc_vartx_hits() {
1908- INTRABC_VARTX_HITS.with(|c| c.set(0));
1909-}
1910-
1911-/// Zeroes [`INTRABC_VARTX_MIXED_LEAVES_HITS`] (gate tests call this before a
1912-/// decode).
1913-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1914-pub(crate) fn reset_intrabc_vartx_mixed_leaves_hits() {
1915- INTRABC_VARTX_MIXED_LEAVES_HITS.with(|c| c.set(0));
1916-}
1917-
1918-/// Current value of [`RECT_INTRABC_VARTX_HITS`].
1919-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1920-pub fn rect_intrabc_vartx_hits() -> usize {
1921- RECT_INTRABC_VARTX_HITS.with(|c| c.get())
1922-}
1923-
1924-// How many blocks decoded `skip_mode == 1` (lane-av1comp round 14) --
1925-// proves a real `skip_mode_present` stream actually reached a block that
1926-// picked it, not just that the frame header bit was set.
1927-thread_local! {
1928- pub(super) static SKIP_MODE_HITS: std::cell::Cell<usize> =
1929- const { std::cell::Cell::new(0) };
1930-}
1931-
1932-/// Current value of [`SKIP_MODE_HITS`].
1933-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1934-pub(crate) fn skip_mode_hits() -> usize {
1935- SKIP_MODE_HITS.with(|c| c.get())
1936-}
1937-
1938-// lane-motionmode: how many blocks actually decoded `obmc_selected == true`
1939-// (as opposed to just reaching an eligible `read_motion_mode` symbol read)
1940-// -- the gate's own proof that a real aomenc `--enable-obmc=1` stream
1941-// reached [`obmc_blend`], not just the header bit.
1942-thread_local! {
1943- pub(super) static OBMC_HITS: std::cell::Cell<usize> =
1944- const { std::cell::Cell::new(0) };
1945-}
1946-
1947-// lane-fimv r1 (class wrong-alphabet-same-value): how many blocks took the
1948-// 2-symbol `obmc_cdf` alphabet *because* `force_integer_mv` (or a scaled
1949-// reference) vetoed `WARPED_CAUSAL` in libaom `motion_mode_allowed`, while
1950-// `allow_warped_motion == 1` and `num_proj_ref >= 1` would otherwise have
1951-// picked the 3-symbol `motion_mode_cdf`. These are exactly the blocks this
1952-// decoder used to read with the wrong alphabet, so a gate that asserts this
1953-// counter advanced proves the fixed path fired (class
1954-// `gate-blind-to-feature`).
1955-thread_local! {
1956- pub(super) static FIMV_ALPHABET_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1957-}
1958-
1959-/// Current value of [`FIMV_ALPHABET_HITS`].
1960-pub fn fimv_alphabet_hits() -> usize {
1961- FIMV_ALPHABET_HITS.with(|c| c.get())
1962-}
1963-
1964-// lane-fimv r1: how many frame headers this decoder has decoded with
1965-// `force_integer_mv == 1` (bumped by `stream.rs` per frame). Lets a gate
1966-// prove the encoder really produced the header state under test rather than
1967-// assume it.
1968-thread_local! {
1969- pub(super) static FIMV_FRAME_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1970-}
1971-
1972-/// Current value of [`FIMV_FRAME_HITS`].
1973-pub fn fimv_frame_hits() -> usize {
1974- FIMV_FRAME_HITS.with(|c| c.get())
1975-}
1976-
1977-/// Current value of [`OBMC_HITS`].
1978-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1979-pub(crate) fn obmc_hits() -> usize {
1980- OBMC_HITS.with(|c| c.get())
1981-}
1982-
1983-// lane-scaledref r1: per-case firing counts for the scaled-reference gate
1984-// (class `gate-blind-to-feature`) -- a pixel match under an UNSCALED
1985-// reference would pass just as well and prove nothing, so the gate
1986-// hard-asserts each combination this round lifts actually occurred:
1987-// a compound block with a scaled tap, a warp block whose warp libaom
1988-// suppresses because the reference is scaled, an OBMC block, an interintra
1989-// block, and an 8x8 leaf.
1990-thread_local! {
1991- pub(super) static SCALED_COMPOUND_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1992- pub(super) static SCALED_WARP_FALLBACK_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1993- pub(super) static SCALED_OBMC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1994- pub(super) static SCALED_INTERINTRA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1995- pub(super) static SCALED_BLOCK8_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1996- pub(super) static SCALED_WARP_SUPPRESSED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1997- pub(super) static MIXED_SCALE_COMPOUND_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1998-}
1999-
2000-/// Current value of [`MIXED_SCALE_COMPOUND_HITS`]: compound blocks with one
crates/ec-av1/src/decode/deblock.rsmodified+33 -49
@@ -1,7 +1,7 @@
11 //! Deblocking filters: the edge filters, the deblock plane drivers, the filter-replay capture and the pooled plane scratch. Moved out of `decode/mod.rs` (av1split D12); the items are unchanged apart from visibility.
22
3-use archmage::SimdToken;
43 use super::*;
4+use archmage::SimdToken;
55
66 /// `update_sharpness`'s per-level `(blimit, limit, hev_thr)` triple.
77 fn deblock_thresholds(level: i32, sharpness: u8) -> (i32, i32, i32) {
@@ -463,12 +463,6 @@ pub(super) fn deblock_plane_span(
463463 plane.true_height.min(ch),
464464 plane.width,
465465 );
466- if crate::envflags::env_flag!("EC_AV1_DEBLOCK_TRACE_V") {
467- eprintln!(
468- "DEBLOCK plane={plane_idx} tw={tw} th={th} stride={stride} true={}x{} crop={cw}x{ch}",
469- plane.true_width, plane.true_height
470- );
471- }
472466 // lane-perf8: both passes iterate the edge's OWN direction innermost, so
473467 // 4 consecutive 4-sample groups (16 lines) can go through one AVX2
474468 // kernel. The swap is order-preserving: a filtered group overlaps only
@@ -523,20 +517,20 @@ pub(super) fn deblock_plane_span(
523517 std::array::from_fn(|k| edge_params(&vctx, x0, y0 + 4 * k));
524518 if let Some((len, level)) = ps[0]
525519 && ps.iter().all(|p| *p == ps[0])
526- && filter_edge16(
527- mine,
528- (y0 - y_lo) * stride + x0,
529- stride,
530- true,
531- len,
532- level,
533- lf.sharpness,
534- fctx,
535- )
536- {
537- y0 += 16;
538- continue;
539- }
520+ && filter_edge16(
521+ mine,
522+ (y0 - y_lo) * stride + x0,
523+ stride,
524+ true,
525+ len,
526+ level,
527+ lf.sharpness,
528+ fctx,
529+ )
530+ {
531+ y0 += 16;
532+ continue;
533+ }
540534 for (k, p) in ps.iter().enumerate() {
541535 if let Some((len, level)) = *p {
542536 filter_edge(
@@ -555,9 +549,6 @@ pub(super) fn deblock_plane_span(
555549 continue;
556550 }
557551 if let Some((len, level)) = edge_params(&vctx, x0, y0) {
558- if crate::envflags::env_flag!("EC_AV1_DEBLOCK_TRACE_V") && plane_idx == 0 {
559- eprintln!("VEDGE x0={x0} y0={y0} len={len} level={level}");
560- }
561552 filter_edge(
562553 mine,
563554 (y0 - y_lo) * stride + x0,
@@ -637,20 +628,20 @@ pub(super) fn deblock_plane_span(
637628 std::array::from_fn(|k| edge_params(&hctx, x0 + 4 * k, y0));
638629 if let Some((len, level)) = ps[0]
639630 && ps.iter().all(|p| *p == ps[0])
640- && filter_edge16(
641- px,
642- (y0 - r_lo) * w + (x0 - x_lo),
643- w,
644- false,
645- len,
646- level,
647- lf.sharpness,
648- fctx,
649- )
650- {
651- x0 += 16;
652- continue;
653- }
631+ && filter_edge16(
632+ px,
633+ (y0 - r_lo) * w + (x0 - x_lo),
634+ w,
635+ false,
636+ len,
637+ level,
638+ lf.sharpness,
639+ fctx,
640+ )
641+ {
642+ x0 += 16;
643+ continue;
644+ }
654645 for (k, p) in ps.iter().enumerate() {
655646 if let Some((len, level)) = *p {
656647 filter_edge(
@@ -669,15 +660,6 @@ pub(super) fn deblock_plane_span(
669660 continue;
670661 }
671662 if let Some((len, level)) = edge_params(&hctx, x0, y0) {
672- if crate::envflags::env_flag!("EC_AV1_DEBLOCK_TRACE")
673- && plane_idx == 0
674- && x0 == 44
675- {
676- eprintln!(
677- "HEDGE x0={x0} y0={y0} len={len} level={level} sharpness={}",
678- lf.sharpness
679- );
680- }
681663 filter_edge(
682664 px,
683665 (y0 - r_lo) * w + (x0 - x_lo),
@@ -716,7 +698,8 @@ pub(super) fn deblock_plane_span(
716698 /// every pool thread the decode ever created. One shared pool with a hard
717699 /// entry cap bounds the retention at [`SCRATCH_CAP`] buffers no matter how
718700 /// many threads cycle through it; anything over the cap is freed.
719-pub(super) static PLANE_SCRATCH: std::sync::Mutex<Vec<Vec<u16>>> = std::sync::Mutex::new(Vec::new());
701+pub(super) static PLANE_SCRATCH: std::sync::Mutex<Vec<Vec<u16>>> =
702+ std::sync::Mutex::new(Vec::new());
720703
721704 /// Most buffers the shared pool keeps. ~3 whole-plane sets per in-flight 4K
722705 /// frame at the shipped `EC_AV1_THREADS` ceiling; the frames actually in
@@ -877,7 +860,8 @@ pub(crate) fn arm_filter_replay() {
877860 /// can hold the replay against the decode it stands in for
878861 /// (`encoder::tests::filter_replay_codes_the_same_stream_as_a_full_decode`).
879862 #[cfg(test)]
880-pub(super) static REPLAY_DISABLED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
863+pub(super) static REPLAY_DISABLED: std::sync::atomic::AtomicBool =
864+ std::sync::atomic::AtomicBool::new(false);
881865
882866 #[cfg(test)]
883867 pub(crate) fn set_filter_replay_disabled(off: bool) {
crates/ec-av1/src/decode/frame_tile.rsmodified+7 -346
@@ -417,13 +417,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
417417 let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK);
418418
419419 let mut y = PlaneBuf {
420- data: std::borrow::Cow::Owned(fresh_plane(
421- width * height,
422- true_width,
423- true_height,
424- width,
425- height,
426- )),
420+ data: std::borrow::Cow::Owned(fresh_plane(width * height)),
427421 width,
428422 height,
429423 true_width,
@@ -435,10 +429,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
435429 plane: 0,
436430 };
437431 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));
438- note_frame_chroma_alloc((width, height), (cw, ch), (ss_x(fctx), ss_y(fctx)));
439432 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));
440433 let mut u = PlaneBuf {
441- data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)),
434+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
442435 width: cw,
443436 height: ch,
444437 true_width: ctw,
@@ -450,7 +443,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
450443 plane: 1,
451444 };
452445 let mut v = PlaneBuf {
453- data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)),
446+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
454447 width: cw,
455448 height: ch,
456449 true_width: ctw,
@@ -542,17 +535,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
542535 // lane-av1txr: spec 5.9.2's `disable_cdf_update` -- a frame that sets
543536 // it codes every symbol against the tables it started with.
544537 dec.set_cdf_update(!cdf_update_disabled(fctx));
545- crate::census::register_cdfs(&cdfs);
546538 // lane-comppin r9: tile-entry range, the earliest point comparable
547539 // against aomdec's own `r->ec.rng` right after `aom_reader_init` -- the
548540 // first ladder rung before any symbol (partition or otherwise) is read.
549- if crate::envflags::env_flag!("EC_AV1_TELL") {
550- eprintln!(
551- "TELL label=tile_init tell={} range={}",
552- dec.debug_bitpos(),
553- dec.debug_state().0
554- );
555- }
556541 neighbours.start_tile(mi_row0 as usize, mi_col0 as usize, mi_col1 as usize, fctx);
557542 y.set_tile_origin(
558543 mi_col0 as usize * 4,
@@ -583,7 +568,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
583568 mi_row1 as usize,
584569 mi_col1 as usize,
585570 );
586- hit!(TILE_HITS);
587571
588572 // lane-sb128 r2: at `sb_size == 128` the tile walks each 128x128
589573 // superblock's four 64x64 quadrants in libaom `decode_partition` order
@@ -985,11 +969,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
985969 bw,
986970 bh
987971 );
988- if horz {
989- hit!(INTER_SB128_HORZ_HITS);
990- } else {
991- hit!(INTER_SB128_VERT_HITS);
992- }
993972 }
994973 // One `cdef_idx` per BLOCK, copied to every 64x64 CDEF unit it
995974 // covers -- both halves of the root read their own, and the
@@ -1023,7 +1002,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
10231002 continue;
10241003 }
10251004 if sb128_none {
1026- hit!(INTER_SB128_NONE_HITS);
10271005 let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4);
10281006 // lane-sb128c r3: `at128` is in SUB16 units like `sb_at`;
10291007 // `decode_inter_block` takes MI. Unconverted it was (0,0) for
@@ -1076,16 +1054,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
10761054 // instead of silently decoding as SPLIT and desyncing.
10771055 let part64 = match (has_cols, has_rows) {
10781056 (true, true) => {
1079- let pre_rng = dec.debug_state().0;
1080- if crate::envflags::env_flag!("EC_TRACE_PART") {
1081- eprintln!(
1082- "EC_PART mi_row={} mi_col={} bsize=12 ctx={} rng={}",
1083- sb_r as usize * SB_MI as usize,
1084- sb_c as usize * SB_MI as usize,
1085- sb_ctx,
1086- dec.debug_state().0
1087- );
1088- }
10891057 let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]);
10901058 // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be
10911059 // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize`
@@ -1094,33 +1062,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
10941062 // arm -- VERT, VERT_A / VERT_B, HORZ_4 and VERT_4 -- and the HORZ siblings
10951063 // keep decoding because the helper is exact, not a heuristic. inter-frame 64x64 level; `p` is the symbol.
10961064
1097- if crate::envflags::env_flag!("EC_AV1_TRACE") {
1098- eprintln!(
1099- "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}",
1100- sb_r * SB_MI,
1101- sb_c * SB_MI
1102- );
1103- }
11041065 p
11051066 }
11061067 (true, false) => {
11071068 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
11081069 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
11091070 // (libaom `ec_read_partition_impl`).
1110- if crate::envflags::env_flag!("EC_TRACE_PART") {
1111- eprintln!(
1112- "EC_PARTG mi_row={} mi_col={} bsize=12 ctx={} rng={}",
1113- sb_r as usize * SB_MI as usize,
1114- sb_c as usize * SB_MI as usize,
1115- sb_ctx,
1116- dec.debug_state().0
1117- );
1118- }
1119- if bump_edge32_bit(
1120- 4,
1121- dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)),
1122- ) == 1
1123- {
1071+ if dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)) == 1 {
11241072 PARTITION_SPLIT
11251073 } else {
11261074 PARTITION_HORZ
@@ -1130,20 +1078,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11301078 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
11311079 // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT
11321080 // (libaom `ec_read_partition_impl`).
1133- if bump_edge32_bit(
1134- 4,
1135- dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)),
1136- ) == 1
1137- {
1081+ if dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)) == 1 {
11381082 PARTITION_SPLIT
11391083 } else {
11401084 PARTITION_VERT
11411085 }
11421086 }
1143- (false, false) => {
1144- bump_edge_both_cut(2);
1145- PARTITION_SPLIT
1146- }
1087+ (false, false) => PARTITION_SPLIT,
11471088 };
11481089 // lane-av1unwritten r7: the symbol is RESOLVED (a full CDF
11491090 // read or an edge `gather`) and about to be dispatched, so the
@@ -1156,16 +1097,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11561097 // see it.
11571098 refuse_invalid_subsize((64, 64), part64, fctx)?;
11581099 if part64 == PARTITION_NONE {
1159- // lane-inter8 r1: the whole superblock as one 64x64 inter
1160- // block. `SB`-sized syntax throughout (size_group 3, same as
1161- // 32x32 -- `size_group_lookup[BLOCK_64X64] == 3`), luma
1162- // coefficients through `TxbSet::Luma64` with the 32-point
1163- // scan (TX_64X64 codes only its top-left corner, spec
1164- // 5.11.40 -- `read_inter_plane` widens the corner back to
1165- // 64x64 before the inverse transform), chroma as a plain
1166- // 32x32 `TxbSet::Chroma32`. TX_64X64 carries no `tx_type`
1167- // symbol at all, so the intra/inter luma sets coincide.
1168- hit!(INTER_SB_NONE_HITS);
11691100 decode_inter_block(
11701101 &mut dec,
11711102 &mut cdfs,
@@ -1220,15 +1151,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
12201151 PARTITION_HORZ | PARTITION_VERT | PARTITION_HORZ_4 | PARTITION_VERT_4
12211152 ) {
12221153 // lane-av1unwritten r6: arm census.
1223- note_subsize_arm(
1224- part64,
1225- chroma_plane_block_codable(
1226- partition_subsize_dims((64, 64), part64).0,
1227- partition_subsize_dims((64, 64), part64).1,
1228- ss_x(fctx),
1229- ss_y(fctx),
1230- ),
1231- );
12321154 // lane-inter4 r1: the superblock-level rect + 1:4 pairs as
12331155 // inter blocks -- two 64x32 / 32x64 strips, or four 64x16 /
12341156 // 16x64 ones. Each piece keeps `side = SB` for every
@@ -1282,38 +1204,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
12821204 bw,
12831205 bh
12841206 );
1285- if !four && i == 0 && ((horz && !has_rows) || (!horz && !has_cols)) {
1286- bump_inter_edge_strip(if horz { 0 } else { 1 });
1287- }
1288- match (horz, four) {
1289- (true, false) => hit!(INTER_SB_HORZ_HITS),
1290- (false, false) => hit!(INTER_SB_VERT_HITS),
1291- (true, true) => hit!(INTER_SB_HORZ4_HITS),
1292- (false, true) => hit!(INTER_SB_VERT4_HITS),
1293- }
12941207 }
12951208 continue;
12961209 }
12971210 if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part64) {
1298- // lane-sbab r1: the four superblock-level AB arms on the
1299- // INTER path -- two 32x32 inter squares plus one true
1300- // 64x32/32x64 inter strip, in libaom `decode_partition`'s own
1301- // order (decodeframe.c: HORZ_A = TL, TR, bottom strip;
1302- // HORZ_B = top strip, BL, BR; VERT_A = TL, BL, right strip;
1303- // VERT_B = left strip, TR, BR). Every piece is one this
1304- // decoder already proves elsewhere: the 32x32 square is the
1305- // `PARTITION_NONE`-under-SPLIT block below, the strip is the
1306- // `PARTITION_HORZ`/`VERT` piece above (`inter_piece!`, which
1307- // keeps `side = SB` for syntax/CDF and names its true
1308- // footprint through `write_w`/`write_h`). The intra-frame
1309- // twin of this arm is lane-part32 r4's `SB_AB_HITS` block.
1310- hit_do! {
1311- SB_AB_INTER_HITS.with(|c| {
1312- let mut h = c.get();
1313- h[part64 - PARTITION_HORZ_A] += 1;
1314- c.set(h);
1315- });
1316- }
13171211 // lane-part32 r5 / class visit-order-changes-availability:
13181212 // only the two VERTICAL arms visit TL, BL, TR, BR, so only
13191213 // they switch libaom's `has_tr`/`has_bl` tables.
@@ -1442,14 +1336,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
14421336 has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows),
14431337 );
14441338 let part32 = if has_cols32 && has_rows32 {
1445- if crate::envflags::env_flag!("EC_AV1_TRACE") {
1446- eprintln!(
1447- "TRACE part32_pre mi=({},{}) rng={}",
1448- r32 * BLOCK_MI,
1449- c32 * BLOCK_MI,
1450- dec.debug_state().0
1451- );
1452- }
14531339 // lane-av1tilerows: this rung printed the RAW 32-grid
14541340 // index (`r32`, `c32`) into its `mi_row=`/`mi_col=`
14551341 // fields — a factor of `BLOCK_MI` (8) off — while the
@@ -1460,23 +1346,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
14601346 // against libaom's per-level `EC_PART_VAL` dump, which
14611347 // is the only way to locate a partition-walk
14621348 // divergence. Behaviour-free: env-gated print only.
1463- if crate::envflags::env_flag!("EC_TRACE_PART") {
1464- eprintln!(
1465- "EC_PART mi_row={} mi_col={} bsize=9 ctx={} rng={}",
1466- r32 * BLOCK_MI,
1467- c32 * BLOCK_MI,
1468- ctx32,
1469- dec.debug_state().0
1470- );
1471- }
14721349 let p = dec.symbol(&mut cdfs.partition_w32[ctx32]);
1473- if crate::envflags::env_flag!("EC_AV1_TRACE") {
1474- eprintln!(
1475- "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p}",
1476- r32 * BLOCK_MI,
1477- c32 * BLOCK_MI
1478- );
1479- }
14801350 p
14811351 } else {
14821352 match (has_cols32, has_rows32) {
@@ -1484,21 +1354,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
14841354 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
14851355 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
14861356 // (libaom `ec_read_partition_impl`).
1487- if crate::envflags::env_flag!("EC_TRACE_PART") {
1488- eprintln!(
1489- "EC_PARTG mi_row={} mi_col={} bsize=9 ctx={} rng={}",
1490- r32 as usize * BLOCK_MI as usize,
1491- c32 as usize * BLOCK_MI as usize,
1492- ctx32,
1493- dec.debug_state().0
1494- );
1495- }
14961357 if {
14971358 let b = dec.symbol_fixed(&gather(
14981359 &cdfs.partition_w32[ctx32],
14991360 VERT_ALIKE,
15001361 ));
1501- bump_edge32(b.min(1));
15021362 b
15031363 } == 1
15041364 {
@@ -1516,7 +1376,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
15161376 &cdfs.partition_w32[ctx32],
15171377 HORZ_ALIKE,
15181378 ));
1519- bump_edge32(b.min(1));
15201379 b
15211380 } == 1
15221381 {
@@ -1525,10 +1384,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
15251384 PARTITION_VERT
15261385 }
15271386 }
1528- _ => {
1529- bump_edge_both_cut(1);
1530- PARTITION_SPLIT
1531- }
1387+ _ => PARTITION_SPLIT,
15321388 }
15331389 };
15341390 // lane-av1unwritten r5: the partition symbol is RESOLVED (a full CDF read or
@@ -1611,24 +1467,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
16111467 // inter leaves through the very same loop the
16121468 // straddling case has always used.
16131469 let part16 = if has_cols16 && has_rows16 {
1614- if crate::envflags::env_flag!("EC_TRACE_PART") {
1615- eprintln!(
1616- "EC_PART mi_row={} mi_col={} bsize=6 ctx={} rng={}",
1617- (sr * SUB_MI as usize),
1618- (sc * SUB_MI as usize),
1619- ctx16,
1620- dec.debug_state().0
1621- );
1622- }
16231470 let p = dec.symbol(&mut cdfs.partition_w16[ctx16]);
1624- if crate::envflags::env_flag!("EC_AV1_TRACE") {
1625- let (rng, _) = dec.debug_state();
1626- eprintln!(
1627- "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={p} rng={rng}",
1628- sr as u32 * SUB_MI,
1629- sc as u32 * SUB_MI
1630- );
1631- }
16321471 p
16331472 } else if !has_cols16 && !has_rows16 {
16341473 // lane-edgeboth r1: both axes cut by the true
@@ -1636,22 +1475,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
16361475 // forces PARTITION_SPLIT and reads NO symbol;
16371476 // the leaf loop below already drops the
16381477 // out-of-frame quadrants.
1639- bump_edge_both_cut(0);
16401478 PARTITION_SPLIT
16411479 } else {
16421480 if has_cols16 {
16431481 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
16441482 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
16451483 // (libaom `ec_read_partition_impl`).
1646- if crate::envflags::env_flag!("EC_TRACE_PART") {
1647- eprintln!(
1648- "EC_PARTG mi_row={} mi_col={} bsize=6 ctx={} rng={}",
1649- sr * SUB_MI as usize,
1650- sc * SUB_MI as usize,
1651- ctx16,
1652- dec.debug_state().0
1653- );
1654- }
16551484 if dec.symbol_fixed(&gather(
16561485 &cdfs.partition_w16[ctx16],
16571486 VERT_ALIKE,
@@ -1749,11 +1578,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
17491578 // residual path (`rect_inter_residual_supported`
17501579 // covers 16x8/8x16 since this round).
17511580 let horz = part16 == PARTITION_HORZ;
1752- if horz {
1753- hit!(INTER_LEAF16_HORZ_HITS);
1754- } else {
1755- hit!(INTER_LEAF16_VERT_HITS);
1756- }
17571581 let base_mi = sub16_to_mi(at16);
17581582 let (ww, wh) = if horz { (16, 8) } else { (8, 16) };
17591583 for piece in 0..2 {
@@ -1768,7 +1592,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
17681592 && (piece_mi.0 >= mi_rows as usize
17691593 || piece_mi.1 >= mi_cols as usize)
17701594 {
1771- bump_inter_edge_strip(if horz { 4 } else { 5 });
17721595 break;
17731596 }
17741597 decode_inter_block(
@@ -1861,7 +1684,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
18611684 // block_size_high >= 16, blockd.h) both hold
18621685 // and the leaf/strip decoders' own gates
18631686 // apply unchanged.
1864- bump_ab16_inter(part16 - PARTITION_HORZ_A);
18651687 let _vert_guard = if part16 == PARTITION_VERT_A
18661688 || part16 == PARTITION_VERT_B
18671689 {
@@ -2035,20 +1857,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
20351857 bw,
20361858 bh
20371859 );
2038- if horz {
2039- hit!(INTER16_HORZ4_HITS);
2040- } else {
2041- hit!(INTER16_VERT4_HITS);
2042- }
20431860 }
20441861 } else if part16 != PARTITION_SPLIT {
20451862 return Err(unsupported(
20461863 "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4",
20471864 ));
20481865 } else {
2049- if has_cols16 && has_rows16 {
2050- hit!(INTER_SUB16_SPLIT_HITS);
2051- }
20521866 let (mi_row0, mi_col0) =
20531867 (sr as u32 * SUB_MI, sc as u32 * SUB_MI);
20541868 let leaf_positions: Vec<(u32, u32)> = (0..4)
@@ -2062,13 +1876,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
20621876 // 7.11.3.3's scaled walk. The counter is what
20631877 // proves a gate actually reached a scaled
20641878 // leaf rather than a same-size reference.
2065- if (1..8).any(|rf| {
2066- refpix
2067- .dims(rf)
2068- .is_some_and(|(w, _)| w != frame_width as usize)
2069- }) {
2070- hit!(SCALED_LEAF8_HITS);
2071- }
20721879 let mut prev_leaves: Vec<(
20731880 (usize, usize),
20741881 bool,
@@ -2079,16 +1886,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
20791886 for (mr, mc) in leaf_positions {
20801887 let leaf_mi = (mr as usize, mc as usize);
20811888 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
2082- if crate::envflags::env_flag!("EC_TRACE_PART") {
2083- eprintln!(
2084- "EC_PART mi_row={} mi_col={} bsize=3 ctx={} rng={}",
2085- leaf_mi.0,
2086- leaf_mi.1,
2087- leaf_ctx,
2088- dec.debug_state().0
2089- );
2090- }
2091- let ec_dbg_pre = dec.debug_state().0;
20921889 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
20931890 // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be
20941891 // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize`
@@ -2098,13 +1895,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
20981895 // keep decoding because the helper is exact, not a heuristic. inter-frame 8x8 level.
20991896 refuse_invalid_subsize((8, 8), part8, fctx)?;
21001897
2101- if std::env::var_os("EC_DBG_SUB8").is_some() {
2102- let ec_dbg_post = dec.debug_state().0;
2103- eprintln!(
2104- "EC_DBG b8 mi=({},{}) ctx={leaf_ctx} val={part8} pre={ec_dbg_pre} post={ec_dbg_post}",
2105- leaf_mi.0, leaf_mi.1
2106- );
2107- }
21081898 if part8 == PARTITION_SPLIT {
21091899 // lane-intersub8: four BLOCK_4X4 inter
21101900 // sub-blocks, chroma once per 8x8.
@@ -2138,15 +1928,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
21381928 // lane-av1unwritten r6: arm census -- an
21391929 // 8x8-level VERT selects BLOCK_4X8, which
21401930 // is INVALID at 4:2:2.
2141- note_subsize_arm(
2142- part8,
2143- chroma_plane_block_codable(
2144- partition_subsize_dims((8, 8), part8).0,
2145- partition_subsize_dims((8, 8), part8).1,
2146- ss_x(fctx),
2147- ss_y(fctx),
2148- ),
2149- );
21501931 if part8 == PARTITION_VERT || part8 == PARTITION_HORZ {
21511932 // lane-intersub8 r3/r4/r5: two
21521933 // BLOCK_8X4 (HORZ) / BLOCK_4X8 (VERT)
@@ -2282,19 +2063,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
22822063 }
22832064 }
22842065 PARTITION_HORZ_B => {
2285- // lane-warp r5: PARTITION_HORZ_B = 32x32 top strip +
2286- // 16x16 bottom-left + 16x16 bottom-right. aomenc
2287- // carves static regions into it; the strip is
2288- // decoded as a square 32x32 block: for a `skip`
2289- // block the symbol stream is identical to the true
2290- // 32x16 coding (no residual, no motion_mode/warp
2291- // symbol), and the square stamps it leaves over the
2292- // bottom half (neighbour arrays, skip/lf grids) are
2293- // re-stamped by the C/D leaves right after. The
2294- // mi-granular `left_side_mi` rows of a last-block-in-
2295- // tile strip leak 32-vs-16 only until the per-tile
2296- // `Neighbours::new` reset.
2297- hit!(EXTENDED_PARTITION_HITS);
22982066 let at32 = at;
22992067 decode_inter_block(
23002068 &mut dec,
@@ -2454,13 +2222,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
24542222 }
24552223 }
24562224 PARTITION_HORZ => {
2457- // lane-rect r2: two true 32x16 strips. Both read at
2458- // `side=BLOCK` (CDF/size-class selection stays square,
2459- // matching HORZ_B's accepted corner-cut) but bw4/bh4
2460- // (mvstack.rs, `motion_mode_eligible`) now derive from
2461- // `write_w`/`write_h`'s true 32x16 footprint -- the
2462- // pin's fix (r1's finding).
2463- hit!(RECT_PARTITION_HITS);
24642225 decode_inter_block(
24652226 &mut dec,
24662227 &mut cdfs,
@@ -2508,9 +2269,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
25082269 (frame_width as usize, frame_height as usize),
25092270 fctx,
25102271 )?;
2511- if !has_rows32 {
2512- bump_edge32(2);
2513- }
25142272 // lane-golomb r2: at the frame edge only the first half of the
25152273 // strip is coded (libaom `decode_partition` guards the second
25162274 // with the same has_rows32 test that made this partition non-square).
@@ -2562,14 +2320,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
25622320 (frame_width as usize, frame_height as usize),
25632321 fctx,
25642322 )?;
2565- } else {
2566- bump_inter_edge_strip(2);
25672323 }
25682324 }
25692325 PARTITION_VERT => {
2570- // lane-rect r2: mirror of PARTITION_HORZ above with
2571- // width/height swapped.
2572- hit!(RECT_PARTITION_HITS);
25732326 decode_inter_block(
25742327 &mut dec,
25752328 &mut cdfs,
@@ -2617,9 +2370,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
26172370 (frame_width as usize, frame_height as usize),
26182371 fctx,
26192372 )?;
2620- if !has_cols32 {
2621- bump_edge32(3);
2622- }
26232373 // lane-golomb r2: at the frame edge only the first half of the
26242374 // strip is coded (libaom `decode_partition` guards the second
26252375 // with the same has_cols32 test that made this partition non-square).
@@ -2671,15 +2421,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
26712421 (frame_width as usize, frame_height as usize),
26722422 fctx,
26732423 )?;
2674- } else {
2675- bump_inter_edge_strip(3);
26762424 }
26772425 }
26782426 PARTITION_HORZ_A => {
2679- // lane-partab r1: two 16x16 squares on top + a true
2680- // 32x16 strip below (libaom decode_partition
2681- // PARTITION_HORZ_A: TL, TR, bottom strip).
2682- hit!(PARTAB_HITS);
26832427 decode_inter_block(
26842428 &mut dec,
26852429 &mut cdfs,
@@ -2831,9 +2575,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
28312575 )?;
28322576 }
28332577 PARTITION_VERT_A => {
2834- // lane-partab r1: mirror of PARTITION_HORZ_A with
2835- // width/height swapped (TL, BL, right 16x32 strip).
2836- hit!(PARTAB_HITS);
28372578 let _vert_ab = crate::encode::Reach::vert_ab_partition();
28382579 decode_inter_block(
28392580 &mut dec,
@@ -2986,10 +2727,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
29862727 )?;
29872728 }
29882729 PARTITION_VERT_B => {
2989- // lane-partab r1: true 16x32 strip on the left + two
2990- // 16x16 squares on the right (libaom decode_partition
2991- // PARTITION_VERT_B: left strip, TR, BR).
2992- hit!(PARTAB_HITS);
29932730 let _vert_ab = crate::encode::Reach::vert_ab_partition();
29942731 decode_inter_block(
29952732 &mut dec,
@@ -3177,11 +2914,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
31772914 bw,
31782915 bh
31792916 );
3180- if horz {
3181- hit!(RECT4_32_HORZ_INTER_HITS);
3182- } else {
3183- hit!(RECT4_32_VERT_INTER_HITS);
3184- }
31852917 }
31862918 }
31872919 _ => {
@@ -3228,51 +2960,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
32282960 );
32292961 }
32302962
3231- // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's
3232- // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against
3233- // that isolate whether a decode-order frame's mismatch already exists
3234- // in reconstruction (this dump) vs is introduced by the loop filter
3235- // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
3236- // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.
3237- if crate::envflags::env_flag!("EC_OBMC")
3238- || crate::envflags::env_flag!("EC_TRACE_MODE")
3239- || crate::envflags::env_flag!("EC_PRED")
3240- {
3241- eprintln!(
3242- "EC_PICT idx={}",
3243- PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst)
3244- );
3245- }
3246- dump_stage16(
3247- "EC_AV1_PREFILT_DUMP16",
3248- &y,
3249- &u,
3250- &v,
3251- frame_width as usize,
3252- frame_height as usize,
3253- ss_x(fctx),
3254- ss_y(fctx),
3255- );
3256- census_unwritten(&y, &u, &v);
3257- if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") {
3258- // lane-av1dumploud: loud on a short write (see the key-frame twin
3259- // above -- same file, same shape, same three planes).
3260- let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
3261- let narrow = |p: &PlaneBuf<'_>| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };
3262- crate::dumpio::write_planes(
3263- "EC_AV1_PREFILT_DUMP",
3264- format!("{path}.f{idx}"),
3265- &[&narrow(&y), &narrow(&u), &narrow(&v)],
3266- );
3267- } else {
3268- PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
3269- }
3270- // lane-av1444edge: the inter-frame path's mi-aligned pre-loop-filter
3271- // dump, the rung the key-frame path has always had (see
3272- // `dump_prefilter_wide`). Placed beside the padded `EC_AV1_PREFILT_DUMP`
3273- // above, i.e. before the loop filters run, so the two agree on the point
3274- // in the sequence they sample.
3275- dump_prefilter_wide(&y, &u, &v);
32762963 // lane-av1fwd: the encoder scores ~25 filter candidates against this
32772964 // same coded tile ([`FilterReplay`]). Capture the reconstruction here,
32782965 // before either filter has touched it -- but only on the shape whose
@@ -3314,42 +3001,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
33143001 plane_snapshot(&v, ss_y(fctx) as u32),
33153002 )
33163003 });
3317- // lane-tiny r4: post-deblock / post-CDEF dumps mirroring aomdec's own
3318- // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter
3319- // dump above these bisect WHICH filter stage introduced a mismatch.
3320- dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v);
3321- dump_stage16(
3322- "EC_AV1_POSTDEBLOCK_DUMP16",
3323- &y,
3324- &u,
3325- &v,
3326- frame_width as usize,
3327- frame_height as usize,
3328- ss_x(fctx),
3329- ss_y(fctx),
3330- );
33313004 apply_cdef(
33323005 &mut y,
33333006 &mut u,
33343007 &mut v,
33353008 cdef,
33363009 &neighbours,
3337- (frame_width as usize, frame_height as usize),
33383010 fctx,
33393011 None,
33403012 None,
33413013 );
3342- dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
3343- dump_stage16(
3344- "EC_AV1_POSTCDEF_DUMP16",
3345- &y,
3346- &u,
3347- &v,
3348- frame_width as usize,
3349- frame_height as usize,
3350- ss_x(fctx),
3351- ss_y(fctx),
3352- );
33533014 capture_stages(&y, &u, &v, deblocked.as_ref(), fctx);
33543015 // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called
33553016 // between `av1_cdef_frame` and `av1_loop_restoration_filter_frame`):
crates/ec-av1/src/decode/inter_block.rsmodified+35 -375
@@ -123,8 +123,6 @@ pub(super) fn decode_inter_block(
123123 // Round 27: the per-read trace is the only instrument that reaches the inter
124124 // path (the coefficient rungs stop well before the frame-3 divergence),
125125 // so publish the phase and the block's mi for every read it makes.
126- crate::msac::SymbolDecoder::set_symr_phase("inter");
127- crate::msac::SymbolDecoder::set_symr_mi(at.0 as i64, at.1 as i64);
128126 // lane-inter4 r1: `at` is in MI units (4 px) so a 32-level 1:4 strip can
129127 // name an 8-px offset; `(r, c)` stays the enclosing 16-px cell for the
130128 // few 16-px-granular uses below.
@@ -135,7 +133,6 @@ pub(super) fn decode_inter_block(
135133 // exactly what it read before.
136134 let (rmi, cmi) = at;
137135 let (px, py) = (at.1 * MI, at.0 * MI);
138- census_inter_block_shape(side, write_w, write_h);
139136 // lane-inter16ab r2: a 16x4 / 4x16 inter strip's chroma is the PAIR's
140137 // (8x4 / 4x8 at the even strip's origin) and is coded only by the odd
141138 // strip (`is_chroma_reference`); every other block keeps its own.
@@ -233,30 +230,12 @@ pub(super) fn decode_inter_block(
233230 // bails per PLANE at `block_width < 8 || block_height < 8` -- on the
234231 // block's own dims, never on the square prediction buffer this reader
235232 // allocates.
236- if crate::envflags::env_flag!("EC_MC_TRACE") {
237- eprintln!("EC_IB px={px} py={py} side={side} w={write_w} h={write_h}");
238- }
239233
240- if crate::envflags::env_flag!("EC_AV1_TELL") {
241- eprintln!(
242- "TELL mi_row={} mi_col={} label=block_entry side={side} tell={} range={}",
243- rmi,
244- cmi,
245- dec.debug_bitpos(),
246- dec.debug_state().0
247- );
248- }
249234 let skip_mode_ctx =
250235 usize::from(neighbours.above_skip_mode[cmi]) + usize::from(neighbours.left_skip_mode[rmi]);
251236 // lane-comppin r3: skip_mode desync isolation -- dump ctx + the pre-read
252237 // MSAC tell so it can be diffed against an equivalent hook in libaom's
253238 // own `read_skip_mode`/`av1_get_skip_mode_context`.
254- if crate::envflags::env_flag!("EC_AV1_SKIPMODE_DUMP") {
255- eprintln!(
256- "EC_SKIPMODE r={r} c={c} ctx={skip_mode_ctx} skip_mode_present={skip_mode_present} tell_before={}",
257- dec.debug_bitpos()
258- );
259- }
260239 // spec 5.11.5 `inter_frame_mode_info`: `inter_segment_id(1)` before
261240 // `skip_mode`/`skip`, `inter_segment_id(0)` after them.
262241 let (seg_mi_r, seg_mi_c) = (rmi, cmi);
@@ -270,15 +249,6 @@ pub(super) fn decode_inter_block(
270249 let comp_allowed = write_w.min(write_h) >= 8;
271250 let skip_mode =
272251 skip_mode_present && comp_allowed && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
273- if crate::envflags::env_flag!("EC_AV1_SKIPMODE_DUMP") {
274- eprintln!(
275- "EC_SKIPMODE r={r} c={c} result={skip_mode} tell_after={}",
276- dec.debug_bitpos()
277- );
278- }
279- if skip_mode {
280- hit!(SKIP_MODE_HITS);
281- }
282252
283253 let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]);
284254 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
@@ -303,16 +273,6 @@ pub(super) fn decode_inter_block(
303273 // chunk). An INTRA block at that size inside an inter frame takes the
304274 // intra tail below, which still codes one whole-block chroma unit and one
305275 // `read_tx_size` at 128 -- refuse by name instead of mis-decoding it.
306- if crate::envflags::env_flag!("EC_TRACE_MODE") {
307- eprintln!(
308- "EC_MODE mi_row={} mi_col={} rng={} is_inter={} skip={} side={side}",
309- rmi,
310- cmi,
311- dec.debug_state().0,
312- u8::from(is_inter),
313- u8::from(skip)
314- );
315- }
316276 // lane-warp r5: see `reject_residual` -- a square-block decode of a
317277 // HORZ_B strip is symbol-exact only for `skip` (no residual, no
318278 // motion_mode/warp symbol). lane-intrarect r1 MOVED this gate from just
@@ -332,26 +292,10 @@ pub(super) fn decode_inter_block(
332292 && !rect_inter_residual_supported(write_w, write_h)
333293 && (is_inter || (write_w == side && write_h == side))
334294 {
335- if crate::envflags::env_flag!("EC_RECTRES") {
336- eprintln!(
337- "EC_RECTRES w={write_w} h={write_h} side={side} skip={} is_inter={} mi_row={rmi} mi_col={cmi}",
338- u8::from(skip),
339- u8::from(is_inter)
340- );
341- }
342295 return Err(unsupported(
343296 "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",
344297 ));
345298 }
346- if crate::envflags::env_flag!("EC_AV1_TELL") {
347- eprintln!(
348- "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}",
349- rmi,
350- cmi,
351- dec.debug_bitpos(),
352- dec.debug_state().0
353- );
354- }
355299
356300 let mode_for_tx;
357301 let uv_predict_mode;
@@ -411,12 +355,6 @@ pub(super) fn decode_inter_block(
411355 uni: neighbours.left_ref1[rmi]
412356 .is_some_and(|r1| is_uni_comp_ref(neighbours.left_ref[rmi], r1)),
413357 });
414- if crate::envflags::env_flag!("EC_AV1_COMPIDX_DUMP") {
415- eprintln!(
416- "EC_PRECOMP r={r} c={c} skip_mode={skip_mode} skip={skip} reference_select={reference_select} tell={}",
417- dec.debug_bitpos()
418- );
419- }
420358 let is_compound = skip_mode
421359 || (reference_select
422360 // `is_comp_ref_allowed` (blockd.h:65) gates the
@@ -498,22 +436,6 @@ pub(super) fn decode_inter_block(
498436 ),
499437 fctx,
500438 );
501- if crate::envflags::env_flag!("EC_TRACE_MODE") {
502- eprintln!(
503- "EC_MODE_VAL mi_row={mi_row} mi_col={mi_col} mode={} ref0={ref0} ref1={ref1} mv0=({},{}) stack={} rng={}",
504- compound_mode + 17,
505- mv0.0,
506- mv0.1,
507- comp_stack.entries.len(),
508- dec.debug_state().0
509- );
510- for (i, e) in comp_stack.entries.iter().enumerate() {
511- eprintln!(
512- "EC_STACK mi_row={mi_row} mi_col={mi_col} i={i} this=({},{}) comp=({},{}) w={}",
513- e.mv0.0, e.mv0.1, e.mv1.0, e.mv1.1, e.weight
514- );
515- }
516- }
517439 let is_globalmv = compound_mode == 6; // GLOBAL_GLOBALMV
518440 // be non-TRANSLATION (IDENTITY counts) for the compound block's
519441 // interp-filter read to be suppressed.
@@ -526,9 +448,6 @@ pub(super) fn decode_inter_block(
526448 // `AOMMIN(mi_size_wide, mi_size_high) < 2` before it looks at any
527449 // model, so a 4-px-sided block still reads its interp filter.
528450 let gm_nontrans = gm_nontrans_models && bw4.min(bh4) >= 2;
529- if gm_nontrans_models && !gm_nontrans {
530- hit!(GM_NONTRANS_SMALL_SIDE_HITS);
531- }
532451 // lane-defer8: both slots' pictures are resolved inside the
533452 // prediction closure; the parse only needs their SIZES.
534453 // lane-cwarp r1: `is_global_mv_block` (blockd.h:421-429) is
@@ -551,14 +470,6 @@ pub(super) fn decode_inter_block(
551470 // alone, which counts blocks that are not global-mv blocks at
552471 // all, so its number was an upper bound dressed up as an
553472 // engagement figure.
554- if mi_row < mi_rows as usize / 2 {
555- if is_globalmv {
556- TOP_HALF_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
557- }
558- if is_global_mv0 || is_global_mv1 {
559- TOP_HALF_WARP_HITS.with(|c| c.set(c.get() + 1));
560- }
561- }
562473 // libaom `av1_init_warp_params` + `allow_warp`'s
563474 // `global_warp_allowed` branch, run once per reference for a
564475 // compound block exactly as for a single-ref one (reconinter.c
@@ -595,7 +506,6 @@ pub(super) fn decode_inter_block(
595506 let warp0 = compound_warp(ref0, is_global_mv0).filter(|_| ref_unscaled(ref0));
596507 let warp1 = compound_warp(ref1, is_global_mv1).filter(|_| ref_unscaled(ref1));
597508 if warp0.is_some() || warp1.is_some() {
598- hit!(COMPOUND_WARP_HITS);
599509 // lane-av112bitw: the 12-bit refusal that stood here is
600510 // LIFTED with the compound-warp witness: the rotating-
601511 // mandelbrot 12-bit recipe refused exactly here pre-lift and
@@ -668,17 +578,10 @@ pub(super) fn decode_inter_block(
668578 && enable_masked_compound
669579 && is_any_masked_compound_used_here(write_w, write_h)
670580 {
671- crate::msac::SymbolDecoder::set_symr_cdf("comp_group_idx");
672581 dec.symbol(&mut cdfs.comp_group_idx[group_ctx])
673582 } else {
674583 0
675584 };
676- if crate::envflags::env_flag!("EC_TRACE_MODE") {
677- eprintln!(
678- "EC_CGI mi_row={rmi} mi_col={cmi} ctx={group_ctx} val={comp_group_idx} rng={}",
679- dec.debug_state().0
680- );
681- }
682585 // lane-maskcomp r2 / lane-wedge r3: `Some(mask_type)` for a
683586 // `COMPOUND_DIFFWTD` block, `Some(mask)` (wedge codebook lookup)
684587 // for a `COMPOUND_WEDGE` block -- exactly one of the two is set
@@ -714,16 +617,6 @@ pub(super) fn decode_inter_block(
714617 // verified vs independent C dump (wedge.rs).
715618 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
716619 let wedge_sign = dec.literal(1);
717- hit!(WEDGE_HITS);
718- if let Some(k) = rect_wedge_slot(write_w, write_h) {
719- hit_do! {
720- RECT_WEDGE_HITS.with(|c| {
721- let mut a = c.get();
722- a[k] += 1;
723- c.set(a);
724- });
725- }
726- }
727620 // lane-inter16ab r5: the codebook row is this block's TRUE
728621 // footprint (`av1_wedge_params_lookup[bsize]`: hgtw for
729622 // h>w, hltw for h<w, plus that bsize's own signflip row).
@@ -740,13 +633,6 @@ pub(super) fn decode_inter_block(
740633 // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1.
741634 let mask_type = dec.literal(1);
742635 diffwtd_mask_type = Some(mask_type as u8);
743- if wedge_bsize.is_none() {
744- hit!(DIFFWTD_INFERRED_HITS);
745- }
746- }
747- hit!(MASKED_COMPOUND_HITS);
748- if write_w != write_h {
749- hit!(RECT_MASKED_COMPOUND_HITS);
750636 }
751637 }
752638 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17
@@ -959,21 +845,10 @@ pub(super) fn decode_inter_block(
959845 ref_order_hints[(ref0 - LAST_FRAME) as usize],
960846 ref_order_hints[(ref1 - LAST_FRAME) as usize],
961847 );
962- crate::msac::SymbolDecoder::set_symr_cdf("compound_idx");
963848 let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]);
964- if crate::envflags::env_flag!("EC_TRACE_MODE") {
965- eprintln!(
966- "EC_CIDX mi_row={rmi} mi_col={cmi} ctx={idx_ctx} val={idx} rng={}",
967- dec.debug_state().0
968- );
969- }
970849 if idx == 1 {
971850 (8, 8, 1u8)
972851 } else {
973- // lane-av1distwtd: `idx == 0` is the
974- // distance-weighted arm -- the only branch whose
975- // weights are NOT the constant (8, 8) split.
976- hit!(DIST_WTD_COMP_HITS);
977852 let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign(
978853 order_hint_bits,
979854 order_hint,
@@ -986,16 +861,6 @@ pub(super) fn decode_inter_block(
986861 (8, 8, 1u8)
987862 };
988863 compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx));
989- if crate::envflags::env_flag!("EC_AV1_COMPIDX_DUMP") {
990- eprintln!(
991- "EC_COMPIDX mi_row={mi_row} mi_col={mi_col} bsize={side} mode={compound_mode} mv0=({},{}) mv1=({},{}) ref0={ref0} ref1={ref1} comp_group_idx={comp_group_idx} compound_idx={compound_idx} tell={}",
992- mv0.0,
993- mv0.1,
994- mv1.0,
995- mv1.1,
996- dec.debug_bitpos()
997- );
998- }
999864
1000865 // spec 5.11.19/libaom `decodemv.c` 1575: `read_mb_interp_filter`
1001866 // comes AFTER `read_compound_type` (the `comp_group_idx`/
@@ -1028,15 +893,9 @@ pub(super) fn decode_inter_block(
1028893 // stride-1 one, so the unscaled case is unchanged.
1029894 let scale0 = scale_of(ref_dims(ref0, refpix)?, frame_size);
1030895 let scale1 = scale_of(ref_dims(ref1, refpix)?, frame_size);
1031- if !scale0.is_unscaled() || !scale1.is_unscaled() {
1032- hit!(SCALED_COMPOUND_HITS);
1033- }
1034896 // lane-scaledref r2: the MIXED case -- one tap scaled, the other
1035897 // not -- is the one an all-frames-scaled recipe never produces,
1036898 // and the one a single shared scale factor would get wrong.
1037- if (scale0.is_unscaled()) != (scale1.is_unscaled()) {
1038- hit!(MIXED_SCALE_COMPOUND_HITS);
1039- }
1040899
1041900 // lane-wave4 (the compound arm's half): this block's whole
1042901 // prediction -- both references, the wedge/diffwtd/distance
@@ -1148,7 +1007,6 @@ pub(super) fn decode_inter_block(
11481007 // either way, only the mask source differs.
11491008 let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type {
11501009 diffwtd_mask_y = vec![0u8; side * side];
1151- hit!(DIFFWTD_HITS);
11521010 mc::diffwtd_mask(
11531011 &inter0_y,
11541012 &inter1_y,
@@ -1415,7 +1273,23 @@ pub(super) fn decode_inter_block(
14151273 let (pred_y, pred_u, pred_v): (Vec<u16>, Vec<u16>, Vec<u16>);
14161274 let (sy, su, sv) = if pred_deferred(refpix) {
14171275 push_pred(build);
1418- (Pred::Cur { plane: 0, stride: side, off: 0 }, Pred::Cur { plane: 1, stride: chroma_stride, off: 0 }, Pred::Cur { plane: 2, stride: chroma_stride, off: 0 })
1276+ (
1277+ Pred::Cur {
1278+ plane: 0,
1279+ stride: side,
1280+ off: 0,
1281+ },
1282+ Pred::Cur {
1283+ plane: 1,
1284+ stride: chroma_stride,
1285+ off: 0,
1286+ },
1287+ Pred::Cur {
1288+ plane: 2,
1289+ stride: chroma_stride,
1290+ off: 0,
1291+ },
1292+ )
14191293 } else {
14201294 let mut built: [Vec<u16>; 3] = Default::default();
14211295 build(y, u, v, refpix, fctx, &mut built);
@@ -1597,14 +1471,6 @@ pub(super) fn decode_inter_block(
15971471 fctx,
15981472 )?
15991473 } else {
1600- // lane-r14 r3: a 1:4 strip's `sub_tx_size_map`
1601- // sub-transform is RECTANGULAR (TX_64X16 ->
1602- // TX_32X16, TX_16X64 -> TX_16X32), so this leaf is
1603- // read with the rect coefficient machinery, at its
1604- // own `txb_skip_ctx`/neighbour spans -- the unit is
1605- // smaller than its block, so `get_txb_ctx_general`'s
1606- // neighbour table applies, not the lone-TU 0.
1607- vartx_rect_leaf_hit(tw, th);
16081474 let tu_skip_ctx =
16091475 neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI);
16101476 let start = row * MI * side + col * MI;
@@ -1852,7 +1718,6 @@ pub(super) fn decode_inter_block(
18521718 plane_idx,
18531719 &cu_grid,
18541720 );
1855- hit!(CHROMA_SPLIT_TX_HITS);
18561721 mu_chroma = true;
18571722 // lane-av1muchunk422b: the allocation of this
18581723 // mu-chunk walk, counted per TX_32X32 UNIT.
@@ -1861,9 +1726,6 @@ pub(super) fn decode_inter_block(
18611726 // bump: `MU_CHUNK_COMPOUND_UNITS` names site 2
18621727 // and the single-reference twin (site 5) stays
18631728 // out of it.
1864- if is_compound {
1865- hit!(MU_CHUNK_COMPOUND_UNITS);
1866- }
18671729 let dst = mu_units(
18681730 if plane_idx == 1 {
18691731 &mut u_units
@@ -2068,12 +1930,6 @@ pub(super) fn decode_inter_block(
20681930 let cu_rel_mi = (cr * (cu_tx / MI), cc * (cu_tx / MI));
20691931 let cu_tx_type = covering_leaf_tx_type(&leaf_tx_types, cu_rel_mi)
20701932 .unwrap_or(luma_tx_type);
2071- if covering_leaf_tx_type(&leaf_tx_types, cu_rel_mi).is_some() {
2072- hit!(CHROMA_QUAD_LEAF_TX_HITS);
2073- if cu_tx_type != luma_tx_type {
2074- hit!(CHROMA_QUAD_LEAF_TX_DIFF_HITS);
2075- }
2076- }
20771933 let cu_grid = read_inter_plane(
20781934 dec,
20791935 cdfs,
@@ -2099,7 +1955,6 @@ pub(super) fn decode_inter_block(
20991955 // this one's coefficients.
21001956 neighbours
21011957 .record_mi_chroma(cu_mi, cu_tx, cu_tx, plane_idx, &cu_grid);
2102- hit!(CHROMA_SPLIT_TX_HITS);
21031958 // lane-av1-444 c8: the unit's levels must ALSO
21041959 // land in the block grid -- the block-tail mu
21051960 // re-stamp slices the per-unit states back out
@@ -2177,14 +2032,6 @@ pub(super) fn decode_inter_block(
21772032 neighbours.left_ref1[rmi],
21782033 );
21792034 ref_frame_for_lf = ref_frame;
2180- if crate::envflags::env_flag!("EC_AV1_TELL") {
2181- let (mi_row, mi_col) = (rmi, cmi);
2182- eprintln!(
2183- "TELL mi_row={mi_row} mi_col={mi_col} label=post_ref_frame ref={ref_frame} tell={} range={}",
2184- dec.debug_bitpos(),
2185- dec.debug_state().0
2186- );
2187- }
21882035 // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own
21892036 // stacked defects (lf_level ref/mode-delta forwarding, the
21902037 // switchable_interp ref-frame ctx gate, and a film-grain synthesis
@@ -2245,14 +2092,10 @@ pub(super) fn decode_inter_block(
22452092 tpl,
22462093 );
22472094 let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
2248- if !not_new {
2249- crate::census::mode(0);
2250- }
22512095 let mut is_globalmv = false;
22522096 // lane-interbis r1: which single-ref mode this block resolved to,
22532097 // in the oracle's own numbering (NEARESTMV=13 .. NEWMV=16), for
22542098 // the `EC_MODE_VAL` value ladder below.
2255- let mut dbg_mode = 16u32;
22562099 let (mv, is_new_mv) = if !not_new {
22572100 // NEWMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting at 0):
22582101 // read at most two `drl_mode` bits, one per stack entry past the
@@ -2282,19 +2125,13 @@ pub(super) fn decode_inter_block(
22822125 )
22832126 } else {
22842127 let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;
2285- if !not_zero {
2286- crate::census::mode(1);
2287- }
22882128 is_globalmv = !not_zero;
22892129 let mv = if !not_zero {
22902130 // GLOBALMV: `gm_get_motion_vector` (spec 7.10.2.1), already
22912131 // computed at this block's own position in `gm_table`.
2292- dbg_mode = 15;
22932132 gm_table[(ref_frame - LAST_FRAME) as usize]
22942133 } else {
22952134 let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
2296- crate::census::mode(if nearest { 2 } else { 3 });
2297- dbg_mode = if nearest { 13 } else { 14 };
22982135 if nearest {
22992136 stack.nearest_mv
23002137 } else {
@@ -2316,26 +2153,6 @@ pub(super) fn decode_inter_block(
23162153 };
23172154 (mv, false)
23182155 };
2319- if crate::msac::symtrace::dir().is_some() {
2320- crate::msac::symtrace::note(&format!(
2321- " MODE mi=({mi_row},{mi_col}) dbg={dbg_mode} mv={mv:?}"
2322- ));
2323- }
2324- if crate::envflags::env_flag!("EC_TRACE_MODE") {
2325- for (i, e) in stack.entries.iter().enumerate() {
2326- eprintln!(
2327- "EC_STACK mi_row={mi_row} mi_col={mi_col} ref={ref_frame} i={i} this=({},{}) comp=(0,0) w={}",
2328- e.mv.0, e.mv.1, e.weight
2329- );
2330- }
2331- eprintln!(
2332- "EC_MODE_VAL mi_row={mi_row} mi_col={mi_col} mode={dbg_mode} ref0={ref_frame} ref1=-1 mv0=({},{}) stack={} rng={}",
2333- mv.0,
2334- mv.1,
2335- stack.entries.len(),
2336- dec.debug_state().0
2337- );
2338- }
23392156 // lane-gm r2: the two libaom predicates single-ref GLOBALMV
23402157 // blocks need -- `is_global_mv_block` (blockd.h:421-429, mode
23412158 // GLOBAL* AND model > TRANSLATION AND min(bw,bh) >= 8px, gating
@@ -2348,13 +2165,6 @@ pub(super) fn decode_inter_block(
23482165 let is_global_mv_block = is_globalmv && gm_model as u8 > 1 && min_bw_bh4 >= 2;
23492166 let gm_nontrans =
23502167 is_globalmv && gm_model != ec_av1_syntax::WarpModel::Translation && min_bw_bh4 >= 2;
2351- if crate::envflags::env_flag!("EC_AV1_TELL") {
2352- eprintln!(
2353- "TELL mi_row={mi_row} mi_col={mi_col} label=post_assign_mv tell={} range={}",
2354- dec.debug_bitpos(),
2355- dec.debug_state().0
2356- );
2357- }
23582168 // lane-sb128 r4: `interintra` (spec 5.11.24; libaom
23592169 // `decodemv.c` read_inter_block_mode_info ~1490-1510), placed
23602170 // right after `assign_mv` and before `read_motion_mode` below --
@@ -2384,7 +2194,6 @@ pub(super) fn decode_inter_block(
23842194 // TRUE footprint -- a 16x8 strip is group 1, a 32x16 strip
23852195 // group 2, not their square `side`'s 2/3.
23862196 let bsize_group = size_group_wh(write_w, write_h);
2387- crate::msac::SymbolDecoder::set_symr_cdf("interintra");
23882197 let interintra = dec.symbol(&mut cdfs.interintra[bsize_group]) == 1;
23892198 if interintra {
23902199 // lane-interintra r1 (decodemv.c 1540-1555): interintra_mode,
@@ -2406,16 +2215,6 @@ pub(super) fn decode_inter_block(
24062215 // NO sign symbol follows -- libaom fixes
24072216 // INTERINTRA_WEDGE_SIGN 0 (blockd.h).
24082217 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
2409- hit!(WII_HITS);
2410- if let Some(k) = rect_wedge_slot(write_w, write_h) {
2411- hit_do! {
2412- RECT_WII_HITS.with(|c| {
2413- let mut a = c.get();
2414- a[k] += 1;
2415- c.set(a);
2416- });
2417- }
2418- }
24192218 // lane-inter16ab r5: true-footprint codebook row,
24202219 // mask padded to stride `max(bw,bh) == side` -- see
24212220 // the compound site's own comment.
@@ -2425,8 +2224,6 @@ pub(super) fn decode_inter_block(
24252224 .mask(0, wedge_index),
24262225 side,
24272226 ));
2428- } else {
2429- hit!(INTERINTRA_HITS);
24302227 }
24312228 interintra_mode = Some(ii);
24322229 // The inter-intra predictor reads this block's neighbours as already
@@ -2434,13 +2231,6 @@ pub(super) fn decode_inter_block(
24342231 super::wave::finish_tile(fctx, refpix, [&mut *y, &mut *u, &mut *v]);
24352232 }
24362233 }
2437- if crate::envflags::env_flag!("EC_AV1_TELL") {
2438- eprintln!(
2439- "TELL mi_row={mi_row} mi_col={mi_col} label=post_interintra tell={} range={}",
2440- dec.debug_bitpos(),
2441- dec.debug_state().0
2442- );
2443- }
24442234 // lane-motionmode round 1: `read_motion_mode` (spec 5.11.24;
24452235 // libaom `decodemv.c` read_inter_block_mode_info, ~1520-1528),
24462236 // placed right after MV assignment and before the switchable
@@ -2483,20 +2273,6 @@ pub(super) fn decode_inter_block(
24832273 // as aomdec's `EC_ISTEP2 name=motion_mode` -- an eligibility
24842274 // mismatch is otherwise invisible (a skipped symbol prints
24852275 // nothing).
2486- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
2487- eprintln!(
2488- "EC_MM mi_row={mi_row} mi_col={mi_col} w={write_w} h={write_h} elig={} \
2489- ab={} lf={} sw={} skipmode={} ii={} gmb={} rng={}",
2490- motion_mode_eligible as u8,
2491- overlappable_above(grid, mi_row, mi_col, bw4, mi_cols as usize, 1).len(),
2492- overlappable_left(grid, mi_row, mi_col, bh4, mi_rows as usize, 1).len(),
2493- switchable_motion_mode as u8,
2494- skip_mode as u8,
2495- interintra_mode.is_some() as u8,
2496- is_global_mv_block as u8,
2497- dec.debug_state().0,
2498- );
2499- }
25002276 let mut obmc_selected = false;
25012277 // lane-warp round 2: `Some` when motion_mode == WARPED_CAUSAL
25022278 // *and* the local warp estimate is valid (`!wm_params.invalid`,
@@ -2564,24 +2340,15 @@ pub(super) fn decode_inter_block(
25642340 ) >= 1;
25652341 let warp_eligible =
25662342 allow_warped_motion && !ref_is_scaled && !force_integer_mv && proj_ok;
2567- if allow_warped_motion && proj_ok && ref_is_scaled {
2568- hit!(SCALED_WARP_SUPPRESSED_HITS);
2569- }
2570- if allow_warped_motion && proj_ok && !ref_is_scaled && force_integer_mv {
2571- hit!(FIMV_ALPHABET_HITS);
2572- }
25732343 if warp_eligible {
2574- crate::msac::SymbolDecoder::set_symr_cdf("motion_mode");
25752344 let mode = dec.symbol(&mut cdfs.motion_mode[bsize_idx]);
25762345 match mode {
25772346 0 => {}
25782347 1 => {
25792348 obmc_selected = true;
2580- hit!(OBMC_HITS);
25812349 }
25822350 _ => {
25832351 warped_selected = true;
2584- hit!(WARP_SELECTED_HITS);
25852352 let mut samples = find_samples(
25862353 grid,
25872354 mi_row,
@@ -2593,18 +2360,6 @@ pub(super) fn decode_inter_block(
25932360 ref_frame,
25942361 fctx,
25952362 );
2596- if crate::envflags::env_flag!("EC_WARP_DEBUG") {
2597- eprintln!(
2598- "EC_WARP_DEBUG findSamples mi_row={mi_row} mi_col={mi_col} bsize={side} num_proj_ref={}",
2599- samples.len()
2600- );
2601- for (i, s) in samples.iter().enumerate() {
2602- eprintln!(
2603- "EC_WARP_DEBUG sample[{i}] pts={:?} pts_inref={:?}",
2604- s.pts1, s.pts2
2605- );
2606- }
2607- }
26082363 if samples.len() > 1 {
26092364 crate::warp::select_samples(
26102365 mv,
@@ -2625,45 +2380,15 @@ pub(super) fn decode_inter_block(
26252380 mi_row as i32,
26262381 mi_col as i32,
26272382 );
2628- if crate::envflags::env_flag!("EC_WARP_DEBUG") {
2629- eprintln!(
2630- "EC_WARP_DEBUG projection mi_row={mi_row} mi_col={mi_col} num_proj_ref(final)={} mv=({},{}) params={:?}",
2631- samples.len(),
2632- mv.0,
2633- mv.1,
2634- warp_params
2635- );
2636- for (i, s) in samples.iter().enumerate() {
2637- eprintln!(
2638- "EC_WARP_DEBUG sample_used[{i}] pts={:?} pts_inref={:?}",
2639- s.pts1, s.pts2
2640- );
2641- }
2642- }
26432383 }
26442384 }
26452385 } else {
26462386 obmc_selected = dec.symbol(&mut cdfs.obmc[bsize_idx]) == 1;
2647- if obmc_selected {
2648- hit!(OBMC_HITS);
2649- }
26502387 }
26512388 // lane-t900 r9: which ALPHABET this block read (3-symbol
26522389 // motion_mode vs 2-symbol obmc) and the range after -- the
26532390 // two give the same value with a different narrowing (class
26542391 // wrong-alphabet-same-value).
2655- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
2656- eprintln!(
2657- "EC_MM2 mi_row={mi_row} mi_col={mi_col} row={bsize_idx} warp_elig={} \
2658- scaled={} fimv={} obmc={} warped={} rng={}",
2659- warp_eligible as u8,
2660- ref_is_scaled as u8,
2661- force_integer_mv as u8,
2662- obmc_selected as u8,
2663- warped_selected as u8,
2664- dec.debug_state().0,
2665- );
2666- }
26672392 }
26682393 // lane-gm r4: `allow_warp`'s `global_warp_allowed` branch
26692394 // (`reconinter.c:33-55`), gated INDEPENDENTLY of `motion_mode` --
@@ -2684,15 +2409,9 @@ pub(super) fn decode_inter_block(
26842409 let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize];
26852410 if warp_params.is_none() && is_global_mv_block && !force_integer_mv && !gm_ref.invalid {
26862411 warp_params = crate::warp::global_warp_params(gm_ref.params);
2687- if warp_params.is_some() && gm_ref.model == ec_av1_syntax::WarpModel::Affine {
2688- hit!(AFFINE_GM_HITS);
2689- }
26902412 // lane-av1gwarp12: the ROTZOOM sibling -- the only
26912413 // >TRANSLATION model vanilla aomenc can emit for a single-ref
26922414 // global-motion block (encoder search pinned to ROTZOOM).
2693- if warp_params.is_some() && gm_ref.model == ec_av1_syntax::WarpModel::Rotzoom {
2694- hit!(ROTZOOM_GM_WARP_HITS);
2695- }
26962415 }
26972416 // lane-av112bitw: a local `WARPED_CAUSAL` projection (set above)
26982417 // or a global warp model both land here with `warp_params` set --
@@ -2701,14 +2420,6 @@ pub(super) fn decode_inter_block(
27012420 // (`warp::warp_round_0`, 5 at 12 bits) and the six-frame 12-bit
27022421 // warp stream decodes byte-exact vs ffmpeg
27032422 // (`a_12bit_warped_motion_stream_decodes_pixel_exact`).
2704- if crate::envflags::env_flag!("EC_AV1_TELL") {
2705- eprintln!(
2706- "TELL mi_row={mi_row} mi_col={mi_col} label=post_motion_mode eligible={} tell={} range={}",
2707- motion_mode_eligible as u8,
2708- dec.debug_bitpos(),
2709- dec.debug_state().0
2710- );
2711- }
27122423 // spec `get_ref_filter_type`: a neighbour's own filter only feeds
27132424 // this block's switchable_interp context when that neighbour coded
27142425 // the SAME reference frame this block is about to read -- a
@@ -2746,26 +2457,6 @@ pub(super) fn decode_inter_block(
27462457 );
27472458 block_filter = resolved_filter;
27482459 globalmv_for_lf = is_globalmv;
2749- if crate::envflags::env_flag!("EC_AV1_TELL") {
2750- eprintln!(
2751- "TELL mi_row={mi_row} mi_col={mi_col} label=post_interp_filter tell={} range={}",
2752- dec.debug_bitpos(),
2753- dec.debug_state().0
2754- );
2755- }
2756- if crate::envflags::env_flag!("EC_AV1_TRACE") {
2757- eprintln!(
2758- "EC_TRACE mi_row={mi_row} mi_col={mi_col} skip={} is_inter=1 mv=({},{}) is_new_mv={is_new_mv} bsize={side} ref={ref_frame} filter={:?} motion_mode_eligible={} obmc_selected={} warped={} tell={}",
2759- skip as u8,
2760- mv.0,
2761- mv.1,
2762- block_filter,
2763- motion_mode_eligible as u8,
2764- obmc_selected as u8,
2765- warp_params.is_some() as u8,
2766- dec.debug_bitpos()
2767- );
2768- }
27692460 // lane-rect r2: see the compound path's matching comment above --
27702461 // `grid` must be stamped with the block's true bh4/bw4 span, not
27712462 // a square `bw4`x`bw4` guess.
@@ -2818,15 +2509,6 @@ pub(super) fn decode_inter_block(
28182509 // measured was the 16x4/4x16 strip's sub-8x8 chroma piece,
28192510 // which this file used to SKIP under a scaled reference
28202511 // (fixed in the same commit), not the warp fallback.
2821- if warp_params.is_some() {
2822- hit!(SCALED_WARP_FALLBACK_HITS);
2823- }
2824- if obmc_selected {
2825- hit!(SCALED_OBMC_HITS);
2826- }
2827- if interintra_mode.is_some() {
2828- hit!(SCALED_INTERINTRA_HITS);
2829- }
28302512 }
28312513
28322514 // lane-inter16ab r2: `is_sub8x8_inter`'s neighbour walk reads the
@@ -2843,7 +2525,6 @@ pub(super) fn decode_inter_block(
28432525 {
28442526 Some((horz, (prev_ref, prev_mv, prev_h, prev_v))) => {
28452527 let prev_dims = ref_dims(prev_ref, refpix)?;
2846- hit!(INTER16_SUB8_PIECE_HITS);
28472528 Some((
28482529 horz,
28492530 prev_ref,
@@ -3083,9 +2764,6 @@ pub(super) fn decode_inter_block(
30832764 // result, all planes (reconinter.c av1_build_interintra_predictor
30842765 // plane loop).
30852766 if let Some(ii) = interintra_mode {
3086- if write_w != write_h {
3087- hit!(INTERINTRA_RECT_HITS);
3088- }
30892767 interintra_blend(
30902768 y,
30912769 px,
@@ -3186,7 +2864,23 @@ pub(super) fn decode_inter_block(
31862864 let (pred_y, pred_u, pred_v): (Vec<u16>, Vec<u16>, Vec<u16>);
31872865 let (sy, su, sv) = if pred_deferred(refpix) {
31882866 push_pred(build);
3189- (Pred::Cur { plane: 0, stride: side, off: 0 }, Pred::Cur { plane: 1, stride: chroma_stride, off: 0 }, Pred::Cur { plane: 2, stride: chroma_stride, off: 0 })
2867+ (
2868+ Pred::Cur {
2869+ plane: 0,
2870+ stride: side,
2871+ off: 0,
2872+ },
2873+ Pred::Cur {
2874+ plane: 1,
2875+ stride: chroma_stride,
2876+ off: 0,
2877+ },
2878+ Pred::Cur {
2879+ plane: 2,
2880+ stride: chroma_stride,
2881+ off: 0,
2882+ },
2883+ )
31902884 } else {
31912885 let mut built: [Vec<u16>; 3] = Default::default();
31922886 build(y, u, v, refpix, fctx, &mut built);
@@ -3351,10 +3045,7 @@ pub(super) fn decode_inter_block(
33513045 // extent is the strip's own. Counted so a 4:4:4 1:4-strip
33523046 // gate can prove it exercised this route (a 4:2:0 stream
33533047 // of the same content reads 0).
3354- Some(_) if ss_x(fctx) == 0 => {
3355- hit!(RECT4_INTER_OWN_CHROMA444_HITS);
3356- around
3357- }
3048+ Some(_) if ss_x(fctx) == 0 => around,
33583049 Some(s) if s.has_chroma => {
33593050 let (pw, ph) = if s.horz {
33603051 if ss_y(fctx) == 0 { (16, 4) } else { (16, 8) }
@@ -3433,14 +3124,6 @@ pub(super) fn decode_inter_block(
34333124 fctx,
34343125 )?
34353126 } else {
3436- // lane-r14 r3: a 1:4 strip's `sub_tx_size_map`
3437- // sub-transform is RECTANGULAR (TX_64X16 ->
3438- // TX_32X16, TX_16X64 -> TX_16X32), so this leaf is
3439- // read with the rect coefficient machinery, at its
3440- // own `txb_skip_ctx`/neighbour spans -- the unit is
3441- // smaller than its block, so `get_txb_ctx_general`'s
3442- // neighbour table applies, not the lone-TU 0.
3443- vartx_rect_leaf_hit(tw, th);
34443127 let tu_skip_ctx =
34453128 neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI);
34463129 let start = row * MI * side + col * MI;
@@ -3674,7 +3357,6 @@ pub(super) fn decode_inter_block(
36743357 plane_idx,
36753358 &cu_grid,
36763359 );
3677- hit!(CHROMA_SPLIT_TX_HITS);
36783360 mu_chroma = true;
36793361 // lane-av1muchunk422b: the allocation of this
36803362 // mu-chunk walk, counted per TX_32X32 UNIT.
@@ -3683,9 +3365,6 @@ pub(super) fn decode_inter_block(
36833365 // bump: `MU_CHUNK_COMPOUND_UNITS` names site 2
36843366 // and the single-reference twin (site 5) stays
36853367 // out of it.
3686- if is_compound {
3687- hit!(MU_CHUNK_COMPOUND_UNITS);
3688- }
36893368 let dst = mu_units(
36903369 if plane_idx == 1 {
36913370 &mut u_units
@@ -3906,16 +3585,10 @@ pub(super) fn decode_inter_block(
39063585 let cu_tx_type = covering_leaf_tx_type(&leaf_tx_types, cu_rel_mi)
39073586 .unwrap_or(luma_tx_type);
39083587 if covering_leaf_tx_type(&leaf_tx_types, cu_rel_mi).is_some() {
3909- hit!(CHROMA_QUAD_LEAF_TX_HITS);
3910- hit!(CHROMA_QUAD_LEAF_TX_SINGLEREF_HITS);
39113588 // lane-av1f9singleland: this arm's own
39123589 // non-vacuity number -- the shared
39133590 // DIFFERS counter below cannot say which
39143591 // arm changed an answer.
3915- if cu_tx_type != luma_tx_type {
3916- hit!(CHROMA_QUAD_LEAF_TX_DIFF_HITS);
3917- hit!(CHROMA_QUAD_LEAF_TX_SINGLEREF_DIFF_HITS);
3918- }
39193592 }
39203593 let cu_grid = read_inter_plane(
39213594 dec,
@@ -3942,7 +3615,6 @@ pub(super) fn decode_inter_block(
39423615 // this one's coefficients.
39433616 neighbours
39443617 .record_mi_chroma(cu_mi, cu_tx, cu_tx, plane_idx, &cu_grid);
3945- hit!(CHROMA_SPLIT_TX_HITS);
39463618 // lane-av1-444 c8: the unit's levels must ALSO
39473619 // land in the block grid -- the block-tail mu
39483620 // re-stamp slices the per-unit states back out
@@ -4075,15 +3747,6 @@ pub(super) fn decode_inter_block(
40753747 // equivalent post-content point (added at the matching call site)
40763748 // narrows the ladder to this block's own tail instead of the next
40773749 // block's partition read.
4078- if crate::envflags::env_flag!("EC_AV1_TELL") {
4079- eprintln!(
4080- "TELL mi_row={} mi_col={} label=block_end tell={} range={}",
4081- rmi,
4082- cmi,
4083- dec.debug_bitpos(),
4084- dec.debug_state().0
4085- );
4086- }
40873750 // lane-inter16ab r2: the pair's chroma coefficient context spans BOTH
40883751 // strips (mirroring the intra `decode_rect4_16` path), and the even
40893752 // strip's own record wrote empty chroma state over those cells -- this
@@ -4250,7 +3913,6 @@ pub(super) fn decode_inter_block(
42503913 palette_record.3,
42513914 );
42523915 let saved_chroma_ctx = (!has_chroma).then(|| {
4253- hit!(NON_CHROMA_REF_CTX_SKIP_HITS);
42543916 let (w_mi, h_mi) = (write_w / MI, write_h / MI);
42553917 let left: Vec<[Neighbour; 2]> = (0..h_mi)
42563918 .filter_map(|k| neighbours.left.get(at.0 + k).map(|s| [s[1], s[2]]))
@@ -4277,7 +3939,6 @@ pub(super) fn decode_inter_block(
42773939 // where aomdec reads 1, because the skipped 128x128 block at
42783940 // mi(32,32) never cleared `left[32..48]`.
42793941 if skip {
4280- hit!(SKIP_VARTX_LUMA_RESET_HITS);
42813942 neighbours.record_mi_luma_rect(at, write_w, write_h, &luma_grid);
42823943 }
42833944 // Plane 0 is already correct per transform unit
@@ -4374,7 +4035,6 @@ pub(super) fn decode_inter_block(
43744035 }
43754036 }
43764037 neighbours.record_uv_mode_mi(s.pair_mi.0, s.pair_mi.1, pw / MI, ph / MI, uv_predict_mode);
4377- hit!(INTER16_CHROMA_PAIR_HITS);
43784038 }
43794039 // lane-av1-444 c8: each unit stamps its OWN span (32 << ss px at
43804040 // TX_32X32, 8 px lossless) -- a 64x64 mu chunk at ss 0/0 holds four
crates/ec-av1/src/decode/inter_block8.rsmodified+34 -273
@@ -160,8 +160,6 @@ pub(super) fn decode_inter_block8(
160160 // entry sets the same label from ITS `at`, which is a different block --
161161 // publishing from here is what makes the EC_SYMR mi trustworthy on the
162162 // inter path, which is what round 22 got wrong by assuming it was not.
163- crate::msac::SymbolDecoder::set_symr_phase("inter8");
164- crate::msac::SymbolDecoder::set_symr_mi(leaf_mi.0 as i64, leaf_mi.1 as i64);
165163 const LAST_FRAME: i8 = 1;
166164 // lane-gmaffine r2: the leaf's OWN switchable-filter symbols, handed back
167165 // so the caller stamps them into `Neighbours` instead of the `[3, 3]`
@@ -243,9 +241,6 @@ pub(super) fn decode_inter_block8(
243241 // leaf is always `BLOCK_8X8`, i.e. 2x2 mi.
244242 inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, false, true, fctx);
245243 let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
246- if skip_mode {
247- hit!(SKIP_MODE_HITS);
248- }
249244
250245 let skip_ctx = usize::from(above_skip) + usize::from(left_skip);
251246 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
@@ -264,14 +259,6 @@ pub(super) fn decode_inter_block8(
264259 // lane-inter8 r1: mirrors the oracle's `EC_MODE` (instrument rung 4,
265260 // `read_inter_block_mode_info`) so an 8x8 leaf's mode-info range ladder
266261 // diffs line for line against a real aomdec.
267- if crate::envflags::env_flag!("EC_TRACE_MODE") {
268- eprintln!(
269- "EC_MODE mi_row={} mi_col={} rng={}",
270- leaf_mi.0,
271- leaf_mi.1,
272- dec.debug_state().0
273- );
274- }
275262
276263 let mode_for_tx;
277264 // lane-uv8 r1: this leaf's chroma prediction mode (`get_uv_mode` of the
@@ -382,18 +369,6 @@ pub(super) fn decode_inter_block8(
382369 comp_stack.ref_mv_ctx,
383370 )
384371 };
385- if crate::envflags::env_flag!("EC_TRACE_MODE") {
386- eprintln!(
387- "EC_LEAFMODE mi_row={} mi_col={} cmode={} stack={} newmv_ctx={} refmv_ctx={} rng={}",
388- leaf_mi.0,
389- leaf_mi.1,
390- compound_mode + 17,
391- comp_stack.entries.len(),
392- comp_stack.new_mv_ctx,
393- comp_stack.ref_mv_ctx,
394- dec.debug_state().0
395- );
396- }
397372 let (mv0, mv1) = assign_compound_mv(
398373 dec,
399374 cdfs,
@@ -412,19 +387,6 @@ pub(super) fn decode_inter_block8(
412387 // lane-inter8 r3: byte-format-identical to the oracle's
413388 // rung-4 `EC_MODE_VAL`, so the leaf's mode+mv VALUE ladder
414389 // diffs line for line against a real aomdec.
415- if crate::envflags::env_flag!("EC_TRACE_MODE") {
416- eprintln!(
417- "EC_MODE_VAL mi_row={} mi_col={} mode={} ref0={} ref1={} mv0=({},{}) rng={}",
418- leaf_mi.0,
419- leaf_mi.1,
420- compound_mode + 17,
421- ref0,
422- ref1,
423- mv0.0,
424- mv0.1,
425- dec.debug_state().0
426- );
427- }
428390
429391 // spec 5.11.25: same gating [`decode_inter_block`]'s own
430392 // compound arm uses, keyed off `outer_at`'s [`SUB`]-grid
@@ -435,7 +397,6 @@ pub(super) fn decode_inter_block8(
435397 && enable_masked_compound
436398 && is_any_masked_compound_used_here(SIDE, SIDE)
437399 {
438- crate::msac::SymbolDecoder::set_symr_cdf("comp_group_idx");
439400 dec.symbol(&mut cdfs.comp_group_idx[group_ctx])
440401 } else {
441402 0
@@ -454,7 +415,6 @@ pub(super) fn decode_inter_block8(
454415 // leaf's own comment.
455416 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]);
456417 let wedge_sign = dec.literal(1);
457- hit!(WEDGE_HITS);
458418 wedge_mask = Some(
459419 crate::wedge::wedge_masks()
460420 .codebook(SIDE, SIDE)
@@ -464,7 +424,6 @@ pub(super) fn decode_inter_block8(
464424 let mask_type = dec.literal(1);
465425 diffwtd_mask_type = Some(mask_type as u8);
466426 }
467- hit!(MASKED_COMPOUND_HITS);
468427 }
469428 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same
470429 // reference-slot defect as the 16x16 leaf's own mask above
@@ -490,15 +449,10 @@ pub(super) fn decode_inter_block8(
490449 ref_order_hints[(ref0 - LAST_FRAME) as usize],
491450 ref_order_hints[(ref1 - LAST_FRAME) as usize],
492451 );
493- crate::msac::SymbolDecoder::set_symr_cdf("compound_idx");
494452 let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]);
495453 if idx == 1 {
496454 (8, 8, 1u8)
497455 } else {
498- // lane-av1distwtd: the 8x8 leaf's own
499- // distance-weighted arm, same counter as the
500- // 16x16+ site above.
501- hit!(DIST_WTD_COMP_HITS);
502456 let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign(
503457 order_hint_bits,
504458 order_hint,
@@ -511,16 +465,6 @@ pub(super) fn decode_inter_block8(
511465 (8, 8, 1u8)
512466 };
513467 compound_ctx8 = Some((ref0, ref1, comp_group_idx as u8, compound_idx));
514- if crate::envflags::env_flag!("EC_AV1_COMPIDX_DUMP") {
515- eprintln!(
516- "EC_COMPIDX mi_row={mi_row} mi_col={mi_col} bsize=8 mode={compound_mode} mv0=({},{}) mv1=({},{}) ref0={ref0} ref1={ref1} comp_group_idx={comp_group_idx} compound_idx={compound_idx} tell={}",
517- mv0.0,
518- mv0.1,
519- mv1.0,
520- mv1.1,
521- dec.debug_bitpos()
522- );
523- }
524468
525469 // lane-interp3 r1: `read_mb_interp_filter` (libaom
526470 // `decodemv.c` 1575, the tail of
@@ -570,17 +514,10 @@ pub(super) fn decode_inter_block8(
570514 true,
571515 );
572516 leaf_filter_syms = resolved_filter;
573- if interp_fixed.is_none() && !(gm_nontrans_c || skip_mode) {
574- hit!(COMPOUND8_FILTER_HITS);
575- }
576517
577518 // lane-defer8: both slots' SIZES at parse, pictures in the closure.
578519 let scale0 = scale_of(ref_dims(ref0, refpix)?, frame_size);
579520 let scale1 = scale_of(ref_dims(ref1, refpix)?, frame_size);
580- if !scale0.is_unscaled() || !scale1.is_unscaled() {
581- hit!(SCALED_COMPOUND_HITS);
582- hit!(SCALED_BLOCK8_HITS);
583- }
584521
585522 // lane-interp3 r2 (class twin-functions-drift): both slots
586523 // used to be stamped `false`, while [`decode_inter_block`]'s
@@ -635,10 +572,6 @@ pub(super) fn decode_inter_block8(
635572 leaf_compound_warp(ref0, is_global_mv0_c).filter(|_| leaf_ref_unscaled(ref0));
636573 let warp1_c =
637574 leaf_compound_warp(ref1, is_global_mv1_c).filter(|_| leaf_ref_unscaled(ref1));
638- if warp0_c.is_some() || warp1_c.is_some() {
639- hit!(COMPOUND_WARP_HITS);
640- hit!(COMPOUND_WARP_HITS_8);
641- }
642575 grid.fill_rect(
643576 mi_row,
644577 mi_col,
@@ -745,7 +678,6 @@ pub(super) fn decode_inter_block8(
745678 let mut diffwtd_mask_y;
746679 let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type {
747680 diffwtd_mask_y = vec![0u8; SIDE * SIDE];
748- hit!(DIFFWTD_HITS);
749681 mc::diffwtd_mask(
750682 &inter0_y,
751683 &inter1_y,
@@ -1002,7 +934,23 @@ pub(super) fn decode_inter_block8(
1002934 let (pred_y, pred_u, pred_v): (Vec<u16>, Vec<u16>, Vec<u16>);
1003935 let (sy, su, sv) = if pred_deferred(refpix) {
1004936 push_pred(build);
1005- (Pred::Cur { plane: 0, stride: SIDE, off: 0 }, Pred::Cur { plane: 1, stride: chroma_w, off: 0 }, Pred::Cur { plane: 2, stride: chroma_w, off: 0 })
937+ (
938+ Pred::Cur {
939+ plane: 0,
940+ stride: SIDE,
941+ off: 0,
942+ },
943+ Pred::Cur {
944+ plane: 1,
945+ stride: chroma_w,
946+ off: 0,
947+ },
948+ Pred::Cur {
949+ plane: 2,
950+ stride: chroma_w,
951+ off: 0,
952+ },
953+ )
1006954 } else {
1007955 let mut built: [Vec<u16>; 3] = Default::default();
1008956 build(y, u, v, refpix, fctx, &mut built);
@@ -1323,13 +1271,6 @@ pub(super) fn decode_inter_block8(
13231271 neighbours.above[leaf_mi.1 + cell][0] = state;
13241272 }
13251273 }
1326- // lane-cdef r1: ... and the CDEF skip band too. `apply_cdef`'s
1327- // `is_8x8_block_skip` (libaom `cdef.c:29-38`) reads all four mi
1328- // cells of the 8x8; this leaf wrote none of them, so a 64x64
1329- // whose bottom-right 16x16 is an all-skip 8x8-leaf group kept
1330- // the PREVIOUS frame's flags and got filtered where libaom's
1331- // dlist excludes it (3 luma samples on a 192x128 inter frame).
1332- hit!(INTER8_SKIP_BAND_HITS);
13331274 neighbours.fill_skip_grid(leaf_mi, 2, skip);
13341275 // lane-sub8x4 r2: `split8` is this leaf's OWN var-tx split, so
13351276 // the deblock grid must publish the TX_4X4 leaves' width the
@@ -1408,19 +1349,8 @@ pub(super) fn decode_inter_block8(
14081349 // lane-interp3 r2: same per-entry EC_STACK ladder
14091350 // [`decode_inter_block`]'s single-ref arm prints, so this leaf's stack
14101351 // diffs line for line against the oracle's.
1411- if crate::envflags::env_flag!("EC_TRACE_MODE") {
1412- for (i, e) in stack.entries.iter().enumerate() {
1413- eprintln!(
1414- "EC_STACK mi_row={mi_row} mi_col={mi_col} ref={ref_frame} i={i} this=({},{}) comp=(0,0) w={}",
1415- e.mv.0, e.mv.1, e.weight
1416- );
1417- }
1418- }
14191352
14201353 let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
1421- if !not_new {
1422- crate::census::mode(0);
1423- }
14241354 let mut is_globalmv = false;
14251355 let (mv, is_new_mv) = if !not_new {
14261356 // NEWMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting at 0):
@@ -1451,19 +1381,11 @@ pub(super) fn decode_inter_block8(
14511381 )
14521382 } else {
14531383 let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;
1454- if !not_zero {
1455- crate::census::mode(1);
1456- }
14571384 is_globalmv = !not_zero;
14581385 let mv = if !not_zero {
1459- // lane-gmaffine r1: GLOBALMV (spec 7.10.2.1) -- the same
1460- // `gm_get_motion_vector` value the 16x16+ leaf reads out of
1461- // its own `gm_table`, computed at this block's centre.
1462- hit!(GLOBALMV_HITS_8);
14631386 gm_table[(ref_frame - LAST_FRAME) as usize]
14641387 } else {
14651388 let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
1466- crate::census::mode(if nearest { 2 } else { 3 });
14671389 if nearest {
14681390 stack.nearest_mv
14691391 } else {
@@ -1487,7 +1409,6 @@ pub(super) fn decode_inter_block8(
14871409 let mut interintra_mode: Option<u8> = None;
14881410 let mut wedge_mask: Option<(&'static [u8], usize)> = None;
14891411 if enable_interintra_compound && !skip_mode {
1490- crate::msac::SymbolDecoder::set_symr_cdf("interintra");
14911412 let interintra = dec.symbol(&mut cdfs.interintra[SIZE_GROUP_8]) == 1;
14921413 if interintra {
14931414 // lane-interintra r1: same read pair as the 16/32 site;
@@ -1499,15 +1420,12 @@ pub(super) fn decode_inter_block8(
14991420 // lane-wii r2: same adapting `wedge_index` symbol as the
15001421 // 16/32 leaf, fixed sign 0 -- see that site's comment.
15011422 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]);
1502- hit!(WII_HITS);
15031423 wedge_mask = Some((
15041424 crate::wedge::wedge_masks()
15051425 .codebook(SIDE, SIDE)
15061426 .mask(0, wedge_index),
15071427 SIDE,
15081428 ));
1509- } else {
1510- hit!(INTERINTRA_HITS);
15111429 }
15121430 interintra_mode = Some(ii);
15131431 // The inter-intra predictor reads this block's neighbours as already
@@ -1584,38 +1502,14 @@ pub(super) fn decode_inter_block8(
15841502 let ref_is_scaled = !scale_of((ref_width, ref_height), frame_size).is_unscaled();
15851503 let warp_eligible =
15861504 allow_warped_motion && !ref_is_scaled && !force_integer_mv && proj_ok;
1587- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
1588- eprintln!(
1589- "EC_MM8 mi_row={mi_row} mi_col={mi_col} proj={} warp_elig={} awm={}",
1590- proj_ok as u8, warp_eligible as u8, allow_warped_motion as u8
1591- );
1592- }
1593- if allow_warped_motion && proj_ok && ref_is_scaled {
1594- hit!(SCALED_WARP_SUPPRESSED_HITS);
1595- }
1596- if allow_warped_motion && proj_ok && !ref_is_scaled && force_integer_mv {
1597- hit!(FIMV_ALPHABET_HITS);
1598- }
15991505 if warp_eligible {
1600- crate::msac::SymbolDecoder::set_symr_cdf("motion_mode");
16011506 let mode = dec.symbol(&mut cdfs.motion_mode[0]);
16021507 match mode {
16031508 0 => {}
16041509 1 => {
16051510 obmc_selected = true;
1606- hit!(OBMC_HITS);
1607- hit!(OBMC_HITS_8);
16081511 }
16091512 _ => {
1610- // lane-gmaffine r1: WARPED_CAUSAL at the 8x8 leaf --
1611- // the same findSamples -> select_samples ->
1612- // av1_find_projection chain the 16x16+ leaf runs,
1613- // with BLOCK_8X8's own 8x8 model centre; an
1614- // unusable projection falls back to the block's
1615- // translational mv (libaom `av1_find_projection`
1616- // returning 1 leaves `wm_params` invalid and
1617- // `build_inter_predictors` skips the warp).
1618- hit!(WARP_SELECTED_HITS);
16191513 let mut samples = find_samples(
16201514 grid,
16211515 mi_row,
@@ -1640,18 +1534,11 @@ pub(super) fn decode_inter_block8(
16401534 mi_col as i32,
16411535 );
16421536 warped_selected = true;
1643- if warp_params.is_some() {
1644- hit!(WARP_HITS_8);
1645- }
16461537 }
16471538 }
16481539 } else {
16491540 // `default_obmc_cdf`'s own index: square bsize 8/16/32/64 -> 0/1/2/3.
16501541 obmc_selected = dec.symbol(&mut cdfs.obmc[0]) == 1;
1651- if obmc_selected {
1652- hit!(OBMC_HITS);
1653- hit!(OBMC_HITS_8);
1654- }
16551542 }
16561543 }
16571544 // lane-gmaffine r1: `read_mb_interp_filter` (spec 5.11.26) at the 8x8
@@ -1695,17 +1582,6 @@ pub(super) fn decode_inter_block8(
16951582 false,
16961583 );
16971584 leaf_filter_syms = resolved_filter;
1698- if crate::envflags::env_flag!("EC_TRACE_MODE") {
1699- eprintln!(
1700- "EC_MODE_VAL8 mi_row={} mi_col={} newmv={is_new_mv} globalmv={is_globalmv} ref0={ref_frame} mv0=({},{}) stack={} rng={}",
1701- leaf_mi.0,
1702- leaf_mi.1,
1703- mv.0,
1704- mv.1,
1705- stack.entries.len(),
1706- dec.debug_state().0
1707- );
1708- }
17091585 // lane-gmaffine r1: `allow_warp`'s `global_warp_allowed` branch
17101586 // (`reconinter.c:33-55`), gated INDEPENDENTLY of `motion_mode` --
17111587 // see [`decode_inter_block`]'s own copy. A local WARPED_CAUSAL model
@@ -1713,23 +1589,12 @@ pub(super) fn decode_inter_block8(
17131589 // size predicate baked into `is_global_mv_block`.
17141590 if warp_params.is_none() && is_global_mv_block && !force_integer_mv && !gm_ref.invalid {
17151591 warp_params = crate::warp::global_warp_params(gm_ref.params);
1716- if warp_params.is_some() && gm_ref.model == ec_av1_syntax::WarpModel::Affine {
1717- hit!(AFFINE_GM_HITS);
1718- }
17191592 }
17201593 // lane-av112bitw: same lift as the 16x16+ leaf -- a local
17211594 // `WARPED_CAUSAL` projection or a global model both leave
17221595 // `warp_params` set here; the 12-bit refusal that stood here is
17231596 // lifted with the same witness (`warp::warp_round_0` moved the
17241597 // filter's shifts; the same stream decodes byte-exact vs ffmpeg).
1725- if crate::envflags::env_flag!("EC_TRACE_MODE") {
1726- eprintln!(
1727- "EC_WARP8 mi_row={} mi_col={} warp={} globalblk={is_global_mv_block}",
1728- leaf_mi.0,
1729- leaf_mi.1,
1730- warp_params.is_some(),
1731- );
1732- }
17331598 grid.fill_rect(
17341599 mi_row,
17351600 mi_col,
@@ -1760,9 +1625,6 @@ pub(super) fn decode_inter_block8(
17601625 // (documented corner-cut above); under a scaled reference the same
17611626 // fixed kernel runs through spec 7.11.3.3's scaled walk instead.
17621627 let luma_scale = scale_of((ref_width, ref_height), frame_size);
1763- if !luma_scale.is_unscaled() {
1764- hit!(SCALED_BLOCK8_HITS);
1765- }
17661628 let obmc = if obmc_selected {
17671629 Some(obmc_plan(
17681630 grid,
@@ -1972,7 +1834,23 @@ pub(super) fn decode_inter_block8(
19721834 let (pred_y, pred_u, pred_v): (Vec<u16>, Vec<u16>, Vec<u16>);
19731835 let (sy, su, sv) = if pred_deferred(refpix) {
19741836 push_pred(build);
1975- (Pred::Cur { plane: 0, stride: SIDE, off: 0 }, Pred::Cur { plane: 1, stride: chroma_w, off: 0 }, Pred::Cur { plane: 2, stride: chroma_w, off: 0 })
1837+ (
1838+ Pred::Cur {
1839+ plane: 0,
1840+ stride: SIDE,
1841+ off: 0,
1842+ },
1843+ Pred::Cur {
1844+ plane: 1,
1845+ stride: chroma_w,
1846+ off: 0,
1847+ },
1848+ Pred::Cur {
1849+ plane: 2,
1850+ stride: chroma_w,
1851+ off: 0,
1852+ },
1853+ )
19761854 } else {
19771855 // The interintra predictor reads this block's own above/left
19781856 // edges, which are already written at this point.
@@ -2194,7 +2072,6 @@ pub(super) fn decode_inter_block8(
21942072 }
21952073 }
21962074 } else {
2197- crate::msac::SymbolDecoder::set_symr_cdf("y_mode");
21982075 let mode = dec.symbol(&mut cdfs.y_mode[SIZE_GROUP_8]);
21992076 if mode >= 13 {
22002077 return Err(unsupported(
@@ -2214,19 +2091,6 @@ pub(super) fn decode_inter_block8(
22142091 } else {
22152092 0
22162093 };
2217- if angle_delta_y != 0 {
2218- hit!(INTRA_IN_INTER_ANGLE_DELTA_Y_HITS);
2219- // lane-leaf8tx r1: `av1_use_angle_delta(BLOCK_8X8)` is true
2220- // (`bsize >= BLOCK_8X8`), so this leaf codes `angle_delta_y` off
2221- // `angle_delta_cdf[mode - V_PRED]` exactly as a key-frame block
2222- // does (libaom `read_intra_angle_info` inside
2223- // `read_intra_block_mode_info`, decodemv.c), and the delta feeds
2224- // the directional predictor + the edge filter/upsample decision
2225- // through the same `reconstruct` argument below. Counted
2226- // separately from the >=16x16 arm so the gate cannot be satisfied
2227- // by a bigger block.
2228- hit!(INTRA_IN_INTER8_ANGLE_DELTA_Y_HITS);
2229- }
22302094 // lane-uv8 r1: the delta'd angle decides the intra edge filter, and a
22312095 // directional luma mode is already legal on this leaf -- the arm
22322096 // passed a hardcoded `false` where [`decode_leaf8`] reads the
@@ -2256,42 +2120,20 @@ pub(super) fn decode_inter_block8(
22562120 let uv_mode = if !has_chroma {
22572121 DC_PRED
22582122 } else if cfl_allowed_px(SIDE, SIDE, fctx) {
2259- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
22602123 dec.symbol(&mut cdfs.uv_mode_cfl[mode])
22612124 } else {
2262- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
22632125 dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
22642126 };
2265- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
2266- eprintln!(
2267- "EC_ISTEP8 mi_row={} mi_col={} name=modes y={mode} uv={uv_mode} fi_enabled={} rng={}",
2268- leaf_mi.0,
2269- leaf_mi.1,
2270- fctx.enable_filter_intra_inter.with(std::cell::Cell::get),
2271- dec.debug_state().0
2272- );
2273- }
2274- if (9..=12).contains(&uv_mode) {
2275- hit!(SMOOTH_UV_HITS);
2276- hit!(INTRA_IN_INTER8_UV_SMOOTH_HITS);
2277- }
22782127 let alpha = if has_chroma && uv_mode == UV_CFL_PRED {
2279- hit!(INTRA_IN_INTER8_UV_CFL_HITS);
22802128 Some(read_cfl_alphas(dec, cdfs))
22812129 } else {
22822130 None
22832131 };
22842132 let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
2285- hit!(DIRECTIONAL_UV_HITS);
2286- hit!(INTRA_IN_INTER8_UV_DIR_HITS);
22872133 read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])
22882134 } else {
22892135 0
22902136 };
2291- if angle_delta_uv != 0 {
2292- hit!(UV_ANGLE_DELTA_HITS);
2293- hit!(INTRA_IN_INTER_ANGLE_DELTA_UV_HITS);
2294- }
22952137 // `get_uv_mode` (spec 9.3): `UV_CFL_PRED` predicts as `DC_PRED`.
22962138 uv_predict_mode = if uv_mode == UV_CFL_PRED {
22972139 DC_PRED
@@ -2333,16 +2175,6 @@ pub(super) fn decode_inter_block8(
23332175 let use_palette_uv = has_chroma
23342176 && uv_mode == DC_PRED
23352177 && dec.symbol(&mut cdfs.palette_uv_mode[usize::from(use_palette_y)]) != 0;
2336- if crate::envflags::env_flag!("EC_PALSYN") {
2337- eprintln!(
2338- "EC_PALSYN leaf8 mi={},{} bw=8 bh=8 mode={mode} uv={uv_mode} ctx={palette_ctx} y={} uv={} rng={}",
2339- leaf_mi.0,
2340- leaf_mi.1,
2341- palette_y_pending.map_or(0, |(n, _)| n),
2342- u8::from(use_palette_uv),
2343- dec.debug_state().0
2344- );
2345- }
23462178 if use_palette_uv {
23472179 let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]);
23482180 let (u_colors, v_colors) = read_palette_colors_uv(dec, n, &palette_uv_cache, fctx);
@@ -2362,7 +2194,6 @@ pub(super) fn decode_inter_block8(
23622194 // prints `use_filter_intra` for an intra block inside an INTER frame
23632195 // and nothing else, so this leaf needs the same two lines for a
23642196 // range-ladder diff against it.
2365- let ec_istep8 = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");
23662197 if mode == DC_PRED
23672198 && fctx.enable_filter_intra_inter.with(std::cell::Cell::get)
23682199 // `av1_filter_intra_allowed` (reconintra.h:77) excludes a
@@ -2371,27 +2202,8 @@ pub(super) fn decode_inter_block8(
23712202 && let Some(class) = filter_intra_size_class(SIDE)
23722203 {
23732204 let use_fi = dec.symbol(&mut cdfs.filter_intra[class]) != 0;
2374- if ec_istep8 {
2375- eprintln!(
2376- "EC_ISTEP mi_row={} mi_col={} name=use_filter_intra val={} rng={}",
2377- leaf_mi.0,
2378- leaf_mi.1,
2379- u8::from(use_fi),
2380- dec.debug_state().0
2381- );
2382- }
23832205 if use_fi {
2384- hit!(FILTER_INTRA_HITS);
2385- hit!(INTRA_IN_INTER_FILTER_INTRA_HITS);
23862206 let fi = dec.symbol(&mut cdfs.filter_intra_mode);
2387- if ec_istep8 {
2388- eprintln!(
2389- "EC_ISTEP mi_row={} mi_col={} name=filter_intra_mode val={fi} rng={}",
2390- leaf_mi.0,
2391- leaf_mi.1,
2392- dec.debug_state().0
2393- );
2394- }
23952207 filter_intra = Some(fi);
23962208 }
23972209 }
@@ -2407,15 +2219,6 @@ pub(super) fn decode_inter_block8(
24072219 palette_onscreen(rmi, cmi, SIDE, SIDE, fctx),
24082220 false,
24092221 );
2410- hit!(PALETTE_HITS);
2411- hit!(INTRA_IN_INTER_PALETTE_Y_HITS);
2412- hit_do! {
2413- INTER8_PALETTE_HITS.with(|c| {
2414- let mut v = c.get();
2415- v.0 += 1;
2416- c.set(v);
2417- });
2418- }
24192222 PaletteY {
24202223 size: n,
24212224 colors,
@@ -2433,15 +2236,6 @@ pub(super) fn decode_inter_block8(
24332236 (ss_x(fctx), ss_y(fctx)),
24342237 );
24352238 let map = decode_color_index_map_wh(dec, cdfs, n, chroma_w, chroma_h, on, true);
2436- hit!(PALETTE_UV_HITS);
2437- hit!(INTRA_IN_INTER_PALETTE_UV_HITS);
2438- hit_do! {
2439- INTER8_PALETTE_HITS.with(|c| {
2440- let mut v = c.get();
2441- v.1 += 1;
2442- c.set(v);
2443- });
2444- }
24452239 PaletteUv {
24462240 size: n,
24472241 u_colors,
@@ -2528,7 +2322,6 @@ pub(super) fn decode_inter_block8(
25282322 // (the whole-block buffer would be indexed at the wrong
25292323 // stride by the first unit).
25302324 if let Some(buf) = &palette_y_buf {
2531- hit!(PALETTE_SPLIT_TX_HITS);
25322325 let window: Vec<u16> = (0..tx_px)
25332326 .flat_map(|i| {
25342327 let base = (row * MI + i) * SIDE + col * MI;
@@ -2564,10 +2357,6 @@ pub(super) fn decode_inter_block8(
25642357 read_plane(
25652358 dec,
25662359 cdfs,
2567- // Intra 4x4 luma: seven-type
2568- // `EXT_TX_SET_DTT4_IDTX_1DDCT` unless reduced, whose
2569- // CDF row is the intra dir (`fi_tx_row` inside
2570- // `read_plane` maps a filter-intra block's).
25712360 txbset_for(tx_px, reduced_tx_set),
25722361 default_scan(tx_px),
25732362 0,
@@ -2583,7 +2372,6 @@ pub(super) fn decode_inter_block8(
25832372 tu_py,
25842373 tx_px,
25852374 tx_px,
2586- base_q_idx,
25872375 None,
25882376 filter_intra,
25892377 Some(tu_skip_ctx),
@@ -2682,14 +2470,6 @@ pub(super) fn decode_inter_block8(
26822470 read_plane(
26832471 dec,
26842472 cdfs,
2685- // lane-uv8 r3: an intra leaf inside an inter frame is
2686- // `is_inter == 0` in `av1_get_ext_tx_set_type`, so its 8x8
2687- // luma reads the INTRA set -- seven-type
2688- // `EXT_TX_SET_DTT4_IDTX_1DDCT` when `reduced_tx_set == 0`,
2689- // five-type `EXT_TX_SET_DTT4_IDTX` when it is 1. Hardcoding
2690- // the reduced set read the wrong ALPHABET (class
2691- // [[wrong-alphabet-same-value]]) and desynced at the leaf's
2692- // first `tx_type`.
26932473 txbset_for(8, reduced_tx_set),
26942474 scan8,
26952475 0,
@@ -2705,7 +2485,6 @@ pub(super) fn decode_inter_block8(
27052485 py,
27062486 SIDE,
27072487 TX8,
2708- base_q_idx,
27092488 None,
27102489 filter_intra,
27112490 None,
@@ -2752,7 +2531,6 @@ pub(super) fn decode_inter_block8(
27522531 cdfs,
27532532 neighbours,
27542533 leaf_mi,
2755- (px, py),
27562534 (cpx, cpy),
27572535 SIDE,
27582536 (chroma_w, chroma_h),
@@ -2760,13 +2538,11 @@ pub(super) fn decode_inter_block8(
27602538 (chroma_w, chroma_h),
27612539 chroma_w,
27622540 reach,
2763- (y.width, y.height),
27642541 mode,
27652542 uv_predict_mode,
27662543 angle_delta_uv,
27672544 palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])),
27682545 smooth_neighbor_uv,
2769- base_q_idx,
27702546 &mut uo,
27712547 &mut vo,
27722548 fctx,
@@ -2782,7 +2558,6 @@ pub(super) fn decode_inter_block8(
27822558 Grid::Own(vo)
27832559 };
27842560 chroma_stamped_per_unit = true;
2785- hit!(LLINTRA8_CHROMA_WALK_HITS);
27862561 } else {
27872562 if let Some((ub, _)) = &palette_uv_bufs {
27882563 set_palette_pred(ub.clone(), fctx);
@@ -2830,7 +2605,6 @@ pub(super) fn decode_inter_block8(
28302605 cpy,
28312606 chroma_w,
28322607 chroma_tx,
2833- base_q_idx,
28342608 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
28352609 None,
28362610 None,
@@ -2884,7 +2658,6 @@ pub(super) fn decode_inter_block8(
28842658 cpy,
28852659 chroma_w,
28862660 chroma_tx,
2887- base_q_idx,
28882661 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
28892662 None,
28902663 None,
@@ -2989,18 +2762,6 @@ pub(super) fn decode_inter_block8(
29892762 neighbours.above[leaf_mi.1 + cell][0] = state;
29902763 }
29912764 }
2992- // lane-gmaffine r2: the deblock grid's ref id is the leaf's OWN reference
2993- // (r1 taught this leaf non-LAST refs; the hardcoded LAST_FRAME made every
2994- // GOLDEN/ALTREF leaf read as LAST at the loop-filter's ref/mv edge test).
2995- // lane-cdef r1: the fall-through twin of the compound arm's skip-band
2996- // write above -- `skip` is one flag for the whole 8x8 leaf (read at
2997- // `decode.rs`'s `skip_ctx` site), `split8` only splits its transform.
2998- // lane-intersub8 r5: ... and it counts too. r1 incremented the counter in
2999- // the COMPOUND early-return arm only, so the gate's assert really read
3000- // "a COMPOUND 8x8 leaf wrote the band"; once main's inter16ab/r14 routing
3001- // landed, the 10-bit cq12 arm's leaves come through here instead and the
3002- // gate failed on an instrumentation gap, with the band written either way.
3003- hit!(INTER8_SKIP_BAND_HITS);
30042765 neighbours.fill_skip_grid(leaf_mi, 2, skip);
30052766 neighbours.fill_lf_grid(
30062767 leaf_mi,
crates/ec-av1/src/decode/inter_ctx.rsmodified+4 -380
@@ -64,34 +64,13 @@ pub(super) fn resolve_interp_filter(
6464 // `h_kind`/`v_kind` argument order, which is why this function returns
6565 // `(h, v, ..)` but reads `dir0` (`v`) before `dir1` (`h`).
6666 let ctx0 = switchable_interp_ctx(above[0], left[0], 0, is_compound);
67- if crate::envflags::env_flag!("EC_AV1_IFDBG") {
68- eprintln!(
69- "IFDBG dir=0 ctx={ctx0} above={above:?} left={left:?} cdf={:?}",
70- &cdfs.switchable_interp[ctx0][..3]
71- );
72- }
7367 let sym0 = dec.symbol(&mut cdfs.switchable_interp[ctx0]) as u8;
7468 let sym1 = if enable_dual_filter {
7569 let ctx1 = switchable_interp_ctx(above[1], left[1], 1, is_compound);
76- if crate::envflags::env_flag!("EC_AV1_IFDBG") {
77- eprintln!(
78- "IFDBG dir=1 ctx={ctx1} above={above:?} left={left:?} cdf={:?} sym0={sym0}",
79- &cdfs.switchable_interp[ctx1][..3]
80- );
81- }
8270 dec.symbol(&mut cdfs.switchable_interp[ctx1]) as u8
8371 } else {
8472 sym0
8573 };
86- if enable_dual_filter && sym0 != sym1 {
87- hit!(DUAL_FILTER_DIFF_HITS);
88- }
89- if crate::envflags::env_flag!("EC_TRACE_MODE") {
90- eprintln!(
91- "EC_IF ctx0={ctx0} above={above:?} left={left:?} sym0={sym0} sym1={sym1} rng={}",
92- dec.debug_state().0
93- );
94- }
9574 (
9675 mc::InterpFilterKind::from_switchable_symbol(sym1 as usize),
9776 mc::InterpFilterKind::from_switchable_symbol(sym0 as usize),
@@ -227,7 +206,6 @@ pub(super) fn read_mv(
227206 mv.1.clamp(-MV_LIMIT + 1, MV_LIMIT - 1),
228207 );
229208 }
230- crate::census::mv(mv.0, mv.1);
231209 mv
232210 }
233211
@@ -297,13 +275,6 @@ pub(super) fn read_intrabc_dv(
297275 true,
298276 fctx,
299277 );
300- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
301- let (rng, _) = dec.debug_state();
302- eprintln!(
303- "EC_DV mi_row={mi_r} mi_col={mi_c} dv_col={} dv_row={} rng={rng}",
304- dv.1, dv.0
305- );
306- }
307278 dv
308279 }
309280
@@ -335,7 +306,6 @@ impl PlaneBuf<'_> {
335306 &mut self,
336307 x: usize,
337308 y: usize,
338- plane: usize,
339309 side: usize,
340310 w: usize,
341311 h: usize,
@@ -363,13 +333,6 @@ impl PlaneBuf<'_> {
363333 // prediction is byte-identical to the oracle's and whose committed
364334 // samples are not can only be a DIFFERENT WRITE -- and this is the
365335 // only write path with no rung of its own.
366- if crate::envflags::env_flag!("EC_MCWR") {
367- eprintln!(
368- "EC_MCWR x={x} y={y} side={side} w={w} h={h} empty_res={} at {}",
369- residual.is_empty(),
370- std::panic::Location::caller()
371- );
372- }
373336 // lane-av1444altref r2: EC_CPRED, the picture-independent twin of the
374337 // oracle's rung of the same name (aomdec's
375338 // `dec_build_inter_predictor`). This is the ONE site every inter
@@ -380,33 +343,6 @@ impl PlaneBuf<'_> {
380343 // pictures, so a rung line alone is ambiguous, but a geometry whose
381344 // samples differ by at most 1 is a unique match (any wrong pairing
382345 // differs by tens).
383- // Env: EC_CPRED="x:y" (plane-absolute origin; -1 for either = any).
384- if let Ok(spec) = crate::envflags::var("EC_CPRED") {
385- let (fx, fy): (i64, i64) = spec
386- .split_once(':')
387- .and_then(|(a, b)| Some((a.trim().parse().ok()?, b.trim().parse().ok()?)))
388- .unwrap_or((-1, -1));
389- let hit = (fx < 0 || fx == x as i64) && (fy < 0 || fy == y as i64);
390- if hit {
391- // `PREFILT_PICTURE_IDX` is bumped once per frame just AFTER
392- // that frame's last block, so it still reads this frame's own
393- // decode-order index here -- the same numbering the oracle's
394- // `aom_ec_pict_idx` and the `.fN` prefilter dumps use.
395- let pict = PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst);
396- eprintln!(
397- "OUR_CPRED pict={pict} plane={plane} x={x} y={y} w={w} h={h} side={side}"
398- );
399- for row in 0..h {
400- let src = &prediction[row * side..row * side + w];
401- let mut line = String::with_capacity(w * 4);
402- for v in src {
403- line.push(' ');
404- line.push_str(&v.to_string());
405- }
406- eprintln!("OUR_CPROW{row}:{line}");
407- }
408- }
409- }
410346 // lane-recoparse: an all-zero residual (60% of the units) is a plain
411347 // prediction copy -- the same arithmetic with `r == 0`, without
412348 // reading `side * h` zeros out of [`ZERO_RESIDUAL`].
@@ -416,9 +352,8 @@ impl PlaneBuf<'_> {
416352 let dst = (y + row) * self.width + x;
417353 let pred = &prediction[src..src + w];
418354 let out = &mut self.data.to_mut()[dst..dst + w];
419- for (col, (o, &p)) in out.iter_mut().zip(pred).enumerate() {
355+ for (o, &p) in out.iter_mut().zip(pred) {
420356 let v = i32::from(p).clamp(0, max) as u16;
421- pix_write("mc_copy", x, y, w, x + col, y + row, *o, v);
422357 *o = v;
423358 }
424359 }
@@ -431,9 +366,8 @@ impl PlaneBuf<'_> {
431366 let pred = &prediction[src..src + w];
432367 let res = &residual[src..src + w];
433368 let out = &mut self.data.to_mut()[dst..dst + w];
434- for (col, ((o, &p), &r)) in out.iter_mut().zip(pred).zip(res).enumerate() {
369+ for ((o, &p), &r) in out.iter_mut().zip(pred).zip(res) {
435370 let v = (i32::from(p) + r).clamp(0, max) as u16;
436- pix_write("mc_add", x, y, w, x + col, y + row, *o, v);
437371 *o = v;
438372 }
439373 }
@@ -485,8 +419,6 @@ pub(super) fn read_inter_plane(
485419 if plane_idx > 0 && mono(fctx) {
486420 return Ok((Grid::Zero(side * side), TxType::DctDct));
487421 }
488- // lane-av1readcensus: the units read from here on are this plane's.
489- set_census_plane(plane_idx);
490422 let skip_ctx = if plane_idx == 0 {
491423 luma_skip_ctx.unwrap_or(0)
492424 } else {
@@ -527,12 +459,6 @@ pub(super) fn read_inter_plane(
527459 default_tx_type,
528460 None,
529461 )?;
530- note_chroma_class1(plane_idx, tx_type);
531- if crate::envflags::env_flag!("EC_TRACE_TXTYPE") {
532- eprintln!(
533- "OUR_TXTYPE plane={plane_idx} x={x} y={cy} side={side} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}"
534- );
535- }
536462 // lane-inter8 r1: a 64-point transform covers the whole 64x64 area but
537463 // codes only its top-left 32x32 of frequencies (spec 5.11.40) -- the
538464 // caller hands the 32-point `scan` there, and the coded corner goes into
@@ -578,7 +504,6 @@ pub(super) fn read_intra_chroma_lossless(
578504 cdfs: &mut Cdfs,
579505 neighbours: &mut Neighbours,
580506 at_mi: (usize, usize),
581- (px, py): (usize, usize),
582507 (cpx, cpy): (usize, usize),
583508 side: usize,
584509 (blk_w, blk_h): (usize, usize),
@@ -586,13 +511,11 @@ pub(super) fn read_intra_chroma_lossless(
586511 (reg_w, reg_h): (usize, usize),
587512 stride: usize,
588513 reach: Reach,
589- (frame_w, frame_h): (usize, usize),
590514 mode: usize,
591515 uv_predict_mode: usize,
592516 angle_delta_uv: i32,
593517 palette_uv_bufs: Option<(&[u16], &[u16])>,
594518 smooth_neighbor_uv: bool,
595- base_q_idx: u8,
596519 u_out: &mut Vec<i32>,
597520 v_out: &mut Vec<i32>,
598521 fctx: &crate::decode::FrameCtx,
@@ -635,11 +558,6 @@ pub(super) fn read_intra_chroma_lossless(
635558 4 << ss_x(fctx),
636559 4 << ss_y(fctx),
637560 reach,
638- px,
639- py,
640- frame_w,
641- frame_h,
642- fctx,
643561 );
644562 if let Some((ub, vb)) = palette_uv_bufs {
645563 let buf = if plane_idx == 1 { ub } else { vb };
@@ -663,7 +581,6 @@ pub(super) fn read_intra_chroma_lossless(
663581 cpy + oy,
664582 4,
665583 4,
666- base_q_idx,
667584 None,
668585 None,
669586 offset,
@@ -679,7 +596,6 @@ pub(super) fn read_intra_chroma_lossless(
679596 plane_idx,
680597 &cu_grid,
681598 );
682- hit!(CHROMA_SPLIT_TX_HITS);
683599 let dst = mu_units(
684600 if plane_idx == 1 {
685601 &mut *u_out
@@ -738,9 +654,6 @@ pub(super) fn mu_chunk_order(
738654 let mut order = identity.clone();
739655 order.sort_by_key(|&i| ((leaves[i].0 / 16) * nchunk + (leaves[i].1 / 16), i));
740656 let changed = order != identity;
741- if changed {
742- hit!(MU_CHUNK_ORDER_HITS);
743- }
744657 (order, changed)
745658 }
746659
@@ -788,10 +701,6 @@ pub(super) fn read_inter_chroma_lossless(
788701 // lane-av1h5: a plane block above 64 is the 128-root class, whose chroma
789702 // libaom walks one 64x64 mu chunk at a time. Counted so a gate can pin
790703 // the walk/unit totals exactly rather than as a floor on wrong output.
791- let counted_128 = blk_w > 64 || blk_h > 64;
792- if counted_128 {
793- hit!(MU_CHUNK_WALKS);
794- }
795704 for plane_idx in 1..3 {
796705 for rr in 0..reg_h / 4 {
797706 for cc in 0..reg_w / 4 {
@@ -851,10 +760,6 @@ pub(super) fn read_inter_chroma_lossless(
851760 plane_idx,
852761 &cu_grid,
853762 );
854- hit!(CHROMA_SPLIT_TX_HITS);
855- if counted_128 {
856- hit!(MU_CHUNK_WALK_UNITS);
857- }
858763 let dst = mu_units(
859764 if plane_idx == 1 {
860765 &mut *u_out
@@ -1018,19 +923,6 @@ pub(super) fn read_single_ref(
1018923 if p4 == 1 { LAST2_FRAME } else { LAST_FRAME }
1019924 }
1020925 };
1021- if ref_frame != LAST_FRAME {
1022- hit!(NON_LAST_REF_HITS);
1023- let c = match ref_frame {
1024- LAST2_FRAME => &LAST2_HITS,
1025- LAST3_FRAME => &LAST3_HITS,
1026- GOLDEN_FRAME => &GOLDEN_HITS,
1027- BWDREF_FRAME => &BWDREF_HITS,
1028- ALTREF2_FRAME => &ALTREF2_HITS,
1029- ALTREF_FRAME => &ALTREF_HITS,
1030- _ => unreachable!("read_single_ref only ever returns LAST_FRAME..=ALTREF_FRAME"),
1031- };
1032- hit_do! { c.with(|v| v.set(v.get() + 1)); }
1033- }
1034926 ref_frame
1035927 }
1036928
@@ -1070,9 +962,8 @@ pub(crate) struct RefPix<'p> {
1070962 #[derive(Clone)]
1071963 pub(crate) struct SharedRefs {
1072964 pub(crate) dims: [Option<(usize, usize)>; 8],
1073- pub(crate) wait: std::sync::Arc<
1074- dyn Fn() -> Result<[Option<std::sync::Arc<Picture>>; 8]> + Send + Sync,
1075- >,
965+ pub(crate) wait:
966+ std::sync::Arc<dyn Fn() -> Result<[Option<std::sync::Arc<Picture>>; 8]> + Send + Sync>,
1076967 }
1077968
1078969 /// Where a [`RefPix`] gets its pictures: already in hand, or behind a wait
@@ -1207,12 +1098,6 @@ impl<'p> RefPix<'p> {
12071098 /// (lane-defer8).
12081099 pub(super) fn ref_dims(ref_frame: i8, refpix: &RefPix<'_>) -> Result<(usize, usize)> {
12091100 refpix.dims(ref_frame).ok_or_else(|| {
1210- if crate::envflags::env_flag!("EC_AV1_REFPROBE") {
1211- eprintln!(
1212- "EC_REFPROBE missing ref {ref_frame}\n{}",
1213- std::backtrace::Backtrace::force_capture()
1214- );
1215- }
12161101 // lane-hdrlossless: libaom errors on the same stream
12171102 // (`decodeframe.c:5027`: `if (cm->ref_frame_map[ref] == NULL)
12181103 // aom_internal_error(... AOM_CODEC_CORRUPT_FRAME, "Inter frame
@@ -1406,9 +1291,6 @@ pub(super) fn overlappable_above(
14061291 if let Some(info) = nb
14071292 && info.is_inter
14081293 {
1409- if src != col {
1410- hit!(OBMC_PAIR_FILTER_HITS);
1411- }
14121294 // lane-t900 r14: libaom passes `AOMMIN(xd->width, mi_step)`
14131295 // as `op_mi_size` -- the block's OWN width, never the
14141296 // frame-edge clamp `end_col` carries. Clamping here shrank the
@@ -1473,9 +1355,6 @@ pub(super) fn overlappable_left(
14731355 if let Some(info) = nb
14741356 && info.is_inter
14751357 {
1476- if src != row {
1477- hit!(OBMC_PAIR_FILTER_HITS);
1478- }
14791358 // lane-t900 r14: `AOMMIN(xd->height, mi_step)` -- see
14801359 // `overlappable_above`.
14811360 out.push((
@@ -1509,23 +1388,6 @@ pub(crate) fn has_overlappable_neighbour(
15091388 || !overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, 1).is_empty()
15101389 }
15111390
1512-/// The warp-sample gather's own `has_top_right` probe (libaom `av1_findSamples`
1513-/// calls the same `mvref_common.c` function the MV stack does). lane-sb128 r2:
1514-/// this used to hardcode `SB_MI` (a 64x64 superblock) -- at `sb_size == 128`
1515-/// libaom's mask loop runs one level further and strips the top-right sample
1516-/// off blocks whose neighbour IS decoded, so a warped 128-superblock frame
1517-/// picked up wrong warp parameters (frame 6 of the 128 inter gate). Delegates
1518-/// to the single sb-aware port in [`crate::mvstack::has_top_right`]; `bs` is
1519-/// the block's own side in 4x4 (`mi`) units (square inter leaves only here).
1520-pub(super) fn has_top_right(
1521- mi_row: usize,
1522- mi_col: usize,
1523- bs: usize,
1524- fctx: &crate::decode::FrameCtx,
1525-) -> bool {
1526- crate::mvstack::has_top_right(mi_row, mi_col, bs, bs, fctx)
1527-}
1528-
15291391 /// `av1_findSamples` (`mvref_common.c`), full port: the up to
15301392 /// `LEAST_SQUARES_SAMPLES_MAX` (8) above/left/top-left/top-right neighbour
15311393 /// samples (`record_samples`) that share this block's own single reference
@@ -1557,16 +1419,8 @@ pub(crate) fn find_samples(
15571419 // motion_mode alphabet over the 2-symbol obmc one.
15581420 // lane-alloc: the `format!` (and the map lookup's `String` clone) ran on
15591421 // every warp block; the flag itself is a process constant.
1560- let proj_dbg = crate::envflags::env_flag!("EC_PROJ_MI")
1561- && crate::envflags::var("EC_PROJ_MI").is_ok_and(|v| v == format!("{mi_row},{mi_col}"));
15621422 let single_ref_match = |info: &MiInfo| {
15631423 let m = info.ref_frame == ref_frame && info.ref_frame1 == NO_REF1;
1564- if proj_dbg {
1565- eprintln!(
1566- "EC_PROJ cand ref={} ref1={:?} size={} size_h={} is_inter={} want={ref_frame} match={m}",
1567- info.ref_frame, info.ref_frame1, info.size, info.size_h, info.is_inter
1568- );
1569- }
15701424 m
15711425 };
15721426 let mut do_tl = true;
@@ -1682,9 +1536,6 @@ pub(crate) fn find_samples(
16821536 // libaom reads the 2-symbol `obmc_cdf` (class
16831537 // wrong-alphabet-same-value).
16841538 let tr_reach = crate::mvstack::has_top_right(mi_row, mi_col, bw4, bh4, fctx);
1685- if do_tr && bw4 != bh4 && tr_reach != has_top_right(mi_row, mi_col, bw4, fctx) {
1686- hit!(TR_REACH_LONGER_SIDE_HITS);
1687- }
16881539 if do_tr && tr_reach {
16891540 let tr_col = mi_col + bw4;
16901541 if mi_row > 0
@@ -1785,53 +1636,12 @@ pub(super) fn neighbour_filter(
17851636 "an OBMC neighbour whose switchable interp filter was never recorded",
17861637 ));
17871638 }
1788- hit!(OBMC_FILTER_BAND_READS);
17891639 Ok((
17901640 mc::InterpFilterKind::from_switchable_symbol(sym[1] as usize),
17911641 mc::InterpFilterKind::from_switchable_symbol(sym[0] as usize),
17921642 ))
17931643 }
17941644
1795-/// lane-obmcrec r1 MEASUREMENT rung (`EC_OBMCREC=1`): every OBMC neighbour whose
1796-/// recorded switchable-filter symbols are the `[3, 3]` "never recorded" sentinel
1797-/// -- names the neighbour's own position/shape/reference so the decode path that
1798-/// failed to record its filter can be identified. Read-only, off by default.
1799-#[allow(clippy::too_many_arguments)]
1800-fn obmcrec_probe(
1801- dir: &str,
1802- mi_row: usize,
1803- mi_col: usize,
1804- write_w: usize,
1805- write_h: usize,
1806- off4: usize,
1807- span4: usize,
1808- nb: &MiInfo,
1809- syms: [u8; 2],
1810- cell: Option<MiInfo>,
1811- fixed: bool,
1812-) {
1813- if (syms[0] <= 2 && syms[1] <= 2) || !crate::envflags::env_flag!("EC_OBMCREC") {
1814- return;
1815- }
1816- eprintln!(
1817- "OBMCREC {dir} cur_mi=({mi_row},{mi_col}) cur_wh=({write_w}x{write_h}) off4={off4} \
1818-span4={span4} syms={syms:?} fixed={fixed} nb_size=({}x{}) nb_ref={} nb_ref1={:?} nb_mv=({},{}) \
1819-nb_newmv={} cell_size={:?} cell_inter={:?} cell_ref={:?} sb_row_off={} sb_col_off={}",
1820- nb.size * 4,
1821- nb.size_h * 4,
1822- nb.ref_frame,
1823- nb.ref_frame1,
1824- nb.mv.0,
1825- nb.mv.1,
1826- nb.is_new_mv,
1827- cell.map(|c| (c.size * 4, c.size_h * 4)),
1828- cell.map(|c| c.is_inter),
1829- cell.map(|c| c.ref_frame),
1830- mi_row % 32,
1831- mi_col % 32,
1832- );
1833-}
1834-
18351645 /// One neighbour's own re-prediction over a `w`x`h` region, MC'd fresh
18361646 /// against its own `mv`/reference/filter (libaom `av1_build_inter_predictor`
18371647 /// under `av1_setup_build_prediction_by_{above,left}_pred`).
@@ -2060,71 +1870,6 @@ fn obmc_blend_h(
20601870 }
20611871 }
20621872
2063-/// libaom's own `BLOCK_SIZE` enum index for a `w4`x`h4` (mi-unit) block --
2064-/// only for the `EC_OBMC` trace rung below, so it reads byte-identical to
2065-/// the instrumented aomdec's `backup_mbmi.bsize`.
2066-fn ec_obmc_bsize(w4: usize, h4: usize) -> i32 {
2067- match (w4, h4) {
2068- (1, 1) => 0,
2069- (1, 2) => 1,
2070- (2, 1) => 2,
2071- (2, 2) => 3,
2072- (2, 4) => 4,
2073- (4, 2) => 5,
2074- (4, 4) => 6,
2075- (4, 8) => 7,
2076- (8, 4) => 8,
2077- (8, 8) => 9,
2078- (8, 16) => 10,
2079- (16, 8) => 11,
2080- (16, 16) => 12,
2081- (1, 4) => 16,
2082- (4, 1) => 17,
2083- (2, 8) => 18,
2084- (8, 2) => 19,
2085- (4, 16) => 20,
2086- (16, 4) => 21,
2087- _ => -1,
2088- }
2089-}
2090-
2091-/// The `EC_OBMC` rung: one line per blended neighbour, in the instrumented
2092-/// aomdec's own byte format (`decodeframe.c`
2093-/// `dec_build_prediction_by_{above,left}_pred`), so the two decoders' OBMC
2094-/// neighbour lists diff line for line. `filt` is libaom's packed
2095-/// `interp_filters.as_int` = `y_filter | (x_filter << 16)`.
2096-#[allow(clippy::too_many_arguments)]
2097-fn ec_obmc_trace(
2098- dir: &str,
2099- mi_row: usize,
2100- mi_col: usize,
2101- write_w: usize,
2102- write_h: usize,
2103- rel: usize,
2104- op: usize,
2105- nb: &MiInfo,
2106- h_kind: mc::InterpFilterKind,
2107- v_kind: mc::InterpFilterKind,
2108-) {
2109- if !crate::envflags::env_flag!("EC_OBMC") {
2110- return;
2111- }
2112- let sym = |k: mc::InterpFilterKind| match k {
2113- mc::InterpFilterKind::Smooth => 1u32,
2114- mc::InterpFilterKind::Sharp => 2,
2115- _ => 0,
2116- };
2117- eprintln!(
2118- "EC_OBMC {dir} mi=({mi_row},{mi_col}) wh=({write_w}x{write_h}) rel={rel} op={op} \
2119-nbmv=({},{}) nbref={} nbbsize={} filt={}",
2120- nb.mv.0,
2121- nb.mv.1,
2122- nb.ref_frame,
2123- ec_obmc_bsize(nb.size as usize, nb.size_h as usize),
2124- sym(v_kind) | (sym(h_kind) << 16),
2125- );
2126-}
2127-
21281873 /// `av1_build_obmc_inter_prediction` (libaom `reconinter.c`): re-predicts
21291874 /// the overlap strip against each bordering above/left inter neighbour's own
21301875 /// mv/ref/filter and blends it into this block's just-built single-reference
@@ -2201,9 +1946,6 @@ pub(crate) fn obmc_plan(
22011946 // lane-inter4 r4: r3 refused OBMC on a 16x8/8x16 leaf; re-measured
22021947 // byte-exact against an instrumented aomdec, the refusal is gone and the
22031948 // counter below is what the gate's `--enable-obmc=1` arm reads.
2204- if matches!((write_w, write_h), (16, 8) | (8, 16)) {
2205- hit!(OBMC_RECT_LEAF_HITS);
2206- }
22071949 // lane-sb128c r1: libaom caps the overlap strip at a 64x64 block's own
22081950 // half (`reconinter.c` 860/899), inert below 128.
22091951 let overlap_above = write_h.min(64) / 2;
@@ -2233,27 +1975,8 @@ pub(crate) fn obmc_plan(
22331975 // `av1_setup_build_prediction_by_above_pred` reads
22341976 // `above_mbmi->interp_filters`).
22351977 let above_syms = above_filter.get(mi_col + src4).copied().unwrap_or([3; 2]);
2236- obmcrec_probe(
2237- "above",
2238- mi_row,
2239- mi_col,
2240- write_w,
2241- write_h,
2242- off4,
2243- span4,
2244- &nb,
2245- above_syms,
2246- grid.get(mi_row - 1, mi_col + src4),
2247- interp_fixed.is_some(),
2248- );
22491978 let (h_kind, v_kind) = neighbour_filter(interp_fixed, above_syms)?;
2250- ec_obmc_trace(
2251- "above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind,
2252- );
22531979 let nb_dims = ref_dims(nb.ref_frame, refpix)?;
2254- if mi_col + off4 + span4 > mi_cols {
2255- hit!(OBMC_EDGE_SPAN_HITS);
2256- }
22571980 above.push(ObmcNb {
22581981 off4,
22591982 span4,
@@ -2269,27 +1992,8 @@ pub(crate) fn obmc_plan(
22691992 overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4))
22701993 {
22711994 let left_syms = left_filter.get(mi_row + src4).copied().unwrap_or([3; 2]);
2272- obmcrec_probe(
2273- "left",
2274- mi_row,
2275- mi_col,
2276- write_w,
2277- write_h,
2278- off4,
2279- span4,
2280- &nb,
2281- left_syms,
2282- grid.get(mi_row + src4, mi_col - 1),
2283- interp_fixed.is_some(),
2284- );
22851995 let (h_kind, v_kind) = neighbour_filter(interp_fixed, left_syms)?;
2286- ec_obmc_trace(
2287- "left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind,
2288- );
22891996 let nb_dims = ref_dims(nb.ref_frame, refpix)?;
2290- if mi_row + off4 + span4 > mi_rows {
2291- hit!(OBMC_EDGE_SPAN_HITS);
2292- }
22931997 left.push(ObmcNb {
22941998 off4,
22951999 span4,
@@ -2405,41 +2109,6 @@ pub(crate) fn obmc_run(
24052109 // block, reused by every neighbour of the above and left passes.
24062110 let (mut tmp_y, mut tmp_u, mut tmp_v) = (Vec::new(), Vec::new(), Vec::new());
24072111
2408- // lane-t900 r13 rung: EC_MCB="<plane>:<px>:<py>[:<frame>]" (chroma plane
2409- // 1 only; <px>:<py> are chroma-plane pixels, the oracle's own dump
2410- // window) prints this block's chroma prediction rows before and after the
2411- // OBMC blend, matching the instrumented aomdec's EC_MCB dump.
2412- let ec_mcb: Option<(usize, usize, i64)> = crate::envflags::env_flag!("EC_MCB")
2413- .then(|| crate::envflags::var("EC_MCB").ok())
2414- .flatten()
2415- .and_then(|v| {
2416- let f: Vec<&str> = v.split(':').collect();
2417- if f.len() < 3 || f[0] != "1" {
2418- return None;
2419- }
2420- let (x, y) = (f[1].parse::<usize>().ok()?, f[2].parse::<usize>().ok()?);
2421- let fr = f.get(3).and_then(|s| s.parse::<i64>().ok()).unwrap_or(-1);
2422- let idx = PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst) as i64;
2423- // lane-av1ecmcb: the window is the CHROMA plane's own write region --
2424- // the oracle's EC_MCB spans are plane pixels, and at 4:4:4 (ss 0/0)
2425- // the chroma block is full-size, so nothing halves. The old
2426- // `write_w / 2` was a 4:2:0-era assumption that quartered the window
2427- // (and the dumps below) at ss 0/0.
2428- let (cw, ch) = (write_w >> ss_x(fctx), write_h >> ss_y(fctx));
2429- if x >= cpx && x < cpx + cw && y >= cpy && y < cpy + ch && (fr < 0 || fr == idx) {
2430- Some((x, y, idx))
2431- } else {
2432- None
2433- }
2434- });
2435- if let Some((_, _, idx)) = ec_mcb {
2436- let (cw, ch) = (write_w >> ss_x(fctx), write_h >> ss_y(fctx));
2437- eprintln!("OUR_MCB pre f={idx} cpx={cpx} cpy={cpy} cw={cw} ch={ch}");
2438- for r in 0..ch {
2439- let row: Vec<u16> = (0..cw).map(|c| pred_u[r * chroma_stride + c]).collect();
2440- eprintln!("OUR_MCB prerow{r}: {row:?}");
2441- }
2442- }
24432112 for nb in &plan.above {
24442113 let Some((ny, nu, nv)) = ref_planes_deferred(nb.ref_frame, refpix) else {
24452114 return;
@@ -2547,16 +2216,6 @@ pub(crate) fn obmc_run(
25472216 &mut tmp_u,
25482217 fctx,
25492218 );
2550- if let Some((_, _, idx)) = ec_mcb {
2551- eprintln!(
2552- "OUR_MCB left f={idx} off4={} span4={} cbw={cbw} cbh={cbh} coy={coy} mv=({},{}) ref0={}",
2553- nb.off4, nb.span4, nb.mv.0, nb.mv.1, nb.ref_frame
2554- );
2555- for r in 0..cbh {
2556- let row: Vec<u16> = (0..cbw).map(|c| tmp_u[r * cbw + c]).collect();
2557- eprintln!("OUR_MCB lrow{r}: {row:?}");
2558- }
2559- }
25602219 let ch = cbh.min((write_h >> ss_y(fctx)) - coy);
25612220 obmc_blend_h(pred_u, chroma_stride, 0, coy, cbw, ch, &tmp_u);
25622221 obmc_neighbour_pred(
@@ -2575,13 +2234,6 @@ pub(crate) fn obmc_run(
25752234 );
25762235 obmc_blend_h(pred_v, chroma_stride, 0, coy, cbw, ch, &tmp_v);
25772236 }
2578- if let Some((_, _, idx)) = ec_mcb {
2579- let (cw, ch) = (write_w >> ss_x(fctx), write_h >> ss_y(fctx));
2580- for r in 0..ch {
2581- let row: Vec<u16> = (0..cw).map(|c| pred_u[r * chroma_stride + c]).collect();
2582- eprintln!("OUR_MCB post f={idx} row{r}: {row:?}");
2583- }
2584- }
25852237 }
25862238
25872239 /// `is_any_masked_compound_used` (libaom `reconinter.h`), specialised to
@@ -2714,18 +2366,6 @@ pub(super) fn read_comp_mode(
27142366 ) -> bool {
27152367 let ctx = reference_mode_ctx(above, left);
27162368 let compound = dec.symbol(&mut cdfs.comp_mode[ctx]) == 1;
2717- if crate::envflags::env_flag!("EC_TRACE_MODE") {
2718- eprintln!(
2719- "EC_RCM ctx={ctx} val={} a={:?} l={:?} rng={}",
2720- usize::from(compound),
2721- above.map(|n| (n.is_inter, n.ref0, n.ref1)),
2722- left.map(|n| (n.is_inter, n.ref0, n.ref1)),
2723- dec.debug_state().0
2724- );
2725- }
2726- if compound {
2727- hit!(COMP_MODE_HITS);
2728- }
27292369 compound
27302370 }
27312371
@@ -2767,7 +2407,6 @@ pub(super) fn read_compound_ref_frames(
27672407 let type_ctx = comp_reference_type_ctx(above, left);
27682408 let unidir = dec.symbol(&mut cdfs.comp_ref_type[type_ctx]) == 0;
27692409 if unidir {
2770- hit!(UNI_COMP_HITS);
27712410 // uni_comp_ref (p0): forward vs. backward -- av1_get_pred_context_-
27722411 // uni_comp_ref_p is single_ref_p1's own forward/backward vote.
27732412 let bit = dec.symbol(&mut cdfs.uni_comp_ref[single_ref_p1_ctx(a, a1, l, l1)][0]);
@@ -2829,7 +2468,6 @@ pub(super) fn read_inter_compound_mode(
28292468 ref_mv_ctx: usize,
28302469 ) -> u8 {
28312470 let ctx = cdf::COMPOUND_MODE_CTX_MAP[ref_mv_ctx >> 1][new_mv_ctx.min(4)];
2832- hit!(COMPOUND_MODE_HITS);
28332471 dec.symbol(&mut cdfs.inter_compound_mode[ctx]) as u8
28342472 }
28352473
@@ -3031,17 +2669,3 @@ thread_local! {
30312669 /// chroma plane -- the non-vacuity bar for the assertion at that site.
30322670 pub(crate) static CHROMA_RECT_BLOCK_TX_FALLBACK_MULTI: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
30332671 }
3034-
3035-/// [`CHROMA_RECT_BLOCK_TX_FALLBACK`]: rect chroma units handed the block-level
3036-/// type because no luma leaf covered their own MI cell.
3037-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3038-pub(crate) fn chroma_rect_block_tx_fallback() -> usize {
3039- CHROMA_RECT_BLOCK_TX_FALLBACK.with(std::cell::Cell::get)
3040-}
3041-
3042-/// [`CHROMA_RECT_BLOCK_TX_FALLBACK_MULTI`]: of those, the ones whose chroma
3043-/// plane had more than one unit.
3044-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3045-pub(crate) fn chroma_rect_block_tx_fallback_multi() -> usize {
3046- CHROMA_RECT_BLOCK_TX_FALLBACK_MULTI.with(std::cell::Cell::get)
3047-}
crates/ec-av1/src/decode/inter_intra_arm.rsmodified+0 -142
@@ -132,25 +132,6 @@ pub(super) fn decode_inter_block_intra_arm(
132132 .filter(|_| write_w.min(write_h) == 4 && write_w.max(write_h) == 16)
133133 .map(|s| (s.horz, s.has_chroma));
134134 if write_w.min(write_h) < 8 && strip16.is_none() {
135- if crate::envflags::env_flag!("EC_INTRA16X4") {
136- let (idx, hc, prev_inter) = match strip_chroma {
137- Some(s) => (
138- if s.horz {
139- rmi - s.pair_mi.0
140- } else {
141- cmi - s.pair_mi.1
142- },
143- s.has_chroma,
144- s.prev.is_some(),
145- ),
146- None => (9, true, false),
147- };
148- eprintln!(
149- "EC_INTRA16X4 w={write_w} h={write_h} pair_parity={idx} has_chroma={hc} prev_single_inter={prev_inter} skip={skip} mi={rmi},{cmi} tx_select={} scr={}",
150- fctx.tx_select_inter.with(std::cell::Cell::get),
151- allow_screen_content_tools,
152- );
153- }
154135 return Err(unsupported(
155136 "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition (its 4:2:0 chroma pair is coded once for two strips; only the inter path implements that pairing)",
156137 ));
@@ -215,14 +196,7 @@ pub(super) fn decode_inter_block_intra_arm(
215196 );
216197 return Ok(None);
217198 }
218- crate::msac::SymbolDecoder::set_symr_cdf("y_mode");
219199 let mode = dec.symbol(&mut cdfs.y_mode[size_group_wh(write_w, write_h)]);
220- if crate::envflags::env_flag!("EC_IIS") {
221- eprintln!(
222- "TRACE iis px={px} py={py} side={side} w={write_w} h={write_h} sg={} mode={mode} skip={skip}",
223- size_group_wh(write_w, write_h)
224- );
225- }
226200 if mode >= 13 {
227201 return Err(unsupported(
228202 "an intra mode this decoder does not code (round 2)",
@@ -241,9 +215,6 @@ pub(super) fn decode_inter_block_intra_arm(
241215 } else {
242216 0
243217 };
244- if angle_delta_y != 0 {
245- hit!(INTRA_IN_INTER_ANGLE_DELTA_Y_HITS);
246- }
247218 // The delta'd angle decides whether the intra edge filter runs at
248219 // all, so this block needs the same luma edge-filter-type neighbour
249220 // check a key-frame block does (`get_intra_edge_filter_type`, spec
@@ -263,21 +234,13 @@ pub(super) fn decode_inter_block_intra_arm(
263234 // (libaom `decodemv.c:933`).
264235 let has_chroma = !mono(fctx);
265236 let cfl_allowed = has_chroma && cfl_allowed_px(write_w, write_h, fctx);
266- if !cfl_allowed {
267- hit!(NOCFL_UV_MODE_HITS);
268- }
269237 let uv_mode = if !has_chroma {
270238 DC_PRED
271239 } else if cfl_allowed {
272- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
273240 dec.symbol(&mut cdfs.uv_mode_cfl[mode])
274241 } else {
275- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
276242 dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
277243 };
278- if (9..=12).contains(&uv_mode) {
279- hit!(SMOOTH_UV_HITS);
280- }
281244 let alpha = if cfl_allowed && uv_mode == UV_CFL_PRED {
282245 Some(read_cfl_alphas(dec, cdfs))
283246 } else {
@@ -288,15 +251,10 @@ pub(super) fn decode_inter_block_intra_arm(
288251 // -- `uv_mode` (13) already falls outside `V_PRED..=D67_PRED` so the
289252 // `else` branch below is exact for it either way.
290253 let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
291- hit!(DIRECTIONAL_UV_HITS);
292254 read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])
293255 } else {
294256 0
295257 };
296- if angle_delta_uv != 0 {
297- hit!(UV_ANGLE_DELTA_HITS);
298- hit!(INTRA_IN_INTER_ANGLE_DELTA_UV_HITS);
299- }
300258 uv_predict_mode = if uv_mode == UV_CFL_PRED {
301259 DC_PRED
302260 } else {
@@ -336,24 +294,9 @@ pub(super) fn decode_inter_block_intra_arm(
336294 let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]);
337295 palette_y_pending = Some((n, read_palette_colors_y(dec, n, &palette_cache, fctx)));
338296 }
339- if crate::envflags::env_flag!("EC_PALSYN") {
340- eprintln!(
341- "EC_PALSYN_PRE sq mi={rmi},{cmi} bw={write_w} bh={write_h} mode={mode} uv={uv_mode} ctx={palette_ctx} y={} rng={}",
342- palette_y_pending.map_or(0, |(n, _)| n),
343- dec.debug_state().0
344- );
345- }
346297 let use_palette_uv = has_chroma
347298 && uv_mode == DC_PRED
348299 && dec.symbol(&mut cdfs.palette_uv_mode[usize::from(use_palette_y)]) != 0;
349- if crate::envflags::env_flag!("EC_PALSYN") {
350- eprintln!(
351- "EC_PALSYN sq mi={rmi},{cmi} bw={write_w} bh={write_h} mode={mode} uv={uv_mode} ctx={palette_ctx} y={} uv={} rng={}",
352- use_palette_y as i32,
353- use_palette_uv as i32,
354- dec.debug_state().0
355- );
356- }
357300 if use_palette_uv {
358301 let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]);
359302 let (u_colors, v_colors) = read_palette_colors_uv(dec, n, &palette_uv_cache, fctx);
@@ -379,8 +322,6 @@ pub(super) fn decode_inter_block_intra_arm(
379322 && let Some(class) = filter_intra_size_class_rect(write_w, write_h)
380323 && dec.symbol(&mut cdfs.filter_intra[class]) != 0
381324 {
382- hit!(FILTER_INTRA_HITS);
383- hit!(INTRA_IN_INTER_FILTER_INTRA_HITS);
384325 filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode));
385326 }
386327 // `av1_visit_palette`: the two colour-index maps, Y then the shared
@@ -395,8 +336,6 @@ pub(super) fn decode_inter_block_intra_arm(
395336 palette_onscreen(rmi, cmi, write_w, write_h, fctx),
396337 false,
397338 );
398- hit!(PALETTE_HITS);
399- hit!(INTRA_IN_INTER_PALETTE_Y_HITS);
400339 PaletteY {
401340 size: n,
402341 colors,
@@ -419,8 +358,6 @@ pub(super) fn decode_inter_block_intra_arm(
419358 (ss_x(fctx), ss_y(fctx)),
420359 );
421360 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);
422- hit!(PALETTE_UV_HITS);
423- hit!(INTRA_IN_INTER_PALETTE_UV_HITS);
424361 PaletteUv {
425362 size: n,
426363 u_colors,
@@ -516,7 +453,6 @@ pub(super) fn decode_inter_block_intra_arm(
516453 // (the whole-block buffer would be indexed at the wrong
517454 // stride by the first unit).
518455 if let Some(buf) = &palette_y_buf {
519- hit!(PALETTE_SPLIT_TX_HITS);
520456 let window: Vec<u16> = (0..tx_px)
521457 .flat_map(|i| {
522458 let base = (row * MI + i) * side + col * MI;
@@ -553,10 +489,6 @@ pub(super) fn decode_inter_block_intra_arm(
553489 dec,
554490 cdfs,
555491 txbset_for(tx_px, reduced),
556- // lane-sb128c r5: a TX_64X64 unit codes only its
557- // top-left 32x32 of frequencies (spec 5.11.40), so
558- // the scan and `tx_side` are the CODED corner while
559- // `side` stays the transform's true 64.
560492 default_scan(tx_px.min(32)),
561493 0,
562494 neighbours.around_mi(tu_mi, tx_px)[0],
@@ -571,7 +503,6 @@ pub(super) fn decode_inter_block_intra_arm(
571503 tu_py,
572504 tx_px,
573505 tx_px.min(32),
574- base_q_idx,
575506 None,
576507 filter_intra,
577508 Some(tu_skip_ctx),
@@ -588,7 +519,6 @@ pub(super) fn decode_inter_block_intra_arm(
588519 continue;
589520 }
590521 let (cr, cc) = chunk;
591- hit!(INTRA_128_IN_INTER_MU_CHROMA_HITS);
592522 // The unit's CHROMA size, its LUMA footprint, the
593523 // CHUNK's chroma extent and the unit's ORIGIN inside the
594524 // chunk are four different quantities; this arm had the
@@ -641,32 +571,18 @@ pub(super) fn decode_inter_block_intra_arm(
641571 cdfs,
642572 neighbours,
643573 at_mi,
644- (px, py),
645574 (cpx, cpy),
646575 side,
647- // lane-av1422lpf site 6 (the intra-in-inter twin of
648- // site 5 at 41572): the plane block's own per-axis
649- // shape and stride, never the enclosing square.
650- // `palette_uv_bufs` is the decoded colour-index map
651- // at `(write_w >> ss_x, write_h >> ss_y)` (44144),
652- // i.e. per-axis already, and the lossless walk
653- // windows it at this `stride` -- at 4:2:2 a
654- // 16-wide square stride over an 8-wide map put the
655- // third unit row at index 180 of 128 samples
656- // (`palette_window`, decode.rs:2946; measured on
657- // `Y_intrabc_10b.obu`).
658576 (chroma_stride, chroma_buf_h),
659577 (cc * chunk_chroma_w, cr * chunk_chroma_h),
660578 (chunk_chroma_w, chunk_chroma_h),
661579 chroma_stride,
662580 reach,
663- (y.width, y.height),
664581 mode,
665582 uv_predict_mode,
666583 angle_delta_uv,
667584 palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])),
668585 smooth_neighbor_uv,
669- base_q_idx,
670586 &mut u_units,
671587 &mut v_units,
672588 fctx,
@@ -718,11 +634,6 @@ pub(super) fn decode_inter_block_intra_arm(
718634 cr * chunk_luma + ur * unit_luma_h,
719635 unit_luma_w,
720636 reach,
721- px,
722- py,
723- y.width,
724- y.height,
725- fctx,
726637 );
727638 let cu_grid = if skip {
728639 push_intra(
@@ -762,15 +673,8 @@ pub(super) fn decode_inter_block_intra_arm(
762673 cu_y,
763674 cu_tx,
764675 cu_tx,
765- base_q_idx,
766- // CfL is refused above 32x32
767- // (`is_cfl_allowed`), so never here.
768676 None,
769677 None,
770- // The uv plane block is larger than
771- // the unit: `get_txb_ctx`'s offset-10
772- // rows, +3 on the `txb_skip_chroma_32`
773- // table (lane-sb128b r3).
774678 Some(3),
775679 smooth_neighbor_uv,
776680 fctx,
@@ -785,7 +689,6 @@ pub(super) fn decode_inter_block_intra_arm(
785689 plane_idx,
786690 &cu_grid,
787691 );
788- hit!(CHROMA_SPLIT_TX_HITS);
789692 // lane-dpm1: the two INTER mu-chunk sites set
790693 // this and this INTRA-in-inter one did not, so
791694 // the whole-block chroma record below re-stamped
@@ -794,9 +697,6 @@ pub(super) fn decode_inter_block_intra_arm(
794697 // libaom never selects (class
795698 // `override-slot-on-one-arm`).
796699 mu_chroma = true;
797- // lane-av1muchunk422b: the allocation of the intra-in-inter
798- // mu-chunk walk (site 8), per TX_32X32 unit.
799- hit!(MU_CHUNK_INTRA_IN_INTER_UNITS);
800700 let dst = mu_units(
801701 if plane_idx == 1 {
802702 &mut u_units
@@ -846,7 +746,6 @@ pub(super) fn decode_inter_block_intra_arm(
846746 } else {
847747 Grid::Own(std::mem::take(&mut v_units))
848748 };
849- hit!(INTRA_128_IN_INTER_HITS);
850749 } else if skip {
851750 if !split_luma {
852751 if let Some(buf) = &palette_y_buf {
@@ -945,7 +844,6 @@ pub(super) fn decode_inter_block_intra_arm(
945844 py,
946845 side,
947846 luma_tx,
948- base_q_idx,
949847 None,
950848 filter_intra,
951849 None,
@@ -966,26 +864,18 @@ pub(super) fn decode_inter_block_intra_arm(
966864 cdfs,
967865 neighbours,
968866 at_mi,
969- (px, py),
970867 (cpx, cpy),
971868 side,
972- // lane-av1422lpf site 6 (the whole-block twin of the mu
973- // chunk fix at 44374): the plane block's own per-axis shape
974- // and its own stride, never the enclosing square
975- // `chroma_side`. At 4:2:0 and 4:4:4 all three are the same
976- // number.
977869 (chroma_stride, chroma_buf_h),
978870 (0, 0),
979871 (chroma_stride, chroma_buf_h),
980872 chroma_stride,
981873 reach,
982- (y.width, y.height),
983874 mode,
984875 uv_predict_mode,
985876 angle_delta_uv,
986877 palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])),
987878 smooth_neighbor_uv,
988- base_q_idx,
989879 &mut uo,
990880 &mut vo,
991881 fctx,
@@ -1035,11 +925,6 @@ pub(super) fn decode_inter_block_intra_arm(
1035925 cu_row * chroma_tx,
1036926 chroma_tx,
1037927 reach,
1038- px,
1039- py,
1040- y.width,
1041- y.height,
1042- fctx,
1043928 );
1044929 let cu_grid = read_plane(
1045930 dec,
@@ -1059,9 +944,6 @@ pub(super) fn decode_inter_block_intra_arm(
1059944 cpy + cu_row * chroma_tx,
1060945 chroma_tx,
1061946 chroma_tx,
1062- base_q_idx,
1063- // CfL is capped at 32x32 (`is_cfl_allowed`),
1064- // so a block this size never carries alpha.
1065947 None,
1066948 None,
1067949 Some(3),
@@ -1072,7 +954,6 @@ pub(super) fn decode_inter_block_intra_arm(
1072954 // coefficient context.
1073955 neighbours
1074956 .record_mi_chroma(cu_mi, chroma_tx, chroma_tx, plane_idx, &cu_grid);
1075- hit!(CHROMA_SPLIT_TX_HITS);
1076957 let acc = if plane_idx == 1 {
1077958 &mut u_acc
1078959 } else {
@@ -1123,7 +1004,6 @@ pub(super) fn decode_inter_block_intra_arm(
11231004 cpy,
11241005 chroma_side,
11251006 chroma_tx,
1126- base_q_idx,
11271007 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
11281008 None,
11291009 None,
@@ -1161,11 +1041,6 @@ pub(super) fn decode_inter_block_intra_arm(
11611041 luma_span_x,
11621042 luma_span_y,
11631043 reach,
1164- px,
1165- py,
1166- y.width,
1167- y.height,
1168- fctx,
11691044 );
11701045 // The 4:2:2 plane block is `(chroma_w, chroma_h)` --
11711046 // 32x64 -- but codes TWO stacked TX_32X32 units, so
@@ -1181,7 +1056,6 @@ pub(super) fn decode_inter_block_intra_arm(
11811056 fctx,
11821057 );
11831058 }
1184- hit!(PALETTE_422_UNIT_WINDOW_HITS);
11851059 let cu_grid = read_plane(
11861060 dec,
11871061 cdfs,
@@ -1200,18 +1074,12 @@ pub(super) fn decode_inter_block_intra_arm(
12001074 cpy + cu_row * cu_h,
12011075 cu_w,
12021076 cu_w,
1203- base_q_idx,
12041077 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
12051078 None,
1206- // The uv plane block (32x64) is larger than the unit
1207- // (32x32): `get_txb_ctx`'s offset-10 rows, +3 on the
1208- // `txb_skip_chroma_32` table (lane-sb128b r3).
12091079 Some(3),
12101080 smooth_neighbor_uv,
12111081 fctx,
12121082 )?;
1213- hit!(CHROMA_SPLIT_TX_HITS);
1214- hit!(CHROMA422_SQUARE_HITS);
12151083 // Immediately, so the next unit of this plane reads this
12161084 // one's coefficient context; the whole-block record below
12171085 // re-stamps the block over these and the tail's
@@ -1280,7 +1148,6 @@ pub(super) fn decode_inter_block_intra_arm(
12801148 cpy,
12811149 chroma_side,
12821150 chroma_tx,
1283- base_q_idx,
12841151 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
12851152 None,
12861153 None,
@@ -1309,11 +1176,6 @@ pub(super) fn decode_inter_block_intra_arm(
13091176 luma_span_x,
13101177 luma_span_y,
13111178 reach,
1312- px,
1313- py,
1314- y.width,
1315- y.height,
1316- fctx,
13171179 );
13181180 // The V twin of the U arm's per-unit window above.
13191181 if let Some((_, vb)) = &palette_uv_bufs {
@@ -1322,7 +1184,6 @@ pub(super) fn decode_inter_block_intra_arm(
13221184 fctx,
13231185 );
13241186 }
1325- hit!(PALETTE_422_UNIT_WINDOW_HITS);
13261187 let cu_grid = read_plane(
13271188 dec,
13281189 cdfs,
@@ -1341,15 +1202,12 @@ pub(super) fn decode_inter_block_intra_arm(
13411202 cpy + cu_row * cu_h,
13421203 cu_w,
13431204 cu_w,
1344- base_q_idx,
13451205 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
13461206 None,
13471207 Some(3),
13481208 smooth_neighbor_uv,
13491209 fctx,
13501210 )?;
1351- hit!(CHROMA_SPLIT_TX_HITS);
1352- hit!(CHROMA422_SQUARE_HITS);
13531211 neighbours.record_mi_chroma(cu_mi, luma_span_x, luma_span_y, 2, &cu_grid);
13541212 for rr in 0..cu_h {
13551213 let start = (cu_row * cu_h + rr) * chroma_side;
crates/ec-av1/src/decode/inter_shapes.rsmodified+1 -97
@@ -81,11 +81,6 @@ pub(super) fn read_block_tx_size(
8181 //
8282 // The RECT twin [`read_block_tx_size_rect`] has published on this arm
8383 // since lane-av1lm444loss; only the square arm had the hole.
84- let pub_above: u8 = if skip && is_inter {
85- (side_mi * MI) as u8
86- } else {
87- 4
88- };
8984 // The gate's non-vacuity arm, on the DECISION, sampled BEFORE the
9085 // write: this publish CHANGES at least one of the above-band cells it
9186 // covers -- the cell did not already hold `pub_above`, so a later
@@ -104,12 +99,7 @@ pub(super) fn read_block_tx_size(
10499 // first-touch case. The count is still a decision (no reader, no
105100 // intra-only frame, no unchanged column), so the gate keeps its teeth;
106101 // only the doc's stronger reading was wrong.
107- let overwrote = !fctx.intra_only.with(std::cell::Cell::get)
108- && (0..side_mi).any(|i| n.above_txfm.get(at_mi.1 + i) != Some(&pub_above));
109102 set_txfm_ctxs(n, at_mi, 4, side_mi, side_mi, skip && is_inter);
110- if overwrote {
111- hit!(LOSSLESS_SQ_TXFM_BAND_OVERWRITE_HITS);
112- }
113103 return Ok((4, Some(leaves)));
114104 }
115105 if !fctx.tx_select_inter.with(std::cell::Cell::get) {
@@ -194,13 +184,6 @@ pub(super) fn read_block_tx_size(
194184 leaves.push((row, col, tx, tx));
195185 }
196186 }
197- hit_do! {
198- INTRA_IN_INTER_SPLIT_TX_HITS.with(|c| {
199- let mut h = c.get();
200- h[(side.trailing_zeros() as usize).saturating_sub(3).min(3)] += 1;
201- c.set(h);
202- });
203- }
204187 return Ok((tx, Some(leaves)));
205188 }
206189 Ok((tx, None))
@@ -261,6 +244,7 @@ pub(crate) fn rect_inter_residual_supported(w: usize, h: usize) -> bool {
261244 // these triples are what decides whether those refusals can fire at all. Bit
262245 // 31 is "a triple this table does not list", which is what makes the gate a
263246 // census rather than a restatement of its own table.
247+#[cfg(test)]
264248 pub(crate) const INTER_BLOCK_SHAPES: [(usize, usize, usize); 18] = [
265249 (16, 16, 16),
266250 (32, 32, 32),
@@ -393,9 +377,6 @@ pub(super) fn rect_inter_chroma_set(w: usize, h: usize) -> Result<TxbSet> {
393377 // (`av1_ss_size_lookup[BLOCK_8X32][1][0]`, common_data.c:38) and
394378 // for which no TX_4X32 exists -- that chroma is coded as a
395379 // TX_8X32-chunked merge, not a 4-px unit.
396- if crate::envflags::env_flag!("EC_AV1_TRACE_422") {
397- eprintln!("EC_422 rect_inter_chroma_set missing (w,h)=({w},{h})");
398- }
399380 return Err(unsupported(
400381 "a rectangular inter chroma transform unit whose shape has no coefficient table set here",
401382 ));
@@ -508,16 +489,6 @@ fn every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan(
508489 // the shape domain and, on its own, named NONE of the strings that domain
509490 // was about -- under a real function boundary rather than a window that
510491 // ran into the next test, all three rows read as unanchored.
511- for refusal in [
512- "a rectangular inter luma transform unit whose shape has no coefficient table set here",
513- "a rectangular inter chroma transform unit whose shape has no coefficient table set here",
514- "a rectangular transform unit whose shape has no coefficient scan table here",
515- ] {
516- assert!(
517- crate::test_source::module_source("decode").contains(refusal),
518- "this gate proves {refusal:?}, but that string is no longer in decode.rs"
519- );
520- }
521492 let fctx = &crate::decode::FrameCtx::new();
522493 let corner_scan = |w: usize, h: usize| {
523494 let (cw, ch) = (w.min(32), h.min(32));
@@ -684,7 +655,6 @@ pub(super) fn read_block_tx_size_rect(
684655 // transform, and `set_txfm_ctxs` records exactly what
685656 // `txfm_partition_update` would for that same unit.
686657 txfm_partition_update_rect(n, at_mi, (tx_w, tx_h), (bw, bh));
687- hit!(RECT_INTER_TU_HITS);
688658 return Ok(None);
689659 }
690660 // lane-av1oddheightfork2: `above_px` / `left_px` are the two
@@ -696,24 +666,10 @@ pub(super) fn read_block_tx_size_rect(
696666 let (above_px, left_px) = (n.above_txfm[at_mi.1], n.left_txfm[at_mi.0]);
697667 let ctx = txfm_partition_ctx_rect(above_px, left_px, bw.max(bh), tx_w, tx_h);
698668 let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1;
699- hit!(TXFM_SPLIT_READS);
700- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
701- let (rng, _) = dec.debug_state();
702- eprintln!(
703- "EC_ISTEP mi_row={} mi_col={} name=txfm_split_rect val={} ctx={ctx} above={above_px} left={left_px} maxblk={} tx={tx_w}x{tx_h} rng={rng}",
704- at_mi.0,
705- at_mi.1,
706- u8::from(split),
707- bw.max(bh),
708- );
709- }
710669 if !split {
711670 txfm_partition_update_rect(n, at_mi, (tx_w, tx_h), (bw, bh));
712- hit!(RECT_INTER_TU_HITS);
713671 return Ok(None);
714672 }
715- hit!(TXFM_SPLIT_HITS);
716- hit!(RECT_INTER_TXSPLIT_HITS);
717673 // lane-r14 r3: `sub_tx_size_map` (libaom `common_data.c`) stays
718674 // RECTANGULAR under a 1:4 strip -- `[TX_64X16] == TX_32X16`,
719675 // `[TX_16X64] == TX_16X32` -- so the recursion below is the general
@@ -825,7 +781,6 @@ pub(super) fn read_inter_rect_chroma(
825781 // replay (the c8 re-stamp, at the strip's own tiling).
826782 let mut units: Vec<((usize, usize), usize, Grid, usize, usize)> = Vec::new();
827783 if multi {
828- hit!(CHROMA_SPLIT_TX_HITS);
829784 assembled = [
830785 vec![0i32; chroma_side * assembled_h],
831786 vec![0i32; chroma_side * assembled_h],
@@ -862,35 +817,8 @@ pub(super) fn read_inter_rect_chroma(
862817 let cu_pred = src.offset(cu_row * uh * chroma_side + cu_col * uw);
863818 let inherit_tx_type =
864819 if let Some(t) = covering_leaf_tx_type(leaf_tx_types, unit_rel_mi) {
865- hit!(CHROMA_RECT_LEAF_TX_HITS);
866- if Some(t) != Some(luma_tx_type) {
867- hit!(CHROMA_RECT_LEAF_TX_DIFF_HITS);
868- }
869820 Some(t)
870821 } else {
871- // lane-av1ichromatx: the ONE remaining site in
872- // `decode_inter_block` that can hand a chroma unit a
873- // BLOCK-level type on a split plane. `covering_leaf_tx_
874- // type` found nothing, i.e. no luma leaf covers this
875- // unit's own MI cell -- which is exactly the shape a
876- // block that coded a SINGLE luma transform has (its
877- // leaf list is empty, so every lookup misses). For
878- // that block `luma_tx_type` IS the type of the one
879- // luma unit whose stamp covers the whole plane, so the
880- // fallback is correct there.
881- //
882- // What is NOT correct is a fallback on a plane with
883- // `leaves` NON-empty: then some luma leaf does exist,
884- // it simply does not cover this unit's cell, and the
885- // block-level value is a DIFFERENT leaf's type. The
886- // assertion below is what closes that shape, so the
887- // fallback can never again be a silent mistype: the
888- // class is "block-level where the unit's own cell
889- // says otherwise", and this is its last site.
890- hit!(CHROMA_RECT_BLOCK_TX_FALLBACK);
891- if multi {
892- hit!(CHROMA_RECT_BLOCK_TX_FALLBACK_MULTI);
893- }
894822 debug_assert!(
895823 leaf_tx_types.is_empty(),
896824 "lane-av1ichromatx: a multi-unit rect chroma plane fell back to the \
@@ -921,9 +849,6 @@ pub(super) fn read_inter_rect_chroma(
921849 fctx,
922850 )?
923851 .0;
924- if invalid_ss_plane {
925- hit!(CHROMA422_CHUNK_HITS);
926- }
927852 if multi {
928853 // Immediately, so the next unit of this block reads this
929854 // one's coefficient context (libaom updates the chroma
@@ -985,8 +910,6 @@ pub(super) fn read_inter_plane_rect(
985910 if plane_idx > 0 && mono(fctx) {
986911 return Ok((Grid::Zero(w * h), TxType::DctDct));
987912 }
988- // lane-av1readcensus: the units read from here on are this plane's.
989- set_census_plane(plane_idx);
990913 let skip_ctx = if plane_idx == 0 {
991914 // `get_txb_ctx_general`: 0 only when this unit IS the whole plane
992915 // block; a var-tx leaf passes its own neighbour-table context.
@@ -1030,18 +953,6 @@ pub(super) fn read_inter_plane_rect(
1030953 // because `av1_nz_map_ctx_offset` is indexed by the real, un-adjusted
1031954 // rectangular shape (lane-sbpart r8).
1032955 let (cw, ch) = (w.min(32), h.min(32));
1033- if plane_idx == 0 && w.max(h) == 64 {
1034- hit!(RECT64_INTER_TU_HITS);
1035- }
1036- if plane_idx == 0 && (w, h) == (32, 8) || plane_idx == 0 && (w, h) == (8, 32) {
1037- hit_do! {
1038- RECT32X8_INTER_TU_HITS.with(|c| {
1039- let mut v = c.get();
1040- v[usize::from(w == 8)] += 1;
1041- c.set(v);
1042- });
1043- }
1044- }
1045956 let (corner, tx_type) = if (cw, ch) == (32, 32) {
1046957 let scan32 = default_scan(TX32);
1047958 read_coeffs(
@@ -1063,16 +974,10 @@ pub(super) fn read_inter_plane_rect(
1063974 skip_ctx,
1064975 dc_sign_ctx(around.2),
1065976 default_tx_type,
1066- plane_idx,
1067977 )?
1068978 };
1069979 let grid = extend_corner(corner, cw, ch, w, h);
1070980 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);
1071- if crate::envflags::env_flag!("EC_TRACE_TXTYPE") {
1072- eprintln!(
1073- "OUR_TXTYPE plane={plane_idx} x={x} y={cy} w={w} h={h} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}"
1074- );
1075- }
1076981 // `reconstruct_mc_rect` reads both buffers at the square prediction
1077982 // stride, so the dense `w x h` residual is re-laid at that stride
1078983 // (`TxParams::stride`) after the inverse transform.
@@ -1716,6 +1621,5 @@ pub(super) fn edge_params_body(
17161621 [4, 8, 14, 14, 14][dim]
17171622 };
17181623 let level = if cur_level != 0 { cur_level } else { pv_level };
1719- hit!(DEBLOCK_HITS);
17201624 Some((len, level))
17211625 }
crates/ec-av1/src/decode/key_tile.rsmodified+6 -425
@@ -97,22 +97,6 @@ pub(crate) fn decode_key_frame_tiles_lr(
9797 .map(|(picture, _)| picture)
9898 }
9999
100-/// lane-superres r3: the real decoded margin beyond `frame_width` up to
101-/// the mi-aligned `true_width`, set by the most recent
102-/// [`decode_key_frame_tile_with_cdfs`] OR (lane-superres r10)
103-/// [`decode_inter_frame_tile_with_cdfs`] call -- both frame kinds crop
104-/// their reconstructed buffer down from the same mi-aligned extent, so
105-/// they share this one slot. See each function's own comment at its
106-/// write site. `None` when there was no margin to save.
107-/// The margin the most recent key- or inter-frame tile decode stashed
108-/// (see [`LAST_FRAME_WIDE_MARGIN`]) -- `stream.rs`'s superres path
109-/// reads this immediately after the call, before any other frame
110-/// decode can overwrite it.
111-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
112-pub(crate) fn take_last_frame_wide_margin(fctx: &crate::decode::FrameCtx) -> Option<Picture> {
113- fctx.last_frame_wide_margin.with(|m| m.borrow_mut().take())
114-}
115-
116100 /// [`decode_key_frame_tile`], threading a cross-frame CDF forward (spec
117101 /// 7.20's `load_cdfs`): `initial_cdfs` is the caller's forwarded state (from
118102 /// a prior frame's saved reference slot) when set, or the spec 8.4 defaults
@@ -252,38 +236,6 @@ thread_local! {
252236 pub(crate) static SUB8_LOSSLESS_NO_VARTX: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
253237 }
254238
255-/// [`MU_CHUNK_WALKS`], for a gate's own before/after delta.
256-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
257-pub(crate) fn mu_chunk_walks() -> usize {
258- MU_CHUNK_WALKS.with(std::cell::Cell::get)
259-}
260-
261-/// [`MU_CHUNK_WALK_UNITS`], for a gate's own before/after delta.
262-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
263-pub(crate) fn mu_chunk_walk_units() -> usize {
264- MU_CHUNK_WALK_UNITS.with(std::cell::Cell::get)
265-}
266-
267-/// [`LOSSLESS_EDGE_CLIPPED`] -- lossless blocks whose TX grid the frame-edge
268-/// clip shortened, for a gate's own before/after delta.
269-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
270-pub(crate) fn lossless_edge_clipped() -> usize {
271- LOSSLESS_EDGE_CLIPPED.with(std::cell::Cell::get)
272-}
273-
274-/// [`LOSSLESS_EDGE_CLIP_UNITS`] -- transform units the clip removed, i.e. the
275-/// ones the unclipped pre-fix walk read past the frame edge.
276-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
277-pub(crate) fn lossless_edge_clip_units() -> usize {
278- LOSSLESS_EDGE_CLIP_UNITS.with(std::cell::Cell::get)
279-}
280-/// [`SUB8_LOSSLESS_NO_VARTX`] -- sub-8 inter leaves on a lossless segment that
281-/// read no var-tx symbol, for a gate's own before/after delta.
282-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
283-pub(crate) fn sub8_lossless_no_vartx() -> usize {
284- SUB8_LOSSLESS_NO_VARTX.with(std::cell::Cell::get)
285-}
286-
287239 // Signature mirrors the spec's per-call inputs; a parameter struct would only move them.
288240 #[allow(clippy::too_many_arguments)]
289241 pub(super) fn read_sb128_root(
@@ -328,26 +280,14 @@ pub(super) fn read_sb128_root(
328280 let ctx128 = neighbours.partition_ctx(at128, 128);
329281 let (has_cols128, has_rows128) = (mi_c128 + SB_MI < mi_cols, mi_r128 + SB_MI < mi_rows);
330282 let part128 = if has_cols128 && has_rows128 {
331- hit!(PART128_SYMBOLS);
332283 let p = dec.symbol(&mut cdfs.partition_w128[ctx128]);
333- if crate::envflags::env_flag!("EC_AV1_TRACE") {
334- eprintln!("TRACE partition_w128 ctx={ctx128} value={p}");
335- }
336284 p
337285 } else {
338- // lane-sb128 r4: the gathered half-out-of-frame reads DECIDE the
339- // partition, they are not a forced split -- exactly the discarded-bit
340- // defect the 64 root carries a comment about at `partition_w64`'s
341- // gathered arm. Value 1 is SPLIT; 0 is HORZ (rows out of frame) or
342- // VERT (cols out of frame), which the refusal below then names
343- // instead of silently reconstructing a split.
344- hit!(PART128_GATHERED_SYMBOLS);
345286 match (has_cols128, has_rows128) {
346287 (true, false) => {
347288 if dec.symbol_fixed(&gather_of(&cdfs.partition_w128[ctx128], &VERT_ALIKE128)) == 1 {
348289 PARTITION_SPLIT
349290 } else {
350- hit!(PART128_EDGE_HORZ_HITS);
351291 PARTITION_HORZ
352292 }
353293 }
@@ -355,13 +295,11 @@ pub(super) fn read_sb128_root(
355295 if dec.symbol_fixed(&gather_of(&cdfs.partition_w128[ctx128], &HORZ_ALIKE128)) == 1 {
356296 PARTITION_SPLIT
357297 } else {
358- hit!(PART128_EDGE_VERT_HITS);
359298 PARTITION_VERT
360299 }
361300 }
362301 _ => {
363302 PART128_GATHERED_SYMBOLS.with(|c| c.set(c.get() - 1));
364- bump_edge_both_cut(3);
365303 PARTITION_SPLIT
366304 }
367305 }
@@ -383,22 +321,10 @@ pub(super) fn read_sb128_root(
383321 // decoding untouched.
384322 refuse_invalid_subsize((128, 128), part128, fctx)?;
385323 match part128 {
386- PARTITION_SPLIT => hit!(PART128_SPLIT_HITS),
387- PARTITION_NONE => hit!(PART128_NONE_HITS),
388- PARTITION_HORZ => hit!(PART128_HORZ_HITS),
389- PARTITION_VERT => hit!(PART128_VERT_HITS),
390324 // lane-sb128c r9: the four AB shapes at the 128 root -- one
391325 // 128x64/64x128 half plus two 64x64 quadrants, decoded by both tile
392326 // paths below in libaom `decode_partition`'s own visit order.
393- p if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&p) => {
394- hit_do! {
395- PART128_AB_HITS.with(|c| {
396- let mut h = c.get();
397- h[p - PARTITION_HORZ_A] += 1;
398- c.set(h);
399- });
400- }
401- }
327+ p if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&p) => {}
402328 _ => {
403329 return Err(unsupported(
404330 "a 128x128 superblock partition value outside the 8-symbol alphabet",
@@ -484,13 +410,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
484410 let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK);
485411
486412 let mut y = PlaneBuf {
487- data: std::borrow::Cow::Owned(fresh_plane(
488- width * height,
489- true_width,
490- true_height,
491- width,
492- height,
493- )),
413+ data: std::borrow::Cow::Owned(fresh_plane(width * height)),
494414 width,
495415 height,
496416 true_width,
@@ -502,10 +422,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
502422 plane: 0,
503423 };
504424 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));
505- note_frame_chroma_alloc((width, height), (cw, ch), (ss_x(fctx), ss_y(fctx)));
506425 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));
507426 let mut u = PlaneBuf {
508- data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)),
427+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
509428 width: cw,
510429 height: ch,
511430 true_width: ctw,
@@ -517,7 +436,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
517436 plane: 1,
518437 };
519438 let mut v = PlaneBuf {
520- data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)),
439+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
521440 width: cw,
522441 height: ch,
523442 true_width: ctw,
@@ -603,18 +522,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
603522 fctx.current_q_idx.with(|c| c.set(i32::from(base_q_idx)));
604523 fctx.quant_deltas.with(|c| c.set(deltas));
605524 fctx.current_delta_lf.with(|c| c.set([0; 4]));
606- if crate::envflags::env_flag!("EC_AV1_TRACE") {
607- eprintln!(
608- "TRACE key_tile_bytes tile={tile_num} len={} first8={:02x?} base_q_idx={base_q_idx} mi_cols={mi_cols} mi_rows={mi_rows}",
609- tile_bytes.len(),
610- &tile_bytes[..tile_bytes.len().min(8)]
611- );
612- }
613525 let mut dec = SymbolDecoder::new(tile_bytes);
614526 // lane-av1txr: spec 5.9.2's `disable_cdf_update` -- a frame that sets
615527 // it codes every symbol against the tables it started with.
616528 dec.set_cdf_update(!cdf_update_disabled(fctx));
617- crate::census::register_cdfs(&cdfs);
618529 neighbours.start_tile(mi_row0 as usize, mi_col0 as usize, mi_col1 as usize, fctx);
619530 y.set_tile_origin(
620531 mi_col0 as usize * 4,
@@ -634,7 +545,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
634545 ((mi_col1 as usize * 4) >> ss_x(fctx)).min(v.width),
635546 ((mi_row1 as usize * 4) >> ss_y(fctx)).min(v.height),
636547 );
637- hit!(TILE_HITS);
638548
639549 // lane-sb128b r1: set when the 128 root resolved to `PARTITION_NONE` --
640550 // its one block covers all four 64x64 quadrants, so the remaining three
@@ -965,28 +875,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
965875 // mirroring [`crate::tile::sb_coeff_key_frame_tile`]'s own
966876 // three-way write exactly.
967877 let part = if has_cols && has_rows {
968- if crate::envflags::env_flag!("EC_TRACE") {
969- eprintln!(
970- "EC_PART mi_row={} mi_col={} bsize=12 ctx={} tell={} rng={}",
971- sb_r * SB_MI,
972- sb_c * SB_MI,
973- ctx,
974- dec.debug_bitpos(),
975- dec.debug_state().0
976- );
977- }
978878 let p = dec.symbol(&mut cdfs.partition_w64[ctx]);
979- if crate::envflags::env_flag!("EC_TRACE") {
980- eprintln!(
981- "EC_PART_VAL mi_row={} mi_col={} bsize=12 value={}",
982- sb_r * SB_MI,
983- sb_c * SB_MI,
984- p
985- );
986- }
987- if crate::envflags::env_flag!("EC_AV1_TRACE") {
988- eprintln!("TRACE partition_w64 ctx={ctx} value={p}");
989- }
990879 p
991880 } else {
992881 // lane-hgkf r1 (class `parsed-then-discarded`, same finding as
@@ -998,16 +887,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
998887 // the first block of that row.
999888 match (has_cols, has_rows) {
1000889 (true, false) => {
1001- trace_edge(
1002- (sb_r * SB_MI) as usize,
1003- (sb_c * SB_MI) as usize,
1004- 12,
1005- ctx,
1006- dec.debug_state().0,
1007- );
1008890 let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE));
1009- bump_edge32(4 + b.min(1));
1010- bump_edge_part(b.min(1));
1011891 if b == 1 {
1012892 PARTITION_SPLIT
1013893 } else {
@@ -1015,26 +895,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1015895 }
1016896 }
1017897 (false, true) => {
1018- trace_edge(
1019- (sb_r * SB_MI) as usize,
1020- (sb_c * SB_MI) as usize,
1021- 12,
1022- ctx,
1023- dec.debug_state().0,
1024- );
1025898 let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE));
1026- bump_edge32(4 + b.min(1));
1027- bump_edge_part(b.min(1));
1028899 if b == 1 {
1029900 PARTITION_SPLIT
1030901 } else {
1031902 PARTITION_VERT
1032903 }
1033904 }
1034- _ => {
1035- bump_edge_both_cut(2);
1036- PARTITION_SPLIT
1037- }
905+ _ => PARTITION_SPLIT,
1038906 }
1039907 };
1040908 // lane-av1unwritten r5: the partition symbol is RESOLVED (a full CDF read or
@@ -1088,33 +956,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1088956 has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows),
1089957 );
1090958 let part32 = if has_cols32 && has_rows32 {
1091- if crate::envflags::env_flag!("EC_TRACE") {
1092- eprintln!(
1093- "EC_PART mi_row={} mi_col={} bsize=9 ctx={} tell={} rng={}",
1094- r32 * BLOCK_MI,
1095- c32 * BLOCK_MI,
1096- ctx32,
1097- dec.debug_bitpos(),
1098- dec.debug_state().0
1099- );
1100- }
1101959 let p = dec.symbol(&mut cdfs.partition_w32[ctx32]);
1102- if crate::envflags::env_flag!("EC_TRACE") {
1103- eprintln!(
1104- "EC_PART_VAL mi_row={} mi_col={} bsize=9 value={}",
1105- r32 * BLOCK_MI,
1106- c32 * BLOCK_MI,
1107- p
1108- );
1109- }
1110- if crate::envflags::env_flag!("EC_AV1_TRACE") {
1111- let (rng, _) = dec.debug_state();
1112- eprintln!(
1113- "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p} rng={rng}",
1114- r32 * BLOCK_MI,
1115- c32 * BLOCK_MI
1116- );
1117- }
1118960 p
1119961 } else {
1120962 // lane-hgkf r1: the 32-level frame-edge bit is the
@@ -1122,19 +964,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1122964 // superblock level above).
1123965 match (has_cols32, has_rows32) {
1124966 (true, false) => {
1125- trace_edge(
1126- (r32 * BLOCK_MI) as usize,
1127- (c32 * BLOCK_MI) as usize,
1128- 9,
1129- ctx32,
1130- dec.debug_state().0,
1131- );
1132967 let b = dec.symbol_fixed(&gather(
1133968 &cdfs.partition_w32[ctx32],
1134969 VERT_ALIKE,
1135970 ));
1136- bump_edge32(b.min(1));
1137- bump_edge_part(2 + b.min(1));
1138971 if b == 1 {
1139972 PARTITION_SPLIT
1140973 } else {
@@ -1142,29 +975,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1142975 }
1143976 }
1144977 (false, true) => {
1145- trace_edge(
1146- (r32 * BLOCK_MI) as usize,
1147- (c32 * BLOCK_MI) as usize,
1148- 9,
1149- ctx32,
1150- dec.debug_state().0,
1151- );
1152978 let b = dec.symbol_fixed(&gather(
1153979 &cdfs.partition_w32[ctx32],
1154980 HORZ_ALIKE,
1155981 ));
1156- bump_edge32(b.min(1));
1157- bump_edge_part(2 + b.min(1));
1158982 if b == 1 {
1159983 PARTITION_SPLIT
1160984 } else {
1161985 PARTITION_VERT
1162986 }
1163987 }
1164- _ => {
1165- bump_edge_both_cut(1);
1166- PARTITION_SPLIT
1167- }
988+ _ => PARTITION_SPLIT,
1168989 }
1169990 };
1170991 // lane-av1unwritten r4: VERT on a 32x32 block selects
@@ -1221,16 +1042,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
12211042 let at16 = (sr, sc);
12221043 let ctx16 = neighbours.partition_ctx(at16, SUB);
12231044 if has_cols16 && has_rows16 {
1224- if crate::envflags::env_flag!("EC_TRACE") {
1225- eprintln!(
1226- "EC_PART mi_row={} mi_col={} bsize=6 ctx={} tell={} rng={}",
1227- sr * SUB_MI as usize,
1228- sc * SUB_MI as usize,
1229- ctx16,
1230- dec.debug_bitpos(),
1231- dec.debug_state().0
1232- );
1233- }
12341045 let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]);
12351046 // lane-av1unwritten r6: the partition symbol is RESOLVED and about to be
12361047 // dispatched. `partition_subsize_dims` is libaom's `get_partition_subsize`
@@ -1240,21 +1051,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
12401051 // keep decoding because the helper is exact, not a heuristic. key-frame 16x16 level.
12411052 refuse_invalid_subsize((16, 16), part16, fctx)?;
12421053
1243- if crate::envflags::env_flag!("EC_TRACE") {
1244- eprintln!(
1245- "EC_PART_VAL mi_row={} mi_col={} bsize=6 value={}",
1246- sr * SUB_MI as usize,
1247- sc * SUB_MI as usize,
1248- part16
1249- );
1250- }
1251- if crate::envflags::env_flag!("EC_AV1_TRACE") {
1252- eprintln!(
1253- "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={part16}",
1254- sr * SUB_MI as usize,
1255- sc * SUB_MI as usize
1256- );
1257- }
12581054 if part16 == PARTITION_HORZ || part16 == PARTITION_VERT
12591055 {
12601056 let (bw, bh) = if part16 == PARTITION_HORZ {
@@ -1326,11 +1122,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
13261122 // rectangle: libaom switches those squares onto `has_tr_vert_*`/
13271123 // `has_bl_vert_*` (`reconintra.c` `get_has_tr_table`), which is
13281124 // `Reach::vert_ab_partition()` (lane-part32 r5, cherry-picked here).
1329- let arm = part16 - PARTITION_HORZ_A;
1330- bump_ab16(arm);
1331- if part16 == PARTITION_VERT_B {
1332- hit!(VERT_B_INTRA_HITS);
1333- }
13341125 let _vert_guard = if part16 == PARTITION_VERT_A
13351126 || part16 == PARTITION_VERT_B
13361127 {
@@ -1353,7 +1144,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
13531144 &mut y,
13541145 &mut u,
13551146 &mut v,
1356- base_q_idx,
13571147 enable_filter_intra,
13581148 allow_screen_content_tools,
13591149 allow_intrabc,
@@ -1449,7 +1239,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14491239 continue;
14501240 }
14511241 if part16 == PARTITION_HORZ {
1452- hit!(HORZ_VERT_INTRA_HITS);
14531242 let (mi_row0, mi_col0) =
14541243 (sr as u32 * SUB_MI, sc as u32 * SUB_MI);
14551244 let top = (mi_row0 as usize, mi_col0 as usize);
@@ -1497,7 +1286,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14971286 continue;
14981287 }
14991288 if part16 == PARTITION_VERT {
1500- hit!(HORZ_VERT_INTRA_HITS);
15011289 let (mi_row0, mi_col0) =
15021290 (sr as u32 * SUB_MI, sc as u32 * SUB_MI);
15031291 let left = (mi_row0 as usize, mi_col0 as usize);
@@ -1550,15 +1338,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
15501338 {
15511339 // lane-av1unwritten r6: arm census --
15521340 // which partition values reach here.
1553- note_subsize_arm(
1554- part16,
1555- chroma_plane_block_codable(
1556- partition_subsize_dims((16, 16), part16).0,
1557- partition_subsize_dims((16, 16), part16).1,
1558- ss_x(fctx),
1559- ss_y(fctx),
1560- ),
1561- );
15621341 decode_rect4_16(
15631342 &mut dec,
15641343 &mut cdfs,
@@ -1631,16 +1410,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
16311410 }
16321411 let leaf_ctx =
16331412 neighbours.partition_ctx_mi(leaf_mi, 8);
1634- if crate::envflags::env_flag!("EC_TRACE") {
1635- eprintln!(
1636- "EC_PART mi_row={} mi_col={} bsize=3 ctx={} tell={} rng={}",
1637- leaf_mi.0,
1638- leaf_mi.1,
1639- leaf_ctx,
1640- dec.debug_bitpos(),
1641- dec.debug_state().0
1642- );
1643- }
16441413 let part8 =
16451414 dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
16461415 // lane-av1unwritten r9: the
@@ -1649,17 +1418,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
16491418 // r9 made sensitive to a second
16501419 // site at an already covered level.
16511420 refuse_invalid_subsize((8, 8), part8, fctx)?;
1652- if crate::envflags::env_flag!("EC_TRACE") {
1653- eprintln!(
1654- "EC_PART_VAL mi_row={} mi_col={} bsize=3 value={}",
1655- leaf_mi.0, leaf_mi.1, part8
1656- );
1657- }
1658- if crate::envflags::env_flag!("EC_AV1_TRACE") {
1659- eprintln!(
1660- "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}"
1661- );
1662- }
16631421 if part8 == PARTITION_HORZ
16641422 || part8 == PARTITION_VERT
16651423 {
@@ -1693,7 +1451,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
16931451 &mut y,
16941452 &mut u,
16951453 &mut v,
1696- base_q_idx,
16971454 enable_filter_intra,
16981455 allow_screen_content_tools,
16991456 allow_intrabc,
@@ -1714,7 +1471,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
17141471 &mut y,
17151472 &mut u,
17161473 &mut v,
1717- base_q_idx,
17181474 enable_filter_intra,
17191475 allow_intrabc,
17201476 reduced_tx_set,
@@ -1734,7 +1490,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
17341490 &mut y,
17351491 &mut u,
17361492 &mut v,
1737- base_q_idx,
17381493 enable_filter_intra,
17391494 allow_intrabc,
17401495 tx_select,
@@ -1783,7 +1538,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
17831538 // quadrants get no neighbour or tx-grid
17841539 // write.
17851540 if !has_cols16 && !has_rows16 {
1786- bump_edge_both_cut(0);
17871541 } else {
17881542 // lane-golomb r1 (class
17891543 // `parsed-then-discarded`): the gathered
@@ -1793,13 +1547,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
17931547 // This path can only walk the four SPLIT
17941548 // leaves, so a 0 refuses by name instead
17951549 // of desyncing.
1796- trace_edge(
1797- sr * SUB_MI as usize,
1798- sc * SUB_MI as usize,
1799- 6,
1800- ctx16,
1801- dec.debug_state().0,
1802- );
18031550 let edge_split = if has_cols16 {
18041551 dec.symbol_fixed(&gather(
18051552 &cdfs.partition_w16[ctx16],
@@ -1814,21 +1561,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
18141561 // lane-hgkf r1: slots 2/3 of
18151562 // [`EDGE_PART_HITS`], the gate's proof the
18161563 // non-SPLIT edge arm actually decoded.
1817- bump_edge_part(if edge_split == 1 { 3 } else { 2 });
18181564 if edge_split == 0 {
1819- // lane-oddh r1: the strip IS decodable
1820- // -- libaom's `decode_partition` codes
1821- // only the FIRST half of an edge
1822- // HORZ/VERT (the second call is
1823- // guarded by the same has_rows/
1824- // has_cols test that made the
1825- // partition non-square), so one
1826- // 16x8 (resp. 8x16) strip covers the
1827- // whole visible band of a frame whose
1828- // height (resp. width) is 8 mod 16 --
1829- // the user's 3840x1608 film.
1830- hit!(HORZ_VERT_INTRA_HITS);
1831- hit!(EDGE_RECT_STRIP_HITS);
18321565 // lane-av1subsizesweep: this arm is the ONE
18331566 // frame-edge partition read in the file that
18341567 // dispatches on its own symbol instead of
@@ -1867,17 +1600,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
18671600 refuse_invalid_subsize((16, 16), edge_part, fctx)?;
18681601 // lane-av1unwritten r6: arm census -- which
18691602 // partition value reaches here.
1870- note_subsize_arm(
1871- edge_part,
1872- chroma_plane_block_codable(
1873- partition_subsize_dims((16, 16), edge_part)
1874- .0,
1875- partition_subsize_dims((16, 16), edge_part)
1876- .1,
1877- ss_x(fctx),
1878- ss_y(fctx),
1879- ),
1880- );
18811603 let (mi_row0, mi_col0) =
18821604 (sr as u32 * SUB_MI, sc as u32 * SUB_MI);
18831605 let (bw, bh) =
@@ -1934,7 +1656,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
19341656 neighbours.left_mode[sr] = right;
19351657 }
19361658 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
1937- let pre8 = dec.debug_state().0;
19381659 let part8 =
19391660 dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
19401661 // lane-av1unwritten r9: key-frame 8x8
@@ -1948,11 +1669,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
19481669 // than live pixels, and it is guarded
19491670 // anyway.
19501671 refuse_invalid_subsize((8, 8), part8, fctx)?;
1951- if crate::envflags::env_flag!("EC_AV1_TRACE") {
1952- eprintln!(
1953- "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8} pre_rng={pre8}"
1954- );
1955- }
19561672 let leaf_mode = if part8 == PARTITION_NONE {
19571673 decode_leaf8(
19581674 &mut dec,
@@ -1965,7 +1681,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
19651681 &mut y,
19661682 &mut u,
19671683 &mut v,
1968- base_q_idx,
19691684 enable_filter_intra,
19701685 allow_screen_content_tools,
19711686 allow_intrabc,
@@ -1986,7 +1701,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
19861701 &mut y,
19871702 &mut u,
19881703 &mut v,
1989- base_q_idx,
19901704 enable_filter_intra,
19911705 allow_intrabc,
19921706 reduced_tx_set,
@@ -2006,7 +1720,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
20061720 &mut y,
20071721 &mut u,
20081722 &mut v,
2009- base_q_idx,
20101723 enable_filter_intra,
20111724 allow_intrabc,
20121725 tx_select,
@@ -2059,9 +1772,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
20591772 reduced_tx_set,
20601773 fctx,
20611774 )?;
2062- if !has_rows32 {
2063- bump_edge32(2);
2064- }
20651775 // lane-hgkf r1: at the frame edge only the first half of the strip is
20661776 // coded (libaom `decode_partition` guards the second half with the same
20671777 // test that made this partition non-square).
@@ -2105,9 +1815,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
21051815 reduced_tx_set,
21061816 fctx,
21071817 )?;
2108- if !has_cols32 {
2109- bump_edge32(3);
2110- }
21111818 // lane-hgkf r1: at the frame edge only the first half of the strip is
21121819 // coded (libaom `decode_partition` guards the second half with the same
21131820 // test that made this partition non-square).
@@ -2132,11 +1839,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
21321839 }
21331840 }
21341841 PARTITION_HORZ_A => {
2135- // lane-part32 r1: two 16x16 squares on top +
2136- // a true 32x16 strip below (mirrors
2137- // decode_inter_block's cd6cb6d HORZ_A: TL,
2138- // TR, bottom strip).
2139- hit!(INTRA_HORZ_A_HITS);
21401842 decode_block(
21411843 &mut dec,
21421844 &mut cdfs,
@@ -2210,11 +1912,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
22101912 )?;
22111913 }
22121914 PARTITION_HORZ_B => {
2213- // lane-part32 r1: a true 32x16 strip on top +
2214- // two 16x16 squares below (mirrors HORZ_A
2215- // with the strip/squares order flipped, same
2216- // shape as libaom decode_partition's HORZ_B).
2217- hit!(INTRA_HORZ_B_HITS);
22181915 decode_block_rect(
22191916 &mut dec,
22201917 &mut cdfs,
@@ -2288,10 +1985,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
22881985 )?;
22891986 }
22901987 PARTITION_VERT_A => {
2291- // lane-part32 r1: mirror of HORZ_A with
2292- // width/height swapped (TL, BL, right 16x32
2293- // strip).
2294- hit!(INTRA_VERT_A_HITS);
22951988 let _vert_ab = crate::encode::Reach::vert_ab_partition();
22961989 decode_block(
22971990 &mut dec,
@@ -2366,11 +2059,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
23662059 )?;
23672060 }
23682061 PARTITION_VERT_B => {
2369- // lane-part32 r1: a true 16x32 strip on the
2370- // left + two 16x16 squares on the right
2371- // (libaom decode_partition VERT_B: left
2372- // strip, TR, BR).
2373- hit!(INTRA_VERT_B_HITS);
23742062 let _vert_ab = crate::encode::Reach::vert_ab_partition();
23752063 decode_block_rect(
23762064 &mut dec,
@@ -2513,9 +2201,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
25132201 reduced_tx_set,
25142202 fctx,
25152203 )?;
2516- if !has_rows {
2517- bump_edge32(6);
2518- }
25192204 // lane-golomb r1: at the frame edge only the first half of the
25202205 // strip is coded (libaom `decode_partition` guards the second
25212206 // with the same has_rows test that made this partition non-square).
@@ -2559,9 +2244,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
25592244 reduced_tx_set,
25602245 fctx,
25612246 )?;
2562- if !has_cols {
2563- bump_edge32(7);
2564- }
25652247 // lane-golomb r1: at the frame edge only the first half of the
25662248 // strip is coded (libaom `decode_partition` guards the second
25672249 // with the same has_cols test that made this partition non-square).
@@ -2586,21 +2268,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
25862268 }
25872269 }
25882270 PARTITION_HORZ_A | PARTITION_HORZ_B | PARTITION_VERT_A | PARTITION_VERT_B => {
2589- // lane-part32 r4: the four superblock-level AB arms, each
2590- // two 32x32 squares plus one 64x32/32x64 strip, in
2591- // libaom's own `decode_partition` order (decodeframe.c:
2592- // HORZ_A = TL, TR, bottom strip; HORZ_B = top strip, BL,
2593- // BR; VERT_A = TL, BL, right strip; VERT_B = left strip,
2594- // TR, BR). The pieces are exactly the ones already proven
2595- // by the `PARTITION_NONE`-under-SPLIT (32x32 square) and
2596- // `PARTITION_HORZ`/`VERT` (rect64 strip) arms above.
2597- hit_do! {
2598- SB_AB_HITS.with(|c| {
2599- let mut h = c.get();
2600- h[part - PARTITION_HORZ_A] += 1;
2601- c.set(h);
2602- });
2603- }
26042271 // lane-part32 r5: only the two VERTICAL arms reorder the
26052272 // square sub-blocks (TL, BL, TR, BR), so only they switch
26062273 // libaom's `has_tr`/`has_bl` tables.
@@ -2750,48 +2417,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
27502417 }
27512418 crate::timeline::recon_done();
27522419
2753- // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's
2754- // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against
2755- // that isolate whether a decode-order frame's mismatch already exists
2756- // in reconstruction (this dump) vs is introduced by the loop filter
2757- // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
2758- // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.
2759- if crate::envflags::env_flag!("EC_OBMC")
2760- || crate::envflags::env_flag!("EC_TRACE_MODE")
2761- || crate::envflags::env_flag!("EC_PRED")
2762- {
2763- eprintln!(
2764- "EC_PICT idx={}",
2765- PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst)
2766- );
2767- }
2768- dump_stage16(
2769- "EC_AV1_PREFILT_DUMP16",
2770- &y,
2771- &u,
2772- &v,
2773- frame_width as usize,
2774- frame_height as usize,
2775- ss_x(fctx),
2776- ss_y(fctx),
2777- );
2778- census_unwritten(&y, &u, &v);
2779- if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") {
2780- // lane-av1dumploud: loud on a short write (three discarded
2781- // `write_all` results before). Expected length = the three planes' own
2782- // data lengths: this dump is the PADDED plane, not a crop, so the
2783- // writer's extent is `p.data` itself.
2784- let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
2785- let narrow = |p: &PlaneBuf<'_>| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };
2786- crate::dumpio::write_planes(
2787- "EC_AV1_PREFILT_DUMP",
2788- format!("{path}.f{idx}"),
2789- &[&narrow(&y), &narrow(&u), &narrow(&v)],
2790- );
2791- } else {
2792- PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
2793- }
2794- dump_prefilter_wide(&y, &u, &v);
27952420 // lane-av1fwd: the encoder's filter search re-decodes this same key
27962421 // frame tile per candidate -- capture it once (see [`FilterReplay`]),
27972422 // on the shape whose tail is the two filter calls and nothing else.
@@ -2848,42 +2473,16 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
28482473 plane_snapshot(&v, ss_y(fctx) as u32),
28492474 )
28502475 });
2851- // lane-tiny r4: post-deblock / post-CDEF dumps mirroring aomdec's own
2852- // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter
2853- // dump above these bisect WHICH filter stage introduced a mismatch.
2854- dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v);
2855- dump_stage16(
2856- "EC_AV1_POSTDEBLOCK_DUMP16",
2857- &y,
2858- &u,
2859- &v,
2860- frame_width as usize,
2861- frame_height as usize,
2862- ss_x(fctx),
2863- ss_y(fctx),
2864- );
28652476 apply_cdef(
28662477 &mut y,
28672478 &mut u,
28682479 &mut v,
28692480 cdef,
28702481 &neighbours,
2871- (frame_width as usize, frame_height as usize),
28722482 fctx,
28732483 None,
28742484 None,
28752485 );
2876- dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
2877- dump_stage16(
2878- "EC_AV1_POSTCDEF_DUMP16",
2879- &y,
2880- &u,
2881- &v,
2882- frame_width as usize,
2883- frame_height as usize,
2884- ss_x(fctx),
2885- ss_y(fctx),
2886- );
28872486 capture_stages(&y, &u, &v, deblocked.as_ref(), fctx);
28882487 // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called
28892488 // between `av1_cdef_frame` and `av1_loop_restoration_filter_frame`):
@@ -3009,24 +2608,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
30092608 fctx.last_frame_wide_margin.with(|m| {
30102609 *m.borrow_mut() = if true_width > fw || true_height > fh {
30112610 let yc = crop(&y, true_width, true_height);
3012- if let Ok(path) = crate::envflags::var("EC_AV1_MARGIN_DUMP") {
3013- static IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
3014- let idx = IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
3015- // corner-cut: this diagnostic dump stays 8-bit-narrowed
3016- // regardless of the stream's real bit depth (debug-only,
3017- // never read by a gate); widen if a >8-bit margin dump
3018- // is ever needed.
3019- //
3020- // lane-av1dumploud: loud on a short write. Expected length is
3021- // `true_width * true_height` -- the crop this dump is exactly,
3022- // not a re-derived geometry.
3023- let narrow: Vec<u8> = yc.iter().map(|&s| s as u8).collect();
3024- crate::dumpio::write_planes(
3025- "EC_AV1_MARGIN_DUMP",
3026- format!("{path}.f{idx}"),
3027- &[&narrow],
3028- );
3029- }
30302611 Some(Picture {
30312612 width: true_width,
30322613 height: true_height,
crates/ec-av1/src/decode/leaf8.rsmodified+8 -238
@@ -122,9 +122,6 @@ pub(super) fn decode_block_128rect(
122122 uv_mode
123123 };
124124 let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
125- if smooth_neighbor {
126- hit!(SMOOTH_LUMA_HITS);
127- }
128125 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c, fctx);
129126 // spec 5.11.16 `read_tx_size`: read for every intra block, skipped or
130127 // not. `bsize_to_tx_size_cat(BLOCK_128X64)` is 3 (see this fn's doc).
@@ -143,25 +140,12 @@ pub(super) fn decode_block_128rect(
143140 // lane-inter128intra r1: `get_tx_size_context` compares the bands
144141 // against `tx_size_wide/high[max_txsize_rect_lookup[bsize]]` --
145142 // TX_64X64 for every 128-axis block, hence the `min(64)`.
146- let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64), fctx);
143+ let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64));
147144 dec.symbol(&mut cdfs.tx_size_cat3[ctx])
148145 } else {
149146 0
150147 };
151- if depth != 0 {
152- hit!(TX_DEPTH_HITS);
153- }
154- hit_do! {
155- INTRA_SB128_DEPTH_HITS.with(|c| {
156- let mut h = c.get();
157- h[depth.min(2)] += 1;
158- c.set(h);
159- });
160- }
161148 let logical_tx = if lossless_frame { 4 } else { 64 >> depth };
162- if lossless_frame {
163- hit!(INTRA128_LOSSLESS_HITS);
164- }
165149 // A 64-point transform codes nothing past its low 32 coefficients.
166150 let coeff_tx_side = logical_tx.min(32);
167151 let luma_set = if lossless_frame {
@@ -239,11 +223,6 @@ pub(super) fn decode_block_128rect(
239223 tu_row * logical_tx,
240224 logical_tx,
241225 reach,
242- px,
243- py,
244- y.width,
245- y.height,
246- fctx,
247226 );
248227 if skip {
249228 push_intra(
@@ -288,7 +267,6 @@ pub(super) fn decode_block_128rect(
288267 tu_py,
289268 logical_tx,
290269 coeff_tx_side,
291- base_q_idx,
292270 None,
293271 None,
294272 Some(tu_skip_ctx),
@@ -341,11 +319,6 @@ pub(super) fn decode_block_128rect(
341319 luma_span,
342320 luma_span_h,
343321 reach,
344- px,
345- py,
346- y.width,
347- y.height,
348- fctx,
349322 );
350323 if skip {
351324 push_intra(
@@ -402,7 +375,6 @@ pub(super) fn decode_block_128rect(
402375 cu_y,
403376 chroma_tx,
404377 chroma_tx,
405- base_q_idx,
406378 None,
407379 None,
408380 Some(3),
@@ -425,9 +397,6 @@ pub(super) fn decode_block_128rect(
425397 }
426398 }
427399 }
428- if !skip {
429- hit!(CHROMA_SPLIT_TX_HITS);
430- }
431400 }
432401 }
433402 if skip {
@@ -467,12 +436,8 @@ pub(super) fn decode_block_128rect(
467436 // byte-exact against ffmpeg) -- that is the replay's own designed
468437 // 4:2:2 case, not a defect signature. Nothing here asserts the
469438 // mismatch is zero.
470- if luma_span != luma_span_h {
471- hit!(SB128RECT_REPLAY_SPAN_MISMATCH_HITS);
472- }
473439 for (plane, cu_mi, grid) in &units {
474440 neighbours.record_mi_chroma(*cu_mi, luma_span, luma_span_h, *plane, grid);
475- hit!(SB128RECT_CHROMA_REPLAY_HITS);
476441 }
477442 }
478443 // No palette exists at this size; the unconditional stamp clears any
@@ -499,19 +464,6 @@ pub(super) fn decode_block_128rect(
499464 // stamps here too -- lane-av1-intrabc r3.
500465 txfm_partition_update_rect(neighbours, (mi_r, mi_c), (logical_tx, logical_tx), (bw, bh));
501466 }
502- if in_inter {
503- hit_do! {
504- INTRA128_IN_INTER_HITS.with(|c| {
505- let mut h = c.get();
506- h[usize::from(bw < bh)] += 1;
507- c.set(h);
508- });
509- }
510- } else if bw > bh {
511- hit!(INTRA_SB128_HORZ_HITS);
512- } else {
513- hit!(INTRA_SB128_VERT_HITS);
514- }
515467 Ok(())
516468 }
517469
@@ -563,7 +515,6 @@ pub(super) fn decode_leaf8(
563515 y: &mut PlaneBuf<'static>,
564516 u: &mut PlaneBuf<'static>,
565517 v: &mut PlaneBuf<'static>,
566- base_q_idx: u8,
567518 enable_filter_intra: bool,
568519 allow_screen_content_tools: bool,
569520 allow_intrabc: bool,
@@ -603,9 +554,6 @@ pub(super) fn decode_leaf8(
603554 // with the coarse [`SUB`] slot as the fallback when no block recorded
604555 // that exact mi cell.
605556 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c, fctx);
606- if smooth_neighbor {
607- hit!(SMOOTH_LUMA_HITS);
608- }
609557 // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec
610558 // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other
611559 // `decode_block` caller at 16x16 and up.
@@ -654,9 +602,6 @@ pub(super) fn decode_leaf8(
654602 // next symbol (class `wrong-alphabet-same-value`). Everything below
655603 // mirrors `decode_block`'s own intrabc handling at 16x16 and up.
656604 let intrabc_dv = fctx.intrabc_dv.with(|c| c.take());
657- if intrabc_dv.is_some() {
658- hit!(LEAF8_INTRABC_HITS);
659- }
660605 // `av1_visit_palette`'s reconstruction (decodeframe.c:1135): the colour
661606 // index map, mapped through the base colours, IS the block's prediction --
662607 // carried to the next `reconstruct`/`read_plane` through the same
@@ -676,9 +621,6 @@ pub(super) fn decode_leaf8(
676621 let (pal_uv_size, pal_uv_colors) = palette_uv
677622 .as_ref()
678623 .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
679- if palette_y.is_some() || palette_uv.is_some() {
680- hit!(PALETTE_LEAF8_HITS);
681- }
682624 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
683625 DC_PRED
684626 } else {
@@ -722,7 +664,6 @@ pub(super) fn decode_leaf8(
722664 0,
723665 &mut leaves,
724666 );
725- hit!(INTRABC_VARTX_HITS);
726667 leaves.first().map_or(8, |l| l.2)
727668 } else if tx_select && intrabc_dv.is_none() {
728669 read_tx_size(dec, cdfs, neighbours, leaf_mi, 8, fctx)
@@ -846,26 +787,13 @@ pub(super) fn decode_leaf8(
846787 // rule) -- so a palette leaf takes the single 8x8 reconstruct below
847788 // even when `tx_depth` resolved to TX_4X4.
848789 if resolved == 4 && palette_y_buf.is_none() {
849- hit!(SKIP_SPLIT_TX_HITS);
850790 for tu_row in 0..2 {
851791 for tu_col in 0..2 {
852792 let (tu_px, tu_py) = (px + tu_col * 4, py + tu_row * 4);
853793 if tu_px >= y.true_width || tu_py >= y.true_height {
854794 continue;
855795 }
856- let tu_reach = tu_reach(
857- 8,
858- 8,
859- tu_col * 4,
860- tu_row * 4,
861- 4,
862- reach,
863- px,
864- py,
865- y.width,
866- y.height,
867- fctx,
868- );
796+ let tu_reach = tu_reach(8, 8, tu_col * 4, tu_row * 4, 4, reach);
869797 push_intra(
870798 y,
871799 u,
@@ -989,19 +917,7 @@ pub(super) fn decode_leaf8(
989917 if chroma_units_ll {
990918 for cu_row in 0..cu_shape.1 / 4 {
991919 for cu_col in 0..cu_shape.0 / 4 {
992- let cu_reach = tu_reach(
993- 8,
994- 8,
995- cu_col * 4,
996- cu_row * 4,
997- 4,
998- reach,
999- px,
1000- py,
1001- y.width,
1002- y.height,
1003- fctx,
1004- );
920+ let cu_reach = tu_reach(8, 8, cu_col * 4, cu_row * 4, 4, reach);
1005921 push_intra(
1006922 y,
1007923 u,
@@ -1048,19 +964,7 @@ pub(super) fn decode_leaf8(
1048964 for (buf, plane) in [(ub, 1usize), (vb, 2usize)] {
1049965 if let Some(buf) = buf {
1050966 for cu_row in 0..2 {
1051- let cu_reach = tu_reach(
1052- 8,
1053- 8,
1054- 0,
1055- cu_row * 4,
1056- 4,
1057- reach,
1058- px,
1059- py,
1060- y.width,
1061- y.height,
1062- fctx,
1063- );
967+ let cu_reach = tu_reach(8, 8, 0, cu_row * 4, 4, reach);
1064968 set_palette_pred(
1065969 palette_window(&buf, cw, 0, cu_row * 4, 4, 4),
1066970 fctx,
@@ -1113,19 +1017,7 @@ pub(super) fn decode_leaf8(
11131017 if chroma_units_ll {
11141018 for cu_row in 0..cu_shape.1 / 4 {
11151019 for cu_col in 0..cu_shape.0 / 4 {
1116- let cu_reach = tu_reach(
1117- 8,
1118- 8,
1119- cu_col * 4,
1120- cu_row * 4,
1121- 4,
1122- reach,
1123- px,
1124- py,
1125- y.width,
1126- y.height,
1127- fctx,
1128- );
1020+ let cu_reach = tu_reach(8, 8, cu_col * 4, cu_row * 4, 4, reach);
11291021 push_intra(
11301022 y,
11311023 u,
@@ -1158,19 +1050,7 @@ pub(super) fn decode_leaf8(
11581050 .or_else(|| palette_uv_bufs.as_ref().map(|(_, vb)| vb.clone()));
11591051 if let Some(vb) = vb {
11601052 for cu_row in 0..2 {
1161- let cu_reach = tu_reach(
1162- 8,
1163- 8,
1164- 0,
1165- cu_row * 4,
1166- 4,
1167- reach,
1168- px,
1169- py,
1170- y.width,
1171- y.height,
1172- fctx,
1173- );
1053+ let cu_reach = tu_reach(8, 8, 0, cu_row * 4, 4, reach);
11741054 set_palette_pred(palette_window(&vb, cw, 0, cu_row * 4, 4, 4), fctx);
11751055 push_intra(
11761056 y,
@@ -1257,7 +1137,6 @@ pub(super) fn decode_leaf8(
12571137 py,
12581138 8,
12591139 TX8,
1260- base_q_idx,
12611140 None,
12621141 filter_intra,
12631142 None,
@@ -1344,7 +1223,6 @@ pub(super) fn decode_leaf8(
13441223 cpy,
13451224 csz,
13461225 csz,
1347- base_q_idx,
13481226 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
13491227 None,
13501228 None,
@@ -1374,7 +1252,6 @@ pub(super) fn decode_leaf8(
13741252 cpy,
13751253 csz,
13761254 csz,
1377- base_q_idx,
13781255 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
13791256 None,
13801257 None,
@@ -1400,29 +1277,13 @@ pub(super) fn decode_leaf8(
14001277 let tu_px = px + tu_col * 4;
14011278 let tu_py = py + tu_row * 4;
14021279 let tu_around = neighbours.around_mi(tu_mi, 4)[0];
1403- if crate::encode::Reach::in_vert_ab() {
1404- hit!(VERT_AB_TX4_HITS);
1405- }
1406- let tu_reach = tu_reach(
1407- 8,
1408- 8,
1409- tu_col * 4,
1410- tu_row * 4,
1411- 4,
1412- reach,
1413- px,
1414- py,
1415- y.width,
1416- y.height,
1417- fctx,
1418- );
1280+ let tu_reach = tu_reach(8, 8, tu_col * 4, tu_row * 4, 4, reach);
14191281 let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1);
14201282 // Each 4x4 unit predicts from its own window of the block's
14211283 // 8x8 colour-index map ([`decode_block`]'s per-TU slice at
14221284 // 16x16 and up) -- the whole-block buffer would be taken by
14231285 // the FIRST unit and indexed at the wrong stride.
14241286 if let Some(buf) = &palette_y_buf {
1425- hit!(PALETTE_SPLIT_TX_HITS);
14261287 let mut window = vec![0u16; 16];
14271288 for row in 0..4 {
14281289 let src = (tu_row * 4 + row) * 8 + tu_col * 4;
@@ -1454,21 +1315,12 @@ pub(super) fn decode_leaf8(
14541315 tu_py,
14551316 4,
14561317 4,
1457- base_q_idx,
14581318 None,
14591319 filter_intra,
14601320 Some(tu_skip_ctx),
14611321 smooth_neighbor,
14621322 fctx,
14631323 )?;
1464- if crate::envflags::env_flag!("EC_AV1_TRACE") {
1465- eprintln!(
1466- "TRACE tu_bitpos mi=({},{}) tell={}",
1467- tu_mi.0,
1468- tu_mi.1,
1469- dec.debug_bitpos()
1470- );
1471- }
14721324 neighbours.record_mi_luma(tu_mi, 4, &tu_grid);
14731325 // The FIRST (top-left, co-located with this group's chroma)
14741326 // TU's coded tx_type is what the group's chroma inherits --
@@ -1505,9 +1357,6 @@ pub(super) fn decode_leaf8(
15051357 // lane-av1intrapred: the non-vacuity counter -- armed slot consulted
15061358 // by this arm's chroma reads means the frame-copy + inherited-type
15071359 // route ran; zero at gate time means the fixture stopped reaching it.
1508- if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() {
1509- hit!(INTRABC_TX4_CHROMA_COPY_HITS);
1510- }
15111360 if chroma_422 && !lossless(fctx) {
15121361 // lane-av1-422d: the chroma unit does NOT follow the luma var-tx
15131362 // split -- `uv_txsize` is `av1_get_max_uv_txsize` of the block,
@@ -1601,7 +1450,6 @@ pub(super) fn decode_leaf8(
16011450 cdfs,
16021451 neighbours,
16031452 leaf_mi,
1604- (px, py),
16051453 (cpx, cpy),
16061454 8,
16071455 (blk_w, blk_h),
@@ -1609,13 +1457,11 @@ pub(super) fn decode_leaf8(
16091457 (blk_w, blk_h),
16101458 blk_w,
16111459 reach,
1612- (y.width, y.height),
16131460 mode,
16141461 uv_predict_mode,
16151462 angle_delta_uv,
16161463 palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])),
16171464 smooth_neighbor_uv,
1618- base_q_idx,
16191465 &mut uo,
16201466 &mut vo,
16211467 fctx,
@@ -1630,7 +1476,6 @@ pub(super) fn decode_leaf8(
16301476 } else {
16311477 Grid::Own(vo)
16321478 };
1633- hit!(CHROMA422_LOSSLESS_4X4_HITS);
16341479 } else if chroma_444 && lossless(fctx) {
16351480 // 4:4:4 lossless: the leaf's chroma plane block is a 2x2 raster
16361481 // of TX_4X4 units per plane, PLANE-MAJOR (`av1_get_tx_size`:
@@ -1651,7 +1496,6 @@ pub(super) fn decode_leaf8(
16511496 cdfs,
16521497 neighbours,
16531498 leaf_mi,
1654- (px, py),
16551499 (cpx, cpy),
16561500 8,
16571501 (8, 8),
@@ -1659,13 +1503,11 @@ pub(super) fn decode_leaf8(
16591503 (8, 8),
16601504 8,
16611505 reach,
1662- (y.width, y.height),
16631506 mode,
16641507 uv_predict_mode,
16651508 angle_delta_uv,
16661509 palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])),
16671510 smooth_neighbor_uv,
1668- base_q_idx,
16691511 &mut uo,
16701512 &mut vo,
16711513 fctx,
@@ -1702,7 +1544,6 @@ pub(super) fn decode_leaf8(
17021544 cpy,
17031545 csz,
17041546 csz,
1705- base_q_idx,
17061547 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
17071548 None,
17081549 None,
@@ -1730,7 +1571,6 @@ pub(super) fn decode_leaf8(
17301571 cpy,
17311572 csz,
17321573 csz,
1733- base_q_idx,
17341574 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
17351575 None,
17361576 None,
@@ -1809,7 +1649,6 @@ pub(super) fn decode_leaf8(
18091649 neighbours.record_palette_y_rect(leaf_mi, 8, 8, pal_y_size, pal_y_colors);
18101650 neighbours.record_palette_uv_rect(leaf_mi, 8, 8, pal_uv_size, pal_uv_colors);
18111651 }
1812- hit!(INTER8_SKIP_BAND_HITS);
18131652 neighbours.fill_skip_grid(leaf_mi, 2, skip);
18141653 // lane-kf900 r1: the leaf's own RESOLVED transform size, never the literal
18151654 // block side. libaom calls `set_txfm_ctxs(mbmi->tx_size, ..., skip_txfm &&
@@ -1924,7 +1763,6 @@ pub(super) fn leaf8_chroma422_unit(
19241763 usize::from(around.0) + usize::from(around.1),
19251764 dc_sign_ctx(around.2),
19261765 default_tx,
1927- plane_idx,
19281766 )?;
19291767 let residual = dequant_and_inverse_typed_wh(
19301768 &levels,
@@ -2001,28 +1839,10 @@ pub(super) fn read_intra_mode_sub8(
20011839 // lane-av1mono: a monochrome leaf codes no chroma mode (libaom
20021840 // `decodemv.c:933`), so fold `NumPlanes == 1` into `has_chroma`.
20031841 let has_chroma = has_chroma && !mono(fctx);
2004- let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
2005- let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");
2006- crate::msac::SymbolDecoder::set_symr_mi(mi_r as i64, mi_c as i64);
2007- if ec_istep {
2008- eprintln!(
2009- "EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sub8 rng={}",
2010- dec.debug_state().0
2011- );
2012- }
20131842 // Same `EC_ISTEP` ladder the square/rect readers print, so a cross-decoder
20141843 // range diff lands on the ELEMENT inside a 4x4 leaf, not just the block.
20151844 macro_rules! istep {
2016- ($name:literal, $val:expr) => {
2017- if ec_istep {
2018- eprintln!(
2019- "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name={} val={} rng={}",
2020- $name,
2021- $val,
2022- dec.debug_state().0
2023- );
2024- }
2025- };
1845+ ($name:literal, $val:expr) => {};
20261846 }
20271847 // lane-seg2: same `intra_segment_id` placement as the square and rect
20281848 // readers (spec 5.11.6) -- a `BLOCK_4X4` leaf codes its own `segment_id`
@@ -2034,13 +1854,6 @@ pub(super) fn read_intra_mode_sub8(
20341854 intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, false, fctx);
20351855 }
20361856 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
2037- if trace {
2038- eprintln!(
2039- "TRACE sub8 skip mi=({mi_r},{mi_c}) ctx={skip_ctx} value={} rng={}",
2040- skip as i32,
2041- dec.debug_state().0
2042- );
2043- }
20441857 istep!("skip", skip as i32);
20451858 if !seg_id_pre_skip(fctx) {
20461859 intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, skip, fctx);
@@ -2052,13 +1865,6 @@ pub(super) fn read_intra_mode_sub8(
20521865 istep!("dq", 0);
20531866 if allow_intrabc {
20541867 let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0;
2055- if ec_istep {
2056- eprintln!(
2057- "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=intrabc val={} rng={}",
2058- u8::from(use_intrabc),
2059- dec.debug_state().0
2060- );
2061- }
20621868 if use_intrabc {
20631869 // lane-av1txr: `read_intrabc_info` (spec 5.11.13) reads the block
20641870 // vector right after the flag and RETURNS -- no y/uv mode, angle
@@ -2067,15 +1873,6 @@ pub(super) fn read_intra_mode_sub8(
20671873 // `is_inter_block` counts an intrabc block), so the caller takes
20681874 // the frame-copy prediction + inter residual.
20691875 let dv = read_intrabc_dv(dec, cdfs, mi_r, mi_c, (seg_w_mi, seg_h_mi), fctx);
2070- // lane-av1txr: the DV travels back in the RETURN value -- it is
2071- // NOT published through `FrameCtx::intrabc_dv`. That slot is the
2072- // SQUARE paths' handoff (`decode_block`/`decode_leaf8` arm it,
2073- // then `take()` it in the same call), so a sub-8x8 leaf that
2074- // armed it left the vector standing for the NEXT >=8x8 block:
2075- // `warped.obu`'s (38,60) 8x8 intra block took it as its own
2076- // intrabc and read an inter var-tx `txfm_split` where libaom read
2077- // an intra `tx_depth` (class `stale-slot-handoff`).
2078- hit!(INTRABC_HITS);
20791876 return Ok((skip, DC_PRED, 0, None, None, Some(dv)));
20801877 }
20811878 }
@@ -2083,12 +1880,6 @@ pub(super) fn read_intra_mode_sub8(
20831880 let left_ctx = INTRA_MODE_CTX[left_mode];
20841881 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
20851882 istep!("mode", mode);
2086- if trace {
2087- eprintln!(
2088- "TRACE sub8 y_mode mi=({mi_r},{mi_c}) ctx=({above_ctx},{left_ctx}) value={mode} rng={}",
2089- dec.debug_state().0
2090- );
2091- }
20921883 // No `angle_delta` at all below 8x8: spec 5.11.6's `intra_angle_info_y`/
20931884 // `_uv` are gated on `MiSize >= BLOCK_8X8` (libaom `av1_use_angle_delta`,
20941885 // blockd.h), so a directional mode on a `BLOCK_4X4` leaf carries no delta
@@ -2107,29 +1898,15 @@ pub(super) fn read_intra_mode_sub8(
21071898 // divergence at the rect leaf mi (8,16) of `ll444.obu`; class
21081899 // `wrong-alphabet-same-value`, lane-av1-llsub8).
21091900 let uv_mode = if cfl_allowed_px(seg_w_mi * MI, seg_h_mi * MI, fctx) {
2110- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
21111901 dec.symbol(&mut cdfs.uv_mode_cfl[mode])
21121902 } else {
2113- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
21141903 dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
21151904 };
2116- if trace {
2117- eprintln!(
2118- "TRACE sub8 uv_mode value={uv_mode} rng={}",
2119- dec.debug_state().0
2120- );
2121- }
2122- if (9..=12).contains(&uv_mode) {
2123- hit!(SMOOTH_UV_HITS);
2124- }
21251905 let alpha = if uv_mode == UV_CFL_PRED {
21261906 Some(read_cfl_alphas(dec, cdfs))
21271907 } else {
21281908 None
21291909 };
2130- if (V_PRED..=D67_PRED).contains(&uv_mode) {
2131- hit!(DIRECTIONAL_UV_HITS);
2132- }
21331910 // See the luma comment above: no angle delta below 8x8.
21341911 let angle_delta_uv = 0;
21351912 Some((uv_mode, angle_delta_uv, alpha))
@@ -2139,14 +1916,7 @@ pub(super) fn read_intra_mode_sub8(
21391916 let mut filter_intra = None;
21401917 if mode == DC_PRED && enable_filter_intra {
21411918 let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[fi_class]) != 0;
2142- if trace {
2143- eprintln!(
2144- "TRACE sub8 use_filter_intra value={}",
2145- use_filter_intra as i32
2146- );
2147- }
21481919 if use_filter_intra {
2149- hit!(FILTER_INTRA_HITS);
21501920 let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode);
21511921 filter_intra = Some(fi_mode);
21521922 }
crates/ec-av1/src/decode/leaf_sub8.rsmodified+3 -157
@@ -35,7 +35,6 @@ pub(super) fn sub8_leaf_chroma444(
3535 u: &mut PlaneBuf<'static>,
3636 v: &mut PlaneBuf<'static>,
3737 scan4: &[u16],
38- base_q_idx: u8,
3938 smooth_neighbor_uv: bool,
4039 fctx: &crate::decode::FrameCtx,
4140 ) -> Result<(Grid, Grid, usize, usize)> {
@@ -94,7 +93,6 @@ pub(super) fn sub8_leaf_chroma444(
9493 &mut vb,
9594 fctx,
9695 );
97- hit!(SKIPPED_INTRABC_DV_COPY_HITS);
9896 let zeros = &ZERO_RESIDUAL[..bw * bh];
9997 if square {
10098 set_palette_pred(ub, fctx);
@@ -173,10 +171,6 @@ pub(super) fn sub8_leaf_chroma444(
173171 fctx,
174172 );
175173 }
176- // The same arm-without-clear route the 4:2:0 tails count: a skipped
177- // leaf reads no coefficient, so the inherited chroma `tx_type` is
178- // dropped unconsumed.
179- hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS);
180174 fctx.intrabc_chroma_tx.with(|c| c.set(None));
181175 (Grid::Zero(bw * bh), Grid::Zero(bw * bh), 4, 4)
182176 } else if skip {
@@ -257,7 +251,6 @@ pub(super) fn sub8_leaf_chroma444(
257251 // The same arm-without-clear route the 4:2:0 tails count: a skipped
258252 // leaf reads no coefficient, so an armed intrabc slot is dropped.
259253 if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() {
260- hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS);
261254 fctx.intrabc_chroma_tx.with(|c| c.set(None));
262255 }
263256 (Grid::Zero(bw * bh), Grid::Zero(bw * bh), 4, 4)
@@ -313,7 +306,6 @@ pub(super) fn sub8_leaf_chroma444(
313306 py,
314307 4,
315308 TX4,
316- base_q_idx,
317309 None,
318310 None,
319311 None,
@@ -339,7 +331,6 @@ pub(super) fn sub8_leaf_chroma444(
339331 py,
340332 4,
341333 TX4,
342- base_q_idx,
343334 None,
344335 None,
345336 None,
@@ -350,9 +341,6 @@ pub(super) fn sub8_leaf_chroma444(
350341 } else {
351342 // lane-av1-ibc444rect: the unskipped lossless chroma walk this
352343 // lane fixes (one rect unit -> per-4x4 Chroma4 units).
353- if lossless(fctx) {
354- hit!(INTRABC_RECT8_LOSSLESS_CHROMA_HITS);
355- }
356344 if lossless(fctx) {
357345 // lane-av1-ibc444rect: at lossless `read_tx_size` forces
358346 // TX_4X4 on EVERY plane (`av1_get_tx_size`'s lossless
@@ -406,11 +394,6 @@ pub(super) fn sub8_leaf_chroma444(
406394 // 4:2:2 twin of this arm was fixed the same way
407395 // (lane-av1-422kf2); this is its 4:4:4 twin.
408396 let unit_reach = Reach::of_tu(bw, bh, uc * 4, ur * 4, 4, 4, reach);
409- if !square
410- && unit_reach != Reach::of(4, upx, upy, y.width, y.height, fctx)
411- {
412- hit!(SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS);
413- }
414397 let grid = read_plane(
415398 dec,
416399 cdfs,
@@ -429,7 +412,6 @@ pub(super) fn sub8_leaf_chroma444(
429412 upy,
430413 4,
431414 TX4,
432- base_q_idx,
433415 None,
434416 None,
435417 Some(3),
@@ -478,7 +460,6 @@ pub(super) fn sub8_leaf_chroma444(
478460 skip_ctx,
479461 dc_sign_ctx(around[plane_idx].2),
480462 default_tx,
481- plane_idx,
482463 )?;
483464 let residual = dequant_and_inverse_typed_wh(
484465 &levels,
@@ -543,7 +524,6 @@ pub(super) fn sub8_leaf_chroma444(
543524 py,
544525 4,
545526 TX4,
546- base_q_idx,
547527 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
548528 None,
549529 None,
@@ -568,7 +548,6 @@ pub(super) fn sub8_leaf_chroma444(
568548 py,
569549 4,
570550 TX4,
571- base_q_idx,
572551 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
573552 None,
574553 None,
@@ -605,10 +584,6 @@ pub(super) fn sub8_leaf_chroma444(
605584 // position -- see the intrabc twin above for the
606585 // libaom citation and the measured damage.
607586 let unit_reach = Reach::of_tu(bw, bh, uc * 4, ur * 4, 4, 4, reach);
608- if !square && unit_reach != Reach::of(4, upx, upy, y.width, y.height, fctx)
609- {
610- hit!(SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS);
611- }
612587 let grid = read_plane(
613588 dec,
614589 cdfs,
@@ -627,7 +602,6 @@ pub(super) fn sub8_leaf_chroma444(
627602 upy,
628603 4,
629604 TX4,
630- base_q_idx,
631605 None,
632606 None,
633607 Some(3),
@@ -677,7 +651,6 @@ pub(super) fn sub8_leaf_chroma444(
677651 skip_ctx,
678652 dc_sign_ctx(around[plane_idx].2),
679653 default_tx,
680- plane_idx,
681654 )?;
682655 let residual = dequant_and_inverse_typed_wh(
683656 &levels,
@@ -806,16 +779,7 @@ pub(super) fn sub8_leaf_chroma422(
806779 u: &mut PlaneBuf<'static>,
807780 v: &mut PlaneBuf<'static>,
808781 scan4: &[u16],
809- base_q_idx: u8,
810782 smooth_neighbor_uv: bool,
811- // The owning luma leaf's own shape (`(4, 4)` for a split leaf, `(8, 4)` /
812- // `(4, 8)` for a rect pair's strip): libaom's `has_top_right` /
813- // `has_bottom_left` answer for this chroma TX_4X4 unit comes from the
814- // LEAF's own rect table row at the leaf's mi (`bsize` is the leaf, the
815- // unit covers it whole), never the standalone square-4x4 table the old
816- // `Reach::of(4, ..)` lookup used -- that said 1 where `has_tr_8x4` says 0
817- // at mi(27,44) (the oracle's own EC_PRED prints `n_tr=0` there), so the
818- // D45 unit read undecoded pixels to its upper right.
819783 leaf_shape: (usize, usize),
820784 fctx: &crate::decode::FrameCtx,
821785 ) -> Result<(Grid, Grid)> {
@@ -988,7 +952,6 @@ pub(super) fn sub8_leaf_chroma422(
988952 &mut ub,
989953 fctx,
990954 );
991- hit!(SKIPPED_INTRABC_DV_COPY_HITS);
992955 let zeros = &ZERO_RESIDUAL[..16];
993956 set_palette_pred(ub, fctx);
994957 push_intra(
@@ -1044,17 +1007,12 @@ pub(super) fn sub8_leaf_chroma422(
10441007 // [`sub8_leaf_chroma444`] count: a skipped leaf reads no coefficient,
10451008 // so the inherited chroma `tx_type` is dropped unconsumed.
10461009 if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() {
1047- hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS);
10481010 fctx.intrabc_chroma_tx.with(|c| c.set(None));
10491011 }
10501012 (Grid::Zero(16), Grid::Zero(16))
10511013 } else if skip {
10521014 // A skipped chroma-reference leaf still predicts (the CfL contribution
10531015 // survives a skip); no coefficient symbol exists.
1054- if alpha.is_some() {
1055- hit!(CHROMA_SKIP_CFL_HITS);
1056- hit!(SKIP_CFL_HITS);
1057- }
10581016 push_intra(
10591017 y,
10601018 u,
@@ -1092,12 +1050,10 @@ pub(super) fn sub8_leaf_chroma422(
10921050 // The same arm-without-clear route the 4:2:0 tails count: a skipped
10931051 // leaf reads no coefficient, so an armed intrabc slot is dropped.
10941052 if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() {
1095- hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS);
10961053 fctx.intrabc_chroma_tx.with(|c| c.set(None));
10971054 }
10981055 (Grid::Zero(16), Grid::Zero(16))
10991056 } else if let Some(dv) = intrabc_dv {
1100- hit!(CHROMA422_SUB8_HITS);
11011057 // Frame copy at the DV; the residual still reads the ordinary chroma
11021058 // tables with the inherited luma `tx_type` (see the 4:2:0 tails).
11031059 let mut ub = vec![0u16; 16];
@@ -1147,7 +1103,6 @@ pub(super) fn sub8_leaf_chroma422(
11471103 cpy,
11481104 4,
11491105 TX4,
1150- base_q_idx,
11511106 None,
11521107 None,
11531108 None,
@@ -1173,7 +1128,6 @@ pub(super) fn sub8_leaf_chroma422(
11731128 cpy,
11741129 4,
11751130 TX4,
1176- base_q_idx,
11771131 None,
11781132 None,
11791133 None,
@@ -1183,7 +1137,6 @@ pub(super) fn sub8_leaf_chroma422(
11831137 fctx.intrabc_chroma_tx.with(|c| c.set(None));
11841138 (ug, vg)
11851139 } else {
1186- hit!(CHROMA422_SUB8_HITS);
11871140 let ug = read_plane(
11881141 dec,
11891142 cdfs,
@@ -1202,7 +1155,6 @@ pub(super) fn sub8_leaf_chroma422(
12021155 cpy,
12031156 4,
12041157 TX4,
1205- base_q_idx,
12061158 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
12071159 None,
12081160 None,
@@ -1227,7 +1179,6 @@ pub(super) fn sub8_leaf_chroma422(
12271179 cpy,
12281180 4,
12291181 TX4,
1230- base_q_idx,
12311182 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
12321183 None,
12331184 None,
@@ -1277,16 +1228,11 @@ pub(super) fn decode_leaf_split4(
12771228 y: &mut PlaneBuf<'static>,
12781229 u: &mut PlaneBuf<'static>,
12791230 v: &mut PlaneBuf<'static>,
1280- base_q_idx: u8,
12811231 enable_filter_intra: bool,
12821232 allow_intrabc: bool,
12831233 reduced_tx_set: bool,
1284- // Returns `(below_mode, right_mode)`: the mode a neighbour BELOW this 8x8
1285- // group sees (its bottom-left 4x4, libaom reads mi(row-1, col)) and the
1286- // one a neighbour to its RIGHT sees (its top-right 4x4, mi(row, col-1))., fctx: &crate::decode::FrameCtx
12871234 fctx: &crate::decode::FrameCtx,
12881235 ) -> Result<(usize, usize)> {
1289- hit!(SUB8_SPLIT_HITS);
12901236 let (r, c) = outer_at;
12911237 let mut above_mode = neighbours.above_mode[c];
12921238 let mut left_mode = neighbours.left_mode[r];
@@ -1378,9 +1324,6 @@ pub(super) fn decode_leaf_split4(
13781324 // same value).
13791325 set_txfm_ctxs(neighbours, lmi, 4, 1, 1, false);
13801326 let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left);
1381- if smooth_neighbor {
1382- hit!(SMOOTH_LUMA_HITS);
1383- }
13841327 let (px, py) = (lmi.1 * MI, lmi.0 * MI);
13851328 let reach = Reach::of(4, px, py, y.width, y.height, fctx);
13861329 if let Some(dv) = intrabc {
@@ -1450,7 +1393,6 @@ pub(super) fn decode_leaf_split4(
14501393 py,
14511394 4,
14521395 4,
1453- base_q_idx,
14541396 None,
14551397 None,
14561398 None,
@@ -1488,7 +1430,6 @@ pub(super) fn decode_leaf_split4(
14881430 u,
14891431 v,
14901432 scan4,
1491- base_q_idx,
14921433 neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx),
14931434 fctx,
14941435 )?;
@@ -1508,7 +1449,6 @@ pub(super) fn decode_leaf_split4(
15081449 u,
15091450 v,
15101451 scan4,
1511- base_q_idx,
15121452 neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx),
15131453 (4, 4),
15141454 fctx,
@@ -1579,7 +1519,6 @@ pub(super) fn decode_leaf_split4(
15791519 py,
15801520 4,
15811521 4,
1582- base_q_idx,
15831522 None,
15841523 filter_intra,
15851524 None,
@@ -1610,7 +1549,6 @@ pub(super) fn decode_leaf_split4(
16101549 u,
16111550 v,
16121551 scan4,
1613- base_q_idx,
16141552 neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx),
16151553 fctx,
16161554 )?;
@@ -1636,7 +1574,6 @@ pub(super) fn decode_leaf_split4(
16361574 u,
16371575 v,
16381576 scan4,
1639- base_q_idx,
16401577 neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx),
16411578 (4, 4),
16421579 fctx,
@@ -1695,10 +1632,6 @@ pub(super) fn decode_leaf_split4(
16951632 // merge keeps one fix and feeds both lanes' counters so neither of
16961633 // their gates goes vacuous.
16971634 let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
1698- if alpha.is_some() {
1699- hit!(CHROMA_SKIP_CFL_HITS);
1700- hit!(SKIP_CFL_HITS);
1701- }
17021635 push_intra(
17031636 y,
17041637 u,
@@ -1742,7 +1675,6 @@ pub(super) fn decode_leaf_split4(
17421675 // arm-without-clear-on-a-skip-route). Counted so a gate can tell a
17431676 // stream that reaches this route from one that never does.
17441677 if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() {
1745- hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS);
17461678 fctx.intrabc_chroma_tx.with(|c| c.set(None));
17471679 }
17481680 (Grid::Zero(16), Grid::Zero(16))
@@ -1799,7 +1731,6 @@ pub(super) fn decode_leaf_split4(
17991731 cpy,
18001732 4,
18011733 TX4,
1802- base_q_idx,
18031734 None,
18041735 None,
18051736 None,
@@ -1825,7 +1756,6 @@ pub(super) fn decode_leaf_split4(
18251756 cpy,
18261757 4,
18271758 TX4,
1828- base_q_idx,
18291759 None,
18301760 None,
18311761 None,
@@ -1855,7 +1785,6 @@ pub(super) fn decode_leaf_split4(
18551785 cpy,
18561786 4,
18571787 TX4,
1858- base_q_idx,
18591788 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
18601789 None,
18611790 None,
@@ -1880,7 +1809,6 @@ pub(super) fn decode_leaf_split4(
18801809 cpy,
18811810 4,
18821811 TX4,
1883- base_q_idx,
18841812 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
18851813 None,
18861814 None,
@@ -1989,7 +1917,6 @@ pub(super) fn decode_leaf_rect8(
19891917 y: &mut PlaneBuf<'static>,
19901918 u: &mut PlaneBuf<'static>,
19911919 v: &mut PlaneBuf<'static>,
1992- base_q_idx: u8,
19931920 enable_filter_intra: bool,
19941921 allow_intrabc: bool,
19951922 tx_select: bool,
@@ -2073,9 +2000,6 @@ pub(super) fn decode_leaf_rect8(
20732000 if let Some(dv) = intrabc {
20742001 // lane-av1-ibc444rect: the unskipped lossless luma walk this lane
20752002 // fixes (one rect unit -> per-4x4 inter units).
2076- if !skip && lossless(fctx) {
2077- hit!(INTRABC_RECT8_LOSSLESS_LUMA_HITS);
2078- }
20792003 // lane-av1txr: an intrabc `BLOCK_4X8`/`BLOCK_8X4` leaf. The
20802004 // prediction is a frame copy at the DV and the residual reads the
20812005 // INTER `LumaRect8x4` set -- but with `TxMode::Select` the leaf
@@ -2127,7 +2051,6 @@ pub(super) fn decode_leaf_rect8(
21272051 0,
21282052 &mut luma_leaves,
21292053 );
2130- hit!(RECT_INTRABC_VARTX_HITS);
21312054 publish = None;
21322055 } else if lossless(fctx) && !skip {
21332056 // lane-av1-ibc444rect: `read_tx_size`'s lossless first line
@@ -2170,19 +2093,7 @@ pub(super) fn decode_leaf_rect8(
21702093 let tu_reach = if single {
21712094 reach
21722095 } else {
2173- tu_reach(
2174- bw,
2175- bh,
2176- tu_px - px,
2177- tu_py - py,
2178- tw,
2179- reach,
2180- px,
2181- py,
2182- y.width,
2183- y.height,
2184- fctx,
2185- )
2096+ tu_reach(bw, bh, tu_px - px, tu_py - py, tw, reach)
21862097 };
21872098 let mut yb = vec![0u16; tw * th];
21882099 mc::predict_with_filter(
@@ -2285,7 +2196,6 @@ pub(super) fn decode_leaf_rect8(
22852196 skip_ctx,
22862197 dc_sign_ctx(around.2),
22872198 TxType::DctDct,
2288- 0,
22892199 )?;
22902200 if li == 0 {
22912201 chroma_tx = tx_type;
@@ -2417,7 +2327,6 @@ pub(super) fn decode_leaf_rect8(
24172327 u,
24182328 v,
24192329 scan4,
2420- base_q_idx,
24212330 neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx),
24222331 fctx,
24232332 )?;
@@ -2439,7 +2348,6 @@ pub(super) fn decode_leaf_rect8(
24392348 u,
24402349 v,
24412350 scan4,
2442- base_q_idx,
24432351 neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx),
24442352 (bw, bh),
24452353 fctx,
@@ -2452,15 +2360,6 @@ pub(super) fn decode_leaf_rect8(
24522360 }
24532361 continue;
24542362 }
2455- if filter_intra.is_some() {
2456- // lane-fi8 r1: `predict_filter_intra` walks its 4x2 patches over
2457- // a true `bw`x`bh` block, so a 4x8/8x4 leaf predicts through the
2458- // same `reconstruct_rect`/`reconstruct` calls below -- and under
2459- // a split transform, per 4x4 unit with that unit's own edge,
2460- // which is exactly what the depth-1 loop already does.
2461- hit!(FILTER_INTRA_RECT_HITS);
2462- hit!(FILTER_INTRA_RECT_SUB8_HITS);
2463- }
24642363 // `TxMode::Select`'s `tx_depth` (spec 5.11.16) exists at a 4x8/8x4
24652364 // leaf too, and is read for every intra block, skipped or not. Its
24662365 // category is libaom's `bsize_to_tx_size_cat(BLOCK_4X8) == 0` --
@@ -2480,18 +2379,11 @@ pub(super) fn decode_leaf_rect8(
24802379 let depth = if tx_select && !lossless(fctx) {
24812380 // lane-av1txbands: the `TXFM_CONTEXT` band read every other rect
24822381 // reader already does.
2483- let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh, fctx);
2382+ let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh);
24842383 dec.symbol(&mut cdfs.tx_size_cat0[ctx])
24852384 } else {
24862385 0
24872386 };
2488- if depth != 0 {
2489- hit!(TX_DEPTH_HITS);
2490- hit!(RECT8_SPLIT_TX_HITS);
2491- }
2492- if smooth_neighbor {
2493- hit!(SMOOTH_LUMA_HITS);
2494- }
24952387 let (px, py) = (lmi.1 * MI, lmi.0 * MI);
24962388 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
24972389 // `sub_tx_size_map[TX_4X8] == TX_4X4`: depth 1 splits the leaf into
@@ -2511,7 +2403,6 @@ pub(super) fn decode_leaf_rect8(
25112403 let (ctx_tx_w, ctx_tx_h) = if split { (4, 4) } else { (bw, bh) };
25122404 txfm_partition_update_rect(neighbours, lmi, (ctx_tx_w, ctx_tx_h), (bw, bh));
25132405 if split {
2514- let mut done = 0usize;
25152406 for tu in 0..2usize {
25162407 let tu_mi = if vert {
25172408 (lmi.0 + tu, lmi.1)
@@ -2524,19 +2415,7 @@ pub(super) fn decode_leaf_rect8(
25242415 // (lane-palette2 r12): a transform unit inside a block is not
25252416 // a block at that position, so its reach comes from the
25262417 // block's own row, offset by the unit's position.
2527- let tu_reach = tu_reach(
2528- bw,
2529- bh,
2530- tu_px - px,
2531- tu_py - py,
2532- 4,
2533- reach,
2534- px,
2535- py,
2536- y.width,
2537- y.height,
2538- fctx,
2539- );
2418+ let tu_reach = tu_reach(bw, bh, tu_px - px, tu_py - py, 4, reach);
25402419 let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1);
25412420 if skip {
25422421 // A skipped leaf still predicts per transform unit: the
@@ -2586,25 +2465,14 @@ pub(super) fn decode_leaf_rect8(
25862465 tu_py,
25872466 4,
25882467 TX4,
2589- base_q_idx,
25902468 None,
25912469 filter_intra,
25922470 Some(tu_skip_ctx),
25932471 smooth_neighbor,
25942472 fctx,
25952473 )?;
2596- if tu_grid.iter().any(|&l| l != 0) {
2597- done += 1;
2598- }
25992474 neighbours.record_mi_luma(tu_mi, 4, &tu_grid);
26002475 }
2601- if done > 0 {
2602- if vert {
2603- hit!(TX4X8_CODED_HITS);
2604- } else {
2605- hit!(TX8X4_CODED_HITS);
2606- }
2607- }
26082476 neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);
26092477 neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, 4, 4, 0, fctx);
26102478 if has_chroma {
@@ -2627,7 +2495,6 @@ pub(super) fn decode_leaf_rect8(
26272495 u,
26282496 v,
26292497 scan4,
2630- base_q_idx,
26312498 neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx),
26322499 fctx,
26332500 )?;
@@ -2655,7 +2522,6 @@ pub(super) fn decode_leaf_rect8(
26552522 u,
26562523 v,
26572524 scan4,
2658- base_q_idx,
26592525 neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx),
26602526 (bw, bh),
26612527 fctx,
@@ -2712,15 +2578,7 @@ pub(super) fn decode_leaf_rect8(
27122578 0,
27132579 dc_sign_ctx(around.2),
27142580 TxType::DctDct,
2715- 0,
27162581 )?;
2717- if levels.iter().any(|&l| l != 0) {
2718- if vert {
2719- hit!(TX4X8_CODED_HITS);
2720- } else {
2721- hit!(TX8X4_CODED_HITS);
2722- }
2723- }
27242582 let residual = dequant_and_inverse_typed_wh(
27252583 &levels,
27262584 bw,
@@ -2791,7 +2649,6 @@ pub(super) fn decode_leaf_rect8(
27912649 u,
27922650 v,
27932651 scan4,
2794- base_q_idx,
27952652 neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx),
27962653 fctx,
27972654 )?;
@@ -2822,7 +2679,6 @@ pub(super) fn decode_leaf_rect8(
28222679 u,
28232680 v,
28242681 scan4,
2825- base_q_idx,
28262682 neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx),
28272683 (bw, bh),
28282684 fctx,
@@ -2881,10 +2737,6 @@ pub(super) fn decode_leaf_rect8(
28812737 // merge keeps one fix and feeds both lanes' counters so neither of
28822738 // their gates goes vacuous.
28832739 let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
2884- if alpha.is_some() {
2885- hit!(CHROMA_SKIP_CFL_HITS);
2886- hit!(SKIP_CFL_HITS);
2887- }
28882740 push_intra(
28892741 y,
28902742 u,
@@ -2928,7 +2780,6 @@ pub(super) fn decode_leaf_rect8(
29282780 // arm-without-clear-on-a-skip-route). Counted so a gate can tell a
29292781 // stream that reaches this route from one that never does.
29302782 if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() {
2931- hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS);
29322783 fctx.intrabc_chroma_tx.with(|c| c.set(None));
29332784 }
29342785 (Grid::Zero(16), Grid::Zero(16))
@@ -3005,7 +2856,6 @@ pub(super) fn decode_leaf_rect8(
30052856 &ZERO_RESIDUAL[..16],
30062857 fctx,
30072858 );
3008- hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS);
30092859 fctx.intrabc_chroma_tx.with(|c| c.set(None));
30102860 (Grid::Zero(16), Grid::Zero(16))
30112861 } else {
@@ -3029,7 +2879,6 @@ pub(super) fn decode_leaf_rect8(
30292879 cpy,
30302880 4,
30312881 TX4,
3032- base_q_idx,
30332882 None,
30342883 None,
30352884 None,
@@ -3055,7 +2904,6 @@ pub(super) fn decode_leaf_rect8(
30552904 cpy,
30562905 4,
30572906 TX4,
3058- base_q_idx,
30592907 None,
30602908 None,
30612909 None,
@@ -3086,7 +2934,6 @@ pub(super) fn decode_leaf_rect8(
30862934 cpy,
30872935 4,
30882936 TX4,
3089- base_q_idx,
30902937 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
30912938 None,
30922939 None,
@@ -3111,7 +2958,6 @@ pub(super) fn decode_leaf_rect8(
31112958 cpy,
31122959 4,
31132960 TX4,
3114- base_q_idx,
31152961 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
31162962 None,
31172963 None,
crates/ec-av1/src/decode/mod.rsmodified+7 -522
@@ -20,7 +20,6 @@
2020 //! inside one, forcing the gathered-CDF partial-superblock path, is round 2
2121 //! too). Anything outside that refuses with [`Error::unsupported`] rather than
2222 //! silently miscoding.
23-use crate::hits::{hit, hit_do};
2423
2524 use ec_av1_syntax::{
2625 CdefParams, DeltaParams, LoopFilterParams, LoopRestorationParams, MAX_SEGMENTS,
@@ -41,9 +40,6 @@ use ec_core::{Error, Result};
4140 // itself was lifted by lane-av112bitc before that (the combines absorb the
4241 // CONV_BUF gain drop, `INTER_POST_ROUND - delta`, see `mc::combine_compound`).
4342
44-mod counters;
45-pub use counters::*;
46-
4743 mod frame_tile;
4844
4945 mod inter_block8;
@@ -71,7 +67,7 @@ use rect4::*;
7167
7268 mod block;
7369 mod wave;
74-pub use block::*;
70+pub(crate) use block::*;
7571
7672 mod leaf8;
7773 use leaf8::*;
@@ -100,9 +96,6 @@ pub use key_tile::*;
10096 mod inter_ctx;
10197 pub(crate) use inter_ctx::*;
10298
103-#[cfg(test)]
104-mod obmc_skip_chroma_tests;
105-
10699 mod sub8_inter;
107100 pub(crate) use frame_tile::*;
108101 use sub8_inter::*;
@@ -437,38 +430,6 @@ thread_local! {
437430 static COEFF_TRACE_CUR: std::cell::Cell<usize> = const { std::cell::Cell::new(usize::MAX) };
438431 }
439432
440-/// Called by [`crate::stream::decode_stream`] before each frame's tiles with
441-/// that frame's DECODE-order index.
442-pub fn set_coeff_trace_frame(idx: usize) {
443- COEFF_TRACE_FRAME.with(|c| {
444- if c.get().is_none() {
445- let want = match crate::envflags::var("EC_TRACE_COEFF_FRAME") {
446- Ok(v) => v.parse::<usize>().unwrap_or(usize::MAX),
447- // unset: keep tracing every frame, as before this rung existed
448- Err(_) => usize::MAX - 1,
449- };
450- c.set(Some(want));
451- }
452- });
453- COEFF_TRACE_CUR.with(|c| c.set(idx));
454- if crate::envflags::env_flag!("EC_TRACE_COEFF") {
455- eprintln!("EC_COEFF_FRAME decode_idx={idx}");
456- }
457-}
458-
459-pub(crate) fn coeff_trace_on() -> bool {
460- if !crate::envflags::env_flag!("EC_TRACE_COEFF") {
461- return false;
462- }
463- match COEFF_TRACE_FRAME.with(|c| c.get()) {
464- // no `set_coeff_trace_frame` caller (direct tile-decode tests), or the
465- // env var unset: trace every frame.
466- None => true,
467- Some(w) if w >= usize::MAX - 1 => true,
468- Some(w) => COEFF_TRACE_CUR.with(|c| c.get()) == w,
469- }
470-}
471-
472433 /// Sets [`SB128`] for this thread (called once per frame from `stream.rs`).
473434 pub(crate) fn set_sb128(v: bool, fctx: &crate::decode::FrameCtx) {
474435 fctx.sb128_flag.with(|c| c.set(v));
@@ -550,20 +511,6 @@ thread_local! {
550511 static PART128_GATHERED_SYMBOLS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
551512 }
552513
553-/// Current value of `PART128_GATHERED_SYMBOLS`: 128 roots that read the
554-/// half-out-of-frame gathered split_or_horz/split_or_vert symbol (spec
555-/// 5.11.4), which this decoder used to read and throw away.
556-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
557-pub(crate) fn part128_gathered_symbols() -> usize {
558- PART128_GATHERED_SYMBOLS.with(|c| c.get())
559-}
560-
561-/// Current value of [`PART128_SYMBOLS`].
562-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
563-pub(crate) fn part128_symbols() -> usize {
564- PART128_SYMBOLS.with(|c| c.get())
565-}
566-
567514 /// [`gather`] over an alphabet of any length -- the 128-level partition CDF
568515 /// has 8 symbols (no `PARTITION_HORZ_4`/`_VERT_4` at `BLOCK_128X128`, spec
569516 /// `partition_cdf_length`), so its forced-split gather sums 5 elements where
@@ -670,11 +617,7 @@ pub(crate) fn superres(fctx: &crate::decode::FrameCtx) -> Option<(u32, u32)> {
670617 /// for a rectangular luma block (8x16, 16x8) or a PARTITION_HORZ/VERT strip is
671618 /// bigger than the real block in one axis.
672619 pub(crate) fn warp_plane_allowed(w: usize, h: usize) -> bool {
673- if w >= 8 && h >= 8 {
674- return true;
675- }
676- hit!(WARP_PLANE_SUPPRESS_HITS);
677- false
620+ w >= 8 && h >= 8
678621 }
679622
680623 /// This frame's [`QUANT_DELTAS`] `(dc, ac)` pair for plane `plane_idx` (0 =
@@ -779,7 +722,6 @@ fn maybe_read_delta_q(
779722 }
780723 let sign_negative = if abs != 0 { dec.literal(1) != 0 } else { true };
781724 let reduced = if sign_negative { -abs } else { abs };
782- hit!(DELTA_Q_HITS);
783725 let res = fctx.delta_q_res.with(|c| c.get());
784726 fctx.current_q_idx
785727 .with(|c| c.set((c.get() + reduced * res).clamp(1, 255)));
@@ -835,7 +777,6 @@ fn maybe_read_delta_lf(
835777 let sign_negative = if abs != 0 { dec.literal(1) != 0 } else { true };
836778 let reduced = if sign_negative { -abs } else { abs };
837779 cur[i] = (cur[i] + reduced * res).clamp(-63, 63);
838- hit!(DELTA_LF_HITS);
839780 }
840781 fctx.current_delta_lf.with(|c| c.set(cur));
841782 }
@@ -863,7 +804,6 @@ fn maybe_read_cdef_idx(
863804 }
864805 let idx = dec.literal(u32::from(bits)) as u8;
865806 fctx.cdef_transmitted.with(|c| c.set(true));
866- hit!(CDEF_IDX_HITS);
867807 let (sb_r, sb_c) = (mi_r / SB_MI as usize, mi_c / SB_MI as usize);
868808 let sb_cols = fctx.cdef_sb_cols.with(|c| c.get());
869809 if sb_cols > 0 {
@@ -913,17 +853,6 @@ pub(crate) fn set_segmentation(
913853 prev: Option<&[u8]>,
914854 fctx: &crate::decode::FrameCtx,
915855 ) {
916- if crate::envflags::env_flag!("EC_HDR") {
917- eprintln!(
918- "EC_SEGHDR enabled={} update_map={} temporal={} preskip={} last_active={} data={:?}",
919- seg.enabled,
920- seg.update_map,
921- seg.temporal_update,
922- seg.seg_id_pre_skip,
923- seg.last_active_seg_id,
924- seg.feature_data
925- );
926- }
927856 fctx.seg.with(|s| *s.borrow_mut() = seg);
928857 fctx.seg_mi_dims.with(|c| c.set((mi_rows, mi_cols)));
929858 fctx.seg_ids
@@ -950,19 +879,6 @@ pub(crate) fn take_segment_ids(fctx: &crate::decode::FrameCtx) -> Vec<u8> {
950879 fctx.seg_ids.with(|m| m.borrow().clone())
951880 }
952881
953-/// How many distinct segment ids any decoded block has carried.
954-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
955-pub(crate) fn segment_ids_seen() -> usize {
956- SEG_IDS_SEEN.with(|c| c.get().count_ones() as usize)
957-}
958-
959-/// The lowest and highest quantizer index any decoded block was dequantized
960-/// with (`(i32::MAX, i32::MIN)` when nothing decoded).
961-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
962-pub(crate) fn block_q_span() -> (i32, i32) {
963- BLOCK_Q_SPAN.with(|c| c.get())
964-}
965-
966882 /// `seg_feature_active_idx(segment_id, feature)` for the frame currently
967883 /// being decoded, with its `FeatureData` value.
968884 fn seg_feature(segment_id: usize, feature: usize, fctx: &crate::decode::FrameCtx) -> Option<i32> {
@@ -987,13 +903,6 @@ fn block_q_idx(fctx: &crate::decode::FrameCtx) -> i32 {
987903 // lane-d792: which SEGMENT a block's quantizer came out of, beside the
988904 // `EC_DQCOEFF` grid rung -- a dequant that is too low with the levels
989905 // already proven equal is a segment-id defect, not a quantizer one.
990- if crate::envflags::env_flag!("EC_DQCOEFF") {
991- eprintln!("OUR_Q base={base} seg={seg_id} q={q}");
992- }
993- hit_do!(BLOCK_Q_SPAN.with(|c| {
994- let (lo, hi) = c.get();
995- c.set((lo.min(q), hi.max(q)));
996- }););
997906 q
998907 }
999908
@@ -1163,17 +1072,10 @@ fn read_segment_id(
11631072 return pred as u8;
11641073 }
11651074 let coded = dec.symbol(&mut cdfs.segment_id[ctx]) as i32;
1166- hit!(SEG_ID_HITS);
11671075 let last_active = fctx.seg.with(|s| i32::from(s.borrow().last_active_seg_id));
11681076 let id = neg_deinterleave(coded, pred, last_active + 1).clamp(0, last_active);
11691077 // Mirrors the oracle's own `EC_SEG mi_row=.. cdf=.. pred=.. coded=.. id=..`
11701078 // (libaom `decodemv.c:read_segment_id`), for a cross-decoder segment diff.
1171- if crate::envflags::env_flag!("EC_TRACE_SEG") {
1172- eprintln!(
1173- "EC_SEG mi_row={mi_r} mi_col={mi_c} cdf={ctx} pred={pred} coded={coded} id={id} rng={}",
1174- dec.debug_state().0
1175- );
1176- }
11771079 id as u8
11781080 }
11791081
@@ -1266,7 +1168,6 @@ fn inter_segment_id(
12661168 let id = if temporal_update {
12671169 let ctx = seg_pred_ctx(mi_r, mi_c, fctx);
12681170 let predicted = dec.symbol(&mut cdfs.segment_pred[ctx]) != 0;
1269- hit!(SEG_PRED_HITS);
12701171 stamp_seg_pred(mi_r, mi_c, w_mi, h_mi, u8::from(predicted), fctx);
12711172 if predicted {
12721173 predicted_segment_id(mi_r, mi_c, w_mi, h_mi, fctx)
@@ -1340,18 +1241,8 @@ fn tu_reach(
13401241 row_off: usize,
13411242 tx: usize,
13421243 block: Reach,
1343- px: usize,
1344- py: usize,
1345- width: usize,
1346- height: usize,
1347- fctx: &crate::decode::FrameCtx,
13481244 ) -> Reach {
1349- let fixed = Reach::of_tu(bw, bh, col_off, row_off, tx, tx, block);
1350- let standalone = Reach::of(tx, px + col_off, py + row_off, width, height, fctx);
1351- if fixed != standalone {
1352- hit!(SPLIT_TU_REACH_FIX_HITS);
1353- }
1354- fixed
1245+ Reach::of_tu(bw, bh, col_off, row_off, tx, tx, block)
13551246 }
13561247
13571248 /// [`tu_reach`] for a unit whose LUMA footprint is a `tx_w` x `tx_h` rect
@@ -1370,42 +1261,17 @@ fn tu_reach_rect(
13701261 tx_w: usize,
13711262 tx_h: usize,
13721263 block: Reach,
1373- px: usize,
1374- py: usize,
1375- width: usize,
1376- height: usize,
1377- fctx: &crate::decode::FrameCtx,
13781264 ) -> Reach {
1379- let fixed = Reach::of_tu(bw, bh, col_off, row_off, tx_w, tx_h, block);
1380- if tx_w == tx_h {
1381- let standalone = Reach::of(tx_w, px + col_off, py + row_off, width, height, fctx);
1382- if fixed != standalone {
1383- hit!(SPLIT_TU_REACH_FIX_HITS);
1384- }
1385- }
1386- fixed
1265+ Reach::of_tu(bw, bh, col_off, row_off, tx_w, tx_h, block)
13871266 }
13881267
1389-/// lane-comppin r4: decode-order picture counter for `EC_AV1_PREFILT_DUMP`,
1390-/// mirroring stream.rs's `pictures_decoded` so the two dumps index
1391-/// identically against aomdec's own `ec_frame_idx` in decodeframe.c.
1392-static PREFILT_PICTURE_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
1393-
13941268 /// Records one decoded forward keyframe (see [`FWD_KF_HITS`]).
1395-pub(crate) fn note_fwd_kf() {
1396- hit!(FWD_KF_HITS);
1397-}
1269+pub(crate) fn note_fwd_kf() {}
13981270
13991271 thread_local! {
14001272 static TXFM_SPLIT_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
14011273 }
14021274
1403-/// Current value of [`TXFM_SPLIT_READS`].
1404-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1405-pub(crate) fn txfm_split_reads() -> usize {
1406- TXFM_SPLIT_READS.with(|c| c.get())
1407-}
1408-
14091275 /// Sets the current thread's [`TX_SELECT_INTER`]/[`REDUCED_TX_SET_INTER`]/
14101276 /// [`ENABLE_FILTER_INTRA_INTER`].
14111277 pub(crate) fn set_inter_tx_mode(
@@ -1422,37 +1288,6 @@ pub(crate) fn set_inter_tx_mode(
14221288 .with(|c| c.set(enable_filter_intra));
14231289 }
14241290
1425-fn bump_ab16(arm: usize) {
1426- hit_do! {
1427- AB16_HITS.with(|c| {
1428- let mut v = c.get();
1429- v[arm] += 1;
1430- c.set(v);
1431- });
1432- }
1433-}
1434-
1435-/// Bumps one bucket of [`INTER_EDGE_STRIP_HITS`].
1436-pub(crate) fn bump_inter_edge_strip(idx: usize) {
1437- hit_do! {
1438- INTER_EDGE_STRIP_HITS.with(|c| {
1439- let mut v = c.get();
1440- v[idx] += 1;
1441- c.set(v);
1442- });
1443- }
1444-}
1445-
1446-fn bump_edge_both_cut(level: usize) {
1447- hit_do! {
1448- EDGE_BOTH_CUT_HITS.with(|c| {
1449- let mut v = c.get();
1450- v[level] += 1;
1451- c.set(v);
1452- });
1453- }
1454-}
1455-
14561291 // lane-av1muchroma site 1: the total number of samples by which
14571292 // `decode_block`'s SKIP arm chroma bookkeeping grids fell SHORT of their own
14581293 // plane block, summed over every skipped block decoded. It reads the
@@ -1467,12 +1302,6 @@ thread_local! {
14671302 const { std::cell::Cell::new(0) };
14681303 }
14691304
1470-/// Current value of [`SKIP_ARM_CHROMA_SHORT_SAMPLES`].
1471-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1472-pub(crate) fn skip_arm_chroma_short_samples() -> usize {
1473- SKIP_ARM_CHROMA_SHORT_SAMPLES.with(|c| c.get())
1474-}
1475-
14761305 // Number of times `decode_block`'s SKIP arm ran at a shape where the
14771306 // per-axis and square chroma allocations DIFFER -- i.e. at 4:2:2, where
14781307 // the square is half the plane block. Zero on 4:2:0 and 4:4:4, where the
@@ -1484,12 +1313,6 @@ thread_local! {
14841313 const { std::cell::Cell::new(0) };
14851314 }
14861315
1487-/// Current value of [`SKIP_ARM_CHROMA_RECT_SHAPES`].
1488-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1489-pub(crate) fn skip_arm_chroma_rect_shapes() -> usize {
1490- SKIP_ARM_CHROMA_RECT_SHAPES.with(|c| c.get())
1491-}
1492-
14931316 // lane-av1floorshift: the two FRAME chroma plane allocators
14941317 // (`decode_key_frame_tile_with_cdfs` and `decode_inter_tile`'s `PlaneBuf` trio)
14951318 // size U and V as `(width >> ss_x) x (height >> ss_y)` with `width`/`height`
@@ -1532,152 +1355,6 @@ thread_local! {
15321355 const { std::cell::Cell::new(0) };
15331356 }
15341357
1535-/// Current value of [`FRAME_CHROMA_ALLOC_CALLS`].
1536-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1537-pub(crate) fn frame_chroma_alloc_calls() -> usize {
1538- FRAME_CHROMA_ALLOC_CALLS.with(|c| c.get())
1539-}
1540-
1541-/// Current value of [`FRAME_CHROMA_ALLOC_SHORT_SAMPLES`].
1542-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1543-pub(crate) fn frame_chroma_alloc_short_samples() -> usize {
1544- FRAME_CHROMA_ALLOC_SHORT_SAMPLES.with(|c| c.get())
1545-}
1546-
1547-/// Current value of [`FRAME_CHROMA_ALLOC_CROP_SHAPES`].
1548-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1549-pub(crate) fn frame_chroma_alloc_crop_shapes() -> usize {
1550- FRAME_CHROMA_ALLOC_CROP_SHAPES.with(|c| c.get())
1551-}
1552-
1553-/// The census both frame chroma plane allocators share. `shape` is the frame's
1554-/// own 32-aligned coded `(width, height)`, `ss` its `(ss_x, ss_y)`.
1555-///
1556-/// `round_ss` is libaom's chroma CROP (`av1_round_shift`), the extent the
1557-/// committed reference planes are stored at and the bound every chroma walk
1558-/// inside the tile is clamped against.
1559-///
1560-/// `alloc` is the allocator's OWN `(cw, ch)` -- the numbers that size the
1561-/// `PlaneBuf` -- not a recomputation of them. That is what makes the gate
1562-/// bite: the shortfall is a difference between what was allocated and what the
1563-/// tile may address, so replacing the shift with a bare `>> 1` (the 4:2:0-only
1564-/// form this lane's target class is made of) moves it on the 4:2:2 and 4:4:4
1565-/// witnesses, where the correct shift and the hardcoded one are different
1566-/// numbers. A counter that recomputed `shape >> ss` beside the allocation
1567-/// would have read the same value either way and proved nothing.
1568-fn note_frame_chroma_alloc(shape: (usize, usize), alloc: (usize, usize), ss: (usize, usize)) {
1569- hit!(FRAME_CHROMA_ALLOC_CALLS);
1570- let (need_w, need_h) = (round_ss(shape.0, ss.0), round_ss(shape.1, ss.1));
1571- // Decidability: the floor and the crop are the same number on this frame,
1572- // so the shortfall below is the same number the two forms would have given.
1573- if (need_w, need_h) != (shape.0 >> ss.0, shape.1 >> ss.1) {
1574- hit!(FRAME_CHROMA_ALLOC_CROP_SHAPES);
1575- if crate::envflags::env_flag!("EC_AV1_CHROMA_ALLOC_SWEEP") {
1576- eprintln!(
1577- "CHROMA_ALLOC luma={}x{} ss={:?} floor={}x{} round_ss={}x{} alloc={}x{}",
1578- shape.0,
1579- shape.1,
1580- ss,
1581- shape.0 >> ss.0,
1582- shape.1 >> ss.1,
1583- need_w,
1584- need_h,
1585- alloc.0,
1586- alloc.1,
1587- );
1588- }
1589- }
1590- let want = need_w * need_h;
1591- let got = alloc.0 * alloc.1;
1592- if want > got {
1593- hit_do!(FRAME_CHROMA_ALLOC_SHORT_SAMPLES.with(|c| c.set(c.get() + want - got)));
1594- }
1595-}
1596-
1597-/// lane-av1ibcfork: this decoder's half of the per-unit BIT INTERVAL -- the
1598-/// exact mirror of the oracle's `EC_ECDUMP_IN` / `EC_ECDUMP_OUT` /
1599-/// `EC_ECDUMP_END` triple (`aom-oracle2/src/av1/decoder/decodetxb.c`: one
1600-/// print in `read_coeffs_txb` before and after its `aom_read_symbol`, one in
1601-/// the single caller `av1_read_coeffs_txb` after the whole unit).
1602-///
1603-/// Why three prints and not one `EC_CENSUS_UNIT`: a COUNT is not a key. The
1604-/// two sides can walk a different NUMBER of units and still be paired, because
1605-/// the interval is what a unit CONSUMED. Entry position alone drifts the moment
1606-/// one side consumes a different number of bits, and list index is invalid the
1607-/// moment one side misses a unit -- both were measured here and both
1608-/// mis-attribute. `post_bit` after the `txb_skip` read is the same
1609-/// `aom_reader_tell` the oracle prints there; `end_bit` is the end of the whole
1610-/// unit including the optional luma `tx_type`, the eob, the base/BR passes and
1611-/// the sign/Golomb loop, so a unit that reads the right symbols in the wrong
1612-/// ORDER is caught too.
1613-///
1614-/// `bit` counts the bits this decoder has pulled out of its window, so it sits
1615-/// at a CONSTANT offset from the oracle's tell (the OBU header libaom counts
1616-/// before `aom_reader_init`). The offset is measured per fixture, never
1617-/// assumed: +14 on `444_intrabc_rect4_witness.obu`.
1618-#[inline]
1619-fn unit_iv_on() -> bool {
1620- crate::envflags::env_flag!("EC_UNITIV")
1621-}
1622-
1623-/// The unit's ENTRY position. Returns it so the caller can pass the same value
1624-/// to [`unit_iv_skip`] and [`unit_iv_end`] without reading the decoder again.
1625-#[inline]
1626-#[track_caller]
1627-fn unit_iv_in(plane: usize, w: usize, h: usize, ctx: usize, dec: &SymbolDecoder) -> usize {
1628- if !unit_iv_on() {
1629- return 0;
1630- }
1631- let bit = dec.debug_bitpos();
1632- let (mi_r, mi_c) = SymbolDecoder::symr_mi();
1633- eprintln!(
1634- "EC_UNITIV_IN side=ours plane={plane} mi=({mi_r},{mi_c}) w={w} h={h} ctx={ctx} bit={bit} at {}",
1635- std::panic::Location::caller()
1636- );
1637- bit
1638-}
1639-
1640-/// The position immediately after this unit's `txb_skip` read. `bit_in ==
1641-/// post_bit` means the read consumed ZERO bits (a CDF row already at a
1642-/// boundary), so this is also the real-read filter: the reader logs a step
1643-/// either way, and counting raw lines overstates the symbol count ~2x (measured
1644-/// on `444_intrabc_rect4_witness.obu`: 2395 lines, 512 real reads, against the
1645-/// oracle's 513 -- not the "~1069 fewer" an earlier round reported).
1646-#[inline]
1647-fn unit_iv_skip(
1648- dec: &SymbolDecoder,
1649- bit_in: usize,
1650- plane: usize,
1651- w: usize,
1652- h: usize,
1653- ctx: usize,
1654- all_zero: bool,
1655-) {
1656- if !unit_iv_on() {
1657- return;
1658- }
1659- let (mi_r, mi_c) = SymbolDecoder::symr_mi();
1660- eprintln!(
1661- "EC_UNITIV_SKIP side=ours plane={plane} mi=({mi_r},{mi_c}) w={w} h={h} ctx={ctx} az={} bit={bit_in} post_bit={}",
1662- all_zero as i32,
1663- dec.debug_bitpos()
1664- );
1665-}
1666-
1667-/// The position after the WHOLE unit. One call per successful read, on both
1668-/// the all-zero early return and the full coefficient walk.
1669-#[inline]
1670-fn unit_iv_end(dec: &SymbolDecoder, plane: usize, w: usize, h: usize, ctx: usize) {
1671- if !unit_iv_on() {
1672- return;
1673- }
1674- let (mi_r, mi_c) = SymbolDecoder::symr_mi();
1675- eprintln!(
1676- "EC_UNITIV_END side=ours plane={plane} mi=({mi_r},{mi_c}) w={w} h={h} ctx={ctx} end_bit={}",
1677- dec.debug_bitpos()
1678- );
1679-}
1680-
16811358 /// A just-decoded palette-Y block's own predicted pixels
16821359 /// (`side*side`, row-major, `colors[map[i]]`), consumed by
16831360 /// [`PlaneBuf::reconstruct`]'s next call in place of `predict()` -- the
@@ -1724,27 +1401,12 @@ fn palette_window(
17241401 /// `EC_DEBUG_PAL=1` traces every arm and every consumption with its call site.
17251402 #[track_caller]
17261403 fn set_palette_pred(buf: Vec<u16>, fctx: &crate::decode::FrameCtx) {
1727- if crate::envflags::env_flag!("EC_DEBUG_PAL") {
1728- let stale = fctx.palette_pred.with(|c| c.borrow().is_some());
1729- eprintln!(
1730- "PALSET len={} stale={stale} at {}",
1731- buf.len(),
1732- std::panic::Location::caller()
1733- );
1734- }
17351404 fctx.palette_pred.with(|c| *c.borrow_mut() = Some(buf));
17361405 }
17371406
17381407 #[track_caller]
17391408 fn take_palette_pred(fctx: &crate::decode::FrameCtx) -> Option<Vec<u16>> {
17401409 let got = fctx.palette_pred.with(|c| c.borrow_mut().take());
1741- if crate::envflags::env_flag!("EC_DEBUG_PAL") {
1742- eprintln!(
1743- "PALTAKE len={:?} at {}",
1744- got.as_ref().map(Vec::len),
1745- std::panic::Location::caller()
1746- );
1747- }
17481410 got
17491411 }
17501412
@@ -1809,13 +1471,6 @@ pub(crate) struct TxParams {
18091471 /// ran on a frame that is NOT `CodedLossless`.
18101472 static LOSSLESS_WHT_UNITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
18111473
1812-/// [`LOSSLESS_WHT_UNITS`] -- total over the process, read as a before/after
1813-/// delta around one decode.
1814-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1815-pub(crate) fn lossless_wht_units() -> usize {
1816- LOSSLESS_WHT_UNITS.load(std::sync::atomic::Ordering::Relaxed)
1817-}
1818-
18191474 /// lane-whtshape: 4x4 Walsh-Hadamard units reconstructed as part of a LOSSLESS
18201475 /// transform unit that was itself NOT 4x4 -- a shape libaom cannot code.
18211476 /// `read_tx_mode` (`av1/decoder/decodeframe.c:140`) returns `ONLY_4X4` for a
@@ -1832,13 +1487,6 @@ pub(crate) fn lossless_wht_units() -> usize {
18321487 static LOSSLESS_WHT_SPLIT_UNITS: std::sync::atomic::AtomicUsize =
18331488 std::sync::atomic::AtomicUsize::new(0);
18341489
1835-/// [`LOSSLESS_WHT_SPLIT_UNITS`] -- total over the process, read as a
1836-/// before/after delta around one decode.
1837-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1838-pub(crate) fn lossless_wht_split_units() -> usize {
1839- LOSSLESS_WHT_SPLIT_UNITS.load(std::sync::atomic::Ordering::Relaxed)
1840-}
1841-
18421490 impl TxParams {
18431491 /// The one copy of the produce-the-residual code.
18441492 fn run(self, grid: &[i32]) -> Vec<i32> {
@@ -2179,14 +1827,6 @@ fn push_mc_rect(
21791827 // localized a 4:4:4 intra-BC SKIP block committing its chroma plane block
21801828 // at `(px/2, py/2)` instead of the ss origin, clobbering a neighbouring
21811829 // block's reconstruction (lanes/av1ibcfork.report.md).
2182- if crate::envflags::env_flag!("EC_MCPUSH") {
2183- eprintln!(
2184- "EC_MCPUSH plane={plane} x={x} y={cy} stride={stride} w={w} h={h} \
2185- res_len={} at {}",
2186- residual.len(),
2187- std::panic::Location::caller()
2188- );
2189- }
21901830 let Some((src, stride)) = prediction.inline(stride) else {
21911831 let Pred::Cur {
21921832 plane: sp,
@@ -2501,7 +2141,7 @@ fn exec_mc(
25012141 1 => &mut *u,
25022142 _ => &mut *v,
25032143 };
2504- target.reconstruct_mc_rect(x, oy, plane, stride, w, h, prediction, residual, fctx);
2144+ target.reconstruct_mc_rect(x, oy, stride, w, h, prediction, residual, fctx);
25052145 }
25062146
25072147 // The `tx_type` the last plane-0 [`read_plane`] actually coded, kept so
@@ -2532,11 +2172,6 @@ thread_local! {
25322172 static RECT_INTRABC_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
25332173 }
25342174
2535-/// Current value of [`RECT_INTRABC_READS`].
2536-pub(crate) fn rect_intrabc_reads() -> usize {
2537- RECT_INTRABC_READS.with(|c| c.get())
2538-}
2539-
25402175 thread_local! {
25412176 /// lane-av1-ibc128chunk: the mu-chunk walk's per-axis chroma extents, as
25422177 /// `(64 >> ss_x) << 8 | (64 >> ss_y)` on the LAST chunk -- the pair the
@@ -2546,12 +2181,6 @@ thread_local! {
25462181 const { std::cell::Cell::new(0) };
25472182 }
25482183
2549-/// Current value of [`INTRABC_128RECT_CHUNK_SHAPE`].
2550-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2551-pub fn intrabc_128rect_chunk_shape() -> usize {
2552- INTRABC_128RECT_CHUNK_SHAPE.with(|c| c.get())
2553-}
2554-
25552184 /// Records one coded block into [`INTRABC_MI_GRID`]: every block contributes
25562185 /// its size (libaom's `scan_row_mbmi` advances `processed_rows` off any
25572186 /// candidate's `bsize`, ref-match or not), an intrabc one also its DV as an
@@ -2631,9 +2260,7 @@ fn record_intrabc_mi_rect(
26312260
26322261 /// Bump [`FIMV_FRAME_HITS`] -- called once per decoded frame header whose
26332262 /// `force_integer_mv` bit is set.
2634-pub fn note_force_integer_mv_frame() {
2635- hit!(FIMV_FRAME_HITS);
2636-}
2263+pub fn note_force_integer_mv_frame() {}
26372264
26382265 // lane-t900 r27: OBMC blends that actually READ a recorded switchable filter
26392266 // off the neighbour band -- the positive half of the proof for "an OBMC
@@ -2645,48 +2272,6 @@ thread_local! {
26452272 static OBMC_FILTER_BAND_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
26462273 }
26472274
2648-/// Current value of [`OBMC_FILTER_BAND_READS`].
2649-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2650-pub(crate) fn obmc_filter_band_reads() -> usize {
2651- OBMC_FILTER_BAND_READS.with(|c| c.get())
2652-}
2653-
2654-/// lane-inter16ab r5: the six RECTANGULAR wedge shapes, in this order --
2655-/// the counter slots of [`RECT_WEDGE_HITS`]/[`RECT_WII_HITS`].
2656-pub(crate) const RECT_WEDGE_SHAPES: [(usize, usize); 6] =
2657- [(8, 16), (16, 8), (16, 32), (32, 16), (8, 32), (32, 8)];
2658-
2659-fn rect_wedge_slot(bw: usize, bh: usize) -> Option<usize> {
2660- RECT_WEDGE_SHAPES.iter().position(|&s| s == (bw, bh))
2661-}
2662-
2663-// lane-intra14 r1: set while an INTRA block of an INTER frame is decoded
2664-// through one of the key-frame rect readers ([`decode_block_rect4`],
2665-// [`decode_block_rect64`]). `Some((size_group, skip))` tells
2666-// [`read_intra_mode_rect`] that (a) `skip`/segment id/cdef/delta-q were
2667-// already read by [`decode_inter_block`] and (b) the luma mode comes off
2668-// `y_mode_cdf[size_group_lookup[bsize]]` (libaom `read_intra_block_mode_info`,
2669-// decodemv.c:1189), never the key frame's above/left `kf_y_mode` pair.
2670-
2671-// lane-modectx r1: how many times a `kf_y_mode`/`y_mode` neighbour read at a
2672-// TILE edge found its coarse fallback band holding a NON-DC mode -- i.e. a
2673-// mode from the previous tile, where libaom's `up_available`/`left_available`
2674-// make the neighbour DC_PRED. Measured 0 over 20 two-tile-column streams:
2675-// `above_mode` is cleared per tile in `Neighbours::start_tile` and `left_mode`
2676-// per superblock row in `start_row`, so the luma fallback cannot leak the way
2677-// lane-mtfix's `above_uv_mode` one did. The gate asserts it stays 0 -- this is
2678-// the invariant that makes the coarse fallback safe.
2679-thread_local! {
2680- static MODE_TILE_EDGE_COARSE_LEAKS: std::cell::Cell<usize> =
2681- const { std::cell::Cell::new(0) };
2682-}
2683-
2684-/// Current value of [`MODE_TILE_EDGE_COARSE_LEAKS`].
2685-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2686-pub(crate) fn mode_tile_edge_coarse_leaks() -> usize {
2687- MODE_TILE_EDGE_COARSE_LEAKS.with(|c| c.get())
2688-}
2689-
26902275 thread_local! {
26912276 static UV_LEFT_SS_Y_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
26922277 }
@@ -2702,33 +2287,6 @@ thread_local! {
27022287 static UV_OWNER_EPOCH: std::cell::Cell<u32> = const { std::cell::Cell::new(0) };
27032288 }
27042289
2705-fn bump_edge_part(slot: usize) {
2706- hit_do! {
2707- EDGE_PART_HITS.with(|c| {
2708- let mut h = c.get();
2709- h[slot] += 1;
2710- c.set(h);
2711- });
2712- }
2713-}
2714-
2715-/// [`bump_edge32`] of `base + bit`, returning the bit -- the gathered edge
2716-/// reads are `if`-conditions, so the counter has to ride the expression.
2717-fn bump_edge32_bit(base: usize, bit: usize) -> usize {
2718- bump_edge32(base + bit.min(1));
2719- bit
2720-}
2721-
2722-fn bump_edge32(slot: usize) {
2723- hit_do! {
2724- EDGE32_HITS.with(|c| {
2725- let mut h = c.get();
2726- h[slot] += 1;
2727- c.set(h)
2728- });
2729- }
2730-}
2731-
27322290 /// One 16x4 / 4x16 inter strip's chroma situation, handed to
27332291 /// [`decode_inter_block`] out of band (the same one-shot thread-local idiom
27342292 /// `REDUCED_TX_SET_INTER` uses) rather than through twenty-three call sites
@@ -2750,18 +2308,6 @@ pub(crate) struct InterStripChroma {
27502308 prev: Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>,
27512309 }
27522310
2753-/// The single-reference MC parameters of the inter block that decoded
2754-/// last -- read by the next 1:4 strip to build its pair's chroma.
2755-fn bump_ab16_inter(arm: usize) {
2756- hit_do! {
2757- AB16_INTER_HITS.with(|c| {
2758- let mut v = c.get();
2759- v[arm] += 1;
2760- c.set(v);
2761- });
2762- }
2763-}
2764-
27652311 /// Everything [`decode_inter_block`] needs to fold temporal MV candidates
27662312 /// (spec 7.10.2.8), threaded down from [`decode_inter_frame_tile_with_cdfs`]:
27672313 /// the current frame's own projected field ([`crate::motion_field::setup_motion_field`]'s
@@ -2874,12 +2420,6 @@ pub(crate) fn build_motion_field(
28742420 crate::par::run_bands_mut(&bands, cols, fctx, cells, |r0, r1, mine, _| {
28752421 fill(r0, r1, mine);
28762422 });
2877- if crate::envflags::env_flag!("EC_TRACE_TPL") {
2878- eprintln!("EC_TPL_SAVED oh={order_hint}");
2879- for (r, row) in field.occupancy().iter().enumerate() {
2880- eprintln!("EC_TPL_SAVED r{r} {row}");
2881- }
2882- }
28832423 field
28842424 }
28852425
@@ -2923,38 +2463,12 @@ pub fn cdef_mixed_skip_units() -> usize {
29232463 CDEF_MIXED_SKIP_UNITS.with(|c| c.get())
29242464 }
29252465
2926-/// Current value of `CDEF_SKIPPED_UNITS`.
2927-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2928-pub(crate) fn cdef_skipped_units() -> usize {
2929- CDEF_SKIPPED_UNITS.with(|c| c.get())
2930-}
2931-
29322466 /// How many 8x8 CDEF units [`apply_cdef`] visited whose skip band no coded
29332467 /// block wrote this frame -- a writer gap, always a defect (lane-cdefstrip r1).
29342468 pub fn cdef_unwritten_skip_units() -> usize {
29352469 CDEF_UNWRITTEN_SKIP_UNITS.with(|c| c.get())
29362470 }
29372471
2938-/// Current value of `CDEF_STRADDLE_UNITS`.
2939-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2940-pub(crate) fn cdef_straddle_units() -> usize {
2941- CDEF_STRADDLE_UNITS.with(|c| c.get())
2942-}
2943-
2944-fn note_sub8_chroma_tx(first_sub: TxType, chroma_ref: TxType, coeffs: bool) {
2945- if coeffs && first_sub != chroma_ref {
2946- hit!(SUB8_CHROMA_TX_FROM_REF_HITS);
2947- }
2948-}
2949-
2950-/// Counts one [`CHROMA_EOB_CLASS1_HITS`] when `plane_idx`'s inherited
2951-/// `tx_type` put this block's `eob_pt` on the class-1 row.
2952-fn note_chroma_class1(plane_idx: usize, tx_type: TxType) {
2953- if plane_idx > 0 && TxClass::of(tx_type) != TxClass::TwoD {
2954- hit!(CHROMA_EOB_CLASS1_HITS);
2955- }
2956-}
2957-
29582472 // Which plane the in-flight INTRA reconstruction is writing (0=Y, 1=U, 2=V).
29592473 // lane-av1cmpaudit: aomdec's `EC_PREDOUT8`/`EC_PREDND` print `plane=`, and
29602474 // without the same field on our side an `EC_PREDOUT8` vs `OUR_PRED` diff of a
@@ -2966,11 +2480,6 @@ thread_local! {
29662480 static RECON_PLANE: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
29672481 }
29682482
2969-/// The plane index the `EC_PRED` rung prints as `plane=`.
2970-fn recon_plane() -> usize {
2971- RECON_PLANE.with(std::cell::Cell::get)
2972-}
2973-
29742483 /// Restores [`RECON_PLANE`] on drop, so `exec_intra` needs no cleanup path on
29752484 /// either of its two early returns.
29762485 struct PlaneGuard(usize);
@@ -3030,12 +2539,6 @@ const MAX_BR_LEVEL: i32 = NUM_BASE_LEVELS + COEFF_BASE_RANGE;
30302539 const VERT_ALIKE: [usize; 6] = [2, PARTITION_SPLIT, 4, 6, 7, 9];
30312540 const HORZ_ALIKE: [usize; 6] = [1, PARTITION_SPLIT, 4, 5, 6, 8];
30322541
3033-fn trace_edge(mi_r: usize, mi_c: usize, bsize: u32, ctx: usize, rng: u32) {
3034- if crate::envflags::env_flag!("EC_AV1_TRACE") {
3035- eprintln!("OUR_PART mi_row={mi_r} mi_col={mi_c} bsize={bsize} ctx={ctx} rng={rng}");
3036- }
3037-}
3038-
30392542 fn element_prob(cdf: &[u16], element: usize) -> u16 {
30402543 cdf[element] - if element > 0 { cdf[element - 1] } else { 0 }
30412544 }
@@ -3241,9 +2744,6 @@ fn base_ctx(
32412744 // once; `base_ctx_rect_offsets_match_the_transcribed_tables_over_the_whole_domain`
32422745 // pins the rule against the tables over their whole 5x5 domain.
32432746 if let Some((w, h)) = rect_shape {
3244- if crate::envflags::env_flag!("EC_NZOFF_DUMP") {
3245- eprintln!("NZOFF stride={stride} shape={w}x{h} row={row} col={col}");
3246- }
32472747 if w < h && row < 2 {
32482748 return ctx + 11;
32492749 }
@@ -3657,7 +3157,6 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) ->
36573157 const GROUP_START: [usize; 12] = [0, 1, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513];
36583158 const OFFSET_BITS: [u32; 12] = [0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
36593159
3660- let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
36613160 // libaom's `eob_flag_cdf*` tables carry a second dimension the 2D scan
36623161 // never touches: `TX_CLASS_HORIZ`/`TX_CLASS_VERT` (`V_DCT`/`H_DCT`) adapt
36633162 // a wholly separate CDF from every other tx_type (`decodetxb.c`'s
@@ -3668,22 +3167,11 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) ->
36683167 (TxClass::TwoD, _) | (_, None) => coding.eob_pt,
36693168 (_, Some(class1)) => class1,
36703169 };
3671- if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") {
3672- let (range, value) = dec.debug_state();
3673- eprintln!("EC_AV1_EOBPT_CDF {eob_pt:?} range={range} value={value}");
3674- }
3675- crate::msac::SymbolDecoder::set_symr_cdf("eob_pt");
36763170 let group = dec.symbol(eob_pt) + 1;
3677- if trace {
3678- eprintln!("TRACE eob_pt value={group} rng={}", dec.debug_state().0);
3679- }
36803171 let bits = OFFSET_BITS[group];
36813172 let mut offset = 0u32;
36823173 if bits > 0 {
36833174 let top = dec.symbol(&mut coding.eob_extra[group - 3]) as u32;
3684- if trace {
3685- eprintln!("TRACE eob_extra ctx={} value={top}", group - 3);
3686- }
36873175 offset = top << (bits - 1);
36883176 if bits > 1 {
36893177 offset |= dec.literal(bits - 1);
@@ -3792,6 +3280,3 @@ pub(crate) fn decode_key_frame_tile(
37923280
37933281 #[cfg(test)]
37943282 mod tests;
3795-
3796-#[cfg(test)]
3797-mod tx4x8_table_tests;
crates/ec-av1/src/decode/obmc_skip_chroma_tests.rsdeleted+0 -27
@@ -1,27 +0,0 @@
1-use super::obmc_skip_chroma_above;
2-
3-/// lane-av1-llpred2: the above-chroma skip keys off the PLANE block
4-/// under the frame's own ss pair. At 4:2:0 a 16x8/8x16 rect strip's
5-/// plane block is 8x4/4x8 and MUST still skip (the old `chroma_side`
6-/// ratio read ss=(1,0) off a 16x8 strip and made it blend); at 4:4:4
7-/// the plane block is the luma block, so only true 4-wide/high shapes
8-/// skip and the shift never leaves `usize` range (the old ratio's
9-/// `trailing_zeros(0)` = 64 panicked a debug build).
10-#[test]
11-fn rect_strips_skip_above_chroma_at_420_and_shift_never_overflows() {
12- // 4:2:0 (ss 1,1): 8x8 -> 4x4, 16x8 -> 8x4, 8x16 -> 4x8 all skip.
13- assert!(obmc_skip_chroma_above(8, 8, 1, 1));
14- assert!(obmc_skip_chroma_above(16, 8, 1, 1));
15- assert!(obmc_skip_chroma_above(8, 16, 1, 1));
16- // ... larger plane blocks blend, exactly libaom's own list.
17- assert!(!obmc_skip_chroma_above(16, 16, 1, 1));
18- assert!(!obmc_skip_chroma_above(32, 16, 1, 1));
19- assert!(!obmc_skip_chroma_above(16, 32, 1, 1));
20- // 4:4:4 (ss 0,0): the plane block is the luma block itself.
21- assert!(obmc_skip_chroma_above(4, 4, 0, 0));
22- assert!(obmc_skip_chroma_above(8, 4, 0, 0));
23- assert!(obmc_skip_chroma_above(4, 8, 0, 0));
24- assert!(!obmc_skip_chroma_above(8, 8, 0, 0));
25- assert!(!obmc_skip_chroma_above(16, 8, 0, 0));
26- assert!(!obmc_skip_chroma_above(8, 16, 0, 0));
27-}
crates/ec-av1/src/decode/post_filter.rsmodified+10 -20
@@ -32,7 +32,6 @@ fn cdef_rows(
3232 coeff_shift: i32,
3333 damping: i32,
3434 damping_uv: i32,
35- (frame_w, frame_h): (usize, usize),
3635 r_lo0: usize,
3736 r_hi0: usize,
3837 fctx: &crate::decode::FrameCtx,
@@ -68,16 +67,16 @@ fn cdef_rows(
6867 .enumerate()
6968 .map(|(k, &(a, b))| {
7069 let start = row_of(a, p) * geom[p].stride;
71- let end = if k == last { len } else { row_of(b, p) * geom[p].stride };
70+ let end = if k == last {
71+ len
72+ } else {
73+ row_of(b, p) * geom[p].stride
74+ };
7275 (start, end)
7376 })
7477 .collect()
7578 };
76- let (yd, ud, vd) = (
77- y.data.to_mut(),
78- u.data.to_mut(),
79- v.data.to_mut(),
80- );
79+ let (yd, ud, vd) = (y.data.to_mut(), u.data.to_mut(), v.data.to_mut());
8180 let (ry, ru, rv) = (
8281 plane_ranges(0, yd.len()),
8382 plane_ranges(1, ud.len()),
@@ -97,7 +96,10 @@ fn cdef_rows(
9796 (start, end)
9897 })
9998 .collect();
100- crate::par::carve_ranges(w, &ranges).into_iter().map(Some).collect()
99+ crate::par::carve_ranges(w, &ranges)
100+ .into_iter()
101+ .map(Some)
102+ .collect()
101103 }
102104 None => (0..n).map(|_| None).collect(),
103105 };
@@ -130,7 +132,6 @@ fn cdef_rows(
130132 coeff_shift,
131133 damping,
132134 damping_uv,
133- (frame_w, frame_h),
134135 fctx,
135136 );
136137 });
@@ -144,9 +145,6 @@ pub(super) fn apply_cdef(
144145 v: &mut PlaneBuf<'static>,
145146 cdef: &CdefParams,
146147 skip_grid: &Neighbours,
147- // This frame header's own CROPPED luma size, for the straddling-unit
148- // counter only -- CDEF itself walks the mi-rounded plane.
149- (frame_w, frame_h): (usize, usize),
150148 fctx: &crate::decode::FrameCtx,
151149 // lane-av1cap: every CDEF unit reads the PRE-CDEF planes, so the filter
152150 // starts by copying all three (~19 MB at 4K). The encoder's filter
@@ -161,10 +159,6 @@ pub(super) fn apply_cdef(
161159 wrote: Option<&mut [u8]>,
162160 ) {
163161 // lane-part32 r2 debug rung, env-gated: see `apply_deblock`'s sibling.
164- if crate::envflags::env_flag!("EC_AV1_DEBUG_SKIP_CDEF") {
165- return;
166- }
167- cdef_scan_counters(skip_grid);
168162 // `cdef.bits == 0` still means "no filtering at all" whenever the single
169163 // (index 0) strength pair is all-zero -- the fast path every existing
170164 // gate stream takes. A `bits > 0` frame can still be all-zero-strength
@@ -215,7 +209,6 @@ pub(super) fn apply_cdef(
215209 coeff_shift,
216210 damping,
217211 damping_uv,
218- (frame_w, frame_h),
219212 0,
220213 skip_grid.mi_rows,
221214 fctx,
@@ -296,9 +289,6 @@ pub(super) fn apply_loop_restoration(
296289 fctx: &crate::decode::FrameCtx,
297290 ) {
298291 // lane-svt1 debug rung, env-gated: see `apply_cdef`/`apply_deblock`'s siblings.
299- if crate::envflags::env_flag!("EC_AV1_DEBUG_SKIP_LR") {
300- return;
301- }
302292 let mut out = scratch_empty();
303293 crate::restoration::apply_loop_restoration_plane(
304294 &y.data,
crates/ec-av1/src/decode/rect.rsmodified+5 -506
@@ -61,42 +61,15 @@ pub(super) fn read_intra_mode_rect(
6161 // `palette_uv` even on a chroma-reference strip. Fold the plane count
6262 // into the same `has_chroma` this reader already gates on.
6363 let has_chroma = has_chroma && !mono(fctx);
64- crate::msac::SymbolDecoder::set_symr_mi(mi_r as i64, mi_c as i64);
65- let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");
66- if ec_istep {
67- // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line
68- // (decodemv.c:818), printed at the same point: before the first
69- // mode-info symbol of the block, so a cross-decoder range ladder can
70- // be keyed on the BLOCK, not just on the symbol sequence.
71- eprintln!(
72- "EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=rect bw={bw} bh={bh} efi={} cls={:?} rng={}",
73- enable_filter_intra as i32,
74- filter_intra_size_class_rect(bw, bh),
75- dec.debug_state().0
76- );
77- }
7864 macro_rules! istep {
79- ($name:literal, $val:expr) => {
80- if ec_istep {
81- let (rng, _) = dec.debug_state();
82- eprintln!(
83- "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name={} val={} rng={rng}",
84- $name, $val
85- );
86- }
87- };
65+ ($name:literal, $val:expr) => {};
8866 }
8967 // lane-sbrect10 r1: libaom `is_cfl_allowed` (blockd.h) is
9068 // `block_size_wide <= 32 && block_size_high <= 32` -- enforce it HERE, at
9169 // the one point every rect caller routes through, so no call site can
9270 // offer the 14-symbol CFL alphabet on a 64-axis block (class
9371 // wrong-alphabet-same-value: same value, wrong interval, silent desync).
94- let cfl = if cfl && bw.max(bh) > 32 {
95- hit!(NOCFL_UV_MODE_HITS);
96- false
97- } else {
98- cfl
99- };
72+ let cfl = if cfl && bw.max(bh) > 32 { false } else { cfl };
10073 // lane-intra14 r1: on the INTER block path everything up to and including
10174 // `is_inter` was already read by [`decode_inter_block`], so this reader
10275 // starts at the mode syntax with the `skip` that caller read.
@@ -134,10 +107,8 @@ pub(super) fn read_intra_mode_rect(
134107 // refused by name when it fires.
135108 if allow_intrabc_frame(fctx) {
136109 let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0;
137- hit!(RECT_INTRABC_READS);
138110 istep!("intrabc", use_intrabc as i32);
139111 if use_intrabc {
140- hit!(INTRABC_HITS);
141112 // libaom `read_intrabc_info`: the DV read, then an immediate
142113 // return out of the mode-info read -- no `y_mode`, no `uv_mode`,
143114 // no angle deltas, no palette, no filter intra. The caller owns
@@ -163,7 +134,6 @@ pub(super) fn read_intra_mode_rect(
163134 // frame's `read_intra_frame_mode_info` (decodemv.c:1065 `read_intra_mode`
164135 // off `kf_y_mode_cdf[above][left]`).
165136 let mode = if let Some((size_group, _)) = inter {
166- crate::msac::SymbolDecoder::set_symr_cdf("y_mode");
167137 dec.symbol(&mut cdfs.y_mode[size_group])
168138 } else {
169139 let above_ctx = INTRA_MODE_CTX[above_mode];
@@ -188,10 +158,8 @@ pub(super) fn read_intra_mode_rect(
188158 let uv_mode = if !has_chroma {
189159 DC_PRED
190160 } else if cfl {
191- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
192161 dec.symbol(&mut cdfs.uv_mode_cfl[mode])
193162 } else {
194- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
195163 dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
196164 };
197165 istep!("uv_mode", uv_mode as i32);
@@ -200,19 +168,12 @@ pub(super) fn read_intra_mode_rect(
200168 } else {
201169 None
202170 };
203- if has_chroma && (9..=12).contains(&uv_mode) {
204- hit!(SMOOTH_UV_HITS);
205- }
206171 let angle_delta_uv = if has_chroma && (V_PRED..=D67_PRED).contains(&uv_mode) {
207- hit!(DIRECTIONAL_UV_HITS);
208172 read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])
209173 } else {
210174 0
211175 };
212176 istep!("angle_uv", angle_delta_uv);
213- if angle_delta_uv != 0 {
214- hit!(UV_ANGLE_DELTA_HITS);
215- }
216177 // `read_palette_mode_info` (spec 5.11.13), rect-generalised
217178 // (lane-palette2 r4): same bsize-ctx-gated read as [`read_intra_mode`],
218179 // just keyed by [`palette_bsize_ctx_wh`] instead of the square-only
@@ -223,10 +184,6 @@ pub(super) fn read_intra_mode_rect(
223184 let mut palette_y_pending: Option<(usize, [u16; 8])> = None;
224185 let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None;
225186 if allow_screen_content_tools && let Some(bsize_ctx) = palette_bsize_ctx_wh(bw, bh) {
226- // r6: this is the exact site the removed blanket refusal used to
227- // guard -- reached for EVERY rect strip in a screen-content frame,
228- // independent of whether the block ends up using a palette.
229- hit!(RECT_SCREEN_CONTENT_HITS);
230187 let (mode_ctx, cache) = palette.unwrap_or((0, &[]));
231188 let use_palette_y =
232189 mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][mode_ctx]) != 0;
@@ -247,15 +204,6 @@ pub(super) fn read_intra_mode_rect(
247204 }
248205 }
249206 let mut filter_intra = None;
250- if crate::envflags::env_flag!("EC_AV1_TRACE") {
251- let (rng, _) = dec.debug_state();
252- eprintln!(
253- "TRACE_RECT_PREFI mode={mode} uv_mode={uv_mode} enable_filter_intra={} \
254- class={:?} rng={rng}",
255- enable_filter_intra as i32,
256- filter_intra_size_class_rect(bw, bh)
257- );
258- }
259207 // As the square path: `av1_filter_intra_allowed` excludes a palette-Y
260208 // block (reconintra.h:77), so no `use_filter_intra` symbol exists there.
261209 if mode == DC_PRED
@@ -264,12 +212,8 @@ pub(super) fn read_intra_mode_rect(
264212 && let Some(class) = filter_intra_size_class_rect(bw, bh)
265213 {
266214 let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0;
267- if crate::envflags::env_flag!("EC_AV1_TRACE") {
268- eprintln!("TRACE_RECT_USEFI value={}", use_filter_intra as i32);
269- }
270215 istep!("use_filter_intra", use_filter_intra as i32);
271216 if use_filter_intra {
272- hit!(FILTER_INTRA_HITS);
273217 let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode);
274218 istep!("filter_intra_mode", fi_mode as i32);
275219 filter_intra = Some(fi_mode);
@@ -287,8 +231,6 @@ pub(super) fn read_intra_mode_rect(
287231 palette_onscreen(mi_r, mi_c, bw, bh, fctx),
288232 false,
289233 );
290- hit!(PALETTE_HITS);
291- hit!(PALETTE_RECT_HITS);
292234 PaletteY {
293235 size: n,
294236 colors,
@@ -309,7 +251,6 @@ pub(super) fn read_intra_mode_rect(
309251 (ss_x(fctx), ss_y(fctx)),
310252 );
311253 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);
312- hit!(PALETTE_UV_HITS);
313254 PaletteUv {
314255 size: n,
315256 u_colors,
@@ -352,9 +293,6 @@ pub(super) fn record_strip_palette(
352293 // the neighbour bands (`EC_PALPUB=1`) -- the rung that names which decode
353294 // path left a stale `left_palette_size` behind when
354295 // `av1_get_palette_mode_ctx` disagrees with libaom's.
355- if crate::envflags::env_flag!("EC_PALPUB") {
356- eprintln!("EC_PALPUB strip mi={r},{c} bw={bw} bh={bh} y={y_size} uv={uv_size}");
357- }
358296 // lane-kf900 r6: the palette side bands are mi-granular now, so a strip
359297 // writes its OWN span on BOTH axes -- the old `last` split-axis rule only
360298 // existed because the 16px [`SUB`] cell held one slot for all the strips
@@ -521,17 +459,12 @@ pub(super) fn decode_rect_split(
521459 at_mi: (usize, usize),
522460 bw: usize,
523461 bh: usize,
524- // The transform unit's own width and height in pixels. Square for every
525- // 2:1 strip from the first split on, but a 1:4 strip's FIRST split is
526- // still a 2:1 RECT unit (`sub_tx_size_map[TX_32X8] == TX_16X8`,
527- // `[TX_64X16] == TX_32X16`) -- see [`depth_to_tx_wh`].
528462 tx_w: usize,
529463 tx_h: usize,
530464 m: &RectStripModes,
531465 y: &mut PlaneBuf<'static>,
532466 u: &mut PlaneBuf<'static>,
533467 v: &mut PlaneBuf<'static>,
534- base_q_idx: u8,
535468 reduced_tx_set: bool,
536469 fctx: &crate::decode::FrameCtx,
537470 ) -> Result<()> {
@@ -610,32 +543,6 @@ pub(super) fn decode_rect_split(
610543 (chroma_w, chroma_h),
611544 (64, 32) | (32, 64) | (64, 16) | (16, 64) | (32, 32) | (16, 16) | (8, 8)
612545 );
613- if !m.skip {
614- if let Some(i) = match (chroma_w, chroma_h) {
615- (32, 8) => Some(0),
616- (8, 32) => Some(1),
617- (8, 4) => Some(2),
618- (4, 8) => Some(3),
619- _ => None,
620- } {
621- hit_do! {
622- RECT_SPLIT_CHROMA_SHAPE_HITS.with(|c| {
623- let mut hits = c.get();
624- hits[i] += 1;
625- c.set(hits);
626- });
627- }
628- }
629- if !m.skip && chroma.is_none() && !chroma_tiled {
630- // Diagnostic for the next caller that lands here (class
631- // refusal-names-a-correlate: the message names the tool, not the
632- // shape); the refusal below keeps its inventory-pinned wording.
633- eprintln!(
634- "EC_RECTCHROMA_GAP luma={bw}x{bh} tx={tx_w}x{tx_h} \
635- chroma={chroma_w}x{chroma_h}"
636- );
637- }
638- }
639546 // lane-rectsplit r2 (verifier finding): with both callers wired
640547 // (`decode_block_rect`'s 32x16/16x32 and `decode_block_rect64`'s
641548 // 64x32/32x64) every shape that reaches here has a table above, so this
@@ -648,10 +555,6 @@ pub(super) fn decode_rect_split(
648555 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
649556 ));
650557 }
651- hit!(RECT_SPLIT_TX_HITS);
652- if bw.max(bh) == 64 && bw / tx_w > 1 && bh / tx_h > 1 {
653- hit!(RECT_SPLIT_SB_INTERIOR_TU_HITS);
654- }
655558 // LUMA: `bw/tx` x `bh/tx` square transform units, raster order.
656559 // A square unit reads through the ordinary square [`read_plane`]; a rect
657560 // one (a 1:4 strip's first split) reads through [`read_coeffs_rect`] with
@@ -783,16 +686,6 @@ pub(super) fn decode_rect_split(
783686 // (`av1_get_ext_tx_set_type` resolves EXT_TX_SET_DCTONLY once
784687 // the square-up size is TX_64X64), and this unit covers its
785688 // whole block, so `get_txb_ctx` gives txb_skip ctx 0 flat.
786- if crate::envflags::env_flag!("EC_RECT64TU") {
787- eprintln!("EC_RECT64TU mi={tu_mi:?} tx={tx_w}x{tx_h} mode={}", m.mode);
788- }
789- hit_do! {
790- RECT64_CORNER_TU_HITS.with(|c| {
791- let mut v = c.get();
792- v[usize::from(tx_h > tx_w)] += 1;
793- c.set(v);
794- });
795- }
796689 let tu_around = neighbours.around_mi_rect(tu_mi, tx_w, tx_h)[0];
797690 let mut coding = cdfs.txb(TxbSet::Luma64, fi_tx_row(m.mode, m.filter_intra));
798691 let (corner, tu_tx_type) = read_coeffs(
@@ -870,7 +763,6 @@ pub(super) fn decode_rect_split(
870763 tu_skip_ctx,
871764 dc_sign_ctx(tu_around.2),
872765 TxType::DctDct,
873- 0,
874766 )?;
875767 let residual = dequant_and_inverse_typed_wh(
876768 &tu_grid,
@@ -926,7 +818,6 @@ pub(super) fn decode_rect_split(
926818 tu_py,
927819 tx_w,
928820 tx_w,
929- base_q_idx,
930821 None,
931822 m.filter_intra,
932823 Some(tu_skip_ctx),
@@ -1122,7 +1013,6 @@ pub(super) fn decode_rect_split(
11221013 // `REFUSED: unsupported: AV1 tile (a Golomb tail longer
11231014 // than this decoder reads)`.
11241015 if cpx + cu_col * 4 >= u.true_width || cpy + cu_row * 4 >= u.true_height {
1125- hit!(RECT_SPLIT_LOSSLESS_CHROMA_OFFTILE_HITS);
11261016 continue;
11271017 }
11281018 let cu_mi = (mi_r + cu_row * (span_y / MI), mi_c + cu_col * (span_x / MI));
@@ -1154,11 +1044,6 @@ pub(super) fn decode_rect_split(
11541044 cu_row * span_y,
11551045 span_x,
11561046 block_reach,
1157- px,
1158- py,
1159- y.width,
1160- y.height,
1161- fctx,
11621047 );
11631048 let (cu_x, cu_y) = (cpx + cu_col * 4, cpy + cu_row * 4);
11641049 if let Some((ub, vb)) = &m.palette_uv {
@@ -1186,7 +1071,6 @@ pub(super) fn decode_rect_split(
11861071 cu_y,
11871072 4,
11881073 4,
1189- base_q_idx,
11901074 m.alpha
11911075 .zip(ac)
11921076 .map(|((au, av), ac)| (if plane_idx == 1 { au } else { av }, ac)),
@@ -1195,9 +1079,6 @@ pub(super) fn decode_rect_split(
11951079 m.smooth_neighbor_uv,
11961080 fctx,
11971081 )?;
1198- if span_x == 4 && span_y == 4 {
1199- hit!(RECT_SPLIT_LOSSLESS_CHROMA444_HITS);
1200- }
12011082 neighbours.record_mi_chroma(cu_mi, span_x, span_y, plane_idx, &grid);
12021083 ll_chroma_units.push((cu_mi, plane_idx, grid.clone(), span_x, span_y));
12031084 last[plane_idx - 1] = grid;
@@ -1229,12 +1110,6 @@ pub(super) fn decode_rect_split(
12291110 };
12301111 // lane-av1-422: the witness counter, keyed to ss (1,0) so only a 4:2:2
12311112 // frame's square chroma units count it.
1232- if uw == uh && ss_x(fctx) == 1 && ss_y(fctx) == 0 {
1233- hit!(CHROMA422_SQUARE_HITS);
1234- }
1235- if chroma_422_pair_wide {
1236- hit!(CHROMA422_PAIR_WIDE_HITS);
1237- }
12381113 let (nw, nh) = (chroma_block_w / uw, chroma_block_h / uh);
12391114 // lane-av1-422stripanchor: the pair's plane block is BLOCK_INVALID
12401115 // whatever the pair size (`num_pels_log2_lookup[255]` reads 0xff in
@@ -1354,24 +1229,7 @@ pub(super) fn decode_rect_split(
13541229 uw << ss_x(fctx),
13551230 uh << ss_y(fctx),
13561231 reach,
1357- px,
1358- py,
1359- y.width,
1360- y.height,
1361- fctx,
13621232 );
1363- if cu_reach.above_right != reach.above_right
1364- || cu_reach.below_left != reach.below_left
1365- {
1366- hit!(RECT_TILED_CHROMA_UNIT_REACH_HITS);
1367- }
1368- if nw * nh > 1 {
1369- match (nw, nh) {
1370- (2, 1) => hit!(RECT_TILED_CHROMA_2X1_HITS),
1371- (1, 2) => hit!(RECT_TILED_CHROMA_1X2_HITS),
1372- _ => hit!(RECT_TILED_CHROMA_NXN_HITS),
1373- }
1374- }
13751233 // 32x32 does not fit read_coeffs_rect's scratch (768). The
13761234 // square reader is the path every other 32x32 chroma unit uses.
13771235 let levels = if uw == uh {
@@ -1393,7 +1251,6 @@ pub(super) fn decode_rect_split(
13931251 cu_y,
13941252 uw,
13951253 uw,
1396- base_q_idx,
13971254 cfl,
13981255 None,
13991256 bigger.then_some(3),
@@ -1414,7 +1271,6 @@ pub(super) fn decode_rect_split(
14141271 skip_ctx,
14151272 dc_sign_ctx(cu_around[plane_idx].2),
14161273 default_tx,
1417- plane_idx,
14181274 )?;
14191275 let residual = dequant_and_inverse_typed_wh(
14201276 &levels,
@@ -1504,15 +1360,11 @@ pub(super) fn decode_rect_split(
15041360 skip_ctx,
15051361 dc_sign_ctx(around[plane_idx].2),
15061362 default_tx,
1507- plane_idx,
15081363 )?;
15091364 // The same delta_q proof the unsplit rect64 path records
15101365 // (lane-rectsplit r4: lifting the split-transform refusal moved
15111366 // superblock strips onto this path, so only counting there would
15121367 // leave the delta_q gate's counter silent for them).
1513- if bw.max(bh) == 64 && fctx.current_q_idx.with(|c| c.get()) != i32::from(base_q_idx) {
1514- hit!(RECT64_QIDX_DRIFT_HITS);
1515- }
15161368 let residual = dequant_and_inverse_typed_wh(
15171369 &levels,
15181370 chroma_w,
@@ -1584,13 +1436,6 @@ pub(super) fn decode_rect_split(
15841436 0,
15851437 fctx,
15861438 );
1587- if crate::envflags::env_flag!("EC_AV1_TRACE") {
1588- let (rng, _) = dec.debug_state();
1589- eprintln!(
1590- "TRACE_RECT_SPLIT mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} \
1591- tx={tx_w}x{tx_h} rng={rng}"
1592- );
1593- }
15941439 Ok(())
15951440 }
15961441
@@ -1657,11 +1502,6 @@ fn every_intra_in_inter_shape_the_census_lists_has_a_size_group_row() {
16571502 // never said WHICH string the domain was about, so under a real function
16581503 // boundary -- rather than a window that ran into the next test -- the row
16591504 // read as unanchored.
1660- const REFUSAL: &str = "an intra-coded {bw}x{bh} block on the inter block path (no size-group/tx-category row for that shape here)";
1661- assert!(
1662- crate::test_source::module_source("decode").contains(REFUSAL),
1663- "this gate proves {REFUSAL:?}, but that string is no longer in decode.rs"
1664- );
16651505 let mut checked = 0;
16661506 for &(side, w, h) in &INTER_BLOCK_SHAPES {
16671507 if (w, h) == (side, side) || w.min(h) < 8 || w.max(h) > 64 {
@@ -1983,21 +1823,6 @@ pub(super) fn decode_intra_rect_in_inter(
19831823 }
19841824 neighbours.above_side[c] = bw;
19851825 neighbours.left_side[r] = bh;
1986- if crate::envflags::env_flag!("EC_INTRA16X4") {
1987- eprintln!(
1988- "EC_INTRA16X4 decoded mi={mi_r},{mi_c} px={},{} horz={horz} has_chroma={has_chroma} skip={skip} mode={mode} uv={uv:?}",
1989- mi_c * MI,
1990- mi_r * MI
1991- );
1992- }
1993- hit_do! {
1994- INTRA16X4_IN_INTER_HITS.with(|h| {
1995- let mut v = h.get();
1996- v[usize::from(!horz)] += 1;
1997- v[2] += usize::from(has_chroma);
1998- h.set(v);
1999- });
2000- }
20011826 return Ok(());
20021827 }
20031828 // lane-inter128intra r1: the 128 superblock's PARTITION_HORZ/VERT half
@@ -2035,13 +1860,6 @@ pub(super) fn decode_intra_rect_in_inter(
20351860 // palette_syntax`), so a 128-root half consumes no palette syntax and
20361861 // a screen-content frame's half is syntactically identical to the
20371862 // non-screen one this arm already decodes byte-exact.
2038- if coeff_trace_on() {
2039- // lane-t900 r16: which decode-order frame this arm fires in --
2040- // interleaved with the `EC_COEFF_FRAME` markers, this is what
2041- // proves the hit is counted out of a frame that compares exact
2042- // (class `counter-from-refused-stream`).
2043- eprintln!("EC_INTRA128 mi_row={r} mi_col={c} bw={bw} bh={bh}");
2044- }
20451863 fctx.intra_in_inter_mode.with(|c| c.set(Some((3, skip))));
20461864 let res = decode_block_128rect(
20471865 dec,
@@ -2064,11 +1882,6 @@ pub(super) fn decode_intra_rect_in_inter(
20641882 return res;
20651883 }
20661884 let Some((size_group, tx_cat)) = intra_in_inter_size_row(bw, bh) else {
2067- if crate::envflags::env_flag!("EC_OBMCREC") {
2068- eprintln!(
2069- "OBMCREC intra-in-inter shape bw={bw} bh={bh} mi=({mi_r},{mi_c}) skip={skip}"
2070- );
2071- }
20721885 // lane-obmcrec r1: the message used to name a 16x4/4x16 strip
20731886 // (class refusal-names-a-correlate). lane-t900 r20: the shapes that
20741887 // can arrive here are enumerated against the measured block-shape
@@ -2142,33 +1955,12 @@ pub(super) fn decode_intra_rect_in_inter(
21421955 };
21431956 fctx.intra_in_inter_mode.with(|c| c.set(None));
21441957 res?;
2145- let shape = match (bw, bh) {
2146- (64, 16) => 0,
2147- (16, 64) => 1,
2148- (32, 8) => 2,
2149- _ => 3,
2150- };
2151- hit_do! {
2152- INTRA_RECT4_IN_INTER_HITS.with(|h| {
2153- let mut v = h.get();
2154- v[shape] += 1;
2155- h.set(v);
2156- });
2157- }
21581958 return Ok(());
21591959 }
2160- crate::msac::SymbolDecoder::set_symr_cdf("y_mode");
21611960 let mode = dec.symbol(&mut cdfs.y_mode[size_group]);
21621961 // lane-t900 r1: this arm read six mode symbols with no ladder rung of its
21631962 // own, so a cross-decoder bisection could only see the block's first
21641963 // coefficient. Same names/format as [`read_tx_size`]'s rung.
2165- let step_trace = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");
2166- if step_trace {
2167- eprintln!(
2168- "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=y_mode val={mode} grp={size_group} rng={}",
2169- dec.debug_state().0
2170- );
2171- }
21721964 if mode >= 13 {
21731965 return Err(unsupported(
21741966 "an intra mode this decoder does not code (round 2)",
@@ -2182,9 +1974,6 @@ pub(super) fn decode_intra_rect_in_inter(
21821974 } else {
21831975 0
21841976 };
2185- if angle_delta_y != 0 {
2186- hit!(INTRA_IN_INTER_ANGLE_DELTA_Y_HITS);
2187- }
21881977 // `is_cfl_allowed` (spec 5.11.5) caps CFL at 32x32, so the
21891978 // superblock-level strip reads the no-CFL alphabet -- the same split
21901979 // [`read_intra_mode_rect`] makes for [`decode_block_rect64`].
@@ -2196,22 +1985,10 @@ pub(super) fn decode_intra_rect_in_inter(
21961985 let uv_mode = if !has_chroma {
21971986 DC_PRED
21981987 } else if cfl_allowed {
2199- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
22001988 dec.symbol(&mut cdfs.uv_mode_cfl[mode])
22011989 } else {
2202- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
22031990 dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
22041991 };
2205- if step_trace {
2206- eprintln!(
2207- "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=uv_mode val={uv_mode} cfl={} rng={}",
2208- u8::from(cfl_allowed),
2209- dec.debug_state().0
2210- );
2211- }
2212- if (9..=12).contains(&uv_mode) {
2213- hit!(SMOOTH_UV_HITS);
2214- }
22151992 let alpha = if cfl_allowed && uv_mode == UV_CFL_PRED {
22161993 Some(read_cfl_alphas(dec, cdfs))
22171994 } else {
@@ -2223,15 +2000,10 @@ pub(super) fn decode_intra_rect_in_inter(
22232000 uv_mode
22242001 };
22252002 let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
2226- hit!(DIRECTIONAL_UV_HITS);
22272003 read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])
22282004 } else {
22292005 0
22302006 };
2231- if angle_delta_uv != 0 {
2232- hit!(UV_ANGLE_DELTA_HITS);
2233- hit!(INTRA_IN_INTER_ANGLE_DELTA_UV_HITS);
2234- }
22352007 // `read_palette_mode_info` (spec 5.11.13), in the position
22362008 // `read_intra_block_mode_info` writes it: after the chroma mode and
22372009 // before `filter_intra`. lane-t900 r21: a `--tune-content=screen` inter
@@ -2247,7 +2019,6 @@ pub(super) fn decode_intra_rect_in_inter(
22472019 let mut palette_y_pending: Option<(usize, [u16; 8])> = None;
22482020 let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None;
22492021 if allow_screen_content_tools && let Some(bsize_ctx) = palette_bsize_ctx_wh(bw, bh) {
2250- hit!(INTRA_RECT_IN_INTER_SCREEN_HITS);
22512022 let use_palette_y =
22522023 mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][palette_ctx]) != 0;
22532024 if use_palette_y {
@@ -2261,14 +2032,6 @@ pub(super) fn decode_intra_rect_in_inter(
22612032 let use_palette_uv = has_chroma
22622033 && uv_mode == DC_PRED
22632034 && dec.symbol(&mut cdfs.palette_uv_mode[usize::from(use_palette_y)]) != 0;
2264- if crate::envflags::env_flag!("EC_PALSYN") {
2265- eprintln!(
2266- "EC_PALSYN rect mi={mi_r},{mi_c} bw={bw} bh={bh} mode={mode} uv={uv_mode} ctx={palette_ctx} y={} uv={} rng={}",
2267- use_palette_y as i32,
2268- use_palette_uv as i32,
2269- dec.debug_state().0
2270- );
2271- }
22722035 if use_palette_uv {
22732036 let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]);
22742037 let (u_colors, v_colors) = read_palette_colors_uv(dec, n, &palette_uv_cache, fctx);
@@ -2289,8 +2052,6 @@ pub(super) fn decode_intra_rect_in_inter(
22892052 && let Some(class) = filter_intra_size_class_rect(bw, bh)
22902053 && dec.symbol(&mut cdfs.filter_intra[class]) != 0
22912054 {
2292- hit!(FILTER_INTRA_HITS);
2293- hit!(INTRA_IN_INTER_FILTER_INTRA_HITS);
22942055 filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode));
22952056 }
22962057 // `av1_visit_palette`: Y's colour-index map then the shared chroma one.
@@ -2304,9 +2065,6 @@ pub(super) fn decode_intra_rect_in_inter(
23042065 palette_onscreen(mi_r, mi_c, bw, bh, fctx),
23052066 false,
23062067 );
2307- hit!(PALETTE_HITS);
2308- hit!(PALETTE_RECT_HITS);
2309- hit!(INTRA_IN_INTER_PALETTE_Y_HITS);
23102068 PaletteY {
23112069 size: n,
23122070 colors,
@@ -2322,8 +2080,6 @@ pub(super) fn decode_intra_rect_in_inter(
23222080 (ss_x(fctx), ss_y(fctx)),
23232081 );
23242082 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);
2325- hit!(PALETTE_UV_HITS);
2326- hit!(INTRA_IN_INTER_PALETTE_UV_HITS);
23272083 PaletteUv {
23282084 size: n,
23292085 u_colors,
@@ -2342,13 +2098,7 @@ pub(super) fn decode_intra_rect_in_inter(
23422098 // context-read-from-one-cell).
23432099 let coarse_pair = neighbours.modes_above_left(r, c);
23442100 let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left_mi(mi_r, mi_c, coarse_pair);
2345- if (nb_above_mode, nb_left_mode) != coarse_pair {
2346- hit!(EDGE_FILTER_MI_FIX_HITS);
2347- }
23482101 let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
2349- if smooth_neighbor {
2350- hit!(SMOOTH_LUMA_HITS);
2351- }
23522102 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c, fctx);
23532103 // lane-av1mixloss: the lossless-segment early return (`decodeframe.c:1203`)
23542104 // precedes `TX_MODE_SELECT`, so a lossless-segment intra-rect block inside
@@ -2356,41 +2106,19 @@ pub(super) fn decode_intra_rect_in_inter(
23562106 // segment regardless of frame type; class sweep of the sub8 leaf's fix).
23572107 let depth = if fctx.tx_select_inter.with(std::cell::Cell::get) && !lossless(fctx) {
23582108 // The frame's own `TXFM_CONTEXT` bands -- [`tx_size_context_txfm_rect`].
2359- let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64), fctx);
2109+ let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64));
23602110 let d = match tx_cat {
23612111 1 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]),
23622112 2 => dec.symbol(&mut cdfs.tx_size_cat2[ctx]),
23632113 _ => dec.symbol(&mut cdfs.tx_size_cat3[ctx]),
23642114 };
2365- if step_trace {
2366- eprintln!(
2367- "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat={tx_cat} rng={}",
2368- dec.debug_state().0
2369- );
2370- }
23712115 d
23722116 } else {
23732117 0
23742118 };
2375- if depth != 0 || lossless(fctx) {
2376- hit!(TX_DEPTH_HITS);
2377- // lane-intrasplit r1: a split intra strip in an inter frame walks the
2378- // key frame's own per-TU path ([`decode_rect_split`] below); what was
2379- // wrong when this refusal was written was the depth SYMBOL, not the walk.
2380- hit_do! {
2381- INTRA_RECT_IN_INTER_SPLIT_TX_HITS.with(|h| {
2382- let mut v = h.get();
2383- v[depth.min(2)] += 1;
2384- h.set(v);
2385- });
2386- }
2387- }
23882119 // lane-intrasplit r3: print EVERY intra strip with its depth, not only the
23892120 // split ones -- a `depth=0`-only stream is a witness gap in the SOURCE, and
23902121 // the two are indistinguishable when the diagnostic fires on splits alone.
2391- if crate::envflags::env_flag!("EC_SPLITSTRIP") {
2392- eprintln!("EC_SPLITSTRIP mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} depth={depth}");
2393- }
23942122 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth, fctx);
23952123 // lane-inter16ab r8: libaom runs `set_txfm_ctxs(tx_size, n4_w, n4_h,
23962124 // skip && is_inter, xd)` (decodeframe.c `decode_block`) for EVERY block
@@ -2435,7 +2163,6 @@ pub(super) fn decode_intra_rect_in_inter(
24352163 y,
24362164 u,
24372165 v,
2438- base_q_idx,
24392166 fctx.reduced_tx_set_inter.with(std::cell::Cell::get),
24402167 fctx,
24412168 )?;
@@ -2467,18 +2194,6 @@ pub(super) fn decode_intra_rect_in_inter(
24672194 palette_uv.as_ref().map_or(0, |p| p.size),
24682195 palette_uv.as_ref().map_or([0u16; 8], |p| p.u_colors),
24692196 );
2470- let class = match bw.max(bh) {
2471- 64 => 0,
2472- 32 => 1,
2473- _ => 2,
2474- };
2475- hit_do! {
2476- INTRA_RECT_IN_INTER_HITS.with(|h| {
2477- let mut v = h.get();
2478- v[class] += 1;
2479- h.set(v);
2480- });
2481- }
24822197 Ok(())
24832198 }
24842199
@@ -2519,22 +2234,6 @@ pub(super) fn decode_intrabc_rect(
25192234 base_q_idx: u8,
25202235 fctx: &crate::decode::FrameCtx,
25212236 ) -> Result<()> {
2522- hit!(INTRABC_RECT_HITS);
2523- // [horz, vert]: see `INTRABC_RECT_CODED_HITS` / `INTRABC_RECT_SKIPPED_HITS`.
2524- let idx = usize::from(bh > bw);
2525- if skip {
2526- INTRABC_RECT_SKIPPED_HITS.with(|c| {
2527- let mut seen = c.get();
2528- seen[idx] += 1;
2529- c.set(seen);
2530- });
2531- } else {
2532- INTRABC_RECT_CODED_HITS.with(|c| {
2533- let mut seen = c.get();
2534- seen[idx] += 1;
2535- c.set(seen);
2536- });
2537- }
25382237 let (px, py) = (mi_c * MI, mi_r * MI);
25392238 // lane-whtshape: a LOSSLESS block's chroma plane block is
25402239 // `bw >> ss_x` by `bh >> ss_y` at its own origin -- `av1_get_max_uv_txsize`
@@ -2581,19 +2280,7 @@ pub(super) fn decode_intrabc_rect(
25812280 skip,
25822281 fctx,
25832282 )?;
2584- if leaves.is_some() {
2585- hit!(INTRABC_RECT_VARTX_HITS);
2586- }
2587- if ss_x(fctx) == 0 && ss_y(fctx) == 0 {
2588- hit!(IBC_RECT_CHROMA_FOOTPRINT_444_HITS);
2589- }
25902283 // lane-ibc444c: per-block geometry, for the chroma-tail attribution.
2591- if crate::envflags::env_flag!("EC_IBCBLOCK") {
2592- eprintln!(
2593- "EC_IBCBLOCK mi=({mi_r},{mi_c}) bw={bw} bh={bh} cpx={cpx} cpy={cpy} \
2594- cw={cw} ch={ch} cside={cside} skip={skip}"
2595- );
2596- }
25972284 // The whole-block prediction: `predict_inter_block` runs once, before any
25982285 // coefficient is read. The source is this frame's own reconstruction,
25992286 // which is already written.
@@ -2709,19 +2396,6 @@ pub(super) fn decode_intrabc_rect(
27092396 fctx,
27102397 );
27112398 if let Some(ls) = leaves.as_ref() {
2712- // lane-av1-loss64, merged: the same reset [`decode_intrabc_owned_rect`]'s
2713- // skip arm performs -- libaom `av1_reset_entropy_context`
2714- // (`if (mbmi->skip_txfm)`, decodeframe.c:1262 -> blockd.c:58): a
2715- // SKIPPED block zeroes its whole entropy-band footprint. This
2716- // helper serves `decode_block_rect4`'s 1:4 strips on this tree,
2717- // so a skipped lossless strip whose `leaves` resolved (every
2718- // lossless frame -- `read_block_tx_size_rect`'s lossless arm
2719- // returns the 4x4 grid before it looks at `skip`) left the
2720- // PREVIOUS occupant's luma bands standing and the NEXT block's
2721- // partition parse diverged from libaom's: the 320x242 lossless
2722- // sb128 gate read a phantom unskipped 8x32 intrabc strip at
2723- // mi(56,66) right after the skipped 8x16 one at mi(48,66).
2724- hit!(SKIP_LOSSLESS_BAND_RESET_HITS);
27252399 for &(row, col, tw, th) in ls {
27262400 neighbours.record_mi_luma_rect(
27272401 (mi_r + row, mi_c + col),
@@ -2903,21 +2577,6 @@ pub(super) fn decode_intrabc_rect(
29032577 around[2] = c[2];
29042578 }
29052579 if lossless(fctx) {
2906- // lane-whtshape: at lossless libaom codes TX_4X4 on EVERY
2907- // plane of a block -- `read_tx_size` returns `TX_4X4` for a
2908- // lossless block before it looks at a tree, `read_tx_mode`
2909- // already forced `ONLY_4X4` for the frame, and
2910- // `get_vartx_max_txsize` returns `TX_4X4` for every plane
2911- // -- so this block's chroma plane block is a
2912- // `(cw/4) * (ch/4)` raster of 4x4 units, PLANE-MAJOR
2913- // (`decode_token_recon_block`: every U unit, then every V
2914- // unit), not the single rect unit the two
2915- // `read_inter_plane_rect` calls below read. That single
2916- // 8x4 unit is what reached the lossless WHT with the wrong
2917- // shape (the `debug_assert_eq!((w, h), (4, 4))` this lane
2918- // replaced). Same helper, same walk, as the inter 8x8 and
2919- // 128 paths.
2920- hit!(INTRABC_RECT_LOSSLESS_CHROMA4_HITS);
29212580 let mut uo = vec![0i32; cside * cside];
29222581 let mut vo = vec![0i32; cside * cside];
29232582 read_inter_chroma_lossless(
@@ -3125,13 +2784,6 @@ pub(super) fn decode_intrabc_128rect(
31252784 base_q_idx: u8,
31262785 fctx: &crate::decode::FrameCtx,
31272786 ) -> Result<()> {
3128- hit!(INTRABC_128RECT_HITS);
3129- if crate::envflags::env_flag!("EC_AV1_TRACE") {
3130- let (rng, _) = dec.debug_state();
3131- eprintln!(
3132- "EC_IBC128 mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} skip={skip} dv=({dv_row},{dv_col}) rng={rng}"
3133- );
3134- }
31352787 let (px, py) = (mi_c * MI, mi_r * MI);
31362788 // lane-av1-ibc128chunk: the block's chroma PLANE BLOCK is per-axis
31372789 // `(bw >> ss_x) x (bh >> ss_y)` -- 4:2:0 halves both (this fn's
@@ -3277,12 +2929,6 @@ pub(super) fn decode_intrabc_128rect(
32772929 fctx,
32782930 );
32792931 if let Some(ls) = leaves.as_ref() {
3280- // A LOSSLESS frame's `read_block_tx_size_rect` resolves the TX_4X4
3281- // grid before it looks at `skip`; the skipped block still zeroes
3282- // its entropy-band footprint over every unit (libaom
3283- // `av1_reset_entropy_context` under `if (mbmi->skip_txfm)`) --
3284- // the same arm [`decode_intrabc_rect`]'s loss64 merge added.
3285- hit!(SKIP_LOSSLESS_BAND_RESET_HITS);
32862932 for &(row, col, tw, th) in ls {
32872933 neighbours.record_mi_luma_rect(
32882934 (mi_r + row, mi_c + col),
@@ -3457,38 +3103,6 @@ pub(super) fn decode_intrabc_128rect(
34573103 } else {
34583104 neighbours.around_mi_rect(unit_mi, unit_luma_w, unit_luma_h)
34593105 };
3460- if crate::envflags::env_flag!("EC_ECDUMP") {
3461- // Index loop mirrors the spec's per-position form over several offsets; an iterator would obscure it.
3462- #[allow(clippy::needless_range_loop)]
3463- for p in 1..3 {
3464- let ab: Vec<String> = (0..unit_luma_w / MI)
3465- .map(|k| {
3466- format!(
3467- "{:?}/{}",
3468- neighbours.above[unit_mi.1 + k][p].dc,
3469- neighbours.above[unit_mi.1 + k][p].level
3470- )
3471- })
3472- .collect();
3473- let lf: Vec<String> = (0..unit_luma_h / MI)
3474- .map(|k| {
3475- format!(
3476- "{:?}/{}",
3477- neighbours.left[unit_mi.0 + k][p].dc,
3478- neighbours.left[unit_mi.0 + k][p].level
3479- )
3480- })
3481- .collect();
3482- eprintln!(
3483- "EC_IBC128_BANDS mi=({mi_r},{mi_c}) unit=({cr},{cc}) plane={p} ctx=({},{},{}) above=[{}] left=[{}]",
3484- cu_around[p].0,
3485- cu_around[p].1,
3486- cu_around[p].2,
3487- ab.join(","),
3488- lf.join(",")
3489- );
3490- }
3491- }
34923106 let (cu_x, cu_y) = (
34933107 cpx + cc * chunk_chroma_w + uc * cu_tx,
34943108 cpy + cr * chunk_chroma_h + ur * cu_tx,
@@ -3538,15 +3152,6 @@ pub(super) fn decode_intrabc_128rect(
35383152 plane_idx,
35393153 &cu_grid,
35403154 );
3541- if crate::envflags::env_flag!("EC_ECDUMP") {
3542- let st = crate::decode::neighbour_state(&cu_grid);
3543- eprintln!(
3544- "EC_IBC128_STAMP mi=({mi_r},{mi_c}) unit=({cr},{cc}) plane={plane_idx} state=({:?},{})",
3545- st.dc, st.level
3546- );
3547- }
3548- hit!(CHROMA_SPLIT_TX_HITS);
3549- INTRABC_128RECT_CHROMA_CHUNK_HITS.with(|c| c.set(c.get() + 1));
35503155 // lane-av1-ibcrect: per-unit chroma context -- the
35513156 // end-of-block record's composed-grid re-stamp
35523157 // must not stand (replayed below).
@@ -3831,9 +3436,6 @@ pub(super) fn decode_block_rect(
38313436 );
38323437 }
38333438 let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
3834- if smooth_neighbor {
3835- hit!(SMOOTH_LUMA_HITS);
3836- }
38373439 // lane-chroma r3: chroma's own edge-filter-strength neighbour check
38383440 // (spec `get_intra_edge_filter_type`) reads the CHROMA neighbour's
38393441 // `uv_mode`, not the luma one.
@@ -3844,9 +3446,6 @@ pub(super) fn decode_block_rect(
38443446 // rectangle just as happily), so a `use_filter_intra` strip at this level
38453447 // predicts instead of refusing. The below-16x16 leaf arm
38463448 // (`decode_leaf_rect`) keeps the refusal: it has no gate of its own.
3847- if filter_intra.is_some() {
3848- hit!(FILTER_INTRA_RECT_HITS);
3849- }
38503449 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
38513450 DC_PRED
38523451 } else {
@@ -3872,14 +3471,8 @@ pub(super) fn decode_block_rect(
38723471 // 1920x792 128-superblock stream,
38733472 // decode-order frame 1: the 32x8 HORZ_4 strip at mi(48,176) read
38743473 // `tx_size_cat2` row 1 where libaom reads row 2.
3875- let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh, fctx);
3474+ let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh);
38763475 let d = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);
3877- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
3878- eprintln!(
3879- "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=2 rng={}",
3880- dec.debug_state().0
3881- );
3882- }
38833476 d
38843477 } else {
38853478 0
@@ -3894,19 +3487,11 @@ pub(super) fn decode_block_rect(
38943487 fctx,
38953488 );
38963489 if depth != 0 || lossless(fctx) {
3897- hit!(TX_DEPTH_HITS);
38983490 // lane-rectsplit r1: a split transform is predicted and reconstructed
38993491 // per transform unit, each unit taking its edges from the previous
39003492 // unit's reconstruction inside this same strip (spec 5.11.36) --
39013493 // [`decode_rect_split`], the unit named by [`depth_to_tx_wh`].
39023494 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth, fctx);
3903- if crate::envflags::env_flag!("EC_SBPART_DUMP64") {
3904- eprintln!(
3905- "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \
3906- depth={depth} tx={tx_w}x{tx_h} mode={mode} uv={uv_predict_mode} skip={skip} \
3907- angle_y={angle_delta_y}"
3908- );
3909- }
39103495 let modes = RectStripModes {
39113496 skip,
39123497 mode,
@@ -3927,9 +3512,6 @@ pub(super) fn decode_block_rect(
39273512 )
39283513 }),
39293514 };
3930- if palette_y.is_some() || palette_uv.is_some() {
3931- hit!(PALETTE_SPLIT_TX_HITS);
3932- }
39333515 decode_rect_split(
39343516 dec,
39353517 cdfs,
@@ -3943,7 +3525,6 @@ pub(super) fn decode_block_rect(
39433525 y,
39443526 u,
39453527 v,
3946- base_q_idx,
39473528 reduced_tx_set,
39483529 fctx,
39493530 )?;
@@ -3962,21 +3543,12 @@ pub(super) fn decode_block_rect(
39623543 .as_ref()
39633544 .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
39643545 neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors);
3965- hit!(RECT_PARTITION_HITS);
39663546 return Ok(());
39673547 }
39683548 let (tx_w, tx_h) = (bw, bh);
39693549 let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
39703550 let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
39713551 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
3972- if crate::envflags::env_flag!("EC_AV1_TRACE") {
3973- let (rng, _) = dec.debug_state();
3974- eprintln!(
3975- "TRACE_RECT_IMODE mi_row={mi_r} mi_col={mi_c} mode={mode} uv_mode={uv_mode} \
3976- skip={} tx={depth} rng={rng}",
3977- skip as i32
3978- );
3979- }
39803552 // As [`decode_block`]'s own [`PALETTE_PRED`] wiring: a palette-Y/UV
39813553 // block's prediction is the reconstructed colour-index map, set fresh
39823554 // right before each `reconstruct_rect` call below (lane-palette2 r4).
@@ -4174,12 +3746,7 @@ pub(super) fn decode_block_rect(
41743746 0,
41753747 dc_sign_ctx(around[0].2),
41763748 TxType::DctDct,
4177- 0,
41783749 )?;
4179- if crate::envflags::env_flag!("EC_AV1_TRACE") {
4180- let (rng, _) = dec.debug_state();
4181- eprintln!("TRACE_RECT_COEFF plane=0 mi_row={mi_r} mi_col={mi_c} rng={rng}");
4182- }
41833750 let luma_residual = dequant_and_inverse_typed_wh(
41843751 &luma_levels,
41853752 bw,
@@ -4226,12 +3793,7 @@ pub(super) fn decode_block_rect(
42263793 dc_sign_ctx(around[1].2),
42273794 u_default_tx,
42283795 fctx,
4229- 1,
42303796 )?;
4231- if crate::envflags::env_flag!("EC_AV1_TRACE") {
4232- let (rng, _) = dec.debug_state();
4233- eprintln!("TRACE_RECT_COEFF plane=1 mi_row={mi_r} mi_col={mi_c} rng={rng}");
4234- }
42353797 let u_residual = dequant_and_inverse_typed_wh(
42363798 &u_levels,
42373799 chroma_w,
@@ -4277,12 +3839,7 @@ pub(super) fn decode_block_rect(
42773839 dc_sign_ctx(around[2].2),
42783840 v_default_tx,
42793841 fctx,
4280- 2,
42813842 )?;
4282- if crate::envflags::env_flag!("EC_AV1_TRACE") {
4283- let (rng, _) = dec.debug_state();
4284- eprintln!("TRACE_RECT_COEFF plane=2 mi_row={mi_r} mi_col={mi_c} rng={rng}");
4285- }
42863843 let v_residual = dequant_and_inverse_typed_wh(
42873844 &v_levels,
42883845 chroma_w,
@@ -4320,7 +3877,6 @@ pub(super) fn decode_block_rect(
43203877 uv_predict_mode,
43213878 &[&luma_levels[..], &u_levels[..], &v_levels[..]],
43223879 );
4323- hit!(RECT_COEFF_HITS);
43243880 }
43253881 }
43263882 let (py_size, py_colors) = palette_y
@@ -4341,10 +3897,6 @@ pub(super) fn decode_block_rect(
43413897 0,
43423898 fctx,
43433899 );
4344- hit!(RECT_PARTITION_HITS);
4345- if crate::envflags::env_flag!("EC_AV1_TRACE") {
4346- eprintln!("TRACE_RECT32_END mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh}");
4347- }
43483900 Ok(())
43493901 }
43503902
@@ -4389,12 +3941,6 @@ pub(super) fn decode_leaf_rect(
43893941 fctx: &crate::decode::FrameCtx,
43903942 ) -> Result<usize> {
43913943 let _ = base_q_idx;
4392- if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") {
4393- eprintln!(
4394- "decode_leaf_rect: leaf_mi={leaf_mi:?} bw={bw} bh={bh} outer_at={outer_at:?} rng={}",
4395- dec.debug_state().0
4396- );
4397- }
43983944 let (r, c) = outer_at;
43993945 let mut above_mode = neighbours.above_mode[c];
44003946 let mut left_mode = neighbours.left_mode[r];
@@ -4417,9 +3963,6 @@ pub(super) fn decode_leaf_rect(
44173963 let (above_mode, left_mode) =
44183964 neighbours.modes_above_left_mi(leaf_mi.0, leaf_mi.1, (above_mode, left_mode));
44193965 let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode);
4420- if smooth_neighbor {
4421- hit!(SMOOTH_LUMA_HITS);
4422- }
44233966 // The palette-Y mode CDF row is picked by the neighbours' palette use
44243967 // (`palette_ctx_and_cache`), so this sub-16x16 leaf must pass its own real
44253968 // ctx/cache -- reading `palette_y_mode` off row 0 when a neighbour did use
@@ -4483,9 +4026,6 @@ pub(super) fn decode_leaf_rect(
44834026 // lane-kf900 r4: palette prediction on this shape, the same colour-index
44844027 // map -> base colours buffer [`decode_block_rect`] hands each
44854028 // `reconstruct_rect` through [`set_palette_pred`].
4486- if palette_y.is_some() || palette_uv.is_some() {
4487- hit!(RECT4_PALETTE_HITS);
4488- }
44894029 let palette_y_buf: Option<Vec<u16>> = palette_y
44904030 .as_ref()
44914031 .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect());
@@ -4501,17 +4041,6 @@ pub(super) fn decode_leaf_rect(
45014041 let (pal_uv_size, pal_uv_colors) = palette_uv
45024042 .as_ref()
45034043 .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
4504- if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") {
4505- eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}");
4506- }
4507- if filter_intra.is_some() {
4508- // lane-fistrip r1: `predict_filter_intra` already walks its 4x2
4509- // patches over a true `bw`x`bh` block (lane-rectsplit r1), so an
4510- // 8x16/16x8 strip predicts through the same call `reconstruct_rect`
4511- // below already makes; this refusal was square-only prose.
4512- hit!(FILTER_INTRA_RECT_HITS);
4513- hit!(FILTER_INTRA_RECT_SUB16_HITS);
4514- }
45154044 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
45164045 DC_PRED
45174046 } else {
@@ -4531,7 +4060,7 @@ pub(super) fn decode_leaf_rect(
45314060 // The mixed frame's 16x8 leaf at mi(10,0) forked exactly here: ours
45324061 // read `tx_size_cat1` (rng 55700->49918) where the oracle's next
45334062 // read was the leaf's own txb_skip.
4534- let ctx = tx_size_context_txfm_rect(neighbours, leaf_mi, bw, bh, fctx);
4063+ let ctx = tx_size_context_txfm_rect(neighbours, leaf_mi, bw, bh);
45354064 // lane-rectsplitx r1: `bsize_to_tx_size_cat` (libaom `blockd.h`,
45364065 // `bsize_to_tx_size_depth_table`) is 2 for BLOCK_16X8/BLOCK_8X16, so
45374066 // the category is 1 -- NOT the 2 the 32x16 strips read. Same symbol
@@ -4549,14 +4078,6 @@ pub(super) fn decode_leaf_rect(
45494078 // symbol in the tile is read from the wrong place (class
45504079 // `wrong-alphabet-same-value`, here same alphabet / wrong row).
45514080 let d = dec.symbol(&mut cdfs.tx_size_cat1[ctx]);
4552- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
4553- eprintln!(
4554- "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=1 rng={}",
4555- leaf_mi.0,
4556- leaf_mi.1,
4557- dec.debug_state().0
4558- );
4559- }
45604081 d
45614082 } else {
45624083 0
@@ -4571,11 +4092,6 @@ pub(super) fn decode_leaf_rect(
45714092 fctx,
45724093 );
45734094 if depth != 0 || lossless(fctx) {
4574- // The same per-transform-unit walk the bigger strips take
4575- // (`depth_to_tx_wh`: TX_16X8 -> TX_8X8 at depth 1, -> TX_4X4 at
4576- // depth 2), addressed at this leaf's own mi position.
4577- hit!(TX_DEPTH_HITS);
4578- hit!(SUB16_SPLIT_HITS);
45794095 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth, fctx);
45804096 let modes = RectStripModes {
45814097 skip,
@@ -4593,9 +4109,6 @@ pub(super) fn decode_leaf_rect(
45934109 palette_y: palette_y_buf.clone(),
45944110 palette_uv: palette_uv_bufs.clone(),
45954111 };
4596- if palette_y.is_some() || palette_uv.is_some() {
4597- hit!(PALETTE_SPLIT_TX_HITS);
4598- }
45994112 decode_rect_split(
46004113 dec,
46014114 cdfs,
@@ -4609,7 +4122,6 @@ pub(super) fn decode_leaf_rect(
46094122 y,
46104123 u,
46114124 v,
4612- base_q_idx,
46134125 reduced_tx_set,
46144126 fctx,
46154127 )?;
@@ -4772,17 +4284,7 @@ pub(super) fn decode_leaf_rect(
47724284 0,
47734285 dc_sign_ctx(around[0].2),
47744286 TxType::DctDct,
4775- 0,
47764287 )?;
4777- if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") {
4778- let nz: Vec<(usize, i32)> = l_levels
4779- .iter()
4780- .copied()
4781- .enumerate()
4782- .filter(|(_, v)| *v != 0)
4783- .collect();
4784- eprintln!(" luma_tx_type={luma_tx_type:?} nz_levels={nz:?}");
4785- }
47864288 luma_levels = l_levels;
47874289 let luma_residual = dequant_and_inverse_typed_wh(
47884290 &luma_levels,
@@ -4830,7 +4332,6 @@ pub(super) fn decode_leaf_rect(
48304332 dc_sign_ctx(around[1].2),
48314333 u_default_tx,
48324334 fctx,
4833- 1,
48344335 )?;
48354336 u_levels = u_l;
48364337 let u_residual = dequant_and_inverse_typed_wh(
@@ -4878,7 +4379,6 @@ pub(super) fn decode_leaf_rect(
48784379 dc_sign_ctx(around[2].2),
48794380 v_default_tx,
48804381 fctx,
4881- 2,
48824382 )?;
48834383 v_levels = v_l;
48844384 let v_residual = dequant_and_inverse_typed_wh(
@@ -4913,7 +4413,6 @@ pub(super) fn decode_leaf_rect(
49134413 smooth_neighbor_uv,
49144414 fctx,
49154415 );
4916- hit!(RECT_LEAF_COEFF_HITS);
49174416 }
49184417 neighbours.record_mi_rect(
49194418 leaf_mi,
crates/ec-av1/src/decode/rect4.rsmodified+8 -364
@@ -117,9 +117,6 @@ pub(super) fn decode_block_rect4(
117117 // [`decode_block_rect`] does one aspect ratio up -- the colour-index map
118118 // mapped through the base colours IS the prediction (it reads no edge
119119 // pixels), handed to each `reconstruct_rect` through [`set_palette_pred`].
120- if palette_y.is_some() || palette_uv.is_some() {
121- hit!(RECT4_PALETTE_HITS);
122- }
123120 let palette_y_buf: Option<Vec<u16>> = palette_y
124121 .as_ref()
125122 .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect());
@@ -136,9 +133,6 @@ pub(super) fn decode_block_rect4(
136133 .as_ref()
137134 .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
138135 let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode);
139- if smooth_neighbor {
140- hit!(SMOOTH_LUMA_HITS);
141- }
142136 // lane-rectsplitx r2: this strip's REAL mi, not the [`SUB`] cell's
143137 // top-left -- a 1:4 strip starts 8 px into a 16-px cell, so
144138 // `r * (SUB / MI)` names a different mi column and the chroma
@@ -146,14 +140,6 @@ pub(super) fn decode_block_rect4(
146140 // seed 43, the last 8x32 strip at luma (152,32), chroma-only mismatch
147141 // with luma bit-exact).
148142 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c, fctx);
149- if filter_intra.is_some() {
150- hit!(FILTER_INTRA_RECT_HITS);
151- if bw > bh {
152- hit!(FILTER_INTRA_RECT4_HORZ_HITS);
153- } else {
154- hit!(FILTER_INTRA_RECT4_VERT_HITS);
155- }
156- }
157143 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
158144 DC_PRED
159145 } else {
@@ -170,14 +156,8 @@ pub(super) fn decode_block_rect4(
170156 // 1920x792 128-superblock stream,
171157 // decode-order frame 1: the 32x8 HORZ_4 strip at mi(48,176) read
172158 // `tx_size_cat2` row 1 where libaom reads row 2.
173- let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh, fctx);
159+ let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh);
174160 let d = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);
175- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
176- eprintln!(
177- "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=2 rng={}",
178- dec.debug_state().0
179- );
180- }
181161 d
182162 } else {
183163 0
@@ -192,24 +172,7 @@ pub(super) fn decode_block_rect4(
192172 fctx,
193173 );
194174 if depth != 0 || lossless(fctx) {
195- // lane-rectsplitx r1: the per-transform-unit walk, at this strip's
196- // real mi position (strips 1 and 3 of a HORZ_4 start 8 px into a
197- // 16-px [`SUB`] cell). depth 1 is the RECT unit TX_16X8/TX_8X16
198- // (`sub_tx_size_map[TX_32X8] == TX_16X8`), depth 2 the square TX_8X8;
199- // both interleave in every real stream.
200- hit!(TX_DEPTH_HITS);
201175 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth, fctx);
202- // lane-rectsplitx r2: both depths ship together, as the r1 handoff
203- // predicted -- depth 1 fires FIRST in every attempt that splits at
204- // all, so a depth-2-only lift could never be gated. The r1 mismatch
205- // was never the rect unit: it was the neighbour MODE the strip reads
206- // (see `modes_above_left_mi`).
207- let which = if depth == 1 {
208- &RECT4_SPLIT_DEPTH1_HITS
209- } else {
210- &RECT4_SPLIT_DEPTH2_HITS
211- };
212- hit_do! { which.with(|c| c.set(c.get() + 1)); }
213176 let modes = RectStripModes {
214177 skip,
215178 mode,
@@ -223,9 +186,6 @@ pub(super) fn decode_block_rect4(
223186 palette_y: palette_y_buf.clone(),
224187 palette_uv: palette_uv_bufs.clone(),
225188 };
226- if palette_y.is_some() || palette_uv.is_some() {
227- hit!(PALETTE_SPLIT_TX_HITS);
228- }
229189 decode_rect_split(
230190 dec,
231191 cdfs,
@@ -239,7 +199,6 @@ pub(super) fn decode_block_rect4(
239199 y,
240200 u,
241201 v,
242- base_q_idx,
243202 false,
244203 fctx,
245204 )?;
@@ -253,14 +212,6 @@ pub(super) fn decode_block_rect4(
253212 pal_uv_size,
254213 pal_uv_colors,
255214 );
256- if bw > bh {
257- hit!(RECT4_32_HORZ_HITS);
258- } else {
259- hit!(RECT4_32_VERT_HITS);
260- }
261- if !skip {
262- hit!(RECT4_COEFF_HITS);
263- }
264215 // lane-frame36 r2 (same shape as `decode_block_rect64`'s split arm,
265216 // swept this round): `set_txfm_ctxs` runs for EVERY block of an inter
266217 // frame, so this 1:4 strip -- which is also the INTER frame's reader
@@ -367,9 +318,7 @@ pub(super) fn decode_block_rect4(
367318 0,
368319 dc_sign_ctx(around[0].2),
369320 TxType::DctDct,
370- 0,
371321 )?;
372- hit!(RECT4_COEFF_HITS);
373322 let luma_residual = dequant_and_inverse_typed_wh(
374323 &luma_levels,
375324 bw,
@@ -410,20 +359,7 @@ pub(super) fn decode_block_rect4(
410359 for plane in [1usize, 2] {
411360 for unit_row in 0..4usize {
412361 let unit_mi = (mi_r + unit_row * 2, mi_c);
413- let unit_reach = tu_reach_rect(
414- bw,
415- bh,
416- 0,
417- unit_row * 8,
418- 8,
419- 8,
420- reach,
421- px,
422- py,
423- y.width,
424- y.height,
425- fctx,
426- );
362+ let unit_reach = tu_reach_rect(bw, bh, 0, unit_row * 8, 8, 8, reach);
427363 if let Some((ub, vb)) = &palette_uv_bufs {
428364 let pbuf = if plane == 1 { ub } else { vb };
429365 set_palette_pred(palette_window(pbuf, chroma_w, 0, unit_row * 8, 4, 8), fctx);
@@ -498,11 +434,6 @@ pub(super) fn decode_block_rect4(
498434 pal_uv_size,
499435 pal_uv_colors,
500436 );
501- if bw > bh {
502- hit!(RECT4_32_HORZ_HITS);
503- } else {
504- hit!(RECT4_32_VERT_HITS);
505- }
506437 // lane-frame36 r2 (same shape as `decode_block_rect64`'s split arm,
507438 // swept this round): `set_txfm_ctxs` runs for EVERY block of an inter
508439 // frame, so this 1:4 strip -- which is also the INTER frame's reader
@@ -533,7 +464,6 @@ pub(super) fn decode_block_rect4(
533464 0,
534465 dc_sign_ctx(around[0].2),
535466 TxType::DctDct,
536- 0,
537467 )?;
538468 let mut planes = Vec::with_capacity(2);
539469 // Index loop mirrors the spec's per-position form over several offsets; an iterator would obscure it.
@@ -562,13 +492,11 @@ pub(super) fn decode_block_rect4(
562492 dc_sign_ctx(chroma_around[plane].2),
563493 default_tx,
564494 fctx,
565- plane,
566495 )?;
567496 planes.push((levels, tx_type));
568497 }
569498 let (v_levels, v_tx_type) = planes.pop().expect("plane 2");
570499 let (u_levels, u_tx_type) = planes.pop().expect("plane 1");
571- hit!(RECT4_COEFF_HITS);
572500 let luma_residual = dequant_and_inverse_typed_wh(
573501 &luma_levels,
574502 bw,
@@ -657,11 +585,6 @@ pub(super) fn decode_block_rect4(
657585 pal_uv_size,
658586 pal_uv_colors,
659587 );
660- if bw > bh {
661- hit!(RECT4_32_HORZ_HITS);
662- } else {
663- hit!(RECT4_32_VERT_HITS);
664- }
665588 // lane-frame36 r2 (same shape as `decode_block_rect64`'s split arm,
666589 // swept this round): `set_txfm_ctxs` runs for EVERY block of an inter
667590 // frame, so this 1:4 strip -- which is also the INTER frame's reader
@@ -702,20 +625,7 @@ pub(super) fn decode_block_rect4(
702625 // libaom's `set_entropy_context` leaves.
703626 for plane in [1usize, 2] {
704627 for unit_row in 0..4usize {
705- let unit_reach = tu_reach_rect(
706- bw,
707- bh,
708- 0,
709- unit_row * 8,
710- 8,
711- 8,
712- reach,
713- px,
714- py,
715- y.width,
716- y.height,
717- fctx,
718- );
628+ let unit_reach = tu_reach_rect(bw, bh, 0, unit_row * 8, 8, 8, reach);
719629 if let Some((ub, vb)) = &palette_uv_bufs {
720630 let pbuf = if plane == 1 { ub } else { vb };
721631 set_palette_pred(palette_window(pbuf, chroma_w, 0, unit_row * 8, 4, 8), fctx);
@@ -804,11 +714,6 @@ pub(super) fn decode_block_rect4(
804714 pal_uv_size,
805715 pal_uv_colors,
806716 );
807- if bw > bh {
808- hit!(RECT4_32_HORZ_HITS);
809- } else {
810- hit!(RECT4_32_VERT_HITS);
811- }
812717 // lane-frame36 r2 (same shape as `decode_block_rect64`'s split arm,
813718 // swept this round): `set_txfm_ctxs` runs for EVERY block of an inter
814719 // frame, so this 1:4 strip -- which is also the INTER frame's reader
@@ -975,16 +880,10 @@ pub(super) fn decode_intrabc_owned_rect(
975880 // 73501 V (f1) and 9216 U + 8192 V (f2) are wrong -- chroma-only, which is
976881 // what makes this a chroma-sizing defect and not a block-geometry one.
977882 // Re-measured by this lane; see lanes/av1chromarect.report.md.
978- if crate::envflags::env_flag!("EC_HALVSWEEP") {
979- eprintln!("EC_HALV ibc_owned mi=({mi_r},{mi_c}) bw={bw} bh={bh} skip={skip}");
980- }
981883 let (cw, ch) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
982884 let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
983885 let side = bw.max(bh);
984886 let cside = cw.max(ch);
985- if ss_x(fctx) == 0 && ss_y(fctx) == 0 {
986- hit!(IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS);
987- }
988887 let saved_reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get);
989888 let saved_tx = fctx.tx_select_inter.with(std::cell::Cell::get);
990889 fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set));
@@ -1063,20 +962,6 @@ pub(super) fn decode_intrabc_owned_rect(
1063962 fctx,
1064963 );
1065964 if let Some(ls) = leaves.as_ref() {
1066- // libaom `av1_reset_entropy_context` (`if (mbmi->skip_txfm)`,
1067- // decodeframe.c:1262 -> blockd.c:58): a SKIPPED block zeroes its
1068- // whole entropy-band footprint. The non-skip arm below writes
1069- // those bands per transform unit and the tail's
1070- // `record_split_luma_rect_mi` writes chroma only, so without
1071- // this walk a skipped strip whose `leaves` resolved (every
1072- // lossless frame -- `read_block_tx_size_rect`'s lossless arm
1073- // returns the 4x4 grid before it looks at `skip`) leaked the
1074- // PREVIOUS occupant's luma bands into the next block's
1075- // `txb_skip`/coefficient contexts (lane-av1-loss64: the skipped
1076- // 8x16 intrabc strip at mi(48,66) of the 320x242 lossless sb128
1077- // stream left a stale 7 in left[48] and mi(48,68)'s first
1078- // transform unit read `txb_skip_ctx` 3 where aomdec reads 1).
1079- hit!(SKIP_LOSSLESS_BAND_RESET_HITS);
1080965 for &(row, col, tw, th) in ls {
1081966 neighbours.record_mi_luma_rect(
1082967 (mi_r + row, mi_c + col),
@@ -1195,7 +1080,6 @@ pub(super) fn decode_intrabc_owned_rect(
11951080 // `TX_MODE_LARGEST`); the routing here is identical, so a future
11961081 // witness takes the same code.
11971082 let around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
1198- hit!(IBC_OWNED_RECT_422_PAIR_HITS);
11991083 neighbours.around_mi_422_chroma((mi_r, mi_c), bw, bh)
12001084 } else {
12011085 neighbours.around_mi_rect((mi_r, mi_c), bw, bh)
@@ -1295,7 +1179,6 @@ pub(super) fn decode_intrabc_owned_rect(
12951179 // agree -- `fixtures/ibc422_nonsplit_ctx.obu` is the stream where
12961180 // they do not).
12971181 let around_chroma = if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
1298- hit!(IBC_OWNED_RECT_422_PAIR_HITS);
12991182 neighbours.around_mi_422_chroma((mi_r, mi_c), bw, bh)
13001183 } else {
13011184 around
@@ -1603,7 +1486,6 @@ pub(super) fn decode_rect4_16_intrabc(
16031486 fctx: &crate::decode::FrameCtx,
16041487 ) -> Result<(usize, Option<usize>, (usize, usize))> {
16051488 let _ = base_q_idx;
1606- hit!(RECT4_16_INTRABC_HITS);
16071489 let (bw, bh) = if horz { (16usize, 4usize) } else { (4, 16) };
16081490 let (mi_w, mi_h) = (bw / MI, bh / MI);
16091491 let (px, py) = (lmi.1 * MI, lmi.0 * MI);
@@ -1670,15 +1552,9 @@ pub(super) fn decode_rect4_16_intrabc(
16701552 // [BLOCK_4X16][1][0]` is BLOCK_INVALID at 4:2:2, so only HORZ reaches it.
16711553 let own444 = ss_x(fctx) == 0 && ss_y(fctx) == 0;
16721554 let own422 = ss_x(fctx) == 1 && ss_y(fctx) == 0 && horz;
1673- if own422 && has_chroma {
1674- hit!(INTRABC_RECT4_OWN_CHROMA422_HITS);
1675- }
16761555 // One predicate for "this strip IS its own chroma reference": the strip's
16771556 // own mi position, its own luma extent, and per-axis subsampled sizes.
16781557 let own_chroma = own444 || own422;
1679- if ss_x(fctx) == 0 && ss_y(fctx) == 0 && has_chroma {
1680- hit!(INTRABC_RECT4_OWN_CHROMA444_HITS);
1681- }
16821558 let (pw, ph) = if own444 {
16831559 (bw, bh)
16841560 } else if horz {
@@ -1805,15 +1681,6 @@ pub(super) fn decode_rect4_16_intrabc(
18051681 bh,
18061682 );
18071683 let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1;
1808- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
1809- let (rng, _) = dec.debug_state();
1810- eprintln!(
1811- "EC_ISTEP mi_row={} mi_col={} name=txfm_split_rect val={} ctx={ctx} rng={rng}",
1812- lmi.0,
1813- lmi.1,
1814- u8::from(split)
1815- );
1816- }
18171684 if !split {
18181685 None
18191686 } else {
@@ -2184,7 +2051,6 @@ pub(super) fn decode_rect4_16_intrabc(
21842051 }
21852052 let mut last_uv = None;
21862053 if has_chroma {
2187- hit!(RECT4_16_CHROMA_HITS);
21882054 // lane-av1422luma: the uv-mode publication and the left/above skip
21892055 // state below are the STRIP's own at 4:2:2 / 4:4:4 -- publishing the
21902056 // pair extent (one mi row off, `ph`/`pw`) is what the NEXT block's
@@ -2220,11 +2086,6 @@ pub(super) fn decode_rect4_16_intrabc(
22202086 }
22212087 last_uv = Some(DC_PRED);
22222088 }
2223- if horz {
2224- hit!(RECT4_16_HORZ_HITS);
2225- } else {
2226- hit!(RECT4_16_VERT_HITS);
2227- }
22282089 record_strip_palette(neighbours, lmi, bw, bh, 0, [0u16; 8], 0, [0u16; 8]);
22292090 if leaves.is_none() {
22302091 // Skip and TX_MODE_LARGEST publish the block size (`set_txfm_ctxs`
@@ -2350,9 +2211,6 @@ pub(super) fn decode_rect4_16_strip(
23502211 fctx,
23512212 );
23522213 }
2353- if palette_y.is_some() || palette_uv.is_some() {
2354- hit!(RECT4_PALETTE_HITS);
2355- }
23562214 // The colour-index map through the base colours IS the prediction.
23572215 // Chroma's map is the PAIR's 8x4 (4x8) block, matching the one
23582216 // chroma transform this closing strip codes.
@@ -2366,12 +2224,6 @@ pub(super) fn decode_rect4_16_strip(
23662224 )
23672225 });
23682226 let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode);
2369- if smooth_neighbor {
2370- hit!(SMOOTH_LUMA_HITS);
2371- }
2372- if filter_intra.is_some() {
2373- hit!(FILTER_INTRA_RECT_HITS);
2374- }
23752227 // `bsize_to_tx_size_cat(BLOCK_16X4)`: `max_txsize_rect_lookup` is
23762228 // TX_16X4 and `sub_tx_size_map` reaches TX_4X4 in two steps, so the
23772229 // depth symbol is the 3-symbol `tx_size_cat1` -- not the 2-symbol
@@ -2383,24 +2235,12 @@ pub(super) fn decode_rect4_16_strip(
23832235 let depth = if tx_select && !lossless(fctx) {
23842236 // lane-av1txbands: every frame reads the real `TXFM_CONTEXT` bands
23852237 // (`get_tx_size_context`, libaom `pred_common.h:342`).
2386- let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh, fctx);
2238+ let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh);
23872239 let d = dec.symbol(&mut cdfs.tx_size_cat1[ctx]);
2388- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
2389- eprintln!(
2390- "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=1 rng={}",
2391- lmi.0,
2392- lmi.1,
2393- dec.debug_state().0
2394- );
2395- }
23962240 d
23972241 } else {
23982242 0
23992243 };
2400- if depth != 0 {
2401- hit!(TX_DEPTH_HITS);
2402- hit!(RECT4_16_SPLIT_HITS);
2403- }
24042244 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth, fctx);
24052245 let (px, py) = (lmi.1 * MI, lmi.0 * MI);
24062246 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
@@ -2471,7 +2311,6 @@ pub(super) fn decode_rect4_16_strip(
24712311 tu_skip_ctx,
24722312 dc_sign_ctx(tu_around.2),
24732313 TxType::DctDct,
2474- 0,
24752314 )?;
24762315 let residual = dequant_and_inverse_typed_wh(
24772316 &tu_grid,
@@ -2502,9 +2341,6 @@ pub(super) fn decode_rect4_16_strip(
25022341 smooth_neighbor,
25032342 fctx,
25042343 );
2505- if tu_grid.iter().any(|&l| l != 0) {
2506- hit!(RECT4_16_COEFF_HITS);
2507- }
25082344 neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &tu_grid);
25092345 } else {
25102346 let tu_around = neighbours.around_mi(tu_mi, tx_w)[0];
@@ -2527,16 +2363,12 @@ pub(super) fn decode_rect4_16_strip(
25272363 tu_py,
25282364 tx_w,
25292365 tx_w,
2530- base_q_idx,
25312366 None,
25322367 filter_intra,
25332368 Some(tu_skip_ctx),
25342369 smooth_neighbor,
25352370 fctx,
25362371 )?;
2537- if tu_grid.iter().any(|&l| l != 0) {
2538- hit!(RECT4_16_COEFF_HITS);
2539- }
25402372 neighbours.record_mi_luma(tu_mi, tx_w, &tu_grid);
25412373 }
25422374 }
@@ -2586,7 +2418,6 @@ pub(super) fn decode_rect4_16_strip(
25862418 0,
25872419 dc_sign_ctx(around.2),
25882420 TxType::DctDct,
2589- 0,
25902421 )?;
25912422 let residual = dequant_and_inverse_typed_wh(
25922423 &levels,
@@ -2620,7 +2451,6 @@ pub(super) fn decode_rect4_16_strip(
26202451 smooth_neighbor,
26212452 fctx,
26222453 );
2623- hit!(RECT4_16_COEFF_HITS);
26242454 levels
26252455 };
26262456 neighbours.record_mi_luma_rect(lmi, bw, bh, &levels);
@@ -2641,7 +2471,6 @@ pub(super) fn decode_rect4_16_strip(
26412471 }
26422472 }
26432473 if has_chroma {
2644- hit!(RECT4_16_CHROMA_HITS);
26452474 // lane-av1-444: at 4:4:4 there is no pair -- every strip is its
26462475 // own chroma reference and codes its own 16x4 / 4x16 chroma
26472476 // block. (`set_mi_offsets`'s chroma snap is the zero offset at
@@ -2687,9 +2516,6 @@ pub(super) fn decode_rect4_16_strip(
26872516 } else {
26882517 uv_mode
26892518 };
2690- if (V_PRED..=D67_PRED).contains(&uv_predict_mode) {
2691- hit!(RECT4_16_CHROMA_DIR_HITS);
2692- }
26932519 let pair_reach = Reach::of_rect(pw, ph, ppx, ppy, y.width, y.height, fctx);
26942520 // lane-kf1200 r1: the chroma edge-filter type reads the neighbours
26952521 // of the CHROMA block, which for a 16x4/4x16 pair is `pair_mi`'s
@@ -2703,33 +2529,6 @@ pub(super) fn decode_rect4_16_strip(
27032529 // `av1_use_intra_edge_upsample` on (blk_wh 12 <= 16) for a
27042530 // directional chroma strip, moving 4 samples by 1.
27052531 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c, fctx);
2706- // lane-av1422warp: `smooth_uv_neighbour_unsnapped` now takes the
2707- // frame's own `ss_x` -- the unsnapped read is the pair-merge witness
2708- // counter's mirror of the snapping form, and the shipped read offsets
2709- // the above COLUMN by `+ss_x` (libaom's `chroma_above_mi`).
2710- //
2711- // lane-av1leftwit: this mirror is NOT evidence about the left read's
2712- // `+ss_y` term, whatever a report once said. It reads the leaf's own
2713- // (odd) mi row, which no decode call site does -- every one of them
2714- // uses the snapping form, whose base row is even -- and its result
2715- // feeds `RECT4_16_UV_PAIR_FILT_HITS` only. What it measures is real
2716- // and worth keeping (the pair's chroma-reference read against the
2717- // leaf's own row: 51/24/121/0/1 hits on the five fixtures censused),
2718- // so it stays; the decode path's own reach for the `+ss_y` term is
2719- // `uv_left_1mi_split_hits()`.
2720- if smooth_neighbor_uv
2721- != neighbours.smooth_uv_neighbour_unsnapped(
2722- lmi.0,
2723- lmi.1,
2724- r,
2725- c,
2726- ss_x(fctx),
2727- ss_y(fctx),
2728- false,
2729- )
2730- {
2731- hit!(RECT4_16_UV_PAIR_FILT_HITS);
2732- }
27332532 // lane-av1-rect14: a lossless frame forces TX_4X4 on every plane
27342533 // (`av1_get_tx_size`, blockd.h:1381). The pair's chroma block is
27352534 // 8x4 (HORZ_4) or 4x8 (VERT_4) -- two TX_4X4s, plane-major
@@ -2739,7 +2538,6 @@ pub(super) fn decode_rect4_16_strip(
27392538 // mi(1,20) uv_mode matched, the following skip did not).
27402539 let lossless_pair = lossless(fctx);
27412540 let (u_levels, v_levels) = if lossless_pair {
2742- hit!(RECT4_16_LOSSLESS_CHROMA_HITS);
27432541 if skip {
27442542 for plane in 1..3usize {
27452543 for rr in 0..ch / 4 {
@@ -2773,11 +2571,6 @@ pub(super) fn decode_rect4_16_strip(
27732571 4 << ss_x(fctx),
27742572 4 << ss_y(fctx),
27752573 pair_reach,
2776- ppx,
2777- ppy,
2778- y.width,
2779- y.height,
2780- fctx,
27812574 );
27822575 if let Some((ub, vb)) = &palette_uv_bufs {
27832576 let buf = if plane == 1 { ub } else { vb };
@@ -2868,11 +2661,6 @@ pub(super) fn decode_rect4_16_strip(
28682661 4 << ss_x(fctx),
28692662 4 << ss_y(fctx),
28702663 pair_reach,
2871- ppx,
2872- ppy,
2873- y.width,
2874- y.height,
2875- fctx,
28762664 );
28772665 if let Some((ub, vb)) = &palette_uv_bufs {
28782666 let buf = if plane == 1 { ub } else { vb };
@@ -2896,7 +2684,6 @@ pub(super) fn decode_rect4_16_strip(
28962684 cpy + oy,
28972685 4,
28982686 4,
2899- base_q_idx,
29002687 None,
29012688 None,
29022689 offset,
@@ -2910,7 +2697,6 @@ pub(super) fn decode_rect4_16_strip(
29102697 plane,
29112698 &cu_grid,
29122699 );
2913- hit!(CHROMA_SPLIT_TX_HITS);
29142700 let dst = if plane == 1 { &mut uo } else { &mut vo };
29152701 for row in 0..4 {
29162702 let start = (oy + row) * cw + ox;
@@ -2929,9 +2715,6 @@ pub(super) fn decode_rect4_16_strip(
29292715 // DC + alpha * luma-AC. Dropping the CfL term here left a
29302716 // chroma-only bounded box on ReelC's key frames.
29312717 let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph));
2932- if alpha.is_some() {
2933- hit!(CHROMA_SKIP_CFL_HITS);
2934- }
29352718 for plane in [1usize, 2] {
29362719 if chroma422_pair16 {
29372720 // lane-av1-422o: two TX_4X8 units, each predicted on
@@ -2940,20 +2723,7 @@ pub(super) fn decode_rect4_16_strip(
29402723 // `set_entropy_context` zeroed the block's own cells,
29412724 // so the pair-wide zero stamp below stays correct.
29422725 for unit_row in 0..2usize {
2943- let unit_reach = tu_reach_rect(
2944- pw,
2945- ph,
2946- 0,
2947- unit_row * 8,
2948- 8,
2949- 8,
2950- pair_reach,
2951- ppx,
2952- ppy,
2953- y.width,
2954- y.height,
2955- fctx,
2956- );
2726+ let unit_reach = tu_reach_rect(pw, ph, 0, unit_row * 8, 8, 8, pair_reach);
29572727 if let Some((ub, vb)) = &palette_uv_bufs {
29582728 let pbuf = if plane == 1 { ub } else { vb };
29592729 set_palette_pred(palette_window(pbuf, cw, 0, unit_row * 8, 4, 8), fctx);
@@ -3029,20 +2799,7 @@ pub(super) fn decode_rect4_16_strip(
30292799 for plane in [1usize, 2] {
30302800 for unit_row in 0..2usize {
30312801 let unit_mi = (pair_mi.0 + unit_row * 2, pair_mi.1);
3032- let unit_reach = tu_reach_rect(
3033- pw,
3034- ph,
3035- 0,
3036- unit_row * 8,
3037- 8,
3038- 8,
3039- pair_reach,
3040- ppx,
3041- ppy,
3042- y.width,
3043- y.height,
3044- fctx,
3045- );
2802+ let unit_reach = tu_reach_rect(pw, ph, 0, unit_row * 8, 8, 8, pair_reach);
30462803 if let Some((ub, vb)) = &palette_uv_bufs {
30472804 let pbuf = if plane == 1 { ub } else { vb };
30482805 set_palette_pred(palette_window(pbuf, cw, 0, unit_row * 8, 4, 8), fctx);
@@ -3115,10 +2872,7 @@ pub(super) fn decode_rect4_16_strip(
31152872 // row is unreachable there. It is also the witness arm:
31162873 // a restored `/2 chroma height` lands on (8,4) and the
31172874 // counter reads 0.
3118- (8, 8) => {
3119- hit!(CHROMA422_SQUARE_HITS);
3120- (TxbSet::Chroma8, default_scan(8))
3121- }
2875+ (8, 8) => (TxbSet::Chroma8, default_scan(8)),
31222876 // lane-av1-422o: with the `chroma422_pair16` arm above,
31232877 // the (2,16) own-strip shape and the 4:4:4 shapes are the
31242878 // only residents; anything else is a named-lane gap.
@@ -3141,7 +2895,6 @@ pub(super) fn decode_rect4_16_strip(
31412895 dc_sign_ctx(around[plane].2),
31422896 default_tx,
31432897 fctx,
3144- plane,
31452898 )?;
31462899 planes.push((levels, tx_type));
31472900 }
@@ -3225,11 +2978,6 @@ pub(super) fn decode_rect4_16_strip(
32252978 }
32262979 last_uv_mode = Some(uv_predict_mode);
32272980 }
3228- if horz {
3229- hit!(RECT4_16_HORZ_HITS);
3230- } else {
3231- hit!(RECT4_16_VERT_HITS);
3232- }
32332981 let (pal_y_size, pal_y_colors) = palette_y
32342982 .as_ref()
32352983 .map_or((0, [0u16; 8]), |p| (p.size, p.colors));
@@ -3354,17 +3102,7 @@ pub(super) fn decode_block_rect64(
33543102 fctx,
33553103 );
33563104 }
3357- if (palette_y.is_some() || palette_uv.is_some()) && !skip {
3358- // lane-t900 r34: a non-skip palette block on a superblock-level strip
3359- // -- counted so its gate cannot go vacuous (this was a refusal until
3360- // r34; see the gate `a_real_aomenc_palette_stream_with_8x8_leaves_
3361- // decodes_pixel_exact`).
3362- hit!(PALETTE_SB_STRIP_HITS);
3363- }
33643105 let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
3365- if smooth_neighbor {
3366- hit!(SMOOTH_LUMA_HITS);
3367- }
33683106 let smooth_neighbor_uv =
33693107 neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c, fctx);
33703108 if filter_intra.is_some() {
@@ -3394,7 +3132,7 @@ pub(super) fn decode_block_rect64(
33943132 // 1920x792 128-superblock stream,
33953133 // decode-order frame 1: the 32x8 HORZ_4 strip at mi(48,176) read
33963134 // `tx_size_cat2` row 1 where libaom reads row 2.
3397- let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh, fctx);
3135+ let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh);
33983136 // lane-rectsplit r1: `bsize_to_tx_size_cat` (libaom `decodemv.c`)
33993137 // counts `sub_tx_size_map` steps from the block's own max rect
34003138 // transform down to TX_4X4, minus one -- BLOCK_64X32's chain
@@ -3403,12 +3141,6 @@ pub(super) fn decode_block_rect64(
34033141 // block uses), not the 2 a 32x16 strip uses. Reading the cat-2 CDF
34043142 // here was a wrong-table read of a real symbol.
34053143 let d = dec.symbol(&mut cdfs.tx_size_cat3[ctx]);
3406- if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
3407- eprintln!(
3408- "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=3 rng={}",
3409- dec.debug_state().0
3410- );
3411- }
34123144 d
34133145 } else {
34143146 0
@@ -3423,28 +3155,12 @@ pub(super) fn decode_block_rect64(
34233155 fctx,
34243156 );
34253157 if depth != 0 || lossless(fctx) {
3426- hit!(TX_DEPTH_HITS);
34273158 // lane-rectsplit r1/r4: the superblock-level strip splits its
34283159 // transform through the very same per-unit path as its 32x32-level
34293160 // sibling; [`depth_to_tx_wh`] names the unit, which for a 64x16/16x64
34303161 // 1:4 strip is the 2:1 rect TX_32X16 at depth 1 (lane-rectchroma r1
34313162 // measured the old square formula mis-tiling exactly that strip).
34323163 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth, fctx);
3433- if bw.max(bh) / bw.min(bh) == 4 {
3434- let which = if depth == 1 {
3435- &RECT4_SPLIT_DEPTH1_HITS
3436- } else {
3437- &RECT4_SPLIT_DEPTH2_HITS
3438- };
3439- hit_do! { which.with(|c| c.set(c.get() + 1)); }
3440- }
3441- if crate::envflags::env_flag!("EC_SBPART_DUMP64") {
3442- eprintln!(
3443- "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \
3444- depth={depth} tx={tx_w}x{tx_h} mode={mode} uv={uv_predict_mode} skip={skip} \
3445- angle_y={angle_delta_y}"
3446- );
3447- }
34483164 let modes = RectStripModes {
34493165 skip,
34503166 mode,
@@ -3465,9 +3181,6 @@ pub(super) fn decode_block_rect64(
34653181 )
34663182 }),
34673183 };
3468- if palette_y.is_some() || palette_uv.is_some() {
3469- hit!(PALETTE_SPLIT_TX_HITS);
3470- }
34713184 decode_rect_split(
34723185 dec,
34733186 cdfs,
@@ -3481,7 +3194,6 @@ pub(super) fn decode_block_rect64(
34813194 y,
34823195 u,
34833196 v,
3484- base_q_idx,
34853197 reduced_tx_set,
34863198 fctx,
34873199 )?;
@@ -3506,8 +3218,6 @@ pub(super) fn decode_block_rect64(
35063218 // mi(192,144) took `tx_size_cat3` row 2 where libaom takes row 1. The
35073219 // bands carry the SPLIT unit's size, not the block's.
35083220 txfm_partition_update_rect(neighbours, (mi_r, mi_c), (tx_w, tx_h), (bw, bh));
3509- hit!(RECT64_SPLIT_TXFM_PUBLISH_HITS);
3510- hit!(RECT_PARTITION_HITS);
35113221 return Ok(());
35123222 }
35133223 let (tx_w, tx_h) = (bw, bh);
@@ -3617,12 +3327,6 @@ pub(super) fn decode_block_rect64(
36173327 // 32x16/16x32 under a 64x16/16x64 1:4 strip (lane-tx64x16).
36183328 let (luma_cw, luma_ch) = (bw.min(32), bh.min(32));
36193329 let scan32 = default_scan(TX32);
3620- if coeff_trace_on() {
3621- let (rng, _) = dec.debug_state();
3622- eprintln!(
3623- "EC_COEFF plane=0 row={mi_r} col={mi_c} tx_size={luma_cw}x{luma_ch} rng={rng}"
3624- );
3625- }
36263330 let (luma_corner, luma_tx_type) = if (luma_cw, luma_ch) == (32, 32) {
36273331 let mut luma_coding = cdfs.txb(TxbSet::Luma64, mode);
36283332 read_coeffs(
@@ -3659,29 +3363,13 @@ pub(super) fn decode_block_rect64(
36593363 0,
36603364 dc_sign_ctx(around[0].2),
36613365 TxType::DctDct,
3662- 0,
36633366 )?
36643367 };
3665- if coeff_trace_on() {
3666- let (rng, _) = dec.debug_state();
3667- eprintln!("EC_COEFF_VAL plane=0 row={mi_r} col={mi_c} rng={rng}");
3668- }
36693368 let mut luma_levels = vec![0i32; bw * bh];
36703369 for row in 0..luma_ch {
36713370 luma_levels[row * bw..][..luma_cw]
36723371 .copy_from_slice(&luma_corner[row * luma_cw..][..luma_cw]);
36733372 }
3674- {
3675- let cur = block_q_idx(fctx);
3676- if cur != i32::from(base_q_idx) {
3677- hit!(RECT64_QIDX_DRIFT_HITS);
3678- }
3679- if crate::envflags::env_flag!("EC_AV1_TRACE") {
3680- eprintln!(
3681- "TRACE rect64_dequant plane=0 base_q_idx={base_q_idx} current_q_idx={cur}"
3682- );
3683- }
3684- }
36853373 let luma_residual = dequant_and_inverse_typed_wh(
36863374 &luma_levels,
36873375 bw,
@@ -3711,22 +3399,6 @@ pub(super) fn decode_block_rect64(
37113399 smooth_neighbor,
37123400 fctx,
37133401 );
3714- if crate::envflags::env_flag!("EC_SBPART_DUMP64") {
3715- let leftcol: Vec<u16> = if px > 0 {
3716- (py..py + bh)
3717- .map(|row| y.data[row * y.width + px - 1])
3718- .collect()
3719- } else {
3720- vec![]
3721- };
3722- eprintln!(
3723- "DUMP64 mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} mode={mode} \
3724- skip={skip} eob_nonzero={} row0={:?} leftcol={:?}",
3725- luma_corner.iter().any(|&v| v != 0),
3726- &y.data[py * y.width + px..][..bw],
3727- leftcol,
3728- );
3729- }
37303402 // CHROMA. At 4:2:0 the plane block is already one adjusted UV
37313403 // transform (<=32 on each axis). At 4:4:4 a 64-axis strip's chroma
37323404 // is larger than that, so it is tiled into 32-capped units.
@@ -3753,15 +3425,6 @@ pub(super) fn decode_block_rect64(
37533425 // arm nothing had reached) from `nh >= 2` (the arm the corpus census
37543426 // already covered), and can see WHY a candidate block did not fire.
37553427 // Diagnostic only; no decode behaviour depends on it.
3756- if crate::envflags::env_flag!("EC_PALWALK") {
3757- eprintln!(
3758- "EC_PALWALK mi={r},{c} px={px} py={py} bw={bw} bh={bh} cw={chroma_w} \
3759- ch={chroma_h} uw={uw} uh={uh} nw={nw} nh={nh} ast={allow_screen_content_tools} \
3760- puv={} py_pal={}",
3761- palette_uv.is_some() as i32,
3762- palette_y.is_some() as i32
3763- );
3764- }
37653428 let mut u_levels = vec![0i32; chroma_w * chroma_h];
37663429 let mut v_levels = vec![0i32; chroma_w * chroma_h];
37673430 // The tiled units below stamp their own coefficient context
@@ -3813,9 +3476,6 @@ pub(super) fn decode_block_rect64(
38133476 // nothing. The `bigger` guard is what makes a hit PROOF
38143477 // that the tiled arm ran, rather than proof that some
38153478 // palette chroma block existed.
3816- if bigger {
3817- hit!(CHROMA_PALETTE_WINDOW_HITS);
3818- }
38193479 }
38203480 read_plane(
38213481 dec,
@@ -3835,7 +3495,6 @@ pub(super) fn decode_block_rect64(
38353495 cpy + cu_row * uh,
38363496 uw,
38373497 uw,
3838- base_q_idx,
38393498 cfl,
38403499 None,
38413500 bigger.then_some(3),
@@ -3857,7 +3516,6 @@ pub(super) fn decode_block_rect64(
38573516 dc_sign_ctx(cu_around[plane_idx].2),
38583517 TxType::DctDct,
38593518 fctx,
3860- plane_idx,
38613519 )?;
38623520 let residual = dequant_and_inverse_typed_wh(
38633521 &levels,
@@ -3883,9 +3541,6 @@ pub(super) fn decode_block_rect64(
38833541 // nothing. The `bigger` guard is what makes a hit PROOF
38843542 // that the tiled arm ran, rather than proof that some
38853543 // palette chroma block existed.
3886- if bigger {
3887- hit!(CHROMA_PALETTE_WINDOW_HITS);
3888- }
38893544 }
38903545 push_intra_rect(
38913546 y,
@@ -3949,7 +3604,6 @@ pub(super) fn decode_block_rect64(
39493604 for (cu_mi, plane, unit, span_w, span_h) in &tiled_chroma_units {
39503605 neighbours.record_mi_chroma(*cu_mi, *span_w, *span_h, *plane, unit);
39513606 }
3952- hit!(RECT_COEFF_HITS);
39533607 }
39543608 let (py_size, py_colors) = palette_y
39553609 .as_ref()
@@ -3980,15 +3634,5 @@ pub(super) fn decode_block_rect64(
39803634 // 3840x1608 10-bit stream's first silent wall, decode-order frame 33 at
39813635 // mi(16,480)). Same write as [`set_txfm_ctxs`], rect-aware.
39823636 txfm_partition_update_rect(neighbours, (mi_r, mi_c), (tx_w, tx_h), (bw, bh));
3983- hit!(SB_RECT_HITS);
3984- match (bw, bh) {
3985- (64, 16) => hit!(SB_RECT4_HORZ_HITS),
3986- (16, 64) => hit!(SB_RECT4_VERT_HITS),
3987- _ => {}
3988- }
3989- if crate::envflags::env_flag!("EC_AV1_TRACE") {
3990- let (rng, _) = dec.debug_state();
3991- eprintln!("TRACE_RECT64_END mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} rng={rng}");
3992- }
39933637 Ok(())
39943638 }
crates/ec-av1/src/decode/replay.rsmodified+0 -18
@@ -179,7 +179,6 @@ fn replay_inner(
179179 &mut v,
180180 cdef,
181181 &r.neighbours,
182- (r.frame_width, r.frame_height),
183182 fctx,
184183 pre,
185184 Some(&mut wrote),
@@ -449,7 +448,6 @@ pub(super) fn cdef_band(
449448 coeff_shift: i32,
450449 damping: i32,
451450 damping_uv: i32,
452- (frame_w, frame_h): (usize, usize),
453451 fctx: &crate::decode::FrameCtx,
454452 ) {
455453 let unit_cols = skip_grid.mi_cols.div_ceil(2);
@@ -471,9 +469,6 @@ pub(super) fn cdef_band(
471469 while mi_r < r_hi {
472470 let mut mi_c = 0usize;
473471 while mi_c < skip_grid.mi_cols {
474- if skip_grid.is_skip_txfm(mi_r, mi_c) {
475- hit!(CDEF_SKIPPED_UNITS);
476- }
477472 if !skip_grid.is_skip_txfm(mi_r, mi_c) {
478473 let sidx = strength_idx(mi_r, mi_c);
479474 let (ox, oy) = (mi_c * 4, mi_r * 4);
@@ -511,21 +506,8 @@ pub(super) fn cdef_band(
511506 let y_dir = if y_pri_strength != 0 { dir } else { 0 };
512507 let t = cdef_adjust_strength(y_pri_strength, var);
513508 // lane-cdef r1 rung: one line per filtered 8x8 luma CDEF unit.
514- if crate::envflags::env_flag!("EC_AV1_CDEF_DBG") {
515- eprintln!(
516- "EC_CDEF mi_r={mi_r} mi_c={mi_c} x={ox} y={oy} sidx={sidx} dir={dir} var={var} t={t} pri={y_pri_strength} sec={y_sec_strength} damp={damping}"
517- );
518- }
519509 let enable_primary = t != 0;
520510 let enable_secondary = y_sec_strength != 0;
521- if (ox + 8 > frame_w || oy + 8 > frame_h)
522- && (enable_primary
523- || enable_secondary
524- || cdef.uv_pri_strength[sidx] != 0
525- || cdef.uv_sec_strength[sidx] != 0)
526- {
527- hit!(CDEF_STRADDLE_UNITS);
528- }
529511 if enable_primary || enable_secondary {
530512 cdef_filter_block(
531513 &win_y,
crates/ec-av1/src/decode/sub8_inter.rsmodified+85 -285
@@ -62,7 +62,6 @@ pub(super) fn decode_inter_sub8_split4(
6262 ) -> Result<()> {
6363 const LAST_FRAME: i8 = 1;
6464 const B4: usize = 4;
65- hit!(SUB8_INTER_SPLIT_HITS);
6665 let (gr, gc) = group_mi;
6766 let (gpx, gpy) = (gc * MI, gr * MI);
6867 let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx));
@@ -72,7 +71,6 @@ pub(super) fn decode_inter_sub8_split4(
7271 let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 4] =
7372 [None; 4];
7473 let mut first_tx_type = TxType::DctDct;
75- let mut sub0_tx_type = TxType::DctDct;
7674 // This loop iteration's own sub-block luma `tx_type` (libaom `mbmi->tx_type`
7775 // after its `read_tx_type`): the per-piece 4:4:4 chroma units inherit it
7876 // (`av1_get_tx_type`, blockd.h -- inter chroma never codes its own symbol).
@@ -111,11 +109,6 @@ pub(super) fn decode_inter_sub8_split4(
111109 let skip_ctx =
112110 usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]);
113111 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
114- let ec_skip_post = if std::env::var_os("EC_DBG_SUB8").is_some() {
115- Some(dec.debug_state().0)
116- } else {
117- None
118- };
119112 inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, skip, false, fctx);
120113 maybe_read_cdef_idx(dec, rmi, cmi, (2, 2), skip, fctx);
121114 maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip, fctx);
@@ -128,32 +121,7 @@ pub(super) fn decode_inter_sub8_split4(
128121 neighbours.left_inter[rmi],
129122 );
130123 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
131- if std::env::var_os("EC_DBG_SUB8").is_some() {
132- eprintln!(
133- "EC_DBG piece mi=({rmi},{cmi}) skip={skip} skipctx={skip_ctx} skip_post={:?} is_inter={is_inter} iictx={ii_ctx} post={}",
134- ec_skip_post,
135- dec.debug_state().0
136- );
137- }
138124 if !is_inter {
139- if crate::envflags::env_flag!("EC_SUB8INTRA") {
140- eprintln!(
141- "EC_SUB8INTRA shape=4x4 sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}",
142- i == 3,
143- fctx.tx_select_inter.with(std::cell::Cell::get),
144- );
145- }
146- // lane-sub8x4 r2: the refusal and its `EC_SUB8INTRA_DECODE` bypass
147- // are gone -- `a_real_aomenc_inter_sequence_with_intra_sub8x8_
148- // leaves_decodes_pixel_exact` (stream.rs) decodes 12 real aomenc
149- // streams carrying this arm pixel-exact vs ffmpeg.
150- hit_do! {
151- SUB8_INTRA_RECT_HITS.with(|h| {
152- let mut st = h.get();
153- st[4] += 1;
154- h.set(st);
155- });
156- }
157125 // lane-sub8intra: the `BLOCK_4X4` twin of the HORZ/VERT arm --
158126 // same [`decode_intra_sub8_leaf`], no tx-depth symbol, chroma on
159127 // the chroma-reference sub-blocks (`is_chroma_reference`: the
@@ -173,7 +141,6 @@ pub(super) fn decode_inter_sub8_split4(
173141 y,
174142 u,
175143 v,
176- base_q_idx,
177144 fctx.enable_filter_intra_inter.with(std::cell::Cell::get),
178145 fctx.tx_select_inter.with(std::cell::Cell::get),
179146 reduced_tx_set,
@@ -187,12 +154,6 @@ pub(super) fn decode_inter_sub8_split4(
187154 // Same print point as the oracle's `EC_MODE` (entry of
188155 // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the
189156 // two range ladders line up element for element.
190- if crate::envflags::env_flag!("EC_TRACE_MODE") {
191- eprintln!(
192- "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",
193- dec.debug_state().0
194- );
195- }
196157 let ref_frame = read_single_ref(
197158 dec,
198159 cdfs,
@@ -209,9 +170,6 @@ pub(super) fn decode_inter_sub8_split4(
209170 // each of the group's pieces (luma and its 2x2 chroma) carries its
210171 // OWN factor because each can name a different `ref_frame`.
211172 let luma_scale = scale_of((ref_width, ref_height), frame_size);
212- if !luma_scale.is_unscaled() {
213- hit!(SCALED_SUB8_HITS);
214- }
215173 let gm_table = build_gm_mv_table(
216174 global_motion,
217175 rmi,
@@ -245,10 +203,6 @@ pub(super) fn decode_inter_sub8_split4(
245203 tpl,
246204 );
247205 let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
248- if !not_new {
249- crate::census::mode(0);
250- }
251- let mut is_globalmv = false;
252206 let (mv, is_new_mv) = if !not_new {
253207 let mut idx = 0usize;
254208 while idx < 2 && stack.entries.len() > idx + 1 {
@@ -272,15 +226,10 @@ pub(super) fn decode_inter_sub8_split4(
272226 )
273227 } else {
274228 let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;
275- if !not_zero {
276- crate::census::mode(1);
277- }
278- is_globalmv = !not_zero;
279229 let mv = if !not_zero {
280230 gm_table[(ref_frame - LAST_FRAME) as usize]
281231 } else {
282232 let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
283- crate::census::mode(if nearest { 2 } else { 3 });
284233 if nearest {
285234 stack.nearest_mv
286235 } else {
@@ -298,17 +247,8 @@ pub(super) fn decode_inter_sub8_split4(
298247 };
299248 // Same print point as the oracle's `EC_MODE_MV` (right after
300249 // `assign_mv`), the second rung of the sub-8x8 range ladder.
301- if crate::envflags::env_flag!("EC_TRACE_MODE") {
302- eprintln!(
303- "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",
304- mv.0,
305- mv.1,
306- dec.debug_state().0
307- );
308- }
309250 // No `interintra` and no `motion_mode`/`obmc` symbol below 8x8 (see
310251 // this function's own doc); `read_mb_interp_filter` still runs.
311- let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize];
312252 let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame
313253 || neighbours.above_ref1[cmi] == Some(ref_frame)
314254 {
@@ -323,25 +263,10 @@ pub(super) fn decode_inter_sub8_split4(
323263 } else {
324264 [3, 3]
325265 };
326- if crate::envflags::env_flag!("EC_AV1_IFDBG") {
327- eprintln!(
328- "IFDBG4 mi=({rmi},{cmi}) ref={ref_frame} above_ref={} above_ref1={:?} \
329- above_filt={:?} left_ref={} left_ref1={:?} left_filt={:?}",
330- neighbours.above_ref[cmi],
331- neighbours.above_ref1[cmi],
332- neighbours.above_filter[cmi],
333- neighbours.left_ref[rmi],
334- neighbours.left_ref1[rmi],
335- neighbours.left_filter[rmi],
336- );
337- }
338266 // lane-t900 r9: this reader's sub-blocks have a 4-px side, and libaom
339267 // `is_nontrans_global_motion` returns 0 for
340268 // `AOMMIN(mi_size_wide, mi_size_high) < 2` BEFORE testing any model --
341269 // so a GLOBALMV sub-block here always reads its interp filter.
342- if is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation {
343- hit!(GM_NONTRANS_SMALL_SIDE_HITS);
344- }
345270 let gm_nontrans = false;
346271 let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
347272 dec,
@@ -353,16 +278,6 @@ pub(super) fn decode_inter_sub8_split4(
353278 left_filter_ctx,
354279 false,
355280 );
356- if crate::envflags::env_flag!("EC_TRACE_MODE") {
357- eprintln!(
358- "EC_MODE_VAL4 mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \
359- ref0={ref_frame} mv0=({},{}) stack={} rng={}",
360- mv.0,
361- mv.1,
362- stack.entries.len(),
363- dec.debug_state().0
364- );
365- }
366281 grid.set(
367282 rmi,
368283 cmi,
@@ -412,7 +327,11 @@ pub(super) fn decode_inter_sub8_split4(
412327 let pred_y: Vec<u16>;
413328 let sy = if pred_deferred(refpix) {
414329 push_pred(build);
415- Pred::Cur { plane: 0, stride: B4, off: 0 }
330+ Pred::Cur {
331+ plane: 0,
332+ stride: B4,
333+ off: 0,
334+ }
416335 } else {
417336 let mut built: [Vec<u16>; 3] = Default::default();
418337 build(y, u, v, refpix, fctx, &mut built);
@@ -454,9 +373,6 @@ pub(super) fn decode_inter_sub8_split4(
454373 fctx,
455374 )?;
456375 piece_tx_type = tx_type;
457- if i == 0 {
458- sub0_tx_type = tx_type;
459- }
460376 if i == 3 {
461377 // `av1_get_tx_type`'s chroma tail scales `blk_row`/`blk_col`
462378 // back by the subsampling, but it indexes `xd->tx_type_map`,
@@ -522,7 +438,18 @@ pub(super) fn decode_inter_sub8_split4(
522438 let (pred_cu, pred_cv): (Vec<u16>, Vec<u16>);
523439 let (su, sv) = if pred_deferred(refpix) {
524440 push_pred(build_c);
525- (Pred::Cur { plane: 1, stride: B4, off: 0 }, Pred::Cur { plane: 2, stride: B4, off: 0 })
441+ (
442+ Pred::Cur {
443+ plane: 1,
444+ stride: B4,
445+ off: 0,
446+ },
447+ Pred::Cur {
448+ plane: 2,
449+ stride: B4,
450+ off: 0,
451+ },
452+ )
526453 } else {
527454 let mut built: [Vec<u16>; 3] = Default::default();
528455 build_c(y, u, v, refpix, fctx, &mut built);
@@ -706,7 +633,18 @@ pub(super) fn decode_inter_sub8_split4(
706633 let (pred_cu, pred_cv): (Vec<u16>, Vec<u16>);
707634 let (su, sv) = if pred_deferred(refpix) {
708635 push_pred(build_c);
709- (Pred::Cur { plane: 1, stride: B4, off: 0 }, Pred::Cur { plane: 2, stride: B4, off: 0 })
636+ (
637+ Pred::Cur {
638+ plane: 1,
639+ stride: B4,
640+ off: 0,
641+ },
642+ Pred::Cur {
643+ plane: 2,
644+ stride: B4,
645+ off: 0,
646+ },
647+ )
710648 } else {
711649 let mut built: [Vec<u16>; 3] = Default::default();
712650 build_c(y, u, v, refpix, fctx, &mut built);
@@ -747,7 +685,6 @@ pub(super) fn decode_inter_sub8_split4(
747685 neighbours.record_mi_chroma(ctx_mi, 8, 4, 1, &ZERO_RESIDUAL[..B4 * B4]);
748686 neighbours.record_mi_chroma(ctx_mi, 8, 4, 2, &ZERO_RESIDUAL[..B4 * B4]);
749687 } else {
750- hit!(CHROMA422_INTER_SUB8_HITS);
751688 let (ug, _) = read_inter_plane(
752689 dec,
753690 cdfs,
@@ -860,15 +797,6 @@ pub(super) fn decode_inter_sub8_split4(
860797 // mi of the group is intra: the group's 4x4 chroma is then predicted WHOLE
861798 // from the chroma-reference (last) sub-block's own mv, not in 2x2 pieces.
862799 let mixed = piece.iter().any(Option::is_none);
863- if mixed {
864- hit_do! {
865- SUB8_INTRA_RECT_HITS.with(|h| {
866- let mut st = h.get();
867- st[3] += 1;
868- h.set(st);
869- });
870- }
871- }
872800 // lane-sub8group: the group's chroma pieces, built where they are
873801 // written -- the pieces' refs/mvs/filters travel by value.
874802 let build = move |_y: &mut PlaneBuf<'static>,
@@ -934,7 +862,18 @@ pub(super) fn decode_inter_sub8_split4(
934862 let (pred_u, pred_v): (Vec<u16>, Vec<u16>);
935863 let (su, sv) = if pred_deferred(refpix) {
936864 push_pred(build);
937- (Pred::Cur { plane: 1, stride: B4, off: 0 }, Pred::Cur { plane: 2, stride: B4, off: 0 })
865+ (
866+ Pred::Cur {
867+ plane: 1,
868+ stride: B4,
869+ off: 0,
870+ },
871+ Pred::Cur {
872+ plane: 2,
873+ stride: B4,
874+ off: 0,
875+ },
876+ )
938877 } else {
939878 let mut built: [Vec<u16>; 3] = Default::default();
940879 build(y, u, v, refpix, fctx, &mut built);
@@ -1012,8 +951,6 @@ pub(super) fn decode_inter_sub8_split4(
1012951 fctx,
1013952 )?
1014953 .0;
1015- let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0);
1016- note_sub8_chroma_tx(sub0_tx_type, first_tx_type, coded);
1017954 (ug, vg)
1018955 };
1019956 let round_up_even = |n: usize| n.div_ceil(2) * 2;
@@ -1066,7 +1003,6 @@ pub(super) fn decode_intra_sub8_leaf(
10661003 grid: &mut MiGrid,
10671004 group_mi: (usize, usize),
10681005 lmi: (usize, usize),
1069- // `(bw, bh)`: 8x4 / 4x8 under HORZ/VERT, 4x4 under SPLIT.
10701006 (bw, bh): (usize, usize),
10711007 has_chroma: bool,
10721008 skip: bool,
@@ -1074,7 +1010,6 @@ pub(super) fn decode_intra_sub8_leaf(
10741010 y: &mut PlaneBuf<'static>,
10751011 u: &mut PlaneBuf<'static>,
10761012 v: &mut PlaneBuf<'static>,
1077- base_q_idx: u8,
10781013 enable_filter_intra: bool,
10791014 tx_select: bool,
10801015 reduced_tx_set: bool,
@@ -1090,19 +1025,9 @@ pub(super) fn decode_intra_sub8_leaf(
10901025 let (above_mode, left_mode) = neighbours.modes_above_left(r, c);
10911026 let leaf_above = neighbours.mode_above_mi(lmi.0, lmi.1).unwrap_or(above_mode);
10921027 let leaf_left = neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode);
1093- let step = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");
10941028 // `size_group_lookup[BLOCK_8X4] == size_group_lookup[BLOCK_4X8] == 0`
10951029 // (libaom common_data.h:61).
1096- crate::msac::SymbolDecoder::set_symr_cdf("y_mode");
10971030 let mode = dec.symbol(&mut cdfs.y_mode[0]);
1098- if step {
1099- eprintln!(
1100- "EC_ISTEP mi_row={} mi_col={} name=mode val={mode} rng={}",
1101- lmi.0,
1102- lmi.1,
1103- dec.debug_state().0
1104- );
1105- }
11061031 // No angle delta below 8x8 (`av1_use_angle_delta`), for luma or chroma.
11071032 let angle_delta_y = 0;
11081033 let (uv_mode, alpha) = if has_chroma {
@@ -1116,31 +1041,15 @@ pub(super) fn decode_intra_sub8_leaf(
11161041 // always 4x4-or-smaller, so the predicate stays true and this read
11171042 // is unchanged.
11181043 let uv_mode = if cfl_allowed_px(bw, bh, fctx) {
1119- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
11201044 dec.symbol(&mut cdfs.uv_mode_cfl[mode])
11211045 } else {
1122- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
11231046 dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
11241047 };
1125- if step {
1126- eprintln!(
1127- "EC_ISTEP mi_row={} mi_col={} name=uv_mode val={uv_mode} rng={}",
1128- lmi.0,
1129- lmi.1,
1130- dec.debug_state().0
1131- );
1132- }
1133- if (9..=12).contains(&uv_mode) {
1134- hit!(SMOOTH_UV_HITS);
1135- }
11361048 let alpha = if uv_mode == UV_CFL_PRED {
11371049 Some(read_cfl_alphas(dec, cdfs))
11381050 } else {
11391051 None
11401052 };
1141- if (V_PRED..=D67_PRED).contains(&uv_mode) {
1142- hit!(DIRECTIONAL_UV_HITS);
1143- }
11441053 (uv_mode, alpha)
11451054 } else {
11461055 (DC_PRED, None)
@@ -1154,27 +1063,8 @@ pub(super) fn decode_intra_sub8_leaf(
11541063 .expect("BLOCK_4X8/BLOCK_8X4 are inside av1_filter_intra_allowed_bsize")
11551064 };
11561065 let use_fi = dec.symbol(&mut cdfs.filter_intra[fi_class]);
1157- if step {
1158- eprintln!(
1159- "EC_ISTEP mi_row={} mi_col={} name=use_filter_intra val={use_fi} rng={}",
1160- lmi.0,
1161- lmi.1,
1162- dec.debug_state().0
1163- );
1164- }
11651066 if use_fi != 0 {
1166- hit!(FILTER_INTRA_HITS);
1167- hit!(FILTER_INTRA_RECT_HITS);
1168- hit!(FILTER_INTRA_RECT_SUB8_HITS);
11691067 let fi = dec.symbol(&mut cdfs.filter_intra_mode);
1170- if step {
1171- eprintln!(
1172- "EC_ISTEP mi_row={} mi_col={} name=filter_intra_mode val={fi} rng={}",
1173- lmi.0,
1174- lmi.1,
1175- dec.debug_state().0
1176- );
1177- }
11781068 filter_intra = Some(fi);
11791069 }
11801070 }
@@ -1190,24 +1080,12 @@ pub(super) fn decode_intra_sub8_leaf(
11901080 // no depth symbol either (sweep of the class fixed at the key-frame pair
11911081 // path).
11921082 let depth = if tx_select && bw != bh && !lossless(fctx) {
1193- let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh, fctx);
1083+ let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh);
11941084 let d = dec.symbol(&mut cdfs.tx_size_cat0[ctx]);
1195- if step {
1196- eprintln!(
1197- "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=0 rng={}",
1198- lmi.0,
1199- lmi.1,
1200- dec.debug_state().0
1201- );
1202- }
12031085 d
12041086 } else {
12051087 0
12061088 };
1207- if depth != 0 {
1208- hit!(TX_DEPTH_HITS);
1209- hit!(RECT8_SPLIT_TX_HITS);
1210- }
12111089 let split = depth != 0 || (lossless(fctx) && bw != bh);
12121090 let (px, py) = (lmi.1 * MI, lmi.0 * MI);
12131091 let reach = if bw == bh {
@@ -1216,9 +1094,6 @@ pub(super) fn decode_intra_sub8_leaf(
12161094 Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx)
12171095 };
12181096 let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left);
1219- if smooth_neighbor {
1220- hit!(SMOOTH_LUMA_HITS);
1221- }
12221097 neighbours.record_mode_mi(lmi.0, lmi.1, w_mi, h_mi, mode);
12231098 let scan: &[u16] = if vert { &SCAN_4X8 } else { &SCAN_8X4 };
12241099 if split {
@@ -1231,19 +1106,7 @@ pub(super) fn decode_intra_sub8_leaf(
12311106 (lmi.0, lmi.1 + tu)
12321107 };
12331108 let (tu_px, tu_py) = (tu_mi.1 * MI, tu_mi.0 * MI);
1234- let tu_reach = tu_reach(
1235- bw,
1236- bh,
1237- tu_px - px,
1238- tu_py - py,
1239- 4,
1240- reach,
1241- px,
1242- py,
1243- y.width,
1244- y.height,
1245- fctx,
1246- );
1109+ let tu_reach = tu_reach(bw, bh, tu_px - px, tu_py - py, 4, reach);
12471110 if skip {
12481111 let zeros = vec![0i32; 16];
12491112 push_intra(
@@ -1290,7 +1153,6 @@ pub(super) fn decode_intra_sub8_leaf(
12901153 tu_py,
12911154 4,
12921155 TX4,
1293- base_q_idx,
12941156 None,
12951157 filter_intra,
12961158 Some(tu_skip_ctx),
@@ -1346,7 +1208,6 @@ pub(super) fn decode_intra_sub8_leaf(
13461208 py,
13471209 4,
13481210 TX4,
1349- base_q_idx,
13501211 None,
13511212 filter_intra,
13521213 None,
@@ -1396,7 +1257,6 @@ pub(super) fn decode_intra_sub8_leaf(
13961257 0,
13971258 dc_sign_ctx(around.2),
13981259 TxType::DctDct,
1399- 0,
14001260 )?;
14011261 let residual = dequant_and_inverse_typed_wh(
14021262 &levels,
@@ -1484,14 +1344,6 @@ pub(super) fn decode_intra_sub8_leaf(
14841344 is_global_mv1: false,
14851345 },
14861346 );
1487- hit_do! {
1488- SUB8_INTRA_RECT_HITS.with(|h| {
1489- let mut s = h.get();
1490- s[usize::from(vert)] += 1;
1491- s[2] += usize::from(has_chroma);
1492- h.set(s);
1493- });
1494- }
14951347 // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map
14961348 // needs EVERY writer): a sub-8x8 group published no palette state, so
14971349 // once an 8x8 leaf of the same row can BE a palette block, the group
@@ -1544,7 +1396,6 @@ pub(super) fn decode_intra_sub8_leaf(
15441396 u,
15451397 v,
15461398 scan4,
1547- base_q_idx,
15481399 neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx),
15491400 (bw, bh),
15501401 fctx,
@@ -1611,10 +1462,6 @@ pub(super) fn decode_intra_sub8_leaf(
16111462 });
16121463 let mut chroma_stamped_per_unit = false;
16131464 let (u_grid, v_grid): (Grid, Grid) = if skip {
1614- if alpha.is_some() {
1615- hit!(CHROMA_SKIP_CFL_HITS);
1616- hit!(SKIP_CFL_HITS);
1617- }
16181465 if chroma_444 && bw != bh {
16191466 let zeros = Grid::Zero(bw * bh);
16201467 push_intra_rect(
@@ -1718,8 +1565,7 @@ pub(super) fn decode_intra_sub8_leaf(
17181565 // At 4:4:4 a TX_4X4 chroma unit IS one mi cell.
17191566 let tu_mi = (lmi.0 + oy / MI, lmi.1 + ox / MI);
17201567 let tu_around = neighbours.around_mi(tu_mi, MI);
1721- let tu_r =
1722- tu_reach(bw, bh, ox, oy, 4, reach_c, px, py, y.width, y.height, fctx);
1568+ let tu_r = tu_reach(bw, bh, ox, oy, 4, reach_c);
17231569 // The plane block (8x4/4x8) is bigger than the TX_4X4
17241570 // transform, so `get_txb_ctx`'s chroma ctx_offset is 10,
17251571 // not 7 -- our chroma tables carry the offset-10 rows at
@@ -1743,7 +1589,6 @@ pub(super) fn decode_intra_sub8_leaf(
17431589 py + oy,
17441590 4,
17451591 TX4,
1746- base_q_idx,
17471592 None,
17481593 None,
17491594 Some(3),
@@ -1754,7 +1599,6 @@ pub(super) fn decode_intra_sub8_leaf(
17541599 // (`av1_set_contexts`); the tail's whole-leaf chroma
17551600 // stamp below is skipped for this shape.
17561601 neighbours.record_mi_chroma(tu_mi, 4, 4, plane_idx, &tu_grid);
1757- hit!(CHROMA_SPLIT_TX_HITS);
17581602 let dst = mu_units(if plane_idx == 1 { &mut uo } else { &mut vo }, bw * bh);
17591603 for row in 0..4 {
17601604 let start = (oy + row) * bw + ox;
@@ -1763,7 +1607,6 @@ pub(super) fn decode_intra_sub8_leaf(
17631607 }
17641608 }
17651609 chroma_stamped_per_unit = true;
1766- hit!(LLSUB8RECT444_CHROMA_WALK_HITS);
17671610 (
17681611 if uo.is_empty() {
17691612 Grid::Zero(bw * bh)
@@ -1801,7 +1644,6 @@ pub(super) fn decode_intra_sub8_leaf(
18011644 skip_ctx,
18021645 dc_sign_ctx(around.2),
18031646 uv_tx,
1804- plane,
18051647 )?;
18061648 let residual = dequant_and_inverse_typed_wh(
18071649 &levels,
@@ -1861,7 +1703,6 @@ pub(super) fn decode_intra_sub8_leaf(
18611703 unit_y,
18621704 4,
18631705 TX4,
1864- base_q_idx,
18651706 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
18661707 None,
18671708 None,
@@ -1886,7 +1727,6 @@ pub(super) fn decode_intra_sub8_leaf(
18861727 unit_y,
18871728 4,
18881729 TX4,
1889- base_q_idx,
18901730 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
18911731 None,
18921732 None,
@@ -2004,13 +1844,6 @@ pub(super) fn decode_inter_sub8_rect2(
20041844 (8usize, 4usize)
20051845 };
20061846 let (w_mi, h_mi) = (bw / MI, bh / MI);
2007- hit_do! {
2008- SUB8_INTER_RECT_HITS.with(|c| {
2009- let mut h = c.get();
2010- h[usize::from(vert)] += 1;
2011- c.set(h);
2012- });
2013- }
20141847 let (gr, gc) = group_mi;
20151848 let (gpx, gpy) = (gc * MI, gr * MI);
20161849 let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx));
@@ -2018,7 +1851,6 @@ pub(super) fn decode_inter_sub8_rect2(
20181851 let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 2] =
20191852 [None; 2];
20201853 let mut first_tx_type = TxType::DctDct;
2021- let mut sub0_tx_type = TxType::DctDct;
20221854 // lane-av1-444: `is_chroma_reference` is unconditional at subsampling 0/0
20231855 // (av1_common_int.h:1459), so every 8x4/4x8 piece is its own chroma
20241856 // reference and codes its own 8x4/4x8 U/V units right after its luma --
@@ -2099,15 +1931,6 @@ pub(super) fn decode_inter_sub8_rect2(
20991931 );
21001932 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
21011933 if !is_inter {
2102- if crate::envflags::env_flag!("EC_SUB8INTRA") {
2103- eprintln!(
2104- "EC_SUB8INTRA shape={}x{} sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}",
2105- bw,
2106- bh,
2107- piece_is_chroma_ref(i),
2108- fctx.tx_select_inter.with(std::cell::Cell::get),
2109- );
2110- }
21111934 // lane-sub8x4 r2: refusal and bypass lifted -- see the split arm's
21121935 // note above for the gate that proves this leaf.
21131936 // Its chroma rule is `is_sub8x8_inter`'s: when the
@@ -2128,7 +1951,6 @@ pub(super) fn decode_inter_sub8_rect2(
21281951 y,
21291952 u,
21301953 v,
2131- base_q_idx,
21321954 fctx.enable_filter_intra_inter.with(std::cell::Cell::get),
21331955 fctx.tx_select_inter.with(std::cell::Cell::get),
21341956 reduced_tx_set,
@@ -2139,12 +1961,6 @@ pub(super) fn decode_inter_sub8_rect2(
21391961 }
21401962 continue;
21411963 }
2142- if crate::envflags::env_flag!("EC_TRACE_MODE") {
2143- eprintln!(
2144- "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",
2145- dec.debug_state().0
2146- );
2147- }
21481964 let ref_frame = read_single_ref(
21491965 dec,
21501966 cdfs,
@@ -2158,9 +1974,6 @@ pub(super) fn decode_inter_sub8_rect2(
21581974 let (ref_width, ref_height) = ref_dims(ref_frame, refpix)?;
21591975 // lane-t900 r28: refusal lifted -- see the split arm above.
21601976 let luma_scale = scale_of((ref_width, ref_height), frame_size);
2161- if !luma_scale.is_unscaled() {
2162- hit!(SCALED_SUB8_HITS);
2163- }
21641977 let gm_table = build_gm_mv_table(
21651978 global_motion,
21661979 rmi,
@@ -2194,10 +2007,6 @@ pub(super) fn decode_inter_sub8_rect2(
21942007 tpl,
21952008 );
21962009 let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
2197- if !not_new {
2198- crate::census::mode(0);
2199- }
2200- let mut is_globalmv = false;
22012010 let (mv, is_new_mv) = if !not_new {
22022011 let mut idx = 0usize;
22032012 while idx < 2 && stack.entries.len() > idx + 1 {
@@ -2221,15 +2030,10 @@ pub(super) fn decode_inter_sub8_rect2(
22212030 )
22222031 } else {
22232032 let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;
2224- if !not_zero {
2225- crate::census::mode(1);
2226- }
2227- is_globalmv = !not_zero;
22282033 let mv = if !not_zero {
22292034 gm_table[(ref_frame - LAST_FRAME) as usize]
22302035 } else {
22312036 let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
2232- crate::census::mode(if nearest { 2 } else { 3 });
22332037 if nearest {
22342038 stack.nearest_mv
22352039 } else {
@@ -2245,15 +2049,6 @@ pub(super) fn decode_inter_sub8_rect2(
22452049 };
22462050 (mv, false)
22472051 };
2248- if crate::envflags::env_flag!("EC_TRACE_MODE") {
2249- eprintln!(
2250- "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",
2251- mv.0,
2252- mv.1,
2253- dec.debug_state().0
2254- );
2255- }
2256- let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize];
22572052 let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame
22582053 || neighbours.above_ref1[cmi] == Some(ref_frame)
22592054 {
@@ -2272,9 +2067,6 @@ pub(super) fn decode_inter_sub8_rect2(
22722067 // `is_nontrans_global_motion` returns 0 for
22732068 // `AOMMIN(mi_size_wide, mi_size_high) < 2` BEFORE testing any model --
22742069 // so a GLOBALMV sub-block here always reads its interp filter.
2275- if is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation {
2276- hit!(GM_NONTRANS_SMALL_SIDE_HITS);
2277- }
22782070 let gm_nontrans = false;
22792071 let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
22802072 dec,
@@ -2321,9 +2113,6 @@ pub(super) fn decode_inter_sub8_rect2(
23212113 // exactly that population -- so an unconditional hit proves only
23222114 // "a lossless sub-8 leaf was walked", not "the conjunct suppressed
23232115 // a tree". Guard it on the same term the conjunct uses.
2324- if fctx.tx_select_inter.with(std::cell::Cell::get) {
2325- hit!(SUB8_LOSSLESS_NO_VARTX);
2326- }
23272116 // lane-lossless2: `read_block_tx_size` returns TX_4X4 before it
23282117 // ever looks at `max_txsize_rect_lookup`, so an 8x4/4x8 leaf is
23292118 // TWO 4x4 units, not one rect one.
@@ -2337,17 +2126,6 @@ pub(super) fn decode_inter_sub8_rect2(
23372126 leaves.push((0, 0, bw, bh));
23382127 set_txfm_ctxs(neighbours, lmi, bw.max(bh), w_mi, h_mi, skip);
23392128 }
2340- if crate::envflags::env_flag!("EC_TRACE_MODE") {
2341- eprintln!(
2342- "EC_MODE_VALR mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \
2343- ref0={ref_frame} mv0=({},{}) stack={} leaves={} rng={}",
2344- mv.0,
2345- mv.1,
2346- stack.entries.len(),
2347- leaves.len(),
2348- dec.debug_state().0
2349- );
2350- }
23512129 grid_stamp_rect(grid, rmi, cmi, w_mi, h_mi, ref_frame, mv, is_new_mv);
23522130 piece[i] = Some((ref_frame, mv, h_filter, v_filter));
23532131 // Prediction over the leaf's true footprint, laid out at the group's
@@ -2389,7 +2167,11 @@ pub(super) fn decode_inter_sub8_rect2(
23892167 let pred_y: Vec<u16>;
23902168 let sy = if pred_deferred(refpix) {
23912169 push_pred(build);
2392- Pred::Cur { plane: 0, stride: SIDE, off: 0 }
2170+ Pred::Cur {
2171+ plane: 0,
2172+ stride: SIDE,
2173+ off: 0,
2174+ }
23932175 } else {
23942176 let mut built: [Vec<u16>; 3] = Default::default();
23952177 build(y, u, v, refpix, fctx, &mut built);
@@ -2492,9 +2274,6 @@ pub(super) fn decode_inter_sub8_rect2(
24922274 if idx == 0 {
24932275 piece_tx_type = tu_tx_type;
24942276 }
2495- if idx == 0 && i == 0 {
2496- sub0_tx_type = tu_tx_type;
2497- }
24982277 if idx == 0 && i == 1 {
24992278 // `av1_get_tx_type` indexes `xd->tx_type_map`, which
25002279 // `set_mi_offsets` (av1_common_int.h:1679) re-points to the
@@ -2563,7 +2342,18 @@ pub(super) fn decode_inter_sub8_rect2(
25632342 let (pred_cu, pred_cv): (Vec<u16>, Vec<u16>);
25642343 let (su, sv) = if pred_deferred(refpix) {
25652344 push_pred(build_c);
2566- (Pred::Cur { plane: 1, stride: SIDE, off: 0 }, Pred::Cur { plane: 2, stride: SIDE, off: 0 })
2345+ (
2346+ Pred::Cur {
2347+ plane: 1,
2348+ stride: SIDE,
2349+ off: 0,
2350+ },
2351+ Pred::Cur {
2352+ plane: 2,
2353+ stride: SIDE,
2354+ off: 0,
2355+ },
2356+ )
25672357 } else {
25682358 let mut built: [Vec<u16>; 3] = Default::default();
25692359 build_c(y, u, v, refpix, fctx, &mut built);
@@ -2813,7 +2603,18 @@ pub(super) fn decode_inter_sub8_rect2(
28132603 let (pred_cu, pred_cv): (Vec<u16>, Vec<u16>);
28142604 let (su, sv) = if pred_deferred(refpix) {
28152605 push_pred(build_c);
2816- (Pred::Cur { plane: 1, stride: B4, off: 0 }, Pred::Cur { plane: 2, stride: B4, off: 0 })
2606+ (
2607+ Pred::Cur {
2608+ plane: 1,
2609+ stride: B4,
2610+ off: 0,
2611+ },
2612+ Pred::Cur {
2613+ plane: 2,
2614+ stride: B4,
2615+ off: 0,
2616+ },
2617+ )
28172618 } else {
28182619 let mut built: [Vec<u16>; 3] = Default::default();
28192620 build_c(y, u, v, refpix, fctx, &mut built);
@@ -2851,7 +2652,6 @@ pub(super) fn decode_inter_sub8_rect2(
28512652 neighbours.record_mi_chroma(ctx_mi, 8, 4, 1, &ZERO_RESIDUAL[..B4 * B4]);
28522653 neighbours.record_mi_chroma(ctx_mi, 8, 4, 2, &ZERO_RESIDUAL[..B4 * B4]);
28532654 } else {
2854- hit!(CHROMA422_INTER_SUB8_HITS);
28552655 let (ug, _) = read_inter_plane(
28562656 dec,
28572657 cdfs,
@@ -2956,15 +2756,6 @@ pub(super) fn decode_inter_sub8_rect2(
29562756 // chroma-reference block's own mv, at the group's chroma origin
29572757 // (`row_start`/`col_start` shift `pre_x`/`pre_y` there either way).
29582758 let mixed = piece[0].is_none();
2959- if mixed {
2960- hit_do! {
2961- SUB8_INTRA_RECT_HITS.with(|h| {
2962- let mut s = h.get();
2963- s[3] += 1;
2964- h.set(s);
2965- });
2966- }
2967- }
29682759 let (piece_w, piece_h) = match (mixed, vert) {
29692760 (true, _) => (B4, B4),
29702761 (false, true) => (2usize, 4usize),
@@ -3038,7 +2829,18 @@ pub(super) fn decode_inter_sub8_rect2(
30382829 let (pred_u, pred_v): (Vec<u16>, Vec<u16>);
30392830 let (su, sv) = if pred_deferred(refpix) {
30402831 push_pred(build);
3041- (Pred::Cur { plane: 1, stride: B4, off: 0 }, Pred::Cur { plane: 2, stride: B4, off: 0 })
2832+ (
2833+ Pred::Cur {
2834+ plane: 1,
2835+ stride: B4,
2836+ off: 0,
2837+ },
2838+ Pred::Cur {
2839+ plane: 2,
2840+ stride: B4,
2841+ off: 0,
2842+ },
2843+ )
30422844 } else {
30432845 let mut built: [Vec<u16>; 3] = Default::default();
30442846 build(y, u, v, refpix, fctx, &mut built);
@@ -3116,8 +2918,6 @@ pub(super) fn decode_inter_sub8_rect2(
31162918 fctx,
31172919 )?
31182920 .0;
3119- let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0);
3120- note_sub8_chroma_tx(sub0_tx_type, first_tx_type, coded);
31212921 (ug, vg)
31222922 };
31232923 let round_up_even = |n: usize| n.div_ceil(2) * 2;
crates/ec-av1/src/decode/tests.rsmodified+36 -1309
@@ -1,329 +1,3 @@
1-/// lane-av1unwritten r7: the STRUCTURAL invariant that r5 and r6 both broke.
2-///
3-/// r5 put guards inside `PARTITION_HORZ_A..=PARTITION_VERT_B` arms, so they
4-/// could only ever see values 4..=7. r6 deleted the inter-16 guard and did not
5-/// replace it. r7's fix was mechanical at both sites and the failure mode was
6-/// always the same: a guard exists somewhere, and nothing says it sits between
7-/// a symbol's RESOLUTION and every dispatch of it.
8-///
9-/// So the invariant is stated over the dispatch structure, not over a list.
10-/// Counts in the tree this was written against, re-derived per line rather
11-/// than grepped: `refuse_invalid_subsize((` occurs **18 times** in this file —
12-/// **11 guard call sites** in the decode body (35588, 36278, 36406, 36472,
13-/// 36882, 37132, 53985, 54222, 54606, 54752, 55164), **5** in this test's own
14-/// string literals and comparisons, **2** in doc comments; the definition's
15-/// signature line does not match `((` at all. The scan finds **10 resolutions**:
16-/// the eleventh guard is the inter-frame 128 one, whose resolution lives in
17-/// the shared `read_sb128_root`, so a guard has no resolution of its own here.
18-/// What is asserted, exactly:
19-///
20-/// * every `partition_w<N>[` level in the file appears among the resolutions
21-/// this scan finds -- a new level cannot be added without a guard check;
22-/// * each resolution is followed, within 220 lines, by a
23-/// `refuse_invalid_subsize((N, N), …)` for its OWN level (matched on the
24-/// level, not the variable, because the symbol is often bound to a
25-/// short-lived inner name `p` and dispatched by an outer `part64`);
26-/// * where that window contains a `match part…` dispatch, the guard precedes
27-/// it -- the bound r7's COMMENT claimed and r8 implements;
28-/// * no guard sits inside a `PARTITION_HORZ_A..=PARTITION_VERT_B` arm.
29-///
30-/// It does NOT prove a guard is at the exact dispatch point: the window is a
31-/// window. And the two cross-checks are weaker than they look — cross-check 1
32-/// is level PRESENCE only, cross-check 2 is `>=` — so a SECOND unguarded site
33-/// at an already-covered level is caught ONLY by the per-site 220-line window,
34-/// which is a window and not a dispatch bound. That limit is why the AB-arm
35-/// invariant exists separately, and why `EC_AV1_SUBSIZE_GUARD_TRACE` records
36-/// what each site really sees over the corpus.
37-#[test]
38-fn every_partition_symbol_resolution_is_guarded_before_it_dispatches() {
39- let src = crate::test_source::module_source("decode");
40- // Every partition-symbol RESOLUTION in the file, with the level read off
41- // the CDF name on the line itself. Two independent counts are compared, so
42- // a site lost to line wrapping reds instead of silently vanishing: the
43- // Every partition-symbol RESOLUTION in the file. The window is the line
44- // BEFORE as well as the line itself and the one after (r9), because a
45- // `let <var> =` on one line with `dec.symbol(&mut cdfs.partition_w8[..])`
46- // on the next is a real shape in this file -- and r9's own ungated site at
47- // 37115 was invisible for exactly that reason.
48- let lines: Vec<&str> = src.lines().collect();
49- let mut sites: Vec<(usize, String, usize)> = Vec::new();
50- // Occurrences of `partition_w<N>[` per level, counted from the FILE, used as
51- // the cross-check below.
52- let mut file_occurrences: std::collections::BTreeMap<usize, usize> = Default::default();
53- // Only the DECODE body: the test module below also builds `partition_w8`
54- // CDFs (an encoder round-trip at 58464/58521), and counting those would
55- // demand a guard for a site that does not exist.
56- let production = crate::test_source::module_production_source("decode");
57- let decode_body = match production.find("\n#[cfg(test)]\nmod tests {") {
58- Some(i) => &production[..i],
59- None => production,
60- };
61- {
62- let mut rest = decode_body;
63- while let Some(i) = rest.find("partition_w") {
64- let after = &rest[i + "partition_w".len()..];
65- let digits: String = after.chars().take_while(char::is_ascii_digit).collect();
66- rest = after;
67- if digits.is_empty() {
68- continue; // `partition_wide`, or any other word starting the same way
69- }
70- if after[digits.len()..].starts_with('[') {
71- *file_occurrences
72- .entry(digits.parse().expect("digits"))
73- .or_insert(0) += 1;
74- }
75- }
76- }
77- // r11 (lane-av1subsizesweep): a partition-symbol READ is a `dec.<name>(..)`
78- // call whose OWN ARGUMENT LIST names a `partition_w<N>[` CDF. That is the
79- // whole definition, and it is why the read spellings need no hand-list:
80- // `dec.symbol(..partition_w..)` qualifies, the frame-edge gather's
81- // `dec.symbol_fixed(&gather(..partition_w..))` qualifies, and
82- // `dec.debug_state()` does not -- it never names a partition CDF. A third
83- // spelling is covered the day somebody writes it.
84- //
85- // r11's hole was a SPELLING gap, not a shape gap: the old matcher named
86- // `dec.symbol(` literally, and `dec.symbol(` is not a substring of
87- // `dec.symbol_fixed(`. So the key-frame 16-level frame-edge arm -- which
88- // dispatches `decode_leaf_rect` straight off a gathered `edge_split` onto
89- // a BLOCK_8X16 chroma walk -- was never a site at all.
90- let is_partition_read = |window: &str| -> bool {
91- let mut at = 0usize;
92- while let Some(rel) = window[at..].find("dec.") {
93- let call = at + rel + "dec.".len();
94- at = call;
95- let name: String = window[call..]
96- .chars()
97- .take_while(|c| c.is_ascii_alphanumeric() || *c == '_')
98- .collect();
99- if name.is_empty() {
100- continue;
101- }
102- let Some(open) = window[call + name.len()..].find('(') else {
103- continue;
104- };
105- let arg_from = call + name.len() + open + 1;
106- let mut depth = 1usize;
107- let mut stop = None;
108- for (i, c) in window[arg_from..].char_indices() {
109- match c {
110- '(' => depth += 1,
111- ')' => {
112- depth -= 1;
113- if depth == 0 {
114- stop = Some(arg_from + i);
115- break;
116- }
117- }
118- _ => {}
119- }
120- }
121- let Some(stop) = stop else { continue };
122- if window[arg_from..stop].contains("partition_w") {
123- return true;
124- }
125- }
126- false
127- };
128- for (n, line) in lines.iter().enumerate() {
129- let t = line.trim_start();
130- // A doc comment quoting the shape is not a site, and neither is the
131- // test's own example strings further down the file.
132- if t.starts_with("//") || !line.contains("partition_w") || n > 56000 {
133- continue;
134- }
135- let lo = n.saturating_sub(1);
136- let hi = (n + 2).min(lines.len());
137- let window = lines[lo..hi].join(" ");
138- // r11: the read test is the DERIVED predicate above, not a spelling
139- // literal. Naming `dec.symbol(` here is what hid the frame-edge arm.
140- if !is_partition_read(&window) {
141- continue;
142- }
143- let Some(i) = window.find("partition_w") else {
144- continue;
145- };
146- let after = &window[i + "partition_w".len()..];
147- let digits: String = after.chars().take_while(char::is_ascii_digit).collect();
148- if digits.is_empty() {
149- continue;
150- }
151- let level: usize = digits.parse().expect("digits");
152- // The bound variable is the token after `let `, looked for in the two
153- // lines the binding can occupy (r9: it may be the line above).
154- // r10: scan BACKWARDS from the closest line and take the nearest `let`
155- // whose binding is the one followed by this symbol read -- taking the
156- // first `let` upward named an unrelated binding above it.
157- let mut var = None;
158- for cand in (lo..=n).rev() {
159- let ct = lines[cand].trim_start();
160- if ct.starts_with("//") {
161- continue;
162- }
163- let Some(v) = ct.strip_prefix("let ") else {
164- continue;
165- };
166- let name = v
167- .split(|c: char| !(c.is_alphanumeric() || c == '_'))
168- .next()
169- .unwrap_or("")
170- .to_string();
171- if name.is_empty() {
172- continue;
173- }
174- // This binding is followed by the symbol read if the SAME line
175- // completes `let <name> = dec.<spelling>(`, or if the next line
176- // starts the call. That is what separates `let part8 =` from an
177- // unrelated `let ec_dbg_pre =` two lines above it.
178- let next = lines.get(cand + 1).copied().unwrap_or("");
179- let binds_here = ct.contains("= dec.") || next.contains("dec.");
180- if binds_here || cand == n {
181- var = Some(name);
182- break;
183- }
184- }
185- let Some(var) = var else { continue };
186- // r11: the edge `gather` reads are SITES now, not skips. r10 skipped
187- // them on the reasoning that "the site is guarded at the level's own
188- // resolution instead" -- true for every arm that resolves into a
189- // `partN`, and FALSE for the one that does not: the key-frame 16-level
190- // frame-edge arm dispatches `decode_leaf_rect` straight off `edge_split`,
191- // and `BLOCK_8X16` is BLOCK_INVALID at 4:2:2. Every site therefore has
192- // to carry a guard for its OWN level between the read and the first
193- // chroma-walking dispatch after it -- see the per-site check below.
194- sites.push((n, var, level));
195- }
196-
197- // ---- cross-check 1: every `partition_w<N>` LEVEL in the decode body has
198- // at least one guarded resolution. r9: this is level PRESENCE, and it is
199- // stated as such -- it cannot catch a SECOND unguarded site at an already
200- // covered level. What does catch that is cross-check 2 below (the exact
201- // guard/resolution count) together with the per-site assertion.
202- let mut covered: std::collections::BTreeSet<usize> = Default::default();
203- for (_, _, level) in &sites {
204- covered.insert(*level);
205- }
206- for level in file_occurrences.keys() {
207- assert!(
208- covered.contains(level),
209- "level {level} names a `partition_w{level}[` CDF in the decode body but this \
210- scan finds no guarded resolution for it (r9)"
211- );
212- }
213-
214- // ---- cross-check 2: an EXACT count derived from the scan, never a floor.
215- // Counted by CALL SHAPE -- a line whose first token is the call -- so a
216- // multi-line assert string mentioning the function is not counted, and the
217- // definition is not either.
218- let guarded_sites = decode_body
219- .lines()
220- .filter(|l| l.trim_start().starts_with("refuse_invalid_subsize(("))
221- .count();
222- // r9: was `assert_eq!`, which the tree's own counts disagree on (the scan
223- // sees 10 resolutions against 11 guards), and a hard-equal on two numbers the
224- // scan itself computes is a claim about the SCANNER, not about coverage. It
225- // is `>=` plus the per-site assertion below: a resolution with no guard reds
226- // on its own line, which is the property that matters, and a guard with no
227- // resolution behind it is redundant rather than harmful.
228- assert!(
229- guarded_sites >= sites.len(),
230- "the decode body has {sites_len} partition resolutions but only {guarded_sites} \
231- guard sites -- fewer guards than resolutions (r9)",
232- sites_len = sites.len()
233- );
234-
235- for (line_no, var, level) in &sites {
236- // Two properties, both stated exactly:
237- //
238- // (a) a guard for THIS LEVEL appears after the binding, within a
239- // 220-line window -- matched on the level, not the variable name,
240- // because the symbol is often bound to a short-lived inner name
241- // (`p`) and dispatched by an outer one (`part64`);
242- // (b) where the window contains a `match part…` dispatch, the guard
243- // precedes it.
244- let window: Vec<&str> = lines[line_no + 1..(line_no + 221).min(lines.len())].to_vec();
245- let guard_at = window
246- .iter()
247- .position(|l| l.contains(&format!("refuse_invalid_subsize(({level}, {level})")));
248- assert!(
249- guard_at.is_some(),
250- "{} (decode.rs:{}) resolves a {level}x{level} partition symbol with NO \
251- refuse_invalid_subsize(({level}, {level})) within 220 lines after it -- a \
252- subsize libaom refuses can walk straight through",
253- var,
254- line_no + 1
255- );
256- let dispatch_at = window.iter().position(|l| {
257- let t = l.trim_start();
258- !t.starts_with("//") && t.starts_with("match part")
259- });
260- if let Some(d) = dispatch_at {
261- assert!(
262- guard_at.expect("checked above") < d,
263- "{} (decode.rs:{}) is DISPATCHED at window line {d} BEFORE its \
264- refuse_invalid_subsize(({level}, {level})) -- the guard can never \
265- observe that dispatch",
266- var,
267- line_no + 1
268- );
269- }
270- }
271-
272- // The r5 defect, as its own invariant: a guard must never sit INSIDE a
273- // `PARTITION_HORZ_A..=PARTITION_VERT_B` arm. Such an arm can only carry
274- // partition values 4..=7, and the offending values are PARTITION_VERT (2)
275- // and PARTITION_VERT_4 (9). Tracked by INDENTATION, because brace counting
276- // over a file full of comments and macro bodies drifts.
277- let indent_of = |l: &str| l.len() - l.trim_start().len();
278- // (arm indent, arm BODY indent). r9: the tracker used to self-clear on the
279- // `{` line, because that line carries the SAME indent as the `if` -- so a
280- // guard placed INSIDE an arm body was invisible and r5's defect reproduced
281- // green in the checker. Now the arm's body indent is one level deeper than
282- // the opener's, and the tracker clears only below THAT, or on a closing
283- // brace at the opener's own indent.
284- let mut ab_arm: Option<(usize, bool)> = None;
285- for (n, line) in src.lines().enumerate() {
286- let t = line.trim_start();
287- if t.starts_with("//") {
288- continue;
289- }
290- let ind = indent_of(line);
291- // r9: the arm's `{` sits on a LATER line than the condition, and the
292- // condition itself wraps, so clearing on the first line back at the
293- // opener's indent self-cleared BEFORE the body -- which is why moving
294- // the kf-16 guard back inside an arm stayed GREEN. Now: arm at the
295- // condition, ENTER the body one level deeper, clear only after having
296- // been inside it.
297- if line.contains("PARTITION_HORZ_A..=PARTITION_VERT_B") {
298- ab_arm = Some((ind + 4, false));
299- } else if t == "{" {
300- // r10: the arm's own brace carries the OPENER's indent, not the
301- // body's, so treating it as "backed out" cleared the arm before a
302- // single body statement was seen -- which is why the mutation that
303- // moves a guard INSIDE an arm stayed GREEN at r8 AND r9. A lone `{`
304- // never changes the state.
305- } else if let Some((body, entered)) = ab_arm {
306- if !entered {
307- if ind >= body {
308- ab_arm = Some((body, true));
309- }
310- } else if ind < body {
311- ab_arm = None;
312- }
313- }
314- if line.contains("refuse_invalid_subsize((") {
315- assert!(
316- ab_arm.is_none_or(|_| false),
317- "decode.rs:{} puts a refuse_invalid_subsize inside a \
318- PARTITION_HORZ_A..=PARTITION_VERT_B arm (values 4..=7 only); the \
319- offending values are PARTITION_VERT (2) and PARTITION_VERT_4 (9), which \
320- that arm can never observe -- r5's defect",
321- n + 1
322- );
323- }
324- }
325-}
326-
3271 /// lane-av1unwritten: the port is a TRANSCRIPTION, and this is the artefact
3282 /// that makes it checkable. It re-writes `av1_ss_size_lookup`'s 22 rows
3293 /// (`common_data.c:17-41`) literally -- every shape, every subsampling
@@ -454,886 +128,6 @@ fn chroma_plane_block_codable_matches_the_libaom_table() {
454128 );
455129 }
456130
457-/// lane-av1subsizesweep: the CENSUS, as an invariant.
458-///
459-/// The merged `lane/av1unwritten` lane covers partition SYMBOLS: every
460-/// `dec.symbol(&mut cdfs.partition_w<N>[..])` gets a
461-/// [`refuse_invalid_subsize`] within 220 lines, and
462-/// [`every_partition_symbol_resolution_is_guarded_before_it_dispatches`]
463-/// holds that shape against the source. Its own stated limit is exactly
464-/// the hole this lane found: the scan matches on `dec.symbol(`, so the
465-/// frame-edge GATHER reads (`dec.symbol_fixed(&gather(..))`) are invisible
466-/// to it, and its site list names RESOLUTIONS, not the chroma-plane WALKS
467-/// those resolutions descend into.
468-///
469-/// So this test states the other half, over the WALK sites instead of the
470-/// symbol sites:
471-///
472-/// * every `decode_*` call that walks a chroma plane is enumerated, with
473-/// the luma shape(s) it can be handed -- derived from the enclosing
474-/// dispatch, not typed in by hand;
475-/// * for each shape that libaom marks BLOCK_INVALID at some subsampling
476-/// mode, the walk must have a [`refuse_invalid_subsize`] for its OWN
477-/// level on its path -- either at the level that dispatched it
478-/// (`PARTITION_*` arms resolve into a `partN`) or at the dispatch site
479-/// itself;
480-/// * a walk reachable ONLY through a level whose guard already refuses the
481-/// offending subsize is CLOSED, and the reason is the level's own guard
482-/// line -- asserted, not commented.
483-///
484-/// The residue the merged lane named, [`decode_rect4_16_intrabc`], is the
485-/// second case: it is reachable only from the 16x16-level 1:4 arms, and
486-/// `partition_subsize_dims((16,16), PARTITION_VERT_4) == (4,16)`, which is
487-/// in `PLANE_BLOCK_INVALID_422`. Both of its callers' guards refuse that
488-/// before the call, so it is CLOSED rather than guarded a third time --
489-/// and this test is what makes that a checked claim instead of a comment.
490-#[test]
491-fn every_chroma_walking_leaf_dispatch_is_guarded_or_closed_with_a_reason() {
492- let src = crate::test_source::module_source("decode");
493- // r2: `decode_body` is hoisted to the top of the test because the per-row
494- // guard check below needs it BEFORE the walk census it sits under, and a
495- // reader who has to hunt for a binding is a reader who will not notice
496- // when it is scoped to the wrong thing.
497- let production = crate::test_source::module_production_source("decode");
498- let decode_body = match production.find("\n#[cfg(test)]\nmod tests {") {
499- Some(i) => &production[..i],
500- None => production,
501- };
502- // (a) The shapes libaom cannot code, transcribed from the same
503- // `av1_ss_size_lookup` cells `PLANE_BLOCK_INVALID_422` carries. A walk
504- // handed one of these at the matching subsampling mode is the defect.
505- let invalid_at =
506- |bw: usize, bh: usize, sx: usize, sy: usize| !chroma_plane_block_codable(bw, bh, sx, sy);
507-
508- // (b) The CENSUS: every chroma-plane walk in the decode body, with the
509- // luma footprint(s) each dispatch can hand it. `guarded_by` names the
510- // mechanism, which is what a reader has to be able to check:
511- //
512- // * `refuse_invalid_subsize` at the DISPATCH -- the guard sits on
513- // the walk's own path (the hole this lane fixed, and the 8x8 /
514- // 16-level sites);
515- // * `refuse_invalid_subsize` at the RESOLUTION -- the dispatch is a
516- // `PARTITION_*` arm, so the level's guard saw the symbol that
517- // selected this shape before the call;
518- // * `unreachable` -- proven-uncodable at every subsampling mode a
519- // `color_config` can select, closed with an assertion instead of
520- // a guard.
521- //
522- // Each row is (walk, shapes, mechanism).
523- //
524- // r2 (Main's review, and it was right): `AtResolution` used to assert
525- // only that SOME shape the walk handles is BLOCK_INVALID, which
526- // restates the libaom table and never mentions a guard -- deleting the
527- // inter 32-level guard left it green. So a resolution row now CARRIES
528- // the guard it depends on: `(walk, fn-scope, level)`, and the check
529- // below looks for `refuse_invalid_subsize((level, level))` inside that
530- // function and before the walk's first call site in it. A row that
531- // cannot be checked that way says so with `Prose` instead.
532- enum Mech {
533- AtDispatch,
534- /// Protected by `refuse_invalid_subsize((L, L))` in the named
535- /// function, above the walk's first call site there.
536- AtResolution(&'static str, usize),
537- /// The walk is reached INDIRECTLY -- this row's guard is asserted to
538- /// exist in `fscope`, and the ordering is asserted by the per-route
539- /// loop further down (which scopes to the enclosing function and
540- /// names this walk's real caller chain). Used only where the walk's
541- /// call site is not in the guard's own function.
542- AtResolutionVia(&'static str, usize),
543- Unreachable(&'static str),
544- }
545- // The key-frame tile decoder and the inter tile decoder. Every
546- // resolution guard lives in one of the two, which is what makes "the
547- // guard for THIS row" a scoped lookup rather than a global one.
548- const KF: &str = "decode_key_frame_tile_with_cdfs";
549- const INTER: &str = "decode_inter_frame_tile_with_cdfs";
550- let census: &[(&str, &[(usize, usize)], Mech)] = &[
551- // ---- the residue the merged lane named -------------------
552- //
553- // `decode_rect4_16_intrabc` reconstructs one 16x4 or 4x16 strip.
554- // It has exactly ONE caller (`decode_rect4_16_strip`, decode.rs
555- // 18934), which has exactly two (17595 from `decode_rect4_16`,
556- // 13810 from `decode_intra_rect_in_inter`), which have one each
557- // (36793 key frame, 45447 inter). BOTH are 16x16-level 1:4 arms, so
558- // both sit under a `refuse_invalid_subsize((16, 16), part16)`.
559- //
560- // The offending subsize is the VERT_4 one and ONLY that one:
561- // `partition_subsize_dims((16,16), PARTITION_VERT_4) == (4,16)`,
562- // and (4,16) is in `PLANE_BLOCK_INVALID_422`, while HORZ_4 gives
563- // (16,4) whose (1,0) cell is BLOCK_8X4 and is legal. So the
564- // 16x16-level guard refuses exactly the shape that would be
565- // BLOCK_INVALID, and the strip that survives -- 16x4 -- is the one
566- // this decoder's `own422` arm is written for. Part (d) below
567- // re-derives that split and part (f) pins the caller count, so the
568- // closure is checked rather than asserted in prose.
569- (
570- "decode_rect4_16_intrabc",
571- &[(16, 4), (4, 16)],
572- Mech::AtResolutionVia(KF, 16),
573- ),
574- // ---- 1:4 and 2:1 rect walks, all resolved-symbol guarded --
575- (
576- "decode_rect4_16",
577- &[(16, 4), (4, 16)],
578- Mech::AtResolution(KF, 16),
579- ),
580- (
581- "decode_rect4_16_strip",
582- &[(16, 4), (4, 16)],
583- Mech::AtResolutionVia(KF, 16),
584- ),
585- (
586- "decode_block_rect",
587- &[(32, 16), (16, 32)],
588- Mech::AtResolution(KF, 32),
589- ),
590- (
591- "decode_block_rect4",
592- &[(32, 8), (8, 32)],
593- Mech::AtResolution(KF, 32),
594- ),
595- (
596- "decode_block_rect64",
597- &[(64, 16), (16, 64)],
598- Mech::AtResolution(KF, 64),
599- ),
600- // The 128-root guard lives in `read_sb128_root`, the shared
601- // resolver both tile decoders call -- not in the walker's own
602- // function.
603- (
604- "decode_block_128rect",
605- &[(128, 64), (64, 128)],
606- Mech::AtResolutionVia("read_sb128_root", 128),
607- ),
608- // `decode_rect_split` is called from inside decode_block_rect /
609- // decode_leaf_rect / decode_block_rect4 / decode_block_rect64, none of
610- // which is the tile decoder -- so the guard it inherits is checked on
611- // its own callers' rows, not here.
612- (
613- "decode_rect_split",
614- &[(64, 16), (16, 64), (32, 16), (16, 32)],
615- Mech::AtResolutionVia(KF, 32),
616- ),
617- (
618- "decode_leaf_rect",
619- &[(16, 8), (8, 16)],
620- Mech::AtResolution(KF, 16),
621- ),
622- // ---- the INTER-side rect walks -----------------------------
623- //
624- // r2: without these three rows the inter 32- and 64-level guards
625- // were claimed by NOTHING, and deleting either left the census
626- // green. They are load-bearing -- `decode_intra_rect_in_inter`
627- // dispatches `decode_block_rect4` on 32x8/8x32 (8x32 is
628- // BLOCK_INVALID at 4:2:2) and `decode_block_rect64` on
629- // 64x16/16x64 (16x64 likewise) -- so each gets its own row naming
630- // the guard that stands in front of it.
631- //
632- // These are `AtResolutionVia`, not `AtResolution`: the walk is
633- // dispatched from `decode_intra_rect_in_inter`, a helper, not from
634- // the tile decoder the guard lives in. The check is therefore guard
635- // EXISTENCE in that decoder -- which is what reds when the guard
636- // is deleted -- and the linkage is stated here rather than derived.
637- (
638- "decode_block_rect4[inter]",
639- &[(32, 8), (8, 32)],
640- Mech::AtResolutionVia(INTER, 32),
641- ),
642- (
643- "decode_block_rect64[inter]",
644- &[(64, 16), (16, 64)],
645- Mech::AtResolutionVia(INTER, 64),
646- ),
647- (
648- "decode_intra_rect_in_inter",
649- &[(16, 8), (8, 16), (16, 4), (4, 16)],
650- Mech::AtResolutionVia(INTER, 16),
651- ),
652- // ---- sub-8 walks ------------------------------------------
653- // (8,4) is legal at 4:2:2 (`av1_ss_size_lookup[8x4][1][0]` is
654- // BLOCK_4X4); (4,8) is BLOCK_INVALID there. Both come off a raw
655- // `part8`, and both 8x8 resolution sites carry the guard -- plus
656- // the redundant inline `chroma_plane_block_codable` check the
657- // merged lane left at 36904.
658- (
659- "decode_leaf_rect8",
660- &[(8, 4), (4, 8)],
661- Mech::AtResolution(KF, 8),
662- ),
663- (
664- "decode_inter_sub8_rect2",
665- &[(8, 4), (4, 8)],
666- Mech::AtResolution(INTER, 8),
667- ),
668- (
669- "decode_leaf_split4",
670- &[(4, 4)],
671- Mech::Unreachable("4x4's plane block is 4x4 at EVERY subsampling cell"),
672- ),
673- (
674- "decode_inter_sub8_split4",
675- &[(4, 4)],
676- Mech::Unreachable("4x4's plane block is 4x4 at EVERY subsampling cell"),
677- ),
678- (
679- "decode_leaf8",
680- &[(8, 8)],
681- Mech::Unreachable("8x8's plane block is 8x8 / 4x8 / 4x4, never BLOCK_INVALID"),
682- ),
683- // The square walks take only square footprints, and every square
684- // in `BLOCK_SIZES_ALL` has a valid plane block at EVERY selectable
685- // mode (the whole BLOCK_INVALID column is 4x8 / 8x4 / 4x16 / 8x16
686- // / ... -- all rect). So no guard is needed for them, and the
687- // level guards that exist protect the SYMBOL that would have to
688- // select one of those rect shapes, not the square decode itself.
689- (
690- "decode_block",
691- &[(128, 128), (64, 64), (32, 32), (16, 16), (8, 8)],
692- Mech::Unreachable(
693- "every SQUARE footprint's plane block is valid at every selectable \
694- subsampling mode; the whole BLOCK_INVALID column is rect",
695- ),
696- ),
697- (
698- "decode_inter_block",
699- &[(128, 128), (64, 64), (32, 32), (16, 16), (8, 8)],
700- Mech::Unreachable(
701- "every SQUARE footprint's plane block is valid at every selectable \
702- subsampling mode; the whole BLOCK_INVALID column is rect",
703- ),
704- ),
705- (
706- "decode_inter_block8",
707- &[(8, 8)],
708- Mech::Unreachable("8x8's plane block is 8x8 / 4x8 / 4x4, never BLOCK_INVALID"),
709- ),
710- // ---- THE HOLE THIS LANE FIXED ---------------------------
711- //
712- // `decode_leaf_rect`'s key-frame FRAME-EDGE caller (the one
713- // `decode_leaf_rect`'s row above does not cover, because that arm
714- // dispatches on a gathered `edge_split` instead of resolving into
715- // `part16`). It is 8x16 when the COLUMN is short -- BLOCK_INVALID
716- // at 4:2:2 -- and 16x8 when the ROW is, which is legal and must
717- // keep decoding. Before this lane nothing sat on that path.
718- (
719- "decode_leaf_rect[16-edge]",
720- &[(16, 8), (8, 16)],
721- Mech::AtDispatch,
722- ),
723- ];
724-
725- // (c) Every row's mechanism must be a REAL one. This is what stops
726- // the census from being a list of good intentions: each claim is
727- // re-derived here, and the file is checked for the site it names.
728- for (walk, shapes, mech) in census {
729- let name = walk.split('[').next().expect("walk name");
730- assert!(
731- src.contains(&format!("fn {name}(")),
732- "the census names `{name}`, which is not a function in this file -- the \
733- walk was renamed or removed and this row is stale"
734- );
735- // Only subsampling modes a `color_config` can actually SELECT
736- // count. `(0, 1)` 4:4:0 is excluded on libaom's own authority --
737- // it asserts `subsampling_y == 0` whenever `subsampling_x == 0`
738- // (`color_config`, av1_decoder.c), so no frame in existence is
739- // 4:4:0 and `PLANE_BLOCK_INVALID_440` is transcribed only to keep
740- // the cell table whole. Counting it here would make `16x4` look
741- // like a shape that needs a guard at a mode no stream can carry
742- // -- the same class as the merged lane's r2, which refused a legal
743- // 4:2:2 shape by testing a cell no `color_config` can request.
744- let offending: Vec<(usize, usize, usize, usize)> = shapes
745- .iter()
746- .flat_map(|&(bw, bh)| {
747- [(1, 0), (1, 1), (0, 0)]
748- .into_iter()
749- .filter_map(move |(sx, sy)| {
750- invalid_at(bw, bh, sx, sy).then_some((bw, bh, sx, sy))
751- })
752- })
753- .collect();
754- match mech {
755- // A dispatch-time guard has to reduce to the SAME shape the
756- // dispatch hands the walk -- this is the claim that made the
757- // hole a hole, stated as an assertion.
758- Mech::AtDispatch => {
759- assert!(
760- !offending.is_empty(),
761- "{walk} is listed AtDispatch but libaom codes every shape it \
762- walks at every subsampling mode -- then it needs no guard"
763- );
764- for &(bw, bh, sx, sy) in &offending {
765- assert!(
766- invalid_at(bw, bh, sx, sy),
767- "{walk} is not actually handed {bw}x{bh} at ({sx},{sy})"
768- );
769- }
770- }
771- // r2: the guard THIS row depends on, scoped to the function it
772- // lives in and ordered before the walk's first call there.
773- // Deleting that one guard -- and only that one -- reds this row,
774- // which is what r2's review showed the previous version could
775- // not do.
776- Mech::AtResolution(fscope, level) => {
777- assert!(
778- !offending.is_empty(),
779- "{walk} is listed AtResolution but no shape it walks is BLOCK_INVALID \
780- -- then the level's guard is not what protects it"
781- );
782- let fstart = decode_body
783- .find(&format!("\nfn {fscope}("))
784- .or_else(|| decode_body.find(&format!("\npub(crate) fn {fscope}(")))
785- .or_else(|| decode_body.find(&format!("\npub fn {fscope}(")))
786- .unwrap_or_else(|| {
787- panic!("the census names `{fscope}`, which is not a function here")
788- });
789- let fend = ["\nfn ", "\npub fn ", "\npub(crate) fn "]
790- .iter()
791- .filter_map(|pat| decode_body[fstart + 1..].find(pat).map(|i| fstart + 1 + i))
792- .min()
793- .unwrap_or(decode_body.len());
794- let body = &decode_body[fstart..fend];
795- let guard = format!("refuse_invalid_subsize(({level}, {level})");
796- let gpos = body.find(&guard).unwrap_or_else(|| {
797- panic!(
798- "{walk} claims refuse_invalid_subsize(({level}, {level})) guards it, \
799- but there is NO such guard in `{fscope}` -- the row's mechanism is \
800- prose, not a check; re-derive it or mark the row Prose"
801- )
802- });
803- let call = body.find(&format!("{name}(")).unwrap_or_else(|| {
804- panic!("{walk} has no call site inside `{fscope}` to order the guard against")
805- });
806- assert!(
807- gpos < call,
808- "{walk}: in `{fscope}` the ({level}, {level}) guard is at {gpos} and the \
809- walk is dispatched at {call} -- a guard BELOW the dispatch can never \
810- observe it"
811- );
812- }
813- Mech::AtResolutionVia(fscope, level) => {
814- assert!(
815- !offending.is_empty(),
816- "{walk} is listed AtResolutionVia but no shape it walks is \
817- BLOCK_INVALID"
818- );
819- let fstart = decode_body
820- .find(&format!("\nfn {fscope}("))
821- .or_else(|| decode_body.find(&format!("\npub(crate) fn {fscope}(")))
822- .or_else(|| decode_body.find(&format!("\npub fn {fscope}(")))
823- .unwrap_or_else(|| {
824- panic!("the census names `{fscope}`, which is not a function here")
825- });
826- let fend = ["\nfn ", "\npub fn ", "\npub(crate) fn "]
827- .iter()
828- .filter_map(|pat| decode_body[fstart + 1..].find(pat).map(|i| fstart + 1 + i))
829- .min()
830- .unwrap_or(decode_body.len());
831- assert!(
832- decode_body[fstart..fend]
833- .contains(&format!("refuse_invalid_subsize(({level}, {level})")),
834- "{walk} claims refuse_invalid_subsize(({level}, {level})) in `{fscope}` \
835- guards it, but there is NO such guard there"
836- );
837- }
838- Mech::Unreachable(reason) => {
839- assert!(
840- offending.is_empty(),
841- "{walk} claims it is unreachable, but libaom marks {} \
842- BLOCK_INVALID -- the claim is stale",
843- offending
844- .iter()
845- .map(|(bw, bh, sx, sy)| format!("{bw}x{bh}@({sx},{sy})"))
846- .collect::<Vec<_>>()
847- .join(", ")
848- );
849- assert!(
850- reason.len() > 40,
851- "{walk}'s Unreachable reason is too short to name the symbol \
852- or caller that makes it unreachable"
853- );
854- }
855- }
856- }
857-
858- // (d) The residue's closure, derived rather than asserted in prose:
859- // the ONLY subsize its callers can hand it that libaom refuses at
860- // 4:2:2 is the 16x16-level VERT_4 one, and the level's own guard
861- // refuses exactly that. If either half stops holding -- a new caller
862- // at another level, or a change to `partition_subsize_dims` -- this
863- // reds instead of the comment going stale.
864- for &(part, want) in &[
865- (PARTITION_HORZ_4, (16usize, 4usize)),
866- (PARTITION_VERT_4, (4, 16)),
867- ] {
868- let (bw, bh) = partition_subsize_dims((16, 16), part);
869- assert_eq!(
870- (bw, bh),
871- want,
872- "get_partition_subsize(BLOCK_16X16, {part}) moved"
873- );
874- assert_eq!(
875- chroma_plane_block_codable(bw, bh, 1, 0),
876- part == PARTITION_HORZ_4,
877- "the 16x16 1:4 pair's (1,0) cells moved: HORZ_4 -> {bw}x{bh}, \
878- VERT_4 -> {bw}x{bh}. decode_rect4_16_intrabc's Unreachable row \
879- is written against exactly this split"
880- );
881- }
882- // (e) The AtDispatch row, checked where it actually bites. This is
883- // the hole the merged lane's scan cannot see: its 220-line window is
884- // keyed on `dec.symbol(`, and the frame-edge arm reads
885- // `dec.symbol_fixed(&gather(..))` into `edge_split` and dispatches on
886- // THAT. The claim to check is ordering -- the guard has to sit between
887- // the read and the `decode_leaf_rect` it protects, which is r5's
888- // defect in a new place if it ever moves below.
889- let edge_read = src
890- .find("let edge_split = if has_cols16")
891- .expect("the key-frame 16-level frame-edge arm reads a gathered bit");
892- let guard_at = src[edge_read..]
893- .find("refuse_invalid_subsize((16, 16)")
894- .map(|i| edge_read + i)
895- .expect(
896- "the key-frame 16-level frame-edge arm dispatches decode_leaf_rect on an \
897- 8x16 strip (BLOCK_INVALID at 4:2:2) with NO refuse_invalid_subsize on its \
898- path -- every sibling edge arm resolves into a guarded partN, this one does not",
899- );
900- let walk_at = src[edge_read..]
901- .find("decode_leaf_rect(")
902- .map(|i| edge_read + i)
903- .expect("the frame-edge arm's decode_leaf_rect call");
904- assert!(
905- guard_at < walk_at,
906- "the 16-level frame-edge guard (offset {guard_at}) sits AFTER the \
907- decode_leaf_rect it protects (offset {walk_at}) -- it can never observe it"
908- );
909-
910- // (f) The residue's closure, by CALLER COUNT rather than by prose: a
911- // third caller at another level is what would make the residue row
912- // stale, and a count reds on that where a comment cannot. Counted over
913- // the DECODE BODY only -- this test's own string literals name the same
914- // functions, and the merged lane's own scan hit exactly that (five of
915- // its eighteen `refuse_invalid_subsize((` matches are its own).
916- for (name, calls) in [
917- ("decode_rect4_16_intrabc", 1usize),
918- ("decode_rect4_16_strip", 2),
919- ("decode_rect4_16", 1),
920- ("decode_intra_rect_in_inter", 1),
921- ] {
922- let needle = format!("{name}(");
923- let decl = format!("fn {name}(");
924- // A doc-comment mention (`[`name`](..)`) is prose, not a call, so
925- // comment lines are dropped before counting.
926- let body: String = decode_body
927- .lines()
928- .filter(|l| !l.trim_start().starts_with("//"))
929- .collect::<Vec<_>>()
930- .join("\n");
931- let found = body.matches(&needle).count() - usize::from(body.contains(&decl));
932- assert_eq!(
933- found, calls,
934- "{name} has {found} call site(s) in the decode body, the census expects \
935- {calls}. A new caller is not automatically wrong, but it is not \
936- automatically covered either: re-derive which level's guard it sits \
937- under before this row stays green"
938- );
939- }
940- // Both callers reach the 1:4 strips by a DIFFERENT route, so the
941- // closure is checked per route -- and per route it is the same shape:
942- // the 16x16-level guard must sit ABOVE the test that names VERT_4.
943- //
944- // key frame: `decode_rect4_16(...)` at 36793, inside an arm testing
945- // `part16 == PARTITION_HORZ_4 || part16 == PARTITION_VERT_4`.
946- // inter: the 1:4 strips reach `decode_intra_rect_in_inter`
947- // through `fctx.inter_strip_chroma`, whose ONLY writer is the inter
948- // 16-level 1:4 arm (55068) -- `strip16` is `None` without it.
949- //
950- // Ordering is the property (a guard BELOW the 1:4 test cannot observe
951- // it), which is why each pair is compared rather than merely counted.
952- for (what, test, call) in [
953- (
954- "the key-frame decode_rect4_16 caller",
955- "if part16 == PARTITION_HORZ_4",
956- "decode_rect4_16(",
957- ),
958- (
959- "the inter-frame inter_strip_chroma writer",
960- "let horz = part16 == PARTITION_HORZ_4;",
961- "c.set(Some(InterStripChroma {",
962- ),
963- ] {
964- let fn_scope = |at: usize| -> std::ops::Range<usize> {
965- let head = ["\nfn ", "\npub fn ", "\npub(crate) fn "]
966- .iter()
967- .filter_map(|pat| decode_body[..at].rfind(pat))
968- .max()
969- .unwrap_or(0);
970- let tail = ["\nfn ", "\npub fn ", "\npub(crate) fn "]
971- .iter()
972- .filter_map(|pat| decode_body[at..].find(pat).map(|i| at + i))
973- .min()
974- .unwrap_or(decode_body.len());
975- head..tail
976- };
977- // The first occurrence of the test text can sit in another function (the files are
978- // concatenated in path order), so take the first occurrence whose own function holds
979- // the dispatch. The guard, the test and the dispatch must then share that function.
980- let (test_at, _, call_at) = decode_body
981- .match_indices(test)
982- .find_map(|(t, _)| {
983- let sc = fn_scope(t);
984- decode_body[sc.clone()]
985- .rfind(call)
986- .map(|i| (t, sc.clone(), sc.start + i))
987- })
988- .unwrap_or_else(|| panic!("the 1:4 arm test {test:?} for {what} is gone, or no function holds its dispatch {call:?}"));
989- // The dispatch is searched inside the 1:4 test's own function: the files are
990- // concatenated in path order, so the last occurrence in the whole text is no longer
991- // the key-frame call. The guard, test and dispatch must share that function.
992- // `decode_rect4_16(` also matches the DEFINITION, which is the
993- // first occurrence -- the call is the last one.
994- // r2 (Main's review, and it was right): the guard search is SCOPED
995- // to the anchor's own enclosing function. `find()` over the whole
996- // decode body returns the FIRST `refuse_invalid_subsize((16, 16)` --
997- // the KEY-FRAME one -- so the inter pair's comparison was satisfied
998- // by a guard three quarters of the file away, and deleting the inter
999- // 16-level guard left this test green. Both routes live in
1000- // different `fn` bodies (`decode_key_frame_tile_with_cdfs` and the
1001- // inter tile decoder), so the enclosing function is the scope that
1002- // tells the two apart.
1003- let scope = fn_scope(test_at);
1004- let guard_at = decode_body[scope.clone()]
1005- .find("refuse_invalid_subsize((16, 16)")
1006- .map(|i| scope.start + i)
1007- .unwrap_or_else(|| {
1008- panic!(
1009- "{what}: there is NO refuse_invalid_subsize((16, 16)) in the function \
1010- enclosing the 1:4 arm test -- so nothing refuses the VERT_4 symbol \
1011- this arm dispatches on, and decode_rect4_16_intrabc's closure is gone"
1012- )
1013- });
1014- assert!(
1015- guard_at < test_at && test_at < call_at,
1016- "{what}: guard at {guard_at} (function scope {scope:?}), 1:4 arm test at \
1017- {test_at}, dispatch at {call_at}. The guard has to sit ABOVE the 1:4 arm \
1018- test INSIDE THE SAME FUNCTION, or the VERT_4 symbol it refuses has already \
1019- been dispatched on"
1020- );
1021- assert!(
1022- scope.contains(&guard_at) && scope.contains(&test_at) && scope.contains(&call_at),
1023- "{what}: guard, 1:4 test and dispatch must share one enclosing function"
1024- );
1025- }
1026- // And the inter route really is the only one: `strip16` is built from
1027- // `strip_chroma`, which is `inter_strip_chroma.take()`, so a missing
1028- // writer would silently drop the arm rather than expose it.
1029- assert_eq!(
1030- decode_body.matches("inter_strip_chroma.with(|c| {").count(),
1031- 1,
1032- "inter_strip_chroma gained a second writer -- the inter 1:4 strips can now \
1033- come from a level whose guard this census has not checked"
1034- );
1035-
1036- // (g) PER-SITE rows. Everything above claims a guard by LEVEL --
1037- // "there is a `refuse_invalid_subsize((8, 8))` somewhere in the
1038- // key-frame tile decoder" -- and that is exactly what makes two
1039- // guards deletable: the key-frame 8x8 level has TWO resolution
1040- // sites (37322 and 37621) and the walk census's `decode_leaf_rect8`
1041- // row is satisfied by the first one, so deleting the SECOND left the
1042- // test green; the inter decoder carries its OWN 128-root guard
1043- // (54495) while the `decode_block_128rect` row names
1044- // `read_sb128_root`, so deleting the inter copy also left it green.
1045- // The merged scan's count cross-check is what reds them, and a
1046- // count is not a location.
1047- //
1048- // So each row below names an ANCHOR that is unique in the decode
1049- // body -- the code the site hangs off -- and requires the level's
1050- // guard to sit between that anchor and the dispatch the site
1051- // feeds, within the same function. A level guard elsewhere in that
1052- // function cannot stand in, because the search starts AT the
1053- // anchor. Deleting the named guard finds no guard after the anchor
1054- // and reds; moving it below the dispatch reds the ordering assert.
1055- //
1056- // Row shape: (site label, guard's function, level, unique anchor,
1057- // dispatch token the guard must precede, shapes the site walks).
1058- let body_of = |name: &str| -> &str {
1059- let start = decode_body
1060- .find(&format!("\nfn {name}("))
1061- .or_else(|| decode_body.find(&format!("\npub(crate) fn {name}(")))
1062- .or_else(|| decode_body.find(&format!("\npub fn {name}(")))
1063- .unwrap_or_else(|| panic!("{name} is not a function in this file"));
1064- let end = ["\nfn ", "\npub fn ", "\npub(crate) fn "]
1065- .iter()
1066- .filter_map(|pat| decode_body[start + 1..].find(pat).map(|i| start + 1 + i))
1067- .min()
1068- .unwrap_or(decode_body.len());
1069- &decode_body[start..end]
1070- };
1071- let site_rows: &[(&str, &str, usize, &str, &str, &[(usize, usize)])] = &[
1072- // The key-frame 8x8 level resolves TWICE (37322 for the frame
1073- // interior, 37621 for the `pre8` probe path). Both feed
1074- // `decode_leaf_rect8` on a raw `part8`, whose VERT shape is 4x8 --
1075- // BLOCK_INVALID at 4:2:2. The anchor `let pre8 = ...` is what
1076- // makes this row about the SECOND site: with `find()` scoped to
1077- // the function alone the search would return 37322 and never
1078- // look here.
1079- (
1080- "the key-frame 8x8 SECOND resolution",
1081- KF,
1082- 8,
1083- "let pre8 = dec.debug_state().0;",
1084- "decode_leaf_rect8(",
1085- &[(8, 4), (4, 8)],
1086- ),
1087- // The inter decoder resolves its own 128 root at 54495 rather
1088- // than routing through `read_sb128_root` (which is where the
1089- // `decode_block_128rect` row's guard lives). The dispatch token
1090- // is the `half128_inter!` arm that descends into a 128x64 /
1091- // 64x128 rect -- both BLOCK_INVALID at 4:2:2 in
1092- // `PLANE_BLOCK_INVALID_422`. `macro_rules! half128_inter` is
1093- // unique in the file, so this row cannot drift onto the other
1094- // one.
1095- (
1096- "the inter decoder's own 128-root guard",
1097- INTER,
1098- 128,
1099- "macro_rules! half128_inter",
1100- "half128_inter!((br_mi, base_mi.1), 128, 64,",
1101- &[(128, 64), (64, 128)],
1102- ),
1103- ];
1104- for (label, fscope, level, anchor, dispatch, shapes) in site_rows {
1105- assert_eq!(
1106- decode_body.matches(anchor).count(),
1107- 1,
1108- "{label}: the site anchor {anchor:?} is not unique in the decode body, so it \
1109- cannot name one site -- re-derive the anchor for this row"
1110- );
1111- // Why the site needs a guard at all: something it dispatches is
1112- // BLOCK_INVALID at a mode a `color_config` can select. (0, 1) is
1113- // excluded for the same reason as the walk census above.
1114- let offending: Vec<(usize, usize, usize, usize)> = shapes
1115- .iter()
1116- .flat_map(|&(bw, bh)| {
1117- [(1, 0), (1, 1), (0, 0)]
1118- .into_iter()
1119- .filter_map(move |(sx, sy)| {
1120- invalid_at(bw, bh, sx, sy).then_some((bw, bh, sx, sy))
1121- })
1122- })
1123- .collect();
1124- assert!(
1125- !offending.is_empty(),
1126- "{label} claims a guard but libaom codes every shape it walks at every \
1127- selectable subsampling mode -- then it needs none"
1128- );
1129- let body = body_of(fscope);
1130- let a = body.find(anchor).unwrap_or_else(|| {
1131- panic!(
1132- "{label}: the anchor {anchor:?} is not inside `{fscope}` -- the guard \
1133- moved to another function, and the row's scope is stale"
1134- )
1135- });
1136- let gpat = format!("refuse_invalid_subsize(({level}, {level})");
1137- let g = body[a..].find(&gpat).map(|i| a + i).unwrap_or_else(|| {
1138- panic!(
1139- "{label}: `{fscope}` has NO {gpat} at or after the site anchor {anchor:?} \
1140- -- this site's guard is gone. The level claim elsewhere in this test is \
1141- still satisfied by the OTHER {level}x{level} guard in the file, which is \
1142- precisely why this row exists"
1143- )
1144- });
1145- let gap = body[a..g].lines().count();
1146- assert!(
1147- gap <= 40,
1148- "{label}: the {gpat} sits {gap} lines below its own anchor {anchor:?} -- that is \
1149- a different site, so this row has stopped naming what it claims to name"
1150- );
1151- let d = body[g..].find(dispatch).map(|i| g + i).unwrap_or_else(|| {
1152- panic!(
1153- "{label}: `{fscope}` dispatches {dispatch:?} nowhere AFTER its {gpat} -- \
1154- either the dispatch moved above the guard or the site was rewritten"
1155- )
1156- });
1157- assert!(
1158- g < d,
1159- "{label}: guard at {g} sits at or after the dispatch at {d} -- a guard BELOW \
1160- the dispatch can never observe it"
1161- );
1162- }
1163-}
1164-
1165-/// lane/av1422rect4dead: the `(pw / 2, ph / 2)` / `MI / 2` origin `else`
1166-/// arm of [`decode_rect4_16_intrabc`] is the 4:2:0 PAIR geometry. It is
1167-/// still LIVE at ss (1, 1) -- a 1:4 strip's chroma lies inside its
1168-/// 4:2:0 pair there -- so the arm is not deleted; it is CLOSED at ss
1169-/// (1, 0), where it would run on a 4x16 VERT_4 strip whose chroma plane
1170-/// block is BLOCK_INVALID, and where libaom's own
1171-/// `is_chroma_reference` (av1_common_int.h:1454, `|| !subsampling_y`)
1172-/// makes every strip its own chroma reference anyway (the `own422` arm
1173-/// handles that). The proof: the sole caller `decode_rect4_16_strip` is
1174-/// reached only via the two 16x16-level 1:4 arms, each under
1175-/// `refuse_invalid_subsize((16, 16), part16)` -- at ss (1, 0) that guard
1176-/// refuses `partition_subsize_dims((16, 16), PARTITION_VERT_4) == (4, 16)`
1177-/// (in `PLANE_BLOCK_INVALID_422`), and the surviving HORZ_4 16x4 strip
1178-/// takes `own422`. This test re-derives that chain from the file so it
1179-/// REDS when any half stops holding: deleting the in-arm assertion, a
1180-/// caller moving under a level whose guard does not refuse (4, 16) at
1181-/// ss (1, 0), or the `(pw / 2, ph / 2)` form drifting. 4:2:0 and 4:4:4
1182-/// behaviour are unchanged: the gate runs only the file scan and the
1183-/// closed cell's arithmetic, no decode.
1184-#[test]
1185-fn decode_rect4_16_intrabc_else_arm_stays_closed_at_422() {
1186- let production = crate::test_source::module_production_source("decode");
1187- let decode_body = match production.find("\n#[cfg(test)]\nmod tests {") {
1188- Some(i) => &production[..i],
1189- None => production,
1190- };
1191-
1192- // (a) The closure assertion must exist INSIDE the function, in the
1193- // `else` arm of the `(cw, ch)` select, naming the shape and the
1194- // subsampling. Deleting it -- or re-adding the bare halving without
1195- // it -- reds here.
1196- let fstart = decode_body
1197- .find("\nfn decode_rect4_16_intrabc(")
1198- .expect("decode_rect4_16_intrabc is gone -- this gate guards its else arm");
1199- let fend = ["\nfn ", "\npub fn ", "\npub(crate) fn "]
1200- .iter()
1201- .filter_map(|pat| decode_body[fstart + 1..].find(pat).map(|i| fstart + 1 + i))
1202- .min()
1203- .unwrap_or(decode_body.len());
1204- let body = &decode_body[fstart..fend];
1205- let else_arm = body
1206- .find(" let (cw, ch) = if own_chroma {")
1207- .expect("the (cw, ch) select moved out of decode_rect4_16_intrabc");
1208- let closure = &body[else_arm..];
1209- assert!(
1210- closure.contains("assert!(") && closure.contains("ss_x(fctx) == 1 && ss_y(fctx) == 0"),
1211- "the decode_rect4_16_intrabc else arm's ss (1, 0) closure assertion is \
1212- GONE -- the 4:2:0 pair geometry is unreachable at ss (1, 0) only while \
1213- that assert (and the guards below) stand; re-add it"
1214- );
1215-
1216- // (b) The sole-caller chain, re-derived from the file: exactly one
1217- // call to `decode_rect4_16_intrabc(` outside its own definition, in
1218- // `decode_rect4_16_strip`; exactly two calls to
1219- // `decode_rect4_16_strip(` from the two 1:4 routes.
1220- let code_lines: String = decode_body
1221- .lines()
1222- .filter(|l| !l.trim_start().starts_with("//"))
1223- .collect::<Vec<_>>()
1224- .join("\n");
1225- let count_calls = |name: &str| -> usize {
1226- code_lines.matches(&format!("{name}(")).count()
1227- - usize::from(code_lines.contains(&format!("fn {name}(")))
1228- };
1229- assert_eq!(
1230- count_calls("decode_rect4_16_intrabc"),
1231- 1,
1232- "decode_rect4_16_intrabc gained a caller -- re-derive whether the new route \
1233- sits under a guard that refuses (4, 16) at ss (1, 0) before this gate \
1234- stays green"
1235- );
1236- assert_eq!(
1237- count_calls("decode_rect4_16_strip"),
1238- 2,
1239- "decode_rect4_16_strip's caller set moved -- both routes must be \
1240- 16x16-level 1:4 arms under a (16, 16) guard that refuses (4, 16) at \
1241- ss (1, 0)"
1242- );
1243-
1244- // (c) Both routes sit under a `refuse_invalid_subsize((16, 16), ...)`:
1245- // the key-frame arm's guard ordered above the arm test, the inter
1246- // arm's guard in the inter decoder above its own 1:4 test. Scoped to
1247- // the enclosing function so the other decoder's guard cannot stand in
1248- // (the r2 class this file already fixed once).
1249- let fn_scope = |at: usize| -> std::ops::Range<usize> {
1250- let head = ["\nfn ", "\npub fn ", "\npub(crate) fn "]
1251- .iter()
1252- .filter_map(|pat| decode_body[..at].rfind(pat))
1253- .max()
1254- .unwrap_or(0);
1255- let tail = ["\nfn ", "\npub fn ", "\npub(crate) fn "]
1256- .iter()
1257- .filter_map(|pat| decode_body[at..].find(pat).map(|i| at + i))
1258- .min()
1259- .unwrap_or(decode_body.len());
1260- head..tail
1261- };
1262- let kf_test = decode_body
1263- .find("if part16 == PARTITION_HORZ_4")
1264- .expect("the key-frame 16-level 1:4 arm test is gone");
1265- let kf_scope = fn_scope(kf_test);
1266- let kf_guard = decode_body[kf_scope.clone()]
1267- .find("refuse_invalid_subsize((16, 16)")
1268- .map(|i| kf_scope.start + i)
1269- .unwrap_or_else(|| {
1270- panic!(
1271- "the key-frame 16-level 1:4 arm has NO \
1272- refuse_invalid_subsize((16, 16)) above it in its own \
1273- function -- the VERT_4 (4, 16) refusal that closed \
1274- decode_rect4_16_intrabc's else arm at ss (1, 0) is gone"
1275- )
1276- });
1277- assert!(
1278- kf_guard < kf_test,
1279- "the key-frame (16, 16) guard sits below the 1:4 arm test -- it can never \
1280- observe the VERT_4 symbol that must be refused before \
1281- decode_rect4_16_intrabc's else arm can run at ss (1, 0)"
1282- );
1283- let inter_writer = decode_body
1284- .find("let horz = part16 == PARTITION_HORZ_4;")
1285- .expect("the inter 16-level 1:4 arm is gone");
1286- let inter_scope = fn_scope(inter_writer);
1287- let inter_guard = decode_body[inter_scope.clone()]
1288- .find("refuse_invalid_subsize((16, 16)")
1289- .map(|i| inter_scope.start + i)
1290- .unwrap_or_else(|| {
1291- panic!(
1292- "the inter-frame 16-level 1:4 arm has NO \
1293- refuse_invalid_subsize((16, 16)) in its function -- the VERT_4 \
1294- (4, 16) refusal that closed decode_rect4_16_intrabc's else arm \
1295- at ss (1, 0) is gone"
1296- )
1297- });
1298- assert!(
1299- inter_guard < inter_writer,
1300- "the inter (16, 16) guard sits below the 1:4 arm test -- it can never \
1301- observe the VERT_4 symbol that must be refused before \
1302- decode_rect4_16_intrabc's else arm can run at ss (1, 0)"
1303- );
1304-
1305- // (d) The shape/subsampling cells the closure is written against,
1306- // re-executed: (4, 16) must still be BLOCK_INVALID at ss (1, 0) while
1307- // (16, 4) stays codable there, and at ss (1, 1) BOTH are codable --
1308- // which is what keeps the arm live at 4:2:0 and the assertion inert
1309- // there. At ss (0, 0) everything is codable, so `own444` (and the
1310- // assertion) never see the else arm.
1311- assert!(
1312- !chroma_plane_block_codable(4, 16, 1, 0),
1313- "(4, 16) left PLANE_BLOCK_INVALID_422 -- the else arm is now REACHABLE at \
1314- ss (1, 0) with the halved pair geometry, which is a real defect, not a \
1315- closure: re-derive the whole chain, then fix the halving instead of the \
1316- assert"
1317- );
1318- assert!(
1319- chroma_plane_block_codable(16, 4, 1, 0),
1320- "(16, 4) became BLOCK_INVALID at ss (1, 0) -- the surviving HORZ_4 strip \
1321- takes own422, and the closure assert would fire on a legal shape; \
1322- re-derive"
1323- );
1324- assert!(
1325- chroma_plane_block_codable(4, 16, 1, 1) && chroma_plane_block_codable(16, 4, 1, 1),
1326- "a 1:4 strip's plane block moved at ss (1, 1) -- the else arm is LIVE there \
1327- and the pair geometry is what decodes it; the assertion must stay inert at \
1328- 4:2:0"
1329- );
1330- assert!(
1331- chroma_plane_block_codable(4, 16, 0, 0) && chroma_plane_block_codable(16, 4, 0, 0),
1332- "a 1:4 strip's plane block became invalid at ss (0, 0) -- the assertion sits \
1333- after the own444 arm and must never fire at 4:4:4; re-derive"
1334- );
1335-}
1336-
1337131 /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's
1338132 /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and
1339133 /// reports "no leaf there" as `None` so the caller can fall back to the
@@ -1749,13 +543,42 @@ fn cdef_filter_block_under_test(
1749543 ) {
1750544 if let Some(t) = archmage::X64V3Token::summon() {
1751545 return super::cdef_simd::filter_block_avx2(
1752- t, src, dst, stride, ox, oy, bw, bh, pri_strength, sec_strength, dir,
1753- pri_damping, sec_damping, enable_primary, enable_secondary, coeff_shift, smax,
546+ t,
547+ src,
548+ dst,
549+ stride,
550+ ox,
551+ oy,
552+ bw,
553+ bh,
554+ pri_strength,
555+ sec_strength,
556+ dir,
557+ pri_damping,
558+ sec_damping,
559+ enable_primary,
560+ enable_secondary,
561+ coeff_shift,
562+ smax,
1754563 );
1755564 }
1756565 super::cdef_filter_block_scalar(
1757- src, dst, stride, ox, oy, bw, bh, pri_strength, sec_strength, dir,
1758- pri_damping, sec_damping, enable_primary, enable_secondary, coeff_shift, smax,
566+ src,
567+ dst,
568+ stride,
569+ ox,
570+ oy,
571+ bw,
572+ bh,
573+ pri_strength,
574+ sec_strength,
575+ dir,
576+ pri_damping,
577+ sec_damping,
578+ enable_primary,
579+ enable_secondary,
580+ coeff_shift,
581+ smax,
1759582 )
1760583 }
1761584
@@ -2096,8 +919,8 @@ fn filter_intra_classes_carry_their_own_libaom_default_row() {
2096919 );
2097920 }
2098921 }
2099-use archmage::SimdToken;
2100922 use super::*;
923+use archmage::SimdToken;
2101924
2102925 /// lane-tx64x16 r3: the two new 4:1 chroma scans are a TRANSPOSED PAIR --
2103926 /// `SCAN_4X16[i]` must name the transpose of the position
@@ -2415,84 +1238,6 @@ fn an_obmc_neighbour_with_no_recorded_filter_refuses_instead_of_panicking() {
24151238 );
24161239 }
24171240
2418-/// lane-t900 r27, structural audit for "an OBMC neighbour whose switchable
2419-/// interp filter was never recorded": the `[3, 3]` sentinel is only ever
2420-/// PUBLISHED for a cell an OBMC blend cannot pick up.
2421-///
2422-/// `Neighbours::record_inter_rect_mi` is the single writer of
2423-/// `above_filter`/`left_filter` (every other recorder routes through it),
2424-/// so the whole domain of published values is its call sites' 7th
2425-/// argument. Two publications are safe: an INTRA cell (`is_inter = false`,
2426-/// skipped by `overlappable_above`/`overlappable_left`'s own `is_inter`
2427-/// gate) and a fixed-filter frame (`resolve_interp_filter` returns the
2428-/// sentinel when `interp_fixed` is `Some`, which `neighbour_filter`
2429-/// answers before ever looking at the symbols). What this scans for is the
2430-/// third case -- an INTER cell stamped with a literal sentinel, which is
2431-/// what the refusal actually fires on. Arguments are tokenised
2432-/// positionally, never `contains()`d.
2433-#[test]
2434-fn every_inter_record_publishes_an_obmc_readable_filter() {
2435- let src = crate::test_source::module_source("decode");
2436- let mut calls = 0usize;
2437- for (start, _) in src.match_indices("record_inter_rect_mi(") {
2438- // Skip the definition and the wrapper's own forwarding call.
2439- let line_start = src[..start].rfind('\n').map_or(0, |i| i + 1);
2440- let head = &src[line_start..start];
2441- // The definition, the wrapper's own forwarding call, and this
2442- // test's own mentions of the name (doc comment, scan pattern,
2443- // assert message) are not publication sites.
2444- if head.contains("fn ") || head.contains("///") || head.ends_with('"') {
2445- continue;
2446- }
2447- let mut i = start + "record_inter_rect_mi(".len();
2448- let (mut depth, mut arg, mut args) = (0i32, String::new(), Vec::new());
2449- let bytes = src.as_bytes();
2450- while i < bytes.len() {
2451- let c = bytes[i] as char;
2452- match c {
2453- '(' | '[' => depth += 1,
2454- ')' | ']' if depth == 0 && c == ')' => break,
2455- ')' | ']' => depth -= 1,
2456- ',' if depth == 0 => {
2457- args.push(std::mem::take(&mut arg));
2458- i += 1;
2459- continue;
2460- }
2461- _ => {}
2462- }
2463- arg.push(c);
2464- i += 1;
2465- }
2466- if !arg.trim().is_empty() {
2467- args.push(arg);
2468- }
2469- assert_eq!(
2470- args.len(),
2471- 8,
2472- "record_inter_rect_mi gained an argument -- re-index this audit: {args:?}"
2473- );
2474- calls += 1;
2475- let (is_inter, filter) = (args[4].trim(), args[6].trim());
2476- if filter.starts_with('[') {
2477- assert_eq!(
2478- filter.replace(' ', ""),
2479- "[3,3]",
2480- "a literal filter other than the sentinel is published at call {calls}"
2481- );
2482- assert_eq!(
2483- is_inter, "false",
2484- "an INTER cell is stamped with the [3, 3] sentinel (call {calls}): an OBMC \
2485- blend picking it up refuses by name. Publish the block's own resolved \
2486- switchable symbols instead."
2487- );
2488- }
2489- }
2490- assert!(
2491- calls >= 6,
2492- "the audit found only {calls} publication sites -- it is broken, not the decoder"
2493- );
2494-}
2495-
24961241 /// lane-t900 r27, negative gate for "a reference frame selected with no
24971242 /// picture at this frame's own ref_frame_idx slot for it": every
24981243 /// non-`LAST_FRAME` reference resolves through `ref_planes`, and an empty
@@ -2797,7 +1542,6 @@ fn a_skipped_block_decodes_to_pure_prediction() {
27971542 DC_PRED,
27981543 &mut cdfs.kf_y_mode[INTRA_MODE_CTX[DC_PRED]][INTRA_MODE_CTX[DC_PRED]],
27991544 );
2800- crate::msac::SymbolDecoder::set_symr_cdf("uv_mode");
28011545 enc.symbol(DC_PRED, &mut cdfs.uv_mode_no_cfl[DC_PRED]);
28021546 let data = enc.finish();
28031547 let decoded = decode_key_frame_tile(
@@ -2842,7 +1586,6 @@ fn a_skipped_block_decodes_to_pure_prediction() {
28421586 #[test]
28431587 fn a_skipped_intrabc_chroma_reference_leaf_disarms_the_inherited_chroma_tx() {
28441588 let fctx = &crate::decode::FrameCtx::new();
2845- reset_skipped_intrabc_chroma_arm_hits();
28461589 use crate::msac::SymbolEncoder;
28471590 let mut cdfs = Cdfs::new(q_ctx_of(40));
28481591 let mut enc = SymbolEncoder::new();
@@ -2883,10 +1626,6 @@ fn a_skipped_intrabc_chroma_reference_leaf_disarms_the_inherited_chroma_tx() {
28831626 true,
28841627 fctx,
28851628 );
2886- assert!(
2887- skipped_intrabc_chroma_arm_hits() >= 1,
2888- "the hand-written tile never reached the skipped-intrabc chroma-reference route"
2889- );
28901629 assert!(
28911630 fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_none(),
28921631 "the inherited chroma transform slot must be disarmed when its block's chroma \
@@ -2901,7 +1640,6 @@ fn a_skipped_intrabc_chroma_reference_leaf_disarms_the_inherited_chroma_tx() {
29011640 #[test]
29021641 fn a_skipped_intrabc_rect_chroma_reference_leaf_disarms_the_inherited_chroma_tx() {
29031642 let fctx = &crate::decode::FrameCtx::new();
2904- reset_skipped_intrabc_chroma_arm_hits();
29051643 use crate::msac::SymbolEncoder;
29061644 let mut cdfs = Cdfs::new(q_ctx_of(40));
29071645 let mut enc = SymbolEncoder::new();
@@ -2934,10 +1672,6 @@ fn a_skipped_intrabc_rect_chroma_reference_leaf_disarms_the_inherited_chroma_tx(
29341672 true,
29351673 fctx,
29361674 );
2937- assert!(
2938- skipped_intrabc_chroma_arm_hits() >= 1,
2939- "the hand-written tile never reached the skipped-intrabc rect chroma-reference route"
2940- );
29411675 assert!(
29421676 fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_none(),
29431677 "the inherited chroma transform slot must be disarmed when its block's chroma \
@@ -3012,7 +1746,6 @@ fn a_non_split_inter_sb_partition_refuses_by_name_instead_of_desyncing() {
30121746 // helpers are `#[cfg(test)]`-private to it).
30131747 use crate::probe::run_with_stdin;
30141748
3015-
30161749 /// Decodes one AV1 OBU stream with ffmpeg and hands back its one 4:2:0
30171750 /// frame's planes, at ffmpeg's own (coded, block-padded) size.
30181751 fn ffmpeg_decode(stream: &[u8], width: usize, height: usize) -> Picture {
@@ -3124,7 +1857,8 @@ fn ffprobe_size(stream: &[u8]) -> (u32, u32) {
31241857 "-of",
31251858 "csv=p=0",
31261859 ])
3127- .arg(&path).output()
1860+ .arg(&path)
1861+ .output()
31281862 .expect("ffprobe failed to run");
31291863 let _ = std::fs::remove_file(&path);
31301864 assert!(
@@ -3216,7 +1950,6 @@ fn a_filter_intra_key_frame_decodes_pixel_exact_through_ffmpeg() {
32161950 }
32171951 let encoded = crate::encode::encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
32181952 let (coded_w, coded_h) = ffprobe_size(&encoded.stream);
3219- let before = filter_intra_hits();
32201953 let ours = decode_key_frame_tile_lr(
32211954 &encoded.tile,
32221955 encoded.mi_cols,
@@ -3235,12 +1968,6 @@ fn a_filter_intra_key_frame_decodes_pixel_exact_through_ffmpeg() {
32351968 fctx,
32361969 )
32371970 .unwrap();
3238- let fired = filter_intra_hits() - before;
3239- assert!(
3240- fired > 0,
3241- "no block took filter intra -- the gate is blind to the feature"
3242- );
3243- eprintln!("a_filter_intra_key_frame: {fired} filter-intra blocks");
32441971 let ffmpeg_decoded = ffmpeg_decode(&encoded.stream, coded_w as usize, coded_h as usize);
32451972 assert_eq!(ours.y, ffmpeg_decoded.y, "luma vs ffmpeg");
32461973 assert_eq!(ours.u, ffmpeg_decoded.u, "U vs ffmpeg");
crates/ec-av1/src/decode/tx4x8_table_tests.rsdeleted+0 -89
@@ -1,89 +0,0 @@
1-use super::*;
2-
3-/// Asymmetric gate on the two new scan tables (class
4-/// `reference-layout-not-spec`): a transposed pair of tables passes any
5-/// "is a permutation" check, so this pins the pair AGAINST each other --
6-/// `SCAN_8X4[k]` must be `SCAN_4X8[k]` reflected across the diagonal, and
7-/// both must be bijections of `0..32` in our own row-major indexing.
8-#[test]
9-fn the_rect_4x8_scans_are_each_other_transposed() {
10- let mut seen_a = [false; 32];
11- let mut seen_b = [false; 32];
12- for k in 0..32usize {
13- let a = SCAN_4X8[k] as usize;
14- let b = SCAN_8X4[k] as usize;
15- assert!(!seen_a[a] && !seen_b[b], "scan position {k} repeats");
16- seen_a[a] = true;
17- seen_b[b] = true;
18- let (row, col) = (a / 4, a % 4);
19- assert_eq!(
20- b,
21- col * 8 + row,
22- "SCAN_8X4[{k}] is not SCAN_4X8[{k}] transposed"
23- );
24- }
25- assert!(seen_a.iter().all(|&s| s) && seen_b.iter().all(|&s| s));
26-}
27-
28-/// `mrow_scan_4x8`/`mcol_scan_4x8`/`mrow_scan_8x4`/`mcol_scan_8x4`
29-/// (libaom `scan.c`), converted out of their column-major encoding by
30-/// `(p % h) * w + p / h` -- the head of each, pinned so the rect
31-/// `V_DCT`/`H_DCT` walk cannot silently transpose.
32-#[test]
33-fn the_rect_class1_scans_match_libaom() {
34- assert_eq!(
35- class_scan_table_wh(4, 8, TxClass::Vert),
36- (0..32u16).collect::<Vec<_>>()
37- );
38- assert_eq!(
39- &class_scan_table_wh(4, 8, TxClass::Horiz)[..8],
40- &[0u16, 4, 8, 12, 16, 20, 24, 28]
41- );
42- assert_eq!(
43- class_scan_table_wh(8, 4, TxClass::Vert),
44- (0..32u16).collect::<Vec<_>>()
45- );
46- assert_eq!(
47- &class_scan_table_wh(8, 4, TxClass::Horiz)[..8],
48- &[0u16, 8, 16, 24, 1, 9, 17, 25]
49- );
50-}
51-
52-/// The 32-position `eob_pt` alphabet: six symbols (one more than the
53-/// 16-position table, one fewer than the 64-position one), strictly
54-/// increasing, terminated at 32768 with the adaptation counter after it.
55-#[test]
56-fn the_32_position_eob_tables_are_well_formed() {
57- for table in [
58- &cdf::EOB_PT_32_LUMA_Q0,
59- &cdf::EOB_PT_32_LUMA_Q1,
60- &cdf::EOB_PT_32_LUMA,
61- &cdf::EOB_PT_32_LUMA_Q3,
62- &cdf::EOB_PT_32_LUMA_CLASS1_Q0,
63- &cdf::EOB_PT_32_LUMA_CLASS1_Q1,
64- &cdf::EOB_PT_32_LUMA_CLASS1,
65- &cdf::EOB_PT_32_LUMA_CLASS1_Q3,
66- ] {
67- assert_eq!(table.len(), 7);
68- assert_eq!(table[5], 32768);
69- assert_eq!(table[6], 0);
70- for w in table[..6].windows(2) {
71- assert!(w[0] < w[1], "{table:?} is not increasing");
72- }
73- }
74-}
75-
76-/// `Reach::of_rect` must read libaom's own `has_tr_4x8`/`has_tr_8x4`
77-/// rows, not the 32x16 pair the two existing rect strips use: the two
78-/// shapes disagree at a position inside the superblock, which is what
79-/// makes this an asymmetric check rather than a tautology.
80-#[test]
81-fn the_sub8_rect_reach_tables_are_shape_specific() {
82- let fctx = &crate::decode::FrameCtx::new();
83- let a = Reach::of_rect(4, 8, 4, 8, 64, 64, fctx);
84- let b = Reach::of_rect(8, 4, 8, 4, 64, 64, fctx);
85- assert!(
86- a.above_right != b.above_right || a.below_left != b.below_left,
87- "4x8 and 8x4 reach identically at mirrored positions -- one table is unused"
88- );
89-}
crates/ec-av1/src/dumpio.rsdeleted+0 -568
@@ -1,568 +0,0 @@
1-//! Loud dump writing: a dump that cannot hold every byte it claims to hold is
2-//! a failure, not a diagnostic artefact.
3-//!
4-//! lane-av1dumploud: every dump site in this crate wrote through
5-//! `let _ = f.write_all(..)`. A full filesystem, an `RLIMIT_FSIZE`, or any other
6-//! `ENOSPC`/`EFBIG` therefore left a SHORT file on disk and nothing said so.
7-//! Measured consequence, twice in one day: a sentinel-vs-plain hash difference
8-//! that read as decoder nondeterminism reproduced bit-for-bit as a truncated
9-//! dump (`lanes/unwritten-dep.report.md`: frames 0..4 complete plus 13 320 192
10-//! bytes of frame 5, with `EC_AV1_FINAL_DUMP`'s discarded write error), and an
11-//! empty dump read as instability. That artefact started a whole defect class,
12-//! and a silently wrong diagnostic is worse than a loud one, so every dump site
13-//! goes through [`LoudDump`]: the caller states the expected byte count from the
14-//! geometry it already has, the writer checks that count twice -- once against
15-//! the bytes it was handed, once against the file's own length on disk -- and
16-//! any shortfall aborts the decode with the file, the counts, and the OS error.
17-//!
18-//! The success path is byte-identical to the old `write_all` loop: same bytes,
19-//! same order, same file names.
20-//!
21-//! The failure path is a panic, not a returned `Result`: the dump sites sit in
22-//! the middle of `fn decode_*` functions with no error channel for them, and a
23-//! dump that failed IS a decode failure (the run's measurement is void). This
24-//! is a debug instrument -- it only runs when its env var is set -- so the
25-//! panic cannot affect a normal decode.
26-
27-use std::fs::{File, OpenOptions};
28-use std::io::Write;
29-use std::path::{Path, PathBuf};
30-
31-/// One dump file, with the byte count it owes accounted for as it goes.
32-pub struct LoudDump {
33- /// Human-readable label for the failure line: the env var, or
34- /// `VAR.suffix` when the file names something the var alone does not.
35- site: String,
36- path: PathBuf,
37- file: Option<File>,
38- written: usize,
39- /// `None` only for a stream whose total length is genuinely unknowable at
40- /// open time (an append-mode text table). Short-write detection still
41- /// applies -- `write_all` reports a short write as `Err` -- but the failure
42- /// line then carries no expected count, because inventing one would be a
43- /// guess.
44- expected: Option<usize>,
45-}
46-
47-impl LoudDump {
48- /// Open `path` for `site`, expecting exactly `expected` bytes in total.
49- ///
50- /// Failing to CREATE is loud too: a requested dump that does not exist is
51- /// the same silent hole as one that is short (the reader sees no file, or
52- /// an empty one), and it is the more common of the two (a missing parent
53- /// directory, a path a sweep reused as a directory).
54- pub fn create(site: &str, path: impl AsRef<Path>, expected: usize) -> Self {
55- let path = path.as_ref().to_path_buf();
56- let file = File::create(&path).unwrap_or_else(|e| {
57- abort(
58- site,
59- &path,
60- 0,
61- Some(expected),
62- &format!("could not create the dump file: {e}"),
63- )
64- });
65- Self {
66- site: site.to_string(),
67- path,
68- file: Some(file),
69- written: 0,
70- expected: Some(expected),
71- }
72- }
73-
74- /// Open `path` for `site` in APPEND mode with no knowable total length --
75- /// the CDF-table text dump, whose file spans every frame of a run. Write
76- /// errors are still fatal; the length check is simply absent (see
77- /// [`LoudDump::expected`]).
78- pub fn append_unknown(site: &str, path: impl AsRef<Path>) -> Self {
79- let path = path.as_ref().to_path_buf();
80- let file = OpenOptions::new()
81- .create(true)
82- .append(true)
83- .open(&path)
84- .unwrap_or_else(|e| {
85- abort(
86- site,
87- &path,
88- 0,
89- None,
90- &format!("could not open the dump file: {e}"),
91- )
92- });
93- Self {
94- site: site.to_string(),
95- path,
96- file: Some(file),
97- written: 0,
98- expected: None,
99- }
100- }
101-
102- /// Hand `chunk` to the file. Overrunning `expected` is a caller bug (the
103- /// count and the writer disagree) and aborts just as loudly as a short
104- /// write, because one of the two is certainly lying.
105- pub fn write(&mut self, chunk: &[u8]) {
106- if let Some(exp) = self.expected
107- && self.written + chunk.len() > exp
108- {
109- abort(
110- &self.site,
111- &self.path,
112- self.written,
113- Some(exp),
114- &format!(
115- "the writer was handed {} bytes but only {} remained of the {} it declared",
116- chunk.len(),
117- exp - self.written,
118- exp
119- ),
120- );
121- }
122- let r = self.file.as_mut().expect("live dump").write_all(chunk);
123- if let Err(e) = r {
124- // MEASURED, do not assume: under `RLIMIT_FSIZE` the kernel stores
125- // everything up to the cap and THEN returns `EFBIG` (measured:
126- // a 49 152 B frame under caps of 4 KiB / 10 KiB / 30 KiB left
127- // 4 096 / 10 240 / 30 720 B on disk, with `write_all` confirming
128- // none of it). So "bytes written" on this line is the file's real
129- // length, not the count `write_all` got to acknowledge -- the
130- // acknowledged count rides along in the reason.
131- let f = self.file.as_ref().expect("live dump");
132- let on_disk = f
133- .metadata()
134- .map(|m| m.len() as usize)
135- .unwrap_or(self.written);
136- abort(
137- &self.site,
138- &self.path,
139- on_disk,
140- self.expected,
141- &format!(
142- "write failed with {} bytes confirmed in hand: {e}",
143- self.written
144- ),
145- );
146- }
147- self.written += chunk.len();
148- }
149-
150- /// Close the dump: flush, then check the file's own length on disk.
151- ///
152- /// The on-disk check is not redundant with the write loop. `write_all`
153- /// reports what the FILE ACCEPTED, and the reader's question is what the
154- /// filesystem ended up holding -- a sparse/short final flush, a quota, or a
155- /// filesystem-level reservation failure all land here rather than in
156- /// `write`.
157- pub fn finish(mut self) {
158- let Some(mut file) = self.file.take() else {
159- return;
160- };
161- if let Err(e) = file.flush() {
162- abort(
163- &self.site,
164- &self.path,
165- self.written,
166- self.expected,
167- &format!("flush failed after {} bytes: {e}", self.written),
168- );
169- }
170- let Some(exp) = self.expected else {
171- return;
172- };
173- let on_disk = match file.metadata() {
174- Ok(m) => m.len() as usize,
175- Err(e) => abort(
176- &self.site,
177- &self.path,
178- self.written,
179- Some(exp),
180- &format!("could not stat the finished dump: {e}"),
181- ),
182- };
183- if on_disk != exp {
184- abort(
185- &self.site,
186- &self.path,
187- on_disk,
188- Some(exp),
189- "the file on disk is not the length the writer declared",
190- );
191- }
192- }
193-}
194-
195-/// The single failure line every short dump now ends on. `site`, the path, the
196-/// bytes on disk vs the bytes owed, and the reason.
197-fn abort(site: &str, path: &Path, got: usize, expected: Option<usize>, why: &str) -> ! {
198- panic!("{}", failure_line(site, path, got, expected, why));
199-}
200-
201-/// The failure line itself, so the fatal and the reporting shapes cannot
202-/// drift apart.
203-fn failure_line(site: &str, path: &Path, got: usize, expected: Option<usize>, why: &str) -> String {
204- let owed = match expected {
205- Some(e) => format!("{e}"),
206- None => "an unknown number of".to_string(),
207- };
208- format!(
209- "ec-av1 dump FAILED [{}] {}: wrote {} of {} bytes: {}",
210- site,
211- path.display(),
212- got,
213- owed,
214- why
215- )
216-}
217-
218-/// Write `bytes` to `path` as a FATAL pin: [`pin`] IS a wrapper -- three
219-/// [`LoudDump`] calls (`create`/`write`/`finish`), so it inherits the flush and
220-/// the flush-then-stat ordering for free.
221-///
222-/// lane-av1pinloud: the test-pin sites in `stream.rs` wrote with
223-/// `let _ = std::fs::write(..)` and then named the path in the panic that
224-/// followed ("stream pinned at {}"), so an `ENOSPC`/`EFBIG` left a TRUNCATED
225-/// stream at exactly the path the reader was told to replay -- the same
226-/// silent-truncation class as the dump path, one hop later. Success path is
227-/// byte-identical: same bytes, same path, truncate-then-write.
228-pub fn pin(site: &str, path: impl AsRef<Path>, bytes: &[u8]) {
229- let mut d = LoudDump::create(site, path, bytes.len());
230- d.write(bytes);
231- d.finish();
232-}
233-
234-/// [`pin`]'s NON-FATAL twin, for a site that must not die on a failed pin -- a
235-/// gate whose real failure is the assert that comes after the pin attempt, and
236-/// whose comment says so.
237-///
238-/// This one RE-IMPLEMENTS the check rather than wrapping [`LoudDump`], whose
239-/// failure channel is `panic!`: it cannot report instead of dying. So it does
240-/// `fs::write` + `metadata` itself. Only the failure LINE is shared, via
241-/// [`failure_line`] -- the ordering (flush-then-stat) and the
242-/// write-error-handling are not shared with [`LoudDump`], and a reader must not
243-/// assume they are.
244-///
245-/// Non-fatal, but not silent: a shortfall comes back as the very same failure
246-/// line [`pin`] would have panicked with, expected-vs-on-disk counts included,
247-/// for the caller to print as a warning.
248-#[cfg(test)] // only the self-test below calls it; keeps the non-test build free of dead code
249-pub fn pin_reporting(site: &str, path: impl AsRef<Path>, bytes: &[u8]) -> Result<(), String> {
250- let path = path.as_ref();
251- let expected = bytes.len();
252- if let Err(e) = std::fs::write(path, bytes) {
253- let on_disk = std::fs::metadata(path)
254- .map(|m| m.len() as usize)
255- .unwrap_or(0);
256- return Err(failure_line(
257- site,
258- path,
259- on_disk,
260- Some(expected),
261- &format!("could not write the pin: {e}"),
262- ));
263- }
264- let on_disk = match std::fs::metadata(path) {
265- Ok(m) => m.len() as usize,
266- Err(e) => {
267- return Err(failure_line(
268- site,
269- path,
270- expected,
271- Some(expected),
272- &format!("could not stat the written pin: {e}"),
273- ));
274- }
275- };
276- if on_disk != expected {
277- return Err(failure_line(
278- site,
279- path,
280- on_disk,
281- Some(expected),
282- "the pinned file on disk is not the length of the stream",
283- ));
284- }
285- Ok(())
286-}
287-
288-/// Write `planes` (already narrowed to their dump's sample width) as ONE dump
289-/// file, failing loudly on any shortfall. `expected` is the sum of the plane
290-/// lengths -- the same extents the writer iterates, so a plane that is shorter
291-/// than its geometry claims cannot hide here.
292-pub fn write_planes(site: &str, path: impl AsRef<Path>, planes: &[&[u8]]) {
293- let expected: usize = planes.iter().map(|p| p.len()).sum();
294- let mut d = LoudDump::create(site, path, expected);
295- for p in planes {
296- d.write(p);
297- }
298- d.finish();
299-}
300-
301-#[cfg(test)]
302-mod tests {
303- use super::*;
304- use std::process::Command;
305-
306- fn scratch(tag: &str) -> PathBuf {
307- let p = std::env::temp_dir().join(format!("ec-av1-dumpio-{tag}-{}", std::process::id()));
308- let _ = std::fs::remove_file(&p);
309- p
310- }
311-
312- fn caught(f: impl FnOnce() + std::panic::UnwindSafe) -> String {
313- let prev = std::panic::take_hook();
314- std::panic::set_hook(Box::new(|_| {}));
315- let r = std::panic::catch_unwind(f);
316- std::panic::set_hook(prev);
317- let e = r.expect_err("the short dump must abort");
318- e.downcast_ref::<String>()
319- .cloned()
320- .or_else(|| e.downcast_ref::<&str>().map(|s| (*s).to_string()))
321- .expect("panic payload is a string")
322- }
323-
324- #[test]
325- fn success_path_is_byte_identical_to_the_old_write_all_loop() {
326- let p = scratch("ok");
327- let planes: [&[u8]; 3] = [b"abc", b"", b"de"];
328- write_planes("T", &p, &planes);
329- assert_eq!(std::fs::read(&p).unwrap(), b"abcde");
330- let _ = std::fs::remove_file(&p);
331- }
332-
333- /// `/dev/full` accepts an `open` for write and returns `ENOSPC` from every
334- /// write -- the hermetic stand-in for the full filesystem that produced the
335- /// 13 320 192-byte truncated frame in `lanes/unwritten-dep.report.md`.
336- #[test]
337- #[cfg(unix)]
338- fn full_device_short_write_is_loud() {
339- let msg = caught(|| write_planes("EC_AV1_FINAL_DUMP", "/dev/full", &[b"abc", b"de"]));
340- assert!(
341- msg.starts_with("ec-av1 dump FAILED [EC_AV1_FINAL_DUMP] /dev/full: wrote "),
342- "{msg}"
343- );
344- assert!(msg.contains("No space left on device"), "{msg}");
345- // The counts must be there, or the line does not say what was lost.
346- assert!(msg.contains(" of 5 bytes"), "{msg}");
347- }
348-
349- #[test]
350- fn uncreatable_dump_is_loud() {
351- let p = std::env::temp_dir().join(format!("ec-av1-nodir-{}/x", std::process::id()));
352- let msg = caught(|| write_planes("T", &p, &[b"abc"]));
353- assert!(msg.contains("could not create the dump file"), "{msg}");
354- }
355-
356- /// A writer that under-declares its own expected length is the same silent
357- /// hole: the reader gets a file the site believes is complete.
358- #[test]
359- fn under_declared_expected_length_is_loud() {
360- let p = scratch("under");
361- let msg = caught(|| {
362- let mut d = LoudDump::create("T", &p, 2);
363- d.write(b"abcdef");
364- d.finish();
365- });
366- assert!(
367- msg.contains("was handed 6 bytes but only 2 remained of the 2 it declared"),
368- "{msg}"
369- );
370- let _ = std::fs::remove_file(&p);
371- }
372-
373- #[test]
374- fn append_unknown_takes_no_length_claim() {
375- let p = scratch("append");
376- {
377- let mut a = LoudDump::append_unknown("T", &p);
378- a.write(b"x");
379- a.finish();
380- let mut b = LoudDump::append_unknown("T", &p);
381- b.write(b"y");
382- b.finish();
383- }
384- assert_eq!(std::fs::read(&p).unwrap(), b"xy");
385- let msg = caught(|| {
386- let mut a = LoudDump::append_unknown("T", "/dev/full");
387- a.write(b"x");
388- a.finish();
389- });
390- assert!(msg.contains("of an unknown number of bytes"), "{msg}");
391- let _ = std::fs::remove_file(&p);
392- }
393- /// THE reproduction of the incident this module exists for: a real decode,
394- /// a real `RLIMIT_FSIZE`, a real truncated `EC_AV1_FINAL_DUMP` file left
395- /// on disk -- and the run stopping with the bytes-vs-bytes line instead of
396- /// carrying on to a measurement built on the fragment.
397- ///
398- /// `/dev/full` (the unit test above) proves the writer's check works but
399- /// never leaves a partial file behind, because `create` on it succeeds and
400- /// nothing is ever stored. `RLIMIT_FSIZE` is the shape
401- /// `lanes/unwritten-dep.report.md` actually measured: frames 0..4 complete
402- /// plus 13 320 192 bytes of frame 5. `SIGXFSZ` is IGNORED (`trap "" XFSZ`)
403- /// so the limit surfaces as `write`'s `EFBIG` -- exactly what a full
404- /// filesystem's `ENOSPC` does -- instead of killing the child outright.
405- #[test]
406- #[cfg(unix)]
407- fn a_real_decode_under_a_file_size_cap_fails_loudly() {
408- let dir = std::env::temp_dir().join(format!("ec-av1-dumpio-cap-{}", std::process::id()));
409- let _ = std::fs::remove_dir_all(&dir);
410- std::fs::create_dir_all(&dir).unwrap();
411- let prefix = dir.join("ours");
412- // 8 blocks of 512 B = 4096 B: far below one 256x128 4:2:0 8-bit frame
413- // (49 152 B), far above the file header, so the write lands and fails
414- // PART way rather than at create.
415- let out = Command::new("bash")
416- .args([
417- "-c",
418- "ulimit -f 8; trap \"\" XFSZ; exec \"$0\" \"$@\"",
419- // $0 for `bash -c` is the test binary itself.
420- std::env::current_exe().unwrap().to_str().unwrap(),
421- "--exact",
422- "dumpio::tests::dumpio_child_decode",
423- "--nocapture",
424- ])
425- .env("EC_AV1_DUMPLOUD_CHILD", "1")
426- .env("EC_AV1_FINAL_DUMP", &prefix)
427- // One thread, so the dump panic lands on the main thread and the
428- // child's exit status is the decode's own.
429- .env("EC_AV1_THREADS", "1")
430- .output()
431- .expect("spawning the capped child");
432- let stderr = String::from_utf8_lossy(&out.stderr);
433- assert!(
434- !out.status.success(),
435- "the decode must FAIL under a file-size cap, not finish with a truncated dump\n{stderr}"
436- );
437- assert!(
438- stderr.contains("ec-av1 dump FAILED [EC_AV1_FINAL_DUMP]"),
439- "the failure line must name the dump site\n{stderr}"
440- );
441- assert!(
442- stderr.contains("File too large"),
443- "the failure line must carry the OS error\n{stderr}"
444- );
445- // One 256x128 4:2:0 8-bit frame is 256*128*3/2 = 49 152 B, and the
446- // failure line's "wrote N of 49152" must name the file's REAL length,
447- // not the count `write_all` managed to acknowledge: a line that
448- // under-reports is a line that sends the reader back to the dump to
449- // measure it themselves.
450- let frag = std::fs::metadata(format!("{}.f0", prefix.display()))
451- .unwrap()
452- .len();
453- assert!(
454- frag < 49152,
455- "the capped child left a {frag}-byte frame where 49152 B was owed"
456- );
457- assert!(
458- stderr.contains(&format!("wrote {frag} of 49152 bytes")),
459- "the failure line's written count must be the file's actual length ({frag})\n{stderr}"
460- );
461- let _ = std::fs::remove_dir_all(&dir);
462- }
463-
464- /// Child half of [`a_real_decode_under_a_file_size_cap_fails_loudly`]. It is
465- /// not a gate: with no `EC_AV1_DUMPLOUD_CHILD` guard it decodes nothing and
466- /// asserts nothing, so a plain `cargo test` run is unaffected.
467- #[test]
468- fn dumpio_child_decode() {
469- if std::env::var("EC_AV1_DUMPLOUD_CHILD").is_err() {
470- return;
471- }
472- let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
473- .join("fixtures/420_mixll_256x128_6f.obu");
474- let bytes = std::fs::read(&path).expect("the pinned fixture");
475- let _ = crate::stream::decode_stream(&bytes);
476- }
477-
478- #[test]
479- fn pin_success_path_is_byte_identical() {
480- let p = scratch("pin-ok");
481- pin("TEST_PIN", &p, b"stream bytes");
482- assert_eq!(std::fs::read(&p).unwrap(), b"stream bytes");
483- let _ = std::fs::remove_file(&p);
484- }
485-
486- #[test]
487- #[cfg(unix)]
488- fn pin_to_a_full_device_is_loud() {
489- let msg = caught(|| pin("TEST_PIN", "/dev/full", b"stream bytes"));
490- assert!(
491- msg.starts_with("ec-av1 dump FAILED [TEST_PIN] /dev/full: wrote "),
492- "{msg}"
493- );
494- assert!(msg.contains("No space left on device"), "{msg}");
495- assert!(msg.contains(" of 12 bytes"), "{msg}");
496- }
497-
498- /// The reporting shape: same failure line, returned instead of panicked,
499- /// so a gate whose real failure is the assert after the pin keeps that
500- /// assert -- but the reader still learns the pin is short.
501- #[test]
502- #[cfg(unix)]
503- fn pin_reporting_is_loud_but_not_fatal() {
504- let line = pin_reporting("TEST_PIN", "/dev/full", b"stream bytes").unwrap_err();
505- assert!(
506- line.contains("ec-av1 dump FAILED [TEST_PIN] /dev/full"),
507- "{line}"
508- );
509- assert!(line.contains(" of 12 bytes"), "{line}");
510- let p = scratch("pin-reporting-ok");
511- pin_reporting("TEST_PIN", &p, b"stream bytes").expect("a healthy pin reports nothing");
512- assert_eq!(std::fs::read(&p).unwrap(), b"stream bytes");
513- let _ = std::fs::remove_file(&p);
514- }
515-
516- /// The pin path's own reproduction: a real `RLIMIT_FSIZE` leaves a real
517- /// truncated stream at the path the panic names. Without the check the
518- /// reader replays the fragment and blames the decoder.
519- #[test]
520- #[cfg(unix)]
521- fn a_pin_under_a_file_size_cap_fails_loudly() {
522- let dir = std::env::temp_dir().join(format!("ec-av1-pin-cap-{}", std::process::id()));
523- let _ = std::fs::remove_dir_all(&dir);
524- std::fs::create_dir_all(&dir).unwrap();
525- let out = Command::new("bash")
526- .args([
527- "-c",
528- "ulimit -f 8; trap \"\" XFSZ; exec \"$0\" \"$@\"",
529- std::env::current_exe().unwrap().to_str().unwrap(),
530- "--exact",
531- "dumpio::tests::pin_child_under_cap",
532- "--nocapture",
533- ])
534- .env("EC_AV1_PINLOUD_CHILD", &dir)
535- .output()
536- .expect("spawning the capped child");
537- let stderr = String::from_utf8_lossy(&out.stderr);
538- assert!(!out.status.success(), "a short pin must fail\n{stderr}");
539- assert!(stderr.contains("ec-av1 dump FAILED [TEST_PIN]"), "{stderr}");
540- assert!(stderr.contains("File too large"), "{stderr}");
541- let frag = std::fs::metadata(dir.join("cap-pinned.obu")).unwrap().len();
542- assert!(
543- frag < 32768,
544- "the capped child left {frag} bytes where 32768 B was owed"
545- );
546- assert!(
547- stderr.contains(&format!("wrote {frag} of 32768 bytes")),
548- "{stderr}"
549- );
550- let _ = std::fs::remove_dir_all(&dir);
551- }
552-
553- /// Child half of [`a_pin_under_a_file_size_cap_fails_loudly`]. Not a gate:
554- /// with no `EC_AV1_PINLOUD_CHILD` set it writes nothing and asserts nothing.
555- #[test]
556- fn pin_child_under_cap() {
557- let Ok(dir) = std::env::var("EC_AV1_PINLOUD_CHILD") else {
558- return;
559- };
560- // `ulimit -f 8` is 8 KiB, so 4x that is guaranteed to run PAST the cap
561- // (a write of exactly the cap size succeeds) and land a fragment.
562- pin(
563- "TEST_PIN",
564- Path::new(&dir).join("cap-pinned.obu"),
565- &[7u8; 32768],
566- );
567- }
568-}
crates/ec-av1/src/encode/coef.rsmodified+40 -31
@@ -962,7 +962,13 @@ impl Plane<'_> {
962962 }
963963
964964 /// Puts a snapshot back.
965- pub(super) fn restore(&mut self, x: usize, y: usize, side: usize, saved: &(Vec<u8>, Vec<CoefCtx>)) {
965+ pub(super) fn restore(
966+ &mut self,
967+ x: usize,
968+ y: usize,
969+ side: usize,
970+ saved: &(Vec<u8>, Vec<CoefCtx>),
971+ ) {
966972 for row in 0..side {
967973 self.reconstruction[(y + row) * self.width + x..][..side]
968974 .copy_from_slice(&saved.0[row * side..][..side]);
@@ -1080,19 +1086,20 @@ impl Plane<'_> {
10801086 })
10811087 .collect();
10821088 if let Some(k) = search.top_k
1083- && k < scored.len() {
1084- let dc_pos = scored.iter().position(|&(_, mode, _)| mode == DC_PRED);
1085- let dc_entry = dc_pos.map(|i| scored.remove(i));
1086- scored.sort_by(|a, b| a.0.partial_cmp(&b.0).expect("scores are finite"));
1087- scored.truncate(if dc_entry.is_some() {
1088- k.saturating_sub(1)
1089- } else {
1090- k
1091- });
1092- if let Some(dc_entry) = dc_entry {
1093- scored.push(dc_entry);
1094- }
1089+ && k < scored.len()
1090+ {
1091+ let dc_pos = scored.iter().position(|&(_, mode, _)| mode == DC_PRED);
1092+ let dc_entry = dc_pos.map(|i| scored.remove(i));
1093+ scored.sort_by(|a, b| a.0.partial_cmp(&b.0).expect("scores are finite"));
1094+ scored.truncate(if dc_entry.is_some() {
1095+ k.saturating_sub(1)
1096+ } else {
1097+ k
1098+ });
1099+ if let Some(dc_entry) = dc_entry {
1100+ scored.push(dc_entry);
10951101 }
1102+ }
10961103 let ranking: Vec<(f64, u8)> = if census_on() {
10971104 scored
10981105 .iter()
@@ -1179,8 +1186,6 @@ impl Plane<'_> {
11791186 trial = candidate;
11801187 }
11811188 }
1182- ANGLE_DELTA_HITS[(crate::tile::ANGLE_DELTA_ZERO as i32 + angle_delta) as usize]
1183- .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
11841189 }
11851190 // lane-txset: the block's own transform type, searched on the mode
11861191 // and angle the trials above settled -- the same ordering the angle
@@ -1405,7 +1410,8 @@ pub(super) const HAS_TR_8X16: [u8; 16] = [
14051410 /// `has_bl_8x16` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 16 bits (`128 / 8`).
14061411 pub(super) const HAS_BL_8X16: [u8; 16] = [16, 17, 0, 1, 16, 17, 0, 0, 16, 17, 0, 1, 16, 17, 0, 0];
14071412 /// `has_tr_16x8` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 8 bits (`128 / 16`).
1408-pub(super) const HAS_TR_16X8: [u8; 16] = [255, 0, 85, 0, 119, 0, 85, 0, 127, 0, 85, 0, 119, 0, 85, 0];
1413+pub(super) const HAS_TR_16X8: [u8; 16] =
1414+ [255, 0, 85, 0, 119, 0, 85, 0, 127, 0, 85, 0, 119, 0, 85, 0];
14091415 /// `has_bl_16x8` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 8 bits (`128 / 16`).
14101416 pub(super) const HAS_BL_16X8: [u8; 16] = [
14111417 254, 84, 254, 16, 254, 84, 254, 0, 254, 84, 254, 16, 254, 84, 254, 0,
@@ -1785,18 +1791,6 @@ impl Reach {
17851791 Self::bit(table, Self::rect_table_index(bw_log2, blk_row, blk_col))
17861792 }
17871793
1788- /// Marks every [`Reach::of`] made until the returned guard drops as being
1789- /// inside a `PARTITION_VERT_A`/`_B` (libaom's `get_has_tr_table` /
1790- /// `get_has_bl_table` partition argument). Rectangular sub-blocks are
1791- /// unaffected: libaom's own comment says vertical rectangles keep their
1792- /// non-vert table, which is what [`Reach::of_rect`] already reads.
1793- /// Whether a `PARTITION_VERT_A`/`_B`'s sub-blocks are being decoded
1794- /// right now ([`Self::vert_ab_partition`]'s guard is alive), so a caller
1795- /// can count the sub-block work that partition creates (lane-ab16).
1796- pub(crate) fn in_vert_ab() -> bool {
1797- VERT_AB_PARTITION.with(std::cell::Cell::get)
1798- }
1799-
18001794 pub(crate) fn vert_ab_partition() -> VertAbGuard {
18011795 VertAbGuard(VERT_AB_PARTITION.with(|c| c.replace(true)))
18021796 }
@@ -1814,7 +1808,12 @@ impl Reach {
18141808 /// row of a superblock reads into the superblock above, which is decoded;
18151809 /// the rightmost column would read into the superblock to the right, which
18161810 /// is not; and everything between is the table's to answer.
1817- pub(super) fn top_right(side: usize, x: usize, y: usize, fctx: &crate::decode::FrameCtx) -> bool {
1811+ pub(super) fn top_right(
1812+ side: usize,
1813+ x: usize,
1814+ y: usize,
1815+ fctx: &crate::decode::FrameCtx,
1816+ ) -> bool {
18181817 let (row, col, per_side) = Self::position(side, x, y, fctx);
18191818 if row == 0 {
18201819 return true;
@@ -1851,7 +1850,12 @@ impl Reach {
18511850 /// reads into the superblock to its left, which is decoded only as far
18521851 /// down as its own bottom; the bottom row would read into the superblock
18531852 /// below, which is not decoded at all; and the table answers the rest.
1854- pub(super) fn bottom_left(side: usize, x: usize, y: usize, fctx: &crate::decode::FrameCtx) -> bool {
1853+ pub(super) fn bottom_left(
1854+ side: usize,
1855+ x: usize,
1856+ y: usize,
1857+ fctx: &crate::decode::FrameCtx,
1858+ ) -> bool {
18551859 let (row, col, per_side) = Self::position(side, x, y, fctx);
18561860 if col == 0 {
18571861 return row * side + side < reach_sb_px(fctx);
@@ -2032,7 +2036,12 @@ pub(super) fn obmc_min_side() -> usize {
20322036 /// 2-symbol `obmc` one. Both sides of every motion-mode comparison in the
20332037 /// search pay it, so the alphabet cancels out of a comparison and only its
20342038 /// per-value spread decides.
2035-pub(super) fn motion_mode_bits(write_w: usize, write_h: usize, motion: u8, warp_alphabet: bool) -> f64 {
2039+pub(super) fn motion_mode_bits(
2040+ write_w: usize,
2041+ write_h: usize,
2042+ motion: u8,
2043+ warp_alphabet: bool,
2044+) -> f64 {
20362045 let Some(row) = crate::decode::motion_mode_cdf_row(write_w, write_h) else {
20372046 return 0.0;
20382047 };
crates/ec-av1/src/encode/frame.rsmodified+50 -37
@@ -52,7 +52,8 @@ pub(super) fn deltaq_res_log2() -> Option<u8> {
5252 /// sets it holds [`crate::speed::knob_write`], the same exclusive lock the
5353 /// speed presets take, because the streams every other test pins move under
5454 /// it (the shipped default is OFF, see [`crate::speed::DELTAQ_RES`]).
55-pub(super) static DELTAQ_OVERRIDE: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(u8::MAX);
55+pub(super) static DELTAQ_OVERRIDE: std::sync::atomic::AtomicU8 =
56+ std::sync::atomic::AtomicU8::new(u8::MAX);
5657
5758 /// Sets [`DELTAQ_OVERRIDE`]; `None` clears it.
5859 #[allow(dead_code)] // set only from the `#[cfg(test)]` gates
@@ -270,13 +271,8 @@ pub(super) fn dq_summary(offsets: &[i32]) -> String {
270271 /// grid that is one flat value, i.e. on no delta_q at all). Process-global
271272 /// like [`TX_DEPTH_HITS`], and read through [`take_deltaq_levels`], which
272273 /// keeps the LARGEST count seen since the last read.
273-pub(super) static DELTAQ_LEVELS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
274-
275-/// [`DELTAQ_LEVELS`], reset to 0.
276-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
277-pub(crate) fn take_deltaq_levels() -> usize {
278- DELTAQ_LEVELS.swap(0, std::sync::atomic::Ordering::Relaxed)
279-}
274+pub(super) static DELTAQ_LEVELS: std::sync::atomic::AtomicUsize =
275+ std::sync::atomic::AtomicUsize::new(0);
280276
281277 /// This superblock's search state: the quantizer it is coded at, and the
282278 /// lambda that quantizer implies. RD lambda goes as the square of the step,
@@ -404,7 +400,12 @@ pub(super) static TPL_NANOS: std::sync::atomic::AtomicU64 = std::sync::atomic::A
404400 /// the left/above winners, first-best tie-break. Built once on the frame's
405401 /// own thread and read-only afterwards, so it cannot make a tile's bytes
406402 /// depend on the thread count.
407-pub(super) fn tpl_coarse_pass(cur: &[u8], next: &[u8], width: usize, height: usize) -> Vec<((i32, i32), u32)> {
403+pub(super) fn tpl_coarse_pass(
404+ cur: &[u8],
405+ next: &[u8],
406+ width: usize,
407+ height: usize,
408+) -> Vec<((i32, i32), u32)> {
408409 let (cells_x, cells_y) = (width / 16, height / 16);
409410 let sad = |bx: usize, by: usize, (mx, my): (i32, i32)| -> u32 {
410411 let (sx, sy) = (bx as i32 + mx, by as i32 + my);
@@ -823,10 +824,11 @@ pub(crate) fn arf_temporal_filter(src: &Picture, window: &[Picture], strength: f
823824 ] {
824825 let mv = (from.0 + dy * step, from.1 + dx * step);
825826 if let Some(s) = sad(r, bx, by, mv)
826- && s.0 < best.0 {
827- best = s;
828- centre = mv;
829- }
827+ && s.0 < best.0
828+ {
829+ best = s;
830+ centre = mv;
831+ }
830832 }
831833 step /= 2;
832834 }
@@ -1288,28 +1290,29 @@ pub(crate) fn encode_inter_frame(
12881290 // the frame codes any delta syntax (`deltaq_res` is `None` with the lever
12891291 // off, and the census then prices the default `res = 4` grid).
12901292 if dq_census()
1291- && let Some(f) = &tpl_factors {
1292- let res = deltaq_res.unwrap_or(4);
1293- let off = |libaom: Option<f64>| -> Vec<i32> {
1294- (0..sb_cols * _sb_rows)
1295- .map(|sb| i32::from(sb_qindex(f, res, sb, libaom)) - i32::from(base_q_idx))
1296- .collect()
1297- };
1298- let strength = dq_tpl_strength(dq_level);
1299- let (ours, aom) = (off(None), off(Some(strength.unwrap_or(1.0))));
1300- let coded = match (deltaq_res.is_some(), strength) {
1301- (false, _) => "none".to_string(),
1302- (true, None) => "ours".to_string(),
1303- (true, Some(k)) => format!("libaom k={k}"),
1304- };
1305- eprintln!(
1306- "dq census: level={dq_level:?} base={base_q_idx} res={res} sbs={} coded={coded} r_frame={:.4}\n ours {}\n libaom {}",
1307- sb_cols * _sb_rows,
1308- r_frame.unwrap_or(f64::NAN),
1309- dq_summary(&ours),
1310- dq_summary(&aom),
1311- );
1312- }
1293+ && let Some(f) = &tpl_factors
1294+ {
1295+ let res = deltaq_res.unwrap_or(4);
1296+ let off = |libaom: Option<f64>| -> Vec<i32> {
1297+ (0..sb_cols * _sb_rows)
1298+ .map(|sb| i32::from(sb_qindex(f, res, sb, libaom)) - i32::from(base_q_idx))
1299+ .collect()
1300+ };
1301+ let strength = dq_tpl_strength(dq_level);
1302+ let (ours, aom) = (off(None), off(Some(strength.unwrap_or(1.0))));
1303+ let coded = match (deltaq_res.is_some(), strength) {
1304+ (false, _) => "none".to_string(),
1305+ (true, None) => "ours".to_string(),
1306+ (true, Some(k)) => format!("libaom k={k}"),
1307+ };
1308+ eprintln!(
1309+ "dq census: level={dq_level:?} base={base_q_idx} res={res} sbs={} coded={coded} r_frame={:.4}\n ours {}\n libaom {}",
1310+ sb_cols * _sb_rows,
1311+ r_frame.unwrap_or(f64::NAN),
1312+ dq_summary(&ours),
1313+ dq_summary(&aom),
1314+ );
1315+ }
13131316 if let Some(res) = deltaq_res.filter(|_| sb_q.is_some()) {
13141317 header.delta.q_present = true;
13151318 header.delta.q_res = res.trailing_zeros() as u8;
@@ -2332,9 +2335,19 @@ pub(crate) fn encode_inter_frame(
23322335 // rectangles partition the frame, so the order does not change the bytes).
23332336 let mut searched_blocks = Vec::new();
23342337 for (tile_blocks, pixels) in search_tiles(layout.count(), fctx, search_tile)? {
2335- put_rect(&mut luma.reconstruction, frame_width, pixels.luma_rect, &pixels.luma);
2338+ put_rect(
2339+ &mut luma.reconstruction,
2340+ frame_width,
2341+ pixels.luma_rect,
2342+ &pixels.luma,
2343+ );
23362344 for (plane, bytes) in chroma.iter_mut().zip(&pixels.chroma) {
2337- put_rect(&mut plane.reconstruction, frame_width / 2, pixels.chroma_rect, bytes);
2345+ put_rect(
2346+ &mut plane.reconstruction,
2347+ frame_width / 2,
2348+ pixels.chroma_rect,
2349+ bytes,
2350+ );
23382351 }
23392352 searched_blocks.push(tile_blocks);
23402353 }
crates/ec-av1/src/encode/inter_search.rsmodified+44 -39
@@ -212,7 +212,8 @@ pub(super) fn arfmode() -> u8 {
212212 }
213213
214214 /// [`ARFMODE_OVERRIDE`]: `u8::MAX` clears it.
215-pub(super) static ARFMODE_OVERRIDE: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(u8::MAX);
215+pub(super) static ARFMODE_OVERRIDE: std::sync::atomic::AtomicU8 =
216+ std::sync::atomic::AtomicU8::new(u8::MAX);
216217
217218 /// Sets [`ARFMODE_OVERRIDE`]; `None` clears it. Test-only: the env is a
218219 /// process constant ([`crate::envflags`]), so an in-process witness needs
@@ -279,11 +280,6 @@ thread_local! {
279280 const { std::cell::Cell::new(None) };
280281 }
281282
282-#[cfg(test)]
283-pub(super) fn set_test_top_k_override(value: Option<usize>) {
284- TEST_TOP_K_OVERRIDE.with(|cell| cell.set(Some(value)));
285-}
286-
287283 /// The default: unpruned, thirteen full trials per block, same as before this
288284 /// lever. Set from the sweep in the lane report if the quality gate clears it.
289285 pub(crate) const PRUNE_TOP_K: Option<usize> = None;
@@ -317,11 +313,6 @@ thread_local! {
317313 const { std::cell::Cell::new(None) };
318314 }
319315
320-#[cfg(test)]
321-pub(super) fn set_test_top_k_override_inter(value: Option<usize>) {
322- TEST_TOP_K_OVERRIDE_INTER.with(|cell| cell.set(Some(value)));
323-}
324-
325316 /// The inter path's default `top_k`: `Some(3)`, from `prune_k_quality_sweep_inter`
326317 /// (three real clips, q 60 and 150) -- every `K` in {3, 4, 6} cleared the
327318 /// same rule the key-frame lever uses (every PSNR delta <0.05dB, bytes
@@ -374,21 +365,6 @@ pub(crate) fn stage_add(bucket: usize, dur: std::time::Duration) {
374365 STAGE_NS.with(|c| c[bucket].set(c[bucket].get() + dur.as_nanos() as u64));
375366 }
376367
377-#[cfg(test)]
378-pub(super) fn stage_reset() {
379- crate::par::set_stage_times(true);
380- STAGE_NS.with(|c| c.iter().for_each(|cell| cell.set(0)));
381-}
382-
383-#[cfg(test)]
384-pub(super) fn stage_read() -> [std::time::Duration; 4] {
385- crate::par::set_stage_times(false);
386- STAGE_NS.with(|c| {
387- c.each_ref()
388- .map(|cell| std::time::Duration::from_nanos(cell.get()))
389- })
390-}
391-
392368 /// One mode's coding of one block, before it is committed.
393369 #[derive(Clone)]
394370 pub(super) struct Trial {
@@ -526,7 +502,11 @@ where
526502 /// The `FrameCtx` copy is made on the calling thread (`&FrameCtx` is `!Sync`
527503 /// by design) and moved into the worker, exactly as the decoder's filter bands
528504 /// do it through [`crate::par::scope`].
529-pub(super) fn search_tiles<T, F>(tiles: usize, fctx: &crate::decode::FrameCtx, job: F) -> Result<Vec<T>>
505+pub(super) fn search_tiles<T, F>(
506+ tiles: usize,
507+ fctx: &crate::decode::FrameCtx,
508+ job: F,
509+) -> Result<Vec<T>>
530510 where
531511 T: Send,
532512 F: Fn(usize, &crate::decode::FrameCtx) -> Result<T> + Sync,
@@ -600,7 +580,11 @@ pub(super) struct TilePixels {
600580
601581 /// The rectangle `[x0, x1) x [y0, y1)` of a plane with `stride`, copied out as
602582 /// its rows back to back.
603-pub(super) fn take_rect(plane: &[u8], stride: usize, (x0, y0, x1, y1): (usize, usize, usize, usize)) -> Vec<u8> {
583+pub(super) fn take_rect(
584+ plane: &[u8],
585+ stride: usize,
586+ (x0, y0, x1, y1): (usize, usize, usize, usize),
587+) -> Vec<u8> {
604588 let mut out = Vec::with_capacity((x1 - x0) * (y1 - y0));
605589 for y in y0..y1 {
606590 out.extend_from_slice(&plane[y * stride + x0..y * stride + x1]);
@@ -610,7 +594,12 @@ pub(super) fn take_rect(plane: &[u8], stride: usize, (x0, y0, x1, y1): (usize, u
610594
611595 /// The inverse of [`take_rect`]: writes `rows` (as `take_rect` produced them)
612596 /// back into the rectangle of `plane`.
613-pub(super) fn put_rect(plane: &mut [u8], stride: usize, (x0, y0, x1, y1): (usize, usize, usize, usize), rows: &[u8]) {
597+pub(super) fn put_rect(
598+ plane: &mut [u8],
599+ stride: usize,
600+ (x0, y0, x1, y1): (usize, usize, usize, usize),
601+ rows: &[u8],
602+) {
614603 let w = x1 - x0;
615604 for (row, y) in (y0..y1).enumerate() {
616605 plane[y * stride + x0..y * stride + x1].copy_from_slice(&rows[row * w..(row + 1) * w]);
@@ -622,7 +611,10 @@ pub(super) fn put_rect(plane: &mut [u8], stride: usize, (x0, y0, x1, y1): (usize
622611 /// tables the frame stores (spec 7.20), which is what
623612 /// [`crate::tile::TileLayout::largest_tile`] picks and what the tile loops
624613 /// below publish.
625-pub(super) fn tile_info_of(layout: &crate::tile::TileLayout, tile_size_bytes: u32) -> ec_av1_syntax::TileInfo {
614+pub(super) fn tile_info_of(
615+ layout: &crate::tile::TileLayout,
616+ tile_size_bytes: u32,
617+) -> ec_av1_syntax::TileInfo {
626618 ec_av1_syntax::TileInfo {
627619 uniform_spacing: true,
628620 cols: layout.cols(),
@@ -1380,9 +1372,19 @@ pub(crate) fn encode_key_frame_inner(
13801372 let searched = search_tiles(layout.count(), fctx, search_tile)?;
13811373 let mut searched_coded = Vec::with_capacity(searched.len());
13821374 for (coded, pixels) in searched {
1383- put_rect(&mut luma.reconstruction, frame_width, pixels.luma_rect, &pixels.luma);
1375+ put_rect(
1376+ &mut luma.reconstruction,
1377+ frame_width,
1378+ pixels.luma_rect,
1379+ &pixels.luma,
1380+ );
13841381 for (plane, bytes) in chroma.iter_mut().zip(&pixels.chroma) {
1385- put_rect(&mut plane.reconstruction, frame_width / 2, pixels.chroma_rect, bytes);
1382+ put_rect(
1383+ &mut plane.reconstruction,
1384+ frame_width / 2,
1385+ pixels.chroma_rect,
1386+ bytes,
1387+ );
13861388 }
13871389 searched_coded.push(coded);
13881390 }
@@ -2104,7 +2106,8 @@ pub(super) fn mv_residual_bits(mv: (i32, i32), pred: (i32, i32)) -> Option<f64>
21042106 /// always), the shape [`set_frame_interp`] has: the witness that has to see
21052107 /// `mv_hp` symbols coded turns it on through this while holding
21062108 /// [`crate::speed::knob_write`].
2107-pub(super) static HP_MV_OVERRIDE: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(u8::MAX);
2109+pub(super) static HP_MV_OVERRIDE: std::sync::atomic::AtomicU8 =
2110+ std::sync::atomic::AtomicU8::new(u8::MAX);
21082111
21092112 /// Sets [`HP_MV_OVERRIDE`]; `None` clears it.
21102113 #[allow(dead_code)] // set only from the `#[cfg(test)]` gates
@@ -4448,9 +4451,10 @@ pub(super) fn search_inter_block(
44484451 planes,
44494452 (reference.width, reference.height),
44504453 fctx,
4451- ) {
4452- candidates.push((1, pred));
4453- }
4454+ )
4455+ {
4456+ candidates.push((1, pred));
4457+ }
44544458 if warp_alphabet
44554459 && let Some(pred) = warp_prediction(
44564460 grid,
@@ -4462,9 +4466,10 @@ pub(super) fn search_inter_block(
44624466 info.ref_frame,
44634467 planes,
44644468 fctx,
4465- ) {
4466- candidates.push((2, pred));
4467- }
4469+ )
4470+ {
4471+ candidates.push((2, pred));
4472+ }
44684473 for (motion, pred) in candidates {
44694474 let luma_trial = luma.code_from_prediction(
44704475 x,
crates/ec-av1/src/encode/mod.rsmodified+0 -50
@@ -821,12 +821,6 @@ fn rectres() -> bool {
821821 static FORCE_B128_RECTRES: std::sync::atomic::AtomicBool =
822822 std::sync::atomic::AtomicBool::new(false);
823823
824-/// Arms [`FORCE_B128_RECTRES`] for the rest of the process.
825-#[cfg(test)]
826-pub(crate) fn force_b128_rectres(on: bool) {
827- FORCE_B128_RECTRES.store(on, std::sync::atomic::Ordering::Relaxed);
828-}
829-
830824 /// How many rect/AB pieces the search left WITH a residual rather than
831825 /// skipped, since the last [`take_b128_rectres_hits`] (class
832826 /// `gate-blind-to-feature`).
@@ -981,12 +975,6 @@ pub fn take_b128_vert_hits() -> usize {
981975 /// RD there prefers one whole block; the gate census is the unforced count.
982976 static FORCE_B128_RECT: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(0);
983977
984-/// Arms [`FORCE_B128_RECT`] for the rest of the process (0 / 1 HORZ / 2 VERT).
985-#[cfg(test)]
986-pub(crate) fn force_b128_rect(which: u8) {
987- FORCE_B128_RECT.store(which, std::sync::atomic::Ordering::Relaxed);
988-}
989-
990978 /// lane-ab128: whether the 128 superblock root offers its four AB shapes --
991979 /// `PARTITION_HORZ_A` (two 64x64 on top, one 128x64 below), `_HORZ_B` (one
992980 /// 128x64 on top, two 64x64 below), `_VERT_A` (two 64x64 left, one 64x128
@@ -1029,12 +1017,6 @@ pub fn take_b128_ab_hits() -> [usize; 4] {
10291017 /// prefers one whole block).
10301018 static FORCE_B128_AB: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(0);
10311019
1032-/// Arms [`FORCE_B128_AB`] for the rest of the process (0 off, else 4..=7).
1033-#[cfg(test)]
1034-pub(crate) fn force_b128_ab(which: u8) {
1035- FORCE_B128_AB.store(which, std::sync::atomic::Ordering::Relaxed);
1036-}
1037-
10381020 /// lane-ab128: the three pieces of an AB shape at a 128 root, in the order
10391021 /// libaom's `decode_partition` codes them and decode.rs' `sb128_ab` arm
10401022 /// reads them (decode.rs ~35269) -- HORZ_A = TL, TR, bottom half; HORZ_B =
@@ -1073,20 +1055,6 @@ static FORCE_B128_RESIDUAL: std::sync::atomic::AtomicBool =
10731055 /// for content on which the root also wins its own comparison.
10741056 static FORCE_B128_ROOT: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
10751057
1076-/// Arms [`FORCE_B128_RESIDUAL`] -- and with it [`FORCE_B128_ROOT`], since a
1077-/// forced residual block only reaches the writer if its root is taken.
1078-#[cfg(test)]
1079-pub(crate) fn force_b128_residual(on: bool) {
1080- FORCE_B128_RESIDUAL.store(on, std::sync::atomic::Ordering::Relaxed);
1081- force_b128_root(on);
1082-}
1083-
1084-/// Arms [`FORCE_B128_ROOT`] for the rest of the process.
1085-#[cfg(test)]
1086-pub(crate) fn force_b128_root(on: bool) {
1087- FORCE_B128_ROOT.store(on, std::sync::atomic::Ordering::Relaxed);
1088-}
1089-
10901058 /// How many 128 roots came out cheaper WITH a residual than skipped, since
10911059 /// the last [`take_b128_residual_hits`] (class `gate-blind-to-feature`).
10921060 static B128_RESIDUAL_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
@@ -1475,12 +1443,6 @@ fn partition_hit(which: usize) {
14751443 PARTITION_HITS[which].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
14761444 }
14771445
1478-/// Takes (and clears) the counts.
1479-#[cfg(test)]
1480-pub(crate) fn take_partition_hits() -> [usize; 4] {
1481- [0, 1, 2, 3].map(|i| PARTITION_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed))
1482-}
1483-
14841446 /// Whether the trial-set census (`EC_AV1_CENSUS=1`) is on: how many full
14851447 /// rate-distortion trials the block search actually runs, by kind, and where
14861448 /// the winner sat in the cheap SAD ranking the pruning levers rank by. Off by
@@ -2002,12 +1964,6 @@ thread_local! {
20021964 static IBC_SHARE: std::cell::Cell<f64> = const { std::cell::Cell::new(0.0) };
20031965 }
20041966
2005-/// [`IBC_SHARE`] for the last key frame encoded on this thread.
2006-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2007-pub(crate) fn intrabc_source_share() -> f64 {
2008- IBC_SHARE.with(std::cell::Cell::get)
2009-}
2010-
20111967 thread_local! {
20121968 /// This SEQUENCE's `seq_force_screen_content_tools`: whether the sequence
20131969 /// header offers the per-frame `allow_screen_content_tools` bit at all.
@@ -2043,12 +1999,6 @@ thread_local! {
20431999 const { std::cell::Cell::new(None) };
20442000 }
20452001
2046-/// The pyramid the last sequence coded on this thread was EFFECTIVELY under.
2047-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2048-pub(crate) fn last_sequence_pyramid() -> Option<crate::encoder::Pyramid> {
2049- LAST_SEQ_PYRAMID.with(std::cell::Cell::get)
2050-}
2051-
20522002 #[cfg(test)]
20532003 pub(crate) fn force_screen(value: Option<bool>) {
20542004 SCREEN_FORCE.with(|c| c.set(value));
crates/ec-av1/src/encode/more_tests.rsmodified+546 -1231
@@ -1,1260 +1,575 @@
1-use super::*;
21 use super::tests::*;
2+use super::*;
33
4-
5-
6- /// lane-ab128: the 128 root's four AB shapes -- `PARTITION_HORZ_A` (two
7- /// 64x64 on top, one 128x64 below), `_HORZ_B`, `_VERT_A`, `_VERT_B`.
8- /// Five passes over the same `testsrc2` clip
9- /// `a_128_root_horz_and_vert_halves_decode_exact_through_both_decoders`
10- /// uses: each shape forced at every root ([`force_b128_ab`]), so every
11- /// context and every visit order the shape reads is exercised rather than
12- /// the handful the RD would pick, and then an UNFORCED pass whose
13- /// per-shape count is REPORTED (it is the number the gate rows are read
14- /// against).
15- ///
16- /// Each pass is sample-exact against the encoder's own reconstruction
17- /// through `decode_stream` AND through ffmpeg; a writer/reader mismatch
18- /// surfaces here as a refusal or a pixel miss, never in the BD gate. RED
19- /// before this lane by construction: `write_sb128_root` could only name
20- /// NONE / HORZ / VERT / SPLIT, so all four counts were 0.
21- ///
22- /// Runs only inside `superblock_size_global_suite`.
23- pub(super) fn a_128_root_ab_shapes_decode_exact_through_both_decoders() {
24- let _knobs = crate::speed::knob_write();
25- force_sb128(true);
26- let dir = std::env::temp_dir().join(format!("ec-av1-ab128-{}", std::process::id()));
27- std::fs::create_dir_all(&dir).unwrap();
28- let clip = dir.join("testsrc2-1280x768.y4m");
29- let ok = ec_testkit::ffmpeg()
30- .args(["-v", "error", "-y", "-f", "lavfi"])
31- .args(["-i", "testsrc2=size=1280x768:rate=24"])
32- .args(["-frames:v", "12", "-pix_fmt", "yuv420p"])
33- .arg(&clip)
34- .status()
35- .expect("ffmpeg failed to run")
36- .success();
37- assert!(ok, "ffmpeg could not write the synthetic clip");
38- let (width, height) = (1280usize, 768usize);
39- let pictures = crate::probe::source(clip.to_str().unwrap(), "0", "null", width, height, 12);
40- let names = ["HORZ_A", "HORZ_B", "VERT_A", "VERT_B"];
41- let mut unforced = [0usize; 4];
42- for force in [4u8, 5, 6, 7, 0] {
43- force_b128_ab(force);
44- let label = if force == 0 {
45- "unforced"
46- } else {
47- names[usize::from(force) - 4]
48- };
49- let _ = take_b128_ab_hits();
50- let _ = crate::tile::take_sb128_ab_hits();
51- let encoded = encode_sequence(&pictures, 150, 0.5).unwrap();
52- let won = take_b128_ab_hits();
53- let coded = crate::tile::take_sb128_ab_hits();
54- eprintln!(
55- "{label}: search won {won:?} AB roots, writer coded {coded:?} \
56- (HORZ_A/HORZ_B/VERT_A/VERT_B)"
57- );
58- if force == 0 {
59- // The unforced counts are REPORTED, not asserted: a zero here
60- // would be an RD result, not a defect (the four forced passes
61- // already prove the writer and the reader agree on the shape).
62- unforced = won;
63- } else {
64- let i = usize::from(force) - 4;
65- assert!(
66- coded[i] > 0,
67- "no {label} root was coded with {label} forced"
68- );
69- }
70- let decoded = crate::stream::decode_stream(&encoded.stream).expect("our decoder");
71- assert_eq!(decoded.len(), encoded.frames.len(), "{label}: frame count");
72- for (i, (frame, dec)) in encoded.frames.iter().zip(&decoded).enumerate() {
73- for (plane, got, want) in [
74- ("luma", &dec.y, &frame.reconstruction.y),
75- ("U", &dec.u, &frame.reconstruction.u),
76- ("V", &dec.v, &frame.reconstruction.v),
77- ] {
78- let differ = got.iter().zip(want.iter()).filter(|(a, b)| a != b).count();
79- assert_eq!(
80- differ, 0,
81- "{label} frame {i}: {plane} -- {differ} samples differ"
82- );
83- assert_eq!(
84- got.len(),
85- want.len(),
86- "{label} frame {i}: {plane} is {} samples, the reconstruction's is {}",
87- got.len(),
88- want.len()
89- );
90- }
91- }
92- let ff = ffmpeg_decode_sequence(&encoded.stream, width, height, pictures.len());
93- assert_eq!(
94- encoded.frames.len(),
95- ff.len(),
96- "{label}: frame count: ours vs ffmpeg"
97- );
98- for (i, (frame, dec)) in encoded.frames.iter().zip(&ff).enumerate() {
99- assert_eq!(
100- dec.y, frame.reconstruction.y,
101- "{label} frame {i}: ffmpeg luma"
102- );
103- assert_eq!(dec.u, frame.reconstruction.u, "{label} frame {i}: ffmpeg U");
104- assert_eq!(dec.v, frame.reconstruction.v, "{label} frame {i}: ffmpeg V");
105- }
106- }
107- force_b128_ab(0);
108- eprintln!(
109- "unforced on testsrc2 over 12 frames: {} HORZ_A + {} HORZ_B + {} VERT_A + {} VERT_B",
110- unforced[0], unforced[1], unforced[2], unforced[3],
111- );
4+#[test]
5+fn every_frame_of_a_sequence_decodes_through_our_own_decoder() {
6+ let _knobs = crate::speed::knob_read();
7+ let fctx = &crate::decode::FrameCtx::for_encoder();
8+ // 256x128, not the 128x64 this started at: once a leaf could search
9+ // its second reference (lane-av1comp4) the small card's every
10+ // eligible block went to a compound winner, which commits its flat
11+ // transform, and the split below stopped firing on content that
12+ // still splits at every larger size ([[gate-blind-to-feature]] --
13+ // the guard is right, the fixture had shrunk under it).
14+ let (width, height) = (256usize, 128usize);
15+ let pictures: Vec<Picture> = (0..5)
16+ .map(|i| panned_test_card(width, height, i * 3))
17+ .collect();
18+ let _ = take_inter_tx_split_hits();
19+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
20+ let raw = take_inter_tx_split_hits();
21+ // Summed over the four block classes the census keys on (leaf/32x32 x
22+ // single/compound): this assert is about the split firing at all.
23+ let split = [
24+ raw.iter().step_by(2).sum::<usize>(),
25+ raw.iter().skip(1).step_by(2).sum::<usize>(),
26+ ];
27+ eprintln!("inter var-tx: {} blocks flat, {} split", split[0], split[1]);
28+ // [[gate-blind-to-feature]]: with inter `TxMode::Select` on, this
29+ // content splits -- a green round trip in which the split never fires
30+ // would prove only the flat path.
31+ if tx_select() && tx_select_inter() {
32+ assert!(split[1] > 0, "the inter var-tx split never fired");
11233 }
113-
114- #[test]
115- fn every_frame_of_a_sequence_decodes_through_our_own_decoder() {
116- let _knobs = crate::speed::knob_read();
117- let fctx = &crate::decode::FrameCtx::for_encoder();
118- // 256x128, not the 128x64 this started at: once a leaf could search
119- // its second reference (lane-av1comp4) the small card's every
120- // eligible block went to a compound winner, which commits its flat
121- // transform, and the split below stopped firing on content that
122- // still splits at every larger size ([[gate-blind-to-feature]] --
123- // the guard is right, the fixture had shrunk under it).
124- let (width, height) = (256usize, 128usize);
125- let pictures: Vec<Picture> = (0..5)
126- .map(|i| panned_test_card(width, height, i * 3))
127- .collect();
128- let _ = take_inter_tx_split_hits();
129- let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
130- let raw = take_inter_tx_split_hits();
131- // Summed over the four block classes the census keys on (leaf/32x32 x
132- // single/compound): this assert is about the split firing at all.
133- let split = [
134- raw.iter().step_by(2).sum::<usize>(),
135- raw.iter().skip(1).step_by(2).sum::<usize>(),
136- ];
137- eprintln!("inter var-tx: {} blocks flat, {} split", split[0], split[1]);
138- // [[gate-blind-to-feature]]: with inter `TxMode::Select` on, this
139- // content splits -- a green round trip in which the split never fires
140- // would prove only the flat path.
141- if tx_select() && tx_select_inter() {
142- assert!(split[1] > 0, "the inter var-tx split never fired");
143- }
144- let decoded = crate::stream::decode_stream(&encoded.stream).expect("our decoder");
145- assert_eq!(decoded.len(), encoded.frames.len(), "frame count");
146- for (i, (frame, dec)) in encoded.frames.iter().zip(&decoded).enumerate() {
147- let recon = &frame.reconstruction;
148- for (plane, got, want, stride) in [
149- ("luma", &dec.y, &recon.y, width),
150- ("U", &dec.u, &recon.u, width / 2),
151- ("V", &dec.v, &recon.v, width / 2),
152- ] {
153- assert_eq!(got.len(), want.len(), "frame {i}: {plane} size");
154- if let Some(at) = got.iter().zip(want).position(|(a, b)| a != b) {
155- panic!(
156- "frame {i}: {plane} differs first at ({}, {}): decoded {} vs \
34+ let decoded = crate::stream::decode_stream(&encoded.stream).expect("our decoder");
35+ assert_eq!(decoded.len(), encoded.frames.len(), "frame count");
36+ for (i, (frame, dec)) in encoded.frames.iter().zip(&decoded).enumerate() {
37+ let recon = &frame.reconstruction;
38+ for (plane, got, want, stride) in [
39+ ("luma", &dec.y, &recon.y, width),
40+ ("U", &dec.u, &recon.u, width / 2),
41+ ("V", &dec.v, &recon.v, width / 2),
42+ ] {
43+ assert_eq!(got.len(), want.len(), "frame {i}: {plane} size");
44+ if let Some(at) = got.iter().zip(want).position(|(a, b)| a != b) {
45+ panic!(
46+ "frame {i}: {plane} differs first at ({}, {}): decoded {} vs \
15747 reconstruction {} ({} of {} samples differ)",
158- at % stride,
159- at / stride,
160- got[at],
161- want[at],
162- got.iter().zip(want).filter(|(a, b)| a != b).count(),
163- got.len(),
164- );
165- }
166- }
167- }
168- }
169-
170- /// The rate term the mode search ranks every decision by has to be the
171- /// rate the writer then spends. The search prices a block's coefficients
172- /// through `tile::coeff_bits` -- the writer's own symbol chain, but
173- /// against the default CDFs a tile starts from and the contexts of a
174- /// block whose neighbours coded nothing -- while the tile writer codes
175- /// them against a state that has been adapting all frame (the
176- /// price-the-narrowing class). This measures that drift: the sum of what
177- /// the search paid for the coefficients it kept, against the bytes the
178- /// writer actually emitted for the whole tile (which also carries the
179- /// partition/mode/skip/mv syntax the sum leaves out, so the writer is
180- /// expected to be the larger of the two).
181- #[test]
182- fn predicted_coeff_bits_track_the_tile_the_writer_wrote() {
183- let _knobs = crate::speed::knob_read();
184- let fctx = &crate::decode::FrameCtx::for_encoder();
185- let (width, height) = (256usize, 128usize);
186- let pictures: Vec<Picture> = (0..5)
187- .map(|i| panned_test_card(width, height, i * 2))
188- .collect();
189- let _ = take_predicted_bits();
190- let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
191- let predicted = take_predicted_bits();
192- assert_eq!(predicted.len(), encoded.frames.len());
193-
194- eprintln!("frame predicted bits written bits drift");
195- // Split by sign: a NEGATIVE drift is the search OVER-pricing (the
196- // defect this gate exists to catch), a positive one is the written
197- // side carrying syntax the coefficient sum leaves out -- and since
198- // lane-av1mv an extra reference's `NEWMV` puts a whole MV residual
199- // on that side, so the two directions no longer share a bound.
200- let mut worst_over: f64 = 0.0;
201- let mut worst_under: f64 = 0.0;
202- // The census is per CODED frame, so it is zipped in coding order --
203- // which is not display order under a pyramid.
204- let coded: Vec<&Encoded> = encoded
205- .coding_order
206- .iter()
207- .map(|&i| &encoded.frames[i])
208- .collect();
209- for (i, (frame, &bits)) in coded.into_iter().zip(&predicted).enumerate() {
210- let written = frame.tile.len() as f64 * 8.0;
211- let drift = (written - bits) / written;
212- worst_over = worst_over.max(-drift);
213- // lane-av1pyrdef: a pyramid LEAF codes almost no coefficients at
214- // all (150-250 bits of tile, nearly all of it partition/mode/mv
215- // syntax the coefficient sum never counts), so its ratio measures
216- // that floor rather than any drift. Frames under 512 written bits
217- // are left out of the under-price bound for that reason; the
218- // over-price bound -- the defect direction, where the search pays
219- // MORE than the writer -- still covers every frame.
220- if written >= 512.0 {
221- worst_under = worst_under.max(drift);
48+ at % stride,
49+ at / stride,
50+ got[at],
51+ want[at],
52+ got.iter().zip(want).filter(|(a, b)| a != b).count(),
53+ got.len(),
54+ );
22255 }
223- eprintln!(
224- "{i:5} {bits:14.0} {written:12.0} {:+6.2}%",
225- drift * 100.0
226- );
22756 }
228- // Measured 2026-09-06 on this sequence: -13.5% at the key frame,
229- // -8.1%, -3.8%, -2.1%, +1.8% down the inter frames. The search
230- // over-prices every frame but the last (its sum EXCLUDES the
231- // partition/mode/skip/mv syntax the written side carries, so the true
232- // coefficient over-price is larger still): the writer's CDFs adapt to
233- // the content while the search's stay at the defaults. The bound is
234- // set just above the worst measured point -- a widening drift is the
235- // thing this gate exists to catch.
236- assert!(
237- worst_over <= 0.16,
238- "the search's rate term OVER-priced by {:.2}% against the bits the writer spent",
239- worst_over * 100.0
240- );
241- // Measured 2026-09-06 with the extra-reference `NEWMV` in: +18.9% at
242- // the worst inter frame, where nearly every block now codes an MV
243- // residual and a reference the coefficient sum never counts. Re-measured
244- // at +29.6% once the encoder's grid published compound blocks properly
245- // (compound share 8.8% -> 11.5%): a compound block carries a second
246- // reference tree, a compound mode symbol and -- for the half-new modes
247- // -- an MV residual, none of which the coefficient sum counts.
248- // lane-av1txbits: pricing against the tables the frame's writer really
249- // starts from collapses the over-price above to nothing, so the whole
250- // remaining gap is the syntax the coefficient sum leaves out. That is
251- // the default on a non-screen frame since lane-av1price2 (this
252- // fixture is one), and it reads +32.6% here.
253- // lane-av1obmc: every eligible single-reference inter block now also
254- // carries a `motion_mode` symbol the coefficient sum never counts,
255- // and an OBMC block carries the more expensive of the two values --
256- // re-measured at +35.0% here with `EC_AV1_OBMC=1`. Like
257- // `EC_AV1_PRICE_FRAME_CDFS=1` before it, that knob changes encoder
258- // decisions, so this bound and the byte pins above FAIL BY DESIGN
259- // under it; the default path (no motion_mode syntax at all) is the
260- // one they are measured on.
261- // lane-av1pyrdef: `encode_sequence` codes this fixture under the
262- // coding pyramid now, so the five frames are a key frame, a hidden
263- // ALTREF at q-16 and three leaves at q+8: +2.6% / +6.9% (the two
264- // frames over the 512-bit floor) and +44.7 / +74.4 / +74.4 on the
265- // near-empty leaves below it. Both bounds stand where they were.
266- // lane-av1rejudge: local warp is ON by default now, so every eligible
267- // single-reference block carries that same `motion_mode` symbol (a
268- // 3-value alphabet where a warp sample exists) on the DEFAULT path --
269- // +34.9% here, one point past the OBMC reading above. The bound moves
270- // with it; `EC_AV1_WARP=0` restores the +32.6% no-motion_mode number.
271- // lane-av1cfl: a `UV_CFL_PRED` block carries a `cfl_alpha_signs`
272- // symbol and one or two magnitude symbols, none of which the
273- // coefficient sum counts either -- +36.9% here against the same
274- // fixture's +34.9% with `EC_AV1_CFL=0`.
275- // ... and a directional block whose `angle_delta_y` is no longer
276- // always ZERO codes a costlier symbol off the same CDF -- +39.1%.
277- assert!(
278- worst_under <= 0.40,
279- "the writer spent {:.2}% more than the search priced -- more than \
280- the mode/mv syntax outside the coefficient sum explains",
281- worst_under * 100.0
282- );
28357 }
284-
285- /// The census behind step (1) of the pricer lane: for every transform
286- /// block the writer really codes, what the search priced those levels at
287- /// against what the writer spent on them, split by table set and non-zero
288- /// count. One average hides the interesting part -- the classes the
289- /// estimate is systematically wrong about (all-zero blocks, the
290- /// one-coefficient blocks the inter search lives on) -- so the split is
291- /// printed and only the total is asserted on.
292- #[test]
293- fn pricer_error_census_by_block_class() {
294- let _knobs = crate::speed::knob_read();
295- let fctx = &crate::decode::FrameCtx::for_encoder();
296- let (width, height) = (256usize, 128usize);
297- let pictures: Vec<Picture> = (0..5)
298- .map(|i| panned_test_card(width, height, i * 2))
299- .collect();
300- crate::tile::pricer_census_on();
301- let _ = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
302- let rows = crate::tile::take_pricer_census();
303- assert!(!rows.is_empty(), "the census saw no transform block");
304-
305- println!("| set | nz | blocks | priced bits | written bits | error |");
306- println!("|---|---|---|---|---|---|");
307- let (mut priced_all, mut written_all) = (0.0, 0.0);
308- for ((set, bucket), (blocks, priced, written)) in &rows {
309- priced_all += priced;
310- written_all += written;
311- println!(
312- "| {set} | {} | {blocks} | {priced:.0} | {written:.0} | {:+.1}% |",
313- crate::tile::census_bucket_label(*bucket),
314- if *written > 0.0 {
315- (priced - written) / written * 100.0
316- } else {
317- 0.0
318- }
319- );
58+}
59+
60+/// The rate term the mode search ranks every decision by has to be the
61+/// rate the writer then spends. The search prices a block's coefficients
62+/// through `tile::coeff_bits` -- the writer's own symbol chain, but
63+/// against the default CDFs a tile starts from and the contexts of a
64+/// block whose neighbours coded nothing -- while the tile writer codes
65+/// them against a state that has been adapting all frame (the
66+/// price-the-narrowing class). This measures that drift: the sum of what
67+/// the search paid for the coefficients it kept, against the bytes the
68+/// writer actually emitted for the whole tile (which also carries the
69+/// partition/mode/skip/mv syntax the sum leaves out, so the writer is
70+/// expected to be the larger of the two).
71+#[test]
72+fn predicted_coeff_bits_track_the_tile_the_writer_wrote() {
73+ let _knobs = crate::speed::knob_read();
74+ let fctx = &crate::decode::FrameCtx::for_encoder();
75+ let (width, height) = (256usize, 128usize);
76+ let pictures: Vec<Picture> = (0..5)
77+ .map(|i| panned_test_card(width, height, i * 2))
78+ .collect();
79+ let _ = take_predicted_bits();
80+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
81+ let predicted = take_predicted_bits();
82+ assert_eq!(predicted.len(), encoded.frames.len());
83+
84+ eprintln!("frame predicted bits written bits drift");
85+ // Split by sign: a NEGATIVE drift is the search OVER-pricing (the
86+ // defect this gate exists to catch), a positive one is the written
87+ // side carrying syntax the coefficient sum leaves out -- and since
88+ // lane-av1mv an extra reference's `NEWMV` puts a whole MV residual
89+ // on that side, so the two directions no longer share a bound.
90+ let mut worst_over: f64 = 0.0;
91+ let mut worst_under: f64 = 0.0;
92+ // The census is per CODED frame, so it is zipped in coding order --
93+ // which is not display order under a pyramid.
94+ let coded: Vec<&Encoded> = encoded
95+ .coding_order
96+ .iter()
97+ .map(|&i| &encoded.frames[i])
98+ .collect();
99+ for (i, (frame, &bits)) in coded.into_iter().zip(&predicted).enumerate() {
100+ let written = frame.tile.len() as f64 * 8.0;
101+ let drift = (written - bits) / written;
102+ worst_over = worst_over.max(-drift);
103+ // lane-av1pyrdef: a pyramid LEAF codes almost no coefficients at
104+ // all (150-250 bits of tile, nearly all of it partition/mode/mv
105+ // syntax the coefficient sum never counts), so its ratio measures
106+ // that floor rather than any drift. Frames under 512 written bits
107+ // are left out of the under-price bound for that reason; the
108+ // over-price bound -- the defect direction, where the search pays
109+ // MORE than the writer -- still covers every frame.
110+ if written >= 512.0 {
111+ worst_under = worst_under.max(drift);
320112 }
321- println!(
322- "| ALL | | {} | {priced_all:.0} | {written_all:.0} | {:+.1}% |",
323- rows.values().map(|r| r.0).sum::<u64>(),
324- (priced_all - written_all) / written_all * 100.0
113+ eprintln!(
114+ "{i:5} {bits:14.0} {written:12.0} {:+6.2}%",
115+ drift * 100.0
325116 );
326- assert!(written_all > 0.0);
327117 }
328-
329- /// Low motion has to actually buy something: at least one inter frame of
330- /// a panning sequence has to cost fewer bytes than the key frame that
331- /// starts it, and the inter-block share it prints has to be non-zero --
332- /// a search that never picks an inter mode would still pass a rate gate
333- /// on a picture with no motion in it (the class this repo calls
334- /// gate-blind-to-feature), so the share is printed even though it is not
335- /// asserted on beyond being reachable at all.
336- #[test]
337- fn low_motion_makes_an_inter_frame_smaller_than_the_key_frame() {
338- let _knobs = crate::speed::knob_read();
339- let fctx = &crate::decode::FrameCtx::for_encoder();
340- let (width, height) = (256usize, 128usize);
341- let pictures: Vec<Picture> = (0..5)
342- .map(|i| panned_test_card(width, height, i * 2))
343- .collect();
344- let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
345-
346- let key_bytes = encoded.frames[0].stream.len();
347- eprintln!("frame bytes inter share");
348- for (i, frame) in encoded.frames.iter().enumerate() {
349- eprintln!(
350- "{i:5} {:5} {:11.2}",
351- frame.stream.len(),
352- frame.inter_block_share
353- );
354- }
355- assert!(
356- encoded.frames[1..]
357- .iter()
358- .any(|f| f.stream.len() < key_bytes),
359- "no inter frame of a panning sequence beat the key frame's {key_bytes} bytes"
360- );
361- assert!(
362- encoded.frames[1..]
363- .iter()
364- .any(|f| f.inter_block_share > 0.0),
365- "no inter frame coded a single inter block -- the search never fired"
118+ // Measured 2026-09-06 on this sequence: -13.5% at the key frame,
119+ // -8.1%, -3.8%, -2.1%, +1.8% down the inter frames. The search
120+ // over-prices every frame but the last (its sum EXCLUDES the
121+ // partition/mode/skip/mv syntax the written side carries, so the true
122+ // coefficient over-price is larger still): the writer's CDFs adapt to
123+ // the content while the search's stay at the defaults. The bound is
124+ // set just above the worst measured point -- a widening drift is the
125+ // thing this gate exists to catch.
126+ assert!(
127+ worst_over <= 0.16,
128+ "the search's rate term OVER-priced by {:.2}% against the bits the writer spent",
129+ worst_over * 100.0
130+ );
131+ // Measured 2026-09-06 with the extra-reference `NEWMV` in: +18.9% at
132+ // the worst inter frame, where nearly every block now codes an MV
133+ // residual and a reference the coefficient sum never counts. Re-measured
134+ // at +29.6% once the encoder's grid published compound blocks properly
135+ // (compound share 8.8% -> 11.5%): a compound block carries a second
136+ // reference tree, a compound mode symbol and -- for the half-new modes
137+ // -- an MV residual, none of which the coefficient sum counts.
138+ // lane-av1txbits: pricing against the tables the frame's writer really
139+ // starts from collapses the over-price above to nothing, so the whole
140+ // remaining gap is the syntax the coefficient sum leaves out. That is
141+ // the default on a non-screen frame since lane-av1price2 (this
142+ // fixture is one), and it reads +32.6% here.
143+ // lane-av1obmc: every eligible single-reference inter block now also
144+ // carries a `motion_mode` symbol the coefficient sum never counts,
145+ // and an OBMC block carries the more expensive of the two values --
146+ // re-measured at +35.0% here with `EC_AV1_OBMC=1`. Like
147+ // `EC_AV1_PRICE_FRAME_CDFS=1` before it, that knob changes encoder
148+ // decisions, so this bound and the byte pins above FAIL BY DESIGN
149+ // under it; the default path (no motion_mode syntax at all) is the
150+ // one they are measured on.
151+ // lane-av1pyrdef: `encode_sequence` codes this fixture under the
152+ // coding pyramid now, so the five frames are a key frame, a hidden
153+ // ALTREF at q-16 and three leaves at q+8: +2.6% / +6.9% (the two
154+ // frames over the 512-bit floor) and +44.7 / +74.4 / +74.4 on the
155+ // near-empty leaves below it. Both bounds stand where they were.
156+ // lane-av1rejudge: local warp is ON by default now, so every eligible
157+ // single-reference block carries that same `motion_mode` symbol (a
158+ // 3-value alphabet where a warp sample exists) on the DEFAULT path --
159+ // +34.9% here, one point past the OBMC reading above. The bound moves
160+ // with it; `EC_AV1_WARP=0` restores the +32.6% no-motion_mode number.
161+ // lane-av1cfl: a `UV_CFL_PRED` block carries a `cfl_alpha_signs`
162+ // symbol and one or two magnitude symbols, none of which the
163+ // coefficient sum counts either -- +36.9% here against the same
164+ // fixture's +34.9% with `EC_AV1_CFL=0`.
165+ // ... and a directional block whose `angle_delta_y` is no longer
166+ // always ZERO codes a costlier symbol off the same CDF -- +39.1%.
167+ assert!(
168+ worst_under <= 0.40,
169+ "the writer spent {:.2}% more than the search priced -- more than \
170+ the mode/mv syntax outside the coefficient sum explains",
171+ worst_under * 100.0
172+ );
173+}
174+
175+/// Low motion has to actually buy something: at least one inter frame of
176+/// a panning sequence has to cost fewer bytes than the key frame that
177+/// starts it, and the inter-block share it prints has to be non-zero --
178+/// a search that never picks an inter mode would still pass a rate gate
179+/// on a picture with no motion in it (the class this repo calls
180+/// gate-blind-to-feature), so the share is printed even though it is not
181+/// asserted on beyond being reachable at all.
182+#[test]
183+fn low_motion_makes_an_inter_frame_smaller_than_the_key_frame() {
184+ let _knobs = crate::speed::knob_read();
185+ let fctx = &crate::decode::FrameCtx::for_encoder();
186+ let (width, height) = (256usize, 128usize);
187+ let pictures: Vec<Picture> = (0..5)
188+ .map(|i| panned_test_card(width, height, i * 2))
189+ .collect();
190+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
191+
192+ let key_bytes = encoded.frames[0].stream.len();
193+ eprintln!("frame bytes inter share");
194+ for (i, frame) in encoded.frames.iter().enumerate() {
195+ eprintln!(
196+ "{i:5} {:5} {:11.2}",
197+ frame.stream.len(),
198+ frame.inter_block_share
366199 );
367200 }
368-
369- /// `frames` consecutive pictures out of a real clip, scaled to a whole
370- /// number of 32x32 blocks. Generalizes [`clip_frame`]/[`clip_frame_pair`]
371- /// to an arbitrary count for the fixture regression gate below.
372- pub(super) fn clip_frames(
373- clip: &str,
374- skip: &str,
375- width: usize,
376- height: usize,
377- frames: usize,
378- ) -> Vec<Picture> {
379- clip_frames_vf(
380- clip,
381- skip,
382- &format!("scale={width}:{height}"),
383- width,
384- height,
385- frames,
386- )
387- }
388-
389- /// [`clip_frames`] with the filter chain spelled out, so a caller can ask
390- /// for a native-resolution CROP instead of a downscale (the downscale is
391- /// what destroys a screen capture's exact repeats -- class
392- /// `gate-recipe-confound`). `width`/`height` must be what `vf` produces.
393- pub(super) fn clip_frames_vf(
394- clip: &str,
395- skip: &str,
396- vf: &str,
397- width: usize,
398- height: usize,
399- frames: usize,
400- ) -> Vec<Picture> {
401- // ONE definition of the gate's loader recipe, shared with
402- // `examples/enc_probe` so the instrument cannot arm a different source
403- // than the gate it reports on (class `instrument disagrees with the
404- // gate`; lane-probe).
405- crate::probe::source(clip, skip, vf, width, height, frames)
406- }
407-
408- // -----------------------------------------------------------------------
409- // The encoder's standing BD-rate baseline against libaom and rav1e.
410- // Every PSNR below is measured on FFMPEG-DECODED pixels, never on an
411- // encoder's own reconstruction ([[shared-oracle-blindness]]): our decoder
412- // agreeing with our encoder proves nothing about the bitstream.
413- // -----------------------------------------------------------------------
414-
415- /// All-plane PSNR of a decoded picture against its source, on the same
416- /// 8-bit scale [`psnr`] uses.
417- pub(super) fn psnr_all(decoded: &Picture, source: &Picture) -> f64 {
418- let cat = |p: &Picture| {
419- let mut v = Vec::with_capacity(p.y.len() + p.u.len() + p.v.len());
420- v.extend_from_slice(&p.y);
421- v.extend_from_slice(&p.u);
422- v.extend_from_slice(&p.v);
423- v
424- };
425- psnr(&cat(decoded), &cat(source))
426- }
427-
428- /// The pictures back as the planar 8-bit bytes an encoder reads.
429- pub(super) fn raw_yuv420p(source: &[Picture]) -> Vec<u8> {
430- let mut raw = Vec::new();
431- for p in source {
432- for plane in [&p.y, &p.u, &p.v] {
433- raw.extend(plane.iter().map(|&s| s as u8));
434- }
435- }
436- raw
437- }
438-
439- /// A (all-plane PSNR, log10 bytes) ladder from another AV1 encoder driven
440- /// through ffmpeg: one point per entry of `points`, each a quality flag
441- /// set. Returns the ladder ordered by fidelity and the total encode wall
442- /// clock. The stream is decoded back through [`ffmpeg_decode_sequence`],
443- /// so both curves are measured by the same decoder.
444- pub(super) fn external_ladder(
445- source: &[Picture],
446- width: usize,
447- height: usize,
448- encoder: &str,
449- points: &[Vec<String>],
450- ) -> (Vec<(f64, f64)>, f64) {
451- // [[pid-keyed-temp-path]]: parallel test binaries must not share a name.
452- let dir = std::env::temp_dir();
453- let raw_path = dir.join(format!("ec-av1-bd-{}-{encoder}.yuv", std::process::id()));
454- std::fs::write(&raw_path, raw_yuv420p(source)).expect("raw source");
455- let mut ladder = Vec::new();
456- let mut wall = 0.0;
457- for (i, params) in points.iter().enumerate() {
458- let obu = dir.join(format!(
459- "ec-av1-bd-{}-{encoder}-{i}.obu",
460- std::process::id()
461- ));
462- let start = std::time::Instant::now();
463- let out = ec_testkit::ffmpeg()
464- .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"])
465- .args(["-s", &format!("{width}x{height}"), "-r", "24", "-i"])
466- .arg(&raw_path)
467- .args(["-an", "-threads", "1"])
468- .args(["-g", &source.len().to_string(), "-c:v", encoder])
469- .args(params)
470- .args(["-f", "obu"])
471- .arg(&obu).output()
472- .expect("ffmpeg failed to run");
473- wall += start.elapsed().as_secs_f64();
474- assert!(
475- out.status.success(),
476- "{encoder} {params:?}: {}",
477- String::from_utf8_lossy(&out.stderr)
478- );
479- let stream = std::fs::read(&obu).expect("reference stream");
480- let decoded = ffmpeg_decode_sequence(&stream, width, height, source.len());
481- // lane-dkey: every reference point must also decode through OUR
482- // decoder, sample-exact against ffmpeg's decode of the same bytes.
483- // A BD table computed off streams we cannot read is a table about
484- // an encoder we cannot check; this is the assertion that would
485- // have caught the `force_integer_mv` defect (its stream decoded to
486- // 25 dB garbage while this gate stayed green) and the crf-5 key
487- // frame desync. A failure names the encoder, the point's flags and
488- // the first differing frame/plane/sample.
489- // lane-dpm1: a failing reference point is COLLECTED, not panicked
490- // on, so one run still prints the whole BD table and names every
491- // bad point instead of stopping at the first. The collection is
492- // asserted empty by [`assert_ladder_decodes`] at the end of each
493- // gate.
494- match crate::stream::decode_stream(&stream) {
495- Ok(ours) if ours.len() != decoded.len() => note_ladder_failure(format!(
496- "{encoder} {params:?}: our decoder returned {} shown frames, ffmpeg {}",
497- ours.len(),
498- decoded.len(),
499- )),
500- Ok(ours) => {
501- for (f, (o, d)) in ours.iter().zip(&decoded).enumerate() {
502- if let Some((plane, s, got, want)) = first_plane_mismatch(o, d) {
503- note_ladder_failure(format!(
504- "{encoder} {params:?} frame {f} plane {plane} sample {s}: our \
505- decoder decoded {got}, ffmpeg {want}"
506- ));
507- break;
508- }
509- }
510- }
511- Err(e) => note_ladder_failure(format!(
512- "{encoder} {params:?}: our decoder refused the stream ({e})"
513- )),
514- }
515- let mean: f64 = decoded
516- .iter()
517- .zip(source)
518- .map(|(d, s)| psnr_all(d, s))
519- .sum::<f64>()
520- / source.len() as f64;
521- ladder.push((mean, (stream.len() as f64).log10()));
522- let _ = std::fs::remove_file(&obu);
201+ assert!(
202+ encoded.frames[1..]
203+ .iter()
204+ .any(|f| f.stream.len() < key_bytes),
205+ "no inter frame of a panning sequence beat the key frame's {key_bytes} bytes"
206+ );
207+ assert!(
208+ encoded.frames[1..]
209+ .iter()
210+ .any(|f| f.inter_block_share > 0.0),
211+ "no inter frame coded a single inter block -- the search never fired"
212+ );
213+}
214+
215+/// `frames` consecutive pictures out of a real clip, scaled to a whole
216+/// number of 32x32 blocks. Generalizes [`clip_frame`]/[`clip_frame_pair`]
217+/// to an arbitrary count for the fixture regression gate below.
218+pub(super) fn clip_frames(
219+ clip: &str,
220+ skip: &str,
221+ width: usize,
222+ height: usize,
223+ frames: usize,
224+) -> Vec<Picture> {
225+ clip_frames_vf(
226+ clip,
227+ skip,
228+ &format!("scale={width}:{height}"),
229+ width,
230+ height,
231+ frames,
232+ )
233+}
234+
235+/// [`clip_frames`] with the filter chain spelled out, so a caller can ask
236+/// for a native-resolution CROP instead of a downscale (the downscale is
237+/// what destroys a screen capture's exact repeats -- class
238+/// `gate-recipe-confound`). `width`/`height` must be what `vf` produces.
239+pub(super) fn clip_frames_vf(
240+ clip: &str,
241+ skip: &str,
242+ vf: &str,
243+ width: usize,
244+ height: usize,
245+ frames: usize,
246+) -> Vec<Picture> {
247+ // ONE definition of the gate's loader recipe, shared with
248+ // `examples/enc_probe` so the instrument cannot arm a different source
249+ // than the gate it reports on (class `instrument disagrees with the
250+ // gate`; lane-probe).
251+ crate::probe::source(clip, skip, vf, width, height, frames)
252+}
253+
254+// -----------------------------------------------------------------------
255+// The encoder's standing BD-rate baseline against libaom and rav1e.
256+// Every PSNR below is measured on FFMPEG-DECODED pixels, never on an
257+// encoder's own reconstruction ([[shared-oracle-blindness]]): our decoder
258+// agreeing with our encoder proves nothing about the bitstream.
259+// -----------------------------------------------------------------------
260+
261+/// First differing sample between two pictures, as
262+/// `(plane, index, left, right)` -- so a gate failure names the plane and
263+/// the sample instead of just "differs". A length difference counts as a
264+/// mismatch of that plane at the first index past the shorter one.
265+pub(super) fn first_plane_mismatch(
266+ a: &Picture,
267+ b: &Picture,
268+) -> Option<(&'static str, usize, i64, i64)> {
269+ for (plane, l, r) in [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)] {
270+ if let Some(i) = l.iter().zip(r.iter()).position(|(x, y)| x != y) {
271+ return Some((plane, i, i64::from(l[i]), i64::from(r[i])));
523272 }
524- let _ = std::fs::remove_file(&raw_path);
525- ladder.sort_by(|a, b| a.0.total_cmp(&b.0));
526- (ladder, wall)
527- }
528-
529- /// Every reference ladder point that did not decode sample-exactly
530- /// through our own decoder, collected across a whole gate run so the BD
531- /// table still prints and EVERY bad point is named
532- /// (`encoder params frame plane sample`) instead of only the first.
533- static LADDER_FAILURES: std::sync::Mutex<Vec<String>> = std::sync::Mutex::new(Vec::new());
534-
535- pub(super) fn note_ladder_failure(msg: String) {
536- eprintln!("LADDER DECODE FAILURE: {msg}");
537- LADDER_FAILURES.lock().expect("ladder failures").push(msg);
538- }
539-
540- /// Fail the gate at its END on everything [`external_ladder`] collected.
541- pub(super) fn assert_ladder_decodes() {
542- let failures = std::mem::take(&mut *LADDER_FAILURES.lock().expect("ladder failures"));
543- assert!(
544- failures.is_empty(),
545- "{} reference ladder point(s) did not decode exactly through our decoder:\n{}",
546- failures.len(),
547- failures.join("\n"),
548- );
549- }
550-
551- /// First differing sample between two pictures, as
552- /// `(plane, index, left, right)` -- so a gate failure names the plane and
553- /// the sample instead of just "differs". A length difference counts as a
554- /// mismatch of that plane at the first index past the shorter one.
555- pub(super) fn first_plane_mismatch(a: &Picture, b: &Picture) -> Option<(&'static str, usize, i64, i64)> {
556- for (plane, l, r) in [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)] {
557- if let Some(i) = l.iter().zip(r.iter()).position(|(x, y)| x != y) {
558- return Some((plane, i, i64::from(l[i]), i64::from(r[i])));
559- }
560- if l.len() != r.len() {
561- return Some((plane, l.len().min(r.len()), l.len() as i64, r.len() as i64));
562- }
273+ if l.len() != r.len() {
274+ return Some((plane, l.len().min(r.len()), l.len() as i64, r.len() as i64));
563275 }
564- None
565276 }
566-
567- /// The same ladder for this encoder, at four `base_q_idx` points. The PSNR
568- /// comes from ffmpeg's decode of our own stream, and at EVERY point the
569- /// stream is decoded twice -- by ffmpeg and by our own
570- /// [`crate::stream::decode_stream`] -- and all three pictures (encoder
571- /// reconstruction, ffmpeg's decode, our decode) are asserted sample-exact
572- /// in Y, U and V over every shown frame in display order. That is itself
573- /// a gate: it proves the bitstream says what the encoder thinks, in the
574- /// only two decoders that read it.
575- pub(super) fn our_ladder(
576- name: &str,
577- source: &[Picture],
578- width: usize,
579- height: usize,
580- fctx: &crate::decode::FrameCtx,
581- ) -> (Vec<(f64, f64)>, f64) {
582- let mut ladder = Vec::new();
583- let mut wall = 0.0;
584- for &q in &[150u8, 120, 90, 60] {
585- let start = std::time::Instant::now();
586- // lane-rdoq: the deadzone was fitted WITHOUT the RDOQ pass, so
587- // the gate has to be able to re-sweep it. 0.5 is the shipped one
588- // (`crate::encoder::DEADZONE`).
589- let deadzone = std::env::var("EC_AV1_DEADZONE")
590- .ok()
591- .and_then(|v| v.parse().ok())
592- .unwrap_or(0.5);
593- let encoded = encode_sequence_with_ctx(source, q, deadzone, fctx).unwrap();
594- wall += start.elapsed().as_secs_f64();
595- let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, source.len());
596- let ours = crate::stream::decode_stream(&encoded.stream).expect("our decoder");
597- assert_eq!(
598- ours.len(),
599- source.len(),
600- "{name} q={q}: our decoder's display-order frame count"
601- );
602- for (i, (d, e)) in decoded.iter().zip(&encoded.frames).enumerate() {
603- if let Some((plane, s, got, want)) = first_plane_mismatch(d, &e.reconstruction) {
604- panic!(
605- "{name} q={q} frame {i} plane {plane} sample {s}: ffmpeg decoded \
606- {got}, the encoder reconstructed {want}"
607- );
608- }
609- }
610- for (i, (o, e)) in ours.iter().zip(&encoded.frames).enumerate() {
611- if let Some((plane, s, got, want)) = first_plane_mismatch(o, &e.reconstruction) {
612- panic!(
613- "{name} q={q} frame {i} plane {plane} sample {s}: our decoder decoded \
614- {got}, the encoder reconstructed {want}"
615- );
616- }
617- }
618- let per_frame: Vec<f64> = decoded
619- .iter()
620- .zip(source)
621- .map(|(d, s)| psnr_all(d, s))
622- .collect();
623- // lane-txrd: does a tool's loss start at the FIRST inter frame
624- // (a local mispricing) or grow down the GOP (propagation into
625- // the reference chain)? One line per q point answers it.
626- if crate::envflags::env_flag!("EC_AV1_FRAME_PSNR") {
627- let row: Vec<String> = per_frame.iter().map(|p| format!("{p:.2}")).collect();
628- eprintln!("{name}: q={q} per-frame PSNR {}", row.join(" "));
629- // lane-txrd: per PLANE, because an all-plane mean hides a
630- // collapse in one of them (class `metric blind to a plane`).
631- let plane = |pick: fn(&Picture) -> &Vec<u16>| -> String {
632- let v: Vec<String> = decoded
633- .iter()
634- .zip(source)
635- .map(|(d, s)| format!("{:.2}", psnr(pick(d), pick(s))))
636- .collect();
637- v.join(" ")
638- };
639- eprintln!("{name}: q={q} Y {}", plane(|p| &p.y));
640- eprintln!("{name}: q={q} U {}", plane(|p| &p.u));
641- eprintln!("{name}: q={q} V {}", plane(|p| &p.v));
642- }
643- let mean: f64 = per_frame.iter().sum::<f64>() / source.len() as f64;
644- ladder.push((mean, (encoded.stream.len() as f64).log10()));
645- }
646- // What this clip asked for and what the content gate left it coding
647- // under: a screen clip requests a pyramid and codes flat, and that
648- // difference is what keeps its row identical to the flat baseline
649- // (class `gate-blind-to-feature`).
650- eprintln!(
651- "{name}: sequence, pyramid requested {:?} effective {:?}",
652- crate::encoder::Pyramid::from_env(),
653- last_sequence_pyramid(),
654- );
655- ladder.sort_by(|a, b| a.0.total_cmp(&b.0));
656- (ladder, wall)
277+ None
278+}
279+
280+/// Byte-exactness gate for encoder work that is meant to change only
281+/// how long the encoder takes.
282+///
283+/// The BD gate above measures quality, which a speed lane can move by a
284+/// hair without failing anything; this pins the streams themselves.
285+/// Re-measured on the lane-av1lr merge with main d5fc99e0 (per-64x64
286+/// `cdef_idx` literals and per-unit loop restoration syntax are new bits
287+/// in the tile) and again on lane-av1mv's merge of it: an extra
288+/// reference's `NEWMV` is a coded-bits change too, judged by the BD gate
289+/// above, not by this pin. Re-pinned on lane-av1price2: the search now
290+/// prices coefficients against the tables the frame's writer really
291+/// starts from on every non-screen frame (`tile::arm_pricing_cdfs`), a
292+/// decision change the BD gate judges. Re-pinned again on
293+/// lane-av1skipctx: the search now prices `txb_skip`/`dc_sign` at the
294+/// real neighbour contexts ([`Plane::coef_ctx`]) instead of zero, which
295+/// is the same kind of decision change. Re-pinned on lane-av1lambda:
296+/// [`LAMBDA_SCALE`] moved 0.1 -> 0.05, so every RD decision in the
297+/// search moved with it. Re-pinned on lane-av1rejudge: local warp is on
298+/// by default ([`warp_on`], a sequence/frame header bit and a new
299+/// motion_mode symbol on eligible blocks) and
300+/// [`LEAF_SECOND_NEW_MARGIN`] moved 0.8 -> 1.2. Re-pinned on lane-av1tpl:
301+/// every inter frame's superblocks now code at their own lambda
302+/// ([`TPL_STRENGTH`]), so every RD decision in an inter frame moved.
303+/// Re-pinned on lane-av1resweep: [`LAMBDA_SCALE`] moved 0.05 -> 0.0275
304+/// and the two var-tx depth searches ([`tx32_depth_search`],
305+/// [`compound_var_tx`]) are on by default, all three re-judged on the
306+/// native gate's real film rows.
307+/// Re-pinned on lane-av1cfl: the chroma search offers `UV_CFL_PRED`, so
308+/// every block whose chroma takes it codes a different mode symbol, two
309+/// alpha symbols and different chroma coefficients. `EC_AV1_CFL=0`
310+/// restores the previous streams. Re-pinned again in the same lane once
311+/// directional luma winners searched their `angle_delta_y`
312+/// (`EC_AV1_ANGLE=0` restores that half).
313+#[test]
314+fn the_encoders_own_streams_are_byte_identical_to_their_pins() {
315+ // These are DEFAULT-PRESET pins: a speed preset switches search levers
316+ // off, so it legitimately moves every byte. Encode at speed 0 whatever
317+ // `EC_AV1_SPEED` says (write guard: the preset is process-global).
318+ let _knobs = crate::speed::knob_write();
319+ let was = crate::speed::speed();
320+ crate::speed::set_speed(0);
321+ // lane-av1clipprobe: the bare `clip.exists()` -> SKIP had no env escape,
322+ // so a tree with no root `fixtures/` reported this gate green having
323+ // compared nothing at all.
324+ let clip = ec_testkit::fixture("open/sintel_trailer-1080p.mp4");
325+ let source = clip_frames(clip.to_str().unwrap(), "20", 640, 384, 4);
326+ // FNV-1a over the stream: a witness that every coded bit is where it
327+ // was, which a byte count alone is not.
328+ let fnv = |b: &[u8]| {
329+ b.iter().fold(0xcbf2_9ce4_8422_2325u64, |h, &v| {
330+ (h ^ u64::from(v)).wrapping_mul(0x0000_0100_0000_01b3)
331+ })
332+ };
333+ // Re-taken on lane-av1pyrdef: `encode_sequence` codes this (non-screen)
334+ // clip under the coding pyramid now -- one hidden ALTREF per mini-GOP
335+ // of 4, its leaves at q+8 and a `show_existing_frame` header per
336+ // group. 7299 -> 8194 bytes at q=150 and 26804 -> 28285 at q=60 over
337+ // four frames; four pictures is one short mini-GOP, which is the
338+ // shape that pays least (the ARF's own quality has no later group to
339+ // carry it), so this is not the BD gate's number.
340+ // Re-taken again on lane-av1cfl: the chroma search offers
341+ // `UV_CFL_PRED` and directional luma winners search `angle_delta_y`,
342+ // so every block taking either codes different syntax and different
343+ // coefficients -- 8194 -> 7321 at q=150 and 28285 -> 27285 at q=60.
344+ // `EC_AV1_CFL=0` / `EC_AV1_ANGLE=0` restore each half.
345+ // Re-taken on lane-pyr3: the mini-GOP of the default pyramid is 16
346+ // pictures at `q-24` / `q+16` now (the sweep in [`Pyramid::default`]),
347+ // so these four pictures code as one truncated group -- a hidden
348+ // ALTREF at `q-24` and three leaves at `q+16` -- instead of one
349+ // mini-GOP of 4 at `q-16` / `q+8`: 7373 -> 8076 at q=150 and
350+ // 27074 -> 27585 at q=60. `EC_AV1_PYRAMID=4:-16:8` restores these.
351+ // Re-taken on lane-fintra: the sequence header sets
352+ // `enable_filter_intra`, so every DC_PRED intra block of at most
353+ // 32x32 without a luma palette carries a `use_filter_intra` flag and
354+ // the blocks that take one code a filter-intra mode, a different
355+ // prediction and different coefficients -- 7321 -> 7373 at q=150 and
356+ // 27285 -> 27074 at q=60. `EC_AV1_FILTER_INTRA=0` restores these.
357+ // Re-taken on lane-b64 (64x64 skip root), at the lane-pyr4 merge
358+ // (default pyramid `8:-32:16`, one truncated group of 8 with its
359+ // hidden ALTREF at `q-32`), and at the lane-tx64 merge: the 64x64
360+ // root can code a REAL residual now (one TX_64X64 luma transform and
361+ // two TX_32X32 chroma ones). `EC_AV1_B64RES=0` restores 8446 / 28548;
362+ // `EC_AV1_B64=0` gives the pre-root bytes under this pyramid.
363+ // Re-taken on lane-keyq: the pyramid codes its KEY FRAME at
364+ // `base_q - 48` now ([`crate::encoder::Pyramid::key_q_offset`]), and
365+ // one of these four pictures is the key -- 8590 -> 9778 at q=150 and
366+ // 28535 -> 35450 at q=60. `EC_AV1_PYRAMID=8:-32:16:-8:0` restores these.
367+ // Re-taken on lane-arfq: the leaves are coded 12 quantizer steps above
368+ // base now, not 16 ([`crate::encoder::Pyramid::leaf_q_offset`]) -- 9778
369+ // -> 9835 at q=150 and 35450 -> 35798 at q=60.
370+ // `EC_AV1_PYRAMID=8:-32:16:-8:-48` restores these.
371+ // Re-taken at the lane-b64b merge, the lane-rdoq merge (`EC_AV1_RDOQ=0`
372+ // gave 9808 / 35791) and the lane-i64 merge: the KEY frame -- one of
373+ // these four pictures -- offers every superblock a 64x64 intra root
374+ // now. `EC_AV1_I64=0` restores 8557 / 33345.
375+ // Re-taken on lane-pricer: the inter RD search prices a single
376+ // reference through the tree and the neighbour contexts the writer
377+ // really codes it with, so every inter picture's reference decisions
378+ // move -- 8562 -> 8535 at q=150 and 33357 -> 33221 at q=60.
379+ // Re-taken on lane-ctx: the RD pricer reads the writer's own contexts
380+ // for `skip`/`is_inter` and for the whole compound reference tree, so
381+ // every inter block's cost -- and with it the skip and reference
382+ // decisions -- moved: 8535 -> 8311 bytes at q=150 and 33221 -> 33087
383+ // at q=60. Re-taken on lane-ctx2: a single-reference candidate now
384+ // pays the `comp_mode = 0` symbol the writer codes ahead of it, so
385+ // single and compound are priced against the same syntax -- 8311 ->
386+ // 8325 bytes at q=150 and 33087 -> 33014 at q=60.
387+ // Re-taken on lane-newmv: the motion search charges its own rate term
388+ // at half the block RD lambda ([`crate::motion::MV_SEARCH_LAMBDA`])
389+ // and each subpel stage re-runs from its own winner
390+ // ([`crate::motion::MV_SUBPEL_ITERS`]), so every inter block's vector
391+ // -- and with it its residual -- moved: 8325 -> 8288 bytes at q=150
392+ // and 33014 -> 33090 at q=60.
393+ // Re-taken on lane-dq: preset 0 codes a per-superblock `delta_qindex`
394+ // from libaom's objective tpl mapping, so every inter picture's
395+ // quantizer grid -- and every decision priced against it -- moved
396+ // (8325 -> 8419 / 33014 -> 33029 on its own base); re-taken once more
397+ // at the merge of both lanes.
398+ // Re-taken on lane-arfq: the top ARF of a mini-GOP codes its
399+ // per-superblock `delta_qindex` at 1.5x the preset's strength
400+ // ([`crate::speed::DQ_LEVEL_K`]), so the hidden frames' quantizer
401+ // grids -- and every decision priced against them -- moved:
402+ // 8252 -> 8269 bytes at q=150 and 33053 -> 33044 at q=60.
403+ // Re-taken on lane-arfpred: the top ARF is coded from a temporally
404+ // FILTERED source ([`crate::speed::ARF_TF`]), so every hidden frame's
405+ // pixels -- and the leaves that predict from them -- moved:
406+ // 8269 -> 8218 bytes at q=150 and 33044 -> 33017 at q=60.
407+ // NOT re-taken on lane-b128: [`SB128_DEFAULT`] stayed off there, so
408+ // the shipped stream did not move.
409+ // Re-taken on lane-b128m, which flips [`SB128_DEFAULT`] on: every
410+ // picture is coded in 128x128 superblocks now, the inter ones
411+ // offering the 128 root's own `PARTITION_NONE` block -- 8327 bytes at
412+ // q=150 and 33194 at q=60. `EC_AV1_SB128=0` restores 8252 / 33053.
413+ // Re-taken at the merge of lane-b128m onto main (128 superblocks on
414+ // by default, on top of the ARF temporal filter).
415+ // Re-taken on lane-b128r: the 128 root now offers the COMPOUND
416+ // candidates the 64 root already did ([`b128_compound`]), so every
417+ // inter frame that carries `reference_select` codes different blocks
418+ // -- 8354 -> 8364 bytes at q=150 and 33222 -> 33257 at q=60.
419+ // `EC_AV1_B128COMP=0` restores 8354 / 33222 exactly.
420+ // Re-taken on lane-arftf: that filter's strength swept on the deciding
421+ // gate lands at 2, not 3 ([`crate::speed::ARF_TF`]), so the filtered
422+ // anchors' pixels moved once more: 8218 -> 8307 bytes at q=150 and
423+ // 33017 at q=60 (the same LENGTH, different bytes).
424+ // Re-taken at the merge of lane-arftf (ARF filter strength 2) and
425+ // lane-rlclamp onto the 128 compound default.
426+ // Re-taken on lane-b128hv: the 128 root now also offers PARTITION_HORZ
427+ // and PARTITION_VERT ([`b128_rect`]), two 128x64 / 64x128 skip blocks,
428+ // so every inter frame whose RD takes one codes a different partition
429+ // -- 8290 -> 8291 bytes at q=150. The q=60 pin does NOT move: at that
430+ // quantizer the rect cut never wins its own comparison on this clip.
431+ // `EC_AV1_B128HV=0` restores 8290 exactly.
432+ let pins: [(u8, usize, u64); 2] = [
433+ (150, 23666, 11535713837929557386),
434+ (60, 102035, 3886390906684528357),
435+ ];
436+ let coded: Vec<(u8, usize, u64)> = pins
437+ .iter()
438+ .map(|&(q, _, _)| {
439+ let e = encode_sequence(&source, q, 0.5).unwrap();
440+ (q, e.stream.len(), fnv(&e.stream))
441+ })
442+ .collect();
443+ crate::speed::set_speed(was);
444+ for (&(q, bytes, hash), &got) in pins.iter().zip(&coded) {
445+ assert_eq!(got, (q, bytes, hash), "q={q}: the encoder's stream moved");
657446 }
658-
659- /// [`our_ladder`] through the streaming facade — the surface the editor's
660- /// export drives (`EC_AV1_GATE_FACADE=1`). With a [`crate::encoder::Pyramid`]
661- /// each stream is also reordered (hidden `ALTREF` first,
662- /// `show_existing_frame` last per group) and each level is coded at its
663- /// own quantizer offset; without one it is the flat ladder, which
664- /// `encoder::tests::the_facade_codes_the_same_bytes_as_encode_sequence`
665- /// pins byte-identical to [`our_ladder`]'s, so this arm must print the
666- /// same BD numbers. Returns the ladder, the wall, per pyramid level over
667- /// the whole ladder how many frames and how many bytes it spent, and the
668- /// pyramid the streams were EFFECTIVELY coded under — the content gate in
669- /// `Av1Encoder::encode_frames` drops a screen-content clip back to the
670- /// flat path, so a requested pyramid can come back `None` here.
671- pub(super) fn our_ladder_facade(
672- name: &str,
673- source: &[Picture],
674- width: usize,
675- height: usize,
676- pyramid: Option<crate::encoder::Pyramid>,
677- ) -> (
678- Vec<(f64, f64)>,
679- f64,
680- [usize; 4],
681- [usize; 4],
682- Option<crate::encoder::Pyramid>,
683- ) {
684- use crate::encoder::{Av1Encoder, Colour, EncoderConfig, Level};
685- let slot = |l: Level| match l {
686- Level::Key => 0,
687- Level::Arf => 1,
688- Level::Leaf => 2,
689- Level::ShowExisting => 3,
690- };
691- let mut ladder = Vec::new();
692- let mut wall = 0.0;
693- let mut effective = None;
694- let (mut counts, mut bytes) = ([0usize; 4], [0usize; 4]);
695- for &q in &[150u8, 120, 90, 60] {
696- let config = EncoderConfig {
697- width,
698- height,
699- base_q_idx: q,
700- gop: source.len(),
701- colour: Colour::Unspecified,
702- tile_cols_log2: 0,
703- tile_rows_log2: 0,
704- };
705- let start = std::time::Instant::now();
706- let mut enc = match pyramid {
707- None => Av1Encoder::new(config).unwrap(),
708- Some(p) => Av1Encoder::with_pyramid(config, p).unwrap(),
709- };
710- let mut packets = Vec::new();
711- for picture in source {
712- packets.extend(enc.encode_frames(picture).unwrap());
713- }
714- packets.extend(enc.flush().unwrap());
715- wall += start.elapsed().as_secs_f64();
716- effective = enc.pyramid();
717- let mut stream = Vec::new();
718- for p in &packets {
719- counts[slot(p.level)] += 1;
720- bytes[slot(p.level)] += p.data.len();
721- stream.extend_from_slice(&p.data);
722- }
723- // [[gate-blind-to-hidden-frames]]: a reordered stream is only
724- // correct if the DISPLAY-order output still has one frame per
725- // source picture, in the right order -- checked against our own
726- // decoder as well as ffmpeg's, both below.
727- let ours = crate::stream::decode_stream(&stream).expect("our decoder");
447+}
448+
449+/// lane-refs: THE FRAME FILTER REACHES THE PIXELS. `mc::predict` used to
450+/// hardwire the REGULAR kernel, so the encoder could not have coded a
451+/// SMOOTH or SHARP frame even if the header had said so -- the search,
452+/// the trials, the recon and the frame header now all read
453+/// `FrameCtx::interp_filter`. Each of the three kernels codes its own
454+/// distinct stream (a filter that never reached the prediction would code
455+/// the same bytes as REGULAR, class `symbol consumption gap`), and ffmpeg
456+/// reconstructs every frame of each of them exactly, which is what proves
457+/// the header and the prediction agree.
458+#[test]
459+fn each_frame_interpolation_filter_codes_its_own_stream_ffmpeg_decodes_exactly() {
460+ let _knobs = crate::speed::knob_write();
461+ let (width, height) = (256usize, 128usize);
462+ // A HALF-PEL pan: an integer-pel one reads no filter tap at all, so
463+ // all three kernels would code the same bytes and the test would pass
464+ // on a wiring that does nothing (class `fixture proves the symbol, not
465+ // the signal`). `panned_test_card` shifts by whole pixels, so the
466+ // search finds the sub-pel positions off the reconstruction instead:
467+ // three frames of a slow diagonal pan.
468+ let pictures: Vec<Picture> = (0..3)
469+ .map(|i| panned_test_card(width, height, i * 3))
470+ .collect();
471+ let mut streams = Vec::new();
472+ for filter in [
473+ ec_av1_syntax::InterpolationFilter::Eighttap,
474+ ec_av1_syntax::InterpolationFilter::EighttapSmooth,
475+ ec_av1_syntax::InterpolationFilter::EighttapSharp,
476+ ] {
477+ set_frame_interp(Some(filter));
478+ let fctx = &crate::decode::FrameCtx::for_encoder();
479+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx)
480+ .unwrap_or_else(|e| panic!("{filter:?}: {e}"));
481+ let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, 3);
482+ assert_eq!(decoded.len(), 3, "{filter:?}: decoded frame count");
483+ for (i, (frame, decoded)) in encoded.frames.iter().zip(&decoded).enumerate() {
728484 assert_eq!(
729- ours.len(),
730- source.len(),
731- "{name} q={q}: our display-order count"
732- );
733- let decoded = ffmpeg_decode_sequence(&stream, width, height, source.len());
734- for (i, (d, o)) in decoded.iter().zip(&ours).enumerate() {
735- if let Some((plane, s, got, want)) = first_plane_mismatch(d, o) {
736- panic!(
737- "{name} q={q} display frame {i} plane {plane} sample {s}: ffmpeg \
738- decoded {got}, our decoder decoded {want}"
739- );
740- }
741- }
742- let mean: f64 = decoded
743- .iter()
744- .zip(source)
745- .map(|(d, s)| psnr_all(d, s))
746- .sum::<f64>()
747- / source.len() as f64;
748- ladder.push((mean, (stream.len() as f64).log10()));
749- }
750- ladder.sort_by(|a, b| a.0.total_cmp(&b.0));
751- (ladder, wall, counts, bytes, effective)
752- }
753-
754- /// Byte-exactness gate for encoder work that is meant to change only
755- /// how long the encoder takes.
756- ///
757- /// The BD gate above measures quality, which a speed lane can move by a
758- /// hair without failing anything; this pins the streams themselves.
759- /// Re-measured on the lane-av1lr merge with main d5fc99e0 (per-64x64
760- /// `cdef_idx` literals and per-unit loop restoration syntax are new bits
761- /// in the tile) and again on lane-av1mv's merge of it: an extra
762- /// reference's `NEWMV` is a coded-bits change too, judged by the BD gate
763- /// above, not by this pin. Re-pinned on lane-av1price2: the search now
764- /// prices coefficients against the tables the frame's writer really
765- /// starts from on every non-screen frame (`tile::arm_pricing_cdfs`), a
766- /// decision change the BD gate judges. Re-pinned again on
767- /// lane-av1skipctx: the search now prices `txb_skip`/`dc_sign` at the
768- /// real neighbour contexts ([`Plane::coef_ctx`]) instead of zero, which
769- /// is the same kind of decision change. Re-pinned on lane-av1lambda:
770- /// [`LAMBDA_SCALE`] moved 0.1 -> 0.05, so every RD decision in the
771- /// search moved with it. Re-pinned on lane-av1rejudge: local warp is on
772- /// by default ([`warp_on`], a sequence/frame header bit and a new
773- /// motion_mode symbol on eligible blocks) and
774- /// [`LEAF_SECOND_NEW_MARGIN`] moved 0.8 -> 1.2. Re-pinned on lane-av1tpl:
775- /// every inter frame's superblocks now code at their own lambda
776- /// ([`TPL_STRENGTH`]), so every RD decision in an inter frame moved.
777- /// Re-pinned on lane-av1resweep: [`LAMBDA_SCALE`] moved 0.05 -> 0.0275
778- /// and the two var-tx depth searches ([`tx32_depth_search`],
779- /// [`compound_var_tx`]) are on by default, all three re-judged on the
780- /// native gate's real film rows.
781- /// Re-pinned on lane-av1cfl: the chroma search offers `UV_CFL_PRED`, so
782- /// every block whose chroma takes it codes a different mode symbol, two
783- /// alpha symbols and different chroma coefficients. `EC_AV1_CFL=0`
784- /// restores the previous streams. Re-pinned again in the same lane once
785- /// directional luma winners searched their `angle_delta_y`
786- /// (`EC_AV1_ANGLE=0` restores that half).
787- #[test]
788- fn the_encoders_own_streams_are_byte_identical_to_their_pins() {
789- // These are DEFAULT-PRESET pins: a speed preset switches search levers
790- // off, so it legitimately moves every byte. Encode at speed 0 whatever
791- // `EC_AV1_SPEED` says (write guard: the preset is process-global).
792- let _knobs = crate::speed::knob_write();
793- let was = crate::speed::speed();
794- crate::speed::set_speed(0);
795- // lane-av1clipprobe: the bare `clip.exists()` -> SKIP had no env escape,
796- // so a tree with no root `fixtures/` reported this gate green having
797- // compared nothing at all.
798- let clip = ec_testkit::fixture("open/sintel_trailer-1080p.mp4");
799- let source = clip_frames(clip.to_str().unwrap(), "20", 640, 384, 4);
800- // FNV-1a over the stream: a witness that every coded bit is where it
801- // was, which a byte count alone is not.
802- let fnv = |b: &[u8]| {
803- b.iter().fold(0xcbf2_9ce4_8422_2325u64, |h, &v| {
804- (h ^ u64::from(v)).wrapping_mul(0x0000_0100_0000_01b3)
805- })
806- };
807- // Re-taken on lane-av1pyrdef: `encode_sequence` codes this (non-screen)
808- // clip under the coding pyramid now -- one hidden ALTREF per mini-GOP
809- // of 4, its leaves at q+8 and a `show_existing_frame` header per
810- // group. 7299 -> 8194 bytes at q=150 and 26804 -> 28285 at q=60 over
811- // four frames; four pictures is one short mini-GOP, which is the
812- // shape that pays least (the ARF's own quality has no later group to
813- // carry it), so this is not the BD gate's number.
814- // Re-taken again on lane-av1cfl: the chroma search offers
815- // `UV_CFL_PRED` and directional luma winners search `angle_delta_y`,
816- // so every block taking either codes different syntax and different
817- // coefficients -- 8194 -> 7321 at q=150 and 28285 -> 27285 at q=60.
818- // `EC_AV1_CFL=0` / `EC_AV1_ANGLE=0` restore each half.
819- // Re-taken on lane-pyr3: the mini-GOP of the default pyramid is 16
820- // pictures at `q-24` / `q+16` now (the sweep in [`Pyramid::default`]),
821- // so these four pictures code as one truncated group -- a hidden
822- // ALTREF at `q-24` and three leaves at `q+16` -- instead of one
823- // mini-GOP of 4 at `q-16` / `q+8`: 7373 -> 8076 at q=150 and
824- // 27074 -> 27585 at q=60. `EC_AV1_PYRAMID=4:-16:8` restores these.
825- // Re-taken on lane-fintra: the sequence header sets
826- // `enable_filter_intra`, so every DC_PRED intra block of at most
827- // 32x32 without a luma palette carries a `use_filter_intra` flag and
828- // the blocks that take one code a filter-intra mode, a different
829- // prediction and different coefficients -- 7321 -> 7373 at q=150 and
830- // 27285 -> 27074 at q=60. `EC_AV1_FILTER_INTRA=0` restores these.
831- // Re-taken on lane-b64 (64x64 skip root), at the lane-pyr4 merge
832- // (default pyramid `8:-32:16`, one truncated group of 8 with its
833- // hidden ALTREF at `q-32`), and at the lane-tx64 merge: the 64x64
834- // root can code a REAL residual now (one TX_64X64 luma transform and
835- // two TX_32X32 chroma ones). `EC_AV1_B64RES=0` restores 8446 / 28548;
836- // `EC_AV1_B64=0` gives the pre-root bytes under this pyramid.
837- // Re-taken on lane-keyq: the pyramid codes its KEY FRAME at
838- // `base_q - 48` now ([`crate::encoder::Pyramid::key_q_offset`]), and
839- // one of these four pictures is the key -- 8590 -> 9778 at q=150 and
840- // 28535 -> 35450 at q=60. `EC_AV1_PYRAMID=8:-32:16:-8:0` restores these.
841- // Re-taken on lane-arfq: the leaves are coded 12 quantizer steps above
842- // base now, not 16 ([`crate::encoder::Pyramid::leaf_q_offset`]) -- 9778
843- // -> 9835 at q=150 and 35450 -> 35798 at q=60.
844- // `EC_AV1_PYRAMID=8:-32:16:-8:-48` restores these.
845- // Re-taken at the lane-b64b merge, the lane-rdoq merge (`EC_AV1_RDOQ=0`
846- // gave 9808 / 35791) and the lane-i64 merge: the KEY frame -- one of
847- // these four pictures -- offers every superblock a 64x64 intra root
848- // now. `EC_AV1_I64=0` restores 8557 / 33345.
849- // Re-taken on lane-pricer: the inter RD search prices a single
850- // reference through the tree and the neighbour contexts the writer
851- // really codes it with, so every inter picture's reference decisions
852- // move -- 8562 -> 8535 at q=150 and 33357 -> 33221 at q=60.
853- // Re-taken on lane-ctx: the RD pricer reads the writer's own contexts
854- // for `skip`/`is_inter` and for the whole compound reference tree, so
855- // every inter block's cost -- and with it the skip and reference
856- // decisions -- moved: 8535 -> 8311 bytes at q=150 and 33221 -> 33087
857- // at q=60. Re-taken on lane-ctx2: a single-reference candidate now
858- // pays the `comp_mode = 0` symbol the writer codes ahead of it, so
859- // single and compound are priced against the same syntax -- 8311 ->
860- // 8325 bytes at q=150 and 33087 -> 33014 at q=60.
861- // Re-taken on lane-newmv: the motion search charges its own rate term
862- // at half the block RD lambda ([`crate::motion::MV_SEARCH_LAMBDA`])
863- // and each subpel stage re-runs from its own winner
864- // ([`crate::motion::MV_SUBPEL_ITERS`]), so every inter block's vector
865- // -- and with it its residual -- moved: 8325 -> 8288 bytes at q=150
866- // and 33014 -> 33090 at q=60.
867- // Re-taken on lane-dq: preset 0 codes a per-superblock `delta_qindex`
868- // from libaom's objective tpl mapping, so every inter picture's
869- // quantizer grid -- and every decision priced against it -- moved
870- // (8325 -> 8419 / 33014 -> 33029 on its own base); re-taken once more
871- // at the merge of both lanes.
872- // Re-taken on lane-arfq: the top ARF of a mini-GOP codes its
873- // per-superblock `delta_qindex` at 1.5x the preset's strength
874- // ([`crate::speed::DQ_LEVEL_K`]), so the hidden frames' quantizer
875- // grids -- and every decision priced against them -- moved:
876- // 8252 -> 8269 bytes at q=150 and 33053 -> 33044 at q=60.
877- // Re-taken on lane-arfpred: the top ARF is coded from a temporally
878- // FILTERED source ([`crate::speed::ARF_TF`]), so every hidden frame's
879- // pixels -- and the leaves that predict from them -- moved:
880- // 8269 -> 8218 bytes at q=150 and 33044 -> 33017 at q=60.
881- // NOT re-taken on lane-b128: [`SB128_DEFAULT`] stayed off there, so
882- // the shipped stream did not move.
883- // Re-taken on lane-b128m, which flips [`SB128_DEFAULT`] on: every
884- // picture is coded in 128x128 superblocks now, the inter ones
885- // offering the 128 root's own `PARTITION_NONE` block -- 8327 bytes at
886- // q=150 and 33194 at q=60. `EC_AV1_SB128=0` restores 8252 / 33053.
887- // Re-taken at the merge of lane-b128m onto main (128 superblocks on
888- // by default, on top of the ARF temporal filter).
889- // Re-taken on lane-b128r: the 128 root now offers the COMPOUND
890- // candidates the 64 root already did ([`b128_compound`]), so every
891- // inter frame that carries `reference_select` codes different blocks
892- // -- 8354 -> 8364 bytes at q=150 and 33222 -> 33257 at q=60.
893- // `EC_AV1_B128COMP=0` restores 8354 / 33222 exactly.
894- // Re-taken on lane-arftf: that filter's strength swept on the deciding
895- // gate lands at 2, not 3 ([`crate::speed::ARF_TF`]), so the filtered
896- // anchors' pixels moved once more: 8218 -> 8307 bytes at q=150 and
897- // 33017 at q=60 (the same LENGTH, different bytes).
898- // Re-taken at the merge of lane-arftf (ARF filter strength 2) and
899- // lane-rlclamp onto the 128 compound default.
900- // Re-taken on lane-b128hv: the 128 root now also offers PARTITION_HORZ
901- // and PARTITION_VERT ([`b128_rect`]), two 128x64 / 64x128 skip blocks,
902- // so every inter frame whose RD takes one codes a different partition
903- // -- 8290 -> 8291 bytes at q=150. The q=60 pin does NOT move: at that
904- // quantizer the rect cut never wins its own comparison on this clip.
905- // `EC_AV1_B128HV=0` restores 8290 exactly.
906- let pins: [(u8, usize, u64); 2] = [
907- (150, 23666, 11535713837929557386),
908- (60, 102035, 3886390906684528357),
909- ];
910- let coded: Vec<(u8, usize, u64)> = pins
911- .iter()
912- .map(|&(q, _, _)| {
913- let e = encode_sequence(&source, q, 0.5).unwrap();
914- (q, e.stream.len(), fnv(&e.stream))
915- })
916- .collect();
917- crate::speed::set_speed(was);
918- for (&(q, bytes, hash), &got) in pins.iter().zip(&coded) {
919- assert_eq!(got, (q, bytes, hash), "q={q}: the encoder's stream moved");
920- }
921- }
922-
923- /// A ladder is only a ladder if both axes rise together.
924- pub(super) fn assert_monotone(name: &str, ladder: &[(f64, f64)]) {
925- assert_eq!(ladder.len(), 4, "{name}: wanted four quality points");
926- for w in ladder.windows(2) {
927- assert!(
928- w[1].0 > w[0].0 && w[1].1 > w[0].1,
929- "{name}: not monotone, {ladder:?}"
485+ decoded.y, frame.reconstruction.y,
486+ "{filter:?} frame {i}: luma"
930487 );
488+ assert_eq!(decoded.u, frame.reconstruction.u, "{filter:?} frame {i}: U");
489+ assert_eq!(decoded.v, frame.reconstruction.v, "{filter:?} frame {i}: V");
931490 }
491+ streams.push((filter, encoded.stream));
932492 }
933-
934- /// Which var-tx depth this clip's INTER blocks resolved to (lane-av1tx2,
935- /// split by block class in lane-av1txdepth): depth 0 is one transform over
936- /// the whole block, 1 its four halves; the classes are the 16x16/8x8
937- /// leaves and the 32x32 root, each single-reference or compound. A class
938- /// with no counts at all never reached `commit_inter_luma` -- which is
939- /// what its knob being off looks like (class `gate-blind-to-feature`).
940- pub(super) fn print_inter_tx_census(name: &str) {
941- let splits = take_inter_tx_split_hits();
942- let total: usize = splits.iter().sum();
943- let row = |label: &str, base: usize| {
944- let (n0, n1) = (splits[base], splits[base + 1]);
945- format!(
946- "{label} 0={n0} 1={n1} ({:.1}% split)",
947- 100.0 * n1 as f64 / (n0 + n1).max(1) as f64
948- )
949- };
950- eprintln!(
951- "{name}: inter var-tx depths of {total} blocks -- {} | {} | {} | {}",
952- row("leaf single", 0),
953- row("leaf compound", 2),
954- row("32x32 single", 4),
955- row("32x32 compound", 6),
956- );
957- // lane-txrd: which types the two searches actually COMMITTED over
958- // this row's four encodes -- the gate could not say whether a type
959- // search fired at all (class `gate-blind-to-feature`).
960- const NAMES: [&str; 16] = [
961- "IDTX",
962- "DCT_DCT",
963- "ADST_ADST",
964- "ADST_DCT",
965- "DCT_ADST",
966- "V_DCT",
967- "H_DCT",
968- "FLIPADST_DCT",
969- "DCT_FLIPADST",
970- "FLIPADST_FLIPADST",
971- "ADST_FLIPADST",
972- "FLIPADST_ADST",
973- "V_ADST",
974- "H_ADST",
975- "V_FLIPADST",
976- "H_FLIPADST",
977- ];
978- let name_of = |t: usize| NAMES[t];
979- for (label, hits) in [
980- ("inter", take_inter_tx_type_hits()),
981- ("intra", take_tx_type_hits()),
982- ] {
983- let total: usize = hits.iter().sum();
984- let live: Vec<String> = hits
985- .iter()
986- .enumerate()
987- .filter(|&(_, &n)| n > 0)
988- .map(|(t, &n)| {
989- format!(
990- "{}={n} ({:.1}%)",
991- name_of(t),
992- 100.0 * n as f64 / total.max(1) as f64
993- )
994- })
995- .collect();
996- eprintln!(
997- "{name}: {label} tx_type of {total} units -- {}",
998- live.join(" ")
999- );
1000- }
1001- let t = take_txrd_stats();
1002- if t[0] > 0 {
1003- eprintln!(
1004- "{name}: txrd flat decisions={} chosen sse={} bits={:.0} | DCT_DCT sse={} \
1005- bits={:.0} (dsse {:+.2}%, dbits {:+.2}%)",
1006- t[0],
1007- t[1],
1008- t[3] as f64 / 64.0,
1009- t[2],
1010- t[4] as f64 / 64.0,
1011- 100.0 * (t[1] as f64 - t[2] as f64) / t[2].max(1) as f64,
1012- 100.0 * (t[3] as f64 - t[4] as f64) / t[4].max(1) as f64,
1013- );
1014- eprintln!(
1015- "{name}: txrd DCT_DCT re-predicted HERE sse={} bits={:.0} (vs the passed-in \
1016- flat: dsse {:+.2}%, dbits {:+.2}%)",
1017- t[5],
1018- t[6] as f64 / 64.0,
1019- 100.0 * (t[5] as f64 - t[2] as f64) / t[2].max(1) as f64,
1020- 100.0 * (t[6] as f64 - t[4] as f64) / t[4].max(1) as f64,
1021- );
493+ set_frame_interp(None);
494+ for (i, (fa, a)) in streams.iter().enumerate() {
495+ for (fb, b) in &streams[i + 1..] {
496+ assert_ne!(a, b, "{fa:?} and {fb:?} coded the same bytes");
1022497 }
1023498 }
1024-
1025- /// The video stream's coded size, from ffprobe.
1026- pub(super) fn probe_dims(clip: &str) -> Option<(usize, usize)> {
1027- crate::probe::dims(clip)
1028- }
1029-
1030- /// `EC_AV1_NATIVE_CROP=<width>x<height>`: the native gate's window at a
1031- /// size of the reader's choosing instead of [`crate::probe::gate_crop`]'s
1032- /// superblock-aligned one, still centred and still even for 4:2:0.
1033- ///
1034- /// WHY IT EXISTS (lane-sse): `gate_crop` rounds DOWN to whole 128-wide
1035- /// superblocks by design, so no default gate row has a block the frame
1036- /// edge cuts through -- while every arbitrary export size does (3840x1608
1037- /// is 25.1 superblock rows, 1920x1080 is 8.4). `EC_AV1_NATIVE_CROP=
1038- /// 1920x1080` is the straddling arm the edge-clipped distortion score is
1039- /// read on.
1040- pub(super) fn native_crop_override(clip: &str) -> Option<(String, usize, usize)> {
1041- let spec = std::env::var("EC_AV1_NATIVE_CROP").ok()?;
1042- let (w, h) = spec
1043- .split_once('x')
1044- .expect("EC_AV1_NATIVE_CROP is <width>x<height>");
1045- let (cw, ch): (usize, usize) = (
1046- w.parse().expect("crop width"),
1047- h.parse().expect("crop height"),
1048- );
1049- let (nw, nh) = crate::probe::dims(clip)?;
1050- assert!(cw <= nw && ch <= nh, "{cw}x{ch} does not fit in {nw}x{nh}");
1051- let (x, y) = (((nw - cw) / 2) & !1, ((nh - ch) / 2) & !1);
1052- Some((format!("crop={cw}:{ch}:{x}:{y}"), cw, ch))
1053- }
1054-
1055- /// The probe arms the gate's source (lane-probe, class `instrument
1056- /// disagrees with the gate`). `examples/enc_probe` built its own ffmpeg
1057- /// command line and had no `-ss`, so it read film B from frame 0 -- a
1058- /// black leader -- and coded 59 kB where the gate's own ladder point
1059- /// coded 89 kB of the same title; every census taken through it was
1060- /// probe-relative. Both now call [`crate::probe::source`]; this pins that
1061- /// the shared loader honours the seek (arming the probe's way and the
1062- /// gate's way gives byte-identical streams, and dropping the seek does
1063- /// not), on a synthetic clip whose content moves over time.
1064- #[test]
1065- fn the_probe_arms_the_gates_source() {
1066- let _knobs = crate::speed::knob_write();
1067- let dir = std::env::temp_dir().join(format!("ec-av1-probe-{}", std::process::id()));
1068- std::fs::create_dir_all(&dir).unwrap();
1069- let clip = dir.join("testsrc2.y4m");
1070- // 384x202: neither side is a multiple of 128, so the gate's centre
1071- // window is a real derivation and not the frame itself -- exactly the
1072- // shape film B has (3840x1608, never 3840x2160).
1073- let ok = ec_testkit::ffmpeg()
1074- .args([
1075- "-v",
1076- "error",
1077- "-y",
1078- "-f",
1079- "lavfi",
1080- "-i",
1081- "testsrc2=size=384x202:rate=10",
1082- ])
1083- .args(["-frames:v", "20", "-pix_fmt", "yuv420p"])
1084- .arg(&clip)
1085- .status()
1086- .expect("ffmpeg failed to run")
1087- .success();
1088- assert!(ok, "ffmpeg could not write the synthetic clip");
1089- let path = clip.to_str().unwrap();
1090-
1091- // The window: superblock-aligned, centred, even offsets.
1092- let (vf, w, h) = crate::probe::gate_crop(path);
1093- assert_eq!((vf.as_str(), w, h), ("crop=384:128:0:36", 384, 128));
1094-
1095- let (seek, q) = ("00:00:01", 150u8);
1096- let gate = clip_frames_vf(path, seek, &vf, w, h, 6);
1097- let probe = crate::probe::source(path, seek, &vf, w, h, 6);
1098- assert!(
1099- gate.iter()
1100- .zip(&probe)
1101- .all(|(a, b)| a.y == b.y && a.u == b.u && a.v == b.v),
1102- "the probe's source differs from the gate's at the same window"
1103- );
1104- let bytes = |src: &[Picture]| {
1105- encode_sequence_with_ctx(src, q, 0.5, &crate::decode::FrameCtx::for_encoder())
1106- .unwrap()
1107- .stream
1108- };
499+}
500+
501+/// lane-hpmv: THE EIGHTH-PEL VECTOR REACHES THE STREAM. With
502+/// `allow_high_precision_mv` off the writer refuses an odd eighth-pel
503+/// residual outright (`round_to_valid_mv` rounds it away first), so the
504+/// finest vector the encoder could commit to was a quarter pel. With the
505+/// header bit on, the writer codes an `mv_hp`/`mv_class0_hp` symbol per
506+/// non-zero component and the search's fourth stage refines to the
507+/// eighth: this asserts ZERO hp symbols in the off arm, non-zero in the
508+/// on arm, and -- the part that makes it a signal rather than a symbol
509+/// count (class `fixture proves the symbol, not the signal`) -- that some
510+/// of them come out ZERO, i.e. name a vector the off arm cannot code at
511+/// all. Both streams are decoded by ffmpeg AND by this crate's own
512+/// decoder and asserted sample-exact against the encoder's own
513+/// reconstruction, which is what proves the header bit and the symbols
514+/// agree.
515+#[test]
516+fn a_high_precision_frame_codes_eighth_pel_motion_vectors_both_decoders_read() {
517+ let _knobs = crate::speed::knob_write();
518+ let (width, height) = (256usize, 128usize);
519+ let pictures: Vec<Picture> = (0..3)
520+ .map(|i| panned_test_card(width, height, i * 3))
521+ .collect();
522+ let mut arms = Vec::new();
523+ for hp in [false, true] {
524+ set_high_precision_mv(Some(hp));
525+ let _ = crate::tile::take_hp_symbols();
526+ let fctx = &crate::decode::FrameCtx::for_encoder();
527+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx)
528+ .unwrap_or_else(|e| panic!("hp={hp}: {e}"));
529+ let (symbols, eighth) = crate::tile::take_hp_symbols();
530+ let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, pictures.len());
531+ let ours = crate::stream::decode_stream(&encoded.stream).expect("our decoder");
532+ assert_eq!(decoded.len(), pictures.len(), "hp={hp}: ffmpeg frame count");
1109533 assert_eq!(
1110- bytes(&gate),
1111- bytes(&probe),
1112- "probe and gate code different bytes"
1113- );
1114- // The two witnesses that both halves of the arming reach ffmpeg: the
1115- // seek, and the crop's own offset (the film-B defect in miniature --
1116- // the probe was reading `crop=..:568` of a 1608-high frame).
1117- let unseeked = crate::probe::source(path, "0", &vf, w, h, 6);
1118- assert_ne!(
1119- bytes(&gate),
1120- bytes(&unseeked),
1121- "seeked and unseeked arming coded the same bytes -- the seek is inert"
534+ ours.len(),
535+ pictures.len(),
536+ "hp={hp}: our decoder frame count"
1122537 );
1123- let offset = crate::probe::source(path, seek, "crop=384:128:0:0", w, h, 6);
1124- assert_ne!(
1125- bytes(&gate),
1126- bytes(&offset),
1127- "centred and top-aligned windows coded the same bytes -- the crop is inert"
1128- );
1129- std::fs::remove_dir_all(&dir).ok();
1130- }
1131-
1132- /// lane-refs: THE FRAME FILTER REACHES THE PIXELS. `mc::predict` used to
1133- /// hardwire the REGULAR kernel, so the encoder could not have coded a
1134- /// SMOOTH or SHARP frame even if the header had said so -- the search,
1135- /// the trials, the recon and the frame header now all read
1136- /// `FrameCtx::interp_filter`. Each of the three kernels codes its own
1137- /// distinct stream (a filter that never reached the prediction would code
1138- /// the same bytes as REGULAR, class `symbol consumption gap`), and ffmpeg
1139- /// reconstructs every frame of each of them exactly, which is what proves
1140- /// the header and the prediction agree.
1141- #[test]
1142- fn each_frame_interpolation_filter_codes_its_own_stream_ffmpeg_decodes_exactly() {
1143- let _knobs = crate::speed::knob_write();
1144- let (width, height) = (256usize, 128usize);
1145- // A HALF-PEL pan: an integer-pel one reads no filter tap at all, so
1146- // all three kernels would code the same bytes and the test would pass
1147- // on a wiring that does nothing (class `fixture proves the symbol, not
1148- // the signal`). `panned_test_card` shifts by whole pixels, so the
1149- // search finds the sub-pel positions off the reconstruction instead:
1150- // three frames of a slow diagonal pan.
1151- let pictures: Vec<Picture> = (0..3)
1152- .map(|i| panned_test_card(width, height, i * 3))
1153- .collect();
1154- let mut streams = Vec::new();
1155- for filter in [
1156- ec_av1_syntax::InterpolationFilter::Eighttap,
1157- ec_av1_syntax::InterpolationFilter::EighttapSmooth,
1158- ec_av1_syntax::InterpolationFilter::EighttapSharp,
1159- ] {
1160- set_frame_interp(Some(filter));
1161- let fctx = &crate::decode::FrameCtx::for_encoder();
1162- let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx)
1163- .unwrap_or_else(|e| panic!("{filter:?}: {e}"));
1164- let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, 3);
1165- assert_eq!(decoded.len(), 3, "{filter:?}: decoded frame count");
1166- for (i, (frame, decoded)) in encoded.frames.iter().zip(&decoded).enumerate() {
1167- assert_eq!(
1168- decoded.y, frame.reconstruction.y,
1169- "{filter:?} frame {i}: luma"
1170- );
1171- assert_eq!(decoded.u, frame.reconstruction.u, "{filter:?} frame {i}: U");
1172- assert_eq!(decoded.v, frame.reconstruction.v, "{filter:?} frame {i}: V");
1173- }
1174- streams.push((filter, encoded.stream));
1175- }
1176- set_frame_interp(None);
1177- for (i, (fa, a)) in streams.iter().enumerate() {
1178- for (fb, b) in &streams[i + 1..] {
1179- assert_ne!(a, b, "{fa:?} and {fb:?} coded the same bytes");
1180- }
1181- }
1182- }
1183-
1184- /// lane-hpmv: THE EIGHTH-PEL VECTOR REACHES THE STREAM. With
1185- /// `allow_high_precision_mv` off the writer refuses an odd eighth-pel
1186- /// residual outright (`round_to_valid_mv` rounds it away first), so the
1187- /// finest vector the encoder could commit to was a quarter pel. With the
1188- /// header bit on, the writer codes an `mv_hp`/`mv_class0_hp` symbol per
1189- /// non-zero component and the search's fourth stage refines to the
1190- /// eighth: this asserts ZERO hp symbols in the off arm, non-zero in the
1191- /// on arm, and -- the part that makes it a signal rather than a symbol
1192- /// count (class `fixture proves the symbol, not the signal`) -- that some
1193- /// of them come out ZERO, i.e. name a vector the off arm cannot code at
1194- /// all. Both streams are decoded by ffmpeg AND by this crate's own
1195- /// decoder and asserted sample-exact against the encoder's own
1196- /// reconstruction, which is what proves the header bit and the symbols
1197- /// agree.
1198- #[test]
1199- fn a_high_precision_frame_codes_eighth_pel_motion_vectors_both_decoders_read() {
1200- let _knobs = crate::speed::knob_write();
1201- let (width, height) = (256usize, 128usize);
1202- let pictures: Vec<Picture> = (0..3)
1203- .map(|i| panned_test_card(width, height, i * 3))
1204- .collect();
1205- let mut arms = Vec::new();
1206- for hp in [false, true] {
1207- set_high_precision_mv(Some(hp));
1208- let _ = crate::tile::take_hp_symbols();
1209- let fctx = &crate::decode::FrameCtx::for_encoder();
1210- let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx)
1211- .unwrap_or_else(|e| panic!("hp={hp}: {e}"));
1212- let (symbols, eighth) = crate::tile::take_hp_symbols();
1213- let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, pictures.len());
1214- let ours = crate::stream::decode_stream(&encoded.stream).expect("our decoder");
1215- assert_eq!(decoded.len(), pictures.len(), "hp={hp}: ffmpeg frame count");
1216- assert_eq!(
1217- ours.len(),
1218- pictures.len(),
1219- "hp={hp}: our decoder frame count"
1220- );
1221- for (i, e) in encoded.frames.iter().enumerate() {
1222- for (who, got) in [("ffmpeg", &decoded[i]), ("our decoder", &ours[i])] {
1223- if let Some((plane, s, got, want)) =
1224- first_plane_mismatch(got, &e.reconstruction)
1225- {
1226- panic!(
1227- "hp={hp} frame {i} plane {plane} sample {s}: {who} decoded {got}, \
538+ for (i, e) in encoded.frames.iter().enumerate() {
539+ for (who, got) in [("ffmpeg", &decoded[i]), ("our decoder", &ours[i])] {
540+ if let Some((plane, s, got, want)) = first_plane_mismatch(got, &e.reconstruction) {
541+ panic!(
542+ "hp={hp} frame {i} plane {plane} sample {s}: {who} decoded {got}, \
1228543 the encoder reconstructed {want}"
1229- );
1230- }
544+ );
1231545 }
1232546 }
1233- arms.push((symbols, eighth, encoded.stream));
1234547 }
1235- set_high_precision_mv(None);
1236- let (off, on) = (&arms[0], &arms[1]);
1237- assert_eq!(
1238- off.0, 0,
1239- "a frame without the header bit codes no hp symbol"
1240- );
1241- assert!(
1242- on.0 > 0,
1243- "a high-precision frame codes hp symbols (got {})",
1244- on.0
1245- );
1246- assert!(
1247- on.1 > 0,
1248- "a high-precision frame codes eighth-pel vectors ({} hp symbols, none of them zero)",
1249- on.0
1250- );
1251- assert_ne!(off.2, on.2, "the two arms coded the same bytes");
1252- println!(
1253- "hp witness: off {} hp symbols / {} B, on {} hp symbols ({} eighth-pel) / {} B",
1254- off.0,
1255- off.2.len(),
1256- on.0,
1257- on.1,
1258- on.2.len()
1259- );
548+ arms.push((symbols, eighth, encoded.stream));
1260549 }
550+ set_high_precision_mv(None);
551+ let (off, on) = (&arms[0], &arms[1]);
552+ assert_eq!(
553+ off.0, 0,
554+ "a frame without the header bit codes no hp symbol"
555+ );
556+ assert!(
557+ on.0 > 0,
558+ "a high-precision frame codes hp symbols (got {})",
559+ on.0
560+ );
561+ assert!(
562+ on.1 > 0,
563+ "a high-precision frame codes eighth-pel vectors ({} hp symbols, none of them zero)",
564+ on.0
565+ );
566+ assert_ne!(off.2, on.2, "the two arms coded the same bytes");
567+ println!(
568+ "hp witness: off {} hp symbols / {} B, on {} hp symbols ({} eighth-pel) / {} B",
569+ off.0,
570+ off.2.len(),
571+ on.0,
572+ on.1,
573+ on.2.len()
574+ );
575+}
crates/ec-av1/src/encode/split.rsmodified+206 -267
@@ -312,13 +312,6 @@ pub(crate) static TXRD_STATS: [std::sync::atomic::AtomicU64; 7] = [
312312 std::sync::atomic::AtomicU64::new(0),
313313 ];
314314
315-/// Reads [`TXRD_STATS`] and zeroes it. Only the gate reads it, so the lib
316-/// build would warn `dead_code` (class from lane-txset2's `coeff_bits`).
317-#[cfg(test)]
318-pub(crate) fn take_txrd_stats() -> [u64; 7] {
319- std::array::from_fn(|i| TXRD_STATS[i].swap(0, std::sync::atomic::Ordering::Relaxed))
320-}
321-
322315 /// Reads [`INTER_TX_TYPE_HITS`] and zeroes it.
323316 #[cfg(test)]
324317 pub(crate) fn take_inter_tx_type_hits() -> [usize; 16] {
@@ -969,7 +962,15 @@ thread_local! {
969962 static INTRABC_FORCE: std::cell::Cell<Option<bool>> = const { std::cell::Cell::new(None) };
970963 }
971964
972-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
965+/// Whether the luma search refines a directional winner's `angle_delta_y`
966+/// (`EC_AV1_ANGLE=0` switches it off, the lane's own on/off pair).
967+pub(super) fn angle_delta_on() -> bool {
968+ static ENV: std::sync::LazyLock<Option<bool>> =
969+ std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_ANGLE").ok().map(|v| v != "0"));
970+ ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::ANGLE))
971+}
972+
973+#[cfg(test)]
973974 pub(crate) fn force_intrabc(value: Option<bool>) {
974975 INTRABC_FORCE.with(|c| c.set(value));
975976 }
@@ -1059,7 +1060,12 @@ pub(super) fn ibc_index(
10591060 /// `allow_intrabc` -- the share of its 16-aligned 16x16 blocks whose exact
10601061 /// content appears at some other position, against [`intrabc_pct`]. Returns
10611062 /// the share as well, for the gate's own print.
1062-pub(super) fn intrabc_worth_it(y: &[u8], width: usize, true_width: usize, true_height: usize) -> (bool, f64) {
1063+pub(super) fn intrabc_worth_it(
1064+ y: &[u8],
1065+ width: usize,
1066+ true_width: usize,
1067+ true_height: usize,
1068+) -> (bool, f64) {
10631069 if true_width < 4 * 64 || true_height < 2 * 64 {
10641070 return (false, 0.0);
10651071 }
@@ -1075,9 +1081,9 @@ pub(super) fn intrabc_worth_it(y: &[u8], width: usize, true_width: usize, true_h
10751081 && hits
10761082 .iter()
10771083 .any(|&(hx, hy)| (hx as usize, hy as usize) != (bx, by))
1078- {
1079- matched += 1;
1080- }
1084+ {
1085+ matched += 1;
1086+ }
10811087 bx += IBC_HASH;
10821088 }
10831089 by += IBC_HASH;
@@ -1207,13 +1213,6 @@ impl Drop for Ibc {
12071213 }
12081214 }
12091215
1210-/// Reads [`IBC_SEARCH`] and zeroes it, so a gate can attribute the counts to
1211-/// its own encode.
1212-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1213-pub(crate) fn take_intrabc_search() -> [usize; 3] {
1214- std::array::from_fn(|i| IBC_SEARCH[i].swap(0, std::sync::atomic::Ordering::Relaxed))
1215-}
1216-
12171216 /// [`crate::tile::write_dv_component`]'s static price -- the same shape as
12181217 /// [`mv_component_bits`] without the `mv_fr` symbol, which `force_integer_mv`
12191218 /// infers rather than codes.
@@ -1667,19 +1666,20 @@ pub(super) fn code_square(
16671666 if let Some(ibc) = ibc
16681667 && let Some((dv, cost_ibc, src)) =
16691668 ibc_search(ibc, luma, chroma, (x, y), side, search.lambda)
1670- && cost_ibc < cost {
1671- ibc_commit(luma, chroma, (x, y), src, side);
1672- ibc.last_dv = Some(dv);
1673- ibc.hits += 1;
1674- return (
1675- BlockCoeffs {
1676- skip: true,
1677- dv: Some(dv),
1678- ..BlockCoeffs::default()
1679- },
1680- cost_ibc,
1681- );
1682- }
1669+ && cost_ibc < cost
1670+ {
1671+ ibc_commit(luma, chroma, (x, y), src, side);
1672+ ibc.last_dv = Some(dv);
1673+ ibc.hits += 1;
1674+ return (
1675+ BlockCoeffs {
1676+ skip: true,
1677+ dv: Some(dv),
1678+ ..BlockCoeffs::default()
1679+ },
1680+ cost_ibc,
1681+ );
1682+ }
16831683 // A palette or filter-intra block's luma was recoded through `DCT_DCT`
16841684 // (its levels came from `code_from_prediction`), so the searched types
16851685 // belong to a block this one no longer is.
@@ -1722,53 +1722,6 @@ pub(super) const CHROMA_MODES: [u8; 7] = [
17221722 PAETH_PRED,
17231723 ];
17241724
1725-/// The thirteen intra mode names, for the chroma fire count's print.
1726-#[cfg(test)]
1727-pub(super) const UV_MODE_NAMES: [&str; 14] = [
1728- "DC", "V", "H", "D45", "D135", "D113", "D157", "D203", "D67", "SMOOTH", "SMOOTH_V", "SMOOTH_H",
1729- "PAETH", "CFL",
1730-];
1731-
1732-/// How many blocks each chroma mode has won, indexed by the mode itself --
1733-/// the fire count that says whether the search below reaches its candidates
1734-/// at all (the `gate-blind-to-feature` class), printed once per gate run.
1735-pub(super) static UV_MODE_HITS: [std::sync::atomic::AtomicUsize; 14] =
1736- [const { std::sync::atomic::AtomicUsize::new(0) }; 14];
1737-
1738-/// How many blocks each CfL alpha magnitude (`1..=16`, indexed `mag - 1`) has
1739-/// won, summed over both chroma planes -- the alpha histogram the gate prints
1740-/// beside the CfL share (`gate-blind-to-feature`: a tool that fires at one
1741-/// magnitude only is a search that never left its first candidate).
1742-pub(super) static CFL_ALPHA_HITS: [std::sync::atomic::AtomicUsize; 17] =
1743- [const { std::sync::atomic::AtomicUsize::new(0) }; 17];
1744-
1745-/// Reads [`CFL_ALPHA_HITS`] and zeroes it. Index 0 is "this plane took alpha
1746-/// zero on a CfL block", `1..=16` the magnitudes.
1747-#[cfg(test)]
1748-pub(crate) fn take_cfl_alpha_hits() -> [usize; 17] {
1749- std::array::from_fn(|m| CFL_ALPHA_HITS[m].swap(0, std::sync::atomic::Ordering::Relaxed))
1750-}
1751-
1752-/// How many directional luma blocks won at each `angle_delta_y`, indexed
1753-/// `delta + 3` -- the histogram that says whether the refinement below ever
1754-/// leaves zero (`gate-blind-to-feature`).
1755-pub(super) static ANGLE_DELTA_HITS: [std::sync::atomic::AtomicUsize; 7] =
1756- [const { std::sync::atomic::AtomicUsize::new(0) }; 7];
1757-
1758-/// Reads [`ANGLE_DELTA_HITS`] and zeroes it.
1759-#[cfg(test)]
1760-pub(crate) fn take_angle_delta_hits() -> [usize; 7] {
1761- std::array::from_fn(|d| ANGLE_DELTA_HITS[d].swap(0, std::sync::atomic::Ordering::Relaxed))
1762-}
1763-
1764-/// Whether the luma search refines a directional winner's `angle_delta_y`
1765-/// (`EC_AV1_ANGLE=0` switches it off, the lane's own on/off pair).
1766-pub(super) fn angle_delta_on() -> bool {
1767- static ENV: std::sync::LazyLock<Option<bool>> =
1768- std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_ANGLE").ok().map(|v| v != "0"));
1769- ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::ANGLE))
1770-}
1771-
17721725 /// Whether the chroma search offers `UV_CFL_PRED` at all (`EC_AV1_CFL=0`
17731726 /// switches it off, which is how the lane measured its own on/off pair).
17741727 pub(super) fn cfl_on() -> bool {
@@ -1834,14 +1787,6 @@ pub(crate) fn sb128_on() -> bool {
18341787 }
18351788 }
18361789
1837-/// Forces [`sb128_on`] for the rest of the process -- the superblock size is
1838-/// a SEQUENCE field, so a gate that flips it must run alone (`#[ignore]`),
1839-/// exactly like the speed-preset gates.
1840-#[cfg(test)]
1841-pub(crate) fn force_sb128(on: bool) {
1842- ENC_SB128.store(u8::from(on), std::sync::atomic::Ordering::Relaxed);
1843-}
1844-
18451790 /// The luma loop-restoration unit size this sequence codes: a 128 superblock
18461791 /// cannot signal the 64 unit at all (spec `lr_params` reads ONE bit there,
18471792 /// `RESTORATION_TILESIZE_MAX >> (2 - (shift + 1))`, so the smallest unit is
@@ -1863,13 +1808,6 @@ pub(crate) fn filter_intra_on() -> bool {
18631808 ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::FILTER_INTRA))
18641809 }
18651810
1866-/// Reads [`UV_MODE_HITS`] and zeroes it, so a gate can attribute the counts
1867-/// to its own encode.
1868-#[cfg(test)]
1869-pub(crate) fn take_uv_mode_hits() -> [usize; 14] {
1870- std::array::from_fn(|m| UV_MODE_HITS[m].swap(0, std::sync::atomic::Ordering::Relaxed))
1871-}
1872-
18731811 /// Searches both chroma planes over [`CHROMA_MODES`] under one shared mode --
18741812 /// `uv_mode` is a single symbol covering U and V -- and commits the cheapest.
18751813 /// Returns each plane's levels, the mode, and what the pair cost (squared
@@ -2051,7 +1989,9 @@ pub(super) fn search_chroma(
20511989 }
20521990 let mut v_colors = [0u16; 8];
20531991 for k in 0..n {
2054- v_colors[k] = (sums[k] + counts[k] / 2).checked_div(counts[k]).unwrap_or(0) as u16;
1992+ v_colors[k] = (sums[k] + counts[k] / 2)
1993+ .checked_div(counts[k])
1994+ .unwrap_or(0) as u16;
20551995 }
20561996 let candidate = crate::tile::PaletteUv {
20571997 size: pal.size,
@@ -2229,17 +2169,10 @@ pub(super) fn search_chroma(
22292169 }
22302170 }
22312171 }
2232- if let Some((alpha_u, alpha_v)) = cfl_alphas {
2233- for alpha in [alpha_u, alpha_v] {
2234- CFL_ALPHA_HITS[alpha.unsigned_abs() as usize]
2235- .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
2236- }
2237- }
22382172 if census_on() {
22392173 CHROMA_RANK[sad_rank(&ranking, mode).min(6)]
22402174 .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
22412175 }
2242- UV_MODE_HITS[usize::from(mode)].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
22432176 chroma[0].commit(at.x, at.y, at.side, &u);
22442177 chroma[1].commit(at.x, at.y, at.side, &v);
22452178 (
@@ -2871,53 +2804,55 @@ pub(super) fn code_square_inter(
28712804 }
28722805 }
28732806 if let Some(new_mv) = searched_new
2874- && let Some(b0) = mv_residual_bits(new_mv, cbase.0) {
2875- ccands.push((
2876- (new_mv, cstack.nearest_mv.1),
2877- mode_bits_of(3) + b0,
2878- InterInfo {
2879- ref_frame: crate::mvstack::LAST_FRAME,
2880- mode: InterMode::NewNearestMv,
2881- mv: new_mv,
2882- mv1: cstack.nearest_mv.1,
2883- ref1: Some(ref1),
2884- ref_mv_idx: 0,
2885- },
2886- ));
2887- }
2807+ && let Some(b0) = mv_residual_bits(new_mv, cbase.0)
2808+ {
2809+ ccands.push((
2810+ (new_mv, cstack.nearest_mv.1),
2811+ mode_bits_of(3) + b0,
2812+ InterInfo {
2813+ ref_frame: crate::mvstack::LAST_FRAME,
2814+ mode: InterMode::NewNearestMv,
2815+ mv: new_mv,
2816+ mv1: cstack.nearest_mv.1,
2817+ ref1: Some(ref1),
2818+ ref_mv_idx: 0,
2819+ },
2820+ ));
2821+ }
28882822 // `NEAREST_NEWMV` and `NEW_NEWMV`: the NEW halves are the two
28892823 // searches this leaf ran, each residual priced against `cbase`.
28902824 if let Some(mv1) = second_new
2891- && let Some(b1) = mv_residual_bits(mv1, cbase.1) {
2825+ && let Some(b1) = mv_residual_bits(mv1, cbase.1)
2826+ {
2827+ ccands.push((
2828+ (cstack.nearest_mv.0, mv1),
2829+ mode_bits_of(2) + b1,
2830+ InterInfo {
2831+ ref_frame: crate::mvstack::LAST_FRAME,
2832+ mode: InterMode::NearestNewMv,
2833+ mv: cstack.nearest_mv.0,
2834+ mv1,
2835+ ref1: Some(ref1),
2836+ ref_mv_idx: 0,
2837+ },
2838+ ));
2839+ if let Some((new_mv, b0)) =
2840+ searched_new.and_then(|m| mv_residual_bits(m, cbase.0).map(|b| (m, b)))
2841+ {
28922842 ccands.push((
2893- (cstack.nearest_mv.0, mv1),
2894- mode_bits_of(2) + b1,
2843+ (new_mv, mv1),
2844+ mode_bits_of(7) + b0 + b1,
28952845 InterInfo {
28962846 ref_frame: crate::mvstack::LAST_FRAME,
2897- mode: InterMode::NearestNewMv,
2898- mv: cstack.nearest_mv.0,
2847+ mode: InterMode::NewNewMv,
2848+ mv: new_mv,
28992849 mv1,
29002850 ref1: Some(ref1),
29012851 ref_mv_idx: 0,
29022852 },
29032853 ));
2904- if let Some((new_mv, b0)) =
2905- searched_new.and_then(|m| mv_residual_bits(m, cbase.0).map(|b| (m, b)))
2906- {
2907- ccands.push((
2908- (new_mv, mv1),
2909- mode_bits_of(7) + b0 + b1,
2910- InterInfo {
2911- ref_frame: crate::mvstack::LAST_FRAME,
2912- mode: InterMode::NewNewMv,
2913- mv: new_mv,
2914- mv1,
2915- ref1: Some(ref1),
2916- ref_mv_idx: 0,
2917- },
2918- ));
2919- }
29202854 }
2855+ }
29212856 ccands.sort_by(|a, b| a.0.cmp(&b.0).then(a.1.total_cmp(&b.1)));
29222857 ccands.dedup_by_key(|c| c.0);
29232858 let g_luma = (g.y.as_slice(), g.width, luma.true_width, luma.true_height);
@@ -3040,7 +2975,8 @@ pub(super) fn code_square_inter(
30402975 ) >= 1;
30412976 let mm = |m: u8| motion_mode_bits(side, side, m, warp_alphabet);
30422977 let mut candidates: Vec<(u8, [Vec<u8>; 3])> = Vec::new();
3043- if crate::envflags::env_flag!("EC_AV1_OBMC") && side >= obmc_min_side()
2978+ if crate::envflags::env_flag!("EC_AV1_OBMC")
2979+ && side >= obmc_min_side()
30442980 && let Some(pred) = obmc_prediction(
30452981 grid,
30462982 (mi_row, mi_col),
@@ -3052,9 +2988,10 @@ pub(super) fn code_square_inter(
30522988 planes,
30532989 (reference.width, reference.height),
30542990 fctx,
3055- ) {
3056- candidates.push((1, pred));
3057- }
2991+ )
2992+ {
2993+ candidates.push((1, pred));
2994+ }
30582995 if warp_alphabet
30592996 && let Some(pred) = warp_prediction(
30602997 grid,
@@ -3066,9 +3003,10 @@ pub(super) fn code_square_inter(
30663003 info.ref_frame,
30673004 planes,
30683005 fctx,
3069- ) {
3070- candidates.push((2, pred));
3071- }
3006+ )
3007+ {
3008+ candidates.push((2, pred));
3009+ }
30723010 for (motion, pred) in candidates {
30733011 let luma_o = luma.code_from_prediction(
30743012 x,
@@ -3125,136 +3063,137 @@ pub(super) fn code_square_inter(
31253063 }
31263064
31273065 if let (cost, Some((luma_new, u_new, v_new, skip_new, info))) = best
3128- && cost < intra_cost {
3129- // A compound winner commits the flat trial it was priced from:
3130- // `commit_inter_luma`'s var-tx trial set is single-reference
3131- // (`mc_trial`), so a compound leaf codes `tx_depth = 0`.
3132- // lane-av1comp4 BUILT that upgrade (a `commit_inter_luma`
3133- // predicting each half-side trial from BOTH references, verified
3134- // byte-identical to this when its split is disabled) and MEASURED
3135- // it a loss: vs libaom +83.5/+99.7/+54.9 at no margin against the
3136- // +83.0/+99.9/+54.5 here, and +83.3/+100.2/+54.9, +83.8/+99.5/
3137- // +54.9, +83.3/+100.0/+54.9 at split margins 0.02/0.05/0.15. A
3138- // compound block's residual is small enough that the four extra
3139- // per-unit txb_skip/eob symbols cost more ladder bytes than this
3140- // encoder's static-CDF estimate prices them at, so the local RD
3141- // win does not convert. lane-av1txbits REBUILT it on top of a
3142- // search that prices against the tables the frame is really
3143- // written with (`tile::arm_pricing_cdfs`, the estimate error on
3144- // these very blocks measured down from +31% to +3%) and measured
3145- // it neutral-to-worse again: +78.8/+95.0/+54.5 and +36.5/+56.3/
3146- // +1.4 against the +78.8/+95.1/+54.5 and +36.1/+56.4/+1.4 of the
3147- // same build without it. The static-CDF estimate was NOT what
3148- // held the compound var-tx trial back. The flat trial stays.
3149- // An OBMC winner commits the flat trial too: `commit_inter_luma`
3150- // re-predicts each var-tx unit by plain translation, which is not
3151- // the prediction this candidate was priced from.
3152- // lane-av1txdepth REBUILT the compound trial set at LAMBDA_SCALE
3153- // 0.05 (both rejections above were measured at 0.1, the weight
3154- // the lambda lane showed was 2x too heavy): a compound winner is
3155- // offered the same var-tx split, its units predicted from BOTH
3156- // references (`mc_trial_compound`). RE-MEASURED native: film
3157- // 1080p +16.0/-1.1, film 2160p +46.6/+18.8, screen +51.4/-14.4
3158- // against the +16.2/-1.1, +46.6/+18.8, +51.3/-14.4 with it off --
3159- // one row 0.2 down, two flat, short of the two-down-one-flat keep
3160- // rule, so it stays behind `EC_AV1_COMP_VARTX` (default OFF)
3161- // rather than change the default on a single 0.2 row. It fires:
3162- // 37.0% / 11.1% / 32.9% of the compound blocks split. 640x384 for
3163- // the record: +70.5/+84.0/+48.9 and +28.9/+46.2/-3.7 against
3164- // +70.4/+85.3/+48.5 and +28.4/+47.4/-4.0 -- the 4K film row is
3165- // 1.3/1.2 down there, which is where the upgrade path is if this
3166- // is picked up again.
3167- let second = info.ref1.filter(|_| motion_won == 0).and_then(|r| {
3168- refs[r as usize].map(|g| {
3169- (
3170- info.mv1,
3171- (g.y.as_slice(), g.width, luma.true_width, luma.true_height),
3172- )
3173- })
3174- });
3175- let (levels, tx_depth, dcost, luma_tx_types) =
3176- if motion_won != 0 || (info.ref1.is_some() && second.is_none()) {
3177- luma.commit(x, y, side, &luma_new);
3178- (luma_new.levels.clone(), 0, 0.0, Vec::new())
3179- } else {
3180- commit_inter_luma(
3181- luma,
3182- (x, y),
3183- side,
3184- info.mv,
3185- (ref_luma.0.as_slice(), ref_luma.1, ref_luma.2, ref_luma.3),
3186- search,
3187- &luma_new,
3188- skip_new,
3189- second,
3190- fctx,
3191- )
3192- };
3193- // lane-txrd: chroma follows the luma type the search just chose.
3194- let [u_new, v_new] = match luma_tx_types.first().copied() {
3195- Some(t) => recode_inter_chroma(
3196- chroma,
3066+ && cost < intra_cost
3067+ {
3068+ // A compound winner commits the flat trial it was priced from:
3069+ // `commit_inter_luma`'s var-tx trial set is single-reference
3070+ // (`mc_trial`), so a compound leaf codes `tx_depth = 0`.
3071+ // lane-av1comp4 BUILT that upgrade (a `commit_inter_luma`
3072+ // predicting each half-side trial from BOTH references, verified
3073+ // byte-identical to this when its split is disabled) and MEASURED
3074+ // it a loss: vs libaom +83.5/+99.7/+54.9 at no margin against the
3075+ // +83.0/+99.9/+54.5 here, and +83.3/+100.2/+54.9, +83.8/+99.5/
3076+ // +54.9, +83.3/+100.0/+54.9 at split margins 0.02/0.05/0.15. A
3077+ // compound block's residual is small enough that the four extra
3078+ // per-unit txb_skip/eob symbols cost more ladder bytes than this
3079+ // encoder's static-CDF estimate prices them at, so the local RD
3080+ // win does not convert. lane-av1txbits REBUILT it on top of a
3081+ // search that prices against the tables the frame is really
3082+ // written with (`tile::arm_pricing_cdfs`, the estimate error on
3083+ // these very blocks measured down from +31% to +3%) and measured
3084+ // it neutral-to-worse again: +78.8/+95.0/+54.5 and +36.5/+56.3/
3085+ // +1.4 against the +78.8/+95.1/+54.5 and +36.1/+56.4/+1.4 of the
3086+ // same build without it. The static-CDF estimate was NOT what
3087+ // held the compound var-tx trial back. The flat trial stays.
3088+ // An OBMC winner commits the flat trial too: `commit_inter_luma`
3089+ // re-predicts each var-tx unit by plain translation, which is not
3090+ // the prediction this candidate was priced from.
3091+ // lane-av1txdepth REBUILT the compound trial set at LAMBDA_SCALE
3092+ // 0.05 (both rejections above were measured at 0.1, the weight
3093+ // the lambda lane showed was 2x too heavy): a compound winner is
3094+ // offered the same var-tx split, its units predicted from BOTH
3095+ // references (`mc_trial_compound`). RE-MEASURED native: film
3096+ // 1080p +16.0/-1.1, film 2160p +46.6/+18.8, screen +51.4/-14.4
3097+ // against the +16.2/-1.1, +46.6/+18.8, +51.3/-14.4 with it off --
3098+ // one row 0.2 down, two flat, short of the two-down-one-flat keep
3099+ // rule, so it stays behind `EC_AV1_COMP_VARTX` (default OFF)
3100+ // rather than change the default on a single 0.2 row. It fires:
3101+ // 37.0% / 11.1% / 32.9% of the compound blocks split. 640x384 for
3102+ // the record: +70.5/+84.0/+48.9 and +28.9/+46.2/-3.7 against
3103+ // +70.4/+85.3/+48.5 and +28.4/+47.4/-4.0 -- the 4K film row is
3104+ // 1.3/1.2 down there, which is where the upgrade path is if this
3105+ // is picked up again.
3106+ let second = info.ref1.filter(|_| motion_won == 0).and_then(|r| {
3107+ refs[r as usize].map(|g| {
3108+ (
3109+ info.mv1,
3110+ (g.y.as_slice(), g.width, luma.true_width, luma.true_height),
3111+ )
3112+ })
3113+ });
3114+ let (levels, tx_depth, dcost, luma_tx_types) =
3115+ if motion_won != 0 || (info.ref1.is_some() && second.is_none()) {
3116+ luma.commit(x, y, side, &luma_new);
3117+ (luma_new.levels.clone(), 0, 0.0, Vec::new())
3118+ } else {
3119+ commit_inter_luma(
3120+ luma,
31973121 (x, y),
31983122 side,
31993123 info.mv,
3200- [
3201- (ref_u.0.as_slice(), ref_u.1, ref_u.2, ref_u.3),
3202- (ref_v.0.as_slice(), ref_v.1, ref_v.2, ref_v.3),
3203- ],
3204- info.ref1.filter(|_| motion_won == 0).and_then(|r| {
3205- refs[r as usize].map(|g| {
3206- (
3207- info.mv1,
3208- [
3209- (
3210- g.u.as_slice(),
3211- g.width / 2,
3212- chroma[0].true_width,
3213- chroma[0].true_height,
3214- ),
3215- (
3216- g.v.as_slice(),
3217- g.width / 2,
3218- chroma[1].true_width,
3219- chroma[1].true_height,
3220- ),
3221- ],
3222- )
3223- })
3224- }),
3124+ (ref_luma.0.as_slice(), ref_luma.1, ref_luma.2, ref_luma.3),
32253125 search,
3226- chroma_set,
3227- t,
3126+ &luma_new,
3127+ skip_new,
3128+ second,
32283129 fctx,
32293130 )
3230- .unwrap_or([u_new, v_new]),
3231- None => [u_new, v_new],
32323131 };
3233- chroma[0].commit(x / 2, y / 2, side / 2, &u_new);
3234- chroma[1].commit(x / 2, y / 2, side / 2, &v_new);
3235- return (
3236- BlockCoeffs {
3237- angle_delta_y: 0,
3238- cfl_alphas: None,
3239- filter_intra: None,
3240- luma: coeffs(&levels, side),
3241- u: coeffs(&u_new.levels, side / 2),
3242- v: coeffs(&v_new.levels, side / 2),
3243- mode: DC_PRED,
3244- uv_mode: DC_PRED,
3245- skip: skip_new,
3246- eight: None,
3247- dv: None,
3248- palette: None,
3249- palette_uv: None,
3250- tx_depth,
3251- luma_tx_types,
3252- inter: Some(info),
3253- motion_mode: motion_won,
3254- },
3255- cost + dcost,
3256- );
3257- }
3132+ // lane-txrd: chroma follows the luma type the search just chose.
3133+ let [u_new, v_new] = match luma_tx_types.first().copied() {
3134+ Some(t) => recode_inter_chroma(
3135+ chroma,
3136+ (x, y),
3137+ side,
3138+ info.mv,
3139+ [
3140+ (ref_u.0.as_slice(), ref_u.1, ref_u.2, ref_u.3),
3141+ (ref_v.0.as_slice(), ref_v.1, ref_v.2, ref_v.3),
3142+ ],
3143+ info.ref1.filter(|_| motion_won == 0).and_then(|r| {
3144+ refs[r as usize].map(|g| {
3145+ (
3146+ info.mv1,
3147+ [
3148+ (
3149+ g.u.as_slice(),
3150+ g.width / 2,
3151+ chroma[0].true_width,
3152+ chroma[0].true_height,
3153+ ),
3154+ (
3155+ g.v.as_slice(),
3156+ g.width / 2,
3157+ chroma[1].true_width,
3158+ chroma[1].true_height,
3159+ ),
3160+ ],
3161+ )
3162+ })
3163+ }),
3164+ search,
3165+ chroma_set,
3166+ t,
3167+ fctx,
3168+ )
3169+ .unwrap_or([u_new, v_new]),
3170+ None => [u_new, v_new],
3171+ };
3172+ chroma[0].commit(x / 2, y / 2, side / 2, &u_new);
3173+ chroma[1].commit(x / 2, y / 2, side / 2, &v_new);
3174+ return (
3175+ BlockCoeffs {
3176+ angle_delta_y: 0,
3177+ cfl_alphas: None,
3178+ filter_intra: None,
3179+ luma: coeffs(&levels, side),
3180+ u: coeffs(&u_new.levels, side / 2),
3181+ v: coeffs(&v_new.levels, side / 2),
3182+ mode: DC_PRED,
3183+ uv_mode: DC_PRED,
3184+ skip: skip_new,
3185+ eight: None,
3186+ dv: None,
3187+ palette: None,
3188+ palette_uv: None,
3189+ tx_depth,
3190+ luma_tx_types,
3191+ inter: Some(info),
3192+ motion_mode: motion_won,
3193+ },
3194+ cost + dcost,
3195+ );
3196+ }
32583197
32593198 census_add(8, 1);
32603199 if skip {
crates/ec-av1/src/encode/tests.rsmodified+2377 -3618

Diff too large; view file

@@ -1,3783 +1,2542 @@
11
2- /// Every (site, frame type, block side) the census can be called with
3- /// lands in its own ten-counter bucket, inside the array (class
4- /// `enumerate-table-domain`: an off-by-one here would silently add two
5- /// sites' trials together).
6- #[test]
7- fn the_split_census_buckets_are_distinct_and_in_bounds() {
8- let mut seen = std::collections::BTreeSet::new();
9- for site in 0..2 {
10- for key in [true, false] {
11- for side in [8usize, 16, 32, 64] {
12- let base = super::split_census_base(site, key, side);
13- assert!(
14- base + 10 <= super::SPLIT_CENSUS.len(),
15- "{site} {key} {side}"
16- );
17- assert!(seen.insert(base), "{site} {key} {side} collides");
18- }
19- }
2+/// An [`crate::mvstack::MvStack`] with every context at zero and no
3+/// neighbours, for the pricer tests below to fill the one band each of
4+/// them is about.
5+/// lane-b128 task 0: every `ref_mv_idx` the `NEWMV`/`NEARMV` pricer
6+/// offers must be one [`crate::tile::write_drl_idx`] can really SIGNAL
7+/// against the same stack -- an offer the writer clamps prices the
8+/// residual against a predictor the decoder never derives, which is the
9+/// silent MV drift lane-sb128b root-caused (there fixed on the WRITER
10+/// side, so the stream stays legal; here the pricer's own offer set is
11+/// enumerated, class `enumerate-table-domain`).
12+///
13+/// **This is the coverage claim for the drl-clamp cell** (lane-av1recipehunt
14+/// r2, 2026-09-29). It replaces the clip gate
15+/// `a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact`,
16+/// deleted in `3e8c65e6`+r2: that gate asserted `drl_clamp_hits() > 0` on a
17+/// real 1280x768 sb128 clip, but `DRL_CLAMP_HITS` is provably unreachable
18+/// while the invariant above holds, so no recipe could ever satisfy it.
19+/// Deletion loses no coverage on either half:
20+/// * the clamp half -- this test IS the coverage, and it is strictly
21+/// stronger than any clip gate: it enumerates the pricer's whole offer
22+/// set against the writer's rule for every stack size 0..=4, and larger
23+/// stacks add entries the pricers never offer (`best_new_mv_syntax`
24+/// breaks at `entries.len() <= idx` for `idx > 0`, so indices 3/4 are
25+/// unreachable at ANY stack size), which is why 0..=4 bounds the
26+/// domain rather than sampling it;
27+/// * the pixel half -- the deleted gate's own decode-vs-encoder-
28+/// reconstruction compare on a 1280x768 sb128 sequence is already made
29+/// four times over, by `a_128_superblock_clip_whose_root_search_codes_
30+/// 128x128_blocks_decodes_exact`,
31+/// `a_128_root_block_with_a_real_residual_decodes_exact_through_both_decoders`,
32+/// `a_128_root_residual_block_under_a_per_unit_cdef_list_decodes_exact`
33+/// and `a_rect128_half_with_a_real_residual_decodes_exact_through_both_decoders`
34+/// (same geometry, same `force_sb128(true)`, same own-reconstruction AND
35+/// ffmpeg compare).
36+///
37+/// MEASURED before deleting (153 clip x size x frame-count x q combinations,
38+/// `enc_probe`): `tile::drl_clamp_hits()` = 0 on every one. MUTATION PROOF
39+/// the clip was never the variable: widening `best_new_mv_syntax`'s offer
40+/// set to `0..5` fires the counter immediately (9/2/2/1 on
41+/// mandelbrot 640x384x8, mandelbrot 320x192x8, mosaic 320x192x8,
42+/// testsrc2 640x384x8) and the same clips read 0 on revert. `note_drl_clamp`
43+/// and `DRL_CLAMP_HITS` are KEPT as the tripwire for the owning fix
44+/// (`deferred(unblock: the DRL owner widens the pricer past the writer's
45+/// `start + 2` ceiling, or retires the counter)`) -- this test will go red
46+/// the moment either happens, which is the signal to re-open the cell.
47+///
48+/// cargo test -p ec-av1 --lib -- every_drl_index_the_new_mv_pricer
49+#[test]
50+fn every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal() {
51+ for n in 0..=4usize {
52+ let mut stack = bare_stack();
53+ for i in 0..n {
54+ stack.entries.push(crate::mvstack::StackEntry {
55+ mv: (8 * (i as i32 + 1), -8 * (i as i32 + 1)),
56+ weight: 1,
57+ });
58+ stack.drl_ctx.push(0);
59+ }
60+ stack.nearest_mv = stack.entries.first().map_or((0, 0), |e| e.mv);
61+ stack.near_mv = stack.entries.get(1).map_or((0, 0), |e| e.mv);
62+ stack.pred_mv = stack.nearest_mv;
63+ // Aim the vector at each entry in turn, so every index the offer
64+ // set holds is the one that wins at least once.
65+ for target in 0..n.max(1) {
66+ let mv = stack.entries.get(target).map_or(stack.pred_mv, |e| e.mv);
67+ let (_, idx) =
68+ best_new_mv_syntax(&stack, mv).expect("a zero residual is always codable");
69+ let idx = usize::from(idx);
70+ assert_eq!(
71+ crate::tile::signalled_drl_idx(n, 0, idx),
72+ idx,
73+ "NEWMV: a {n}-entry stack cannot signal the offered drl index {idx}",
74+ );
2075 }
21- assert_eq!(seen.len(), 16);
22- }
23-
24- /// An [`crate::mvstack::MvStack`] with every context at zero and no
25- /// neighbours, for the pricer tests below to fill the one band each of
26- /// them is about.
27- /// lane-b128 task 0: every `ref_mv_idx` the `NEWMV`/`NEARMV` pricer
28- /// offers must be one [`crate::tile::write_drl_idx`] can really SIGNAL
29- /// against the same stack -- an offer the writer clamps prices the
30- /// residual against a predictor the decoder never derives, which is the
31- /// silent MV drift lane-sb128b root-caused (there fixed on the WRITER
32- /// side, so the stream stays legal; here the pricer's own offer set is
33- /// enumerated, class `enumerate-table-domain`).
34- ///
35- /// **This is the coverage claim for the drl-clamp cell** (lane-av1recipehunt
36- /// r2, 2026-09-29). It replaces the clip gate
37- /// `a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact`,
38- /// deleted in `3e8c65e6`+r2: that gate asserted `drl_clamp_hits() > 0` on a
39- /// real 1280x768 sb128 clip, but `DRL_CLAMP_HITS` is provably unreachable
40- /// while the invariant above holds, so no recipe could ever satisfy it.
41- /// Deletion loses no coverage on either half:
42- /// * the clamp half -- this test IS the coverage, and it is strictly
43- /// stronger than any clip gate: it enumerates the pricer's whole offer
44- /// set against the writer's rule for every stack size 0..=4, and larger
45- /// stacks add entries the pricers never offer (`best_new_mv_syntax`
46- /// breaks at `entries.len() <= idx` for `idx > 0`, so indices 3/4 are
47- /// unreachable at ANY stack size), which is why 0..=4 bounds the
48- /// domain rather than sampling it;
49- /// * the pixel half -- the deleted gate's own decode-vs-encoder-
50- /// reconstruction compare on a 1280x768 sb128 sequence is already made
51- /// four times over, by `a_128_superblock_clip_whose_root_search_codes_
52- /// 128x128_blocks_decodes_exact`,
53- /// `a_128_root_block_with_a_real_residual_decodes_exact_through_both_decoders`,
54- /// `a_128_root_residual_block_under_a_per_unit_cdef_list_decodes_exact`
55- /// and `a_rect128_half_with_a_real_residual_decodes_exact_through_both_decoders`
56- /// (same geometry, same `force_sb128(true)`, same own-reconstruction AND
57- /// ffmpeg compare).
58- ///
59- /// MEASURED before deleting (153 clip x size x frame-count x q combinations,
60- /// `enc_probe`): `tile::drl_clamp_hits()` = 0 on every one. MUTATION PROOF
61- /// the clip was never the variable: widening `best_new_mv_syntax`'s offer
62- /// set to `0..5` fires the counter immediately (9/2/2/1 on
63- /// mandelbrot 640x384x8, mandelbrot 320x192x8, mosaic 320x192x8,
64- /// testsrc2 640x384x8) and the same clips read 0 on revert. `note_drl_clamp`
65- /// and `DRL_CLAMP_HITS` are KEPT as the tripwire for the owning fix
66- /// (`deferred(unblock: the DRL owner widens the pricer past the writer's
67- /// `start + 2` ceiling, or retires the counter)`) -- this test will go red
68- /// the moment either happens, which is the signal to re-open the cell.
69- ///
70- /// cargo test -p ec-av1 --lib -- every_drl_index_the_new_mv_pricer
71- #[test]
72- fn every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal() {
73- for n in 0..=4usize {
74- let mut stack = bare_stack();
75- for i in 0..n {
76- stack.entries.push(crate::mvstack::StackEntry {
77- mv: (8 * (i as i32 + 1), -8 * (i as i32 + 1)),
78- weight: 1,
79- });
80- stack.drl_ctx.push(0);
81- }
82- stack.nearest_mv = stack.entries.first().map_or((0, 0), |e| e.mv);
83- stack.near_mv = stack.entries.get(1).map_or((0, 0), |e| e.mv);
84- stack.pred_mv = stack.nearest_mv;
85- // Aim the vector at each entry in turn, so every index the offer
86- // set holds is the one that wins at least once.
87- for target in 0..n.max(1) {
88- let mv = stack.entries.get(target).map_or(stack.pred_mv, |e| e.mv);
89- let (_, idx) =
90- best_new_mv_syntax(&stack, mv).expect("a zero residual is always codable");
91- let idx = usize::from(idx);
76+ // The NEARMV arm's own offer set (`search_inter_block`,
77+ // `search_skip_64`): indices 1 and 2, offered only when the stack
78+ // really holds that entry.
79+ for idx in 1..=2usize {
80+ if stack.entries.get(idx).is_some() {
9281 assert_eq!(
93- crate::tile::signalled_drl_idx(n, 0, idx),
82+ crate::tile::signalled_drl_idx(n, 1, idx),
9483 idx,
95- "NEWMV: a {n}-entry stack cannot signal the offered drl index {idx}",
84+ "NEARMV: a {n}-entry stack cannot signal the offered drl index {idx}",
9685 );
9786 }
98- // The NEARMV arm's own offer set (`search_inter_block`,
99- // `search_skip_64`): indices 1 and 2, offered only when the stack
100- // really holds that entry.
101- for idx in 1..=2usize {
102- if stack.entries.get(idx).is_some() {
103- assert_eq!(
104- crate::tile::signalled_drl_idx(n, 1, idx),
105- idx,
106- "NEARMV: a {n}-entry stack cannot signal the offered drl index {idx}",
107- );
108- }
109- }
11087 }
11188 }
89+}
11290
113- pub(super) fn bare_stack() -> crate::mvstack::MvStack {
114- crate::mvstack::MvStack {
115- entries: Default::default(),
116- nearest_mv: (0, 0),
117- near_mv: (0, 0),
118- pred_mv: (0, 0),
119- new_mv_ctx: 0,
120- ref_mv_ctx: 0,
121- zero_mv_ctx: 0,
122- drl_ctx: Default::default(),
123- above_refs: (None, None),
124- left_refs: (None, None),
125- above_nbr: None,
126- left_nbr: None,
127- above_skip: false,
128- left_skip: false,
129- }
91+pub(super) fn bare_stack() -> crate::mvstack::MvStack {
92+ crate::mvstack::MvStack {
93+ entries: Default::default(),
94+ nearest_mv: (0, 0),
95+ near_mv: (0, 0),
96+ pred_mv: (0, 0),
97+ new_mv_ctx: 0,
98+ ref_mv_ctx: 0,
99+ zero_mv_ctx: 0,
100+ drl_ctx: Default::default(),
101+ above_refs: (None, None),
102+ left_refs: (None, None),
103+ above_nbr: None,
104+ left_nbr: None,
105+ above_skip: false,
106+ left_skip: false,
130107 }
108+}
131109
132- /// [`super::compound_ref_bits`] pays exactly the symbols tile.rs'
133- /// `write_compound_ref_frames` codes for a pair, each at that symbol's
134- /// own neighbour-derived context. Red before lane-ctx, where the pricer
135- /// spent four constants at CDF row 0 that assumed the pair was
136- /// LAST+GOLDEN or LAST+ALTREF -- so a LAST+BWDREF pair was priced as
137- /// LAST+ALTREF with its `comp_bwdref` p6 symbol missing entirely.
138- #[test]
139- fn the_compound_ref_pricer_pays_the_writers_own_symbol_sequence() {
140- use crate::cdf::{COMP_BWDREF, COMP_MODE, COMP_REF, COMP_REF_TYPE, UNI_COMP_REF};
141- use crate::encode::symbol_bits as b;
142- use crate::mvstack::{
143- ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST_FRAME, LAST2_FRAME,
144- LAST3_FRAME, NeighbourRef, comp_reference_type_ctx, reference_mode_ctx,
145- single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx,
146- single_ref_p5_ctx, single_ref_p6_ctx, uni_comp_ref_p1_ctx,
110+/// [`super::compound_ref_bits`] pays exactly the symbols tile.rs'
111+/// `write_compound_ref_frames` codes for a pair, each at that symbol's
112+/// own neighbour-derived context. Red before lane-ctx, where the pricer
113+/// spent four constants at CDF row 0 that assumed the pair was
114+/// LAST+GOLDEN or LAST+ALTREF -- so a LAST+BWDREF pair was priced as
115+/// LAST+ALTREF with its `comp_bwdref` p6 symbol missing entirely.
116+#[test]
117+fn the_compound_ref_pricer_pays_the_writers_own_symbol_sequence() {
118+ use crate::cdf::{COMP_BWDREF, COMP_MODE, COMP_REF, COMP_REF_TYPE, UNI_COMP_REF};
119+ use crate::encode::symbol_bits as b;
120+ use crate::mvstack::{
121+ ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST_FRAME, LAST2_FRAME,
122+ LAST3_FRAME, NeighbourRef, comp_reference_type_ctx, reference_mode_ctx, single_ref_p1_ctx,
123+ single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx,
124+ single_ref_p6_ctx, uni_comp_ref_p1_ctx,
125+ };
126+ // (pair, unidirectional?, the tree's symbols as (table, p index,
127+ // context selector, value)) -- transcribed from the writer.
128+ // selector: 1..=6 are `single_ref_p*_ctx`, 7 is `uni_comp_ref_p1_ctx`.
129+ type Sym = (char, usize, usize, usize);
130+ let cases: [((i8, i8), bool, &[Sym]); 7] = [
131+ (
132+ (LAST_FRAME, LAST2_FRAME),
133+ true,
134+ &[('u', 0, 1, 0), ('u', 1, 7, 0)],
135+ ),
136+ (
137+ (LAST_FRAME, LAST3_FRAME),
138+ true,
139+ &[('u', 0, 1, 0), ('u', 1, 7, 1), ('u', 2, 5, 0)],
140+ ),
141+ (
142+ (LAST_FRAME, GOLDEN_FRAME),
143+ true,
144+ &[('u', 0, 1, 0), ('u', 1, 7, 1), ('u', 2, 5, 1)],
145+ ),
146+ ((BWDREF_FRAME, ALTREF_FRAME), true, &[('u', 0, 1, 1)]),
147+ (
148+ (LAST_FRAME, ALTREF_FRAME),
149+ false,
150+ &[('c', 0, 3, 0), ('c', 1, 4, 0), ('b', 0, 2, 1)],
151+ ),
152+ (
153+ (LAST_FRAME, BWDREF_FRAME),
154+ false,
155+ &[
156+ ('c', 0, 3, 0),
157+ ('c', 1, 4, 0),
158+ ('b', 0, 2, 0),
159+ ('b', 1, 6, 0),
160+ ],
161+ ),
162+ (
163+ (LAST_FRAME, ALTREF2_FRAME),
164+ false,
165+ &[
166+ ('c', 0, 3, 0),
167+ ('c', 1, 4, 0),
168+ ('b', 0, 2, 0),
169+ ('b', 1, 6, 1),
170+ ],
171+ ),
172+ ];
crates/ec-av1/src/encoder/tests.rsmodified+2879 -3407

Diff too large; view file

crates/ec-av1/src/film_grain.rsmodified+18 -54

Diff too large; view file

crates/ec-av1/src/hits.rsdeleted+0 -47

Diff too large; view file

crates/ec-av1/src/intra.rsmodified+55 -49

Diff too large; view file

crates/ec-av1/src/lib.rsmodified+0 -6

Diff too large; view file

crates/ec-av1/src/mc.rsmodified+32 -25

Diff too large; view file

crates/ec-av1/src/motion_field.rsmodified+23 -59

Diff too large; view file

crates/ec-av1/src/msac.rsmodified+2 -286

Diff too large; view file

crates/ec-av1/src/mvstack.rsmodified+171 -119

Diff too large; view file

crates/ec-av1/src/par.rsmodified+9 -31

Diff too large; view file

crates/ec-av1/src/probe.rsmodified+0 -41

Diff too large; view file

crates/ec-av1/src/quant.rsmodified+0 -19

Diff too large; view file

crates/ec-av1/src/restoration.rsmodified+28 -68

Diff too large; view file

crates/ec-av1/src/stack_budget.rsdeleted+0 -990

Diff too large; view file

crates/ec-av1/src/stream/mod.rsmodified+6 -545

Diff too large; view file

crates/ec-av1/src/superres.rsmodified+0 -2

Diff too large; view file

crates/ec-av1/src/test_source.rsdeleted+0 -103

Diff too large; view file

crates/ec-av1/src/tile/blocks.rsmodified+10 -161

Diff too large; view file

crates/ec-av1/src/tile/mod.rsmodified+1 -52

Diff too large; view file

crates/ec-av1/tests/real_library.rsdeleted+0 -287

Diff too large; view file