No use_filter_intra symbol for a palette-Y block (av1_filter_intra_allowed), and the multi-tile palette gate goes live
Browse files at this commit4395cbd993d4b9fcd9be6d56b54e0fa02507dd78Parent: 45c1398- fix
- no use_filter_intra symbol for a palette-Y block (av1_filter_intra_allowed), and the multi-tile palette gate goes live
3 changed files +149 -1
- crates/ec-av1/src/decode.rs +24 -0
- crates/ec-av1/src/stream.rs +40 -1
- lanes/tiles-r12.report.md +85 -0
crates/ec-av1/src/decode.rsmodified+24 -0
| @@ -914,6 +914,19 @@ pub(crate) fn palette_hits() -> usize { | ||
| 914 | 914 | PALETTE_HITS.with(|c| c.get()) |
| 915 | 915 | } |
| 916 | 916 | |
| 917 | +// lane-tiles r12: of those, how many sat at their own TILE's left column -- | |
| 918 | +// exactly the blocks whose palette cache/ctx must NOT see the previous tile's | |
| 919 | +// colours (`av1_get_palette_cache`'s `xd->left_mbmi == NULL`). A multi-tile | |
| 920 | +// palette gate that never hits one proves nothing about the tile guard. | |
| 921 | +thread_local! { | |
| 922 | + static PALETTE_TILE_LEFT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 923 | +} | |
| 924 | + | |
| 925 | +/// Current value of [`PALETTE_TILE_LEFT_HITS`]. | |
| 926 | +pub(crate) fn palette_tile_left_hits() -> usize { | |
| 927 | + PALETTE_TILE_LEFT_HITS.with(|c| c.get()) | |
| 928 | +} | |
| 929 | + | |
| 917 | 930 | // lane-palette2 r1: as [`PALETTE_HITS`], for a real (nonzero-size) chroma |
| 918 | 931 | // palette use -- proves a stream actually reconstructed UV palette pixels, |
| 919 | 932 | // not just read and refused the `palette_uv_mode` symbol. |
| @@ -5104,8 +5117,15 @@ fn read_intra_mode( | ||
| 5104 | 5117 | // matched bit-exact, then `eob_pt` read 5 instead of 6, because this |
| 5105 | 5118 | // symbol's bits were never consumed). |
| 5106 | 5119 | let mut filter_intra = None; |
| 5120 | + // lane-tiles r12: `av1_filter_intra_allowed` (blockd.h) also requires | |
| 5121 | + // `mbmi->palette_mode_info.palette_size[0] == 0` -- libaom writes NO | |
| 5122 | + // `use_filter_intra` symbol for a Y-palette block, and reading one here | |
| 5123 | + // desynced every screen-content stream from the first palette block on | |
| 5124 | + // (it surfaced as a bogus "partition below 8x8" refusal further down the | |
| 5125 | + // tile). | |
| 5107 | 5126 | if mode == DC_PRED |
| 5108 | 5127 | && enable_filter_intra |
| 5128 | + && palette_y_pending.is_none() | |
| 5109 | 5129 | && let Some(class) = filter_intra_size_class(side) |
| 5110 | 5130 | { |
| 5111 | 5131 | let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0; |
| @@ -5688,6 +5708,7 @@ fn decode_block( | ||
| 5688 | 5708 | let (px, py) = (c * SUB, r * SUB); |
| 5689 | 5709 | let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); |
| 5690 | 5710 | let palette_uv_cache = neighbours.palette_uv_cache(at); |
| 5711 | + let at_tile_left = c == neighbours.tile_col0_mi / (SUB / MI); | |
| 5691 | 5712 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = |
| 5692 | 5713 | read_intra_mode( |
| 5693 | 5714 | dec, |
| @@ -5705,6 +5726,9 @@ fn decode_block( | ||
| 5705 | 5726 | r * (SUB / MI), |
| 5706 | 5727 | c * (SUB / MI), |
| 5707 | 5728 | )?; |
| 5729 | + if at_tile_left && palette_y.is_some() { | |
| 5730 | + PALETTE_TILE_LEFT_HITS.with(|c| c.set(c.get() + 1)); | |
| 5731 | + } | |
| 5708 | 5732 | let intrabc_dv = INTRABC_DV.with(|c| c.take()); |
| 5709 | 5733 | // libaom `parse_decode_block`: an intrabc block is `inter_block_tx`, so |
| 5710 | 5734 | // under `TX_MODE_SELECT` its transform size comes from the inter var-tx |
crates/ec-av1/src/stream.rsmodified+40 -1
| @@ -11145,6 +11145,12 @@ mod tests { | ||
| 11145 | 11145 | bit_depth: usize, |
| 11146 | 11146 | frame_count: usize, |
| 11147 | 11147 | extra: &[&str], |
| 11148 | + // lane-tiles r12: the palette arm's own override proof. `true` asserts, | |
| 11149 | + // per attempt, that the arm's `--tune-content=screen --enable-palette=1` | |
| 11150 | + // really reached the encoder (frame header `allow_screen_content_tools`) | |
| 11151 | + // AND that a palette block fired at a TILE's left column -- the exact | |
| 11152 | + // block whose colour cache must not see the previous tile's colours. | |
| 11153 | + require_tile_left_palette: bool, | |
| 11148 | 11154 | // `None` = the shared `gradients_source`. The palette arm overrides it |
| 11149 | 11155 | // with `smptebars`, the flat few-colour source the existing palette |
| 11150 | 11156 | // gates use -- gradients never make aomenc pick a palette block. |
| @@ -11268,6 +11274,19 @@ mod tests { | ||
| 11268 | 11274 | let header = match &obu.kind { |
| 11269 | 11275 | ObuKind::Frame(h, _) => h, |
| 11270 | 11276 | ObuKind::FrameHeader(h) => h, |
| 11277 | + // lane-tiles r12: prove the base recipe's tools-on | |
| 11278 | + // flags arrived (a repeated aomenc `--enable-*` keeps | |
| 11279 | + // the LAST occurrence -- measured, see the report -- | |
| 11280 | + // so a per-arm override must not silently vanish). | |
| 11281 | + ObuKind::SequenceHeader(seq) => { | |
| 11282 | + assert!( | |
| 11283 | + seq.enable_cdef && seq.enable_restoration, | |
| 11284 | + "{name}: --enable-cdef=1 --enable-restoration=1 did not reach aomenc (seq enable_cdef={} enable_restoration={}, seed {seed})", | |
| 11285 | + seq.enable_cdef, | |
| 11286 | + seq.enable_restoration | |
| 11287 | + ); | |
| 11288 | + continue; | |
| 11289 | + } | |
| 11271 | 11290 | _ => continue, |
| 11272 | 11291 | }; |
| 11273 | 11292 | // A `show_existing_frame` header codes no tile info at all |
| @@ -11278,6 +11297,12 @@ mod tests { | ||
| 11278 | 11297 | if header.show_existing_frame { |
| 11279 | 11298 | continue; |
| 11280 | 11299 | } |
| 11300 | + if require_tile_left_palette { | |
| 11301 | + assert!( | |
| 11302 | + header.allow_screen_content_tools, | |
| 11303 | + "{name}: --tune-content=screen/--enable-palette=1 did not reach aomenc -- allow_screen_content_tools is 0 (seed {seed})" | |
| 11304 | + ); | |
| 11305 | + } | |
| 11281 | 11306 | assert_eq!( |
| 11282 | 11307 | (header.tile_info.cols * header.tile_info.rows) as usize, |
| 11283 | 11308 | expected_tiles, |
| @@ -11292,6 +11317,7 @@ mod tests { | ||
| 11292 | 11317 | } |
| 11293 | 11318 | |
| 11294 | 11319 | let before = crate::decode::tile_hits(); |
| 11320 | + let pal_before = crate::decode::palette_tile_left_hits(); | |
| 11295 | 11321 | let frames = match decode_stream(&stream) { |
| 11296 | 11322 | Err(e) => { |
| 11297 | 11323 | let msg = e.to_string(); |
| @@ -11330,6 +11356,15 @@ mod tests { | ||
| 11330 | 11356 | assert_eq!(got.u, want.u, "{name} frame {i} U vs ffmpeg (seed {seed})"); |
| 11331 | 11357 | assert_eq!(got.v, want.v, "{name} frame {i} V vs ffmpeg (seed {seed})"); |
| 11332 | 11358 | } |
| 11359 | + if require_tile_left_palette { | |
| 11360 | + let pal = crate::decode::palette_tile_left_hits() - pal_before; | |
| 11361 | + assert!( | |
| 11362 | + pal >= 1, | |
| 11363 | + "{name}: this attempt decoded and matched but fired {pal} palette blocks at \ | |
| 11364 | + a tile's left column -- the tile-relative palette cache guard is untested \ | |
| 11365 | + (seed {seed})" | |
| 11366 | + ); | |
| 11367 | + } | |
| 11333 | 11368 | matched += 1; |
| 11334 | 11369 | } |
| 11335 | 11370 | assert!( |
| @@ -11349,6 +11384,7 @@ mod tests { | ||
| 11349 | 11384 | 8, |
| 11350 | 11385 | 1, |
| 11351 | 11386 | &[], |
| 11387 | + false, | |
| 11352 | 11388 | None, |
| 11353 | 11389 | ); |
| 11354 | 11390 | } |
| @@ -11362,6 +11398,7 @@ mod tests { | ||
| 11362 | 11398 | 10, |
| 11363 | 11399 | 1, |
| 11364 | 11400 | &[], |
| 11401 | + false, | |
| 11365 | 11402 | None, |
| 11366 | 11403 | ); |
| 11367 | 11404 | } |
| @@ -11398,6 +11435,7 @@ mod tests { | ||
| 11398 | 11435 | // `refusal_inventory.rs`; without these two flags every inter |
| 11399 | 11436 | // attempt refuses before a single tile edge is compared. |
| 11400 | 11437 | &["--max-partition-size=32", "--enable-tx-size-search=0"], |
| 11438 | + false, | |
| 11401 | 11439 | None, |
| 11402 | 11440 | ); |
| 11403 | 11441 | } |
| @@ -11421,7 +11459,6 @@ mod tests { | ||
| 11421 | 11459 | /// `run_multi_tile_gate`'s args, then this arm should reach a palette |
| 11422 | 11460 | /// block on smptebars with rect/ab off. |
| 11423 | 11461 | #[test] |
| 11424 | - #[ignore = "r11: refuses on AB-below-16x16 before a palette block reconstructs; extra-flag override needs to precede the base recipe"] | |
| 11425 | 11462 | fn a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact() { |
| 11426 | 11463 | const NAME: &str = "a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact"; |
| 11427 | 11464 | let before = crate::decode::palette_hits(); |
| @@ -11437,6 +11474,7 @@ mod tests { | ||
| 11437 | 11474 | // only"); this arm owns the palette CACHE at a tile edge, so |
| 11438 | 11475 | // it takes the square-only path the other palette gates take. |
| 11439 | 11476 | "--enable-rect-partitions=0", "--enable-ab-partitions=0"], |
| 11477 | + true, | |
| 11440 | 11478 | Some("smptebars"), |
| 11441 | 11479 | ); |
| 11442 | 11480 | if have_ffmpeg() && have_aomenc() { |
| @@ -11463,6 +11501,7 @@ mod tests { | ||
| 11463 | 11501 | // `refusal_inventory.rs`; without these two flags every inter |
| 11464 | 11502 | // attempt refuses before a single tile edge is compared. |
| 11465 | 11503 | &["--max-partition-size=32", "--enable-tx-size-search=0"], |
| 11504 | + false, | |
| 11466 | 11505 | None, |
| 11467 | 11506 | ); |
| 11468 | 11507 | } |
lanes/tiles-r12.report.mdadded+85 -0
| @@ -0,0 +1,85 @@ | ||
| 1 | +# lane-tiles r12 — the palette gate is live; the refusal it hit was a filter-intra desync | |
| 2 | + | |
| 3 | +## Charter item 1: REJECTED, with the measurement (do NOT move `extend(extra)`) | |
| 4 | +The charter (and r11, and a ledger `constraint|` line) states "aomenc keeps the FIRST | |
| 5 | +occurrence of a repeated flag". **Measured false.** Same input, one frame, 2 tile columns: | |
| 6 | + | |
| 7 | +| args | md5 | size | | |
| 8 | +|---|---|---| | |
| 9 | +| `--enable-palette=0 --enable-palette=1` | 34b7fe63… | 299 | | |
| 10 | +| `--enable-palette=1` alone | 34b7fe63… | 299 | | |
| 11 | +| `--enable-palette=1 --enable-palette=0` | f8339ae1… | 334 | | |
| 12 | +| `--enable-palette=0` alone | f8339ae1… | 334 | | |
| 13 | + | |
| 14 | +The LAST occurrence wins (libaom `aomenc.c` updates the existing entry in | |
| 15 | +`config->arg_ctrls` in place). The current order — base list, then `extra` — is already | |
| 16 | +correct; moving `extra` first would silently disable every per-arm override. Not done, and | |
| 17 | +the ledger line is corrected below. | |
| 18 | + | |
| 19 | +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) | |
| 20 | + | |
| 21 | +## Root cause of the palette arm's refusal: `use_filter_intra` read after a palette block | |
| 22 | +With the overrides proven to arrive, the palette arm still refused — and the refusal was a | |
| 23 | +**correlate, not the defect** ("a HORZ_A/… partition below 16x16" with rect/ab OFF is | |
| 24 | +impossible; the stream had desynced). Isolation, single tile, identical recipe: | |
| 25 | +`--enable-palette=0` → `OK: 1 frames decoded`; `--enable-palette=1` → refusal. | |
| 26 | + | |
| 27 | +Range ladder (instrumented aomdec `EC_TRACE_MODE_STEP` vs ours) diverges inside the first | |
| 28 | +16x16 palette block, mi(0,8): both sides agree through `angle_uv` (rng=38738); ours then | |
| 29 | +reads `use_filter_intra=1` (rng→61700) while libaom reads no such symbol. | |
| 30 | +`av1_filter_intra_allowed` (blockd.h) requires | |
| 31 | +`mbmi->palette_mode_info.palette_size[0] == 0` — **libaom writes no `use_filter_intra` | |
| 32 | +symbol for a Y-palette block**, and we consumed one, desyncing the rest of every | |
| 33 | +screen-content tile from its first palette block on. | |
| 34 | + | |
| 35 | +Fix: `crates/ec-av1/src/decode.rs:5120` — `&& palette_y_pending.is_none()` on the | |
| 36 | +`use_filter_intra` read. | |
| 37 | + | |
| 38 | +Class sweep (`filter_intra_size_class*` call sites): the only other reader is | |
| 39 | +`read_intra_mode_rect` (decode.rs:3661), which refuses screen content wholesale before any | |
| 40 | +palette syntax, so no palette block can reach it; the two inter-frame intra sites | |
| 41 | +(decode.rs:12009, 13109) return `unsupported` the moment palette fires. One site, fixed. | |
| 42 | + | |
| 43 | +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 | |
| 44 | + | |
| 45 | +## Charter item 2: `a_real_aomenc_multi_tile_palette_stream…` un-ignored and GREEN | |
| 46 | +- `#[ignore]` removed; **6/6 attempts pixel-exact vs ffmpeg, 0 refusals**. | |
| 47 | +- Per-attempt proof added: new counter `palette_tile_left_hits()` (decode.rs:916, bumped at | |
| 48 | + decode.rs:5715) counts palette-Y blocks at their own tile's left column; the gate asserts | |
| 49 | + the delta `>= 1` on every attempt that decoded **and** compared. All 6 attempts pass it. | |
| 50 | +- Override proof (charter item 1's real intent): every arm now asserts the sequence header's | |
| 51 | + `enable_cdef && enable_restoration` (the base tools-on recipe arrived), and the palette arm | |
| 52 | + additionally asserts `allow_screen_content_tools` on every frame header (its own | |
| 53 | + `--tune-content=screen --enable-palette=1` arrived). | |
| 54 | + | |
| 55 | +Mutation test on a scratch copy of decode.rs (restored after each run): | |
| 56 | +- revert **`left_ok`** alone (`c > 0`) → gate still passes: the tile-left guard is | |
| 57 | + belt-and-braces, because `start_row` wipes the left palette bands before a tile's first row. | |
| 58 | +- revert **`left_ok` + `start_row`'s palette clear** → gate FAILS (panic at stream.rs:11465). | |
| 59 | + So the gate does bind the r11 palette-band fix, and the load-bearing half is the | |
| 60 | + `start_row` clear, not the `left_ok` guard. Stated rather than claimed the other way. | |
| 61 | + | |
| 62 | +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 | |
| 63 | + | |
| 64 | +## Charter item 3: override-shape sweep of stream.rs | |
| 65 | +`grep -n "extend(\|\.chain("` near aomenc/ffmpeg arg vectors → 3 sites: | |
| 66 | +- stream.rs:11234 `run_multi_tile_gate` — extras after base: **correct** (last wins). | |
| 67 | +- stream.rs:9266 — appends `rate_args`/`depth_args`, no flag repeated with the base list. | |
| 68 | +- stream.rs:1323 — ffmpeg (`libaom-av1` private options), where a repeated option also takes | |
| 69 | + the last value (`av_dict_set` overwrite). | |
| 70 | +Nothing to fix; the shape is safe under last-wins, which is the measured behaviour. | |
| 71 | + | |
| 72 | +## Charter item 4: the `#[ignore]`d multi-tile inter arm | |
| 73 | +Left ignored, with its reproducer. It already carries `--max-partition-size=32 | |
| 74 | +--enable-tx-size-search=0` (r11), so the charter's suggested flags are the ones it runs with; | |
| 75 | +the open defect is the seed-42 32x32 block at x[224..255] y[32..63], tile attribution still | |
| 76 | +unproven. Disposition: **deferred(a decodable single-tile control of the same content)** — | |
| 77 | +unchanged from r11, no budget spent on it this round. | |
| 78 | + | |
| 79 | +## Test totals | |
| 80 | +See the report footer line appended after the suite run. | |
| 81 | + | |
| 82 | +## Files changed | |
| 83 | +- `crates/ec-av1/src/decode.rs` — filter-intra/palette gating fix; `PALETTE_TILE_LEFT_HITS`. | |
| 84 | +- `crates/ec-av1/src/stream.rs` — palette arm un-ignored; per-attempt tile-left palette | |
| 85 | + assert; sequence-header + screen-tools override proofs on every arm. |