Merge main 4eff3a1 (lane-sb128b e8e64a6) into lane-sbrect10
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()); |
| @@ -4873,6 +4877,32 @@ impl Neighbours { | |||
| 4873 | self.record_mi_luma_rect(at_mi, tx_px, tx_px, grid); | 4877 | self.record_mi_luma_rect(at_mi, tx_px, tx_px, grid); |
| 4874 | } | 4878 | } |
| 4875 | 4879 | ||
| 4880 | + /// [`Self::record_mi_luma`] for ONE CHROMA transform unit of a block whose | ||
| 4881 | + /// uv plane block is several units (lane-sb128b r2: a 128x128 block's | ||
| 4882 | + /// 64x64 uv plane block is four TX_32X32 units, `av1_get_max_uv_txsize`). | ||
| 4883 | + /// `w_px`/`h_px` are the unit's extent in LUMA pixels -- the chroma | ||
| 4884 | + /// coefficient-context arrays are indexed by luma mi, the convention | ||
| 4885 | + /// [`Self::record_split_luma_rect_mi`] already writes them in, frame-edge | ||
| 4886 | + /// clamp included. | ||
| 4887 | + fn record_mi_chroma( | ||
| 4888 | + &mut self, | ||
| 4889 | + (mi_r, mi_c): (usize, usize), | ||
| 4890 | + w_px: usize, | ||
| 4891 | + h_px: usize, | ||
| 4892 | + plane: usize, | ||
| 4893 | + grid: &[i32], | ||
| 4894 | + ) { | ||
| 4895 | + let round_up_even = |n: usize| n.div_ceil(2) * 2; | ||
| 4896 | + let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); | ||
| 4897 | + let state = neighbour_state(grid); | ||
| 4898 | + for cell in 0..(h_px / MI).min(bound_h.saturating_sub(mi_r)) { | ||
| 4899 | + self.left[mi_r + cell][plane] = state; | ||
| 4900 | + } | ||
| 4901 | + for cell in 0..(w_px / MI).min(bound_w.saturating_sub(mi_c)) { | ||
| 4902 | + self.above[mi_c + cell][plane] = state; | ||
| 4903 | + } | ||
| 4904 | + } | ||
| 4905 | + | ||
| 4876 | /// [`Self::record_mi_luma`] for a RECTANGULAR transform unit (lane-rectsplitx | 4906 | /// [`Self::record_mi_luma`] for a RECTANGULAR transform unit (lane-rectsplitx |
| 4877 | /// r1): the above context spans the unit's width, the left context its | 4907 | /// r1): the above context spans the unit's width, the left context its |
| 4878 | /// height, which for a square unit is the same loop it always was. | 4908 | /// height, which for a square unit is the same loop it always was. |
| @@ -8432,8 +8462,12 @@ fn read_intra_mode( | |||
| 8432 | // `segment_id`, `cdef`, `delta_q` -- `cdef` lands right here. | 8462 | // `segment_id`, `cdef`, `delta_q` -- `cdef` lands right here. |
| 8433 | maybe_read_cdef_idx(dec, mi_r, mi_c, skip); | 8463 | maybe_read_cdef_idx(dec, mi_r, mi_c, skip); |
| 8434 | istep!("cdef", 0); | 8464 | istep!("cdef", 0); |
| 8435 | - maybe_read_delta_q(dec, cdfs, mi_r, mi_c, side == 64, skip); | 8465 | + // lane-sb128b r1: "this leaf IS the superblock" is `side == sb_size`, not |
| 8436 | - maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, side == 64, skip); | 8466 | + // a hardcoded 64 -- a `PARTITION_NONE` 128x128 root is the whole |
| 8467 | + // superblock and skips `delta_q` exactly like a 64 one under a 64 root. | ||
| 8468 | + let whole_sb = side == sb_mi_cur() as usize * 4; | ||
| 8469 | + maybe_read_delta_q(dec, cdfs, mi_r, mi_c, whole_sb, skip); | ||
| 8470 | + maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, whole_sb, skip); | ||
| 8437 | istep!("dq", 0); | 8471 | istep!("dq", 0); |
| 8438 | // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at | 8472 | // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at |
| 8439 | // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before | 8473 | // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before |
| @@ -9132,7 +9166,12 @@ fn read_plane( | |||
| 9132 | let skip_ctx = if plane_idx == 0 { | 9166 | let skip_ctx = if plane_idx == 0 { |
| 9133 | luma_skip_ctx.unwrap_or(0) | 9167 | luma_skip_ctx.unwrap_or(0) |
| 9134 | } else { | 9168 | } else { |
| 9135 | - usize::from(around.0) + usize::from(around.1) | 9169 | + // libaom `get_txb_ctx`: a chroma unit's context is |
| 9170 | + // `combine_entropy_contexts(above, left)` plus 7, or plus 10 when the | ||
| 9171 | + // plane block is bigger than the transform. Our chroma tables hold the | ||
| 9172 | + // offset-7 rows first, so the caller adds 3 for the bigger-block case | ||
| 9173 | + // (only a 128x128 block's TX_32X32 chroma units, lane-sb128b r3). | ||
| 9174 | + usize::from(around.0) + usize::from(around.1) + luma_skip_ctx.unwrap_or(0) | ||
| 9136 | }; | 9175 | }; |
| 9137 | // spec 5.11.47/libaom `av1_read_tx_type`: a filter-intra luma block's | 9176 | // spec 5.11.47/libaom `av1_read_tx_type`: a filter-intra luma block's |
| 9138 | // `intra_ext_tx_cdf` row is indexed by `fimode_to_intradir[filter_intra_mode]`, | 9177 | // `intra_ext_tx_cdf` row is indexed by `fimode_to_intradir[filter_intra_mode]`, |
| @@ -9317,7 +9356,11 @@ fn decode_block( | |||
| 9317 | let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, None); | 9356 | let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, None); |
| 9318 | (resolved, if resolved == 64 { 32 } else { resolved }) | 9357 | (resolved, if resolved == 64 { 32 } else { resolved }) |
| 9319 | } else { | 9358 | } else { |
| 9320 | - (side, luma_tx) | 9359 | + // lane-sb128b r1: `max_txsize_rect_lookup[BLOCK_128X128]` is |
| 9360 | + // TX_64X64, so a 128x128 block is always FOUR luma transform units | ||
| 9361 | + // even with `tx_select` off -- the TU loop below, never the | ||
| 9362 | + // single-unit path. | ||
| 9363 | + (side.min(64), luma_tx) | ||
| 9321 | }; | 9364 | }; |
| 9322 | if tx_select && logical_tx < side && uv_mode != DC_PRED { | 9365 | if tx_select && logical_tx < side && uv_mode != DC_PRED { |
| 9323 | SQ_CHROMA_TX_HITS.with(|c| c.set(c.get() + 1)); | 9366 | SQ_CHROMA_TX_HITS.with(|c| c.set(c.get() + 1)); |
| @@ -9422,10 +9465,17 @@ fn decode_block( | |||
| 9422 | // The palette/intrabc override path keeps the single-call shape (its | 9465 | // The palette/intrabc override path keeps the single-call shape (its |
| 9423 | // per-TU windowing is the non-skip loop's own `palette_y_buf` slice, | 9466 | // per-TU windowing is the non-skip loop's own `palette_y_buf` slice, |
| 9424 | // untested for skip and unreachable in these streams). | 9467 | // untested for skip and unreachable in these streams). |
| 9468 | + // lane-sb128b r2: a 128x128 block's transform is TX_64X64 even with | ||
| 9469 | + // `tx_select` off (`max_txsize_rect_lookup[BLOCK_128X128]`), so the | ||
| 9470 | + // per-unit prediction is keyed on the transform being smaller than | ||
| 9471 | + // the block, not on the tx-depth syntax. The counter keeps lane-hgkf's | ||
| 9472 | + // narrower meaning (a READ split tx depth). | ||
| 9425 | let split_tx_skip = | 9473 | let split_tx_skip = |
| 9426 | - tx_select && logical_tx < side && palette_y_buf.is_none() && intrabc_bufs.is_none(); | 9474 | + logical_tx < side && palette_y_buf.is_none() && intrabc_bufs.is_none(); |
| 9427 | if split_tx_skip { | 9475 | if split_tx_skip { |
| 9428 | - SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | 9476 | + if tx_select { |
| 9477 | + SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | ||
| 9478 | + } | ||
| 9429 | let n_axis = side / logical_tx; | 9479 | let n_axis = side / logical_tx; |
| 9430 | for tu_row in 0..n_axis { | 9480 | for tu_row in 0..n_axis { |
| 9431 | for tu_col in 0..n_axis { | 9481 | for tu_col in 0..n_axis { |
| @@ -9475,41 +9525,62 @@ fn decode_block( | |||
| 9475 | ); | 9525 | ); |
| 9476 | } | 9526 | } |
| 9477 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 9527 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 9478 | - if let Some((ub, _)) = &palette_uv_bufs { | 9528 | + let cn = (chroma_side / chroma_tx).max(1); |
| 9479 | - set_palette_pred(ub.clone()); | 9529 | + for cu_row in 0..cn { |
| 9480 | - } | 9530 | + for cu_col in 0..cn { |
| 9481 | - u.reconstruct( | 9531 | + let luma_span = chroma_tx * 2; |
| 9482 | - cpx, | 9532 | + let cu_r = if cn == 1 { |
| 9483 | - cpy, | 9533 | + reach |
| 9484 | - chroma_side, | 9534 | + } else { |
| 9485 | - uv_predict_mode, | 9535 | + tu_reach( |
| 9486 | - angle_delta_uv, | 9536 | + side, side, |
| 9487 | - reach, | 9537 | + cu_col * luma_span, cu_row * luma_span, luma_span, |
| 9488 | - &vec![0i32; chroma_side * chroma_side], | 9538 | + reach, px, py, y.width, y.height, |
| 9489 | - alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | 9539 | + ) |
| 9490 | - None, | 9540 | + }; |
| 9491 | - smooth_neighbor_uv, | 9541 | + let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx); |
| 9492 | - ); | 9542 | + if let Some((ub, _)) = &palette_uv_bufs { |
| 9493 | - if let Some((_, vb)) = &palette_uv_bufs { | 9543 | + set_palette_pred(ub.clone()); |
| 9494 | - set_palette_pred(vb.clone()); | 9544 | + } |
| 9545 | + u.reconstruct( | ||
| 9546 | + cu_x, | ||
| 9547 | + cu_y, | ||
| 9548 | + chroma_tx, | ||
| 9549 | + uv_predict_mode, | ||
| 9550 | + angle_delta_uv, | ||
| 9551 | + cu_r, | ||
| 9552 | + &vec![0i32; chroma_tx * chroma_tx], | ||
| 9553 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | ||
| 9554 | + None, | ||
| 9555 | + smooth_neighbor_uv, | ||
| 9556 | + ); | ||
| 9557 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 9558 | + set_palette_pred(vb.clone()); | ||
| 9559 | + } | ||
| 9560 | + v.reconstruct( | ||
| 9561 | + cu_x, | ||
| 9562 | + cu_y, | ||
| 9563 | + chroma_tx, | ||
| 9564 | + uv_predict_mode, | ||
| 9565 | + angle_delta_uv, | ||
| 9566 | + cu_r, | ||
| 9567 | + &vec![0i32; chroma_tx * chroma_tx], | ||
| 9568 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 9569 | + None, | ||
| 9570 | + smooth_neighbor_uv, | ||
| 9571 | + ); | ||
| 9572 | + } | ||
| 9495 | } | 9573 | } |
| 9496 | - v.reconstruct( | ||
| 9497 | - cpx, | ||
| 9498 | - cpy, | ||
| 9499 | - chroma_side, | ||
| 9500 | - uv_predict_mode, | ||
| 9501 | - angle_delta_uv, | ||
| 9502 | - reach, | ||
| 9503 | - &vec![0i32; chroma_side * chroma_side], | ||
| 9504 | - alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 9505 | - None, | ||
| 9506 | - smooth_neighbor_uv, | ||
| 9507 | - ); | ||
| 9508 | let luma_grid = vec![0i32; side * side]; | 9574 | let luma_grid = vec![0i32; side * side]; |
| 9509 | let u_grid = vec![0i32; chroma_side * chroma_side]; | 9575 | let u_grid = vec![0i32; chroma_side * chroma_side]; |
| 9510 | let v_grid = vec![0i32; chroma_side * chroma_side]; | 9576 | let v_grid = vec![0i32; chroma_side * chroma_side]; |
| 9511 | neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]); | 9577 | neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]); |
| 9512 | - } else if !tx_select || logical_tx == side { | 9578 | + } else if logical_tx == side { |
| 9579 | + // lane-sb128b r1: the test used to be `!tx_select || logical_tx == side`. | ||
| 9580 | + // Without `tx_select` `logical_tx` IS `side` at every size <= 64, so | ||
| 9581 | + // that arm was redundant -- and wrong at 128, where | ||
| 9582 | + // `max_txsize_rect_lookup` caps the block's transform at 64 and the | ||
| 9583 | + // block is four units whether or not `tx_select` is on. | ||
| 9513 | // A single luma transform unit -- the old path, unchanged (including | 9584 | // A single luma transform unit -- the old path, unchanged (including |
| 9514 | // the 64x64 corner case, `logical_tx == side == 64` with | 9585 | // the 64x64 corner case, `logical_tx == side == 64` with |
| 9515 | // `coeff_tx_side == 32`). | 9586 | // `coeff_tx_side == 32`). |
| @@ -9602,8 +9673,27 @@ fn decode_block( | |||
| 9602 | // the earlier tiles in this same block already wrote -- the same | 9673 | // the earlier tiles in this same block already wrote -- the same |
| 9603 | // per-TU pattern [`decode_leaf8`] already runs for an 8x8 leaf. | 9674 | // per-TU pattern [`decode_leaf8`] already runs for an 8x8 leaf. |
| 9604 | let n_axis = side / logical_tx; | 9675 | let n_axis = side / logical_tx; |
| 9605 | - for tu_row in 0..n_axis { | 9676 | + let cn = (chroma_side / chroma_tx).max(1); |
| 9606 | - for tu_col in 0..n_axis { | 9677 | + // libaom's transform-block loop is over 64x64 luma "mu" chunks |
| 9678 | + // (`decode_token_recon_block`: `mu_blocks_wide/high` = | ||
| 9679 | + // `mi_size_wide[BLOCK_64X64]`), and it codes EVERY PLANE of a chunk | ||
| 9680 | + // before moving to the next one. Below 128 a block is a single chunk, | ||
| 9681 | + // so this is byte-for-byte the all-luma-then-all-chroma order that has | ||
| 9682 | + // always run; at 128 the four quadrants interleave Y,U,V per quadrant | ||
| 9683 | + // and reading all four luma units first desyncs the tile at the second | ||
| 9684 | + // one (lane-sb128b r3, measured against aomdec's `EC_TRACE_COEFF`). | ||
| 9685 | + let nchunk = (side / 64).max(1); | ||
| 9686 | + // `cn > 1` means the uv plane block is larger than the uv transform, | ||
| 9687 | + // which moves libaom's chroma `txb_skip_ctx` offset from 7 to 10. | ||
| 9688 | + let chroma_ctx_offset = if cn > 1 { Some(3) } else { None }; | ||
| 9689 | + let tpc = (n_axis / nchunk).max(1); | ||
| 9690 | + let cpc = (cn / nchunk).max(1); | ||
| 9691 | + let mut last_grids = [Vec::new(), Vec::new()]; | ||
| 9692 | + let mut units: Vec<((usize, usize), usize, Vec<i32>, Vec<i32>)> = Vec::new(); | ||
| 9693 | + for ch_row in 0..nchunk { | ||
| 9694 | + for ch_col in 0..nchunk { | ||
| 9695 | + for tu_row in ch_row * tpc..(ch_row + 1) * tpc { | ||
| 9696 | + for tu_col in ch_col * tpc..(ch_col + 1) * tpc { | ||
| 9607 | let tu_mi = ( | 9697 | let tu_mi = ( |
| 9608 | mi_r + tu_row * (logical_tx / MI), | 9698 | mi_r + tu_row * (logical_tx / MI), |
| 9609 | mi_c + tu_col * (logical_tx / MI), | 9699 | mi_c + tu_col * (logical_tx / MI), |
| @@ -9664,7 +9754,11 @@ fn decode_block( | |||
| 9664 | tu_px, | 9754 | tu_px, |
| 9665 | tu_py, | 9755 | tu_py, |
| 9666 | logical_tx, | 9756 | logical_tx, |
| 9667 | - logical_tx, | 9757 | + // The unit's own COEFFICIENT grid, half its side at |
| 9758 | + // TX_64X64 (a 64-point transform codes nothing past 32); | ||
| 9759 | + // identical to `logical_tx` at every smaller size | ||
| 9760 | + // (lane-sb128b r1). | ||
| 9761 | + coeff_tx_side, | ||
| 9668 | base_q_idx, | 9762 | base_q_idx, |
| 9669 | None, | 9763 | None, |
| 9670 | filter_intra, | 9764 | filter_intra, |
| @@ -9682,59 +9776,81 @@ fn decode_block( | |||
| 9682 | neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid); | 9776 | neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid); |
| 9683 | } | 9777 | } |
| 9684 | } | 9778 | } |
| 9779 | + // CfL is only allowed up to 32x32, i.e. only at `nchunk == 1`, where | ||
| 9780 | + // this still runs after every luma unit of the block. | ||
| 9685 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 9781 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 9686 | - let chroma_around = neighbours.around(at, side); | 9782 | + // The block's uv plane block is `chroma_side` across but its uv |
| 9687 | - if let Some((ub, _)) = &palette_uv_bufs { | 9783 | + // transform is `chroma_tx` (`av1_get_max_uv_txsize` = |
| 9688 | - set_palette_pred(ub.clone()); | 9784 | + // `av1_get_adjusted_tx_size(max_txsize_rect_lookup[uv_plane_bsize])`): |
| 9785 | + // identical at every size up to 64x64, but a 128x128 block's 64x64 uv | ||
| 9786 | + // plane block adjusts TX_64X64 down to TX_32X32, so each plane is | ||
| 9787 | + // FOUR units (lane-sb128b r2) -- one per mu chunk. | ||
| 9788 | + for cu_row in ch_row * cpc..(ch_row + 1) * cpc { | ||
| 9789 | + for cu_col in ch_col * cpc..(ch_col + 1) * cpc { | ||
| 9790 | + // The chroma context arrays are indexed in LUMA mi, so this | ||
| 9791 | + // unit's anchor is its own luma quadrant: `chroma_tx` chroma | ||
| 9792 | + // pixels span `2 * chroma_tx` luma ones. | ||
| 9793 | + let luma_span = chroma_tx * 2; | ||
| 9794 | + let cu_mi = ( | ||
| 9795 | + mi_r + cu_row * (luma_span / MI), | ||
| 9796 | + mi_c + cu_col * (luma_span / MI), | ||
| 9797 | + ); | ||
| 9798 | + let cu_around = neighbours.around_mi(cu_mi, luma_span); | ||
| 9799 | + let cu_reach = if cn == 1 { | ||
| 9800 | + reach | ||
| 9801 | + } else { | ||
| 9802 | + tu_reach( | ||
| 9803 | + side, side, | ||
| 9804 | + cu_col * luma_span, cu_row * luma_span, luma_span, | ||
| 9805 | + reach, px, py, y.width, y.height, | ||
| 9806 | + ) | ||
| 9807 | + }; | ||
| 9808 | + let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx); | ||
| 9809 | + if let Some((ub, _)) = &palette_uv_bufs { | ||
| 9810 | + set_palette_pred(ub.clone()); | ||
| 9811 | + } | ||
| 9812 | + let u_grid = read_plane( | ||
| 9813 | + dec, cdfs, chroma_set, scans.1, 1, cu_around[1], mode, | ||
| 9814 | + uv_predict_mode, angle_delta_uv, cu_reach, u, cu_x, cu_y, | ||
| 9815 | + chroma_tx, chroma_tx, base_q_idx, | ||
| 9816 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | ||
| 9817 | + None, chroma_ctx_offset, smooth_neighbor_uv, | ||
| 9818 | + )?; | ||
| 9819 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 9820 | + set_palette_pred(vb.clone()); | ||
| 9821 | + } | ||
| 9822 | + let v_grid = read_plane( | ||
| 9823 | + dec, cdfs, chroma_set, scans.1, 2, cu_around[2], mode, | ||
| 9824 | + uv_predict_mode, angle_delta_uv, cu_reach, v, cu_x, cu_y, | ||
| 9825 | + chroma_tx, chroma_tx, base_q_idx, | ||
| 9826 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 9827 | + None, chroma_ctx_offset, smooth_neighbor_uv, | ||
| 9828 | + )?; | ||
| 9829 | + if cn > 1 { | ||
| 9830 | + CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | ||
| 9831 | + // Immediately, so the NEXT unit of this same block reads | ||
| 9832 | + // this one's coefficient context (libaom's chroma | ||
| 9833 | + // `txb_skip_ctx` for the second quadrant is 11, i.e. base | ||
| 9834 | + // 1 from this left neighbour -- measured against aomdec). | ||
| 9835 | + // The same writes are replayed after `record_split_luma` | ||
| 9836 | + // below, which would otherwise clobber them whole-block. | ||
| 9837 | + neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, 1, &u_grid); | ||
| 9838 | + neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, 2, &v_grid); | ||
| 9839 | + units.push((cu_mi, luma_span, u_grid.clone(), v_grid.clone())); | ||
| 9840 | + } | ||
| 9841 | + last_grids = [u_grid, v_grid]; | ||
| 9842 | + } | ||
| 9689 | } | 9843 | } |
| 9690 | - let u_grid = read_plane( | ||
| 9691 | - dec, | ||
| 9692 | - cdfs, | ||
| 9693 | - chroma_set, | ||
| 9694 | - scans.1, | ||
| 9695 | - 1, | ||
| 9696 | - chroma_around[1], | ||
| 9697 | - mode, | ||
| 9698 | - uv_predict_mode, | ||
| 9699 | - angle_delta_uv, | ||
| 9700 | - reach, | ||
| 9701 | - u, | ||
| 9702 | - cpx, | ||
| 9703 | - cpy, | ||
| 9704 | - chroma_side, | ||
| 9705 | - chroma_tx, | ||
| 9706 | - base_q_idx, | ||
| 9707 | - alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | ||
| 9708 | - None, | ||
| 9709 | - None, | ||
| 9710 | - smooth_neighbor_uv, | ||
| 9711 | - )?; | ||
| 9712 | - if let Some((_, vb)) = &palette_uv_bufs { | ||
| 9713 | - set_palette_pred(vb.clone()); | ||
| 9714 | } | 9844 | } |
| 9715 | - let v_grid = read_plane( | 9845 | + } |
| 9716 | - dec, | 9846 | + // Mode/side bookkeeping plus, at `cn == 1`, the whole-plane chroma |
| 9717 | - cdfs, | 9847 | + // context write; at `cn > 1` the per-unit writes above are what the |
| 9718 | - chroma_set, | 9848 | + // next block reads, so they run after this (last writer wins). |
| 9719 | - scans.1, | 9849 | + neighbours.record_split_luma(at, side, mode, uv_predict_mode, [&last_grids[0], &last_grids[1]]); |
| 9720 | - 2, | 9850 | + for (cu_mi, luma_span, u_grid, v_grid) in &units { |
| 9721 | - chroma_around[2], | 9851 | + neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 1, u_grid); |
| 9722 | - mode, | 9852 | + neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 2, v_grid); |
| 9723 | - uv_predict_mode, | 9853 | + } |
| 9724 | - angle_delta_uv, | ||
| 9725 | - reach, | ||
| 9726 | - v, | ||
| 9727 | - cpx, | ||
| 9728 | - cpy, | ||
| 9729 | - chroma_side, | ||
| 9730 | - chroma_tx, | ||
| 9731 | - base_q_idx, | ||
| 9732 | - alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 9733 | - None, | ||
| 9734 | - None, | ||
| 9735 | - smooth_neighbor_uv, | ||
| 9736 | - )?; | ||
| 9737 | - neighbours.record_split_luma(at, side, mode, uv_predict_mode, [&u_grid, &v_grid]); | ||
| 9738 | } | 9854 | } |
| 9739 | // Unconditional, `size == 0` for a non-palette block: clears any stale | 9855 | // Unconditional, `size == 0` for a non-palette block: clears any stale |
| 9740 | // neighbour palette state the same way [`Neighbours::record`] always | 9856 | // neighbour palette state the same way [`Neighbours::record`] always |
| @@ -11141,8 +11257,14 @@ fn read_tx_size( | |||
| 11141 | // key-frame path's own deblock-grid approximation. | 11257 | // key-frame path's own deblock-grid approximation. |
| 11142 | ctx_override: Option<usize>, | 11258 | ctx_override: Option<usize>, |
| 11143 | ) -> usize { | 11259 | ) -> usize { |
| 11144 | - let ctx = ctx_override.unwrap_or_else(|| tx_size_context(n, at_mi, side)); | 11260 | + // `max_txsize_rect_lookup[bsize]` (libaom `read_selected_tx_size` / |
| 11145 | - let depth = match side { | 11261 | + // `get_tx_size_context`): a block wider than 64 still tops out at |
| 11262 | + // TX_64X64, so BLOCK_128X128 reads BLOCK_64X64's own category (its depth | ||
| 11263 | + // chain 64->32->16->8->4 is the same four steps) and resolves against 64, | ||
| 11264 | + // never against its own 128 side (lane-sb128b r1). | ||
| 11265 | + let max_tx = side.min(64); | ||
| 11266 | + let ctx = ctx_override.unwrap_or_else(|| tx_size_context(n, at_mi, max_tx)); | ||
| 11267 | + let depth = match max_tx { | ||
| 11146 | 8 => { | 11268 | 8 => { |
| 11147 | dec.symbol(&mut cdfs.tx_size_cat0[ctx]) | 11269 | dec.symbol(&mut cdfs.tx_size_cat0[ctx]) |
| 11148 | } | 11270 | } |
| @@ -11155,7 +11277,7 @@ fn read_tx_size( | |||
| 11155 | 64 => { | 11277 | 64 => { |
| 11156 | dec.symbol(&mut cdfs.tx_size_cat3[ctx]) | 11278 | dec.symbol(&mut cdfs.tx_size_cat3[ctx]) |
| 11157 | } | 11279 | } |
| 11158 | - _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64"), | 11280 | + _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64/128"), |
| 11159 | }; | 11281 | }; |
| 11160 | if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { | 11282 | if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { |
| 11161 | let (rng, _) = dec.debug_state(); | 11283 | let (rng, _) = dec.debug_state(); |
| @@ -11167,7 +11289,7 @@ fn read_tx_size( | |||
| 11167 | if depth != 0 { | 11289 | if depth != 0 { |
| 11168 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); | 11290 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); |
| 11169 | } | 11291 | } |
| 11170 | - side >> depth | 11292 | + max_tx >> depth |
| 11171 | } | 11293 | } |
| 11172 | 11294 | ||
| 11173 | /// `txfm_partition_context` (libaom `av1_common_int.h`): an inter block's | 11295 | /// `txfm_partition_context` (libaom `av1_common_int.h`): an inter block's |
| @@ -12774,6 +12896,29 @@ fn sb_visit_order(r0: u32, r1: u32, c0: u32, c1: u32, sb128: bool) -> Vec<(u32, | |||
| 12774 | /// decides the root -- only SPLIT recurses into the four 64x64 quadrants this | 12896 | /// decides the root -- only SPLIT recurses into the four 64x64 quadrants this |
| 12775 | /// decoder codes, the other seven arms refuse by name. | 12897 | /// decoder codes, the other seven arms refuse by name. |
| 12776 | #[allow(clippy::too_many_arguments)] | 12898 | #[allow(clippy::too_many_arguments)] |
| 12899 | +thread_local! { | ||
| 12900 | + /// How many 128x128 superblock roots resolved to `PARTITION_NONE` -- one | ||
| 12901 | + /// whole 128x128 block (lane-sb128b r1's gate counter). | ||
| 12902 | + pub(crate) static PART128_NONE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 12903 | +} | ||
| 12904 | + | ||
| 12905 | +/// [`PART128_NONE_HITS`], for a gate's own before/after delta. | ||
| 12906 | +pub(crate) fn part128_none_hits() -> usize { | ||
| 12907 | + PART128_NONE_HITS.with(std::cell::Cell::get) | ||
| 12908 | +} | ||
| 12909 | + | ||
| 12910 | +thread_local! { | ||
| 12911 | + /// How many CHROMA transform units were coded inside a block whose uv | ||
| 12912 | + /// plane block is more than one unit (lane-sb128b r2 -- only a 128x128 | ||
| 12913 | + /// block, four per plane). | ||
| 12914 | + pub(crate) static CHROMA_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 12915 | +} | ||
| 12916 | + | ||
| 12917 | +/// [`CHROMA_SPLIT_TX_HITS`], for a gate's own before/after delta. | ||
| 12918 | +pub(crate) fn chroma_split_tx_hits() -> usize { | ||
| 12919 | + CHROMA_SPLIT_TX_HITS.with(std::cell::Cell::get) | ||
| 12920 | +} | ||
| 12921 | + | ||
| 12777 | fn read_sb128_root( | 12922 | fn read_sb128_root( |
| 12778 | dec: &mut SymbolDecoder, | 12923 | dec: &mut SymbolDecoder, |
| 12779 | cdfs: &mut Cdfs, | 12924 | cdfs: &mut Cdfs, |
| @@ -12788,7 +12933,7 @@ fn read_sb128_root( | |||
| 12788 | sb_c: u32, | 12933 | sb_c: u32, |
| 12789 | mi_cols: u32, | 12934 | mi_cols: u32, |
| 12790 | mi_rows: u32, | 12935 | mi_rows: u32, |
| 12791 | -) -> Result<()> { | 12936 | +) -> Result<usize> { |
| 12792 | let (mi_r128, mi_c128) = ((sb_r & !1) * SB_MI, (sb_c & !1) * SB_MI); | 12937 | let (mi_r128, mi_c128) = ((sb_r & !1) * SB_MI, (sb_c & !1) * SB_MI); |
| 12793 | crate::restoration::read_lr( | 12938 | crate::restoration::read_lr( |
| 12794 | dec, | 12939 | dec, |
| @@ -12839,13 +12984,20 @@ fn read_sb128_root( | |||
| 12839 | } | 12984 | } |
| 12840 | } | 12985 | } |
| 12841 | }; | 12986 | }; |
| 12842 | - if part128 != PARTITION_SPLIT { | 12987 | + // lane-sb128b r1: `PARTITION_NONE` -- one 128x128 block -- is decoded by |
| 12988 | + // the key-frame caller below. The six remaining arms (HORZ/VERT and the | ||
| 12989 | + // four AB shapes) still need the rect/AB machinery at this size. | ||
| 12990 | + if part128 != PARTITION_SPLIT && part128 != PARTITION_NONE { | ||
| 12843 | return Err(unsupported( | 12991 | return Err(unsupported( |
| 12844 | - "a 128x128 superblock partition other than SPLIT (NONE/HORZ/VERT and the four AB arms at the 128 root are not decoded)", | 12992 | + "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)", |
| 12845 | )); | 12993 | )); |
| 12846 | } | 12994 | } |
| 12847 | - PART128_SPLIT_HITS.with(|c| c.set(c.get() + 1)); | 12995 | + if part128 == PARTITION_SPLIT { |
| 12848 | - Ok(()) | 12996 | + PART128_SPLIT_HITS.with(|c| c.set(c.get() + 1)); |
| 12997 | + } else { | ||
| 12998 | + PART128_NONE_HITS.with(|c| c.set(c.get() + 1)); | ||
| 12999 | + } | ||
| 13000 | + Ok(part128) | ||
| 12849 | } | 13001 | } |
| 12850 | 13002 | ||
| 12851 | pub(crate) fn decode_key_frame_tile_with_cdfs( | 13003 | pub(crate) fn decode_key_frame_tile_with_cdfs( |
| @@ -13023,10 +13175,20 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 13023 | ); | 13175 | ); |
| 13024 | TILE_HITS.with(|c| c.set(c.get() + 1)); | 13176 | TILE_HITS.with(|c| c.set(c.get() + 1)); |
| 13025 | 13177 | ||
| 13178 | + // lane-sb128b r1: set when the 128 root resolved to `PARTITION_NONE` -- | ||
| 13179 | + // its one block covers all four 64x64 quadrants, so the remaining three | ||
| 13180 | + // visits of this superblock code nothing at all. | ||
| 13181 | + let mut sb128_none = false; | ||
| 13026 | for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) { | 13182 | for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) { |
| 13027 | if row_start { | 13183 | if row_start { |
| 13028 | neighbours.start_row(); | 13184 | neighbours.start_row(); |
| 13029 | } | 13185 | } |
| 13186 | + if sb_start { | ||
| 13187 | + sb128_none = false; | ||
| 13188 | + } | ||
| 13189 | + if sb128_none { | ||
| 13190 | + continue; | ||
| 13191 | + } | ||
| 13030 | { | 13192 | { |
| 13031 | // lane-sb128 r1: the 128 root. Its loop-restoration units are read | 13193 | // lane-sb128 r1: the 128 root. Its loop-restoration units are read |
| 13032 | // once for the whole 128x128 (spec 5.11.57 is called with the | 13194 | // once for the whole 128x128 (spec 5.11.57 is called with the |
| @@ -13034,7 +13196,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 13034 | // `BLOCK_128X128` CDF (8 symbols) decides the root -- only SPLIT | 13196 | // `BLOCK_128X128` CDF (8 symbols) decides the root -- only SPLIT |
| 13035 | // recurses into the four 64x64 quadrants this decoder codes. | 13197 | // recurses into the four 64x64 quadrants this decoder codes. |
| 13036 | if sb128 && sb_start { | 13198 | if sb128 && sb_start { |
| 13037 | - read_sb128_root( | 13199 | + let part128 = read_sb128_root( |
| 13038 | &mut dec, | 13200 | &mut dec, |
| 13039 | &mut cdfs, | 13201 | &mut cdfs, |
| 13040 | &neighbours, | 13202 | &neighbours, |
| @@ -13046,6 +13208,62 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 13046 | mi_cols, | 13208 | mi_cols, |
| 13047 | mi_rows, | 13209 | mi_rows, |
| 13048 | )?; | 13210 | )?; |
| 13211 | + if part128 == PARTITION_NONE { | ||
| 13212 | + // One 128x128 intra block: four TX_64X64 luma units and a | ||
| 13213 | + // single 64x64 chroma unit per plane (`av1_get_max_uv_txsize` | ||
| 13214 | + // of a 128x128 block is TX_64X64 over its 64x64 uv plane | ||
| 13215 | + // block). No CfL, no filter intra, no palette at this size -- | ||
| 13216 | + // [`read_intra_mode`]'s own size gates already say so. | ||
| 13217 | + sb128_none = true; | ||
| 13218 | + CDEF_TRANSMITTED.with(|c| c.set(false)); | ||
| 13219 | + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); | ||
| 13220 | + decode_block( | ||
| 13221 | + &mut dec, | ||
| 13222 | + &mut cdfs, | ||
| 13223 | + &mut neighbours, | ||
| 13224 | + at128, | ||
| 13225 | + SB * 2, | ||
| 13226 | + TxbSet::Luma64, | ||
| 13227 | + TxbSet::Chroma32, | ||
| 13228 | + TX32, | ||
| 13229 | + TX32, | ||
| 13230 | + (&scan32, &scan32), | ||
| 13231 | + false, | ||
| 13232 | + &mut y, | ||
| 13233 | + &mut u, | ||
| 13234 | + &mut v, | ||
| 13235 | + base_q_idx, | ||
| 13236 | + enable_filter_intra, | ||
| 13237 | + allow_screen_content_tools, | ||
| 13238 | + allow_intrabc, | ||
| 13239 | + &scan32, | ||
| 13240 | + &scan16, | ||
| 13241 | + &scan8, | ||
| 13242 | + &scan4, | ||
| 13243 | + tx_select, | ||
| 13244 | + reduced_tx_set, | ||
| 13245 | + )?; | ||
| 13246 | + // libaom writes one `cdef_strength` into the block's own | ||
| 13247 | + // `MB_MODE_INFO`, which every mi cell of the block -- | ||
| 13248 | + // hence all four 64x64 CDEF units -- points at; our grid | ||
| 13249 | + // is per-unit, so the read (which only ever lands in the | ||
| 13250 | + // top-left unit, `read_cdef`'s index 0) is copied across. | ||
| 13251 | + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); | ||
| 13252 | + CDEF_IDX_GRID.with(|g| { | ||
| 13253 | + let mut g = g.borrow_mut(); | ||
| 13254 | + let cols = CDEF_SB_COLS.with(|c| c.get()); | ||
| 13255 | + if cols > 0 && q_r * cols + q_c < g.len() { | ||
| 13256 | + let idx = g[q_r * cols + q_c]; | ||
| 13257 | + for (dr, dc) in [(0, 1), (1, 0), (1, 1)] { | ||
| 13258 | + let i = (q_r + dr) * cols + q_c + dc; | ||
| 13259 | + if q_c + dc < cols && i < g.len() { | ||
| 13260 | + g[i] = idx; | ||
| 13261 | + } | ||
| 13262 | + } | ||
| 13263 | + } | ||
| 13264 | + }); | ||
| 13265 | + continue; | ||
| 13266 | + } | ||
| 13049 | } | 13267 | } |
| 13050 | if !sb128 { | 13268 | if !sb128 { |
| 13051 | crate::restoration::read_lr( | 13269 | crate::restoration::read_lr( |
| @@ -20656,7 +20874,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 20656 | } | 20874 | } |
| 20657 | { | 20875 | { |
| 20658 | if sb128 && sb_start { | 20876 | if sb128 && sb_start { |
| 20659 | - read_sb128_root( | 20877 | + if read_sb128_root( |
| 20660 | &mut dec, | 20878 | &mut dec, |
| 20661 | &mut cdfs, | 20879 | &mut cdfs, |
| 20662 | &neighbours, | 20880 | &neighbours, |
| @@ -20667,7 +20885,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 20667 | sb_c, | 20885 | sb_c, |
| 20668 | mi_cols, | 20886 | mi_cols, |
| 20669 | mi_rows, | 20887 | mi_rows, |
| 20670 | - )?; | 20888 | + )? != PARTITION_SPLIT |
| 20889 | + { | ||
| 20890 | + // lane-sb128b r1 decodes a `PARTITION_NONE` 128 root on | ||
| 20891 | + // KEY frames only; an inter 128x128 leaf needs whole-block | ||
| 20892 | + // MC, OBMC and compound at a size this path has never run. | ||
| 20893 | + return Err(unsupported( | ||
| 20894 | + "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)", | ||
| 20895 | + )); | ||
| 20896 | + } | ||
| 20671 | } | 20897 | } |
| 20672 | if !sb128 { | 20898 | if !sb128 { |
| 20673 | crate::restoration::read_lr( | 20899 | 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
| @@ -18175,6 +18175,162 @@ mod tests { | |||
| 18175 | ); | 18175 | ); |
| 18176 | } | 18176 | } |
| 18177 | 18177 | ||
| 18178 | + /// lane-sb128b r1 gate: a real `aomenc --sb-size=128` KEY frame whose 128 | ||
| 18179 | + /// roots resolve to `PARTITION_NONE` -- one whole 128x128 intra block, | ||
| 18180 | + /// four TX_64X64 luma transform units and FOUR TX_32X32 chroma units per | ||
| 18181 | + /// plane (`av1_get_max_uv_txsize(BLOCK_128X128)` is | ||
| 18182 | + /// `av1_get_adjusted_tx_size` of its 64x64 uv plane block's TX_64X64, so | ||
| 18183 | + /// TX_32X32) -- lane-sb128b r2's `chroma_split_tx_hits` asserts them. The r1 gate above pins `--max-partition-size=64`, which | ||
| 18184 | + /// makes every 128 root a forced SPLIT and leaves this arm unexercised. | ||
| 18185 | + /// Smooth gradients at a high `--cq-level` are what make the RD search | ||
| 18186 | + /// keep a whole 128x128 block; `part128_none_hits` HARD-asserts it did. | ||
| 18187 | + #[test] | ||
| 18188 | + fn a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact() { | ||
| 18189 | + const NAME: &str = | ||
| 18190 | + "a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact"; | ||
| 18191 | + let _gate_lock = lock_gate_counters(); | ||
| 18192 | + if !have_ffmpeg() { | ||
| 18193 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 18194 | + return; | ||
| 18195 | + } | ||
| 18196 | + if !have_aomenc() { | ||
| 18197 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 18198 | + return; | ||
| 18199 | + } | ||
| 18200 | + let render = |seed: u32, width: usize, height: usize, ten_bit: bool| -> Vec<u8> { | ||
| 18201 | + let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; | ||
| 18202 | + let out = Command::new("ffmpeg") | ||
| 18203 | + .args([ | ||
| 18204 | + "-v", "error", "-f", "lavfi", "-i", | ||
| 18205 | + &gradients_source(seed, width, height, "duration=0.04:rate=25"), | ||
| 18206 | + "-pix_fmt", pix, "-strict", "-1", "-t", "0.04", | ||
| 18207 | + "-f", "yuv4mpegpipe", "-", | ||
| 18208 | + ]) | ||
| 18209 | + .stdin(Stdio::null()) | ||
| 18210 | + .stdout(Stdio::piped()) | ||
| 18211 | + .stderr(Stdio::piped()) | ||
| 18212 | + .output() | ||
| 18213 | + .expect("ffmpeg failed to run"); | ||
| 18214 | + assert!( | ||
| 18215 | + out.status.success(), | ||
| 18216 | + "ffmpeg fixture: {}", | ||
| 18217 | + String::from_utf8_lossy(&out.stderr) | ||
| 18218 | + ); | ||
| 18219 | + out.stdout | ||
| 18220 | + }; | ||
| 18221 | + let mut matched = 0u32; | ||
| 18222 | + let mut named_refusals = 0u32; | ||
| 18223 | + let mut none_arms = 0u32; | ||
| 18224 | + // (seed, cq, width, height, 10-bit). 384x384 is a 3x3 grid of whole | ||
| 18225 | + // 128 superblocks; 256x256 a 2x2. | ||
| 18226 | + let arms: Vec<(u32, &str, usize, usize, bool)> = vec![ | ||
| 18227 | + (42, "--cq-level=63", 384, 384, false), | ||
| 18228 | + (43, "--cq-level=55", 384, 384, false), | ||
| 18229 | + (44, "--cq-level=63", 256, 256, false), | ||
| 18230 | + (45, "--cq-level=63", 384, 384, true), | ||
| 18231 | + ]; | ||
| 18232 | + for (seed, cq, width, height, ten_bit) in arms { | ||
| 18233 | + let y4m = render(seed, width, height, ten_bit); | ||
| 18234 | + let mut args: Vec<&str> = vec![ | ||
| 18235 | + "--codec=av1", "--passes=1", "--end-usage=q", cq, | ||
| 18236 | + "--cpu-used=0", "--threads=1", "--row-mt=0", | ||
| 18237 | + "--sb-size=128", | ||
| 18238 | + "--enable-rect-partitions=0", | ||
| 18239 | + "--enable-ab-partitions=0", | ||
| 18240 | + "--enable-1to4-partitions=0", | ||
| 18241 | + "--min-partition-size=16", | ||
| 18242 | + "--enable-restoration=1", | ||
| 18243 | + "--enable-palette=0", | ||
| 18244 | + "--deltaq-mode=0", | ||
| 18245 | + "--enable-intrabc=0", | ||
| 18246 | + "--enable-tx-size-search=0", | ||
| 18247 | + "--limit=1", | ||
| 18248 | + ]; | ||
| 18249 | + if ten_bit { | ||
| 18250 | + args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); | ||
| 18251 | + } | ||
| 18252 | + args.extend_from_slice(&["--obu", "-o", "-", "-"]); | ||
| 18253 | + let mut child = Command::new(aomenc_path()) | ||
| 18254 | + .args(&args) | ||
| 18255 | + .stdin(Stdio::piped()) | ||
| 18256 | + .stdout(Stdio::piped()) | ||
| 18257 | + .stderr(Stdio::piped()) | ||
| 18258 | + .spawn() | ||
| 18259 | + .expect("aomenc failed to start"); | ||
| 18260 | + child | ||
| 18261 | + .stdin | ||
| 18262 | + .take() | ||
| 18263 | + .expect("aomenc stdin") | ||
| 18264 | + .write_all(&y4m) | ||
| 18265 | + .expect("writing y4m to aomenc"); | ||
| 18266 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 18267 | + assert!( | ||
| 18268 | + out.status.success(), | ||
| 18269 | + "aomenc refused the fixture: {}", | ||
| 18270 | + String::from_utf8_lossy(&out.stderr) | ||
| 18271 | + ); | ||
| 18272 | + let stream = out.stdout; | ||
| 18273 | + let before = crate::decode::part128_none_hits(); | ||
| 18274 | + let frames = match decode_stream(&stream) { | ||
| 18275 | + Err(e) => { | ||
| 18276 | + let msg = e.to_string(); | ||
| 18277 | + assert!( | ||
| 18278 | + msg.contains("unsupported"), | ||
| 18279 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | ||
| 18280 | + ); | ||
| 18281 | + named_refusals += 1; | ||
| 18282 | + eprintln!("seed {seed} refusal: {msg}"); | ||
| 18283 | + continue; | ||
| 18284 | + } | ||
| 18285 | + Ok(frames) => frames, | ||
| 18286 | + }; | ||
| 18287 | + let want = if ten_bit { | ||
| 18288 | + ffmpeg_decode_sequence_10bit(&stream, width, height, 1) | ||
| 18289 | + } else { | ||
| 18290 | + ffmpeg_decode_sequence(&stream, width, height, 1) | ||
| 18291 | + }; | ||
| 18292 | + assert_eq!(frames.len(), 1); | ||
| 18293 | + for (i, (got, want)) in frames.iter().zip(&want).enumerate() { | ||
| 18294 | + for (name, a, b, w) in [ | ||
| 18295 | + ("Y", &got.y, &want.y, width), | ||
| 18296 | + ("U", &got.u, &want.u, width / 2), | ||
| 18297 | + ("V", &got.v, &want.v, width / 2), | ||
| 18298 | + ] { | ||
| 18299 | + let n = a.iter().zip(b.iter()).filter(|(x, y)| x != y).count(); | ||
| 18300 | + let first = a.iter().zip(b.iter()).position(|(x, y)| x != y); | ||
| 18301 | + assert_eq!( | ||
| 18302 | + n, 0, | ||
| 18303 | + "{NAME} frame {i} {name} vs ffmpeg (seed {seed}): {n} differ, first row {} col {} ours {:?} ffmpeg {:?}", | ||
| 18304 | + first.unwrap_or(0) / w, | ||
| 18305 | + first.unwrap_or(0) % w, | ||
| 18306 | + first.map(|k| a[k]), | ||
| 18307 | + first.map(|k| b[k]), | ||
| 18308 | + ); | ||
| 18309 | + } | ||
| 18310 | + } | ||
| 18311 | + let hits = crate::decode::part128_none_hits() - before; | ||
| 18312 | + eprintln!("seed {seed} cq {cq} {width}x{height}: part128_none_hits +{hits}"); | ||
| 18313 | + if hits > 0 { | ||
| 18314 | + none_arms += 1; | ||
| 18315 | + } | ||
| 18316 | + matched += 1; | ||
| 18317 | + } | ||
| 18318 | + assert!( | ||
| 18319 | + matched > 0, | ||
| 18320 | + "{NAME}: every attempt refused; the gate never decoded a stream" | ||
| 18321 | + ); | ||
| 18322 | + assert!( | ||
| 18323 | + none_arms > 0, | ||
| 18324 | + "{NAME}: {matched} stream(s) decoded pixel-exact but NOT ONE 128 root was \ | ||
| 18325 | + PARTITION_NONE -- the arm this gate exists for never fired" | ||
| 18326 | + ); | ||
| 18327 | + eprintln!( | ||
| 18328 | + "{NAME}: {matched} pixel-exact ({none_arms} with a 128 NONE root), \ | ||
| 18329 | + {named_refusals} named refusals, part128_none_hits={}", | ||
| 18330 | + crate::decode::part128_none_hits() | ||
| 18331 | + ); | ||
| 18332 | + } | ||
| 18333 | + | ||
| 18178 | #[test] | 18334 | #[test] |
| 18179 | #[ignore = "lane-sb128 r2 diagnostic: is the frame-6 mismatch sb128-specific?"] | 18335 | #[ignore = "lane-sb128 r2 diagnostic: is the frame-6 mismatch sb128-specific?"] |
| 18180 | fn sb128_r2_control_sb64() { | 18336 | 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. | ||