edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching·0 forks·Rust·370.3 MiB·9b67700·Tahinli·3 days ago·4021 commits
| 1 | # lane-txset2 -- the inter transform-type search, and reduced_tx_set=0 |
| 2 | |
| 3 | Branch `lane-txset2` off main `5e923074`. Predecessor: `lanes/txset.report.md` |
| 4 | (intra 5-type reduced set, screen-gated). |
| 5 | |
| 6 | ## Step 1 -- inter luma IDTX vs DCT_DCT (`TX_SET_INTER_3`) |
| 7 | |
| 8 | The writer already codes a two-symbol `tx_type` for every inter luma unit at |
| 9 | 32x32 and below (`TxbSet::Luma{4,8,16,32}Inter`) and always named `DCT_DCT`. |
| 10 | |
| 11 | * `encode::inter_tx_type_candidates(set, screen)` -- `[DCT_DCT, IDTX]` for |
| 12 | those four sets, `[DCT_DCT]` for the 64-point transform (no symbol) and for |
| 13 | chroma. |
| 14 | * `Plane::code_from_prediction_typed` / `mc_trial_typed` / |
| 15 | `mc_trial_compound_typed`: the untyped entries are now `DCT_DCT` wrappers, |
| 16 | so no call site outside the search moved. |
| 17 | * `commit_inter_luma` prices the candidates twice: once for the whole-block |
| 18 | (depth 0) residual, once per var-tx split unit, both by `sse + lambda * |
| 19 | bits` with the bits carrying the `tx_type` symbol through RDOQ -- the same |
| 20 | rule the intra search uses. The chosen types leave through the new fourth |
| 21 | element of its return and reach the writer as `BlockCoeffs::luma_tx_types` |
| 22 | (flat = one entry, split = four in the writer's raster order). |
| 23 | * Levers: `speed::TX_TYPE_SEARCH_INTER` (OFF at every preset until the gate |
| 24 | says otherwise), `EC_AV1_TXSET_INTER=0|screen|1`, plus a test-only |
| 25 | process-global override (`encode::set_inter_tx_search`). |
| 26 | * Census: `encode::INTER_TX_TYPE_HITS`, counted at the COMMIT points only, so |
| 27 | a split unit's winner the flat cost then beats is not counted. |
| 28 | |
| 29 | Witness: `encoder::tests::an_inter_clip_codes_both_inter_set_tx_types_both_decoders_read_exactly` |
| 30 | -- PASS, hits `[DCT_DCT 154 .., IDTX 1368 ..]`, ours == ffmpeg every sample. |
| 31 | |
| 32 | Gate rows: see below (arms running). |
| 33 | |
| 34 | ### The 12-frame gate (`encode::tests::bd_rate_screen_native`, 12 frames, gop 12) |
| 35 | |
| 36 | Control re-run on this head (`EC_AV1_TXSET_INTER=0`, which is also the |
| 37 | default): it REPRODUCES the charter's numbers to the digit, byte counts |
| 38 | included. |
| 39 | |
| 40 | | clip | control | arm: every frame, every size | delta | wall ctl -> arm | |
| 41 | |---|---|---|---|---| |
| 42 | | bars 1080p | -1.0% / -16.8% | **+23.1% / +3.3%** | +24.1 / +20.1 | 177.2s -> 182.0s | |
| 43 | | bars 2160p | +9.4% / -12.7% | **+31.2% / +3.7%** | +21.8 / +16.4 | 155.9s -> 160.7s | |
| 44 | | film A | +21.7% / -4.4% | +21.5% / -4.5% | -0.2 / -0.1 | 154.9s -> 167.7s | |
| 45 | | film B | +26.9% / -0.6% | +27.2% / -0.3% | +0.3 / +0.3 | 161.5s -> 167.6s | |
| 46 | | screen capture | +20.8% / -30.1% | +20.1% / -30.4% | -0.7 / -0.3 | 112.2s -> 109.5s | |
| 47 | |
| 48 | KEEP RULE on the unconditional arm: FAIL, and not marginally -- the two |
| 49 | synthetic bars rows lose TWENTY points (2 dB of luma PSNR at the same byte |
| 50 | count). Film A is 0.2/0.1 down, film B 0.3/0.3 up, the capture 0.7/0.3 down. |
| 51 | |
| 52 | The identity transform is not mis-scaled at 32x32: the typed round trip now |
| 53 | covers `side = 32` for the two types any set names there (`DCT_DCT`, `IDTX`; |
| 54 | ADST is undefined above 16) and `IDTX`'s rmse stays inside the DCT's 2x bound. |
| 55 | The bars collapse is the `local-rd-on-references` class again, at its loudest: |
| 56 | a flat synthetic frame is all 32x32 inter blocks whose residual `IDTX` prices |
| 57 | cheapest locally, and every later frame predicts from that reconstruction. |
| 58 | |
| 59 | ## Step 3 -- what libaom actually picks (instrument, read off lane-libcen's census) |
| 60 | |
| 61 | `lanes/libcen.report.md`'s census files (`~/.cache/lc-libcen/cen-*.txt`, |
| 62 | `crates/ec-av1/examples/syntax_census.rs`) already carry the per-frame |
| 63 | `tx_type` histogram keyed by CDF row length, so no new run was needed. Film B, |
| 64 | libaom cpu-used 6 crf41 (48 pictures), row length -> set: 3 = the 2-symbol |
| 65 | inter `DCT_IDTX` (32x32), 6 = the 5-symbol `TX_SET_INTRA_2` (intra 16x16 and, |
| 66 | under `reduced_tx_set`, all intra), 8 = the 7-symbol `TX_SET_INTRA_1` (intra |
| 67 | 8x8/4x4), 13 = the 12-symbol `TX_SET_INTER_2` (inter 16x16), 17 = ALL16 |
| 68 | (inter 8x8/4x4). |
| 69 | |
| 70 | | frame | set3 (inter 32) | set6 (intra 16) | set8 (intra 8/4) | set13 (inter 16) | set17 (inter <=8) | |
| 71 | |---|---|---|---|---|---| |
| 72 | | key (718 symbols) | -- | 85.3% | 14.7% | -- | -- | |
| 73 | | arf hint 30 (1058) | 27.5% | 6.8% | 4.5% | 51.7% | 9.7% | |
| 74 | | arf hint 15 (364) | 34.1% | 1.7% | 1.6% | 46.8% | 15.7% | |
| 75 | | arf hint 7 (61) | 67.2% | 1.6% | -- | 19.7% | 11.5% | |
| 76 | | arf hint 3 (41) | 78.0% | -- | -- | 9.7% | 12.3% | |
| 77 | |
| 78 | Two readings, both decisions: |
| 79 | |
| 80 | 1. **libaom never codes `IDTX` at 32x32 on film B.** Every one of its set3 |
| 81 | symbols is symbol 1 (`DCT_DCT`); symbol 0 does not appear in any frame of |
| 82 | the stream. That is exactly the size our unconditional arm loses its twenty |
| 83 | points on -- hence the `le16` arm below. |
| 84 | 2. **41% of its inter `tx_type` symbols are in sets 13/17**, i.e. the alphabets |
| 85 | `reduced_tx_set = 0` unlocks, and they are spread across nine or more |
| 86 | distinct types (set13 symbols 3..11 at 1.5-14% each). Our own stream codes |
| 87 | `set3/1` and `set6/1` only, 100% `DCT_DCT` in inter frames -- the gap step 2 |
| 88 | is aimed at. |
| 89 | |
| 90 | ### Step 1, second round: `le16` (the census's own prune) and the screen gate |
| 91 | |
| 92 | | clip | control | `le16` (16x16 and below) | screen-gated (SHIPPED) | |
| 93 | |---|---|---|---| |
| 94 | | bars 1080p | -1.0% / -16.8% | +22.9% / +3.1% | -1.0% / -16.8% (byte-identical) | |
| 95 | | bars 2160p | +9.4% / -12.7% | +31.6% / +4.0% | +9.4% / -12.7% (byte-identical) | |
| 96 | | film A | +21.7% / -4.4% | +21.6% / -4.5% | +21.7% / -4.4% (byte-identical) | |
| 97 | | film B | +26.9% / -0.6% | +27.4% / -0.1% | +26.9% / -0.6% (byte-identical) | |
| 98 | | screen capture | +20.8% / -30.1% | +19.9% / -30.4% | **+20.1% / -30.4%** | |
| 99 | |
| 100 | `le16` does NOT recover the bars rows (+22.9/+31.6 against the unconditional |
| 101 | arm's +23.1/+31.2), so the size restriction the libaom census suggested is |
| 102 | refuted as a fix: the damage is in the 16x16-and-below inter units, not the |
| 103 | 32x32 ones. It also drifts film B further up (+27.4/-0.1). |
| 104 | |
| 105 | DECISION: ship SCREEN-GATED, the same shape the intra half of lane-txset |
| 106 | ships behind. The four non-screen rows land on the control's own byte counts |
| 107 | to the digit (194497/299067/419042/567789, 205409/321883/435765/564573, |
| 108 | 64392/102508/170169/413430, 27442/50374/105485/296813 -- the clips classify |
| 109 | 0 screen frames of 4, the capture 48 of 48), so nothing outside screen |
| 110 | content moves, pins included. The capture is 0.7 down against libaom and 0.3 |
| 111 | against rav1e, at no wall cost (112.2s -> 109.4s, inside the noise). |
| 112 | |
| 113 | Levers as shipped: `speed::TX_TYPE_SEARCH_INTER` true at presets 0-6 (the row |
| 114 | the intra search carries), `inter_tx_type_search()` defaulting to |
| 115 | `Screen` on top of it. `EC_AV1_TXSET_INTER=1` is the unconditional arm, |
| 116 | `le16` the pruned one, `0` off. |
| 117 | |
| 118 | ## Step 2 -- `reduced_tx_set = 0` and the 13/17 alphabets: NOT ATTEMPTED, scoped |
| 119 | |
| 120 | `deferred: reduced_tx_set = 0 (sets 13/17, and the 7-symbol intra set at |
| 121 | 8x8/4x4) -- not started; the two gate slots and the budget went to step 1's |
| 122 | three arms. What it needs, from this lane's reading:` |
| 123 | |
| 124 | * The DECODER half is complete and needs nothing: `decode::txbset_for` / |
| 125 | `txbset_for_inter` already pick `Luma{8,4}Set1`, `Luma{16,8,4}InterSet1`, |
| 126 | `LumaRect16x8Set1`, `LumaRect{4x8,16x4}Set1`, `LumaRect8x4InterSet1` off the |
| 127 | frame's own bit, and `decode::tx_type_symbol` answers for the 7/12/16-symbol |
| 128 | alphabets. Note the spec shape the charter's table simplifies: intra 16x16 |
| 129 | stays the FIVE-type `TX_SET_INTRA_2` even with the bit off (there is no |
| 130 | `Luma16Set1` and none is needed), only intra 8x8/4x4 widen to seven; inter |
| 131 | 32x32 stays the two-type `DCT_IDTX`, inter 16x16 becomes the 12-symbol set |
| 132 | and inter 8x8/4x4 ALL16. |
| 133 | * The WRITER half is the cross-cutting part (class `tx-class-cross-cutting`): |
| 134 | the frame-header bit (`encode.rs:1660`, `:1760`) plus EVERY luma `TxbSet` |
| 135 | the writer and the pricer pick, which is `tile.rs` 2844, 4087, 4231-4238 |
| 136 | (`write_luma_tus`), 4611-4616, 6078, 7004/7006, 7217/7219 and `encode.rs` |
| 137 | `code_tx_depth` / `commit_inter_luma` / `inter_luma_set` / the trial set |
| 138 | arguments. A site that misses the bit codes the right value against the |
| 139 | wrong CDF -- the `wrong-alphabet-same-value` class -- so the bit belongs in |
| 140 | one accessor both sides read, not in nine `match` arms. |
| 141 | * The gate shape this lane measured says what to expect: a wider set is worth |
| 142 | BD only where the reference chain is short or intra-heavy. Both halves of |
| 143 | the search now measured (intra 5-type, inter 2-type) win on the capture and |
| 144 | lose on film, so a 13/17 lane should be armed screen-gated from the start |
| 145 | and spend its slots on the FILM question separately (the rate term, class |
| 146 | `rd-rate-term-calibration`, is the suspect: at equal bytes the bars rows |
| 147 | lose 2 dB of PSNR, which is a pricer that under-charges the cheap type, not |
| 148 | a decoder or kernel defect -- the typed round trip at 32 is inside its |
| 149 | bound). |
| 150 | |
| 151 | ## Invariants, the long-GOP gate and the suite (at the shipped state) |
| 152 | |
| 153 | | invariant | preset 0 | preset 6 | |
| 154 | |---|---|---| |
| 155 | | `an_inter_clip_codes_both_inter_set_tx_types_both_decoders_read_exactly` (new) | PASS | PASS | |
| 156 | | `an_edge_clip_codes_every_reduced_set_tx_type_both_decoders_read_exactly` | PASS | PASS | |
| 157 | | `tile_bytes_do_not_depend_on_the_thread_count --include-ignored` | PASS | PASS | |
| 158 | | `the_facade_codes_the_same_bytes_as_encode_sequence` | PASS | PASS | |
| 159 | | `predicted_coeff_bits_track_the_tile_the_writer_wrote` | PASS | PASS | |
| 160 | | all five above with `EC_COMP_MISMATCH=1` | 0 mismatches | 0 mismatches | |
| 161 | |
| 162 | `transform::tests::a_typed_forward_round_trips_like_the_dct_one` now covers |
| 163 | `side = 32` for `IDTX` (the size the inter search newly offers): PASS. |
| 164 | `every_speed_preset_decodes_sample_exact_through_both_decoders --ignored` |
| 165 | with `EC_COMP_MISMATCH=1`: PASS. |
| 166 | `the_encoders_own_streams_are_byte_identical_to_their_pins`: PASS at the |
| 167 | UNCHANGED 8562 / 33357 -- no re-pin, the pin clip is not screen content |
| 168 | (`EC_AV1_TXSET=0` therefore also restores them unchanged). |
| 169 | |
| 170 | `encode::tests::bd_rate_film_long_gop` at the shipped state (both rows are |
| 171 | non-screen, so byte-identical to the encoder before the lane, which the |
| 172 | 12-frame confirm run proves clip by clip): |
| 173 | |
| 174 | | clip | shipped | wall ours:libaom:rav1e | |
| 175 | |---|---|---| |
| 176 | | film A | +26.4% / -6.6% | 726.9s:52.9s:73.5s | |
| 177 | | film B | +89.8% / +9.1% | 489.9s:78.8s:52.2s | |
| 178 | |
| 179 | Full `ec-av1` suite, detached: **569 passed / 0 failed / 45 ignored** |
| 180 | (1327.8s). `timeout 890 cargo check --workspace --all-targets -j4`: 0 errors, |
| 181 | 0 `ec-av1` warnings (the 22 warnings the workspace prints are `ec-opus` / |
| 182 | `ec-vorbis`, untouched by this lane). |
| 183 | |
| 184 | ## Deferred |
| 185 | |
| 186 | * `deferred: reduced_tx_set = 0 and the 13/17 alphabets -- see the scoped |
| 187 | section above; unblocked by a lane of its own with two gate slots. Arm it |
| 188 | screen-gated from the start.` |
| 189 | * `deferred: the FILM question behind both halves of this search -- at equal |
| 190 | bytes the bars rows lose 2 dB, i.e. the pricer under-charges the cheap type |
| 191 | rather than any kernel or decoder being wrong (round trip at 32 is inside |
| 192 | its bound, the witness decodes sample-exact through ffmpeg). The upgrade |
| 193 | path is the rate term / lambda the type search compares with (class |
| 194 | rd-rate-term-calibration), not a wider set -- unblocked by a sweep of that |
| 195 | term against the bars and film rows.` |
| 196 | * `deferred: offering the inter search on a warp/OBMC winner -- commit_inter_luma |
| 197 | is skipped entirely for those blocks (motion_won != 0), so they still code |
| 198 | DCT_DCT; unblocked by pricing the type on the motion-mode prediction.` |