From 3a302e703f7738b15b5f64e3fef7f951620187e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 5 Sep 2026 00:51:00 +0300 Subject: [PATCH] fix(av1): a non-skip palette block on a superblock-level strip lost its UV prediction `decode_block_rect64` built the UV-palette prediction buffers and installed them into the PALETTE_PRED slot only in its `skip` arm. The non-skip arm reconstructed both chroma planes straight from `reconstruct_rect`'s edge prediction, so a palette block with a real residual on a 64x32/32x64 strip decoded its luma exactly and both chroma planes wrong -- which is why the shape was refused by name ("corner-cropped luma coefficients not ported for palette", a misattribution: the corner crop was never the defect). FIRST BAD: testsrc2 128x128 10-bit cq55 `--tune-content=screen --enable-palette=1 --min-partition-size=8 --sb-size=64 --tile-columns=1 --enable-tx-size-search=0`, the 32x64 strip at px=96: luma byte-exact, U/V each 512 samples wrong over the block's 16x32 chroma footprint. Installing the per-plane override right before each chroma `reconstruct_rect`, exactly as the `skip` arm does, makes the frame byte-exact against ffmpeg. Class: an override slot installed on one arm of a skip/non-skip split. Swept every palette+residual reconstruct path in decode.rs (rect, rect4, rect_split, leaf_rect, leaf8, block, inter_block, inter_block8): this was the only site missing the install. The gate that documented the refusal now asserts zero refusals and a non-zero superblock-strip palette count; inventory row deleted. --- crates/ec-av1/src/decode.rs | 34 +++++++++++++------------- crates/ec-av1/src/refusal_inventory.rs | 11 --------- crates/ec-av1/src/stream.rs | 14 +++++++---- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index ec33b4d2..5f33e5db 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -10416,24 +10416,11 @@ fn decode_block_rect64( c * (SUB / MI), fctx, )?; if (palette_y.is_some() || palette_uv.is_some()) && !skip { - // The luma coefficient path here is the corner-cropped 32x32 real - // transform embedded in a 64x32/32x64 grid ([`decode_block_rect64`]'s - // own doc comment) -- a real (non-skip) palette block's residual - // 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. + // lane-t900 r34: a non-skip palette block on a superblock-level strip + // -- counted so its gate cannot go vacuous (this was a refusal until + // r34; see the gate `a_real_aomenc_palette_stream_with_8x8_leaves_ + // decodes_pixel_exact`). 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)", - )); } let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode); if smooth_neighbor { @@ -10817,6 +10804,16 @@ fn decode_block_rect64( plane_q_delta(1, fctx).1, u_tx_type, ); + // lane-t900 r34: the UV-palette prediction override, exactly as the + // `skip` arm above installs it. The [`PALETTE_PRED`] slot is a + // set-then-take, so it must be filled again right before each plane's + // own reconstruct; leaving this out of the non-skip arm predicted a + // palette block's chroma off its block edges (measured: testsrc2 + // 128x128 10-bit cq55 `--tile-columns=1`, the 32x64 strip at px=96 -- + // luma exact, both chroma planes wrong over its whole 16x32). + if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone(), fctx); + } u.reconstruct_rect( cpx, cpy, @@ -10871,6 +10868,9 @@ fn decode_block_rect64( plane_q_delta(2, fctx).1, v_tx_type, ); + if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone(), fctx); + } v.reconstruct_rect( cpx, cpy, diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 7df900cd..cd1eec6b 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -43,7 +43,6 @@ const REFUSALS: &[&str] = &[ "a 128x128 superblock partition value outside the 8-symbol alphabet", "an inter var-tx tree with a leaf transform larger than 64x64", "CfL, filter intra or a palette on a 128-root HORZ/VERT intra block (every one of their size gates caps at 64x64 or below, so none of these symbols exists there)", - "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", // lane-t900 r23: palette RECONSTRUCTION now covers the key-frame paths // (earlier lanes), the intra-in-inter square/rect paths (r22) and the // 8x8 LEAF inside an inter frame (this round, gate @@ -371,16 +370,6 @@ const PROVEN: &[(&str, &str)] = &[ "CfL, filter intra or a palette on a 128-root HORZ/VERT intra block (every one of their size gates caps at 64x64 or below, so none of these symbols exists there)", "no_128_root_half_reads_a_cfl_filter_intra_or_palette_symbol", ), - // lane-t900 r33, WITNESS of a capability gap: the refusal is REACHED by - // real `--tune-content=screen --enable-palette=1` streams, counted - // (`palette_sb_strip_hits`) and hard-asserted non-zero by its gate, which - // also decodes the arms that do not reach it pixel-exact. lane-pal8 r1 - // measured the lift and it mismatches whole-frame, so the string names a - // real shape a real encoder writes -- an open capability, not a claim. - ( - "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", - "a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact", - ), // lane-t900 r33, CENSUS: the `use_intrabc` symbol IS read at the sub-8 // reader for every sub-8x8 leaf of an `allow_intrabc` frame, and over the // `--min-partition-size=4` exact-repetition screen arms every such symbol diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index ea68982f..2ade4c0e 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -4141,8 +4141,8 @@ mod tests { (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). + // lane-t900 r34 LIFTED this shape; the counter stays so the gate + // fails loudly if the refusal ever comes back. let mut sb_strip_refusals = 0u32; for src in ["testsrc2", "smptebars"] { for depth in [8usize, 10usize] { @@ -4322,10 +4322,14 @@ mod tests { leaf8_total > 0 && fired_arms > 0, "{NAME}: gate is vacuous -- no compared arm decoded an 8x8-leaf palette block" ); + assert_eq!( + sb_strip_refusals, 0, + "{NAME}: the superblock-strip palette refusal is back (lane-t900 r34 lifted it)" + ); assert!( - sb_strip_refusals > 0, - "{NAME}: no arm reached the superblock-strip palette refusal -- the open residue \ - this gate documents is no longer exercised" + sb_strip_arms > 0 && sb_strip_total > 0, + "{NAME}: no arm decoded a non-skip palette block on a superblock-level strip -- \ + the shape r34 lifted is no longer exercised" ); assert_eq!( out_of_scope_mismatch, 0,