forge
Explore
Log in

Don't you dare go Hollow

lanes/av1seglvl: record census verdict, map-inheritance fix, witness gates; suite staged for server

Browse files at this commit

2700457b7528910d3d22a2c1a0b588c270626580Ahmet Kaan GümüşParent: 587b6a0
lanes/av1seglvl.report.mdadded+170 -0
@@ -0,0 +1,170 @@
1+# lane-av1-seglvl — the segmentation mode-override refusal: census, the map-inheritance fix, and the reaching stream
2+
3+Base: `main` **73f3ac64** (2026-09-24). Worktree `edith_codecs-av1seg`, branch
4+`lane-av1-seglvl`, lane commit **5a96bff9**,
5+`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1seg` (private). No push.
6+Region: `decode.rs`'s segment-id/map block (`inter_segment_id`), the
7+`stream.rs` segmentation refusal + census gates, and the inventory entry that
8+pins them. Sibling lanes' block-decoder regions untouched.
9+
10+## TL;DR
11+
12+- **Census (re-scoped):** over 11 real-aomenc recipes — 1-pass, alt-ref-lag
13+ (`--lag-in-frames=16 --auto-alt-ref=1`), and a **genuine two-pass** encode,
14+ `--aq-mode=1/2/3`, cq 10/40/45/63, screen (`testsrc2`) and film
15+ (`mandelbrot`) sources — **every frame header parsed**: aomenc enables
16+ `SEG_LVL_ALT_Q` and nothing else. 162 seg-enabled frames in the lag/two-pass
17+ arms alone, zero instances of any other `SEG_LVL` feature. The refusal
18+ **stays, by name, unchanged** (`a frame whose segmentation enables
19+ SEG_LVL_REF_FRAME/SKIP/GLOBALMV ...`).
20+- **The "reachability is nil" claim survived the census but its old PROOF did
21+ not:** the stale comment cited only "CLI exposes no ROI/active-map flag".
22+ The full answer has three legs (§1), the load-bearing one being that
23+ `configure_static_seg_features` (`encoder_utils.c:315`) — the ONLY setter of
24+ `SEG_LVL_ALT_LF_*`/`REF_FRAME`/`SKIP` in the tree — is gated on
25+ `hl_sf.static_segmentation`, which libaom's own `speed_features.h` documents
26+ as **"Always set to 0"**, AND on the second pass (`encoder_utils.c:738`).
27+- **One real defect found and fixed** on the way: `update_map == 0` frames
28+ inherited the previous segment map through the MINIFIED block id, flattening
29+ heterogeneous footprints. libaom (`copy_segment_id`, `decodemv.c:342`)
30+ copies the previous map **verbatim** and hands the block only the min. Fixed
31+ bug-for-bug; witness stream now byte-exact (§2/§3).
32+
33+Inventory delta: none (strings unchanged); the PROVEN entry's comment now
34+carries the corrected evidence and the new witness gate name.
35+
36+## 1. Census: which SEG_LVL features does aomenc actually emit?
37+
38+Instrument: not the refusal — the refusal is blind to a pure-`ALT_LF` stream,
39+which would decode silently past it. `segmentation_feature_census` (new,
40+`stream.rs`) parses every frame OBU and tallies `feature_enabled` per
41+segment-feature instance, alongside the shape counters the premise asserts on
42+(`update_map == 1` map-coding frames, `update_map == 0` map-inheriting
43+frames, `ALT_Q`-carrying frames).
44+
45+Arms (`a_segmentation_census_over_real_aq_streams_finds_no_mode_overriding_feature`,
46+re-scoped in place):
47+
48+- r27's six 1-pass no-lag recipes (kept verbatim: baseline, `--aq-mode=1/2/3`,
49+ `--aq-mode=3 cq10`, `--deltaq-mode=1` over mandelbrot 192x128);
50+- four alt-ref-lag arms: `--aq-mode=1 cq45` over mandelbrot AND testsrc2
51+ 256x192, `--aq-mode=1 cq63` (the `high_q = avg_q > 48` regime of the
52+ static-seg branch), `--aq-mode=2 cq45` — 40 frames each;
53+- one **two-pass** arm (`--passes=2 --pass=1/--pass=2 --fpf=...`,
54+ `--aq-mode=1 cq45 lag16`): `configure_static_seg_features` runs ONLY at
55+ `is_stat_consumption_stage_twopass`, so this arm covers the encoder surface
56+ that would expose the branch if its speed feature were ever revived.
57+
58+Verdict: `SEG_LVL_ALT_Q` only — e.g. `aq-mode=1 lag16 mandelbrot`: 40/40
59+frames seg-enabled, 7 map-coding, 33 inheriting, 12 with `ALT_Q` tables,
60+per-feature `[96, 0, 0, 0, 0, 0, 0, 0]`; twopass arm `[80, 0, ...]`. All
61+non-`ALT_Q` counts asserted zero.
62+
63+Source-side proof that the other seven features have no CLI path
64+(`stream.rs` refusal comment + inventory, all sites read in the oracle tree
65+`~/.cache/aom-oracle/src`, libaom v3.13.3):
66+
67+1. AQ modules clear the table then set `SEG_LVL_ALT_Q` only
68+ (`aq_variance.c:61` clear + `:89` enable, `aq_complexity.c:74` + `:118`,
69+ `aq_cyclicrefresh.c:616` + `:630`).
70+2. `configure_static_seg_features` (`encoder_utils.c:315`) — sets seg-1
71+ `ALT_Q + ALT_LF_*(-2)` on arfs and `REF_FRAME(ALTREF)` (+`SKIP` when
72+ `high_q`) on `is_src_frame_alt_ref` overlays — runs only under
73+ `is_stat_consumption_stage_twopass(cpi) && cpi->sf.hl_sf.static_segmentation`
74+ (`encoder_utils.c:738-740`); `static_segmentation` has **zero assignments
75+ in the tree** and is documented "Always set to 0" (`speed_features.h:436`).
76+ Dead code in v3.13.3, upstream-confirmed.
77+3. `av1_apply_roi_map` / `av1_apply_active_map` (the `REF_FRAME`/`SKIP`
78+ library paths) are control-API only; `aomenc.c` exposes no flag for either
79+ (checked this round).
80+
81+`SEG_LVL_GLOBALMV` additionally has **no setter anywhere in the encoder** —
82+it stays refused with no caveat.
83+
84+## 2. The defect: map inheritance flattened mixed footprints
85+
86+The census's richest arm (`--aq-mode=1 lag16`) decoded 2 luma bytes wrong on
87+film content: mandelbrot 192x128, 40 frames, **frame 35, Y px (75,81) and
88+(74,86)** — one 8x8 block at mi (18..19, 20..21), everything else exact vs
89+ffmpeg. Stage bisect (`EC_AV1_PREFILT_DUMP`): the divergence exists at
90+RECONSTRUCTION — prediction/dequant, not a filter decision. The paired
91+`EC_TRACE_SEG` ladders (ours and the oracle's instrumented aomdec, 386 coded
92+ids) were **line-identical** — every CODED id matched. The divergence had to
93+be in the ids nobody codes: the `update_map == 0` inheritance.
94+
95+libaom (`decodemv.c:386-390`), on such a block:
96+
97+- `copy_segment_id` (`:342`) **memcpys** the previous map over the block's own
98+ footprint — mixed ids intact;
99+- the id the BLOCK carries is `get_predicted_segment_id` = **min** over that
100+ footprint (`dec_get_segment_id`, `:307`).
101+
102+Our port did one step: `write_segment_id(min)`, stamping the min over the
103+footprint. Any block wider than 1 mi sitting on a heterogeneous patch of the
104+previous map (exactly what an arf full of 1:4 splits leaves) flattened the
105+saved map; every later inheriting frame or temporal prediction that read that
106+position got the wrong segment id → wrong `SEG_LVL_ALT_Q` delta → wrong
107+dequant. 2 pixels, frames away from the cause (class
108+`simplified-inheritance`).
109+
110+Fix (`decode.rs`, lane commit 5a96bff9): `copy_segment_ids` — the verbatim
111+per-cell copy — plus the min only as the block's own id; map writes on the
112+coded/temporal paths are untouched (`set_segment_id` semantics, already
113+correct there). `av1_get_qindex` parity re-verified while there
114+(`quant_common.c:222`: `clamp(base + data, 0, MAXQ)` — our `block_q_idx`
115+identical; libaom applies it per block in `parse_decode_block`, values equal
116+at every dequant site).
117+
118+## 3. Proof
119+
120+- **Fail-pre-fix (single mutation, scratch archive of 5a96bff9, only the
121+ `copy_segment_ids` call reverted to the min-stamp):**
122+ `a_real_aomenc_segmentation_stream_with_map_inheritance_decodes_pixel_exact`
123+ FAILS with `film mandelbrot: decode-order frame 35 of 40 (40 shown, 0
124+ hidden) differs from the oracle at byte 15627 (ours 132 vs 43), 2 bytes
125+ differ` — the gate reproduces the exact defect unaided.
126+- **Post-fix:** same gate green on both arms — screen testsrc2: 41 frames
127+ decode-order byte-exact vs the instrumented oracle (1 hidden), 40 shown
128+ frames pixel-exact vs ffmpeg, q span 48..189, 308 segment symbols; film
129+ mandelbrot: 40/40 exact, q span 60..202, 386 symbols. Premise asserts:
130+ `enabled > 0 && umap > 0`, `inherited > 0`, `alt_q > 0`,
131+ `segment_id_hits > 0`, `block_q_span.hi > lo`.
132+- Determinism: the lag stream re-encodes byte-identical across runs
133+ (`mand_r1.obu == mand_r2.obu`, sha256 `76ece5d2...`); screen arm sha256
134+ `2b0548e9...`.
135+
136+## 4. Gates
137+
138+- **NEW witness:** `a_real_aomenc_segmentation_stream_with_map_inheritance_decodes_pixel_exact`
139+ (the reaching stream: segmentation on every frame + real alt-ref groups +
140+ 33-34 inheriting frames per arm; every decode-order frame vs oracle,
141+ every shown frame vs ffmpeg).
142+- **RE-SCOPED census:** `a_segmentation_census_over_real_aq_streams_finds_no_mode_overriding_feature`
143+ — r27's six arms kept, four lag arms + one two-pass arm added, instrument
144+ upgraded from refusal-fires to header-parse tally, verdict asserted per
145+ feature.
146+- **KEPT unchanged:** `a_frame_whose_segmentation_overrides_a_block_mode_is_refused_by_name`
147+ (the hand-written header sweep over all three features x segments 0/3/7 —
148+ still the proof the refusal fires on conformant streams).
149+- **Regression arms run green** post-fix: `a_real_libaom_monochrome_key_frame_decodes_pixel_exact`
150+ (mono), `a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact`
151+ + `a_real_film_key_frame_with_a_skipped_cfl_block_decodes_pixel_exact`
152+ (reelb_*/reelc 10-bit fixtures), `a_non_420_subsampled_sequence_header_is_refused_by_name`
153+ (444 refused), `a_frame_using_quantisation_matrices_is_refused_by_name`
154+ (qmatrix refused), `a_real_aomenc_stream_with_cdf_update_disabled_decodes_pixel_exact`
155+ + `a_real_aomenc_inter_sequence_with_cdf_forwarding_decodes_pixel_exact`
156+ (cdf exact), `a_coded_rect_intrabc_block_reconstructs_in_both_orientations`
157+ + `an_sb128_screen_stream_with_intrabc_decodes_pixel_exact` (the cq50/cq45
158+ screen families), `a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name`
159+ (aq-mode cq0 refusal, still fires).
160+
161+## 5. Suite + deferred
162+
163+- Full suite (`cargo test -p ec-av1 --lib -- --test-threads=1`,
164+ EC_AV1_REQUIRE_AOMENC/FFMPEG=1) runs on the server per the batch standing
165+ order, staged by Main from this commit (5a96bff9, tree clean except the
166+ gitignored `assets` symlink); the literal final line is recorded in the
167+ merge ticket. The batch's targeted regression arms (§4) all ran green
168+ locally, as did the three lane gates and the fail-pre-fix run (§3).
169+- `deferred(aomenc has no recipe; unblock = an encoder that emits seg SKIP/REF on intra-only frames — needs a per-segment skip guard on the intra-frame path, where libaom's own read has a stale-segment-id wrinkle worth a look first)`: SEG_LVL_SKIP/REF on INTRA-only frames is not applied on our intra path. aomenc never emits it (features are cleared on key frames, `configure_static_seg_features:334-344`; ROI/active-map gate `!frame_is_intra_only`/`frame_is_intra_only`), and the stream-level refusal is being lifted for none of it — GLOBALMV frames still refuse wholesale. No stream in the suite can reach the shape.
170+- `deferred(no decoder-side effect found; unblock = a census arm that catches configure_static_seg_features going live — the two-pass arm + parse tally in the re-scoped census is that tripwire)`: the arf `ALT_LF(-2)` tables and overlay `REF_FRAME/SKIP` tables cannot reach a stream while `static_segmentation` stays 0. The deblocker's per-segment `ALT_LF` port (`decode.rs`, lane-seg) is in place but stays unwitnessed by a real stream for the same reason.