forge
Explore
Log in

Don't you dare go Hollow

wip(av1): r23 palette on sub-8x8 leaves / 128-root screen strip, partial (committed by the orchestrator at the builder's turn cap)

Browse files at this commit

4b093b12a344429ca94b1cb700f1b5ca0f881eedAhmet Kaan GümüşParent: 2b9468d
crates/ec-av1/src/decode.rsmodified+175 -11
@@ -1737,6 +1737,20 @@ thread_local! {
1737 static INTRA_IN_INTER_PALETTE_UV_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };1737 static INTRA_IN_INTER_PALETTE_UV_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1738 }1738 }
1739 1739
1740+// lane-t900 r23: as [`INTRA_IN_INTER_PALETTE_Y_HITS`], narrowed to the 8x8
1741+// LEAF site ([`decode_inter_block8`]'s intra arm) -- the >=16 site fires the
1742+// shared counter too, so only this one proves a gate really reached the leaf
1743+// where the refusal used to sit.
1744+thread_local! {
1745+ static INTER8_PALETTE_HITS: std::cell::Cell<(usize, usize)> =
1746+ const { std::cell::Cell::new((0, 0)) };
1747+}
1748+
1749+/// Current values of the 8x8-leaf intra-in-inter palette counters, `(y, uv)`.
1750+pub(crate) fn inter8_palette_hits() -> (usize, usize) {
1751+ INTER8_PALETTE_HITS.with(std::cell::Cell::get)
1752+}
1753+
1740 /// Current values of the two intra-in-inter palette counters, `(y, uv)`.1754 /// Current values of the two intra-in-inter palette counters, `(y, uv)`.
1741 pub(crate) fn intra_in_inter_palette_hits() -> (usize, usize) {1755 pub(crate) fn intra_in_inter_palette_hits() -> (usize, usize) {
1742 (1756 (
@@ -5016,6 +5030,9 @@ impl Neighbours {
5016 colors: [u16; 8],5030 colors: [u16; 8],
5017 ) {5031 ) {
5018 let (r, c) = mi;5032 let (r, c) = mi;
5033+ if crate::envflags::env_flag!("EC_PALPUB") {
5034+ eprintln!("EC_PALPUB yrect mi={r},{c} bw={w} bh={h} y={size}");
5035+ }
5019 // lane-kf900 r6: mi (4px) granularity, libaom's own -- `palette_size`5036 // lane-kf900 r6: mi (4px) granularity, libaom's own -- `palette_size`
5020 // lives per mi cell in `MB_MODE_INFO`, and `xd->left_mbmi` is the mi5037 // lives per mi cell in `MB_MODE_INFO`, and `xd->left_mbmi` is the mi
5021 // cell immediately left of the block, not its 16px [`SUB`] cell. The5038 // cell immediately left of the block, not its 16px [`SUB`] cell. The
@@ -7023,6 +7040,13 @@ fn record_strip_palette(
7023 uv_colors: [u16; 8],7040 uv_colors: [u16; 8],
7024 ) {7041 ) {
7025 let (r, c) = mi;7042 let (r, c) = mi;
7043+ // lane-t900 r23 rung: every publication of a block's palette state into
7044+ // the neighbour bands (`EC_PALPUB=1`) -- the rung that names which decode
7045+ // path left a stale `left_palette_size` behind when
7046+ // `av1_get_palette_mode_ctx` disagrees with libaom's.
7047+ if crate::envflags::env_flag!("EC_PALPUB") {
7048+ eprintln!("EC_PALPUB strip mi={r},{c} bw={bw} bh={bh} y={y_size} uv={uv_size}");
7049+ }
7026 // lane-kf900 r6: the palette side bands are mi-granular now, so a strip7050 // lane-kf900 r6: the palette side bands are mi-granular now, so a strip
7027 // writes its OWN span on BOTH axes -- the old `last` split-axis rule only7051 // writes its OWN span on BOTH axes -- the old `last` split-axis rule only
7028 // existed because the 16px [`SUB`] cell held one slot for all the strips7052 // existed because the 16px [`SUB`] cell held one slot for all the strips
@@ -25901,6 +25925,11 @@ fn decode_inter_block8(
25901 // neighbour (`Neighbours`' arrays only move once per 16x16 block).25925 // neighbour (`Neighbours`' arrays only move once per 16x16 block).
25902 // `(0, None)` is intra.25926 // `(0, None)` is intra.
25903 let mut leaf_refs: (i8, Option<i8>) = (0, None);25927 let mut leaf_refs: (i8, Option<i8>) = (0, None);
25928+ // lane-t900 r23: this leaf's own palette state for the neighbour bands
25929+ // (`(y_size, y_colors, uv_size, uv_colors)`), all-zero for an inter leaf
25930+ // and for an intra one that codes no palette -- same publication the
25931+ // >=16 intra-in-inter block makes through [`record_strip_palette`].
25932+ let mut palette_record8: (usize, [u16; 8], usize, [u16; 8]) = (0, [0u16; 8], 0, [0u16; 8]);
25904 if is_inter {25933 if is_inter {
25905 if reference_select || skip_mode {25934 if reference_select || skip_mode {
25906 // lane-inter8 r1: the REAL neighbour references, not a25935 // lane-inter8 r1: the REAL neighbour references, not a
@@ -26526,6 +26555,21 @@ fn decode_inter_block8(
26526 ],26555 ],
26527 )26556 )
26528 });26557 });
26558+ // lane-t900 r23: every leaf stamps its palette state (all-zero for an
26559+ // inter leaf or a non-palette intra one, real for a palette block) into
26560+ // the mi-granular neighbour bands, so the next intra block's
26561+ // `av1_get_palette_mode_ctx` and colour cache see exactly what libaom's
26562+ // mode-info grid holds.
26563+ record_strip_palette(
26564+ neighbours,
26565+ leaf_mi,
26566+ 8,
26567+ 8,
26568+ palette_record8.0,
26569+ palette_record8.1,
26570+ palette_record8.2,
26571+ palette_record8.3,
26572+ );
26529 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);26573 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
26530 if let Some((left, above)) = saved_luma_ctx {26574 if let Some((left, above)) = saved_luma_ctx {
26531 for (cell, state) in left.into_iter().enumerate() {26575 for (cell, state) in left.into_iter().enumerate() {
@@ -27204,19 +27248,47 @@ fn decode_inter_block8(
27204 // leaf (a nonzero `mode` still passes, but `uv_mode` is forced27248 // leaf (a nonzero `mode` still passes, but `uv_mode` is forced
27205 // `DC_PRED` by the refusal just above), same order as libaom's27249 // `DC_PRED` by the refusal just above), same order as libaom's
27206 // `read_palette_mode_info` call right after `xd->cfl.store_y`.27250 // `read_palette_mode_info` call right after `xd->cfl.store_y`.
27207- if allow_screen_content_tools {27251+ // lane-t900 r23: reconstructed, not refused. Same syntax, same
27208- if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[0][0]) != 0 {27252+ // deferral of the colour-index maps past `use_filter_intra`
27209- return Err(unsupported(27253+ // (`av1_visit_palette` runs from `parse_decode_block`, after the whole
27210- "a block that actually uses a palette (Y) -- reconstruction is out of scope",27254+ // mode-info read) as the >=16 intra-in-inter block's own copy in
27211- ));27255+ // [`decode_inter_block`]; the mode context, the colour cache and the
27256+ // `palette_uv_mode` context are this leaf's REAL ones, not the
27257+ // hardcoded 0/empty pair the refusal could get away with while no
27258+ // neighbour could ever be a palette (class
27259+ // [[cdf-row-held-constant]]). `av1_get_palette_bsize_ctx(BLOCK_8X8)`
27260+ // = `num_pels_log2_lookup[BLOCK_8X8] - 6` = row 0.
27261+ let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(leaf_mi);
27262+ let palette_uv_cache = neighbours.palette_uv_cache_mi(leaf_mi);
27263+ let mut palette_y_pending: Option<(usize, [u16; 8])> = None;
27264+ let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None;
27265+ if allow_screen_content_tools
27266+ && let Some(bsize_ctx) = palette_bsize_ctx(SIDE)
27267+ {
27268+ let use_palette_y =
27269+ mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][palette_ctx]) != 0;
27270+ if use_palette_y {
27271+ let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]);
27272+ palette_y_pending = Some((n, read_palette_colors_y(dec, n, &palette_cache)));
27212 }27273 }
27213 // lane-uv8 r1: `read_palette_mode_info` reads the UV symbol only27274 // lane-uv8 r1: `read_palette_mode_info` reads the UV symbol only
27214- // when `uv_mode == UV_DC_PRED` (decodemv.c) -- unconditional here27275+ // when `uv_mode == UV_DC_PRED` (decodemv.c).
27215- // while every non-DC uv_mode was refused a few lines above.27276+ let use_palette_uv = uv_mode == DC_PRED
27216- if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 {27277+ && dec.symbol(&mut cdfs.palette_uv_mode[usize::from(use_palette_y)]) != 0;
27217- return Err(unsupported(27278+ if crate::envflags::env_flag!("EC_PALSYN") {
27218- "a block that actually uses a palette (UV) -- reconstruction is out of scope",27279+ eprintln!(
27219- ));27280+ "EC_PALSYN leaf8 mi={},{} bw=8 bh=8 mode={mode} uv={uv_mode} ctx={palette_ctx} y={} uv={} rng={}",
27281+ leaf_mi.0,
27282+ leaf_mi.1,
27283+ palette_y_pending.map_or(0, |(n, _)| n),
27284+ u8::from(use_palette_uv),
27285+ dec.debug_state().0
27286+ );
27287+ }
27288+ if use_palette_uv {
27289+ let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]);
27290+ let (u_colors, v_colors) = read_palette_colors_uv(dec, n, &palette_uv_cache);
27291+ palette_uv_pending = Some((n, u_colors, v_colors));
27220 }27292 }
27221 }27293 }
27222 // lane-fiinter r1: `read_filter_intra_mode_info` (libaom `decodemv.c`,27294 // lane-fiinter r1: `read_filter_intra_mode_info` (libaom `decodemv.c`,
@@ -27235,6 +27307,9 @@ fn decode_inter_block8(
27235 let ec_istep8 = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");27307 let ec_istep8 = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");
27236 if mode == DC_PRED27308 if mode == DC_PRED
27237 && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get)27309 && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get)
27310+ // `av1_filter_intra_allowed` (reconintra.h:77) excludes a
27311+ // palette-Y block, so no `use_filter_intra` symbol exists there.
27312+ && palette_y_pending.is_none()
27238 && let Some(class) = filter_intra_size_class(SIDE)27313 && let Some(class) = filter_intra_size_class(SIDE)
27239 {27314 {
27240 let use_fi = dec.symbol(&mut cdfs.filter_intra[class]) != 0;27315 let use_fi = dec.symbol(&mut cdfs.filter_intra[class]) != 0;
@@ -27262,6 +27337,49 @@ fn decode_inter_block8(
27262 filter_intra = Some(fi);27337 filter_intra = Some(fi);
27263 }27338 }
27264 }27339 }
27340+ // lane-t900 r23: `av1_visit_palette` -- the two colour-index maps, Y
27341+ // then the shared chroma one, after the WHOLE mode-info read.
27342+ let palette_y = palette_y_pending.map(|(n, colors)| {
27343+ let map = decode_color_index_map_wh(dec, cdfs, n, SIDE, SIDE, false);
27344+ PALETTE_HITS.with(|c| c.set(c.get() + 1));
27345+ INTRA_IN_INTER_PALETTE_Y_HITS.with(|c| c.set(c.get() + 1));
27346+ INTER8_PALETTE_HITS.with(|c| {
27347+ let mut v = c.get();
27348+ v.0 += 1;
27349+ c.set(v);
27350+ });
27351+ PaletteY { size: n, colors, map }
27352+ });
27353+ let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| {
27354+ // `av1_get_plane_block_size(BLOCK_8X8, 1, 1)` = BLOCK_4X4.
27355+ let map = decode_color_index_map_wh(dec, cdfs, n, CHROMA_SIDE, CHROMA_SIDE, true);
27356+ PALETTE_UV_HITS.with(|c| c.set(c.get() + 1));
27357+ INTRA_IN_INTER_PALETTE_UV_HITS.with(|c| c.set(c.get() + 1));
27358+ INTER8_PALETTE_HITS.with(|c| {
27359+ let mut v = c.get();
27360+ v.1 += 1;
27361+ c.set(v);
27362+ });
27363+ PaletteUv { size: n, u_colors, v_colors, map }
27364+ });
27365+ palette_record8 = (
27366+ palette_y.as_ref().map_or(0, |p| p.size),
27367+ palette_y.as_ref().map_or([0u16; 8], |p| p.colors),
27368+ palette_uv.as_ref().map_or(0, |p| p.size),
27369+ palette_uv.as_ref().map_or([0u16; 8], |p| p.u_colors),
27370+ );
27371+ // A palette block predicts from its own colour-index map, never from
27372+ // the block edge (spec 7.11.2/7.11.4) -- these ride the
27373+ // [`PALETTE_PRED`] slot into each `reconstruct`/`read_plane` call
27374+ // below, exactly as the key-frame and >=16 intra-in-inter paths do.
27375+ let palette_y_buf: Option<Vec<u16>> =
27376+ palette_y.as_ref().map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect());
27377+ let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|p| {
27378+ (
27379+ p.map.iter().map(|&i| p.u_colors[i as usize]).collect(),
27380+ p.map.iter().map(|&i| p.v_colors[i as usize]).collect(),
27381+ )
27382+ });
27265 mode_for_tx = mode;27383 mode_for_tx = mode;
27266 let (mi_row, mi_col) = leaf_mi;27384 let (mi_row, mi_col) = leaf_mi;
27267 for dr in 0..2 {27385 for dr in 0..2 {
@@ -27319,6 +27437,19 @@ fn decode_inter_block8(
27319 // position: top-right / bottom-left availability is the27437 // position: top-right / bottom-left availability is the
27320 // block's, narrowed by the unit's offset inside it.27438 // block's, narrowed by the unit's offset inside it.
27321 let tu_reach = Reach::of_tu(SIDE, SIDE, col * MI, row * MI, tx_px, tx_px, reach);27439 let tu_reach = Reach::of_tu(SIDE, SIDE, col * MI, row * MI, tx_px, tx_px, reach);
27440+ // This unit's own window on the block's palette prediction
27441+ // (the whole-block buffer would be indexed at the wrong
27442+ // stride by the first unit).
27443+ if let Some(buf) = &palette_y_buf {
27444+ PALETTE_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
27445+ let window: Vec<u16> = (0..tx_px)
27446+ .flat_map(|i| {
27447+ let base = (row * MI + i) * SIDE + col * MI;
27448+ buf[base..base + tx_px].iter().copied()
27449+ })
27450+ .collect();
27451+ set_palette_pred(window);
27452+ }
27322 let tu_grid = if skip {27453 let tu_grid = if skip {
27323 y.reconstruct(27454 y.reconstruct(
27324 tu_px,27455 tu_px,
@@ -27370,6 +27501,9 @@ fn decode_inter_block8(
27370 }27501 }
27371 if skip {27502 if skip {
27372 if !split8 {27503 if !split8 {
27504+ if let Some(buf) = &palette_y_buf {
27505+ set_palette_pred(buf.clone());
27506+ }
27373 y.reconstruct(27507 y.reconstruct(
27374 px,27508 px,
27375 py,27509 py,
@@ -27386,6 +27520,9 @@ fn decode_inter_block8(
27386 // CfL's AC contribution is the luma this leaf just reconstructed,27520 // CfL's AC contribution is the luma this leaf just reconstructed,
27387 // averaged over the 4x4 chroma block (`cfl_ac_q3`, spec 7.11.5).27521 // averaged over the 4x4 chroma block (`cfl_ac_q3`, spec 7.11.5).
27388 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE));27522 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE));
27523+ if let Some((ub, _)) = &palette_uv_bufs {
27524+ set_palette_pred(ub.clone());
27525+ }
27389 u.reconstruct(27526 u.reconstruct(
27390 cpx,27527 cpx,
27391 cpy,27528 cpy,
@@ -27398,6 +27535,9 @@ fn decode_inter_block8(
27398 None,27535 None,
27399 smooth_neighbor_uv,27536 smooth_neighbor_uv,
27400 );27537 );
27538+ if let Some((_, vb)) = &palette_uv_bufs {
27539+ set_palette_pred(vb.clone());
27540+ }
27401 v.reconstruct(27541 v.reconstruct(
27402 cpx,27542 cpx,
27403 cpy,27543 cpy,
@@ -27421,6 +27561,9 @@ fn decode_inter_block8(
27421 // which the `saved_luma_ctx` restore below keeps per-TU.27561 // which the `saved_luma_ctx` restore below keeps per-TU.
27422 vec![0i32; SIDE * SIDE]27562 vec![0i32; SIDE * SIDE]
27423 } else {27563 } else {
27564+ if let Some(buf) = &palette_y_buf {
27565+ set_palette_pred(buf.clone());
27566+ }
27424 read_plane(27567 read_plane(
27425 dec,27568 dec,
27426 cdfs,27569 cdfs,
@@ -27453,6 +27596,9 @@ fn decode_inter_block8(
27453 )?27596 )?
27454 };27597 };
27455 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE));27598 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE));
27599+ if let Some((ub, _)) = &palette_uv_bufs {
27600+ set_palette_pred(ub.clone());
27601+ }
27456 u_grid = read_plane(27602 u_grid = read_plane(
27457 dec,27603 dec,
27458 cdfs,27604 cdfs,
@@ -27475,6 +27621,9 @@ fn decode_inter_block8(
27475 None,27621 None,
27476 smooth_neighbor_uv,27622 smooth_neighbor_uv,
27477 )?;27623 )?;
27624+ if let Some((_, vb)) = &palette_uv_bufs {
27625+ set_palette_pred(vb.clone());
27626+ }
27478 v_grid = read_plane(27627 v_grid = read_plane(
27479 dec,27628 dec,
27480 cdfs,27629 cdfs,
@@ -27516,6 +27665,21 @@ fn decode_inter_block8(
27516 ],27665 ],
27517 )27666 )
27518 });27667 });
27668+ // lane-t900 r23: every leaf stamps its palette state (all-zero for an
27669+ // inter leaf or a non-palette intra one, real for a palette block) into
27670+ // the mi-granular neighbour bands, so the next intra block's
27671+ // `av1_get_palette_mode_ctx` and colour cache see exactly what libaom's
27672+ // mode-info grid holds.
27673+ record_strip_palette(
27674+ neighbours,
27675+ leaf_mi,
27676+ 8,
27677+ 8,
27678+ palette_record8.0,
27679+ palette_record8.1,
27680+ palette_record8.2,
27681+ palette_record8.3,
27682+ );
27519 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);27683 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
27520 // lane-uv8 r1: this leaf never stamped a mode band at all, so the block27684 // lane-uv8 r1: this leaf never stamped a mode band at all, so the block
27521 // below/right of it read whatever block last wrote the coarse [`SUB`]27685 // below/right of it read whatever block last wrote the coarse [`SUB`]
crates/ec-av1/src/stream.rsmodified+7 -0
@@ -126,6 +126,13 @@ pub fn intra_in_inter_palette_hits() -> (usize, usize) {
126 crate::decode::intra_in_inter_palette_hits()126 crate::decode::intra_in_inter_palette_hits()
127 }127 }
128 128
129+/// `(y, uv)` palette blocks reconstructed on an 8x8 LEAF inside an inter
130+/// frame (lane-t900 r23) -- the site-specific half of
131+/// [`intra_in_inter_palette_hits`], which a >=16 block also moves.
132+pub fn inter8_palette_hits() -> (usize, usize) {
133+ crate::decode::inter8_palette_hits()
134+}
135+
129 /// lane-rect64port r1: coded 64-level HORZ/VERT intra strips whose luma136 /// lane-rect64port r1: coded 64-level HORZ/VERT intra strips whose luma
130 /// transform unit is the un-split TX_64X32 (orient 0) / TX_32X64 (orient 1).137 /// transform unit is the un-split TX_64X32 (orient 0) / TX_32X64 (orient 1).
131 pub fn rect64_corner_tu_hits(orient: usize) -> usize {138 pub fn rect64_corner_tu_hits(orient: usize) -> usize {