forge
Explore
Log in

Don't you dare go Hollow

Split transform (TX_8X4/TX_4X8, TX_4X4) on a 16-level 1:4 strip

Browse files at this commit

e1a08a19d7dd4a259a361f259fbab77a268f6236Ahmet Kaan GümüşParent: b1f19e6
  • feat
    • split transform (TX_8X4/TX_4X8, TX_4X4) on a 16-level 1:4 strip
Show full message
feat(av1): split transform (TX_8X4/TX_4X8, TX_4X4) on a 16-level 1:4 strip

The 4K 10-bit AV1 mkv's next stop after the partition itself: every 16x4/4x16
strip of its key frame reads tx_depth != 0. `decode_rect_split`'s own
per-unit walk, inlined into `decode_rect4_16` because the chroma of this
shape belongs to the strip's 4:2:0 PAIR, not to the strip (that function
codes one chroma transform per block). depth 1 is the 2:1 rect unit
TX_8X4/TX_4X8 (`sub_tx_size_map[TX_16X4]`, TxbSet::LumaRect4x8 -- the 8x8
class with 32 positions and the TX_4X4 tx_type row), depth 2 the square
TX_4X4 through the ordinary `read_plane`; each unit predicts off the units
before it and reads its own `txb_skip` context, and the block's lf grid now
carries the UNIT's transform size.

Gate: the same gate grew the `--enable-tx-size-search=1` half of its attempt
window (the 32-level 1:4 gate's own shape). 8-bit: 15 compared attempts, 192
16x4 + 288 4x16 strips, 240 chroma pairs, 102 split-transform strips; 10-bit:
16 attempts, 148 + 280 strips, 214 pairs, 82 split strips. Every decode
pixel-compared against ffmpeg, zero refusals. CfL stays `=0` on the recipe:
no CfL hit counter exists, so `=1` would retire `enable-cfl-intra` from
gate_coverage::NEVER_EXERCISED_* on a flag alone.

Film check: the 4K 10-bit AV1 key frame at t=300s now walks past the 1:4 wall
(104 16x4 + 172 4x16 strips at the 32 level alone) and stops at another
lane's refusal, "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs
rectangular residual coding".
crates/ec-av1/src/decode.rsmodified+113 -8
@@ -1960,16 +1960,19 @@ thread_local! {
19601960 static RECT4_16_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
19611961 static RECT4_16_CHROMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
19621962 static RECT4_16_COEFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1963+ static RECT4_16_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
19631964 }
19641965
19651966 /// Current values of the 16x16-level 1:4 counters: `(16x4 strips, 4x16
1966-/// strips, chroma-reference strips, strips with a coded residual)`.
1967-pub fn rect4_16_counters() -> (usize, usize, usize, usize) {
1967+/// strips, chroma-reference strips, strips with a coded residual, strips
1968+/// whose luma transform is split)`.
1969+pub fn rect4_16_counters() -> (usize, usize, usize, usize, usize) {
19681970 (
19691971 RECT4_16_HORZ_HITS.with(|c| c.get()),
19701972 RECT4_16_VERT_HITS.with(|c| c.get()),
19711973 RECT4_16_CHROMA_HITS.with(|c| c.get()),
19721974 RECT4_16_COEFF_HITS.with(|c| c.get()),
1975+ RECT4_16_SPLIT_HITS.with(|c| c.get()),
19731976 )
19741977 }
19751978
@@ -6828,7 +6831,6 @@ fn decode_rect4_16(
68286831 tx_select: bool,
68296832 reduced_tx_set: bool,
68306833 ) -> Result<()> {
6831- let _ = base_q_idx;
68326834 let (r, c) = at16;
68336835 let (mi_row0, mi_col0) = (r * (SUB / MI), c * (SUB / MI));
68346836 let (bw, bh) = if horz { (16, 4) } else { (4, 16) };
@@ -6910,12 +6912,115 @@ fn decode_rect4_16(
69106912 };
69116913 if depth != 0 {
69126914 TX_DEPTH_HITS.with(|h| h.set(h.get() + 1));
6913- return Err(unsupported(
6914- "a 16x4/4x16 strip whose transform is split (sub_tx_size_map[TX_16X4] == TX_8X4; the per-unit walk is not ported at this shape)",
6915- ));
6915+ RECT4_16_SPLIT_HITS.with(|h| h.set(h.get() + 1));
69166916 }
6917+ let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth);
69176918 let (px, py) = (lmi.1 * MI, lmi.0 * MI);
69186919 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height);
6920+ neighbours.record_mode_mi(lmi.0, lmi.1, mi_w, mi_h, mode);
6921+ if depth != 0 {
6922+ // [`decode_rect_split`]'s per-unit walk, inlined because the
6923+ // CHROMA of this shape belongs to the strip's 4:2:0 pair, not to
6924+ // the strip (that function codes one chroma transform per block).
6925+ // depth 1 is the 2:1 rect unit TX_8X4/TX_4X8
6926+ // (`sub_tx_size_map[TX_16X4]`), depth 2 the square TX_4X4; each
6927+ // unit predicts off the units before it in raster order.
6928+ let rect_unit = tx_w != tx_h;
6929+ let zero_tu = vec![0i32; tx_w * tx_h];
6930+ for tu_row in 0..bh / tx_h {
6931+ for tu_col in 0..bw / tx_w {
6932+ let tu_mi = (lmi.0 + tu_row * (tx_h / MI), lmi.1 + tu_col * (tx_w / MI));
6933+ let (tu_px, tu_py) = (px + tu_col * tx_w, py + tu_row * tx_h);
6934+ let tu_reach = Reach::of_tu(
6935+ bw,
6936+ bh,
6937+ tu_col * tx_w,
6938+ tu_row * tx_h,
6939+ tx_w,
6940+ tx_h,
6941+ reach,
6942+ );
6943+ if skip {
6944+ y.reconstruct_rect(
6945+ tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &zero_tu,
6946+ None, filter_intra, smooth_neighbor,
6947+ );
6948+ neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &zero_tu);
6949+ } else if rect_unit {
6950+ // `get_txsize_entropy_ctx(TX_8X4)` is the 8x8 class with
6951+ // 32 coded positions and the `TX_4X4` `tx_type` row:
6952+ // exactly [`TxbSet::LumaRect4x8`].
6953+ let tu_around = neighbours.around_mi_rect(tu_mi, tx_w, tx_h)[0];
6954+ let tu_skip_ctx =
6955+ neighbours.luma_skip_ctx_rect(tu_mi, tx_w / MI, tx_h / MI);
6956+ let set = if reduced_tx_set {
6957+ TxbSet::LumaRect4x8
6958+ } else {
6959+ TxbSet::LumaRect4x8Set1
6960+ };
6961+ let tu_scan: &[u16] = if tx_w > tx_h { &SCAN_8X4 } else { &SCAN_4X8 };
6962+ let mut coding = cdfs.txb(set, fi_tx_row(mode, filter_intra));
6963+ let (tu_grid, tu_tx_type) = read_coeffs_rect(
6964+ dec,
6965+ &mut coding,
6966+ tu_scan,
6967+ tx_w,
6968+ tx_h,
6969+ tu_skip_ctx,
6970+ dc_sign_ctx(tu_around.2),
6971+ TxType::DctDct,
6972+ )?;
6973+ let residual = dequant_and_inverse_typed_wh(
6974+ &tu_grid,
6975+ tx_w,
6976+ tx_h,
6977+ crate::decode::bit_depth(),
6978+ block_q_idx(),
6979+ plane_q_delta(0).0,
6980+ plane_q_delta(0).1,
6981+ tu_tx_type,
6982+ );
6983+ y.reconstruct_rect(
6984+ tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &residual,
6985+ None, filter_intra, smooth_neighbor,
6986+ );
6987+ if tu_grid.iter().any(|&l| l != 0) {
6988+ RECT4_16_COEFF_HITS.with(|h| h.set(h.get() + 1));
6989+ }
6990+ neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &tu_grid);
6991+ } else {
6992+ let tu_around = neighbours.around_mi(tu_mi, tx_w)[0];
6993+ let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_w / MI);
6994+ let tu_grid = read_plane(
6995+ dec,
6996+ cdfs,
6997+ txbset_for(tx_w, reduced_tx_set),
6998+ &default_scan(tx_w),
6999+ 0,
7000+ tu_around,
7001+ mode,
7002+ mode,
7003+ angle_delta_y,
7004+ tu_reach,
7005+ y,
7006+ tu_px,
7007+ tu_py,
7008+ tx_w,
7009+ tx_w,
7010+ base_q_idx,
7011+ None,
7012+ filter_intra,
7013+ Some(tu_skip_ctx),
7014+ smooth_neighbor,
7015+ )?;
7016+ if tu_grid.iter().any(|&l| l != 0) {
7017+ RECT4_16_COEFF_HITS.with(|h| h.set(h.get() + 1));
7018+ }
7019+ neighbours.record_mi_luma(tu_mi, tx_w, &tu_grid);
7020+ }
7021+ }
7022+ }
7023+ } else {
69197024 let levels = if skip {
69207025 let zeros = vec![0i32; bw * bh];
69217026 y.reconstruct_rect(
@@ -6961,10 +7066,10 @@ fn decode_rect4_16(
69617066 RECT4_16_COEFF_HITS.with(|h| h.set(h.get() + 1));
69627067 levels
69637068 };
6964- neighbours.record_mode_mi(lmi.0, lmi.1, mi_w, mi_h, mode);
69657069 neighbours.record_mi_luma_rect(lmi, bw, bh, &levels);
7070+ }
69667071 neighbours.fill_skip_grid_rect(lmi, mi_w, mi_h, skip);
6967- neighbours.fill_lf_grid_rect(lmi, mi_w, mi_h, bw as u8, bh as u8, 0);
7072+ neighbours.fill_lf_grid_rect(lmi, mi_w, mi_h, tx_w as u8, tx_h as u8, 0);
69687073 // `update_partition_context` writes `partition_context_lookup[
69697074 // BLOCK_16X4]` over the whole 16x16: full width above, a 4-px side on
69707075 // the left (mirrored under VERT_4).
crates/ec-av1/src/refusal_inventory.rsmodified+0 -1
@@ -35,7 +35,6 @@ const REFUSALS: &[&str] = &[
3535 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",
3636 "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)",
3737 "a 16x16-level partition value outside PARTITION_NONE..PARTITION_VERT_4",
38- "a 16x4/4x16 strip whose transform is split (sub_tx_size_map[TX_16X4] == TX_8X4; the per-unit walk is not ported at this shape)",
3938 "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)",
4039 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
4140 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
crates/ec-av1/src/stream.rsmodified+33 -9
@@ -18188,10 +18188,10 @@ mod tests {
1818818188 /// transposed scan or nz-map table cannot pass (class
1818918189 /// scan-weights-cross-axis), plus an explicit-seed noise layer that keeps
1819018190 /// aomenc out of screen-content mode. `--enable-filter-intra=1` and
18191- /// `--enable-cfl-intra=1` are ON: this shape reads `use_filter_intra` off
18192- /// its own CDF rows (classes 12/13) and its CfL averages the whole 16x8
18193- /// (8x16) luma PAIR, not the strip. `--enable-tx-size-search=0`: a split
18194- /// transform at this shape is still refused by name.
18191+ /// is ON: this shape reads `use_filter_intra` off its own CDF rows
18192+ /// (classes 12/13). The `--enable-tx-size-search=1` half of the window
18193+ /// splits the strip's transform (depth 1 = TX_8X4/TX_4X8, depth 2 =
18194+ /// TX_4X4).
1819518195 ///
1819618196 /// Counters: 16x4 strips, 4x16 strips, chroma-reference strips (the odd
1819718197 /// strip of each 4:2:0 pair, the only one that codes chroma) and strips
@@ -18221,8 +18221,14 @@ mod tests {
1822118221 let mut matched = 0u32;
1822218222 let (mut horz_proved, mut vert_proved) = (0usize, 0usize);
1822318223 let (mut chroma_proved, mut coeff_proved) = (0usize, 0usize);
18224+ let mut split_proved = 0usize;
1822418225 let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32);
18225- for attempt in 0..n_attempts {
18226+ // The second half of the window turns `--enable-tx-size-search` on:
18227+ // that is what makes a 16x4 strip SPLIT its transform (depth 1 =
18228+ // TX_8X4, depth 2 = TX_4X4), the arm the first half never reaches.
18229+ for attempt in 0..n_attempts * 2 {
18230+ let tx_search = attempt >= n_attempts;
18231+ let attempt = attempt % n_attempts;
1822618232 let seed = 42 + attempt;
1822718233 let duration = frame_count as f64 / 25.0;
1822818234 let axis = if attempt % 2 == 0 { "Y" } else { "X" };
@@ -18272,9 +18278,19 @@ mod tests {
1827218278 "--enable-palette=0",
1827318279 "--deltaq-mode=0",
1827418280 "--enable-filter-intra=1",
18275- "--enable-cfl-intra=1",
18281+ // lane-r14: CfL stays OFF here. This shape's CfL averages
18282+ // the luma of the whole PAIR and is written, but no gate
18283+ // asserts a CfL hit counter (there is none), and passing
18284+ // `=1` would retire `enable-cfl-intra` from
18285+ // `gate_coverage::NEVER_EXERCISED_*` on a flag alone --
18286+ // exactly the false coverage that list exists to prevent.
18287+ "--enable-cfl-intra=0",
1827618288 "--enable-intrabc=0",
18277- "--enable-tx-size-search=0",
18289+ if tx_search {
18290+ "--enable-tx-size-search=1"
18291+ } else {
18292+ "--enable-tx-size-search=0"
18293+ },
1827818294 "--obu",
1827918295 "-o",
1828018296 "-",
@@ -18316,11 +18332,12 @@ mod tests {
1831618332 Ok(frames) => frames,
1831718333 };
1831818334 let now = crate::decode::rect4_16_counters();
18319- let (horz, vert, chroma, coeff) = (
18335+ let (horz, vert, chroma, coeff, split) = (
1832018336 now.0 - before.0,
1832118337 now.1 - before.1,
1832218338 now.2 - before.2,
1832318339 now.3 - before.3,
18340+ now.4 - before.4,
1832418341 );
1832518342 let ffmpeg_frames = if bit_depth == 10 {
1832618343 ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
@@ -18368,6 +18385,7 @@ mod tests {
1836818385 vert_proved += vert;
1836918386 chroma_proved += chroma;
1837018387 coeff_proved += coeff;
18388+ split_proved += split;
1837118389 matched += 1;
1837218390 }
1837318391 assert!(
@@ -18394,10 +18412,16 @@ mod tests {
1839418412 coeff_proved > 0,
1839518413 "{NAME}: {bit_depth}-bit compared attempts coded no residual on any strip"
1839618414 );
18415+ assert!(
18416+ split_proved > 0,
18417+ "{NAME}: {bit_depth}-bit compared attempts never split a strip's transform -- \
18418+ the `--enable-tx-size-search=1` half of the window proved nothing"
18419+ );
1839718420 eprintln!(
1839818421 "{NAME}: {bit_depth}-bit {matched} compared attempts, {horz_proved} 16x4 / \
1839918422 {vert_proved} 4x16 strips, {chroma_proved} chroma pairs, {coeff_proved} coded \
18400- strips, {named_refusals} refusals, {out_of_scope} out of scope"
18423+ units, {split_proved} split-transform strips, {named_refusals} refusals, \
18424+ {out_of_scope} out of scope"
1840118425 );
1840218426 }
1840318427 }