forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-arftf' (dbf5dad5): ARF temporal filter strength swept on the long-GOP gate and shipped at 2; mid-ARF filter and a 4-past window refuted; pins re-taken at the merge 8290 / 33227

Browse files at this commit

fa0b48ef6e312d89b81e68ea3f78bb0868967f91Ahmet Kaan GümüşParent: 0a6acfeb9d6edb
crates/ec-av1/src/encode.rsmodified+8 -2
@@ -11711,7 +11711,7 @@ pub(crate) fn arf_temporal_filter(src: &Picture, window: &[Picture], strength: f
11711 let neighbours: Vec<&Picture> = window11711 let neighbours: Vec<&Picture> = window
11712 .iter()11712 .iter()
11713 .filter(|p| p.width == src.width && p.height == src.height)11713 .filter(|p| p.width == src.width && p.height == src.height)
11714- .take(2)11714+ .take(crate::encoder::arf_tf_window())
11715 .collect();11715 .collect();
11716 if neighbours.is_empty() || strength <= 0.0 {11716 if neighbours.is_empty() || strength <= 0.0 {
11717 return src.clone();11717 return src.clone();
@@ -17914,7 +17914,13 @@ mod tests {
17914 // inter frame that carries `reference_select` codes different blocks17914 // inter frame that carries `reference_select` codes different blocks
17915 // -- 8354 -> 8364 bytes at q=150 and 33222 -> 33257 at q=60.17915 // -- 8354 -> 8364 bytes at q=150 and 33222 -> 33257 at q=60.
17916 // `EC_AV1_B128COMP=0` restores 8354 / 33222 exactly.17916 // `EC_AV1_B128COMP=0` restores 8354 / 33222 exactly.
17917- let pins: [(u8, usize, u64); 2] = [(150, 8364, 0xcb2ad7936d5127c5), (60, 33257, 0x87db250ba556e5a6)];17917+ // Re-taken on lane-arftf: that filter's strength swept on the deciding
17918+ // gate lands at 2, not 3 ([`crate::speed::ARF_TF`]), so the filtered
17919+ // anchors' pixels moved once more: 8218 -> 8307 bytes at q=150 and
17920+ // 33017 at q=60 (the same LENGTH, different bytes).
17921+ // Re-taken at the merge of lane-arftf (ARF filter strength 2) and
17922+ // lane-rlclamp onto the 128 compound default.
17923+ let pins: [(u8, usize, u64); 2] = [(150, 8290, 0x92cb11033d1f5813), (60, 33227, 0x57ee6b1f8eacd881)];
17918 let coded: Vec<(u8, usize, u64)> = pins17924 let coded: Vec<(u8, usize, u64)> = pins
17919 .iter()17925 .iter()
17920 .map(|&(q, _, _)| {17926 .map(|&(q, _, _)| {
crates/ec-av1/src/encoder.rsmodified+34 -6
@@ -1215,6 +1215,29 @@ fn arf_tf_strength() -> f64 {
1215 .unwrap_or_else(|| crate::speed::at(&crate::speed::ARF_TF))1215 .unwrap_or_else(|| crate::speed::at(&crate::speed::ARF_TF))
1216 }1216 }
1217 1217
1218+/// lane-arftf: the same filter's strength on the MID ARF, whose own window
1219+/// is the display-FUTURE leaves of its group (`tpl_window(at, false)`).
1220+/// `EC_AV1_ARF_TF_MID=<strength>` overrides [`crate::speed::ARF_TF_MID`];
1221+/// `0` is off.
1222+fn arf_tf_mid_strength() -> f64 {
1223+ std::env::var("EC_AV1_ARF_TF_MID")
1224+ .ok()
1225+ .and_then(|v| v.parse().ok())
1226+ .unwrap_or_else(|| crate::speed::at(&crate::speed::ARF_TF_MID))
1227+}
1228+
1229+/// lane-arftf: how many of the window's pictures the filter averages in
1230+/// ([`crate::speed::ARF_TF_WIN`], `EC_AV1_ARF_TF_WIN=<n>`). The top ARF's
1231+/// window holds only DISPLAY-PAST neighbours -- it is the group's last
1232+/// picture and the next group's sources are not buffered when it is coded --
1233+/// so this widens the filter backwards only.
1234+pub(crate) fn arf_tf_window() -> usize {
1235+ std::env::var("EC_AV1_ARF_TF_WIN")
1236+ .ok()
1237+ .and_then(|v| v.parse().ok())
1238+ .unwrap_or_else(|| crate::speed::at(&crate::speed::ARF_TF_WIN))
1239+}
1240+
1218 fn tpl_pyramid() -> bool {1241 fn tpl_pyramid() -> bool {
1219 match std::env::var("EC_AV1_TPL_PYRAMID").ok() {1242 match std::env::var("EC_AV1_TPL_PYRAMID").ok() {
1220 Some(v) => v != "0",1243 Some(v) => v != "0",
@@ -1938,15 +1961,20 @@ impl Av1Encoder {
1938 // ... and never at the very top of the quality range, where the1961 // ... and never at the very top of the quality range, where the
1939 // anchor's own quantizer has hit the rate loop's floor1962 // anchor's own quantizer has hit the rate loop's floor
1940 // ([`crate::speed::ARF_TF_QMIN`]).1963 // ([`crate::speed::ARF_TF_QMIN`]).
1964+ let tf = match dq_level {
1965+ crate::encode::DqLevel::TopArf => arf_tf_strength(),
1966+ // lane-arftf: the mid ARF gets its own strength -- its window is
1967+ // the group's later leaves, i.e. the filter runs FORWARD there.
1968+ crate::encode::DqLevel::MidArf => arf_tf_mid_strength(),
1969+ crate::encode::DqLevel::Leaf => 0.0,
1970+ };
1941 let tf = match base_q_idx >= crate::speed::ARF_TF_QMIN {1971 let tf = match base_q_idx >= crate::speed::ARF_TF_QMIN {
1942- true => arf_tf_strength(),1972+ true => tf,
1943 false => 0.0,1973 false => 0.0,
1944 };1974 };
1945- let source = match (tf > 0.0, dq_level) {1975+ let source = match tf > 0.0 {
1946- (true, crate::encode::DqLevel::TopArf) => {1976+ true => crate::encode::arf_temporal_filter(&source, lookahead, tf),
1947- crate::encode::arf_temporal_filter(&source, lookahead, tf)1977+ false => source,
1948- }
1949- _ => source,
1950 };1978 };
1951 let encoded = || -> Result<Encoded> { encode_inter_frame(1979 let encoded = || -> Result<Encoded> { encode_inter_frame(
1952 &source,1980 &source,
crates/ec-av1/src/speed.rsmodified+41 -1
@@ -393,7 +393,47 @@ pub(crate) const DQ_LEVEL_K: [f64; 3] = [1.5, 1.0, 1.0];
393 /// (`lanes/arfpred.report.md` section 3). Hard filtering does remove 6-7% of393 /// (`lanes/arfpred.report.md` section 3). Hard filtering does remove 6-7% of
394 /// the stream's bytes and gives all of it back in quality, because the leaves394 /// the stream's bytes and gives all of it back in quality, because the leaves
395 /// still carry the grain the anchor no longer has.395 /// still carry the grain the anchor no longer has.
396-pub(crate) const ARF_TF: [f64; 11] = [3.0; 11];396+///
397+/// lane-arftf SWEPT IT ON THE DECIDING GATE (48 pictures, film A / film B,
398+/// BD vs libaom `cpu-used 6` / rav1e `speed 6`, lower is better) -- the probe
399+/// of lane-arfpred mispredicts this lever's sign, so only these count:
400+///
401+/// | strength | film A | film B |
402+/// |---|---|---|
403+/// | 1 | +22.6/-8.1 | +81.6/+4.8 |
404+/// | **2 (ships)** | **+22.2/-8.2** | **+78.6/+2.7** |
405+/// | 3 (was) | +22.7/-7.9 | +79.0/+2.7 |
406+/// | 5 | +23.9/-7.4 | +83.6/+5.1 |
407+///
408+/// The curve is single-peaked at 2 and bracketed on both sides; 2 is down on
409+/// all four columns against the shipped 3 (film A -0.5/-0.3, film B
410+/// -0.4/0.0).
411+pub(crate) const ARF_TF: [f64; 11] = [2.0; 11];
412+
413+/// lane-arftf: the same filter on the MID ARF (the second hidden frame of a
414+/// group), whose window is the group's later leaves -- so it filters FORWARD
415+/// where the top ARF filters backward. `EC_AV1_ARF_TF_MID=<strength>`
416+/// overrides it; `0` is off, which is where the long-GOP gate left it:
417+/// filtering the mid ARF at the same strength as the top one reads film A
418+/// +22.2/-8.3 and film B +78.9/+2.6 against the top-only +22.2/-8.2 and
419+/// +78.6/+2.7 -- inside the noise on three columns and 0.3 WORSE on film B's
420+/// libaom one, so the mechanism does not pay a second time one level down.
421+pub(crate) const ARF_TF_MID: [f64; 11] = [0.0; 11];
422+
423+/// lane-arftf: how many window pictures [`crate::encode::arf_temporal_filter`]
424+/// averages in. The top ARF is its group's LAST picture and the next group's
425+/// sources are not buffered when it is coded, so the window holds only
426+/// display-PAST neighbours and this widens the filter backwards only (a
427+/// symmetric +-2 needs a one-group lookahead the encoder does not have).
428+/// `EC_AV1_ARF_TF_WIN=<n>` overrides it.
429+///
430+/// 4 (past-only +-2) is REFUTED on the long-GOP gate at strength 2: film A
431+/// +22.8/-7.8 and film B +78.9/+2.8 against 2's +22.2/-8.2 and +78.6/+2.7 --
432+/// worse on three of the four columns. The census's 14.3% SAD removal was
433+/// measured with two neighbours on EACH side; four pictures of one-sided
434+/// past is a different (and worse) window, and the anchor drifts away from
435+/// the leaves it has to predict.
436+pub(crate) const ARF_TF_WIN: [usize; 11] = [2; 11];
397 437
398 /// lane-arfpred: the qindex below which the ARF temporal filter is OFF --438 /// lane-arfpred: the qindex below which the ARF temporal filter is OFF --
399 /// libaom scales `arnr` strength with the quantizer and stops filtering at439 /// libaom scales `arnr` strength with the quantizer and stops filtering at
lanes/arftf.report.mdadded+116 -0
@@ -0,0 +1,116 @@
1+# lane-arftf — the ARF temporal filter's strength, window and level
2+
3+Worktree `edith_codecs-arftf`, branch `lane-arftf` off main `8d9d056b`.
4+Deciding gate `encode::tests::bd_rate_film_long_gop` (48 pictures, both film
5+rows, BD vs libaom `cpu-used 6` / rav1e `speed 6`, lower is better).
6+**Control RUN, not quoted: film A +22.7 / −7.9, film B +79.0 / +2.7 — the
7+charter's numbers to the digit.**
8+
9+lane-arfpred shipped the filter at strength 3 with only that one point on the
10+gate; its two-point probe mispredicted the SIGN of this lever, so every arm
11+here is a gate arm.
12+
13+## 1. Strength sweep — the shipped point moves 3 → 2
14+
15+| strength | film A | film B |
16+|---|---|---|
17+| 1 | +22.6 / −8.1 | +81.6 / +4.8 |
18+| 2 **(ships)** | **+22.2 / −8.2** | **+78.6 / +2.7** |
19+| 3 (was) | +22.7 / −7.9 | +79.0 / +2.7 |
20+| 5 | +23.9 / −7.4 | +83.6 / +5.1 |
21+
22+Single-peaked and BRACKETED on both sides. 2 is down on all four columns
23+against the shipped 3 (film A −0.5 / −0.3, film B −0.4 / 0.0), which clears
24+the keep rule outright. Both neighbours are worse on the film B libaom
25+column by 2.6 (s1) and 5.0 (s5), so this peak is not a noise artefact.
26+
27+## 2. The ±2 window — the future half is NOT buffered, past-only ±2 loses
28+
29+`Av1Encoder::drain_pending` codes the group's top ARF as the group's LAST
30+picture (`group.last()`), and `encode_frames` pushes into `pending` and drains
31+the whole group before the next picture arrives, so **when the top ARF is
32+coded no picture after it exists in the encoder at all**. `tpl_window(pos,
33+true)` hands it `group[..pos]` reversed — display-PAST neighbours only, up to
34+`tpl_depth() − 1` of them (7 at the default preset). A symmetric ±2 needs a
35+one-group lookahead this encoder does not have; that is the blocker, and it
36+is a picture-buffer change, not a filter change.
37+
38+What IS available is more past, so the charter's fallback was measured:
39+`speed::ARF_TF_WIN` (new, `EC_AV1_ARF_TF_WIN=<n>`) widens the neighbour count
40+from the literal 2 to any n.
41+
42+| window | film A | film B |
43+|---|---|---|
44+| 2 past (ships) | +22.2 / −8.2 | +78.6 / +2.7 |
45+| 4 past (±2 one-sided) | +22.8 / −7.8 | +78.9 / +2.8 |
46+
47+REFUTED on three of the four columns. `arf_pred_census`'s 14.3% SAD removal
48+was measured with two neighbours on EACH side; four pictures of one-sided past
49+is a different window, and the anchor drifts away from the leaves that have to
50+predict from it.
51+
52+## 3. The mid ARF — filtering it a second level down does not pay
53+
54+`speed::ARF_TF_MID` (new, `EC_AV1_ARF_TF_MID=<strength>`) runs the same filter
55+on the group's second hidden frame, whose own window is `tpl_window(at,
56+false)` — the group's LATER leaves, i.e. it filters forward where the top ARF
57+filters backward, and those pictures ARE buffered.
58+
59+| arm | film A | film B |
60+|---|---|---|
61+| top ARF only, s = 2 | +22.2 / −8.2 | +78.6 / +2.7 |
62+| top + mid, both s = 2 | +22.2 / −8.3 | +78.9 / +2.6 |
63+
64+Inside the noise on three columns and 0.3 WORSE on film B's libaom one, so it
65+ships OFF (`ARF_TF_MID = 0`). Deviation from the charter, named: the mid arm
66+was run at strength 2, not 3, because the sweep had already put 2 above 3 at
67+the top level and a 3 there would have confounded the level with the strength.
68+
69+Per-block weight refinement was left alone (charter: out of scope unless
70+one line — it is not).
71+
72+## 4. Guard rows — `bd_rate_screen_native`, 12 pictures, all five rows
73+
74+| clip | control (s = 3) | s = 2 | Δ |
75+|---|---|---|---|
76+| bars 1080p | −2.9 / −18.6 | −3.2 / −18.8 | −0.3 / −0.2 |
77+| bars 2160p | +9.1 / −13.3 | +9.1 / −13.4 | 0.0 / −0.1 |
78+| film A | +18.3 / −6.0 | +18.5 / −5.9 | +0.2 / +0.1 |
79+| film B | +24.6 / −2.1 | +24.6 / −2.0 | 0.0 / +0.1 |
80+| screen capture | +14.6 / −33.2 | +14.6 / −33.2 | byte-identical |
81+
82+Control reproduces the charter's numbers exactly. Nothing moves by more than
83+0.3; the two bars rows actually improve, and the screen sequence codes no
84+pyramid ARF at all so the filter never runs there.
85+
86+## 5. Invariants
87+
88+* Byte pins re-taken (the filtered anchors' pixels move by construction):
89+ `(150, 8218 → 8307)`, and `(60, 33017)` keeps its LENGTH with a different
90+ hash. Green at the default AND at `EC_AV1_SPEED=6`.
91+* `encoder::tests::bitrate_target_lands_within_5_percent_over_48_frames` is
92+ green in the split suite below (it sits near its bound at the rate loop's
93+ quantizer floor; `ARF_TF_QMIN = 16` still keeps the filter off there).
94+* Split suite on the shipped default: `--skip stream::` **343 passed / 0
95+ failed**, `stream:: --skip 10bit` **202 passed / 0 failed**, `10bit`
96+ **42 passed / 0 failed** (587 in all).
97+* `--ignored --exact
98+ encoder::tests::every_speed_preset_decodes_sample_exact_through_both_decoders`
99+ 1 passed.
100+* `cargo check --workspace --all-targets -j4`: 0 errors, 0 `ec-av1` warnings
101+ (the 25 warnings are `ec-opus` / `ec-vorbis`, pre-existing).
102+
103+## 6. What this lane did NOT do
104+
105+* `deferred: the symmetric ±2 window — the census's best filter shape needs
106+ the two DISPLAY-FUTURE neighbours of the top ARF, which the encoder does
107+ not hold when it codes it — unblocked by a lane that gives
108+ Av1Encoder::drain_pending one group of lookahead (buffer group N+1's
109+ sources before coding group N's ARF).`
110+* `deferred: per-block weight refinement (libaom weights each 16x16 block by
111+ its own error against each neighbour separately, and uses up to 7 frames) —
112+ out of the charter's scope and not a one-liner — unblocked by a lane that
113+ ports libaom's temporal_filter weighting.`
114+* `deferred: a mid-ARF strength of its own (only 2 was measured there, and it
115+ was flat-to-worse) — unblocked by a lane with spare long-GOP arms; the knob
116+ ships wired (EC_AV1_ARF_TF_MID) so the arm is env-only.`