forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-realworld': the inter path stops assuming SPLIT

Browse files at this commit

0e15bcf74e31ed64260b3a074b42227e8ec2b5f2Ahmet Kaan GümüşParent: be7060a9167027
decode_inter_frame_tile_with_cdfs read the superblock's part64 symbol and threw
it away (`let _ = part64;`), recursing as SPLIT regardless. A real non-SPLIT
part64 in an inter frame silently miscoded the whole superblock -- the one
failure mode this decoder does not tolerate. It now matches: SPLIT is still
inferred for the three straddle/forced-half cases, and any other real value
refuses by name before the quadrant recursion, with a hand-built PARTITION_HORZ
stream as the test.

refusal_inventory gained that string, as designed. The refusal describes what
this decoder does, not what an encoder emits, so it is a plain refusal and not
a capability claim.

delta_q/delta_lf is scoped but unstarted; lanes/realworld-r3.report.md carries
the verified default CDFs, the four call sites (the same four maybe_read_cdef_idx
uses), and the finding that base_q_idx is read at only 2 of ~90 sites, so a
thread-local running quantizer avoids threading a parameter through every block
signature. The DeltaLF-to-deblocker path still needs per-block MiGrid state.

Suite 240 passed / 0 failed.
crates/ec-av1/src/decode.rsmodified+60 -5
@@ -9557,25 +9557,40 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
95579557 sb_c * SB_MI + SB_MI / 2 < mi_cols,
95589558 sb_r * SB_MI + SB_MI / 2 < mi_rows,
95599559 );
9560- match (has_cols, has_rows) {
9560+ // The straddle cases (one or both halves outside the true
9561+ // frame) never carry a real alphabet symbol -- spec forces
9562+ // SPLIT there (mirrors the intra key-frame tile's own
9563+ // three-way write above). Only the (true, true) case can name
9564+ // a non-SPLIT value, and this loop below only ever recurses as
9565+ // SPLIT -- so a real non-SPLIT part64 here must refuse by name
9566+ // instead of silently decoding as SPLIT and desyncing.
9567+ let part64 = match (has_cols, has_rows) {
95619568 (true, true) => {
9562- let part64 = dec.symbol(&mut cdfs.partition_w64[sb_ctx]);
9569+ let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]);
95639570 if std::env::var_os("EC_AV1_TRACE").is_some() {
95649571 eprintln!(
9565- "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={part64}",
9572+ "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p}",
95669573 sb_r * SB_MI,
95679574 sb_c * SB_MI
95689575 );
95699576 }
9570- let _ = part64;
9577+ p
95719578 }
95729579 (true, false) => {
95739580 dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE));
9581+ PARTITION_SPLIT
95749582 }
95759583 (false, true) => {
95769584 dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE));
9585+ PARTITION_SPLIT
95779586 }
9578- (false, false) => {}
9587+ (false, false) => PARTITION_SPLIT,
9588+ };
9589+ if part64 != PARTITION_SPLIT {
9590+ return Err(unsupported(
9591+ "an inter SB-level partition type other than SPLIT (this decoder's \
9592+ inter tile path only recurses a superblock as SPLIT)",
9593+ ));
95799594 }
95809595
95819596 for quadrant in 0..4 {
@@ -11004,6 +11019,46 @@ mod tests {
1100411019 );
1100511020 }
1100611021
11022+ /// An inter tile's SB-level `part64` used to be read and thrown away
11023+ /// (`let _ = part64;`), recursing as SPLIT unconditionally -- a real
11024+ /// non-SPLIT value there silently desynced the whole tile instead of
11025+ /// refusing. Hand-writes a single whole superblock's `part64 = HORZ`
11026+ /// symbol (never produced by this crate's own encoder, which only ever
11027+ /// writes NONE/SPLIT at this level, but a real aomenc-class encoder can)
11028+ /// and asserts this decoder refuses by name rather than decoding garbage.
11029+ #[test]
11030+ fn a_non_split_inter_sb_partition_refuses_by_name_instead_of_desyncing() {
11031+ use crate::msac::SymbolEncoder;
11032+ let mut cdfs = Cdfs::new(q_ctx_of(40));
11033+ let mut enc = SymbolEncoder::new();
11034+ enc.symbol(PARTITION_HORZ, &mut cdfs.partition_w64[0]);
11035+ let data = enc.finish();
11036+ let reference = crate::encode::Picture::grey(64, 64);
11037+ let err = decode_inter_frame_tile(
11038+ &data,
11039+ 16,
11040+ 16,
11041+ 40,
11042+ 64,
11043+ 64,
11044+ &reference,
11045+ [None; 8],
11046+ &CdefParams::default(),
11047+ &LoopFilterParams::default(),
11048+ false,
11049+ false,
11050+ Some(mc::InterpFilterKind::Regular),
11051+ false,
11052+ false,
11053+ )
11054+ .unwrap_err();
11055+ let msg = err.to_string();
11056+ assert!(
11057+ msg.contains("SPLIT"),
11058+ "expected the named inter-SB-partition refusal, got: {msg}"
11059+ );
11060+ }
11061+
1100711062 // ffmpeg cross-oracle: an independent decoder (not this crate's own
1100811063 // encoder-side reconstruction) agrees with what this module decodes,
1100911064 // duplicating `crate::encode`'s own `#[cfg(test)]` helpers of the same
crates/ec-av1/src/refusal_inventory.rsmodified+1 -0
@@ -60,6 +60,7 @@ const REFUSALS: &[&str] = &[
6060 "an inter frame using TxMode::Select (this decoder's inter path never reads a tx_depth symbol, so it desyncs after the first block's mode)",
6161 "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)",
6262 "an inter frame with no key frame before it",
63+ "an inter SB-level partition type other than SPLIT (this decoder's inter tile path only recurses a superblock as SPLIT)",
6364 "an inter partition below 16x16 (8x8 and smaller inter blocks are not coded yet)",
6465 "an intra mode this decoder does not code (round 2)",
6566 "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet",
lanes/realworld-r3.report.mdadded+158 -0
@@ -0,0 +1,158 @@
1+# lane-realworld r3 report
2+
3+VERDICT: Job 1 (part64 silent desync) FIXED, tested, committed (879999d).
4+Job 2 (delta_q/delta_lf) UNSTARTED but fully scoped below — turn budget ran
5+out during the design phase, before any code was written, so there is
6+nothing half-done to unwind for the next agent.
7+
8+## Job 1 -- part64 silent desync (committed 879999d)
9+`decode_inter_frame_tile_with_cdfs` (decode.rs, the `(true, true)` arm around
10+what was line 9397) read `part64` then `let _ = part64;`, always recursing
11+the quadrant loop as if SPLIT. Fixed: the value is now kept (still inferred
12+as `PARTITION_SPLIT` for the three straddle/forced-half cases, matching the
13+intra tile's own three-way write), and if a real read comes back anything
14+other than `PARTITION_SPLIT` the function returns
15+`Err(unsupported("an inter SB-level partition type other than SPLIT (this
16+decoder's inter tile path only recurses a superblock as SPLIT)"))` before
17+the quadrant recursion runs.
18+
19+**New refusal string** (verbatim, for the merge's `refusal_inventory.rs`):
20+`"an inter SB-level partition type other than SPLIT (this decoder's inter
21+tile path only recurses a superblock as SPLIT)"`
22+
23+Test: `decode::tests::a_non_split_inter_sb_partition_refuses_by_name_instead_of_desyncing`
24+hand-writes a single `PARTITION_HORZ` `part64` symbol with `SymbolEncoder`
25+and asserts `decode_inter_frame_tile` returns that named error rather than
26+decoding garbage. `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j4`:
27+**234 passed, 0 failed, 17 ignored** (was 232/0/17 before this lane; +1 this
28+test, +1 from r2's CDEF work already on the branch).
29+
30+No gate needed for this one (charter: "make it refuse by name... and prove
31+the refusal with a test" -- minimum rung taken deliberately, not the
32+"handle it" rung, since real non-SPLIT part64 content requires the same
33+multi-SB, non-`--cpu-used=0` recipe r2 already flagged as its own separate
34+lane, not this desync fix).
35+
36+## Job 2 -- delta_q/delta_lf: scoped, not started
37+
38+Ran the libaom source at `~/.cache/aom-oracle/src/av1/decoder/decodemv.c`
39+and `av1/common/entropymode.c` directly (real oracle, not memory) before
40+running out of budget. Concrete plan for the next agent:
41+
42+### Default CDFs (verified against entropymode.c:840-852)
43+Both are 4-symbol alphabets (`DELTA_Q_PROBS`/`DELTA_LF_PROBS` = 3), and this
44+crate's CDF convention already matches libaom's `AOM_CDF4` arguments
45+directly (confirmed against `cdf.rs`'s existing `SKIP` table, which is
46+`AOM_CDF2(31671)` verbatim) -- no inversion needed:
47+```rust
48+pub const DELTA_Q: [u16; 5] = [28160, 32120, 32677, 32768, 0];
49+pub const DELTA_LF: [u16; 5] = [28160, 32120, 32677, 32768, 0];
50+pub const DELTA_LF_MULTI: [[u16; 5]; 4] = [DELTA_Q; 4]; // same value x FRAME_LF_COUNT
51+```
52+(`FRAME_LF_COUNT = 4`, `MAX_LOOP_FILTER = 63`, `DELTA_Q_SMALL = DELTA_LF_SMALL = 3`.)
53+
54+### Read logic (decodemv.c:85-146, `read_delta_qindex`/`read_delta_lflevel`,
55+called from `read_delta_q_params` at :732)
56+Both follow the same shape: a 4-symbol CDF read; if the result is 3
57+(`DELTA_*_SMALL`), extend with `L(3)`-then-`1+that`-many literal bits
58+(`rem_bits = literal(3)+1; thr = (1<<rem_bits)+1; abs = literal(rem_bits) +
59+thr`); if `abs != 0` read one sign literal bit (sign=1/no-read implied
60+"positive" when abs==0, matching spec/libaom exactly -- `sign = abs ?
61+read_bit() : 1`); `reduced = sign ? -abs : abs`. For q: `CurrentQIndex =
62+clamp(CurrentQIndex + reduced*delta_q_res, 1, 255)`. For lf: same shape,
63+`clamp(DeltaLF[i] + reduced*delta_lf_res, -63, 63)`, looped over 4 planes
64+if `delta_lf_multi` else just index 0 against the single `delta_lf_cdf`.
65+
66+### The gating condition (decodemv.c:94-95, :121-122) -- **not** a spec
67+`ReadDeltas` global, libaom computes it locally per call:
68+```c
69+read_delta_q_flag = (mi_col & (mib_size-1) == 0 && mi_row & (mib_size-1) == 0);
70+if ((bsize != sb_size || !skip) && read_delta_q_flag) { ...read... }
71+```
72+Both conditions collapse to: **the very first block decoded inside a
73+superblock always has this MI position** (partition trees decode top-left
74+leaf first, always), so a per-SB `Cell<bool>` reset exactly like
75+`CDEF_TRANSMITTED` (decode.rs ~82, reset alongside it at the top of both
76+tile loops' `sb_c` loop bodies) replaces the position check with no
77+behavioural difference. The remaining condition, "skip the read entirely
78+(state carries over unchanged)", fires only when this first block **is
79+itself the whole superblock** (`bsize == sb_size`) **and** `skip == true`.
80+
81+### Call sites -- only 4, not the dozen it looks like
82+`maybe_read_cdef_idx` (decode.rs:115) is called from exactly 4 places,
83+right after each one's own `skip` read, and delta_q/delta_lf's spec order
84+is `skip -> cdef -> delta_q -> delta_lf` (already commented at decode.rs
85+~2474: "spec order... `cdef` lands right here" -- delta lands right after
86+that same line, one function per call site):
87+- `read_intra_mode_rect` (decode.rs:1987, feeds `decode_block_rect`) --
88+ `bw`/`bh` never both 64 here (SB-level partition never recurses to a rect
89+ strip directly), so `is_whole_sb` is always `false`.
90+- `read_intra_mode` (decode.rs:2447, feeds `decode_block`/`decode_leaf8`) --
91+ has a `side: usize` param; `is_whole_sb = side == 64`.
92+- `decode_inter_block` (decode.rs:6344) -- has `side: usize`; same rule.
93+- `decode_inter_block8` (decode.rs:8215) -- always sub-8x8, `is_whole_sb`
94+ always `false`.
95+
96+### Threading `CurrentQIndex` into dequant -- narrower than it looks
97+`base_q_idx: u8` is already threaded as a plain pass-through parameter
98+through every one of these functions down to exactly 2 real use sites
99+(confirmed by grep -- `base_q_idx` appears 92x in decode.rs but is *read*,
100+not just passed, only at decode.rs:2986 and :5397, both
101+`dequant_and_inverse_typed(..., i32::from(base_q_idx), ...)`). This means
102+the running quantizer state does **not** need a new parameter threaded
103+through every block/leaf/rect function signature: a `thread_local!
104+static CURRENT_Q_IDX: Cell<i32>`, reset to `base_q_idx as i32` at the top
105+of both `decode_key_frame_tile_with_cdfs`/`decode_inter_frame_tile_with_cdfs`
106+(same place `CDEF_BITS`/`CDEF_SB_COLS` already get set per tile), mutated
107+only inside the new `maybe_read_delta_q_lf` helper, and read back at the 2
108+dequant call sites instead of `i32::from(base_q_idx)`, reproduces the exact
109+running-state semantics with no signature changes to the block readers.
110+`DeltaLF` needs the same `Cell<[i32; 4]>` treatment, but **does** need a
111+consumer: `lf_level`/`edge_params` (decode.rs:3991/4020) currently read
112+only the frame-level `LoopFilterParams.level` array -- applying `DeltaLF`
113+there needs `MiGrid`/`fill_lf_grid` (decode.rs:1444) to carry a per-block
114+delta value forward to the deblocker, which is genuinely new state, not a
115+narrow substitution like q_idx. This is the part of Job 2 that needs a
116+real design pass, not just wiring -- flag it to whoever picks this up next.
117+
118+### Header threading + refusal removal
119+`header.delta.{q_present,q_res,lf_present,lf_res,lf_multi}`
120+(`ec_av1_syntax::frame::DeltaParams`, already parsed) need to become new
121+parameters on `decode_key_frame_tile_with_cdfs`/`_inter_..._with_cdfs` (and
122+their public non-`_with_cdfs` wrappers, and `stream.rs`'s 2 call sites),
123+mirroring how `CdefParams`/`LoopFilterParams` are already threaded. Then
124+delete the `stream.rs:170-174` refusal
125+(`"a frame with delta_q_present or delta_lf_present set..."`).
126+
127+### Gate
128+Reproducible refusal fixture already on file (r2's note): `--aq-mode=1` or
129+default `cpu-used>=1` at 128x64+. Same shape as the CDEF gate (128x64,
130+2 SBs, `--threads=1 --row-mt=0`), with a hard-asserted firing counter
131+(`DELTA_Q_HITS`/`DELTA_LF_HITS`, same `Cell<usize>` pattern as
132+`CDEF_IDX_HITS`).
133+
134+## Remaining refusal strings verbatim (all pre-existing, untouched by this
135+lane except the one new one above)
136+- `"a partition type this encoder never writes"` (decode.rs, intra SB
137+ level, key frame catchall) -- pre-existing, real, out of scope.
138+- `"a partition type this encoder never writes (value={part32})"` -- pre-existing.
139+- `"an INTER 32x32 partition type this encoder never writes (value={part32})"` -- pre-existing.
140+- `"a frame with delta_q_present or delta_lf_present set (this decoder
141+ never reads the per-superblock delta symbols)"` -- Job 2's target,
142+ **still present, still refuses correctly** (not touched this round).
143+- `"an inter SB-level partition type other than SPLIT (this decoder's
144+ inter tile path only recurses a superblock as SPLIT)"` -- **new this
145+ lane**, Job 1.
146+
147+## Merge note
148+`gate_coverage.rs`/`refusal_inventory.rs` (main-only guards this worktree
149+doesn't have) need the one new refusal string above added at merge; nothing
150+to delete from `gate_coverage.rs` this round since no gate closed a tool
151+entry (Job 1 has no gate by design, see above).
152+
153+## Next lever
154+Job 2 exactly as scoped above. The `DeltaLF`-into-deblocker sub-problem
155+(new `MiGrid` state, not a narrow substitution) is the one piece that needs
156+design before code -- everything else (CDFs, read logic, call sites,
157+`CURRENT_Q_IDX` substitution, header threading, refusal removal, gate
158+recipe) is now a direct port, not an investigation.