Lane-superres charter -- superres decode
Browse files at this commit33241d043172f2785f0601e2758213b6e36f0957Parent: 94033af- docs
- lane-superres charter -- superres decode
1 changed file +91 -0
- lanes/superres.charter.md +91 -0
lanes/superres.charter.mdadded+91 -0
| @@ -0,0 +1,91 @@ | |||
| 1 | +# lane-superres — superres decode (frame_size_with_refs / horizontal upscale) | ||
| 2 | + | ||
| 3 | +Worktree `/home/user/Documents/Code/Rust/edith_codecs-superres`, branch | ||
| 4 | +`lane-superres`, off main 87a1e34. | ||
| 5 | + | ||
| 6 | +## Goal | ||
| 7 | +Make the decoder handle a stream aomenc produced with `--superres-mode=` | ||
| 8 | +(fixed and/or qthresh) end to end, pixel-exact vs libaom: | ||
| 9 | +1. header side: `use_superres` / `superres_denom` are read into the frame | ||
| 10 | + header (check whether `crates/ec-av1-syntax` already parses them — see | ||
| 11 | + `crates/ec-av1-syntax/src/frame.rs:518` — and whether the DECODE path in | ||
| 12 | + `crates/ec-av1/src/stream.rs` refuses or silently ignores them); | ||
| 13 | +2. decode side: the frame is coded at `frame_width` (the DOWNSCALED width), | ||
| 14 | + every block/MV/loop-filter/CDEF operation happens at that width, and only | ||
| 15 | + after loop restoration is the frame upscaled horizontally to | ||
| 16 | + `upscaled_width` by the spec's linear-filter upscaler; | ||
| 17 | +3. reference frames are stored UPSCALED, and `frame_size_with_refs` / | ||
| 18 | + MV scaling for inter prediction across a size change must be right. | ||
| 19 | + | ||
| 20 | +## Anchors | ||
| 21 | +- Spec: 5.9.8 `superres_params`, 7.16 `upscaling process`, 5.9.7 | ||
| 22 | + `frame_size_with_refs`, 7.11.3.3 (motion vector scaling / scaled reference). | ||
| 23 | +- libaom (source tree under `~/.cache/aom-oracle`): | ||
| 24 | + `av1/common/resize.c` — `av1_upscale_normative_rows`, | ||
| 25 | + `av1_upscale_normative_and_extend_frame`, `upscale_normative_rect`, | ||
| 26 | + and the `av1_resize_filter_normative` coefficient table (the 8-tap | ||
| 27 | + `SUPERRES_FILTER` table with `RS_SUBPEL_BITS`/`RS_SCALE_SUBPEL_BITS`); | ||
| 28 | + `av1/decoder/decodeframe.c` `setup_superres` / `superres_post_decode`. | ||
| 29 | +- Note the ORDER: superres upscaling happens AFTER deblock+CDEF and | ||
| 30 | + AFTER loop restoration in libaom's pipeline | ||
| 31 | + (`av1_loop_restoration_filter_frame` runs on the downscaled frame using the | ||
| 32 | + saved pre-upscale buffer). Get this order from the source, not from memory. | ||
| 33 | +- Writer side already exists and refuses: `crates/ec-av1/src/frame.rs:309-316` | ||
| 34 | + writes `use_superres` and refuses a denom other than 8. Leave the writer's | ||
| 35 | + refusal in place unless you also implement the encoder-side downscale — that | ||
| 36 | + is OUT of scope for this lane; this lane is DECODE. | ||
| 37 | +- `crates/ec-av1/src/stream.rs` holds every decode refusal and every gate. | ||
| 38 | + `grep -n unsupported crates/ec-av1/src/stream.rs` to see the shape. | ||
| 39 | + | ||
| 40 | +## Step 0 — measure before building | ||
| 41 | +Encode a real fixture with `--superres-mode=1 --superres-denominator=<n>` | ||
| 42 | +(check `aomenc --help | grep -i superres` for the actual flag spelling in | ||
| 43 | +v3.13.3) and run it through our decoder as it stands today. Report in the | ||
| 44 | +report file: does it refuse (with what exact string), desync, or decode wrong? | ||
| 45 | +That answer decides whether stage 1 is a refusal removal or a bug fix. If the | ||
| 46 | +header path already silently ignores superres and produces wrong pixels, that | ||
| 47 | +is a SILENT WRONGNESS defect and must first become an explicit refusal, in its | ||
| 48 | +own commit, before the implementation lands. | ||
| 49 | + | ||
| 50 | +## Staging — commit after EVERY green milestone | ||
| 51 | +1. Header + explicit refusal by accurate name. COMMIT. | ||
| 52 | +2. Upscaler implemented and unit-pinned: a `#[test]` that feeds a known row to | ||
| 53 | + our upscaler and compares against values captured from libaom's | ||
| 54 | + `av1_upscale_normative_rows` (add an instrumentation rung to | ||
| 55 | + `scripts/instrument-aom-oracle.sh` if you need to capture them — follow the | ||
| 56 | + existing rungs' shape exactly: env-gated, silent when unset, idempotent, | ||
| 57 | + wrapper-around-impl — then rebuild with `scripts/build-aom-oracle.sh`). | ||
| 58 | + COMMIT. | ||
| 59 | +3. Full-frame gate: decode an aomenc superres stream pixel-exact vs | ||
| 60 | + `aomdec --rawvideo`. COMMIT. | ||
| 61 | +4. Inter frames referencing a differently-sized reference (superres-mode=2 | ||
| 62 | + /qthresh, so denom varies frame to frame). COMMIT. | ||
| 63 | + | ||
| 64 | +## Gate (mandatory) | ||
| 65 | +- Follow the existing gate shape in `crates/ec-av1/src/stream.rs`. | ||
| 66 | + `EC_AV1_REQUIRE_AOMENC=1` must be set when you run tests: a missing oracle | ||
| 67 | + must FAIL, never SKIP. | ||
| 68 | +- Bound every ffmpeg `generate` with `-t <seconds>`. | ||
| 69 | +- Build the fixture through the existing `gradients_source(seed, w, h, tail)` | ||
| 70 | + helper — ffmpeg's `gradients` source ignores its seed, so a hand-written | ||
| 71 | + `gradients=size=` string makes the gate non-reproducible. | ||
| 72 | +- aomenc: `--threads=1 --row-mt=0`. | ||
| 73 | +- Hard-assert a firing count via a thread-local `Cell<usize>` counter like the | ||
| 74 | + existing `*_HITS` in decode.rs (they are thread-local now, NOT atomics). | ||
| 75 | + A gate that cannot prove superres actually fired is vacuous | ||
| 76 | + (CLASS `gate-blind-to-feature`). | ||
| 77 | +- Refusals inside the gate are FORBIDDEN once the stage removing them lands. | ||
| 78 | + | ||
| 79 | +## Hard rules | ||
| 80 | +- Own build dir: `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-superres`. | ||
| 81 | + Foreground builds only, `nice -n 19 cargo ... -j4`. Never build in another | ||
| 82 | + worktree, never touch a sibling worktree's files. | ||
| 83 | +- Suite: `nice -n 19 cargo test -p ec-av1 --lib` (baseline 232 passed / 0 | ||
| 84 | + failed, ~67 s). Must stay green. | ||
| 85 | +- NEVER push, never merge, never touch `main`. Commit on `lane-superres` only. | ||
| 86 | +- 75-turn cap: **commit after every green milestone**; near the cap commit | ||
| 87 | + whatever compiles as `wip(av1): ...` and write `lanes/superres.report.md`. | ||
| 88 | +- Refuse-by-name rather than desync. Never claim in a refusal string that the | ||
| 89 | + encoder cannot emit a case unless you proved it. | ||
| 90 | +- Write `lanes/superres.report.md`: what landed, gate name + firing count, | ||
| 91 | + remaining refusal strings verbatim, next lever. | ||