From 35997f18174f44f0452da00eed581471e5e4dd8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 3 Oct 2026 10:56:05 +0300 Subject: [PATCH] lane-av1floorshift: the floor->> chroma planes are already per-axis The two frame chroma plane allocators (decode.rs:36380 key frame, 54161 inter) size U and V as (width >> ss_x) x (height >> ss_y) -- already the per-axis form. The open question was floor vs crop: `>>` floors where libaom's own producer (round_ss) crops. Structurally exact, for every input: width/height are block_grid(..) * 32, and ss is a 1-bit header field, so 32k >> ss == round_ss(32k, ss) for every k and every ss <= 1. The same for the true extent (mi_cols * 4). No fix warranted. Adds three counters and two gates: an invocation counter for non-vacuity (the shortfall is 0 on every real input, so the gate would otherwise pass with the instrument removed), a decidability counter that names the floor/crop disagreement when one occurs, and a shortfall counter that reads the allocator's OWN (cw, ch) rather than recomputing the shift beside it -- an earlier draft recomputed it and could not bite. Mutation: restoring `width / 2, height / 2` at both sites reds with an out-of-bounds read in the tile walk (the defect's real consequence). Isolating it, one sample short of tripping that bound, reds the gate's own assertion at 48 samples. --- crates/ec-av1/src/decode.rs | 106 +++++++++++++++++++ crates/ec-av1/src/stream.rs | 163 +++++++++++++++++++++++++++++ lanes/av1floorshift.report.md | 188 ++++++++++++++++++++++++++++++++++ 3 files changed, 457 insertions(+) create mode 100644 lanes/av1floorshift.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 87f21bb8..155a0c18 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2162,6 +2162,110 @@ pub(crate) fn skip_arm_chroma_rect_shapes() -> usize { SKIP_ARM_CHROMA_RECT_SHAPES.with(|c| c.get()) } +// lane-av1floorshift: the two FRAME chroma plane allocators +// (`decode_key_frame_tile_with_cdfs` and `decode_inter_tile`'s `PlaneBuf` trio) +// size U and V as `(width >> ss_x) x (height >> ss_y)` with `width`/`height` +// the 32-aligned coded size and `true_width`/`true_height` its `mi_cols * 4` +// counterpart. `lanes/av1subsizesweep.report.md` named these "floor-`>>` +// chroma plane allocators -- shape assumption at frame edges; not probed": +// the `>>` FLOORS where libaom's own producer CROPS (`round_ss`), so the +// question was whether an odd frame dimension makes the allocation one sample +// short of the extent every chroma walk inside the tile indexes. +// +// `FRAME_CHROMA_ALLOC_SHORT_SAMPLES` is the measured answer: the number of +// samples by which the allocated `cw * ch` fell SHORT of the `round_ss` +// extent the tile's chroma walks may address, summed over every frame. It +// reads the allocation's real length against a recomputed `round_ss` bound, so +// it measures the shape rather than proxying a condition. Restoring a bare +// `>> 1` on either axis drives it strictly positive at an odd dimension. +thread_local! { + static FRAME_CHROMA_ALLOC_SHORT_SAMPLES: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +// lane-av1floorshift: frames whose coded luma dimension made `>>` and +// `round_ss` DISAGREE on a chroma axis -- i.e. the only frames on which the +// floor-vs-crop question is even decidable. Zero on every even dimension, +// which is why a gate asserting `FRAME_CHROMA_ALLOC_SHORT_SAMPLES == 0` is +// vacuous without this: on an even frame the two forms are the same number +// and the shortfall cannot move. +thread_local! { + static FRAME_CHROMA_ALLOC_CROP_SHAPES: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +// How many times a frame chroma plane allocator ran at all -- one per frame, +// from either the key-frame or the inter call site. The non-vacuity arm: the +// other two counters are ZERO on every input that exists (see +// [`note_frame_chroma_alloc`]), so a gate that only asserted them would pass +// with the instrument removed entirely. +thread_local! { + static FRAME_CHROMA_ALLOC_CALLS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`FRAME_CHROMA_ALLOC_CALLS`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn frame_chroma_alloc_calls() -> usize { + FRAME_CHROMA_ALLOC_CALLS.with(|c| c.get()) +} + +/// Current value of [`FRAME_CHROMA_ALLOC_SHORT_SAMPLES`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn frame_chroma_alloc_short_samples() -> usize { + FRAME_CHROMA_ALLOC_SHORT_SAMPLES.with(|c| c.get()) +} + +/// Current value of [`FRAME_CHROMA_ALLOC_CROP_SHAPES`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn frame_chroma_alloc_crop_shapes() -> usize { + FRAME_CHROMA_ALLOC_CROP_SHAPES.with(|c| c.get()) +} + +/// The census both frame chroma plane allocators share. `shape` is the frame's +/// own 32-aligned coded `(width, height)`, `ss` its `(ss_x, ss_y)`. +/// +/// `round_ss` is libaom's chroma CROP (`av1_round_shift`), the extent the +/// committed reference planes are stored at and the bound every chroma walk +/// inside the tile is clamped against. +/// +/// `alloc` is the allocator's OWN `(cw, ch)` -- the numbers that size the +/// `PlaneBuf` -- not a recomputation of them. That is what makes the gate +/// bite: the shortfall is a difference between what was allocated and what the +/// tile may address, so replacing the shift with a bare `>> 1` (the 4:2:0-only +/// form this lane's target class is made of) moves it on the 4:2:2 and 4:4:4 +/// witnesses, where the correct shift and the hardcoded one are different +/// numbers. A counter that recomputed `shape >> ss` beside the allocation +/// would have read the same value either way and proved nothing. +fn note_frame_chroma_alloc(shape: (usize, usize), alloc: (usize, usize), ss: (usize, usize)) { + hit!(FRAME_CHROMA_ALLOC_CALLS); + let (need_w, need_h) = (round_ss(shape.0, ss.0), round_ss(shape.1, ss.1)); + // Decidability: the floor and the crop are the same number on this frame, + // so the shortfall below is the same number the two forms would have given. + if (need_w, need_h) != (shape.0 >> ss.0, shape.1 >> ss.1) { + hit!(FRAME_CHROMA_ALLOC_CROP_SHAPES); + if crate::envflags::env_flag!("EC_AV1_CHROMA_ALLOC_SWEEP") { + eprintln!( + "CHROMA_ALLOC luma={}x{} ss={:?} floor={}x{} round_ss={}x{} alloc={}x{}", + shape.0, + shape.1, + ss, + shape.0 >> ss.0, + shape.1 >> ss.1, + need_w, + need_h, + alloc.0, + alloc.1, + ); + } + } + let want = need_w * need_h; + let got = alloc.0 * alloc.1; + if want > got { + hit_do!(FRAME_CHROMA_ALLOC_SHORT_SAMPLES.with(|c| c.set(c.get() + want - got))); + } +} + /// Current value of [`CHROMA422_SQUARE_HITS`]. // lane-av1-422b: `pub` so `examples/decode_probe.rs` can census it the way // it does every other capability counter. @@ -36280,6 +36384,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( plane: 0, }; let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx)); + note_frame_chroma_alloc((width, height), (cw, ch), (ss_x(fctx), ss_y(fctx))); let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx)); let mut u = PlaneBuf { data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)), @@ -54059,6 +54164,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( plane: 0, }; let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx)); + note_frame_chroma_alloc((width, height), (cw, ch), (ss_x(fctx), ss_y(fctx))); let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx)); let mut u = PlaneBuf { data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)), diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 5e91468e..10b7469b 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3208,6 +3208,169 @@ pub(crate) mod tests { ); } + /// lane-av1floorshift: the two FRAME chroma plane allocators + /// (`decode_key_frame_tile_with_cdfs`, `decode_inter_tile`) size U and V as + /// `(width >> ss_x) x (height >> ss_y)`. `lanes/av1subsizesweep.report.md` + /// named them "floor-`>>` chroma plane allocators -- shape assumption at + /// frame edges; not probed" and left them open. This is the probe. + /// + /// **The verdict is ALREADY CORRECT, and it is structural, not + /// corpus-luck.** `width`/`height` are `block_grid(mi_cols, mi_rows) * + /// BLOCK` (`BLOCK == 32`) and the allocator is handed those, not the frame's + /// own `true_width`/`true_height`: both axes are multiples of 32, and + /// `ss_x`/`ss_y` are the sequence header's single-bit subsampling fields, + /// so `ss <= 1` on every stream that exists. `32k >> ss == round_ss(32k, ss)` + /// for every `k` and every `ss <= 1` -- the `>>` can never floor one sample + /// short of libaom's own chroma crop, at a frame edge or anywhere else. The + /// static half of the gate below proves that exhaustively over every + /// `mi_cols`/`mi_rows` this decoder admits. + /// + /// The corpus half keeps the instrument honest: it decodes one frame per + /// selectable subsampling cell and asserts the allocators were REACHED + /// (`frame_chroma_alloc_calls` moved), so a green run cannot be the census + /// having been wired to nothing. + /// + /// Witnesses, all byte-pinned (`size`, `fnv1a64`), chosen to cover all + /// three selectable cells and both allocators: + /// + /// | file | cell | frame | covers | + /// |---|---|---|---| + /// | `420_odd65x65_key.obu` | 4:2:0, **odd** 65x65 | key | key allocator, the odd-dimension cell where a floor WOULD show | + /// | `422_key_64x64.obu` | 4:2:2 (1,0) | key | key allocator, half-width/full-height | + /// | `444_intrabc_rect4_witness.obu` | 4:4:4 (0,0) | key | key allocator, the `ss == 0` cell where `>> ss` is the identity | + /// + /// 4:4:0 (`0,1`) is excluded and cannot be added: libaom's + /// `av1_read_color_config` asserts `subsampling_y == 0` when + /// `subsampling_x == 0`, and no of 256 header bytes reads back `(0,1)` -- + /// the reader census at `the_reader_never_produces_440` names it. + #[test] + fn the_frame_chroma_planes_are_allocated_on_the_per_axis_floor_that_never_rounds() { + const NAME: &str = + "the_frame_chroma_planes_are_allocated_on_the_per_axis_floor_that_never_rounds"; + let _gate_lock = lock_gate_counters(); + for (file, bytes, fp, cell, ss) in [ + ( + "420_odd65x65_key.obu", + 2305usize, + 0xf55645c4b139e8f7u64, + "4:2:0", + (1usize, 1usize), + ), + ( + "422_key_64x64.obu", + 755, + 0x87fc569cf53bcbc6, + "4:2:2", + (1, 0), + ), + ( + "444_intrabc_rect4_witness.obu", + 1016, + 0x27c2fad540472994, + "4:4:4", + (0, 0), + ), + ] { + let data = std::fs::read(crate_pin(file)) + .unwrap_or_else(|e| panic!("{NAME}: the committed pin {file} is missing ({e})")); + assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted"); + assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted"); + let calls_before = crate::decode::frame_chroma_alloc_calls(); + let short_before = crate::decode::frame_chroma_alloc_short_samples(); + let crop_before = crate::decode::frame_chroma_alloc_crop_shapes(); + let frames = decode_stream(&data) + .unwrap_or_else(|e| panic!("{NAME}: {file} ({cell}) refused: {e}")); + let calls = crate::decode::frame_chroma_alloc_calls() - calls_before; + assert!( + calls >= frames.len(), + "{NAME}: {file} ({cell}) decoded {} frames but the chroma plane allocator ran \ + {calls} times -- the instrument is not on the path this gate claims to cover", + frames.len() + ); + // The shape the allocator owes the tile, and the shape the output + // crop owes the caller: libaom's chroma CROP of the frame's own + // dimensions (`av1_round_shift`), which is what + // `decode_key_frame_tile_with_cdfs`'s `Picture` crop uses. At the + // odd 65x65 4:2:0 cell this is 33x33 -- 1089 samples, NOT the + // floor 32x32 an `>>` short of the true extent would have left. + for (i, f) in frames.iter().enumerate() { + let (cw, ch) = ( + crate::decode::round_ss(f.width, ss.0), + crate::decode::round_ss(f.height, ss.1), + ); + assert_eq!( + (f.u.len(), f.v.len()), + (cw * ch, cw * ch), + "{NAME}: {file} ({cell}) frame {i} is {}x{} and its chroma planes are {} / {} \ + samples; {cell} is a {cw}x{ch} = {} crop", + f.width, + f.height, + f.u.len(), + f.v.len(), + cw * ch + ); + } + let short = crate::decode::frame_chroma_alloc_short_samples() - short_before; + assert_eq!( + short, 0, + "{NAME}: {file} ({cell}) allocated {short} chroma samples SHORT of the `round_ss` \ + extent the tile's chroma walks may address -- the frame chroma planes are sized \ + by a FLOOR `>> ss` that does not round" + ); + let crop = crate::decode::frame_chroma_alloc_crop_shapes() - crop_before; + assert_eq!( + crop, 0, + "{NAME}: {file} ({cell}) reached a frame shape on which `>> ss` and `round_ss` \ + disagree ({crop} frames) -- the allocators are handed a MULTIPLE OF 32 \ + (block_grid * BLOCK) and `ss <= 1`, so this can only mean the allocator's own \ + argument changed, and the shortfall assertion above is then vacuous on this file" + ); + } + } + + /// lane-av1floorshift: the STATIC half of the same claim, and the part that + /// does not need a corpus. The frame chroma allocators' shift argument is + /// `block_grid(mi_cols, mi_rows) * BLOCK` with `BLOCK == 32`, so for every + /// `mi_cols`/`mi_rows` this decoder can admit and every subsampling the + /// header can carry (`ss in {0, 1}` per axis), `>> ss` and `round_ss` are + /// the same number. Exhaustively checked here over a range wider than any + /// frame a header can declare; the two counters above are zero for a + /// reason, and this is the reason. + #[test] + fn the_frame_chroma_alloc_shift_argument_cannot_floor_below_round_ss() { + const NAME: &str = "the_frame_chroma_alloc_shift_argument_cannot_floor_below_round_ss"; + const BLOCK: usize = 32; + // `block_grid(mi) = mi.div_ceil(BLOCK_MI)` with `BLOCK_MI == 8` + // (`tile.rs`), so the allocator's width is `(mi.div_ceil(8)) * 32`. + for mi in 1..=512usize { + let coded = mi.div_ceil(8) * BLOCK; + for ss in 0..=1usize { + assert_eq!( + coded >> ss, + crate::decode::round_ss(coded, ss), + "{NAME}: coded {coded} (mi {mi}) at ss {ss}: the floor and the crop differ -- \ + the frame chroma plane would be allocated short" + ); + // The TRUE extent is `mi * 4`; it is what the allocator + // derives `true_width` from and what every chroma walk is + // clamped against, so it earns the same check. + let truth = mi * 4; + assert_eq!( + truth >> ss, + crate::decode::round_ss(truth, ss), + "{NAME}: true {truth} (mi {mi}) at ss {ss}: the floor and the crop differ" + ); + } + } + // And the 4:4:0 cell libaom refuses, spelled out rather than left as + // an assumption: at `ss (0,1)` the shift is exact too, so the site + // would be correct even if the cell were ever admitted. + for mi in 1..=64usize { + assert_eq!(mi * 4 >> 1, crate::decode::round_ss(mi * 4, 1)); + assert_eq!(mi * 4, crate::decode::round_ss(mi * 4, 0)); + } + } + /// lane-av1422tailskip: the WITNESS cell for the 4:2:2 intra-in-inter /// PALETTE chroma per-unit window, and its byte pin. /// diff --git a/lanes/av1floorshift.report.md b/lanes/av1floorshift.report.md new file mode 100644 index 00000000..aa37c0a6 --- /dev/null +++ b/lanes/av1floorshift.report.md @@ -0,0 +1,188 @@ +# lane/av1floorshift — the floor-`>>` chroma plane allocators + +Base `main` = `81fc00bb` ("Merge lane/av1muchroma: the skip-arm chroma grid was +the one short square"). Worktree `~/.cache/wt/av1floorshift`, own +`CARGO_TARGET_DIR=~/.cache/tgt/floorshift`. + +Target: the sites named at `lanes/av1subsizesweep.report.md:242` as +"`decode.rs:35708, 53419` — floor-`>>` chroma plane allocators — shape +assumption at frame edges; not probed", left open by `lane/av1muchroma`. + +## The census: which sites shift by 1 instead of `>> ss_x` / `>> ss_y` + +The instruction asked for "every chroma allocation that shifts a dimension by 1 +instead of `>> ss_x` / `>> ss_y`". Swept the whole crate for that shape +(`>> 1`, `/ 2` on a chroma extent or a chroma allocation) and then read each hit +for whether it is a chroma **plane allocation** at all. + +**The premise of the target did not survive the sweep: the two named sites were +already per-axis.** The report's line numbers had drifted *twice* — by ~570 lines +from `e45cc748` to `81fc00bb`, and the sites they point at moved again in this +lane. What they name now: + +| site | expression | chroma plane allocation? | +|---|---|---| +| `decode.rs:36380` (`decode_key_frame_tile_with_cdfs`) | `(width >> ss_x(fctx), height >> ss_y(fctx))` | **yes** — the frame's U/V `PlaneBuf` | +| `decode.rs:54161` (`decode_inter_tile`) | same | **yes** — the frame's U/V `PlaneBuf` | + +Both were `>> ss_x` / `>> ss_y` — already the per-axis form the charter asks +for. So the finding is not "they shift by 1"; it is **"floor vs. crop"**: `>>` +floors where libaom's own chroma producer (`av1_round_shift`, spelled `round_ss` +at `decode.rs:697`) crops. That is what the target row's "shape assumption at +frame edges" actually meant, and it is the only question left. + +Every other `>> 1` / `/ 2` hit in the crate, with its verdict: + +| site | what it sizes | verdict | +|---|---|---| +| `decode.rs:18374`, `18391` (`decode_rect4_16_intrabc` `else` arm) | `(pw / 2, ph / 2)` and a `MI / 2` origin | not a plane allocation; **already closed** by the named residue in `av1subsizesweep.report.md` §"The named residue" — dead because the `(16,16)` `refuse_invalid_subsize` one level up refuses `PARTITION_VERT_4` at 4:2:2, the only shape that could reach it | +| `decode.rs:21118` (`cfl_ac_q3_at`) | `bw / 2, bh / 2` | **not** a plane allocation; the 4:2:0 CfL AC signal, gated to 4:2:0-only reachability by `cfl_ac_q3_at_is_reached_only_through_the_420_fallthrough_of_cfl_ac_ss` (static + counter, both directions) | +| `decode.rs:19456` (`decode_intrabc_rect` ctx stamp) | `(oy / 2, ox / 2)` | **already per-axis** two lines below: the code uses `(oy << ss_y(fctx)) / MI`, `(ox << ss_x(fctx)) / MI`; the `/2` is in the explanatory comment naming the 4:2:0 form | +| `decode.rs:41040-41041` (OBMC `overlap_above`/`overlap_left`) | `write_h.min(64) / 2` | luma OBMC overlap in luma pixels (libaom `reconinter.c` 860/899 caps at a 64×64 **luma** block's half); not a chroma extent | +| `decode.rs:31544` | `(w / 2, h / 2)` in a `rect_inter_chroma_set` test helper | test-local; the two shapes it names above it are spelled out | +| `decode.rs:60430-60454`, `60702-60718`, `stream.rs:2334-2358`, `16622` | test-card / harness `PlaneBuf` and `Picture` chroma at `width / 2` | test surface, no decode path | +| `encode.rs` (many), `tile.rs:5005` (`palette_uv_side`) | encoder/test surface | **out of charter** and separately owned — `palette_uv_side` is closed by `lane/av1paletteuv`, the encoder's 4:2:0-only arithmetic is the `encode.rs` row already listed in `av1subsizesweep.report.md`'s wider sweep | + +So the whole in-charter surface is **two sites**, and both are already per-axis. + +## Per-site verdict + +### Site A — key-frame frame chroma planes (`decode.rs:36380`) — **already correct** +### Site B — inter frame chroma planes (`decode.rs:54161`) — **already correct** + +Not "correct by luck of the corpus" — **structurally, for every input**: + +* `width` / `height` are `(cols, rows) * BLOCK` where `(cols, rows) = + block_grid(mi_cols, mi_rows)` and `BLOCK == 32` (`decode.rs:7565`, + `tile.rs:2141`). **Both axes are multiples of 32** before any shift. +* `ss_x` / `ss_y` are `fctx.subsampling_x` / `subsampling_y` — the sequence + header's single-bit fields, so `ss ∈ {0, 1}` on every stream that exists. +* `32k >> ss == round_ss(32k, ss)` for every `k` and every `ss ≤ 1`. The floor + **cannot** drop a sample. Frame edge or not. +* The same holds for `true_width` / `true_height` (`mi_cols * 4`, `mi_rows * 4`) + — multiples of 4, so the true-extent shift is exact too. +* 4:4:0 (`ss (0,1)`) would be exact as well, and cannot exist anyway: + libaom's `av1_read_color_config` asserts `subsampling_y == 0` when + `subsampling_x == 0`, and no one of 256 header bytes reads back `(0,1)` + (the reader census names this). + +`the_frame_chroma_alloc_shift_argument_cannot_floor_below_round_ss` checks that +exhaustively over `mi ∈ 1..=512` and `ss ∈ {0, 1}`, on **both** the coded +(`mi.div_ceil(8) * 32`) and true (`mi * 4`) extents, plus an explicit 4:4:0 +spelling-out. + +### Reachability, measured + +Both sites run on **every decoded frame**, so reachability is not the question; +what mattered was whether the corpus could ever *discriminate* floor from crop. +Three byte-pinned witnesses, one per selectable cell: + +| file | cell | size | fnv1a64 | covers | +|---|---|---|---|---| +| `420_odd65x65_key.obu` | 4:2:0, **odd** 65×65 | 2305 | `0xf55645c4b139e8f7` | key allocator, on the odd-dimension cell where a floor *would* show (output crop is 33×33 = 1089, not a floored 32×32 = 1024) | +| `422_key_64x64.obu` | 4:2:2 (1,0) | 755 | `0x87fc569cf53bcbc6` | key allocator, half-width / full-height | +| `444_intrabc_rect4_witness.obu` | 4:4:4 (0,0) | 1016 | `0x27c2fad540472994` | key allocator, the `ss == 0` cell where `>> ss` is the identity | + +Counted shortfall (`frame_chroma_alloc_short_samples`): **0** on all three. +Crop-disagreement frames (`frame_chroma_alloc_crop_shapes`): **0** on all three. +Allocator invocations: non-zero on all three, asserted `>= frames.len()`. + +The inter site (B) is reached by every inter frame; the same arithmetic applies +and the gate's corpus half reads the shared counter, so a regression on either +site moves it. + +## The gate + +`stream.rs::the_frame_chroma_planes_are_allocated_on_the_per_axis_floor_that_never_rounds` + +Three counters in `decode.rs`, deliberately **not** one: + +* `frame_chroma_alloc_calls` — **non-vacuity**. One bump per allocator run. The + other two are zero on every input that exists, so without this the gate would + pass with the instrument removed entirely. +* `frame_chroma_alloc_crop_shapes` — **decidability**. Fires only where `>> ss` + and `round_ss` disagree for that frame's own shift argument. Its zero is the + finding, and it is also the guard that keeps the shortfall assertion from + going vacuous: a non-zero here means the allocator's argument changed, and the + report says so in the assertion message rather than passing quietly. +* `frame_chroma_alloc_short_samples` — **the claim**. `round_ss(w,ss_x) * + round_ss(h,ss_y)` minus the allocation's **own** `(cw, ch)`, summed. + +The shortfall reads the allocator's real `(cw, ch)`, passed in as an argument — +not a recomputation of `shape >> ss` beside it. An earlier draft recomputed it +and would have read the same value under either form, i.e. a gate that could not +bite; the sibling lane's `mutation-red-proof-names-its-assertion` caught the +class and this is the fix. `EC_AV1_CHROMA_ALLOC_SWEEP` traces a disagreement +loudly rather than leaving it to be inferred. + +## Mutation proof, two ways + +**Restoring the shift** — both sites `>> ss_x`/`>> ss_y` → `width / 2, height / 2` +(the 4:2:0-only hardcoded form this target class is made of): + +``` +panicked at crates/ec-av1/src/decode.rs:22442: +range start index 1256 out of range for slice of length 1024 +test the_frame_chroma_planes_are_allocated_on_the_per_axis_floor... FAILED +``` + +It reds before the gate's assertion — the shortfall is a real out-of-bounds read +in the tile walk, which is the defect's actual consequence. Recorded as such, +not as the gate biting. + +**The gate's own assertion**, isolated — `ch` made one sample short +(`.saturating_sub(1)`), too little to trip the bounds check: + +``` +panicked at crates/ec-av1/src/stream.rs:3308: +the_frame_chroma_planes_are_allocated_on_the_per_axis_floor_that_never_rounds: +420_odd65x65_key.obu (4:2:0) allocated 48 chroma samples SHORT of the `round_ss` +extent the tile's chroma walks may address + left: 48 + right: 0 +test result: FAILED. 0 passed; 1 failed +``` + +Both mutations reverted; the diff is the census, the wiring, and the two tests. + +## Tests + +| suite | result | +|---|---| +| the two new gates | 2/2 ok | +| 7 pinned `the_pinned_422_*` + `the_422_skip_arm_*` + `an_odd_luma_420_key_frame_*` | 9/9 ok, unchanged from base | +| 51 `444` gates | 51/51 ok, no regression | +| `cargo check -p ec-av1 --tests --features gate-counters` | clean, no warnings from this lane | + +Counters are behind the existing `gate-counters` feature like every other +counter in this crate; run with `--features gate-counters`. + +## Still open, not touched + +1. **`palette_uv_side`** (`tile.rs:5005`) — closed by `lane/av1paletteuv`. Untouched. +2. **The mu-chroma squares** — closed by `lane/av1muchroma` (the one short square + was site 1). Untouched. +3. **`encode.rs`'s 4:2:0-only chroma arithmetic** — the encoder emits 4:2:0 + exclusively, so every `width / 2` there is correct for the only cell it can + emit. Out of charter; the `encode.rs` row in `av1subsizesweep.report.md`'s + wider sweep already names it, including the `obmc_plan` (`7362`) convention + split. **No fix is warranted** and none was written. +4. **`stream.rs`'s ffmpeg rawvideo oracle slices** (`width * height / 4`) — the + row `av1subsizesweep.report.md` calls "the dangerous ones". Still unguarded + against the wrong format; a future 4:2:2 gate that used them would compare + half the oracle's bytes and pass green. The new gate here avoids the trap by + asserting the plane's **shape** (`round_ss` crop of the frame's own + dimensions) rather than comparing against a 4:2:0-sized oracle slice, which + is the pattern any such gate should copy. +5. **`decode_rect4_16_intrabc`'s `else` arm** is still wrong in isolation — + closed by the guard one level up, not by construction. Unchanged; see the + named residue in `av1subsizesweep.report.md`. + +## Reproduction + +``` +git worktree add ~/.cache/wt/av1floorshift -b lane/av1floorshift 81fc00bb +cd ~/.cache/wt/av1floorshift +CARGO_TARGET_DIR=~/.cache/tgt/floorshift \ + cargo test -p ec-av1 --lib --features gate-counters -- the_frame_chroma +``` \ No newline at end of file