forge
Explore
Log in

Don't you dare go Hollow

Rectwire r1 report -- design worked out, not landed

Browse files at this commit

46dcc37fce5bf9c2062a4749d9daf417c6bf9f81Ahmet Kaan GümüşParent: 8775a26
  • docs
    • rectwire r1 report -- design worked out, not landed
Show full message
docs(av1): rectwire r1 report -- design worked out, not landed

Scan-table transpose, rect eob-context reduction, and the two missing
eob_pt CDF table sets (512-luma, 128-chroma) all cross-checked against
real libaom source with byte-level verification. Not implemented this
round: threading base_q_idx through decode_block_rect's four call
sites plus a real coefficient-decode desync risk was more edit-and-
verify surface than the remaining turn budget could safely absorb.
Full wiring plan + exact CDF values in lanes/rectwire-r1.report.md for
the next round.
lanes/rectwire-r1.report.mdadded+168 -0
@@ -0,0 +1,168 @@
1+# lane-rectwire r1 report
2+
3+VERDICT: NO CODE LANDED — design fully worked out and verified against real
4+libaom source, but not implemented, because the remaining turn budget did not
5+leave room to implement AND test-iterate a coefficient-decode surface where
6+"a desync is not acceptable" is the hard rule. Landing an unverified multi-site
7+edit at the end of a budget is exactly how a desync gets shipped; refusing by
8+inaction here is the charter's own method applied to the meta-level. Tree is
9+untouched (`git status --short` empty on HEAD), lib suite is unchanged at
10+226 passed / 0 failed, refusal counts are unchanged from before this round.
11+
12+## What actually narrowed: the scope, not the code
13+
14+`decode_block_rect` (`decode.rs:1713`) is called from exactly **four** call
15+sites, all at exactly **two** fixed size pairs: luma 32x16/16x32
16+(`decode.rs:4341-4396`, only from a 32x32 quadrant's `PARTITION_HORZ`/`VERT`)
17+and its chroma half 16x8/8x16. This is much narrower than the charter's "every
18+INTER partition below 16x16" framing suggested for the intra strip -- the
19+non-skip refusal at `decode.rs:1772-1776` only ever needs to cover these two
20+size pairs, not a general rect-tx-size machine. The INTER-partition-below-16x16
21+refusal (`decode.rs:8697`) was not investigated this round (charter: land one
22+cleanly, not both).
23+
24+## The three "missing surfaces" the charter named, resolved
25+
26+1. **Rectangular scan order.** libaom's `default_scan_WxH` tables are
27+ precomputed data, not a general algorithm in source (no generator shipped
28+ in `~/.cache/aom-oracle/src`). Extracted+transposed via a one-off script
29+ (libaom's own buffer is column-major, `col = pos >> bhl; row = pos -
30+ (col << bhl)` where `bhl = log2(height)`; our grid is row-major, so
31+ `our_pos = row * w + col`). Verified as a genuine bijection of `0..w*h` for
32+ all four needed tables (32x16, 16x32, 16x8, 8x16). Script + generated
33+ consts are in `/tmp/claude-1000/gen_scan.py` and
34+ `/tmp/claude-1000/scan_tables.rs` in this worktree's scratchpad (not
35+ copied into the repo since nothing consumes them yet).
36+
37+2. **Rectangular eob context.** `eob_coeff_ctx(scan_idx, area)` already takes
38+ `area`, not `side`, and libaom's own `get_lower_levels_ctx_eob` formula
39+ (`(width << bhl)`, i.e. `width * height`) reduces to the exact same `area`
40+ — **no change needed here**, only a caller passing `w * h` instead of
41+ `side * side`. The genuine gap is `base_ctx`'s 2D-class position-offset
42+ table (`NZ_MAP_CTX_OFFSET_32`, `cdf.rs:569`), which is square-only.
43+ libaom's own comment in `txb_common.h:189-224`
44+ (`get_nz_map_ctx_from_stats`) gives the exact rect generalization
45+ verbatim: `if width < height && row < 2: offset 11; else if width > height
46+ && col < 2: offset 16; else` fall through to the existing `row+col<2→1,
47+ <4→6, else 21` table square case already implements. Confirmed this
48+ reduces to the identical square table when `width == height` (the two new
49+ branches never fire). `br_ctx`'s neighbour-offset math is shape-independent
50+ for `TxClass::TwoD` (only the boundary clamp needs real `w`/`h` instead of
51+ one `side`).
52+
53+3. **`max_txsize_rect_lookup` threading.** Turned out to be unnecessary for
54+ this specific lift: `decode_block_rect` already resolves `tx_w = bw, tx_h
55+ = bh` directly (no split, since `depth != 0` is refused above the skip
56+ check) — the real tx size *is* the block size here, spec's rect-lookup
57+ table is a non-issue at this call site.
58+
59+## The one genuinely new piece: two CDF table sets
60+
61+Coefficient CDFs are selected by `get_txsize_entropy_ctx(tx_size) =
62+txsize_sqr_up_map[tx_size]` (`entropy.h:172`, confirmed algebraically: for any
63+2:1 rect size this reduces to exactly `sqr_up`, never the average). For our
64+two size pairs that means:
65+- 32x16/16x32 luma → same square-equivalent (`TX_32X32`) as the already-wired
66+ `TxbSet::Luma32` for **every** field except `eob_pt` — `txb_skip`, `base`,
67+ `base_eob`, `br`, `dc_sign` are all directly reusable as-is (confirmed field
68+ presence: `txb_skip_luma_32`, `base_luma_32`, `base_eob_luma_32`,
69+ `br_luma_32`, `dc_sign_luma` all already exist in `cdf_state.rs`).
70+- 16x8/8x16 chroma → same square-equivalent (`TX_16X16`) as `TxbSet::Chroma16`,
71+ same story (`txb_skip_chroma_16`, `base_chroma_16`, `base_eob_chroma_16`,
72+ `br_chroma_16`, `dc_sign_chroma` all exist).
73+
74+Only `eob_pt` differs: the real-size eob group count is `log2(w*h) - 4`
75+(`txsize_log2_minus4`, confirmed exact match against the table in
76+`common_data.h:346`), which for 32x16/16x32 is 5 (the **512**-group, 10
77+symbols) — not 6 (**1024**-group, `eob_pt_1024_luma`, what `Luma32` reads for
78+a true 32x32) — and for 16x8/8x16 is 3 (the **128**-group, 8 symbols) — not 4
79+(**256**-group, `eob_pt_256_chroma`, what `Chroma16` reads for a true 16x16).
80+Neither `eob_pt_512_luma` nor `eob_pt_128_chroma` exist in `cdf_state.rs`
81+today. Their default values (4 q-context variants each, luma plane_type 0
82+class-2D and chroma plane_type 1 class-2D) were extracted and transcribed
83+from `~/.cache/aom-oracle/src/av1/common/token_cdfs.h:829-906`
84+(`av1_default_eob_multi128_cdfs`, `av1_default_eob_multi512_cdfs`), format
85+confirmed against this codebase's own conversion convention (`AOM_CDFn`'s raw
86+arguments direct, no `AOM_ICDF` inversion — cross-checked `EOB_PT_1024_LUMA`
87+byte-for-byte against `av1_default_eob_multi1024_cdfs[2][0][0]`, an exact
88+match, q-index 2 = the unsuffixed default, 0/1/3 = `_Q0`/`_Q1`/`_Q3`):
89+
90+```
91+EOB_PT_512_LUMA (q2, plane0, class2D): 2624,3936,6480,9686,13979,17726,23267,28410,31078,32768,0
92+EOB_PT_512_LUMA_Q0: 641,983,3707,5430,10234,14958,18788,23412,26061,32768,0
93+EOB_PT_512_LUMA_Q1: 1230,2278,5035,7776,11871,15346,19590,24584,28749,32768,0
94+EOB_PT_512_LUMA_Q3: 5927,7809,10923,14597,19439,24135,28456,31142,32060,32768,0
95+
96+EOB_PT_128_CHROMA (q2, plane1, class2D): 13627,16246,20173,24429,27948,30415,31863,32768,0
97+EOB_PT_128_CHROMA_Q0: 5245,7456,12880,15852,20033,23932,27608,32768,0
98+EOB_PT_128_CHROMA_Q1: 8045,11200,15497,19595,23948,27408,30938,32768,0
99+EOB_PT_128_CHROMA_Q3: 24313,26062,28385,30107,31217,31898,32345,32768,0
100+```
101+
102+## The wiring plan (unexecuted, for the next round)
103+
104+1. `cdf.rs`: add the 8 arrays above.
105+2. `cdf_state.rs`: add `eob_pt_512_luma: [u16; 11]` / `eob_pt_128_chroma:
106+ [u16; 9]` fields, `pick()`-initialize in `Cdfs::new`, add two `TxbSet`
107+ variants (`LumaRect32x16`, `ChromaRect16x8`) whose `txb()` match arms are
108+ byte-identical to `Luma32`/`Chroma16` except `eob_pt` points at the new
109+ fields. One variant each covers both orientations (32x16 and 16x32 share
110+ one square-equivalent context; likewise 16x8/8x16) — no per-orientation
111+ duplication needed.
112+3. `decode.rs`: four new small functions mirroring the existing square ones'
113+ `TxClass::TwoD` branch only (refuse-by-name if a symbol somehow produces a
114+ different class — should be geometrically impossible here since neither
115+ size pair ever reads a `tx_type` symbol: luma's is forced `DctDct` by
116+ `EXT_TX_SET_DCTONLY` at `tx_size_sqr_up == TX_32X32`, chroma is always
117+ mode-derived via the existing `default_intra_tx_type`, spec
118+ `av1_get_ext_tx_set_type`, `blockd.h:1097`):
119+ - `nz_map_offset_2d(row, col, w, h)`, `base_ctx_rect`, `br_ctx_rect`,
120+ `neighbour_rect` (the rect generalization above).
121+ - `read_coeffs_rect(dec, coding, scan, w, h, skip_ctx, sign_ctx,
122+ default_tx_type)`, a `(w, h)`-aware copy of `read_coeffs` restricted to
123+ `TxClass::TwoD` (refuses by name otherwise).
124+ - A rect `Neighbours::around_rect` (independent `w`/`h` extents, mirroring
125+ the already-landed `record_rect`/`record_mi_rect` asymmetric-extent
126+ pattern at `decode.rs:1378-1457` — `record_mi_rect` already handles real
127+ coefficient grids correctly with no change needed, since a lone
128+ non-split TU broadcasts one state uniformly across its own mi span
129+ either way).
130+ - `decode_block_rect` gains a `base_q_idx: u8` parameter (threaded from
131+ the four already-in-scope call sites at `decode.rs:4341-4396`, where
132+ `base_q_idx` is already a local), replaces the
133+ `if !skip { return Err(...) }` block with real reads through
134+ `read_coeffs_rect` + `transform::dequant_and_inverse_typed_wh` (already
135+ landed by lane-recttx) for luma then chroma, and passes the real
136+ residual (not `vec![0i32; ...]`) into the existing `reconstruct_rect`
137+ calls and the real coefficient grid (not the zero placeholder) into
138+ `record_rect`.
139+ - A new `RECT_COEFF_HITS` atomic counter incremented once per real
140+ non-skip decode, hard-asserted `> 0` in the existing free-partition gate
141+ (`stream.rs:4060-4137`, which already tracks `rect_partition_hits` and
142+ currently only ever sees the skip case reach decode) — no new gate file
143+ needed, this lift makes the *existing* gate exercise more of the stream
144+ it already decodes.
145+
146+## Why this stopped here instead of landing partial code
147+
148+Every individual piece above was cross-checked against real libaom source
149+(not memory, not the spec's prose) with byte-level verification where a
150+mistake would desync silently: the scan-table transpose was checked as a
151+bijection, the `EOB_PT_512_LUMA`/`_128_CHROMA` q2 rows follow the exact
152+`AOM_CDFn`-argument-direct convention this codebase already uses (verified
153+against `EOB_PT_1024_LUMA`'s known-good transcription), and the
154+`nz_map_offset_2d` rect branches are libaom's own comment, not a derivation.
155+But none of it has been compiled or run against a real aomenc stream, and
156+this decode path has no tolerance for "probably right" — the method this
157+lane was chartered under is explicit that a desync is never acceptable, only
158+a clean refusal is. Implementing all of the above plus threading
159+`base_q_idx` through four call sites plus writing/running the gate assertion
160+was more edit-and-verify surface than the remaining turn budget could safely
161+absorb, so nothing was committed rather than risk landing something wrong
162+this round left no room to catch.
163+
164+## Before/after refusal counts, firing count
165+
166+Unchanged this round: both named refusals (`decode.rs:1772-1776` intra
167+HORZ/VERT non-skip, `decode.rs:8697` inter-below-16x16) still fire exactly as
168+before. No gate firing count to report — nothing new decodes yet.