lanes: av1chrtx report — rect chroma per-unit tx_type + rect coeff-trace plane tag
Browse files at this commit4106dd6b8f2e0db3362d81cabcdcd475671903e8Parent: 7a367331 changed file +187 -0
- lanes/av1chrtx.report.md +187 -0
lanes/av1chrtx.report.mdadded+187 -0
| @@ -0,0 +1,187 @@ | |||
| 1 | +# lane-av1chrtx — rect inter chroma per-unit tx_type (H1) + rect coeff-trace plane tag (H2) | ||
| 2 | + | ||
| 3 | +Branch `lane-av1chrtx` (worktree `~/.cache/wt/av1chrtx`), base `a21f3680`. | ||
| 4 | +Oracle `~/.cache/aom-oracle/build/{aomdec,aomenc}` (instrumented). | ||
| 5 | +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1chrtx`. | ||
| 6 | + | ||
| 7 | +Commits: `d791c464` (H2), `2142d2cf` (H1) — one per defect, as chartered. | ||
| 8 | + | ||
| 9 | +--- | ||
| 10 | + | ||
| 11 | +## H1 — FIXED. `read_inter_rect_chroma` handed every chroma unit the BLOCK-level `tx_type` | ||
| 12 | + | ||
| 13 | +### The defect | ||
| 14 | + | ||
| 15 | +`read_inter_rect_chroma` is the sibling of the two 4:4:4 four-unit arms. | ||
| 16 | +lane-av1444chr extracted `covering_leaf_tx_type` and re-pointed both | ||
| 17 | +four-unit arms at it, but left this sibling passing the block-level | ||
| 18 | +`luma_tx_type` (the top-left leaf's type) to **every** unit of the plane: | ||
| 19 | + | ||
| 20 | +```rust | ||
| 21 | +let inherit_tx_type = Some(luma_tx_type); // before | ||
| 22 | +``` | ||
| 23 | + | ||
| 24 | +`av1_get_tx_type` (`blockd.h:1287-1297`) reads `xd->tx_type_map` at the | ||
| 25 | +chroma unit's own position scaled back to luma, and `read_coeffs`'s | ||
| 26 | +`all_zero` arm stamps `DCT_DCT` into that leaf's map cell | ||
| 27 | +(`decodetxb.c:199-203`) — so a unit sitting over a luma leaf that coded | ||
| 28 | +**nothing** inherits `DctDct`, not the block-level type. With | ||
| 29 | +`nx*ny > 1` over mixed var-tx leaves that is a per-unit wrong answer. | ||
| 30 | + | ||
| 31 | +### The witness hunt (bounded, then found) | ||
| 32 | + | ||
| 33 | +lane-av1444chr's report recorded the route as unreachable on five | ||
| 34 | +4:4:4 rect recipes (`multi` = 0 on every one). Two facts explain why, | ||
| 35 | +and they shape the hunt: | ||
| 36 | + | ||
| 37 | +1. **`multi` is false by construction at 4:2:0.** The arm is only reached | ||
| 38 | + for `side <= 64` blocks (the `side > 64` mu-chunk path runs first), and | ||
| 39 | + a `side <= 64` block's 4:2:0 chroma plane is at most 32x32 — exactly | ||
| 40 | + one `uw x uh` unit, so `nx*ny == 1` always. The earlier hunt's | ||
| 41 | + recipes were 4:4:4 but used partition settings that never produced a | ||
| 42 | + block keeping a 64-px axis. | ||
| 43 | +2. So the arm needs **4:4:4 AND a rect block with a 64-px luma axis** | ||
| 44 | + (32x64 / 64x32 / 64x16 / 16x64) — a 4:4:4 chroma plane then exceeds | ||
| 45 | + the 32 cap on one axis and splits. | ||
| 46 | + | ||
| 47 | +Hunt: 200+ encodes, three 4:4:4 sources (testsrc2 128/192/256, mandelbrot | ||
| 48 | +128/256, testsrc2 192x256), swept over `--min-partition-size` 8/16/32, | ||
| 49 | +`--max-partition-size` 32/64/128, `--enable-tx-size-search` 0/1, | ||
| 50 | +`--enable-rect-partitions`, `cq-level` 18-44, `--cpu-used` 0/2/3/5/7, | ||
| 51 | +sizes 128x128 through 256x256. Instrumented with a temporary | ||
| 52 | +`EC_AV1_CHRTX_PROBE` eprintln in the arm printing `(nx, ny, multi, leaves)` | ||
| 53 | +(removed before the commit). | ||
| 54 | + | ||
| 55 | +Result: the arm's `multi` is 0 on every 4:2:0 recipe and on every 4:4:4 | ||
| 56 | +recipe whose rect strips keep a 32-px axis. It first fires with | ||
| 57 | +**`--cpu-used=0 --min-partition-size=32 --max-partition-size=64` on a | ||
| 58 | +256x256 source** — the slow encoder is what actually picks a 32x64 strip | ||
| 59 | +over two 32x32 blocks. | ||
| 60 | + | ||
| 61 | +### The witness (pinned) | ||
| 62 | + | ||
| 63 | +`crates/ec-av1/fixtures/444_rect_strip_leaf_tx_type.obu`, 26839 bytes, | ||
| 64 | +sha256 `06174a66e92aaeb751a8e86db59711fcb1f18d74bde2d77e1ef1be7983eb7c80`, | ||
| 65 | +fnv1a64 `0xc77f310c036dff73`. | ||
| 66 | + | ||
| 67 | +``` | ||
| 68 | +ffmpeg -f lavfi -i "testsrc2=size=256x256:rate=25" -frames:v 3 -pix_fmt yuv444p \ | ||
| 69 | + -f yuv4mpegpipe ts256.y4m | ||
| 70 | +aomenc --codec=av1 --profile=1 --cq-level=30 --cpu-used=0 --sb-size=64 \ | ||
| 71 | + --min-partition-size=32 --max-partition-size=64 --enable-tx-size-search=1 \ | ||
| 72 | + --passes=1 --end-usage=q --threads=1 --row-mt=0 --lag-in-frames=0 \ | ||
| 73 | + --kf-max-dist=100 --limit=3 --obu -o w.obu ts256.y4m | ||
| 74 | +``` | ||
| 75 | + | ||
| 76 | +The qualifying block is the **32x64 inter strip at mi(32,48)**: | ||
| 77 | +a 4:4:4 chroma plane of `(32, 64)` = **two** TX_32X32 units, over a | ||
| 78 | +five-leaf luma tree | ||
| 79 | + | ||
| 80 | +| leaf (row, col, tw, th, tx_type) | covering mi rows | | ||
| 81 | +|---|---| | ||
| 82 | +| `(0, 0, 32, 32, Idtx)` | 0..8 | | ||
| 83 | +| `(8, 0, 16, 16, VDct)` | 8..12 | | ||
| 84 | +| `(8, 4, 16, 16, DctDct)` | 8..12 | | ||
| 85 | +| `(12, 0, 16, 16, HDct)` | 12..16 | | ||
| 86 | +| `(12, 4, 16, 16, VDct)` | 12..16 | | ||
| 87 | + | ||
| 88 | +The **lower** chroma unit (its own mi cell `(8, 0)`) therefore resolves | ||
| 89 | +`VDct` where the block-level value is `Idtx` — once per chroma plane, so | ||
| 90 | +`diff = 2`. The upper unit resolves `Idtx`, i.e. the same as the | ||
| 91 | +block-level value: the defect is strictly per-unit. | ||
| 92 | + | ||
| 93 | +### The fix | ||
| 94 | + | ||
| 95 | +- `read_inter_rect_chroma` takes the block's `leaf_tx_types` and resolves | ||
| 96 | + `inherit_tx_type` **per unit** through the shared | ||
| 97 | + `covering_leaf_tx_type(leaf_tx_types, unit_rel_mi)`, with | ||
| 98 | + `.unwrap_or(luma_tx_type)` as the fallback for a block that coded a | ||
| 99 | + single luma unit (no vartx tree, so `leaves` is empty). Both call sites | ||
| 100 | + (the compound and single-reference copies of `decode_inter_block`) | ||
| 101 | + pass their `&leaf_tx_types` — the same list the four-unit arms read. | ||
| 102 | +- Two new gate counters, `CHROMA_RECT_LEAF_TX_HITS` / | ||
| 103 | + `CHROMA_RECT_LEAF_TX_DIFF_HITS`, deliberately **separate** from | ||
| 104 | + `CHROMA_QUAD_LEAF_TX_HITS` / `_DIFF_HITS`: the latter pair gates a | ||
| 105 | + 4:2:0 control asserting exactly `(0, 0)`, and this route **is** | ||
| 106 | + reachable at 4:2:0, so sharing the counter would destroy that | ||
| 107 | + control's meaning. | ||
| 108 | + | ||
| 109 | +### Bar | ||
| 110 | + | ||
| 111 | +- **Red-before by mutation** (revert only the resolve to the block-level | ||
| 112 | + type; everything else intact): | ||
| 113 | + `decode-order frame 1 of 3 (3 shown, 0 hidden) differs from the oracle | ||
| 114 | + at byte 105949 (ours 166 vs 167), 1998 bytes differ`. | ||
| 115 | + Restored: green. (A first mutation attempt used `.or(None::<TxType>)`, | ||
| 116 | + which is the identity on `Option` and therefore did **not** bite — the | ||
| 117 | + red run above uses `.and(None::<TxType>)`, the real removal.) | ||
| 118 | +- **New gate** `stream::tests::a_pinned_444_rect_inter_stream_resolves_each_chroma_unit_from_its_own_luma_leaf`: | ||
| 119 | + fixture length + fnv pinned, `decode_all_frames_vs_oracle` (length- | ||
| 120 | + asserting, byte-exact, 3 frames, 0 hidden), asserts `hits >= 2*diff && | ||
| 121 | + hits > 0` and **`diff >= 2`**. | ||
| 122 | + Measured: `rect chroma units resolved from their own leaf 4, of which 2 differed`. | ||
| 123 | +- **In-gate control**: the committed | ||
| 124 | + `fixtures/444_sb128rect_lr_witness.obu` fires the same route (2 units | ||
| 125 | + resolved) with **0** differing types — the exact shape a no-op fix | ||
| 126 | + looks green on, which is why the DIFF counter and not the route counter | ||
| 127 | + is the non-vacuity bar. | ||
| 128 | +- **Resolver unit test** `decode::tests::covering_leaf_tx_type_picks_the_leaf_under_the_unit_or_reports_none`: | ||
| 129 | + mixed-leaf lookup on the witness's own five-leaf tree, interior cells | ||
| 130 | + (containment, not raster position), the mi cell just past the block's | ||
| 131 | + extent → `None`, and the empty leaf list → `None`. | ||
| 132 | + Mutation-proven red: turning the containment `<` into `<=` → | ||
| 133 | + `panicked at crates/ec-av1/src/decode.rs:52883, left: Some(Idtx), right: Some(VDct)`. | ||
| 134 | + Restored: green. | ||
| 135 | +- **Identity green** (13 tests, one binary, `--test-threads=4`, no SKIP | ||
| 136 | + lines): the new gate, the resolver unit test, the av1444chr gate | ||
| 137 | + (`quad-resolved chroma units 96, of which 8 differed` — unchanged), plus | ||
| 138 | + `a_444_lossy_rect4_inter_stream_decodes_pixel_exact`, | ||
| 139 | + `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact`, | ||
| 140 | + `a_lossless_444_defaultp_inter_strip_stream_decodes_byte_exact`, | ||
| 141 | + `a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact`, | ||
| 142 | + `a_lossless_444_min_partition8_inter_stream_decodes_sample_exact`, | ||
| 143 | + `a_real_aomenc_rect_inter_block_predicts_chroma_with_the_narrow_kernel_pixel_exact`, | ||
| 144 | + `a_real_aomenc_rect_strip_palette_decodes_pixel_exact`, | ||
| 145 | + `a_real_aomenc_inter_sequence_with_a_16_level_rect_leaf_decodes_pixel_exact`, | ||
| 146 | + `a_444_intrabc_rect4_reads_its_own_chroma_plane_block`, | ||
| 147 | + `a_lossless_444_rect16x4_chroma_reach_is_ss_aware` — **13 passed, 0 failed**. | ||
| 148 | + | ||
| 149 | +--- | ||
| 150 | + | ||
| 151 | +## H2 — FIXED. `read_coeffs_rect`'s `EC_COEFF_STEP` traces hardcoded `plane=0` | ||
| 152 | + | ||
| 153 | +`read_coeffs_rect` printed `plane=0` on both tagged lines | ||
| 154 | +(`tag=all_zero`, `tag=tx_type`), so every **chroma** rect coefficient | ||
| 155 | +read was logged as a luma one. Two independent lane reports mis-read a | ||
| 156 | +chroma unit's `txb_skip` / `tx_type` symbol on those lines and followed | ||
| 157 | +the luma arm — the log could not tell them apart. | ||
| 158 | + | ||
| 159 | +Fix: a `plane: usize` parameter on `read_coeffs_rect`, with each of the | ||
| 160 | +twenty call sites passing its own plane (`0` for the luma readers, | ||
| 161 | +`plane_idx` / `plane` where the enclosing reader already has one). | ||
| 162 | +`read_chroma_coeffs_rect` takes the same parameter and passes it | ||
| 163 | +through, so the U and V call sites in `decode_block_rect`, | ||
| 164 | +`decode_leaf_rect`, `decode_block_rect4`, `decode_rect4_16_strip` and | ||
| 165 | +`decode_block_rect64` stop collapsing into one tag. | ||
| 166 | + | ||
| 167 | +**Measurement** (`EC_TRACE_COEFF=1` on | ||
| 168 | +`a_444_lossy_rect4_inter_stream_decodes_pixel_exact`): | ||
| 169 | + | ||
| 170 | +| line | before | after | | ||
| 171 | +|---|---|---| | ||
| 172 | +| `tag=all_zero` | 932 lines, all `plane=0` | 312 `plane=0` / 310 `plane=1` / 310 `plane=2` | | ||
| 173 | +| `tag=tx_type` | 110 lines, all `plane=0` | 110 `plane=0` (this set's units are luma-only on this fixture) | | ||
| 174 | + | ||
| 175 | +No trace output changes in a default build: both lines are behind | ||
| 176 | +`coeff_trace_on()`, i.e. the env-gated `EC_TRACE_COEFF`. No gate output | ||
| 177 | +changes — the counter and assert set is untouched by this commit. | ||
| 178 | + | ||
| 179 | +--- | ||
| 180 | + | ||
| 181 | +## Not run here (Main's validation) | ||
| 182 | + | ||
| 183 | +Full crate suite, the multi-encode sweeps | ||
| 184 | +(`a_real_aomenc_inter_sequence_with_a_16_level_rect_leaf_decodes_pixel_exact` | ||
| 185 | +was run as a single named test only), the 4:2:0/10-bit/12-bit sweep | ||
| 186 | +families, and the server stages. Local runs were single named tests / one | ||
| 187 | +named-test batch, per the lane's local-scope rule. | ||