Merge branch 'lane-intrabc': intrabc DV read (ndvc CDFs, INTRA_FRAME mv stack, find_ref_dv fallback) + block-copy prediction; refusal narrowed to 'intrabc under TxMode::Select' pending inter var-tx; mvstack sign_bias/gm_mv INTRA_FRAME index panics fixed (267/0 on branch)
Browse files at this commit6 changed files +351 -5
- crates/ec-av1/src/cdf_state.rs +12 -0
- crates/ec-av1/src/decode.rs +205 -3
- crates/ec-av1/src/gate_coverage.rs +7 -1
- crates/ec-av1/src/mvstack.rs +12 -0
- crates/ec-av1/src/refusal_inventory.rs +1 -1
- lanes/intrabc-r1.report.md +114 -0
crates/ec-av1/src/cdf_state.rsmodified+12 -0
| @@ -420,6 +420,12 @@ pub(crate) struct Cdfs { | |||
| 420 | /// The two motion vector components' own tables: separate owned state, | 420 | /// The two motion vector components' own tables: separate owned state, |
| 421 | /// since spec 8.3.2 adapts one component without touching the other. | 421 | /// since spec 8.3.2 adapts one component without touching the other. |
| 422 | pub mv_comp: [MvComponentCdfs; 2], | 422 | pub mv_comp: [MvComponentCdfs; 2], |
| 423 | + /// libaom's `ndvc` (`av1_init_mv_probs`): the block-vector MV context an | ||
| 424 | + /// intrabc block reads (spec's `MV_INTRABC_CONTEXT`). Same spec-8.4 | ||
| 425 | + /// defaults as [`Self::mv_joint`]/[`Self::mv_comp`], separate adaptation. | ||
| 426 | + pub dv_joint: [u16; 5], | ||
| 427 | + /// [`Self::dv_joint`]'s per-component half. | ||
| 428 | + pub dv_comp: [MvComponentCdfs; 2], | ||
| 423 | /// The `use_filter_intra` flag, indexed by block-size class (`[0]`=4x4, | 429 | /// The `use_filter_intra` flag, indexed by block-size class (`[0]`=4x4, |
| 424 | /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32, `[4]`=32x16, `[5]`=16x32) -- | 430 | /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32, `[4]`=32x16, `[5]`=16x32) -- |
| 425 | /// see [`cdf::FILTER_INTRA`]. | 431 | /// see [`cdf::FILTER_INTRA`]. |
| @@ -686,6 +692,10 @@ impl Cdfs { | |||
| 686 | reset2(&mut self.ref_mv); | 692 | reset2(&mut self.ref_mv); |
| 687 | reset2(&mut self.drl_mode); | 693 | reset2(&mut self.drl_mode); |
| 688 | reset1(&mut self.mv_joint); | 694 | reset1(&mut self.mv_joint); |
| 695 | + reset1(&mut self.dv_joint); | ||
| 696 | + self.dv_comp | ||
| 697 | + .iter_mut() | ||
| 698 | + .for_each(MvComponentCdfs::reset_counts); | ||
| 689 | self.mv_comp | 699 | self.mv_comp |
| 690 | .iter_mut() | 700 | .iter_mut() |
| 691 | .for_each(MvComponentCdfs::reset_counts); | 701 | .for_each(MvComponentCdfs::reset_counts); |
| @@ -1161,6 +1171,8 @@ impl Cdfs { | |||
| 1161 | drl_mode: cdf::DRL_MODE, | 1171 | drl_mode: cdf::DRL_MODE, |
| 1162 | mv_joint: cdf::MV_JOINT, | 1172 | mv_joint: cdf::MV_JOINT, |
| 1163 | mv_comp: [MvComponentCdfs::new(), MvComponentCdfs::new()], | 1173 | mv_comp: [MvComponentCdfs::new(), MvComponentCdfs::new()], |
| 1174 | + dv_joint: cdf::MV_JOINT, | ||
| 1175 | + dv_comp: [MvComponentCdfs::new(), MvComponentCdfs::new()], | ||
| 1164 | filter_intra: cdf::FILTER_INTRA, | 1176 | filter_intra: cdf::FILTER_INTRA, |
| 1165 | filter_intra_mode: cdf::FILTER_INTRA_MODE, | 1177 | filter_intra_mode: cdf::FILTER_INTRA_MODE, |
| 1166 | tx_size_cat0: cdf::TX_SIZE_CAT0, | 1178 | tx_size_cat0: cdf::TX_SIZE_CAT0, |
crates/ec-av1/src/decode.rsmodified+205 -3
| @@ -935,6 +935,69 @@ thread_local! { | |||
| 935 | const { std::cell::RefCell::new(None) }; | 935 | const { std::cell::RefCell::new(None) }; |
| 936 | } | 936 | } |
| 937 | 937 | ||
| 938 | +thread_local! { | ||
| 939 | + /// The current frame's `mi` grid, kept only while a frame header set | ||
| 940 | + /// `allow_intrabc` -- an intrabc block's DV predictor is the ordinary | ||
| 941 | + /// MV stack ([`crate::mvstack::find_mv_stack`]) built against | ||
| 942 | + /// `INTRA_FRAME`, which needs the neighbour state a key frame otherwise | ||
| 943 | + /// never keeps. `(grid, mi_cols, mi_rows)`; `None` on every frame that | ||
| 944 | + /// does not allow intrabc (so nothing is paid for it). | ||
| 945 | + /// | ||
| 946 | + /// corner-cut: only [`decode_block`] (the square path) records into it, | ||
| 947 | + /// so a frame mixing intrabc with rect/sub-8x8 leaves would predict off | ||
| 948 | + /// an incomplete grid. Ceiling: the DV *value* (never the parse) would | ||
| 949 | + /// be wrong there; upgrade = record from the rect/leaf paths too. | ||
| 950 | + static INTRABC_MI_GRID: std::cell::RefCell<Option<(crate::mvstack::MiGrid, usize, usize)>> = | ||
| 951 | + const { std::cell::RefCell::new(None) }; | ||
| 952 | + /// The block vector [`read_intra_mode`] just decoded, handed to | ||
| 953 | + /// [`decode_block`] off the call stack (same idiom as [`PALETTE_PRED`], | ||
| 954 | + /// which the alternative -- a tenth tuple member through every caller -- | ||
| 955 | + /// already avoids). Always `.take()`n by the block that reads it. | ||
| 956 | + static INTRABC_DV: std::cell::Cell<Option<(i32, i32)>> = const { std::cell::Cell::new(None) }; | ||
| 957 | + /// How many blocks decoded `use_intrabc == 1` -- the gate's hit counter. | ||
| 958 | + static INTRABC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 959 | +} | ||
| 960 | + | ||
| 961 | +/// Current value of [`INTRABC_HITS`]. | ||
| 962 | +pub(crate) fn intrabc_hits() -> usize { | ||
| 963 | + INTRABC_HITS.with(|c| c.get()) | ||
| 964 | +} | ||
| 965 | + | ||
| 966 | +/// Zeroes [`INTRABC_HITS`] (gate tests call this before a decode). | ||
| 967 | +pub(crate) fn reset_intrabc_hits() { | ||
| 968 | + INTRABC_HITS.with(|c| c.set(0)); | ||
| 969 | +} | ||
| 970 | + | ||
| 971 | +/// Records one coded block into [`INTRABC_MI_GRID`]: every block contributes | ||
| 972 | +/// its size (libaom's `scan_row_mbmi` advances `processed_rows` off any | ||
| 973 | +/// candidate's `bsize`, ref-match or not), an intrabc one also its DV as an | ||
| 974 | +/// `INTRA_FRAME` candidate (libaom treats intrabc as `is_inter_block`). | ||
| 975 | +fn record_intrabc_mi(mi_r: usize, mi_c: usize, n4: usize, dv: Option<(i32, i32)>) { | ||
| 976 | + INTRABC_MI_GRID.with(|g| { | ||
| 977 | + let mut g = g.borrow_mut(); | ||
| 978 | + let Some((grid, _, _)) = g.as_mut() else { | ||
| 979 | + return; | ||
| 980 | + }; | ||
| 981 | + let info = crate::mvstack::MiInfo { | ||
| 982 | + is_inter: dv.is_some(), | ||
| 983 | + ref_frame: 0, | ||
| 984 | + ref_frame1: None, | ||
| 985 | + mv: dv.unwrap_or((0, 0)), | ||
| 986 | + mv1: None, | ||
| 987 | + is_new_mv: dv.is_some(), | ||
| 988 | + is_global_mv0: false, | ||
| 989 | + is_global_mv1: false, | ||
| 990 | + size: n4, | ||
| 991 | + size_h: n4, | ||
| 992 | + }; | ||
| 993 | + for r in mi_r..mi_r + n4 { | ||
| 994 | + for c in mi_c..mi_c + n4 { | ||
| 995 | + grid.set(r, c, info); | ||
| 996 | + } | ||
| 997 | + } | ||
| 998 | + }); | ||
| 999 | +} | ||
| 1000 | + | ||
| 938 | // How many blocks decoded `skip_mode == 1` (lane-av1comp round 14) -- | 1001 | // How many blocks decoded `skip_mode == 1` (lane-av1comp round 14) -- |
| 939 | // proves a real `skip_mode_present` stream actually reached a block that | 1002 | // proves a real `skip_mode_present` stream actually reached a block that |
| 940 | // picked it, not just that the frame header bit was set. | 1003 | // picked it, not just that the frame header bit was set. |
| @@ -4440,9 +4503,18 @@ fn read_intra_mode( | |||
| 4440 | eprintln!("TRACE use_intrabc value={}", use_intrabc as i32); | 4503 | eprintln!("TRACE use_intrabc value={}", use_intrabc as i32); |
| 4441 | } | 4504 | } |
| 4442 | if use_intrabc { | 4505 | if use_intrabc { |
| 4443 | - return Err(unsupported( | 4506 | + let dv = read_intrabc_dv(dec, cdfs, mi_r, mi_c, side); |
| 4444 | - "a block that actually uses intrabc (this decoder never reconstructs one)", | 4507 | + if trace { |
| 4445 | - )); | 4508 | + eprintln!("TRACE intrabc dv={dv:?}"); |
| 4509 | + } | ||
| 4510 | + INTRABC_DV.with(|c| c.set(Some(dv))); | ||
| 4511 | + INTRABC_HITS.with(|c| c.set(c.get() + 1)); | ||
| 4512 | + // spec 5.11.13 / libaom `read_intra_frame_mode_info` returns the | ||
| 4513 | + // moment `is_intrabc_block`: no y/uv mode, angle delta, palette, | ||
| 4514 | + // CFL or filter-intra syntax follows. `YMode`/`UVMode` are forced | ||
| 4515 | + // `DC_PRED` (which is also what the neighbour mode contexts and | ||
| 4516 | + // the loop filter then see). | ||
| 4517 | + return Ok((skip, DC_PRED, 0, DC_PRED, 0, None, None, None, None)); | ||
| 4446 | } | 4518 | } |
| 4447 | } | 4519 | } |
| 4448 | let above_ctx = INTRA_MODE_CTX[above_mode]; | 4520 | let above_ctx = INTRA_MODE_CTX[above_mode]; |
| @@ -5173,6 +5245,16 @@ fn decode_block( | |||
| 5173 | r * (SUB / MI), | 5245 | r * (SUB / MI), |
| 5174 | c * (SUB / MI), | 5246 | c * (SUB / MI), |
| 5175 | )?; | 5247 | )?; |
| 5248 | + let intrabc_dv = INTRABC_DV.with(|c| c.take()); | ||
| 5249 | + // libaom `parse_decode_block`: an intrabc block is `inter_block_tx`, so | ||
| 5250 | + // under `TX_MODE_SELECT` its transform size comes from the inter var-tx | ||
| 5251 | + // partition tree (`read_var_tx_size`), a syntax element this decoder has | ||
| 5252 | + // nowhere -- reading the intra `tx_depth` symbol instead would desync. | ||
| 5253 | + if intrabc_dv.is_some() && tx_select && !skip { | ||
| 5254 | + return Err(unsupported( | ||
| 5255 | + "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)", | ||
| 5256 | + )); | ||
| 5257 | + } | ||
| 5176 | // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED` | 5258 | // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED` |
| 5177 | // (13) predicts as `DC_PRED` with the [`cfl_scaled`] nudge carrying the | 5259 | // (13) predicts as `DC_PRED` with the [`cfl_scaled`] nudge carrying the |
| 5178 | // actual chroma-from-luma correlation, same as this decoder always did. | 5260 | // actual chroma-from-luma correlation, same as this decoder always did. |
| @@ -5212,10 +5294,45 @@ fn decode_block( | |||
| 5212 | } else { | 5294 | } else { |
| 5213 | luma_set | 5295 | luma_set |
| 5214 | }; | 5296 | }; |
| 5297 | + let luma_set = if intrabc_dv.is_some() { | ||
| 5298 | + txbset_for_inter(logical_tx, reduced_tx_set) | ||
| 5299 | + } else { | ||
| 5300 | + luma_set | ||
| 5301 | + }; | ||
| 5215 | let luma_scan = scan_for(coeff_tx_side, scan32, scan16, scan8, scan4); | 5302 | let luma_scan = scan_for(coeff_tx_side, scan32, scan16, scan8, scan4); |
| 5216 | let reach = Reach::of(side, px, py, y.width, y.height); | 5303 | let reach = Reach::of(side, px, py, y.width, y.height); |
| 5217 | let (cpx, cpy) = (px / 2, py / 2); | 5304 | let (cpx, cpy) = (px / 2, py / 2); |
| 5218 | let chroma_side = side / 2; | 5305 | let chroma_side = side / 2; |
| 5306 | + // spec 7.11.3.4 with `use_intrabc`: the reference is the *current* | ||
| 5307 | + // frame's own pre-loop-filter reconstruction (all loop filters are off | ||
| 5308 | + // whenever `allow_intrabc`, frame.rs:194/210/252/272) at the full-pel | ||
| 5309 | + // block vector, with the BILINEAR kernel libaom forces for intrabc -- | ||
| 5310 | + // luma is a straight copy, chroma lands half-pel whenever the luma DV is | ||
| 5311 | + // odd, which is exactly what the bilinear taps then interpolate. | ||
| 5312 | + let intrabc_bufs = intrabc_dv.map(|(dv_row, dv_col)| { | ||
| 5313 | + let mut yb = vec![0u16; side * side]; | ||
| 5314 | + mc::predict_with_filter( | ||
| 5315 | + &y.data, y.width, y.true_width, y.true_height, | ||
| 5316 | + mv_to_q4(px, dv_col, true), mv_to_q4(py, dv_row, true), | ||
| 5317 | + side, side, mc::InterpFilterKind::Bilinear, &mut yb, | ||
| 5318 | + ); | ||
| 5319 | + let mut ub = vec![0u16; chroma_side * chroma_side]; | ||
| 5320 | + mc::predict_with_filter( | ||
| 5321 | + &u.data, u.width, u.true_width, u.true_height, | ||
| 5322 | + mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false), | ||
| 5323 | + chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut ub, | ||
| 5324 | + ); | ||
| 5325 | + let mut vb = vec![0u16; chroma_side * chroma_side]; | ||
| 5326 | + mc::predict_with_filter( | ||
| 5327 | + &v.data, v.width, v.true_width, v.true_height, | ||
| 5328 | + mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false), | ||
| 5329 | + chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut vb, | ||
| 5330 | + ); | ||
| 5331 | + (yb, ub, vb) | ||
| 5332 | + }); | ||
| 5333 | + if let Some((yb, _, _)) = &intrabc_bufs { | ||
| 5334 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(yb.clone())); | ||
| 5335 | + } | ||
| 5219 | // A palette-Y block's own prediction is the reconstructed colour-index | 5336 | // A palette-Y block's own prediction is the reconstructed colour-index |
| 5220 | // map, not `predict()`'s edge-based one -- [`PALETTE_PRED`] carries it | 5337 | // map, not `predict()`'s edge-based one -- [`PALETTE_PRED`] carries it |
| 5221 | // to [`PlaneBuf::reconstruct`]'s next call rather than threading a | 5338 | // to [`PlaneBuf::reconstruct`]'s next call rather than threading a |
| @@ -5248,6 +5365,13 @@ fn decode_block( | |||
| 5248 | puv.map.iter().map(|&idx| puv.v_colors[idx as usize]).collect(), | 5365 | puv.map.iter().map(|&idx| puv.v_colors[idx as usize]).collect(), |
| 5249 | ) | 5366 | ) |
| 5250 | }); | 5367 | }); |
| 5368 | + // The chroma half of the intrabc prediction rides the same per-plane | ||
| 5369 | + // override slot the UV-palette buffers do (set fresh before each plane's | ||
| 5370 | + // own `reconstruct`/`read_plane` call below). | ||
| 5371 | + let palette_uv_bufs = match &intrabc_bufs { | ||
| 5372 | + Some((_, ub, vb)) => Some((ub.clone(), vb.clone())), | ||
| 5373 | + None => palette_uv_bufs, | ||
| 5374 | + }; | ||
| 5251 | if skip { | 5375 | if skip { |
| 5252 | // A skipped block codes no residual syntax at all (spec 5.11.34): | 5376 | // A skipped block codes no residual syntax at all (spec 5.11.34): |
| 5253 | // straight prediction, on every plane. | 5377 | // straight prediction, on every plane. |
| @@ -5513,6 +5637,7 @@ fn decode_block( | |||
| 5513 | logical_tx as u8, | 5637 | logical_tx as u8, |
| 5514 | 0, | 5638 | 0, |
| 5515 | ); | 5639 | ); |
| 5640 | + record_intrabc_mi(mi_r, mi_c, side / MI, intrabc_dv); | ||
| 5516 | Ok(()) | 5641 | Ok(()) |
| 5517 | } | 5642 | } |
| 5518 | 5643 | ||
| @@ -6172,6 +6297,21 @@ fn scan_for<'a>( | |||
| 6172 | /// `tx_size_sqr == TX_16X16` branch ignores `use_reduced_set` once it is past | 6297 | /// `tx_size_sqr == TX_16X16` branch ignores `use_reduced_set` once it is past |
| 6173 | /// the `TX_32X32`/reduced-set checks), so only the 8x8 and 4x4 cases have a | 6298 | /// the `TX_32X32`/reduced-set checks), so only the 8x8 and 4x4 cases have a |
| 6174 | /// second table ([`TxbSet::Luma8Set1`]/[`TxbSet::Luma4Set1`]). | 6299 | /// second table ([`TxbSet::Luma8Set1`]/[`TxbSet::Luma4Set1`]). |
| 6300 | +/// [`txbset_for`], for a block libaom's `is_inter_block` calls inter -- which | ||
| 6301 | +/// an intrabc block is (`blockd.h:373`), so its `tx_type` comes off the | ||
| 6302 | +/// inter `ext_tx` sets, never the mode-indexed intra ones. | ||
| 6303 | +fn txbset_for_inter(tx_px: usize, reduced_tx_set: bool) -> TxbSet { | ||
| 6304 | + match tx_px { | ||
| 6305 | + 64 => TxbSet::Luma64, | ||
| 6306 | + 32 => TxbSet::Luma32Inter, | ||
| 6307 | + 16 if reduced_tx_set => TxbSet::Luma16Inter, | ||
| 6308 | + 16 => TxbSet::Luma16InterSet1, | ||
| 6309 | + 8 if reduced_tx_set => TxbSet::Luma8Inter, | ||
| 6310 | + 8 => TxbSet::Luma8InterSet1, | ||
| 6311 | + _ => TxbSet::Luma64, | ||
| 6312 | + } | ||
| 6313 | +} | ||
| 6314 | + | ||
| 6175 | fn txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet { | 6315 | fn txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet { |
| 6176 | match tx_px { | 6316 | match tx_px { |
| 6177 | 64 => TxbSet::Luma64, | 6317 | 64 => TxbSet::Luma64, |
| @@ -6994,6 +7134,16 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 6994 | } | 7134 | } |
| 6995 | ENABLE_EDGE_FILTER.with(|f| f.set(enable_edge_filter)); | 7135 | ENABLE_EDGE_FILTER.with(|f| f.set(enable_edge_filter)); |
| 6996 | let (sb_cols, sb_rows) = (mi_cols.div_ceil(SB_MI), mi_rows.div_ceil(SB_MI)); | 7136 | let (sb_cols, sb_rows) = (mi_cols.div_ceil(SB_MI), mi_rows.div_ceil(SB_MI)); |
| 7137 | + INTRABC_MI_GRID.with(|g| { | ||
| 7138 | + *g.borrow_mut() = allow_intrabc.then(|| { | ||
| 7139 | + ( | ||
| 7140 | + crate::mvstack::MiGrid::new(mi_cols as usize, mi_rows as usize), | ||
| 7141 | + mi_cols as usize, | ||
| 7142 | + mi_rows as usize, | ||
| 7143 | + ) | ||
| 7144 | + }); | ||
| 7145 | + }); | ||
| 7146 | + INTRABC_DV.with(|c| c.set(None)); | ||
| 6997 | CDEF_BITS.with(|c| c.set(cdef.bits)); | 7147 | CDEF_BITS.with(|c| c.set(cdef.bits)); |
| 6998 | CDEF_SB_COLS.with(|c| c.set(sb_cols as usize)); | 7148 | CDEF_SB_COLS.with(|c| c.set(sb_cols as usize)); |
| 6999 | CDEF_IDX_GRID.with(|g| *g.borrow_mut() = vec![0u8; sb_cols as usize * sb_rows as usize]); | 7149 | CDEF_IDX_GRID.with(|g| *g.borrow_mut() = vec![0u8; sb_cols as usize * sb_rows as usize]); |
| @@ -8103,6 +8253,58 @@ fn read_mv( | |||
| 8103 | (pred.0 + diff.0, pred.1 + diff.1) | 8253 | (pred.0 + diff.0, pred.1 + diff.1) |
| 8104 | } | 8254 | } |
| 8105 | 8255 | ||
| 8256 | +/// One intrabc block's block vector (spec 5.11.13 `read_intrabc_info` -> | ||
| 8257 | +/// `assign_mv` with `use_intrabc`, libaom `assign_dv`/`av1_find_ref_dv`). | ||
| 8258 | +/// | ||
| 8259 | +/// The predictor is the ordinary MV stack built against `INTRA_FRAME` | ||
| 8260 | +/// (`av1_find_mv_refs(..., INTRA_FRAME, ...)`): `nearestmv`, or `nearmv` | ||
| 8261 | +/// when that is zero, or -- when both are -- the fixed fallback DV one | ||
| 8262 | +/// superblock up, or `INTRABC_DELAY_PIXELS` (256) plus one superblock to the | ||
| 8263 | +/// left when this is the tile's first superblock row. The predictor is then | ||
| 8264 | +/// rounded to full pel, and the difference reads off the *dv* nmv context | ||
| 8265 | +/// (libaom `ndvc`) at full-pel precision (`MV_SUBPEL_NONE`: no `fr`/`hp` | ||
| 8266 | +/// symbols, exactly this decoder's `force_integer_mv` carve-out). No DRL | ||
| 8267 | +/// symbol is coded for a DV, so none of this can move the bitstream | ||
| 8268 | +/// position -- only the reconstructed vector. | ||
| 8269 | +fn read_intrabc_dv( | ||
| 8270 | + dec: &mut SymbolDecoder, | ||
| 8271 | + cdfs: &mut Cdfs, | ||
| 8272 | + mi_r: usize, | ||
| 8273 | + mi_c: usize, | ||
| 8274 | + side: usize, | ||
| 8275 | +) -> (i32, i32) { | ||
| 8276 | + const INTRABC_DELAY_PIXELS: i32 = 256; | ||
| 8277 | + let n4 = side / MI; | ||
| 8278 | + let stack_pred = INTRABC_MI_GRID.with(|g| { | ||
| 8279 | + let g = g.borrow(); | ||
| 8280 | + g.as_ref().map(|(grid, mi_cols, mi_rows)| { | ||
| 8281 | + let stack = crate::mvstack::find_mv_stack( | ||
| 8282 | + grid, mi_r, mi_c, n4, n4, 0, /* INTRA_FRAME */ | ||
| 8283 | + *mi_cols, *mi_rows, | ||
| 8284 | + ); | ||
| 8285 | + if stack.nearest_mv == (0, 0) { | ||
| 8286 | + stack.near_mv | ||
| 8287 | + } else { | ||
| 8288 | + stack.nearest_mv | ||
| 8289 | + } | ||
| 8290 | + }) | ||
| 8291 | + }); | ||
| 8292 | + let mut pred = stack_pred.unwrap_or((0, 0)); | ||
| 8293 | + if pred == (0, 0) { | ||
| 8294 | + // `av1_find_ref_dv` (mvref_common.c). Tile row start is 0 here (the | ||
| 8295 | + // single-tile-row case every intrabc gate stream is). | ||
| 8296 | + let sb_px = SB_MI as i32 * MI as i32; | ||
| 8297 | + pred = if mi_r < SB_MI as usize { | ||
| 8298 | + (0, -(sb_px + INTRABC_DELAY_PIXELS) * 8) | ||
| 8299 | + } else { | ||
| 8300 | + (-sb_px * 8, 0) | ||
| 8301 | + }; | ||
| 8302 | + } | ||
| 8303 | + // "Ref DV should not have sub-pel" (`assign_dv`): floor to full pel. | ||
| 8304 | + let pred = ((pred.0 >> 3) * 8, (pred.1 >> 3) * 8); | ||
| 8305 | + read_mv(dec, &mut cdfs.dv_comp, &mut cdfs.dv_joint, pred, false, true) | ||
| 8306 | +} | ||
| 8307 | + | ||
| 8106 | /// A 1/8-pel motion vector component converted to the 1/16-pel offset | 8308 | /// A 1/8-pel motion vector component converted to the 1/16-pel offset |
| 8107 | /// [`mc::predict`] takes, duplicating [`crate::encode`]'s private `mv_to_q4` | 8309 | /// [`mc::predict`] takes, duplicating [`crate::encode`]'s private `mv_to_q4` |
| 8108 | /// (its own doc comment explains the `*2`/`*1` luma/chroma split). | 8310 | /// (its own doc comment explains the `*2`/`*1` luma/chroma split). |
crates/ec-av1/src/gate_coverage.rsmodified+7 -1
| @@ -33,7 +33,13 @@ | |||
| 33 | /// its tool is now covered by a real stream. | 33 | /// its tool is now covered by a real stream. |
| 34 | #[cfg(test)] | 34 | #[cfg(test)] |
| 35 | const NEVER_EXERCISED: &[(&str, &str)] = &[ | 35 | const NEVER_EXERCISED: &[(&str, &str)] = &[ |
| 36 | - ("enable-intrabc", "intra block copy syntax is consumed but no block is reconstructed from it"), | 36 | + // lane-intrabc r1: the DV itself (mv stack against INTRA_FRAME, `ndvc` |
| 37 | + // full-pel read, `av1_find_ref_dv` fallback) and the block-copy | ||
| 38 | + // prediction are now decoded, but every real aomenc intrabc block this | ||
| 39 | + // lane could produce sits under TX_MODE_SELECT, whose inter var-tx | ||
| 40 | + // partition tree is unread -- so no stream reconstructs one end to end | ||
| 41 | + // yet and this entry stays. | ||
| 42 | + ("enable-intrabc", "the block vector is decoded and predicted from, but every real stream's intrabc block needs the unread inter var-tx transform tree"), | ||
| 37 | ]; | 43 | ]; |
| 38 | 44 | ||
| 39 | #[cfg(test)] | 45 | #[cfg(test)] |
crates/ec-av1/src/mvstack.rsmodified+12 -0
| @@ -327,6 +327,13 @@ fn add_candidate(candidates: &mut Vec<StackEntry>, mv: (i32, i32), weight: u32) | |||
| 327 | /// `LAST_FRAME`) pass an all-`false` table, matching this stub's old | 327 | /// `LAST_FRAME`) pass an all-`false` table, matching this stub's old |
| 328 | /// always-`false` behaviour exactly. | 328 | /// always-`false` behaviour exactly. |
| 329 | fn sign_bias(table: &SignBiasTable, ref_frame: i8) -> bool { | 329 | fn sign_bias(table: &SignBiasTable, ref_frame: i8) -> bool { |
| 330 | + // lane-intrabc: `INTRA_FRAME` (0) and `NONE` (-1) sit *below* the table's | ||
| 331 | + // own `LAST_FRAME` base and have no sign bias at all -- an intrabc block | ||
| 332 | + // queries the stack with `ref_frame == INTRA_FRAME`, which indexed this | ||
| 333 | + // table at `usize::MAX` before. | ||
| 334 | + if ref_frame < LAST_FRAME { | ||
| 335 | + return false; | ||
| 336 | + } | ||
| 330 | table[(ref_frame - LAST_FRAME) as usize] | 337 | table[(ref_frame - LAST_FRAME) as usize] |
| 331 | } | 338 | } |
| 332 | 339 | ||
| @@ -359,6 +366,11 @@ pub const NO_GM_MV: GmMvTable = [(0, 0); 7]; | |||
| 359 | /// `table[ref_frame - LAST_FRAME]`, [`sign_bias`]'s shape for a | 366 | /// `table[ref_frame - LAST_FRAME]`, [`sign_bias`]'s shape for a |
| 360 | /// [`GmMvTable`]. | 367 | /// [`GmMvTable`]. |
| 361 | fn gm_mv(table: &GmMvTable, ref_frame: i8) -> (i32, i32) { | 368 | fn gm_mv(table: &GmMvTable, ref_frame: i8) -> (i32, i32) { |
| 369 | + // Same below-`LAST_FRAME` guard as [`sign_bias`]: `INTRA_FRAME` (the | ||
| 370 | + // intrabc query's own ref) has no global motion model. | ||
| 371 | + if ref_frame < LAST_FRAME { | ||
| 372 | + return (0, 0); | ||
| 373 | + } | ||
| 362 | table[(ref_frame - LAST_FRAME) as usize] | 374 | table[(ref_frame - LAST_FRAME) as usize] |
| 363 | } | 375 | } |
| 364 | 376 | ||
crates/ec-av1/src/refusal_inventory.rsmodified+1 -1
| @@ -50,7 +50,7 @@ const REFUSALS: &[&str] = &[ | |||
| 50 | "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)", | 50 | "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)", |
| 51 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", | 51 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", |
| 52 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", | 52 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 53 | - "a block that actually uses intrabc (this decoder never reconstructs one)", | 53 | + "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)", |
| 54 | "a frame OBU with no tile group", | 54 | "a frame OBU with no tile group", |
| 55 | "a frame naming primary_ref_frame at a reference slot with no saved CDF state", | 55 | "a frame naming primary_ref_frame at a reference slot with no saved CDF state", |
| 56 | "a frame with no mode-info grid", | 56 | "a frame with no mode-info grid", |
lanes/intrabc-r1.report.mdadded+114 -0
| @@ -0,0 +1,114 @@ | |||
| 1 | +# lane-intrabc r1 — the block vector decodes; the transform tree does not | ||
| 2 | + | ||
| 3 | +## Verdict | ||
| 4 | + | ||
| 5 | +The headline refusal `a block that actually uses intrabc (this decoder never | ||
| 6 | +reconstructs one)` is **replaced, not lifted**. Its successor names the real | ||
| 7 | +remaining wall: | ||
| 8 | + | ||
| 9 | +``` | ||
| 10 | +an intrabc block under TxMode::Select (its transform size is coded by the | ||
| 11 | +inter var-tx partition tree, which this decoder never reads) | ||
| 12 | +``` | ||
| 13 | + | ||
| 14 | +Everything the charter listed *before* the residual is implemented and runs on | ||
| 15 | +real aomenc streams: `use_intrabc`, the DV's own mv stack, the `ndvc` full-pel | ||
| 16 | +`read_mv`, `av1_find_ref_dv`'s fallback, and the block-copy prediction. No | ||
| 17 | +pixel-exact gate exists yet, because no aomenc recipe found this round produces | ||
| 18 | +an intrabc block that does *not* also need `read_var_tx_size`. | ||
| 19 | + | ||
| 20 | +## What changed (worktree `edith_codecs-intrabc`, branch `lane-intrabc`) | ||
| 21 | + | ||
| 22 | +- `crates/ec-av1/src/cdf_state.rs:422` — `dv_joint`/`dv_comp`: libaom's `ndvc` | ||
| 23 | + (`av1_init_mv_probs` gives it the same spec-8.4 defaults as `nmvc`, separate | ||
| 24 | + adaptation), added to the per-frame counter-reset list at `:684`. | ||
| 25 | +- `crates/ec-av1/src/decode.rs:590` — `INTRABC_MI_GRID` / `INTRABC_DV` / | ||
| 26 | + `INTRABC_HITS` thread-locals + `intrabc_hits()`, `reset_intrabc_hits()`, | ||
| 27 | + `record_intrabc_mi()`. The mi grid exists only while a frame header set | ||
| 28 | + `allow_intrabc`. | ||
| 29 | +- `crates/ec-av1/src/decode.rs:4046` (`read_intra_mode`) — `use_intrabc == 1` | ||
| 30 | + now reads the DV instead of refusing, and returns immediately with | ||
| 31 | + `YMode`/`UVMode` forced `DC_PRED` (libaom `read_intra_frame_mode_info` | ||
| 32 | + returns at `decodemv.c:895`, so no mode/angle/palette/CFL/filter-intra | ||
| 33 | + syntax follows). | ||
| 34 | +- `crates/ec-av1/src/decode.rs:7681` — `read_intrabc_dv`: MV stack against | ||
| 35 | + `INTRA_FRAME`, `nearest` else `near`, else `av1_find_ref_dv` | ||
| 36 | + (`(0, -(64+256)*8)` in the first SB row, else `(-64*8, 0)`), predictor | ||
| 37 | + floored to full pel, then `read_mv` on `dv_comp`/`dv_joint` with | ||
| 38 | + `MV_SUBPEL_NONE` semantics (`force_integer_mv=true`, | ||
| 39 | + `allow_high_precision_mv=false`). No DRL symbol is coded for a DV, so a | ||
| 40 | + wrong predictor can only move pixels, never the bitstream position. | ||
| 41 | +- `crates/ec-av1/src/decode.rs` (`decode_block`) — takes the DV, refuses | ||
| 42 | + var-tx by name, switches the luma `TxbSet` to the **inter** ext-tx sets | ||
| 43 | + (`txbset_for_inter`, since libaom's `is_inter_block` is true for intrabc, | ||
| 44 | + `blockd.h:373`), builds the Y/U/V block-copy prediction with | ||
| 45 | + `mc::predict_with_filter(.., Bilinear, ..)` off the *current* planes and | ||
| 46 | + ships it through the existing `PALETTE_PRED` per-block prediction override, | ||
| 47 | + and records the block into the mi grid. | ||
| 48 | +- `crates/ec-av1/src/mvstack.rs:330,368` — **two real index bugs**: | ||
| 49 | + `sign_bias()` and `gm_mv()` both indexed `table[ref_frame - LAST_FRAME]` | ||
| 50 | + with no lower guard, so any query with `ref_frame == INTRA_FRAME` (0), which | ||
| 51 | + is exactly what an intrabc block does, panicked with | ||
| 52 | + `index out of bounds: the len is 7 but the index is 18446744073709551615`. | ||
| 53 | + Both now return the neutral value below `LAST_FRAME`. Same-shape sweep: those | ||
| 54 | + are the only two `- LAST_FRAME` table indexes in the crate. | ||
| 55 | +- `crates/ec-av1/src/refusal_inventory.rs:55`, `gate_coverage.rs:36` — refusal | ||
| 56 | + string replaced; `enable-intrabc` stays in `NEVER_EXERCISED` with its reason | ||
| 57 | + rewritten to the true state. | ||
| 58 | + | ||
| 59 | +## Fixture recipe (the round's most reusable finding) | ||
| 60 | + | ||
| 61 | +Intra block copy is **impossible in a 64x64 frame**: a valid DV must clear | ||
| 62 | +`INTRABC_DELAY_PIXELS` (256) plus one superblock, so a single-SB frame can | ||
| 63 | +never contain one. Every 64x64 sweep this lane ran (3 sources x 6 cq) produced | ||
| 64 | +zero intrabc blocks. A 512-wide frame with horizontally repeated content does: | ||
| 65 | + | ||
| 66 | +``` | ||
| 67 | +ffmpeg -f lavfi -i "testsrc2=size=64x64:rate=1" -t 0.04 \ | ||
| 68 | + -vf "tile=8x1,scale=512:64" -pix_fmt yuv420p -f rawvideo wide512.yuv | ||
| 69 | +~/.cache/aom-oracle/build/aomenc --codec=av1 -w 512 -h 64 --i420 --limit=1 \ | ||
| 70 | + --kf-max-dist=1 --cpu-used=1 --passes=1 --end-usage=q --cq-level=20 \ | ||
| 71 | + --enable-intrabc=1 --tune-content=screen --enable-palette=0 \ | ||
| 72 | + --enable-rect-partitions=0 --enable-ab-partitions=0 \ | ||
| 73 | + --enable-1to4-partitions=0 --min-partition-size=16 --max-partition-size=32 \ | ||
| 74 | + --obu -o w.obu wide512.yuv | ||
| 75 | +cargo run -p ec-av1 --release --example decode_probe -- w.obu | ||
| 76 | +``` | ||
| 77 | + | ||
| 78 | +`--enable-palette=0` and the partition switches are a **deviation from the | ||
| 79 | +charter's gate recipe** (`--enable-palette=1`): with palette on, or with rect/AB | ||
| 80 | +partitions available, the stream refuses on palette or on a sub-16x16 AB | ||
| 81 | +partition *before* the first intrabc block, so it cannot isolate this lane's | ||
| 82 | +capability at all. `cpu-used` must be <= 2 — at 3 and above aomenc's speed | ||
| 83 | +features stop searching intrabc entirely (sweep: cpu 3/5/6/8 x cq 20/40, all 8 | ||
| 84 | +decode clean, i.e. no intrabc block at all). | ||
| 85 | + | ||
| 86 | +## EVIDENCE | ||
| 87 | + | ||
| 88 | +EVIDENCE: /tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/b6d8a07f-96a4-4bbb-b378-af9ae25cf7c9/scratchpad/w.obu | recipe above, cpu-used 1 and 2 x cq 20/40, decode_probe before vs after | before: `REFUSED: ... a block that actually uses intrabc`; after: `REFUSED: ... an intrabc block under TxMode::Select` — the `use_intrabc` symbol, the DV read and the prediction all ran, 4/4 streams | ||
| 89 | +EVIDENCE: same streams | sweep cpu-used 0,1,2,3,5,6,8 x cq 20,40,55 | intrabc only appears at cpu-used <= 2; cpu 0 stops earlier on an SB-level partition type | ||
| 90 | + | ||
| 91 | +## Residue | ||
| 92 | + | ||
| 93 | +- fix-now (next round, needs its own charter): `read_var_tx_size` — the | ||
| 94 | + `txfm_partition` CDF (21 contexts) does not exist anywhere in the crate, nor | ||
| 95 | + do the above/left txfm-context arrays it needs, nor does the residual loop | ||
| 96 | + handle a non-uniform TU tree. This is the single blocker between here and a | ||
| 97 | + pixel-exact intrabc gate. | ||
| 98 | +- deferred(var-tx): the pixel-exact 8-bit/10-bit gate the charter asks for, and | ||
| 99 | + the `gate_coverage.rs` entry retirement — no stream can reach reconstruction | ||
| 100 | + until var-tx reads. | ||
| 101 | +- accepted, documented as corner-cuts in source: only `decode_block` (square | ||
| 102 | + path) records into the intrabc mi grid; a frame mixing intrabc with rect or | ||
| 103 | + sub-8x8 leaves would predict off an incomplete grid (DV value only, never the | ||
| 104 | + parse). Chroma of an inter/intrabc block should inherit the co-located luma | ||
| 105 | + `tx_type` (libaom `av1_get_tx_type`), while `read_plane` still derives | ||
| 106 | + `DCT_DCT` for chroma — no symbol difference, but a suspected pixel difference | ||
| 107 | + the moment luma picks a non-DCT type. Both are prime suspects for the first | ||
| 108 | + pixel mismatch once var-tx lands. | ||
| 109 | + | ||
| 110 | +## Test totals | ||
| 111 | + | ||
| 112 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (worktree, commit 09d6ff9): | ||
| 113 | +**267 passed, 0 failed, 23 ignored**, 1125 s. `refusal_inventory` and | ||
| 114 | +`gate_coverage` are green with the rewritten entries. | ||