Merge branch 'lane-sb128b' (e8e64a6): the 128x128 PARTITION_NONE block decodes pixel-exact
Browse files at this commit8 changed files +825 -118
- crates/ec-av1/src/cdf.rs +10 -0
- crates/ec-av1/src/cdf_state.rs +21 -8
- crates/ec-av1/src/decode.rs +335 -109
- crates/ec-av1/src/refusal_inventory.rs +2 -1
- crates/ec-av1/src/stream.rs +156 -0
- lanes/sb128b-r1.report.md +103 -0
- lanes/sb128b-r2.report.md +97 -0
- lanes/sb128b-r3.report.md +101 -0
crates/ec-av1/src/cdf.rsmodified+10 -0
| @@ -3167,6 +3167,16 @@ pub const TXB_SKIP_CHROMA_16_Q3: [[u16; 3]; 3] = | |||
| 3167 | /// TXB_SKIP_CHROMA_32, q-context 3: the same table as [`TXB_SKIP_CHROMA_32`], for `base_q_idx` 121..=255. | 3167 | /// TXB_SKIP_CHROMA_32, q-context 3: the same table as [`TXB_SKIP_CHROMA_32`], for `base_q_idx` 121..=255. |
| 3168 | pub const TXB_SKIP_CHROMA_32_Q3: [[u16; 3]; 3] = | 3168 | pub const TXB_SKIP_CHROMA_32_Q3: [[u16; 3]; 3] = |
| 3169 | [[4656, 32768, 0], [16074, 32768, 0], [24704, 32768, 0]]; | 3169 | [[4656, 32768, 0], [16074, 32768, 0], [24704, 32768, 0]]; |
| 3170 | + | ||
| 3171 | +/// `av1_default_txb_skip_cdfs[q][TX_32X32][10..13]` (token_cdfs.h): libaom's | ||
| 3172 | +/// chroma `txb_skip_ctx` offset is 10 instead of 7 when the plane block is | ||
| 3173 | +/// LARGER than the transform (`get_txb_ctx`), which in AV1 happens only for a | ||
| 3174 | +/// 128x128 block's four TX_32X32 chroma units -- the offset-7 rows above are | ||
| 3175 | +/// every other case (lane-sb128b r3). | ||
| 3176 | +pub const TXB_SKIP_CHROMA_32_BIG_Q0: [[u16; 3]; 3] = [[146, 32768, 0], [5132, 32768, 0], [31657, 32768, 0]]; | ||
| 3177 | +pub const TXB_SKIP_CHROMA_32_BIG_Q1: [[u16; 3]; 3] = [[641, 32768, 0], [22265, 32768, 0], [31452, 32768, 0]]; | ||
| 3178 | +pub const TXB_SKIP_CHROMA_32_BIG: [[u16; 3]; 3] = [[3082, 32768, 0], [20982, 32768, 0], [29443, 32768, 0]]; | ||
| 3179 | +pub const TXB_SKIP_CHROMA_32_BIG_Q3: [[u16; 3]; 3] = [[1806, 32768, 0], [14645, 32768, 0], [25336, 32768, 0]]; | ||
| 3170 | /// EOB_EXTRA_LUMA_16, q-context 3: the same table as [`EOB_EXTRA_LUMA_16`], for `base_q_idx` 121..=255. | 3180 | /// EOB_EXTRA_LUMA_16, q-context 3: the same table as [`EOB_EXTRA_LUMA_16`], for `base_q_idx` 121..=255. |
| 3171 | pub const EOB_EXTRA_LUMA_16_Q3: [[u16; 3]; 9] = [ | 3181 | pub const EOB_EXTRA_LUMA_16_Q3: [[u16; 3]; 9] = [ |
| 3172 | [19941, 32768, 0], | 3182 | [19941, 32768, 0], |
crates/ec-av1/src/cdf_state.rsmodified+21 -8
| @@ -399,7 +399,10 @@ pub(crate) struct Cdfs { | |||
| 399 | /// The all-zero flag of a 16x16 chroma transform. | 399 | /// The all-zero flag of a 16x16 chroma transform. |
| 400 | pub txb_skip_chroma_16: [[u16; 3]; 3], | 400 | pub txb_skip_chroma_16: [[u16; 3]; 3], |
| 401 | /// The all-zero flag of a 32x32 chroma transform. | 401 | /// The all-zero flag of a 32x32 chroma transform. |
| 402 | - pub txb_skip_chroma_32: [[u16; 3]; 3], | 402 | + /// SIX contexts, not three: rows 0..3 are libaom's `txb_skip_ctx` 7..9 |
| 403 | + /// (chroma transform == its plane block) and rows 3..6 its 10..12 (plane | ||
| 404 | + /// block larger, i.e. a 128x128 block's four TX_32X32 chroma units). | ||
| 405 | + pub txb_skip_chroma_32: [[u16; 3]; 6], | ||
| 403 | /// The end-of-block group of a luma transform of 1024 positions. | 406 | /// The end-of-block group of a luma transform of 1024 positions. |
| 404 | pub eob_pt_1024_luma: [u16; 12], | 407 | pub eob_pt_1024_luma: [u16; 12], |
| 405 | /// The same, for chroma. | 408 | /// The same, for chroma. |
| @@ -1253,13 +1256,23 @@ impl Cdfs { | |||
| 1253 | cdf::TXB_SKIP_CHROMA_16, | 1256 | cdf::TXB_SKIP_CHROMA_16, |
| 1254 | cdf::TXB_SKIP_CHROMA_16_Q3, | 1257 | cdf::TXB_SKIP_CHROMA_16_Q3, |
| 1255 | ), | 1258 | ), |
| 1256 | - txb_skip_chroma_32: pick( | 1259 | + txb_skip_chroma_32: { |
| 1257 | - q_ctx, | 1260 | + let small = pick( |
| 1258 | - cdf::TXB_SKIP_CHROMA_32_Q0, | 1261 | + q_ctx, |
| 1259 | - cdf::TXB_SKIP_CHROMA_32_Q1, | 1262 | + cdf::TXB_SKIP_CHROMA_32_Q0, |
| 1260 | - cdf::TXB_SKIP_CHROMA_32, | 1263 | + cdf::TXB_SKIP_CHROMA_32_Q1, |
| 1261 | - cdf::TXB_SKIP_CHROMA_32_Q3, | 1264 | + cdf::TXB_SKIP_CHROMA_32, |
| 1262 | - ), | 1265 | + cdf::TXB_SKIP_CHROMA_32_Q3, |
| 1266 | + ); | ||
| 1267 | + let big = pick( | ||
| 1268 | + q_ctx, | ||
| 1269 | + cdf::TXB_SKIP_CHROMA_32_BIG_Q0, | ||
| 1270 | + cdf::TXB_SKIP_CHROMA_32_BIG_Q1, | ||
| 1271 | + cdf::TXB_SKIP_CHROMA_32_BIG, | ||
| 1272 | + cdf::TXB_SKIP_CHROMA_32_BIG_Q3, | ||
| 1273 | + ); | ||
| 1274 | + [small[0], small[1], small[2], big[0], big[1], big[2]] | ||
| 1275 | + }, | ||
| 1263 | eob_pt_1024_luma: pick( | 1276 | eob_pt_1024_luma: pick( |
| 1264 | q_ctx, | 1277 | q_ctx, |
| 1265 | cdf::EOB_PT_1024_LUMA_Q0, | 1278 | cdf::EOB_PT_1024_LUMA_Q0, |
crates/ec-av1/src/decode.rsmodified+335 -109
| @@ -310,10 +310,12 @@ fn maybe_read_delta_q(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_ | |||
| 310 | if mi_r % sb_mi != 0 || mi_c % sb_mi != 0 { | 310 | if mi_r % sb_mi != 0 || mi_c % sb_mi != 0 { |
| 311 | return; | 311 | return; |
| 312 | } | 312 | } |
| 313 | - // `is_whole_sb` is the caller's "this leaf IS the superblock" flag, which | 313 | + // `is_whole_sb` is the caller's "this leaf IS the superblock" flag, |
| 314 | - // it computes against the 64x64 root; under a 128 superblock no leaf this | 314 | + // computed against the sequence's own superblock size (lane-sb128b r1: |
| 315 | - // decoder codes can be the whole superblock (the root is always SPLIT). | 315 | + // it used to be hardcoded against 64 and disabled under `sb128`, which a |
| 316 | - if is_whole_sb && !sb128() && skip { | 316 | + // `PARTITION_NONE` 128x128 root -- itself the whole superblock -- makes |
| 317 | + // wrong). | ||
| 318 | + if is_whole_sb && skip { | ||
| 317 | return; | 319 | return; |
| 318 | } | 320 | } |
| 319 | let mut abs = dec.symbol(&mut cdfs.delta_q) as i32; | 321 | let mut abs = dec.symbol(&mut cdfs.delta_q) as i32; |
| @@ -369,10 +371,12 @@ fn maybe_read_delta_lf(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi | |||
| 369 | if mi_r % sb_mi != 0 || mi_c % sb_mi != 0 { | 371 | if mi_r % sb_mi != 0 || mi_c % sb_mi != 0 { |
| 370 | return; | 372 | return; |
| 371 | } | 373 | } |
| 372 | - // `is_whole_sb` is the caller's "this leaf IS the superblock" flag, which | 374 | + // `is_whole_sb` is the caller's "this leaf IS the superblock" flag, |
| 373 | - // it computes against the 64x64 root; under a 128 superblock no leaf this | 375 | + // computed against the sequence's own superblock size (lane-sb128b r1: |
| 374 | - // decoder codes can be the whole superblock (the root is always SPLIT). | 376 | + // it used to be hardcoded against 64 and disabled under `sb128`, which a |
| 375 | - if is_whole_sb && !sb128() && skip { | 377 | + // `PARTITION_NONE` 128x128 root -- itself the whole superblock -- makes |
| 378 | + // wrong). | ||
| 379 | + if is_whole_sb && skip { | ||
| 376 | return; | 380 | return; |
| 377 | } | 381 | } |
| 378 | let multi = DELTA_LF_MULTI.with(|c| c.get()); | 382 | let multi = DELTA_LF_MULTI.with(|c| c.get()); |
| @@ -4859,6 +4863,32 @@ impl Neighbours { | |||
| 4859 | self.record_mi_luma_rect(at_mi, tx_px, tx_px, grid); | 4863 | self.record_mi_luma_rect(at_mi, tx_px, tx_px, grid); |
| 4860 | } | 4864 | } |
| 4861 | 4865 | ||
| 4866 | + /// [`Self::record_mi_luma`] for ONE CHROMA transform unit of a block whose | ||
| 4867 | + /// uv plane block is several units (lane-sb128b r2: a 128x128 block's | ||
| 4868 | + /// 64x64 uv plane block is four TX_32X32 units, `av1_get_max_uv_txsize`). | ||
| 4869 | + /// `w_px`/`h_px` are the unit's extent in LUMA pixels -- the chroma | ||
| 4870 | + /// coefficient-context arrays are indexed by luma mi, the convention | ||
| 4871 | + /// [`Self::record_split_luma_rect_mi`] already writes them in, frame-edge | ||
| 4872 | + /// clamp included. | ||
| 4873 | + fn record_mi_chroma( | ||
| 4874 | + &mut self, | ||
| 4875 | + (mi_r, mi_c): (usize, usize), | ||
| 4876 | + w_px: usize, | ||
| 4877 | + h_px: usize, | ||
| 4878 | + plane: usize, | ||
| 4879 | + grid: &[i32], | ||
| 4880 | + ) { | ||
| 4881 | + let round_up_even = |n: usize| n.div_ceil(2) * 2; | ||
| 4882 | + let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); | ||
| 4883 | + let state = neighbour_state(grid); | ||
| 4884 | + for cell in 0..(h_px / MI).min(bound_h.saturating_sub(mi_r)) { | ||
| 4885 | + self.left[mi_r + cell][plane] = state; | ||
| 4886 | + } | ||
| 4887 | + for cell in 0..(w_px / MI).min(bound_w.saturating_sub(mi_c)) { | ||
| 4888 | + self.above[mi_c + cell][plane] = state; | ||
| 4889 | + } | ||
| 4890 | + } | ||
| 4891 | + | ||
| 4862 | /// [`Self::record_mi_luma`] for a RECTANGULAR transform unit (lane-rectsplitx | 4892 | /// [`Self::record_mi_luma`] for a RECTANGULAR transform unit (lane-rectsplitx |
| 4863 | /// r1): the above context spans the unit's width, the left context its | 4893 | /// r1): the above context spans the unit's width, the left context its |
| 4864 | /// height, which for a square unit is the same loop it always was. | 4894 | /// height, which for a square unit is the same loop it always was. |
| @@ -8399,8 +8429,12 @@ fn read_intra_mode( | |||
| 8399 | // `segment_id`, `cdef`, `delta_q` -- `cdef` lands right here. | 8429 | // `segment_id`, `cdef`, `delta_q` -- `cdef` lands right here. |
| 8400 | maybe_read_cdef_idx(dec, mi_r, mi_c, skip); | 8430 | maybe_read_cdef_idx(dec, mi_r, mi_c, skip); |
| 8401 | istep!("cdef", 0); | 8431 | istep!("cdef", 0); |
| 8402 | - maybe_read_delta_q(dec, cdfs, mi_r, mi_c, side == 64, skip); | 8432 | + // lane-sb128b r1: "this leaf IS the superblock" is `side == sb_size`, not |
| 8403 | - maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, side == 64, skip); | 8433 | + // a hardcoded 64 -- a `PARTITION_NONE` 128x128 root is the whole |
| 8434 | + // superblock and skips `delta_q` exactly like a 64 one under a 64 root. | ||
| 8435 | + let whole_sb = side == sb_mi_cur() as usize * 4; | ||
| 8436 | + maybe_read_delta_q(dec, cdfs, mi_r, mi_c, whole_sb, skip); | ||
| 8437 | + maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, whole_sb, skip); | ||
| 8404 | istep!("dq", 0); | 8438 | istep!("dq", 0); |
| 8405 | // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at | 8439 | // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at |
| 8406 | // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before | 8440 | // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before |
| @@ -9094,7 +9128,12 @@ fn read_plane( | |||
| 9094 | let skip_ctx = if plane_idx == 0 { | 9128 | let skip_ctx = if plane_idx == 0 { |
| 9095 | luma_skip_ctx.unwrap_or(0) | 9129 | luma_skip_ctx.unwrap_or(0) |
| 9096 | } else { | 9130 | } else { |
| 9097 | - usize::from(around.0) + usize::from(around.1) | 9131 | + // libaom `get_txb_ctx`: a chroma unit's context is |
| 9132 | + // `combine_entropy_contexts(above, left)` plus 7, or plus 10 when the | ||
| 9133 | + // plane block is bigger than the transform. Our chroma tables hold the | ||
| 9134 | + // offset-7 rows first, so the caller adds 3 for the bigger-block case | ||
| 9135 | + // (only a 128x128 block's TX_32X32 chroma units, lane-sb128b r3). | ||
| 9136 | + usize::from(around.0) + usize::from(around.1) + luma_skip_ctx.unwrap_or(0) | ||
| 9098 | }; | 9137 | }; |
| 9099 | // spec 5.11.47/libaom `av1_read_tx_type`: a filter-intra luma block's | 9138 | // spec 5.11.47/libaom `av1_read_tx_type`: a filter-intra luma block's |
| 9100 | // `intra_ext_tx_cdf` row is indexed by `fimode_to_intradir[filter_intra_mode]`, | 9139 | // `intra_ext_tx_cdf` row is indexed by `fimode_to_intradir[filter_intra_mode]`, |
| @@ -9279,7 +9318,11 @@ fn decode_block( | |||
| 9279 | let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, None); | 9318 | let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, None); |
| 9280 | (resolved, if resolved == 64 { 32 } else { resolved }) | 9319 | (resolved, if resolved == 64 { 32 } else { resolved }) |
| 9281 | } else { | 9320 | } else { |
| 9282 | - (side, luma_tx) | 9321 | + // lane-sb128b r1: `max_txsize_rect_lookup[BLOCK_128X128]` is |
| 9322 | + // TX_64X64, so a 128x128 block is always FOUR luma transform units | ||
| 9323 | + // even with `tx_select` off -- the TU loop below, never the | ||
| 9324 | + // single-unit path. | ||
| 9325 | + (side.min(64), luma_tx) | ||
| 9283 | }; | 9326 | }; |
| 9284 | if tx_select && logical_tx < side && uv_mode != DC_PRED { | 9327 | if tx_select && logical_tx < side && uv_mode != DC_PRED { |
| 9285 | SQ_CHROMA_TX_HITS.with(|c| c.set(c.get() + 1)); | 9328 | SQ_CHROMA_TX_HITS.with(|c| c.set(c.get() + 1)); |
| @@ -9384,10 +9427,17 @@ fn decode_block( | |||
| 9384 | // The palette/intrabc override path keeps the single-call shape (its | 9427 | // The palette/intrabc override path keeps the single-call shape (its |
| 9385 | // per-TU windowing is the non-skip loop's own `palette_y_buf` slice, | 9428 | // per-TU windowing is the non-skip loop's own `palette_y_buf` slice, |
| 9386 | // untested for skip and unreachable in these streams). | 9429 | // untested for skip and unreachable in these streams). |
| 9430 | + // lane-sb128b r2: a 128x128 block's transform is TX_64X64 even with | ||
| 9431 | + // `tx_select` off (`max_txsize_rect_lookup[BLOCK_128X128]`), so the | ||
| 9432 | + // per-unit prediction is keyed on the transform being smaller than | ||
| 9433 | + // the block, not on the tx-depth syntax. The counter keeps lane-hgkf's | ||
| 9434 | + // narrower meaning (a READ split tx depth). | ||
| 9387 | let split_tx_skip = | 9435 | let split_tx_skip = |
| 9388 | - tx_select && logical_tx < side && palette_y_buf.is_none() && intrabc_bufs.is_none(); | 9436 | + logical_tx < side && palette_y_buf.is_none() && intrabc_bufs.is_none(); |
| 9389 | if split_tx_skip { | 9437 | if split_tx_skip { |
| 9390 | - SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | 9438 | + if tx_select { |
| 9439 | + SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | ||
| 9440 | + } | ||
| 9391 | let n_axis = side / logical_tx; | 9441 | let n_axis = side / logical_tx; |
| 9392 | for tu_row in 0..n_axis { | 9442 | for tu_row in 0..n_axis { |
| 9393 | for tu_col in 0..n_axis { | 9443 | for tu_col in 0..n_axis { |
| @@ -9437,41 +9487,62 @@ fn decode_block( | |||
| 9437 | ); | 9487 | ); |
| 9438 | } | 9488 | } |
| 9439 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 9489 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 9440 | - if let Some((ub, _)) = &palette_uv_bufs { | 9490 | + let cn = (chroma_side / chroma_tx).max(1); |
| 9441 | - set_palette_pred(ub.clone()); | 9491 | + for cu_row in 0..cn { |
| 9442 | - } | 9492 | + for cu_col in 0..cn { |
| 9443 | - u.reconstruct( | 9493 | + let luma_span = chroma_tx * 2; |
| 9444 | - cpx, | 9494 | + let cu_r = if cn == 1 { |
| 9445 | - cpy, | 9495 | + reach |
| 9446 | - chroma_side, | 9496 | + } else { |
| 9447 | - uv_predict_mode, | 9497 | + tu_reach( |
| 9448 | - angle_delta_uv, | 9498 | + side, side, |
| 9449 | - reach, | 9499 | + cu_col * luma_span, cu_row * luma_span, luma_span, |
| 9450 | - &vec![0i32; chroma_side * chroma_side], | 9500 | + reach, px, py, y.width, y.height, |
| 9451 | - alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | 9501 | + ) |
| 9452 | - None, | 9502 | + }; |
| 9453 | - smooth_neighbor_uv, | 9503 | + let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx); |
| 9454 | - ); | 9504 | + if let Some((ub, _)) = &palette_uv_bufs { |
| 9455 | - if let Some((_, vb)) = &palette_uv_bufs { | 9505 | + set_palette_pred(ub.clone()); |
| 9456 | - set_palette_pred(vb.clone()); | 9506 | + } |
| 9507 | + u.reconstruct( | ||
| 9508 | + cu_x, | ||
| 9509 | + cu_y, | ||
| 9510 | + chroma_tx, | ||
| 9511 | + uv_predict_mode, | ||
| 9512 | + angle_delta_uv, | ||
| 9513 | + cu_r, | ||
| 9514 | + &vec![0i32; chroma_tx * chroma_tx], | ||
| 9515 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | ||
| 9516 | + None, | ||
| 9517 | + smooth_neighbor_uv, | ||
| 9518 | + ); | ||
| 9519 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 9520 | + set_palette_pred(vb.clone()); | ||
| 9521 | + } | ||
| 9522 | + v.reconstruct( | ||
| 9523 | + cu_x, | ||
| 9524 | + cu_y, | ||
| 9525 | + chroma_tx, | ||
| 9526 | + uv_predict_mode, | ||
| 9527 | + angle_delta_uv, | ||
| 9528 | + cu_r, | ||
| 9529 | + &vec![0i32; chroma_tx * chroma_tx], | ||
| 9530 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 9531 | + None, | ||
| 9532 | + smooth_neighbor_uv, | ||
| 9533 | + ); | ||
| 9534 | + } | ||
| 9457 | } | 9535 | } |
| 9458 | - v.reconstruct( | ||
| 9459 | - cpx, | ||
| 9460 | - cpy, | ||
| 9461 | - chroma_side, | ||
| 9462 | - uv_predict_mode, | ||
| 9463 | - angle_delta_uv, | ||
| 9464 | - reach, | ||
| 9465 | - &vec![0i32; chroma_side * chroma_side], | ||
| 9466 | - alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 9467 | - None, | ||
| 9468 | - smooth_neighbor_uv, | ||
| 9469 | - ); | ||
| 9470 | let luma_grid = vec![0i32; side * side]; | 9536 | let luma_grid = vec![0i32; side * side]; |
| 9471 | let u_grid = vec![0i32; chroma_side * chroma_side]; | 9537 | let u_grid = vec![0i32; chroma_side * chroma_side]; |
| 9472 | let v_grid = vec![0i32; chroma_side * chroma_side]; | 9538 | let v_grid = vec![0i32; chroma_side * chroma_side]; |
| 9473 | neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]); | 9539 | neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]); |
| 9474 | - } else if !tx_select || logical_tx == side { | 9540 | + } else if logical_tx == side { |
| 9541 | + // lane-sb128b r1: the test used to be `!tx_select || logical_tx == side`. | ||
| 9542 | + // Without `tx_select` `logical_tx` IS `side` at every size <= 64, so | ||
| 9543 | + // that arm was redundant -- and wrong at 128, where | ||
| 9544 | + // `max_txsize_rect_lookup` caps the block's transform at 64 and the | ||
| 9545 | + // block is four units whether or not `tx_select` is on. | ||
| 9475 | // A single luma transform unit -- the old path, unchanged (including | 9546 | // A single luma transform unit -- the old path, unchanged (including |
| 9476 | // the 64x64 corner case, `logical_tx == side == 64` with | 9547 | // the 64x64 corner case, `logical_tx == side == 64` with |
| 9477 | // `coeff_tx_side == 32`). | 9548 | // `coeff_tx_side == 32`). |
| @@ -9564,8 +9635,27 @@ fn decode_block( | |||
| 9564 | // the earlier tiles in this same block already wrote -- the same | 9635 | // the earlier tiles in this same block already wrote -- the same |
| 9565 | // per-TU pattern [`decode_leaf8`] already runs for an 8x8 leaf. | 9636 | // per-TU pattern [`decode_leaf8`] already runs for an 8x8 leaf. |
| 9566 | let n_axis = side / logical_tx; | 9637 | let n_axis = side / logical_tx; |
| 9567 | - for tu_row in 0..n_axis { | 9638 | + let cn = (chroma_side / chroma_tx).max(1); |
| 9568 | - for tu_col in 0..n_axis { | 9639 | + // libaom's transform-block loop is over 64x64 luma "mu" chunks |
| 9640 | + // (`decode_token_recon_block`: `mu_blocks_wide/high` = | ||
| 9641 | + // `mi_size_wide[BLOCK_64X64]`), and it codes EVERY PLANE of a chunk | ||
| 9642 | + // before moving to the next one. Below 128 a block is a single chunk, | ||
| 9643 | + // so this is byte-for-byte the all-luma-then-all-chroma order that has | ||
| 9644 | + // always run; at 128 the four quadrants interleave Y,U,V per quadrant | ||
| 9645 | + // and reading all four luma units first desyncs the tile at the second | ||
| 9646 | + // one (lane-sb128b r3, measured against aomdec's `EC_TRACE_COEFF`). | ||
| 9647 | + let nchunk = (side / 64).max(1); | ||
| 9648 | + // `cn > 1` means the uv plane block is larger than the uv transform, | ||
| 9649 | + // which moves libaom's chroma `txb_skip_ctx` offset from 7 to 10. | ||
| 9650 | + let chroma_ctx_offset = if cn > 1 { Some(3) } else { None }; | ||
| 9651 | + let tpc = (n_axis / nchunk).max(1); | ||
| 9652 | + let cpc = (cn / nchunk).max(1); | ||
| 9653 | + let mut last_grids = [Vec::new(), Vec::new()]; | ||
| 9654 | + let mut units: Vec<((usize, usize), usize, Vec<i32>, Vec<i32>)> = Vec::new(); | ||
| 9655 | + for ch_row in 0..nchunk { | ||
| 9656 | + for ch_col in 0..nchunk { | ||
| 9657 | + for tu_row in ch_row * tpc..(ch_row + 1) * tpc { | ||
| 9658 | + for tu_col in ch_col * tpc..(ch_col + 1) * tpc { | ||
| 9569 | let tu_mi = ( | 9659 | let tu_mi = ( |
| 9570 | mi_r + tu_row * (logical_tx / MI), | 9660 | mi_r + tu_row * (logical_tx / MI), |
| 9571 | mi_c + tu_col * (logical_tx / MI), | 9661 | mi_c + tu_col * (logical_tx / MI), |
| @@ -9626,7 +9716,11 @@ fn decode_block( | |||
| 9626 | tu_px, | 9716 | tu_px, |
| 9627 | tu_py, | 9717 | tu_py, |
| 9628 | logical_tx, | 9718 | logical_tx, |
| 9629 | - logical_tx, | 9719 | + // The unit's own COEFFICIENT grid, half its side at |
| 9720 | + // TX_64X64 (a 64-point transform codes nothing past 32); | ||
| 9721 | + // identical to `logical_tx` at every smaller size | ||
| 9722 | + // (lane-sb128b r1). | ||
| 9723 | + coeff_tx_side, | ||
| 9630 | base_q_idx, | 9724 | base_q_idx, |
| 9631 | None, | 9725 | None, |
| 9632 | filter_intra, | 9726 | filter_intra, |
| @@ -9644,59 +9738,81 @@ fn decode_block( | |||
| 9644 | neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid); | 9738 | neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid); |
| 9645 | } | 9739 | } |
| 9646 | } | 9740 | } |
| 9741 | + // CfL is only allowed up to 32x32, i.e. only at `nchunk == 1`, where | ||
| 9742 | + // this still runs after every luma unit of the block. | ||
| 9647 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 9743 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 9648 | - let chroma_around = neighbours.around(at, side); | 9744 | + // The block's uv plane block is `chroma_side` across but its uv |
| 9649 | - if let Some((ub, _)) = &palette_uv_bufs { | 9745 | + // transform is `chroma_tx` (`av1_get_max_uv_txsize` = |
| 9650 | - set_palette_pred(ub.clone()); | 9746 | + // `av1_get_adjusted_tx_size(max_txsize_rect_lookup[uv_plane_bsize])`): |
| 9747 | + // identical at every size up to 64x64, but a 128x128 block's 64x64 uv | ||
| 9748 | + // plane block adjusts TX_64X64 down to TX_32X32, so each plane is | ||
| 9749 | + // FOUR units (lane-sb128b r2) -- one per mu chunk. | ||
| 9750 | + for cu_row in ch_row * cpc..(ch_row + 1) * cpc { | ||
| 9751 | + for cu_col in ch_col * cpc..(ch_col + 1) * cpc { | ||
| 9752 | + // The chroma context arrays are indexed in LUMA mi, so this | ||
| 9753 | + // unit's anchor is its own luma quadrant: `chroma_tx` chroma | ||
| 9754 | + // pixels span `2 * chroma_tx` luma ones. | ||
| 9755 | + let luma_span = chroma_tx * 2; | ||
| 9756 | + let cu_mi = ( | ||
| 9757 | + mi_r + cu_row * (luma_span / MI), | ||
| 9758 | + mi_c + cu_col * (luma_span / MI), | ||
| 9759 | + ); | ||
| 9760 | + let cu_around = neighbours.around_mi(cu_mi, luma_span); | ||
| 9761 | + let cu_reach = if cn == 1 { | ||
| 9762 | + reach | ||
| 9763 | + } else { | ||
| 9764 | + tu_reach( | ||
| 9765 | + side, side, | ||
| 9766 | + cu_col * luma_span, cu_row * luma_span, luma_span, | ||
| 9767 | + reach, px, py, y.width, y.height, | ||
| 9768 | + ) | ||
| 9769 | + }; | ||
| 9770 | + let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx); | ||
| 9771 | + if let Some((ub, _)) = &palette_uv_bufs { | ||
| 9772 | + set_palette_pred(ub.clone()); | ||
| 9773 | + } | ||
| 9774 | + let u_grid = read_plane( | ||
| 9775 | + dec, cdfs, chroma_set, scans.1, 1, cu_around[1], mode, | ||
| 9776 | + uv_predict_mode, angle_delta_uv, cu_reach, u, cu_x, cu_y, | ||
| 9777 | + chroma_tx, chroma_tx, base_q_idx, | ||
| 9778 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | ||
| 9779 | + None, chroma_ctx_offset, smooth_neighbor_uv, | ||
| 9780 | + )?; | ||
| 9781 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 9782 | + set_palette_pred(vb.clone()); | ||
| 9783 | + } | ||
| 9784 | + let v_grid = read_plane( | ||
| 9785 | + dec, cdfs, chroma_set, scans.1, 2, cu_around[2], mode, | ||
| 9786 | + uv_predict_mode, angle_delta_uv, cu_reach, v, cu_x, cu_y, | ||
| 9787 | + chroma_tx, chroma_tx, base_q_idx, | ||
| 9788 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 9789 | + None, chroma_ctx_offset, smooth_neighbor_uv, | ||
| 9790 | + )?; | ||
| 9791 | + if cn > 1 { | ||
| 9792 | + CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | ||
| 9793 | + // Immediately, so the NEXT unit of this same block reads | ||
| 9794 | + // this one's coefficient context (libaom's chroma | ||
| 9795 | + // `txb_skip_ctx` for the second quadrant is 11, i.e. base | ||
| 9796 | + // 1 from this left neighbour -- measured against aomdec). | ||
| 9797 | + // The same writes are replayed after `record_split_luma` | ||
| 9798 | + // below, which would otherwise clobber them whole-block. | ||
| 9799 | + neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, 1, &u_grid); | ||
| 9800 | + neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, 2, &v_grid); | ||
| 9801 | + units.push((cu_mi, luma_span, u_grid.clone(), v_grid.clone())); | ||
| 9802 | + } | ||
| 9803 | + last_grids = [u_grid, v_grid]; | ||
| 9804 | + } | ||
| 9651 | } | 9805 | } |
| 9652 | - let u_grid = read_plane( | ||
| 9653 | - dec, | ||
| 9654 | - cdfs, | ||
| 9655 | - chroma_set, | ||
| 9656 | - scans.1, | ||
| 9657 | - 1, | ||
| 9658 | - chroma_around[1], | ||
| 9659 | - mode, | ||
| 9660 | - uv_predict_mode, | ||
| 9661 | - angle_delta_uv, | ||
| 9662 | - reach, | ||
| 9663 | - u, | ||
| 9664 | - cpx, | ||
| 9665 | - cpy, | ||
| 9666 | - chroma_side, | ||
| 9667 | - chroma_tx, | ||
| 9668 | - base_q_idx, | ||
| 9669 | - alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | ||
| 9670 | - None, | ||
| 9671 | - None, | ||
| 9672 | - smooth_neighbor_uv, | ||
| 9673 | - )?; | ||
| 9674 | - if let Some((_, vb)) = &palette_uv_bufs { | ||
| 9675 | - set_palette_pred(vb.clone()); | ||
| 9676 | } | 9806 | } |
| 9677 | - let v_grid = read_plane( | 9807 | + } |
| 9678 | - dec, | 9808 | + // Mode/side bookkeeping plus, at `cn == 1`, the whole-plane chroma |
| 9679 | - cdfs, | 9809 | + // context write; at `cn > 1` the per-unit writes above are what the |
| 9680 | - chroma_set, | 9810 | + // next block reads, so they run after this (last writer wins). |
| 9681 | - scans.1, | 9811 | + neighbours.record_split_luma(at, side, mode, uv_predict_mode, [&last_grids[0], &last_grids[1]]); |
| 9682 | - 2, | 9812 | + for (cu_mi, luma_span, u_grid, v_grid) in &units { |
| 9683 | - chroma_around[2], | 9813 | + neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 1, u_grid); |
| 9684 | - mode, | 9814 | + neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 2, v_grid); |
| 9685 | - uv_predict_mode, | 9815 | + } |
| 9686 | - angle_delta_uv, | ||
| 9687 | - reach, | ||
| 9688 | - v, | ||
| 9689 | - cpx, | ||
| 9690 | - cpy, | ||
| 9691 | - chroma_side, | ||
| 9692 | - chroma_tx, | ||
| 9693 | - base_q_idx, | ||
| 9694 | - alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 9695 | - None, | ||
| 9696 | - None, | ||
| 9697 | - smooth_neighbor_uv, | ||
| 9698 | - )?; | ||
| 9699 | - neighbours.record_split_luma(at, side, mode, uv_predict_mode, [&u_grid, &v_grid]); | ||
| 9700 | } | 9816 | } |
| 9701 | // Unconditional, `size == 0` for a non-palette block: clears any stale | 9817 | // Unconditional, `size == 0` for a non-palette block: clears any stale |
| 9702 | // neighbour palette state the same way [`Neighbours::record`] always | 9818 | // neighbour palette state the same way [`Neighbours::record`] always |
| @@ -11103,8 +11219,14 @@ fn read_tx_size( | |||
| 11103 | // key-frame path's own deblock-grid approximation. | 11219 | // key-frame path's own deblock-grid approximation. |
| 11104 | ctx_override: Option<usize>, | 11220 | ctx_override: Option<usize>, |
| 11105 | ) -> usize { | 11221 | ) -> usize { |
| 11106 | - let ctx = ctx_override.unwrap_or_else(|| tx_size_context(n, at_mi, side)); | 11222 | + // `max_txsize_rect_lookup[bsize]` (libaom `read_selected_tx_size` / |
| 11107 | - let depth = match side { | 11223 | + // `get_tx_size_context`): a block wider than 64 still tops out at |
| 11224 | + // TX_64X64, so BLOCK_128X128 reads BLOCK_64X64's own category (its depth | ||
| 11225 | + // chain 64->32->16->8->4 is the same four steps) and resolves against 64, | ||
| 11226 | + // never against its own 128 side (lane-sb128b r1). | ||
| 11227 | + let max_tx = side.min(64); | ||
| 11228 | + let ctx = ctx_override.unwrap_or_else(|| tx_size_context(n, at_mi, max_tx)); | ||
| 11229 | + let depth = match max_tx { | ||
| 11108 | 8 => { | 11230 | 8 => { |
| 11109 | dec.symbol(&mut cdfs.tx_size_cat0[ctx]) | 11231 | dec.symbol(&mut cdfs.tx_size_cat0[ctx]) |
| 11110 | } | 11232 | } |
| @@ -11117,7 +11239,7 @@ fn read_tx_size( | |||
| 11117 | 64 => { | 11239 | 64 => { |
| 11118 | dec.symbol(&mut cdfs.tx_size_cat3[ctx]) | 11240 | dec.symbol(&mut cdfs.tx_size_cat3[ctx]) |
| 11119 | } | 11241 | } |
| 11120 | - _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64"), | 11242 | + _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64/128"), |
| 11121 | }; | 11243 | }; |
| 11122 | if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { | 11244 | if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { |
| 11123 | let (rng, _) = dec.debug_state(); | 11245 | let (rng, _) = dec.debug_state(); |
| @@ -11129,7 +11251,7 @@ fn read_tx_size( | |||
| 11129 | if depth != 0 { | 11251 | if depth != 0 { |
| 11130 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); | 11252 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); |
| 11131 | } | 11253 | } |
| 11132 | - side >> depth | 11254 | + max_tx >> depth |
| 11133 | } | 11255 | } |
| 11134 | 11256 | ||
| 11135 | /// `txfm_partition_context` (libaom `av1_common_int.h`): an inter block's | 11257 | /// `txfm_partition_context` (libaom `av1_common_int.h`): an inter block's |
| @@ -12736,6 +12858,29 @@ fn sb_visit_order(r0: u32, r1: u32, c0: u32, c1: u32, sb128: bool) -> Vec<(u32, | |||
| 12736 | /// decides the root -- only SPLIT recurses into the four 64x64 quadrants this | 12858 | /// decides the root -- only SPLIT recurses into the four 64x64 quadrants this |
| 12737 | /// decoder codes, the other seven arms refuse by name. | 12859 | /// decoder codes, the other seven arms refuse by name. |
| 12738 | #[allow(clippy::too_many_arguments)] | 12860 | #[allow(clippy::too_many_arguments)] |
| 12861 | +thread_local! { | ||
| 12862 | + /// How many 128x128 superblock roots resolved to `PARTITION_NONE` -- one | ||
| 12863 | + /// whole 128x128 block (lane-sb128b r1's gate counter). | ||
| 12864 | + pub(crate) static PART128_NONE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 12865 | +} | ||
| 12866 | + | ||
| 12867 | +/// [`PART128_NONE_HITS`], for a gate's own before/after delta. | ||
| 12868 | +pub(crate) fn part128_none_hits() -> usize { | ||
| 12869 | + PART128_NONE_HITS.with(std::cell::Cell::get) | ||
| 12870 | +} | ||
| 12871 | + | ||
| 12872 | +thread_local! { | ||
| 12873 | + /// How many CHROMA transform units were coded inside a block whose uv | ||
| 12874 | + /// plane block is more than one unit (lane-sb128b r2 -- only a 128x128 | ||
| 12875 | + /// block, four per plane). | ||
| 12876 | + pub(crate) static CHROMA_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 12877 | +} | ||
| 12878 | + | ||
| 12879 | +/// [`CHROMA_SPLIT_TX_HITS`], for a gate's own before/after delta. | ||
| 12880 | +pub(crate) fn chroma_split_tx_hits() -> usize { | ||
| 12881 | + CHROMA_SPLIT_TX_HITS.with(std::cell::Cell::get) | ||
| 12882 | +} | ||
| 12883 | + | ||
| 12739 | fn read_sb128_root( | 12884 | fn read_sb128_root( |
| 12740 | dec: &mut SymbolDecoder, | 12885 | dec: &mut SymbolDecoder, |
| 12741 | cdfs: &mut Cdfs, | 12886 | cdfs: &mut Cdfs, |
| @@ -12750,7 +12895,7 @@ fn read_sb128_root( | |||
| 12750 | sb_c: u32, | 12895 | sb_c: u32, |
| 12751 | mi_cols: u32, | 12896 | mi_cols: u32, |
| 12752 | mi_rows: u32, | 12897 | mi_rows: u32, |
| 12753 | -) -> Result<()> { | 12898 | +) -> Result<usize> { |
| 12754 | let (mi_r128, mi_c128) = ((sb_r & !1) * SB_MI, (sb_c & !1) * SB_MI); | 12899 | let (mi_r128, mi_c128) = ((sb_r & !1) * SB_MI, (sb_c & !1) * SB_MI); |
| 12755 | crate::restoration::read_lr( | 12900 | crate::restoration::read_lr( |
| 12756 | dec, | 12901 | dec, |
| @@ -12801,13 +12946,20 @@ fn read_sb128_root( | |||
| 12801 | } | 12946 | } |
| 12802 | } | 12947 | } |
| 12803 | }; | 12948 | }; |
| 12804 | - if part128 != PARTITION_SPLIT { | 12949 | + // lane-sb128b r1: `PARTITION_NONE` -- one 128x128 block -- is decoded by |
| 12950 | + // the key-frame caller below. The six remaining arms (HORZ/VERT and the | ||
| 12951 | + // four AB shapes) still need the rect/AB machinery at this size. | ||
| 12952 | + if part128 != PARTITION_SPLIT && part128 != PARTITION_NONE { | ||
| 12805 | return Err(unsupported( | 12953 | return Err(unsupported( |
| 12806 | - "a 128x128 superblock partition other than SPLIT (NONE/HORZ/VERT and the four AB arms at the 128 root are not decoded)", | 12954 | + "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)", |
| 12807 | )); | 12955 | )); |
| 12808 | } | 12956 | } |
| 12809 | - PART128_SPLIT_HITS.with(|c| c.set(c.get() + 1)); | 12957 | + if part128 == PARTITION_SPLIT { |
| 12810 | - Ok(()) | 12958 | + PART128_SPLIT_HITS.with(|c| c.set(c.get() + 1)); |
| 12959 | + } else { | ||
| 12960 | + PART128_NONE_HITS.with(|c| c.set(c.get() + 1)); | ||
| 12961 | + } | ||
| 12962 | + Ok(part128) | ||
| 12811 | } | 12963 | } |
| 12812 | 12964 | ||
| 12813 | pub(crate) fn decode_key_frame_tile_with_cdfs( | 12965 | pub(crate) fn decode_key_frame_tile_with_cdfs( |
| @@ -12985,10 +13137,20 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 12985 | ); | 13137 | ); |
| 12986 | TILE_HITS.with(|c| c.set(c.get() + 1)); | 13138 | TILE_HITS.with(|c| c.set(c.get() + 1)); |
| 12987 | 13139 | ||
| 13140 | + // lane-sb128b r1: set when the 128 root resolved to `PARTITION_NONE` -- | ||
| 13141 | + // its one block covers all four 64x64 quadrants, so the remaining three | ||
| 13142 | + // visits of this superblock code nothing at all. | ||
| 13143 | + let mut sb128_none = false; | ||
| 12988 | for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) { | 13144 | for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) { |
| 12989 | if row_start { | 13145 | if row_start { |
| 12990 | neighbours.start_row(); | 13146 | neighbours.start_row(); |
| 12991 | } | 13147 | } |
| 13148 | + if sb_start { | ||
| 13149 | + sb128_none = false; | ||
| 13150 | + } | ||
| 13151 | + if sb128_none { | ||
| 13152 | + continue; | ||
| 13153 | + } | ||
| 12992 | { | 13154 | { |
| 12993 | // lane-sb128 r1: the 128 root. Its loop-restoration units are read | 13155 | // lane-sb128 r1: the 128 root. Its loop-restoration units are read |
| 12994 | // once for the whole 128x128 (spec 5.11.57 is called with the | 13156 | // once for the whole 128x128 (spec 5.11.57 is called with the |
| @@ -12996,7 +13158,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 12996 | // `BLOCK_128X128` CDF (8 symbols) decides the root -- only SPLIT | 13158 | // `BLOCK_128X128` CDF (8 symbols) decides the root -- only SPLIT |
| 12997 | // recurses into the four 64x64 quadrants this decoder codes. | 13159 | // recurses into the four 64x64 quadrants this decoder codes. |
| 12998 | if sb128 && sb_start { | 13160 | if sb128 && sb_start { |
| 12999 | - read_sb128_root( | 13161 | + let part128 = read_sb128_root( |
| 13000 | &mut dec, | 13162 | &mut dec, |
| 13001 | &mut cdfs, | 13163 | &mut cdfs, |
| 13002 | &neighbours, | 13164 | &neighbours, |
| @@ -13008,6 +13170,62 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 13008 | mi_cols, | 13170 | mi_cols, |
| 13009 | mi_rows, | 13171 | mi_rows, |
| 13010 | )?; | 13172 | )?; |
| 13173 | + if part128 == PARTITION_NONE { | ||
| 13174 | + // One 128x128 intra block: four TX_64X64 luma units and a | ||
| 13175 | + // single 64x64 chroma unit per plane (`av1_get_max_uv_txsize` | ||
| 13176 | + // of a 128x128 block is TX_64X64 over its 64x64 uv plane | ||
| 13177 | + // block). No CfL, no filter intra, no palette at this size -- | ||
| 13178 | + // [`read_intra_mode`]'s own size gates already say so. | ||
| 13179 | + sb128_none = true; | ||
| 13180 | + CDEF_TRANSMITTED.with(|c| c.set(false)); | ||
| 13181 | + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); | ||
| 13182 | + decode_block( | ||
| 13183 | + &mut dec, | ||
| 13184 | + &mut cdfs, | ||
| 13185 | + &mut neighbours, | ||
| 13186 | + at128, | ||
| 13187 | + SB * 2, | ||
| 13188 | + TxbSet::Luma64, | ||
| 13189 | + TxbSet::Chroma32, | ||
| 13190 | + TX32, | ||
| 13191 | + TX32, | ||
| 13192 | + (&scan32, &scan32), | ||
| 13193 | + false, | ||
| 13194 | + &mut y, | ||
| 13195 | + &mut u, | ||
| 13196 | + &mut v, | ||
| 13197 | + base_q_idx, | ||
| 13198 | + enable_filter_intra, | ||
| 13199 | + allow_screen_content_tools, | ||
| 13200 | + allow_intrabc, | ||
| 13201 | + &scan32, | ||
| 13202 | + &scan16, | ||
| 13203 | + &scan8, | ||
| 13204 | + &scan4, | ||
| 13205 | + tx_select, | ||
| 13206 | + reduced_tx_set, | ||
| 13207 | + )?; | ||
| 13208 | + // libaom writes one `cdef_strength` into the block's own | ||
| 13209 | + // `MB_MODE_INFO`, which every mi cell of the block -- | ||
| 13210 | + // hence all four 64x64 CDEF units -- points at; our grid | ||
| 13211 | + // is per-unit, so the read (which only ever lands in the | ||
| 13212 | + // top-left unit, `read_cdef`'s index 0) is copied across. | ||
| 13213 | + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); | ||
| 13214 | + CDEF_IDX_GRID.with(|g| { | ||
| 13215 | + let mut g = g.borrow_mut(); | ||
| 13216 | + let cols = CDEF_SB_COLS.with(|c| c.get()); | ||
| 13217 | + if cols > 0 && q_r * cols + q_c < g.len() { | ||
| 13218 | + let idx = g[q_r * cols + q_c]; | ||
| 13219 | + for (dr, dc) in [(0, 1), (1, 0), (1, 1)] { | ||
| 13220 | + let i = (q_r + dr) * cols + q_c + dc; | ||
| 13221 | + if q_c + dc < cols && i < g.len() { | ||
| 13222 | + g[i] = idx; | ||
| 13223 | + } | ||
| 13224 | + } | ||
| 13225 | + } | ||
| 13226 | + }); | ||
| 13227 | + continue; | ||
| 13228 | + } | ||
| 13011 | } | 13229 | } |
| 13012 | if !sb128 { | 13230 | if !sb128 { |
| 13013 | crate::restoration::read_lr( | 13231 | crate::restoration::read_lr( |
| @@ -20604,7 +20822,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 20604 | } | 20822 | } |
| 20605 | { | 20823 | { |
| 20606 | if sb128 && sb_start { | 20824 | if sb128 && sb_start { |
| 20607 | - read_sb128_root( | 20825 | + if read_sb128_root( |
| 20608 | &mut dec, | 20826 | &mut dec, |
| 20609 | &mut cdfs, | 20827 | &mut cdfs, |
| 20610 | &neighbours, | 20828 | &neighbours, |
| @@ -20615,7 +20833,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 20615 | sb_c, | 20833 | sb_c, |
| 20616 | mi_cols, | 20834 | mi_cols, |
| 20617 | mi_rows, | 20835 | mi_rows, |
| 20618 | - )?; | 20836 | + )? != PARTITION_SPLIT |
| 20837 | + { | ||
| 20838 | + // lane-sb128b r1 decodes a `PARTITION_NONE` 128 root on | ||
| 20839 | + // KEY frames only; an inter 128x128 leaf needs whole-block | ||
| 20840 | + // MC, OBMC and compound at a size this path has never run. | ||
| 20841 | + return Err(unsupported( | ||
| 20842 | + "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)", | ||
| 20843 | + )); | ||
| 20844 | + } | ||
| 20619 | } | 20845 | } |
| 20620 | if !sb128 { | 20846 | if !sb128 { |
| 20621 | crate::restoration::read_lr( | 20847 | crate::restoration::read_lr( |
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
| @@ -42,7 +42,8 @@ const REFUSALS: &[&str] = &[ | |||
| 42 | "a tx_type symbol outside its CDF's own set: {t}", | 42 | "a tx_type symbol outside its CDF's own set: {t}", |
| 43 | "an INTER 32x32 partition type this decoder does not code (value={part32})", | 43 | "an INTER 32x32 partition type this decoder does not code (value={part32})", |
| 44 | "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", | 44 | "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", |
| 45 | - "a 128x128 superblock partition other than SPLIT (NONE/HORZ/VERT and the four AB arms at the 128 root are not decoded)", | 45 | + "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)", |
| 46 | + "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)", | ||
| 46 | "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", | 47 | "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", |
| 47 | "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)", | 48 | "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)", |
| 48 | "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", | 49 | "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", |
crates/ec-av1/src/stream.rsmodified+156 -0
| @@ -18001,6 +18001,162 @@ mod tests { | |||
| 18001 | ); | 18001 | ); |
| 18002 | } | 18002 | } |
| 18003 | 18003 | ||
| 18004 | + /// lane-sb128b r1 gate: a real `aomenc --sb-size=128` KEY frame whose 128 | ||
| 18005 | + /// roots resolve to `PARTITION_NONE` -- one whole 128x128 intra block, | ||
| 18006 | + /// four TX_64X64 luma transform units and FOUR TX_32X32 chroma units per | ||
| 18007 | + /// plane (`av1_get_max_uv_txsize(BLOCK_128X128)` is | ||
| 18008 | + /// `av1_get_adjusted_tx_size` of its 64x64 uv plane block's TX_64X64, so | ||
| 18009 | + /// TX_32X32) -- lane-sb128b r2's `chroma_split_tx_hits` asserts them. The r1 gate above pins `--max-partition-size=64`, which | ||
| 18010 | + /// makes every 128 root a forced SPLIT and leaves this arm unexercised. | ||
| 18011 | + /// Smooth gradients at a high `--cq-level` are what make the RD search | ||
| 18012 | + /// keep a whole 128x128 block; `part128_none_hits` HARD-asserts it did. | ||
| 18013 | + #[test] | ||
| 18014 | + fn a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact() { | ||
| 18015 | + const NAME: &str = | ||
| 18016 | + "a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact"; | ||
| 18017 | + let _gate_lock = lock_gate_counters(); | ||
| 18018 | + if !have_ffmpeg() { | ||
| 18019 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 18020 | + return; | ||
| 18021 | + } | ||
| 18022 | + if !have_aomenc() { | ||
| 18023 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 18024 | + return; | ||
| 18025 | + } | ||
| 18026 | + let render = |seed: u32, width: usize, height: usize, ten_bit: bool| -> Vec<u8> { | ||
| 18027 | + let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; | ||
| 18028 | + let out = Command::new("ffmpeg") | ||
| 18029 | + .args([ | ||
| 18030 | + "-v", "error", "-f", "lavfi", "-i", | ||
| 18031 | + &gradients_source(seed, width, height, "duration=0.04:rate=25"), | ||
| 18032 | + "-pix_fmt", pix, "-strict", "-1", "-t", "0.04", | ||
| 18033 | + "-f", "yuv4mpegpipe", "-", | ||
| 18034 | + ]) | ||
| 18035 | + .stdin(Stdio::null()) | ||
| 18036 | + .stdout(Stdio::piped()) | ||
| 18037 | + .stderr(Stdio::piped()) | ||
| 18038 | + .output() | ||
| 18039 | + .expect("ffmpeg failed to run"); | ||
| 18040 | + assert!( | ||
| 18041 | + out.status.success(), | ||
| 18042 | + "ffmpeg fixture: {}", | ||
| 18043 | + String::from_utf8_lossy(&out.stderr) | ||
| 18044 | + ); | ||
| 18045 | + out.stdout | ||
| 18046 | + }; | ||
| 18047 | + let mut matched = 0u32; | ||
| 18048 | + let mut named_refusals = 0u32; | ||
| 18049 | + let mut none_arms = 0u32; | ||
| 18050 | + // (seed, cq, width, height, 10-bit). 384x384 is a 3x3 grid of whole | ||
| 18051 | + // 128 superblocks; 256x256 a 2x2. | ||
| 18052 | + let arms: Vec<(u32, &str, usize, usize, bool)> = vec![ | ||
| 18053 | + (42, "--cq-level=63", 384, 384, false), | ||
| 18054 | + (43, "--cq-level=55", 384, 384, false), | ||
| 18055 | + (44, "--cq-level=63", 256, 256, false), | ||
| 18056 | + (45, "--cq-level=63", 384, 384, true), | ||
| 18057 | + ]; | ||
| 18058 | + for (seed, cq, width, height, ten_bit) in arms { | ||
| 18059 | + let y4m = render(seed, width, height, ten_bit); | ||
| 18060 | + let mut args: Vec<&str> = vec![ | ||
| 18061 | + "--codec=av1", "--passes=1", "--end-usage=q", cq, | ||
| 18062 | + "--cpu-used=0", "--threads=1", "--row-mt=0", | ||
| 18063 | + "--sb-size=128", | ||
| 18064 | + "--enable-rect-partitions=0", | ||
| 18065 | + "--enable-ab-partitions=0", | ||
| 18066 | + "--enable-1to4-partitions=0", | ||
| 18067 | + "--min-partition-size=16", | ||
| 18068 | + "--enable-restoration=1", | ||
| 18069 | + "--enable-palette=0", | ||
| 18070 | + "--deltaq-mode=0", | ||
| 18071 | + "--enable-intrabc=0", | ||
| 18072 | + "--enable-tx-size-search=0", | ||
| 18073 | + "--limit=1", | ||
| 18074 | + ]; | ||
| 18075 | + if ten_bit { | ||
| 18076 | + args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); | ||
| 18077 | + } | ||
| 18078 | + args.extend_from_slice(&["--obu", "-o", "-", "-"]); | ||
| 18079 | + let mut child = Command::new(aomenc_path()) | ||
| 18080 | + .args(&args) | ||
| 18081 | + .stdin(Stdio::piped()) | ||
| 18082 | + .stdout(Stdio::piped()) | ||
| 18083 | + .stderr(Stdio::piped()) | ||
| 18084 | + .spawn() | ||
| 18085 | + .expect("aomenc failed to start"); | ||
| 18086 | + child | ||
| 18087 | + .stdin | ||
| 18088 | + .take() | ||
| 18089 | + .expect("aomenc stdin") | ||
| 18090 | + .write_all(&y4m) | ||
| 18091 | + .expect("writing y4m to aomenc"); | ||
| 18092 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 18093 | + assert!( | ||
| 18094 | + out.status.success(), | ||
| 18095 | + "aomenc refused the fixture: {}", | ||
| 18096 | + String::from_utf8_lossy(&out.stderr) | ||
| 18097 | + ); | ||
| 18098 | + let stream = out.stdout; | ||
| 18099 | + let before = crate::decode::part128_none_hits(); | ||
| 18100 | + let frames = match decode_stream(&stream) { | ||
| 18101 | + Err(e) => { | ||
| 18102 | + let msg = e.to_string(); | ||
| 18103 | + assert!( | ||
| 18104 | + msg.contains("unsupported"), | ||
| 18105 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | ||
| 18106 | + ); | ||
| 18107 | + named_refusals += 1; | ||
| 18108 | + eprintln!("seed {seed} refusal: {msg}"); | ||
| 18109 | + continue; | ||
| 18110 | + } | ||
| 18111 | + Ok(frames) => frames, | ||
| 18112 | + }; | ||
| 18113 | + let want = if ten_bit { | ||
| 18114 | + ffmpeg_decode_sequence_10bit(&stream, width, height, 1) | ||
| 18115 | + } else { | ||
| 18116 | + ffmpeg_decode_sequence(&stream, width, height, 1) | ||
| 18117 | + }; | ||
| 18118 | + assert_eq!(frames.len(), 1); | ||
| 18119 | + for (i, (got, want)) in frames.iter().zip(&want).enumerate() { | ||
| 18120 | + for (name, a, b, w) in [ | ||
| 18121 | + ("Y", &got.y, &want.y, width), | ||
| 18122 | + ("U", &got.u, &want.u, width / 2), | ||
| 18123 | + ("V", &got.v, &want.v, width / 2), | ||
| 18124 | + ] { | ||
| 18125 | + let n = a.iter().zip(b.iter()).filter(|(x, y)| x != y).count(); | ||
| 18126 | + let first = a.iter().zip(b.iter()).position(|(x, y)| x != y); | ||
| 18127 | + assert_eq!( | ||
| 18128 | + n, 0, | ||
| 18129 | + "{NAME} frame {i} {name} vs ffmpeg (seed {seed}): {n} differ, first row {} col {} ours {:?} ffmpeg {:?}", | ||
| 18130 | + first.unwrap_or(0) / w, | ||
| 18131 | + first.unwrap_or(0) % w, | ||
| 18132 | + first.map(|k| a[k]), | ||
| 18133 | + first.map(|k| b[k]), | ||
| 18134 | + ); | ||
| 18135 | + } | ||
| 18136 | + } | ||
| 18137 | + let hits = crate::decode::part128_none_hits() - before; | ||
| 18138 | + eprintln!("seed {seed} cq {cq} {width}x{height}: part128_none_hits +{hits}"); | ||
| 18139 | + if hits > 0 { | ||
| 18140 | + none_arms += 1; | ||
| 18141 | + } | ||
| 18142 | + matched += 1; | ||
| 18143 | + } | ||
| 18144 | + assert!( | ||
| 18145 | + matched > 0, | ||
| 18146 | + "{NAME}: every attempt refused; the gate never decoded a stream" | ||
| 18147 | + ); | ||
| 18148 | + assert!( | ||
| 18149 | + none_arms > 0, | ||
| 18150 | + "{NAME}: {matched} stream(s) decoded pixel-exact but NOT ONE 128 root was \ | ||
| 18151 | + PARTITION_NONE -- the arm this gate exists for never fired" | ||
| 18152 | + ); | ||
| 18153 | + eprintln!( | ||
| 18154 | + "{NAME}: {matched} pixel-exact ({none_arms} with a 128 NONE root), \ | ||
| 18155 | + {named_refusals} named refusals, part128_none_hits={}", | ||
| 18156 | + crate::decode::part128_none_hits() | ||
| 18157 | + ); | ||
| 18158 | + } | ||
| 18159 | + | ||
| 18004 | #[test] | 18160 | #[test] |
| 18005 | #[ignore = "lane-sb128 r2 diagnostic: is the frame-6 mismatch sb128-specific?"] | 18161 | #[ignore = "lane-sb128 r2 diagnostic: is the frame-6 mismatch sb128-specific?"] |
| 18006 | fn sb128_r2_control_sb64() { | 18162 | fn sb128_r2_control_sb64() { |
lanes/sb128b-r1.report.mdadded+103 -0
| @@ -0,0 +1,103 @@ | |||
| 1 | +# lane-sb128b r1 — the 128 root's `PARTITION_NONE` arm (key frames) | ||
| 2 | + | ||
| 3 | +Branch `lane-sb128b` off `lane-sb128` 807c110, worktree `edith_codecs-sb128b`, commit `ceec9fa`. | ||
| 4 | + | ||
| 5 | +## ReelC first — the charter's premise is FALSE on ReelC's key frame | ||
| 6 | + | ||
| 7 | +EVIDENCE: `$HOME/.cache/sb128b-work/reelc2s.obu` (fresh cut, `ffmpeg -t 2 -c:v copy -f obu` | ||
| 8 | +off the real film, 1428 bytes) | release `decode_probe` under a 6G scope with `EC_AV1_TRACE=1` | ||
| 9 | +| **90 `partition_w128` symbols, value=3 (`PARTITION_SPLIT`) on every one** (ctx 3 x70, ctx 2 | ||
| 10 | +x14, ctx 1 x5, ctx 0 x1); the run then stops at `an inter frame under a 128x128 superblock`. | ||
| 11 | +Same numbers on the pre-existing `reelc-head.obu`. | ||
| 12 | + | ||
| 13 | +So ReelC's KEY frame is 100% SPLIT at the 128 root — the key-frame 128 arms are **not** its | ||
| 14 | +blocker, and TASK 4's "the inter arms" is where ReelC's non-SPLIT roots live (r2 saw them only | ||
| 15 | +with the inter refusal locally lifted). Charter premise "ReelC's key frame is the first thing to | ||
| 16 | +decode / stops at a TASK-B arm" corrected here, measured, not argued. | ||
| 17 | + | ||
| 18 | +## What landed (all against libaom, each cited) | ||
| 19 | + | ||
| 20 | +`crates/ec-av1/src/decode.rs` | ||
| 21 | +- `read_sb128_root` (11286) returns the root partition; the key-frame loop (11536) decodes | ||
| 22 | + `PARTITION_NONE` as one 128x128 block and skips the superblock's other three visits | ||
| 23 | + (`sb128_none`). The inter loop refuses any non-SPLIT root by name. | ||
| 24 | +- `read_tx_size` (10003): `max_txsize_rect_lookup[BLOCK_128X128]` is TX_64X64 → a 128 block | ||
| 25 | + reads BLOCK_64X64's own `tx_size_cat3` and resolves `max_tx >> depth`, and | ||
| 26 | + `get_tx_size_context` is asked about 64, not 128. | ||
| 27 | +- `decode_block`: the single-TU arm was `!tx_select || logical_tx == side`. Without `tx_select` | ||
| 28 | + `logical_tx` IS `side` at every size <= 64, so the first half was redundant — and wrong at | ||
| 29 | + 128. Now `logical_tx == side`, and the non-select resolve is `(side.min(64), luma_tx)`, so a | ||
| 30 | + 128 block is always four TX_64X64 units. The TU loop passes the unit's **coefficient** side | ||
| 31 | + (32 at TX_64X64), not its transform side. | ||
| 32 | +- `delta_q`/`delta_lf` "this leaf IS the superblock" is now `side == sb_size` (was a hardcoded | ||
| 33 | + 64 plus a `!sb128()` disable) — a NONE 128 root is the whole superblock. | ||
| 34 | +- the 128 block's one `cdef_idx` read is copied to all four 64x64 CDEF units (libaom's four | ||
| 35 | + units share one `MB_MODE_INFO`). | ||
| 36 | + | ||
| 37 | +`crates/ec-av1/src/stream.rs`: new gate (below). `refusal_inventory.rs`: the single | ||
| 38 | +"partition other than SPLIT" string splits into three named arms. | ||
| 39 | + | ||
| 40 | +## Gate | ||
| 41 | + | ||
| 42 | +`a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact` — real aomenc | ||
| 43 | +`--sb-size=128` with **no** `--max-partition-size` (the r1 gate's flag is exactly what made | ||
| 44 | +every 128 root a forced SPLIT), smooth gradients at `--cq-level=63/55`, 384x384 + 256x256, | ||
| 45 | +8- and 10-bit, `--enable-tx-size-search=0`. `#[ignore]`d: it is a reproducer, not a pass. | ||
| 46 | + | ||
| 47 | +EVIDENCE: `cargo test -p ec-av1 --lib -- --nocapture a_real_aomenc_key_frame_with_a_128x128_none` | ||
| 48 | +| aomenc 384x384 cq63 seed 42, decoded then compared to ffmpeg | the NONE arm **fires** and the | ||
| 49 | +tile decodes end to end (no desync panic, no refusal), but frame 0 luma differs from ffmpeg at | ||
| 50 | +138523 of 147456 samples, first at row 0 col 60, magnitudes 1..3 (ours 114/113 where ffmpeg has | ||
| 51 | +115) — a reconstruction difference, not an entropy blow-up. | ||
| 52 | + | ||
| 53 | +Two earlier failures on the way, both fixed and both real defects of the generalisation: | ||
| 54 | +`transform.rs:843 index out of bounds (len 64, index 64)` = the redundant `!tx_select` arm | ||
| 55 | +above sending a 128-wide inverse transform; then the pixel deltas. | ||
| 56 | + | ||
| 57 | +## Root cause of the residual (found, not guessed) | ||
| 58 | + | ||
| 59 | +`av1_get_max_uv_txsize` = `av1_get_adjusted_tx_size(max_txsize_rect_lookup[uv_plane_bsize])`. | ||
| 60 | +The uv plane block of a 128x128 is 64x64 → TX_64X64 → **adjusted to TX_32X32**. A 128 block's | ||
| 61 | +chroma is therefore FOUR TX_32X32 units per plane, and `decode_block` codes exactly one | ||
| 62 | +whole-plane chroma unit. That is the desync, and it also means the charter's | ||
| 63 | +"one chroma TU of 64x64 per plane / new chroma TX_64X64 path" is wrong: **no `TxbSet::Chroma64` | ||
| 64 | +is needed at all.** I had transcribed the 16 libaom `[TX_64X64][PLANE_TYPE_UV]` CDF tables and | ||
| 65 | +wired the variant before finding this; that work is reverted (`cdf.rs`/`cdf_state.rs` are | ||
| 66 | +untouched in this commit) rather than shipped as dead code. | ||
| 67 | + | ||
| 68 | +## Refusals | ||
| 69 | + | ||
| 70 | +- `a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 | ||
| 71 | + root)` — NOT lifted, TASKs 2/3, not started. | ||
| 72 | +- `a 128x128 superblock PARTITION_NONE root on an inter frame (...)` — NOT lifted, TASK 4. | ||
| 73 | +- `a 128x128 PARTITION_NONE block's chroma (its 64x64 uv plane block is four TX_32X32 units, | ||
| 74 | + and this decoder codes one whole-plane chroma unit per block)` — NEW, guards the arm this | ||
| 75 | + round built. fix-now(r2): give `decode_block` a chroma TU loop (2x2 TX_32X32, `TxbSet::Chroma32`, | ||
| 76 | + per-unit `chroma_skip_ctx`, grids assembled for `record_split_luma`) — unblocked by that loop; | ||
| 77 | + the gate above is the reproducer and flips green the moment it is right. | ||
| 78 | +- `intrabc under a 128x128 superblock` — accepted, unchanged. | ||
| 79 | + | ||
| 80 | +## Suite | ||
| 81 | + | ||
| 82 | +`cargo test -p ec-av1 --lib` under user unit `sb128b-suite-1788322151.service`, | ||
| 83 | +log `$HOME/.cache/sb128b-suite.log` — result appended below by the handoff line in the report | ||
| 84 | +message. The 7 rect/AB reds inherited from 807c110 (r2's `deferred: attribute the 7`) are the | ||
| 85 | +sibling lane's; this round touched no rect/AB path. | ||
| 86 | + | ||
| 87 | +## Deferred | ||
| 88 | + | ||
| 89 | +- deferred: TASK 2/3 (HORZ/VERT + AB at 128) — not started — unblocked by the chroma TU loop | ||
| 90 | + plus rect handling at 128. | ||
| 91 | +- deferred: TASK 4 (inter 128 NONE) — refused by name — unblocked by the same loop and the | ||
| 92 | + sibling lane's inter residue. | ||
| 93 | +- deferred: `tx_select` at 128 (`read_tx_size` now handles it, cat3 against 64) is UNTESTED — | ||
| 94 | + every gate arm here runs `--enable-tx-size-search=0` — unblocked by an r2 arm with it on. | ||
| 95 | + | ||
| 96 | +## Suite state at hand-off (honest, incomplete) | ||
| 97 | + | ||
| 98 | +`sb128b-suite-1788322151.service` was STILL RUNNING when this round hit its tool-call ceiling. | ||
| 99 | +At that point the log showed **2 failures, both inherited from 807c110's rect/AB cluster**: | ||
| 100 | +`a_real_aomenc_10bit_rect_and_ab_partitions_decode_pixel_exact`, | ||
| 101 | +`a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_decodes_pixel_exact`. | ||
| 102 | +No total ("test result:" line) yet — read `$HOME/.cache/sb128b-suite.log` for the final count | ||
| 103 | +before merging. NOT a clean-suite claim. | ||
lanes/sb128b-r2.report.mdadded+97 -0
| @@ -0,0 +1,97 @@ | |||
| 1 | +# lane-sb128b r2 — ReelC's key frame is BIT-EXACT; the 128 chroma TU loop; the 128 root's residual | ||
| 2 | + | ||
| 3 | +Branch `lane-sb128b`, worktree `edith_codecs-sb128b`, commits `4e13f60`, `1524838`, `c415a31` | ||
| 4 | +(off r1's `d3bc8da` + `git merge main` b51719f, clean). | ||
| 5 | + | ||
| 6 | +## FIRST: the ReelC KEY-frame pixel check (the charter's first task — first ReelC pixel measurement ever) | ||
| 7 | + | ||
| 8 | +EVIDENCE: `$HOME/.cache/sb128b-work/{reelckf0.obu,ours.f0.yuv,ref.yuv}` | | ||
| 9 | +`ffmpeg -ss 0 -t 2 -c:v copy -frames:v 1 -f obu` off the real film (74 B, 1920x792 yuv420p10le) | ||
| 10 | +→ `dump_yuv` (release, 6G scope) vs `ffmpeg -pix_fmt yuv420p10le -f rawvideo` | | ||
| 11 | +**`cmp` says BYTES EQUAL — ReelC's key frame decodes BIT-EXACT (4 561 920 bytes, 0 differing samples).** | ||
| 12 | + | ||
| 13 | +It was NOT exact before the merge. Pre-merge measurement (same artifacts, r1's tree): | ||
| 14 | +Y 36448 samples off (max |d| 2), U/V 9483 each (max |d| 4), all inside the bottom partial | ||
| 15 | +superblock row — luma rows 765..791 (768 = 6*128, frame is 792 tall) plus 3 deblock rows above, | ||
| 16 | +`+1` per 16-row band, ref uniformly flat (this key frame is black). `git merge main` (lane-oddh's | ||
| 17 | +odd-frame-size work) removes it entirely. Class: [[stale-premise lanes]] — the lane's base | ||
| 18 | +predates the fix. | ||
| 19 | + | ||
| 20 | +ReelC now stops at `an inter frame under a 128x128 superblock` (probe on the 2 s cut, 72 frame | ||
| 21 | +headers parsed) — the sibling lane-sb128 r3's residue, exactly as r1 predicted. | ||
| 22 | + | ||
| 23 | +## Merge seam (had to be fixed before anything could run) | ||
| 24 | + | ||
| 25 | +main b51719f re-introduced lane-oddh's blanket refusal `a sequence using 128x128 superblocks on a | ||
| 26 | +frame larger than 64x64` (stream.rs) — textually a clean merge, semantically a lane-killer (the | ||
| 27 | +ledger's recorded `merge seam` constraint). Deleted, with its inventory line, and its gate | ||
| 28 | +`a_real_aomenc_128x128_superblock_stream_is_refused_by_name` turned into | ||
| 29 | +`..._decodes_pixel_exact`. | ||
| 30 | + | ||
| 31 | +EVIDENCE: `cargo test -p ec-av1 --lib -- a_real_aomenc_128x128_superblock_stream gate_coverage` | | ||
| 32 | +real aomenc 64x72 mandelbrot `--cpu-used=0 --sb-size=128` (`use_128x128_superblock` asserted in | ||
| 33 | +the stream), decoded vs ffmpeg | **ok — 10 passed, 0 failed**; the frame's Y/U/V match ffmpeg | ||
| 34 | +sample for sample. One recipe change was needed and is unrelated to the 128 root: at 64x72 | ||
| 35 | +aomenc also picks `PARTITION_HORZ_4` below 16x16, so the gate now passes | ||
| 36 | +`--enable-1to4-partitions=0 --min-partition-size=16` (gate_coverage green with it). | ||
| 37 | + | ||
| 38 | +## TASK A — the chroma half of a 128x128 `PARTITION_NONE` block (landed, not yet exact) | ||
| 39 | + | ||
| 40 | +`crates/ec-av1/src/decode.rs` | ||
| 41 | +- `decode_block`'s multi-TU arm now codes `cn = chroma_side / chroma_tx` **squared** chroma units | ||
| 42 | + per plane instead of one whole-plane unit. `av1_get_max_uv_txsize(BLOCK_128X128)` = | ||
| 43 | + `av1_get_adjusted_tx_size(max_txsize_rect_lookup[BLOCK_64X64])` = TX_32X32, so a 128 block is | ||
| 44 | + 2x2 TX_32X32 per plane; `cn == 1` (every block at 64 and below) is byte-for-byte the read this | ||
| 45 | + always did. Per unit: `around_mi` gathered over the unit's own 64-luma-pixel span (which is | ||
| 46 | + also its `txb_skip_ctx`, `read_plane`'s chroma branch), `tu_reach` on the matching luma | ||
| 47 | + quadrant, own `set_palette_pred`. | ||
| 48 | +- `Neighbours::record_mi_chroma` (new, next to `record_mi_luma`): per-unit chroma coefficient | ||
| 49 | + context, luma-mi indexed with `record_split_luma_rect_mi`'s own frame-edge clamp. Applied | ||
| 50 | + AFTER `record_split_luma` so the per-unit state is what the next block reads. | ||
| 51 | +- The `skip` arm predicts per transform unit now (libaom predicts inside the transform-block | ||
| 52 | + loop); `n_axis == 1` / `cn == 1` is the unchanged whole-block call. | ||
| 53 | +- counter `chroma_split_tx_hits()`. | ||
| 54 | + | ||
| 55 | +**Result: not pixel-exact, so the refusal is BACK, reworded to what was measured.** | ||
| 56 | +EVIDENCE: `$HOME/.cache/sb128b-work/g42.obu` (the gate's own arm reproduced by hand: gradients | ||
| 57 | +seed 42, 384x384, cq63, `--sb-size=128 --cpu-used=0 --enable-tx-size-search=0`) | `dump_yuv` vs | ||
| 58 | +`ffmpeg -pix_fmt yuv420p` | 139162/147456 luma samples differ, first at row 0 col 60 (ours 114, | ||
| 59 | +ffmpeg 115). **ffmpeg's row 0 is a CONSTANT 115 across the whole first unit where ours ramps | ||
| 60 | +115 → 112**, and the stream is 76 bytes: the mode and the DC agree, our first TX_64X64 luma unit | ||
| 61 | +reads AC coefficients libaom never wrote. So the divergence is inside that unit's coefficient | ||
| 62 | +read, not in chroma and not in prediction. | ||
| 63 | + | ||
| 64 | +Refusal now reads: `a 128x128 PARTITION_NONE block (four TX_64X64 luma and four TX_32X32 chroma | ||
| 65 | +units all decode, but the first unit's coefficients already carry AC where libaom has DC only -- | ||
| 66 | +lane-sb128b r2's open entropy residual)`. Gate | ||
| 67 | +`a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact` stays `#[ignore]`d as | ||
| 68 | +the reproducer, with its plane asserts rewritten to LOCATE the divergence (count + first | ||
| 69 | +row/col/values) instead of printing 147 456 samples. | ||
| 70 | + | ||
| 71 | +Also corrected in that gate's doc: r1 wrote "ONE TX_64X64 chroma unit per plane / `TxbSet::Chroma64`"; | ||
| 72 | +the truth is four TX_32X32 and no `Chroma64` set exists or is needed. | ||
| 73 | + | ||
| 74 | +## Not done | ||
| 75 | + | ||
| 76 | +- deferred: TASK A's `tx_select` at 128 arm (`--enable-tx-size-search=1`) — not added — unblocked | ||
| 77 | + by the NONE arm being exact at all (an inexact arm cannot gate a tx-depth counter). | ||
| 78 | +- deferred: TASK B (HORZ/VERT + AB at 128) — not started, refused by name | ||
| 79 | + (`a 128x128 superblock HORZ/VERT or AB partition`) — unblocked by the same residual. | ||
| 80 | +- deferred: TASK C (inter 128) — not started, refused by name on both this tree and the sibling's | ||
| 81 | + (`an inter frame under a 128x128 superblock`) — unblocked by lane-sb128 r3 lifting its inter | ||
| 82 | + root refusal; nothing of TASK C was written, so nothing is "ready behind" it. | ||
| 83 | +- `git merge lane-sb128` NOT done: the sibling's tip is `dbf15a4` (gate-recipe fix only, no | ||
| 84 | + inter-128 lift yet), so there was nothing to take. | ||
| 85 | + | ||
| 86 | +## Suite | ||
| 87 | + | ||
| 88 | +r2's first run (`$HOME/.cache/sb128b-suite-r2.log`, unit `sb128b-suite-r2-1788322817.service`) was | ||
| 89 | +armed at the intermediate commit `1524838` and is superseded. Its FAILED list: the 2 rect/AB reds | ||
| 90 | +inherited from 807c110 (`a_real_aomenc_10bit_rect_and_ab_partitions_decode_pixel_exact`, | ||
| 91 | +`a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_decodes_pixel_exact`) — **still red after | ||
| 92 | +`git merge main` b51719f, so main did NOT fix them** — plus the two 128 gates that this round's | ||
| 93 | +final commit resolves (`..._128x128_superblock_stream...` now green, | ||
| 94 | +`..._128x128_none_partition...` now `#[ignore]`d). | ||
| 95 | +The authoritative run for `c415a31` is unit `sb128b-suite-r2b-1788323051.service` → | ||
| 96 | +`$HOME/.cache/sb128b-suite-r2b.log`; it was still running at this round's tool-call ceiling. | ||
| 97 | +NOT a clean-suite claim: read that log for the totals before merging. | ||
lanes/sb128b-r3.report.mdadded+101 -0
| @@ -0,0 +1,101 @@ | |||
| 1 | +# lane-sb128b r3 — the 128x128 PARTITION_NONE block decodes PIXEL-EXACT (3 root causes), the 10-bit reds were a recipe defect | ||
| 2 | + | ||
| 3 | +Branch `lane-sb128b`, worktree `edith_codecs-sb128b`, commits `dd6f934` (merge main 7a47fc1 + TASK B), | ||
| 4 | +`f2b6f1c` (TASK A), `7ceb309` (merge main 18bf7dc / lane-sb128 5ea5ec8). | ||
| 5 | + | ||
| 6 | +## TASK A — the 128 NONE residual: THREE root causes, none of them where r2 pointed | ||
| 7 | + | ||
| 8 | +r2 read "our first TX_64X64 luma unit reads AC coefficients libaom never wrote". Measured with a | ||
| 9 | +range ladder (instrumented `aomdec` `EC_TRACE_COEFF` vs our `EC_TRACE_COEFF`) that premise is | ||
| 10 | +WRONG: the first luma unit is identical symbol for symbol and range for range | ||
| 11 | +(`all_zero ctx=1 rng=59208 / eob=3 rng=41268 / base_eob level=5 rng=44688 / ... / rng=36616`). | ||
| 12 | +The divergence is at the SECOND element of the block, and it is three separate defects: | ||
| 13 | + | ||
| 14 | +1. **Plane order.** libaom's `decode_token_recon_block` loops 64x64 luma "mu" chunks | ||
| 15 | + (`mu_blocks_wide/high = mi_size_wide[BLOCK_64X64]`) and codes EVERY PLANE of a chunk before the | ||
| 16 | + next chunk. The oracle ladder is Y(0,0) U(0,0) V(0,0) Y(0,16) U(0,8) V(0,8) ... — Y,U,V per | ||
| 17 | + quadrant. We read all four luma units and then all chroma units. Below 128 a block is one chunk, | ||
| 18 | + so the fix (`nchunk = side/64`, luma TUs then chroma units per chunk) is byte-for-byte the old | ||
| 19 | + order at every size the decoder already handled. | ||
| 20 | +2. **The chroma `txb_skip_ctx` offset.** `get_txb_ctx`: chroma ctx is | ||
| 21 | + `combine_entropy_contexts(above,left)` **+7** normally, **+10** when the plane block is LARGER | ||
| 22 | + than the transform. A 128 block's 64x64 uv plane block with TX_32X32 units is AV1's only such | ||
| 23 | + case, and our chroma table only ever carried the offset-7 rows (`txb_skip_chroma_*: [[u16;3];3]`). | ||
| 24 | + Oracle read ctx=10, we read ctx=0. Added `TXB_SKIP_CHROMA_32_BIG{,_Q0,_Q1,_Q3}` from | ||
| 25 | + `av1_default_txb_skip_cdfs[q][TX_32X32][10..13]` (token_cdfs.h, all four q contexts, verified by | ||
| 26 | + re-deriving the existing offset-7 rows from the same array), `txb_skip_chroma_32` is six rows, | ||
| 27 | + caller adds 3 when `cn > 1`. | ||
| 28 | +3. **Deferred chroma context writes.** r2 recorded each chroma unit's coefficient context only | ||
| 29 | + after the whole block, so the second quadrant read ctx 10 where the oracle reads 11 (base 1 from | ||
| 30 | + its left neighbour inside the same block). Now recorded per unit inside the loop; the | ||
| 31 | + post-`record_split_luma` replay stays, because that call would otherwise clobber them whole-block. | ||
| 32 | + | ||
| 33 | +Files: `crates/ec-av1/src/decode.rs` (mu-chunk loop + `chroma_ctx_offset` + per-unit record + | ||
| 34 | +`read_plane`'s chroma `skip_ctx`), `crates/ec-av1/src/cdf.rs` (4 tables), | ||
| 35 | +`crates/ec-av1/src/cdf_state.rs` (`txb_skip_chroma_32` 3 -> 6 rows). | ||
| 36 | + | ||
| 37 | +EVIDENCE: `$HOME/.cache/sb128b-work/{s44.obu,ref44.yuv,ours44.yuv.f0.yuv,ref.ladder}` | | ||
| 38 | +aomenc gate-arm-3 recipe (seed 44 gradients 256x256 cq63 `--sb-size=128 --cpu-used=0 | ||
| 39 | +--enable-tx-size-search=0 ...`), `EC_TRACE_COEFF` ladders of aomdec and `dump_yuv`, then | ||
| 40 | +`dump_yuv` vs `ffmpeg -pix_fmt yuv420p` | **48 `txb_skip` symbols, ranges identical one for one; | ||
| 41 | +0 of 98304 samples differ (pixel-exact)**. Before the fix: 60857 luma samples differed. | ||
| 42 | + | ||
| 43 | +REFUSAL LIFTED (with its gate): `a 128x128 PARTITION_NONE block (...)` deleted from `decode.rs` and | ||
| 44 | +`refusal_inventory.rs`; `a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact` | ||
| 45 | +un-`#[ignore]`d. | ||
| 46 | +EVIDENCE: `cargo test -p ec-av1 --lib -- a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact --nocapture` | | ||
| 47 | +4 real-aomenc arms (384x384 seed 42 cq63, 384x384 seed 43 cq55, 256x256 seed 44 cq63, 384x384 seed 45 | ||
| 48 | +10-bit) decoded vs ffmpeg | **ok — 4/4 pixel-exact, 0 named refusals, `part128_none_hits=31`** | ||
| 49 | +(9+9+4+9 128-NONE roots). Sibling gates `a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact`, | ||
| 50 | +`refusal_inventory`, `gate_coverage` re-run green in the same invocation (14 passed / 0 failed). | ||
| 51 | + | ||
| 52 | +## TASK B — the 2 inherited 10-bit reds were an ENCODER RECIPE defect | ||
| 53 | + | ||
| 54 | +`git show main:crates/ec-av1/src/stream.rs` vs the lane's: r2 rewrote `--min-partition-size=16` to | ||
| 55 | +`32` at **13** call sites that main has at 16, including both failing gates. 32 removes the 16-level | ||
| 56 | +the rect/AB gates assert. Reverted all 13 (the lane's own two 128 gates keep their deliberate 32). | ||
| 57 | +EVIDENCE: `cargo test -p ec-av1 --lib -- a_real_aomenc_10bit_rect_and_ab_partitions_decode_pixel_exact a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_decodes_pixel_exact refusal_inventory gate_coverage` | | ||
| 58 | +recipe reverted, rebuilt, re-run | **ok — 14 passed, 0 failed**. Class: | ||
| 59 | +[[gate-recipe-confound]] / the ledger's "a gate that decodes pixel-exact with counter 0 is an | ||
| 60 | +encoder-recipe defect". Swept: those 13 are every 16->32 rewrite in the lane. | ||
| 61 | + | ||
| 62 | +## TASK C — merges | ||
| 63 | + | ||
| 64 | +`git merge main` twice: 7a47fc1 (one conflict, `decode.rs`'s skipped-block arm: took main's | ||
| 65 | +lane-hgkf per-TU prediction + `true_width` guard + `SKIP_SPLIT_TX_HITS`, broadened its condition | ||
| 66 | +from `tx_select && logical_tx < side` to `logical_tx < side` because a 128 block's transform is | ||
| 67 | +TX_64X64 with no tx-depth syntax; the counter keeps its narrow `tx_select` meaning), then 18bf7dc | ||
| 68 | +(= lane-sb128 5ea5ec8; three conflicts in `stream.rs`, ALL resolved to main's side per the batch | ||
| 69 | +coordinator, so main's single seam gate `a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact` | ||
| 70 | +survives and lane-oddh's seam refusal stays deleted). `cdf.rs` merged clean; its NZ_MAP and | ||
| 71 | +FILTER_INTRA regions are byte-identical to main's (`git diff main -- crates/ec-av1/src/cdf.rs` shows | ||
| 72 | +only the four new `TXB_SKIP_CHROMA_32_BIG*` tables). | ||
| 73 | + | ||
| 74 | +## Suite | ||
| 75 | + | ||
| 76 | +EVIDENCE: `$HOME/.cache/sb128b-suite-r3.log` (unit `sb128b-suite-r3-1788323779.service`, tip | ||
| 77 | +`7ceb309`) | `EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3` | | ||
| 78 | +**test result: ok. 371 passed; 0 failed; 32 ignored; 473.61s** — GREEN. | ||
| 79 | + | ||
| 80 | +## ReelC key frame | ||
| 81 | + | ||
| 82 | +EVIDENCE: `$HOME/.cache/sb128b-work/{reelckf0.obu,reelcours.yuv.f0.yuv,ref.yuv}` | r2's recipe | ||
| 83 | +(`ffmpeg -t 2 -c:v copy -f obu` off the film, 1920x792 yuv420p10le), `dump_yuv` under a 6G scope vs | ||
| 84 | +ffmpeg's rawvideo | **`cmp` says BYTES EQUAL — 4 561 920 bytes, 0 differing samples.** | ||
| 85 | + | ||
| 86 | +Film probe on the 2 s cut (`decode_probe reelc2s.obu`) still stops at | ||
| 87 | +`an inter frame under a 128x128 superblock (this decoder's inter tile path recurses a 64x64 | ||
| 88 | +superblock root only)` — main 18bf7dc (lane-sb128 5ea5ec8) did NOT lift this one on this tree. | ||
| 89 | + | ||
| 90 | +## Open residue | ||
| 91 | + | ||
| 92 | +- deferred: `a 128x128 superblock HORZ/VERT or AB partition` — not started; every 128 root in the | ||
| 93 | + four gate arms resolves NONE or SPLIT, so nothing here is measured. Unblocked by an aomenc recipe | ||
| 94 | + that actually emits a 128-level HORZ/VERT (r2's seed-42 "HORZ/VERT at 128" sighting was our own | ||
| 95 | + desync talking — class [[refusal-from-own-desync]]: with the entropy fixed, that same stream | ||
| 96 | + reads nine NONE roots). | ||
| 97 | +- deferred: `a 128x128 superblock PARTITION_NONE root on an inter frame` and | ||
| 98 | + `an inter frame under a 128x128 superblock` (the ReelC blocker) — inter path untouched this round; | ||
| 99 | + unblocked by the inter tile path recursing a 128 root. | ||
| 100 | +- deferred: the `--enable-tx-size-search=1` arm at 128 (a read tx_depth under a 128 NONE root) — | ||
| 101 | + the four arms all pin `=0`; unblocked now that the NONE arm is exact, so it is a one-arm follow-up. | ||