Split transform (TX_8X4/TX_4X8, TX_4X4) on a 16-level 1:4 strip
Browse files at this commite1a08a19d7dd4a259a361f259fbab77a268f6236Parent: b1f19e6- feat
- split transform (TX_8X4/TX_4X8, TX_4X4) on a 16-level 1:4 strip
3 changed files +146 -18
- crates/ec-av1/src/decode.rs +113 -8
- crates/ec-av1/src/refusal_inventory.rs +0 -1
- crates/ec-av1/src/stream.rs +33 -9
crates/ec-av1/src/decode.rsmodified+113 -8
| @@ -1960,16 +1960,19 @@ thread_local! { | |||
| 1960 | static RECT4_16_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 1960 | static RECT4_16_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 1961 | static RECT4_16_CHROMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 1961 | static RECT4_16_CHROMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 1962 | static RECT4_16_COEFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 1962 | 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) }; | ||
| 1963 | } | 1964 | } |
| 1964 | 1965 | ||
| 1965 | /// Current values of the 16x16-level 1:4 counters: `(16x4 strips, 4x16 | 1966 | /// Current values of the 16x16-level 1:4 counters: `(16x4 strips, 4x16 |
| 1966 | -/// strips, chroma-reference strips, strips with a coded residual)`. | 1967 | +/// strips, chroma-reference strips, strips with a coded residual, strips |
| 1967 | -pub fn rect4_16_counters() -> (usize, usize, usize, usize) { | 1968 | +/// whose luma transform is split)`. |
| 1969 | +pub fn rect4_16_counters() -> (usize, usize, usize, usize, usize) { | ||
| 1968 | ( | 1970 | ( |
| 1969 | RECT4_16_HORZ_HITS.with(|c| c.get()), | 1971 | RECT4_16_HORZ_HITS.with(|c| c.get()), |
| 1970 | RECT4_16_VERT_HITS.with(|c| c.get()), | 1972 | RECT4_16_VERT_HITS.with(|c| c.get()), |
| 1971 | RECT4_16_CHROMA_HITS.with(|c| c.get()), | 1973 | RECT4_16_CHROMA_HITS.with(|c| c.get()), |
| 1972 | RECT4_16_COEFF_HITS.with(|c| c.get()), | 1974 | RECT4_16_COEFF_HITS.with(|c| c.get()), |
| 1975 | + RECT4_16_SPLIT_HITS.with(|c| c.get()), | ||
| 1973 | ) | 1976 | ) |
| 1974 | } | 1977 | } |
| 1975 | 1978 | ||
| @@ -6828,7 +6831,6 @@ fn decode_rect4_16( | |||
| 6828 | tx_select: bool, | 6831 | tx_select: bool, |
| 6829 | reduced_tx_set: bool, | 6832 | reduced_tx_set: bool, |
| 6830 | ) -> Result<()> { | 6833 | ) -> Result<()> { |
| 6831 | - let _ = base_q_idx; | ||
| 6832 | let (r, c) = at16; | 6834 | let (r, c) = at16; |
| 6833 | let (mi_row0, mi_col0) = (r * (SUB / MI), c * (SUB / MI)); | 6835 | let (mi_row0, mi_col0) = (r * (SUB / MI), c * (SUB / MI)); |
| 6834 | let (bw, bh) = if horz { (16, 4) } else { (4, 16) }; | 6836 | let (bw, bh) = if horz { (16, 4) } else { (4, 16) }; |
| @@ -6910,12 +6912,115 @@ fn decode_rect4_16( | |||
| 6910 | }; | 6912 | }; |
| 6911 | if depth != 0 { | 6913 | if depth != 0 { |
| 6912 | TX_DEPTH_HITS.with(|h| h.set(h.get() + 1)); | 6914 | TX_DEPTH_HITS.with(|h| h.set(h.get() + 1)); |
| 6913 | - return Err(unsupported( | 6915 | + RECT4_16_SPLIT_HITS.with(|h| h.set(h.get() + 1)); |
| 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 | - )); | ||
| 6916 | } | 6916 | } |
| 6917 | + let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth); | ||
| 6917 | let (px, py) = (lmi.1 * MI, lmi.0 * MI); | 6918 | let (px, py) = (lmi.1 * MI, lmi.0 * MI); |
| 6918 | let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); | 6919 | 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 { | ||
| 6919 | let levels = if skip { | 7024 | let levels = if skip { |
| 6920 | let zeros = vec![0i32; bw * bh]; | 7025 | let zeros = vec![0i32; bw * bh]; |
| 6921 | y.reconstruct_rect( | 7026 | y.reconstruct_rect( |
| @@ -6961,10 +7066,10 @@ fn decode_rect4_16( | |||
| 6961 | RECT4_16_COEFF_HITS.with(|h| h.set(h.get() + 1)); | 7066 | RECT4_16_COEFF_HITS.with(|h| h.set(h.get() + 1)); |
| 6962 | levels | 7067 | levels |
| 6963 | }; | 7068 | }; |
| 6964 | - neighbours.record_mode_mi(lmi.0, lmi.1, mi_w, mi_h, mode); | ||
| 6965 | neighbours.record_mi_luma_rect(lmi, bw, bh, &levels); | 7069 | neighbours.record_mi_luma_rect(lmi, bw, bh, &levels); |
| 7070 | + } | ||
| 6966 | neighbours.fill_skip_grid_rect(lmi, mi_w, mi_h, skip); | 7071 | 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); |
| 6968 | // `update_partition_context` writes `partition_context_lookup[ | 7073 | // `update_partition_context` writes `partition_context_lookup[ |
| 6969 | // BLOCK_16X4]` over the whole 16x16: full width above, a 4-px side on | 7074 | // BLOCK_16X4]` over the whole 16x16: full width above, a 4-px side on |
| 6970 | // the left (mirrored under VERT_4). | 7075 | // the left (mirrored under VERT_4). |
crates/ec-av1/src/refusal_inventory.rsmodified+0 -1
| @@ -35,7 +35,6 @@ const REFUSALS: &[&str] = &[ | |||
| 35 | "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", | 35 | "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", |
| 36 | "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", | 36 | "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", |
| 37 | "a 16x16-level partition value outside PARTITION_NONE..PARTITION_VERT_4", | 37 | "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)", | ||
| 39 | "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", | 38 | "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", |
| 40 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 39 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 41 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 40 | "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 { | |||
| 18188 | /// transposed scan or nz-map table cannot pass (class | 18188 | /// transposed scan or nz-map table cannot pass (class |
| 18189 | /// scan-weights-cross-axis), plus an explicit-seed noise layer that keeps | 18189 | /// scan-weights-cross-axis), plus an explicit-seed noise layer that keeps |
| 18190 | /// aomenc out of screen-content mode. `--enable-filter-intra=1` and | 18190 | /// 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 | 18191 | + /// is ON: this shape reads `use_filter_intra` off its own CDF rows |
| 18192 | - /// its own CDF rows (classes 12/13) and its CfL averages the whole 16x8 | 18192 | + /// (classes 12/13). The `--enable-tx-size-search=1` half of the window |
| 18193 | - /// (8x16) luma PAIR, not the strip. `--enable-tx-size-search=0`: a split | 18193 | + /// splits the strip's transform (depth 1 = TX_8X4/TX_4X8, depth 2 = |
| 18194 | - /// transform at this shape is still refused by name. | 18194 | + /// TX_4X4). |
| 18195 | /// | 18195 | /// |
| 18196 | /// Counters: 16x4 strips, 4x16 strips, chroma-reference strips (the odd | 18196 | /// Counters: 16x4 strips, 4x16 strips, chroma-reference strips (the odd |
| 18197 | /// strip of each 4:2:0 pair, the only one that codes chroma) and strips | 18197 | /// strip of each 4:2:0 pair, the only one that codes chroma) and strips |
| @@ -18221,8 +18221,14 @@ mod tests { | |||
| 18221 | let mut matched = 0u32; | 18221 | let mut matched = 0u32; |
| 18222 | let (mut horz_proved, mut vert_proved) = (0usize, 0usize); | 18222 | let (mut horz_proved, mut vert_proved) = (0usize, 0usize); |
| 18223 | let (mut chroma_proved, mut coeff_proved) = (0usize, 0usize); | 18223 | let (mut chroma_proved, mut coeff_proved) = (0usize, 0usize); |
| 18224 | + let mut split_proved = 0usize; | ||
| 18224 | let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32); | 18225 | 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; | ||
| 18226 | let seed = 42 + attempt; | 18232 | let seed = 42 + attempt; |
| 18227 | let duration = frame_count as f64 / 25.0; | 18233 | let duration = frame_count as f64 / 25.0; |
| 18228 | let axis = if attempt % 2 == 0 { "Y" } else { "X" }; | 18234 | let axis = if attempt % 2 == 0 { "Y" } else { "X" }; |
| @@ -18272,9 +18278,19 @@ mod tests { | |||
| 18272 | "--enable-palette=0", | 18278 | "--enable-palette=0", |
| 18273 | "--deltaq-mode=0", | 18279 | "--deltaq-mode=0", |
| 18274 | "--enable-filter-intra=1", | 18280 | "--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", | ||
| 18276 | "--enable-intrabc=0", | 18288 | "--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 | + }, | ||
| 18278 | "--obu", | 18294 | "--obu", |
| 18279 | "-o", | 18295 | "-o", |
| 18280 | "-", | 18296 | "-", |
| @@ -18316,11 +18332,12 @@ mod tests { | |||
| 18316 | Ok(frames) => frames, | 18332 | Ok(frames) => frames, |
| 18317 | }; | 18333 | }; |
| 18318 | let now = crate::decode::rect4_16_counters(); | 18334 | let now = crate::decode::rect4_16_counters(); |
| 18319 | - let (horz, vert, chroma, coeff) = ( | 18335 | + let (horz, vert, chroma, coeff, split) = ( |
| 18320 | now.0 - before.0, | 18336 | now.0 - before.0, |
| 18321 | now.1 - before.1, | 18337 | now.1 - before.1, |
| 18322 | now.2 - before.2, | 18338 | now.2 - before.2, |
| 18323 | now.3 - before.3, | 18339 | now.3 - before.3, |
| 18340 | + now.4 - before.4, | ||
| 18324 | ); | 18341 | ); |
| 18325 | let ffmpeg_frames = if bit_depth == 10 { | 18342 | let ffmpeg_frames = if bit_depth == 10 { |
| 18326 | ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | 18343 | ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) |
| @@ -18368,6 +18385,7 @@ mod tests { | |||
| 18368 | vert_proved += vert; | 18385 | vert_proved += vert; |
| 18369 | chroma_proved += chroma; | 18386 | chroma_proved += chroma; |
| 18370 | coeff_proved += coeff; | 18387 | coeff_proved += coeff; |
| 18388 | + split_proved += split; | ||
| 18371 | matched += 1; | 18389 | matched += 1; |
| 18372 | } | 18390 | } |
| 18373 | assert!( | 18391 | assert!( |
| @@ -18394,10 +18412,16 @@ mod tests { | |||
| 18394 | coeff_proved > 0, | 18412 | coeff_proved > 0, |
| 18395 | "{NAME}: {bit_depth}-bit compared attempts coded no residual on any strip" | 18413 | "{NAME}: {bit_depth}-bit compared attempts coded no residual on any strip" |
| 18396 | ); | 18414 | ); |
| 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 | + ); | ||
| 18397 | eprintln!( | 18420 | eprintln!( |
| 18398 | "{NAME}: {bit_depth}-bit {matched} compared attempts, {horz_proved} 16x4 / \ | 18421 | "{NAME}: {bit_depth}-bit {matched} compared attempts, {horz_proved} 16x4 / \ |
| 18399 | {vert_proved} 4x16 strips, {chroma_proved} chroma pairs, {coeff_proved} coded \ | 18422 | {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" | ||
| 18401 | ); | 18425 | ); |
| 18402 | } | 18426 | } |
| 18403 | } | 18427 | } |