Merge branch 'lane-txw' (832daabb): the tile writer coded every transform unit as TX_CLASS_2D; V_DCT/H_DCT now take the 1-D class scan, eob row and contexts; wide intra tx set ships screen-gated
Browse files at this commit6 changed files +308 -31
- crates/ec-av1/src/decode.rs +4 -4
- crates/ec-av1/src/encode.rs +15 -11
- crates/ec-av1/src/encoder.rs +1 -3
- crates/ec-av1/src/speed.rs +11 -3
- crates/ec-av1/src/tile.rs +121 -10
- lanes/txw.report.md +156 -0
crates/ec-av1/src/decode.rsmodified+4 -4
| @@ -5508,7 +5508,7 @@ fn default_scan_gen(side: usize) -> Vec<u16> { | ||
| 5508 | 5508 | /// `Mrow_Scan` visits row 0 across every column, then row 1, ... — precisely |
| 5509 | 5509 | /// `0..side*side` in our own indexing — and `Mcol_Scan` is that walk |
| 5510 | 5510 | /// transposed (column 0 down every row, then column 1, ...). |
| 5511 | -fn class_scan_table(side: usize, class: TxClass) -> Vec<u16> { | |
| 5511 | +pub(crate) fn class_scan_table(side: usize, class: TxClass) -> Vec<u16> { | |
| 5512 | 5512 | class_scan_table_wh(side, side, class) |
| 5513 | 5513 | } |
| 5514 | 5514 | |
| @@ -5555,14 +5555,14 @@ fn neighbour(grid: &[u8], stride: usize, row: usize, col: usize) -> i32 { | ||
| 5555 | 5555 | /// `txb_common.h`): everything but the two lone-axis-identity types this |
| 5556 | 5556 | /// decoder reads (`V_DCT`/`H_DCT`) is `TX_CLASS_2D`. |
| 5557 | 5557 | #[derive(Clone, Copy, PartialEq, Eq)] |
| 5558 | -enum TxClass { | |
| 5558 | +pub(crate) enum TxClass { | |
| 5559 | 5559 | TwoD, |
| 5560 | 5560 | Horiz, |
| 5561 | 5561 | Vert, |
| 5562 | 5562 | } |
| 5563 | 5563 | |
| 5564 | 5564 | impl TxClass { |
| 5565 | - fn of(tx_type: TxType) -> Self { | |
| 5565 | + pub(crate) fn of(tx_type: TxType) -> Self { | |
| 5566 | 5566 | match tx_type { |
| 5567 | 5567 | // `TX_CLASS_VERT`/`TX_CLASS_HORIZ` (`txb_common.h`'s `tx_type_to_class`) |
| 5568 | 5568 | // key on axis alone -- FLIPADST is still ADST for this purpose. |
| @@ -5578,7 +5578,7 @@ impl TxClass { | ||
| 5578 | 5578 | /// `col` for horiz, `row` for vert) that places their contexts past the 2D |
| 5579 | 5579 | /// table's own 26 rows (`SIG_COEF_CONTEXTS_2D`), 16 rows total |
| 5580 | 5580 | /// (`SIG_COEF_CONTEXTS_1D`) split 26/31/36. |
| 5581 | -fn nz_map_ctx_offset_1d(i: usize) -> usize { | |
| 5581 | +pub(crate) fn nz_map_ctx_offset_1d(i: usize) -> usize { | |
| 5582 | 5582 | match i { |
| 5583 | 5583 | 0 => 26, |
| 5584 | 5584 | 1 => 31, |
crates/ec-av1/src/encode.rsmodified+15 -11
| @@ -472,17 +472,21 @@ fn inter_tx_type_search() -> InterTxSearch { | ||
| 472 | 472 | |
| 473 | 473 | /// The inter luma [`TxbSet`] a `tx`-sided transform unit reads, `None` for the |
| 474 | 474 | /// 64-point one (it codes no `tx_type` symbol). |
| 475 | -/// lane-txi: the INTER half of the widening is deliberately NOT applied | |
| 476 | -/// here. A `reduced_tx_set = 0` frame's writer still codes its inter luma | |
| 477 | -/// `tx_type` into the twelve/sixteen-symbol alphabet (the frame bit widens | |
| 478 | -/// every luma set at once, spec `get_tx_set`), but the SEARCH keeps offering | |
| 479 | -/// the two-type list: with the wider inter candidates priced, some block's | |
| 480 | -/// winner selects a reference slot this encoder holds no picture in | |
| 481 | -/// ("a reference frame selected with no picture at this frame's own | |
| 482 | -/// ref_frame_idx slot for it", refused out of the encoder's own MC), which is | |
| 483 | -/// the `refs` lane's DPB bookkeeping (`encoder.rs` maps LAST2/LAST3 onto | |
| 484 | -/// LAST's slot), not a transform defect -- measured by bisection: the intra | |
| 485 | -/// half alone passes every witness, the inter half alone refuses. | |
| 475 | +/// lane-txw: the INTER half of the widening is still NOT applied here, and | |
| 476 | +/// the reason lane-txi recorded (the `refs` lane's DPB bookkeeping) was | |
| 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` | |
| 479 | +/// (`tile::write_coeffs`, fixed by this lane, which is what unblocked the | |
| 480 | +/// intra half). What remains is the CHROMA inheritance: an inter block's | |
| 481 | +/// 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 | |
| 483 | +/// sets `FrameCtx::reduced_tx_set_inter`, so [`recode_inter_chroma`] reduces | |
| 484 | +/// against the REDUCED allowance while a `reduced_tx_set = 0` frame's | |
| 485 | +/// decoder allows the full one, and (b) `tile::write_block_planes` codes | |
| 486 | +/// every chroma plane as `DCT_DCT`, so an inherited 1-D type desyncs the | |
| 487 | +/// chroma exactly as luma did. Both are deferred with the wider inter search | |
| 488 | +/// itself; the intra half needs neither (an intra block's chroma type comes | |
| 489 | +/// off its own UV mode, never off luma). | |
| 486 | 490 | fn inter_luma_set(tx: usize) -> Option<TxbSet> { |
| 487 | 491 | Some(match tx { |
| 488 | 492 | 4 => TxbSet::Luma4Inter, |
crates/ec-av1/src/encoder.rsmodified+1 -3
| @@ -3822,9 +3822,7 @@ mod tests { | ||
| 3822 | 3822 | /// (class `wrong-alphabet-same-value`: a disagreement here changes no |
| 3823 | 3823 | /// symbol VALUE and desyncs the arithmetic coder anyway). |
| 3824 | 3824 | #[test] |
| 3825 | - #[ignore = "reduced_tx_set = 0 desyncs the encoder's own trial decode when the \ | |
| 3826 | - seven-type intra search is on -- bisected in lanes/txi.report.md; \ | |
| 3827 | - the lever is off at every preset until that is closed"] | |
| 3825 | + #[ignore = "sets process-global search levers: run it alone"] | |
| 3828 | 3826 | fn a_wide_tx_set_clip_codes_the_new_alphabets_both_decoders_read_exactly() { |
| 3829 | 3827 | // Every lever below is process-global: the same exclusive lock the |
| 3830 | 3828 | // presets take. |
crates/ec-av1/src/speed.rsmodified+11 -3
| @@ -515,10 +515,18 @@ pub(crate) const TX_TYPE_SEARCH_INTER: [bool; 11] = [ | ||
| 515 | 515 | /// `encode::wide_tx_set`: whether a frame codes `reduced_tx_set = 0`, the |
| 516 | 516 | /// wider `tx_type` alphabets (intra 8x8/4x4 seven types, inter 16x16 twelve, |
| 517 | 517 | /// inter 8x8/4x4 sixteen) instead of the reduced sets every stream this |
| 518 | -/// encoder wrote before lane-txi carries. OFF at every preset until the gate | |
| 519 | -/// says otherwise; `EC_AV1_TXSET_WIDE` overrides. | |
| 518 | +/// encoder wrote before lane-txi carries. ON at preset 0, SCREEN CONTENT ONLY | |
| 519 | +/// like both halves of the type search itself (`encode::wide_tx_set` returns | |
| 520 | +/// the screen flag), so a non-screen frame codes the same | |
| 521 | +/// `reduced_tx_set = 1` bit and the same bytes as before. | |
| 522 | +/// MEASURED at preset 0 (lane-txw, 12-frame `bd_rate_screen_native`, screen | |
| 523 | +/// row): +19.8/-30.5 -> +14.8/-32.9 -- five BD points against libaom and 2.4 | |
| 524 | +/// against rav1e, on 2.8% `V_DCT` + 7.4% `H_DCT` of the row's intra units, | |
| 525 | +/// the two types only the seven-type `TX_SET_INTRA_1` can name. It costs | |
| 526 | +/// wall: 92.8s -> 123.3s for the row. Presets 1..6 carry the type search but | |
| 527 | +/// are UNMEASURED here, so they stay off. `EC_AV1_TXSET_WIDE` overrides. | |
| 520 | 528 | pub(crate) const WIDE_TX_SET: [bool; 11] = [ |
| 521 | - false, false, false, false, false, false, false, false, false, false, false, | |
| 529 | + true, false, false, false, false, false, false, false, false, false, false, | |
| 522 | 530 | ]; |
| 523 | 531 | |
| 524 | 532 | /// `filter_search`: whether the deblock ladder's +-1/+-2 refinement stage runs. |
crates/ec-av1/src/tile.rsmodified+121 -10
| @@ -4724,6 +4724,29 @@ fn scan_of(side: usize) -> &'static Vec<u16> { | ||
| 4724 | 4724 | } |
| 4725 | 4725 | } |
| 4726 | 4726 | |
| 4727 | +/// [`scan_of`]'s `TX_CLASS_HORIZ`/`TX_CLASS_VERT` sibling (lane-txw): the | |
| 4728 | +/// `Mrow_Scan`/`Mcol_Scan` a `V_DCT`/`H_DCT` unit is coded in, built off the | |
| 4729 | +/// DECODER's own table so the two cannot drift, cached per size and class. | |
| 4730 | +fn class_scan_of(side: usize, class: crate::decode::TxClass) -> &'static [u16] { | |
| 4731 | + static SCANS: LazyLock<[[Vec<u16>; 2]; 4]> = LazyLock::new(|| { | |
| 4732 | + use crate::decode::{TxClass, class_scan_table}; | |
| 4733 | + [TX4, TX8, TX16, TX32].map(|side| { | |
| 4734 | + [ | |
| 4735 | + class_scan_table(side, TxClass::Horiz), | |
| 4736 | + class_scan_table(side, TxClass::Vert), | |
| 4737 | + ] | |
| 4738 | + }) | |
| 4739 | + }); | |
| 4740 | + let size = match side { | |
| 4741 | + TX4 => 0, | |
| 4742 | + TX8 => 1, | |
| 4743 | + TX16 => 2, | |
| 4744 | + _ => 3, | |
| 4745 | + }; | |
| 4746 | + let idx = usize::from(class == crate::decode::TxClass::Vert); | |
| 4747 | + &SCANS[size][idx] | |
| 4748 | +} | |
| 4749 | + | |
| 4727 | 4750 | /// [`coeff_bits_typed`] at `DCT_DCT`, the only type the test-only pricers |
| 4728 | 4751 | /// ([`predicted_coeff_bits`]) model. |
| 4729 | 4752 | #[cfg(test)] |
| @@ -4936,7 +4959,19 @@ pub(crate) fn rdoq( | ||
| 4936 | 4959 | // cannot cost two hundred re-codings. |
| 4937 | 4960 | let mut budget = rdoq_budget(); |
| 4938 | 4961 | let max_level = rdoq_max_level(); |
| 4939 | - for &position in scan_of(coded).iter().rev() { | |
| 4962 | + // lane-txw: the tail this walks back from is the tail of the unit's OWN | |
| 4963 | + // scan -- a `V_DCT`/`H_DCT` unit is coded in `Mrow_Scan`/`Mcol_Scan`, so | |
| 4964 | + // the 2D zigzag's last positions are not the ones whose removal shortens | |
| 4965 | + // its eob. Every candidate is still priced through the class-aware writer | |
| 4966 | + // ([`write_coeffs`]), so this changes which positions the budget reaches, | |
| 4967 | + // never whether a decision is right. | |
| 4968 | + let class = crate::decode::TxClass::of(tx_type); | |
| 4969 | + let order: &[u16] = if class == crate::decode::TxClass::TwoD { | |
| 4970 | + scan_of(coded) | |
| 4971 | + } else { | |
| 4972 | + class_scan_of(coded, class) | |
| 4973 | + }; | |
| 4974 | + for &position in order.iter().rev() { | |
| 4940 | 4975 | if budget == 0 { |
| 4941 | 4976 | break; |
| 4942 | 4977 | } |
| @@ -5233,6 +5268,22 @@ fn write_coeffs( | ||
| 5233 | 5268 | ec_rng_trace(|| format!("EC_PLANE plane={plane} tell_before={}", enc.tell())); |
| 5234 | 5269 | } |
| 5235 | 5270 | let side = coding.side; |
| 5271 | + // lane-txw ROOT CAUSE: this writer used to code every transform unit as | |
| 5272 | + // `TX_CLASS_2D` -- default zigzag scan, the 2D `eob_pt` table and the 2D | |
| 5273 | + // neighbour taps -- while the decoder resolves `V_DCT`/`H_DCT` to | |
| 5274 | + // `TX_CLASS_VERT`/`TX_CLASS_HORIZ` (`decode::TxClass::of`), which read | |
| 5275 | + // their own scan (`class_scan_table`), their own `eob_pt` row | |
| 5276 | + // (`eob_pt_class1`) and their own context offsets. So the first 1-D type | |
| 5277 | + // the search ever offered (the wider `reduced_tx_set == 0` alphabets) | |
| 5278 | + // desynced the tile from its own trial decode. The class is a property of | |
| 5279 | + // the type alone, so it is resolved here, once per unit, exactly as the | |
| 5280 | + // reader does it. | |
| 5281 | + let class = crate::decode::TxClass::of(tx_type); | |
| 5282 | + let scan: &[u16] = if class == crate::decode::TxClass::TwoD { | |
| 5283 | + scan | |
| 5284 | + } else { | |
| 5285 | + class_scan_of(side, class) | |
| 5286 | + }; | |
| 5236 | 5287 | // The scan-order search reads the grid in scan order, one dependent load |
| 5237 | 5288 | // per position, and an all-zero block makes it walk every one of them -- |
| 5238 | 5289 | // which the pricer does for candidate after candidate. A straight-line |
| @@ -5280,7 +5331,7 @@ fn write_coeffs( | ||
| 5280 | 5331 | } |
| 5281 | 5332 | } |
| 5282 | 5333 | |
| 5283 | - write_eob(enc, coding, eob, plane); | |
| 5334 | + write_eob(enc, coding, eob, plane, class); | |
| 5284 | 5335 | |
| 5285 | 5336 | // lane-av1speed3: `side` is 4, 8, 16 or 32, but it is a runtime value -- |
| 5286 | 5337 | // `pos / side` compiles to a real integer division, once per coefficient, |
| @@ -5305,7 +5356,7 @@ fn write_coeffs( | ||
| 5305 | 5356 | }); |
| 5306 | 5357 | } |
| 5307 | 5358 | } else { |
| 5308 | - let ctx = base_ctx(grid, side, row, col); | |
| 5359 | + let ctx = base_ctx(grid, side, row, col, class); | |
| 5309 | 5360 | let sym = level.min(NUM_BASE_LEVELS + 1) as usize; |
| 5310 | 5361 | enc.symbol(sym, &mut coding.base[ctx]); |
| 5311 | 5362 | if plane.is_some() { |
| @@ -5318,7 +5369,7 @@ fn write_coeffs( | ||
| 5318 | 5369 | } |
| 5319 | 5370 | } |
| 5320 | 5371 | if level > NUM_BASE_LEVELS { |
| 5321 | - let ctx = br_ctx(grid, side, row, col); | |
| 5372 | + let ctx = br_ctx(grid, side, row, col, class); | |
| 5322 | 5373 | let mut remaining = level - (NUM_BASE_LEVELS + 1); |
| 5323 | 5374 | let mut sent = 0; |
| 5324 | 5375 | while sent < COEFF_BASE_RANGE { |
| @@ -5379,7 +5430,13 @@ fn write_coeffs( | ||
| 5379 | 5430 | /// The end-of-block position (spec 5.11.39): which group of scan positions the |
| 5380 | 5431 | /// last coded coefficient falls in, then its offset inside that group — the |
| 5381 | 5432 | /// offset's top bit from a CDF and the rest as raw bits. |
| 5382 | -fn write_eob(enc: &mut SymbolEncoder, coding: &mut TxbTables, eob: usize, plane: Option<usize>) { | |
| 5433 | +fn write_eob( | |
| 5434 | + enc: &mut SymbolEncoder, | |
| 5435 | + coding: &mut TxbTables, | |
| 5436 | + eob: usize, | |
| 5437 | + plane: Option<usize>, | |
| 5438 | + class: crate::decode::TxClass, | |
| 5439 | +) { | |
| 5383 | 5440 | /// `Eob_Group_Start` (spec 5.11.39): the first scan position each group of |
| 5384 | 5441 | /// end-of-block positions covers, indexed by the group's own number. |
| 5385 | 5442 | const GROUP_START: [usize; 12] = [0, 1, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513]; |
| @@ -5391,8 +5448,14 @@ fn write_eob(enc: &mut SymbolEncoder, coding: &mut TxbTables, eob: usize, plane: | ||
| 5391 | 5448 | .rposition(|&start| start <= eob) |
| 5392 | 5449 | .expect("the first group starts at zero"); |
| 5393 | 5450 | // The groups are numbered from one, and how many of them the transform |
| 5394 | - // reaches is the size of its own end-of-block alphabet. | |
| 5395 | - enc.symbol(group - 1, coding.eob_pt); | |
| 5451 | + // reaches is the size of its own end-of-block alphabet. A | |
| 5452 | + // `TX_CLASS_HORIZ`/`TX_CLASS_VERT` unit adapts a wholly separate row | |
| 5453 | + // (libaom's `eob_multi_ctx`), which is what `decode::read_eob` reads. | |
| 5454 | + let eob_pt: &mut [u16] = match (class, coding.eob_pt_class1.as_deref_mut()) { | |
| 5455 | + (crate::decode::TxClass::TwoD, _) | (_, None) => coding.eob_pt, | |
| 5456 | + (_, Some(class1)) => class1, | |
| 5457 | + }; | |
| 5458 | + enc.symbol(group - 1, eob_pt); | |
| 5396 | 5459 | if let Some(plane) = plane { |
| 5397 | 5460 | ec_rng_trace(|| { |
| 5398 | 5461 | format!( |
| @@ -5460,10 +5523,35 @@ fn eob_coeff_ctx(scan_idx: usize, area: usize) -> usize { | ||
| 5460 | 5523 | /// five neighbours below and to the right of it — the ones a decoder walking |
| 5461 | 5524 | /// the scan backwards already has — plus a term for where in the transform it |
| 5462 | 5525 | /// sits. The DC reads context 0 whatever its neighbours carry. |
| 5463 | -fn base_ctx(grid: &[i32], side: usize, row: usize, col: usize) -> usize { | |
| 5464 | - if row == 0 && col == 0 { | |
| 5526 | +fn base_ctx( | |
| 5527 | + grid: &[i32], | |
| 5528 | + side: usize, | |
| 5529 | + row: usize, | |
| 5530 | + col: usize, | |
| 5531 | + class: crate::decode::TxClass, | |
| 5532 | +) -> usize { | |
| 5533 | + use crate::decode::TxClass; | |
| 5534 | + // Only `TX_CLASS_2D` short-circuits its DC to context 0 | |
| 5535 | + // (`get_nz_map_ctx_from_stats`'s `(tx_class | coeff_idx) == 0`); a 1-D | |
| 5536 | + // class runs the DC through the same neighbour sum as every other | |
| 5537 | + // position. | |
| 5538 | + if class == TxClass::TwoD && row == 0 && col == 0 { | |
| 5465 | 5539 | return 0; |
| 5466 | 5540 | } |
| 5541 | + if class != TxClass::TwoD { | |
| 5542 | + let offsets: [(usize, usize); 5] = if class == TxClass::Horiz { | |
| 5543 | + [(1, 0), (0, 1), (0, 2), (0, 3), (0, 4)] | |
| 5544 | + } else { | |
| 5545 | + [(1, 0), (0, 1), (2, 0), (3, 0), (4, 0)] | |
| 5546 | + }; | |
| 5547 | + let mag: i32 = offsets | |
| 5548 | + .iter() | |
| 5549 | + .map(|&(dr, dc)| neighbour(grid, side, row + dr, col + dc).abs().min(3)) | |
| 5550 | + .sum(); | |
| 5551 | + let along = if class == TxClass::Horiz { col } else { row }; | |
| 5552 | + return (((mag + 1) >> 1).min(4) as usize) | |
| 5553 | + + crate::decode::nz_map_ctx_offset_1d(along.min(31)); | |
| 5554 | + } | |
| 5467 | 5555 | // A coefficient two rows and two columns clear of the far edges reaches |
| 5468 | 5556 | // all five neighbours, so the gather is five loads off one index with no |
| 5469 | 5557 | // per-neighbour edge test -- which is where this writer spends a third of |
| @@ -5487,7 +5575,30 @@ fn base_ctx(grid: &[i32], side: usize, row: usize, col: usize) -> usize { | ||
| 5487 | 5575 | /// The context of a coefficient's base-range tail (spec 8.3.2): the magnitudes |
| 5488 | 5576 | /// of its three closest neighbours below and to the right, uncapped, and a |
| 5489 | 5577 | /// term separating the DC, the corner of the transform, and the rest. |
| 5490 | -fn br_ctx(grid: &[i32], side: usize, row: usize, col: usize) -> usize { | |
| 5578 | +fn br_ctx( | |
| 5579 | + grid: &[i32], | |
| 5580 | + side: usize, | |
| 5581 | + row: usize, | |
| 5582 | + col: usize, | |
| 5583 | + class: crate::decode::TxClass, | |
| 5584 | +) -> usize { | |
| 5585 | + use crate::decode::TxClass; | |
| 5586 | + if class != TxClass::TwoD { | |
| 5587 | + let extra = if class == TxClass::Horiz { | |
| 5588 | + neighbour(grid, side, row, col + 2) | |
| 5589 | + } else { | |
| 5590 | + neighbour(grid, side, row + 2, col) | |
| 5591 | + }; | |
| 5592 | + let mag = neighbour(grid, side, row + 1, col).abs() | |
| 5593 | + + neighbour(grid, side, row, col + 1).abs() | |
| 5594 | + + extra.abs(); | |
| 5595 | + let mag = (((mag + 1) >> 1).min(6)) as usize; | |
| 5596 | + if row == 0 && col == 0 { | |
| 5597 | + return mag; | |
| 5598 | + } | |
| 5599 | + let near_origin = if class == TxClass::Horiz { col == 0 } else { row == 0 }; | |
| 5600 | + return if near_origin { mag + 7 } else { mag + 14 }; | |
| 5601 | + } | |
| 5491 | 5602 | let p = row * side + col; |
| 5492 | 5603 | let mag: i32 = if row + 1 < side && col + 1 < side { |
| 5493 | 5604 | grid[p + side].abs() + grid[p + 1].abs() + grid[p + side + 1].abs() |
lanes/txw.report.mdadded+156 -0
| @@ -0,0 +1,156 @@ | ||
| 1 | +# lane-txw -- the tile writer coded every transform unit as TX_CLASS_2D | |
| 2 | + | |
| 3 | +## First divergent symbol | |
| 4 | + | |
| 5 | +`EC_AV1_TXSET_WIDE=1 EC_AV1_REFPROBE=1 cargo test -p ec-av1 --release --lib | |
| 6 | +an_inter_clip_codes_both` refused on BWDREF ("a reference frame selected with | |
| 7 | +no picture at this frame's own ref_frame_idx slot"), raised out of the | |
| 8 | +ENCODER's own trial decode (`filter_search::pick_filters` -> | |
| 9 | +`decode_inter_frame_tiles_lr`). No symbol-stream diff was needed: the writer | |
| 10 | +side has no `TxClass` at all (`grep -n "TxClass" crates/ec-av1/src/tile.rs` | |
| 11 | +was empty), while the reader resolves one for every unit | |
| 12 | +(`decode::TxClass::of`). The FIRST symbol that can diverge is therefore the | |
| 13 | +`eob_pt` of the first `V_DCT`/`H_DCT` unit -- the writer coded it into the 2D | |
| 14 | +row, the reader reads `eob_pt_class1` -- and every context after it. | |
| 15 | + | |
| 16 | +## Root cause | |
| 17 | + | |
| 18 | +`tile::write_coeffs` treated every unit as `TX_CLASS_2D`: | |
| 19 | + | |
| 20 | +* default zigzag scan instead of `Mrow_Scan`/`Mcol_Scan` | |
| 21 | + (`decode::class_scan_table`), | |
| 22 | +* `coding.eob_pt` instead of the class-1 row (`eob_pt_class1`, the split | |
| 23 | + lane-av1tx4 r5 put on the reader), | |
| 24 | +* `base_ctx`/`br_ctx` with the 2D taps, the 2D DC short-circuit and | |
| 25 | + `NZ_MAP_CTX_OFFSET_32` instead of the 1-D taps and | |
| 26 | + `nz_map_ctx_offset_1d`. | |
| 27 | + | |
| 28 | +Under the reduced alphabets no search ever offered a 1-D type, so the writer | |
| 29 | +was right by accident. The `reduced_tx_set = 0` intra set (`TX_SET_INTRA_1`) | |
| 30 | +is the first alphabet whose candidate list holds `V_DCT`/`H_DCT`, so the | |
| 31 | +lever exposed it. The refusal is the `refusal-from-own-desync` class: the | |
| 32 | +desynced tile named a reference the frame holds no picture in. | |
| 33 | + | |
| 34 | +## Class and sweep | |
| 35 | + | |
| 36 | +Class: `writer half of a decoder-side split` -- a per-unit property the | |
| 37 | +reader derives (here `TxClass`) that the writer never mirrored. Swept every | |
| 38 | +writer site that codes coefficients: | |
| 39 | + | |
| 40 | +* `tile::write_coeffs` -- the one coefficient writer (luma and chroma, all | |
| 41 | + four square sides, both the tile writer and the pricer through | |
| 42 | + `coeff_bits_typed`): FIXED. Every other pricer funnels through it, so the | |
| 43 | + class reaches them with the fix: `coeff_bits_typed` (the search's price), | |
| 44 | + `coeff_bits` and `predicted_coeff_bits`/`predicted_coeff_bits_sb` (the | |
| 45 | + `#[cfg(test)]` pricers, `DCT_DCT` only by construction -- `TxClass::TwoD`) | |
| 46 | + and `luma_32_coeff_bits` (32x32, which codes no `tx_type` symbol at all). | |
| 47 | +* `tile::rdoq` -- prices every candidate through `coeff_bits_typed`, so its | |
| 48 | + DECISIONS were already class-correct, but it spends its budget from the | |
| 49 | + TAIL of the scan backwards and read the 2D zigzag's tail on a 1-D unit: | |
| 50 | + now walks `class_scan_of` (commit "RDOQ walked the 2D zigzag's tail"). | |
| 51 | +* `tile::write_dc_coeffs` -- the fixed-CDF 32x32 luma DC path; 32x32 codes no | |
| 52 | + `tx_type` symbol and is always `DCT_DCT`, so 2D is correct there. | |
| 53 | +* `tile::write_block_planes` chroma -- codes chroma as `DCT_DCT` while an | |
| 54 | + INTER block's decoder INHERITS the luma type | |
| 55 | + (`decode::reduce_inherited_chroma_tx_type`): a real sibling defect, see | |
| 56 | + "deferred" below. Intra chroma takes its type from its own UV mode, never | |
| 57 | + from luma, so the intra half is unaffected. | |
| 58 | +* `encode::recode_inter_chroma` -- reduces against a `FrameCtx` whose | |
| 59 | + `reduced_tx_set_inter` the encoder NEVER sets (always `true`): same | |
| 60 | + sibling. | |
| 61 | + | |
| 62 | +## Fix | |
| 63 | + | |
| 64 | +`crates/ec-av1/src/tile.rs`: `write_coeffs` resolves `crate::decode::TxClass::of(tx_type)` | |
| 65 | +once per unit and takes its scan (`class_scan_of`, cached, built from the | |
| 66 | +decoder's own `class_scan_table`), its `eob_pt` row (`write_eob` now picks | |
| 67 | +`eob_pt_class1` exactly as `decode::read_eob` does) and class-aware | |
| 68 | +`base_ctx`/`br_ctx` from it. `crates/ec-av1/src/decode.rs`: `TxClass`, | |
| 69 | +`TxClass::of`, `class_scan_table` and `nz_map_ctx_offset_1d` are | |
| 70 | +`pub(crate)` so the writer reads the reader's own tables (class | |
| 71 | +`table-and-reader-move-together`). | |
| 72 | + | |
| 73 | +## Witness | |
| 74 | + | |
| 75 | +`encoder::tests::a_wide_tx_set_clip_codes_the_new_alphabets_both_decoders_read_exactly` | |
| 76 | +un-ignored as a blocker (it keeps a "run it alone" ignore: it sets | |
| 77 | +process-global search levers). At preset 0 it codes | |
| 78 | +`intra [962, 25435, 1630, 1665, 1888, 1820, 2435, 0..]` -- 1820 `V_DCT` and | |
| 79 | +2435 `H_DCT` units, the two types only `TX_SET_INTRA_1` can name -- 8724 | |
| 80 | +bytes, and both decoders (ours and ffmpeg) read every frame sample-exact. | |
| 81 | + | |
| 82 | +## Deferred | |
| 83 | + | |
| 84 | +* `deferred: the INTER half of the widening (`encode::inter_luma_set` still | |
| 85 | + names the narrow sets) -- with it widened the same refusal returns AFTER | |
| 86 | + this fix, and the remaining cause is the chroma inheritance above: the | |
| 87 | + encoder never sets `FrameCtx::reduced_tx_set_inter` (so | |
| 88 | + `recode_inter_chroma` quantises chroma against the REDUCED allowance while | |
| 89 | + a `reduced_tx_set = 0` decoder allows the full one) and | |
| 90 | + `write_block_planes` codes chroma as `DCT_DCT` whatever luma chose -- | |
| 91 | + unblocked by threading the frame bit into the encoder's `FrameCtx` and | |
| 92 | + giving the writer the inherited chroma type. | |
| 93 | +## Gate and decision | |
| 94 | + | |
| 95 | +12-frame `bd_rate_screen_native`, SCREEN row (`EC_AV1_NATIVE_SCREEN=1`), | |
| 96 | +preset 0, control vs `EC_AV1_TXSET_WIDE=screen`: | |
| 97 | + | |
| 98 | +| arm | ours (4 points) | BD vs libaom | BD vs rav1e | wall | | |
| 99 | +|---|---|---|---|---| | |
| 100 | +| control | 45.50/36806, 48.20/45672, 50.78/56996, 53.14/71310 | +19.8% | -30.5% | 92.8s | | |
| 101 | +| wide | 45.38/35791, 48.19/43938, 50.88/55290, 53.24/68250 | +14.8% | -32.9% | 123.3s | | |
| 102 | + | |
| 103 | +The row's intra census goes `IDTX 7.5% / DCT_DCT 80.1% / ADST_ADST 3.3% / | |
| 104 | +ADST_DCT 5.3% / DCT_ADST 3.8%` to `IDTX 4.1% / DCT_DCT 78.0% / ADST_ADST | |
| 105 | +2.4% / ADST_DCT 3.0% / DCT_ADST 2.3% / V_DCT 2.8% / H_DCT 7.4%`: the win is | |
| 106 | +the two types that only exist in the wide set. | |
| 107 | + | |
| 108 | +FILM rows (`EC_AV1_NATIVE_FILM4K=1`), the HEADER BIT ALONE -- the intra type | |
| 109 | +search left screen-gated as shipped, so a film frame searches no type and | |
| 110 | +only the ALPHABET it names changes (`EC_AV1_TXSET_WIDE=1`, every frame): | |
| 111 | + | |
| 112 | +| row | control | bit on every frame | | |
| 113 | +|---|---|---| | |
| 114 | +| bars 2160p | +9.4% / -12.7%, 205409 B at point 1 | +9.6% / -12.6%, 208456 B | | |
| 115 | +| film B 2160p | +26.9% / -0.6%, 27442 B at point 1 | +27.2% / -0.3%, 27562 B | | |
| 116 | + | |
| 117 | +So the answer to the charter's question is YES: the header bit alone MOVES | |
| 118 | +BYTES on a film. Every intra 8x8/4x4 luma unit still codes a `tx_type` | |
| 119 | +symbol, and coding `DCT_DCT` into the seven-symbol `TX_SET_INTRA_1` CDF is | |
| 120 | +not the same number of bits as coding it into the five-symbol | |
| 121 | +`TX_SET_INTRA_2` one -- both films come out 0.2/0.3 WORSE against libaom | |
| 122 | +(and 0.1/0.3 better against rav1e) for it. That fails the keep rule's film | |
| 123 | +half, which is exactly why the lever ships behind the SCREEN gate: | |
| 124 | +`encode::wide_tx_set` returns the frame's own screen flag, so a non-screen | |
| 125 | +frame writes `reduced_tx_set = 1` and the same bytes as before the lane. | |
| 126 | +The byte pins (8562 / 33357) unmoved with the lever ON are the in-suite | |
| 127 | +instance of that. | |
| 128 | + | |
| 129 | +DECISION: `speed::WIDE_TX_SET[0] = true` (preset 0 only). Presets 1..6 carry | |
| 130 | +the type search but were not measured with the wider alphabets, so they stay | |
| 131 | +off; the wall cost at preset 0 is +33% on this row. | |
| 132 | + | |
| 133 | +## Invariants | |
| 134 | + | |
| 135 | +* `ec-av1` lib suite, split under `$HOME/.cache/txw` (final state, lever ON | |
| 136 | + at preset 0): `--skip stream::` 332 passed / 31 ignored; `stream:: --skip | |
| 137 | + 10bit` 198 passed / 15 ignored; `10bit` 42 passed / 1 ignored -- 0 failed | |
| 138 | + in all three (572 / 47 with the `10bit` rows counted twice; one earlier | |
| 139 | + unsplit run of the same tree read 570 passed / 47 ignored). The witness | |
| 140 | + KEEPS an `#[ignore]` -- it sets process-global levers, like | |
| 141 | + `every_speed_preset` -- so the ignored count is unchanged from the | |
| 142 | + charter's 47. | |
| 143 | +* `--include-ignored thread_count`: 2 passed. `--ignored | |
| 144 | + every_speed_preset` (presets 0/3/6/10, both decoders sample-exact): 1 | |
| 145 | + passed. Byte pins: passed inside the first split, 8562 / 33357 unmoved | |
| 146 | + WITH the lever on. `predicted_coeff_bits_track_the_tile_the_writer_wrote` | |
| 147 | + and the facade identity are inside the same split. | |
| 148 | +* the witness at the final tree: `intra [949, 25443, 1659, 1660, 1891, | |
| 149 | + 1785, 2448, ..]` -- 1785 `V_DCT` + 2448 `H_DCT` -- 8724 bytes, ffmpeg and | |
| 150 | + `decode_stream` both sample-exact. | |
| 151 | +* `timeout 900 cargo check --workspace --all-targets -j4`: 0 errors, 0 | |
| 152 | + ec-av1 warnings (the 21 `ec-opus` + 1 `ec-vorbis` warnings pre-date the | |
| 153 | + lane). | |
| 154 | +* `EC_COMP_MISMATCH` is a STALE charter item: the flag exists in no source | |
| 155 | + file in this repo any more (`grep -rn COMP_MISMATCH crates/` matches only | |
| 156 | + older lane reports). |