forge
Explore
Log in

Don't you dare go Hollow

Lane-tiles charter -- multi-tile decode

Browse files at this commit

994cca7c7b34e0772d38f4f71d083f215ba0c23aAhmet Kaan GümüşParent: 7895d2a
  • docs
    • lane-tiles charter -- multi-tile decode
Show full message
docs(av1): lane-tiles charter -- multi-tile decode
lanes/tiles.charter.mdadded+96 -0
@@ -0,0 +1,96 @@
1+# lane-tiles — multi-tile decode
2+
3+Worktree `/home/user/Documents/Code/Rust/edith_codecs-tiles`, branch
4+`lane-tiles`, off main (48a6e29 or later).
5+
6+## Goal
7+Remove the refusal at `crates/ec-av1/src/stream.rs:293-298`
8+("a frame with more than one tile (this decoder only ever decodes tile 0)")
9+by decoding every tile of every tile group, in order, into one picture.
10+
11+## What is already there
12+- `crates/ec-av1-syntax/src/frame.rs:115` `TileInfo` already carries everything
13+ the walk needs: `cols`, `rows`, `cols_log2`, `rows_log2`, `mi_col_starts`
14+ (`TileCols + 1` entries, 4x4 units), `mi_row_starts`, `context_update_tile_id`,
15+ `tile_size_bytes`. The uniform/non-uniform spacing derivation is at
16+ `frame.rs:1292` onward and is already implemented — READ it, do not re-derive.
17+- The tile-group OBU parse already produces per-tile `offset`/`size`; today
18+ `stream.rs` takes `tiles.first()` and drops the rest. `Tile::offset` is
19+ relative to the OBU buffer, not to `data` — see the comment at stream.rs:298.
20+- The superblock walk lives in `crates/ec-av1/src/decode.rs` (two sites, around
21+ lines 4547 and 9275: `for sb_r in 0..sb_rows { for sb_c ... }`). Today those
22+ bounds are the whole frame; per tile they become the tile's own sb range
23+ derived from `mi_row_starts[t]..mi_row_starts[t+1]`.
24+
25+## The three things that make tiles more than a loop
26+1. **Entropy reset per tile.** Each tile starts a FRESH msac decoder over its
27+ own byte range AND a fresh copy of the frame's initial CDFs (spec 5.11.2
28+ `decode_tile`: `init_symbol` + `clear_above_context`). Only the tile named by
29+ `context_update_tile_id` has its END-of-tile adapted CDFs saved as the
30+ frame's output tables (spec `exit_symbol`) — every other tile's adaptation is
31+ discarded. This is exactly what the current refusal comment warns about.
32+2. **Context reset at tile boundaries.** Above-context arrays are cleared at the
33+ start of each tile ROW of superblocks within the tile; left-context at each
34+ superblock row. Neighbour availability MUST be clipped to the tile: a block
35+ at the tile's left edge has NO left neighbour even though a decoded block
36+ sits there in the picture. Same for above. Grep libaom
37+ `av1/decoder/decodeframe.c` `av1_tile_init`/`av1_tile_set_col`/
38+ `av1_tile_set_row` and `av1/common/tile_common.c`; the availability
39+ predicates are `xd->left_available` / `xd->up_available`, set in
40+ `set_mi_row_col` (av1/common/blockd.h). Deblocking and CDEF, by contrast,
41+ run ACROSS tile boundaries unless `loop_filter_across_tiles` says otherwise —
42+ check the actual v3.13.3 source, AV1 has no such flag in the final spec but
43+ verify rather than assume.
44+ Also check the mv-stack / ref-mv scan (`crates/ec-av1/src/mvstack.rs`) and
45+ the CDEF/deblock neighbour reads for the same tile clipping.
46+3. **Tile ordering across tile groups.** A frame may carry several tile-group
47+ OBUs; tiles are numbered `tg_start..tg_end` globally.
48+
49+## Method
50+CLASS `compare-range-not-tell`: compare the msac RANGE against the oracle after
51+each element, never `tell()`. The instrumented oracle is at `~/.cache/aom-oracle`
52+with env-gated rungs (`EC_TRACE=1` partitions, `EC_TRACE_COEFF=1`,
53+`EC_TRACE_MODE=1`); `scripts/instrument-aom-oracle.sh` + `scripts/build-aom-oracle.sh`
54+add and rebuild rungs. If you need a per-tile rung (tile index at each
55+`decode_tile` entry), add one in the existing shape: env-gated, silent when
56+unset, idempotent, wrapper-around-impl.
57+CLASS `equal-range-means-unread`: reference range unchanged where ours moves =
58+we read a symbol it never wrote; theirs moves and ours does not = we skipped one.
59+
60+## Staging — COMMIT AFTER EVERY GREEN MILESTONE (75-turn cap; builders have lost whole implementations here)
61+1. Two tiles, one column split, all-intra key frame. COMMIT.
62+2. Tile rows as well as columns; non-uniform spacing. COMMIT.
63+3. Inter frames (mv-stack + neighbour clipping is where this will break). COMMIT.
64+4. Several tile-group OBUs per frame. COMMIT.
65+5. `context_update_tile_id` proven: a stream where it is NOT tile 0, decoding
66+ pixel-exact across the following frame (which inherits those CDFs). COMMIT.
67+
68+## Gate (mandatory, in `crates/ec-av1/src/stream.rs` beside the existing gates)
69+- Copy the existing gate shape. Tests must be run with `EC_AV1_REQUIRE_AOMENC=1`
70+ so a missing oracle FAILS instead of SKIPping.
71+- Bound every ffmpeg `generate` with `-t <seconds>` (an unbounded source once
72+ hung a gate for an hour).
73+- Build fixtures through the existing `gradients_source(seed, w, h, tail)`
74+ helper — ffmpeg's `gradients` ignores its own seed, so a hand-written
75+ `gradients=size=` string makes the gate non-reproducible.
76+- aomenc: `--threads=1 --row-mt=0` plus `--tile-columns=1 --tile-rows=1`
77+ (log2 values in aomenc) on a frame large enough that the tiles are legal —
78+ a 64x64 frame cannot be split, so size the fixture accordingly.
79+- Hard-assert a firing count: a thread-local `Cell<usize>` counter in decode.rs
80+ matching the existing `*_HITS` (thread-local, NOT atomics), incremented per
81+ tile decoded, asserted `> 1`. CLASS `gate-blind-to-feature`: a gate that
82+ cannot prove its feature fired is vacuous.
83+- Refusals inside the gate are FORBIDDEN once the stage removing them lands.
84+
85+## Hard rules
86+- `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tiles`. Foreground builds
87+ only, `nice -n 19 cargo ... -j4`. Never build in or edit another worktree:
88+ edith_codecs, -chroma, -realworld, -lr, -superres all have agents in them NOW.
89+- Suite: `nice -n 19 cargo test -p ec-av1 --lib`, baseline 232 passed / 0 failed
90+ (~67 s). It stays green.
91+- NEVER push, never merge, never touch `main`. Commit on `lane-tiles` only.
92+- Refuse-by-name rather than desync; never write a refusal string claiming the
93+ encoder cannot emit a case unless you proved it (class
94+ `refusal-claim-disproved-by-its-own-gate`).
95+- End with `lanes/tiles.report.md`: what landed, gate name + firing count,
96+ remaining refusal strings verbatim, next lever.