Merge branch 'lane-intertx' (c2653e06): the inter tx-type search widens to the Set1 alphabets with the chroma inheritance made honest -- the frame sets its own reduced_tx_set_inter and the writer codes inter chroma with the inherited reduced type (a live-latent desync pre-fix, RED-proven); screen default improves +14.4 -> +13.7 vs libaom, the film arm EC_AV1_TXSET_INTER=all measures BD-neutral (best -0.1) so the lever stays Screen; the raw-tile decode test helper's hardcoded reduced_tx_set=true stale-header bug fixed with Encoded carrying the frame's own bit; pins 8291/33227, suite 592/0
Browse files at this commit8 changed files +594 -30
- crates/ec-av1/src/cdf_state.rs +5 -4
- crates/ec-av1/src/decode.rs +39 -7
- crates/ec-av1/src/encode.rs +48 -15
- crates/ec-av1/src/encoder.rs +101 -0
- crates/ec-av1/src/stream.rs +5 -2
- crates/ec-av1/src/tile.rs +34 -2
- lanes/intertx.charter.md +104 -0
- lanes/intertx.report.md +258 -0
crates/ec-av1/src/cdf_state.rsmodified+5 -4
| @@ -278,10 +278,11 @@ pub(crate) struct TxbTables<'a> { | |||
| 278 | pub txb_skip: &'a mut [[u16; 3]], | 278 | pub txb_skip: &'a mut [[u16; 3]], |
| 279 | /// The end-of-block group, whose alphabet the transform size sets. | 279 | /// The end-of-block group, whose alphabet the transform size sets. |
| 280 | pub eob_pt: &'a mut [u16], | 280 | pub eob_pt: &'a mut [u16], |
| 281 | - /// `eob_pt`'s `TX_CLASS_HORIZ`/`TX_CLASS_VERT` sibling table (r5): read | 281 | + /// Read instead of `eob_pt` once this TU's `tx_type` is known to be |
| 282 | - /// instead of `eob_pt` once this TU's `tx_type` is known to be | 282 | + /// `V_DCT`/`H_DCT` (lane-intertx doc fix: every set here carries the |
| 283 | - /// `V_DCT`/`H_DCT`. `None` for any size/set whose `tx_type` alphabet | 283 | + /// row -- the older "none for chroma and every inter set" note |
| 284 | - /// cannot produce those two symbols (chroma, and every inter set). | 284 | + /// described the r5 alphabet, before the wider inter/chroma-reachable |
| 285 | + /// sets made those classes reachable there). | ||
| 285 | pub eob_pt_class1: Option<&'a mut [u16]>, | 286 | pub eob_pt_class1: Option<&'a mut [u16]>, |
| 286 | /// The top bit of the offset inside that group. | 287 | /// The top bit of the offset inside that group. |
| 287 | pub eob_extra: &'a mut [[u16; 3]; 9], | 288 | pub eob_extra: &'a mut [[u16; 3]; 9], |
crates/ec-av1/src/decode.rsmodified+39 -7
| @@ -18711,10 +18711,19 @@ fn read_inter_luma8( | |||
| 18711 | /// sync and only corrupted the inverse transform (one 64x64 superblock of | 18711 | /// sync and only corrupted the inverse transform (one 64x64 superblock of |
| 18712 | /// high-frequency chroma noise, luma bit-exact). | 18712 | /// high-frequency chroma noise, luma bit-exact). |
| 18713 | pub(crate) fn reduce_inherited_chroma_tx_type(t: TxType, w: usize, h: usize, fctx: &crate::decode::FrameCtx) -> TxType { | 18713 | pub(crate) fn reduce_inherited_chroma_tx_type(t: TxType, w: usize, h: usize, fctx: &crate::decode::FrameCtx) -> TxType { |
| 18714 | + reduce_inherited_chroma_tx_type_flagged(t, w, h, fctx.reduced_tx_set_inter.with(std::cell::Cell::get)) | ||
| 18715 | +} | ||
| 18716 | + | ||
| 18717 | +/// [`reduce_inherited_chroma_tx_type`] against an explicit `reduced_tx_set` | ||
| 18718 | +/// bit (lane-intertx): the WRITER calls this with the frame's own header bit | ||
| 18719 | +/// ([`crate::cdf_state::Cdfs::reduced_tx_set`]) to derive the type an inter | ||
| 18720 | +/// block's chroma transform is coded with, the same derivation its reader | ||
| 18721 | +/// makes -- it has no `FrameCtx` in reach and must not silently read one | ||
| 18722 | +/// whose value can lag the frame being written (class `stale-context-bit`). | ||
| 18723 | +pub(crate) fn reduce_inherited_chroma_tx_type_flagged(t: TxType, w: usize, h: usize, reduced: bool) -> TxType { | ||
| 18714 | use TxType::*; | 18724 | use TxType::*; |
| 18715 | let sqr_up = w.max(h); | 18725 | let sqr_up = w.max(h); |
| 18716 | let sqr = w.min(h); | 18726 | let sqr = w.min(h); |
| 18717 | - let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get); | ||
| 18718 | // `av1_get_ext_tx_set_type(tx_size, is_inter = 1, reduced)`. | 18727 | // `av1_get_ext_tx_set_type(tx_size, is_inter = 1, reduced)`. |
| 18719 | let allowed: &[TxType] = if sqr_up > 32 { | 18728 | let allowed: &[TxType] = if sqr_up > 32 { |
| 18720 | // EXT_TX_SET_DCTONLY | 18729 | // EXT_TX_SET_DCTONLY |
| @@ -34434,6 +34443,10 @@ pub(crate) fn decode_inter_frame_tile( | |||
| 34434 | interp_fixed: Option<mc::InterpFilterKind>, | 34443 | interp_fixed: Option<mc::InterpFilterKind>, |
| 34435 | enable_dual_filter: bool, | 34444 | enable_dual_filter: bool, |
| 34436 | reference_select: bool, | 34445 | reference_select: bool, |
| 34446 | + // lane-intertx: this frame header's own `reduced_tx_set` (spec 5.9.2) -- | ||
| 34447 | + // see [`decode_inter_frame_tile_lr`]'s parameter. Same stale-header | ||
| 34448 | + // class as `tx_select` below. | ||
| 34449 | + reduced_tx_set: bool, | ||
| 34437 | // This frame header's `tx_mode == TxMode::Select`: `Encoded::tx_select`. | 34450 | // This frame header's `tx_mode == TxMode::Select`: `Encoded::tx_select`. |
| 34438 | // Hard-coding `false` here desynced at the first `tx_depth` symbol once | 34451 | // Hard-coding `false` here desynced at the first `tx_depth` symbol once |
| 34439 | // inter frames coded Select by default (class: test asserts against a | 34452 | // inter frames coded Select by default (class: test asserts against a |
| @@ -34454,7 +34467,7 @@ pub(crate) fn decode_inter_frame_tile( | |||
| 34454 | decode_inter_frame_tile_lr( | 34467 | decode_inter_frame_tile_lr( |
| 34455 | data, mi_cols, mi_rows, base_q_idx, frame_width, frame_height, refpix, cdef, | 34468 | data, mi_cols, mi_rows, base_q_idx, frame_width, frame_height, refpix, cdef, |
| 34456 | loop_filter, allow_high_precision_mv, force_integer_mv, interp_fixed, | 34469 | loop_filter, allow_high_precision_mv, force_integer_mv, interp_fixed, |
| 34457 | - enable_dual_filter, reference_select, tx_select, | 34470 | + enable_dual_filter, reference_select, reduced_tx_set, tx_select, |
| 34458 | &LoopRestorationParams::default(), initial_cdfs, NO_SIGN_BIAS, false, | 34471 | &LoopRestorationParams::default(), initial_cdfs, NO_SIGN_BIAS, false, |
| 34459 | // `enable_filter_intra`: as the `false`s beside it, this convenience | 34472 | // `enable_filter_intra`: as the `false`s beside it, this convenience |
| 34460 | // entry names a stream written without the sequence bit (lane-fintra). | 34473 | // entry names a stream written without the sequence bit (lane-fintra). |
| @@ -34480,6 +34493,15 @@ pub(crate) fn decode_inter_frame_tile_lr( | |||
| 34480 | interp_fixed: Option<mc::InterpFilterKind>, | 34493 | interp_fixed: Option<mc::InterpFilterKind>, |
| 34481 | enable_dual_filter: bool, | 34494 | enable_dual_filter: bool, |
| 34482 | reference_select: bool, | 34495 | reference_select: bool, |
| 34496 | + // lane-intertx: this frame header's own `reduced_tx_set` (spec 5.9.2). | ||
| 34497 | + // The wrapper used to hard-code `true` ("the tests all code the reduced | ||
| 34498 | + // sets") -- true until the widened inter search put 1-D/DTT types on | ||
| 34499 | + // `reduced_tx_set = 0` frames' inter luma, whose CHROMA then inherits | ||
| 34500 | + // the type against this very bit | ||
| 34501 | + // ([`reduce_inherited_chroma_tx_type`]): guessing `true` mis-derives | ||
| 34502 | + // every inherited chroma type and desyncs the tile (class: test asserts | ||
| 34503 | + // against a stale header, next instance). | ||
| 34504 | + reduced_tx_set: bool, | ||
| 34483 | tx_select: bool, | 34505 | tx_select: bool, |
| 34484 | lr: &LoopRestorationParams, | 34506 | lr: &LoopRestorationParams, |
| 34485 | initial_cdfs: Option<Cdfs>, | 34507 | initial_cdfs: Option<Cdfs>, |
| @@ -34537,9 +34559,9 @@ pub(crate) fn decode_inter_frame_tile_lr( | |||
| 34537 | interp_fixed, | 34559 | interp_fixed, |
| 34538 | enable_dual_filter, | 34560 | enable_dual_filter, |
| 34539 | reference_select, | 34561 | reference_select, |
| 34540 | - // lane-txi: this wrapper's callers are the decoder's own tests, which | 34562 | + // lane-intertx: this frame's own bit, not the hardcoded `true` -- |
| 34541 | - // all code the reduced sets. | 34563 | + // see the parameter's note above. |
| 34542 | - true, | 34564 | + reduced_tx_set, |
| 34543 | tx_select, | 34565 | tx_select, |
| 34544 | lr, | 34566 | lr, |
| 34545 | initial_cdfs, | 34567 | initial_cdfs, |
| @@ -38775,6 +38797,9 @@ mod tests { | |||
| 38775 | Some(mc::InterpFilterKind::Regular), | 38797 | Some(mc::InterpFilterKind::Regular), |
| 38776 | false, | 38798 | false, |
| 38777 | false, | 38799 | false, |
| 38800 | + // The fixture's own implied header codes the reduced sets (the | ||
| 38801 | + // wrapper's old hardcoded value). | ||
| 38802 | + true, | ||
| 38778 | false, | 38803 | false, |
| 38779 | None, | 38804 | None, |
| 38780 | false, | 38805 | false, |
| @@ -39268,6 +39293,12 @@ mod tests { | |||
| 39268 | // `false` (stale-header class -- a `reference_select` stream | 39293 | // `false` (stale-header class -- a `reference_select` stream |
| 39269 | // reads a `comp_mode` symbol this decode would skip). | 39294 | // reads a `comp_mode` symbol this decode would skip). |
| 39270 | crate::encode::reference_select(), | 39295 | crate::encode::reference_select(), |
| 39296 | + // lane-intertx: this frame's own `reduced_tx_set` -- the | ||
| 39297 | + // bit the chroma inheritance reduces against. The wrapper | ||
| 39298 | + // used to guess `true`, which mis-derived every inherited | ||
| 39299 | + // chroma type on a screen frame's widened inter blocks | ||
| 39300 | + // (stale-header class). | ||
| 39301 | + frame.reduced_tx_set, | ||
| 39271 | frame.tx_select, | 39302 | frame.tx_select, |
| 39272 | &frame.loop_restoration, | 39303 | &frame.loop_restoration, |
| 39273 | Some(frame.start_cdfs.0.clone()), | 39304 | Some(frame.start_cdfs.0.clone()), |
| @@ -39610,9 +39641,10 @@ mod tests { | |||
| 39610 | // The encoder's own `reference_select` (spec 5.9.22): these | 39641 | // The encoder's own `reference_select` (spec 5.9.22): these |
| 39611 | // GOP round trips decode a tile the ENCODER wrote, so the | 39642 | // GOP round trips decode a tile the ENCODER wrote, so the |
| 39612 | // header bit must be the one it wrote, not a hard-coded | 39643 | // header bit must be the one it wrote, not a hard-coded |
| 39613 | - // `false` (stale-header class -- a `reference_select` stream | ||
| 39614 | - // reads a `comp_mode` symbol this decode would skip). | ||
| 39615 | crate::encode::reference_select(), | 39644 | crate::encode::reference_select(), |
| 39645 | + // lane-intertx: the frame's own `reduced_tx_set` -- see the | ||
| 39646 | + // first GOP round trip's note. | ||
| 39647 | + frame.reduced_tx_set, | ||
| 39616 | frame.tx_select, | 39648 | frame.tx_select, |
| 39617 | &frame.loop_restoration, | 39649 | &frame.loop_restoration, |
| 39618 | Some(frame.start_cdfs.0.clone()), | 39650 | Some(frame.start_cdfs.0.clone()), |
crates/ec-av1/src/encode.rsmodified+48 -15
| @@ -472,21 +472,24 @@ fn inter_tx_type_search() -> InterTxSearch { | |||
| 472 | 472 | ||
| 473 | /// The inter luma [`TxbSet`] a `tx`-sided transform unit reads, `None` for the | 473 | /// The inter luma [`TxbSet`] a `tx`-sided transform unit reads, `None` for the |
| 474 | /// 64-point one (it codes no `tx_type` symbol). | 474 | /// 64-point one (it codes no `tx_type` symbol). |
| 475 | -/// lane-txw: the INTER half of the widening is still NOT applied here, and | 475 | +/// lane-txw history, resolved by lane-intertx: the INTER half of the |
| 476 | -/// the reason lane-txi recorded (the `refs` lane's DPB bookkeeping) was | 476 | +/// widening was blocked by `refusal-from-own-desync` twice over. Half of it |
| 477 | -/// WRONG -- the refusal is `refusal-from-own-desync` twice over. Half of it | ||
| 478 | /// was this writer coding a `V_DCT`/`H_DCT` unit as `TX_CLASS_2D` | 477 | /// was this writer coding a `V_DCT`/`H_DCT` unit as `TX_CLASS_2D` |
| 479 | -/// (`tile::write_coeffs`, fixed by this lane, which is what unblocked the | 478 | +/// (`tile::write_coeffs`, fixed by lane-txw, which unblocked the intra |
| 480 | -/// intra half). What remains is the CHROMA inheritance: an inter block's | 479 | +/// half). The other half was the CHROMA inheritance: an inter block's |
| 481 | /// chroma transform type is the luma type reduced to the chroma size's set | 480 | /// chroma transform type is the luma type reduced to the chroma size's set |
| 482 | /// (`decode::reduce_inherited_chroma_tx_type`), and (a) the encoder never | 481 | /// (`decode::reduce_inherited_chroma_tx_type`), and (a) the encoder never |
| 483 | -/// sets `FrameCtx::reduced_tx_set_inter`, so [`recode_inter_chroma`] reduces | 482 | +/// set `FrameCtx::reduced_tx_set_inter`, so [`recode_inter_chroma`] reduced |
| 484 | -/// against the REDUCED allowance while a `reduced_tx_set = 0` frame's | 483 | +/// against a STALE allowance, and (b) `tile::write_block_planes` coded |
| 485 | -/// decoder allows the full one, and (b) `tile::write_block_planes` codes | 484 | +/// every chroma plane as `DCT_DCT`, so an inherited 1-D type desynced the |
| 486 | -/// every chroma plane as `DCT_DCT`, so an inherited 1-D type desyncs the | 485 | +/// chroma exactly as luma did. lane-intertx fixed both -- the frame sets |
| 487 | -/// chroma exactly as luma did. Both are deferred with the wider inter search | 486 | +/// its own bit on the context (`encode_inter_frame`), the writer derives |
| 488 | -/// itself; the intra half needs neither (an intra block's chroma type comes | 487 | +/// the chroma type from this frame's own header bit |
| 489 | -/// off its own UV mode, never off luma). | 488 | +/// (`reduce_inherited_chroma_tx_type_flagged`) -- and the widened SEARCH |
| 489 | +/// names these sets through [`luma_set_for`] at its call sites, so the | ||
| 490 | +/// wider candidates are reachable and honestly priced. The intra half | ||
| 491 | +/// never needed either (an intra block's chroma type comes off its own UV | ||
| 492 | +/// mode, never off luma). | ||
| 490 | fn inter_luma_set(tx: usize) -> Option<TxbSet> { | 493 | fn inter_luma_set(tx: usize) -> Option<TxbSet> { |
| 491 | Some(match tx { | 494 | Some(match tx { |
| 492 | 4 => TxbSet::Luma4Inter, | 495 | 4 => TxbSet::Luma4Inter, |
| @@ -1794,6 +1797,7 @@ pub(crate) fn crop_encoded(encoded: &Encoded, width: usize, height: usize) -> En | |||
| 1794 | tx_select: encoded.tx_select, | 1797 | tx_select: encoded.tx_select, |
| 1795 | switchable_motion_mode: encoded.switchable_motion_mode, | 1798 | switchable_motion_mode: encoded.switchable_motion_mode, |
| 1796 | screen: encoded.screen, | 1799 | screen: encoded.screen, |
| 1800 | + reduced_tx_set: encoded.reduced_tx_set, | ||
| 1797 | start_cdfs: encoded.start_cdfs.clone(), | 1801 | start_cdfs: encoded.start_cdfs.clone(), |
| 1798 | next_cdfs: encoded.next_cdfs.clone(), | 1802 | next_cdfs: encoded.next_cdfs.clone(), |
| 1799 | loop_filter: encoded.loop_filter, | 1803 | loop_filter: encoded.loop_filter, |
| @@ -1880,6 +1884,14 @@ pub struct Encoded { | |||
| 1880 | /// palette-mode symbols under it, so a raw tile decode that guessed | 1884 | /// palette-mode symbols under it, so a raw tile decode that guessed |
| 1881 | /// `false` would desync at the first block (same class as `tx_select`). | 1885 | /// `false` would desync at the first block (same class as `tx_select`). |
| 1882 | pub(crate) screen: bool, | 1886 | pub(crate) screen: bool, |
| 1887 | + /// This frame header's own `reduced_tx_set` (spec 5.9.2) -- the bit that | ||
| 1888 | + /// picks the inter `tx_type` alphabets AND, on an inter block, the | ||
| 1889 | + /// allowance the chroma transform's inherited type reduces against | ||
| 1890 | + /// ([`crate::decode::reduce_inherited_chroma_tx_type`]). A raw tile | ||
| 1891 | + /// decode that guesses `true` here mis-derives every inherited chroma | ||
| 1892 | + /// type on a `reduced_tx_set = 0` frame (lane-intertx; same class as | ||
| 1893 | + /// `tx_select`/`screen` above). | ||
| 1894 | + pub(crate) reduced_tx_set: bool, | ||
| 1883 | /// This frame header's chosen loop restoration parameters, threaded for | 1895 | /// This frame header's chosen loop restoration parameters, threaded for |
| 1884 | /// the same reason as `loop_filter` -- and doubly so: the per-unit | 1896 | /// the same reason as `loop_filter` -- and doubly so: the per-unit |
| 1885 | /// filters themselves are coded in `tile`, so a decode of it under a | 1897 | /// filters themselves are coded in `tile`, so a decode of it under a |
| @@ -5109,7 +5121,15 @@ fn commit_inter_luma( | |||
| 5109 | let mut flat_typed: Option<Trial> = None; | 5121 | let mut flat_typed: Option<Trial> = None; |
| 5110 | let mut flat_type = TxType::DctDct; | 5122 | let mut flat_type = TxType::DctDct; |
| 5111 | if !skip { | 5123 | if !skip { |
| 5112 | - if let Some(fset) = inter_luma_set(side) { | 5124 | + // lane-intertx: on a `reduced_tx_set = 0` frame the search names the |
| 5125 | + // Set1 alphabet the writer codes into ([`luma_set_for`], the shape | ||
| 5126 | + // the intra search already takes), which is what makes the wider | ||
| 5127 | + // seven-type candidate list below reachable -- and prices every | ||
| 5128 | + // candidate, `IDTX` included, in the alphabet its symbol is really | ||
| 5129 | + // coded into. | ||
| 5130 | + if let Some(fset) = | ||
| 5131 | + inter_luma_set(side).map(|set| luma_set_for(set, search.screen)) | ||
| 5132 | + { | ||
| 5113 | let lambda = search.lambda * tx_type_lambda_mult(); | 5133 | let lambda = search.lambda * tx_type_lambda_mult(); |
| 5114 | let cost = |t: &Trial| t.sse + lambda * t.bits; | 5134 | let cost = |t: &Trial| t.sse + lambda * t.bits; |
| 5115 | for &tx_type in inter_tx_type_candidates(fset, search.screen) { | 5135 | for &tx_type in inter_tx_type_candidates(fset, search.screen) { |
| @@ -5200,14 +5220,17 @@ fn commit_inter_luma( | |||
| 5200 | return (flat_ref.levels.clone(), 0, flat_gain, vec![flat_type]); | 5220 | return (flat_ref.levels.clone(), 0, flat_gain, vec![flat_type]); |
| 5201 | } | 5221 | } |
| 5202 | let tx = side / 2; | 5222 | let tx = side / 2; |
| 5203 | - let set = if tx >= 32 { | 5223 | + let set = luma_set_for( |
| 5224 | + if tx >= 32 { | ||
| 5204 | // lane-b64b: the 64x64 root's halved transform is TX_32X32. | 5225 | // lane-b64b: the 64x64 root's halved transform is TX_32X32. |
| 5205 | TxbSet::Luma32Inter | 5226 | TxbSet::Luma32Inter |
| 5206 | } else if tx >= 16 { | 5227 | } else if tx >= 16 { |
| 5207 | TxbSet::Luma16Inter | 5228 | TxbSet::Luma16Inter |
| 5208 | } else { | 5229 | } else { |
| 5209 | TxbSet::Luma8Inter | 5230 | TxbSet::Luma8Inter |
| 5210 | - }; | 5231 | + }, |
| 5232 | + search.screen, | ||
| 5233 | + ); | ||
| 5211 | let mut levels = vec![0i32; side * side]; | 5234 | let mut levels = vec![0i32; side * side]; |
| 5212 | let (mut sse, mut bits) = (0.0, 0.0); | 5235 | let (mut sse, mut bits) = (0.0, 0.0); |
| 5213 | let mut units = Vec::with_capacity(4); | 5236 | let mut units = Vec::with_capacity(4); |
| @@ -8859,6 +8882,7 @@ pub(crate) fn encode_key_frame_inner( | |||
| 8859 | // A key frame codes no inter block, so no motion_mode symbol. | 8882 | // A key frame codes no inter block, so no motion_mode symbol. |
| 8860 | switchable_motion_mode: false, | 8883 | switchable_motion_mode: false, |
| 8861 | screen, | 8884 | screen, |
| 8885 | + reduced_tx_set: header.reduced_tx_set, | ||
| 8862 | next_cdfs: start_cdfs.clone(), | 8886 | next_cdfs: start_cdfs.clone(), |
| 8863 | start_cdfs, | 8887 | start_cdfs, |
| 8864 | loop_filter: header.loop_filter, | 8888 | loop_filter: header.loop_filter, |
| @@ -12594,6 +12618,14 @@ pub(crate) fn encode_inter_frame( | |||
| 12594 | // lane-txi, as on the key frame: the header bit the writer's own | 12618 | // lane-txi, as on the key frame: the header bit the writer's own |
| 12595 | // `Cdfs` then reads for every luma `tx_type` symbol. | 12619 | // `Cdfs` then reads for every luma `tx_type` symbol. |
| 12596 | header.reduced_tx_set = !wide_tx_set(screen); | 12620 | header.reduced_tx_set = !wide_tx_set(screen); |
| 12621 | + // lane-intertx, desync (a): the frame context this value is read back | ||
| 12622 | + // through ([`decode::reduce_inherited_chroma_tx_type`] inside | ||
| 12623 | + // `recode_inter_chroma`, and every inter decode helper the search's own | ||
| 12624 | + // trial decode shares) must carry THIS frame's bit, not whatever the | ||
| 12625 | + // previous frame's trial decode last left in the shared cell -- a stale | ||
| 12626 | + // `true` here narrows the chroma allowance the search reconstructs | ||
| 12627 | + // against under the one the header's bit actually allows. | ||
| 12628 | + fctx.reduced_tx_set_inter.set(header.reduced_tx_set); | ||
| 12597 | // The search prices coefficients against the tables this frame's writer | 12629 | // The search prices coefficients against the tables this frame's writer |
| 12598 | // starts from, not against the defaults (lane-av1txbits) -- but only on a | 12630 | // starts from, not against the defaults (lane-av1txbits) -- but only on a |
| 12599 | // frame the screen detector said no to (lane-av1price2): armed HERE, after | 12631 | // frame the screen detector said no to (lane-av1price2): armed HERE, after |
| @@ -14088,6 +14120,7 @@ pub(crate) fn encode_inter_frame( | |||
| 14088 | tx_select, | 14120 | tx_select, |
| 14089 | switchable_motion_mode, | 14121 | switchable_motion_mode, |
| 14090 | screen, | 14122 | screen, |
| 14123 | + reduced_tx_set: header.reduced_tx_set, | ||
| 14091 | start_cdfs, | 14124 | start_cdfs, |
| 14092 | next_cdfs, | 14125 | next_cdfs, |
| 14093 | loop_filter: header.loop_filter, | 14126 | loop_filter: header.loop_filter, |
crates/ec-av1/src/encoder.rsmodified+101 -0
| @@ -4993,6 +4993,107 @@ mod tests { | |||
| 4993 | eprintln!("SKIP the ffmpeg half: no ffmpeg"); | 4993 | eprintln!("SKIP the ffmpeg half: no ffmpeg"); |
| 4994 | } | 4994 | } |
| 4995 | } | 4995 | } |
| 4996 | + /// lane-intertx's witness: on a clip the screen detector calls | ||
| 4997 | + /// NON-screen, the inter luma search offers the wider | ||
| 4998 | + /// `reduced_tx_set = 0` alphabets and CODES a 1-D `V_DCT`/`H_DCT` unit | ||
| 4999 | + /// (a `coded > 0` guard on the committed-winners census, class | ||
| 5000 | + /// `gate-blind-to-feature`), the block's chroma transforms inherit that | ||
| 5001 | + /// type reduced to the chroma size's set against the frame's own honest | ||
| 5002 | + /// header bit, and BOTH decoders reconstruct every frame sample-exact on | ||
| 5003 | + /// ALL THREE planes -- chroma is the plane the inheritance desync | ||
| 5004 | + /// corrupts, so luma-only comparisons cannot see it. | ||
| 5005 | + #[test] | ||
| 5006 | + #[ignore = "sets process-global search levers: run it alone"] | ||
| 5007 | + fn a_non_screen_inter_clip_codes_a_one_d_type_both_decoders_read_every_plane_exactly() { | ||
| 5008 | + let _knobs = crate::speed::knob_write(); | ||
| 5009 | + let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 5010 | + crate::encode::set_intra_tx_search(Some(true)); | ||
| 5011 | + crate::encode::set_inter_tx_search(Some(true)); | ||
| 5012 | + crate::encode::set_wide_tx_set(Some(true)); | ||
| 5013 | + crate::encode::force_screen(Some(false)); | ||
| 5014 | + let (width, height) = (320usize, 192usize); | ||
| 5015 | + // The wide witness's moving card: vertical steps (where a 1-D | ||
| 5016 | + // `V_DCT`/`H_DCT` beats the 2-D DCT on the motion-compensated | ||
| 5017 | + // residual), ramps (`ADST`) and moving plateaus (`IDTX`), translated | ||
| 5018 | + // a few samples per frame so the inter search sees real motion. | ||
| 5019 | + let sources: Vec<Picture> = (0..4) | ||
| 5020 | + .map(|t| { | ||
| 5021 | + let mut p = test_card(width, height, t * 3); | ||
| 5022 | + for y in 0..height { | ||
| 5023 | + for x in 0..width { | ||
| 5024 | + let v = match ((x + t * 5) / 16 % 2, (y + t * 3) / 16 % 2) { | ||
| 5025 | + (0, 0) => 16u16, | ||
| 5026 | + (1, 0) => 235, | ||
| 5027 | + (0, 1) => ((x + t) % 64 * 3) as u16, | ||
| 5028 | + _ => ((y + t) % 64 * 3) as u16, | ||
| 5029 | + }; | ||
| 5030 | + p.y[y * width + x] = v; | ||
| 5031 | + } | ||
| 5032 | + } | ||
| 5033 | + p | ||
| 5034 | + }) | ||
| 5035 | + .collect(); | ||
| 5036 | + let config = EncoderConfig { | ||
| 5037 | + width, | ||
| 5038 | + height, | ||
| 5039 | + base_q_idx: 90, | ||
| 5040 | + gop: 4, | ||
| 5041 | + colour: Colour::Bt709Limited, | ||
| 5042 | + tile_cols_log2: 0, | ||
| 5043 | + tile_rows_log2: 0, | ||
| 5044 | + }; | ||
| 5045 | + let mut enc = Av1Encoder::new(config).unwrap(); | ||
| 5046 | + let _ = crate::encode::take_inter_tx_type_hits(); | ||
| 5047 | + let mut stream = Vec::new(); | ||
| 5048 | + for packet in encode_all(&mut enc, &sources) { | ||
| 5049 | + stream.extend_from_slice(&packet.data); | ||
| 5050 | + } | ||
| 5051 | + let hits = crate::encode::take_inter_tx_type_hits(); | ||
| 5052 | + crate::encode::force_screen(None); | ||
| 5053 | + crate::encode::set_wide_tx_set(None); | ||
| 5054 | + crate::encode::set_inter_tx_search(None); | ||
| 5055 | + crate::encode::set_intra_tx_search(None); | ||
| 5056 | + use crate::transform::TxType; | ||
| 5057 | + eprintln!( | ||
| 5058 | + "inter wide-set witness: inter hits {hits:?}, {} bytes", | ||
| 5059 | + stream.len() | ||
| 5060 | + ); | ||
| 5061 | + assert!( | ||
| 5062 | + hits[TxType::Idtx as usize] > 0, | ||
| 5063 | + "no inter luma unit was CODED IDTX: {hits:?}" | ||
| 5064 | + ); | ||
| 5065 | + assert!( | ||
| 5066 | + hits[TxType::VDct as usize] + hits[TxType::HDct as usize] > 0, | ||
| 5067 | + "no inter luma unit was CODED a 1-D type -- the wider search \ | ||
| 5068 | + never fired on non-screen content (class gate-blind-to-feature): {hits:?}" | ||
| 5069 | + ); | ||
| 5070 | + let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | ||
| 5071 | + assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | ||
| 5072 | + if have_ffmpeg() { | ||
| 5073 | + let theirs = ffmpeg_decode_planes(&stream, width, height); | ||
| 5074 | + assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | ||
| 5075 | + let (cw, ch) = (width / 2, height / 2); | ||
| 5076 | + for (i, (a, (y, u, v))) in ours.iter().zip(&theirs).enumerate() { | ||
| 5077 | + for (name, got16, want, w) in | ||
| 5078 | + [("y", &a.y, y, width), ("u", &a.u, u, cw), ("v", &a.v, v, ch)] | ||
| 5079 | + { | ||
| 5080 | + let got: Vec<u8> = got16.iter().map(|&s| s as u8).collect(); | ||
| 5081 | + assert_eq!(got.len(), want.len(), "frame {i} {name} plane size"); | ||
| 5082 | + if let Some(at) = got.iter().zip(want.iter()).position(|(x, y)| x != y) { | ||
| 5083 | + panic!( | ||
| 5084 | + "frame {i}: {name} differs first at ({}, {}): ours {} vs ffmpeg {}", | ||
| 5085 | + at % w, | ||
| 5086 | + at / w, | ||
| 5087 | + got[at], | ||
| 5088 | + want[at], | ||
| 5089 | + ); | ||
| 5090 | + } | ||
| 5091 | + } | ||
| 5092 | + } | ||
| 5093 | + } else { | ||
| 5094 | + eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 5095 | + } | ||
| 5096 | + } | ||
| 4996 | 5097 | ||
| 4997 | /// Every SHIPPED SPEED PRESET codes a stream both decoders reconstruct | 5098 | /// Every SHIPPED SPEED PRESET codes a stream both decoders reconstruct |
| 4998 | /// sample-exact -- ours and ffmpeg's -- and codes a DIFFERENT stream from | 5099 | /// sample-exact -- ours and ffmpeg's -- and codes a DIFFERENT stream from |
crates/ec-av1/src/stream.rsmodified+5 -2
| @@ -3035,8 +3035,11 @@ pub(crate) mod tests { | |||
| 3035 | &encoded.cdef, | 3035 | &encoded.cdef, |
| 3036 | &encoded.loop_filter, | 3036 | &encoded.loop_filter, |
| 3037 | encoded.tx_select, | 3037 | encoded.tx_select, |
| 3038 | - // Our own encoder always writes `reduced_tx_set: true`. | 3038 | + // lane-intertx: the frame's own `reduced_tx_set` -- a screen |
| 3039 | - true, | 3039 | + // key frame at preset 0 codes the wider intra alphabets, so |
| 3040 | + // the old hardcoded `true` (ours "always" wrote true) is a | ||
| 3041 | + // stale-header bug waiting for the first screen fixture. | ||
| 3042 | + encoded.reduced_tx_set, | ||
| 3040 | // `allow_screen_content_tools` off the frame the encoder | 3043 | // `allow_screen_content_tools` off the frame the encoder |
| 3041 | // actually wrote: a screen-content picture codes two palette | 3044 | // actually wrote: a screen-content picture codes two palette |
| 3042 | // symbols per intra block, and a raw tile decode that guessed | 3045 | // symbols per intra block, and a raw tile decode that guessed |
crates/ec-av1/src/tile.rsmodified+34 -2
| @@ -4827,6 +4827,7 @@ fn write_block( | |||
| 4827 | tx_mode, | 4827 | tx_mode, |
| 4828 | tx_select, | 4828 | tx_select, |
| 4829 | block_tx_type(block), | 4829 | block_tx_type(block), |
| 4830 | + false, | ||
| 4830 | ); | 4831 | ); |
| 4831 | neighbours.record_planes(at, side, mode, grids, !split); | 4832 | neighbours.record_planes(at, side, mode, grids, !split); |
| 4832 | clear_skip_band(neighbours, at_mi, side); | 4833 | clear_skip_band(neighbours, at_mi, side); |
| @@ -4927,6 +4928,7 @@ fn write_leaf8( | |||
| 4927 | tx_mode, | 4928 | tx_mode, |
| 4928 | tx_select, | 4929 | tx_select, |
| 4929 | block_tx_type(block), | 4930 | block_tx_type(block), |
| 4931 | + false, | ||
| 4930 | ); | 4932 | ); |
| 4931 | neighbours.record_mi_planes(leaf_mi, 8, grids, !split); | 4933 | neighbours.record_mi_planes(leaf_mi, 8, grids, !split); |
| 4932 | clear_skip_band(neighbours, leaf_mi, 8); | 4934 | clear_skip_band(neighbours, leaf_mi, 8); |
| @@ -4951,7 +4953,20 @@ fn write_block_planes( | |||
| 4951 | // This block's single luma transform type (lane-txset); chroma's is | 4953 | // This block's single luma transform type (lane-txset); chroma's is |
| 4952 | // derived from its mode by the decoder and codes no symbol. | 4954 | // derived from its mode by the decoder and codes no symbol. |
| 4953 | luma_tx_type: TxType, | 4955 | luma_tx_type: TxType, |
| 4956 | + // lane-intertx: an INTER block's chroma transforms INHERIT the luma | ||
| 4957 | + // type (reduced to the chroma set against this frame's own | ||
| 4958 | + // `reduced_tx_set` bit); an intra block's comes off its UV mode and | ||
| 4959 | + // rides `DCT_DCT`'s 2D class exactly as before. | ||
| 4960 | + inter: bool, | ||
| 4954 | ) { | 4961 | ) { |
| 4962 | + // lane-intertx, desync (b): the writer used to code every chroma plane | ||
| 4963 | + // `DCT_DCT`. Chroma codes no `tx_type` symbol, but the type names the | ||
| 4964 | + // transform class, and the class picks the scan, the `eob_pt` row and | ||
| 4965 | + // the context offsets (the lane-txw note in `write_coeffs`) -- so an | ||
| 4966 | + // inherited 1-D luma type desynced the chroma exactly as luma itself | ||
| 4967 | + // once did. The reduced bit read here is the frame's own header bit, | ||
| 4968 | + // the ONE the writer's `Cdfs` is armed with (`Cdfs::reduced_tx_set`). | ||
| 4969 | + let reduced = cdfs.reduced_tx_set; | ||
| 4955 | for (plane, (grid, scan)) in grids.iter().zip(scans.iter()).enumerate() { | 4970 | for (plane, (grid, scan)) in grids.iter().zip(scans.iter()).enumerate() { |
| 4956 | if plane == 0 && skip_luma { | 4971 | if plane == 0 && skip_luma { |
| 4957 | continue; | 4972 | continue; |
| @@ -4969,15 +4984,28 @@ fn write_block_planes( | |||
| 4969 | let before = enc.tell(); | 4984 | let before = enc.tell(); |
| 4970 | #[cfg(test)] | 4985 | #[cfg(test)] |
| 4971 | let q_ctx = cdfs.q_ctx; | 4986 | let q_ctx = cdfs.q_ctx; |
| 4987 | + let mut coding = cdfs.txb(planes[plane], mode); | ||
| 4988 | + let tx_type = if plane == 0 { | ||
| 4989 | + luma_tx_type | ||
| 4990 | + } else if inter { | ||
| 4991 | + crate::decode::reduce_inherited_chroma_tx_type_flagged( | ||
| 4992 | + luma_tx_type, | ||
| 4993 | + coding.side.min(32), | ||
| 4994 | + coding.side.min(32), | ||
| 4995 | + reduced, | ||
| 4996 | + ) | ||
| 4997 | + } else { | ||
| 4998 | + TxType::DctDct | ||
| 4999 | + }; | ||
| 4972 | write_coeffs( | 5000 | write_coeffs( |
| 4973 | enc, | 5001 | enc, |
| 4974 | - &mut cdfs.txb(planes[plane], mode), | 5002 | + &mut coding, |
| 4975 | grid, | 5003 | grid, |
| 4976 | scan, | 5004 | scan, |
| 4977 | skip_ctx, | 5005 | skip_ctx, |
| 4978 | dc_sign_ctx(around[plane].dc_vote), | 5006 | dc_sign_ctx(around[plane].dc_vote), |
| 4979 | Some(plane), | 5007 | Some(plane), |
| 4980 | - if plane == 0 { luma_tx_type } else { TxType::DctDct }, | 5008 | + tx_type, |
| 4981 | ); | 5009 | ); |
| 4982 | #[cfg(test)] | 5010 | #[cfg(test)] |
| 4983 | census_record( | 5011 | census_record( |
| @@ -7474,6 +7502,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 7474 | 0, | 7502 | 0, |
| 7475 | split, | 7503 | split, |
| 7476 | block_tx_type(block), | 7504 | block_tx_type(block), |
| 7505 | + true, | ||
| 7477 | ); | 7506 | ); |
| 7478 | neighbours.record_planes(sb_at, SB, 0, &grids, !split); | 7507 | neighbours.record_planes(sb_at, SB, 0, &grids, !split); |
| 7479 | } | 7508 | } |
| @@ -7938,6 +7967,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 7938 | mode_for_tx, | 7967 | mode_for_tx, |
| 7939 | split, | 7968 | split, |
| 7940 | block_tx_type(block), | 7969 | block_tx_type(block), |
| 7970 | + is_inter, | ||
| 7941 | ); | 7971 | ); |
| 7942 | neighbours.record_planes(at, BLOCK, mode_for_tx, &grids, !split); | 7972 | neighbours.record_planes(at, BLOCK, mode_for_tx, &grids, !split); |
| 7943 | } | 7973 | } |
| @@ -8179,6 +8209,7 @@ fn write_inter_frame_leaf( | |||
| 8179 | mode_for_tx, | 8209 | mode_for_tx, |
| 8180 | split, | 8210 | split, |
| 8181 | block_tx_type(block), | 8211 | block_tx_type(block), |
| 8212 | + is_inter, | ||
| 8182 | ); | 8213 | ); |
| 8183 | neighbours.record_planes(at, SUB, mode_for_tx, &grids, !split); | 8214 | neighbours.record_planes(at, SUB, mode_for_tx, &grids, !split); |
| 8184 | } | 8215 | } |
| @@ -8432,6 +8463,7 @@ fn write_inter_frame_leaf8( | |||
| 8432 | mode_for_tx, | 8463 | mode_for_tx, |
| 8433 | split, | 8464 | split, |
| 8434 | block_tx_type(block), | 8465 | block_tx_type(block), |
| 8466 | + is_inter, | ||
| 8435 | ); | 8467 | ); |
| 8436 | neighbours.record_mi_planes(leaf_mi, 8, &grids, !split); | 8468 | neighbours.record_mi_planes(leaf_mi, 8, &grids, !split); |
| 8437 | neighbours.record_inter_mi(leaf_mi, 8, block.skip, is_inter, block_ref(block)); | 8469 | neighbours.record_inter_mi(leaf_mi, 8, block.skip, is_inter, block_ref(block)); |
lanes/intertx.charter.mdadded+104 -0
| @@ -0,0 +1,104 @@ | |||
| 1 | +# lane-intertx — inter tx-type search on film (TX_TYPE_SEARCH_INTER past screen-only) | ||
| 2 | + | ||
| 3 | +GOAL: the inter tx-type search (`inter_tx_type_search`, encode.rs ~L450) | ||
| 4 | +runs only on screen content at the preset lever | ||
| 5 | +(`crate::speed::TX_TYPE_SEARCH_INTER` → `InterTxSearch::Screen`). | ||
| 6 | +`EC_AV1_TXSET_INTER=all` exists but has never been measured on film, and | ||
| 7 | +the `inter_luma_set` doc (encode.rs ~L475) records a deferred CHROMA | ||
| 8 | +inheritance desync: (a) `FrameCtx::reduced_tx_set_inter` never set while | ||
| 9 | +`recode_inter_chroma` reduces against the reduced allowance, and (b) | ||
| 10 | +`tile::write_block_planes` codes every chroma plane `DCT_DCT`, so an | ||
| 11 | +inherited 1-D luma type desyncs chroma. This lane makes inter tx-type | ||
| 12 | +search correct and measured on film, then ships or parks by the keep | ||
| 13 | +rule. | ||
| 14 | + | ||
| 15 | +Work ONLY in this worktree (`lane-intertx`, | ||
| 16 | +`/home/user/Documents/Code/Rust/edith_codecs-intertx`). Absolute paths | ||
| 17 | +only. Never touch main's checkout or the rectres worktree, never push, | ||
| 18 | +never `git checkout <file>`, never repo-wide `cargo fmt` (rustfmt only | ||
| 19 | +files you edited). Local builds: `export | ||
| 20 | +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-intertx`. Local logs under | ||
| 21 | +`~/.cache/intertx/`. Media files read-only. Pins 8291 / 33227. Keep | ||
| 22 | +rule: one film row ≥0.5 BD down on a column, the other flat within | ||
| 23 | +±0.3, screen not worse by 0.3, wall ≤+15%. BD-rate, lower better. | ||
| 24 | + | ||
| 25 | +## 1. Correctness first (witnesses BEFORE any BD gate) | ||
| 26 | + | ||
| 27 | +- Determine whether the chroma inheritance desync is LIVE when the | ||
| 28 | + search offers non-`DCT_DCT` types on inter blocks: build a witness in | ||
| 29 | + the standing pattern (process-global `set_inter_tx_search` override + | ||
| 30 | + `crate::speed::knob_write`, like the existing inter-tx witness) on | ||
| 31 | + NON-screen content where the search picks a 1-D type, decoded | ||
| 32 | + sample-exact through ffmpeg AND `decode_stream` (all planes — the | ||
| 33 | + desync is chroma). If it desyncs: fix (a) and (b) — the decoder's | ||
| 34 | + `decode::reduce_inherited_chroma_tx_type` is the spec behavior; the | ||
| 35 | + encoder must set `reduced_tx_set_inter` honestly and code chroma with | ||
| 36 | + the inherited reduced type, not unconditional `DCT_DCT`. | ||
| 37 | +- Witness must assert the search actually WON a non-`DCT_DCT` inter | ||
| 38 | + type (a `coded > 0`-style counter guard — class | ||
| 39 | + `gate-blind-to-feature`), on a frame the detector calls non-screen. | ||
| 40 | + | ||
| 41 | +## 2. Measure (control = Screen, arm = All) | ||
| 42 | + | ||
| 43 | +Both on the SAME server (see §3), same HEAD: | ||
| 44 | + | ||
| 45 | +- `encode::tests::bd_rate_film_long_gop` (deciding, both films): | ||
| 46 | + control = default; arm = `EC_AV1_TXSET_INTER=all`. | ||
| 47 | +- `encode::tests::bd_rate_screen_native` (all five rows), control and | ||
| 48 | + arm. The screen row must not regress (arm should equal control there | ||
| 49 | + — screen already searches; if it moves, find out why). | ||
| 50 | +- Census: non-`DCT_DCT` inter tx-type picks per clip (search won / | ||
| 51 | + coded), printed per run; report per-frame rates like lane-b128res §4. | ||
| 52 | + | ||
| 53 | +Keep rule met → make the lever `All` at the presets where it measured | ||
| 54 | +(a speed.rs preset-table change), pins at default and `EC_AV1_SPEED=6`, | ||
| 55 | +three-lane lib suite LOCALLY (`--skip stream::` / `stream:: --skip | ||
| 56 | +10bit` / `10bit`), `timeout 900 cargo check --workspace --all-targets | ||
| 57 | +-j4` (0 ec-av1 warnings). Not met → leave `Screen`, document. | ||
| 58 | + | ||
| 59 | +## 3. Gates run on server-1 (the box stays free for lane-rectres) | ||
| 60 | + | ||
| 61 | +server-1 = `user@host-e` (Fedora 44, 4 vCPU, 7G RAM, rust 1.98.1, | ||
| 62 | +ffmpeg with libaom-av1+librav1e). Provisioned layout: | ||
| 63 | +`/home/user/gates/library/fixtures/` (bars fixtures + rewritten | ||
| 64 | +real-library-manifest.tsv), `/home/user/gates/library/Films/ | ||
| 65 | +filmA-gate.mkv` + `filmB-gate.mkv` (windowed substitutes, sha256-verified | ||
| 66 | +pixel-identical to the originals at the pinned seeks — 48 frames each), | ||
| 67 | +`/home/user/gates/library/OBS/…mkv` (screen row), | ||
| 68 | +`/home/user/gates/bin/ffmpeg` (shim that rewrites the pinned `-ss` | ||
| 69 | +values onto the windows; all other invocations exec `/usr/bin/ffmpeg` | ||
| 70 | +untouched). | ||
| 71 | + | ||
| 72 | +Gate recipe per run (control and arm alike): | ||
| 73 | + | ||
| 74 | +``` | ||
| 75 | +rsync -a --delete --exclude /fixtures/ --exclude /target/ \ | ||
| 76 | + --exclude /.git/ \ | ||
| 77 | + /home/user/Documents/Code/Rust/edith_codecs-intertx/ \ | ||
| 78 | + user@host-e:/home/user/gates/repo-intertx/ | ||
| 79 | +ssh -o BatchMode=yes user@host-e 'ln -sfn \ | ||
| 80 | + /home/user/gates/library/fixtures \ | ||
| 81 | + /home/user/gates/repo-intertx/fixtures' | ||
| 82 | +ssh -o BatchMode=yes user@host-e 'cat /proc/loadavg; cd | ||
| 83 | + /home/user/gates/repo-intertx && PATH=/home/user/gates/bin:$PATH \ | ||
| 84 | + CARGO_TARGET_DIR=/home/user/gates/target-intertx \ | ||
| 85 | + [EC_AV1_TXSET_INTER=all] \ | ||
| 86 | + systemd-run --user -p MemoryMax=5G --wait --unit=intertx-<name> \ | ||
| 87 | + --pipe cargo test -p ec-av1 --release --lib -- --ignored --exact \ | ||
| 88 | + --nocapture encode::tests::bd_rate_film_long_gop; cat /proc/loadavg' \ | ||
| 89 | + | tee ~/.cache/intertx/<name>.log | ||
| 90 | +``` | ||
| 91 | + | ||
| 92 | +If `systemd-run --user` is unavailable on the server (no user session | ||
| 93 | +bus), run bare and note it. First run compiles (~15 min on 4 vCPU) — | ||
| 94 | +that is normal. ONE gate at a time on the server. LOADAVG before AND | ||
| 95 | +after, recorded. `--ignored --exact` is load-bearing (the tests are | ||
| 96 | +`#[ignore]`). TMPDIR never on any cargo line. | ||
| 97 | + | ||
| 98 | +## DONE | ||
| 99 | + | ||
| 100 | +Commits on `lane-intertx` + `lanes/intertx.report.md` with EVIDENCE | ||
| 101 | +lines (`EVIDENCE: <artifact> | <steps> | <measurement>`), witness | ||
| 102 | +results, BD tables control vs arm on both gates, tx-type census, wall | ||
| 103 | +deltas, LOADAVG pairs, pins line, disposition `ships-on | stays-off | | ||
| 104 | +stopped`. Never merge or push. | ||
lanes/intertx.report.mdadded+258 -0
| @@ -0,0 +1,258 @@ | |||
| 1 | +# lane-intertx — the inter tx-type search on film (chroma inheritance made honest) | ||
| 2 | + | ||
| 3 | +Base: `810d8972` (charter). Fix commit: `9af60b4d`. Regression fix + report | ||
| 4 | +commit: this one. Disposition: **stays-off** | ||
| 5 | +(`crate::speed::TX_TYPE_SEARCH_INTER` keeps `Screen` at presets 0-6; the keep | ||
| 6 | +rule's deciding column fails at best -0.1 against the required -0.5), but the | ||
| 7 | +lane's correctness work is real and committed: the chroma inheritance desync | ||
| 8 | +was LIVE and is fixed, the wider inter search is reachable and honest on | ||
| 9 | +`reduced_tx_set = 0` frames, and on screen content the fix itself measures | ||
| 10 | +-0.7/-0.4 BD against the pre-lane standing table. Pins untouched at | ||
| 11 | +8291 / 33227 (default non-screen streams byte-identical; pin test re-run | ||
| 12 | +green). Never merged, never pushed. | ||
| 13 | + | ||
| 14 | +## 1. The chroma inheritance desync: LIVE, fixed | ||
| 15 | + | ||
| 16 | +The wider inter search (`inter_tx_type_candidates`' seven-type `INTER_WIDE` | ||
| 17 | +list) was unreachable: `inter_luma_set` named only the plain `Luma*Inter` | ||
| 18 | +sets, so the `Set1` arms were dead code. The refusal reason lane-txi recorded | ||
| 19 | +(the refs lane's DPB bookkeeping) was already known wrong; the real blocker | ||
| 20 | +was `refusal-from-own-desync` in the CHROMA inheritance: | ||
| 21 | + | ||
| 22 | +- (a) the encoder never set `FrameCtx::reduced_tx_set_inter` on the shared | ||
| 23 | + frame context, so `recode_inter_chroma`'s | ||
| 24 | + `reduce_inherited_chroma_tx_type` reduced against a STALE allowance — | ||
| 25 | + whatever the previous frame's own trial decode had last left in the cell — | ||
| 26 | + while a `reduced_tx_set = 0` frame's decoder allows the full set; | ||
| 27 | +- (b) `tile::write_block_planes` coded every chroma plane as `DCT_DCT`. | ||
| 28 | + Chroma codes no `tx_type` symbol, but the type names the transform class, | ||
| 29 | + and the class picks the scan, the `eob_pt` row and the neighbour contexts | ||
| 30 | + (`write_coeffs`' lane-txw note) — so an inherited 1-D type desynced the | ||
| 31 | + chroma exactly as luma once did. | ||
| 32 | + | ||
| 33 | +Fix (commit `9af60b4d`): (a) `encode_inter_frame` sets | ||
| 34 | +`fctx.reduced_tx_set_inter` from the frame's own header bit the moment it is | ||
| 35 | +decided (`header.reduced_tx_set = !wide_tx_set(screen)`); (b) the writer | ||
| 36 | +derives each inter block's chroma type from the first luma unit's coded type | ||
| 37 | +via the new `decode::reduce_inherited_chroma_tx_type_flagged` against | ||
| 38 | +`Cdfs::reduced_tx_set` — the frame's own honest bit — and codes chroma with | ||
| 39 | +it; the search names the Set1 sets through `luma_set_for` (the intra search's | ||
| 40 | +own shape) at both the flat and the split-unit trial, so every candidate is | ||
| 41 | +priced in the alphabet its symbol is coded into. All six | ||
| 42 | +`write_block_planes` callers now pass the block's inter flag; intra chroma | ||
| 43 | +rides `DCT_DCT`'s 2D class exactly as before. | ||
| 44 | + | ||
| 45 | +Witness `encoder::tests::a_non_screen_inter_clip_codes_a_one_d_type_both_decoders_read_every_plane_exactly` | ||
| 46 | +(process-global `set_inter_tx_search(Some(true))` + `set_wide_tx_set(Some(true))` | ||
| 47 | ++ `force_screen(Some(false))` under `knob_write`, 320x192 moving | ||
| 48 | +steps/ramps/plateaus, gop 4, q 90): the inter search WON and CODED | ||
| 49 | +non-`DCT_DCT` types on the non-screen clip, and ALL THREE planes read | ||
| 50 | +sample-exact through `decode_stream` AND ffmpeg at every frame. | ||
| 51 | + | ||
| 52 | +EVIDENCE: ~/.cache/intertx/witness-green.log | --ignored --exact --nocapture | ||
| 53 | +run of the witness on `9af60b4d` | "inter wide-set witness: inter hits | ||
| 54 | +[200, 979, 3, 97, 111, 40, 521, 0, ...], 8143 bytes" — coded>0 guards pass | ||
| 55 | +for `IDTX` (200) and for the 1-D types (`V_DCT`=40 + `H_DCT`=521); all three | ||
| 56 | +planes identical to ffmpeg on all four frames. ok. | ||
| 57 | + | ||
| 58 | +RED run (desync live): with the widening applied and fix (b) neutralized — | ||
| 59 | +chroma coded `DCT_DCT` unconditionally, the pre-lane writer — the same encode | ||
| 60 | +FAILS inside its own trial decode: the reader inherits the 1-D chroma type | ||
| 61 | +the writer refused to code with, the tile desyncs, and the derail surfaces as | ||
| 62 | +"a reference frame selected with no picture at this frame's own | ||
| 63 | +ref_frame_idx slot" (class `refusal-from-own-desync`, not a real ref defect). | ||
| 64 | + | ||
| 65 | +EVIDENCE: ~/.cache/intertx/witness-red.log | same witness, fix (b) probe | ||
| 66 | +removed | FAILED: trial-decode refusal aborts the encode at flush. | ||
| 67 | + | ||
| 68 | +Standing witnesses re-run green on the fixed HEAD: the wide witness now codes | ||
| 69 | +1-D inter units on its screen card too (`V_DCT`=41, `H_DCT`=405, `IDTX`=702 | ||
| 70 | +of 1305) and reads every frame exact; the two-type inter witness passes. | ||
| 71 | + | ||
| 72 | +EVIDENCE: ~/.cache/intertx/standing-witnesses.log | --ignored --exact and | ||
| 73 | +default runs | "a_wide_tx_set_clip... ok", "an_inter_clip... ok". | ||
| 74 | + | ||
| 75 | +## 2. Long-GOP BD (deciding; 48 pictures, gop=48, both films, server-1) | ||
| 76 | + | ||
| 77 | +Control = default (lever `Screen`), arm = `EC_AV1_TXSET_INTER=all`, same HEAD | ||
| 78 | +`9af60b4d`, same ladder (`encode::tests::bd_rate_film_long_gop`, | ||
| 79 | +`--ignored --exact`). BD-rate, lower better: | ||
| 80 | + | ||
| 81 | +| row | ctrl vs libaom | ctrl vs rav1e | arm vs libaom | arm vs rav1e | | ||
| 82 | +|---|---|---|---|---| | ||
| 83 | +| film A (1080p) 1920x768 | +20.9% | -9.0% | +20.8% | -9.1% | | ||
| 84 | +| film B (2160p HDR) 1920x1024 | +70.4% | -2.2% | +70.3% | -2.1% | | ||
| 85 | + | ||
| 86 | +Arm-minus-control: film A -0.1/-0.1, film B -0.1/+0.1. The control | ||
| 87 | +reproduces the standing table (b128res-era film A +20.9/-9.0, film B | ||
| 88 | ++70.4/-2.2) to the digit on a different HEAD. | ||
| 89 | + | ||
| 90 | +Wall ours: film A 1314.7s -> 1395.1s (+6.1%), film B 1031.5s -> 1074.0s | ||
| 91 | +(+4.1%). LOADAVG 0.28/0.35/0.20 before, 1.30/1.20/1.11 after (control); | ||
| 92 | +0.93/1.12/1.09 before, 1.12/1.10/1.09 after (arm). | ||
| 93 | + | ||
| 94 | +EVIDENCE: ~/.cache/intertx/longgop-control.log | gate 2 control, server-1, | ||
| 95 | +MemoryMax=5G, `systemd-run --user` | film A +20.9%/-9.0%, film B | ||
| 96 | ++70.4%/-2.2%; census 100.0% `DCT_DCT` on both films. ok. | ||
| 97 | +EVIDENCE: ~/.cache/intertx/longgop-arm.log | gate 2 arm, EC_AV1_TXSET_INTER=all | | ||
| 98 | +film A +20.8%/-9.1%, film B +70.3%/-2.1%. ok. | ||
| 99 | + | ||
| 100 | +## 3. 12-frame native guard (all five rows, server-1) | ||
| 101 | + | ||
| 102 | +`encode::tests::bd_rate_screen_native`, control and arm: | ||
| 103 | + | ||
| 104 | +| row | ctrl vs libaom | ctrl vs rav1e | arm vs libaom | arm vs rav1e | | ||
| 105 | +|---|---|---|---|---| | ||
| 106 | +| bars 1080p | -3.3% | -19.0% | -3.5% | -19.0% | | ||
| 107 | +| bars 2160p | +8.4% | -13.9% | +8.5% | -13.8% | | ||
| 108 | +| film A | +17.9% | -6.3% | +17.8% | -6.4% | | ||
| 109 | +| film B | +22.6% | -3.8% | +22.7% | -3.7% | | ||
| 110 | +| screen capture | +13.7% | -33.6% | +13.7% | -33.6% | | ||
| 111 | + | ||
| 112 | +The screen row is byte-identical between control and arm (same PSNR/bytes at | ||
| 113 | +every point, same census) — exactly the charter's prediction: the search is | ||
| 114 | +already on for screen frames, so `All` can add nothing there. | ||
| 115 | + | ||
| 116 | +Wall ours: bars 1080p 396.2s -> 411.1s (+3.8%), bars 2160p 336.3s -> 358.1s | ||
| 117 | +(+6.5%), film A 350.9s -> 371.0s (+5.7%), film B 301.4s -> 309.8s (+2.8%), | ||
| 118 | +screen capture 226.1s -> 225.1s (-0.4%). LOADAVG 0.88/1.05/1.07 before, | ||
| 119 | +1.07/1.14/1.11 after (control); 0.91/1.10/1.10 before, 1.12/1.13/1.09 after | ||
| 120 | +(arm). | ||
| 121 | + | ||
| 122 | +Screen-content attribution note: the control screen row against the | ||
| 123 | +b128res-era standing table moved +14.4% -> +13.7% (libaom) and -33.2% -> | ||
| 124 | +-33.6% (rav1e). That delta is THIS lane's fix reaching the screen default: | ||
| 125 | +the widened inter candidates are now offered to screen frames at preset 0, | ||
| 126 | +where the lever already said `Screen`, and the census shows the new types | ||
| 127 | +coding (below). Cross-HEAD comparison, so attribution is indicative only. | ||
| 128 | + | ||
| 129 | +EVIDENCE: ~/.cache/intertx/native-control.log | gate 3 control, five rows | | ||
| 130 | +table above, control columns; three-way exactness held at every clip x q x | ||
| 131 | +frame. ok. | ||
| 132 | +EVIDENCE: ~/.cache/intertx/native-arm.log | gate 3 arm, EC_AV1_TXSET_INTER=all | | ||
| 133 | +table above, arm columns. ok. | ||
| 134 | + | ||
| 135 | +## 4. Inter tx-type census (search won / coded, per clip) | ||
| 136 | + | ||
| 137 | +Non-`DCT_DCT` share of COMMITTED inter luma units (the census names types | ||
| 138 | +that were really coded), arm runs: | ||
| 139 | + | ||
| 140 | +| clip | inter units | coded non-DCT_DCT | share | | ||
| 141 | +|---|---|---|---| | ||
| 142 | +| film A long-GOP | 1468708 | 35618 `IDTX` | 2.4% | | ||
| 143 | +| film B long-GOP | 1250132 | 41586 `IDTX` | 3.3% | | ||
| 144 | +| bars 1080p 12f | 115907 | 21033 `IDTX` | 18.1% | | ||
| 145 | +| bars 2160p 12f | 83614 | 20634 `IDTX` | 24.7% | | ||
| 146 | +| film A 12f | 330189 | 7311 `IDTX` | 2.2% | | ||
| 147 | +| film B 12f | 310009 | 7002 `IDTX` | 2.3% | | ||
| 148 | +| screen capture 12f | 59731 | 1080 `IDTX` + 266 `ADST_ADST` + 346 `ADST_DCT` + 187 `DCT_ADST` + 455 `V_DCT` + 1572 `H_DCT` | 6.5% | | ||
| 149 | + | ||
| 150 | +Controls: 100.0% `DCT_DCT` on every non-screen clip (lever off there); | ||
| 151 | +screen capture control already carries the wider alphabet (the fix's doing). | ||
| 152 | +With `all`, film takes only the two-type set's `IDTX` (2.2-3.3%) — the | ||
| 153 | +arm is INERT ON FILM, the same 0-to-small band the b128res arm showed. | ||
| 154 | +Every one of these units decoded three-way exact (encoder == ffmpeg == | ||
| 155 | +decode_stream) at every q point of every run — the gates' standing | ||
| 156 | +exactness assertion covers the whole census, native resolution, both films | ||
| 157 | +and all five native rows. | ||
| 158 | + | ||
| 159 | +## 5. Keep rule — NOT met | ||
| 160 | + | ||
| 161 | +One film row >=0.5 BD down on a column: best delta anywhere is -0.1 (film A | ||
| 162 | +long-GOP and 12-frame; native bars rows are not film). Other film row flat | ||
| 163 | +within +/-0.3: yes (max 0.1). Screen not worse by 0.3: yes (byte-identical). | ||
| 164 | +Wall <= +15%: yes (max +6.5%). The deciding column fails at -0.1 against the | ||
| 165 | +required -0.5: `IDTX` at 2-3% of film units buys a tenth of a point. The | ||
| 166 | +lever stays `Screen` at every preset; `speed.rs` is untouched. | ||
| 167 | + | ||
| 168 | +## 6. Pins, witnesses, scope | ||
| 169 | + | ||
| 170 | +- Pins `encode::tests::the_encoders_own_streams_are_byte_identical_to_their_pins`: | ||
| 171 | + re-run green on `9af60b4d` — `(150, 8291, 0x1f00bb0eb099a27f)` and | ||
| 172 | + `(60, 33227, 0x57ee6b1f8eacd881)` stand. The pin fixture is the non-screen | ||
| 173 | + h264 clip, where the fix changes nothing by construction (the widened | ||
| 174 | + candidates need `reduced_tx_set = 0`, which only screen frames code at the | ||
| 175 | + default preset). No pin re-take. | ||
| 176 | + | ||
| 177 | +EVIDENCE: ~/.cache/intertx/pins.log | default-preset pin run on 9af60b4d | | ||
| 178 | +ok, both pins byte-identical. | ||
| 179 | + | ||
| 180 | +- server-1 provisioning verified before the first gate: filmA-gate.mkv 8833494 | ||
| 181 | + bytes, filmB-gate.mkv 195927872 bytes, no partial files. | ||
| 182 | +- Gate recipe deviations from charter §3 (all recorded): `systemd-run` | ||
| 183 | + needs `-p WorkingDirectory=` (the unit does not inherit the shell's cwd), | ||
| 184 | + `PATH`/`CARGO_TARGET_DIR` must be set INSIDE the unit (a | ||
| 185 | + `bash -lc` wrapper), and the synced repo's `.git` was a stale worktree | ||
| 186 | + pointer file that broke the memguard runner's `git rev-parse` — replaced | ||
| 187 | + with a fresh `git init` on the server. One gate at a time throughout. | ||
| 188 | +- Not verified: nothing in the charter's scope is unverified. The | ||
| 189 | + three-lane lib suite and `cargo check --workspace --all-targets` were NOT | ||
| 190 | + run — charter §2 requires them only on the keep-rule-met (ships-on) | ||
| 191 | + branch; the stays-off branch carries the scoped local checks (ec-av1 lib | ||
| 192 | + + tests compile warning-free; the three tx witnesses; the pin test) and | ||
| 193 | + project-wide validation stays with the main agent. `FLIPADST` family and | ||
| 194 | + the 1-D ADSTs remain unoffered (the standing lane-txi deferral). | ||
| 195 | + | ||
| 196 | +## 7. Regression caught by the merge tier: the raw-tile decode wrapper's | ||
| 197 | +## stale `reduced_tx_set` | ||
| 198 | + | ||
| 199 | +Main's regression tier caught three `decode::tests` failures on the lane | ||
| 200 | +HEAD (`a_gop_round_trips_bit_exact_against_the_encoder_reconstruction`, | ||
| 201 | +`an_odd_size_gop_round_trips_bit_exact_against_the_encoder_reconstruction`, | ||
| 202 | +`ffmpeg_and_this_decoder_agree_on_a_gop`), all refusing with "a reference | ||
| 203 | +frame selected with no picture at this frame's own ref_frame_idx slot". | ||
| 204 | + | ||
| 205 | +Root cause (class: **test asserts against a stale header** -- the wrapper's | ||
| 206 | +own parameter docs document five prior instances of exactly this class): | ||
| 207 | +`decode::decode_inter_frame_tile_lr`, the raw-tile decode helper the GOP | ||
| 208 | +round-trip tests use, hard-coded `reduced_tx_set: true` | ||
| 209 | +(`decode.rs:34552` at the fix commit's parent) with the comment "this | ||
| 210 | +wrapper's callers are the decoder's own tests, which all code the reduced | ||
| 211 | +sets". True until this lane: no inter block ever inherited a non-`DCT_DCT` | ||
| 212 | +chroma type. With the widened inter search live, a screen-detected GOP at | ||
| 213 | +the default preset codes `reduced_tx_set = 0` frames whose inter luma takes | ||
| 214 | +`V_DCT` (the traces show the first inter block at (0,0) 16x16 winning | ||
| 215 | +exactly that), and the chroma inheritance reduces the inherited type | ||
| 216 | +against the very bit the wrapper guessed: the test's decode derived | ||
| 217 | +`DCT_DCT` from `inh=Some(V_DCT)` at chroma 8x8 where the writer coded | ||
| 218 | +`V_DCT`, desynced, and the garbage symbols eventually read a ref_frame_idx | ||
| 219 | +that names an empty slot -- the named refusal is downstream noise, the | ||
| 220 | +first divergence is the chroma type. | ||
| 221 | + | ||
| 222 | +Fix (this commit): the wrapper takes the frame's own | ||
| 223 | +`reduced_tx_set: bool` (placed before `tx_select`, mirroring the plural | ||
| 224 | +fn), `Encoded` carries the bit (`encode.rs`, the `screen`/`tx_select` | ||
| 225 | +pattern), the GOP tests and the key-frame tile test (`stream.rs`, whose | ||
| 226 | +"our own encoder always writes `reduced_tx_set: true`" comment had the | ||
| 227 | +same latent stale-header bug) pass the honest value. | ||
| 228 | + | ||
| 229 | +Why the gates and witnesses did not see it: every production decode path | ||
| 230 | +(`stream.rs`'s parser, `decode_stream`, ffmpeg) reads the bit off the wire | ||
| 231 | +honestly -- the gates' three-way exactness and all witnesses ride those. | ||
| 232 | +Only the raw-tile test helper guessed. | ||
| 233 | + | ||
| 234 | +Encoder output is UNCHANGED by the fix: the diff touches the `Encoded` | ||
| 235 | +metadata struct, the test-facing decode wrappers and one test call -- no | ||
| 236 | +writer or search code (tile.rs is not in the fix diff at all), and the | ||
| 237 | +three witnesses code byte-identical streams after it (8143 / 8211 bytes, | ||
| 238 | +same census). The server-1 BD tables in sections 2-4 remain valid; no gate | ||
| 239 | +re-run needed. | ||
| 240 | + | ||
| 241 | +EVIDENCE: ~/.cache/intertx/regression-repro.log | the three tests on the | ||
| 242 | +unfixed lane HEAD | 3 failed, all with the named refusal. | ||
| 243 | +EVIDENCE: ~/.cache/intertx/regression-fix.log | the three tests + the pin | ||
| 244 | +test after the fix | 4 passed. | ||
| 245 | +EVIDENCE: ~/.cache/intertx/witness-rerun.log | all three tx witnesses | ||
| 246 | +re-run after the fix | byte-identical streams (8143 / 8211 bytes), ok. | ||
| 247 | + | ||
| 248 | +## 8. Full suite and workspace check (post-fix) | ||
| 249 | + | ||
| 250 | +Three-lane lib suite LOCALLY on the fix commit, `--release --lib`: | ||
| 251 | +`--skip stream::` 348 passed / 0 failed; `stream:: --skip 10bit` 202 | ||
| 252 | +passed / 0 failed; `10bit` 42 passed / 0 failed -- **592 passed, 0 | ||
| 253 | +failed**. `timeout 900 cargo check --workspace --all-targets -j4`: 0 | ||
| 254 | +ec-av1 warnings (the 25 workspace warnings are ec-opus's, pre-existing). | ||
| 255 | + | ||
| 256 | +EVIDENCE: ~/.cache/intertx/suite-lane1.log | --skip stream:: | 348 passed. | ||
| 257 | +EVIDENCE: ~/.cache/intertx/suite-lane2.log | stream:: --skip 10bit | 202 passed. | ||
| 258 | +EVIDENCE: ~/.cache/intertx/suite-lane3.log | 10bit | 42 passed. | ||