Merge 04743eff (rect128recon) — suite green: rect128recon 628/0
Browse files at this commit22 changed files +2788 -163
- crates/ec-av1/examples/decode_probe.rs +8 -0
- crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu +0 -0
- crates/ec-av1/fixtures/ll444_minp64_inter.obu +0 -0
- crates/ec-av1/fixtures/ll444_minp8_inter.obu +0 -0
- crates/ec-av1/src/decode.rs +902 -163
- crates/ec-av1/src/encode.rs +2 -0
- crates/ec-av1/src/stream.rs +491 -0
- lanes/av1422filter.report.md +109 -0
- lanes/av1444sb.report.md +115 -0
- lanes/av1444sbf2.report.md +74 -0
- lanes/av1ll64.report.md +108 -0
- lanes/av1llband2.report.md +90 -0
- lanes/av1llinter2.report.md +101 -0
- lanes/av1llintra.report.md +93 -0
- lanes/av1llintra8.report.md +105 -0
- lanes/av1llkf.report.md +97 -0
- lanes/av1llpred.report.md +80 -0
- lanes/av1llpred2.report.md +62 -0
- lanes/av1llpredgate2.report.md +87 -0
- lanes/av1llsub8.report.md +84 -0
- lanes/av1llsub8b.report.md +92 -0
- lanes/av1rect128recon.report.md +88 -0
crates/ec-av1/examples/decode_probe.rsmodified+8 -0
| @@ -105,6 +105,10 @@ fn main() { | ||
| 105 | 105 | ); |
| 106 | 106 | let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits(); |
| 107 | 107 | println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}"); |
| 108 | + println!( | |
| 109 | + "llintra8_chroma_walk: {}", | |
| 110 | + ec_av1::decode::llintra8_chroma_walk_hits() | |
| 111 | + ); | |
| 108 | 112 | let si = ec_av1::stream::sub8_intra_rect_hits(); |
| 109 | 113 | println!( |
| 110 | 114 | "sub8_intra_rect: horz8x4={} vert4x8={} chroma_ref={} mixed={} split4x4={}", |
| @@ -216,6 +220,10 @@ fn main() { | ||
| 216 | 220 | ec_av1::decode::chroma_edge_tu_clip_hits(), |
| 217 | 221 | ec_av1::decode::skip_lossless_band_reset_hits(), |
| 218 | 222 | ); |
| 223 | + println!( | |
| 224 | + "llband: rect_split_lossless_chroma444={}", | |
| 225 | + ec_av1::decode::rect_split_lossless_chroma444_hits() | |
| 226 | + ); | |
| 219 | 227 | // lane-t900 r12: chroma edge-filter neighbour answered from the mi-granular |
| 220 | 228 | // uv_mode grid instead of the coarse one-slot-per-column map. |
| 221 | 229 | println!( |
crates/ec-av1/fixtures/444_sb128rect_lr_witness.obuadded+0 -0
Binary file changed
crates/ec-av1/fixtures/ll444_minp64_inter.obuadded+0 -0
Binary file changed
crates/ec-av1/fixtures/ll444_minp8_inter.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+902 -163
| @@ -486,7 +486,15 @@ pub(crate) fn lossless_tx(px: usize, fctx: &crate::decode::FrameCtx) -> usize { | ||
| 486 | 486 | /// picks the 13-symbol one (class `wrong-alphabet-same-value`). |
| 487 | 487 | pub(crate) fn cfl_allowed_px(bw: usize, bh: usize, fctx: &crate::decode::FrameCtx) -> bool { |
| 488 | 488 | if lossless(fctx) { |
| 489 | - bw <= 8 && bh <= 8 | |
| 489 | + // `is_cfl_allowed`: at lossless CfL is available only when the | |
| 490 | + // partition size equals the transform size -- the CHROMA plane block | |
| 491 | + // must be a single TX_4X4. True for an 8x8 partition at 4:2:0 (its | |
| 492 | + // plane block is 4x4) and for 4x4 partitions; FALSE for an 8x8 | |
| 493 | + // partition at 4:4:4, whose plane block is 8x8 -- that partition | |
| 494 | + // reads the 13-symbol uv_mode CDF, and reading the CFL alphabet | |
| 495 | + // there desynced the tile from the leaf's own uv_mode symbol (class | |
| 496 | + // `wrong-alphabet-same-value`). | |
| 497 | + (bw >> ss_x(fctx)).max(4) == 4 && (bh >> ss_y(fctx)).max(4) == 4 | |
| 490 | 498 | } else { |
| 491 | 499 | bw <= 32 && bh <= 32 |
| 492 | 500 | } |
| @@ -5313,6 +5321,10 @@ thread_local! { | ||
| 5313 | 5321 | /// entropy bands were zeroed per unit (libaom `av1_reset_entropy_context`, |
| 5314 | 5322 | /// decodeframe.c:1262) instead of leaking the previous occupant's. |
| 5315 | 5323 | static SKIP_LOSSLESS_BAND_RESET_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 5324 | + /// lane-av1-llband: 4x4 chroma transform units a lossless HORZ/VERT strip | |
| 5325 | + /// walked at subsampling 0/0 (one unit per mi cell -- the geometry the | |
| 5326 | + /// hardcoded 4:2:0 span mis-stepped). | |
| 5327 | + static RECT_SPLIT_LOSSLESS_CHROMA444_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 5316 | 5328 | } |
| 5317 | 5329 | |
| 5318 | 5330 | /// How many skipped sub-8x8 chroma blocks carried a CfL alpha (the shape |
| @@ -5335,6 +5347,14 @@ pub fn skip_lossless_band_reset_hits() -> usize { | ||
| 5335 | 5347 | SKIP_LOSSLESS_BAND_RESET_HITS.with(|c| c.get()) |
| 5336 | 5348 | } |
| 5337 | 5349 | |
| 5350 | +/// How many 4x4 chroma transform units a lossless HORZ/VERT strip walked at | |
| 5351 | +/// subsampling 0/0 (lane-av1-llband). Zero means a stream never decoded the | |
| 5352 | +/// 4:4:4 lossless unit walk this counter proves -- a gate asserting the fix | |
| 5353 | +/// must see this nonzero. | |
| 5354 | +pub fn rect_split_lossless_chroma444_hits() -> usize { | |
| 5355 | + RECT_SPLIT_LOSSLESS_CHROMA444_HITS.with(|c| c.get()) | |
| 5356 | +} | |
| 5357 | + | |
| 5338 | 5358 | /// Gate-side reset for the two lane-av1-loss64 counters above. |
| 5339 | 5359 | pub fn reset_loss64_hits() { |
| 5340 | 5360 | CHROMA_EDGE_TU_CLIP_HITS.with(|c| c.set(0)); |
| @@ -8960,6 +8980,13 @@ impl Neighbours { | ||
| 8960 | 8980 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 8961 | 8981 | let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); |
| 8962 | 8982 | let state = neighbour_state(grid); |
| 8983 | + if crate::envflags::env_flag!("EC_CHROMA_PUB") { | |
| 8984 | + eprintln!( | |
| 8985 | + "EC_CHROMA_PUB plane={plane} mi=({mi_r},{mi_c}) wh=({w_px},{h_px}) lvl={} dc={}", | |
| 8986 | + state.level, | |
| 8987 | + state.dc.map_or(-1, |s| i32::from(s)) | |
| 8988 | + ); | |
| 8989 | + } | |
| 8963 | 8990 | for cell in 0..(h_px / MI).min(bound_h.saturating_sub(mi_r)) { |
| 8964 | 8991 | self.left[mi_r + cell][plane] = state; |
| 8965 | 8992 | } |
| @@ -10083,6 +10110,10 @@ fn decode_rect_split( | ||
| 10083 | 10110 | (4, 8) => Some((TxbSet::ChromaRect8x4, &SCAN_4X8[..])), |
| 10084 | 10111 | _ => None, |
| 10085 | 10112 | }; |
| 10113 | + // A 4:4:4 64-axis strip's chroma plane block is larger than one adjusted | |
| 10114 | + // UV transform (TX_64X32 adjusts to TX_32X32). Those sizes are tiled | |
| 10115 | + // below; everything else still needs a single-unit table. | |
| 10116 | + let chroma_tiled = matches!((chroma_w, chroma_h), (64, 32) | (32, 64) | (64, 16) | (16, 64)); | |
| 10086 | 10117 | if !m.skip { |
| 10087 | 10118 | if let Some(i) = match (chroma_w, chroma_h) { |
| 10088 | 10119 | (32, 8) => Some(0), |
| @@ -10099,11 +10130,24 @@ fn decode_rect_split( | ||
| 10099 | 10130 | }); |
| 10100 | 10131 | } |
| 10101 | 10132 | } |
| 10102 | - if chroma.is_none() { | |
| 10133 | + if chroma.is_none() && !chroma_tiled { | |
| 10103 | 10134 | // Diagnostic for the next caller that lands here (class |
| 10104 | 10135 | // refusal-names-a-correlate: the message names the tool, not the |
| 10105 | 10136 | // shape); the refusal below keeps its inventory-pinned wording. |
| 10106 | - eprintln!("EC_RECTCHROMA_GAP luma={bw}x{bh} tx={tx_w}x{tx_h} chroma={chroma_w}x{chroma_h}"); | |
| 10137 | + // The condition is the refusal's exact precondition, so the | |
| 10138 | + // print can never fire without the refusal (or vice versa): the | |
| 10139 | + // four 64-axis chroma shapes are tiled below and at LOSSLESS the | |
| 10140 | + // 4x4 walk never consults `chroma` at all -- libaom has no such | |
| 10141 | + // transform to name a row for (`av1_get_tx_size` returns TX_4X4 | |
| 10142 | + // for every plane at lossless, blockd.h:1383; outside it | |
| 10143 | + // `av1_get_adjusted_tx_size` collapses TX_64X32/32X64 to TX_32X32 | |
| 10144 | + // for chroma, blockd.h:1361-1367). lane-av1-ll64: the old | |
| 10145 | + // ungated print fired on those working routes and mislabelled | |
| 10146 | + // them a gap (one lane report cited it as a decode stop). | |
| 10147 | + eprintln!( | |
| 10148 | + "EC_RECTCHROMA_GAP luma={bw}x{bh} tx={tx_w}x{tx_h} \ | |
| 10149 | + chroma={chroma_w}x{chroma_h} libaom_lossless_tx=none" | |
| 10150 | + ); | |
| 10107 | 10151 | } |
| 10108 | 10152 | } |
| 10109 | 10153 | // lane-rectsplit r2 (verifier finding): with both callers wired |
| @@ -10113,10 +10157,6 @@ fn decode_rect_split( | ||
| 10113 | 10157 | // caller -- a new strip size would otherwise hit the `expect` below and |
| 10114 | 10158 | // panic instead of refusing by name -- and so stays in |
| 10115 | 10159 | // `refusal_inventory::REFUSALS`. |
| 10116 | - // A 4:4:4 64-axis strip's chroma plane block is larger than one adjusted | |
| 10117 | - // UV transform (TX_64X32 adjusts to TX_32X32). Those sizes are tiled | |
| 10118 | - // below; everything else still needs a single-unit table. | |
| 10119 | - let chroma_tiled = matches!((chroma_w, chroma_h), (64, 32) | (32, 64) | (64, 16) | (16, 64)); | |
| 10120 | 10160 | if !m.skip && chroma.is_none() && !chroma_tiled { |
| 10121 | 10161 | return Err(unsupported( |
| 10122 | 10162 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", |
| @@ -10395,7 +10435,7 @@ fn decode_rect_split( | ||
| 10395 | 10435 | // them with the LAST unit's state (class `override-slot-on-one-arm`: the |
| 10396 | 10436 | // next block then read `dc_sign_ctx` 1 where libaom reads 0). They are |
| 10397 | 10437 | // collected here and replayed after that record. |
| 10398 | - let mut ll_chroma_units: Vec<((usize, usize), usize, Grid)> = Vec::new(); | |
| 10438 | + let mut ll_chroma_units: Vec<((usize, usize), usize, Grid, usize, usize)> = Vec::new(); | |
| 10399 | 10439 | // The chroma_tiled arm below stamps each unit's coefficient context |
| 10400 | 10440 | // immediately (so the NEXT unit reads it), then the whole-strip |
| 10401 | 10441 | // `record_split_luma_rect_mi` rewrites every chroma cell with ONE |
| @@ -10443,19 +10483,29 @@ fn decode_rect_split( | ||
| 10443 | 10483 | let scan4 = default_scan(4); |
| 10444 | 10484 | let offset = (chroma_w > 4 || chroma_h > 4).then_some(3); |
| 10445 | 10485 | let (cw_n, ch_n) = (chroma_w / 4, chroma_h / 4); |
| 10486 | + // lane-av1-llband: one 4x4 chroma unit's extent in LUMA pixels -- 4 | |
| 10487 | + // chroma px scaled by the plane's own subsampling. The hardcoded 8 | |
| 10488 | + // was the 4:2:0 unit's span; at 4:4:4 a unit is 4x4 LUMA px (one mi | |
| 10489 | + // cell), and the 8-px step made every unit past the first column/row | |
| 10490 | + // read its `txb_skip` context at the WRONG mi (two cells over) and | |
| 10491 | + // stamp a 2-cell span with one unit's state -- the polluted above-band | |
| 10492 | + // cell behind a 16x8 leaf's U bc=2 unit of the 444 lossless key frame | |
| 10493 | + // (measured: oracle `EC_DBGCTX` reads 1-cell spans at 1-mi steps; | |
| 10494 | + // ours read `above[28..29]` where the oracle read `above[26]`). | |
| 10495 | + let span_x = 4 << ss_x(fctx); | |
| 10496 | + let span_y = 4 << ss_y(fctx); | |
| 10446 | 10497 | let mut last = [Grid::Zero(16), Grid::Zero(16)]; |
| 10447 | 10498 | for plane_idx in 1..=2 { |
| 10448 | 10499 | for cu_row in 0..ch_n { |
| 10449 | 10500 | for cu_col in 0..cw_n { |
| 10450 | - let luma_span = 8; | |
| 10451 | 10501 | let cu_mi = ( |
| 10452 | - mi_r + cu_row * (luma_span / MI), | |
| 10453 | - mi_c + cu_col * (luma_span / MI), | |
| 10502 | + mi_r + cu_row * (span_y / MI), | |
| 10503 | + mi_c + cu_col * (span_x / MI), | |
| 10454 | 10504 | ); |
| 10455 | - let cu_around = neighbours.around_mi(cu_mi, luma_span); | |
| 10505 | + let cu_around = neighbours.around_mi_rect(cu_mi, span_x, span_y); | |
| 10456 | 10506 | let cu_reach = tu_reach( |
| 10457 | 10507 | bw, bh, |
| 10458 | - cu_col * luma_span, cu_row * luma_span, luma_span, | |
| 10508 | + cu_col * span_x, cu_row * span_y, span_x, | |
| 10459 | 10509 | block_reach, px, py, y.width, y.height, fctx, |
| 10460 | 10510 | ); |
| 10461 | 10511 | let (cu_x, cu_y) = (cpx + cu_col * 4, cpy + cu_row * 4); |
| @@ -10477,8 +10527,11 @@ fn decode_rect_split( | ||
| 10477 | 10527 | }), |
| 10478 | 10528 | None, offset, m.smooth_neighbor_uv, fctx, |
| 10479 | 10529 | )?; |
| 10480 | - neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, plane_idx, &grid); | |
| 10481 | - ll_chroma_units.push((cu_mi, plane_idx, grid.clone())); | |
| 10530 | + if span_x == 4 && span_y == 4 { | |
| 10531 | + hit!(RECT_SPLIT_LOSSLESS_CHROMA444_HITS); | |
| 10532 | + } | |
| 10533 | + neighbours.record_mi_chroma(cu_mi, span_x, span_y, plane_idx, &grid); | |
| 10534 | + ll_chroma_units.push((cu_mi, plane_idx, grid.clone(), span_x, span_y)); | |
| 10482 | 10535 | last[plane_idx - 1] = grid; |
| 10483 | 10536 | } |
| 10484 | 10537 | } |
| @@ -10650,8 +10703,8 @@ fn decode_rect_split( | ||
| 10650 | 10703 | m.uv_predict_mode, |
| 10651 | 10704 | [&u_grid, &v_grid], |
| 10652 | 10705 | ); |
| 10653 | - for (cu_mi, plane, unit) in &ll_chroma_units { | |
| 10654 | - neighbours.record_mi_chroma(*cu_mi, 8, 8, *plane, unit); | |
| 10706 | + for (cu_mi, plane, unit, span_w, span_h) in &ll_chroma_units { | |
| 10707 | + neighbours.record_mi_chroma(*cu_mi, *span_w, *span_h, *plane, unit); | |
| 10655 | 10708 | } |
| 10656 | 10709 | for (cu_mi, plane, unit, span_w, span_h) in &tiled_chroma_units { |
| 10657 | 10710 | neighbours.record_mi_chroma(*cu_mi, *span_w, *span_h, *plane, unit); |
| @@ -14595,9 +14648,16 @@ fn decode_rect4_16_strip( | ||
| 14595 | 14648 | angle_delta_uv, cu_reach, &ZERO_RESIDUAL[..16], None, None, |
| 14596 | 14649 | smooth_neighbor_uv, fctx, |
| 14597 | 14650 | ); |
| 14598 | - let cu_mi = (pair_mi.0 + oy / 2, pair_mi.1 + ox / 2); | |
| 14651 | + let cu_mi = ( | |
| 14652 | + pair_mi.0 + (oy << ss_y(fctx)) / MI, | |
| 14653 | + pair_mi.1 + (ox << ss_x(fctx)) / MI, | |
| 14654 | + ); | |
| 14599 | 14655 | neighbours.record_mi_chroma( |
| 14600 | - cu_mi, 8, 8, plane, &ZERO_RESIDUAL[..16], | |
| 14656 | + cu_mi, | |
| 14657 | + 4 << ss_x(fctx), | |
| 14658 | + 4 << ss_y(fctx), | |
| 14659 | + plane, | |
| 14660 | + &ZERO_RESIDUAL[..16], | |
| 14601 | 14661 | ); |
| 14602 | 14662 | } |
| 14603 | 14663 | } |
| @@ -14617,7 +14677,25 @@ fn decode_rect4_16_strip( | ||
| 14617 | 14677 | if cpx + ox >= u.true_width || cpy + oy >= u.true_height { |
| 14618 | 14678 | continue; |
| 14619 | 14679 | } |
| 14620 | - let cu_mi = (pair_mi.0 + oy / 2, pair_mi.1 + ox / 2); | |
| 14680 | + // The unit's stamp is its own span: aom | |
| 14681 | + // `av1_set_entropy_contexts` (blockd.c:29) | |
| 14682 | + // memsets exactly `tx_size_wide_unit` x | |
| 14683 | + // `tx_size_high_unit` cells at the unit's own | |
| 14684 | + // `(aoff, loff)` -- for TX_4X4 ONE above cell | |
| 14685 | + // and ONE left cell. `(oy / 2, ox / 2)` + | |
| 14686 | + // `(8, 8)` is the 4:2:0 subsampled form (one | |
| 14687 | + // chroma cell = 8 luma px = 2 mi cells); at | |
| 14688 | + // 4:4:4 a unit is ONE mi cell, and the 2x2 | |
| 14689 | + // smear let a 4-wide strip's later units | |
| 14690 | + // overwrite the NEXT COLUMN's above cell with | |
| 14691 | + // their own state -- a column aom never sees | |
| 14692 | + // this block write -- so the following block's | |
| 14693 | + // `all_zero` read the wrong `txb_skip` row | |
| 14694 | + // (frame-0 read #452, the llkf named gap). | |
| 14695 | + let cu_mi = ( | |
| 14696 | + pair_mi.0 + (oy << ss_y(fctx)) / MI, | |
| 14697 | + pair_mi.1 + (ox << ss_x(fctx)) / MI, | |
| 14698 | + ); | |
| 14621 | 14699 | // One luma-mi cell: the chroma entropy arrays |
| 14622 | 14700 | // are subsampled, and our bands replicate that |
| 14623 | 14701 | // one entry over the unit's two cells |
| @@ -14639,7 +14717,13 @@ fn decode_rect4_16_strip( | ||
| 14639 | 14717 | cu_reach, buf, cpx + ox, cpy + oy, 4, 4, base_q_idx, |
| 14640 | 14718 | None, None, offset, smooth_neighbor_uv, fctx, |
| 14641 | 14719 | )?; |
| 14642 | - neighbours.record_mi_chroma(cu_mi, 8, 8, plane, &cu_grid); | |
| 14720 | + neighbours.record_mi_chroma( | |
| 14721 | + cu_mi, | |
| 14722 | + 4 << ss_x(fctx), | |
| 14723 | + 4 << ss_y(fctx), | |
| 14724 | + plane, | |
| 14725 | + &cu_grid, | |
| 14726 | + ); | |
| 14643 | 14727 | hit!(CHROMA_SPLIT_TX_HITS); |
| 14644 | 14728 | let dst = if plane == 1 { &mut uo } else { &mut vo }; |
| 14645 | 14729 | for row in 0..4 { |
| @@ -17279,9 +17363,17 @@ fn decode_block( | ||
| 17279 | 17363 | (2 * y.true_width.div_ceil(8)) as i32 - mi_c as i32 - span_mi as i32; |
| 17280 | 17364 | let over_h_mi = |
| 17281 | 17365 | (2 * y.true_height.div_ceil(8)) as i32 - mi_r as i32 - span_mi as i32; |
| 17282 | - let plane_px = ((span_mi * 2).max(4)) as i32; | |
| 17283 | - let max_units_w = ((plane_px + 2 * over_w_mi.min(0)) >> 2).max(0) as usize; | |
| 17284 | - let max_units_h = ((plane_px + 2 * over_h_mi.min(0)) >> 2).max(0) as usize; | |
| 17366 | + // `max_block_wide/high` in chroma pixels: the plane block's | |
| 17367 | + // own span (`side` at 4:4:4, `side / 2` at 4:2:0 -- the old | |
| 17368 | + // hardcoded `span_mi * 2` clipped three quarters of a 4:4:4 | |
| 17369 | + // block's coded units and desynced the tile) plus the | |
| 17370 | + // negative overhang (`mb_to_*_edge >> (3 + ss)`), whose | |
| 17371 | + // chroma-px scale is `MI >> ss` per mi. | |
| 17372 | + let plane_px = (((span_mi * MI) >> ss_x(fctx)).max(4)) as i32; | |
| 17373 | + let over_w_px = over_w_mi.min(0) * (MI >> ss_x(fctx)) as i32; | |
| 17374 | + let over_h_px = over_h_mi.min(0) * (MI >> ss_y(fctx)) as i32; | |
| 17375 | + let max_units_w = ((plane_px + over_w_px) >> 2).max(0) as usize; | |
| 17376 | + let max_units_h = ((plane_px + over_h_px) >> 2).max(0) as usize; | |
| 17285 | 17377 | let unit = chroma_tx / 4; // TU side in 4x4 chroma units |
| 17286 | 17378 | if cu_col * unit >= max_units_w || cu_row * unit >= max_units_h { |
| 17287 | 17379 | hit!(CHROMA_EDGE_TU_CLIP_HITS); |
| @@ -17627,8 +17719,16 @@ fn decode_block_128rect( | ||
| 17627 | 17719 | let mi_rows = 2 * y.true_height.div_ceil(8); |
| 17628 | 17720 | let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(mi_c)); |
| 17629 | 17721 | let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(mi_r)); |
| 17630 | - // Non-lossless: one 32x32 chroma unit per mu chunk, per plane. | |
| 17631 | - debug_assert!(lossless_frame || (chroma_w / chroma_tx, chroma_h / chroma_tx) == (nch_x, nch_y)); | |
| 17722 | + // Non-lossless: per mu chunk, `(64 >> ss) / chroma_tx` chroma units per | |
| 17723 | + // axis (one 32x32 at 4:2:0, four 32x32 at 4:4:4 — lane-av1-444sb). | |
| 17724 | + debug_assert!( | |
| 17725 | + lossless_frame | |
| 17726 | + || (chroma_w / chroma_tx, chroma_h / chroma_tx) | |
| 17727 | + == ( | |
| 17728 | + nch_x * ((64 >> ss_x(fctx)) / chroma_tx), | |
| 17729 | + nch_y * ((64 >> ss_y(fctx)) / chroma_tx) | |
| 17730 | + ) | |
| 17731 | + ); | |
| 17632 | 17732 | let tpc = 64 / logical_tx; |
| 17633 | 17733 | let zero_tu = vec![0i32; logical_tx * logical_tx]; |
| 17634 | 17734 | let zero_cu = vec![0i32; chroma_tx * chroma_tx]; |
| @@ -17706,9 +17806,13 @@ fn decode_block_128rect( | ||
| 17706 | 17806 | neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid); |
| 17707 | 17807 | } |
| 17708 | 17808 | } |
| 17709 | - // Transform units per axis inside this mu chunk's 32x32 chroma | |
| 17710 | - // span: one 32x32 unit normally, 8x8 TX_4X4 units when lossless. | |
| 17711 | - let cn = (32 / chroma_tx).max(1); | |
| 17809 | + // Transform units per axis inside this mu chunk's chroma span: | |
| 17810 | + // a 64x64 luma chunk covers `64 >> ss` chroma pixels per axis, so | |
| 17811 | + // it holds `(64 >> ss) / chroma_tx` units — one 32x32 at 4:2:0, | |
| 17812 | + // four at 4:4:4 (lane-av1-444sb: the hardcoded 4:2:0 span read | |
| 17813 | + // one unit per chunk there, left six of a 128x64 block's eight | |
| 17814 | + // 32x32 units unread and desynced the tile from that block on). | |
| 17815 | + let cn = ((64 >> ss_x(fctx)) / chroma_tx).max(1); | |
| 17712 | 17816 | // libaom's per-chunk `unit_width/height` (plane-mi units of the |
| 17713 | 17817 | // luma mi grid): `min(mu_blocks + col, max_blocks) >> ss`. |
| 17714 | 17818 | let unit_w = ((ch_col + 1) * 16).min(max_w_mi) >> ss_x(fctx); |
| @@ -17722,13 +17826,13 @@ fn decode_block_128rect( | ||
| 17722 | 17826 | for plane_pass in 1..=2usize { |
| 17723 | 17827 | for ci_row in 0..cn { |
| 17724 | 17828 | for ci_col in 0..cn { |
| 17725 | - if ch_col * 8 + ci_col * stepc >= unit_w | |
| 17726 | - || ch_row * 8 + ci_row * stepc >= unit_h | |
| 17829 | + if ch_col * (16 >> ss_x(fctx)) + ci_col * stepc >= unit_w | |
| 17830 | + || ch_row * (16 >> ss_y(fctx)) + ci_row * stepc >= unit_h | |
| 17727 | 17831 | { |
| 17728 | 17832 | continue; |
| 17729 | 17833 | } |
| 17730 | - let cu_x = cpx + ch_col * 32 + ci_col * chroma_tx; | |
| 17731 | - let cu_y = cpy + ch_row * 32 + ci_row * chroma_tx; | |
| 17834 | + let cu_x = cpx + ch_col * (64 >> ss_x(fctx)) + ci_col * chroma_tx; | |
| 17835 | + let cu_y = cpy + ch_row * (64 >> ss_y(fctx)) + ci_row * chroma_tx; | |
| 17732 | 17836 | let cu_mi = ( |
| 17733 | 17837 | mi_r + ch_row * 16 + ci_row * ((chroma_tx << ss_y(fctx)) / 4), |
| 17734 | 17838 | mi_c + ch_col * 16 + ci_col * ((chroma_tx << ss_x(fctx)) / 4), |
| @@ -18169,12 +18273,45 @@ fn decode_leaf8( | ||
| 18169 | 18273 | ); |
| 18170 | 18274 | } |
| 18171 | 18275 | let ac = alpha.map(|_| cfl_src(px, py, 8)); |
| 18276 | + // 4:4:4 lossless: the leaf's chroma plane block is a 2x2 raster of | |
| 18277 | + // TX_4X4 units (`av1_get_tx_size`: lossless forces TX_4X4 on EVERY | |
| 18278 | + // plane), so a skipped leaf predicts per unit -- each from its own | |
| 18279 | + // edges -- like the luma `SKIP_SPLIT_TX` loop above. CfL never fires | |
| 18280 | + // here (`is_cfl_allowed` at lossless needs plane_bsize == 4x4; this | |
| 18281 | + // chroma plane block is 8x8), and intrabc/palette keep the | |
| 18282 | + // whole-plane-block prediction they already run. | |
| 18283 | + let chroma_units_444 = chroma_444 | |
| 18284 | + && lossless(fctx) | |
| 18285 | + && intrabc_bufs.is_none() | |
| 18286 | + && palette_uv_bufs.is_none(); | |
| 18172 | 18287 | if let Some((_, ub, _)) = &intrabc_bufs { |
| 18173 | 18288 | set_palette_pred(ub.clone(), fctx); |
| 18174 | 18289 | } else if let Some((ub, _)) = &palette_uv_bufs { |
| 18175 | 18290 | set_palette_pred(ub.clone(), fctx); |
| 18176 | 18291 | } |
| 18177 | - push_intra(1, | |
| 18292 | + if chroma_units_444 { | |
| 18293 | + for cu_row in 0..2 { | |
| 18294 | + for cu_col in 0..2 { | |
| 18295 | + let cu_reach = tu_reach( | |
| 18296 | + 8, 8, cu_col * 4, cu_row * 4, 4, | |
| 18297 | + reach, px, py, y.width, y.height, fctx, | |
| 18298 | + ); | |
| 18299 | + push_intra(1, | |
| 18300 | + cpx + cu_col * 4, | |
| 18301 | + cpy + cu_row * 4, | |
| 18302 | + 4, | |
| 18303 | + uv_predict_mode, | |
| 18304 | + angle_delta_uv, | |
| 18305 | + cu_reach, | |
| 18306 | + &ZERO_RESIDUAL[..16], | |
| 18307 | + None, | |
| 18308 | + None, | |
| 18309 | + smooth_neighbor_uv, fctx, | |
| 18310 | + ); | |
| 18311 | + } | |
| 18312 | + } | |
| 18313 | + } else { | |
| 18314 | + push_intra(1, | |
| 18178 | 18315 | cpx, |
| 18179 | 18316 | cpy, |
| 18180 | 18317 | csz, |
| @@ -18186,12 +18323,35 @@ fn decode_leaf8( | ||
| 18186 | 18323 | None, |
| 18187 | 18324 | smooth_neighbor_uv, fctx, |
| 18188 | 18325 | ); |
| 18326 | + } | |
| 18189 | 18327 | if let Some((_, _, vb)) = &intrabc_bufs { |
| 18190 | 18328 | set_palette_pred(vb.clone(), fctx); |
| 18191 | 18329 | } else if let Some((_, vb)) = &palette_uv_bufs { |
| 18192 | 18330 | set_palette_pred(vb.clone(), fctx); |
| 18193 | 18331 | } |
| 18194 | - push_intra(2, | |
| 18332 | + if chroma_units_444 { | |
| 18333 | + for cu_row in 0..2 { | |
| 18334 | + for cu_col in 0..2 { | |
| 18335 | + let cu_reach = tu_reach( | |
| 18336 | + 8, 8, cu_col * 4, cu_row * 4, 4, | |
| 18337 | + reach, px, py, y.width, y.height, fctx, | |
| 18338 | + ); | |
| 18339 | + push_intra(2, | |
| 18340 | + cpx + cu_col * 4, | |
| 18341 | + cpy + cu_row * 4, | |
| 18342 | + 4, | |
| 18343 | + uv_predict_mode, | |
| 18344 | + angle_delta_uv, | |
| 18345 | + cu_reach, | |
| 18346 | + &ZERO_RESIDUAL[..16], | |
| 18347 | + None, | |
| 18348 | + None, | |
| 18349 | + smooth_neighbor_uv, fctx, | |
| 18350 | + ); | |
| 18351 | + } | |
| 18352 | + } | |
| 18353 | + } else { | |
| 18354 | + push_intra(2, | |
| 18195 | 18355 | cpx, |
| 18196 | 18356 | cpy, |
| 18197 | 18357 | csz, |
| @@ -18203,6 +18363,7 @@ fn decode_leaf8( | ||
| 18203 | 18363 | None, |
| 18204 | 18364 | smooth_neighbor_uv, fctx, |
| 18205 | 18365 | ); |
| 18366 | + } | |
| 18206 | 18367 | luma_grid = Grid::Zero(64); |
| 18207 | 18368 | u_grid = Grid::Zero(csz * csz); |
| 18208 | 18369 | v_grid = Grid::Zero(csz * csz); |
| @@ -18416,6 +18577,28 @@ fn decode_leaf8( | ||
| 18416 | 18577 | if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { |
| 18417 | 18578 | hit!(INTRABC_TX4_CHROMA_COPY_HITS); |
| 18418 | 18579 | } |
| 18580 | + if chroma_444 && lossless(fctx) { | |
| 18581 | + // 4:4:4 lossless: the leaf's chroma plane block is a 2x2 raster | |
| 18582 | + // of TX_4X4 units per plane, PLANE-MAJOR (`av1_get_tx_size`: | |
| 18583 | + // lossless forces TX_4X4 on EVERY plane) -- the same walk | |
| 18584 | + // `read_intra_chroma_lossless` runs for whole blocks. Reading one | |
| 18585 | + // TX_8X8 unit here panicked before: the lossless inverse is the | |
| 18586 | + // 4x4-only WHT (`TxParams::run`'s own `(w, h) == (4, 4)` | |
| 18587 | + // invariant), and the unit count desyncs the tile either way. | |
| 18588 | + // Per-unit `record_mi_chroma` calls stamp the neighbour bands | |
| 18589 | + // inside, which is why the tail's whole-leaf chroma stamp below | |
| 18590 | + // is skipped for this shape. | |
| 18591 | + let (mut uo, mut vo) = (Vec::new(), Vec::new()); | |
| 18592 | + read_intra_chroma_lossless( | |
| 18593 | + dec, cdfs, neighbours, u, v, leaf_mi, (px, py), (cpx, cpy), | |
| 18594 | + 8, (8, 8), (0, 0), (8, 8), 8, reach, (y.width, y.height), mode, | |
| 18595 | + uv_predict_mode, angle_delta_uv, | |
| 18596 | + palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])), | |
| 18597 | + smooth_neighbor_uv, base_q_idx, &mut uo, &mut vo, fctx, | |
| 18598 | + )?; | |
| 18599 | + u_grid = if uo.is_empty() { Grid::Zero(64) } else { Grid::Own(uo) }; | |
| 18600 | + v_grid = if vo.is_empty() { Grid::Zero(64) } else { Grid::Own(vo) }; | |
| 18601 | + } else { | |
| 18419 | 18602 | if let Some((ub, _)) = &palette_uv_bufs { |
| 18420 | 18603 | set_palette_pred(ub.clone(), fctx); |
| 18421 | 18604 | } |
| @@ -18466,6 +18649,7 @@ fn decode_leaf8( | ||
| 18466 | 18649 | None, |
| 18467 | 18650 | smooth_neighbor_uv, fctx, |
| 18468 | 18651 | )?; |
| 18652 | + } | |
| 18469 | 18653 | // The two chroma reads above are the only consulters of this leaf's |
| 18470 | 18654 | // armed [`INTRABC_CHROMA_TX`]; leaving it set would make the NEXT |
| 18471 | 18655 | // leaf's chroma inherit this leaf's luma type instead of its own |
| @@ -18493,14 +18677,21 @@ fn decode_leaf8( | ||
| 18493 | 18677 | let bound_w = round_up_even(neighbours.mi_cols); |
| 18494 | 18678 | let u_state = neighbour_state(&u_grid); |
| 18495 | 18679 | let v_state = neighbour_state(&v_grid); |
| 18496 | - for cell in 0..side_mi { | |
| 18497 | - if cell < side_mi.min(bound_h.saturating_sub(leaf_mi.0)) { | |
| 18498 | - neighbours.left[leaf_mi.0 + cell][1] = u_state; | |
| 18499 | - neighbours.left[leaf_mi.0 + cell][2] = v_state; | |
| 18500 | - } | |
| 18501 | - if cell < side_mi.min(bound_w.saturating_sub(leaf_mi.1)) { | |
| 18502 | - neighbours.above[leaf_mi.1 + cell][1] = u_state; | |
| 18503 | - neighbours.above[leaf_mi.1 + cell][2] = v_state; | |
| 18680 | + // The 4:4:4 lossless walk above already stamped these bands PER UNIT | |
| 18681 | + // (its raster-order last writer per cell is exactly libaom's | |
| 18682 | + // per-entry last update); this whole-leaf aggregate would clobber | |
| 18683 | + // four distinct unit states with one, so it runs only for the shapes | |
| 18684 | + // whose chroma really is one unit. | |
| 18685 | + if !(chroma_444 && lossless(fctx)) { | |
| 18686 | + for cell in 0..side_mi { | |
| 18687 | + if cell < side_mi.min(bound_h.saturating_sub(leaf_mi.0)) { | |
| 18688 | + neighbours.left[leaf_mi.0 + cell][1] = u_state; | |
| 18689 | + neighbours.left[leaf_mi.0 + cell][2] = v_state; | |
| 18690 | + } | |
| 18691 | + if cell < side_mi.min(bound_w.saturating_sub(leaf_mi.1)) { | |
| 18692 | + neighbours.above[leaf_mi.1 + cell][1] = u_state; | |
| 18693 | + neighbours.above[leaf_mi.1 + cell][2] = v_state; | |
| 18694 | + } | |
| 18504 | 18695 | } |
| 18505 | 18696 | } |
| 18506 | 18697 | // This leaf's own palette state into the mi-granular above/left bands |
| @@ -18668,7 +18859,21 @@ fn read_intra_mode_sub8( | ||
| 18668 | 18859 | // desynced the tile at the very next element. |
| 18669 | 18860 | let angle_delta_y = 0; |
| 18670 | 18861 | let chroma = if has_chroma { |
| 18671 | - let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); | |
| 18862 | + // `is_cfl_allowed` (blockd.h): at lossless CfL needs the CHROMA plane | |
| 18863 | + // block to be a single TX_4X4 (`cfl_allowed_px`). True for this leaf | |
| 18864 | + // at 4:2:0 (the group's plane block is 4x4) and for a 4:4:4 | |
| 18865 | + // `BLOCK_4X4` split leaf, but FALSE for a 4:4:4 `BLOCK_8X4`/`BLOCK_4X8` | |
| 18866 | + // rect leaf, whose plane block is the rect itself -- that shape reads | |
| 18867 | + // the 13-symbol `uv_mode_no_cfl` CDF, and reading the CFL alphabet | |
| 18868 | + // there desynced the tile at the rect leaf's own uv_mode symbol (measured: | |
| 18869 | + // ours consumed the 14-symbol interval where the oracle read 13, first | |
| 18870 | + // divergence at the rect leaf mi (8,16) of `ll444.obu`; class | |
| 18871 | + // `wrong-alphabet-same-value`, lane-av1-llsub8). | |
| 18872 | + let uv_mode = if cfl_allowed_px(seg_w_mi * MI, seg_h_mi * MI, fctx) { | |
| 18873 | + dec.symbol(&mut cdfs.uv_mode_cfl[mode]) | |
| 18874 | + } else { | |
| 18875 | + dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) | |
| 18876 | + }; | |
| 18672 | 18877 | if trace { |
| 18673 | 18878 | eprintln!("TRACE sub8 uv_mode value={uv_mode} rng={}", dec.debug_state().0); |
| 18674 | 18879 | } |
| @@ -18736,7 +18941,7 @@ fn sub8_leaf_chroma444( | ||
| 18736 | 18941 | base_q_idx: u8, |
| 18737 | 18942 | smooth_neighbor_uv: bool, |
| 18738 | 18943 | fctx: &crate::decode::FrameCtx, |
| 18739 | -) -> Result<(Grid, Grid)> { | |
| 18944 | +) -> Result<(Grid, Grid, usize, usize)> { | |
| 18740 | 18945 | let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; |
| 18741 | 18946 | let (w_mi, h_mi) = (bw / MI, bh / MI); |
| 18742 | 18947 | neighbours.record_uv_mode_mi(lmi.0, lmi.1, w_mi, h_mi, uv_predict_mode); |
| @@ -18764,7 +18969,7 @@ fn sub8_leaf_chroma444( | ||
| 18764 | 18969 | hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); |
| 18765 | 18970 | fctx.intrabc_chroma_tx.with(|c| c.set(None)); |
| 18766 | 18971 | } |
| 18767 | - (Grid::Zero(bw * bh), Grid::Zero(bw * bh)) | |
| 18972 | + (Grid::Zero(bw * bh), Grid::Zero(bw * bh), 4, 4) | |
| 18768 | 18973 | } else if let Some(dv) = intrabc_dv { |
| 18769 | 18974 | // Frame copy at the DV; the residual still reads the ordinary chroma |
| 18770 | 18975 | // tables with the inherited luma `tx_type` (see the 4:2:0 tails). |
| @@ -18794,12 +18999,12 @@ fn sub8_leaf_chroma444( | ||
| 18794 | 18999 | 0, reach, v, px, py, 4, TX4, base_q_idx, |
| 18795 | 19000 | None, None, None, smooth_neighbor_uv, fctx, |
| 18796 | 19001 | )?; |
| 18797 | - (ug, vg) | |
| 19002 | + (ug, vg, 4, 4) | |
| 18798 | 19003 | } else { |
| 18799 | 19004 | let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 }; |
| 18800 | 19005 | let default_tx = |
| 18801 | 19006 | fctx.intrabc_chroma_tx.with(std::cell::Cell::get).unwrap_or(TxType::DctDct); |
| 18802 | - let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh)); | |
| 19007 | + let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh), bw, bh); | |
| 18803 | 19008 | for (plane_idx, buf) in [(1usize, ub), (2usize, vb)] { |
| 18804 | 19009 | let skip_ctx = |
| 18805 | 19010 | usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1); |
| @@ -18839,14 +19044,62 @@ fn sub8_leaf_chroma444( | ||
| 18839 | 19044 | 0, reach, v, px, py, 4, TX4, base_q_idx, |
| 18840 | 19045 | alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx, |
| 18841 | 19046 | )?; |
| 18842 | - (ug, vg) | |
| 19047 | + (ug, vg, 4, 4) | |
| 19048 | + } else if lossless(fctx) { | |
| 19049 | + // lane-av1-llsub8: `read_tx_size` answers TX_4X4 for EVERY plane of | |
| 19050 | + // a lossless block, so this rect leaf's chroma is (bw/4)*(bh/4) | |
| 19051 | + // TX_4X4 units at their own 4x4 origins -- not the single | |
| 19052 | + // TX_8X4/TX_4X8 rect unit the non-lossless arm below reads (that | |
| 19053 | + // one is `av1_get_max_uv_txsize(BLOCK_8X4)`'s rect transform, which | |
| 19054 | + // lossless never reaches). Measured on `ll444.obu`'s HORZ leaf at | |
| 19055 | + // mi (8,16): the oracle codes U units at bc 0,1 with | |
| 19056 | + // `get_txb_ctx`'s +10 rows (`txb_skip_cdf[0][10..12]`, | |
| 19057 | + // plane pels 32 > tx pels 16) where the rect-unit read consumed | |
| 19058 | + // `txb_skip_cdf[1][0]` -- the tile desynced at that U unit's | |
| 19059 | + // all_zero symbol. Walk is plane-major like libaom | |
| 19060 | + // `decode_token_recon_block`'s plane/row/col loop; each unit adds | |
| 19061 | + // 3 to the chroma context (Chroma4's `big` rows, the same fold | |
| 19062 | + // [`read_plane`]'s 128x128 caller uses); CFL is never allowed at | |
| 19063 | + // lossless, so no alpha rides along. | |
| 19064 | + let mut out_u = Grid::Own(vec![0i32; bw * bh]); | |
| 19065 | + let mut out_v = Grid::Own(vec![0i32; bw * bh]); | |
| 19066 | + for (plane_idx, buf) in [(1usize, u), (2usize, v)] { | |
| 19067 | + for ur in 0..bh / 4usize { | |
| 19068 | + for uc in 0..bw / 4usize { | |
| 19069 | + let (umi_r, umi_c) = (lmi.0 + ur, lmi.1 + uc); | |
| 19070 | + let (upx, upy) = (px + uc * 4, py + ur * 4); | |
| 19071 | + let unit_around = neighbours.around_mi_rect((umi_r, umi_c), 4, 4); | |
| 19072 | + let unit_reach = Reach::of(4, upx, upy, y.width, y.height, fctx); | |
| 19073 | + let grid = read_plane( | |
| 19074 | + dec, cdfs, TxbSet::Chroma4, scan4, plane_idx, unit_around[plane_idx], | |
| 19075 | + uv_mode, uv_predict_mode, 0, unit_reach, buf, upx, upy, 4, | |
| 19076 | + TX4, base_q_idx, None, None, Some(3), smooth_neighbor_uv, fctx, | |
| 19077 | + )?; | |
| 19078 | + let cell = grid_unit_state(&grid, 4, 0, 0, 4, 4); | |
| 19079 | + if umi_r < neighbours.mi_rows { | |
| 19080 | + neighbours.left[umi_r][plane_idx] = cell; | |
| 19081 | + } | |
| 19082 | + if umi_c < neighbours.mi_cols { | |
| 19083 | + neighbours.above[umi_c][plane_idx] = cell; | |
| 19084 | + } | |
| 19085 | + let out = if plane_idx == 1 { &mut out_u } else { &mut out_v }; | |
| 19086 | + if let Grid::Own(v) = out { | |
| 19087 | + for r in 0..4usize { | |
| 19088 | + v[(ur * 4 + r) * bw + uc * 4..][..4] | |
| 19089 | + .copy_from_slice(&grid[r * 4..][..4]); | |
| 19090 | + } | |
| 19091 | + } | |
| 19092 | + } | |
| 19093 | + } | |
| 19094 | + } | |
| 19095 | + (out_u, out_v, 4, 4) | |
| 18843 | 19096 | } else { |
| 18844 | 19097 | // `av1_get_max_uv_txsize(BLOCK_4X8/8X4)` at ss 0/0 is the rect |
| 18845 | 19098 | // transform itself; its `tx_type` is mode-derived with the |
| 18846 | 19099 | // <32 set (`decode_rect_split`'s own rule for this shape). |
| 18847 | 19100 | let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 }; |
| 18848 | 19101 | let default_tx = default_intra_tx_type(uv_predict_mode as u8); |
| 18849 | - let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh)); | |
| 19102 | + let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh), bw, bh); | |
| 18850 | 19103 | for plane_idx in 1..=2usize { |
| 18851 | 19104 | let skip_ctx = |
| 18852 | 19105 | usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1); |
| @@ -18874,23 +19127,54 @@ fn sub8_leaf_chroma444( | ||
| 18874 | 19127 | } |
| 18875 | 19128 | }; |
| 18876 | 19129 | // libaom `av1_set_entropy_contexts` stamps above/left PER TRANSFORM UNIT: |
| 18877 | - // the leaf's own chroma span, not the 8x8 group's. | |
| 18878 | - let (u_grid, v_grid) = grids; | |
| 18879 | - let u_state = neighbour_state(&u_grid); | |
| 18880 | - let v_state = neighbour_state(&v_grid); | |
| 18881 | - for cell in 0..h_mi { | |
| 18882 | - if lmi.0 + cell < neighbours.mi_rows { | |
| 18883 | - neighbours.left[lmi.0 + cell][1] = u_state; | |
| 18884 | - neighbours.left[lmi.0 + cell][2] = v_state; | |
| 19130 | + // the leaf's own chroma span, not the 8x8 group's. A rect leaf's lossless | |
| 19131 | + // units (4x4) each carry their own state -- a 4:2:0-style whole-leaf smear | |
| 19132 | + // gave one unit's state to its neighbour's cells (lane-av1-llsub8). | |
| 19133 | + let (u_grid, v_grid, unit_w, unit_h) = grids; | |
| 19134 | + // One unit covers `unit_w/MI` mi columns and `unit_h/MI` mi rows (a 4x4 | |
| 19135 | + // unit: one cell each; the non-lossless rect unit: the whole leaf). | |
| 19136 | + let (uw_cells, uh_cells) = ((unit_w / MI).max(1), (unit_h / MI).max(1)); | |
| 19137 | + for ur in 0..h_mi / uh_cells { | |
| 19138 | + for uc in 0..w_mi / uw_cells { | |
| 19139 | + let (x0, y0) = (uc * unit_w, ur * unit_h); | |
| 19140 | + let us = grid_unit_state(&u_grid, bw, x0, y0, unit_w, unit_h); | |
| 19141 | + let vs = grid_unit_state(&v_grid, bw, x0, y0, unit_w, unit_h); | |
| 19142 | + for cell in 0..uh_cells { | |
| 19143 | + if lmi.0 + ur * uh_cells + cell < neighbours.mi_rows { | |
| 19144 | + neighbours.left[lmi.0 + ur * uh_cells + cell][1] = us; | |
| 19145 | + neighbours.left[lmi.0 + ur * uh_cells + cell][2] = vs; | |
| 19146 | + } | |
| 19147 | + } | |
| 19148 | + for cell in 0..uw_cells { | |
| 19149 | + if lmi.1 + uc * uw_cells + cell < neighbours.mi_cols { | |
| 19150 | + neighbours.above[lmi.1 + uc * uw_cells + cell][1] = us; | |
| 19151 | + neighbours.above[lmi.1 + uc * uw_cells + cell][2] = vs; | |
| 19152 | + } | |
| 19153 | + } | |
| 18885 | 19154 | } |
| 18886 | 19155 | } |
| 18887 | - for cell in 0..w_mi { | |
| 18888 | - if lmi.1 + cell < neighbours.mi_cols { | |
| 18889 | - neighbours.above[lmi.1 + cell][1] = u_state; | |
| 18890 | - neighbours.above[lmi.1 + cell][2] = v_state; | |
| 19156 | + Ok((u_grid, v_grid, unit_w, unit_h)) | |
| 19157 | +} | |
| 19158 | + | |
| 19159 | +/// [`neighbour_state`] over one `(unit_w x unit_h)` transform unit at offset | |
| 19160 | +/// `(x0, y0)` inside a `bw`-wide assembled chroma grid -- the per-unit stamp | |
| 19161 | +/// the rect arms need when a leaf carries more than one unit. | |
| 19162 | +fn grid_unit_state(grid: &Grid, bw: usize, x0: usize, y0: usize, unit_w: usize, unit_h: usize) -> Neighbour { | |
| 19163 | + let mut cul = 0u32; | |
| 19164 | + let mut dc = None; | |
| 19165 | + for r in 0..unit_h { | |
| 19166 | + for c in 0..unit_w { | |
| 19167 | + let v = grid[(y0 + r) * bw + x0 + c]; | |
| 19168 | + cul += v.unsigned_abs(); | |
| 19169 | + if r == 0 && c == 0 && v != 0 { | |
| 19170 | + dc = Some(v < 0); | |
| 19171 | + } | |
| 18891 | 19172 | } |
| 18892 | 19173 | } |
| 18893 | - Ok((u_grid, v_grid)) | |
| 19174 | + if cul == 0 { | |
| 19175 | + return Neighbour::default(); | |
| 19176 | + } | |
| 19177 | + Neighbour { level: cul.min(7) as u8, dc } | |
| 18894 | 19178 | } |
| 18895 | 19179 | |
| 18896 | 19180 | |
| @@ -20000,6 +20284,15 @@ const CDEF_DIRECTIONS: [[(i32, i32); 2]; 8] = [ | ||
| 20000 | 20284 | const CDEF_VERY_LARGE: i32 = 0x4000; |
| 20001 | 20285 | const CDEF_PRI_TAPS: [[i32; 2]; 2] = [[4, 2], [3, 3]]; |
| 20002 | 20286 | const CDEF_SEC_TAPS: [i32; 2] = [2, 1]; |
| 20287 | +/// lane-av1422filter: libaom `av1_cdef_filter_fb` (cdef_block.c) remaps the | |
| 20288 | +/// luma direction before filtering CHROMA whenever `xdec != ydec` — the | |
| 20289 | +/// direction grid lives on the subsampled chroma grid, so a direction found | |
| 20290 | +/// on the 8x8 luma block means a different line there. `conv422` applies | |
| 20291 | +/// under 4:2:2 (`xdec` set), `conv440` under its mirror (not expressible in | |
| 20292 | +/// the profiles this decoder accepts, kept for fidelity). 4:2:0 and 4:4:4 | |
| 20293 | +/// (`xdec == ydec`) take no remap, exactly as before this lane. | |
| 20294 | +const CDEF_DIR_CONV422: [usize; 8] = [7, 0, 2, 4, 5, 6, 6, 6]; | |
| 20295 | +const CDEF_DIR_CONV440: [usize; 8] = [1, 2, 2, 2, 3, 4, 6, 0]; | |
| 20003 | 20296 | |
| 20004 | 20297 | fn cdef_msb(x: i32) -> i32 { |
| 20005 | 20298 | 31 - x.leading_zeros() as i32 |
| @@ -24525,7 +24818,19 @@ fn cdef_band( | ||
| 24525 | 24818 | |
| 24526 | 24819 | let t_uv = i32::from(cdef.uv_pri_strength[sidx]) << coeff_shift; |
| 24527 | 24820 | let uv_sec_strength = i32::from(cdef.uv_sec_strength[sidx]) << coeff_shift; |
| 24528 | - let uv_dir = if t_uv != 0 { dir } else { 0 }; | |
| 24821 | + // lane-av1422filter: the chroma direction is the luma one | |
| 24822 | + // remapped through `conv422`/`conv440` under asymmetric | |
| 24823 | + // subsampling (see [`CDEF_DIR_CONV422`]); identical to the | |
| 24824 | + // raw luma direction for 4:2:0 and 4:4:4. | |
| 24825 | + let uv_dir = if t_uv != 0 { | |
| 24826 | + match (ss_x(fctx), ss_y(fctx)) { | |
| 24827 | + (1, 0) => CDEF_DIR_CONV422[dir], | |
| 24828 | + (0, 1) => CDEF_DIR_CONV440[dir], | |
| 24829 | + _ => dir, | |
| 24830 | + } | |
| 24831 | + } else { | |
| 24832 | + 0 | |
| 24833 | + }; | |
| 24529 | 24834 | let enable_primary_uv = t_uv != 0; |
| 24530 | 24835 | let enable_secondary_uv = uv_sec_strength != 0; |
| 24531 | 24836 | if let Some(w) = wrote.as_deref_mut() { |
| @@ -24728,8 +25033,11 @@ fn pipe_run( | ||
| 24728 | 25033 | let j = k - 2; |
| 24729 | 25034 | if let Some((sy2, su2, sv2)) = snap.as_mut() { |
| 24730 | 25035 | snap_band(sy2.data.to_mut(), y, 0, j * 64, (j + 1) * 64, cfg.cdef_on); |
| 24731 | - snap_band(su2.data.to_mut(), u, 1, j * 32, (j + 1) * 32, cfg.cdef_on); | |
| 24732 | - snap_band(sv2.data.to_mut(), v, 1, j * 32, (j + 1) * 32, cfg.cdef_on); | |
| 25036 | + // lane-av1422filter: chroma band rows follow the frame's ss_y | |
| 25037 | + // (4:2:2 chroma bands the luma 64-row grid, not 32). | |
| 25038 | + let (c_lo, c_hi) = ((j * 64) >> ss_y(fctx), ((j + 1) * 64) >> ss_y(fctx)); | |
| 25039 | + snap_band(su2.data.to_mut(), u, ss_y(fctx) as u32, c_lo, c_hi, cfg.cdef_on); | |
| 25040 | + snap_band(sv2.data.to_mut(), v, ss_y(fctx) as u32, c_lo, c_hi, cfg.cdef_on); | |
| 24733 | 25041 | } |
| 24734 | 25042 | } |
| 24735 | 25043 | if cfg.cdef_on && k >= 3 && k - 3 < nb { |
| @@ -24784,8 +25092,23 @@ fn pipe_run_lr( | ||
| 24784 | 25092 | let (fw, fh) = (cfg.frame_w, cfg.frame_h); |
| 24785 | 25093 | let dims = [ |
| 24786 | 25094 | (fw, fh, 0u32, y.width, y.data.len()), |
| 24787 | - (fw.div_ceil(2), fh.div_ceil(2), 1, u.width, u.data.len()), | |
| 24788 | - (fw.div_ceil(2), fh.div_ceil(2), 1, v.width, v.data.len()), | |
| 25095 | + // lane-av1422filter: chroma plane extents and stripe geometry follow | |
| 25096 | + // the frame's own subsampling -- 4:2:2 chroma is full-height with | |
| 25097 | + // luma-grid stripes (only 4:2:0 halves both). | |
| 25098 | + ( | |
| 25099 | + round_ss(fw, ss_x(fctx)), | |
| 25100 | + round_ss(fh, ss_y(fctx)), | |
| 25101 | + ss_y(fctx) as u32, | |
| 25102 | + u.width, | |
| 25103 | + u.data.len(), | |
| 25104 | + ), | |
| 25105 | + ( | |
| 25106 | + round_ss(fw, ss_x(fctx)), | |
| 25107 | + round_ss(fh, ss_y(fctx)), | |
| 25108 | + ss_y(fctx) as u32, | |
| 25109 | + v.width, | |
| 25110 | + v.data.len(), | |
| 25111 | + ), | |
| 24789 | 25112 | ]; |
| 24790 | 25113 | let mut planes: Vec<LrPlane> = Vec::new(); |
| 24791 | 25114 | for (p, &(pw, ph, ss, stride, len)) in dims.iter().enumerate() { |
| @@ -25561,6 +25884,21 @@ pub(crate) fn chroma_split_tx_hits() -> usize { | ||
| 25561 | 25884 | CHROMA_SPLIT_TX_HITS.with(std::cell::Cell::get) |
| 25562 | 25885 | } |
| 25563 | 25886 | |
| 25887 | +thread_local! { | |
| 25888 | + /// How many INTRA leaves of an inter frame's 8x8 block ran the lossless | |
| 25889 | + /// 4:4:4 chroma walk ([`read_intra_chroma_lossless`], lane-av1-llintra8) | |
| 25890 | + /// -- one bump per leaf, four units per plane inside it. A gate proving | |
| 25891 | + /// the arm must see this nonzero; CHROMA_SPLIT_TX_HITS alone cannot | |
| 25892 | + /// attribute its bumps to THIS leaf. | |
| 25893 | + pub(crate) static LLINTRA8_CHROMA_WALK_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 25894 | +} | |
| 25895 | + | |
| 25896 | +/// [`LLINTRA8_CHROMA_WALK_HITS`]: lossless 4:4:4 chroma walks through an | |
| 25897 | +/// inter frame's 8x8 INTRA leaf. | |
| 25898 | +pub fn llintra8_chroma_walk_hits() -> usize { | |
| 25899 | + LLINTRA8_CHROMA_WALK_HITS.with(|c| c.get()) | |
| 25900 | +} | |
| 25901 | + | |
| 25564 | 25902 | fn read_sb128_root( |
| 25565 | 25903 | dec: &mut SymbolDecoder, |
| 25566 | 25904 | cdfs: &mut Cdfs, |
| @@ -27751,8 +28089,20 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 27751 | 28089 | lr.frame_restoration_type[p] != ec_av1_syntax::RestorationType::None |
| 27752 | 28090 | && lr.loop_restoration_size[p] != 0 |
| 27753 | 28091 | }); |
| 27754 | - let deblocked = | |
| 27755 | - lr_active.then(|| (plane_snapshot(&y, 0), plane_snapshot(&u, 1), plane_snapshot(&v, 1))); | |
| 28092 | + let deblocked = lr_active.then(|| { | |
| 28093 | + ( | |
| 28094 | + plane_snapshot(&y, 0), | |
| 28095 | + // lane-av1422filter: the bands are the LR stripe-boundary context | |
| 28096 | + // (`RESTORATION_UNIT_OFFSET >> ss_y` above/below each 64-luma-row | |
| 28097 | + // stripe). Chroma stripes are half-height ONLY under 4:2:0; a | |
| 28098 | + // 4:2:2 frame's chroma (ss_y = 0) stripes on the luma grid, so | |
| 28099 | + // the hardcoded `1` saved bands at rows 26/60/92/124 where LR | |
| 28100 | + // reads rows 54..57/118..121 -- every 4:2:2 boundary | |
| 28101 | + // substitution read uninitialised zeros (frame-0 V (48,0)). | |
| 28102 | + plane_snapshot(&u, ss_y(fctx) as u32), | |
| 28103 | + plane_snapshot(&v, ss_y(fctx) as u32), | |
| 28104 | + ) | |
| 28105 | + }); | |
| 27756 | 28106 | // lane-tiny r4: post-deblock / post-CDEF dumps mirroring aomdec's own |
| 27757 | 28107 | // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter |
| 27758 | 28108 | // dump above these bisect WHICH filter stage introduced a mismatch. |
| @@ -28390,7 +28740,13 @@ fn read_intra_chroma_lossless( | ||
| 28390 | 28740 | if cpx + ox >= u.true_width || cpy + oy >= u.true_height { |
| 28391 | 28741 | continue; |
| 28392 | 28742 | } |
| 28393 | - let cu_mi = (at_mi.0 + oy / 2, at_mi.1 + ox / 2); | |
| 28743 | + // Chroma pixels per mi cell: 2 at 4:2:0, 4 at 4:4:4. At | |
| 28744 | + // 4:2:0 a TX_4X4 chroma unit spans two mi cells and anchors | |
| 28745 | + // at the even one; at 4:4:4 it IS one mi cell. | |
| 28746 | + let cu_mi = ( | |
| 28747 | + at_mi.0 + oy / (MI >> ss_y(fctx)), | |
| 28748 | + at_mi.1 + ox / (MI >> ss_x(fctx)), | |
| 28749 | + ); | |
| 28394 | 28750 | // libaom's chroma entropy-context arrays are SUBSAMPLED: |
| 28395 | 28751 | // `get_txb_ctx` reads exactly one entry per plane for a |
| 28396 | 28752 | // TX_4X4 chroma unit (`a[0]`/`l[0]`). Our bands are luma-mi |
| @@ -28399,8 +28755,12 @@ fn read_intra_chroma_lossless( | ||
| 28399 | 28755 | // cell is past the band on a unit whose block hangs off the |
| 28400 | 28756 | // frame edge, which libaom still codes. |
| 28401 | 28757 | let cu_around = neighbours.around_mi(cu_mi, MI); |
| 28758 | + // The unit's origin and extent in LUMA pixels: `<< ss` at | |
| 28759 | + // 4:2:0 (8x8 luma for a 4x4 chroma unit), identity at 4:4:4. | |
| 28402 | 28760 | let cu_reach = tu_reach( |
| 28403 | - side, side, ox * 2, oy * 2, 8, reach, px, py, frame_w, frame_h, fctx, | |
| 28761 | + side, side, | |
| 28762 | + ox << ss_x(fctx), oy << ss_y(fctx), 4 << ss_x(fctx), | |
| 28763 | + reach, px, py, frame_w, frame_h, fctx, | |
| 28404 | 28764 | ); |
| 28405 | 28765 | if let Some((ub, vb)) = palette_uv_bufs { |
| 28406 | 28766 | let buf = if plane_idx == 1 { ub } else { vb }; |
| @@ -28431,7 +28791,11 @@ fn read_intra_chroma_lossless( | ||
| 28431 | 28791 | smooth_neighbor_uv, |
| 28432 | 28792 | fctx, |
| 28433 | 28793 | )?; |
| 28434 | - neighbours.record_mi_chroma(cu_mi, 8, 8, plane_idx, &cu_grid); | |
| 28794 | + // The unit's own footprint on the LUMA mi grid: 8 luma px | |
| 28795 | + // (two cells) at 4:2:0, 4 (one cell) at 4:4:4. | |
| 28796 | + neighbours.record_mi_chroma( | |
| 28797 | + cu_mi, 4 << ss_x(fctx), 4 << ss_y(fctx), plane_idx, &cu_grid, | |
| 28798 | + ); | |
| 28435 | 28799 | hit!(CHROMA_SPLIT_TX_HITS); |
| 28436 | 28800 | let dst = mu_units( |
| 28437 | 28801 | if plane_idx == 1 { &mut *u_out } else { &mut *v_out }, |
| @@ -28498,9 +28862,13 @@ fn read_inter_chroma_lossless( | ||
| 28498 | 28862 | if cpx + ox >= u.true_width || cpy + oy >= u.true_height { |
| 28499 | 28863 | continue; |
| 28500 | 28864 | } |
| 28501 | - // The chroma neighbour bands are indexed in LUMA mi: 4 chroma | |
| 28502 | - // pixels span 8 luma ones, i.e. 2 mi. | |
| 28503 | - let cu_mi = (at_mi.0 + oy / 2, at_mi.1 + ox / 2); | |
| 28865 | + // The chroma neighbour bands are indexed in LUMA mi: a 4-wide | |
| 28866 | + // chroma unit spans `4 << ss` luma pixels, i.e. `4 >> ss` -- | |
| 28867 | + // 2 mi cells at 4:2:0, one at 4:4:4. | |
| 28868 | + let cu_mi = ( | |
| 28869 | + at_mi.0 + oy / (4 >> ss_y(fctx)), | |
| 28870 | + at_mi.1 + ox / (4 >> ss_x(fctx)), | |
| 28871 | + ); | |
| 28504 | 28872 | // libaom's chroma entropy-context arrays are SUBSAMPLED: |
| 28505 | 28873 | // `get_txb_ctx` reads exactly one entry per plane for a |
| 28506 | 28874 | // TX_4X4 chroma unit (`a[0]`/`l[0]`). Our bands are luma-mi |
| @@ -28537,7 +28905,13 @@ fn read_inter_chroma_lossless( | ||
| 28537 | 28905 | )? |
| 28538 | 28906 | .0; |
| 28539 | 28907 | // Immediately, so the NEXT unit reads this one's context. |
| 28540 | - neighbours.record_mi_chroma(cu_mi, 8, 8, plane_idx, &cu_grid); | |
| 28908 | + neighbours.record_mi_chroma( | |
| 28909 | + cu_mi, | |
| 28910 | + 4 << ss_x(fctx), | |
| 28911 | + 4 << ss_y(fctx), | |
| 28912 | + plane_idx, | |
| 28913 | + &cu_grid, | |
| 28914 | + ); | |
| 28541 | 28915 | hit!(CHROMA_SPLIT_TX_HITS); |
| 28542 | 28916 | let dst = mu_units( |
| 28543 | 28917 | if plane_idx == 1 { &mut *u_out } else { &mut *v_out }, |
| @@ -28553,6 +28927,39 @@ fn read_inter_chroma_lossless( | ||
| 28553 | 28927 | Ok(()) |
| 28554 | 28928 | } |
| 28555 | 28929 | |
| 28930 | +/// The 8x8 inter leaf's lossless 4:4:4 chroma arm (lane-av1-llinter), shared | |
| 28931 | +/// by the single-ref and compound paths: the plane block is a 2x2 raster of | |
| 28932 | +/// TX_4X4 units (`av1_get_tx_size`: lossless returns TX_4X4 for EVERY plane, | |
| 28933 | +/// not just luma), read by the same per-unit walk the bigger inter blocks | |
| 28934 | +/// run. Returns the two block grids composed at stride 8 (`Grid::Zero` when | |
| 28935 | +/// every unit hung off the frame edge) and leaves each unit's own coefficient | |
| 28936 | +/// context stamped in the neighbour bands -- the caller's tail must not let | |
| 28937 | +/// its whole-block `record_mi` overwrite them. | |
| 28938 | +#[allow(clippy::too_many_arguments)] | |
| 28939 | +fn leaf8_inter_chroma_lossless( | |
| 28940 | + dec: &mut SymbolDecoder, | |
| 28941 | + cdfs: &mut Cdfs, | |
| 28942 | + neighbours: &mut Neighbours, | |
| 28943 | + u: &mut PlaneBuf<'static>, | |
| 28944 | + v: &mut PlaneBuf<'static>, | |
| 28945 | + su: Pred<'_>, | |
| 28946 | + sv: Pred<'_>, | |
| 28947 | + at_mi: (usize, usize), | |
| 28948 | + (cpx, cpy): (usize, usize), | |
| 28949 | + base_q_idx: u8, fctx: &crate::decode::FrameCtx, | |
| 28950 | +) -> Result<(Grid, Grid)> { | |
| 28951 | + let (mut uo, mut vo) = (Vec::new(), Vec::new()); | |
| 28952 | + read_inter_chroma_lossless( | |
| 28953 | + dec, cdfs, neighbours, u, v, su, sv, | |
| 28954 | + at_mi, (cpx, cpy), (0, 0), (8, 8), (8, 8), 8, 0, | |
| 28955 | + base_q_idx, &mut uo, &mut vo, fctx, | |
| 28956 | + )?; | |
| 28957 | + Ok(( | |
| 28958 | + if uo.is_empty() { Grid::Zero(64) } else { Grid::Own(uo) }, | |
| 28959 | + if vo.is_empty() { Grid::Zero(64) } else { Grid::Own(vo) }, | |
| 28960 | + )) | |
| 28961 | +} | |
| 28962 | + | |
| 28556 | 28963 | /// Spec 5.11.25's `single_ref_p1`..`p6` tree (reachable only once `comp_mode` |
| 28557 | 28964 | /// is known `SINGLE_REFERENCE` -- `decode_stream` refuses any frame with |
| 28558 | 28965 | /// `reference_select` set before this is ever called, so that read is never |
| @@ -29547,6 +29954,13 @@ pub(crate) fn obmc_plan( | ||
| 29547 | 29954 | side: usize, |
| 29548 | 29955 | write_w: usize, |
| 29549 | 29956 | write_h: usize, |
| 29957 | + // lane-av1-llpred2: the FRAME's own subsampling pair -- the same pair the | |
| 29958 | + // chroma window half in [`obmc_run`] shifts by. A rect strip's ss cannot | |
| 29959 | + // be derived from a rect size over the square `chroma_side`: that ratio | |
| 29960 | + // gave a 16x8 strip at 4:2:0 ss=(1,0) (losing its above-chroma skip) and | |
| 29961 | + // divides by zero at 4:4:4 (`trailing_zeros(0)` = 64, a debug shift panic). | |
| 29962 | + ss_x: usize, | |
| 29963 | + ss_y: usize, | |
| 29550 | 29964 | chroma_side: usize, |
| 29551 | 29965 | px: usize, |
| 29552 | 29966 | py: usize, |
| @@ -29591,10 +30005,19 @@ pub(crate) fn obmc_plan( | ||
| 29591 | 30005 | let overlap_above = write_h.min(64) / 2; |
| 29592 | 30006 | let overlap_left = write_w.min(64) / 2; |
| 29593 | 30007 | // lane-inter8 r1 / lane-scaledref r1: `av1_skip_u4x4_pred_in_obmc` |
| 29594 | - // (`reconinter.c` 820) returns `dir == 0` when the chroma plane's own | |
| 29595 | - // block is BLOCK_4X4/8X4/4X8 (an 8x8, 16x8 or 8x16 luma block at 4:2:0): | |
| 29596 | - // the ABOVE pass skips chroma entirely, the LEFT pass still blends it. | |
| 29597 | - let skip_chroma_above = matches!((write_w, write_h), (8, 8) | (16, 8) | (8, 16)); | |
| 30008 | + // (`reconinter.c` 829) switches on the PLANE block | |
| 30009 | + // (`get_plane_block_size`, ss-shifted): only 4x4/8x4/4x8 skip the ABOVE | |
| 30010 | + // pass's chroma (`return dir == 0`), the LEFT pass still blends them. | |
| 30011 | + // lane-av1-llpred: the old luma-shape list `(8,8)|(16,8)|(8,16)` | |
| 30012 | + // hardcoded the 4:2:0 plane sizes; at 4:4:4 the plane block is the luma | |
| 30013 | + // block itself (never 4-wide), so every one of those blocks was silently | |
| 30014 | + // missing its above-pass chroma OBMC blend. | |
| 30015 | + // lane-av1-llpred2: ss is the FRAME's own pair (`ss_x`/`ss_y(fctx)`, the | |
| 30016 | + // same values [`obmc_run`]'s chroma windows shift by), never a ratio of | |
| 30017 | + // the rect write size over the square `chroma_side` -- that ratio gave a | |
| 30018 | + // 4:2:0 16x8 strip ss=(1,0) and dropped its above-chroma skip, and at | |
| 30019 | + // 4:4:4 divided to zero (`trailing_zeros(0)` = 64, a debug shift panic). | |
| 30020 | + let skip_chroma_above = obmc_skip_chroma_above(write_w, write_h, ss_x, ss_y); | |
| 29598 | 30021 | let mut above = Vec::new(); |
| 29599 | 30022 | for (off4, span4, nb, src4) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4)) |
| 29600 | 30023 | { |
| @@ -29666,6 +30089,56 @@ pub(crate) fn obmc_plan( | ||
| 29666 | 30089 | }) |
| 29667 | 30090 | } |
| 29668 | 30091 | |
| 30092 | +/// `av1_skip_u4x4_pred_in_obmc`'s above-pass decision (libaom | |
| 30093 | +/// `reconinter.c` 829): the PLANE block (`write_w >> ss_x`, `write_h >> | |
| 30094 | +/// ss_y`) is 4x4, 8x4 or 4x8. `ss_x`/`ss_y` are the FRAME's own pair -- the | |
| 30095 | +/// same values [`obmc_run`]'s chroma windows shift by -- never a ratio over | |
| 30096 | +/// the square `chroma_side` (lane-av1-llpred2: that ratio dropped the | |
| 30097 | +/// 4:2:0 16x8/8x16 skip and shifted by 64 at 4:4:4). Pure so the check | |
| 30098 | +/// below pins the rect-strip decision without decoding a stream. | |
| 30099 | +pub(crate) fn obmc_skip_chroma_above( | |
| 30100 | + write_w: usize, | |
| 30101 | + write_h: usize, | |
| 30102 | + ss_x: usize, | |
| 30103 | + ss_y: usize, | |
| 30104 | +) -> bool { | |
| 30105 | + matches!( | |
| 30106 | + (write_w >> ss_x, write_h >> ss_y), | |
| 30107 | + (4, 4) | (8, 4) | (4, 8) | |
| 30108 | + ) | |
| 30109 | +} | |
| 30110 | + | |
| 30111 | +#[cfg(test)] | |
| 30112 | +mod obmc_skip_chroma_tests { | |
| 30113 | + use super::obmc_skip_chroma_above; | |
| 30114 | + | |
| 30115 | + /// lane-av1-llpred2: the above-chroma skip keys off the PLANE block | |
| 30116 | + /// under the frame's own ss pair. At 4:2:0 a 16x8/8x16 rect strip's | |
| 30117 | + /// plane block is 8x4/4x8 and MUST still skip (the old `chroma_side` | |
| 30118 | + /// ratio read ss=(1,0) off a 16x8 strip and made it blend); at 4:4:4 | |
| 30119 | + /// the plane block is the luma block, so only true 4-wide/high shapes | |
| 30120 | + /// skip and the shift never leaves `usize` range (the old ratio's | |
| 30121 | + /// `trailing_zeros(0)` = 64 panicked a debug build). | |
| 30122 | + #[test] | |
| 30123 | + fn rect_strips_skip_above_chroma_at_420_and_shift_never_overflows() { | |
| 30124 | + // 4:2:0 (ss 1,1): 8x8 -> 4x4, 16x8 -> 8x4, 8x16 -> 4x8 all skip. | |
| 30125 | + assert!(obmc_skip_chroma_above(8, 8, 1, 1)); | |
| 30126 | + assert!(obmc_skip_chroma_above(16, 8, 1, 1)); | |
| 30127 | + assert!(obmc_skip_chroma_above(8, 16, 1, 1)); | |
| 30128 | + // ... larger plane blocks blend, exactly libaom's own list. | |
| 30129 | + assert!(!obmc_skip_chroma_above(16, 16, 1, 1)); | |
| 30130 | + assert!(!obmc_skip_chroma_above(32, 16, 1, 1)); | |
| 30131 | + assert!(!obmc_skip_chroma_above(16, 32, 1, 1)); | |
| 30132 | + // 4:4:4 (ss 0,0): the plane block is the luma block itself. | |
| 30133 | + assert!(obmc_skip_chroma_above(4, 4, 0, 0)); | |
| 30134 | + assert!(obmc_skip_chroma_above(8, 4, 0, 0)); | |
| 30135 | + assert!(obmc_skip_chroma_above(4, 8, 0, 0)); | |
| 30136 | + assert!(!obmc_skip_chroma_above(8, 8, 0, 0)); | |
| 30137 | + assert!(!obmc_skip_chroma_above(16, 8, 0, 0)); | |
| 30138 | + assert!(!obmc_skip_chroma_above(8, 16, 0, 0)); | |
| 30139 | + } | |
| 30140 | +} | |
| 30141 | + | |
| 29669 | 30142 | /// One OBMC neighbour as the PARSE thread resolved it (lane-defer8): every |
| 29670 | 30143 | /// value [`obmc_run`] needs that lives in the mode-info grid or the |
| 29671 | 30144 | /// neighbour bands, which the parse keeps overwriting as it walks on. |
| @@ -29774,9 +30247,13 @@ pub(crate) fn obmc_run( | ||
| 29774 | 30247 | if !skip_chroma_above { |
| 29775 | 30248 | // lane-t900 r13 (measured, NOT a defect): libaom's min-4 clamp |
| 29776 | 30249 | // sizes only the OBMC PREDICTION buffer; the blend length is the |
| 29777 | - // plain half (`build_obmc_inter_pred_above`: `overlap >> ss_y`). | |
| 29778 | - let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2); | |
| 29779 | - let cw = cbw.min(write_w / 2 - cox); | |
| 30250 | + // plain overlap (`build_obmc_inter_pred_above`: | |
| 30251 | + // `overlap >> ss_y`) -- the PLANE's own subsampling shift, 0 at | |
| 30252 | + // 4:4:4 (lane-av1-llpred: the old `/2` hardcoded the 4:2:0 half | |
| 30253 | + // and half-blended every 4:4:4 OBMC block's chroma). | |
| 30254 | + let (cbw, cbh, cox) = | |
| 30255 | + (bw >> ss_x(fctx), overlap_above >> ss_y(fctx), ox >> ss_x(fctx)); | |
| 30256 | + let cw = cbw.min((write_w >> ss_x(fctx)) - cox); | |
| 29780 | 30257 | obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_u, fctx); |
| 29781 | 30258 | obmc_blend_v(pred_u, chroma_side, cox, 0, cw, cbh, cbw, &tmp_u); |
| 29782 | 30259 | obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx); |
| @@ -29791,7 +30268,8 @@ pub(crate) fn obmc_run( | ||
| 29791 | 30268 | let (bw, bh, oy) = (overlap_left, nb.span4 * 4, nb.off4 * 4); |
| 29792 | 30269 | obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_y, fctx); |
| 29793 | 30270 | obmc_blend_h(pred_y, side, 0, oy, bw, bh.min(write_h - oy), &tmp_y); |
| 29794 | - let (cbw, cbh, coy) = (overlap_left / 2, bh / 2, oy / 2); | |
| 30271 | + let (cbw, cbh, coy) = | |
| 30272 | + (overlap_left >> ss_x(fctx), bh >> ss_y(fctx), oy >> ss_y(fctx)); | |
| 29795 | 30273 | obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_u, fctx); |
| 29796 | 30274 | if let Some((_, _, idx)) = ec_mcb { |
| 29797 | 30275 | eprintln!( |
| @@ -29803,7 +30281,7 @@ pub(crate) fn obmc_run( | ||
| 29803 | 30281 | eprintln!("OUR_MCB lrow{r}: {row:?}"); |
| 29804 | 30282 | } |
| 29805 | 30283 | } |
| 29806 | - let ch = cbh.min(write_h / 2 - coy); | |
| 30284 | + let ch = cbh.min((write_h >> ss_y(fctx)) - coy); | |
| 29807 | 30285 | obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, ch, &tmp_u); |
| 29808 | 30286 | obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx); |
| 29809 | 30287 | obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, ch, &tmp_v); |
| @@ -32618,6 +33096,8 @@ fn decode_inter_block( | ||
| 32618 | 33096 | side, |
| 32619 | 33097 | write_w, |
| 32620 | 33098 | write_h, |
| 33099 | + ss_x(fctx), | |
| 33100 | + ss_y(fctx), | |
| 32621 | 33101 | chroma_side, |
| 32622 | 33102 | px, |
| 32623 | 33103 | py, |
| @@ -34146,6 +34626,89 @@ fn decode_inter_block( | ||
| 34146 | 34626 | u_grid = if uo.is_empty() { Grid::Zero(zero) } else { Grid::Own(uo) }; |
| 34147 | 34627 | v_grid = if vo.is_empty() { Grid::Zero(zero) } else { Grid::Own(vo) }; |
| 34148 | 34628 | mu_chroma = true; |
| 34629 | + } else if ss_x(fctx) == 0 && ss_y(fctx) == 0 && chroma_side > chroma_tx { | |
| 34630 | + // lane-av1-rect128recon: at ss 0/0 the uv plane block of a | |
| 34631 | + // 64x64 intra block inside an inter frame is 64x64 while | |
| 34632 | + // `av1_get_max_uv_txsize` caps the unit at TX_32X32 -- FOUR | |
| 34633 | + // plane-major TX_32X32 units (libaom | |
| 34634 | + // `decode_token_recon_block`'s plane loop), each with its own | |
| 34635 | + // neighbour context and `get_txb_ctx`'s offset-10 rows (+3 on | |
| 34636 | + // the `txb_skip_chroma_32` table, lane-sb128b r3), each | |
| 34637 | + // stamped immediately so the next unit reads it. The old arm | |
| 34638 | + // read ONE whole-plane unit with the block-level context and | |
| 34639 | + // no offset: three quarters of the plane's residual was never | |
| 34640 | + // read, the unit's `txb_skip` came off the offset-7 row (444 | |
| 34641 | + // witness f2, right-half intra 64x64: U unit (0,0) ctx 0 | |
| 34642 | + // where aom reads 10), and the coded corner was even | |
| 34643 | + // dequantized at the TX_64X64 dqDenom. | |
| 34644 | + let mu_units_n = chroma_side / chroma_tx; | |
| 34645 | + let mut u_acc = vec![0i32; chroma_side * chroma_side]; | |
| 34646 | + let mut v_acc = vec![0i32; chroma_side * chroma_side]; | |
| 34647 | + for plane_idx in 1..=2 { | |
| 34648 | + let buf: &mut PlaneBuf<'static> = | |
| 34649 | + if plane_idx == 1 { &mut *u } else { &mut *v }; | |
| 34650 | + for cu_row in 0..mu_units_n { | |
| 34651 | + for cu_col in 0..mu_units_n { | |
| 34652 | + let cu_mi = ( | |
| 34653 | + at_mi.0 + cu_row * (chroma_tx / MI), | |
| 34654 | + at_mi.1 + cu_col * (chroma_tx / MI), | |
| 34655 | + ); | |
| 34656 | + let cu_around = neighbours.around_mi(cu_mi, chroma_tx); | |
| 34657 | + let cu_reach = crate::decode::tu_reach( | |
| 34658 | + side, | |
| 34659 | + side, | |
| 34660 | + cu_col * chroma_tx, | |
| 34661 | + cu_row * chroma_tx, | |
| 34662 | + chroma_tx, | |
| 34663 | + reach, | |
| 34664 | + px, | |
| 34665 | + py, | |
| 34666 | + y.width, | |
| 34667 | + y.height, fctx, | |
| 34668 | + ); | |
| 34669 | + let cu_grid = read_plane( | |
| 34670 | + dec, | |
| 34671 | + cdfs, | |
| 34672 | + chroma_set, | |
| 34673 | + scan_chroma, | |
| 34674 | + plane_idx, | |
| 34675 | + cu_around[plane_idx], | |
| 34676 | + mode, | |
| 34677 | + uv_predict_mode, | |
| 34678 | + angle_delta_uv, | |
| 34679 | + cu_reach, | |
| 34680 | + buf, | |
| 34681 | + cpx + cu_col * chroma_tx, | |
| 34682 | + cpy + cu_row * chroma_tx, | |
| 34683 | + chroma_tx, | |
| 34684 | + chroma_tx, | |
| 34685 | + base_q_idx, | |
| 34686 | + // CfL is capped at 32x32 (`is_cfl_allowed`), | |
| 34687 | + // so a block this size never carries alpha. | |
| 34688 | + None, | |
| 34689 | + None, | |
| 34690 | + Some(3), | |
| 34691 | + smooth_neighbor_uv, fctx, | |
| 34692 | + )?; | |
| 34693 | + // Immediately, so the NEXT unit reads this one's | |
| 34694 | + // coefficient context. | |
| 34695 | + neighbours.record_mi_chroma( | |
| 34696 | + cu_mi, chroma_tx, chroma_tx, plane_idx, &cu_grid, | |
| 34697 | + ); | |
| 34698 | + hit!(CHROMA_SPLIT_TX_HITS); | |
| 34699 | + let acc = if plane_idx == 1 { &mut u_acc } else { &mut v_acc }; | |
| 34700 | + for rr in 0..chroma_tx { | |
| 34701 | + let start = | |
| 34702 | + (cu_row * chroma_tx + rr) * chroma_side + cu_col * chroma_tx; | |
| 34703 | + acc[start..start + chroma_tx] | |
| 34704 | + .copy_from_slice(&cu_grid[rr * chroma_tx..][..chroma_tx]); | |
| 34705 | + } | |
| 34706 | + } | |
| 34707 | + } | |
| 34708 | + } | |
| 34709 | + mu_chroma = true; | |
| 34710 | + u_grid = Grid::Own(u_acc); | |
| 34711 | + v_grid = Grid::Own(v_acc); | |
| 34149 | 34712 | } else { |
| 34150 | 34713 | if let Some((ub, _)) = &palette_uv_bufs { |
| 34151 | 34714 | set_palette_pred(ub.clone(), fctx); |
| @@ -34217,8 +34780,21 @@ fn decode_inter_block( | ||
| 34217 | 34780 | // strip's own record wrote empty chroma state over those cells -- this |
| 34218 | 34781 | // rewrite is what libaom's single `av1_set_contexts` call for the 8x4 |
| 34219 | 34782 | // (4x8) chroma unit leaves behind. |
| 34783 | + // lane-av1-444interband: 4:2:0 ONLY. At ss 0/0 every strip IS its own | |
| 34784 | + // chroma reference (`is_chroma_reference`, no mi parity test), its own | |
| 34785 | + // `record_rect_mi` above already stamps exactly the strip's 16x4 (4x16) | |
| 34786 | + // chroma span -- libaom `av1_set_entropy_contexts`, or | |
| 34787 | + // `av1_reset_entropy_context` for a skipped strip (decodeframe.c:1180) | |
| 34788 | + // -- and the pair-form 16x8 (8x16) span anchored at `pair_mi` (== the | |
| 34789 | + // strip's own mi at ss 0/0) smeared the strip's state over one extra | |
| 34790 | + // row/col of cells: a skipped strip wrote zero over `left[r+1][1..2]`, | |
| 34791 | + // erasing the 16x16-intra block to its left's U/V stamps, and the strip | |
| 34792 | + // below read its chroma `txb_skip` off the wrong CDF row (t6 frame 1, | |
| 34793 | + // U unit (2,8): our base 0 vs aom's base 1, `left[2][1]` 0 vs 23 -- | |
| 34794 | + // `INTER16_CHROMA_PAIR_HITS` fired 31x on a stream that has no pairs). | |
| 34220 | 34795 | let pair_chroma = strip_chroma |
| 34221 | 34796 | .filter(|s| s.has_chroma) |
| 34797 | + .filter(|_| ss_x(fctx) == 1 && ss_y(fctx) == 1) | |
| 34222 | 34798 | .map(|s| (s, neighbour_state(&u_grid), neighbour_state(&v_grid))); |
| 34223 | 34799 | // lane-vert46 r1: libaom stamps the chroma entropy context PER TRANSFORM |
| 34224 | 34800 | // UNIT (`av1_set_entropy_contexts` inside `decode_reconstruct_tx`'s mu-chunk |
| @@ -34236,17 +34812,37 @@ fn decode_inter_block( | ||
| 34236 | 34812 | let cu = if lossless(fctx) { 4usize } else { 32usize }; |
| 34237 | 34813 | let mut units = Vec::new(); |
| 34238 | 34814 | if lossless(fctx) { |
| 34239 | - let (rows, cols) = ((write_h / 2).div_ceil(cu), (write_w / 2).div_ceil(cu)); | |
| 34815 | + // lane-av1-llinter: a TX_4X4 chroma unit covers `4 << ss` LUMA | |
| 34816 | + // pixels (8, x2-per-unit, at 4:2:0; 4, x1, at 4:4:4) -- the | |
| 34817 | + // composed plane grid then holds a full cu-row per chroma row and | |
| 34818 | + // each unit's own origin sits `(cu << ss) / MI` mi cells out. | |
| 34819 | + // The hardcoded 4:2:0 /2-and-x2 math stamped half the plane with | |
| 34820 | + // double spans at 4:4:4 and corrupted the next block's | |
| 34821 | + // `txb_skip_ctx` (dodge2 frame 1, U unit mi (4,16) read row 11 | |
| 34822 | + // where the oracle reads row 10). | |
| 34823 | + let (rows, cols) = ( | |
| 34824 | + (write_h >> ss_y(fctx)).div_ceil(cu), | |
| 34825 | + (write_w >> ss_x(fctx)).div_ceil(cu), | |
| 34826 | + ); | |
| 34240 | 34827 | for cr in 0..rows { |
| 34241 | 34828 | for cc in 0..cols { |
| 34242 | - let cu_mi = (at.0 + cr * (cu * 2 / MI), at.1 + cc * (cu * 2 / MI)); | |
| 34829 | + let cu_mi = ( | |
| 34830 | + at.0 + cr * ((cu << ss_y(fctx)) / MI), | |
| 34831 | + at.1 + cc * ((cu << ss_x(fctx)) / MI), | |
| 34832 | + ); | |
| 34243 | 34833 | for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] { |
| 34244 | 34834 | let mut unit = Vec::with_capacity(cu * cu); |
| 34245 | 34835 | for rr in 0..cu { |
| 34246 | 34836 | let start = (cr * cu + rr) * chroma_side + cc * cu; |
| 34247 | 34837 | unit.extend_from_slice(&grid[start..start + cu]); |
| 34248 | 34838 | } |
| 34249 | - units.push((cu_mi, plane, Grid::Own(unit), cu * 2, cu * 2)); | |
| 34839 | + units.push(( | |
| 34840 | + cu_mi, | |
| 34841 | + plane, | |
| 34842 | + Grid::Own(unit), | |
| 34843 | + cu << ss_x(fctx), | |
| 34844 | + cu << ss_y(fctx), | |
| 34845 | + )); | |
| 34250 | 34846 | } |
| 34251 | 34847 | } |
| 34252 | 34848 | } |
| @@ -36313,6 +36909,23 @@ fn decode_inter_sub8_rect2( | ||
| 36313 | 36909 | push_mc_rect(2, px, py, SIDE, bw, bh, sv, &ZERO_RESIDUAL[..SIDE * SIDE], fctx); |
| 36314 | 36910 | neighbours.record_mi_chroma(lmi, bw, bh, 1, &ZERO_RESIDUAL[..bw * bh]); |
| 36315 | 36911 | neighbours.record_mi_chroma(lmi, bw, bh, 2, &ZERO_RESIDUAL[..bw * bh]); |
| 36912 | + } else if lossless(fctx) && !mono(fctx) { | |
| 36913 | + // lane-av1-llsub8b: lossless codes TX_4X4 on EVERY plane | |
| 36914 | + // (`av1_get_tx_size`, blockd.h:1383), so this 4:4:4 piece's | |
| 36915 | + // (8,4)/(4,8) chroma plane block is a 2x1/1x2 raster of | |
| 36916 | + // TX_4X4 units, not the ONE TX_8X4 rect unit the lossy arm | |
| 36917 | + // below reads -- that single rect is what tripped | |
| 36918 | + // `TxParams::run`'s WHT assert ((8,4) != (4,4), | |
| 36919 | + // decode.rs:2566). The walk stamps each unit's own | |
| 36920 | + // coefficient context, so -- unlike the lossy arm -- no | |
| 36921 | + // whole-block `record_mi_chroma` runs after it: the walk's | |
| 36922 | + // per-unit stamps ARE the block's chroma contexts (the same | |
| 36923 | + // rule `leaf8_inter_chroma_lossless`'s caller obeys). | |
| 36924 | + read_inter_chroma_lossless( | |
| 36925 | + dec, cdfs, neighbours, u, v, su, sv, | |
| 36926 | + (rmi, cmi), (px, py), (0, 0), (bw, bh), (bw, bh), SIDE, 0, | |
| 36927 | + base_q_idx, &mut Vec::new(), &mut Vec::new(), fctx, | |
| 36928 | + )?; | |
| 36316 | 36929 | } else { |
| 36317 | 36930 | let ca = neighbours.around_mi_rect(lmi, bw, bh); |
| 36318 | 36931 | let (ug, _) = read_inter_plane_rect( |
| @@ -36751,6 +37364,12 @@ fn decode_inter_block8( | ||
| 36751 | 37364 | // stores `UV_DC_PRED`, exactly as [`decode_inter_block`] one level up. |
| 36752 | 37365 | let mut uv_predict_mode = DC_PRED; |
| 36753 | 37366 | let (luma_grid, u_grid, v_grid); |
| 37367 | + // lane-av1-llinter: set when a lossless 4:4:4 leaf's chroma went through | |
| 37368 | + // the per-unit walk (`read_inter_chroma_lossless`) -- the walk stamps each | |
| 37369 | + // TX_4X4 unit's own coefficient context, so the tail's whole-block | |
| 37370 | + // `record_mi` gets its chroma half saved/restored around, exactly like | |
| 37371 | + // `saved_luma_ctx` does for a `split8` luma. | |
| 37372 | + let mut chroma_stamped_per_unit = false; | |
| 36754 | 37373 | let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None; |
| 36755 | 37374 | // lane-inter8 r1: this leaf's own resolved references, handed back so the |
| 36756 | 37375 | // NEXT leaf of the same 16x16 can use them as its real above/left |
| @@ -37360,42 +37979,52 @@ fn decode_inter_block8( | ||
| 37360 | 37979 | split8, fctx, |
| 37361 | 37980 | )?; |
| 37362 | 37981 | luma_grid = grid8; |
| 37363 | - u_grid = read_inter_plane( | |
| 37364 | - dec, | |
| 37365 | - cdfs, | |
| 37366 | - chroma_set, | |
| 37367 | - chroma_scan, | |
| 37368 | - 1, | |
| 37369 | - around[1], | |
| 37370 | - mode_for_tx, | |
| 37371 | - u, | |
| 37372 | - cpx, | |
| 37373 | - cpy, | |
| 37374 | - chroma_side, | |
| 37375 | - base_q_idx, | |
| 37376 | - su, | |
| 37377 | - Some(luma_tx_type), | |
| 37378 | - None, fctx, | |
| 37379 | - )? | |
| 37380 | - .0; | |
| 37381 | - v_grid = read_inter_plane( | |
| 37382 | - dec, | |
| 37383 | - cdfs, | |
| 37384 | - chroma_set, | |
| 37385 | - chroma_scan, | |
| 37386 | - 2, | |
| 37387 | - around[2], | |
| 37388 | - mode_for_tx, | |
| 37389 | - v, | |
| 37390 | - cpx, | |
| 37391 | - cpy, | |
| 37392 | - chroma_side, | |
| 37393 | - base_q_idx, | |
| 37394 | - sv, | |
| 37395 | - Some(luma_tx_type), | |
| 37396 | - None, fctx, | |
| 37397 | - )? | |
| 37398 | - .0; | |
| 37982 | + if chroma_side == 8 && lossless(fctx) && !mono(fctx) { | |
| 37983 | + let (ug, vg) = leaf8_inter_chroma_lossless( | |
| 37984 | + dec, cdfs, neighbours, u, v, su, sv, | |
| 37985 | + leaf_mi, (cpx, cpy), base_q_idx, fctx, | |
| 37986 | + )?; | |
| 37987 | + u_grid = ug; | |
| 37988 | + v_grid = vg; | |
| 37989 | + chroma_stamped_per_unit = true; | |
| 37990 | + } else { | |
| 37991 | + u_grid = read_inter_plane( | |
| 37992 | + dec, | |
| 37993 | + cdfs, | |
| 37994 | + chroma_set, | |
| 37995 | + chroma_scan, | |
| 37996 | + 1, | |
| 37997 | + around[1], | |
| 37998 | + mode_for_tx, | |
| 37999 | + u, | |
| 38000 | + cpx, | |
| 38001 | + cpy, | |
| 38002 | + chroma_side, | |
| 38003 | + base_q_idx, | |
| 38004 | + su, | |
| 38005 | + Some(luma_tx_type), | |
| 38006 | + None, fctx, | |
| 38007 | + )? | |
| 38008 | + .0; | |
| 38009 | + v_grid = read_inter_plane( | |
| 38010 | + dec, | |
| 38011 | + cdfs, | |
| 38012 | + chroma_set, | |
| 38013 | + chroma_scan, | |
| 38014 | + 2, | |
| 38015 | + around[2], | |
| 38016 | + mode_for_tx, | |
| 38017 | + v, | |
| 38018 | + cpx, | |
| 38019 | + cpy, | |
| 38020 | + chroma_side, | |
| 38021 | + base_q_idx, | |
| 38022 | + sv, | |
| 38023 | + Some(luma_tx_type), | |
| 38024 | + None, fctx, | |
| 38025 | + )? | |
| 38026 | + .0; | |
| 38027 | + } | |
| 37399 | 38028 | } |
| 37400 | 38029 | // lane-inter8 r2: the COMPOUND leaf used to return here |
| 37401 | 38030 | // WITHOUT the end-of-function `record_mi`/`fill_lf_grid` the |
| @@ -37451,7 +38080,32 @@ fn decode_inter_block8( | ||
| 37451 | 38080 | palette_record8.2, |
| 37452 | 38081 | palette_record8.3, |
| 37453 | 38082 | ); |
| 38083 | + let saved_chroma_ctx = chroma_stamped_per_unit.then(|| { | |
| 38084 | + ( | |
| 38085 | + [ | |
| 38086 | + [neighbours.left[leaf_mi.0][1], neighbours.left[leaf_mi.0][2]], | |
| 38087 | + [neighbours.left[leaf_mi.0 + 1][1], neighbours.left[leaf_mi.0 + 1][2]], | |
| 38088 | + ], | |
| 38089 | + [ | |
| 38090 | + [neighbours.above[leaf_mi.1][1], neighbours.above[leaf_mi.1][2]], | |
| 38091 | + [neighbours.above[leaf_mi.1 + 1][1], neighbours.above[leaf_mi.1 + 1][2]], | |
| 38092 | + ], | |
| 38093 | + ) | |
| 38094 | + }); | |
| 37454 | 38095 | neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]); |
| 38096 | + if let Some((left, above)) = saved_chroma_ctx { | |
| 38097 | + // The walk's per-unit stamps are the block's real chroma | |
| 38098 | + // coefficient contexts (`av1_set_contexts` per TX_4X4 | |
| 38099 | + // unit); put them back over `record_mi`'s composed state. | |
| 38100 | + for (cell, uv) in left.into_iter().enumerate() { | |
| 38101 | + neighbours.left[leaf_mi.0 + cell][1] = uv[0]; | |
| 38102 | + neighbours.left[leaf_mi.0 + cell][2] = uv[1]; | |
| 38103 | + } | |
| 38104 | + for (cell, uv) in above.into_iter().enumerate() { | |
| 38105 | + neighbours.above[leaf_mi.1 + cell][1] = uv[0]; | |
| 38106 | + neighbours.above[leaf_mi.1 + cell][2] = uv[1]; | |
| 38107 | + } | |
| 38108 | + } | |
| 37455 | 38109 | if let Some((left, above)) = saved_luma_ctx { |
| 37456 | 38110 | for (cell, state) in left.into_iter().enumerate() { |
| 37457 | 38111 | neighbours.left[leaf_mi.0 + cell][0] = state; |
| @@ -37881,6 +38535,8 @@ fn decode_inter_block8( | ||
| 37881 | 38535 | SIDE, |
| 37882 | 38536 | SIDE, |
| 37883 | 38537 | SIDE, |
| 38538 | + ss_x(fctx), | |
| 38539 | + ss_y(fctx), | |
| 37884 | 38540 | chroma_side, |
| 37885 | 38541 | px, |
| 37886 | 38542 | py, |
| @@ -38073,42 +38729,52 @@ fn decode_inter_block8( | ||
| 38073 | 38729 | split8, fctx, |
| 38074 | 38730 | )?; |
| 38075 | 38731 | luma_grid = grid8; |
| 38076 | - u_grid = read_inter_plane( | |
| 38077 | - dec, | |
| 38078 | - cdfs, | |
| 38079 | - chroma_set, | |
| 38080 | - chroma_scan, | |
| 38081 | - 1, | |
| 38082 | - around[1], | |
| 38083 | - mode_for_tx, | |
| 38084 | - u, | |
| 38085 | - cpx, | |
| 38086 | - cpy, | |
| 38087 | - chroma_side, | |
| 38088 | - base_q_idx, | |
| 38089 | - su, | |
| 38090 | - Some(luma_tx_type), | |
| 38091 | - None, fctx, | |
| 38092 | - )? | |
| 38093 | - .0; | |
| 38094 | - v_grid = read_inter_plane( | |
| 38095 | - dec, | |
| 38096 | - cdfs, | |
| 38097 | - chroma_set, | |
| 38098 | - chroma_scan, | |
| 38099 | - 2, | |
| 38100 | - around[2], | |
| 38101 | - mode_for_tx, | |
| 38102 | - v, | |
| 38103 | - cpx, | |
| 38104 | - cpy, | |
| 38105 | - chroma_side, | |
| 38106 | - base_q_idx, | |
| 38107 | - sv, | |
| 38108 | - Some(luma_tx_type), | |
| 38109 | - None, fctx, | |
| 38110 | - )? | |
| 38111 | - .0; | |
| 38732 | + if chroma_side == 8 && lossless(fctx) && !mono(fctx) { | |
| 38733 | + let (ug, vg) = leaf8_inter_chroma_lossless( | |
| 38734 | + dec, cdfs, neighbours, u, v, su, sv, | |
| 38735 | + leaf_mi, (cpx, cpy), base_q_idx, fctx, | |
| 38736 | + )?; | |
| 38737 | + u_grid = ug; | |
| 38738 | + v_grid = vg; | |
| 38739 | + chroma_stamped_per_unit = true; | |
| 38740 | + } else { | |
| 38741 | + u_grid = read_inter_plane( | |
| 38742 | + dec, | |
| 38743 | + cdfs, | |
| 38744 | + chroma_set, | |
| 38745 | + chroma_scan, | |
| 38746 | + 1, | |
| 38747 | + around[1], | |
| 38748 | + mode_for_tx, | |
| 38749 | + u, | |
| 38750 | + cpx, | |
| 38751 | + cpy, | |
| 38752 | + chroma_side, | |
| 38753 | + base_q_idx, | |
| 38754 | + su, | |
| 38755 | + Some(luma_tx_type), | |
| 38756 | + None, fctx, | |
| 38757 | + )? | |
| 38758 | + .0; | |
| 38759 | + v_grid = read_inter_plane( | |
| 38760 | + dec, | |
| 38761 | + cdfs, | |
| 38762 | + chroma_set, | |
| 38763 | + chroma_scan, | |
| 38764 | + 2, | |
| 38765 | + around[2], | |
| 38766 | + mode_for_tx, | |
| 38767 | + v, | |
| 38768 | + cpx, | |
| 38769 | + cpy, | |
| 38770 | + chroma_side, | |
| 38771 | + base_q_idx, | |
| 38772 | + sv, | |
| 38773 | + Some(luma_tx_type), | |
| 38774 | + None, fctx, | |
| 38775 | + )? | |
| 38776 | + .0; | |
| 38777 | + } | |
| 38112 | 38778 | } |
| 38113 | 38779 | } else { |
| 38114 | 38780 | let mode = dec.symbol(&mut cdfs.y_mode[SIZE_GROUP_8]); |
| @@ -38159,10 +38825,22 @@ fn decode_inter_block8( | ||
| 38159 | 38825 | // but `DC_PRED` was refused here, which is what blocked the low-cq |
| 38160 | 38826 | // CDEF arms and the 10-bit gates. |
| 38161 | 38827 | let has_chroma = !mono(fctx); |
| 38828 | + // lane-av1-llintra8: `read_intra_mode_uv` (decodemv.c:145) picks the | |
| 38829 | + // uv CDF row by `is_cfl_allowed` (cfl.h:23) -- at LOSSLESS that is | |
| 38830 | + // "the chroma plane block is BLOCK_4X4" (cfl.h:29), for this | |
| 38831 | + // BLOCK_8X8 leaf only at 4:2:0. The 4:4:4 lossless leaf reads the | |
| 38832 | + // 13-symbol `uv_mode_no_cfl` alphabet; the unconditional CFL row | |
| 38833 | + // consumed a different partition than aomdec at the leaf's own | |
| 38834 | + // uv_mode symbol (class wrong-alphabet-same-value) and desynced | |
| 38835 | + // every stream that reached the leaf's lossless chroma walk below. | |
| 38836 | + // 4:2:0 and every non-lossless partition keep the CFL row | |
| 38837 | + // (`cfl_allowed_px` answers true exactly as before). | |
| 38162 | 38838 | let uv_mode = if !has_chroma { |
| 38163 | 38839 | DC_PRED |
| 38164 | - } else { | |
| 38840 | + } else if cfl_allowed_px(SIDE, SIDE, fctx) { | |
| 38165 | 38841 | dec.symbol(&mut cdfs.uv_mode_cfl[mode]) |
| 38842 | + } else { | |
| 38843 | + dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) | |
| 38166 | 38844 | }; |
| 38167 | 38845 | if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { |
| 38168 | 38846 | eprintln!( |
| @@ -38572,6 +39250,33 @@ fn decode_inter_block8( | ||
| 38572 | 39250 | )? |
| 38573 | 39251 | }; |
| 38574 | 39252 | let ac = alpha.map(|_| cfl_src(px, py, SIDE)); |
| 39253 | + if chroma_side == 8 && lossless(fctx) && !mono(fctx) { | |
| 39254 | + // lane-av1-llintra8: lossless codes TX_4X4 on EVERY plane | |
| 39255 | + // (`av1_get_tx_size`, blockd.h:1383), so this intra leaf's 8x8 | |
| 39256 | + // chroma plane block is a 2x2 raster of TX_4X4 units per | |
| 39257 | + // plane, plane-major -- the same per-unit walk the >=16x16 | |
| 39258 | + // intra-in-inter block runs, not one TX_8X8 unit (whose WHT | |
| 39259 | + // hits `TxParams::run`'s `(8, 8) != (4, 4)` lossless assert). | |
| 39260 | + // The walk stamps each unit's own coefficient context | |
| 39261 | + // (`record_mi_chroma` inside it), so the tail's whole-block | |
| 39262 | + // `record_mi` gets its chroma half saved/restored around -- | |
| 39263 | + // the same rule the INTER arms' | |
| 39264 | + // `leaf8_inter_chroma_lossless` obeys. 4:2:0 keeps its single | |
| 39265 | + // TX_4X4 unit in the `else` below. | |
| 39266 | + let (mut uo, mut vo) = (Vec::new(), Vec::new()); | |
| 39267 | + read_intra_chroma_lossless( | |
| 39268 | + dec, cdfs, neighbours, u, v, leaf_mi, (px, py), (cpx, cpy), | |
| 39269 | + SIDE, (chroma_side, chroma_side), (0, 0), | |
| 39270 | + (chroma_side, chroma_side), chroma_side, reach, | |
| 39271 | + (y.width, y.height), mode, uv_predict_mode, angle_delta_uv, | |
| 39272 | + palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])), | |
| 39273 | + smooth_neighbor_uv, base_q_idx, &mut uo, &mut vo, fctx, | |
| 39274 | + )?; | |
| 39275 | + u_grid = if uo.is_empty() { Grid::Zero(64) } else { Grid::Own(uo) }; | |
| 39276 | + v_grid = if vo.is_empty() { Grid::Zero(64) } else { Grid::Own(vo) }; | |
| 39277 | + chroma_stamped_per_unit = true; | |
| 39278 | + hit!(LLINTRA8_CHROMA_WALK_HITS); | |
| 39279 | + } else { | |
| 38575 | 39280 | if let Some((ub, _)) = &palette_uv_bufs { |
| 38576 | 39281 | set_palette_pred(ub.clone(), fctx); |
| 38577 | 39282 | } |
| @@ -38622,6 +39327,7 @@ fn decode_inter_block8( | ||
| 38622 | 39327 | None, |
| 38623 | 39328 | smooth_neighbor_uv, fctx, |
| 38624 | 39329 | )?; |
| 39330 | + } | |
| 38625 | 39331 | } |
| 38626 | 39332 | } |
| 38627 | 39333 | // lane-txselect: a split leaf's plane-0 neighbour context is per 4x4 |
| @@ -38665,7 +39371,32 @@ fn decode_inter_block8( | ||
| 38665 | 39371 | palette_record8.2, |
| 38666 | 39372 | palette_record8.3, |
| 38667 | 39373 | ); |
| 39374 | + let saved_chroma_ctx = chroma_stamped_per_unit.then(|| { | |
| 39375 | + ( | |
| 39376 | + [ | |
| 39377 | + [neighbours.left[leaf_mi.0][1], neighbours.left[leaf_mi.0][2]], | |
| 39378 | + [neighbours.left[leaf_mi.0 + 1][1], neighbours.left[leaf_mi.0 + 1][2]], | |
| 39379 | + ], | |
| 39380 | + [ | |
| 39381 | + [neighbours.above[leaf_mi.1][1], neighbours.above[leaf_mi.1][2]], | |
| 39382 | + [neighbours.above[leaf_mi.1 + 1][1], neighbours.above[leaf_mi.1 + 1][2]], | |
| 39383 | + ], | |
| 39384 | + ) | |
| 39385 | + }); | |
| 38668 | 39386 | neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]); |
| 39387 | + if let Some((left, above)) = saved_chroma_ctx { | |
| 39388 | + // The walk's per-unit stamps are the block's real chroma coefficient | |
| 39389 | + // contexts (`av1_set_contexts` per TX_4X4 unit); put them back over | |
| 39390 | + // `record_mi`'s one composed state. | |
| 39391 | + for (cell, uv) in left.into_iter().enumerate() { | |
| 39392 | + neighbours.left[leaf_mi.0 + cell][1] = uv[0]; | |
| 39393 | + neighbours.left[leaf_mi.0 + cell][2] = uv[1]; | |
| 39394 | + } | |
| 39395 | + for (cell, uv) in above.into_iter().enumerate() { | |
| 39396 | + neighbours.above[leaf_mi.1 + cell][1] = uv[0]; | |
| 39397 | + neighbours.above[leaf_mi.1 + cell][2] = uv[1]; | |
| 39398 | + } | |
| 39399 | + } | |
| 38669 | 39400 | // lane-uv8 r1: this leaf never stamped a mode band at all, so the block |
| 38670 | 39401 | // below/right of it read whatever block last wrote the coarse [`SUB`] |
| 38671 | 39402 | // slot -- now that an intra leaf here can code a smooth/directional |
| @@ -41810,7 +42541,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 41810 | 42541 | (false, None) => None, |
| 41811 | 42542 | } |
| 41812 | 42543 | } else { |
| 41813 | - lr_active.then(|| (plane_snapshot(&y, 0), plane_snapshot(&u, 1), plane_snapshot(&v, 1))) | |
| 42544 | + // lane-av1422filter: chroma band geometry follows the frame's own | |
| 42545 | + // ss_y (see the keyframe path's note) -- 4:2:2 stripes full-height. | |
| 42546 | + lr_active.then(|| { | |
| 42547 | + ( | |
| 42548 | + plane_snapshot(&y, 0), | |
| 42549 | + plane_snapshot(&u, ss_y(fctx) as u32), | |
| 42550 | + plane_snapshot(&v, ss_y(fctx) as u32), | |
| 42551 | + ) | |
| 42552 | + }) | |
| 41814 | 42553 | }; |
| 41815 | 42554 | // lane-tiny r4: post-deblock / post-CDEF dumps mirroring aomdec's own |
| 41816 | 42555 | // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter |
crates/ec-av1/src/encode.rsmodified+2 -0
| @@ -6801,6 +6801,8 @@ fn obmc_prediction( | ||
| 6801 | 6801 | side, |
| 6802 | 6802 | side, |
| 6803 | 6803 | side, |
| 6804 | + crate::decode::ss_x(fctx), | |
| 6805 | + crate::decode::ss_y(fctx), | |
| 6804 | 6806 | side / 2, |
| 6805 | 6807 | x, |
| 6806 | 6808 | y, |
crates/ec-av1/src/stream.rsmodified+491 -0
| @@ -5399,6 +5399,497 @@ pub(crate) mod tests { | ||
| 5399 | 5399 | } |
| 5400 | 5400 | } |
| 5401 | 5401 | |
| 5402 | + /// lane-av1-llband: the pinned 4:4:4 LOSSLESS key frame | |
| 5403 | + /// (`fixtures/ll444-lossless-key.obu`, the `ll444` recipe's frame 0 -- | |
| 5404 | + /// `testsrc2 128x96` yuv444p cut to its key frame) decodes sample-exact, | |
| 5405 | + /// and its HORZ/VERT strips really walked their chroma as 4x4 units at | |
| 5406 | + /// subsampling 0/0 (one unit per mi cell). That unit walk used the 4:2:0 | |
| 5407 | + /// span (8 luma px per 4x4 chroma unit) unconditionally, so every unit | |
| 5408 | + /// past the first column/row read its `txb_skip` context two mi cells | |
| 5409 | + /// over and stamped a 2-cell smear -- the 178-byte key-frame miss, first | |
| 5410 | + /// divergence at the 16x8 leaf mi (16,24)'s U bc=2 unit (oracle | |
| 5411 | + /// `txb_skip` base 0 off `above[26]`, ours base 1 off the polluted | |
| 5412 | + /// `above[29]`). The counter assertion is the non-vacuity half (class | |
| 5413 | + /// `gate-blind-to-feature`): a stream that never reaches the 4:4:4 unit | |
| 5414 | + /// walk must not pass. | |
| 5415 | + #[test] | |
| 5416 | + fn a_real_aomenc_lossless_444_key_frame_decodes_sample_exact() { | |
| 5417 | + const NAME: &str = "a_real_aomenc_lossless_444_key_frame_decodes_sample_exact"; | |
| 5418 | + if !have_ffmpeg() { | |
| 5419 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 5420 | + return; | |
| 5421 | + } | |
| 5422 | + let Ok(stream) = std::fs::read(pin_dir().join("ll444-lossless-key.obu")) else { | |
| 5423 | + eprintln!( | |
| 5424 | + "SKIP {NAME}: no pinned bytes at {} -- regenerate with \ | |
| 5425 | + `testsrc2 128x96` yuv444p 6 frames, aomenc --profile=1 --lossless=1 \ | |
| 5426 | + --enable-palette=0 --enable-intrabc=0, cut to the key frame's OBUs", | |
| 5427 | + pin_dir().join("ll444-lossless-key.obu").display() | |
| 5428 | + ); | |
| 5429 | + return; | |
| 5430 | + }; | |
| 5431 | + // Blindness guard: the pinned fixture must really be a lossless frame. | |
| 5432 | + let mut parser = Av1Parser::new(); | |
| 5433 | + let mut pos = 0usize; | |
| 5434 | + let mut lossless = false; | |
| 5435 | + while pos < stream.len() { | |
| 5436 | + let obu = parser.parse_obu(&stream[pos..]).expect("aomenc OBU parses"); | |
| 5437 | + pos += obu.total_size.max(1); | |
| 5438 | + if let ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) = obu.kind { | |
| 5439 | + lossless = h.lossless.iter().all(|&l| l); | |
| 5440 | + } | |
| 5441 | + } | |
| 5442 | + assert!(lossless, "{NAME} went blind: the pinned frame is not lossless"); | |
| 5443 | + let before = crate::decode::rect_split_lossless_chroma444_hits(); | |
| 5444 | + let ours = decode_stream(&stream).expect("a 444 lossless key-frame stream decodes"); | |
| 5445 | + assert_eq!(ours.len(), 1, "{NAME}: frame count"); | |
| 5446 | + assert!( | |
| 5447 | + crate::decode::rect_split_lossless_chroma444_hits() > before, | |
| 5448 | + "{NAME} went blind: no lossless HORZ/VERT strip walked its chroma \ | |
| 5449 | + as 4x4 units at subsampling 0/0" | |
| 5450 | + ); | |
| 5451 | + let refs = Command::new("ffmpeg") | |
| 5452 | + .args(["-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv444p", "-"]) | |
| 5453 | + .stdin(Stdio::piped()) | |
| 5454 | + .stdout(Stdio::piped()) | |
| 5455 | + .stderr(Stdio::piped()) | |
| 5456 | + .spawn() | |
| 5457 | + .and_then(|mut child| { | |
| 5458 | + use std::io::Write as _; | |
| 5459 | + child.stdin.as_mut().expect("stdin").write_all(&stream)?; | |
| 5460 | + child.wait_with_output() | |
| 5461 | + }) | |
| 5462 | + .expect("ffmpeg 444 decode failed"); | |
| 5463 | + assert!(refs.status.success(), "{}", String::from_utf8_lossy(&refs.stderr)); | |
| 5464 | + let frame = &ours[0]; | |
| 5465 | + let planes = [ | |
| 5466 | + (&frame.y, frame.width * frame.height), | |
| 5467 | + (&frame.u, frame.width * frame.height), | |
| 5468 | + (&frame.v, frame.width * frame.height), | |
| 5469 | + ]; | |
| 5470 | + let mut off = 0usize; | |
| 5471 | + for (plane, (g, len)) in planes.iter().enumerate() { | |
| 5472 | + let raw = &refs.stdout[off..off + len]; | |
| 5473 | + let bad = g.iter().zip(raw.iter()).filter(|&(&a, &b)| a != u16::from(b)).count(); | |
| 5474 | + assert_eq!(bad, 0, "{NAME}: plane {plane}: {bad} samples differ"); | |
| 5475 | + off += len; | |
| 5476 | + } | |
| 5477 | + } | |
| 5478 | + | |
| 5479 | + /// As [`ffmpeg_decode_sequence`], for a 4:4:4 stream: chroma planes are | |
| 5480 | + /// FULL resolution (`yuv444p` rawvideo), the shape lane-av1-llinter's | |
| 5481 | + /// lossless profile-1 fixture codes. | |
| 5482 | + fn ffmpeg_decode_sequence_444( | |
| 5483 | + stream: &[u8], | |
| 5484 | + width: usize, | |
| 5485 | + height: usize, | |
| 5486 | + frames: usize, | |
| 5487 | + ) -> Vec<Pic> { | |
| 5488 | + let out = run_with_stdin( | |
| 5489 | + Command::new("ffmpeg").args([ | |
| 5490 | + "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv444p", "-", | |
| 5491 | + ]), | |
| 5492 | + stream, | |
| 5493 | + ); | |
| 5494 | + assert!( | |
| 5495 | + out.status.success(), | |
| 5496 | + "ffmpeg refused the 4:4:4 stream: {}", | |
| 5497 | + String::from_utf8_lossy(&out.stderr) | |
| 5498 | + ); | |
| 5499 | + let plane = width * height; | |
| 5500 | + let frame_bytes = 3 * plane; | |
| 5501 | + assert_eq!( | |
| 5502 | + out.stdout.len(), | |
| 5503 | + frame_bytes * frames, | |
| 5504 | + "expected {frames} 4:4:4 frames, ffmpeg said: {}", | |
| 5505 | + String::from_utf8_lossy(&out.stderr) | |
| 5506 | + ); | |
| 5507 | + (0..frames) | |
| 5508 | + .map(|i| { | |
| 5509 | + let base = i * frame_bytes; | |
| 5510 | + Pic { | |
| 5511 | + width, | |
| 5512 | + height, | |
| 5513 | + y: out.stdout[base..base + plane].iter().map(|&v| u16::from(v)).collect(), | |
| 5514 | + u: out.stdout[base + plane..base + 2 * plane].iter().map(|&v| u16::from(v)).collect(), | |
| 5515 | + v: out.stdout[base + 2 * plane..base + 3 * plane].iter().map(|&v| u16::from(v)).collect(), | |
| 5516 | + } | |
| 5517 | + }) | |
| 5518 | + .collect() | |
| 5519 | + } | |
| 5520 | + | |
| 5521 | + /// lane-av1-llinter: the firing gate for the lossless 4:4:4 INTER chroma | |
| 5522 | + /// fix. The fixture is the report's dodge2 stream pinned into `fixtures/`: | |
| 5523 | + /// aomenc profile 1 over testsrc2 128x96 yuv444p, `--lossless=1`, | |
| 5524 | + /// `--sb-size=64 --min-partition-size=64 --max-partition-size=64`, 6 | |
| 5525 | + /// frames; 37658 bytes, sha256 | |
| 5526 | + /// `5a070fa351a3f2109de855234f2b3d0a872970f3e7f658db21f65c12eeb135b4`. | |
| 5527 | + /// The firing counter is the EXISTING `decode::chroma_split_tx_hits` (one | |
| 5528 | + /// bump per lossless chroma TX unit read): with min=max partition 64 the | |
| 5529 | + /// roots stay whole 64x64 inter blocks -- no 8x8 leaf exists in this | |
| 5530 | + /// stream -- so every chroma unit goes through the big-block ss-aware | |
| 5531 | + /// lossless route this lane fixed (fixes 2-5). A 4:2:0 lossless stream | |
| 5532 | + /// fires the same counter, but the fixture bytes are pinned, so the gate | |
| 5533 | + /// cannot run on anything else; the pre-fix 4:2:0-hardcoded math corrupts | |
| 5534 | + /// at 4:4:4, so the pixel-exact compares are what prove the ss-aware path | |
| 5535 | + /// (class `gate-blind-to-feature`). Every frame must come out pixel-exact | |
| 5536 | + /// through BOTH the oracle `aomdec --rawvideo` and ffmpeg. The | |
| 5537 | + /// default-partition ll444 stream is deliberately NOT claimed here: its | |
| 5538 | + /// key frame is still the intra lane's named sub8-chroma stop | |
| 5539 | + /// (lanes/av1llintra.report.md). | |
| 5540 | + #[test] | |
| 5541 | + fn a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact() { | |
| 5542 | + const NAME: &str = "a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact"; | |
| 5543 | + const FIXTURE_LEN: usize = 37658; | |
| 5544 | + const FIXTURE_FNV: u64 = 0xf68d_c26f_a14d_283c; | |
| 5545 | + const W: usize = 128; | |
| 5546 | + const H: usize = 96; | |
| 5547 | + const FRAMES: usize = 6; | |
| 5548 | + let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | |
| 5549 | + .join("fixtures/ll444_minp64_inter.obu"); | |
| 5550 | + let stream = std::fs::read(&obu).unwrap_or_else(|e| { | |
| 5551 | + panic!( | |
| 5552 | + "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ | |
| 5553 | + which is a failure, not a skip", | |
| 5554 | + obu.display() | |
| 5555 | + ) | |
| 5556 | + }); | |
| 5557 | + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); | |
| 5558 | + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | |
| 5559 | + | |
| 5560 | + let _guard = lock_gate_counters(); | |
| 5561 | + let before = crate::decode::chroma_split_tx_hits(); | |
| 5562 | + let frames = decode_stream(&stream).unwrap_or_else(|e| { | |
| 5563 | + panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") | |
| 5564 | + }); | |
| 5565 | + let hits = crate::decode::chroma_split_tx_hits(); | |
| 5566 | + assert!( | |
| 5567 | + hits > before, | |
| 5568 | + "{NAME}: gate is vacuous -- no lossless chroma TX unit was read \ | |
| 5569 | + (delta {before} -> {hits})" | |
| 5570 | + ); | |
| 5571 | + assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); | |
| 5572 | + for f in &frames { | |
| 5573 | + assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); | |
| 5574 | + } | |
| 5575 | + | |
| 5576 | + // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames. | |
| 5577 | + if aomdec_path().is_file() { | |
| 5578 | + let dir = std::env::temp_dir().join(format!("ec-av1-ll444-{}", std::process::id())); | |
| 5579 | + let _ = std::fs::remove_dir_all(&dir); | |
| 5580 | + std::fs::create_dir_all(&dir).expect("scratch dir"); | |
| 5581 | + let raw = dir.join("aomdec.raw"); | |
| 5582 | + let out = Command::new(aomdec_path()) | |
| 5583 | + .args(["--codec=av1", "--rawvideo", "-o"]) | |
| 5584 | + .arg(&raw) | |
| 5585 | + .arg(&obu) | |
| 5586 | + .stdin(Stdio::null()) | |
| 5587 | + .stdout(Stdio::piped()) | |
| 5588 | + .stderr(Stdio::piped()) | |
| 5589 | + .output() | |
| 5590 | + .expect("aomdec failed to run"); | |
| 5591 | + assert!( | |
| 5592 | + out.status.success(), | |
| 5593 | + "{NAME}: the oracle aomdec refused the stream: {}", | |
| 5594 | + String::from_utf8_lossy(&out.stderr) | |
| 5595 | + ); | |
| 5596 | + let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); | |
| 5597 | + let _ = std::fs::remove_dir_all(&dir); | |
| 5598 | + assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); | |
| 5599 | + for (i, f) in frames.iter().enumerate() { | |
| 5600 | + let base = i * W * H * 3; | |
| 5601 | + for ((plane, off), p) in [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] | |
| 5602 | + .into_iter() | |
| 5603 | + .zip(["y", "u", "v"]) | |
| 5604 | + { | |
| 5605 | + let want = &ref_raw[base + off..base + off + W * H]; | |
| 5606 | + let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); | |
| 5607 | + assert_eq!(bad, 0, "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ"); | |
| 5608 | + } | |
| 5609 | + } | |
| 5610 | + } else { | |
| 5611 | + eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); | |
| 5612 | + } | |
| 5613 | + | |
| 5614 | + // ffmpeg's decoder: same frames, full-resolution chroma. | |
| 5615 | + if have_ffmpeg() { | |
| 5616 | + let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); | |
| 5617 | + for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate() { | |
| 5618 | + for (p, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] | |
| 5619 | + .iter() | |
| 5620 | + .enumerate() | |
| 5621 | + { | |
| 5622 | + let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); | |
| 5623 | + assert_eq!(bad, 0, "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ"); | |
| 5624 | + } | |
| 5625 | + } | |
| 5626 | + } else { | |
| 5627 | + eprintln!("SKIP {NAME} ffmpeg arm: no ffmpeg"); | |
| 5628 | + } | |
| 5629 | + } | |
| 5630 | + | |
| 5631 | + /// lane-av1llpredgate2: the debug-exact pin for the ss-aware | |
| 5632 | + /// `obmc_skip_chroma_above` decision (lane-av1-llpred2). Fixture is the | |
| 5633 | + /// llpred/llpred2 reports' stream pinned into `fixtures/`: testsrc2 | |
| 5634 | + /// 128x96 yuv444p, aomenc `--profile=1 --lossless=1 --enable-palette=0 | |
| 5635 | + /// --enable-intrabc=0 --min-partition-size=8 --max-partition-size=64`, | |
| 5636 | + /// 6 frames; 34037 bytes, sha256 | |
| 5637 | + /// `04fb6d38de5382e647bfb70b6a17802f1fccc5502e6698c0394167891f2b27dc`. | |
| 5638 | + /// | |
| 5639 | + /// This is a DEBUG-build path by construction: the old ratio-based ss | |
| 5640 | + /// derivation read `write_h >> trailing_zeros(0)` = `>> 64` on this | |
| 5641 | + /// stream's 4:4:4 OBMC rect strips, a panic ONLY under | |
| 5642 | + /// debug_assertions (release wraps and was already byte-exact), so | |
| 5643 | + /// `cargo test`'s default dev profile is the profile where the defect | |
| 5644 | + /// class reproduces and where the parent's byte-exact proof was | |
| 5645 | + /// measured. | |
| 5646 | + /// | |
| 5647 | + /// No skip-arm counter gate is possible on this stream, measured: | |
| 5648 | + /// OBMC runs 77 times with 20 rect leaves, but | |
| 5649 | + /// `obmc_skip_chroma_above` returns true 0 times -- at 4:4:4 the skip | |
| 5650 | + /// needs a 4x4/8x4/4x8 PLANE block and min-partition-8 never codes one. | |
| 5651 | + /// So per the lane ticket the proof splits in two: the decision TABLE | |
| 5652 | + /// (4:2:0 rect strips still skip, 4:4:4 shifts never leave `usize`) | |
| 5653 | + /// stays pinned by `decode::obmc_skip_chroma_tests:: | |
| 5654 | + /// rect_strips_skip_above_chroma_at_420_and_shift_never_overflows`, | |
| 5655 | + /// and THIS stream gate pins the end-to-end behaviour -- every sample | |
| 5656 | + /// of every frame must match the oracle aomdec exactly, so a returning | |
| 5657 | + /// chroma diff (the lane-av1-llpred ss-blind re-blend class | |
| 5658 | + /// `obmc-ss-blind-chroma-above`) or the debug shift panic goes red | |
| 5659 | + /// here by name. | |
| 5660 | + #[test] | |
| 5661 | + fn a_lossless_444_min_partition8_inter_stream_decodes_sample_exact() { | |
| 5662 | + const NAME: &str = "a_lossless_444_min_partition8_inter_stream_decodes_sample_exact"; | |
| 5663 | + const FIXTURE_LEN: usize = 34037; | |
| 5664 | + const FIXTURE_FNV: u64 = 0x2c8f_4a2c_c025_52da; | |
| 5665 | + const W: usize = 128; | |
| 5666 | + const H: usize = 96; | |
| 5667 | + const FRAMES: usize = 6; | |
| 5668 | + let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | |
| 5669 | + .join("fixtures/ll444_minp8_inter.obu"); | |
| 5670 | + let stream = std::fs::read(&obu).unwrap_or_else(|e| { | |
| 5671 | + panic!( | |
| 5672 | + "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ | |
| 5673 | + which is a failure, not a skip", | |
| 5674 | + obu.display() | |
| 5675 | + ) | |
| 5676 | + }); | |
| 5677 | + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); | |
| 5678 | + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | |
| 5679 | + | |
| 5680 | + let _guard = lock_gate_counters(); | |
| 5681 | + let frames = decode_stream(&stream).unwrap_or_else(|e| { | |
| 5682 | + panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") | |
| 5683 | + }); | |
| 5684 | + assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); | |
| 5685 | + for f in &frames { | |
| 5686 | + assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); | |
| 5687 | + } | |
| 5688 | + | |
| 5689 | + // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames. | |
| 5690 | + if aomdec_path().is_file() { | |
| 5691 | + let dir = std::env::temp_dir().join(format!("ec-av1-llminp8-{}", std::process::id())); | |
| 5692 | + let _ = std::fs::remove_dir_all(&dir); | |
| 5693 | + std::fs::create_dir_all(&dir).expect("scratch dir"); | |
| 5694 | + let raw = dir.join("aomdec.raw"); | |
| 5695 | + let out = Command::new(aomdec_path()) | |
| 5696 | + .args(["--codec=av1", "--rawvideo", "-o"]) | |
| 5697 | + .arg(&raw) | |
| 5698 | + .arg(&obu) | |
| 5699 | + .stdin(Stdio::null()) | |
| 5700 | + .stdout(Stdio::piped()) | |
| 5701 | + .stderr(Stdio::piped()) | |
| 5702 | + .output() | |
| 5703 | + .expect("aomdec failed to run"); | |
| 5704 | + assert!( | |
| 5705 | + out.status.success(), | |
| 5706 | + "{NAME}: the oracle aomdec refused the stream: {}", | |
| 5707 | + String::from_utf8_lossy(&out.stderr) | |
| 5708 | + ); | |
| 5709 | + let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); | |
| 5710 | + let _ = std::fs::remove_dir_all(&dir); | |
| 5711 | + assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); | |
| 5712 | + for (i, f) in frames.iter().enumerate() { | |
| 5713 | + let base = i * W * H * 3; | |
| 5714 | + for ((plane, off), p) in [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] | |
| 5715 | + .into_iter() | |
| 5716 | + .zip(["y", "u", "v"]) | |
| 5717 | + { | |
| 5718 | + let want = &ref_raw[base + off..base + off + W * H]; | |
| 5719 | + let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); | |
| 5720 | + assert_eq!( | |
| 5721 | + bad, 0, | |
| 5722 | + "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ | |
| 5723 | + (class obmc-ss-blind-chroma-above)" | |
| 5724 | + ); | |
| 5725 | + } | |
| 5726 | + } | |
| 5727 | + } else { | |
| 5728 | + eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); | |
| 5729 | + } | |
| 5730 | + | |
| 5731 | + // ffmpeg's decoder: same frames, full-resolution chroma. | |
| 5732 | + if have_ffmpeg() { | |
| 5733 | + let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); | |
| 5734 | + for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate() { | |
| 5735 | + for (p, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] | |
| 5736 | + .iter() | |
| 5737 | + .enumerate() | |
| 5738 | + { | |
| 5739 | + let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); | |
| 5740 | + assert_eq!(bad, 0, "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ"); | |
| 5741 | + } | |
| 5742 | + } | |
| 5743 | + } else { | |
| 5744 | + eprintln!("SKIP {NAME} ffmpeg arm: no ffmpeg"); | |
| 5745 | + } | |
| 5746 | + } | |
| 5747 | + | |
| 5748 | + /// lane-av1-444sb: the byte-exact pin for the ss-aware 128-rect chroma | |
| 5749 | + /// unit walk (`decode_block_128rect`). The parent walk hardcoded the | |
| 5750 | + /// 4:2:0 mu-chunk span -- one 32x32 chroma unit per 64x64 chunk, chunk | |
| 5751 | + /// offsets `*32`, clip step `*8` -- so at 4:4:4 a 128-root HORZ/VERT | |
| 5752 | + /// intra block coded HALF its chroma units, left the remaining units' | |
| 5753 | + /// coefficients unread and desynced the tile from the first such block | |
| 5754 | + /// on; every superblock after SB(0,0) carried damage and the chroma | |
| 5755 | + /// first-diffs sat on the 64/128 grid. | |
| 5756 | + /// | |
| 5757 | + /// `crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu`, 794 bytes, | |
| 5758 | + /// sha256 | |
| 5759 | + /// `27825e14633a4b23e37d48a2acdc7f5d814ca4fadd0b8797d72a1ffb34061e80`: | |
| 5760 | + /// `ffmpeg -i bands444.y4m -frames:v 3 -vf scale=192:160 -pix_fmt | |
| 5761 | + /// yuv444p -f yuv4mpegpipe` piped to `aomenc --codec=av1 --profile=1 | |
| 5762 | + /// --passes=1 --end-usage=q --cq-level=32 --cpu-used=0 --threads=1 | |
| 5763 | + /// --row-mt=0 --sb-size=128 --lag-in-frames=0 --auto-alt-ref=0 | |
| 5764 | + /// --kf-max-dist=1000 --i444 --enable-restoration=1 --obu --limit=3`. | |
| 5765 | + /// Real content is required: the synthetic lavfi sources this lane swept | |
| 5766 | + /// (testsrc2/testsrc/smptebars/mandelbrot/gradients) all decode frame 0 | |
| 5767 | + /// exact because they never force a 128-root rect; bands does (kf | |
| 5768 | + /// PARTITION_VERT 64x128 at mi(0,32) plus an intra-in-inter 64x128). | |
| 5769 | + /// | |
| 5770 | + /// Non-vacuity via the `decode::intra_sb128_hits` delta: a stream that | |
| 5771 | + /// stopped coding 128-axis intra blocks reads 0 and the gate fails | |
| 5772 | + /// instead of passing over a decode that never reached the fixed body | |
| 5773 | + /// (class `gate-blind-to-feature`). The oracle arms pin every sample of | |
| 5774 | + /// every frame against both aomdec and ffmpeg, so a returning chroma | |
| 5775 | + /// span regression goes red here by name. | |
| 5776 | + #[test] | |
| 5777 | + fn a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact() { | |
| 5778 | + const NAME: &str = "a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact"; | |
| 5779 | + const FIXTURE_LEN: usize = 794; | |
| 5780 | + const FIXTURE_FNV: u64 = 0xf5a7_27f4_3fa7_abc3; | |
| 5781 | + const W: usize = 192; | |
| 5782 | + const H: usize = 160; | |
| 5783 | + const FRAMES: usize = 3; | |
| 5784 | + let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | |
| 5785 | + .join("fixtures/444_sb128rect_lr_witness.obu"); | |
| 5786 | + let stream = std::fs::read(&obu).unwrap_or_else(|e| { | |
| 5787 | + panic!( | |
| 5788 | + "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ | |
| 5789 | + which is a failure, not a skip", | |
| 5790 | + obu.display() | |
| 5791 | + ) | |
| 5792 | + }); | |
| 5793 | + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); | |
| 5794 | + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | |
| 5795 | + | |
| 5796 | + let _guard = lock_gate_counters(); | |
| 5797 | + let before = crate::decode::intra_sb128_hits(); | |
| 5798 | + let frames = decode_stream(&stream).unwrap_or_else(|e| { | |
| 5799 | + panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") | |
| 5800 | + }); | |
| 5801 | + let (horz, vert, _) = crate::decode::intra_sb128_hits(); | |
| 5802 | + assert!( | |
| 5803 | + horz - before.0 + (vert - before.1) > 0, | |
| 5804 | + "{NAME}: this stream coded NO 128-axis intra block -- the fixed body \ | |
| 5805 | + never ran (class gate-blind-to-feature)" | |
| 5806 | + ); | |
| 5807 | + assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); | |
| 5808 | + for f in &frames { | |
| 5809 | + assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); | |
| 5810 | + } | |
| 5811 | + // All three frames are pinned byte-exact against both oracles (the | |
| 5812 | + // aomdec/ffmpeg arms below run over `.take(3)`): frame 0's keyframe | |
| 5813 | + // PARTITION_VERT 64x128, frame 1's inter pieces, and frame 2 -- whose | |
| 5814 | + // right superblock column (the 128-root VERT piece at the frame edge) | |
| 5815 | + // is three intra blocks (64x64, 64x32, 64x32) whose chroma units ride | |
| 5816 | + // the inter-frame intra tail. That tail read ONE whole-plane chroma | |
| 5817 | + // unit with the block-level context where 4:4:4 codes four | |
| 5818 | + // plane-major TX_32X32 units with per-unit contexts and the | |
| 5819 | + // offset-10 `get_txb_ctx` rows, which left three quarters of the | |
| 5820 | + // planes' residual unread and misaligned the symbol stream from the | |
| 5821 | + // first chroma unit on (f2 PREFILT Y 6952 / U 9568 / V 13496, first | |
| 5822 | + // diffs entering at column 128). Fixed on lane-av1-rect128recon; | |
| 5823 | + // the earlier "LR never restores RU row 0" attribution on this frame | |
| 5824 | + // was a stage-ladder mixup, refuted in lane-av1lrflush r3. | |
| 5825 | + | |
| 5826 | + // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames. | |
| 5827 | + if aomdec_path().is_file() { | |
| 5828 | + let dir = | |
| 5829 | + std::env::temp_dir().join(format!("ec-av1-444sb-{}", std::process::id())); | |
| 5830 | + let _ = std::fs::remove_dir_all(&dir); | |
| 5831 | + std::fs::create_dir_all(&dir).expect("scratch dir"); | |
| 5832 | + let raw = dir.join("aomdec.raw"); | |
| 5833 | + let out = Command::new(aomdec_path()) | |
| 5834 | + .args(["--codec=av1", "--rawvideo", "-o"]) | |
| 5835 | + .arg(&raw) | |
| 5836 | + .arg(&obu) | |
| 5837 | + .stdin(Stdio::null()) | |
| 5838 | + .stdout(Stdio::piped()) | |
| 5839 | + .stderr(Stdio::piped()) | |
| 5840 | + .output() | |
| 5841 | + .expect("aomdec failed to run"); | |
| 5842 | + assert!( | |
| 5843 | + out.status.success(), | |
| 5844 | + "{NAME}: the oracle aomdec refused the stream: {}", | |
| 5845 | + String::from_utf8_lossy(&out.stderr) | |
| 5846 | + ); | |
| 5847 | + let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); | |
| 5848 | + let _ = std::fs::remove_dir_all(&dir); | |
| 5849 | + assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); | |
| 5850 | + for (i, f) in frames.iter().enumerate().take(3) { | |
| 5851 | + let base = i * W * H * 3; | |
| 5852 | + for ((plane, off), p) in | |
| 5853 | + [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] | |
| 5854 | + .into_iter() | |
| 5855 | + .zip(["y", "u", "v"]) | |
| 5856 | + { | |
| 5857 | + let want = &ref_raw[base + off..base + off + W * H]; | |
| 5858 | + let bad = | |
| 5859 | + plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); | |
| 5860 | + assert_eq!( | |
| 5861 | + bad, 0, | |
| 5862 | + "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ | |
| 5863 | + (class 444-128rect-chroma-span)" | |
| 5864 | + ); | |
| 5865 | + } | |
| 5866 | + } | |
| 5867 | + } else { | |
| 5868 | + eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); | |
| 5869 | + } | |
| 5870 | + | |
| 5871 | + // ffmpeg's decoder: same frames, full-resolution chroma. Same | |
| 5872 | + // three-frame scope as the aomdec arm above. | |
| 5873 | + if have_ffmpeg() { | |
| 5874 | + let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); | |
| 5875 | + for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate().take(3) { | |
| 5876 | + for (p, (g, r)) in | |
| 5877 | + [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] | |
| 5878 | + .iter() | |
| 5879 | + .enumerate() | |
| 5880 | + { | |
| 5881 | + let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); | |
| 5882 | + assert_eq!( | |
| 5883 | + bad, 0, | |
| 5884 | + "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ" | |
| 5885 | + ); | |
| 5886 | + } | |
| 5887 | + } | |
| 5888 | + } else { | |
| 5889 | + eprintln!("SKIP {NAME} ffmpeg arm: no ffmpeg"); | |
| 5890 | + } | |
| 5891 | + } | |
| 5892 | + | |
| 5402 | 5893 | /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis |
| 5403 | 5894 | /// (`BLOCK_64X128`) intra block -- the shape libaom's `read_tx_size` forces |
| 5404 | 5895 | /// to `TX_4X4` on its very first line (`decodeframe.c:1183`), so every plane |
lanes/av1422filter.report.mdadded+109 -0
| @@ -0,0 +1,109 @@ | ||
| 1 | +# lane-av1-422filter — the 4:2:2 loop-filter chroma class: NAMED and FIXED | |
| 2 | + | |
| 3 | +## Outcome | |
| 4 | + | |
| 5 | +1. REMEASURED first (pinned fixture `/tmp/t422.obu` sha256 | |
| 6 | + `d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129`, | |
| 7 | + single-frame cut `/tmp/t422f0.obu` sha256 | |
| 8 | + `3dd3f768ef553c02316848c2d3184c3765030c0a6fcb95887e4719add9ded3af`, | |
| 9 | + 256x144 / chroma 128x144, local `EC_AV1_ALLOW_422_PROBE` bypass applied | |
| 10 | + and reverted byte-identical after): with `EC_AV1_PREFILT_DUMP` / | |
| 11 | + `EC_AV1_POSTDEBLOCK_DUMP` / `EC_AV1_POSTCDEF_DUMP` / `EC_AV1_FINAL_DUMP` | |
| 12 | + on both sides, the frame-0 pre-filter AND post-deblock planes are | |
| 13 | + byte-exact (deblock did identical work both sides: 797/637/727 samples | |
| 14 | + changed, same set) — the 1236/1263 final chroma diffs are introduced | |
| 15 | + AFTER deblock. Attribution ladder, ours vs the instrumented aomdec: | |
| 16 | + | |
| 17 | + | stage | Y | U | V | | |
| 18 | + |----------------------|------------|-----------------|-----------------| | |
| 19 | + | pre-filter | 0 | 0 | 0 | | |
| 20 | + | post-deblock | 0 | 0 | 0 | | |
| 21 | + | post-CDEF | 0 | **251** (50,0) | **259** (48,0) | | |
| 22 | + | final | 0 | **1236→253** | **1263→266** | | |
| 23 | + | |
| 24 | + (the pre-fix row shows the parent's numbers; the ticket's first final | |
| 25 | + sample V (48,0) is literally the first post-CDEF defect sample.) | |
| 26 | +2. The oracle had NO 8-bit post-CDEF rung (its `EC_AV1_POSTCDEF_DUMP` was | |
| 27 | + 16-bit only; the earlier `aom/pcd.f0` measurement was actually its | |
| 28 | + post-deblock output — the rung had to be re-derived to isolate CDEF from | |
| 29 | + LR). Added an 8-bit `EC_AV1_POSTCDEF_DUMP` twin to the oracle's | |
| 30 | + `decodeframe.c` (right after the `do_cdef` block, full aligned buffer, | |
| 31 | + same shape as the POSTDEBLOCK rung) and rebuilt | |
| 32 | + `$HOME/.cache/aom-oracle/build` aomdec with ninja. The CDEF verdict was | |
| 33 | + then direct: 251/259 samples, first exactly U (50,0) / V (48,0). | |
| 34 | +3. DEFECT 1 (the big one) — **the 4:2:2 LR boundary-band snapshot is taken | |
| 35 | + on a 4:2:0 stripe grid**. `plane_snapshot` copies only the 4-row bands | |
| 36 | + LR's stripe substitution reads (`stripe_h - offset` per 64 rows); the | |
| 37 | + chroma calls hardcoded `ss_y = 1`, so for 4:2:2 (chroma stripes on the | |
| 38 | + luma 64-row grid, offset 8) the bands landed at rows 26/60/92/124 while | |
| 39 | + LR read rows 54..57/118..121 — every boundary substitution read | |
| 40 | + uninitialised scratch (zeros): 999 U / 963 V samples filtered where aom | |
| 41 | + filters nothing, |delta| up to 24 at the top rows. Fixed at all three | |
| 42 | + sites of the class: the keyframe and inter non-pipelined | |
| 43 | + `plane_snapshot(&u/&v, ss_y(fctx))`, the pipeline's `snap_band` band rows | |
| 44 | + `(j*64) >> ss_y`, and `pipe_run_lr`'s chroma `dims` (plane extents | |
| 45 | + `round_ss`, ss carried, not `div_ceil(2)`+1). 4:2:0 is bit-identical | |
| 46 | + (ss_y=1 reproduces the old bands/rows/dims exactly). | |
| 47 | +4. DEFECT 2 — **the CDEF chroma direction remap was missing**. libaom | |
| 48 | + `av1_cdef_filter_fb` (cdef_block.c) remaps the luma direction through | |
| 49 | + `conv422 = [7,0,2,4,5,6,6,6]` (in place; V then inherits U's remapped | |
| 50 | + grid) whenever `xdec != ydec` — the direction grid lives on the | |
| 51 | + subsampled chroma grid. The port filtered chroma with the raw luma | |
| 52 | + direction: after the LR fix the residual was exactly the CDEF stage, | |
| 53 | + 251/259 samples all ±1/±2 (168 we-filtered-aom-doesn't, 71 | |
| 54 | + aom-filters-we-don't, 12 value diffs on shared samples; scalar and AVX2 | |
| 55 | + kernels byte-identical, so shared logic, not the SIMD path). Fixed with | |
| 56 | + `CDEF_DIR_CONV422`/`CDEF_DIR_CONV440` applied for `(ss_x, ss_y)` = | |
| 57 | + (1,0)/(0,1); 4:2:0 and 4:4:4 take `_ => dir` unchanged. | |
| 58 | +5. MEASURED after both fixes: **frame 0 of the pinned 4:2:2 fixture is | |
| 59 | + byte-exact vs the oracle at PREFILT, POSTDEBLOCK, POSTCDEF and FINAL on | |
| 60 | + Y, U and V** (0 diffs everywhere). Non-vacuity on this frame: | |
| 61 | + `chroma422_square` = 24, `chroma422_rect` = 96, `chroma422_sub8` = 26 — | |
| 62 | + the touched 422 arms provably ran. Instrument for the LR half: a python | |
| 63 | + re-computation of the stripe walk + `lr_src_row` substitution + the | |
| 64 | + port's own wiener rounding reproduced the oracle's post-LR chroma plane | |
| 65 | + EXACTLY from the oracle's post-CDEF input (0 mismatches), which pinned | |
| 66 | + the residual defect to the snapshot input, not the filter math. | |
| 67 | +6. REMAINING: none for this class. The `read_coeffs_rect` frame-9 scratch | |
| 68 | + panic (inter frames of the 22-frame stream) is untouched, as chartered. | |
| 69 | + | |
| 70 | +## Decision | |
| 71 | + | |
| 72 | +- The header refusal STAYS unconditional in `stream.rs` — the probe bypass | |
| 73 | + was local-only, applied and reverted byte-identical before the commit | |
| 74 | + (`git diff` after the revert carries only the decode.rs fix); the | |
| 75 | + refusal-by-name gate re-verified firing. | |
| 76 | +- `read_coeffs_rect` untouched. The 4:2:0 group-tail SKIP arm untouched. | |
| 77 | + `sub8_leaf_chroma422` (parent lane's three fixes) untouched. | |
| 78 | +- The 8-bit `EC_AV1_POSTCDEF_DUMP` rung was added to the ORACLE's source | |
| 79 | + tree (`$HOME/.cache/aom-oracle/src/av1/decoder/decodeframe.c`, rebuilt | |
| 80 | + with ninja), not to this repo's `scripts/instrument-aom-oracle.sh` — the | |
| 81 | + script's generator should grow the same patch if the oracle is ever | |
| 82 | + rebuilt from scratch. | |
| 83 | + | |
| 84 | +## Verification | |
| 85 | + | |
| 86 | +- `cargo check -p ec-av1` (target `~/.cache/cargo-target-av1422filter`): | |
| 87 | + 0 warnings, 0 errors. | |
| 88 | +- Frame-0 stage dumps, ours vs the instrumented aomdec (cropped | |
| 89 | + comparisons; our stage dumps are 256x160/128x160 padded, the oracle's | |
| 90 | + cropped 256x144/128x144 — the comparator crops): all four stages, all | |
| 91 | + three planes, 0 diffs. | |
| 92 | +- 420 gates green (all with the fix in place): | |
| 93 | + `stream::tests::a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ | |
| 94 | + whose_tx_split_decodes_pixel_exact` under `EC_AV1_REQUIRE_AOMENC=1` | |
| 95 | + (1 passed), `stream::tests::a_real_aomenc_stream_with_restoration_reads_ | |
| 96 | + lr_symbols_correctly` (1 passed — the LR-snapshot regression gate), | |
| 97 | + `a_superres_key_frame_with_cdef_and_loop_restoration_decodes_pixel_exact` | |
| 98 | + (1 passed), `a_non_420_subsampled_sequence_header_is_refused_by_name` | |
| 99 | + (1 passed). | |
| 100 | +- Scalar-vs-AVX2 CDEF chroma A/B on this frame: 0 diffs between kernels | |
| 101 | + (the 4x8 chroma shape was already SIMD-faithful; the defect was the | |
| 102 | + direction input). | |
| 103 | + | |
| 104 | +## State | |
| 105 | + | |
| 106 | +- Commit on lane-av1-422filter (no push): the LR snapshot ss_y fix (three | |
| 107 | + sites) + the CDEF conv422 direction remap + this report. | |
| 108 | +- The instrumented oracle build at `$HOME/.cache/aom-oracle/build` now | |
| 109 | + carries the 8-bit `EC_AV1_POSTCDEF_DUMP` rung for future lanes. |
lanes/av1444sb.report.mdadded+115 -0
| @@ -0,0 +1,115 @@ | ||
| 1 | +# lane-av1-444sb — the 128-rect 4:4:4 chroma-span desync: NAMED and FIXED (r2) | |
| 2 | + | |
| 3 | +## Outcome | |
| 4 | + | |
| 5 | +1. REMEASURED first (pinned fixture | |
| 6 | + `crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu`, sha256 | |
| 7 | + `27825e14633a4b23e37d48a2acdc7f5d814ca4fadd0b8797d72a1ffb34061e80`, | |
| 8 | + generated per the report recipe: `ffmpeg -i bands444.y4m -frames:v 3 -vf | |
| 9 | + scale=192:160 -pix_fmt yuv444p -f yuv4mpegpipe` piped to | |
| 10 | + `aomenc --codec=av1 --profile=1 --passes=1 --end-usage=q --cq-level=32 | |
| 11 | + --cpu-used=0 --threads=1 --row-mt=0 --sb-size=128 --lag-in-frames=0 | |
| 12 | + --auto-alt-ref=0 --kf-max-dist=1000 --i444 --enable-restoration=1 --obu | |
| 13 | + --limit=3`): at 76f8c3fe frame 0 diverges at EC_AV1_PREFILT_DUMP with | |
| 14 | + Y 9700 @ (128,64), U 12272 @ (160,0), V 13175 @ (128,0) — the ticket's | |
| 15 | + class (first diffs on the 64/128 grid, chroma columns 160/128 matching | |
| 16 | + the finding). The synthetic-content variants tried first (testsrc2, | |
| 17 | + testsrc, smptebars, mandelbrot, gradients × cpu-used × cq) all decode | |
| 18 | + frame 0 exact — the damage needs an edge-forced 128-root rect, which | |
| 19 | + real content provides. | |
| 20 | +2. DEFECT 1 (this lane's, FIXED) — **`decode_block_128rect`'s chroma unit | |
| 21 | + walk is hardcoded to the 4:2:0 mu-chunk span**. One 32x32 chroma unit per | |
| 22 | + 64x64 mu chunk per plane (`cn = 32 / chroma_tx` = 1), chunk offsets | |
| 23 | + `ch_col * 32` / `ch_row * 32`, and a per-chunk clip step of `ch_col * 8`: | |
| 24 | + all three are the 4:2:0 numbers. At 4:4:4 a 64x64 luma chunk covers 64 | |
| 25 | + chroma pixels and needs TWO 32x32 units per axis. The units never pushed | |
| 26 | + (measured by env-gated per-unit exec tracing): (160,0),(160,32) of the | |
| 27 | + 64x128 PART_VERT block at (128,0), all four units of its second chunk, | |
| 28 | + (64,128),(96,128) of the bottom-row 128x64 — exactly the PREFILT damage | |
| 29 | + cells. Because the missing units' coefficients are still in the | |
| 30 | + bitstream, the entropy decoder desyncs from the first 128-rect intra | |
| 31 | + block on: SB(0,0) decodes byte-exact and every later superblock of | |
| 32 | + frames 0/1 carries damage. | |
| 33 | +3. FIX (one site, decode.rs `decode_block_128rect`): per-chunk unit count | |
| 34 | + `(64 >> ss) / chroma_tx`, chunk chroma offsets `64 >> ss`, clip step | |
| 35 | + `16 >> ss` — every expression reduces to the old constant at ss=1, so | |
| 36 | + 4:2:0 is bit-identical by construction; the stale `debug_assert!` (which | |
| 37 | + stated the 4:2:0 invariant and would fire on 444 in debug builds) now | |
| 38 | + states the ss-aware one. | |
| 39 | +4. DEFECT 2 (fixed by CHERRY-PICK, not this lane's code) — after DEFECT 1's | |
| 40 | + fix the review still failed frames 1-2: frame 1 U/V full rows 54 and 118 | |
| 41 | + +-1 — the LR boundary-band signature. `lane-av1-422filter`'s e3798a34 | |
| 42 | + (LR boundary-band snapshot ss_y + CDEF conv422 remap) was NOT in this | |
| 43 | + branch's ancestry; cherry-picked as 168442bd. Frame 1 went byte-exact. | |
| 44 | + An r1 experiment had concluded the cherry-pick "changed nothing on 444" — | |
| 45 | + that conclusion was an artifact of a broken comparison (see 6) and is | |
| 46 | + retracted. | |
| 47 | +5. DEFECT 3 (NAMED, NOT FIXED — stop-with-site) — frame 2 still diverges at | |
| 48 | + FINAL: Y 7308 / U 9685 / V 14012 vs aomdec, deterministic. Stage ladder: | |
| 49 | + PREFILT, POSTDEBLOCK and POSTCDEF are byte-exact vs the oracle; the | |
| 50 | + damage is introduced by the LOOP RESTORATION stage, and its shape is | |
| 51 | + **LR stripe 0 (RU row 0, rows 0..63, full width, all three planes) is | |
| 52 | + never restored** — our final equals the post-CDEF plane above row 63 | |
| 53 | + (our LR-changed rows start at 63; the oracle's start at 0), while stripes | |
| 54 | + 1-2 are restored (imperfectly vs the oracle only through the reference | |
| 55 | + shift this induces in rows above? no: rows 64..159 also still differ — | |
| 56 | + the stripe-0 skip is the dominant, first-introduced defect; stripe | |
| 57 | + delta details in the r2 measurement notes). Site: the pipelined LR band | |
| 58 | + accounting — `pipe_run_lr`'s `rrows: Some` branch (restoration.rs) | |
| 59 | + refills only the RU rows its caller passes, and the band release | |
| 60 | + (`ls.note(k - 2)` / `ls.close(nb, false)`, decode.rs filter pipeline | |
| 61 | + ~25000-25032) never flushes RU row 0 on this frame — the frame whose top | |
| 62 | + superblock row carries a 128-root rect block (f2's inter 64x128 at | |
| 63 | + (128,0); f0's 128-rects sit on the keyframe path and f1 codes no | |
| 64 | + 128-root rect, which is why only f2 shows it). Fixing the flush is its | |
| 65 | + own scoped change; asserting f2's current samples in a gate would pin | |
| 66 | + the bug. | |
| 67 | +6. MEASUREMENT-METHOD CORRECTION (r1's false "all frames exact"): the r1 | |
| 68 | + final comparisons sliced the raw YUV with a plane-stride instead of a | |
| 69 | + frame-stride, so every "fN vs aomdec" row actually compared row 0 of | |
| 70 | + plane N — frame 2 was never truly compared and the 0-diff results were | |
| 71 | + an illusion. All r2 numbers above come from per-frame strided slices | |
| 72 | + (92160 bytes/frame), cross-checked against BOTH aomdec and ffmpeg, with | |
| 73 | + the binary's provenance pinned by a fresh-target-dir sha256 match | |
| 74 | + (incremental `Finished` in <2s does NOT imply a rebuild; `cargo clean | |
| 75 | + -p` without error checking can silently no-op — twice caught this wave). | |
| 76 | + | |
| 77 | +## Verification | |
| 78 | + | |
| 79 | +- `cargo check -p ec-av1`: 0 warnings, 0 errors | |
| 80 | + (target `$HOME/.cache/cargo-target-av1444sb`). | |
| 81 | +- New pinned gate (this commit): | |
| 82 | + `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact` — | |
| 83 | + pins the fixture by length + FNV1a64, proves non-vacuity via the | |
| 84 | + `decode::intra_sb128_hits` delta, and asserts frames 0/1 byte-exact | |
| 85 | + against BOTH the oracle aomdec and ffmpeg (frame 2 = DEFECT 3, named in | |
| 86 | + the test body; pinning its current samples would freeze the bug). | |
| 87 | +- Gates green with fix + cherry-pick (EC_AV1_REQUIRE_AOMENC=1): | |
| 88 | + `a_real_aomenc_stream_with_restoration_reads_lr_symbols_correctly`, | |
| 89 | + `a_superres_key_frame_with_cdef_and_loop_restoration_decodes_pixel_exact`, | |
| 90 | + `a_non_420_subsampled_sequence_header_is_refused_by_name`, | |
| 91 | + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_ | |
| 92 | + decodes_pixel_exact` — 4 passed. | |
| 93 | + | |
| 94 | +## Decision | |
| 95 | + | |
| 96 | +- DEFECT 1: one site, fixed. `decode_block_128rect` serves the kf PART128 | |
| 97 | + HORZ/VERT and AB arms plus the intra-in-inter 128 path (`in_inter` flag) | |
| 98 | + — one walk, all callers covered. | |
| 99 | +- DEFECT 2: fixed upstream-of-merge by cherry-pick (168442bd), kept. | |
| 100 | +- DEFECT 3: STOP-WITH-SITE per charter — the LR stripe-0 flush on inter | |
| 101 | + frames whose top SB row carries a 128-root rect. Named function/lines | |
| 102 | + above; the stage-dump evidence (PC exact, FINAL wrong, delta rows 63+) | |
| 103 | + is in the r2 notes. | |
| 104 | +- NOT touched: `sub8_leaf_chroma444`'s rect arm (sibling lane, distinct | |
| 105 | + open defect), `decode_leaf8` OOB (leaf8oob's), the 4:2:0 group-tail | |
| 106 | + chroma SKIP arm (reserved), `read_coeffs_rect`. | |
| 107 | +- Temp EC_TRACE_444SB / EREAD_RECT / TEMP-444SB instrumentation removed | |
| 108 | + before commit; the commits carry only the fix, the assert, the gate and | |
| 109 | + the reports. | |
| 110 | + | |
| 111 | +## State | |
| 112 | + | |
| 113 | +- Commits on lane-av1-444sb (no push): 349b3918 (DEFECT 1 fix + fixture + | |
| 114 | + r1 report), 168442bd (cherry-pick of e3798a34), this commit (DEFECT 3 | |
| 115 | + named, gate added/scoped, r2 report). |
lanes/av1444sbf2.report.mdadded+74 -0
| @@ -0,0 +1,74 @@ | ||
| 1 | +# lane-av1-444sbf2 — the 444sb witness f2 after d5325172: NOT exact; residual re-measured sample-identical to DEFECT A; gate NOT extended (r1) | |
| 2 | + | |
| 3 | +## Outcome | |
| 4 | + | |
| 5 | +1. Gate-extension precondition FAILED — frame 2 is not byte-exact, so | |
| 6 | + `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact` stays at | |
| 7 | + `take(2)`. Measured at HEAD 85ce04de (48411287 + the d5325172 cherry-pick) | |
| 8 | + with the pinned fixture (`crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu`, | |
| 9 | + sha256 re-verified `27825e14633a4b23e37d48a2acdc7f5d814ca4fadd0b8797d72a1ffb34061e80`), | |
| 10 | + a FRESH target dir (`cargo-target-av1444sbf2` did not exist before this lane; | |
| 11 | + probe binary sha256 | |
| 12 | + `9f50af10a11fb77a3461e35427e75e616e29c3ff0403978db4a503e4ccecde3f`), and | |
| 13 | + per-frame strided slices (92160 bytes/frame, W*H*3, planes Y/U/V at | |
| 14 | + 0/30720/61440). Frame 2 vs BOTH oracles: **Y 7308 / U 9685 / V 13854**, and | |
| 15 | + the two oracles agree with each other sample-for-sample on all three frames | |
| 16 | + (ours is the diverging side; no measurement-method ambiguity this time). | |
| 17 | + Frames 0/1: byte-exact vs both. | |
| 18 | +2. Stage ladder (instrumented oracle + ours, decode-order `.fN` dumps, 92160-byte | |
| 19 | + crop-shaped files on both sides, default serial filter path): f0/f1 EXACT at | |
| 20 | + PREFILT, POSTDEBLOCK, POSTCDEF and FINAL. f2 diverges already at **PREFILT** — | |
| 21 | + Y 6952 / U 9568 / V 13496, first diffs Y (col 128, row 98), U (col 128, | |
| 22 | + row 64), V (col 128, row 0) — i.e. in reconstruction, BEFORE any loop filter. | |
| 23 | + The filters only carry the damage downstream: POSTDEBLOCK 6956/9568/13614, | |
| 24 | + POSTCDEF 7307/9685/13722, FINAL 7308/9685/13854. | |
| 25 | +3. The residual is UNCHANGED by d5325172. av1lrflush r3 measured the identical | |
| 26 | + ladder at base 48411287 (without the cherry-pick): PREFILT 6952/9568/13496 | |
| 27 | + with the same three first-diff samples, POSTCDEF 7307/9685/13722 — every rung | |
| 28 | + I can cross-check matches my with-fix numbers exactly. The inter 1:4 strip | |
| 29 | + chroma pair-rewrite fix (its t6 class) is inert on this fixture: f2's damage | |
| 30 | + is a different (or wider) instance of the same inter rect-strip class, not | |
| 31 | + the one d5325172 fixed. (The old r2 "FINAL V 14012" was r3's identified | |
| 32 | + one-rung-off comparison artifact, not a fix effect.) | |
| 33 | +4. Site (STOP-WITH-SITE, unchanged from av1lrflush r3's DEFECT A): the inter | |
| 34 | + rect-strip entropy/recon path on f2's inter 64x128 block at (128,0) — all | |
| 35 | + three planes' first diffs enter at column 128 inside that block and | |
| 36 | + everything downstream carries it. There is no entropy desync: both decoders | |
| 37 | + consume the full stream and complete the frame with bounded diffs, so the | |
| 38 | + symbol reads are identical and the divergence is in the strip's | |
| 39 | + reconstruction / band-stamping reads — Agent044's `decode_rect4_16_strip` | |
| 40 | + territory (their t6-adjacent class). r2's LR-stripe-0 attribution stays | |
| 41 | + refuted (av1lrflush r3); the gate's scoping comment naming it is now stale | |
| 42 | + but is deliberately left untouched here: per av1lrflush r3 §6 the comment | |
| 43 | + fix and the `take(3)` extension land together in the SAME deferred edit | |
| 44 | + once the entropy fix actually clears f2 — a comment-only commit on another | |
| 45 | + lane's gate would split that pairing. | |
| 46 | +5. No decoder edit on this lane: 4:2:0 identity untouched by construction; no | |
| 47 | + cargo check owed. | |
| 48 | + | |
| 49 | +## Verification | |
| 50 | + | |
| 51 | +- `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact` | |
| 52 | + (unmodified): PASS at this HEAD — f0/f1 pins intact, non-vacuity | |
| 53 | + `intra_sb128_hits` delta fires (target `cargo-target-av1444sbf2`). | |
| 54 | +- Ladder + slice numbers above produced from that same fresh target dir; the | |
| 55 | + throwaway decode example and all `/tmp` dumps were deleted before commit. | |
| 56 | +- Both oracle references regenerated this session (aomdec | |
| 57 | + `~/.cache/aom-oracle/build` binary, 2026-09-25 17:46; ffmpeg 8.1.2) and | |
| 58 | + cross-agreed before any diff was trusted. | |
| 59 | + | |
| 60 | +## Decision | |
| 61 | + | |
| 62 | +- Gate NOT extended (assignment branch 2: "do not extend … do not pin wrong | |
| 63 | + samples"). Asserting f2's current samples would freeze DEFECT A into the | |
| 64 | + gate. | |
| 65 | +- Next owner: the entropy lane (inter rect-strip band stamping, | |
| 66 | + `decode_rect4_16_strip`). Re-run THIS measurement (stage ladder + per-frame | |
| 67 | + strided slices + fresh target dir, both oracles) after that fix lands; extend | |
| 68 | + `take(2)`→`take(3)` and fix the stale scoping comment in the same edit only | |
| 69 | + when f2 goes byte-exact. | |
| 70 | + | |
| 71 | +## State | |
| 72 | + | |
| 73 | +- Commit on lane-av1-444sbf2 (no push): this report only; production tree | |
| 74 | + untouched since 85ce04de. |
lanes/av1ll64.report.mdadded+108 -0
| @@ -0,0 +1,108 @@ | ||
| 1 | +# lane-av1-ll64: the rect64-route 64x32 chroma row — named, not invented (r1) | |
| 2 | + | |
| 3 | +## Ticket | |
| 4 | + | |
| 5 | +Default-partition lossless 4:4:4 stops at a missing 64x32 chroma lossless | |
| 6 | +coefficient row on the rect64 route (the `EC_RECTCHROMA_GAP luma=64x32 | |
| 7 | +tx=4x4 chroma=64x32` diagnostic `lane-av1-llinter2` deferred here). Name | |
| 8 | +the row; add it only if libaom has that transform; do not invent one. | |
| 9 | +`decode_rect4_16_strip` is off-limits (owned by the lossless-444 strip | |
| 10 | +lane). | |
| 11 | + | |
| 12 | +## The named row | |
| 13 | + | |
| 14 | +The `chroma` match in `decode_rect_split` (decode.rs:10086) has no | |
| 15 | +`(64, 32)`/`(32, 64)` arm: a 4:4:4 64-axis strip's chroma plane block | |
| 16 | +cannot be coded as ONE rect unit here. That missing arm is the row the | |
| 17 | +gap print names. | |
| 18 | + | |
| 19 | +## libaom verdict (oracle source, measured): no such transform — row NOT added | |
| 20 | + | |
| 21 | +- Lossless: `av1_get_tx_size` returns TX_4X4 for EVERY plane | |
| 22 | + (`av1/common/blockd.h:1383`), so a 64x32 chroma plane block codes as a | |
| 23 | + plane-major raster of TX_4X4 units (16x8 = 128 per plane at 4:4:4). | |
| 24 | + There is no 64x32 lossless transform at all. | |
| 25 | +- Non-lossless: `av1_get_max_uv_txsize` routes chroma through | |
| 26 | + `av1_get_adjusted_tx_size` (`blockd.h:1361-1367`), which collapses | |
| 27 | + TX_64X32 and TX_32X64 to TX_32X32. A chroma transform wider/taller | |
| 28 | + than 32 is never one coded unit. | |
| 29 | + | |
| 30 | +Per ticket step 3: libaom marks the single-unit 64x32 chroma transform | |
| 31 | +not-codeable ⇒ STOP; no row invented. | |
| 32 | + | |
| 33 | +## The route truth: nothing stops at HEAD — the print was a false gap | |
| 34 | + | |
| 35 | +`decode_rect_split`'s arms already cover every shape that reaches it: | |
| 36 | + | |
| 37 | +- LOSSLESS: the 4x4 walk (decode.rs `else if lossless(fctx)`) is | |
| 38 | + shape-agnostic — for a (64,32) chroma block it walks 128 plane-major | |
| 39 | + `TxbSet::Chroma4` units with `4 << ss` spans, which IS the libaom | |
| 40 | + behavior above. The same code the key-frame gate proves on 16x8 | |
| 41 | + strips. | |
| 42 | +- Non-lossless: `chroma_tiled` tiles those four shapes as 32x32 / | |
| 43 | + 32x16 units (the 10-bit film gates' verified path). | |
| 44 | + | |
| 45 | +The old diagnostic fired whenever `chroma` was None and `!m.skip` — | |
| 46 | +INCLUDING on those two working routes, printing a "GAP" for shapes the | |
| 47 | +function decodes correctly. That false print is what `lane-av1-llinter2`'s | |
| 48 | +report cited as a "named non-panic stop" of default-partition `ll444.obu`. | |
| 49 | + | |
| 50 | +## Change (one diagnostic, no decode-path edit) | |
| 51 | + | |
| 52 | +decode.rs only: the `EC_RECTCHROMA_GAP` print's condition is now the | |
| 53 | +refusal's exact precondition (`chroma.is_none() && !chroma_tiled` inside | |
| 54 | +the existing `!m.skip`, so print↔refusal can never diverge), and its | |
| 55 | +message states the libaom verdict (`libaom_lossless_tx=none`). The | |
| 56 | +inventory-pinned refusal wording is byte-identical; every coefficient | |
| 57 | +read, CDF, span and neighbour stamp untouched. `chroma_tiled`'s `let` | |
| 58 | +moved above its new first use; its explanatory comments stay with it. | |
| 59 | +4:2:0: zero-change (a 64x32 luma strip is 32x16 chroma there — a row | |
| 60 | +that always existed; the print never fired at 4:2:0). | |
| 61 | + | |
| 62 | +## Verification (measured, this tree @ HEAD + this change) | |
| 63 | + | |
| 64 | +- Encoder sweep (aomenc `--lossless=1 --profile=1`, palette/intrabc off, | |
| 65 | + contents from testsrc2 to forced HORZ-biased noise, `--cpu-used` 0..8, | |
| 66 | + partition caps, bottom-edge smooth bands): NO lossless fixture presents | |
| 67 | + a 64x32 intra strip — at lossless RD the encoder picks NONE/SPLIT, so | |
| 68 | + the print never fired on any stream, old or new. | |
| 69 | +- Probes post-change (decode_probe): `ll444.obu` (default partition, 6 | |
| 70 | + frames) OK 6/6; `force_kf.obu`, `h2.obu` OK; committed | |
| 71 | + `lossless_sb128_rect_kf.obu` OK 4/4; pinned `ll444_minp64_inter.obu` | |
| 72 | + OK 6/6; `EC_RECTCHROMA` count 0 on every stream. | |
| 73 | +- Gates (7 passed, 0 failed): `a_lossless_444_min_partition64_inter_ | |
| 74 | + stream_decodes_pixel_exact` (6-frame inter gate: pixel-exact through | |
| 75 | + BOTH oracle aomdec --rawvideo and ffmpeg, counter non-vacuity), | |
| 76 | + `a_real_aomenc_lossless_444_key_frame_decodes_sample_exact` (run for | |
| 77 | + real, not SKIP: pinned bytes `fixtures/ll444-lossless-key.obu` copied | |
| 78 | + from the av1llband2 worktree, sha256 `9fc9ce1f5f6475a1d483f404b44acb9 | |
| 79 | + 0f72a80be2e5c51dedf0aeb1da9a3f5dc`; fixtures/ is gitignored, nothing | |
| 80 | + committed from it), both 4:2:0 lossless gates | |
| 81 | + (`a_lossless_libaom_key_frame_decodes_sample_exact`, | |
| 82 | + `a_lossless_libaom_inter_frame_decodes_sample_exact`), both | |
| 83 | + `a_lossless_sb128_*` gates, `a_lossless_16x4_chroma_pair_*`. | |
| 84 | +- `cargo check -p ec-av1 --all-targets` (target dir | |
| 85 | + `$HOME/.cache/cargo-target-av1ll64`): 0 warnings, 0 errors. | |
| 86 | + | |
| 87 | +## Same-class suspects, measured on scratch streams, deferred (spoken) | |
| 88 | + | |
| 89 | +Repro recipe (scratch, regenerable): `testsrc2 128x96 yuv444p`, aomenc | |
| 90 | +`--profile=1 --lossless=1 --enable-palette=0 --enable-intrabc=0`, | |
| 91 | +`--max-partition-size=64`, 6 frames. Both defects verified PRE-EXISTING | |
| 92 | +at 2ac149e3 via `git stash` probe, so neither is caused by this change; | |
| 93 | +both are the inter sub8 lossless class (a lossless inter route coding a | |
| 94 | +rect TX unit where `av1_get_tx_size` forces TX_4X4 per plane — the | |
| 95 | +`decode_inter_block8`/84acbd09 defect class one route over): | |
| 96 | + | |
| 97 | +- `decode_inter_sub8_rect2` → `read_inter_plane_rect` → | |
| 98 | + `push_mc_rect_tx` → `TxParams::run` lossless WHT assert | |
| 99 | + `(8, 4) != (4, 4)` at decode.rs:2566. deferred(fix-now in the lane | |
| 100 | + owning the inter sub8 lossless rect route; the fix shape is the | |
| 101 | + established per-plane TX_4X4 unit walk). | |
| 102 | +- The 12-frame sibling stream refuses mid-tile: `REFUSED: unsupported: | |
| 103 | + AV1 tile (a Golomb tail longer than this decoder reads)` — same | |
| 104 | + route class, downstream desync form. deferred(with the same lane; | |
| 105 | + likely disappears when the (8,4) read is fixed). | |
| 106 | + | |
| 107 | +`decode_rect4_16_strip`'s 4:2:0-hardcoded lossless chroma walk remains | |
| 108 | +with its owning lane (untouched here, per lane ownership). |
lanes/av1llband2.report.mdadded+90 -0
| @@ -0,0 +1,90 @@ | ||
| 1 | +# lane-av1-llband2: 4:4:4 lossless above-band cell — sibling fix ported (r1) | |
| 2 | + | |
| 3 | +## Charter | |
| 4 | + | |
| 5 | +Resolve the `av1llsub8` stop (aligned step 19228: 16x8 leaf, U unit bc=2 | |
| 6 | +br=0, `txb_skip` base 1 vs oracle base 0 — an above-band cell). Port the | |
| 7 | +already-reviewed sibling fix if it is the same writer; never author a | |
| 8 | +second fix for the same defect. 4:2:0 lossless stays exact. Work in | |
| 9 | +`edith_codecs-av1llband2` @ 6cf92769. | |
| 10 | + | |
| 11 | +## Writer identification (done before any edit) | |
| 12 | + | |
| 13 | +Read `edith_codecs-av1llband` r1 (`lanes/av1llband.report.md`) and commit | |
| 14 | +`01a34bc8` before writing anything. That sibling took the exact same stop | |
| 15 | +(178-byte key-frame miss, first divergence at the 16x8 leaf mi (16,24)'s | |
| 16 | +U bc=2 unit) to **0 differing bytes**, and was reviewed. | |
| 17 | + | |
| 18 | +Same-writer proof: | |
| 19 | + | |
| 20 | +- This branch HEAD is the sibling's parent commit `6cf92769` byte-for-byte | |
| 21 | + (both continue `av1llsub8`). | |
| 22 | +- The defect site in THIS tree is the identical code the sibling named: | |
| 23 | + `decode_rect_split`'s lossless chroma arm hardcoding the 4:2:0 unit span | |
| 24 | + — `let luma_span = 8;` at `decode.rs:10458` here, feeding the `cu_mi` | |
| 25 | + step, `around_mi`, `tu_reach` and both `record_mi_chroma` stamps. | |
| 26 | +- The stop signature matches the sibling's reproduced defect exactly | |
| 27 | + (step 19228, 16x8 leaf, U bc=2 br=0, base 1 / row `[0][11]` vs oracle | |
| 28 | + base 0 / row `[0][10]`). | |
| 29 | + | |
| 30 | +⇒ `01a34bc8` IS that writer's fix. Ported it; no second fix invented. | |
| 31 | + | |
| 32 | +## Port (faithful, byte-identical) | |
| 33 | + | |
| 34 | +`git cherry-pick -n 01a34bc8`, dropping the sibling's lane report file | |
| 35 | +(`lanes/av1llband.report.md` — this lane writes its own). Post-images of | |
| 36 | +all three source files `cmp`-verified IDENTICAL against the sibling | |
| 37 | +worktree at `01a34bc8`: | |
| 38 | + | |
| 39 | +- `crates/ec-av1/src/decode.rs` (+45/−10): `span_x = 4 << ss_x(fctx)`, | |
| 40 | + `span_y = 4 << ss_y(fctx)` replaces the hardcoded 8 for the `cu_mi` | |
| 41 | + step, `around_mi_rect`, `tu_reach`, the immediate and replayed | |
| 42 | + `record_mi_chroma` stamps (`ll_chroma_units` carries per-unit spans); | |
| 43 | + non-vacuity counter `RECT_SPLIT_LOSSLESS_CHROMA444_HITS` + | |
| 44 | + `rect_split_lossless_chroma444_hits()`. | |
| 45 | +- `crates/ec-av1/src/stream.rs` (+77): gate | |
| 46 | + `a_real_aomenc_lossless_444_key_frame_decodes_sample_exact` over the | |
| 47 | + pinned fixture, with the lossless-frame blindness guard and the | |
| 48 | + counter-moved non-vacuity assert. | |
| 49 | +- `crates/ec-av1/examples/decode_probe.rs` (+4): `llband:` counter line. | |
| 50 | + | |
| 51 | +Off-limits files untouched: `decode_rect4_16_strip`, | |
| 52 | +`read_inter_rect_chroma`, `restoration.rs`, intra write-back. No 422 | |
| 53 | +model, no luma path, no `sub8_leaf_chroma444` (innocent: the 16x8 leaf | |
| 54 | +never reaches it). 4:2:0 arithmetic is unchanged (`4 << 1 = 8`). | |
| 55 | + | |
| 56 | +Fixture provenance: `fixtures/ll444-lossless-key.obu` (untracked, as in | |
| 57 | +the sibling), copied from the sibling worktree, sha256 | |
| 58 | +`9fc9ce1f5f6475a1d483f404b44acb90f72a80be2e5c51dedf0aeb1da9a3f5dc` | |
| 59 | +(4927 B; cut of the `ll444` recipe's key-frame OBUs: `testsrc2 128x96` | |
| 60 | +yuv444p, `aomenc --profile=1 --lossless=1 --enable-palette=0 | |
| 61 | +--enable-intrabc=0`, oracle build `~/.cache/aom-oracle`). | |
| 62 | + | |
| 63 | +## Verification (measured, this tree) | |
| 64 | + | |
| 65 | +- New gate `a_real_aomenc_lossless_444_key_frame_decodes_sample_exact`: | |
| 66 | + **green** — key frame decodes **0 differing bytes** (sample-exact, | |
| 67 | + all 3 planes vs ffmpeg `yuv444p` rawvideo, 36864 samples compared) and | |
| 68 | + the counter moved (non-vacuity). | |
| 69 | +- `decode_probe` on the pinned fixture: `llband: | |
| 70 | + rect_split_lossless_chroma444=160` (matches the sibling's 160 units), | |
| 71 | + no panic. | |
| 72 | +- 4:2:0 lossless stays green: | |
| 73 | + `a_lossless_libaom_key_frame_decodes_sample_exact`, | |
| 74 | + `a_lossless_libaom_inter_frame_decodes_sample_exact` — both ok | |
| 75 | + (3 passed, 0 failed in the gate run). | |
| 76 | +- `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors. | |
| 77 | + | |
| 78 | +## Deferred (spoken, not hidden) | |
| 79 | + | |
| 80 | +- **1:4 strips at lossless 4:4:4** (`decode_rect4_16_strip`): same span | |
| 81 | + defect class (per the sibling's r1), but the file is owned by a live | |
| 82 | + lane and off-limits to this branch — the fix is the same span | |
| 83 | + derivation measured here. deferred(fix-now in the owning lane). | |
| 84 | +- Lossless INTER frames panic at `reconstruct_mc_rect` (decode.rs:2589): | |
| 85 | + `read_inter_rect_chroma`'s branch, untouched, as chartered. | |
| 86 | + deferred(fix-now in the owning lane). | |
| 87 | +- Intrabc rect leaves at lossless 444 still route the rect arm's | |
| 88 | + `read_coeffs_rect` path: unreachable with `--enable-intrabc=0` | |
| 89 | + fixtures. deferred(fix-now after the inter side is green, with an | |
| 90 | + intrabc 4:4:4 fixture), matching `av1llsub8`/`av1llband`. |
lanes/av1llinter2.report.mdadded+101 -0
| @@ -0,0 +1,101 @@ | ||
| 1 | +# lane-av1-llinter2: 4:4:4 lossless inter side — sibling panic ported (r1) | |
| 2 | + | |
| 3 | +## Charter | |
| 4 | + | |
| 5 | +The lossless INTER panic named by `av1llband2` (`reconstruct_mc_rect`, | |
| 6 | +decode.rs:2589, `read_inter_rect_chroma`'s branch) is the same panic | |
| 7 | +sibling lane `av1llinter` fixed in 84acbd09 + 13a262a6. Port that fix; | |
| 8 | +never author a second fix for the same defect. 4:2:0 lossless stays | |
| 9 | +identical; the key-frame gate stays green. Work in | |
| 10 | +`edith_codecs-av1llinter2` @ 6da581a8. | |
| 11 | + | |
| 12 | +## Same-panic proof (measured, before any edit) | |
| 13 | + | |
| 14 | +Repro on the sibling's pinned bytes `dodge2.obu` (37658 B, sha256 | |
| 15 | +`5a070fa351a3f2109de855234f2b3d0a872970f3e7f658db21f65c12eeb135b4` — | |
| 16 | +byte-identical to the sibling's committed | |
| 17 | +`crates/ec-av1/fixtures/ll444_minp64_inter.obu`): | |
| 18 | + | |
| 19 | +- RELEASE build: `panicked at crates/ec-av1/src/decode.rs:28454:32: | |
| 20 | + range end index 24 out of range for slice of length 16` in `exec_mc` — | |
| 21 | + line 28454 is `reconstruct_mc_rect`'s coded-arm `dst..dst + w` index | |
| 22 | + (fn at 28413), inlined into `exec_mc`. The sibling's parent-tree panic | |
| 23 | + was the identical message and numbers at their decode.rs:28336, same | |
| 24 | + fn, same inline frame. | |
| 25 | +- DEBUG build: the underlying unit defect surfaces first — the lossless | |
| 26 | + WHT assert `(8, 8) != (4, 4)` at `TxParams::run` (decode.rs:2566), via | |
| 27 | + `decode_inter_block8 -> read_inter_plane -> push_mc_rect_tx` — the | |
| 28 | + sibling report's exact chain. The band2 report's "decode.rs:2589" | |
| 29 | + citation is this same worker (`strided[row * self.stride..][..self.w]`, | |
| 30 | + the release-form panic of the same 8-wide lossless unit); the | |
| 31 | + "reconstruct_mc_rect" name is the release-build site proven above. | |
| 32 | + | |
| 33 | +⇒ same defect, same root cause the sibling named: the 8x8 inter leaf's | |
| 34 | +chroma plane block read as ONE TX_8X8 unit where lossless codes TX_4X4 | |
| 35 | +on every plane (`av1_get_tx_size`). 84acbd09 IS the writer's fix. | |
| 36 | +Ported it; no second fix invented. | |
| 37 | + | |
| 38 | +## Port (faithful cherry-pick of 84acbd09, three deliberate deltas) | |
| 39 | + | |
| 40 | +`git cherry-pick -n 84acbd09`: | |
| 41 | + | |
| 42 | +1. `decode_rect_split` conflicts (fix 4) resolved to THIS tree's version: | |
| 43 | + lane-av1-llband2 already ported that exact fix (01a34bc8) with the | |
| 44 | + `RECT_SPLIT_LOSSLESS_CHROMA444_HITS` non-vacuity counter; semantics | |
| 45 | + identical (`4 << ss` spans, span-carrying `ll_chroma_units`). | |
| 46 | +2. **fix 5 EXCLUDED**: its three hunks are inside | |
| 47 | + `decode_rect4_16_strip` (the `cu_mi` divisor and both | |
| 48 | + `record_mi_chroma` spans), a function owned by a live lane — reverted | |
| 49 | + to HEAD byte-for-byte. The strip fn still carries the 4:2:0-hardcoded | |
| 50 | + walk at 4:4:4 lossless: deferred(fix-now in the owning lane, same | |
| 51 | + span derivation as fixes 2-4). | |
| 52 | +3. The sibling's lane report file dropped; this lane writes its own. | |
| 53 | + | |
| 54 | +Applied verbatim: fix 1 (`decode_inter_block8`'s single-ref AND compound | |
| 55 | +chroma arms route `chroma_side == 8 && lossless && !mono` through the | |
| 56 | +new `leaf8_inter_chroma_lossless` helper wrapping the per-unit | |
| 57 | +`read_inter_chroma_lossless` walk, with the tail `record_mi`'s chroma | |
| 58 | +half saved/restored — `saved_chroma_ctx`, the `saved_luma_ctx` pattern; | |
| 59 | +both `record_mi` tails patched), fix 2 (`read_inter_chroma_lossless`: | |
| 60 | +`cu_mi` divisor `4 >> ss`, record spans `4 << ss`), fix 3 | |
| 61 | +(`decode_inter_block`'s `mu_chroma_units` lossless replay: extents | |
| 62 | +`>> ss`, mi-steps and spans `cu << ss`). All byte-identical at 4:2:0 | |
| 63 | +(`4 << 1 = 8`). Off-limits files untouched: `decode_rect4_16_strip`, | |
| 64 | +`restoration.rs`, intra write-back. Net diff vs HEAD: 9 hunks, earliest | |
| 65 | +at decode.rs:28734 — nothing before `read_inter_chroma_lossless`. | |
| 66 | + | |
| 67 | +Gate port: `git cherry-pick -n 13a262a6` (fixture | |
| 68 | +`fixtures/ll444_minp64_inter.obu` 37658 B, the `ffmpeg_decode_sequence_444` | |
| 69 | +helper, gate `a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact` | |
| 70 | +with the `chroma_split_tx_hits` non-vacuity assert and FNV/len pins). | |
| 71 | +stream.rs conflict = both lanes appended tests at the same spot; resolved | |
| 72 | +by keeping BOTH (band2's key-frame gate first, then the helper + inter | |
| 73 | +gate). | |
| 74 | + | |
| 75 | +## Verification (measured, this tree @ HEAD+2) | |
| 76 | + | |
| 77 | +- `a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact`: | |
| 78 | + **PASS** — all 6 dodge2 frames pixel-exact through BOTH the oracle | |
| 79 | + `aomdec --rawvideo` (oracle at `~/.cache/aom-oracle/build`, arm | |
| 80 | + executed, not skipped) and ffmpeg `yuv444p`; counter moved (non-vacuity). | |
| 81 | +- Key-frame gate stays green: `a_real_aomenc_lossless_444_key_frame_ | |
| 82 | + decodes_sample_exact` PASS. | |
| 83 | +- 4:2:0 unchanged: `a_lossless_libaom_key_frame_decodes_sample_exact`, | |
| 84 | + `a_lossless_libaom_inter_frame_decodes_sample_exact` — both PASS | |
| 85 | + (4 passed, 0 failed in the battery run). | |
| 86 | +- `decode_probe dodge2.obu`: `OK: 6 frames decoded`, no panic, debug AND | |
| 87 | + release. | |
| 88 | +- `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors. | |
| 89 | + | |
| 90 | +## Same-class suspects, deferred (spoken, not hidden) | |
| 91 | + | |
| 92 | +- `decode_rect4_16_strip`'s lossless chroma walk still hardcodes the | |
| 93 | + 4:2:0 span (`oy / 2`, `record_mi_chroma(.., 8, 8, ..)` at decode.rs | |
| 94 | + ~14631/14653/14675): excluded per lane ownership. | |
| 95 | + deferred(fix-now in the owning lane; shape = fixes 2-4's `4 << ss`). | |
| 96 | +- Default-partition `ll444.obu` no longer panics but stops at a NAMED | |
| 97 | + non-panic gap: `EC_RECTCHROMA_GAP luma=64x32 tx=4x4 chroma=64x32` | |
| 98 | + (decode.rs:10126 — the `(64, 32)` chroma plane block has no TxbSet row | |
| 99 | + at the rect64 lossless route). The sibling's gate deliberately does not | |
| 100 | + claim this stream either. deferred(fix-now in a lane chartering the | |
| 101 | + rect64 chroma lossless route; distinct defect, not this panic). |
lanes/av1llintra.report.mdadded+93 -0
| @@ -0,0 +1,93 @@ | ||
| 1 | +# lane-av1-llintra: 4:4:4 lossless intra side (class 444-lossless-intra-side) | |
| 2 | + | |
| 3 | +## Charter | |
| 4 | + | |
| 5 | +Fix the 4:4:4 lossless intra-side panic (decode.rs:3766, `index 16 len 16`, via | |
| 6 | +`decode_leaf8 -> read_plane -> exec_intra`) and the same-class 64x64 lossless | |
| 7 | +intra luma mis-decode, or stop at the first site that cannot be finished. | |
| 8 | + | |
| 9 | +## Repro (fail-before) | |
| 10 | + | |
| 11 | +`aomenc profile 1 --lossless=1`, testsrc2 128x96 yuv444p, 6 frames, palette and | |
| 12 | +intrabc off, cdef/restoration off (`ll444.obu` = default partitions, | |
| 13 | +`dodge2.obu` = `--sb-size=64 --max/min-partition-size=64`): | |
| 14 | + | |
| 15 | +- `ll444.obu`: PANIC decode.rs:3766 (`reconstruct`, index 16 len 16) on the KEY | |
| 16 | + frame, `decode_leaf8 -> read_plane -> exec_intra` (measured, RUST_BACKTRACE). | |
| 17 | +- `dodge2.obu`: key frame decoded but luma pixel-diffed the oracle from byte 65 | |
| 18 | + (31729 of 36864). | |
| 19 | + | |
| 20 | +## Root causes and fixes (all in decode.rs) | |
| 21 | + | |
| 22 | +1. **Leaf8 chroma is one TX_8X8 unit at 4:4:4 lossless** (the panic). Oracle | |
| 23 | + `av1_get_tx_size`: `if (xd->lossless[..]) return TX_4X4;` for EVERY plane, so | |
| 24 | + the leaf's 8x8 chroma plane block is a plane-major 2x2 raster of TX_4X4 | |
| 25 | + units. Our `TxbSet::Chroma8` single unit hit `TxParams::run`'s lossless WHT, | |
| 26 | + which is 4x4-only (`debug_assert_eq!((w, h), (4, 4))`), silently producing a | |
| 27 | + 16-coeff residual for a side-8 reconstruct. Fixed: in `decode_leaf8`'s TX4 | |
| 28 | + arm, `chroma_444 && lossless` routes through `read_intra_chroma_lossless` | |
| 29 | + (per-unit reads + per-unit `record_mi_chroma`); the tail's whole-leaf chroma | |
| 30 | + band stamp is skipped for that shape (raster-order last writer per band cell | |
| 31 | + is exactly libaom's per-entry last update). In the skip arm, the 4:4:4 | |
| 32 | + lossless leaf predicts four TX_4X4 chroma units (per-unit edges), like the | |
| 33 | + luma `SKIP_SPLIT_TX` loop; intrabc/palette keep the whole-plane-block | |
| 34 | + prediction. | |
| 35 | +2. **`read_intra_chroma_lossless` carried 4:2:0 math**: `cu_mi = at_mi + oy/2`, | |
| 36 | + `tu_reach(.., ox * 2, oy * 2, 8, ..)`, `record_mi_chroma(.., 8, 8, ..)`. | |
| 37 | + Made subsampling-aware (`MI >> ss` divisors, `<< ss` scaling, `4 << ss` | |
| 38 | + spans) -- byte-identical at 4:2:0, correct at 4:4:4 (one mi cell per unit). | |
| 39 | +3. **Whole-block chroma unit clip was a 4:2:0-sized raster** (`plane_px = | |
| 40 | + span_mi * 2`, overhang `2 * over_mi`): at 4:4:4 it clipped three quarters of | |
| 41 | + each 64x64 block's coded units and desynced the tile -- this was the dodge2 | |
| 42 | + key frame's luma diff from byte 65 (the desynced chroma garbage-fed the | |
| 43 | + following superblocks' luma). Fixed to `span_mi * MI >> ss` and `over_mi * | |
| 44 | + (MI >> ss)`, libaom `max_block_wide/high`. | |
| 45 | +4. **Lossless CFL alphabet gate**: oracle `is_cfl_allowed` at lossless requires | |
| 46 | + `plane_bsize == BLOCK_4X4` (TRUE for an 8x8 partition at 4:2:0, FALSE at | |
| 47 | + 4:4:4). Our `cfl_allowed_px` lossless arm accepted any <=8x8, so a 4:4:4 | |
| 48 | + lossless leaf read the 14-symbol `uv_mode_cfl` CDF where the stream carries | |
| 49 | + the 13-symbol one (class `wrong-alphabet-same-value`). Fixed to | |
| 50 | + `(bw >> ss_x).max(4) == 4 && (bh >> ss_y).max(4) == 4`; 4:2:0 identities | |
| 51 | + unchanged. | |
| 52 | + | |
| 53 | +## Verification (measured) | |
| 54 | + | |
| 55 | +- `ll444.obu` no longer panics on the key frame; the key frame decodes. | |
| 56 | +- `dodge2.obu` KEY FRAME: byte-exact vs `aomdec --rawvideo` (first diff at byte | |
| 57 | + 37493, i.e. inside inter frame 1). | |
| 58 | +- 4:2:0 regression gate `a_lossless_libaom_inter_frame_decodes_sample_exact`: | |
| 59 | + green. | |
| 60 | +- `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors. | |
| 61 | + | |
| 62 | +## STOP -- named, with the measured site | |
| 63 | + | |
| 64 | +`ll444.obu`'s key frame is NOT yet pixel-exact: 36254 of 36864 bytes differ | |
| 65 | +from byte 19. Localized with the trace pair (ours `EC_AV1_TRACE`, oracle | |
| 66 | +`EC_TRACE_MODE_STEP` + `EC_DQCOEFF`): the structural read order matches the | |
| 67 | +oracle exactly (per-4x4-leaf plane-interleaved luma,U,V; luma unit 0 of the | |
| 68 | +first sub8 group is byte-exact), but the FIRST chroma unit (`plane 1 @(0,0)`, | |
| 69 | +`TxbSet::Chroma4`, TX_4X4) decodes near-miss coefficients from scan position 4 | |
| 70 | +(e.g. ours `2:-8` vs oracle `2:-4`, ours `6:4` vs oracle `9:4`) with every | |
| 71 | +classical context input equal (bands all zero at frame start, `txb_skip_ctx` | |
| 72 | +base 7 both sides, DCT_DCT forced, same scan). Site: `sub8_leaf_chroma444`'s | |
| 73 | +square branch (decode.rs read_plane calls around 18935) -- the divergence is a | |
| 74 | +symbol-level CDF-row input unique to lossless chroma at 4x4 that the current | |
| 75 | +ctx arguments do not capture. Next step: oracle-paired token trace | |
| 76 | +(`EC_TRACE_MODE_STEP`'s `EC_COEFF` rng stream vs an rng/tell dump inside | |
| 77 | +`read_coeffs`) to name the first divergent symbol, then diff its CDF row | |
| 78 | +selection. | |
| 79 | + | |
| 80 | +Per charter, stopped there. Frames 1+ of BOTH streams panic in | |
| 81 | +`reconstruct_mc_rect` (decode.rs:28328 post-insert, was 28233) via the | |
| 82 | +`decode_inter_block8` inter path -- a different function from anything this | |
| 83 | +lane changed; that is the charter's named stop for the inter side, and | |
| 84 | +`read_inter_chroma_lossless` remains untouched (another report owns its /2 | |
| 85 | +design). | |
| 86 | + | |
| 87 | +## Deferred (spoken, not hidden) | |
| 88 | + | |
| 89 | +- `decode_leaf8`'s intrabc chroma prediction buffers are hardcoded 4x4 | |
| 90 | + (18074-18085), so an intrabc 8x8 leaf at 4:4:4 predicts 16 samples for a | |
| 91 | + 64-sample reconstruct. Unreachable with `--enable-intrabc=0` fixtures; | |
| 92 | + deferred(fix-now after the inter side is green, with an intrabc 4:4:4 | |
| 93 | + fixture). |
lanes/av1llintra8.report.mdadded+105 -0
| @@ -0,0 +1,105 @@ | ||
| 1 | +# lane-av1-llintra8: the inter frame's 8x8 INTRA leaf lossless 4:4:4 chroma walk | |
| 2 | + | |
| 3 | +## Ticket | |
| 4 | + | |
| 5 | +`decode_inter_block8`'s intra leaf read 4:4:4 lossless chroma as ONE TX_8X8 | |
| 6 | +unit (`u_grid`/`v_grid = read_plane(..)` at `chroma_side == 8`, | |
| 7 | +decode.rs:38958/:38985 pre-change) and hit `TxParams::run`'s lossless WHT | |
| 8 | +assert `(8, 8) != (4, 4)` at decode.rs:2566 — the one arm sibling | |
| 9 | +`84acbd09`/fb4e4b0e did not cover (it routed the INTER arms only, named in | |
| 10 | +llsub8b's report item 1). `decode_inter_sub8_rect2` and | |
| 11 | +`sub8_leaf_chroma444` untouched (owned elsewhere). | |
| 12 | + | |
| 13 | +## Change (decode.rs, one branch + one alphabet gate + counter) | |
| 14 | + | |
| 15 | +1. `chroma_side == 8 && lossless(fctx) && !mono(fctx)` routes the leaf's | |
| 16 | + chroma through `read_intra_chroma_lossless` — the intra twin the >=16x16 | |
| 17 | + intra-in-inter block already runs (plane-major 2x2 raster of TX_4X4 | |
| 18 | + units per plane, `av1_get_tx_size` blockd.h:1383) — with region and | |
| 19 | + block `(8, 8)` at stride 8, the leaf's own `reach`, and the leaf's | |
| 20 | + `palette_uv_bufs` windowed per unit by the helper. The walk stamps each | |
| 21 | + unit's own coefficient context, so `chroma_stamped_per_unit = true` and | |
| 22 | + the tail's whole-block `record_mi` gets its chroma half saved/restored | |
| 23 | + around — the same rule the INTER arms' `leaf8_inter_chroma_lossless` | |
| 24 | + obeys (the mechanism was already in place). `Grid::Zero(64)` when every | |
| 25 | + unit hung off the frame edge, matching the inter helper. 4:2:0: zero | |
| 26 | + change — the branch lives inside `chroma_side == 8`, and the reserved | |
| 27 | + 4:2:0 group-tail chroma arm was not touched. | |
| 28 | +2. SAME LEAF, one read earlier, second defect of the same class: the leaf | |
| 29 | + read `uv_mode` off `uv_mode_cfl[mode]` unconditionally, but libaom picks | |
| 30 | + the uv CDF row by `is_cfl_allowed` (decodemv.c:145, cfl.h:23) and at | |
| 31 | + LOSSLESS that is "the chroma plane block is BLOCK_4X4" (cfl.h:29) — | |
| 32 | + for this BLOCK_8X8 leaf only at 4:2:0. A 4:4:4 lossless leaf must read | |
| 33 | + the 13-symbol `uv_mode_no_cfl` alphabet; the tables differ (cdf.rs | |
| 34 | + `UV_MODE_CFL` vs `UV_MODE_NO_CFL`, row 0: 10407.. vs 22631..), so the | |
| 35 | + unconditional CFL row consumed a different partition at the leaf's own | |
| 36 | + uv_mode symbol and desynced every stream that reached the leaf. | |
| 37 | + Now gated on `cfl_allowed_px(SIDE, SIDE, fctx)` — the same gate five | |
| 38 | + other readers use; 4:2:0 lossless and every non-lossless partition | |
| 39 | + still take the CFL row (value-identical reads). | |
| 40 | +3. Non-vacuity counter `LLINTRA8_CHROMA_WALK_HITS` + | |
| 41 | + `llintra8_chroma_walk_hits()` + a `decode_probe` line, per the lane | |
| 42 | + convention: CHROMA_SPLIT_TX_HITS cannot attribute its bumps to this | |
| 43 | + leaf. | |
| 44 | + | |
| 45 | +## Verification (measured, this tree @ HEAD + this change) | |
| 46 | + | |
| 47 | +- Fail-before (assert): `testsrc2 128x96 yuv444p`, aomenc | |
| 48 | + `--profile=1 --lossless=1 --enable-palette=0 --enable-intrabc=0 | |
| 49 | + --max-partition-size=64`, 6 frames (`/tmp/llintra8/t6.obu`) → panic | |
| 50 | + `(8, 8) != (4, 4)` at decode.rs:2566, debug backtrace | |
| 51 | + `read_plane (decode.rs:38958) → push_intra_tx → TxParams::run`. The | |
| 52 | + release build's assert folds into an index panic at `exec_intra`; the | |
| 53 | + debug line numbers are the evidence. | |
| 54 | +- Fail-before (alphabet): with only the uv hunk reverted, the regenerated | |
| 55 | + `--min-partition-size=8` stream's EC_COEFF trace diverges from aomdec's | |
| 56 | + at all_zero #2400 — `plane=0 mi(4,0)`, the reads right after that leaf's | |
| 57 | + uv_mode symbol. With the fix: divergence gone (below). | |
| 58 | +- Entropy witness: `testsrc2 128x96 yuv444p` with | |
| 59 | + `--min-partition-size=8 --max-partition-size=64` (min 8 excludes the | |
| 60 | + sub-8 shapes so the leaf actually fires; key frame becomes exact too): | |
| 61 | + our EC_COEFF `all_zero` rng sequence matches fresh | |
| 62 | + `aomdec --rawvideo` **11292/11292 reads across all 6 frames** with the | |
| 63 | + walk firing 34 times; frame 0 is byte-exact and ALL luma planes are | |
| 64 | + byte-exact stream-wide. The pre-fix stream panicked at the leaf; this | |
| 65 | + stream decodes all 6 frames. | |
| 66 | +- Non-regression: sibling's own witness bytes | |
| 67 | + `/tmp/ll444/dodge2.obu` decode byte-exact vs fresh `aomdec`, 6 frames, | |
| 68 | + in this tree with this change. | |
| 69 | +- Gates: `cargo test -p ec-av1 --lib a_lossless` → 6 passed, 0 failed | |
| 70 | + (both 4:2:0 lossless libaom gates, the 444 min-partition-64 inter gate, | |
| 71 | + the sb128 pair, the 16x4 pair). | |
| 72 | +- `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors (target dir | |
| 73 | + `$HOME/.cache/cargo-target-av1llintra8`). Release decode_probe output | |
| 74 | + identical to debug on both streams. | |
| 75 | +- Fixtures are scratch in /tmp/llintra8 (regenerable recipes above); | |
| 76 | + fixtures/ is gitignored, nothing committed from it. | |
| 77 | + | |
| 78 | +## Named, not chased (spoken) | |
| 79 | + | |
| 80 | +1. Chroma PREDICTION pixel diffs, entropy-exact: on the min-8 stream, | |
| 81 | + 2772 bytes differ from aomdec — all chroma, luma exact, and the EC_COEFF | |
| 82 | + trace is bit-aligned everywhere (so symbols, uv modes and angle deltas | |
| 83 | + all match; only reconstructed pixels differ). Frame 1's diffs cover | |
| 84 | + three readers at once with clean upstream edges: the inter 8x16 strip's | |
| 85 | + chroma at mi(0,16) (2x4 units, MC-side), an INTRA 8x8 leaf at mi(2,24) | |
| 86 | + (uv V_PRED, via this lane's new walk), and the >=16x16 intra block's | |
| 87 | + chroma at mi(8,28) (the pre-existing `read_intra_chroma_lossless` | |
| 88 | + caller, untouched by this change). One shared per-unit chroma | |
| 89 | + prediction-input class across readers, present before this change | |
| 90 | + (the >=16 arm predates it) — larger than this arm. | |
| 91 | + deferred(the lane owning per-unit 4:4:4 chroma prediction: | |
| 92 | + `read_plane`/`PlaneBuf::reconstruct` intra chroma edges + the inter | |
| 93 | + strip chroma MC), with the min-8 stream as a ready-made fixture. | |
| 94 | +2. The default-partition (min 4) testsrc2 key frame still entropy-diverges | |
| 95 | + at frame-0 coefficient read #452 (pre-existing, key-frame intra lane; | |
| 96 | + llsub8b's item 3). The min-8 key frame is exact, so this lane's witness | |
| 97 | + does not depend on it. | |
| 98 | + | |
| 99 | +## Note on the shared oracle | |
| 100 | + | |
| 101 | +aomenc/aomdec are the shared `$HOME/.cache/aom-oracle/build`; the | |
| 102 | +EC_COEFF/EC_COEFF_STEP rungs of that patched tree are what the entropy | |
| 103 | +pairing above used. Today's aomenc produces different RD picks than this | |
| 104 | +morning's (llsub8b's note), so every comparison is against fresh aomdec | |
| 105 | +output of THE SAME bytes. |
lanes/av1llkf.report.mdadded+97 -0
| @@ -0,0 +1,97 @@ | ||
| 1 | +# lane-av1-llkf: the default-partition lossless 4:4:4 key frame's read #452 | |
| 2 | + | |
| 3 | +## Ticket | |
| 4 | + | |
| 5 | +Default-partition lossless 4:4:4 key frames entropy-diverge at frame-0 | |
| 6 | +coefficient read #452 (mandelbrot/testsrc2, `llsub8b` item 3 / `llintra8` | |
| 7 | +item 2). Min-partition-64 and min-8 keys stay exact, so the defect lives in | |
| 8 | +the shapes only a min-4 stream produces: 4x4 leaves and their 4x16/16x4 | |
| 9 | +neighbours. | |
| 10 | + | |
| 11 | +## Named symbol and reader (measured, t1 = testsrc2 128x96, 1 key frame, | |
| 12 | +`--profile=1 --lossless=1 --enable-palette=0 --enable-intrabc=0`, default | |
| 13 | +partition) | |
| 14 | + | |
| 15 | +- Reads 1..452 of the frame's `all_zero` (TXB_SKIP) rng sequence match the | |
| 16 | + oracle exactly; read #452 (0-indexed) diverges: | |
| 17 | + - aom: `EC_COEFF plane=2 row=0 col=0 mi=(8,5)` — the V plane's FIRST | |
| 18 | + TX_4X4 unit of the 4x16 intra block at mi=(8,5), read off | |
| 19 | + `txb_skip_cdf[0][12]` (`ctx=12` = base 2 + offset 10; above=`23`, | |
| 20 | + left=`21`, both nonzero). | |
| 21 | + - ours: `side=4 ctx=4` — our offset-10 row for base 1 (one band cell | |
| 22 | + reads zero), a different CDF row, so the rng diverges on the same | |
| 23 | + symbol. Reader: `read_plane`'s `all_zero` symbol read | |
| 24 | + (decode.rs:6819, `dec.symbol(&mut coding.txb_skip[skip_ctx])`), fed by | |
| 25 | + `decode_rect4_16_strip`'s lossless chroma walk. | |
| 26 | +- Whose band cell: block (8,4) (the 4x16 strip to the LEFT) recorded each | |
| 27 | + of its TX_4X4 units with `record_mi_chroma(cu_mi, 8, 8, plane, ...)` | |
| 28 | + anchored at `oy / 2, ox / 2` — the 4:2:0 subsampled form. At 4:4:4 a unit | |
| 29 | + is ONE mi cell, so the `(8, 8)` span smeared every unit's state over a | |
| 30 | + 2x2 mi block: the strip's later V units overwrote `above[5]` — a column | |
| 31 | + a 4-px-wide block never touches in aom — with their own (zero) state, | |
| 32 | + where aom keeps the 4x4 leaf (7,5)'s nonzero write | |
| 33 | + (`av1_set_entropy_contexts`, blockd.c:29, stamps exactly | |
| 34 | + `tx_size_wide_unit` x `tx_size_high_unit` cells = one above + one left | |
| 35 | + for TX_4X4). The skipped-unit twin arm has the same defect (aom's skip | |
| 36 | + path zeroes the plane block's own cells, `av1_reset_entropy_context`, | |
| 37 | + blockd.c:58 — the 8x8 smear also stamped past the block). | |
| 38 | + | |
| 39 | +## Change (decode.rs, two record sites, one branch) | |
| 40 | + | |
| 41 | +`decode_rect4_16_strip`'s `lossless_pair` chroma walk (skip and non-skip | |
| 42 | +arms): the per-unit record is now ss-aware — | |
| 43 | + | |
| 44 | +- anchor `cu_mi = (pair_mi.0 + (oy << ss_y) / MI, pair_mi.1 + (ox << ss_x) / MI)` | |
| 45 | +- span `record_mi_chroma(cu_mi, 4 << ss_x, 4 << ss_y, plane, ...)` | |
| 46 | + | |
| 47 | +4:2:0 is arithmetically identical (`(oy << 1) / 4 == oy / 2` for the | |
| 48 | +multiple-of-4 unit origins, `4 << 1 == 8`); non-lossless arms untouched; | |
| 49 | +the intrabc arms untouched. `RECT4_16_LOSSLESS_CHROMA_HITS` remains the | |
| 50 | +route's non-vacuity counter. | |
| 51 | + | |
| 52 | +## Verification (measured, this tree @ HEAD + this change) | |
| 53 | + | |
| 54 | +- Entropy: the `all_zero` rng ladders now match the oracle on ALL reads of | |
| 55 | + the whole frame — t1 (testsrc2) 2304/2304, m1 (mandelbrot) 2304/2304. | |
| 56 | + Fail-before on the same bytes: t1 diverges at read #452, m1 at read #208 | |
| 57 | + (base-tree control, `$HOME/.cache/cargo-target-av1llkf-base`). | |
| 58 | +- Pixel witness: t1 decodes byte-exact vs fresh `aomdec --rawvideo` | |
| 59 | + (36864 bytes). The 6-frame default-partition testsrc2 stream (`t6.obu`) | |
| 60 | + reads frame 0 fully in sync (reads 1..2304 of 12582 consumed before the | |
| 61 | + next, DIFFERENT divergence — see deferred (1)) and completes all 6 | |
| 62 | + frames with no refusal. | |
| 63 | +- Sibling non-regression: `/tmp/ll444/dodge2.obu` (llsub8b/llintra8's | |
| 64 | + witness bytes) decodes byte-exact vs fresh aomdec in this tree. | |
| 65 | +- Gates: `cargo test -p ec-av1 --lib a_lossless` → 7 passed, 0 failed | |
| 66 | + (both 4:2:0 lossless libaom gates, the 444 min-partition-64 inter gate, | |
| 67 | + the sb128 pair, the 16x4 pair). | |
| 68 | +- `cargo check -p ec-av1 --all-targets` (target dir | |
| 69 | + `$HOME/.cache/cargo-target-av1llkf`): 0 warnings, 0 errors. | |
| 70 | +- Fixtures are scratch in /tmp/llkf (regenerable recipes above); | |
| 71 | + fixtures/ is gitignored, nothing committed from it. | |
| 72 | + | |
| 73 | +## Named, not chased (spoken) | |
| 74 | + | |
| 75 | +1. t6's NEXT divergence is a different site: frame 1 (INTER), luma | |
| 76 | + `all_zero` at our read #2317 — same ctx row (1) and same decoded value | |
| 77 | + as the oracle but different CDF contents (ours `cdf0=5892` vs aom | |
| 78 | + `27244`), i.e. an adaptation-history/row-selection desync on the inter | |
| 79 | + frame, not a band smear. deferred(the inter-frame lossless-444 lane), | |
| 80 | + with t6.obu's recipe as a ready-made fixture. | |
| 81 | +2. m1 (mandelbrot) pixels: entropy exact frame-wide, chroma-only pixel | |
| 82 | + diffs (U 4436 / V 9070 samples, luma 0) — the pre-existing per-unit | |
| 83 | + 4:4:4 chroma PREDICTION class `llintra8` named. One concrete suspect | |
| 84 | + site of that class observed while here: | |
| 85 | + `decode_rect4_16_strip`'s lossless walk calls | |
| 86 | + `tu_reach(pw, ph, ox * 2, oy * 2, 8, ...)` — the 4:2:0 luma-space | |
| 87 | + offsets — where `read_intra_chroma_lossless` uses `ox << ss_x, oy << | |
| 88 | + ss_y` with unit size `4 << ss_x`; at 4:4:4 the doubled origin moves the | |
| 89 | + unit's prediction edge window. Prediction-domain, entropy unaffected | |
| 90 | + (proven by the exact coefficient reads above); owned by the same | |
| 91 | + chroma-prediction lane. deferred(that lane). | |
| 92 | + | |
| 93 | +## Note on the shared oracle | |
| 94 | + | |
| 95 | +aomenc/aomdec are the shared `$HOME/.cache/aom-oracle/build`; the | |
| 96 | +EC_TRACE_COEFF / EC_ECDUMP rungs of the patched tree carried the pairing. | |
| 97 | +Every comparison is against fresh aomdec output of THE SAME bytes. |
lanes/av1llpred.report.mdadded+80 -0
| @@ -0,0 +1,80 @@ | ||
| 1 | +# lane-av1-llpred: the min-partition-8 lossless 4:4:4 chroma OBMC blend is ss-blind | |
| 2 | + | |
| 3 | +## Ticket | |
| 4 | + | |
| 5 | +Remeasure the 2772 chroma pixel diffs the llintra8 lane named (entropy-exact, | |
| 6 | +luma-exact), name the FIRST differing sample, and fix it only if one index | |
| 7 | +explains it. `decode_leaf8`'s palette set untouched (another branch), the | |
| 8 | +reserved 4:2:0 group-tail chroma arm untouched. | |
| 9 | + | |
| 10 | +## Remeasure (this tree @ b3f815c8, BEFORE the change) | |
| 11 | + | |
| 12 | +Same pinned fixture `/tmp/llintra8/testsrc2_min8.obu` (testsrc2 128x96 | |
| 13 | +yuv444p, aomenc `--profile=1 --lossless=1 --enable-palette=0 | |
| 14 | +--enable-intrabc=0 --min-partition-size=8 --max-partition-size=64`, 6 | |
| 15 | +frames), fresh `aomdec --rawvideo` of the same bytes: **2772 chroma diffs | |
| 16 | +reproduced exactly** (frame 0 and all luma planes clean). But the parent's | |
| 17 | +three named sites did NOT hold: the first differing sample is | |
| 18 | + | |
| 19 | +> frame 1, plane 1 (U), x=88 y=4 (mi row 1, col 22), ours=149 ref=150 | |
| 20 | + | |
| 21 | +— an inter 8x8 leaf at mi(0,22) with mv=(0,11), not any of mi(0,16), | |
| 22 | +mi(2,24) or mi(8,28) as named. Error maps (residuals are equal by | |
| 23 | +entropy-exactness, so final diff = prediction diff) showed narrow | |
| 24 | +column/row fragments inside blend regions — OBMC shape, not whole-block MC | |
| 25 | +or intra-edge shape. | |
| 26 | + | |
| 27 | +## Root cause: one class, two sites, both "the 4:2:0 half hardcoded" | |
| 28 | + | |
| 29 | +1. `obmc_run` (decode.rs ~30085/30101/30113) sized the CHROMA neighbour | |
| 30 | + prediction and blend windows with literal `/ 2` (cbw/cbh/cox/cw and | |
| 31 | + cbh/coy/ch). libaom sizes them per plane with the PLANE's own | |
| 32 | + subsampling shift (`dec_build_prediction_by_above_pred`: | |
| 33 | + `(op_mi_size * MI_SIZE) >> pd->subsampling_x`, blend bounds likewise), | |
| 34 | + which is `>> 0` at 4:4:4 — the chroma blend covered half the columns at | |
| 35 | + half the offsets. Luma was never affected (luma exact everywhere). | |
| 36 | +2. `obmc_plan`'s `skip_chroma_above` hardcoded the luma shape list | |
| 37 | + `(8,8)|(16,8)|(8,16)`. libaom's `av1_skip_u4x4_pred_in_obmc` | |
| 38 | + (reconinter.c:829) switches on the PLANE block | |
| 39 | + (`get_plane_block_size`): only 4x4/8x4/4x8 skip the ABOVE pass's chroma | |
| 40 | + (`return dir == 0`). At 4:4:4 the plane block is the luma block itself, | |
| 41 | + so every 8x8/16x8/8x16 OBMC block was silently missing its above-pass | |
| 42 | + chroma blend — the (96..101, y8..10) family on leaf mi(2,24). | |
| 43 | + | |
| 44 | +Both fixed to derive ss (from `chroma_side` in `obmc_plan`, `ss_x/ss_y(fctx)` | |
| 45 | +in `obmc_run`); value-identical at 4:2:0 (`/2 == >>ss`). `obmc_run` is shared | |
| 46 | +by the 16x16+ square path and the 8x8 leaf path, so one fix covers both. | |
| 47 | +The `obmc_mask` table was already complete (M1..M32). | |
| 48 | + | |
| 49 | +## Verification (this tree @ HEAD + the change) | |
| 50 | + | |
| 51 | +- Fail-before → fix-after measured in steps: 2772 chroma diffs → 1126 | |
| 52 | + (geometry fix alone) → **0** (skip fix): decode output is byte-exact | |
| 53 | + against fresh `aomdec --rawvideo` for ALL 6 frames, all planes | |
| 54 | + (`cmp`-equal 221184 bytes). The stream-exactness claim is now TOTAL for | |
| 55 | + this fixture. | |
| 56 | +- 4:2:0 non-regression: `cargo test -p ec-av1 --lib a_lossless` → 6 passed, | |
| 57 | + 0 failed (both 4:2:0 lossless libaom gates, the 444 min-partition-64 | |
| 58 | + inter gate, the sb128 pair, the 16x4 pair). | |
| 59 | +- `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors (target dir | |
| 60 | + `$HOME/.cache/cargo-target-av1llpred`). | |
| 61 | + | |
| 62 | +## Named, not chased (spoken) | |
| 63 | + | |
| 64 | +1. `EC_MCB` rung (decode.rs obmc_run) still windows its own dump with | |
| 65 | + `write_w / 2` — a lane-t900 4:2:0-era INSTRUMENTATION assumption only; | |
| 66 | + output-inert, decode unaffected. fix-now(deferred to whoever next | |
| 67 | + touches that rung). | |
| 68 | +2. The llintra8 report's three named sites (mi(0,16)/mi(2,24)/mi(8,28)) | |
| 69 | + did not match a fresh run of the same bytes; mi(2,24) and mi(8,28) do | |
| 70 | + appear in the diff set but the FIRST miss was mi(0,22). Lesson recorded: | |
| 71 | + reremeasure before owning. | |
| 72 | + | |
| 73 | +## Note on the shared oracle | |
| 74 | + | |
| 75 | +All comparisons against fresh `$HOME/.cache/aom-oracle/build/aomdec | |
| 76 | +--rawvideo` output of THE SAME pinned bytes. The oracle tree has no | |
| 77 | +`EC_OBMC` rung (the decoder-side comment claiming a byte-matching oracle | |
| 78 | +format is aspirational); EC_PREDND covers intra only. Fixtures stay in | |
| 79 | +/tmp/llpred + /tmp/llintra8 (regenerable recipes above); nothing committed | |
| 80 | +from fixtures/. |
lanes/av1llpred2.report.mdadded+62 -0
| @@ -0,0 +1,62 @@ | ||
| 1 | +# lane-av1-llpred2: `skip_chroma_above` must read the frame's own ss pair, not a rect-over-square ratio | |
| 2 | + | |
| 3 | +## Ticket | |
| 4 | + | |
| 5 | +Reviewer FAIL on 71f07edd's `obmc_plan`: both ss axes were derived from ONE | |
| 6 | +square chroma side, `ss = trailing_zeros(write_w|write_h / chroma_side)`. | |
| 7 | +Two defects, one root: | |
| 8 | + | |
| 9 | +1. 4:2:0, a 16x8 strip: `write_h/chroma_side = 8/8 = 1`, `trailing_zeros(1)` | |
| 10 | + = 0, so ss=(1,0) and the plane block read (8,8) — `skip_chroma_above` | |
| 11 | + went FALSE. The old pre-llpred code skipped, and libaom's | |
| 12 | + `av1_skip_u4x4_pred_in_obmc` (reconinter.c 829) skips on the PLANE block | |
| 13 | + `(8,4)` (frame ss (1,1)). Every 4:2:0 16x8/8x16 OBMC strip blended a | |
| 14 | + chroma above pass the reference never blends (and would desync a | |
| 15 | + stream that carries one). | |
| 16 | +2. 4:4:4, a 16x8 strip: `write_h/chroma_side = 8/16 = 0`, | |
| 17 | + `trailing_zeros(0)` = 64, `write_h >> 64` panics in a debug build. | |
| 18 | + The parent lane's byte-exact claim was measured in a release build, | |
| 19 | + where the out-of-range shift wraps instead of panicking. | |
| 20 | + | |
| 21 | +## Change (this tree @ 71f07edd + the fix) | |
| 22 | + | |
| 23 | +`obmc_plan` takes `ss_x`/`ss_y` — the FRAME's own pair, exactly what the | |
| 24 | +chroma window half in `obmc_run` shifts by (`ss_x(fctx)`/`ss_y(fctx)`) — | |
| 25 | +and the decision moved to a pure helper: | |
| 26 | + | |
| 27 | +```rust | |
| 28 | +pub(crate) fn obmc_skip_chroma_above(write_w, write_h, ss_x, ss_y) -> bool { | |
| 29 | + matches!((write_w >> ss_x, write_h >> ss_y), (4, 4) | (8, 4) | (4, 8)) | |
| 30 | +} | |
| 31 | +``` | |
| 32 | + | |
| 33 | +All three callsites pass the frame pair: `decode_inter_block`, | |
| 34 | +`decode_inter_block8` (`ss_x(fctx), ss_y(fctx)`), and the encoder's | |
| 35 | +`obmc_prediction` (`crate::decode::ss_x(fctx)`, 4:2:0-only encoder). No | |
| 36 | +ratio over `chroma_side` survives; `trailing_zeros` of anything is gone. | |
| 37 | +The window-size half that reduces to `/2` at 4:2:0 is untouched, and the | |
| 38 | +reserved 4:2:0 group-tail chroma arm is untouched. | |
| 39 | + | |
| 40 | +## Proof (debug build, `dev` profile throughout) | |
| 41 | + | |
| 42 | +- Decision check (new `obmc_skip_chroma_tests`): | |
| 43 | + `rect_strips_skip_above_chroma_at_420_and_shift_never_overflows` pins | |
| 44 | + 4:2:0 (16,8,1,1) and (8,16,1,1) → SKIP (with (8,8,1,1), and | |
| 45 | + (16,16)/(32,16)/(16,32) → blend), and 4:4:4 → only true 4-wide/high | |
| 46 | + shapes skip, (16,8,0,0)/(8,16,0,0)/(8,8,0,0) → blend with no shift | |
| 47 | + out of `usize` range. No hit-counter gate was added: the skip | |
| 48 | + decision itself is what is proven. | |
| 49 | +- 6-frame 4:4:4 stream, DEBUG decode probe: fixture | |
| 50 | + `/tmp/llintra8/testsrc2_min8.obu` | |
| 51 | + sha256 `04fb6d38de5382e647bfb70b6a17802f1fccc5502e6698c0394167891f2b27dc`, | |
| 52 | + `$HOME/.cache/cargo-target-av1llpred2/debug/examples/decode_probe` | |
| 53 | + → 6 frames, 221184 bytes, `cmp`-equal to fresh | |
| 54 | + `$HOME/.cache/aom-oracle/build/aomdec --rawvideo`. Byte-exact, now in | |
| 55 | + a build that would have panicked on the old code. | |
| 56 | +- 4:2:0 non-regression: `cargo test -p ec-av1 --lib -- obmc_skip_chroma | |
| 57 | + a_lossless` → 7 passed, 0 failed (the new check + the 4:2:0 lossless | |
| 58 | + libaom gates, the 444 min-partition-64 inter gate, the sb128 pair, the | |
| 59 | + 16x4 pair). | |
| 60 | +- `cargo check -p ec-av1 --all-targets` | |
| 61 | + (`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1llpred2`): 0 warnings, | |
| 62 | + 0 errors. |
lanes/av1llpredgate2.report.mdadded+87 -0
| @@ -0,0 +1,87 @@ | ||
| 1 | +# lane-av1llpredgate2: pin the debug-exact 6-frame stream for the ss-aware `obmc_skip_chroma_above` fix | |
| 2 | + | |
| 3 | +Tree: lane-av1-llpredgate2 @ 041e3eae (the lane-av1-llpred2 fix, under | |
| 4 | +review — no code change landed here). This lane adds ONLY the regression | |
| 5 | +gate. | |
| 6 | + | |
| 7 | +## Regression gate | |
| 8 | + | |
| 9 | +`stream::tests::a_lossless_444_min_partition8_inter_stream_decodes_sample_exact` | |
| 10 | +(crates/ec-av1/src/stream.rs), modelled on | |
| 11 | +`a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact`. | |
| 12 | + | |
| 13 | +### Fixture provenance | |
| 14 | + | |
| 15 | +- Origin: lanes/av1llpred.report.md / lanes/av1llpred2.report.md stream — | |
| 16 | + `testsrc2=size=128x96:rate=?` ffmpeg source, yuv444p, encoded by the | |
| 17 | + shared aomenc (`$HOME/.cache/aom-oracle/build`, pre-2026 build) with | |
| 18 | + `--profile=1 --lossless=1 --enable-palette=0 --enable-intrabc=0 | |
| 19 | + --min-partition-size=8 --max-partition-size=64`, 6 frames. | |
| 20 | +- Committed at `crates/ec-av1/fixtures/ll444_minp8_inter.obu` | |
| 21 | + (gitignored pattern `fixtures`, force-added like every sibling fixture; | |
| 22 | + on-disk == `git ls-tree` blob verified at commit time). | |
| 23 | +- 34037 bytes, sha256 | |
| 24 | + `04fb6d38de5382e647bfb70b6a17802f1fccc5502e6698c0394167891f2b27dc` | |
| 25 | + (= the /tmp/llintra8 original, byte-identical copy), | |
| 26 | + FNV-1a64 `0x2c8f4a2cc02552da`. Both pinned as test consts; missing | |
| 27 | + file panics — no skip path. | |
| 28 | + | |
| 29 | +### Debug build path, not release-only | |
| 30 | + | |
| 31 | +The defect this gate pins is a DEBUG-only panic: the pre-llpred2 ratio | |
| 32 | +(`(write_h / chroma_side).trailing_zeros()` = 64 at 4:4:4) shifted by 64, | |
| 33 | +which panics under debug_assertions and silently wraps in release | |
| 34 | +(release was already byte-exact). The test runs under `cargo test`'s | |
| 35 | +default dev profile — the profile where the parent measured byte-exact | |
| 36 | +and where the old code dies — so a red run names the class instead of | |
| 37 | +silently passing. | |
| 38 | + | |
| 39 | +### Counter disposition: cited unit check, not a skip-arm counter | |
| 40 | + | |
| 41 | +A skip-arm counter was added and measured, then removed: | |
| 42 | + | |
| 43 | +- With the counter bumped at the ONE site the ss-aware decision returns | |
| 44 | + true (after the `obmc_skip_chroma_above` call in `obmc_plan`), the | |
| 45 | + pinned stream measured `OBMC_SS_SKIP_CHROMA_ABOVE_HITS 0 -> 0` while | |
| 46 | + OBMC itself fired (`OBMC_HITS 0 -> 77`, `OBMC_RECT_LEAF_HITS 0 -> 20`). | |
| 47 | + At 4:4:4 the skip needs a 4x4/8x4/4x8 PLANE block; min-partition-8 | |
| 48 | + never codes one, so the skip arm cannot fire on this stream and any | |
| 49 | + `delta > 0` assert would be permanently red — vacuity in reverse. | |
| 50 | +- Per the ticket's fallback: the decision TABLE is pinned by the existing | |
| 51 | + unit check | |
| 52 | + `decode::obmc_skip_chroma_tests::rect_strips_skip_above_chroma_at_420_and_shift_never_overflows` | |
| 53 | + (4:2:0 16x8/8x16 strips still skip; 4:4:4 shifts never leave `usize`), | |
| 54 | + and the stream gate pins the END-TO-END behaviour sample-for-sample. | |
| 55 | + | |
| 56 | +### Assertions (all before/without any skip path) | |
| 57 | + | |
| 58 | +1. Fixture bytes: exact length + FNV-1a64. | |
| 59 | +2. `decode_stream` of the pinned bytes succeeds (a returning `>> 64` | |
| 60 | + panic fails here) — 6 frames, 128x96. | |
| 61 | +3. Oracle aomdec (`--codec=av1 --rawvideo`): raw size 221184, then | |
| 62 | + per-frame per-plane `assert_eq!(bad, 0)` — 0 differing samples, | |
| 63 | + message carries class `obmc-ss-blind-chroma-above`. | |
| 64 | +4. ffmpeg arm (`ffmpeg_decode_sequence_444`): same sample-exact compare. | |
| 65 | + Neither arm skipped in the green run (aomdec + ffmpeg both present). | |
| 66 | + | |
| 67 | +## Red probes (mutation verification) | |
| 68 | + | |
| 69 | +1. Old-ratio probe: callsite swapped to the exact 71f07edd derivation | |
| 70 | + (`(write_w|write_h per chroma_side).trailing_zeros()` pair) → test | |
| 71 | + RED: `attempt to shift right with overflow` at decode.rs | |
| 72 | + `obmc_skip_chroma_above` — the debug-panic class reproduced. | |
| 73 | +2. Chroma-diff probe: `skip_chroma_above = true` forced at the callsite | |
| 74 | + (re-blend class) → test RED at the named assert: `aomdec frame 1 | |
| 75 | + plane u: 46 samples differ (class obmc-ss-blind-chroma-above)`. | |
| 76 | +3. decode.rs restored byte-identical after both probes | |
| 77 | + (`git diff --stat`: only stream.rs + the fixture). | |
| 78 | + | |
| 79 | +## Non-regression / hygiene | |
| 80 | + | |
| 81 | +- `cargo test -p ec-av1 --lib | |
| 82 | + a_lossless_444_min_partition8_inter_stream_decodes_sample_exact` | |
| 83 | + (CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1llpredgate2, dev | |
| 84 | + profile): 1 passed, 0 failed, no SKIP lines. | |
| 85 | +- `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors. | |
| 86 | +- The skip expression itself is untouched (no diff in decode.rs); the | |
| 87 | + reserved 4:2:0 group-tail chroma arm untouched; no server, no full suite. |
lanes/av1llsub8.report.mdadded+84 -0
| @@ -0,0 +1,84 @@ | ||
| 1 | +# lane-av1-llsub8: 4:4:4 lossless sub8 chroma coefficient miss (r1) | |
| 2 | + | |
| 3 | +## Charter | |
| 4 | + | |
| 5 | +Localize the 4:4:4 lossless sub8 chroma coefficient miss. Work in | |
| 6 | +`edith_codecs-av1llsub8` @ 38393554; own `sub8_leaf_chroma444` and the | |
| 7 | +coefficient read it calls. 4:2:0 lossless stays exact. | |
| 8 | + | |
| 9 | +## Repro | |
| 10 | + | |
| 11 | +Fixture regenerated per the llintra report's recipe (raw `--i444` input, same | |
| 12 | +encoder): `testsrc2 128x96` yuv444p, 6 frames, `aomenc --profile=1 | |
| 13 | +--lossless=1 --enable-palette=0 --enable-intrabc=0` (`~/ll444.obu`, 26511 B; | |
| 14 | +key-frame cut `~/ll444kf.obu`). Pre-fix key frame: 15001/36864 bytes differ | |
| 15 | +from `aomdec --rawvideo` (first diff byte 4181). Probe exits 101 at frame 1 | |
| 16 | +(`reconstruct_mc_rect`, decode.rs:2589 path) — the charter's named inter side, | |
| 17 | +untouched. | |
| 18 | + | |
| 19 | +## Ladder (EC_TRACE_COEFF, symbol-anchored, key frame only) | |
| 20 | + | |
| 21 | +12136 aligned `(tag,rng)` steps, then: | |
| 22 | + | |
| 23 | +1. **uv_mode alphabet (FIXED).** First divergence is *not* a coefficient: at | |
| 24 | + the first 8x8 `PARTITION_HORZ` leaf (mi (8,16)) the leaf's own `uv_mode` | |
| 25 | + symbol desyncs. `read_intra_mode_sub8` read `cdfs.uv_mode_cfl[mode]` | |
| 26 | + (14-symbol) unconditionally; a 4:4:4 lossless `BLOCK_8X4`/`BLOCK_4X8` | |
| 27 | + leaf's plane block is the rect itself, so `is_cfl_allowed` is FALSE and the | |
| 28 | + stream carries the 13-symbol `uv_mode_no_cfl` row (class | |
| 29 | + `wrong-alphabet-same-value`; oracle post-read rng 33082 vs ours 38358 off | |
| 30 | + the same entry 56906). Fix: gate on `cfl_allowed_px(seg_w_mi*MI, | |
| 31 | + seg_h_mi*MI)` — true for the 4:2:0 group tail (plane block 4x4) and 4:4:4 | |
| 32 | + split leaves, false for 4:4:4 rect leaves; 4:2:0 unchanged. | |
| 33 | +2. **Rect-leaf lossless chroma unit structure (FIXED).** Next divergence | |
| 34 | + (step 12138): the rect leaf's chroma. `read_tx_size` answers TX_4X4 for | |
| 35 | + EVERY plane of a lossless block, so the oracle codes the 8x4 leaf's chroma | |
| 36 | + as TWO plane-major TX_4X4 units (U bc 0, U bc 1, then V) with | |
| 37 | + `get_txb_ctx`'s **+10** rows (`plane pels 32 > tx pels 16`, | |
| 38 | + `txb_skip_cdf[0][10..12]`), while ours read ONE TX_8X4 rect unit off | |
| 39 | + `ChromaRect8x4` (rows `[1][0..2]`, only reached correctly non-losslessly). | |
| 40 | + Fix: lossless rect arm reads per-4x4 units via `read_plane(TxbSet::Chroma4, | |
| 41 | + luma_skip_ctx=Some(3))` (Chroma4's `big` rows = `[0][10..12]`), plane-major | |
| 42 | + per `decode_token_recon_block`, per-unit ctx from the unit's own | |
| 43 | + `around_mi_rect`, immediate per-unit `av1_set_entropy_contexts` stamps. | |
| 44 | + The non-lossless arm (single rect transform, rows `[1][7..9]`) is kept. | |
| 45 | + Tail now stamps per-unit (`grid_unit_state`) instead of one whole-leaf | |
| 46 | + smear; 4x4 leaves and the single-unit rect arm are bit-identical to before. | |
| 47 | + | |
| 48 | +After both fixes: divergence moves to step 19228, key frame 178/36864 bytes | |
| 49 | +off (first diff byte 8320). | |
| 50 | + | |
| 51 | +## STOP — named, not fixed (budget) | |
| 52 | + | |
| 53 | +Step 19228: inside a **16x8 leaf** (`PARTITION_HORZ` of a 16x16; U units | |
| 54 | +bc 0..3, br 0..1) the U unit at **bc=2, br=0** reads `txb_skip` base **1** | |
| 55 | +(ours, row `[0][11]` — the same `+3` fold, cdf `[8570,...]`) where the oracle | |
| 56 | +reads base **0** (row `[0][10]`, cdf0=32705): one of ours' above/left entropy | |
| 57 | +cells for that unit is stamped nonzero where the oracle's is clean. bc=0/1 of | |
| 58 | +the same leaf aligned (rng 40879/40628), and ours' `dcctx=2` on the diverging | |
| 59 | +read (vs 0 on bc=1) says the polluted cell carries a DC-sign vote — i.e. an | |
| 60 | +above-band cell written by the block above with a state the oracle doesn't | |
| 61 | +hold. Next step: dump the above-band cell contents (both sides, | |
| 62 | +`EC_DCDUMP`/oracle equivalent) for the units directly above this leaf's | |
| 63 | +bc 2/3 columns and diff the writer — suspect the 16x8-path's per-unit stamp | |
| 64 | +map (which unit owns which above/left cell when a leaf spans >1 mi row) in | |
| 65 | +`decode_leaf_rect`'s chroma loop, NOT `sub8_leaf_chroma444` (16x8 leaves are | |
| 66 | +read by `decode_leaf_rect`, which already had per-unit +3 reads before this | |
| 67 | +lane). | |
| 68 | + | |
| 69 | +## Verification (measured) | |
| 70 | + | |
| 71 | +- `a_lossless_libaom_key_frame_decodes_sample_exact` + `a_lossless_libaom_ | |
| 72 | + inter_frame_decodes_sample_exact` (4:2:0): green. | |
| 73 | +- `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors. | |
| 74 | +- Key frame: 15001 → 178 differing bytes; first diff byte 4181 → 8320. | |
| 75 | +- Consumed-count ladder: 12136 → 12138 → 19228 aligned steps. | |
| 76 | + | |
| 77 | +## Deferred (spoken, not hidden) | |
| 78 | + | |
| 79 | +- 16x8 above-band stamp diff above (fix-now; named cell + writer). | |
| 80 | +- Intrabc rect leaves at lossless 444 still route the rect arm's | |
| 81 | + `read_coeffs_rect` path with the wrong unit structure — unreachable with | |
| 82 | + `--enable-intrabc=0` fixtures; same fix shape as the non-intrabc arm | |
| 83 | + (deferred(fix-now after the inter side is green, with an intrabc 4:4:4 | |
| 84 | + fixture), matching the llintra report's deferral). |
lanes/av1llsub8b.report.mdadded+92 -0
| @@ -0,0 +1,92 @@ | ||
| 1 | +# lane-av1-llsub8b: the inter sub8 rect route's 4:4:4 lossless chroma raster | |
| 2 | + | |
| 3 | +## Ticket | |
| 4 | + | |
| 5 | +`decode_inter_sub8_rect2` hit `TxParams::run`'s lossless WHT assert | |
| 6 | +`(8, 4) != (4, 4)` at decode.rs:2566 (pre-existing at the parent, named by | |
| 7 | +`lane-av1-ll64`'s same-class sweep). Port sibling `84acbd09` if it covers | |
| 8 | +this route; else fix only the unit size that trips the assert. | |
| 9 | +`decode_rect4_16_strip` untouched (sibling-owned). The 12-frame stream's | |
| 10 | +Golomb-tail refusal was expected to disappear once the (8,4) read was | |
| 11 | +fixed. | |
| 12 | + | |
| 13 | +## Sibling verdict: not covered — own fix, same shape | |
| 14 | + | |
| 15 | +`84acbd09` (already ported here as fb4e4b0e) routed `decode_inter_block8`'s | |
| 16 | +INTER arms' 8x8 chroma through `leaf8_inter_chroma_lossless`. The rect2 | |
| 17 | +route was one arm over: `decode_inter_sub8_rect2`'s `chroma_444` coded arm | |
| 18 | +read each piece's (8,4)/(4,8) U/V plane block as ONE `TxbSet::ChromaRect8x4` | |
| 19 | +rect unit — at lossless that unit hits the WHT assert, exactly the ll64 | |
| 20 | +report's prediction. | |
| 21 | + | |
| 22 | +## Change (decode.rs, one branch) | |
| 23 | + | |
| 24 | +New arm in `decode_inter_sub8_rect2`'s `chroma_444` coded path: | |
| 25 | +`lossless(fctx) && !mono(fctx)` routes the piece's chroma through the | |
| 26 | +sibling's `read_inter_chroma_lossless` walk with region and block | |
| 27 | +`(bw, bh)` at stride `SIDE` — lossless codes TX_4X4 on EVERY plane | |
| 28 | +(`av1_get_tx_size`, blockd.h:1383), so the plane block is a 2x1/1x2 raster | |
| 29 | +of `TxbSet::Chroma4` units. The walk stamps each unit's own coefficient | |
| 30 | +context, so — unlike the lossy arm — no whole-block `record_mi_chroma` | |
| 31 | +runs after it (the leaf8 rule). `piece_tx_type` inheritance stays lossy- | |
| 32 | +only (lossless is DCT_DCT on every plane). 4:2:0: zero change — the branch | |
| 33 | +lives inside `chroma_444`, and the reserved 4:2:0 group-tail chroma arm was | |
| 34 | +not touched. Luma was already correct (`lane-lossless2`'s TX_4X4 leaf walk). | |
| 35 | + | |
| 36 | +## Verification (measured, this tree @ HEAD + this change) | |
| 37 | + | |
| 38 | +- Fail-before: `testsrc2 128x96 yuv444p`, aomenc `--profile=1 --lossless=1 | |
| 39 | + --enable-palette=0 --enable-intrabc=0 --max-partition-size=64`, 6 frames | |
| 40 | + → panic `(8, 4) != (4, 4)` at decode.rs:2566, backtrace | |
| 41 | + `read_inter_plane_rect → push_mc_rect_tx`. Fail-after: gone; the decoder | |
| 42 | + reads through the rect2 pieces and arrives coherently at the next | |
| 43 | + (pre-existing) defect site — see deferred (1). | |
| 44 | +- Witness with the route actually firing: mandelbrot 128x96 6 frames, same | |
| 45 | + recipe, `--cpu-used` 0 and 3 both decode ALL 6 frames; | |
| 46 | + `sub8_inter_rect: horz8x4=22 vert4x8=15` (cpu0) / `10/12` (cpu3) — 37 | |
| 47 | + and 22 lossless 444 rect2 chroma pieces through the new walk, stream | |
| 48 | + completes. | |
| 49 | +- Sibling non-regression: the ORIGINAL `/tmp/ll444/dodge2.obu` (sibling's | |
| 50 | + own witness bytes) decodes byte-exact vs fresh `aomdec --rawvideo`, all 6 | |
| 51 | + frames, in this tree with this change. | |
| 52 | +- Entropy alignment on the repro stream: frames 0-2 of the 6-frame | |
| 53 | + testsrc2 stream byte-exact vs aomdec; `sub8_inter_rect` counters 0 there | |
| 54 | + (its first rect2 piece sits behind deferred (1)'s site), and its frame 3 | |
| 55 | + reads through the new arm up to the (8,8) site without a desync-form | |
| 56 | + failure. | |
| 57 | +- Gates: `cargo test -p ec-av1 --lib a_lossless` → 6 passed, 0 failed | |
| 58 | + (both 4:2:0 lossless libaom gates, the 444 min-partition-64 inter gate, | |
| 59 | + the sb128 pair). | |
| 60 | +- `cargo check -p ec-av1 --all-targets` (target dir | |
| 61 | + `$HOME/.cache/cargo-target-av1llsub8b`): 0 warnings, 0 errors. | |
| 62 | +- Fixtures are scratch in /tmp/llsub8b (regenerable recipes above); | |
| 63 | + fixtures/ is gitignored, nothing committed from it. | |
| 64 | + | |
| 65 | +## Named, not chased (spoken) | |
| 66 | + | |
| 67 | +1. `decode_inter_block8`'s INTRA-leaf chroma arm (decode.rs:38958/:38985, | |
| 68 | + `u_grid`/`v_grid = read_plane(..)` at `chroma_side == 8`) reads 4:4:4 | |
| 69 | + lossless chroma as ONE TX_8X8 unit → the same WHT assert, `(8, 8) != | |
| 70 | + (4, 4)`. Same class, the one arm the sibling's fix did not cover (it | |
| 71 | + routed the INTER arms only). decode_inter_block8 is the llinter lane's | |
| 72 | + function — deferred(fix-now by the lane owning block8's intra arm; the | |
| 73 | + fix shape is the same per-unit lossless walk with intra-plane read | |
| 74 | + semantics, not a port of the inter helper). | |
| 75 | +2. The 12-frame stream's `REFUSED: AV1 tile (a Golomb tail …)` from the | |
| 76 | + ll64 report: GONE after this fix — that stream now stops at deferred | |
| 77 | + (1)'s (8,8) site instead, exactly as ll64 predicted. | |
| 78 | +3. Fresh observation on today's regenerated fixtures: a mandelbrot | |
| 79 | + default-partition lossless 444 KEY frame pixel-differs from aomdec | |
| 80 | + (key-frame-only stream, zero sub8 counters, no refusal, first diff at | |
| 81 | + sample 40). Key frames never enter `decode_inter_sub8_rect2`, so this | |
| 82 | + is pre-existing and intra-side — the earlier lanes' key-frame proofs | |
| 83 | + ran min-partition-64 keys, which stay exact. deferred(the intra lane). | |
| 84 | + | |
| 85 | +## Note on the shared oracle | |
| 86 | + | |
| 87 | +aomenc/aomdec binaries are the shared `$HOME/.cache/aom-oracle/build`. | |
| 88 | +Today's aomenc produces different RD picks than this morning's (the | |
| 89 | +regenerated min-partition-64 testsrc2 stream's inter frames differ from | |
| 90 | +the sibling's original bytes) — streams were therefore compared only | |
| 91 | +against aomdec output of THE SAME bytes, and the sibling's original | |
| 92 | +dodge2.obu was used verbatim for the non-regression check. |
lanes/av1rect128recon.report.mdadded+88 -0
| @@ -0,0 +1,88 @@ | ||
| 1 | +# lane-av1-rect128recon — the 444_sb128rect witness f2 is byte-exact vs aomdec AND ffmpeg; root cause: the inter-frame intra tail's chroma walk coded ONE whole-plane unit where 4:4:4 codes four TX_32X32 units; gate extended take(2)→take(3) (r1) | |
| 2 | + | |
| 3 | +## Outcome | |
| 4 | + | |
| 5 | +1. REPRODUCED at HEAD 99232190 (fresh target dir `cargo-target-av1rect128recon`, | |
| 6 | + fixture sha256 `27825e14633a4b23e37d48a2acdc7f5d814ca4fadd0b8797d72a1ffb34061e80` | |
| 7 | + re-verified, oracle aomdec `~/.cache/aom-oracle/build` regenerated this | |
| 8 | + session): frame 2 diverges at PREFILT Y 6952 / U 9568 / V 13496, first diffs | |
| 9 | + Y (col 128, row 98), U (col 128, row 64), V (col 128, row 0); f0/f1 exact. | |
| 10 | + Numbers match av1444sbf2 r1 / av1lrflush r3 sample-for-sample. | |
| 11 | +2. BLOCK-SHAPE CORRECTION (ladder evidence, not inference): the oracle's f2 | |
| 12 | + top-right superblock root is a gathered-bit SPLIT, and its right column is | |
| 13 | + INTRA blocks — 64x64 at (128,0), 64x32 at (128,64), 64x32 at (128,96), | |
| 14 | + 64x64 at (128,128) — not "the inter 64x128 at (128,0)" the earlier lane | |
| 15 | + reports name. Evidence: oracle `EC_PART`/`EC_PART_VAL` (ctx 14, values | |
| 16 | + NONE/HORZ at mi (0,32)/(16,32)), `EC_PREDOUT8` per-unit sums, and | |
| 17 | + `EC_DQCOEFF`. The earlier reports' pixel numbers are all reproduced here; | |
| 18 | + only the block-shape naming was wrong. | |
| 19 | +3. FIRST DIVERGENT SYMBOL, pinned by consecutive-TU rng alignment on both | |
| 20 | + ladders (`EC_COEFF_STEP`, TU-boundary values 60168/55581/51541 matching | |
| 21 | + line-for-line): the 64x64 intra block's FIRST chroma TX_32X32 unit at | |
| 22 | + mi (0,32). Ours decoded `txb_skip` off the offset-7 context row (printed | |
| 23 | + ctx 0); aom reads the offset-10 row (true ctx 10 — the uv plane block | |
| 24 | + 64x64 is larger than the TX_32X32 unit). Same decoded value (skip), but | |
| 25 | + the CDF rows differ, so the arithmetic coders consumed different bits and | |
| 26 | + the rest of frame 2 decodes off a drifting state — bounded, mostly-skip | |
| 27 | + garbage that still corrupted the block's own V plane (uniform −1: the | |
| 28 | + missing V residual) and the bottom superblock row. | |
| 29 | +4. ROOT CAUSE (one site): `decode_inter_block`'s intra tail read the block's | |
| 30 | + chroma as ONE whole-plane unit (`read_plane` with `chroma_side`/`chroma_tx`, | |
| 31 | + block-level `around`, no +10 offset) — a 4:2:0-era remnant. At 4:4:4 a | |
| 32 | + 64x64 plane block is FOUR plane-major TX_32X32 units, each with its own | |
| 33 | + `around_mi` context and the offset-10 rows. The keyframe path | |
| 34 | + (`decode_block`'s `cn > 1` loop, lane-av1-444) and the inter tail's own | |
| 35 | + ss-0/0 arm already did this correctly; the intra-in-inter tail was the one | |
| 36 | + remaining copy of the old shape. The misnaming in (2) hid this: the | |
| 37 | + "inter 64x128" framing pointed at Agent044's strip/inter territory, while | |
| 38 | + the real site is the intra tail. | |
| 39 | +5. FIX (decode.rs, intra tail chroma chain): new `ss_x==0 && ss_y==0 && | |
| 40 | + chroma_side > chroma_tx` arm — four plane-major TX_32X32 units, per-unit | |
| 41 | + `around_mi(cu_mi, 32)`, `Some(3)` skip-ctx offset (+10 convention on our | |
| 42 | + chroma-32 table), immediate per-unit `record_mi_chroma`, per-unit | |
| 43 | + `tu_reach`, assembled 64x64 plane grids, `mu_chroma = true` so the | |
| 44 | + block-tail unit replay re-stamps after the whole-block record (class | |
| 45 | + `override-slot-on-one-arm`). 4:2:0 is identical by construction: the arm | |
| 46 | + is ss-gated and `chroma_side == chroma_tx` there still takes the old | |
| 47 | + single-read path. Class sweep: the only other intra-in-inter chroma arms | |
| 48 | + are the side>64 mu-chunk walk (already per-unit, correct) and the | |
| 49 | + rect-strip readers (separate paths, sibling-owned, untouched). | |
| 50 | +6. RESULT: f2 PREFILT byte-exact; FINAL (full deblock/CDEF/LR pipeline) | |
| 51 | + byte-exact on ALL THREE frames against BOTH oracles — ours == | |
| 52 | + `ffmpeg -f rawvideo -pix_fmt yuv444p` byte-for-byte (276480 bytes), and | |
| 53 | + frame-equal to aomdec's Y4M output (its 12 interleaved `FRAME` markers | |
| 54 | + stripped). | |
| 55 | + | |
| 56 | +## Verification | |
| 57 | + | |
| 58 | +- `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact` | |
| 59 | + (extended to `.take(3)` in both oracle arms + rewritten scoping comment, | |
| 60 | + same commit): PASS. | |
| 61 | +- `cargo check -p ec-av1`: 0 warnings (target `$HOME/.cache/cargo-target-av1rect128recon`). | |
| 62 | +- sb128 family (`cargo test -p ec-av1 --lib sb128`): 10 passed, 1 ignored. | |
| 63 | +- 444 family (`--lib 444`): 4 passed (includes the lossless 444 | |
| 64 | + min-partition-64 inter stream). | |
| 65 | +- Restoration battery (`EC_AV1_REQUIRE_AOMENC=1 --lib restoration`): | |
| 66 | + 10 passed, 0 failed. | |
| 67 | +- chroma family (`--lib chroma`): 28 passed, 0 failed. | |
| 68 | +- Stage evidence from env-gated rungs on both decoders (EC_PART/EC_PART_VAL, | |
| 69 | + EC_COEFF_STEP, EC_ECDUMP_IN, EC_PREDOUT8, EC_IMODE, AOMMB, EC_DQCOEFF); | |
| 70 | + throwaway /tmp scratch only, nothing left in the tree. | |
| 71 | + | |
| 72 | +## Decision | |
| 73 | + | |
| 74 | +- Gate extended and the stale "LR never restores RU row 0" scoping comment | |
| 75 | + replaced (that attribution was refuted in lane-av1lrflush r3 as a | |
| 76 | + stage-ladder mixup) — the deferred same-commit pairing is now discharged. | |
| 77 | +- Sibling ownership respected: `decode_rect4_16_strip`'s 16x4/strip-tail | |
| 78 | + territory and the sub-8 leaf paths untouched; the fix lands in | |
| 79 | + `decode_inter_block`'s intra tail only. | |
| 80 | +- Named for the record: any future block-shape work must sweep BOTH copies | |
| 81 | + of the chroma unit walk — `decode_block` (keyframe) and | |
| 82 | + `decode_inter_block`'s intra tail — plus the inter tail; this defect was | |
| 83 | + the third copy drifting from the first two. | |
| 84 | + | |
| 85 | +## State | |
| 86 | + | |
| 87 | +- Commit on lane-av1-rect128recon (no push): decode.rs fix + stream.rs gate | |
| 88 | + extension/comment + this report. |