An intrabc block reads the INTER tx-size syntax under TX_MODE_SELECT
Browse files at this commit0674134d28d21c4cb8bc5901aa78992d440c7205Parent: 63370ce- feat
- an intrabc block reads the INTER tx-size syntax under TX_MODE_SELECT
1 changed file +147 -27
- crates/ec-av1/src/decode.rs +147 -27
crates/ec-av1/src/decode.rsmodified+147 -27
| @@ -2005,6 +2005,23 @@ pub(crate) fn reset_intrabc_hits() { | |||
| 2005 | INTRABC_HITS.with(|c| c.set(0)); | 2005 | INTRABC_HITS.with(|c| c.set(0)); |
| 2006 | } | 2006 | } |
| 2007 | 2007 | ||
| 2008 | +thread_local! { | ||
| 2009 | + /// lane-t900 r32: intrabc blocks whose transform size came off the INTER | ||
| 2010 | + /// var-tx partition tree (unskipped, `TX_MODE_SELECT`) -- the capability | ||
| 2011 | + /// that replaced the refusal "an intrabc block under TxMode::Select". | ||
| 2012 | + static INTRABC_VARTX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2013 | +} | ||
| 2014 | + | ||
| 2015 | +/// Current value of [`INTRABC_VARTX_HITS`]. | ||
| 2016 | +pub(crate) fn intrabc_vartx_hits() -> usize { | ||
| 2017 | + INTRABC_VARTX_HITS.with(|c| c.get()) | ||
| 2018 | +} | ||
| 2019 | + | ||
| 2020 | +/// Zeroes [`INTRABC_VARTX_HITS`] (gate tests call this before a decode). | ||
| 2021 | +pub(crate) fn reset_intrabc_vartx_hits() { | ||
| 2022 | + INTRABC_VARTX_HITS.with(|c| c.set(0)); | ||
| 2023 | +} | ||
| 2024 | + | ||
| 2008 | /// Records one coded block into [`INTRABC_MI_GRID`]: every block contributes | 2025 | /// Records one coded block into [`INTRABC_MI_GRID`]: every block contributes |
| 2009 | /// its size (libaom's `scan_row_mbmi` advances `processed_rows` off any | 2026 | /// its size (libaom's `scan_row_mbmi` advances `processed_rows` off any |
| 2010 | /// candidate's `bsize`, ref-match or not), an intrabc one also its DV as an | 2027 | /// candidate's `bsize`, ref-match or not), an intrabc one also its DV as an |
| @@ -11920,15 +11937,6 @@ fn decode_block( | |||
| 11920 | PALETTE_TILE_LEFT_HITS.with(|c| c.set(c.get() + 1)); | 11937 | PALETTE_TILE_LEFT_HITS.with(|c| c.set(c.get() + 1)); |
| 11921 | } | 11938 | } |
| 11922 | let intrabc_dv = fctx.intrabc_dv.with(|c| c.take()); | 11939 | let intrabc_dv = fctx.intrabc_dv.with(|c| c.take()); |
| 11923 | - // libaom `parse_decode_block`: an intrabc block is `inter_block_tx`, so | ||
| 11924 | - // under `TX_MODE_SELECT` its transform size comes from the inter var-tx | ||
| 11925 | - // partition tree (`read_var_tx_size`), a syntax element this decoder has | ||
| 11926 | - // nowhere -- reading the intra `tx_depth` symbol instead would desync. | ||
| 11927 | - if intrabc_dv.is_some() && tx_select && !skip { | ||
| 11928 | - return Err(unsupported( | ||
| 11929 | - "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)", | ||
| 11930 | - )); | ||
| 11931 | - } | ||
| 11932 | // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED` | 11940 | // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED` |
| 11933 | // (13) predicts as `DC_PRED` with the [`cfl_scaled`] nudge carrying the | 11941 | // (13) predicts as `DC_PRED` with the [`cfl_scaled`] nudge carrying the |
| 11934 | // actual chroma-from-luma correlation, same as this decoder always did. | 11942 | // actual chroma-from-luma correlation, same as this decoder always did. |
| @@ -11956,7 +11964,59 @@ fn decode_block( | |||
| 11956 | // transform size -- 64 even for the 64x64 corner-scanned case, spec | 11964 | // transform size -- 64 even for the 64x64 corner-scanned case, spec |
| 11957 | // 5.11.40); `coeff_tx_side` is the actual coded coefficient grid's side, | 11965 | // 5.11.40); `coeff_tx_side` is the actual coded coefficient grid's side, |
| 11958 | // which only differs from it at that one corner case. | 11966 | // which only differs from it at that one corner case. |
| 11959 | - let (logical_tx, coeff_tx_side) = if tx_select { | 11967 | + // lane-t900 r32: spec 5.11.16 `read_block_tx_size` gates the `tx_depth` |
| 11968 | + // symbol on `allowSelect = !skip || !is_inter`, and libaom's | ||
| 11969 | + // `is_inter_block` counts an INTRABC block (`blockd.h:373`). So a SKIPPED | ||
| 11970 | + // intrabc block reads NO tx-size symbol at all -- it takes | ||
| 11971 | + // `maxRectTxSize` -- while every ordinary skipped intra block does read | ||
| 11972 | + // one. Reading it anyway consumed a symbol libaom never wrote and desynced | ||
| 11973 | + // the tile from that block on (class `equal-range-means-unread`). | ||
| 11974 | + // lane-t900 r32: and an UNSKIPPED one reads the inter var-tx partition | ||
| 11975 | + // tree instead (`read_var_tx_size`), the same syntax the inter block path | ||
| 11976 | + // has always read -- libaom's `parse_decode_block` dispatches on | ||
| 11977 | + // `is_inter_block`, so both branches of `read_block_tx_size` treat an | ||
| 11978 | + // intrabc block as inter. | ||
| 11979 | + let intrabc_skip_tx = intrabc_dv.is_some() && skip; | ||
| 11980 | + let intrabc_vartx = intrabc_dv.is_some() && tx_select && !skip; | ||
| 11981 | + let intrabc_leaves = if intrabc_vartx { | ||
| 11982 | + let max_tx = side.min(64); | ||
| 11983 | + // `max_block_wide`/`max_block_high`: the frame's own mi grid | ||
| 11984 | + // (`av1_calc_mi_size`, 8-px aligned), so a block hanging over the | ||
| 11985 | + // right/bottom edge reads no split symbol for the units outside it. | ||
| 11986 | + let mi_cols = 2 * y.true_width.div_ceil(8); | ||
| 11987 | + let mi_rows = 2 * y.true_height.div_ceil(8); | ||
| 11988 | + let side_mi = side / MI; | ||
| 11989 | + let max_w_mi = side_mi.min(mi_cols.saturating_sub(mi_c)); | ||
| 11990 | + let max_h_mi = side_mi.min(mi_rows.saturating_sub(mi_r)); | ||
| 11991 | + let mut leaves = Vec::new(); | ||
| 11992 | + for row in (0..side_mi).step_by(max_tx / MI) { | ||
| 11993 | + for col in (0..side_mi).step_by(max_tx / MI) { | ||
| 11994 | + read_var_tx_size( | ||
| 11995 | + dec, cdfs, neighbours, (mi_r, mi_c), side, | ||
| 11996 | + (max_w_mi, max_h_mi), (max_tx, max_tx), 0, row, col, &mut leaves, | ||
| 11997 | + ); | ||
| 11998 | + } | ||
| 11999 | + } | ||
| 12000 | + INTRABC_VARTX_HITS.with(|c| c.set(c.get() + 1)); | ||
| 12001 | + // The luma reconstruct loop below is a UNIFORM grid of one square | ||
| 12002 | + // transform (the intra `tx_depth` shape), so a tree that resolved to | ||
| 12003 | + // mixed leaf sizes is refused by name rather than reconstructed at the | ||
| 12004 | + // wrong stride. | ||
| 12005 | + let uniform = leaves | ||
| 12006 | + .first() | ||
| 12007 | + .is_some_and(|f| leaves.iter().all(|l| (l.2, l.3) == (f.2, f.3) && l.2 == l.3)); | ||
| 12008 | + if !uniform { | ||
| 12009 | + return Err(unsupported( | ||
| 12010 | + "an intrabc block whose var-tx tree resolved to mixed leaf transform sizes", | ||
| 12011 | + )); | ||
| 12012 | + } | ||
| 12013 | + Some(leaves[0].2) | ||
| 12014 | + } else { | ||
| 12015 | + None | ||
| 12016 | + }; | ||
| 12017 | + let (logical_tx, coeff_tx_side) = if let Some(tx) = intrabc_leaves { | ||
| 12018 | + (tx, if tx == 64 { 32 } else { tx }) | ||
| 12019 | + } else if tx_select && !intrabc_skip_tx { | ||
| 11960 | let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, None); | 12020 | let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, None); |
| 11961 | (resolved, if resolved == 64 { 32 } else { resolved }) | 12021 | (resolved, if resolved == 64 { 32 } else { resolved }) |
| 11962 | } else { | 12022 | } else { |
| @@ -12010,9 +12070,6 @@ fn decode_block( | |||
| 12010 | ); | 12070 | ); |
| 12011 | (yb, ub, vb) | 12071 | (yb, ub, vb) |
| 12012 | }); | 12072 | }); |
| 12013 | - if let Some((yb, _, _)) = &intrabc_bufs { | ||
| 12014 | - set_palette_pred(yb.clone(), fctx); | ||
| 12015 | - } | ||
| 12016 | // A palette-Y block's own prediction is the reconstructed colour-index | 12073 | // A palette-Y block's own prediction is the reconstructed colour-index |
| 12017 | // map, not `predict()`'s edge-based one -- [`PALETTE_PRED`] carries it | 12074 | // map, not `predict()`'s edge-based one -- [`PALETTE_PRED`] carries it |
| 12018 | // to [`PlaneBuf::reconstruct`]'s next call rather than threading a | 12075 | // to [`PlaneBuf::reconstruct`]'s next call rather than threading a |
| @@ -12027,6 +12084,16 @@ fn decode_block( | |||
| 12027 | .map(|&idx| py.colors[idx as usize]) | 12084 | .map(|&idx| py.colors[idx as usize]) |
| 12028 | .collect() | 12085 | .collect() |
| 12029 | }); | 12086 | }); |
| 12087 | + // lane-t900 r32: the intrabc luma prediction rides the very same | ||
| 12088 | + // whole-block override slot, so the multi-TU loop below windows it per | ||
| 12089 | + // transform unit exactly like a palette map -- setting it once up front | ||
| 12090 | + // handed the whole `side`x`side` buffer to the FIRST unit and left every | ||
| 12091 | + // later one predicting off block edges (the var-tx tree above is what | ||
| 12092 | + // first makes `logical_tx < side` reachable for an intrabc block). | ||
| 12093 | + let palette_y_buf = match &intrabc_bufs { | ||
| 12094 | + Some((yb, _, _)) => Some(yb.clone()), | ||
| 12095 | + None => palette_y_buf, | ||
| 12096 | + }; | ||
| 12030 | // With one luma transform unit the whole `side`x`side` map is the | 12097 | // With one luma transform unit the whole `side`x`side` map is the |
| 12031 | // prediction; with several (`logical_tx != side`) each unit takes its own | 12098 | // prediction; with several (`logical_tx != side`) each unit takes its own |
| 12032 | // `logical_tx`-sized window of that same map, set fresh inside the TU loop | 12099 | // `logical_tx`-sized window of that same map, set fresh inside the TU loop |
| @@ -12483,6 +12550,22 @@ fn decode_block( | |||
| 12483 | logical_tx as u8, | 12550 | logical_tx as u8, |
| 12484 | 0, fctx, | 12551 | 0, fctx, |
| 12485 | ); | 12552 | ); |
| 12553 | + // lane-t900 r32: libaom runs `set_txfm_ctxs` at the end of EVERY | ||
| 12554 | + // `decode_block`, key frames included, and the intrabc var-tx read above | ||
| 12555 | + // (`txfm_partition_ctx`) is the only intra-path reader of those bands -- | ||
| 12556 | + // left at `TXFM_CTX_INIT` it would take the split symbol off the wrong CDF | ||
| 12557 | + // row. Armed by the frame's own `allow_intrabc` so every other key frame | ||
| 12558 | + // (whose readers use the deblock-grid approximation) is untouched. | ||
| 12559 | + if allow_intrabc { | ||
| 12560 | + set_txfm_ctxs( | ||
| 12561 | + neighbours, | ||
| 12562 | + (mi_r, mi_c), | ||
| 12563 | + logical_tx, | ||
| 12564 | + side / MI, | ||
| 12565 | + side / MI, | ||
| 12566 | + skip && intrabc_dv.is_some(), | ||
| 12567 | + ); | ||
| 12568 | + } | ||
| 12486 | record_intrabc_mi(mi_r, mi_c, side / MI, intrabc_dv, fctx); | 12569 | record_intrabc_mi(mi_r, mi_c, side / MI, intrabc_dv, fctx); |
| 12487 | Ok(()) | 12570 | Ok(()) |
| 12488 | } | 12571 | } |
| @@ -12965,11 +13048,6 @@ fn decode_leaf8( | |||
| 12965 | if intrabc_dv.is_some() { | 13048 | if intrabc_dv.is_some() { |
| 12966 | LEAF8_INTRABC_HITS.with(|c| c.set(c.get() + 1)); | 13049 | LEAF8_INTRABC_HITS.with(|c| c.set(c.get() + 1)); |
| 12967 | } | 13050 | } |
| 12968 | - if intrabc_dv.is_some() && tx_select && !skip { | ||
| 12969 | - return Err(unsupported( | ||
| 12970 | - "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)", | ||
| 12971 | - )); | ||
| 12972 | - } | ||
| 12973 | // `av1_visit_palette`'s reconstruction (decodeframe.c:1135): the colour | 13051 | // `av1_visit_palette`'s reconstruction (decodeframe.c:1135): the colour |
| 12974 | // index map, mapped through the base colours, IS the block's prediction -- | 13052 | // index map, mapped through the base colours, IS the block's prediction -- |
| 12975 | // carried to the next `reconstruct`/`read_plane` through the same | 13053 | // carried to the next `reconstruct`/`read_plane` through the same |
| @@ -13003,11 +13081,35 @@ fn decode_leaf8( | |||
| 13003 | // which splits the leaf's own 8x8 prediction into a 2x2 grid of 4x4 | 13081 | // which splits the leaf's own 8x8 prediction into a 2x2 grid of 4x4 |
| 13004 | // transform units, same raster-order per-TU pattern `decode_block`'s | 13082 | // transform units, same raster-order per-TU pattern `decode_block`'s |
| 13005 | // multi-TU branch runs). | 13083 | // multi-TU branch runs). |
| 13006 | - // ... and an intrabc leaf reads no intra `tx_depth` symbol at all: under | 13084 | + // ... and an intrabc leaf reads no intra `tx_depth` symbol at all: libaom |
| 13007 | - // `TX_MODE_SELECT` a skipped inter block takes the largest transform | 13085 | + // dispatches `read_block_tx_size` on `is_inter_block`, which counts an |
| 13008 | - // (`read_tx_size(.., is_inter=1, ..)`), and the unskipped case is refused | 13086 | + // intrabc block, so a SKIPPED one takes the largest transform and an |
| 13009 | - // above. | 13087 | + // UNSKIPPED one reads the inter var-tx tree (lane-t900 r32). At 8x8 that |
| 13010 | - let resolved = if tx_select && intrabc_dv.is_none() { | 13088 | + // tree is one `txfm_split` symbol: TX_8X8, or TX_4X4 over all four mi |
| 13089 | + // cells (`read_var_tx_size`'s `sub_txs == TX_4X4` early return). | ||
| 13090 | + let resolved = if tx_select && intrabc_dv.is_some() && !skip { | ||
| 13091 | + let mut leaves = Vec::new(); | ||
| 13092 | + let mi_cols = 2 * y.true_width.div_ceil(8); | ||
| 13093 | + let mi_rows = 2 * y.true_height.div_ceil(8); | ||
| 13094 | + read_var_tx_size( | ||
| 13095 | + dec, | ||
| 13096 | + cdfs, | ||
| 13097 | + neighbours, | ||
| 13098 | + leaf_mi, | ||
| 13099 | + 8, | ||
| 13100 | + ( | ||
| 13101 | + 2usize.min(mi_cols.saturating_sub(leaf_mi.1)), | ||
| 13102 | + 2usize.min(mi_rows.saturating_sub(leaf_mi.0)), | ||
| 13103 | + ), | ||
| 13104 | + (8, 8), | ||
| 13105 | + 0, | ||
| 13106 | + 0, | ||
| 13107 | + 0, | ||
| 13108 | + &mut leaves, | ||
| 13109 | + ); | ||
| 13110 | + INTRABC_VARTX_HITS.with(|c| c.set(c.get() + 1)); | ||
| 13111 | + leaves.first().map_or(8, |l| l.2) | ||
| 13112 | + } else if tx_select && intrabc_dv.is_none() { | ||
| 13011 | read_tx_size(dec, cdfs, neighbours, leaf_mi, 8, None) | 13113 | read_tx_size(dec, cdfs, neighbours, leaf_mi, 8, None) |
| 13012 | } else { | 13114 | } else { |
| 13013 | 8 | 13115 | 8 |
| @@ -13043,9 +13145,13 @@ fn decode_leaf8( | |||
| 13043 | // The per-plane prediction override rides the same [`PALETTE_PRED`] slot | 13145 | // The per-plane prediction override rides the same [`PALETTE_PRED`] slot |
| 13044 | // `decode_block` uses: set fresh right before each plane's own | 13146 | // `decode_block` uses: set fresh right before each plane's own |
| 13045 | // `reconstruct`/`read_plane` call (the slot is taken, not copied). | 13147 | // `reconstruct`/`read_plane` call (the slot is taken, not copied). |
| 13046 | - if let Some((yb, _, _)) = &intrabc_bufs { | 13148 | + // lane-t900 r32: through `palette_y_buf`, so the 4x4 TU loop below windows |
| 13047 | - set_palette_pred(yb.clone(), fctx); | 13149 | + // it per unit (an intrabc leaf whose var-tx tree split to TX_4X4 is the |
| 13048 | - } | 13150 | + // first shape that reaches that loop with an override set). |
| 13151 | + let palette_y_buf = match &intrabc_bufs { | ||
| 13152 | + Some((yb, _, _)) => Some(yb.clone()), | ||
| 13153 | + None => palette_y_buf, | ||
| 13154 | + }; | ||
| 13049 | let (luma_grid, u_grid, v_grid); | 13155 | let (luma_grid, u_grid, v_grid); |
| 13050 | if skip { | 13156 | if skip { |
| 13051 | // lane-hgkf r2 (same shape as `decode_block`'s own skip branch): an | 13157 | // lane-hgkf r2 (same shape as `decode_block`'s own skip branch): an |
| @@ -13290,7 +13396,9 @@ fn decode_leaf8( | |||
| 13290 | let tu_grid = read_plane( | 13396 | let tu_grid = read_plane( |
| 13291 | dec, | 13397 | dec, |
| 13292 | cdfs, | 13398 | cdfs, |
| 13293 | - if reduced_tx_set { | 13399 | + if intrabc_dv.is_some() { |
| 13400 | + txbset_for_inter(4, reduced_tx_set) | ||
| 13401 | + } else if reduced_tx_set { | ||
| 13294 | TxbSet::Luma4 | 13402 | TxbSet::Luma4 |
| 13295 | } else { | 13403 | } else { |
| 13296 | TxbSet::Luma4Set1 | 13404 | TxbSet::Luma4Set1 |
| @@ -13413,6 +13521,12 @@ fn decode_leaf8( | |||
| 13413 | } | 13521 | } |
| 13414 | neighbours.fill_skip_grid(leaf_mi, 2, skip); | 13522 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 13415 | neighbours.fill_lf_grid(leaf_mi, 2, 4, 0, fctx); | 13523 | neighbours.fill_lf_grid(leaf_mi, 2, 4, 0, fctx); |
| 13524 | + // lane-t900 r32: `set_txfm_ctxs` for an 8x8 leaf -- see `decode_block`'s | ||
| 13525 | + // own copy; only an intrabc var-tx read consumes these bands on the intra | ||
| 13526 | + // path, so the write is armed by `allow_intrabc`. | ||
| 13527 | + if allow_intrabc { | ||
| 13528 | + set_txfm_ctxs(neighbours, leaf_mi, 4, 2, 2, skip && intrabc_dv.is_some()); | ||
| 13529 | + } | ||
| 13416 | neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); | 13530 | neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); |
| 13417 | record_intrabc_mi(leaf_mi.0, leaf_mi.1, 2, intrabc_dv, fctx); | 13531 | record_intrabc_mi(leaf_mi.0, leaf_mi.1, 2, intrabc_dv, fctx); |
| 13418 | return Ok(mode); | 13532 | return Ok(mode); |
| @@ -13438,6 +13552,12 @@ fn decode_leaf8( | |||
| 13438 | // (class `wrong-alphabet-same-value`; the ReelB key frame at | 13552 | // (class `wrong-alphabet-same-value`; the ReelB key frame at |
| 13439 | // -ss 900, first bad luma sample row 186 col 1803). | 13553 | // -ss 900, first bad luma sample row 186 col 1803). |
| 13440 | neighbours.fill_lf_grid(leaf_mi, 2, resolved as u8, 0, fctx); | 13554 | neighbours.fill_lf_grid(leaf_mi, 2, resolved as u8, 0, fctx); |
| 13555 | + // lane-t900 r32: `set_txfm_ctxs` for an 8x8 leaf -- see `decode_block`'s | ||
| 13556 | + // own copy; only an intrabc var-tx read consumes these bands on the intra | ||
| 13557 | + // path, so the write is armed by `allow_intrabc`. | ||
| 13558 | + if allow_intrabc { | ||
| 13559 | + set_txfm_ctxs(neighbours, leaf_mi, resolved, 2, 2, skip && intrabc_dv.is_some()); | ||
| 13560 | + } | ||
| 13441 | neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); | 13561 | neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); |
| 13442 | // The DV predictor of a LATER intrabc block is the ordinary `INTRA_FRAME` | 13562 | // The DV predictor of a LATER intrabc block is the ordinary `INTRA_FRAME` |
| 13443 | // MV stack over this grid (`av1_find_mv_refs`), so an 8x8 leaf has to | 13563 | // MV stack over this grid (`av1_find_mv_refs`), so an 8x8 leaf has to |