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