forge
Explore
Log in

Don't you dare go Hollow

A real stream decodes identically at 1 and at 4 threads

Browse files at this commit

5f3725c3f6a7e3d4dd0d5101a98ecd601d3b2cb2Ahmet Kaan GümüşParent: b3a78b4
  • test
    • a real stream decodes identically at 1 and at 4 threads
Show full message
test(av1): a real stream decodes identically at 1 and at 4 threads

Two real fixtures through `decode_stream_with_threads`, every sink call
compared (decode index, shown flag, all three planes).
`reelb_arf_witness.obu` is the arm that proves the parallel path -- 18 of
its 40 coded frames are leaves of the reference graph and really are
decoded off the main thread, and it carries hidden alt-refs, where
"output in coded order" and "output in worker completion order" differ;
`palette_screen_witness.obu` is the complement, an 8-bit screen stream
that dispatches nothing because every coded frame refreshes a slot. The
dispatch counter is asserted in both directions (18 and 0), so neither
arm can pass vacuously.
crates/ec-av1/src/stream.rsmodified+65 -0
@@ -32124,6 +32124,71 @@ mod tests {
3212432124 );
3212532125 }
3212632126
32127+ /// lane-thread2 (iv): frame-parallel decoding changes nothing a caller
32128+ /// can observe. Two real streams are decoded through
32129+ /// [`decode_stream_with_threads`] at 1 and at 4 threads and every sink
32130+ /// call is compared -- decode index, shown flag, and all three planes.
32131+ ///
32132+ /// `reelb_arf_witness.obu` is the one that proves the parallel path: 18 of
32133+ /// its 40 coded frames are leaves of the reference graph (shown,
32134+ /// non-key, `refresh_frame_flags == 0`), so 18 frames really are decoded
32135+ /// off the main thread, and it carries hidden alt-refs, which is exactly
32136+ /// the case where "output in coded order" is not the same as "output in
32137+ /// the order workers finish". `palette_screen_witness.obu` is the
32138+ /// complement: an 8-bit screen stream whose every coded frame refreshes a
32139+ /// slot, so at 4 threads it dispatches NOTHING and pins that the threaded
32140+ /// entry point is byte-identical on the inline path too. The dispatch
32141+ /// counter is asserted in both directions, so neither arm can pass
32142+ /// vacuously.
32143+ #[test]
32144+ fn a_real_stream_decodes_identically_with_one_and_four_threads() {
32145+ const NAME: &str = "a_real_stream_decodes_identically_with_one_and_four_threads";
32146+ // (fixture, shown frames, leaf frames a 4-thread run must dispatch)
32147+ for (fixture, shown_frames, want_leaves) in [
32148+ ("fixtures/reelb_arf_witness.obu", 37usize, 18usize),
32149+ ("fixtures/palette_screen_witness.obu", 15, 0),
32150+ ] {
32151+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(fixture);
32152+ let stream = std::fs::read(&path)
32153+ .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display()));
32154+ let run = |threads: usize| -> Vec<(usize, bool, Picture)> {
32155+ let mut out = Vec::new();
32156+ decode_stream_with_threads(&stream, threads, |p, idx, shown| {
32157+ out.push((idx, shown, p.clone()));
32158+ Ok(())
32159+ })
32160+ .unwrap_or_else(|e| panic!("{NAME}: {fixture} at {threads} threads refused: {e}"));
32161+ out
32162+ };
32163+ let serial = run(1);
32164+ let before = leaf_frames_dispatched();
32165+ let parallel = run(4);
32166+ let dispatched = leaf_frames_dispatched() - before;
32167+ assert_eq!(
32168+ dispatched, want_leaves,
32169+ "{NAME}: {fixture} dispatched {dispatched} leaf frames to workers, expected {want_leaves}"
32170+ );
32171+ assert_eq!(
32172+ serial.iter().filter(|f| f.1).count(),
32173+ shown_frames,
32174+ "{NAME}: {fixture} shown frames"
32175+ );
32176+ assert_eq!(
32177+ serial.len(),
32178+ parallel.len(),
32179+ "{NAME}: {fixture} sink call count differs"
32180+ );
32181+ for (i, (a, b)) in serial.iter().zip(&parallel).enumerate() {
32182+ assert_eq!(a.0, b.0, "{NAME}: {fixture} sink {i} decode index");
32183+ assert_eq!(a.1, b.1, "{NAME}: {fixture} sink {i} shown flag");
32184+ assert_eq!(a.2.y, b.2.y, "{NAME}: {fixture} sink {i} luma");
32185+ assert_eq!(a.2.u, b.2.u, "{NAME}: {fixture} sink {i} U");
32186+ assert_eq!(a.2.v, b.2.v, "{NAME}: {fixture} sink {i} V");
32187+ }
32188+ eprintln!("{NAME}: {fixture} {} sink calls identical, {dispatched} decoded on workers", serial.len());
32189+ }
32190+ }
32191+
3212732192 /// lane-frame36 r2: the hidden-ARF witness. `crates/ec-av1/fixtures/
3212832193 /// reelb_arf_witness.obu`, 32126 bytes, sha256
3212932194 /// `7f3b060da5aa9c537633e760c4af71316237db7692f6ae0d459bd2c2dd867d37`: