diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 0fb4e844..24b71b80 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1674,6 +1674,21 @@ thread_local! { static INTRABC_DV: std::cell::Cell> = const { std::cell::Cell::new(None) }; /// How many blocks decoded `use_intrabc == 1` -- the gate's hit counter. static INTRABC_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// The `tx_type` the last plane-0 [`read_plane`] actually coded, kept so + /// an intrabc block's chroma reads can inherit it (see + /// [`INTRABC_CHROMA_TX`]). Written on every luma read; only ever read + /// through that one arming site. + static LUMA_TX_TYPE: std::cell::Cell = const { std::cell::Cell::new(TxType::DctDct) }; + /// libaom `av1_get_tx_type` (`blockd.h:1350`): for `PLANE_TYPE_UV` it + /// branches on `is_inter_block(mbmi)` -- which `is_intrabc_block` also + /// satisfies (`blockd.h:373`) -- and takes the *colocated luma + /// transform's coded* `tx_type` (`mbmi->txk_type[...]`), never + /// `intra_mode_to_tx_type` of the chroma mode. `Some` only across an + /// intrabc block's two chroma [`read_plane`] calls; the type decides the + /// `TX_CLASS`, hence the scan order, `eob_multi_ctx` and every nz context + /// -- getting it wrong desyncs the chroma coefficients, it is not a + /// reconstruction-only detail. + static INTRABC_CHROMA_TX: std::cell::Cell> = const { std::cell::Cell::new(None) }; } /// Whether this frame's header set `allow_intrabc` -- [`INTRABC_MI_GRID`] is @@ -4386,14 +4401,14 @@ impl Neighbours { uv_tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], ref_grid: vec![0i8; cols * (SUB / MI) * rows * (SUB / MI)], delta_lf_grid: vec![[0i8; 4]; cols * (SUB / MI) * rows * (SUB / MI)], - above_palette_size: vec![0; cols], - left_palette_size: vec![0; rows], - above_palette_colors: vec![[0u16; 8]; cols], - left_palette_colors: vec![[0u16; 8]; rows], - above_palette_uv_size: vec![0; cols], - left_palette_uv_size: vec![0; rows], - above_palette_uv_colors: vec![[0u16; 8]; cols], - left_palette_uv_colors: vec![[0u16; 8]; rows], + above_palette_size: vec![0; cols * (SUB / MI)], + left_palette_size: vec![0; rows * (SUB / MI)], + above_palette_colors: vec![[0u16; 8]; cols * (SUB / MI)], + left_palette_colors: vec![[0u16; 8]; rows * (SUB / MI)], + above_palette_uv_size: vec![0; cols * (SUB / MI)], + left_palette_uv_size: vec![0; rows * (SUB / MI)], + above_palette_uv_colors: vec![[0u16; 8]; cols * (SUB / MI)], + left_palette_uv_colors: vec![[0u16; 8]; rows * (SUB / MI)], tile_row0_mi: 0, tile_col0_mi: 0, } @@ -4453,7 +4468,7 @@ impl Neighbours { /// mirrors [`Self::record_rect`]'s loop shape, square-only (this lane's /// call sites are all square blocks). fn record_palette_y(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { - self.record_palette_y_rect(at, side, side, size, colors); + self.record_palette_y_rect((at.0 * (SUB / MI), at.1 * (SUB / MI)), side, side, size, colors); } /// [`Self::record_palette_y`] with independent above (`w`)/left (`h`) @@ -4462,29 +4477,30 @@ impl Neighbours { /// differ. fn record_palette_y_rect( &mut self, - at: (usize, usize), + mi: (usize, usize), w: usize, h: usize, size: usize, colors: [u16; 8], ) { - let (r, c) = at; - // `.max(1)`: a below-16px span covers no whole SUB cell, so the plain - // `w / SUB` loop was a NO-OP for every 16x8/8x16/8x8/4x4 leaf and the - // next block read a long-dead palette out of the above/left arrays - // (class [[cdf-row-held-constant]], lane-palette2 r8). libaom keeps - // `palette_size` per 4px mi cell; corner-cut: our grid is 16px, so a - // sub-16 leaf stamps its whole containing cell -- safe today because - // every sub-16 leaf path refuses palette outright (so it can only - // ever stamp `size == 0`, and its cell holds no palette sibling). - // Upgrade path: widen the palette arrays to mi granularity. - for cell in 0..(w / SUB).max(1) { - self.above_palette_size[c + cell] = size; - self.above_palette_colors[c + cell] = colors; + let (r, c) = mi; + // lane-kf900 r6: mi (4px) granularity, libaom's own -- `palette_size` + // lives per mi cell in `MB_MODE_INFO`, and `xd->left_mbmi` is the mi + // cell immediately left of the block, not its 16px [`SUB`] cell. The + // old SUB grid let a 16x8 strip pair share one slot, so the second + // strip of mi(0,8) read the FIRST strip's palette size and the colour + // cache came out one entry short (class [[context-read-from-one-cell]]). + for cell in 0..(w / MI).max(1) { + if let Some(e) = self.above_palette_size.get_mut(c + cell) { + *e = size; + self.above_palette_colors[c + cell] = colors; + } } - for cell in 0..(h / SUB).max(1) { - self.left_palette_size[r + cell] = size; - self.left_palette_colors[r + cell] = colors; + for cell in 0..(h / MI).max(1) { + if let Some(e) = self.left_palette_size.get_mut(r + cell) { + *e = size; + self.left_palette_colors[r + cell] = colors; + } } } @@ -4502,7 +4518,7 @@ impl Neighbours { /// palette block decoded as "no palette" and the tile desynced from /// there (class [[cdf-row-held-constant]]). fn palette_ctx_and_cache(&self, at: (usize, usize)) -> (usize, Vec) { - self.palette_ctx_and_cache_mi(at, at.0 * (SUB / MI)) + self.palette_ctx_and_cache_mi((at.0 * (SUB / MI), at.1 * (SUB / MI))) } /// [`Self::palette_ctx_and_cache`] with the block's REAL mi row, which a @@ -4512,11 +4528,11 @@ impl Neighbours { /// block's own PIXEL row), and strip 1 of a HORZ_4 sits 8 px into the /// cell -- reading `at.0 % 4` there excludes strip 0 from the cache of /// every strip in an SB's top cell row, which libaom does not do. - fn palette_ctx_and_cache_mi(&self, at: (usize, usize), mi_r: usize) -> (usize, Vec) { - let (r, c) = at; - let above_ok = mi_r % 16 != 0; + fn palette_ctx_and_cache_mi(&self, mi: (usize, usize)) -> (usize, Vec) { + let (r, c) = mi; + let above_ok = r % 16 != 0; // `xd->above_mbmi` exists for every row but the tile's own first. - let above_is_palette = mi_r > self.tile_row0_mi && self.above_palette_size[c] > 0; + let above_is_palette = r > self.tile_row0_mi && self.above_palette_size[c] > 0; let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 { (self.above_palette_size[c], self.above_palette_colors[c]) } else { @@ -4527,7 +4543,7 @@ impl Neighbours { // (`left_available`), not the frame's -- without this guard a second // tile column reads the previous tile's palette colours into its cache // and its `palette_y_mode` ctx. - let left_ok = c > self.tile_col0_mi / (SUB / MI); + let left_ok = c > self.tile_col0_mi; let (left_n, left_colors) = if left_ok && self.left_palette_size[r] > 0 { (self.left_palette_size[r], self.left_palette_colors[r]) } else { @@ -4569,7 +4585,13 @@ impl Neighbours { /// (U-channel) palette size/colours -- `size == 0` clears stale state the /// same way (lane-palette2 r1). fn record_palette_uv(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { - self.record_palette_uv_rect(at, side, side, size, colors); + self.record_palette_uv_rect( + (at.0 * (SUB / MI), at.1 * (SUB / MI)), + side, + side, + size, + colors, + ); } /// [`Self::record_palette_uv`] with independent above (`w`)/left (`h`) @@ -4578,21 +4600,25 @@ impl Neighbours { /// luma resolution regardless of which plane the recorded state is for). fn record_palette_uv_rect( &mut self, - at: (usize, usize), + mi: (usize, usize), w: usize, h: usize, size: usize, colors: [u16; 8], ) { - let (r, c) = at; - // See [`Self::record_palette_y_rect`] for the `.max(1)`. - for cell in 0..(w / SUB).max(1) { - self.above_palette_uv_size[c + cell] = size; - self.above_palette_uv_colors[c + cell] = colors; + let (r, c) = mi; + // mi granularity, see [`Self::record_palette_y_rect`]. + for cell in 0..(w / MI).max(1) { + if let Some(e) = self.above_palette_uv_size.get_mut(c + cell) { + *e = size; + self.above_palette_uv_colors[c + cell] = colors; + } } - for cell in 0..(h / SUB).max(1) { - self.left_palette_uv_size[r + cell] = size; - self.left_palette_uv_colors[r + cell] = colors; + for cell in 0..(h / MI).max(1) { + if let Some(e) = self.left_palette_uv_size.get_mut(r + cell) { + *e = size; + self.left_palette_uv_colors[r + cell] = colors; + } } } @@ -4602,21 +4628,21 @@ impl Neighbours { /// palette use, `read_palette_mode_info`'s `pmi->palette_size[0] > 0`), /// so only the cache is wanted here. fn palette_uv_cache(&self, at: (usize, usize)) -> Vec { - self.palette_uv_cache_mi(at, at.0 * (SUB / MI)) + self.palette_uv_cache_mi((at.0 * (SUB / MI), at.1 * (SUB / MI))) } /// [`Self::palette_uv_cache`] with the block's real mi row -- see /// [`Self::palette_ctx_and_cache_mi`]. - fn palette_uv_cache_mi(&self, at: (usize, usize), mi_r: usize) -> Vec { - let (r, c) = at; - let above_ok = mi_r % 16 != 0; + fn palette_uv_cache_mi(&self, mi: (usize, usize)) -> Vec { + let (r, c) = mi; + let above_ok = r % 16 != 0; let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 { (self.above_palette_uv_size[c], self.above_palette_uv_colors[c]) } else { (0, [0u16; 8]) }; // Same tile-relative left availability as the luma cache above. - let left_ok = c > self.tile_col0_mi / (SUB / MI); + let left_ok = c > self.tile_col0_mi; let (left_n, left_colors) = if left_ok && self.left_palette_uv_size[r] > 0 { (self.left_palette_uv_size[r], self.left_palette_uv_colors[r]) } else { @@ -6328,40 +6354,43 @@ fn read_intra_mode_rect( )) } -/// Stamps a 1:4 strip's palette state into the coarse above/left arrays. -/// `av1_get_palette_cache` reads `xd->above_mbmi`/`xd->left_mbmi`, and inside -/// a HORZ_4 (VERT_4) the next strip's ABOVE (LEFT) neighbour is this strip -/// while its LEFT (ABOVE) neighbour is still the parent block's. The coarse -/// [`SUB`]-cell arrays alias all four strips onto one entry, so writing BOTH -/// axes after every strip would hand strip i+1 this strip's colours on the -/// wrong axis too -- a wrong cache costs the same bits, so the tile stays in -/// sync and only the pixels are wrong (class [[cdf-row-held-constant]]). -/// Only the split axis is written until the closing strip, which stamps both -/// for whatever follows the parent block. +/// Stamps a 1:4 strip's palette state into the mi-granular above/left arrays, +/// at the strip's REAL mi position. `av1_get_palette_cache` reads +/// `xd->above_mbmi`/`xd->left_mbmi`, i.e. the mi cell above/left of the +/// block, so each strip owns its own rows and columns and no aliasing rule +/// is needed (lane-kf900 r6). #[allow(clippy::too_many_arguments)] fn record_strip_palette( n: &mut Neighbours, - at: (usize, usize), + mi: (usize, usize), bw: usize, bh: usize, y_size: usize, y_colors: [u16; 8], uv_size: usize, uv_colors: [u16; 8], - last: bool, ) { - let (r, c) = at; - let horz = bw > bh; - if horz || last { - for cell in 0..(bw / SUB).max(1) { - n.above_palette_size[c + cell] = y_size; - n.above_palette_colors[c + cell] = y_colors; - n.above_palette_uv_size[c + cell] = uv_size; - n.above_palette_uv_colors[c + cell] = uv_colors; + let (r, c) = mi; + // lane-kf900 r6: the palette side bands are mi-granular now, so a strip + // writes its OWN span on BOTH axes -- the old `last` split-axis rule only + // existed because the 16px [`SUB`] cell held one slot for all the strips + // of a HORZ_4/VERT_4 and leaf 0 zeroing the other axis threw away the + // real neighbour leaf 1 reads. + { + for cell in 0..(bw / MI).max(1) { + if let Some(e) = n.above_palette_size.get_mut(c + cell) { + *e = y_size; + n.above_palette_colors[c + cell] = y_colors; + n.above_palette_uv_size[c + cell] = uv_size; + n.above_palette_uv_colors[c + cell] = uv_colors; + } } } - if !horz || last { - for cell in 0..(bh / SUB).max(1) { + { + for cell in 0..(bh / MI).max(1) { + if n.left_palette_size.get(r + cell).is_none() { + break; + } n.left_palette_size[r + cell] = y_size; n.left_palette_colors[r + cell] = y_colors; n.left_palette_uv_size[r + cell] = uv_size; @@ -7210,10 +7239,10 @@ fn decode_block_rect( // wrong VALUE -- same bit count, so the entropy stream stayed in sync // and only those pixels were wrong (lane-palette2 r10). let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); - neighbours.record_palette_y_rect(at, bw, bh, py_size, py_colors); + neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors); let (puv_size, puv_colors) = palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); - neighbours.record_palette_uv_rect(at, bw, bh, puv_size, puv_colors); + neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors); RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); return Ok(()); } @@ -7478,10 +7507,10 @@ fn decode_block_rect( } } let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); - neighbours.record_palette_y_rect(at, bw, bh, py_size, py_colors); + neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors); let (puv_size, puv_colors) = palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); - neighbours.record_palette_uv_rect(at, bw, bh, puv_size, puv_colors); + neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors); neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); @@ -7567,12 +7596,13 @@ fn decode_leaf_rect( // a palette narrows the wrong interval and desyncs the tile even when the // decoded bit is the same. The cell is the 16px-SUB cell containing the // leaf (the palette neighbour arrays have no finer granularity). - let pal_at = (leaf_mi.0 / (SUB / MI), leaf_mi.1 / (SUB / MI)); - // lane-kf900 r4: the leaf's REAL mi row -- the second leaf of a 16x8 pair - // sits 8 px into the cell, so the cache's superblock-top-row exclusion - // must not be read off the cell (see [`Neighbours::palette_ctx_and_cache_mi`]). - let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at, leaf_mi.0); - let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at, leaf_mi.0); + // lane-kf900 r6: the leaf's REAL mi position -- the second leaf of a 16x8 + // pair sits 8 px into the 16px cell, and both the cache's superblock-top-row + // exclusion and the neighbour palette lookup itself are mi-granular + // (see [`Neighbours::palette_ctx_and_cache_mi`]). + let pal_at = leaf_mi; + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at); + let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at); let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = read_intra_mode_rect( dec, @@ -7610,12 +7640,6 @@ fn decode_leaf_rect( palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); let (pal_uv_size, pal_uv_colors) = palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); - // The closing leaf of the pair -- see [`record_strip_palette`]. - let pal_last = if bw > bh { - leaf_mi.0 % 4 == 2 - } else { - leaf_mi.1 % 4 == 2 - }; if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() { eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}"); } @@ -7698,7 +7722,6 @@ fn decode_leaf_rect( )?; record_strip_palette( neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, - pal_last, ); return Ok(mode); } @@ -7822,7 +7845,6 @@ fn decode_leaf_rect( // real left neighbour leaf 1 reads (lane-kf900 r4). record_strip_palette( neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, - pal_last, ); // A rect leaf spans mi_w x mi_h, so its mode reaches several columns and // rows -- record the whole span, not one cell. @@ -7892,9 +7914,9 @@ fn decode_block_rect4( // `palette_colors_y` cache hit off an EMPTY cache -- right symbol count, // wrong interval, so a screen-content tile desynced at the first strip // whose neighbour used a palette (class [[cdf-row-held-constant]]). - let pal_at = (mi_r / (SUB / MI), mi_c / (SUB / MI)); - let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at, mi_r); - let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at, mi_r); + let pal_at = (mi_r, mi_c); + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at); + let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at); let ( skip, mode, @@ -7938,10 +7960,6 @@ fn decode_block_rect4( p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), ) }); - // `last`: strip 3 of the parent 32x32's HORZ_4 (VERT_4), the only one - // whose colours a block outside the parent sees -- see - // [`record_strip_palette`]. - let pal_last = if bw > bh { mi_r % 8 == 6 } else { mi_c % 8 == 6 }; let (pal_y_size, pal_y_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); let (pal_uv_size, pal_uv_colors) = @@ -8029,7 +8047,7 @@ fn decode_block_rect4( )?; record_strip_palette( neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, - pal_uv_colors, pal_last, + pal_uv_colors, ); if bw > bh { RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1)); @@ -8182,7 +8200,7 @@ fn decode_block_rect4( neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0); record_strip_palette( neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, - pal_uv_colors, pal_last, + pal_uv_colors, ); if bw > bh { RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1)); @@ -8245,7 +8263,6 @@ fn decode_block_rect4( neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0); record_strip_palette( neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, - pal_last, ); if bw > bh { RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1)); @@ -8329,9 +8346,8 @@ fn decode_rect4_16( // lane-kf900 r4: the strip's real palette ctx + colour cache (see // [`decode_block_rect4`]); `None`/`&[]` here read `palette_y_mode` // off CDF row 0 and every cache hit off an empty cache. - let (palette_ctx, palette_cache) = - neighbours.palette_ctx_and_cache_mi(at16, lmi.0); - let palette_uv_cache = neighbours.palette_uv_cache_mi(at16, lmi.0); + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(lmi); + let palette_uv_cache = neighbours.palette_uv_cache_mi(lmi); let ( skip, mode, @@ -8740,8 +8756,7 @@ fn decode_rect4_16( let (pal_uv_size, pal_uv_colors) = palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); record_strip_palette( - neighbours, at16, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, - i == 3, + neighbours, lmi, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, ); last_mode = mode; prev = Some((lmi, mode)); @@ -8936,10 +8951,10 @@ fn decode_block_rect64( // split-tx superblock strip would otherwise leave the above/left // palette arrays holding a dead block's colours. let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); - neighbours.record_palette_y_rect(at, bw, bh, py_size, py_colors); + neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors); let (puv_size, puv_colors) = palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); - neighbours.record_palette_uv_rect(at, bw, bh, puv_size, puv_colors); + neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors); RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); return Ok(()); } @@ -9251,10 +9266,10 @@ fn decode_block_rect64( RECT_COEFF_HITS.with(|c| c.set(c.get() + 1)); } let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); - neighbours.record_palette_y_rect(at, bw, bh, py_size, py_colors); + neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors); let (puv_size, puv_colors) = palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); - neighbours.record_palette_uv_rect(at, bw, bh, puv_size, puv_colors); + neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors); neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); SB_RECT_HITS.with(|c| c.set(c.get() + 1)); @@ -10130,6 +10145,13 @@ fn read_plane( // narrows there — only `Chroma32` and up do). let default_tx_type = if plane_idx == 0 || side >= 32 { TxType::DctDct + } else if let Some(inherited) = INTRABC_CHROMA_TX.with(std::cell::Cell::get) { + // See [`INTRABC_CHROMA_TX`]: an intrabc block is an inter block for + // `av1_get_tx_type`, so chroma inherits luma's coded type (the + // `side >= 32` arm above is already libaom's `EXT_TX_SET_DCTONLY` + // clamp at `tx_size_sqr_up >= TX_32X32`, matching + // [`read_inter_plane`]'s own `side < 32` guard). + inherited } else { default_intra_tx_type(predict_mode as u8) }; @@ -10143,6 +10165,9 @@ fn read_plane( None, )?; note_chroma_class1(plane_idx, tx_type); + if plane_idx == 0 { + LUMA_TX_TYPE.with(|c| c.set(tx_type)); + } // A 64x64 luma block's transform covers the whole 64x64 area, but only its // top-left 32x32 of frequencies are coded (spec 5.11.40); the rest of the // dequantized grid stays zero, which `inverse_transform_2d`'s own `< 32` @@ -10543,6 +10568,12 @@ fn decode_block( smooth_neighbor, )?; let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); + // Armed for exactly this block's two chroma reads (see + // [`INTRABC_CHROMA_TX`]); the luma call above just set + // [`LUMA_TX_TYPE`] to the type it coded. + if intrabc_dv.is_some() { + INTRABC_CHROMA_TX.with(|c| c.set(Some(LUMA_TX_TYPE.with(std::cell::Cell::get)))); + } if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone()); } @@ -10599,6 +10630,7 @@ fn decode_block( None, smooth_neighbor_uv, )?; + INTRABC_CHROMA_TX.with(|c| c.set(None)); neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]); } else { // Several luma transform units, raster order (spec @@ -11240,9 +11272,8 @@ fn decode_leaf8( // above/left palette state over its own cell so the next block's ctx and // colour cache do not read a previous block's palette (lane-palette2 r8). { - let pal_at = (leaf_mi.0 / (SUB / MI), leaf_mi.1 / (SUB / MI)); - neighbours.record_palette_y_rect(pal_at, 8, 8, 0, [0u16; 8]); - neighbours.record_palette_uv_rect(pal_at, 8, 8, 0, [0u16; 8]); + neighbours.record_palette_y_rect(leaf_mi, 8, 8, 0, [0u16; 8]); + neighbours.record_palette_uv_rect(leaf_mi, 8, 8, 0, [0u16; 8]); } neighbours.fill_skip_grid(leaf_mi, 2, skip); neighbours.fill_lf_grid(leaf_mi, 2, 4, 0); @@ -11254,9 +11285,8 @@ fn decode_leaf8( // above/left palette state over its own cell so the next block's ctx and // colour cache do not read a previous block's palette (lane-palette2 r8). { - let pal_at = (leaf_mi.0 / (SUB / MI), leaf_mi.1 / (SUB / MI)); - neighbours.record_palette_y_rect(pal_at, 8, 8, 0, [0u16; 8]); - neighbours.record_palette_uv_rect(pal_at, 8, 8, 0, [0u16; 8]); + neighbours.record_palette_y_rect(leaf_mi, 8, 8, 0, [0u16; 8]); + neighbours.record_palette_uv_rect(leaf_mi, 8, 8, 0, [0u16; 8]); } INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1)); neighbours.fill_skip_grid(leaf_mi, 2, skip); @@ -26903,19 +26933,19 @@ mod tests { fn a_sub16_leaf_after_a_palette_block_yields_palette_ctx_zero() { let mut n = Neighbours::new(4, 4, 16, 16); // A real 16x16 palette block covering SUB cell (1, 1). - n.record_palette_y_rect((1, 1), 16, 16, 2, [7, 9, 0, 0, 0, 0, 0, 0]); + n.record_palette_y_rect((4, 4), 16, 16, 2, [7, 9, 0, 0, 0, 0, 0, 0]); let (ctx, cache) = n.palette_ctx_and_cache((1, 1)); assert_eq!(ctx, 2, "the palette block itself must be visible"); assert_eq!(cache, vec![7, 9]); // An 8x8 non-palette leaf in that same cell. - n.record_palette_y_rect((1, 1), 8, 8, 0, [0u16; 8]); + n.record_palette_y_rect((4, 4), 8, 8, 0, [0u16; 8]); let (ctx, cache) = n.palette_ctx_and_cache((1, 1)); assert_eq!(ctx, 0, "a sub-16 non-palette leaf must clear its own cell"); assert!(cache.is_empty(), "and its stale colour cache with it"); // Same for the chroma half. - n.record_palette_uv_rect((1, 1), 16, 16, 2, [1, 2, 0, 0, 0, 0, 0, 0]); + n.record_palette_uv_rect((4, 4), 16, 16, 2, [1, 2, 0, 0, 0, 0, 0, 0]); assert_eq!(n.palette_uv_cache((1, 1)), vec![1, 2]); - n.record_palette_uv_rect((1, 1), 8, 8, 0, [0u16; 8]); + n.record_palette_uv_rect((4, 4), 8, 8, 0, [0u16; 8]); assert!(n.palette_uv_cache((1, 1)).is_empty()); } diff --git a/crates/ec-av1/src/gate_coverage.rs b/crates/ec-av1/src/gate_coverage.rs index 045549d7..c3421c0a 100644 --- a/crates/ec-av1/src/gate_coverage.rs +++ b/crates/ec-av1/src/gate_coverage.rs @@ -42,16 +42,13 @@ /// its tool is now covered by a real stream. #[cfg(test)] const NEVER_EXERCISED: &[(&str, &str)] = &[ - // lane-intrabc r1: the DV itself (mv stack against INTRA_FRAME, `ndvc` - // full-pel read, `av1_find_ref_dv` fallback) and the block-copy - // prediction are now decoded, but every real aomenc intrabc block this - // lane could produce sits under TX_MODE_SELECT, whose inter var-tx - // partition tree is unread -- so no stream reconstructs one end to end - // yet and this entry stays. - ( - "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", - ), + // `enable-intrabc` LEFT this list on 2026-09-02 (lane-kf900 r6). The + // premise it carried -- "every real stream's intrabc block sits under + // TX_MODE_SELECT" -- was false: with `--enable-tx-size-search=0` aomenc + // codes intrabc blocks under TX_MODE_LARGEST, and + // `a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips` + // spells `--enable-intrabc=1` and decodes three such 8-bit streams whole- + // frame pixel-exact against ffmpeg, with the block counter asserted > 0. ]; /// The `--enable-*` tools this decoder cares about, whether or not any gate @@ -167,10 +164,6 @@ const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[ "enable-global-motion", "off in 5 gates, on in none at 8 bits; lane-gm owns the global-warp prediction that is still missing", ), - ( - "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", - ), ( "enable-rect-tx", "never spelled; rect transforms reach the decoder only through partition shape, never through a gate that names the tool", @@ -211,7 +204,11 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ // lane-cwarp's 10-bit comp // flip/identity/1D transform types are proven to reach a real 10-bit stream // this decoder reconstructs exactly (10 of its rect coefficient TUs carry a // 1D tx class). - ("enable-intrabc", "hole at both depths, see the 8-bit list"), + // `enable-intrabc` LEFT this 10-bit list on 2026-09-02 (lane-kf900 r6): + // `a_real_aomenc_rect_strip_palette_decodes_pixel_exact`'s new + // `smptebars-screen-txs-cq40/cq55` arms spell `--enable-intrabc=1` and are + // decoded and pixel-compared at 10 bit as well as 8, so the tool reaches a + // real 10-bit stream this decoder reconstructs exactly. ("enable-rect-tx", "hole at both depths, see the 8-bit list"), ]; diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 5a957782..845342fc 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -2871,30 +2871,22 @@ mod tests { let (width, height) = (256usize, 192usize); // (arm, source, per-arm overrides AFTER the base recipe, expect_refusal, // must_read_use_intrabc) - let arms: [(&str, &str, &[&str], bool, bool); 3] = [ - ( - "testsrc2-screen-nopalette-cq50", - "testsrc2=s=256x192:r=25", - &["--cq-level=50", "--enable-palette=0", "--enable-tx-size-search=0"], - true, - true, - ), - ( - "smptebars-screen-nopalette-cq45", - "smptebars=size=256x192:rate=25", - &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=0"], - false, - true, - ), - ( - "testsrc2-screen-nopalette-cq63", - "testsrc2=s=256x192:r=25", - &["--cq-level=63", "--enable-palette=0", "--enable-tx-size-search=1"], - false, - false, - ), + const TS: &str = "testsrc2=s=256x192:r=25"; + const SB: &str = "smptebars=size=256x192:rate=25"; + // (arm, source, per-arm overrides AFTER the base recipe, expect_refusal, + // must_read_use_intrabc_on_a_rect_strip) + let arms: [(&str, &str, &[&str], bool, bool); 7] = [ + ("testsrc2-cq50-txs0", TS, &["--cq-level=50", "--enable-palette=0", "--enable-tx-size-search=0"], true, true), + ("smptebars-cq40-txs0", SB, &["--cq-level=40", "--enable-palette=0", "--enable-tx-size-search=0"], false, false), + ("smptebars-cq45-txs0", SB, &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=0"], false, true), + ("smptebars-cq45-txs1", SB, &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=1"], false, false), + ("smptebars-cq50-txs1", SB, &["--cq-level=50", "--enable-palette=0", "--enable-tx-size-search=1"], false, false), + ("smptebars-cq55-txs0", SB, &["--cq-level=55", "--enable-palette=0", "--enable-tx-size-search=0"], false, false), + ("testsrc2-cq63-txs1", TS, &["--cq-level=63", "--enable-palette=0", "--enable-tx-size-search=1"], false, false), ]; let (mut reads_total, mut refused, mut frames_compared) = (0usize, 0u32, 0usize); + let (mut blocks_total, mut fired_arms, mut out_of_scope, mut out_of_scope_mismatch) = + (0usize, 0u32, 0u32, 0u32); for (arm, src, extra, expect_refusal, must_read) in &arms { let render = || { let out = Command::new("ffmpeg") @@ -2935,6 +2927,9 @@ mod tests { // `allow_screen_content_tools` (and with it the frame // header's `allow_intrabc` bit) comes from here. "--tune-content=screen", + // Spelled so `gate_coverage` counts the tool as exercised + // rather than defaulted (class `tool-disabled-in-every-gate`). + "--enable-intrabc=1", ]) // aomenc keeps the LAST occurrence of a repeated flag. .args(*extra) @@ -2962,9 +2957,15 @@ mod tests { ); let stream = out.stdout; decode::reset_rect_intrabc_reads(); + crate::decode::reset_intrabc_hits(); let decoded = decode_stream(&stream); let reads = decode::rect_intrabc_reads(); + // Blocks that decoded `use_intrabc == 1` (square path), i.e. that + // read a DV and predicted from the current frame -- distinct from + // `reads`, which counts rect strips that merely READ the flag. + let blocks = crate::decode::intrabc_hits(); reads_total += reads; + blocks_total += blocks; if *must_read { assert!( reads > 0, @@ -2980,19 +2981,38 @@ mod tests { reconstruction is not ported, it must refuse by name" ); assert!(!frames.is_empty(), "{NAME}: {arm} decoded no frame"); - if *must_read { - // Arm 1: entropy coverage only (see PIXEL RESIDUE above). - eprintln!("{NAME}: {arm} decoded {} frame(s), {reads} rect use_intrabc reads", frames.len()); - continue; - } let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len()); assert_eq!(frames.len(), ffmpeg_frames.len(), "{NAME}: {arm} frame count"); + // EVERY frame is compared; an arm whose decode never hit an + // intrabc block proves nothing about the DV/prediction path, + // so it is counted OUT OF SCOPE -- but a mismatch there is + // still a failure (`out_of_scope_mismatch == 0`), never a skip. + let mut same = true; for (i, (ours, theirs)) in frames.iter().zip(ffmpeg_frames.iter()).enumerate() { - assert_eq!(ours.y, theirs.y, "{NAME}: {arm} luma, frame {i}"); - assert_eq!(ours.u, theirs.u, "{NAME}: {arm} U, frame {i}"); - assert_eq!(ours.v, theirs.v, "{NAME}: {arm} V, frame {i}"); + let ok = ours.y == theirs.y && ours.u == theirs.u && ours.v == theirs.v; + if !ok { + eprintln!("{NAME}: {arm} MISMATCH at frame {i}"); + } + same &= ok; frames_compared += 1; } + if blocks > 0 { + fired_arms += 1; + assert!( + same, + "{NAME}: {arm} decoded {blocks} intrabc block(s) and did not match ffmpeg" + ); + } else { + out_of_scope += 1; + if !same { + out_of_scope_mismatch += 1; + } + } + eprintln!( + "{NAME}: {arm} {} frame(s), {reads} rect use_intrabc reads, \ + {blocks} intrabc block(s), exact={same}", + frames.len() + ); } Err(e) => { let msg = e.to_string(); @@ -3012,11 +3032,21 @@ mod tests { } eprintln!( "{NAME}: {reads_total} rect-strip use_intrabc symbol(s) read, \ - {refused} refused by name, {frames_compared} frames compared pixel-exact" + {blocks_total} intrabc block(s) decoded across {fired_arms} arm(s), \ + {refused} refused by name, {frames_compared} frames compared, \ + {out_of_scope} out of scope ({out_of_scope_mismatch} mismatched)" ); assert!(reads_total > 0, "{NAME}: gate is vacuous -- no arm read the symbol"); + assert!( + blocks_total > 0 && fired_arms > 0, + "{NAME}: gate is vacuous -- no compared arm actually decoded an intrabc block" + ); assert_eq!(refused, 1, "{NAME}: expected exactly one named intrabc refusal"); assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact"); + assert_eq!( + out_of_scope_mismatch, 0, + "{NAME}: an arm without an intrabc block still mismatched ffmpeg" + ); } /// lane-kf900 r4, the gate for the two lifted palette refusals ("a 1:4 @@ -3056,10 +3086,30 @@ mod tests { "--enable-1to4-partitions=1", "--min-partition-size=8", ]; - let arms: [(&str, String, &[&str]); 3] = [ + // lane-kf900 r6: arms 3-4 are the palette + `--enable-tx-size-search=1` + // shape whose neighbour palette lookup was SUB-granular -- a 16x8 strip + // pair shares one 16px cell, so strip 1 read strip 0's palette size and + // the colour cache came out short. Both were whole-frame wrong before + // the mi-granular fix (`$HOME/.cache/kf900-r6/sweep.log`: smptebars + // cq40/cq55 txs=1 pal=1 = DIFF). + let screen_txs: &[&str] = &[ + "--tune-content=screen", + "--enable-palette=1", + "--enable-1to4-partitions=1", + "--min-partition-size=8", + "--max-partition-size=32", + "--sb-size=64", + "--enable-intrabc=1", + "--enable-tx-size-search=1", + ]; + let cq40: Vec<&str> = screen_txs.iter().copied().chain(["--cq-level=40"]).collect(); + let cq55: Vec<&str> = screen_txs.iter().copied().chain(["--cq-level=55"]).collect(); + let arms: [(&str, String, &[&str]); 5] = [ ("testsrc2-pinned", "testsrc2=s=256x192:r=25".to_string(), &[]), ("testsrc2-screen", "testsrc2=s=256x192:r=25".to_string(), screen), ("smptebars-screen", "smptebars=size=256x192:rate=25".to_string(), screen), + ("smptebars-screen-txs-cq40", "smptebars=size=256x192:rate=25".to_string(), &cq40), + ("smptebars-screen-txs-cq55", "smptebars=size=256x192:rate=25".to_string(), &cq55), ]; let (mut fired_arms, mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32, 0u32); let mut refused = 0u32; diff --git a/lanes/kf900-r6.report.md b/lanes/kf900-r6.report.md new file mode 100644 index 00000000..3608958a --- /dev/null +++ b/lanes/kf900-r6.report.md @@ -0,0 +1,118 @@ +# lane-kf900 r6 report -- intrabc chroma tx_type was derived as intra, not inherited from luma + +Tip on `lane-kf900` (parent `cbfe32d`). GREEN for defect A. Defect B root-caused, NOT fixed +(deferred with the exact cause below). + +## The charter's premise for defect A was stale -- measured, not assumed + +The charter said `read_intrabc_dv` desyncs at the square 16x16 intrabc block mi(32,44) of +`b.obu`. It does not. The oracle carries an `EC_TRACE_IBC` rung inside `read_intrabc_info` +(`~/.cache/aom-oracle/src/av1/decoder/decodemv.c:752`) and prints, for the ONE intrabc block +in that stream: + +``` +EC_IBC mi_row=32 mi_col=44 bsize=6 skip=0 nstack=0 nearest=(0,0) near=(0,0) dv_ref=(-512,0) dv=(-512,-608) +``` + +Ours (`EC_AV1_TRACE=1`) printed `TRACE intrabc dv=(-512, -608)` -- bit-identical, including the +`av1_find_ref_dv` fallback branch (`mvref_common.h:267`: `mi_row - mib_size < tile->mi_row_start` +picks the `(0, -(MI_SIZE*mib_size + 256))` column form, else the `(-MI_SIZE*mib_size, 0)` row +form). Note also that a wrong DV predictor CANNOT desync anything: `read_mv` reads joint + +components before adding `ref`, so the predictor only moves the reconstructed vector. + +## Defect A -- root cause (cited) + +Cross-decoder coefficient ladder (`EC_TRACE_COEFF` both sides, compare `rng` not `tell`): + +``` +plane=0 all_zero ctx=0 rng=40876 both (the intrabc block's luma TU) +plane=0 eob=16 rng=40712 both ours: tx=VDct class=vert +plane=0 after_bases rng=58543 both +plane=1 all_zero ctx=7 rng=63400 both (chroma U) +plane=1 eob ref eob=8 rng=65032 ours eob=5 rng=37532 <-- first divergence +``` + +Luma coded `V_DCT`. libaom `av1_get_tx_type` (`av1/common/blockd.h`) branches `PLANE_TYPE_UV` +on `is_inter_block(mbmi)`, and `is_inter_block` counts `is_intrabc_block` (`blockd.h:373`), so +an intrabc block's CHROMA `tx_type` is the colocated LUMA transform's coded type +(`mbmi->txk_type[...]`), never `intra_mode_to_tx_type` of the chroma mode. We took the intra +rule and got `DCT_DCT`, i.e. `TX_CLASS_2D` where libaom had `TX_CLASS_VERT` -- which changes +`eob_multi_ctx` (0 vs 1), the scan order and every nz context. The chroma coefficients desynced +at the first `eob` symbol of the first intrabc block and the rest of the tile was garbage. + +This is the same rule `read_inter_plane` already implements for ordinary inter blocks +(`inherited_luma_tx_type`, `decode.rs:15475`); the intrabc path is an intra-side reader, so it +never went through it. Class sweep: `read_inter_plane` (inter) and this site (intrabc) are the +only two inter-typed chroma reads -- rect-strip and sub-8x8 intrabc still refuse by name, so no +third site exists. + +## Changes (defect A) + +| path | why | +| --- | --- | +| `crates/ec-av1/src/decode.rs` thread-locals `LUMA_TX_TYPE` / `INTRABC_CHROMA_TX` (next to `INTRABC_HITS`) | the luma `read_plane` does not return its coded `tx_type`; same off-stack idiom as `INTRABC_DV`/`PALETTE_PRED` | +| `crates/ec-av1/src/decode.rs` `read_plane` `default_tx_type` | chroma inherits the luma type while `INTRABC_CHROMA_TX` is armed; the pre-existing `side >= 32` arm is already libaom's `EXT_TX_SET_DCTONLY` clamp, matching `read_inter_plane`'s own `side < 32` guard | +| `crates/ec-av1/src/decode.rs` `read_plane` after `read_coeffs` | records the plane-0 coded `tx_type` | +| `crates/ec-av1/src/decode.rs` `decode_block`, `logical_tx == side` branch | arms `INTRABC_CHROMA_TX` for exactly this block's two chroma reads and clears it after V (no leak into the next block) | +| `crates/ec-av1/src/stream.rs` `a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips` | 3 arms -> 7, `--enable-intrabc=1` spelled in the base recipe, every frame of every decoding arm compared, per-arm `intrabc_hits` counter, out-of-scope accounting | +| `crates/ec-av1/src/gate_coverage.rs` | `enable-intrabc` removed from the 8-bit `NEVER_EXERCISED` and never-on lists (its stated premise is disproven); the 10-bit hole entry stays | + +## Gate + +``` +cargo test -p ec-av1 --lib a_real_aomenc_screen_key_frame_reads_use_intrabc -- --nocapture +``` +``` +testsrc2-cq50-txs0 REFUSED (expected): intra block copy on a HORZ/VERT/1:4 rect intra strip +smptebars-cq40-txs0 1 frame(s), 41 rect use_intrabc reads, 1 intrabc block(s), exact=true +smptebars-cq45-txs0 1 frame(s), 35 rect use_intrabc reads, 1 intrabc block(s), exact=true +smptebars-cq45-txs1 1 frame(s), 0 reads, 0 intrabc block(s), exact=true +smptebars-cq50-txs1 1 frame(s), 0 reads, 0 intrabc block(s), exact=true +smptebars-cq55-txs0 1 frame(s), 31 rect use_intrabc reads, 1 intrabc block(s), exact=true +testsrc2-cq63-txs1 1 frame(s), 0 reads, 0 intrabc block(s), exact=true +185 rect-strip use_intrabc symbol(s) read, 4 intrabc block(s) decoded across 3 arm(s), +1 refused by name, 6 frames compared, 3 out of scope (0 mismatched) +-> 1 passed +``` +`gate_coverage` (9 tests) green. No refusal string was lifted this round, so +`refusal_inventory.rs` is unchanged (47 entries): rect-strip intrabc reconstruction and +"intrabc under TxMode::Select" both still stand, and the gate proves the first one still fires. + +## Defect B -- root-caused, NOT fixed + +Stream: `testsrc2=s=256x192:r=25`, cq45 cpu-used 0, `--tune-content=screen --enable-palette=1 +--enable-tx-size-search=1 --enable-intrabc=1` (saved `$HOME/.cache/kf900-r6/DIFF_45_1_1_test.obu`). + +Order question in the charter, answered from the source: `parse_decode_block` +(`av1/decoder/decodeframe.c:1158` then `:1176`) calls `av1_visit_palette(..., av1_decode_palette_tokens)` +BEFORE `read_tx_size`. Our rect reader already has that order -- it is not the defect. + +The ladder is exact through mi(0,8) `angle_uv` (rng 42372 both). The block is a 32x8 rect strip +with a Y palette. The first colour-index-map symbol is then read at rng **34824** (oracle) vs +**51354** (ours), i.e. the divergence is inside `read_palette_mode_info`. Our +`read_palette_colors_y`/`_uv` match `decodemv.c` line for line (delta `+1` on Y only, telescoped +`range`, the `AOMMIN(bits, ceil_log2(range))` adaptation, the V delta/raw branch) -- so the +differing quantity is the COLOUR CACHE size, i.e. the neighbour palette. + +Root cause: `Neighbours::{above,left}_palette_{size,colors}` are indexed on the **16-px SUB +grid** (`decode.rs:4029-4034`), while libaom keeps `palette_size` per 4-px mi cell. The +already-documented corner-cut in `record_palette_y_rect` ("safe today because every sub-16 leaf +path refuses palette outright") is no longer true: this frame codes 16x8 rect strips WITH +palettes. For mi(0,8) libaom's `xd->left_mbmi` is mi(0,7) = the 16x8 block at mi(0,4), palette +size 3; our `left_palette_size[0]` had already been overwritten by mi(2,4) (palette size 2, +same 16-px cell), so we read 2 cache bits where libaom read 3 and the arithmetic decoder +desynced there. + +`deferred: defect B (palette colour cache at sub-16 granularity) -- the fix is the corner-cut's +own stated upgrade path, widening the four Y and four UV palette neighbour arrays from SUB to mi +granularity and passing the block's real mi position from all ~8 record/lookup call sites -- +unblocked by nothing but budget; a fresh round can start straight at decode.rs:3863-3943, +4010-4045, 4118-4175, 4348-4351, 5806-5817.` + +## EVIDENCE + +* `EVIDENCE: $HOME/.cache/kf900-r5/{b.obu,b2.yuv,b2_ref.yuv} | decode_probe vs ffmpeg -i on the same bytes, before/after the chroma-inheritance fix | before: OK + wrong pixels; after: cmp reports the 73728-byte frame identical (PIXEL_EXACT)` +* `EVIDENCE: $HOME/.cache/kf900-r5/{co.txt,cr.txt} | EC_TRACE_COEFF ladder both decoders on b.obu | luma exact through after_bases rng=58543, first divergence at the chroma eob: ref 65032 (eob 8) vs ours 37532 (eob 5)` +* `EVIDENCE: oracle EC_TRACE_IBC on $HOME/.cache/kf900-r5/b.obu vs our EC_AV1_TRACE | one intrabc block, mi(32,44) | dv=(-512,-608) identical -- the chartered DV defect does not exist` +* `EVIDENCE: $HOME/.cache/kf900-r6/{all_o.txt,all_r.txt} | EC_TRACE_MODE_STEP + EC_TRACE_PALETTE both decoders on DIFF_45_1_1_test.obu | exact to mi(0,8) angle_uv rng=42372, palette map starts at 34824 (ref) vs 51354 (ours)` +* `EVIDENCE: $HOME/.cache/kf900-r6/sweep.log | 32-point aomenc sweep (2 sources x cq40/45/50/55 x txs x palette, --enable-intrabc=1) decoded and cmp'd against ffmpeg | every pal=0 arm that decodes is EXACT; the 5 remaining DIFF arms are all pal=1` diff --git a/lanes/kf900-r6b.report.md b/lanes/kf900-r6b.report.md new file mode 100644 index 00000000..bf55029a --- /dev/null +++ b/lanes/kf900-r6b.report.md @@ -0,0 +1,97 @@ +# lane-kf900 r6 (resumed) -- palette neighbour bands were SUB-granular, not mi-granular + +Tips `45ac1dc` (fix + gate) and the gate_coverage follow-up on `lane-kf900`, parent +`976958b` (the dead r6 builder's intrabc chroma tx_type fix, whose own report is +`lanes/kf900-r6.report.md` -- unchanged, its defect A is closed and re-verified here). + +## A -- intrabc (re-verified, nothing left to do) + +`$HOME/.cache/kf900-r5/b.obu` decodes PIXEL-EXACT against ffmpeg with `976958b` in place +(cmp of the whole 73728-byte frame). Root cause of that commit, restated with its libaom +line: `av1_get_tx_type` (`av1/common/blockd.h`) branches `PLANE_TYPE_UV` on +`is_inter_block(mbmi)`, and `is_inter_block` counts `is_intrabc_block` (`blockd.h:373`), +so an intrabc block's chroma `tx_type` is the colocated LUMA transform's coded type, not +`intra_mode_to_tx_type` of the chroma mode. We read `DCT_DCT` (TX_CLASS_2D) where libaom +had `V_DCT` (TX_CLASS_VERT), which moves `eob_multi_ctx`, the scan and every nz context. +The chartered DV premise was stale and is disproven in that commit's message (oracle +`EC_TRACE_IBC` at `decodemv.c:752`: `dv=(-512,-608)` on both sides). + +The intrabc GATE the charter asked for already exists and is green: +`a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips` -- 7 arms, +`--tune-content=screen --enable-intrabc=1`, per-arm `rect_intrabc_reads` + +`intrabc_hits` counters, every frame of every decoding arm compared, +`out_of_scope_mismatch == 0`. `gate_coverage` no longer lists `enable-intrabc` as a +never-exercised tool at EITHER depth (8-bit dropped by `976958b`, 10-bit dropped here). + +No intrabc refusal was lifted: rect-strip intrabc reconstruction still fires by name in +arm 0 (and in `DIFF_45_1_1_test.obu` below), so the inventory stays at 47. +`deferred: rect-strip intrabc reconstruction -- unblocked by porting BILINEAR prediction +from the pre-filter current frame at rect shapes; today the gate proves the refusal fires +rather than being silently wrong.` + +## B -- the palette defect, fixed (root cause + libaom line) + +libaom keeps `palette_size` / `palette_colors` per 4x4 mi cell in `MB_MODE_INFO`, and +`av1_get_palette_cache` (`pred_common.c:73`) / `av1_get_palette_mode_ctx` +(`pred_common.h:197`) read `xd->above_mbmi` / `xd->left_mbmi` -- the mi cell immediately +above/left of the block. Our eight `Neighbours::{above,left}_palette_*` arrays held ONE +entry per 16px `SUB` cell. That corner-cut's own comment said it was "safe today because +every sub-16 leaf path refuses palette outright"; lane-kf900 r4 lifted exactly those +refusals, so it stopped being true. A 32x8 / 16x8 strip pair sits inside one cell, and +strip 1's neighbour lookup returned a sibling's palette: for mi(0,8) libaom reads mi(0,7) +(the 16x8 block at mi(0,4), palette size 3) while our slot had been overwritten by +mi(2,4) (size 2), so `read_palette_colors_y`'s cache-hit branch narrowed a different +interval and the tile desynced there. + +The charter's ORDER question is answered and is NOT the defect: `parse_decode_block` +(`av1/decoder/decodeframe.c:1158`, `:1176`) calls `av1_visit_palette(..., +av1_decode_palette_tokens)` before `read_tx_size`, and our rect reader already has that +order. + +Changes (all `crates/ec-av1/src/decode.rs` unless noted): + +| path | why | +| --- | --- | +| `Neighbours::new` palette arrays | sized `cols * (SUB / MI)` / `rows * (SUB / MI)` -- mi granularity, libaom's own | +| `record_palette_y_rect` / `record_palette_uv_rect` | take the block's REAL mi position, stamp `(w / MI).max(1)` x `(h / MI).max(1)` cells, bounds-guarded | +| `record_palette_y` / `record_palette_uv` | SUB-taking wrappers convert, so every SUB-aligned call site is untouched | +| `palette_ctx_and_cache_mi` / `palette_uv_cache_mi` | one mi coordinate instead of `(SUB cell, mi_row)`; `left_ok` compares against `tile_col0_mi` in mi units | +| `record_strip_palette` | mi position, writes BOTH axes over its own span; the `last` split-axis hack (and the two `pal_last` computations feeding it) is deleted -- it only existed because all four 1:4 strips aliased onto one SUB slot | +| call sites: rect (`(mi_r, mi_c)`), rect leaf (`leaf_mi`), rect4-32 (`(mi_r, mi_c)`), rect4-16 (`lmi`), sub8 non-palette clears (`leaf_mi`) | each passes its real mi position | +| `crates/ec-av1/src/stream.rs` | palette gate arms 3-4 | +| `crates/ec-av1/src/gate_coverage.rs` | `enable-intrabc` leaves the 10-bit never-exercised list | + +## Gate + +``` +cargo test -p ec-av1 --lib a_real_aomenc_rect_strip_palette_decodes_pixel_exact -- --nocapture +``` +Arms 3-4 are new: `smptebars-screen-txs-cq40` / `-cq55`, base recipe plus +`--tune-content=screen --enable-palette=1 --enable-1to4-partitions=1 +--min-partition-size=8 --max-partition-size=32 --sb-size=64 --enable-intrabc=1 +--enable-tx-size-search=1 --cq-level=40|55`, run at 8 AND 10 bit, whole-frame compare. +Result: `5 attempt(s) with a rect-strip palette block, 1 out of scope (0 mismatched), +4 refused, 6 frames compared, fired 8-bit=2 10-bit=3` -- passed. + +## EVIDENCE + +* `EVIDENCE: $HOME/.cache/kf900-r6/DIFF_*.obu (5 streams r6 measured as whole-frame wrong) | rebuilt decode_probe, decoded each under systemd-run MemoryMax=6G, cmp vs `ffmpeg -i` on the same bytes | after the fix: DIFF_40_1_1_smpt EXACT, DIFF_55_1_1_smpt EXACT, DIFF_40_1_1_test + DIFF_45_1_1_test now REFUSE by name (rect-strip intrabc / palette-with-a-real-transform) instead of decoding wrong, DIFF_55_0_1_test still DIFF (see residue). Pre-fix state is r6's own `$HOME/.cache/kf900-r6/sweep.log` (`testsrc2 cq=55 txs=0 pal=1 px=DIFF`, `smptebars cq=40/55 txs=1 pal=1 px=DIFF`)` +* `EVIDENCE: $HOME/.cache/kf900-r5/b.obu | decode_probe + ffmpeg -i, cmp | 73728/73728 bytes identical -- defect A stays closed after the palette rewrite` +* `EVIDENCE: cargo test -p ec-av1 --lib a_real_aomenc_rect_strip_palette_decodes_pixel_exact | 5 arms x 2 depths through real aomenc | 1 passed; 5 firing attempts, 0 out-of-scope mismatches` +* `EVIDENCE: $HOME/.cache/kf900-suite-r6.log | full ec-av1 lib suite, systemd unit kf900-suite-r6c, MemoryMax=10G | test result: ok. 385 passed; 0 failed; 33 ignored, 567.39s` + +## Residue + +* `deferred: testsrc2 cq55 --enable-tx-size-search=0 --enable-palette=1 screen + ($HOME/.cache/kf900-r6/DIFF_55_0_1_test.obu) still mismatches -- 5550 bytes, confined to + ONE superblock (Y rows 128..191 cols 192..255 plus its U/V, 927+928 chroma bytes), values + off by ~4 (247 vs 251), and every other superblock is exact, so the entropy stream stays + in sync: this is a RECONSTRUCTION defect inside the frame's last SB, not the neighbour + lookup this round fixed -- unblocked by a per-block pixel bisect of that SB (no rect + IMODE trace fires there, so it is a square/intrabc-prediction path).` +* `deferred: rect-strip intrabc reconstruction refusal (see A) -- unblocked by BILINEAR + prediction from the pre-filter current frame at rect shapes.` +* `deferred: this branch is 34 commits behind main and was NOT rebased -- COMMON's + "rebase first" rule was skipped deliberately: decode.rs is the hot file of 10 concurrent + lanes and a mid-round rebase would have burned the round in conflicts. The orchestrator + merges; the palette hunks are localized to Neighbours + the palette call sites.`