forge
Explore
Log in

Don't you dare go Hollow

Lane-lr r2 charter -- read_lr wiring then the filters

Browse files at this commit

a3c51d9104be5697f469b8e866bb72f7a692612eAhmet Kaan GümüşParent: ed03937
  • docs
    • lane-lr r2 charter -- read_lr wiring then the filters
Show full message
docs(av1): lane-lr r2 charter -- read_lr wiring then the filters
lanes/lr-r2.charter.mdadded+85 -0
@@ -0,0 +1,85 @@
1+# lane-lr r2 — read_lr wiring, then the two filters
2+
3+Worktree `/home/user/Documents/Code/Rust/edith_codecs-lr`, branch `lane-lr`,
4+at 4d7ae64.
5+
6+## Read these two files first, then start writing code
7+- `lanes/lr.report.md` — r1's complete design writeup. Its "Next lever" section
8+ has every formula and `file:line` you need. Do NOT re-derive what it already
9+ contains (class `worker-cap-spent-reading`).
10+- `lanes/lr.charter.md` — the original charter: staging, gate rules, hard rules.
11+ Still binding.
12+
13+## What r1 landed (both committed, suite confirmed green 232/0 on this tree)
14+- `crates/ec-av1/src/cdf.rs`: `RESTORE_WIENER = [11570, 32768, 0]`,
15+ `RESTORE_SGRPROJ = [16855, 32768, 0]`,
16+ `RESTORE_SWITCHABLE = [9413, 22581, 32768, 0]` — copied from libaom
17+ `entropymode.c` `default_{wiener,sgrproj,switchable}_restore_cdf` and
18+ converted to this codebase's `[a0, (a1,) 32768, 0]` convention, checked
19+ against `INTRABC`'s own `AOM_CDF2(30531) -> [30531, 32768, 0]`.
20+- `crates/ec-av1/src/cdf_state.rs`: the three tables wired into `Cdfs` —
21+ fields, `new()` defaults, `reset_counts` via `reset1` — following `intrabc`.
22+- Nothing reads them from the bitstream yet; the whole-frame refusal at
23+ `crates/ec-av1/src/stream.rs:195-198` is unchanged.
24+
25+## r1's decisive facts, so you do not re-find them
26+- `restoration.c:1277` `av1_loop_restoration_corners_in_sb` returns 0 unless
27+ `bsize == sb_size`, so "read LR once per superblock" is spec-exact here, not
28+ a simplification — every restoration unit is >= 64px.
29+- `msac.rs:348` `SymbolDecoder::literal(bits)` is the `L(n)` primitive LR's
30+ subexp reads need. The existing `decode_subexp` /
31+ `decode_unsigned_subexp_with_ref` / `decode_signed_subexp_with_ref` /
32+ `inverse_recenter` at `ec-av1-syntax/src/frame.rs:1797-1848` are
33+ `BitReader`-only (uncompressed frame header) — LR needs a SECOND,
34+ msac-flavoured port, not reuse.
35+- Threading point: `decode_key_frame_tile_with_cdfs` (decode.rs:4478) and
36+ `decode_inter_frame_tile_with_cdfs` (decode.rs:9088) already take long
37+ positional argument lists including cdef and loop_filter. Add
38+ `&LoopRestorationParams` there and pass `&LoopRestorationParams::default()`
39+ from the public wrappers (`decode_key_frame_tile:4435`,
40+ `decode_inter_frame_tile:9030`) — that keeps ~10 test call sites untouched.
41+- Wiener tap ranges `(-5, 10, k1)` `(-23, 8, k2)` `(-17, 46, k3)`;
42+ SGR ranges `(-96, 31, k4)` `(-32, 95, k4)`. `av1_sgr_params` is in libaom
43+ `restoration.c`.
44+
45+## Order of work — COMMIT AFTER EVERY GREEN MILESTONE
46+1. Port the msac-flavoured subexp/recenter helpers with their own unit tests
47+ pinned against known values. COMMIT.
48+2. `read_lr` / `read_lr_unit` called once per superblock before
49+ `decode_partition` at decode.rs ~4547 (key frame) and ~9275 (inter), with
50+ the per-plane unit-grid formula from the report. The frame still refuses,
51+ by a NEW and accurate name ("loop restoration symbols are read but the
52+ filters are not applied"). The proof this stage works: a stream that used to
53+ desync the partition walk into out-of-alphabet garbage now walks its
54+ partitions cleanly and fails only the pixel compare. COMMIT.
55+3. Wiener filter, incl. the 3-pixel stripe boundary save/restore (libaom's
56+ `rlbs`) — that boundary handling is the classic trap. COMMIT.
57+4. Self-guided, incl. the box-sum radii and `av1_sgr_params`. COMMIT.
58+5. Switchable; remove the last refusal; the gate asserts Ok, never an Err.
59+ COMMIT.
60+
61+## Gate rules (mandatory, unchanged from r1's charter)
62+`EC_AV1_REQUIRE_AOMENC=1` on every test run; `-t <seconds>` on every ffmpeg
63+generate; fixtures through the existing `gradients_source(seed, w, h, tail)`
64+helper (ffmpeg's `gradients` ignores its own seed); aomenc
65+`--threads=1 --row-mt=0 --enable-restoration=1`; a HARD-asserted firing count
66+via a thread-local `Cell<usize>` counter matching the existing `*_HITS`
67+(thread-local, NOT atomics). A gate that cannot prove LR fired is vacuous.
68+
69+Note: main now carries a `gate_coverage` guard that derives, from the gate
70+source, which aomenc tools are switched off in all 20 gates and on in none.
71+`enable-restoration` is one gate short of that list today; your gate enabling it
72+is exactly the right outcome.
73+
74+## Hard rules
75+- `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-lr`. Foreground builds,
76+ `nice -n 19 cargo ... -j4`. The suite takes ~4 minutes on this tree — give
77+ any `cargo test` call a timeout of at least 600000 ms; do not let a 120 s
78+ default kill it and then background it unpolled, as r1 did.
79+- Sibling worktrees (edith_codecs, -chroma, -realworld, -superres, -tiles) have
80+ live agents. Never build in or edit them.
81+- Baseline to hold: 232 passed / 0 failed on this tree (main is at 234 with two
82+ new guard tests you will inherit at merge).
83+- NEVER push, never merge, never touch `main`. Commit on `lane-lr` only.
84+- 75-turn cap: commit at every green step; near the cap, commit whatever
85+ compiles as `wip(av1): ...` and update `lanes/lr.report.md`.