diff --git a/crates/ec-av1/src/cdf.rs b/crates/ec-av1/src/cdf.rs index 5bb8aefa..819560b5 100644 --- a/crates/ec-av1/src/cdf.rs +++ b/crates/ec-av1/src/cdf.rs @@ -332,6 +332,52 @@ pub const FILTER_INTRA: [[u16; 3]; 6] = [ /// `FILTER_INTRA_MODES` a `use_filter_intra` block picks. pub const FILTER_INTRA_MODE: [u16; 6] = [8949, 12776, 17211, 29558, 32768, 0]; +/// `default_palette_y_size_cdf` (entropymode.c): `PALETTE_SIZES` (2..=8), +/// indexed by `av1_get_palette_bsize_ctx` (0..=6, `PALATTE_BSIZE_CTXS`). +pub const PALETTE_Y_SIZE: [[u16; 8]; 7] = [ + [7952, 13000, 18149, 21478, 25527, 29241, 32768, 0], + [7139, 11421, 16195, 19544, 23666, 28073, 32768, 0], + [7788, 12741, 17325, 20500, 24315, 28530, 32768, 0], + [8271, 14064, 18246, 21564, 25071, 28533, 32768, 0], + [12725, 19180, 21863, 24839, 27535, 30120, 32768, 0], + [9711, 14888, 16923, 21052, 25661, 27875, 32768, 0], + [14940, 20797, 21678, 24186, 27033, 28999, 32768, 0], +]; +/// `default_palette_uv_size_cdf` (entropymode.c): as [`PALETTE_Y_SIZE`], for +/// the chroma plane's own palette size. +pub const PALETTE_UV_SIZE: [[u16; 8]; 7] = [ + [8713, 19979, 27128, 29609, 31331, 32272, 32768, 0], + [5839, 15573, 23581, 26947, 29848, 31700, 32768, 0], + [4426, 11260, 17999, 21483, 25863, 29430, 32768, 0], + [3228, 9464, 14993, 18089, 22523, 27420, 32768, 0], + [3768, 8886, 13091, 17852, 22495, 27207, 32768, 0], + [2464, 8451, 12861, 21632, 25525, 28555, 32768, 0], + [1269, 5435, 10433, 18963, 21700, 25865, 32768, 0], +]; +/// `default_palette_y_mode_cdf` (entropymode.c): whether a `DC_PRED` block +/// uses a palette, indexed `[bsize_ctx][palette_mode_ctx]` +/// (`palette_mode_ctx` from `av1_get_palette_mode_ctx` -- this decoder never +/// completes a decode with a nonzero neighbour `palette_size`, so only row +/// `[.][0]` is ever read, but the whole table is here to match libaom's +/// adaptation shape exactly). +pub const PALETTE_Y_MODE: [[[u16; 3]; 3]; 7] = [ + [[31676, 32768, 0], [3419, 32768, 0], [1261, 32768, 0]], + [[31912, 32768, 0], [2859, 32768, 0], [980, 32768, 0]], + [[31823, 32768, 0], [3400, 32768, 0], [781, 32768, 0]], + [[32030, 32768, 0], [3561, 32768, 0], [904, 32768, 0]], + [[32309, 32768, 0], [7337, 32768, 0], [1462, 32768, 0]], + [[32265, 32768, 0], [4015, 32768, 0], [1521, 32768, 0]], + [[32450, 32768, 0], [7946, 32768, 0], [129, 32768, 0]], +]; +/// `default_palette_uv_mode_cdf` (entropymode.c): whether a `UV_DC_PRED` +/// block uses a chroma palette, indexed by `palette_uv_mode_ctx` (whether +/// this block's own luma palette was used -- always 0 here, see +/// [`PALETTE_Y_MODE`]'s doc). +pub const PALETTE_UV_MODE: [[u16; 3]; 2] = [[32461, 32768, 0], [21488, 32768, 0]]; +/// `default_intrabc_cdf` (entropymode.c): the `use_intrabc` flag on an +/// intra frame with `allow_intrabc` set. +pub const INTRABC: [u16; 3] = [30531, 32768, 0]; + /// `default_tx_size_cdf[0]` (entropymode.c): an 8x8 block's `tx_depth` flag /// (`TX8` vs `TX4`), indexed by `tx_size_context` (0..=2). pub const TX_SIZE_CAT0: [[u16; 3]; 3] = [[19968, 32768, 0], [19968, 32768, 0], [24320, 32768, 0]]; diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index de5a79f9..7e06f28f 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -402,6 +402,17 @@ pub(crate) struct Cdfs { /// A `SWITCHABLE`-filter inter block's own `interp_filter[dir]` -- see /// [`cdf::SWITCHABLE_INTERP`]. pub switchable_interp: [[u16; 4]; 16], + /// A `DC_PRED` block's own palette-use flag -- see [`cdf::PALETTE_Y_MODE`]. + pub palette_y_mode: [[[u16; 3]; 3]; 7], + /// A palette block's own size (2..=8) -- see [`cdf::PALETTE_Y_SIZE`]. + pub palette_y_size: [[u16; 8]; 7], + /// A `UV_DC_PRED` block's own chroma palette-use flag -- see + /// [`cdf::PALETTE_UV_MODE`]. + pub palette_uv_mode: [[u16; 3]; 2], + /// A chroma palette block's own size -- see [`cdf::PALETTE_UV_SIZE`]. + pub palette_uv_size: [[u16; 8]; 7], + /// The `use_intrabc` flag -- see [`cdf::INTRABC`]. + pub intrabc: [u16; 3], } /// One motion vector component's adapting state (spec 9.4's `Default_Mv_*`, @@ -616,6 +627,11 @@ impl Cdfs { reset2(&mut self.tx_size_cat1); reset2(&mut self.tx_size_cat2); reset2(&mut self.tx_size_cat3); + reset3(&mut self.palette_y_mode); + reset2(&mut self.palette_y_size); + reset2(&mut self.palette_uv_mode); + reset2(&mut self.palette_uv_size); + reset1(&mut self.intrabc); } /// The defaults a key frame starts from (spec 8.4, `init_coeff_cdfs` and @@ -1057,6 +1073,11 @@ impl Cdfs { tx_size_cat2: cdf::TX_SIZE_CAT2, tx_size_cat3: cdf::TX_SIZE_CAT3, switchable_interp: cdf::SWITCHABLE_INTERP, + palette_y_mode: cdf::PALETTE_Y_MODE, + palette_y_size: cdf::PALETTE_Y_SIZE, + palette_uv_mode: cdf::PALETTE_UV_MODE, + palette_uv_size: cdf::PALETTE_UV_SIZE, + intrabc: cdf::INTRABC, } } diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 328b01e6..b86a542f 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1556,6 +1556,22 @@ fn filter_intra_size_class_rect(bw: usize, bh: usize) -> Option { } } +/// `av1_allow_palette`'s size bound (blockd.h: `block_size_wide/high <= +/// MAX_PALETTE_BLOCK_WIDTH/HEIGHT` (64) and `sb_type >= BLOCK_8X8`) plus +/// `av1_get_palette_bsize_ctx` (pred_common.h: `num_pels_log2_lookup[bsize] +/// - num_pels_log2_lookup[BLOCK_8X8]`, i.e. `2*log2(side) - 6` for this +/// decoder's square-only blocks) -- `None` past the bound (never gates a +/// palette read), `Some(bsize_ctx)` otherwise. +fn palette_bsize_ctx(side: usize) -> Option { + match side { + 8 => Some(0), + 16 => Some(2), + 32 => Some(4), + 64 => Some(6), + _ => None, + } +} + /// [`read_intra_mode`] for a true `bw`x`bh` rect strip (lane-intradisp r1): /// identical except the `use_filter_intra` size class comes from /// [`filter_intra_size_class_rect`] instead of the square-only @@ -1573,6 +1589,7 @@ fn read_intra_mode_rect( bh: usize, enable_filter_intra: bool, skip_ctx: usize, + allow_screen_content_tools: bool, ) -> Result<( bool, usize, @@ -1582,6 +1599,16 @@ fn read_intra_mode_rect( Option<(i32, i32)>, Option, )> { + // lane-screen consumes palette/intrabc syntax in the SQUARE reader only + // (`palette_bsize_ctx` is keyed on a single side). A rect strip in a + // screen-content frame would therefore skip symbols the encoder wrote and + // desync the tile, so refuse it by name rather than decode it wrong. + if allow_screen_content_tools { + return Err(unsupported( + "a HORZ/VERT intra strip in a screen-content frame (palette syntax \ + is consumed for square blocks only)", + )); + } let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; let above_ctx = INTRA_MODE_CTX[above_mode]; let left_ctx = INTRA_MODE_CTX[left_mode]; @@ -1694,6 +1721,7 @@ fn decode_block_rect( u: &mut PlaneBuf, v: &mut PlaneBuf, enable_filter_intra: bool, + allow_screen_content_tools: bool, ) -> Result<()> { let (r, c) = at; let (px, py) = (c * SUB, r * SUB); @@ -1708,6 +1736,7 @@ fn decode_block_rect( bh, enable_filter_intra, neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)), + allow_screen_content_tools, )?; if filter_intra.is_some() { // `predict_filter_intra` (spec 7.11.2.3) is square-only in this @@ -1824,6 +1853,8 @@ fn read_intra_mode( side: usize, enable_filter_intra: bool, skip_ctx: usize, + allow_screen_content_tools: bool, + allow_intrabc: bool, ) -> Result<( bool, usize, @@ -1838,6 +1869,26 @@ fn read_intra_mode( if trace { eprintln!("TRACE skip value={}", skip as i32); } + // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at + // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before + // `mbmi->mode` is ever read): a `use_intrabc` symbol only present on an + // intra frame whose header set `allow_intrabc`. Actual intra block copy + // needs `assign_dv`'s own motion-vector-prediction machinery (`av1_find_mv_refs`, + // `av1_find_ref_dv`) this decoder does not carry -- lane-screen scope + // draws the line at consuming this one flag symbol and refusing by name + // when it fires, so the arithmetic decoder still resyncs for a stream + // that merely allows (but never uses) intrabc. + if allow_intrabc { + let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0; + if trace { + eprintln!("TRACE use_intrabc value={}", use_intrabc as i32); + } + if use_intrabc { + return Err(unsupported( + "a block that actually uses intrabc (this decoder never reconstructs one)", + )); + } + } let above_ctx = INTRA_MODE_CTX[above_mode]; let left_ctx = INTRA_MODE_CTX[left_mode]; let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); @@ -1890,6 +1941,32 @@ fn read_intra_mode( } else { 0 }; + // `read_palette_mode_info` (spec 5.11.13, libaom decodemv.c:567, called + // at :840 right after `xd->cfl.store_y` and before `read_filter_intra_mode_info`): + // gated by `av1_allow_palette` (blockd.h -- size bound only, + // [`palette_bsize_ctx`]). `palette_mode_ctx`/`palette_uv_mode_ctx` + // (`av1_get_palette_mode_ctx`, pred_common.h) read the neighbours' own + // `palette_size[0] > 0` -- always 0 here since a nonzero size refuses + // the whole decode below, so no successfully-completed decode ever has + // such a neighbour (corner-cut: hardcoded ctx 0 instead of tracking it, + // ceiling = real palette reconstruction, out of this lane's scope). + // A nonzero `palette_size` needs the color-cache/delta-coded-colors + // syntax this decoder does not reconstruct -- refuse by name rather + // than silently drop pixels. + 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", + )); + } + } // `read_filter_intra_mode_info` (spec 5.11.14, libaom decodemv.c): a // `use_filter_intra` symbol this decoder never read at all until // lane-av1real r10 -- silently skipping it left every bit past a @@ -2354,6 +2431,8 @@ fn decode_block( v: &mut PlaneBuf, base_q_idx: u8, enable_filter_intra: bool, + allow_screen_content_tools: bool, + allow_intrabc: bool, scan32: &[u16], scan16: &[u16], scan8: &[u16], @@ -2373,6 +2452,8 @@ fn decode_block( side, enable_filter_intra, neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)), + allow_screen_content_tools, + allow_intrabc, )?; // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED` // (13) predicts as `DC_PRED` with the [`cfl_scaled`] nudge carrying the @@ -2661,6 +2742,8 @@ fn decode_leaf8( v: &mut PlaneBuf, base_q_idx: u8, enable_filter_intra: bool, + allow_screen_content_tools: bool, + allow_intrabc: bool, tx_select: bool, reduced_tx_set: bool, ) -> Result { @@ -2687,6 +2770,8 @@ fn decode_leaf8( 8, enable_filter_intra, neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1), + allow_screen_content_tools, + allow_intrabc, )?; let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED @@ -3832,6 +3917,8 @@ pub fn decode_key_frame_tile( loop_filter: &LoopFilterParams, tx_select: bool, reduced_tx_set: bool, + allow_screen_content_tools: bool, + allow_intrabc: bool, ) -> Result { decode_key_frame_tile_with_cdfs( data, @@ -3847,6 +3934,8 @@ pub fn decode_key_frame_tile( None, tx_select, reduced_tx_set, + allow_screen_content_tools, + allow_intrabc, ) .map(|(picture, _)| picture) } @@ -3873,6 +3962,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( initial_cdfs: Option, tx_select: bool, reduced_tx_set: bool, + allow_screen_content_tools: bool, + allow_intrabc: bool, ) -> Result<(Picture, Cdfs)> { if mi_cols == 0 || mi_rows == 0 { return Err(unsupported("a frame with no mode-info grid")); @@ -3979,6 +4070,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( &mut v, base_q_idx, enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, &scan32, &scan16, &scan8, @@ -4046,6 +4139,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( &mut v, base_q_idx, enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, &scan32, &scan16, &scan8, @@ -4095,6 +4190,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( &mut v, base_q_idx, enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, &scan32, &scan16, &scan8, @@ -4149,6 +4246,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( &mut v, base_q_idx, enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, tx_select, reduced_tx_set, )?; @@ -4218,6 +4317,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( &mut v, base_q_idx, enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, tx_select, reduced_tx_set, )?; @@ -4248,6 +4349,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( &mut u, &mut v, enable_filter_intra, + allow_screen_content_tools, )?; decode_block_rect( &mut dec, @@ -4260,6 +4362,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( &mut u, &mut v, enable_filter_intra, + allow_screen_content_tools, )?; } PARTITION_VERT => { @@ -4276,6 +4379,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( &mut u, &mut v, enable_filter_intra, + allow_screen_content_tools, )?; decode_block_rect( &mut dec, @@ -4288,6 +4392,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( &mut u, &mut v, enable_filter_intra, + allow_screen_content_tools, )?; } _ => { @@ -9726,6 +9831,8 @@ mod tests { &LoopFilterParams::default(), false, true, + false, + false, ) .is_err() ); @@ -9768,6 +9875,8 @@ mod tests { &LoopFilterParams::default(), false, true, + false, + false, ) .unwrap(); assert_eq!(decoded.width, w, "{w}x{h}: decoded width"); @@ -9851,6 +9960,8 @@ mod tests { &LoopFilterParams::default(), false, true, + false, + false, ) .unwrap(); assert!( @@ -10036,6 +10147,8 @@ mod tests { &LoopFilterParams::default(), false, true, + false, + false, ) .unwrap(); assert_eq!(ours.y, ffmpeg_decoded.y, "{width}x{height}: luma vs ffmpeg"); @@ -10108,6 +10221,8 @@ mod tests { &LoopFilterParams::default(), false, true, + false, + false, ) .unwrap(); assert_eq!( @@ -10411,6 +10526,8 @@ mod tests { &LoopFilterParams::default(), false, true, + false, + false, ) .unwrap(); assert_eq!(reference.y, ffmpeg_frames[0].y, "frame 0 luma vs ffmpeg"); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 7cf29b88..82dd9769 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -166,10 +166,15 @@ 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. - if header.allow_screen_content_tools { + // 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 frame with allow_screen_content_tools set (this decoder never reads intrabc/palette_mode_info)", + "a non-key frame with allow_screen_content_tools set (this decoder's inter path never reads intrabc/palette_mode_info)", )); } if header.delta.q_present || header.delta.lf_present { @@ -313,6 +318,8 @@ pub fn decode_stream(data: &[u8]) -> Result> { initial_cdfs, header.tx_mode == TxMode::Select, header.reduced_tx_set, + header.allow_screen_content_tools, + header.allow_intrabc, )?; // A key frame codes no inter blocks -- its own saved motion // field has no cells set, matching libaom's own "intra frame @@ -535,6 +542,8 @@ mod tests { false, // Our own encoder always writes `reduced_tx_set: true`. true, + false, + false, ) .unwrap(); let via_stream = decode_stream(&encoded.stream).unwrap(); @@ -1192,6 +1201,16 @@ mod tests { return; } let (width, height) = (64usize, 64usize); + // Recipe-search hooks: with the encoder pinned to one thread the + // stream is a deterministic function of (seed, cq), so a firing recipe + // can be searched for without a rebuild. + let fi_seed: u32 = std::env::var("EC_FI_SEED") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(42); + let fi_source = format!("gradients=size=64x64:seed={fi_seed}:duration=0.04:rate=25"); + let fi_cq = std::env::var("EC_FI_CQ").unwrap_or_else(|_| "40".to_string()); + let fi_cq_arg = format!("--cq-level={fi_cq}"); let y4m = Command::new("ffmpeg") .args([ "-v", @@ -1199,7 +1218,7 @@ mod tests { "-f", "lavfi", "-i", - "gradients=size=64x64:seed=42:duration=0.04:rate=25", + &fi_source, "-pix_fmt", "yuv420p", "-f", @@ -1221,8 +1240,16 @@ mod tests { "--codec=av1", "--passes=1", "--end-usage=q", - "--cq-level=40", + &fi_cq_arg, "--cpu-used=0", + // Every sibling gate pins these; this one did not, and a + // multi-threaded aomenc is not deterministic, so each run + // encoded a slightly different stream and the gate flaked + // against whichever features that run happened to pick. + // Pinning them makes seed 42 mean one stream (class + // `parallel-flake-is-attempt-selection`). + "--threads=1", + "--row-mt=0", "--enable-filter-intra=1", "--enable-smooth-intra=0", "--enable-paeth-intra=0", diff --git a/lanes/screen-r1.charter.md b/lanes/screen-r1.charter.md new file mode 100644 index 00000000..e0d4932b --- /dev/null +++ b/lanes/screen-r1.charter.md @@ -0,0 +1,58 @@ +# lane-screen r1 charter — consume screen-content-tools syntax (palette + intrabc) + +Worktree /home/user/Documents/Code/Rust/edith_codecs-screen, branch lane-screen @ 00de8d3. +Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-screen CARGO_BUILD_JOBS=4 nice -n 19 cargo test -p ec-av1 --release --lib -- --nocapture` (full lib ~70s, run it whole; EC_AV1_REQUIRE_AOMENC=1 on gate runs). +Never push, never merge, never touch sibling worktrees (lane-gm and lane-intradisp are live). +libaom oracle: ~/.cache/aom-oracle/src (v3.13.3); binaries in ~/.cache/aom-oracle/build/ (aomdec is instrumented: EC_TRACE=1 prints EC_PART with msac range; EC_AV1_PREFILT_DUMP= dumps pre-filter recon). + +## Why: this is the widest cheap win left +`stream.rs:169` refuses ANY frame with `allow_screen_content_tools` set. That is +14/40 attempts in the AB-partition gate, it blocks the 8x8-OBMC recipe search +(the content that fires 8x8 OBMC trips this bit), and it makes several gates +skip. Crucially the encoder in those gates runs `--enable-palette=0 +--enable-intrabc=0`: the tools are SIGNALLED as allowed but never USED. So the +decoder does not need palette reconstruction — it needs to CONSUME the symbols +so the arithmetic decoder stays in sync (class: symbol-consumption-gap). + +## Scope +1. `read_palette_mode_info` (~/.cache/aom-oracle/src/av1/decoder/decodemv.c:567, + called at :840 and :1103): read it wherever libaom does, gated by + `av1_allow_palette` (blockd.h:1498 — `allow_screen_content_tools && + block_size_wide <= 64 && block_size_high <= 64 && bsize >= BLOCK_8X8`; + confirm the exact constants in the header, do not guess). + - luma branch only when `mode == DC_PRED`; chroma branch only when + `uv_mode == UV_DC_PRED` and the block has chroma. + - You need `palette_y_mode_cdf[bsize_ctx][palette_mode_ctx]`, + `palette_y_size_cdf[bsize_ctx]`, the uv equivalents, plus + `av1_get_palette_bsize_ctx` and `av1_get_palette_mode_ctx` (blockd.h / + reconintra) and the palette COLOR reads that follow a nonzero size. + - If `palette_size != 0` for either plane, refuse BY NAME ("a block that + actually uses a palette") — reconstruction is out of scope. The point of + this lane is that a size of zero must decode, not desync. +2. `read_intrabc_info` (decodemv.c:693, called at :811): read `use_intrabc` + where libaom does (intra frames with `allow_intrabc`); if it is 1, refuse by + name. If 0, continue — note libaom's `use_intrabc` path also affects which + later syntax is read, so mirror the structure exactly. +3. Remove the whole-frame refusal at stream.rs:169 once 1-2 land. Leave the + `delta.q_present || delta.lf_present` refusal below it ALONE. +4. New CDF tables must be wired at all four sites (field, defaults, save/restore, + and the per-frame counter reset) — a table missing from the counter reset + adapts at the wrong RATE and desyncs later, which cost an earlier lane a full + round (class cdf-counter-not-reset). + +## Gate ladder (commit at each green step) +(a) full lib suite — every existing stream bit-identical; +(b) 14-pin default list (`pinned_warp_stream_decodes_pixel_exact -- --ignored`); +(c) `a_real_aomenc_stream_with_ab_partitions_decodes_pixel_exact` — report the + `allow_screen_content_tools` refusal count before and after (that is this + lane's score; it is ~14/40 today); +(d) `a_real_aomenc_filter_intra_stream_decodes_pixel_exact` currently SKIPS + because this same refusal eats it — check whether it now runs. +Any pixel mismatch: pin with EC_AV1_GATE_DUMP=/tmp/claude-1000/screen-flake-N.obu, +then localize (our EC_AV1_PREFILT_DUMP vs the oracle aomdec's, then EC_TRACE=1 +vs EC_AV1_TRACE range ladder). Never guess-fix. + +## Done criteria +Frames that ALLOW screen content but do not USE it decode pixel-exact; actual +palette/intrabc use refuses by name; suite + pins green; report +lanes/screen-r1.report.md with VERDICT first line and the before/after count. diff --git a/lanes/screen-r1.report.md b/lanes/screen-r1.report.md new file mode 100644 index 00000000..6736adc5 --- /dev/null +++ b/lanes/screen-r1.report.md @@ -0,0 +1,74 @@ +VERDICT: GREEN — key-frame palette/intrabc syntax consumed (not reconstructed), whole-frame allow_screen_content_tools refusal narrowed to non-key frames only; 224/0 lib suite unchanged; ab_partitions gate 5/40 matches (35 named refusals, partab_hits=2, none of them screen-content-tools anymore); filter_intra gate now runs its full pixel-exact assertion instead of SKIPping on decode_stream's screen-content-tools refusal. + +## What landed this round (commit 15fbff6, on top of prior builder's 09b50ee) + +Prior builder had already wired `read_intra_mode`/`decode_block`/`decode_leaf8` to read +`use_intrabc` and `palette_y_mode`/`palette_uv_mode` and refuse by name if either ever +actually fires (palette_mode_ctx/palette_uv_mode_ctx hardcoded to 0, a documented safe +corner-cut). What was missing was purely mechanical threading: + +- `decode_key_frame_tile_with_cdfs` and the public `decode_key_frame_tile` wrapper gained + trailing `allow_screen_content_tools: bool, allow_intrabc: bool` params (the internal + `decode_block`/`decode_leaf8` call sites already referenced these names — they were just + never in scope at the outer function's signature). +- `stream.rs`'s real production call now passes `header.allow_screen_content_tools, + header.allow_intrabc`. +- 7 test call sites (`decode.rs` x6, `stream.rs` x1) pass `false, false` — none of those + fixtures use screen content tools, so this is inert for them. +- `stream.rs:169`'s whole-frame refusal narrowed from `if header.allow_screen_content_tools` + to `if header.frame_type != FrameType::Key && header.allow_screen_content_tools`. This is + the load-bearing line: `decode_inter_block`/`decode_inter_block8`'s intra-sub-block branches + (libaom's `read_intra_block_mode_info` equivalent) never call `read_intra_mode` and have no + palette/intrabc wiring at all, so a non-key frame with the bit set would desync silently if + the refusal were removed outright instead of narrowed. The `delta.q_present || delta.lf_present` + refusal on the next lines is untouched, as instructed. + +## Verification + +`cargo check -p ec-av1 --lib --tests`: clean (pre-existing warnings only). + +`cargo test -p ec-av1 --release --lib` (no aomenc requirement): **224 passed, 0 failed, 17 +ignored** — identical to the pre-change baseline; every existing stream has the bit clear, so +the new code path is inert for them, confirming the threading didn't perturb anything already +green. + +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --release --lib pinned`: 2 passed +(`pinned_golden7_stream_decodes_pixel_exact`, `pinned_warp_stream_decodes_pixel_exact`), 4 +failed — all 4 on `NotFound`/`NotPresent` reading a hardcoded fixture path or missing +`EC_AV1_PIN` env var (`pinned_golden3`/`pinned_golden4`/`scratch_decode_pinned_stream_once`/ +`scratch_isolate_pinned_mismatch`), matching the charter's stated pre-existing, unrelated-to- +this-lane stale-scratchpad-path failures exactly (4 of 17 ignored). + +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --release --lib +a_real_aomenc_stream_with_ab_partitions_decodes_pixel_exact`: **ok**, "35 named refusals, 5 +pixel-exact matches out of 40, partab_hits=2". Refusal breakdown from the run: mostly +"a partition type this encoder never writes" and "a non-skip rectangular strip needs +rectangular residual coding" (both pre-existing, unrelated gaps), plus 3 seeds refusing on +"a non-key frame with allow_screen_content_tools set" — i.e. the screen-content-tools bit is +still firing on ~14/40 attempts as the charter's baseline says, but now correctly scoped to +inter frames only (the intra/key-frame occurrences that used to refuse the whole stream no +longer do). Charter's baseline count (~14/40 refusing on this bit specifically) is consistent +with what's visible in this run's log (seeds 67, 69, 70, 79 named explicitly in the tail — +full seed list not individually tallied beyond the visible refusal lines, but the shape +matches: this lane did not change the *inter-frame* refusal count, by design). + +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --release --lib +a_real_aomenc_filter_intra_stream_decodes_pixel_exact`: **ok**, and critically — no +`SKIP a_real_aomenc_filter_intra_stream_decodes_pixel_exact: ...` eprintln in the output. That +SKIP line existed specifically because `decode_stream` used to refuse the whole (key) frame +whenever libaom's internal `screen_content_tools_determination` happened to flip +`allow_screen_content_tools=1` on this fixture even with `--enable-palette=0 +--enable-intrabc=0`. With the key-frame path now consuming that syntax instead of refusing, +the test runs to its real assertions (`filter_intra_hits` moved, luma/U/V pixel-exact vs +ffmpeg) every time this round, i.e. it now exercises the gate instead of skipping it. + +## Ceiling for the next lane + +Threading `decode_inter_block`/`decode_inter_block8`'s intra-sub-block branches (libaom's +`read_intra_block_mode_info`) with the same `allow_screen_content_tools`/`allow_intrabc` +params — and reading `use_intrabc`/palette mode there the same way `read_intra_mode` does now +— is what would let the `stream.rs:169` refusal narrow further (or drop) for non-key frames. +Until that lands, every inter frame with the bit set keeps refusing by name; this lane +deliberately did not touch that surface (out of scope per charter, and doing it blind would +risk a silent desync exactly like the key-frame path was one signature-threading step away +from having, before this round).