Palette on a square 8x8 intra leaf (decode_leaf8 passed None palette ctx/cache and refused every real 8x8 palette block)
Browse files at this commitc9d2302aed8506fc7ced361194ebfdf837a9d010Parent: 377b730- feat
- palette on a square 8x8 intra leaf (decode_leaf8 passed None palette ctx/cache and refused every real 8x8 palette block)
3 changed files +424 -14
- crates/ec-av1/src/decode.rs +126 -14
- crates/ec-av1/src/stream.rs +229 -0
- lanes/pal8-r1.report.md +69 -0
crates/ec-av1/src/decode.rsmodified+126 -14
| @@ -1519,6 +1519,41 @@ pub(crate) fn palette_split_tx_hits() -> usize { | |||
| 1519 | PALETTE_SPLIT_TX_HITS.with(|c| c.get()) | 1519 | PALETTE_SPLIT_TX_HITS.with(|c| c.get()) |
| 1520 | } | 1520 | } |
| 1521 | 1521 | ||
| 1522 | +thread_local! { | ||
| 1523 | + /// lane-pal8 r1: square 8x8 LEAVES ([`decode_leaf8`]) that actually use a | ||
| 1524 | + /// palette (Y or UV) -- the shape every 8-bit `--tune-content=screen` | ||
| 1525 | + /// stream stopped on, since aomenc palettes square blocks at 8 bit and | ||
| 1526 | + /// `--min-partition-size=8` puts them on this leaf path. | ||
| 1527 | + static PALETTE_LEAF8_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1528 | +} | ||
| 1529 | + | ||
| 1530 | +/// Current value of [`PALETTE_LEAF8_HITS`]. | ||
| 1531 | +pub(crate) fn palette_leaf8_hits() -> usize { | ||
| 1532 | + PALETTE_LEAF8_HITS.with(|c| c.get()) | ||
| 1533 | +} | ||
| 1534 | + | ||
| 1535 | +/// Zeroes [`PALETTE_LEAF8_HITS`] (per-attempt gate counting). | ||
| 1536 | +pub(crate) fn reset_palette_leaf8_hits() { | ||
| 1537 | + PALETTE_LEAF8_HITS.with(|c| c.set(0)); | ||
| 1538 | +} | ||
| 1539 | + | ||
| 1540 | +thread_local! { | ||
| 1541 | + /// lane-pal8 r1: NON-SKIP palette blocks on a superblock-level (64-level) | ||
| 1542 | + /// HORZ/VERT or 1:4 strip ([`decode_block_rect64`]) -- i.e. a palette | ||
| 1543 | + /// block that also carries a real, corner-cropped luma transform. | ||
| 1544 | + static PALETTE_SB_STRIP_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1545 | +} | ||
| 1546 | + | ||
| 1547 | +/// Current value of [`PALETTE_SB_STRIP_HITS`]. | ||
| 1548 | +pub(crate) fn palette_sb_strip_hits() -> usize { | ||
| 1549 | + PALETTE_SB_STRIP_HITS.with(|c| c.get()) | ||
| 1550 | +} | ||
| 1551 | + | ||
| 1552 | +/// Zeroes [`PALETTE_SB_STRIP_HITS`] (per-attempt gate counting). | ||
| 1553 | +pub(crate) fn reset_palette_sb_strip_hits() { | ||
| 1554 | + PALETTE_SB_STRIP_HITS.with(|c| c.set(0)); | ||
| 1555 | +} | ||
| 1556 | + | ||
| 1522 | // lane-hgkf r2: SKIPPED intra blocks whose `tx_depth` split the luma transform | 1557 | // lane-hgkf r2: SKIPPED intra blocks whose `tx_depth` split the luma transform |
| 1523 | // and which are therefore predicted one transform unit at a time (a skipped | 1558 | // and which are therefore predicted one transform unit at a time (a skipped |
| 1524 | // block codes no coefficients, so nothing else in the stream witnesses this | 1559 | // block codes no coefficients, so nothing else in the stream witnesses this |
| @@ -8593,6 +8628,14 @@ fn decode_block_rect64( | |||
| 8593 | // needs the plain, uncropped rect reader [`decode_block_rect`] already | 8628 | // needs the plain, uncropped rect reader [`decode_block_rect`] already |
| 8594 | // has, not this one's truncation. `skip` (no residual at all) is | 8629 | // has, not this one's truncation. `skip` (no residual at all) is |
| 8595 | // still supported below (lane-palette2 r4). | 8630 | // still supported below (lane-palette2 r4). |
| 8631 | + // | ||
| 8632 | + // lane-pal8 r1 MEASURED the lift and it is NOT free: dropping this | ||
| 8633 | + // refusal decodes `testsrc2` 128x128 10-bit cq55 `--enable-palette=1 | ||
| 8634 | + // --min-partition-size=8 --tile-columns=1` with a whole-frame pixel | ||
| 8635 | + // mismatch (the arm the gate below counts). Something in this shape's | ||
| 8636 | + // palette prediction or its corner-cropped residual is wrong, and the | ||
| 8637 | + // refusal stays until that is found -- it is counted, never skipped. | ||
| 8638 | + PALETTE_SB_STRIP_HITS.with(|c| c.set(c.get() + 1)); | ||
| 8596 | return Err(unsupported( | 8639 | return Err(unsupported( |
| 8597 | "a palette block with a real transform on a superblock-level HORZ/VERT \ | 8640 | "a palette block with a real transform on a superblock-level HORZ/VERT \ |
| 8598 | strip (corner-cropped luma coefficients not ported for palette)", | 8641 | strip (corner-cropped luma coefficients not ported for palette)", |
| @@ -10670,7 +10713,15 @@ fn decode_leaf8( | |||
| 10670 | // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec | 10713 | // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec |
| 10671 | // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other | 10714 | // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other |
| 10672 | // `decode_block` caller at 16x16 and up. | 10715 | // `decode_block` caller at 16x16 and up. |
| 10673 | - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, _palette_y, _palette_uv) = | 10716 | + // lane-pal8 r1: this leaf's own palette-Y mode ctx and colour cache |
| 10717 | + // (`av1_get_palette_mode_ctx` / `av1_get_palette_cache`, decodemv.c:567, | ||
| 10718 | + // `read_palette_mode_info`), at its REAL mi position -- passing | ||
| 10719 | + // `None`/`&[]` read `palette_y_mode` off CDF row 0 and refused by name the | ||
| 10720 | + // moment a real 8x8 palette block fired, which is where every 8-bit | ||
| 10721 | + // `--tune-content=screen --min-partition-size=8` stream stopped. | ||
| 10722 | + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(leaf_mi); | ||
| 10723 | + let palette_uv_cache = neighbours.palette_uv_cache_mi(leaf_mi); | ||
| 10724 | + let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = | ||
| 10674 | read_intra_mode( | 10725 | read_intra_mode( |
| 10675 | dec, | 10726 | dec, |
| 10676 | cdfs, | 10727 | cdfs, |
| @@ -10682,11 +10733,31 @@ fn decode_leaf8( | |||
| 10682 | neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1), | 10733 | neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1), |
| 10683 | allow_screen_content_tools, | 10734 | allow_screen_content_tools, |
| 10684 | allow_intrabc, | 10735 | allow_intrabc, |
| 10685 | - None, | 10736 | + Some((palette_ctx, &palette_cache)), |
| 10686 | - &[], | 10737 | + &palette_uv_cache, |
| 10687 | leaf_mi.0, | 10738 | leaf_mi.0, |
| 10688 | leaf_mi.1, | 10739 | leaf_mi.1, |
| 10689 | )?; | 10740 | )?; |
| 10741 | + // `av1_visit_palette`'s reconstruction (decodeframe.c:1135): the colour | ||
| 10742 | + // index map, mapped through the base colours, IS the block's prediction -- | ||
| 10743 | + // carried to the next `reconstruct`/`read_plane` through the same | ||
| 10744 | + // [`PALETTE_PRED`] slot [`decode_block`] uses at 16x16 and up. | ||
| 10745 | + let palette_y_buf: Option<Vec<u16>> = palette_y | ||
| 10746 | + .as_ref() | ||
| 10747 | + .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()); | ||
| 10748 | + let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|p| { | ||
| 10749 | + ( | ||
| 10750 | + p.map.iter().map(|&i| p.u_colors[i as usize]).collect(), | ||
| 10751 | + p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), | ||
| 10752 | + ) | ||
| 10753 | + }); | ||
| 10754 | + let (pal_y_size, pal_y_colors) = | ||
| 10755 | + palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); | ||
| 10756 | + let (pal_uv_size, pal_uv_colors) = | ||
| 10757 | + palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); | ||
| 10758 | + if palette_y.is_some() || palette_uv.is_some() { | ||
| 10759 | + PALETTE_LEAF8_HITS.with(|c| c.set(c.get() + 1)); | ||
| 10760 | + } | ||
| 10690 | let uv_predict_mode = if uv_mode == UV_CFL_PRED { | 10761 | let uv_predict_mode = if uv_mode == UV_CFL_PRED { |
| 10691 | DC_PRED | 10762 | DC_PRED |
| 10692 | } else { | 10763 | } else { |
| @@ -10715,7 +10786,11 @@ fn decode_leaf8( | |||
| 10715 | // transform units, each off the units already written left/above of | 10786 | // transform units, each off the units already written left/above of |
| 10716 | // it inside this same leaf -- an intra block's transform size is read | 10787 | // it inside this same leaf -- an intra block's transform size is read |
| 10717 | // whether or not it is skipped, and spec 7.11.2 predicts per unit. | 10788 | // whether or not it is skipped, and spec 7.11.2 predicts per unit. |
| 10718 | - if resolved == 4 { | 10789 | + // A palette block's prediction is the whole-block index map, never |
| 10790 | + // per-transform-unit edges ([`decode_block`]'s own `split_tx_skip` | ||
| 10791 | + // rule) -- so a palette leaf takes the single 8x8 reconstruct below | ||
| 10792 | + // even when `tx_depth` resolved to TX_4X4. | ||
| 10793 | + if resolved == 4 && palette_y_buf.is_none() { | ||
| 10719 | SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | 10794 | SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); |
| 10720 | for tu_row in 0..2 { | 10795 | for tu_row in 0..2 { |
| 10721 | for tu_col in 0..2 { | 10796 | for tu_col in 0..2 { |
| @@ -10750,6 +10825,9 @@ fn decode_leaf8( | |||
| 10750 | } | 10825 | } |
| 10751 | } | 10826 | } |
| 10752 | } else { | 10827 | } else { |
| 10828 | + if let Some(buf) = &palette_y_buf { | ||
| 10829 | + set_palette_pred(buf.clone()); | ||
| 10830 | + } | ||
| 10753 | y.reconstruct( | 10831 | y.reconstruct( |
| 10754 | px, | 10832 | px, |
| 10755 | py, | 10833 | py, |
| @@ -10764,6 +10842,9 @@ fn decode_leaf8( | |||
| 10764 | ); | 10842 | ); |
| 10765 | } | 10843 | } |
| 10766 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8)); | 10844 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8)); |
| 10845 | + if let Some((ub, _)) = &palette_uv_bufs { | ||
| 10846 | + set_palette_pred(ub.clone()); | ||
| 10847 | + } | ||
| 10767 | u.reconstruct( | 10848 | u.reconstruct( |
| 10768 | cpx, | 10849 | cpx, |
| 10769 | cpy, | 10850 | cpy, |
| @@ -10776,6 +10857,9 @@ fn decode_leaf8( | |||
| 10776 | None, | 10857 | None, |
| 10777 | smooth_neighbor_uv, | 10858 | smooth_neighbor_uv, |
| 10778 | ); | 10859 | ); |
| 10860 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 10861 | + set_palette_pred(vb.clone()); | ||
| 10862 | + } | ||
| 10779 | v.reconstruct( | 10863 | v.reconstruct( |
| 10780 | cpx, | 10864 | cpx, |
| 10781 | cpy, | 10865 | cpy, |
| @@ -10793,6 +10877,9 @@ fn decode_leaf8( | |||
| 10793 | v_grid = vec![0i32; 16]; | 10877 | v_grid = vec![0i32; 16]; |
| 10794 | } else if resolved != 4 { | 10878 | } else if resolved != 4 { |
| 10795 | let around = neighbours.around_mi(leaf_mi, 8); | 10879 | let around = neighbours.around_mi(leaf_mi, 8); |
| 10880 | + if let Some(buf) = &palette_y_buf { | ||
| 10881 | + set_palette_pred(buf.clone()); | ||
| 10882 | + } | ||
| 10796 | luma_grid = read_plane( | 10883 | luma_grid = read_plane( |
| 10797 | dec, | 10884 | dec, |
| 10798 | cdfs, | 10885 | cdfs, |
| @@ -10820,6 +10907,9 @@ fn decode_leaf8( | |||
| 10820 | smooth_neighbor, | 10907 | smooth_neighbor, |
| 10821 | )?; | 10908 | )?; |
| 10822 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8)); | 10909 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8)); |
| 10910 | + if let Some((ub, _)) = &palette_uv_bufs { | ||
| 10911 | + set_palette_pred(ub.clone()); | ||
| 10912 | + } | ||
| 10823 | u_grid = read_plane( | 10913 | u_grid = read_plane( |
| 10824 | dec, | 10914 | dec, |
| 10825 | cdfs, | 10915 | cdfs, |
| @@ -10842,6 +10932,9 @@ fn decode_leaf8( | |||
| 10842 | None, | 10932 | None, |
| 10843 | smooth_neighbor_uv, | 10933 | smooth_neighbor_uv, |
| 10844 | )?; | 10934 | )?; |
| 10935 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 10936 | + set_palette_pred(vb.clone()); | ||
| 10937 | + } | ||
| 10845 | v_grid = read_plane( | 10938 | v_grid = read_plane( |
| 10846 | dec, | 10939 | dec, |
| 10847 | cdfs, | 10940 | cdfs, |
| @@ -10893,6 +10986,19 @@ fn decode_leaf8( | |||
| 10893 | y.height, | 10986 | y.height, |
| 10894 | ); | 10987 | ); |
| 10895 | let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1); | 10988 | let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1); |
| 10989 | + // Each 4x4 unit predicts from its own window of the block's | ||
| 10990 | + // 8x8 colour-index map ([`decode_block`]'s per-TU slice at | ||
| 10991 | + // 16x16 and up) -- the whole-block buffer would be taken by | ||
| 10992 | + // the FIRST unit and indexed at the wrong stride. | ||
| 10993 | + if let Some(buf) = &palette_y_buf { | ||
| 10994 | + PALETTE_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | ||
| 10995 | + let mut window = vec![0u16; 16]; | ||
| 10996 | + for row in 0..4 { | ||
| 10997 | + let src = (tu_row * 4 + row) * 8 + tu_col * 4; | ||
| 10998 | + window[row * 4..][..4].copy_from_slice(&buf[src..][..4]); | ||
| 10999 | + } | ||
| 11000 | + set_palette_pred(window); | ||
| 11001 | + } | ||
| 10896 | let tu_grid = read_plane( | 11002 | let tu_grid = read_plane( |
| 10897 | dec, | 11003 | dec, |
| 10898 | cdfs, | 11004 | cdfs, |
| @@ -10932,6 +11038,9 @@ fn decode_leaf8( | |||
| 10932 | } | 11038 | } |
| 10933 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8)); | 11039 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8)); |
| 10934 | let chroma_around = neighbours.around_mi(leaf_mi, 8); | 11040 | let chroma_around = neighbours.around_mi(leaf_mi, 8); |
| 11041 | + if let Some((ub, _)) = &palette_uv_bufs { | ||
| 11042 | + set_palette_pred(ub.clone()); | ||
| 11043 | + } | ||
| 10935 | u_grid = read_plane( | 11044 | u_grid = read_plane( |
| 10936 | dec, | 11045 | dec, |
| 10937 | cdfs, | 11046 | cdfs, |
| @@ -10954,6 +11063,9 @@ fn decode_leaf8( | |||
| 10954 | None, | 11063 | None, |
| 10955 | smooth_neighbor_uv, | 11064 | smooth_neighbor_uv, |
| 10956 | )?; | 11065 | )?; |
| 11066 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 11067 | + set_palette_pred(vb.clone()); | ||
| 11068 | + } | ||
| 10957 | v_grid = read_plane( | 11069 | v_grid = read_plane( |
| 10958 | dec, | 11070 | dec, |
| 10959 | cdfs, | 11071 | cdfs, |
| @@ -11004,12 +11116,12 @@ fn decode_leaf8( | |||
| 11004 | neighbours.above[leaf_mi.1 + cell][2] = v_state; | 11116 | neighbours.above[leaf_mi.1 + cell][2] = v_state; |
| 11005 | } | 11117 | } |
| 11006 | } | 11118 | } |
| 11007 | - // Non-palette 8x8 leaf (this path never reads a palette): clear the | 11119 | + // This leaf's own palette state into the mi-granular above/left bands |
| 11008 | - // above/left palette state over its own cell so the next block's ctx and | 11120 | + // (sizes 0 when it used none, which is what clears a previous block's |
| 11009 | - // colour cache do not read a previous block's palette (lane-palette2 r8). | 11121 | + // palette out of the next block's ctx and colour cache). |
| 11010 | { | 11122 | { |
| 11011 | - neighbours.record_palette_y_rect(leaf_mi, 8, 8, 0, [0u16; 8]); | 11123 | + neighbours.record_palette_y_rect(leaf_mi, 8, 8, pal_y_size, pal_y_colors); |
| 11012 | - neighbours.record_palette_uv_rect(leaf_mi, 8, 8, 0, [0u16; 8]); | 11124 | + neighbours.record_palette_uv_rect(leaf_mi, 8, 8, pal_uv_size, pal_uv_colors); |
| 11013 | } | 11125 | } |
| 11014 | neighbours.fill_skip_grid(leaf_mi, 2, skip); | 11126 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 11015 | neighbours.fill_lf_grid(leaf_mi, 2, 4, 0); | 11127 | neighbours.fill_lf_grid(leaf_mi, 2, 4, 0); |
| @@ -11017,12 +11129,12 @@ fn decode_leaf8( | |||
| 11017 | return Ok(mode); | 11129 | return Ok(mode); |
| 11018 | } | 11130 | } |
| 11019 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); | 11131 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); |
| 11020 | - // Non-palette 8x8 leaf (this path never reads a palette): clear the | 11132 | + // This leaf's own palette state into the mi-granular above/left bands |
| 11021 | - // above/left palette state over its own cell so the next block's ctx and | 11133 | + // (sizes 0 when it used none, which is what clears a previous block's |
| 11022 | - // colour cache do not read a previous block's palette (lane-palette2 r8). | 11134 | + // palette out of the next block's ctx and colour cache). |
| 11023 | { | 11135 | { |
| 11024 | - neighbours.record_palette_y_rect(leaf_mi, 8, 8, 0, [0u16; 8]); | 11136 | + neighbours.record_palette_y_rect(leaf_mi, 8, 8, pal_y_size, pal_y_colors); |
| 11025 | - neighbours.record_palette_uv_rect(leaf_mi, 8, 8, 0, [0u16; 8]); | 11137 | + neighbours.record_palette_uv_rect(leaf_mi, 8, 8, pal_uv_size, pal_uv_colors); |
| 11026 | } | 11138 | } |
| 11027 | INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1)); | 11139 | INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1)); |
| 11028 | neighbours.fill_skip_grid(leaf_mi, 2, skip); | 11140 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
crates/ec-av1/src/stream.rsmodified+229 -0
| @@ -2800,6 +2800,235 @@ mod tests { | |||
| 2800 | } | 2800 | } |
| 2801 | } | 2801 | } |
| 2802 | 2802 | ||
| 2803 | + /// lane-pal8 r1, the gate for a palette on a SQUARE 8x8 LEAF. | ||
| 2804 | + /// | ||
| 2805 | + /// `read_palette_mode_info` (decodemv.c:567) reads `palette_y_mode` for | ||
| 2806 | + /// every `DC_PRED` block whose `av1_get_palette_bsize_ctx` | ||
| 2807 | + /// (`num_pels_log2 - num_pels_log2[BLOCK_8X8]`, 0 at 8x8) exists, and | ||
| 2808 | + /// `av1_decode_palette_tokens` (decodeframe.c:1135, `av1_visit_palette`) | ||
| 2809 | + /// reads the colour-index map after the WHOLE mode-info read. Ours passed | ||
| 2810 | + /// `None`/`&[]` from [`decode::decode_leaf8`], reading the mode symbol off | ||
| 2811 | + /// CDF row 0 and refusing "a block that actually uses a palette (Y) -- | ||
| 2812 | + /// reconstruction is out of scope" the moment it fired -- and at 8 bit | ||
| 2813 | + /// aomenc palettes SQUARE blocks, so with `--min-partition-size=8` every | ||
| 2814 | + /// 8-bit screen-content stream stopped there (lane-kf900 r4's measurement). | ||
| 2815 | + /// | ||
| 2816 | + /// Sweeps both bit depths x cq 30/40/55 x `--enable-tx-size-search` 0/1 x | ||
| 2817 | + /// two lavfi sources (+ a `--tile-columns=1` arm, per the neighbour-map | ||
| 2818 | + /// rule: the palette bands are per-mi and tile-guarded). Key frame only | ||
| 2819 | + /// (`--limit=1`): the inter frames of these recipes stop on OTHER lanes' | ||
| 2820 | + /// open refusals (8x8 inter leaf chroma mode, inter 1:4 partitions). | ||
| 2821 | + /// HARD-asserts the 8x8-leaf palette counter moved on the compared arms | ||
| 2822 | + /// and that no arm mismatched, in or out of scope. | ||
| 2823 | + #[test] | ||
| 2824 | + fn a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact() { | ||
| 2825 | + const NAME: &str = "a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact"; | ||
| 2826 | + if !have_ffmpeg() { | ||
| 2827 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 2828 | + return; | ||
| 2829 | + } | ||
| 2830 | + if !have_aomenc() { | ||
| 2831 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 2832 | + return; | ||
| 2833 | + } | ||
| 2834 | + let (width, height) = (128usize, 128usize); | ||
| 2835 | + let (mut leaf8_total, mut fired_arms, mut compared, mut frames_compared) = | ||
| 2836 | + (0usize, 0u32, 0u32, 0usize); | ||
| 2837 | + let (mut out_of_scope, mut out_of_scope_mismatch, mut refusals) = (0u32, 0u32, 0u32); | ||
| 2838 | + let (mut sb_strip_total, mut sb_strip_arms) = (0usize, 0u32); | ||
| 2839 | + // The one palette shape this round did NOT lift (measured: lifting it | ||
| 2840 | + // mismatches -- see [`decode_block_rect64`]'s own comment). | ||
| 2841 | + let mut sb_strip_refusals = 0u32; | ||
| 2842 | + for src in ["testsrc2", "smptebars"] { | ||
| 2843 | + for depth in [8usize, 10usize] { | ||
| 2844 | + for cq in [30usize, 40, 55] { | ||
| 2845 | + for txs in [0usize, 1] { | ||
| 2846 | + for tiles in [0usize, 1] { | ||
| 2847 | + let arm = format!("{src}-{depth}bit-cq{cq}-txs{txs}-tc{tiles}"); | ||
| 2848 | + let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 2849 | + let size = format!("{src}=size={width}x{height}:rate=25"); | ||
| 2850 | + let render = || { | ||
| 2851 | + let out = Command::new("ffmpeg") | ||
| 2852 | + .args([ | ||
| 2853 | + "-v", "error", "-f", "lavfi", "-i", &size, "-t", "0.04", | ||
| 2854 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", | ||
| 2855 | + "yuv4mpegpipe", "-", | ||
| 2856 | + ]) | ||
| 2857 | + .stdin(Stdio::null()) | ||
| 2858 | + .stdout(Stdio::piped()) | ||
| 2859 | + .stderr(Stdio::piped()) | ||
| 2860 | + .output() | ||
| 2861 | + .expect("ffmpeg failed to run"); | ||
| 2862 | + assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}"); | ||
| 2863 | + out.stdout | ||
| 2864 | + }; | ||
| 2865 | + let y4m_a = render(); | ||
| 2866 | + let y4m_b = render(); | ||
| 2867 | + assert_eq!( | ||
| 2868 | + y4m_a, y4m_b, | ||
| 2869 | + "{NAME}: {arm} must render byte-identical across two runs" | ||
| 2870 | + ); | ||
| 2871 | + let y4m = y4m_a; | ||
| 2872 | + let depth_arg = format!("--bit-depth={depth}"); | ||
| 2873 | + let input_depth_arg = format!("--input-bit-depth={depth}"); | ||
| 2874 | + let cq_arg = format!("--cq-level={cq}"); | ||
| 2875 | + let txs_arg = format!("--enable-tx-size-search={txs}"); | ||
| 2876 | + let tiles_arg = format!("--tile-columns={tiles}"); | ||
| 2877 | + let mut child = Command::new(aomenc_path()) | ||
| 2878 | + .args([ | ||
| 2879 | + "--codec=av1", | ||
| 2880 | + "--passes=1", | ||
| 2881 | + "--end-usage=q", | ||
| 2882 | + "--cpu-used=0", | ||
| 2883 | + "--threads=1", | ||
| 2884 | + "--row-mt=0", | ||
| 2885 | + "--lag-in-frames=0", | ||
| 2886 | + "--limit=1", | ||
| 2887 | + "--sb-size=64", | ||
| 2888 | + "--tune-content=screen", | ||
| 2889 | + "--enable-palette=1", | ||
| 2890 | + "--enable-intrabc=0", | ||
| 2891 | + "--min-partition-size=8", | ||
| 2892 | + "--enable-cdef=0", | ||
| 2893 | + "--enable-restoration=0", | ||
| 2894 | + "--loopfilter-control=0", | ||
| 2895 | + ]) | ||
| 2896 | + // aomenc keeps the LAST occurrence of a repeated flag, | ||
| 2897 | + // so per-arm overrides go after the base recipe. | ||
| 2898 | + .args([&depth_arg, &input_depth_arg, &cq_arg, &txs_arg, &tiles_arg]) | ||
| 2899 | + .args(["--obu", "-o", "-", "-"]) | ||
| 2900 | + .stdin(Stdio::piped()) | ||
| 2901 | + .stdout(Stdio::piped()) | ||
| 2902 | + .stderr(Stdio::piped()) | ||
| 2903 | + .spawn() | ||
| 2904 | + .expect("aomenc failed to start"); | ||
| 2905 | + child | ||
| 2906 | + .stdin | ||
| 2907 | + .take() | ||
| 2908 | + .expect("aomenc stdin") | ||
| 2909 | + .write_all(&y4m) | ||
| 2910 | + .or_else(|e| match e.kind() { | ||
| 2911 | + std::io::ErrorKind::BrokenPipe => Ok(()), | ||
| 2912 | + _ => Err(e), | ||
| 2913 | + }) | ||
| 2914 | + .expect("writing y4m to aomenc"); | ||
| 2915 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 2916 | + assert!( | ||
| 2917 | + out.status.success(), | ||
| 2918 | + "{NAME}: aomenc refused {arm}: {}", | ||
| 2919 | + String::from_utf8_lossy(&out.stderr) | ||
| 2920 | + ); | ||
| 2921 | + let stream = out.stdout; | ||
| 2922 | + decode::reset_palette_leaf8_hits(); | ||
| 2923 | + decode::reset_palette_sb_strip_hits(); | ||
| 2924 | + let decoded = decode_stream(&stream); | ||
| 2925 | + let leaf8 = decode::palette_leaf8_hits(); | ||
| 2926 | + let sb_strip = decode::palette_sb_strip_hits(); | ||
| 2927 | + leaf8_total += leaf8; | ||
| 2928 | + sb_strip_total += sb_strip; | ||
| 2929 | + match decoded { | ||
| 2930 | + Ok(frames) => { | ||
| 2931 | + assert!(!frames.is_empty(), "{NAME}: {arm} decoded no frame"); | ||
| 2932 | + let theirs = if depth == 10 { | ||
| 2933 | + ffmpeg_decode_sequence_10bit( | ||
| 2934 | + &stream, | ||
| 2935 | + width, | ||
| 2936 | + height, | ||
| 2937 | + frames.len(), | ||
| 2938 | + ) | ||
| 2939 | + } else { | ||
| 2940 | + ffmpeg_decode_sequence(&stream, width, height, frames.len()) | ||
| 2941 | + }; | ||
| 2942 | + assert_eq!( | ||
| 2943 | + frames.len(), | ||
| 2944 | + theirs.len(), | ||
| 2945 | + "{NAME}: {arm} frame count" | ||
| 2946 | + ); | ||
| 2947 | + let mut same = true; | ||
| 2948 | + for (i, (ours, ref_f)) in | ||
| 2949 | + frames.iter().zip(theirs.iter()).enumerate() | ||
| 2950 | + { | ||
| 2951 | + let ok = ours.y == ref_f.y | ||
| 2952 | + && ours.u == ref_f.u | ||
| 2953 | + && ours.v == ref_f.v; | ||
| 2954 | + if !ok { | ||
| 2955 | + eprintln!("{NAME}: {arm} MISMATCH at frame {i}"); | ||
| 2956 | + } | ||
| 2957 | + same &= ok; | ||
| 2958 | + frames_compared += 1; | ||
| 2959 | + } | ||
| 2960 | + compared += 1; | ||
| 2961 | + if sb_strip > 0 { | ||
| 2962 | + sb_strip_arms += 1; | ||
| 2963 | + assert!( | ||
| 2964 | + same, | ||
| 2965 | + "{NAME}: {arm} decoded {sb_strip} non-skip palette \ | ||
| 2966 | + block(s) on a superblock-level strip and did not \ | ||
| 2967 | + match ffmpeg" | ||
| 2968 | + ); | ||
| 2969 | + } | ||
| 2970 | + if leaf8 > 0 || sb_strip > 0 { | ||
| 2971 | + fired_arms += 1; | ||
| 2972 | + assert!( | ||
| 2973 | + same, | ||
| 2974 | + "{NAME}: {arm} decoded {leaf8} 8x8-leaf palette \ | ||
| 2975 | + block(s) and did not match ffmpeg" | ||
| 2976 | + ); | ||
| 2977 | + } else { | ||
| 2978 | + out_of_scope += 1; | ||
| 2979 | + if !same { | ||
| 2980 | + out_of_scope_mismatch += 1; | ||
| 2981 | + } | ||
| 2982 | + } | ||
| 2983 | + eprintln!( | ||
| 2984 | + "{NAME}: {arm} {} frame(s), {leaf8} 8x8-leaf palette \ | ||
| 2985 | + block(s), {sb_strip} superblock-strip palette \ | ||
| 2986 | + block(s), exact={same}", | ||
| 2987 | + frames.len() | ||
| 2988 | + ); | ||
| 2989 | + } | ||
| 2990 | + Err(e) => { | ||
| 2991 | + let msg = e.to_string(); | ||
| 2992 | + assert!( | ||
| 2993 | + msg.contains("unsupported"), | ||
| 2994 | + "{NAME}: {arm} decode failed: {e}" | ||
| 2995 | + ); | ||
| 2996 | + // Named, counted, never turned into a skip. | ||
| 2997 | + if msg.contains("superblock-level HORZ/VERT strip") { | ||
| 2998 | + sb_strip_refusals += 1; | ||
| 2999 | + } | ||
| 3000 | + eprintln!("{NAME}: {arm} REFUSED: {e}"); | ||
| 3001 | + refusals += 1; | ||
| 3002 | + } | ||
| 3003 | + } | ||
| 3004 | + } | ||
| 3005 | + } | ||
| 3006 | + } | ||
| 3007 | + } | ||
| 3008 | + } | ||
| 3009 | + eprintln!( | ||
| 3010 | + "{NAME}: {leaf8_total} 8x8-leaf palette block(s) across {fired_arms} arm(s), \ | ||
| 3011 | + {compared} arms compared ({frames_compared} frames), {sb_strip_total} \ | ||
| 3012 | + superblock-strip palette block(s) across {sb_strip_arms} arm(s), \ | ||
| 3013 | + {out_of_scope} out of scope ({out_of_scope_mismatch} mismatched), \ | ||
| 3014 | + {refusals} refused ({sb_strip_refusals} superblock-strip palette)" | ||
| 3015 | + ); | ||
| 3016 | + assert!( | ||
| 3017 | + leaf8_total > 0 && fired_arms > 0, | ||
| 3018 | + "{NAME}: gate is vacuous -- no compared arm decoded an 8x8-leaf palette block" | ||
| 3019 | + ); | ||
| 3020 | + assert!( | ||
| 3021 | + sb_strip_refusals > 0, | ||
| 3022 | + "{NAME}: no arm reached the superblock-strip palette refusal -- the open residue \ | ||
| 3023 | + this gate documents is no longer exercised" | ||
| 3024 | + ); | ||
| 3025 | + assert_eq!( | ||
| 3026 | + out_of_scope_mismatch, 0, | ||
| 3027 | + "{NAME}: an out-of-scope arm mismatched ffmpeg -- a defect, never a skip" | ||
| 3028 | + ); | ||
| 3029 | + assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact"); | ||
| 3030 | + } | ||
| 3031 | + | ||
| 2803 | /// lane-kf900 r5, the gate for the rect-strip `use_intrabc` read. | 3032 | /// lane-kf900 r5, the gate for the rect-strip `use_intrabc` read. |
| 2804 | /// | 3033 | /// |
| 2805 | /// `av1_allow_intrabc` is a FRAME-level test (`decodemv.c:892`, | 3034 | /// `av1_allow_intrabc` is a FRAME-level test (`decodemv.c:892`, |
lanes/pal8-r1.report.mdadded+69 -0
| @@ -0,0 +1,69 @@ | |||
| 1 | +# lane-pal8 r1 -- palette on a square 8x8 leaf | ||
| 2 | + | ||
| 3 | +Built on `lane-kf900` 5a28354 (merged first, commit `merge lane-kf900`). | ||
| 4 | + | ||
| 5 | +## What changed | ||
| 6 | + | ||
| 7 | +- `crates/ec-av1/src/decode.rs` `decode_leaf8` (~10680): the square 8x8 leaf now | ||
| 8 | + passes its OWN palette-Y mode ctx + colour cache | ||
| 9 | + (`neighbours.palette_ctx_and_cache_mi(leaf_mi)` / `palette_uv_cache_mi`) into | ||
| 10 | + `read_intra_mode` instead of `None`/`&[]`, and keeps the returned | ||
| 11 | + `PaletteY`/`PaletteUv` instead of dropping them. Mirrors | ||
| 12 | + `read_palette_mode_info` (decodemv.c:567; `av1_get_palette_mode_ctx`, | ||
| 13 | + `av1_get_palette_cache`, `read_palette_colors_y/uv` at decodemv.c:478) and | ||
| 14 | + `av1_decode_palette_tokens` / `av1_visit_palette` (decodeframe.c:1135), whose | ||
| 15 | + colour-index map is read after the whole mode-info read -- both already | ||
| 16 | + implemented in `read_intra_mode`; only this call site was excluded. | ||
| 17 | + `palette_bsize_ctx(8)` is `num_pels_log2 - 6 = 0`, chroma map is the 4x4 | ||
| 18 | + (`ss_size_lookup`) one `read_intra_mode` already decodes at `side / 2`. | ||
| 19 | +- Same fn: reconstruction wired through the existing `PALETTE_PRED` slot -- | ||
| 20 | + whole-block 8x8 buffer for the single-TX8 and skip arms, a per-4x4-TU window | ||
| 21 | + slice under a `tx_depth`-split leaf (the same slicing `decode_block` does at | ||
| 22 | + 16x16 and up); a palette skip leaf takes the single 8x8 reconstruct, never the | ||
| 23 | + per-TU one (`decode_block`'s own `split_tx_skip` rule). | ||
| 24 | +- Same fn: the two `record_palette_y_rect(leaf_mi, 8, 8, 0, [0; 8])` tail sites | ||
| 25 | + now stamp the leaf's REAL palette size/colours into the per-mi neighbour bands | ||
| 26 | + (kf900's bands), so the next block's ctx and colour cache see it. | ||
| 27 | +- New counters `PALETTE_LEAF8_HITS` (+ getter/reset) for the gate. | ||
| 28 | +- `crates/ec-av1/src/stream.rs`: new gate | ||
| 29 | + `a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact`. | ||
| 30 | + | ||
| 31 | +## Refusals | ||
| 32 | + | ||
| 33 | +- LIFTED (for the square 8x8 leaf): `"a block that actually uses a palette (Y) | ||
| 34 | + -- reconstruction is out of scope"` and its UV twin no longer reachable from | ||
| 35 | + `decode_leaf8`. The two strings STAY in `refusal_inventory.rs`: they are still | ||
| 36 | + live on the inter-frame intra paths (decode.rs:19783/19788, 22479/22484), | ||
| 37 | + another lane's scope. No inventory line was removable this round. | ||
| 38 | +- NOT lifted, MEASURED: `"a palette block with a real transform on a | ||
| 39 | + superblock-level HORZ/VERT strip"`. I removed it and re-ran the gate: the arm | ||
| 40 | + `testsrc2-10bit-cq55-txs0-tc1` decodes a whole-frame MISMATCH vs ffmpeg, so | ||
| 41 | + the refusal is real, not stale. Restored, with the measurement recorded in the | ||
| 42 | + code comment, and the gate now HARD-asserts that some arm still reaches it | ||
| 43 | + (`sb_strip_refusals > 0`) so the residue cannot silently disappear. | ||
| 44 | + Disposition: deferred(root-cause of the 64-level-strip palette mismatch -- | ||
| 45 | + bisect the msac range of that stream's first SB-strip palette block, and check | ||
| 46 | + the class `refusal-hides-a-defect`: the mismatch may be an unrelated defect | ||
| 47 | + that the refusal was masking). | ||
| 48 | + | ||
| 49 | +## Gate | ||
| 50 | + | ||
| 51 | +`cargo test -p ec-av1 --lib a_real_aomenc_palette_stream_with_8x8_leaves -- --nocapture` | ||
| 52 | +(`EC_AV1_REQUIRE_AOMENC=1`, oracle `~/.cache/aom-oracle/build/aomenc`). | ||
| 53 | +48 arms: {testsrc2, smptebars} x {8, 10} bit x cq {30,40,55} x | ||
| 54 | +`--enable-tx-size-search` {0,1} x `--tile-columns` {0,1}, 128x128, | ||
| 55 | +`--tune-content=screen --enable-palette=1 --min-partition-size=8 --limit=1` | ||
| 56 | +(key frame; the inter frames of this recipe stop on OTHER lanes' open refusals: | ||
| 57 | +non-DC chroma on an 8x8 inter leaf, inter 16x16 1:4 partitions). Every decoded | ||
| 58 | +frame compared against ffmpeg, `out_of_scope_mismatch == 0` asserted. | ||
| 59 | + | ||
| 60 | +EVIDENCE: ~/.cache/pal8-tmp/gate.log (pre-lift run) + the run below | aomenc 48 arms, ec-av1 decode, ffmpeg compare per frame | 44 8x8-leaf palette block(s) across 24 arm(s), 47 arms compared (47 frames), 23 out of scope (0 mismatched), 1 refused (1 superblock-strip palette) -- test result: ok | ||
| 61 | +EVIDENCE: gate rerun with the SB-strip refusal REMOVED | same 48 arms | `testsrc2-10bit-cq55-txs0-tc1 MISMATCH at frame 0`, test FAILED -- which is why that refusal stayed | ||
| 62 | + | ||
| 63 | +Before this change the same 8-bit recipe refused with "a block that actually | ||
| 64 | +uses a palette (Y)": measured with `~/.cache/pal8-tmp/enc.sh` + `decode_probe` | ||
| 65 | +on 12 streams before the fix. | ||
| 66 | + | ||
| 67 | +## Suite | ||
| 68 | + | ||
| 69 | +`$HOME/.cache/pal8-suite-r1.log` -- see the tail of this file / the lane report line. | ||