Lane-edge128 report
Browse files at this commit44fd4a8047d5196cb9e56f2b6b5912f83e89542aParent: 5e3125c- docs
- lane-edge128 report
1 changed file +167 -0
- lanes/edge128.report.md +167 -0
lanes/edge128.report.mdadded+167 -0
| @@ -0,0 +1,167 @@ | |||
| 1 | +# lane-edge128 — the 8-sample diff at the 128 superblock's edge | ||
| 2 | + | ||
| 3 | +The charter's premise was that reader and writer shared a wrong assumption | ||
| 4 | +about something read per 64x64 unit under a 128 block (deblock levels, tx | ||
| 5 | +sizes, skip, `delta_lf`, LR). **They do not.** The bitstream was always | ||
| 6 | +right: on the exact stream that fails, ffmpeg's decode and this crate's | ||
| 7 | +`decode_stream` are byte-identical over all 12 frames and all three planes. | ||
| 8 | +What disagreed with both of them is the ENCODER's own reconstruction — the | ||
| 9 | +picture the next frame predicts from — and the stage is CDEF, on the | ||
| 10 | +encoder's side of it alone. | ||
| 11 | + | ||
| 12 | +## 1. Reproduced | ||
| 13 | + | ||
| 14 | +`bd_rate_screen_native` with `EC_AV1_B128RES=1 EC_AV1_NATIVE_FILM4K=1`: | ||
| 15 | + | ||
| 16 | + B128R MISMATCH bars 2160p q=90 frame 11 plane Y: 8 samples, | ||
| 17 | + rows 126..127, cols 1611..1616 | ||
| 18 | + panicked: sample 243531: ffmpeg decoded 106, the encoder reconstructed 107 | ||
| 19 | + | ||
| 20 | +The gate's own q=90 stream (dumped from the failing run) is **byte-identical** | ||
| 21 | +to the one `enc_probe` writes for that row (411920 bytes, `fnv1a | ||
| 22 | +d36717e86823f28f`), so the defect reproduces outside the gate. Decoding that | ||
| 23 | +stream two ways: | ||
| 24 | + | ||
| 25 | +| pair | differing samples, frame 11 | | ||
| 26 | +|---|---| | ||
| 27 | +| ffmpeg vs `decode_stream` | **0** (and 0 over the whole 12-frame sequence) | | ||
| 28 | +| encoder reconstruction vs either decoder | **710** — Y 8, U 9, V 693 | | ||
| 29 | + | ||
| 30 | +The luma 8 the gate reports are the visible corner of a 710-sample block: | ||
| 31 | +V rows 0..63 cols 801..815 and U rows 62..63 cols 802..809 in chroma | ||
| 32 | +samples, i.e. **luma columns 1600..1663 of the 128x128 superblock at columns | ||
| 33 | +1536..1663** — the RIGHT half of one 128 superblock, its whole height. Not a | ||
| 34 | +band along an edge: two whole 64x64 CDEF units. | ||
| 35 | + | ||
| 36 | +## 2. The first divergent stage, and the rule | ||
| 37 | + | ||
| 38 | +There is no divergent DECODE stage — the pre-filter, post-deblock and | ||
| 39 | +post-CDEF planes are moot when both decoders agree byte for byte with each | ||
| 40 | +other. The divergence is between the stream and the encoder's | ||
| 41 | +`Encoded::reconstruction`, which is not a decode of the final tile at all: | ||
| 42 | +`pick_and_apply_filters` gets it from `crate::decode::replay_final`, a | ||
| 43 | +replay of deblock+CDEF over the captured pre-filter planes driven by the | ||
| 44 | +CDEF search's own per-64x64 `idx_grid`. | ||
| 45 | + | ||
| 46 | +**The rule the encoder broke** — `read_cdef`, spec 5.11.56: | ||
| 47 | + | ||
| 48 | + cdefSize4 = Num_4x4_Blocks_Wide[BLOCK_64X64] | ||
| 49 | + r = MiRow & ~(cdefSize4-1); c = MiCol & ~(cdefSize4-1) | ||
| 50 | + if (cdef_idx[r][c] == -1) { | ||
| 51 | + cdef_idx[r][c] = L(cdef_bits) | ||
| 52 | + for (i = r; i < r + h4; i += cdefSize4) | ||
| 53 | + for (j = c; j < c + w4; j += cdefSize4) | ||
| 54 | + cdef_idx[i][j] = cdef_idx[r][c] // every unit the BLOCK spans | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | +One literal per block, copied over every 64x64 unit that block spans. A | ||
| 58 | +whole 128x128 root block therefore puts **one** `cdef_idx` in the stream for | ||
| 59 | +all **four** of its units — which is exactly what `tile::write_cdef_idx` | ||
| 60 | +writes (one literal per superblock, at the first non-skip block) and exactly | ||
| 61 | +what `decode::maybe_read_cdef_idx` reads back since lane-b128r stamped the | ||
| 62 | +block's mi span. Both are right. | ||
| 63 | + | ||
| 64 | +`filter_search::pick_filters` priced a preset per 64x64 unit and handed all | ||
| 65 | +four to the replay. Only the origin unit's index reached the tile, so every | ||
| 66 | +decoder filtered the other three with the origin's strengths while the | ||
| 67 | +encoder's reconstruction carried three other strength pairs. Frame 11 is | ||
| 68 | +where the residual 128 root and a per-unit `cdef_idx` list finally met. | ||
| 69 | + | ||
| 70 | +**Class: `plan finer than its syntax`** — an encoder-side per-unit plan for | ||
| 71 | +a parameter the bitstream can only carry once per block. It is invisible to | ||
| 72 | +every stream-level gate (the stream is legal and decodes identically | ||
| 73 | +everywhere); it surfaces only where the encoder's reconstruction is compared | ||
| 74 | +against a decoder's, and then as a reference-chain error, not a syntax one. | ||
| 75 | + | ||
| 76 | +## 3. The fix (one shared map, both consumers) | ||
| 77 | + | ||
| 78 | +`tile::cdef_unit_owner(blocks, mi_cols, mi_rows)` maps each 64x64 unit to | ||
| 79 | +the unit whose literal covers it — identity for every block of one unit or | ||
| 80 | +less, and the root's top-left unit for the four units of a `Whole128` root. | ||
| 81 | +`pick_filters` takes it and decides per GROUP: a covered unit's per-unit SSE | ||
| 82 | +is summed into its owner's before the preset histogram and the `cdef_bits` | ||
| 83 | +cost are read off it, and after the grid is built each covered unit takes | ||
| 84 | +its owner's index. The identity map (`&[]`, the key-frame path, which has no | ||
| 85 | +128 root) is the behaviour this function always had. | ||
| 86 | + | ||
| 87 | +The map is built where the coded blocks are (`encode_inter_frame`) and | ||
| 88 | +travels through `pick_and_apply_filters` to the search, so the writer's | ||
| 89 | +`recode` and the encoder's filter replay read the same indices a decoder | ||
| 90 | +does. | ||
| 91 | + | ||
| 92 | +## 4. Same-shape sweep — every per-64x64-unit plan under a 128 block | ||
| 93 | + | ||
| 94 | +Three writer-side plans are keyed per 64x64 unit; the sweep is all three: | ||
| 95 | + | ||
| 96 | +| plan | state | | ||
| 97 | +|---|---| | ||
| 98 | +| `cdef_idx` (`arm_cdef_idx`) | **the defect, fixed here** | | ||
| 99 | +| `delta_q` (`arm_delta_q`) | already correct: `write_delta_q` gates on the 128-wide superblock (lane-b128m) AND `encode_inter_frame` collapses `sb_q` to the root's top-left cell before the search quantizes with it — the same shape, closed one lane earlier | | ||
| 100 | +| loop restoration (`arm_lr`) | not per-64 at all: `lr_unit()` is 128 under `EC_AV1_SB128`, `write_lr` writes it once at the root, and `pick_restoration` builds its grid from the same `lr_unit()` | | ||
| 101 | + | ||
| 102 | +The reads the charter suspected — deblock filter levels, the tx-size lookup | ||
| 103 | +for a TX_64X64 unit inside a 128 block, `delta_lf`, the per-unit CDEF skip | ||
| 104 | +decision — are all in the DECODER, which the encoder runs verbatim as its | ||
| 105 | +own filter stage, so reader and writer cannot disagree there by | ||
| 106 | +construction; and ffmpeg agreeing with `decode_stream` sample for sample on | ||
| 107 | +this exact stream clears them empirically as well. | ||
| 108 | + | ||
| 109 | +## 5. Witness | ||
| 110 | + | ||
| 111 | +`encode::tests::a_128_root_residual_block_under_a_per_unit_cdef_list_decodes_exact` | ||
| 112 | +(`--ignored`, 128 superblocks + the 128 root + its residual arm forced), | ||
| 113 | +`testsrc2` 1280x768, 12 frames, q=90: | ||
| 114 | + | ||
| 115 | + 128x128 blocks WITH a residual: writer coded 1440; | ||
| 116 | + 64x64 CDEF units taking another unit's literal: 168 | ||
| 117 | + test ... ok | ||
| 118 | + | ||
| 119 | +Both readers, every frame, every plane: `decode_stream` and ffmpeg against | ||
| 120 | +the encoder's own reconstruction. `take_cdef_covered_units` is the gate on | ||
| 121 | +the fixture (class `gate-blind-to-feature`): a clip whose CDEF spends one | ||
| 122 | +strength pair codes no literal and would witness nothing. | ||
| 123 | + | ||
| 124 | +**RED before the fix** (collapse disabled on this same tree, everything else | ||
| 125 | +identical): | ||
| 126 | + | ||
| 127 | + assertion `left == right` failed: frame 1: U -- 521 samples differ | ||
| 128 | + | ||
| 129 | +## 6. The residual arm, re-measured with the fix | ||
| 130 | + | ||
| 131 | +`bd_rate_screen_native`, 12 frames, `EC_AV1_B128RES=1` (control = the | ||
| 132 | +standing table, i.e. the arm off): | ||
| 133 | + | ||
| 134 | +| row | control | + the residual arm, fixed | | ||
| 135 | +|---|---|---| | ||
| 136 | +| bars 2160p | +8.6 / −13.7 | +8.6 / −13.7 | | ||
| 137 | +| film B (2160p) | +23.6 / −3.1 | +23.4 / −3.2 | | ||
| 138 | + | ||
| 139 | +This is the first COMPLETE measurement of the arm — before the fix the row | ||
| 140 | +panicked instead of finishing. It stays **behind `EC_AV1_B128RES=1`**: the | ||
| 141 | +arm is still inert on content (0–2 blocks per frame against ~90 whole 128 | ||
| 142 | +roots) and the two rows are inside the flat band. What the lane buys is not | ||
| 143 | +the arm; it is that the encoder's reconstruction is no longer a filter apart | ||
| 144 | +from what a decoder produces the moment a 128 root carries a residual. | ||
| 145 | + | ||
| 146 | +**The default encoder is byte-identical**: both pins hold at default and at | ||
| 147 | +`EC_AV1_SPEED=6`. They must — a default 128 root is always skipped, CDEF | ||
| 148 | +does not filter a unit whose blocks are all skip, and the fold it now goes | ||
| 149 | +through adds candidate-independent constants that cannot move an argmin. | ||
| 150 | + | ||
| 151 | +## 7. Suite / checks | ||
| 152 | + | ||
| 153 | + s1 --skip stream:: 344 passed; 0 failed; 37 ignored RC=0 | ||
| 154 | + s2 stream:: --skip 10bit 202 passed; 0 failed; 15 ignored RC=0 | ||
| 155 | + s3 10bit 42 passed; 0 failed; 1 ignored RC=0 | ||
| 156 | + --ignored every_speed_preset_decodes_sample_exact_through_both_decoders ok | ||
| 157 | + --ignored a_128_root_residual_block_under_a_per_unit_cdef_list... ok (1440 blocks, 168 covered units) | ||
| 158 | + --ignored a_128_superblock_clip_whose_root_search... ok | ||
| 159 | + --ignored a_128_root_block_with_a_real_residual... ok | ||
| 160 | + --ignored a_128_root_compound_block... ok | ||
| 161 | + the_encoders_own_streams_are_byte_identical_to_their_pins ok, and ok at EC_AV1_SPEED=6 | ||
| 162 | + cargo check --workspace --all-targets -j4 0 errors, 0 ec-av1 warnings | ||
| 163 | + | ||
| 164 | +## Pins | ||
| 165 | + | ||
| 166 | +NOT re-taken: 8364 / 33257 stand, at default and at `EC_AV1_SPEED=6`. The | ||
| 167 | +fix cannot reach a default stream (see §6). | ||