forge
Explore
Log in

Don't you dare go Hollow

Lane-superres r2 charter

Browse files at this commit

c28ee95d14b173c76dfb92834a6cf4dde7466849Ahmet Kaan GümüşParent: 0e6258a
  • docs
    • lane-superres r2 charter
    • commit the libaom upscaler pin harness out of the reapable scratchpad
Show full message
docs(av1): lane-superres r2 charter; commit the libaom upscaler pin harness out of the reapable scratchpad
lanes/superres-r2.charter.mdadded+86 -0
@@ -0,0 +1,86 @@
1+# lane-superres r2 — finish the stage-3 gate, then inter-frame superres
2+
3+Worktree `/home/user/Documents/Code/Rust/edith_codecs-superres`, branch
4+`lane-superres`, at 150bbdc (+ the pin harness commit).
5+
6+## State (r1's, verified where it says so)
7+Committed and green:
8+- `79252c8` — `use_superres` refused BY NAME in `crates/ec-av1/src/stream.rs`.
9+ It was silent wrongness before: the header parsed fully but decode stored the
10+ `Picture` at the downscaled `frame_width` instead of `upscaled_width`. Gate
11+ `a_real_aomenc_stream_with_superres_refuses_by_name` proves it against a real
12+ `--superres-mode=1` stream.
13+- `aec76d1` — `crates/ec-av1/src/superres.rs`: the spec 7.16 horizontal
14+ upscaler (`upscale_row` / `upscale_plane`), coefficient table and constants
15+ transcribed from libaom `resize.c` / `convolve.c`, pinned against the REAL
16+ exported `av1_get_upscale_convolve_step` / `av1_convolve_horiz_rs_c` /
17+ `av1_resize_filter_normative` through a C harness. Three unit tests green.
18+ The harness is now committed at `scripts/superres-pin-harness.c` (it lived in
19+ a reapable scratchpad — class `oracle-in-reaped-dir`); build it against
20+ `~/.cache/aom-oracle/build/libaom.a` if you need to extend the pins.
21+- `150bbdc` — stage-3 wiring: the `use_superres` refusal narrowed to
22+ `frame_type != Key`; key frames call `crate::superres::upscale_picture` after
23+ `decode_key_frame_tile_with_cdfs`, before storage/output; `SUPERRES_HITS`
24+ thread-local + `superres_hits()`; `upscale_picture` covers Y/U/V with 4:2:0
25+ chroma halved by `div_ceil(2)`. Compiles clean.
26+
27+r1 also corrected an error in the original charter: libaom's
28+`decodeframe.c` calls `superres_post_decode()` BETWEEN `av1_cdef_frame` and
29+`av1_loop_restoration_filter_frame` — **superres runs BEFORE loop restoration**,
30+not after. Recorded in `superres.rs`'s module doc. Not load-bearing while LR is
31+refused, but lane-lr will need it.
32+
33+## Not landed
34+- The stage-3 gate `a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact`
35+ (in 150bbdc) FAILS with `unsupported: AV1 tile (a partition type this encoder
36+ never writes)`. That is a pre-existing capability gap in the bare
37+ `--superres-mode=1 --superres-denominator=12 --cpu-used=0` recipe, not a
38+ superres defect — the same shape the warp gate's original recipe hit.
39+- r1's fix was in flight when its budget ran out and **did not apply** — the
40+ worktree is clean. Redo it: give the gate the restrictive flag set the warp
41+ gate uses (`--enable-rect-partitions=0 --enable-ab-partitions=0
42+ --enable-1to4-partitions=0 --enable-filter-intra=0 --enable-smooth-intra=0
43+ --enable-paeth-intra=0 --enable-directional-intra=0 --enable-angle-delta=0
44+ --enable-tx-size-search=0 --enable-cdef=0 --enable-restoration=0
45+ --max-partition-size=32 --min-partition-size=32 --enable-palette=0
46+ --enable-intrabc=0 --enable-cfl-intra=0`), around stream.rs:3860-3875.
47+- Stage 4 (inter frames referencing a differently-sized reference — superres
48+ mode 2 / qthresh) is not started. It needs spec 7.11.3.3 scaled-reference
49+ motion compensation, which is genuinely new work, not wiring.
50+- `lanes/superres.report.md` was never written.
51+
52+## Order of work — COMMIT AFTER EVERY GREEN STEP
53+1. Apply the flag-set fix; run just that gate
54+ (`cargo test -p ec-av1 --lib a_real_aomenc_superres_key_frame_sequence -j4 -- --nocapture`,
55+ timeout >= 600000 ms). It must decode pixel-exact AND hard-assert
56+ `superres_hits() > 0`.
57+2. Full scoped suite `EC_AV1_REQUIRE_AOMENC=1 nice -n 19 cargo test -p ec-av1 --lib -j4`
58+ (~4 min, timeout >= 600000 ms). Baseline: 232/0 on this tree; main now
59+ carries 234/0 with two new guard tests you will inherit at merge. COMMIT
60+ stage 3.
61+3. Stage 4: inter-frame superres. Scaled-reference MC, spec 7.11.3.3; libaom
62+ `av1_setup_scale_factors_for_frame` / `av1_convolve_2d_scale`. Its own gate,
63+ its own firing counter, its own commit.
64+
65+## Note on the coverage guard
66+Main now carries `crates/ec-av1/src/gate_coverage.rs`, which derives from the
67+gate source the aomenc tools switched off in every gate and on in none, and
68+pins that set. The flag list above only disables tools already in the pinned set
69+(cdef, intrabc, paeth-intra, palette, smooth-intra) plus tools other gates leave
70+on, so it will not trip the guard — but run the full suite before committing.
71+
72+## Gate rules (mandatory)
73+`EC_AV1_REQUIRE_AOMENC=1` on every run; `-t <seconds>` on every ffmpeg generate;
74+fixtures through `gradients_source(seed, w, h, tail)`; aomenc
75+`--threads=1 --row-mt=0`; the firing count is a HARD assert, never a warning.
76+
77+## Hard rules
78+- `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-superres`. Foreground
79+ builds, `nice -n 19 cargo ... -j4`, every `cargo test` given a timeout of at
80+ least 600000 ms — a 120 s default kills the suite mid-run.
81+- Sibling worktrees (edith_codecs, -chroma, -realworld, -lr, -tiles) have live
82+ agents. Never build in or edit them.
83+- NEVER push, never merge, never touch `main`. Commit on `lane-superres` only.
84+- 75-turn cap; commit at every green step; near the cap commit whatever
85+ compiles as `wip(av1): ...`.
86+- Finish with `lanes/superres.report.md`, VERDICT on the first line.
scripts/superres-pin-harness.cadded+58 -0
@@ -0,0 +1,58 @@
1+#include <stdio.h>
2+#include <stdint.h>
3+#include <string.h>
4+
5+#define RS_SUBPEL_BITS 6
6+#define RS_SCALE_SUBPEL_BITS 14
7+#define RS_SCALE_SUBPEL_MASK ((1 << RS_SCALE_SUBPEL_BITS) - 1)
8+#define RS_SCALE_EXTRA_BITS (RS_SCALE_SUBPEL_BITS - RS_SUBPEL_BITS)
9+#define RS_SCALE_EXTRA_OFF (1 << (RS_SCALE_EXTRA_BITS - 1))
10+#define UPSCALE_NORMATIVE_TAPS 8
11+
12+extern const int16_t av1_resize_filter_normative[1 << RS_SUBPEL_BITS][UPSCALE_NORMATIVE_TAPS];
13+extern int32_t av1_get_upscale_convolve_step(int in_length, int out_length);
14+extern void av1_convolve_horiz_rs_c(const uint8_t *src, int src_stride,
15+ uint8_t *dst, int dst_stride, int w,
16+ int h, const int16_t *x_filters,
17+ int x0_qn, int x_step_qn);
18+
19+// verbatim copy of resize.c's static get_upscale_convolve_x0 -- the one
20+// formula in the pipeline this harness does not exercise via a real
21+// exported symbol; everything else (the coefficient table + the
22+// convolution/rounding kernel, the actual bug risk) runs real compiled
23+// libaom code.
24+static int32_t get_upscale_convolve_x0(int in_length, int out_length,
25+ int32_t x_step_qn) {
26+ const int err = out_length * x_step_qn - (in_length << RS_SCALE_SUBPEL_BITS);
27+ const int32_t x0 =
28+ (-((out_length - in_length) << (RS_SCALE_SUBPEL_BITS - 1)) +
29+ out_length / 2) /
30+ out_length +
31+ RS_SCALE_EXTRA_OFF - err / 2;
32+ return (int32_t)((uint32_t)x0 & RS_SCALE_SUBPEL_MASK);
33+}
34+
35+int main(void) {
36+ const int in_len = 8, out_len = 16;
37+ uint8_t input[8] = { 10, 20, 30, 40, 50, 60, 70, 80 };
38+ const int border = UPSCALE_NORMATIVE_TAPS / 2 + 1; // 5
39+ uint8_t padded[8 + 2 * 16];
40+ uint8_t *row = padded + 16; // row[0..7] == input
41+ memset(padded, input[0], 16);
42+ memcpy(row, input, 8);
43+ memset(row + 8, input[7], 16);
44+
45+ int32_t x_step_qn = av1_get_upscale_convolve_step(in_len, out_len);
46+ int32_t x0_qn = get_upscale_convolve_x0(in_len, out_len, x_step_qn);
47+ printf("x_step_qn=%d x0_qn=%d\n", x_step_qn, x0_qn);
48+
49+ uint8_t out[12];
50+ av1_convolve_horiz_rs_c(row - 1, 0, out, 0, out_len, 1,
51+ &av1_resize_filter_normative[0][0], x0_qn,
52+ x_step_qn);
53+ printf("out:");
54+ for (int i = 0; i < out_len; i++) printf(" %d", out[i]);
55+ printf("\n");
56+ (void)border;
57+ return 0;
58+}