Lane-palette charter -- palette reconstruction then intrabc
Browse files at this commite23b762ec4ff83b8a0134fcec26be13eaccf8ec2Parent: 21b2356- docs
- lane-palette charter -- palette reconstruction then intrabc
1 changed file +115 -0
- lanes/palette.charter.md +115 -0
lanes/palette.charter.mdadded+115 -0
| @@ -0,0 +1,115 @@ | |||
| 1 | +# lane-palette — palette reconstruction, then intra block copy | ||
| 2 | + | ||
| 3 | +Worktree `/home/user/Documents/Code/Rust/edith_codecs-palette`, branch | ||
| 4 | +`lane-palette`, off main (c4904ee or later). | ||
| 5 | + | ||
| 6 | +## Goal | ||
| 7 | +Two of the five coding tools that **no gate in this repository exercises** | ||
| 8 | +(main's `crates/ec-av1/src/gate_coverage.rs` pins the set) are palette and | ||
| 9 | +intrabc. Both have their syntax consumed and both refuse the moment a block | ||
| 10 | +actually uses them. Make them decode. | ||
| 11 | + | ||
| 12 | +## Where the refusals are | ||
| 13 | +- Palette, key-frame reader — `crates/ec-av1/src/decode.rs:2484-2494`: | ||
| 14 | + `"a block that actually uses a palette (Y) -- reconstruction is out of scope"` | ||
| 15 | + and the `(UV)` twin. The `palette_y_mode` / `palette_uv_mode` symbols ARE | ||
| 16 | + read; only a nonzero size refuses. | ||
| 17 | +- Palette, inter-frame intra-block reader — `decode.rs:7795-7805`, the same two | ||
| 18 | + strings. Note the comment there: `palette_mode_ctx` / `palette_uv_mode_ctx` | ||
| 19 | + are hardcoded 0, which is only safe while a nonzero neighbour `palette_size` | ||
| 20 | + is impossible. **The moment palette blocks decode, those contexts become | ||
| 21 | + live** — `av1_get_palette_mode_ctx` (pred_common.h) reads the neighbours' | ||
| 22 | + own `palette_size[0] > 0`. Class `context-read-from-one-cell` and | ||
| 23 | + `cdf-row-held-constant` both apply: fix the context in the SAME round that | ||
| 24 | + removes the refusal, or the gate will desync in a way that looks like a | ||
| 25 | + table bug. | ||
| 26 | +- Intrabc — `decode.rs:2408-2416`: | ||
| 27 | + `"a block that actually uses intrabc (this decoder never reconstructs one)"`. | ||
| 28 | +- Also `decode.rs:1940-1947`: a HORZ/VERT intra strip in a screen-content frame | ||
| 29 | + refuses because `palette_bsize_ctx` is keyed on a single side. That refusal | ||
| 30 | + is in scope for stage 3. | ||
| 31 | + | ||
| 32 | +## Anchors | ||
| 33 | +- Spec 5.11.13 `palette_mode_info`, 5.11.46 `palette_tokens`, 5.11.50 | ||
| 34 | + `get_palette_cache`, 7.11.4 `palette prediction process`; 5.11.13 | ||
| 35 | + `read_intrabc_info`, 6.10.19, 7.11.3.x for the intrabc MV rules. | ||
| 36 | +- libaom, source tree under `~/.cache/aom-oracle`: | ||
| 37 | + `av1/decoder/decodemv.c` `read_palette_mode_info` (line ~567), | ||
| 38 | + `read_palette_colors_y` / `read_palette_colors_uv`, and the delta-coded | ||
| 39 | + colour reads; `av1/common/pred_common.h` `av1_get_palette_mode_ctx` and | ||
| 40 | + `av1_get_palette_bsize_ctx`; `av1/decoder/decodetxb.c` / | ||
| 41 | + `av1/common/blockd.h` for the colour index map; `av1_get_palette_cache` | ||
| 42 | + (av1/common/reconintra.c) for the above/left colour cache; | ||
| 43 | + `read_intrabc_info` (decodemv.c ~693) and `av1_find_ref_dv` for intrabc's | ||
| 44 | + forced DV predictor and its validity bounds. | ||
| 45 | +- `crates/ec-av1/src/cdf_state.rs:425-433` already carries `palette_y_mode`, | ||
| 46 | + `palette_y_size`, `palette_uv_mode`, `palette_uv_size` with defaults and | ||
| 47 | + counter resets. The colour-index-map CDFs (`palette_y_color_index` / | ||
| 48 | + `palette_uv_color_index`, indexed by palette size and a neighbour context) | ||
| 49 | + are NOT there — adding them is four wiring sites: struct field, defaults | ||
| 50 | + array, save/restore, per-frame counter reset (`cdf_state.rs` `reset2`/`reset3` | ||
| 51 | + are length-generic and save/restore is a whole-struct Clone, so the defaults | ||
| 52 | + array is what needs hand-checking; still verify the counter reset covers the | ||
| 53 | + new tables — class `cdf-counter-not-reset`). | ||
| 54 | + | ||
| 55 | +## Staging — COMMIT AFTER EVERY GREEN MILESTONE | ||
| 56 | +1. **Palette Y.** Colour cache from the above/left neighbours, delta-coded | ||
| 57 | + colours, the colour index map (wavefront diagonal scan, the | ||
| 58 | + `palette_color_index` symbol per pixel with its neighbour context), and | ||
| 59 | + reconstruction. Fix `palette_mode_ctx` / `palette_uv_mode_ctx` to read the | ||
| 60 | + neighbours' real palette sizes in this same commit. COMMIT. | ||
| 61 | +2. **Palette UV.** COMMIT. | ||
| 62 | +3. **The rect-strip refusal** at decode.rs:1940 — key `palette_bsize_ctx` on | ||
| 63 | + both sides the way `av1_get_palette_bsize_ctx` does | ||
| 64 | + (`num_pels_log2_lookup[bsize]`). COMMIT. | ||
| 65 | +4. **Intrabc.** The DV predictor, the wavefront/delay validity bounds (a DV may | ||
| 66 | + only reference already-reconstructed pixels far enough behind the current | ||
| 67 | + superblock), and prediction from the current frame's own reconstruction. | ||
| 68 | + COMMIT. | ||
| 69 | + | ||
| 70 | +## Gate (mandatory, in `crates/ec-av1/src/stream.rs` beside the existing gates) | ||
| 71 | +- Copy an existing gate's shape. `EC_AV1_REQUIRE_AOMENC=1` must be set on every | ||
| 72 | + test run, so a missing oracle FAILS rather than SKIPs. | ||
| 73 | +- Bound every ffmpeg `generate` with `-t <seconds>`. | ||
| 74 | +- Build fixtures through the existing `gradients_source(seed, w, h, tail)` | ||
| 75 | + helper — ffmpeg's `gradients` source ignores its own seed. Palette and intrabc | ||
| 76 | + are screen-content tools: aomenc will only choose them on flat, few-colour, | ||
| 77 | + repetitive content, so you will likely need a synthetic source | ||
| 78 | + (few-colour test pattern, repeated tiles) rather than a gradient. Whatever you | ||
| 79 | + use, it must be deterministic — hash the fixture across two runs and prove it. | ||
| 80 | +- aomenc `--threads=1 --row-mt=0 --enable-palette=1` (and `--enable-intrabc=1` | ||
| 81 | + for stage 4), plus `--tune-content=screen` if that is what makes the encoder | ||
| 82 | + actually pick the tool. | ||
| 83 | +- Hard-assert firing counts via thread-local `Cell<usize>` counters in decode.rs | ||
| 84 | + matching the existing `*_HITS` (thread-local, NOT atomics): palette blocks | ||
| 85 | + reconstructed > 0, intrabc blocks > 0. A gate that cannot prove its feature | ||
| 86 | + fired is vacuous (class `gate-blind-to-feature`). | ||
| 87 | +- **Main's `gate_coverage.rs` guard will fail by design** once your gate enables | ||
| 88 | + these tools: its `NEVER_EXERCISED` list names `enable-palette` and | ||
| 89 | + `enable-intrabc`. Deleting those two entries is part of landing this work. | ||
| 90 | + | ||
| 91 | +## Method | ||
| 92 | +CLASS `compare-range-not-tell`: compare the msac RANGE against the oracle after | ||
| 93 | +each element, never `tell()`. Oracle at `~/.cache/aom-oracle`; env-gated rungs | ||
| 94 | +`EC_TRACE=1` (partitions), `EC_TRACE_COEFF=1`, `EC_TRACE_MODE=1` (inter + intra | ||
| 95 | +mode info), `EC_AV1_PREFILT_DUMP=<prefix>` (per-frame pre-filter recon — the | ||
| 96 | +right rung for separating a prediction bug from a filter one). Add a rung with | ||
| 97 | +`scripts/instrument-aom-oracle.sh` + `scripts/build-aom-oracle.sh` in the | ||
| 98 | +existing shape (env-gated, silent when unset, idempotent, wrapper-around-impl). | ||
| 99 | +CLASS `equal-range-means-unread`: reference range unchanged where ours moves = | ||
| 100 | +we read a symbol it never wrote; theirs moves and ours does not = we skipped one. | ||
| 101 | + | ||
| 102 | +## Hard rules | ||
| 103 | +- `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-palette`. Foreground | ||
| 104 | + builds, `nice -n 19 cargo ... -j4`. Give every `cargo test` a timeout of at | ||
| 105 | + least 600000 ms — the suite runs 3-4 minutes and a 120 s default kills it. | ||
| 106 | +- Sibling worktrees (edith_codecs, -chroma, -realworld, -lr, -superres, -tiles) | ||
| 107 | + have live agents. Never build in or edit them. | ||
| 108 | +- Baseline: 234 passed / 0 failed on main. | ||
| 109 | +- NEVER push, never merge, never touch `main`. Commit on `lane-palette` only. | ||
| 110 | +- 75-turn cap and it does NOT reset on resume: commit at every green step. | ||
| 111 | + Stage 1 committed and green is a good round on its own. | ||
| 112 | +- Refuse-by-name rather than desync; never claim in a refusal string that the | ||
| 113 | + encoder cannot emit a case unless you proved it. | ||
| 114 | +- End with `lanes/palette.report.md`, VERDICT on the first line: what landed, | ||
| 115 | + gate names + firing counts, remaining refusal strings verbatim, next lever. | ||