forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-screen2': palette syntax on inter-frame intra sub-blocks

Browse files at this commit

a447d857ee707de38f387118f66b42a7ed6b01faAhmet Kaan GümüşParent: 384a87488cde18
Inter frames with allow_screen_content_tools decode now, and the whole-frame
refusal is gone entirely rather than narrowed. The AB-partition gate refused 6
of 40 attempts on that string; it refuses none.

The round corrected a scope assumption worth recording: libaom's
read_intra_block_mode_info -- the inter-frame intra reader -- has no
use_intrabc call at all. intrabc is intra-frame-only by spec dispatch, since
av1_read_mode_info branches on frame_is_intra_only, so this path needed palette
wiring only.

Genuine palette or intrabc use still refuses by name at any frame type, as do
rect intra strips in screen-content frames.

Full lib suite 231 passed / 0 failed.
crates/ec-av1/src/decode.rsmodified+77 -0
@@ -5796,6 +5796,15 @@ fn decode_inter_block(
57965796 // for every existing (square) caller.
57975797 write_w: usize,
57985798 write_h: usize,
5799+ // lane-screen r2: this frame header's own `allow_screen_content_tools`
5800+ // bit, threaded to the intra-sub-block branch below -- libaom's
5801+ // `read_intra_block_mode_info` (decodemv.c:1065-1107, the inter-frame
5802+ // counterpart of `read_intra_frame_mode_info`) reads `y_mode_cdf`
5803+ // (never `kf_y_mode_cdf`) and has NO `use_intrabc` call at all (that
5804+ // symbol is intra-frame-only, spec `av1_read_mode_info` dispatches on
5805+ // `frame_is_intra_only`), but it still calls `read_palette_mode_info`
5806+ // under the same `av1_allow_palette` gate as the key-frame path.
5807+ allow_screen_content_tools: bool,
57995808 ) -> Result<()> {
58005809 let (r, c) = at;
58015810 let (px, py) = (c * SUB, r * SUB);
@@ -7240,6 +7249,26 @@ fn decode_inter_block(
72407249 } else {
72417250 return Err(unsupported("a directional chroma mode (round 2)"));
72427251 };
7252+ // `read_palette_mode_info` (decodemv.c:567, called from
7253+ // `read_intra_block_mode_info` right after `xd->cfl.store_y`, same
7254+ // gating and same corner-cut as `read_intra_mode`'s own copy above
7255+ // -- `palette_mode_ctx`/`palette_uv_mode_ctx` hardcoded 0, provably
7256+ // safe since a nonzero neighbour `palette_size` would already have
7257+ // refused the decode that produced it.
7258+ if allow_screen_content_tools
7259+ && let Some(bsize_ctx) = palette_bsize_ctx(side)
7260+ {
7261+ if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][0]) != 0 {
7262+ return Err(unsupported(
7263+ "a block that actually uses a palette (Y) -- reconstruction is out of scope",
7264+ ));
7265+ }
7266+ if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 {
7267+ return Err(unsupported(
7268+ "a block that actually uses a palette (UV) -- reconstruction is out of scope",
7269+ ));
7270+ }
7271+ }
72437272 mode_for_tx = mode;
72447273 block_filter = [3, 3];
72457274 ref_frame_for_lf = 0;
@@ -7503,6 +7532,10 @@ fn decode_inter_block8(
75037532 // `compound_ctx` local, just handed back instead of applied here (this
75047533 // fn's `neighbours` recording happens once for the whole straddling
75057534 // 16x16 block, after every leaf).
7535+ // lane-screen r2: see [`decode_inter_block`]'s own copy of this param --
7536+ // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`-
7537+ // eligible (`bsize >= BLOCK_8X8`).
7538+ allow_screen_content_tools: bool,
75067539 ) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>)> {
75077540 const LAST_FRAME: i8 = 1;
75087541 /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`).
@@ -8295,6 +8328,23 @@ fn decode_inter_block8(
82958328 "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)",
82968329 ));
82978330 }
8331+ // lane-screen r2: see [`decode_inter_block`]'s own copy -- `mode`/
8332+ // `uv_mode` are both effectively `DC_PRED`-gated already on this
8333+ // leaf (a nonzero `mode` still passes, but `uv_mode` is forced
8334+ // `DC_PRED` by the refusal just above), same order as libaom's
8335+ // `read_palette_mode_info` call right after `xd->cfl.store_y`.
8336+ if allow_screen_content_tools {
8337+ if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[0][0]) != 0 {
8338+ return Err(unsupported(
8339+ "a block that actually uses a palette (Y) -- reconstruction is out of scope",
8340+ ));
8341+ }
8342+ if dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 {
8343+ return Err(unsupported(
8344+ "a block that actually uses a palette (UV) -- reconstruction is out of scope",
8345+ ));
8346+ }
8347+ }
82988348 mode_for_tx = mode;
82998349 let (mi_row, mi_col) = leaf_mi;
83008350 for dr in 0..2 {
@@ -8489,6 +8539,7 @@ pub fn decode_inter_frame_tile(
84898539 true,
84908540 false,
84918541 false,
8542+ false,
84928543 )
84938544 .map(|(picture, _, _)| picture)
84948545 }
@@ -8552,6 +8603,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
85528603 // `decode_inter_block8` call below (spec 5.11.24's `read_motion_mode`).
85538604 switchable_motion_mode: bool,
85548605 allow_warped_motion: bool,
8606+ // lane-screen r2: this frame header's own `allow_screen_content_tools`
8607+ // bit, threaded to every `decode_inter_block`/`decode_inter_block8`
8608+ // call below -- consumes (never reconstructs) the intra-sub-block
8609+ // palette syntax libaom's `read_intra_block_mode_info` reads under the
8610+ // same `av1_allow_palette` gate as the key-frame path.
8611+ allow_screen_content_tools: bool,
85558612 ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> {
85568613 let tpl_frame = tpl_field.map(|field| TplFrameArgs {
85578614 field,
@@ -8798,6 +8855,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
87988855 false,
87998856 BLOCK,
88008857 BLOCK,
8858+ allow_screen_content_tools,
88018859 )?;
88028860 }
88038861 PARTITION_SPLIT => {
@@ -8876,6 +8934,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
88768934 false,
88778935 SUB,
88788936 SUB,
8937+ allow_screen_content_tools,
88798938 )?;
88808939 } else {
88818940 let ctx16 = neighbours.partition_ctx(at16, SUB);
@@ -8943,6 +9002,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
89439002 interp_fixed,
89449003 switchable_motion_mode,
89459004 allow_warped_motion,
9005+ allow_screen_content_tools,
89469006 )?;
89479007 prev_leaf = Some((leaf_mi, skip, is_inter));
89489008 last_skip_mode = skip_mode_leaf;
@@ -9052,6 +9112,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
90529112 // corner-cut rect-flake-1 exposed on HORZ).
90539113 BLOCK,
90549114 SUB,
9115+ allow_screen_content_tools,
90559116 )?;
90569117 if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows {
90579118 decode_inter_block(
@@ -9104,6 +9165,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
91049165 false,
91059166 SUB,
91069167 SUB,
9168+ allow_screen_content_tools,
91079169 )?;
91089170 if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols {
91099171 decode_inter_block(
@@ -9156,6 +9218,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
91569218 false,
91579219 SUB,
91589220 SUB,
9221+ allow_screen_content_tools,
91599222 )?;
91609223 }
91619224 }
@@ -9214,6 +9277,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
92149277 true,
92159278 BLOCK,
92169279 SUB,
9280+ allow_screen_content_tools,
92179281 )?;
92189282 decode_inter_block(
92199283 &mut dec,
@@ -9261,6 +9325,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
92619325 true,
92629326 BLOCK,
92639327 SUB,
9328+ allow_screen_content_tools,
92649329 )?;
92659330 }
92669331 PARTITION_VERT => {
@@ -9313,6 +9378,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
93139378 true,
93149379 SUB,
93159380 BLOCK,
9381+ allow_screen_content_tools,
93169382 )?;
93179383 decode_inter_block(
93189384 &mut dec,
@@ -9360,6 +9426,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
93609426 true,
93619427 SUB,
93629428 BLOCK,
9429+ allow_screen_content_tools,
93639430 )?;
93649431 }
93659432 PARTITION_HORZ_A => {
@@ -9417,6 +9484,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
94179484 false,
94189485 SUB,
94199486 SUB,
9487+ allow_screen_content_tools,
94209488 )?;
94219489 decode_inter_block(
94229490 &mut dec,
@@ -9468,6 +9536,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
94689536 false,
94699537 SUB,
94709538 SUB,
9539+ allow_screen_content_tools,
94719540 )?;
94729541 decode_inter_block(
94739542 &mut dec,
@@ -9515,6 +9584,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
95159584 true,
95169585 BLOCK,
95179586 SUB,
9587+ allow_screen_content_tools,
95189588 )?;
95199589 }
95209590 PARTITION_VERT_A => {
@@ -9571,6 +9641,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
95719641 false,
95729642 SUB,
95739643 SUB,
9644+ allow_screen_content_tools,
95749645 )?;
95759646 decode_inter_block(
95769647 &mut dec,
@@ -9622,6 +9693,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
96229693 false,
96239694 SUB,
96249695 SUB,
9696+ allow_screen_content_tools,
96259697 )?;
96269698 decode_inter_block(
96279699 &mut dec,
@@ -9669,6 +9741,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
96699741 true,
96709742 SUB,
96719743 BLOCK,
9744+ allow_screen_content_tools,
96729745 )?;
96739746 }
96749747 PARTITION_VERT_B => {
@@ -9722,6 +9795,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
97229795 true,
97239796 SUB,
97249797 BLOCK,
9798+ allow_screen_content_tools,
97259799 )?;
97269800 decode_inter_block(
97279801 &mut dec,
@@ -9773,6 +9847,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
97739847 false,
97749848 SUB,
97759849 SUB,
9850+ allow_screen_content_tools,
97769851 )?;
97779852 decode_inter_block(
97789853 &mut dec,
@@ -9824,6 +9899,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
98249899 false,
98259900 SUB,
98269901 SUB,
9902+ allow_screen_content_tools,
98279903 )?;
98289904 }
98299905 _ => {
@@ -10601,6 +10677,7 @@ mod tests {
1060110677 false,
1060210678 side,
1060310679 side,
10680+ false,
1060410681 )
1060510682 .unwrap();
1060610683
crates/ec-av1/src/stream.rsmodified+8 -11
@@ -166,17 +166,13 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
166166 // (spec 5.11.10/5.11.11, one symbol group per superblock). Refuse
167167 // before desyncing rather than silently miscode, the same pattern as
168168 // the CDEF/TxMode::Select refusals above.
169- // Key frames now consume (not reconstruct) palette/intrabc syntax
170- // via read_intra_mode, so the arithmetic decoder stays in sync;
171- // decode_inter_block/decode_inter_block8's intra-sub-block branches
172- // still have no such wiring, so a non-key frame with the bit set
173- // still desyncs and must refuse.
174- if header.frame_type != FrameType::Key && header.allow_screen_content_tools {
175- return Err(Error::unsupported(
176- "AV1 decode_stream",
177- "a non-key frame with allow_screen_content_tools set (this decoder's inter path never reads intrabc/palette_mode_info)",
178- ));
179- }
169+ // lane-screen r2: key frames consume (not reconstruct) palette/
170+ // intrabc syntax via read_intra_mode, and decode_inter_block/
171+ // decode_inter_block8's own intra-sub-block branches now consume
172+ // palette the same way (libaom's read_intra_block_mode_info has no
173+ // intrabc call at all -- that symbol is intra-frame-only). A
174+ // genuine palette/intrabc use still refuses by name deeper in the
175+ // block readers, so no whole-frame refusal is needed here anymore.
180176 if header.delta.q_present || header.delta.lf_present {
181177 return Err(Error::unsupported(
182178 "AV1 decode_stream",
@@ -464,6 +460,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
464460 header.reduced_tx_set,
465461 header.is_motion_mode_switchable,
466462 header.allow_warped_motion,
463+ header.allow_screen_content_tools,
467464 )?
468465 };
469466 // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's
lanes/screen-r2.report.mdadded+96 -0
@@ -0,0 +1,96 @@
1+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.
2+
3+## What landed (commit daa6934, on top of merged lane-screen r1 at 42af470)
4+
5+libaom's inter-frame intra-sub-block reader is `read_intra_block_mode_info`
6+(decodemv.c:1065-1107) — confirmed by reading it directly, NOT the
7+key-frame `read_intra_frame_mode_info` the charter warned might not
8+transfer. Two findings that changed scope from what the charter assumed:
9+
10+- Its `mbmi->mode` read already uses `ec_ctx->y_mode_cdf[size_group_lookup[bsize]]`,
11+ never `kf_y_mode_cdf` — and this decoder's `decode_inter_block`/
12+ `decode_inter_block8` intra branches already read `cdfs.y_mode[size_group]`/
13+ `cdfs.y_mode[SIZE_GROUP_8]` respectively (pre-existing code, unrelated to
14+ this lane). No CDF-selection bug to fix here.
15+- `read_intra_block_mode_info` has **no `use_intrabc` call at all**.
16+ `av1_read_mode_info` dispatches `use_intrabc = 0` then branches on
17+ `frame_is_intra_only(cm)`: only that branch calls `read_intra_frame_mode_info`
18+ (which reads `use_intrabc`); the inter-frame branch calls
19+ `read_inter_frame_mode_info` → `read_intra_block_mode_info` for an intra
20+ sub-block, with no intrabc symbol at all — it's an intra-frame-only bit by
21+ spec construction, not something this decoder was ever missing here. So
22+ this round's whole job collapsed to palette only.
23+
24+What was added, mirroring `read_intra_mode`'s existing r1 wiring exactly
25+(same `av1_allow_palette` gate reused via the existing `palette_bsize_ctx`
26+helper, same `palette_mode_ctx`/`palette_uv_mode_ctx` hardcoded-0
27+corner-cut — still safe, unchanged reasoning):
28+
29+- `decode_inter_block`'s square-intra branch: after `uv_mode`/`alpha` are
30+ read (same point `read_palette_mode_info` sits at in libaom, right after
31+ `xd->cfl.store_y`), reads `palette_y_mode[bsize_ctx][0]` when
32+ `mode == DC_PRED` and `palette_uv_mode[0]` when `uv_mode == DC_PRED`,
33+ refusing by name on either firing nonzero.
34+- `decode_inter_block8`'s 8x8-leaf intra branch: same two reads, `bsize_ctx`
35+ fixed at 0 (`BLOCK_8X8` is always `av1_allow_palette`-eligible; the leaf's
36+ own existing refusal already forces `uv_mode == DC_PRED`, so the UV read
37+ is unconditional there, matching libaom's own always-true gate for this
38+ shape).
39+- Both functions gained a trailing `allow_screen_content_tools: bool` param;
40+ `decode_inter_frame_tile_with_cdfs` gained the same param, threaded to all
41+ 19 `decode_inter_block` and 1 `decode_inter_block8` call sites (the public
42+ `decode_inter_frame_tile` wrapper and one test call site pass `false`,
43+ matching the existing key-frame wrapper convention).
44+- `stream.rs`'s production call passes `header.allow_screen_content_tools`.
45+- `stream.rs:169`'s remaining `frame_type != Key && allow_screen_content_tools`
46+ refusal is deleted (comment left explaining why no whole-frame refusal is
47+ needed anymore — genuine palette use still refuses deeper in the block
48+ readers, same as key frames). The `delta.q_present || delta.lf_present`
49+ refusal on the lines below is untouched, per charter.
50+
51+No new CDF tables — `palette_y_mode`/`palette_uv_mode`/`palette_y_size`/
52+`palette_uv_size` already exist and were already 4-site-wired in r1
53+(`reset2`/`reset3` length-generic, save/restore whole-struct, defaults
54+checked then). This round only reused them from a second call site.
55+
56+Rect intra strips inside a screen-content frame still refuse by name
57+("a HORZ/VERT intra strip in a screen-content frame (palette syntax is
58+consumed for square blocks only)") — untouched, per charter.
59+
60+## Verification
61+
62+`cargo check -p ec-av1 --lib --tests`: clean (pre-existing warnings only).
63+
64+`cargo test -p ec-av1 --release --lib`: **231 passed, 0 failed, 17 ignored**
65+— identical to the pre-change baseline; the bit is clear on every existing
66+stream, so the new palette reads are unreached (inert) for all of them.
67+
68+`allow_screen_content_tools` refusal count, before (commit 42af470) vs after
69+(daa6934), same seed range, same test:
70+
71+- `a_real_aomenc_stream_with_ab_partitions_decodes_pixel_exact`: **before 6/40**
72+ refusing specifically on `"a non-key frame with allow_screen_content_tools set"`
73+ (34 named refusals total, 6 pixel-exact matches, partab_hits=3) → **after
74+ 0/40** on that string (31 named refusals — same partition/rect-transform/
75+ rect-screen-content-strip reasons as before minus the 6 whole-frame ones,
76+ 9 pixel-exact matches, partab_hits=5).
77+- `a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact`: 0/40 on
78+ that string both before and after in this fixed-seed run — every refusal
79+ here is `"more than one concurrently active ROTZOOM/AFFINE global-motion
80+ ref slot"` (unrelated, pre-existing gap), 20/40 pixel-exact both times
81+ (wii_hits 8-9, consistent with the documented aomenc-RD-nondeterminism
82+ attempt-selection class). The charter's "9 of 40" estimate for this gate
83+ did not reproduce in this measurement — noted rather than silently
84+ dropped; the AB-partitions gate is the one that actually carried this
85+ refusal in both rounds.
86+
87+## What still refuses
88+
89+- Genuine palette use (nonzero `palette_size`) or genuine intrabc use, on
90+ any frame type — reconstruction is out of scope, by design (spec-correct
91+ named refusal, not a desync).
92+- A HORZ/VERT (rect) intra strip in a screen-content frame — the square-only
93+ `palette_bsize_ctx` doesn't cover rect strips; unchanged from r1.
94+- `SMOOTH_PRED`/`PAETH_PRED` chroma, directional chroma on the general
95+ intra-in-inter path, non-angle-zero deltas, `mode >= 13` — all pre-existing,
96+ unrelated round-2 gaps this lane didn't touch.