From 45c1398f02fb30f1be5f1b4b346218d787c31c9c 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:40:20 +0300 Subject: [PATCH] fix(av1): palette left neighbour/colour cache is tile-relative, not frame-relative `palette_ctx_and_cache` and `palette_uv_cache` read the LEFT palette size and colours with no availability guard at all, where libaom's `av1_get_palette_cache` takes `xd->left_mbmi` -- NULL whenever the block sits at its own TILE's left column. A second tile column therefore inherited the previous tile's palette colours into its cache and its `palette_y_mode` context. Guarded with `c > tile_col0_mi / (SUB / MI)` on both, and `Neighbours::start_row` now clears the four palette side bands it always skipped. Also adds the multi-tile palette gate arm (smptebars, 2 tile columns, screen content), `#[ignore]`d: it refuses before a palette block reconstructs because aomenc keeps the FIRST occurrence of a repeated --enable-* flag, so the arm's overrides never take. One edit next round (extra before the base recipe). Tile suite 54/54 green, gate_coverage 5/5. --- crates/ec-av1/src/decode.rs | 20 ++++++++++-- crates/ec-av1/src/stream.rs | 61 ++++++++++++++++++++++++++++++++++++- lanes/tiles-r11.report.md | 28 +++++++++++++++++ 3 files changed, 106 insertions(+), 3 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 044d1d7e..4857f4cb 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2541,7 +2541,13 @@ impl Neighbours { } else { (0, [0u16; 8]) }; - let (left_n, left_colors) = if self.left_palette_size[r] > 0 { + // lane-tiles r11: `av1_get_palette_cache` takes `xd->left_mbmi`, which + // is NULL whenever the block sits at its TILE's own left column + // (`left_available`), not the frame's -- without this guard a second + // tile column reads the previous tile's palette colours into its cache + // and its `palette_y_mode` ctx. + let left_ok = c > self.tile_col0_mi / (SUB / MI); + let (left_n, left_colors) = if left_ok && self.left_palette_size[r] > 0 { (self.left_palette_size[r], self.left_palette_colors[r]) } else { (0, [0u16; 8]) @@ -2606,7 +2612,9 @@ impl Neighbours { } else { (0, [0u16; 8]) }; - let (left_n, left_colors) = if self.left_palette_uv_size[r] > 0 { + // Same tile-relative left availability as the luma cache above. + let left_ok = c > self.tile_col0_mi / (SUB / MI); + let (left_n, left_colors) = if left_ok && self.left_palette_uv_size[r] > 0 { (self.left_palette_uv_size[r], self.left_palette_uv_colors[r]) } else { (0, [0u16; 8]) @@ -2776,6 +2784,14 @@ impl Neighbours { self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0); self.left_compound_idx.iter_mut().for_each(|r| *r = 0); self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]); + // lane-tiles r11 (COMMON's NEIGHBOUR MAPS rule): the palette side bands + // are per-mi maps like every other one here, so they reset with the + // row too -- the left guard above is what actually stops a cross-tile + // read, this keeps a stale colour out of the arrays at all. + self.left_palette_size.iter_mut().for_each(|s| *s = 0); + self.left_palette_colors.iter_mut().for_each(|c| *c = [0u16; 8]); + self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0); + self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]); } /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 9e53333f..3131d5c3 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -11145,6 +11145,10 @@ mod tests { bit_depth: usize, frame_count: usize, extra: &[&str], + // `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. + source_override: Option<&str>, ) { let _gate_lock = lock_gate_counters(); if !have_ffmpeg() { @@ -11166,7 +11170,10 @@ mod tests { for attempt in 0..n_attempts { let seed = 42 + attempt; let duration = frame_count as f64 / 25.0; - let source = gradients_source(seed, width, height, &format!("duration={duration}:rate=25")); + let source = match source_override { + Some(src) => format!("{src}=size={width}x{height}:duration={duration}:rate=25"), + None => gradients_source(seed, width, height, &format!("duration={duration}:rate=25")), + }; let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; let y4m = Command::new("ffmpeg") .args([ @@ -11217,6 +11224,8 @@ mod tests { // vacuous rather than proving anything about tiles. "--enable-1to4-partitions=0", "--min-partition-size=16", + // Overridable by `extra` (aomenc takes the last occurrence of + // a repeated flag), which the palette arm below relies on. "--enable-palette=0", "--enable-intrabc=0", "--enable-ref-frame-mvs=0", @@ -11340,6 +11349,7 @@ mod tests { 8, 1, &[], + None, ); } @@ -11352,6 +11362,7 @@ mod tests { 10, 1, &[], + None, ); } @@ -11387,9 +11398,56 @@ 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"], + None, ); } + /// lane-tiles r11, the defect this arm exists for: `palette_ctx_and_cache` + /// / `palette_uv_cache` (`decode.rs`) read the LEFT palette neighbour with + /// no availability guard at all, where libaom's `av1_get_palette_cache` + /// takes `xd->left_mbmi`, which is NULL at the block's own TILE left + /// column. A second tile column therefore inherited the previous tile's + /// palette colours and `palette_y_mode` ctx. Screen content is what makes + /// aomenc pick palette at all, so this arm drives `--tune-content=screen + /// --enable-palette=1` over a 2-column grid and asserts a real palette + /// block actually fired. + /// `#[ignore]`d at r11 and NOT yet proof of the fix: with the broad tool + /// set every seed refuses before a palette block reconstructs + /// ("a HORZ_A/HORZ_B/VERT_A partition below 16x16"), and the per-arm + /// `extra` overrides do not switch the base recipe's tools off -- aomenc + /// keeps the FIRST occurrence of a repeated `--enable-*` flag (measured: + /// appending `--enable-rect-partitions=0` after the base `=1` changed the + /// refusal not at all). Next round: put `extra` BEFORE the base list in + /// `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(); + run_multi_tile_gate( + NAME, + 1, + 0, + 8, + 1, + &["--enable-palette=1", "--tune-content=screen", "--cq-level=30", "--enable-tx-size-search=0", "--max-partition-size=32", + // Screen content + rect strips is a separate, pre-existing + // refusal ("palette syntax is consumed for square blocks + // 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"], + Some("smptebars"), + ); + if have_ffmpeg() && have_aomenc() { + assert!( + crate::decode::palette_hits() > before, + "{NAME}: no palette block fired -- the gate proves nothing about the palette \ + cache at a tile edge" + ); + } + } + #[test] fn a_real_aomenc_multi_tile_inter_10bit_stream_decodes_pixel_exact() { run_multi_tile_gate( @@ -11405,6 +11463,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"], + None, ); } } diff --git a/lanes/tiles-r11.report.md b/lanes/tiles-r11.report.md index 34c3886b..2d229e6c 100644 --- a/lanes/tiles-r11.report.md +++ b/lanes/tiles-r11.report.md @@ -102,3 +102,31 @@ band. Nothing to fix — recorded so the next lane does not re-sweep it. ## Commit - 2e73186 on `lane-tiles`. Never pushed, never merged, main untouched. + +## Coordinator items received mid-round (after the r11 commit) +1. **Palette left neighbour has no tile guard — CONFIRMED and FIXED.** + `decode.rs` `palette_ctx_and_cache` and `palette_uv_cache` read + `left_palette_size[r]` / `left_palette_uv_size[r]` with **no availability guard at + all**, where libaom's `av1_get_palette_cache` takes `xd->left_mbmi`, NULL at the + block's own tile left column. Fixed with `let left_ok = c > self.tile_col0_mi / (SUB / MI);` + on both (`at` is in SUB units, so the mi-unit tile origin is divided the same way + `start_tile` divides `col0_mi` for `above_mode`). `start_row` also never cleared + `left_palette_*`/`left_palette_uv_*`; it does now (COMMON's NEIGHBOUR MAPS rule 2). + Status: **code-verified** — 54 tile tests + gate_coverage green, no gate yet proves it. +2. **Palette + screen-content multi-tile arm — written, `#[ignore]`d, NOT yet proof.** + `a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact` (smptebars, 2 tile + columns, `--tune-content=screen --enable-palette=1`, asserts `palette_hits` rose). + It currently refuses on every seed before a palette block reconstructs, because the + per-arm `extra` flags do NOT override the base recipe: **aomenc keeps the FIRST + occurrence of a repeated `--enable-*` flag** (measured — appending + `--enable-rect-partitions=0` after the base `=1` changed the refusal not at all). + Fix next round: move `args.extend(extra)` to precede the base list in + `run_multi_tile_gate`. Disposition: **deferred(one edit — extra before base)**. +3. **lane-ab16's `--tile-columns=1` mismatch (mandelbrot 96x96, x=32..63 y=80..95)** — + NOT reproduced this round. Disposition: **deferred(tool-call cap)**. +4. **Frame-relative `mi_row > 0` / `mi_col > 0` guards at decode.rs ~8547-8548 and + mvstack.rs ~727,733,742,756,1486,1492,1501,1515** — NOT swept. mvstack has no tile + origin plumbed in at all, so this is a signature change plus a call-site sweep, and + it needs a multi-tile INTER gate to show — the arm that is `#[ignore]`d above for an + unrelated open defect. Disposition: **deferred(next round; needs tile bounds threaded + into mvstack, then the inter multi-tile arm re-enabled to measure)**.