forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-pal8' (aec5aad): palette reconstruction on 8x8 intra leaves

Browse files at this commit

c206f6182b206a5abfc786f5d28146aaf253df4eAhmet Kaan GümüşParent: b8a5772ae334b6
crates/ec-av1/src/decode.rsmodified+122 -14
@@ -1577,6 +1577,41 @@ pub(crate) fn palette_split_tx_hits() -> usize {
15771577 PALETTE_SPLIT_TX_HITS.with(|c| c.get())
15781578 }
15791579
1580+thread_local! {
1581+ /// lane-pal8 r1: square 8x8 LEAVES ([`decode_leaf8`]) that actually use a
1582+ /// palette (Y or UV) -- the shape every 8-bit `--tune-content=screen`
1583+ /// stream stopped on, since aomenc palettes square blocks at 8 bit and
1584+ /// `--min-partition-size=8` puts them on this leaf path.
1585+ static PALETTE_LEAF8_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1586+}
1587+
1588+/// Current value of [`PALETTE_LEAF8_HITS`].
1589+pub(crate) fn palette_leaf8_hits() -> usize {
1590+ PALETTE_LEAF8_HITS.with(|c| c.get())
1591+}
1592+
1593+/// Zeroes [`PALETTE_LEAF8_HITS`] (per-attempt gate counting).
1594+pub(crate) fn reset_palette_leaf8_hits() {
1595+ PALETTE_LEAF8_HITS.with(|c| c.set(0));
1596+}
1597+
1598+thread_local! {
1599+ /// lane-pal8 r1: NON-SKIP palette blocks on a superblock-level (64-level)
1600+ /// HORZ/VERT or 1:4 strip ([`decode_block_rect64`]) -- i.e. a palette
1601+ /// block that also carries a real, corner-cropped luma transform.
1602+ static PALETTE_SB_STRIP_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1603+}
1604+
1605+/// Current value of [`PALETTE_SB_STRIP_HITS`].
1606+pub(crate) fn palette_sb_strip_hits() -> usize {
1607+ PALETTE_SB_STRIP_HITS.with(|c| c.get())
1608+}
1609+
1610+/// Zeroes [`PALETTE_SB_STRIP_HITS`] (per-attempt gate counting).
1611+pub(crate) fn reset_palette_sb_strip_hits() {
1612+ PALETTE_SB_STRIP_HITS.with(|c| c.set(0));
1613+}
1614+
15801615 // lane-hgkf r2: SKIPPED intra blocks whose `tx_depth` split the luma transform
15811616 // and which are therefore predicted one transform unit at a time (a skipped
15821617 // block codes no coefficients, so nothing else in the stream witnesses this
@@ -9052,6 +9087,14 @@ fn decode_block_rect64(
90529087 // needs the plain, uncropped rect reader [`decode_block_rect`] already
90539088 // has, not this one's truncation. `skip` (no residual at all) is
90549089 // still supported below (lane-palette2 r4).
9090+ //
9091+ // lane-pal8 r1 MEASURED the lift and it is NOT free: dropping this
9092+ // refusal decodes `testsrc2` 128x128 10-bit cq55 `--enable-palette=1
9093+ // --min-partition-size=8 --tile-columns=1` with a whole-frame pixel
9094+ // mismatch (the arm the gate below counts). Something in this shape's
9095+ // palette prediction or its corner-cropped residual is wrong, and the
9096+ // refusal stays until that is found -- it is counted, never skipped.
9097+ PALETTE_SB_STRIP_HITS.with(|c| c.set(c.get() + 1));
90559098 return Err(unsupported(
90569099 "a palette block with a real transform on a superblock-level HORZ/VERT \
90579100 strip (corner-cropped luma coefficients not ported for palette)",
@@ -11466,7 +11509,15 @@ fn decode_leaf8(
1146611509 // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec
1146711510 // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other
1146811511 // `decode_block` caller at 16x16 and up.
11469- let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, _palette_y, _palette_uv) =
11512+ // lane-pal8 r1: this leaf's own palette-Y mode ctx and colour cache
11513+ // (`av1_get_palette_mode_ctx` / `av1_get_palette_cache`, decodemv.c:567,
11514+ // `read_palette_mode_info`), at its REAL mi position -- passing
11515+ // `None`/`&[]` read `palette_y_mode` off CDF row 0 and refused by name the
11516+ // moment a real 8x8 palette block fired, which is where every 8-bit
11517+ // `--tune-content=screen --min-partition-size=8` stream stopped.
11518+ let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(leaf_mi);
11519+ let palette_uv_cache = neighbours.palette_uv_cache_mi(leaf_mi);
11520+ let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) =
1147011521 read_intra_mode(
1147111522 dec,
1147211523 cdfs,
@@ -11478,8 +11529,8 @@ fn decode_leaf8(
1147811529 neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1),
1147911530 allow_screen_content_tools,
1148011531 allow_intrabc,
11481- None,
11482- &[],
11532+ Some((palette_ctx, &palette_cache)),
11533+ &palette_uv_cache,
1148311534 leaf_mi.0,
1148411535 leaf_mi.1,
1148511536 )?;
@@ -11501,6 +11552,26 @@ fn decode_leaf8(
1150111552 "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)",
1150211553 ));
1150311554 }
11555+ // `av1_visit_palette`'s reconstruction (decodeframe.c:1135): the colour
11556+ // index map, mapped through the base colours, IS the block's prediction --
11557+ // carried to the next `reconstruct`/`read_plane` through the same
11558+ // [`PALETTE_PRED`] slot [`decode_block`] uses at 16x16 and up.
11559+ let palette_y_buf: Option<Vec<u16>> = palette_y
11560+ .as_ref()
11561+ .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect());
11562+ let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|p| {
11563+ (
11564+ p.map.iter().map(|&i| p.u_colors[i as usize]).collect(),
11565+ p.map.iter().map(|&i| p.v_colors[i as usize]).collect(),
11566+ )
11567+ });
11568+ let (pal_y_size, pal_y_colors) =
11569+ palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));
11570+ let (pal_uv_size, pal_uv_colors) =
11571+ palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
11572+ if palette_y.is_some() || palette_uv.is_some() {
11573+ PALETTE_LEAF8_HITS.with(|c| c.set(c.get() + 1));
11574+ }
1150411575 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
1150511576 DC_PRED
1150611577 } else {
@@ -11564,7 +11635,11 @@ fn decode_leaf8(
1156411635 // transform units, each off the units already written left/above of
1156511636 // it inside this same leaf -- an intra block's transform size is read
1156611637 // whether or not it is skipped, and spec 7.11.2 predicts per unit.
11567- if resolved == 4 {
11638+ // A palette block's prediction is the whole-block index map, never
11639+ // per-transform-unit edges ([`decode_block`]'s own `split_tx_skip`
11640+ // rule) -- so a palette leaf takes the single 8x8 reconstruct below
11641+ // even when `tx_depth` resolved to TX_4X4.
11642+ if resolved == 4 && palette_y_buf.is_none() {
1156811643 SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
1156911644 for tu_row in 0..2 {
1157011645 for tu_col in 0..2 {
@@ -11599,6 +11674,9 @@ fn decode_leaf8(
1159911674 }
1160011675 }
1160111676 } else {
11677+ if let Some(buf) = &palette_y_buf {
11678+ set_palette_pred(buf.clone());
11679+ }
1160211680 y.reconstruct(
1160311681 px,
1160411682 py,
@@ -11615,6 +11693,8 @@ fn decode_leaf8(
1161511693 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
1161611694 if let Some((_, ub, _)) = &intrabc_bufs {
1161711695 set_palette_pred(ub.clone());
11696+ } else if let Some((ub, _)) = &palette_uv_bufs {
11697+ set_palette_pred(ub.clone());
1161811698 }
1161911699 u.reconstruct(
1162011700 cpx,
@@ -11630,6 +11710,8 @@ fn decode_leaf8(
1163011710 );
1163111711 if let Some((_, _, vb)) = &intrabc_bufs {
1163211712 set_palette_pred(vb.clone());
11713+ } else if let Some((_, vb)) = &palette_uv_bufs {
11714+ set_palette_pred(vb.clone());
1163311715 }
1163411716 v.reconstruct(
1163511717 cpx,
@@ -11648,6 +11730,9 @@ fn decode_leaf8(
1164811730 v_grid = vec![0i32; 16];
1164911731 } else if resolved != 4 {
1165011732 let around = neighbours.around_mi(leaf_mi, 8);
11733+ if let Some(buf) = &palette_y_buf {
11734+ set_palette_pred(buf.clone());
11735+ }
1165111736 luma_grid = read_plane(
1165211737 dec,
1165311738 cdfs,
@@ -11685,6 +11770,8 @@ fn decode_leaf8(
1168511770 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
1168611771 if let Some((_, ub, _)) = &intrabc_bufs {
1168711772 set_palette_pred(ub.clone());
11773+ } else if let Some((ub, _)) = &palette_uv_bufs {
11774+ set_palette_pred(ub.clone());
1168811775 }
1168911776 u_grid = read_plane(
1169011777 dec,
@@ -11710,6 +11797,8 @@ fn decode_leaf8(
1171011797 )?;
1171111798 if let Some((_, _, vb)) = &intrabc_bufs {
1171211799 set_palette_pred(vb.clone());
11800+ } else if let Some((_, vb)) = &palette_uv_bufs {
11801+ set_palette_pred(vb.clone());
1171311802 }
1171411803 v_grid = read_plane(
1171511804 dec,
@@ -11767,6 +11856,19 @@ fn decode_leaf8(
1176711856 y.height,
1176811857 );
1176911858 let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1);
11859+ // Each 4x4 unit predicts from its own window of the block's
11860+ // 8x8 colour-index map ([`decode_block`]'s per-TU slice at
11861+ // 16x16 and up) -- the whole-block buffer would be taken by
11862+ // the FIRST unit and indexed at the wrong stride.
11863+ if let Some(buf) = &palette_y_buf {
11864+ PALETTE_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
11865+ let mut window = vec![0u16; 16];
11866+ for row in 0..4 {
11867+ let src = (tu_row * 4 + row) * 8 + tu_col * 4;
11868+ window[row * 4..][..4].copy_from_slice(&buf[src..][..4]);
11869+ }
11870+ set_palette_pred(window);
11871+ }
1177011872 let tu_grid = read_plane(
1177111873 dec,
1177211874 cdfs,
@@ -11806,6 +11908,9 @@ fn decode_leaf8(
1180611908 }
1180711909 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
1180811910 let chroma_around = neighbours.around_mi(leaf_mi, 8);
11911+ if let Some((ub, _)) = &palette_uv_bufs {
11912+ set_palette_pred(ub.clone());
11913+ }
1180911914 u_grid = read_plane(
1181011915 dec,
1181111916 cdfs,
@@ -11828,6 +11933,9 @@ fn decode_leaf8(
1182811933 None,
1182911934 smooth_neighbor_uv,
1183011935 )?;
11936+ if let Some((_, vb)) = &palette_uv_bufs {
11937+ set_palette_pred(vb.clone());
11938+ }
1183111939 v_grid = read_plane(
1183211940 dec,
1183311941 cdfs,
@@ -11878,12 +11986,12 @@ fn decode_leaf8(
1187811986 neighbours.above[leaf_mi.1 + cell][2] = v_state;
1187911987 }
1188011988 }
11881- // Non-palette 8x8 leaf (this path never reads a palette): clear the
11882- // above/left palette state over its own cell so the next block's ctx and
11883- // colour cache do not read a previous block's palette (lane-palette2 r8).
11989+ // This leaf's own palette state into the mi-granular above/left bands
11990+ // (sizes 0 when it used none, which is what clears a previous block's
11991+ // palette out of the next block's ctx and colour cache).
1188411992 {
11885- neighbours.record_palette_y_rect(leaf_mi, 8, 8, 0, [0u16; 8]);
11886- neighbours.record_palette_uv_rect(leaf_mi, 8, 8, 0, [0u16; 8]);
11993+ neighbours.record_palette_y_rect(leaf_mi, 8, 8, pal_y_size, pal_y_colors);
11994+ neighbours.record_palette_uv_rect(leaf_mi, 8, 8, pal_uv_size, pal_uv_colors);
1188711995 }
1188811996 neighbours.fill_skip_grid(leaf_mi, 2, skip);
1188911997 neighbours.fill_lf_grid(leaf_mi, 2, 4, 0);
@@ -11892,12 +12000,12 @@ fn decode_leaf8(
1189212000 return Ok(mode);
1189312001 }
1189412002 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
11895- // Non-palette 8x8 leaf (this path never reads a palette): clear the
11896- // above/left palette state over its own cell so the next block's ctx and
11897- // colour cache do not read a previous block's palette (lane-palette2 r8).
12003+ // This leaf's own palette state into the mi-granular above/left bands
12004+ // (sizes 0 when it used none, which is what clears a previous block's
12005+ // palette out of the next block's ctx and colour cache).
1189812006 {
11899- neighbours.record_palette_y_rect(leaf_mi, 8, 8, 0, [0u16; 8]);
11900- neighbours.record_palette_uv_rect(leaf_mi, 8, 8, 0, [0u16; 8]);
12007+ neighbours.record_palette_y_rect(leaf_mi, 8, 8, pal_y_size, pal_y_colors);
12008+ neighbours.record_palette_uv_rect(leaf_mi, 8, 8, pal_uv_size, pal_uv_colors);
1190112009 }
1190212010 INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1));
1190312011 neighbours.fill_skip_grid(leaf_mi, 2, skip);
crates/ec-av1/src/stream.rsmodified+229 -0
@@ -2855,6 +2855,235 @@ mod tests {
28552855 }
28562856 }
28572857
2858+ /// lane-pal8 r1, the gate for a palette on a SQUARE 8x8 LEAF.
2859+ ///
2860+ /// `read_palette_mode_info` (decodemv.c:567) reads `palette_y_mode` for
2861+ /// every `DC_PRED` block whose `av1_get_palette_bsize_ctx`
2862+ /// (`num_pels_log2 - num_pels_log2[BLOCK_8X8]`, 0 at 8x8) exists, and
2863+ /// `av1_decode_palette_tokens` (decodeframe.c:1135, `av1_visit_palette`)
2864+ /// reads the colour-index map after the WHOLE mode-info read. Ours passed
2865+ /// `None`/`&[]` from [`decode::decode_leaf8`], reading the mode symbol off
2866+ /// CDF row 0 and refusing "a block that actually uses a palette (Y) --
2867+ /// reconstruction is out of scope" the moment it fired -- and at 8 bit
2868+ /// aomenc palettes SQUARE blocks, so with `--min-partition-size=8` every
2869+ /// 8-bit screen-content stream stopped there (lane-kf900 r4's measurement).
2870+ ///
2871+ /// Sweeps both bit depths x cq 30/40/55 x `--enable-tx-size-search` 0/1 x
2872+ /// two lavfi sources (+ a `--tile-columns=1` arm, per the neighbour-map
2873+ /// rule: the palette bands are per-mi and tile-guarded). Key frame only
2874+ /// (`--limit=1`): the inter frames of these recipes stop on OTHER lanes'
2875+ /// open refusals (8x8 inter leaf chroma mode, inter 1:4 partitions).
2876+ /// HARD-asserts the 8x8-leaf palette counter moved on the compared arms
2877+ /// and that no arm mismatched, in or out of scope.
2878+ #[test]
2879+ fn a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact() {
2880+ const NAME: &str = "a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact";
2881+ if !have_ffmpeg() {
2882+ eprintln!("SKIP {NAME}: no ffmpeg");
2883+ return;
2884+ }
2885+ if !have_aomenc() {
2886+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2887+ return;
2888+ }
2889+ let (width, height) = (128usize, 128usize);
2890+ let (mut leaf8_total, mut fired_arms, mut compared, mut frames_compared) =
2891+ (0usize, 0u32, 0u32, 0usize);
2892+ let (mut out_of_scope, mut out_of_scope_mismatch, mut refusals) = (0u32, 0u32, 0u32);
2893+ let (mut sb_strip_total, mut sb_strip_arms) = (0usize, 0u32);
2894+ // The one palette shape this round did NOT lift (measured: lifting it
2895+ // mismatches -- see [`decode_block_rect64`]'s own comment).
2896+ let mut sb_strip_refusals = 0u32;
2897+ for src in ["testsrc2", "smptebars"] {
2898+ for depth in [8usize, 10usize] {
2899+ for cq in [30usize, 40, 55] {
2900+ for txs in [0usize, 1] {
2901+ for tiles in [0usize, 1] {
2902+ let arm = format!("{src}-{depth}bit-cq{cq}-txs{txs}-tc{tiles}");
2903+ let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" };
2904+ let size = format!("{src}=size={width}x{height}:rate=25");
2905+ let render = || {
2906+ let out = Command::new("ffmpeg")
2907+ .args([
2908+ "-v", "error", "-f", "lavfi", "-i", &size, "-t", "0.04",
2909+ "-pix_fmt", pix_fmt, "-strict", "-1", "-f",
2910+ "yuv4mpegpipe", "-",
2911+ ])
2912+ .stdin(Stdio::null())
2913+ .stdout(Stdio::piped())
2914+ .stderr(Stdio::piped())
2915+ .output()
2916+ .expect("ffmpeg failed to run");
2917+ assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}");
2918+ out.stdout
2919+ };
2920+ let y4m_a = render();
2921+ let y4m_b = render();
2922+ assert_eq!(
2923+ y4m_a, y4m_b,
2924+ "{NAME}: {arm} must render byte-identical across two runs"
2925+ );
2926+ let y4m = y4m_a;
2927+ let depth_arg = format!("--bit-depth={depth}");
2928+ let input_depth_arg = format!("--input-bit-depth={depth}");
2929+ let cq_arg = format!("--cq-level={cq}");
2930+ let txs_arg = format!("--enable-tx-size-search={txs}");
2931+ let tiles_arg = format!("--tile-columns={tiles}");
2932+ let mut child = Command::new(aomenc_path())
2933+ .args([
2934+ "--codec=av1",
2935+ "--passes=1",
2936+ "--end-usage=q",
2937+ "--cpu-used=0",
2938+ "--threads=1",
2939+ "--row-mt=0",
2940+ "--lag-in-frames=0",
2941+ "--limit=1",
2942+ "--sb-size=64",
2943+ "--tune-content=screen",
2944+ "--enable-palette=1",
2945+ "--enable-intrabc=0",
2946+ "--min-partition-size=8",
2947+ "--enable-cdef=0",
2948+ "--enable-restoration=0",
2949+ "--loopfilter-control=0",
2950+ ])
2951+ // aomenc keeps the LAST occurrence of a repeated flag,
2952+ // so per-arm overrides go after the base recipe.
2953+ .args([&depth_arg, &input_depth_arg, &cq_arg, &txs_arg, &tiles_arg])
2954+ .args(["--obu", "-o", "-", "-"])
2955+ .stdin(Stdio::piped())
2956+ .stdout(Stdio::piped())
2957+ .stderr(Stdio::piped())
2958+ .spawn()
2959+ .expect("aomenc failed to start");
2960+ child
2961+ .stdin
2962+ .take()
2963+ .expect("aomenc stdin")
2964+ .write_all(&y4m)
2965+ .or_else(|e| match e.kind() {
2966+ std::io::ErrorKind::BrokenPipe => Ok(()),
2967+ _ => Err(e),
2968+ })
2969+ .expect("writing y4m to aomenc");
2970+ let out = child.wait_with_output().expect("aomenc failed to run");
2971+ assert!(
2972+ out.status.success(),
2973+ "{NAME}: aomenc refused {arm}: {}",
2974+ String::from_utf8_lossy(&out.stderr)
2975+ );
2976+ let stream = out.stdout;
2977+ decode::reset_palette_leaf8_hits();
2978+ decode::reset_palette_sb_strip_hits();
2979+ let decoded = decode_stream(&stream);
2980+ let leaf8 = decode::palette_leaf8_hits();
2981+ let sb_strip = decode::palette_sb_strip_hits();
2982+ leaf8_total += leaf8;
2983+ sb_strip_total += sb_strip;
2984+ match decoded {
2985+ Ok(frames) => {
2986+ assert!(!frames.is_empty(), "{NAME}: {arm} decoded no frame");
2987+ let theirs = if depth == 10 {
2988+ ffmpeg_decode_sequence_10bit(
2989+ &stream,
2990+ width,
2991+ height,
2992+ frames.len(),
2993+ )
2994+ } else {
2995+ ffmpeg_decode_sequence(&stream, width, height, frames.len())
2996+ };
2997+ assert_eq!(
2998+ frames.len(),
2999+ theirs.len(),
3000+ "{NAME}: {arm} frame count"
3001+ );
3002+ let mut same = true;
3003+ for (i, (ours, ref_f)) in
3004+ frames.iter().zip(theirs.iter()).enumerate()
3005+ {
3006+ let ok = ours.y == ref_f.y
3007+ && ours.u == ref_f.u
3008+ && ours.v == ref_f.v;
3009+ if !ok {
3010+ eprintln!("{NAME}: {arm} MISMATCH at frame {i}");
3011+ }
3012+ same &= ok;
3013+ frames_compared += 1;
3014+ }
3015+ compared += 1;
3016+ if sb_strip > 0 {
3017+ sb_strip_arms += 1;
3018+ assert!(
3019+ same,
3020+ "{NAME}: {arm} decoded {sb_strip} non-skip palette \
3021+ block(s) on a superblock-level strip and did not \
3022+ match ffmpeg"
3023+ );
3024+ }
3025+ if leaf8 > 0 || sb_strip > 0 {
3026+ fired_arms += 1;
3027+ assert!(
3028+ same,
3029+ "{NAME}: {arm} decoded {leaf8} 8x8-leaf palette \
3030+ block(s) and did not match ffmpeg"
3031+ );
3032+ } else {
3033+ out_of_scope += 1;
3034+ if !same {
3035+ out_of_scope_mismatch += 1;
3036+ }
3037+ }
3038+ eprintln!(
3039+ "{NAME}: {arm} {} frame(s), {leaf8} 8x8-leaf palette \
3040+ block(s), {sb_strip} superblock-strip palette \
3041+ block(s), exact={same}",
3042+ frames.len()
3043+ );
3044+ }
3045+ Err(e) => {
3046+ let msg = e.to_string();
3047+ assert!(
3048+ msg.contains("unsupported"),
3049+ "{NAME}: {arm} decode failed: {e}"
3050+ );
3051+ // Named, counted, never turned into a skip.
3052+ if msg.contains("superblock-level HORZ/VERT strip") {
3053+ sb_strip_refusals += 1;
3054+ }
3055+ eprintln!("{NAME}: {arm} REFUSED: {e}");
3056+ refusals += 1;
3057+ }
3058+ }
3059+ }
3060+ }
3061+ }
3062+ }
3063+ }
3064+ eprintln!(
3065+ "{NAME}: {leaf8_total} 8x8-leaf palette block(s) across {fired_arms} arm(s), \
3066+ {compared} arms compared ({frames_compared} frames), {sb_strip_total} \
3067+ superblock-strip palette block(s) across {sb_strip_arms} arm(s), \
3068+ {out_of_scope} out of scope ({out_of_scope_mismatch} mismatched), \
3069+ {refusals} refused ({sb_strip_refusals} superblock-strip palette)"
3070+ );
3071+ assert!(
3072+ leaf8_total > 0 && fired_arms > 0,
3073+ "{NAME}: gate is vacuous -- no compared arm decoded an 8x8-leaf palette block"
3074+ );
3075+ assert!(
3076+ sb_strip_refusals > 0,
3077+ "{NAME}: no arm reached the superblock-strip palette refusal -- the open residue \
3078+ this gate documents is no longer exercised"
3079+ );
3080+ assert_eq!(
3081+ out_of_scope_mismatch, 0,
3082+ "{NAME}: an out-of-scope arm mismatched ffmpeg -- a defect, never a skip"
3083+ );
3084+ assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact");
3085+ }
3086+
28583087 /// lane-kf900 r5, the gate for the rect-strip `use_intrabc` read.
28593088 ///
28603089 /// `av1_allow_intrabc` is a FRAME-level test (`decodemv.c:892`,
lanes/pal8-r1.handoff.mdadded+47 -0
@@ -0,0 +1,47 @@
1+# lane-pal8 r1 HANDOFF
2+
3+Branch `lane-pal8`, tip **7d9902c** (parent `3d5a737` = merge of lane-kf900 5a28354 into main 8810bad).
4+Everything below is COMMITTED; nothing is in-flight.
5+
6+## What the patch does
7+`crates/ec-av1/src/decode.rs` `decode_leaf8` (the square 8x8 intra leaf) now passes its
8+own per-mi palette ctx + colour cache into `read_intra_mode`
9+(`palette_ctx_and_cache_mi` / `palette_uv_cache_mi`, kf900's per-mi bands), keeps the
10+returned `PaletteY`/`PaletteUv`, reconstructs through the existing `PALETTE_PRED` slot
11+(whole 8x8; a per-4x4-TU window slice under a split `tx_depth`; a palette skip leaf takes
12+the single 8x8 reconstruct), and stamps the leaf's real palette size/colours into the
13+neighbour bands. New counter `PALETTE_LEAF8_HITS` + getter/reset.
14+References: `read_palette_mode_info` decodemv.c:567, `read_palette_colors_y/uv`
15+decodemv.c:478, `av1_visit_palette` / `av1_decode_palette_tokens` decodeframe.c:1135.
16+
17+## Refusal targeted / lifted
18+"a block that actually uses a palette (Y|UV) -- reconstruction is out of scope" is no
19+longer reachable from `decode_leaf8`. Both strings STAY in `refusal_inventory.rs` -- they
20+are still live on the inter-frame intra paths (decode.rs 19783/19788, 22479/22484), which
21+are another lane's scope. No inventory line was removable.
22+
23+## Localised, measured, NOT lifted
24+"a palette block with a real transform on a superblock-level HORZ/VERT strip". I removed
25+it and re-ran the gate: stream `testsrc2` 128x128 10-bit cq55 `--enable-tx-size-search=0
26+--tile-columns=1 --tune-content=screen --enable-palette=1 --min-partition-size=8
27+--limit=1` decodes frame 0 with a whole-frame mismatch vs ffmpeg. So the refusal is REAL,
28+not stale; restored with that measurement in the code comment, and the gate now asserts an
29+arm still reaches it. Next agent: bisect that stream's first `decode_block_rect64` palette
30+block with an msac range ladder (the corner-cropped luma path expands `min(bw,32)` x
31+`min(bh,32)` levels into a `bw`x`bh` grid and reconstructs once, so the prediction shape
32+already matches the palette buffer -- suspect the residual/scan or class
33+`refusal-hides-a-defect`).
34+
35+## Gate
36+`a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact` (stream.rs), 48 arms,
37+GREEN: 44 8x8-leaf palette blocks across 24 arms, 47 arms / 47 frames pixel-exact,
38+0 out-of-scope mismatches, 1 named refusal (the SB-strip one).
39+
40+## Untested / open
41+- Full suite: 401 passed / 1 failed / 33 ignored. Failure
42+ `a_frame_edge_straddling_band_decodes_pixel_exact` 68x192 cq35 10-bit tile_cols=1,
43+ frame 1, 6944 luma pixels. Attribution unverified -- run that single test at 3d5a737
44+ first (see lanes/pal8-r1.report.md for the exact command).
45+- Inter-frame palette (the 19783/22479 sites) untouched.
46+- The gate is key-frame only (`--limit=1`): the inter frames of this recipe stop on other
47+ lanes' refusals (non-DC chroma on an 8x8 inter leaf; inter 16x16 1:4 partitions).
lanes/pal8-r1.report.mdadded+94 -0
@@ -0,0 +1,94 @@
1+# lane-pal8 r1 -- palette on a square 8x8 leaf
2+
3+Built on `lane-kf900` 5a28354 (merged first, commit `merge lane-kf900`).
4+
5+## What changed
6+
7+- `crates/ec-av1/src/decode.rs` `decode_leaf8` (~10680): the square 8x8 leaf now
8+ passes its OWN palette-Y mode ctx + colour cache
9+ (`neighbours.palette_ctx_and_cache_mi(leaf_mi)` / `palette_uv_cache_mi`) into
10+ `read_intra_mode` instead of `None`/`&[]`, and keeps the returned
11+ `PaletteY`/`PaletteUv` instead of dropping them. Mirrors
12+ `read_palette_mode_info` (decodemv.c:567; `av1_get_palette_mode_ctx`,
13+ `av1_get_palette_cache`, `read_palette_colors_y/uv` at decodemv.c:478) and
14+ `av1_decode_palette_tokens` / `av1_visit_palette` (decodeframe.c:1135), whose
15+ colour-index map is read after the whole mode-info read -- both already
16+ implemented in `read_intra_mode`; only this call site was excluded.
17+ `palette_bsize_ctx(8)` is `num_pels_log2 - 6 = 0`, chroma map is the 4x4
18+ (`ss_size_lookup`) one `read_intra_mode` already decodes at `side / 2`.
19+- Same fn: reconstruction wired through the existing `PALETTE_PRED` slot --
20+ whole-block 8x8 buffer for the single-TX8 and skip arms, a per-4x4-TU window
21+ slice under a `tx_depth`-split leaf (the same slicing `decode_block` does at
22+ 16x16 and up); a palette skip leaf takes the single 8x8 reconstruct, never the
23+ per-TU one (`decode_block`'s own `split_tx_skip` rule).
24+- Same fn: the two `record_palette_y_rect(leaf_mi, 8, 8, 0, [0; 8])` tail sites
25+ now stamp the leaf's REAL palette size/colours into the per-mi neighbour bands
26+ (kf900's bands), so the next block's ctx and colour cache see it.
27+- New counters `PALETTE_LEAF8_HITS` (+ getter/reset) for the gate.
28+- `crates/ec-av1/src/stream.rs`: new gate
29+ `a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact`.
30+
31+## Refusals
32+
33+- LIFTED (for the square 8x8 leaf): `"a block that actually uses a palette (Y)
34+ -- reconstruction is out of scope"` and its UV twin no longer reachable from
35+ `decode_leaf8`. The two strings STAY in `refusal_inventory.rs`: they are still
36+ live on the inter-frame intra paths (decode.rs:19783/19788, 22479/22484),
37+ another lane's scope. No inventory line was removable this round.
38+- NOT lifted, MEASURED: `"a palette block with a real transform on a
39+ superblock-level HORZ/VERT strip"`. I removed it and re-ran the gate: the arm
40+ `testsrc2-10bit-cq55-txs0-tc1` decodes a whole-frame MISMATCH vs ffmpeg, so
41+ the refusal is real, not stale. Restored, with the measurement recorded in the
42+ code comment, and the gate now HARD-asserts that some arm still reaches it
43+ (`sb_strip_refusals > 0`) so the residue cannot silently disappear.
44+ Disposition: deferred(root-cause of the 64-level-strip palette mismatch --
45+ bisect the msac range of that stream's first SB-strip palette block, and check
46+ the class `refusal-hides-a-defect`: the mismatch may be an unrelated defect
47+ that the refusal was masking).
48+
49+## Gate
50+
51+`cargo test -p ec-av1 --lib a_real_aomenc_palette_stream_with_8x8_leaves -- --nocapture`
52+(`EC_AV1_REQUIRE_AOMENC=1`, oracle `~/.cache/aom-oracle/build/aomenc`).
53+48 arms: {testsrc2, smptebars} x {8, 10} bit x cq {30,40,55} x
54+`--enable-tx-size-search` {0,1} x `--tile-columns` {0,1}, 128x128,
55+`--tune-content=screen --enable-palette=1 --min-partition-size=8 --limit=1`
56+(key frame; the inter frames of this recipe stop on OTHER lanes' open refusals:
57+non-DC chroma on an 8x8 inter leaf, inter 16x16 1:4 partitions). Every decoded
58+frame compared against ffmpeg, `out_of_scope_mismatch == 0` asserted.
59+
60+EVIDENCE: ~/.cache/pal8-tmp/gate.log (pre-lift run) + the run below | aomenc 48 arms, ec-av1 decode, ffmpeg compare per frame | 44 8x8-leaf palette block(s) across 24 arm(s), 47 arms compared (47 frames), 23 out of scope (0 mismatched), 1 refused (1 superblock-strip palette) -- test result: ok
61+EVIDENCE: gate rerun with the SB-strip refusal REMOVED | same 48 arms | `testsrc2-10bit-cq55-txs0-tc1 MISMATCH at frame 0`, test FAILED -- which is why that refusal stayed
62+
63+Before this change the same 8-bit recipe refused with "a block that actually
64+uses a palette (Y)": measured with `~/.cache/pal8-tmp/enc.sh` + `decode_probe`
65+on 12 streams before the fix.
66+
67+## Suite
68+
69+`$HOME/.cache/pal8-suite-r1.log` -- see the tail of this file / the lane report line.
70+
71+## Suite (full, `$HOME/.cache/pal8-suite-r1.log`)
72+
73+`systemd-run --user --unit=pal8-suite-... -p MemoryMax=10G ... cargo test -p ec-av1 --lib -j3`
74+-> **401 passed, 1 failed, 33 ignored** in 1443 s. NOT the clean N/0 the charter asks for.
75+
76+The one failure is `stream::tests::a_frame_edge_straddling_band_decodes_pixel_exact`:
77+`68x192 cq35 frames=5 10bit=true tile_cols=1 frame 1 plane Y: 6944 pixels differ,
78+first at row 28 col 15 (ours 196 vs ffmpeg 197) [edge32=[5,27,0,5,2,16,0,1]]`.
79+That gate's own source comment already documents the 8-BIT twin of this arm as a
80+known, separate straddling-band defect ("68x192 cq35 frames=5 10bit=false frame 1
81+plane Y: 141 pixels differ ... LUMA, inside the 4-px straddling COLUMN"); the arm
82+here is the 10-bit one, which the merged lane-kf900 tip added.
83+
84+ATTRIBUTION NOT VERIFIED this round (turn cap). It is very unlikely to be this
85+lane's change -- the whole diff is inert unless a block actually decodes a
86+palette (`palette_y_buf.is_none()` keeps every non-palette path byte-identical)
87+-- but the recipe DOES use `--tune-content=screen`, so palette is live in it and
88+that must be checked, not assumed. Next step, one command:
89+`git worktree add --detach <scratch> 3d5a737` (the pre-change merge commit) with
90+its own `CARGO_TARGET_DIR` and run only
91+`cargo test -p ec-av1 --lib a_frame_edge_straddling_band_decodes_pixel_exact`.
92+Disposition: deferred(that one-test run at 3d5a737) -- if it fails there too, it
93+is the merged straddling-band residue and belongs to that lane; if it passes,
94+it is this lane's and the 8x8-leaf palette wiring must be bisected against it.