forge
Explore
Log in

Don't you dare go Hollow

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 commit

4395cbd993d4b9fcd9be6d56b54e0fa02507dd78Ahmet Kaan GümüşParent: 45c1398
  • fix
    • no use_filter_intra symbol for a palette-Y block (av1_filter_intra_allowed), and the multi-tile palette gate goes live
Show full message
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.rsmodified+24 -0
@@ -914,6 +914,19 @@ pub(crate) fn palette_hits() -> usize {
914914 PALETTE_HITS.with(|c| c.get())
915915 }
916916
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+
917930 // lane-palette2 r1: as [`PALETTE_HITS`], for a real (nonzero-size) chroma
918931 // palette use -- proves a stream actually reconstructed UV palette pixels,
919932 // not just read and refused the `palette_uv_mode` symbol.
@@ -5104,8 +5117,15 @@ fn read_intra_mode(
51045117 // matched bit-exact, then `eob_pt` read 5 instead of 6, because this
51055118 // symbol's bits were never consumed).
51065119 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).
51075126 if mode == DC_PRED
51085127 && enable_filter_intra
5128+ && palette_y_pending.is_none()
51095129 && let Some(class) = filter_intra_size_class(side)
51105130 {
51115131 let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0;
@@ -5688,6 +5708,7 @@ fn decode_block(
56885708 let (px, py) = (c * SUB, r * SUB);
56895709 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at);
56905710 let palette_uv_cache = neighbours.palette_uv_cache(at);
5711+ let at_tile_left = c == neighbours.tile_col0_mi / (SUB / MI);
56915712 let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) =
56925713 read_intra_mode(
56935714 dec,
@@ -5705,6 +5726,9 @@ fn decode_block(
57055726 r * (SUB / MI),
57065727 c * (SUB / MI),
57075728 )?;
5729+ if at_tile_left && palette_y.is_some() {
5730+ PALETTE_TILE_LEFT_HITS.with(|c| c.set(c.get() + 1));
5731+ }
57085732 let intrabc_dv = INTRABC_DV.with(|c| c.take());
57095733 // libaom `parse_decode_block`: an intrabc block is `inter_block_tx`, so
57105734 // 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 {
1114511145 bit_depth: usize,
1114611146 frame_count: usize,
1114711147 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,
1114811154 // `None` = the shared `gradients_source`. The palette arm overrides it
1114911155 // with `smptebars`, the flat few-colour source the existing palette
1115011156 // gates use -- gradients never make aomenc pick a palette block.
@@ -11268,6 +11274,19 @@ mod tests {
1126811274 let header = match &obu.kind {
1126911275 ObuKind::Frame(h, _) => h,
1127011276 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+ }
1127111290 _ => continue,
1127211291 };
1127311292 // A `show_existing_frame` header codes no tile info at all
@@ -11278,6 +11297,12 @@ mod tests {
1127811297 if header.show_existing_frame {
1127911298 continue;
1128011299 }
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+ }
1128111306 assert_eq!(
1128211307 (header.tile_info.cols * header.tile_info.rows) as usize,
1128311308 expected_tiles,
@@ -11292,6 +11317,7 @@ mod tests {
1129211317 }
1129311318
1129411319 let before = crate::decode::tile_hits();
11320+ let pal_before = crate::decode::palette_tile_left_hits();
1129511321 let frames = match decode_stream(&stream) {
1129611322 Err(e) => {
1129711323 let msg = e.to_string();
@@ -11330,6 +11356,15 @@ mod tests {
1133011356 assert_eq!(got.u, want.u, "{name} frame {i} U vs ffmpeg (seed {seed})");
1133111357 assert_eq!(got.v, want.v, "{name} frame {i} V vs ffmpeg (seed {seed})");
1133211358 }
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+ }
1133311368 matched += 1;
1133411369 }
1133511370 assert!(
@@ -11349,6 +11384,7 @@ mod tests {
1134911384 8,
1135011385 1,
1135111386 &[],
11387+ false,
1135211388 None,
1135311389 );
1135411390 }
@@ -11362,6 +11398,7 @@ mod tests {
1136211398 10,
1136311399 1,
1136411400 &[],
11401+ false,
1136511402 None,
1136611403 );
1136711404 }
@@ -11398,6 +11435,7 @@ mod tests {
1139811435 // `refusal_inventory.rs`; without these two flags every inter
1139911436 // attempt refuses before a single tile edge is compared.
1140011437 &["--max-partition-size=32", "--enable-tx-size-search=0"],
11438+ false,
1140111439 None,
1140211440 );
1140311441 }
@@ -11421,7 +11459,6 @@ mod tests {
1142111459 /// `run_multi_tile_gate`'s args, then this arm should reach a palette
1142211460 /// block on smptebars with rect/ab off.
1142311461 #[test]
11424- #[ignore = "r11: refuses on AB-below-16x16 before a palette block reconstructs; extra-flag override needs to precede the base recipe"]
1142511462 fn a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact() {
1142611463 const NAME: &str = "a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact";
1142711464 let before = crate::decode::palette_hits();
@@ -11437,6 +11474,7 @@ mod tests {
1143711474 // only"); this arm owns the palette CACHE at a tile edge, so
1143811475 // it takes the square-only path the other palette gates take.
1143911476 "--enable-rect-partitions=0", "--enable-ab-partitions=0"],
11477+ true,
1144011478 Some("smptebars"),
1144111479 );
1144211480 if have_ffmpeg() && have_aomenc() {
@@ -11463,6 +11501,7 @@ mod tests {
1146311501 // `refusal_inventory.rs`; without these two flags every inter
1146411502 // attempt refuses before a single tile edge is compared.
1146511503 &["--max-partition-size=32", "--enable-tx-size-search=0"],
11504+ false,
1146611505 None,
1146711506 );
1146811507 }
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.