diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index a6081b24..2ce94401 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -278,10 +278,11 @@ pub(crate) struct TxbTables<'a> { pub txb_skip: &'a mut [[u16; 3]], /// The end-of-block group, whose alphabet the transform size sets. pub eob_pt: &'a mut [u16], - /// `eob_pt`'s `TX_CLASS_HORIZ`/`TX_CLASS_VERT` sibling table (r5): read - /// instead of `eob_pt` once this TU's `tx_type` is known to be - /// `V_DCT`/`H_DCT`. `None` for any size/set whose `tx_type` alphabet - /// cannot produce those two symbols (chroma, and every inter set). + /// Read instead of `eob_pt` once this TU's `tx_type` is known to be + /// `V_DCT`/`H_DCT` (lane-intertx doc fix: every set here carries the + /// row -- the older "none for chroma and every inter set" note + /// described the r5 alphabet, before the wider inter/chroma-reachable + /// sets made those classes reachable there). pub eob_pt_class1: Option<&'a mut [u16]>, /// The top bit of the offset inside that group. pub eob_extra: &'a mut [[u16; 3]; 9], diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 06c3e511..023dbbbe 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -18711,10 +18711,19 @@ fn read_inter_luma8( /// sync and only corrupted the inverse transform (one 64x64 superblock of /// high-frequency chroma noise, luma bit-exact). pub(crate) fn reduce_inherited_chroma_tx_type(t: TxType, w: usize, h: usize, fctx: &crate::decode::FrameCtx) -> TxType { + reduce_inherited_chroma_tx_type_flagged(t, w, h, fctx.reduced_tx_set_inter.with(std::cell::Cell::get)) +} + +/// [`reduce_inherited_chroma_tx_type`] against an explicit `reduced_tx_set` +/// bit (lane-intertx): the WRITER calls this with the frame's own header bit +/// ([`crate::cdf_state::Cdfs::reduced_tx_set`]) to derive the type an inter +/// block's chroma transform is coded with, the same derivation its reader +/// makes -- it has no `FrameCtx` in reach and must not silently read one +/// whose value can lag the frame being written (class `stale-context-bit`). +pub(crate) fn reduce_inherited_chroma_tx_type_flagged(t: TxType, w: usize, h: usize, reduced: bool) -> TxType { use TxType::*; let sqr_up = w.max(h); let sqr = w.min(h); - let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get); // `av1_get_ext_tx_set_type(tx_size, is_inter = 1, reduced)`. let allowed: &[TxType] = if sqr_up > 32 { // EXT_TX_SET_DCTONLY @@ -34434,6 +34443,10 @@ pub(crate) fn decode_inter_frame_tile( interp_fixed: Option, enable_dual_filter: bool, reference_select: bool, + // lane-intertx: this frame header's own `reduced_tx_set` (spec 5.9.2) -- + // see [`decode_inter_frame_tile_lr`]'s parameter. Same stale-header + // class as `tx_select` below. + reduced_tx_set: bool, // This frame header's `tx_mode == TxMode::Select`: `Encoded::tx_select`. // Hard-coding `false` here desynced at the first `tx_depth` symbol once // inter frames coded Select by default (class: test asserts against a @@ -34454,7 +34467,7 @@ pub(crate) fn decode_inter_frame_tile( decode_inter_frame_tile_lr( data, mi_cols, mi_rows, base_q_idx, frame_width, frame_height, refpix, cdef, loop_filter, allow_high_precision_mv, force_integer_mv, interp_fixed, - enable_dual_filter, reference_select, tx_select, + enable_dual_filter, reference_select, reduced_tx_set, tx_select, &LoopRestorationParams::default(), initial_cdfs, NO_SIGN_BIAS, false, // `enable_filter_intra`: as the `false`s beside it, this convenience // entry names a stream written without the sequence bit (lane-fintra). @@ -34480,6 +34493,15 @@ pub(crate) fn decode_inter_frame_tile_lr( interp_fixed: Option, enable_dual_filter: bool, reference_select: bool, + // lane-intertx: this frame header's own `reduced_tx_set` (spec 5.9.2). + // The wrapper used to hard-code `true` ("the tests all code the reduced + // sets") -- true until the widened inter search put 1-D/DTT types on + // `reduced_tx_set = 0` frames' inter luma, whose CHROMA then inherits + // the type against this very bit + // ([`reduce_inherited_chroma_tx_type`]): guessing `true` mis-derives + // every inherited chroma type and desyncs the tile (class: test asserts + // against a stale header, next instance). + reduced_tx_set: bool, tx_select: bool, lr: &LoopRestorationParams, initial_cdfs: Option, @@ -34537,9 +34559,9 @@ pub(crate) fn decode_inter_frame_tile_lr( interp_fixed, enable_dual_filter, reference_select, - // lane-txi: this wrapper's callers are the decoder's own tests, which - // all code the reduced sets. - true, + // lane-intertx: this frame's own bit, not the hardcoded `true` -- + // see the parameter's note above. + reduced_tx_set, tx_select, lr, initial_cdfs, @@ -38775,6 +38797,9 @@ mod tests { Some(mc::InterpFilterKind::Regular), false, false, + // The fixture's own implied header codes the reduced sets (the + // wrapper's old hardcoded value). + true, false, None, false, @@ -39268,6 +39293,12 @@ mod tests { // `false` (stale-header class -- a `reference_select` stream // reads a `comp_mode` symbol this decode would skip). crate::encode::reference_select(), + // lane-intertx: this frame's own `reduced_tx_set` -- the + // bit the chroma inheritance reduces against. The wrapper + // used to guess `true`, which mis-derived every inherited + // chroma type on a screen frame's widened inter blocks + // (stale-header class). + frame.reduced_tx_set, frame.tx_select, &frame.loop_restoration, Some(frame.start_cdfs.0.clone()), @@ -39610,9 +39641,10 @@ mod tests { // The encoder's own `reference_select` (spec 5.9.22): these // GOP round trips decode a tile the ENCODER wrote, so the // header bit must be the one it wrote, not a hard-coded - // `false` (stale-header class -- a `reference_select` stream - // reads a `comp_mode` symbol this decode would skip). crate::encode::reference_select(), + // lane-intertx: the frame's own `reduced_tx_set` -- see the + // first GOP round trip's note. + frame.reduced_tx_set, frame.tx_select, &frame.loop_restoration, Some(frame.start_cdfs.0.clone()), diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 240a9e42..d7f7a60c 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -472,21 +472,24 @@ fn inter_tx_type_search() -> InterTxSearch { /// The inter luma [`TxbSet`] a `tx`-sided transform unit reads, `None` for the /// 64-point one (it codes no `tx_type` symbol). -/// lane-txw: the INTER half of the widening is still NOT applied here, and -/// the reason lane-txi recorded (the `refs` lane's DPB bookkeeping) was -/// WRONG -- the refusal is `refusal-from-own-desync` twice over. Half of it +/// lane-txw history, resolved by lane-intertx: the INTER half of the +/// widening was blocked by `refusal-from-own-desync` twice over. Half of it /// was this writer coding a `V_DCT`/`H_DCT` unit as `TX_CLASS_2D` -/// (`tile::write_coeffs`, fixed by this lane, which is what unblocked the -/// intra half). What remains is the CHROMA inheritance: an inter block's +/// (`tile::write_coeffs`, fixed by lane-txw, which unblocked the intra +/// half). The other half was the CHROMA inheritance: an inter block's /// chroma transform type is the luma type reduced to the chroma size's set /// (`decode::reduce_inherited_chroma_tx_type`), and (a) the encoder never -/// sets `FrameCtx::reduced_tx_set_inter`, so [`recode_inter_chroma`] reduces -/// against the REDUCED allowance while a `reduced_tx_set = 0` frame's -/// decoder allows the full one, and (b) `tile::write_block_planes` codes -/// every chroma plane as `DCT_DCT`, so an inherited 1-D type desyncs the -/// chroma exactly as luma did. Both are deferred with the wider inter search -/// itself; the intra half needs neither (an intra block's chroma type comes -/// off its own UV mode, never off luma). +/// set `FrameCtx::reduced_tx_set_inter`, so [`recode_inter_chroma`] reduced +/// against a STALE allowance, and (b) `tile::write_block_planes` coded +/// every chroma plane as `DCT_DCT`, so an inherited 1-D type desynced the +/// chroma exactly as luma did. lane-intertx fixed both -- the frame sets +/// its own bit on the context (`encode_inter_frame`), the writer derives +/// the chroma type from this frame's own header bit +/// (`reduce_inherited_chroma_tx_type_flagged`) -- and the widened SEARCH +/// names these sets through [`luma_set_for`] at its call sites, so the +/// wider candidates are reachable and honestly priced. The intra half +/// never needed either (an intra block's chroma type comes off its own UV +/// mode, never off luma). fn inter_luma_set(tx: usize) -> Option { Some(match tx { 4 => TxbSet::Luma4Inter, @@ -1794,6 +1797,7 @@ pub(crate) fn crop_encoded(encoded: &Encoded, width: usize, height: usize) -> En tx_select: encoded.tx_select, switchable_motion_mode: encoded.switchable_motion_mode, screen: encoded.screen, + reduced_tx_set: encoded.reduced_tx_set, start_cdfs: encoded.start_cdfs.clone(), next_cdfs: encoded.next_cdfs.clone(), loop_filter: encoded.loop_filter, @@ -1880,6 +1884,14 @@ pub struct Encoded { /// palette-mode symbols under it, so a raw tile decode that guessed /// `false` would desync at the first block (same class as `tx_select`). pub(crate) screen: bool, + /// This frame header's own `reduced_tx_set` (spec 5.9.2) -- the bit that + /// picks the inter `tx_type` alphabets AND, on an inter block, the + /// allowance the chroma transform's inherited type reduces against + /// ([`crate::decode::reduce_inherited_chroma_tx_type`]). A raw tile + /// decode that guesses `true` here mis-derives every inherited chroma + /// type on a `reduced_tx_set = 0` frame (lane-intertx; same class as + /// `tx_select`/`screen` above). + pub(crate) reduced_tx_set: bool, /// This frame header's chosen loop restoration parameters, threaded for /// the same reason as `loop_filter` -- and doubly so: the per-unit /// filters themselves are coded in `tile`, so a decode of it under a @@ -5109,7 +5121,15 @@ fn commit_inter_luma( let mut flat_typed: Option = None; let mut flat_type = TxType::DctDct; if !skip { - if let Some(fset) = inter_luma_set(side) { + // lane-intertx: on a `reduced_tx_set = 0` frame the search names the + // Set1 alphabet the writer codes into ([`luma_set_for`], the shape + // the intra search already takes), which is what makes the wider + // seven-type candidate list below reachable -- and prices every + // candidate, `IDTX` included, in the alphabet its symbol is really + // coded into. + if let Some(fset) = + inter_luma_set(side).map(|set| luma_set_for(set, search.screen)) + { let lambda = search.lambda * tx_type_lambda_mult(); let cost = |t: &Trial| t.sse + lambda * t.bits; for &tx_type in inter_tx_type_candidates(fset, search.screen) { @@ -5200,14 +5220,17 @@ fn commit_inter_luma( return (flat_ref.levels.clone(), 0, flat_gain, vec![flat_type]); } let tx = side / 2; - let set = if tx >= 32 { - // lane-b64b: the 64x64 root's halved transform is TX_32X32. - TxbSet::Luma32Inter - } else if tx >= 16 { - TxbSet::Luma16Inter - } else { - TxbSet::Luma8Inter - }; + let set = luma_set_for( + if tx >= 32 { + // lane-b64b: the 64x64 root's halved transform is TX_32X32. + TxbSet::Luma32Inter + } else if tx >= 16 { + TxbSet::Luma16Inter + } else { + TxbSet::Luma8Inter + }, + search.screen, + ); let mut levels = vec![0i32; side * side]; let (mut sse, mut bits) = (0.0, 0.0); let mut units = Vec::with_capacity(4); @@ -8859,6 +8882,7 @@ pub(crate) fn encode_key_frame_inner( // A key frame codes no inter block, so no motion_mode symbol. switchable_motion_mode: false, screen, + reduced_tx_set: header.reduced_tx_set, next_cdfs: start_cdfs.clone(), start_cdfs, loop_filter: header.loop_filter, @@ -12594,6 +12618,14 @@ pub(crate) fn encode_inter_frame( // lane-txi, as on the key frame: the header bit the writer's own // `Cdfs` then reads for every luma `tx_type` symbol. header.reduced_tx_set = !wide_tx_set(screen); + // lane-intertx, desync (a): the frame context this value is read back + // through ([`decode::reduce_inherited_chroma_tx_type`] inside + // `recode_inter_chroma`, and every inter decode helper the search's own + // trial decode shares) must carry THIS frame's bit, not whatever the + // previous frame's trial decode last left in the shared cell -- a stale + // `true` here narrows the chroma allowance the search reconstructs + // against under the one the header's bit actually allows. + fctx.reduced_tx_set_inter.set(header.reduced_tx_set); // The search prices coefficients against the tables this frame's writer // starts from, not against the defaults (lane-av1txbits) -- but only on a // frame the screen detector said no to (lane-av1price2): armed HERE, after @@ -14088,6 +14120,7 @@ pub(crate) fn encode_inter_frame( tx_select, switchable_motion_mode, screen, + reduced_tx_set: header.reduced_tx_set, start_cdfs, next_cdfs, loop_filter: header.loop_filter, diff --git a/crates/ec-av1/src/encoder.rs b/crates/ec-av1/src/encoder.rs index 9e2644f1..57da7296 100644 --- a/crates/ec-av1/src/encoder.rs +++ b/crates/ec-av1/src/encoder.rs @@ -4993,6 +4993,107 @@ mod tests { eprintln!("SKIP the ffmpeg half: no ffmpeg"); } } + /// lane-intertx's witness: on a clip the screen detector calls + /// NON-screen, the inter luma search offers the wider + /// `reduced_tx_set = 0` alphabets and CODES a 1-D `V_DCT`/`H_DCT` unit + /// (a `coded > 0` guard on the committed-winners census, class + /// `gate-blind-to-feature`), the block's chroma transforms inherit that + /// type reduced to the chroma size's set against the frame's own honest + /// header bit, and BOTH decoders reconstruct every frame sample-exact on + /// ALL THREE planes -- chroma is the plane the inheritance desync + /// corrupts, so luma-only comparisons cannot see it. + #[test] + #[ignore = "sets process-global search levers: run it alone"] + fn a_non_screen_inter_clip_codes_a_one_d_type_both_decoders_read_every_plane_exactly() { + let _knobs = crate::speed::knob_write(); + let _gate_lock = crate::stream::tests::lock_gate_counters(); + crate::encode::set_intra_tx_search(Some(true)); + crate::encode::set_inter_tx_search(Some(true)); + crate::encode::set_wide_tx_set(Some(true)); + crate::encode::force_screen(Some(false)); + let (width, height) = (320usize, 192usize); + // The wide witness's moving card: vertical steps (where a 1-D + // `V_DCT`/`H_DCT` beats the 2-D DCT on the motion-compensated + // residual), ramps (`ADST`) and moving plateaus (`IDTX`), translated + // a few samples per frame so the inter search sees real motion. + let sources: Vec = (0..4) + .map(|t| { + let mut p = test_card(width, height, t * 3); + for y in 0..height { + for x in 0..width { + let v = match ((x + t * 5) / 16 % 2, (y + t * 3) / 16 % 2) { + (0, 0) => 16u16, + (1, 0) => 235, + (0, 1) => ((x + t) % 64 * 3) as u16, + _ => ((y + t) % 64 * 3) as u16, + }; + p.y[y * width + x] = v; + } + } + p + }) + .collect(); + let config = EncoderConfig { + width, + height, + base_q_idx: 90, + gop: 4, + colour: Colour::Bt709Limited, + tile_cols_log2: 0, + tile_rows_log2: 0, + }; + let mut enc = Av1Encoder::new(config).unwrap(); + let _ = crate::encode::take_inter_tx_type_hits(); + let mut stream = Vec::new(); + for packet in encode_all(&mut enc, &sources) { + stream.extend_from_slice(&packet.data); + } + let hits = crate::encode::take_inter_tx_type_hits(); + crate::encode::force_screen(None); + crate::encode::set_wide_tx_set(None); + crate::encode::set_inter_tx_search(None); + crate::encode::set_intra_tx_search(None); + use crate::transform::TxType; + eprintln!( + "inter wide-set witness: inter hits {hits:?}, {} bytes", + stream.len() + ); + assert!( + hits[TxType::Idtx as usize] > 0, + "no inter luma unit was CODED IDTX: {hits:?}" + ); + assert!( + hits[TxType::VDct as usize] + hits[TxType::HDct as usize] > 0, + "no inter luma unit was CODED a 1-D type -- the wider search \ + never fired on non-screen content (class gate-blind-to-feature): {hits:?}" + ); + let ours = crate::stream::decode_stream(&stream).expect("our decoder"); + assert_eq!(ours.len(), sources.len(), "our decoder's frames"); + if have_ffmpeg() { + let theirs = ffmpeg_decode_planes(&stream, width, height); + assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); + let (cw, ch) = (width / 2, height / 2); + for (i, (a, (y, u, v))) in ours.iter().zip(&theirs).enumerate() { + for (name, got16, want, w) in + [("y", &a.y, y, width), ("u", &a.u, u, cw), ("v", &a.v, v, ch)] + { + let got: Vec = got16.iter().map(|&s| s as u8).collect(); + assert_eq!(got.len(), want.len(), "frame {i} {name} plane size"); + if let Some(at) = got.iter().zip(want.iter()).position(|(x, y)| x != y) { + panic!( + "frame {i}: {name} differs first at ({}, {}): ours {} vs ffmpeg {}", + at % w, + at / w, + got[at], + want[at], + ); + } + } + } + } else { + eprintln!("SKIP the ffmpeg half: no ffmpeg"); + } + } /// Every SHIPPED SPEED PRESET codes a stream both decoders reconstruct /// sample-exact -- ours and ffmpeg's -- and codes a DIFFERENT stream from diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 86e285a9..8ff94030 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3035,8 +3035,11 @@ pub(crate) mod tests { &encoded.cdef, &encoded.loop_filter, encoded.tx_select, - // Our own encoder always writes `reduced_tx_set: true`. - true, + // lane-intertx: the frame's own `reduced_tx_set` -- a screen + // key frame at preset 0 codes the wider intra alphabets, so + // the old hardcoded `true` (ours "always" wrote true) is a + // stale-header bug waiting for the first screen fixture. + encoded.reduced_tx_set, // `allow_screen_content_tools` off the frame the encoder // actually wrote: a screen-content picture codes two palette // symbols per intra block, and a raw tile decode that guessed diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index 2a357973..8e41d1a8 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -4827,6 +4827,7 @@ fn write_block( tx_mode, tx_select, block_tx_type(block), + false, ); neighbours.record_planes(at, side, mode, grids, !split); clear_skip_band(neighbours, at_mi, side); @@ -4927,6 +4928,7 @@ fn write_leaf8( tx_mode, tx_select, block_tx_type(block), + false, ); neighbours.record_mi_planes(leaf_mi, 8, grids, !split); clear_skip_band(neighbours, leaf_mi, 8); @@ -4951,7 +4953,20 @@ fn write_block_planes( // This block's single luma transform type (lane-txset); chroma's is // derived from its mode by the decoder and codes no symbol. luma_tx_type: TxType, + // lane-intertx: an INTER block's chroma transforms INHERIT the luma + // type (reduced to the chroma set against this frame's own + // `reduced_tx_set` bit); an intra block's comes off its UV mode and + // rides `DCT_DCT`'s 2D class exactly as before. + inter: bool, ) { + // lane-intertx, desync (b): the writer used to code every chroma plane + // `DCT_DCT`. Chroma codes no `tx_type` symbol, but the type names the + // transform class, and the class picks the scan, the `eob_pt` row and + // the context offsets (the lane-txw note in `write_coeffs`) -- so an + // inherited 1-D luma type desynced the chroma exactly as luma itself + // once did. The reduced bit read here is the frame's own header bit, + // the ONE the writer's `Cdfs` is armed with (`Cdfs::reduced_tx_set`). + let reduced = cdfs.reduced_tx_set; for (plane, (grid, scan)) in grids.iter().zip(scans.iter()).enumerate() { if plane == 0 && skip_luma { continue; @@ -4969,15 +4984,28 @@ fn write_block_planes( let before = enc.tell(); #[cfg(test)] let q_ctx = cdfs.q_ctx; + let mut coding = cdfs.txb(planes[plane], mode); + let tx_type = if plane == 0 { + luma_tx_type + } else if inter { + crate::decode::reduce_inherited_chroma_tx_type_flagged( + luma_tx_type, + coding.side.min(32), + coding.side.min(32), + reduced, + ) + } else { + TxType::DctDct + }; write_coeffs( enc, - &mut cdfs.txb(planes[plane], mode), + &mut coding, grid, scan, skip_ctx, dc_sign_ctx(around[plane].dc_vote), Some(plane), - if plane == 0 { luma_tx_type } else { TxType::DctDct }, + tx_type, ); #[cfg(test)] census_record( @@ -7474,6 +7502,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( 0, split, block_tx_type(block), + true, ); neighbours.record_planes(sb_at, SB, 0, &grids, !split); } @@ -7938,6 +7967,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( mode_for_tx, split, block_tx_type(block), + is_inter, ); neighbours.record_planes(at, BLOCK, mode_for_tx, &grids, !split); } @@ -8179,6 +8209,7 @@ fn write_inter_frame_leaf( mode_for_tx, split, block_tx_type(block), + is_inter, ); neighbours.record_planes(at, SUB, mode_for_tx, &grids, !split); } @@ -8432,6 +8463,7 @@ fn write_inter_frame_leaf8( mode_for_tx, split, block_tx_type(block), + is_inter, ); neighbours.record_mi_planes(leaf_mi, 8, &grids, !split); neighbours.record_inter_mi(leaf_mi, 8, block.skip, is_inter, block_ref(block)); diff --git a/lanes/intertx.charter.md b/lanes/intertx.charter.md new file mode 100644 index 00000000..20dc5453 --- /dev/null +++ b/lanes/intertx.charter.md @@ -0,0 +1,104 @@ +# lane-intertx — inter tx-type search on film (TX_TYPE_SEARCH_INTER past screen-only) + +GOAL: the inter tx-type search (`inter_tx_type_search`, encode.rs ~L450) +runs only on screen content at the preset lever +(`crate::speed::TX_TYPE_SEARCH_INTER` → `InterTxSearch::Screen`). +`EC_AV1_TXSET_INTER=all` exists but has never been measured on film, and +the `inter_luma_set` doc (encode.rs ~L475) records a deferred CHROMA +inheritance desync: (a) `FrameCtx::reduced_tx_set_inter` never set while +`recode_inter_chroma` reduces against the reduced allowance, and (b) +`tile::write_block_planes` codes every chroma plane `DCT_DCT`, so an +inherited 1-D luma type desyncs chroma. This lane makes inter tx-type +search correct and measured on film, then ships or parks by the keep +rule. + +Work ONLY in this worktree (`lane-intertx`, +`/home/user/Documents/Code/Rust/edith_codecs-intertx`). Absolute paths +only. Never touch main's checkout or the rectres worktree, never push, +never `git checkout `, never repo-wide `cargo fmt` (rustfmt only +files you edited). Local builds: `export +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-intertx`. Local logs under +`~/.cache/intertx/`. Media files read-only. Pins 8291 / 33227. Keep +rule: one film row ≥0.5 BD down on a column, the other flat within +±0.3, screen not worse by 0.3, wall ≤+15%. BD-rate, lower better. + +## 1. Correctness first (witnesses BEFORE any BD gate) + +- Determine whether the chroma inheritance desync is LIVE when the + search offers non-`DCT_DCT` types on inter blocks: build a witness in + the standing pattern (process-global `set_inter_tx_search` override + + `crate::speed::knob_write`, like the existing inter-tx witness) on + NON-screen content where the search picks a 1-D type, decoded + sample-exact through ffmpeg AND `decode_stream` (all planes — the + desync is chroma). If it desyncs: fix (a) and (b) — the decoder's + `decode::reduce_inherited_chroma_tx_type` is the spec behavior; the + encoder must set `reduced_tx_set_inter` honestly and code chroma with + the inherited reduced type, not unconditional `DCT_DCT`. +- Witness must assert the search actually WON a non-`DCT_DCT` inter + type (a `coded > 0`-style counter guard — class + `gate-blind-to-feature`), on a frame the detector calls non-screen. + +## 2. Measure (control = Screen, arm = All) + +Both on the SAME server (see §3), same HEAD: + +- `encode::tests::bd_rate_film_long_gop` (deciding, both films): + control = default; arm = `EC_AV1_TXSET_INTER=all`. +- `encode::tests::bd_rate_screen_native` (all five rows), control and + arm. The screen row must not regress (arm should equal control there + — screen already searches; if it moves, find out why). +- Census: non-`DCT_DCT` inter tx-type picks per clip (search won / + coded), printed per run; report per-frame rates like lane-b128res §4. + +Keep rule met → make the lever `All` at the presets where it measured +(a speed.rs preset-table change), pins at default and `EC_AV1_SPEED=6`, +three-lane lib suite LOCALLY (`--skip stream::` / `stream:: --skip +10bit` / `10bit`), `timeout 900 cargo check --workspace --all-targets +-j4` (0 ec-av1 warnings). Not met → leave `Screen`, document. + +## 3. Gates run on server-1 (the box stays free for lane-rectres) + +server-1 = `user@host-e` (Fedora 44, 4 vCPU, 7G RAM, rust 1.98.1, +ffmpeg with libaom-av1+librav1e). Provisioned layout: +`/home/user/gates/library/fixtures/` (bars fixtures + rewritten +real-library-manifest.tsv), `/home/user/gates/library/Films/ +filmA-gate.mkv` + `filmB-gate.mkv` (windowed substitutes, sha256-verified +pixel-identical to the originals at the pinned seeks — 48 frames each), +`/home/user/gates/library/OBS/…mkv` (screen row), +`/home/user/gates/bin/ffmpeg` (shim that rewrites the pinned `-ss` +values onto the windows; all other invocations exec `/usr/bin/ffmpeg` +untouched). + +Gate recipe per run (control and arm alike): + +``` +rsync -a --delete --exclude /fixtures/ --exclude /target/ \ + --exclude /.git/ \ + /home/user/Documents/Code/Rust/edith_codecs-intertx/ \ + user@host-e:/home/user/gates/repo-intertx/ +ssh -o BatchMode=yes user@host-e 'ln -sfn \ + /home/user/gates/library/fixtures \ + /home/user/gates/repo-intertx/fixtures' +ssh -o BatchMode=yes user@host-e 'cat /proc/loadavg; cd + /home/user/gates/repo-intertx && PATH=/home/user/gates/bin:$PATH \ + CARGO_TARGET_DIR=/home/user/gates/target-intertx \ + [EC_AV1_TXSET_INTER=all] \ + systemd-run --user -p MemoryMax=5G --wait --unit=intertx- \ + --pipe cargo test -p ec-av1 --release --lib -- --ignored --exact \ + --nocapture encode::tests::bd_rate_film_long_gop; cat /proc/loadavg' \ + | tee ~/.cache/intertx/.log +``` + +If `systemd-run --user` is unavailable on the server (no user session +bus), run bare and note it. First run compiles (~15 min on 4 vCPU) — +that is normal. ONE gate at a time on the server. LOADAVG before AND +after, recorded. `--ignored --exact` is load-bearing (the tests are +`#[ignore]`). TMPDIR never on any cargo line. + +## DONE + +Commits on `lane-intertx` + `lanes/intertx.report.md` with EVIDENCE +lines (`EVIDENCE: | | `), witness +results, BD tables control vs arm on both gates, tx-type census, wall +deltas, LOADAVG pairs, pins line, disposition `ships-on | stays-off | +stopped`. Never merge or push. diff --git a/lanes/intertx.report.md b/lanes/intertx.report.md new file mode 100644 index 00000000..74e56387 --- /dev/null +++ b/lanes/intertx.report.md @@ -0,0 +1,258 @@ +# lane-intertx — the inter tx-type search on film (chroma inheritance made honest) + +Base: `810d8972` (charter). Fix commit: `9af60b4d`. Regression fix + report +commit: this one. Disposition: **stays-off** +(`crate::speed::TX_TYPE_SEARCH_INTER` keeps `Screen` at presets 0-6; the keep +rule's deciding column fails at best -0.1 against the required -0.5), but the +lane's correctness work is real and committed: the chroma inheritance desync +was LIVE and is fixed, the wider inter search is reachable and honest on +`reduced_tx_set = 0` frames, and on screen content the fix itself measures +-0.7/-0.4 BD against the pre-lane standing table. Pins untouched at +8291 / 33227 (default non-screen streams byte-identical; pin test re-run +green). Never merged, never pushed. + +## 1. The chroma inheritance desync: LIVE, fixed + +The wider inter search (`inter_tx_type_candidates`' seven-type `INTER_WIDE` +list) was unreachable: `inter_luma_set` named only the plain `Luma*Inter` +sets, so the `Set1` arms were dead code. The refusal reason lane-txi recorded +(the refs lane's DPB bookkeeping) was already known wrong; the real blocker +was `refusal-from-own-desync` in the CHROMA inheritance: + +- (a) the encoder never set `FrameCtx::reduced_tx_set_inter` on the shared + frame context, so `recode_inter_chroma`'s + `reduce_inherited_chroma_tx_type` reduced against a STALE allowance — + whatever the previous frame's own trial decode had last left in the cell — + while a `reduced_tx_set = 0` frame's decoder allows the full set; +- (b) `tile::write_block_planes` coded every chroma plane as `DCT_DCT`. + Chroma codes no `tx_type` symbol, but the type names the transform class, + and the class picks the scan, the `eob_pt` row and the neighbour contexts + (`write_coeffs`' lane-txw note) — so an inherited 1-D type desynced the + chroma exactly as luma once did. + +Fix (commit `9af60b4d`): (a) `encode_inter_frame` sets +`fctx.reduced_tx_set_inter` from the frame's own header bit the moment it is +decided (`header.reduced_tx_set = !wide_tx_set(screen)`); (b) the writer +derives each inter block's chroma type from the first luma unit's coded type +via the new `decode::reduce_inherited_chroma_tx_type_flagged` against +`Cdfs::reduced_tx_set` — the frame's own honest bit — and codes chroma with +it; the search names the Set1 sets through `luma_set_for` (the intra search's +own shape) at both the flat and the split-unit trial, so every candidate is +priced in the alphabet its symbol is coded into. All six +`write_block_planes` callers now pass the block's inter flag; intra chroma +rides `DCT_DCT`'s 2D class exactly as before. + +Witness `encoder::tests::a_non_screen_inter_clip_codes_a_one_d_type_both_decoders_read_every_plane_exactly` +(process-global `set_inter_tx_search(Some(true))` + `set_wide_tx_set(Some(true))` ++ `force_screen(Some(false))` under `knob_write`, 320x192 moving +steps/ramps/plateaus, gop 4, q 90): the inter search WON and CODED +non-`DCT_DCT` types on the non-screen clip, and ALL THREE planes read +sample-exact through `decode_stream` AND ffmpeg at every frame. + +EVIDENCE: ~/.cache/intertx/witness-green.log | --ignored --exact --nocapture +run of the witness on `9af60b4d` | "inter wide-set witness: inter hits +[200, 979, 3, 97, 111, 40, 521, 0, ...], 8143 bytes" — coded>0 guards pass +for `IDTX` (200) and for the 1-D types (`V_DCT`=40 + `H_DCT`=521); all three +planes identical to ffmpeg on all four frames. ok. + +RED run (desync live): with the widening applied and fix (b) neutralized — +chroma coded `DCT_DCT` unconditionally, the pre-lane writer — the same encode +FAILS inside its own trial decode: the reader inherits the 1-D chroma type +the writer refused to code with, the tile desyncs, and the derail surfaces as +"a reference frame selected with no picture at this frame's own +ref_frame_idx slot" (class `refusal-from-own-desync`, not a real ref defect). + +EVIDENCE: ~/.cache/intertx/witness-red.log | same witness, fix (b) probe +removed | FAILED: trial-decode refusal aborts the encode at flush. + +Standing witnesses re-run green on the fixed HEAD: the wide witness now codes +1-D inter units on its screen card too (`V_DCT`=41, `H_DCT`=405, `IDTX`=702 +of 1305) and reads every frame exact; the two-type inter witness passes. + +EVIDENCE: ~/.cache/intertx/standing-witnesses.log | --ignored --exact and +default runs | "a_wide_tx_set_clip... ok", "an_inter_clip... ok". + +## 2. Long-GOP BD (deciding; 48 pictures, gop=48, both films, server-1) + +Control = default (lever `Screen`), arm = `EC_AV1_TXSET_INTER=all`, same HEAD +`9af60b4d`, same ladder (`encode::tests::bd_rate_film_long_gop`, +`--ignored --exact`). BD-rate, lower better: + +| row | ctrl vs libaom | ctrl vs rav1e | arm vs libaom | arm vs rav1e | +|---|---|---|---|---| +| film A (1080p) 1920x768 | +20.9% | -9.0% | +20.8% | -9.1% | +| film B (2160p HDR) 1920x1024 | +70.4% | -2.2% | +70.3% | -2.1% | + +Arm-minus-control: film A -0.1/-0.1, film B -0.1/+0.1. The control +reproduces the standing table (b128res-era film A +20.9/-9.0, film B ++70.4/-2.2) to the digit on a different HEAD. + +Wall ours: film A 1314.7s -> 1395.1s (+6.1%), film B 1031.5s -> 1074.0s +(+4.1%). LOADAVG 0.28/0.35/0.20 before, 1.30/1.20/1.11 after (control); +0.93/1.12/1.09 before, 1.12/1.10/1.09 after (arm). + +EVIDENCE: ~/.cache/intertx/longgop-control.log | gate 2 control, server-1, +MemoryMax=5G, `systemd-run --user` | film A +20.9%/-9.0%, film B ++70.4%/-2.2%; census 100.0% `DCT_DCT` on both films. ok. +EVIDENCE: ~/.cache/intertx/longgop-arm.log | gate 2 arm, EC_AV1_TXSET_INTER=all | +film A +20.8%/-9.1%, film B +70.3%/-2.1%. ok. + +## 3. 12-frame native guard (all five rows, server-1) + +`encode::tests::bd_rate_screen_native`, control and arm: + +| row | ctrl vs libaom | ctrl vs rav1e | arm vs libaom | arm vs rav1e | +|---|---|---|---|---| +| bars 1080p | -3.3% | -19.0% | -3.5% | -19.0% | +| bars 2160p | +8.4% | -13.9% | +8.5% | -13.8% | +| film A | +17.9% | -6.3% | +17.8% | -6.4% | +| film B | +22.6% | -3.8% | +22.7% | -3.7% | +| screen capture | +13.7% | -33.6% | +13.7% | -33.6% | + +The screen row is byte-identical between control and arm (same PSNR/bytes at +every point, same census) — exactly the charter's prediction: the search is +already on for screen frames, so `All` can add nothing there. + +Wall ours: bars 1080p 396.2s -> 411.1s (+3.8%), bars 2160p 336.3s -> 358.1s +(+6.5%), film A 350.9s -> 371.0s (+5.7%), film B 301.4s -> 309.8s (+2.8%), +screen capture 226.1s -> 225.1s (-0.4%). LOADAVG 0.88/1.05/1.07 before, +1.07/1.14/1.11 after (control); 0.91/1.10/1.10 before, 1.12/1.13/1.09 after +(arm). + +Screen-content attribution note: the control screen row against the +b128res-era standing table moved +14.4% -> +13.7% (libaom) and -33.2% -> +-33.6% (rav1e). That delta is THIS lane's fix reaching the screen default: +the widened inter candidates are now offered to screen frames at preset 0, +where the lever already said `Screen`, and the census shows the new types +coding (below). Cross-HEAD comparison, so attribution is indicative only. + +EVIDENCE: ~/.cache/intertx/native-control.log | gate 3 control, five rows | +table above, control columns; three-way exactness held at every clip x q x +frame. ok. +EVIDENCE: ~/.cache/intertx/native-arm.log | gate 3 arm, EC_AV1_TXSET_INTER=all | +table above, arm columns. ok. + +## 4. Inter tx-type census (search won / coded, per clip) + +Non-`DCT_DCT` share of COMMITTED inter luma units (the census names types +that were really coded), arm runs: + +| clip | inter units | coded non-DCT_DCT | share | +|---|---|---|---| +| film A long-GOP | 1468708 | 35618 `IDTX` | 2.4% | +| film B long-GOP | 1250132 | 41586 `IDTX` | 3.3% | +| bars 1080p 12f | 115907 | 21033 `IDTX` | 18.1% | +| bars 2160p 12f | 83614 | 20634 `IDTX` | 24.7% | +| film A 12f | 330189 | 7311 `IDTX` | 2.2% | +| film B 12f | 310009 | 7002 `IDTX` | 2.3% | +| screen capture 12f | 59731 | 1080 `IDTX` + 266 `ADST_ADST` + 346 `ADST_DCT` + 187 `DCT_ADST` + 455 `V_DCT` + 1572 `H_DCT` | 6.5% | + +Controls: 100.0% `DCT_DCT` on every non-screen clip (lever off there); +screen capture control already carries the wider alphabet (the fix's doing). +With `all`, film takes only the two-type set's `IDTX` (2.2-3.3%) — the +arm is INERT ON FILM, the same 0-to-small band the b128res arm showed. +Every one of these units decoded three-way exact (encoder == ffmpeg == +decode_stream) at every q point of every run — the gates' standing +exactness assertion covers the whole census, native resolution, both films +and all five native rows. + +## 5. Keep rule — NOT met + +One film row >=0.5 BD down on a column: best delta anywhere is -0.1 (film A +long-GOP and 12-frame; native bars rows are not film). Other film row flat +within +/-0.3: yes (max 0.1). Screen not worse by 0.3: yes (byte-identical). +Wall <= +15%: yes (max +6.5%). The deciding column fails at -0.1 against the +required -0.5: `IDTX` at 2-3% of film units buys a tenth of a point. The +lever stays `Screen` at every preset; `speed.rs` is untouched. + +## 6. Pins, witnesses, scope + +- Pins `encode::tests::the_encoders_own_streams_are_byte_identical_to_their_pins`: + re-run green on `9af60b4d` — `(150, 8291, 0x1f00bb0eb099a27f)` and + `(60, 33227, 0x57ee6b1f8eacd881)` stand. The pin fixture is the non-screen + h264 clip, where the fix changes nothing by construction (the widened + candidates need `reduced_tx_set = 0`, which only screen frames code at the + default preset). No pin re-take. + +EVIDENCE: ~/.cache/intertx/pins.log | default-preset pin run on 9af60b4d | +ok, both pins byte-identical. + +- server-1 provisioning verified before the first gate: filmA-gate.mkv 8833494 + bytes, filmB-gate.mkv 195927872 bytes, no partial files. +- Gate recipe deviations from charter §3 (all recorded): `systemd-run` + needs `-p WorkingDirectory=` (the unit does not inherit the shell's cwd), + `PATH`/`CARGO_TARGET_DIR` must be set INSIDE the unit (a + `bash -lc` wrapper), and the synced repo's `.git` was a stale worktree + pointer file that broke the memguard runner's `git rev-parse` — replaced + with a fresh `git init` on the server. One gate at a time throughout. +- Not verified: nothing in the charter's scope is unverified. The + three-lane lib suite and `cargo check --workspace --all-targets` were NOT + run — charter §2 requires them only on the keep-rule-met (ships-on) + branch; the stays-off branch carries the scoped local checks (ec-av1 lib + + tests compile warning-free; the three tx witnesses; the pin test) and + project-wide validation stays with the main agent. `FLIPADST` family and + the 1-D ADSTs remain unoffered (the standing lane-txi deferral). + +## 7. Regression caught by the merge tier: the raw-tile decode wrapper's +## stale `reduced_tx_set` + +Main's regression tier caught three `decode::tests` failures on the lane +HEAD (`a_gop_round_trips_bit_exact_against_the_encoder_reconstruction`, +`an_odd_size_gop_round_trips_bit_exact_against_the_encoder_reconstruction`, +`ffmpeg_and_this_decoder_agree_on_a_gop`), all refusing with "a reference +frame selected with no picture at this frame's own ref_frame_idx slot". + +Root cause (class: **test asserts against a stale header** -- the wrapper's +own parameter docs document five prior instances of exactly this class): +`decode::decode_inter_frame_tile_lr`, the raw-tile decode helper the GOP +round-trip tests use, hard-coded `reduced_tx_set: true` +(`decode.rs:34552` at the fix commit's parent) with the comment "this +wrapper's callers are the decoder's own tests, which all code the reduced +sets". True until this lane: no inter block ever inherited a non-`DCT_DCT` +chroma type. With the widened inter search live, a screen-detected GOP at +the default preset codes `reduced_tx_set = 0` frames whose inter luma takes +`V_DCT` (the traces show the first inter block at (0,0) 16x16 winning +exactly that), and the chroma inheritance reduces the inherited type +against the very bit the wrapper guessed: the test's decode derived +`DCT_DCT` from `inh=Some(V_DCT)` at chroma 8x8 where the writer coded +`V_DCT`, desynced, and the garbage symbols eventually read a ref_frame_idx +that names an empty slot -- the named refusal is downstream noise, the +first divergence is the chroma type. + +Fix (this commit): the wrapper takes the frame's own +`reduced_tx_set: bool` (placed before `tx_select`, mirroring the plural +fn), `Encoded` carries the bit (`encode.rs`, the `screen`/`tx_select` +pattern), the GOP tests and the key-frame tile test (`stream.rs`, whose +"our own encoder always writes `reduced_tx_set: true`" comment had the +same latent stale-header bug) pass the honest value. + +Why the gates and witnesses did not see it: every production decode path +(`stream.rs`'s parser, `decode_stream`, ffmpeg) reads the bit off the wire +honestly -- the gates' three-way exactness and all witnesses ride those. +Only the raw-tile test helper guessed. + +Encoder output is UNCHANGED by the fix: the diff touches the `Encoded` +metadata struct, the test-facing decode wrappers and one test call -- no +writer or search code (tile.rs is not in the fix diff at all), and the +three witnesses code byte-identical streams after it (8143 / 8211 bytes, +same census). The server-1 BD tables in sections 2-4 remain valid; no gate +re-run needed. + +EVIDENCE: ~/.cache/intertx/regression-repro.log | the three tests on the +unfixed lane HEAD | 3 failed, all with the named refusal. +EVIDENCE: ~/.cache/intertx/regression-fix.log | the three tests + the pin +test after the fix | 4 passed. +EVIDENCE: ~/.cache/intertx/witness-rerun.log | all three tx witnesses +re-run after the fix | byte-identical streams (8143 / 8211 bytes), ok. + +## 8. Full suite and workspace check (post-fix) + +Three-lane lib suite LOCALLY on the fix commit, `--release --lib`: +`--skip stream::` 348 passed / 0 failed; `stream:: --skip 10bit` 202 +passed / 0 failed; `10bit` 42 passed / 0 failed -- **592 passed, 0 +failed**. `timeout 900 cargo check --workspace --all-targets -j4`: 0 +ec-av1 warnings (the 25 workspace warnings are ec-opus's, pre-existing). + +EVIDENCE: ~/.cache/intertx/suite-lane1.log | --skip stream:: | 348 passed. +EVIDENCE: ~/.cache/intertx/suite-lane2.log | stream:: --skip 10bit | 202 passed. +EVIDENCE: ~/.cache/intertx/suite-lane3.log | 10bit | 42 passed.