forge
Explore
Log in

Don't you dare go Hollow

diag(av1): EC_AV1_TRACE range-ladder inside decode_color_index_map + palette Y mode/size/colors (lane-palette r6)

Browse files at this commit

f62adbfb30df73cce788771a618830d0e4b09b5bAhmet Kaan GümüşParent: 0e5435a
Range-ladder bisect against aomdec's EC_TRACE_PALETTE rung (rungs 6/6b)
on the r3/r4 smptebars gate fixture: every symbol up through
read_palette_colors_y matches the oracle's ranges exactly
(partition_w32 rng, skip/y_mode/uv_mode, palette_y_mode, palette_y_size,
palette colours all bit-identical). The desync starts right after --
libaom's decode_color_map_tokens is NOT called inline from
read_palette_mode_info; it runs later, from parse_decode_block via
av1_visit_palette, after palette UV mode_info (mode/size/colors, which
this decoder does not read at all yet) and filter_intra. Our
decode_color_index_map is called immediately after the Y colours
instead, so it reads the color-index symbols against the wrong point in
the bitstream whenever a block is chroma-referenced with UV_DC_PRED
(this gate's block: bsize_ctx=4, uv_mode=0). Confirmed by patching a
throwaway EC_PRE_PALETTE/EC_PALETTE_Y_MODE/SIZE/COLORS print into the
oracle's decodemv.c (not committed, reverted after use) -- ranges
matched ours field-for-field through EC_PALETTE_Y_COLORS rng=39432, then
the oracle's own decode_color_map_tokens entry read rng=51752, proving
UV palette mode_info consumed real bits in between that this decoder
skips.

Adds an EC_AV1_TRACE-gated EC_PAL/EC_PAL_VAL print inside our own
decode_color_index_map (row/col/ctx/n/rng before, color_idx/rng after,
plus the map[0] uniform read) and TRACE prints around the Y palette
mode/size/colors reads, matching the oracle rung's field names so a
future round's bisect doesn't have to re-instrument. No behaviour
change: the palette_y_mode `&&` short-circuit (only read the symbol
when mode == DC_PRED) is preserved exactly.

Refusal strings: none added or removed -- the palette-Y refusal stays
in place; removing it needs the reorder fix (read/skip UV palette
mode_info in the right position, defer the Y+UV color-index-map reads
to after filter_intra) which is next round's job, not this one's.

Suite: EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j4 -- 244
passed, 0 failed, 17 ignored (unchanged).
crates/ec-av1/src/decode.rsmodified+40 -1
@@ -2368,8 +2368,17 @@ fn palette_color_index_context(
23682368 /// rows/cols-vs-plane_width/height cropping special case is needed, unlike
23692369 /// libaom's own non-block-aligned split.
23702370 fn decode_color_index_map(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, n: usize, side: usize) -> Vec<u8> {
2371+ let trace = std::env::var_os("EC_AV1_TRACE").is_some();
23712372 let mut map = vec![0u8; side * side];
2373+ if trace {
2374+ let (rng, _) = dec.debug_state();
2375+ eprintln!("EC_PAL row=0 col=0 ctx=-1 n={n} rng={rng}");
2376+ }
23722377 map[0] = read_uniform(dec, n) as u8;
2378+ if trace {
2379+ let (rng, _) = dec.debug_state();
2380+ eprintln!("EC_PAL_VAL row=0 col=0 color_idx={} rng={rng}", map[0]);
2381+ }
23732382 for i in 1..(2 * side - 1) {
23742383 let j_hi = i.min(side - 1);
23752384 let j_lo = i.saturating_sub(side - 1);
@@ -2377,8 +2386,16 @@ fn decode_color_index_map(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, n: usize, si
23772386 let row = i - j;
23782387 let col = j;
23792388 let (ctx, color_order) = palette_color_index_context(&map, side, row, col, n);
2389+ if trace {
2390+ let (rng, _) = dec.debug_state();
2391+ eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} rng={rng}");
2392+ }
23802393 let symbol = dec.symbol(&mut cdfs.palette_y_color_index[n - 2][ctx][..=n]);
23812394 map[row * side + col] = color_order[symbol];
2395+ if trace {
2396+ let (rng, _) = dec.debug_state();
2397+ eprintln!("EC_PAL_VAL row={row} col={col} color_idx={symbol} rng={rng}");
2398+ }
23822399 }
23832400 }
23842401 map
@@ -2995,14 +3012,36 @@ fn read_intra_mode(
29953012 && let Some(bsize_ctx) = palette_bsize_ctx(side)
29963013 {
29973014 let (mode_ctx, cache) = palette.unwrap_or((0, &[]));
2998- if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][mode_ctx]) != 0 {
3015+ if mode == DC_PRED {
3016+ if trace {
3017+ let (rng, _) = dec.debug_state();
3018+ eprintln!(
3019+ "TRACE pre_palette_y_mode bsize_ctx={bsize_ctx} mode_ctx={mode_ctx} rng={rng}"
3020+ );
3021+ }
3022+ }
3023+ let use_palette_y =
3024+ mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][mode_ctx]) != 0;
3025+ if mode == DC_PRED && trace {
3026+ let (rng, _) = dec.debug_state();
3027+ eprintln!("TRACE palette_y_mode value={} rng={rng}", use_palette_y as i32);
3028+ }
3029+ if use_palette_y {
29993030 if palette.is_none() {
30003031 return Err(unsupported(
30013032 "a block that actually uses a palette (Y) -- reconstruction is out of scope",
30023033 ));
30033034 }
30043035 let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]);
3036+ if trace {
3037+ let (rng, _) = dec.debug_state();
3038+ eprintln!("TRACE palette_y_size n={n} rng={rng}");
3039+ }
30053040 let colors = read_palette_colors_y(dec, n, cache);
3041+ if trace {
3042+ let (rng, _) = dec.debug_state();
3043+ eprintln!("TRACE palette_y_colors colors={:?} rng={rng}", &colors[..n]);
3044+ }
30063045 let map = decode_color_index_map(dec, cdfs, n, side);
30073046 PALETTE_HITS.with(|c| c.set(c.get() + 1));
30083047 if trace {