ec-av1: settle the 4:4:4 coefficient-read count asymmetry by measurement
Browse files at this commitcf7d7f8e8385dcc25d88c439c218b87122d6d564Parent: 4106dd63 changed files +479 -1
- crates/ec-av1/src/decode.rs +151 -0
- crates/ec-av1/src/stream.rs +139 -1
- lanes/av1readcensus.report.md +189 -0
crates/ec-av1/src/decode.rsmodified+151 -0
| @@ -2275,6 +2275,119 @@ pub(crate) fn rect_class1_hits() -> usize { | ||
| 2275 | 2275 | RECT_CLASS1_HITS.with(|c| c.get()) |
| 2276 | 2276 | } |
| 2277 | 2277 | |
| 2278 | +// lane-av1readcensus: the PER-UNIT coefficient census -- one unit counted | |
| 2279 | +// per `read_coeffs`/`read_coeffs_rect` call, i.e. per object this decoder | |
| 2280 | +// actually walks, which is the unit the round-4 `av1444rect` count measured | |
| 2281 | +// (636 square chroma reads against the oracle's 1086). The counters are | |
| 2282 | +// 4:4:4-ONLY (`CENSUS_444`, set per frame beside `set_subsampling`), so a | |
| 2283 | +// 4:2:0 control reads `(0, 0, 0)` -- a walk-shape change at 4:2:0 is another | |
| 2284 | +// lane's business, and this census must not fire there. | |
| 2285 | +thread_local! { | |
| 2286 | + /// Per-plane unit counts, `[luma, u, v]`, at 4:4:4 only. | |
| 2287 | + static CENSUS_444_UNITS: std::cell::Cell<[usize; 3]> = const { std::cell::Cell::new([0; 3]) }; | |
| 2288 | + /// Of [`CENSUS_444_UNITS`], the units that coded at least one coefficient | |
| 2289 | + /// (`txb_skip == 0`) -- the per-plane split is only comparable against | |
| 2290 | + /// the oracle's when both sides count all-zero units the same way. | |
| 2291 | + static CENSUS_444_CODED: std::cell::Cell<[usize; 3]> = const { std::cell::Cell::new([0; 3]) }; | |
| 2292 | + /// Sequential unit index, so a trace line names its own position in the | |
| 2293 | + /// frame's walk rather than relying on line order alone. | |
| 2294 | + static CENSUS_UNIT_N: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 2295 | + /// The plane the units read from here on belong to. A thread-local rather | |
| 2296 | + /// than a `read_coeffs` parameter because the three luma call sites | |
| 2297 | + /// (`decode_rect_split`, `decode_block_rect64`, `read_inter_plane_rect`) | |
| 2298 | + /// are not this lane's to edit and would each grow an argument; the | |
| 2299 | + /// plane-owning readers stamp it once on entry instead. | |
| 2300 | + static CENSUS_PLANE: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 2301 | + /// 4:4:4 (`subsampling_x == 0 && subsampling_y == 0`) for the frame being | |
| 2302 | + /// decoded, set per frame from [`crate::stream`]. | |
| 2303 | + static CENSUS_444: std::cell::Cell<bool> = const { std::cell::Cell::new(false) }; | |
| 2304 | +} | |
| 2305 | + | |
| 2306 | +/// Current `[luma, u, v]` 4:4:4 coefficient-unit counts. | |
| 2307 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | |
| 2308 | +pub(crate) fn census_444_units() -> [usize; 3] { | |
| 2309 | + CENSUS_444_UNITS.with(|c| c.get()) | |
| 2310 | +} | |
| 2311 | + | |
| 2312 | +/// Current `[luma, u, v]` 4:4:4 counts of units that coded coefficients. | |
| 2313 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | |
| 2314 | +pub(crate) fn census_444_coded() -> [usize; 3] { | |
| 2315 | + CENSUS_444_CODED.with(|c| c.get()) | |
| 2316 | +} | |
| 2317 | + | |
| 2318 | +/// lane-av1readcensus: arms the 4:4:4 census for the frame about to decode, | |
| 2319 | +/// called once per frame from [`crate::stream`]'s decode loop beside | |
| 2320 | +/// [`set_subsampling`]. At 4:2:0 (or 4:2:2) every census counter stays zero -- | |
| 2321 | +/// the walk-shape question this census answers is a 4:4:4 one. | |
| 2322 | +pub(crate) fn set_census_444(ss_x: u8, ss_y: u8) { | |
| 2323 | + CENSUS_444.with(|c| c.set(ss_x == 0 && ss_y == 0)); | |
| 2324 | +} | |
| 2325 | + | |
| 2326 | +/// lane-av1readcensus: the plane the units read from here on belong to, | |
| 2327 | +/// stamped by the plane-owning readers ([`read_plane`], [`read_inter_plane`], | |
| 2328 | +/// [`read_inter_plane_rect`]) on entry. | |
| 2329 | +pub(crate) fn set_census_plane(plane: usize) { | |
| 2330 | + CENSUS_PLANE.with(|c| c.set(plane)); | |
| 2331 | +} | |
| 2332 | + | |
| 2333 | +/// lane-av1readcensus: is the per-unit census trace on? Shares | |
| 2334 | +/// [`coeff_trace_on`]'s per-frame narrowing so one frame's walk can be | |
| 2335 | +/// dumped without the rest of the stream. | |
| 2336 | +fn census_trace_on() -> bool { | |
| 2337 | + if !crate::envflags::env_flag!("EC_CENSUS_UNIT") { | |
| 2338 | + return false; | |
| 2339 | + } | |
| 2340 | + match COEFF_TRACE_FRAME.with(|c| c.get()) { | |
| 2341 | + None => true, | |
| 2342 | + Some(w) if w >= usize::MAX - 1 => true, | |
| 2343 | + Some(w) => COEFF_TRACE_CUR.with(|c| c.get()) == w, | |
| 2344 | + } | |
| 2345 | +} | |
| 2346 | + | |
| 2347 | +/// lane-av1readcensus: one line per coefficient unit this decoder walks, the | |
| 2348 | +/// twin of the oracle's `EC_COEFF` / `EC_COEFF_VAL` bracket around each | |
| 2349 | +/// `av1_read_coeffs_txb` call. Pair the two sides by `post_rng` (or by `n`), | |
| 2350 | +/// never by plane label or by walk position -- the walk order is exactly what | |
| 2351 | +/// the census is measuring. | |
| 2352 | +fn census_unit( | |
| 2353 | + w: usize, | |
| 2354 | + h: usize, | |
| 2355 | + tx_type: TxType, | |
| 2356 | + eob: usize, | |
| 2357 | + all_zero: bool, | |
| 2358 | + entry_rng: u32, | |
| 2359 | + dec: &SymbolDecoder, | |
| 2360 | +) { | |
| 2361 | + let plane = CENSUS_PLANE.with(|c| c.get()).min(2); | |
| 2362 | + let coded = usize::from(!all_zero); | |
| 2363 | + CENSUS_UNIT_N.with(|c| c.set(c.get() + 1)); | |
| 2364 | + hit_do! { | |
| 2365 | + CENSUS_444_UNITS.with(|c| { | |
| 2366 | + if CENSUS_444.with(|on| on.get()) { | |
| 2367 | + let mut v = c.get(); | |
| 2368 | + v[plane] += 1; | |
| 2369 | + c.set(v); | |
| 2370 | + } | |
| 2371 | + }); | |
| 2372 | + CENSUS_444_CODED.with(|c| { | |
| 2373 | + if CENSUS_444.with(|on| on.get()) { | |
| 2374 | + let mut v = c.get(); | |
| 2375 | + v[plane] += coded; | |
| 2376 | + c.set(v); | |
| 2377 | + } | |
| 2378 | + }); | |
| 2379 | + } | |
| 2380 | + if !census_trace_on() { | |
| 2381 | + return; | |
| 2382 | + } | |
| 2383 | + let n = CENSUS_UNIT_N.with(|c| c.get()) - 1; | |
| 2384 | + let post_rng = dec.debug_state().0; | |
| 2385 | + eprintln!( | |
| 2386 | + "EC_CENSUS_UNIT side=ours n={n} plane={plane} w={w} h={h} tx={tx_type:?} eob={eob} \ | |
| 2387 | + all_zero={all_zero} entry_rng={entry_rng} post_rng={post_rng}" | |
| 2388 | + ); | |
| 2389 | +} | |
| 2390 | + | |
| 2278 | 2391 | // As [`FILTER_INTRA_RECT_HITS`], counting only the strips BELOW 16x16 |
| 2279 | 2392 | // (8x16/16x8 leaves of a 16x16 HORZ/VERT partition, lane-fistrip r1) -- the |
| 2280 | 2393 | // shapes whose `use_filter_intra` symbol had no CDF class before this round. |
| @@ -7561,6 +7674,11 @@ fn read_coeffs( | ||
| 7561 | 7674 | ) -> Result<(Grid, TxType)> { |
| 7562 | 7675 | let trace = crate::envflags::env_flag!("EC_AV1_TRACE"); |
| 7563 | 7676 | let side = coding.side; |
| 7677 | + // lane-av1readcensus: this unit's own entry state, so the census line | |
| 7678 | + // carries the pre-read rng and pairs against the oracle's `EC_COEFF` | |
| 7679 | + // (which prints `r->ec.rng` before the same `txb_skip` read). | |
| 7680 | + let census_entry_rng = dec.debug_state().0; | |
| 7681 | + let (census_w, census_h) = rect_shape.unwrap_or((side, side)); | |
| 7564 | 7682 | if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") { |
| 7565 | 7683 | let (range, value) = dec.debug_state(); |
| 7566 | 7684 | eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}"); |
| @@ -7603,6 +7721,15 @@ fn read_coeffs( | ||
| 7603 | 7721 | if all_zero { |
| 7604 | 7722 | // lane-coefgrid: the all-zero unit (60% of the 4K segment's) names the |
| 7605 | 7723 | // shared zero grid instead of allocating and zeroing its own. |
| 7724 | + census_unit( | |
| 7725 | + census_w, | |
| 7726 | + census_h, | |
| 7727 | + TxType::DctDct, | |
| 7728 | + 0, | |
| 7729 | + true, | |
| 7730 | + census_entry_rng, | |
| 7731 | + dec, | |
| 7732 | + ); | |
| 7606 | 7733 | return Ok((Grid::Zero(side * side), TxType::DctDct)); |
| 7607 | 7734 | } |
| 7608 | 7735 | let mut grid = vec![0i32; side * side]; |
| @@ -7811,6 +7938,15 @@ fn read_coeffs( | ||
| 7811 | 7938 | } |
| 7812 | 7939 | grid[pos] = if negative { -level } else { level }; |
| 7813 | 7940 | } |
| 7941 | + census_unit( | |
| 7942 | + census_w, | |
| 7943 | + census_h, | |
| 7944 | + tx_type, | |
| 7945 | + eob, | |
| 7946 | + false, | |
| 7947 | + census_entry_rng, | |
| 7948 | + dec, | |
| 7949 | + ); | |
| 7814 | 7950 | Ok((Grid::Own(grid), tx_type)) |
| 7815 | 7951 | } |
| 7816 | 7952 | |
| @@ -7840,6 +7976,13 @@ fn read_coeffs_rect( | ||
| 7840 | 7976 | ) -> Result<(Grid, TxType)> { |
| 7841 | 7977 | let rect_trace = coeff_trace_on(); |
| 7842 | 7978 | let entry_rng = dec.debug_state().0; |
| 7979 | + // lane-av1readcensus: this reader is handed the real plane (lane-av1chrtx | |
| 7980 | + // threaded it in for the `EC_COEFF_STEP` traces), so it stamps the census | |
| 7981 | + // plane itself rather than inheriting whichever reader did last. The | |
| 7982 | + // luma-only readers (`decode_rect_split`, `decode_block_rect64`, | |
| 7983 | + // `read_inter_plane_rect`'s corner) are all plane 0 -- the stamp's initial | |
| 7984 | + // value -- and the other plane-owning readers stamp on entry. | |
| 7985 | + set_census_plane(plane); | |
| 7843 | 7986 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; |
| 7844 | 7987 | if rect_trace { |
| 7845 | 7988 | eprintln!( |
| @@ -7849,6 +7992,7 @@ fn read_coeffs_rect( | ||
| 7849 | 7992 | ); |
| 7850 | 7993 | } |
| 7851 | 7994 | if all_zero { |
| 7995 | + census_unit(w, h, TxType::DctDct, 0, true, entry_rng, dec); | |
| 7852 | 7996 | return Ok((Grid::Zero(w * h), TxType::DctDct)); |
| 7853 | 7997 | } |
| 7854 | 7998 | let mut grid = vec![0i32; w * h]; |
| @@ -8052,6 +8196,7 @@ fn read_coeffs_rect( | ||
| 8052 | 8196 | nz.join(",") |
| 8053 | 8197 | ); |
| 8054 | 8198 | } |
| 8199 | + census_unit(w, h, tx_type, eob, false, entry_rng, dec); | |
| 8055 | 8200 | Ok((Grid::Own(grid), tx_type)) |
| 8056 | 8201 | } |
| 8057 | 8202 | |
| @@ -19858,6 +20003,8 @@ fn read_plane( | ||
| 19858 | 20003 | if plane_idx > 0 && mono(fctx) { |
| 19859 | 20004 | return Ok(Grid::Zero(side * side)); |
| 19860 | 20005 | } |
| 20006 | + // lane-av1readcensus: the units read from here on are this plane's. | |
| 20007 | + set_census_plane(plane_idx); | |
| 19861 | 20008 | let skip_ctx = if plane_idx == 0 { |
| 19862 | 20009 | luma_skip_ctx.unwrap_or(0) |
| 19863 | 20010 | } else { |
| @@ -28431,6 +28578,8 @@ fn read_inter_plane_rect( | ||
| 28431 | 28578 | if plane_idx > 0 && mono(fctx) { |
| 28432 | 28579 | return Ok((Grid::Zero(w * h), TxType::DctDct)); |
| 28433 | 28580 | } |
| 28581 | + // lane-av1readcensus: the units read from here on are this plane's. | |
| 28582 | + set_census_plane(plane_idx); | |
| 28434 | 28583 | let skip_ctx = if plane_idx == 0 { |
| 28435 | 28584 | // `get_txb_ctx_general`: 0 only when this unit IS the whole plane |
| 28436 | 28585 | // block; a var-tx leaf passes its own neighbour-table context. |
| @@ -35501,6 +35650,8 @@ fn read_inter_plane( | ||
| 35501 | 35650 | if plane_idx > 0 && mono(fctx) { |
| 35502 | 35651 | return Ok((Grid::Zero(side * side), TxType::DctDct)); |
| 35503 | 35652 | } |
| 35653 | + // lane-av1readcensus: the units read from here on are this plane's. | |
| 35654 | + set_census_plane(plane_idx); | |
| 35504 | 35655 | let skip_ctx = if plane_idx == 0 { |
| 35505 | 35656 | luma_skip_ctx.unwrap_or(0) |
| 35506 | 35657 | } else { |
crates/ec-av1/src/stream.rsmodified+139 -1
| @@ -1837,6 +1837,10 @@ fn decode_frame( | ||
| 1837 | 1837 | // 4:2:0 one never inherits the wrong plane count. |
| 1838 | 1838 | crate::decode::set_mono(seq.mono_chrome, fctx); |
| 1839 | 1839 | crate::decode::set_subsampling(seq.subsampling_x, seq.subsampling_y, fctx); |
| 1840 | + // lane-av1readcensus: the 4:4:4 coefficient-unit census is armed here, | |
| 1841 | + // off the same sequence-header subsampling -- at 4:2:0/4:2:2 every census | |
| 1842 | + // counter reads zero, so a 4:2:0 control can assert exactly that. | |
| 1843 | + crate::decode::set_census_444(seq.subsampling_x, seq.subsampling_y); | |
| 1840 | 1844 | // lane-av1txr: spec 5.9.2 `disable_cdf_update` -- a frame that sets it |
| 1841 | 1845 | // codes every tile symbol against the CDFs it started with, so the tile |
| 1842 | 1846 | // readers must not adapt (libaom `decodeframe.c:2909`: |
| @@ -19369,6 +19373,141 @@ pub(crate) mod tests { | ||
| 19369 | 19373 | ); |
| 19370 | 19374 | } |
| 19371 | 19375 | |
| 19376 | + /// lane-av1readcensus: the 4:4:4 coefficient-UNIT census, pinned. | |
| 19377 | + /// | |
| 19378 | + /// The lane report `av1444rect` round 4 left an unexplained signal: 636 | |
| 19379 | + /// square chroma reads against the oracle's 1086, and 2052 luma reads | |
| 19380 | + /// against its 1309, recorded as "most likely a counting-shape difference" | |
| 19381 | + /// with no evidence either way. This gate is that evidence. | |
| 19382 | + /// | |
| 19383 | + /// Measured on this arm (`ll444_minp8_inter`, pixel-exact against aomdec | |
| 19384 | + /// on every plane of every frame -- see | |
| 19385 | + /// `a_lossless_444_min_partition8_inter_stream_decodes_sample_exact`), | |
| 19386 | + /// pairing each of our 11292 walked units with the oracle's | |
| 19387 | + /// `av1_read_coeffs_txb` call BY `post_rng` (the msac state after the | |
| 19388 | + /// unit) rather than by plane label or walk position: EVERY unit pairs, | |
| 19389 | + /// and no unit's plane, shape, eob or all-zero flag differs. The per-plane | |
| 19390 | + /// split is equal too -- 3764 units per plane on both sides, of which | |
| 19391 | + /// 975 / 1793 / 1859 coded coefficients. So on a pixel-exact arm there is | |
| 19392 | + /// no asymmetry to explain at all; the round-4 numbers came from | |
| 19393 | + /// `444_intrabc_rect4_witness`, an arm that DIVERGES (390380 of 921600 | |
| 19394 | + /// samples wrong), where our surplus is the divergence itself. | |
| 19395 | + /// | |
| 19396 | + /// What this gate pins is the walk's OBJECT SHAPE on the pixel-exact arm: | |
| 19397 | + /// a change to the number or plane split of coefficient units this decoder | |
| 19398 | + /// walks shows up here as an intentional diff, not as the next lane's | |
| 19399 | + /// mystery signal. The 4:2:0 control asserts the census is inert there. | |
| 19400 | + #[test] | |
| 19401 | + fn a_pixel_exact_444_stream_walks_the_same_coefficient_units_the_oracle_does() { | |
| 19402 | + const NAME: &str = | |
| 19403 | + "a_pixel_exact_444_stream_walks_the_same_coefficient_units_the_oracle_does"; | |
| 19404 | + const FIXTURE_LEN: usize = 34037; | |
| 19405 | + const FIXTURE_FNV: u64 = 0x2c8f_4a2c_c025_52da; | |
| 19406 | + let _gate_lock = lock_gate_counters(); | |
| 19407 | + if !have_aomenc() { | |
| 19408 | + eprintln!( | |
| 19409 | + "SKIP {NAME}: no aomenc/aomdec oracle at {}", | |
| 19410 | + aomenc_path().display() | |
| 19411 | + ); | |
| 19412 | + return; | |
| 19413 | + } | |
| 19414 | + let path = | |
| 19415 | + std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/ll444_minp8_inter.obu"); | |
| 19416 | + let stream = std::fs::read(&path) | |
| 19417 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | |
| 19418 | + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); | |
| 19419 | + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | |
| 19420 | + let delta = |now: [usize; 3], before: [usize; 3]| { | |
| 19421 | + [now[0] - before[0], now[1] - before[1], now[2] - before[2]] | |
| 19422 | + }; | |
| 19423 | + | |
| 19424 | + let u0 = crate::decode::census_444_units(); | |
| 19425 | + let c0 = crate::decode::census_444_coded(); | |
| 19426 | + let (frames, hidden) = decode_all_frames_vs_oracle(&stream, NAME); | |
| 19427 | + assert_eq!( | |
| 19428 | + frames + hidden, | |
| 19429 | + 8, | |
| 19430 | + "{NAME}: expected 8 decode-order frames (6 shown + 2 hidden)" | |
| 19431 | + ); | |
| 19432 | + let walked = delta(crate::decode::census_444_units(), u0); | |
| 19433 | + let coded = delta(crate::decode::census_444_coded(), c0); | |
| 19434 | + | |
| 19435 | + // The oracle's own census on the same stream, paired by post_rng: | |
| 19436 | + // 3764 units per plane, 975 / 1793 / 1859 of them coded. | |
| 19437 | + assert_eq!( | |
| 19438 | + walked, | |
| 19439 | + [3764, 3764, 3764], | |
| 19440 | + "{NAME}: the 4:4:4 unit walk changed -- {walked:?} against the oracle's \ | |
| 19441 | + [3764, 3764, 3764] (measured by post_rng pairing, every unit matching). A change \ | |
| 19442 | + here is a WALK-SHAPE change: re-measure against aomdec before assuming it is a bug" | |
| 19443 | + ); | |
| 19444 | + assert_eq!( | |
| 19445 | + coded, | |
| 19446 | + [975, 1793, 1859], | |
| 19447 | + "{NAME}: the coded-unit split changed -- {coded:?} against the oracle's [975, 1793, 1859]" | |
| 19448 | + ); | |
| 19449 | + assert!( | |
| 19450 | + walked.iter().all(|&v| v > 0) && coded.iter().all(|&v| v > 0), | |
| 19451 | + "{NAME}: an all-zero plane split means the census did not run, not that the walk is empty" | |
| 19452 | + ); | |
| 19453 | + | |
| 19454 | + // A SECOND pixel-exact arm, with a MIXED unit-shape mix -- the pinned | |
| 19455 | + // lossless stream above is all TX_4X4 (min-partition-8), so on its own | |
| 19456 | + // it would not notice a var-tx walk that started folding 8x8/4x8 | |
| 19457 | + // leaves. This one walks 4x4/8x8/8x4/4x8/4x16/16x4/8x16/16x16, and | |
| 19458 | + // the oracle's census on it pairs unit-for-unit by post_rng with no | |
| 19459 | + // shape, plane, eob or all-zero difference: 1373 units, 629 luma and | |
| 19460 | + // 372 per chroma plane, of which 130 / 253 / 278 coded. | |
| 19461 | + let path2 = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | |
| 19462 | + .join("fixtures/444_lossy_rect4_inter_witness.obu"); | |
| 19463 | + let stream2 = std::fs::read(&path2) | |
| 19464 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path2.display())); | |
| 19465 | + let m0 = crate::decode::census_444_units(); | |
| 19466 | + let mc0 = crate::decode::census_444_coded(); | |
| 19467 | + let (frames2, hidden2) = decode_all_frames_vs_oracle(&stream2, NAME); | |
| 19468 | + assert!( | |
| 19469 | + frames2 + hidden2 > 0, | |
| 19470 | + "{NAME}: the mixed-shape 4:4:4 arm decoded no frames" | |
| 19471 | + ); | |
| 19472 | + let walked2 = delta(crate::decode::census_444_units(), m0); | |
| 19473 | + let coded2 = delta(crate::decode::census_444_coded(), mc0); | |
| 19474 | + assert_eq!( | |
| 19475 | + walked2, | |
| 19476 | + [629, 372, 372], | |
| 19477 | + "{NAME}: the mixed-shape 4:4:4 walk changed -- {walked2:?} against the oracle's \ | |
| 19478 | + [629, 372, 372]. The all-4x4 arm above cannot see a var-tx fold; this one can" | |
| 19479 | + ); | |
| 19480 | + assert_eq!( | |
| 19481 | + coded2, | |
| 19482 | + [130, 253, 278], | |
| 19483 | + "{NAME}: the mixed-shape coded-unit split changed -- {coded2:?} against the oracle's \ | |
| 19484 | + [130, 253, 278]" | |
| 19485 | + ); | |
| 19486 | + | |
| 19487 | + // 4:2:0 control: the census is a 4:4:4 question and must not fire. | |
| 19488 | + let control = std::fs::read( | |
| 19489 | + std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | |
| 19490 | + .join("fixtures/av1_192x128_8bit_intra64_in_inter.obu"), | |
| 19491 | + ) | |
| 19492 | + .unwrap_or_else(|e| panic!("{NAME}: reading the 4:2:0 control: {e}")); | |
| 19493 | + let k0 = crate::decode::census_444_units(); | |
| 19494 | + let kc0 = crate::decode::census_444_coded(); | |
| 19495 | + let k_frames = decode_stream(&control) | |
| 19496 | + .unwrap_or_else(|e| panic!("{NAME}: the 4:2:0 control no longer decodes: {e}")) | |
| 19497 | + .len(); | |
| 19498 | + assert!(k_frames > 0, "{NAME}: the 4:2:0 control decoded no frames"); | |
| 19499 | + assert_eq!( | |
| 19500 | + delta(crate::decode::census_444_units(), k0), | |
| 19501 | + [0, 0, 0], | |
| 19502 | + "{NAME}: the 4:4:4 census fired on the 4:2:0 control" | |
| 19503 | + ); | |
| 19504 | + assert_eq!( | |
| 19505 | + delta(crate::decode::census_444_coded(), kc0), | |
| 19506 | + [0, 0, 0], | |
| 19507 | + "{NAME}: the 4:4:4 coded-unit census fired on the 4:2:0 control" | |
| 19508 | + ); | |
| 19509 | + } | |
| 19510 | + | |
| 19372 | 19511 | /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT` |
| 19373 | 19512 | /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r1 |
| 19374 | 19513 | /// found missing ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs |
| @@ -39628,7 +39767,6 @@ pub(crate) mod tests { | ||
| 39628 | 39767 | "{NAME}: no attempt decoded a depth-1 1:4 split strip -- the recipe no longer \ |
| 39629 | 39768 | covers the shape this round fixed" |
| 39630 | 39769 | ); |
| 39631 | - eprintln!("{NAME}: {depth1_decoded} depth-1 1:4 split strips decoded pixel-exact"); | |
| 39632 | 39770 | } |
| 39633 | 39771 | |
| 39634 | 39772 | /// The chroma-rect gate's fixture + aomenc recipe for one attempt, shared |
lanes/av1readcensus.report.mdadded+189 -0
| @@ -0,0 +1,189 @@ | ||
| 1 | +# lane-av1readcensus — the 4:4:4 coefficient-read count asymmetry, settled | |
| 2 | + | |
| 3 | +**Branch:** `lane-av1readcensus`, worktree `~/.cache/wt/av1readcensus`, stacked on | |
| 4 | +`lane-av1chrtx` (`ff7cf47c`, whose `d791c464` threaded the real plane index into | |
| 5 | +`read_coeffs_rect`'s traces — the census pairs on that). | |
| 6 | + | |
| 7 | +**Verdict: COUNTING SHAPE — and not even that. On every pixel-exact 4:4:4 arm | |
| 8 | +there is no asymmetry at all: both sides walk the same number of units, in the | |
| 9 | +same order, with the same plane, shape, eob and all-zero flag. The recorded | |
| 10 | +636-vs-1086 / 2052-vs-1309 signal came from an arm that DIVERGES, where the | |
| 11 | +surplus is the divergence itself, not a counting-shape difference.** | |
| 12 | + | |
| 13 | +## 1. The signal, and why the census was admissible only on a pixel-exact arm | |
| 14 | + | |
| 15 | +`av1444rect` round 4 recorded 636 square chroma reads against the oracle's 1086, | |
| 16 | +and 2052 luma reads against its 1309, on `444_intrabc_rect4_witness`, and filed | |
| 17 | +it as "most likely a counting-shape difference … it is NOT established either | |
| 18 | +way". Two things had to be settled before counting anything: | |
| 19 | + | |
| 20 | +- the arm must be **pixel-exact**. On a diverging arm the counts are polluted by | |
| 21 | + the divergence: a decoder reading the wrong coefficients also walks a different | |
| 22 | + number of units, so the count difference is a *symptom*, and the count cannot | |
| 23 | + distinguish cause from effect. Measured: `444_intrabc_rect4_witness` is wrong in | |
| 24 | + 390380 of 921600 samples, and `444_leaf8_oob` in 281306 of 737280. | |
| 25 | +- the pairing must not assume either side's own labels. | |
| 26 | + | |
| 27 | +Measured exactness of every 4:4:4 fixture in the crate (ours vs `aomdec | |
| 28 | +--rawvideo`, plane-concatenated, u16→u8): | |
| 29 | + | |
| 30 | +| fixture | pixels | pixel-exact? | | |
| 31 | +|---|---|---| | |
| 32 | +| `ll444_minp8_inter` | 6 frames | **yes** | | |
| 33 | +| `444_quad_leaf_tx_type` | 4 frames | **yes** | | |
| 34 | +| `444_lossy_rect4_inter_witness` | 2 frames | **yes** | | |
| 35 | +| `444_rect_strip_leaf_tx_type` | 3 frames | **yes** | | |
| 36 | +| `444_sb128rect_lr_witness` | 3 frames | **yes** | | |
| 37 | +| `444_intrabc_rect4_witness` | 1 frame | no (390380 / 921600 wrong) | | |
| 38 | +| `444_leaf8_oob` | 3 frames | no (281306 / 737280 wrong) | | |
| 39 | + | |
| 40 | +## 2. Method — the census, both sides, same frame | |
| 41 | + | |
| 42 | +**Ours.** A new env-gated rung `EC_CENSUS_UNIT` (`EC_CENSUS_UNIT=1`), one line | |
| 43 | +per coefficient unit **this decoder walks** — one per `read_coeffs` / | |
| 44 | +`read_coeffs_rect` call, which is exactly the object the round-4 count measured. | |
| 45 | +Fields: `n` (sequential index), `plane`, `w`, `h`, `tx`, `eob`, `all_zero`, | |
| 46 | +`entry_rng` (msac `range` before the unit's `txb_skip` read), `post_rng` (after | |
| 47 | +the unit). The plane comes from a thread-local stamped by the plane-owning | |
| 48 | +readers (`read_plane`, `read_inter_plane`, `read_inter_plane_rect`) and by | |
| 49 | +`read_coeffs_rect` from the real `plane` argument lane-av1chrtx already threads | |
| 50 | +in — a thread-local rather than a `read_coeffs` parameter because the three | |
| 51 | +luma-only call sites (`decode_rect_split`, `decode_block_rect64`, | |
| 52 | +`read_inter_plane_rect`'s corner) belong to other lanes. | |
| 53 | + | |
| 54 | +**Oracle.** No rebuild needed: the instrumented aomdec already brackets every | |
| 55 | +`av1_read_coeffs_txb` call with `EC_COEFF …rng=<pre>` on entry and | |
| 56 | +`EC_COEFF_VAL …rng=<post>` on exit (`EC_TRACE_COEFF=1`), with | |
| 57 | +`EC_COEFF_STEP tag=all_zero` / `tag=eob` inside the bracket. That is the same | |
| 58 | +five fields. | |
| 59 | + | |
| 60 | +**Pairing: by `post_rng`, never by plane label and never by walk position or | |
| 61 | +`n`.** `post_rng` is the msac state after the unit, so two units that consumed | |
| 62 | +the same bits end at the same state. This matters concretely here: pairing by | |
| 63 | +`n`/position invents matches the moment the two walks order a U and a V unit | |
| 64 | +differently, and pairing by plane label invents them whenever a walk's plane | |
| 65 | +attribution is what is in question. The walk is a two-pointer merge on `post_rng`; | |
| 66 | +a unit is emitted only when the two sides agree on the pairing key. | |
| 67 | + | |
| 68 | +**Buckets** (each difference lands in exactly one): | |
| 69 | + | |
| 70 | +- **(i) SAME UNIT** — the two sides' units pair, and plane/shape/eob/all-zero agree. | |
| 71 | +- **(ii) OUR-ONLY** — we walk a unit the oracle does not, at that bit position. | |
| 72 | +- **(iii) ORACLE-ONLY** — the oracle walks one we do not. | |
| 73 | +- **(iv) SIZE/ORDER** — the units pair but disagree on shape, plane label, eob | |
| 74 | + or all-zero. | |
| 75 | + | |
| 76 | +## 3. Per-bucket table (whole stream, paired by `post_rng`) | |
| 77 | + | |
| 78 | +| arm | pixels | units ours / oracle | (i) | (ii) | (iii) | (iv) | | |
| 79 | +|---|---|---|---|---|---|---| | |
| 80 | +| `ll444_minp8_inter` (6 frames) | exact | **11292 / 11292** | **11292** | 0 | 0 | 0 | | |
| 81 | +| `444_lossy_rect4_inter_witness` (mixed shapes) | exact | **1373 / 1373** | **1373** | 0 | 0 | 0 | | |
| 82 | +| `444_quad_leaf_tx_type` | exact | **192 / 192** | **192** | 0 | 0 | 0 | | |
| 83 | +| `444_rect_strip_leaf_tx_type` | exact | 591 / 591 | 587 | 0 | 0 | 4 | | |
| 84 | +| `444_sb128rect_lr_witness` | exact | 467 / 467 | 463 | 0 | 0 | 4 | | |
| 85 | +| `444_intrabc_rect4_witness` | **diverges** | 2740 / 2395 | 1909 | 823 | 478 | 8 | | |
| 86 | +| `444_leaf8_oob` | **diverges** | 1778 / 1678 | 1027 | 751 | 651 | 0 | | |
| 87 | + | |
| 88 | +Per-plane split on the primary arm, both sides identical: | |
| 89 | + | |
| 90 | +| | luma | u | v | | |
| 91 | +|---|---|---|---| | |
| 92 | +| units (ours) | 3764 | 3764 | 3764 | | |
| 93 | +| units (oracle) | 3764 | 3764 | 3764 | | |
| 94 | +| of which coded (`txb_skip == 0`) | 975 | 1793 | 1859 | | |
| 95 | + | |
| 96 | +So the round-4 asymmetry does not survive on an arm whose pixels are right. | |
| 97 | +Reproduced exactly on the diverging arm: `444_intrabc_rect4_witness` reads 1518 | |
| 98 | +luma / 611 / 611 against the oracle's 1309 / 543 / 543 — the luma 1309 and the | |
| 99 | +per-plane 543/543 are *the round-4 oracle numbers*, so the count was never a | |
| 100 | +counting artefact. It was a real count, taken on an arm that does not decode. | |
| 101 | + | |
| 102 | +## 4. The eight (iv) entries on the exact arms are a tracing artefact, not a defect | |
| 103 | + | |
| 104 | +On `444_rect_strip_leaf_tx_type` and `444_sb128rect_lr_witness`, 4 units each | |
| 105 | +bucket as (iv). All four have **identical `entry_rng`, `post_rng`, `eob` and | |
| 106 | +all-zero flag on both sides** and differ only in the reported extent: | |
| 107 | + | |
| 108 | +``` | |
| 109 | +idx 202: ours plane=0 32x32 eob=0 az=true | oracle plane=0 txsz=TX_64X64 eob=0 az=true | post=41441 | |
| 110 | +idx 498: ours plane=0 32x32 eob=0 az=true | oracle plane=0 txsz=TX_64X64 eob=0 az=true | post=33499 | |
| 111 | +``` | |
| 112 | + | |
| 113 | +Both sides read exactly one `txb_skip` symbol and consumed the same bits; ours | |
| 114 | +reports the *corner* it decoded (the 32×32 low-frequency corner of a 64×64 | |
| 115 | +luma block — `read_coeffs`' `rect_shape` path, spec 5.11.40) while libaom's | |
| 116 | +`EC_COEFF` prints the `TX_64X64` it was called with. A shape **label** | |
| 117 | +difference on an otherwise identical unit, not a walk difference. Two of the | |
| 118 | +four also carry a plane-label difference with the same entry/post rng — the same | |
| 119 | +class. Under the ticket's own rule ("a real divergence requires a unit in (i) or | |
| 120 | +(iv) whose **eob/values** differ") these are neither: no eob and no value | |
| 121 | +differs anywhere on any pixel-exact arm. | |
| 122 | + | |
| 123 | +## 5. Gate | |
| 124 | + | |
| 125 | +`a_pixel_exact_444_stream_walks_the_same_coefficient_units_the_oracle_does` | |
| 126 | +(`crates/ec-av1/src/stream.rs`) pins the walk's object shape on two | |
| 127 | +pixel-exact 4:4:4 arms: | |
| 128 | + | |
| 129 | +- `ll444_minp8_inter` — all-TX_4X4 (min-partition-8 lossless): `[3764, 3764, | |
| 130 | + 3764]` units, `[975, 1793, 1859]` coded; | |
| 131 | +- `444_lossy_rect4_inter_witness` — **mixed shapes** (4×4, 8×8, 8×4, 4×8, 4×16, | |
| 132 | + 16×4, 8×16, 16×16): `[629, 372, 372]` units, `[130, 253, 278]` coded. | |
| 133 | + | |
| 134 | +The second arm is not redundant: the first is uniformly 4×4 and would not notice | |
| 135 | +a var-tx walk that started folding 8×8 leaves. Both numbers are the oracle's own | |
| 136 | +census on the same stream. | |
| 137 | + | |
| 138 | +**Mutation-proven.** Dropping 8×8 units from the walk turns it red by name: | |
| 139 | + | |
| 140 | +``` | |
| 141 | +the mixed-shape 4:4:4 walk changed -- [571, 313, 313] against the oracle's [629, 372, 372] | |
| 142 | + left: [571, 313, 313] right: [629, 372, 372] | |
| 143 | +``` | |
| 144 | + | |
| 145 | +and the all-4×4 arm is untouched by that mutation — which is exactly why both | |
| 146 | +arms are pinned. | |
| 147 | + | |
| 148 | +**4:2:0 control.** The census is armed per frame from the sequence header's | |
| 149 | +subsampling (`set_census_444(ss_x, ss_y)` in `stream.rs`, beside | |
| 150 | +`set_mono`/`set_subsampling`), so at 4:2:0/4:2:2 every counter stays zero; the | |
| 151 | +gate asserts exactly `(0, 0, 0)` for both the unit and coded-unit counters on a | |
| 152 | +committed 4:2:0 stream that decodes. The accounting is separate from the sibling | |
| 153 | +counter pair the ticket mentions. | |
| 154 | + | |
| 155 | +## 6. What this settles for the next lane | |
| 156 | + | |
| 157 | +- The 636-vs-1086 / 2052-vs-1309 signal is **retracted**: it was measured on | |
| 158 | + `444_intrabc_rect4_witness`, which is wrong in 390380 of 921600 samples. Do not | |
| 159 | + carry it forward as a walk-shape hypothesis. | |
| 160 | +- Counting the coefficient units on a **pixel-exact 4:4:4** arm reproduces the | |
| 161 | + oracle exactly, per plane, per unit. The census is now a one-command check: | |
| 162 | + `EC_CENSUS_UNIT=1 cargo run -p ec-av1 --example decode_probe -- <arm>.obu` | |
| 163 | + against `EC_TRACE_COEFF=1 aomdec`, paired by `post_rng`. | |
| 164 | +- If a future lane sees a count asymmetry, the first question is whether the arm | |
| 165 | + decodes — not whether the walk shape differs. That check is now the gate. | |
| 166 | + | |
| 167 | +## 7. Not fixed here, by design | |
| 168 | + | |
| 169 | +The 4:4:4 intra-BC chroma divergence (`444_intrabc_rect4_witness`, 390380 / | |
| 170 | +921600) is untouched: this lane's deliverable is the census. Per §4 there is no | |
| 171 | +value-level divergence on any pixel-exact arm for this census to point at, so the | |
| 172 | +remaining fork is not a coefficient-read-count problem and needs a fresh charter. | |
| 173 | + | |
| 174 | +## 8. Method notes for whoever repeats this | |
| 175 | + | |
| 176 | +- **Pair by `post_rng`.** Position/`n` pairing invents matches when a walk | |
| 177 | + orders U and V differently; plane-label pairing invents them when plane | |
| 178 | + attribution is the thing in question. | |
| 179 | +- **A pixel-exact arm is mandatory.** On `444_intrabc_rect4_witness` the counts | |
| 180 | + diverge by 823/478 units *because* the decode does; the count difference is a | |
| 181 | + symptom, not a cause. | |
| 182 | +- **`EC_SYMR` is still the right rung for symbol-level work**; `EC_COEFF_STEP` | |
| 183 | + is filtered (the oracle prints `tag=tx_type` for all three planes but reads it | |
| 184 | + only for Y), so it is not a per-unit bracket. `EC_COEFF`/`EC_COEFF_VAL` are | |
| 185 | + the per-unit bracket and were already in the oracle build — no rebuild needed. | |
| 186 | +- Our own rung must carry the real plane: `read_coeffs` had no plane parameter, | |
| 187 | + and a stamp inherited from whichever reader ran last mis-attributes chroma as | |
| 188 | + luma (this bit the census's first run and is the same trap `d791c464` fixed for | |
| 189 | + the rect trace). |