From ddf43e86ffb3d750efc0cd9c77848fd97ff0bf3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 25 Sep 2026 21:11:08 +0300 Subject: [PATCH] ec-av1: lane-av1wavefront -- the recon wavefront replayed chroma against a default-seeded FrameCtx: wave_worker carries only bit_depth/enable_edge_filter into its fresh context, so every replay-side ss_x/ss_y read (the deferred chroma builds' mv_to_q4(.., ss_x(fctx)) reference positions and exec_intra's CfL AC signal) saw the 4:2:0 constructor default on any stream whose sequence says otherwise; at 4:4:4 each worker fetched its chroma prediction at HALF the true reference position and the 444_sb128rect witness lost its chroma planes at PREFILT (f1 U 17504 / V 3, f2 U 25472 / V 1472, Y exact) while every existing recon-threads gate stream stayed exact because 4:2:0 is what the default already was; WaveState now carries the frame's subsampling pair next to bit_depth and the worker seeds it, fixing all replay-side ss readers with one field and no op-shape change; serial byte-identical (inline path never builds a WaveState), recon=2 and recon=4 byte-exact vs serial on all three fixture frames, and the 1-vs-4 recon-threads gate pins the witness with a mutation proof (worker ss seed commented out fails exactly on the new fixture, frame 1 U differs) --- crates/ec-av1/src/decode.rs | 17 +++++++++- crates/ec-av1/src/stream.rs | 7 ++++ lanes/av1wavefront.report.md | 66 ++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 lanes/av1wavefront.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index af8ee876..d81a148e 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2991,10 +2991,18 @@ pub(crate) struct WaveState { q: std::sync::Mutex, cv: std::sync::Condvar, planes: ReconPlanes, - /// The two [`FrameCtx`] fields reconstruction reads (`sample_max` is + /// The [`FrameCtx`] fields reconstruction reads (`sample_max` is /// `bit_depth`'s; everything else a `reconstruct*` needs is in the op). bit_depth: u8, enable_edge_filter: bool, + /// lane-av1wavefront: the sequence's chroma subsampling. The replay-side + /// readers -- the deferred chroma builds' `mv_to_q4(.., ss_x(fctx))` + /// positions and `exec_intra`'s CfL AC signal -- must see the FRAME's + /// pair, not [`FrameCtx::new`]'s 4:2:0 default: on a 4:4:4 stream the + /// default halved every worker's chroma reference position and lost the + /// chroma planes (the 444_sb128rect witness, U 17504 / V 3 at PREFILT on + /// frame 1) while every 4:2:0 gate stream stayed accidentally exact. + subsampling: (u8, u8), last_col: usize, } @@ -3147,6 +3155,9 @@ fn wave_worker(st: &WaveState, idx: usize) { let fctx = FrameCtx::new(); fctx.bit_depth.set(st.bit_depth); fctx.enable_edge_filter.set(st.enable_edge_filter); + let (sx, sy) = st.subsampling; + fctx.subsampling_x.set(sx); + fctx.subsampling_y.set(sy); let stats = wave_stats(); let slot = idx.min(WS_SLOTS - 1); loop { @@ -3243,6 +3254,10 @@ impl<'a> WaveGuard<'a> { ), bit_depth: fctx.bit_depth.with(std::cell::Cell::get), enable_edge_filter: fctx.enable_edge_filter.with(std::cell::Cell::get), + subsampling: ( + fctx.subsampling_x.with(std::cell::Cell::get), + fctx.subsampling_y.with(std::cell::Cell::get), + ), last_col: cols - 1, }); let batch = crate::par::Batch::new("ec-av1-recon"); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 06fc1380..2a211bc6 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -10129,6 +10129,13 @@ pub(crate) mod tests { "reelb_arf_witness.obu", "palette_screen_witness.obu", "palette_screen_witness_10bit.obu", + // lane-av1wavefront: the 4:4:4 inter witness. The wavefront's + // replay-side chroma (`mv_to_q4(.., ss_x(fctx))` in the deferred + // builds, `exec_intra`'s CfL AC) used to read the worker's fresh + // `FrameCtx` 4:2:0 DEFAULT instead of the frame's subsampling -- + // invisible on the three 4:2:0 streams above, chroma-only loss on + // this one (f1 U 17504 / V 3, f2 U 25472 / V 1472 at PREFILT). + "444_sb128rect_lr_witness.obu", ] { let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) .join("fixtures") diff --git a/lanes/av1wavefront.report.md b/lanes/av1wavefront.report.md new file mode 100644 index 00000000..451c7622 --- /dev/null +++ b/lanes/av1wavefront.report.md @@ -0,0 +1,66 @@ +# lane-av1wavefront — defect B fixed: the wavefront replay read frame state off a default-seeded `FrameCtx`; 4:4:4 chroma lost, 4:2:0 accidentally exact + +## Outcome + +1. DEFECT B (lanes/av1lrflush.report.md) reproduced and fixed at the source. + `EC_AV1_RECON_THREADS>1` diverged from serial at PREFILT, chroma-only, on + `444_sb128rect_lr_witness.obu` (sha256 `27825e14…61e80`, verified): f1 U + 17504 samples (first (0,1)) / V 3 (first (67,29)), f2 U 25472 (first (0,0)) + / V 1472 (first (2,128)), Y byte-exact, f0 exact — the report's own numbers, + re-measured off `EC_AV1_PREFILT_DUMP` runs at recon=2/filter=1 vs + recon=1/filter=1. +2. ROOT CAUSE — not a stride/plane-index bug in the write records, and not a + lost op: [`wave_worker`] seeds each recon worker with a FRESH + [`FrameCtx`] (`FrameCtx::new()`), carrying only `bit_depth` and + `enable_edge_filter`. Every replay-side read of the frame's chroma + subsampling therefore saw the CONSTRUCTOR DEFAULT `subsampling = (1, 1)` + (4:2:0) regardless of the sequence. On a 4:4:4 stream the deferred chroma + prediction builds read `ss_x(fctx)` at CLOSURE-RUN time — + `mv_to_q4(px, mv.1, ss_x(fctx))` in the sub-8x8 group's `build_c` (and the + same shape in the 4x4-piece and leaf-8 chroma builds) — so every worker + fetched its chroma reference at HALF the true position: the prediction was + wrong, the recorded op replayed faithfully at the wrong content. `exec_intra`'s + CfL AC read (`cfl_ac_ss(.., ss_x(fctx), ss_y(fctx))`) is the same class one + reader over. Serial is exact because there the closure runs at push time on + the parse thread's real context. Every earlier wavefront gate stream is + 4:2:0, where the default happens to BE the frame's pair — the defect was + invisible to the whole existing recon-threads gate set. +3. FIX: `WaveState` carries `subsampling: (u8, u8)`; `WaveGuard::install` + copies it from the tile's `FrameCtx` next to `bit_depth`; + `wave_worker` seeds it into the worker context. All replay-side ss readers + (the three `build_c` closure shapes and `exec_intra`'s CfL) are fixed by + the one field; no recorded op changed shape, no push-site read moved. +4. Verified: + - recon=2/filter=1 and recon=4/filter=1 now byte-identical to serial on + all three frames of the fixture (`dump_yuv` output compare; the example + binary rebuilt from this tree). + - Serial byte-identical pre/post fix (same compare against the pre-fix + binary's serial run) — the inline path never constructs a `WaveState`. + - Gate: `444_sb128rect_lr_witness.obu` added to + `a_real_stream_reconstructs_identically_with_one_and_four_recon_threads` + (the 1-vs-4 recon-threads byte-exact gate, per-frame Y/U/V asserts). + Mutation-verified: commenting the worker's `subsampling_x/y.set` seed + makes the gate FAIL exactly on the new fixture ("frame 1 U differs at 4 + recon threads") while the three 4:2:0 fixtures still pass — the gate is + non-vacuous and discriminates the class. Fix restored, gate green. + - `cargo check -p ec-av1`: 0 warnings. +5. CLASS SWEEP (replay-side `FrameCtx` reads on a worker): enumerated every + fctx read reachable from `exec_op` → `exec_intra`/`exec_mc`/PredBuild + closures: `sample_max` (bit_depth — carried), `enable_edge_filter` + (carried), `subsampling` (this fix), and nothing else — + `reconstruct_mc_rect` reads only `sample_max`; `mc::predict`'s + `interp_filter` read is not in any replay path (the deferred builds pass + the explicitly parsed kernels to `predict_maybe_scaled`; the two + `mc::predict` callers are `#[cfg(test)]` gate code). Parse-side ss reads + run on the parse thread's real context and were never wrong. + +## Not touched + +- Entropy band stamping / `read_coeffs_rect` / `decode_rect4_16_strip` + (Agent044's defect A territory) — nothing here lands in entropy code. +- Osman4's LR pipeline (proven clean; recon=1/filter=4 stays exact). +- The 4:2:0 group-tail chroma SKIP arm (reserved to its owning lane). + +## State + +Committed on lane-av1-wavefront. No push.