forge
Explore
Log in

Don't you dare go Hollow

Lane-recttx r1 charter (rectangular inverse transforms)

Browse files at this commit

1ae8ebf842e0e73125d783da03b4292589b44a1bAhmet Kaan GümüşParent: 90aeec8
  • docs
    • lane-recttx r1 charter (rectangular inverse transforms)
Show full message
docs(av1): lane-recttx r1 charter (rectangular inverse transforms)
lanes/recttx-r1.charter.mdadded+93 -0
@@ -0,0 +1,93 @@
1+# lane-recttx r1 charter — rectangular inverse transforms in transform.rs
2+
3+## Where you are
4+Worktree /home/user/Documents/Code/Rust/edith_codecs-recttx, branch lane-recttx @ 836a002.
5+Build/test ONLY:
6+ `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-recttx CARGO_BUILD_JOBS=4 nice -n 19 cargo test -p ec-av1 --release --lib <name> -- --nocapture`
7+FOREGROUND. Never push. Never touch the main checkout or the sibling
8+-gm / -intradisp / -screen worktrees (three other lanes are live in them).
9+`fixtures` is a symlink — leave it alone.
10+WIP COMMIT after every green milestone. Budget your turns; commit compiling
11+state before you run low.
12+
13+## Why this lane exists (measured)
14+`crates/ec-av1/src/transform.rs` is entirely square: every entry point takes a
15+single `side: usize` and asserts `dequant.len() == side * side`. That single
16+fact is the ceiling under two separate capability gaps found this batch:
17+- intra HORZ/VERT strips (32x16 / 16x32) can read every symbol but can only
18+ reconstruct SKIP blocks, because `av1_get_max_uv_txsize` hands chroma a
19+ genuinely rectangular TX_16X8 / TX_8X16 with no square escape;
20+- `decode.rs:8172` refuses every inter partition below 16x16 outright, so the
21+ 8x8-OBMC gate has never fired a single 8x8 OBMC block in 80 attempts.
22+
23+This lane does NOT wire decode.rs. It makes transform.rs able to do the
24+rectangular transform correctly, with its own unit tests, so the follow-up
25+lanes have something to call.
26+
27+## Scope
28+Generalize the inverse path from `side` to `(w, h)`, keeping the CURRENT raster
29+coefficient convention (`dequant[i * w + j]`, row-major) — libaom's own buffer
30+is column-major (`input[c * txfm_size_row + r]`), so do NOT copy its indexing;
31+copy its ARITHMETIC.
32+
33+1. `inverse_transform_2d_typed(dequant, w, h, bit_depth, tx_type)`; keep a
34+ `side`-taking wrapper so no existing call site changes in this lane.
35+ Same for `dequant_and_inverse_typed`. `crate::quant::dequant` also takes
36+ `side` — widen it the same way (check what its `side` is actually used for
37+ before assuming it is only a length).
38+2. The rect scale, exactly: when `abs(log2(w) - log2(h)) == 1`, each row's
39+ input is scaled BEFORE the row transform by
40+ `round2(coeff * 2896, 12)` (libaom `NewInvSqrt2 = 2896`,
41+ `NewSqrt2Bits = 12`, av1_inv_txfm2d.c:272-276; spec 7.13.3 says the same
42+ with the literal 2896). When the log2 ratio is 0 or 2, NO scale.
43+3. Row shift by tx size, from libaom `av1_inv_txfm_shift_ls`
44+ (av1_inv_txfm2d.c:132-158). `shift[0]` is the row shift, `shift[1]` is
45+ always -4 (our existing `round2(t[i], 4)` column shift is already right).
46+ The square values our `row_shift(log2)` already returns are 4x4:0, 8x8:1,
47+ 16x16:2, 32x32:2, 64x64:2 — confirm that, then extend with the rect rows:
48+ 4x8:0 8x4:0 8x16:1 16x8:1 16x32:1 32x16:1 32x64:1 64x32:1
49+ 4x16:1 16x4:1 8x32:2 32x8:2 16x64:2 64x16:2
50+ Key it on `(w, h)`, not on a single log2.
51+4. Clamp ranges are unchanged in shape: row clamp `bit_depth + 8`, column
52+ clamp `max(bit_depth + 6, 16)`; the row pass clamps over `w` entries and
53+ the column pass over `h`.
54+5. The coded-coefficient region: the existing `if i < 32 && j < 32` zeroing
55+ generalizes to `min(w,32) x min(h,32)`. Get the axes the right way round.
56+6. `inverse_1d` is already per-axis (`log2`, kind) — the row pass uses
57+ `log2(w)` and the column pass `log2(h)`. `inverse_identity` keys its scale
58+ on the axis LENGTH, so make sure each axis passes its OWN length; an
59+ identity row on a 32x8 block is a 32-point identity, not an 8-point one.
60+ This is the single easiest place to swap the axes; test it explicitly.
61+7. FLIPADST: the existing two-buffer read/write with `lr_flip` / `ud_flip` is
62+ correct — just re-index it for `(w, h)`. `lr_flip` mirrors over `w`,
63+ `ud_flip` over `h`.
64+
65+## Tests you must write (this is most of the lane's value)
66+The oracle binaries are at ~/.cache/aom-oracle/build/ and the pinned libaom
67+source at ~/.cache/aom-oracle/src.
68+- A per-size pin: for each of the 14 rect sizes, one fixed input coefficient
69+ block through our `inverse_transform_2d_typed` compared against values
70+ TRANSCRIBED from libaom. Get those values by writing a tiny C harness that
71+ links or copies `av1_inv_txfm2d.c`'s `av1_inv_txfm2d_add_<w>x<h>_c` (or
72+ drives the facade) — put the harness in `lanes/recttx_dump.c` with its
73+ expected output checked in, the same shape as the already-landed
74+ `lanes/intrarect_dump.c` + `.expected.txt` pair on main; read that pair
75+ first and copy its structure.
76+ IMPORTANT (class `reference-layout-not-spec`): libaom's input buffer is
77+ column-major. When you feed the harness, feed the SAME logical coefficients
78+ our function gets and transpose at the boundary — then a transposed-axis bug
79+ in our code still shows up, instead of being cancelled by a transposed
80+ harness. Use an ASYMMETRIC input (different values per row AND column) for
81+ every case; a symmetric probe cannot see an axis swap.
82+- A transposed-pair sweep (class `scan-weights-cross-axis`): every WxH case is
83+ run alongside its HxW twin in the SAME test, so an axis swap fails loudly.
84+- Keep the existing square tests passing byte-identically — the square path
85+ must not move at all.
86+
87+## Done criteria
88+Square behaviour bit-identical (full lib suite `-p ec-av1 --release --lib`
89+must stay 224 passed / 0 failed); all 14 rect sizes pinned against libaom;
90+WIP commits; REPORT `lanes/recttx-r1.report.md` with VERDICT on the FIRST line,
91+the per-size pass table, and an explicit statement of what a decode.rs lane
92+still has to do to USE this (rect scan order, rect eob context, rect
93+`max_txsize_rect_lookup` threading) — that wiring is OUT of scope here.