forge
Explore
Log in

Don't you dare go Hollow

Palette left neighbour/colour cache is tile-relative, not frame-relative

Browse files at this commit

45c1398f02fb30f1be5f1b4b346218d787c31c9cAhmet Kaan GümüşParent: 60a3b42
  • fix
    • palette left neighbour/colour cache is tile-relative, not frame-relative
Show full message
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.rsmodified+18 -2
@@ -2541,7 +2541,13 @@ impl Neighbours {
2541 } else {2541 } else {
2542 (0, [0u16; 8])2542 (0, [0u16; 8])
2543 };2543 };
2544- let (left_n, left_colors) = if self.left_palette_size[r] > 0 {2544+ // lane-tiles r11: `av1_get_palette_cache` takes `xd->left_mbmi`, which
2545+ // is NULL whenever the block sits at its TILE's own left column
2546+ // (`left_available`), not the frame's -- without this guard a second
2547+ // tile column reads the previous tile's palette colours into its cache
2548+ // and its `palette_y_mode` ctx.
2549+ let left_ok = c > self.tile_col0_mi / (SUB / MI);
2550+ let (left_n, left_colors) = if left_ok && self.left_palette_size[r] > 0 {
2545 (self.left_palette_size[r], self.left_palette_colors[r])2551 (self.left_palette_size[r], self.left_palette_colors[r])
2546 } else {2552 } else {
2547 (0, [0u16; 8])2553 (0, [0u16; 8])
@@ -2606,7 +2612,9 @@ impl Neighbours {
2606 } else {2612 } else {
2607 (0, [0u16; 8])2613 (0, [0u16; 8])
2608 };2614 };
2609- let (left_n, left_colors) = if self.left_palette_uv_size[r] > 0 {2615+ // Same tile-relative left availability as the luma cache above.
2616+ let left_ok = c > self.tile_col0_mi / (SUB / MI);
2617+ let (left_n, left_colors) = if left_ok && self.left_palette_uv_size[r] > 0 {
2610 (self.left_palette_uv_size[r], self.left_palette_uv_colors[r])2618 (self.left_palette_uv_size[r], self.left_palette_uv_colors[r])
2611 } else {2619 } else {
2612 (0, [0u16; 8])2620 (0, [0u16; 8])
@@ -2776,6 +2784,14 @@ impl Neighbours {
2776 self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0);2784 self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0);
2777 self.left_compound_idx.iter_mut().for_each(|r| *r = 0);2785 self.left_compound_idx.iter_mut().for_each(|r| *r = 0);
2778 self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]);2786 self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]);
2787+ // lane-tiles r11 (COMMON's NEIGHBOUR MAPS rule): the palette side bands
2788+ // are per-mi maps like every other one here, so they reset with the
2789+ // row too -- the left guard above is what actually stops a cross-tile
2790+ // read, this keeps a stale colour out of the arrays at all.
2791+ self.left_palette_size.iter_mut().for_each(|s| *s = 0);
2792+ self.left_palette_colors.iter_mut().for_each(|c| *c = [0u16; 8]);
2793+ self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0);
2794+ self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]);
2779 }2795 }
2780 2796
2781 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next2797 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next
crates/ec-av1/src/stream.rsmodified+60 -1
@@ -11145,6 +11145,10 @@ mod tests {
11145 bit_depth: usize,11145 bit_depth: usize,
11146 frame_count: usize,11146 frame_count: usize,
11147 extra: &[&str],11147 extra: &[&str],
11148+ // `None` = the shared `gradients_source`. The palette arm overrides it
11149+ // with `smptebars`, the flat few-colour source the existing palette
11150+ // gates use -- gradients never make aomenc pick a palette block.
11151+ source_override: Option<&str>,
11148 ) {11152 ) {
11149 let _gate_lock = lock_gate_counters();11153 let _gate_lock = lock_gate_counters();
11150 if !have_ffmpeg() {11154 if !have_ffmpeg() {
@@ -11166,7 +11170,10 @@ mod tests {
11166 for attempt in 0..n_attempts {11170 for attempt in 0..n_attempts {
11167 let seed = 42 + attempt;11171 let seed = 42 + attempt;
11168 let duration = frame_count as f64 / 25.0;11172 let duration = frame_count as f64 / 25.0;
11169- let source = gradients_source(seed, width, height, &format!("duration={duration}:rate=25"));11173+ let source = match source_override {
11174+ Some(src) => format!("{src}=size={width}x{height}:duration={duration}:rate=25"),
11175+ None => gradients_source(seed, width, height, &format!("duration={duration}:rate=25")),
11176+ };
11170 let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };11177 let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
11171 let y4m = Command::new("ffmpeg")11178 let y4m = Command::new("ffmpeg")
11172 .args([11179 .args([
@@ -11217,6 +11224,8 @@ mod tests {
11217 // vacuous rather than proving anything about tiles.11224 // vacuous rather than proving anything about tiles.
11218 "--enable-1to4-partitions=0",11225 "--enable-1to4-partitions=0",
11219 "--min-partition-size=16",11226 "--min-partition-size=16",
11227+ // Overridable by `extra` (aomenc takes the last occurrence of
11228+ // a repeated flag), which the palette arm below relies on.
11220 "--enable-palette=0",11229 "--enable-palette=0",
11221 "--enable-intrabc=0",11230 "--enable-intrabc=0",
11222 "--enable-ref-frame-mvs=0",11231 "--enable-ref-frame-mvs=0",
@@ -11340,6 +11349,7 @@ mod tests {
11340 8,11349 8,
11341 1,11350 1,
11342 &[],11351 &[],
11352+ None,
11343 );11353 );
11344 }11354 }
11345 11355
@@ -11352,6 +11362,7 @@ mod tests {
11352 10,11362 10,
11353 1,11363 1,
11354 &[],11364 &[],
11365+ None,
11355 );11366 );
11356 }11367 }
11357 11368
@@ -11387,9 +11398,56 @@ mod tests {
11387 // `refusal_inventory.rs`; without these two flags every inter11398 // `refusal_inventory.rs`; without these two flags every inter
11388 // attempt refuses before a single tile edge is compared.11399 // attempt refuses before a single tile edge is compared.
11389 &["--max-partition-size=32", "--enable-tx-size-search=0"],11400 &["--max-partition-size=32", "--enable-tx-size-search=0"],
11401+ None,
11390 );11402 );
11391 }11403 }
11392 11404
11405+ /// lane-tiles r11, the defect this arm exists for: `palette_ctx_and_cache`
11406+ /// / `palette_uv_cache` (`decode.rs`) read the LEFT palette neighbour with
11407+ /// no availability guard at all, where libaom's `av1_get_palette_cache`
11408+ /// takes `xd->left_mbmi`, which is NULL at the block's own TILE left
11409+ /// column. A second tile column therefore inherited the previous tile's
11410+ /// palette colours and `palette_y_mode` ctx. Screen content is what makes
11411+ /// aomenc pick palette at all, so this arm drives `--tune-content=screen
11412+ /// --enable-palette=1` over a 2-column grid and asserts a real palette
11413+ /// block actually fired.
11414+ /// `#[ignore]`d at r11 and NOT yet proof of the fix: with the broad tool
11415+ /// set every seed refuses before a palette block reconstructs
11416+ /// ("a HORZ_A/HORZ_B/VERT_A partition below 16x16"), and the per-arm
11417+ /// `extra` overrides do not switch the base recipe's tools off -- aomenc
11418+ /// keeps the FIRST occurrence of a repeated `--enable-*` flag (measured:
11419+ /// appending `--enable-rect-partitions=0` after the base `=1` changed the
11420+ /// refusal not at all). Next round: put `extra` BEFORE the base list in
11421+ /// `run_multi_tile_gate`'s args, then this arm should reach a palette
11422+ /// block on smptebars with rect/ab off.
11423+ #[test]
11424+ #[ignore = "r11: refuses on AB-below-16x16 before a palette block reconstructs; extra-flag override needs to precede the base recipe"]
11425+ fn a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact() {
11426+ const NAME: &str = "a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact";
11427+ let before = crate::decode::palette_hits();
11428+ run_multi_tile_gate(
11429+ NAME,
11430+ 1,
11431+ 0,
11432+ 8,
11433+ 1,
11434+ &["--enable-palette=1", "--tune-content=screen", "--cq-level=30", "--enable-tx-size-search=0", "--max-partition-size=32",
11435+ // Screen content + rect strips is a separate, pre-existing
11436+ // refusal ("palette syntax is consumed for square blocks
11437+ // only"); this arm owns the palette CACHE at a tile edge, so
11438+ // it takes the square-only path the other palette gates take.
11439+ "--enable-rect-partitions=0", "--enable-ab-partitions=0"],
11440+ Some("smptebars"),
11441+ );
11442+ if have_ffmpeg() && have_aomenc() {
11443+ assert!(
11444+ crate::decode::palette_hits() > before,
11445+ "{NAME}: no palette block fired -- the gate proves nothing about the palette \
11446+ cache at a tile edge"
11447+ );
11448+ }
11449+ }
11450+
11393 #[test]11451 #[test]
11394 fn a_real_aomenc_multi_tile_inter_10bit_stream_decodes_pixel_exact() {11452 fn a_real_aomenc_multi_tile_inter_10bit_stream_decodes_pixel_exact() {
11395 run_multi_tile_gate(11453 run_multi_tile_gate(
@@ -11405,6 +11463,7 @@ mod tests {
11405 // `refusal_inventory.rs`; without these two flags every inter11463 // `refusal_inventory.rs`; without these two flags every inter
11406 // attempt refuses before a single tile edge is compared.11464 // attempt refuses before a single tile edge is compared.
11407 &["--max-partition-size=32", "--enable-tx-size-search=0"],11465 &["--max-partition-size=32", "--enable-tx-size-search=0"],
11466+ None,
11408 );11467 );
11409 }11468 }
11410 }11469 }
lanes/tiles-r11.report.mdmodified+28 -0
@@ -102,3 +102,31 @@ band. Nothing to fix — recorded so the next lane does not re-sweep it.
102 102
103 ## Commit103 ## Commit
104 - 2e73186 on `lane-tiles`. Never pushed, never merged, main untouched.104 - 2e73186 on `lane-tiles`. Never pushed, never merged, main untouched.
105+
106+## Coordinator items received mid-round (after the r11 commit)
107+1. **Palette left neighbour has no tile guard — CONFIRMED and FIXED.**
108+ `decode.rs` `palette_ctx_and_cache` and `palette_uv_cache` read
109+ `left_palette_size[r]` / `left_palette_uv_size[r]` with **no availability guard at
110+ all**, where libaom's `av1_get_palette_cache` takes `xd->left_mbmi`, NULL at the
111+ block's own tile left column. Fixed with `let left_ok = c > self.tile_col0_mi / (SUB / MI);`
112+ on both (`at` is in SUB units, so the mi-unit tile origin is divided the same way
113+ `start_tile` divides `col0_mi` for `above_mode`). `start_row` also never cleared
114+ `left_palette_*`/`left_palette_uv_*`; it does now (COMMON's NEIGHBOUR MAPS rule 2).
115+ Status: **code-verified** — 54 tile tests + gate_coverage green, no gate yet proves it.
116+2. **Palette + screen-content multi-tile arm — written, `#[ignore]`d, NOT yet proof.**
117+ `a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact` (smptebars, 2 tile
118+ columns, `--tune-content=screen --enable-palette=1`, asserts `palette_hits` rose).
119+ It currently refuses on every seed before a palette block reconstructs, because the
120+ per-arm `extra` flags do NOT override the base recipe: **aomenc keeps the FIRST
121+ occurrence of a repeated `--enable-*` flag** (measured — appending
122+ `--enable-rect-partitions=0` after the base `=1` changed the refusal not at all).
123+ Fix next round: move `args.extend(extra)` to precede the base list in
124+ `run_multi_tile_gate`. Disposition: **deferred(one edit — extra before base)**.
125+3. **lane-ab16's `--tile-columns=1` mismatch (mandelbrot 96x96, x=32..63 y=80..95)** —
126+ NOT reproduced this round. Disposition: **deferred(tool-call cap)**.
127+4. **Frame-relative `mi_row > 0` / `mi_col > 0` guards at decode.rs ~8547-8548 and
128+ mvstack.rs ~727,733,742,756,1486,1492,1501,1515** — NOT swept. mvstack has no tile
129+ origin plumbed in at all, so this is a signature change plus a call-site sweep, and
130+ it needs a multi-tile INTER gate to show — the arm that is `#[ignore]`d above for an
131+ unrelated open defect. Disposition: **deferred(next round; needs tile bounds threaded
132+ into mvstack, then the inter multi-tile arm re-enabled to measure)**.