From 4395cbd993d4b9fcd9be6d56b54e0fa02507dd78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 1 Sep 2026 23:59:57 +0300 Subject: [PATCH] fix(av1): no use_filter_intra symbol for a palette-Y block (av1_filter_intra_allowed), and the multi-tile palette gate goes live libaom's av1_filter_intra_allowed also requires palette_size[0] == 0, so it writes no use_filter_intra symbol for a Y-palette block. This decoder read one anyway, desyncing every screen-content stream from its first palette block -- surfacing as a bogus "partition below 8x8"/"HORZ_A below 16x16" refusal further down the tile (refusal-names-a-correlate). Range ladder vs instrumented aomdec: both sides agree through angle_uv at mi(0,8) rng=38738, ours then reads use_filter_intra=1. a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact is un-ignored and green 6/6 with a per-attempt counter (palette_tile_left_hits) proving a palette block fired at a tile's own left column, plus per-arm override proofs (sequence header enable_cdef/enable_restoration; allow_screen_content_tools on the palette arm). r11's charter premise that aomenc keeps the FIRST occurrence of a repeated flag is MEASURED FALSE (last wins) -- extras stay after the base recipe. --- crates/ec-av1/src/decode.rs | 24 +++++++++++ crates/ec-av1/src/stream.rs | 41 +++++++++++++++++- lanes/tiles-r12.report.md | 85 +++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 lanes/tiles-r12.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 4857f4cb..20845c20 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -914,6 +914,19 @@ pub(crate) fn palette_hits() -> usize { PALETTE_HITS.with(|c| c.get()) } +// lane-tiles r12: of those, how many sat at their own TILE's left column -- +// exactly the blocks whose palette cache/ctx must NOT see the previous tile's +// colours (`av1_get_palette_cache`'s `xd->left_mbmi == NULL`). A multi-tile +// palette gate that never hits one proves nothing about the tile guard. +thread_local! { + static PALETTE_TILE_LEFT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`PALETTE_TILE_LEFT_HITS`]. +pub(crate) fn palette_tile_left_hits() -> usize { + PALETTE_TILE_LEFT_HITS.with(|c| c.get()) +} + // lane-palette2 r1: as [`PALETTE_HITS`], for a real (nonzero-size) chroma // palette use -- proves a stream actually reconstructed UV palette pixels, // not just read and refused the `palette_uv_mode` symbol. @@ -5104,8 +5117,15 @@ fn read_intra_mode( // matched bit-exact, then `eob_pt` read 5 instead of 6, because this // symbol's bits were never consumed). let mut filter_intra = None; + // lane-tiles r12: `av1_filter_intra_allowed` (blockd.h) also requires + // `mbmi->palette_mode_info.palette_size[0] == 0` -- libaom writes NO + // `use_filter_intra` symbol for a Y-palette block, and reading one here + // desynced every screen-content stream from the first palette block on + // (it surfaced as a bogus "partition below 8x8" refusal further down the + // tile). if mode == DC_PRED && enable_filter_intra + && palette_y_pending.is_none() && let Some(class) = filter_intra_size_class(side) { let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0; @@ -5688,6 +5708,7 @@ fn decode_block( let (px, py) = (c * SUB, r * SUB); let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); let palette_uv_cache = neighbours.palette_uv_cache(at); + let at_tile_left = c == neighbours.tile_col0_mi / (SUB / MI); let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = read_intra_mode( dec, @@ -5705,6 +5726,9 @@ fn decode_block( r * (SUB / MI), c * (SUB / MI), )?; + if at_tile_left && palette_y.is_some() { + PALETTE_TILE_LEFT_HITS.with(|c| c.set(c.get() + 1)); + } let intrabc_dv = INTRABC_DV.with(|c| c.take()); // libaom `parse_decode_block`: an intrabc block is `inter_block_tx`, so // under `TX_MODE_SELECT` its transform size comes from the inter var-tx diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 3131d5c3..2397de91 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -11145,6 +11145,12 @@ mod tests { bit_depth: usize, frame_count: usize, extra: &[&str], + // lane-tiles r12: the palette arm's own override proof. `true` asserts, + // per attempt, that the arm's `--tune-content=screen --enable-palette=1` + // really reached the encoder (frame header `allow_screen_content_tools`) + // AND that a palette block fired at a TILE's left column -- the exact + // block whose colour cache must not see the previous tile's colours. + require_tile_left_palette: bool, // `None` = the shared `gradients_source`. The palette arm overrides it // with `smptebars`, the flat few-colour source the existing palette // gates use -- gradients never make aomenc pick a palette block. @@ -11268,6 +11274,19 @@ mod tests { let header = match &obu.kind { ObuKind::Frame(h, _) => h, ObuKind::FrameHeader(h) => h, + // lane-tiles r12: prove the base recipe's tools-on + // flags arrived (a repeated aomenc `--enable-*` keeps + // the LAST occurrence -- measured, see the report -- + // so a per-arm override must not silently vanish). + ObuKind::SequenceHeader(seq) => { + assert!( + seq.enable_cdef && seq.enable_restoration, + "{name}: --enable-cdef=1 --enable-restoration=1 did not reach aomenc (seq enable_cdef={} enable_restoration={}, seed {seed})", + seq.enable_cdef, + seq.enable_restoration + ); + continue; + } _ => continue, }; // A `show_existing_frame` header codes no tile info at all @@ -11278,6 +11297,12 @@ mod tests { if header.show_existing_frame { continue; } + if require_tile_left_palette { + assert!( + header.allow_screen_content_tools, + "{name}: --tune-content=screen/--enable-palette=1 did not reach aomenc -- allow_screen_content_tools is 0 (seed {seed})" + ); + } assert_eq!( (header.tile_info.cols * header.tile_info.rows) as usize, expected_tiles, @@ -11292,6 +11317,7 @@ mod tests { } let before = crate::decode::tile_hits(); + let pal_before = crate::decode::palette_tile_left_hits(); let frames = match decode_stream(&stream) { Err(e) => { let msg = e.to_string(); @@ -11330,6 +11356,15 @@ mod tests { assert_eq!(got.u, want.u, "{name} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{name} frame {i} V vs ffmpeg (seed {seed})"); } + if require_tile_left_palette { + let pal = crate::decode::palette_tile_left_hits() - pal_before; + assert!( + pal >= 1, + "{name}: this attempt decoded and matched but fired {pal} palette blocks at \ + a tile's left column -- the tile-relative palette cache guard is untested \ + (seed {seed})" + ); + } matched += 1; } assert!( @@ -11349,6 +11384,7 @@ mod tests { 8, 1, &[], + false, None, ); } @@ -11362,6 +11398,7 @@ mod tests { 10, 1, &[], + false, None, ); } @@ -11398,6 +11435,7 @@ mod tests { // `refusal_inventory.rs`; without these two flags every inter // attempt refuses before a single tile edge is compared. &["--max-partition-size=32", "--enable-tx-size-search=0"], + false, None, ); } @@ -11421,7 +11459,6 @@ mod tests { /// `run_multi_tile_gate`'s args, then this arm should reach a palette /// block on smptebars with rect/ab off. #[test] - #[ignore = "r11: refuses on AB-below-16x16 before a palette block reconstructs; extra-flag override needs to precede the base recipe"] fn a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact() { const NAME: &str = "a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact"; let before = crate::decode::palette_hits(); @@ -11437,6 +11474,7 @@ mod tests { // only"); this arm owns the palette CACHE at a tile edge, so // it takes the square-only path the other palette gates take. "--enable-rect-partitions=0", "--enable-ab-partitions=0"], + true, Some("smptebars"), ); if have_ffmpeg() && have_aomenc() { @@ -11463,6 +11501,7 @@ mod tests { // `refusal_inventory.rs`; without these two flags every inter // attempt refuses before a single tile edge is compared. &["--max-partition-size=32", "--enable-tx-size-search=0"], + false, None, ); } diff --git a/lanes/tiles-r12.report.md b/lanes/tiles-r12.report.md new file mode 100644 index 00000000..dff72660 --- /dev/null +++ b/lanes/tiles-r12.report.md @@ -0,0 +1,85 @@ +# lane-tiles r12 — the palette gate is live; the refusal it hit was a filter-intra desync + +## Charter item 1: REJECTED, with the measurement (do NOT move `extend(extra)`) +The charter (and r11, and a ledger `constraint|` line) states "aomenc keeps the FIRST +occurrence of a repeated flag". **Measured false.** Same input, one frame, 2 tile columns: + +| args | md5 | size | +|---|---|---| +| `--enable-palette=0 --enable-palette=1` | 34b7fe63… | 299 | +| `--enable-palette=1` alone | 34b7fe63… | 299 | +| `--enable-palette=1 --enable-palette=0` | f8339ae1… | 334 | +| `--enable-palette=0` alone | f8339ae1… | 334 | + +The LAST occurrence wins (libaom `aomenc.c` updates the existing entry in +`config->arg_ctrls` in place). The current order — base list, then `extra` — is already +correct; moving `extra` first would silently disable every per-arm override. Not done, and +the ledger line is corrected below. + +EVIDENCE: /tmp/.../scratchpad/p01.obu,p10.obu,p0.obu,p1.obu | aomenc same y4m, 4 flag orders | md5(p01)==md5(p1), md5(p10)==md5(p0) + +## Root cause of the palette arm's refusal: `use_filter_intra` read after a palette block +With the overrides proven to arrive, the palette arm still refused — and the refusal was a +**correlate, not the defect** ("a HORZ_A/… partition below 16x16" with rect/ab OFF is +impossible; the stream had desynced). Isolation, single tile, identical recipe: +`--enable-palette=0` → `OK: 1 frames decoded`; `--enable-palette=1` → refusal. + +Range ladder (instrumented aomdec `EC_TRACE_MODE_STEP` vs ours) diverges inside the first +16x16 palette block, mi(0,8): both sides agree through `angle_uv` (rng=38738); ours then +reads `use_filter_intra=1` (rng→61700) while libaom reads no such symbol. +`av1_filter_intra_allowed` (blockd.h) requires +`mbmi->palette_mode_info.palette_size[0] == 0` — **libaom writes no `use_filter_intra` +symbol for a Y-palette block**, and we consumed one, desyncing the rest of every +screen-content tile from its first palette block on. + +Fix: `crates/ec-av1/src/decode.rs:5120` — `&& palette_y_pending.is_none()` on the +`use_filter_intra` read. + +Class sweep (`filter_intra_size_class*` call sites): the only other reader is +`read_intra_mode_rect` (decode.rs:3661), which refuses screen content wholesale before any +palette syntax, so no palette block can reach it; the two inter-frame intra sites +(decode.rs:12009, 13109) return `unsupported` the moment palette fires. One site, fixed. + +EVIDENCE: /tmp/.../scratchpad/{w0,w1}.obu + ref2.txt/our2.txt | aomenc palette=0/1, same recipe; EC_TRACE_MODE_STEP ladder both decoders | w0 OK / w1 refused before; both OK after; first divergence mi(0,8) rng 38738: oracle no symbol, ours use_filter_intra=1 + +## Charter item 2: `a_real_aomenc_multi_tile_palette_stream…` un-ignored and GREEN +- `#[ignore]` removed; **6/6 attempts pixel-exact vs ffmpeg, 0 refusals**. +- Per-attempt proof added: new counter `palette_tile_left_hits()` (decode.rs:916, bumped at + decode.rs:5715) counts palette-Y blocks at their own tile's left column; the gate asserts + the delta `>= 1` on every attempt that decoded **and** compared. All 6 attempts pass it. +- Override proof (charter item 1's real intent): every arm now asserts the sequence header's + `enable_cdef && enable_restoration` (the base tools-on recipe arrived), and the palette arm + additionally asserts `allow_screen_content_tools` on every frame header (its own + `--tune-content=screen --enable-palette=1` arrived). + +Mutation test on a scratch copy of decode.rs (restored after each run): +- revert **`left_ok`** alone (`c > 0`) → gate still passes: the tile-left guard is + belt-and-braces, because `start_row` wipes the left palette bands before a tile's first row. +- revert **`left_ok` + `start_row`'s palette clear** → gate FAILS (panic at stream.rs:11465). + So the gate does bind the r11 palette-band fix, and the load-bearing half is the + `start_row` clear, not the `left_ok` guard. Stated rather than claimed the other way. + +EVIDENCE: cargo test output | `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib multi_tile -- --test-threads=1`; two mutations of decode.rs re-run | palette arm 6/6 exact; mutation(left_ok) passes, mutation(left_ok+start_row) fails + +## Charter item 3: override-shape sweep of stream.rs +`grep -n "extend(\|\.chain("` near aomenc/ffmpeg arg vectors → 3 sites: +- stream.rs:11234 `run_multi_tile_gate` — extras after base: **correct** (last wins). +- stream.rs:9266 — appends `rate_args`/`depth_args`, no flag repeated with the base list. +- stream.rs:1323 — ffmpeg (`libaom-av1` private options), where a repeated option also takes + the last value (`av_dict_set` overwrite). +Nothing to fix; the shape is safe under last-wins, which is the measured behaviour. + +## Charter item 4: the `#[ignore]`d multi-tile inter arm +Left ignored, with its reproducer. It already carries `--max-partition-size=32 +--enable-tx-size-search=0` (r11), so the charter's suggested flags are the ones it runs with; +the open defect is the seed-42 32x32 block at x[224..255] y[32..63], tile attribution still +unproven. Disposition: **deferred(a decodable single-tile control of the same content)** — +unchanged from r11, no budget spent on it this round. + +## Test totals +See the report footer line appended after the suite run. + +## Files changed +- `crates/ec-av1/src/decode.rs` — filter-intra/palette gating fix; `PALETTE_TILE_LEFT_HITS`. +- `crates/ec-av1/src/stream.rs` — palette arm un-ignored; per-attempt tile-left palette + assert; sequence-header + screen-tools override proofs on every arm.