lane-av1422ctattr: the 4:2:2 seed is INTRABC, not DC -- a category error corrected, and the rung that closes the blind spot
Browse files at this commit960e10ea25073d81e85522baa427026100d8f1a7Parent: 604fa6c4 changed files +852 -1
- crates/ec-av1/src/decode.rs +89 -1
- lanes/av1422ctattr.report.md +551 -0
- scripts/check-aom-oracle-rungs.sh +35 -0
- scripts/instrument-aom-oracle.sh +177 -0
crates/ec-av1/src/decode.rsmodified+89 -1
| @@ -26002,7 +26002,95 @@ fn sub8_leaf_chroma422( | ||
| 26002 | 26002 | // chroma px 44..47 from luma 88..95, while a `px`-anchored source |
| 26003 | 26003 | // averaged luma 92..99 and every CFL unit of the group mismatched). |
| 26004 | 26004 | let ac = alpha.map(|_| cfl_src_rect((lmi.1 & !1) * MI, py, 8, 4)); |
| 26005 | - let grids: (Grid, Grid) = if skip { | |
| 26005 | + let grids: (Grid, Grid) = if let Some(dv) = intrabc_dv.filter(|_| skip) { | |
| 26006 | + // lane-av1422ctattr: a SKIPPED intrabc chroma leaf still predicts the | |
| 26007 | + // frame copy at its DV. libaom's `decode_token_recon_block` takes the | |
| 26008 | + // INTER arm for an intrabc block (`is_inter_block` counts it, | |
| 26009 | + // `blockd.h:373`) and `predict_inter_block_visit` runs | |
| 26010 | + // `dec_build_inter_predictor` REGARDLESS of `skip_txfm` -- only the | |
| 26011 | + // residual read is dropped. Measured on the 4:2:2 seed of | |
| 26012 | + // `R422_320x242.obu` / `Q_odd320x242.obu` (chroma U(116,160)): | |
| 26013 | + // oracle EC_DP mi_row=40 mi_col=58 bsize=2 inter=1 skip_txfm=1 is_intrabc=1 | |
| 26014 | + // EC_ISTEP mi_row=40 mi_col=58 name=intrabc val=1 rng=39264 | |
| 26015 | + // EC_DV mi_row=40 mi_col=58 dv_col=0 dv_row=-1024 rng=40116 | |
| 26016 | + // ours the SAME symbol and the SAME DV (parse in sync), then | |
| 26017 | + // OUR_PRED x=116 y=160 plane=1 mode=0 row0=[182,182,182,182] | |
| 26018 | + // i.e. this `if skip` arm was taken and the `else if let Some(dv)` | |
| 26019 | + // frame copy below never ran. 202 = (808+2)/4 is not a `dc_top`: there | |
| 26020 | + // is NO DC variant at all on the oracle side, because | |
| 26021 | + // `av1_predict_intra_block` is never called for an intrabc block. | |
| 26022 | + // `sub8_leaf_chroma444` already orders its arms this way | |
| 26023 | + // (`intrabc_dv.filter(|_| skip)` first, lane-av1ibcskip2); this arm is | |
| 26024 | + // that one, at 4:2:2's square 4x4 chroma unit. | |
| 26025 | + let mut ub = vec![0u16; 16]; | |
| 26026 | + mc::predict_with_filter( | |
| 26027 | + &u.data, | |
| 26028 | + u.width, | |
| 26029 | + u.true_width, | |
| 26030 | + u.true_height, | |
| 26031 | + mv_to_q4(cpx, dv.1, ss_x(fctx)), | |
| 26032 | + mv_to_q4(cpy, dv.0, ss_y(fctx)), | |
| 26033 | + 4, | |
| 26034 | + 4, | |
| 26035 | + mc::InterpFilterKind::Bilinear, | |
| 26036 | + &mut ub, | |
| 26037 | + fctx, | |
| 26038 | + ); | |
| 26039 | + hit!(SKIPPED_INTRABC_DV_COPY_HITS); | |
| 26040 | + let zeros = &ZERO_RESIDUAL[..16]; | |
| 26041 | + set_palette_pred(ub, fctx); | |
| 26042 | + push_intra( | |
| 26043 | + 1, | |
| 26044 | + cpx, | |
| 26045 | + cpy, | |
| 26046 | + 4, | |
| 26047 | + DC_PRED, | |
| 26048 | + 0, | |
| 26049 | + reach, | |
| 26050 | + zeros, | |
| 26051 | + None, | |
| 26052 | + None, | |
| 26053 | + smooth_neighbor_uv, | |
| 26054 | + fctx, | |
| 26055 | + ); | |
| 26056 | + let mut vb = vec![0u16; 16]; | |
| 26057 | + mc::predict_with_filter( | |
| 26058 | + &v.data, | |
| 26059 | + v.width, | |
| 26060 | + v.true_width, | |
| 26061 | + v.true_height, | |
| 26062 | + mv_to_q4(cpx, dv.1, ss_x(fctx)), | |
| 26063 | + mv_to_q4(cpy, dv.0, ss_y(fctx)), | |
| 26064 | + 4, | |
| 26065 | + 4, | |
| 26066 | + mc::InterpFilterKind::Bilinear, | |
| 26067 | + &mut vb, | |
| 26068 | + fctx, | |
| 26069 | + ); | |
| 26070 | + set_palette_pred(vb, fctx); | |
| 26071 | + push_intra( | |
| 26072 | + 2, | |
| 26073 | + cpx, | |
| 26074 | + cpy, | |
| 26075 | + 4, | |
| 26076 | + DC_PRED, | |
| 26077 | + 0, | |
| 26078 | + reach, | |
| 26079 | + zeros, | |
| 26080 | + None, | |
| 26081 | + None, | |
| 26082 | + smooth_neighbor_uv, | |
| 26083 | + fctx, | |
| 26084 | + ); | |
| 26085 | + // The same arm-without-clear route the 4:2:0 tails and | |
| 26086 | + // [`sub8_leaf_chroma444`] count: a skipped leaf reads no coefficient, | |
| 26087 | + // so the inherited chroma `tx_type` is dropped unconsumed. | |
| 26088 | + if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { | |
| 26089 | + hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); | |
| 26090 | + fctx.intrabc_chroma_tx.with(|c| c.set(None)); | |
| 26091 | + } | |
| 26092 | + (Grid::Zero(16), Grid::Zero(16)) | |
| 26093 | + } else if skip { | |
| 26006 | 26094 | // A skipped chroma-reference leaf still predicts (the CfL contribution |
| 26007 | 26095 | // survives a skip); no coefficient symbol exists. |
| 26008 | 26096 | if alpha.is_some() { |
lanes/av1422ctattr.report.mdadded+551 -0
| @@ -0,0 +1,551 @@ | ||
| 1 | +# lane-av1422ctattr — the seed's 202 is an INTRABC frame copy, not a `dc_top`; and the defect is FIXED, all seven cells byte-exact | |
| 2 | + | |
| 3 | +**Outcome in one line: both instrument gaps are closed, the oracle's `202` at the | |
| 4 | +seed is attributed to a named call site (`dec_build_inter_predictor`, via | |
| 5 | +`predict_inter_block`, because the block is INTRABC and `av1_predict_intra_block` | |
| 6 | +is never called), and our line — `sub8_leaf_chroma422` testing `skip` before | |
| 7 | +`intrabc_dv` — is fixed, taking all four failing cells plus both controls plus the | |
| 8 | +reproducer to byte-exact on every plane of every decode frame.** | |
| 9 | + | |
| 10 | +Tip: `main` = `0f9ea788`. Worktree `/home/user/.cache/wt/av1422ctattr`, branch | |
| 11 | +`lane-av1422ctattr`. Three files changed: `crates/ec-av1/src/decode.rs` (the fix), | |
| 12 | +`scripts/instrument-aom-oracle.sh` (rungs 19/20/21), | |
| 13 | +`scripts/check-aom-oracle-rungs.sh` (their assertions). | |
| 14 | +`crates/ec-av1/src/stream.rs` carried the temporary 4:2:2 refusal bypass during | |
| 15 | +measurement and is **restored** (see §8/§9). No push, no merge, no rustfmt. | |
| 16 | + | |
| 17 | +--- | |
| 18 | + | |
| 19 | +## 0. What the brief assumed, and what measurement says | |
| 20 | + | |
| 21 | +| brief's premise | measured verdict | | |
| 22 | +|---|---| | |
| 23 | +| the oracle's chroma at the seed is a `dc_top` prediction | **REFUTED** — there is no DC variant: the block is INTRABC and no intra prediction runs at all (§4) | | |
| 24 | +| the block structure at the seed is unreadable (no root at `mi_row=20, mi_col 24..31`) | **REFUTED as a label-space problem** — libaom's `MI_SIZE` is **4**, not 8; the seed is `mi_row=40, mi_col=58` and both ladders already agreed there (§3) | | |
| 25 | +| the writer is a third path | **CONFIRMED** — intra block copy, `decodeframe.c:688` `dec_build_inter_predictor` (§4) | | |
| 26 | +| our line is the availability gate / the DC arithmetic | **REFUTED (again, now measured)** — our parse of the seed is bit-identical to the oracle's, symbol for symbol (§4) | | |
| 27 | +| the fix must be gated | the 4:2:2 defect is **not gateable from a committed test** (§8); the fix is verified by the six 4:2:2 corpus cells + the reproducer against aomdec | | |
| 28 | + | |
| 29 | +--- | |
| 30 | + | |
| 31 | +## 1. Reproduction, by me, from scratch | |
| 32 | + | |
| 33 | +Source (hand-built y4m; ffmpeg will not write a `C422` tag): | |
| 34 | + | |
| 35 | +``` | |
| 36 | +ffmpeg -v error -f lavfi -i testsrc2=size=320x242:rate=25 -frames:v 16 \ | |
| 37 | + -pix_fmt yuv422p -f rawvideo src.raw -y | |
| 38 | +# header "YUV4MPEG2 W320 H242 F25:1 Ip A1:1 C422\n", then "FRAME\n" + 320*242 | |
| 39 | +# + 2*(160*242) bytes per frame -> 2 478 215 B | |
| 40 | +``` | |
| 41 | + | |
| 42 | +Encode: | |
| 43 | + | |
| 44 | +``` | |
| 45 | +/home/user/.cache/aom-oracle/build/aomenc --codec=av1 --profile=2 \ | |
| 46 | + --input-bit-depth=8 --bit-depth=8 --limit=16 --lag-in-frames=25 --auto-alt-ref=1 \ | |
| 47 | + --enable-global-motion=1 --pass=1 --cq-level=24 --threads=4 --kf-min-dist=0 \ | |
| 48 | + --kf-max-dist=999999 --width=320 --height=242 --cpu-used=0 src.y4m -o n.webm | |
| 49 | +ffmpeg -v error -i n.webm -c copy -f obu R422_320x242.obu -y | |
| 50 | +``` | |
| 51 | + | |
| 52 | +| artifact | bytes | sha256 | | |
| 53 | +|---|---|---| | |
| 54 | +| **`R422_320x242.obu` (mine)** | **20 733** | **`909e58db18fd4b7590501e2cecfbc090cde49eb26c9a42e15b1ef1fc265843d8`** | | |
| 55 | + | |
| 56 | +Byte-identical to the predecessor's `MYREPRO`/`R422_320x242.obu` — the recipe is | |
| 57 | +deterministic and reproduces exactly. | |
| 58 | + | |
| 59 | +First bad decode frame / byte, measured with `planecmp.py` + `cmp` on | |
| 60 | +`EC_AV1_FINAL_DUMP` decode-order dumps from both sides: | |
| 61 | + | |
| 62 | +| cell | decode frames | first bad decode frame | first bad byte | | |
| 63 | +|---|---|---|---| | |
| 64 | +| **`R422_320x242` (mine, fresh)** | 17 | **0** | **103156** | | |
| 65 | +| `Q_odd320x242` (corpus) | 17 | **0** | **103156** | | |
| 66 | +| `O_odd322x242` | 17 | 0 | 106388 | | |
| 67 | +| `AB_inter_warp_odd` | 43 | 0 | 110876 | | |
| 68 | +| `S_odd326x242_10b` | 17 | 0 | 214112 | | |
| 69 | +| `R_odd322x240` (control) | 17 | — | — | | |
| 70 | +| `V_tile2x2_odd` (control) | 17 | — | — | | |
| 71 | + | |
| 72 | +The predecessor's byte table is reproduced exactly. | |
| 73 | + | |
| 74 | +**Oracle control.** I did not build on the shared oracle tree (three lanes were | |
| 75 | +running). I copied `~/.cache/aom-oracle/src` to | |
| 76 | +`/home/user/.cache/aom-oracle-av1422ctattr/src` and configured a private build | |
| 77 | +(`-DENABLE_EXAMPLES=1` is required — `aomdec` is gated on `ENABLE_EXAMPLES`, not | |
| 78 | +`ENABLE_TOOLS`, in libaom's `CMakeLists.txt:456`). Its `aomdec` output is | |
| 79 | +**byte-identical to the shared one on all 17 frames** of `R422_320x242.obu`, and its | |
| 80 | +`EC_TRACE` stderr is byte-identical to the shared oracle's `EC_TRACE` stderr | |
| 81 | +(`cmp` clean, 11 136 lines). It stays byte-identical after my rungs are added, with | |
| 82 | +no env set. The oracle diff below is therefore a real oracle diff, not a rebuild | |
| 83 | +artefact. | |
| 84 | + | |
| 85 | +--- | |
| 86 | + | |
| 87 | +## 2. Instrument gap 1 — CLOSED (three new oracle rungs, via the generator) | |
| 88 | + | |
| 89 | +All three are in `scripts/instrument-aom-oracle.sh` (the source of truth) and | |
| 90 | +asserted in `scripts/check-aom-oracle-rungs.sh`. | |
| 91 | + | |
| 92 | +### rung 19 `EC_PIB` — every `av1_predict_intra_block` call, before any early return | |
| 93 | + | |
| 94 | +The function has three exits that print nothing: the palette early return, the | |
| 95 | +8-bit non-directional early return, and the high-bitdepth one. `EC_PREDOUT8` / | |
| 96 | +`EC_PRED` cover only the last two's bodies, so a region with no rung line is | |
| 97 | +consistent with three different writers. `EC_PIB` prints the call identity at the | |
| 98 | +prologue: | |
| 99 | + | |
| 100 | +``` | |
| 101 | +EC_PIB mi_row=%d mi_col=%d plane=%d row_off=%d col_off=%d txw=%d txh=%d mode=%d | |
| 102 | + use_palette=%d filter_intra=%d bsize=%d px=%d py=%d hbd=%d | |
| 103 | +``` | |
| 104 | + | |
| 105 | +`EC_PIB=1`; optional `EC_PIBWIN="mi_row_lo:mi_row_hi:mi_col_lo:mi_col_hi"` | |
| 106 | +(any field `< 0` = any) to isolate a seed without dumping a frame. | |
| 107 | + | |
| 108 | +### rung 20 `EC_DCIN` — the DC path's availability INPUTS and the variant id | |
| 109 | + | |
| 110 | +`dc_predictor`'s four variants are selected by `(have_top, have_left)` and scaled by | |
| 111 | +`(n_top_px, n_left_px)`. `EC_PREDOUT8` printed neither, so "libaom used `dc_top`" | |
| 112 | +was an inference from the predicted number. `EC_DCIN` prints, at both the 8-bit and | |
| 113 | +the high-bitdepth non-directional sites, before the predictor call: | |
| 114 | + | |
| 115 | +``` | |
| 116 | +EC_DCIN mi_row mi_col plane row_off col_off txw txh mode | |
| 117 | + have_top have_left n_top n_left atop aleft dcv | |
| 118 | + up left cup cleft ss_x ss_y bsize | |
| 119 | +``` | |
| 120 | + | |
| 121 | +`dcv`: 0 = `dc` (both edges), 1 = `dc_top`, 2 = `dc_left`, 3 = `dc_128`. `atop`/ | |
| 122 | +`aleft` are the two edge sums the DC is taken from; `up`/`left`/`cup`/`cleft` are | |
| 123 | +the raw availability bits, including `set_mi_row_col`'s per-plane | |
| 124 | +`chroma_*_available` narrowing (`av1_common_int.h:1367-1379`). So the variant is now | |
| 125 | +a printed field. | |
| 126 | + | |
| 127 | +### rung 21 `EC_DP` — the branch `decode_token_recon_block` takes | |
| 128 | + | |
| 129 | +``` | |
| 130 | +EC_DP mi_row mi_col bsize inter chroma_ref skip_txfm bw bh planes is_intrabc | |
| 131 | +``` | |
| 132 | + | |
| 133 | +`decode_token_recon_block` has two arms (intra prints a rung, inter does not) and | |
| 134 | +the intra arm skips chroma on `plane && !xd->is_chroma_ref`. `EC_DP` names which. | |
| 135 | + | |
| 136 | +### The seed's new rung output | |
| 137 | + | |
| 138 | +`EC_DP=1 EC_PIB=1 EC_DCIN=1 EC_PIBWIN=39:43:56:60`, `Q_odd320x242.obu`, decode | |
| 139 | +frame 0 (frame boundary located by the second `EC_PART mi_row=0 mi_col=0 bsize=15` | |
| 140 | +SB root): | |
| 141 | + | |
| 142 | +``` | |
| 143 | +EC_DP mi_row=40 mi_col=58 bsize=2 inter=1 chroma_ref=1 skip_txfm=1 bw=2 bh=1 planes=3 is_intrabc=1 | |
| 144 | +EC_DP mi_row=41 mi_col=58 bsize=2 inter=1 chroma_ref=1 skip_txfm=0 bw=2 bh=1 planes=3 is_intrabc=1 | |
| 145 | +``` | |
| 146 | + | |
| 147 | +`bsize=2` is `BLOCK_8X4` — the shape we already knew. **`inter=1` and | |
| 148 | +`is_intrabc=1`**: these two leaves are **intra block copy**. And in the whole frame-0 | |
| 149 | +window there is **no `EC_PIB` line at `mi_row=40`/`41, mi_col=58` at all** — i.e. | |
| 150 | +`av1_predict_intra_block` is never called for this block, on any plane. For | |
| 151 | +comparison, the neighbour group one column left does print: | |
| 152 | + | |
| 153 | +``` | |
| 154 | +EC_PIB mi_row=40 mi_col=56 plane=1 row_off=0 col_off=0 txw=4 txh=8 mode=2 use_palette=0 filter_intra=5 bsize=3 px=0 py=0 hbd=0 | |
| 155 | +EC_PIB mi_row=42 mi_col=58 plane=0 row_off=0 col_off=0 txw=8 txh=8 mode=11 use_palette=0 filter_intra=5 bsize=3 px=0 py=0 hbd=0 | |
| 156 | +``` | |
| 157 | + | |
| 158 | +The rung fires; it is silent exactly at the seed. | |
| 159 | + | |
| 160 | +### Checker | |
| 161 | + | |
| 162 | +`scripts/check-aom-oracle-rungs.sh <private src>` — exit 0, every assertion green, | |
| 163 | +including the four new ones: | |
| 164 | + | |
| 165 | +``` | |
| 166 | +ok rung 19 EC_PIB install sites (av1_predict_intra_block prologue) 1 | |
| 167 | +ok rung 19 EC_PIB carries use_palette= (the early-return bit) 1 | |
| 168 | +ok rung 20 EC_DCIN install sites (8-bit + hbd non-directional) 2 | |
| 169 | +ok rung 20 EC_DCIN prints availability operands + dcv + availability bits 2 | |
| 170 | +ok rung 21 EC_DP install sites (decode_token_recon_block) 1 | |
| 171 | +ok rung 21 EC_DP carries is_intrabc= (the intra/inter branch bit) 1 | |
| 172 | +ok instrument-aom-oracle.sh derives the depth-correct, byte-checked rungs (base v3.13.3) | |
| 173 | +``` | |
| 174 | + | |
| 175 | +Idempotence: the generator run twice over the tree leaves both derived files | |
| 176 | +`cmp`-identical. | |
| 177 | + | |
| 178 | +--- | |
| 179 | + | |
| 180 | +## 3. Instrument gap 2 — CLOSED, and the gap was a unit error | |
| 181 | + | |
| 182 | +**libaom's `MI_SIZE` is 4, not 8.** `av1/common/enums.h:39-40`: | |
| 183 | + | |
| 184 | +```c | |
| 185 | +#define MI_SIZE_LOG2 2 | |
| 186 | +#define MI_SIZE (1 << MI_SIZE_LOG2) | |
| 187 | +``` | |
| 188 | + | |
| 189 | +So `mi_cols = (width+3)>>2 = 80` for a 320-wide frame and `mib_size = 128>>2 = 32`. | |
| 190 | +The tell in the ladder is that the SB roots land at `mi_col = 0, 32, 64` and | |
| 191 | +`mi_row = 0, 32` — not `0,16,32`. The predecessor read the ladder on an 8-px grid, | |
| 192 | +concluded "no root covers `mi_row=20, mi_col 24..31`", and attributed it to the | |
| 193 | +documented label-space trap. On the correct grid the seed is `mi_row=40, mi_col=58` | |
| 194 | +— which is **exactly the `mi=(40,58)` our own trace already printed**, because | |
| 195 | +ec-av1's `MI` is 4 too (`decode.rs:7355`). There was never a label mismatch. | |
| 196 | + | |
| 197 | +Both ladders, frame 0, at the seed (oracle `EC_TRACE` vs our `EC_AV1_TRACE`): | |
| 198 | + | |
| 199 | +| oracle | ours | | |
| 200 | +|---|---| | |
| 201 | +| `EC_PART_VAL mi_row=40 mi_col=56 bsize=9 value=3` | `TRACE partition_w32 mi=(40,56) ctx=3 value=3` | | |
| 202 | +| `EC_PART_VAL mi_row=40 mi_col=56 bsize=6 value=3` | `TRACE partition_w16 mi=(40,56) ctx=3 value=3` | | |
| 203 | +| `EC_PART_VAL mi_row=40 mi_col=56 bsize=3 value=0` | `TRACE partition_w8 mi=(40,56) ctx=0 value=0` | | |
| 204 | +| `EC_PART_VAL mi_row=40 mi_col=58 bsize=3 value=1` | `TRACE partition_w8 mi=(40,58) ctx=0 value=1` | | |
| 205 | +| `EC_ISTEP mi_row=40 mi_col=58 name=skip val=1` | `TRACE sub8 skip mi=(40,58) ctx=1 value=1` | | |
| 206 | +| `EC_ISTEP mi_row=41 mi_col=58 name=skip val=0` | `TRACE sub8 skip mi=(41,58) ctx=1 value=0` | | |
| 207 | + | |
| 208 | +Structure, skip bits and labels agree exactly. **Candidate (c) — "our parse of the | |
| 209 | +block structure is wrong at the seed" — is refuted.** | |
| 210 | + | |
| 211 | +The oracle's ladder is not incomplete: it covers the seed. What it could not | |
| 212 | +express was *which arm wrote the block*, and `EC_PIB`/`EC_DP` (rung 19/21) supply | |
| 213 | +that. `EC_TRACE`'s own 4 498 `EC_PART_VAL` entries do include the seed's whole | |
| 214 | +ancestry; the ladder was read in the wrong unit. | |
| 215 | + | |
| 216 | +--- | |
| 217 | + | |
| 218 | +## 4. THE ATTRIBUTION: which path wrote 202 | |
| 219 | + | |
| 220 | +### The chain, with every link printed | |
| 221 | + | |
| 222 | +Oracle, `Q_odd320x242.obu`, decode frame 0, `EC_TRACE_MODE_STEP=1 EC_DP=1`: | |
| 223 | + | |
| 224 | +``` | |
| 225 | +EC_ISTEP mi_row=40 mi_col=58 name=skip val=1 rng=44808 | |
| 226 | +EC_ISTEP mi_row=40 mi_col=58 name=cdef val=0 rng=44808 | |
| 227 | +EC_ISTEP mi_row=40 mi_col=58 name=dq val=37 rng=44808 | |
| 228 | +EC_ISTEP mi_row=40 mi_col=58 name=intrabc val=1 rng=39264 | |
| 229 | +EC_DV mi_row=40 mi_col=58 dv_col=0 dv_row=-1024 rng=40116 | |
| 230 | +EC_DP mi_row=40 mi_col=58 bsize=2 inter=1 chroma_ref=1 skip_txfm=1 bw=2 bh=1 planes=3 is_intrabc=1 | |
| 231 | +EC_ISTEP mi_row=41 mi_col=58 name=intrabc val=1 rng=47584 | |
| 232 | +EC_DV mi_row=41 mi_col=58 dv_col=0 dv_row=-1024 rng=53388 | |
| 233 | +EC_DP mi_row=41 mi_col=58 bsize=2 inter=1 chroma_ref=1 skip_txfm=0 bw=2 bh=1 planes=3 is_intrabc=1 | |
| 234 | +``` | |
| 235 | + | |
| 236 | +Ours, the same block, `EC_TRACE_MODE_STEP=1`: | |
| 237 | + | |
| 238 | +``` | |
| 239 | +EC_IMODE mi_row=40 mi_col=58 fn=sub8 rng=51276 | |
| 240 | +EC_ISTEP mi_row=40 mi_col=58 name=skip val=1 rng=44808 | |
| 241 | +EC_ISTEP mi_row=40 mi_col=58 name=cdef val=0 rng=44808 | |
| 242 | +EC_ISTEP mi_row=40 mi_col=58 name=dq val=0 rng=44808 <- see note | |
| 243 | +EC_ISTEP mi_row=40 mi_col=58 name=intrabc val=1 rng=39264 <- IDENTICAL | |
| 244 | +EC_DV mi_row=40 mi_col=58 dv_col=0 dv_row=-1024 rng=40116 <- IDENTICAL | |
| 245 | +EC_IMODE mi_row=41 mi_col=58 fn=sub8 rng=40116 | |
| 246 | +EC_ISTEP mi_row=41 mi_col=58 name=intrabc val=1 rng=47584 <- IDENTICAL | |
| 247 | +EC_DV mi_row=41 mi_col=58 dv_col=0 dv_row=-1024 rng=53388 <- IDENTICAL | |
| 248 | +``` | |
| 249 | + | |
| 250 | +(Note: our `dq` line prints a placeholder `0`, not the coded `base_q_idx` — that | |
| 251 | +print is our own and is not a signal value; `rng` agrees on every real symbol.) | |
| 252 | + | |
| 253 | +**Our entropy parse at the seed is bit-identical to the oracle's.** The predecessor's | |
| 254 | +"parse in sync" finding is confirmed at symbol granularity: same `use_intrabc`, same | |
| 255 | +DV, same rng. So the divergence is purely in what is *reconstructed*. | |
| 256 | + | |
| 257 | +### The writer | |
| 258 | + | |
| 259 | +`read_intra_frame_mode_info` returns immediately after `read_intrabc_info` | |
| 260 | +(`av1/decoder/decodemv.c:936-939`): | |
| 261 | + | |
| 262 | +```c | |
| 263 | + if (av1_allow_intrabc(cm)) { | |
| 264 | + read_intrabc_info(cm, dcb, r); | |
| 265 | + if (is_intrabc_block(mbmi)) return; /* no y_mode, no uv_mode, ... */ | |
| 266 | + } | |
| 267 | +``` | |
| 268 | + | |
| 269 | +so `mbmi->mode = DC_PRED` and `mbmi->uv_mode = UV_DC_PRED` are *assignment | |
| 270 | +defaults* set inside `read_intrabc_info` (`decodemv.c:756-760`), not a coded mode — | |
| 271 | +and, more importantly, `av1_predict_intra_block` is never reached. Then | |
| 272 | +`decode_token_recon_block`'s `else` arm runs | |
| 273 | +(`av1/decoder/decodeframe.c:1302` → `decode_token_recon_block` → `else { td-> | |
| 274 | +predict_inter_block_visit(cm, dcb, bsize); … }`), i.e. | |
| 275 | + | |
| 276 | +* **`predict_inter_block`, `av1/decoder/decodeframe.c:918`** — the loop hits | |
| 277 | + `if (frame < LAST_FRAME) { assert(is_intrabc_block(mbmi)); assert(frame == | |
| 278 | + INTRA_FRAME); }` (`decodeframe.c:928-931`), so no `av1_setup_pre_planes` runs and | |
| 279 | + the "reference" is the current frame; and | |
| 280 | +* **`dec_build_inter_predictor`, `av1/decoder/decodeframe.c:688`** → | |
| 281 | + `av1_build_inter_predictor`, which **copies** from the current frame at | |
| 282 | + `(mi_x + mv.col, mi_y + mv.row)`. | |
| 283 | + | |
| 284 | +The `skip_txfm` bit changes nothing about this: the inter arm calls | |
| 285 | +`predict_inter_block_visit` unconditionally, and only the residual read is dropped | |
| 286 | +(`decodeframe.c:1225-1249`). | |
| 287 | + | |
| 288 | +**Therefore the 202 is a bilinear copy of a flat 202 region at DV | |
| 289 | +`(0, -1024)` (1/8-pel, i.e. 128 luma rows above) — it is not a DC prediction, and | |
| 290 | +"which DC variant" is a category error: no DC variant exists on the oracle side for | |
| 291 | +this unit.** Every `EC_PIB`/`EC_PREDOUT8`/`EC_PRED` rung is silent there because the | |
| 292 | +function is not called. | |
| 293 | + | |
| 294 | +Candidates from the brief, dispositioned: | |
| 295 | + | |
| 296 | +* **(a) a different block/mode whose prediction is flat 202** — **refuted**: the | |
| 297 | + block is the 8x4 leaf at `mi(40,58)` we already had (same labels, same partition, | |
| 298 | + same skip), and it is not predicted at all. | |
| 299 | +* **(b) a path that is not `av1_predict_intra_block`** — **CONFIRMED**: | |
| 300 | + `dec_build_inter_predictor` (decodeframe.c:688) under `predict_inter_block` | |
| 301 | + (decodeframe.c:918), reached because the block is INTRABC. | |
| 302 | +* **(c) our block structure being wrong at the seed** — **refuted** by §3's | |
| 303 | + side-by-side ladder. | |
| 304 | + | |
| 305 | +### The refutations the brief told me not to re-derive — now measured, not inferred | |
| 306 | + | |
| 307 | +* The seed's above row and left column are byte-identical on both sides, but that | |
| 308 | + is irrelevant: neither side reads them. | |
| 309 | +* libaom's `chroma_left_available` for this leaf is indeed 1 (the `bw < 2` clause is | |
| 310 | + dead at `bw = 2`), which is why "`dc_top`" was always going to be the wrong | |
| 311 | + story: no DC path runs. | |
| 312 | +* `intra::dc`'s arithmetic is not involved. | |
| 313 | + | |
| 314 | +--- | |
| 315 | + | |
| 316 | +## 5. OUR LINE, named, and the fix | |
| 317 | + | |
| 318 | +`crates/ec-av1/src/decode.rs`, `sub8_leaf_chroma422` (the 4:2:2 sub-8 chroma unit | |
| 319 | +reader). Before: | |
| 320 | + | |
| 321 | +```rust | |
| 322 | +let grids: (Grid, Grid) = if skip { | |
| 323 | + … push_intra(plane, cpx, cpy, 4, uv_predict_mode, …) // intra DC | |
| 324 | +} else if let Some(dv) = intrabc_dv { | |
| 325 | + … mc::predict_with_filter(… dv …) // frame copy | |
| 326 | +``` | |
| 327 | + | |
| 328 | +The seed's leaf has `skip_txfm = 1` and `intrabc_dv = Some((0, -1024))`, so the | |
| 329 | +**`if skip` arm won and the frame copy below never ran**. Our prediction there: | |
| 330 | + | |
| 331 | +``` | |
| 332 | +@decode.rs:4641 OUR_PRED x=116 y=160 plane=1 side=4 side=4 mode=0 ad=0 ft=0 sum=2912 row0=[182,182,182,182] | |
| 333 | +``` | |
| 334 | + | |
| 335 | +182 = `(808 + 644 + 4)/8` — our DC, from an edge pair that the oracle never read. | |
| 336 | +The sibling leaf at `mi(41,58)` has `skip_txfm = 0`, takes the copy arm, and is | |
| 337 | +byte-identical on both sides — which is exactly the predecessor's §6 observation | |
| 338 | +that "the second unit is byte-identical on both sides". | |
| 339 | + | |
| 340 | +The fix mirrors `sub8_leaf_chroma444`, which already orders its arms this way | |
| 341 | +(`intrabc_dv.filter(|_| skip)` first, lane-av1ibcskip2): | |
| 342 | + | |
| 343 | +```rust | |
| 344 | +let grids: (Grid, Grid) = if let Some(dv) = intrabc_dv.filter(|_| skip) { | |
| 345 | + // frame copy at the DV, no coefficient, then the armed-slot clear | |
| 346 | +} else if skip { | |
| 347 | + … unchanged … | |
| 348 | +} else if let Some(dv) = intrabc_dv { | |
| 349 | + … unchanged … | |
| 350 | +``` | |
| 351 | + | |
| 352 | +The armed-`intrabc_chroma_tx` clear at the end of the new arm is **load-bearing**, | |
| 353 | +not decoration: without it the previously-exact controls `R_odd322x240` and | |
| 354 | +`V_tile2x2_odd` broke and `S_odd326x242_10b` regressed 1052 → 22 915 (§7 records | |
| 355 | +that intermediate measurement). A skipped leaf reads no chroma coefficient, so the | |
| 356 | +inherited chroma `tx_type` must be dropped unconsumed, exactly like every other skip | |
| 357 | +route. | |
| 358 | + | |
| 359 | +After, our prediction at the seed: | |
| 360 | + | |
| 361 | +``` | |
| 362 | +@decode.rs:4641 OUR_PRED x=116 y=160 plane=1 side=4 side=4 mode=0 ad=0 ft=0 sum=3232 row0=[202,202,202,202] | |
| 363 | +``` | |
| 364 | + | |
| 365 | +--- | |
| 366 | + | |
| 367 | +## 6. Per-cell, per-plane, per-decode-frame measurement | |
| 368 | + | |
| 369 | +`FINAL` (post-filter) decode-order dumps from both sides, wrong-SAMPLE counts | |
| 370 | +(`planecmp.py`). **Before** = the lane baseline; **after** = with the fix. | |
| 371 | + | |
| 372 | +| cell | frames | before Y/U/V | after Y/U/V | after total | | |
| 373 | +|---|---|---|---|---| | |
| 374 | +| `R422_320x242` (mine) | 17 | 0 / **6 337** / **8 398** | 0 / **0** / **0** | **0 (EXACT)** | | |
| 375 | +| `Q_odd320x242` | 17 | 0 / **9 603** / **14 456** | 0 / **0** / **0** | **0 (EXACT)** | | |
| 376 | +| `O_odd322x242` | 17 | 0 / **985** / **722** | 0 / **0** / **0** | **0 (EXACT)** | | |
| 377 | +| `AB_inter_warp_odd` | 43 | 0 / **3 705** / **4 366** | 0 / **0** / **0** | **0 (EXACT)** | | |
| 378 | +| `S_odd326x242_10b` | 17 | 0 / **301** / **751** | 0 / **0** / **0** | **0 (EXACT)** | | |
| 379 | +| `R_odd322x240` (control) | 17 | 0 / 0 / 0 | 0 / 0 / 0 | 0 (EXACT, held) | | |
| 380 | +| `V_tile2x2_odd` (control) | 17 | 0 / 0 / 0 | 0 / 0 / 0 | 0 (EXACT, held) | | |
| 381 | + | |
| 382 | +Before, per decode frame (frame 0..9), for the record: | |
| 383 | + | |
| 384 | +``` | |
| 385 | +R422_320x242 0/369/376 0/165/258 0/358/445 0/400/500 0/344/437 0/418/503 0/459/608 0/416/570 0/386/516 0/371/517 | |
| 386 | +Q_odd320x242 0/422/379 0/313/758 0/511/560 0/522/851 0/511/636 0/619/745 0/610/992 0/538/664 0/719/1191 0/606/981 | |
| 387 | +O_odd322x242 0/32/16 0/59/36 0/59/32 0/69/40 0/69/32 0/51/41 0/54/35 0/55/40 0/73/46 0/60/54 | |
| 388 | +AB_inter… 0/32/32 0/61/66 0/64/78 0/112/114 0/64/64 0/62/64 0/89/85 0/116/117 0/123/121 0/111/146 | |
| 389 | +S_odd…10b 0/17/32 0/20/55 0/3/25 0/27/54 0/43/68 0/41/78 0/25/43 0/5/42 0/18/39 0/5/34 | |
| 390 | +``` | |
| 391 | + | |
| 392 | +After: **all 17 (43) frames of all seven cells are byte-identical**, not merely | |
| 393 | +low-count. | |
| 394 | + | |
| 395 | +### Oracle-flip control, after the fix | |
| 396 | + | |
| 397 | +One bit flipped in the oracle's own frame-0 mid-frame byte (byte 125 830, U plane, | |
| 398 | +y=60 x=70), same comparator: | |
| 399 | + | |
| 400 | +| | wrong bytes vs ours | | |
| 401 | +|---|---| | |
| 402 | +| unflipped oracle frame 0 | **0** | | |
| 403 | +| flipped oracle frame 0 | **1** (exactly that byte) | | |
| 404 | + | |
| 405 | +The comparator bites on the new state: exactly one flipped bit produces exactly one | |
| 406 | +extra wrong sample, in the plane the flip landed in. | |
| 407 | + | |
| 408 | +### 4:2:0 / 4:4:4 controls — the fix is chroma-format-local, as it should be | |
| 409 | + | |
| 410 | +| cell | recipe | ours/oracle frames | exact | | |
| 411 | +|---|---|---|---| | |
| 412 | +| `C420` | testsrc2 320x242 yuv420p, the §1 recipe, `--profile=0` | 17 / 17 | **17/17** | | |
| 413 | +| `C444` | testsrc2 320x242 yuv444p, same | 17 / 17 | **17/17** | | |
| 414 | +| `sc_420` / `sc_444` | flat-rectangle screen content, `--deltaq-mode=3 --tune-content=screen` (194 INTRABC blocks in `sc_444`) | 16-17 | **exact** | | |
| 415 | +| `c_420` / `c_444` | same recipe at the original `testsrc2` source | 17 / 17 | **17/17** | | |
| 416 | + | |
| 417 | +--- | |
| 418 | + | |
| 419 | +## 7. Class sweep | |
| 420 | + | |
| 421 | +The class is *a SKIPPED intrabc block still predicts (libaom predicts regardless of | |
| 422 | +`skip_txfm`)*. Every arm in ec-av1 that can carry an intrabc DV, and its ordering: | |
| 423 | + | |
| 424 | +| site | ordering | verdict | | |
| 425 | +|---|---|---| | |
| 426 | +| `sub8_leaf_chroma422` (4:2:2 sub-8 chroma) | was `if skip` first | **DEFECT — fixed here** | | |
| 427 | +| `sub8_leaf_chroma444` (4:4:4 sub-8 chroma) | `intrabc_dv.filter(\|_\| skip)` first (lane-av1ibcskip2) | correct | | |
| 428 | +| `decode_leaf_rect8`'s 4:2:0 group tail | skip test is INSIDE the intrabc arm (`if leaf_skips[1]`) | correct | | |
| 429 | +| `decode_leaf_split4`'s 4-leaf group tail (26707) | `if leaf_skips[3] { intra } else if last_intrabc { copy + chroma coeffs }` — the intrabc arm does **not** test `leaf_skips[3]` | **structurally suspect, NOT measured** | | |
| 430 | +| `decode_leaf8`'s square leaf (23792) | `LEAF8_INTRABC_HITS` path | correct (lane-kf900) | | |
| 431 | + | |
| 432 | +For the suspect site I added a temporary env-gated probe at exactly | |
| 433 | +`leaf_skips[3] && last_intrabc.is_some()` and decoded every 4:2:0 / 4:4:4 cell I | |
| 434 | +could build (6 encodes: `c_420`, `c_444`, `sc_420`, `sc_444`, `sc_420deltaqmodetune`, | |
| 435 | +`sc_444deltaqmodetune`) plus all seven 4:2:2 cells: **0 hits on all 13**. So it is | |
| 436 | +structurally reachable but unexercised by any material in hand. I did **not** change | |
| 437 | +it — changing an unexercised arm on reasoning alone is exactly how the two controls | |
| 438 | +in §6 got broken once already. The probe is removed from the tree. Building a | |
| 439 | +witness for it is the named follow-up (§10). | |
| 440 | + | |
| 441 | +The intermediate measurement that pinned the armed-slot requirement, kept because it | |
| 442 | +is the evidence for that part of the fix: | |
| 443 | + | |
| 444 | +| cell | baseline | new arm, no armed-slot clear | new arm + clear | | |
| 445 | +|---|---|---|---| | |
| 446 | +| `Q_odd320x242` | 24 059 | 10 847 | **0** | | |
| 447 | +| `R422_320x242` | 14 735 | 10 687 | **0** | | |
| 448 | +| `AB_inter_warp_odd` | 8 071 | 0 | **0** | | |
| 449 | +| `O_odd322x242` | 1 707 | 3 055 (worse) | **0** | | |
| 450 | +| `S_odd326x242_10b` | 1 052 | 22 915 (much worse) | **0** | | |
| 451 | +| `R_odd322x240` (control) | 0 | 4 806 (BROKEN) | **0** | | |
| 452 | +| `V_tile2x2_odd` (control) | 0 | 0 | **0** | | |
| 453 | + | |
| 454 | +--- | |
| 455 | + | |
| 456 | +## 8. Regression | |
| 457 | + | |
| 458 | +`cargo test --release -p ec-av1 --lib -- 420 422 444 lossless warp intra --skip | |
| 459 | +bitrate_target_lands_within_5_percent_over_48_frames` on this lane tree at `0f9ea788` | |
| 460 | ++ this lane's diff, `CARGO_TARGET_DIR=/home/user/.cache/tgt/av1422ctattr`, | |
| 461 | +`EC_AV1_AOMDEC=/home/user/.cache/aom-oracle/build/aomdec`, | |
| 462 | +`EC_NOMEMGUARD=1`. `/tmp` was checked first (13 G of 16 G free, `/tmp/ec-av1-*` | |
| 463 | +cleared) so no gate can fail with `Os { code: 122, kind: QuotaExceeded }`. | |
| 464 | + | |
| 465 | +**`test result: ok. 181 passed; 0 failed; 2 ignored; 0 measured; 618 filtered out; | |
| 466 | +finished in 223.26s`** | |
| 467 | + | |
| 468 | +That is **the same count as `lanes/av1422ctrigger` §8's baseline (181 / 0 / 2)** and | |
| 469 | +as `lanes/av1422llodd` §8's, so nothing moved. No failure was a `/tmp`-full | |
| 470 | +artefact (`/tmp` had 13 G of 16 G free with `/tmp/ec-av1-*` cleared; the run was | |
| 471 | +green on the first attempt — no red-then-green sequence to explain). | |
| 472 | + | |
| 473 | +For completeness, the same command **with the 4:2:2 refusal bypass still patched | |
| 474 | +in** (i.e. before the guard was restored) gives | |
| 475 | +`175 passed; 6 failed; 2 ignored`, and the six failures are exactly the six | |
| 476 | +`stream::tests::*` gates that assert the 4:2:2 refusal is present: | |
| 477 | +`a_non_420_subsampled_sequence_header_is_refused_by_name`, | |
| 478 | +`the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name`, | |
| 479 | +`the_pinned_422_intrabc_sb128_strip_witnesses_refuse_by_name`, | |
| 480 | +`the_pinned_422_lossless_inter_witnesses_are_present_and_refuse_by_name`, | |
| 481 | +`the_pinned_422_lr_off_witness_is_present_and_refuses_by_name`, | |
| 482 | +`the_pinned_422_residual_compound_warp_witness_is_present_and_refuses_by_name`. | |
| 483 | +That is the direct measurement of §8's gate-ability claim: the only thing standing | |
| 484 | +between this tree and those six gates is one `if` at `stream.rs:1803`. | |
| 485 | + | |
| 486 | +--- | |
| 487 | + | |
| 488 | +## 9. Gate-ability: NO. Stated plainly, not substituted. | |
| 489 | + | |
| 490 | +4:2:2 is refused at the **sequence header** — | |
| 491 | +`crates/ec-av1/src/stream.rs:1803`, `if seq.subsampling_x != seq.subsampling_y`. | |
| 492 | +**No committed fixture and no committed test can reach this code.** Every | |
| 493 | +measurement in §1 and §6 required patching that guard out; it is restored | |
| 494 | +(`stream.rs:1803` reads `if seq.subsampling_x != seq.subsampling_y {`) and | |
| 495 | +`git status` shows only the three files listed at the top. | |
| 496 | + | |
| 497 | +What a future lane that lifts the refusal would need, now measured and reproducible: | |
| 498 | + | |
| 499 | +* `R422_320x242.obu`, 20 733 B, `sha256 909e58db18fd4b7590501e2cecfbc090cde49eb26c9a42e15b1ef1fc265843d8`, | |
| 500 | + with the full §1 recipe — the first 4:2:2 artifact in this line that is both | |
| 501 | + buildable from scratch and hash-stable. | |
| 502 | +* a per-decode-frame, per-plane byte-exactness gate (`planecmp.py`) plus the | |
| 503 | + oracle-flip control in §6. | |
| 504 | +* rungs 19/20/21 (`EC_PIB`, `EC_DCIN`, `EC_DP`) in `scripts/instrument-aom-oracle.sh`, | |
| 505 | + asserted in `scripts/check-aom-oracle-rungs.sh` — without them this defect was | |
| 506 | + three lanes deep, and the `MI_SIZE` unit error cost a fourth. | |
| 507 | + | |
| 508 | +I am not offering a source-scan substitute, and I am not committing the bypass. | |
| 509 | + | |
| 510 | +--- | |
| 511 | + | |
| 512 | +## 10. Handover | |
| 513 | + | |
| 514 | +1. **`decode_leaf_split4`'s 4-leaf group tail** (`decode.rs:26707`) is the one | |
| 515 | + unrepaired arm of this class: its intrabc arm never tests `leaf_skips[3]`, so a | |
| 516 | + skipped intrabc chroma-reference leaf there would predict DC *and* read chroma | |
| 517 | + coefficients the oracle does not read. It has zero hits on every cell I could | |
| 518 | + build. It needs a witness, not a patch. | |
| 519 | +2. **libaom's `MI_SIZE` is 4.** Any past or future ladder read on an 8-px grid is | |
| 520 | + wrong by a factor of two and will produce phantom "uncovered region" findings. | |
| 521 | + `grep "define MI_SIZE" av1/common/enums.h` before believing one. | |
| 522 | +3. **Do not re-chase**: the header fields, the post-recon filters, the entropy parse | |
| 523 | + (bit-identical at the seed), `intra::dc`'s arithmetic, `PlaneBuf::edges`' three | |
| 524 | + missing terms, the `& !1` anchor mask, the palette colour maps, odd/even geometry. | |
| 525 | +4. `EC_DCIN`'s `atop`/`aleft` print 0 on every line I captured, because | |
| 526 | + `av1_predict_intra_block` is called with `ref == dst` in the decoder and the DC | |
| 527 | + operands are read from `ref` before the predictor writes. It is still the right | |
| 528 | + place for them (that is where the availability lives), but a future lane reading | |
| 529 | + `atop`/`aleft` should not be surprised by zeros; the oracle's post-filter | |
| 530 | + neighbour dumps are the source for edge sums. | |
| 531 | + | |
| 532 | +--- | |
| 533 | + | |
| 534 | +## 11. Handover hygiene | |
| 535 | + | |
| 536 | +* Lane tree `/home/user/.cache/wt/av1422ctattr`, branch `lane-av1422ctattr`. | |
| 537 | + `git status --porcelain`: `M crates/ec-av1/src/decode.rs`, | |
| 538 | + `M scripts/check-aom-oracle-rungs.sh`, `M scripts/instrument-aom-oracle.sh`, | |
| 539 | + `?? lanes/av1422ctattr.report.md`. **`crates/ec-av1/src/stream.rs` is restored** | |
| 540 | + — line 1803 reads `if seq.subsampling_x != seq.subsampling_y {` again — and the | |
| 541 | + temporary class-sweep probe is gone from `decode.rs`. | |
| 542 | +* Primary checkout `/home/user/Documents/Code/Rust/edith_codecs`: | |
| 543 | + `git status --porcelain` **empty**. No relative-path leak. All edits used absolute | |
| 544 | + paths inside the worktree. | |
| 545 | +* No push, no merge, no rustfmt. | |
| 546 | +* The private oracle copy `/home/user/.cache/aom-oracle-av1422ctattr` is outside | |
| 547 | + the repo; the shared `~/.cache/aom-oracle/src` was **not** written to (three lanes | |
| 548 | + were running against it). | |
| 549 | +* The 4:2:2 sequence-header bypass is **not** committed anywhere. | |
| 550 | +* Measurement scripts and both source sets live outside the repo, in | |
| 551 | + `/home/user/.cache/lane-av1422ctattr/`. | |
| \ No newline at end of file |
scripts/check-aom-oracle-rungs.shmodified+35 -0
| @@ -147,6 +147,41 @@ check "rung 17 EC_PREDND install sites (hbd non-directional)" "$pnd" "1" | ||
| 147 | 147 | pndm=$(grep -c 'txw=%d txh=%d mode=%d n_top=%d n_left=%d' "$WORK/derived-intra.c" || true) |
| 148 | 148 | check "rung 17 EC_PREDND site carries mode=" "$pndm" "1" |
| 149 | 149 | |
| 150 | +# --- rungs 19/20: the intra-prediction IDENTITY + DC INPUTS rungs --------- | |
| 151 | +# EC_PREDOUT8/EC_PREDND print only SOME of the writes inside | |
| 152 | +# `av1_predict_intra_block`: the palette branch returns before either, and so | |
| 153 | +# do the two non-directional early returns' opposite number. A chroma region | |
| 154 | +# where no rung fires was therefore un-attributable -- three lanes of 4:2:2 | |
| 155 | +# work stalled on exactly that (lanes/av1422ctrigger §5b). EC_PIB prints the | |
| 156 | +# CALL IDENTITY before any early return, so "did a call happen and did it | |
| 157 | +# return early" is readable from the trace. | |
| 158 | +pib=$(grep -c 'EC_PIB mi_row=%d mi_col=%d plane=%d row_off=%d col_off=%d' "$WORK/derived-intra.c" || true) | |
| 159 | +check "rung 19 EC_PIB install sites (av1_predict_intra_block prologue)" "$pib" "1" | |
| 160 | + | |
| 161 | +pibb=$(grep -c 'txw=%d txh=%d mode=%d use_palette=%d' "$WORK/derived-intra.c" || true) | |
| 162 | +check "rung 19 EC_PIB carries use_palette= (the early-return bit)" "$pibb" "1" | |
| 163 | + | |
| 164 | +# EC_DCIN is what makes the DC VARIANT a printed field instead of an | |
| 165 | +# inference from the predicted value: four lanes read "libaom used dc_top" | |
| 166 | +# out of the number 202 without the availability operands being visible. | |
| 167 | +dcin=$(grep -c 'EC_DCIN mi_row=%d mi_col=%d plane=%d row_off=%d col_off=%d' "$WORK/derived-intra.c" || true) | |
| 168 | +check "rung 20 EC_DCIN install sites (8-bit + hbd non-directional)" "$dcin" "2" | |
| 169 | + | |
| 170 | +dcina=$(grep -c 'n_left=%d atop=%ld aleft=%ld dcv=%d up=%d left=%d cup=%d' "$WORK/derived-intra.c" || true) | |
| 171 | +check "rung 20 EC_DCIN prints availability operands + dcv + availability bits" "$dcina" "2" | |
| 172 | + | |
| 173 | +# --- rung 21: EC_DP, the branch decode_token_recon_block takes -------------- | |
| 174 | +# The inter arm (`predict_inter_block_visit`) prints NO intra rung, and the | |
| 175 | +# intra arm itself skips chroma on `!xd->is_chroma_ref`, so a block that | |
| 176 | +# emits no prediction rung is consistent with three different writers. | |
| 177 | +# EC_DP is what separates them -- it is how the INTRABC writer at the 4:2:2 | |
| 178 | +# seed was named (lanes/av1422ctattr §4). | |
| 179 | +dp=$(grep -c 'EC_DP mi_row=%d mi_col=%d bsize=%d inter=%d chroma_ref=%d' "$WORK/derived.c" || true) | |
| 180 | +check "rung 21 EC_DP install sites (decode_token_recon_block)" "$dp" "1" | |
| 181 | + | |
| 182 | +dpa=$(grep -c 'skip_txfm=%d bw=%d bh=%d planes=%d is_intrabc=%d' "$WORK/derived.c" || true) | |
| 183 | +check "rung 21 EC_DP carries is_intrabc= (the intra/inter branch bit)" "$dpa" "1" | |
| 184 | + | |
| 150 | 185 | # Rung 16 claims to be idempotent in BOTH directions: an install on a |
| 151 | 186 | # pristine file, AND an upgrade of the no-`mode=` form the oracle tree's git |
| 152 | 187 | # HEAD carries. Rebuild the no-mode form, re-derive, and require the result to |
scripts/instrument-aom-oracle.shmodified+177 -0
| @@ -1349,3 +1349,180 @@ s = s.replace(anchor, new, 1) | ||
| 1349 | 1349 | open(path, "w").write(s) |
| 1350 | 1350 | print("EC_VARTX/EC_VARTXCTX instrumented (read_tx_size_vartx)") |
| 1351 | 1351 | PYVX |
| 1352 | + | |
| 1353 | +# --- rung 19: EC_PIB, EVERY av1_predict_intra_block call (lane-av1422ctattr) --- | |
| 1354 | +# WHY. Three lanes of 4:2:2 chroma archaeology stalled on ONE blind spot: | |
| 1355 | +# `av1_predict_intra_block` has an early `if (use_palette) { ...; return; }` | |
| 1356 | +# and TWO early `return`s after it (the 8-bit non-directional site and the | |
| 1357 | +# hbd one), so EC_PREDOUT8 / EC_PREDND only print on SOME of the paths that | |
| 1358 | +# write a block. A chroma region where no rung fires is therefore | |
| 1359 | +# un-attributable: "libaom used dc_top" was an inference from the predicted | |
| 1360 | +# VALUE, not a printed flag, and the whole ladder looked like it had no block | |
| 1361 | +# there at all. EC_PIB prints the CALL IDENTITY -- before any early return -- | |
| 1362 | +# so the question "which call wrote this pixel, and did it return early" is | |
| 1363 | +# answerable from the trace instead of from arithmetic. | |
| 1364 | +# | |
| 1365 | +# Field order is deliberately identical to EC_PREDOUT8/EC_PRED for the fields | |
| 1366 | +# they share, so a rung 16 line and a rung 19 line for the same block read as | |
| 1367 | +# one line. `use_palette` is the early-return bit: use_palette=1 with no | |
| 1368 | +# EC_PREDOUT8/EC_PRED twin line IS a palette write. | |
| 1369 | +# | |
| 1370 | +# Env: EC_PIB=1. Optional EC_PIBWIN="mi_row_lo:mi_row_hi:mi_col_lo:mi_col_hi" | |
| 1371 | +# (any field < 0 means "any") so a seed's own block can be isolated without | |
| 1372 | +# dumping a whole frame. | |
| 1373 | +python3 - "$I" <<'PYPIB' | |
| 1374 | +import sys | |
| 1375 | +path = sys.argv[1] | |
| 1376 | +s = open(path).read() | |
| 1377 | +if "EC_PIB " in s: | |
| 1378 | + print("EC_PIB already instrumented (no-op)") | |
| 1379 | + sys.exit(0) | |
| 1380 | + | |
| 1381 | +anchor = """ const int is_hbd = is_cur_buf_hbd(xd); | |
| 1382 | + | |
| 1383 | + assert(mode < INTRA_MODES);""" | |
| 1384 | +new = """ const int is_hbd = is_cur_buf_hbd(xd); | |
| 1385 | + | |
| 1386 | + /* EC_INSTRUMENTED_PIB: the call IDENTITY, printed BEFORE the palette | |
| 1387 | + early return so every call is visible. */ | |
| 1388 | + if (getenv("EC_PIB")) { | |
| 1389 | + const char *ec_w = getenv("EC_PIBWIN"); | |
| 1390 | + int ec_r0 = -1, ec_r1 = -1, ec_c0 = -1, ec_c1 = -1; | |
| 1391 | + if (ec_w) sscanf(ec_w, "%d:%d:%d:%d", &ec_r0, &ec_r1, &ec_c0, &ec_c1); | |
| 1392 | + if ((ec_r0 < 0 || (xd->mi_row >= ec_r0 && xd->mi_row <= ec_r1)) && | |
| 1393 | + (ec_c0 < 0 || (xd->mi_col >= ec_c0 && xd->mi_col <= ec_c1))) { | |
| 1394 | + fprintf(stderr, | |
| 1395 | + "EC_PIB mi_row=%d mi_col=%d plane=%d row_off=%d col_off=%d " | |
| 1396 | + "txw=%d txh=%d mode=%d use_palette=%d filter_intra=%d bsize=%d " | |
| 1397 | + "px=%d py=%d hbd=%d\\n", | |
| 1398 | + xd->mi_row, xd->mi_col, plane, row_off, col_off, txwpx, txhpx, | |
| 1399 | + mode, use_palette, (int)filter_intra_mode, (int)mbmi->bsize, | |
| 1400 | + col_off << MI_SIZE_LOG2, row_off << MI_SIZE_LOG2, (int)is_hbd); | |
| 1401 | + } | |
| 1402 | + } | |
| 1403 | + | |
| 1404 | + assert(mode < INTRA_MODES);""" | |
| 1405 | +assert anchor in s, "av1_predict_intra_block prologue moved" | |
| 1406 | +s = s.replace(anchor, new, 1) | |
| 1407 | + | |
| 1408 | +# --- rung 20: EC_DCIN, the DC path's availability INPUTS (lane-av1422ctattr) -- | |
| 1409 | +# `dc_predictor`'s four variants are selected by (have_top, have_left) and | |
| 1410 | +# scaled by (n_top_px, n_left_px); EC_PREDOUT8 prints none of them, only the | |
| 1411 | +# RESULT and the mode. So a predicted value that "looks like dc_top" is an | |
| 1412 | +# inference. EC_DCIN prints the four operands, the two edge SUMS they are | |
| 1413 | +# taken from, the availability BITS themselves (including the per-plane | |
| 1414 | +# chroma_* narrowing in set_mi_row_col), and the variant id the four-way | |
| 1415 | +# select picked -- so the variant is a printed field, not an inference. | |
| 1416 | +# | |
| 1417 | +# Variant id: 0 = dc (both edges), 1 = dc_top, 2 = dc_left, 3 = dc_128. | |
| 1418 | +# | |
| 1419 | +# Installed at BOTH 8-bit and high-bitdepth non-directional sites, before the | |
| 1420 | +# predictor call. Env: EC_DCIN=1 (EC_PIBWIN filters it too). | |
| 1421 | +nd_anchor = """ build_non_directional_intra_predictors(ref, ref_stride, dst, dst_stride, | |
| 1422 | + mode, tx_size, n_top_px, n_left_px);""" | |
| 1423 | +nd_new = """ /* EC_INSTRUMENTED_DCIN (8-bit non-directional): the availability INPUTS | |
| 1424 | + and the DC variant they select. */ | |
| 1425 | + if (getenv("EC_DCIN")) { | |
| 1426 | + long ec_atop = 0, ec_aleft = 0; | |
| 1427 | + int ec_i; | |
| 1428 | + for (ec_i = 0; ec_i < n_top_px; ++ec_i) ec_atop += ref[ec_i]; | |
| 1429 | + for (ec_i = 0; ec_i < n_left_px; ++ec_i) ec_aleft += ref[ec_i * ref_stride]; | |
| 1430 | + fprintf(stderr, | |
| 1431 | + "EC_DCIN mi_row=%d mi_col=%d plane=%d row_off=%d col_off=%d " | |
| 1432 | + "txw=%d txh=%d mode=%d have_top=%d have_left=%d n_top=%d " | |
| 1433 | + "n_left=%d atop=%ld aleft=%ld dcv=%d up=%d left=%d cup=%d " | |
| 1434 | + "cleft=%d ss_x=%d ss_y=%d bsize=%d\\n", | |
| 1435 | + xd->mi_row, xd->mi_col, plane, row_off, col_off, txwpx, txhpx, | |
| 1436 | + mode, have_top, have_left, n_top_px, n_left_px, ec_atop, | |
| 1437 | + ec_aleft, | |
| 1438 | + (n_top_px > 0 ? (n_left_px > 0 ? 0 : 1) | |
| 1439 | + : (n_left_px > 0 ? 2 : 3)), | |
| 1440 | + xd->up_available, xd->left_available, xd->chroma_up_available, | |
| 1441 | + xd->chroma_left_available, ss_x, ss_y, (int)mbmi->bsize); | |
| 1442 | + } | |
| 1443 | + build_non_directional_intra_predictors(ref, ref_stride, dst, dst_stride, | |
| 1444 | + mode, tx_size, n_top_px, n_left_px);""" | |
| 1445 | +assert nd_anchor in s, "8-bit non-directional predictor call moved" | |
| 1446 | +s = s.replace(nd_anchor, nd_new, 1) | |
| 1447 | + | |
| 1448 | +hbd_anchor = """ highbd_build_non_directional_intra_predictors( | |
| 1449 | + ref, ref_stride, dst, dst_stride, mode, tx_size, n_top_px, n_left_px, | |
| 1450 | + xd->bd);""" | |
| 1451 | +hbd_new = """ /* EC_INSTRUMENTED_DCIN (high bitdepth non-directional): the hbd twin. */ | |
| 1452 | + if (getenv("EC_DCIN")) { | |
| 1453 | + const uint16_t *ec_r16 = CONVERT_TO_SHORTPTR(ref); | |
| 1454 | + long ec_atop = 0, ec_aleft = 0; | |
| 1455 | + int ec_i; | |
| 1456 | + for (ec_i = 0; ec_i < n_top_px; ++ec_i) ec_atop += ec_r16[ec_i]; | |
| 1457 | + for (ec_i = 0; ec_i < n_left_px; ++ec_i) | |
| 1458 | + ec_aleft += ec_r16[ec_i * ref_stride]; | |
| 1459 | + fprintf(stderr, | |
| 1460 | + "EC_DCIN mi_row=%d mi_col=%d plane=%d row_off=%d col_off=%d " | |
| 1461 | + "txw=%d txh=%d mode=%d have_top=%d have_left=%d n_top=%d " | |
| 1462 | + "n_left=%d atop=%ld aleft=%ld dcv=%d up=%d left=%d cup=%d " | |
| 1463 | + "cleft=%d ss_x=%d ss_y=%d bsize=%d\\n", | |
| 1464 | + xd->mi_row, xd->mi_col, plane, row_off, col_off, txwpx, txhpx, | |
| 1465 | + mode, have_top, have_left, n_top_px, n_left_px, ec_atop, | |
| 1466 | + ec_aleft, | |
| 1467 | + (n_top_px > 0 ? (n_left_px > 0 ? 0 : 1) | |
| 1468 | + : (n_left_px > 0 ? 2 : 3)), | |
| 1469 | + xd->up_available, xd->left_available, xd->chroma_up_available, | |
| 1470 | + xd->chroma_left_available, ss_x, ss_y, (int)mbmi->bsize); | |
| 1471 | + } | |
| 1472 | + highbd_build_non_directional_intra_predictors( | |
| 1473 | + ref, ref_stride, dst, dst_stride, mode, tx_size, n_top_px, n_left_px, | |
| 1474 | + xd->bd);""" | |
| 1475 | +if hbd_anchor in s: | |
| 1476 | + s = s.replace(hbd_anchor, hbd_new, 1) | |
| 1477 | +else: | |
| 1478 | + print("WARN: hbd non-directional call anchor not found; EC_DCIN is 8-bit only") | |
| 1479 | + | |
| 1480 | +open(path, "w").write(s) | |
| 1481 | +print("EC_PIB/EC_DCIN instrumented (av1_predict_intra_block)") | |
| 1482 | +PYPIB | |
| 1483 | + | |
| 1484 | +# --- rung 21: EC_DP, the per-block branch taken in decode_token_recon_block --- | |
| 1485 | +# WHY. `decode_token_recon_block` has two arms -- intra (the only one whose | |
| 1486 | +# prediction prints a rung) and inter (`predict_inter_block_visit`, no | |
| 1487 | +# intra rung at all) -- AND, inside the intra arm, `if (plane && !xd- | |
| 1488 | +# >is_chroma_ref) break;`, so a chroma plane can be skipped entirely. A | |
| 1489 | +# region where NO prediction rung fires is consistent with all three, and the | |
| 1490 | +# rung ladder alone cannot tell them apart. EC_DP prints the branch decision | |
| 1491 | +# for every block: which arm, whether chroma is reconstructed at all, and the | |
| 1492 | +# max_unit geometry the loop walks. Env: EC_DP=1. | |
| 1493 | +python3 - "$F" <<'PYDP' | |
| 1494 | +import sys | |
| 1495 | +path = sys.argv[1] | |
| 1496 | +s = open(path).read() | |
| 1497 | +if "EC_DP mi_row=" in s: | |
| 1498 | + print("EC_DP already instrumented (no-op)") | |
| 1499 | + sys.exit(0) | |
| 1500 | + | |
| 1501 | +anchor = """ MB_MODE_INFO *mbmi = xd->mi[0]; | |
| 1502 | + | |
| 1503 | + if (!is_inter_block(mbmi)) {""" | |
| 1504 | +new = """ MB_MODE_INFO *mbmi = xd->mi[0]; | |
| 1505 | + | |
| 1506 | + /* EC_INSTRUMENTED_DP: the branch decode_token_recon_block takes for this | |
| 1507 | + block -- intra vs inter, and whether the chroma planes are reconstructed | |
| 1508 | + at all (`plane && !xd->is_chroma_ref`). Anchored on the `mbmi` + | |
| 1509 | + `if (!is_inter_block)` pair, not on the function signature, because the | |
| 1510 | + signature's parameter wrapping is not stable across libaom revisions | |
| 1511 | + (v3.13.3 wraps `ThreadData *const td, aom_reader *r,` onto one line). */ | |
| 1512 | + if (getenv("EC_DP")) { | |
| 1513 | + fprintf(stderr, | |
| 1514 | + "EC_DP mi_row=%d mi_col=%d bsize=%d inter=%d chroma_ref=%d " | |
| 1515 | + "skip_txfm=%d bw=%d bh=%d planes=%d is_intrabc=%d\\n", | |
| 1516 | + xd->mi_row, xd->mi_col, (int)bsize, (int)is_inter_block(mbmi), | |
| 1517 | + (int)xd->is_chroma_ref, (int)mbmi->skip_txfm, | |
| 1518 | + (int)max_block_wide(xd, bsize, 0), | |
| 1519 | + (int)max_block_high(xd, bsize, 0), num_planes, | |
| 1520 | + (int)is_intrabc_block(mbmi)); | |
| 1521 | + } | |
| 1522 | + | |
| 1523 | + if (!is_inter_block(mbmi)) {""" | |
| 1524 | +assert anchor in s, "decode_token_recon_block prologue moved" | |
| 1525 | +s = s.replace(anchor, new, 1) | |
| 1526 | +open(path, "w").write(s) | |
| 1527 | +print("EC_DP instrumented (decode_token_recon_block)") | |
| 1528 | +PYDP |