forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-cen3' (79792051): matched-rate bit census of film B against libaom and rav1e; syntax_census takes EC_CENSUS_TABLES

Browse files at this commit

19e7ef8bd80646e5e4a2fcf58307f289ea83c5cbAhmet Kaan GümüşParent: abd9bdb1cb5cf6
crates/ec-av1/examples/syntax_census.rsmodified+9 -1
@@ -240,11 +240,19 @@ fn report(label: &str, f: &Frame, frames: usize) {
240240 }
241241 let mut tables: Vec<_> = f.families.iter().collect();
242242 tables.sort_by(|a, b| b.1 .1.total_cmp(&a.1 .1));
243+ // lane-cen3: how many tables the row names. The default 8 hides the
244+ // mode family's own split (a level can spend 40% of its bits on `mode`
245+ // with no mode table in its top 8), so a census that has to rank
246+ // per-table gaps between two encoders sets `EC_CENSUS_TABLES`.
247+ let top = std::env::var("EC_CENSUS_TABLES")
248+ .ok()
249+ .and_then(|v| v.parse().ok())
250+ .unwrap_or(8usize);
243251 println!(
244252 " top tables: {}",
245253 tables
246254 .iter()
247- .take(8)
255+ .take(top)
248256 .map(|(name, (_, bits))| format!("{name} {:.1}%", 100.0 * bits / total_bits.max(1.0)))
249257 .collect::<Vec<_>>()
250258 .join(" "),
lanes/cen3.report.mdadded+307 -0
@@ -0,0 +1,307 @@
1+# lane-cen3 — where film B's bytes go at MATCHED RATE, ours vs libaom vs rav1e
2+
3+Measurement lane: no encoder behaviour changed. One instrument added
4+(`EC_CENSUS_TABLES`, below). Every number is read by OUR decoder through
5+`EC_AV1_BITCENSUS=1 EC_CENSUS_PERFRAME=1 examples/syntax_census`, so all three
6+encoders are measured by the same reader; PSNR-Y is computed in that tool
7+against the very pixels the encoders were handed.
8+
9+Window: the native gate's own film B crop — `crop=1920:1024:960:292` at seek
10+`00:40:00` of the 2160p source, 8-bit 4:2:0, one tile, one thread, `gop =
11+frames`. Ours is `enc_probe <clip> gate 0 <frames> 150` (byte-exact with the
12+gate's `q=150` ladder point: 12 frames 27634 B, 48 frames 71601 B).
13+References are the gate's own ffmpeg recipes at a finer crf/quantizer grid, so
14+the comparison can be made at MATCHED BYTES rather than at the ladder's four
15+points. Artifacts: `$HOME/.cache/cen3/{12f,48f}` (streams, `cen-*.txt`
16+censuses, `parse.py`/`agg.py`/`perblock.py`/`modes.py`).
17+
18+## 0. The matched-rate points
19+
20+| window | stream | bytes | PSNR-Y | vs ours |
21+|---|---|---|---|---|
22+| 12 frames | **ours q150** | **27634** | **45.491** | — |
23+| 12 frames | libaom `cpu-used 6` crf 36 | 26923 | 46.033 | −2.6% bytes, **+0.54 dB** |
24+| 12 frames | rav1e `speed 6` q125 | 26688 | 45.563 | −3.4% bytes, +0.07 dB |
25+| 48 frames | **ours q150** | **71601** | **45.444** | — |
26+| 48 frames | libaom `cpu-used 6` crf 34 | 70345 | 46.539 | −1.8% bytes, **+1.10 dB** |
27+| 48 frames | rav1e `speed 6` q110 | 75452 | 45.751 | +5.4% bytes, +0.31 dB |
28+
29+Local slope of our own 48-frame ladder (q150 71601 B/45.444, q120 149971 B/
30+46.730): **1.21 dB per doubling**, i.e. +10% bytes = +0.166 dB. Every "bytes
31+→ dB" conversion below uses that number. The 1.10 dB deficit against libaom
32+over 48 pictures is therefore worth **+87% bytes at matched PSNR**, which
33+reproduces `libcen`'s +92% on the same window at the same recipe (our streams
34+have since got smaller: 90674 B → 71601 B at q150).
35+
36+## 1. Where the bytes go — whole stream, 48 frames, matched rate
37+
38+Family bytes (census, ±0.03% of payload on every stream):
39+
40+| family | ours | libaom crf34 | rav1e q110 | ours − libaom |
41+|---|---|---|---|---|
42+| coeff | 33016 | 36627 | 37460 | **−3611** |
43+| literal (raw coeff bits) | 10917 | 14231 | 13400 | **−3314** |
44+| **mode** | **15770** | **6592** | 12729 | **+9178** |
45+| mv | 7175 | 8720 | 8068 | **−1545** |
46+| partition | 2890 | 1807 | 2272 | +1083 |
47+| txsize | 322 | 127 | 0 | +195 |
48+| txtype | 255 | 995 | 67 | −740 |
49+
50+Read it in one line: **at the same total size we spend 9.2 kB more on mode
51+syntax and 6.9 kB less on actual residual than libaom does, and we are 1.10 dB
52+worse.** Signalling is eating the residual budget. rav1e sits between us.
53+
54+Split by frame type (the key is ONE frame in all three streams):
55+
56+| | ours | libaom | rav1e |
57+|---|---|---|---|
58+| key bytes / PSNR-Y / qindex | 15827 / **47.34** / 102 | 28803 / 47.05 / 41 | 20763 / **47.95** / 80 |
59+| inter bytes (47 frames) | 55774 | 41542 | 54689 |
60+| inter mean PSNR-Y | 45.40 | **46.53** | 45.70 |
61+
62+Our key frame is the cheapest of the three and beats libaom's by 0.29 dB at
63+55% of its bytes (`libcen` found the same on both films). **The entire gap is
64+inter: +34% bytes for −1.13 dB against libaom.** Inter families, ours −
65+libaom: mode **+8804 B**, coeff +5633 B, partition +1125 B, literal +627 B,
66+mv **−1545 B**.
67+
68+## 2. Per level, 48 frames, matched rate
69+
70+Ours (`8:-32:12:-8:-48` pyramid), by qindex:
71+
72+| level | n | q | bytes | share | B/frame | PSNR-Y | skip% | comp% | blocks/frame | mode b/blk | mv b/blk | coeff b/blk |
73+|---|---|---|---|---|---|---|---|---|---|---|---|---|
74+| top ARF (dist 8) | 6 | 118 | 38930 | 55.3% | 6488 | 45.75 | 59.9 | 22.3 | 2123 | 4.77 | 2.17 | 12.27 |
75+| key | 1 | 102 | 15827 | 22.5% | 15827 | 47.34 | 0.0 | 0.0 | 1479 | 5.66 | 0.00 | 57.69 |
76+| leaf | 35 | 162 | 8304 | 11.8% | 237 | 45.31 | 98.1 | 57.4 | 543 | 1.94 | 0.83 | 0.34 |
77+| mid ARF (dist 4) | 6 | 142 | 7377 | 10.5% | 1229 | 45.63 | 89.3 | 58.4 | 917 | 3.65 | 2.52 | 2.89 |
78+
79+libaom `cpu-used 6` crf 34 (top rows; 17 distinct qindex levels in all):
80+
81+| level | n | q | bytes | share | B/frame | PSNR-Y | skip% | blocks/frame | mode b/blk | mv b/blk | coeff b/blk |
82+|---|---|---|---|---|---|---|---|---|---|---|---|
83+| key | 1 | 41 | 28803 | 41.6% | 28803 | 47.05 | 0.0 | 1289 | 4.17 | 0.00 | 123.6 |
84+| ALTREF (hint ≈30) | 1 | 52 | 16885 | 24.4% | 16885 | **48.56** | 60.2 | 1529 | 4.22 | 4.91 | 55.2 |
85+| 2nd anchor | 1 | 104 | 5567 | 8.0% | 5567 | 47.38 | 72.8 | 996 | 3.88 | 7.54 | 22.0 |
86+| mid | 4 | 128 | 3113 | 4.5% | 778 | 46.14 | 90.7 | 478 | 3.27 | 4.47 | 2.84 |
87+| leaves | 22 | 136 | 2737 | 4.0% | **124** | **46.33** | 99.8 | **156** | 2.25 | 3.20 | 0.32 |
88+
89+rav1e `speed 6` q110:
90+
91+| level | n | q | bytes | share | B/frame | PSNR-Y | skip% | blocks/frame | mode b/blk | mv b/blk | coeff b/blk |
92+|---|---|---|---|---|---|---|---|---|---|---|---|
93+| key | 1 | 80 | 20763 | 28.0% | 20763 | 47.95 | 0.0 | 1266 | 5.23 | 0.00 | 92.6 |
94+| L1 ARF (dist 4) | 11 | 104 | 42590 | 57.5% | 3871 | 45.97 | 80.7 | 1507 | 3.23 | 2.17 | 10.59 |
95+| L2 (dist 2) | 12 | 122 | 6446 | 8.7% | 537 | 45.48 | 98.7 | 732 | 2.49 | 2.03 | 0.65 |
96+| leaves | 24 | 139 | 4290 | 5.8% | 178 | 45.69 | 99.8 | 528 | 1.57 | 0.84 | 0.09 |
97+
98+## 3. Ranked table — where our bytes go that they do not spend
99+
100+Bytes at the 48-frame matched point (71601 B ours). "dB equivalent" uses the
101+1.21 dB/doubling slope.
102+
103+| # | what | ours | libaom | gap | % of our stream | dB equiv |
104+|---|---|---|---|---|---|---|
105+| 1 | **per-block syntax (mode+partition+txsize)** driven by BLOCK COUNT: 38754 coded blocks vs 16178 | 18982 B | 8526 B | **+10456 B** | 14.6% | **0.24** |
106+| 2 | **inter coefficients** (excess residual left by weaker prediction) | 22350 B | 16717 B | +5633 B | 7.9% | 0.13 |
107+| 3 | partition alone (inside #1) | 2890 B | 1807 B | +1083 B | 1.5% | 0.03 |
108+| 4 | motion vectors — we spend LESS | 7175 B | 8720 B | **−1545 B** | −2.2% | — |
109+| 5 | tx_type — we spend LESS (set3/set6 only) | 255 B | 995 B | −740 B | −1.0% | — |
110+| 6 | `delta_q` (per-SB, libaom every inter frame; we code none) | 0 B | 254 B | −254 B | −0.4% | — |
111+
112+Where their PSNR is higher for the same bytes, by level: libaom's LEAVES cost
113+124 B/frame at 46.33 dB where ours cost 237 B/frame at 45.31 dB (**half the
114+bytes, +1.02 dB**), and libaom's whole 48-picture window never drops below
115+45.08 dB while ours falls monotonically from 47.34 to 45.31 (2.03 dB spread
116+against libaom's 47.05 → 46.33 = 0.72 dB).
117+
118+## 4. One level down on the top three families
119+
120+### 4a. mode — it is block COUNT, not per-block cost
121+
122+| | ours | libaom | rav1e |
123+|---|---|---|---|
124+| coded blocks (48 frames) | 38754 | **16178** | 39303 |
125+| mode bits per block | **3.26** | **3.26** | 2.59 |
126+| block sizes | 64x64 53.0%, 32x32 20.7%, 16x16 17.6%, 8x8 8.7%, **no 128** | **128x128 28.6%**, 32x32 28.1%, 64x64 19.5%, 16x16 16.9%, 8x8 1.8% | 64x64 52.0%, 32x32 20.9%, 16x16 20.2%, 8x8 6.9% |
127+| leaf-level blocks/frame | 543 | **156** | 528 |
128+| leaf blocks at 64x64+ | 85.5% | 89.0% | 88.8% |
129+
130+Our per-block mode cost is IDENTICAL to libaom's to two decimals — the 9.2 kB
131+mode gap is 2.4x the block count and nothing else. At the leaf level, where
132+the ratio is worst (543 vs 156 blocks a frame), **85.5% of our blocks are
133+already 64x64, the largest root our sequence header allows**
134+(`use_128x128_superblock = 0`): a 1920x1024 frame is 480 64-roots for us and
135+120 128-roots for libaom, and both encoders mostly code one block per root.
136+The only reachable mechanism for this gap is the 128 root. Top tables of our
137+leaf level confirm it is pure signalling: `mv_comp 18.3% comp_mode 14.7%
138+inter_compound_mode 10.6% new_mv 7.9% ref_mv 7.4% mv_joint 5.8% skip 5.5%
139+partition_w64 4.8%` — coefficients are 1.3% of a leaf's bits.
140+
141+### 4b. coeff — prediction, not quantisation
142+
143+Our inter coefficient excess (+5633 B) sits at the ARF level: 6 frames × 6488 B
144+with 59.9% skip area and 12.27 coeff bits/block. libaom holds **72.8% skip at
145+a reference distance of ~30 pictures** where ours is 59.9% at distance 8, and
146+its coefficient bits per block at every inter level are at or below ours. Our
147+residual spend per stream is already the LOWEST of the three (coeff+literal
148+43933 B vs libaom 50858 B, rav1e 50860 B) — RDOQ is not the gap; what we code
149+residual over is.
150+
151+### 4c. mv / modes — the same motion field coded three times less precisely
152+
153+| level pair | NEW% | NEAREST% | mv bits/block | mv \|max\| ≤32 | skip% |
154+|---|---|---|---|---|---|
155+| ours leaf q162 | **18.1** | 61.5 | 0.83 | 59.7% | 98.1 |
156+| libaom leaves q136 | **54.1** | 37.8 | **3.20** | 61.0% | 99.8 |
157+| ours mid ARF q142 | 33.4 | 47.6 | 2.52 | 24.7% | 89.3 |
158+| libaom mid q128 | 63.0 | 30.6 | **4.47** | 31.0% | 90.7 |
159+| ours top ARF q118 | 33.0 | 52.8 | 2.17 | 8.2% | 59.9 |
160+| libaom anchors q104-121 | 61-76 | 20-32 | **5.5-7.5** | — | 72.8-90 |
161+| rav1e L1 q104 | 26.0 | 49.5 | 2.17 | 20.9% | 80.7 |
162+
163+At the leaf level the two encoders see the SAME motion field (mv magnitude
164+histograms agree: ≤32 is 59.7% ours, 61.0% libaom) and libaom codes a fresh
165+`NEWMV` on three times as many blocks, paying 3.9x our mv bits per block —
166+and lands at 99.8% skip for half our bytes. Across the whole stream we
167+underspend mv by 1545 B and overspend inter coefficients by 5633 B. Tool
168+fires: our `motion_mode` costs 4646 bits over 16382 symbols to win OBMC on
169+1212 blocks; libaom spends 7935 bits on 9200 symbols; **wedge, interintra,
170+intrabc, global motion and warp fire ZERO times in all three streams** on this
171+content (they are not the gap). rav1e codes no `motion_mode` at all and codes
172+`segment_id` on every frame (8149 bits, 1.4%); we code neither segmentation
173+nor `delta_q`.
174+
175+## 5. Long-GOP, ours vs rav1e (the closer reference at 48 pictures)
176+
177+Per level, at matched rate (ours 71601 B/45.444, rav1e 75452 B/45.751):
178+
179+| level | ours B/frame | ours dB | rav1e B/frame | rav1e dB | verdict |
180+|---|---|---|---|---|---|
181+| key | 15827 | 47.34 | 20763 | **47.95** | ours 24% cheaper, **0.61 dB worse** — under-quality |
182+| top anchor | 6488 (×6, dist 8) | 45.75 | 3871 (×11, dist 4) | **45.97** | **+68% bytes for −0.22 dB — the overspent level** |
183+| mid anchor | 1229 (×6) | 45.63 | 537 (×12) | 45.48 | **+129% bytes for +0.15 dB — overspent** |
184+| leaf | 237 (×35) | 45.31 | 178 (×24) | **45.69** | +33% bytes for −0.38 dB — overspent AND under-quality |
185+
186+Named: **the top-ARF level is where the long-GOP bytes are overspent** (55.3%
187+of our stream; rav1e reaches a better picture at 60% of the per-frame cost),
188+and **the key frame is where we are under-quality** (0.61 dB below rav1e's,
189+and every level under it inherits that). The two are one decision: rav1e puts
190+28% of its stream in the key and coasts; we put 22% in the key and 55% in six
191+anchors that are still 0.22 dB below rav1e's cheaper ones. Note this is NOT
192+the pyramid-shape axis that six lanes have already refuted (mini-GOP length,
193+level count, q offsets) — the per-frame cost of OUR anchor at a FIXED shape is
194+what reads 1.68x.
195+
196+## 6. Lever proposals (at most 3, none built here)
197+
198+### L1 — 128x128 superblock roots, after fixing the ref-slot refusal (biggest measured number)
199+
200+* **Gap targeted**: 10456 B = 14.6% of the 48-frame stream ≈ **0.24 dB** of
201+ the 1.10 dB deficit; 38754 coded blocks against libaom's 16178 at identical
202+ per-block mode cost (3.26 bits both). At the leaf level 85.5% of our blocks
203+ are already at the 64x64 maximum, so no partition tuning can reach it.
204+* **Mechanism**: `use_128x128_superblock = 1` so a skipped 128x128 region
205+ costs one block instead of four.
206+* **Files**: `crates/ec-av1/src/encode.rs` — `sb128_on` (≈5705) and the leaf
207+ reference-slot selection the refusal names; `crates/ec-av1/src/filter_search.rs`
208+ for the loop-restoration unit size the flag forces to ≥128.
209+* **Expected BD**: the syntax saving alone is ~14% bytes on the long-GOP film
210+ B row (+86.7 vs libaom, +7.3 vs rav1e today) minus whatever the forced LR
211+ unit costs; lane-sb128 measured that cost as −0.3 dB on FILM A's 12-frame
212+ row, which is the same order as the gain, so the arm must be run with
213+ `EC_AV1_LR=0` on both sides to attribute it.
214+* **State found here (new)**: `EC_AV1_SB128=1` **panics deterministically on
215+ film B**, at 12 and at 48 frames, on the first leaf — `Leaf frame at order 3
216+ (last slot 0, self 0, altref 4, last2 None, shown true, golden true, altref
217+ pic true): a reference frame selected with no picture at this frame's own
218+ ref_frame_idx slot`. The memo's "intermittent" desync is not intermittent on
219+ this content, and lane-sb128's refutation was therefore never measured on
220+ the clip this gap is largest on.
221+* **Charter**: reproduce the refusal from `enc_probe <film B> gate 0 12 150`
222+ with `EC_AV1_SB128=1` (3 min, no gate needed), fix the ref-slot bookkeeping
223+ under a 128 root, then measure four arms at the 12-frame AND 48-frame film B
224+ points: sb128 off/on × `EC_AV1_LR` on/off, each judged at matched bytes
225+ through its own rate/quality slope, plus the census's block count and mode
226+ bytes as the mechanism witness (class `gate-blind-to-feature`: a 128-root
227+ fire counter, not a byte claim). Keep only if the film B long-GOP row
228+ improves against BOTH references with screen and bars flat; if the LR unit
229+ is what loses, the follow-on is the LR unit search under a 128 SB, not the
230+ 128 root itself.
231+
232+### L2 — the block-level NEWMV-vs-NEAREST margin (prediction precision)
233+
234+* **Gap targeted**: +5633 B of inter coefficients and −1545 B of mv at matched
235+ rate; NEWMV share 18-33% against libaom's 54-76% at every level, on the SAME
236+ motion field (leaf mv magnitude histograms agree within 1.3 points); mv bits
237+ per block 0.83/2.17/2.52 against libaom's 3.20/4.47/5.5-7.5. Worth up to
238+ 0.13 dB directly plus whatever the skip area recovers (our top ARF is 59.9%
239+ skip at distance 8 where libaom holds 72.8% at distance ~30).
240+* **Mechanism**: the RD margin that lets a block take `NEAREST/NEARMV` plus
241+ residual instead of paying for a coded mv. Not the search early-outs —
242+ `EXTRA_NEW_SKIP_MARGIN` and `LEAF_SECOND_NEW_MARGIN` are already swept to
243+ their floors — but the mv RATE term inside the block decision, the same
244+ shape `EC_AV1_SPLIT_LAMBDA` gave the split trial.
245+* **Files**: `crates/ec-av1/src/encode.rs` `search_inter_block` (9411) and the
246+ `symbol_bits(&cdf::NEW_MV[..])` prices at 9074/9133/9597/9681;
247+ `crates/ec-av1/src/motion.rs` `mv_bits` (184) for the search-side weight.
248+* **Expected BD**: a rate-term sweep is cheap and its ceiling here is ~0.13 dB
249+ (≈8% bytes) on the direct term; the class warning applies —
250+ `rd-rate-term-calibration` sweeps have come back single-peaked at the
251+ control twice (lane-txd, lane-split), so the arm that matters is the one
252+ that also moves the SKIP area, not just the mv share.
253+* **Charter**: add `EC_AV1_MV_LAMBDA` multiplying ONLY the mv-rate term of the
254+ block-level inter decision (search weight left alone, so the candidate set
255+ is unchanged), sweep 0.5/0.75/1.0/1.5/2.0 on the 12-frame film B row, and
256+ for each point record NEWMV share and skip area from the census beside the
257+ BD number — a point that moves BD without moving the NEWMV share is
258+ measuring something else. Take the best point to the 48-frame row and to
259+ screen/bars before keeping. If the sweep is single-peaked at 1.0 again, the
260+ finding is that our search, not our pricing, cannot find the vectors libaom
261+ codes, and the follow-on is subpel refinement depth at the ARF level.
262+
263+### L3 — per-SB `delta_q` from the tpl map (the last unbuilt allocation mechanism)
264+
265+* **Gap targeted**: not separable into bytes, but its footprint is: libaom
266+ codes 988 `delta_q` symbols = 2031 bits = **0.36% of its stream** in every
267+ inter frame and holds its whole 48-picture window inside
268+ [45.08, 48.56] dB with leaves 0.72 dB under its key; ours has no `delta_q`
269+ path at all and falls monotonically 47.34 → 45.31 (2.03 dB). Its leaves are
270+ +1.02 dB at half our bytes.
271+* **Mechanism**: move quality WITHIN a frame toward the blocks that propagate,
272+ using the tpl map the pyramid path already builds (lane-arfcen). Six lanes
273+ have refuted moving quality BETWEEN frames; this is the axis none of them
274+ touched.
275+* **Files**: `crates/ec-av1/src/encode.rs` frame-header `delta_q_present` and
276+ the per-superblock delta write; the tpl map from lane-arfcen.
277+* **Expected BD**: unpriced — the honest statement is that the syntax costs
278+ 0.4% and the allocation it enables is the only mechanism libaom uses in
279+ every frame that we use in none.
280+* **Charter**: write `delta_q_present`/`delta_q_res` in the inter frame header
281+ and one `delta_q` per superblock derived from the tpl map's propagation
282+ weight (libaom's `deltaq-mode 1` shape: finer q where the block is
283+ referenced more), clamped to ±a quarter of the base qindex. Land the decode
284+ witness first (a stream that codes a non-zero per-SB delta and round-trips
285+ through ffmpeg AND `decode_stream`), then a fire counter, then the 12-frame
286+ film B row, then long-GOP. Do NOT re-open the pyramid offsets in the same
287+ lane: this must be measured at the shipped shape or it becomes the seventh
288+ structure lane.
289+
290+## 7. Instrument added
291+
292+`EC_CENSUS_TABLES=<n>` in `examples/syntax_census` — how many CDF tables the
293+`top tables` line names (default 8, unchanged when unset). The default hid the
294+mode family's own split: a level can spend 41% of its bits on `mode` with no
295+mode table in its top 8, which is exactly the ranking §4a needed. Zero cost
296+when unset.
297+
298+## 8. What this lane did NOT measure
299+
300+`deferred: the LR-unit attribution of the 128 root (EC_AV1_LR=0 arms) — the
301+knob is test-build-only (`restoration_enabled`, encode.rs:983) so it cannot be
302+armed through enc_probe, and EC_AV1_SB128 panics on film B before any stream
303+exists. Unblocked by the ref-slot fix in L1's charter plus a test-binary arm.`
304+
305+`deferred: film A and the screen capture at matched rate — this lane's charter
306+is film B; the ranking above is a film B ranking, and libcen's film A census
307+(same shape, +38.9%) is the control that says the mechanism is not clip-only.`