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-txset -- the transform-type search |
| 2 | |
| 3 | Branch `lane-txset` off main `3ebe0de9`. Scope: which `tx_type` an intra luma |
| 4 | transform unit is coded with, the forward kernels the missing types need, and |
| 5 | the writer symbol that names them. |
| 6 | |
| 7 | ## 1. Instrument: what was coded, what was searched (read off the code) |
| 8 | |
| 9 | The writer coded ONE transform type, everywhere, always: |
| 10 | |
| 11 | tile.rs:5216 enc.symbol(TX_TYPE_DCT_DCT_SET2, tx_type); // a constant |
| 12 | |
| 13 | and the search never varied a luma type either -- `search_block` and |
| 14 | `code_tx_depth` both go through `code_from_prediction`/`trial`, which pass |
| 15 | `TxType::DctDct` (`encode.rs:1993`, `:2278`). The only non-DCT types this |
| 16 | encoder has ever produced are CHROMA's, which code no symbol at all: the |
| 17 | decoder derives them from the chroma mode (`search_chroma` -> |
| 18 | `default_intra_tx_type`). |
| 19 | |
| 20 | STALE PREMISE IN THE CHARTER, corrected: this encoder writes |
| 21 | `reduced_tx_set: true` (`encode.rs:1660`, `:1760`) -- not 0. Under that bit |
| 22 | `get_tx_set` gives, per block class: |
| 23 | |
| 24 | | block class | tx size | set the WRITER uses | alphabet | types the search tried (before) | now | |
| 25 | |---|---|---|---|---|---| |
| 26 | | intra luma | 4x4, 8x8, 16x16 | `TX_SET_INTRA_2` (`intra_tx_type_{4,8,16}`) | 5 | DCT_DCT only | all 5 | |
| 27 | | intra luma | 32x32, 64x64 | none (`TxbSet::Luma{32,64}.tx_type == None`) | 1 | -- | -- | |
| 28 | | inter luma | 4x4..32x32 | `TX_SET_INTER_3` (`inter_tx_type_*`) | 2 (IDTX, DCT_DCT) | DCT_DCT only | DCT_DCT only | |
| 29 | | chroma | any | none, derived from uv_mode | -- | mode's default | unchanged | |
| 30 | |
| 31 | So the bytes reachable WITHOUT touching the frame header were the four |
| 32 | non-DCT members of `TX_SET_INTRA_2` on every intra luma unit at 16x16 and |
| 33 | below -- an alphabet the writer was already coding into, one symbol wide, and |
| 34 | never using. That is what this lane spends. |
| 35 | |
| 36 | Sets 13/17 (`DTT9_IDTX_1DDCT`, `ALL16`) that the charter names are NOT |
| 37 | reachable from here: they need `reduced_tx_set == 0` in the frame header, |
| 38 | which changes the alphabet of EVERY luma `tx_type` symbol in the stream |
| 39 | (`TxbSet::Luma*Set1`/`Set2` exist on the decode side with their CDFs; the |
| 40 | writer's set map at `tile.rs:4208` would have to take the bit). Deferred -- |
| 41 | see below. |
| 42 | |
| 43 | ## 2. Forward kernels |
| 44 | |
| 45 | `forward_transform_2d_typed` is basis-driven (`TxType::axes`), so |
| 46 | `V_DCT`/`H_DCT`/`V_ADST`/`H_ADST` and the plain ADST family already had |
| 47 | kernels; the FLIPADST family was refused by a `debug_assert`. A flipped axis |
| 48 | is the plain ADST kernel with the DECODER's output mirrored (`ud_flip` -> |
| 49 | row `h-1-i`, `lr_flip` -> column `w-1-j`), and a mirror is its own inverse, |
| 50 | so the analysis half is the same basis over the MIRRORED residual -- 12 lines, |
| 51 | no new kernel. |
| 52 | |
| 53 | Check: `transform::tests::a_typed_forward_round_trips_like_the_dct_one`, now |
| 54 | over all SIXTEEN types at 4x4/8x8/16x16 (was 3), each round trip's rmse under |
| 55 | 2x `DCT_DCT`'s. PASS. |
| 56 | |
| 57 | ## 3. The search + the writer |
| 58 | |
| 59 | * `encode::tx_type_candidates(set)` returns exactly the alphabet the writer |
| 60 | can name for that set, so a searched type is always codable. |
| 61 | * `code_tx_depth` picks a type PER TRANSFORM UNIT (RD: sse + lambda * bits, |
| 62 | the trial's bits carrying the `tx_type` symbol itself through |
| 63 | `coeff_bits_typed`/`rdoq`), stored at `tu_row * n + tu_col` -- the writer's |
| 64 | own index, so a unit the frame edge cuts away cannot slide the rest. |
| 65 | * `search_block` picks one for a whole-block transform, on the mode and angle |
| 66 | already settled (libaom's ordering, the same shape the angle refinement has). |
| 67 | * `BlockCoeffs::luma_tx_types` carries them to `write_luma_tus` / |
| 68 | `write_block_planes`; empty = `DCT_DCT` throughout, which is every inter, |
| 69 | palette and filter-intra block. |
| 70 | * The symbol comes from the DECODER's own map (`decode::tx_type_symbol`, |
| 71 | keyed by the CDF's alphabet width), so writer and reader cannot drift -- |
| 72 | and it already answers for the 7/12/16-symbol sets a `reduced_tx_set == 0` |
| 73 | lane would turn on. |
| 74 | * Lever: `speed::TX_TYPE_SEARCH` (presets 0-6 on, 7-10 off) AND a content |
| 75 | gate -- SCREEN FRAMES ONLY, see the gate table below. `EC_AV1_TXSET=0` |
| 76 | forces it off entirely. |
| 77 | |
| 78 | ## 4. Checks |
| 79 | |
| 80 | | check | result | |
| 81 | |---|---| |
| 82 | | `transform::tests::a_typed_forward_round_trips_like_the_dct_one` (16 types) | PASS | |
| 83 | | `encoder::tests::an_edge_clip_codes_every_reduced_set_tx_type_both_decoders_read_exactly` | PASS -- hits `[IDTX 12, DCT_DCT 15445, ADST_ADST 70, ADST_DCT 161, DCT_ADST 467]`, ours == ffmpeg every sample | |
| 84 | | `cargo test -p ec-av1 --lib --release round_trip` (19 tests) | PASS | |
| 85 | | `predicted_coeff_bits_track_the_tile_the_writer_wrote`, `tile_bytes_do_not_depend_on_the_thread_count --include-ignored`, `the_facade_codes_the_same_bytes_as_encode_sequence` | PASS | |
| 86 | | `cargo check -p ec-av1 --all-targets` | 0 errors, 0 warnings | |
| 87 | |
| 88 | |
| 89 | ## 5. The 12-frame gate (`encode::tests::bd_rate_screen_native`, 12 frames, gop 12) |
| 90 | |
| 91 | Control re-run on this head first (`EC_AV1_TXSET=0`), arm = the search on for |
| 92 | every frame. BD-rate vs libaom cpu-used 6 / vs rav1e speed 6, lower is better; |
| 93 | wall is ours per row. |
| 94 | |
| 95 | | clip | control | arm (all frames) | delta | wall ctl -> arm | |
| 96 | |---|---|---|---|---| |
| 97 | | bars 1080p | -1.0% / -16.8% | -2.3% / -17.8% | -1.3 / -1.0 | 247.2s -> 280.4s | |
| 98 | | bars 2160p | +9.4% / -12.7% | +10.2% / -11.6% | +0.8 / +1.1 | 168.8s -> 180.7s | |
| 99 | | film A | +21.7% / -4.4% | +22.1% / -4.0% | +0.4 / +0.4 | 153.9s -> 203.9s | |
| 100 | | film B | +26.9% / -0.6% | +28.1% / +0.7% | +1.2 / +1.3 | 133.5s -> 164.0s | |
| 101 | | screen capture | +27.8% / -26.0% | **+20.8% / -30.1%** | **-7.0 / -4.1** | 83.7s -> 120.6s | |
| 102 | |
| 103 | KEEP RULE VERDICT on the unconditional arm: FAIL. The rule wants both film |
| 104 | rows down; both go UP (film A +0.4/+0.4, film B +1.2/+1.3). The capture wins |
| 105 | seven points against libaom and four against rav1e -- the largest single |
| 106 | screen move this lane has on record -- so the search ships behind the SAME |
| 107 | content gate palette, intrabc and the angle-delta refinement already stand |
| 108 | behind (`search.screen`): a non-screen frame is byte-identical to the encoder |
| 109 | before the lane. |
| 110 | |
| 111 | Class note for the film loss: an ADST/IDTX unit is a locally cheaper |
| 112 | reconstruction that the next picture then predicts from -- the same |
| 113 | `local-rd-on-references` shape lane-fitu measured for filter intra, which is |
| 114 | why the film rows lose while the intra-heavy capture wins. |
| 115 | |
| 116 | ### Shipped state (screen gate on), confirm run |
| 117 | |
| 118 | | clip | control | shipped | note | |
| 119 | |---|---|---|---| |
| 120 | | bars 1080p | -1.0% / -16.8% | -1.0% / -16.8% | byte-identical (194497/299067/419042/567789 B) | |
| 121 | | bars 2160p | +9.4% / -12.7% | +9.4% / -12.7% | byte-identical (205409/321883/435765/564573 B) | |
| 122 | | film A | +21.7% / -4.4% | +21.7% / -4.4% | byte-identical (64392/102508/170169/413430 B) | |
| 123 | | film B | +26.9% / -0.6% | +26.9% / -0.6% | byte-identical (27442/50374/105485/296813 B) | |
| 124 | | screen capture | +27.8% / -26.0% | **+20.8% / -30.1%** | 36775/45758/57095/71711 B, wall 83.7s -> 96.2s (+15%) | |
| 125 | |
| 126 | Every non-screen row lands on the control's own byte counts to the digit -- |
| 127 | the gate is the frame classifier, and the four non-capture clips classify 0 |
| 128 | screen frames of 4 -- so nothing outside screen content moves, pins included. |
| 129 | |
| 130 | Pins: `encode::tests::the_encoders_own_streams_are_byte_identical_to_their_pins` |
| 131 | PASSES UNCHANGED at 8562 / 33357 -- the pin clip is not screen, so nothing to |
| 132 | re-pin. |
| 133 | |
| 134 | ## 6. Preset lever and invariants |
| 135 | |
| 136 | `speed::TX_TYPE_SEARCH = [true x7, false x4]` (presets 0-6 on) on top of the |
| 137 | screen content gate. The FIVE-type fire count is preset 0's: at preset 6 the |
| 138 | mode/partition pruning removes the blocks `ADST_ADST` and `IDTX` were winning |
| 139 | on (hits `[0, 6192, 0, 79, 284, ..]`), so the witness asserts the full set at |
| 140 | preset 0 and "some non-`DCT_DCT` type fires" at every preset that carries the |
| 141 | lever. |
| 142 | |
| 143 | | invariant | preset 0 | preset 6 | |
| 144 | |---|---|---| |
| 145 | | `an_edge_clip_codes_every_reduced_set_tx_type_both_decoders_read_exactly` | PASS | PASS | |
| 146 | | `tile_bytes_do_not_depend_on_the_thread_count --include-ignored` | PASS | PASS | |
| 147 | | `the_facade_codes_the_same_bytes_as_encode_sequence` | PASS | PASS | |
| 148 | | `predicted_coeff_bits_track_the_tile_the_writer_wrote` | PASS | PASS | |
| 149 | | all four above with `EC_COMP_MISMATCH=1` | 0 mismatches | 0 mismatches | |
| 150 | |
| 151 | `every_speed_preset_decodes_sample_exact_through_both_decoders --ignored` |
| 152 | PASS (with `EC_COMP_MISMATCH=1`). |
| 153 | `the_encoders_own_streams_are_byte_identical_to_their_pins`: PASS at the |
| 154 | UNCHANGED 8562 / 33357 -- no re-pin, the pin clip is not screen content. |
| 155 | |
| 156 | ## 7. The long-GOP gate at what ships, and the suite |
| 157 | |
| 158 | `encode::tests::bd_rate_film_long_gop` (48 pictures, gop 48) on the shipped |
| 159 | state -- both rows are non-screen and therefore byte-identical to the encoder |
| 160 | before the lane, which the 12-frame confirm run proves clip by clip: |
| 161 | |
| 162 | | clip | shipped | wall ours:libaom:rav1e | |
| 163 | |---|---|---| |
| 164 | | film A | +26.4% / -6.6% | 713.0s:38.4s:60.4s | |
| 165 | | film B | +89.8% / +9.1% | 459.0s:71.9s:59.0s | |
| 166 | |
| 167 | Full `ec-av1` suite, detached: **567 passed / 1 failed / 45 ignored** |
| 168 | (943s). The one failure is `stream::tests::no_per_frame_state_is_thread_local_any_more` |
| 169 | -- `["encode.rs: SB128"]`, main's own red from the sb128 merge that a fix lane |
| 170 | owns, not this lane's. `timeout 900 cargo check --workspace --all-targets -j4`: |
| 171 | 0 errors, 0 `ec-av1` warnings. |
| 172 | |
| 173 | ## 8. Deferred |
| 174 | |
| 175 | * `deferred: inter luma IDTX vs DCT_DCT (the two-type TX_SET_INTER_3 the |
| 176 | writer already codes) -- the plumbing is done (an inter block's |
| 177 | BlockCoeffs carries luma_tx_types through the same writer path), what is |
| 178 | missing is the candidate loop in code_from_prediction/commit_inter_luma and |
| 179 | a gate round -- unblocked by ~40 min of gate wall; the screen row is where |
| 180 | it would pay, same as the intra half.` |
| 181 | * `deferred: reduced_tx_set = 0 and the 13/17 alphabets (DTT9_IDTX_1DDCT, |
| 182 | ALL16) -- the FORWARD kernels are DONE and round-trip tested (all sixteen |
| 183 | types), decode::tx_type_symbol already answers for the 7/12/16-symbol sets, |
| 184 | and the decoder reads them; what is missing is the frame-header bit plus |
| 185 | the writer's set map (tile.rs:4208 -> the Luma*Set1/Set2 variants) and a |
| 186 | rav1e-speed-6-shaped candidate list per class -- unblocked by a lane of its |
| 187 | own. Note the shape this lane measured first: the wider a set gets, the |
| 188 | more the FILM rows lose (this five-type set already costs film A +0.4 and |
| 189 | film B +1.2), so that lane should gate by content from the start rather |
| 190 | than measure an unconditional arm.` |
| 191 | * `deferred: libaom's own tx_type histogram on film B (syntax_census) -- the |
| 192 | charter's instrument half. Not run: the two gate slots were the budget, and |
| 193 | the decision it would have informed (which types to offer) was settled by |
| 194 | the gate itself. Unblocked by one census run.` |