Merge branch 'lane-palette2': UV palette blocks decode pixel-exact
Browse files at this commit5 changed files +568 -25
- crates/ec-av1/src/decode.rs +282 -25
- crates/ec-av1/src/stream.rs +118 -0
- lanes/palette2-r1.charter.md +60 -0
- lanes/palette2-r2.charter.md +35 -0
- lanes/palette2-r2.report.md +73 -0
crates/ec-av1/src/decode.rsmodified+282 -25
| @@ -451,6 +451,42 @@ pub(crate) fn palette_hits() -> usize { | |||
| 451 | PALETTE_HITS.with(|c| c.get()) | 451 | PALETTE_HITS.with(|c| c.get()) |
| 452 | } | 452 | } |
| 453 | 453 | ||
| 454 | +// lane-palette2 r1: as [`PALETTE_HITS`], for a real (nonzero-size) chroma | ||
| 455 | +// palette use -- proves a stream actually reconstructed UV palette pixels, | ||
| 456 | +// not just read and refused the `palette_uv_mode` symbol. | ||
| 457 | +thread_local! { | ||
| 458 | + static PALETTE_UV_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 459 | +} | ||
| 460 | + | ||
| 461 | +/// Current value of [`PALETTE_UV_HITS`]. | ||
| 462 | +pub(crate) fn palette_uv_hits() -> usize { | ||
| 463 | + PALETTE_UV_HITS.with(|c| c.get()) | ||
| 464 | +} | ||
| 465 | + | ||
| 466 | +// lane-palette2 r1: how many HORZ/VERT rect intra strips ([`read_intra_mode_rect`]) | ||
| 467 | +// decoded a real palette-Y use -- proves the rect strip's own palette syntax | ||
| 468 | +// (not just the square path's) actually fired. | ||
| 469 | +thread_local! { | ||
| 470 | + static PALETTE_RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 471 | +} | ||
| 472 | + | ||
| 473 | +/// Current value of [`PALETTE_RECT_HITS`]. | ||
| 474 | +pub(crate) fn palette_rect_hits() -> usize { | ||
| 475 | + PALETTE_RECT_HITS.with(|c| c.get()) | ||
| 476 | +} | ||
| 477 | + | ||
| 478 | +// lane-palette2 r1: how many palette-Y blocks decoded with a split luma | ||
| 479 | +// transform (`tx_select && logical_tx != side`) -- proves the per-TU index-map | ||
| 480 | +// slicing actually ran, not just that the whole-block path stayed exact. | ||
| 481 | +thread_local! { | ||
| 482 | + static PALETTE_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 483 | +} | ||
| 484 | + | ||
| 485 | +/// Current value of [`PALETTE_SPLIT_TX_HITS`]. | ||
| 486 | +pub(crate) fn palette_split_tx_hits() -> usize { | ||
| 487 | + PALETTE_SPLIT_TX_HITS.with(|c| c.get()) | ||
| 488 | +} | ||
| 489 | + | ||
| 454 | thread_local! { | 490 | thread_local! { |
| 455 | /// A just-decoded palette-Y block's own predicted pixels | 491 | /// A just-decoded palette-Y block's own predicted pixels |
| 456 | /// (`side*side`, row-major, `colors[map[i]]`), consumed by | 492 | /// (`side*side`, row-major, `colors[map[i]]`), consumed by |
| @@ -1630,6 +1666,13 @@ struct Neighbours { | |||
| 1630 | left_palette_size: Vec<usize>, | 1666 | left_palette_size: Vec<usize>, |
| 1631 | above_palette_colors: Vec<[u16; 8]>, | 1667 | above_palette_colors: Vec<[u16; 8]>, |
| 1632 | left_palette_colors: Vec<[u16; 8]>, | 1668 | left_palette_colors: Vec<[u16; 8]>, |
| 1669 | + /// As the four fields above, for the neighbour's own chroma (U-channel | ||
| 1670 | + /// only -- `av1_get_palette_cache`'s plane-1 lookup, [`Self::palette_uv_cache`]) | ||
| 1671 | + /// palette size/colours (lane-palette2 r1). | ||
| 1672 | + above_palette_uv_size: Vec<usize>, | ||
| 1673 | + left_palette_uv_size: Vec<usize>, | ||
| 1674 | + above_palette_uv_colors: Vec<[u16; 8]>, | ||
| 1675 | + left_palette_uv_colors: Vec<[u16; 8]>, | ||
| 1633 | /// This tile's own top-left corner, in 4x4 mode-info units (spec | 1676 | /// This tile's own top-left corner, in 4x4 mode-info units (spec |
| 1634 | /// `MiRowStart`/`MiColStart`) -- lane-tiles: every "is there really a | 1677 | /// `MiRowStart`/`MiColStart`) -- lane-tiles: every "is there really a |
| 1635 | /// neighbour" check compares against this instead of literal `0`, since a | 1678 | /// neighbour" check compares against this instead of literal `0`, since a |
| @@ -1684,6 +1727,10 @@ impl Neighbours { | |||
| 1684 | left_palette_size: vec![0; rows], | 1727 | left_palette_size: vec![0; rows], |
| 1685 | above_palette_colors: vec![[0u16; 8]; cols], | 1728 | above_palette_colors: vec![[0u16; 8]; cols], |
| 1686 | left_palette_colors: vec![[0u16; 8]; rows], | 1729 | left_palette_colors: vec![[0u16; 8]; rows], |
| 1730 | + above_palette_uv_size: vec![0; cols], | ||
| 1731 | + left_palette_uv_size: vec![0; rows], | ||
| 1732 | + above_palette_uv_colors: vec![[0u16; 8]; cols], | ||
| 1733 | + left_palette_uv_colors: vec![[0u16; 8]; rows], | ||
| 1687 | tile_row0_mi: 0, | 1734 | tile_row0_mi: 0, |
| 1688 | tile_col0_mi: 0, | 1735 | tile_col0_mi: 0, |
| 1689 | } | 1736 | } |
| @@ -1789,6 +1836,70 @@ impl Neighbours { | |||
| 1789 | (ctx, cache) | 1836 | (ctx, cache) |
| 1790 | } | 1837 | } |
| 1791 | 1838 | ||
| 1839 | + /// As [`Self::record_palette_y`], for a just-decoded block's own chroma | ||
| 1840 | + /// (U-channel) palette size/colours -- `size == 0` clears stale state the | ||
| 1841 | + /// same way (lane-palette2 r1). | ||
| 1842 | + fn record_palette_uv(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { | ||
| 1843 | + let (r, c) = at; | ||
| 1844 | + for cell in 0..side / SUB { | ||
| 1845 | + self.above_palette_uv_size[c + cell] = size; | ||
| 1846 | + self.above_palette_uv_colors[c + cell] = colors; | ||
| 1847 | + } | ||
| 1848 | + for cell in 0..side / SUB { | ||
| 1849 | + self.left_palette_uv_size[r + cell] = size; | ||
| 1850 | + self.left_palette_uv_colors[r + cell] = colors; | ||
| 1851 | + } | ||
| 1852 | + } | ||
| 1853 | + | ||
| 1854 | + /// [`Self::palette_ctx_and_cache`]'s cache half, for the U channel | ||
| 1855 | + /// (`av1_get_palette_cache(xd, 1, cache)`) -- `palette_uv_mode_ctx` needs | ||
| 1856 | + /// no neighbour lookup at all (it is this block's own just-decided Y | ||
| 1857 | + /// palette use, `read_palette_mode_info`'s `pmi->palette_size[0] > 0`), | ||
| 1858 | + /// so only the cache is wanted here. | ||
| 1859 | + fn palette_uv_cache(&self, at: (usize, usize)) -> Vec<u16> { | ||
| 1860 | + let (r, c) = at; | ||
| 1861 | + let above_ok = r % 4 != 0; | ||
| 1862 | + let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 { | ||
| 1863 | + (self.above_palette_uv_size[c], self.above_palette_uv_colors[c]) | ||
| 1864 | + } else { | ||
| 1865 | + (0, [0u16; 8]) | ||
| 1866 | + }; | ||
| 1867 | + let (left_n, left_colors) = if self.left_palette_uv_size[r] > 0 { | ||
| 1868 | + (self.left_palette_uv_size[r], self.left_palette_uv_colors[r]) | ||
| 1869 | + } else { | ||
| 1870 | + (0, [0u16; 8]) | ||
| 1871 | + }; | ||
| 1872 | + let mut cache = Vec::with_capacity(16); | ||
| 1873 | + let push_dedup = |cache: &mut Vec<u16>, v: u16| { | ||
| 1874 | + if cache.last() != Some(&v) { | ||
| 1875 | + cache.push(v); | ||
| 1876 | + } | ||
| 1877 | + }; | ||
| 1878 | + let (mut ai, mut li) = (0usize, 0usize); | ||
| 1879 | + while ai < above_n && li < left_n { | ||
| 1880 | + let (va, vl) = (above_colors[ai], left_colors[li]); | ||
| 1881 | + if vl < va { | ||
| 1882 | + push_dedup(&mut cache, vl); | ||
| 1883 | + li += 1; | ||
| 1884 | + } else { | ||
| 1885 | + push_dedup(&mut cache, va); | ||
| 1886 | + ai += 1; | ||
| 1887 | + if vl == va { | ||
| 1888 | + li += 1; | ||
| 1889 | + } | ||
| 1890 | + } | ||
| 1891 | + } | ||
| 1892 | + while ai < above_n { | ||
| 1893 | + push_dedup(&mut cache, above_colors[ai]); | ||
| 1894 | + ai += 1; | ||
| 1895 | + } | ||
| 1896 | + while li < left_n { | ||
| 1897 | + push_dedup(&mut cache, left_colors[li]); | ||
| 1898 | + li += 1; | ||
| 1899 | + } | ||
| 1900 | + cache | ||
| 1901 | + } | ||
| 1902 | + | ||
| 1792 | /// Marks every 4x4 mi cell a just-decoded coded block covers with its own | 1903 | /// Marks every 4x4 mi cell a just-decoded coded block covers with its own |
| 1793 | /// transform width (in pixels) and `is_inter` flag -- the loop filter's | 1904 | /// transform width (in pixels) and `is_inter` flag -- the loop filter's |
| 1794 | /// per-edge lookup (`apply_deblock`), filled at the same call sites and | 1905 | /// per-edge lookup (`apply_deblock`), filled at the same call sites and |
| @@ -2339,15 +2450,22 @@ fn filter_intra_size_class_rect(bw: usize, bh: usize) -> Option<usize> { | |||
| 2339 | /// `av1_allow_palette`'s size bound (blockd.h: `block_size_wide/high <= | 2450 | /// `av1_allow_palette`'s size bound (blockd.h: `block_size_wide/high <= |
| 2340 | /// MAX_PALETTE_BLOCK_WIDTH/HEIGHT` (64) and `sb_type >= BLOCK_8X8`) plus | 2451 | /// MAX_PALETTE_BLOCK_WIDTH/HEIGHT` (64) and `sb_type >= BLOCK_8X8`) plus |
| 2341 | /// `av1_get_palette_bsize_ctx` (pred_common.h: `num_pels_log2_lookup[bsize] | 2452 | /// `av1_get_palette_bsize_ctx` (pred_common.h: `num_pels_log2_lookup[bsize] |
| 2342 | -/// - num_pels_log2_lookup[BLOCK_8X8]`, i.e. `2*log2(side) - 6` for this | 2453 | +/// - num_pels_log2_lookup[BLOCK_8X8]`, i.e. `log2(bw*bh) - 6`) -- `None` past |
| 2343 | -/// decoder's square-only blocks) -- `None` past the bound (never gates a | 2454 | +/// the bound (never gates a palette read), `Some(bsize_ctx)` otherwise. |
| 2344 | -/// palette read), `Some(bsize_ctx)` otherwise. | ||
| 2345 | fn palette_bsize_ctx(side: usize) -> Option<usize> { | 2455 | fn palette_bsize_ctx(side: usize) -> Option<usize> { |
| 2346 | - match side { | 2456 | + palette_bsize_ctx_wh(side, side) |
| 2347 | - 8 => Some(0), | 2457 | +} |
| 2348 | - 16 => Some(2), | 2458 | + |
| 2349 | - 32 => Some(4), | 2459 | +/// [`palette_bsize_ctx`], generalised to a true `bw`x`bh` rect strip |
| 2350 | - 64 => Some(6), | 2460 | +/// (lane-palette2 r1) -- the same `log2(bw*bh) - 6` formula, this decoder's |
| 2461 | +/// square call sites are just `bw == bh`. | ||
| 2462 | +fn palette_bsize_ctx_wh(bw: usize, bh: usize) -> Option<usize> { | ||
| 2463 | + match (bw, bh) { | ||
| 2464 | + (8, 8) => Some(0), | ||
| 2465 | + (16, 16) => Some(2), | ||
| 2466 | + (32, 16) | (16, 32) => Some(3), | ||
| 2467 | + (32, 32) => Some(4), | ||
| 2468 | + (64, 64) => Some(6), | ||
| 2351 | _ => None, | 2469 | _ => None, |
| 2352 | } | 2470 | } |
| 2353 | } | 2471 | } |
| @@ -2361,6 +2479,17 @@ struct PaletteY { | |||
| 2361 | map: Vec<u8>, | 2479 | map: Vec<u8>, |
| 2362 | } | 2480 | } |
| 2363 | 2481 | ||
| 2482 | +/// As [`PaletteY`], for a just-decoded chroma palette block: one shared | ||
| 2483 | +/// per-pixel colour-index map (spec `av1_visit_palette`'s plane-1 pass is | ||
| 2484 | +/// shared between U and V, both co-located after 4:2:0 subsampling) plus | ||
| 2485 | +/// each plane's own base colours. | ||
| 2486 | +struct PaletteUv { | ||
| 2487 | + size: usize, | ||
| 2488 | + u_colors: [u16; 8], | ||
| 2489 | + v_colors: [u16; 8], | ||
| 2490 | + map: Vec<u8>, | ||
| 2491 | +} | ||
| 2492 | + | ||
| 2364 | /// `aom_ceil_log2` (aom_dsp/bitwriter_buffer.h-adjacent helper, used both by | 2493 | /// `aom_ceil_log2` (aom_dsp/bitwriter_buffer.h-adjacent helper, used both by |
| 2365 | /// `read_palette_colors_y`'s shrinking `bits` and `av1_read_uniform`'s | 2494 | /// `read_palette_colors_y`'s shrinking `bits` and `av1_read_uniform`'s |
| 2366 | /// `get_unsigned_bits`, which is the same formula): smallest `n` with | 2495 | /// `get_unsigned_bits`, which is the same formula): smallest `n` with |
| @@ -2446,6 +2575,74 @@ fn read_palette_colors_y(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> [u | |||
| 2446 | colors | 2575 | colors |
| 2447 | } | 2576 | } |
| 2448 | 2577 | ||
| 2578 | +/// `read_palette_colors_uv` (decodemv.c:509), bit_depth fixed at 8: U reads | ||
| 2579 | +/// exactly [`read_palette_colors_y`]'s cache/delta scheme (against the U-only | ||
| 2580 | +/// cache, `range` starting at `255 - prev` with no `-1`, and each raw `delta` | ||
| 2581 | +/// unbiased by `+1` -- both differences from Y's own reader, matching the C | ||
| 2582 | +/// side by side). V never uses a cache: a leading bit picks either `n` raw | ||
| 2583 | +/// literals, or a first raw value plus `n-1` signed deltas that wrap mod 256 | ||
| 2584 | +/// rather than clamp. | ||
| 2585 | +fn read_palette_colors_uv(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> ([u16; 8], [u16; 8]) { | ||
| 2586 | + let mut cached = Vec::with_capacity(n); | ||
| 2587 | + for &c in cache { | ||
| 2588 | + if cached.len() >= n { | ||
| 2589 | + break; | ||
| 2590 | + } | ||
| 2591 | + if dec.literal(1) == 1 { | ||
| 2592 | + cached.push(c); | ||
| 2593 | + } | ||
| 2594 | + } | ||
| 2595 | + let mut u_colors = [0u16; 8]; | ||
| 2596 | + let n_cached = cached.len(); | ||
| 2597 | + if n_cached < n { | ||
| 2598 | + let mut transmitted = Vec::with_capacity(n - n_cached); | ||
| 2599 | + let first = dec.literal(8) as u16; | ||
| 2600 | + transmitted.push(first); | ||
| 2601 | + if n_cached + 1 < n { | ||
| 2602 | + let min_bits = 8u32 - 3; | ||
| 2603 | + let mut bits = min_bits + dec.literal(2); | ||
| 2604 | + let mut range = 255i32 - i32::from(first); | ||
| 2605 | + for _ in (n_cached + 1)..n { | ||
| 2606 | + let delta = dec.literal(bits) as i32; | ||
| 2607 | + let prev = *transmitted.last().unwrap(); | ||
| 2608 | + let val = (i32::from(prev) + delta).clamp(0, 255) as u16; | ||
| 2609 | + range -= i32::from(val) - i32::from(prev); | ||
| 2610 | + bits = bits.min(ceil_log2(range.max(0) as u32)); | ||
| 2611 | + transmitted.push(val); | ||
| 2612 | + } | ||
| 2613 | + } | ||
| 2614 | + let merged = merge_colors(&transmitted, &cached); | ||
| 2615 | + u_colors[..n].copy_from_slice(&merged); | ||
| 2616 | + } else { | ||
| 2617 | + u_colors[..n].copy_from_slice(&cached[..n]); | ||
| 2618 | + } | ||
| 2619 | + let mut v_colors = [0u16; 8]; | ||
| 2620 | + if dec.literal(1) == 1 { | ||
| 2621 | + let min_bits_v = 8u32 - 4; | ||
| 2622 | + let bits = min_bits_v + dec.literal(2); | ||
| 2623 | + v_colors[0] = dec.literal(8) as u16; | ||
| 2624 | + for i in 1..n { | ||
| 2625 | + let mut delta = dec.literal(bits) as i32; | ||
| 2626 | + if delta != 0 && dec.literal(1) == 1 { | ||
| 2627 | + delta = -delta; | ||
| 2628 | + } | ||
| 2629 | + let mut val = i32::from(v_colors[i - 1]) + delta; | ||
| 2630 | + if val < 0 { | ||
| 2631 | + val += 256; | ||
| 2632 | + } | ||
| 2633 | + if val >= 256 { | ||
| 2634 | + val -= 256; | ||
| 2635 | + } | ||
| 2636 | + v_colors[i] = val as u16; | ||
| 2637 | + } | ||
| 2638 | + } else { | ||
| 2639 | + for i in 0..n { | ||
| 2640 | + v_colors[i] = dec.literal(8) as u16; | ||
| 2641 | + } | ||
| 2642 | + } | ||
| 2643 | + (u_colors, v_colors) | ||
| 2644 | +} | ||
| 2645 | + | ||
| 2449 | /// `av1_palette_color_index_context_lookup` (entropymode.c:889): maps a | 2646 | /// `av1_palette_color_index_context_lookup` (entropymode.c:889): maps a |
| 2450 | /// `NUM_PALETTE_NEIGHBORS`-weighted score hash (`0..=8`) to the real | 2647 | /// `NUM_PALETTE_NEIGHBORS`-weighted score hash (`0..=8`) to the real |
| 2451 | /// `0..=4` context, `-1` for hashes no real neighbour configuration produces. | 2648 | /// `0..=4` context, `-1` for hashes no real neighbour configuration produces. |
| @@ -2514,7 +2711,13 @@ fn palette_color_index_context( | |||
| 2514 | /// region (every other skip/residual path here does the same), so no | 2711 | /// region (every other skip/residual path here does the same), so no |
| 2515 | /// rows/cols-vs-plane_width/height cropping special case is needed, unlike | 2712 | /// rows/cols-vs-plane_width/height cropping special case is needed, unlike |
| 2516 | /// libaom's own non-block-aligned split. | 2713 | /// libaom's own non-block-aligned split. |
| 2517 | -fn decode_color_index_map(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, n: usize, side: usize) -> Vec<u8> { | 2714 | +fn decode_color_index_map( |
| 2715 | + dec: &mut SymbolDecoder, | ||
| 2716 | + cdfs: &mut Cdfs, | ||
| 2717 | + n: usize, | ||
| 2718 | + side: usize, | ||
| 2719 | + uv: bool, | ||
| 2720 | +) -> Vec<u8> { | ||
| 2518 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); | 2721 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); |
| 2519 | let mut map = vec![0u8; side * side]; | 2722 | let mut map = vec![0u8; side * side]; |
| 2520 | if trace { | 2723 | if trace { |
| @@ -2537,7 +2740,11 @@ fn decode_color_index_map(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, n: usize, si | |||
| 2537 | let (rng, _) = dec.debug_state(); | 2740 | let (rng, _) = dec.debug_state(); |
| 2538 | eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} rng={rng}"); | 2741 | eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} rng={rng}"); |
| 2539 | } | 2742 | } |
| 2540 | - let symbol = dec.symbol(&mut cdfs.palette_y_color_index[n - 2][ctx][..=n]); | 2743 | + let symbol = if uv { |
| 2744 | + dec.symbol(&mut cdfs.palette_uv_color_index[n - 2][ctx][..=n]) | ||
| 2745 | + } else { | ||
| 2746 | + dec.symbol(&mut cdfs.palette_y_color_index[n - 2][ctx][..=n]) | ||
| 2747 | + }; | ||
| 2541 | map[row * side + col] = color_order[symbol]; | 2748 | map[row * side + col] = color_order[symbol]; |
| 2542 | if trace { | 2749 | if trace { |
| 2543 | let (rng, _) = dec.debug_state(); | 2750 | let (rng, _) = dec.debug_state(); |
| @@ -3056,6 +3263,11 @@ fn read_intra_mode( | |||
| 3056 | // decoder reads either way -- but refuse by name the moment it fires, | 3263 | // decoder reads either way -- but refuse by name the moment it fires, |
| 3057 | // exactly the old behaviour. | 3264 | // exactly the old behaviour. |
| 3058 | palette: Option<(usize, &[u16])>, | 3265 | palette: Option<(usize, &[u16])>, |
| 3266 | + // The U-channel colour cache for a chroma palette read ([`Neighbours::palette_uv_cache`]), | ||
| 3267 | + // `&[]` at the excluded call sites -- same corner-cut as `palette` above, | ||
| 3268 | + // no `mode_ctx` needed (`palette_uv_mode_ctx` is this block's own just-read | ||
| 3269 | + // `use_palette_y`, not a neighbour lookup). | ||
| 3270 | + palette_uv_cache: &[u16], | ||
| 3059 | mi_r: usize, | 3271 | mi_r: usize, |
| 3060 | mi_c: usize, | 3272 | mi_c: usize, |
| 3061 | ) -> Result<( | 3273 | ) -> Result<( |
| @@ -3067,6 +3279,7 @@ fn read_intra_mode( | |||
| 3067 | Option<(i32, i32)>, | 3279 | Option<(i32, i32)>, |
| 3068 | Option<usize>, | 3280 | Option<usize>, |
| 3069 | Option<PaletteY>, | 3281 | Option<PaletteY>, |
| 3282 | + Option<PaletteUv>, | ||
| 3070 | )> { | 3283 | )> { |
| 3071 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); | 3284 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); |
| 3072 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; | 3285 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; |
| @@ -3174,6 +3387,7 @@ fn read_intra_mode( | |||
| 3174 | // bit-for-bit through the Y colours, diverged only at the old inline | 3387 | // bit-for-bit through the Y colours, diverged only at the old inline |
| 3175 | // `decode_color_index_map` call). | 3388 | // `decode_color_index_map` call). |
| 3176 | let mut palette_y_pending: Option<(usize, [u16; 8])> = None; | 3389 | let mut palette_y_pending: Option<(usize, [u16; 8])> = None; |
| 3390 | + let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None; | ||
| 3177 | if allow_screen_content_tools | 3391 | if allow_screen_content_tools |
| 3178 | && let Some(bsize_ctx) = palette_bsize_ctx(side) | 3392 | && let Some(bsize_ctx) = palette_bsize_ctx(side) |
| 3179 | { | 3393 | { |
| @@ -3215,15 +3429,12 @@ fn read_intra_mode( | |||
| 3215 | // UV_DC_PRED`, regardless of whether Y just fired -- this decoder's | 3429 | // UV_DC_PRED`, regardless of whether Y just fired -- this decoder's |
| 3216 | // scope always reconstructs chroma alongside luma (`decode_block` | 3430 | // scope always reconstructs chroma alongside luma (`decode_block` |
| 3217 | // always calls `u.reconstruct`/`v.reconstruct`), so `is_chroma_ref` | 3431 | // always calls `u.reconstruct`/`v.reconstruct`), so `is_chroma_ref` |
| 3218 | - // is always true here and does not need threading in. UV palette | 3432 | + // is always true here and does not need threading in. |
| 3219 | - // reconstruction stays out of scope: refusing the moment the mode | ||
| 3220 | - // symbol fires needs no further reads (the whole decode aborts), | ||
| 3221 | - // so `palette_uv_size`/`read_palette_colors_uv` are never reached. | ||
| 3222 | let palette_uv_mode_ctx = usize::from(use_palette_y); | 3433 | let palette_uv_mode_ctx = usize::from(use_palette_y); |
| 3223 | if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[palette_uv_mode_ctx]) != 0 { | 3434 | if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[palette_uv_mode_ctx]) != 0 { |
| 3224 | - return Err(unsupported( | 3435 | + let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]); |
| 3225 | - "a block that actually uses a palette (UV) -- reconstruction is out of scope", | 3436 | + let (u_colors, v_colors) = read_palette_colors_uv(dec, n, palette_uv_cache); |
| 3226 | - )); | 3437 | + palette_uv_pending = Some((n, u_colors, v_colors)); |
| 3227 | } | 3438 | } |
| 3228 | } | 3439 | } |
| 3229 | // `read_filter_intra_mode_info` (spec 5.11.14, libaom decodemv.c): a | 3440 | // `read_filter_intra_mode_info` (spec 5.11.14, libaom decodemv.c): a |
| @@ -3254,19 +3465,28 @@ fn read_intra_mode( | |||
| 3254 | filter_intra = Some(fi_mode); | 3465 | filter_intra = Some(fi_mode); |
| 3255 | } | 3466 | } |
| 3256 | } | 3467 | } |
| 3257 | - // `av1_visit_palette` (decoder.c:234): the colour-index-map decode runs | 3468 | + // `av1_visit_palette` (decoder.c:234): plane 0 (Y) then plane 1 (chroma, |
| 3258 | - // here, after every mode-info symbol for the block (including UV | 3469 | + // shared U/V map) -- the same order libaom's own loop visits them in. |
| 3259 | - // palette and filter_intra above) -- plane 0 (Y) only in this decoder's | ||
| 3260 | - // scope, since UV palette already refused by name above and never left | ||
| 3261 | - // a pending map to decode. | ||
| 3262 | let palette_y = palette_y_pending.map(|(n, colors)| { | 3470 | let palette_y = palette_y_pending.map(|(n, colors)| { |
| 3263 | - let map = decode_color_index_map(dec, cdfs, n, side); | 3471 | + let map = decode_color_index_map(dec, cdfs, n, side, false); |
| 3264 | PALETTE_HITS.with(|c| c.set(c.get() + 1)); | 3472 | PALETTE_HITS.with(|c| c.set(c.get() + 1)); |
| 3265 | if trace { | 3473 | if trace { |
| 3266 | eprintln!("TRACE palette_y size={n} colors={:?}", &colors[..n]); | 3474 | eprintln!("TRACE palette_y size={n} colors={:?}", &colors[..n]); |
| 3267 | } | 3475 | } |
| 3268 | PaletteY { size: n, colors, map } | 3476 | PaletteY { size: n, colors, map } |
| 3269 | }); | 3477 | }); |
| 3478 | + let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { | ||
| 3479 | + let map = decode_color_index_map(dec, cdfs, n, side / 2, true); | ||
| 3480 | + PALETTE_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 3481 | + if trace { | ||
| 3482 | + eprintln!( | ||
| 3483 | + "TRACE palette_uv size={n} u_colors={:?} v_colors={:?}", | ||
| 3484 | + &u_colors[..n], | ||
| 3485 | + &v_colors[..n] | ||
| 3486 | + ); | ||
| 3487 | + } | ||
| 3488 | + PaletteUv { size: n, u_colors, v_colors, map } | ||
| 3489 | + }); | ||
| 3270 | Ok(( | 3490 | Ok(( |
| 3271 | skip, | 3491 | skip, |
| 3272 | mode, | 3492 | mode, |
| @@ -3276,6 +3496,7 @@ fn read_intra_mode( | |||
| 3276 | alpha, | 3496 | alpha, |
| 3277 | filter_intra, | 3497 | filter_intra, |
| 3278 | palette_y, | 3498 | palette_y, |
| 3499 | + palette_uv, | ||
| 3279 | )) | 3500 | )) |
| 3280 | } | 3501 | } |
| 3281 | 3502 | ||
| @@ -3766,7 +3987,8 @@ fn decode_block( | |||
| 3766 | let (r, c) = at; | 3987 | let (r, c) = at; |
| 3767 | let (px, py) = (c * SUB, r * SUB); | 3988 | let (px, py) = (c * SUB, r * SUB); |
| 3768 | let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); | 3989 | let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); |
| 3769 | - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y) = | 3990 | + let palette_uv_cache = neighbours.palette_uv_cache(at); |
| 3991 | + let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = | ||
| 3770 | read_intra_mode( | 3992 | read_intra_mode( |
| 3771 | dec, | 3993 | dec, |
| 3772 | cdfs, | 3994 | cdfs, |
| @@ -3779,6 +4001,7 @@ fn decode_block( | |||
| 3779 | allow_screen_content_tools, | 4001 | allow_screen_content_tools, |
| 3780 | allow_intrabc, | 4002 | allow_intrabc, |
| 3781 | Some((palette_ctx, &palette_cache)), | 4003 | Some((palette_ctx, &palette_cache)), |
| 4004 | + &palette_uv_cache, | ||
| 3782 | r * (SUB / MI), | 4005 | r * (SUB / MI), |
| 3783 | c * (SUB / MI), | 4006 | c * (SUB / MI), |
| 3784 | )?; | 4007 | )?; |
| @@ -3842,6 +4065,17 @@ fn decode_block( | |||
| 3842 | let buf: Vec<u8> = py.map.iter().map(|&idx| py.colors[idx as usize] as u8).collect(); | 4065 | let buf: Vec<u8> = py.map.iter().map(|&idx| py.colors[idx as usize] as u8).collect(); |
| 3843 | PALETTE_PRED.with(|c| *c.borrow_mut() = Some(buf)); | 4066 | PALETTE_PRED.with(|c| *c.borrow_mut() = Some(buf)); |
| 3844 | } | 4067 | } |
| 4068 | + // A UV-palette block's own chroma prediction override (lane-palette2 r1), | ||
| 4069 | + // same [`PALETTE_PRED`] slot as Y above -- set fresh right before each | ||
| 4070 | + // plane's own `reconstruct`/`read_plane` call below (never both planes at | ||
| 4071 | + // once), since Y's own set-then-take already emptied the slot by the time | ||
| 4072 | + // either of these run. | ||
| 4073 | + let palette_uv_bufs: Option<(Vec<u8>, Vec<u8>)> = palette_uv.as_ref().map(|puv| { | ||
| 4074 | + ( | ||
| 4075 | + puv.map.iter().map(|&idx| puv.u_colors[idx as usize] as u8).collect(), | ||
| 4076 | + puv.map.iter().map(|&idx| puv.v_colors[idx as usize] as u8).collect(), | ||
| 4077 | + ) | ||
| 4078 | + }); | ||
| 3845 | if skip { | 4079 | if skip { |
| 3846 | // A skipped block codes no residual syntax at all (spec 5.11.34): | 4080 | // A skipped block codes no residual syntax at all (spec 5.11.34): |
| 3847 | // straight prediction, on every plane. | 4081 | // straight prediction, on every plane. |
| @@ -3858,6 +4092,9 @@ fn decode_block( | |||
| 3858 | smooth_neighbor, | 4092 | smooth_neighbor, |
| 3859 | ); | 4093 | ); |
| 3860 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 4094 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 4095 | + if let Some((ub, _)) = &palette_uv_bufs { | ||
| 4096 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(ub.clone())); | ||
| 4097 | + } | ||
| 3861 | u.reconstruct( | 4098 | u.reconstruct( |
| 3862 | cpx, | 4099 | cpx, |
| 3863 | cpy, | 4100 | cpy, |
| @@ -3870,6 +4107,9 @@ fn decode_block( | |||
| 3870 | None, | 4107 | None, |
| 3871 | smooth_neighbor_uv, | 4108 | smooth_neighbor_uv, |
| 3872 | ); | 4109 | ); |
| 4110 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 4111 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(vb.clone())); | ||
| 4112 | + } | ||
| 3873 | v.reconstruct( | 4113 | v.reconstruct( |
| 3874 | cpx, | 4114 | cpx, |
| 3875 | cpy, | 4115 | cpy, |
| @@ -3914,6 +4154,9 @@ fn decode_block( | |||
| 3914 | smooth_neighbor, | 4154 | smooth_neighbor, |
| 3915 | )?; | 4155 | )?; |
| 3916 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 4156 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 4157 | + if let Some((ub, _)) = &palette_uv_bufs { | ||
| 4158 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(ub.clone())); | ||
| 4159 | + } | ||
| 3917 | let u_grid = read_plane( | 4160 | let u_grid = read_plane( |
| 3918 | dec, | 4161 | dec, |
| 3919 | cdfs, | 4162 | cdfs, |
| @@ -3942,6 +4185,9 @@ fn decode_block( | |||
| 3942 | &u.data[cpy * u.width + cpx..][..chroma_side] | 4185 | &u.data[cpy * u.width + cpx..][..chroma_side] |
| 3943 | ); | 4186 | ); |
| 3944 | } | 4187 | } |
| 4188 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 4189 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(vb.clone())); | ||
| 4190 | + } | ||
| 3945 | let v_grid = read_plane( | 4191 | let v_grid = read_plane( |
| 3946 | dec, | 4192 | dec, |
| 3947 | cdfs, | 4193 | cdfs, |
| @@ -4023,6 +4269,9 @@ fn decode_block( | |||
| 4023 | } | 4269 | } |
| 4024 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 4270 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 4025 | let chroma_around = neighbours.around(at, side); | 4271 | let chroma_around = neighbours.around(at, side); |
| 4272 | + if let Some((ub, _)) = &palette_uv_bufs { | ||
| 4273 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(ub.clone())); | ||
| 4274 | + } | ||
| 4026 | let u_grid = read_plane( | 4275 | let u_grid = read_plane( |
| 4027 | dec, | 4276 | dec, |
| 4028 | cdfs, | 4277 | cdfs, |
| @@ -4045,6 +4294,9 @@ fn decode_block( | |||
| 4045 | None, | 4294 | None, |
| 4046 | smooth_neighbor_uv, | 4295 | smooth_neighbor_uv, |
| 4047 | )?; | 4296 | )?; |
| 4297 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 4298 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(vb.clone())); | ||
| 4299 | + } | ||
| 4048 | let v_grid = read_plane( | 4300 | let v_grid = read_plane( |
| 4049 | dec, | 4301 | dec, |
| 4050 | cdfs, | 4302 | cdfs, |
| @@ -4078,6 +4330,10 @@ fn decode_block( | |||
| 4078 | .as_ref() | 4330 | .as_ref() |
| 4079 | .map_or((0, [0u16; 8]), |p| (p.size, p.colors)); | 4331 | .map_or((0, [0u16; 8]), |p| (p.size, p.colors)); |
| 4080 | neighbours.record_palette_y(at, side, py_size, py_colors); | 4332 | neighbours.record_palette_y(at, side, py_size, py_colors); |
| 4333 | + let (puv_size, puv_colors) = palette_uv | ||
| 4334 | + .as_ref() | ||
| 4335 | + .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); | ||
| 4336 | + neighbours.record_palette_uv(at, side, puv_size, puv_colors); | ||
| 4081 | neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip); | 4337 | neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip); |
| 4082 | neighbours.fill_lf_grid( | 4338 | neighbours.fill_lf_grid( |
| 4083 | (r * (SUB / MI), c * (SUB / MI)), | 4339 | (r * (SUB / MI), c * (SUB / MI)), |
| @@ -4135,7 +4391,7 @@ fn decode_leaf8( | |||
| 4135 | // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec | 4391 | // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec |
| 4136 | // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other | 4392 | // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other |
| 4137 | // `decode_block` caller at 16x16 and up. | 4393 | // `decode_block` caller at 16x16 and up. |
| 4138 | - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, _palette_y) = | 4394 | + let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, _palette_y, _palette_uv) = |
| 4139 | read_intra_mode( | 4395 | read_intra_mode( |
| 4140 | dec, | 4396 | dec, |
| 4141 | cdfs, | 4397 | cdfs, |
| @@ -4148,6 +4404,7 @@ fn decode_leaf8( | |||
| 4148 | allow_screen_content_tools, | 4404 | allow_screen_content_tools, |
| 4149 | allow_intrabc, | 4405 | allow_intrabc, |
| 4150 | None, | 4406 | None, |
| 4407 | + &[], | ||
| 4151 | leaf_mi.0, | 4408 | leaf_mi.0, |
| 4152 | leaf_mi.1, | 4409 | leaf_mi.1, |
| 4153 | )?; | 4410 | )?; |
crates/ec-av1/src/stream.rsmodified+118 -0
| @@ -1707,6 +1707,124 @@ mod tests { | |||
| 1707 | assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg"); | 1707 | assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg"); |
| 1708 | } | 1708 | } |
| 1709 | 1709 | ||
| 1710 | + /// A real `aomenc` palette-**UV** fixture (lane-palette2 r2): `testsrc2` | ||
| 1711 | + /// (the multicoloured AV1 test pattern -- flat, few-colour, repetitive | ||
| 1712 | + /// per-region colour *and* chroma, unlike `smptebars=hue=s=0` above, | ||
| 1713 | + /// which flattened chroma to a single value specifically to avoid | ||
| 1714 | + /// exercising this path). Same square-only recipe as the palette-Y gate | ||
| 1715 | + /// (`--enable-rect-partitions=0`/`-ab-`/`-1to4-`, fixed 32x32 partition) | ||
| 1716 | + /// so a UV palette block never lands inside the still-refused HORZ/VERT | ||
| 1717 | + /// screen-content strip. HARD-asserts [`decode::palette_uv_hits`] moved | ||
| 1718 | + /// -- a stream that never reads a real UV palette block would decode (or | ||
| 1719 | + /// not) by construction without proving this milestone at all | ||
| 1720 | + /// ([[gate-blind-to-feature]]). | ||
| 1721 | + #[test] | ||
| 1722 | + fn a_real_aomenc_stream_with_palette_uv_decodes_pixel_exact() { | ||
| 1723 | + const NAME: &str = "a_real_aomenc_stream_with_palette_uv_decodes_pixel_exact"; | ||
| 1724 | + if !have_ffmpeg() { | ||
| 1725 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1726 | + return; | ||
| 1727 | + } | ||
| 1728 | + if !have_aomenc() { | ||
| 1729 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 1730 | + return; | ||
| 1731 | + } | ||
| 1732 | + let source = "testsrc2=size=64x64:rate=25"; | ||
| 1733 | + fn render(source: &str) -> Vec<u8> { | ||
| 1734 | + Command::new("ffmpeg") | ||
| 1735 | + .args([ | ||
| 1736 | + "-v", | ||
| 1737 | + "error", | ||
| 1738 | + "-f", | ||
| 1739 | + "lavfi", | ||
| 1740 | + "-i", | ||
| 1741 | + source, | ||
| 1742 | + "-pix_fmt", | ||
| 1743 | + "yuv420p", | ||
| 1744 | + "-t", | ||
| 1745 | + "0.16", | ||
| 1746 | + "-f", | ||
| 1747 | + "yuv4mpegpipe", | ||
| 1748 | + "-", | ||
| 1749 | + ]) | ||
| 1750 | + .stdin(Stdio::null()) | ||
| 1751 | + .stdout(Stdio::piped()) | ||
| 1752 | + .stderr(Stdio::piped()) | ||
| 1753 | + .output() | ||
| 1754 | + .expect("ffmpeg failed to run") | ||
| 1755 | + .stdout | ||
| 1756 | + } | ||
| 1757 | + let y4m_a = render(source); | ||
| 1758 | + let y4m_b = render(source); | ||
| 1759 | + assert_eq!( | ||
| 1760 | + y4m_a, y4m_b, | ||
| 1761 | + "testsrc2 must render byte-identical across two runs" | ||
| 1762 | + ); | ||
| 1763 | + let y4m = y4m_a; | ||
| 1764 | + let mut child = Command::new(aomenc_path()) | ||
| 1765 | + .args([ | ||
| 1766 | + "--codec=av1", | ||
| 1767 | + "--passes=1", | ||
| 1768 | + "--end-usage=q", | ||
| 1769 | + "--cq-level=30", | ||
| 1770 | + "--cpu-used=0", | ||
| 1771 | + "--threads=1", | ||
| 1772 | + "--row-mt=0", | ||
| 1773 | + "--sb-size=64", | ||
| 1774 | + "--tune-content=screen", | ||
| 1775 | + "--enable-palette=1", | ||
| 1776 | + "--enable-intrabc=0", | ||
| 1777 | + "--enable-rect-partitions=0", | ||
| 1778 | + "--enable-ab-partitions=0", | ||
| 1779 | + "--enable-1to4-partitions=0", | ||
| 1780 | + "--min-partition-size=32", | ||
| 1781 | + "--max-partition-size=32", | ||
| 1782 | + "--enable-filter-intra=0", | ||
| 1783 | + "--enable-cdef=0", | ||
| 1784 | + "--enable-restoration=0", | ||
| 1785 | + "--enable-tx-size-search=0", | ||
| 1786 | + "--loopfilter-control=0", | ||
| 1787 | + "--obu", | ||
| 1788 | + "-o", | ||
| 1789 | + "-", | ||
| 1790 | + "-", | ||
| 1791 | + ]) | ||
| 1792 | + .stdin(Stdio::piped()) | ||
| 1793 | + .stdout(Stdio::piped()) | ||
| 1794 | + .stderr(Stdio::piped()) | ||
| 1795 | + .spawn() | ||
| 1796 | + .expect("aomenc failed to start"); | ||
| 1797 | + child | ||
| 1798 | + .stdin | ||
| 1799 | + .take() | ||
| 1800 | + .expect("aomenc stdin") | ||
| 1801 | + .write_all(&y4m) | ||
| 1802 | + .expect("writing y4m to aomenc"); | ||
| 1803 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 1804 | + assert!( | ||
| 1805 | + out.status.success(), | ||
| 1806 | + "aomenc refused the fixture: {}", | ||
| 1807 | + String::from_utf8_lossy(&out.stderr) | ||
| 1808 | + ); | ||
| 1809 | + let stream = out.stdout; | ||
| 1810 | + let before = decode::palette_uv_hits(); | ||
| 1811 | + let frames = match decode_stream(&stream) { | ||
| 1812 | + Ok(frames) => frames, | ||
| 1813 | + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), | ||
| 1814 | + }; | ||
| 1815 | + assert!( | ||
| 1816 | + decode::palette_uv_hits() > before, | ||
| 1817 | + "palette_uv_mode never fired decoding this stream -- gate is vacuous" | ||
| 1818 | + ); | ||
| 1819 | + let frame_count = frames.len(); | ||
| 1820 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 64, 64, frame_count); | ||
| 1821 | + for i in 0..frame_count { | ||
| 1822 | + assert_eq!(frames[i].y, ffmpeg_frames[i].y, "luma vs ffmpeg, frame {i}"); | ||
| 1823 | + assert_eq!(frames[i].u, ffmpeg_frames[i].u, "U vs ffmpeg, frame {i}"); | ||
| 1824 | + assert_eq!(frames[i].v, ffmpeg_frames[i].v, "V vs ffmpeg, frame {i}"); | ||
| 1825 | + } | ||
| 1826 | + } | ||
| 1827 | + | ||
| 1710 | /// As [`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`]'s | 1828 | /// As [`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`]'s |
| 1711 | /// harness, but with the deblocking filter left *on* (no | 1829 | /// harness, but with the deblocking filter left *on* (no |
| 1712 | /// `--loopfilter-control=0`) at a crf high enough that libaom actually | 1830 | /// `--loopfilter-control=0`) at a crf high enough that libaom actually |
lanes/palette2-r1.charter.mdadded+60 -0
| @@ -0,0 +1,60 @@ | |||
| 1 | +# lane-palette2 r1 — the palette frontier | ||
| 2 | + | ||
| 3 | +Fresh lane off main (170a5a3). Palette-Y already decodes pixel-exact; the lane | ||
| 4 | +that landed it is merged and retired. Read its work in `git log` for | ||
| 5 | +`decode_color_index_map` and `read_intra_mode`'s palette branch before editing. | ||
| 6 | + | ||
| 7 | +## Why this lane exists — measured, not guessed | ||
| 8 | +I probed five content classes through plain default-settings aomenc | ||
| 9 | +(`--cpu-used=4 --end-usage=q --cq-level=32`, no `--enable-*` flags) with | ||
| 10 | +`cargo run -p ec-av1 --example decode_probe`. Three of the five stop on a | ||
| 11 | +palette refusal: | ||
| 12 | +- `testsrc2` -> "a block that actually uses a palette (UV) -- reconstruction | ||
| 13 | + is out of scope" | ||
| 14 | +- `smptebars` and `rgbtestsrc` -> "a HORZ/VERT intra strip in a screen-content | ||
| 15 | + frame (palette syntax is consumed for square blocks only)" | ||
| 16 | +- `life` -> "a palette block with a split luma transform (round 1)" | ||
| 17 | + | ||
| 18 | +Palette is the single biggest thing between this decoder and an ordinary AV1 | ||
| 19 | +stream. Close those three, in that order — each is a gate-then-lift. | ||
| 20 | + | ||
| 21 | +## Order | ||
| 22 | +1. **UV palette reconstruction.** The reads already exist and are correct (the | ||
| 23 | + previous lane ported `palette_uv_mode`/`palette_uv_size`; it deliberately | ||
| 24 | + skipped `read_palette_colors_uv` because the refusal aborts immediately, so | ||
| 25 | + that reader still needs writing). Then reconstruct both chroma planes from | ||
| 26 | + the palette and its index map. | ||
| 27 | +2. **Palette on a rectangular (HORZ/VERT) intra strip.** `palette_bsize_ctx` | ||
| 28 | + and the size/context derivation assume a square block today. | ||
| 29 | +3. **Palette block with a split luma transform.** | ||
| 30 | + | ||
| 31 | +Each step: gate FIRST against a real aomenc stream, driving the tile decode | ||
| 32 | +below `decode_stream` so the refusal cannot short-circuit the code you are | ||
| 33 | +measuring ([[refusal-short-circuits-its-own-code]]); then the implementation; | ||
| 34 | +then lift the refusal and update `refusal_inventory.rs` **in the same commit**. | ||
| 35 | +A branch that lifts a refusal without a gate does not merge to main. The gate | ||
| 36 | +must hard-assert that the feature actually fired — a pixel match on a stream | ||
| 37 | +that never used a palette proves nothing ([[gate-blind-to-feature]]). | ||
| 38 | + | ||
| 39 | +Content that reaches each case is known: `testsrc2` for UV, `smptebars` or | ||
| 40 | +`rgbtestsrc` for the rect strips, `life` for the split transform, all at the | ||
| 41 | +default settings above and `--sb-size=64` (this decoder hardcodes 64px | ||
| 42 | +superblocks). `gate_coverage.rs` requires an explicit `--enable-palette=1` for a | ||
| 43 | +gate to count as exercising palette. | ||
| 44 | + | ||
| 45 | +## Budget discipline | ||
| 46 | +75 turns, and they do NOT reset if you are resumed. At about turn 55, stop | ||
| 47 | +starting new work: commit what is green and write your report. Five rounds in a | ||
| 48 | +recent batch died mid-edit with nothing reported, each costing a whole round to | ||
| 49 | +recover. | ||
| 50 | + | ||
| 51 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-palette2`; foreground | ||
| 52 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; fixtures | ||
| 53 | +through `gradients_source(seed, w, h, tail)` where a synthetic source will do; | ||
| 54 | +every ffmpeg generate bounded with `-t`; `EC_AV1_REQUIRE_AOMENC=1`; aomenc | ||
| 55 | +`--threads=1 --row-mt=0 --sb-size=64`. Oracle rungs 6, 7, 8, 8b are taken — take | ||
| 56 | +9; `~/.cache/aom-oracle` is SHARED with sibling lanes, so env-gated rungs in | ||
| 57 | +`scripts/instrument-aom-oracle.sh` only, never a throwaway patch left in the | ||
| 58 | +tree. Sibling worktrees have live agents — never build in or edit them. Never | ||
| 59 | +push, never merge into main. End with `lanes/palette2-r1.report.md`, VERDICT on | ||
| 60 | +line 1. | ||
lanes/palette2-r2.charter.mdadded+35 -0
| @@ -0,0 +1,35 @@ | |||
| 1 | +# lane-palette2 r2 — finish UV palette reconstruction | ||
| 2 | + | ||
| 3 | +At 96fde87. **I merged main for you.** r1 hit its cap mid-edit, having just | ||
| 4 | +said "now add `record_palette_uv` at the tail, near `record_palette_y`"; its | ||
| 5 | +tree is committed verbatim at d2ea8e7 and **is unverified — it may not compile.** | ||
| 6 | +Check that first, then continue. | ||
| 7 | + | ||
| 8 | +Your charter is still `lanes/palette2-r1.charter.md`; read it. Step 1 is UV | ||
| 9 | +palette reconstruction: the previous palette lane ported `palette_uv_mode` and | ||
| 10 | +`palette_uv_size` but deliberately skipped `read_palette_colors_uv`, because the | ||
| 11 | +refusal aborted the decode immediately and no later bit needed to stay in sync. | ||
| 12 | +That reader now has to exist, and both chroma planes have to be reconstructed | ||
| 13 | +from the palette and its index map. | ||
| 14 | + | ||
| 15 | +Gate first, below `decode_stream`, hard-asserting the UV palette path actually | ||
| 16 | +fired — a pixel match on a stream that never used a UV palette proves nothing | ||
| 17 | +([[gate-blind-to-feature]]). `testsrc2` at plain default aomenc settings reaches | ||
| 18 | +this case; that is how I found it. Then lift the refusal and update | ||
| 19 | +`refusal_inventory.rs` in the SAME commit. | ||
| 20 | + | ||
| 21 | +Steps 2 and 3 (palette on a HORZ/VERT rect strip, palette with a split luma | ||
| 22 | +transform) stay in the charter for a later round — do not start them until UV is | ||
| 23 | +green and committed. | ||
| 24 | + | ||
| 25 | +## Budget discipline | ||
| 26 | +75 turns, no reset on resume. At about turn 55, stop starting new work: commit | ||
| 27 | +what is green and write your report. The merge is already done for you. | ||
| 28 | + | ||
| 29 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-palette2`; foreground | ||
| 30 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; ffmpeg | ||
| 31 | +generates bounded with `-t`; `EC_AV1_REQUIRE_AOMENC=1`; aomenc | ||
| 32 | +`--threads=1 --row-mt=0 --sb-size=64`. Oracle rung 12 is yours; `~/.cache/aom-oracle` | ||
| 33 | +is SHARED, env-gated rungs only. Sibling worktrees have live agents — never build | ||
| 34 | +in or edit them. Never push, never merge into main. End with | ||
| 35 | +`lanes/palette2-r2.report.md`, VERDICT on line 1. | ||
lanes/palette2-r2.report.mdadded+73 -0
| @@ -0,0 +1,73 @@ | |||
| 1 | +VERDICT: DONE -- UV palette reconstruction green and committed (0b79412) | ||
| 2 | + | ||
| 3 | +## What happened | ||
| 4 | + | ||
| 5 | +r1's uncommitted WIP (committed verbatim at d2ea8e7, "unverified") was much | ||
| 6 | +further along than the charter's own description suggested: `read_palette_colors_uv`, | ||
| 7 | +`PaletteUv` reconstruction into both chroma planes (`palette_uv_bufs` -> | ||
| 8 | +`PALETTE_PRED` for `u.reconstruct`/`v.reconstruct`, mirroring the palette-Y | ||
| 9 | +path), and `record_palette_uv` neighbour tracking were all already written | ||
| 10 | +and, on inspection, correct. The tree did not compile for one reason: the | ||
| 11 | +8x8-leaf call site of `read_intra_mode` (crates/ec-av1/src/decode.rs:4394) | ||
| 12 | +was still destructuring the pre-UV 8-tuple and passing the pre-UV 13-arg | ||
| 13 | +call, one edit behind the widened `read_intra_mode` signature (9-tuple | ||
| 14 | +return, 14-arg call with the new `palette_uv_cache: &[u16]` parameter) that | ||
| 15 | +the rest of the file had already moved to. | ||
| 16 | + | ||
| 17 | +Fixed by adding `_palette_uv` to the destructured tuple and `&[]` for | ||
| 18 | +`palette_uv_cache` at that one call site -- the same "read+refuse the | ||
| 19 | +symbol, never reconstruct" corner-cut that site already used for palette_y | ||
| 20 | +(`None` for the `palette` param), extended to UV. That site is the excluded | ||
| 21 | +8x8-leaf path (`prev_leaf`/rect handling), not the intra square-block path | ||
| 22 | +this round's gate exercises, so no new refusal or behaviour needed there. | ||
| 23 | + | ||
| 24 | +## Gate | ||
| 25 | + | ||
| 26 | +`a_real_aomenc_stream_with_palette_uv_decodes_pixel_exact` | ||
| 27 | +(crates/ec-av1/src/stream.rs, new): `testsrc2` (the multicoloured AV1 test | ||
| 28 | +pattern -- flat, few-colour, repetitive chroma per region, unlike | ||
| 29 | +`smptebars=hue=s=0` in the sibling palette-Y gate, which deliberately | ||
| 30 | +flattened chroma to sidestep this exact case) through the same square-only | ||
| 31 | +recipe as the palette-Y gate (`--enable-rect-partitions=0`/`-ab-`/`-1to4-`, | ||
| 32 | +fixed 32x32 partition, `--enable-palette=1`, `--sb-size=64 --threads=1 | ||
| 33 | +--row-mt=0`). Hard-asserts `decode::palette_uv_hits()` moved before | ||
| 34 | +comparing pixel output, per [[gate-blind-to-feature]] -- a pixel match on a | ||
| 35 | +stream that never used a UV palette would prove nothing. Live run: 2 UV | ||
| 36 | +palette blocks fire, both frames' Y/U/V match ffmpeg's independent decode | ||
| 37 | +of the same bytes exactly. | ||
| 38 | + | ||
| 39 | +## refusal_inventory.rs | ||
| 40 | + | ||
| 41 | +No edit needed. "a block that actually uses a palette (UV) -- reconstruction | ||
| 42 | +is out of scope" is still genuinely present in decode.rs at two other call | ||
| 43 | +sites -- the HORZ/VERT rect-strip path (decode.rs ~9263) and the inter-frame | ||
| 44 | +8x8-leaf path (decode.rs ~10359) -- both out of this round's scope (charter | ||
| 45 | +steps 2/3, plus inter-frame palette which the charter never named). Those | ||
| 46 | +stay refused; the inventory's scan is string-presence-based, so it already | ||
| 47 | +passes with no change. Confirmed: `refusal_inventory::tests::the_decode_path_refuses_exactly_the_listed_cases` | ||
| 48 | +and `capability_claims_are_declared_not_scattered` both green. | ||
| 49 | + | ||
| 50 | +## Checks run | ||
| 51 | + | ||
| 52 | +- `cargo check -p ec-av1` -- clean (was 2 errors before the fix). | ||
| 53 | +- `cargo test -p ec-av1 --lib` (EC_AV1_REQUIRE_AOMENC=1) -- 263 passed, 18 | ||
| 54 | + ignored, 0 failed, in 133.5s. Includes the new UV palette gate, the | ||
| 55 | + existing palette-Y gate, refusal_inventory, and gate_coverage, all green. | ||
| 56 | +- Command: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-palette2 | ||
| 57 | + EC_AV1_REQUIRE_AOMENC=1 nice -n 19 cargo test -p ec-av1 --lib -j4` | ||
| 58 | + | ||
| 59 | +## Scope discipline | ||
| 60 | + | ||
| 61 | +Did not touch steps 2 (HORZ/VERT rect-strip palette) or 3 (split-transform | ||
| 62 | +palette) -- both stay refused, per charter instruction to wait until UV is | ||
| 63 | +green and committed first. Turn budget: finished well under the ~55-turn | ||
| 64 | +soft cap (compile fix + one gate + verification), so no further step was | ||
| 65 | +started this round per charter ("do not start them until UV is green and | ||
| 66 | +committed" -- deferring to the next round rather than scope-creeping into | ||
| 67 | +step 2 with remaining budget). | ||
| 68 | + | ||
| 69 | +## Oracle / sibling worktrees | ||
| 70 | + | ||
| 71 | +Used the shared `~/.cache/aom-oracle/build/aomenc` read-only (rung 12 was | ||
| 72 | +not needed -- no change to `scripts/instrument-aom-oracle.sh`). No edits | ||
| 73 | +outside this worktree. Nothing pushed, nothing merged into main. | ||