diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 22bd6e8a..ea1fe20f 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1577,6 +1577,41 @@ pub(crate) fn palette_split_tx_hits() -> usize { PALETTE_SPLIT_TX_HITS.with(|c| c.get()) } +thread_local! { + /// lane-pal8 r1: square 8x8 LEAVES ([`decode_leaf8`]) that actually use a + /// palette (Y or UV) -- the shape every 8-bit `--tune-content=screen` + /// stream stopped on, since aomenc palettes square blocks at 8 bit and + /// `--min-partition-size=8` puts them on this leaf path. + static PALETTE_LEAF8_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`PALETTE_LEAF8_HITS`]. +pub(crate) fn palette_leaf8_hits() -> usize { + PALETTE_LEAF8_HITS.with(|c| c.get()) +} + +/// Zeroes [`PALETTE_LEAF8_HITS`] (per-attempt gate counting). +pub(crate) fn reset_palette_leaf8_hits() { + PALETTE_LEAF8_HITS.with(|c| c.set(0)); +} + +thread_local! { + /// lane-pal8 r1: NON-SKIP palette blocks on a superblock-level (64-level) + /// HORZ/VERT or 1:4 strip ([`decode_block_rect64`]) -- i.e. a palette + /// block that also carries a real, corner-cropped luma transform. + static PALETTE_SB_STRIP_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`PALETTE_SB_STRIP_HITS`]. +pub(crate) fn palette_sb_strip_hits() -> usize { + PALETTE_SB_STRIP_HITS.with(|c| c.get()) +} + +/// Zeroes [`PALETTE_SB_STRIP_HITS`] (per-attempt gate counting). +pub(crate) fn reset_palette_sb_strip_hits() { + PALETTE_SB_STRIP_HITS.with(|c| c.set(0)); +} + // lane-hgkf r2: SKIPPED intra blocks whose `tx_depth` split the luma transform // and which are therefore predicted one transform unit at a time (a skipped // block codes no coefficients, so nothing else in the stream witnesses this @@ -9052,6 +9087,14 @@ fn decode_block_rect64( // needs the plain, uncropped rect reader [`decode_block_rect`] already // has, not this one's truncation. `skip` (no residual at all) is // still supported below (lane-palette2 r4). + // + // lane-pal8 r1 MEASURED the lift and it is NOT free: dropping this + // refusal decodes `testsrc2` 128x128 10-bit cq55 `--enable-palette=1 + // --min-partition-size=8 --tile-columns=1` with a whole-frame pixel + // mismatch (the arm the gate below counts). Something in this shape's + // palette prediction or its corner-cropped residual is wrong, and the + // refusal stays until that is found -- it is counted, never skipped. + PALETTE_SB_STRIP_HITS.with(|c| c.set(c.get() + 1)); return Err(unsupported( "a palette block with a real transform on a superblock-level HORZ/VERT \ strip (corner-cropped luma coefficients not ported for palette)", @@ -11466,7 +11509,15 @@ fn decode_leaf8( // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other // `decode_block` caller at 16x16 and up. - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, _palette_y, _palette_uv) = + // lane-pal8 r1: this leaf's own palette-Y mode ctx and colour cache + // (`av1_get_palette_mode_ctx` / `av1_get_palette_cache`, decodemv.c:567, + // `read_palette_mode_info`), at its REAL mi position -- passing + // `None`/`&[]` read `palette_y_mode` off CDF row 0 and refused by name the + // moment a real 8x8 palette block fired, which is where every 8-bit + // `--tune-content=screen --min-partition-size=8` stream stopped. + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(leaf_mi); + let palette_uv_cache = neighbours.palette_uv_cache_mi(leaf_mi); + let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = read_intra_mode( dec, cdfs, @@ -11478,8 +11529,8 @@ fn decode_leaf8( neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1), allow_screen_content_tools, allow_intrabc, - None, - &[], + Some((palette_ctx, &palette_cache)), + &palette_uv_cache, leaf_mi.0, leaf_mi.1, )?; @@ -11501,6 +11552,26 @@ fn decode_leaf8( "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)", )); } + // `av1_visit_palette`'s reconstruction (decodeframe.c:1135): the colour + // index map, mapped through the base colours, IS the block's prediction -- + // carried to the next `reconstruct`/`read_plane` through the same + // [`PALETTE_PRED`] slot [`decode_block`] uses at 16x16 and up. + let palette_y_buf: Option> = palette_y + .as_ref() + .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()); + let palette_uv_bufs: Option<(Vec, Vec)> = palette_uv.as_ref().map(|p| { + ( + p.map.iter().map(|&i| p.u_colors[i as usize]).collect(), + p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), + ) + }); + 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) = + palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); + if palette_y.is_some() || palette_uv.is_some() { + PALETTE_LEAF8_HITS.with(|c| c.set(c.get() + 1)); + } let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { @@ -11564,7 +11635,11 @@ fn decode_leaf8( // transform units, each off the units already written left/above of // it inside this same leaf -- an intra block's transform size is read // whether or not it is skipped, and spec 7.11.2 predicts per unit. - if resolved == 4 { + // A palette block's prediction is the whole-block index map, never + // per-transform-unit edges ([`decode_block`]'s own `split_tx_skip` + // rule) -- so a palette leaf takes the single 8x8 reconstruct below + // even when `tx_depth` resolved to TX_4X4. + if resolved == 4 && palette_y_buf.is_none() { SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); for tu_row in 0..2 { for tu_col in 0..2 { @@ -11599,6 +11674,9 @@ fn decode_leaf8( } } } else { + if let Some(buf) = &palette_y_buf { + set_palette_pred(buf.clone()); + } y.reconstruct( px, py, @@ -11615,6 +11693,8 @@ fn decode_leaf8( let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8)); if let Some((_, ub, _)) = &intrabc_bufs { set_palette_pred(ub.clone()); + } else if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone()); } u.reconstruct( cpx, @@ -11630,6 +11710,8 @@ fn decode_leaf8( ); if let Some((_, _, vb)) = &intrabc_bufs { set_palette_pred(vb.clone()); + } else if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone()); } v.reconstruct( cpx, @@ -11648,6 +11730,9 @@ fn decode_leaf8( v_grid = vec![0i32; 16]; } else if resolved != 4 { let around = neighbours.around_mi(leaf_mi, 8); + if let Some(buf) = &palette_y_buf { + set_palette_pred(buf.clone()); + } luma_grid = read_plane( dec, cdfs, @@ -11685,6 +11770,8 @@ fn decode_leaf8( let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8)); if let Some((_, ub, _)) = &intrabc_bufs { set_palette_pred(ub.clone()); + } else if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone()); } u_grid = read_plane( dec, @@ -11710,6 +11797,8 @@ fn decode_leaf8( )?; if let Some((_, _, vb)) = &intrabc_bufs { set_palette_pred(vb.clone()); + } else if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone()); } v_grid = read_plane( dec, @@ -11767,6 +11856,19 @@ fn decode_leaf8( y.height, ); let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1); + // Each 4x4 unit predicts from its own window of the block's + // 8x8 colour-index map ([`decode_block`]'s per-TU slice at + // 16x16 and up) -- the whole-block buffer would be taken by + // the FIRST unit and indexed at the wrong stride. + if let Some(buf) = &palette_y_buf { + PALETTE_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + let mut window = vec![0u16; 16]; + for row in 0..4 { + let src = (tu_row * 4 + row) * 8 + tu_col * 4; + window[row * 4..][..4].copy_from_slice(&buf[src..][..4]); + } + set_palette_pred(window); + } let tu_grid = read_plane( dec, cdfs, @@ -11806,6 +11908,9 @@ fn decode_leaf8( } let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8)); let chroma_around = neighbours.around_mi(leaf_mi, 8); + if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone()); + } u_grid = read_plane( dec, cdfs, @@ -11828,6 +11933,9 @@ fn decode_leaf8( None, smooth_neighbor_uv, )?; + if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone()); + } v_grid = read_plane( dec, cdfs, @@ -11878,12 +11986,12 @@ fn decode_leaf8( neighbours.above[leaf_mi.1 + cell][2] = v_state; } } - // Non-palette 8x8 leaf (this path never reads a palette): clear the - // 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). + // This leaf's own palette state into the mi-granular above/left bands + // (sizes 0 when it used none, which is what clears a previous block's + // palette out of the next block's ctx and colour cache). { - 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.record_palette_y_rect(leaf_mi, 8, 8, pal_y_size, pal_y_colors); + neighbours.record_palette_uv_rect(leaf_mi, 8, 8, pal_uv_size, pal_uv_colors); } neighbours.fill_skip_grid(leaf_mi, 2, skip); neighbours.fill_lf_grid(leaf_mi, 2, 4, 0); @@ -11892,12 +12000,12 @@ fn decode_leaf8( return Ok(mode); } neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); - // Non-palette 8x8 leaf (this path never reads a palette): clear the - // 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). + // This leaf's own palette state into the mi-granular above/left bands + // (sizes 0 when it used none, which is what clears a previous block's + // palette out of the next block's ctx and colour cache). { - 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.record_palette_y_rect(leaf_mi, 8, 8, pal_y_size, pal_y_colors); + neighbours.record_palette_uv_rect(leaf_mi, 8, 8, pal_uv_size, pal_uv_colors); } INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1)); neighbours.fill_skip_grid(leaf_mi, 2, skip); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 15beb06e..8c171baa 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -2855,6 +2855,235 @@ mod tests { } } + /// lane-pal8 r1, the gate for a palette on a SQUARE 8x8 LEAF. + /// + /// `read_palette_mode_info` (decodemv.c:567) reads `palette_y_mode` for + /// every `DC_PRED` block whose `av1_get_palette_bsize_ctx` + /// (`num_pels_log2 - num_pels_log2[BLOCK_8X8]`, 0 at 8x8) exists, and + /// `av1_decode_palette_tokens` (decodeframe.c:1135, `av1_visit_palette`) + /// reads the colour-index map after the WHOLE mode-info read. Ours passed + /// `None`/`&[]` from [`decode::decode_leaf8`], reading the mode symbol off + /// CDF row 0 and refusing "a block that actually uses a palette (Y) -- + /// reconstruction is out of scope" the moment it fired -- and at 8 bit + /// aomenc palettes SQUARE blocks, so with `--min-partition-size=8` every + /// 8-bit screen-content stream stopped there (lane-kf900 r4's measurement). + /// + /// Sweeps both bit depths x cq 30/40/55 x `--enable-tx-size-search` 0/1 x + /// two lavfi sources (+ a `--tile-columns=1` arm, per the neighbour-map + /// rule: the palette bands are per-mi and tile-guarded). Key frame only + /// (`--limit=1`): the inter frames of these recipes stop on OTHER lanes' + /// open refusals (8x8 inter leaf chroma mode, inter 1:4 partitions). + /// HARD-asserts the 8x8-leaf palette counter moved on the compared arms + /// and that no arm mismatched, in or out of scope. + #[test] + fn a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact"; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + let (width, height) = (128usize, 128usize); + let (mut leaf8_total, mut fired_arms, mut compared, mut frames_compared) = + (0usize, 0u32, 0u32, 0usize); + let (mut out_of_scope, mut out_of_scope_mismatch, mut refusals) = (0u32, 0u32, 0u32); + let (mut sb_strip_total, mut sb_strip_arms) = (0usize, 0u32); + // The one palette shape this round did NOT lift (measured: lifting it + // mismatches -- see [`decode_block_rect64`]'s own comment). + let mut sb_strip_refusals = 0u32; + for src in ["testsrc2", "smptebars"] { + for depth in [8usize, 10usize] { + for cq in [30usize, 40, 55] { + for txs in [0usize, 1] { + for tiles in [0usize, 1] { + let arm = format!("{src}-{depth}bit-cq{cq}-txs{txs}-tc{tiles}"); + let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let size = format!("{src}=size={width}x{height}:rate=25"); + let render = || { + let out = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &size, "-t", "0.04", + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", + "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}"); + out.stdout + }; + let y4m_a = render(); + let y4m_b = render(); + assert_eq!( + y4m_a, y4m_b, + "{NAME}: {arm} must render byte-identical across two runs" + ); + let y4m = y4m_a; + let depth_arg = format!("--bit-depth={depth}"); + let input_depth_arg = format!("--input-bit-depth={depth}"); + let cq_arg = format!("--cq-level={cq}"); + let txs_arg = format!("--enable-tx-size-search={txs}"); + let tiles_arg = format!("--tile-columns={tiles}"); + let mut child = Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--lag-in-frames=0", + "--limit=1", + "--sb-size=64", + "--tune-content=screen", + "--enable-palette=1", + "--enable-intrabc=0", + "--min-partition-size=8", + "--enable-cdef=0", + "--enable-restoration=0", + "--loopfilter-control=0", + ]) + // aomenc keeps the LAST occurrence of a repeated flag, + // so per-arm overrides go after the base recipe. + .args([&depth_arg, &input_depth_arg, &cq_arg, &txs_arg, &tiles_arg]) + .args(["--obu", "-o", "-", "-"]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m) + .or_else(|e| match e.kind() { + std::io::ErrorKind::BrokenPipe => Ok(()), + _ => Err(e), + }) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "{NAME}: aomenc refused {arm}: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + decode::reset_palette_leaf8_hits(); + decode::reset_palette_sb_strip_hits(); + let decoded = decode_stream(&stream); + let leaf8 = decode::palette_leaf8_hits(); + let sb_strip = decode::palette_sb_strip_hits(); + leaf8_total += leaf8; + sb_strip_total += sb_strip; + match decoded { + Ok(frames) => { + assert!(!frames.is_empty(), "{NAME}: {arm} decoded no frame"); + let theirs = if depth == 10 { + ffmpeg_decode_sequence_10bit( + &stream, + width, + height, + frames.len(), + ) + } else { + ffmpeg_decode_sequence(&stream, width, height, frames.len()) + }; + assert_eq!( + frames.len(), + theirs.len(), + "{NAME}: {arm} frame count" + ); + let mut same = true; + for (i, (ours, ref_f)) in + frames.iter().zip(theirs.iter()).enumerate() + { + let ok = ours.y == ref_f.y + && ours.u == ref_f.u + && ours.v == ref_f.v; + if !ok { + eprintln!("{NAME}: {arm} MISMATCH at frame {i}"); + } + same &= ok; + frames_compared += 1; + } + compared += 1; + if sb_strip > 0 { + sb_strip_arms += 1; + assert!( + same, + "{NAME}: {arm} decoded {sb_strip} non-skip palette \ + block(s) on a superblock-level strip and did not \ + match ffmpeg" + ); + } + if leaf8 > 0 || sb_strip > 0 { + fired_arms += 1; + assert!( + same, + "{NAME}: {arm} decoded {leaf8} 8x8-leaf palette \ + block(s) and did not match ffmpeg" + ); + } else { + out_of_scope += 1; + if !same { + out_of_scope_mismatch += 1; + } + } + eprintln!( + "{NAME}: {arm} {} frame(s), {leaf8} 8x8-leaf palette \ + block(s), {sb_strip} superblock-strip palette \ + block(s), exact={same}", + frames.len() + ); + } + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME}: {arm} decode failed: {e}" + ); + // Named, counted, never turned into a skip. + if msg.contains("superblock-level HORZ/VERT strip") { + sb_strip_refusals += 1; + } + eprintln!("{NAME}: {arm} REFUSED: {e}"); + refusals += 1; + } + } + } + } + } + } + } + eprintln!( + "{NAME}: {leaf8_total} 8x8-leaf palette block(s) across {fired_arms} arm(s), \ + {compared} arms compared ({frames_compared} frames), {sb_strip_total} \ + superblock-strip palette block(s) across {sb_strip_arms} arm(s), \ + {out_of_scope} out of scope ({out_of_scope_mismatch} mismatched), \ + {refusals} refused ({sb_strip_refusals} superblock-strip palette)" + ); + assert!( + leaf8_total > 0 && fired_arms > 0, + "{NAME}: gate is vacuous -- no compared arm decoded an 8x8-leaf palette block" + ); + assert!( + sb_strip_refusals > 0, + "{NAME}: no arm reached the superblock-strip palette refusal -- the open residue \ + this gate documents is no longer exercised" + ); + assert_eq!( + out_of_scope_mismatch, 0, + "{NAME}: an out-of-scope arm mismatched ffmpeg -- a defect, never a skip" + ); + assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact"); + } + /// lane-kf900 r5, the gate for the rect-strip `use_intrabc` read. /// /// `av1_allow_intrabc` is a FRAME-level test (`decodemv.c:892`, diff --git a/lanes/pal8-r1.handoff.md b/lanes/pal8-r1.handoff.md new file mode 100644 index 00000000..5e062320 --- /dev/null +++ b/lanes/pal8-r1.handoff.md @@ -0,0 +1,47 @@ +# lane-pal8 r1 HANDOFF + +Branch `lane-pal8`, tip **7d9902c** (parent `3d5a737` = merge of lane-kf900 5a28354 into main 8810bad). +Everything below is COMMITTED; nothing is in-flight. + +## What the patch does +`crates/ec-av1/src/decode.rs` `decode_leaf8` (the square 8x8 intra leaf) now passes its +own per-mi palette ctx + colour cache into `read_intra_mode` +(`palette_ctx_and_cache_mi` / `palette_uv_cache_mi`, kf900's per-mi bands), keeps the +returned `PaletteY`/`PaletteUv`, reconstructs through the existing `PALETTE_PRED` slot +(whole 8x8; a per-4x4-TU window slice under a split `tx_depth`; a palette skip leaf takes +the single 8x8 reconstruct), and stamps the leaf's real palette size/colours into the +neighbour bands. New counter `PALETTE_LEAF8_HITS` + getter/reset. +References: `read_palette_mode_info` decodemv.c:567, `read_palette_colors_y/uv` +decodemv.c:478, `av1_visit_palette` / `av1_decode_palette_tokens` decodeframe.c:1135. + +## Refusal targeted / lifted +"a block that actually uses a palette (Y|UV) -- reconstruction is out of scope" is no +longer reachable from `decode_leaf8`. Both strings STAY in `refusal_inventory.rs` -- they +are still live on the inter-frame intra paths (decode.rs 19783/19788, 22479/22484), which +are another lane's scope. No inventory line was removable. + +## Localised, measured, NOT lifted +"a palette block with a real transform on a superblock-level HORZ/VERT strip". I removed +it and re-ran the gate: stream `testsrc2` 128x128 10-bit cq55 `--enable-tx-size-search=0 +--tile-columns=1 --tune-content=screen --enable-palette=1 --min-partition-size=8 +--limit=1` decodes frame 0 with a whole-frame mismatch vs ffmpeg. So the refusal is REAL, +not stale; restored with that measurement in the code comment, and the gate now asserts an +arm still reaches it. Next agent: bisect that stream's first `decode_block_rect64` palette +block with an msac range ladder (the corner-cropped luma path expands `min(bw,32)` x +`min(bh,32)` levels into a `bw`x`bh` grid and reconstructs once, so the prediction shape +already matches the palette buffer -- suspect the residual/scan or class +`refusal-hides-a-defect`). + +## Gate +`a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact` (stream.rs), 48 arms, +GREEN: 44 8x8-leaf palette blocks across 24 arms, 47 arms / 47 frames pixel-exact, +0 out-of-scope mismatches, 1 named refusal (the SB-strip one). + +## Untested / open +- Full suite: 401 passed / 1 failed / 33 ignored. Failure + `a_frame_edge_straddling_band_decodes_pixel_exact` 68x192 cq35 10-bit tile_cols=1, + frame 1, 6944 luma pixels. Attribution unverified -- run that single test at 3d5a737 + first (see lanes/pal8-r1.report.md for the exact command). +- Inter-frame palette (the 19783/22479 sites) untouched. +- The gate is key-frame only (`--limit=1`): the inter frames of this recipe stop on other + lanes' refusals (non-DC chroma on an 8x8 inter leaf; inter 16x16 1:4 partitions). diff --git a/lanes/pal8-r1.report.md b/lanes/pal8-r1.report.md new file mode 100644 index 00000000..1ab021da --- /dev/null +++ b/lanes/pal8-r1.report.md @@ -0,0 +1,94 @@ +# lane-pal8 r1 -- palette on a square 8x8 leaf + +Built on `lane-kf900` 5a28354 (merged first, commit `merge lane-kf900`). + +## What changed + +- `crates/ec-av1/src/decode.rs` `decode_leaf8` (~10680): the square 8x8 leaf now + passes its OWN palette-Y mode ctx + colour cache + (`neighbours.palette_ctx_and_cache_mi(leaf_mi)` / `palette_uv_cache_mi`) into + `read_intra_mode` instead of `None`/`&[]`, and keeps the returned + `PaletteY`/`PaletteUv` instead of dropping them. Mirrors + `read_palette_mode_info` (decodemv.c:567; `av1_get_palette_mode_ctx`, + `av1_get_palette_cache`, `read_palette_colors_y/uv` at decodemv.c:478) and + `av1_decode_palette_tokens` / `av1_visit_palette` (decodeframe.c:1135), whose + colour-index map is read after the whole mode-info read -- both already + implemented in `read_intra_mode`; only this call site was excluded. + `palette_bsize_ctx(8)` is `num_pels_log2 - 6 = 0`, chroma map is the 4x4 + (`ss_size_lookup`) one `read_intra_mode` already decodes at `side / 2`. +- Same fn: reconstruction wired through the existing `PALETTE_PRED` slot -- + whole-block 8x8 buffer for the single-TX8 and skip arms, a per-4x4-TU window + slice under a `tx_depth`-split leaf (the same slicing `decode_block` does at + 16x16 and up); a palette skip leaf takes the single 8x8 reconstruct, never the + per-TU one (`decode_block`'s own `split_tx_skip` rule). +- Same fn: the two `record_palette_y_rect(leaf_mi, 8, 8, 0, [0; 8])` tail sites + now stamp the leaf's REAL palette size/colours into the per-mi neighbour bands + (kf900's bands), so the next block's ctx and colour cache see it. +- New counters `PALETTE_LEAF8_HITS` (+ getter/reset) for the gate. +- `crates/ec-av1/src/stream.rs`: new gate + `a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact`. + +## Refusals + +- LIFTED (for the square 8x8 leaf): `"a block that actually uses a palette (Y) + -- reconstruction is out of scope"` and its UV twin no longer reachable from + `decode_leaf8`. The two strings STAY in `refusal_inventory.rs`: they are still + live on the inter-frame intra paths (decode.rs:19783/19788, 22479/22484), + another lane's scope. No inventory line was removable this round. +- NOT lifted, MEASURED: `"a palette block with a real transform on a + superblock-level HORZ/VERT strip"`. I removed it and re-ran the gate: the arm + `testsrc2-10bit-cq55-txs0-tc1` decodes a whole-frame MISMATCH vs ffmpeg, so + the refusal is real, not stale. Restored, with the measurement recorded in the + code comment, and the gate now HARD-asserts that some arm still reaches it + (`sb_strip_refusals > 0`) so the residue cannot silently disappear. + Disposition: deferred(root-cause of the 64-level-strip palette mismatch -- + bisect the msac range of that stream's first SB-strip palette block, and check + the class `refusal-hides-a-defect`: the mismatch may be an unrelated defect + that the refusal was masking). + +## Gate + +`cargo test -p ec-av1 --lib a_real_aomenc_palette_stream_with_8x8_leaves -- --nocapture` +(`EC_AV1_REQUIRE_AOMENC=1`, oracle `~/.cache/aom-oracle/build/aomenc`). +48 arms: {testsrc2, smptebars} x {8, 10} bit x cq {30,40,55} x +`--enable-tx-size-search` {0,1} x `--tile-columns` {0,1}, 128x128, +`--tune-content=screen --enable-palette=1 --min-partition-size=8 --limit=1` +(key frame; the inter frames of this recipe stop on OTHER lanes' open refusals: +non-DC chroma on an 8x8 inter leaf, inter 16x16 1:4 partitions). Every decoded +frame compared against ffmpeg, `out_of_scope_mismatch == 0` asserted. + +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 +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 + +Before this change the same 8-bit recipe refused with "a block that actually +uses a palette (Y)": measured with `~/.cache/pal8-tmp/enc.sh` + `decode_probe` +on 12 streams before the fix. + +## Suite + +`$HOME/.cache/pal8-suite-r1.log` -- see the tail of this file / the lane report line. + +## Suite (full, `$HOME/.cache/pal8-suite-r1.log`) + +`systemd-run --user --unit=pal8-suite-... -p MemoryMax=10G ... cargo test -p ec-av1 --lib -j3` +-> **401 passed, 1 failed, 33 ignored** in 1443 s. NOT the clean N/0 the charter asks for. + +The one failure is `stream::tests::a_frame_edge_straddling_band_decodes_pixel_exact`: +`68x192 cq35 frames=5 10bit=true tile_cols=1 frame 1 plane Y: 6944 pixels differ, +first at row 28 col 15 (ours 196 vs ffmpeg 197) [edge32=[5,27,0,5,2,16,0,1]]`. +That gate's own source comment already documents the 8-BIT twin of this arm as a +known, separate straddling-band defect ("68x192 cq35 frames=5 10bit=false frame 1 +plane Y: 141 pixels differ ... LUMA, inside the 4-px straddling COLUMN"); the arm +here is the 10-bit one, which the merged lane-kf900 tip added. + +ATTRIBUTION NOT VERIFIED this round (turn cap). It is very unlikely to be this +lane's change -- the whole diff is inert unless a block actually decodes a +palette (`palette_y_buf.is_none()` keeps every non-palette path byte-identical) +-- but the recipe DOES use `--tune-content=screen`, so palette is live in it and +that must be checked, not assumed. Next step, one command: +`git worktree add --detach 3d5a737` (the pre-change merge commit) with +its own `CARGO_TARGET_DIR` and run only +`cargo test -p ec-av1 --lib a_frame_edge_straddling_band_decodes_pixel_exact`. +Disposition: deferred(that one-test run at 3d5a737) -- if it fails there too, it +is the merged straddling-band residue and belongs to that lane; if it passes, +it is this lane's and the 8x8-leaf palette wiring must be bisected against it.