diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 1c84ab7a..62503f7a 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -5796,6 +5796,15 @@ fn decode_inter_block( // for every existing (square) caller. write_w: usize, write_h: usize, + // lane-screen r2: this frame header's own `allow_screen_content_tools` + // bit, threaded to the intra-sub-block branch below -- libaom's + // `read_intra_block_mode_info` (decodemv.c:1065-1107, the inter-frame + // counterpart of `read_intra_frame_mode_info`) reads `y_mode_cdf` + // (never `kf_y_mode_cdf`) and has NO `use_intrabc` call at all (that + // symbol is intra-frame-only, spec `av1_read_mode_info` dispatches on + // `frame_is_intra_only`), but it still calls `read_palette_mode_info` + // under the same `av1_allow_palette` gate as the key-frame path. + allow_screen_content_tools: bool, ) -> Result<()> { let (r, c) = at; let (px, py) = (c * SUB, r * SUB); @@ -7240,6 +7249,26 @@ fn decode_inter_block( } else { return Err(unsupported("a directional chroma mode (round 2)")); }; + // `read_palette_mode_info` (decodemv.c:567, called from + // `read_intra_block_mode_info` right after `xd->cfl.store_y`, same + // gating and same corner-cut as `read_intra_mode`'s own copy above + // -- `palette_mode_ctx`/`palette_uv_mode_ctx` hardcoded 0, provably + // safe since a nonzero neighbour `palette_size` would already have + // refused the decode that produced it. + if allow_screen_content_tools + && let Some(bsize_ctx) = palette_bsize_ctx(side) + { + if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][0]) != 0 { + return Err(unsupported( + "a block that actually uses a palette (Y) -- reconstruction is out of scope", + )); + } + if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 { + return Err(unsupported( + "a block that actually uses a palette (UV) -- reconstruction is out of scope", + )); + } + } mode_for_tx = mode; block_filter = [3, 3]; ref_frame_for_lf = 0; @@ -7503,6 +7532,10 @@ fn decode_inter_block8( // `compound_ctx` local, just handed back instead of applied here (this // fn's `neighbours` recording happens once for the whole straddling // 16x16 block, after every leaf). + // lane-screen r2: see [`decode_inter_block`]'s own copy of this param -- + // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`- + // eligible (`bsize >= BLOCK_8X8`). + allow_screen_content_tools: bool, ) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>)> { const LAST_FRAME: i8 = 1; /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`). @@ -8295,6 +8328,23 @@ fn decode_inter_block8( "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", )); } + // lane-screen r2: see [`decode_inter_block`]'s own copy -- `mode`/ + // `uv_mode` are both effectively `DC_PRED`-gated already on this + // leaf (a nonzero `mode` still passes, but `uv_mode` is forced + // `DC_PRED` by the refusal just above), same order as libaom's + // `read_palette_mode_info` call right after `xd->cfl.store_y`. + if allow_screen_content_tools { + if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[0][0]) != 0 { + return Err(unsupported( + "a block that actually uses a palette (Y) -- reconstruction is out of scope", + )); + } + if dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 { + return Err(unsupported( + "a block that actually uses a palette (UV) -- reconstruction is out of scope", + )); + } + } mode_for_tx = mode; let (mi_row, mi_col) = leaf_mi; for dr in 0..2 { @@ -8489,6 +8539,7 @@ pub fn decode_inter_frame_tile( true, false, false, + false, ) .map(|(picture, _, _)| picture) } @@ -8552,6 +8603,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // `decode_inter_block8` call below (spec 5.11.24's `read_motion_mode`). switchable_motion_mode: bool, allow_warped_motion: bool, + // lane-screen r2: this frame header's own `allow_screen_content_tools` + // bit, threaded to every `decode_inter_block`/`decode_inter_block8` + // call below -- consumes (never reconstructs) the intra-sub-block + // palette syntax libaom's `read_intra_block_mode_info` reads under the + // same `av1_allow_palette` gate as the key-frame path. + allow_screen_content_tools: bool, ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> { let tpl_frame = tpl_field.map(|field| TplFrameArgs { field, @@ -8798,6 +8855,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( false, BLOCK, BLOCK, + allow_screen_content_tools, )?; } PARTITION_SPLIT => { @@ -8876,6 +8934,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( false, SUB, SUB, + allow_screen_content_tools, )?; } else { let ctx16 = neighbours.partition_ctx(at16, SUB); @@ -8943,6 +9002,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( interp_fixed, switchable_motion_mode, allow_warped_motion, + allow_screen_content_tools, )?; prev_leaf = Some((leaf_mi, skip, is_inter)); last_skip_mode = skip_mode_leaf; @@ -9052,6 +9112,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // corner-cut rect-flake-1 exposed on HORZ). BLOCK, SUB, + allow_screen_content_tools, )?; if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows { decode_inter_block( @@ -9104,6 +9165,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( false, SUB, SUB, + allow_screen_content_tools, )?; if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols { decode_inter_block( @@ -9156,6 +9218,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( false, SUB, SUB, + allow_screen_content_tools, )?; } } @@ -9214,6 +9277,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( true, BLOCK, SUB, + allow_screen_content_tools, )?; decode_inter_block( &mut dec, @@ -9261,6 +9325,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( true, BLOCK, SUB, + allow_screen_content_tools, )?; } PARTITION_VERT => { @@ -9313,6 +9378,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( true, SUB, BLOCK, + allow_screen_content_tools, )?; decode_inter_block( &mut dec, @@ -9360,6 +9426,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( true, SUB, BLOCK, + allow_screen_content_tools, )?; } PARTITION_HORZ_A => { @@ -9417,6 +9484,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( false, SUB, SUB, + allow_screen_content_tools, )?; decode_inter_block( &mut dec, @@ -9468,6 +9536,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( false, SUB, SUB, + allow_screen_content_tools, )?; decode_inter_block( &mut dec, @@ -9515,6 +9584,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( true, BLOCK, SUB, + allow_screen_content_tools, )?; } PARTITION_VERT_A => { @@ -9571,6 +9641,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( false, SUB, SUB, + allow_screen_content_tools, )?; decode_inter_block( &mut dec, @@ -9622,6 +9693,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( false, SUB, SUB, + allow_screen_content_tools, )?; decode_inter_block( &mut dec, @@ -9669,6 +9741,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( true, SUB, BLOCK, + allow_screen_content_tools, )?; } PARTITION_VERT_B => { @@ -9722,6 +9795,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( true, SUB, BLOCK, + allow_screen_content_tools, )?; decode_inter_block( &mut dec, @@ -9773,6 +9847,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( false, SUB, SUB, + allow_screen_content_tools, )?; decode_inter_block( &mut dec, @@ -9824,6 +9899,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( false, SUB, SUB, + allow_screen_content_tools, )?; } _ => { @@ -10601,6 +10677,7 @@ mod tests { false, side, side, + false, ) .unwrap(); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 57a2d289..d361a5f7 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -166,17 +166,13 @@ pub fn decode_stream(data: &[u8]) -> Result> { // (spec 5.11.10/5.11.11, one symbol group per superblock). Refuse // before desyncing rather than silently miscode, the same pattern as // the CDEF/TxMode::Select refusals above. - // Key frames now consume (not reconstruct) palette/intrabc syntax - // via read_intra_mode, so the arithmetic decoder stays in sync; - // decode_inter_block/decode_inter_block8's intra-sub-block branches - // still have no such wiring, so a non-key frame with the bit set - // still desyncs and must refuse. - if header.frame_type != FrameType::Key && header.allow_screen_content_tools { - return Err(Error::unsupported( - "AV1 decode_stream", - "a non-key frame with allow_screen_content_tools set (this decoder's inter path never reads intrabc/palette_mode_info)", - )); - } + // lane-screen r2: key frames consume (not reconstruct) palette/ + // intrabc syntax via read_intra_mode, and decode_inter_block/ + // decode_inter_block8's own intra-sub-block branches now consume + // palette the same way (libaom's read_intra_block_mode_info has no + // intrabc call at all -- that symbol is intra-frame-only). A + // genuine palette/intrabc use still refuses by name deeper in the + // block readers, so no whole-frame refusal is needed here anymore. if header.delta.q_present || header.delta.lf_present { return Err(Error::unsupported( "AV1 decode_stream", @@ -464,6 +460,7 @@ pub fn decode_stream(data: &[u8]) -> Result> { header.reduced_tx_set, header.is_motion_mode_switchable, header.allow_warped_motion, + header.allow_screen_content_tools, )? }; // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's diff --git a/lanes/screen-r2.report.md b/lanes/screen-r2.report.md new file mode 100644 index 00000000..c2da8a42 --- /dev/null +++ b/lanes/screen-r2.report.md @@ -0,0 +1,96 @@ +VERDICT: GREEN — decode_inter_block/decode_inter_block8's intra-sub-block branches now consume PALETTE_Y_MODE/PALETTE_UV_MODE the same way read_intra_mode does for key frames; stream.rs:169's `frame_type != Key && allow_screen_content_tools` whole-frame refusal is removed entirely; 231/0 lib suite unchanged. + +## What landed (commit daa6934, on top of merged lane-screen r1 at 42af470) + +libaom's inter-frame intra-sub-block reader is `read_intra_block_mode_info` +(decodemv.c:1065-1107) — confirmed by reading it directly, NOT the +key-frame `read_intra_frame_mode_info` the charter warned might not +transfer. Two findings that changed scope from what the charter assumed: + +- Its `mbmi->mode` read already uses `ec_ctx->y_mode_cdf[size_group_lookup[bsize]]`, + never `kf_y_mode_cdf` — and this decoder's `decode_inter_block`/ + `decode_inter_block8` intra branches already read `cdfs.y_mode[size_group]`/ + `cdfs.y_mode[SIZE_GROUP_8]` respectively (pre-existing code, unrelated to + this lane). No CDF-selection bug to fix here. +- `read_intra_block_mode_info` has **no `use_intrabc` call at all**. + `av1_read_mode_info` dispatches `use_intrabc = 0` then branches on + `frame_is_intra_only(cm)`: only that branch calls `read_intra_frame_mode_info` + (which reads `use_intrabc`); the inter-frame branch calls + `read_inter_frame_mode_info` → `read_intra_block_mode_info` for an intra + sub-block, with no intrabc symbol at all — it's an intra-frame-only bit by + spec construction, not something this decoder was ever missing here. So + this round's whole job collapsed to palette only. + +What was added, mirroring `read_intra_mode`'s existing r1 wiring exactly +(same `av1_allow_palette` gate reused via the existing `palette_bsize_ctx` +helper, same `palette_mode_ctx`/`palette_uv_mode_ctx` hardcoded-0 +corner-cut — still safe, unchanged reasoning): + +- `decode_inter_block`'s square-intra branch: after `uv_mode`/`alpha` are + read (same point `read_palette_mode_info` sits at in libaom, right after + `xd->cfl.store_y`), reads `palette_y_mode[bsize_ctx][0]` when + `mode == DC_PRED` and `palette_uv_mode[0]` when `uv_mode == DC_PRED`, + refusing by name on either firing nonzero. +- `decode_inter_block8`'s 8x8-leaf intra branch: same two reads, `bsize_ctx` + fixed at 0 (`BLOCK_8X8` is always `av1_allow_palette`-eligible; the leaf's + own existing refusal already forces `uv_mode == DC_PRED`, so the UV read + is unconditional there, matching libaom's own always-true gate for this + shape). +- Both functions gained a trailing `allow_screen_content_tools: bool` param; + `decode_inter_frame_tile_with_cdfs` gained the same param, threaded to all + 19 `decode_inter_block` and 1 `decode_inter_block8` call sites (the public + `decode_inter_frame_tile` wrapper and one test call site pass `false`, + matching the existing key-frame wrapper convention). +- `stream.rs`'s production call passes `header.allow_screen_content_tools`. +- `stream.rs:169`'s remaining `frame_type != Key && allow_screen_content_tools` + refusal is deleted (comment left explaining why no whole-frame refusal is + needed anymore — genuine palette use still refuses deeper in the block + readers, same as key frames). The `delta.q_present || delta.lf_present` + refusal on the lines below is untouched, per charter. + +No new CDF tables — `palette_y_mode`/`palette_uv_mode`/`palette_y_size`/ +`palette_uv_size` already exist and were already 4-site-wired in r1 +(`reset2`/`reset3` length-generic, save/restore whole-struct, defaults +checked then). This round only reused them from a second call site. + +Rect intra strips inside a screen-content frame still refuse by name +("a HORZ/VERT intra strip in a screen-content frame (palette syntax is +consumed for square blocks only)") — untouched, per charter. + +## Verification + +`cargo check -p ec-av1 --lib --tests`: clean (pre-existing warnings only). + +`cargo test -p ec-av1 --release --lib`: **231 passed, 0 failed, 17 ignored** +— identical to the pre-change baseline; the bit is clear on every existing +stream, so the new palette reads are unreached (inert) for all of them. + +`allow_screen_content_tools` refusal count, before (commit 42af470) vs after +(daa6934), same seed range, same test: + +- `a_real_aomenc_stream_with_ab_partitions_decodes_pixel_exact`: **before 6/40** + refusing specifically on `"a non-key frame with allow_screen_content_tools set"` + (34 named refusals total, 6 pixel-exact matches, partab_hits=3) → **after + 0/40** on that string (31 named refusals — same partition/rect-transform/ + rect-screen-content-strip reasons as before minus the 6 whole-frame ones, + 9 pixel-exact matches, partab_hits=5). +- `a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact`: 0/40 on + that string both before and after in this fixed-seed run — every refusal + here is `"more than one concurrently active ROTZOOM/AFFINE global-motion + ref slot"` (unrelated, pre-existing gap), 20/40 pixel-exact both times + (wii_hits 8-9, consistent with the documented aomenc-RD-nondeterminism + attempt-selection class). The charter's "9 of 40" estimate for this gate + did not reproduce in this measurement — noted rather than silently + dropped; the AB-partitions gate is the one that actually carried this + refusal in both rounds. + +## What still refuses + +- Genuine palette use (nonzero `palette_size`) or genuine intrabc use, on + any frame type — reconstruction is out of scope, by design (spec-correct + named refusal, not a desync). +- A HORZ/VERT (rect) intra strip in a screen-content frame — the square-only + `palette_bsize_ctx` doesn't cover rect strips; unchanged from r1. +- `SMOOTH_PRED`/`PAETH_PRED` chroma, directional chroma on the general + intra-in-inter path, non-angle-zero deltas, `mode >= 13` — all pre-existing, + unrelated round-2 gaps this lane didn't touch.