forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-b128res' (86ac0f65): the 128 residual arm re-measures three-way exact after edge128's CDEF owner map; still inert at 0.4-1.9 writer fires/frame so EC_AV1_B128RES stays off; pan residual witness re-vitalizes at q=60

Browse files at this commit

8fbaba433cb8c124a947dc85b10b7336e34ed1f0Ahmet Kaan GümüşParent: 4b37b0c329dee9
crates/ec-av1/src/encode.rsmodified+30 -17
@@ -738,22 +738,23 @@ fn b128_root() -> bool {
738738 /// pair per 64x64 mu chunk, var-tx depth 0 (the shape
739739 /// [`crate::tile::write_inter_block_128`] codes and `decode_inter_block`
740740 /// reads). Written, witnessed and byte-exact through both decoders, and
741-/// **off by default** (`EC_AV1_B128RES=1` turns it on) for two measured
742-/// reasons:
741+/// **off by default** (`EC_AV1_B128RES=1` turns it on) because it is INERT
742+/// on content: the RD takes it 0.7-1.9 times per frame against thousands of
743+/// whole 128 roots (lane-b128res census, native 12-frame gate, every clip),
744+/// and the BD effect is inside the noise on both gates -- long-GOP films
745+/// -0.1/+0.1 and all five 12-frame rows within 0.1 of the off default.
743746 ///
744-/// * it is INERT on content: over the native 12-frame gate the RD takes it
745-/// 0-2 times per frame against ~90 whole 128 roots, so the BD effect is
746-/// inside the noise either way;
747-/// * with it on, `bd_rate_screen_native`'s bars 2160p row q=90 frame 11
748-/// reads 8 luma samples (rows 126..127, cols 1611..1616 -- the two rows
749-/// above a 128-superblock horizontal edge) where ffmpeg and this
750-/// encoder's own reconstruction disagree. The residual arm's own witness
751-/// clip is byte-exact through ffmpeg over 420 forced blocks at 1280x768,
752-/// so the open half is a FILTER-stage interaction (deblock/CDEF at a 128
753-/// block's own edge), not the coefficient path.
754-///
755-/// An inert candidate does not buy a live filter mismatch, so the default
756-/// stays off until that is root-caused; the knob is the gate for it.
747+/// The historical reason for the parking is CLOSED: the bars 2160p q=90
748+/// frame 11 disagreement with ffmpeg (8 luma samples at the rows above a
749+/// 128-superblock horizontal edge) was the CDEF search pricing a preset per
750+/// 64x64 unit under a root that codes ONE literal for all four -- lane-
751+/// edge128's `crate::tile::cdef_unit_owner` collapses the four to the one
752+/// the decoder derives, and on this HEAD the same row re-measures three-way
753+/// EXACT (encoder reconstruction == ffmpeg == `decode_stream`, every frame,
754+/// every plane, both gates). The knob stays as the arm's gate, not as a
755+/// defect flag; the residual arm is also what
756+/// [`crate::tile::write_inter_block_128_rect`]'s skip-only halves would
757+/// share if they ever carry one.
757758 fn b128_residual() -> bool {
758759 static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| {
759760 crate::envflags::var("EC_AV1_B128RES").ok().map(|v| v != "0")
@@ -17095,6 +17096,15 @@ mod tests {
1709517096 /// `skip = true` for a block that carries a residual -- the next root's
1709617097 /// `skip` symbol then took CDF row 1 where the reader takes row 0.
1709717098 ///
17099+ /// lane-b128res: the fixture's q moved 150 -> 60. The forced arm replaces
17100+ /// the skip arm's cost unconditionally (that is what makes the writer see
17101+ /// the residual), and the cost model moved under it since lane-b128r --
17102+ /// lane-rectdq made every non-skipped root pay its delta_q group and the
17103+ /// pyramid re-prices the leaves -- so at q=150, then q=90, the NONE root
17104+ /// lost its partition at ALL 420 roots and the writer coded none. q=60
17105+ /// puts 52 written blocks back on this clip; the `coded > 0` assert below
17106+ /// is the guard that catches the next such drift.
17107+ ///
1709817108 /// cargo test -p ec-av1 --release --lib -- --ignored \
1709917109 /// a_128_root_block_with_a_real_residual --nocapture
1710017110 #[test]
@@ -17125,7 +17135,7 @@ mod tests {
1712517135 let _ = take_b128_residual_hits();
1712617136 let _ = crate::tile::take_sb128_residual_hits();
1712717137 force_b128_residual(true);
17128- let encoded = encode_sequence(&pictures, 150, 0.5).unwrap();
17138+ let encoded = encode_sequence(&pictures, 60, 0.5).unwrap();
1712917139 let (won, coded) =
1713017140 (take_b128_residual_hits(), crate::tile::take_sb128_residual_hits());
1713117141 eprintln!("128x128 blocks WITH a residual: search won {won}, writer coded {coded}");
@@ -20239,9 +20249,12 @@ mod tests {
2023920249 100.0 * i64_whole as f64 / i64_offered.max(1) as f64,
2024020250 );
2024120251 eprintln!(
20242- "{name}: 128x128 roots {} (search) / {} (writer)",
20252+ "{name}: 128x128 roots {} (search) / {} (writer), with a residual \
20253+ {} (search) / {} (writer)",
2024320254 take_b128_none_hits(),
2024420255 crate::tile::take_sb128_none_hits(),
20256+ take_b128_residual_hits(),
20257+ crate::tile::take_sb128_residual_hits(),
2024520258 );
2024620259 eprintln!(
2024720260 "{name}: 64x64 roots {} (with a residual {}, split luma {}, compound {})",
lanes/b128res.charter.mdadded+70 -0
@@ -0,0 +1,70 @@
1+# lane-b128res — re-measure the parked 128 residual arm after edge128
2+
3+GOAL: `EC_AV1_B128RES` is written, witnessed, and OFF because (1) RD took it
4+0-2 times/frame (inert) and (2) bars 2160p q=90 frame 11 disagreed with
5+ffmpeg by 8 luma samples at a 128 block's horizontal edge. lane-edge128
6+claimed that mismatch was CDEF search pricing four indices under a root
7+that carries one literal, fixed with an owner map. This lane decides
8+whether the residual arm can ship.
9+
10+Work ONLY in this worktree (`lane-b128res`). Never touch main, never
11+push, never `git checkout <file>`, never repo-wide `cargo fmt`.
12+`export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-b128res` on every cargo
13+command. Logs under `~/.cache/b128res/`. TMPDIR only on gate command
14+lines, not on the sccache server. Gates: `systemd-run --user -p MemoryMax=14G`,
15+`--ignored --exact` on both BD tests (they are `#[ignore]`; without
16+`--ignored` they measure nothing). One gate at a time; record LOADAVG
17+before AND after. Pins 8291 / 33227. Keep rule: one film row ≥0.5 BD
18+down on a column, the other flat within ±0.3, screen not worse by 0.3,
19+wall ≤+15%. Sign: BD-rate, lower better.
20+
21+## 1. Refute or confirm the 8-sample mismatch (do this FIRST)
22+
23+Recipe: the native bars 2160p row, `EC_AV1_B128RES=1`, q=90, the frame
24+and rows named in `encode.rs` `b128_residual` (frame 11, luma rows
25+126..127, cols 1611..1616). Compare encoder reconstruction vs ffmpeg vs
26+`decode_stream`. Cite the command.
27+
28+- If the 8 samples are STILL wrong: STOP. Do not ship. Report the
29+ remaining mismatch (class, path:line). Leave the default off.
30+- If they are gone: continue.
31+
32+INVARIANT from lane-ab128: a skip-only 128-wide piece writes no
33+`cdef_idx`. `cdef_unit_owner` currently only special-cases `Whole128`.
34+The residual arm IS Whole128. Do not extend the owner map to Rect128/Ab128
35+in this lane unless you turn those pieces into residual carriers — that
36+is a different lane.
37+
38+## 2. If the mismatch is gone: measure
39+
40+Control = default (B128RES off) on this HEAD. Arm = `EC_AV1_B128RES=1`.
41+
42+- `cargo test -p ec-av1 --release --lib -- --ignored --exact --nocapture encode::tests::bd_rate_film_long_gop`
43+ (deciding). Both films.
44+- 12-frame guard: `encode::tests::bd_rate_screen_native` with
45+ `EC_AV1_NATIVE_FILM=1` then `EC_AV1_NATIVE_FILM4K=1` then the screen
46+ arm, or however the standing table ran them — all five 12-frame rows.
47+- Residual fire count: `take_b128_residual_hits` / writer
48+ `take_sb128_residual_hits` on the long-GOP arm. If still 0-2/frame,
49+ it is still inert even if exact.
50+
51+Keep → default ON (and drop the "filter mismatch" paragraph). Inert +
52+exact → leave OFF, but rewrite the comment so it no longer names an
53+open filter bug. Mismatch remains → OFF, report.
54+
55+## 3. Witness / pins / suite (only if you change the default)
56+
57+Pins at default and `EC_AV1_SPEED=6`. Existing residual witnesses
58+(`a_128_root_block_with_a_real_residual_decodes_exact_through_both_decoders`
59+and the CDEF-covered-units one) `--ignored`. Workspace check
60+`timeout 900 cargo check --workspace --all-targets -j4` (0 ec-av1
61+warnings). Do NOT run the full lib suite unless you change the default;
62+if you do, three lanes: `--skip stream::` / `stream:: --skip 10bit` /
63+`10bit`.
64+
65+## DONE
66+
67+Commit on `lane-b128res` + `lanes/b128res.report.md` with EVIDENCE lines
68+(`EVIDENCE: <artifact> | <steps> | <measurement>`), fire counts, BD
69+table, mismatch gone/still, disposition `ships-on | stays-off | stopped`.
70+Never merge or push.
lanes/b128res.report.mdadded+144 -0
@@ -0,0 +1,144 @@
1+# lane-b128res — the parked 128 residual arm after edge128
2+
3+Base: `6de54e81` (lane-b128res worktree). Disposition: **stays-off**.
4+`EC_AV1_B128RES` keeps its default (off). Pins untouched at 8291 / 33227
5+(no default change, so no pin run). Never merged, never pushed.
6+
7+## 1. The 8-sample mismatch: GONE
8+
9+lane-edge128's diagnosis was right: `read_cdef` codes ONE literal for the
10+block that first reaches a unit and copies it over every unit the block
11+spans, while the encoder's CDEF search priced a preset per 64x64 unit —
12+`crate::tile::cdef_unit_owner` (tile.rs) collapses the four to the one the
13+decoder derives. On this HEAD the parked recipe re-measures clean:
14+
15+- Command: `systemd-run --user -p MemoryMax=14G --wait --unit=b128res-probe
16+ bash -lc 'cd <worktree> && CARGO_TARGET_DIR=$HOME/.cache/cargo-target-b128res
17+ EC_AV1_B128RES=1 cargo test -p ec-av1 --release --lib --
18+ encode::tests::b128res_mismatch_probe --ignored --exact --nocapture'`
19+ (throwaway probe, removed after the run; recipe = the gate's own:
20+ bars 2160p fixture, `gate_crop` window 1920x1024:960:568, 12 frames,
21+ `encode_sequence_with_ctx(…, 90, …)`).
22+- frame 11 q=90, luma rows 126..127 cols 1611..1616 (idx 243531..243536,
23+ 245451..245456): encoder reconstruction == ffmpeg == decode_stream, all
24+ eight samples read 107. Whole stream (12 frames, Y/U/V): three-way EXACT.
25+- Broader: with `EC_AV1_B128RES=1` BOTH BD gates passed their standing
26+ three-way exactness assertion (encoder == ffmpeg == decode_stream) at
27+ every clip x every q point x every frame — 5 clips x 4 q x 12 frames and
28+ 2 films x 4 q x 48 frames.
29+
30+EVIDENCE: ~/.cache/b128res/probe-mismatch.log | EC_AV1_B128RES=1, q=90,
31+frame 11, rows 126..127 cols 1611..1616 + whole-stream sweep | 8/8 samples
32+agree (all 107); 0 differing samples in any plane/frame; "whole stream
33+three-way EXACT". LOADAVG 1.96/2.43/3.42 before, 2.44/2.51/3.41 after.
34+
35+## 2. Long-GOP BD (deciding; 48 pictures, gop=48, both films)
36+
37+Control = default (off), arm = `EC_AV1_B128RES=1`, same HEAD, same ladder
38+(`encode::tests::bd_rate_film_long_gop`, `--ignored --exact`). BD-rate,
39+lower better:
40+
41+| row | off vs libaom | off vs rav1e | on vs libaom | on vs rav1e |
42+|---|---|---|---|---|
43+| film A (1080p) 1920x768 | +20.9% | -9.0% | +20.8% | -9.1% |
44+| film B (2160p HDR) 1920x1024 | +70.4% | -2.2% | +70.5% | -2.1% |
45+
46+Wall ours: film A 542.3s -> 549.8s (+1.4%), film B 422.9s -> 445.5s (+5.3%).
47+Control reproduces the standing table (film B +70.4/-2.2) to the digit.
48+
49+EVIDENCE: ~/.cache/b128res/longgop-control.log | gate 2a, MemoryMax=14G |
50+film A +20.9%/-9.0%, film B +70.4%/-2.2%. LOADAVG 2.64/2.57/3.07 before,
51+3.44/2.79/2.76 after.
52+EVIDENCE: ~/.cache/b128res/longgop-arm.log | gate 2b, EC_AV1_B128RES=1,
53+MemoryMax=14G | film A +20.8%/-9.1%, film B +70.5%/-2.1%. LOADAVG
54+3.35/2.80/2.76 before, 3.07/3.53/3.19 after.
55+
56+## 3. 12-frame native guard (all five rows)
57+
58+`encode::tests::bd_rate_screen_native`, control and arm:
59+
60+| row | off vs libaom | off vs rav1e | on vs libaom | on vs rav1e | wall ours off->on |
61+|---|---|---|---|---|---|
62+| bars 1080p | -3.3% | -19.0% | -3.4% | -18.9% | 160.4s -> 164.4s |
63+| bars 2160p | +8.4% | -13.9% | +8.4% | -13.9% | 137.1s -> 143.7s |
64+| film A | +17.9% | -6.3% | +17.8% | -6.4% | 144.2s -> 145.0s |
65+| film B | +22.6% | -3.8% | +22.6% | -3.8% | 122.8s -> 123.8s |
66+| screen capture | +14.4% | -33.2% | +14.5% | -33.2% | 94.9s -> 94.3s |
67+
68+EVIDENCE: ~/.cache/b128res/native12-control.log | gate 3a, five rows,
69+MemoryMax=14G | table above, "off" columns. LOADAVG 2.38/3.32/3.13 before,
70+3.63/3.57/3.34 after.
71+EVIDENCE: ~/.cache/b128res/native12-arm.log | gate 3b, five rows,
72+EC_AV1_B128RES=1, MemoryMax=14G | table above, "on" columns; three-way
73+sample exactness held at every point. LOADAVG 3.42/3.53/3.33 before,
74+3.32/3.23/3.27 after.
75+
76+## 4. Residual fire counts (writer `take_sb128_residual_hits`)
77+
78+Per clip, cumulative over the run's four-q ladder (12-frame rows: 48
79+encoded frames; long-GOP rows: 192):
80+
81+| clip (frames encoded) | search won | writer coded | per frame |
82+|---|---|---|---|
83+| bars 1080p (48) | 1567 | 63 | 1.3 |
84+| bars 2160p (48) | 985 | 32 | 0.7 |
85+| film A 12f (48) | 2331 | 92 | 1.9 |
86+| film B 12f (48) | 1797 | 47 | 1.0 |
87+| screen capture (48) | 307 | 61 | 1.3 |
88+| film A long-GOP (192) | 10205 | 320 | 1.7 |
89+| film B long-GOP (192) | 6056 | 75 | 0.4 |
90+
91+0.4-1.9 fires/frame against thousands of whole 128 roots — still INERT,
92+exactly the historical 0-2 band. The census is now a permanent line of the
93+native arm ("128x128 roots … with a residual … (search) / … (writer)"), so
94+the next reader does not need a custom run.
95+
96+## 5. Keep rule — NOT met
97+
98+One film row >=0.5 BD down on a column: best delta anywhere is -0.1
99+(film A long-GOP and 12-frame). Other film row flat within +/-0.3: yes
100+(+0.1). Screen not worse by 0.3: yes (+0.1). Wall <= +15%: yes (max +5.3%).
101+The deciding column fails, and the arm is inert. Inert + exact = the
102+charter's stays-off branch.
103+
104+## 6. Witnesses (both `--ignored`, run standalone)
105+
106+- `a_128_root_residual_block_under_a_per_unit_cdef_list_decodes_exact`:
107+ PASS as-is — writer coded 566 residual 128 blocks, 24 CDEF units taking
108+ another unit's literal, byte-exact through both decoders. This is the
109+ witness lane-edge128 built for the exact interaction that used to break
110+ bars 2160p.
111+EVIDENCE: ~/.cache/b128res/witness-cdef.log | --ignored --exact run |
112+"writer coded 566; covered 24", ok. LOADAVG 2.03/2.21/3.13 before,
113+2.72/2.36/3.15 after.
114+- `a_128_root_block_with_a_real_residual_decodes_exact_through_both_decoders`:
115+ was RED on its precondition at its fixture q (150: writer coded 0) and
116+ still at 90 — the forced residual arm replaces the skip arm's cost
117+ unconditionally, and the cost model moved under it since lane-b128r
118+ (lane-rectdq's delta_q group on every non-skipped root; the pyramid's
119+ per-level q), so the NONE root lost its partition at all 420 roots and
120+ nothing reached the writer. Fixture re-vitalized at q=60: writer coded
121+ 52, byte-exact through both decoders, PASS. q change + a doc paragraph
122+ naming the drift class are in the commit; the `coded > 0` assert stays
123+ as the guard.
124+EVIDENCE: ~/.cache/b128res/witness-residual.log (q=90, FAILED, writer 0),
125+witness-residual-q60.log (q=60, "search won 420, writer coded 52", ok).
126+
127+## 7. Changes on the lane
128+
129+- encode.rs `b128_residual` doc: the "open filter bug" paragraph is
130+ replaced by the closed story (owner map, re-measured three-way EXACT)
131+ and the inertness numbers; the knob stays as the arm's gate.
132+- encode.rs `native_bd_arm`: one census line added — residual fires
133+ (search/writer) next to the standing 128-root census.
134+- encode.rs pan residual witness: fixture q 150 -> 60 + drift note.
135+- Throwaway probe removed after its run.
136+
137+## 8. Non-goals respected
138+
139+Rect128/Ab128 residual pieces (a rect half carrying a residual still
140+refuses in `write_inter_block_128_rect`, owner map still Whole128-only),
141+merging, pushing, full workspace suite (default did not flip). Media files
142+read-only; all runs gated under `systemd-run --user -p MemoryMax=14G`, one
143+gate at a time, `--ignored --exact` on the ignored tests, logs under
144+`~/.cache/b128res/`.