diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index bec376fd..d2be96a5 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -1,3 +1,5 @@ +/home/user/Documents/Code/Rust/edith_codecs/crates/ec-av1/examples/decode_probe.rs: + //! Where does a real stream stop? Decode one AV1 file and print the answer. //! //! The gates in [`ec_av1::stream`] each pin one capability against one encoder @@ -91,6 +93,13 @@ fn main() { "intrabc_128rect: {}", ec_av1::stream::intrabc_128rect_hits() ); + // lane-av1-ibc128chunk: the 128-root intrabc strip's per-axis chroma + // mu-chunk walk -- unit count and the `(64>>ss_x)|(64>>ss_y)` extent. + println!( + "intrabc_128rect_chroma_chunk: units={} shape=0x{:x}", + ec_av1::stream::intrabc_128rect_chroma_chunk_hits(), + ec_av1::stream::intrabc_128rect_chunk_shape() + ); let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); println!( diff --git a/crates/ec-av1/fixtures/422_intrabc_sb128_strip.obu b/crates/ec-av1/fixtures/422_intrabc_sb128_strip.obu new file mode 100644 index 0000000000000000000000000000000000000000..d8e6180299408bf3938eb7f238e22d6a38d96eaf GIT binary patch literal 1672 zcmZwF{Xf%*0|4-kT`~_x9^#T^d1%S=GS(BO$itVWi*q`RxFO`}JPi#s4^1e{4clT) z$BuPhCL8n6NGR2vwT5In)*Q#RXpY(aa`$?DU%kHn!u$2s12i<<0bq~kZoYD75D)JM z831$ukWhW4u3Pk~YwqZL$J&v5UiscouXCB4bukF8F~526{9-useAy38 zKtY>=6!*A;C8N&woUJzBF$1e6!q{KWFL~-}E-TX!(E&kH(!L{Cs50KTYkEo@=1k>r z)8V+^FV(OBdO4H3*6Nhld3v;m%b57Zlh_^-!~0-IuQ?B^|B*VB3v-jP81}nksamSP zru}u*n!UX>uj$0$p)Uw(x;9Nt!7r^1E=)D|bczFx8Wq0urWmlEUcWy=>*As2!m4l0 z_Jvt4_WC&IY8a&6w@e&Q4&SK1V+$|lV6MaE`U8V&Hl7>DIQI=^WM50nErQ466fxn+ za=lMDpMVSi3jkCIEhJ372i7&%teG{SeWIY>%4-R#wgB~{61a=t|30Ry*33Pa38W?D zy^cyxsR=O*vi4JpfA)jYdN0i~Y4riEp>gvxWC{MwO7m=^Ph%UyW!TKUuS;m-rh|_a zCTn)#wCLEmIVKYui(44Sw{|u|%cmh|ZAlBZ&B!W9_-qBr1EvP)*wnr=sR6~lVd&=C^V+HbHE%A)8!@IL6W{v~nXUAKiM&p>|g=ZQ+FKMqS_XqNYi0 zePB~)@!2UN*J)z&V6i!36S=LIV4WEMEU=+HT>UB-(`=ioK*&{MAh)ei0y;WdrFIDFC3ABWFFaZ3209E7mk zIqH;(v`!ja8Kxdmkih`-FRjK+#$9=8BocQt&7lQ?oBatvdeJNFO_FQ36`9H<829?j z><<{_GW%toF^_MV8GQ=L`WLcJk(MXorIlR_D+=yTDe7oZ<44Kbt8G$46TPZ;t)2!5 zzMbAB7-kK<&Jp&E9+swGh)S+7yr2);22U_=6W-VxM`*Xc^d4~xZyphAxpfnl@re$x zWQ3Z?3;CuRJ7!U@D|<0j7k;jyda4`dO5GqKtTFdG_Yz_n36-$7$=FI0f~sBi&Nj@Mp7o@|7?I}*dI)!|+y zUZ){SW`CMjkDpW?JF!)YU+Nd+#o)_Yg8#Inr*|pX>-mgMzygUrshKBHRjslOD0$L} zjNH?d9ln$aP*uJQvyRJnb31b&QRF$BEPN;V9JP893YER>NXcD{F-q3H?n?C01pUaU*c*Z zF0kA~KYwtcs@Etr4wWs0!%zD*JUhS-ZT?~jc;!z?@{W^xjBSj%qj)_cg)^!BXnt;h z=V#2bY3~3CIAO}Fn41JoQ+Jn?^qbwWEH^z=f<;DY)PF7Y|v z|6y|XA3V&_89k+jWRe1WRdG{%vBmxSo#1^lA4TyxcgSk%c>)0Z9F)4&ifag o_02G{FCjTlK^e;>{<`98oSeHqfTLW9u7pNDS2G#2@ae_>4Wwc=^8f$< literal 0 HcmV?d00001 diff --git a/crates/ec-av1/fixtures/422_intrabc_sb128_strip_notxsearch.obu b/crates/ec-av1/fixtures/422_intrabc_sb128_strip_notxsearch.obu new file mode 100644 index 0000000000000000000000000000000000000000..717bf96f765238bad223962e793e7821cf94af16 GIT binary patch literal 1675 zcmZwF`8(SO0|4-Ev#JQwI?9Sv>S$`NQb8}oRmUrhuFR`-mN{DLnk%9~8%LvPLsCbQ z64ON%Yy?4C8b?cMZB#?5NruK4Z$rvUWWVfvp7-hd{tKVyqX|G%T>xOe$6l^t_bJYn z3(^MY0I)>$kvMJBD{i`=b8V^yA9?0_!93kFde+4tTgbdj|H49Dc4MEUpf?8N_43>mt~^Le;CiX&hF?0eV!q^u zdLWM>C&dl3*i!0zryJ3D*9feX0O$O3e$hiiby<;yh(ZNONQaJJqe^)%oYIoX;pfXw z84kq#ak-KW&`VpnYfW|uE$4U^Qv||JoLqx%66H-S=-BNPlXc=oh@S23ElijFN!w%<*mnqw00g+5JJ2= z*BfHG(CuxX1JO=-Y?|;QDRk4_8QeZ}Q(8~lW)6&ZsZUx%suJDe6pW-_>VAKyH#`w+ zh(&3B=J_0?4VVC+d{{ny>?5!a;jm}dfacM>J~Pinn6eP&LB(?yz`qPrRx1T%FVIRL~^P_Ijk3a2k5awfpNm6e);~|!Vh*5G?AIl48_zc`e zJ{ZzYXz$|thkd*T~Rk4 z-sGz-_r&VXI6|ZKpea|fEys3Udp}5a{^1!>yKrGDyhhNhFy{mKG#M@X3kqo8AFF~Y zqccksdm$BmCKHU(J?gHu$9#R+-L^6wcJ__Gvi@!XPF3%#W0!3FFgPr-r)V0Kjo_Es zN1oj$Axi?wLsWwD(wTtP<<+>cxN9$UMPgRH06jBvr|(99X4DEtMsn&ftEO`Cdfnc$ zhfzb^);_66^zdCH-OnMr{sT#tr(#9C)RIdf1%VyO1*}Hp=}2ia(IO={!IQXW_7XMo z-P9glC$s-;HotS|m?Z6DWKx;VMJ@Oac(nB%{++d6n0nKs*Pu;k!=PBrxr4BbOE?)@ zjZhYOI=&;ujF{ADNMBEoL*2`W6CH3T>Lv+c9{#B106w}7Uk-nt6jN@1SF+0LUm;a2 zhi&D078$+D8l4_kDsH8xOxRiYo|i}-MG?0ibZ26cNytyvZEj9NpKk_zI3CTbI>^03 zxJ5%0&HXg55nA$y#=B=pt*zkQpIAQY}s<%YWe!}SUji9Zpn z)#UrB+pzyFEGuJ<^Ko^qt|2bjc&jjw@Pxl(I2Zt58=3kZ bool { } } - /// Sets [`SB128`] for this thread (called once per frame from `stream.rs`). pub(crate) fn set_sb128(v: bool, fctx: &crate::decode::FrameCtx) { fctx.sb128_flag.with(|c| c.set(v)); @@ -438,10 +440,7 @@ pub(crate) fn set_sb128(v: bool, fctx: &crate::decode::FrameCtx) { /// lane-av1mixloss: sets [`FrameCtx::lossless_per_seg`] (called once per frame /// from `stream.rs`). -pub(crate) fn set_lossless_per_seg( - table: [bool; MAX_SEGMENTS], - fctx: &crate::decode::FrameCtx, -) { +pub(crate) fn set_lossless_per_seg(table: [bool; MAX_SEGMENTS], fctx: &crate::decode::FrameCtx) { fctx.lossless_per_seg.with(|c| c.set(table)); } @@ -701,17 +700,16 @@ pub(crate) fn round_ss(dim: usize, ss: usize) -> usize { (dim + ((1usize << ss) >> 1)) >> ss } - - /// This frame's superres state: `(upscaled_width, superres_denom)`, or - /// `(0, 8)` when the frame is not scaled. Spec 7.16's upscale runs - /// between CDEF and loop restoration, so LOOP RESTORATION -- unit grid, - /// `read_lr`'s unit corners and the pixel filters themselves -- works in - /// UPSCALED coordinates while deblock and CDEF work in downscaled ones - /// (libaom `av1_superres_upscale` in `decodeframe.c`, and - /// `av1_loop_restoration_corners_in_sb`'s own `mi_to_num_x`/`denom_x` - /// superres arms). Set once per frame from [`crate::stream`]'s decode - /// loop, like [`BIT_DEPTH`], and reset to `(0, 8)` on an unscaled frame - /// so a later frame never inherits it. +/// This frame's superres state: `(upscaled_width, superres_denom)`, or +/// `(0, 8)` when the frame is not scaled. Spec 7.16's upscale runs +/// between CDEF and loop restoration, so LOOP RESTORATION -- unit grid, +/// `read_lr`'s unit corners and the pixel filters themselves -- works in +/// UPSCALED coordinates while deblock and CDEF work in downscaled ones +/// (libaom `av1_superres_upscale` in `decodeframe.c`, and +/// `av1_loop_restoration_corners_in_sb`'s own `mi_to_num_x`/`denom_x` +/// superres arms). Set once per frame from [`crate::stream`]'s decode +/// loop, like [`BIT_DEPTH`], and reset to `(0, 8)` on an unscaled frame +/// so a later frame never inherits it. /// Sets [`SUPERRES`] for the current thread. `upscaled_width` is 0 (and /// `denom` 8) for a frame that is not superres-scaled. @@ -902,7 +900,15 @@ fn block_iqmatrix( /// top-left leaf is the only block that can ever land there), or when that /// leaf both *is* the whole superblock and is `skip` (the one case libaom /// itself skips the read, state carrying over unchanged). -fn maybe_read_delta_q(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: usize, is_whole_sb: bool, skip: bool, fctx: &crate::decode::FrameCtx) { +fn maybe_read_delta_q( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + mi_r: usize, + mi_c: usize, + is_whole_sb: bool, + skip: bool, + fctx: &crate::decode::FrameCtx, +) { if !fctx.delta_q_present.with(|c| c.get()) { return; } @@ -929,7 +935,8 @@ fn maybe_read_delta_q(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_ let reduced = if sign_negative { -abs } else { abs }; hit!(DELTA_Q_HITS); let res = fctx.delta_q_res.with(|c| c.get()); - fctx.current_q_idx.with(|c| c.set((c.get() + reduced * res).clamp(1, 255))); + fctx.current_q_idx + .with(|c| c.set((c.get() + reduced * res).clamp(1, 255))); } // lane-realworld r5: this frame's `delta.lf_present`/`lf_res`/`lf_multi` @@ -956,7 +963,15 @@ pub(crate) fn delta_lf_hits() -> usize { /// [`maybe_read_delta_q`] (spec order `delta_q -> delta_lf`), looped over /// `FRAME_LF_COUNT = 4` planes/directions when `delta_lf_multi` is set, or /// read once into index 0 otherwise. -fn maybe_read_delta_lf(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: usize, is_whole_sb: bool, skip: bool, fctx: &crate::decode::FrameCtx) { +fn maybe_read_delta_lf( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + mi_r: usize, + mi_c: usize, + is_whole_sb: bool, + skip: bool, + fctx: &crate::decode::FrameCtx, +) { if !fctx.delta_lf_present.with(|c| c.get()) { return; } @@ -1091,17 +1106,24 @@ pub(crate) fn set_segmentation( seg: SegmentationParams, mi_rows: usize, mi_cols: usize, - prev: Option<&[u8]>, fctx: &crate::decode::FrameCtx, + prev: Option<&[u8]>, + fctx: &crate::decode::FrameCtx, ) { if crate::envflags::env_flag!("EC_HDR") { eprintln!( "EC_SEGHDR enabled={} update_map={} temporal={} preskip={} last_active={} data={:?}", - seg.enabled, seg.update_map, seg.temporal_update, seg.seg_id_pre_skip, seg.last_active_seg_id, seg.feature_data + seg.enabled, + seg.update_map, + seg.temporal_update, + seg.seg_id_pre_skip, + seg.last_active_seg_id, + seg.feature_data ); } fctx.seg.with(|s| *s.borrow_mut() = seg); fctx.seg_mi_dims.with(|c| c.set((mi_rows, mi_cols))); - fctx.seg_ids.with(|m| *m.borrow_mut() = vec![0u8; mi_rows * mi_cols]); + fctx.seg_ids + .with(|m| *m.borrow_mut() = vec![0u8; mi_rows * mi_cols]); fctx.prev_seg_ids.with(|m| { let mut m = m.borrow_mut(); m.clear(); @@ -1111,8 +1133,10 @@ pub(crate) fn set_segmentation( } } }); - fctx.above_seg_pred.with(|m| *m.borrow_mut() = vec![0u8; mi_cols]); - fctx.left_seg_pred.with(|m| *m.borrow_mut() = vec![0u8; mi_rows]); + fctx.above_seg_pred + .with(|m| *m.borrow_mut() = vec![0u8; mi_cols]); + fctx.left_seg_pred + .with(|m| *m.borrow_mut() = vec![0u8; mi_rows]); fctx.cur_segment_id.with(|c| c.set(0)); } @@ -1200,9 +1224,19 @@ fn segment_id_at(mi_r: usize, mi_c: usize, fctx: &crate::decode::FrameCtx) -> u8 } /// `set_segment_id`: stamps `id` over every mi cell this block covers. -fn write_segment_id(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, id: u8, fctx: &crate::decode::FrameCtx) { +fn write_segment_id( + mi_r: usize, + mi_c: usize, + w_mi: usize, + h_mi: usize, + id: u8, + fctx: &crate::decode::FrameCtx, +) { let (mi_rows, mi_cols) = fctx.seg_mi_dims.with(|c| c.get()); - let (x_mis, y_mis) = (w_mi.min(mi_cols.saturating_sub(mi_c)), h_mi.min(mi_rows.saturating_sub(mi_r))); + let (x_mis, y_mis) = ( + w_mi.min(mi_cols.saturating_sub(mi_c)), + h_mi.min(mi_rows.saturating_sub(mi_r)), + ); fctx.seg_ids.with(|m| { let mut m = m.borrow_mut(); for y in 0..y_mis { @@ -1219,9 +1253,18 @@ fn write_segment_id(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, id: u8, /// inherited VERBATIM over this block's own mi footprint -- per-cell copies, /// not the minified id [`predicted_segment_id`] hands the block. Without a /// previous map the footprint is zeroed, exactly as the C NULL branch does. -fn copy_segment_ids(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, fctx: &crate::decode::FrameCtx) { +fn copy_segment_ids( + mi_r: usize, + mi_c: usize, + w_mi: usize, + h_mi: usize, + fctx: &crate::decode::FrameCtx, +) { let (mi_rows, mi_cols) = fctx.seg_mi_dims.with(|c| c.get()); - let (x_mis, y_mis) = (w_mi.min(mi_cols.saturating_sub(mi_c)), h_mi.min(mi_rows.saturating_sub(mi_r))); + let (x_mis, y_mis) = ( + w_mi.min(mi_cols.saturating_sub(mi_c)), + h_mi.min(mi_rows.saturating_sub(mi_r)), + ); fctx.seg_ids.with(|m| { let mut m = m.borrow_mut(); fctx.prev_seg_ids.with(|p| { @@ -1239,14 +1282,23 @@ fn copy_segment_ids(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, fctx: &c /// `get_predicted_segment_id` (libaom `dec_get_segment_id` over /// `last_frame_seg_map`): the minimum previous-frame segment id over the /// block's own mi footprint. `0` when there is no previous map. -fn predicted_segment_id(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, fctx: &crate::decode::FrameCtx) -> u8 { +fn predicted_segment_id( + mi_r: usize, + mi_c: usize, + w_mi: usize, + h_mi: usize, + fctx: &crate::decode::FrameCtx, +) -> u8 { let (mi_rows, mi_cols) = fctx.seg_mi_dims.with(|c| c.get()); fctx.prev_seg_ids.with(|m| { let m = m.borrow(); if m.is_empty() { return 0; } - let (x_mis, y_mis) = (w_mi.min(mi_cols.saturating_sub(mi_c)), h_mi.min(mi_rows.saturating_sub(mi_r))); + let (x_mis, y_mis) = ( + w_mi.min(mi_cols.saturating_sub(mi_c)), + h_mi.min(mi_rows.saturating_sub(mi_r)), + ); let mut id = u8::MAX; for y in 0..y_mis { for x in 0..x_mis { @@ -1277,7 +1329,11 @@ fn neg_deinterleave(diff: i32, reference: i32, max: i32) -> i32 { reference - (diff >> 1) }; } - if 2 * reference < max { diff } else { max - (diff + 1) } + if 2 * reference < max { + diff + } else { + max - (diff + 1) + } } /// `av1_get_spatial_seg_pred`: `(prediction, cdf_index)` from the current @@ -1311,7 +1367,14 @@ fn spatial_seg_pred(mi_r: usize, mi_c: usize, fctx: &crate::decode::FrameCtx) -> /// `read_segment_id` (libaom `decodemv.c:280`): the spatially predicted id /// when `skip`, otherwise one `segment_id` symbol de-interleaved against /// that prediction. Does NOT write the map -- callers do. -fn read_segment_id(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: usize, skip: bool, fctx: &crate::decode::FrameCtx) -> u8 { +fn read_segment_id( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + mi_r: usize, + mi_c: usize, + skip: bool, + fctx: &crate::decode::FrameCtx, +) -> u8 { let (pred, ctx) = spatial_seg_pred(mi_r, mi_c, fctx); if skip { return pred as u8; @@ -1323,7 +1386,10 @@ fn read_segment_id(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: // Mirrors the oracle's own `EC_SEG mi_row=.. cdf=.. pred=.. coded=.. id=..` // (libaom `decodemv.c:read_segment_id`), for a cross-decoder segment diff. if crate::envflags::env_flag!("EC_TRACE_SEG") { - eprintln!("EC_SEG mi_row={mi_r} mi_col={mi_c} cdf={ctx} pred={pred} coded={coded} id={id} rng={}", dec.debug_state().0); + eprintln!( + "EC_SEG mi_row={mi_r} mi_col={mi_c} cdf={ctx} pred={pred} coded={coded} id={id} rng={}", + dec.debug_state().0 + ); } id as u8 } @@ -1338,7 +1404,8 @@ fn intra_segment_id( mi_c: usize, w_mi: usize, h_mi: usize, - skip: bool, fctx: &crate::decode::FrameCtx, + skip: bool, + fctx: &crate::decode::FrameCtx, ) { if !fctx.seg.with(|s| s.borrow().enabled) { return; @@ -1367,11 +1434,17 @@ fn inter_segment_id( w_mi: usize, h_mi: usize, skip: bool, - pre_skip: bool, fctx: &crate::decode::FrameCtx, + pre_skip: bool, + fctx: &crate::decode::FrameCtx, ) { let (enabled, update_map, temporal_update, pre_skip_frame) = fctx.seg.with(|s| { let s = s.borrow(); - (s.enabled, s.update_map, s.temporal_update, s.seg_id_pre_skip) + ( + s.enabled, + s.update_map, + s.temporal_update, + s.seg_id_pre_skip, + ) }); if !enabled { return; @@ -1426,12 +1499,14 @@ fn seg_pred_ctx(mi_r: usize, mi_c: usize, fctx: &crate::decode::FrameCtx) -> usi // what keeps a previous tile's stamps out of this tile's context. let (row0, col0) = fctx.seg_tile_origin.with(|c| c.get()); let above = if mi_r > row0 { - fctx.above_seg_pred.with(|m| m.borrow().get(mi_c).copied().unwrap_or(0)) + fctx.above_seg_pred + .with(|m| m.borrow().get(mi_c).copied().unwrap_or(0)) } else { 0 }; let left = if mi_c > col0 { - fctx.left_seg_pred.with(|m| m.borrow().get(mi_r).copied().unwrap_or(0)) + fctx.left_seg_pred + .with(|m| m.borrow().get(mi_r).copied().unwrap_or(0)) } else { 0 }; @@ -1439,7 +1514,14 @@ fn seg_pred_ctx(mi_r: usize, mi_c: usize, fctx: &crate::decode::FrameCtx) -> usi } /// Spec 5.11.9's `AboveSegPredContext`/`LeftSegPredContext` update. -fn stamp_seg_pred(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, value: u8, fctx: &crate::decode::FrameCtx) { +fn stamp_seg_pred( + mi_r: usize, + mi_c: usize, + w_mi: usize, + h_mi: usize, + value: u8, + fctx: &crate::decode::FrameCtx, +) { fctx.above_seg_pred.with(|m| { let mut m = m.borrow_mut(); for i in 0..w_mi { @@ -1507,7 +1589,8 @@ fn tu_reach( px: usize, py: usize, width: usize, - height: usize, fctx: &crate::decode::FrameCtx, + height: usize, + fctx: &crate::decode::FrameCtx, ) -> Reach { let fixed = Reach::of_tu(bw, bh, col_off, row_off, tx, tx, block); let standalone = Reach::of(tx, px + col_off, py + row_off, width, height, fctx); @@ -1535,7 +1618,8 @@ fn tu_reach_rect( px: usize, py: usize, width: usize, - height: usize, fctx: &crate::decode::FrameCtx, + height: usize, + fctx: &crate::decode::FrameCtx, ) -> Reach { let fixed = Reach::of_tu(bw, bh, col_off, row_off, tx_w, tx_h, block); if tx_w == tx_h { @@ -1589,8 +1673,7 @@ thread_local! { /// lane-comppin r4: decode-order picture counter for `EC_AV1_PREFILT_DUMP`, /// mirroring stream.rs's `pictures_decoded` so the two dumps index /// identically against aomdec's own `ec_frame_idx` in decodeframe.c. -static PREFILT_PICTURE_IDX: std::sync::atomic::AtomicUsize = - std::sync::atomic::AtomicUsize::new(0); +static PREFILT_PICTURE_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); /// Current value of [`DEBLOCK_HITS`]. #[allow(dead_code)] // read only from the `#[cfg(test)]` gates @@ -1802,7 +1885,11 @@ fn vartx_rect_leaf_hit(tw: usize, th: usize) { if crate::envflags::env_flag!("EC_VARTXLEAF") { eprintln!("EC_VARTXLEAF tw={tw} th={th}"); } - let cell = if tw.min(th) == 4 { &VARTX_RECT_LEAF4_HITS } else { &VARTX_RECT_LEAF_HITS }; + let cell = if tw.min(th) == 4 { + &VARTX_RECT_LEAF4_HITS + } else { + &VARTX_RECT_LEAF_HITS + }; cell.with(|c| { let mut h = c.get(); h[usize::from(th > tw)] += 1; @@ -1815,13 +1902,15 @@ fn vartx_rect_leaf_hit(tw: usize, th: usize) { pub(crate) fn set_inter_tx_mode( tx_select: bool, reduced_tx_set: bool, - enable_filter_intra: bool, fctx: &crate::decode::FrameCtx, + enable_filter_intra: bool, + fctx: &crate::decode::FrameCtx, ) { fctx.tx_select_inter.with(|c| c.set(tx_select)); fctx.intra_only.with(|c| c.set(false)); fctx.tx_select_frame.with(|c| c.set(tx_select)); fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set)); - fctx.enable_filter_intra_inter.with(|c| c.set(enable_filter_intra)); + fctx.enable_filter_intra_inter + .with(|c| c.set(enable_filter_intra)); } // How many `partition_w16` reads (a 16x16 block's own partition symbol, key @@ -2559,15 +2648,14 @@ pub(crate) fn intra_in_inter_split_tx_hits() -> [usize; 4] { INTRA_IN_INTER_SPLIT_TX_HITS.with(std::cell::Cell::get) } - /// A just-decoded palette-Y block's own predicted pixels - /// (`side*side`, row-major, `colors[map[i]]`), consumed by - /// [`PlaneBuf::reconstruct`]'s next call in place of `predict()` -- the - /// same off-the-call-stack idiom as [`ENABLE_EDGE_FILTER`] (threading a - /// per-block override through `read_plane`'s two dozen call sites is the - /// alternative this avoids). Always empty again once that call consumes - /// it (`.take()`), so a non-palette block's own `reconstruct` call never - /// sees stale state. - +/// A just-decoded palette-Y block's own predicted pixels +/// (`side*side`, row-major, `colors[map[i]]`), consumed by +/// [`PlaneBuf::reconstruct`]'s next call in place of `predict()` -- the +/// same off-the-call-stack idiom as [`ENABLE_EDGE_FILTER`] (threading a +/// per-block override through `read_plane`'s two dozen call sites is the +/// alternative this avoids). Always empty again once that call consumes +/// it (`.take()`), so a non-palette block's own `reconstruct` call never +/// sees stale state. /// Arms the pending [`PALETTE_PRED`] override for the next `reconstruct` /// (`set`) / consumes it (`take`). Set and take MUST pair: a buffer armed at a @@ -2579,7 +2667,14 @@ pub(crate) fn intra_in_inter_split_tx_hits() -> [usize; 4] { /// top-left corner (the luma split-transform paths already window; the chroma /// ones did not, which is invisible until a lossless frame codes a palette /// block as 4x4 chroma units). -fn palette_window(buf: &[u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize) -> Vec { +fn palette_window( + buf: &[u16], + stride: usize, + ox: usize, + oy: usize, + w: usize, + h: usize, +) -> Vec { (0..h) .flat_map(|r| buf[(oy + r) * stride + ox..][..w].iter().copied()) .collect() @@ -2624,7 +2719,12 @@ pub(crate) struct CflSrc { } fn cfl_src(px: usize, py: usize, side: usize) -> CflSrc { - CflSrc { px, py, bw: side, bh: side } + CflSrc { + px, + py, + bw: side, + bh: side, + } } fn cfl_src_rect(px: usize, py: usize, bw: usize, bh: usize) -> CflSrc { @@ -2670,8 +2770,7 @@ pub(crate) struct TxParams { /// The mixed-lossless witness's proof the per-segment lossless path really /// ran on a frame that is NOT `CodedLossless`. Atomic because the wavefront /// workers run this on their own threads. -static LOSSLESS_WHT_UNITS: std::sync::atomic::AtomicUsize = - std::sync::atomic::AtomicUsize::new(0); +static LOSSLESS_WHT_UNITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); /// [`LOSSLESS_WHT_UNITS`] -- total over the process, read as a before/after /// delta around one decode. @@ -2690,11 +2789,21 @@ impl TxParams { debug_assert_eq!((self.w, self.h), (4, 4)); debug_assert_eq!(self.tx_type, TxType::DctDct); crate::transform::dequant_and_inverse_wht4x4( - grid, self.bit_depth, self.q_idx, self.dc_delta, self.ac_delta, + grid, + self.bit_depth, + self.q_idx, + self.dc_delta, + self.ac_delta, ) } else { dequant_and_inverse_typed_wh( - grid, self.w, self.h, self.bit_depth, self.q_idx, self.dc_delta, self.ac_delta, + grid, + self.w, + self.h, + self.bit_depth, + self.q_idx, + self.dc_delta, + self.ac_delta, self.tx_type, self.qm, ) @@ -2836,7 +2945,11 @@ pub(crate) fn is_zero_grid(grid: &[i32]) -> bool { /// `residual`, or `n` zeros when it is the empty all-zero marker. fn dense_residual(residual: &[i32], n: usize) -> &[i32] { - if residual.is_empty() { &ZERO_RESIDUAL[..n] } else { residual } + if residual.is_empty() { + &ZERO_RESIDUAL[..n] + } else { + residual + } } /// Where a recorded motion-compensated write reads its prediction from. @@ -2854,7 +2967,11 @@ pub(crate) enum Pred<'a> { Inline(&'a [u16], usize), /// The current block's deferred prediction: plane, its stride, and this /// unit's offset into it. - Cur { plane: usize, stride: usize, off: usize }, + Cur { + plane: usize, + stride: usize, + off: usize, + }, } impl<'a> Pred<'a> { @@ -2878,7 +2995,11 @@ impl<'a> Pred<'a> { fn offset(self, n: usize) -> Self { match self { Self::Inline(b, s) => Self::Inline(&b[n..], s), - Self::Cur { plane, stride, off } => Self::Cur { plane, stride, off: off + n }, + Self::Cur { plane, stride, off } => Self::Cur { + plane, + stride, + off: off + n, + }, } } } @@ -2891,7 +3012,11 @@ pub(crate) enum PredSrc { /// stride it is read at -- which is the block's, not necessarily the /// op's (a transform unit's residual stays dense, so the worker takes /// its window out of the block prediction itself). - Cur { plane: usize, off: usize, src: usize }, + Cur { + plane: usize, + off: usize, + src: usize, + }, } /// One block's whole-block prediction build, deferred to a recon worker. @@ -2954,12 +3079,12 @@ fn push_pred<'a>( ) + 'a, ) { type Dyn<'x> = dyn FnOnce( - &mut PlaneBuf<'static>, - &mut PlaneBuf<'static>, - &mut PlaneBuf<'static>, - &crate::decode::FrameCtx, - &mut [Vec; 3], - ) + 'x; + &mut PlaneBuf<'static>, + &mut PlaneBuf<'static>, + &mut PlaneBuf<'static>, + &crate::decode::FrameCtx, + &mut [Vec; 3], + ) + 'x; let boxed: Box> = Box::new(f); // SAFETY: see [`PredBuild`] -- every worker is joined by [`WaveGuard`] // before the borrows the closure holds go out of scope. @@ -3090,7 +3215,16 @@ fn push_op(fctx: &crate::decode::FrameCtx, op: ReconOp) { // The inline path never records coefficients (the transform runs at // the push site), so the arena is not read here. unsafe { - exec_op(op, &mut *y, &mut *u, &mut *v, &mut Default::default(), &[], &[], fctx) + exec_op( + op, + &mut *y, + &mut *u, + &mut *v, + &mut Default::default(), + &[], + &[], + fctx, + ) }; return; } @@ -3172,11 +3306,7 @@ type JobBufs = (Vec, Vec, Vec); impl WaveQueue { /// The lowest-row queued job whose wavefront dependencies are satisfied, /// or `None` (with the blocking condition counted when instrumented). - fn take_runnable( - &mut self, - last_col: usize, - stats: bool, - ) -> Option<(usize, usize, ReconJob)> { + fn take_runnable(&mut self, last_col: usize, stats: bool) -> Option<(usize, usize, ReconJob)> { let mut blocked: Option = None; for r in 0..self.rows.len() { let Some(front) = self.rows[r].front() else { @@ -3312,10 +3442,16 @@ fn wave_worker(st: &WaveState, idx: usize) { // every superblock that could have written or be reading them is // complete by the wavefront rule above. let mut cur: [Vec; 3] = Default::default(); - let ReconJob { mut ops, mut coeffs, mut preds } = job; + let ReconJob { + mut ops, + mut coeffs, + mut preds, + } = job; unsafe { for op in ops.drain(..) { - exec_op(op, &mut *y, &mut *u, &mut *v, &mut cur, &coeffs, &preds, &fctx); + exec_op( + op, &mut *y, &mut *u, &mut *v, &mut cur, &coeffs, &preds, &fctx, + ); } } if stats { @@ -3361,7 +3497,9 @@ impl<'a> WaveGuard<'a> { } let st = std::sync::Arc::new(WaveState { q: std::sync::Mutex::new(WaveQueue { - rows: (0..rows).map(|_| std::collections::VecDeque::new()).collect(), + rows: (0..rows) + .map(|_| std::collections::VecDeque::new()) + .collect(), queued: 0, done: vec![-1; rows], last_sub: vec![-1; rows], @@ -3393,7 +3531,8 @@ impl<'a> WaveGuard<'a> { batch.submit(move || wave_worker(&st, idx)); } fctx.wave.with(|w| *w.borrow_mut() = Some(st)); - fctx.wave_mark.with(|c| c.set(Some(std::time::Instant::now()))); + fctx.wave_mark + .with(|c| c.set(Some(std::time::Instant::now()))); Some(Self(fctx, Some(batch))) } } @@ -3527,8 +3666,24 @@ fn inline_intra( // SAFETY: see [`ReconPlanes`]. unsafe { exec_intra( - &mut *y, &mut *u, &mut *v, plane, x, oy, bw, bh, rect, mode, angle_delta, reach, - residual, cfl, filter_intra, smooth_neighbor, pred, fctx, + &mut *y, + &mut *u, + &mut *v, + plane, + x, + oy, + bw, + bh, + rect, + mode, + angle_delta, + reach, + residual, + cfl, + filter_intra, + smooth_neighbor, + pred, + fctx, ); } true @@ -3553,7 +3708,9 @@ fn inline_mc( }; // SAFETY: see [`ReconPlanes`]. unsafe { - exec_mc(&mut *y, &mut *u, &mut *v, plane, x, oy, stride, w, h, prediction, residual, fctx); + exec_mc( + &mut *y, &mut *u, &mut *v, plane, x, oy, stride, w, h, prediction, residual, fctx, + ); } true } @@ -3571,19 +3728,47 @@ fn push_intra( residual: &[i32], cfl: Option<(i32, CflSrc)>, filter_intra: Option, - smooth_neighbor: bool, fctx: &crate::decode::FrameCtx, + smooth_neighbor: bool, + fctx: &crate::decode::FrameCtx, ) { if inline_intra( - plane, x, y, side, side, false, mode, angle_delta, reach, residual, cfl, filter_intra, - smooth_neighbor, fctx, + plane, + x, + y, + side, + side, + false, + mode, + angle_delta, + reach, + residual, + cfl, + filter_intra, + smooth_neighbor, + fctx, ) { return; } let pred = take_palette_pred(fctx); - push_op(fctx, ReconOp::Intra { - plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach, - residual: Residual::done(residual, fctx), cfl, filter_intra, smooth_neighbor, pred, - }); + push_op( + fctx, + ReconOp::Intra { + plane, + x, + y, + bw: side, + bh: side, + rect: false, + mode, + angle_delta, + reach, + residual: Residual::done(residual, fctx), + cfl, + filter_intra, + smooth_neighbor, + pred, + }, + ); } /// [`PlaneBuf::reconstruct_rect`], recorded (lane-wave1 step (i)). @@ -3600,19 +3785,47 @@ fn push_intra_rect( residual: &[i32], cfl: Option<(i32, CflSrc)>, filter_intra: Option, - smooth_neighbor: bool, fctx: &crate::decode::FrameCtx, + smooth_neighbor: bool, + fctx: &crate::decode::FrameCtx, ) { if inline_intra( - plane, x, y, bw, bh, true, mode, angle_delta, reach, residual, cfl, filter_intra, - smooth_neighbor, fctx, + plane, + x, + y, + bw, + bh, + true, + mode, + angle_delta, + reach, + residual, + cfl, + filter_intra, + smooth_neighbor, + fctx, ) { return; } let pred = take_palette_pred(fctx); - push_op(fctx, ReconOp::Intra { - plane, x, y, bw, bh, rect: true, mode, angle_delta, reach, - residual: Residual::done(residual, fctx), cfl, filter_intra, smooth_neighbor, pred, - }); + push_op( + fctx, + ReconOp::Intra { + plane, + x, + y, + bw, + bh, + rect: true, + mode, + angle_delta, + reach, + residual: Residual::done(residual, fctx), + cfl, + filter_intra, + smooth_neighbor, + pred, + }, + ); } /// [`PlaneBuf::reconstruct_mc_rect`] at `stride == w == h == side`, recorded. @@ -3622,7 +3835,8 @@ fn push_mc( y: usize, side: usize, prediction: Pred<'_>, - residual: &[i32], fctx: &crate::decode::FrameCtx, + residual: &[i32], + fctx: &crate::decode::FrameCtx, ) { push_mc_rect(plane, x, y, side, side, side, prediction, residual, fctx); } @@ -3637,30 +3851,58 @@ fn push_mc_rect( w: usize, h: usize, prediction: Pred<'_>, - residual: &[i32], fctx: &crate::decode::FrameCtx, + residual: &[i32], + fctx: &crate::decode::FrameCtx, ) { let (src, stride) = match prediction.inline(stride) { Some(v) => v, None => { - let Pred::Cur { plane: sp, stride: ss, off } = prediction else { unreachable!() }; - push_op(fctx, ReconOp::Mc { - plane, x, y, stride: ss, w, h, - prediction: PredSrc::Cur { plane: sp, off, src: ss }, - residual: Residual::done(residual, fctx), - }); + let Pred::Cur { + plane: sp, + stride: ss, + off, + } = prediction + else { + unreachable!() + }; + push_op( + fctx, + ReconOp::Mc { + plane, + x, + y, + stride: ss, + w, + h, + prediction: PredSrc::Cur { + plane: sp, + off, + src: ss, + }, + residual: Residual::done(residual, fctx), + }, + ); return; } }; if inline_mc(plane, x, y, stride, w, h, src, residual, fctx) { return; } - push_op(fctx, ReconOp::Mc { - plane, x, y, stride, w, h, - // The whole window `reconstruct_mc_rect` reads at `stride`, not - // `w * h`: the record keeps exactly what `src.to_vec()` carried. - prediction: PredSrc::Owned(push_pred_samples(src, fctx), src.len() as u32), - residual: Residual::done(residual, fctx), - }); + push_op( + fctx, + ReconOp::Mc { + plane, + x, + y, + stride, + w, + h, + // The whole window `reconstruct_mc_rect` reads at `stride`, not + // `w * h`: the record keeps exactly what `src.to_vec()` carried. + prediction: PredSrc::Owned(push_pred_samples(src, fctx), src.len() as u32), + residual: Residual::done(residual, fctx), + }, + ); } /// [`push_intra_rect`] carrying the transform's INPUTS: at one reconstruction @@ -3686,16 +3928,43 @@ fn push_intra_tx( ) { if fctx.recon_planes.with(std::cell::Cell::get).is_some() { inline_intra( - plane, x, y, bw, bh, rect, mode, angle_delta, reach, &tx.run(grid), cfl, filter_intra, - smooth_neighbor, fctx, + plane, + x, + y, + bw, + bh, + rect, + mode, + angle_delta, + reach, + &tx.run(grid), + cfl, + filter_intra, + smooth_neighbor, + fctx, ); return; } let pred = take_palette_pred(fctx); - push_op(fctx, ReconOp::Intra { - plane, x, y, bw, bh, rect, mode, angle_delta, reach, - residual: Residual::coeffs(tx, grid, fctx), cfl, filter_intra, smooth_neighbor, pred, - }); + push_op( + fctx, + ReconOp::Intra { + plane, + x, + y, + bw, + bh, + rect, + mode, + angle_delta, + reach, + residual: Residual::coeffs(tx, grid, fctx), + cfl, + filter_intra, + smooth_neighbor, + pred, + }, + ); } /// [`push_mc_rect`] carrying the transform's inputs -- see [`push_intra_tx`]. @@ -3719,14 +3988,33 @@ fn push_mc_rect_tx( let (prediction, stride) = match prediction.inline(stride) { Some(v) => v, None => { - let Pred::Cur { plane: sp, stride: ss, off } = prediction else { unreachable!() }; + let Pred::Cur { + plane: sp, + stride: ss, + off, + } = prediction + else { + unreachable!() + }; let mut tx = tx; tx.stride = 0; - push_op(fctx, ReconOp::Mc { - plane, x, y, stride: w, w, h, - prediction: PredSrc::Cur { plane: sp, off, src: ss }, - residual: Residual::coeffs(tx, grid, fctx), - }); + push_op( + fctx, + ReconOp::Mc { + plane, + x, + y, + stride: w, + w, + h, + prediction: PredSrc::Cur { + plane: sp, + off, + src: ss, + }, + residual: Residual::coeffs(tx, grid, fctx), + }, + ); return; } }; @@ -3768,10 +4056,19 @@ fn push_mc_rect_tx( }); let mut tx = tx; tx.stride = 0; - push_op(fctx, ReconOp::Mc { - plane, x, y, stride: w, w, h, prediction: PredSrc::Owned(off, (w * h) as u32), - residual: Residual::coeffs(tx, grid, fctx), - }); + push_op( + fctx, + ReconOp::Mc { + plane, + x, + y, + stride: w, + w, + h, + prediction: PredSrc::Owned(off, (w * h) as u32), + residual: Residual::coeffs(tx, grid, fctx), + }, + ); } /// Replays every recorded [`ReconOp`] into the frame's planes, in push order, @@ -3791,12 +4088,21 @@ fn flush_recon( // lane-wave1 step (ii): a parse-time pixel READ needs every worker's // writes in place, not just this superblock's queue. wave_barrier(fctx); - let mut ops = fctx.recon_spare.with(|c| std::mem::take(&mut *c.borrow_mut())); - fctx.recon_ops.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut ops)); - let mut coeffs = fctx.coeff_spare.with(|c| std::mem::take(&mut *c.borrow_mut())); - fctx.coeff_arena.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut coeffs)); - let mut preds = fctx.pred_spare.with(|c| std::mem::take(&mut *c.borrow_mut())); - fctx.pred_arena.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut preds)); + let mut ops = fctx + .recon_spare + .with(|c| std::mem::take(&mut *c.borrow_mut())); + fctx.recon_ops + .with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut ops)); + let mut coeffs = fctx + .coeff_spare + .with(|c| std::mem::take(&mut *c.borrow_mut())); + fctx.coeff_arena + .with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut coeffs)); + let mut preds = fctx + .pred_spare + .with(|c| std::mem::take(&mut *c.borrow_mut())); + fctx.pred_arena + .with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut preds)); let mut cur: [Vec; 3] = Default::default(); for op in ops.drain(..) { exec_op(op, y, u, v, &mut cur, &coeffs, &preds, fctx); @@ -3838,24 +4144,77 @@ fn exec_op( match op { ReconOp::Pred(b) => (b.0)(y, u, v, fctx, cur), ReconOp::Intra { - plane, x, y: oy, bw, bh, rect, mode, angle_delta, reach, residual, cfl, - filter_intra, smooth_neighbor, pred, + plane, + x, + y: oy, + bw, + bh, + rect, + mode, + angle_delta, + reach, + residual, + cfl, + filter_intra, + smooth_neighbor, + pred, } => exec_intra( - y, u, v, plane, x, oy, bw, bh, rect, mode, angle_delta, reach, + y, + u, + v, + plane, + x, + oy, + bw, + bh, + rect, + mode, + angle_delta, + reach, residual.resolve(coeffs, &mut scratch), - cfl, filter_intra, smooth_neighbor, pred, fctx, + cfl, + filter_intra, + smooth_neighbor, + pred, + fctx, ), - ReconOp::Mc { plane, x, y: oy, stride, w, h, prediction, residual } => { + ReconOp::Mc { + plane, + x, + y: oy, + stride, + w, + h, + prediction, + residual, + } => { let residual = residual.resolve(coeffs, &mut scratch); match prediction { PredSrc::Owned(off, len) => { let p = &preds[off as usize..][..len as usize]; exec_mc(y, u, v, plane, x, oy, stride, w, h, p, residual, fctx); } - PredSrc::Cur { plane: sp, off, src } => { + PredSrc::Cur { + plane: sp, + off, + src, + } => { let block = std::mem::take(&mut cur[sp]); if src == stride { - exec_mc(y, u, v, plane, x, oy, stride, w, h, &block[off..], residual, fctx); + exec_mc( + y, + u, + v, + plane, + x, + oy, + stride, + w, + h, + &block[off..], + residual, + fctx, + ); } else { // A transform unit's residual is dense, so its window // of the block prediction is taken out dense too -- @@ -3906,16 +4265,41 @@ fn exec_intra( (alpha, sig) }); let cfl = ac.as_ref().map(|(a, sig)| (*a, sig.as_slice())); - let target: &mut PlaneBuf<'static> = match plane { 0 => &mut *y, 1 => &mut *u, _ => &mut *v }; + let target: &mut PlaneBuf<'static> = match plane { + 0 => &mut *y, + 1 => &mut *u, + _ => &mut *v, + }; if rect { target.reconstruct_rect( - x, oy, bw, bh, mode, angle_delta, reach, residual, cfl, filter_intra, - smooth_neighbor, pred, fctx, + x, + oy, + bw, + bh, + mode, + angle_delta, + reach, + residual, + cfl, + filter_intra, + smooth_neighbor, + pred, + fctx, ); } else { target.reconstruct( - x, oy, bw, mode, angle_delta, reach, residual, cfl, filter_intra, - smooth_neighbor, pred, fctx, + x, + oy, + bw, + mode, + angle_delta, + reach, + residual, + cfl, + filter_intra, + smooth_neighbor, + pred, + fctx, ); } } @@ -3936,7 +4320,11 @@ fn exec_mc( residual: &[i32], fctx: &crate::decode::FrameCtx, ) { - let target: &mut PlaneBuf<'static> = match plane { 0 => &mut *y, 1 => &mut *u, _ => &mut *v }; + let target: &mut PlaneBuf<'static> = match plane { + 0 => &mut *y, + 1 => &mut *u, + _ => &mut *v, + }; target.reconstruct_mc_rect(x, oy, stride, w, h, prediction, residual, fctx); } @@ -3962,19 +4350,19 @@ thread_local! { /// is never reconstructed). static INTRABC_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } - // The `tx_type` the last plane-0 [`read_plane`] actually coded, kept so - // an intrabc block's chroma reads can inherit it (see - // [`INTRABC_CHROMA_TX`]). Written on every luma read; only ever read - // through that one arming site. - // libaom `av1_get_tx_type` (`blockd.h:1350`): for `PLANE_TYPE_UV` it - // branches on `is_inter_block(mbmi)` -- which `is_intrabc_block` also - // satisfies (`blockd.h:373`) -- and takes the *colocated luma - // transform's coded* `tx_type` (`mbmi->txk_type[...]`), never - // `intra_mode_to_tx_type` of the chroma mode. `Some` only across an - // intrabc block's two chroma [`read_plane`] calls; the type decides the - // `TX_CLASS`, hence the scan order, `eob_multi_ctx` and every nz context - // -- getting it wrong desyncs the chroma coefficients, it is not a - // reconstruction-only detail. +// The `tx_type` the last plane-0 [`read_plane`] actually coded, kept so +// an intrabc block's chroma reads can inherit it (see +// [`INTRABC_CHROMA_TX`]). Written on every luma read; only ever read +// through that one arming site. +// libaom `av1_get_tx_type` (`blockd.h:1350`): for `PLANE_TYPE_UV` it +// branches on `is_inter_block(mbmi)` -- which `is_intrabc_block` also +// satisfies (`blockd.h:373`) -- and takes the *colocated luma +// transform's coded* `tx_type` (`mbmi->txk_type[...]`), never +// `intra_mode_to_tx_type` of the chroma mode. `Some` only across an +// intrabc block's two chroma [`read_plane`] calls; the type decides the +// `TX_CLASS`, hence the scan order, `eob_multi_ctx` and every nz context +// -- getting it wrong desyncs the chroma coefficients, it is not a +// reconstruction-only detail. /// Whether this frame's header set `allow_intrabc` -- [`INTRABC_MI_GRID`] is /// `Some` exactly then (set once per frame in `decode_frame`), so the flag @@ -4179,6 +4567,21 @@ thread_local! { /// guard (`decode_block_128rect`). A refused block bumps /// [`INTRABC_HITS`] but never this one. static INTRABC_128RECT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// lane-av1-ibc128chunk: chroma transform units the 128-root intrabc + /// strip's mu-chunk walk read, one per `read_inter_plane` chroma call. + /// At 4:2:0 a 64x64 mu chunk's chroma plane block is 32x32, so one + /// TX_32X32 per plane per chunk; at 4:2:2 it is 32x64 and holds TWO + /// STACKED units per plane. The square-cut `chunk_chroma = cside * 64 / + /// side` model walked the 4:2:0 count on every axis, so this counter is + /// the reach/arm witness for the per-axis walk. + static INTRABC_128RECT_CHROMA_CHUNK_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; + /// lane-av1-ibc128chunk: the mu-chunk walk's per-axis chroma extents, as + /// `(64 >> ss_x) << 8 | (64 >> ss_y)` on the LAST chunk -- the pair the + /// per-axis walk used. A 4:2:2 run and a 4:2:0 run of the same block + /// differ here (32|64 vs 32|32), which is what the de-square-cut fixes. + static INTRABC_128RECT_CHUNK_SHAPE: std::cell::Cell = + const { std::cell::Cell::new(0) }; } /// Current value of [`INTRABC_128RECT_HITS`]. @@ -4193,6 +4596,26 @@ pub(crate) fn reset_intrabc_128rect_hits() { INTRABC_128RECT_HITS.with(|c| c.set(0)); } +/// Current value of [`INTRABC_128RECT_CHROMA_CHUNK_HITS`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub fn intrabc_128rect_chroma_chunk_hits() -> usize { + INTRABC_128RECT_CHROMA_CHUNK_HITS.with(|c| c.get()) +} + +/// Current value of [`INTRABC_128RECT_CHUNK_SHAPE`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub fn intrabc_128rect_chunk_shape() -> usize { + INTRABC_128RECT_CHUNK_SHAPE.with(|c| c.get()) +} + +/// Zeroes [`INTRABC_128RECT_CHROMA_CHUNK_HITS`] and +/// [`INTRABC_128RECT_CHUNK_SHAPE`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn reset_intrabc_128rect_chroma_chunk_hits() { + INTRABC_128RECT_CHROMA_CHUNK_HITS.with(|c| c.set(0)); + INTRABC_128RECT_CHUNK_SHAPE.with(|c| c.set(0)); +} + /// Current value of [`INTRABC_VARTX_HITS`]. pub fn intrabc_vartx_hits() -> usize { INTRABC_VARTX_HITS.with(|c| c.get()) @@ -4226,7 +4649,14 @@ pub fn rect_intrabc_vartx_hits() -> usize { /// its size (libaom's `scan_row_mbmi` advances `processed_rows` off any /// candidate's `bsize`, ref-match or not), an intrabc one also its DV as an /// `INTRA_FRAME` candidate (libaom treats intrabc as `is_inter_block`). -fn record_intrabc_mi(mi_r: usize, mi_c: usize, n4: usize, dv: Option<(i32, i32)>, n: &mut Neighbours, fctx: &crate::decode::FrameCtx) { +fn record_intrabc_mi( + mi_r: usize, + mi_c: usize, + n4: usize, + dv: Option<(i32, i32)>, + n: &mut Neighbours, + fctx: &crate::decode::FrameCtx, +) { record_intrabc_mi_rect(mi_r, mi_c, n4, n4, dv, n, fctx); } @@ -5461,8 +5891,8 @@ pub(crate) struct InterStripChroma { prev: Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>, } - /// The single-reference MC parameters of the inter block that decoded - /// last -- read by the next 1:4 strip to build its pair's chroma. +/// The single-reference MC parameters of the inter block that decoded +/// last -- read by the next 1:4 strip to build its pair's chroma. fn bump_ab16_inter(arm: usize) { hit_do! { @@ -5820,7 +6250,11 @@ pub(crate) fn build_motion_field( let i = rf.wrapping_sub(LAST_FRAME as usize); order_hint_bits != 0 && i < 7 - && (crate::motion_field::get_relative_dist(order_hint_bits, ref_order_hints[i], order_hint) > 0 + && (crate::motion_field::get_relative_dist( + order_hint_bits, + ref_order_hints[i], + order_hint, + ) > 0 || ref_order_hints[i] == order_hint) }); // libaom `REFMVS_LIMIT` (`mvref_common.h`): a stored motion field mv is @@ -5913,11 +6347,11 @@ pub(crate) fn ref_hits(ref_frame: i8) -> usize { c.with(|v| v.get()) } - /// The sequence header's `enable_intra_edge_filter`, set once per - /// [`decode_key_frame_tile_with_cdfs`] call: [`PlaneBuf::reconstruct`]'s - /// own read of it, kept off the call stack (see that function's own doc - /// comment for why) rather than threaded through every `read_plane`/ - /// `decode_block`/`decode_leaf8` call between here and there. +/// The sequence header's `enable_intra_edge_filter`, set once per +/// [`decode_key_frame_tile_with_cdfs`] call: [`PlaneBuf::reconstruct`]'s +/// own read of it, kept off the call stack (see that function's own doc +/// comment for why) rather than threaded through every `read_plane`/ +/// `decode_block`/`decode_leaf8` call between here and there. /// Set [`ENABLE_EDGE_FILTER`] for this thread. /// @@ -6496,9 +6930,7 @@ fn br_ctx(grid: &[u8], stride: usize, row: usize, col: usize, class: TxClass) -> TxClass::Horiz => neighbour(grid, stride, row, col + 2), TxClass::Vert => neighbour(grid, stride, row + 2, col), }; - let mag = neighbour(grid, stride, row + 1, col) - + neighbour(grid, stride, row, col + 1) - + extra; + let mag = neighbour(grid, stride, row + 1, col) + neighbour(grid, stride, row, col + 1) + extra; let mag = (((mag + 1) >> 1).min(6)) as usize; if row == 0 && col == 0 { return mag; @@ -6517,33 +6949,33 @@ fn br_ctx(grid: &[u8], stride: usize, row: usize, col: usize, class: TxClass) -> /// against the real table). Not the square zigzag formula generalized to /// unequal `w`/`h` -- checked and that does NOT reproduce this table. const SCAN_32X16: [u16; 512] = [ - 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, - 130, 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 256, 225, 194, 163, 132, 101, 70, 39, - 8, 288, 257, 226, 195, 164, 133, 102, 71, 40, 9, 320, 289, 258, 227, 196, 165, 134, 103, 72, - 41, 10, 352, 321, 290, 259, 228, 197, 166, 135, 104, 73, 42, 11, 384, 353, 322, 291, 260, 229, - 198, 167, 136, 105, 74, 43, 12, 416, 385, 354, 323, 292, 261, 230, 199, 168, 137, 106, 75, 44, - 13, 448, 417, 386, 355, 324, 293, 262, 231, 200, 169, 138, 107, 76, 45, 14, 480, 449, 418, - 387, 356, 325, 294, 263, 232, 201, 170, 139, 108, 77, 46, 15, 481, 450, 419, 388, 357, 326, - 295, 264, 233, 202, 171, 140, 109, 78, 47, 16, 482, 451, 420, 389, 358, 327, 296, 265, 234, - 203, 172, 141, 110, 79, 48, 17, 483, 452, 421, 390, 359, 328, 297, 266, 235, 204, 173, 142, - 111, 80, 49, 18, 484, 453, 422, 391, 360, 329, 298, 267, 236, 205, 174, 143, 112, 81, 50, 19, - 485, 454, 423, 392, 361, 330, 299, 268, 237, 206, 175, 144, 113, 82, 51, 20, 486, 455, 424, - 393, 362, 331, 300, 269, 238, 207, 176, 145, 114, 83, 52, 21, 487, 456, 425, 394, 363, 332, - 301, 270, 239, 208, 177, 146, 115, 84, 53, 22, 488, 457, 426, 395, 364, 333, 302, 271, 240, - 209, 178, 147, 116, 85, 54, 23, 489, 458, 427, 396, 365, 334, 303, 272, 241, 210, 179, 148, - 117, 86, 55, 24, 490, 459, 428, 397, 366, 335, 304, 273, 242, 211, 180, 149, 118, 87, 56, 25, - 491, 460, 429, 398, 367, 336, 305, 274, 243, 212, 181, 150, 119, 88, 57, 26, 492, 461, 430, - 399, 368, 337, 306, 275, 244, 213, 182, 151, 120, 89, 58, 27, 493, 462, 431, 400, 369, 338, - 307, 276, 245, 214, 183, 152, 121, 90, 59, 28, 494, 463, 432, 401, 370, 339, 308, 277, 246, - 215, 184, 153, 122, 91, 60, 29, 495, 464, 433, 402, 371, 340, 309, 278, 247, 216, 185, 154, - 123, 92, 61, 30, 496, 465, 434, 403, 372, 341, 310, 279, 248, 217, 186, 155, 124, 93, 62, 31, - 497, 466, 435, 404, 373, 342, 311, 280, 249, 218, 187, 156, 125, 94, 63, 498, 467, 436, 405, - 374, 343, 312, 281, 250, 219, 188, 157, 126, 95, 499, 468, 437, 406, 375, 344, 313, 282, 251, - 220, 189, 158, 127, 500, 469, 438, 407, 376, 345, 314, 283, 252, 221, 190, 159, 501, 470, 439, - 408, 377, 346, 315, 284, 253, 222, 191, 502, 471, 440, 409, 378, 347, 316, 285, 254, 223, 503, - 472, 441, 410, 379, 348, 317, 286, 255, 504, 473, 442, 411, 380, 349, 318, 287, 505, 474, 443, - 412, 381, 350, 319, 506, 475, 444, 413, 382, 351, 507, 476, 445, 414, 383, 508, 477, 446, 415, - 509, 478, 447, 510, 479, 511, + 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, 130, + 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 256, 225, 194, 163, 132, 101, 70, 39, 8, + 288, 257, 226, 195, 164, 133, 102, 71, 40, 9, 320, 289, 258, 227, 196, 165, 134, 103, 72, 41, + 10, 352, 321, 290, 259, 228, 197, 166, 135, 104, 73, 42, 11, 384, 353, 322, 291, 260, 229, 198, + 167, 136, 105, 74, 43, 12, 416, 385, 354, 323, 292, 261, 230, 199, 168, 137, 106, 75, 44, 13, + 448, 417, 386, 355, 324, 293, 262, 231, 200, 169, 138, 107, 76, 45, 14, 480, 449, 418, 387, + 356, 325, 294, 263, 232, 201, 170, 139, 108, 77, 46, 15, 481, 450, 419, 388, 357, 326, 295, + 264, 233, 202, 171, 140, 109, 78, 47, 16, 482, 451, 420, 389, 358, 327, 296, 265, 234, 203, + 172, 141, 110, 79, 48, 17, 483, 452, 421, 390, 359, 328, 297, 266, 235, 204, 173, 142, 111, 80, + 49, 18, 484, 453, 422, 391, 360, 329, 298, 267, 236, 205, 174, 143, 112, 81, 50, 19, 485, 454, + 423, 392, 361, 330, 299, 268, 237, 206, 175, 144, 113, 82, 51, 20, 486, 455, 424, 393, 362, + 331, 300, 269, 238, 207, 176, 145, 114, 83, 52, 21, 487, 456, 425, 394, 363, 332, 301, 270, + 239, 208, 177, 146, 115, 84, 53, 22, 488, 457, 426, 395, 364, 333, 302, 271, 240, 209, 178, + 147, 116, 85, 54, 23, 489, 458, 427, 396, 365, 334, 303, 272, 241, 210, 179, 148, 117, 86, 55, + 24, 490, 459, 428, 397, 366, 335, 304, 273, 242, 211, 180, 149, 118, 87, 56, 25, 491, 460, 429, + 398, 367, 336, 305, 274, 243, 212, 181, 150, 119, 88, 57, 26, 492, 461, 430, 399, 368, 337, + 306, 275, 244, 213, 182, 151, 120, 89, 58, 27, 493, 462, 431, 400, 369, 338, 307, 276, 245, + 214, 183, 152, 121, 90, 59, 28, 494, 463, 432, 401, 370, 339, 308, 277, 246, 215, 184, 153, + 122, 91, 60, 29, 495, 464, 433, 402, 371, 340, 309, 278, 247, 216, 185, 154, 123, 92, 61, 30, + 496, 465, 434, 403, 372, 341, 310, 279, 248, 217, 186, 155, 124, 93, 62, 31, 497, 466, 435, + 404, 373, 342, 311, 280, 249, 218, 187, 156, 125, 94, 63, 498, 467, 436, 405, 374, 343, 312, + 281, 250, 219, 188, 157, 126, 95, 499, 468, 437, 406, 375, 344, 313, 282, 251, 220, 189, 158, + 127, 500, 469, 438, 407, 376, 345, 314, 283, 252, 221, 190, 159, 501, 470, 439, 408, 377, 346, + 315, 284, 253, 222, 191, 502, 471, 440, 409, 378, 347, 316, 285, 254, 223, 503, 472, 441, 410, + 379, 348, 317, 286, 255, 504, 473, 442, 411, 380, 349, 318, 287, 505, 474, 443, 412, 381, 350, + 319, 506, 475, 444, 413, 382, 351, 507, 476, 445, 414, 383, 508, 477, 446, 415, 509, 478, 447, + 510, 479, 511, ]; /// `Default_Scan_16x32`, this decoder's own row-major transcription (see @@ -6623,18 +7055,18 @@ const SCAN_8X16: [u16; 128] = [ /// are byte-identical to this decoder's [`SCAN_8X16`]. const SCAN_32X8: [u16; 256] = [ 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, 130, - 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 225, 194, 163, 132, 101, 70, 39, 8, 226, 195, - 164, 133, 102, 71, 40, 9, 227, 196, 165, 134, 103, 72, 41, 10, 228, 197, 166, 135, 104, 73, 42, - 11, 229, 198, 167, 136, 105, 74, 43, 12, 230, 199, 168, 137, 106, 75, 44, 13, 231, 200, 169, - 138, 107, 76, 45, 14, 232, 201, 170, 139, 108, 77, 46, 15, 233, 202, 171, 140, 109, 78, 47, 16, - 234, 203, 172, 141, 110, 79, 48, 17, 235, 204, 173, 142, 111, 80, 49, 18, 236, 205, 174, 143, - 112, 81, 50, 19, 237, 206, 175, 144, 113, 82, 51, 20, 238, 207, 176, 145, 114, 83, 52, 21, 239, - 208, 177, 146, 115, 84, 53, 22, 240, 209, 178, 147, 116, 85, 54, 23, 241, 210, 179, 148, 117, - 86, 55, 24, 242, 211, 180, 149, 118, 87, 56, 25, 243, 212, 181, 150, 119, 88, 57, 26, 244, 213, - 182, 151, 120, 89, 58, 27, 245, 214, 183, 152, 121, 90, 59, 28, 246, 215, 184, 153, 122, 91, - 60, 29, 247, 216, 185, 154, 123, 92, 61, 30, 248, 217, 186, 155, 124, 93, 62, 31, 249, 218, 187, - 156, 125, 94, 63, 250, 219, 188, 157, 126, 95, 251, 220, 189, 158, 127, 252, 221, 190, 159, 253, - 222, 191, 254, 223, 255, + 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 225, 194, 163, 132, 101, 70, 39, 8, 226, + 195, 164, 133, 102, 71, 40, 9, 227, 196, 165, 134, 103, 72, 41, 10, 228, 197, 166, 135, 104, + 73, 42, 11, 229, 198, 167, 136, 105, 74, 43, 12, 230, 199, 168, 137, 106, 75, 44, 13, 231, 200, + 169, 138, 107, 76, 45, 14, 232, 201, 170, 139, 108, 77, 46, 15, 233, 202, 171, 140, 109, 78, + 47, 16, 234, 203, 172, 141, 110, 79, 48, 17, 235, 204, 173, 142, 111, 80, 49, 18, 236, 205, + 174, 143, 112, 81, 50, 19, 237, 206, 175, 144, 113, 82, 51, 20, 238, 207, 176, 145, 114, 83, + 52, 21, 239, 208, 177, 146, 115, 84, 53, 22, 240, 209, 178, 147, 116, 85, 54, 23, 241, 210, + 179, 148, 117, 86, 55, 24, 242, 211, 180, 149, 118, 87, 56, 25, 243, 212, 181, 150, 119, 88, + 57, 26, 244, 213, 182, 151, 120, 89, 58, 27, 245, 214, 183, 152, 121, 90, 59, 28, 246, 215, + 184, 153, 122, 91, 60, 29, 247, 216, 185, 154, 123, 92, 61, 30, 248, 217, 186, 155, 124, 93, + 62, 31, 249, 218, 187, 156, 125, 94, 63, 250, 219, 188, 157, 126, 95, 251, 220, 189, 158, 127, + 252, 221, 190, 159, 253, 222, 191, 254, 223, 255, ]; /// `Default_Scan_8x32`, [`SCAN_32X8`]'s transpose (the chroma plane of a /// 16x64 `PARTITION_VERT_4` strip). @@ -6737,13 +7169,7 @@ fn base_ctx_rect( /// its body was character-for-character [`br_ctx`]'s, which /// `flat_taps_match_the_row_col_neighbour_reads` now asserts. #[cfg(test)] -fn br_ctx_rect( - grid: &[u8], - stride: usize, - row: usize, - col: usize, - class: TxClass, -) -> usize { +fn br_ctx_rect(grid: &[u8], stride: usize, row: usize, col: usize, class: TxClass) -> usize { let extra = match class { TxClass::TwoD => neighbour_rect(grid, stride, row + 1, col + 1), TxClass::Horiz => neighbour_rect(grid, stride, row, col + 2), @@ -6933,7 +7359,9 @@ fn is_smooth_mode(mode: usize) -> bool { #[cold] #[inline(never)] fn trace_base_eob(scan_idx: usize, pos: usize, row: usize, col: usize, ctx: usize, v: i32) { - eprintln!("TRACE base_eob scan_idx={scan_idx} pos={pos} row={row} col={col} ctx={ctx} value={v}"); + eprintln!( + "TRACE base_eob scan_idx={scan_idx} pos={pos} row={row} col={col} ctx={ctx} value={v}" + ); } #[cold] @@ -6966,7 +7394,10 @@ fn coeff_step_br(dec: &SymbolDecoder, scan_idx: usize, apos: usize, ctx: usize, #[inline(never)] fn coeff_step_sign(dec: &SymbolDecoder, c: usize, negative: bool) { let (rng, _) = dec.debug_state(); - eprintln!("EC_COEFF_STEP tag=sign c={c} sign={} rng={rng}", negative as i32); + eprintln!( + "EC_COEFF_STEP tag=sign c={c} sign={} rng={rng}", + negative as i32 + ); } #[cold] @@ -7026,14 +7457,15 @@ fn read_coeffs( let (rng, _) = dec.debug_state(); eprintln!( "EC_COEFF_STEP tag=all_zero side={} ctx={skip_ctx} dcctx={sign_ctx} cdf={dbg_txbskip:?} all_zero={} rng={rng}", - coding.side, - all_zero as i32 + coding.side, all_zero as i32 ); } if crate::envflags::env_flag!("EC_AV1_TELL") { eprintln!( "TELL label=post_txb_skip ctx={skip_ctx} all_zero={} tell={} range={}", - all_zero as u8, dec.debug_bitpos(), dec.debug_state().0 + all_zero as u8, + dec.debug_bitpos(), + dec.debug_state().0 ); } if trace { @@ -7076,8 +7508,9 @@ fn read_coeffs( if trace { eprintln!("TRACE tx_type value={t} len={len}"); } - tx_type = tx_type_from_symbol(len, t) - .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; + tx_type = tx_type_from_symbol(len, t).ok_or_else(|| { + unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")) + })?; } let class = TxClass::of(tx_type); @@ -7092,7 +7525,11 @@ fn read_coeffs( let ec_trace_coeff = coeff_trace_on(); if ec_trace_coeff { let (rng, _) = dec.debug_state(); - let cls = match class { TxClass::TwoD => "2d", TxClass::Horiz => "horiz", TxClass::Vert => "vert" }; + let cls = match class { + TxClass::TwoD => "2d", + TxClass::Horiz => "horiz", + TxClass::Vert => "vert", + }; eprintln!("EC_COEFF_STEP tag=eob eob={eob} tx={tx_type:?} class={cls} rng={rng}"); } let class_scan; @@ -7297,10 +7734,14 @@ fn read_coeffs_rect( let len = tx_type_cdf.len(); let t = dec.symbol(tx_type_cdf); crate::census::tx_type(len, t); - tx_type = tx_type_from_symbol(len, t) - .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; + tx_type = tx_type_from_symbol(len, t).ok_or_else(|| { + unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")) + })?; if rect_trace { - eprintln!("EC_COEFF_STEP tag=tx_type plane=0 rng={}", dec.debug_state().0); + eprintln!( + "EC_COEFF_STEP tag=tx_type plane=0 rng={}", + dec.debug_state().0 + ); } } let class = TxClass::of(tx_type); @@ -7309,7 +7750,10 @@ fn read_coeffs_rect( } let eob = read_eob(dec, coding, class); if rect_trace { - eprintln!("EC_COEFF_STEP tag=eob eob={eob} rng={}", dec.debug_state().0); + eprintln!( + "EC_COEFF_STEP tag=eob eob={eob} rng={}", + dec.debug_state().0 + ); } let class_scan; let scan: &[u16] = if class == TxClass::TwoD { @@ -7449,7 +7893,10 @@ fn read_coeffs_rect( }; if rect_trace { let (rng, _) = dec.debug_state(); - eprintln!("EC_COEFF_STEP tag=sign_rect pos={pos} sign={} dcctx={sign_ctx} rng={rng}", u8::from(negative)); + eprintln!( + "EC_COEFF_STEP tag=sign_rect pos={pos} sign={} dcctx={sign_ctx} rng={rng}", + u8::from(negative) + ); } let level = if level > MAX_BR_LEVEL { let g = read_golomb(dec)?; @@ -7470,7 +7917,10 @@ fn read_coeffs_rect( .filter(|&(_, &v)| v != 0) .map(|(i, &v)| format!("{}/{}:{v}", i / w, i % w)) .collect(); - eprintln!("OUR_LEVELS w={w} h={h} eob={eob} tx={tx_type:?} nz={}", nz.join(",")); + eprintln!( + "OUR_LEVELS w={w} h={h} eob={eob} tx={tx_type:?} nz={}", + nz.join(",") + ); } Ok((Grid::Own(grid), tx_type)) } @@ -7813,7 +8263,13 @@ struct Neighbours { impl Neighbours { /// `cols`/`rows` are in [`SUB`] units; `mi_cols`/`mi_rows` are the frame's /// true (unpadded) size in 4x4 mode-info units. - fn new(cols: usize, rows: usize, mi_cols: usize, mi_rows: usize, fctx: &crate::decode::FrameCtx) -> Self { + fn new( + cols: usize, + rows: usize, + mi_cols: usize, + mi_rows: usize, + fctx: &crate::decode::FrameCtx, + ) -> Self { // lane-sb128c r7: a 128x64 block at the bottom frame edge records its // neighbour state over the whole 64-row extent, past the frame's last // mi row (mi_rows 198, block rows 192..208). libaom's own context @@ -7822,10 +8278,7 @@ impl Neighbours { // side arrays to a superblock multiple and leave those cells unread -- // every availability check uses the true `mi_rows`/`mi_cols` below. let sb_sub = (sb_mi_cur(fctx) as usize) / (SUB / MI); - let (cols, rows) = ( - cols.next_multiple_of(sb_sub), - rows.next_multiple_of(sb_sub), - ); + let (cols, rows) = (cols.next_multiple_of(sb_sub), rows.next_multiple_of(sb_sub)); Self { above: vec![[Neighbour::default(); 3]; cols * (SUB / MI)], left: vec![[Neighbour::default(); 3]; rows * (SUB / MI)], @@ -7868,7 +8321,12 @@ impl Neighbours { mi_cols, mi_rows, blk_grid: vec![ - BlkCell { skip: false, written: false, org: [0; 2], dim: [1; 2] }; + BlkCell { + skip: false, + written: false, + org: [0; 2], + dim: [1; 2] + }; cols * (SUB / MI) * rows * (SUB / MI) ], skip_grid_cols_mi: cols * (SUB / MI), @@ -7897,7 +8355,13 @@ impl Neighbours { /// availability check below. Left context resets every superblock row /// regardless of tile ([`Self::start_row`], already called once per SB /// row by every caller) so it needs no tile-specific reset here. - fn start_tile(&mut self, row0_mi: usize, col0_mi: usize, col1_mi: usize, fctx: &crate::decode::FrameCtx) { + fn start_tile( + &mut self, + row0_mi: usize, + col0_mi: usize, + col1_mi: usize, + fctx: &crate::decode::FrameCtx, + ) { // lane-seg: `AvailU`/`AvailL` for the segment-id neighbour prediction // are tile-relative, same as every other neighbour lookup here. fctx.seg_tile_origin.with(|c| c.set((row0_mi, col0_mi))); @@ -7953,7 +8417,13 @@ impl Neighbours { /// mirrors [`Self::record_rect`]'s loop shape, square-only (this lane's /// call sites are all square blocks). fn record_palette_y(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { - self.record_palette_y_rect((at.0 * (SUB / MI), at.1 * (SUB / MI)), side, side, size, colors); + self.record_palette_y_rect( + (at.0 * (SUB / MI), at.1 * (SUB / MI)), + side, + side, + size, + colors, + ); } /// [`Self::record_palette_y`] with independent above (`w`)/left (`h`) @@ -8029,7 +8499,10 @@ impl Neighbours { // `xd->above_mbmi` exists for every row but the tile's own first. let above_is_palette = r > self.tile_row0_mi && self.above_palette_size[c] > 0; let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 { - (usize::from(self.above_palette_size[c]), self.above_palette_colors[c]) + ( + usize::from(self.above_palette_size[c]), + self.above_palette_colors[c], + ) } else { (0, [0u16; 8]) }; @@ -8040,7 +8513,10 @@ impl Neighbours { // and its `palette_y_mode` ctx. let left_ok = c > self.tile_col0_mi; let (left_n, left_colors) = if left_ok && self.left_palette_size[r] > 0 { - (usize::from(self.left_palette_size[r]), self.left_palette_colors[r]) + ( + usize::from(self.left_palette_size[r]), + self.left_palette_colors[r], + ) } else { (0, [0u16; 8]) }; @@ -8079,7 +8555,13 @@ impl Neighbours { /// As [`Self::record_palette_y`], for a just-decoded block's own chroma /// (U-channel) palette size/colours -- `size == 0` clears stale state the /// same way (lane-palette2 r1). - fn record_palette_uv(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { + fn record_palette_uv( + &mut self, + at: (usize, usize), + side: usize, + size: usize, + colors: [u16; 8], + ) { self.record_palette_uv_rect( (at.0 * (SUB / MI), at.1 * (SUB / MI)), side, @@ -8136,14 +8618,20 @@ impl Neighbours { let (r, c) = mi; let above_ok = r % 16 != 0; let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 { - (usize::from(self.above_palette_uv_size[c]), self.above_palette_uv_colors[c]) + ( + usize::from(self.above_palette_uv_size[c]), + self.above_palette_uv_colors[c], + ) } else { (0, [0u16; 8]) }; // Same tile-relative left availability as the luma cache above. let left_ok = c > self.tile_col0_mi; let (left_n, left_colors) = if left_ok && self.left_palette_uv_size[r] > 0 { - (usize::from(self.left_palette_uv_size[r]), self.left_palette_uv_colors[r]) + ( + usize::from(self.left_palette_uv_size[r]), + self.left_palette_uv_colors[r], + ) } else { (0, [0u16; 8]) }; @@ -8182,7 +8670,14 @@ impl Neighbours { /// transform width (in pixels) and `is_inter` flag -- the loop filter's /// per-edge lookup (`apply_deblock`), filled at the same call sites and /// units as [`Self::fill_skip_grid`]. - fn fill_lf_grid(&mut self, at_mi: (usize, usize), side_mi: usize, tx_px: u8, ref_frame: i8, fctx: &crate::decode::FrameCtx) { + fn fill_lf_grid( + &mut self, + at_mi: (usize, usize), + side_mi: usize, + tx_px: u8, + ref_frame: i8, + fctx: &crate::decode::FrameCtx, + ) { self.fill_lf_grid_rect(at_mi, side_mi, side_mi, tx_px, tx_px, ref_frame, fctx); } @@ -8218,7 +8713,8 @@ impl Neighbours { h_mi: usize, tx_px: u8, tx_h_px: u8, - ref_frame: i8, fctx: &crate::decode::FrameCtx, + ref_frame: i8, + fctx: &crate::decode::FrameCtx, ) { let (mi_r, mi_c) = at_mi; // `av1_get_max_uv_txsize` under 4:2:0: the block's chroma extent is @@ -8227,7 +8723,9 @@ impl Neighbours { let uv_tx_w = (((w_mi * MI) >> ss_x(fctx)).max(4).min(32)) as u8; let uv_tx_h = (((h_mi * MI) >> ss_y(fctx)).max(4).min(32)) as u8; if crate::envflags::env_flag!("EC_TXGRID_TRACE") { - eprintln!("EC_LFGRID mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}"); + eprintln!( + "EC_LFGRID mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}" + ); } crate::census::tx(tx_px, tx_h_px); let cur = fctx.current_delta_lf.with(|c| c.get()); @@ -8313,7 +8811,9 @@ impl Neighbours { ) { let (mi_r, mi_c) = at_mi; if crate::envflags::env_flag!("EC_TXGRID_TRACE") { - eprintln!("EC_LFLEAF mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}"); + eprintln!( + "EC_LFLEAF mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}" + ); } for rr in 0..h_mi { let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c; @@ -8394,8 +8894,12 @@ impl Neighbours { self.left.iter_mut().for_each(|l| *l = Default::default()); self.left_mode.iter_mut().for_each(|m| *m = DC_PRED); self.left_uv_mode.iter_mut().for_each(|m| *m = DC_PRED); - self.left_side.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE); - self.left_side_mi.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE as u8); + self.left_side + .iter_mut() + .for_each(|s| *s = NO_NEIGHBOUR_SIDE); + self.left_side_mi + .iter_mut() + .for_each(|s| *s = NO_NEIGHBOUR_SIDE as u8); self.left_skip.iter_mut().for_each(|s| *s = false); self.left_skip_mode.iter_mut().for_each(|s| *s = false); self.left_inter.iter_mut().for_each(|i| *i = false); @@ -8406,16 +8910,22 @@ impl Neighbours { self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]); // lane-sub8 r6: mi-granular row maps reset with the rest of the left // context (a tile/SB-row boundary has no left neighbour). - self.sub8_mode_row.iter_mut().for_each(|s| *s = (u16::MAX, 0)); + self.sub8_mode_row + .iter_mut() + .for_each(|s| *s = (u16::MAX, 0)); self.uv_mode_row.iter_mut().for_each(|s| *s = (u16::MAX, 0)); // lane-tiles r11 (COMMON's NEIGHBOUR MAPS rule): the palette side bands // are per-mi maps like every other one here, so they reset with the // row too -- the left guard above is what actually stops a cross-tile // read, this keeps a stale colour out of the arrays at all. self.left_palette_size.iter_mut().for_each(|s| *s = 0); - self.left_palette_colors.iter_mut().for_each(|c| *c = [0u16; 8]); + self.left_palette_colors + .iter_mut() + .for_each(|c| *c = [0u16; 8]); self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0); - self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]); + self.left_palette_uv_colors + .iter_mut() + .for_each(|c| *c = [0u16; 8]); // lane-mergefix r2: `av1_zero_left_context` memsets // `left_txfm_context_buffer` to `tx_size_high[TX_SIZES_LARGEST]` at // every superblock row of every tile -- the var-tx left context does @@ -8662,7 +9172,7 @@ impl Neighbours { o.2 += dc_vote(left[plane].dc); } } - out + out } /// [`Self::around_mi_rect`] for the CHROMA planes of a 4:2:2 frame @@ -8710,12 +9220,28 @@ impl Neighbours { let vote = o.2; let ab: Vec = (0..above_mi) .step_by(2) - .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level)) + .map(|k| { + format!( + "{:?}/{}", + self.above[mi_c + k][plane].dc, + self.above[mi_c + k][plane].level + ) + }) .collect(); let lf: Vec = (0..left_mi) - .map(|k| format!("{:?}/{}", self.left[mi_r + k][plane].dc, self.left[mi_r + k][plane].level)) + .map(|k| { + format!( + "{:?}/{}", + self.left[mi_r + k][plane].dc, + self.left[mi_r + k][plane].level + ) + }) .collect(); - eprintln!("EC_DCDUMP422 mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(",")); + eprintln!( + "EC_DCDUMP422 mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", + ab.join(","), + lf.join(",") + ); } } out @@ -8730,7 +9256,12 @@ impl Neighbours { /// [`Self::around_rect`] taking the block's position directly in 4x4 /// mode-info units, mirroring [`Self::around_mi`]. - fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] { + fn around_mi_rect( + &self, + (mi_r, mi_c): (usize, usize), + w: usize, + h: usize, + ) -> [(bool, bool, i32); 3] { let (w_mi, h_mi) = (w / MI, h / MI); let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c)); let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r)); @@ -8754,12 +9285,28 @@ impl Neighbours { for (plane, o) in out.iter().enumerate() { let vote = o.2; let ab: Vec = (0..above_mi) - .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level)) + .map(|k| { + format!( + "{:?}/{}", + self.above[mi_c + k][plane].dc, + self.above[mi_c + k][plane].level + ) + }) .collect(); let lf: Vec = (0..left_mi) - .map(|k| format!("{:?}/{}", self.left[mi_r + k][plane].dc, self.left[mi_r + k][plane].level)) + .map(|k| { + format!( + "{:?}/{}", + self.left[mi_r + k][plane].dc, + self.left[mi_r + k][plane].level + ) + }) .collect(); - eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(",")); + eprintln!( + "EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", + ab.join(","), + lf.join(",") + ); } } out @@ -8779,12 +9326,7 @@ impl Neighbours { /// [`Self::luma_skip_ctx`] with the unit's own width and height in mi /// units (lane-rectsplitx r1) -- `get_txb_ctx_general` ORs the above /// context over `tx_size_wide` and the left one over `tx_size_high`. - fn luma_skip_ctx_rect( - &self, - (mi_r, mi_c): (usize, usize), - w_mi: usize, - h_mi: usize, - ) -> usize { + fn luma_skip_ctx_rect(&self, (mi_r, mi_c): (usize, usize), w_mi: usize, h_mi: usize) -> usize { let side_mi = w_mi; let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c)); let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r)); @@ -8798,10 +9340,12 @@ impl Neighbours { } let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)]; if crate::envflags::env_flag!("EC_ECDUMP") { - let ab: Vec = - (0..above_mi).map(|k| self.above[mi_c + k][0].level.to_string()).collect(); - let lf: Vec = - (0..left_mi).map(|k| self.left[mi_r + k][0].level.to_string()).collect(); + let ab: Vec = (0..above_mi) + .map(|k| self.above[mi_c + k][0].level.to_string()) + .collect(); + let lf: Vec = (0..left_mi) + .map(|k| self.left[mi_r + k][0].level.to_string()) + .collect(); // lane-av1mix: the last few msac register states, so the // byte-position of the `all_zero` read can be matched against // aomdec's `EC=(value,rng,bytepos)` dump (decodetxb.c) without a @@ -8813,7 +9357,9 @@ impl Neighbours { .join(" "); eprintln!( "EC_ECDUMP plane=0 mi=({mi_r},{mi_c}) wh=({w_mi},{h_mi}) ctx={ctx} above=[{},] left=[{},] recentEC=[{}]", - ab.join(","), lf.join(","), recent + ab.join(","), + lf.join(","), + recent ); } if crate::envflags::env_flag!("EC_AV1_TRACE") { @@ -8856,14 +9402,7 @@ impl Neighbours { /// block to the right reads via `mi(row, col-1)`). Only sub-8x8 leaves /// read these back, and only when the recorded position is exactly their /// own neighbour -- see [`Self::sub8_mode_col`]'s doc. - fn record_mode_mi( - &mut self, - mi_r: usize, - mi_c: usize, - mi_w: usize, - mi_h: usize, - mode: usize, - ) { + fn record_mode_mi(&mut self, mi_r: usize, mi_c: usize, mi_w: usize, mi_h: usize, mode: usize) { let (last_r, last_c) = ((mi_r + mi_h - 1) as u16, (mi_c + mi_w - 1) as u16); let mode = mode as u8; for cell in 0..mi_w { @@ -8884,14 +9423,18 @@ impl Neighbours { /// construction). See [`Self::record_mode_mi`]. fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option { match self.sub8_mode_col.get(mi_c) { - Some(&(row, m)) if mi_r > self.tile_row0_mi && usize::from(row) == mi_r - 1 => Some(usize::from(m)), + Some(&(row, m)) if mi_r > self.tile_row0_mi && usize::from(row) == mi_r - 1 => { + Some(usize::from(m)) + } _ => None, } } fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option { match self.sub8_mode_row.get(mi_r) { - Some(&(col, m)) if mi_c > self.tile_col0_mi && usize::from(col) == mi_c - 1 => Some(usize::from(m)), + Some(&(col, m)) if mi_c > self.tile_col0_mi && usize::from(col) == mi_c - 1 => { + Some(usize::from(m)) + } _ => None, } } @@ -8907,14 +9450,29 @@ impl Neighbours { uv_mode: usize, ) { let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1); - fill_span(&mut self.uv_mode_col, mi_c, mi_w, (last_r as u16, uv_mode as u8)); - fill_span(&mut self.uv_mode_row, mi_r, mi_h, (last_c as u16, uv_mode as u8)); + fill_span( + &mut self.uv_mode_col, + mi_c, + mi_w, + (last_r as u16, uv_mode as u8), + ); + fill_span( + &mut self.uv_mode_row, + mi_r, + mi_h, + (last_c as u16, uv_mode as u8), + ); // libaom writes one `MB_MODE_INFO` pointer into every mi cell a block // covers, so the chroma neighbour read below is a plain grid read. let stride = self.uv_grid_cols; let n = stride.saturating_sub(mi_c).min(last_c + 1 - mi_c); for row in mi_r..=last_r { - fill_span(&mut self.uv_mode_grid, row * stride + mi_c, n, uv_mode as u8); + fill_span( + &mut self.uv_mode_grid, + row * stride + mi_c, + n, + uv_mode as u8, + ); } } @@ -8961,13 +9519,7 @@ impl Neighbours { /// counter wants this: it measures how often the snap CHANGES the answer, /// which is what the lane-kf1200/kf900 chroma-reference fix buys. Every /// decode path uses the snapping form. - fn smooth_uv_neighbour_unsnapped( - &self, - mi_r: usize, - mi_c: usize, - r: usize, - c: usize, - ) -> bool { + fn smooth_uv_neighbour_unsnapped(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool { // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid // array that `start_tile` does not clear, so a block on a tile's first @@ -9152,18 +9704,15 @@ impl Neighbours { /// [`Self::record_mi`] with independent above (`w`)/left (`h`) extents, /// in pixels (lane-partitions r1, mirroring [`Self::record_rect`]). - fn record_mi_rect( - &mut self, - at_mi: (usize, usize), - w: usize, - h: usize, - grids: &[&[i32]; 3], - ) { + fn record_mi_rect(&mut self, at_mi: (usize, usize), w: usize, h: usize, grids: &[&[i32]; 3]) { let (mi_r, mi_c) = at_mi; let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(grids[plane])); let (w_mi, h_mi) = (w / MI, h / MI); if crate::envflags::env_flag!("EC_ECPUB") { - eprintln!("EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", states[0].level); + eprintln!( + "EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", + states[0].level + ); } fill_span(&mut self.left_side_mi, mi_r, h_mi, h as u8); fill_span(&mut self.above_side_mi, mi_c, w_mi, w as u8); @@ -9271,7 +9820,10 @@ impl Neighbours { ) { let state = neighbour_state(grid); if crate::envflags::env_flag!("EC_ECPUB") { - eprintln!("EC_ECPUB tu mi=({mi_r},{mi_c}) wh=({w_px},{h_px}) lvl={}", state.level); + eprintln!( + "EC_ECPUB tu mi=({mi_r},{mi_c}) wh=({w_px},{h_px}) lvl={}", + state.level + ); } for cell in 0..h_px / MI { if mi_r + cell < self.mi_rows { @@ -9509,7 +10061,11 @@ struct PaletteUv { /// `get_unsigned_bits`, which is the same formula): smallest `n` with /// `2^n >= x`, `0` for `x <= 1`. pub(crate) fn ceil_log2(x: u32) -> u32 { - if x < 2 { 0 } else { 32 - (x - 1).leading_zeros() } + if x < 2 { + 0 + } else { + 32 - (x - 1).leading_zeros() + } } /// `av1_read_uniform` (decoder.h:425): a uniform `0..n` value coded as @@ -9560,7 +10116,12 @@ fn merge_colors(transmitted: &[u16], cached: &[u16]) -> Vec { /// (one flag bit each, in cache order), then delta-codes the remainder /// (first value raw, each following delta `>= 1` off a shrinking bit width), /// and merges the two ascending lists back together. -fn read_palette_colors_y(dec: &mut SymbolDecoder, n: usize, cache: &[u16], fctx: &crate::decode::FrameCtx) -> [u16; 8] { +fn read_palette_colors_y( + dec: &mut SymbolDecoder, + n: usize, + cache: &[u16], + fctx: &crate::decode::FrameCtx, +) -> [u16; 8] { let mut cached = Vec::with_capacity(n); for &c in cache { if cached.len() >= n { @@ -9607,7 +10168,12 @@ fn read_palette_colors_y(dec: &mut SymbolDecoder, n: usize, cache: &[u16], fctx: /// side by side). V never uses a cache: a leading bit picks either `n` raw /// literals, or a first raw value plus `n-1` signed deltas that wrap mod 256 /// rather than clamp. -fn read_palette_colors_uv(dec: &mut SymbolDecoder, n: usize, cache: &[u16], fctx: &crate::decode::FrameCtx) -> ([u16; 8], [u16; 8]) { +fn read_palette_colors_uv( + dec: &mut SymbolDecoder, + n: usize, + cache: &[u16], + fctx: &crate::decode::FrameCtx, +) -> ([u16; 8], [u16; 8]) { let mut cached = Vec::with_capacity(n); for &c in cache { if cached.len() >= n { @@ -9689,13 +10255,21 @@ pub(crate) fn palette_color_index_context( col: usize, n: usize, ) -> (usize, [u8; 8]) { - let left = if col >= 1 { Some(map[row * side + col - 1]) } else { None }; + let left = if col >= 1 { + Some(map[row * side + col - 1]) + } else { + None + }; let up_left = if col >= 1 && row >= 1 { Some(map[(row - 1) * side + col - 1]) } else { None }; - let up = if row >= 1 { Some(map[(row - 1) * side + col]) } else { None }; + let up = if row >= 1 { + Some(map[(row - 1) * side + col]) + } else { + None + }; let mut scores = [0i32; 8]; for (neighbour, weight) in [(left, 2), (up_left, 1), (up, 2)] { if let Some(v) = neighbour { @@ -9847,7 +10421,10 @@ fn decode_color_index_map_wh( } else { &cdfs.palette_y_color_index[n - 2][ctx] }; - eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} cdf0={} cnt={} rng={rng}", row_cdf[0], row_cdf[n]); + eprintln!( + "EC_PAL row={row} col={col} ctx={ctx} n={n} cdf0={} cnt={} rng={rng}", + row_cdf[0], row_cdf[n] + ); } let symbol = if uv { dec.symbol(&mut cdfs.palette_uv_color_index[n - 2][ctx][..=n]) @@ -9914,7 +10491,8 @@ fn read_intra_mode_rect( palette: Option<(usize, &[u16])>, palette_uv_cache: &[u16], mi_r: usize, - mi_c: usize, fctx: &crate::decode::FrameCtx, + mi_c: usize, + fctx: &crate::decode::FrameCtx, ) -> Result<( bool, usize, @@ -9946,7 +10524,12 @@ fn read_intra_mode_rect( // (decodemv.c:818), printed at the same point: before the first // mode-info symbol of the block, so a cross-decoder range ladder can // be keyed on the BLOCK, not just on the symbol sequence. - eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=rect bw={bw} bh={bh} efi={} cls={:?} rng={}", enable_filter_intra as i32, filter_intra_size_class_rect(bw, bh), dec.debug_state().0); + eprintln!( + "EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=rect bw={bw} bh={bh} efi={} cls={:?} rng={}", + enable_filter_intra as i32, + filter_intra_size_class_rect(bw, bh), + dec.debug_state().0 + ); } macro_rules! istep { ($name:literal, $val:expr) => { @@ -9977,60 +10560,60 @@ fn read_intra_mode_rect( let skip = if let Some((_, skip)) = inter { skip } else { - // Same `intra_segment_id` placement as the square reader above. - let (seg_w_mi, seg_h_mi) = (bw / 4, bh / 4); - if seg_id_pre_skip(fctx) { - intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, false, fctx); - } - let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; - istep!("skip", skip as i32); - if !seg_id_pre_skip(fctx) { - intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, skip, fctx); - } - maybe_read_cdef_idx(dec, mi_r, mi_c, (bw / MI, bh / MI), skip, fctx); - istep!("cdef", 0); - // A HORZ/VERT rect strip is never the whole superblock (`bw`/`bh` never - // both 64 here -- see this fn's own doc), so `is_whole_sb` is always - // `false`. - maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip, fctx); - maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip, fctx); - istep!("dq", 0); - // `read_intrabc_info` (spec 5.11.13, libaom `decodemv.c:892`, right after - // `skip`/`segment_id`/`cdef`/`delta_q` and before `mbmi->mode`): the - // `use_intrabc` symbol is read for EVERY intra block of an `allow_intrabc` - // frame -- `av1_allow_intrabc` is a frame-level test with no shape term, so - // rect strips read it exactly like square leaves ([`read_intra_mode`], - // [`read_intra_mode_sub8`]). Missing it here desynced the arithmetic - // decoder at the FIRST symbol of the first rect block of every - // `--tune-content=screen` key frame. Reconstruction of a real intrabc - // block at this shape is out of scope, so the flag is consumed and - // refused by name when it fires. - if allow_intrabc_frame(fctx) { - let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0; - hit!(RECT_INTRABC_READS); - istep!("intrabc", use_intrabc as i32); - if use_intrabc { - hit!(INTRABC_HITS); - // libaom `read_intrabc_info`: the DV read, then an immediate - // return out of the mode-info read -- no `y_mode`, no `uv_mode`, - // no angle deltas, no palette, no filter intra. The caller owns - // the reconstruction at its own shape. - let dv = read_intrabc_dv(dec, cdfs, mi_r, mi_c, (bw / MI, bh / MI), fctx); - return Ok(( - skip, - DC_PRED, - 0, - DC_PRED, - 0, - None, - None, - None, - None, - Some(dv), - )); + // Same `intra_segment_id` placement as the square reader above. + let (seg_w_mi, seg_h_mi) = (bw / 4, bh / 4); + if seg_id_pre_skip(fctx) { + intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, false, fctx); + } + let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; + istep!("skip", skip as i32); + if !seg_id_pre_skip(fctx) { + intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, skip, fctx); + } + maybe_read_cdef_idx(dec, mi_r, mi_c, (bw / MI, bh / MI), skip, fctx); + istep!("cdef", 0); + // A HORZ/VERT rect strip is never the whole superblock (`bw`/`bh` never + // both 64 here -- see this fn's own doc), so `is_whole_sb` is always + // `false`. + maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip, fctx); + maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip, fctx); + istep!("dq", 0); + // `read_intrabc_info` (spec 5.11.13, libaom `decodemv.c:892`, right after + // `skip`/`segment_id`/`cdef`/`delta_q` and before `mbmi->mode`): the + // `use_intrabc` symbol is read for EVERY intra block of an `allow_intrabc` + // frame -- `av1_allow_intrabc` is a frame-level test with no shape term, so + // rect strips read it exactly like square leaves ([`read_intra_mode`], + // [`read_intra_mode_sub8`]). Missing it here desynced the arithmetic + // decoder at the FIRST symbol of the first rect block of every + // `--tune-content=screen` key frame. Reconstruction of a real intrabc + // block at this shape is out of scope, so the flag is consumed and + // refused by name when it fires. + if allow_intrabc_frame(fctx) { + let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0; + hit!(RECT_INTRABC_READS); + istep!("intrabc", use_intrabc as i32); + if use_intrabc { + hit!(INTRABC_HITS); + // libaom `read_intrabc_info`: the DV read, then an immediate + // return out of the mode-info read -- no `y_mode`, no `uv_mode`, + // no angle deltas, no palette, no filter intra. The caller owns + // the reconstruction at its own shape. + let dv = read_intrabc_dv(dec, cdfs, mi_r, mi_c, (bw / MI, bh / MI), fctx); + return Ok(( + skip, + DC_PRED, + 0, + DC_PRED, + 0, + None, + None, + None, + None, + Some(dv), + )); + } } - } - skip + skip }; // libaom `read_intra_block_mode_info` (decodemv.c:1189) vs the key // frame's `read_intra_frame_mode_info` (decodemv.c:1065 `read_intra_mode` @@ -10092,9 +10675,7 @@ fn read_intra_mode_rect( // runs from the caller, after the whole mode-info read). let mut palette_y_pending: Option<(usize, [u16; 8])> = None; let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None; - if allow_screen_content_tools - && let Some(bsize_ctx) = palette_bsize_ctx_wh(bw, bh) - { + if allow_screen_content_tools && let Some(bsize_ctx) = palette_bsize_ctx_wh(bw, bh) { // r6: this is the exact site the removed blanket refusal used to // guard -- reached for EVERY rect strip in a screen-content frame, // independent of whether the block ends up using a palette. @@ -10150,11 +10731,22 @@ fn read_intra_mode_rect( // `av1_visit_palette`: plane 0 (Y) then plane 1 (chroma, shared U/V map), // same order as [`read_intra_mode`]'s own square path. let palette_y = palette_y_pending.map(|(n, colors)| { - let map = - decode_color_index_map_wh(dec, cdfs, n, bw, bh, palette_onscreen(mi_r, mi_c, bw, bh, fctx), false); + let map = decode_color_index_map_wh( + dec, + cdfs, + n, + bw, + bh, + palette_onscreen(mi_r, mi_c, bw, bh, fctx), + false, + ); hit!(PALETTE_HITS); hit!(PALETTE_RECT_HITS); - PaletteY { size: n, colors, map } + PaletteY { + size: n, + colors, + map, + } }); let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { // `av1_get_plane_block_size(bsize, 1, 1)` (`ss_size_lookup`), NOT a @@ -10163,10 +10755,20 @@ fn read_intra_mode_rect( // axis to 2 read HALF the colour-index symbols of a 1:4 strip's // chroma palette and desynced the tile from there. let (cw, ch) = ((bw >> ss_x(fctx)).max(4), (bh >> ss_y(fctx)).max(4)); - let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch), (ss_x(fctx), ss_y(fctx))); + let on = palette_onscreen_uv( + (bw, bh), + palette_onscreen(mi_r, mi_c, bw, bh, fctx), + (cw, ch), + (ss_x(fctx), ss_y(fctx)), + ); let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true); hit!(PALETTE_UV_HITS); - PaletteUv { size: n, u_colors, v_colors, map } + PaletteUv { + size: n, + u_colors, + v_colors, + map, + } }); Ok(( skip, @@ -10246,7 +10848,9 @@ fn record_strip_palette( /// [`cfl_ac_q3`] for a true `bw`x`bh` rect strip (lane-intradisp r1). fn cfl_ac_q3_rect(y: &PlaneBuf<'_>, px: usize, py: usize, bw: usize, bh: usize) -> Vec { - cfl_ac_q3_at(px, py, bw, bh, |lx, ly| i32::from(y.data[ly * y.width + lx])) + cfl_ac_q3_at(px, py, bw, bh, |lx, ly| { + i32::from(y.data[ly * y.width + lx]) + }) } /// Everything a rect strip already read out of the stream before its luma @@ -10375,7 +10979,8 @@ fn decode_rect_split( u: &mut PlaneBuf<'static>, v: &mut PlaneBuf<'static>, base_q_idx: u8, - reduced_tx_set: bool, fctx: &crate::decode::FrameCtx, + reduced_tx_set: bool, + fctx: &crate::decode::FrameCtx, ) -> Result<()> { let (mi_r, mi_c) = at_mi; let (px, py) = (mi_c * MI, mi_r * MI); @@ -10409,8 +11014,8 @@ fn decode_rect_split( // needs. let chroma422_pair = chroma422_pair_plane(ss_x(fctx) == 1, ss_y(fctx) == 0, mi_c, bw, bh); let chroma_422_pair_wide = chroma422_pair.is_some(); - let (chroma_block_w, chroma_block_h, chroma_x) = chroma422_pair - .map_or((chroma_w, chroma_h, cpx), |(w, h, x, _)| (w, h, x)); + let (chroma_block_w, chroma_block_h, chroma_x) = + chroma422_pair.map_or((chroma_w, chroma_h, cpx), |(w, h, x, _)| (w, h, x)); // The chroma transform is picked before any symbol is read, so an // unsupported chroma shape refuses before this strip desyncs the tile. let chroma: Option<(TxbSet, &[u16])> = match (chroma_w, chroma_h) { @@ -10506,7 +11111,11 @@ fn decode_rect_split( } else { TxbSet::LumaRect16x8Set1 }, - if tx_w == 16 { &SCAN_16X8[..] } else { &SCAN_8X16[..] }, + if tx_w == 16 { + &SCAN_16X8[..] + } else { + &SCAN_8X16[..] + }, )), (32, 16) => Some((TxbSet::LumaRect32x16, &SCAN_32X16[..])), (16, 32) => Some((TxbSet::LumaRect32x16, &SCAN_16X32[..])), @@ -10532,7 +11141,7 @@ fn decode_rect_split( return Err(unsupported(format!( "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma \ coefficient tables for that shape here)" - ))) + ))); } }; // The `None` above that is NOT the square arm. @@ -10592,7 +11201,8 @@ fn decode_rect_split( set_palette_pred(tu_buf, fctx); } if m.skip { - push_intra_rect(0, + push_intra_rect( + 0, tu_px, tu_py, tx_w, @@ -10603,7 +11213,8 @@ fn decode_rect_split( &zero_tu, None, m.filter_intra, - m.smooth_neighbor, fctx, + m.smooth_neighbor, + fctx, ); neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &zero_tu); } else if luma_64corner && luma_rect.is_none() { @@ -10651,9 +11262,10 @@ fn decode_rect_split( plane_q_delta(0, fctx).0, plane_q_delta(0, fctx).1, tu_tx_type, - block_iqmatrix(fctx, 0, tx_w, tx_h, tu_tx_type), + block_iqmatrix(fctx, 0, tx_w, tx_h, tu_tx_type), ); - push_intra_rect(0, + push_intra_rect( + 0, tu_px, tu_py, tx_w, @@ -10664,7 +11276,8 @@ fn decode_rect_split( &residual, None, m.filter_intra, - m.smooth_neighbor, fctx, + m.smooth_neighbor, + fctx, ); neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &tu_grid); } else if let Some((rect_set, rect_scan)) = luma_rect { @@ -10708,9 +11321,10 @@ fn decode_rect_split( plane_q_delta(0, fctx).0, plane_q_delta(0, fctx).1, tu_tx_type, - block_iqmatrix(fctx, 0, tx_w, tx_h, tu_tx_type), + block_iqmatrix(fctx, 0, tx_w, tx_h, tu_tx_type), ); - push_intra_rect(0, + push_intra_rect( + 0, tu_px, tu_py, tx_w, @@ -10721,7 +11335,8 @@ fn decode_rect_split( &residual, None, m.filter_intra, - m.smooth_neighbor, fctx, + m.smooth_neighbor, + fctx, ); neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &tu_grid); } else { @@ -10750,7 +11365,8 @@ fn decode_rect_split( None, m.filter_intra, Some(tu_skip_ctx), - m.smooth_neighbor, fctx, + m.smooth_neighbor, + fctx, )?; neighbours.record_mi_luma(tu_mi, tx_w, &tu_grid); } @@ -10829,14 +11445,12 @@ fn decode_rect_split( m.angle_delta_uv, reach, &ZERO_RESIDUAL[..uw * uh], - m.alpha.zip(ac.clone()).map(|((au, av), ac)| { - ( - if plane_idx == 1 { au } else { av }, - ac, - ) - }), + m.alpha + .zip(ac.clone()) + .map(|((au, av), ac)| (if plane_idx == 1 { au } else { av }, ac)), None, - m.smooth_neighbor_uv, fctx, + m.smooth_neighbor_uv, + fctx, ); } } @@ -10845,16 +11459,38 @@ fn decode_rect_split( if let Some((ub, _)) = &m.palette_uv { set_palette_pred(ub.clone(), fctx); } - push_intra_rect(1, - cpx, cpy, chroma_w, chroma_h, m.uv_predict_mode, m.angle_delta_uv, reach, &zero, - m.alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, m.smooth_neighbor_uv, fctx, + push_intra_rect( + 1, + cpx, + cpy, + chroma_w, + chroma_h, + m.uv_predict_mode, + m.angle_delta_uv, + reach, + &zero, + m.alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + m.smooth_neighbor_uv, + fctx, ); if let Some((_, vb)) = &m.palette_uv { set_palette_pred(vb.clone(), fctx); } - push_intra_rect(2, - cpx, cpy, chroma_w, chroma_h, m.uv_predict_mode, m.angle_delta_uv, reach, &zero, - m.alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, m.smooth_neighbor_uv, fctx, + push_intra_rect( + 2, + cpx, + cpy, + chroma_w, + chroma_h, + m.uv_predict_mode, + m.angle_delta_uv, + reach, + &zero, + m.alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + m.smooth_neighbor_uv, + fctx, ); } (zero.clone(), zero) @@ -10885,15 +11521,20 @@ fn decode_rect_split( for plane_idx in 1..=2 { for cu_row in 0..ch_n { for cu_col in 0..cw_n { - let cu_mi = ( - mi_r + cu_row * (span_y / MI), - mi_c + cu_col * (span_x / MI), - ); + let cu_mi = (mi_r + cu_row * (span_y / MI), mi_c + cu_col * (span_x / MI)); let cu_around = neighbours.around_mi_rect(cu_mi, span_x, span_y); let cu_reach = tu_reach( - bw, bh, - cu_col * span_x, cu_row * span_y, span_x, - block_reach, px, py, y.width, y.height, fctx, + bw, + bh, + cu_col * span_x, + cu_row * span_y, + span_x, + block_reach, + px, + py, + y.width, + y.height, + fctx, ); let (cu_x, cu_y) = (cpx + cu_col * 4, cpy + cu_row * 4); if let Some((ub, vb)) = &m.palette_uv { @@ -10905,14 +11546,29 @@ fn decode_rect_split( } let plane = if plane_idx == 1 { &mut *u } else { &mut *v }; let grid = read_plane( - dec, cdfs, TxbSet::Chroma4, &scan4, plane_idx, - cu_around[plane_idx], m.mode, m.uv_predict_mode, - m.angle_delta_uv, cu_reach, plane, cu_x, cu_y, 4, 4, + dec, + cdfs, + TxbSet::Chroma4, + &scan4, + plane_idx, + cu_around[plane_idx], + m.mode, + m.uv_predict_mode, + m.angle_delta_uv, + cu_reach, + plane, + cu_x, + cu_y, + 4, + 4, base_q_idx, - m.alpha.zip(ac).map(|((au, av), ac)| { - (if plane_idx == 1 { au } else { av }, ac) - }), - None, offset, m.smooth_neighbor_uv, fctx, + m.alpha + .zip(ac) + .map(|((au, av), ac)| (if plane_idx == 1 { au } else { av }, ac)), + None, + offset, + m.smooth_neighbor_uv, + fctx, )?; if span_x == 4 && span_y == 4 { hit!(RECT_SPLIT_LOSSLESS_CHROMA444_HITS); @@ -10928,24 +11584,24 @@ fn decode_rect_split( } else if chroma_tiled { let (uw, uh, set, scan): (usize, usize, TxbSet, &[u16]) = if chroma_422_pair_wide || chroma_422_oob { - // lane-av1-422blockhalf / lane-av1-422stripanchor: the - // BLOCK_INVALID-plane chroma's (4, 8) units -- the Release - // oracle's out-of-bounds `max_txsize_rect_lookup` byte (TX_4X8, - // see above). For the 4-wide strip the units tile the PAIR's - // plane, stepping from the floored anchor. - (4, 8, TxbSet::ChromaRect8x4, &SCAN_4X8) - } else { - match (chroma_w, chroma_h) { - (64, 32) | (32, 64) | (32, 32) => (32, 32, TxbSet::Chroma32, default_scan(32)), - (64, 16) => (32, 16, TxbSet::ChromaRect32x16, &SCAN_32X16), - (16, 64) => (16, 32, TxbSet::ChromaRect32x16, &SCAN_16X32), - // lane-av1-422: the 4:2:2 square chroma planes (height unhalved), - // through the square reader like every other square chroma unit. - (16, 16) => (16, 16, TxbSet::Chroma16, default_scan(16)), - (8, 8) => (8, 8, TxbSet::Chroma8, default_scan(8)), - _ => unreachable!("chroma_tiled"), - } - }; + // lane-av1-422blockhalf / lane-av1-422stripanchor: the + // BLOCK_INVALID-plane chroma's (4, 8) units -- the Release + // oracle's out-of-bounds `max_txsize_rect_lookup` byte (TX_4X8, + // see above). For the 4-wide strip the units tile the PAIR's + // plane, stepping from the floored anchor. + (4, 8, TxbSet::ChromaRect8x4, &SCAN_4X8) + } else { + match (chroma_w, chroma_h) { + (64, 32) | (32, 64) | (32, 32) => (32, 32, TxbSet::Chroma32, default_scan(32)), + (64, 16) => (32, 16, TxbSet::ChromaRect32x16, &SCAN_32X16), + (16, 64) => (16, 32, TxbSet::ChromaRect32x16, &SCAN_16X32), + // lane-av1-422: the 4:2:2 square chroma planes (height unhalved), + // through the square reader like every other square chroma unit. + (16, 16) => (16, 16, TxbSet::Chroma16, default_scan(16)), + (8, 8) => (8, 8, TxbSet::Chroma8, default_scan(8)), + _ => unreachable!("chroma_tiled"), + } + }; // lane-av1-422: the witness counter, keyed to ss (1,0) so only a 4:2:2 // frame's square chroma units count it. if uw == uh && ss_x(fctx) == 1 && ss_y(fctx) == 0 { @@ -10977,8 +11633,11 @@ fn decode_rect_split( let luma_span_y = uh << ss_y(fctx); let cu_mi = ( mi_r + cu_row * (luma_span_y / MI), - if chroma_422_pair_wide { mi_c & !1 } else { mi_c } - + cu_col * (luma_span_x / MI), + if chroma_422_pair_wide { + mi_c & !1 + } else { + mi_c + } + cu_col * (luma_span_x / MI), ); // lane-av1-422blockhalf: the 4:2:2 (4, 8) units read their // chroma context per chroma cell @@ -10993,9 +11652,7 @@ fn decode_rect_split( // ctx row high (t422 frame 1). Route every ss (1,0) // unit through the every-second-above-cell sampling; // 4:2:0/4:4:4 keep the plain walk verbatim. - let cu_around = if chroma_422_oob - || (ss_x(fctx) == 1 && ss_y(fctx) == 0) - { + let cu_around = if chroma_422_oob || (ss_x(fctx) == 1 && ss_y(fctx) == 0) { neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y) } else { neighbours.around_mi_rect(cu_mi, luma_span_x, luma_span_y) @@ -11034,14 +11691,7 @@ fn decode_rect_split( if let Some((ub, vb)) = &m.palette_uv { let buf = if plane_idx == 1 { ub } else { vb }; set_palette_pred( - palette_window( - buf, - chroma_block_w, - cu_col * uw, - cu_row * uh, - uw, - uh, - ), + palette_window(buf, chroma_block_w, cu_col * uw, cu_row * uh, uw, uh), fctx, ); } @@ -11050,10 +11700,27 @@ fn decode_rect_split( let levels = if uw == uh { let plane = if plane_idx == 1 { &mut *u } else { &mut *v }; read_plane( - dec, cdfs, set, scan, plane_idx, cu_around[plane_idx], - m.mode, m.uv_predict_mode, m.angle_delta_uv, reach, - plane, cu_x, cu_y, uw, uw, base_q_idx, cfl, None, - bigger.then_some(3), m.smooth_neighbor_uv, fctx, + dec, + cdfs, + set, + scan, + plane_idx, + cu_around[plane_idx], + m.mode, + m.uv_predict_mode, + m.angle_delta_uv, + reach, + plane, + cu_x, + cu_y, + uw, + uw, + base_q_idx, + cfl, + None, + bigger.then_some(3), + m.smooth_neighbor_uv, + fctx, )? } else { let skip_ctx = usize::from(cu_around[plane_idx].0) @@ -11061,25 +11728,50 @@ fn decode_rect_split( + usize::from(bigger) * 3; let mut coding = cdfs.txb(set, m.uv_predict_mode); let (levels, tx_type) = read_coeffs_rect( - dec, &mut coding, scan, uw, uh, skip_ctx, - dc_sign_ctx(cu_around[plane_idx].2), default_tx, + dec, + &mut coding, + scan, + uw, + uh, + skip_ctx, + dc_sign_ctx(cu_around[plane_idx].2), + default_tx, )?; let residual = dequant_and_inverse_typed_wh( - &levels, uw, uh, crate::decode::bit_depth(fctx), + &levels, + uw, + uh, + crate::decode::bit_depth(fctx), block_q_idx(fctx), plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1, tx_type, - block_iqmatrix(fctx, plane_idx, uw, uh, tx_type), + block_iqmatrix(fctx, plane_idx, uw, uh, tx_type), ); push_intra_rect( - plane_idx, cu_x, cu_y, uw, uh, - m.uv_predict_mode, m.angle_delta_uv, reach, &residual, - cfl, None, m.smooth_neighbor_uv, fctx, + plane_idx, + cu_x, + cu_y, + uw, + uh, + m.uv_predict_mode, + m.angle_delta_uv, + reach, + &residual, + cfl, + None, + m.smooth_neighbor_uv, + fctx, ); levels }; - neighbours.record_mi_chroma(cu_mi, luma_span_x, luma_span_y, plane_idx, &levels); + neighbours.record_mi_chroma( + cu_mi, + luma_span_x, + luma_span_y, + plane_idx, + &levels, + ); tiled_chroma_units.push(( cu_mi, plane_idx, @@ -11117,8 +11809,7 @@ fn decode_rect_split( } let mut grids: Vec = Vec::with_capacity(2); for plane_idx in 1..=2 { - let skip_ctx = - usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1); + let skip_ctx = usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1); let mut coding = cdfs.txb(chroma_set, m.uv_predict_mode); let (levels, tx_type) = read_coeffs_rect( dec, @@ -11151,7 +11842,7 @@ fn decode_rect_split( plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1, tx_type, - block_iqmatrix(fctx, plane_idx, chroma_w, chroma_h, tx_type), + block_iqmatrix(fctx, plane_idx, chroma_w, chroma_h, tx_type), ); let cfl = m .alpha @@ -11162,7 +11853,8 @@ fn decode_rect_split( let buf = if plane_idx == 1 { ub } else { vb }; set_palette_pred(buf.clone(), fctx); } - push_intra_rect(plane_idx, + push_intra_rect( + plane_idx, cpx, cpy, chroma_w, @@ -11173,7 +11865,8 @@ fn decode_rect_split( &residual, cfl, None, - m.smooth_neighbor_uv, fctx, + m.smooth_neighbor_uv, + fctx, ); grids.push(levels); } @@ -11195,7 +11888,15 @@ fn decode_rect_split( neighbours.record_mi_chroma(*cu_mi, *span_w, *span_h, *plane, unit); } neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, m.skip); - neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0, fctx); + neighbours.fill_lf_grid_rect( + (mi_r, mi_c), + bw / MI, + bh / MI, + tx_w as u8, + tx_h as u8, + 0, + fctx, + ); if crate::envflags::env_flag!("EC_AV1_TRACE") { let (rng, _) = dec.debug_state(); eprintln!( @@ -11456,13 +12157,24 @@ fn chroma422_pair_plane_matches_the_ss_size_lookup_cells() { Some((_, _, x, c)) => (x, c), None => panic!("{bw}x{bh} lost its pair arm at an even mi_col"), }; - assert_eq!((x_even, col_even), (12, 6), "even column keeps its own cell"); + assert_eq!( + (x_even, col_even), + (12, 6), + "even column keeps its own cell" + ); } } // The tall/wide BLOCK_INVALID shapes (8 px wide or more) are the // `chroma_422_oob` tiling's residents, not the pair arm's: both are // 4:2:2-only, so the two arms partition the BLOCK_INVALID column. - for (bw, bh) in [(8usize, 16), (16, 32), (32, 64), (64, 128), (8, 32), (16, 64)] { + for (bw, bh) in [ + (8usize, 16), + (16, 32), + (32, 64), + (64, 128), + (8, 32), + (16, 64), + ] { assert!(chroma422_pair_plane(true, false, 7, bw, bh).is_none()); } } @@ -11482,7 +12194,8 @@ fn decode_intra_rect_in_inter( y: &mut PlaneBuf<'static>, u: &mut PlaneBuf<'static>, v: &mut PlaneBuf<'static>, - base_q_idx: u8, fctx: &crate::decode::FrameCtx, + base_q_idx: u8, + fctx: &crate::decode::FrameCtx, ) -> Result<()> { // `at` is in MI units (the inter path's own unit since lane-inter4); // `(r, c)` is the enclosing SUB cell the SUB-granular neighbour bands @@ -11533,7 +12246,8 @@ fn decode_intra_rect_in_inter( allow_screen_content_tools, base_q_idx, fctx.tx_select_inter.with(std::cell::Cell::get), - fctx.reduced_tx_set_inter.with(std::cell::Cell::get), fctx, + fctx.reduced_tx_set_inter.with(std::cell::Cell::get), + fctx, ); fctx.intra_in_inter_mode.with(|c| c.set(None)); let (mode, uv, (tx_w, tx_h)) = res?; @@ -11643,7 +12357,8 @@ fn decode_intra_rect_in_inter( fctx.enable_filter_intra_inter.with(std::cell::Cell::get), allow_screen_content_tools, fctx.tx_select_inter.with(std::cell::Cell::get), - fctx.reduced_tx_set_inter.with(std::cell::Cell::get), fctx, + fctx.reduced_tx_set_inter.with(std::cell::Cell::get), + fctx, ); fctx.intra_in_inter_mode.with(|c| c.set(None)); return res; @@ -11685,7 +12400,8 @@ fn decode_intra_rect_in_inter( // `decode_block_rect64`), asserted here so a future shape cannot drift. if bw.max(bh) == 4 * bw.min(bh) { debug_assert_eq!(tx_cat, if bw.max(bh) == 64 { 3 } else { 2 }); - fctx.intra_in_inter_mode.with(|c| c.set(Some((size_group, skip)))); + fctx.intra_in_inter_mode + .with(|c| c.set(Some((size_group, skip)))); let res = if bw.max(bh) == 64 { decode_block_rect64( dec, @@ -11701,7 +12417,8 @@ fn decode_intra_rect_in_inter( allow_screen_content_tools, base_q_idx, fctx.tx_select_inter.with(std::cell::Cell::get), - fctx.reduced_tx_set_inter.with(std::cell::Cell::get), fctx, + fctx.reduced_tx_set_inter.with(std::cell::Cell::get), + fctx, ) } else { decode_block_rect4( @@ -11718,7 +12435,8 @@ fn decode_intra_rect_in_inter( fctx.enable_filter_intra_inter.with(std::cell::Cell::get), allow_screen_content_tools, base_q_idx, - fctx.tx_select_inter.with(std::cell::Cell::get), fctx, + fctx.tx_select_inter.with(std::cell::Cell::get), + fctx, ) .map(|_| ()) }; @@ -11825,9 +12543,7 @@ fn decode_intra_rect_in_inter( let palette_uv_cache = neighbours.palette_uv_cache_mi((mi_r, mi_c)); let mut palette_y_pending: Option<(usize, [u16; 8])> = None; let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None; - if allow_screen_content_tools - && let Some(bsize_ctx) = palette_bsize_ctx_wh(bw, bh) - { + if allow_screen_content_tools && let Some(bsize_ctx) = palette_bsize_ctx_wh(bw, bh) { hit!(INTRA_RECT_IN_INTER_SCREEN_HITS); let use_palette_y = mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][palette_ctx]) != 0; @@ -11843,7 +12559,12 @@ fn decode_intra_rect_in_inter( && uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[usize::from(use_palette_y)]) != 0; if crate::envflags::env_flag!("EC_PALSYN") { - eprintln!("EC_PALSYN rect mi={mi_r},{mi_c} bw={bw} bh={bh} mode={mode} uv={uv_mode} ctx={palette_ctx} y={} uv={} rng={}", use_palette_y as i32, use_palette_uv as i32, dec.debug_state().0); + eprintln!( + "EC_PALSYN rect mi={mi_r},{mi_c} bw={bw} bh={bh} mode={mode} uv={uv_mode} ctx={palette_ctx} y={} uv={} rng={}", + use_palette_y as i32, + use_palette_uv as i32, + dec.debug_state().0 + ); } if use_palette_uv { let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]); @@ -11871,20 +12592,41 @@ fn decode_intra_rect_in_inter( } // `av1_visit_palette`: Y's colour-index map then the shared chroma one. let palette_y = palette_y_pending.map(|(n, colors)| { - let map = - decode_color_index_map_wh(dec, cdfs, n, bw, bh, palette_onscreen(mi_r, mi_c, bw, bh, fctx), false); + let map = decode_color_index_map_wh( + dec, + cdfs, + n, + bw, + bh, + palette_onscreen(mi_r, mi_c, bw, bh, fctx), + false, + ); hit!(PALETTE_HITS); hit!(PALETTE_RECT_HITS); hit!(INTRA_IN_INTER_PALETTE_Y_HITS); - PaletteY { size: n, colors, map } + PaletteY { + size: n, + colors, + map, + } }); let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { let (cw, ch) = ((bw >> ss_x(fctx)).max(4), (bh >> ss_y(fctx)).max(4)); - let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch), (ss_x(fctx), ss_y(fctx))); + let on = palette_onscreen_uv( + (bw, bh), + palette_onscreen(mi_r, mi_c, bw, bh, fctx), + (cw, ch), + (ss_x(fctx), ss_y(fctx)), + ); let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true); hit!(PALETTE_UV_HITS); hit!(INTRA_IN_INTER_PALETTE_UV_HITS); - PaletteUv { size: n, u_colors, v_colors, map } + PaletteUv { + size: n, + u_colors, + v_colors, + map, + } }); // The intra-edge filter type is the NEIGHBOUR's mode (libaom // `get_filt_type`), luma's off the luma neighbours and chroma's off the @@ -11991,7 +12733,8 @@ fn decode_intra_rect_in_inter( u, v, base_q_idx, - fctx.reduced_tx_set_inter.with(std::cell::Cell::get), fctx, + fctx.reduced_tx_set_inter.with(std::cell::Cell::get), + fctx, )?; // `set_txfm_ctxs` (libaom `decodeframe.c:1078`, at the end of // `decode_token_recon_block`): an INTRA block records its TRANSFORM size in @@ -12115,7 +12858,8 @@ fn decode_intrabc_rect( (mi_r, mi_c), (bw, bh), (mi_cols, mi_rows), - skip, fctx, + skip, + fctx, )?; if leaves.is_some() { hit!(INTRABC_RECT_VARTX_HITS); @@ -12129,9 +12873,17 @@ fn decode_intrabc_rect( // path takes for its own square prediction buffer. let mut pred_y_dense = vec![0u16; bw * bh]; mc::predict_with_filter( - &y.data, y.width, y.true_width, y.true_height, - mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0), - bw, bh, mc::InterpFilterKind::Bilinear, &mut pred_y_dense, fctx, + &y.data, + y.width, + y.true_width, + y.true_height, + mv_to_q4(px, dv_col, 0), + mv_to_q4(py, dv_row, 0), + bw, + bh, + mc::InterpFilterKind::Bilinear, + &mut pred_y_dense, + fctx, ); let mut pred_y = vec![0u16; side * side]; for row in 0..bh { @@ -12139,9 +12891,17 @@ fn decode_intrabc_rect( } let mut pred_u_dense = vec![0u16; cw * ch]; mc::predict_with_filter( - &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), - cw, ch, mc::InterpFilterKind::Bilinear, &mut pred_u_dense, fctx, + &u.data, + u.width, + u.true_width, + u.true_height, + mv_to_q4(cpx, dv_col, ss_x(fctx)), + mv_to_q4(cpy, dv_row, ss_y(fctx)), + cw, + ch, + mc::InterpFilterKind::Bilinear, + &mut pred_u_dense, + fctx, ); let mut pred_u = vec![0u16; cside * cside]; for row in 0..ch { @@ -12149,9 +12909,17 @@ fn decode_intrabc_rect( } let mut pred_v_dense = vec![0u16; cw * ch]; mc::predict_with_filter( - &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), - cw, ch, mc::InterpFilterKind::Bilinear, &mut pred_v_dense, fctx, + &v.data, + v.width, + v.true_width, + v.true_height, + mv_to_q4(cpx, dv_col, ss_x(fctx)), + mv_to_q4(cpy, dv_row, ss_y(fctx)), + cw, + ch, + mc::InterpFilterKind::Bilinear, + &mut pred_v_dense, + fctx, ); let mut pred_v = vec![0u16; cside * cside]; for row in 0..ch { @@ -12165,9 +12933,39 @@ fn decode_intrabc_rect( // Residual stride is `side` (and `cside`), not `bw`: reconstruct_mc_rect indexes // `residual[row * side .. row*side + w]` for row in 0..h, so a skipped VERT strip // (bh > bw) overruns a `bw * bh` slice. Bug-for-bug with the inter skip arm. - push_mc_rect(0, px, py, side, bw, bh, Pred::Inline(&pred_y, side), &ZERO_RESIDUAL[..side * side], fctx); - push_mc_rect(1, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_u, cside), &ZERO_RESIDUAL[..cside * cside], fctx); - push_mc_rect(2, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_v, cside), &ZERO_RESIDUAL[..cside * cside], fctx); + push_mc_rect( + 0, + px, + py, + side, + bw, + bh, + Pred::Inline(&pred_y, side), + &ZERO_RESIDUAL[..side * side], + fctx, + ); + push_mc_rect( + 1, + cpx, + cpy, + cside, + cw, + ch, + Pred::Inline(&pred_u, cside), + &ZERO_RESIDUAL[..cside * cside], + fctx, + ); + push_mc_rect( + 2, + cpx, + cpy, + cside, + cw, + ch, + Pred::Inline(&pred_v, cside), + &ZERO_RESIDUAL[..cside * cside], + fctx, + ); if let Some(ls) = leaves.as_ref() { // lane-av1-loss64, merged: the same reset [`decode_intrabc_owned_rect`]'s // skip arm performs -- libaom `av1_reset_entropy_context` @@ -12228,7 +13026,8 @@ fn decode_intrabc_rect( py, Pred::Inline(&pred_y, side), None, - None, fctx, + None, + fctx, )?; luma_tx_type = tx_type; luma_grid = embed_grid_stride(&grid, bw, bh, side); @@ -12246,7 +13045,8 @@ fn decode_intrabc_rect( cpy, Pred::Inline(&pred_u, cside), Some(luma_tx_type), - None, fctx, + None, + fctx, )?; u_grid = embed_grid_stride(&ug, cw, ch, cside); let (vg, _) = read_inter_plane_rect( @@ -12263,7 +13063,8 @@ fn decode_intrabc_rect( cpy, Pred::Inline(&pred_v, cside), Some(luma_tx_type), - None, fctx, + None, + fctx, )?; v_grid = embed_grid_stride(&vg, cw, ch, cside); } @@ -12309,7 +13110,8 @@ fn decode_intrabc_rect( base_q_idx, tu_pred, None, - Some(tu_skip_ctx), fctx, + Some(tu_skip_ctx), + fctx, )? } else { let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI); @@ -12327,7 +13129,8 @@ fn decode_intrabc_rect( tu_py, tu_pred, None, - Some(tu_skip_ctx), fctx, + Some(tu_skip_ctx), + fctx, )? }; if idx == 0 { @@ -12361,7 +13164,8 @@ fn decode_intrabc_rect( cpy, Pred::Inline(&pred_u, cside), Some(luma_tx_type), - None, fctx, + None, + fctx, )?; u_grid = embed_grid_stride(&ug, cw, ch, cside); let (vg, _) = read_inter_plane_rect( @@ -12378,7 +13182,8 @@ fn decode_intrabc_rect( cpy, Pred::Inline(&pred_v, cside), Some(luma_tx_type), - None, fctx, + None, + fctx, )?; v_grid = embed_grid_stride(&vg, cw, ch, cside); luma_grid = Grid::Zero(side * side); @@ -12393,11 +13198,21 @@ fn decode_intrabc_rect( // DV into the intrabc mi grid the next block's DV predictor reads. if leaves.is_some() { neighbours.record_split_luma_rect_mi( - (mi_r, mi_c), bw, bh, DC_PRED, DC_PRED, [&u_grid, &v_grid], + (mi_r, mi_c), + bw, + bh, + DC_PRED, + DC_PRED, + [&u_grid, &v_grid], ); } else { neighbours.record_rect_mi( - (mi_r, mi_c), bw, bh, DC_PRED, DC_PRED, &[&luma_grid, &u_grid, &v_grid], + (mi_r, mi_c), + bw, + bh, + DC_PRED, + DC_PRED, + &[&luma_grid, &u_grid, &v_grid], ); } neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, 0, [0u16; 8]); @@ -12409,7 +13224,8 @@ fn decode_intrabc_rect( bh / MI, bw.min(64) as u8, bh.min(64) as u8, - 0, fctx, + 0, + fctx, ); record_intrabc_mi_rect( mi_r, @@ -12460,8 +13276,16 @@ fn decode_intrabc_128rect( ); } let (px, py) = (mi_c * MI, mi_r * MI); - let (cpx, cpy) = (px / 2, py / 2); - let (cw, ch) = (bw / 2, bh / 2); + // lane-av1-ibc128chunk: the block's chroma PLANE BLOCK is per-axis + // `(bw >> ss_x) x (bh >> ss_y)` -- 4:2:0 halves both (this fn's + // `mv_to_q4(cpy, dv_row, ss_y(fctx))` calls two lines below already + // scaled the DV on the y axis by ITS OWN subsampling, so the hardcoded + // `/2` origin and extent made the prediction window half as tall as + // the motion vector asked for), 4:2:2 is HALF-WIDTH and FULL-HEIGHT, + // 4:4:4 is luma-sized. At ss (1,1) every value below is the old + // `bw / 2, bh / 2` line-for-line. + let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx)); + let (cw, ch) = (bw >> ss_x(fctx), bh >> ss_y(fctx)); // The square strides the proven INTER path lays its residual grids, // prediction windows and `TxParams` at (see [`decode_intrabc_rect`]'s r2 // note): 128/64 here. @@ -12483,7 +13307,8 @@ fn decode_intrabc_128rect( (mi_r, mi_c), (bw, bh), (mi_cols, mi_rows), - skip, fctx, + skip, + fctx, )?; // Whole-block prediction, once, before any coefficient is read // (`predict_inter_block`); the source is this frame's own @@ -12491,9 +13316,17 @@ fn decode_intrabc_128rect( flush_recon(fctx, y, u, v); let mut pred_y_dense = vec![0u16; bw * bh]; mc::predict_with_filter( - &y.data, y.width, y.true_width, y.true_height, - mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0), - bw, bh, mc::InterpFilterKind::Bilinear, &mut pred_y_dense, fctx, + &y.data, + y.width, + y.true_width, + y.true_height, + mv_to_q4(px, dv_col, 0), + mv_to_q4(py, dv_row, 0), + bw, + bh, + mc::InterpFilterKind::Bilinear, + &mut pred_y_dense, + fctx, ); let mut pred_y = vec![0u16; side * side]; for row in 0..bh { @@ -12501,9 +13334,17 @@ fn decode_intrabc_128rect( } let mut pred_u_dense = vec![0u16; cw * ch]; mc::predict_with_filter( - &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), - cw, ch, mc::InterpFilterKind::Bilinear, &mut pred_u_dense, fctx, + &u.data, + u.width, + u.true_width, + u.true_height, + mv_to_q4(cpx, dv_col, ss_x(fctx)), + mv_to_q4(cpy, dv_row, ss_y(fctx)), + cw, + ch, + mc::InterpFilterKind::Bilinear, + &mut pred_u_dense, + fctx, ); let mut pred_u = vec![0u16; cside * cside]; for row in 0..ch { @@ -12511,9 +13352,17 @@ fn decode_intrabc_128rect( } let mut pred_v_dense = vec![0u16; cw * ch]; mc::predict_with_filter( - &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), - cw, ch, mc::InterpFilterKind::Bilinear, &mut pred_v_dense, fctx, + &v.data, + v.width, + v.true_width, + v.true_height, + mv_to_q4(cpx, dv_col, ss_x(fctx)), + mv_to_q4(cpy, dv_row, ss_y(fctx)), + cw, + ch, + mc::InterpFilterKind::Bilinear, + &mut pred_v_dense, + fctx, ); let mut pred_v = vec![0u16; cside * cside]; for row in 0..ch { @@ -12529,9 +13378,39 @@ fn decode_intrabc_128rect( // No residual syntax at all: the prediction IS the block. Strides are // `side`/`cside`, not `bw` -- `reconstruct_mc_rect` indexes // `row * stride + w` for row in 0..h (the r5 VERT-strip overrun). - push_mc_rect(0, px, py, side, bw, bh, Pred::Inline(&pred_y, side), &ZERO_RESIDUAL[..side * side], fctx); - push_mc_rect(1, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_u, cside), &ZERO_RESIDUAL[..cside * cside], fctx); - push_mc_rect(2, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_v, cside), &ZERO_RESIDUAL[..cside * cside], fctx); + push_mc_rect( + 0, + px, + py, + side, + bw, + bh, + Pred::Inline(&pred_y, side), + &ZERO_RESIDUAL[..side * side], + fctx, + ); + push_mc_rect( + 1, + cpx, + cpy, + cside, + cw, + ch, + Pred::Inline(&pred_u, cside), + &ZERO_RESIDUAL[..cside * cside], + fctx, + ); + push_mc_rect( + 2, + cpx, + cpy, + cside, + cw, + ch, + Pred::Inline(&pred_v, cside), + &ZERO_RESIDUAL[..cside * cside], + fctx, + ); if let Some(ls) = leaves.as_ref() { // A LOSSLESS frame's `read_block_tx_size_rect` resolves the TX_4X4 // grid before it looks at `skip`; the skipped block still zeroes @@ -12552,9 +13431,8 @@ fn decode_intrabc_128rect( u_grid = Grid::Zero(cside * cside); v_grid = Grid::Zero(cside * cside); } else { - let leaves = leaves.expect( - "read_block_tx_size_rect returns None only for skip below 128 at this shape", - ); + let leaves = leaves + .expect("read_block_tx_size_rect returns None only for skip below 128 at this shape"); // libaom `get_transform_size`'s split override applies to LUMA only, // per leaf -- each unit's own transform edges get filtered // ([`decode_intrabc_rect`]'s P2, the proven inter path's step). @@ -12576,7 +13454,10 @@ fn decode_intrabc_128rect( let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(mi_c)); let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(mi_r)); for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() { - debug_assert_eq!(tw, th, "a square TX_64X64 tree root only yields square leaves"); + debug_assert_eq!( + tw, th, + "a square TX_64X64 tree root only yields square leaves" + ); let tu_mi = (mi_r + row, mi_c + col); let (tu_px, tu_py) = (px + col * MI, py + row * MI); if tu_px >= y.true_width || tu_py >= y.true_height { @@ -12600,7 +13481,8 @@ fn decode_intrabc_128rect( base_q_idx, tu_pred, None, - Some(tu_skip_ctx), fctx, + Some(tu_skip_ctx), + fctx, )?; leaf_tx_types.push((row, col, tw, th, tu_tx_type)); neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); @@ -12617,34 +13499,57 @@ fn decode_intrabc_128rect( // TX_32X32 chroma unit per plane per chunk at 4:2:0, raster // within the chunk, plane-major inside the chunk. let cu_tx = 32usize; - let chunk_chroma = cside * 64 / side; - // lane-av1-128rectspan: SQUARE per-axis geometry -- one value - // for both axes, which holds only while `ss_x == ss_y`. At - // 4:2:2 a TX_32X32 chroma unit's luma footprint is - // (64, 32), a mu chunk's chroma plane block is 32x64 (two - // stacked units), and `units_y`/`cu_y`/`unit_mi.0` below all - // need the same per-axis treatment - // `decode_block_128rect`'s walk already has. 4:2:2 is refused - // by name at the sequence header, so this arm is - // unreachable for it today -- it is a PORT note for that - // format, not a live defect. - let unit_luma = cu_tx * (side / cside); + // lane-av1-ibc128chunk: a 64x64 mu chunk's chroma plane + // block is PER-AXIS `(64 >> ss_x) x (64 >> ss_y)` -- 32x32 at + // 4:2:0, TWO STACKED TX_32X32 at 4:2:2 (the chunk's chroma + // plane block is 32x64 there), four at 4:4:4. The old + // `chunk_chroma = cside * 64 / side` walked a + // `chroma_side`-SQUARE chunk, i.e. the 4:2:0 count on both + // axes: at 4:2:2 it read HALF the chroma units of a chunk + // (one 32x32 at the chunk's top-left instead of two), left + // the chunk's lower 32 chroma rows with no residual at all, + // and stamped every unit's entropy context over a 16x16-mi + // luma span instead of 16x8. The same defect and the same + // per-axis repair as `decode_inter_block`'s + // `chunk_chroma_w/chunk_chroma_h` (lane-av1-422bigblock, + // witnessed on `422_sb128_3f.obu`). + let chunk_chroma_w = (64usize) >> ss_x(fctx); + let chunk_chroma_h = (64usize) >> ss_y(fctx); + // The unit's own footprint on the LUMA mi grid, per axis: + // `(32 << ss) px` = `(32 << ss) / MI` mi -- 16x16 at 4:2:0, + // 16x8 at 4:2:2, 8x8 at 4:4:4. `around_mi_rect` reads and + // `record_mi_chroma` stamp exactly the unit's own cells. + let unit_luma_w = cu_tx << ss_x(fctx); + let unit_luma_h = cu_tx << ss_y(fctx); + INTRABC_128RECT_CHUNK_SHAPE.with(|c| { + c.set((chunk_chroma_w << 8) | chunk_chroma_h); + }); let chunk_w_mi = 16.min(max_w_mi.saturating_sub(cc * 16)); let chunk_h_mi = 16.min(max_h_mi.saturating_sub(cr * 16)); - let units_x = chunk_w_mi / (unit_luma / MI); - let units_y = chunk_h_mi / (unit_luma / MI); + let units_x = chunk_w_mi / (unit_luma_w / MI); + let units_y = chunk_h_mi / (unit_luma_h / MI); if lossless(fctx) { // TX_4X4 chroma units over this chunk (lane-lossless2's // walk, shared with the inter 128 path). read_inter_chroma_lossless( - dec, cdfs, neighbours, u, v, - Pred::Inline(&pred_u, cside), Pred::Inline(&pred_v, cside), - (mi_r, mi_c), (cpx, cpy), - (cc * chunk_chroma, cr * chunk_chroma), - (chunk_chroma, chunk_chroma), + dec, + cdfs, + neighbours, + u, + v, + Pred::Inline(&pred_u, cside), + Pred::Inline(&pred_v, cside), + (mi_r, mi_c), + (cpx, cpy), + (cc * chunk_chroma_w, cr * chunk_chroma_h), + (chunk_chroma_w, chunk_chroma_h), (cw, ch), - cside, 0, base_q_idx, - &mut u_units, &mut v_units, fctx, + cside, + 0, + base_q_idx, + &mut u_units, + &mut v_units, + fctx, )?; // lane-av1-ibcrect: read_inter_chroma_lossless stamped // every TX_4X4 unit's own context (`record_mi_chroma` @@ -12664,15 +13569,16 @@ fn decode_intrabc_128rect( for ur in 0..units_y { for uc in 0..units_x { let unit_mi = ( - mi_r + cr * 16 + ur * (unit_luma / MI), - mi_c + cc * 16 + uc * (unit_luma / MI), + mi_r + cr * 16 + ur * (unit_luma_h / MI), + mi_c + cc * 16 + uc * (unit_luma_w / MI), ); // Per unit, AFTER the earlier units' stamps: this // unit's coefficient context must see them. - let cu_around = neighbours.around_mi(unit_mi, unit_luma); + let cu_around = + neighbours.around_mi_rect(unit_mi, unit_luma_w, unit_luma_h); if crate::envflags::env_flag!("EC_ECDUMP") { for p in 1..3 { - let ab: Vec = (0..unit_luma / MI) + let ab: Vec = (0..unit_luma_w / MI) .map(|k| { format!( "{:?}/{}", @@ -12681,7 +13587,7 @@ fn decode_intrabc_128rect( ) }) .collect(); - let lf: Vec = (0..unit_luma / MI) + let lf: Vec = (0..unit_luma_h / MI) .map(|k| { format!( "{:?}/{}", @@ -12692,23 +13598,24 @@ fn decode_intrabc_128rect( .collect(); eprintln!( "EC_IBC128_BANDS mi=({mi_r},{mi_c}) unit=({cr},{cc}) plane={p} ctx=({},{},{}) above=[{}] left=[{}]", - cu_around[p].0, cu_around[p].1, cu_around[p].2, ab.join(","), lf.join(",") + cu_around[p].0, + cu_around[p].1, + cu_around[p].2, + ab.join(","), + lf.join(",") ); } } let (cu_x, cu_y) = ( - cpx + cc * chunk_chroma + uc * cu_tx, - cpy + cr * chunk_chroma + ur * cu_tx, + cpx + cc * chunk_chroma_w + uc * cu_tx, + cpy + cr * chunk_chroma_h + ur * cu_tx, ); // `av1_get_tx_type` (blockd.h:1291): an inter // block's chroma unit never codes a tx_type; it // inherits the coded type of the luma leaf // covering its own quadrant (all of this chunk's // leaves are read by now). - let unit_rel_mi = ( - unit_mi.0 - mi_r, - unit_mi.1 - mi_c, - ); + let unit_rel_mi = (unit_mi.0 - mi_r, unit_mi.1 - mi_c); let covering = leaf_tx_types .iter() .copied() @@ -12719,9 +13626,12 @@ fn decode_intrabc_128rect( && unit_rel_mi.1 < lc + lw / MI }) .map(|(_, _, _, _, t)| t); + // The prediction window is the block's own square + // `cside` buffer with the unit's true per-axis + // position inside it. let cu_pred = src.offset( - (cr * chunk_chroma + ur * cu_tx) * cside - + cc * chunk_chroma + (cr * chunk_chroma_h + ur * cu_tx) * cside + + cc * chunk_chroma_w + uc * cu_tx, ); let cu_grid = read_inter_plane( @@ -12739,15 +13649,16 @@ fn decode_intrabc_128rect( base_q_idx, cu_pred, Some(covering.unwrap_or(TxType::DctDct)), - Some(3), fctx, + Some(3), + fctx, )? .0; // Immediately, so the NEXT unit reads this one's // coefficient context. neighbours.record_mi_chroma( unit_mi, - unit_luma, - unit_luma, + unit_luma_w, + unit_luma_h, plane_idx, &cu_grid, ); @@ -12759,18 +13670,22 @@ fn decode_intrabc_128rect( ); } hit!(CHROMA_SPLIT_TX_HITS); + INTRABC_128RECT_CHROMA_CHUNK_HITS.with(|c| c.set(c.get() + 1)); // lane-av1-ibcrect: per-unit chroma context -- the // end-of-block record's composed-grid re-stamp // must not stand (replayed below). mu_chroma = true; let dst = mu_units( - if plane_idx == 1 { &mut u_units } else { &mut v_units }, + if plane_idx == 1 { + &mut u_units + } else { + &mut v_units + }, cside * cside, ); for rr in 0..cu_tx { - let start = (cr * chunk_chroma + ur * cu_tx + rr) - * cside - + cc * chunk_chroma + let start = (cr * chunk_chroma_h + ur * cu_tx + rr) * cside + + cc * chunk_chroma_w + uc * cu_tx; dst[start..start + cu_tx] .copy_from_slice(&cu_grid[rr * cu_tx..][..cu_tx]); @@ -12800,12 +13715,21 @@ fn decode_intrabc_128rect( // and the DV into the intrabc mi grid. if skip { neighbours.record_rect_mi( - (mi_r, mi_c), bw, bh, DC_PRED, DC_PRED, + (mi_r, mi_c), + bw, + bh, + DC_PRED, + DC_PRED, &[&luma_grid[..], &u_grid[..], &v_grid[..]], ); } else { neighbours.record_split_luma_rect_mi( - (mi_r, mi_c), bw, bh, DC_PRED, DC_PRED, [&u_grid[..], &v_grid[..]], + (mi_r, mi_c), + bw, + bh, + DC_PRED, + DC_PRED, + [&u_grid[..], &v_grid[..]], ); } // lane-av1-ibcrect: the coded arm's chroma contexts were stamped PER @@ -12825,28 +13749,102 @@ fn decode_intrabc_128rect( let cu = if lossless(fctx) { 4usize } else { 32usize }; // The unit's own footprint on the LUMA mi grid (the chroma context // bands are luma-mi indexed, [`Self::record_mi_chroma`]'s - // convention): 8 px x2 per TX_4X4 unit, 64 px per TX_32X32 one. - let unit_luma = cu * 2; - // Raster over the block's chroma plane, `chunk_chroma` per mu chunk - // (the same extents the read loop above laid the composed grid out - // at) -- a unit the frame edge clipped codes nothing and carries no - // composed samples beyond the clip, so it replays as the zero state - // exactly like libaom's uncoded unit. - let chunk_chroma = cside * 64 / side; - let (rows, cols) = ((ch / chunk_chroma).max(1), (cw / chunk_chroma).max(1)); - for cr in 0..rows { - for cc in 0..cols { - let unit_mi = (mi_r + cr * (unit_luma / MI), mi_c + cc * (unit_luma / MI)); - for (plane_idx, grid) in [(1usize, &u_grid), (2usize, &v_grid)] { - let mut unit = Vec::with_capacity(cu * cu); - for rr in 0..cu { - let start = - (cr * chunk_chroma + rr) * cside + cc * chunk_chroma; - unit.extend_from_slice(&grid[start..start + cu]); - } - neighbours.record_mi_chroma( - unit_mi, unit_luma, unit_luma, plane_idx, &unit, + // convention), PER AXIS: `cu << ss` px, i.e. 8 px per TX_4x4 unit and + // 64 px per TX_32X32 one at 4:2:0 -- 4 px / 32 px at 4:2:2. + let unit_luma_w = cu << ss_x(fctx); + let unit_luma_h = cu << ss_y(fctx); + // A 64x64 mu chunk's chroma plane block is PER-AXIS + // `(64 >> ss_x) x (64 >> ss_y)` -- 32x32 at 4:2:0 (ONE TX_32X32 per + // chunk), 32x64 at 4:2:2 (TWO STACKED), 64x64 at 4:4:4 (FOUR); + // `av1_get_max_uv_txsize` caps the unit at 32 on each axis. + let chunk_chroma_w = (64usize) >> ss_x(fctx); + let chunk_chroma_h = (64usize) >> ss_y(fctx); + if lossless(fctx) { + // lane-av1-ibc128chunk, PRE-EXISTING and NOT this lane's: on a + // LOSSLESS frame `cu` is 4 and the composed plane grid is a raster + // of TX_4x4 units, not a `cu`-per-chunk tiling -- so `rows`/`cols` + // below (which count mu CHUNKS at the 4:2:0 chunk extent) do not + // enumerate it, and this arm re-stamps only the 4x4 at each + // chunk's top-left with a 2x2-mi span. The twin + // (`decode_inter_block`'s `mu_chroma_units`, lane-av1-llinter) + // instead raster-walks the WHOLE plane block at `cu` steps, and + // that is the correct shape here too. It is left as-is on purpose: + // it is a 4:2:0 defect, not a subsampling square-cut, and fixing + // it would change 4:2:0 LOSSLESS output -- which this lane's + // byte-identity requirement forbids doing on an unverified + // reconstruction. Measured unreachability: this arm is entered + // 0 times by the whole `lossless` and `intrabc` gate battery + // (temporary env-gated counter in the arm). Unblock: one + // lossless sb128 4:2:0 stream coding a NON-SKIP 128-root + // intrabc strip (`--lossless=1 --sb-size=128 + // --min-partition-size=64 --enable-rect-partitions=1 + // --enable-intrabc=1` over near-match screen content). + let (rows, cols) = ((ch / chunk_chroma_h).max(1), (cw / chunk_chroma_w).max(1)); + for cr in 0..rows { + for cc in 0..cols { + let unit_mi = ( + mi_r + cr * (unit_luma_h / MI), + mi_c + cc * (unit_luma_w / MI), ); + for (plane_idx, grid) in [(1usize, &u_grid), (2usize, &v_grid)] { + let mut unit = Vec::with_capacity(cu * cu); + for rr in 0..cu { + let start = (cr * chunk_chroma_h + rr) * cside + cc * chunk_chroma_w; + unit.extend_from_slice(&grid[start..start + cu]); + } + neighbours.record_mi_chroma( + unit_mi, + unit_luma_w, + unit_luma_h, + plane_idx, + &unit, + ); + } + } + } + } else { + // The chunk count on each axis, then EVERY unit inside each + // chunk at its own mi origin, its own `(cu << ss)`-px entropy-cell + // span, and its own quadrant of the composed plane grid -- the + // twin's loop (decode_inter_block's `mu_chroma_units`, + // lane-av1-444 c8). lane-av1-ibc128chunk: the loop used to count + // mu CHUNKS in `rows`/`cols` and then step the mi origin and read + // the grid PER UNIT, which only agrees when a chunk holds exactly + // one unit. At 4:2:0 (`chunk_chroma == cu`) it is + // line-identical to the old walk; at 4:2:2 and 4:4:4 a chunk holds + // 2 or 4, so the old body reached only the first of the stacked + // units and the rest of the chunk kept the composed-grid smearing + // this replay exists to undo. A unit the frame edge clipped codes + // nothing and carries no composed samples beyond the clip, so it + // replays as the zero state exactly like libaom's uncoded unit. + let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w / cu); + let (rows, cols) = ((ch / chunk_chroma_h).max(1), (cw / chunk_chroma_w).max(1)); + for cr in 0..rows { + for cc in 0..cols { + for kr in 0..ur { + for kc in 0..uc { + let unit_mi = ( + mi_r + (cr * 64 + kr * unit_luma_h) / MI, + mi_c + (cc * 64 + kc * unit_luma_w) / MI, + ); + let (cy, cx) = + (cr * chunk_chroma_h + kr * cu, cc * chunk_chroma_w + kc * cu); + for (plane_idx, grid) in [(1usize, &u_grid), (2usize, &v_grid)] { + let mut unit = Vec::with_capacity(cu * cu); + for rr in 0..cu { + let start = (cy + rr) * cside + cx; + unit.extend_from_slice(&grid[start..start + cu]); + } + neighbours.record_mi_chroma( + unit_mi, + unit_luma_w, + unit_luma_h, + plane_idx, + &unit, + ); + } + } + } } } } @@ -12860,7 +13858,8 @@ fn decode_intrabc_128rect( bh / MI, bw.min(64) as u8, bh.min(64) as u8, - 0, fctx, + 0, + fctx, ); record_intrabc_mi_rect( mi_r, @@ -12899,31 +13898,43 @@ fn decode_block_rect( allow_screen_content_tools: bool, base_q_idx: u8, tx_select: bool, - reduced_tx_set: bool, fctx: &crate::decode::FrameCtx, + reduced_tx_set: bool, + fctx: &crate::decode::FrameCtx, ) -> Result<()> { let (r, c) = at; let (px, py) = (c * SUB, r * SUB); let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); let palette_uv_cache = neighbours.palette_uv_cache(at); - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv, intrabc) = - read_intra_mode_rect( - dec, - cdfs, - nb_above_mode, - nb_left_mode, - true, - true, - bw, - bh, - enable_filter_intra, - neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)), - allow_screen_content_tools, - Some((palette_ctx, &palette_cache)), - &palette_uv_cache, - r * (SUB / MI), - c * (SUB / MI), fctx, - )?; + let ( + skip, + mode, + angle_delta_y, + uv_mode, + angle_delta_uv, + alpha, + filter_intra, + palette_y, + palette_uv, + intrabc, + ) = read_intra_mode_rect( + dec, + cdfs, + nb_above_mode, + nb_left_mode, + true, + true, + bw, + bh, + enable_filter_intra, + neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)), + allow_screen_content_tools, + Some((palette_ctx, &palette_cache)), + &palette_uv_cache, + r * (SUB / MI), + c * (SUB / MI), + fctx, + )?; if let Some((dv_row, dv_col)) = intrabc { return decode_intrabc_rect( @@ -12937,7 +13948,8 @@ fn decode_block_rect( y, u, v, - base_q_idx, fctx, + base_q_idx, + fctx, ); } let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode); @@ -13000,7 +14012,8 @@ fn decode_block_rect( neighbours, (mi_r, mi_c), depth_to_tx_wh(bw, bh, depth, fctx), - (bw, bh), fctx, + (bw, bh), + fctx, ); if depth != 0 || lossless(fctx) { hit!(TX_DEPTH_HITS); @@ -13053,7 +14066,8 @@ fn decode_block_rect( u, v, base_q_idx, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )?; // This early return skips this fn's own tail, so the palette // neighbour state has to be stamped HERE too: without it a split-tx @@ -13062,10 +14076,13 @@ fn decode_block_rect( // ([`Neighbours::palette_uv_cache`]) then hit a cached entry with the // wrong VALUE -- same bit count, so the entropy stream stayed in sync // and only those pixels were wrong (lane-palette2 r10). - let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); + let (py_size, py_colors) = palette_y + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.colors)); neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors); - let (puv_size, puv_colors) = - palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); + let (puv_size, puv_colors) = palette_uv + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors); hit!(RECT_PARTITION_HITS); return Ok(()); @@ -13086,17 +14103,28 @@ fn decode_block_rect( // block's prediction is the reconstructed colour-index map, set fresh // right before each `reconstruct_rect` call below (lane-palette2 r4). if let Some(ref pyv) = palette_y { - let buf: Vec = pyv.map.iter().map(|&idx| pyv.colors[idx as usize]).collect(); + let buf: Vec = pyv + .map + .iter() + .map(|&idx| pyv.colors[idx as usize]) + .collect(); set_palette_pred(buf, fctx); } let palette_uv_bufs: Option<(Vec, Vec)> = palette_uv.as_ref().map(|puv| { ( - puv.map.iter().map(|&idx| puv.u_colors[idx as usize]).collect(), - puv.map.iter().map(|&idx| puv.v_colors[idx as usize]).collect(), + puv.map + .iter() + .map(|&idx| puv.u_colors[idx as usize]) + .collect(), + puv.map + .iter() + .map(|&idx| puv.v_colors[idx as usize]) + .collect(), ) }); if skip { - push_intra_rect(0, + push_intra_rect( + 0, px, py, bw, @@ -13107,13 +14135,15 @@ fn decode_block_rect( &ZERO_RESIDUAL[..bw * bh], None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - push_intra_rect(1, + push_intra_rect( + 1, cpx, cpy, chroma_w, @@ -13124,12 +14154,14 @@ fn decode_block_rect( &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - push_intra_rect(2, + push_intra_rect( + 2, cpx, cpy, chroma_w, @@ -13140,7 +14172,8 @@ fn decode_block_rect( &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); neighbours.record_rect( at, @@ -13182,7 +14215,7 @@ fn decode_block_rect( _ => { return Err(unsupported( "a rectangular chroma transform whose size has no coefficient table", - )) + )); } }; let chroma_default_tx = if chroma_w.max(chroma_h) >= 32 { @@ -13225,148 +14258,172 @@ fn decode_block_rect( // --enable-tx-size-search=0 the encoder writes no such symbol, so the // decoder consumed one that was never there. { - let around = neighbours.around_rect(at, bw, bh); - let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, fi_tx_row(mode, filter_intra)); - let (luma_levels, luma_tx_type) = read_coeffs_rect( - dec, - &mut luma_coding, - luma_scan, - bw, - bh, - 0, - dc_sign_ctx(around[0].2), - TxType::DctDct, - )?; - if crate::envflags::env_flag!("EC_AV1_TRACE") { - let (rng, _) = dec.debug_state(); - eprintln!("TRACE_RECT_COEFF plane=0 mi_row={mi_r} mi_col={mi_c} rng={rng}"); - } - let luma_residual = dequant_and_inverse_typed_wh( - &luma_levels, - bw, - bh, - crate::decode::bit_depth(fctx), - block_q_idx(fctx), - plane_q_delta(0, fctx).0, - plane_q_delta(0, fctx).1, - luma_tx_type, + let around = neighbours.around_rect(at, bw, bh); + let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, fi_tx_row(mode, filter_intra)); + let (luma_levels, luma_tx_type) = read_coeffs_rect( + dec, + &mut luma_coding, + luma_scan, + bw, + bh, + 0, + dc_sign_ctx(around[0].2), + TxType::DctDct, + )?; + if crate::envflags::env_flag!("EC_AV1_TRACE") { + let (rng, _) = dec.debug_state(); + eprintln!("TRACE_RECT_COEFF plane=0 mi_row={mi_r} mi_col={mi_c} rng={rng}"); + } + let luma_residual = dequant_and_inverse_typed_wh( + &luma_levels, + bw, + bh, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(0, fctx).0, + plane_q_delta(0, fctx).1, + luma_tx_type, block_iqmatrix(fctx, 0, bw, bh, luma_tx_type), - ); - push_intra_rect(0, - px, - py, - bw, - bh, - mode, - angle_delta_y, - reach, - &luma_residual, - None, - filter_intra, - smooth_neighbor, fctx, - ); - let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); - if let Some((ub, _)) = &palette_uv_bufs { - set_palette_pred(ub.clone(), fctx); - } - let u_default_tx = chroma_default_tx; - let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); - let mut u_coding = cdfs.txb(chroma_set, uv_predict_mode); - let (u_levels, u_tx_type) = read_chroma_coeffs_rect( - dec, - &mut u_coding, - chroma_scan, - chroma_w, - chroma_h, - u_skip_ctx, - dc_sign_ctx(around[1].2), - u_default_tx, - fctx, - )?; - if crate::envflags::env_flag!("EC_AV1_TRACE") { - let (rng, _) = dec.debug_state(); - eprintln!("TRACE_RECT_COEFF plane=1 mi_row={mi_r} mi_col={mi_c} rng={rng}"); - } - let u_residual = dequant_and_inverse_typed_wh( - &u_levels, - chroma_w, - chroma_h, - crate::decode::bit_depth(fctx), - block_q_idx(fctx), - plane_q_delta(1, fctx).0, - plane_q_delta(1, fctx).1, - u_tx_type, + ); + push_intra_rect( + 0, + px, + py, + bw, + bh, + mode, + angle_delta_y, + reach, + &luma_residual, + None, + filter_intra, + smooth_neighbor, + fctx, + ); + let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); + if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone(), fctx); + } + let u_default_tx = chroma_default_tx; + let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); + let mut u_coding = cdfs.txb(chroma_set, uv_predict_mode); + let (u_levels, u_tx_type) = read_chroma_coeffs_rect( + dec, + &mut u_coding, + chroma_scan, + chroma_w, + chroma_h, + u_skip_ctx, + dc_sign_ctx(around[1].2), + u_default_tx, + fctx, + )?; + if crate::envflags::env_flag!("EC_AV1_TRACE") { + let (rng, _) = dec.debug_state(); + eprintln!("TRACE_RECT_COEFF plane=1 mi_row={mi_r} mi_col={mi_c} rng={rng}"); + } + let u_residual = dequant_and_inverse_typed_wh( + &u_levels, + chroma_w, + chroma_h, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(1, fctx).0, + plane_q_delta(1, fctx).1, + u_tx_type, block_iqmatrix(fctx, 1, chroma_w, chroma_h, u_tx_type), - ); - push_intra_rect(1, - cpx, - cpy, - chroma_w, - chroma_h, - uv_predict_mode, - angle_delta_uv, - reach, - &u_residual, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - None, - smooth_neighbor_uv, fctx, - ); - if let Some((_, vb)) = &palette_uv_bufs { - set_palette_pred(vb.clone(), fctx); - } - let v_default_tx = chroma_default_tx; - let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); - let mut v_coding = cdfs.txb(chroma_set, uv_predict_mode); - let (v_levels, v_tx_type) = read_chroma_coeffs_rect( - dec, - &mut v_coding, - chroma_scan, - chroma_w, - chroma_h, - v_skip_ctx, - dc_sign_ctx(around[2].2), - v_default_tx, - fctx, - )?; - if crate::envflags::env_flag!("EC_AV1_TRACE") { - let (rng, _) = dec.debug_state(); - eprintln!("TRACE_RECT_COEFF plane=2 mi_row={mi_r} mi_col={mi_c} rng={rng}"); - } - let v_residual = dequant_and_inverse_typed_wh( - &v_levels, - chroma_w, - chroma_h, - crate::decode::bit_depth(fctx), - block_q_idx(fctx), - plane_q_delta(2, fctx).0, - plane_q_delta(2, fctx).1, - v_tx_type, + ); + push_intra_rect( + 1, + cpx, + cpy, + chroma_w, + chroma_h, + uv_predict_mode, + angle_delta_uv, + reach, + &u_residual, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + fctx, + ); + if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone(), fctx); + } + let v_default_tx = chroma_default_tx; + let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); + let mut v_coding = cdfs.txb(chroma_set, uv_predict_mode); + let (v_levels, v_tx_type) = read_chroma_coeffs_rect( + dec, + &mut v_coding, + chroma_scan, + chroma_w, + chroma_h, + v_skip_ctx, + dc_sign_ctx(around[2].2), + v_default_tx, + fctx, + )?; + if crate::envflags::env_flag!("EC_AV1_TRACE") { + let (rng, _) = dec.debug_state(); + eprintln!("TRACE_RECT_COEFF plane=2 mi_row={mi_r} mi_col={mi_c} rng={rng}"); + } + let v_residual = dequant_and_inverse_typed_wh( + &v_levels, + chroma_w, + chroma_h, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(2, fctx).0, + plane_q_delta(2, fctx).1, + v_tx_type, block_iqmatrix(fctx, 2, chroma_w, chroma_h, v_tx_type), - ); - push_intra_rect(2, - cpx, - cpy, - chroma_w, - chroma_h, - uv_predict_mode, - angle_delta_uv, - reach, - &v_residual, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - None, - smooth_neighbor_uv, fctx, - ); - neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[&luma_levels[..], &u_levels[..], &v_levels[..]]); - hit!(RECT_COEFF_HITS); + ); + push_intra_rect( + 2, + cpx, + cpy, + chroma_w, + chroma_h, + uv_predict_mode, + angle_delta_uv, + reach, + &v_residual, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + fctx, + ); + neighbours.record_rect( + at, + bw, + bh, + mode, + uv_predict_mode, + &[&luma_levels[..], &u_levels[..], &v_levels[..]], + ); + hit!(RECT_COEFF_HITS); } } - let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); + let (py_size, py_colors) = palette_y + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.colors)); neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors); - let (puv_size, puv_colors) = - palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); + let (puv_size, puv_colors) = palette_uv + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors); neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); - neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0, fctx); + neighbours.fill_lf_grid_rect( + (mi_r, mi_c), + bw / MI, + bh / MI, + tx_w as u8, + tx_h as u8, + 0, + fctx, + ); hit!(RECT_PARTITION_HITS); if crate::envflags::env_flag!("EC_AV1_TRACE") { eprintln!("TRACE_RECT32_END mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh}"); @@ -13411,7 +14468,8 @@ fn decode_leaf_rect( allow_screen_content_tools: bool, base_q_idx: u8, tx_select: bool, - reduced_tx_set: bool, fctx: &crate::decode::FrameCtx, + reduced_tx_set: bool, + fctx: &crate::decode::FrameCtx, ) -> Result { let _ = base_q_idx; if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") { @@ -13441,8 +14499,7 @@ fn decode_leaf_rect( // tile-edge neighbour. let (above_mode, left_mode) = neighbours.modes_above_left_mi(leaf_mi.0, leaf_mi.1, (above_mode, left_mode)); - let smooth_neighbor = - is_smooth_mode(above_mode) || is_smooth_mode(left_mode); + let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); if smooth_neighbor { hit!(SMOOTH_LUMA_HITS); } @@ -13459,29 +14516,50 @@ fn decode_leaf_rect( let pal_at = leaf_mi; let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at); let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at); - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv, intrabc) = - read_intra_mode_rect( - dec, - cdfs, - above_mode, - left_mode, - true, - true, - bw, - bh, - enable_filter_intra, - neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1), - allow_screen_content_tools, - Some((palette_ctx, &palette_cache)), - &palette_uv_cache, - leaf_mi.0, - leaf_mi.1, fctx, - )?; + let ( + skip, + mode, + angle_delta_y, + uv_mode, + angle_delta_uv, + alpha, + filter_intra, + palette_y, + palette_uv, + intrabc, + ) = read_intra_mode_rect( + dec, + cdfs, + above_mode, + left_mode, + true, + true, + bw, + bh, + enable_filter_intra, + neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1), + allow_screen_content_tools, + Some((palette_ctx, &palette_cache)), + &palette_uv_cache, + leaf_mi.0, + leaf_mi.1, + fctx, + )?; if let Some((dv_row, dv_col)) = intrabc { decode_intrabc_rect( - dec, cdfs, neighbours, leaf_mi, (bw, bh), skip, (dv_row, dv_col), - y, u, v, base_q_idx, fctx, + dec, + cdfs, + neighbours, + leaf_mi, + (bw, bh), + skip, + (dv_row, dv_col), + y, + u, + v, + base_q_idx, + fctx, )?; return Ok(DC_PRED); } @@ -13500,10 +14578,12 @@ fn decode_leaf_rect( p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), ) }); - let (pal_y_size, pal_y_colors) = - palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); - let (pal_uv_size, pal_uv_colors) = - palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); + let (pal_y_size, pal_y_colors) = palette_y + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.colors)); + let (pal_uv_size, pal_uv_colors) = palette_uv + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") { eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}"); } @@ -13515,7 +14595,11 @@ fn decode_leaf_rect( hit!(FILTER_INTRA_RECT_HITS); hit!(FILTER_INTRA_RECT_SUB16_HITS); } - let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + let uv_predict_mode = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; // lane-cfl r1, same defect as [`decode_leaf_8x8`]: chroma's intra-edge // filter type is the NEIGHBOUR's `uv_mode` (libaom `get_filt_type`), not // a constant `false`. @@ -13549,7 +14633,12 @@ fn decode_leaf_rect( // `wrong-alphabet-same-value`, here same alphabet / wrong row). let d = dec.symbol(&mut cdfs.tx_size_cat1[ctx]); if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { - eprintln!("EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=1 rng={}", leaf_mi.0, leaf_mi.1, dec.debug_state().0); + eprintln!( + "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=1 rng={}", + leaf_mi.0, + leaf_mi.1, + dec.debug_state().0 + ); } d } else { @@ -13561,7 +14650,8 @@ fn decode_leaf_rect( neighbours, leaf_mi, depth_to_tx_wh(bw, bh, depth, fctx), - (bw, bh), fctx, + (bw, bh), + fctx, ); if depth != 0 || lossless(fctx) { // The same per-transform-unit walk the bigger strips take @@ -13603,10 +14693,18 @@ fn decode_leaf_rect( u, v, base_q_idx, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )?; record_strip_palette( - neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, + neighbours, + pal_at, + bw, + bh, + pal_y_size, + pal_y_colors, + pal_uv_size, + pal_uv_colors, ); return Ok(mode); } @@ -13622,24 +14720,57 @@ fn decode_leaf_rect( if let Some(b) = &palette_y_buf { set_palette_pred(b.clone(), fctx); } - push_intra_rect(0, - px, py, bw, bh, mode, angle_delta_y, reach, &luma_levels, None, filter_intra, - smooth_neighbor, fctx, + push_intra_rect( + 0, + px, + py, + bw, + bh, + mode, + angle_delta_y, + reach, + &luma_levels, + None, + filter_intra, + smooth_neighbor, + fctx, ); let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - push_intra_rect(1, - cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_levels, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx, + push_intra_rect( + 1, + cpx, + cpy, + chroma_w, + chroma_h, + uv_predict_mode, + angle_delta_uv, + reach, + &u_levels, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + fctx, ); if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - push_intra_rect(2, - cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_levels, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx, + push_intra_rect( + 2, + cpx, + cpy, + chroma_w, + chroma_h, + uv_predict_mode, + angle_delta_uv, + reach, + &v_levels, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + fctx, ); } else { // lane-rectx: a genuine 16x8/8x16 luma transform (`TxbSet::LumaRect16x8`, @@ -13655,9 +14786,17 @@ fn decode_leaf_rect( // leaves the full 16x8/8x16 rect (`TxbSet::ChromaRect16x8`). let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0; let (luma_scan, chroma_scan): (&[u16], &[u16]) = if ss_x(fctx) == 0 { - if bw == 16 { (&SCAN_16X8, &SCAN_16X8) } else { (&SCAN_8X16, &SCAN_8X16) } + if bw == 16 { + (&SCAN_16X8, &SCAN_16X8) + } else { + (&SCAN_8X16, &SCAN_8X16) + } } else if chroma_422 { - if bw == 16 { (&SCAN_16X8, default_scan(8)) } else { (&SCAN_8X16, default_scan(8)) } + if bw == 16 { + (&SCAN_16X8, default_scan(8)) + } else { + (&SCAN_8X16, default_scan(8)) + } } else if bw == 16 { (&SCAN_16X8, &SCAN_8X4) } else { @@ -13678,69 +14817,151 @@ fn decode_leaf_rect( }; let mut luma_coding = cdfs.txb(luma_set, fi_tx_row(mode, filter_intra)); let (l_levels, luma_tx_type) = read_coeffs_rect( - dec, &mut luma_coding, luma_scan, bw, bh, 0, dc_sign_ctx(around[0].2), TxType::DctDct, + dec, + &mut luma_coding, + luma_scan, + bw, + bh, + 0, + dc_sign_ctx(around[0].2), + TxType::DctDct, )?; if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") { - let nz: Vec<(usize, i32)> = l_levels.iter().copied().enumerate().filter(|(_, v)| *v != 0).collect(); + let nz: Vec<(usize, i32)> = l_levels + .iter() + .copied() + .enumerate() + .filter(|(_, v)| *v != 0) + .collect(); eprintln!(" luma_tx_type={luma_tx_type:?} nz_levels={nz:?}"); } luma_levels = l_levels; let luma_residual = dequant_and_inverse_typed_wh( - &luma_levels, bw, bh, crate::decode::bit_depth(fctx), - block_q_idx(fctx), plane_q_delta(0, fctx).0, plane_q_delta(0, fctx).1, luma_tx_type, - block_iqmatrix(fctx, 0, bw, bh, luma_tx_type), + &luma_levels, + bw, + bh, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(0, fctx).0, + plane_q_delta(0, fctx).1, + luma_tx_type, + block_iqmatrix(fctx, 0, bw, bh, luma_tx_type), ); if let Some(b) = &palette_y_buf { set_palette_pred(b.clone(), fctx); } - push_intra_rect(0, - px, py, bw, bh, mode, angle_delta_y, reach, &luma_residual, None, filter_intra, - smooth_neighbor, fctx, + push_intra_rect( + 0, + px, + py, + bw, + bh, + mode, + angle_delta_y, + reach, + &luma_residual, + None, + filter_intra, + smooth_neighbor, + fctx, ); let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); let u_default_tx = default_intra_tx_type(uv_predict_mode as u8); let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); let mut u_coding = cdfs.txb(chroma_rect_set, uv_predict_mode); let (u_l, u_tx_type) = read_chroma_coeffs_rect( - dec, &mut u_coding, chroma_scan, chroma_w, chroma_h, u_skip_ctx, - dc_sign_ctx(around[1].2), u_default_tx, fctx, + dec, + &mut u_coding, + chroma_scan, + chroma_w, + chroma_h, + u_skip_ctx, + dc_sign_ctx(around[1].2), + u_default_tx, + fctx, )?; u_levels = u_l; let u_residual = dequant_and_inverse_typed_wh( - &u_levels, chroma_w, chroma_h, crate::decode::bit_depth(fctx), - block_q_idx(fctx), plane_q_delta(1, fctx).0, plane_q_delta(1, fctx).1, u_tx_type, - block_iqmatrix(fctx, 1, chroma_w, chroma_h, u_tx_type), + &u_levels, + chroma_w, + chroma_h, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(1, fctx).0, + plane_q_delta(1, fctx).1, + u_tx_type, + block_iqmatrix(fctx, 1, chroma_w, chroma_h, u_tx_type), ); if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - push_intra_rect(1, - cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_residual, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx, + push_intra_rect( + 1, + cpx, + cpy, + chroma_w, + chroma_h, + uv_predict_mode, + angle_delta_uv, + reach, + &u_residual, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + fctx, ); let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); let mut v_coding = cdfs.txb(chroma_rect_set, uv_predict_mode); let (v_l, v_tx_type) = read_chroma_coeffs_rect( - dec, &mut v_coding, chroma_scan, chroma_w, chroma_h, v_skip_ctx, - dc_sign_ctx(around[2].2), v_default_tx, fctx, + dec, + &mut v_coding, + chroma_scan, + chroma_w, + chroma_h, + v_skip_ctx, + dc_sign_ctx(around[2].2), + v_default_tx, + fctx, )?; v_levels = v_l; let v_residual = dequant_and_inverse_typed_wh( - &v_levels, chroma_w, chroma_h, crate::decode::bit_depth(fctx), - block_q_idx(fctx), plane_q_delta(2, fctx).0, plane_q_delta(2, fctx).1, v_tx_type, - block_iqmatrix(fctx, 2, chroma_w, chroma_h, v_tx_type), + &v_levels, + chroma_w, + chroma_h, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(2, fctx).0, + plane_q_delta(2, fctx).1, + v_tx_type, + block_iqmatrix(fctx, 2, chroma_w, chroma_h, v_tx_type), ); if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - push_intra_rect(2, - cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_residual, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx, + push_intra_rect( + 2, + cpx, + cpy, + chroma_w, + chroma_h, + uv_predict_mode, + angle_delta_uv, + reach, + &v_residual, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + fctx, ); hit!(RECT_LEAF_COEFF_HITS); } - neighbours.record_mi_rect(leaf_mi, bw, bh, &[&luma_levels[..], &u_levels[..], &v_levels[..]]); + neighbours.record_mi_rect( + leaf_mi, + bw, + bh, + &[&luma_levels[..], &u_levels[..], &v_levels[..]], + ); neighbours.fill_skip_grid_rect(leaf_mi, mi_w, mi_h, skip); neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0, fctx); // The leaf's own palette state (`0` clears, as this site always did @@ -13749,7 +14970,14 @@ fn decode_leaf_rect( // entry for both leaves, and leaf 0 zeroing the LEFT one threw away the // real left neighbour leaf 1 reads (lane-kf900 r4). record_strip_palette( - neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, + neighbours, + pal_at, + bw, + bh, + pal_y_size, + pal_y_colors, + pal_uv_size, + pal_uv_colors, ); // A rect leaf spans mi_w x mi_h, so its mode reaches several columns and // rows -- record the whole span, not one cell. @@ -13793,7 +15021,8 @@ fn decode_block_rect4( enable_filter_intra: bool, allow_screen_content_tools: bool, base_q_idx: u8, - tx_select: bool, fctx: &crate::decode::FrameCtx, + tx_select: bool, + fctx: &crate::decode::FrameCtx, ) -> Result<(usize, usize)> { let _ = base_q_idx; let (mi_r, mi_c) = strip_mi; @@ -13848,17 +15077,28 @@ fn decode_block_rect4( Some((palette_ctx, &palette_cache)), &palette_uv_cache, mi_r, - mi_c, fctx, + mi_c, + fctx, )?; if let Some((dv_row, dv_col)) = intrabc { decode_intrabc_rect( - dec, cdfs, neighbours, strip_mi, (bw, bh), skip, (dv_row, dv_col), - y, u, v, base_q_idx, fctx, - )?; - return Ok((DC_PRED, DC_PRED)); - } - // lane-kf900 r4: palette prediction on this shape, exactly as - // [`decode_block_rect`] does one aspect ratio up -- the colour-index map + dec, + cdfs, + neighbours, + strip_mi, + (bw, bh), + skip, + (dv_row, dv_col), + y, + u, + v, + base_q_idx, + fctx, + )?; + return Ok((DC_PRED, DC_PRED)); + } + // lane-kf900 r4: palette prediction on this shape, exactly as + // [`decode_block_rect`] does one aspect ratio up -- the colour-index map // mapped through the base colours IS the prediction (it reads no edge // pixels), handed to each `reconstruct_rect` through [`set_palette_pred`]. if palette_y.is_some() || palette_uv.is_some() { @@ -13873,10 +15113,12 @@ fn decode_block_rect4( p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), ) }); - let (pal_y_size, pal_y_colors) = - palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); - let (pal_uv_size, pal_uv_colors) = - palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); + let (pal_y_size, pal_y_colors) = palette_y + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.colors)); + let (pal_uv_size, pal_uv_colors) = palette_uv + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); if smooth_neighbor { hit!(SMOOTH_LUMA_HITS); @@ -13930,7 +15172,8 @@ fn decode_block_rect4( neighbours, (mi_r, mi_c), depth_to_tx_wh(bw, bh, depth, fctx), - (bw, bh), fctx, + (bw, bh), + fctx, ); if depth != 0 || lossless(fctx) { // lane-rectsplitx r1: the per-transform-unit walk, at this strip's @@ -13981,10 +15224,17 @@ fn decode_block_rect4( u, v, base_q_idx, - false, fctx, + false, + fctx, )?; record_strip_palette( - neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, + neighbours, + pal_at, + bw, + bh, + pal_y_size, + pal_y_colors, + pal_uv_size, pal_uv_colors, ); if bw > bh { @@ -14038,8 +15288,7 @@ fn decode_block_rect4( // `TxbSet::Chroma16`). The caller set is closed -- this reader only // ever sees 32x8 / 8x32 luma and the sequence header admits ss 0/0 // and 1/1 only -- so the table is exhaustive. - let chroma422_rect32 = - (chroma_w, chroma_h) == (4, 32) && ss_x(fctx) == 1 && ss_y(fctx) == 0; + let chroma422_rect32 = (chroma_w, chroma_h) == (4, 32) && ss_x(fctx) == 1 && ss_y(fctx) == 0; let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (chroma_w, chroma_h) { (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]), (4, 16) => (TxbSet::Chroma8, &SCAN_4X16[..]), @@ -14069,12 +15318,8 @@ fn decode_block_rect4( // lane-av1-422p: the units' own set/scan -- the whole-rect read // below never sees this row, the `chroma422_rect32` arm chunks // first. Anything else is still a named-lane gap. - (4, 32) if ss_x(fctx) == 1 && ss_y(fctx) == 0 => { - (TxbSet::ChromaRect8x4, &SCAN_4X8[..]) - } - _ => unreachable!( - "decode_block_rect4 chroma shape set is closed: {chroma_w}x{chroma_h}" - ), + (4, 32) if ss_x(fctx) == 1 && ss_y(fctx) == 0 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), + _ => unreachable!("decode_block_rect4 chroma shape set is closed: {chroma_w}x{chroma_h}"), }; let luma_scan: &[u16] = if bw > bh { &SCAN_32X8 } else { &SCAN_8X32 }; let (luma_levels, u_levels, v_levels) = if skip { @@ -14112,12 +15357,13 @@ fn decode_block_rect4( plane_q_delta(0, fctx).0, plane_q_delta(0, fctx).1, luma_tx_type, - block_iqmatrix(fctx, 0, bw, bh, luma_tx_type), + block_iqmatrix(fctx, 0, bw, bh, luma_tx_type), ); if let Some(b) = &palette_y_buf { set_palette_pred(b.clone(), fctx); } - push_intra_rect(0, + push_intra_rect( + 0, px, py, bw, @@ -14128,7 +15374,8 @@ fn decode_block_rect4( &luma_residual, None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); // CfL parameters are computed ONCE per block over the strip's luma // (`are_parameters_computed`) and shared by all four units, as in @@ -14139,15 +15386,22 @@ fn decode_block_rect4( for unit_row in 0..4usize { let unit_mi = (mi_r + unit_row * 2, mi_c); let unit_reach = tu_reach_rect( - bw, bh, 0, unit_row * 8, 8, 8, reach, - px, py, y.width, y.height, fctx, + bw, + bh, + 0, + unit_row * 8, + 8, + 8, + reach, + px, + py, + y.width, + y.height, + fctx, ); if let Some((ub, vb)) = &palette_uv_bufs { let pbuf = if plane == 1 { ub } else { vb }; - set_palette_pred( - palette_window(pbuf, chroma_w, 0, unit_row * 8, 4, 8), - fctx, - ); + set_palette_pred(palette_window(pbuf, chroma_w, 0, unit_row * 8, 4, 8), fctx); } // Each unit is read and recorded IMMEDIATELY: unit row 0's // `txb_skip_ctx` still sees the real above/left neighbour @@ -14183,7 +15437,8 @@ fn decode_block_rect4( alpha .zip(ac) .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, )?; neighbours.record_mi_chroma(unit_mi, 8, 8, plane, &unit_grid); unit_grids.push((unit_mi, plane, unit_grid)); @@ -14207,7 +15462,13 @@ fn decode_block_rect4( neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip); neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0, fctx); record_strip_palette( - neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, + neighbours, + pal_at, + bw, + bh, + pal_y_size, + pal_y_colors, + pal_uv_size, pal_uv_colors, ); if bw > bh { @@ -14275,12 +15536,13 @@ fn decode_block_rect4( plane_q_delta(0, fctx).0, plane_q_delta(0, fctx).1, luma_tx_type, - block_iqmatrix(fctx, 0, bw, bh, luma_tx_type), + block_iqmatrix(fctx, 0, bw, bh, luma_tx_type), ); if let Some(b) = &palette_y_buf { set_palette_pred(b.clone(), fctx); } - push_intra_rect(0, + push_intra_rect( + 0, px, py, bw, @@ -14291,7 +15553,8 @@ fn decode_block_rect4( &luma_residual, None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); for (plane, _buf, levels, tx_type) in [ @@ -14307,12 +15570,13 @@ fn decode_block_rect4( plane_q_delta(plane, fctx).0, plane_q_delta(plane, fctx).1, tx_type, - block_iqmatrix(fctx, plane, chroma_w, chroma_h, tx_type), + block_iqmatrix(fctx, plane, chroma_w, chroma_h, tx_type), ); if let Some((ub, vb)) = &palette_uv_bufs { set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx); } - push_intra_rect(plane, + push_intra_rect( + plane, cpx, cpy, chroma_w, @@ -14325,7 +15589,8 @@ fn decode_block_rect4( .zip(ac) .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); } neighbours.record_mi_rect( @@ -14337,7 +15602,13 @@ fn decode_block_rect4( neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip); neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0, fctx); record_strip_palette( - neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, + neighbours, + pal_at, + bw, + bh, + pal_y_size, + pal_y_colors, + pal_uv_size, pal_uv_colors, ); if bw > bh { @@ -14357,7 +15628,8 @@ fn decode_block_rect4( if let Some(b) = &palette_y_buf { set_palette_pred(b.clone(), fctx); } - push_intra_rect(0, + push_intra_rect( + 0, px, py, bw, @@ -14368,7 +15640,8 @@ fn decode_block_rect4( &luma_levels, None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); if chroma422_rect32 { @@ -14381,17 +15654,25 @@ fn decode_block_rect4( for (plane, _buf) in [(1usize, &mut *u), (2usize, &mut *v)] { for unit_row in 0..4usize { let unit_reach = tu_reach_rect( - bw, bh, 0, unit_row * 8, 8, 8, reach, - px, py, y.width, y.height, fctx, + bw, + bh, + 0, + unit_row * 8, + 8, + 8, + reach, + px, + py, + y.width, + y.height, + fctx, ); if let Some((ub, vb)) = &palette_uv_bufs { let pbuf = if plane == 1 { ub } else { vb }; - set_palette_pred( - palette_window(pbuf, chroma_w, 0, unit_row * 8, 4, 8), - fctx, - ); + set_palette_pred(palette_window(pbuf, chroma_w, 0, unit_row * 8, 4, 8), fctx); } - push_intra_rect(plane, + push_intra_rect( + plane, cpx, cpy + unit_row * 8, 4, @@ -14404,7 +15685,8 @@ fn decode_block_rect4( .zip(ac) .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); } } @@ -14412,7 +15694,8 @@ fn decode_block_rect4( if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - push_intra_rect(1, + push_intra_rect( + 1, cpx, cpy, chroma_w, @@ -14423,12 +15706,14 @@ fn decode_block_rect4( &u_levels, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - push_intra_rect(2, + push_intra_rect( + 2, cpx, cpy, chroma_w, @@ -14439,14 +15724,27 @@ fn decode_block_rect4( &v_levels, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); } - neighbours.record_mi_rect((mi_r, mi_c), bw, bh, &[&luma_levels[..], &u_levels[..], &v_levels[..]]); + neighbours.record_mi_rect( + (mi_r, mi_c), + bw, + bh, + &[&luma_levels[..], &u_levels[..], &v_levels[..]], + ); neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip); neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0, fctx); record_strip_palette( - neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, + neighbours, + pal_at, + bw, + bh, + pal_y_size, + pal_y_colors, + pal_uv_size, + pal_uv_colors, ); if bw > bh { hit!(RECT4_32_HORZ_HITS); @@ -14502,7 +15800,8 @@ fn decode_rect4_16( allow_screen_content_tools: bool, base_q_idx: u8, tx_select: bool, - reduced_tx_set: bool, fctx: &crate::decode::FrameCtx, + reduced_tx_set: bool, + fctx: &crate::decode::FrameCtx, ) -> Result<()> { let (r, c) = at16; let (mi_row0, mi_col0) = (r * (SUB / MI), c * (SUB / MI)); @@ -14530,9 +15829,7 @@ fn decode_rect4_16( // every ss_x == 1 format -- the ODD strip closes the pair and reads // the chroma, exactly like 4:2:0. (VERT_4 partitions start on an // even mi_col, so `i % 2 == 1` is that clause.) - let has_chroma = i % 2 == 1 - || (horz && ss_y(fctx) == 0) - || (!horz && ss_x(fctx) == 0); + let has_chroma = i % 2 == 1 || (horz && ss_y(fctx) == 0) || (!horz && ss_x(fctx) == 0); let (mode, uv, _tx) = decode_rect4_16_strip( dec, cdfs, @@ -14548,7 +15845,8 @@ fn decode_rect4_16( allow_screen_content_tools, base_q_idx, tx_select, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )?; if let Some(m) = uv { last_uv_mode = m; @@ -14613,17 +15911,50 @@ fn decode_intrabc_owned_rect( // `read_block_tx_size_rect` keys on this cell. A key frame forces it // false; the real bit is the caller's `tx_select`. Restored before return. fctx.tx_select_inter.with(|c| c.set(tx_select)); - let restore = ReducedTxRestore { fctx, saved_reduced, saved_tx }; + let restore = ReducedTxRestore { + fctx, + saved_reduced, + saved_tx, + }; flush_recon(fctx, y, u, v); let pred_y = predict_intrabc_window(y, px, py, bw, bh, dv_col, dv_row, true, side, fctx); - let pred_u = predict_intrabc_window(u, px / 2, py / 2, cw, ch, dv_col, dv_row, false, cside, fctx); - let pred_v = predict_intrabc_window(v, px / 2, py / 2, cw, ch, dv_col, dv_row, false, cside, fctx); + let pred_u = predict_intrabc_window( + u, + px / 2, + py / 2, + cw, + ch, + dv_col, + dv_row, + false, + cside, + fctx, + ); + let pred_v = predict_intrabc_window( + v, + px / 2, + py / 2, + cw, + ch, + dv_col, + dv_row, + false, + cside, + fctx, + ); let mi_cols = 2 * y.true_width.div_ceil(8); let mi_rows = 2 * y.true_height.div_ceil(8); let leaves = read_block_tx_size_rect( - dec, cdfs, neighbours, (mi_r, mi_c), (bw, bh), (mi_cols, mi_rows), skip, fctx, + dec, + cdfs, + neighbours, + (mi_r, mi_c), + (bw, bh), + (mi_cols, mi_rows), + skip, + fctx, )?; let mut luma_tx_type = TxType::DctDct; let luma_grid; @@ -14632,9 +15963,39 @@ fn decode_intrabc_owned_rect( if skip { // `reconstruct_mc_rect` indexes the residual at the square stride. // `bw * bh` underruns on a VERT strip (8x16: stride 16, 16 rows, index 136). - push_mc_rect(0, px, py, side, bw, bh, Pred::Inline(&pred_y, side), &ZERO_RESIDUAL[..side * bh], fctx); - push_mc_rect(1, px / 2, py / 2, cside, cw, ch, Pred::Inline(&pred_u, cside), &ZERO_RESIDUAL[..cside * ch], fctx); - push_mc_rect(2, px / 2, py / 2, cside, cw, ch, Pred::Inline(&pred_v, cside), &ZERO_RESIDUAL[..cside * ch], fctx); + push_mc_rect( + 0, + px, + py, + side, + bw, + bh, + Pred::Inline(&pred_y, side), + &ZERO_RESIDUAL[..side * bh], + fctx, + ); + push_mc_rect( + 1, + px / 2, + py / 2, + cside, + cw, + ch, + Pred::Inline(&pred_u, cside), + &ZERO_RESIDUAL[..cside * ch], + fctx, + ); + push_mc_rect( + 2, + px / 2, + py / 2, + cside, + cw, + ch, + Pred::Inline(&pred_v, cside), + &ZERO_RESIDUAL[..cside * ch], + fctx, + ); if let Some(ls) = leaves.as_ref() { // libaom `av1_reset_entropy_context` (`if (mbmi->skip_txfm)`, // decodeframe.c:1262 -> blockd.c:58): a SKIPPED block zeroes its @@ -14669,15 +16030,40 @@ fn decode_intrabc_owned_rect( let tu_pred = Pred::Inline(&pred_y, side).offset(row * MI * side + col * MI); let (g, tt) = if tw == th { read_inter_plane( - dec, cdfs, inter_txbset_for(tw, reduced_tx_set), &default_scan(tw.min(32)), - 0, neighbours.around_mi(tu_mi, tw)[0], 0, y, tu_px, tu_py, tw, base_q_idx, - tu_pred, None, Some(neighbours.luma_skip_ctx(tu_mi, tw / MI)), fctx, + dec, + cdfs, + inter_txbset_for(tw, reduced_tx_set), + &default_scan(tw.min(32)), + 0, + neighbours.around_mi(tu_mi, tw)[0], + 0, + y, + tu_px, + tu_py, + tw, + base_q_idx, + tu_pred, + None, + Some(neighbours.luma_skip_ctx(tu_mi, tw / MI)), + fctx, )? } else { read_inter_plane_rect( - dec, cdfs, rect_inter_luma_set(tw, th, fctx)?, (tw, th), side, 0, - neighbours.around_mi_rect(tu_mi, tw, th)[0], 0, y, tu_px, tu_py, tu_pred, - None, Some(neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI)), fctx, + dec, + cdfs, + rect_inter_luma_set(tw, th, fctx)?, + (tw, th), + side, + 0, + neighbours.around_mi_rect(tu_mi, tw, th)[0], + 0, + y, + tu_px, + tu_py, + tu_pred, + None, + Some(neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI)), + fctx, )? }; if idx == 0 { @@ -14685,51 +16071,152 @@ fn decode_intrabc_owned_rect( } neighbours.record_mi_luma_rect(tu_mi, tw, th, &g); if tw != th { - neighbours.fill_lf_grid_leaf_luma((tu_mi.0, tu_mi.1), tw / MI, th / MI, tw as u8, th as u8); + neighbours.fill_lf_grid_leaf_luma( + (tu_mi.0, tu_mi.1), + tw / MI, + th / MI, + tw as u8, + th as u8, + ); } } luma_grid = Grid::Zero(side * side); let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); let (ug, _) = read_inter_plane_rect( - dec, cdfs, rect_inter_chroma_set(cw, ch)?, (cw, ch), cside, 1, around[1], 0, - u, px / 2, py / 2, Pred::Inline(&pred_u, cside), Some(luma_tx_type), None, fctx, + dec, + cdfs, + rect_inter_chroma_set(cw, ch)?, + (cw, ch), + cside, + 1, + around[1], + 0, + u, + px / 2, + py / 2, + Pred::Inline(&pred_u, cside), + Some(luma_tx_type), + None, + fctx, )?; let (vg, _) = read_inter_plane_rect( - dec, cdfs, rect_inter_chroma_set(cw, ch)?, (cw, ch), cside, 2, around[2], 0, - v, px / 2, py / 2, Pred::Inline(&pred_v, cside), Some(luma_tx_type), None, fctx, + dec, + cdfs, + rect_inter_chroma_set(cw, ch)?, + (cw, ch), + cside, + 2, + around[2], + 0, + v, + px / 2, + py / 2, + Pred::Inline(&pred_v, cside), + Some(luma_tx_type), + None, + fctx, )?; u_grid = ug; v_grid = vg; } else { let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); let (g, tt) = read_inter_plane_rect( - dec, cdfs, rect_inter_luma_set(bw, bh, fctx)?, (bw, bh), side, 0, around[0], 0, - y, px, py, Pred::Inline(&pred_y, side), None, None, fctx, + dec, + cdfs, + rect_inter_luma_set(bw, bh, fctx)?, + (bw, bh), + side, + 0, + around[0], + 0, + y, + px, + py, + Pred::Inline(&pred_y, side), + None, + None, + fctx, )?; luma_tx_type = tt; luma_grid = g; let (ug, _) = read_inter_plane_rect( - dec, cdfs, rect_inter_chroma_set(cw, ch)?, (cw, ch), cside, 1, around[1], 0, - u, px / 2, py / 2, Pred::Inline(&pred_u, cside), Some(luma_tx_type), None, fctx, + dec, + cdfs, + rect_inter_chroma_set(cw, ch)?, + (cw, ch), + cside, + 1, + around[1], + 0, + u, + px / 2, + py / 2, + Pred::Inline(&pred_u, cside), + Some(luma_tx_type), + None, + fctx, )?; let (vg, _) = read_inter_plane_rect( - dec, cdfs, rect_inter_chroma_set(cw, ch)?, (cw, ch), cside, 2, around[2], 0, - v, px / 2, py / 2, Pred::Inline(&pred_v, cside), Some(luma_tx_type), None, fctx, + dec, + cdfs, + rect_inter_chroma_set(cw, ch)?, + (cw, ch), + cside, + 2, + around[2], + 0, + v, + px / 2, + py / 2, + Pred::Inline(&pred_v, cside), + Some(luma_tx_type), + None, + fctx, )?; u_grid = ug; v_grid = vg; } drop(restore); if leaves.is_some() { - neighbours.record_split_luma_rect_mi((mi_r, mi_c), bw, bh, DC_PRED, DC_PRED, [&u_grid, &v_grid]); + neighbours.record_split_luma_rect_mi( + (mi_r, mi_c), + bw, + bh, + DC_PRED, + DC_PRED, + [&u_grid, &v_grid], + ); } else { - neighbours.record_rect_mi((mi_r, mi_c), bw, bh, DC_PRED, DC_PRED, &[&luma_grid, &u_grid, &v_grid]); + neighbours.record_rect_mi( + (mi_r, mi_c), + bw, + bh, + DC_PRED, + DC_PRED, + &[&luma_grid, &u_grid, &v_grid], + ); } neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, 0, [0u16; 8]); neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, 0, [0u16; 8]); neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); - neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, bw.min(64) as u8, bh.min(64) as u8, 0, fctx); - record_intrabc_mi_rect(mi_r, mi_c, bw / MI, bh / MI, Some((dv_row, dv_col)), neighbours, fctx); + neighbours.fill_lf_grid_rect( + (mi_r, mi_c), + bw / MI, + bh / MI, + bw.min(64) as u8, + bh.min(64) as u8, + 0, + fctx, + ); + record_intrabc_mi_rect( + mi_r, + mi_c, + bw / MI, + bh / MI, + Some((dv_row, dv_col)), + neighbours, + fctx, + ); let _ = luma_tx_type; Ok(()) } @@ -14748,9 +16235,17 @@ fn predict_intrabc_window( ) -> Vec { let mut dense = vec![0u16; w * h]; mc::predict_with_filter( - &plane.data, plane.width, plane.true_width, plane.true_height, - mv_to_q4(px, dv_col, if luma { 0 } else { ss_x(fctx) }), mv_to_q4(py, dv_row, if luma { 0 } else { ss_y(fctx) }), - w, h, mc::InterpFilterKind::Bilinear, &mut dense, fctx, + &plane.data, + plane.width, + plane.true_width, + plane.true_height, + mv_to_q4(px, dv_col, if luma { 0 } else { ss_x(fctx) }), + mv_to_q4(py, dv_row, if luma { 0 } else { ss_y(fctx) }), + w, + h, + mc::InterpFilterKind::Bilinear, + &mut dense, + fctx, ); let mut laid = vec![0u16; stride * stride]; for row in 0..h { @@ -14766,7 +16261,9 @@ struct ReducedTxRestore<'a> { } impl Drop for ReducedTxRestore<'_> { fn drop(&mut self) { - self.fctx.reduced_tx_set_inter.with(|c| c.set(self.saved_reduced)); + self.fctx + .reduced_tx_set_inter + .with(|c| c.set(self.saved_reduced)); self.fctx.tx_select_inter.with(|c| c.set(self.saved_tx)); } } @@ -14821,9 +16318,17 @@ fn decode_rect4_16_intrabc( flush_recon(fctx, y, u, v); let mut pred_y_dense = vec![0u16; bw * bh]; mc::predict_with_filter( - &y.data, y.width, y.true_width, y.true_height, - mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0), - bw, bh, mc::InterpFilterKind::Bilinear, &mut pred_y_dense, fctx, + &y.data, + y.width, + y.true_width, + y.true_height, + mv_to_q4(px, dv_col, 0), + mv_to_q4(py, dv_row, 0), + bw, + bh, + mc::InterpFilterKind::Bilinear, + &mut pred_y_dense, + fctx, ); let mut pred_y = vec![0u16; side * side]; for row in 0..bh { @@ -14833,7 +16338,11 @@ fn decode_rect4_16_intrabc( let (pw, ph) = if horz { (16usize, 8usize) } else { (8, 16) }; let (cw, ch) = (pw / 2, ph / 2); let pair_mi = if has_chroma { - if horz { (lmi.0 - 1, lmi.1) } else { (lmi.0, lmi.1 - 1) } + if horz { + (lmi.0 - 1, lmi.1) + } else { + (lmi.0, lmi.1 - 1) + } } else { lmi }; @@ -14846,9 +16355,17 @@ fn decode_rect4_16_intrabc( let (pred_u, pred_v) = if has_chroma { let mut ud = vec![0u16; cw * ch]; mc::predict_with_filter( - &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), - cw, ch, mc::InterpFilterKind::Bilinear, &mut ud, fctx, + &u.data, + u.width, + u.true_width, + u.true_height, + mv_to_q4(cpx, dv_col, ss_x(fctx)), + mv_to_q4(cpy, dv_row, ss_y(fctx)), + cw, + ch, + mc::InterpFilterKind::Bilinear, + &mut ud, + fctx, ); let mut us = vec![0u16; cside * cside]; for row in 0..ch { @@ -14856,9 +16373,17 @@ fn decode_rect4_16_intrabc( } let mut vd = vec![0u16; cw * ch]; mc::predict_with_filter( - &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), - cw, ch, mc::InterpFilterKind::Bilinear, &mut vd, fctx, + &v.data, + v.width, + v.true_width, + v.true_height, + mv_to_q4(cpx, dv_col, ss_x(fctx)), + mv_to_q4(cpy, dv_row, ss_y(fctx)), + cw, + ch, + mc::InterpFilterKind::Bilinear, + &mut vd, + fctx, ); let mut vs = vec![0u16; cside * cside]; for row in 0..ch { @@ -14898,7 +16423,9 @@ fn decode_rect4_16_intrabc( let (rng, _) = dec.debug_state(); eprintln!( "EC_ISTEP mi_row={} mi_col={} name=txfm_split_rect val={} ctx={ctx} rng={rng}", - lmi.0, lmi.1, u8::from(split) + lmi.0, + lmi.1, + u8::from(split) ); } if !split { @@ -14913,15 +16440,27 @@ fn decode_rect4_16_intrabc( for row in (0..bh / MI).step_by(sub_h / MI) { for col in (0..bw / MI).step_by(sub_w / MI) { read_var_tx_size( - dec, cdfs, neighbours, lmi, side, (max_w_mi, max_h_mi), - (sub_w, sub_h), 1, row, col, &mut out, + dec, + cdfs, + neighbours, + lmi, + side, + (max_w_mi, max_h_mi), + (sub_w, sub_h), + 1, + row, + col, + &mut out, ); } } Some(out) } }; - let (tx_w, tx_h) = leaves.as_ref().and_then(|ls| ls.first()).map_or((bw, bh), |l| (l.2, l.3)); + let (tx_w, tx_h) = leaves + .as_ref() + .and_then(|ls| ls.first()) + .map_or((bw, bh), |l| (l.2, l.3)); let mut luma_tx_type = TxType::DctDct; let luma_grid; @@ -14931,17 +16470,39 @@ fn decode_rect4_16_intrabc( if skip { push_mc_rect( - 0, px, py, side, bw, bh, Pred::Inline(&pred_y, side), &ZERO_RESIDUAL[..side * bh], fctx, + 0, + px, + py, + side, + bw, + bh, + Pred::Inline(&pred_y, side), + &ZERO_RESIDUAL[..side * bh], + fctx, ); luma_grid = Grid::Zero(bw * bh); if has_chroma { push_mc_rect( - 1, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_u, cside), - &ZERO_RESIDUAL[..cside * ch], fctx, + 1, + cpx, + cpy, + cside, + cw, + ch, + Pred::Inline(&pred_u, cside), + &ZERO_RESIDUAL[..cside * ch], + fctx, ); push_mc_rect( - 2, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_v, cside), - &ZERO_RESIDUAL[..cside * ch], fctx, + 2, + cpx, + cpy, + cside, + cw, + ch, + Pred::Inline(&pred_v, cside), + &ZERO_RESIDUAL[..cside * ch], + fctx, ); } chroma_stamped_per_unit = false; @@ -14952,11 +16513,26 @@ fn decode_rect4_16_intrabc( let (tu_px, tu_py) = (px + col * MI, py + row * MI); let tu_pred = Pred::Inline(&pred_y, side).offset(row * MI * side + col * MI); let (g, _) = read_inter_plane( - dec, cdfs, - if reduced_tx_set { TxbSet::Luma4Inter } else { TxbSet::Luma4InterSet1 }, - &default_scan(4), 0, neighbours.around_mi(tu_mi, 4)[0], 0, - y, tu_px, tu_py, 4, base_q_idx, tu_pred, None, - Some(neighbours.luma_skip_ctx(tu_mi, 1)), fctx, + dec, + cdfs, + if reduced_tx_set { + TxbSet::Luma4Inter + } else { + TxbSet::Luma4InterSet1 + }, + &default_scan(4), + 0, + neighbours.around_mi(tu_mi, 4)[0], + 0, + y, + tu_px, + tu_py, + 4, + base_q_idx, + tu_pred, + None, + Some(neighbours.luma_skip_ctx(tu_mi, 1)), + fctx, )?; neighbours.record_mi_luma_rect(tu_mi, 4, 4, &g); } @@ -14967,16 +16543,40 @@ fn decode_rect4_16_intrabc( let tu_pred = Pred::Inline(&pred_y, side).offset(row * MI * side + col * MI); let (g, tt) = if tw == th { read_inter_plane( - dec, cdfs, inter_txbset_for(tw, reduced_tx_set), - &default_scan(tw.min(32)), 0, neighbours.around_mi(tu_mi, tw)[0], 0, - y, tu_px, tu_py, tw, base_q_idx, tu_pred, None, - Some(neighbours.luma_skip_ctx(tu_mi, tw / MI)), fctx, + dec, + cdfs, + inter_txbset_for(tw, reduced_tx_set), + &default_scan(tw.min(32)), + 0, + neighbours.around_mi(tu_mi, tw)[0], + 0, + y, + tu_px, + tu_py, + tw, + base_q_idx, + tu_pred, + None, + Some(neighbours.luma_skip_ctx(tu_mi, tw / MI)), + fctx, )? } else { read_inter_plane_rect( - dec, cdfs, rect_inter_luma_set(tw, th, fctx)?, (tw, th), side, 0, - neighbours.around_mi_rect(tu_mi, tw, th)[0], 0, y, tu_px, tu_py, tu_pred, - None, Some(neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI)), fctx, + dec, + cdfs, + rect_inter_luma_set(tw, th, fctx)?, + (tw, th), + side, + 0, + neighbours.around_mi_rect(tu_mi, tw, th)[0], + 0, + y, + tu_px, + tu_py, + tu_pred, + None, + Some(neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI)), + fctx, )? }; if idx == 0 { @@ -14990,31 +16590,92 @@ fn decode_rect4_16_intrabc( if has_chroma && lossless(fctx) { let (mut uo, mut vo) = (Vec::new(), Vec::new()); read_inter_chroma_lossless( - dec, cdfs, neighbours, u, v, - Pred::Inline(&pred_u, cside), Pred::Inline(&pred_v, cside), - pair_mi, (cpx, cpy), (0, 0), (cw, ch), (cw, ch), cside, 0, base_q_idx, - &mut uo, &mut vo, fctx, + dec, + cdfs, + neighbours, + u, + v, + Pred::Inline(&pred_u, cside), + Pred::Inline(&pred_v, cside), + pair_mi, + (cpx, cpy), + (0, 0), + (cw, ch), + (cw, ch), + cside, + 0, + base_q_idx, + &mut uo, + &mut vo, + fctx, )?; - u_grid = if uo.is_empty() { Grid::Zero(cw * ch) } else { Grid::Own(uo) }; - v_grid = if vo.is_empty() { Grid::Zero(cw * ch) } else { Grid::Own(vo) }; + u_grid = if uo.is_empty() { + Grid::Zero(cw * ch) + } else { + Grid::Own(uo) + }; + v_grid = if vo.is_empty() { + Grid::Zero(cw * ch) + } else { + Grid::Own(vo) + }; } else if has_chroma { let around = neighbours.around_mi_rect(pair_mi, pw, ph); let (ug, _) = read_inter_plane_rect( - dec, cdfs, rect_inter_chroma_set(cw, ch)?, (cw, ch), cside, 1, around[1], 0, - u, cpx, cpy, Pred::Inline(&pred_u, cside), Some(luma_tx_type), None, fctx, + dec, + cdfs, + rect_inter_chroma_set(cw, ch)?, + (cw, ch), + cside, + 1, + around[1], + 0, + u, + cpx, + cpy, + Pred::Inline(&pred_u, cside), + Some(luma_tx_type), + None, + fctx, )?; u_grid = ug; let (vg, _) = read_inter_plane_rect( - dec, cdfs, rect_inter_chroma_set(cw, ch)?, (cw, ch), cside, 2, around[2], 0, - v, cpx, cpy, Pred::Inline(&pred_v, cside), Some(luma_tx_type), None, fctx, + dec, + cdfs, + rect_inter_chroma_set(cw, ch)?, + (cw, ch), + cside, + 2, + around[2], + 0, + v, + cpx, + cpy, + Pred::Inline(&pred_v, cside), + Some(luma_tx_type), + None, + fctx, )?; v_grid = vg; } } else { let around = neighbours.around_mi_rect(lmi, bw, bh); let (g, tt) = read_inter_plane_rect( - dec, cdfs, rect_inter_luma_set(bw, bh, fctx)?, (bw, bh), side, 0, around[0], 0, - y, px, py, Pred::Inline(&pred_y, side), None, None, fctx, + dec, + cdfs, + rect_inter_luma_set(bw, bh, fctx)?, + (bw, bh), + side, + 0, + around[0], + 0, + y, + px, + py, + Pred::Inline(&pred_y, side), + None, + None, + fctx, )?; luma_tx_type = tt; luma_grid = g; @@ -15022,13 +16683,39 @@ fn decode_rect4_16_intrabc( if has_chroma { let around = neighbours.around_mi_rect(pair_mi, pw, ph); let (ug, _) = read_inter_plane_rect( - dec, cdfs, rect_inter_chroma_set(cw, ch)?, (cw, ch), cside, 1, around[1], 0, - u, cpx, cpy, Pred::Inline(&pred_u, cside), Some(luma_tx_type), None, fctx, + dec, + cdfs, + rect_inter_chroma_set(cw, ch)?, + (cw, ch), + cside, + 1, + around[1], + 0, + u, + cpx, + cpy, + Pred::Inline(&pred_u, cside), + Some(luma_tx_type), + None, + fctx, )?; u_grid = ug; let (vg, _) = read_inter_plane_rect( - dec, cdfs, rect_inter_chroma_set(cw, ch)?, (cw, ch), cside, 2, around[2], 0, - v, cpx, cpy, Pred::Inline(&pred_v, cside), Some(luma_tx_type), None, fctx, + dec, + cdfs, + rect_inter_chroma_set(cw, ch)?, + (cw, ch), + cside, + 2, + around[2], + 0, + v, + cpx, + cpy, + Pred::Inline(&pred_v, cside), + Some(luma_tx_type), + None, + fctx, )?; v_grid = vg; } @@ -15093,7 +16780,13 @@ fn decode_rect4_16_intrabc( txfm_partition_update_rect(neighbours, lmi, (tx_w, tx_h), (bw, bh)); } record_intrabc_mi_rect( - lmi.0, lmi.1, mi_w, mi_h, Some((dv_row, dv_col)), neighbours, fctx, + lmi.0, + lmi.1, + mi_w, + mi_h, + Some((dv_row, dv_col)), + neighbours, + fctx, ); Ok((DC_PRED, last_uv, (tx_w, tx_h))) } @@ -15129,242 +16822,283 @@ fn decode_rect4_16_strip( allow_screen_content_tools: bool, base_q_idx: u8, tx_select: bool, - reduced_tx_set: bool, fctx: &crate::decode::FrameCtx, + reduced_tx_set: bool, + fctx: &crate::decode::FrameCtx, ) -> Result<(usize, Option, (usize, usize))> { let (r, c) = (lmi.0 / (SUB / MI), lmi.1 / (SUB / MI)); let (bw, bh) = if horz { (16usize, 4usize) } else { (4, 16) }; let (mi_w, mi_h) = (bw / MI, bh / MI); let scan: &[u16] = if horz { &SCAN_16X4 } else { &SCAN_4X16 }; let mut last_uv_mode: Option = None; - // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell - // aliases all four strips onto one entry, so the mi-exact map wins and - // the previous strip stands in on the split axis. - let mut above_mode = neighbours.above_mode[c]; - let mut left_mode = neighbours.left_mode[r]; - if let Some(((pr, pc), pmode)) = prev { - if pc == lmi.1 && lmi.0 == pr + mi_h { - above_mode = pmode; - } else if pr == lmi.0 && lmi.1 == pc + mi_w { - left_mode = pmode; - } + // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell + // aliases all four strips onto one entry, so the mi-exact map wins and + // the previous strip stands in on the split axis. + let mut above_mode = neighbours.above_mode[c]; + let mut left_mode = neighbours.left_mode[r]; + if let Some(((pr, pc), pmode)) = prev { + if pc == lmi.1 && lmi.0 == pr + mi_h { + above_mode = pmode; + } else if pr == lmi.0 && lmi.1 == pc + mi_w { + left_mode = pmode; } - let (above_mode, left_mode) = - neighbours.modes_above_left_mi(lmi.0, lmi.1, (above_mode, left_mode)); - // lane-kf900 r4: the strip's real palette ctx + colour cache (see - // [`decode_block_rect4`]); `None`/`&[]` here read `palette_y_mode` - // off CDF row 0 and every cache hit off an empty cache. - let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(lmi); - let palette_uv_cache = neighbours.palette_uv_cache_mi(lmi); - let ( - skip, - mode, - angle_delta_y, - uv_mode, - angle_delta_uv, - alpha, - filter_intra, - palette_y, - palette_uv, - intrabc, - ) = read_intra_mode_rect( + } + let (above_mode, left_mode) = + neighbours.modes_above_left_mi(lmi.0, lmi.1, (above_mode, left_mode)); + // lane-kf900 r4: the strip's real palette ctx + colour cache (see + // [`decode_block_rect4`]); `None`/`&[]` here read `palette_y_mode` + // off CDF row 0 and every cache hit off an empty cache. + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(lmi); + let palette_uv_cache = neighbours.palette_uv_cache_mi(lmi); + let ( + skip, + mode, + angle_delta_y, + uv_mode, + angle_delta_uv, + alpha, + filter_intra, + palette_y, + palette_uv, + intrabc, + ) = read_intra_mode_rect( + dec, + cdfs, + above_mode, + left_mode, + true, + has_chroma, + bw, + bh, + enable_filter_intra, + neighbours.skip_txfm_ctx(lmi.0, lmi.1), + allow_screen_content_tools, + Some((palette_ctx, &palette_cache)), + &palette_uv_cache, + lmi.0, + lmi.1, + fctx, + )?; + if let Some(dv) = intrabc { + return decode_rect4_16_intrabc( dec, cdfs, - above_mode, - left_mode, - true, + neighbours, + lmi, + horz, has_chroma, - bw, - bh, - enable_filter_intra, - neighbours.skip_txfm_ctx(lmi.0, lmi.1), - allow_screen_content_tools, - Some((palette_ctx, &palette_cache)), - &palette_uv_cache, - lmi.0, - lmi.1, fctx, - )?; - if let Some(dv) = intrabc { - return decode_rect4_16_intrabc( - dec, cdfs, neighbours, lmi, horz, has_chroma, skip, dv, y, u, v, - base_q_idx, tx_select, reduced_tx_set, fctx, + skip, + dv, + y, + u, + v, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + ); + } + if palette_y.is_some() || palette_uv.is_some() { + hit!(RECT4_PALETTE_HITS); + } + // The colour-index map through the base colours IS the prediction. + // Chroma's map is the PAIR's 8x4 (4x8) block, matching the one + // chroma transform this closing strip codes. + let palette_y_buf: Option> = palette_y + .as_ref() + .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()); + let palette_uv_bufs: Option<(Vec, Vec)> = palette_uv.as_ref().map(|p| { + ( + p.map.iter().map(|&i| p.u_colors[i as usize]).collect(), + p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), + ) + }); + let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); + if smooth_neighbor { + hit!(SMOOTH_LUMA_HITS); + } + if filter_intra.is_some() { + hit!(FILTER_INTRA_RECT_HITS); + } + // `bsize_to_tx_size_cat(BLOCK_16X4)`: `max_txsize_rect_lookup` is + // TX_16X4 and `sub_tx_size_map` reaches TX_4X4 in two steps, so the + // depth symbol is the 3-symbol `tx_size_cat1` -- not the 2-symbol + // `cat0` a 4x8 leaf reads nor the `cat2` a 32x8 strip does. + // lane-av1mixloss: the lossless-segment early return + // (`decodeframe.c:1203`) precedes `TX_MODE_SELECT`, so a + // lossless-segment strip codes no depth symbol here either (class + // sweep of the sub8 leaf's fix). + let depth = if tx_select && !lossless(fctx) { + // lane-av1txbands: every frame reads the real `TXFM_CONTEXT` bands + // (`get_tx_size_context`, libaom `pred_common.h:342`). + let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh, fctx); + let d = dec.symbol(&mut cdfs.tx_size_cat1[ctx]); + if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { + eprintln!( + "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=1 rng={}", + lmi.0, + lmi.1, + dec.debug_state().0 ); } - if palette_y.is_some() || palette_uv.is_some() { - hit!(RECT4_PALETTE_HITS); - } - // The colour-index map through the base colours IS the prediction. - // Chroma's map is the PAIR's 8x4 (4x8) block, matching the one - // chroma transform this closing strip codes. - let palette_y_buf: Option> = palette_y - .as_ref() - .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()); - let palette_uv_bufs: Option<(Vec, Vec)> = palette_uv.as_ref().map(|p| { - ( - p.map.iter().map(|&i| p.u_colors[i as usize]).collect(), - p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), - ) - }); - let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); - if smooth_neighbor { - hit!(SMOOTH_LUMA_HITS); - } - if filter_intra.is_some() { - hit!(FILTER_INTRA_RECT_HITS); - } - // `bsize_to_tx_size_cat(BLOCK_16X4)`: `max_txsize_rect_lookup` is - // TX_16X4 and `sub_tx_size_map` reaches TX_4X4 in two steps, so the - // depth symbol is the 3-symbol `tx_size_cat1` -- not the 2-symbol - // `cat0` a 4x8 leaf reads nor the `cat2` a 32x8 strip does. - // lane-av1mixloss: the lossless-segment early return - // (`decodeframe.c:1203`) precedes `TX_MODE_SELECT`, so a - // lossless-segment strip codes no depth symbol here either (class - // sweep of the sub8 leaf's fix). - let depth = if tx_select && !lossless(fctx) { - // lane-av1txbands: every frame reads the real `TXFM_CONTEXT` bands - // (`get_tx_size_context`, libaom `pred_common.h:342`). - let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh, fctx); - let d = dec.symbol(&mut cdfs.tx_size_cat1[ctx]); - if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { - eprintln!( - "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=1 rng={}", - lmi.0, - lmi.1, - dec.debug_state().0 - ); - } - d - } else { - 0 - }; - if depth != 0 { - hit!(TX_DEPTH_HITS); - hit!(RECT4_16_SPLIT_HITS); - } - let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth, fctx); - let (px, py) = (lmi.1 * MI, lmi.0 * MI); - let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx); - neighbours.record_mode_mi(lmi.0, lmi.1, mi_w, mi_h, mode); - if depth != 0 || lossless(fctx) { - // [`decode_rect_split`]'s per-unit walk, inlined because the - // CHROMA of this shape belongs to the strip's 4:2:0 pair, not to - // the strip (that function codes one chroma transform per block). - // depth 1 is the 2:1 rect unit TX_8X4/TX_4X8 - // (`sub_tx_size_map[TX_16X4]`), depth 2 the square TX_4X4; each - // unit predicts off the units before it in raster order. - let rect_unit = tx_w != tx_h; - let zero_tu = vec![0i32; tx_w * tx_h]; - for tu_row in 0..bh / tx_h { - for tu_col in 0..bw / tx_w { - let tu_mi = (lmi.0 + tu_row * (tx_h / MI), lmi.1 + tu_col * (tx_w / MI)); - let (tu_px, tu_py) = (px + tu_col * tx_w, py + tu_row * tx_h); - let tu_reach = Reach::of_tu( - bw, - bh, - tu_col * tx_w, - tu_row * tx_h, + d + } else { + 0 + }; + if depth != 0 { + hit!(TX_DEPTH_HITS); + hit!(RECT4_16_SPLIT_HITS); + } + let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth, fctx); + let (px, py) = (lmi.1 * MI, lmi.0 * MI); + let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx); + neighbours.record_mode_mi(lmi.0, lmi.1, mi_w, mi_h, mode); + if depth != 0 || lossless(fctx) { + // [`decode_rect_split`]'s per-unit walk, inlined because the + // CHROMA of this shape belongs to the strip's 4:2:0 pair, not to + // the strip (that function codes one chroma transform per block). + // depth 1 is the 2:1 rect unit TX_8X4/TX_4X8 + // (`sub_tx_size_map[TX_16X4]`), depth 2 the square TX_4X4; each + // unit predicts off the units before it in raster order. + let rect_unit = tx_w != tx_h; + let zero_tu = vec![0i32; tx_w * tx_h]; + for tu_row in 0..bh / tx_h { + for tu_col in 0..bw / tx_w { + let tu_mi = (lmi.0 + tu_row * (tx_h / MI), lmi.1 + tu_col * (tx_w / MI)); + let (tu_px, tu_py) = (px + tu_col * tx_w, py + tu_row * tx_h); + let tu_reach = + Reach::of_tu(bw, bh, tu_col * tx_w, tu_row * tx_h, tx_w, tx_h, reach); + if let Some(b) = &palette_y_buf { + let tu_buf: Vec = (0..tx_h) + .flat_map(|i| { + let base = (tu_row * tx_h + i) * bw + tu_col * tx_w; + b[base..base + tx_w].iter().copied() + }) + .collect(); + set_palette_pred(tu_buf, fctx); + } + if skip { + push_intra_rect( + 0, + tu_px, + tu_py, tx_w, tx_h, - reach, + mode, + angle_delta_y, + tu_reach, + &zero_tu, + None, + filter_intra, + smooth_neighbor, + fctx, ); - if let Some(b) = &palette_y_buf { - let tu_buf: Vec = (0..tx_h) - .flat_map(|i| { - let base = (tu_row * tx_h + i) * bw + tu_col * tx_w; - b[base..base + tx_w].iter().copied() - }) - .collect(); - set_palette_pred(tu_buf, fctx); - } - if skip { - push_intra_rect(0, - tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &zero_tu, - None, filter_intra, smooth_neighbor, fctx, - ); - neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &zero_tu); - } else if rect_unit { - // `get_txsize_entropy_ctx(TX_8X4)` is the 8x8 class with - // 32 coded positions and the `TX_4X4` `tx_type` row: - // exactly [`TxbSet::LumaRect4x8`]. - let tu_around = neighbours.around_mi_rect(tu_mi, tx_w, tx_h)[0]; - let tu_skip_ctx = - neighbours.luma_skip_ctx_rect(tu_mi, tx_w / MI, tx_h / MI); - let set = if reduced_tx_set { - TxbSet::LumaRect4x8 - } else { - TxbSet::LumaRect4x8Set1 - }; - let tu_scan: &[u16] = if tx_w > tx_h { &SCAN_8X4 } else { &SCAN_4X8 }; - let mut coding = cdfs.txb(set, fi_tx_row(mode, filter_intra)); - let (tu_grid, tu_tx_type) = read_coeffs_rect( - dec, - &mut coding, - tu_scan, - tx_w, - tx_h, - tu_skip_ctx, - dc_sign_ctx(tu_around.2), - TxType::DctDct, - )?; - let residual = dequant_and_inverse_typed_wh( - &tu_grid, - tx_w, - tx_h, - crate::decode::bit_depth(fctx), - block_q_idx(fctx), - plane_q_delta(0, fctx).0, - plane_q_delta(0, fctx).1, - tu_tx_type, - block_iqmatrix(fctx, 0, tx_w, tx_h, tu_tx_type), - ); - push_intra_rect(0, - tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &residual, - None, filter_intra, smooth_neighbor, fctx, - ); - if tu_grid.iter().any(|&l| l != 0) { - hit!(RECT4_16_COEFF_HITS); - } - neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &tu_grid); + neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &zero_tu); + } else if rect_unit { + // `get_txsize_entropy_ctx(TX_8X4)` is the 8x8 class with + // 32 coded positions and the `TX_4X4` `tx_type` row: + // exactly [`TxbSet::LumaRect4x8`]. + let tu_around = neighbours.around_mi_rect(tu_mi, tx_w, tx_h)[0]; + let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tx_w / MI, tx_h / MI); + let set = if reduced_tx_set { + TxbSet::LumaRect4x8 } else { - let tu_around = neighbours.around_mi(tu_mi, tx_w)[0]; - let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_w / MI); - let tu_grid = read_plane( - dec, - cdfs, - txbset_for(tx_w, reduced_tx_set), - default_scan(tx_w), - 0, - tu_around, - mode, - mode, - angle_delta_y, - tu_reach, - y, - tu_px, - tu_py, - tx_w, - tx_w, - base_q_idx, - None, - filter_intra, - Some(tu_skip_ctx), - smooth_neighbor, fctx, - )?; - if tu_grid.iter().any(|&l| l != 0) { - hit!(RECT4_16_COEFF_HITS); - } - neighbours.record_mi_luma(tu_mi, tx_w, &tu_grid); + TxbSet::LumaRect4x8Set1 + }; + let tu_scan: &[u16] = if tx_w > tx_h { &SCAN_8X4 } else { &SCAN_4X8 }; + let mut coding = cdfs.txb(set, fi_tx_row(mode, filter_intra)); + let (tu_grid, tu_tx_type) = read_coeffs_rect( + dec, + &mut coding, + tu_scan, + tx_w, + tx_h, + tu_skip_ctx, + dc_sign_ctx(tu_around.2), + TxType::DctDct, + )?; + let residual = dequant_and_inverse_typed_wh( + &tu_grid, + tx_w, + tx_h, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(0, fctx).0, + plane_q_delta(0, fctx).1, + tu_tx_type, + block_iqmatrix(fctx, 0, tx_w, tx_h, tu_tx_type), + ); + push_intra_rect( + 0, + tu_px, + tu_py, + tx_w, + tx_h, + mode, + angle_delta_y, + tu_reach, + &residual, + None, + filter_intra, + smooth_neighbor, + fctx, + ); + if tu_grid.iter().any(|&l| l != 0) { + hit!(RECT4_16_COEFF_HITS); + } + neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &tu_grid); + } else { + let tu_around = neighbours.around_mi(tu_mi, tx_w)[0]; + let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_w / MI); + let tu_grid = read_plane( + dec, + cdfs, + txbset_for(tx_w, reduced_tx_set), + default_scan(tx_w), + 0, + tu_around, + mode, + mode, + angle_delta_y, + tu_reach, + y, + tu_px, + tu_py, + tx_w, + tx_w, + base_q_idx, + None, + filter_intra, + Some(tu_skip_ctx), + smooth_neighbor, + fctx, + )?; + if tu_grid.iter().any(|&l| l != 0) { + hit!(RECT4_16_COEFF_HITS); } + neighbours.record_mi_luma(tu_mi, tx_w, &tu_grid); } } - } else { + } + } else { let levels = if skip { let zeros = Grid::Zero(bw * bh); if let Some(b) = &palette_y_buf { set_palette_pred(b.clone(), fctx); } - push_intra_rect(0, - px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra, - smooth_neighbor, fctx, + push_intra_rect( + 0, + px, + py, + bw, + bh, + mode, + angle_delta_y, + reach, + &zeros, + None, + filter_intra, + smooth_neighbor, + fctx, ); zeros } else { @@ -15397,433 +17131,332 @@ fn decode_rect4_16_strip( plane_q_delta(0, fctx).0, plane_q_delta(0, fctx).1, tx_type, - block_iqmatrix(fctx, 0, bw, bh, tx_type), + block_iqmatrix(fctx, 0, bw, bh, tx_type), ); if let Some(b) = &palette_y_buf { set_palette_pred(b.clone(), fctx); } - push_intra_rect(0, - px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra, - smooth_neighbor, fctx, + push_intra_rect( + 0, + px, + py, + bw, + bh, + mode, + angle_delta_y, + reach, + &residual, + None, + filter_intra, + smooth_neighbor, + fctx, ); hit!(RECT4_16_COEFF_HITS); levels }; neighbours.record_mi_luma_rect(lmi, bw, bh, &levels); + } + neighbours.fill_skip_grid_rect(lmi, mi_w, mi_h, skip); + neighbours.fill_lf_grid_rect(lmi, mi_w, mi_h, tx_w as u8, tx_h as u8, 0, fctx); + // `update_partition_context` writes `partition_context_lookup[ + // BLOCK_16X4]` over the whole 16x16: full width above, a 4-px side on + // the left (mirrored under VERT_4). + for cell in 0..mi_w { + if let Some(slot) = neighbours.above_side_mi.get_mut(lmi.1 + cell) { + *slot = bw as u8; } - neighbours.fill_skip_grid_rect(lmi, mi_w, mi_h, skip); - neighbours.fill_lf_grid_rect(lmi, mi_w, mi_h, tx_w as u8, tx_h as u8, 0, fctx); - // `update_partition_context` writes `partition_context_lookup[ - // BLOCK_16X4]` over the whole 16x16: full width above, a 4-px side on - // the left (mirrored under VERT_4). - for cell in 0..mi_w { - if let Some(slot) = neighbours.above_side_mi.get_mut(lmi.1 + cell) { - *slot = bw as u8; - } - } - for cell in 0..mi_h { - if let Some(slot) = neighbours.left_side_mi.get_mut(lmi.0 + cell) { - *slot = bh as u8; - } + } + for cell in 0..mi_h { + if let Some(slot) = neighbours.left_side_mi.get_mut(lmi.0 + cell) { + *slot = bh as u8; } - if has_chroma { - hit!(RECT4_16_CHROMA_HITS); - // lane-av1-444: at 4:4:4 there is no pair -- every strip is its - // own chroma reference and codes its own 16x4 / 4x16 chroma - // block. (`set_mi_offsets`'s chroma snap is the zero offset at - // ss 0/0, so the neighbour reads below anchor at the strip.) - let (pair_mi, pw, ph) = if ss_x(fctx) == 0 && ss_y(fctx) == 0 { - (lmi, bw, bh) - } else if ss_y(fctx) == 0 && horz { - // lane-av1-422: chroma height is NOT subsampled, so a HORZ - // 16x4 strip is its own chroma reference (`is_chroma_reference` - // at ss(1,0): bh == 1 mi, so the row clause reduces to - // `!ss_y`) and codes its own `ss_size_lookup[BLOCK_16X4][1][0]` - // = BLOCK_8X4 chroma block -- a valid transform, no pair. - // (lane-av1-422o: a VERTICAL 4x16 strip now falls through to - // the pair merge below -- its own chroma block - // `ss_size_lookup[BLOCK_4X16][1][0]` is BLOCK_INVALID, the - // walk proved such leaves exist, and libaom codes the pair's - // chroma from the closing strip; the chunk lives in the - // `chroma422_pair16` arm below.) - (lmi, bw, bh) - } else if horz { - ((lmi.0 - 1, lmi.1), 16, 8) - } else { - ((lmi.0, lmi.1 - 1), 8, 16) - }; - let (ppx, ppy) = (pair_mi.1 * MI, pair_mi.0 * MI); - let (cpx, cpy) = (ppx >> ss_x(fctx), ppy >> ss_y(fctx)); - let (cw, ch) = (pw >> ss_x(fctx), ph >> ss_y(fctx)); - // lane-av1-422o: the 4:2:2 pair's chroma of a VERT 4x16 strip - // pair: (4, 16) at ss(1,0). The bsize is still BLOCK_4X16, whose - // `ss_size_lookup[..][1][0]` is BLOCK_INVALID, so libaom's - // `av1_get_tx_size` reads `max_txsize_rect_lookup[255]` -- the - // out-of-bounds byte is TX_4X8 in the pinned Release oracle, and - // `av1_get_adjusted_tx_size` has no TX_4X8 case to adjust it. - // `decode_token_recon_block` walks unit_width = - // ROUND_POWER_OF_TWO(1, 1) = 1, unit_height = 4, with stepr = - // tx_size_high_unit[TX_4X8] = 2: TWO TX_4X8 units per plane - // (chroma rows 0..8 and 8..16), plane-major. Even the skip arm - // walks per unit: `predict_and_reconstruct_intra_block` predicts - // every unit regardless of `skip_txfm`. - let chroma422_pair16 = (cw, ch) == (4, 16) && ss_x(fctx) == 1; - let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; - if (V_PRED..=D67_PRED).contains(&uv_predict_mode) { - hit!(RECT4_16_CHROMA_DIR_HITS); - } - let pair_reach = Reach::of_rect(pw, ph, ppx, ppy, y.width, y.height, fctx); - // lane-kf1200 r1: the chroma edge-filter type reads the neighbours - // of the CHROMA block, which for a 16x4/4x16 pair is `pair_mi`'s - // 16x8/8x16 region -- libaom builds `chroma_above_mbmi`/ - // `chroma_left_mbmi` from `mi[-((mi_row & ss_y) * stride + (mi_col - // & ss_x))]` (`set_mi_offsets`, av1/common/blockd.h ~1050), i.e. - // the pair's top-left luma mi, never this leaf's odd row/column. - // Reading `lmi` here named the leaf directly above (a non-chroma - // -reference 4-row block, `uv_mode == UV_DC_PRED`) and so lost a - // SMOOTH neighbour: filt_type 0 instead of 1 turned - // `av1_use_intra_edge_upsample` on (blk_wh 12 <= 16) for a - // directional chroma strip, moving 4 samples by 1. - let smooth_neighbor_uv = - neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c, fctx); - if smooth_neighbor_uv != neighbours.smooth_uv_neighbour_unsnapped(lmi.0, lmi.1, r, c) - { - hit!(RECT4_16_UV_PAIR_FILT_HITS); - } - // lane-av1-rect14: a lossless frame forces TX_4X4 on every plane - // (`av1_get_tx_size`, blockd.h:1381). The pair's chroma block is - // 8x4 (HORZ_4) or 4x8 (VERT_4) -- two TX_4X4s, plane-major - // (`decode_token_recon_block`), not one `ChromaRect8x4`. Reading - // the rect here consumed one symbol block too few and desynced - // the next strip's `skip` (measured: lossless sb128 320x240, - // mi(1,20) uv_mode matched, the following skip did not). - let lossless_pair = lossless(fctx); - let (u_levels, v_levels) = if lossless_pair { - hit!(RECT4_16_LOSSLESS_CHROMA_HITS); - if skip { - for plane in 1..3usize { - for rr in 0..ch / 4 { - for cc in 0..cw / 4 { - let (ox, oy) = (cc * 4, rr * 4); - let cu_reach = tu_reach( - pw, ph, ox * 2, oy * 2, 8, pair_reach, ppx, ppy, - y.width, y.height, fctx, - ); - if let Some((ub, vb)) = &palette_uv_bufs { - let buf = if plane == 1 { ub } else { vb }; - set_palette_pred(palette_window(buf, cw, ox, oy, 4, 4), fctx); - } - push_intra( - plane, cpx + ox, cpy + oy, 4, uv_predict_mode, - angle_delta_uv, cu_reach, &ZERO_RESIDUAL[..16], None, None, - smooth_neighbor_uv, fctx, - ); - let cu_mi = ( - pair_mi.0 + (oy << ss_y(fctx)) / MI, - pair_mi.1 + (ox << ss_x(fctx)) / MI, - ); - neighbours.record_mi_chroma( - cu_mi, - 4 << ss_x(fctx), - 4 << ss_y(fctx), - plane, - &ZERO_RESIDUAL[..16], - ); + } + if has_chroma { + hit!(RECT4_16_CHROMA_HITS); + // lane-av1-444: at 4:4:4 there is no pair -- every strip is its + // own chroma reference and codes its own 16x4 / 4x16 chroma + // block. (`set_mi_offsets`'s chroma snap is the zero offset at + // ss 0/0, so the neighbour reads below anchor at the strip.) + let (pair_mi, pw, ph) = if ss_x(fctx) == 0 && ss_y(fctx) == 0 { + (lmi, bw, bh) + } else if ss_y(fctx) == 0 && horz { + // lane-av1-422: chroma height is NOT subsampled, so a HORZ + // 16x4 strip is its own chroma reference (`is_chroma_reference` + // at ss(1,0): bh == 1 mi, so the row clause reduces to + // `!ss_y`) and codes its own `ss_size_lookup[BLOCK_16X4][1][0]` + // = BLOCK_8X4 chroma block -- a valid transform, no pair. + // (lane-av1-422o: a VERTICAL 4x16 strip now falls through to + // the pair merge below -- its own chroma block + // `ss_size_lookup[BLOCK_4X16][1][0]` is BLOCK_INVALID, the + // walk proved such leaves exist, and libaom codes the pair's + // chroma from the closing strip; the chunk lives in the + // `chroma422_pair16` arm below.) + (lmi, bw, bh) + } else if horz { + ((lmi.0 - 1, lmi.1), 16, 8) + } else { + ((lmi.0, lmi.1 - 1), 8, 16) + }; + let (ppx, ppy) = (pair_mi.1 * MI, pair_mi.0 * MI); + let (cpx, cpy) = (ppx >> ss_x(fctx), ppy >> ss_y(fctx)); + let (cw, ch) = (pw >> ss_x(fctx), ph >> ss_y(fctx)); + // lane-av1-422o: the 4:2:2 pair's chroma of a VERT 4x16 strip + // pair: (4, 16) at ss(1,0). The bsize is still BLOCK_4X16, whose + // `ss_size_lookup[..][1][0]` is BLOCK_INVALID, so libaom's + // `av1_get_tx_size` reads `max_txsize_rect_lookup[255]` -- the + // out-of-bounds byte is TX_4X8 in the pinned Release oracle, and + // `av1_get_adjusted_tx_size` has no TX_4X8 case to adjust it. + // `decode_token_recon_block` walks unit_width = + // ROUND_POWER_OF_TWO(1, 1) = 1, unit_height = 4, with stepr = + // tx_size_high_unit[TX_4X8] = 2: TWO TX_4X8 units per plane + // (chroma rows 0..8 and 8..16), plane-major. Even the skip arm + // walks per unit: `predict_and_reconstruct_intra_block` predicts + // every unit regardless of `skip_txfm`. + let chroma422_pair16 = (cw, ch) == (4, 16) && ss_x(fctx) == 1; + let uv_predict_mode = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; + if (V_PRED..=D67_PRED).contains(&uv_predict_mode) { + hit!(RECT4_16_CHROMA_DIR_HITS); + } + let pair_reach = Reach::of_rect(pw, ph, ppx, ppy, y.width, y.height, fctx); + // lane-kf1200 r1: the chroma edge-filter type reads the neighbours + // of the CHROMA block, which for a 16x4/4x16 pair is `pair_mi`'s + // 16x8/8x16 region -- libaom builds `chroma_above_mbmi`/ + // `chroma_left_mbmi` from `mi[-((mi_row & ss_y) * stride + (mi_col + // & ss_x))]` (`set_mi_offsets`, av1/common/blockd.h ~1050), i.e. + // the pair's top-left luma mi, never this leaf's odd row/column. + // Reading `lmi` here named the leaf directly above (a non-chroma + // -reference 4-row block, `uv_mode == UV_DC_PRED`) and so lost a + // SMOOTH neighbour: filt_type 0 instead of 1 turned + // `av1_use_intra_edge_upsample` on (blk_wh 12 <= 16) for a + // directional chroma strip, moving 4 samples by 1. + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c, fctx); + if smooth_neighbor_uv != neighbours.smooth_uv_neighbour_unsnapped(lmi.0, lmi.1, r, c) { + hit!(RECT4_16_UV_PAIR_FILT_HITS); + } + // lane-av1-rect14: a lossless frame forces TX_4X4 on every plane + // (`av1_get_tx_size`, blockd.h:1381). The pair's chroma block is + // 8x4 (HORZ_4) or 4x8 (VERT_4) -- two TX_4X4s, plane-major + // (`decode_token_recon_block`), not one `ChromaRect8x4`. Reading + // the rect here consumed one symbol block too few and desynced + // the next strip's `skip` (measured: lossless sb128 320x240, + // mi(1,20) uv_mode matched, the following skip did not). + let lossless_pair = lossless(fctx); + let (u_levels, v_levels) = if lossless_pair { + hit!(RECT4_16_LOSSLESS_CHROMA_HITS); + if skip { + for plane in 1..3usize { + for rr in 0..ch / 4 { + for cc in 0..cw / 4 { + let (ox, oy) = (cc * 4, rr * 4); + let cu_reach = tu_reach( + pw, + ph, + ox * 2, + oy * 2, + 8, + pair_reach, + ppx, + ppy, + y.width, + y.height, + fctx, + ); + if let Some((ub, vb)) = &palette_uv_bufs { + let buf = if plane == 1 { ub } else { vb }; + set_palette_pred(palette_window(buf, cw, ox, oy, 4, 4), fctx); } + push_intra( + plane, + cpx + ox, + cpy + oy, + 4, + uv_predict_mode, + angle_delta_uv, + cu_reach, + &ZERO_RESIDUAL[..16], + None, + None, + smooth_neighbor_uv, + fctx, + ); + let cu_mi = ( + pair_mi.0 + (oy << ss_y(fctx)) / MI, + pair_mi.1 + (ox << ss_x(fctx)) / MI, + ); + neighbours.record_mi_chroma( + cu_mi, + 4 << ss_x(fctx), + 4 << ss_y(fctx), + plane, + &ZERO_RESIDUAL[..16], + ); } } - (Grid::Zero(cw * ch), Grid::Zero(cw * ch)) - } else { - let scan4 = default_scan(4); - // `get_txb_ctx`: offset 10 (our tables store it at +3) - // when the plane block is larger than the transform. - let offset = Some(3usize); - let mut uo = vec![0i32; cw * ch]; - let mut vo = vec![0i32; cw * ch]; - for plane in 1..3usize { - for rr in 0..ch / 4 { - for cc in 0..cw / 4 { - let (ox, oy) = (cc * 4, rr * 4); - if cpx + ox >= u.true_width || cpy + oy >= u.true_height { - continue; - } - // The unit's stamp is its own span: aom - // `av1_set_entropy_contexts` (blockd.c:29) - // memsets exactly `tx_size_wide_unit` x - // `tx_size_high_unit` cells at the unit's own - // `(aoff, loff)` -- for TX_4X4 ONE above cell - // and ONE left cell. `(oy / 2, ox / 2)` + - // `(8, 8)` is the 4:2:0 subsampled form (one - // chroma cell = 8 luma px = 2 mi cells); at - // 4:4:4 a unit is ONE mi cell, and the 2x2 - // smear let a 4-wide strip's later units - // overwrite the NEXT COLUMN's above cell with - // their own state -- a column aom never sees - // this block write -- so the following block's - // `all_zero` read the wrong `txb_skip` row - // (frame-0 read #452, the llkf named gap). - let cu_mi = ( - pair_mi.0 + (oy << ss_y(fctx)) / MI, - pair_mi.1 + (ox << ss_x(fctx)) / MI, - ); - // One luma-mi cell: the chroma entropy arrays - // are subsampled, and our bands replicate that - // one entry over the unit's two cells - // (`read_intra_chroma_lossless`). - let cu_around = neighbours.around_mi(cu_mi, MI); - let cu_reach = tu_reach( - pw, ph, ox * 2, oy * 2, 8, pair_reach, ppx, ppy, - y.width, y.height, fctx, - ); - if let Some((ub, vb)) = &palette_uv_bufs { - let buf = if plane == 1 { ub } else { vb }; - set_palette_pred(palette_window(buf, cw, ox, oy, 4, 4), fctx); - } - let buf: &mut PlaneBuf<'static> = - if plane == 1 { &mut *u } else { &mut *v }; - let cu_grid = read_plane( - dec, cdfs, TxbSet::Chroma4, &scan4, plane, - cu_around[plane], mode, uv_predict_mode, angle_delta_uv, - cu_reach, buf, cpx + ox, cpy + oy, 4, 4, base_q_idx, - None, None, offset, smooth_neighbor_uv, fctx, - )?; - neighbours.record_mi_chroma( - cu_mi, - 4 << ss_x(fctx), - 4 << ss_y(fctx), - plane, - &cu_grid, - ); - hit!(CHROMA_SPLIT_TX_HITS); - let dst = if plane == 1 { &mut uo } else { &mut vo }; - for row in 0..4 { - let start = (oy + row) * cw + ox; - dst[start..start + 4] - .copy_from_slice(&cu_grid[row * 4..][..4]); - } + } + (Grid::Zero(cw * ch), Grid::Zero(cw * ch)) + } else { + let scan4 = default_scan(4); + // `get_txb_ctx`: offset 10 (our tables store it at +3) + // when the plane block is larger than the transform. + let offset = Some(3usize); + let mut uo = vec![0i32; cw * ch]; + let mut vo = vec![0i32; cw * ch]; + for plane in 1..3usize { + for rr in 0..ch / 4 { + for cc in 0..cw / 4 { + let (ox, oy) = (cc * 4, rr * 4); + if cpx + ox >= u.true_width || cpy + oy >= u.true_height { + continue; } - } - } - (Grid::Own(uo), Grid::Own(vo)) - } - } else if skip { - let zeros = Grid::Zero(cw * ch); - // libaom `predict_and_reconstruct_intra_block` (decodeframe.c - // ~1000) predicts EVERY plane and only guards the residual on - // `mbmi->skip_txfm`, so a skipped `UV_CFL_PRED` block is still - // DC + alpha * luma-AC. Dropping the CfL term here left a - // chroma-only bounded box on ReelC's key frames. - let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph)); - if alpha.is_some() { - hit!(CHROMA_SKIP_CFL_HITS); - } - for (_buf, plane) in [(&mut *u, 1usize), (&mut *v, 2)] { - if chroma422_pair16 { - // lane-av1-422o: two TX_4X8 units, each predicted on - // its own edges (the lower one off the upper one's - // samples); no coefficients are coded, and libaom's - // `set_entropy_context` zeroed the block's own cells, - // so the pair-wide zero stamp below stays correct. - for unit_row in 0..2usize { - let unit_reach = tu_reach_rect( - pw, ph, 0, unit_row * 8, 8, 8, pair_reach, - ppx, ppy, y.width, y.height, fctx, + // The unit's stamp is its own span: aom + // `av1_set_entropy_contexts` (blockd.c:29) + // memsets exactly `tx_size_wide_unit` x + // `tx_size_high_unit` cells at the unit's own + // `(aoff, loff)` -- for TX_4X4 ONE above cell + // and ONE left cell. `(oy / 2, ox / 2)` + + // `(8, 8)` is the 4:2:0 subsampled form (one + // chroma cell = 8 luma px = 2 mi cells); at + // 4:4:4 a unit is ONE mi cell, and the 2x2 + // smear let a 4-wide strip's later units + // overwrite the NEXT COLUMN's above cell with + // their own state -- a column aom never sees + // this block write -- so the following block's + // `all_zero` read the wrong `txb_skip` row + // (frame-0 read #452, the llkf named gap). + let cu_mi = ( + pair_mi.0 + (oy << ss_y(fctx)) / MI, + pair_mi.1 + (ox << ss_x(fctx)) / MI, + ); + // One luma-mi cell: the chroma entropy arrays + // are subsampled, and our bands replicate that + // one entry over the unit's two cells + // (`read_intra_chroma_lossless`). + let cu_around = neighbours.around_mi(cu_mi, MI); + let cu_reach = tu_reach( + pw, + ph, + ox * 2, + oy * 2, + 8, + pair_reach, + ppx, + ppy, + y.width, + y.height, + fctx, ); if let Some((ub, vb)) = &palette_uv_bufs { - let pbuf = if plane == 1 { ub } else { vb }; - set_palette_pred( - palette_window(pbuf, cw, 0, unit_row * 8, 4, 8), - fctx, - ); + let buf = if plane == 1 { ub } else { vb }; + set_palette_pred(palette_window(buf, cw, ox, oy, 4, 4), fctx); } - push_intra_rect(plane, - cpx, - cpy + unit_row * 8, - 4, - 8, + let buf: &mut PlaneBuf<'static> = + if plane == 1 { &mut *u } else { &mut *v }; + let cu_grid = read_plane( + dec, + cdfs, + TxbSet::Chroma4, + &scan4, + plane, + cu_around[plane], + mode, uv_predict_mode, angle_delta_uv, - unit_reach, - &ZERO_RESIDUAL[..4 * 8], - alpha - .zip(ac) - .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), + cu_reach, + buf, + cpx + ox, + cpy + oy, + 4, + 4, + base_q_idx, + None, None, - smooth_neighbor_uv, fctx, + offset, + smooth_neighbor_uv, + fctx, + )?; + neighbours.record_mi_chroma( + cu_mi, + 4 << ss_x(fctx), + 4 << ss_y(fctx), + plane, + &cu_grid, ); + hit!(CHROMA_SPLIT_TX_HITS); + let dst = if plane == 1 { &mut uo } else { &mut vo }; + for row in 0..4 { + let start = (oy + row) * cw + ox; + dst[start..start + 4].copy_from_slice(&cu_grid[row * 4..][..4]); + } } - } else { - if let Some((ub, vb)) = &palette_uv_bufs { - set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx); - } - push_intra_rect(plane, - cpx, - cpy, - cw, - ch, - uv_predict_mode, - angle_delta_uv, - pair_reach, - &zeros, - alpha - .zip(ac) - .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), - None, - smooth_neighbor_uv, fctx, - ); } } - (zeros.clone(), zeros) - } else if chroma422_pair16 { - // lane-av1-422o: the pair's 4x16 chroma as TWO TX_4X8 units - // per plane, plane-major (every U unit, then every V). Each - // unit: the `ChromaRect8x4` tables (`get_txsize_entropy_ctx` - // squares TX_4X8 up to the 8x8 class), `SCAN_4X8`, and a - // `txb_skip_ctx` of above+left in the OFFSET-10 rows -- the - // offset comes from `num_pels_log2_lookup[plane_bsize] > - // num_pels_log2_lookup[BLOCK_4X8]` with plane_bsize = - // BLOCK_INVALID (255), and the byte at that table's +255 in - // the pinned Release oracle is 255 (`cmpb` against the - // `0xc0db70` copy decodetxb.c links), i.e. the bigger-plane - // arm: +3 on the offset-7-first chroma tables. No tx_type - // symbol (only y plane's is transmitted); the unit's type is - // `intra_mode_to_tx_type(UV mode)` kept by the all-16 ext-tx - // set -- [`read_rect_chroma_unit`]'s own default. CfL params - // are computed ONCE per block (`are_parameters_computed`) - // over the pair's luma, shared by both units. Each unit is - // predicted and recorded immediately, so the lower unit - // reads the upper one's coefficient context. - let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph)); - for (plane, buf) in [(1usize, &mut *u), (2usize, &mut *v)] { + (Grid::Own(uo), Grid::Own(vo)) + } + } else if skip { + let zeros = Grid::Zero(cw * ch); + // libaom `predict_and_reconstruct_intra_block` (decodeframe.c + // ~1000) predicts EVERY plane and only guards the residual on + // `mbmi->skip_txfm`, so a skipped `UV_CFL_PRED` block is still + // DC + alpha * luma-AC. Dropping the CfL term here left a + // chroma-only bounded box on ReelC's key frames. + let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph)); + if alpha.is_some() { + hit!(CHROMA_SKIP_CFL_HITS); + } + for (_buf, plane) in [(&mut *u, 1usize), (&mut *v, 2)] { + if chroma422_pair16 { + // lane-av1-422o: two TX_4X8 units, each predicted on + // its own edges (the lower one off the upper one's + // samples); no coefficients are coded, and libaom's + // `set_entropy_context` zeroed the block's own cells, + // so the pair-wide zero stamp below stays correct. for unit_row in 0..2usize { - let unit_mi = (pair_mi.0 + unit_row * 2, pair_mi.1); let unit_reach = tu_reach_rect( - pw, ph, 0, unit_row * 8, 8, 8, pair_reach, - ppx, ppy, y.width, y.height, fctx, + pw, + ph, + 0, + unit_row * 8, + 8, + 8, + pair_reach, + ppx, + ppy, + y.width, + y.height, + fctx, ); if let Some((ub, vb)) = &palette_uv_bufs { let pbuf = if plane == 1 { ub } else { vb }; - set_palette_pred( - palette_window(pbuf, cw, 0, unit_row * 8, 4, 8), - fctx, - ); + set_palette_pred(palette_window(pbuf, cw, 0, unit_row * 8, 4, 8), fctx); } - let chroma_around = neighbours.around_mi_422_chroma(unit_mi, 8, 8); - let unit_grid = read_rect_chroma_unit( - dec, - cdfs, - TxbSet::ChromaRect8x4, - &SCAN_4X8, + push_intra_rect( + plane, + cpx, + cpy + unit_row * 8, 4, 8, - plane, - chroma_around[plane], uv_predict_mode, angle_delta_uv, unit_reach, - buf, - cpx, - cpy + unit_row * 8, - base_q_idx, - // lane-av1-422q: the offset-10 rows -- the same - // measured rule as the 4x32 arm (plane_bsize - // BLOCK_INVALID for the pair's BLOCK_4X16 too; - // num_pels_log2_lookup[255] = 0xff at the - // 0xc0de70 copy -> +3 on the offset-7-first - // chroma tables; see lanes/av1422q.report.md). - Some(3), + &ZERO_RESIDUAL[..4 * 8], alpha .zip(ac) .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), - smooth_neighbor_uv, fctx, - )?; - neighbours.record_mi_chroma(unit_mi, 8, 8, plane, &unit_grid); + None, + smooth_neighbor_uv, + fctx, + ); } - } - (Grid::Zero(cw * ch), Grid::Zero(cw * ch)) - } else { - // lane-av1422ctxgather: 4:2:2's chroma above votes sample - // every second luma-mi cell - // ([`Neighbours::around_mi_422_chroma`]: at ss_x 1 one - // chroma 4-px column spans two luma mi columns, and the - // plain per-mi gather counts each column's whole-unit dc - // sign twice). The left extent is unsubsampled at ss_y 0, - // so its per-mi cells already line up one-to-one. - let around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { - neighbours.around_mi_422_chroma(pair_mi, pw, ph) } else { - neighbours.around_mi_rect(pair_mi, pw, ph) - }; - // lane-av1-444: the strip's own 16x4 / 4x16 chroma at ss 0/0 - // (`TxbSet::Chroma8`, `get_txsize_entropy_ctx(TX_16X4)` = - // the 8x8 set); 4:2:0 keeps the pair's 8x4 / 4x8. - let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (cw, ch) { - (8, 4) => (TxbSet::ChromaRect8x4, &SCAN_8X4[..]), - (4, 8) => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), - (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]), - // lane-av1-444: 4:4:4's own-strip vert chroma is (4,16) - // -- one TX_4X16. (lane-av1-422o: the 4:2:2 pair's - // (4,16) never reaches this row; `chroma422_pair16` - // intercepts it above and chunks it into TX_4X8 units.) - (4, 16) => (TxbSet::Chroma8, &SCAN_4X16[..]), - // lane-av1-422: a 4:2:2 HORZ pair (16x8 luma) keeps the - // pair's height: an 8x8 SQUARE chroma block, the same - // `TxbSet::Chroma8` set any 8x8 chroma plane reads. The - // 4:2:0 pair's chroma is 8x4 and 4:4:4's is 16x4, so this - // row is unreachable there. It is also the witness arm: - // a restored `/2 chroma height` lands on (8,4) and the - // counter reads 0. - (8, 8) => { - hit!(CHROMA422_SQUARE_HITS); - (TxbSet::Chroma8, default_scan(8)) - } - // lane-av1-422o: with the `chroma422_pair16` arm above, - // the (2,16) own-strip shape and the 4:4:4 shapes are the - // only residents; anything else is a named-lane gap. - _ => unreachable!("decode_rect4_16_strip chroma shape set is closed"), - }; - let mut planes = Vec::with_capacity(2); - for plane in 1..3 { - let default_tx = default_intra_tx_type(uv_predict_mode as u8); - let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); - let mut coding = cdfs.txb(chroma_set, uv_predict_mode); - let (levels, tx_type) = read_chroma_coeffs_rect( - dec, - &mut coding, - chroma_scan, - cw, - ch, - skip_ctx, - dc_sign_ctx(around[plane].2), - default_tx, - fctx, - )?; - planes.push((levels, tx_type)); - } - let (v_levels, v_tx_type) = planes.pop().expect("plane 2"); - let (u_levels, u_tx_type) = planes.pop().expect("plane 1"); - // CfL averages the luma of the WHOLE pair, the region this one - // chroma transform covers. - let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph)); - for (plane, _buf, levels, tx_type) in [ - (1usize, &mut *u, &u_levels, u_tx_type), - (2, &mut *v, &v_levels, v_tx_type), - ] { - let residual = dequant_and_inverse_typed_wh( - levels, - cw, - ch, - crate::decode::bit_depth(fctx), - block_q_idx(fctx), - plane_q_delta(plane, fctx).0, - plane_q_delta(plane, fctx).1, - tx_type, - block_iqmatrix(fctx, plane, cw, ch, tx_type), - ); if let Some((ub, vb)) = &palette_uv_bufs { set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx); } - push_intra_rect(plane, + push_intra_rect( + plane, cpx, cpy, cw, @@ -15831,24 +17464,202 @@ fn decode_rect4_16_strip( uv_predict_mode, angle_delta_uv, pair_reach, - &residual, + &zeros, alpha .zip(ac) .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, + ); + } + } + (zeros.clone(), zeros) + } else if chroma422_pair16 { + // lane-av1-422o: the pair's 4x16 chroma as TWO TX_4X8 units + // per plane, plane-major (every U unit, then every V). Each + // unit: the `ChromaRect8x4` tables (`get_txsize_entropy_ctx` + // squares TX_4X8 up to the 8x8 class), `SCAN_4X8`, and a + // `txb_skip_ctx` of above+left in the OFFSET-10 rows -- the + // offset comes from `num_pels_log2_lookup[plane_bsize] > + // num_pels_log2_lookup[BLOCK_4X8]` with plane_bsize = + // BLOCK_INVALID (255), and the byte at that table's +255 in + // the pinned Release oracle is 255 (`cmpb` against the + // `0xc0db70` copy decodetxb.c links), i.e. the bigger-plane + // arm: +3 on the offset-7-first chroma tables. No tx_type + // symbol (only y plane's is transmitted); the unit's type is + // `intra_mode_to_tx_type(UV mode)` kept by the all-16 ext-tx + // set -- [`read_rect_chroma_unit`]'s own default. CfL params + // are computed ONCE per block (`are_parameters_computed`) + // over the pair's luma, shared by both units. Each unit is + // predicted and recorded immediately, so the lower unit + // reads the upper one's coefficient context. + let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph)); + for (plane, buf) in [(1usize, &mut *u), (2usize, &mut *v)] { + for unit_row in 0..2usize { + let unit_mi = (pair_mi.0 + unit_row * 2, pair_mi.1); + let unit_reach = tu_reach_rect( + pw, + ph, + 0, + unit_row * 8, + 8, + 8, + pair_reach, + ppx, + ppy, + y.width, + y.height, + fctx, ); + if let Some((ub, vb)) = &palette_uv_bufs { + let pbuf = if plane == 1 { ub } else { vb }; + set_palette_pred(palette_window(pbuf, cw, 0, unit_row * 8, 4, 8), fctx); + } + let chroma_around = neighbours.around_mi_422_chroma(unit_mi, 8, 8); + let unit_grid = read_rect_chroma_unit( + dec, + cdfs, + TxbSet::ChromaRect8x4, + &SCAN_4X8, + 4, + 8, + plane, + chroma_around[plane], + uv_predict_mode, + angle_delta_uv, + unit_reach, + buf, + cpx, + cpy + unit_row * 8, + base_q_idx, + // lane-av1-422q: the offset-10 rows -- the same + // measured rule as the 4x32 arm (plane_bsize + // BLOCK_INVALID for the pair's BLOCK_4X16 too; + // num_pels_log2_lookup[255] = 0xff at the + // 0xc0de70 copy -> +3 on the offset-7-first + // chroma tables; see lanes/av1422q.report.md). + Some(3), + alpha + .zip(ac) + .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), + smooth_neighbor_uv, + fctx, + )?; + neighbours.record_mi_chroma(unit_mi, 8, 8, plane, &unit_grid); + } + } + (Grid::Zero(cw * ch), Grid::Zero(cw * ch)) + } else { + // lane-av1422ctxgather: 4:2:2's chroma above votes sample + // every second luma-mi cell + // ([`Neighbours::around_mi_422_chroma`]: at ss_x 1 one + // chroma 4-px column spans two luma mi columns, and the + // plain per-mi gather counts each column's whole-unit dc + // sign twice). The left extent is unsubsampled at ss_y 0, + // so its per-mi cells already line up one-to-one. + let around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + neighbours.around_mi_422_chroma(pair_mi, pw, ph) + } else { + neighbours.around_mi_rect(pair_mi, pw, ph) + }; + // lane-av1-444: the strip's own 16x4 / 4x16 chroma at ss 0/0 + // (`TxbSet::Chroma8`, `get_txsize_entropy_ctx(TX_16X4)` = + // the 8x8 set); 4:2:0 keeps the pair's 8x4 / 4x8. + let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (cw, ch) { + (8, 4) => (TxbSet::ChromaRect8x4, &SCAN_8X4[..]), + (4, 8) => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), + (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]), + // lane-av1-444: 4:4:4's own-strip vert chroma is (4,16) + // -- one TX_4X16. (lane-av1-422o: the 4:2:2 pair's + // (4,16) never reaches this row; `chroma422_pair16` + // intercepts it above and chunks it into TX_4X8 units.) + (4, 16) => (TxbSet::Chroma8, &SCAN_4X16[..]), + // lane-av1-422: a 4:2:2 HORZ pair (16x8 luma) keeps the + // pair's height: an 8x8 SQUARE chroma block, the same + // `TxbSet::Chroma8` set any 8x8 chroma plane reads. The + // 4:2:0 pair's chroma is 8x4 and 4:4:4's is 16x4, so this + // row is unreachable there. It is also the witness arm: + // a restored `/2 chroma height` lands on (8,4) and the + // counter reads 0. + (8, 8) => { + hit!(CHROMA422_SQUARE_HITS); + (TxbSet::Chroma8, default_scan(8)) } - (u_levels, v_levels) + // lane-av1-422o: with the `chroma422_pair16` arm above, + // the (2,16) own-strip shape and the 4:4:4 shapes are the + // only residents; anything else is a named-lane gap. + _ => unreachable!("decode_rect4_16_strip chroma shape set is closed"), }; - neighbours.record_uv_mode_mi(pair_mi.0, pair_mi.1, pw / MI, ph / MI, uv_predict_mode); - // A lossless pair already stamped each TX_4X4 (`record_mi_chroma`). - // The single-state rewrite below is the non-lossless TX_8X4/TX_4X8. - // lane-av1-422o: the chunked pair's cells are stamped PER UNIT in - // the arm above (libaom's coefficient contexts are per - // 4x4-cell); a pair-wide state would erase the unit boundary the - // next block reads. - if !lossless_pair && !chroma422_pair16 { + let mut planes = Vec::with_capacity(2); + for plane in 1..3 { + let default_tx = default_intra_tx_type(uv_predict_mode as u8); + let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); + let mut coding = cdfs.txb(chroma_set, uv_predict_mode); + let (levels, tx_type) = read_chroma_coeffs_rect( + dec, + &mut coding, + chroma_scan, + cw, + ch, + skip_ctx, + dc_sign_ctx(around[plane].2), + default_tx, + fctx, + )?; + planes.push((levels, tx_type)); + } + let (v_levels, v_tx_type) = planes.pop().expect("plane 2"); + let (u_levels, u_tx_type) = planes.pop().expect("plane 1"); + // CfL averages the luma of the WHOLE pair, the region this one + // chroma transform covers. + let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph)); + for (plane, _buf, levels, tx_type) in [ + (1usize, &mut *u, &u_levels, u_tx_type), + (2, &mut *v, &v_levels, v_tx_type), + ] { + let residual = dequant_and_inverse_typed_wh( + levels, + cw, + ch, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(plane, fctx).0, + plane_q_delta(plane, fctx).1, + tx_type, + block_iqmatrix(fctx, plane, cw, ch, tx_type), + ); + if let Some((ub, vb)) = &palette_uv_bufs { + set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx); + } + push_intra_rect( + plane, + cpx, + cpy, + cw, + ch, + uv_predict_mode, + angle_delta_uv, + pair_reach, + &residual, + alpha + .zip(ac) + .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), + None, + smooth_neighbor_uv, + fctx, + ); + } + (u_levels, v_levels) + }; + neighbours.record_uv_mode_mi(pair_mi.0, pair_mi.1, pw / MI, ph / MI, uv_predict_mode); + // A lossless pair already stamped each TX_4X4 (`record_mi_chroma`). + // The single-state rewrite below is the non-lossless TX_8X4/TX_4X8. + // lane-av1-422o: the chunked pair's cells are stamped PER UNIT in + // the arm above (libaom's coefficient contexts are per + // 4x4-cell); a pair-wide state would erase the unit boundary the + // next block reads. + if !lossless_pair && !chroma422_pair16 { // The chroma planes' coefficient context, over the PAIR's mi span // (`decode_leaf_rect8`'s own rule: a subsampled plane's bound is // the luma one rounded up to its 4x4 unit). @@ -15873,21 +17684,30 @@ fn decode_rect4_16_strip( slot[2] = v_state; } } - } - last_uv_mode = Some(uv_predict_mode); } - if horz { - hit!(RECT4_16_HORZ_HITS); - } else { - hit!(RECT4_16_VERT_HITS); - } - let (pal_y_size, pal_y_colors) = - palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); - let (pal_uv_size, pal_uv_colors) = - palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); - record_strip_palette( - neighbours, lmi, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, - ); + last_uv_mode = Some(uv_predict_mode); + } + if horz { + hit!(RECT4_16_HORZ_HITS); + } else { + hit!(RECT4_16_VERT_HITS); + } + let (pal_y_size, pal_y_colors) = palette_y + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.colors)); + let (pal_uv_size, pal_uv_colors) = palette_uv + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); + record_strip_palette( + neighbours, + lmi, + bw, + bh, + pal_y_size, + pal_y_colors, + pal_uv_size, + pal_uv_colors, + ); // `set_txfm_ctxs(mbmi->tx_size, n4_w, n4_h, skip && is_inter, xd)` // (libaom `decode_token_recon_block`, run for EVERY block of an inter // frame): the above row records `tx_size_wide` over the block's width and @@ -15902,7 +17722,6 @@ fn decode_rect4_16_strip( Ok((mode, last_uv_mode, (tx_w, tx_h))) } - /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/ /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` / /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike @@ -15935,42 +17754,66 @@ fn decode_block_rect64( allow_screen_content_tools: bool, base_q_idx: u8, tx_select: bool, - reduced_tx_set: bool, fctx: &crate::decode::FrameCtx, + reduced_tx_set: bool, + fctx: &crate::decode::FrameCtx, ) -> Result<()> { let (r, c) = at; let (px, py) = (c * SUB, r * SUB); let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); let palette_uv_cache = neighbours.palette_uv_cache(at); - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv, intrabc) = - read_intra_mode_rect( - dec, - cdfs, - nb_above_mode, - nb_left_mode, - // `is_cfl_allowed` (spec 5.11.5) caps CFL at <=32x32; these - // superblock-level HORZ/VERT strips are 64x32/32x64, so unlike - // `decode_block_rect`'s own 32x16/16x32 strips (where `true` is - // correct), CFL must never be offered here -- passing `true` - // read `uv_mode` off the 14-symbol `uv_mode_cfl` CDF instead of - // the real 13-symbol `uv_mode_no_cfl` one and desynced the tile - // from this block's very first symbol (lane-sbpart r3 bisect). - false, - true, - bw, - bh, - enable_filter_intra, - neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)), - allow_screen_content_tools, - Some((palette_ctx, &palette_cache)), - &palette_uv_cache, - r * (SUB / MI), - c * (SUB / MI), fctx, - )?; + let ( + skip, + mode, + angle_delta_y, + uv_mode, + angle_delta_uv, + alpha, + filter_intra, + palette_y, + palette_uv, + intrabc, + ) = read_intra_mode_rect( + dec, + cdfs, + nb_above_mode, + nb_left_mode, + // `is_cfl_allowed` (spec 5.11.5) caps CFL at <=32x32; these + // superblock-level HORZ/VERT strips are 64x32/32x64, so unlike + // `decode_block_rect`'s own 32x16/16x32 strips (where `true` is + // correct), CFL must never be offered here -- passing `true` + // read `uv_mode` off the 14-symbol `uv_mode_cfl` CDF instead of + // the real 13-symbol `uv_mode_no_cfl` one and desynced the tile + // from this block's very first symbol (lane-sbpart r3 bisect). + false, + true, + bw, + bh, + enable_filter_intra, + neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)), + allow_screen_content_tools, + Some((palette_ctx, &palette_cache)), + &palette_uv_cache, + r * (SUB / MI), + c * (SUB / MI), + fctx, + )?; if let Some((dv_row, dv_col)) = intrabc { return decode_intrabc_owned_rect( - dec, cdfs, neighbours, (r * (SUB / MI), c * (SUB / MI)), (bw, bh), skip, - (dv_row, dv_col), y, u, v, base_q_idx, tx_select, reduced_tx_set, fctx, + dec, + cdfs, + neighbours, + (r * (SUB / MI), c * (SUB / MI)), + (bw, bh), + skip, + (dv_row, dv_col), + y, + u, + v, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, ); } if (palette_y.is_some() || palette_uv.is_some()) && !skip { @@ -16038,7 +17881,8 @@ fn decode_block_rect64( neighbours, (mi_r, mi_c), depth_to_tx_wh(bw, bh, depth, fctx), - (bw, bh), fctx, + (bw, bh), + fctx, ); if depth != 0 || lossless(fctx) { hit!(TX_DEPTH_HITS); @@ -16100,16 +17944,20 @@ fn decode_block_rect64( u, v, base_q_idx, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )?; // Same early-return palette stamp as [`decode_block_rect`]'s split arm // (lane-palette2 r10): this return skips the fn's own tail, so a // split-tx superblock strip would otherwise leave the above/left // palette arrays holding a dead block's colours. - let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); + let (py_size, py_colors) = palette_y + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.colors)); neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors); - let (puv_size, puv_colors) = - palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); + let (puv_size, puv_colors) = palette_uv + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors); // lane-frame36 r2: `set_txfm_ctxs` runs for EVERY block and this early // return skips the fn's own tail, so a SPLIT superblock-level strip @@ -16129,17 +17977,28 @@ fn decode_block_rect64( let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx)); let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx); if let Some(ref pyv) = palette_y { - let buf: Vec = pyv.map.iter().map(|&idx| pyv.colors[idx as usize]).collect(); + let buf: Vec = pyv + .map + .iter() + .map(|&idx| pyv.colors[idx as usize]) + .collect(); set_palette_pred(buf, fctx); } let palette_uv_bufs: Option<(Vec, Vec)> = palette_uv.as_ref().map(|puv| { ( - puv.map.iter().map(|&idx| puv.u_colors[idx as usize]).collect(), - puv.map.iter().map(|&idx| puv.v_colors[idx as usize]).collect(), + puv.map + .iter() + .map(|&idx| puv.u_colors[idx as usize]) + .collect(), + puv.map + .iter() + .map(|&idx| puv.v_colors[idx as usize]) + .collect(), ) }); if skip { - push_intra_rect(0, + push_intra_rect( + 0, px, py, bw, @@ -16150,13 +18009,15 @@ fn decode_block_rect64( &ZERO_RESIDUAL[..bw * bh], None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - push_intra_rect(1, + push_intra_rect( + 1, cpx, cpy, chroma_w, @@ -16167,12 +18028,14 @@ fn decode_block_rect64( &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - push_intra_rect(2, + push_intra_rect( + 2, cpx, cpy, chroma_w, @@ -16183,7 +18046,8 @@ fn decode_block_rect64( &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); neighbours.record_rect( at, @@ -16208,7 +18072,9 @@ fn decode_block_rect64( let scan32 = default_scan(TX32); if coeff_trace_on() { let (rng, _) = dec.debug_state(); - eprintln!("EC_COEFF plane=0 row={mi_r} col={mi_c} tx_size={luma_cw}x{luma_ch} rng={rng}"); + eprintln!( + "EC_COEFF plane=0 row={mi_r} col={mi_c} tx_size={luma_cw}x{luma_ch} rng={rng}" + ); } let (luma_corner, luma_tx_type) = if (luma_cw, luma_ch) == (32, 32) { let mut luma_coding = cdfs.txb(TxbSet::Luma64, mode); @@ -16277,9 +18143,10 @@ fn decode_block_rect64( plane_q_delta(0, fctx).0, plane_q_delta(0, fctx).1, luma_tx_type, - block_iqmatrix(fctx, 0, bw, bh, luma_tx_type), + block_iqmatrix(fctx, 0, bw, bh, luma_tx_type), ); - push_intra_rect(0, + push_intra_rect( + 0, px, py, bw, @@ -16290,11 +18157,14 @@ fn decode_block_rect64( &luma_residual, None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); if crate::envflags::env_flag!("EC_SBPART_DUMP64") { let leftcol: Vec = if px > 0 { - (py..py + bh).map(|row| y.data[row * y.width + px - 1]).collect() + (py..py + bh) + .map(|row| y.data[row * y.width + px - 1]) + .collect() } else { vec![] }; @@ -16321,7 +18191,7 @@ fn decode_block_rect64( _ => { return Err(unsupported( "a 64-axis strip whose chroma unit has no coefficient table", - )) + )); } }; let bigger = nw * nh > 1; @@ -16342,17 +18212,17 @@ fn decode_block_rect64( } else { let lsx = uw << ss_x(fctx); let lsy = uh << ss_y(fctx); - let cu_mi = ( - mi_r + cu_row * (lsy / MI), - mi_c + cu_col * (lsx / MI), - ); + let cu_mi = (mi_r + cu_row * (lsy / MI), mi_c + cu_col * (lsx / MI)); neighbours.around_mi_rect(cu_mi, lsx, lsy) }; let lsx = uw << ss_x(fctx); let lsy = uh << ss_y(fctx); let cfl = alpha.map(|(au, av)| { let a = if plane_idx == 1 { au } else { av }; - (a, cfl_src_rect(px + cu_col * lsx, py + cu_row * lsy, lsx, lsy)) + ( + a, + cfl_src_rect(px + cu_col * lsx, py + cu_row * lsy, lsx, lsy), + ) }); let levels = if uw == uh { let plane = if plane_idx == 1 { &mut *u } else { &mut *v }; @@ -16360,10 +18230,27 @@ fn decode_block_rect64( set_palette_pred((if plane_idx == 1 { ub } else { vb }).clone(), fctx); } read_plane( - dec, cdfs, chroma_set, chroma_scan, plane_idx, cu_around[plane_idx], - mode, uv_predict_mode, angle_delta_uv, reach, plane, - cpx + cu_col * uw, cpy + cu_row * uh, uw, uw, base_q_idx, - cfl, None, bigger.then_some(3), smooth_neighbor_uv, fctx, + dec, + cdfs, + chroma_set, + chroma_scan, + plane_idx, + cu_around[plane_idx], + mode, + uv_predict_mode, + angle_delta_uv, + reach, + plane, + cpx + cu_col * uw, + cpy + cu_row * uh, + uw, + uw, + base_q_idx, + cfl, + None, + bigger.then_some(3), + smooth_neighbor_uv, + fctx, )? } else { let skip_ctx = usize::from(cu_around[plane_idx].0) @@ -16371,28 +18258,52 @@ fn decode_block_rect64( + usize::from(bigger) * 3; let mut coding = cdfs.txb(chroma_set, uv_predict_mode); let (levels, tx_type) = read_chroma_coeffs_rect( - dec, &mut coding, chroma_scan, uw, uh, skip_ctx, - dc_sign_ctx(cu_around[plane_idx].2), TxType::DctDct, fctx, + dec, + &mut coding, + chroma_scan, + uw, + uh, + skip_ctx, + dc_sign_ctx(cu_around[plane_idx].2), + TxType::DctDct, + fctx, )?; let residual = dequant_and_inverse_typed_wh( - &levels, uw, uh, crate::decode::bit_depth(fctx), + &levels, + uw, + uh, + crate::decode::bit_depth(fctx), block_q_idx(fctx), plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1, tx_type, - block_iqmatrix(fctx, plane_idx, uw, uh, tx_type), + block_iqmatrix(fctx, plane_idx, uw, uh, tx_type), ); if let Some((ub, vb)) = &palette_uv_bufs { set_palette_pred((if plane_idx == 1 { ub } else { vb }).clone(), fctx); } push_intra_rect( - plane_idx, cpx + cu_col * uw, cpy + cu_row * uh, uw, uh, - uv_predict_mode, angle_delta_uv, reach, &residual, - cfl, None, smooth_neighbor_uv, fctx, + plane_idx, + cpx + cu_col * uw, + cpy + cu_row * uh, + uw, + uh, + uv_predict_mode, + angle_delta_uv, + reach, + &residual, + cfl, + None, + smooth_neighbor_uv, + fctx, ); levels }; - let dst = if plane_idx == 1 { &mut u_levels } else { &mut v_levels }; + let dst = if plane_idx == 1 { + &mut u_levels + } else { + &mut v_levels + }; for row in 0..uh { let d = (cu_row * uh + row) * chroma_w + cu_col * uw; dst[d..d + uw].copy_from_slice(&levels[row * uw..][..uw]); @@ -16400,7 +18311,10 @@ fn decode_block_rect64( if bigger { neighbours.record_mi_chroma( (mi_r + cu_row * (lsy / MI), mi_c + cu_col * (lsx / MI)), - lsx, lsy, plane_idx, &levels, + lsx, + lsy, + plane_idx, + &levels, ); tiled_chroma_units.push(( (mi_r + cu_row * (lsy / MI), mi_c + cu_col * (lsx / MI)), @@ -16413,7 +18327,14 @@ fn decode_block_rect64( } } } - neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[&luma_levels[..], &u_levels[..], &v_levels[..]]); + neighbours.record_rect( + at, + bw, + bh, + mode, + uv_predict_mode, + &[&luma_levels[..], &u_levels[..], &v_levels[..]], + ); // The per-unit re-stamp: `record_rect` above wrote the whole strip's // chroma cells from the assembled grids' one whole-strip state, // overwriting exactly the stamps the tiled loop just made. @@ -16422,13 +18343,24 @@ fn decode_block_rect64( } hit!(RECT_COEFF_HITS); } - let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); + let (py_size, py_colors) = palette_y + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.colors)); neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors); - let (puv_size, puv_colors) = - palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); + let (puv_size, puv_colors) = palette_uv + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors); neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); - neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0, fctx); + neighbours.fill_lf_grid_rect( + (mi_r, mi_c), + bw / MI, + bh / MI, + tx_w as u8, + tx_h as u8, + 0, + fctx, + ); // `set_txfm_ctxs(mbmi->tx_size, n4_w, n4_h, skip && is_inter, xd)` // (libaom `decode_token_recon_block`, run for EVERY block of an inter // frame): the above row records `tx_size_wide` over the block's width and @@ -16491,7 +18423,8 @@ fn read_intra_mode( // `use_palette_y`, not a neighbour lookup). palette_uv_cache: &[u16], mi_r: usize, - mi_c: usize, fctx: &crate::decode::FrameCtx, + mi_c: usize, + fctx: &crate::decode::FrameCtx, ) -> Result<( bool, usize, @@ -16514,7 +18447,10 @@ fn read_intra_mode( // (decodemv.c:818), printed at the same point: before the first // mode-info symbol of the block, so a cross-decoder range ladder can // be keyed on the BLOCK, not just on the symbol sequence. - eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sq side={side} rng={}", dec.debug_state().0); + eprintln!( + "EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sq side={side} rng={}", + dec.debug_state().0 + ); } macro_rules! istep { ($name:literal, $val:expr) => { @@ -16543,7 +18479,11 @@ fn read_intra_mode( } let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; if trace { - eprintln!("TRACE skip value={} rng={}", skip as i32, dec.debug_state().0); + eprintln!( + "TRACE skip value={} rng={}", + skip as i32, + dec.debug_state().0 + ); } istep!("skip", skip as i32); if !seg_id_pre_skip(fctx) { @@ -16572,7 +18512,11 @@ fn read_intra_mode( if allow_intrabc { let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0; if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { - eprintln!("EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=intrabc val={} rng={}", u8::from(use_intrabc), dec.debug_state().0); + eprintln!( + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=intrabc val={} rng={}", + u8::from(use_intrabc), + dec.debug_state().0 + ); } if trace { eprintln!("TRACE use_intrabc value={}", use_intrabc as i32); @@ -16596,7 +18540,10 @@ fn read_intra_mode( let left_ctx = INTRA_MODE_CTX[left_mode]; let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); if trace { - eprintln!("TRACE y_mode ctx=({above_ctx},{left_ctx}) value={mode} rng={}", dec.debug_state().0); + eprintln!( + "TRACE y_mode ctx=({above_ctx},{left_ctx}) value={mode} rng={}", + dec.debug_state().0 + ); } istep!("mode", mode as i32); let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) { @@ -16626,7 +18573,10 @@ fn read_intra_mode( dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) }; if trace { - eprintln!("TRACE uv_mode cfl={cfl} y_mode={mode} value={uv_mode} rng={}", dec.debug_state().0); + eprintln!( + "TRACE uv_mode cfl={cfl} y_mode={mode} value={uv_mode} rng={}", + dec.debug_state().0 + ); } istep!("uv_mode", uv_mode as i32); let alpha = if cfl && uv_mode == UV_CFL_PRED { @@ -16684,9 +18634,7 @@ fn read_intra_mode( // `decode_color_index_map` call). let mut palette_y_pending: Option<(usize, [u16; 8])> = None; let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None; - if allow_screen_content_tools - && let Some(bsize_ctx) = palette_bsize_ctx(side) - { + if allow_screen_content_tools && let Some(bsize_ctx) = palette_bsize_ctx(side) { let (mode_ctx, cache) = palette.unwrap_or((0, &[])); if mode == DC_PRED { if trace { @@ -16700,7 +18648,10 @@ fn read_intra_mode( mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][mode_ctx]) != 0; if mode == DC_PRED && trace { let (rng, _) = dec.debug_state(); - eprintln!("TRACE palette_y_mode value={} rng={rng}", use_palette_y as i32); + eprintln!( + "TRACE palette_y_mode value={} rng={rng}", + use_palette_y as i32 + ); } if use_palette_y { let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); @@ -16758,7 +18709,8 @@ fn read_intra_mode( let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0; if trace { eprintln!( - "TRACE use_filter_intra side={side} rng={} value={}", dec.debug_state().0, + "TRACE use_filter_intra side={side} rng={} value={}", + dec.debug_state().0, use_filter_intra as i32 ); } @@ -16776,13 +18728,23 @@ fn read_intra_mode( // `av1_visit_palette` (decoder.c:234): plane 0 (Y) then plane 1 (chroma, // shared U/V map) -- the same order libaom's own loop visits them in. let palette_y = palette_y_pending.map(|(n, colors)| { - let map = - decode_color_index_map(dec, cdfs, n, side, palette_onscreen(mi_r, mi_c, side, side, fctx), false); + let map = decode_color_index_map( + dec, + cdfs, + n, + side, + palette_onscreen(mi_r, mi_c, side, side, fctx), + false, + ); hit!(PALETTE_HITS); if trace { eprintln!("TRACE palette_y size={n} colors={:?}", &colors[..n]); } - PaletteY { size: n, colors, map } + PaletteY { + size: n, + colors, + map, + } }); let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { let on = palette_onscreen_uv( @@ -16796,7 +18758,13 @@ fn read_intra_mode( // square call's `(side >> ss_x)`-squared (4x4), which left a // 16-entry map for a 32-sample unit and panicked the reconstruct. let map = decode_color_index_map_wh( - dec, cdfs, n, side >> ss_x(fctx), side >> ss_y(fctx), on, true, + dec, + cdfs, + n, + side >> ss_x(fctx), + side >> ss_y(fctx), + on, + true, ); hit!(PALETTE_UV_HITS); if trace { @@ -16806,7 +18774,12 @@ fn read_intra_mode( &v_colors[..n] ); } - PaletteUv { size: n, u_colors, v_colors, map } + PaletteUv { + size: n, + u_colors, + v_colors, + map, + } }); Ok(( skip, @@ -16860,7 +18833,9 @@ fn read_cfl_alphas(dec: &mut SymbolDecoder, cdfs: &mut Cdfs) -> (i32, i32) { /// subtracted (`round_offset = num_pel/2`, right-shifted by `log2(num_pel)`) /// to give the AC values [`cfl_scaled`] scales by alpha. fn cfl_ac_q3(y: &PlaneBuf<'_>, px: usize, py: usize, side: usize) -> Vec { - cfl_ac_q3_at(px, py, side, side, |lx, ly| i32::from(y.data[ly * y.width + lx])) + cfl_ac_q3_at(px, py, side, side, |lx, ly| { + i32::from(y.data[ly * y.width + lx]) + }) } /// The one body [`cfl_ac_q3`] and [`cfl_ac_q3_rect`] share, reading its luma @@ -16936,11 +18911,9 @@ pub(crate) fn cfl_ac_q3_at( for cy in 0..ch { for cx in 0..cw { let (lx, ly) = (px + cx * 2, py + cy * 2); - let q3 = (sample(lx, ly) - + sample(lx + 1, ly) - + sample(lx, ly + 1) - + sample(lx + 1, ly + 1)) - << 1; + let q3 = + (sample(lx, ly) + sample(lx + 1, ly) + sample(lx, ly + 1) + sample(lx + 1, ly + 1)) + << 1; ac[cy * cw + cx] = q3; sum += q3; } @@ -16980,10 +18953,19 @@ pub(crate) fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 { /// compared the LAST decoded frame (ledger, class stale-output-faked-measurement). #[allow(dead_code)] // gate counter accessor with no reader yet; the counter itself is live fn stage_dump_idx() -> usize { - PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst).saturating_sub(1) + PREFILT_PICTURE_IDX + .load(std::sync::atomic::Ordering::SeqCst) + .saturating_sub(1) } -fn dump_stage16(var: &str, y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>, fw: usize, fh: usize) { +fn dump_stage16( + var: &str, + y: &PlaneBuf<'_>, + u: &PlaneBuf<'_>, + v: &PlaneBuf<'_>, + fw: usize, + fh: usize, +) { use std::io::Write; // lane-sbrect10 r2 / lane-cdef r1 (one shared helper): index the dump by // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed @@ -16992,7 +18974,11 @@ fn dump_stage16(var: &str, y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>, if let Ok(path) = crate::envflags::var(var) && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var))) { - for (p, w, h) in [(y, fw, fh), (u, fw.div_ceil(2), fh.div_ceil(2)), (v, fw.div_ceil(2), fh.div_ceil(2))] { + for (p, w, h) in [ + (y, fw, fh), + (u, fw.div_ceil(2), fh.div_ceil(2)), + (v, fw.div_ceil(2), fh.div_ceil(2)), + ] { for row in 0..h { let mut bytes = Vec::with_capacity(w * 2); for &s in &p.data[row * p.width..][..w] { @@ -17012,7 +18998,10 @@ fn dump_stage_idx(var: &str) -> usize { use std::collections::HashMap; use std::sync::{Mutex, OnceLock}; static IDX: OnceLock>> = OnceLock::new(); - let mut m = IDX.get_or_init(|| Mutex::new(HashMap::new())).lock().unwrap(); + let mut m = IDX + .get_or_init(|| Mutex::new(HashMap::new())) + .lock() + .unwrap(); let e = m.entry(var.to_string()).or_insert(0); let i = *e; *e += 1; @@ -17212,7 +19201,8 @@ impl PlaneBuf<'_> { // lane-wave1 step (i): the palette/intrabc prediction override, taken // off `FrameCtx::palette_pred` by the PUSH site (parse order) rather // than by this replay. - pred: Option>, fctx: &crate::decode::FrameCtx, + pred: Option>, + fctx: &crate::decode::FrameCtx, ) { // As [`Self::reconstruct`]'s own [`PALETTE_PRED`] override // (lane-palette2 r4): a palette block's prediction is the @@ -17227,7 +19217,10 @@ impl PlaneBuf<'_> { above.as_ref().map(|a| (a.len(), a[0])), left.as_ref().map(|l| l.len()), left.as_ref().map(|l| l[0]), - self.tile_x0, self.tile_y0, self.true_width, self.true_height + self.tile_x0, + self.tile_y0, + self.true_width, + self.true_height ); } let mut prediction = vec![0u16; bw * bh]; @@ -17239,7 +19232,8 @@ impl PlaneBuf<'_> { corner, bw, bh, - &mut prediction, fctx, + &mut prediction, + fctx, ); } else { let enable_edge_filter = fctx.enable_edge_filter.with(std::cell::Cell::get); @@ -17253,7 +19247,8 @@ impl PlaneBuf<'_> { bh, enable_edge_filter, smooth_neighbor, - &mut prediction, fctx, + &mut prediction, + fctx, ); } prediction @@ -17265,14 +19260,18 @@ impl PlaneBuf<'_> { let row0: Vec = prediction[..bw.min(8)].to_vec(); let col0: Vec = (0..bh.min(8)).map(|r| prediction[r * bw]).collect(); eprintln!( - "@{} OUR_PRED x={x} y={y} bw={bw} bh={bh} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}", std::panic::Location::caller(), i32::from(smooth_neighbor) + "@{} OUR_PRED x={x} y={y} bw={bw} bh={bh} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}", + std::panic::Location::caller(), + i32::from(smooth_neighbor) ); } let residual = dense_residual(residual, bw * bh); if crate::envflags::env_flag!("EC_DBG192") && y == 168 && (x == 224 || x == 232) { let res0: Vec = residual[..bw.min(8)].to_vec(); let pred0: Vec = prediction[..bw.min(8)].to_vec(); - eprintln!("DBG192 rect x={x} y={y} bw={bw} bh={bh} mode={mode} pred0={pred0:?} res0={res0:?}"); + eprintln!( + "DBG192 rect x={x} y={y} bw={bw} bh={bh} mode={mode} pred0={pred0:?} res0={res0:?}" + ); } for row in 0..bh { // Same bottom/right frame-edge clip as [`Self::reconstruct`]'s @@ -17299,10 +19298,12 @@ impl PlaneBuf<'_> { // samples do not is either a residual defect or a later overwrite, and // only this print separates the two. if crate::envflags::env_flag!("EC_PRED") { - let row0: Vec = - (0..bw.min(8)).map(|c| self.data[y * self.width + x + c]).collect(); - let col0: Vec = - (0..bh.min(8)).map(|r| self.data[(y + r) * self.width + x]).collect(); + let row0: Vec = (0..bw.min(8)) + .map(|c| self.data[y * self.width + x + c]) + .collect(); + let col0: Vec = (0..bh.min(8)) + .map(|r| self.data[(y + r) * self.width + x]) + .collect(); eprintln!("OUR_RECON x={x} y={y} bw={bw} bh={bh} row0={row0:?} col0={col0:?}"); } } @@ -17337,7 +19338,8 @@ impl PlaneBuf<'_> { // lane-wave1 step (i): the palette/intrabc prediction override, taken // off `FrameCtx::palette_pred` by the PUSH site (parse order) rather // than by this replay. - pred: Option>, fctx: &crate::decode::FrameCtx, + pred: Option>, + fctx: &crate::decode::FrameCtx, ) { // A palette block's own [`PALETTE_PRED`] override (lane-palette r2) // takes priority over `predict()`/`predict_filter_intra` entirely -- @@ -17362,7 +19364,8 @@ impl PlaneBuf<'_> { corner, side, side, - &mut prediction, fctx, + &mut prediction, + fctx, ); } else { // `enable_intra_edge_filter` is the sequence header's own flag @@ -17383,7 +19386,8 @@ impl PlaneBuf<'_> { side, enable_edge_filter, smooth_neighbor, - &mut prediction, fctx, + &mut prediction, + fctx, ); } prediction @@ -17395,25 +19399,30 @@ impl PlaneBuf<'_> { let row0: Vec = prediction[..side.min(8)].to_vec(); let col0: Vec = (0..side.min(8)).map(|r| prediction[r * side]).collect(); eprintln!( - "@{} OUR_PRED x={x} y={y} side={side} side={side} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}", std::panic::Location::caller(), i32::from(smooth_neighbor) + "@{} OUR_PRED x={x} y={y} side={side} side={side} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}", + std::panic::Location::caller(), + i32::from(smooth_neighbor) ); } let residual = dense_residual(residual, side * side); if crate::envflags::env_flag!("EC_DBG192") && y == 168 && (x == 224 || x == 232) { let res0: Vec = residual[..side.min(8)].to_vec(); let pred0: Vec = prediction[..side.min(8)].to_vec(); - eprintln!("DBG192 sq x={x} y={y} side={side} mode={mode} cfl={} pred0={pred0:?} res0={res0:?}", cfl.is_some()); + eprintln!( + "DBG192 sq x={x} y={y} side={side} mode={mode} cfl={} pred0={pred0:?} res0={res0:?}", + cfl.is_some() + ); } for row in 0..side { - // lane-sb128c r8: libaom's frame buffer is superblock - // aligned; ours is padded to 32 (`block_grid`), so a 64x64 - // transform unit of a 128x64 block at the BOTTOM frame edge - // can hang past the last padded row (1920x792: a unit at - // y=768 wants 832 rows of an 800-row buffer, which panicked - // the film's key frames). Those samples are outside the - // frame: never output, and no block below ever references - // them. - if y + row >= self.height { + // lane-sb128c r8: libaom's frame buffer is superblock + // aligned; ours is padded to 32 (`block_grid`), so a 64x64 + // transform unit of a 128x64 block at the BOTTOM frame edge + // can hang past the last padded row (1920x792: a unit at + // y=768 wants 832 rows of an 800-row buffer, which panicked + // the film's key frames). Those samples are outside the + // frame: never output, and no block below ever references + // them. + if y + row >= self.height { break; } for col in 0..side { @@ -17469,7 +19478,8 @@ fn read_plane( // formula below. luma_skip_ctx: Option, // See [`PlaneBuf::reconstruct`]'s own doc: caller's neighbour-smooth check. - smooth_neighbor: bool, fctx: &crate::decode::FrameCtx, + smooth_neighbor: bool, + fctx: &crate::decode::FrameCtx, ) -> Result { // lane-av1mono: a monochrome frame has `NumPlanes == 1`, so libaom's // coefficient loop (`for (plane = 0; plane < av1_num_planes(cm); ++plane)`) @@ -17495,7 +19505,11 @@ fn read_plane( // filter-intra is on) -- caller passes the raw filter-intra mode 0..4 in // `filter_intra`, only meaningful for `plane_idx == 0` (chroma has no // filter-intra in AV1). - let tx_mode = if plane_idx == 0 { fi_tx_row(tx_mode, filter_intra) } else { tx_mode }; + let tx_mode = if plane_idx == 0 { + fi_tx_row(tx_mode, filter_intra) + } else { + tx_mode + }; let mut coding = cdfs.txb(set, tx_mode); // libaom `read_tx_type` (`av1/decoder/decodetxb.c`): "No need to read // transform type for lossless mode(qindex==0)" -- the symbol is not coded @@ -17531,7 +19545,11 @@ fn read_plane( }; // libaom `av1_get_tx_type` (`blockd.h`): a lossless block's type is // DCT_DCT on EVERY plane, so chroma never inherits or mode-derives one. - let default_tx_type = if lossless(fctx) { TxType::DctDct } else { default_tx_type }; + let default_tx_type = if lossless(fctx) { + TxType::DctDct + } else { + default_tx_type + }; let (grid, tx_type) = read_coeffs( dec, &mut coding, @@ -17556,14 +19574,22 @@ fn read_plane( let levels = extend_corner(grid, tx_side, tx_side, side, side); let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx); let tx = TxParams { - w: side, h: side, bit_depth: bit_depth(fctx), q_idx: block_q_idx(fctx), dc_delta, - ac_delta, tx_type, qm: block_iqmatrix(fctx, plane_idx, side, side, tx_type), stride: 0, + w: side, + h: side, + bit_depth: bit_depth(fctx), + q_idx: block_q_idx(fctx), + dc_delta, + ac_delta, + tx_type, + qm: block_iqmatrix(fctx, plane_idx, side, side, tx_type), + stride: 0, lossless: lossless(fctx), }; if crate::envflags::env_flag!("EC_AV1_TRACE") { let residual = tx.run(&levels); eprintln!( - "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={:?} residual={residual:?}", &*levels, + "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={:?} residual={residual:?}", + &*levels, ); } push_intra_tx( @@ -17580,7 +19606,8 @@ fn read_plane( &levels, cfl, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); // `record`'s neighbour state only reads whether *the coded grid* (not the // residual) has nonzero entries, so the levels this function already @@ -17607,14 +19634,40 @@ fn push_intra_unit( residual: &[i32], cfl: Option<(i32, CflSrc)>, filter_intra: Option, - smooth_neighbor: bool, fctx: &crate::decode::FrameCtx, + smooth_neighbor: bool, + fctx: &crate::decode::FrameCtx, ) { if w == h { - push_intra(plane, x, y, w, mode, angle_delta, reach, residual, cfl, - filter_intra, smooth_neighbor, fctx); + push_intra( + plane, + x, + y, + w, + mode, + angle_delta, + reach, + residual, + cfl, + filter_intra, + smooth_neighbor, + fctx, + ); } else { - push_intra_rect(plane, x, y, w, h, mode, angle_delta, reach, residual, cfl, - filter_intra, smooth_neighbor, fctx); + push_intra_rect( + plane, + x, + y, + w, + h, + mode, + angle_delta, + reach, + residual, + cfl, + filter_intra, + smooth_neighbor, + fctx, + ); } } @@ -17663,7 +19716,8 @@ fn read_rect_chroma_unit( // rect unit except in the chunk arms. chroma_skip_offset: Option, cfl: Option<(i32, CflSrc)>, - smooth_neighbor_uv: bool, fctx: &crate::decode::FrameCtx, + smooth_neighbor_uv: bool, + fctx: &crate::decode::FrameCtx, ) -> Result { if ss_x(fctx) == 1 && ss_y(fctx) == 0 && w != h { hit!(CHROMA422_RECT_HITS); @@ -17671,25 +19725,46 @@ fn read_rect_chroma_unit( let default_tx = if w.max(h) >= 32 { TxType::DctDct } else { - fctx - .intrabc_chroma_tx + fctx.intrabc_chroma_tx .with(std::cell::Cell::get) .unwrap_or_else(|| default_intra_tx_type(uv_predict_mode as u8)) }; let mut coding = cdfs.txb(set, uv_predict_mode); let (levels, tx_type) = read_coeffs_rect( - dec, &mut coding, scan, w, h, + dec, + &mut coding, + scan, + w, + h, usize::from(around.0) + usize::from(around.1) + chroma_skip_offset.unwrap_or(0), - dc_sign_ctx(around.2), default_tx, + dc_sign_ctx(around.2), + default_tx, )?; let residual = dequant_and_inverse_typed_wh( - &levels, w, h, crate::decode::bit_depth(fctx), block_q_idx(fctx), - plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1, - tx_type, block_iqmatrix(fctx, plane_idx, w, h, tx_type), + &levels, + w, + h, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(plane_idx, fctx).0, + plane_q_delta(plane_idx, fctx).1, + tx_type, + block_iqmatrix(fctx, plane_idx, w, h, tx_type), ); push_intra_rect( - plane_idx, x, y, w, h, uv_predict_mode, angle_delta_uv, reach, - &residual, cfl, None, smooth_neighbor_uv, fctx, + plane_idx, + x, + y, + w, + h, + uv_predict_mode, + angle_delta_uv, + reach, + &residual, + cfl, + None, + smooth_neighbor_uv, + fctx, ); Ok(levels) } @@ -17722,7 +19797,8 @@ fn decode_block( scan8: &[u16], scan4: &[u16], tx_select: bool, - reduced_tx_set: bool, fctx: &crate::decode::FrameCtx, + reduced_tx_set: bool, + fctx: &crate::decode::FrameCtx, ) -> Result<()> { let (r, c) = at; let (px, py) = (c * SUB, r * SUB); @@ -17730,23 +19806,33 @@ fn decode_block( let palette_uv_cache = neighbours.palette_uv_cache(at); let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); let at_tile_left = c == neighbours.tile_col0_mi / (SUB / MI); - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = - read_intra_mode( - dec, - cdfs, - nb_above_mode, - nb_left_mode, - cfl, - side, - enable_filter_intra, - neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)), - allow_screen_content_tools, - allow_intrabc, - Some((palette_ctx, &palette_cache)), - &palette_uv_cache, - r * (SUB / MI), - c * (SUB / MI), fctx, - )?; + let ( + skip, + mode, + angle_delta_y, + uv_mode, + angle_delta_uv, + alpha, + filter_intra, + palette_y, + palette_uv, + ) = read_intra_mode( + dec, + cdfs, + nb_above_mode, + nb_left_mode, + cfl, + side, + enable_filter_intra, + neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)), + allow_screen_content_tools, + allow_intrabc, + Some((palette_ctx, &palette_cache)), + &palette_uv_cache, + r * (SUB / MI), + c * (SUB / MI), + fctx, + )?; if at_tile_left && palette_y.is_some() { hit!(PALETTE_TILE_LEFT_HITS); } @@ -17871,8 +19957,17 @@ fn decode_block( for row in (0..side_mi).step_by(max_tx / MI) { for col in (0..side_mi).step_by(max_tx / MI) { read_var_tx_size( - dec, cdfs, neighbours, (mi_r, mi_c), side, - (max_w_mi, max_h_mi), (max_tx, max_tx), 0, row, col, &mut leaves, + dec, + cdfs, + neighbours, + (mi_r, mi_c), + side, + (max_w_mi, max_h_mi), + (max_tx, max_tx), + 0, + row, + col, + &mut leaves, ); } } @@ -17885,9 +19980,11 @@ fn decode_block( // transform unit), so mixed sizes reconstruct at their own stride. // The counter marks the shape so a gate can prove a witness actually // carries a mixed tree and not merely another uniform one. - let uniform = leaves - .first() - .is_some_and(|f| leaves.iter().all(|l| (l.2, l.3) == (f.2, f.3) && l.2 == l.3)); + let uniform = leaves.first().is_some_and(|f| { + leaves + .iter() + .all(|l| (l.2, l.3) == (f.2, f.3) && l.2 == l.3) + }); if !uniform { hit!(INTRABC_VARTX_MIXED_LEAVES_HITS); if crate::envflags::env_flag!("EC_AV1_IBCVTX_DEBUG") { @@ -17943,21 +20040,45 @@ fn decode_block( let intrabc_bufs = intrabc_dv.map(|(dv_row, dv_col)| { let mut yb = vec![0u16; side * side]; mc::predict_with_filter( - &y.data, y.width, y.true_width, y.true_height, - mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0), - side, side, mc::InterpFilterKind::Bilinear, &mut yb, fctx, + &y.data, + y.width, + y.true_width, + y.true_height, + mv_to_q4(px, dv_col, 0), + mv_to_q4(py, dv_row, 0), + side, + side, + mc::InterpFilterKind::Bilinear, + &mut yb, + fctx, ); let mut ub = vec![0u16; chroma_side * chroma_height]; mc::predict_with_filter( - &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), - chroma_side, chroma_height, mc::InterpFilterKind::Bilinear, &mut ub, fctx, + &u.data, + u.width, + u.true_width, + u.true_height, + mv_to_q4(cpx, dv_col, ss_x(fctx)), + mv_to_q4(cpy, dv_row, ss_y(fctx)), + chroma_side, + chroma_height, + mc::InterpFilterKind::Bilinear, + &mut ub, + fctx, ); let mut vb = vec![0u16; chroma_side * chroma_height]; mc::predict_with_filter( - &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), - chroma_side, chroma_height, mc::InterpFilterKind::Bilinear, &mut vb, fctx, + &v.data, + v.width, + v.true_width, + v.true_height, + mv_to_q4(cpx, dv_col, ss_x(fctx)), + mv_to_q4(cpy, dv_row, ss_y(fctx)), + chroma_side, + chroma_height, + mc::InterpFilterKind::Bilinear, + &mut vb, + fctx, ); (yb, ub, vb) }); @@ -17969,12 +20090,9 @@ fn decode_block( // would need the map sliced per-TU -- untested against a real // `--enable-palette=1` stream this round, so refuse by name rather than // guess at the slicing (charter's own named-acceptable fallback). - let palette_y_buf: Option> = palette_y.as_ref().map(|py| { - py.map - .iter() - .map(|&idx| py.colors[idx as usize]) - .collect() - }); + let palette_y_buf: Option> = palette_y + .as_ref() + .map(|py| py.map.iter().map(|&idx| py.colors[idx as usize]).collect()); // lane-t900 r32: the intrabc luma prediction rides the very same // whole-block override slot, so the multi-TU loop below windows it per // transform unit exactly like a palette map -- setting it once up front @@ -18017,8 +20135,14 @@ fn decode_block( // either of these run. let palette_uv_bufs: Option<(Vec, Vec)> = palette_uv.as_ref().map(|puv| { ( - puv.map.iter().map(|&idx| puv.u_colors[idx as usize]).collect(), - puv.map.iter().map(|&idx| puv.v_colors[idx as usize]).collect(), + puv.map + .iter() + .map(|&idx| puv.u_colors[idx as usize]) + .collect(), + puv.map + .iter() + .map(|&idx| puv.v_colors[idx as usize]) + .collect(), ) }); // The chroma half of the intrabc prediction rides the same per-plane @@ -18047,8 +20171,7 @@ fn decode_block( // per-unit prediction is keyed on the transform being smaller than // the block, not on the tx-depth syntax. The counter keeps lane-hgkf's // narrower meaning (a READ split tx depth). - let split_tx_skip = - logical_tx < side && palette_y_buf.is_none() && intrabc_bufs.is_none(); + let split_tx_skip = logical_tx < side && palette_y_buf.is_none() && intrabc_bufs.is_none(); if split_tx_skip { if tx_select { hit!(SKIP_SPLIT_TX_HITS); @@ -18071,9 +20194,11 @@ fn decode_block( px, py, y.width, - y.height, fctx, + y.height, + fctx, ); - push_intra(0, + push_intra( + 0, tu_px, tu_py, logical_tx, @@ -18083,12 +20208,14 @@ fn decode_block( &ZERO_RESIDUAL[..logical_tx * logical_tx], None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); } } } else { - push_intra(0, + push_intra( + 0, px, py, side, @@ -18098,7 +20225,8 @@ fn decode_block( &ZERO_RESIDUAL[..side * side], None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); } let ac = alpha.map(|_| cfl_src(px, py, side)); @@ -18119,16 +20247,26 @@ fn decode_block( reach } else { tu_reach_rect( - side, side, - cu_col * luma_span_x, cu_row * luma_span_y, luma_span_x, luma_span_y, - reach, px, py, y.width, y.height, fctx, + side, + side, + cu_col * luma_span_x, + cu_row * luma_span_y, + luma_span_x, + luma_span_y, + reach, + px, + py, + y.width, + y.height, + fctx, ) }; let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h); if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - push_intra_unit(1, + push_intra_unit( + 1, cu_x, cu_y, chroma_tx, @@ -18139,12 +20277,14 @@ fn decode_block( &ZERO_RESIDUAL[..chroma_tx * chroma_tx_h], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - push_intra_unit(2, + push_intra_unit( + 2, cu_x, cu_y, chroma_tx, @@ -18155,14 +20295,21 @@ fn decode_block( &ZERO_RESIDUAL[..chroma_tx * chroma_tx_h], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); } } let luma_grid = vec![0i32; side * side]; let u_grid = vec![0i32; chroma_side * chroma_side]; let v_grid = vec![0i32; chroma_side * chroma_side]; - neighbours.record(at, side, mode, uv_predict_mode, &[&luma_grid[..], &u_grid[..], &v_grid[..]]); + neighbours.record( + at, + side, + mode, + uv_predict_mode, + &[&luma_grid[..], &u_grid[..], &v_grid[..]], + ); } else if logical_tx == side { // lane-sb128b r1: the test used to be `!tx_select || logical_tx == side`. // Without `tx_select` `logical_tx` IS `side` at every size <= 64, so @@ -18193,14 +20340,16 @@ fn decode_block( None, filter_intra, None, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, )?; let ac = alpha.map(|_| cfl_src(px, py, side)); // Armed for exactly this block's two chroma reads (see // [`INTRABC_CHROMA_TX`]); the luma call above just set // [`LUMA_TX_TYPE`] to the type it coded. if intrabc_dv.is_some() { - fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get)))); + fctx.intrabc_chroma_tx + .with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get)))); } // lane-av1-444: this arm is one luma TU (`logical_tx == side`), including // the 64x64 case whose coefficient grid is 32. At 4:4:4 the chroma plane @@ -18219,63 +20368,65 @@ fn decode_block( let luma_span_y = chroma_tx_h << ss_y(fctx); let (u_grid, v_grid, chroma_units) = if cn_rows == 1 && cn_cols == 1 { if chroma_tx == chroma_tx_h { - if let Some((ub, _)) = &palette_uv_bufs { - set_palette_pred(ub.clone(), fctx); - } - let u_grid = read_plane( - dec, - cdfs, - chroma_set, - scans.1, - 1, - around[1], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - u, - cpx, - cpy, - chroma_side, - chroma_tx, - base_q_idx, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )?; - if crate::envflags::env_flag!("EC_AV1_TRACE") { - eprintln!( - "TRACE u-write cpx={cpx} cpy={cpy} chroma_side={chroma_side} row0={:?}", - &u.data[cpy * u.width + cpx..][..chroma_side] - ); - } - if let Some((_, vb)) = &palette_uv_bufs { - set_palette_pred(vb.clone(), fctx); - } - let v_grid = read_plane( - dec, - cdfs, - chroma_set, - scans.1, - 2, - around[2], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - v, - cpx, - cpy, - chroma_side, - chroma_tx, - base_q_idx, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )?; - (u_grid, v_grid, Vec::new()) + if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone(), fctx); + } + let u_grid = read_plane( + dec, + cdfs, + chroma_set, + scans.1, + 1, + around[1], + mode, + uv_predict_mode, + angle_delta_uv, + reach, + u, + cpx, + cpy, + chroma_side, + chroma_tx, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + None, + smooth_neighbor_uv, + fctx, + )?; + if crate::envflags::env_flag!("EC_AV1_TRACE") { + eprintln!( + "TRACE u-write cpx={cpx} cpy={cpy} chroma_side={chroma_side} row0={:?}", + &u.data[cpy * u.width + cpx..][..chroma_side] + ); + } + if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone(), fctx); + } + let v_grid = read_plane( + dec, + cdfs, + chroma_set, + scans.1, + 2, + around[2], + mode, + uv_predict_mode, + angle_delta_uv, + reach, + v, + cpx, + cpy, + chroma_side, + chroma_tx, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + None, + smooth_neighbor_uv, + fctx, + )?; + (u_grid, v_grid, Vec::new()) } else { // lane-av1-422f: the one unit is a RECT filling the plane // block -- the square-shaped [`read_plane`] cannot express @@ -18283,27 +20434,54 @@ fn decode_block( // (U, then V, the same order the square arm reads). The // chroma context reads per chroma 4-px cell (see // [`Neighbours::around_mi_422_chroma`]). - let chroma_around = - neighbours.around_mi_422_chroma((mi_r, mi_c), side, side); + let chroma_around = neighbours.around_mi_422_chroma((mi_r, mi_c), side, side); if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } let u_grid = read_rect_chroma_unit( - dec, cdfs, chroma_set, scans.1, chroma_tx, chroma_tx_h, 1, - chroma_around[1], uv_predict_mode, angle_delta_uv, reach, u, - cpx, cpy, base_q_idx, None, + dec, + cdfs, + chroma_set, + scans.1, + chroma_tx, + chroma_tx_h, + 1, + chroma_around[1], + uv_predict_mode, + angle_delta_uv, + reach, + u, + cpx, + cpy, + base_q_idx, + None, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, )?; if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } let v_grid = read_rect_chroma_unit( - dec, cdfs, chroma_set, scans.1, chroma_tx, chroma_tx_h, 2, - chroma_around[2], uv_predict_mode, angle_delta_uv, reach, v, - cpx, cpy, base_q_idx, None, + dec, + cdfs, + chroma_set, + scans.1, + chroma_tx, + chroma_tx_h, + 2, + chroma_around[2], + uv_predict_mode, + angle_delta_uv, + reach, + v, + cpx, + cpy, + base_q_idx, + None, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, )?; (u_grid, v_grid, Vec::new()) } @@ -18338,16 +20516,20 @@ fn decode_block( px, py, y.width, - y.height, fctx, + y.height, + fctx, ); - let (cu_x, cu_y) = - (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h); + let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h); if let Some((ub, vb)) = &palette_uv_bufs { let pbuf = if plane_pass == 1 { ub } else { vb }; set_palette_pred( palette_window( - pbuf, chroma_side, cu_col * chroma_tx, - cu_row * chroma_tx_h, chroma_tx, chroma_tx_h, + pbuf, + chroma_side, + cu_col * chroma_tx, + cu_row * chroma_tx_h, + chroma_tx, + chroma_tx_h, ), fctx, ); @@ -18355,13 +20537,29 @@ fn decode_block( let buf: &mut PlaneBuf<'static> = if plane_pass == 1 { &mut *u } else { &mut *v }; let cu_grid = read_plane( - dec, cdfs, chroma_set, scans.1, plane_pass, cu_around[plane_pass], mode, - uv_predict_mode, angle_delta_uv, cu_reach, buf, cu_x, cu_y, - chroma_tx, chroma_tx, base_q_idx, - alpha.zip(ac).map(|((au, av), ac)| { - (if plane_pass == 1 { au } else { av }, ac) - }), - None, chroma_ctx_offset, smooth_neighbor_uv, fctx, + dec, + cdfs, + chroma_set, + scans.1, + plane_pass, + cu_around[plane_pass], + mode, + uv_predict_mode, + angle_delta_uv, + cu_reach, + buf, + cu_x, + cu_y, + chroma_tx, + chroma_tx, + base_q_idx, + alpha + .zip(ac) + .map(|((au, av), ac)| (if plane_pass == 1 { au } else { av }, ac)), + None, + chroma_ctx_offset, + smooth_neighbor_uv, + fctx, )?; hit!(CHROMA_SPLIT_TX_HITS); if ss_x(fctx) == 1 && ss_y(fctx) == 0 { @@ -18372,13 +20570,23 @@ fn decode_block( // chroma state across the whole block; the replay after // it puts the per-unit state back. neighbours.record_mi_chroma( - cu_mi, luma_span_x, luma_span_y, plane_pass, &cu_grid, + cu_mi, + luma_span_x, + luma_span_y, + plane_pass, + &cu_grid, ); if plane_pass == 1 { u_pass.push(cu_grid); } else { let u_grid = std::mem::replace(&mut u_pass[pass_idx], Grid::Zero(0)); - units.push((cu_mi, luma_span_x, luma_span_y, u_grid.clone(), cu_grid.clone())); + units.push(( + cu_mi, + luma_span_x, + luma_span_y, + u_grid.clone(), + cu_grid.clone(), + )); last_grids = [u_grid, cu_grid]; } pass_idx += 1; @@ -18388,7 +20596,13 @@ fn decode_block( (last_grids[0].clone(), last_grids[1].clone(), units) }; fctx.intrabc_chroma_tx.with(|c| c.set(None)); - neighbours.record(at, side, mode, uv_predict_mode, &[&luma_grid[..], &u_grid[..], &v_grid[..]]); + neighbours.record( + at, + side, + mode, + uv_predict_mode, + &[&luma_grid[..], &u_grid[..], &v_grid[..]], + ); for (cu_mi, sw, sh, u_unit, v_unit) in &chroma_units { neighbours.record_mi_chroma(*cu_mi, *sw, *sh, 1, u_unit); neighbours.record_mi_chroma(*cu_mi, *sw, *sh, 2, v_unit); @@ -18450,289 +20664,349 @@ fn decode_block( let mut last_grids = [Grid::Zero(0), Grid::Zero(0)]; let mut units: Vec<((usize, usize), usize, usize, Grid, Grid)> = Vec::new(); for ch_row in 0..nchunk { - for ch_col in 0..nchunk { - // lane-av1-ibcvtx: the chunk's chroma units inherit the CHROMA tx - // type of the co-located luma position (`av1_get_tx_type`, - // blockd.h:1278: a non-Y plane of an inter-classified block -- and - // intrabc is one -- reads `tx_type_map`, i.e. the coded type of the - // luma unit covering it). Inside a mu chunk that is the chunk's - // FIRST luma unit in raster order (the chunk origin is always the - // first leaf's own origin). Captured right after that unit's read; - // the single-TU arm below does the same for a whole-block unit. - let mut first_leaf_tx: Option = None; - for &(tu_off_y, tu_off_x, tu_tx) in &chunk_tus[ch_row * nchunk + ch_col] { - let tu_mi = (mi_r + tu_off_y / MI, mi_c + tu_off_x / MI); - let tu_px = px + tu_off_x; - let tu_py = py + tu_off_y; - // Same libaom clip as `decode_rect_split`'s loop above; a - // square block only hangs off the frame when the frame's mi - // dimensions are odd at the block's own level. - if tu_px >= y.true_width || tu_py >= y.true_height { - continue; - } - let tu_around = neighbours.around_mi(tu_mi, tu_tx)[0]; - // A transform unit inside a block is NOT a block at that - // position (lane-palette2 r12): `Reach::of` granted the - // top-right 8x8 unit of a 16x16 D203 block bottom-left - // pixels libaom refuses outright (`col_off > 0`), which is - // the diagonal wedge seed 46 reconstructed wrong. - let tu_reach = tu_reach( - side, - side, - tu_off_x, - tu_off_y, - tu_tx, - reach, - px, - py, - y.width, - y.height, fctx, - ); - // This transform unit's own bsize (`tu_tx`) is smaller - // than the block it sits in (`side`), so `txb_skip_ctx` is - // the neighbour-magnitude table, not the lone-TU 0 (spec - // `get_txb_ctx_general`'s `plane_bsize != tx_size` branch). - let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tu_tx / MI); - // An intrabc unit's CDF set and scan follow the unit's OWN - // resolved size (`get_txsize_entropy_ctx` / - // `av1_get_scan` per `av1_read_coeffs_txb` call); the - // uniform grid's precomputed pair already matches because - // `tu_tx == logical_tx` there. - let (tu_set, tu_scan) = if intrabc_dv.is_some() { - ( - inter_txbset_for(tu_tx, reduced_tx_set), - scan_for(if tu_tx == 64 { 32 } else { tu_tx }, scan32, scan16, scan8, scan4), - ) - } else { - (luma_set, luma_scan) - }; - if let Some(buf) = &palette_y_buf { - hit!(PALETTE_SPLIT_TX_HITS); - let mut window = vec![0u16; tu_tx * tu_tx]; - for row in 0..tu_tx { - let src = (tu_off_y + row) * side + tu_off_x; - window[row * tu_tx..][..tu_tx] - .copy_from_slice(&buf[src..][..tu_tx]); + for ch_col in 0..nchunk { + // lane-av1-ibcvtx: the chunk's chroma units inherit the CHROMA tx + // type of the co-located luma position (`av1_get_tx_type`, + // blockd.h:1278: a non-Y plane of an inter-classified block -- and + // intrabc is one -- reads `tx_type_map`, i.e. the coded type of the + // luma unit covering it). Inside a mu chunk that is the chunk's + // FIRST luma unit in raster order (the chunk origin is always the + // first leaf's own origin). Captured right after that unit's read; + // the single-TU arm below does the same for a whole-block unit. + let mut first_leaf_tx: Option = None; + for &(tu_off_y, tu_off_x, tu_tx) in &chunk_tus[ch_row * nchunk + ch_col] { + let tu_mi = (mi_r + tu_off_y / MI, mi_c + tu_off_x / MI); + let tu_px = px + tu_off_x; + let tu_py = py + tu_off_y; + // Same libaom clip as `decode_rect_split`'s loop above; a + // square block only hangs off the frame when the frame's mi + // dimensions are odd at the block's own level. + if tu_px >= y.true_width || tu_py >= y.true_height { + continue; } - set_palette_pred(window, fctx); - } - let tu_grid = read_plane( - dec, - cdfs, - tu_set, - tu_scan, - 0, - tu_around, - mode, - mode, - angle_delta_y, - tu_reach, - y, - tu_px, - tu_py, - tu_tx, - // The unit's own COEFFICIENT grid, half its side at - // TX_64X64 (a 64-point transform codes nothing past 32); - // identical to `tu_tx` at every smaller size - // (lane-sb128b r1). - if tu_tx == 64 { 32 } else { tu_tx }, - base_q_idx, - None, - filter_intra, - Some(tu_skip_ctx), - smooth_neighbor, fctx, - )?; - if crate::envflags::env_flag!("EC_AV1_TRACE") { - eprintln!( - "TRACE tu_bitpos mi=({},{}) tell={}", - tu_mi.0, - tu_mi.1, - dec.debug_bitpos() - ); - } - neighbours.record_mi_luma(tu_mi, tu_tx, &tu_grid); - if first_leaf_tx.is_none() { - first_leaf_tx = Some(fctx.luma_tx_type.with(std::cell::Cell::get)); - } - } - // CfL is only allowed up to 32x32, i.e. only at `nchunk == 1`, where - // this still runs after every luma unit of the block. - let ac = alpha.map(|_| cfl_src(px, py, side)); - // lane-av1-ibcvtx: an intrabc block's chroma rides the luma's coded - // tx type (see `first_leaf_tx` above) -- the same arm the single-TU - // branch sets before its own chroma reads. - if intrabc_dv.is_some() { - if let Some(t) = first_leaf_tx { - fctx.intrabc_chroma_tx.with(|c| c.set(Some(t))); - } - } - // The block's uv plane block is `chroma_side` across but its uv - // transform is `chroma_tx` (`av1_get_max_uv_txsize` = - // `av1_get_adjusted_tx_size(max_txsize_rect_lookup[uv_plane_bsize])`): - // identical at every size up to 64x64, but a 128x128 block's 64x64 uv - // plane block adjusts TX_64X64 down to TX_32X32, so each plane is - // FOUR units (lane-sb128b r2) -- one per mu chunk. - // libaom `decode_token_recon_block` codes a mu chunk PLANE-MAJOR - // (`for (plane..) for (blk_row..) for (blk_col..)`): every U unit of - // the chunk, then every V unit. At one unit per plane per chunk -- - // every non-lossless case this decoder reaches -- that is the same - // symbol order as the interleaved pair this loop used to read; a - // lossless frame's 4x4 chroma units are the case where it differs - // (lane-lossless2). - let mut u_pass: Vec = Vec::new(); - for plane_pass in 1..=2usize { - let mut pass_idx = 0usize; - for cu_row in ch_row * cpc_rows..(ch_row + 1) * cpc_rows { - for cu_col in ch_col * cpc_cols..(ch_col + 1) * cpc_cols { - // libaom `decode_reconstruct_tx`'s frame-edge clip - // (decodeframe.c:299, `blk_row >= max_blocks_high || blk_col - // >= max_blocks_wide` returns before ANY symbol is read): a - // transform unit whose 4x4 origin sits outside the frame's mi - // grid is not coded at all. The luma loop above carries the - // same clip; its absence here read `txb_skip` (+coeffs) for - // chroma units libaom never wrote -- the lossless 64x64 block - // at mi(48,0) of a 320x240 frame overhangs the bottom edge by - // 4 mi, so its 32x32 chroma codes SIX rows of 4x4 units, not - // eight (lane-av1-loss64; 48 chroma units per plane in - // aomdec's EC_COEFF census vs the 64 this loop read). - // `max_block_wide/high` (av1_common_int.h:1565): the plane - // block's pixel span (4:2:0 halves the luma span, clamped to - // 4 by `set_plane_n4`) plus the negative overhang - // (`mb_to_*_edge` = `2 * overhang_mi` chroma px), in 4x4 - // units. - let span_mi = side / MI; - let over_w_mi = - (2 * y.true_width.div_ceil(8)) as i32 - mi_c as i32 - span_mi as i32; - let over_h_mi = - (2 * y.true_height.div_ceil(8)) as i32 - mi_r as i32 - span_mi as i32; - // `max_block_wide/high` in chroma pixels: the plane block's - // own span (`side` at 4:4:4, `side / 2` at 4:2:0 -- the old - // hardcoded `span_mi * 2` clipped three quarters of a 4:4:4 - // block's coded units and desynced the tile) plus the - // negative overhang (`mb_to_*_edge >> (3 + ss)`), whose - // chroma-px scale is `MI >> ss` per mi. - let plane_px = (((span_mi * MI) >> ss_x(fctx)).max(4)) as i32; - let over_w_px = over_w_mi.min(0) * (MI >> ss_x(fctx)) as i32; - let over_h_px = over_h_mi.min(0) * (MI >> ss_y(fctx)) as i32; - let max_units_w = ((plane_px + over_w_px) >> 2).max(0) as usize; - // lane-av1-422f: the shared halved formula in the `else` counts - // the plane span in 4-px units through the 2-px-per-mi - // subsampled height, which a 4:2:2 plane does not have (ss_y - // 0) -- its span is the full luma mi count, so a keyed - // formula clips the same units libaom's `max_block_high` - // does. 4:2:0 and 4:4:4 keep the proven shared rows (at 4:2:0 - // `MI >> ss_y` is 2, the same `2 * over_h_mi.min(0)` the - // pre-ss form spelled). - let max_units_h = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { - (span_mi as i32 + over_h_mi.min(0)).max(0) as usize - } else { - ((plane_px + over_h_px) >> 2).max(0) as usize - }; - let (unit_w, unit_h) = (chroma_tx / 4, chroma_tx_h / 4); - if cu_col * unit_w >= max_units_w || cu_row * unit_h >= max_units_h { - hit!(CHROMA_EDGE_TU_CLIP_HITS); - continue; - } - // The chroma context arrays are indexed in LUMA mi, so this - // unit's anchor is its own luma quadrant (lane-av1-422b: the - // quadrant spans `chroma_tx << ss_x` luma px wide by - // `chroma_tx_h << ss_y` tall -- at 4:2:2 below side 64 the - // one unit's quadrant is the whole block). - let cu_mi = ( - mi_r + cu_row * (luma_span_y / MI), - mi_c + cu_col * (luma_span_x / MI), - ); - let cu_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { - // lane-av1-422f: chroma-only loop; per-chroma-cell above - // votes (see [`Neighbours::around_mi_422_chroma`]). - neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y) - } else { - neighbours.around_mi_rect(cu_mi, luma_span_x, luma_span_y) - }; - let cu_reach = if cn_rows == 1 && cn_cols == 1 { - reach - } else { - tu_reach_rect( - side, side, - cu_col * luma_span_x, cu_row * luma_span_y, luma_span_x, luma_span_y, - reach, px, py, y.width, y.height, fctx, - ) - }; - let (cu_x, cu_y) = - (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h); - if let Some((ub, vb)) = &palette_uv_bufs { - let pbuf = if plane_pass == 1 { ub } else { vb }; - set_palette_pred( - palette_window( - pbuf, chroma_side, cu_col * chroma_tx, - cu_row * chroma_tx_h, chroma_tx, chroma_tx_h, - ), + let tu_around = neighbours.around_mi(tu_mi, tu_tx)[0]; + // A transform unit inside a block is NOT a block at that + // position (lane-palette2 r12): `Reach::of` granted the + // top-right 8x8 unit of a 16x16 D203 block bottom-left + // pixels libaom refuses outright (`col_off > 0`), which is + // the diagonal wedge seed 46 reconstructed wrong. + let tu_reach = tu_reach( + side, side, tu_off_x, tu_off_y, tu_tx, reach, px, py, y.width, y.height, fctx, ); + // This transform unit's own bsize (`tu_tx`) is smaller + // than the block it sits in (`side`), so `txb_skip_ctx` is + // the neighbour-magnitude table, not the lone-TU 0 (spec + // `get_txb_ctx_general`'s `plane_bsize != tx_size` branch). + let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tu_tx / MI); + // An intrabc unit's CDF set and scan follow the unit's OWN + // resolved size (`get_txsize_entropy_ctx` / + // `av1_get_scan` per `av1_read_coeffs_txb` call); the + // uniform grid's precomputed pair already matches because + // `tu_tx == logical_tx` there. + let (tu_set, tu_scan) = if intrabc_dv.is_some() { + ( + inter_txbset_for(tu_tx, reduced_tx_set), + scan_for( + if tu_tx == 64 { 32 } else { tu_tx }, + scan32, + scan16, + scan8, + scan4, + ), + ) + } else { + (luma_set, luma_scan) + }; + if let Some(buf) = &palette_y_buf { + hit!(PALETTE_SPLIT_TX_HITS); + let mut window = vec![0u16; tu_tx * tu_tx]; + for row in 0..tu_tx { + let src = (tu_off_y + row) * side + tu_off_x; + window[row * tu_tx..][..tu_tx].copy_from_slice(&buf[src..][..tu_tx]); + } + set_palette_pred(window, fctx); + } + let tu_grid = read_plane( + dec, + cdfs, + tu_set, + tu_scan, + 0, + tu_around, + mode, + mode, + angle_delta_y, + tu_reach, + y, + tu_px, + tu_py, + tu_tx, + // The unit's own COEFFICIENT grid, half its side at + // TX_64X64 (a 64-point transform codes nothing past 32); + // identical to `tu_tx` at every smaller size + // (lane-sb128b r1). + if tu_tx == 64 { 32 } else { tu_tx }, + base_q_idx, + None, + filter_intra, + Some(tu_skip_ctx), + smooth_neighbor, + fctx, + )?; + if crate::envflags::env_flag!("EC_AV1_TRACE") { + eprintln!( + "TRACE tu_bitpos mi=({},{}) tell={}", + tu_mi.0, + tu_mi.1, + dec.debug_bitpos() + ); + } + neighbours.record_mi_luma(tu_mi, tu_tx, &tu_grid); + if first_leaf_tx.is_none() { + first_leaf_tx = Some(fctx.luma_tx_type.with(std::cell::Cell::get)); + } } - let buf: &mut PlaneBuf<'static> = - if plane_pass == 1 { &mut *u } else { &mut *v }; - let cu_grid = if chroma_tx == chroma_tx_h { - read_plane( - dec, cdfs, chroma_set, scans.1, plane_pass, cu_around[plane_pass], mode, - uv_predict_mode, angle_delta_uv, cu_reach, buf, cu_x, cu_y, - chroma_tx, chroma_tx, base_q_idx, - alpha.zip(ac).map(|((au, av), ac)| { - (if plane_pass == 1 { au } else { av }, ac) - }), - None, chroma_ctx_offset, smooth_neighbor_uv, fctx, - )? - } else { - // lane-av1-422f: the whole plane block as one rect unit; - // `chroma_ctx_offset` is `None` there (the unit covers - // the plane block, so the offset-7 skip rows are right). - read_rect_chroma_unit( - dec, cdfs, chroma_set, scans.1, chroma_tx, chroma_tx_h, plane_pass, - cu_around[plane_pass], uv_predict_mode, angle_delta_uv, cu_reach, buf, - cu_x, cu_y, base_q_idx, None, - alpha.zip(ac).map(|((au, av), ac)| { - (if plane_pass == 1 { au } else { av }, ac) - }), - smooth_neighbor_uv, fctx, - )? - }; - if cn_rows * cn_cols > 1 { - hit!(CHROMA_SPLIT_TX_HITS); - if ss_x(fctx) == 1 && ss_y(fctx) == 0 { - hit!(CHROMA422_SQUARE_HITS); + // CfL is only allowed up to 32x32, i.e. only at `nchunk == 1`, where + // this still runs after every luma unit of the block. + let ac = alpha.map(|_| cfl_src(px, py, side)); + // lane-av1-ibcvtx: an intrabc block's chroma rides the luma's coded + // tx type (see `first_leaf_tx` above) -- the same arm the single-TU + // branch sets before its own chroma reads. + if intrabc_dv.is_some() { + if let Some(t) = first_leaf_tx { + fctx.intrabc_chroma_tx.with(|c| c.set(Some(t))); } - // Immediately, so the NEXT unit of this same block reads - // this one's coefficient context (libaom's chroma - // `txb_skip_ctx` for the second quadrant is 11, i.e. base - // 1 from this left neighbour -- measured against aomdec). - // The same writes are replayed after `record_split_luma` - // below, which would otherwise clobber them whole-block. - neighbours.record_mi_chroma( - cu_mi, luma_span_x, luma_span_y, plane_pass, &cu_grid, - ); } - if plane_pass == 1 { - u_pass.push(cu_grid); - } else { - let u_grid = std::mem::replace(&mut u_pass[pass_idx], Grid::Zero(0)); - if cn_rows * cn_cols > 1 { - units.push((cu_mi, luma_span_x, luma_span_y, u_grid.clone(), cu_grid.clone())); + // The block's uv plane block is `chroma_side` across but its uv + // transform is `chroma_tx` (`av1_get_max_uv_txsize` = + // `av1_get_adjusted_tx_size(max_txsize_rect_lookup[uv_plane_bsize])`): + // identical at every size up to 64x64, but a 128x128 block's 64x64 uv + // plane block adjusts TX_64X64 down to TX_32X32, so each plane is + // FOUR units (lane-sb128b r2) -- one per mu chunk. + // libaom `decode_token_recon_block` codes a mu chunk PLANE-MAJOR + // (`for (plane..) for (blk_row..) for (blk_col..)`): every U unit of + // the chunk, then every V unit. At one unit per plane per chunk -- + // every non-lossless case this decoder reaches -- that is the same + // symbol order as the interleaved pair this loop used to read; a + // lossless frame's 4x4 chroma units are the case where it differs + // (lane-lossless2). + let mut u_pass: Vec = Vec::new(); + for plane_pass in 1..=2usize { + let mut pass_idx = 0usize; + for cu_row in ch_row * cpc_rows..(ch_row + 1) * cpc_rows { + for cu_col in ch_col * cpc_cols..(ch_col + 1) * cpc_cols { + // libaom `decode_reconstruct_tx`'s frame-edge clip + // (decodeframe.c:299, `blk_row >= max_blocks_high || blk_col + // >= max_blocks_wide` returns before ANY symbol is read): a + // transform unit whose 4x4 origin sits outside the frame's mi + // grid is not coded at all. The luma loop above carries the + // same clip; its absence here read `txb_skip` (+coeffs) for + // chroma units libaom never wrote -- the lossless 64x64 block + // at mi(48,0) of a 320x240 frame overhangs the bottom edge by + // 4 mi, so its 32x32 chroma codes SIX rows of 4x4 units, not + // eight (lane-av1-loss64; 48 chroma units per plane in + // aomdec's EC_COEFF census vs the 64 this loop read). + // `max_block_wide/high` (av1_common_int.h:1565): the plane + // block's pixel span (4:2:0 halves the luma span, clamped to + // 4 by `set_plane_n4`) plus the negative overhang + // (`mb_to_*_edge` = `2 * overhang_mi` chroma px), in 4x4 + // units. + let span_mi = side / MI; + let over_w_mi = (2 * y.true_width.div_ceil(8)) as i32 + - mi_c as i32 + - span_mi as i32; + let over_h_mi = (2 * y.true_height.div_ceil(8)) as i32 + - mi_r as i32 + - span_mi as i32; + // `max_block_wide/high` in chroma pixels: the plane block's + // own span (`side` at 4:4:4, `side / 2` at 4:2:0 -- the old + // hardcoded `span_mi * 2` clipped three quarters of a 4:4:4 + // block's coded units and desynced the tile) plus the + // negative overhang (`mb_to_*_edge >> (3 + ss)`), whose + // chroma-px scale is `MI >> ss` per mi. + let plane_px = (((span_mi * MI) >> ss_x(fctx)).max(4)) as i32; + let over_w_px = over_w_mi.min(0) * (MI >> ss_x(fctx)) as i32; + let over_h_px = over_h_mi.min(0) * (MI >> ss_y(fctx)) as i32; + let max_units_w = ((plane_px + over_w_px) >> 2).max(0) as usize; + // lane-av1-422f: the shared halved formula in the `else` counts + // the plane span in 4-px units through the 2-px-per-mi + // subsampled height, which a 4:2:2 plane does not have (ss_y + // 0) -- its span is the full luma mi count, so a keyed + // formula clips the same units libaom's `max_block_high` + // does. 4:2:0 and 4:4:4 keep the proven shared rows (at 4:2:0 + // `MI >> ss_y` is 2, the same `2 * over_h_mi.min(0)` the + // pre-ss form spelled). + let max_units_h = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + (span_mi as i32 + over_h_mi.min(0)).max(0) as usize + } else { + ((plane_px + over_h_px) >> 2).max(0) as usize + }; + let (unit_w, unit_h) = (chroma_tx / 4, chroma_tx_h / 4); + if cu_col * unit_w >= max_units_w || cu_row * unit_h >= max_units_h { + hit!(CHROMA_EDGE_TU_CLIP_HITS); + continue; + } + // The chroma context arrays are indexed in LUMA mi, so this + // unit's anchor is its own luma quadrant (lane-av1-422b: the + // quadrant spans `chroma_tx << ss_x` luma px wide by + // `chroma_tx_h << ss_y` tall -- at 4:2:2 below side 64 the + // one unit's quadrant is the whole block). + let cu_mi = ( + mi_r + cu_row * (luma_span_y / MI), + mi_c + cu_col * (luma_span_x / MI), + ); + let cu_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + // lane-av1-422f: chroma-only loop; per-chroma-cell above + // votes (see [`Neighbours::around_mi_422_chroma`]). + neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y) + } else { + neighbours.around_mi_rect(cu_mi, luma_span_x, luma_span_y) + }; + let cu_reach = if cn_rows == 1 && cn_cols == 1 { + reach + } else { + tu_reach_rect( + side, + side, + cu_col * luma_span_x, + cu_row * luma_span_y, + luma_span_x, + luma_span_y, + reach, + px, + py, + y.width, + y.height, + fctx, + ) + }; + let (cu_x, cu_y) = + (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h); + if let Some((ub, vb)) = &palette_uv_bufs { + let pbuf = if plane_pass == 1 { ub } else { vb }; + set_palette_pred( + palette_window( + pbuf, + chroma_side, + cu_col * chroma_tx, + cu_row * chroma_tx_h, + chroma_tx, + chroma_tx_h, + ), + fctx, + ); + } + let buf: &mut PlaneBuf<'static> = + if plane_pass == 1 { &mut *u } else { &mut *v }; + let cu_grid = if chroma_tx == chroma_tx_h { + read_plane( + dec, + cdfs, + chroma_set, + scans.1, + plane_pass, + cu_around[plane_pass], + mode, + uv_predict_mode, + angle_delta_uv, + cu_reach, + buf, + cu_x, + cu_y, + chroma_tx, + chroma_tx, + base_q_idx, + alpha.zip(ac).map(|((au, av), ac)| { + (if plane_pass == 1 { au } else { av }, ac) + }), + None, + chroma_ctx_offset, + smooth_neighbor_uv, + fctx, + )? + } else { + // lane-av1-422f: the whole plane block as one rect unit; + // `chroma_ctx_offset` is `None` there (the unit covers + // the plane block, so the offset-7 skip rows are right). + read_rect_chroma_unit( + dec, + cdfs, + chroma_set, + scans.1, + chroma_tx, + chroma_tx_h, + plane_pass, + cu_around[plane_pass], + uv_predict_mode, + angle_delta_uv, + cu_reach, + buf, + cu_x, + cu_y, + base_q_idx, + None, + alpha.zip(ac).map(|((au, av), ac)| { + (if plane_pass == 1 { au } else { av }, ac) + }), + smooth_neighbor_uv, + fctx, + )? + }; + if cn_rows * cn_cols > 1 { + hit!(CHROMA_SPLIT_TX_HITS); + if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + hit!(CHROMA422_SQUARE_HITS); + } + // Immediately, so the NEXT unit of this same block reads + // this one's coefficient context (libaom's chroma + // `txb_skip_ctx` for the second quadrant is 11, i.e. base + // 1 from this left neighbour -- measured against aomdec). + // The same writes are replayed after `record_split_luma` + // below, which would otherwise clobber them whole-block. + neighbours.record_mi_chroma( + cu_mi, + luma_span_x, + luma_span_y, + plane_pass, + &cu_grid, + ); + } + if plane_pass == 1 { + u_pass.push(cu_grid); + } else { + let u_grid = + std::mem::replace(&mut u_pass[pass_idx], Grid::Zero(0)); + if cn_rows * cn_cols > 1 { + units.push(( + cu_mi, + luma_span_x, + luma_span_y, + u_grid.clone(), + cu_grid.clone(), + )); + } + last_grids = [u_grid, cu_grid]; + } + pass_idx += 1; + } } - last_grids = [u_grid, cu_grid]; } - pass_idx += 1; } - } - } - } - if intrabc_dv.is_some() { - fctx.intrabc_chroma_tx.with(|c| c.set(None)); - } + if intrabc_dv.is_some() { + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + } } // Mode/side bookkeeping plus, at `cn == 1`, the whole-plane chroma // context write; at `cn > 1` the per-unit writes above are what the // next block reads, so they run after this (last writer wins). - neighbours.record_split_luma(at, side, mode, uv_predict_mode, [&last_grids[0], &last_grids[1]]); + neighbours.record_split_luma( + at, + side, + mode, + uv_predict_mode, + [&last_grids[0], &last_grids[1]], + ); for (cu_mi, sw, sh, u_grid, v_grid) in &units { neighbours.record_mi_chroma(*cu_mi, *sw, *sh, 1, u_grid); neighbours.record_mi_chroma(*cu_mi, *sw, *sh, 2, v_grid); @@ -18756,7 +21030,8 @@ fn decode_block( (r * (SUB / MI), c * (SUB / MI)), side / MI, logical_tx as u8, - 0, fctx, + 0, + fctx, ); // lane-t900 r32 / lane-av1txbands: libaom runs `set_txfm_ctxs(mbmi->tx_size, // n4_w, n4_h, skip_txfm && is_inter_block(mbmi), xd)` at the end of EVERY @@ -18910,7 +21185,8 @@ fn decode_block_128rect( enable_filter_intra: bool, allow_screen_content_tools: bool, tx_select: bool, - reduced_tx_set: bool, fctx: &crate::decode::FrameCtx, + reduced_tx_set: bool, + fctx: &crate::decode::FrameCtx, ) -> Result<()> { let (r, c) = at; let (px, py) = (c * SUB, r * SUB); @@ -18918,26 +21194,37 @@ fn decode_block_128rect( let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); let palette_uv_cache = neighbours.palette_uv_cache(at); - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv, intrabc) = - read_intra_mode_rect( - dec, - cdfs, - nb_above_mode, - nb_left_mode, - // `is_cfl_allowed` caps CFL at 32x32: `uv_mode` comes off the - // 13-symbol no-CFL CDF here, never the 14-symbol one. - false, - true, - bw, - bh, - enable_filter_intra, - neighbours.skip_txfm_ctx(mi_r, mi_c), - allow_screen_content_tools, - Some((palette_ctx, &palette_cache)), - &palette_uv_cache, - mi_r, - mi_c, fctx, - )?; + let ( + skip, + mode, + angle_delta_y, + uv_mode, + angle_delta_uv, + alpha, + filter_intra, + palette_y, + palette_uv, + intrabc, + ) = read_intra_mode_rect( + dec, + cdfs, + nb_above_mode, + nb_left_mode, + // `is_cfl_allowed` caps CFL at 32x32: `uv_mode` comes off the + // 13-symbol no-CFL CDF here, never the 14-symbol one. + false, + true, + bw, + bh, + enable_filter_intra, + neighbours.skip_txfm_ctx(mi_r, mi_c), + allow_screen_content_tools, + Some((palette_ctx, &palette_cache)), + &palette_uv_cache, + mi_r, + mi_c, + fctx, + )?; if let Some((dv_row, dv_col)) = intrabc { // lane-av1-ibcrect: the reconstruction is ported -- an intrabc block // is is_inter_block, so libaom predicts the whole 128x64/64x128 strip @@ -18954,7 +21241,8 @@ fn decode_block_128rect( y, u, v, - base_q_idx, fctx, + base_q_idx, + fctx, ); } if alpha.is_some() || filter_intra.is_some() || palette_y.is_some() || palette_uv.is_some() { @@ -18963,7 +21251,11 @@ fn decode_block_128rect( their size gates caps at 64x64 or below, so none of these symbols exists there)", )); } - let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + let uv_predict_mode = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode); if smooth_neighbor { hit!(SMOOTH_LUMA_HITS); @@ -18978,7 +21270,10 @@ fn decode_block_128rect( // (`decodeframe.c:1183`). So `tx_select` is off, every plane is walked as // TX_4X4 transform units, and no `tx_size_cat3` symbol may be consumed. let lossless_frame = lossless(fctx); - let in_inter = fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_some(); + let in_inter = fctx + .intra_in_inter_mode + .with(std::cell::Cell::get) + .is_some(); let depth = if tx_select && !lossless_frame { // lane-inter128intra r1: `get_tx_size_context` compares the bands // against `tx_size_wide/high[max_txsize_rect_lookup[bsize]]` -- @@ -19082,12 +21377,23 @@ fn decode_block_128rect( px, py, y.width, - y.height, fctx, + y.height, + fctx, ); if skip { - push_intra(0, - tu_px, tu_py, logical_tx, mode, angle_delta_y, tu_r, &zero_tu, None, - None, smooth_neighbor, fctx, + push_intra( + 0, + tu_px, + tu_py, + logical_tx, + mode, + angle_delta_y, + tu_r, + &zero_tu, + None, + None, + smooth_neighbor, + fctx, ); neighbours.record_mi_luma(tu_mi, logical_tx, &zero_tu); continue; @@ -19116,7 +21422,8 @@ fn decode_block_128rect( None, None, Some(tu_skip_ctx), - smooth_neighbor, fctx, + smooth_neighbor, + fctx, )?; neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid); } @@ -19167,24 +21474,51 @@ fn decode_block_128rect( px, py, y.width, - y.height, fctx, + y.height, + fctx, ); if skip { - push_intra(plane_pass, - cu_x, cu_y, chroma_tx, uv_predict_mode, angle_delta_uv, cu_r, - &zero_cu, None, None, smooth_neighbor_uv, fctx, + push_intra( + plane_pass, + cu_x, + cu_y, + chroma_tx, + uv_predict_mode, + angle_delta_uv, + cu_r, + &zero_cu, + None, + None, + smooth_neighbor_uv, + fctx, ); continue; } - let cu_around = - neighbours.around_mi_rect(cu_mi, luma_span, luma_span_h); + let cu_around = neighbours.around_mi_rect(cu_mi, luma_span, luma_span_h); let buf: &mut PlaneBuf<'static> = if plane_pass == 1 { &mut *u } else { &mut *v }; let grid = read_plane( - dec, cdfs, chroma_set, &chroma_scan, plane_pass, cu_around[plane_pass], - mode, uv_predict_mode, angle_delta_uv, cu_r, buf, cu_x, cu_y, - chroma_tx, chroma_tx, base_q_idx, None, None, Some(3), - smooth_neighbor_uv, fctx, + dec, + cdfs, + chroma_set, + &chroma_scan, + plane_pass, + cu_around[plane_pass], + mode, + uv_predict_mode, + angle_delta_uv, + cu_r, + buf, + cu_x, + cu_y, + chroma_tx, + chroma_tx, + base_q_idx, + None, + None, + Some(3), + smooth_neighbor_uv, + fctx, )?; last_grids[plane_pass - 1] = grid.clone(); // Immediately, so the NEXT unit of this same block @@ -19265,7 +21599,8 @@ fn decode_block_128rect( bh / MI, logical_tx as u8, logical_tx as u8, - 0, fctx, + 0, + fctx, ); if in_inter || allow_intrabc_frame(fctx) { // `set_txfm_ctxs(tx_size, n4_w, n4_h, skip && is_inter, xd)` @@ -19275,12 +21610,7 @@ fn decode_block_128rect( // A key frame reads those bands only when it allows intrabc // ([`read_block_tx_size_rect`]'s var-tx context), and then libaom // stamps here too -- lane-av1-intrabc r3. - txfm_partition_update_rect( - neighbours, - (mi_r, mi_c), - (logical_tx, logical_tx), - (bw, bh), - ); + txfm_partition_update_rect(neighbours, (mi_r, mi_c), (logical_tx, logical_tx), (bw, bh)); } if in_inter { hit_do! { @@ -19298,7 +21628,6 @@ fn decode_block_128rect( Ok(()) } - /// Decodes one 8x8 leaf of a straddling 16x16 block (lane-av1-rect), mirroring /// [`crate::tile::write_leaf8`]: its intra-mode context comes from the /// *enclosing* 16x16 slot's `above_mode`/`left_mode` (`outer_at`, [`SUB`]-grid), @@ -19350,7 +21679,8 @@ fn decode_leaf8( allow_screen_content_tools: bool, allow_intrabc: bool, tx_select: bool, - reduced_tx_set: bool, fctx: &crate::decode::FrameCtx, + reduced_tx_set: bool, + fctx: &crate::decode::FrameCtx, ) -> Result { let (r, c) = outer_at; // lane-modectx r1: the group's own availability-correct fallback pair, not @@ -19398,23 +21728,33 @@ fn decode_leaf8( // `--tune-content=screen --min-partition-size=8` stream stopped. let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(leaf_mi); let palette_uv_cache = neighbours.palette_uv_cache_mi(leaf_mi); - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = - read_intra_mode( - dec, - cdfs, - above_mode, - left_mode, - true, - 8, - enable_filter_intra, - neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1), - allow_screen_content_tools, - allow_intrabc, - Some((palette_ctx, &palette_cache)), - &palette_uv_cache, - leaf_mi.0, - leaf_mi.1, fctx, - )?; + let ( + skip, + mode, + angle_delta_y, + uv_mode, + angle_delta_uv, + alpha, + filter_intra, + palette_y, + palette_uv, + ) = read_intra_mode( + dec, + cdfs, + above_mode, + left_mode, + true, + 8, + enable_filter_intra, + neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1), + allow_screen_content_tools, + allow_intrabc, + Some((palette_ctx, &palette_cache)), + &palette_uv_cache, + leaf_mi.0, + leaf_mi.1, + fctx, + )?; // lane-kf900 r7: an 8x8 leaf consumed `use_intrabc` (and its DV) through // `read_intra_mode` and then decoded the block as if it were ordinary // intra. libaom's `is_inter_block` counts an intrabc block @@ -19441,10 +21781,12 @@ fn decode_leaf8( p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), ) }); - let (pal_y_size, pal_y_colors) = - palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); - let (pal_uv_size, pal_uv_colors) = - palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); + let (pal_y_size, pal_y_colors) = palette_y + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.colors)); + let (pal_uv_size, pal_uv_colors) = palette_uv + .as_ref() + .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); if palette_y.is_some() || palette_uv.is_some() { hit!(PALETTE_LEAF8_HITS); } @@ -19528,9 +21870,17 @@ fn decode_leaf8( let intrabc_bufs = intrabc_dv.map(|(dv_row, dv_col)| { let mut yb = vec![0u16; 8 * 8]; mc::predict_with_filter( - &y.data, y.width, y.true_width, y.true_height, - mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0), - 8, 8, mc::InterpFilterKind::Bilinear, &mut yb, fctx, + &y.data, + y.width, + y.true_width, + y.true_height, + mv_to_q4(px, dv_col, 0), + mv_to_q4(py, dv_row, 0), + 8, + 8, + mc::InterpFilterKind::Bilinear, + &mut yb, + fctx, ); // The chroma extent is THIS frame's subsampled size of the 8x8 luma // leaf (`get_plane_block_size`): 4x4 at 4:2:0, 4x8 at 4:2:2, 8x8 at @@ -19547,15 +21897,31 @@ fn decode_leaf8( let (cw, ch) = (8 >> ss_x(fctx), 8 >> ss_y(fctx)); let mut ub = vec![0u16; cw * ch]; mc::predict_with_filter( - &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), - cw, ch, mc::InterpFilterKind::Bilinear, &mut ub, fctx, + &u.data, + u.width, + u.true_width, + u.true_height, + mv_to_q4(cpx, dv_col, ss_x(fctx)), + mv_to_q4(cpy, dv_row, ss_y(fctx)), + cw, + ch, + mc::InterpFilterKind::Bilinear, + &mut ub, + fctx, ); let mut vb = vec![0u16; cw * ch]; mc::predict_with_filter( - &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), - cw, ch, mc::InterpFilterKind::Bilinear, &mut vb, fctx, + &v.data, + v.width, + v.true_width, + v.true_height, + mv_to_q4(cpx, dv_col, ss_x(fctx)), + mv_to_q4(cpy, dv_row, ss_y(fctx)), + cw, + ch, + mc::InterpFilterKind::Bilinear, + &mut vb, + fctx, ); (yb, ub, vb) }); @@ -19609,9 +21975,11 @@ fn decode_leaf8( px, py, y.width, - y.height, fctx, + y.height, + fctx, ); - push_intra(0, + push_intra( + 0, tu_px, tu_py, 4, @@ -19621,7 +21989,8 @@ fn decode_leaf8( &ZERO_RESIDUAL[..16], None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); } } @@ -19629,7 +21998,8 @@ fn decode_leaf8( if let Some(buf) = &palette_y_buf { set_palette_pred(buf.clone(), fctx); } - push_intra(0, + push_intra( + 0, px, py, 8, @@ -19639,7 +22009,8 @@ fn decode_leaf8( &ZERO_RESIDUAL[..64], None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); } let ac = alpha.map(|_| cfl_src(px, py, 8)); @@ -19650,116 +22021,166 @@ fn decode_leaf8( // context never enters the rect read. if chroma_422 { u_grid = leaf8_chroma422_unit( - dec, cdfs, (false, false, 0), uv_predict_mode, angle_delta_uv, reach, - 1, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), true, - intrabc_bufs.as_ref().map(|(_, ub, _)| ub.clone()) + dec, + cdfs, + (false, false, 0), + uv_predict_mode, + angle_delta_uv, + reach, + 1, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + true, + intrabc_bufs + .as_ref() + .map(|(_, ub, _)| ub.clone()) .or_else(|| palette_uv_bufs.as_ref().map(|(ub, _)| ub.clone())), - u, cpx, cpy, smooth_neighbor_uv, fctx, + u, + cpx, + cpy, + smooth_neighbor_uv, + fctx, )?; v_grid = leaf8_chroma422_unit( - dec, cdfs, (false, false, 0), uv_predict_mode, angle_delta_uv, reach, - 2, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), true, - intrabc_bufs.as_ref().map(|(_, _, vb)| vb.clone()) + dec, + cdfs, + (false, false, 0), + uv_predict_mode, + angle_delta_uv, + reach, + 2, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + true, + intrabc_bufs + .as_ref() + .map(|(_, _, vb)| vb.clone()) .or_else(|| palette_uv_bufs.as_ref().map(|(_, vb)| vb.clone())), - v, cpx, cpy, smooth_neighbor_uv, fctx, + v, + cpx, + cpy, + smooth_neighbor_uv, + fctx, )?; luma_grid = Grid::Zero(64); } else { - // 4:4:4 lossless: the leaf's chroma plane block is a 2x2 raster of - // TX_4X4 units (`av1_get_tx_size`: lossless forces TX_4X4 on EVERY - // plane), so a skipped leaf predicts per unit -- each from its own - // edges -- like the luma `SKIP_SPLIT_TX` loop above. CfL never fires - // here (`is_cfl_allowed` at lossless needs plane_bsize == 4x4; this - // chroma plane block is 8x8), and intrabc/palette keep the - // whole-plane-block prediction they already run. The guard also - // requires `chroma_444`, so it can never reach the 4:2:2 arm above. - let chroma_units_444 = chroma_444 - && lossless(fctx) - && intrabc_bufs.is_none() - && palette_uv_bufs.is_none(); - if let Some((_, ub, _)) = &intrabc_bufs { - set_palette_pred(ub.clone(), fctx); - } else if let Some((ub, _)) = &palette_uv_bufs { - set_palette_pred(ub.clone(), fctx); - } - if chroma_units_444 { - for cu_row in 0..2 { - for cu_col in 0..2 { - let cu_reach = tu_reach( - 8, 8, cu_col * 4, cu_row * 4, 4, - reach, px, py, y.width, y.height, fctx, - ); - push_intra(1, - cpx + cu_col * 4, - cpy + cu_row * 4, - 4, - uv_predict_mode, - angle_delta_uv, - cu_reach, - &ZERO_RESIDUAL[..16], - None, - None, - smooth_neighbor_uv, fctx, - ); + // 4:4:4 lossless: the leaf's chroma plane block is a 2x2 raster of + // TX_4X4 units (`av1_get_tx_size`: lossless forces TX_4X4 on EVERY + // plane), so a skipped leaf predicts per unit -- each from its own + // edges -- like the luma `SKIP_SPLIT_TX` loop above. CfL never fires + // here (`is_cfl_allowed` at lossless needs plane_bsize == 4x4; this + // chroma plane block is 8x8), and intrabc/palette keep the + // whole-plane-block prediction they already run. The guard also + // requires `chroma_444`, so it can never reach the 4:2:2 arm above. + let chroma_units_444 = + chroma_444 && lossless(fctx) && intrabc_bufs.is_none() && palette_uv_bufs.is_none(); + if let Some((_, ub, _)) = &intrabc_bufs { + set_palette_pred(ub.clone(), fctx); + } else if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone(), fctx); + } + if chroma_units_444 { + for cu_row in 0..2 { + for cu_col in 0..2 { + let cu_reach = tu_reach( + 8, + 8, + cu_col * 4, + cu_row * 4, + 4, + reach, + px, + py, + y.width, + y.height, + fctx, + ); + push_intra( + 1, + cpx + cu_col * 4, + cpy + cu_row * 4, + 4, + uv_predict_mode, + angle_delta_uv, + cu_reach, + &ZERO_RESIDUAL[..16], + None, + None, + smooth_neighbor_uv, + fctx, + ); + } } + } else { + push_intra( + 1, + cpx, + cpy, + csz, + uv_predict_mode, + angle_delta_uv, + reach, + &ZERO_RESIDUAL[..csz * csz], + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + fctx, + ); } - } else { - push_intra(1, - cpx, - cpy, - csz, - uv_predict_mode, - angle_delta_uv, - reach, - &ZERO_RESIDUAL[..csz * csz], - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - None, - smooth_neighbor_uv, fctx, - ); - } - if let Some((_, _, vb)) = &intrabc_bufs { - set_palette_pred(vb.clone(), fctx); - } else if let Some((_, vb)) = &palette_uv_bufs { - set_palette_pred(vb.clone(), fctx); - } - if chroma_units_444 { - for cu_row in 0..2 { - for cu_col in 0..2 { - let cu_reach = tu_reach( - 8, 8, cu_col * 4, cu_row * 4, 4, - reach, px, py, y.width, y.height, fctx, - ); - push_intra(2, - cpx + cu_col * 4, - cpy + cu_row * 4, - 4, - uv_predict_mode, - angle_delta_uv, - cu_reach, - &ZERO_RESIDUAL[..16], - None, - None, - smooth_neighbor_uv, fctx, - ); + if let Some((_, _, vb)) = &intrabc_bufs { + set_palette_pred(vb.clone(), fctx); + } else if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone(), fctx); + } + if chroma_units_444 { + for cu_row in 0..2 { + for cu_col in 0..2 { + let cu_reach = tu_reach( + 8, + 8, + cu_col * 4, + cu_row * 4, + 4, + reach, + px, + py, + y.width, + y.height, + fctx, + ); + push_intra( + 2, + cpx + cu_col * 4, + cpy + cu_row * 4, + 4, + uv_predict_mode, + angle_delta_uv, + cu_reach, + &ZERO_RESIDUAL[..16], + None, + None, + smooth_neighbor_uv, + fctx, + ); + } } + } else { + push_intra( + 2, + cpx, + cpy, + csz, + uv_predict_mode, + angle_delta_uv, + reach, + &ZERO_RESIDUAL[..csz * csz], + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + fctx, + ); } - } else { - push_intra(2, - cpx, - cpy, - csz, - uv_predict_mode, - angle_delta_uv, - reach, - &ZERO_RESIDUAL[..csz * csz], - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - None, - smooth_neighbor_uv, fctx, - ); - } - luma_grid = Grid::Zero(64); - u_grid = Grid::Zero(csz * csz); - v_grid = Grid::Zero(csz * csz); + luma_grid = Grid::Zero(64); + u_grid = Grid::Zero(csz * csz); + v_grid = Grid::Zero(csz * csz); } } else if resolved != 4 { let around = neighbours.around_mi(leaf_mi, 8); @@ -19805,13 +22226,15 @@ fn decode_leaf8( None, filter_intra, None, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, )?; // `av1_get_tx_type` branches `PLANE_TYPE_UV` on `is_inter_block`, so // an intrabc block's chroma tx_type is the colocated LUMA transform's // coded type (lane-kf900 r6's own fix, `decode_block`'s line). if intrabc_dv.is_some() { - fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get)))); + fctx.intrabc_chroma_tx + .with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get)))); } let ac = alpha.map(|_| cfl_src(px, py, 8)); if chroma_422 { @@ -19819,74 +22242,102 @@ fn decode_leaf8( // at ss (1,0) == TX_4X8), covering the plane block exactly, off the // leaf's own 8x8-span entropy context (`chroma_tiled`'s convention). u_grid = leaf8_chroma422_unit( - dec, cdfs, chroma_around[1], uv_predict_mode, angle_delta_uv, reach, - 1, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), false, - intrabc_bufs.as_ref().map(|(_, ub, _)| ub.clone()) + dec, + cdfs, + chroma_around[1], + uv_predict_mode, + angle_delta_uv, + reach, + 1, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + false, + intrabc_bufs + .as_ref() + .map(|(_, ub, _)| ub.clone()) .or_else(|| palette_uv_bufs.as_ref().map(|(ub, _)| ub.clone())), - u, cpx, cpy, smooth_neighbor_uv, fctx, + u, + cpx, + cpy, + smooth_neighbor_uv, + fctx, )?; v_grid = leaf8_chroma422_unit( - dec, cdfs, chroma_around[2], uv_predict_mode, angle_delta_uv, reach, - 2, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), false, - intrabc_bufs.as_ref().map(|(_, _, vb)| vb.clone()) + dec, + cdfs, + chroma_around[2], + uv_predict_mode, + angle_delta_uv, + reach, + 2, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + false, + intrabc_bufs + .as_ref() + .map(|(_, _, vb)| vb.clone()) .or_else(|| palette_uv_bufs.as_ref().map(|(_, vb)| vb.clone())), - v, cpx, cpy, smooth_neighbor_uv, fctx, + v, + cpx, + cpy, + smooth_neighbor_uv, + fctx, )?; } else { - if let Some((_, ub, _)) = &intrabc_bufs { - set_palette_pred(ub.clone(), fctx); - } else if let Some((ub, _)) = &palette_uv_bufs { - set_palette_pred(ub.clone(), fctx); - } - u_grid = read_plane( - dec, - cdfs, - cset, - cscan, - 1, - around[1], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - u, - cpx, - cpy, - csz, - csz, - base_q_idx, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )?; - if let Some((_, _, vb)) = &intrabc_bufs { - set_palette_pred(vb.clone(), fctx); - } else if let Some((_, vb)) = &palette_uv_bufs { - set_palette_pred(vb.clone(), fctx); - } - v_grid = read_plane( - dec, - cdfs, - cset, - cscan, - 2, - around[2], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - v, - cpx, - cpy, - csz, - csz, - base_q_idx, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )?; + if let Some((_, ub, _)) = &intrabc_bufs { + set_palette_pred(ub.clone(), fctx); + } else if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone(), fctx); + } + u_grid = read_plane( + dec, + cdfs, + cset, + cscan, + 1, + around[1], + mode, + uv_predict_mode, + angle_delta_uv, + reach, + u, + cpx, + cpy, + csz, + csz, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + None, + smooth_neighbor_uv, + fctx, + )?; + if let Some((_, _, vb)) = &intrabc_bufs { + set_palette_pred(vb.clone(), fctx); + } else if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone(), fctx); + } + v_grid = read_plane( + dec, + cdfs, + cset, + cscan, + 2, + around[2], + mode, + uv_predict_mode, + angle_delta_uv, + reach, + v, + cpx, + cpy, + csz, + csz, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + None, + smooth_neighbor_uv, + fctx, + )?; } // Disarm: `INTRABC_CHROMA_TX` is `Some` across exactly this block's // two chroma reads (`decode_block`'s own tail does the same) -- left @@ -19919,7 +22370,8 @@ fn decode_leaf8( px, py, y.width, - y.height, fctx, + y.height, + fctx, ); let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1); // Each 4x4 unit predicts from its own window of the block's @@ -19961,7 +22413,8 @@ fn decode_leaf8( None, filter_intra, Some(tu_skip_ctx), - smooth_neighbor, fctx, + smooth_neighbor, + fctx, )?; if crate::envflags::env_flag!("EC_AV1_TRACE") { eprintln!( @@ -20015,18 +22468,44 @@ fn decode_leaf8( // split -- `uv_txsize` is `av1_get_max_uv_txsize` of the block, // still the one 4x8 rect unit per plane at ss (1,0). u_grid = leaf8_chroma422_unit( - dec, cdfs, chroma_around[1], uv_predict_mode, angle_delta_uv, reach, - 1, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), false, - intrabc_bufs.as_ref().map(|(_, ub, _)| ub.clone()) + dec, + cdfs, + chroma_around[1], + uv_predict_mode, + angle_delta_uv, + reach, + 1, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + false, + intrabc_bufs + .as_ref() + .map(|(_, ub, _)| ub.clone()) .or_else(|| palette_uv_bufs.as_ref().map(|(ub, _)| ub.clone())), - u, cpx, cpy, smooth_neighbor_uv, fctx, + u, + cpx, + cpy, + smooth_neighbor_uv, + fctx, )?; v_grid = leaf8_chroma422_unit( - dec, cdfs, chroma_around[2], uv_predict_mode, angle_delta_uv, reach, - 2, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), false, - intrabc_bufs.as_ref().map(|(_, _, vb)| vb.clone()) + dec, + cdfs, + chroma_around[2], + uv_predict_mode, + angle_delta_uv, + reach, + 2, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + false, + intrabc_bufs + .as_ref() + .map(|(_, _, vb)| vb.clone()) .or_else(|| palette_uv_bufs.as_ref().map(|(_, vb)| vb.clone())), - v, cpx, cpy, smooth_neighbor_uv, fctx, + v, + cpx, + cpy, + smooth_neighbor_uv, + fctx, )?; } else if chroma_444 && lossless(fctx) { // 4:4:4 lossless: the leaf's chroma plane block is a 2x2 raster @@ -20041,65 +22520,94 @@ fn decode_leaf8( // is skipped for this shape. let (mut uo, mut vo) = (Vec::new(), Vec::new()); read_intra_chroma_lossless( - dec, cdfs, neighbours, u, v, leaf_mi, (px, py), (cpx, cpy), - 8, (8, 8), (0, 0), (8, 8), 8, reach, (y.width, y.height), mode, - uv_predict_mode, angle_delta_uv, + dec, + cdfs, + neighbours, + u, + v, + leaf_mi, + (px, py), + (cpx, cpy), + 8, + (8, 8), + (0, 0), + (8, 8), + 8, + reach, + (y.width, y.height), + mode, + uv_predict_mode, + angle_delta_uv, palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])), - smooth_neighbor_uv, base_q_idx, &mut uo, &mut vo, fctx, + smooth_neighbor_uv, + base_q_idx, + &mut uo, + &mut vo, + fctx, )?; - u_grid = if uo.is_empty() { Grid::Zero(64) } else { Grid::Own(uo) }; - v_grid = if vo.is_empty() { Grid::Zero(64) } else { Grid::Own(vo) }; + u_grid = if uo.is_empty() { + Grid::Zero(64) + } else { + Grid::Own(uo) + }; + v_grid = if vo.is_empty() { + Grid::Zero(64) + } else { + Grid::Own(vo) + }; } else { - if let Some((ub, _)) = &palette_uv_bufs { - set_palette_pred(ub.clone(), fctx); - } - u_grid = read_plane( - dec, - cdfs, - cset, - cscan, - 1, - chroma_around[1], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - u, - cpx, - cpy, - csz, - csz, - base_q_idx, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )?; - if let Some((_, vb)) = &palette_uv_bufs { - set_palette_pred(vb.clone(), fctx); - } - v_grid = read_plane( - dec, - cdfs, - cset, - cscan, - 2, - chroma_around[2], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - v, - cpx, - cpy, - csz, - csz, - base_q_idx, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )?; + if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone(), fctx); + } + u_grid = read_plane( + dec, + cdfs, + cset, + cscan, + 1, + chroma_around[1], + mode, + uv_predict_mode, + angle_delta_uv, + reach, + u, + cpx, + cpy, + csz, + csz, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + None, + smooth_neighbor_uv, + fctx, + )?; + if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone(), fctx); + } + v_grid = read_plane( + dec, + cdfs, + cset, + cscan, + 2, + chroma_around[2], + mode, + uv_predict_mode, + angle_delta_uv, + reach, + v, + cpx, + cpy, + csz, + csz, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + None, + smooth_neighbor_uv, + fctx, + )?; } // The two chroma reads above are the only consulters of this leaf's // armed [`INTRABC_CHROMA_TX`]; leaving it set would make the NEXT @@ -20145,16 +22653,16 @@ fn decode_leaf8( } } } - // This leaf's own palette state into the mi-granular above/left bands - // (sizes 0 when it used none, which is what clears a previous block's - // palette out of the next block's ctx and colour cache). - { - neighbours.record_palette_y_rect(leaf_mi, 8, 8, pal_y_size, pal_y_colors); - neighbours.record_palette_uv_rect(leaf_mi, 8, 8, pal_uv_size, pal_uv_colors); - } + // This leaf's own palette state into the mi-granular above/left bands + // (sizes 0 when it used none, which is what clears a previous block's + // palette out of the next block's ctx and colour cache). + { + neighbours.record_palette_y_rect(leaf_mi, 8, 8, pal_y_size, pal_y_colors); + neighbours.record_palette_uv_rect(leaf_mi, 8, 8, pal_uv_size, pal_uv_colors); + } neighbours.fill_skip_grid(leaf_mi, 2, skip); neighbours.fill_lf_grid(leaf_mi, 2, 4, 0, fctx); - // lane-t900 r32: `set_txfm_ctxs` for an 8x8 leaf -- see `decode_block`'s + // lane-t900 r32: `set_txfm_ctxs` for an 8x8 leaf -- see `decode_block`'s // own copy; only an intrabc var-tx read consumes these bands on the intra // path, so the write is armed by `allow_intrabc`. if allow_intrabc { @@ -20190,7 +22698,14 @@ fn decode_leaf8( // [`Neighbours::fill_lf_grid_rect`]'s publish (the skipped-intrabc // BLOCK-size term). if allow_intrabc { - set_txfm_ctxs(neighbours, leaf_mi, resolved, 2, 2, skip && intrabc_dv.is_some()); + set_txfm_ctxs( + neighbours, + leaf_mi, + resolved, + 2, + 2, + skip && intrabc_dv.is_some(), + ); } neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); // The DV predictor of a LATER intrabc block is the ordinary `INTRA_FRAME` @@ -20234,7 +22749,8 @@ fn leaf8_chroma422_unit( _plane: &mut PlaneBuf<'static>, cpx: usize, cpy: usize, - smooth_neighbor_uv: bool, fctx: &crate::decode::FrameCtx, + smooth_neighbor_uv: bool, + fctx: &crate::decode::FrameCtx, ) -> Result { // The unit's prediction runs whether or not a residual follows it -- a // skipped leaf still predicts (the CfL contribution survives a skip), @@ -20244,8 +22760,19 @@ fn leaf8_chroma422_unit( } if skip { push_intra_rect( - plane_idx, cpx, cpy, 4, 8, uv_predict_mode, angle_delta_uv, reach, - &ZERO_RESIDUAL[..4 * 8], cfl, None, smooth_neighbor_uv, fctx, + plane_idx, + cpx, + cpy, + 4, + 8, + uv_predict_mode, + angle_delta_uv, + reach, + &ZERO_RESIDUAL[..4 * 8], + cfl, + None, + smooth_neighbor_uv, + fctx, ); return Ok(Grid::Zero(4 * 8)); } @@ -20255,18 +22782,40 @@ fn leaf8_chroma422_unit( .unwrap_or_else(|| default_intra_tx_type(uv_predict_mode as u8)); let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); let (levels, tx_type) = read_coeffs_rect( - dec, &mut coding, &SCAN_4X8, 4, 8, + dec, + &mut coding, + &SCAN_4X8, + 4, + 8, usize::from(around.0) + usize::from(around.1), - dc_sign_ctx(around.2), default_tx, + dc_sign_ctx(around.2), + default_tx, )?; let residual = dequant_and_inverse_typed_wh( - &levels, 4, 8, crate::decode::bit_depth(fctx), block_q_idx(fctx), - plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1, - tx_type, block_iqmatrix(fctx, plane_idx, 4, 8, tx_type), + &levels, + 4, + 8, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(plane_idx, fctx).0, + plane_q_delta(plane_idx, fctx).1, + tx_type, + block_iqmatrix(fctx, plane_idx, 4, 8, tx_type), ); push_intra_rect( - plane_idx, cpx, cpy, 4, 8, uv_predict_mode, angle_delta_uv, reach, - &residual, cfl, None, smooth_neighbor_uv, fctx, + plane_idx, + cpx, + cpy, + 4, + 8, + uv_predict_mode, + angle_delta_uv, + reach, + &residual, + cfl, + None, + smooth_neighbor_uv, + fctx, ); Ok(levels) } @@ -20301,22 +22850,38 @@ fn read_intra_mode_sub8( // left the second mi column at segment 0, which reads back as a // neighbour's `cdf_index`/prediction two blocks later. seg_w_mi: usize, - seg_h_mi: usize, fctx: &crate::decode::FrameCtx, -) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option, Option<(i32, i32)>)> { + seg_h_mi: usize, + fctx: &crate::decode::FrameCtx, +) -> Result<( + bool, + usize, + i32, + Option<(usize, i32, Option<(i32, i32)>)>, + Option, + Option<(i32, i32)>, +)> { // lane-av1mono: a monochrome leaf codes no chroma mode (libaom // `decodemv.c:933`), so fold `NumPlanes == 1` into `has_chroma`. let has_chroma = has_chroma && !mono(fctx); let trace = crate::envflags::env_flag!("EC_AV1_TRACE"); let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP"); if ec_istep { - eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sub8 rng={}", dec.debug_state().0); + eprintln!( + "EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sub8 rng={}", + dec.debug_state().0 + ); } // Same `EC_ISTEP` ladder the square/rect readers print, so a cross-decoder // range diff lands on the ELEMENT inside a 4x4 leaf, not just the block. macro_rules! istep { ($name:literal, $val:expr) => { if ec_istep { - eprintln!("EC_ISTEP mi_row={mi_r} mi_col={mi_c} name={} val={} rng={}", $name, $val, dec.debug_state().0); + eprintln!( + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name={} val={} rng={}", + $name, + $val, + dec.debug_state().0 + ); } }; } @@ -20331,7 +22896,11 @@ fn read_intra_mode_sub8( } let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; if trace { - eprintln!("TRACE sub8 skip mi=({mi_r},{mi_c}) ctx={skip_ctx} value={} rng={}", skip as i32, dec.debug_state().0); + eprintln!( + "TRACE sub8 skip mi=({mi_r},{mi_c}) ctx={skip_ctx} value={} rng={}", + skip as i32, + dec.debug_state().0 + ); } istep!("skip", skip as i32); if !seg_id_pre_skip(fctx) { @@ -20345,7 +22914,11 @@ fn read_intra_mode_sub8( if allow_intrabc { let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0; if ec_istep { - eprintln!("EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=intrabc val={} rng={}", u8::from(use_intrabc), dec.debug_state().0); + eprintln!( + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=intrabc val={} rng={}", + u8::from(use_intrabc), + dec.debug_state().0 + ); } if use_intrabc { // lane-av1txr: `read_intrabc_info` (spec 5.11.13) reads the block @@ -20372,7 +22945,10 @@ fn read_intra_mode_sub8( let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); istep!("mode", mode); if trace { - eprintln!("TRACE sub8 y_mode mi=({mi_r},{mi_c}) ctx=({above_ctx},{left_ctx}) value={mode} rng={}", dec.debug_state().0); + eprintln!( + "TRACE sub8 y_mode mi=({mi_r},{mi_c}) ctx=({above_ctx},{left_ctx}) value={mode} rng={}", + dec.debug_state().0 + ); } // No `angle_delta` at all below 8x8: spec 5.11.6's `intra_angle_info_y`/ // `_uv` are gated on `MiSize >= BLOCK_8X8` (libaom `av1_use_angle_delta`, @@ -20397,7 +22973,10 @@ fn read_intra_mode_sub8( dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) }; if trace { - eprintln!("TRACE sub8 uv_mode value={uv_mode} rng={}", dec.debug_state().0); + eprintln!( + "TRACE sub8 uv_mode value={uv_mode} rng={}", + dec.debug_state().0 + ); } if (9..=12).contains(&uv_mode) { hit!(SMOOTH_UV_HITS); @@ -20420,7 +22999,10 @@ fn read_intra_mode_sub8( if mode == DC_PRED && enable_filter_intra { let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[fi_class]) != 0; if trace { - eprintln!("TRACE sub8 use_filter_intra value={}", use_filter_intra as i32); + eprintln!( + "TRACE sub8 use_filter_intra value={}", + use_filter_intra as i32 + ); } if use_filter_intra { hit!(FILTER_INTRA_HITS); @@ -20467,7 +23049,11 @@ fn sub8_leaf_chroma444( smooth_neighbor_uv: bool, fctx: &crate::decode::FrameCtx, ) -> Result<(Grid, Grid, usize, usize)> { - let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + let uv_predict_mode = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; let (w_mi, h_mi) = (bw / MI, bh / MI); neighbours.record_uv_mode_mi(lmi.0, lmi.1, w_mi, h_mi, uv_predict_mode); let (px, py) = (lmi.1 * MI, lmi.0 * MI); @@ -20493,28 +23079,98 @@ fn sub8_leaf_chroma444( // before its luma DV copy, so the source samples are current. let mut ub = vec![0u16; bw * bh]; mc::predict_with_filter( - &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(px, dv.1, 0), mv_to_q4(py, dv.0, 0), - bw, bh, mc::InterpFilterKind::Bilinear, &mut ub, fctx, + &u.data, + u.width, + u.true_width, + u.true_height, + mv_to_q4(px, dv.1, 0), + mv_to_q4(py, dv.0, 0), + bw, + bh, + mc::InterpFilterKind::Bilinear, + &mut ub, + fctx, ); let mut vb = vec![0u16; bw * bh]; mc::predict_with_filter( - &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(px, dv.1, 0), mv_to_q4(py, dv.0, 0), - bw, bh, mc::InterpFilterKind::Bilinear, &mut vb, fctx, + &v.data, + v.width, + v.true_width, + v.true_height, + mv_to_q4(px, dv.1, 0), + mv_to_q4(py, dv.0, 0), + bw, + bh, + mc::InterpFilterKind::Bilinear, + &mut vb, + fctx, ); hit!(SKIPPED_INTRABC_DV_COPY_HITS); let zeros = &ZERO_RESIDUAL[..bw * bh]; if square { set_palette_pred(ub, fctx); - push_intra(1, px, py, 4, DC_PRED, 0, reach, zeros, None, None, smooth_neighbor_uv, fctx); + push_intra( + 1, + px, + py, + 4, + DC_PRED, + 0, + reach, + zeros, + None, + None, + smooth_neighbor_uv, + fctx, + ); set_palette_pred(vb, fctx); - push_intra(2, px, py, 4, DC_PRED, 0, reach, zeros, None, None, smooth_neighbor_uv, fctx); + push_intra( + 2, + px, + py, + 4, + DC_PRED, + 0, + reach, + zeros, + None, + None, + smooth_neighbor_uv, + fctx, + ); } else { set_palette_pred(ub, fctx); - push_intra_rect(1, px, py, bw, bh, DC_PRED, 0, reach, zeros, None, None, smooth_neighbor_uv, fctx); + push_intra_rect( + 1, + px, + py, + bw, + bh, + DC_PRED, + 0, + reach, + zeros, + None, + None, + smooth_neighbor_uv, + fctx, + ); set_palette_pred(vb, fctx); - push_intra_rect(2, px, py, bw, bh, DC_PRED, 0, reach, zeros, None, None, smooth_neighbor_uv, fctx); + push_intra_rect( + 2, + px, + py, + bw, + bh, + DC_PRED, + 0, + reach, + zeros, + None, + None, + smooth_neighbor_uv, + fctx, + ); } // The same arm-without-clear route the 4:2:0 tails count: a skipped // leaf reads no coefficient, so the inherited chroma `tx_type` is @@ -20525,11 +23181,65 @@ fn sub8_leaf_chroma444( } else if skip { let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); if square { - push_intra(1, px, py, 4, uv_predict_mode, 0, reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); - push_intra(2, px, py, 4, uv_predict_mode, 0, reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); + push_intra( + 1, + px, + py, + 4, + uv_predict_mode, + 0, + reach, + &ZERO_RESIDUAL[..16], + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + fctx, + ); + push_intra( + 2, + px, + py, + 4, + uv_predict_mode, + 0, + reach, + &ZERO_RESIDUAL[..16], + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + fctx, + ); } else { - push_intra_rect(1, px, py, bw, bh, uv_predict_mode, 0, reach, &ZERO_RESIDUAL[..bw * bh], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); - push_intra_rect(2, px, py, bw, bh, uv_predict_mode, 0, reach, &ZERO_RESIDUAL[..bw * bh], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); + push_intra_rect( + 1, + px, + py, + bw, + bh, + uv_predict_mode, + 0, + reach, + &ZERO_RESIDUAL[..bw * bh], + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + fctx, + ); + push_intra_rect( + 2, + px, + py, + bw, + bh, + uv_predict_mode, + 0, + reach, + &ZERO_RESIDUAL[..bw * bh], + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + fctx, + ); } // The same arm-without-clear route the 4:2:0 tails count: a skipped // leaf reads no coefficient, so an armed intrabc slot is dropped. @@ -20543,29 +23253,81 @@ fn sub8_leaf_chroma444( // tables with the inherited luma `tx_type` (see the 4:2:0 tails). let mut ub = vec![0u16; bw * bh]; mc::predict_with_filter( - &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(px, dv.1, 0), mv_to_q4(py, dv.0, 0), - bw, bh, mc::InterpFilterKind::Bilinear, &mut ub, fctx, + &u.data, + u.width, + u.true_width, + u.true_height, + mv_to_q4(px, dv.1, 0), + mv_to_q4(py, dv.0, 0), + bw, + bh, + mc::InterpFilterKind::Bilinear, + &mut ub, + fctx, ); let mut vb = vec![0u16; bw * bh]; mc::predict_with_filter( - &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(px, dv.1, 0), mv_to_q4(py, dv.0, 0), - bw, bh, mc::InterpFilterKind::Bilinear, &mut vb, fctx, + &v.data, + v.width, + v.true_width, + v.true_height, + mv_to_q4(px, dv.1, 0), + mv_to_q4(py, dv.0, 0), + bw, + bh, + mc::InterpFilterKind::Bilinear, + &mut vb, + fctx, ); let around = neighbours.around_mi_rect(lmi, bw, bh); let pair = if square { set_palette_pred(ub, fctx); let ug = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], DC_PRED, DC_PRED, - 0, reach, u, px, py, 4, TX4, base_q_idx, - None, None, None, smooth_neighbor_uv, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + around[1], + DC_PRED, + DC_PRED, + 0, + reach, + u, + px, + py, + 4, + TX4, + base_q_idx, + None, + None, + None, + smooth_neighbor_uv, + fctx, )?; set_palette_pred(vb, fctx); let vg = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], DC_PRED, DC_PRED, - 0, reach, v, px, py, 4, TX4, base_q_idx, - None, None, None, smooth_neighbor_uv, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + around[2], + DC_PRED, + DC_PRED, + 0, + reach, + v, + px, + py, + 4, + TX4, + base_q_idx, + None, + None, + None, + smooth_neighbor_uv, + fctx, )?; (ug, vg, 4, 4) } else { @@ -20595,17 +23357,43 @@ fn sub8_leaf_chroma444( let (upx, upy) = (px + uc * 4, py + ur * 4); let mut pb = vec![0u16; 16]; mc::predict_with_filter( - &buf.data, buf.width, buf.true_width, buf.true_height, - mv_to_q4(upx, dv.1, 0), mv_to_q4(upy, dv.0, 0), - 4, 4, mc::InterpFilterKind::Bilinear, &mut pb, fctx, + &buf.data, + buf.width, + buf.true_width, + buf.true_height, + mv_to_q4(upx, dv.1, 0), + mv_to_q4(upy, dv.0, 0), + 4, + 4, + mc::InterpFilterKind::Bilinear, + &mut pb, + fctx, ); set_palette_pred(pb, fctx); let unit_around = neighbours.around_mi_rect((umi_r, umi_c), 4, 4); let unit_reach = Reach::of(4, upx, upy, y.width, y.height, fctx); let grid = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, plane_idx, unit_around[plane_idx], - DC_PRED, DC_PRED, 0, unit_reach, buf, upx, upy, 4, - TX4, base_q_idx, None, None, Some(3), smooth_neighbor_uv, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + plane_idx, + unit_around[plane_idx], + DC_PRED, + DC_PRED, + 0, + unit_reach, + buf, + upx, + upy, + 4, + TX4, + base_q_idx, + None, + None, + Some(3), + smooth_neighbor_uv, + fctx, )?; let cell = grid_unit_state(&grid, 4, 0, 0, 4, 4); if umi_r < neighbours.mi_rows { @@ -20614,7 +23402,11 @@ fn sub8_leaf_chroma444( if umi_c < neighbours.mi_cols { neighbours.above[umi_c][plane_idx] = cell; } - let out = if plane_idx == 1 { &mut out_u } else { &mut out_v }; + let out = if plane_idx == 1 { + &mut out_u + } else { + &mut out_v + }; if let Grid::Own(v) = out { for r in 0..4usize { v[(ur * 4 + r) * bw + uc * 4..][..4] @@ -20626,52 +23418,116 @@ fn sub8_leaf_chroma444( } (out_u, out_v, 4, 4) } else { - let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 }; - let default_tx = - fctx.intrabc_chroma_tx.with(std::cell::Cell::get).unwrap_or(TxType::DctDct); - let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh), bw, bh); - for (plane_idx, buf) in [(1usize, ub), (2usize, vb)] { - let skip_ctx = - usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1); - let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, DC_PRED); - let (levels, tx_type) = read_coeffs_rect( - dec, &mut coding, scan, bw, bh, skip_ctx, - dc_sign_ctx(around[plane_idx].2), default_tx, - )?; - let residual = dequant_and_inverse_typed_wh( - &levels, bw, bh, crate::decode::bit_depth(fctx), block_q_idx(fctx), - plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1, - tx_type, + let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 }; + let default_tx = fctx + .intrabc_chroma_tx + .with(std::cell::Cell::get) + .unwrap_or(TxType::DctDct); + let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh), bw, bh); + for (plane_idx, buf) in [(1usize, ub), (2usize, vb)] { + let skip_ctx = + usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1); + let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, DC_PRED); + let (levels, tx_type) = read_coeffs_rect( + dec, + &mut coding, + scan, + bw, + bh, + skip_ctx, + dc_sign_ctx(around[plane_idx].2), + default_tx, + )?; + let residual = dequant_and_inverse_typed_wh( + &levels, + bw, + bh, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(plane_idx, fctx).0, + plane_q_delta(plane_idx, fctx).1, + tx_type, block_iqmatrix(fctx, plane_idx, bw, bh, tx_type), - ); - set_palette_pred(buf, fctx); - push_intra_rect( - plane_idx, px, py, bw, bh, DC_PRED, 0, reach, &residual, - None, None, smooth_neighbor_uv, fctx, - ); - if plane_idx == 1 { out.0 = levels; } else { out.1 = levels; } - } - out - } - }; - fctx.intrabc_chroma_tx.with(|c| c.set(None)); - pair - } else { - let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); - let around = neighbours.around_mi_rect(lmi, bw, bh); - if square { - let ug = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], uv_mode, uv_predict_mode, - 0, reach, u, px, py, 4, TX4, base_q_idx, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx, - )?; - let vg = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], uv_mode, uv_predict_mode, - 0, reach, v, px, py, 4, TX4, base_q_idx, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx, - )?; - (ug, vg, 4, 4) - } else if lossless(fctx) { + ); + set_palette_pred(buf, fctx); + push_intra_rect( + plane_idx, + px, + py, + bw, + bh, + DC_PRED, + 0, + reach, + &residual, + None, + None, + smooth_neighbor_uv, + fctx, + ); + if plane_idx == 1 { + out.0 = levels; + } else { + out.1 = levels; + } + } + out + } + }; + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + pair + } else { + let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); + let around = neighbours.around_mi_rect(lmi, bw, bh); + if square { + let ug = read_plane( + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + around[1], + uv_mode, + uv_predict_mode, + 0, + reach, + u, + px, + py, + 4, + TX4, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + None, + smooth_neighbor_uv, + fctx, + )?; + let vg = read_plane( + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + around[2], + uv_mode, + uv_predict_mode, + 0, + reach, + v, + px, + py, + 4, + TX4, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + None, + smooth_neighbor_uv, + fctx, + )?; + (ug, vg, 4, 4) + } else if lossless(fctx) { // lane-av1-llsub8: `read_tx_size` answers TX_4X4 for EVERY plane of // a lossless block, so this rect leaf's chroma is (bw/4)*(bh/4) // TX_4X4 units at their own 4x4 origins -- not the single @@ -20697,9 +23553,27 @@ fn sub8_leaf_chroma444( let unit_around = neighbours.around_mi_rect((umi_r, umi_c), 4, 4); let unit_reach = Reach::of(4, upx, upy, y.width, y.height, fctx); let grid = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, plane_idx, unit_around[plane_idx], - uv_mode, uv_predict_mode, 0, unit_reach, buf, upx, upy, 4, - TX4, base_q_idx, None, None, Some(3), smooth_neighbor_uv, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + plane_idx, + unit_around[plane_idx], + uv_mode, + uv_predict_mode, + 0, + unit_reach, + buf, + upx, + upy, + 4, + TX4, + base_q_idx, + None, + None, + Some(3), + smooth_neighbor_uv, + fctx, )?; let cell = grid_unit_state(&grid, 4, 0, 0, 4, 4); if umi_r < neighbours.mi_rows { @@ -20708,7 +23582,11 @@ fn sub8_leaf_chroma444( if umi_c < neighbours.mi_cols { neighbours.above[umi_c][plane_idx] = cell; } - let out = if plane_idx == 1 { &mut out_u } else { &mut out_v }; + let out = if plane_idx == 1 { + &mut out_u + } else { + &mut out_v + }; if let Grid::Own(v) = out { for r in 0..4usize { v[(ur * 4 + r) * bw + uc * 4..][..4] @@ -20727,27 +23605,52 @@ fn sub8_leaf_chroma444( let default_tx = default_intra_tx_type(uv_predict_mode as u8); let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh), bw, bh); for plane_idx in 1..=2usize { - let skip_ctx = - usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1); + let skip_ctx = usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1); let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); let (levels, tx_type) = read_coeffs_rect( - dec, &mut coding, scan, bw, bh, skip_ctx, - dc_sign_ctx(around[plane_idx].2), default_tx, + dec, + &mut coding, + scan, + bw, + bh, + skip_ctx, + dc_sign_ctx(around[plane_idx].2), + default_tx, )?; let residual = dequant_and_inverse_typed_wh( - &levels, bw, bh, crate::decode::bit_depth(fctx), block_q_idx(fctx), - plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1, + &levels, + bw, + bh, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(plane_idx, fctx).0, + plane_q_delta(plane_idx, fctx).1, tx_type, - block_iqmatrix(fctx, plane_idx, bw, bh, tx_type), + block_iqmatrix(fctx, plane_idx, bw, bh, tx_type), ); let cfl = alpha .zip(ac) .map(|((au, av), ac)| (if plane_idx == 1 { au } else { av }, ac)); push_intra_rect( - plane_idx, px, py, bw, bh, uv_predict_mode, 0, reach, &residual, - cfl, None, smooth_neighbor_uv, fctx, + plane_idx, + px, + py, + bw, + bh, + uv_predict_mode, + 0, + reach, + &residual, + cfl, + None, + smooth_neighbor_uv, + fctx, ); - if plane_idx == 1 { out.0 = levels; } else { out.1 = levels; } + if plane_idx == 1 { + out.0 = levels; + } else { + out.1 = levels; + } } out } @@ -20785,7 +23688,14 @@ fn sub8_leaf_chroma444( /// [`neighbour_state`] over one `(unit_w x unit_h)` transform unit at offset /// `(x0, y0)` inside a `bw`-wide assembled chroma grid -- the per-unit stamp /// the rect arms need when a leaf carries more than one unit. -fn grid_unit_state(grid: &Grid, bw: usize, x0: usize, y0: usize, unit_w: usize, unit_h: usize) -> Neighbour { +fn grid_unit_state( + grid: &Grid, + bw: usize, + x0: usize, + y0: usize, + unit_w: usize, + unit_h: usize, +) -> Neighbour { let mut cul = 0u32; let mut dc = None; for r in 0..unit_h { @@ -20800,10 +23710,12 @@ fn grid_unit_state(grid: &Grid, bw: usize, x0: usize, y0: usize, unit_w: usize, if cul == 0 { return Neighbour::default(); } - Neighbour { level: cul.min(7) as u8, dc } + Neighbour { + level: cul.min(7) as u8, + dc, + } } - /// [`sub8_leaf_chroma444`] for 4:2:2 (lane-av1-422g): an even-mi-column 4x4 /// leaf is its plane's own chroma reference (`is_chroma_reference`'s /// `!(mi_col & ss_x)` at ss_x 1 -- every even-column leaf, not 4:2:0's single @@ -20842,7 +23754,11 @@ fn sub8_leaf_chroma422( leaf_shape: (usize, usize), fctx: &crate::decode::FrameCtx, ) -> Result<(Grid, Grid)> { - let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + let uv_predict_mode = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; // lane-av1-422kf2: libaom writes one MB_MODE_INFO per mi cell the LEAF // covers, and `chroma_left_mbmi`/`chroma_above_mbmi` read whichever of // those cells the next block's snap lands on -- an 8x4 strip's SM_V @@ -20904,8 +23820,34 @@ fn sub8_leaf_chroma422( hit!(CHROMA_SKIP_CFL_HITS); hit!(SKIP_CFL_HITS); } - push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); - push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); + push_intra( + 1, + cpx, + cpy, + 4, + uv_predict_mode, + angle_delta_uv, + reach, + &ZERO_RESIDUAL[..16], + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + fctx, + ); + push_intra( + 2, + cpx, + cpy, + 4, + uv_predict_mode, + angle_delta_uv, + reach, + &ZERO_RESIDUAL[..16], + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + fctx, + ); // The same arm-without-clear route the 4:2:0 tails count: a skipped // leaf reads no coefficient, so an armed intrabc slot is dropped. if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { @@ -20919,41 +23861,129 @@ fn sub8_leaf_chroma422( // tables with the inherited luma `tx_type` (see the 4:2:0 tails). let mut ub = vec![0u16; 16]; mc::predict_with_filter( - &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), - 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, + &u.data, + u.width, + u.true_width, + u.true_height, + mv_to_q4(cpx, dv.1, ss_x(fctx)), + mv_to_q4(cpy, dv.0, ss_y(fctx)), + 4, + 4, + mc::InterpFilterKind::Bilinear, + &mut ub, + fctx, ); let mut vb = vec![0u16; 16]; mc::predict_with_filter( - &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), - 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, + &v.data, + v.width, + v.true_width, + v.true_height, + mv_to_q4(cpx, dv.1, ss_x(fctx)), + mv_to_q4(cpy, dv.0, ss_y(fctx)), + 4, + 4, + mc::InterpFilterKind::Bilinear, + &mut vb, + fctx, ); set_palette_pred(ub, fctx); let ug = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], DC_PRED, DC_PRED, - 0, reach, u, cpx, cpy, 4, TX4, base_q_idx, - None, None, None, smooth_neighbor_uv, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + chroma_around[1], + DC_PRED, + DC_PRED, + 0, + reach, + u, + cpx, + cpy, + 4, + TX4, + base_q_idx, + None, + None, + None, + smooth_neighbor_uv, + fctx, )?; set_palette_pred(vb, fctx); let vg = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], DC_PRED, DC_PRED, - 0, reach, v, cpx, cpy, 4, TX4, base_q_idx, - None, None, None, smooth_neighbor_uv, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + chroma_around[2], + DC_PRED, + DC_PRED, + 0, + reach, + v, + cpx, + cpy, + 4, + TX4, + base_q_idx, + None, + None, + None, + smooth_neighbor_uv, + fctx, )?; fctx.intrabc_chroma_tx.with(|c| c.set(None)); (ug, vg) } else { hit!(CHROMA422_SUB8_HITS); let ug = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode, - angle_delta_uv, reach, u, cpx, cpy, 4, TX4, base_q_idx, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + chroma_around[1], + uv_mode, + uv_predict_mode, + angle_delta_uv, + reach, + u, + cpx, + cpy, + 4, + TX4, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + None, + smooth_neighbor_uv, + fctx, )?; let vg = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode, - angle_delta_uv, reach, v, cpx, cpy, 4, TX4, base_q_idx, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + chroma_around[2], + uv_mode, + uv_predict_mode, + angle_delta_uv, + reach, + v, + cpx, + cpy, + 4, + TX4, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + None, + smooth_neighbor_uv, + fctx, )?; (ug, vg) }; @@ -20976,7 +24006,6 @@ fn sub8_leaf_chroma422( Ok((u_grid, v_grid)) } - /// Decodes a `PARTITION_SPLIT` of one 8x8 block into four `BLOCK_4X4` leaves /// (spec `decode_partition`'s recursion bottom), sharing [`decode_leaf8`]'s /// own signature so its caller's `prev_leaf`/`above_mode`/`left_mode` @@ -21073,9 +24102,20 @@ fn decode_leaf_split4( }; let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1); let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8( - dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, + dec, + cdfs, + leaf_above, + leaf_left, + has_chroma, + enable_filter_intra, filter_intra_size_class(4).expect("BLOCK_4X4 has its own filter_intra row"), - skip_ctx, allow_intrabc, lmi.0, lmi.1, 1, 1, fctx, + skip_ctx, + allow_intrabc, + lmi.0, + lmi.1, + 1, + 1, + fctx, )?; leaf_modes[i] = mode; leaf_skips[i] = skip; @@ -21106,20 +24146,45 @@ fn decode_leaf_split4( flush_recon(fctx, y, u, v); let mut yb = vec![0u16; 16]; mc::predict_with_filter( - &y.data, y.width, y.true_width, y.true_height, - mv_to_q4(px, dv.1, 0), mv_to_q4(py, dv.0, 0), - 4, 4, mc::InterpFilterKind::Bilinear, &mut yb, fctx, + &y.data, + y.width, + y.true_width, + y.true_height, + mv_to_q4(px, dv.1, 0), + mv_to_q4(py, dv.0, 0), + 4, + 4, + mc::InterpFilterKind::Bilinear, + &mut yb, + fctx, ); set_palette_pred(yb.clone(), fctx); if skip { - push_intra(0, px, py, 4, DC_PRED, 0, reach, &ZERO_RESIDUAL[..16], None, None, smooth_neighbor, fctx); + push_intra( + 0, + px, + py, + 4, + DC_PRED, + 0, + reach, + &ZERO_RESIDUAL[..16], + None, + None, + smooth_neighbor, + fctx, + ); neighbours.record_mi_luma(lmi, 4, &ZERO_RESIDUAL[..16]); } else { let tu_around = neighbours.around_mi(lmi, 4)[0]; let tu_grid = read_plane( dec, cdfs, - if reduced_tx_set { TxbSet::Luma4Inter } else { TxbSet::Luma4InterSet1 }, + if reduced_tx_set { + TxbSet::Luma4Inter + } else { + TxbSet::Luma4InterSet1 + }, scan4, 0, tu_around, @@ -21136,7 +24201,8 @@ fn decode_leaf_split4( None, None, None, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, )?; neighbours.record_mi_luma(lmi, 4, &tu_grid); } @@ -21149,22 +24215,50 @@ fn decode_leaf_split4( // (`xd->tx_type_map` at the co-located luma position) -- the // luma `read_plane` above just set [`LUMA_TX_TYPE`]. Armed for // exactly this leaf's two chroma reads. - fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get)))); + fctx.intrabc_chroma_tx + .with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get)))); if chroma_444 { // lane-av1-444: this leaf codes its OWN 4x4 chroma unit // right here (frame copy at the DV); no group tail. sub8_leaf_chroma444( - dec, cdfs, neighbours, lmi, 4, 4, DC_PRED, None, skip, - Some(dv), y, u, v, scan4, base_q_idx, - neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, + dec, + cdfs, + neighbours, + lmi, + 4, + 4, + DC_PRED, + None, + skip, + Some(dv), + y, + u, + v, + scan4, + base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + fctx, )?; last_uv444 = DC_PRED; } else if chroma_422 { sub8_leaf_chroma422( - dec, cdfs, neighbours, lmi, DC_PRED, 0, None, skip, - Some(dv), y, u, v, scan4, base_q_idx, + dec, + cdfs, + neighbours, + lmi, + DC_PRED, + 0, + None, + skip, + Some(dv), + y, + u, + v, + scan4, + base_q_idx, neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), - (4, 4), fctx, + (4, 4), + fctx, )?; last_uv422 = DC_PRED; } else { @@ -21185,7 +24279,20 @@ fn decode_leaf_split4( continue; } if skip { - push_intra(0, px, py, 4, mode, angle_delta_y, reach, &ZERO_RESIDUAL[..16], None, filter_intra, smooth_neighbor, fctx); + push_intra( + 0, + px, + py, + 4, + mode, + angle_delta_y, + reach, + &ZERO_RESIDUAL[..16], + None, + filter_intra, + smooth_neighbor, + fctx, + ); neighbours.record_mi_luma(lmi, 4, &ZERO_RESIDUAL[..16]); } else { let tu_around = neighbours.around_mi(lmi, 4)[0]; @@ -21197,7 +24304,11 @@ fn decode_leaf_split4( let tu_grid = read_plane( dec, cdfs, - if reduced_tx_set { TxbSet::Luma4 } else { TxbSet::Luma4Set1 }, + if reduced_tx_set { + TxbSet::Luma4 + } else { + TxbSet::Luma4Set1 + }, scan4, 0, tu_around, @@ -21214,7 +24325,8 @@ fn decode_leaf_split4( None, filter_intra, None, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, )?; neighbours.record_mi_luma(lmi, 4, &tu_grid); } @@ -21224,24 +24336,58 @@ fn decode_leaf_split4( if chroma_444 { // lane-av1-444: the leaf's own 4x4 chroma unit, coded right // after its luma (no shared group unit at ss 0/0). - let (uv_mode, _, alpha) = - chroma.expect("4:4:4 reads uv_mode on every leaf"); + let (uv_mode, _, alpha) = chroma.expect("4:4:4 reads uv_mode on every leaf"); sub8_leaf_chroma444( - dec, cdfs, neighbours, lmi, 4, 4, uv_mode, alpha, skip, - None, y, u, v, scan4, base_q_idx, - neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, + dec, + cdfs, + neighbours, + lmi, + 4, + 4, + uv_mode, + alpha, + skip, + None, + y, + u, + v, + scan4, + base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + fctx, )?; - last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + last_uv444 = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; } else if chroma_422 { let (uv_mode, angle_delta_uv, alpha) = chroma.expect("4:2:2 reads uv_mode on even-column leaves"); sub8_leaf_chroma422( - dec, cdfs, neighbours, lmi, uv_mode, angle_delta_uv, alpha, skip, - None, y, u, v, scan4, base_q_idx, + dec, + cdfs, + neighbours, + lmi, + uv_mode, + angle_delta_uv, + alpha, + skip, + None, + y, + u, + v, + scan4, + base_q_idx, neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), - (4, 4), fctx, + (4, 4), + fctx, )?; - last_uv422 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + last_uv422 = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; } else { last_uv = chroma; } @@ -21268,92 +24414,210 @@ fn decode_leaf_split4( neighbours.left_uv_mode[r] = last_uv422; (Grid::Zero(16), Grid::Zero(16)) } else { - let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI); - let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx)); - let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx); - let (uv_mode, angle_delta_uv, alpha) = - last_uv.expect("i==3 always sets has_chroma, so chroma is always Some"); - let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; - neighbours.above_uv_mode[c] = uv_predict_mode; - neighbours.left_uv_mode[r] = uv_predict_mode; - neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); - let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[3] { - // A skipped chroma block still gets its CfL contribution: libaom's - // `predict_and_reconstruct_intra_block` calls `cfl_predict_block` - // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719) - // whenever `mbmi->uv_mode == UV_CFL_PRED`, before any residual is - // added -- `skip_txfm` only drops the residual, never the alpha. - // lane-reelckf and lane-kf1200 fixed THIS SAME arm independently; the - // merge keeps one fix and feeds both lanes' counters so neither of - // their gates goes vacuous. - let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); - if alpha.is_some() { - hit!(CHROMA_SKIP_CFL_HITS); - hit!(SKIP_CFL_HITS); - } - push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); - push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); - // lane-av1txbands: a SKIPPED chroma-reference leaf reads no chroma - // coefficient, so it never consults the inherited luma transform type - // -- but an intrabc chroma-reference leaf did arm - // [`INTRABC_CHROMA_TX`] above (`has_chroma`), and the two coefficient - // branches below are the only ones that disarm it. Left armed, the slot - // picks the NEXT block's chroma scan and inverse transform (class - // arm-without-clear-on-a-skip-route). Counted so a gate can tell a - // stream that reaches this route from one that never does. - if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { - hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); + let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI); + let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx)); + let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx); + let (uv_mode, angle_delta_uv, alpha) = + last_uv.expect("i==3 always sets has_chroma, so chroma is always Some"); + let uv_predict_mode = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; + neighbours.above_uv_mode[c] = uv_predict_mode; + neighbours.left_uv_mode[r] = uv_predict_mode; + neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); + let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[3] { + // A skipped chroma block still gets its CfL contribution: libaom's + // `predict_and_reconstruct_intra_block` calls `cfl_predict_block` + // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719) + // whenever `mbmi->uv_mode == UV_CFL_PRED`, before any residual is + // added -- `skip_txfm` only drops the residual, never the alpha. + // lane-reelckf and lane-kf1200 fixed THIS SAME arm independently; the + // merge keeps one fix and feeds both lanes' counters so neither of + // their gates goes vacuous. + let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); + if alpha.is_some() { + hit!(CHROMA_SKIP_CFL_HITS); + hit!(SKIP_CFL_HITS); + } + push_intra( + 1, + cpx, + cpy, + 4, + uv_predict_mode, + angle_delta_uv, + group_reach, + &ZERO_RESIDUAL[..16], + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + fctx, + ); + push_intra( + 2, + cpx, + cpy, + 4, + uv_predict_mode, + angle_delta_uv, + group_reach, + &ZERO_RESIDUAL[..16], + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + fctx, + ); + // lane-av1txbands: a SKIPPED chroma-reference leaf reads no chroma + // coefficient, so it never consults the inherited luma transform type + // -- but an intrabc chroma-reference leaf did arm + // [`INTRABC_CHROMA_TX`] above (`has_chroma`), and the two coefficient + // branches below are the only ones that disarm it. Left armed, the slot + // picks the NEXT block's chroma scan and inverse transform (class + // arm-without-clear-on-a-skip-route). Counted so a gate can tell a + // stream that reaches this route from one that never does. + if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { + hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + } + (Grid::Zero(16), Grid::Zero(16)) + } else if let Some(dv) = last_intrabc { + // lane-av1txr: the chroma-reference leaf was an intrabc block, so the + // group's one chroma unit is a frame copy at that DV too (its residual + // still reads the ordinary `Chroma4` coefficient tables -- libaom + // codes a chroma `tx_type` nowhere). + let mut ub = vec![0u16; 16]; + mc::predict_with_filter( + &u.data, + u.width, + u.true_width, + u.true_height, + mv_to_q4(cpx, dv.1, ss_x(fctx)), + mv_to_q4(cpy, dv.0, ss_y(fctx)), + 4, + 4, + mc::InterpFilterKind::Bilinear, + &mut ub, + fctx, + ); + let mut vb = vec![0u16; 16]; + mc::predict_with_filter( + &v.data, + v.width, + v.true_width, + v.true_height, + mv_to_q4(cpx, dv.1, ss_x(fctx)), + mv_to_q4(cpy, dv.0, ss_y(fctx)), + 4, + 4, + mc::InterpFilterKind::Bilinear, + &mut vb, + fctx, + ); + let chroma_around = neighbours.around_mi(leaf_mi, 8); + set_palette_pred(ub, fctx); + let ug = read_plane( + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + chroma_around[1], + DC_PRED, + DC_PRED, + 0, + group_reach, + u, + cpx, + cpy, + 4, + TX4, + base_q_idx, + None, + None, + None, + smooth_neighbor_uv, + fctx, + )?; + set_palette_pred(vb, fctx); + let vg = read_plane( + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + chroma_around[2], + DC_PRED, + DC_PRED, + 0, + group_reach, + v, + cpx, + cpy, + 4, + TX4, + base_q_idx, + None, + None, + None, + smooth_neighbor_uv, + fctx, + )?; fctx.intrabc_chroma_tx.with(|c| c.set(None)); - } - (Grid::Zero(16), Grid::Zero(16)) - } else if let Some(dv) = last_intrabc { - // lane-av1txr: the chroma-reference leaf was an intrabc block, so the - // group's one chroma unit is a frame copy at that DV too (its residual - // still reads the ordinary `Chroma4` coefficient tables -- libaom - // codes a chroma `tx_type` nowhere). - let mut ub = vec![0u16; 16]; - mc::predict_with_filter( - &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), - 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, - ); - let mut vb = vec![0u16; 16]; - mc::predict_with_filter( - &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), - 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, - ); - let chroma_around = neighbours.around_mi(leaf_mi, 8); - set_palette_pred(ub, fctx); - let ug = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], DC_PRED, DC_PRED, - 0, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, - None, None, None, smooth_neighbor_uv, fctx, - )?; - set_palette_pred(vb, fctx); - let vg = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], DC_PRED, DC_PRED, - 0, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, - None, None, None, smooth_neighbor_uv, fctx, - )?; - fctx.intrabc_chroma_tx.with(|c| c.set(None)); - (ug, vg) - } else { - let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); - let chroma_around = neighbours.around_mi(leaf_mi, 8); - let ug = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode, - angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx, - )?; - let vg = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode, - angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx, - )?; - (ug, vg) - }; - (u_grid, v_grid) + (ug, vg) + } else { + let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); + let chroma_around = neighbours.around_mi(leaf_mi, 8); + let ug = read_plane( + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + chroma_around[1], + uv_mode, + uv_predict_mode, + angle_delta_uv, + group_reach, + u, + cpx, + cpy, + 4, + TX4, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + None, + smooth_neighbor_uv, + fctx, + )?; + let vg = read_plane( + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + chroma_around[2], + uv_mode, + uv_predict_mode, + angle_delta_uv, + group_reach, + v, + cpx, + cpy, + 4, + TX4, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + None, + smooth_neighbor_uv, + fctx, + )?; + (ug, vg) + }; + (u_grid, v_grid) }; // Chroma neighbour bookkeeping for the whole 8x8 group -- mirrors // [`decode_leaf8`]'s own tx4-chroma section (`record_split_luma`'s @@ -21457,7 +24721,8 @@ fn decode_leaf_rect8( enable_filter_intra: bool, allow_intrabc: bool, tx_select: bool, - reduced_tx_set: bool, fctx: &crate::decode::FrameCtx, + reduced_tx_set: bool, + fctx: &crate::decode::FrameCtx, ) -> Result<(usize, usize)> { let (r, c) = outer_at; // lane-modectx r1: availability-correct fallback pair (see @@ -21513,10 +24778,21 @@ fn decode_leaf_rect8( }; let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1); let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8( - dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, + dec, + cdfs, + leaf_above, + leaf_left, + has_chroma, + enable_filter_intra, filter_intra_size_class_rect(bw, bh) .expect("BLOCK_4X8/BLOCK_8X4 are inside av1_filter_intra_allowed_bsize"), - skip_ctx, allow_intrabc, lmi.0, lmi.1, bw / 4, bh / 4, fctx, + skip_ctx, + allow_intrabc, + lmi.0, + lmi.1, + bw / 4, + bh / 4, + fctx, )?; leaf_modes[i] = mode; leaf_skips[i] = skip; @@ -21615,29 +24891,74 @@ fn decode_leaf_rect8( reach } else { tu_reach( - bw, bh, tu_px - px, tu_py - py, tw, reach, px, py, y.width, y.height, fctx, + bw, + bh, + tu_px - px, + tu_py - py, + tw, + reach, + px, + py, + y.width, + y.height, + fctx, ) }; let mut yb = vec![0u16; tw * th]; - mc::predict_with_filter( - &y.data, y.width, y.true_width, y.true_height, - mv_to_q4(tu_px, dv.1, 0), mv_to_q4(tu_py, dv.0, 0), - tw, th, mc::InterpFilterKind::Bilinear, &mut yb, fctx, - ); - set_palette_pred(yb, fctx); + mc::predict_with_filter( + &y.data, + y.width, + y.true_width, + y.true_height, + mv_to_q4(tu_px, dv.1, 0), + mv_to_q4(tu_py, dv.0, 0), + tw, + th, + mc::InterpFilterKind::Bilinear, + &mut yb, + fctx, + ); + set_palette_pred(yb, fctx); let tu_grid = if skip { let zeros = Grid::Zero(tw * th); if (tw, th) == (4, 4) { - push_intra(0, tu_px, tu_py, 4, DC_PRED, 0, tu_reach, &zeros, None, None, smooth_neighbor, fctx); + push_intra( + 0, + tu_px, + tu_py, + 4, + DC_PRED, + 0, + tu_reach, + &zeros, + None, + None, + smooth_neighbor, + fctx, + ); } else { - push_intra_rect(0, tu_px, tu_py, tw, th, DC_PRED, 0, tu_reach, &zeros, None, None, smooth_neighbor, fctx); - } - zeros - } else { - // A unit smaller than its own block (the var-tx split) - // reads its `txb_skip_ctx` off the neighbours; the - // whole-leaf unit's `plane_bsize == txsize_to_bsize` fixes - // it at 0. + push_intra_rect( + 0, + tu_px, + tu_py, + tw, + th, + DC_PRED, + 0, + tu_reach, + &zeros, + None, + None, + smooth_neighbor, + fctx, + ); + } + zeros + } else { + // A unit smaller than its own block (the var-tx split) + // reads its `txb_skip_ctx` off the neighbours; the + // whole-leaf unit's `plane_bsize == txsize_to_bsize` fixes + // it at 0. let (set, tu_scan, around, skip_ctx) = if (tw, th) == (4, 4) { ( inter_txbset_for(4, reduced_tx_set), @@ -21648,64 +24969,97 @@ fn decode_leaf_rect8( } else { ( if reduced_tx_set { - TxbSet::LumaRect8x4Inter - } else { - TxbSet::LumaRect8x4InterSet1 + TxbSet::LumaRect8x4Inter + } else { + TxbSet::LumaRect8x4InterSet1 }, scan, neighbours.around_mi_rect(tu_mi, tw, th)[0], 0, ) - }; - let mut coding = cdfs.txb(set, DC_PRED); - // lane-av1-ibc444rect: `av1_read_tx_type` returns before any - // symbol for a lossless block (qindex == 0, decodemv.c:681) - // on EVERY plane and size -- the lossless units this arm now - // walks must not read the set's tx_type either (`read_plane` - // does the same for its own call sites). Measured on the - // lane's `ll444_ibc_rect.obu`: with the symbol read, the - // first unit's ladder diverged right after a matched - // `all_zero` (ours +4096 rng on the unused tx_type). - if lossless(fctx) { - coding.tx_type = None; - } - let (levels, tx_type) = read_coeffs_rect( - dec, &mut coding, tu_scan, tw, th, skip_ctx, dc_sign_ctx(around.2), + }; + let mut coding = cdfs.txb(set, DC_PRED); + // lane-av1-ibc444rect: `av1_read_tx_type` returns before any + // symbol for a lossless block (qindex == 0, decodemv.c:681) + // on EVERY plane and size -- the lossless units this arm now + // walks must not read the set's tx_type either (`read_plane` + // does the same for its own call sites). Measured on the + // lane's `ll444_ibc_rect.obu`: with the symbol read, the + // first unit's ladder diverged right after a matched + // `all_zero` (ours +4096 rng on the unused tx_type). + if lossless(fctx) { + coding.tx_type = None; + } + let (levels, tx_type) = read_coeffs_rect( + dec, + &mut coding, + tu_scan, + tw, + th, + skip_ctx, + dc_sign_ctx(around.2), TxType::DctDct, - )?; + )?; if li == 0 { chroma_tx = tx_type; fctx.luma_tx_type.with(|c| c.set(tx_type)); } - // lane-av1-ibc444rect: the residual goes through [`TxParams`] - // with the frame's lossless flag, exactly like - // [`read_plane`]'s own dequant -- at lossless `TxParams::run` - // is the Walsh-Hadamard inverse on every plane, and the - // `dequant_and_inverse_typed_wh` shortcut the lossy var-tx - // callers use has no lossless flag (it would run the DCT - // inverse over the WHT-ordered levels). Measured on the lane - // fixture: the DCT route left ±1..30 sample errors on every - // walked leaf's luma. - let tx = TxParams { - w: tw, - h: th, - bit_depth: crate::decode::bit_depth(fctx), - q_idx: block_q_idx(fctx), - dc_delta: plane_q_delta(0, fctx).0, - ac_delta: plane_q_delta(0, fctx).1, - tx_type, - qm: block_iqmatrix(fctx, 0, tw, th, tx_type), - stride: 0, - lossless: lossless(fctx), - }; - let residual = tx.run(&levels); + // lane-av1-ibc444rect: the residual goes through [`TxParams`] + // with the frame's lossless flag, exactly like + // [`read_plane`]'s own dequant -- at lossless `TxParams::run` + // is the Walsh-Hadamard inverse on every plane, and the + // `dequant_and_inverse_typed_wh` shortcut the lossy var-tx + // callers use has no lossless flag (it would run the DCT + // inverse over the WHT-ordered levels). Measured on the lane + // fixture: the DCT route left ±1..30 sample errors on every + // walked leaf's luma. + let tx = TxParams { + w: tw, + h: th, + bit_depth: crate::decode::bit_depth(fctx), + q_idx: block_q_idx(fctx), + dc_delta: plane_q_delta(0, fctx).0, + ac_delta: plane_q_delta(0, fctx).1, + tx_type, + qm: block_iqmatrix(fctx, 0, tw, th, tx_type), + stride: 0, + lossless: lossless(fctx), + }; + let residual = tx.run(&levels); if (tw, th) == (4, 4) { - push_intra(0, tu_px, tu_py, 4, DC_PRED, 0, tu_reach, &residual, None, None, smooth_neighbor, fctx); + push_intra( + 0, + tu_px, + tu_py, + 4, + DC_PRED, + 0, + tu_reach, + &residual, + None, + None, + smooth_neighbor, + fctx, + ); } else { - push_intra_rect(0, tu_px, tu_py, tw, th, DC_PRED, 0, tu_reach, &residual, None, None, smooth_neighbor, fctx); + push_intra_rect( + 0, + tu_px, + tu_py, + tw, + th, + DC_PRED, + 0, + tu_reach, + &residual, + None, + None, + smooth_neighbor, + fctx, + ); } - levels - }; + levels + }; if single { grid = tu_grid; } else { @@ -21722,18 +25076,18 @@ fn decode_leaf_rect8( txfm_partition_update_rect(neighbours, lmi, (pub_w, pub_h), (bw, bh)); } if single { - let state = neighbour_state(&grid); - for cell in 0..h_mi { - if lmi.0 + cell < neighbours.mi_rows { - neighbours.left[lmi.0 + cell][0] = state; + let state = neighbour_state(&grid); + for cell in 0..h_mi { + if lmi.0 + cell < neighbours.mi_rows { + neighbours.left[lmi.0 + cell][0] = state; + } } - } - for cell in 0..w_mi { - if lmi.1 + cell < neighbours.mi_cols { - neighbours.above[lmi.1 + cell][0] = state; + for cell in 0..w_mi { + if lmi.1 + cell < neighbours.mi_cols { + neighbours.above[lmi.1 + cell][0] = state; + } } } - } neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip); neighbours.fill_lf_grid_rect( lmi, @@ -21755,19 +25109,46 @@ fn decode_leaf_rect8( // lane-av1-444: this leaf codes its OWN rect chroma unit // right here (frame copy at the DV); no group tail. sub8_leaf_chroma444( - dec, cdfs, neighbours, lmi, bw, bh, DC_PRED, None, skip, - Some(dv), y, u, v, scan4, base_q_idx, - neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, + dec, + cdfs, + neighbours, + lmi, + bw, + bh, + DC_PRED, + None, + skip, + Some(dv), + y, + u, + v, + scan4, + base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + fctx, )?; last_uv444 = DC_PRED; } else if chroma_422 { // lane-av1-422h: same at ss (1,0) -- the strip's own square // TX_4X4 chroma unit at its halved position. sub8_leaf_chroma422( - dec, cdfs, neighbours, lmi, DC_PRED, 0, None, skip, - Some(dv), y, u, v, scan4, base_q_idx, + dec, + cdfs, + neighbours, + lmi, + DC_PRED, + 0, + None, + skip, + Some(dv), + y, + u, + v, + scan4, + base_q_idx, neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), - (bw, bh), fctx, + (bw, bh), + fctx, )?; last_uv422 = DC_PRED; } else { @@ -21859,7 +25240,8 @@ fn decode_leaf_rect8( px, py, y.width, - y.height, fctx, + y.height, + fctx, ); let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1); if skip { @@ -21868,9 +25250,19 @@ fn decode_leaf_rect8( // one's reconstruction, which is NOT what a single 4x8 // prediction of the same mode produces. let zeros = vec![0i32; 16]; - push_intra(0, - tu_px, tu_py, 4, mode, angle_delta_y, tu_reach, &zeros, None, - filter_intra, smooth_neighbor, fctx, + push_intra( + 0, + tu_px, + tu_py, + 4, + mode, + angle_delta_y, + tu_reach, + &zeros, + None, + filter_intra, + smooth_neighbor, + fctx, ); neighbours.record_mi_luma(tu_mi, 4, &zeros); continue; @@ -21899,7 +25291,8 @@ fn decode_leaf_rect8( None, filter_intra, Some(tu_skip_ctx), - smooth_neighbor, fctx, + smooth_neighbor, + fctx, )?; if tu_grid.iter().any(|&l| l != 0) { done += 1; @@ -21919,26 +25312,60 @@ fn decode_leaf_rect8( if chroma_444 { // lane-av1-444: the leaf's own rect chroma unit after its // split luma (no shared group unit at ss 0/0). - let (uv_mode, _, alpha) = - chroma.expect("4:4:4 reads uv_mode on every leaf"); + let (uv_mode, _, alpha) = chroma.expect("4:4:4 reads uv_mode on every leaf"); sub8_leaf_chroma444( - dec, cdfs, neighbours, lmi, bw, bh, uv_mode, alpha, skip, - None, y, u, v, scan4, base_q_idx, - neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, + dec, + cdfs, + neighbours, + lmi, + bw, + bh, + uv_mode, + alpha, + skip, + None, + y, + u, + v, + scan4, + base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + fctx, )?; - last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + last_uv444 = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; } else if chroma_422 { // lane-av1-422h: the strip's own square TX_4X4 chroma unit // per plane right after its split luma (one per ref strip). let (uv_mode, angle_delta_uv, alpha) = chroma.expect("4:2:2 chroma references read uv_mode"); sub8_leaf_chroma422( - dec, cdfs, neighbours, lmi, uv_mode, angle_delta_uv, alpha, - skip, None, y, u, v, scan4, base_q_idx, + dec, + cdfs, + neighbours, + lmi, + uv_mode, + angle_delta_uv, + alpha, + skip, + None, + y, + u, + v, + scan4, + base_q_idx, neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), - (bw, bh), fctx, + (bw, bh), + fctx, )?; - last_uv422 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + last_uv422 = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; } else { last_uv = chroma; } @@ -21947,9 +25374,20 @@ fn decode_leaf_rect8( } let grid = if skip { let zeros = Grid::Zero(bw * bh); - push_intra_rect(0, - px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra, - smooth_neighbor, fctx, + push_intra_rect( + 0, + px, + py, + bw, + bh, + mode, + angle_delta_y, + reach, + &zeros, + None, + filter_intra, + smooth_neighbor, + fctx, ); zeros } else { @@ -21991,11 +25429,22 @@ fn decode_leaf_rect8( plane_q_delta(0, fctx).0, plane_q_delta(0, fctx).1, tx_type, - block_iqmatrix(fctx, 0, bw, bh, tx_type), + block_iqmatrix(fctx, 0, bw, bh, tx_type), ); - push_intra_rect(0, - px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra, - smooth_neighbor, fctx, + push_intra_rect( + 0, + px, + py, + bw, + bh, + mode, + angle_delta_y, + reach, + &residual, + None, + filter_intra, + smooth_neighbor, + fctx, ); levels }; @@ -22020,14 +25469,31 @@ fn decode_leaf_rect8( if chroma_444 { // lane-av1-444: the leaf's own rect chroma unit after its // luma (no shared group unit at ss 0/0). - let (uv_mode, _, alpha) = - chroma.expect("4:4:4 reads uv_mode on every leaf"); + let (uv_mode, _, alpha) = chroma.expect("4:4:4 reads uv_mode on every leaf"); sub8_leaf_chroma444( - dec, cdfs, neighbours, lmi, bw, bh, uv_mode, alpha, skip, - None, y, u, v, scan4, base_q_idx, - neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, + dec, + cdfs, + neighbours, + lmi, + bw, + bh, + uv_mode, + alpha, + skip, + None, + y, + u, + v, + scan4, + base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + fctx, )?; - last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + last_uv444 = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; } else if chroma_422 { // lane-av1-422h: the strip's own square TX_4X4 chroma unit // per plane right after its luma -- libaom codes each @@ -22037,12 +25503,29 @@ fn decode_leaf_rect8( let (uv_mode, angle_delta_uv, alpha) = chroma.expect("4:2:2 chroma references read uv_mode"); sub8_leaf_chroma422( - dec, cdfs, neighbours, lmi, uv_mode, angle_delta_uv, alpha, - skip, None, y, u, v, scan4, base_q_idx, + dec, + cdfs, + neighbours, + lmi, + uv_mode, + angle_delta_uv, + alpha, + skip, + None, + y, + u, + v, + scan4, + base_q_idx, neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), - (bw, bh), fctx, + (bw, bh), + fctx, )?; - last_uv422 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + last_uv422 = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; } else { last_uv = chroma; } @@ -22069,117 +25552,249 @@ fn decode_leaf_rect8( neighbours.left_uv_mode[r] = last_uv422; (Grid::Zero(16), Grid::Zero(16)) } else { - let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI); - let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx)); - let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx); - let (uv_mode, angle_delta_uv, alpha) = - last_uv.expect("i==1 always sets has_chroma, so chroma is always Some"); - let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; - neighbours.above_uv_mode[c] = uv_predict_mode; - neighbours.left_uv_mode[r] = uv_predict_mode; - neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); - let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[1] && last_intrabc.is_none() { - // A skipped chroma block still gets its CfL contribution: libaom's - // `predict_and_reconstruct_intra_block` calls `cfl_predict_block` - // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719) - // whenever `mbmi->uv_mode == UV_CFL_PRED`, before any residual is - // added -- `skip_txfm` only drops the residual, never the alpha. - // lane-reelckf and lane-kf1200 fixed THIS SAME arm independently; the - // merge keeps one fix and feeds both lanes' counters so neither of - // their gates goes vacuous. - let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); - if alpha.is_some() { - hit!(CHROMA_SKIP_CFL_HITS); - hit!(SKIP_CFL_HITS); - } - push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); - push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); - // lane-av1txbands: a SKIPPED chroma-reference leaf reads no chroma - // coefficient, so it never consults the inherited luma transform type - // -- but an intrabc chroma-reference leaf did arm - // [`INTRABC_CHROMA_TX`] above (`has_chroma`), and the two coefficient - // branches below are the only ones that disarm it. Left armed, the slot - // picks the NEXT block's chroma scan and inverse transform (class - // arm-without-clear-on-a-skip-route). Counted so a gate can tell a - // stream that reaches this route from one that never does. - if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { - hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); - fctx.intrabc_chroma_tx.with(|c| c.set(None)); - } - (Grid::Zero(16), Grid::Zero(16)) - } else if let Some(dv) = last_intrabc { - // A 4:2:0 `BLOCK_4X8`/`BLOCK_8X4` leaf maps to a clamped chroma - // `BLOCK_4X4` (`get_plane_block_size`, blockd.h:1184; `set_plane_n4`, - // av1_common_int.h:1344). The chroma reference is still the whole - // 8x8 group's 4x4 plane block at `(cpx, cpy)`, so prediction uses the - // group's destination origin, not the odd-mi leaf's nominal 2x4/4x2 - // extent. The old route treated a skipped intrabc leaf as skipped - // intra and predicted this block with DC, first differing at - // mi(46,52), U(104,92), while consuming identical symbols. - // `decode_reconstruct_tx` reads no chroma coefficients for a skipped - // intrabc block, but an unskipped one reads the ordinary Chroma4 - // tables; chroma inherits no coded tx_type of its own. - let mut ub = vec![0u16; 16]; - mc::predict_with_filter( - &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), - 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, - ); - let mut vb = vec![0u16; 16]; - mc::predict_with_filter( - &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), - 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, - ); - if leaf_skips[1] { - // `skip_txfm` still reconstructs an intrabc prediction, but - // libaom's `decode_reconstruct_tx` reads NO chroma coefficients. - // The ordinary skipped-intra arm above is therefore not valid for - // an intrabc leaf: use the copied, clamped 4x4 prediction directly. - push_mc_rect( - 1, cpx, cpy, 4, 4, 4, Pred::Inline(&ub, 4), - &ZERO_RESIDUAL[..16], fctx, + let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI); + let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx)); + let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx); + let (uv_mode, angle_delta_uv, alpha) = + last_uv.expect("i==1 always sets has_chroma, so chroma is always Some"); + let uv_predict_mode = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; + neighbours.above_uv_mode[c] = uv_predict_mode; + neighbours.left_uv_mode[r] = uv_predict_mode; + neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); + let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[1] && last_intrabc.is_none() { + // A skipped chroma block still gets its CfL contribution: libaom's + // `predict_and_reconstruct_intra_block` calls `cfl_predict_block` + // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719) + // whenever `mbmi->uv_mode == UV_CFL_PRED`, before any residual is + // added -- `skip_txfm` only drops the residual, never the alpha. + // lane-reelckf and lane-kf1200 fixed THIS SAME arm independently; the + // merge keeps one fix and feeds both lanes' counters so neither of + // their gates goes vacuous. + let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); + if alpha.is_some() { + hit!(CHROMA_SKIP_CFL_HITS); + hit!(SKIP_CFL_HITS); + } + push_intra( + 1, + cpx, + cpy, + 4, + uv_predict_mode, + angle_delta_uv, + group_reach, + &ZERO_RESIDUAL[..16], + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + fctx, ); - push_mc_rect( - 2, cpx, cpy, 4, 4, 4, Pred::Inline(&vb, 4), - &ZERO_RESIDUAL[..16], fctx, + push_intra( + 2, + cpx, + cpy, + 4, + uv_predict_mode, + angle_delta_uv, + group_reach, + &ZERO_RESIDUAL[..16], + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + fctx, ); - hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); - fctx.intrabc_chroma_tx.with(|c| c.set(None)); + // lane-av1txbands: a SKIPPED chroma-reference leaf reads no chroma + // coefficient, so it never consults the inherited luma transform type + // -- but an intrabc chroma-reference leaf did arm + // [`INTRABC_CHROMA_TX`] above (`has_chroma`), and the two coefficient + // branches below are the only ones that disarm it. Left armed, the slot + // picks the NEXT block's chroma scan and inverse transform (class + // arm-without-clear-on-a-skip-route). Counted so a gate can tell a + // stream that reaches this route from one that never does. + if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { + hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + } (Grid::Zero(16), Grid::Zero(16)) + } else if let Some(dv) = last_intrabc { + // A 4:2:0 `BLOCK_4X8`/`BLOCK_8X4` leaf maps to a clamped chroma + // `BLOCK_4X4` (`get_plane_block_size`, blockd.h:1184; `set_plane_n4`, + // av1_common_int.h:1344). The chroma reference is still the whole + // 8x8 group's 4x4 plane block at `(cpx, cpy)`, so prediction uses the + // group's destination origin, not the odd-mi leaf's nominal 2x4/4x2 + // extent. The old route treated a skipped intrabc leaf as skipped + // intra and predicted this block with DC, first differing at + // mi(46,52), U(104,92), while consuming identical symbols. + // `decode_reconstruct_tx` reads no chroma coefficients for a skipped + // intrabc block, but an unskipped one reads the ordinary Chroma4 + // tables; chroma inherits no coded tx_type of its own. + let mut ub = vec![0u16; 16]; + mc::predict_with_filter( + &u.data, + u.width, + u.true_width, + u.true_height, + mv_to_q4(cpx, dv.1, ss_x(fctx)), + mv_to_q4(cpy, dv.0, ss_y(fctx)), + 4, + 4, + mc::InterpFilterKind::Bilinear, + &mut ub, + fctx, + ); + let mut vb = vec![0u16; 16]; + mc::predict_with_filter( + &v.data, + v.width, + v.true_width, + v.true_height, + mv_to_q4(cpx, dv.1, ss_x(fctx)), + mv_to_q4(cpy, dv.0, ss_y(fctx)), + 4, + 4, + mc::InterpFilterKind::Bilinear, + &mut vb, + fctx, + ); + if leaf_skips[1] { + // `skip_txfm` still reconstructs an intrabc prediction, but + // libaom's `decode_reconstruct_tx` reads NO chroma coefficients. + // The ordinary skipped-intra arm above is therefore not valid for + // an intrabc leaf: use the copied, clamped 4x4 prediction directly. + push_mc_rect( + 1, + cpx, + cpy, + 4, + 4, + 4, + Pred::Inline(&ub, 4), + &ZERO_RESIDUAL[..16], + fctx, + ); + push_mc_rect( + 2, + cpx, + cpy, + 4, + 4, + 4, + Pred::Inline(&vb, 4), + &ZERO_RESIDUAL[..16], + fctx, + ); + hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + (Grid::Zero(16), Grid::Zero(16)) + } else { + let chroma_around = neighbours.around_mi(leaf_mi, 8); + set_palette_pred(ub, fctx); + let ug = read_plane( + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + chroma_around[1], + DC_PRED, + DC_PRED, + 0, + group_reach, + u, + cpx, + cpy, + 4, + TX4, + base_q_idx, + None, + None, + None, + smooth_neighbor_uv, + fctx, + )?; + set_palette_pred(vb, fctx); + let vg = read_plane( + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + chroma_around[2], + DC_PRED, + DC_PRED, + 0, + group_reach, + v, + cpx, + cpy, + 4, + TX4, + base_q_idx, + None, + None, + None, + smooth_neighbor_uv, + fctx, + )?; + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + (ug, vg) + } } else { + let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); let chroma_around = neighbours.around_mi(leaf_mi, 8); - set_palette_pred(ub, fctx); let ug = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], DC_PRED, DC_PRED, - 0, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, - None, None, None, smooth_neighbor_uv, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + chroma_around[1], + uv_mode, + uv_predict_mode, + angle_delta_uv, + group_reach, + u, + cpx, + cpy, + 4, + TX4, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + None, + smooth_neighbor_uv, + fctx, )?; - set_palette_pred(vb, fctx); let vg = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], DC_PRED, DC_PRED, - 0, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, - None, None, None, smooth_neighbor_uv, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + chroma_around[2], + uv_mode, + uv_predict_mode, + angle_delta_uv, + group_reach, + v, + cpx, + cpy, + 4, + TX4, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + None, + smooth_neighbor_uv, + fctx, )?; - fctx.intrabc_chroma_tx.with(|c| c.set(None)); (ug, vg) - } - } else { - let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); - let chroma_around = neighbours.around_mi(leaf_mi, 8); - let ug = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode, - angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx, - )?; - let vg = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode, - angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx, - )?; - (ug, vg) - }; - (u_grid, v_grid) + }; + (u_grid, v_grid) }; // `update_partition_context` at the 8x8 level writes // `partition_context_lookup[subsize]` over the whole 8x8 span: BLOCK_4X8 @@ -22361,7 +25976,8 @@ fn cdef_find_dir_partials(win: &[i16], bstride: usize, coeff_shift: i32) -> [[i3 let base = (i + CDEF_BORDER) * bstride + CDEF_BORDER; // libaom `cdef_find_dir_c`: normalise to an 8-bit sample before // accumulating, same as `constrain`'s threshold shift. - let row: [i32; 8] = core::array::from_fn(|j| (i32::from(win[base + j]) >> coeff_shift) - 128); + let row: [i32; 8] = + core::array::from_fn(|j| (i32::from(win[base + j]) >> coeff_shift) - 128); let rev: [i32; 8] = core::array::from_fn(|j| row[7 - j]); let pair: [i32; 4] = core::array::from_fn(|k| row[2 * k] + row[2 * k + 1]); let rpair: [i32; 4] = core::array::from_fn(|k| pair[3 - k]); @@ -22466,7 +26082,8 @@ fn cdef_filter_block( sec_damping: i32, enable_primary: bool, enable_secondary: bool, - coeff_shift: i32, fctx: &crate::decode::FrameCtx, + coeff_shift: i32, + fctx: &crate::decode::FrameCtx, ) { let (stride, smax) = (dst.width, sample_max(fctx)); #[cfg(target_arch = "x86_64")] @@ -22553,10 +26170,15 @@ fn cdef_filter_block_scalar( // `src` is [`cdef_gather`]'s window: (i, j) in block coordinates, taps // reaching +-CDEF_BORDER, so every index below is in range by construction. let at = |i: i32, j: i32| -> i32 { - i32::from(src[(i + CDEF_BORDER as i32) as usize * bstride + (j + CDEF_BORDER as i32) as usize]) + i32::from( + src[(i + CDEF_BORDER as i32) as usize * bstride + (j + CDEF_BORDER as i32) as usize], + ) }; - let (pri_dir, sec_dir0, sec_dir1) = - (CDEF_DIRECTIONS[dir], CDEF_DIRECTIONS[(dir + 2) & 7], CDEF_DIRECTIONS[(dir + 6) & 7]); + let (pri_dir, sec_dir0, sec_dir1) = ( + CDEF_DIRECTIONS[dir], + CDEF_DIRECTIONS[(dir + 2) & 7], + CDEF_DIRECTIONS[(dir + 6) & 7], + ); for i in 0..bh { for j in 0..bw { let (i32i, i32j) = (i as i32, j as i32); @@ -22628,8 +26250,8 @@ fn cdef_filter_block_scalar( #[allow(unsafe_op_in_unsafe_fn)] // the kernel's whole body is its contract mod cdef_simd { use super::{ - cdef_constrain_shift, CDEF_BORDER, CDEF_DIRECTIONS, CDEF_PRI_TAPS, CDEF_SEC_TAPS, - CDEF_VERY_LARGE, + CDEF_BORDER, CDEF_DIRECTIONS, CDEF_PRI_TAPS, CDEF_SEC_TAPS, CDEF_VERY_LARGE, + cdef_constrain_shift, }; use std::arch::x86_64::*; @@ -22764,8 +26386,11 @@ mod cdef_simd { let zero = _mm256_setzero_si256(); let eight = _mm256_set1_epi16(8); let smaxv = _mm256_set1_epi16(smax as i16); - let (pri_dir, sec_dir0, sec_dir1) = - (CDEF_DIRECTIONS[dir], CDEF_DIRECTIONS[(dir + 2) & 7], CDEF_DIRECTIONS[(dir + 6) & 7]); + let (pri_dir, sec_dir0, sec_dir1) = ( + CDEF_DIRECTIONS[dir], + CDEF_DIRECTIONS[(dir + 2) & 7], + CDEF_DIRECTIONS[(dir + 6) & 7], + ); let wp = w.as_ptr(); let bs = bstride as isize; let dp = dst.as_mut_ptr(); @@ -22824,10 +26449,7 @@ mod cdef_simd { } min = _mm256_min_epi16( min, - _mm256_min_epi16( - _mm256_min_epi16(s0, s1), - _mm256_min_epi16(s2, s3), - ), + _mm256_min_epi16(_mm256_min_epi16(s0, s1), _mm256_min_epi16(s2, s3)), ); } let c = _mm256_add_epi16( @@ -22888,7 +26510,8 @@ fn apply_deblock( lf: &LoopFilterParams, n: &Neighbours, frame_width: usize, - frame_height: usize, fctx: &crate::decode::FrameCtx, + frame_height: usize, + fctx: &crate::decode::FrameCtx, ) { // lane-part32 r2 debug rung, env-gated: bisecting a widespread pixel // mismatch between the raw reconstruction and post-filter output. @@ -22926,13 +26549,46 @@ fn deblock_span( fctx: &crate::decode::FrameCtx, ) { if lf.level[0] != 0 || lf.level[1] != 0 { - deblock_plane_span(y, 0, lf, n, frame_width, frame_height, y_lo, y_hi, horz, fctx); + deblock_plane_span( + y, + 0, + lf, + n, + frame_width, + frame_height, + y_lo, + y_hi, + horz, + fctx, + ); } if lf.level[2] != 0 { - deblock_plane_span(u, 1, lf, n, frame_width, frame_height, y_lo >> ss_y(fctx), y_hi >> ss_y(fctx), horz, fctx); + deblock_plane_span( + u, + 1, + lf, + n, + frame_width, + frame_height, + y_lo >> ss_y(fctx), + y_hi >> ss_y(fctx), + horz, + fctx, + ); } if lf.level[3] != 0 { - deblock_plane_span(v, 2, lf, n, frame_width, frame_height, y_lo >> ss_y(fctx), y_hi >> ss_y(fctx), horz, fctx); + deblock_plane_span( + v, + 2, + lf, + n, + frame_width, + frame_height, + y_lo >> ss_y(fctx), + y_hi >> ss_y(fctx), + horz, + fctx, + ); } } @@ -22953,7 +26609,11 @@ fn deblock_span( /// `context-read-from-one-cell`). fn plane_to_mi(chroma: bool, coord: usize, ss: usize) -> usize { // scale | ((coord << scale) >> 2). ss=1 is (coord/2)|1; ss=0 is coord/4. - if chroma { ss | ((coord << ss) >> 2) } else { coord / 4 } + if chroma { + ss | ((coord << ss) >> 2) + } else { + coord / 4 + } } /// This plane's own transform width in pixels at the covering block, spec @@ -22963,15 +26623,23 @@ fn plane_to_mi(chroma: bool, coord: usize, ss: usize) -> usize { /// under 4:2:0 and a block that never splits its own transform). fn tx_px_at(n: &Neighbours, chroma: bool, mi_r: usize, mi_c: usize) -> u32 { let grid = if chroma { &n.uv_tx_grid } else { &n.tx_grid }; - grid.get(mi_r * n.skip_grid_cols_mi + mi_c).copied().unwrap_or(0) as u32 + grid.get(mi_r * n.skip_grid_cols_mi + mi_c) + .copied() + .unwrap_or(0) as u32 } /// [`tx_px_at`]'s HEIGHT twin (lane-rect r2): the deblocker's horizontal /// edges step and gate by transform height, which differs from width only /// on rect partition strips. fn tx_h_px_at(n: &Neighbours, chroma: bool, mi_r: usize, mi_c: usize) -> u32 { - let grid = if chroma { &n.uv_tx_h_grid } else { &n.tx_h_grid }; - grid.get(mi_r * n.skip_grid_cols_mi + mi_c).copied().unwrap_or(0) as u32 + let grid = if chroma { + &n.uv_tx_h_grid + } else { + &n.tx_h_grid + }; + grid.get(mi_r * n.skip_grid_cols_mi + mi_c) + .copied() + .unwrap_or(0) as u32 } /// `get_tx_size_context` (spec 9.3's `TxDepthCtx`, libaom @@ -23001,7 +26669,8 @@ fn tx_size_context_txfm_rect( n: &Neighbours, (mi_r, mi_c): (usize, usize), own_w: usize, - own_h: usize, fctx: &crate::decode::FrameCtx, + own_h: usize, + fctx: &crate::decode::FrameCtx, ) -> usize { hit!(INTRA_IN_INTER_TXCTX_HITS); // `max_txsize_rect_lookup[bsize]` tops out at TX_64X64: no transform is @@ -23125,18 +26794,10 @@ fn read_tx_size( let max_tx = side.min(64); let ctx = tx_size_context_txfm(n, at_mi, max_tx); let depth = match max_tx { - 8 => { - dec.symbol(&mut cdfs.tx_size_cat0[ctx]) - } - 16 => { - dec.symbol(&mut cdfs.tx_size_cat1[ctx]) - } - 32 => { - dec.symbol(&mut cdfs.tx_size_cat2[ctx]) - } - 64 => { - dec.symbol(&mut cdfs.tx_size_cat3[ctx]) - } + 8 => dec.symbol(&mut cdfs.tx_size_cat0[ctx]), + 16 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]), + 32 => dec.symbol(&mut cdfs.tx_size_cat2[ctx]), + 64 => dec.symbol(&mut cdfs.tx_size_cat3[ctx]), _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64/128"), }; if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { @@ -23191,12 +26852,7 @@ pub(crate) fn txfm_partition_ctx_rect( /// resolves, every mi cell its *parent* unit (`txb_px`) spans records the /// resolved transform's own size. #[allow(dead_code)] // read only from the `#[cfg(test)]` gates -fn txfm_partition_update( - n: &mut Neighbours, - at_mi: (usize, usize), - tx_px: usize, - txb_px: usize, -) { +fn txfm_partition_update(n: &mut Neighbours, at_mi: (usize, usize), tx_px: usize, txb_px: usize) { txfm_partition_update_rect(n, at_mi, (tx_px, tx_px), (txb_px, txb_px)); } @@ -23235,9 +26891,13 @@ fn publish_txfm_bands_if_in_inter( n: &mut Neighbours, at_mi: (usize, usize), (tx_w, tx_h): (usize, usize), - (bw, bh): (usize, usize), fctx: &crate::decode::FrameCtx, + (bw, bh): (usize, usize), + fctx: &crate::decode::FrameCtx, ) { - if fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_none() + if fctx + .intra_in_inter_mode + .with(std::cell::Cell::get) + .is_none() && !allow_intrabc_frame(fctx) { return; @@ -23263,7 +26923,10 @@ fn txfm_partition_update_rect( (txb_w, txb_h): (usize, usize), ) { if crate::envflags::env_flag!("EC_TXUPD") { - eprintln!("EC_TXUPD rect mi=({},{}) tx=({tx_w},{tx_h}) txb=({txb_w},{txb_h})", mi_r, mi_c); + eprintln!( + "EC_TXUPD rect mi=({},{}) tx=({tx_w},{tx_h}) txb=({txb_w},{txb_h})", + mi_r, mi_c + ); } for i in 0..txb_h / MI { if let Some(cell) = n.left_txfm.get_mut(mi_r + i) { @@ -23289,7 +26952,9 @@ fn set_txfm_ctxs( skip_inter: bool, ) { if crate::envflags::env_flag!("EC_TXUPD") { - eprintln!("EC_TXUPD ctxs mi=({mi_r},{mi_c}) tx={tx_px} wh=({w_mi},{h_mi}) skip_inter={skip_inter}"); + eprintln!( + "EC_TXUPD ctxs mi=({mi_r},{mi_c}) tx={tx_px} wh=({w_mi},{h_mi}) skip_inter={skip_inter}" + ); } let bw = if skip_inter { w_mi * MI } else { tx_px }; let bh = if skip_inter { h_mi * MI } else { tx_px }; @@ -23346,11 +27011,25 @@ fn sub_tx_size_map(tx_w: usize, tx_h: usize) -> (usize, usize) { fn sub_tx_size_map_matches_libaom() { // libaom `common_data.c` `sub_tx_size_map`, in TX_SIZES_ALL order. const TABLE: [((usize, usize), (usize, usize)); 19] = [ - ((4, 4), (4, 4)), ((8, 8), (4, 4)), ((16, 16), (8, 8)), ((32, 32), (16, 16)), - ((64, 64), (32, 32)), ((4, 8), (4, 4)), ((8, 4), (4, 4)), ((8, 16), (8, 8)), - ((16, 8), (8, 8)), ((16, 32), (16, 16)), ((32, 16), (16, 16)), ((32, 64), (32, 32)), - ((64, 32), (32, 32)), ((4, 16), (4, 8)), ((16, 4), (8, 4)), ((8, 32), (8, 16)), - ((32, 8), (16, 8)), ((16, 64), (16, 32)), ((64, 16), (32, 16)), + ((4, 4), (4, 4)), + ((8, 8), (4, 4)), + ((16, 16), (8, 8)), + ((32, 32), (16, 16)), + ((64, 64), (32, 32)), + ((4, 8), (4, 4)), + ((8, 4), (4, 4)), + ((8, 16), (8, 8)), + ((16, 8), (8, 8)), + ((16, 32), (16, 16)), + ((32, 16), (16, 16)), + ((32, 64), (32, 32)), + ((64, 32), (32, 32)), + ((4, 16), (4, 8)), + ((16, 4), (8, 4)), + ((8, 32), (8, 16)), + ((32, 8), (16, 8)), + ((16, 64), (16, 32)), + ((64, 16), (32, 16)), ]; for (tx, want) in TABLE { assert_eq!(sub_tx_size_map(tx.0, tx.1), want, "sub_tx_size_map({tx:?})"); @@ -23409,7 +27088,11 @@ fn a_var_tx_tree_never_presents_a_leaf_larger_than_the_unit_it_entered() { if entry == (64, 64) { let above: Vec<&(usize, usize, usize)> = leaves.iter().filter(|(_, w, h)| w.max(h) > &32).collect(); - assert_eq!(above, [&(0usize, 64usize, 64usize)], "64x64 entry, leaves above 32"); + assert_eq!( + above, + [&(0usize, 64usize, 64usize)], + "64x64 entry, leaves above 32" + ); } } @@ -23537,7 +27220,8 @@ fn read_block_tx_size( side: usize, (mi_cols, mi_rows): (usize, usize), is_inter: bool, - skip: bool, fctx: &crate::decode::FrameCtx, + skip: bool, + fctx: &crate::decode::FrameCtx, ) -> Result<(usize, Option>)> { // lane-lossless: TX_4X4 over the whole block, and NO var-tx tree -- libaom // `read_block_tx_size` (`decodeframe.c`) sends a lossless block down the @@ -23852,7 +27536,6 @@ fn rect_inter_chroma_set(w: usize, h: usize) -> Result { }) } - /// libaom `size_group_lookup[bsize]` for the block shapes this decoder's /// inter path reaches, from the block's TRUE footprint rather than the /// square `side` corner-cut: 8x8/8x16/16x8 -> 1, 16x16/16x32/32x16 -> 2, @@ -23875,10 +27558,28 @@ fn size_group_wh_matches_libaom_size_group_lookup() { // `BLOCK_SIZES_ALL` in libaom's own order, with `size_group_lookup`'s // transcribed values (common_data.h:60-62). const TABLE: [((usize, usize), usize); 22] = [ - ((4, 4), 0), ((4, 8), 0), ((8, 4), 0), ((8, 8), 1), ((8, 16), 1), ((16, 8), 1), - ((16, 16), 2), ((16, 32), 2), ((32, 16), 2), ((32, 32), 3), ((32, 64), 3), - ((64, 32), 3), ((64, 64), 3), ((64, 128), 3), ((128, 64), 3), ((128, 128), 3), - ((4, 16), 0), ((16, 4), 0), ((8, 32), 1), ((32, 8), 1), ((16, 64), 2), ((64, 16), 2), + ((4, 4), 0), + ((4, 8), 0), + ((8, 4), 0), + ((8, 8), 1), + ((8, 16), 1), + ((16, 8), 1), + ((16, 16), 2), + ((16, 32), 2), + ((32, 16), 2), + ((32, 32), 3), + ((32, 64), 3), + ((64, 32), 3), + ((64, 64), 3), + ((64, 128), 3), + ((128, 64), 3), + ((128, 128), 3), + ((4, 16), 0), + ((16, 4), 0), + ((8, 32), 1), + ((32, 8), 1), + ((16, 64), 2), + ((64, 16), 2), ]; for ((w, h), want) in TABLE { assert_eq!(size_group_wh(w, h), want, "size_group_wh({w}, {h})"); @@ -24004,7 +27705,8 @@ fn read_block_tx_size_rect( at_mi: (usize, usize), (bw, bh): (usize, usize), (mi_cols, mi_rows): (usize, usize), - skip: bool, fctx: &crate::decode::FrameCtx, + skip: bool, + fctx: &crate::decode::FrameCtx, ) -> Result>> { if lossless(fctx) { let mut leaves = Vec::new(); @@ -24182,9 +27884,8 @@ fn read_inter_rect_chroma( // inherited luma type reduced into the TX_4X8 ext-tx set // (`reduce_inherited_chroma_tx_type`), exactly like every other rect // unit here, so the 4:2:2 drop-the-type special case is gone. - let invalid_ss_plane = ss_x(fctx) == 1 - && ss_y(fctx) == 0 - && (write_chroma_w, write_chroma_h) == (4, 32); + let invalid_ss_plane = + ss_x(fctx) == 1 && ss_y(fctx) == 0 && (write_chroma_w, write_chroma_h) == (4, 32); let (uw, uh) = if invalid_ss_plane { (4, 8) } else { (uw, uh) }; let inherit_tx_type = Some(luma_tx_type); let (nx, ny) = (write_chroma_w / uw, write_chroma_h / uh); @@ -24212,7 +27913,11 @@ fn read_inter_rect_chroma( ]; } for plane_idx in 1..=2 { - let (src, buf) = if plane_idx == 1 { (su, &mut *u) } else { (sv, &mut *v) }; + let (src, buf) = if plane_idx == 1 { + (su, &mut *u) + } else { + (sv, &mut *v) + }; for cu_row in 0..ny { for cu_col in 0..nx { let (span_x, span_y) = (uw << ss_x(fctx), uh << ss_y(fctx)); @@ -24253,7 +27958,8 @@ fn read_inter_rect_chroma( cu_y, cu_pred, inherit_tx_type, - multi.then_some(3), fctx, + multi.then_some(3), + fctx, )? .0; if invalid_ss_plane { @@ -24273,8 +27979,7 @@ fn read_inter_rect_chroma( } else { let mut full = vec![0i32; chroma_side * assembled_h]; for rr in 0..uh { - full[rr * chroma_side..][..uw] - .copy_from_slice(&cu_grid[rr * uw..][..uw]); + full[rr * chroma_side..][..uw].copy_from_slice(&cu_grid[rr * uw..][..uw]); } assembled[plane_idx - 1] = full; } @@ -24315,7 +28020,8 @@ fn read_inter_plane_rect( y: usize, prediction: Pred<'_>, inherited_luma_tx_type: Option, - luma_skip_ctx: Option, fctx: &crate::decode::FrameCtx, + luma_skip_ctx: Option, + fctx: &crate::decode::FrameCtx, ) -> Result<(Grid, TxType)> { // lane-av1mono: as [`read_plane`] -- a monochrome frame codes no chroma // coefficients (`plane < av1_num_planes == 1`). @@ -24351,7 +28057,11 @@ fn read_inter_plane_rect( }; // libaom `av1_get_tx_type` (`blockd.h`): a lossless block's type is // DCT_DCT on EVERY plane, so chroma never inherits or mode-derives one. - let default_tx_type = if lossless(fctx) { TxType::DctDct } else { default_tx_type }; + let default_tx_type = if lossless(fctx) { + TxType::DctDct + } else { + default_tx_type + }; // lane-r14 r2: a 64-length axis codes only its low 32 coefficients // (`av1_get_max_eob`), so the coded unit is the `min(w,32) x min(h,32)` // corner, zero-extended into the true `w x h` grid before the inverse @@ -24399,15 +28109,24 @@ fn read_inter_plane_rect( let grid = extend_corner(corner, cw, ch, w, h); let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx); if crate::envflags::env_flag!("EC_TRACE_TXTYPE") { - eprintln!("OUR_TXTYPE plane={plane_idx} x={x} y={y} w={w} h={h} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}"); + eprintln!( + "OUR_TXTYPE plane={plane_idx} x={x} y={y} w={w} h={h} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}" + ); } // `reconstruct_mc_rect` reads both buffers at the square prediction // stride, so the dense `w x h` residual is re-laid at that stride // (`TxParams::stride`) after the inverse transform. let tx = TxParams { - w, h, bit_depth: bit_depth(fctx), q_idx: block_q_idx(fctx), dc_delta, ac_delta, tx_type, + w, + h, + bit_depth: bit_depth(fctx), + q_idx: block_q_idx(fctx), + dc_delta, + ac_delta, + tx_type, qm: block_iqmatrix(fctx, plane_idx, w, h, tx_type), - stride, lossless: lossless(fctx), + stride, + lossless: lossless(fctx), }; push_mc_rect_tx(plane_idx, x, y, stride, w, h, prediction, tx, &grid, fctx); Ok((grid, tx_type)) @@ -24474,7 +28193,8 @@ fn read_inter_luma8( scan8: &[u16], scan4: &[u16], reduced_tx_set: bool, - split: bool, fctx: &crate::decode::FrameCtx, + split: bool, + fctx: &crate::decode::FrameCtx, ) -> Result<(Grid, TxType)> { // lane-lossless: an 8x8 inter block is FOUR 4x4 units (libaom // `read_block_tx_size`'s lossless TX_4X4), tree or no tree. @@ -24499,7 +28219,8 @@ fn read_inter_luma8( base_q_idx, pred_y, None, - None, fctx, + None, + fctx, ); } let mut first = TxType::DctDct; @@ -24527,7 +28248,8 @@ fn read_inter_luma8( base_q_idx, tu_pred, None, - Some(tu_skip_ctx), fctx, + Some(tu_skip_ctx), + fctx, )?; if tu_row == 0 && tu_col == 0 { first = tu_tx_type; @@ -24553,8 +28275,18 @@ fn read_inter_luma8( /// both `TX_CLASS_2D`, so that mistake left the entropy stream perfectly in /// sync and only corrupted the inverse transform (one 64x64 superblock of /// high-frequency chroma noise, luma bit-exact). -pub(crate) fn reduce_inherited_chroma_tx_type(t: TxType, w: usize, h: usize, fctx: &crate::decode::FrameCtx) -> TxType { - reduce_inherited_chroma_tx_type_flagged(t, w, h, fctx.reduced_tx_set_inter.with(std::cell::Cell::get)) +pub(crate) fn reduce_inherited_chroma_tx_type( + t: TxType, + w: usize, + h: usize, + fctx: &crate::decode::FrameCtx, +) -> TxType { + reduce_inherited_chroma_tx_type_flagged( + t, + w, + h, + fctx.reduced_tx_set_inter.with(std::cell::Cell::get), + ) } /// [`reduce_inherited_chroma_tx_type`] against an explicit `reduced_tx_set` @@ -24563,7 +28295,12 @@ pub(crate) fn reduce_inherited_chroma_tx_type(t: TxType, w: usize, h: usize, fct /// block's chroma transform is coded with, the same derivation its reader /// makes -- it has no `FrameCtx` in reach and must not silently read one /// whose value can lag the frame being written (class `stale-context-bit`). -pub(crate) fn reduce_inherited_chroma_tx_type_flagged(t: TxType, w: usize, h: usize, reduced: bool) -> TxType { +pub(crate) fn reduce_inherited_chroma_tx_type_flagged( + t: TxType, + w: usize, + h: usize, + reduced: bool, +) -> TxType { use TxType::*; let sqr_up = w.max(h); let sqr = w.min(h); @@ -24578,8 +28315,18 @@ pub(crate) fn reduce_inherited_chroma_tx_type_flagged(t: TxType, w: usize, h: us // EXT_TX_SET_DTT9_IDTX_1DDCT -- TX_TYPES 0..=11, i.e. everything but // the four 1D ADST/FLIPADST types. &[ - DctDct, AdstDct, DctAdst, AdstAdst, FlipAdstDct, DctFlipAdst, FlipAdstFlipAdst, - AdstFlipAdst, FlipAdstAdst, Idtx, VDct, HDct, + DctDct, + AdstDct, + DctAdst, + AdstAdst, + FlipAdstDct, + DctFlipAdst, + FlipAdstFlipAdst, + AdstFlipAdst, + FlipAdstAdst, + Idtx, + VDct, + HDct, ] } else { // EXT_TX_SET_ALL16 @@ -24646,7 +28393,6 @@ fn scan_for<'a>( } } - fn txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet { match tx_px { 64 => TxbSet::Luma64, @@ -24684,7 +28430,8 @@ fn lf_level( dir: usize, ref_frame: i8, delta_lf: i32, - segment_id: u8, fctx: &crate::decode::FrameCtx, + segment_id: u8, + fctx: &crate::decode::FrameCtx, ) -> i32 { let base = i32::from(if plane_idx == 0 { lf.level[dir] @@ -24702,7 +28449,11 @@ fn lf_level( // per-superblock `DeltaLF` term and before the ref/mode deltas below. // Feature index: `SEG_LVL_ALT_LF_Y_V + dir` for luma, `_U`/`_V` (3/4) // for chroma. - let feature = if plane_idx == 0 { SEG_LVL_ALT_LF_Y_V + dir } else { plane_idx + 2 }; + let feature = if plane_idx == 0 { + SEG_LVL_ALT_LF_Y_V + dir + } else { + plane_idx + 2 + }; // lane-perf9: `segment_id` is `0` and this lookup is skipped entirely // when the frame codes no segmentation (`seg_lf_active`), which is what // spares the deblock loop two thread-local reads per 4x4 edge. @@ -24748,18 +28499,28 @@ fn lvl_table( base0: i32, fctx: &crate::decode::FrameCtx, ) -> [[u8; 15]; 64] { - let feature = if plane_idx == 0 { SEG_LVL_ALT_LF_Y_V + dir } else { plane_idx + 2 }; + let feature = if plane_idx == 0 { + SEG_LVL_ALT_LF_Y_V + dir + } else { + plane_idx + 2 + }; let key = (plane_idx, dir, *lf, seg_feature(0, feature, fctx)); - if let Some(t) = LVL_CACHE.with(|c| { - c.borrow().iter().find(|(k, _)| *k == key).map(|(_, t)| *t) - }) { + if let Some(t) = LVL_CACHE.with(|c| c.borrow().iter().find(|(k, _)| *k == key).map(|(_, t)| *t)) + { return t; } let mut lvl = [[0u8; 15]; 64]; for (b, row) in lvl.iter_mut().enumerate() { for (r, cell) in row.iter_mut().enumerate() { - *cell = - lf_level(lf, plane_idx, dir, (r as i32 - 7) as i8, b as i32 - base0, 0, fctx) as u8; + *cell = lf_level( + lf, + plane_idx, + dir, + (r as i32 - 7) as i8, + b as i32 - base0, + 0, + fctx, + ) as u8; } } LVL_CACHE.with(|c| { @@ -24834,7 +28595,11 @@ impl<'a> EdgeCtx<'a> { chroma, seg_lf_active, delta_idx: if plane_idx == 0 { dir } else { plane_idx + 1 }, - step: if chroma { 1 << (if dir == 0 { ss_x(fctx) } else { ss_y(fctx) }) } else { 1 }, + step: if chroma { + 1 << (if dir == 0 { ss_x(fctx) } else { ss_y(fctx) }) + } else { + 1 + }, base0, lvl, } @@ -24845,7 +28610,15 @@ impl<'a> EdgeCtx<'a> { #[inline(always)] fn level(&self, ref_frame: i8, delta_lf: i32, seg: u8) -> i32 { if self.seg_lf_active { - return lf_level(self.lf, self.plane_idx, self.dir, ref_frame, delta_lf, seg, self.fctx); + return lf_level( + self.lf, + self.plane_idx, + self.dir, + ref_frame, + delta_lf, + seg, + self.fctx, + ); } let b = (self.base0 + delta_lf).clamp(0, 63) as usize; debug_assert!((-7..=7).contains(&ref_frame)); @@ -24938,7 +28711,11 @@ fn edge_params_body( (usize::from(cur_org[0]), usize::from(cur_dim[1])) }; let pu_edge = if c.chroma { - let ss = if c.dir == 0 { ss_x(c.fctx) } else { ss_y(c.fctx) }; + let ss = if c.dir == 0 { + ss_x(c.fctx) + } else { + ss_y(c.fctx) + }; let plane_dim = ((dim_mi * MI) >> ss).max(4); (if c.dir == 0 { x0 } else { y0 }) % plane_dim == 0 } else { @@ -24953,7 +28730,10 @@ fn edge_params_body( return None; } let (cur_seg, pv_seg) = if c.seg_lf_active { - (segment_id_at(mi_r, mi_c, c.fctx), segment_id_at(pv_mi_r, pv_mi_c, c.fctx)) + ( + segment_id_at(mi_r, mi_c, c.fctx), + segment_id_at(pv_mi_r, pv_mi_c, c.fctx), + ) } else { (0, 0) }; @@ -24999,7 +28779,15 @@ fn round_pow2(v: i32, n: u32) -> i32 { /// `filter4`: the narrow 4-tap kernel, and every wider kernel's non-flat /// fallback. -fn filter4(mask: bool, thresh: i32, p1: i32, p0: i32, q0: i32, q1: i32, fctx: &crate::decode::FrameCtx) -> [i32; 4] { +fn filter4( + mask: bool, + thresh: i32, + p1: i32, + p0: i32, + q0: i32, + q1: i32, + fctx: &crate::decode::FrameCtx, +) -> [i32; 4] { if !mask { return [p1, p0, q0, q1]; } @@ -25035,7 +28823,8 @@ fn filter6( p0: i32, q0: i32, q1: i32, - q2: i32, fctx: &crate::decode::FrameCtx, + q2: i32, + fctx: &crate::decode::FrameCtx, ) -> [i32; 4] { if flat && mask { [ @@ -25062,7 +28851,8 @@ fn filter8( q0: i32, q1: i32, q2: i32, - q3: i32, fctx: &crate::decode::FrameCtx, + q3: i32, + fctx: &crate::decode::FrameCtx, ) -> [i32; 6] { if flat && mask { [ @@ -25101,7 +28891,8 @@ fn filter14( q3: i32, q4: i32, q5: i32, - q6: i32, fctx: &crate::decode::FrameCtx, + q6: i32, + fctx: &crate::decode::FrameCtx, ) -> [i32; 12] { if flat2 && flat && mask { [ @@ -25167,7 +28958,8 @@ fn filter_edge( tap_stride: isize, len: u8, level: i32, - sharpness: u8, fctx: &crate::decode::FrameCtx, + sharpness: u8, + fctx: &crate::decode::FrameCtx, ) { let (blimit, limit, hev_thr) = deblock_thresholds(level, sharpness); // libaom `highbd_filter_mask*`/`highbd_flat_mask4`/`highbd_hev_mask`: @@ -25205,7 +28997,8 @@ fn filter_edge( && (q1 - q0).abs() <= flat_thresh && (p2 - p0).abs() <= flat_thresh && (q2 - q0).abs() <= flat_thresh; - let [op1, op0, oq0, oq1] = filter6(mask, hev_thr, flat, p2, p1, p0, q0, q1, q2, fctx); + let [op1, op0, oq0, oq1] = + filter6(mask, hev_thr, flat, p2, p1, p0, q0, q1, q2, fctx); data[idx(-2)] = op1.clamp(0, smax) as u16; data[idx(-1)] = op0.clamp(0, smax) as u16; data[idx(0)] = oq0.clamp(0, smax) as u16; @@ -25403,10 +29196,7 @@ mod deblock_simd { /// 34% of this kernel's samples, and the spilled tap slices another 17%). #[target_feature(enable = "avx2")] #[inline] // rust#145574: `inline(always)` is rejected on a `target_feature` fn - unsafe fn wsum( - taps: &[__m256i; N], - w: &[i16; N], - ) -> __m256i { + unsafe fn wsum(taps: &[__m256i; N], w: &[i16; N]) -> __m256i { let mut s = _mm256_setzero_si256(); for i in 0..N { match w[i] { @@ -25539,10 +29329,22 @@ mod deblock_simd { if LEN == 6 { if any_flat { let taps = [p2, p1, p0, q0, q1, q2]; - put!(6, _mm256_blendv_epi8(b_p1, wsum::<_, 3>(&taps, &W6[0]), flat)); - put!(7, _mm256_blendv_epi8(b_p0, wsum::<_, 3>(&taps, &W6[1]), flat)); - put!(8, _mm256_blendv_epi8(b_q0, wsum::<_, 3>(&taps, &W6[2]), flat)); - put!(9, _mm256_blendv_epi8(b_q1, wsum::<_, 3>(&taps, &W6[3]), flat)); + put!( + 6, + _mm256_blendv_epi8(b_p1, wsum::<_, 3>(&taps, &W6[0]), flat) + ); + put!( + 7, + _mm256_blendv_epi8(b_p0, wsum::<_, 3>(&taps, &W6[1]), flat) + ); + put!( + 8, + _mm256_blendv_epi8(b_q0, wsum::<_, 3>(&taps, &W6[2]), flat) + ); + put!( + 9, + _mm256_blendv_epi8(b_q1, wsum::<_, 3>(&taps, &W6[3]), flat) + ); } else { put!(6, b_p1); put!(7, b_p0); @@ -25733,7 +29535,8 @@ fn filter_edge16( vertical: bool, len: u8, level: i32, - sharpness: u8, fctx: &crate::decode::FrameCtx, + sharpness: u8, + fctx: &crate::decode::FrameCtx, ) -> bool { #[cfg(target_arch = "x86_64")] { @@ -25772,14 +29575,37 @@ fn deblock_plane( lf: &LoopFilterParams, n: &Neighbours, frame_width: usize, - frame_height: usize, fctx: &crate::decode::FrameCtx, + frame_height: usize, + fctx: &crate::decode::FrameCtx, ) { // spec 7.14's order: this plane's whole vertical pass, then its whole // horizontal one. lane-pipefilt split the two into one row-ranged // function so the per-superblock-row pipeline can run them a band at a // time; `0..usize::MAX` is the whole plane, i.e. exactly this call. - deblock_plane_span(plane, plane_idx, lf, n, frame_width, frame_height, 0, usize::MAX, false, fctx); - deblock_plane_span(plane, plane_idx, lf, n, frame_width, frame_height, 0, usize::MAX, true, fctx); + deblock_plane_span( + plane, + plane_idx, + lf, + n, + frame_width, + frame_height, + 0, + usize::MAX, + false, + fctx, + ); + deblock_plane_span( + plane, + plane_idx, + lf, + n, + frame_width, + frame_height, + 0, + usize::MAX, + true, + fctx, + ); } /// One pass of [`deblock_plane`] -- vertical edges (`horz == false`) or @@ -25840,7 +29666,10 @@ fn deblock_plane_span( plane.width, ); if crate::envflags::env_flag!("EC_AV1_DEBLOCK_TRACE_V") { - eprintln!("DEBLOCK plane={plane_idx} tw={tw} th={th} stride={stride} true={}x{} crop={cw}x{ch}", plane.true_width, plane.true_height); + eprintln!( + "DEBLOCK plane={plane_idx} tw={tw} th={th} stride={stride} true={}x{} crop={cw}x{ch}", + plane.true_width, plane.true_height + ); } // lane-perf8: both passes iterate the edge's OWN direction innermost, so // 4 consecutive 4-sample groups (16 lines) can go through one AVX2 @@ -25900,7 +29729,8 @@ fn deblock_plane_span( true, len, level, - lf.sharpness, fctx, + lf.sharpness, + fctx, ) { y0 += 16; @@ -25916,7 +29746,8 @@ fn deblock_plane_span( 1, len, level, - lf.sharpness, fctx, + lf.sharpness, + fctx, ); } } @@ -25934,7 +29765,8 @@ fn deblock_plane_span( 1, len, level, - lf.sharpness, fctx, + lf.sharpness, + fctx, ); } y0 += 4; @@ -25973,7 +29805,8 @@ fn deblock_plane_span( false, len, level, - lf.sharpness, fctx, + lf.sharpness, + fctx, ) { x0 += 16; @@ -25989,7 +29822,8 @@ fn deblock_plane_span( stride as isize, len, level, - lf.sharpness, fctx, + lf.sharpness, + fctx, ); } } @@ -26013,13 +29847,15 @@ fn deblock_plane_span( stride as isize, len, level, - lf.sharpness, fctx, + lf.sharpness, + fctx, ); } x0 += 4; } y0 += 4; - } }); + } + }); } /// lane-perf6: reused whole-plane `u16` buffers. Every frame takes a @@ -26115,12 +29951,19 @@ fn scratch_sized(n: usize) -> Vec { /// the pooled buffer keeps whatever a previous frame left there -- an /// initialised value that no reader ever reaches. fn snap_alloc(p: &PlaneBuf<'_>) -> PlaneBuf<'static> { - PlaneBuf { data: std::borrow::Cow::Owned(scratch_sized(p.data.len())), ..*p } + PlaneBuf { + data: std::borrow::Cow::Owned(scratch_sized(p.data.len())), + ..*p + } } fn plane_snapshot(p: &PlaneBuf<'_>, ss_y: u32) -> PlaneBuf<'static> { let mut data = scratch_sized(p.data.len()); - let rows = if p.width == 0 { 0 } else { p.data.len() / p.width }; + let rows = if p.width == 0 { + 0 + } else { + p.data.len() / p.width + }; let stripe_h = 64usize >> ss_y; let offset = 8usize >> ss_y; let mut b = stripe_h - offset; @@ -26129,7 +29972,10 @@ fn plane_snapshot(p: &PlaneBuf<'_>, ss_y: u32) -> PlaneBuf<'static> { data[lo * p.width..hi * p.width].copy_from_slice(&p.data[lo * p.width..hi * p.width]); b += stripe_h; } - PlaneBuf { data: std::borrow::Cow::Owned(data), ..*p } + PlaneBuf { + data: std::borrow::Cow::Owned(data), + ..*p + } } /// The pre-filter reconstruction of one coded frame, plus the per-block state @@ -26188,7 +30034,12 @@ pub(crate) struct FilterReplay { /// Deblocking depends on nothing else the search moves, and the search /// fixes the levels before it walks the CDEF strengths, so every /// candidate after the first of a level pair replays CDEF alone. - deblocked: Option<(LoopFilterParams, PlaneBuf<'static>, PlaneBuf<'static>, PlaneBuf<'static>)>, + deblocked: Option<( + LoopFilterParams, + PlaneBuf<'static>, + PlaneBuf<'static>, + PlaneBuf<'static>, + )>, } thread_local! { @@ -26259,7 +30110,10 @@ fn capture_filter_replay( if !REPLAY_ARMED.replace(false) { return; } - let own = |p: &PlaneBuf<'_>| PlaneBuf { data: std::borrow::Cow::Owned(p.data.to_vec()), ..*p }; + let own = |p: &PlaneBuf<'_>| PlaneBuf { + data: std::borrow::Cow::Owned(p.data.to_vec()), + ..*p + }; REPLAY.with_borrow_mut(|slot| { *slot = Some(FilterReplay { y: own(y), @@ -26308,7 +30162,10 @@ fn restore_written( let Some(c0) = row.iter().position(|&b| b & mask != 0) else { continue; }; - let c1 = row.iter().rposition(|&b| b & mask != 0).expect("just found one"); + let c1 = row + .iter() + .rposition(|&b| b & mask != 0) + .expect("just found one"); let (x0, x1) = ((c0 * unit).min(w), ((c1 + 1) * unit).min(w)); let ur = ur0 + i; let (y0, y1) = ((ur * unit).min(rows), ((ur + 1) * unit).min(rows)); @@ -26326,7 +30183,10 @@ fn restore_written( } let per = urows.div_ceil(threads); let batch = crate::par::Batch::new("ec-av1-filter"); - for (i, (dc, wr)) in d.chunks_mut(per * unit * w).zip(wrote.chunks(per * unit_cols)).enumerate() + for (i, (dc, wr)) in d + .chunks_mut(per * unit * w) + .zip(wrote.chunks(per * unit_cols)) + .enumerate() { let band = &band; batch.submit(move || band(dc, wr, i * per)); @@ -26354,7 +30214,10 @@ fn pooled(p: &PlaneBuf<'_>, scratch: &mut Vec>) -> PlaneBuf<'static> { batch.submit(move || dst.copy_from_slice(src)); } } - PlaneBuf { data: std::borrow::Cow::Owned(buf), ..*p } + PlaneBuf { + data: std::borrow::Cow::Owned(buf), + ..*p + } } /// The filter half of a captured decode, under new parameters: exactly the @@ -26429,7 +30292,8 @@ fn replay_inner( // source, so the samples under it need not be put back first. // Only while both candidates carry ONE strength pair (`bits == // 0`, every scoring candidate) and read the same `cdef_idx` grid. - let superset = |cur: (u8, u8), old: (u8, u8)| cur.0 >= old.0 && (cur.1 != 0 || old.1 == 0); + let superset = + |cur: (u8, u8), old: (u8, u8)| cur.0 >= old.0 && (cur.1 != 0 || old.1 == 0); let (skip_y, skip_uv) = match (final_pass, &r.work_cdef) { (None, Some(old)) if old.bits == 0 && cdef.bits == 0 => ( superset( @@ -26456,7 +30320,11 @@ fn replay_inner( } (wy, wu, wv) } - None => (pooled(dy, scratch), pooled(du, scratch), pooled(dv, scratch)), + None => ( + pooled(dy, scratch), + pooled(du, scratch), + pooled(dv, scratch), + ), } } else { // The levels moved, so the cached deblocked planes are dead: @@ -26471,8 +30339,11 @@ fn replay_inner( r.scratch.push(dv.data.into_owned()); } let (cap_y, cap_u, cap_v, scratch) = (&r.y, &r.u, &r.v, &mut r.scratch); - let (mut y, mut u, mut v) = - (pooled(cap_y, scratch), pooled(cap_u, scratch), pooled(cap_v, scratch)); + let (mut y, mut u, mut v) = ( + pooled(cap_y, scratch), + pooled(cap_u, scratch), + pooled(cap_v, scratch), + ); let _t = crate::par::timer(crate::par::S_DEBLOCK); apply_deblock( &mut y, @@ -26516,11 +30387,18 @@ fn replay_inner( wrote.clear(); wrote.resize(unit_cols * unit_rows, 0); r.work_cdef = Some(*cdef); - let pre = r.deblocked.as_ref().map(|(_, dy, du, dv)| { - (dy.data.as_ref(), du.data.as_ref(), dv.data.as_ref()) - }); + let pre = r + .deblocked + .as_ref() + .map(|(_, dy, du, dv)| (dy.data.as_ref(), du.data.as_ref(), dv.data.as_ref())); apply_cdef( - &mut y, &mut u, &mut v, cdef, &r.neighbours, (r.frame_width, r.frame_height), fctx, + &mut y, + &mut u, + &mut v, + cdef, + &r.neighbours, + (r.frame_width, r.frame_height), + fctx, pre, Some(&mut wrote), ); @@ -26535,7 +30413,9 @@ fn replay_inner( // are the post-deblock picture themselves. Some(plane_snapshot(&y, 0)) } else { - r.deblocked.as_ref().map(|(_, dy, ..)| plane_snapshot(dy, 0)) + r.deblocked + .as_ref() + .map(|(_, dy, ..)| plane_snapshot(dy, 0)) }; let scratch = &mut r.scratch; r.final_luma = snapshot.map(|d| (pooled(&y, scratch), d)); @@ -26654,14 +30534,25 @@ pub(crate) fn replay_restoration( let r = slot.as_mut()?; let (cdefed, deblocked) = r.final_luma.as_ref()?; let (fw, fh) = (r.frame_width, r.frame_height); - let mut grid = crate::restoration::RestorationGrid::with_ss(lr, fw as u32, fh as u32, fctx.subsampling_x.get(), fctx.subsampling_y.get()); + let mut grid = crate::restoration::RestorationGrid::with_ss( + lr, + fw as u32, + fh as u32, + fctx.subsampling_x.get(), + fctx.subsampling_y.get(), + ); let (horz, vert) = (grid.horz_units[0], grid.vert_units[0]); if horz == 0 || units.len() != horz * vert { return None; } for (i, filter) in units.iter().enumerate() { if let Some(info) = filter { - grid.set(0, i / horz, i % horz, crate::restoration::UnitFilter::Wiener(*info)); + grid.set( + 0, + i / horz, + i % horz, + crate::restoration::UnitFilter::Wiener(*info), + ); } } let stride = cdefed.width; @@ -26771,144 +30662,157 @@ fn cdef_band( let (sb_r, sb_c) = (mi_r / SB_MI as usize, mi_c / SB_MI as usize); idx_grid.get(sb_r * sb_cols + sb_c).copied().unwrap_or(0) as usize }; - // One scratch window per plane kind, reused by every unit (8x8 luma and - // 4x4 chroma, each grown by the [`CDEF_BORDER`] tap ring). - // 256 entries, not the (bw + 4) x (bh + 4) samples themselves: the - // AVX2 kernel taps the window in place with two-row loads that reach - // past the last sample, and the tail stays zero for every unit. - let mut win_y = [0i16; 256]; - let mut win_uv = [0i16; 256]; - let mut mi_r = r_lo; - while mi_r < r_hi { - let mut mi_c = 0usize; - while mi_c < skip_grid.mi_cols { - if skip_grid.is_skip_txfm(mi_r, mi_c) { - hit!(CDEF_SKIPPED_UNITS); - } - if !skip_grid.is_skip_txfm(mi_r, mi_c) { - let sidx = strength_idx(mi_r, mi_c); - let (ox, oy) = (mi_c * 4, mi_r * 4); - // Nothing to do for this unit at all: the direction search is - // only ever consumed through a strength, so a unit whose four - // strengths are zero never needs its 8x8 window gathered. - if cdef.y_pri_strength[sidx] == 0 - && cdef.y_sec_strength[sidx] == 0 - && cdef.uv_pri_strength[sidx] == 0 - && cdef.uv_sec_strength[sidx] == 0 - { - mi_c += 2; - continue; + // One scratch window per plane kind, reused by every unit (8x8 luma and + // 4x4 chroma, each grown by the [`CDEF_BORDER`] tap ring). + // 256 entries, not the (bw + 4) x (bh + 4) samples themselves: the + // AVX2 kernel taps the window in place with two-row loads that reach + // past the last sample, and the tail stays zero for every unit. + let mut win_y = [0i16; 256]; + let mut win_uv = [0i16; 256]; + let mut mi_r = r_lo; + while mi_r < r_hi { + let mut mi_c = 0usize; + while mi_c < skip_grid.mi_cols { + if skip_grid.is_skip_txfm(mi_r, mi_c) { + hit!(CDEF_SKIPPED_UNITS); + } + if !skip_grid.is_skip_txfm(mi_r, mi_c) { + let sidx = strength_idx(mi_r, mi_c); + let (ox, oy) = (mi_c * 4, mi_r * 4); + // Nothing to do for this unit at all: the direction search is + // only ever consumed through a strength, so a unit whose four + // strengths are zero never needs its 8x8 window gathered. + if cdef.y_pri_strength[sidx] == 0 + && cdef.y_sec_strength[sidx] == 0 + && cdef.uv_pri_strength[sidx] == 0 + && cdef.uv_sec_strength[sidx] == 0 + { + mi_c += 2; + continue; + } + let (y_stride, y_true_w, y_true_h) = (y.width, y.true_width, y.true_height); + cdef_gather( + src_y, y_stride, y_true_w, y_true_h, ox, oy, 8, 8, &mut win_y, + ); + // lane-cdef r1: the direction search reads the SAME padded + // block the taps do -- libaom runs `cdef_find_dir` on the + // prepared filter block (`cdef_block.c:296-320` over + // `cdef_prepare_fb`'s buffer, `cdef.c:249-256`), whose columns + // and rows past the mi-rounded frame extent are CDEF_VERY_LARGE. + // Clamping to the last real sample instead made every straddling + // edge 8x8 (odd `mi_cols`/`mi_rows`) pick a different var, hence + // a different `adjust_strength`, hence a +-1 band at the crop edge. + let (dir, var) = cdef_find_dir(&win_y, 8 + 2 * CDEF_BORDER, coeff_shift); + + // libaom `av1_cdef_filter_fb` passes `pri_strength ? dir : 0` + // -- each plane zeroes the shared direction when *its own* + // frame-level primary strength is 0, independent of the + // per-block adjusted `t` and of the other plane's strength. + let y_pri_strength = i32::from(cdef.y_pri_strength[sidx]) << coeff_shift; + let y_sec_strength = i32::from(cdef.y_sec_strength[sidx]) << coeff_shift; + let y_dir = if y_pri_strength != 0 { dir } else { 0 }; + let t = cdef_adjust_strength(y_pri_strength, var); + // lane-cdef r1 rung: one line per filtered 8x8 luma CDEF unit. + if crate::envflags::env_flag!("EC_AV1_CDEF_DBG") { + eprintln!( + "EC_CDEF mi_r={mi_r} mi_c={mi_c} x={ox} y={oy} sidx={sidx} dir={dir} var={var} t={t} pri={y_pri_strength} sec={y_sec_strength} damp={damping}" + ); + } + let enable_primary = t != 0; + let enable_secondary = y_sec_strength != 0; + if (ox + 8 > frame_w || oy + 8 > frame_h) + && (enable_primary + || enable_secondary + || cdef.uv_pri_strength[sidx] != 0 + || cdef.uv_sec_strength[sidx] != 0) + { + hit!(CDEF_STRADDLE_UNITS); + } + if enable_primary || enable_secondary { + cdef_filter_block( + &win_y, + y, + ox, + oy, + 8, + 8, + t, + y_sec_strength, + y_dir, + damping, + damping, + enable_primary, + enable_secondary, + coeff_shift, + fctx, + ); + } + + let t_uv = i32::from(cdef.uv_pri_strength[sidx]) << coeff_shift; + let uv_sec_strength = i32::from(cdef.uv_sec_strength[sidx]) << coeff_shift; + // lane-av1422filter: the chroma direction is the luma one + // remapped through `conv422`/`conv440` under asymmetric + // subsampling (see [`CDEF_DIR_CONV422`]); identical to the + // raw luma direction for 4:2:0 and 4:4:4. + let uv_dir = if t_uv != 0 { + match (ss_x(fctx), ss_y(fctx)) { + (1, 0) => CDEF_DIR_CONV422[dir], + (0, 1) => CDEF_DIR_CONV440[dir], + _ => dir, } - let (y_stride, y_true_w, y_true_h) = (y.width, y.true_width, y.true_height); - cdef_gather(src_y, y_stride, y_true_w, y_true_h, ox, oy, 8, 8, &mut win_y); - // lane-cdef r1: the direction search reads the SAME padded - // block the taps do -- libaom runs `cdef_find_dir` on the - // prepared filter block (`cdef_block.c:296-320` over - // `cdef_prepare_fb`'s buffer, `cdef.c:249-256`), whose columns - // and rows past the mi-rounded frame extent are CDEF_VERY_LARGE. - // Clamping to the last real sample instead made every straddling - // edge 8x8 (odd `mi_cols`/`mi_rows`) pick a different var, hence - // a different `adjust_strength`, hence a +-1 band at the crop edge. - let (dir, var) = cdef_find_dir(&win_y, 8 + 2 * CDEF_BORDER, coeff_shift); - - // libaom `av1_cdef_filter_fb` passes `pri_strength ? dir : 0` - // -- each plane zeroes the shared direction when *its own* - // frame-level primary strength is 0, independent of the - // per-block adjusted `t` and of the other plane's strength. - let y_pri_strength = i32::from(cdef.y_pri_strength[sidx]) << coeff_shift; - let y_sec_strength = i32::from(cdef.y_sec_strength[sidx]) << coeff_shift; - let y_dir = if y_pri_strength != 0 { dir } else { 0 }; - let t = cdef_adjust_strength(y_pri_strength, var); - // lane-cdef r1 rung: one line per filtered 8x8 luma CDEF unit. - if crate::envflags::env_flag!("EC_AV1_CDEF_DBG") { - eprintln!( - "EC_CDEF mi_r={mi_r} mi_c={mi_c} x={ox} y={oy} sidx={sidx} dir={dir} var={var} t={t} pri={y_pri_strength} sec={y_sec_strength} damp={damping}" + } else { + 0 + }; + let enable_primary_uv = t_uv != 0; + let enable_secondary_uv = uv_sec_strength != 0; + if let Some(w) = wrote.as_deref_mut() { + let mark = u8::from(enable_primary || enable_secondary) + | (u8::from(enable_primary_uv || enable_secondary_uv) << 1); + w[(mi_r / 2) * unit_cols + mi_c / 2] = mark; + } + if enable_primary_uv || enable_secondary_uv { + let (cox, coy) = (ox >> ss_x(fctx), oy >> ss_y(fctx)); + let (csize_x, csize_y) = (8 >> ss_x(fctx), 8 >> ss_y(fctx)); + for (plane, src_p) in [(&mut *u, src_u), (&mut *v, src_v)] { + let (tw, th) = (plane.true_width, plane.true_height); + let stride = plane.width; + cdef_gather( + src_p, + stride, + tw, + th, + cox, + coy, + csize_x, + csize_y, + &mut win_uv, ); - } - let enable_primary = t != 0; - let enable_secondary = y_sec_strength != 0; - if (ox + 8 > frame_w || oy + 8 > frame_h) - && (enable_primary - || enable_secondary - || cdef.uv_pri_strength[sidx] != 0 - || cdef.uv_sec_strength[sidx] != 0) - { - hit!(CDEF_STRADDLE_UNITS); - } - if enable_primary || enable_secondary { cdef_filter_block( - &win_y, - y, - ox, - oy, - 8, - 8, - t, - y_sec_strength, - y_dir, - damping, - damping, - enable_primary, - enable_secondary, - coeff_shift, fctx, + &win_uv, + plane, + cox, + coy, + csize_x, + csize_y, + t_uv, + uv_sec_strength, + uv_dir, + damping_uv, + damping_uv, + enable_primary_uv, + enable_secondary_uv, + coeff_shift, + fctx, ); } - - let t_uv = i32::from(cdef.uv_pri_strength[sidx]) << coeff_shift; - let uv_sec_strength = i32::from(cdef.uv_sec_strength[sidx]) << coeff_shift; - // lane-av1422filter: the chroma direction is the luma one - // remapped through `conv422`/`conv440` under asymmetric - // subsampling (see [`CDEF_DIR_CONV422`]); identical to the - // raw luma direction for 4:2:0 and 4:4:4. - let uv_dir = if t_uv != 0 { - match (ss_x(fctx), ss_y(fctx)) { - (1, 0) => CDEF_DIR_CONV422[dir], - (0, 1) => CDEF_DIR_CONV440[dir], - _ => dir, - } - } else { - 0 - }; - let enable_primary_uv = t_uv != 0; - let enable_secondary_uv = uv_sec_strength != 0; - if let Some(w) = wrote.as_deref_mut() { - let mark = u8::from(enable_primary || enable_secondary) - | (u8::from(enable_primary_uv || enable_secondary_uv) << 1); - w[(mi_r / 2) * unit_cols + mi_c / 2] = mark; - } - if enable_primary_uv || enable_secondary_uv { - let (cox, coy) = (ox >> ss_x(fctx), oy >> ss_y(fctx)); - let (csize_x, csize_y) = (8 >> ss_x(fctx), 8 >> ss_y(fctx)); - for (plane, src_p) in [(&mut *u, src_u), (&mut *v, src_v)] { - let (tw, th) = (plane.true_width, plane.true_height); - let stride = plane.width; - cdef_gather(src_p, stride, tw, th, cox, coy, csize_x, csize_y, &mut win_uv); - cdef_filter_block( - &win_uv, - plane, - cox, - coy, - csize_x, - csize_y, - t_uv, - uv_sec_strength, - uv_dir, - damping_uv, - damping_uv, - enable_primary_uv, - enable_secondary_uv, - coeff_shift, fctx, - ); - } - } } - mi_c += 2; } - mi_r += 2; + mi_c += 2; } + mi_r += 2; + } } - // --- lane-pipefilt: the per-superblock-row loop filter pipeline ---------- // // DEPENDENCY SHAPE (derived from this decoder's own whole-frame pass order: @@ -26949,7 +30853,10 @@ pub(crate) struct PipeSync { impl PipeSync { fn new() -> Self { Self { - m: std::sync::Mutex::new(PipeQ { ready: 0, abort: false }), + m: std::sync::Mutex::new(PipeQ { + ready: 0, + abort: false, + }), cv: std::sync::Condvar::new(), } } @@ -27062,7 +30969,19 @@ fn pipe_run( return; } if k < nb { - deblock_span(y, u, v, cfg.lf, n, fw, fh, k * 64, (k + 1) * 64, false, fctx); + deblock_span( + y, + u, + v, + cfg.lf, + n, + fw, + fh, + k * 64, + (k + 1) * 64, + false, + fctx, + ); } if k >= 1 && k - 1 < nb { deblock_span(y, u, v, cfg.lf, n, fw, fh, (k - 1) * 64, k * 64, true, fctx); @@ -27074,16 +30993,45 @@ fn pipe_run( // lane-av1422filter: chroma band rows follow the frame's ss_y // (4:2:2 chroma bands the luma 64-row grid, not 32). let (c_lo, c_hi) = ((j * 64) >> ss_y(fctx), ((j + 1) * 64) >> ss_y(fctx)); - snap_band(su2.data.to_mut(), u, ss_y(fctx) as u32, c_lo, c_hi, cfg.cdef_on); - snap_band(sv2.data.to_mut(), v, ss_y(fctx) as u32, c_lo, c_hi, cfg.cdef_on); + snap_band( + su2.data.to_mut(), + u, + ss_y(fctx) as u32, + c_lo, + c_hi, + cfg.cdef_on, + ); + snap_band( + sv2.data.to_mut(), + v, + ss_y(fctx) as u32, + c_lo, + c_hi, + cfg.cdef_on, + ); } } if cfg.cdef_on && k >= 3 && k - 3 < nb { let j = k - 3; if let Some((sy2, su2, sv2)) = snap.as_ref() { cdef_rows( - y, u, v, &sy2.data, &su2.data, &sv2.data, cfg.cdef, n, idx_grid, cfg.sb_cols, - coeff_shift, damping, damping_uv, (fw, fh), j * 16, (j + 1) * 16, fctx, + y, + u, + v, + &sy2.data, + &su2.data, + &sv2.data, + cfg.cdef, + n, + idx_grid, + cfg.sb_cols, + coeff_shift, + damping, + damping_uv, + (fw, fh), + j * 16, + (j + 1) * 16, + fctx, None, ); } @@ -27159,13 +31107,24 @@ fn pipe_run_lr( if rows.is_empty() { continue; } - planes.push(LrPlane { p, out: scratch_sized(len), rows, next: 0, pw, ph, ss, stride }); + planes.push(LrPlane { + p, + out: scratch_sized(len), + rows, + next: 0, + pw, + ph, + ss, + stride, + }); } for band in 0..cfg.nbands { if !sync.wait_for(band + 1) { return; } - let Some((sy2, su2, sv2)) = snap.as_ref() else { return }; + let Some((sy2, su2, sv2)) = snap.as_ref() else { + return; + }; for lp in &mut planes { let stripe = 64usize >> lp.ss; let r_lo = lp.next; @@ -27347,7 +31306,10 @@ pub(crate) fn lr_pipeline_row0_flushes() -> u64 { /// threading is on -- at (1, 1) the filters would run on a worker thread for /// nothing and the crate's `thread_local!` gate counters would miss them. fn pipe_filters_ok(fctx: &crate::decode::FrameCtx, tile_cols: u32, lf_present: bool) -> bool { - if crate::envflags::var("EC_AV1_PIPE_FILTERS").map(|v| v.trim() == "0").unwrap_or(false) { + if crate::envflags::var("EC_AV1_PIPE_FILTERS") + .map(|v| v.trim() == "0") + .unwrap_or(false) + { return false; } if crate::par::filter_threads() == 1 && crate::par::recon_threads() == 1 { @@ -27446,7 +31408,8 @@ fn cdef_rows( damping_uv: i32, (frame_w, frame_h): (usize, usize), r_lo0: usize, - r_hi0: usize, fctx: &crate::decode::FrameCtx, + r_hi0: usize, + fctx: &crate::decode::FrameCtx, // See [`cdef_band`]. Shared because the bands below write disjoint unit // ROWS of it, exactly as they write disjoint plane rows. wrote: Option>, @@ -27461,10 +31424,11 @@ fn cdef_rows( crate::par::Shared::new(u), crate::par::Shared::new(v), ); - let cbands: Vec<(usize, usize)> = crate::par::bands((hi - lo).div_ceil(2), crate::par::filter_threads()) - .into_iter() - .map(|(a, b)| (lo + a * 2, (lo + b * 2).min(hi))) - .collect(); + let cbands: Vec<(usize, usize)> = + crate::par::bands((hi - lo).div_ceil(2), crate::par::filter_threads()) + .into_iter() + .map(|(a, b)| (lo + a * 2, (lo + b * 2).min(hi))) + .collect(); crate::par::run_bands(&cbands, fctx, |r_lo, r_hi, fctx| { // SAFETY: this band writes only the plane rows its own mi rows cover, // disjoint from every other band's (see `Shared`). @@ -27505,7 +31469,8 @@ fn apply_cdef( skip_grid: &Neighbours, // This frame header's own CROPPED luma size, for the straddling-unit // counter only -- CDEF itself walks the mi-rounded plane. - (frame_w, frame_h): (usize, usize), fctx: &crate::decode::FrameCtx, + (frame_w, frame_h): (usize, usize), + fctx: &crate::decode::FrameCtx, // lane-av1cap: every CDEF unit reads the PRE-CDEF planes, so the filter // starts by copying all three (~19 MB at 4K). The encoder's filter // replay already holds an untouched copy of exactly those planes -- its @@ -27538,7 +31503,11 @@ fn apply_cdef( let idx_grid = fctx.cdef_idx_grid.with(|g| g.borrow().clone()); let owned = src.is_none(); let (src_y, src_u, src_v) = match src { - Some((a, b, c)) => (std::borrow::Cow::Borrowed(a), std::borrow::Cow::Borrowed(b), std::borrow::Cow::Borrowed(c)), + Some((a, b, c)) => ( + std::borrow::Cow::Borrowed(a), + std::borrow::Cow::Borrowed(b), + std::borrow::Cow::Borrowed(c), + ), None => ( std::borrow::Cow::Owned(scratch_from(&y.data)), std::borrow::Cow::Owned(scratch_from(&u.data)), @@ -27556,8 +31525,23 @@ fn apply_cdef( // mi = 8 luma rows, 4 chroma rows), which makes each band's writes a // disjoint row range of all three planes. cdef_rows( - y, u, v, &src_y, &src_u, &src_v, cdef, skip_grid, &idx_grid, sb_cols, coeff_shift, - damping, damping_uv, (frame_w, frame_h), 0, skip_grid.mi_rows, fctx, + y, + u, + v, + &src_y, + &src_u, + &src_v, + cdef, + skip_grid, + &idx_grid, + sb_cols, + coeff_shift, + damping, + damping_uv, + (frame_w, frame_h), + 0, + skip_grid.mi_rows, + fctx, wrote.as_deref_mut().map(crate::par::Shared::new), ); if owned { @@ -27631,7 +31615,8 @@ fn apply_loop_restoration( // read this decoder's own decoded samples at columns 68..71 where // libaom reads column 67 replicated -- +-1 over the straddling band // (class av1-truesize-lane: true frame size vs mi-rounded). - (frame_w, frame_h): (usize, usize), fctx: &crate::decode::FrameCtx, + (frame_w, frame_h): (usize, usize), + fctx: &crate::decode::FrameCtx, ) { // lane-svt1 debug rung, env-gated: see `apply_cdef`/`apply_deblock`'s siblings. if crate::envflags::env_flag!("EC_AV1_DEBUG_SKIP_LR") { @@ -27649,7 +31634,9 @@ fn apply_loop_restoration( lr.loop_restoration_size[0], grid, 0, - &mut out, None, fctx, + &mut out, + None, + fctx, ); scratch_return(std::mem::replace(&mut y.data, std::borrow::Cow::Owned(out)).into_owned()); let mut out = scratch_empty(); @@ -27664,7 +31651,9 @@ fn apply_loop_restoration( lr.loop_restoration_size[1], grid, 1, - &mut out, None, fctx, + &mut out, + None, + fctx, ); scratch_return(std::mem::replace(&mut u.data, std::borrow::Cow::Owned(out)).into_owned()); let mut out = scratch_empty(); @@ -27679,7 +31668,9 @@ fn apply_loop_restoration( lr.loop_restoration_size[2], grid, 2, - &mut out, None, fctx, + &mut out, + None, + fctx, ); scratch_return(std::mem::replace(&mut v.data, std::borrow::Cow::Owned(out)).into_owned()); } @@ -27716,12 +31707,25 @@ pub(crate) fn decode_key_frame_tile( tx_select: bool, reduced_tx_set: bool, allow_screen_content_tools: bool, - allow_intrabc: bool, fctx: &crate::decode::FrameCtx, + allow_intrabc: bool, + fctx: &crate::decode::FrameCtx, ) -> Result { decode_key_frame_tile_lr( - data, mi_cols, mi_rows, base_q_idx, frame_width, frame_height, enable_filter_intra, - cdef, loop_filter, tx_select, reduced_tx_set, allow_screen_content_tools, allow_intrabc, - &LoopRestorationParams::default(), fctx, + data, + mi_cols, + mi_rows, + base_q_idx, + frame_width, + frame_height, + enable_filter_intra, + cdef, + loop_filter, + tx_select, + reduced_tx_set, + allow_screen_content_tools, + allow_intrabc, + &LoopRestorationParams::default(), + fctx, ) } @@ -27814,18 +31818,19 @@ pub(crate) fn decode_key_frame_tiles_lr( reduced_tx_set, allow_screen_content_tools, allow_intrabc, - delta, fctx, + delta, + fctx, ) .map(|(picture, _)| picture) } - /// lane-superres r3: the real decoded margin beyond `frame_width` up to - /// the mi-aligned `true_width`, set by the most recent - /// [`decode_key_frame_tile_with_cdfs`] OR (lane-superres r10) - /// [`decode_inter_frame_tile_with_cdfs`] call -- both frame kinds crop - /// their reconstructed buffer down from the same mi-aligned extent, so - /// they share this one slot. See each function's own comment at its - /// write site. `None` when there was no margin to save. +/// lane-superres r3: the real decoded margin beyond `frame_width` up to +/// the mi-aligned `true_width`, set by the most recent +/// [`decode_key_frame_tile_with_cdfs`] OR (lane-superres r10) +/// [`decode_inter_frame_tile_with_cdfs`] call -- both frame kinds crop +/// their reconstructed buffer down from the same mi-aligned extent, so +/// they share this one slot. See each function's own comment at its +/// write site. `None` when there was no margin to save. /// The margin the most recent key- or inter-frame tile decode stashed /// (see [`LAST_FRAME_WIDE_MARGIN`]) -- `stream.rs`'s superres path @@ -28002,7 +32007,8 @@ fn read_sb128_root( sb_r: u32, sb_c: u32, mi_cols: u32, - mi_rows: u32, fctx: &crate::decode::FrameCtx, + mi_rows: u32, + fctx: &crate::decode::FrameCtx, ) -> Result { let (mi_r128, mi_c128) = ((sb_r & !1) * SB_MI, (sb_c & !1) * SB_MI); crate::restoration::read_lr( @@ -28013,7 +32019,8 @@ fn read_sb128_root( lr_reference, mi_r128, mi_c128, - SB_MI * 2, fctx, + SB_MI * 2, + fctx, ); let at128 = ((mi_r128 / SUB_MI) as usize, (mi_c128 / SUB_MI) as usize); let ctx128 = neighbours.partition_ctx(at128, 128); @@ -28119,7 +32126,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // -- only `q_present`/`q_res` are actually read ([`maybe_read_delta_q`]); // `stream.rs` still refuses a frame with `lf_present` set before this // function is ever called. - delta: DeltaParams, fctx: &crate::decode::FrameCtx, + delta: DeltaParams, + fctx: &crate::decode::FrameCtx, ) -> Result<(Picture, Cdfs)> { // lane-frame80: [`TX_SELECT_INTER`] is set by the INTER tile decoder // only, so a key frame decoded after an inter frame on this thread would @@ -28154,7 +32162,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( fctx.intrabc_dv.with(|c| c.set(None)); fctx.cdef_bits.with(|c| c.set(cdef.bits)); fctx.cdef_sb_cols.with(|c| c.set(sb_cols as usize)); - fctx.cdef_idx_grid.with(|g| *g.borrow_mut() = vec![0u8; sb_cols as usize * sb_rows as usize]); + fctx.cdef_idx_grid + .with(|g| *g.borrow_mut() = vec![0u8; sb_cols as usize * sb_rows as usize]); fctx.delta_q_present.with(|c| c.set(delta.q_present)); fctx.delta_q_res.with(|c| c.set(1i32 << delta.q_res)); fctx.delta_lf_present.with(|c| c.set(delta.lf_present)); @@ -28211,7 +32220,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( cols32 as usize * 2, rows32 as usize * 2, mi_cols as usize, - mi_rows as usize, fctx, + mi_rows as usize, + fctx, ); // spec 7.16/libaom `av1_alloc_restoration_struct`: the unit grid is // sized from `av1_get_upsampled_plane_size`, i.e. the UPSCALED width -- @@ -28247,8 +32257,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // last entry) is not, so the upper bound needs `div_ceil` the same // way the whole-frame `sb_rows`/`sb_cols` above does, to keep the // trailing partial superblock row/column in scope. - let (sb_r0, sb_r1) = ((mi_row0 / SB_MI).min(sb_rows), mi_row1.div_ceil(SB_MI).min(sb_rows)); - let (sb_c0, sb_c1) = ((mi_col0 / SB_MI).min(sb_cols), mi_col1.div_ceil(SB_MI).min(sb_cols)); + let (sb_r0, sb_r1) = ( + (mi_row0 / SB_MI).min(sb_rows), + mi_row1.div_ceil(SB_MI).min(sb_rows), + ); + let (sb_c0, sb_c1) = ( + (mi_col0 / SB_MI).min(sb_cols), + mi_col1.div_ceil(SB_MI).min(sb_cols), + ); // lane-t900 r19: spec 5.11.2 `decode_tile` resets `RefLrWiener` / // `RefSgrXqd` to the midpoint filter at the top of EVERY tile, not @@ -28300,160 +32316,239 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( ); hit!(TILE_HITS); - // lane-sb128b r1: set when the 128 root resolved to `PARTITION_NONE` -- - // its one block covers all four 64x64 quadrants, so the remaining three - // visits of this superblock code nothing at all. - let mut sb128_none = false; - // lane-wave1 step (ii): at one reconstruction thread the recorded writes - // are performed at their push sites (nothing reaches the queue below). - let _recon_inline = ReconInline::install(fctx, &mut y, &mut u, &mut v); - // lane-wave1 step (ii): one job per superblock (per 128x128 superblock - // when `sb128`, since a 128 block writes across its four 64x64 visits). - let wave_shift = u32::from(sb128); - let (wave_r0, wave_c0) = ((sb_r0 >> wave_shift) as usize, (sb_c0 >> wave_shift) as usize); - let (wave_rows, wave_cols) = if sb_r1 > sb_r0 && sb_c1 > sb_c0 { - ( - ((sb_r1 - 1) >> wave_shift) as usize - wave_r0 + 1, - ((sb_c1 - 1) >> wave_shift) as usize - wave_c0 + 1, - ) - } else { - (0, 0) - }; - let _wave = WaveGuard::install(fctx, &mut y, &mut u, &mut v, wave_rows, wave_cols); - let waving = fctx.wave.with(|w| w.borrow().is_some()); - let mut wave_job = (0usize, 0usize); - for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) { - // lane-wave1: the previous superblock's recorded writes -- handed to - // the wavefront workers, or replayed here at one recon thread (where - // the queue is empty, every write having run at its push site). - if waving { + // lane-sb128b r1: set when the 128 root resolved to `PARTITION_NONE` -- + // its one block covers all four 64x64 quadrants, so the remaining three + // visits of this superblock code nothing at all. + let mut sb128_none = false; + // lane-wave1 step (ii): at one reconstruction thread the recorded writes + // are performed at their push sites (nothing reaches the queue below). + let _recon_inline = ReconInline::install(fctx, &mut y, &mut u, &mut v); + // lane-wave1 step (ii): one job per superblock (per 128x128 superblock + // when `sb128`, since a 128 block writes across its four 64x64 visits). + let wave_shift = u32::from(sb128); + let (wave_r0, wave_c0) = ( + (sb_r0 >> wave_shift) as usize, + (sb_c0 >> wave_shift) as usize, + ); + let (wave_rows, wave_cols) = if sb_r1 > sb_r0 && sb_c1 > sb_c0 { + ( + ((sb_r1 - 1) >> wave_shift) as usize - wave_r0 + 1, + ((sb_c1 - 1) >> wave_shift) as usize - wave_c0 + 1, + ) + } else { + (0, 0) + }; + let _wave = WaveGuard::install(fctx, &mut y, &mut u, &mut v, wave_rows, wave_cols); + let waving = fctx.wave.with(|w| w.borrow().is_some()); + let mut wave_job = (0usize, 0usize); + for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) { + // lane-wave1: the previous superblock's recorded writes -- handed to + // the wavefront workers, or replayed here at one recon thread (where + // the queue is empty, every write having run at its push site). + if waving { + if sb_start { + wave_submit(fctx, wave_job.0, wave_job.1); + wave_job = ( + (sb_r >> wave_shift) as usize - wave_r0, + (sb_c >> wave_shift) as usize - wave_c0, + ); + } + } else { + flush_recon(fctx, &mut y, &mut u, &mut v); + } + if row_start { + neighbours.start_row(); + } if sb_start { - wave_submit(fctx, wave_job.0, wave_job.1); - wave_job = ( - (sb_r >> wave_shift) as usize - wave_r0, - (sb_c >> wave_shift) as usize - wave_c0, - ); + sb128_none = false; } - } else { - flush_recon(fctx, &mut y, &mut u, &mut v); - } - if row_start { - neighbours.start_row(); - } - if sb_start { - sb128_none = false; - } - if sb128_none { - continue; - } - { - // lane-sb128 r1: the 128 root. Its loop-restoration units are read - // once for the whole 128x128 (spec 5.11.57 is called with the - // superblock's own size), then one partition symbol off the - // `BLOCK_128X128` CDF (8 symbols) decides the root -- only SPLIT - // recurses into the four 64x64 quadrants this decoder codes. - if sb128 && sb_start { - let part128 = read_sb128_root( - &mut dec, - &mut cdfs, - &neighbours, - lr, - &mut lr_grid, - &mut lr_reference, - sb_r, - sb_c, - mi_cols, - mi_rows, fctx, - )?; - if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part128) { - // lane-sb128c r9: the four AB shapes at the 128 root. - // libaom `decode_partition` (decodeframe.c) codes each as - // two `bsize2` (64x64) squares plus one `subsize` - // (128x64 / 64x128) half, visited HORZ_A = TL, TR, bottom - // half; HORZ_B = top half, BL, BR; VERT_A = TL, BL, right - // half; VERT_B = left half, TR, BR. AB values only come - // from the FULL alphabet symbol, which is only read when - // both halves of the root are inside the frame, so no - // piece needs libaom's `i > 0` frame-edge break (a piece - // may still overhang the bottom/right, which - // `PlaneBuf::reconstruct`'s r8 clip handles). - sb128_none = true; - let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); - let (br, bc) = (at128.0 + 4, at128.1 + 4); - let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); - // Only the VERTICAL arms reorder the squares (TL, BL, TR, - // BR), so only they switch libaom's `has_tr_vert_*` / - // `has_bl_vert_*` tables (lane-sb128c r6 visit order). - let _vert_ab = - (part128 == PARTITION_VERT_A || part128 == PARTITION_VERT_B) + if sb128_none { + continue; + } + { + // lane-sb128 r1: the 128 root. Its loop-restoration units are read + // once for the whole 128x128 (spec 5.11.57 is called with the + // superblock's own size), then one partition symbol off the + // `BLOCK_128X128` CDF (8 symbols) decides the root -- only SPLIT + // recurses into the four 64x64 quadrants this decoder codes. + if sb128 && sb_start { + let part128 = read_sb128_root( + &mut dec, + &mut cdfs, + &neighbours, + lr, + &mut lr_grid, + &mut lr_reference, + sb_r, + sb_c, + mi_cols, + mi_rows, + fctx, + )?; + if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part128) { + // lane-sb128c r9: the four AB shapes at the 128 root. + // libaom `decode_partition` (decodeframe.c) codes each as + // two `bsize2` (64x64) squares plus one `subsize` + // (128x64 / 64x128) half, visited HORZ_A = TL, TR, bottom + // half; HORZ_B = top half, BL, BR; VERT_A = TL, BL, right + // half; VERT_B = left half, TR, BR. AB values only come + // from the FULL alphabet symbol, which is only read when + // both halves of the root are inside the frame, so no + // piece needs libaom's `i > 0` frame-edge break (a piece + // may still overhang the bottom/right, which + // `PlaneBuf::reconstruct`'s r8 clip handles). + sb128_none = true; + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); + let (br, bc) = (at128.0 + 4, at128.1 + 4); + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); + // Only the VERTICAL arms reorder the squares (TL, BL, TR, + // BR), so only they switch libaom's `has_tr_vert_*` / + // `has_bl_vert_*` tables (lane-sb128c r6 visit order). + let _vert_ab = (part128 == PARTITION_VERT_A || part128 == PARTITION_VERT_B) .then(crate::encode::Reach::vert_ab_partition); - // One `cdef_idx` literal per CODED BLOCK, at the first - // non-skip one of each 64x64 CDEF unit; the 128x64 / - // 64x128 half covers two units and its read lands in the - // unit holding its origin, so that value is copied to the - // other one (libaom: every mi of the block points at the - // same `MB_MODE_INFO`). - let cdef_copy = |src: (usize, usize), dst: (usize, usize)| { - fctx.cdef_idx_grid.with(|g| { - let mut g = g.borrow_mut(); - let cols = fctx.cdef_sb_cols.with(|c| c.get()); - if cols == 0 { - return; + // One `cdef_idx` literal per CODED BLOCK, at the first + // non-skip one of each 64x64 CDEF unit; the 128x64 / + // 64x128 half covers two units and its read lands in the + // unit holding its origin, so that value is copied to the + // other one (libaom: every mi of the block points at the + // same `MB_MODE_INFO`). + let cdef_copy = |src: (usize, usize), dst: (usize, usize)| { + fctx.cdef_idx_grid.with(|g| { + let mut g = g.borrow_mut(); + let cols = fctx.cdef_sb_cols.with(|c| c.get()); + if cols == 0 { + return; + } + let (si, di) = ( + (q_r + src.0) * cols + q_c + src.1, + (q_r + dst.0) * cols + q_c + dst.1, + ); + if q_c + src.1 < cols + && q_c + dst.1 < cols + && si < g.len() + && di < g.len() + { + g[di] = g[si]; + } + }); + }; + macro_rules! square64 { + ($at:expr) => {{ + fctx.cdef_transmitted.with(|c| c.set(false)); + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + $at, + SB, + TxbSet::Luma64, + TxbSet::Chroma32, + TX32, + TX32, + (&scan32, &scan32), + false, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + fctx, + )? + }}; + } + macro_rules! half128 { + ($at:expr, $bw:expr, $bh:expr, $src:expr, $dst:expr) => {{ + fctx.cdef_transmitted.with(|c| c.set(false)); + decode_block_128rect( + &mut dec, + &mut cdfs, + &mut neighbours, + $at, + $bw, + $bh, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + tx_select, + reduced_tx_set, + fctx, + )?; + cdef_copy($src, $dst); + }}; + } + match part128 { + PARTITION_HORZ_A => { + square64!(at128); + square64!((at128.0, bc)); + half128!((br, at128.1), 128, 64, (1, 0), (1, 1)); } - let (si, di) = ( - (q_r + src.0) * cols + q_c + src.1, - (q_r + dst.0) * cols + q_c + dst.1, - ); - if q_c + src.1 < cols - && q_c + dst.1 < cols - && si < g.len() - && di < g.len() - { - g[di] = g[si]; + PARTITION_HORZ_B => { + half128!(at128, 128, 64, (0, 0), (0, 1)); + square64!((br, at128.1)); + square64!((br, bc)); } - }); - }; - macro_rules! square64 { - ($at:expr) => {{ - fctx.cdef_transmitted.with(|c| c.set(false)); - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - $at, - SB, - TxbSet::Luma64, - TxbSet::Chroma32, - TX32, - TX32, - (&scan32, &scan32), - false, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, fctx, - )? - }}; + PARTITION_VERT_A => { + square64!(at128); + square64!((br, at128.1)); + half128!((at128.0, bc), 64, 128, (0, 1), (1, 1)); + } + _ => { + half128!(at128, 64, 128, (0, 0), (1, 0)); + square64!((at128.0, bc)); + square64!((br, bc)); + } + } + continue; } - macro_rules! half128 { - ($at:expr, $bw:expr, $bh:expr, $src:expr, $dst:expr) => {{ + if matches!(part128, PARTITION_HORZ | PARTITION_VERT) { + // lane-sb128c r8: libaom `decode_partition` + // (decodeframe.c:1554) codes PARTITION_HORZ at the 128 + // root as `subsize = BLOCK_128X64` at (mi_row, mi_col) + // plus a second one at (mi_row + hbs, mi_col) only + // `if (mi_row + hbs < mi_rows)`; PARTITION_VERT mirrors it + // on the column. `hbs` is `mi_size_high[BLOCK_128X128]/2` + // = 16 mi. Both halves together cover the whole root, so + // the remaining three 64x64 quadrant visits code nothing + // (same flag the NONE arm sets). + sb128_none = true; + let horz = part128 == PARTITION_HORZ; + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); + let (bw, bh) = if horz { (128usize, 64usize) } else { (64, 128) }; + for i in 0..2 { + let at = if horz { + (at128.0 + i * 4, at128.1) + } else { + (at128.0, at128.1 + i * 4) + }; + let (blk_mi_r, blk_mi_c) = (at.0 * (SUB / MI), at.1 * (SUB / MI)); + if i > 0 + && (blk_mi_r >= mi_rows as usize || blk_mi_c >= mi_cols as usize) + { + break; + } + // Each half reads its OWN `cdef_idx` literal + // (libaom `read_cdef` keys the `-1` test on the + // block's own `MB_MODE_INFO`, and the two halves have + // different ones). fctx.cdef_transmitted.with(|c| c.set(false)); decode_block_128rect( &mut dec, &mut cdfs, &mut neighbours, - $at, - $bw, - $bh, + at, + bw, + bh, &mut y, &mut u, &mut v, @@ -28461,689 +32556,953 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( enable_filter_intra, allow_screen_content_tools, tx_select, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )?; - cdef_copy($src, $dst); - }}; - } - match part128 { - PARTITION_HORZ_A => { - square64!(at128); - square64!((at128.0, bc)); - half128!((br, at128.1), 128, 64, (1, 0), (1, 1)); - } - PARTITION_HORZ_B => { - half128!(at128, 128, 64, (0, 0), (0, 1)); - square64!((br, at128.1)); - square64!((br, bc)); - } - PARTITION_VERT_A => { - square64!(at128); - square64!((br, at128.1)); - half128!((at128.0, bc), 64, 128, (0, 1), (1, 1)); - } - _ => { - half128!(at128, 64, 128, (0, 0), (1, 0)); - square64!((at128.0, bc)); - square64!((br, bc)); } + // One `cdef_idx` per BLOCK, copied to every 64x64 CDEF + // unit it covers (the inter path's own fan-out). + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); + fctx.cdef_idx_grid.with(|g| { + let mut g = g.borrow_mut(); + let cols = fctx.cdef_sb_cols.with(|c| c.get()); + if cols == 0 { + return; + } + for (src, dst) in if horz { + [((0, 0), (0, 1)), ((1, 0), (1, 1))] + } else { + [((0, 0), (1, 0)), ((0, 1), (1, 1))] + } { + let (si, di) = ( + (q_r + src.0) * cols + q_c + src.1, + (q_r + dst.0) * cols + q_c + dst.1, + ); + if q_c + src.1 < cols + && q_c + dst.1 < cols + && si < g.len() + && di < g.len() + { + g[di] = g[si]; + } + } + }); + continue; } - continue; - } - if matches!(part128, PARTITION_HORZ | PARTITION_VERT) { - // lane-sb128c r8: libaom `decode_partition` - // (decodeframe.c:1554) codes PARTITION_HORZ at the 128 - // root as `subsize = BLOCK_128X64` at (mi_row, mi_col) - // plus a second one at (mi_row + hbs, mi_col) only - // `if (mi_row + hbs < mi_rows)`; PARTITION_VERT mirrors it - // on the column. `hbs` is `mi_size_high[BLOCK_128X128]/2` - // = 16 mi. Both halves together cover the whole root, so - // the remaining three 64x64 quadrant visits code nothing - // (same flag the NONE arm sets). - sb128_none = true; - let horz = part128 == PARTITION_HORZ; - let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); - let (bw, bh) = if horz { (128usize, 64usize) } else { (64, 128) }; - for i in 0..2 { - let at = if horz { - (at128.0 + i * 4, at128.1) - } else { - (at128.0, at128.1 + i * 4) - }; - let (blk_mi_r, blk_mi_c) = (at.0 * (SUB / MI), at.1 * (SUB / MI)); - if i > 0 - && (blk_mi_r >= mi_rows as usize || blk_mi_c >= mi_cols as usize) - { - break; - } - // Each half reads its OWN `cdef_idx` literal - // (libaom `read_cdef` keys the `-1` test on the - // block's own `MB_MODE_INFO`, and the two halves have - // different ones). + if part128 == PARTITION_NONE { + // One 128x128 intra block: four TX_64X64 luma units and a + // single 64x64 chroma unit per plane (`av1_get_max_uv_txsize` + // of a 128x128 block is TX_64X64 over its 64x64 uv plane + // block). No CfL, no filter intra, no palette at this size -- + // [`read_intra_mode`]'s own size gates already say so. + sb128_none = true; fctx.cdef_transmitted.with(|c| c.set(false)); - decode_block_128rect( + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); + decode_block( &mut dec, &mut cdfs, &mut neighbours, - at, - bw, - bh, + at128, + SB * 2, + TxbSet::Luma64, + TxbSet::Chroma32, + TX32, + TX32, + (&scan32, &scan32), + false, &mut y, &mut u, &mut v, base_q_idx, enable_filter_intra, allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, tx_select, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )?; - } - // One `cdef_idx` per BLOCK, copied to every 64x64 CDEF - // unit it covers (the inter path's own fan-out). - let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); - fctx.cdef_idx_grid.with(|g| { - let mut g = g.borrow_mut(); - let cols = fctx.cdef_sb_cols.with(|c| c.get()); - if cols == 0 { - return; - } - for (src, dst) in if horz { - [((0, 0), (0, 1)), ((1, 0), (1, 1))] - } else { - [((0, 0), (1, 0)), ((0, 1), (1, 1))] - } { - let (si, di) = ( - (q_r + src.0) * cols + q_c + src.1, - (q_r + dst.0) * cols + q_c + dst.1, - ); - if q_c + src.1 < cols - && q_c + dst.1 < cols - && si < g.len() - && di < g.len() - { - g[di] = g[si]; + // libaom writes one `cdef_strength` into the block's own + // `MB_MODE_INFO`, which every mi cell of the block -- + // hence all four 64x64 CDEF units -- points at; our grid + // is per-unit, so the read (which only ever lands in the + // top-left unit, `read_cdef`'s index 0) is copied across. + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); + fctx.cdef_idx_grid.with(|g| { + let mut g = g.borrow_mut(); + let cols = fctx.cdef_sb_cols.with(|c| c.get()); + if cols > 0 && q_r * cols + q_c < g.len() { + let idx = g[q_r * cols + q_c]; + for (dr, dc) in [(0, 1), (1, 0), (1, 1)] { + let i = (q_r + dr) * cols + q_c + dc; + if q_c + dc < cols && i < g.len() { + g[i] = idx; + } + } } - } - }); - continue; + }); + continue; + } } - if part128 == PARTITION_NONE { - // One 128x128 intra block: four TX_64X64 luma units and a - // single 64x64 chroma unit per plane (`av1_get_max_uv_txsize` - // of a 128x128 block is TX_64X64 over its 64x64 uv plane - // block). No CfL, no filter intra, no palette at this size -- - // [`read_intra_mode`]'s own size gates already say so. - sb128_none = true; - fctx.cdef_transmitted.with(|c| c.set(false)); - let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); - decode_block( + if !sb128 { + crate::restoration::read_lr( &mut dec, &mut cdfs, - &mut neighbours, - at128, - SB * 2, - TxbSet::Luma64, - TxbSet::Chroma32, - TX32, - TX32, - (&scan32, &scan32), - false, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, fctx, - )?; - // libaom writes one `cdef_strength` into the block's own - // `MB_MODE_INFO`, which every mi cell of the block -- - // hence all four 64x64 CDEF units -- points at; our grid - // is per-unit, so the read (which only ever lands in the - // top-left unit, `read_cdef`'s index 0) is copied across. - let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); - fctx.cdef_idx_grid.with(|g| { - let mut g = g.borrow_mut(); - let cols = fctx.cdef_sb_cols.with(|c| c.get()); - if cols > 0 && q_r * cols + q_c < g.len() { - let idx = g[q_r * cols + q_c]; - for (dr, dc) in [(0, 1), (1, 0), (1, 1)] { - let i = (q_r + dr) * cols + q_c + dc; - if q_c + dc < cols && i < g.len() { - g[i] = idx; - } - } - } - }); - continue; + lr, + &mut lr_grid, + &mut lr_reference, + sb_r * SB_MI, + sb_c * SB_MI, + SB_MI, + fctx, + ); } - } - if !sb128 { - crate::restoration::read_lr( - &mut dec, - &mut cdfs, - lr, - &mut lr_grid, - &mut lr_reference, - sb_r * SB_MI, - sb_c * SB_MI, - SB_MI, fctx, + fctx.cdef_transmitted.with(|c| c.set(false)); + let at = (sb_r as usize * 4, sb_c as usize * 4); + let ctx = neighbours.partition_ctx(at, SB); + let (has_cols, has_rows) = ( + sb_c * SB_MI + SB_MI / 2 < mi_cols, + sb_r * SB_MI + SB_MI / 2 < mi_rows, ); - } - fctx.cdef_transmitted.with(|c| c.set(false)); - let at = (sb_r as usize * 4, sb_c as usize * 4); - let ctx = neighbours.partition_ctx(at, SB); - let (has_cols, has_rows) = ( - sb_c * SB_MI + SB_MI / 2 < mi_cols, - sb_r * SB_MI + SB_MI / 2 < mi_rows, - ); - // Recomputed at this superblock's own half (spec - // `decode_partition`): a full alphabet symbol when both halves are - // inside the true frame, a single gathered bit when just one is - // (the superblock cannot be left whole, so this is forced split), - // and nothing at all (SPLIT inferred, no bits) when neither is — - // mirroring [`crate::tile::sb_coeff_key_frame_tile`]'s own - // three-way write exactly. - let part = if has_cols && has_rows { - if crate::envflags::env_flag!("EC_TRACE") { - eprintln!("EC_PART mi_row={} mi_col={} bsize=12 ctx={} tell={} rng={}", sb_r * SB_MI, sb_c * SB_MI, ctx, dec.debug_bitpos(), dec.debug_state().0); - } - let p = dec.symbol(&mut cdfs.partition_w64[ctx]); - if crate::envflags::env_flag!("EC_TRACE") { - eprintln!("EC_PART_VAL mi_row={} mi_col={} bsize=12 value={}", sb_r * SB_MI, sb_c * SB_MI, p); - } - if crate::envflags::env_flag!("EC_AV1_TRACE") { - eprintln!("TRACE partition_w64 ctx={ctx} value={p}"); - } - p - } else { - // lane-hgkf r1 (class `parsed-then-discarded`, same finding as - // the unmerged lane-golomb r1): the gathered bit IS the - // partition -- libaom `ec_read_partition_impl` returns - // PARTITION_HORZ (resp. VERT) for 0 and only SPLIT for 1. - // Forcing SPLIT desynced the last superblock row of every - // frame whose height is not a multiple of 64: the ReelB key frames (3840x1608) diverge at mi_row=400 mi_col=0, - // the first block of that row. - match (has_cols, has_rows) { - (true, false) => { - trace_edge((sb_r * SB_MI) as usize, (sb_c * SB_MI) as usize, 12, ctx, dec.debug_state().0 as u32); - let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)); - bump_edge32(4 + b.min(1) as usize); - bump_edge_part(b.min(1) as usize); - if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ } + // Recomputed at this superblock's own half (spec + // `decode_partition`): a full alphabet symbol when both halves are + // inside the true frame, a single gathered bit when just one is + // (the superblock cannot be left whole, so this is forced split), + // and nothing at all (SPLIT inferred, no bits) when neither is — + // mirroring [`crate::tile::sb_coeff_key_frame_tile`]'s own + // three-way write exactly. + let part = if has_cols && has_rows { + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!( + "EC_PART mi_row={} mi_col={} bsize=12 ctx={} tell={} rng={}", + sb_r * SB_MI, + sb_c * SB_MI, + ctx, + dec.debug_bitpos(), + dec.debug_state().0 + ); } - (false, true) => { - trace_edge((sb_r * SB_MI) as usize, (sb_c * SB_MI) as usize, 12, ctx, dec.debug_state().0 as u32); - let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)); - bump_edge32(4 + b.min(1) as usize); - bump_edge_part(b.min(1) as usize); - if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT } + let p = dec.symbol(&mut cdfs.partition_w64[ctx]); + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!( + "EC_PART_VAL mi_row={} mi_col={} bsize=12 value={}", + sb_r * SB_MI, + sb_c * SB_MI, + p + ); } - _ => { - bump_edge_both_cut(2); - PARTITION_SPLIT + if crate::envflags::env_flag!("EC_AV1_TRACE") { + eprintln!("TRACE partition_w64 ctx={ctx} value={p}"); } - } - }; - match part { - PARTITION_NONE => { - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - at, - SB, - TxbSet::Luma64, - TxbSet::Chroma32, - TX32, - TX32, - (&scan32, &scan32), - false, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, fctx, - )?; - } - PARTITION_SPLIT => { - for q in 0..4 { - let (r32, c32) = (sb_r * 2 + q / 2, sb_c * 2 + q % 2); - if r32 >= rows32 || c32 >= cols32 { - continue; - } - let at32 = (r32 as usize * 2, c32 as usize * 2); - let ctx32 = neighbours.partition_ctx(at32, BLOCK); - let (has_cols32, has_rows32) = ( - has_half(c32 * BLOCK_MI, BLOCK_MI, mi_cols), - has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), - ); - let part32 = if has_cols32 && has_rows32 { - if crate::envflags::env_flag!("EC_TRACE") { - eprintln!("EC_PART mi_row={} mi_col={} bsize=9 ctx={} tell={} rng={}", r32 * BLOCK_MI, c32 * BLOCK_MI, ctx32, dec.debug_bitpos(), dec.debug_state().0); + p + } else { + // lane-hgkf r1 (class `parsed-then-discarded`, same finding as + // the unmerged lane-golomb r1): the gathered bit IS the + // partition -- libaom `ec_read_partition_impl` returns + // PARTITION_HORZ (resp. VERT) for 0 and only SPLIT for 1. + // Forcing SPLIT desynced the last superblock row of every + // frame whose height is not a multiple of 64: the ReelB key frames (3840x1608) diverge at mi_row=400 mi_col=0, + // the first block of that row. + match (has_cols, has_rows) { + (true, false) => { + trace_edge( + (sb_r * SB_MI) as usize, + (sb_c * SB_MI) as usize, + 12, + ctx, + dec.debug_state().0 as u32, + ); + let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)); + bump_edge32(4 + b.min(1) as usize); + bump_edge_part(b.min(1) as usize); + if b == 1 { + PARTITION_SPLIT + } else { + PARTITION_HORZ } - let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); - if crate::envflags::env_flag!("EC_TRACE") { - eprintln!("EC_PART_VAL mi_row={} mi_col={} bsize=9 value={}", r32 * BLOCK_MI, c32 * BLOCK_MI, p); + } + (false, true) => { + trace_edge( + (sb_r * SB_MI) as usize, + (sb_c * SB_MI) as usize, + 12, + ctx, + dec.debug_state().0 as u32, + ); + let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)); + bump_edge32(4 + b.min(1) as usize); + bump_edge_part(b.min(1) as usize); + if b == 1 { + PARTITION_SPLIT + } else { + PARTITION_VERT } - if crate::envflags::env_flag!("EC_AV1_TRACE") { - let (rng, _) = dec.debug_state(); - eprintln!( - "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p} rng={rng}", - r32 * BLOCK_MI, - c32 * BLOCK_MI - ); + } + _ => { + bump_edge_both_cut(2); + PARTITION_SPLIT + } + } + }; + match part { + PARTITION_NONE => { + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + at, + SB, + TxbSet::Luma64, + TxbSet::Chroma32, + TX32, + TX32, + (&scan32, &scan32), + false, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + fctx, + )?; + } + PARTITION_SPLIT => { + for q in 0..4 { + let (r32, c32) = (sb_r * 2 + q / 2, sb_c * 2 + q % 2); + if r32 >= rows32 || c32 >= cols32 { + continue; } - p - } else { - // lane-hgkf r1: the 32-level frame-edge bit is the - // partition too (same libaom reader as the - // superblock level above). - match (has_cols32, has_rows32) { - (true, false) => { - trace_edge((r32 * BLOCK_MI) as usize, (c32 * BLOCK_MI) as usize, 9, ctx32, dec.debug_state().0 as u32); - let b = dec.symbol_fixed(&gather( - &cdfs.partition_w32[ctx32], - VERT_ALIKE, - )); - bump_edge32(b.min(1) as usize); - bump_edge_part(2 + b.min(1) as usize); - if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ } - } - (false, true) => { - trace_edge((r32 * BLOCK_MI) as usize, (c32 * BLOCK_MI) as usize, 9, ctx32, dec.debug_state().0 as u32); - let b = dec.symbol_fixed(&gather( - &cdfs.partition_w32[ctx32], - HORZ_ALIKE, - )); - bump_edge32(b.min(1) as usize); - bump_edge_part(2 + b.min(1) as usize); - if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT } + let at32 = (r32 as usize * 2, c32 as usize * 2); + let ctx32 = neighbours.partition_ctx(at32, BLOCK); + let (has_cols32, has_rows32) = ( + has_half(c32 * BLOCK_MI, BLOCK_MI, mi_cols), + has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), + ); + let part32 = if has_cols32 && has_rows32 { + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!( + "EC_PART mi_row={} mi_col={} bsize=9 ctx={} tell={} rng={}", + r32 * BLOCK_MI, + c32 * BLOCK_MI, + ctx32, + dec.debug_bitpos(), + dec.debug_state().0 + ); } - _ => { - bump_edge_both_cut(1); - PARTITION_SPLIT + let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!( + "EC_PART_VAL mi_row={} mi_col={} bsize=9 value={}", + r32 * BLOCK_MI, + c32 * BLOCK_MI, + p + ); } - } - }; - match part32 { - PARTITION_NONE => { - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - at32, - BLOCK, - TxbSet::Luma32, - TxbSet::Chroma16, - TX32, - TX16, - (&scan32, &scan16), - true, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, fctx, - )?; - } - PARTITION_SPLIT => { - for sub in 0..4 { - let (sr, sc) = - (r32 as usize * 2 + sub / 2, c32 as usize * 2 + sub % 2); - if (sr as u32) * SUB_MI >= mi_rows - || (sc as u32) * SUB_MI >= mi_cols - { - continue; - } - let (has_cols16, has_rows16) = ( - has_half(sc as u32 * SUB_MI, SUB_MI, mi_cols), - has_half(sr as u32 * SUB_MI, SUB_MI, mi_rows), + if crate::envflags::env_flag!("EC_AV1_TRACE") { + let (rng, _) = dec.debug_state(); + eprintln!( + "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p} rng={rng}", + r32 * BLOCK_MI, + c32 * BLOCK_MI ); - let at16 = (sr, sc); - let ctx16 = neighbours.partition_ctx(at16, SUB); - if has_cols16 && has_rows16 { - if crate::envflags::env_flag!("EC_TRACE") { - eprintln!("EC_PART mi_row={} mi_col={} bsize=6 ctx={} tell={} rng={}", at16.0, at16.1, ctx16, dec.debug_bitpos(), dec.debug_state().0); - } - let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); - if crate::envflags::env_flag!("EC_TRACE") { - eprintln!("EC_PART_VAL mi_row={} mi_col={} bsize=6 value={}", at16.0, at16.1, part16); + } + p + } else { + // lane-hgkf r1: the 32-level frame-edge bit is the + // partition too (same libaom reader as the + // superblock level above). + match (has_cols32, has_rows32) { + (true, false) => { + trace_edge( + (r32 * BLOCK_MI) as usize, + (c32 * BLOCK_MI) as usize, + 9, + ctx32, + dec.debug_state().0 as u32, + ); + let b = dec.symbol_fixed(&gather( + &cdfs.partition_w32[ctx32], + VERT_ALIKE, + )); + bump_edge32(b.min(1) as usize); + bump_edge_part(2 + b.min(1) as usize); + if b == 1 { + PARTITION_SPLIT + } else { + PARTITION_HORZ } - if crate::envflags::env_flag!("EC_AV1_TRACE") { - eprintln!( - "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={part16}", - at16.0, at16.1 - ); + } + (false, true) => { + trace_edge( + (r32 * BLOCK_MI) as usize, + (c32 * BLOCK_MI) as usize, + 9, + ctx32, + dec.debug_state().0 as u32, + ); + let b = dec.symbol_fixed(&gather( + &cdfs.partition_w32[ctx32], + HORZ_ALIKE, + )); + bump_edge32(b.min(1) as usize); + bump_edge_part(2 + b.min(1) as usize); + if b == 1 { + PARTITION_SPLIT + } else { + PARTITION_VERT } - if part16 == PARTITION_NONE { - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - SUB, - TxbSet::Luma16, - TxbSet::Chroma8, - TX16, - TX8, - (&scan16, &scan8), - true, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, fctx, - )?; + } + _ => { + bump_edge_both_cut(1); + PARTITION_SPLIT + } + } + }; + match part32 { + PARTITION_NONE => { + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + at32, + BLOCK, + TxbSet::Luma32, + TxbSet::Chroma16, + TX32, + TX16, + (&scan32, &scan16), + true, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + fctx, + )?; + } + PARTITION_SPLIT => { + for sub in 0..4 { + let (sr, sc) = ( + r32 as usize * 2 + sub / 2, + c32 as usize * 2 + sub % 2, + ); + if (sr as u32) * SUB_MI >= mi_rows + || (sc as u32) * SUB_MI >= mi_cols + { continue; } - if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part16) { - // lane-ab16 r1: the four AB (T-shaped) partitions at the 16x16 - // level -- two 8x8 squares plus one 16x8/8x16 strip. libaom's - // `decode_partition` visit order (decodeframe.c): - // HORZ_A: TL 8x8, TR 8x8, bottom 16x8 - // HORZ_B: top 16x8, BL 8x8, BR 8x8 - // VERT_A: TL 8x8, BL 8x8, right 8x16 - // VERT_B: left 8x16, TR 8x8, BR 8x8 - // The squares go through `decode_leaf8`, the strip through - // `decode_leaf_rect` (real, non-skip 16x8/8x16 coefficients -- - // lane-rectx r2-r4; the older `decode_block_rect` this VERT_B arm - // used refuses the non-skip case at this size). Both writers keep - // mi-granular mode/skip/palette records, so a later block's - // `above_mi`/`left_mi` sees the real sub-block, not the coarse - // 16x16 cell. - // - // VERT_A/VERT_B visit TL,BL,TR,BR, so the bottom-left square's - // top-right neighbour is the partition's own not-yet-decoded - // rectangle: libaom switches those squares onto `has_tr_vert_*`/ - // `has_bl_vert_*` (`reconintra.c` `get_has_tr_table`), which is - // `Reach::vert_ab_partition()` (lane-part32 r5, cherry-picked here). - let arm = part16 - PARTITION_HORZ_A; - bump_ab16(arm); - if part16 == PARTITION_VERT_B { - hit!(VERT_B_INTRA_HITS); + let (has_cols16, has_rows16) = ( + has_half(sc as u32 * SUB_MI, SUB_MI, mi_cols), + has_half(sr as u32 * SUB_MI, SUB_MI, mi_rows), + ); + let at16 = (sr, sc); + let ctx16 = neighbours.partition_ctx(at16, SUB); + if has_cols16 && has_rows16 { + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!( + "EC_PART mi_row={} mi_col={} bsize=6 ctx={} tell={} rng={}", + at16.0, + at16.1, + ctx16, + dec.debug_bitpos(), + dec.debug_state().0 + ); } - let _vert_guard = if part16 == PARTITION_VERT_A || part16 == PARTITION_VERT_B { - Some(crate::encode::Reach::vert_ab_partition()) - } else { - None - }; - let (mi_row0, mi_col0) = (sr * SUB_MI as usize, sc * SUB_MI as usize); - macro_rules! ab_leaf8 { - ($mi:expr, $prev:expr) => { - decode_leaf8( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - $mi, - (&scan8, &scan4), - $prev, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - tx_select, - reduced_tx_set, fctx, - )? + let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!( + "EC_PART_VAL mi_row={} mi_col={} bsize=6 value={}", + at16.0, at16.1, part16 + ); + } + if crate::envflags::env_flag!("EC_AV1_TRACE") { + eprintln!( + "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={part16}", + at16.0, at16.1 + ); + } + if part16 == PARTITION_NONE { + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + SUB, + TxbSet::Luma16, + TxbSet::Chroma8, + TX16, + TX8, + (&scan16, &scan8), + true, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + fctx, + )?; + continue; + } + if (PARTITION_HORZ_A..=PARTITION_VERT_B) + .contains(&part16) + { + // lane-ab16 r1: the four AB (T-shaped) partitions at the 16x16 + // level -- two 8x8 squares plus one 16x8/8x16 strip. libaom's + // `decode_partition` visit order (decodeframe.c): + // HORZ_A: TL 8x8, TR 8x8, bottom 16x8 + // HORZ_B: top 16x8, BL 8x8, BR 8x8 + // VERT_A: TL 8x8, BL 8x8, right 8x16 + // VERT_B: left 8x16, TR 8x8, BR 8x8 + // The squares go through `decode_leaf8`, the strip through + // `decode_leaf_rect` (real, non-skip 16x8/8x16 coefficients -- + // lane-rectx r2-r4; the older `decode_block_rect` this VERT_B arm + // used refuses the non-skip case at this size). Both writers keep + // mi-granular mode/skip/palette records, so a later block's + // `above_mi`/`left_mi` sees the real sub-block, not the coarse + // 16x16 cell. + // + // VERT_A/VERT_B visit TL,BL,TR,BR, so the bottom-left square's + // top-right neighbour is the partition's own not-yet-decoded + // rectangle: libaom switches those squares onto `has_tr_vert_*`/ + // `has_bl_vert_*` (`reconintra.c` `get_has_tr_table`), which is + // `Reach::vert_ab_partition()` (lane-part32 r5, cherry-picked here). + let arm = part16 - PARTITION_HORZ_A; + bump_ab16(arm); + if part16 == PARTITION_VERT_B { + hit!(VERT_B_INTRA_HITS); + } + let _vert_guard = if part16 == PARTITION_VERT_A + || part16 == PARTITION_VERT_B + { + Some(crate::encode::Reach::vert_ab_partition()) + } else { + None }; + let (mi_row0, mi_col0) = + (sr * SUB_MI as usize, sc * SUB_MI as usize); + macro_rules! ab_leaf8 { + ($mi:expr, $prev:expr) => { + decode_leaf8( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + $mi, + (&scan8, &scan4), + $prev, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + tx_select, + reduced_tx_set, + fctx, + )? + }; + } + macro_rules! ab_strip { + ($mi:expr, $bw:expr, $bh:expr, $prev:expr) => { + decode_leaf_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + $mi, + $bw, + $bh, + $prev, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + )? + }; + } + let tl = (mi_row0, mi_col0); + let tr = (mi_row0, mi_col0 + 2); + let bl = (mi_row0 + 2, mi_col0); + let br = (mi_row0 + 2, mi_col0 + 2); + let mut done: Vec<((usize, usize), usize)> = + Vec::new(); + match part16 { + PARTITION_HORZ_A => { + let m_tl = + ab_leaf8!(tl, done.last().copied()); + done.push((tl, m_tl)); + let m_tr = + ab_leaf8!(tr, done.last().copied()); + done.push((tr, m_tr)); + let m_bot = + ab_strip!(bl, 16, 8, Some((tl, m_tl))); + done.push((bl, m_bot)); + } + PARTITION_HORZ_B => { + let m_top = ab_strip!(tl, 16, 8, None); + done.push((tl, m_top)); + let m_bl = + ab_leaf8!(bl, done.last().copied()); + done.push((bl, m_bl)); + let m_br = + ab_leaf8!(br, done.last().copied()); + done.push((br, m_br)); + } + PARTITION_VERT_A => { + let m_tl = + ab_leaf8!(tl, done.last().copied()); + done.push((tl, m_tl)); + let m_bl = + ab_leaf8!(bl, done.last().copied()); + done.push((bl, m_bl)); + let m_right = + ab_strip!(tr, 8, 16, Some((tl, m_tl))); + done.push((tr, m_right)); + } + _ => { + let m_left = ab_strip!(tl, 8, 16, None); + done.push((tl, m_left)); + let m_tr = + ab_leaf8!(tr, done.last().copied()); + done.push((tr, m_tr)); + let m_br = + ab_leaf8!(br, done.last().copied()); + done.push((br, m_br)); + } + } + // Same coarse-slot write-back the real SPLIT path takes: the + // 16x16 cell's single `above_mode`/`left_mode` entry gets the + // sub-block on the parent's bottom / right edge (the mi-exact map + // above wins wherever it has an entry). + write_back_split_modes( + &mut neighbours, + &done, + (mi_row0, mi_col0), + (sr, sc), + ); + continue; + } + if part16 == PARTITION_HORZ { + hit!(HORZ_VERT_INTRA_HITS); + let (mi_row0, mi_col0) = + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); + let top = (mi_row0 as usize, mi_col0 as usize); + let bot = (mi_row0 as usize + 2, mi_col0 as usize); + let mode_top = decode_leaf_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + top, + 16, + 8, + None, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + )?; + let mode_bot = decode_leaf_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + bot, + 16, + 8, + Some((top, mode_top)), + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + )?; + neighbours.above_mode[sc] = mode_bot; + neighbours.left_mode[sr] = mode_bot; + continue; + } + if part16 == PARTITION_VERT { + hit!(HORZ_VERT_INTRA_HITS); + let (mi_row0, mi_col0) = + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); + let left = (mi_row0 as usize, mi_col0 as usize); + let right = + (mi_row0 as usize, mi_col0 as usize + 2); + let mode_left = decode_leaf_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + left, + 8, + 16, + None, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + )?; + let mode_right = decode_leaf_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + right, + 8, + 16, + Some((left, mode_left)), + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + )?; + neighbours.above_mode[sc] = mode_right; + neighbours.left_mode[sr] = mode_right; + continue; + } + if part16 == PARTITION_HORZ_4 + || part16 == PARTITION_VERT_4 + { + decode_rect4_16( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + part16 == PARTITION_HORZ_4, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + )?; + continue; } - macro_rules! ab_strip { - ($mi:expr, $bw:expr, $bh:expr, $prev:expr) => { - decode_leaf_rect( + // lane-r14 r2 (verifier note): every + // one of the 10 symbols this CDF can + // produce is handled above, so SPLIT + // is the only value that reaches + // here -- the refusal that used to + // stand here was unreachable and is + // gone from `refusal_inventory`. + debug_assert_eq!(part16, PARTITION_SPLIT); + // A real (non-straddle) SPLIT of a + // whole 16x16 into four 8x8 leaves -- + // the same recursion the straddle + // path below already runs when the + // true frame edge forces it, just + // over all four positions instead of + // the one or two the edge leaves. + let (mi_row0, mi_col0) = + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); + // Each 8x8 leaf's intra-mode context + // must see its own siblings: the + // bottom-left leaf's ABOVE neighbour + // is leaf 0, not the previously + // decoded leaf 1 (and the bottom-right + // leaf's above is leaf 1, while + // `prev_leaf` only ever carried the + // immediately preceding one). The + // coarse `above_mode`/`left_mode` + // arrays hold one slot per 16x16, so + // the sibling modes are swapped in + // around each leaf call and restored + // after; the loop tail writes the last + // leaf's mode as before. + let mut sib_modes: [Option<(usize, usize)>; 4] = + [None; 4]; + for i in 0..4 { + let (mr, mc) = + (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2); + let leaf_mi = (mr as usize, mc as usize); + let li = i as usize; + let saved_modes = ( + neighbours.above_mode[sc], + neighbours.left_mode[sr], + ); + if li >= 2 { + if let Some((below, _)) = sib_modes[li - 2] { + neighbours.above_mode[sc] = below; + } + } + if li % 2 == 1 { + if let Some((_, right)) = sib_modes[li - 1] { + neighbours.left_mode[sr] = right; + } + } + let leaf_ctx = + neighbours.partition_ctx_mi(leaf_mi, 8); + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!( + "EC_PART mi_row={} mi_col={} bsize=3 ctx={} tell={} rng={}", + leaf_mi.0, + leaf_mi.1, + leaf_ctx, + dec.debug_bitpos(), + dec.debug_state().0 + ); + } + let part8 = + dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!( + "EC_PART_VAL mi_row={} mi_col={} bsize=3 value={}", + leaf_mi.0, leaf_mi.1, part8 + ); + } + if crate::envflags::env_flag!("EC_AV1_TRACE") { + eprintln!( + "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" + ); + } + let leaf_mode = if part8 == PARTITION_NONE { + decode_leaf8( &mut dec, &mut cdfs, &mut neighbours, at16, - $mi, - $bw, - $bh, - $prev, + leaf_mi, + (&scan8, &scan4), + None, &mut y, &mut u, &mut v, + base_q_idx, enable_filter_intra, allow_screen_content_tools, + allow_intrabc, + tx_select, + reduced_tx_set, + fctx, + ) + .map(|m| (m, m))? + } else if part8 == PARTITION_SPLIT { + decode_leaf_split4( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + leaf_mi, + &scan4, + None, + &mut y, + &mut u, + &mut v, base_q_idx, + enable_filter_intra, + allow_intrabc, + reduced_tx_set, + fctx, + )? + } else if part8 == PARTITION_HORZ + || part8 == PARTITION_VERT + { + decode_leaf_rect8( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + leaf_mi, + part8 == PARTITION_VERT, + &scan4, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_intrabc, tx_select, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )? + } else { + unreachable!( + "partition_w8 is a 4-symbol CDF: NONE/HORZ/VERT/SPLIT only" + ); }; + neighbours.above_mode[sc] = saved_modes.0; + neighbours.left_mode[sr] = saved_modes.1; + sib_modes[li] = Some(leaf_mode); } - let tl = (mi_row0, mi_col0); - let tr = (mi_row0, mi_col0 + 2); - let bl = (mi_row0 + 2, mi_col0); - let br = (mi_row0 + 2, mi_col0 + 2); - let mut done: Vec<((usize, usize), usize)> = Vec::new(); - match part16 { - PARTITION_HORZ_A => { - let m_tl = ab_leaf8!(tl, done.last().copied()); - done.push((tl, m_tl)); - let m_tr = ab_leaf8!(tr, done.last().copied()); - done.push((tr, m_tr)); - let m_bot = ab_strip!(bl, 16, 8, Some((tl, m_tl))); - done.push((bl, m_bot)); - } - PARTITION_HORZ_B => { - let m_top = ab_strip!(tl, 16, 8, None); - done.push((tl, m_top)); - let m_bl = ab_leaf8!(bl, done.last().copied()); - done.push((bl, m_bl)); - let m_br = ab_leaf8!(br, done.last().copied()); - done.push((br, m_br)); - } - PARTITION_VERT_A => { - let m_tl = ab_leaf8!(tl, done.last().copied()); - done.push((tl, m_tl)); - let m_bl = ab_leaf8!(bl, done.last().copied()); - done.push((bl, m_bl)); - let m_right = ab_strip!(tr, 8, 16, Some((tl, m_tl))); - done.push((tr, m_right)); - } - _ => { - let m_left = ab_strip!(tl, 8, 16, None); - done.push((tl, m_left)); - let m_tr = ab_leaf8!(tr, done.last().copied()); - done.push((tr, m_tr)); - let m_br = ab_leaf8!(br, done.last().copied()); - done.push((br, m_br)); - } + if let Some((below, _)) = + sib_modes[2].or(sib_modes[3]).or(sib_modes[0]) + { + neighbours.above_mode[sc] = below; + } + if let Some((_, right)) = + sib_modes[1].or(sib_modes[3]).or(sib_modes[0]) + { + neighbours.left_mode[sr] = right; } - // Same coarse-slot write-back the real SPLIT path takes: the - // 16x16 cell's single `above_mode`/`left_mode` entry gets the - // sub-block on the parent's bottom / right edge (the mi-exact map - // above wins wherever it has an entry). - write_back_split_modes(&mut neighbours, &done, (mi_row0, mi_col0), (sr, sc)); - continue; - } - if part16 == PARTITION_HORZ { - hit!(HORZ_VERT_INTRA_HITS); - let (mi_row0, mi_col0) = ( - sr as u32 * SUB_MI, - sc as u32 * SUB_MI, - ); - let top = (mi_row0 as usize, mi_col0 as usize); - let bot = (mi_row0 as usize + 2, mi_col0 as usize); - let mode_top = decode_leaf_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - top, - 16, - 8, - None, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; - let mode_bot = decode_leaf_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - bot, - 16, - 8, - Some((top, mode_top)), - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; - neighbours.above_mode[sc] = mode_bot; - neighbours.left_mode[sr] = mode_bot; continue; } - if part16 == PARTITION_VERT { - hit!(HORZ_VERT_INTRA_HITS); - let (mi_row0, mi_col0) = ( - sr as u32 * SUB_MI, - sc as u32 * SUB_MI, + // The true edge falls inside this 16x16 + // leaf itself (mod-32==8 target sizes, + // lane-av1-rect): one axis only -- an 8x8 + // leaf never itself straddles, so the + // block splits cleanly along whichever + // axis is short. + // lane-edgeboth r1: when the true frame + // edge cuts BOTH axes libaom's + // `decode_partition` takes + // `else if (!has_rows && !has_cols) + // partition = PARTITION_SPLIT;` -- no + // symbol of any kind is read, and the four + // 8x8 children are then visited by the + // same loop below, whose + // `mr < mi_rows && mc < mi_cols` filter IS + // libaom's own + // `if (mi_row >= mi_rows || mi_col >= mi_cols) return;` + // early return, so the three out-of-frame + // quadrants get no neighbour or tx-grid + // write. + if !has_cols16 && !has_rows16 { + bump_edge_both_cut(0); + } else { + // lane-golomb r1 (class + // `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 names + // PARTITION_HORZ (resp. VERT), only 1 is + // SPLIT (libaom `ec_read_partition_impl`). + // This path can only walk the four SPLIT + // leaves, so a 0 refuses by name instead + // of desyncing. + trace_edge( + sr * SUB_MI as usize, + sc * SUB_MI as usize, + 6, + ctx16, + dec.debug_state().0 as u32, ); - let left = (mi_row0 as usize, mi_col0 as usize); - let right = (mi_row0 as usize, mi_col0 as usize + 2); - let mode_left = decode_leaf_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - left, - 8, - 16, - None, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; - let mode_right = decode_leaf_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - right, - 8, - 16, - Some((left, mode_left)), - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; - neighbours.above_mode[sc] = mode_right; - neighbours.left_mode[sr] = mode_right; - continue; - } - if part16 == PARTITION_HORZ_4 - || part16 == PARTITION_VERT_4 - { - decode_rect4_16( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - part16 == PARTITION_HORZ_4, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; - continue; + let edge_split = if has_cols16 { + dec.symbol_fixed(&gather( + &cdfs.partition_w16[ctx16], + VERT_ALIKE, + )) + } else { + dec.symbol_fixed(&gather( + &cdfs.partition_w16[ctx16], + HORZ_ALIKE, + )) + }; + // lane-hgkf r1: slots 2/3 of + // [`EDGE_PART_HITS`], the gate's proof the + // non-SPLIT edge arm actually decoded. + bump_edge_part(if edge_split == 1 { 3 } else { 2 }); + if edge_split == 0 { + // lane-oddh r1: the strip IS decodable + // -- libaom's `decode_partition` codes + // only the FIRST half of an edge + // HORZ/VERT (the second call is + // guarded by the same has_rows/ + // has_cols test that made the + // partition non-square), so one + // 16x8 (resp. 8x16) strip covers the + // whole visible band of a frame whose + // height (resp. width) is 8 mod 16 -- + // the user's 3840x1608 film. + hit!(HORZ_VERT_INTRA_HITS); + hit!(EDGE_RECT_STRIP_HITS); + let (mi_row0, mi_col0) = + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); + let (bw, bh) = + if has_cols16 { (16, 8) } else { (8, 16) }; + let mode = decode_leaf_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + (mi_row0 as usize, mi_col0 as usize), + bw, + bh, + None, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + )?; + neighbours.above_mode[sc] = mode; + neighbours.left_mode[sr] = mode; + continue; + } } - // lane-r14 r2 (verifier note): every - // one of the 10 symbols this CDF can - // produce is handled above, so SPLIT - // is the only value that reaches - // here -- the refusal that used to - // stand here was unreachable and is - // gone from `refusal_inventory`. - debug_assert_eq!(part16, PARTITION_SPLIT); - // A real (non-straddle) SPLIT of a - // whole 16x16 into four 8x8 leaves -- - // the same recursion the straddle - // path below already runs when the - // true frame edge forces it, just - // over all four positions instead of - // the one or two the edge leaves. let (mi_row0, mi_col0) = (sr as u32 * SUB_MI, sc as u32 * SUB_MI); - // Each 8x8 leaf's intra-mode context - // must see its own siblings: the - // bottom-left leaf's ABOVE neighbour - // is leaf 0, not the previously - // decoded leaf 1 (and the bottom-right - // leaf's above is leaf 1, while - // `prev_leaf` only ever carried the - // immediately preceding one). The - // coarse `above_mode`/`left_mode` - // arrays hold one slot per 16x16, so - // the sibling modes are swapped in - // around each leaf call and restored - // after; the loop tail writes the last - // leaf's mode as before. + let leaf_positions: Vec<(u32, u32)> = (0..4) + .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) + .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) + .collect(); + // See the sibling-mode note in the clean + // SPLIT path above. let mut sib_modes: [Option<(usize, usize)>; 4] = [None; 4]; - for i in 0..4 { - let (mr, mc) = - (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2); + for (mr, mc) in leaf_positions { let leaf_mi = (mr as usize, mc as usize); - let li = i as usize; - let saved_modes = - (neighbours.above_mode[sc], neighbours.left_mode[sr]); + let li = (((mr - mi_row0) / 2) * 2 + (mc - mi_col0) / 2) + as usize; + let saved_modes = ( + neighbours.above_mode[sc], + neighbours.left_mode[sr], + ); if li >= 2 { if let Some((below, _)) = sib_modes[li - 2] { neighbours.above_mode[sc] = below; @@ -29155,17 +33514,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( } } let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); - if crate::envflags::env_flag!("EC_TRACE") { - eprintln!("EC_PART mi_row={} mi_col={} bsize=3 ctx={} tell={} rng={}", leaf_mi.0, leaf_mi.1, leaf_ctx, dec.debug_bitpos(), dec.debug_state().0); - } + let pre8 = dec.debug_state().0; let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); - if crate::envflags::env_flag!("EC_TRACE") { - eprintln!("EC_PART_VAL mi_row={} mi_col={} bsize=3 value={}", leaf_mi.0, leaf_mi.1, part8); - } if crate::envflags::env_flag!("EC_AV1_TRACE") { eprintln!( - "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" + "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8} pre_rng={pre8}" ); } let leaf_mode = if part8 == PARTITION_NONE { @@ -29185,8 +33539,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, allow_intrabc, tx_select, - reduced_tx_set, fctx, - ).map(|m| (m, m))? + reduced_tx_set, + fctx, + ) + .map(|m| (m, m))? } else if part8 == PARTITION_SPLIT { decode_leaf_split4( &mut dec, @@ -29202,7 +33558,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( base_q_idx, enable_filter_intra, allow_intrabc, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )? } else if part8 == PARTITION_HORZ || part8 == PARTITION_VERT @@ -29222,96 +33579,69 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( enable_filter_intra, allow_intrabc, tx_select, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )? } else { - unreachable!("partition_w8 is a 4-symbol CDF: NONE/HORZ/VERT/SPLIT only"); + unreachable!( + "partition_w8 is a 4-symbol CDF: NONE/HORZ/VERT/SPLIT only" + ); }; neighbours.above_mode[sc] = saved_modes.0; neighbours.left_mode[sr] = saved_modes.1; sib_modes[li] = Some(leaf_mode); } - if let Some((below, _)) = sib_modes[2].or(sib_modes[3]).or(sib_modes[0]) { + // `record()`'s `above_mode`/`left_mode` + // write is a no-op at an 8x8 leaf's own + // side, so force the write once the whole + // 16x16 slot's leaves are done, from the + // last leaf (mirrors the writer's r15 + // fix). + if let Some((below, _)) = + sib_modes[2].or(sib_modes[3]).or(sib_modes[0]) + { neighbours.above_mode[sc] = below; } - if let Some((_, right)) = sib_modes[1].or(sib_modes[3]).or(sib_modes[0]) { + if let Some((_, right)) = + sib_modes[1].or(sib_modes[3]).or(sib_modes[0]) + { neighbours.left_mode[sr] = right; } - continue; } - // The true edge falls inside this 16x16 - // leaf itself (mod-32==8 target sizes, - // lane-av1-rect): one axis only -- an 8x8 - // leaf never itself straddles, so the - // block splits cleanly along whichever - // axis is short. - // lane-edgeboth r1: when the true frame - // edge cuts BOTH axes libaom's - // `decode_partition` takes - // `else if (!has_rows && !has_cols) - // partition = PARTITION_SPLIT;` -- no - // symbol of any kind is read, and the four - // 8x8 children are then visited by the - // same loop below, whose - // `mr < mi_rows && mc < mi_cols` filter IS - // libaom's own - // `if (mi_row >= mi_rows || mi_col >= mi_cols) return;` - // early return, so the three out-of-frame - // quadrants get no neighbour or tx-grid - // write. - if !has_cols16 && !has_rows16 { - bump_edge_both_cut(0); - } else { - // lane-golomb r1 (class - // `parsed-then-discarded`): the gathered - // bit IS the partition -- 0 names - // PARTITION_HORZ (resp. VERT), only 1 is - // SPLIT (libaom `ec_read_partition_impl`). - // This path can only walk the four SPLIT - // leaves, so a 0 refuses by name instead - // of desyncing. - trace_edge(sr * SUB_MI as usize, sc * SUB_MI as usize, 6, ctx16, dec.debug_state().0 as u32); - let edge_split = if has_cols16 { - dec.symbol_fixed(&gather( - &cdfs.partition_w16[ctx16], - VERT_ALIKE, - )) - } else { - dec.symbol_fixed(&gather( - &cdfs.partition_w16[ctx16], - HORZ_ALIKE, - )) - }; - // lane-hgkf r1: slots 2/3 of - // [`EDGE_PART_HITS`], the gate's proof the - // non-SPLIT edge arm actually decoded. - bump_edge_part(if edge_split == 1 { 3 } else { 2 }); - if edge_split == 0 { - // lane-oddh r1: the strip IS decodable - // -- libaom's `decode_partition` codes - // only the FIRST half of an edge - // HORZ/VERT (the second call is - // guarded by the same has_rows/ - // has_cols test that made the - // partition non-square), so one - // 16x8 (resp. 8x16) strip covers the - // whole visible band of a frame whose - // height (resp. width) is 8 mod 16 -- - // the user's 3840x1608 film. - hit!(HORZ_VERT_INTRA_HITS); - hit!(EDGE_RECT_STRIP_HITS); - let (mi_row0, mi_col0) = - (sr as u32 * SUB_MI, sc as u32 * SUB_MI); - let (bw, bh) = if has_cols16 { (16, 8) } else { (8, 16) }; - let mode = decode_leaf_rect( + } + PARTITION_HORZ => { + // lane-intradisp r1: two true 32x16 strips. + decode_block_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at32, + 32, + 16, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + )?; + if !has_rows32 { + bump_edge32(2); + } + // lane-hgkf r1: at the frame edge only the first half of the strip is + // coded (libaom `decode_partition` guards the second half with the same + // test that made this partition non-square). + if has_rows32 { + decode_block_rect( &mut dec, &mut cdfs, &mut neighbours, - at16, - (mi_row0 as usize, mi_col0 as usize), - bw, - bh, - None, + (at32.0 + 1, at32.1), + 32, + 16, &mut y, &mut u, &mut v, @@ -29319,148 +33649,117 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )?; - neighbours.above_mode[sc] = mode; - neighbours.left_mode[sr] = mode; - continue; - } - } - let (mi_row0, mi_col0) = - (sr as u32 * SUB_MI, sc as u32 * SUB_MI); - let leaf_positions: Vec<(u32, u32)> = (0..4) - .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) - .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) - .collect(); - // See the sibling-mode note in the clean - // SPLIT path above. - let mut sib_modes: [Option<(usize, usize)>; 4] = [None; 4]; - for (mr, mc) in leaf_positions { - let leaf_mi = (mr as usize, mc as usize); - let li = (((mr - mi_row0) / 2) * 2 + (mc - mi_col0) / 2) - as usize; - let saved_modes = - (neighbours.above_mode[sc], neighbours.left_mode[sr]); - if li >= 2 { - if let Some((below, _)) = sib_modes[li - 2] { - neighbours.above_mode[sc] = below; - } - } - if li % 2 == 1 { - if let Some((_, right)) = sib_modes[li - 1] { - neighbours.left_mode[sr] = right; - } - } - let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); - let pre8 = dec.debug_state().0; - let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); - if crate::envflags::env_flag!("EC_AV1_TRACE") { - eprintln!( - "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8} pre_rng={pre8}" - ); - } - let leaf_mode = if part8 == PARTITION_NONE { - decode_leaf8( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - leaf_mi, - (&scan8, &scan4), - None, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - tx_select, - reduced_tx_set, fctx, - ).map(|m| (m, m))? - } else if part8 == PARTITION_SPLIT { - decode_leaf_split4( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - leaf_mi, - &scan4, - None, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_intrabc, - reduced_tx_set, fctx, - )? - } else if part8 == PARTITION_HORZ - || part8 == PARTITION_VERT - { - decode_leaf_rect8( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - leaf_mi, - part8 == PARTITION_VERT, - &scan4, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_intrabc, - tx_select, - reduced_tx_set, fctx, - )? - } else { - unreachable!("partition_w8 is a 4-symbol CDF: NONE/HORZ/VERT/SPLIT only"); - }; - neighbours.above_mode[sc] = saved_modes.0; - neighbours.left_mode[sr] = saved_modes.1; - sib_modes[li] = Some(leaf_mode); } - // `record()`'s `above_mode`/`left_mode` - // write is a no-op at an 8x8 leaf's own - // side, so force the write once the whole - // 16x16 slot's leaves are done, from the - // last leaf (mirrors the writer's r15 - // fix). - if let Some((below, _)) = sib_modes[2].or(sib_modes[3]).or(sib_modes[0]) { - neighbours.above_mode[sc] = below; + } + PARTITION_VERT => { + // lane-intradisp r1: mirror of PARTITION_HORZ + // above with width/height swapped. + decode_block_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at32, + 16, + 32, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + )?; + if !has_cols32 { + bump_edge32(3); } - if let Some((_, right)) = sib_modes[1].or(sib_modes[3]).or(sib_modes[0]) { - neighbours.left_mode[sr] = right; + // lane-hgkf r1: at the frame edge only the first half of the strip is + // coded (libaom `decode_partition` guards the second half with the same + // test that made this partition non-square). + if has_cols32 { + decode_block_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + (at32.0, at32.1 + 1), + 16, + 32, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + )?; } } - } - PARTITION_HORZ => { - // lane-intradisp r1: two true 32x16 strips. - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at32, - 32, - 16, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; - if !has_rows32 { - bump_edge32(2); - } - // lane-hgkf r1: at the frame edge only the first half of the strip is - // coded (libaom `decode_partition` guards the second half with the same - // test that made this partition non-square). - if has_rows32 { + PARTITION_HORZ_A => { + // lane-part32 r1: two 16x16 squares on top + + // a true 32x16 strip below (mirrors + // decode_inter_block's cd6cb6d HORZ_A: TL, + // TR, bottom strip). + hit!(INTRA_HORZ_A_HITS); + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + at32, + SUB, + TxbSet::Luma16, + TxbSet::Chroma8, + TX16, + TX8, + (&scan16, &scan8), + true, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + fctx, + )?; + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + (at32.0, at32.1 + 1), + SUB, + TxbSet::Luma16, + TxbSet::Chroma8, + TX16, + TX8, + (&scan16, &scan8), + true, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + fctx, + )?; decode_block_rect( &mut dec, &mut cdfs, @@ -29475,36 +33774,148 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )?; } - } - PARTITION_VERT => { - // lane-intradisp r1: mirror of PARTITION_HORZ - // above with width/height swapped. - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at32, - 16, - 32, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; - if !has_cols32 { - bump_edge32(3); + PARTITION_HORZ_B => { + // lane-part32 r1: a true 32x16 strip on top + + // two 16x16 squares below (mirrors HORZ_A + // with the strip/squares order flipped, same + // shape as libaom decode_partition's HORZ_B). + hit!(INTRA_HORZ_B_HITS); + decode_block_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at32, + 32, + 16, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + )?; + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + (at32.0 + 1, at32.1), + SUB, + TxbSet::Luma16, + TxbSet::Chroma8, + TX16, + TX8, + (&scan16, &scan8), + true, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + fctx, + )?; + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + (at32.0 + 1, at32.1 + 1), + SUB, + TxbSet::Luma16, + TxbSet::Chroma8, + TX16, + TX8, + (&scan16, &scan8), + true, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + fctx, + )?; } - // lane-hgkf r1: at the frame edge only the first half of the strip is - // coded (libaom `decode_partition` guards the second half with the same - // test that made this partition non-square). - if has_cols32 { + PARTITION_VERT_A => { + // lane-part32 r1: mirror of HORZ_A with + // width/height swapped (TL, BL, right 16x32 + // strip). + hit!(INTRA_VERT_A_HITS); + let _vert_ab = crate::encode::Reach::vert_ab_partition(); + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + at32, + SUB, + TxbSet::Luma16, + TxbSet::Chroma8, + TX16, + TX8, + (&scan16, &scan8), + true, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + fctx, + )?; + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + (at32.0 + 1, at32.1), + SUB, + TxbSet::Luma16, + TxbSet::Chroma8, + TX16, + TX8, + (&scan16, &scan8), + true, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + fctx, + )?; decode_block_rect( &mut dec, &mut cdfs, @@ -29519,390 +33930,146 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )?; } - } - PARTITION_HORZ_A => { - // lane-part32 r1: two 16x16 squares on top + - // a true 32x16 strip below (mirrors - // decode_inter_block's cd6cb6d HORZ_A: TL, - // TR, bottom strip). - hit!(INTRA_HORZ_A_HITS); - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - at32, - SUB, - TxbSet::Luma16, - TxbSet::Chroma8, - TX16, - TX8, - (&scan16, &scan8), - true, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, fctx, - )?; - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - (at32.0, at32.1 + 1), - SUB, - TxbSet::Luma16, - TxbSet::Chroma8, - TX16, - TX8, - (&scan16, &scan8), - true, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, fctx, - )?; - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - (at32.0 + 1, at32.1), - 32, - 16, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; - } - PARTITION_HORZ_B => { - // lane-part32 r1: a true 32x16 strip on top + - // two 16x16 squares below (mirrors HORZ_A - // with the strip/squares order flipped, same - // shape as libaom decode_partition's HORZ_B). - hit!(INTRA_HORZ_B_HITS); - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at32, - 32, - 16, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - (at32.0 + 1, at32.1), - SUB, - TxbSet::Luma16, - TxbSet::Chroma8, - TX16, - TX8, - (&scan16, &scan8), - true, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, fctx, - )?; - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - (at32.0 + 1, at32.1 + 1), - SUB, - TxbSet::Luma16, - TxbSet::Chroma8, - TX16, - TX8, - (&scan16, &scan8), - true, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, fctx, - )?; - } - PARTITION_VERT_A => { - // lane-part32 r1: mirror of HORZ_A with - // width/height swapped (TL, BL, right 16x32 - // strip). - hit!(INTRA_VERT_A_HITS); - let _vert_ab = crate::encode::Reach::vert_ab_partition(); - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - at32, - SUB, - TxbSet::Luma16, - TxbSet::Chroma8, - TX16, - TX8, - (&scan16, &scan8), - true, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, fctx, - )?; - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - (at32.0 + 1, at32.1), - SUB, - TxbSet::Luma16, - TxbSet::Chroma8, - TX16, - TX8, - (&scan16, &scan8), - true, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, fctx, - )?; - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - (at32.0, at32.1 + 1), - 16, - 32, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; - } - PARTITION_VERT_B => { - // lane-part32 r1: a true 16x32 strip on the - // left + two 16x16 squares on the right - // (libaom decode_partition VERT_B: left - // strip, TR, BR). - hit!(INTRA_VERT_B_HITS); - let _vert_ab = crate::encode::Reach::vert_ab_partition(); - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at32, - 16, - 32, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - (at32.0, at32.1 + 1), - SUB, - TxbSet::Luma16, - TxbSet::Chroma8, - TX16, - TX8, - (&scan16, &scan8), - true, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, fctx, - )?; - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - (at32.0 + 1, at32.1 + 1), - SUB, - TxbSet::Luma16, - TxbSet::Chroma8, - TX16, - TX8, - (&scan16, &scan8), - true, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, fctx, - )?; - } - PARTITION_HORZ_4 | PARTITION_VERT_4 => { - // lane-tx64x16 r3: the 1:4 pair at the 32x32 - // level -- four 32x8 (or 8x32) strips in - // raster order, `quarter_step` = 2 mi, with - // libaom `decode_partition`'s own `i > 0` - // frame-edge break. - let horz = part32 == PARTITION_HORZ_4; - let base_mi = (at32.0 * (SUB / MI), at32.1 * (SUB / MI)); - let mut prev: Option<((usize, usize), usize)> = None; - for i in 0..4 { - let strip_mi = if horz { - (base_mi.0 + i * 2, base_mi.1) - } else { - (base_mi.0, base_mi.1 + i * 2) - }; - if i > 0 - && (strip_mi.0 >= mi_rows as usize - || strip_mi.1 >= mi_cols as usize) - { - break; - } - let (bw, bh) = if horz { (32, 8) } else { (8, 32) }; - let (mode, _uv) = decode_block_rect4( + PARTITION_VERT_B => { + // lane-part32 r1: a true 16x32 strip on the + // left + two 16x16 squares on the right + // (libaom decode_partition VERT_B: left + // strip, TR, BR). + hit!(INTRA_VERT_B_HITS); + let _vert_ab = crate::encode::Reach::vert_ab_partition(); + decode_block_rect( &mut dec, &mut cdfs, &mut neighbours, - strip_mi, - bw, - bh, - prev, + at32, + 16, + 32, &mut y, &mut u, &mut v, enable_filter_intra, allow_screen_content_tools, base_q_idx, - tx_select, fctx, + tx_select, + reduced_tx_set, + fctx, + )?; + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + (at32.0, at32.1 + 1), + SUB, + TxbSet::Luma16, + TxbSet::Chroma8, + TX16, + TX8, + (&scan16, &scan8), + true, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + fctx, + )?; + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + (at32.0 + 1, at32.1 + 1), + SUB, + TxbSet::Luma16, + TxbSet::Chroma8, + TX16, + TX8, + (&scan16, &scan8), + true, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + fctx, )?; - prev = Some((strip_mi, mode)); } - } - _ => { - return Err(unsupported(format!( - "a 32x32 partition type this decoder does not code (value={part32})" - ))); + PARTITION_HORZ_4 | PARTITION_VERT_4 => { + // lane-tx64x16 r3: the 1:4 pair at the 32x32 + // level -- four 32x8 (or 8x32) strips in + // raster order, `quarter_step` = 2 mi, with + // libaom `decode_partition`'s own `i > 0` + // frame-edge break. + let horz = part32 == PARTITION_HORZ_4; + let base_mi = (at32.0 * (SUB / MI), at32.1 * (SUB / MI)); + let mut prev: Option<((usize, usize), usize)> = None; + for i in 0..4 { + let strip_mi = if horz { + (base_mi.0 + i * 2, base_mi.1) + } else { + (base_mi.0, base_mi.1 + i * 2) + }; + if i > 0 + && (strip_mi.0 >= mi_rows as usize + || strip_mi.1 >= mi_cols as usize) + { + break; + } + let (bw, bh) = if horz { (32, 8) } else { (8, 32) }; + let (mode, _uv) = decode_block_rect4( + &mut dec, + &mut cdfs, + &mut neighbours, + strip_mi, + bw, + bh, + prev, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + fctx, + )?; + prev = Some((strip_mi, mode)); + } + } + _ => { + return Err(unsupported(format!( + "a 32x32 partition type this decoder does not code (value={part32})" + ))); + } } } } - } - PARTITION_HORZ => { - // lane-sbpart r2: two true 64x32 strips. - decode_block_rect64( - &mut dec, - &mut cdfs, - &mut neighbours, - at, - 64, - 32, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; - if !has_rows { - bump_edge32(6); - } - // lane-golomb r1: at the frame edge only the first half of the - // strip is coded (libaom `decode_partition` guards the second - // with the same has_rows test that made this partition non-square). - if has_rows { + PARTITION_HORZ => { + // lane-sbpart r2: two true 64x32 strips. decode_block_rect64( &mut dec, &mut cdfs, &mut neighbours, - (at.0 + 2, at.1), + at, 64, 32, &mut y, @@ -29912,41 +34079,43 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )?; + if !has_rows { + bump_edge32(6); + } + // lane-golomb r1: at the frame edge only the first half of the + // strip is coded (libaom `decode_partition` guards the second + // with the same has_rows test that made this partition non-square). + if has_rows { + decode_block_rect64( + &mut dec, + &mut cdfs, + &mut neighbours, + (at.0 + 2, at.1), + 64, + 32, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + )?; + } } - } - PARTITION_VERT => { - // lane-sbpart r2: mirror of PARTITION_HORZ above with - // width/height swapped. - decode_block_rect64( - &mut dec, - &mut cdfs, - &mut neighbours, - at, - 32, - 64, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; - if !has_cols { - bump_edge32(7); - } - // lane-golomb r1: at the frame edge only the first half of the - // strip is coded (libaom `decode_partition` guards the second - // with the same has_cols test that made this partition non-square). - if has_cols { + PARTITION_VERT => { + // lane-sbpart r2: mirror of PARTITION_HORZ above with + // width/height swapped. decode_block_rect64( &mut dec, &mut cdfs, &mut neighbours, - (at.0, at.1 + 2), + at, 32, 64, &mut y, @@ -29956,70 +34125,171 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )?; - } - } - PARTITION_HORZ_A | PARTITION_HORZ_B | PARTITION_VERT_A | PARTITION_VERT_B => { - // lane-part32 r4: the four superblock-level AB arms, each - // two 32x32 squares plus one 64x32/32x64 strip, in - // libaom's own `decode_partition` order (decodeframe.c: - // HORZ_A = TL, TR, bottom strip; HORZ_B = top strip, BL, - // BR; VERT_A = TL, BL, right strip; VERT_B = left strip, - // TR, BR). The pieces are exactly the ones already proven - // by the `PARTITION_NONE`-under-SPLIT (32x32 square) and - // `PARTITION_HORZ`/`VERT` (rect64 strip) arms above. - hit_do! { - SB_AB_HITS.with(|c| { - let mut h = c.get(); - h[part - PARTITION_HORZ_A] += 1; - c.set(h); - }); - } - // lane-part32 r5: only the two VERTICAL arms reorder the - // square sub-blocks (TL, BL, TR, BR), so only they switch - // libaom's `has_tr`/`has_bl` tables. - let _vert_ab = (part == PARTITION_VERT_A || part == PARTITION_VERT_B) - .then(crate::encode::Reach::vert_ab_partition); - macro_rules! square32 { - ($at:expr) => { - decode_block( + if !has_cols { + bump_edge32(7); + } + // lane-golomb r1: at the frame edge only the first half of the + // strip is coded (libaom `decode_partition` guards the second + // with the same has_cols test that made this partition non-square). + if has_cols { + decode_block_rect64( &mut dec, &mut cdfs, &mut neighbours, - $at, - BLOCK, - TxbSet::Luma32, - TxbSet::Chroma16, - TX32, - TX16, - (&scan32, &scan16), - true, + (at.0, at.1 + 2), + 32, + 64, &mut y, &mut u, &mut v, - base_q_idx, enable_filter_intra, allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, + base_q_idx, tx_select, - reduced_tx_set, fctx, - )? - }; + reduced_tx_set, + fctx, + )?; + } + } + PARTITION_HORZ_A | PARTITION_HORZ_B | PARTITION_VERT_A | PARTITION_VERT_B => { + // lane-part32 r4: the four superblock-level AB arms, each + // two 32x32 squares plus one 64x32/32x64 strip, in + // libaom's own `decode_partition` order (decodeframe.c: + // HORZ_A = TL, TR, bottom strip; HORZ_B = top strip, BL, + // BR; VERT_A = TL, BL, right strip; VERT_B = left strip, + // TR, BR). The pieces are exactly the ones already proven + // by the `PARTITION_NONE`-under-SPLIT (32x32 square) and + // `PARTITION_HORZ`/`VERT` (rect64 strip) arms above. + hit_do! { + SB_AB_HITS.with(|c| { + let mut h = c.get(); + h[part - PARTITION_HORZ_A] += 1; + c.set(h); + }); + } + // lane-part32 r5: only the two VERTICAL arms reorder the + // square sub-blocks (TL, BL, TR, BR), so only they switch + // libaom's `has_tr`/`has_bl` tables. + let _vert_ab = (part == PARTITION_VERT_A || part == PARTITION_VERT_B) + .then(crate::encode::Reach::vert_ab_partition); + macro_rules! square32 { + ($at:expr) => { + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + $at, + BLOCK, + TxbSet::Luma32, + TxbSet::Chroma16, + TX32, + TX16, + (&scan32, &scan16), + true, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + fctx, + )? + }; + } + macro_rules! strip64 { + ($at:expr, $bw:expr, $bh:expr) => { + decode_block_rect64( + &mut dec, + &mut cdfs, + &mut neighbours, + $at, + $bw, + $bh, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + fctx, + )? + }; + } + let (br, bc) = (at.0 + 2, at.1 + 2); + match part { + PARTITION_HORZ_A => { + square32!(at); + square32!((at.0, bc)); + strip64!((br, at.1), 64, 32); + } + PARTITION_HORZ_B => { + strip64!(at, 64, 32); + square32!((br, at.1)); + square32!((br, bc)); + } + PARTITION_VERT_A => { + square32!(at); + square32!((br, at.1)); + strip64!((at.0, bc), 32, 64); + } + _ => { + strip64!(at, 32, 64); + square32!((at.0, bc)); + square32!((br, bc)); + } + } } - macro_rules! strip64 { - ($at:expr, $bw:expr, $bh:expr) => { + PARTITION_HORZ_4 | PARTITION_VERT_4 => { + // lane-tx64x16: the 1:4 pair at 64x64 -- four 64x16 (or + // 16x64) strips in raster order. `decode_partition` + // (`decodeframe.c`) steps by `quarter_step = mi_size / 4` + // (4 mi = 16 px = one SUB unit here) and BREAKS at the + // frame edge for `i > 0`, so a partial superblock codes + // only the strips whose origin is inside the frame. + let horz = part == PARTITION_HORZ_4; + for i in 0..4 { + let step_mi = i * (SB_MI as usize / 4); + let (this_r_mi, this_c_mi) = if horz { + ( + sb_r as usize * SB_MI as usize + step_mi, + sb_c as usize * SB_MI as usize, + ) + } else { + ( + sb_r as usize * SB_MI as usize, + sb_c as usize * SB_MI as usize + step_mi, + ) + }; + if i > 0 + && (this_r_mi >= mi_rows as usize || this_c_mi >= mi_cols as usize) + { + break; + } + let strip_at = if horz { + (at.0 + i, at.1) + } else { + (at.0, at.1 + i) + }; + let (bw, bh) = if horz { (64, 16) } else { (16, 64) }; decode_block_rect64( &mut dec, &mut cdfs, &mut neighbours, - $at, - $bw, - $bh, + strip_at, + bw, + bh, &mut y, &mut u, &mut v, @@ -30027,89 +34297,26 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, - reduced_tx_set, fctx, - )? - }; - } - let (br, bc) = (at.0 + 2, at.1 + 2); - match part { - PARTITION_HORZ_A => { - square32!(at); - square32!((at.0, bc)); - strip64!((br, at.1), 64, 32); - } - PARTITION_HORZ_B => { - strip64!(at, 64, 32); - square32!((br, at.1)); - square32!((br, bc)); - } - PARTITION_VERT_A => { - square32!(at); - square32!((br, at.1)); - strip64!((at.0, bc), 32, 64); - } - _ => { - strip64!(at, 32, 64); - square32!((at.0, bc)); - square32!((br, bc)); + reduced_tx_set, + fctx, + )?; } } - } - PARTITION_HORZ_4 | PARTITION_VERT_4 => { - // lane-tx64x16: the 1:4 pair at 64x64 -- four 64x16 (or - // 16x64) strips in raster order. `decode_partition` - // (`decodeframe.c`) steps by `quarter_step = mi_size / 4` - // (4 mi = 16 px = one SUB unit here) and BREAKS at the - // frame edge for `i > 0`, so a partial superblock codes - // only the strips whose origin is inside the frame. - let horz = part == PARTITION_HORZ_4; - for i in 0..4 { - let step_mi = i * (SB_MI as usize / 4); - let (this_r_mi, this_c_mi) = if horz { - (sb_r as usize * SB_MI as usize + step_mi, sb_c as usize * SB_MI as usize) - } else { - (sb_r as usize * SB_MI as usize, sb_c as usize * SB_MI as usize + step_mi) - }; - if i > 0 - && (this_r_mi >= mi_rows as usize || this_c_mi >= mi_cols as usize) - { - break; - } - let strip_at = if horz { (at.0 + i, at.1) } else { (at.0, at.1 + i) }; - let (bw, bh) = if horz { (64, 16) } else { (16, 64) }; - decode_block_rect64( - &mut dec, - &mut cdfs, - &mut neighbours, - strip_at, - bw, - bh, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, fctx, - )?; + _ => { + return Err(unsupported( + "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", + )); } } - _ => { - return Err(unsupported( - "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", - )); - } } } - } - if waving { - wave_submit(fctx, wave_job.0, wave_job.1); - } - // lane-timeline: this tile's last symbol is read here; its wavefront - // workers are drained by `_wave`'s drop at the end of the iteration. - crate::timeline::tile_done(); - flush_recon(fctx, &mut y, &mut u, &mut v); + if waving { + wave_submit(fctx, wave_job.0, wave_job.1); + } + // lane-timeline: this tile's last symbol is read here; its wavefront + // workers are drained by `_wave`'s drop at the end of the iteration. + crate::timeline::tile_done(); + flush_recon(fctx, &mut y, &mut u, &mut v); if tile_num == tile_info.context_update_tile_id { result_cdfs = cdfs; @@ -30132,12 +34339,20 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst) ); } - dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); + dump_stage16( + "EC_AV1_PREFILT_DUMP16", + &y, + &u, + &v, + frame_width as usize, + frame_height as usize, + ); if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { use std::io::Write; let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { - let narrow = |p: &PlaneBuf<'_>| -> Vec { p.data.iter().map(|&s| s as u8).collect() }; + let narrow = + |p: &PlaneBuf<'_>| -> Vec { p.data.iter().map(|&s| s as u8).collect() }; let _ = f.write_all(&narrow(&y)); let _ = f.write_all(&narrow(&u)); let _ = f.write_all(&narrow(&v)); @@ -30152,7 +34367,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( let crop_wide = |plane: &PlaneBuf<'_>| -> Vec { let mut out = Vec::with_capacity(plane.true_width * plane.true_height); for row in 0..plane.true_height { - out.extend(plane.data[row * plane.width..][..plane.true_width].iter().map(|&s| s as u8)); + out.extend( + plane.data[row * plane.width..][..plane.true_width] + .iter() + .map(|&s| s as u8), + ); } out }; @@ -30191,7 +34410,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( loop_filter, &neighbours, frame_width as usize, - frame_height as usize, fctx, + frame_height as usize, + fctx, ); // lane-perf4: loop restoration is the only reader of the pre-CDEF planes, // and a frame that restores nothing copied every plane twice for nothing @@ -30221,19 +34441,34 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter // dump above these bisect WHICH filter stage introduced a mismatch. dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v); - dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); + dump_stage16( + "EC_AV1_POSTDEBLOCK_DUMP16", + &y, + &u, + &v, + frame_width as usize, + frame_height as usize, + ); apply_cdef( &mut y, &mut u, &mut v, cdef, &neighbours, - (frame_width as usize, frame_height as usize), fctx, + (frame_width as usize, frame_height as usize), + fctx, None, None, ); dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); - dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); + dump_stage16( + "EC_AV1_POSTCDEF_DUMP16", + &y, + &u, + &v, + frame_width as usize, + frame_height as usize, + ); capture_stages(&y, &u, &v, deblocked.as_ref(), fctx); // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called // between `av1_cdef_frame` and `av1_loop_restoration_filter_frame`): @@ -30247,10 +34482,20 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( let mut lr_w = frame_width as usize; if let Some((upscaled_w, _)) = superres(fctx) { let bd = u32::from(bit_depth(fctx)); - let (uw, fw, fh) = (upscaled_w as usize, frame_width as usize, frame_height as usize); + let (uw, fw, fh) = ( + upscaled_w as usize, + frame_width as usize, + frame_height as usize, + ); let up = |p: &PlaneBuf<'_>, in_w: usize, in_h: usize, out_w: usize| PlaneBuf { data: std::borrow::Cow::Owned(crate::superres::upscale_plane_strided( - &p.data, p.width, in_w, in_h, p.true_width, out_w, bd, + &p.data, + p.width, + in_w, + in_h, + p.true_width, + out_w, + bd, )), width: out_w, height: in_h, @@ -30261,20 +34506,36 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( tile_x1: out_w, tile_y1: in_h, }; - let (cw, ch, cuw) = (round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx)), round_ss(uw, ss_x(fctx))); + let (cw, ch, cuw) = ( + round_ss(fw, ss_x(fctx)), + round_ss(fh, ss_y(fctx)), + round_ss(uw, ss_x(fctx)), + ); y = up(&y, fw, fh, uw); u = up(&u, cw, ch, cuw); v = up(&v, cw, ch, cuw); if let Some((dy, du, dv)) = deblocked.take() { - deblocked = Some((up(&dy, fw, fh, uw), up(&du, cw, ch, cuw), up(&dv, cw, ch, cuw))); + deblocked = Some(( + up(&dy, fw, fh, uw), + up(&du, cw, ch, cuw), + up(&dv, cw, ch, cuw), + )); } lr_w = uw; crate::superres::note_upscaled_picture(); } if let Some((deblocked_y, deblocked_u, deblocked_v)) = &deblocked { apply_loop_restoration( - &mut y, &mut u, &mut v, deblocked_y, deblocked_u, deblocked_v, lr, &lr_grid, - (lr_w, frame_height as usize), fctx, + &mut y, + &mut u, + &mut v, + deblocked_y, + deblocked_u, + deblocked_v, + lr, + &lr_grid, + (lr_w, frame_height as usize), + fctx, ); } if let Some((db_y, db_u, db_v)) = deblocked { @@ -30348,8 +34609,16 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( width: true_width, height: true_height, y: yc, - u: crop(&u, round_ss(true_width, ss_x(fctx)), round_ss(true_height, ss_y(fctx))), - v: crop(&v, round_ss(true_width, ss_x(fctx)), round_ss(true_height, ss_y(fctx))), + u: crop( + &u, + round_ss(true_width, ss_x(fctx)), + round_ss(true_height, ss_y(fctx)), + ), + v: crop( + &v, + round_ss(true_width, ss_x(fctx)), + round_ss(true_height, ss_y(fctx)), + ), }) } else { None @@ -30533,7 +34802,11 @@ fn read_mv_component( } // spec 5.11.32 `mv_fr`: same force_integer_mv carve-out as // `mv_class0_fr` above. - let fr = if force_integer_mv { 3 } else { dec.symbol(&mut c.fr) }; + let fr = if force_integer_mv { + 3 + } else { + dec.symbol(&mut c.fr) + }; let hp = if allow_high_precision_mv { dec.symbol(&mut c.hp) } else { @@ -30558,10 +34831,20 @@ fn read_mv( let joint = dec.symbol(mv_joint); let mut diff = (0, 0); if joint == 2 || joint == 3 { - diff.0 = read_mv_component(dec, &mut mv_comp[0], allow_high_precision_mv, force_integer_mv); + diff.0 = read_mv_component( + dec, + &mut mv_comp[0], + allow_high_precision_mv, + force_integer_mv, + ); } if joint == 1 || joint == 3 { - diff.1 = read_mv_component(dec, &mut mv_comp[1], allow_high_precision_mv, force_integer_mv); + diff.1 = read_mv_component( + dec, + &mut mv_comp[1], + allow_high_precision_mv, + force_integer_mv, + ); } crate::census::mv(pred.0 + diff.0, pred.1 + diff.1); (pred.0 + diff.0, pred.1 + diff.1) @@ -30588,7 +34871,8 @@ fn read_intrabc_dv( // The block's own mi footprint (`av1_find_mv_refs` takes the real bsize, // so a sub-8x8 `BLOCK_4X8`/`BLOCK_8X4` leaf scans a 1x2/2x1 neighbourhood // -- lane-av1txr). - (n4_w, n4_h): (usize, usize), fctx: &crate::decode::FrameCtx, + (n4_w, n4_h): (usize, usize), + fctx: &crate::decode::FrameCtx, ) -> (i32, i32) { const INTRABC_DELAY_PIXELS: i32 = 256; let stack_pred = fctx.intrabc_mi_grid.with(|g| { @@ -30623,10 +34907,20 @@ fn read_intrabc_dv( } // "Ref DV should not have sub-pel" (`assign_dv`): floor to full pel. let pred = ((pred.0 >> 3) * 8, (pred.1 >> 3) * 8); - let dv = read_mv(dec, &mut cdfs.dv_comp, &mut cdfs.dv_joint, pred, false, true); + let dv = read_mv( + dec, + &mut cdfs.dv_comp, + &mut cdfs.dv_joint, + pred, + false, + true, + ); if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { let (rng, _) = dec.debug_state(); - eprintln!("EC_DV mi_row={mi_r} mi_col={mi_c} dv_col={} dv_row={} rng={rng}", dv.1, dv.0); + eprintln!( + "EC_DV mi_row={mi_r} mi_col={mi_c} dv_col={} dv_row={} rng={rng}", + dv.1, dv.0 + ); } dv } @@ -30660,14 +34954,18 @@ impl PlaneBuf<'_> { w: usize, h: usize, prediction: &[u16], - residual: &[i32], fctx: &crate::decode::FrameCtx, + residual: &[i32], + fctx: &crate::decode::FrameCtx, ) { // lane-sb128c r7: a 128x64 half of a 128 root at the BOTTOM frame edge // is the first block shape whose true footprint overhangs the padded // coding surface (mi_rows = 198 -> a plane 800 rows tall, block rows // 768..832). libaom reconstructs those rows into the frame buffer's // border; nothing reads them back, so they are simply dropped here. - let (h, w) = (h.min(self.height.saturating_sub(y)), w.min(self.width.saturating_sub(x))); + let (h, w) = ( + h.min(self.height.saturating_sub(y)), + w.min(self.width.saturating_sub(x)), + ); // lane-perf4: one row of each operand at a time. `side` is the // prediction/residual stride and `self.width` the plane's, so the // three row bases are computed once per row instead of a @@ -30741,7 +35039,8 @@ fn read_inter_plane( // branch, [`Neighbours::luma_skip_ctx`]) -- `None` for the whole-block // transform every non-var-tx caller reads, whose plane-0 context is the // lone-transform-unit 0. - luma_skip_ctx: Option, fctx: &crate::decode::FrameCtx, + luma_skip_ctx: Option, + fctx: &crate::decode::FrameCtx, ) -> Result<(Grid, TxType)> { // lane-av1mono: as [`read_plane`] -- a monochrome frame codes no chroma // coefficients (`plane < av1_num_planes == 1`). @@ -30774,7 +35073,11 @@ fn read_inter_plane( }; // libaom `av1_get_tx_type` (`blockd.h`): a lossless block's type is // DCT_DCT on EVERY plane, so chroma never inherits or mode-derives one. - let default_tx_type = if lossless(fctx) { TxType::DctDct } else { default_tx_type }; + let default_tx_type = if lossless(fctx) { + TxType::DctDct + } else { + default_tx_type + }; let (grid, tx_type) = read_coeffs( dec, &mut coding, @@ -30786,7 +35089,9 @@ fn read_inter_plane( )?; note_chroma_class1(plane_idx, tx_type); if crate::envflags::env_flag!("EC_TRACE_TXTYPE") { - eprintln!("OUR_TXTYPE plane={plane_idx} x={x} y={y} side={side} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}"); + eprintln!( + "OUR_TXTYPE plane={plane_idx} x={x} y={y} side={side} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}" + ); } // lane-inter8 r1: a 64-point transform covers the whole 64x64 area but // codes only its top-left 32x32 of frequencies (spec 5.11.40) -- the @@ -30799,11 +35104,20 @@ fn read_inter_plane( let grid = extend_corner(grid, tx_side, tx_side, side, side); let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx); let tx = TxParams { - w: side, h: side, bit_depth: bit_depth(fctx), q_idx: block_q_idx(fctx), dc_delta, - ac_delta, tx_type, qm: block_iqmatrix(fctx, plane_idx, side, side, tx_type), stride: 0, + w: side, + h: side, + bit_depth: bit_depth(fctx), + q_idx: block_q_idx(fctx), + dc_delta, + ac_delta, + tx_type, + qm: block_iqmatrix(fctx, plane_idx, side, side, tx_type), + stride: 0, lossless: lossless(fctx), }; - push_mc_rect_tx(plane_idx, x, y, side, side, side, prediction, tx, &grid, fctx); + push_mc_rect_tx( + plane_idx, x, y, side, side, side, prediction, tx, &grid, fctx, + ); Ok((grid, tx_type)) } @@ -30872,16 +35186,23 @@ fn read_intra_chroma_lossless( // The unit's origin and extent in LUMA pixels: `<< ss` at // 4:2:0 (8x8 luma for a 4x4 chroma unit), identity at 4:4:4. let cu_reach = tu_reach( - side, side, - ox << ss_x(fctx), oy << ss_y(fctx), 4 << ss_x(fctx), - reach, px, py, frame_w, frame_h, fctx, + side, + side, + ox << ss_x(fctx), + oy << ss_y(fctx), + 4 << ss_x(fctx), + reach, + px, + py, + frame_w, + frame_h, + fctx, ); if let Some((ub, vb)) = palette_uv_bufs { let buf = if plane_idx == 1 { ub } else { vb }; set_palette_pred(palette_window(buf, stride, ox, oy, 4, 4), fctx); } - let buf: &mut PlaneBuf<'static> = - if plane_idx == 1 { &mut *u } else { &mut *v }; + let buf: &mut PlaneBuf<'static> = if plane_idx == 1 { &mut *u } else { &mut *v }; let cu_grid = read_plane( dec, cdfs, @@ -30908,11 +35229,19 @@ fn read_intra_chroma_lossless( // The unit's own footprint on the LUMA mi grid: 8 luma px // (two cells) at 4:2:0, 4 (one cell) at 4:4:4. neighbours.record_mi_chroma( - cu_mi, 4 << ss_x(fctx), 4 << ss_y(fctx), plane_idx, &cu_grid, + cu_mi, + 4 << ss_x(fctx), + 4 << ss_y(fctx), + plane_idx, + &cu_grid, ); hit!(CHROMA_SPLIT_TX_HITS); let dst = mu_units( - if plane_idx == 1 { &mut *u_out } else { &mut *v_out }, + if plane_idx == 1 { + &mut *u_out + } else { + &mut *v_out + }, stride * stride, ); for row in 0..4 { @@ -31028,7 +35357,11 @@ fn read_inter_chroma_lossless( ); hit!(CHROMA_SPLIT_TX_HITS); let dst = mu_units( - if plane_idx == 1 { &mut *u_out } else { &mut *v_out }, + if plane_idx == 1 { + &mut *u_out + } else { + &mut *v_out + }, stride * stride, ); for row in 0..4 { @@ -31060,17 +35393,41 @@ fn leaf8_inter_chroma_lossless( sv: Pred<'_>, at_mi: (usize, usize), (cpx, cpy): (usize, usize), - base_q_idx: u8, fctx: &crate::decode::FrameCtx, + base_q_idx: u8, + fctx: &crate::decode::FrameCtx, ) -> Result<(Grid, Grid)> { let (mut uo, mut vo) = (Vec::new(), Vec::new()); read_inter_chroma_lossless( - dec, cdfs, neighbours, u, v, su, sv, - at_mi, (cpx, cpy), (0, 0), (8, 8), (8, 8), 8, 0, - base_q_idx, &mut uo, &mut vo, fctx, + dec, + cdfs, + neighbours, + u, + v, + su, + sv, + at_mi, + (cpx, cpy), + (0, 0), + (8, 8), + (8, 8), + 8, + 0, + base_q_idx, + &mut uo, + &mut vo, + fctx, )?; Ok(( - if uo.is_empty() { Grid::Zero(64) } else { Grid::Own(uo) }, - if vo.is_empty() { Grid::Zero(64) } else { Grid::Own(vo) }, + if uo.is_empty() { + Grid::Zero(64) + } else { + Grid::Own(uo) + }, + if vo.is_empty() { + Grid::Zero(64) + } else { + Grid::Own(vo) + }, )) } @@ -31089,22 +35446,31 @@ fn read_single_ref( ) -> i8 { let above = (above_ref > 0).then_some(above_ref); let left = (left_ref > 0).then_some(left_ref); - let p1 = dec.symbol(&mut cdfs.single_ref[single_ref_p1_ctx(above, above_ref1, left, left_ref1)][0]); + let p1 = + dec.symbol(&mut cdfs.single_ref[single_ref_p1_ctx(above, above_ref1, left, left_ref1)][0]); let ref_frame = if p1 == 1 { - let p2 = dec.symbol(&mut cdfs.single_ref[single_ref_p2_ctx(above, above_ref1, left, left_ref1)][1]); + let p2 = dec + .symbol(&mut cdfs.single_ref[single_ref_p2_ctx(above, above_ref1, left, left_ref1)][1]); if p2 == 1 { ALTREF_FRAME } else { - let p6 = dec.symbol(&mut cdfs.single_ref[single_ref_p6_ctx(above, above_ref1, left, left_ref1)][5]); + let p6 = dec.symbol( + &mut cdfs.single_ref[single_ref_p6_ctx(above, above_ref1, left, left_ref1)][5], + ); if p6 == 1 { ALTREF2_FRAME } else { BWDREF_FRAME } } } else { - let p3 = dec.symbol(&mut cdfs.single_ref[single_ref_p3_ctx(above, above_ref1, left, left_ref1)][2]); + let p3 = dec + .symbol(&mut cdfs.single_ref[single_ref_p3_ctx(above, above_ref1, left, left_ref1)][2]); if p3 == 1 { - let p5 = dec.symbol(&mut cdfs.single_ref[single_ref_p5_ctx(above, above_ref1, left, left_ref1)][4]); + let p5 = dec.symbol( + &mut cdfs.single_ref[single_ref_p5_ctx(above, above_ref1, left, left_ref1)][4], + ); if p5 == 1 { GOLDEN_FRAME } else { LAST3_FRAME } } else { - let p4 = dec.symbol(&mut cdfs.single_ref[single_ref_p4_ctx(above, above_ref1, left, left_ref1)][3]); + let p4 = dec.symbol( + &mut cdfs.single_ref[single_ref_p4_ctx(above, above_ref1, left, left_ref1)][3], + ); if p4 == 1 { LAST2_FRAME } else { LAST_FRAME } } }; @@ -31175,7 +35541,12 @@ impl<'p> RefPix<'p> { let dims = Self::compatible(std::array::from_fn(|i| { refs[i].map(|p| (p.width, p.height)) })); - Self { dims, src: RefSrc::Ready(refs), bufs: std::sync::OnceLock::new(), err: std::sync::Mutex::new(None) } + Self { + dims, + src: RefSrc::Ready(refs), + bufs: std::sync::OnceLock::new(), + err: std::sync::Mutex::new(None), + } } /// References whose sizes are known (from their producers' headers) but @@ -31212,7 +35583,10 @@ impl<'p> RefPix<'p> { /// Parks a deferred prediction's failure (first one wins). fn park_err(&self, e: Error) { - let mut slot = self.err.lock().expect("the parked-error slot is never poisoned"); + let mut slot = self + .err + .lock() + .expect("the parked-error slot is never poisoned"); if slot.is_none() { *slot = Some(e); } @@ -31221,7 +35595,12 @@ impl<'p> RefPix<'p> { /// The first failure any deferred prediction parked, taken once every /// recon worker of the frame has been joined. pub(crate) fn take_err(&self) -> Result<()> { - match self.err.lock().expect("the parked-error slot is never poisoned").take() { + match self + .err + .lock() + .expect("the parked-error slot is never poisoned") + .take() + { Some(e) => Err(e), None => Ok(()), } @@ -31391,7 +35770,11 @@ fn ref_planes<'a, 'p>( ref_frame: i8, refpix: &'a RefPix<'p>, ) -> Result<(&'a PlaneBuf<'p>, &'a PlaneBuf<'p>, &'a PlaneBuf<'p>)> { - match refpix.planes()?.get(ref_frame as usize).and_then(Option::as_ref) { + match refpix + .planes()? + .get(ref_frame as usize) + .and_then(Option::as_ref) + { Some((y, u, v)) => Ok((y, u, v)), None => Err(unsupported( "a reference frame selected with no picture at this frame's own \ @@ -31436,7 +35819,10 @@ fn overlappable_above( let mut col = mi_col; while col < end_col && out.len() < max_neighbors { let cell = grid.get(mi_row - 1, col); - let mut step = cell.map_or(1, |c| c.size as usize).max(1).min(SB_MI as usize); + let mut step = cell + .map_or(1, |c| c.size as usize) + .max(1) + .min(SB_MI as usize); let mut nb = cell; // lane-obmcrec r1: the mi the neighbour's `MiInfo` is actually taken // from -- the pair merge below moves it, and libaom reads that same @@ -31491,7 +35877,10 @@ fn overlappable_left( let cell = grid.get(row, mi_col - 1); // Vertical walk steps by the neighbour's HEIGHT -- a 32x16 strip's // width (8) would swallow the strip below it. - let mut step = cell.map_or(1, |c| c.size_h as usize).max(1).min(SB_MI as usize); + let mut step = cell + .map_or(1, |c| c.size_h as usize) + .max(1) + .min(SB_MI as usize); let mut nb = cell; // lane-obmcrec r1: see `overlappable_above`'s `src`. let mut src = row; @@ -31568,7 +35957,8 @@ pub(crate) fn find_samples( bh4: usize, mi_cols: usize, mi_rows: usize, - ref_frame: i8, fctx: &crate::decode::FrameCtx, + ref_frame: i8, + fctx: &crate::decode::FrameCtx, ) -> Vec { const MAX: usize = crate::warp::LEAST_SQUARES_SAMPLES_MAX; let up_available = mi_row > 0; @@ -31581,8 +35971,7 @@ pub(crate) fn find_samples( // lane-alloc: the `format!` (and the map lookup's `String` clone) ran on // every warp block; the flag itself is a process constant. let proj_dbg = crate::envflags::env_flag!("EC_PROJ_MI") - && crate::envflags::var("EC_PROJ_MI") - .is_ok_and(|v| v == format!("{mi_row},{mi_col}")); + && crate::envflags::var("EC_PROJ_MI").is_ok_and(|v| v == format!("{mi_row},{mi_col}")); let single_ref_match = |info: &MiInfo| { let m = info.ref_frame == ref_frame && info.ref_frame1 == NO_REF1; if proj_dbg { @@ -31601,7 +35990,15 @@ pub(crate) fn find_samples( // neighbour donates its sample at ITS center (aom pts y=-72 for a // 32x16 above strip; the square assumption put it at -136). let nb_bh = (info.size_h * 4) as i32; - crate::warp::record_sample(nb_bw, nb_bh, mv32(info.mv), row_offset, sign_r, col_offset, sign_c) + crate::warp::record_sample( + nb_bw, + nb_bh, + mv32(info.mv), + row_offset, + sign_r, + col_offset, + sign_c, + ) }; 'outer: { @@ -31726,9 +36123,13 @@ pub(crate) fn num_proj_ref( bh4: usize, mi_cols: usize, mi_rows: usize, - ref_frame: i8, fctx: &crate::decode::FrameCtx, + ref_frame: i8, + fctx: &crate::decode::FrameCtx, ) -> u8 { - find_samples(grid, mi_row, mi_col, bw4, bh4, mi_cols, mi_rows, ref_frame, fctx).len() as u8 + find_samples( + grid, mi_row, mi_col, bw4, bh4, mi_cols, mi_rows, ref_frame, fctx, + ) + .len() as u8 } /// `av1_get_obmc_mask` (`reconinter.c`): the per-position blend weight @@ -31756,8 +36157,8 @@ fn obmc_mask(len: usize) -> &'static [u8] { 34, 37, 40, 43, 46, 49, 52, 54, 56, 58, 60, 61, 64, 64, 64, 64, ]; const M32: [u8; 32] = [ - 33, 35, 36, 38, 40, 41, 43, 44, 45, 47, 48, 50, 51, 52, 53, 55, 56, 57, 58, 59, 60, 60, - 61, 62, 64, 64, 64, 64, 64, 64, 64, 64, + 33, 35, 36, 38, 40, 41, 43, 44, 45, 47, 48, 50, 51, 52, 53, 55, 56, 57, 58, 59, 60, 60, 61, + 62, 64, 64, 64, 64, 64, 64, 64, 64, ]; match len { 1 => &M1, @@ -31882,7 +36283,8 @@ fn obmc_neighbour_pred( h, h_kind, v_kind, - out, fctx, + out, + fctx, ); } else { mc::predict_scaled( @@ -31897,7 +36299,8 @@ fn obmc_neighbour_pred( h, h_kind, v_kind, - out, fctx, + out, + fctx, ); } } @@ -31906,13 +36309,11 @@ fn obmc_neighbour_pred( /// row (the above-neighbour pass, `aom_blend_a64_vmask`). /// `ii_weights1d` (reconinter.c:524): the interintra smooth-mask falloff. const II_WEIGHTS_1D: [u8; 128] = [ - 60, 58, 56, 54, 52, 50, 48, 47, 45, 44, 42, 41, 39, 38, 37, 35, 34, 33, 32, - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 22, 21, 20, 19, 19, 18, 18, 17, 16, - 16, 15, 15, 14, 14, 13, 13, 12, 12, 12, 11, 11, 10, 10, 10, 9, 9, 9, 8, - 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 4, 4, - 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 60, 58, 56, 54, 52, 50, 48, 47, 45, 44, 42, 41, 39, 38, 37, 35, 34, 33, 32, 31, 30, 29, 28, 27, + 26, 25, 24, 23, 22, 22, 21, 20, 19, 19, 18, 18, 17, 16, 16, 15, 15, 14, 14, 13, 13, 12, 12, 12, + 11, 11, 10, 10, 10, 9, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 4, 4, 4, 4, + 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ]; /// lane-interintra r1: non-wedge interintra prediction for one plane @@ -31936,7 +36337,8 @@ fn interintra_blend( subh: usize, ii_mode: u8, wedge: Option<(&'static [u8], usize)>, - pred: &mut [u16], fctx: &crate::decode::FrameCtx, + pred: &mut [u16], + fctx: &crate::decode::FrameCtx, ) { // `interintra_to_intra_mode`: II_DC/II_V/II_H/II_SMOOTH. let intra_mode = match ii_mode { @@ -31969,7 +36371,8 @@ fn interintra_blend( bh, false, false, - &mut intra, fctx, + &mut intra, + fctx, ); // `ii_size_scales[bsize]` is keyed on the block's LONGER side // (`MAX_SB_SIZE >> max(bw,bh)` order), not on the square this decoder @@ -32024,7 +36427,16 @@ fn interintra_blend( /// buffer at a frame edge); `ts` is `tmp`'s own stride, the neighbour /// prediction's full width. #[allow(clippy::too_many_arguments)] -fn obmc_blend_v(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, ts: usize, tmp: &[u16]) { +fn obmc_blend_v( + dst: &mut [u16], + stride: usize, + ox: usize, + oy: usize, + w: usize, + h: usize, + ts: usize, + tmp: &[u16], +) { let mask = obmc_mask(h); for row in 0..h { let m = u32::from(mask[row]); @@ -32038,7 +36450,15 @@ fn obmc_blend_v(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, /// Blends `tmp` into `dst` at `(ox, oy)`, mask varying by column (the /// left-neighbour pass, `aom_blend_a64_hmask`). -fn obmc_blend_h(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u16]) { +fn obmc_blend_h( + dst: &mut [u16], + stride: usize, + ox: usize, + oy: usize, + w: usize, + h: usize, + tmp: &[u16], +) { let mask = obmc_mask(w); for row in 0..h { for col in 0..w { @@ -32213,7 +36633,8 @@ pub(crate) fn obmc_plan( // 4:4:4 divided to zero (`trailing_zeros(0)` = 64, a debug shift panic). let skip_chroma_above = obmc_skip_chroma_above(write_w, write_h, ss_x, ss_y); let mut above = Vec::new(); - for (off4, span4, nb, src4) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4)) + for (off4, span4, nb, src4) in + overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4)) { // `Neighbours::above_filter` is indexed in `SUB`(16px)-wide columns, // one step coarser than the mi(4px) units `overlappable_above` walks @@ -32223,11 +36644,22 @@ pub(crate) fn obmc_plan( // `above_mbmi->interp_filters`). let above_syms = above_filter.get(mi_col + src4).copied().unwrap_or([3; 2]); obmcrec_probe( - "above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, above_syms, - grid.get(mi_row - 1, mi_col + src4), interp_fixed.is_some(), + "above", + mi_row, + mi_col, + write_w, + write_h, + off4, + span4, + &nb, + above_syms, + grid.get(mi_row - 1, mi_col + src4), + interp_fixed.is_some(), ); let (h_kind, v_kind) = neighbour_filter(interp_fixed, above_syms)?; - ec_obmc_trace("above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind); + ec_obmc_trace( + "above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind, + ); let (nb_width, _) = ref_dims(nb.ref_frame, refpix)?; if mi_col + off4 + span4 > mi_cols { hit!(OBMC_EDGE_SPAN_HITS); @@ -32243,15 +36675,27 @@ pub(crate) fn obmc_plan( }); } let mut left = Vec::new(); - for (off4, span4, nb, src4) in overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4)) + for (off4, span4, nb, src4) in + overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4)) { let left_syms = left_filter.get(mi_row + src4).copied().unwrap_or([3; 2]); obmcrec_probe( - "left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, left_syms, - grid.get(mi_row + src4, mi_col - 1), interp_fixed.is_some(), + "left", + mi_row, + mi_col, + write_w, + write_h, + off4, + span4, + &nb, + left_syms, + grid.get(mi_row + src4, mi_col - 1), + interp_fixed.is_some(), ); let (h_kind, v_kind) = neighbour_filter(interp_fixed, left_syms)?; - ec_obmc_trace("left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind); + ec_obmc_trace( + "left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind, + ); let (nb_width, _) = ref_dims(nb.ref_frame, refpix)?; if mi_row + off4 + span4 > mi_rows { hit!(OBMC_EDGE_SPAN_HITS); @@ -32296,10 +36740,7 @@ pub(crate) fn obmc_skip_chroma_above( ss_x: usize, ss_y: usize, ) -> bool { - matches!( - (write_w >> ss_x, write_h >> ss_y), - (4, 4) | (8, 4) | (4, 8) - ) + matches!((write_w >> ss_x, write_h >> ss_y), (4, 4) | (8, 4) | (4, 8)) } #[cfg(test)] @@ -32404,25 +36845,25 @@ pub(crate) fn obmc_run( .then(|| crate::envflags::var("EC_MCB").ok()) .flatten() .and_then(|v| { - let f: Vec<&str> = v.split(':').collect(); - if f.len() < 3 || f[0] != "1" { - return None; - } - let (x, y) = (f[1].parse::().ok()?, f[2].parse::().ok()?); - let fr = f.get(3).and_then(|s| s.parse::().ok()).unwrap_or(-1); - let idx = PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst) as i64; - // lane-av1ecmcb: the window is the CHROMA plane's own write region -- - // the oracle's EC_MCB spans are plane pixels, and at 4:4:4 (ss 0/0) - // the chroma block is full-size, so nothing halves. The old - // `write_w / 2` was a 4:2:0-era assumption that quartered the window - // (and the dumps below) at ss 0/0. - let (cw, ch) = (write_w >> ss_x(fctx), write_h >> ss_y(fctx)); - if x >= cpx && x < cpx + cw && y >= cpy && y < cpy + ch && (fr < 0 || fr == idx) { - Some((x, y, idx)) - } else { - None - } - }); + let f: Vec<&str> = v.split(':').collect(); + if f.len() < 3 || f[0] != "1" { + return None; + } + let (x, y) = (f[1].parse::().ok()?, f[2].parse::().ok()?); + let fr = f.get(3).and_then(|s| s.parse::().ok()).unwrap_or(-1); + let idx = PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst) as i64; + // lane-av1ecmcb: the window is the CHROMA plane's own write region -- + // the oracle's EC_MCB spans are plane pixels, and at 4:4:4 (ss 0/0) + // the chroma block is full-size, so nothing halves. The old + // `write_w / 2` was a 4:2:0-era assumption that quartered the window + // (and the dumps below) at ss 0/0. + let (cw, ch) = (write_w >> ss_x(fctx), write_h >> ss_y(fctx)); + if x >= cpx && x < cpx + cw && y >= cpy && y < cpy + ch && (fr < 0 || fr == idx) { + Some((x, y, idx)) + } else { + None + } + }); if let Some((_, _, idx)) = ec_mcb { let (cw, ch) = (write_w >> ss_x(fctx), write_h >> ss_y(fctx)); eprintln!("OUR_MCB pre f={idx} cpx={cpx} cpy={cpy} cw={cw} ch={ch}"); @@ -32438,7 +36879,20 @@ pub(crate) fn obmc_run( let (bw, bh, ox) = (nb.span4 * 4, overlap_above, nb.off4 * 4); // lane-t900 r14: the prediction is `op_mi_size` wide (kernel choice // included); only the WRITE is clipped to this block's own buffer. - obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_y, fctx); + obmc_neighbour_pred( + ny, + px + ox, + py, + nb.mv, + bw, + bh, + true, + nb.h_kind, + nb.v_kind, + nb.scale, + &mut tmp_y, + fctx, + ); obmc_blend_v(pred_y, side, ox, 0, bw.min(write_w - ox), bh, bw, &tmp_y); if !skip_chroma_above { // lane-t900 r13 (measured, NOT a defect): libaom's min-4 clamp @@ -32447,12 +36901,41 @@ pub(crate) fn obmc_run( // `overlap >> ss_y`) -- the PLANE's own subsampling shift, 0 at // 4:4:4 (lane-av1-llpred: the old `/2` hardcoded the 4:2:0 half // and half-blended every 4:4:4 OBMC block's chroma). - let (cbw, cbh, cox) = - (bw >> ss_x(fctx), overlap_above >> ss_y(fctx), ox >> ss_x(fctx)); + let (cbw, cbh, cox) = ( + bw >> ss_x(fctx), + overlap_above >> ss_y(fctx), + ox >> ss_x(fctx), + ); let cw = cbw.min((write_w >> ss_x(fctx)) - cox); - obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_u, fctx); + obmc_neighbour_pred( + nu, + cpx + cox, + cpy, + nb.mv, + cbw, + cbh, + false, + nb.h_kind, + nb.v_kind, + nb.scale, + &mut tmp_u, + fctx, + ); obmc_blend_v(pred_u, chroma_side, cox, 0, cw, cbh, cbw, &tmp_u); - obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx); + obmc_neighbour_pred( + nv, + cpx + cox, + cpy, + nb.mv, + cbw, + cbh, + false, + nb.h_kind, + nb.v_kind, + nb.scale, + &mut tmp_v, + fctx, + ); obmc_blend_v(pred_v, chroma_side, cox, 0, cw, cbh, cbw, &tmp_v); } } @@ -32462,11 +36945,40 @@ pub(crate) fn obmc_run( return; }; let (bw, bh, oy) = (overlap_left, nb.span4 * 4, nb.off4 * 4); - obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_y, fctx); + obmc_neighbour_pred( + ny, + px, + py + oy, + nb.mv, + bw, + bh, + true, + nb.h_kind, + nb.v_kind, + nb.scale, + &mut tmp_y, + fctx, + ); obmc_blend_h(pred_y, side, 0, oy, bw, bh.min(write_h - oy), &tmp_y); - let (cbw, cbh, coy) = - (overlap_left >> ss_x(fctx), bh >> ss_y(fctx), oy >> ss_y(fctx)); - obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_u, fctx); + let (cbw, cbh, coy) = ( + overlap_left >> ss_x(fctx), + bh >> ss_y(fctx), + oy >> ss_y(fctx), + ); + obmc_neighbour_pred( + nu, + cpx, + cpy + coy, + nb.mv, + cbw, + cbh, + false, + nb.h_kind, + nb.v_kind, + nb.scale, + &mut tmp_u, + fctx, + ); if let Some((_, _, idx)) = ec_mcb { eprintln!( "OUR_MCB left f={idx} off4={} span4={} cbw={cbw} cbh={cbh} coy={coy} mv=({},{}) ref0={}", @@ -32479,7 +36991,20 @@ pub(crate) fn obmc_run( } let ch = cbh.min((write_h >> ss_y(fctx)) - coy); obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, ch, &tmp_u); - obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx); + obmc_neighbour_pred( + nv, + cpx, + cpy + coy, + nb.mv, + cbw, + cbh, + false, + nb.h_kind, + nb.v_kind, + nb.scale, + &mut tmp_v, + fctx, + ); obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, ch, &tmp_v); } if let Some((_, _, idx)) = ec_mcb { @@ -32554,9 +37079,6 @@ fn wedge_used_bsize(bw: usize, bh: usize) -> bool { ) } - - - /// Whether a compound reference pair is unidirectional (both references on /// the same temporal side of the current frame) -- `has_uni_comp_refs` /// (libaom `av1_reference_frame_utils.h`/`pred_common.c`'s own definition: @@ -33000,9 +37522,9 @@ fn decode_inter_block( // stride-1 one (`mc::predict_with_filters`) applies per reference, and to // refuse (rather than mis-decode) the warp/OBMC/interintra/compound // combinations that don't implement scaled MC yet. - frame_width: usize, fctx: &crate::decode::FrameCtx, + frame_width: usize, + fctx: &crate::decode::FrameCtx, ) -> Result<()> { - // lane-inter4 r1: `at` is in MI units (4 px) so a 32-level 1:4 strip can // name an 8-px offset; `(r, c)` stays the enclosing 16-px cell for the // few 16-px-granular uses below. @@ -33021,7 +37543,10 @@ fn decode_inter_block( fctx.inter_last_mc.with(|c| c.set(None)); let has_chroma = strip_chroma.is_none_or(|s| s.has_chroma); let (cpx, cpy) = match strip_chroma { - Some(s) if s.has_chroma => (s.pair_mi.1 * MI >> ss_x(fctx), s.pair_mi.0 * MI >> ss_y(fctx)), + Some(s) if s.has_chroma => ( + s.pair_mi.1 * MI >> ss_x(fctx), + s.pair_mi.0 * MI >> ss_y(fctx), + ), _ => (px >> ss_x(fctx), py >> ss_y(fctx)), }; // lane-av1-422j: the chroma prediction/residual buffers are @@ -33088,7 +37613,10 @@ fn decode_inter_block( if crate::envflags::env_flag!("EC_AV1_TELL") { eprintln!( "TELL mi_row={} mi_col={} label=block_entry side={side} tell={} range={}", - rmi, cmi, dec.debug_bitpos(), dec.debug_state().0 + rmi, + cmi, + dec.debug_bitpos(), + dec.debug_state().0 ); } let skip_mode_ctx = @@ -33106,7 +37634,9 @@ fn decode_inter_block( // `skip_mode`/`skip`, `inter_segment_id(0)` after them. let (seg_mi_r, seg_mi_c) = (rmi, cmi); let (seg_w_mi, seg_h_mi) = (write_w / 4, write_h / 4); - inter_segment_id(dec, cdfs, seg_mi_r, seg_mi_c, seg_w_mi, seg_h_mi, false, true, fctx); + inter_segment_id( + dec, cdfs, seg_mi_r, seg_mi_c, seg_w_mi, seg_h_mi, false, true, fctx, + ); // libaom `read_skip_mode` (decodemv.c): `if (!is_comp_ref_allowed(bsize)) // return 0` -- a 16x4 / 4x16 strip (min(bw, bh) == 4, blockd.h:65) reads // no `skip_mode` symbol at all. @@ -33125,7 +37655,9 @@ fn decode_inter_block( let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; - inter_segment_id(dec, cdfs, seg_mi_r, seg_mi_c, seg_w_mi, seg_h_mi, skip, false, fctx); + inter_segment_id( + dec, cdfs, seg_mi_r, seg_mi_c, seg_w_mi, seg_h_mi, skip, false, fctx, + ); maybe_read_cdef_idx(dec, rmi, cmi, (write_w / MI, write_h / MI), skip, fctx); // lane-inter4 r1: spec 5.11.6's `bSize == sbSize` -- a 64x32/64x16 strip // is NOT the whole superblock, so its `skip` never suppresses the read. @@ -33135,10 +37667,7 @@ fn decode_inter_block( let whole_sb = side == sb_px && write_w == sb_px && write_h == sb_px; maybe_read_delta_q(dec, cdfs, rmi, cmi, whole_sb, skip, fctx); maybe_read_delta_lf(dec, cdfs, rmi, cmi, whole_sb, skip, fctx); - let (has_above, has_left) = ( - rmi > neighbours.tile_row0_mi, - cmi > neighbours.tile_col0_mi, - ); + let (has_above, has_left) = (rmi > neighbours.tile_row0_mi, cmi > neighbours.tile_col0_mi); let (above_inter, left_inter) = (neighbours.above_inter[cmi], neighbours.left_inter[rmi]); let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; @@ -33190,7 +37719,10 @@ fn decode_inter_block( if crate::envflags::env_flag!("EC_AV1_TELL") { eprintln!( "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}", - rmi, cmi, dec.debug_bitpos(), dec.debug_state().0 + rmi, + cmi, + dec.debug_bitpos(), + dec.debug_state().0 ); } @@ -33258,9 +37790,8 @@ fn decode_inter_block( dec.debug_bitpos() ); } - let is_compound = - skip_mode - || (reference_select + let is_compound = skip_mode + || (reference_select // `is_comp_ref_allowed` (blockd.h:65) gates the // `comp_mode` read exactly as it gates `skip_mode`. && comp_allowed @@ -33334,7 +37865,10 @@ fn decode_inter_block( compound_mode, allow_high_precision_mv, force_integer_mv, - (gm_table[(ref0 - LAST_FRAME) as usize], gm_table[(ref1 - LAST_FRAME) as usize]), + ( + gm_table[(ref0 - LAST_FRAME) as usize], + gm_table[(ref1 - LAST_FRAME) as usize], + ), ); if crate::envflags::env_flag!("EC_TRACE_MODE") { eprintln!( @@ -33357,8 +37891,10 @@ fn decode_inter_block( // be non-TRANSLATION (IDENTITY counts) for the compound block's // interp-filter read to be suppressed. let gm_nontrans_models = is_globalmv - && global_motion[(ref0 - LAST_FRAME) as usize].model != ec_av1_syntax::WarpModel::Translation - && global_motion[(ref1 - LAST_FRAME) as usize].model != ec_av1_syntax::WarpModel::Translation; + && global_motion[(ref0 - LAST_FRAME) as usize].model + != ec_av1_syntax::WarpModel::Translation + && global_motion[(ref1 - LAST_FRAME) as usize].model + != ec_av1_syntax::WarpModel::Translation; // lane-t900 r9: `is_nontrans_global_motion` bails at // `AOMMIN(mi_size_wide, mi_size_high) < 2` before it looks at any // model, so a 4-px-sided block still reads its interp filter. @@ -33432,20 +37968,18 @@ fn decode_inter_block( // real filter match down to the "no neighbour" sentinel // whenever the shared reference sits in the neighbour's SECOND // slot (lane-av1idx r2). - let above_filter_ctx = if neighbours.above_ref[cmi] == ref0 - || neighbours.above_ref1[cmi] == Some(ref0) - { - neighbours.above_filter[cmi] - } else { - [3, 3] - }; - let left_filter_ctx = if neighbours.left_ref[rmi] == ref0 - || neighbours.left_ref1[rmi] == Some(ref0) - { - neighbours.left_filter[rmi] - } else { - [3, 3] - }; + let above_filter_ctx = + if neighbours.above_ref[cmi] == ref0 || neighbours.above_ref1[cmi] == Some(ref0) { + neighbours.above_filter[cmi] + } else { + [3, 3] + }; + let left_filter_ctx = + if neighbours.left_ref[rmi] == ref0 || neighbours.left_ref1[rmi] == Some(ref0) { + neighbours.left_filter[rmi] + } else { + [3, 3] + }; globalmv_for_lf = is_globalmv; ref_frame_for_lf = ref0; mode_for_tx = 0; @@ -33525,8 +38059,8 @@ fn decode_inter_block( // lane-inter16ab r3: the row is this block's TRUE // `BLOCK_SIZES_ALL` index, not the enclosing square `side`'s // -- a 16x8 strip reads `compound_type_cdf[BLOCK_16X8]`. - let wedge_bsize = - bsize_all_index(write_w, write_h).filter(|_| wedge_used_bsize(write_w, write_h)); + let wedge_bsize = bsize_all_index(write_w, write_h) + .filter(|_| wedge_used_bsize(write_w, write_h)); let compound_type = match wedge_bsize { Some(b) => dec.symbol(&mut cdfs.compound_type[b]), None => 1, @@ -33770,45 +38304,47 @@ fn decode_inter_block( // split. This gate was missing before r2 (dead code: the masked // path always refused earlier, so it never executed with // `comp_group_idx == 1` in practice). - let (fwd_offset, bck_offset, compound_idx) = if comp_group_idx == 0 - && !skip_mode - && enable_jnt_comp - { - let idx_ctx = get_comp_index_context( - neighbours, - (rmi, cmi), - side, - order_hint_bits, - order_hint, - ref_order_hints[(ref0 - LAST_FRAME) as usize], - ref_order_hints[(ref1 - LAST_FRAME) as usize], - ); - let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); - if crate::envflags::env_flag!("EC_TRACE_MODE") { - eprintln!( - "EC_CIDX mi_row={rmi} mi_col={cmi} ctx={idx_ctx} val={idx} rng={}", - dec.debug_state().0 - ); - } - if idx == 1 { - (8, 8, 1u8) - } else { - let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign( + let (fwd_offset, bck_offset, compound_idx) = + if comp_group_idx == 0 && !skip_mode && enable_jnt_comp { + let idx_ctx = get_comp_index_context( + neighbours, + (rmi, cmi), + side, order_hint_bits, order_hint, ref_order_hints[(ref0 - LAST_FRAME) as usize], ref_order_hints[(ref1 - LAST_FRAME) as usize], ); - (fwd, bck, 0u8) - } - } else { - (8, 8, 1u8) - }; + let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); + if crate::envflags::env_flag!("EC_TRACE_MODE") { + eprintln!( + "EC_CIDX mi_row={rmi} mi_col={cmi} ctx={idx_ctx} val={idx} rng={}", + dec.debug_state().0 + ); + } + if idx == 1 { + (8, 8, 1u8) + } else { + let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign( + order_hint_bits, + order_hint, + ref_order_hints[(ref0 - LAST_FRAME) as usize], + ref_order_hints[(ref1 - LAST_FRAME) as usize], + ); + (fwd, bck, 0u8) + } + } else { + (8, 8, 1u8) + }; compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx)); if crate::envflags::env_flag!("EC_AV1_COMPIDX_DUMP") { eprintln!( "EC_COMPIDX mi_row={mi_row} mi_col={mi_col} bsize={side} mode={compound_mode} mv0=({},{}) mv1=({},{}) ref0={ref0} ref1={ref1} comp_group_idx={comp_group_idx} compound_idx={compound_idx} tell={}", - mv0.0, mv0.1, mv1.0, mv1.1, dec.debug_bitpos() + mv0.0, + mv0.1, + mv1.0, + mv1.1, + dec.debug_bitpos() ); } @@ -33865,252 +38401,387 @@ fn decode_inter_block( _v: &mut PlaneBuf<'static>, fctx: &crate::decode::FrameCtx, out: &mut [Vec; 3]| { - let (Some((py0, pu0, pv0)), Some((py1, pu1, pv1))) = - (ref_planes_deferred(ref0, refpix), ref_planes_deferred(ref1, refpix)) - else { - return; - }; - let mut inter0_y = vec![0i32; side * side]; - mc::predict_compound_intermediate_kern( - &py0.data, - py0.width, - py0.true_width, - py0.true_height, - mv_to_q4(px, mv0.1, 0), - mv_to_q4(py, mv0.0, 0), - scale0, - side, - side, - write_w, - write_h, - h_filter, - v_filter, - &mut inter0_y, fctx,); - // lane-cwarp r1: this reference's own GLOBAL warp replaces the - // translational tap (libaom `av1_warp_plane` with - // `conv_params->is_compound`); the blend below is unchanged. - if let Some(wp) = warp0.as_ref().filter(|_| warp_plane_allowed(write_w, write_h)) { - crate::warp::warp_affine_compound( - wp, &py0.data, py0.true_width as i32, py0.true_height as i32, - py0.width as i32, &mut inter0_y, px as i32, py as i32, side as i32, - side as i32, side as i32, 0, 0, fctx, - ); - } - let mut inter1_y = vec![0i32; side * side]; - mc::predict_compound_intermediate_kern( - &py1.data, - py1.width, - py1.true_width, - py1.true_height, - mv_to_q4(px, mv1.1, 0), - mv_to_q4(py, mv1.0, 0), - scale1, - side, - side, - write_w, - write_h, - h_filter, - v_filter, - &mut inter1_y, fctx,); - // lane-cwarp r1: this reference's own GLOBAL warp replaces the - // translational tap (libaom `av1_warp_plane` with - // `conv_params->is_compound`); the blend below is unchanged. - if let Some(wp) = warp1.as_ref().filter(|_| warp_plane_allowed(write_w, write_h)) { - crate::warp::warp_affine_compound( - wp, &py1.data, py1.true_width as i32, py1.true_height as i32, - py1.width as i32, &mut inter1_y, px as i32, py as i32, side as i32, - side as i32, side as i32, 0, 0, fctx, - ); - } - let mut pred_y = refill(std::mem::take(&mut out[0]), side * side); - let mut diffwtd_mask_y; - // lane-wedge r3: `mask_y` is the DIFFWTD buffer just computed OR - // the wedge codebook lookup (comp_group_idx==1's two mutually - // exclusive branches) -- same [`mc::blend_masked_compound`] call - // either way, only the mask source differs. - let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type { - diffwtd_mask_y = vec![0u8; side * side]; - hit!(DIFFWTD_HITS); - mc::diffwtd_mask(&inter0_y, &inter1_y, mask_type == 1, &mut diffwtd_mask_y, fctx); - Some(diffwtd_mask_y.as_slice()) - } else { - wedge_mask - }; - if let Some(mask_y) = mask_y { - mc::blend_masked_compound( - &inter0_y, &inter1_y, mask_y, side, side, side, 0, 0, &mut pred_y, fctx, + let (Some((py0, pu0, pv0)), Some((py1, pu1, pv1))) = ( + ref_planes_deferred(ref0, refpix), + ref_planes_deferred(ref1, refpix), + ) else { + return; + }; + let mut inter0_y = vec![0i32; side * side]; + mc::predict_compound_intermediate_kern( + &py0.data, + py0.width, + py0.true_width, + py0.true_height, + mv_to_q4(px, mv0.1, 0), + mv_to_q4(py, mv0.0, 0), + scale0, + side, + side, + write_w, + write_h, + h_filter, + v_filter, + &mut inter0_y, + fctx, ); - } else { - mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y, fctx); - } - - let mut inter0_u = vec![0i32; chroma_stride * chroma_buf_h]; - mc::predict_compound_intermediate_kern( - &pu0.data, - pu0.width, - pu0.true_width, - pu0.true_height, - mv_to_q4(cpx, mv0.1, ss_x(fctx)), - mv_to_q4(cpy, mv0.0, ss_y(fctx)), - scale0, - chroma_stride, - chroma_buf_h, - write_chroma_w, - write_chroma_h, - h_filter, - v_filter, - &mut inter0_u, fctx,); - // `av1_init_warp_params` bails when the PLANE's block is - // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma - // block of an 8x8 luma block stays translational. - if let Some(wp) = &warp0 { - if warp_plane_allowed(write_chroma_w, write_chroma_h) { + // lane-cwarp r1: this reference's own GLOBAL warp replaces the + // translational tap (libaom `av1_warp_plane` with + // `conv_params->is_compound`); the blend below is unchanged. + if let Some(wp) = warp0 + .as_ref() + .filter(|_| warp_plane_allowed(write_w, write_h)) + { crate::warp::warp_affine_compound( - wp, &pu0.data, pu0.true_width as i32, pu0.true_height as i32, - pu0.width as i32, &mut inter0_u, cpx as i32, cpy as i32, - chroma_stride as i32, chroma_buf_h as i32, chroma_stride as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx, + wp, + &py0.data, + py0.true_width as i32, + py0.true_height as i32, + py0.width as i32, + &mut inter0_y, + px as i32, + py as i32, + side as i32, + side as i32, + side as i32, + 0, + 0, + fctx, ); } - } - let mut inter1_u = vec![0i32; chroma_stride * chroma_buf_h]; - mc::predict_compound_intermediate_kern( - &pu1.data, - pu1.width, - pu1.true_width, - pu1.true_height, - mv_to_q4(cpx, mv1.1, ss_x(fctx)), - mv_to_q4(cpy, mv1.0, ss_y(fctx)), - scale1, - chroma_stride, - chroma_buf_h, - write_chroma_w, - write_chroma_h, - h_filter, - v_filter, - &mut inter1_u, fctx,); - // `av1_init_warp_params` bails when the PLANE's block is - // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma - // block of an 8x8 luma block stays translational. - if let Some(wp) = &warp1 { - if warp_plane_allowed(write_chroma_w, write_chroma_h) { + let mut inter1_y = vec![0i32; side * side]; + mc::predict_compound_intermediate_kern( + &py1.data, + py1.width, + py1.true_width, + py1.true_height, + mv_to_q4(px, mv1.1, 0), + mv_to_q4(py, mv1.0, 0), + scale1, + side, + side, + write_w, + write_h, + h_filter, + v_filter, + &mut inter1_y, + fctx, + ); + // lane-cwarp r1: this reference's own GLOBAL warp replaces the + // translational tap (libaom `av1_warp_plane` with + // `conv_params->is_compound`); the blend below is unchanged. + if let Some(wp) = warp1 + .as_ref() + .filter(|_| warp_plane_allowed(write_w, write_h)) + { crate::warp::warp_affine_compound( - wp, &pu1.data, pu1.true_width as i32, pu1.true_height as i32, - pu1.width as i32, &mut inter1_u, cpx as i32, cpy as i32, - chroma_stride as i32, chroma_buf_h as i32, chroma_stride as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx, + wp, + &py1.data, + py1.true_width as i32, + py1.true_height as i32, + py1.width as i32, + &mut inter1_y, + px as i32, + py as i32, + side as i32, + side as i32, + side as i32, + 0, + 0, + fctx, ); } - } - let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_stride * chroma_buf_h); - if let Some(mask_y) = mask_y { - // lane-av1-422blockhalf: the blend walks this plane's own - // (chroma_stride x chroma_buf_h) rect through the plane's - // real subsampling shifts -- the mask read is aom_dsp/ - // blend-a64-mask.c's `(1, 0)` branch at 4:2:2, the direct - // luma sample at 4:2:0/4:4:4. - mc::blend_masked_compound( - &inter0_u, - &inter1_u, - mask_y, - side, + let mut pred_y = refill(std::mem::take(&mut out[0]), side * side); + let mut diffwtd_mask_y; + // lane-wedge r3: `mask_y` is the DIFFWTD buffer just computed OR + // the wedge codebook lookup (comp_group_idx==1's two mutually + // exclusive branches) -- same [`mc::blend_masked_compound`] call + // either way, only the mask source differs. + let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type { + diffwtd_mask_y = vec![0u8; side * side]; + hit!(DIFFWTD_HITS); + mc::diffwtd_mask( + &inter0_y, + &inter1_y, + mask_type == 1, + &mut diffwtd_mask_y, + fctx, + ); + Some(diffwtd_mask_y.as_slice()) + } else { + wedge_mask + }; + if let Some(mask_y) = mask_y { + mc::blend_masked_compound( + &inter0_y, + &inter1_y, + mask_y, + side, + side, + side, + 0, + 0, + &mut pred_y, + fctx, + ); + } else { + mc::combine_compound( + &inter0_y, + &inter1_y, + fwd_offset, + bck_offset, + &mut pred_y, + fctx, + ); + } + + let mut inter0_u = vec![0i32; chroma_stride * chroma_buf_h]; + mc::predict_compound_intermediate_kern( + &pu0.data, + pu0.width, + pu0.true_width, + pu0.true_height, + mv_to_q4(cpx, mv0.1, ss_x(fctx)), + mv_to_q4(cpy, mv0.0, ss_y(fctx)), + scale0, chroma_stride, chroma_buf_h, - ss_x(fctx), - ss_y(fctx), - &mut pred_u, fctx, + write_chroma_w, + write_chroma_h, + h_filter, + v_filter, + &mut inter0_u, + fctx, ); - } else { - mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u, fctx); - } - - let mut inter0_v = vec![0i32; chroma_stride * chroma_buf_h]; - mc::predict_compound_intermediate_kern( - &pv0.data, - pv0.width, - pv0.true_width, - pv0.true_height, - mv_to_q4(cpx, mv0.1, ss_x(fctx)), - mv_to_q4(cpy, mv0.0, ss_y(fctx)), - scale0, - chroma_stride, - chroma_buf_h, - write_chroma_w, - write_chroma_h, - h_filter, - v_filter, - &mut inter0_v, fctx,); - // `av1_init_warp_params` bails when the PLANE's block is - // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma - // block of an 8x8 luma block stays translational. - if let Some(wp) = &warp0 { - if warp_plane_allowed(write_chroma_w, write_chroma_h) { - crate::warp::warp_affine_compound( - wp, &pv0.data, pv0.true_width as i32, pv0.true_height as i32, - pv0.width as i32, &mut inter0_v, cpx as i32, cpy as i32, - chroma_stride as i32, chroma_buf_h as i32, chroma_stride as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx, - ); + // `av1_init_warp_params` bails when the PLANE's block is + // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma + // block of an 8x8 luma block stays translational. + if let Some(wp) = &warp0 { + if warp_plane_allowed(write_chroma_w, write_chroma_h) { + crate::warp::warp_affine_compound( + wp, + &pu0.data, + pu0.true_width as i32, + pu0.true_height as i32, + pu0.width as i32, + &mut inter0_u, + cpx as i32, + cpy as i32, + chroma_stride as i32, + chroma_buf_h as i32, + chroma_stride as i32, + ss_x(fctx) as i32, + ss_y(fctx) as i32, + fctx, + ); + } } - } - let mut inter1_v = vec![0i32; chroma_stride * chroma_buf_h]; - mc::predict_compound_intermediate_kern( - &pv1.data, - pv1.width, - pv1.true_width, - pv1.true_height, - mv_to_q4(cpx, mv1.1, ss_x(fctx)), - mv_to_q4(cpy, mv1.0, ss_y(fctx)), - scale1, - chroma_stride, - chroma_buf_h, - write_chroma_w, - write_chroma_h, - h_filter, - v_filter, - &mut inter1_v, fctx,); - // `av1_init_warp_params` bails when the PLANE's block is - // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma - // block of an 8x8 luma block stays translational. - if let Some(wp) = &warp1 { - if warp_plane_allowed(write_chroma_w, write_chroma_h) { - crate::warp::warp_affine_compound( - wp, &pv1.data, pv1.true_width as i32, pv1.true_height as i32, - pv1.width as i32, &mut inter1_v, cpx as i32, cpy as i32, - chroma_stride as i32, chroma_buf_h as i32, chroma_stride as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx, + let mut inter1_u = vec![0i32; chroma_stride * chroma_buf_h]; + mc::predict_compound_intermediate_kern( + &pu1.data, + pu1.width, + pu1.true_width, + pu1.true_height, + mv_to_q4(cpx, mv1.1, ss_x(fctx)), + mv_to_q4(cpy, mv1.0, ss_y(fctx)), + scale1, + chroma_stride, + chroma_buf_h, + write_chroma_w, + write_chroma_h, + h_filter, + v_filter, + &mut inter1_u, + fctx, + ); + // `av1_init_warp_params` bails when the PLANE's block is + // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma + // block of an 8x8 luma block stays translational. + if let Some(wp) = &warp1 { + if warp_plane_allowed(write_chroma_w, write_chroma_h) { + crate::warp::warp_affine_compound( + wp, + &pu1.data, + pu1.true_width as i32, + pu1.true_height as i32, + pu1.width as i32, + &mut inter1_u, + cpx as i32, + cpy as i32, + chroma_stride as i32, + chroma_buf_h as i32, + chroma_stride as i32, + ss_x(fctx) as i32, + ss_y(fctx) as i32, + fctx, + ); + } + } + let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_stride * chroma_buf_h); + if let Some(mask_y) = mask_y { + // lane-av1-422blockhalf: the blend walks this plane's own + // (chroma_stride x chroma_buf_h) rect through the plane's + // real subsampling shifts -- the mask read is aom_dsp/ + // blend-a64-mask.c's `(1, 0)` branch at 4:2:2, the direct + // luma sample at 4:2:0/4:4:4. + mc::blend_masked_compound( + &inter0_u, + &inter1_u, + mask_y, + side, + chroma_stride, + chroma_buf_h, + ss_x(fctx), + ss_y(fctx), + &mut pred_u, + fctx, + ); + } else { + mc::combine_compound( + &inter0_u, + &inter1_u, + fwd_offset, + bck_offset, + &mut pred_u, + fctx, ); } - } - let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_stride * chroma_buf_h); - if let Some(mask_y) = mask_y { - // lane-av1-422blockhalf: the blend walks this plane's own - // (chroma_stride x chroma_buf_h) rect through the plane's - // real subsampling shifts -- the mask read is aom_dsp/ - // blend-a64-mask.c's `(1, 0)` branch at 4:2:2, the direct - // luma sample at 4:2:0/4:4:4. - mc::blend_masked_compound( - &inter0_v, - &inter1_v, - mask_y, - side, + + let mut inter0_v = vec![0i32; chroma_stride * chroma_buf_h]; + mc::predict_compound_intermediate_kern( + &pv0.data, + pv0.width, + pv0.true_width, + pv0.true_height, + mv_to_q4(cpx, mv0.1, ss_x(fctx)), + mv_to_q4(cpy, mv0.0, ss_y(fctx)), + scale0, chroma_stride, chroma_buf_h, - ss_x(fctx), - ss_y(fctx), - &mut pred_v, fctx, + write_chroma_w, + write_chroma_h, + h_filter, + v_filter, + &mut inter0_v, + fctx, ); - } else { - mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v, fctx); - } + // `av1_init_warp_params` bails when the PLANE's block is + // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma + // block of an 8x8 luma block stays translational. + if let Some(wp) = &warp0 { + if warp_plane_allowed(write_chroma_w, write_chroma_h) { + crate::warp::warp_affine_compound( + wp, + &pv0.data, + pv0.true_width as i32, + pv0.true_height as i32, + pv0.width as i32, + &mut inter0_v, + cpx as i32, + cpy as i32, + chroma_stride as i32, + chroma_buf_h as i32, + chroma_stride as i32, + ss_x(fctx) as i32, + ss_y(fctx) as i32, + fctx, + ); + } + } + let mut inter1_v = vec![0i32; chroma_stride * chroma_buf_h]; + mc::predict_compound_intermediate_kern( + &pv1.data, + pv1.width, + pv1.true_width, + pv1.true_height, + mv_to_q4(cpx, mv1.1, ss_x(fctx)), + mv_to_q4(cpy, mv1.0, ss_y(fctx)), + scale1, + chroma_stride, + chroma_buf_h, + write_chroma_w, + write_chroma_h, + h_filter, + v_filter, + &mut inter1_v, + fctx, + ); + // `av1_init_warp_params` bails when the PLANE's block is + // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma + // block of an 8x8 luma block stays translational. + if let Some(wp) = &warp1 { + if warp_plane_allowed(write_chroma_w, write_chroma_h) { + crate::warp::warp_affine_compound( + wp, + &pv1.data, + pv1.true_width as i32, + pv1.true_height as i32, + pv1.width as i32, + &mut inter1_v, + cpx as i32, + cpy as i32, + chroma_stride as i32, + chroma_buf_h as i32, + chroma_stride as i32, + ss_x(fctx) as i32, + ss_y(fctx) as i32, + fctx, + ); + } + } + let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_stride * chroma_buf_h); + if let Some(mask_y) = mask_y { + // lane-av1-422blockhalf: the blend walks this plane's own + // (chroma_stride x chroma_buf_h) rect through the plane's + // real subsampling shifts -- the mask read is aom_dsp/ + // blend-a64-mask.c's `(1, 0)` branch at 4:2:2, the direct + // luma sample at 4:2:0/4:4:4. + mc::blend_masked_compound( + &inter0_v, + &inter1_v, + mask_y, + side, + chroma_stride, + chroma_buf_h, + ss_x(fctx), + ss_y(fctx), + &mut pred_v, + fctx, + ); + } else { + mc::combine_compound( + &inter0_v, + &inter1_v, + fwd_offset, + bck_offset, + &mut pred_v, + fctx, + ); + } - // lane-inter4 r2: a rectangular strip's transform tree starts from - // its own rect `max_txsize_rect_lookup` entry, not a square one. - *out = [pred_y, pred_u, pred_v]; + // lane-inter4 r2: a rectangular strip's transform tree starts from + // its own rect `max_txsize_rect_lookup` entry, not a square one. + *out = [pred_y, pred_u, pred_v]; }; let (pred_y, pred_u, pred_v): (Vec, Vec, Vec); let (sy, su, sv) = if recon_deferred(fctx) { push_pred(fctx, build); ( - Pred::Cur { plane: 0, stride: side, off: 0 }, - Pred::Cur { plane: 1, stride: chroma_stride, off: 0 }, - Pred::Cur { plane: 2, stride: chroma_stride, off: 0 }, + Pred::Cur { + plane: 0, + stride: side, + off: 0, + }, + Pred::Cur { + plane: 1, + stride: chroma_stride, + off: 0, + }, + Pred::Cur { + plane: 2, + stride: chroma_stride, + off: 0, + }, ) } else { let mut built: [Vec; 3] = Default::default(); @@ -34133,7 +38804,8 @@ fn decode_inter_block( at_mi, (write_w, write_h), (mi_cols as usize, mi_rows as usize), - skip, fctx, + skip, + fctx, )? } else { read_block_tx_size( @@ -34144,37 +38816,44 @@ fn decode_inter_block( side, (mi_cols as usize, mi_rows as usize), true, - skip, fctx, + skip, + fctx, )? .1 }; if skip { - push_mc_rect(0, + push_mc_rect( + 0, px, py, side, write_w, write_h, sy, - &ZERO_RESIDUAL[..side * side], fctx, + &ZERO_RESIDUAL[..side * side], + fctx, ); - push_mc_rect(1, + push_mc_rect( + 1, cpx, cpy, chroma_stride, write_chroma_w, write_chroma_h, su, - &ZERO_RESIDUAL[..chroma_stride * chroma_buf_h], fctx, + &ZERO_RESIDUAL[..chroma_stride * chroma_buf_h], + fctx, ); - push_mc_rect(2, + push_mc_rect( + 2, cpx, cpy, chroma_stride, write_chroma_w, write_chroma_h, sv, - &ZERO_RESIDUAL[..chroma_stride * chroma_buf_h], fctx, + &ZERO_RESIDUAL[..chroma_stride * chroma_buf_h], + fctx, ); luma_grid = Grid::Zero(side * side); u_grid = Grid::Zero(chroma_stride * chroma_buf_h); @@ -34231,8 +38910,7 @@ fn decode_inter_block( // chunk tail's chroma units can each inherit the type of the // leaf covering their own quadrant (`av1_get_tx_type`, // blockd.h:1291, scales the CHROMA 4x4 position back to luma). - let mut leaf_tx_types: Vec<(usize, usize, usize, usize, TxType)> = - Vec::new(); + let mut leaf_tx_types: Vec<(usize, usize, usize, usize, TxType)> = Vec::new(); if let Some(leaves) = vartx_leaves.as_ref() { // spec 5.11.17's transform tree, leaf by leaf in the order // `read_var_tx_size` coded it: each unit reads its own @@ -34264,7 +38942,8 @@ fn decode_inter_block( base_q_idx, tu_pred, None, - Some(tu_skip_ctx), fctx, + Some(tu_skip_ctx), + fctx, )? } else { // lane-r14 r3: a 1:4 strip's `sub_tx_size_map` @@ -34292,7 +38971,8 @@ fn decode_inter_block( tu_py, sy.offset(start), None, - Some(tu_skip_ctx), fctx, + Some(tu_skip_ctx), + fctx, )? }; if idx == 0 { @@ -34365,13 +39045,24 @@ fn decode_inter_block( // lane-lossless2: TX_4X4 units over this // chunk's chroma, not one TX_32X32 unit. read_inter_chroma_lossless( - dec, cdfs, neighbours, u, v, su, sv, - at_mi, (cpx, cpy), + dec, + cdfs, + neighbours, + u, + v, + su, + sv, + at_mi, + (cpx, cpy), (cc * chunk_chroma_w, cr * chunk_chroma_h), (chunk_chroma_w, chunk_chroma_h), (write_chroma_w, write_chroma_h), - chroma_side, mode_for_tx, base_q_idx, - &mut u_units, &mut v_units, fctx, + chroma_side, + mode_for_tx, + base_q_idx, + &mut u_units, + &mut v_units, + fctx, )?; mu_chroma = true; continue; @@ -34388,26 +39079,21 @@ fn decode_inter_block( for ur in 0..units_h { for uc in 0..units_w { let unit_mi = ( - at_mi.0 + cr * 16 - + ur * (unit_luma_h / MI), - at_mi.1 + cc * 16 - + uc * (unit_luma_w / MI), + at_mi.0 + cr * 16 + ur * (unit_luma_h / MI), + at_mi.1 + cc * 16 + uc * (unit_luma_w / MI), ); // Per unit, AFTER the earlier // units' stamps: this unit's // coefficient context must see // them. - let cu_around = neighbours - .around_mi_rect( - unit_mi, - unit_luma_w, - unit_luma_h, - ); + let cu_around = neighbours.around_mi_rect( + unit_mi, + unit_luma_w, + unit_luma_h, + ); let (cu_x, cu_y) = ( - cpx + cc * chunk_chroma_w - + uc * cu_tx, - cpy + cr * chunk_chroma_h - + ur * cu_tx, + cpx + cc * chunk_chroma_w + uc * cu_tx, + cpy + cr * chunk_chroma_h + ur * cu_tx, ); // `av1_get_tx_type` (blockd.h: // 1291): an inter block's chroma @@ -34416,26 +39102,20 @@ fn decode_inter_block( // luma leaf covering its own // quadrant (all of this chunk's // leaves are read by now). - let unit_rel_mi = ( - unit_mi.0 - at_mi.0, - unit_mi.1 - at_mi.1, - ); + let unit_rel_mi = + (unit_mi.0 - at_mi.0, unit_mi.1 - at_mi.1); let covering = leaf_tx_types .iter() .copied() // leaf (row, col) are mi but // (tw, th) are px (the rect // leaf path divides by MI too) - .find( - |&(lr, lc, lw, lh, _)| { - lr <= unit_rel_mi.0 - && unit_rel_mi.0 - < lr + lh / MI - && lc <= unit_rel_mi.1 - && unit_rel_mi.1 - < lc + lw / MI - }, - ) + .find(|&(lr, lc, lw, lh, _)| { + lr <= unit_rel_mi.0 + && unit_rel_mi.0 < lr + lh / MI + && lc <= unit_rel_mi.1 + && unit_rel_mi.1 < lc + lw / MI + }) .map(|(_, _, _, _, t)| t); // The prediction buffer is // `chroma_stride`-strided (the @@ -34443,9 +39123,7 @@ fn decode_inter_block( // 4:2:2), not the square // `chroma_side`. let cu_pred = src.offset( - (cr * chunk_chroma_h - + ur * cu_tx) - * chroma_stride + (cr * chunk_chroma_h + ur * cu_tx) * chroma_stride + cc * chunk_chroma_w + uc * cu_tx, ); @@ -34463,12 +39141,9 @@ fn decode_inter_block( cu_tx, base_q_idx, cu_pred, - Some( - covering.unwrap_or( - TxType::DctDct - ), - ), - Some(3), fctx, + Some(covering.unwrap_or(TxType::DctDct)), + Some(3), + fctx, )? .0; // Immediately, so the NEXT unit @@ -34499,18 +39174,13 @@ fn decode_inter_block( // indexes; the unit's true // per-axis position is what // changes. - let start = (cr * chunk_chroma_h - + ur * cu_tx - + rr) + let start = (cr * chunk_chroma_h + ur * cu_tx + rr) * chroma_side + cc * chunk_chroma_w + uc * cu_tx; - dst[start..start + cu_tx] - .copy_from_slice( - &cu_grid - [rr * cu_tx..] - [..cu_tx], - ); + dst[start..start + cu_tx].copy_from_slice( + &cu_grid[rr * cu_tx..][..cu_tx], + ); } } } @@ -34542,29 +39212,31 @@ fn decode_inter_block( py, sy, None, - None, fctx, + None, + fctx, )?; luma_tx_type = tx_type; luma_grid = Grid::Own(embed_rect_grid(&grid, write_w, write_h, side)); } else { { let coded = read_inter_plane( - dec, - cdfs, - luma_set_inter, - scan_luma, - 0, - around[0], - mode_for_tx, - y, - px, - py, - side, - base_q_idx, - sy, - None, - None, fctx, - )?; + dec, + cdfs, + luma_set_inter, + scan_luma, + 0, + around[0], + mode_for_tx, + y, + px, + py, + side, + base_q_idx, + sy, + None, + None, + fctx, + )?; luma_grid = coded.0; luma_tx_type = coded.1; } @@ -34588,20 +39260,41 @@ fn decode_inter_block( // (libaom `read_tx_size` + `decode_token_recon_block`). let (mut uo, mut vo) = (Vec::new(), Vec::new()); read_inter_chroma_lossless( - dec, cdfs, neighbours, u, v, su, sv, at_mi, (cpx, cpy), - (0, 0), (write_chroma_w, write_chroma_h), - (write_chroma_w, write_chroma_h), chroma_stride, - mode_for_tx, base_q_idx, &mut uo, &mut vo, fctx, + dec, + cdfs, + neighbours, + u, + v, + su, + sv, + at_mi, + (cpx, cpy), + (0, 0), + (write_chroma_w, write_chroma_h), + (write_chroma_w, write_chroma_h), + chroma_stride, + mode_for_tx, + base_q_idx, + &mut uo, + &mut vo, + fctx, )?; let zero = chroma_side * chroma_side; - u_grid = if uo.is_empty() { Grid::Zero(zero) } else { Grid::Own(uo) }; - v_grid = if vo.is_empty() { Grid::Zero(zero) } else { Grid::Own(vo) }; + u_grid = if uo.is_empty() { + Grid::Zero(zero) + } else { + Grid::Own(uo) + }; + v_grid = if vo.is_empty() { + Grid::Zero(zero) + } else { + Grid::Own(vo) + }; // Every unit stamped its own neighbour context above; the // whole-block record must not overwrite them with the // assembled grid (class `override-slot-on-one-arm`). mu_chroma = true; - } else if rect_tu - || (write_chroma_w, write_chroma_h) != (chroma_side, chroma_side) + } else if rect_tu || (write_chroma_w, write_chroma_h) != (chroma_side, chroma_side) { // One chroma read for the whole strip at 4:2:0, two // 32-capped units at 4:4:4 -- see the helper. @@ -34627,7 +39320,8 @@ fn decode_inter_block( (write_chroma_w, write_chroma_h), chroma_stride, mode_for_tx, - luma_tx_type, fctx, + luma_tx_type, + fctx, )?; } else if ss_x(fctx) == 0 && ss_y(fctx) == 0 && chroma_side > chroma_tx { // lane-av1-444: at ss 0/0 this block's chroma plane is @@ -34669,14 +39363,14 @@ fn decode_inter_block( base_q_idx, src.offset(cr * cu_tx * chroma_side + cc * cu_tx), Some(luma_tx_type), - Some(3), fctx, + Some(3), + fctx, )? .0; // Immediately, so the next unit's context sees // this one's coefficients. - neighbours.record_mi_chroma( - cu_mi, cu_tx, cu_tx, plane_idx, &cu_grid, - ); + neighbours + .record_mi_chroma(cu_mi, cu_tx, cu_tx, plane_idx, &cu_grid); hit!(CHROMA_SPLIT_TX_HITS); // lane-av1-444 c8: the unit's levels must ALSO // land in the block grid -- the block-tail mu @@ -34701,60 +39395,62 @@ fn decode_inter_block( u_grid = Grid::Own(u_acc); v_grid = Grid::Own(v_acc); } else { - u_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - scan_chroma, - 1, - around[1], - mode_for_tx, - u, - cpx, - cpy, - chroma_side, - base_q_idx, - su, - Some(luma_tx_type), - None, fctx, - )? - .0; - v_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - scan_chroma, - 2, - around[2], - mode_for_tx, - v, - cpx, - cpy, - chroma_side, - base_q_idx, - sv, - Some(luma_tx_type), - None, fctx, - )? - .0; + u_grid = read_inter_plane( + dec, + cdfs, + chroma_set, + scan_chroma, + 1, + around[1], + mode_for_tx, + u, + cpx, + cpy, + chroma_side, + base_q_idx, + su, + Some(luma_tx_type), + None, + fctx, + )? + .0; + v_grid = read_inter_plane( + dec, + cdfs, + chroma_set, + scan_chroma, + 2, + around[2], + mode_for_tx, + v, + cpx, + cpy, + chroma_side, + base_q_idx, + sv, + Some(luma_tx_type), + None, + fctx, + )? + .0; } } } else { - let ref_frame = - read_single_ref( - dec, - cdfs, - neighbours.above_ref[cmi], - neighbours.above_ref1[cmi], - neighbours.left_ref[rmi], - neighbours.left_ref1[rmi], - ); + let ref_frame = read_single_ref( + dec, + cdfs, + neighbours.above_ref[cmi], + neighbours.above_ref1[cmi], + neighbours.left_ref[rmi], + neighbours.left_ref1[rmi], + ); ref_frame_for_lf = ref_frame; if crate::envflags::env_flag!("EC_AV1_TELL") { let (mi_row, mi_col) = (rmi, cmi); eprintln!( "TELL mi_row={mi_row} mi_col={mi_col} label=post_ref_frame ref={ref_frame} tell={} range={}", - dec.debug_bitpos(), dec.debug_state().0 + dec.debug_bitpos(), + dec.debug_state().0 ); } // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own @@ -34817,7 +39513,9 @@ fn decode_inter_block( tpl, ); let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; - if !not_new { crate::census::mode(0); } + if !not_new { + crate::census::mode(0); + } let mut is_globalmv = false; // lane-interbis r1: which single-ref mode this block resolved to, // in the oracle's own numbering (NEARESTMV=13 .. NEWMV=16), for @@ -34851,7 +39549,9 @@ fn decode_inter_block( ) } else { let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; - if !not_zero { crate::census::mode(1); } + if !not_zero { + crate::census::mode(1); + } is_globalmv = !not_zero; let mv = if !not_zero { // GLOBALMV: `gm_get_motion_vector` (spec 7.10.2.1), already @@ -34860,7 +39560,7 @@ fn decode_inter_block( gm_table[(ref_frame - LAST_FRAME) as usize] } else { let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; - crate::census::mode(if nearest { 2 } else { 3 }); + crate::census::mode(if nearest { 2 } else { 3 }); dbg_mode = if nearest { 13 } else { 14 }; if nearest { stack.nearest_mv @@ -34918,7 +39618,8 @@ fn decode_inter_block( if crate::envflags::env_flag!("EC_AV1_TELL") { eprintln!( "TELL mi_row={mi_row} mi_col={mi_col} label=post_assign_mv tell={} range={}", - dec.debug_bitpos(), dec.debug_state().0 + dec.debug_bitpos(), + dec.debug_state().0 ); } // lane-sb128 r4: `interintra` (spec 5.11.24; libaom @@ -34999,7 +39700,8 @@ fn decode_inter_block( if crate::envflags::env_flag!("EC_AV1_TELL") { eprintln!( "TELL mi_row={mi_row} mi_col={mi_col} label=post_interintra tell={} range={}", - dec.debug_bitpos(), dec.debug_state().0 + dec.debug_bitpos(), + dec.debug_state().0 ); } // lane-motionmode round 1: `read_motion_mode` (spec 5.11.24; @@ -35114,8 +39816,7 @@ fn decode_inter_block( // true size is refused before any tile decodes ("a reference // picture whose height does not match this frame's own true // size", ~14681). Whoever lifts that refusal adds the y term. - let ref_is_scaled = - mc::scale_factor(ref_width, frame_width) != mc::REF_NO_SCALE; + let ref_is_scaled = mc::scale_factor(ref_width, frame_width) != mc::REF_NO_SCALE; let proj_ok = num_proj_ref( grid, mi_row, @@ -35124,7 +39825,8 @@ fn decode_inter_block( bh4, mi_cols as usize, mi_rows as usize, - ref_frame, fctx, + ref_frame, + fctx, ) >= 1; let warp_eligible = allow_warped_motion && !ref_is_scaled && !force_integer_mv && proj_ok; @@ -35153,7 +39855,8 @@ fn decode_inter_block( bh4, mi_cols as usize, mi_rows as usize, - ref_frame, fctx, + ref_frame, + fctx, ); if crate::envflags::env_flag!("EC_WARP_DEBUG") { eprintln!( @@ -35161,11 +39864,19 @@ fn decode_inter_block( samples.len() ); for (i, s) in samples.iter().enumerate() { - eprintln!("EC_WARP_DEBUG sample[{i}] pts={:?} pts_inref={:?}", s.pts1, s.pts2); + eprintln!( + "EC_WARP_DEBUG sample[{i}] pts={:?} pts_inref={:?}", + s.pts1, s.pts2 + ); } } if samples.len() > 1 { - crate::warp::select_samples(mv, &mut samples, side as i32, side as i32); + crate::warp::select_samples( + mv, + &mut samples, + side as i32, + side as i32, + ); } warp_params = crate::warp::find_projection( &samples, @@ -35182,10 +39893,16 @@ fn decode_inter_block( if crate::envflags::env_flag!("EC_WARP_DEBUG") { eprintln!( "EC_WARP_DEBUG projection mi_row={mi_row} mi_col={mi_col} num_proj_ref(final)={} mv=({},{}) params={:?}", - samples.len(), mv.0, mv.1, warp_params + samples.len(), + mv.0, + mv.1, + warp_params ); for (i, s) in samples.iter().enumerate() { - eprintln!("EC_WARP_DEBUG sample_used[{i}] pts={:?} pts_inref={:?}", s.pts1, s.pts2); + eprintln!( + "EC_WARP_DEBUG sample_used[{i}] pts={:?} pts_inref={:?}", + s.pts1, s.pts2 + ); } } } @@ -35252,7 +39969,9 @@ fn decode_inter_block( if crate::envflags::env_flag!("EC_AV1_TELL") { eprintln!( "TELL mi_row={mi_row} mi_col={mi_col} label=post_motion_mode eligible={} tell={} range={}", - motion_mode_eligible as u8, dec.debug_bitpos(), dec.debug_state().0 + motion_mode_eligible as u8, + dec.debug_bitpos(), + dec.debug_state().0 ); } // spec `get_ref_filter_type`: a neighbour's own filter only feeds @@ -35295,13 +40014,21 @@ fn decode_inter_block( if crate::envflags::env_flag!("EC_AV1_TELL") { eprintln!( "TELL mi_row={mi_row} mi_col={mi_col} label=post_interp_filter tell={} range={}", - dec.debug_bitpos(), dec.debug_state().0 + dec.debug_bitpos(), + dec.debug_state().0 ); } if crate::envflags::env_flag!("EC_AV1_TRACE") { eprintln!( "EC_TRACE mi_row={mi_row} mi_col={mi_col} skip={} is_inter=1 mv=({},{}) is_new_mv={is_new_mv} bsize={side} ref={ref_frame} filter={:?} motion_mode_eligible={} obmc_selected={} warped={} tell={}", - skip as u8, mv.0, mv.1, block_filter, motion_mode_eligible as u8, obmc_selected as u8, warp_params.is_some() as u8, dec.debug_bitpos() + skip as u8, + mv.0, + mv.1, + block_filter, + motion_mode_eligible as u8, + obmc_selected as u8, + warp_params.is_some() as u8, + dec.debug_bitpos() ); } // lane-rect r2: see the compound path's matching comment above -- @@ -35321,7 +40048,11 @@ fn decode_inter_block( // requires ref_frame[1] == NONE_FRAME, so such a // neighbour must not donate samples or count in // num_proj_ref. - ref_frame1: if interintra_mode.is_some() { 0 } else { NO_REF1 }, + ref_frame1: if interintra_mode.is_some() { + 0 + } else { + NO_REF1 + }, mv1: (0, 0), mv: mv16(mv), is_new_mv, @@ -35367,10 +40098,14 @@ fn decode_inter_block( // PREVIOUS strip's `mv`/`ref_frame`/`interp_filters` // (reconinter_template.inc:75-82); record them for the next 1:4 // strip, which is the only reader. - fctx.inter_last_mc.with(|c| c.set(Some((ref_frame, mv, h_filter, v_filter)))); + fctx.inter_last_mc + .with(|c| c.set(Some((ref_frame, mv, h_filter, v_filter)))); // lane-defer8: the sub-8x8 chroma piece's own reference resolved to // a SIZE here and to pixels inside the closure, like the block's own. - let sub8 = match strip_chroma.filter(|s| s.has_chroma).and_then(|s| s.prev.map(|p| (s.horz, p))) { + let sub8 = match strip_chroma + .filter(|s| s.has_chroma) + .and_then(|s| s.prev.map(|p| (s.horz, p))) + { Some((horz, (prev_ref, prev_mv, prev_h, prev_v))) => { let (prev_width, _) = ref_dims(prev_ref, refpix)?; hit!(INTER16_SUB8_PIECE_HITS); @@ -35429,207 +40164,290 @@ fn decode_inter_block( v: &mut PlaneBuf<'static>, fctx: &crate::decode::FrameCtx, out: &mut [Vec; 3]| { - let Some((py_ref, pu_ref, pv_ref)) = ref_planes_deferred(ref_frame, refpix) else { - return; - }; - let mut pred_y = refill(std::mem::take(&mut out[0]), side * side); - let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_stride * chroma_buf_h); - let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_stride * chroma_buf_h); - if luma_scale == mc::REF_NO_SCALE { - mc::predict_with_filters_kern( - &py_ref.data, - py_ref.width, - py_ref.true_width, - py_ref.true_height, - mv_to_q4(px, mv.1, 0), - mv_to_q4(py, mv.0, 0), - side, - side, - write_w, - write_h, - h_filter, - v_filter, - &mut pred_y, fctx, - ); - mc::predict_with_filters_kern( - &pu_ref.data, - pu_ref.width, - pu_ref.true_width, - pu_ref.true_height, - mv_to_q4(cpx, mv.1, ss_x(fctx)), - mv_to_q4(cpy, mv.0, ss_y(fctx)), - chroma_stride, - chroma_buf_h, - write_chroma_w, - write_chroma_h, - h_filter, - v_filter, - &mut pred_u, fctx, - ); - mc::predict_with_filters_kern( - &pv_ref.data, - pv_ref.width, - pv_ref.true_width, - pv_ref.true_height, - mv_to_q4(cpx, mv.1, ss_x(fctx)), - mv_to_q4(cpy, mv.0, ss_y(fctx)), - chroma_stride, - chroma_buf_h, - write_chroma_w, - write_chroma_h, - h_filter, - v_filter, - &mut pred_v, fctx, - ); - } else { - mc::predict_scaled_kern( - &py_ref.data, - py_ref.width, - py_ref.true_width, - py_ref.true_height, - mv_to_q4(px, mv.1, 0), - mv_to_q4(py, mv.0, 0), - luma_scale, - side, - side, - write_w, - write_h, - h_filter, - v_filter, - &mut pred_y, fctx, - ); - mc::predict_scaled_kern( - &pu_ref.data, - pu_ref.width, - pu_ref.true_width, - pu_ref.true_height, - mv_to_q4(cpx, mv.1, ss_x(fctx)), - mv_to_q4(cpy, mv.0, ss_y(fctx)), - luma_scale, - chroma_stride, - chroma_buf_h, - write_chroma_w, - write_chroma_h, - h_filter, - v_filter, - &mut pred_u, fctx, - ); - mc::predict_scaled_kern( - &pv_ref.data, - pv_ref.width, - pv_ref.true_width, - pv_ref.true_height, - mv_to_q4(cpx, mv.1, ss_x(fctx)), - mv_to_q4(cpy, mv.0, ss_y(fctx)), - luma_scale, - chroma_stride, - chroma_buf_h, - write_chroma_w, - write_chroma_h, - h_filter, - v_filter, - &mut pred_v, fctx, - ); - } - - // lane-scaledref r1: libaom `allow_warp` (av1/common/reconinter.c:41) - // opens with `if (av1_is_scaled(sf)) return 0;` -- BOTH local - // (`wm_params`) and global warp fall back to the translational - // prediction above when the reference is scaled, even though the - // motion_mode symbol was still read and warp_params still - // resolved. Suppress the warp, keep every symbol read. - if let Some(params) = warp_params.as_ref().filter(|_| luma_scale == mc::REF_NO_SCALE) { - // `av1_init_warp_params` is per PLANE: the luma plane's - // own block is `write_w`x`write_h` (a PARTITION_HORZ/VERT - // strip is not `side`x`side`), so a strip under 8 px in - // either direction keeps the translational prediction too. - if warp_plane_allowed(write_w, write_h) { - crate::warp::warp_affine( - params, &py_ref.data, py_ref.true_width as i32, py_ref.true_height as i32, - py_ref.width as i32, &mut pred_y, px as i32, py as i32, side as i32, - side as i32, side as i32, 0, 0, fctx, + let Some((py_ref, pu_ref, pv_ref)) = ref_planes_deferred(ref_frame, refpix) else { + return; + }; + let mut pred_y = refill(std::mem::take(&mut out[0]), side * side); + let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_stride * chroma_buf_h); + let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_stride * chroma_buf_h); + if luma_scale == mc::REF_NO_SCALE { + mc::predict_with_filters_kern( + &py_ref.data, + py_ref.width, + py_ref.true_width, + py_ref.true_height, + mv_to_q4(px, mv.1, 0), + mv_to_q4(py, mv.0, 0), + side, + side, + write_w, + write_h, + h_filter, + v_filter, + &mut pred_y, + fctx, ); - } - // libaom `av1_init_warp_params` (reconinter.c): warp is - // per PLANE and bails out at `block_width < 8 || - // block_height < 8`, so a plane whose own block is under - // 8x8 keeps the translational prediction built above -- - // in 420 that is every chroma plane whose own width or - // height is under 8 -- `write_chroma_w`/`write_chroma_h`, - // NOT the square `chroma_side` (lane-t900 r5: an 8x16 luma - // block has `chroma_side == 8` but a 4x8 chroma block, so - // the square side warped chroma libaom predicts - // translationally; lane-gmaffine r4 for the 8x8 leaf). - if warp_plane_allowed(write_chroma_w, write_chroma_h) { - crate::warp::warp_affine( - params, &pu_ref.data, pu_ref.true_width as i32, pu_ref.true_height as i32, - pu_ref.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_stride as i32, chroma_buf_h as i32, chroma_stride as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx, + mc::predict_with_filters_kern( + &pu_ref.data, + pu_ref.width, + pu_ref.true_width, + pu_ref.true_height, + mv_to_q4(cpx, mv.1, ss_x(fctx)), + mv_to_q4(cpy, mv.0, ss_y(fctx)), + chroma_stride, + chroma_buf_h, + write_chroma_w, + write_chroma_h, + h_filter, + v_filter, + &mut pred_u, + fctx, ); - crate::warp::warp_affine( - params, &pv_ref.data, pv_ref.true_width as i32, pv_ref.true_height as i32, - pv_ref.width as i32, &mut pred_v, cpx as i32, cpy as i32, chroma_stride as i32, chroma_buf_h as i32, chroma_stride as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx, + mc::predict_with_filters_kern( + &pv_ref.data, + pv_ref.width, + pv_ref.true_width, + pv_ref.true_height, + mv_to_q4(cpx, mv.1, ss_x(fctx)), + mv_to_q4(cpy, mv.0, ss_y(fctx)), + chroma_stride, + chroma_buf_h, + write_chroma_w, + write_chroma_h, + h_filter, + v_filter, + &mut pred_v, + fctx, + ); + } else { + mc::predict_scaled_kern( + &py_ref.data, + py_ref.width, + py_ref.true_width, + py_ref.true_height, + mv_to_q4(px, mv.1, 0), + mv_to_q4(py, mv.0, 0), + luma_scale, + side, + side, + write_w, + write_h, + h_filter, + v_filter, + &mut pred_y, + fctx, + ); + mc::predict_scaled_kern( + &pu_ref.data, + pu_ref.width, + pu_ref.true_width, + pu_ref.true_height, + mv_to_q4(cpx, mv.1, ss_x(fctx)), + mv_to_q4(cpy, mv.0, ss_y(fctx)), + luma_scale, + chroma_stride, + chroma_buf_h, + write_chroma_w, + write_chroma_h, + h_filter, + v_filter, + &mut pred_u, + fctx, + ); + mc::predict_scaled_kern( + &pv_ref.data, + pv_ref.width, + pv_ref.true_width, + pv_ref.true_height, + mv_to_q4(cpx, mv.1, ss_x(fctx)), + mv_to_q4(cpy, mv.0, ss_y(fctx)), + luma_scale, + chroma_stride, + chroma_buf_h, + write_chroma_w, + write_chroma_h, + h_filter, + v_filter, + &mut pred_v, + fctx, ); } - } - // Mutually exclusive with warp/OBMC (motion_mode is not read for - // an interintra block): blend the intra predictor over the MC - // result, all planes (reconinter.c av1_build_interintra_predictor - // plane loop). - if let Some(ii) = interintra_mode { - if write_w != write_h { - hit!(INTERINTRA_RECT_HITS); + + // lane-scaledref r1: libaom `allow_warp` (av1/common/reconinter.c:41) + // opens with `if (av1_is_scaled(sf)) return 0;` -- BOTH local + // (`wm_params`) and global warp fall back to the translational + // prediction above when the reference is scaled, even though the + // motion_mode symbol was still read and warp_params still + // resolved. Suppress the warp, keep every symbol read. + if let Some(params) = warp_params + .as_ref() + .filter(|_| luma_scale == mc::REF_NO_SCALE) + { + // `av1_init_warp_params` is per PLANE: the luma plane's + // own block is `write_w`x`write_h` (a PARTITION_HORZ/VERT + // strip is not `side`x`side`), so a strip under 8 px in + // either direction keeps the translational prediction too. + if warp_plane_allowed(write_w, write_h) { + crate::warp::warp_affine( + params, + &py_ref.data, + py_ref.true_width as i32, + py_ref.true_height as i32, + py_ref.width as i32, + &mut pred_y, + px as i32, + py as i32, + side as i32, + side as i32, + side as i32, + 0, + 0, + fctx, + ); + } + // libaom `av1_init_warp_params` (reconinter.c): warp is + // per PLANE and bails out at `block_width < 8 || + // block_height < 8`, so a plane whose own block is under + // 8x8 keeps the translational prediction built above -- + // in 420 that is every chroma plane whose own width or + // height is under 8 -- `write_chroma_w`/`write_chroma_h`, + // NOT the square `chroma_side` (lane-t900 r5: an 8x16 luma + // block has `chroma_side == 8` but a 4x8 chroma block, so + // the square side warped chroma libaom predicts + // translationally; lane-gmaffine r4 for the 8x8 leaf). + if warp_plane_allowed(write_chroma_w, write_chroma_h) { + crate::warp::warp_affine( + params, + &pu_ref.data, + pu_ref.true_width as i32, + pu_ref.true_height as i32, + pu_ref.width as i32, + &mut pred_u, + cpx as i32, + cpy as i32, + chroma_stride as i32, + chroma_buf_h as i32, + chroma_stride as i32, + ss_x(fctx) as i32, + ss_y(fctx) as i32, + fctx, + ); + crate::warp::warp_affine( + params, + &pv_ref.data, + pv_ref.true_width as i32, + pv_ref.true_height as i32, + pv_ref.width as i32, + &mut pred_v, + cpx as i32, + cpy as i32, + chroma_stride as i32, + chroma_buf_h as i32, + chroma_stride as i32, + ss_x(fctx) as i32, + ss_y(fctx) as i32, + fctx, + ); + } } - interintra_blend(y, px, py, write_w, write_h, side, 0, 0, ii, wedge_mask, &mut pred_y, fctx); - interintra_blend( - u, cpx, cpy, write_chroma_w, write_chroma_h, chroma_stride, ss_x(fctx), - ss_y(fctx), ii, wedge_mask, &mut pred_u, fctx, - ); - interintra_blend( - v, cpx, cpy, write_chroma_w, write_chroma_h, chroma_stride, ss_x(fctx), - ss_y(fctx), ii, wedge_mask, &mut pred_v, fctx, - ); - } - if let Some(plan) = &obmc { - obmc_run(plan, refpix, &mut pred_y, &mut pred_u, &mut pred_v, fctx); - } - // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8` - // (reconinter_template.inc:87-160). A 4:2:0 chroma block under a - // 16x4 (4x16) luma pair covers TWO luma blocks, so it is built in - // `b4_w x b4_h` = 8x2 (2x8) pieces, each from its own strip's - // mv/ref/filters. The bottom (right) piece is this strip's own mv - // over its own rows, which the whole-block prediction above - // already wrote there (MC is position-invariant for a fixed mv), - // so only the FIRST piece has to be rebuilt -- and only when - // `is_sub8x8_inter` holds. lane-t900 r28: it scales off the - // PREVIOUS strip's own reference, not this block's. - if let Some((horz, prev_ref, prev_mv, prev_h, prev_v, prev_scale)) = sub8 { - let Some((_, prev_u, prev_v_plane)) = ref_planes_deferred(prev_ref, refpix) else { - return; - }; - let (piece_w, piece_h) = if horz { (8usize, 2usize) } else { (2usize, 8usize) }; - for (src, dst) in [(prev_u, &mut pred_u), (prev_v_plane, &mut pred_v)] { - let mut piece = vec![0u16; piece_w * piece_h]; - mc::predict_maybe_scaled( - &src.data, - src.width, - src.true_width, - src.true_height, - mv_to_q4(cpx, prev_mv.1, ss_x(fctx)), - mv_to_q4(cpy, prev_mv.0, ss_y(fctx)), - prev_scale, - piece_w, - piece_h, - prev_h, - prev_v, - &mut piece, fctx, + // Mutually exclusive with warp/OBMC (motion_mode is not read for + // an interintra block): blend the intra predictor over the MC + // result, all planes (reconinter.c av1_build_interintra_predictor + // plane loop). + if let Some(ii) = interintra_mode { + if write_w != write_h { + hit!(INTERINTRA_RECT_HITS); + } + interintra_blend( + y, + px, + py, + write_w, + write_h, + side, + 0, + 0, + ii, + wedge_mask, + &mut pred_y, + fctx, ); - for row in 0..piece_h { - dst[row * chroma_stride..row * chroma_stride + piece_w] - .copy_from_slice(&piece[row * piece_w..(row + 1) * piece_w]); + interintra_blend( + u, + cpx, + cpy, + write_chroma_w, + write_chroma_h, + chroma_stride, + ss_x(fctx), + ss_y(fctx), + ii, + wedge_mask, + &mut pred_u, + fctx, + ); + interintra_blend( + v, + cpx, + cpy, + write_chroma_w, + write_chroma_h, + chroma_stride, + ss_x(fctx), + ss_y(fctx), + ii, + wedge_mask, + &mut pred_v, + fctx, + ); + } + if let Some(plan) = &obmc { + obmc_run(plan, refpix, &mut pred_y, &mut pred_u, &mut pred_v, fctx); + } + // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8` + // (reconinter_template.inc:87-160). A 4:2:0 chroma block under a + // 16x4 (4x16) luma pair covers TWO luma blocks, so it is built in + // `b4_w x b4_h` = 8x2 (2x8) pieces, each from its own strip's + // mv/ref/filters. The bottom (right) piece is this strip's own mv + // over its own rows, which the whole-block prediction above + // already wrote there (MC is position-invariant for a fixed mv), + // so only the FIRST piece has to be rebuilt -- and only when + // `is_sub8x8_inter` holds. lane-t900 r28: it scales off the + // PREVIOUS strip's own reference, not this block's. + if let Some((horz, prev_ref, prev_mv, prev_h, prev_v, prev_scale)) = sub8 { + let Some((_, prev_u, prev_v_plane)) = ref_planes_deferred(prev_ref, refpix) + else { + return; + }; + let (piece_w, piece_h) = if horz { + (8usize, 2usize) + } else { + (2usize, 8usize) + }; + for (src, dst) in [(prev_u, &mut pred_u), (prev_v_plane, &mut pred_v)] { + let mut piece = vec![0u16; piece_w * piece_h]; + mc::predict_maybe_scaled( + &src.data, + src.width, + src.true_width, + src.true_height, + mv_to_q4(cpx, prev_mv.1, ss_x(fctx)), + mv_to_q4(cpy, prev_mv.0, ss_y(fctx)), + prev_scale, + piece_w, + piece_h, + prev_h, + prev_v, + &mut piece, + fctx, + ); + for row in 0..piece_h { + dst[row * chroma_stride..row * chroma_stride + piece_w] + .copy_from_slice(&piece[row * piece_w..(row + 1) * piece_w]); + } } } - } - *out = [pred_y, pred_u, pred_v]; + *out = [pred_y, pred_u, pred_v]; }; // OBMC and interintra are mutually exclusive (`motion_mode` is // never read for an interintra block), so blending interintra @@ -35648,9 +40466,21 @@ fn decode_inter_block( // this arm used to take for interintra. push_pred(fctx, build); ( - Pred::Cur { plane: 0, stride: side, off: 0 }, - Pred::Cur { plane: 1, stride: chroma_stride, off: 0 }, - Pred::Cur { plane: 2, stride: chroma_stride, off: 0 }, + Pred::Cur { + plane: 0, + stride: side, + off: 0, + }, + Pred::Cur { + plane: 1, + stride: chroma_stride, + off: 0, + }, + Pred::Cur { + plane: 2, + stride: chroma_stride, + off: 0, + }, ) } else { if interintra_mode.is_some() { @@ -35661,17 +40491,17 @@ fn decode_inter_block( let [by, bu, bv] = built; (pred_y, pred_u, pred_v) = (by, bu, bv); - // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8` - // (reconinter_template.inc:87-160). A 4:2:0 chroma block under a - // 16x4 (4x16) luma pair covers TWO luma blocks, so it is built in - // `b4_w x b4_h` = 8x2 (2x8) pieces, each from its own strip's - // mv/ref/filters. The bottom (right) piece is this strip's own mv - // over its own rows, which the whole-block prediction above - // already wrote there (MC is position-invariant for a fixed mv), - // so only the FIRST piece has to be rebuilt -- and only when - // `is_sub8x8_inter` holds, i.e. the previous strip was itself a - // single-reference inter block (`prev`), else libaom falls - // through to the ordinary whole-block predictor. + // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8` + // (reconinter_template.inc:87-160). A 4:2:0 chroma block under a + // 16x4 (4x16) luma pair covers TWO luma blocks, so it is built in + // `b4_w x b4_h` = 8x2 (2x8) pieces, each from its own strip's + // mv/ref/filters. The bottom (right) piece is this strip's own mv + // over its own rows, which the whole-block prediction above + // already wrote there (MC is position-invariant for a fixed mv), + // so only the FIRST piece has to be rebuilt -- and only when + // `is_sub8x8_inter` holds, i.e. the previous strip was itself a + // single-reference inter block (`prev`), else libaom falls + // through to the ordinary whole-block predictor. ( Pred::Inline(&pred_y, side), Pred::Inline(&pred_u, chroma_stride), @@ -35679,7 +40509,6 @@ fn decode_inter_block( ) }; - // lane-inter4 r2: a rectangular strip's transform tree starts from // its own rect `max_txsize_rect_lookup` entry, not a square one. let rect_tu = (write_w, write_h) != (side, side); @@ -35691,7 +40520,8 @@ fn decode_inter_block( at_mi, (write_w, write_h), (mi_cols as usize, mi_rows as usize), - skip, fctx, + skip, + fctx, )? } else { read_block_tx_size( @@ -35702,38 +40532,45 @@ fn decode_inter_block( side, (mi_cols as usize, mi_rows as usize), true, - skip, fctx, + skip, + fctx, )? .1 }; if skip { - push_mc_rect(0, + push_mc_rect( + 0, px, py, side, write_w, write_h, sy, - &ZERO_RESIDUAL[..side * side], fctx, + &ZERO_RESIDUAL[..side * side], + fctx, ); if has_chroma { - push_mc_rect(1, + push_mc_rect( + 1, cpx, cpy, chroma_stride, write_chroma_w, write_chroma_h, su, - &ZERO_RESIDUAL[..chroma_stride * chroma_buf_h], fctx, + &ZERO_RESIDUAL[..chroma_stride * chroma_buf_h], + fctx, ); - push_mc_rect(2, + push_mc_rect( + 2, cpx, cpy, chroma_stride, write_chroma_w, write_chroma_h, sv, - &ZERO_RESIDUAL[..chroma_stride * chroma_buf_h], fctx, + &ZERO_RESIDUAL[..chroma_stride * chroma_buf_h], + fctx, ); } luma_grid = Grid::Zero(side * side); @@ -35811,8 +40648,7 @@ fn decode_inter_block( // chunk tail's chroma units can each inherit the type of the // leaf covering their own quadrant (`av1_get_tx_type`, // blockd.h:1291, scales the CHROMA 4x4 position back to luma). - let mut leaf_tx_types: Vec<(usize, usize, usize, usize, TxType)> = - Vec::new(); + let mut leaf_tx_types: Vec<(usize, usize, usize, usize, TxType)> = Vec::new(); if let Some(leaves) = vartx_leaves.as_ref() { // spec 5.11.17's transform tree, leaf by leaf in the order // `read_var_tx_size` coded it: each unit reads its own @@ -35844,7 +40680,8 @@ fn decode_inter_block( base_q_idx, tu_pred, None, - Some(tu_skip_ctx), fctx, + Some(tu_skip_ctx), + fctx, )? } else { // lane-r14 r3: a 1:4 strip's `sub_tx_size_map` @@ -35872,7 +40709,8 @@ fn decode_inter_block( tu_py, sy.offset(start), None, - Some(tu_skip_ctx), fctx, + Some(tu_skip_ctx), + fctx, )? }; if idx == 0 { @@ -35945,13 +40783,24 @@ fn decode_inter_block( // lane-lossless2: TX_4X4 units over this // chunk's chroma, not one TX_32X32 unit. read_inter_chroma_lossless( - dec, cdfs, neighbours, u, v, su, sv, - at_mi, (cpx, cpy), + dec, + cdfs, + neighbours, + u, + v, + su, + sv, + at_mi, + (cpx, cpy), (cc * chunk_chroma_w, cr * chunk_chroma_h), (chunk_chroma_w, chunk_chroma_h), (write_chroma_w, write_chroma_h), - chroma_side, mode_for_tx, base_q_idx, - &mut u_units, &mut v_units, fctx, + chroma_side, + mode_for_tx, + base_q_idx, + &mut u_units, + &mut v_units, + fctx, )?; mu_chroma = true; continue; @@ -35968,26 +40817,21 @@ fn decode_inter_block( for ur in 0..units_h { for uc in 0..units_w { let unit_mi = ( - at_mi.0 + cr * 16 - + ur * (unit_luma_h / MI), - at_mi.1 + cc * 16 - + uc * (unit_luma_w / MI), + at_mi.0 + cr * 16 + ur * (unit_luma_h / MI), + at_mi.1 + cc * 16 + uc * (unit_luma_w / MI), ); // Per unit, AFTER the earlier // units' stamps: this unit's // coefficient context must see // them. - let cu_around = neighbours - .around_mi_rect( - unit_mi, - unit_luma_w, - unit_luma_h, - ); + let cu_around = neighbours.around_mi_rect( + unit_mi, + unit_luma_w, + unit_luma_h, + ); let (cu_x, cu_y) = ( - cpx + cc * chunk_chroma_w - + uc * cu_tx, - cpy + cr * chunk_chroma_h - + ur * cu_tx, + cpx + cc * chunk_chroma_w + uc * cu_tx, + cpy + cr * chunk_chroma_h + ur * cu_tx, ); // `av1_get_tx_type` (blockd.h: // 1291): an inter block's chroma @@ -35996,26 +40840,20 @@ fn decode_inter_block( // luma leaf covering its own // quadrant (all of this chunk's // leaves are read by now). - let unit_rel_mi = ( - unit_mi.0 - at_mi.0, - unit_mi.1 - at_mi.1, - ); + let unit_rel_mi = + (unit_mi.0 - at_mi.0, unit_mi.1 - at_mi.1); let covering = leaf_tx_types .iter() .copied() // leaf (row, col) are mi but // (tw, th) are px (the rect // leaf path divides by MI too) - .find( - |&(lr, lc, lw, lh, _)| { - lr <= unit_rel_mi.0 - && unit_rel_mi.0 - < lr + lh / MI - && lc <= unit_rel_mi.1 - && unit_rel_mi.1 - < lc + lw / MI - }, - ) + .find(|&(lr, lc, lw, lh, _)| { + lr <= unit_rel_mi.0 + && unit_rel_mi.0 < lr + lh / MI + && lc <= unit_rel_mi.1 + && unit_rel_mi.1 < lc + lw / MI + }) .map(|(_, _, _, _, t)| t); // The prediction buffer is // `chroma_stride`-strided (the @@ -36023,9 +40861,7 @@ fn decode_inter_block( // 4:2:2), not the square // `chroma_side`. let cu_pred = src.offset( - (cr * chunk_chroma_h - + ur * cu_tx) - * chroma_stride + (cr * chunk_chroma_h + ur * cu_tx) * chroma_stride + cc * chunk_chroma_w + uc * cu_tx, ); @@ -36043,12 +40879,9 @@ fn decode_inter_block( cu_tx, base_q_idx, cu_pred, - Some( - covering.unwrap_or( - TxType::DctDct - ), - ), - Some(3), fctx, + Some(covering.unwrap_or(TxType::DctDct)), + Some(3), + fctx, )? .0; // Immediately, so the NEXT unit @@ -36079,18 +40912,13 @@ fn decode_inter_block( // indexes; the unit's true // per-axis position is what // changes. - let start = (cr * chunk_chroma_h - + ur * cu_tx - + rr) + let start = (cr * chunk_chroma_h + ur * cu_tx + rr) * chroma_side + cc * chunk_chroma_w + uc * cu_tx; - dst[start..start + cu_tx] - .copy_from_slice( - &cu_grid - [rr * cu_tx..] - [..cu_tx], - ); + dst[start..start + cu_tx].copy_from_slice( + &cu_grid[rr * cu_tx..][..cu_tx], + ); } } } @@ -36122,29 +40950,31 @@ fn decode_inter_block( py, sy, None, - None, fctx, + None, + fctx, )?; luma_tx_type = tx_type; luma_grid = Grid::Own(embed_rect_grid(&grid, write_w, write_h, side)); } else { { let coded = read_inter_plane( - dec, - cdfs, - luma_set_inter, - scan_luma, - 0, - around[0], - mode_for_tx, - y, - px, - py, - side, - base_q_idx, - sy, - None, - None, fctx, - )?; + dec, + cdfs, + luma_set_inter, + scan_luma, + 0, + around[0], + mode_for_tx, + y, + px, + py, + side, + base_q_idx, + sy, + None, + None, + fctx, + )?; luma_grid = coded.0; luma_tx_type = coded.1; } @@ -36177,20 +41007,41 @@ fn decode_inter_block( // (libaom `read_tx_size` + `decode_token_recon_block`). let (mut uo, mut vo) = (Vec::new(), Vec::new()); read_inter_chroma_lossless( - dec, cdfs, neighbours, u, v, su, sv, at_mi, (cpx, cpy), - (0, 0), (write_chroma_w, write_chroma_h), - (write_chroma_w, write_chroma_h), chroma_stride, - mode_for_tx, base_q_idx, &mut uo, &mut vo, fctx, + dec, + cdfs, + neighbours, + u, + v, + su, + sv, + at_mi, + (cpx, cpy), + (0, 0), + (write_chroma_w, write_chroma_h), + (write_chroma_w, write_chroma_h), + chroma_stride, + mode_for_tx, + base_q_idx, + &mut uo, + &mut vo, + fctx, )?; let zero = chroma_side * chroma_side; - u_grid = if uo.is_empty() { Grid::Zero(zero) } else { Grid::Own(uo) }; - v_grid = if vo.is_empty() { Grid::Zero(zero) } else { Grid::Own(vo) }; + u_grid = if uo.is_empty() { + Grid::Zero(zero) + } else { + Grid::Own(uo) + }; + v_grid = if vo.is_empty() { + Grid::Zero(zero) + } else { + Grid::Own(vo) + }; // Every unit stamped its own neighbour context above; the // whole-block record must not overwrite them with the // assembled grid (class `override-slot-on-one-arm`). mu_chroma = true; - } else if rect_tu - || (write_chroma_w, write_chroma_h) != (chroma_side, chroma_side) + } else if rect_tu || (write_chroma_w, write_chroma_h) != (chroma_side, chroma_side) { // One chroma read for the whole strip at 4:2:0, two // 32-capped units at 4:4:4 -- see the helper. @@ -36213,7 +41064,8 @@ fn decode_inter_block( (write_chroma_w, write_chroma_h), chroma_stride, mode_for_tx, - luma_tx_type, fctx, + luma_tx_type, + fctx, )?; } else if ss_x(fctx) == 0 && ss_y(fctx) == 0 && chroma_side > chroma_tx { // lane-av1-444: at ss 0/0 this block's chroma plane is @@ -36255,14 +41107,14 @@ fn decode_inter_block( base_q_idx, src.offset(cr * cu_tx * chroma_side + cc * cu_tx), Some(luma_tx_type), - Some(3), fctx, + Some(3), + fctx, )? .0; // Immediately, so the next unit's context sees // this one's coefficients. - neighbours.record_mi_chroma( - cu_mi, cu_tx, cu_tx, plane_idx, &cu_grid, - ); + neighbours + .record_mi_chroma(cu_mi, cu_tx, cu_tx, plane_idx, &cu_grid); hit!(CHROMA_SPLIT_TX_HITS); // lane-av1-444 c8: the unit's levels must ALSO // land in the block grid -- the block-tail mu @@ -36287,42 +41139,44 @@ fn decode_inter_block( u_grid = Grid::Own(u_acc); v_grid = Grid::Own(v_acc); } else { - u_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - scan_chroma, - 1, - around[1], - mode_for_tx, - u, - cpx, - cpy, - chroma_side, - base_q_idx, - su, - Some(luma_tx_type), - None, fctx, - )? - .0; - v_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - scan_chroma, - 2, - around[2], - mode_for_tx, - v, - cpx, - cpy, - chroma_side, - base_q_idx, - sv, - Some(luma_tx_type), - None, fctx, - )? - .0; + u_grid = read_inter_plane( + dec, + cdfs, + chroma_set, + scan_chroma, + 1, + around[1], + mode_for_tx, + u, + cpx, + cpy, + chroma_side, + base_q_idx, + su, + Some(luma_tx_type), + None, + fctx, + )? + .0; + v_grid = read_inter_plane( + dec, + cdfs, + chroma_set, + scan_chroma, + 2, + around[2], + mode_for_tx, + v, + cpx, + cpy, + chroma_side, + base_q_idx, + sv, + Some(luma_tx_type), + None, + fctx, + )? + .0; } } } @@ -36393,7 +41247,11 @@ fn decode_inter_block( if crate::envflags::env_flag!("EC_INTRA16X4") { let (idx, hc, prev_inter) = match strip_chroma { Some(s) => ( - if s.horz { rmi - s.pair_mi.0 } else { cmi - s.pair_mi.1 }, + if s.horz { + rmi - s.pair_mi.0 + } else { + cmi - s.pair_mi.1 + }, s.has_chroma, s.prev.is_some(), ), @@ -36431,7 +41289,8 @@ fn decode_inter_block( y, u, v, - base_q_idx, fctx, + base_q_idx, + fctx, )?; // merge b51719f+lane-intrarect: `at` is in MI units on this path // (lane-inter4), so the strip's mi origin is `at` itself -- the @@ -36582,20 +41441,29 @@ fn decode_inter_block( if allow_screen_content_tools && let Some(bsize_ctx) = palette_bsize_ctx_wh(write_w, write_h) { - let use_palette_y = - mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][palette_ctx]) != 0; + let use_palette_y = mode == DC_PRED + && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][palette_ctx]) != 0; if use_palette_y { let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); palette_y_pending = Some((n, read_palette_colors_y(dec, n, &palette_cache, fctx))); } if crate::envflags::env_flag!("EC_PALSYN") { - eprintln!("EC_PALSYN_PRE sq mi={rmi},{cmi} bw={write_w} bh={write_h} mode={mode} uv={uv_mode} ctx={palette_ctx} y={} rng={}", palette_y_pending.map_or(0, |(n, _)| n), dec.debug_state().0); + eprintln!( + "EC_PALSYN_PRE sq mi={rmi},{cmi} bw={write_w} bh={write_h} mode={mode} uv={uv_mode} ctx={palette_ctx} y={} rng={}", + palette_y_pending.map_or(0, |(n, _)| n), + dec.debug_state().0 + ); } let use_palette_uv = has_chroma && uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[usize::from(use_palette_y)]) != 0; if crate::envflags::env_flag!("EC_PALSYN") { - eprintln!("EC_PALSYN sq mi={rmi},{cmi} bw={write_w} bh={write_h} mode={mode} uv={uv_mode} ctx={palette_ctx} y={} uv={} rng={}", use_palette_y as i32, use_palette_uv as i32, dec.debug_state().0); + eprintln!( + "EC_PALSYN sq mi={rmi},{cmi} bw={write_w} bh={write_h} mode={mode} uv={uv_mode} ctx={palette_ctx} y={} uv={} rng={}", + use_palette_y as i32, + use_palette_uv as i32, + dec.debug_state().0 + ); } if use_palette_uv { let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]); @@ -36630,19 +41498,31 @@ fn decode_inter_block( // chroma one, after the WHOLE mode-info read. let palette_y = palette_y_pending.map(|(n, colors)| { let map = decode_color_index_map_wh( - dec, cdfs, n, write_w, write_h, - palette_onscreen(rmi, cmi, write_w, write_h, fctx), false, + dec, + cdfs, + n, + write_w, + write_h, + palette_onscreen(rmi, cmi, write_w, write_h, fctx), + false, ); hit!(PALETTE_HITS); hit!(INTRA_IN_INTER_PALETTE_Y_HITS); - PaletteY { size: n, colors, map } + PaletteY { + size: n, + colors, + map, + } }); let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { // `av1_get_plane_block_size(bsize, 1, 1)` at the sequence's own // subsampling, floored at the 4-px transform -- the rect reader's // own copy; a hardcoded `/ 2` sized a 4:4:4 chroma map at 4:2:0 // and the full-size reconstruct panicked on it (lane-av1-444). - let (cw, ch) = ((write_w >> ss_x(fctx)).max(4), (write_h >> ss_y(fctx)).max(4)); + let (cw, ch) = ( + (write_w >> ss_x(fctx)).max(4), + (write_h >> ss_y(fctx)).max(4), + ); let on = palette_onscreen_uv( (write_w, write_h), palette_onscreen(rmi, cmi, write_w, write_h, fctx), @@ -36652,7 +41532,12 @@ fn decode_inter_block( let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true); hit!(PALETTE_UV_HITS); hit!(INTRA_IN_INTER_PALETTE_UV_HITS); - PaletteUv { size: n, u_colors, v_colors, map } + PaletteUv { + size: n, + u_colors, + v_colors, + map, + } }); palette_record = ( palette_y.as_ref().map_or(0, |p| p.size), @@ -36664,8 +41549,9 @@ fn decode_inter_block( // the block edge (spec 7.11.2/7.11.4) -- these ride the [`PALETTE_PRED`] // slot into each `reconstruct`/`read_plane` call below, exactly as the // key-frame paths do. - let palette_y_buf: Option> = - palette_y.as_ref().map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()); + let palette_y_buf: Option> = palette_y + .as_ref() + .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()); let palette_uv_bufs: Option<(Vec, Vec)> = palette_uv.as_ref().map(|p| { ( p.map.iter().map(|&i| p.u_colors[i as usize]).collect(), @@ -36711,7 +41597,8 @@ fn decode_inter_block( side, (mi_cols as usize, mi_rows as usize), false, - skip, fctx, + skip, + fctx, )? .1; let reach = Reach::of(side, px, py, y.width, y.height, fctx); @@ -36747,7 +41634,8 @@ fn decode_inter_block( set_palette_pred(window, fctx); } let tu_grid = if skip { - push_intra(0, + push_intra( + 0, tu_px, tu_py, tx_px, @@ -36757,7 +41645,8 @@ fn decode_inter_block( &ZERO_RESIDUAL[..tx_px * tx_px], None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); Grid::Zero(tx_px * tx_px) } else { @@ -36789,7 +41678,8 @@ fn decode_inter_block( None, filter_intra, Some(tu_skip_ctx), - smooth_neighbor, fctx, + smooth_neighbor, + fctx, )? }; neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); @@ -36809,31 +41699,57 @@ fn decode_inter_block( let cu_around = neighbours.around_mi(cu_mi, luma_span); let (cu_x, cu_y) = (cpx + cc * cu_tx, cpy + cr * cu_tx); let cu_reach = crate::decode::tu_reach( - side, side, - cc * luma_span, cr * luma_span, luma_span, - reach, px, py, y.width, y.height, fctx, + side, + side, + cc * luma_span, + cr * luma_span, + luma_span, + reach, + px, + py, + y.width, + y.height, + fctx, ); let cu_scan = default_scan(cu_tx); if lossless(fctx) { // lane-lossless2: 8x8 TX_4X4 units per plane in this // chunk, not one TX_32X32 unit. read_intra_chroma_lossless( - dec, cdfs, neighbours, u, v, at_mi, (px, py), - (cpx, cpy), side, (chroma_side, chroma_side), - (cc * cu_tx, cr * cu_tx), (cu_tx, cu_tx), - chroma_side, reach, (y.width, y.height), mode, - uv_predict_mode, angle_delta_uv, + dec, + cdfs, + neighbours, + u, + v, + at_mi, + (px, py), + (cpx, cpy), + side, + (chroma_side, chroma_side), + (cc * cu_tx, cr * cu_tx), + (cu_tx, cu_tx), + chroma_side, + reach, + (y.width, y.height), + mode, + uv_predict_mode, + angle_delta_uv, palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])), - smooth_neighbor_uv, base_q_idx, - &mut u_units, &mut v_units, fctx, + smooth_neighbor_uv, + base_q_idx, + &mut u_units, + &mut v_units, + fctx, )?; mu_chroma = true; continue; } for plane_idx in 1..3 { - let buf: &mut PlaneBuf<'static> = if plane_idx == 1 { &mut *u } else { &mut *v }; + let buf: &mut PlaneBuf<'static> = + if plane_idx == 1 { &mut *u } else { &mut *v }; let cu_grid = if skip { - push_intra(plane_idx, + push_intra( + plane_idx, cu_x, cu_y, cu_tx, @@ -36843,7 +41759,8 @@ fn decode_inter_block( &ZERO_RESIDUAL[..cu_tx * cu_tx], None, None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); Grid::Zero(cu_tx * cu_tx) } else { @@ -36873,14 +41790,14 @@ fn decode_inter_block( // rows, +3 on the `txb_skip_chroma_32` table // (lane-sb128b r3). Some(3), - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, )? }; // Immediately, so the NEXT chunk's unit reads this // one's coefficient context. - neighbours.record_mi_chroma( - cu_mi, luma_span, luma_span, plane_idx, &cu_grid, - ); + neighbours + .record_mi_chroma(cu_mi, luma_span, luma_span, plane_idx, &cu_grid); hit!(CHROMA_SPLIT_TX_HITS); // lane-dpm1: the two INTER mu-chunk sites set this and this // INTRA-in-inter one did not, so the whole-block chroma @@ -36889,7 +41806,11 @@ fn decode_inter_block( // row libaom never selects (class `override-slot-on-one-arm`). mu_chroma = true; let dst = mu_units( - if plane_idx == 1 { &mut u_units } else { &mut v_units }, + if plane_idx == 1 { + &mut u_units + } else { + &mut v_units + }, chroma_side * chroma_side, ); for rr in 0..cu_tx { @@ -36916,22 +41837,23 @@ fn decode_inter_block( // Chroma is already coded and reconstructed per mu chunk above. luma_grid = Grid::Zero(side * side); u_grid = if u_units.is_empty() { - Grid::Zero(chroma_stride * chroma_buf_h) - } else { - Grid::Own(std::mem::take(&mut u_units)) - }; + Grid::Zero(chroma_stride * chroma_buf_h) + } else { + Grid::Own(std::mem::take(&mut u_units)) + }; v_grid = if v_units.is_empty() { - Grid::Zero(chroma_stride * chroma_buf_h) - } else { - Grid::Own(std::mem::take(&mut v_units)) - }; + Grid::Zero(chroma_stride * chroma_buf_h) + } else { + Grid::Own(std::mem::take(&mut v_units)) + }; hit!(INTRA_128_IN_INTER_HITS); } else if skip { if !split_luma { if let Some(buf) = &palette_y_buf { set_palette_pred(buf.clone(), fctx); } - push_intra(0, + push_intra( + 0, px, py, side, @@ -36941,14 +41863,16 @@ fn decode_inter_block( &ZERO_RESIDUAL[..side * side], None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); } let ac = alpha.map(|_| cfl_src(px, py, side)); if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - push_intra_unit(1, + push_intra_unit( + 1, cpx, cpy, chroma_w, @@ -36959,12 +41883,14 @@ fn decode_inter_block( &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - push_intra_unit(2, + push_intra_unit( + 2, cpx, cpy, chroma_w, @@ -36975,7 +41901,8 @@ fn decode_inter_block( &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); luma_grid = Grid::Zero(side * side); u_grid = Grid::Zero(chroma_w * chroma_h); @@ -37011,7 +41938,8 @@ fn decode_inter_block( None, filter_intra, None, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, )?; } let ac = alpha.map(|_| cfl_src(px, py, side)); @@ -37020,16 +41948,42 @@ fn decode_inter_block( // units, plane-major (`read_intra_chroma_lossless`). let (mut uo, mut vo) = (Vec::new(), Vec::new()); read_intra_chroma_lossless( - dec, cdfs, neighbours, u, v, at_mi, (px, py), (cpx, cpy), - side, (chroma_side, chroma_side), (0, 0), - (chroma_side, chroma_side), chroma_side, reach, - (y.width, y.height), mode, uv_predict_mode, angle_delta_uv, + dec, + cdfs, + neighbours, + u, + v, + at_mi, + (px, py), + (cpx, cpy), + side, + (chroma_side, chroma_side), + (0, 0), + (chroma_side, chroma_side), + chroma_side, + reach, + (y.width, y.height), + mode, + uv_predict_mode, + angle_delta_uv, palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])), - smooth_neighbor_uv, base_q_idx, &mut uo, &mut vo, fctx, + smooth_neighbor_uv, + base_q_idx, + &mut uo, + &mut vo, + fctx, )?; let zero = chroma_side * chroma_side; - u_grid = if uo.is_empty() { Grid::Zero(zero) } else { Grid::Own(uo) }; - v_grid = if vo.is_empty() { Grid::Zero(zero) } else { Grid::Own(vo) }; + u_grid = if uo.is_empty() { + Grid::Zero(zero) + } else { + Grid::Own(uo) + }; + v_grid = if vo.is_empty() { + Grid::Zero(zero) + } else { + Grid::Own(vo) + }; mu_chroma = true; } else if ss_x(fctx) == 0 && ss_y(fctx) == 0 && chroma_side > chroma_tx { // lane-av1-rect128recon: at ss 0/0 the uv plane block of a @@ -37069,7 +42023,8 @@ fn decode_inter_block( px, py, y.width, - y.height, fctx, + y.height, + fctx, ); let cu_grid = read_plane( dec, @@ -37093,15 +42048,19 @@ fn decode_inter_block( None, None, Some(3), - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, )?; // Immediately, so the NEXT unit reads this one's // coefficient context. - neighbours.record_mi_chroma( - cu_mi, chroma_tx, chroma_tx, plane_idx, &cu_grid, - ); + neighbours + .record_mi_chroma(cu_mi, chroma_tx, chroma_tx, plane_idx, &cu_grid); hit!(CHROMA_SPLIT_TX_HITS); - let acc = if plane_idx == 1 { &mut u_acc } else { &mut v_acc }; + let acc = if plane_idx == 1 { + &mut u_acc + } else { + &mut v_acc + }; for rr in 0..chroma_tx { let start = (cu_row * chroma_tx + rr) * chroma_side + cu_col * chroma_tx; @@ -37115,237 +42074,271 @@ fn decode_inter_block( u_grid = Grid::Own(u_acc); v_grid = Grid::Own(v_acc); } else { - // lane-av1-422k: the chroma plane block is (`chroma_w`, - // `chroma_h`) -- the square read above at 4:2:0/4:4:4, one rect - // TX_{side/2}X{side} unit through [`read_rect_chroma_unit`] at - // 4:2:2 (the key-frame path's proven set/scan rows, and the - // per-chroma-cell context read [`around_mi_422_chroma`]). - let chroma_around = if chroma_w == chroma_h { - around - } else { - neighbours.around_mi_422_chroma(at, side, side) - }; - if let Some((ub, _)) = &palette_uv_bufs { - set_palette_pred(ub.clone(), fctx); - } - u_grid = if chroma_w == chroma_h { - read_plane( - dec, - cdfs, - chroma_set, - scan_chroma, - 1, - chroma_around[1], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - u, - cpx, - cpy, - chroma_side, - chroma_tx, - base_q_idx, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )? - } else if side == 64 { - // lane-av1-422inter: `av1_get_max_uv_txsize(BLOCK_64X64)` at - // ss (1,0) adjusts `max_txsize_rect_lookup[BLOCK_32X64]` = - // TX_32X64 down to TX_32X32 (`av1_get_adjusted_tx_size`), so - // the (side/2, side) = (32, 64) plane block codes TWO stacked - // SQUARE TX_32X32 units per plane, plane-major -- the - // key-frame path's own model (`decode_block`'s 4:2:2 - // chroma_tx table, "64 and 128: TX_32X64 / TX_64X64 adjust - // down to TX_32X32", proven byte-exact on this fixture's - // frame 0) and the twin of this function's own side>64 - // mu-chunk walk above. The whole-plane-block rect read this - // arm replaced handed [`read_coeffs_rect`] a 36x68 levels - // frame it never had (the frame-9 panic) and would have read - // a full TX_32X64 scan libaom never codes. - let cu_scan = default_scan(32); - let (cu_w, cu_h) = (32usize, 32usize); - let luma_span_x = cu_w << ss_x(fctx); - let luma_span_y = cu_h << ss_y(fctx); - let mut assembled = vec![0i32; chroma_side * chroma_side]; - for cu_row in 0..chroma_h / cu_h { - let cu_mi = (at_mi.0 + cu_row * (luma_span_y / MI), at_mi.1); - let cu_around = - neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y); - let cu_reach = tu_reach_rect( - side, - side, - 0, - cu_row * luma_span_y, - luma_span_x, - luma_span_y, - reach, - px, - py, - y.width, - y.height, fctx, - ); - let cu_grid = read_plane( + // lane-av1-422k: the chroma plane block is (`chroma_w`, + // `chroma_h`) -- the square read above at 4:2:0/4:4:4, one rect + // TX_{side/2}X{side} unit through [`read_rect_chroma_unit`] at + // 4:2:2 (the key-frame path's proven set/scan rows, and the + // per-chroma-cell context read [`around_mi_422_chroma`]). + let chroma_around = if chroma_w == chroma_h { + around + } else { + neighbours.around_mi_422_chroma(at, side, side) + }; + if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone(), fctx); + } + u_grid = if chroma_w == chroma_h { + read_plane( dec, cdfs, - TxbSet::Chroma32, - &cu_scan, + chroma_set, + scan_chroma, 1, - cu_around[1], + chroma_around[1], mode, uv_predict_mode, angle_delta_uv, - cu_reach, + reach, u, cpx, - cpy + cu_row * cu_h, - cu_w, - cu_w, + cpy, + chroma_side, + chroma_tx, base_q_idx, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, - // The uv plane block (32x64) is larger than the unit - // (32x32): `get_txb_ctx`'s offset-10 rows, +3 on the - // `txb_skip_chroma_32` table (lane-sb128b r3). - Some(3), - smooth_neighbor_uv, fctx, - )?; - hit!(CHROMA_SPLIT_TX_HITS); - hit!(CHROMA422_SQUARE_HITS); - // Immediately, so the next unit of this plane reads this - // one's coefficient context; the whole-block record below - // re-stamps the block over these and the tail's - // `mu_chroma_units` replay puts the per-unit state back - // (lane-dpm1). - neighbours.record_mi_chroma(cu_mi, luma_span_x, luma_span_y, 1, &cu_grid); - for rr in 0..cu_h { - let start = (cu_row * cu_h + rr) * chroma_side; - assembled[start..start + cu_w] - .copy_from_slice(&cu_grid[rr * cu_w..][..cu_w]); + None, + smooth_neighbor_uv, + fctx, + )? + } else if side == 64 { + // lane-av1-422inter: `av1_get_max_uv_txsize(BLOCK_64X64)` at + // ss (1,0) adjusts `max_txsize_rect_lookup[BLOCK_32X64]` = + // TX_32X64 down to TX_32X32 (`av1_get_adjusted_tx_size`), so + // the (side/2, side) = (32, 64) plane block codes TWO stacked + // SQUARE TX_32X32 units per plane, plane-major -- the + // key-frame path's own model (`decode_block`'s 4:2:2 + // chroma_tx table, "64 and 128: TX_32X64 / TX_64X64 adjust + // down to TX_32X32", proven byte-exact on this fixture's + // frame 0) and the twin of this function's own side>64 + // mu-chunk walk above. The whole-plane-block rect read this + // arm replaced handed [`read_coeffs_rect`] a 36x68 levels + // frame it never had (the frame-9 panic) and would have read + // a full TX_32X64 scan libaom never codes. + let cu_scan = default_scan(32); + let (cu_w, cu_h) = (32usize, 32usize); + let luma_span_x = cu_w << ss_x(fctx); + let luma_span_y = cu_h << ss_y(fctx); + let mut assembled = vec![0i32; chroma_side * chroma_side]; + for cu_row in 0..chroma_h / cu_h { + let cu_mi = (at_mi.0 + cu_row * (luma_span_y / MI), at_mi.1); + let cu_around = + neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y); + let cu_reach = tu_reach_rect( + side, + side, + 0, + cu_row * luma_span_y, + luma_span_x, + luma_span_y, + reach, + px, + py, + y.width, + y.height, + fctx, + ); + let cu_grid = read_plane( + dec, + cdfs, + TxbSet::Chroma32, + &cu_scan, + 1, + cu_around[1], + mode, + uv_predict_mode, + angle_delta_uv, + cu_reach, + u, + cpx, + cpy + cu_row * cu_h, + cu_w, + cu_w, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + // The uv plane block (32x64) is larger than the unit + // (32x32): `get_txb_ctx`'s offset-10 rows, +3 on the + // `txb_skip_chroma_32` table (lane-sb128b r3). + Some(3), + smooth_neighbor_uv, + fctx, + )?; + hit!(CHROMA_SPLIT_TX_HITS); + hit!(CHROMA422_SQUARE_HITS); + // Immediately, so the next unit of this plane reads this + // one's coefficient context; the whole-block record below + // re-stamps the block over these and the tail's + // `mu_chroma_units` replay puts the per-unit state back + // (lane-dpm1). + neighbours.record_mi_chroma(cu_mi, luma_span_x, luma_span_y, 1, &cu_grid); + for rr in 0..cu_h { + let start = (cu_row * cu_h + rr) * chroma_side; + assembled[start..start + cu_w] + .copy_from_slice(&cu_grid[rr * cu_w..][..cu_w]); + } } - } - mu_chroma = true; - Grid::Own(assembled) - } else { - let (rect_set, rect_scan): (TxbSet, &[u16]) = match side { - 4 => (TxbSet::Chroma4, default_scan(4)), - 8 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), - 16 => (TxbSet::ChromaRect16x8, &SCAN_8X16[..]), - 32 => (TxbSet::ChromaRect32x16, &SCAN_16X32[..]), - _ => (TxbSet::Chroma32, default_scan(32)), - }; - read_rect_chroma_unit( - dec, cdfs, rect_set, rect_scan, chroma_w, chroma_h, 1, - chroma_around[1], uv_predict_mode, angle_delta_uv, reach, u, - cpx, cpy, base_q_idx, None, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - smooth_neighbor_uv, fctx, - )? - }; - if let Some((_, vb)) = &palette_uv_bufs { - set_palette_pred(vb.clone(), fctx); - } - v_grid = if chroma_w == chroma_h { - read_plane( - dec, - cdfs, - chroma_set, - scan_chroma, - 2, - chroma_around[2], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - v, - cpx, - cpy, - chroma_side, - chroma_tx, - base_q_idx, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )? - } else if side == 64 { - // lane-av1-422inter: plane 2 of the TX_32X32-adjusted walk - // above -- same two stacked square units, plane-major (every - // U unit, then every V unit, libaom `decode_token_recon_block`'s - // per-mu-chunk plane loop). - let cu_scan = default_scan(32); - let (cu_w, cu_h) = (32usize, 32usize); - let luma_span_x = cu_w << ss_x(fctx); - let luma_span_y = cu_h << ss_y(fctx); - let mut assembled = vec![0i32; chroma_side * chroma_side]; - for cu_row in 0..chroma_h / cu_h { - let cu_mi = (at_mi.0 + cu_row * (luma_span_y / MI), at_mi.1); - let cu_around = - neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y); - let cu_reach = tu_reach_rect( - side, - side, - 0, - cu_row * luma_span_y, - luma_span_x, - luma_span_y, + mu_chroma = true; + Grid::Own(assembled) + } else { + let (rect_set, rect_scan): (TxbSet, &[u16]) = match side { + 4 => (TxbSet::Chroma4, default_scan(4)), + 8 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), + 16 => (TxbSet::ChromaRect16x8, &SCAN_8X16[..]), + 32 => (TxbSet::ChromaRect32x16, &SCAN_16X32[..]), + _ => (TxbSet::Chroma32, default_scan(32)), + }; + read_rect_chroma_unit( + dec, + cdfs, + rect_set, + rect_scan, + chroma_w, + chroma_h, + 1, + chroma_around[1], + uv_predict_mode, + angle_delta_uv, reach, - px, - py, - y.width, - y.height, fctx, - ); - let cu_grid = read_plane( + u, + cpx, + cpy, + base_q_idx, + None, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + smooth_neighbor_uv, + fctx, + )? + }; + if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone(), fctx); + } + v_grid = if chroma_w == chroma_h { + read_plane( dec, cdfs, - TxbSet::Chroma32, - &cu_scan, + chroma_set, + scan_chroma, 2, - cu_around[2], + chroma_around[2], mode, uv_predict_mode, angle_delta_uv, - cu_reach, + reach, v, cpx, - cpy + cu_row * cu_h, - cu_w, - cu_w, + cpy, + chroma_side, + chroma_tx, base_q_idx, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, - Some(3), - smooth_neighbor_uv, fctx, - )?; - hit!(CHROMA_SPLIT_TX_HITS); - hit!(CHROMA422_SQUARE_HITS); - neighbours.record_mi_chroma(cu_mi, luma_span_x, luma_span_y, 2, &cu_grid); - for rr in 0..cu_h { - let start = (cu_row * cu_h + rr) * chroma_side; - assembled[start..start + cu_w] - .copy_from_slice(&cu_grid[rr * cu_w..][..cu_w]); + None, + smooth_neighbor_uv, + fctx, + )? + } else if side == 64 { + // lane-av1-422inter: plane 2 of the TX_32X32-adjusted walk + // above -- same two stacked square units, plane-major (every + // U unit, then every V unit, libaom `decode_token_recon_block`'s + // per-mu-chunk plane loop). + let cu_scan = default_scan(32); + let (cu_w, cu_h) = (32usize, 32usize); + let luma_span_x = cu_w << ss_x(fctx); + let luma_span_y = cu_h << ss_y(fctx); + let mut assembled = vec![0i32; chroma_side * chroma_side]; + for cu_row in 0..chroma_h / cu_h { + let cu_mi = (at_mi.0 + cu_row * (luma_span_y / MI), at_mi.1); + let cu_around = + neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y); + let cu_reach = tu_reach_rect( + side, + side, + 0, + cu_row * luma_span_y, + luma_span_x, + luma_span_y, + reach, + px, + py, + y.width, + y.height, + fctx, + ); + let cu_grid = read_plane( + dec, + cdfs, + TxbSet::Chroma32, + &cu_scan, + 2, + cu_around[2], + mode, + uv_predict_mode, + angle_delta_uv, + cu_reach, + v, + cpx, + cpy + cu_row * cu_h, + cu_w, + cu_w, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + Some(3), + smooth_neighbor_uv, + fctx, + )?; + hit!(CHROMA_SPLIT_TX_HITS); + hit!(CHROMA422_SQUARE_HITS); + neighbours.record_mi_chroma(cu_mi, luma_span_x, luma_span_y, 2, &cu_grid); + for rr in 0..cu_h { + let start = (cu_row * cu_h + rr) * chroma_side; + assembled[start..start + cu_w] + .copy_from_slice(&cu_grid[rr * cu_w..][..cu_w]); + } } - } - mu_chroma = true; - Grid::Own(assembled) - } else { - let (rect_set, rect_scan): (TxbSet, &[u16]) = match side { - 4 => (TxbSet::Chroma4, default_scan(4)), - 8 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), - 16 => (TxbSet::ChromaRect16x8, &SCAN_8X16[..]), - 32 => (TxbSet::ChromaRect32x16, &SCAN_16X32[..]), - _ => (TxbSet::Chroma32, default_scan(32)), + mu_chroma = true; + Grid::Own(assembled) + } else { + let (rect_set, rect_scan): (TxbSet, &[u16]) = match side { + 4 => (TxbSet::Chroma4, default_scan(4)), + 8 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), + 16 => (TxbSet::ChromaRect16x8, &SCAN_8X16[..]), + 32 => (TxbSet::ChromaRect32x16, &SCAN_16X32[..]), + _ => (TxbSet::Chroma32, default_scan(32)), + }; + read_rect_chroma_unit( + dec, + cdfs, + rect_set, + rect_scan, + chroma_w, + chroma_h, + 2, + chroma_around[2], + uv_predict_mode, + angle_delta_uv, + reach, + v, + cpx, + cpy, + base_q_idx, + None, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + smooth_neighbor_uv, + fctx, + )? }; - read_rect_chroma_unit( - dec, cdfs, rect_set, rect_scan, chroma_w, chroma_h, 2, - chroma_around[2], uv_predict_mode, angle_delta_uv, reach, v, - cpx, cpy, base_q_idx, None, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - smooth_neighbor_uv, fctx, - )? - }; } } } @@ -37358,7 +42351,10 @@ fn decode_inter_block( if crate::envflags::env_flag!("EC_AV1_TELL") { eprintln!( "TELL mi_row={} mi_col={} label=block_end tell={} range={}", - rmi, cmi, dec.debug_bitpos(), dec.debug_state().0 + rmi, + cmi, + dec.debug_bitpos(), + dec.debug_state().0 ); } // lane-inter16ab r2: the pair's chroma coefficient context spans BOTH @@ -37441,7 +42437,10 @@ fn decode_inter_block( // quadrant of the assembled plane grid; stamping one quadrant's // state over the whole chunk desynced the next block's // `txb_skip_ctx` (f52 mi(52,16) U read base 0, aom 1). - let (ur, uc) = (((64usize) >> ss_y(fctx)) / cu, ((64usize) >> ss_x(fctx)) / cu); + let (ur, uc) = ( + ((64usize) >> ss_y(fctx)) / cu, + ((64usize) >> ss_x(fctx)) / cu, + ); let (rows, cols) = ((write_h / 64).max(1), (write_w / 64).max(1)); for cr in 0..rows { for cc in 0..cols { @@ -37557,7 +42556,14 @@ fn decode_inter_block( // root's HORZ/VERT arm decodes 128x64 / 64x128 var-tx blocks), and // `side` there stamped `above_side`/`left_side` = 128, so the NEXT // superblock's 128-root partition context read 16 where libaom reads 19. - neighbours.record_split_luma_rect_mi(at, write_w, write_h, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]); + neighbours.record_split_luma_rect_mi( + at, + write_w, + write_h, + mode_for_tx, + uv_predict_mode, + [&u_grid, &v_grid], + ); } else { neighbours.record_rect_mi( at, @@ -37643,14 +42649,16 @@ fn decode_inter_block( skip_mode, ); if let Some((ref1, group_idx, idx)) = compound_ctx { - neighbours.record_compound_ctx_rect_mi(at, write_w / MI, write_h / MI, ref1, group_idx, idx); + neighbours.record_compound_ctx_rect_mi( + at, + write_w / MI, + write_h / MI, + ref1, + group_idx, + idx, + ); } - neighbours.fill_skip_grid_rect( - (rmi, cmi), - write_w / MI, - write_h / MI, - skip, - ); + neighbours.fill_skip_grid_rect((rmi, cmi), write_w / MI, write_h / MI, skip); neighbours.fill_lf_grid_rect( (rmi, cmi), write_w / MI, @@ -37666,7 +42674,8 @@ fn decode_inter_block( -ref_frame_for_lf } else { ref_frame_for_lf - }, fctx, + }, + fctx, ); // lane-txselect: a var-tx block's deblock edges follow its own transform // units, not the block -- for LUMA only (lane-golomb r6): the chroma @@ -37757,7 +42766,8 @@ fn decode_inter_sub8_split4( enable_dual_filter: bool, tpl_frame: Option<&TplFrameArgs>, reduced_tx_set: bool, - frame_width: usize, fctx: &crate::decode::FrameCtx, + frame_width: usize, + fctx: &crate::decode::FrameCtx, ) -> Result<()> { const LAST_FRAME: i8 = 1; const B4: usize = 4; @@ -37807,17 +42817,19 @@ fn decode_inter_sub8_split4( let (px, py) = (cmi * MI, rmi * MI); inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, false, true, fctx); // No `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_4X4)` is false. - let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); + let skip_ctx = + usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; - let ec_skip_post = if std::env::var_os("EC_DBG_SUB8").is_some() { Some(dec.debug_state().0) } else { None }; + let ec_skip_post = if std::env::var_os("EC_DBG_SUB8").is_some() { + Some(dec.debug_state().0) + } else { + None + }; inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, skip, false, fctx); maybe_read_cdef_idx(dec, rmi, cmi, (2, 2), skip, fctx); maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip, fctx); maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip, fctx); - let (has_above, has_left) = ( - rmi > neighbours.tile_row0_mi, - cmi > neighbours.tile_col0_mi, - ); + let (has_above, has_left) = (rmi > neighbours.tile_row0_mi, cmi > neighbours.tile_col0_mi); let ii_ctx = intra_inter_ctx( has_above, has_left, @@ -37826,7 +42838,11 @@ fn decode_inter_sub8_split4( ); let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; if std::env::var_os("EC_DBG_SUB8").is_some() { - eprintln!("EC_DBG piece mi=({rmi},{cmi}) skip={skip} skipctx={skip_ctx} skip_post={:?} is_inter={is_inter} iictx={ii_ctx} post={}", ec_skip_post, dec.debug_state().0); + eprintln!( + "EC_DBG piece mi=({rmi},{cmi}) skip={skip} skipctx={skip_ctx} skip_post={:?} is_inter={is_inter} iictx={ii_ctx} post={}", + ec_skip_post, + dec.debug_state().0 + ); } if !is_inter { if crate::envflags::env_flag!("EC_SUB8INTRA") { @@ -37869,7 +42885,8 @@ fn decode_inter_sub8_split4( base_q_idx, fctx.enable_filter_intra_inter.with(std::cell::Cell::get), fctx.tx_select_inter.with(std::cell::Cell::get), - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )?; if i == 3 { intra_chroma = true; @@ -37937,7 +42954,9 @@ fn decode_inter_sub8_split4( tpl, ); let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; - if !not_new { crate::census::mode(0); } + if !not_new { + crate::census::mode(0); + } let mut is_globalmv = false; let (mv, is_new_mv) = if !not_new { let mut idx = 0usize; @@ -37961,7 +42980,9 @@ fn decode_inter_sub8_split4( ) } else { let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; - if !not_zero { crate::census::mode(1); } + if !not_zero { + crate::census::mode(1); + } is_globalmv = !not_zero; let mv = if !not_zero { gm_table[(ref_frame - LAST_FRAME) as usize] @@ -38091,14 +43112,19 @@ fn decode_inter_sub8_split4( B4, h_filter, v_filter, - &mut pred_y, fctx, + &mut pred_y, + fctx, ); out[0] = pred_y; }; let pred_y: Vec; let sy = if recon_deferred(fctx) { push_pred(fctx, build); - Pred::Cur { plane: 0, stride: B4, off: 0 } + Pred::Cur { + plane: 0, + stride: B4, + off: 0, + } } else { let mut built: [Vec; 3] = Default::default(); build(y, u, v, fctx, &mut built); @@ -38134,7 +43160,8 @@ fn decode_inter_sub8_split4( base_q_idx, sy, None, - None, fctx, + None, + fctx, )?; piece_tx_type = tx_type; if i == 0 { @@ -38193,7 +43220,8 @@ fn decode_inter_sub8_split4( B4, pc_hf, pc_vf, - &mut buf, fctx, + &mut buf, + fctx, ); dst.copy_from_slice(&buf); } @@ -38204,8 +43232,16 @@ fn decode_inter_sub8_split4( let (su, sv) = if recon_deferred(fctx) { push_pred(fctx, build_c); ( - Pred::Cur { plane: 1, stride: B4, off: 0 }, - Pred::Cur { plane: 2, stride: B4, off: 0 }, + Pred::Cur { + plane: 1, + stride: B4, + off: 0, + }, + Pred::Cur { + plane: 2, + stride: B4, + off: 0, + }, ) } else { let mut built: [Vec; 3] = Default::default(); @@ -38222,12 +43258,40 @@ fn decode_inter_sub8_split4( } else { let ca = neighbours.around_mi(lmi, B4); let (ug, _) = read_inter_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, ca[1], 0, u, px, py, B4, base_q_idx, - su, Some(piece_tx_type), None, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + ca[1], + 0, + u, + px, + py, + B4, + base_q_idx, + su, + Some(piece_tx_type), + None, + fctx, )?; let (vg, _) = read_inter_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, ca[2], 0, v, px, py, B4, base_q_idx, - sv, Some(piece_tx_type), None, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + ca[2], + 0, + v, + px, + py, + B4, + base_q_idx, + sv, + Some(piece_tx_type), + None, + fctx, )?; neighbours.record_mi_chroma(lmi, B4, B4, 1, &ug); neighbours.record_mi_chroma(lmi, B4, B4, 2, &vg); @@ -38272,9 +43336,7 @@ fn decode_inter_sub8_split4( // is an inter piece (`is_sub8x8_inter`'s `mi[-1]` probe). let left = piece_left .as_ref() - .map(|&(l_ref, l_mv, l_hf, l_vf)| { - (l_ref, l_mv, l_hf, l_vf) - }) + .map(|&(l_ref, l_mv, l_hf, l_vf)| (l_ref, l_mv, l_hf, l_vf)) .and_then(|(l_ref, l_mv, l_hf, l_vf)| { ref_planes_deferred(l_ref, refpix).map(|planes| { let (lp_y, _, _) = planes; @@ -38284,8 +43346,9 @@ fn decode_inter_sub8_split4( }); let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4); let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4); - for (pi, (plane, dst)) in - [(sref_u, &mut pred_u), (sref_v, &mut pred_v)].into_iter().enumerate() + for (pi, (plane, dst)) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] + .into_iter() + .enumerate() { let mut buf = vec![0u16; B4 * B4]; // Right 2x4 half: this piece's own ref/mv/filters. @@ -38302,7 +43365,8 @@ fn decode_inter_sub8_split4( 4, pc_hf, pc_vf, - &mut half, fctx, + &mut half, + fctx, ); for row in 0..4 { buf[row * B4 + 2..row * B4 + 4] @@ -38343,7 +43407,8 @@ fn decode_inter_sub8_split4( 4, l_hf, l_vf, - &mut half, fctx, + &mut half, + fctx, ); for row in 0..4 { buf[row * B4..row * B4 + 2].copy_from_slice(&half[row * 2..row * 2 + 2]); @@ -38357,8 +43422,16 @@ fn decode_inter_sub8_split4( let (su, sv) = if recon_deferred(fctx) { push_pred(fctx, build_c); ( - Pred::Cur { plane: 1, stride: B4, off: 0 }, - Pred::Cur { plane: 2, stride: B4, off: 0 }, + Pred::Cur { + plane: 1, + stride: B4, + off: 0, + }, + Pred::Cur { + plane: 2, + stride: B4, + off: 0, + }, ) } else { let mut built: [Vec; 3] = Default::default(); @@ -38380,12 +43453,40 @@ fn decode_inter_sub8_split4( } else { hit!(CHROMA422_INTER_SUB8_HITS); let (ug, _) = read_inter_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, ca[1], 0, u, unit_x, unit_y, B4, - base_q_idx, su, Some(piece_tx_type), None, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + ca[1], + 0, + u, + unit_x, + unit_y, + B4, + base_q_idx, + su, + Some(piece_tx_type), + None, + fctx, )?; let (vg, _) = read_inter_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, ca[2], 0, v, unit_x, unit_y, B4, - base_q_idx, sv, Some(piece_tx_type), None, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + ca[2], + 0, + v, + unit_x, + unit_y, + B4, + base_q_idx, + sv, + Some(piece_tx_type), + None, + fctx, )?; neighbours.record_mi_chroma(ctx_mi, 8, 4, 1, &ug); neighbours.record_mi_chroma(ctx_mi, 8, 4, 2, &vg); @@ -38400,7 +43501,15 @@ fn decode_inter_sub8_split4( // var-tx context instead of leaving whatever the previous block left. set_txfm_ctxs(neighbours, lmi, B4, 1, 1, false); neighbours.fill_skip_grid_rect(lmi, 1, 1, skip); - neighbours.fill_lf_grid_rect(lmi, 1, 1, B4 as u8, B4 as u8, ref_frame.max(LAST_FRAME), fctx); + neighbours.fill_lf_grid_rect( + lmi, + 1, + 1, + B4 as u8, + B4 as u8, + ref_frame.max(LAST_FRAME), + fctx, + ); last_skip = skip; } // lane-av1-444: when the chroma-reference sub-block was INTRA it coded @@ -38503,7 +43612,8 @@ fn decode_inter_sub8_split4( ph, h_filter, v_filter, - &mut buf, fctx, + &mut buf, + fctx, ); for row in 0..ph { for col in 0..pw { @@ -38519,8 +43629,16 @@ fn decode_inter_sub8_split4( let (su, sv) = if recon_deferred(fctx) { push_pred(fctx, build); ( - Pred::Cur { plane: 1, stride: B4, off: 0 }, - Pred::Cur { plane: 2, stride: B4, off: 0 }, + Pred::Cur { + plane: 1, + stride: B4, + off: 0, + }, + Pred::Cur { + plane: 2, + stride: B4, + off: 0, + }, ) } else { let mut built: [Vec; 3] = Default::default(); @@ -38536,13 +43654,41 @@ fn decode_inter_sub8_split4( } else { let around = neighbours.around_mi(group_mi, 8); let ug = read_inter_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx, - su, Some(first_tx_type), None, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + around[1], + 0, + u, + cpx, + cpy, + B4, + base_q_idx, + su, + Some(first_tx_type), + None, + fctx, )? .0; let vg = read_inter_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx, - sv, Some(first_tx_type), None, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + around[2], + 0, + v, + cpx, + cpy, + B4, + base_q_idx, + sv, + Some(first_tx_type), + None, + fctx, )? .0; let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0); @@ -38610,7 +43756,8 @@ fn decode_intra_sub8_leaf( base_q_idx: u8, enable_filter_intra: bool, tx_select: bool, - reduced_tx_set: bool, fctx: &crate::decode::FrameCtx, + reduced_tx_set: bool, + fctx: &crate::decode::FrameCtx, ) -> Result { // lane-av1mono: a monochrome leaf codes no chroma mode (libaom // `decodemv.c:933`). @@ -38620,9 +43767,7 @@ fn decode_intra_sub8_leaf( let (gr, gc) = group_mi; let (r, c) = (gr / (SUB / MI), gc / (SUB / MI)); let (above_mode, left_mode) = neighbours.modes_above_left(r, c); - let leaf_above = neighbours - .mode_above_mi(lmi.0, lmi.1) - .unwrap_or(above_mode); + let leaf_above = neighbours.mode_above_mi(lmi.0, lmi.1).unwrap_or(above_mode); let leaf_left = neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode); let step = crate::envflags::env_flag!("EC_TRACE_MODE_STEP"); // `size_group_lookup[BLOCK_8X4] == size_group_lookup[BLOCK_4X8] == 0` @@ -38772,13 +43917,24 @@ fn decode_intra_sub8_leaf( px, py, y.width, - y.height, fctx, + y.height, + fctx, ); if skip { let zeros = vec![0i32; 16]; - push_intra(0, - tu_px, tu_py, 4, mode, angle_delta_y, tu_reach, &zeros, None, filter_intra, - smooth_neighbor, fctx, + push_intra( + 0, + tu_px, + tu_py, + 4, + mode, + angle_delta_y, + tu_reach, + &zeros, + None, + filter_intra, + smooth_neighbor, + fctx, ); neighbours.record_mi_luma(tu_mi, 4, &zeros); continue; @@ -38809,7 +43965,8 @@ fn decode_intra_sub8_leaf( None, filter_intra, Some(tu_skip_ctx), - smooth_neighbor, fctx, + smooth_neighbor, + fctx, )?; neighbours.record_mi_luma(tu_mi, 4, &tu_grid); } @@ -38818,9 +43975,19 @@ fn decode_intra_sub8_leaf( // fixes `txb_skip_ctx` at 0 (`luma_skip_ctx: None`) -- the same square // reader [`decode_leaf_split4`] uses. if skip { - push_intra(0, - px, py, 4, mode, angle_delta_y, reach, &ZERO_RESIDUAL[..16], None, filter_intra, - smooth_neighbor, fctx, + push_intra( + 0, + px, + py, + 4, + mode, + angle_delta_y, + reach, + &ZERO_RESIDUAL[..16], + None, + filter_intra, + smooth_neighbor, + fctx, ); neighbours.record_mi_luma(lmi, 4, &ZERO_RESIDUAL[..16]); } else { @@ -38849,16 +44016,28 @@ fn decode_intra_sub8_leaf( None, filter_intra, None, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, )?; neighbours.record_mi_luma(lmi, 4, &tu_grid); } } else { let grid_levels = if skip { let zeros = Grid::Zero(bw * bh); - push_intra_rect(0, - px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra, - smooth_neighbor, fctx, + push_intra_rect( + 0, + px, + py, + bw, + bh, + mode, + angle_delta_y, + reach, + &zeros, + None, + filter_intra, + smooth_neighbor, + fctx, ); zeros } else { @@ -38892,11 +44071,22 @@ fn decode_intra_sub8_leaf( plane_q_delta(0, fctx).0, plane_q_delta(0, fctx).1, tx_type, - block_iqmatrix(fctx, 0, bw, bh, tx_type), + block_iqmatrix(fctx, 0, bw, bh, tx_type), ); - push_intra_rect(0, - px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra, - smooth_neighbor, fctx, + push_intra_rect( + 0, + px, + py, + bw, + bh, + mode, + angle_delta_y, + reach, + &residual, + None, + filter_intra, + smooth_neighbor, + fctx, ); levels }; @@ -39000,10 +44190,23 @@ fn decode_intra_sub8_leaf( // `None` here. if ss_x(fctx) == 1 && ss_y(fctx) == 0 { sub8_leaf_chroma422( - dec, cdfs, neighbours, lmi, uv_mode, 0, alpha, skip, - None, y, u, v, scan4, base_q_idx, + dec, + cdfs, + neighbours, + lmi, + uv_mode, + 0, + alpha, + skip, + None, + y, + u, + v, + scan4, + base_q_idx, neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), - (bw, bh), fctx, + (bw, bh), + fctx, )?; return Ok(mode); } @@ -39037,9 +44240,18 @@ fn decode_intra_sub8_leaf( } else { (r, c) }; - let smooth_neighbor_uv = - neighbours.smooth_uv_neighbour(if chroma_444 { lmi.0 } else { gr }, if chroma_444 { lmi.1 } else { gc }, band_r, band_c, fctx); - let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour( + if chroma_444 { lmi.0 } else { gr }, + if chroma_444 { lmi.1 } else { gc }, + band_r, + band_c, + fctx, + ); + let uv_predict_mode = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; let angle_delta_uv = 0; neighbours.above_uv_mode[band_c] = uv_predict_mode; neighbours.left_uv_mode[band_r] = uv_predict_mode; @@ -39049,7 +44261,13 @@ fn decode_intra_sub8_leaf( neighbours.record_uv_mode_mi(gr, gc, 2, 2, uv_predict_mode); } - let ac = alpha.map(|_| if chroma_444 { cfl_src_rect(px, py, bw, bh) } else { cfl_src(gpx, gpy, 8) }); + let ac = alpha.map(|_| { + if chroma_444 { + cfl_src_rect(px, py, bw, bh) + } else { + cfl_src(gpx, gpy, 8) + } + }); let mut chroma_stamped_per_unit = false; let (u_grid, v_grid): (Grid, Grid) = if skip { if alpha.is_some() { @@ -39058,12 +44276,66 @@ fn decode_intra_sub8_leaf( } if chroma_444 && bw != bh { let zeros = Grid::Zero(bw * bh); - push_intra_rect(1, unit_x, unit_y, bw, bh, uv_predict_mode, angle_delta_uv, reach_c, &zeros, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); - push_intra_rect(2, unit_x, unit_y, bw, bh, uv_predict_mode, angle_delta_uv, reach_c, &zeros, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); + push_intra_rect( + 1, + unit_x, + unit_y, + bw, + bh, + uv_predict_mode, + angle_delta_uv, + reach_c, + &zeros, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + fctx, + ); + push_intra_rect( + 2, + unit_x, + unit_y, + bw, + bh, + uv_predict_mode, + angle_delta_uv, + reach_c, + &zeros, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + fctx, + ); (zeros, Grid::Zero(bw * bh)) } else { - push_intra(1, unit_x, unit_y, 4, uv_predict_mode, angle_delta_uv, reach_c, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); - push_intra(2, unit_x, unit_y, 4, uv_predict_mode, angle_delta_uv, reach_c, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); + push_intra( + 1, + unit_x, + unit_y, + 4, + uv_predict_mode, + angle_delta_uv, + reach_c, + &ZERO_RESIDUAL[..16], + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + fctx, + ); + push_intra( + 2, + unit_x, + unit_y, + 4, + uv_predict_mode, + angle_delta_uv, + reach_c, + &ZERO_RESIDUAL[..16], + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + fctx, + ); (Grid::Zero(16), Grid::Zero(16)) } } else if chroma_444 && bw != bh { @@ -39093,18 +44365,8 @@ fn decode_intra_sub8_leaf( // At 4:4:4 a TX_4X4 chroma unit IS one mi cell. let tu_mi = (lmi.0 + oy / MI, lmi.1 + ox / MI); let tu_around = neighbours.around_mi(tu_mi, MI); - let tu_r = tu_reach( - bw, - bh, - ox, - oy, - 4, - reach_c, - px, - py, - y.width, - y.height, fctx, - ); + let tu_r = + tu_reach(bw, bh, ox, oy, 4, reach_c, px, py, y.width, y.height, fctx); let buf: &mut PlaneBuf<'static> = if plane_idx == 1 { &mut *u } else { &mut *v }; // The plane block (8x4/4x8) is bigger than the TX_4X4 @@ -39132,17 +44394,15 @@ fn decode_intra_sub8_leaf( None, None, Some(3), - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, )?; // The unit's own coefficient context, stamped per unit // (`av1_set_contexts`); the tail's whole-leaf chroma // stamp below is skipped for this shape. neighbours.record_mi_chroma(tu_mi, 4, 4, plane_idx, &tu_grid); hit!(CHROMA_SPLIT_TX_HITS); - let dst = mu_units( - if plane_idx == 1 { &mut uo } else { &mut vo }, - bw * bh, - ); + let dst = mu_units(if plane_idx == 1 { &mut uo } else { &mut vo }, bw * bh); for row in 0..4 { let start = (oy + row) * bw + ox; dst[start..start + 4].copy_from_slice(&tu_grid[row * 4..][..4]); @@ -39152,60 +44412,121 @@ fn decode_intra_sub8_leaf( chroma_stamped_per_unit = true; hit!(LLSUB8RECT444_CHROMA_WALK_HITS); ( - if uo.is_empty() { Grid::Zero(bw * bh) } else { Grid::Own(uo) }, - if vo.is_empty() { Grid::Zero(bw * bh) } else { Grid::Own(vo) }, + if uo.is_empty() { + Grid::Zero(bw * bh) + } else { + Grid::Own(uo) + }, + if vo.is_empty() { + Grid::Zero(bw * bh) + } else { + Grid::Own(vo) + }, ) } else { - // The leaf's own TX_8X4/TX_4X8 chroma unit: it IS the chroma plane - // block, so `get_txb_ctx` fixes the skip context at above+left. - let ca = neighbours.around_mi_rect(lmi, bw, bh); - let scan_c: &[u16] = if vert { &SCAN_4X8 } else { &SCAN_8X4 }; - let uv_tx = default_intra_tx_type(uv_predict_mode as u8); - let mut read_chroma = |plane: usize, - around: (bool, bool, i32), - alpha_uv: Option<(i32, CflSrc)>| - -> Result { - let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, 0); - let skip_ctx = usize::from(around.0) + usize::from(around.1); - let (levels, tx_type) = read_coeffs_rect( - dec, - &mut coding, - scan_c, - bw, - bh, - skip_ctx, - dc_sign_ctx(around.2), - uv_tx, - )?; - let residual = dequant_and_inverse_typed_wh( - &levels, - bw, - bh, - crate::decode::bit_depth(fctx), - block_q_idx(fctx), - plane_q_delta(plane, fctx).0, - plane_q_delta(plane, fctx).1, - tx_type, + // The leaf's own TX_8X4/TX_4X8 chroma unit: it IS the chroma plane + // block, so `get_txb_ctx` fixes the skip context at above+left. + let ca = neighbours.around_mi_rect(lmi, bw, bh); + let scan_c: &[u16] = if vert { &SCAN_4X8 } else { &SCAN_8X4 }; + let uv_tx = default_intra_tx_type(uv_predict_mode as u8); + let mut read_chroma = |plane: usize, + around: (bool, bool, i32), + alpha_uv: Option<(i32, CflSrc)>| + -> Result { + let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, 0); + let skip_ctx = usize::from(around.0) + usize::from(around.1); + let (levels, tx_type) = read_coeffs_rect( + dec, + &mut coding, + scan_c, + bw, + bh, + skip_ctx, + dc_sign_ctx(around.2), + uv_tx, + )?; + let residual = dequant_and_inverse_typed_wh( + &levels, + bw, + bh, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(plane, fctx).0, + plane_q_delta(plane, fctx).1, + tx_type, block_iqmatrix(fctx, plane, bw, bh, tx_type), - ); - push_intra_rect(plane, unit_x, unit_y, bw, bh, uv_predict_mode, angle_delta_uv, reach_c, &residual, alpha_uv, None, smooth_neighbor_uv, fctx); - Ok(levels) - }; - let ug = read_chroma(1, ca[1], alpha.zip(ac).map(|((au, _), ac)| (au, ac)))?; - let vg = read_chroma(2, ca[2], alpha.zip(ac).map(|((_, av), ac)| (av, ac)))?; - (ug, vg) + ); + push_intra_rect( + plane, + unit_x, + unit_y, + bw, + bh, + uv_predict_mode, + angle_delta_uv, + reach_c, + &residual, + alpha_uv, + None, + smooth_neighbor_uv, + fctx, + ); + Ok(levels) + }; + let ug = read_chroma(1, ca[1], alpha.zip(ac).map(|((au, _), ac)| (au, ac)))?; + let vg = read_chroma(2, ca[2], alpha.zip(ac).map(|((_, av), ac)| (av, ac)))?; + (ug, vg) } } else { - let chroma_around = neighbours.around_mi(if chroma_444 { lmi } else { group_mi }, if chroma_444 { 4 } else { 8 }); + let chroma_around = neighbours.around_mi( + if chroma_444 { lmi } else { group_mi }, + if chroma_444 { 4 } else { 8 }, + ); let ug = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode, - angle_delta_uv, reach_c, u, unit_x, unit_y, 4, TX4, base_q_idx, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + chroma_around[1], + uv_mode, + uv_predict_mode, + angle_delta_uv, + reach_c, + u, + unit_x, + unit_y, + 4, + TX4, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + None, + smooth_neighbor_uv, + fctx, )?; let vg = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode, - angle_delta_uv, reach_c, v, unit_x, unit_y, 4, TX4, base_q_idx, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + chroma_around[2], + uv_mode, + uv_predict_mode, + angle_delta_uv, + reach_c, + v, + unit_x, + unit_y, + 4, + TX4, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + None, + smooth_neighbor_uv, + fctx, )?; (ug, vg) }; @@ -39305,13 +44626,18 @@ fn decode_inter_sub8_rect2( enable_dual_filter: bool, tpl_frame: Option<&TplFrameArgs>, reduced_tx_set: bool, - frame_width: usize, fctx: &crate::decode::FrameCtx, + frame_width: usize, + fctx: &crate::decode::FrameCtx, ) -> Result<()> { const LAST_FRAME: i8 = 1; // The 8x8 group's own square stride: both leaves' prediction buffers are // laid out at it, as every other rect inter unit here is. const SIDE: usize = 8; - let (bw, bh) = if vert { (4usize, 8usize) } else { (8usize, 4usize) }; + let (bw, bh) = if vert { + (4usize, 8usize) + } else { + (8usize, 4usize) + }; let (w_mi, h_mi) = (bw / MI, bh / MI); hit_do! { SUB8_INTER_RECT_HITS.with(|c| { @@ -39399,10 +44725,7 @@ fn decode_inter_sub8_rect2( maybe_read_cdef_idx(dec, rmi, cmi, (2, 2), skip, fctx); maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip, fctx); maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip, fctx); - let (has_above, has_left) = ( - rmi > neighbours.tile_row0_mi, - cmi > neighbours.tile_col0_mi, - ); + let (has_above, has_left) = (rmi > neighbours.tile_row0_mi, cmi > neighbours.tile_col0_mi); let ii_ctx = intra_inter_ctx( has_above, has_left, @@ -39443,7 +44766,8 @@ fn decode_inter_sub8_rect2( base_q_idx, fctx.enable_filter_intra_inter.with(std::cell::Cell::get), fctx.tx_select_inter.with(std::cell::Cell::get), - reduced_tx_set, fctx, + reduced_tx_set, + fctx, )?; if piece_is_chroma_ref(i) { intra_chroma = true; @@ -39505,7 +44829,9 @@ fn decode_inter_sub8_rect2( tpl, ); let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; - if !not_new { crate::census::mode(0); } + if !not_new { + crate::census::mode(0); + } let mut is_globalmv = false; let (mv, is_new_mv) = if !not_new { let mut idx = 0usize; @@ -39529,7 +44855,9 @@ fn decode_inter_sub8_rect2( ) } else { let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; - if !not_zero { crate::census::mode(1); } + if !not_zero { + crate::census::mode(1); + } is_globalmv = !not_zero; let mv = if !not_zero { gm_table[(ref_frame - LAST_FRAME) as usize] @@ -39669,7 +44997,8 @@ fn decode_inter_sub8_rect2( bh, h_filter, v_filter, - &mut dense, fctx, + &mut dense, + fctx, ); for row in 0..bh { pred_y[row * SIDE..][..bw].copy_from_slice(&dense[row * bw..][..bw]); @@ -39679,7 +45008,11 @@ fn decode_inter_sub8_rect2( let pred_y: Vec; let sy = if recon_deferred(fctx) { push_pred(fctx, build); - Pred::Cur { plane: 0, stride: SIDE, off: 0 } + Pred::Cur { + plane: 0, + stride: SIDE, + off: 0, + } } else { let mut built: [Vec; 3] = Default::default(); build(y, u, v, fctx, &mut built); @@ -39688,9 +45021,27 @@ fn decode_inter_sub8_rect2( Pred::Inline(&pred_y, SIDE) }; if skip { - push_mc_rect(0, px, py, SIDE, bw, bh, sy, &ZERO_RESIDUAL[..SIDE * SIDE], fctx); + push_mc_rect( + 0, + px, + py, + SIDE, + bw, + bh, + sy, + &ZERO_RESIDUAL[..SIDE * SIDE], + fctx, + ); neighbours.record_mi_luma_rect(lmi, bw, bh, &ZERO_RESIDUAL[..bw * bh]); - neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME), fctx); + neighbours.fill_lf_grid_rect( + lmi, + w_mi, + h_mi, + bw as u8, + bh as u8, + ref_frame.max(LAST_FRAME), + fctx, + ); } else { let (mut last_tw, mut last_th) = (bw, bh); for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() { @@ -39728,7 +45079,8 @@ fn decode_inter_sub8_rect2( base_q_idx, sy.offset(start), None, - Some(tu_skip_ctx), fctx, + Some(tu_skip_ctx), + fctx, )? } else { // The whole leaf as one `TX_8X4`/`TX_4X8` unit: it IS the @@ -39752,7 +45104,8 @@ fn decode_inter_sub8_rect2( tu_py, sy.offset(start), None, - None, fctx, + None, + fctx, )? }; if idx == 0 { @@ -39778,7 +45131,8 @@ fn decode_inter_sub8_rect2( h_mi, last_tw as u8, last_th as u8, - ref_frame.max(LAST_FRAME), fctx, + ref_frame.max(LAST_FRAME), + fctx, ); } // lane-av1-444: at ss 0/0 this piece codes its OWN 8x4/4x8 U and V @@ -39814,7 +45168,8 @@ fn decode_inter_sub8_rect2( bh, h_filter, v_filter, - &mut dense, fctx, + &mut dense, + fctx, ); for row in 0..bh { dst[row * SIDE..][..bw].copy_from_slice(&dense[row * bw..][..bw]); @@ -39827,8 +45182,16 @@ fn decode_inter_sub8_rect2( let (su, sv) = if recon_deferred(fctx) { push_pred(fctx, build_c); ( - Pred::Cur { plane: 1, stride: SIDE, off: 0 }, - Pred::Cur { plane: 2, stride: SIDE, off: 0 }, + Pred::Cur { + plane: 1, + stride: SIDE, + off: 0, + }, + Pred::Cur { + plane: 2, + stride: SIDE, + off: 0, + }, ) } else { let mut built: [Vec; 3] = Default::default(); @@ -39838,8 +45201,28 @@ fn decode_inter_sub8_rect2( (Pred::Inline(&pred_cu, SIDE), Pred::Inline(&pred_cv, SIDE)) }; if skip { - push_mc_rect(1, px, py, SIDE, bw, bh, su, &ZERO_RESIDUAL[..SIDE * SIDE], fctx); - push_mc_rect(2, px, py, SIDE, bw, bh, sv, &ZERO_RESIDUAL[..SIDE * SIDE], fctx); + push_mc_rect( + 1, + px, + py, + SIDE, + bw, + bh, + su, + &ZERO_RESIDUAL[..SIDE * SIDE], + fctx, + ); + push_mc_rect( + 2, + px, + py, + SIDE, + bw, + bh, + sv, + &ZERO_RESIDUAL[..SIDE * SIDE], + fctx, + ); neighbours.record_mi_chroma(lmi, bw, bh, 1, &ZERO_RESIDUAL[..bw * bh]); neighbours.record_mi_chroma(lmi, bw, bh, 2, &ZERO_RESIDUAL[..bw * bh]); } else if lossless(fctx) && !mono(fctx) { @@ -39855,19 +45238,60 @@ fn decode_inter_sub8_rect2( // per-unit stamps ARE the block's chroma contexts (the same // rule `leaf8_inter_chroma_lossless`'s caller obeys). read_inter_chroma_lossless( - dec, cdfs, neighbours, u, v, su, sv, - (rmi, cmi), (px, py), (0, 0), (bw, bh), (bw, bh), SIDE, 0, - base_q_idx, &mut Vec::new(), &mut Vec::new(), fctx, + dec, + cdfs, + neighbours, + u, + v, + su, + sv, + (rmi, cmi), + (px, py), + (0, 0), + (bw, bh), + (bw, bh), + SIDE, + 0, + base_q_idx, + &mut Vec::new(), + &mut Vec::new(), + fctx, )?; } else { let ca = neighbours.around_mi_rect(lmi, bw, bh); let (ug, _) = read_inter_plane_rect( - dec, cdfs, TxbSet::ChromaRect8x4, (bw, bh), SIDE, 1, ca[1], 0, u, px, py, - su, Some(piece_tx_type), None, fctx, + dec, + cdfs, + TxbSet::ChromaRect8x4, + (bw, bh), + SIDE, + 1, + ca[1], + 0, + u, + px, + py, + su, + Some(piece_tx_type), + None, + fctx, )?; let (vg, _) = read_inter_plane_rect( - dec, cdfs, TxbSet::ChromaRect8x4, (bw, bh), SIDE, 2, ca[2], 0, v, px, py, - sv, Some(piece_tx_type), None, fctx, + dec, + cdfs, + TxbSet::ChromaRect8x4, + (bw, bh), + SIDE, + 2, + ca[2], + 0, + v, + px, + py, + sv, + Some(piece_tx_type), + None, + fctx, )?; neighbours.record_mi_chroma(lmi, bw, bh, 1, &ug); neighbours.record_mi_chroma(lmi, bw, bh, 2, &vg); @@ -39902,16 +45326,14 @@ fn decode_inter_sub8_rect2( let left_piece = if i > 0 { piece[i - 1] } else if lmi.1 > 0 { - grid.get(rmi, lmi.1 - 1).filter(|mi| mi.is_inter).map( - |mi| { - ( - mi.ref_frame, - (i32::from(mi.mv.0), i32::from(mi.mv.1)), - pc_hf, - pc_vf, - ) - }, - ) + grid.get(rmi, lmi.1 - 1).filter(|mi| mi.is_inter).map(|mi| { + ( + mi.ref_frame, + (i32::from(mi.mv.0), i32::from(mi.mv.1)), + pc_hf, + pc_vf, + ) + }) } else { None }; @@ -39943,7 +45365,8 @@ fn decode_inter_sub8_rect2( 4, pc_hf, pc_vf, - &mut half, fctx, + &mut half, + fctx, ); for row in 0..4 { buf[row * B4 + 2..row * B4 + 4] @@ -39971,7 +45394,8 @@ fn decode_inter_sub8_rect2( 4, l_hf, l_vf, - &mut half, fctx, + &mut half, + fctx, ); for row in 0..4 { buf[row * B4..row * B4 + 2] @@ -39990,7 +45414,8 @@ fn decode_inter_sub8_rect2( B4, pc_hf, pc_vf, - &mut buf, fctx, + &mut buf, + fctx, ); } dst.copy_from_slice(&buf); @@ -40002,8 +45427,16 @@ fn decode_inter_sub8_rect2( let (su, sv) = if recon_deferred(fctx) { push_pred(fctx, build_c); ( - Pred::Cur { plane: 1, stride: B4, off: 0 }, - Pred::Cur { plane: 2, stride: B4, off: 0 }, + Pred::Cur { + plane: 1, + stride: B4, + off: 0, + }, + Pred::Cur { + plane: 2, + stride: B4, + off: 0, + }, ) } else { let mut built: [Vec; 3] = Default::default(); @@ -40022,19 +45455,56 @@ fn decode_inter_sub8_rect2( } else { hit!(CHROMA422_INTER_SUB8_HITS); let (ug, _) = read_inter_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, ca[1], 0, u, unit_x, unit_y, B4, - base_q_idx, su, Some(piece_tx_type), None, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + ca[1], + 0, + u, + unit_x, + unit_y, + B4, + base_q_idx, + su, + Some(piece_tx_type), + None, + fctx, )?; let (vg, _) = read_inter_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, ca[2], 0, v, unit_x, unit_y, B4, - base_q_idx, sv, Some(piece_tx_type), None, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + ca[2], + 0, + v, + unit_x, + unit_y, + B4, + base_q_idx, + sv, + Some(piece_tx_type), + None, + fctx, )?; neighbours.record_mi_chroma(ctx_mi, 8, 4, 1, &ug); neighbours.record_mi_chroma(ctx_mi, 8, 4, 2, &vg); } } neighbours.record_mode_mi(rmi, cmi, w_mi, h_mi, DC_PRED); - neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, true, ref_frame, resolved_filter, false); + neighbours.record_inter_rect_mi( + lmi, + w_mi, + h_mi, + skip, + true, + ref_frame, + resolved_filter, + false, + ); neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip); last_skip = skip; } @@ -40144,7 +45614,8 @@ fn decode_inter_sub8_rect2( piece_h, h_filter, v_filter, - &mut buf, fctx, + &mut buf, + fctx, ); for row in 0..piece_h { for col in 0..piece_w { @@ -40160,8 +45631,16 @@ fn decode_inter_sub8_rect2( let (su, sv) = if recon_deferred(fctx) { push_pred(fctx, build); ( - Pred::Cur { plane: 1, stride: B4, off: 0 }, - Pred::Cur { plane: 2, stride: B4, off: 0 }, + Pred::Cur { + plane: 1, + stride: B4, + off: 0, + }, + Pred::Cur { + plane: 2, + stride: B4, + off: 0, + }, ) } else { let mut built: [Vec; 3] = Default::default(); @@ -40177,13 +45656,41 @@ fn decode_inter_sub8_rect2( } else { let around = neighbours.around_mi(group_mi, 8); let ug = read_inter_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx, - su, Some(first_tx_type), None, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 1, + around[1], + 0, + u, + cpx, + cpy, + B4, + base_q_idx, + su, + Some(first_tx_type), + None, + fctx, )? .0; let vg = read_inter_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx, - sv, Some(first_tx_type), None, fctx, + dec, + cdfs, + TxbSet::Chroma4, + scan4, + 2, + around[2], + 0, + v, + cpx, + cpy, + B4, + base_q_idx, + sv, + Some(first_tx_type), + None, + fctx, )? .0; let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0); @@ -40355,8 +45862,16 @@ fn decode_inter_block8( // for the scaled-reference MC this leaf's own single-ref/compound/OBMC // predictions take when a stored reference was coded at another width // (`use_superres`) -- mirrors [`decode_inter_block`]'s own param. - frame_width: usize, fctx: &crate::decode::FrameCtx, -) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, [u8; 2], (i8, Option))> { + frame_width: usize, + fctx: &crate::decode::FrameCtx, +) -> Result<( + bool, + bool, + bool, + Option<(i8, i8, u8, u8)>, + [u8; 2], + (i8, Option), +)> { const LAST_FRAME: i8 = 1; // lane-gmaffine r2: the leaf's OWN switchable-filter symbols, handed back // so the caller stamps them into `Neighbours` instead of the `[3, 3]` @@ -40527,14 +46042,7 @@ fn decode_inter_block8( // [`decode_inter_block`]'s own compound arm passes // (`-1` when the band is unavailable is start_tile's / // start_row's own reset value, so no `has_above` guard). - read_compound_ref_frames( - dec, - cdfs, - above_nbr, - left_nbr, - above_ref0, - left_ref0, - ) + read_compound_ref_frames(dec, cdfs, above_nbr, left_nbr, above_ref0, left_ref0) }; leaf_refs = (ref0, Some(ref1)); let (mi_row, mi_col) = leaf_mi; @@ -40679,39 +46187,41 @@ fn decode_inter_block8( // compound_idx defect surfaces on the wide gate sweep. // lane-av1idx r1: same re-mask as the 16x16 leaf above -- // see that comment. - let (fwd_offset, bck_offset, compound_idx) = if comp_group_idx == 0 - && !skip_mode - && enable_jnt_comp - { - let idx_ctx = get_comp_index_context( - neighbours, - leaf_mi, - SIDE, - order_hint_bits, - order_hint, - ref_order_hints[(ref0 - LAST_FRAME) as usize], - ref_order_hints[(ref1 - LAST_FRAME) as usize], - ); - let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); - if idx == 1 { - (8, 8, 1u8) - } else { - let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign( + let (fwd_offset, bck_offset, compound_idx) = + if comp_group_idx == 0 && !skip_mode && enable_jnt_comp { + let idx_ctx = get_comp_index_context( + neighbours, + leaf_mi, + SIDE, order_hint_bits, order_hint, ref_order_hints[(ref0 - LAST_FRAME) as usize], ref_order_hints[(ref1 - LAST_FRAME) as usize], ); - (fwd, bck, 0u8) - } - } else { - (8, 8, 1u8) - }; + let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); + if idx == 1 { + (8, 8, 1u8) + } else { + let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign( + order_hint_bits, + order_hint, + ref_order_hints[(ref0 - LAST_FRAME) as usize], + ref_order_hints[(ref1 - LAST_FRAME) as usize], + ); + (fwd, bck, 0u8) + } + } else { + (8, 8, 1u8) + }; compound_ctx8 = Some((ref0, ref1, comp_group_idx as u8, compound_idx)); if crate::envflags::env_flag!("EC_AV1_COMPIDX_DUMP") { eprintln!( "EC_COMPIDX mi_row={mi_row} mi_col={mi_col} bsize=8 mode={compound_mode} mv0=({},{}) mv1=({},{}) ref0={ref0} ref1={ref1} comp_group_idx={comp_group_idx} compound_idx={compound_idx} tell={}", - mv0.0, mv0.1, mv1.0, mv1.1, dec.debug_bitpos() + mv0.0, + mv0.1, + mv1.0, + mv1.1, + dec.debug_bitpos() ); } @@ -40787,10 +46297,10 @@ fn decode_inter_block8( // candidate -- a wrong mv stack, wrong mode contexts, and a // desync one block later. let is_globalmv_c = compound_mode == 6; - let is_global_mv0_c = is_globalmv_c - && global_motion[(ref0 - LAST_FRAME) as usize].model as u8 > 1; - let is_global_mv1_c = is_globalmv_c - && global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1; + let is_global_mv0_c = + is_globalmv_c && global_motion[(ref0 - LAST_FRAME) as usize].model as u8 > 1; + let is_global_mv1_c = + is_globalmv_c && global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1; // lane-interp3 r3 (class twin-functions-drift, second // instance): libaom applies `allow_warp`'s GLOBAL branch // (`reconinter.c:33-55`, reached from `av1_init_warp_params` @@ -40860,187 +46370,268 @@ fn decode_inter_block8( _v: &mut PlaneBuf<'static>, fctx: &crate::decode::FrameCtx, out: &mut [Vec; 3]| { - let (Some((py0, pu0, pv0)), Some((py1, pu1, pv1))) = - (ref_planes_deferred(ref0, refpix), ref_planes_deferred(ref1, refpix)) - else { - return; - }; - let mut inter0_y = vec![0i32; SIDE * SIDE]; - mc::predict_compound_intermediate( - &py0.data, - py0.width, - py0.true_width, - py0.true_height, - mv_to_q4(px, mv0.1, 0), - mv_to_q4(py, mv0.0, 0), - scale0, - SIDE, - SIDE, - h_filter, - v_filter, - &mut inter0_y, fctx,); - if let Some(wp) = &warp0_c { - crate::warp::warp_affine_compound( - wp, &py0.data, py0.true_width as i32, py0.true_height as i32, - py0.width as i32, &mut inter0_y, px as i32, py as i32, SIDE as i32, - SIDE as i32, SIDE as i32, 0, 0, fctx, - ); - } - let mut inter1_y = vec![0i32; SIDE * SIDE]; - mc::predict_compound_intermediate( - &py1.data, - py1.width, - py1.true_width, - py1.true_height, - mv_to_q4(px, mv1.1, 0), - mv_to_q4(py, mv1.0, 0), - scale1, - SIDE, - SIDE, - h_filter, - v_filter, - &mut inter1_y, fctx,); - if let Some(wp) = &warp1_c { - crate::warp::warp_affine_compound( - wp, &py1.data, py1.true_width as i32, py1.true_height as i32, - py1.width as i32, &mut inter1_y, px as i32, py as i32, SIDE as i32, - SIDE as i32, SIDE as i32, 0, 0, fctx, + let (Some((py0, pu0, pv0)), Some((py1, pu1, pv1))) = ( + ref_planes_deferred(ref0, refpix), + ref_planes_deferred(ref1, refpix), + ) else { + return; + }; + let mut inter0_y = vec![0i32; SIDE * SIDE]; + mc::predict_compound_intermediate( + &py0.data, + py0.width, + py0.true_width, + py0.true_height, + mv_to_q4(px, mv0.1, 0), + mv_to_q4(py, mv0.0, 0), + scale0, + SIDE, + SIDE, + h_filter, + v_filter, + &mut inter0_y, + fctx, ); - } - let mut pred_y = refill(std::mem::take(&mut out[0]), SIDE * SIDE); - let mut diffwtd_mask_y; - let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type { - diffwtd_mask_y = vec![0u8; SIDE * SIDE]; - hit!(DIFFWTD_HITS); - mc::diffwtd_mask(&inter0_y, &inter1_y, mask_type == 1, &mut diffwtd_mask_y, fctx); - Some(diffwtd_mask_y.as_slice()) - } else { - wedge_mask - }; - if let Some(mask_y) = mask_y { - mc::blend_masked_compound( - &inter0_y, &inter1_y, mask_y, SIDE, SIDE, SIDE, 0, 0, &mut pred_y, fctx, + if let Some(wp) = &warp0_c { + crate::warp::warp_affine_compound( + wp, + &py0.data, + py0.true_width as i32, + py0.true_height as i32, + py0.width as i32, + &mut inter0_y, + px as i32, + py as i32, + SIDE as i32, + SIDE as i32, + SIDE as i32, + 0, + 0, + fctx, + ); + } + let mut inter1_y = vec![0i32; SIDE * SIDE]; + mc::predict_compound_intermediate( + &py1.data, + py1.width, + py1.true_width, + py1.true_height, + mv_to_q4(px, mv1.1, 0), + mv_to_q4(py, mv1.0, 0), + scale1, + SIDE, + SIDE, + h_filter, + v_filter, + &mut inter1_y, + fctx, ); - } else { - mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y, fctx); - } + if let Some(wp) = &warp1_c { + crate::warp::warp_affine_compound( + wp, + &py1.data, + py1.true_width as i32, + py1.true_height as i32, + py1.width as i32, + &mut inter1_y, + px as i32, + py as i32, + SIDE as i32, + SIDE as i32, + SIDE as i32, + 0, + 0, + fctx, + ); + } + let mut pred_y = refill(std::mem::take(&mut out[0]), SIDE * SIDE); + let mut diffwtd_mask_y; + let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type { + diffwtd_mask_y = vec![0u8; SIDE * SIDE]; + hit!(DIFFWTD_HITS); + mc::diffwtd_mask( + &inter0_y, + &inter1_y, + mask_type == 1, + &mut diffwtd_mask_y, + fctx, + ); + Some(diffwtd_mask_y.as_slice()) + } else { + wedge_mask + }; + if let Some(mask_y) = mask_y { + mc::blend_masked_compound( + &inter0_y, + &inter1_y, + mask_y, + SIDE, + SIDE, + SIDE, + 0, + 0, + &mut pred_y, + fctx, + ); + } else { + mc::combine_compound( + &inter0_y, + &inter1_y, + fwd_offset, + bck_offset, + &mut pred_y, + fctx, + ); + } - let mut inter0_u = vec![0i32; chroma_w * chroma_h]; - mc::predict_compound_intermediate( - &pu0.data, - pu0.width, - pu0.true_width, - pu0.true_height, - mv_to_q4(cpx, mv0.1, ss_x(fctx)), - mv_to_q4(cpy, mv0.0, ss_y(fctx)), - scale0, - chroma_w, - chroma_h, - h_filter, - v_filter, - &mut inter0_u, fctx, - ); - let mut inter1_u = vec![0i32; chroma_w * chroma_h]; - mc::predict_compound_intermediate( - &pu1.data, - pu1.width, - pu1.true_width, - pu1.true_height, - mv_to_q4(cpx, mv1.1, ss_x(fctx)), - mv_to_q4(cpy, mv1.0, ss_y(fctx)), - scale1, - chroma_w, - chroma_h, - h_filter, - v_filter, - &mut inter1_u, fctx, - ); - let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_w * chroma_h); - if let Some(mask_y) = mask_y { - mc::blend_masked_compound( - &inter0_u, - &inter1_u, - mask_y, - SIDE, + let mut inter0_u = vec![0i32; chroma_w * chroma_h]; + mc::predict_compound_intermediate( + &pu0.data, + pu0.width, + pu0.true_width, + pu0.true_height, + mv_to_q4(cpx, mv0.1, ss_x(fctx)), + mv_to_q4(cpy, mv0.0, ss_y(fctx)), + scale0, chroma_w, chroma_h, - ss_x(fctx), -ss_y(fctx), - &mut pred_u, fctx, + h_filter, + v_filter, + &mut inter0_u, + fctx, ); - } else { - mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u, fctx); - } + let mut inter1_u = vec![0i32; chroma_w * chroma_h]; + mc::predict_compound_intermediate( + &pu1.data, + pu1.width, + pu1.true_width, + pu1.true_height, + mv_to_q4(cpx, mv1.1, ss_x(fctx)), + mv_to_q4(cpy, mv1.0, ss_y(fctx)), + scale1, + chroma_w, + chroma_h, + h_filter, + v_filter, + &mut inter1_u, + fctx, + ); + let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_w * chroma_h); + if let Some(mask_y) = mask_y { + mc::blend_masked_compound( + &inter0_u, + &inter1_u, + mask_y, + SIDE, + chroma_w, + chroma_h, + ss_x(fctx), + ss_y(fctx), + &mut pred_u, + fctx, + ); + } else { + mc::combine_compound( + &inter0_u, + &inter1_u, + fwd_offset, + bck_offset, + &mut pred_u, + fctx, + ); + } - let mut inter0_v = vec![0i32; chroma_w * chroma_h]; - mc::predict_compound_intermediate( - &pv0.data, - pv0.width, - pv0.true_width, - pv0.true_height, - mv_to_q4(cpx, mv0.1, ss_x(fctx)), - mv_to_q4(cpy, mv0.0, ss_y(fctx)), - scale0, - chroma_w, - chroma_h, - h_filter, - v_filter, - &mut inter0_v, fctx, - ); - let mut inter1_v = vec![0i32; chroma_w * chroma_h]; - mc::predict_compound_intermediate( - &pv1.data, - pv1.width, - pv1.true_width, - pv1.true_height, - mv_to_q4(cpx, mv1.1, ss_x(fctx)), - mv_to_q4(cpy, mv1.0, ss_y(fctx)), - scale1, - chroma_w, - chroma_h, - h_filter, - v_filter, - &mut inter1_v, fctx, - ); - let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_w * chroma_h); - if let Some(mask_y) = mask_y { - mc::blend_masked_compound( - &inter0_v, - &inter1_v, - mask_y, - SIDE, + let mut inter0_v = vec![0i32; chroma_w * chroma_h]; + mc::predict_compound_intermediate( + &pv0.data, + pv0.width, + pv0.true_width, + pv0.true_height, + mv_to_q4(cpx, mv0.1, ss_x(fctx)), + mv_to_q4(cpy, mv0.0, ss_y(fctx)), + scale0, chroma_w, chroma_h, - ss_x(fctx), -ss_y(fctx), - &mut pred_v, fctx, + h_filter, + v_filter, + &mut inter0_v, + fctx, ); - } else { - mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v, fctx); - } + let mut inter1_v = vec![0i32; chroma_w * chroma_h]; + mc::predict_compound_intermediate( + &pv1.data, + pv1.width, + pv1.true_width, + pv1.true_height, + mv_to_q4(cpx, mv1.1, ss_x(fctx)), + mv_to_q4(cpy, mv1.0, ss_y(fctx)), + scale1, + chroma_w, + chroma_h, + h_filter, + v_filter, + &mut inter1_v, + fctx, + ); + let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_w * chroma_h); + if let Some(mask_y) = mask_y { + mc::blend_masked_compound( + &inter0_v, + &inter1_v, + mask_y, + SIDE, + chroma_w, + chroma_h, + ss_x(fctx), + ss_y(fctx), + &mut pred_v, + fctx, + ); + } else { + mc::combine_compound( + &inter0_v, + &inter1_v, + fwd_offset, + bck_offset, + &mut pred_v, + fctx, + ); + } - *out = [pred_y, pred_u, pred_v]; + *out = [pred_y, pred_u, pred_v]; + }; + let deferred = recon_deferred(fctx); + let (pred_y, pred_u, pred_v): (Vec, Vec, Vec); + let (sy, su, sv) = if deferred { + push_pred(fctx, build); + ( + Pred::Cur { + plane: 0, + stride: SIDE, + off: 0, + }, + Pred::Cur { + plane: 1, + stride: chroma_w, + off: 0, + }, + Pred::Cur { + plane: 2, + stride: chroma_w, + off: 0, + }, + ) + } else { + let mut built: [Vec; 3] = Default::default(); + build(y, u, v, fctx, &mut built); + let [by, bu, bv] = built; + (pred_y, pred_u, pred_v) = (by, bu, bv); + ( + Pred::Inline(&pred_y, SIDE), + Pred::Inline(&pred_u, chroma_w), + Pred::Inline(&pred_v, chroma_w), + ) }; - let deferred = recon_deferred(fctx); - let (pred_y, pred_u, pred_v): (Vec, Vec, Vec); - let (sy, su, sv) = if deferred { - push_pred(fctx, build); - ( - Pred::Cur { plane: 0, stride: SIDE, off: 0 }, - Pred::Cur { plane: 1, stride: chroma_w, off: 0 }, - Pred::Cur { plane: 2, stride: chroma_w, off: 0 }, - ) - } else { - let mut built: [Vec; 3] = Default::default(); - build(y, u, v, fctx, &mut built); - let [by, bu, bv] = built; - (pred_y, pred_u, pred_v) = (by, bu, bv); - ( - Pred::Inline(&pred_y, SIDE), - Pred::Inline(&pred_u, chroma_w), - Pred::Inline(&pred_v, chroma_w), - ) - }; split8 = read_block_tx_size( dec, cdfs, @@ -41049,7 +46640,8 @@ ss_y(fctx), SIDE, (mi_cols as usize, mi_rows as usize), true, - skip, fctx, + skip, + fctx, )? .1 .is_some(); @@ -41058,23 +46650,27 @@ ss_y(fctx), // lane-av1-422sub8rect: the plane block is the (chroma_w, // chroma_h) rect at 4:2:2 -- the recorded write is // stride `chroma_w`, full `chroma_h` rows. - push_mc_rect(1, + push_mc_rect( + 1, cpx, cpy, chroma_w, chroma_w, chroma_h, su, - &ZERO_RESIDUAL[..chroma_w * chroma_h], fctx, + &ZERO_RESIDUAL[..chroma_w * chroma_h], + fctx, ); - push_mc_rect(2, + push_mc_rect( + 2, cpx, cpy, chroma_w, chroma_w, chroma_h, sv, - &ZERO_RESIDUAL[..chroma_w * chroma_h], fctx, + &ZERO_RESIDUAL[..chroma_w * chroma_h], + fctx, ); luma_grid = Grid::Zero(SIDE * SIDE); u_grid = Grid::Zero(chroma_w * chroma_h); @@ -41106,7 +46702,8 @@ ss_y(fctx), scan8, scan4, reduced_tx_set, - split8, fctx, + split8, + fctx, )?; luma_grid = grid8; // 4:4:4 lossless 8x8 inter leaf: the chroma plane block is @@ -41116,8 +46713,17 @@ ss_y(fctx), // the `else` below, dispatched on `chroma_422`. if chroma_w == 8 && lossless(fctx) && !mono(fctx) { let (ug, vg) = leaf8_inter_chroma_lossless( - dec, cdfs, neighbours, u, v, su, sv, - leaf_mi, (cpx, cpy), base_q_idx, fctx, + dec, + cdfs, + neighbours, + u, + v, + su, + sv, + leaf_mi, + (cpx, cpy), + base_q_idx, + fctx, )?; u_grid = ug; v_grid = vg; @@ -41138,7 +46744,8 @@ ss_y(fctx), cpy, su, Some(luma_tx_type), - None, fctx, + None, + fctx, )? .0 } else { @@ -41157,7 +46764,8 @@ ss_y(fctx), base_q_idx, su, Some(luma_tx_type), - None, fctx, + None, + fctx, )? .0 }; @@ -41176,7 +46784,8 @@ ss_y(fctx), cpy, sv, Some(luma_tx_type), - None, fctx, + None, + fctx, )? .0 } else { @@ -41195,7 +46804,8 @@ ss_y(fctx), base_q_idx, sv, Some(luma_tx_type), - None, fctx, + None, + fctx, )? .0 }; @@ -41240,30 +46850,39 @@ ss_y(fctx), ], ) }); - // lane-t900 r23: every leaf stamps its palette state (all-zero for an - // inter leaf or a non-palette intra one, real for a palette block) into - // the mi-granular neighbour bands, so the next intra block's - // `av1_get_palette_mode_ctx` and colour cache see exactly what libaom's - // mode-info grid holds. - record_strip_palette( - neighbours, - leaf_mi, - 8, - 8, - palette_record8.0, - palette_record8.1, - palette_record8.2, - palette_record8.3, - ); + // lane-t900 r23: every leaf stamps its palette state (all-zero for an + // inter leaf or a non-palette intra one, real for a palette block) into + // the mi-granular neighbour bands, so the next intra block's + // `av1_get_palette_mode_ctx` and colour cache see exactly what libaom's + // mode-info grid holds. + record_strip_palette( + neighbours, + leaf_mi, + 8, + 8, + palette_record8.0, + palette_record8.1, + palette_record8.2, + palette_record8.3, + ); let saved_chroma_ctx = chroma_stamped_per_unit.then(|| { ( [ [neighbours.left[leaf_mi.0][1], neighbours.left[leaf_mi.0][2]], - [neighbours.left[leaf_mi.0 + 1][1], neighbours.left[leaf_mi.0 + 1][2]], + [ + neighbours.left[leaf_mi.0 + 1][1], + neighbours.left[leaf_mi.0 + 1][2], + ], ], [ - [neighbours.above[leaf_mi.1][1], neighbours.above[leaf_mi.1][2]], - [neighbours.above[leaf_mi.1 + 1][1], neighbours.above[leaf_mi.1 + 1][2]], + [ + neighbours.above[leaf_mi.1][1], + neighbours.above[leaf_mi.1][2], + ], + [ + neighbours.above[leaf_mi.1 + 1][1], + neighbours.above[leaf_mi.1 + 1][2], + ], ], ) }); @@ -41309,7 +46928,12 @@ ss_y(fctx), leaf_mi, 2, if split8 { 4 } else { 8 }, - if is_inter { leaf_refs.0.max(LAST_FRAME) } else { 0 }, fctx, + if is_inter { + leaf_refs.0.max(LAST_FRAME) + } else { + 0 + }, + fctx, ); return Ok(( skip, @@ -41379,7 +47003,9 @@ ss_y(fctx), } let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; - if !not_new { crate::census::mode(0); } + if !not_new { + crate::census::mode(0); + } let mut is_globalmv = false; let (mv, is_new_mv) = if !not_new { // NEWMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting at 0): @@ -41409,7 +47035,9 @@ ss_y(fctx), ) } else { let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; - if !not_zero { crate::census::mode(1); } + if !not_zero { + crate::census::mode(1); + } is_globalmv = !not_zero; let mv = if !not_zero { // lane-gmaffine r1: GLOBALMV (spec 7.10.2.1) -- the same @@ -41487,7 +47115,13 @@ ss_y(fctx), && interintra_mode.is_none() && !(is_global_mv_block && !force_integer_mv) && has_overlappable_neighbour( - grid, mi_row, mi_col, 2, 2, mi_cols as usize, mi_rows as usize, + grid, + mi_row, + mi_col, + 2, + 2, + mi_cols as usize, + mi_rows as usize, ); let mut warp_params: Option = None; let mut warped_selected = false; @@ -41506,8 +47140,17 @@ ss_y(fctx), // `!xd->cur_frame_force_integer_mv`, so a screen-content frame // that set `force_integer_mv` reads the 2-symbol `obmc_cdf` here // (class wrong-alphabet-same-value). - let proj_ok = - num_proj_ref(grid, mi_row, mi_col, 2, 2, mi_cols as usize, mi_rows as usize, ref_frame, fctx) >= 1; + let proj_ok = num_proj_ref( + grid, + mi_row, + mi_col, + 2, + 2, + mi_cols as usize, + mi_rows as usize, + ref_frame, + fctx, + ) >= 1; // lane-t900 r28: the `&& !ref_is_scaled` the note above asked the // lifter of the 8x8-leaf refusal to add. libaom // `motion_mode_allowed` (blockd.h) makes WARPED_CAUSAL eligible @@ -41518,8 +47161,7 @@ ss_y(fctx), // wrong-alphabet-same-value: reading the 3-symbol row here // desynced every warped-motion superres stream at its first // eligible 8x8 leaf). - let ref_is_scaled = - mc::scale_factor(ref_width, frame_width) != mc::REF_NO_SCALE; + let ref_is_scaled = mc::scale_factor(ref_width, frame_width) != mc::REF_NO_SCALE; let warp_eligible = allow_warped_motion && !ref_is_scaled && !force_integer_mv && proj_ok; if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { @@ -41561,7 +47203,8 @@ ss_y(fctx), 2, mi_cols as usize, mi_rows as usize, - ref_frame, fctx, + ref_frame, + fctx, ); if samples.len() > 1 { crate::warp::select_samples(mv, &mut samples, SIDE as i32, SIDE as i32); @@ -41619,8 +47262,7 @@ ss_y(fctx), } else { [3, 3] }; - let gm_nontrans = - is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation; + let gm_nontrans = is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation; let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( dec, cdfs, @@ -41677,7 +47319,11 @@ ss_y(fctx), ref_frame, // INTRA_FRAME marker for interintra blocks -- keeps // them out of warp-sample gathering (see 16/32 site). - ref_frame1: if interintra_mode.is_some() { 0 } else { NO_REF1 }, + ref_frame1: if interintra_mode.is_some() { + 0 + } else { + NO_REF1 + }, mv1: (0, 0), mv: mv16(mv), is_new_mv, @@ -41732,114 +47378,197 @@ ss_y(fctx), v: &mut PlaneBuf<'static>, fctx: &crate::decode::FrameCtx, out: &mut [Vec; 3]| { - let Some((sref_y, sref_u, sref_v)) = ref_planes_deferred(ref_frame, refpix) else { - return; - }; - let mut pred_y = refill(std::mem::take(&mut out[0]), SIDE * SIDE); - let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_w * chroma_h); - let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_w * chroma_h); - // Merge of lane-gmaffine (this leaf's own switchable filters) with - // lane-scaledref (spec 7.11.3.3's scaled walk): same kernels either - // way, only the sample walk differs. - for (plane, x, y, (dim_w, dim_h), dst) in [ - (sref_y, px, py, (SIDE, SIDE), &mut pred_y), - (sref_u, cpx, cpy, (chroma_w, chroma_h), &mut pred_u), - (sref_v, cpx, cpy, (chroma_w, chroma_h), &mut pred_v), - ] { - let luma = std::ptr::eq(plane, sref_y); - if luma_scale == mc::REF_NO_SCALE { - mc::predict_with_filters( - &plane.data, - plane.width, - plane.true_width, - plane.true_height, - mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }), - mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }), - dim_w, - dim_h, - h_filter, - v_filter, - dst, fctx, - ); - } else { - mc::predict_scaled( - &plane.data, - plane.width, - plane.true_width, - plane.true_height, - mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }), - mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }), - luma_scale, - dim_w, - dim_h, - h_filter, - v_filter, - dst, fctx, - ); + let Some((sref_y, sref_u, sref_v)) = ref_planes_deferred(ref_frame, refpix) else { + return; + }; + let mut pred_y = refill(std::mem::take(&mut out[0]), SIDE * SIDE); + let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_w * chroma_h); + let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_w * chroma_h); + // Merge of lane-gmaffine (this leaf's own switchable filters) with + // lane-scaledref (spec 7.11.3.3's scaled walk): same kernels either + // way, only the sample walk differs. + for (plane, x, y, (dim_w, dim_h), dst) in [ + (sref_y, px, py, (SIDE, SIDE), &mut pred_y), + (sref_u, cpx, cpy, (chroma_w, chroma_h), &mut pred_u), + (sref_v, cpx, cpy, (chroma_w, chroma_h), &mut pred_v), + ] { + let luma = std::ptr::eq(plane, sref_y); + if luma_scale == mc::REF_NO_SCALE { + mc::predict_with_filters( + &plane.data, + plane.width, + plane.true_width, + plane.true_height, + mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }), + mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }), + dim_w, + dim_h, + h_filter, + v_filter, + dst, + fctx, + ); + } else { + mc::predict_scaled( + &plane.data, + plane.width, + plane.true_width, + plane.true_height, + mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }), + mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }), + luma_scale, + dim_w, + dim_h, + h_filter, + v_filter, + dst, + fctx, + ); + } } - } - // lane-gmaffine r1: the warp filter REPLACES the translational - // prediction just built (libaom builds one or the other), same as - // the 16x16+ leaf's own call trio. - // lane-t900 r28: `allow_warp`'s scaled-reference bail-out, which this - // leaf was missing -- it is the defect the 8x8-leaf refusal hid (a - // warped 8x8 leaf over a superres reference; libaom predicts it - // translationally, every symbol still read). - if let Some(params) = warp_params.as_ref().filter(|_| luma_scale == mc::REF_NO_SCALE) { - crate::warp::warp_affine( - params, &sref_y.data, sref_y.true_width as i32, sref_y.true_height as i32, - sref_y.width as i32, &mut pred_y, px as i32, py as i32, SIDE as i32, - SIDE as i32, SIDE as i32, 0, 0, fctx, - ); - // `av1_init_warp_params`'s per-plane `block_width/height < 8` - // bail-out: an 8x8 leaf's chroma plane block is narrower than 8 - // at any subsampled format (4:2:0 4x4, 4:2:2 4x8), so it is - // predicted translationally even when the luma warps; 4:4:4's - // 8x8 chroma warps with the luma. - #[allow(clippy::absurd_extreme_comparisons)] - if chroma_w >= 8 { - crate::warp::warp_affine( - params, &sref_u.data, sref_u.true_width as i32, sref_u.true_height as i32, - sref_u.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_w as i32, - chroma_h as i32, chroma_w as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx, - ); + // lane-gmaffine r1: the warp filter REPLACES the translational + // prediction just built (libaom builds one or the other), same as + // the 16x16+ leaf's own call trio. + // lane-t900 r28: `allow_warp`'s scaled-reference bail-out, which this + // leaf was missing -- it is the defect the 8x8-leaf refusal hid (a + // warped 8x8 leaf over a superres reference; libaom predicts it + // translationally, every symbol still read). + if let Some(params) = warp_params + .as_ref() + .filter(|_| luma_scale == mc::REF_NO_SCALE) + { crate::warp::warp_affine( - params, &sref_v.data, sref_v.true_width as i32, sref_v.true_height as i32, - sref_v.width as i32, &mut pred_v, cpx as i32, cpy as i32, chroma_w as i32, - chroma_h as i32, chroma_w as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx, + params, + &sref_y.data, + sref_y.true_width as i32, + sref_y.true_height as i32, + sref_y.width as i32, + &mut pred_y, + px as i32, + py as i32, + SIDE as i32, + SIDE as i32, + SIDE as i32, + 0, + 0, + fctx, ); + // `av1_init_warp_params`'s per-plane `block_width/height < 8` + // bail-out: an 8x8 leaf's chroma plane block is narrower than 8 + // at any subsampled format (4:2:0 4x4, 4:2:2 4x8), so it is + // predicted translationally even when the luma warps; 4:4:4's + // 8x8 chroma warps with the luma. + #[allow(clippy::absurd_extreme_comparisons)] + if chroma_w >= 8 { + crate::warp::warp_affine( + params, + &sref_u.data, + sref_u.true_width as i32, + sref_u.true_height as i32, + sref_u.width as i32, + &mut pred_u, + cpx as i32, + cpy as i32, + chroma_w as i32, + chroma_h as i32, + chroma_w as i32, + ss_x(fctx) as i32, + ss_y(fctx) as i32, + fctx, + ); + crate::warp::warp_affine( + params, + &sref_v.data, + sref_v.true_width as i32, + sref_v.true_height as i32, + sref_v.width as i32, + &mut pred_v, + cpx as i32, + cpy as i32, + chroma_w as i32, + chroma_h as i32, + chroma_w as i32, + ss_x(fctx) as i32, + ss_y(fctx) as i32, + fctx, + ); + } } - } - if let Some(plan) = &obmc { - obmc_run(plan, refpix, &mut pred_y, &mut pred_u, &mut pred_v, fctx); - } + if let Some(plan) = &obmc { + obmc_run(plan, refpix, &mut pred_y, &mut pred_u, &mut pred_v, fctx); + } - // Non-wedge interintra blend, mutually exclusive with OBMC (the - // motion_mode symbol is not read for an interintra block). - if let Some(ii) = interintra_mode { - interintra_blend(y, px, py, SIDE, SIDE, SIDE, 0, 0, ii, wedge_mask, &mut pred_y, fctx); - interintra_blend( - u, cpx, cpy, chroma_w, chroma_h, chroma_w, ss_x(fctx), ss_y(fctx), ii, wedge_mask, - &mut pred_u, fctx, - ); - interintra_blend( - v, cpx, cpy, chroma_w, chroma_h, chroma_w, ss_x(fctx), ss_y(fctx), ii, wedge_mask, - &mut pred_v, fctx, - ); - } + // Non-wedge interintra blend, mutually exclusive with OBMC (the + // motion_mode symbol is not read for an interintra block). + if let Some(ii) = interintra_mode { + interintra_blend( + y, + px, + py, + SIDE, + SIDE, + SIDE, + 0, + 0, + ii, + wedge_mask, + &mut pred_y, + fctx, + ); + interintra_blend( + u, + cpx, + cpy, + chroma_w, + chroma_h, + chroma_w, + ss_x(fctx), + ss_y(fctx), + ii, + wedge_mask, + &mut pred_u, + fctx, + ); + interintra_blend( + v, + cpx, + cpy, + chroma_w, + chroma_h, + chroma_w, + ss_x(fctx), + ss_y(fctx), + ii, + wedge_mask, + &mut pred_v, + fctx, + ); + } - *out = [pred_y, pred_u, pred_v]; + *out = [pred_y, pred_u, pred_v]; }; let deferred = recon_deferred(fctx); let (pred_y, pred_u, pred_v): (Vec, Vec, Vec); let (sy, su, sv) = if deferred { push_pred(fctx, build); ( - Pred::Cur { plane: 0, stride: SIDE, off: 0 }, - Pred::Cur { plane: 1, stride: chroma_w, off: 0 }, - Pred::Cur { plane: 2, stride: chroma_w, off: 0 }, + Pred::Cur { + plane: 0, + stride: SIDE, + off: 0, + }, + Pred::Cur { + plane: 1, + stride: chroma_w, + off: 0, + }, + Pred::Cur { + plane: 2, + stride: chroma_w, + off: 0, + }, ) } else { // The interintra predictor reads this block's own above/left @@ -41866,7 +47595,8 @@ ss_y(fctx), SIDE, (mi_cols as usize, mi_rows as usize), true, - skip, fctx, + skip, + fctx, )? .1 .is_some(); @@ -41875,23 +47605,27 @@ ss_y(fctx), // lane-av1-422sub8rect: the plane block is the (chroma_w, // chroma_h) rect at 4:2:2 -- the recorded write is stride // `chroma_w`, full `chroma_h` rows. - push_mc_rect(1, + push_mc_rect( + 1, cpx, cpy, chroma_w, chroma_w, chroma_h, su, - &ZERO_RESIDUAL[..chroma_w * chroma_h], fctx, + &ZERO_RESIDUAL[..chroma_w * chroma_h], + fctx, ); - push_mc_rect(2, + push_mc_rect( + 2, cpx, cpy, chroma_w, chroma_w, chroma_h, sv, - &ZERO_RESIDUAL[..chroma_w * chroma_h], fctx, + &ZERO_RESIDUAL[..chroma_w * chroma_h], + fctx, ); luma_grid = Grid::Zero(SIDE * SIDE); u_grid = Grid::Zero(chroma_w * chroma_h); @@ -41923,7 +47657,8 @@ ss_y(fctx), scan8, scan4, reduced_tx_set, - split8, fctx, + split8, + fctx, )?; luma_grid = grid8; // 4:4:4 lossless 8x8 inter leaf (compound twin of the single-ref @@ -41932,8 +47667,17 @@ ss_y(fctx), // 4:2:0/4:4:4 square read are the `else` below. if chroma_w == 8 && lossless(fctx) && !mono(fctx) { let (ug, vg) = leaf8_inter_chroma_lossless( - dec, cdfs, neighbours, u, v, su, sv, - leaf_mi, (cpx, cpy), base_q_idx, fctx, + dec, + cdfs, + neighbours, + u, + v, + su, + sv, + leaf_mi, + (cpx, cpy), + base_q_idx, + fctx, )?; u_grid = ug; v_grid = vg; @@ -41954,7 +47698,8 @@ ss_y(fctx), cpy, su, Some(luma_tx_type), - None, fctx, + None, + fctx, )? .0 } else { @@ -41973,7 +47718,8 @@ ss_y(fctx), base_q_idx, su, Some(luma_tx_type), - None, fctx, + None, + fctx, )? .0 }; @@ -41992,7 +47738,8 @@ ss_y(fctx), cpy, sv, Some(luma_tx_type), - None, fctx, + None, + fctx, )? .0 } else { @@ -42011,7 +47758,8 @@ ss_y(fctx), base_q_idx, sv, Some(luma_tx_type), - None, fctx, + None, + fctx, )? .0 }; @@ -42142,11 +47890,9 @@ ss_y(fctx), let palette_uv_cache = neighbours.palette_uv_cache_mi(leaf_mi); let mut palette_y_pending: Option<(usize, [u16; 8])> = None; let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None; - if allow_screen_content_tools - && let Some(bsize_ctx) = palette_bsize_ctx(SIDE) - { - let use_palette_y = - mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][palette_ctx]) != 0; + if allow_screen_content_tools && let Some(bsize_ctx) = palette_bsize_ctx(SIDE) { + let use_palette_y = mode == DC_PRED + && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][palette_ctx]) != 0; if use_palette_y { let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); palette_y_pending = Some((n, read_palette_colors_y(dec, n, &palette_cache, fctx))); @@ -42222,8 +47968,13 @@ ss_y(fctx), // then the shared chroma one, after the WHOLE mode-info read. let palette_y = palette_y_pending.map(|(n, colors)| { let map = decode_color_index_map_wh( - dec, cdfs, n, SIDE, SIDE, - palette_onscreen(rmi, cmi, SIDE, SIDE, fctx), false, + dec, + cdfs, + n, + SIDE, + SIDE, + palette_onscreen(rmi, cmi, SIDE, SIDE, fctx), + false, ); hit!(PALETTE_HITS); hit!(INTRA_IN_INTER_PALETTE_Y_HITS); @@ -42234,7 +47985,11 @@ ss_y(fctx), c.set(v); }); } - PaletteY { size: n, colors, map } + PaletteY { + size: n, + colors, + map, + } }); let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { // `av1_get_plane_block_size(BLOCK_8X8, ss)` at the sequence's own @@ -42246,8 +48001,7 @@ ss_y(fctx), (chroma_w, chroma_h), (ss_x(fctx), ss_y(fctx)), ); - let map = - decode_color_index_map_wh(dec, cdfs, n, chroma_w, chroma_h, on, true); + let map = decode_color_index_map_wh(dec, cdfs, n, chroma_w, chroma_h, on, true); hit!(PALETTE_UV_HITS); hit!(INTRA_IN_INTER_PALETTE_UV_HITS); hit_do! { @@ -42257,7 +48011,12 @@ ss_y(fctx), c.set(v); }); } - PaletteUv { size: n, u_colors, v_colors, map } + PaletteUv { + size: n, + u_colors, + v_colors, + map, + } }); palette_record8 = ( palette_y.as_ref().map_or(0, |p| p.size), @@ -42269,8 +48028,9 @@ ss_y(fctx), // the block edge (spec 7.11.2/7.11.4) -- these ride the // [`PALETTE_PRED`] slot into each `reconstruct`/`read_plane` call // below, exactly as the key-frame and >=16 intra-in-inter paths do. - let palette_y_buf: Option> = - palette_y.as_ref().map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()); + let palette_y_buf: Option> = palette_y + .as_ref() + .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()); let palette_uv_bufs: Option<(Vec, Vec)> = palette_uv.as_ref().map(|p| { ( p.map.iter().map(|&i| p.u_colors[i as usize]).collect(), @@ -42314,7 +48074,8 @@ ss_y(fctx), SIDE, (mi_cols as usize, mi_rows as usize), false, - skip, fctx, + skip, + fctx, )? .1; // lane-leaf8tx r4: the per-TU loop below is entropy- and pixel-exact @@ -42346,7 +48107,8 @@ ss_y(fctx), set_palette_pred(window, fctx); } let tu_grid = if skip { - push_intra(0, + push_intra( + 0, tu_px, tu_py, tx_px, @@ -42356,7 +48118,8 @@ ss_y(fctx), &ZERO_RESIDUAL[..tx_px * tx_px], None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); Grid::Zero(tx_px * tx_px) } else { @@ -42388,7 +48151,8 @@ ss_y(fctx), None, filter_intra, Some(tu_skip_ctx), - smooth_neighbor, fctx, + smooth_neighbor, + fctx, )? }; neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); @@ -42399,7 +48163,8 @@ ss_y(fctx), if let Some(buf) = &palette_y_buf { set_palette_pred(buf.clone(), fctx); } - push_intra(0, + push_intra( + 0, px, py, SIDE, @@ -42409,7 +48174,8 @@ ss_y(fctx), &ZERO_RESIDUAL[..SIDE * SIDE], None, filter_intra, - smooth_neighbor, fctx, + smooth_neighbor, + fctx, ); } // CfL's AC contribution is the luma this leaf just reconstructed, @@ -42421,7 +48187,8 @@ ss_y(fctx), // lane-av1-422sub8rect: the plane block is the (chroma_w, // chroma_h) rect at 4:2:2 -- the recorded prediction/write uses // the rect push. - push_intra_rect(1, + push_intra_rect( + 1, cpx, cpy, chroma_w, @@ -42432,12 +48199,14 @@ ss_y(fctx), &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - push_intra_rect(2, + push_intra_rect( + 2, cpx, cpy, chroma_w, @@ -42448,7 +48217,8 @@ ss_y(fctx), &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, - smooth_neighbor_uv, fctx, + smooth_neighbor_uv, + fctx, ); luma_grid = Grid::Zero(SIDE * SIDE); u_grid = Grid::Zero(chroma_w * chroma_h); @@ -42465,35 +48235,36 @@ ss_y(fctx), set_palette_pred(buf.clone(), fctx); } read_plane( - dec, - cdfs, - // lane-uv8 r3: an intra leaf inside an inter frame is - // `is_inter == 0` in `av1_get_ext_tx_set_type`, so its 8x8 - // luma reads the INTRA set -- seven-type - // `EXT_TX_SET_DTT4_IDTX_1DDCT` when `reduced_tx_set == 0`, - // five-type `EXT_TX_SET_DTT4_IDTX` when it is 1. Hardcoding - // the reduced set read the wrong ALPHABET (class - // [[wrong-alphabet-same-value]]) and desynced at the leaf's - // first `tx_type`. - txbset_for(8, reduced_tx_set), - scan8, - 0, - around[0], - mode, - mode, - angle_delta_y, - reach, - y, - px, - py, - SIDE, - TX8, - base_q_idx, - None, - filter_intra, - None, - smooth_neighbor, fctx, - )? + dec, + cdfs, + // lane-uv8 r3: an intra leaf inside an inter frame is + // `is_inter == 0` in `av1_get_ext_tx_set_type`, so its 8x8 + // luma reads the INTRA set -- seven-type + // `EXT_TX_SET_DTT4_IDTX_1DDCT` when `reduced_tx_set == 0`, + // five-type `EXT_TX_SET_DTT4_IDTX` when it is 1. Hardcoding + // the reduced set read the wrong ALPHABET (class + // [[wrong-alphabet-same-value]]) and desynced at the leaf's + // first `tx_type`. + txbset_for(8, reduced_tx_set), + scan8, + 0, + around[0], + mode, + mode, + angle_delta_y, + reach, + y, + px, + py, + SIDE, + TX8, + base_q_idx, + None, + filter_intra, + None, + smooth_neighbor, + fctx, + )? }; let ac = alpha.map(|_| cfl_src(px, py, SIDE)); // lane-av1-422sub8rect: at 4:2:2 the plane block is the BLOCK_4X8 @@ -42524,88 +48295,144 @@ ss_y(fctx), // TX_4X4 unit in the `else` below. let (mut uo, mut vo) = (Vec::new(), Vec::new()); read_intra_chroma_lossless( - dec, cdfs, neighbours, u, v, leaf_mi, (px, py), (cpx, cpy), - SIDE, (chroma_w, chroma_w), (0, 0), - (chroma_w, chroma_w), chroma_w, reach, - (y.width, y.height), mode, uv_predict_mode, angle_delta_uv, - palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])), - smooth_neighbor_uv, base_q_idx, &mut uo, &mut vo, fctx, - )?; - u_grid = if uo.is_empty() { Grid::Zero(64) } else { Grid::Own(uo) }; - v_grid = if vo.is_empty() { Grid::Zero(64) } else { Grid::Own(vo) }; - chroma_stamped_per_unit = true; - hit!(LLINTRA8_CHROMA_WALK_HITS); - } else { - if let Some((ub, _)) = &palette_uv_bufs { - set_palette_pred(ub.clone(), fctx); - } - u_grid = if chroma_422 { - read_rect_chroma_unit( - dec, cdfs, chroma_set, chroma_scan, chroma_w, chroma_h, 1, - chroma_around_u, uv_predict_mode, angle_delta_uv, reach, u, - cpx, cpy, base_q_idx, None, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - smooth_neighbor_uv, fctx, - )? - } else { - read_plane( dec, cdfs, - chroma_set, - chroma_scan, - 1, - chroma_around_u, - mode, - uv_predict_mode, - angle_delta_uv, - reach, + neighbours, u, - cpx, - cpy, + v, + leaf_mi, + (px, py), + (cpx, cpy), + SIDE, + (chroma_w, chroma_w), + (0, 0), + (chroma_w, chroma_w), chroma_w, - chroma_tx, - base_q_idx, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )? - }; - if let Some((_, vb)) = &palette_uv_bufs { - set_palette_pred(vb.clone(), fctx); - } - v_grid = if chroma_422 { - read_rect_chroma_unit( - dec, cdfs, chroma_set, chroma_scan, chroma_w, chroma_h, 2, - chroma_around_v, uv_predict_mode, angle_delta_uv, reach, v, - cpx, cpy, base_q_idx, None, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - smooth_neighbor_uv, fctx, - )? - } else { - read_plane( - dec, - cdfs, - chroma_set, - chroma_scan, - 2, - chroma_around_v, + reach, + (y.width, y.height), mode, uv_predict_mode, angle_delta_uv, - reach, - v, - cpx, - cpy, - chroma_w, - chroma_tx, + palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])), + smooth_neighbor_uv, base_q_idx, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )? - }; + &mut uo, + &mut vo, + fctx, + )?; + u_grid = if uo.is_empty() { + Grid::Zero(64) + } else { + Grid::Own(uo) + }; + v_grid = if vo.is_empty() { + Grid::Zero(64) + } else { + Grid::Own(vo) + }; + chroma_stamped_per_unit = true; + hit!(LLINTRA8_CHROMA_WALK_HITS); + } else { + if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone(), fctx); + } + u_grid = if chroma_422 { + read_rect_chroma_unit( + dec, + cdfs, + chroma_set, + chroma_scan, + chroma_w, + chroma_h, + 1, + chroma_around_u, + uv_predict_mode, + angle_delta_uv, + reach, + u, + cpx, + cpy, + base_q_idx, + None, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + smooth_neighbor_uv, + fctx, + )? + } else { + read_plane( + dec, + cdfs, + chroma_set, + chroma_scan, + 1, + chroma_around_u, + mode, + uv_predict_mode, + angle_delta_uv, + reach, + u, + cpx, + cpy, + chroma_w, + chroma_tx, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + None, + smooth_neighbor_uv, + fctx, + )? + }; + if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone(), fctx); + } + v_grid = if chroma_422 { + read_rect_chroma_unit( + dec, + cdfs, + chroma_set, + chroma_scan, + chroma_w, + chroma_h, + 2, + chroma_around_v, + uv_predict_mode, + angle_delta_uv, + reach, + v, + cpx, + cpy, + base_q_idx, + None, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + smooth_neighbor_uv, + fctx, + )? + } else { + read_plane( + dec, + cdfs, + chroma_set, + chroma_scan, + 2, + chroma_around_v, + mode, + uv_predict_mode, + angle_delta_uv, + reach, + v, + cpx, + cpy, + chroma_w, + chroma_tx, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + None, + smooth_neighbor_uv, + fctx, + )? + }; } } } @@ -42614,7 +48441,7 @@ ss_y(fctx), // but `record_mi` rewrites all three planes of these cells at once -- so // save plane 0 across it, exactly as `record_split_luma` leaves plane 0 // alone at the bigger block sizes. -// lane-lossless3: `!skip` too. A SKIP block codes no coefficients and so + // lane-lossless3: `!skip` too. A SKIP block codes no coefficients and so // publishes nothing per transform unit, and on a LOSSLESS frame // `read_block_tx_size` hands back 4x4 leaves for a skip block as well // (libaom's `read_tx_size` returns TX_4X4 before it reads anything), so @@ -42654,11 +48481,20 @@ ss_y(fctx), ( [ [neighbours.left[leaf_mi.0][1], neighbours.left[leaf_mi.0][2]], - [neighbours.left[leaf_mi.0 + 1][1], neighbours.left[leaf_mi.0 + 1][2]], + [ + neighbours.left[leaf_mi.0 + 1][1], + neighbours.left[leaf_mi.0 + 1][2], + ], ], [ - [neighbours.above[leaf_mi.1][1], neighbours.above[leaf_mi.1][2]], - [neighbours.above[leaf_mi.1 + 1][1], neighbours.above[leaf_mi.1 + 1][2]], + [ + neighbours.above[leaf_mi.1][1], + neighbours.above[leaf_mi.1][2], + ], + [ + neighbours.above[leaf_mi.1 + 1][1], + neighbours.above[leaf_mi.1 + 1][2], + ], ], ) }); @@ -42711,7 +48547,12 @@ ss_y(fctx), leaf_mi, 2, if split8 { 4 } else { 8 }, - if is_inter { leaf_refs.0.max(LAST_FRAME) } else { 0 }, fctx, + if is_inter { + leaf_refs.0.max(LAST_FRAME) + } else { + 0 + }, + fctx, ); Ok(( skip, @@ -42774,13 +48615,33 @@ pub(crate) fn decode_inter_frame_tile( fctx: &crate::decode::FrameCtx, ) -> Result { decode_inter_frame_tile_lr( - data, mi_cols, mi_rows, base_q_idx, frame_width, frame_height, refpix, cdef, - loop_filter, allow_high_precision_mv, force_integer_mv, interp_fixed, - enable_dual_filter, reference_select, reduced_tx_set, tx_select, - &LoopRestorationParams::default(), initial_cdfs, NO_SIGN_BIAS, false, + data, + mi_cols, + mi_rows, + base_q_idx, + frame_width, + frame_height, + refpix, + cdef, + loop_filter, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + reference_select, + reduced_tx_set, + tx_select, + &LoopRestorationParams::default(), + initial_cdfs, + NO_SIGN_BIAS, + false, // `enable_filter_intra`: as the `false`s beside it, this convenience // entry names a stream written without the sequence bit (lane-fintra). - switchable_motion_mode, false, false, DeltaParams::default(), fctx, + switchable_motion_mode, + false, + false, + DeltaParams::default(), + fctx, ) } @@ -43115,7 +48976,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // capability gap. No aomenc witness reaches it: superres changes width // alone, and the only both-axes route (dynamic resize) stops earlier on // this decoder. See `lanes/av1hdr.report.md` §4.3. - if refpix.dims(1).is_none_or(|(_, h)| h != frame_height as usize) { + if refpix + .dims(1) + .is_none_or(|(_, h)| h != frame_height as usize) + { return Err(unsupported( "a reference picture whose height does not match this frame's own true size", )); @@ -43125,7 +48989,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( let (sb_cols, sb_rows) = (cols.div_ceil(2), rows.div_ceil(2)); fctx.cdef_bits.with(|c| c.set(cdef.bits)); fctx.cdef_sb_cols.with(|c| c.set(sb_cols as usize)); - fctx.cdef_idx_grid.with(|g| *g.borrow_mut() = vec![0u8; sb_cols as usize * sb_rows as usize]); + fctx.cdef_idx_grid + .with(|g| *g.borrow_mut() = vec![0u8; sb_cols as usize * sb_rows as usize]); let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK); let mut y = PlaneBuf { @@ -43185,7 +49050,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( cols as usize * 2, rows as usize * 2, mi_cols as usize, - mi_rows as usize, fctx, + mi_rows as usize, + fctx, ); let mut grid = MiGrid::new(mi_cols as usize, mi_rows as usize); // spec 7.16/libaom `av1_alloc_restoration_struct`: the unit grid is @@ -43260,9 +49126,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( #[allow(unsafe_code)] let ssnap = unsafe { crate::par::Shared::from_ptr(std::ptr::from_mut(&mut pipe_snap)) }; let snap = &mut pipe_snap; - batch.submit(move || { - pipe_run(&sync2, sy, su, sv, sn, cfg, snap, lr_sync2.as_deref(), &ctx) - }); + batch + .submit(move || pipe_run(&sync2, sy, su, sv, sn, cfg, snap, lr_sync2.as_deref(), &ctx)); if let Some(ls) = lr_sync.clone() { let lcfg = LrCfg { lr, @@ -43274,7 +49139,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( let ctx2 = crate::decode::filter_ctx_copy(fctx); batch.submit(move || pipe_run_lr(&ls, sy, su, sv, ssnap, lcfg, &ctx2)); } - PipeGuard { sync, batch: Some(batch), nbands, lr_sync } + PipeGuard { + sync, + batch: Some(batch), + nbands, + lr_sync, + } }); if !pipe_on && wave_stats() { PIPE_WHOLE.fetch_add(1, Relaxed); @@ -43362,195 +49232,201 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( ); hit!(TILE_HITS); - // lane-sb128 r2: at `sb_size == 128` the tile walks each 128x128 - // superblock's four 64x64 quadrants in libaom `decode_partition` order - // (TL, TR, BL, BR) and reads the 128 root's own loop-restoration units and - // partition symbol once per superblock -- exactly what the key-frame tile - // loop does; the 64-level body below is unchanged, `read_cdef`'s - // per-64x64-quadrant reset (`CDEF_TRANSMITTED`) already matches libaom's - // `cdef_idx[(mi_row & 16) >> 4 * 2 + (mi_col & 16) >> 4]` slot per quadrant. - // lane-sb128c r1: set when the 128 root resolved to `PARTITION_NONE` -- its - // one 128x128 inter block covers all four 64x64 quadrants, so the remaining - // three items of this superblock carry no syntax at all (same skip the - // key-frame tile loop runs). - let mut sb128_none = false; - // lane-wave1 step (ii): at one reconstruction thread the recorded writes - // are performed at their push sites (nothing reaches the queue below). - let _recon_inline = ReconInline::install(fctx, &mut y, &mut u, &mut v); - // lane-wave1 step (ii): one job per superblock (per 128x128 superblock - // when `sb128`, since a 128 block writes across its four 64x64 visits). - let wave_shift = u32::from(sb128); - let (wave_r0, wave_c0) = ((sb_r0 >> wave_shift) as usize, (sb_c0 >> wave_shift) as usize); - let (wave_rows, wave_cols) = if sb_r1 > sb_r0 && sb_c1 > sb_c0 { - ( - ((sb_r1 - 1) >> wave_shift) as usize - wave_r0 + 1, - ((sb_c1 - 1) >> wave_shift) as usize - wave_c0 + 1, - ) - } else { - (0, 0) - }; - let _wave = WaveGuard::install(fctx, &mut y, &mut u, &mut v, wave_rows, wave_cols); - let waving = fctx.wave.with(|w| w.borrow().is_some()); - let mut wave_job = (0usize, 0usize); - for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) { - // lane-wave1: the previous superblock's recorded writes -- handed to - // the wavefront workers, or replayed here at one recon thread (where - // the queue is empty, every write having run at its push site). - if waving { - if sb_start { - wave_submit(fctx, wave_job.0, wave_job.1); - wave_job = ( - (sb_r >> wave_shift) as usize - wave_r0, - (sb_c >> wave_shift) as usize - wave_c0, - ); - } + // lane-sb128 r2: at `sb_size == 128` the tile walks each 128x128 + // superblock's four 64x64 quadrants in libaom `decode_partition` order + // (TL, TR, BL, BR) and reads the 128 root's own loop-restoration units and + // partition symbol once per superblock -- exactly what the key-frame tile + // loop does; the 64-level body below is unchanged, `read_cdef`'s + // per-64x64-quadrant reset (`CDEF_TRANSMITTED`) already matches libaom's + // `cdef_idx[(mi_row & 16) >> 4 * 2 + (mi_col & 16) >> 4]` slot per quadrant. + // lane-sb128c r1: set when the 128 root resolved to `PARTITION_NONE` -- its + // one 128x128 inter block covers all four 64x64 quadrants, so the remaining + // three items of this superblock carry no syntax at all (same skip the + // key-frame tile loop runs). + let mut sb128_none = false; + // lane-wave1 step (ii): at one reconstruction thread the recorded writes + // are performed at their push sites (nothing reaches the queue below). + let _recon_inline = ReconInline::install(fctx, &mut y, &mut u, &mut v); + // lane-wave1 step (ii): one job per superblock (per 128x128 superblock + // when `sb128`, since a 128 block writes across its four 64x64 visits). + let wave_shift = u32::from(sb128); + let (wave_r0, wave_c0) = ( + (sb_r0 >> wave_shift) as usize, + (sb_c0 >> wave_shift) as usize, + ); + let (wave_rows, wave_cols) = if sb_r1 > sb_r0 && sb_c1 > sb_c0 { + ( + ((sb_r1 - 1) >> wave_shift) as usize - wave_r0 + 1, + ((sb_c1 - 1) >> wave_shift) as usize - wave_c0 + 1, + ) } else { - flush_recon(fctx, &mut y, &mut u, &mut v); - } - if row_start { - if let Some(p) = &pipe { - // Reconstruction complete through this pixel row: the parse - // position itself when reconstruction is inline, the - // wavefront's own leading completed rows otherwise. - let px = if waving { - ((wave_r0 + wave_rows_complete(fctx)) << wave_shift) * 64 - } else { - sb_r as usize * 64 - }; - p.note(px / 64); + (0, 0) + }; + let _wave = WaveGuard::install(fctx, &mut y, &mut u, &mut v, wave_rows, wave_cols); + let waving = fctx.wave.with(|w| w.borrow().is_some()); + let mut wave_job = (0usize, 0usize); + for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) { + // lane-wave1: the previous superblock's recorded writes -- handed to + // the wavefront workers, or replayed here at one recon thread (where + // the queue is empty, every write having run at its push site). + if waving { + if sb_start { + wave_submit(fctx, wave_job.0, wave_job.1); + wave_job = ( + (sb_r >> wave_shift) as usize - wave_r0, + (sb_c >> wave_shift) as usize - wave_c0, + ); + } + } else { + flush_recon(fctx, &mut y, &mut u, &mut v); + } + if row_start { + if let Some(p) = &pipe { + // Reconstruction complete through this pixel row: the parse + // position itself when reconstruction is inline, the + // wavefront's own leading completed rows otherwise. + let px = if waving { + ((wave_r0 + wave_rows_complete(fctx)) << wave_shift) * 64 + } else { + sb_r as usize * 64 + }; + p.note(px / 64); + } + neighbours.start_row(); } - neighbours.start_row(); - } - if sb_start { - sb128_none = false; - } - if sb128_none { - continue; - } - { - let mut sb128_rect = None; - let mut sb128_ab = None; - if sb128 && sb_start { - let part128 = read_sb128_root( - &mut dec, - &mut cdfs, - &neighbours, - lr, - &mut lr_grid, - &mut lr_reference, - sb_r, - sb_c, - mi_cols, - mi_rows, fctx, - )?; - if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part128) { - // lane-sb128c r9: an AB shape at the 128 root -- one - // 128x64/64x128 half plus two 64x64 quadrants, same visit - // order as the key-frame path. - sb128_none = true; - sb128_ab = Some(part128); - } - if matches!(part128, PARTITION_HORZ | PARTITION_VERT) { - // Two 128x64 (HORZ) or two 64x128 (VERT) inter blocks; the - // whole 128x128 root is consumed here, so the remaining - // three 64-quadrant visits of this superblock carry no - // syntax (same skip the NONE arm runs). - sb128_none = true; - sb128_rect = Some(part128); - fctx.cdef_transmitted.with(|c| c.set(false)); - } - if part128 == PARTITION_NONE { - // One 128x128 inter block. Its luma transform is - // `max_txsize_rect_lookup[BLOCK_128X128]` = TX_64X64 (four - // units, read as var-tx leaves), its uv plane block is - // 64x64 with TX_32X32 units (`av1_get_max_uv_txsize`), and - // `size_group_lookup[BLOCK_128X128]` is 3, same as 64x64. - sb128_none = true; - fctx.cdef_transmitted.with(|c| c.set(false)); - } - } - if !sb128 { - crate::restoration::read_lr( - &mut dec, - &mut cdfs, - lr, - &mut lr_grid, - &mut lr_reference, - sb_r * SB_MI, - sb_c * SB_MI, - SB_MI, fctx, - ); + if sb_start { + sb128_none = false; } - fctx.cdef_transmitted.with(|c| c.set(false)); - let sb_at = (sb_r as usize * 4, sb_c as usize * 4); - // lane-inter4 r1: every rect inter piece below is the same - // `decode_inter_block` call with only position / true footprint / - // transform-set differing; the macro keeps the new arms readable - // instead of six more 60-line copies of the argument list. - macro_rules! inter_piece { - ($at_mi:expr, $side:expr, $li:expr, $lt:expr, $ch:expr, $ltx:expr, - $ctx:expr, $sl:expr, $sc:expr, $sg:expr, $ww:expr, $wh:expr) => { - decode_inter_block( + if sb128_none { + continue; + } + { + let mut sb128_rect = None; + let mut sb128_ab = None; + if sb128 && sb_start { + let part128 = read_sb128_root( &mut dec, &mut cdfs, - &mut neighbours, - &mut grid, - $at_mi, - $side, + &neighbours, + lr, + &mut lr_grid, + &mut lr_reference, + sb_r, + sb_c, mi_cols, mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - $li, - $lt, - $ch, - $ltx, - $ctx, - $sl, - $sc, - $sg, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - // lane-sb128c r3: `reject_residual` is about a - // RECTANGULAR strip decoded with square dimensions -- - // the 128x128 NONE root is square, and a hardcoded - // `true` refused every one of them at its first - // non-skip block. - $ww != $side || $wh != $side, - $ww, - $wh, - allow_screen_content_tools, - frame_width as usize, fctx, - )? - }; - } - // lane-inter16ab r1: one 8x8 inter leaf of a 16x16-level AB - // partition (libaom `decode_partition` PARTITION_HORZ_A/_B/ - // VERT_A/_B at BLOCK_16X16 code `bsize2` = BLOCK_8X8 for two of - // their three pieces, decodeframe.c ~1900). Same body the - // PARTITION_SPLIT arm runs per leaf, minus its own partition - // symbol (an AB piece carries none) and its `prev_leaves` - // bookkeeping. - macro_rules! inter_leaf8 { + fctx, + )?; + if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part128) { + // lane-sb128c r9: an AB shape at the 128 root -- one + // 128x64/64x128 half plus two 64x64 quadrants, same visit + // order as the key-frame path. + sb128_none = true; + sb128_ab = Some(part128); + } + if matches!(part128, PARTITION_HORZ | PARTITION_VERT) { + // Two 128x64 (HORZ) or two 64x128 (VERT) inter blocks; the + // whole 128x128 root is consumed here, so the remaining + // three 64-quadrant visits of this superblock carry no + // syntax (same skip the NONE arm runs). + sb128_none = true; + sb128_rect = Some(part128); + fctx.cdef_transmitted.with(|c| c.set(false)); + } + if part128 == PARTITION_NONE { + // One 128x128 inter block. Its luma transform is + // `max_txsize_rect_lookup[BLOCK_128X128]` = TX_64X64 (four + // units, read as var-tx leaves), its uv plane block is + // 64x64 with TX_32X32 units (`av1_get_max_uv_txsize`), and + // `size_group_lookup[BLOCK_128X128]` is 3, same as 64x64. + sb128_none = true; + fctx.cdef_transmitted.with(|c| c.set(false)); + } + } + if !sb128 { + crate::restoration::read_lr( + &mut dec, + &mut cdfs, + lr, + &mut lr_grid, + &mut lr_reference, + sb_r * SB_MI, + sb_c * SB_MI, + SB_MI, + fctx, + ); + } + fctx.cdef_transmitted.with(|c| c.set(false)); + let sb_at = (sb_r as usize * 4, sb_c as usize * 4); + // lane-inter4 r1: every rect inter piece below is the same + // `decode_inter_block` call with only position / true footprint / + // transform-set differing; the macro keeps the new arms readable + // instead of six more 60-line copies of the argument list. + macro_rules! inter_piece { + ($at_mi:expr, $side:expr, $li:expr, $lt:expr, $ch:expr, $ltx:expr, + $ctx:expr, $sl:expr, $sc:expr, $sg:expr, $ww:expr, $wh:expr) => { + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + $at_mi, + $side, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + $li, + $lt, + $ch, + $ltx, + $ctx, + $sl, + $sc, + $sg, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + // lane-sb128c r3: `reject_residual` is about a + // RECTANGULAR strip decoded with square dimensions -- + // the 128x128 NONE root is square, and a hardcoded + // `true` refused every one of them at its first + // non-skip block. + $ww != $side || $wh != $side, + $ww, + $wh, + allow_screen_content_tools, + frame_width as usize, + fctx, + )? + }; + } + // lane-inter16ab r1: one 8x8 inter leaf of a 16x16-level AB + // partition (libaom `decode_partition` PARTITION_HORZ_A/_B/ + // VERT_A/_B at BLOCK_16X16 code `bsize2` = BLOCK_8X8 for two of + // their three pieces, decodeframe.c ~1900). Same body the + // PARTITION_SPLIT arm runs per leaf, minus its own partition + // symbol (an AB piece carries none) and its `prev_leaves` + // bookkeeping. + macro_rules! inter_leaf8 { ($outer:expr, $leaf:expr) => {{ let leaf_mi = $leaf; let ( @@ -43617,338 +49493,324 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } }}; } - if let Some(part128) = sb128_ab { - // libaom `decode_partition` (decodeframe.c): HORZ_A = TL, TR, - // bottom half; HORZ_B = top half, BL, BR; VERT_A = TL, BL, - // right half; VERT_B = left half, TR, BR. AB only comes from - // the full alphabet symbol (both halves in frame), so there is - // no `i > 0` edge break to mirror. - let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); - let base_mi = sub16_to_mi(at128); - let (br_mi, bc_mi) = (base_mi.0 + 16, base_mi.1 + 16); - let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); - let _vert_ab = (part128 == PARTITION_VERT_A || part128 == PARTITION_VERT_B) - .then(crate::encode::Reach::vert_ab_partition); - let cdef_copy = |src: (usize, usize), dst: (usize, usize)| { + if let Some(part128) = sb128_ab { + // libaom `decode_partition` (decodeframe.c): HORZ_A = TL, TR, + // bottom half; HORZ_B = top half, BL, BR; VERT_A = TL, BL, + // right half; VERT_B = left half, TR, BR. AB only comes from + // the full alphabet symbol (both halves in frame), so there is + // no `i > 0` edge break to mirror. + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); + let base_mi = sub16_to_mi(at128); + let (br_mi, bc_mi) = (base_mi.0 + 16, base_mi.1 + 16); + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); + let _vert_ab = (part128 == PARTITION_VERT_A || part128 == PARTITION_VERT_B) + .then(crate::encode::Reach::vert_ab_partition); + let cdef_copy = |src: (usize, usize), dst: (usize, usize)| { + fctx.cdef_idx_grid.with(|g| { + let mut g = g.borrow_mut(); + let cols = fctx.cdef_sb_cols.with(|c| c.get()); + if cols == 0 { + return; + } + let (si, di) = ( + (q_r + src.0) * cols + q_c + src.1, + (q_r + dst.0) * cols + q_c + dst.1, + ); + if q_c + src.1 < cols + && q_c + dst.1 < cols + && si < g.len() + && di < g.len() + { + g[di] = g[si]; + } + }); + }; + macro_rules! square64_inter { + ($at_mi:expr) => {{ + fctx.cdef_transmitted.with(|c| c.set(false)); + inter_piece!( + $at_mi, + SB, + TxbSet::Luma64, + TxbSet::Luma64, + TxbSet::Chroma32, + TX32, + TX32, + &scan32, + &scan32, + 3, + SB, + SB + ); + }}; + } + macro_rules! half128_inter { + ($at_mi:expr, $bw:expr, $bh:expr, $src:expr, $dst:expr) => {{ + fctx.cdef_transmitted.with(|c| c.set(false)); + inter_piece!( + $at_mi, + SB * 2, + TxbSet::Luma64, + TxbSet::Luma64, + TxbSet::Chroma32, + TX32, + TX32, + &scan32, + &scan32, + 3, + $bw, + $bh + ); + cdef_copy($src, $dst); + }}; + } + match part128 { + PARTITION_HORZ_A => { + square64_inter!(base_mi); + square64_inter!((base_mi.0, bc_mi)); + half128_inter!((br_mi, base_mi.1), 128, 64, (1, 0), (1, 1)); + } + PARTITION_HORZ_B => { + half128_inter!(base_mi, 128, 64, (0, 0), (0, 1)); + square64_inter!((br_mi, base_mi.1)); + square64_inter!((br_mi, bc_mi)); + } + PARTITION_VERT_A => { + square64_inter!(base_mi); + square64_inter!((br_mi, base_mi.1)); + half128_inter!((base_mi.0, bc_mi), 64, 128, (0, 1), (1, 1)); + } + _ => { + half128_inter!(base_mi, 64, 128, (0, 0), (1, 0)); + square64_inter!((base_mi.0, bc_mi)); + square64_inter!((br_mi, bc_mi)); + } + } + continue; + } + if let Some(part128) = sb128_rect { + // lane-sb128c r7: libaom `decode_partition` (decodeframe.c:1554) + // codes PARTITION_HORZ at the 128 root as `subsize = + // BLOCK_128X64` at (mi_row, mi_col) and a second one at + // (mi_row + hbs, mi_col) only `if (mi_row + hbs < mi_rows)`; + // PARTITION_VERT mirrors it on the column. `hbs` here is + // `mi_size_high[BLOCK_128X128] / 2` = 16 mi. + let horz = part128 == PARTITION_HORZ; + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); + let base_mi = sub16_to_mi(at128); + let (bw, bh) = if horz { (128usize, 64usize) } else { (64, 128) }; + for i in 0..2 { + let at_mi = if horz { + (base_mi.0 + i * 16, base_mi.1) + } else { + (base_mi.0, base_mi.1 + i * 16) + }; + if i > 0 && (at_mi.0 >= mi_rows as usize || at_mi.1 >= mi_cols as usize) { + break; + } + // Each half reads its OWN `cdef_idx` literal: libaom keeps + // `cdef_transmitted[4]`, one flag per 64x64 CDEF unit of a + // 128x128 superblock (`read_cdef`, decodemv.c:50-81), and + // the two halves of a 128-root HORZ/VERT sit in different + // units (index `col_in_sb != 0` + 2 * `row_in_sb != 0`). + // The key-frame 128 loop already resets here; without it + // the second half skipped a `cdef_bits`-wide literal that + // libaom reads, desyncing the tile at that block. + fctx.cdef_transmitted.with(|c| c.set(false)); + inter_piece!( + at_mi, + SB * 2, + TxbSet::Luma64, + TxbSet::Luma64, + TxbSet::Chroma32, + TX32, + TX32, + &scan32, + &scan32, + 3, + bw, + bh + ); + if horz { + hit!(INTER_SB128_HORZ_HITS); + } else { + hit!(INTER_SB128_VERT_HITS); + } + } + // One `cdef_idx` per BLOCK, copied to every 64x64 CDEF unit it + // covers -- both halves of the root read their own, and the + // first one's read lands in the top-left unit while the + // second's lands in the bottom-left (HORZ) / top-right (VERT). + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); fctx.cdef_idx_grid.with(|g| { let mut g = g.borrow_mut(); let cols = fctx.cdef_sb_cols.with(|c| c.get()); if cols == 0 { return; } - let (si, di) = ( - (q_r + src.0) * cols + q_c + src.1, - (q_r + dst.0) * cols + q_c + dst.1, - ); - if q_c + src.1 < cols && q_c + dst.1 < cols && si < g.len() && di < g.len() - { - g[di] = g[si]; + for (src, dst) in if horz { + [((0, 0), (0, 1)), ((1, 0), (1, 1))] + } else { + [((0, 0), (1, 0)), ((0, 1), (1, 1))] + } { + let (si, di) = ( + (q_r + src.0) * cols + q_c + src.1, + (q_r + dst.0) * cols + q_c + dst.1, + ); + if q_c + src.1 < cols + && q_c + dst.1 < cols + && si < g.len() + && di < g.len() + { + g[di] = g[si]; + } } }); - }; - macro_rules! square64_inter { - ($at_mi:expr) => {{ - fctx.cdef_transmitted.with(|c| c.set(false)); - inter_piece!( - $at_mi, SB, - TxbSet::Luma64, TxbSet::Luma64, TxbSet::Chroma32, TX32, TX32, - &scan32, &scan32, 3, SB, SB - ); - }}; - } - macro_rules! half128_inter { - ($at_mi:expr, $bw:expr, $bh:expr, $src:expr, $dst:expr) => {{ - fctx.cdef_transmitted.with(|c| c.set(false)); - inter_piece!( - $at_mi, SB * 2, - TxbSet::Luma64, TxbSet::Luma64, TxbSet::Chroma32, TX32, TX32, - &scan32, &scan32, 3, $bw, $bh - ); - cdef_copy($src, $dst); - }}; - } - match part128 { - PARTITION_HORZ_A => { - square64_inter!(base_mi); - square64_inter!((base_mi.0, bc_mi)); - half128_inter!((br_mi, base_mi.1), 128, 64, (1, 0), (1, 1)); - } - PARTITION_HORZ_B => { - half128_inter!(base_mi, 128, 64, (0, 0), (0, 1)); - square64_inter!((br_mi, base_mi.1)); - square64_inter!((br_mi, bc_mi)); - } - PARTITION_VERT_A => { - square64_inter!(base_mi); - square64_inter!((br_mi, base_mi.1)); - half128_inter!((base_mi.0, bc_mi), 64, 128, (0, 1), (1, 1)); - } - _ => { - half128_inter!(base_mi, 64, 128, (0, 0), (1, 0)); - square64_inter!((base_mi.0, bc_mi)); - square64_inter!((br_mi, bc_mi)); - } + continue; } - continue; - } - if let Some(part128) = sb128_rect { - // lane-sb128c r7: libaom `decode_partition` (decodeframe.c:1554) - // codes PARTITION_HORZ at the 128 root as `subsize = - // BLOCK_128X64` at (mi_row, mi_col) and a second one at - // (mi_row + hbs, mi_col) only `if (mi_row + hbs < mi_rows)`; - // PARTITION_VERT mirrors it on the column. `hbs` here is - // `mi_size_high[BLOCK_128X128] / 2` = 16 mi. - let horz = part128 == PARTITION_HORZ; - let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); - let base_mi = sub16_to_mi(at128); - let (bw, bh) = if horz { (128usize, 64usize) } else { (64, 128) }; - for i in 0..2 { - let at_mi = if horz { - (base_mi.0 + i * 16, base_mi.1) - } else { - (base_mi.0, base_mi.1 + i * 16) - }; - if i > 0 && (at_mi.0 >= mi_rows as usize || at_mi.1 >= mi_cols as usize) { - break; - } - // Each half reads its OWN `cdef_idx` literal: libaom keeps - // `cdef_transmitted[4]`, one flag per 64x64 CDEF unit of a - // 128x128 superblock (`read_cdef`, decodemv.c:50-81), and - // the two halves of a 128-root HORZ/VERT sit in different - // units (index `col_in_sb != 0` + 2 * `row_in_sb != 0`). - // The key-frame 128 loop already resets here; without it - // the second half skipped a `cdef_bits`-wide literal that - // libaom reads, desyncing the tile at that block. - fctx.cdef_transmitted.with(|c| c.set(false)); + if sb128_none { + hit!(INTER_SB128_NONE_HITS); + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); + // lane-sb128c r3: `at128` is in SUB16 units like `sb_at`; + // `decode_inter_block` takes MI. Unconverted it was (0,0) for + // the first 128 root and a quarter-position for every other + // one -- the whole-frame gate never got past superblock 1. inter_piece!( - at_mi, SB * 2, - TxbSet::Luma64, TxbSet::Luma64, TxbSet::Chroma32, TX32, TX32, - &scan32, &scan32, 3, bw, bh + sub16_to_mi(at128), + SB * 2, + TxbSet::Luma64, + TxbSet::Luma64, + TxbSet::Chroma32, + TX32, + TX32, + &scan32, + &scan32, + 3, + SB * 2, + SB * 2 ); - if horz { - hit!(INTER_SB128_HORZ_HITS); - } else { - hit!(INTER_SB128_VERT_HITS); - } + // libaom writes one `cdef_strength` into the block's own + // `MB_MODE_INFO`, which all four 64x64 CDEF units point at + // (mirrors the key-frame 128 NONE block). + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); + fctx.cdef_idx_grid.with(|g| { + let mut g = g.borrow_mut(); + let cols = fctx.cdef_sb_cols.with(|c| c.get()); + if cols > 0 && q_r * cols + q_c < g.len() { + let idx = g[q_r * cols + q_c]; + for (dr, dc) in [(0, 1), (1, 0), (1, 1)] { + let i = (q_r + dr) * cols + q_c + dc; + if q_c + dc < cols && i < g.len() { + g[i] = idx; + } + } + } + }); + continue; } - // One `cdef_idx` per BLOCK, copied to every 64x64 CDEF unit it - // covers -- both halves of the root read their own, and the - // first one's read lands in the top-left unit while the - // second's lands in the bottom-left (HORZ) / top-right (VERT). - let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); - fctx.cdef_idx_grid.with(|g| { - let mut g = g.borrow_mut(); - let cols = fctx.cdef_sb_cols.with(|c| c.get()); - if cols == 0 { - return; + let sb_ctx = neighbours.partition_ctx(sb_at, SB); + let (has_cols, has_rows) = ( + sb_c * SB_MI + SB_MI / 2 < mi_cols, + sb_r * SB_MI + SB_MI / 2 < mi_rows, + ); + // The straddle cases (one or both halves outside the true + // frame) never carry a real alphabet symbol -- spec forces + // SPLIT there (mirrors the intra key-frame tile's own + // three-way write above). Only the (true, true) case can name + // a non-SPLIT value, and this loop below only ever recurses as + // SPLIT -- so a real non-SPLIT part64 here must refuse by name + // instead of silently decoding as SPLIT and desyncing. + let part64 = match (has_cols, has_rows) { + (true, true) => { + let pre_rng = dec.debug_state().0; + if crate::envflags::env_flag!("EC_TRACE_PART") { + eprintln!( + "EC_PART mi_row={} mi_col={} bsize=12 ctx={} rng={}", + sb_r as usize * SB_MI as usize, + sb_c as usize * SB_MI as usize, + sb_ctx, + dec.debug_state().0 + ); + } + let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); + if crate::envflags::env_flag!("EC_AV1_TRACE") { + eprintln!( + "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}", + sb_r * SB_MI, + sb_c * SB_MI + ); + } + p } - for (src, dst) in if horz { - [((0, 0), (0, 1)), ((1, 0), (1, 1))] - } else { - [((0, 0), (1, 0)), ((0, 1), (1, 1))] - } { - let (si, di) = ( - (q_r + src.0) * cols + q_c + src.1, - (q_r + dst.0) * cols + q_c + dst.1, - ); - if q_c + src.1 < cols && q_c + dst.1 < cols && si < g.len() && di < g.len() + (true, false) => { + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if crate::envflags::env_flag!("EC_TRACE_PART") { + eprintln!( + "EC_PARTG mi_row={} mi_col={} bsize=12 ctx={} rng={}", + sb_r as usize * SB_MI as usize, + sb_c as usize * SB_MI as usize, + sb_ctx, + dec.debug_state().0 + ); + } + if bump_edge32_bit( + 4, + dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)), + ) == 1 { - g[di] = g[si]; + PARTITION_SPLIT + } else { + PARTITION_HORZ } } - }); - continue; - } - if sb128_none { - hit!(INTER_SB128_NONE_HITS); - let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); - // lane-sb128c r3: `at128` is in SUB16 units like `sb_at`; - // `decode_inter_block` takes MI. Unconverted it was (0,0) for - // the first 128 root and a quarter-position for every other - // one -- the whole-frame gate never got past superblock 1. - inter_piece!( - sub16_to_mi(at128), SB * 2, - TxbSet::Luma64, TxbSet::Luma64, TxbSet::Chroma32, TX32, TX32, - &scan32, &scan32, 3, SB * 2, SB * 2 - ); - // libaom writes one `cdef_strength` into the block's own - // `MB_MODE_INFO`, which all four 64x64 CDEF units point at - // (mirrors the key-frame 128 NONE block). - let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); - fctx.cdef_idx_grid.with(|g| { - let mut g = g.borrow_mut(); - let cols = fctx.cdef_sb_cols.with(|c| c.get()); - if cols > 0 && q_r * cols + q_c < g.len() { - let idx = g[q_r * cols + q_c]; - for (dr, dc) in [(0, 1), (1, 0), (1, 1)] { - let i = (q_r + dr) * cols + q_c + dc; - if q_c + dc < cols && i < g.len() { - g[i] = idx; - } + (false, true) => { + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if bump_edge32_bit( + 4, + dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)), + ) == 1 + { + PARTITION_SPLIT + } else { + PARTITION_VERT } } - }); - continue; - } - let sb_ctx = neighbours.partition_ctx(sb_at, SB); - let (has_cols, has_rows) = ( - sb_c * SB_MI + SB_MI / 2 < mi_cols, - sb_r * SB_MI + SB_MI / 2 < mi_rows, - ); - // The straddle cases (one or both halves outside the true - // frame) never carry a real alphabet symbol -- spec forces - // SPLIT there (mirrors the intra key-frame tile's own - // three-way write above). Only the (true, true) case can name - // a non-SPLIT value, and this loop below only ever recurses as - // SPLIT -- so a real non-SPLIT part64 here must refuse by name - // instead of silently decoding as SPLIT and desyncing. - let part64 = match (has_cols, has_rows) { - (true, true) => { - let pre_rng = dec.debug_state().0; - if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PART mi_row={} mi_col={} bsize=12 ctx={} rng={}", sb_r as usize * SB_MI as usize, sb_c as usize * SB_MI as usize, sb_ctx, dec.debug_state().0); } - let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); - if crate::envflags::env_flag!("EC_AV1_TRACE") { - eprintln!( - "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}", - sb_r * SB_MI, - sb_c * SB_MI - ); - } - p - } - (true, false) => { - // lane-golomb r1 (class `parsed-then-discarded`): the gathered - // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT - // (libaom `ec_read_partition_impl`). - if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PARTG mi_row={} mi_col={} bsize=12 ctx={} rng={}", sb_r as usize * SB_MI as usize, sb_c as usize * SB_MI as usize, sb_ctx, dec.debug_state().0); } - if bump_edge32_bit( - 4, - dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)), - ) == 1 { - PARTITION_SPLIT - } else { - PARTITION_HORZ - } - } - (false, true) => { - // lane-golomb r1 (class `parsed-then-discarded`): the gathered - // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT - // (libaom `ec_read_partition_impl`). - if bump_edge32_bit( - 4, - dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)), - ) == 1 { + (false, false) => { + bump_edge_both_cut(2); PARTITION_SPLIT - } else { - PARTITION_VERT } - } - (false, false) => { - bump_edge_both_cut(2); - PARTITION_SPLIT - } - }; - if part64 == PARTITION_NONE { - // lane-inter8 r1: the whole superblock as one 64x64 inter - // block. `SB`-sized syntax throughout (size_group 3, same as - // 32x32 -- `size_group_lookup[BLOCK_64X64] == 3`), luma - // coefficients through `TxbSet::Luma64` with the 32-point - // scan (TX_64X64 codes only its top-left corner, spec - // 5.11.40 -- `read_inter_plane` widens the corner back to - // 64x64 before the inverse transform), chroma as a plain - // 32x32 `TxbSet::Chroma32`. TX_64X64 carries no `tx_type` - // symbol at all, so the intra/inter luma sets coincide. - hit!(INTER_SB_NONE_HITS); - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi(sb_at), - SB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma64, - TxbSet::Luma64, - TxbSet::Chroma32, - TX32, - TX32, - &scan32, - &scan32, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SB, - SB, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - continue; - } - if matches!( - part64, - PARTITION_HORZ | PARTITION_VERT | PARTITION_HORZ_4 | PARTITION_VERT_4 - ) { - // lane-inter4 r1: the superblock-level rect + 1:4 pairs as - // inter blocks -- two 64x32 / 32x64 strips, or four 64x16 / - // 16x64 ones. Each piece keeps `side = SB` for every - // syntax/CDF/prediction-buffer decision (the square-context - // corner-cut PARTITION_HORZ already ships at the 32 level) - // but names its own true footprint through `write_w`/ - // `write_h`, which is what `motion_mode`'s bsize row, the - // mv-stack's bw4/bh4, the delta-q `bSize == sbSize` test and - // every neighbour stamp read. `reject_residual = true`: a - // non-skip strip refuses by name rather than over-read a - // square residual (rectangular inter residual coding is not - // ported -- see lanes/inter4-r1.report.md). - let horz = matches!(part64, PARTITION_HORZ | PARTITION_HORZ_4); - let four = matches!(part64, PARTITION_HORZ_4 | PARTITION_VERT_4); - let base_mi = ( - sb_r as usize * SB_MI as usize, - sb_c as usize * SB_MI as usize, - ); - let (n_pieces, step_mi) = if four { (4usize, 4usize) } else { (2usize, 8usize) }; - let (bw, bh) = match (horz, four) { - (true, false) => (64usize, 32usize), - (false, false) => (32, 64), - (true, true) => (64, 16), - (false, true) => (16, 64), }; - for i in 0..n_pieces { - let at_mi = if horz { - (base_mi.0 + i * step_mi, base_mi.1) - } else { - (base_mi.0, base_mi.1 + i * step_mi) - }; - // libaom `decode_partition`'s own `i > 0` frame-edge break. - if i > 0 && (at_mi.0 >= mi_rows as usize || at_mi.1 >= mi_cols as usize) { - break; - } - inter_piece!( - at_mi, + if part64 == PARTITION_NONE { + // lane-inter8 r1: the whole superblock as one 64x64 inter + // block. `SB`-sized syntax throughout (size_group 3, same as + // 32x32 -- `size_group_lookup[BLOCK_64X64] == 3`), luma + // coefficients through `TxbSet::Luma64` with the 32-point + // scan (TX_64X64 codes only its top-left corner, spec + // 5.11.40 -- `read_inter_plane` widens the corner back to + // 64x64 before the inverse transform), chroma as a plain + // 32x32 `TxbSet::Chroma32`. TX_64X64 carries no `tx_type` + // symbol at all, so the intra/inter luma sets coincide. + hit!(INTER_SB_NONE_HITS); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi(sb_at), SB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, TxbSet::Luma64, TxbSet::Luma64, TxbSet::Chroma32, @@ -43957,59 +49819,76 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &scan32, &scan32, 3, - bw, - bh - ); - if !four && i == 0 && ((horz && !has_rows) || (!horz && !has_cols)) { - bump_inter_edge_strip(if horz { 0 } else { 1 }); - } - match (horz, four) { - (true, false) => hit!(INTER_SB_HORZ_HITS), - (false, false) => hit!(INTER_SB_VERT_HITS), - (true, true) => hit!(INTER_SB_HORZ4_HITS), - (false, true) => hit!(INTER_SB_VERT4_HITS), - } - } - continue; - } - if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part64) { - // lane-sbab r1: the four superblock-level AB arms on the - // INTER path -- two 32x32 inter squares plus one true - // 64x32/32x64 inter strip, in libaom `decode_partition`'s own - // order (decodeframe.c: HORZ_A = TL, TR, bottom strip; - // HORZ_B = top strip, BL, BR; VERT_A = TL, BL, right strip; - // VERT_B = left strip, TR, BR). Every piece is one this - // decoder already proves elsewhere: the 32x32 square is the - // `PARTITION_NONE`-under-SPLIT block below, the strip is the - // `PARTITION_HORZ`/`VERT` piece above (`inter_piece!`, which - // keeps `side = SB` for syntax/CDF and names its true - // footprint through `write_w`/`write_h`). The intra-frame - // twin of this arm is lane-part32 r4's `SB_AB_HITS` block. - hit_do! { - SB_AB_INTER_HITS.with(|c| { - let mut h = c.get(); - h[part64 - PARTITION_HORZ_A] += 1; - c.set(h); - }); + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SB, + SB, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; + continue; } - // lane-part32 r5 / class visit-order-changes-availability: - // only the two VERTICAL arms visit TL, BL, TR, BR, so only - // they switch libaom's `has_tr`/`has_bl` tables. - let _vert_guard = (part64 == PARTITION_VERT_A || part64 == PARTITION_VERT_B) - .then(crate::encode::Reach::vert_ab_partition); - let (mi_row0, mi_col0) = ( - sb_r as usize * SB_MI as usize, - sb_c as usize * SB_MI as usize, - ); - // 32 px = 8 MI units. - let tl = (mi_row0, mi_col0); - let tr = (mi_row0, mi_col0 + 8); - let bl = (mi_row0 + 8, mi_col0); - let br = (mi_row0 + 8, mi_col0 + 8); - macro_rules! ab_strip64 { - ($mi:expr, $ww:expr, $wh:expr) => { + if matches!( + part64, + PARTITION_HORZ | PARTITION_VERT | PARTITION_HORZ_4 | PARTITION_VERT_4 + ) { + // lane-inter4 r1: the superblock-level rect + 1:4 pairs as + // inter blocks -- two 64x32 / 32x64 strips, or four 64x16 / + // 16x64 ones. Each piece keeps `side = SB` for every + // syntax/CDF/prediction-buffer decision (the square-context + // corner-cut PARTITION_HORZ already ships at the 32 level) + // but names its own true footprint through `write_w`/ + // `write_h`, which is what `motion_mode`'s bsize row, the + // mv-stack's bw4/bh4, the delta-q `bSize == sbSize` test and + // every neighbour stamp read. `reject_residual = true`: a + // non-skip strip refuses by name rather than over-read a + // square residual (rectangular inter residual coding is not + // ported -- see lanes/inter4-r1.report.md). + let horz = matches!(part64, PARTITION_HORZ | PARTITION_HORZ_4); + let four = matches!(part64, PARTITION_HORZ_4 | PARTITION_VERT_4); + let base_mi = ( + sb_r as usize * SB_MI as usize, + sb_c as usize * SB_MI as usize, + ); + let (n_pieces, step_mi) = if four { + (4usize, 4usize) + } else { + (2usize, 8usize) + }; + let (bw, bh) = match (horz, four) { + (true, false) => (64usize, 32usize), + (false, false) => (32, 64), + (true, true) => (64, 16), + (false, true) => (16, 64), + }; + for i in 0..n_pieces { + let at_mi = if horz { + (base_mi.0 + i * step_mi, base_mi.1) + } else { + (base_mi.0, base_mi.1 + i * step_mi) + }; + // libaom `decode_partition`'s own `i > 0` frame-edge break. + if i > 0 && (at_mi.0 >= mi_rows as usize || at_mi.1 >= mi_cols as usize) { + break; + } inter_piece!( - $mi, + at_mi, SB, TxbSet::Luma64, TxbSet::Luma64, @@ -44019,361 +49898,392 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &scan32, &scan32, 3, - $ww, - $wh - ) - }; - } - // The 32x32 squares carry a full square residual, so unlike - // `inter_piece!` (which hardcodes `reject_residual = true` - // for its strips) they pass `false`. - macro_rules! ab_square32 { - ($mi:expr) => { - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - $mi, - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - BLOCK, - BLOCK, - allow_screen_content_tools, - frame_width as usize, fctx, - )? - }; - } - match part64 { - PARTITION_HORZ_A => { - ab_square32!(tl); - ab_square32!(tr); - ab_strip64!(bl, 64, 32); - } - PARTITION_HORZ_B => { - ab_strip64!(tl, 64, 32); - ab_square32!(bl); - ab_square32!(br); - } - PARTITION_VERT_A => { - ab_square32!(tl); - ab_square32!(bl); - ab_strip64!(tr, 32, 64); - } - _ => { - ab_strip64!(tl, 32, 64); - ab_square32!(tr); - ab_square32!(br); + bw, + bh + ); + if !four && i == 0 && ((horz && !has_rows) || (!horz && !has_cols)) { + bump_inter_edge_strip(if horz { 0 } else { 1 }); + } + match (horz, four) { + (true, false) => hit!(INTER_SB_HORZ_HITS), + (false, false) => hit!(INTER_SB_VERT_HITS), + (true, true) => hit!(INTER_SB_HORZ4_HITS), + (false, true) => hit!(INTER_SB_VERT4_HITS), + } } - } - continue; - } - // Every value of the 10-symbol `partition_w64` alphabet is now - // handled above except SPLIT, which falls through to the quadrant - // loop below (lane-sbab r1 took the AB four; the rect/1:4 arms - // and NONE `continue` earlier). - debug_assert_eq!(part64, PARTITION_SPLIT); - - for quadrant in 0..4 { - let (r32, c32) = (sb_r * 2 + quadrant / 2, sb_c * 2 + quadrant % 2); - if r32 >= rows || c32 >= cols { continue; } - let at = (r32 as usize * 2, c32 as usize * 2); - let ctx32 = neighbours.partition_ctx(at, BLOCK); - let (has_cols32, has_rows32) = ( - has_half(c32 * BLOCK_MI, BLOCK_MI, mi_cols), - has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), - ); - let part32 = if has_cols32 && has_rows32 { - if crate::envflags::env_flag!("EC_AV1_TRACE") { - eprintln!( - "TRACE part32_pre mi=({},{}) rng={}", - r32 * BLOCK_MI, - c32 * BLOCK_MI, - dec.debug_state().0 - ); + if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part64) { + // lane-sbab r1: the four superblock-level AB arms on the + // INTER path -- two 32x32 inter squares plus one true + // 64x32/32x64 inter strip, in libaom `decode_partition`'s own + // order (decodeframe.c: HORZ_A = TL, TR, bottom strip; + // HORZ_B = top strip, BL, BR; VERT_A = TL, BL, right strip; + // VERT_B = left strip, TR, BR). Every piece is one this + // decoder already proves elsewhere: the 32x32 square is the + // `PARTITION_NONE`-under-SPLIT block below, the strip is the + // `PARTITION_HORZ`/`VERT` piece above (`inter_piece!`, which + // keeps `side = SB` for syntax/CDF and names its true + // footprint through `write_w`/`write_h`). The intra-frame + // twin of this arm is lane-part32 r4's `SB_AB_HITS` block. + hit_do! { + SB_AB_INTER_HITS.with(|c| { + let mut h = c.get(); + h[part64 - PARTITION_HORZ_A] += 1; + c.set(h); + }); } - if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PART mi_row={} mi_col={} bsize=9 ctx={} rng={}", (r32 as usize), (c32 as usize), ctx32, dec.debug_state().0); } - let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); - if crate::envflags::env_flag!("EC_AV1_TRACE") { - eprintln!( - "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p}", - r32 * BLOCK_MI, - c32 * BLOCK_MI - ); + // lane-part32 r5 / class visit-order-changes-availability: + // only the two VERTICAL arms visit TL, BL, TR, BR, so only + // they switch libaom's `has_tr`/`has_bl` tables. + let _vert_guard = (part64 == PARTITION_VERT_A || part64 == PARTITION_VERT_B) + .then(crate::encode::Reach::vert_ab_partition); + let (mi_row0, mi_col0) = ( + sb_r as usize * SB_MI as usize, + sb_c as usize * SB_MI as usize, + ); + // 32 px = 8 MI units. + let tl = (mi_row0, mi_col0); + let tr = (mi_row0, mi_col0 + 8); + let bl = (mi_row0 + 8, mi_col0); + let br = (mi_row0 + 8, mi_col0 + 8); + macro_rules! ab_strip64 { + ($mi:expr, $ww:expr, $wh:expr) => { + inter_piece!( + $mi, + SB, + TxbSet::Luma64, + TxbSet::Luma64, + TxbSet::Chroma32, + TX32, + TX32, + &scan32, + &scan32, + 3, + $ww, + $wh + ) + }; } - p - } else { - match (has_cols32, has_rows32) { - (true, false) => { - // lane-golomb r1 (class `parsed-then-discarded`): the gathered - // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT - // (libaom `ec_read_partition_impl`). - if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PARTG mi_row={} mi_col={} bsize=9 ctx={} rng={}", r32 as usize * BLOCK_MI as usize, c32 as usize * BLOCK_MI as usize, ctx32, dec.debug_state().0); } - if { - let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)); - bump_edge32(b.min(1) as usize); - b - } == 1 { - PARTITION_SPLIT - } else { - PARTITION_HORZ - } - } - (false, true) => { - // lane-golomb r1 (class `parsed-then-discarded`): the gathered - // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT - // (libaom `ec_read_partition_impl`). - if { - let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)); - bump_edge32(b.min(1) as usize); - b - } == 1 { - PARTITION_SPLIT - } else { - PARTITION_VERT - } + // The 32x32 squares carry a full square residual, so unlike + // `inter_piece!` (which hardcodes `reject_residual = true` + // for its strips) they pass `false`. + macro_rules! ab_square32 { + ($mi:expr) => { + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + $mi, + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + BLOCK, + BLOCK, + allow_screen_content_tools, + frame_width as usize, + fctx, + )? + }; + } + match part64 { + PARTITION_HORZ_A => { + ab_square32!(tl); + ab_square32!(tr); + ab_strip64!(bl, 64, 32); + } + PARTITION_HORZ_B => { + ab_strip64!(tl, 64, 32); + ab_square32!(bl); + ab_square32!(br); + } + PARTITION_VERT_A => { + ab_square32!(tl); + ab_square32!(bl); + ab_strip64!(tr, 32, 64); } _ => { - bump_edge_both_cut(1); - PARTITION_SPLIT + ab_strip64!(tl, 32, 64); + ab_square32!(tr); + ab_square32!(br); } } - }; - match part32 { - PARTITION_NONE => { - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi(at), - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - BLOCK, - BLOCK, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; + continue; + } + // Every value of the 10-symbol `partition_w64` alphabet is now + // handled above except SPLIT, which falls through to the quadrant + // loop below (lane-sbab r1 took the AB four; the rect/1:4 arms + // and NONE `continue` earlier). + debug_assert_eq!(part64, PARTITION_SPLIT); + + for quadrant in 0..4 { + let (r32, c32) = (sb_r * 2 + quadrant / 2, sb_c * 2 + quadrant % 2); + if r32 >= rows || c32 >= cols { + continue; } - PARTITION_SPLIT => { - for sub in 0..4 { - let (sr, sc) = (r32 as usize * 2 + sub / 2, c32 as usize * 2 + sub % 2); - if (sr as u32) * SUB_MI >= mi_rows || (sc as u32) * SUB_MI >= mi_cols { - continue; - } - let (has_cols16, has_rows16) = ( - has_half(sc as u32 * SUB_MI, SUB_MI, mi_cols), - has_half(sr as u32 * SUB_MI, SUB_MI, mi_rows), + let at = (r32 as usize * 2, c32 as usize * 2); + let ctx32 = neighbours.partition_ctx(at, BLOCK); + let (has_cols32, has_rows32) = ( + has_half(c32 * BLOCK_MI, BLOCK_MI, mi_cols), + has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), + ); + let part32 = if has_cols32 && has_rows32 { + if crate::envflags::env_flag!("EC_AV1_TRACE") { + eprintln!( + "TRACE part32_pre mi=({},{}) rng={}", + r32 * BLOCK_MI, + c32 * BLOCK_MI, + dec.debug_state().0 ); - let at16 = (sr, sc); - let ctx16 = neighbours.partition_ctx(at16, SUB); - // lane-inter8 r1: a straddling 16x16 cannot name a - // value (spec forces SPLIT, one gathered bit); an - // interior one reads the real alphabet, and - // `PARTITION_SPLIT` now recurses into four 8x8 - // inter leaves through the very same loop the - // straddling case has always used. - let part16 = if has_cols16 && has_rows16 { - if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PART mi_row={} mi_col={} bsize=6 ctx={} rng={}", (sr as usize*SUB_MI as usize), (sc as usize*SUB_MI as usize), ctx16, dec.debug_state().0); } - let p = dec.symbol(&mut cdfs.partition_w16[ctx16]); - if crate::envflags::env_flag!("EC_AV1_TRACE") { - let (rng, _) = dec.debug_state(); + } + if crate::envflags::env_flag!("EC_TRACE_PART") { + eprintln!( + "EC_PART mi_row={} mi_col={} bsize=9 ctx={} rng={}", + (r32 as usize), + (c32 as usize), + ctx32, + dec.debug_state().0 + ); + } + let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); + if crate::envflags::env_flag!("EC_AV1_TRACE") { + eprintln!( + "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p}", + r32 * BLOCK_MI, + c32 * BLOCK_MI + ); + } + p + } else { + match (has_cols32, has_rows32) { + (true, false) => { + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!( - "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={p} rng={rng}", - sr as u32 * SUB_MI, - sc as u32 * SUB_MI + "EC_PARTG mi_row={} mi_col={} bsize=9 ctx={} rng={}", + r32 as usize * BLOCK_MI as usize, + c32 as usize * BLOCK_MI as usize, + ctx32, + dec.debug_state().0 ); } - p - } else if !has_cols16 && !has_rows16 { - // lane-edgeboth r1: both axes cut by the true - // frame edge -- libaom `decode_partition` - // forces PARTITION_SPLIT and reads NO symbol; - // the leaf loop below already drops the - // out-of-frame quadrants. - bump_edge_both_cut(0); - PARTITION_SPLIT - } else { - if has_cols16 { - // lane-golomb r1 (class `parsed-then-discarded`): the gathered - // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT - // (libaom `ec_read_partition_impl`). - if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PARTG mi_row={} mi_col={} bsize=6 ctx={} rng={}", sr as usize * SUB_MI as usize, sc as usize * SUB_MI as usize, ctx16, dec.debug_state().0); } - if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], VERT_ALIKE)) == 1 { - PARTITION_SPLIT - } else { - PARTITION_HORZ - } + if { + let b = dec.symbol_fixed(&gather( + &cdfs.partition_w32[ctx32], + VERT_ALIKE, + )); + bump_edge32(b.min(1) as usize); + b + } == 1 + { + PARTITION_SPLIT } else { - // lane-golomb r1 (class `parsed-then-discarded`): the gathered - // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT - // (libaom `ec_read_partition_impl`). - if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], HORZ_ALIKE)) == 1 { - PARTITION_SPLIT - } else { - PARTITION_VERT - } + PARTITION_HORZ } - }; - if part16 == PARTITION_NONE { - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi(at16), - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - } else if part16 == PARTITION_HORZ || part16 == PARTITION_VERT { - // lane-inter4 r3: the 16x16-level rect inter - // leaves -- two true 16x8 (HORZ) or 8x16 - // (VERT) inter blocks. Same shape as the - // 32-level HORZ/VERT arm above: `side = SUB` - // keeps every CDF/prediction-buffer decision - // square, `write_w`/`write_h` carry the true - // footprint into the mv stack, the motion-mode - // row, the neighbour stamps and the rectangular - // residual path (`rect_inter_residual_supported` - // covers 16x8/8x16 since this round). - let horz = part16 == PARTITION_HORZ; - if horz { - hit!(INTER_LEAF16_HORZ_HITS); + } + (false, true) => { + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if { + let b = dec.symbol_fixed(&gather( + &cdfs.partition_w32[ctx32], + HORZ_ALIKE, + )); + bump_edge32(b.min(1) as usize); + b + } == 1 + { + PARTITION_SPLIT } else { - hit!(INTER_LEAF16_VERT_HITS); + PARTITION_VERT + } + } + _ => { + bump_edge_both_cut(1); + PARTITION_SPLIT + } + } + }; + match part32 { + PARTITION_NONE => { + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi(at), + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + BLOCK, + BLOCK, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; + } + PARTITION_SPLIT => { + for sub in 0..4 { + let (sr, sc) = + (r32 as usize * 2 + sub / 2, c32 as usize * 2 + sub % 2); + if (sr as u32) * SUB_MI >= mi_rows + || (sc as u32) * SUB_MI >= mi_cols + { + continue; } - let base_mi = sub16_to_mi(at16); - let (ww, wh) = if horz { (16, 8) } else { (8, 16) }; - for piece in 0..2 { - let piece_mi = if horz { - (base_mi.0 + piece * 2, base_mi.1) + let (has_cols16, has_rows16) = ( + has_half(sc as u32 * SUB_MI, SUB_MI, mi_cols), + has_half(sr as u32 * SUB_MI, SUB_MI, mi_rows), + ); + let at16 = (sr, sc); + let ctx16 = neighbours.partition_ctx(at16, SUB); + // lane-inter8 r1: a straddling 16x16 cannot name a + // value (spec forces SPLIT, one gathered bit); an + // interior one reads the real alphabet, and + // `PARTITION_SPLIT` now recurses into four 8x8 + // inter leaves through the very same loop the + // straddling case has always used. + let part16 = if has_cols16 && has_rows16 { + if crate::envflags::env_flag!("EC_TRACE_PART") { + eprintln!( + "EC_PART mi_row={} mi_col={} bsize=6 ctx={} rng={}", + (sr as usize * SUB_MI as usize), + (sc as usize * SUB_MI as usize), + ctx16, + dec.debug_state().0 + ); + } + let p = dec.symbol(&mut cdfs.partition_w16[ctx16]); + if crate::envflags::env_flag!("EC_AV1_TRACE") { + let (rng, _) = dec.debug_state(); + eprintln!( + "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={p} rng={rng}", + sr as u32 * SUB_MI, + sc as u32 * SUB_MI + ); + } + p + } else if !has_cols16 && !has_rows16 { + // lane-edgeboth r1: both axes cut by the true + // frame edge -- libaom `decode_partition` + // forces PARTITION_SPLIT and reads NO symbol; + // the leaf loop below already drops the + // out-of-frame quadrants. + bump_edge_both_cut(0); + PARTITION_SPLIT + } else { + if has_cols16 { + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if crate::envflags::env_flag!("EC_TRACE_PART") { + eprintln!( + "EC_PARTG mi_row={} mi_col={} bsize=6 ctx={} rng={}", + sr as usize * SUB_MI as usize, + sc as usize * SUB_MI as usize, + ctx16, + dec.debug_state().0 + ); + } + if dec.symbol_fixed(&gather( + &cdfs.partition_w16[ctx16], + VERT_ALIKE, + )) == 1 + { + PARTITION_SPLIT + } else { + PARTITION_HORZ + } } else { - (base_mi.0, base_mi.1 + piece * 2) - }; - // libaom `decode_partition`'s own second- - // half frame-edge break. - if piece > 0 - && (piece_mi.0 >= mi_rows as usize - || piece_mi.1 >= mi_cols as usize) - { - bump_inter_edge_strip(if horz { 4 } else { 5 }); - break; + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if dec.symbol_fixed(&gather( + &cdfs.partition_w16[ctx16], + HORZ_ALIKE, + )) == 1 + { + PARTITION_SPLIT + } else { + PARTITION_VERT + } } + }; + if part16 == PARTITION_NONE { decode_inter_block( &mut dec, &mut cdfs, &mut neighbours, &mut grid, - piece_mi, + sub16_to_mi(at16), SUB, mi_cols, mi_rows, @@ -44395,7 +50305,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( TX8, &scan16, &scan8, - 1, + 2, allow_high_precision_mv, force_integer_mv, interp_fixed, @@ -44412,69 +50322,63 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( skip_mode_frame, switchable_motion_mode, allow_warped_motion, - true, - ww, - wh, + false, + SUB, + SUB, allow_screen_content_tools, - frame_width as usize, fctx, + frame_width as usize, + fctx, )?; - } - } else if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part16) { - // lane-inter16ab r1: the four AB (T-shaped) - // partitions at the 16x16 level of an INTER - // frame -- two 8x8 inter leaves plus one true - // 16x8/8x16 inter strip. libaom - // `decode_partition` (decodeframe.c ~5040, - // `bsize2 = get_partition_subsize(bsize, - // PARTITION_SPLIT)` = BLOCK_8X8 here) visits: - // HORZ_A: TL 8x8, TR 8x8, bottom 16x8 - // HORZ_B: top 16x8, BL 8x8, BR 8x8 - // VERT_A: TL 8x8, BL 8x8, right 8x16 - // VERT_B: left 8x16, TR 8x8, BR 8x8 - // Every piece is inside the frame by - // construction: an AB value can only be read - // from the (has_cols16 && has_rows16) branch - // above, i.e. mi_row+2 < mi_rows and - // mi_col+2 < mi_cols, which is exactly - // libaom's own `has_rows`/`has_cols`. - // - // VERT_A/VERT_B visit TL,BL,TR,BR, so a - // bottom-left square's top-right neighbour is - // the partition's own not-yet-decoded - // rectangle: libaom switches those squares - // onto `has_tr_vert_*`/`has_bl_vert_*` - // (`reconintra.c get_has_tr_table`) -- - // `Reach::vert_ab_partition()`, the same - // guard the intra 16-level arm and the - // 32-level inter AB arms take (class - // `visit-order-changes-availability`). - // - // OBMC/warp and compound stay legal here: - // every piece is >= 8x8, so libaom's - // `is_motion_variation_allowed_bsize` - // (min(bw,bh) >= 8, blockd.h) and - // `is_comp_ref_allowed` (block_size_wide + - // block_size_high >= 16, blockd.h) both hold - // and the leaf/strip decoders' own gates - // apply unchanged. - bump_ab16_inter(part16 - PARTITION_HORZ_A); - let _vert_guard = if part16 == PARTITION_VERT_A - || part16 == PARTITION_VERT_B - { - Some(crate::encode::Reach::vert_ab_partition()) - } else { - None - }; - let (mi_row0, mi_col0) = sub16_to_mi(at16); - let tl = (mi_row0, mi_col0); - let tr = (mi_row0, mi_col0 + 2); - let bl = (mi_row0 + 2, mi_col0); - let br = (mi_row0 + 2, mi_col0 + 2); - macro_rules! ab_strip16 { - ($mi:expr, $ww:expr, $wh:expr) => { - inter_piece!( - $mi, + } else if part16 == PARTITION_HORZ || part16 == PARTITION_VERT { + // lane-inter4 r3: the 16x16-level rect inter + // leaves -- two true 16x8 (HORZ) or 8x16 + // (VERT) inter blocks. Same shape as the + // 32-level HORZ/VERT arm above: `side = SUB` + // keeps every CDF/prediction-buffer decision + // square, `write_w`/`write_h` carry the true + // footprint into the mv stack, the motion-mode + // row, the neighbour stamps and the rectangular + // residual path (`rect_inter_residual_supported` + // covers 16x8/8x16 since this round). + let horz = part16 == PARTITION_HORZ; + if horz { + hit!(INTER_LEAF16_HORZ_HITS); + } else { + hit!(INTER_LEAF16_VERT_HITS); + } + let base_mi = sub16_to_mi(at16); + let (ww, wh) = if horz { (16, 8) } else { (8, 16) }; + for piece in 0..2 { + let piece_mi = if horz { + (base_mi.0 + piece * 2, base_mi.1) + } else { + (base_mi.0, base_mi.1 + piece * 2) + }; + // libaom `decode_partition`'s own second- + // half frame-edge break. + if piece > 0 + && (piece_mi.0 >= mi_rows as usize + || piece_mi.1 >= mi_cols as usize) + { + bump_inter_edge_strip(if horz { 4 } else { 5 }); + break; + } + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + piece_mi, SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, TxbSet::Luma16, if reduced_tx_set { TxbSet::Luma16Inter @@ -44487,272 +50391,383 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &scan16, &scan8, 1, - $ww, - $wh - ) - }; - } - match part16 { - PARTITION_HORZ_A => { - inter_leaf8!(at16, tl); - inter_leaf8!(at16, tr); - ab_strip16!(bl, 16, 8); - } - PARTITION_HORZ_B => { - ab_strip16!(tl, 16, 8); - inter_leaf8!(at16, bl); - inter_leaf8!(at16, br); - } - PARTITION_VERT_A => { - inter_leaf8!(at16, tl); - inter_leaf8!(at16, bl); - ab_strip16!(tr, 8, 16); - } - _ => { - ab_strip16!(tl, 8, 16); - inter_leaf8!(at16, tr); - inter_leaf8!(at16, br); + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + ww, + wh, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; } - } - } else if part16 == PARTITION_HORZ_4 - || part16 == PARTITION_VERT_4 - { - // lane-inter16ab r2: four 16x4 (4x16) INTER - // strips. libaom `decode_partition` - // (decodeframe.c, PARTITION_HORZ_4/VERT_4) - // walks them top to bottom (left to right) - // with its own `i > 0` frame-edge break. - // - // Each strip is >= 8 in one dimension only, - // so `is_comp_ref_allowed`, - // `is_motion_variation_allowed_bsize` - // (blockd.h:65/1455, min(bw, bh) >= 8) and - // `is_interintra_allowed_bsize` (BLOCK_8X8.. - // BLOCK_32X32 in enum order, which excludes - // BLOCK_16X4 = 17) are all false: no - // skip_mode, no comp_mode, no OBMC/warp and - // no interintra symbol is read -- gated in - // `decode_inter_block` off `write_w`/ - // `write_h`. - // - // CHROMA is the pair's: - // `is_chroma_reference` - // (av1_common_int.h:1454) is false on the - // even strips, and the odd one codes one 8x4 - // (4x8) chroma transform at the pair's - // origin, built from BOTH strips' motion - // (`is_sub8x8_inter`). - let horz = part16 == PARTITION_HORZ_4; - let (mi_row0, mi_col0) = sub16_to_mi(at16); - let (bw, bh) = if horz { (16usize, 4usize) } else { (4usize, 16usize) }; - for i in 0..4usize { - let at_mi = if horz { - (mi_row0 + i, mi_col0) + } else if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part16) { + // lane-inter16ab r1: the four AB (T-shaped) + // partitions at the 16x16 level of an INTER + // frame -- two 8x8 inter leaves plus one true + // 16x8/8x16 inter strip. libaom + // `decode_partition` (decodeframe.c ~5040, + // `bsize2 = get_partition_subsize(bsize, + // PARTITION_SPLIT)` = BLOCK_8X8 here) visits: + // HORZ_A: TL 8x8, TR 8x8, bottom 16x8 + // HORZ_B: top 16x8, BL 8x8, BR 8x8 + // VERT_A: TL 8x8, BL 8x8, right 8x16 + // VERT_B: left 8x16, TR 8x8, BR 8x8 + // Every piece is inside the frame by + // construction: an AB value can only be read + // from the (has_cols16 && has_rows16) branch + // above, i.e. mi_row+2 < mi_rows and + // mi_col+2 < mi_cols, which is exactly + // libaom's own `has_rows`/`has_cols`. + // + // VERT_A/VERT_B visit TL,BL,TR,BR, so a + // bottom-left square's top-right neighbour is + // the partition's own not-yet-decoded + // rectangle: libaom switches those squares + // onto `has_tr_vert_*`/`has_bl_vert_*` + // (`reconintra.c get_has_tr_table`) -- + // `Reach::vert_ab_partition()`, the same + // guard the intra 16-level arm and the + // 32-level inter AB arms take (class + // `visit-order-changes-availability`). + // + // OBMC/warp and compound stay legal here: + // every piece is >= 8x8, so libaom's + // `is_motion_variation_allowed_bsize` + // (min(bw,bh) >= 8, blockd.h) and + // `is_comp_ref_allowed` (block_size_wide + + // block_size_high >= 16, blockd.h) both hold + // and the leaf/strip decoders' own gates + // apply unchanged. + bump_ab16_inter(part16 - PARTITION_HORZ_A); + let _vert_guard = if part16 == PARTITION_VERT_A + || part16 == PARTITION_VERT_B + { + Some(crate::encode::Reach::vert_ab_partition()) } else { - (mi_row0, mi_col0 + i) + None }; - if i > 0 - && (at_mi.0 >= mi_rows as usize - || at_mi.1 >= mi_cols as usize) - { - break; + let (mi_row0, mi_col0) = sub16_to_mi(at16); + let tl = (mi_row0, mi_col0); + let tr = (mi_row0, mi_col0 + 2); + let bl = (mi_row0 + 2, mi_col0); + let br = (mi_row0 + 2, mi_col0 + 2); + macro_rules! ab_strip16 { + ($mi:expr, $ww:expr, $wh:expr) => { + inter_piece!( + $mi, + SUB, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 1, + $ww, + $wh + ) + }; } - // lane-av1-444: at 4:4:4 every strip is - // its own chroma reference - // (`is_chroma_reference`: no mi parity - // test at ss 0/0 and the strip's 16x4 / - // 4x16 chroma block is already >= 4x4), - // so there is no pair: each strip codes - // and predicts its own chroma from its - // own motion (`prev` = None). - // lane-av1-422l: a strip pairs along its - // OWN subsampled axis -- horz strips pair - // on rows (no pair once ss_y == 0: chroma - // has no row parity, every 16x4 strip is - // its own reference, exactly the intra - // strip arm's `else if ss_y(fctx) == 0`); - // vert strips pair on columns (ss_x == 0 - // => every strip self-pairs, 4:2:2 keeps - // the 4:2:0 column pairing -- a VERT_4 - // 4x16 strip's `ss_size_lookup` chroma - // at ss (1,0) is BLOCK_INVALID, so only - // the pair shape can ever be coded). - let strip_has_chroma = if horz { - i % 2 == 1 || ss_y(fctx) == 0 + match part16 { + PARTITION_HORZ_A => { + inter_leaf8!(at16, tl); + inter_leaf8!(at16, tr); + ab_strip16!(bl, 16, 8); + } + PARTITION_HORZ_B => { + ab_strip16!(tl, 16, 8); + inter_leaf8!(at16, bl); + inter_leaf8!(at16, br); + } + PARTITION_VERT_A => { + inter_leaf8!(at16, tl); + inter_leaf8!(at16, bl); + ab_strip16!(tr, 8, 16); + } + _ => { + ab_strip16!(tl, 8, 16); + inter_leaf8!(at16, tr); + inter_leaf8!(at16, br); + } + } + } else if part16 == PARTITION_HORZ_4 || part16 == PARTITION_VERT_4 { + // lane-inter16ab r2: four 16x4 (4x16) INTER + // strips. libaom `decode_partition` + // (decodeframe.c, PARTITION_HORZ_4/VERT_4) + // walks them top to bottom (left to right) + // with its own `i > 0` frame-edge break. + // + // Each strip is >= 8 in one dimension only, + // so `is_comp_ref_allowed`, + // `is_motion_variation_allowed_bsize` + // (blockd.h:65/1455, min(bw, bh) >= 8) and + // `is_interintra_allowed_bsize` (BLOCK_8X8.. + // BLOCK_32X32 in enum order, which excludes + // BLOCK_16X4 = 17) are all false: no + // skip_mode, no comp_mode, no OBMC/warp and + // no interintra symbol is read -- gated in + // `decode_inter_block` off `write_w`/ + // `write_h`. + // + // CHROMA is the pair's: + // `is_chroma_reference` + // (av1_common_int.h:1454) is false on the + // even strips, and the odd one codes one 8x4 + // (4x8) chroma transform at the pair's + // origin, built from BOTH strips' motion + // (`is_sub8x8_inter`). + let horz = part16 == PARTITION_HORZ_4; + let (mi_row0, mi_col0) = sub16_to_mi(at16); + let (bw, bh) = if horz { + (16usize, 4usize) } else { - i % 2 == 1 || ss_x(fctx) == 0 + (4usize, 16usize) }; - let pair_mi = - if !strip_has_chroma + for i in 0..4usize { + let at_mi = if horz { + (mi_row0 + i, mi_col0) + } else { + (mi_row0, mi_col0 + i) + }; + if i > 0 + && (at_mi.0 >= mi_rows as usize + || at_mi.1 >= mi_cols as usize) + { + break; + } + // lane-av1-444: at 4:4:4 every strip is + // its own chroma reference + // (`is_chroma_reference`: no mi parity + // test at ss 0/0 and the strip's 16x4 / + // 4x16 chroma block is already >= 4x4), + // so there is no pair: each strip codes + // and predicts its own chroma from its + // own motion (`prev` = None). + // lane-av1-422l: a strip pairs along its + // OWN subsampled axis -- horz strips pair + // on rows (no pair once ss_y == 0: chroma + // has no row parity, every 16x4 strip is + // its own reference, exactly the intra + // strip arm's `else if ss_y(fctx) == 0`); + // vert strips pair on columns (ss_x == 0 + // => every strip self-pairs, 4:2:2 keeps + // the 4:2:0 column pairing -- a VERT_4 + // 4x16 strip's `ss_size_lookup` chroma + // at ss (1,0) is BLOCK_INVALID, so only + // the pair shape can ever be coded). + let strip_has_chroma = if horz { + i % 2 == 1 || ss_y(fctx) == 0 + } else { + i % 2 == 1 || ss_x(fctx) == 0 + }; + let pair_mi = if !strip_has_chroma || (if horz { ss_y(fctx) == 0 } else { ss_x(fctx) == 0 - }) - { + }) { at_mi } else if horz { (at_mi.0 - 1, at_mi.1) } else { (at_mi.0, at_mi.1 - 1) }; - fctx.inter_strip_chroma.with(|c| { - c.set(Some(InterStripChroma { - has_chroma: strip_has_chroma, - horz, - pair_mi, - prev: if strip_has_chroma - && (if horz { - ss_y(fctx) == 1 + fctx.inter_strip_chroma.with(|c| { + c.set(Some(InterStripChroma { + has_chroma: strip_has_chroma, + horz, + pair_mi, + prev: if strip_has_chroma + && (if horz { + ss_y(fctx) == 1 + } else { + ss_x(fctx) == 1 + }) { + fctx.inter_last_mc.with(std::cell::Cell::get) } else { - ss_x(fctx) == 1 - }) { - fctx.inter_last_mc - .with(std::cell::Cell::get) + None + }, + })) + }); + inter_piece!( + at_mi, + SUB, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter } else { - None + TxbSet::Luma16InterSet1 }, - })) - }); - inter_piece!( - at_mi, - SUB, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 1, + bw, + bh + ); + if horz { + hit!(INTER16_HORZ4_HITS); } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 1, - bw, - bh - ); - if horz { - hit!(INTER16_HORZ4_HITS); - } else { - hit!(INTER16_VERT4_HITS); - } - } - } else if part16 != PARTITION_SPLIT { - return Err(unsupported( - "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4", - )); - } else { - if has_cols16 && has_rows16 { - hit!(INTER_SUB16_SPLIT_HITS); - } - let (mi_row0, mi_col0) = (sr as u32 * SUB_MI, sc as u32 * SUB_MI); - let leaf_positions: Vec<(u32, u32)> = (0..4) - .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) - .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) - .collect(); - // lane-t900 r28: the 8x8-leaf refusal under a - // scaled reference is LIFTED -- - // `decode_inter_block8`'s single-ref, - // compound and OBMC MC all take spec - // 7.11.3.3's scaled walk. The counter is what - // proves a gate actually reached a scaled - // leaf rather than a same-size reference. - if (1..8).any(|rf| { - refpix.dims(rf).is_some_and(|(w, _)| { - w != frame_width as usize - }) - }) { - hit!(SCALED_LEAF8_HITS); - } - let mut prev_leaves: Vec<((usize, usize), bool, bool, i8, Option)> = Vec::new(); - for (mr, mc) in leaf_positions { - let leaf_mi = (mr as usize, mc as usize); - let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); - if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PART mi_row={} mi_col={} bsize=3 ctx={} rng={}", leaf_mi.0, leaf_mi.1, leaf_ctx, dec.debug_state().0); } - let ec_dbg_pre = dec.debug_state().0; - let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); - if std::env::var_os("EC_DBG_SUB8").is_some() { - let ec_dbg_post = dec.debug_state().0; - eprintln!("EC_DBG b8 mi=({},{}) ctx={leaf_ctx} val={part8} pre={ec_dbg_pre} post={ec_dbg_post}", leaf_mi.0, leaf_mi.1); + hit!(INTER16_VERT4_HITS); + } } - if part8 == PARTITION_SPLIT { - // lane-intersub8: four BLOCK_4X4 inter - // sub-blocks, chroma once per 8x8. - decode_inter_sub8_split4( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - leaf_mi, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - &scan4, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reduced_tx_set, - frame_width as usize, fctx, - )?; - continue; + } else if part16 != PARTITION_SPLIT { + return Err(unsupported( + "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4", + )); + } else { + if has_cols16 && has_rows16 { + hit!(INTER_SUB16_SPLIT_HITS); } - if part8 == PARTITION_VERT || part8 == PARTITION_HORZ { - // lane-intersub8 r3/r4/r5: two - // BLOCK_8X4 (HORZ) / BLOCK_4X8 (VERT) - // inter leaves, chroma once per 8x8 on - // the second of them. HORZ was refused - // by name through r4 over a |d| <= 2 - // luma band; r5 merged lane-cdef - // 8c6065e, whose `decode_inter_block8` - // skip-band write is that band's root - // cause, and the 56-arm sweep went 3 - // mismatching arms -> 0. - decode_inter_sub8_rect2( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - leaf_mi, - part8 == PARTITION_VERT, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - &scan4, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reduced_tx_set, - frame_width as usize, fctx, - )?; - continue; + let (mi_row0, mi_col0) = + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); + let leaf_positions: Vec<(u32, u32)> = (0..4) + .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) + .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) + .collect(); + // lane-t900 r28: the 8x8-leaf refusal under a + // scaled reference is LIFTED -- + // `decode_inter_block8`'s single-ref, + // compound and OBMC MC all take spec + // 7.11.3.3's scaled walk. The counter is what + // proves a gate actually reached a scaled + // leaf rather than a same-size reference. + if (1..8).any(|rf| { + refpix + .dims(rf) + .is_some_and(|(w, _)| w != frame_width as usize) + }) { + hit!(SCALED_LEAF8_HITS); } - // `partition_w8` is a 4-symbol alphabet - // (NONE/HORZ/VERT/SPLIT), all four handled. - let ( - skip, - is_inter, - skip_mode_leaf, - compound_ctx8, - leaf_filter, - leaf_refs, - ) = decode_inter_block8( + let mut prev_leaves: Vec<( + (usize, usize), + bool, + bool, + i8, + Option, + )> = Vec::new(); + for (mr, mc) in leaf_positions { + let leaf_mi = (mr as usize, mc as usize); + let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); + if crate::envflags::env_flag!("EC_TRACE_PART") { + eprintln!( + "EC_PART mi_row={} mi_col={} bsize=3 ctx={} rng={}", + leaf_mi.0, + leaf_mi.1, + leaf_ctx, + dec.debug_state().0 + ); + } + let ec_dbg_pre = dec.debug_state().0; + let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); + if std::env::var_os("EC_DBG_SUB8").is_some() { + let ec_dbg_post = dec.debug_state().0; + eprintln!( + "EC_DBG b8 mi=({},{}) ctx={leaf_ctx} val={part8} pre={ec_dbg_pre} post={ec_dbg_post}", + leaf_mi.0, leaf_mi.1 + ); + } + if part8 == PARTITION_SPLIT { + // lane-intersub8: four BLOCK_4X4 inter + // sub-blocks, chroma once per 8x8. + decode_inter_sub8_split4( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + leaf_mi, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + &scan4, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reduced_tx_set, + frame_width as usize, + fctx, + )?; + continue; + } + if part8 == PARTITION_VERT || part8 == PARTITION_HORZ { + // lane-intersub8 r3/r4/r5: two + // BLOCK_8X4 (HORZ) / BLOCK_4X8 (VERT) + // inter leaves, chroma once per 8x8 on + // the second of them. HORZ was refused + // by name through r4 over a |d| <= 2 + // luma band; r5 merged lane-cdef + // 8c6065e, whose `decode_inter_block8` + // skip-band write is that band's root + // cause, and the 56-arm sweep went 3 + // mismatching arms -> 0. + decode_inter_sub8_rect2( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + leaf_mi, + part8 == PARTITION_VERT, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + &scan4, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reduced_tx_set, + frame_width as usize, + fctx, + )?; + continue; + } + // `partition_w8` is a 4-symbol alphabet + // (NONE/HORZ/VERT/SPLIT), all four handled. + let ( + skip, + is_inter, + skip_mode_leaf, + compound_ctx8, + leaf_filter, + leaf_refs, + ) = decode_inter_block8( &mut dec, &mut cdfs, &mut neighbours, @@ -44788,121 +50803,78 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( allow_screen_content_tools, &sign_bias_table, tpl_frame.as_ref(), - frame_width as usize, fctx, + frame_width as usize, + fctx, )?; - prev_leaves.push((leaf_mi, skip, is_inter, leaf_refs.0, leaf_refs.1)); - // lane-inter8 r2: stamp THIS leaf's own - // 2x2-mi span before the next leaf reads - // it as a neighbour -- the whole-16x16 - // stamp below only ever described the - // last leaf, so three quarters of the - // block carried the wrong skip/ref/inter - // state into the next block's contexts - // (class context-read-from-one-cell). - // lane-gmaffine r3: with the mi-granular - // band, the leaf's OWN switchable-filter - // symbols go in here -- the `[3, 3]` - // ("intra, no filter") sentinel this used - // to stamp made `obmc_blend`'s - // `neighbour_filter` PANIC as soon as a - // sibling leaf blended one of these. - neighbours.record_inter_rect_mi( - leaf_mi, - 2, - 2, - skip, - is_inter, - leaf_refs.0, - leaf_filter, - skip_mode_leaf, - ); - if let Some(ref1) = leaf_refs.1 - && let Some((_, _, group_idx, idx)) = compound_ctx8 - { - neighbours.record_compound_ctx_rect_mi( - leaf_mi, 2, 2, ref1, group_idx, idx, + prev_leaves.push(( + leaf_mi, + skip, + is_inter, + leaf_refs.0, + leaf_refs.1, + )); + // lane-inter8 r2: stamp THIS leaf's own + // 2x2-mi span before the next leaf reads + // it as a neighbour -- the whole-16x16 + // stamp below only ever described the + // last leaf, so three quarters of the + // block carried the wrong skip/ref/inter + // state into the next block's contexts + // (class context-read-from-one-cell). + // lane-gmaffine r3: with the mi-granular + // band, the leaf's OWN switchable-filter + // symbols go in here -- the `[3, 3]` + // ("intra, no filter") sentinel this used + // to stamp made `obmc_blend`'s + // `neighbour_filter` PANIC as soon as a + // sibling leaf blended one of these. + neighbours.record_inter_rect_mi( + leaf_mi, + 2, + 2, + skip, + is_inter, + leaf_refs.0, + leaf_filter, + skip_mode_leaf, ); + if let Some(ref1) = leaf_refs.1 + && let Some((_, _, group_idx, idx)) = compound_ctx8 + { + neighbours.record_compound_ctx_rect_mi( + leaf_mi, 2, 2, ref1, group_idx, idx, + ); + } } + // lane-inter8 r2: the four per-leaf + // `record_inter_rect_mi` stamps above replace + // the single whole-16x16 one that used to run + // here with the LAST leaf's state. } - // lane-inter8 r2: the four per-leaf - // `record_inter_rect_mi` stamps above replace - // the single whole-16x16 one that used to run - // here with the LAST leaf's state. } } - } - PARTITION_HORZ_B => { - // lane-warp r5: PARTITION_HORZ_B = 32x32 top strip + - // 16x16 bottom-left + 16x16 bottom-right. aomenc - // carves static regions into it; the strip is - // decoded as a square 32x32 block: for a `skip` - // block the symbol stream is identical to the true - // 32x16 coding (no residual, no motion_mode/warp - // symbol), and the square stamps it leaves over the - // bottom half (neighbour arrays, skip/lf grids) are - // re-stamped by the C/D leaves right after. The - // mi-granular `left_side_mi` rows of a last-block-in- - // tile strip leak 32-vs-16 only until the per-tile - // `Neighbours::new` reset. - hit!(EXTENDED_PARTITION_HITS); - let at32 = at; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi(at32), - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - // lane-rect r2: the top strip's TRUE 32x16 - // footprint (was BLOCK,BLOCK -- the same square - // corner-cut rect-flake-1 exposed on HORZ). - BLOCK, - SUB, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows { + PARTITION_HORZ_B => { + // lane-warp r5: PARTITION_HORZ_B = 32x32 top strip + + // 16x16 bottom-left + 16x16 bottom-right. aomenc + // carves static regions into it; the strip is + // decoded as a square 32x32 block: for a `skip` + // block the symbol stream is identical to the true + // 32x16 coding (no residual, no motion_mode/warp + // symbol), and the square stamps it leaves over the + // bottom half (neighbour arrays, skip/lf grids) are + // re-stamped by the C/D leaves right after. The + // mi-granular `left_side_mi` rows of a last-block-in- + // tile strip leak 32-vs-16 only until the per-tile + // `Neighbours::new` reset. + hit!(EXTENDED_PARTITION_HITS); + let at32 = at; decode_inter_block( &mut dec, &mut cdfs, &mut neighbours, &mut grid, - sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), - SUB, + sub16_to_mi(at32), + BLOCK, mi_cols, mi_rows, &mut y, @@ -44910,20 +50882,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut v, refpix, &sign_bias_table, - &global_motion, + &global_motion, base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, TX16, - TX8, + &scan32, &scan16, - &scan8, - 2, + 3, allow_high_precision_mv, force_integer_mv, interp_fixed, @@ -44940,19 +50908,23 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( skip_mode_frame, switchable_motion_mode, allow_warped_motion, - false, - SUB, + true, + // lane-rect r2: the top strip's TRUE 32x16 + // footprint (was BLOCK,BLOCK -- the same square + // corner-cut rect-flake-1 exposed on HORZ). + BLOCK, SUB, allow_screen_content_tools, - frame_width as usize, fctx, + frame_width as usize, + fctx, )?; - if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols { + if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows { decode_inter_block( &mut dec, &mut cdfs, &mut neighbours, &mut grid, - sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2 + 1)), + sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), SUB, mi_cols, mi_rows, @@ -44961,7 +50933,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut v, refpix, &sign_bias_table, - &global_motion, + &global_motion, base_q_idx, TxbSet::Luma16, if reduced_tx_set { @@ -44995,78 +50967,78 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( SUB, SUB, allow_screen_content_tools, - frame_width as usize, fctx, + frame_width as usize, + fctx, )?; + if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols { + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2 + 1)), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; + } } } - } - PARTITION_HORZ => { - // lane-rect r2: two true 32x16 strips. Both read at - // `side=BLOCK` (CDF/size-class selection stays square, - // matching HORZ_B's accepted corner-cut) but bw4/bh4 - // (mvstack.rs, `motion_mode_eligible`) now derive from - // `write_w`/`write_h`'s true 32x16 footprint -- the - // pin's fix (r1's finding). - hit!(RECT_PARTITION_HITS); - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi(at), - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - BLOCK, - SUB, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - if !has_rows32 { - bump_edge32(2); - } - // lane-golomb r2: at the frame edge only the first half of the - // strip is coded (libaom `decode_partition` guards the second - // with the same has_rows32 test that made this partition non-square). - if has_rows32 { + PARTITION_HORZ => { + // lane-rect r2: two true 32x16 strips. Both read at + // `side=BLOCK` (CDF/size-class selection stays square, + // matching HORZ_B's accepted corner-cut) but bw4/bh4 + // (mvstack.rs, `motion_mode_eligible`) now derive from + // `write_w`/`write_h`'s true 32x16 footprint -- the + // pin's fix (r1's finding). + hit!(RECT_PARTITION_HITS); decode_inter_block( &mut dec, &mut cdfs, &mut neighbours, &mut grid, - sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), + sub16_to_mi(at), BLOCK, mi_cols, mi_rows, @@ -45105,75 +51077,77 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( BLOCK, SUB, allow_screen_content_tools, - frame_width as usize, fctx, + frame_width as usize, + fctx, )?; - } else { - bump_inter_edge_strip(2); - } - } - PARTITION_VERT => { - // lane-rect r2: mirror of PARTITION_HORZ above with - // width/height swapped. - hit!(RECT_PARTITION_HITS); - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi(at), - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - SUB, - BLOCK, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - if !has_cols32 { - bump_edge32(3); + if !has_rows32 { + bump_edge32(2); + } + // lane-golomb r2: at the frame edge only the first half of the + // strip is coded (libaom `decode_partition` guards the second + // with the same has_rows32 test that made this partition non-square). + if has_rows32 { + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + BLOCK, + SUB, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; + } else { + bump_inter_edge_strip(2); + } } - // lane-golomb r2: at the frame edge only the first half of the - // strip is coded (libaom `decode_partition` guards the second - // with the same has_cols32 test that made this partition non-square). - if has_cols32 { + PARTITION_VERT => { + // lane-rect r2: mirror of PARTITION_HORZ above with + // width/height swapped. + hit!(RECT_PARTITION_HITS); decode_inter_block( &mut dec, &mut cdfs, &mut neighbours, &mut grid, - sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), + sub16_to_mi(at), BLOCK, mi_cols, mi_rows, @@ -45212,494 +51186,190 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( SUB, BLOCK, allow_screen_content_tools, - frame_width as usize, fctx, + frame_width as usize, + fctx, )?; - } else { - bump_inter_edge_strip(3); - } - } - PARTITION_HORZ_A => { - // lane-partab r1: two 16x16 squares on top + a true - // 32x16 strip below (libaom decode_partition - // PARTITION_HORZ_A: TL, TR, bottom strip). - hit!(PARTAB_HITS); - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi(at), - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - BLOCK, - SUB, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - } - PARTITION_VERT_A => { - // lane-partab r1: mirror of PARTITION_HORZ_A with - // width/height swapped (TL, BL, right 16x32 strip). - hit!(PARTAB_HITS); - let _vert_ab = crate::encode::Reach::vert_ab_partition(); - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi(at), - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - SUB, - BLOCK, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - } - PARTITION_VERT_B => { - // lane-partab r1: true 16x32 strip on the left + two - // 16x16 squares on the right (libaom decode_partition - // PARTITION_VERT_B: left strip, TR, BR). - hit!(PARTAB_HITS); - let _vert_ab = crate::encode::Reach::vert_ab_partition(); - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi(at), - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - SUB, - BLOCK, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2 + 1)), - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - refpix, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, fctx, - )?; - } - PARTITION_HORZ_4 | PARTITION_VERT_4 => { - // lane-inter4 r1: four 32x8 / 8x32 inter strips, - // `quarter_step` = 2 mi -- the arm ReelC's first inter - // frame stops at (`value=9` = PARTITION_VERT_4). - // `at` is in 16-px cells and cannot name an 8-px - // offset, which is why `decode_inter_block` takes mi - // coordinates now. - let horz = part32 == PARTITION_HORZ_4; - let base_mi = (at.0 * (SUB / MI), at.1 * (SUB / MI)); - let (bw, bh) = if horz { (32usize, 8usize) } else { (8, 32) }; - for i in 0..4 { - let strip_mi = if horz { - (base_mi.0 + i * 2, base_mi.1) + if !has_cols32 { + bump_edge32(3); + } + // lane-golomb r2: at the frame edge only the first half of the + // strip is coded (libaom `decode_partition` guards the second + // with the same has_cols32 test that made this partition non-square). + if has_cols32 { + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + SUB, + BLOCK, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; } else { - (base_mi.0, base_mi.1 + i * 2) - }; - if i > 0 - && (strip_mi.0 >= mi_rows as usize - || strip_mi.1 >= mi_cols as usize) - { - break; + bump_inter_edge_strip(3); } - inter_piece!( - strip_mi, + } + PARTITION_HORZ_A => { + // lane-partab r1: two 16x16 squares on top + a true + // 32x16 strip below (libaom decode_partition + // PARTITION_HORZ_A: TL, TR, bottom strip). + hit!(PARTAB_HITS); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi(at), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, TxbSet::Luma32, TxbSet::Luma32Inter, TxbSet::Chroma16, @@ -45708,32 +51378,400 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &scan32, &scan16, 3, - bw, - bh - ); - if horz { - hit!(RECT4_32_HORZ_INTER_HITS); - } else { - hit!(RECT4_32_VERT_INTER_HITS); + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + BLOCK, + SUB, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; + } + PARTITION_VERT_A => { + // lane-partab r1: mirror of PARTITION_HORZ_A with + // width/height swapped (TL, BL, right 16x32 strip). + hit!(PARTAB_HITS); + let _vert_ab = crate::encode::Reach::vert_ab_partition(); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi(at), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + SUB, + BLOCK, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; + } + PARTITION_VERT_B => { + // lane-partab r1: true 16x32 strip on the left + two + // 16x16 squares on the right (libaom decode_partition + // PARTITION_VERT_B: left strip, TR, BR). + hit!(PARTAB_HITS); + let _vert_ab = crate::encode::Reach::vert_ab_partition(); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi(at), + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + SUB, + BLOCK, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2 + 1)), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + refpix, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + fctx, + )?; + } + PARTITION_HORZ_4 | PARTITION_VERT_4 => { + // lane-inter4 r1: four 32x8 / 8x32 inter strips, + // `quarter_step` = 2 mi -- the arm ReelC's first inter + // frame stops at (`value=9` = PARTITION_VERT_4). + // `at` is in 16-px cells and cannot name an 8-px + // offset, which is why `decode_inter_block` takes mi + // coordinates now. + let horz = part32 == PARTITION_HORZ_4; + let base_mi = (at.0 * (SUB / MI), at.1 * (SUB / MI)); + let (bw, bh) = if horz { (32usize, 8usize) } else { (8, 32) }; + for i in 0..4 { + let strip_mi = if horz { + (base_mi.0 + i * 2, base_mi.1) + } else { + (base_mi.0, base_mi.1 + i * 2) + }; + if i > 0 + && (strip_mi.0 >= mi_rows as usize + || strip_mi.1 >= mi_cols as usize) + { + break; + } + inter_piece!( + strip_mi, + BLOCK, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + bw, + bh + ); + if horz { + hit!(RECT4_32_HORZ_INTER_HITS); + } else { + hit!(RECT4_32_VERT_INTER_HITS); + } } } - } - _ => { - return Err(unsupported(format!( - "an INTER 32x32 partition type this decoder does not code (value={part32})" - ))); + _ => { + return Err(unsupported(format!( + "an INTER 32x32 partition type this decoder does not code (value={part32})" + ))); + } } } } } - } - if waving { - wave_submit(fctx, wave_job.0, wave_job.1); - } - // lane-timeline: this tile's last symbol is read here; its wavefront - // workers are drained by `_wave`'s drop at the end of the iteration. - crate::timeline::tile_done(); - flush_recon(fctx, &mut y, &mut u, &mut v); + if waving { + wave_submit(fctx, wave_job.0, wave_job.1); + } + // lane-timeline: this tile's last symbol is read here; its wavefront + // workers are drained by `_wave`'s drop at the end of the iteration. + crate::timeline::tile_done(); + flush_recon(fctx, &mut y, &mut u, &mut v); if tile_num == tile_info.context_update_tile_id { result_cdfs = cdfs; @@ -45753,14 +51791,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( order_hint, order_hint_bits, ref_order_hints, - fctx, + fctx, )); if let Some(stage1) = stage1 && superres(fctx).is_none() { stage1( result_cdfs.clone(), - motion_field.take().expect("the motion field was just built"), + motion_field + .take() + .expect("the motion field was just built"), frame_width as usize, frame_height as usize, ); @@ -45781,12 +51821,20 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst) ); } - dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); + dump_stage16( + "EC_AV1_PREFILT_DUMP16", + &y, + &u, + &v, + frame_width as usize, + frame_height as usize, + ); if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { use std::io::Write; let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { - let narrow = |p: &PlaneBuf<'_>| -> Vec { p.data.iter().map(|&s| s as u8).collect() }; + let narrow = + |p: &PlaneBuf<'_>| -> Vec { p.data.iter().map(|&s| s as u8).collect() }; let _ = f.write_all(&narrow(&y)); let _ = f.write_all(&narrow(&u)); let _ = f.write_all(&narrow(&v)); @@ -45831,7 +51879,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( loop_filter, &neighbours, frame_width as usize, - frame_height as usize, fctx, + frame_height as usize, + fctx, ); } // lane-perf4: loop restoration is the only reader of the pre-CDEF planes, @@ -45868,7 +51917,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter // dump above these bisect WHICH filter stage introduced a mismatch. dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v); - dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); + dump_stage16( + "EC_AV1_POSTDEBLOCK_DUMP16", + &y, + &u, + &v, + frame_width as usize, + frame_height as usize, + ); if !pipelined { apply_cdef( &mut y, @@ -45876,13 +51932,21 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut v, cdef, &neighbours, - (frame_width as usize, frame_height as usize), fctx, + (frame_width as usize, frame_height as usize), + fctx, None, None, ); } dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); - dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); + dump_stage16( + "EC_AV1_POSTCDEF_DUMP16", + &y, + &u, + &v, + frame_width as usize, + frame_height as usize, + ); capture_stages(&y, &u, &v, deblocked.as_ref(), fctx); // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called // between `av1_cdef_frame` and `av1_loop_restoration_filter_frame`): @@ -45896,10 +51960,20 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( let mut lr_w = frame_width as usize; if let Some((upscaled_w, _)) = superres(fctx) { let bd = u32::from(bit_depth(fctx)); - let (uw, fw, fh) = (upscaled_w as usize, frame_width as usize, frame_height as usize); + let (uw, fw, fh) = ( + upscaled_w as usize, + frame_width as usize, + frame_height as usize, + ); let up = |p: &PlaneBuf<'_>, in_w: usize, in_h: usize, out_w: usize| PlaneBuf { data: std::borrow::Cow::Owned(crate::superres::upscale_plane_strided( - &p.data, p.width, in_w, in_h, p.true_width, out_w, bd, + &p.data, + p.width, + in_w, + in_h, + p.true_width, + out_w, + bd, )), width: out_w, height: in_h, @@ -45910,12 +51984,20 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( tile_x1: out_w, tile_y1: in_h, }; - let (cw, ch, cuw) = (round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx)), round_ss(uw, ss_x(fctx))); + let (cw, ch, cuw) = ( + round_ss(fw, ss_x(fctx)), + round_ss(fh, ss_y(fctx)), + round_ss(uw, ss_x(fctx)), + ); y = up(&y, fw, fh, uw); u = up(&u, cw, ch, cuw); v = up(&v, cw, ch, cuw); if let Some((dy, du, dv)) = deblocked.take() { - deblocked = Some((up(&dy, fw, fh, uw), up(&du, cw, ch, cuw), up(&dv, cw, ch, cuw))); + deblocked = Some(( + up(&dy, fw, fh, uw), + up(&du, cw, ch, cuw), + up(&dv, cw, ch, cuw), + )); } lr_w = uw; crate::superres::note_upscaled_picture(); @@ -45926,8 +52008,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // band that completes the row's last line). if !pipelined { apply_loop_restoration( - &mut y, &mut u, &mut v, deblocked_y, deblocked_u, deblocked_v, lr, &lr_grid, - (lr_w, frame_height as usize), fctx, + &mut y, + &mut u, + &mut v, + deblocked_y, + deblocked_u, + deblocked_v, + lr, + &lr_grid, + (lr_w, frame_height as usize), + fctx, ); } } @@ -45988,8 +52078,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( width: true_width, height: true_height, y: crop(&y, true_width, true_height), - u: crop(&u, round_ss(true_width, ss_x(fctx)), round_ss(true_height, ss_y(fctx))), - v: crop(&v, round_ss(true_width, ss_x(fctx)), round_ss(true_height, ss_y(fctx))), + u: crop( + &u, + round_ss(true_width, ss_x(fctx)), + round_ss(true_height, ss_y(fctx)), + ), + v: crop( + &v, + round_ss(true_width, ss_x(fctx)), + round_ss(true_height, ss_y(fctx)), + ), }) } else { None @@ -46033,12 +52131,12 @@ mod tests { for h in [2usize, 3, 4, 5, 8, 9, 64, 65, 144, 145] { let cases = [ ("4:4:4", round_ss(w, 0) * round_ss(h, 0), (w, h)), - ("4:2:2", round_ss(w, 1) * round_ss(h, 0), (round_ss(w, 1), h)), ( - "4:2:0", - round_ss(w, 1) * round_ss(h, 1), - (w / 2, h / 2), + "4:2:2", + round_ss(w, 1) * round_ss(h, 0), + (round_ss(w, 1), h), ), + ("4:2:0", round_ss(w, 1) * round_ss(h, 1), (w / 2, h / 2)), ]; for (name, len, want) in cases { assert_eq!( @@ -46062,7 +52160,10 @@ mod tests { let (cw, ch) = ref_chroma_shape(round_ss(256, 1) * 144, 256, 144); assert_eq!((cw, ch), (128, 144)); // The bug's own signature: 72 rows claimed for 144 rows held. - assert!(ch > 144 / 2, "a 4:2:2 reference must not claim half its rows"); + assert!( + ch > 144 / 2, + "a 4:2:2 reference must not claim half its rows" + ); } /// [`last_only`] plus `GOLDEN_FRAME` (index 4 of the name-keyed array) @@ -46081,7 +52182,6 @@ mod tests { RefPix::ready(refs) } - /// lane-perf6 step 2: the CDEF kernel now reads a pre-gathered window and /// a pre-resolved damping shift instead of a bounds-testing closure and a /// per-tap `msb`. Both replacements must be value-identical to the spec @@ -46188,7 +52288,10 @@ mod tests { best_dir = i; } } - (best_dir, ((best_cost - cost[(best_dir + 4) & 7]) >> 10) as i32) + ( + best_dir, + ((best_cost - cost[(best_dir + 4) & 7]) >> 10) as i32, + ) } let mut rng = 0x0bad_c0de_dead_beefu64; let mut next = move || { @@ -46299,15 +52402,43 @@ mod tests { let mut a = seed.clone(); let mut b = seed; super::cdef_filter_block_scalar( - &win, &mut a, stride, 1, 1, bw, bh, pri, sec, dir, - damping, damping, ep, es, coeff_shift, smax, + &win, + &mut a, + stride, + 1, + 1, + bw, + bh, + pri, + sec, + dir, + damping, + damping, + ep, + es, + coeff_shift, + smax, ); // SAFETY: the avx2 arm was probed above. #[allow(unsafe_code)] unsafe { super::cdef_simd::filter_block_avx2( - &win, &mut b, stride, 1, 1, bw, bh, pri, sec, dir, - damping, damping, ep, es, coeff_shift, smax, + &win, + &mut b, + stride, + 1, + 1, + bw, + bh, + pri, + sec, + dir, + damping, + damping, + ep, + es, + coeff_shift, + smax, ) }; assert_eq!( @@ -46333,7 +52464,7 @@ mod tests { #[test] #[cfg(target_arch = "x86_64")] fn deblock_simd_kernel_matches_the_scalar_filter() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); if crate::mc::simd_level() != crate::mc::SimdLevel::Avx2 { eprintln!("SKIP deblock simd: no avx2"); return; @@ -46358,7 +52489,10 @@ mod tests { // Uniform-ish: every mask and both flats pass. 0 => base, // A step across the edge column/row. - 1 => (base + if k % stride >= 32 { smax / 2 } else { 0 }) % (smax + 1), + 1 => { + (base + if k % stride >= 32 { smax / 2 } else { 0 }) + % (smax + 1) + } // Small noise: flat passes at 8-bit, not always higher. 2 => (base + next() % 4) % (smax + 1), _ => next() % (smax + 1), @@ -46387,7 +52521,8 @@ mod tests { } let mut b = seed.clone(); assert!(super::filter_edge16( - &mut b, base, stride, vertical, len, level, sharpness, fctx, + &mut b, base, stride, vertical, len, level, sharpness, + fctx, )); assert_eq!( a, b, @@ -46411,23 +52546,32 @@ mod tests { /// `EXT_TX_SET_DCT_IDTX`, where IDTX survives and we forced `DCT_DCT`. #[test] fn an_inter_chroma_transform_narrows_its_inherited_tx_type_to_its_own_set() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); use TxType::*; // EXT_TX_SET_DCTONLY: `tx_size_sqr_up > TX_32X32`. set_inter_tx_mode(true, false, true, fctx); assert_eq!(reduce_inherited_chroma_tx_type(Idtx, 64, 64, fctx), DctDct); // EXT_TX_SET_DCT_IDTX at exactly TX_32X32 -- the residue's case. assert_eq!(reduce_inherited_chroma_tx_type(Idtx, 32, 32, fctx), Idtx); - assert_eq!(reduce_inherited_chroma_tx_type(AdstAdst, 32, 32, fctx), DctDct); + assert_eq!( + reduce_inherited_chroma_tx_type(AdstAdst, 32, 32, fctx), + DctDct + ); // EXT_TX_SET_DTT9_IDTX_1DDCT at `tx_size_sqr == TX_16X16`: the four // 1D ADST/FLIPADST types (TX_TYPES 12..15) drop out, the rest stay. assert_eq!(reduce_inherited_chroma_tx_type(HDct, 16, 16, fctx), HDct); - assert_eq!(reduce_inherited_chroma_tx_type(FlipAdstAdst, 16, 16, fctx), FlipAdstAdst); + assert_eq!( + reduce_inherited_chroma_tx_type(FlipAdstAdst, 16, 16, fctx), + FlipAdstAdst + ); assert_eq!(reduce_inherited_chroma_tx_type(HAdst, 16, 16, fctx), DctDct); // EXT_TX_SET_ALL16 below that (`tx_size_sqr < TX_16X16`, so a 16x8 // chroma unit too). assert_eq!(reduce_inherited_chroma_tx_type(HAdst, 16, 8, fctx), HAdst); - assert_eq!(reduce_inherited_chroma_tx_type(VFlipAdst, 8, 8, fctx), VFlipAdst); + assert_eq!( + reduce_inherited_chroma_tx_type(VFlipAdst, 8, 8, fctx), + VFlipAdst + ); // `reduced_tx_set` collapses every inter set to DCT_IDTX. set_inter_tx_mode(true, true, true, fctx); assert_eq!(reduce_inherited_chroma_tx_type(Idtx, 8, 8, fctx), Idtx); @@ -46514,7 +52658,10 @@ mod tests { but has no CDF class -- its use_filter_intra symbol is never read" ) }); - assert!(!why.is_empty(), "{bw}x{bh}'s refusal string must name the blocker"); + assert!( + !why.is_empty(), + "{bw}x{bh}'s refusal string must name the blocker" + ); } } } @@ -46737,8 +52884,14 @@ mod tests { "the two libaom source sequences must differ, or this pin would \ pass regardless of a swap" ); - assert_eq!(SCAN_8X4, LIBAOM_DEFAULT_SCAN_4X8, "SCAN_8X4 vs libaom default_scan_4x8"); - assert_eq!(SCAN_4X8, LIBAOM_DEFAULT_SCAN_8X4, "SCAN_4X8 vs libaom default_scan_8x4"); + assert_eq!( + SCAN_8X4, LIBAOM_DEFAULT_SCAN_4X8, + "SCAN_8X4 vs libaom default_scan_4x8" + ); + assert_eq!( + SCAN_4X8, LIBAOM_DEFAULT_SCAN_8X4, + "SCAN_4X8 vs libaom default_scan_8x4" + ); } /// lane-rectx r3: `av1_filter_intra_allowed_bsize` is "both sides <= 32", @@ -46761,12 +52914,29 @@ mod tests { const LIBAOM_16X8: u16 = 9394; let c16x8 = filter_intra_size_class_rect(16, 8).expect("16x8 reads use_filter_intra"); let c8x16 = filter_intra_size_class_rect(8, 16).expect("8x16 reads use_filter_intra"); - assert_ne!(c16x8, c8x16, "the two orientations must not share a CDF row"); - assert_eq!(cdf::FILTER_INTRA[c16x8][0], LIBAOM_16X8, "16x8 filter_intra row"); - assert_eq!(cdf::FILTER_INTRA[c8x16][0], LIBAOM_8X16, "8x16 filter_intra row"); + assert_ne!( + c16x8, c8x16, + "the two orientations must not share a CDF row" + ); + assert_eq!( + cdf::FILTER_INTRA[c16x8][0], + LIBAOM_16X8, + "16x8 filter_intra row" + ); + assert_eq!( + cdf::FILTER_INTRA[c8x16][0], + LIBAOM_8X16, + "8x16 filter_intra row" + ); // The sizes one class up keep their own distinct rows (lane-intradisp). - assert_eq!(cdf::FILTER_INTRA[filter_intra_size_class_rect(32, 16).unwrap()][0], 12756); - assert_eq!(cdf::FILTER_INTRA[filter_intra_size_class_rect(16, 32).unwrap()][0], 14301); + assert_eq!( + cdf::FILTER_INTRA[filter_intra_size_class_rect(32, 16).unwrap()][0], + 12756 + ); + assert_eq!( + cdf::FILTER_INTRA[filter_intra_size_class_rect(16, 32).unwrap()][0], + 14301 + ); // A size with a side over 32 is genuinely not allowed the flag. assert_eq!(filter_intra_size_class_rect(64, 32), None); } @@ -46810,11 +52980,22 @@ mod tests { ); assert!(neighbour_filter(None, [3, 0]).is_err()); let (h, v) = neighbour_filter(None, [0, 2]).expect("real symbols decode"); - assert_eq!(h, mc::InterpFilterKind::Sharp, "sym[1] is the horizontal kernel"); - assert_eq!(v, mc::InterpFilterKind::Regular, "sym[0] is the vertical kernel"); + assert_eq!( + h, + mc::InterpFilterKind::Sharp, + "sym[1] is the horizontal kernel" + ); + assert_eq!( + v, + mc::InterpFilterKind::Regular, + "sym[0] is the vertical kernel" + ); let (h, v) = neighbour_filter(Some(mc::InterpFilterKind::Smooth), [3, 3]) .expect("a fixed-filter frame never reads a symbol"); - assert_eq!((h, v), (mc::InterpFilterKind::Smooth, mc::InterpFilterKind::Smooth)); + assert_eq!( + (h, v), + (mc::InterpFilterKind::Smooth, mc::InterpFilterKind::Smooth) + ); } /// lane-t900 r27, structural audit for "an OBMC neighbour whose switchable @@ -46926,12 +53107,22 @@ mod tests { let mut refs: [Option<&Picture>; 8] = [None; 8]; refs[1] = Some(&pic); let refpix = RefPix::ready(refs); - for ref_frame in [LAST2_FRAME, LAST3_FRAME, GOLDEN_FRAME, BWDREF_FRAME, ALTREF2_FRAME, ALTREF_FRAME] { + for ref_frame in [ + LAST2_FRAME, + LAST3_FRAME, + GOLDEN_FRAME, + BWDREF_FRAME, + ALTREF2_FRAME, + ALTREF_FRAME, + ] { let err = match ref_planes(ref_frame, &refpix) { Ok(_) => panic!("ref {ref_frame}: an empty slot resolved to a picture"), Err(e) => e.to_string(), }; - assert!(err.contains(REFUSAL), "ref {ref_frame}: expected {REFUSAL:?}, got: {err}"); + assert!( + err.contains(REFUSAL), + "ref {ref_frame}: expected {REFUSAL:?}, got: {err}" + ); } // `LAST_FRAME` never consults the slots: `decode_stream` checked it. let Ok((y, _, _)) = ref_planes(LAST_FRAME, &refpix) else { @@ -46942,7 +53133,7 @@ mod tests { #[test] fn record_compound_ctx_stamps_ref1_for_the_next_block_to_read() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); let mut n = Neighbours::new(4, 4, 16, 16, fctx); n.record_inter((0, 0), SUB, false, true, LAST_FRAME, [3, 3], false); assert_eq!(n.above_ref1[0], None, "record_inter alone never sets ref1"); @@ -46961,7 +53152,7 @@ mod tests { /// [[cdf-row-held-constant]]). #[test] fn a_sub16_leaf_after_a_palette_block_yields_palette_ctx_zero() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); let mut n = Neighbours::new(4, 4, 16, 16, fctx); // A real 16x16 palette block covering SUB cell (1, 1). n.record_palette_y_rect((4, 4), 16, 16, 2, [7, 9, 0, 0, 0, 0, 0, 0]); @@ -46988,12 +53179,19 @@ mod tests { /// narrowed `(u16, u8)` mi maps keep their "never written" sentinel. #[test] fn narrowed_publish_surface_keeps_neighbour_semantics() { - assert_eq!(std::mem::size_of::<(u16, u8)>(), 4, "the narrowing must actually be 4 bytes"); + assert_eq!( + std::mem::size_of::<(u16, u8)>(), + 4, + "the narrowing must actually be 4 bytes" + ); let fctx = &crate::decode::FrameCtx::new(); let mut n = Neighbours::new(4, 4, 16, 16, fctx); n.record_palette_y_rect((4, 4), 16, 16, 2, [7, 9, 0, 0, 0, 0, 0, 0]); n.record_palette_y_rect((4, 4), 16, 16, 0, [0u16; 8]); - assert_eq!(n.above_palette_size[4], 0, "the size is what a reader gates on"); + assert_eq!( + n.above_palette_size[4], 0, + "the size is what a reader gates on" + ); assert_eq!( n.above_palette_colors[4], [7, 9, 0, 0, 0, 0, 0, 0], @@ -47002,7 +53200,11 @@ mod tests { let (ctx, cache) = n.palette_ctx_and_cache((1, 1)); assert_eq!(ctx, 0, "and they stay invisible to every reader"); assert!(cache.is_empty()); - assert_eq!(n.mode_above_mi(4, 4), None, "u16::MAX sentinel = never written"); + assert_eq!( + n.mode_above_mi(4, 4), + None, + "u16::MAX sentinel = never written" + ); n.record_mode_mi(3, 4, 1, 1, DC_PRED); assert_eq!(n.mode_above_mi(4, 4), Some(DC_PRED)); } @@ -47027,7 +53229,7 @@ mod tests { #[test] fn a_frame_with_no_mode_info_grid_is_refused() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); assert!( decode_key_frame_tile( &[0u8; 4], @@ -47042,7 +53244,8 @@ mod tests { false, true, false, - false, fctx, + false, + fctx, ) .is_err() ); @@ -47076,7 +53279,9 @@ mod tests { cdef, loop_restoration, .. - }: Encoded = crate::encode::encode_key_frame_with_modes_with_ctx(&picture, 40, 0.0, modes, fctx).unwrap(); + }: Encoded = + crate::encode::encode_key_frame_with_modes_with_ctx(&picture, 40, 0.0, modes, fctx) + .unwrap(); let decoded = decode_key_frame_tile_lr( &tile, mi_cols, @@ -47094,7 +53299,8 @@ mod tests { true, false, false, - &loop_restoration, fctx, + &loop_restoration, + fctx, ) .unwrap(); assert_eq!(decoded.width, w, "{w}x{h}: decoded width"); @@ -47106,7 +53312,7 @@ mod tests { #[test] fn real_yuv_round_trips_bit_exact_against_the_encoder_reconstruction() { - let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) for (w, h) in [(128usize, 128usize), (192, 128)] { round_trips(w, h, &[DC_PRED as u8], fctx); } @@ -47118,7 +53324,7 @@ mod tests { /// decoder round adds, not just `DC_PRED`. #[test] fn every_intra_mode_round_trips_bit_exact_against_the_encoder_reconstruction() { - let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) for (w, h) in [(128usize, 128usize), (192, 128)] { round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx); } @@ -47129,7 +53335,7 @@ mod tests { /// this decoder round adds. #[test] fn odd_sizes_round_trip_bit_exact_against_the_encoder_reconstruction() { - let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: encodes, so the decode context takes this process's superblock size + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: encodes, so the decode context takes this process's superblock size for (w, h) in [(854usize, 480usize), (216, 96)] { round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx); } @@ -47143,7 +53349,7 @@ mod tests { /// bit, `partition_w8` leaves). #[test] fn leaf8_straddle_sizes_round_trip_bit_exact_against_the_encoder_reconstruction() { - let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) for (w, h) in [(40usize, 32usize), (640, 360)] { round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx); } @@ -47158,7 +53364,7 @@ mod tests { /// refusing. #[test] fn a_skipped_block_decodes_to_pure_prediction() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); use crate::msac::SymbolEncoder; let mut cdfs = Cdfs::new(q_ctx_of(40)); let mut enc = SymbolEncoder::new(); @@ -47184,7 +53390,8 @@ mod tests { false, true, false, - false, fctx, + false, + fctx, ) .unwrap(); assert!( @@ -47324,7 +53531,7 @@ mod tests { /// and asserts this decoder refuses by name rather than decoding garbage. #[test] fn a_non_split_inter_sb_partition_refuses_by_name_instead_of_desyncing() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); use crate::msac::SymbolEncoder; let mut cdfs = Cdfs::new(q_ctx_of(40)); let mut enc = SymbolEncoder::new(); @@ -47430,8 +53637,14 @@ mod tests { width, height, y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(), - u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), - v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), + u: out.stdout[luma..luma + chroma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + v: out.stdout[luma + chroma..] + .iter() + .map(|&v| u16::from(v)) + .collect(), } } @@ -47467,9 +53680,18 @@ mod tests { Picture { width, height, - y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), - u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), - v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), + y: out.stdout[base..base + luma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + u: out.stdout[base + luma..base + luma + chroma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + v: out.stdout[base + luma + chroma..base + frame_bytes] + .iter() + .map(|&v| u16::from(v)) + .collect(), } }) .collect() @@ -47524,7 +53746,7 @@ mod tests { /// crate's own writer and reader could otherwise share. #[test] fn ffmpeg_and_this_decoder_agree_on_a_key_frame() { - let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) if !have_ffmpeg() { eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_key_frame: no ffmpeg"); return; @@ -47552,7 +53774,8 @@ mod tests { true, encoded.screen, encoded.allow_intrabc, - &encoded.loop_restoration, fctx, + &encoded.loop_restoration, + fctx, ) .unwrap(); assert_eq!(ours.y, ffmpeg_decoded.y, "{width}x{height}: luma vs ffmpeg"); @@ -47592,7 +53815,11 @@ mod tests { // through the middle of every superblock, which no 64x64 // prediction fits and which sends the quadrants back to the // sizes the recursive modes are offered at. - let step = if (row % 64) > 40 && (col % 64) > 24 { 55.0 } else { 0.0 }; + let step = if (row % 64) > 40 && (col % 64) > 24 { + 55.0 + } else { + 0.0 + }; let v = 128.0 + 60.0 * ((row as f64) / 9.0).sin() * ((col as f64) / 11.0).cos() + 8.0 * ((row + col) as f64 / 3.0).sin() @@ -47622,13 +53849,19 @@ mod tests { ) .unwrap(); let fired = filter_intra_hits() - before; - assert!(fired > 0, "no block took filter intra -- the gate is blind to the feature"); + assert!( + fired > 0, + "no block took filter intra -- the gate is blind to the feature" + ); eprintln!("a_filter_intra_key_frame: {fired} filter-intra blocks"); let ffmpeg_decoded = ffmpeg_decode(&encoded.stream, coded_w as usize, coded_h as usize); assert_eq!(ours.y, ffmpeg_decoded.y, "luma vs ffmpeg"); assert_eq!(ours.u, ffmpeg_decoded.u, "U vs ffmpeg"); assert_eq!(ours.v, ffmpeg_decoded.v, "V vs ffmpeg"); - assert_eq!(ours.y, encoded.reconstruction.y, "luma vs the encoder's own reconstruction"); + assert_eq!( + ours.y, encoded.reconstruction.y, + "luma vs the encoder's own reconstruction" + ); } /// The key frame the encoder writes carries `tx_mode == TxMode::Select`, @@ -47761,7 +53994,8 @@ mod tests { // ... and its own `allow_intrabc`: every intra block carries a // `use_intrabc` symbol under it (stale-header class). key.allow_intrabc, - &key.loop_restoration, fctx, + &key.loop_restoration, + fctx, ) .unwrap(); assert_eq!( @@ -47847,7 +54081,7 @@ mod tests { #[test] fn a_gop_round_trips_bit_exact_against_the_encoder_reconstruction() { - let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) gop_round_trips(128, 64, fctx); } @@ -47856,7 +54090,7 @@ mod tests { /// split path is exercised too. #[test] fn an_odd_size_gop_round_trips_bit_exact_against_the_encoder_reconstruction() { - let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) gop_round_trips(216, 96, fctx); } @@ -47869,7 +54103,7 @@ mod tests { /// writes NEARMV (round 3: it never chooses the mode). #[test] fn a_nearmv_block_predicts_from_the_stacks_second_candidate() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); use crate::msac::SymbolEncoder; use crate::mvstack::{MiGrid, MiInfo, find_mv_stack, single_ref_ctx}; @@ -48034,7 +54268,8 @@ mod tests { side, side, false, - width, fctx, + width, + fctx, ) .unwrap(); // lane-wave1: a direct caller of the block decoder RECORDS its writes @@ -48053,7 +54288,8 @@ mod tests { mv_to_q4(py, left_mv.0, 0), side, side, - &mut want_near, fctx, + &mut want_near, + fctx, ); let mut want_nearest = vec![0u16; side * side]; crate::mc::predict( @@ -48065,7 +54301,8 @@ mod tests { mv_to_q4(py, above_mv.0, 0), side, side, - &mut want_nearest, fctx, + &mut want_nearest, + fctx, ); assert_ne!( want_near, want_nearest, @@ -48086,7 +54323,7 @@ mod tests { #[test] fn ffmpeg_and_this_decoder_agree_on_a_gop() { - let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) if !have_ffmpeg() { eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_gop: no ffmpeg"); return; @@ -48123,7 +54360,8 @@ mod tests { // ... and its own `allow_intrabc`: every intra block carries a // `use_intrabc` symbol under it (stale-header class). key.allow_intrabc, - &key.loop_restoration, fctx, + &key.loop_restoration, + fctx, ) .unwrap(); assert_eq!(reference.y, ffmpeg_frames[0].y, "frame 0 luma vs ffmpeg"); @@ -48203,7 +54441,11 @@ mod tx4x8_table_tests { seen_a[a] = true; seen_b[b] = true; let (row, col) = (a / 4, a % 4); - assert_eq!(b, col * 8 + row, "SCAN_8X4[{k}] is not SCAN_4X8[{k}] transposed"); + assert_eq!( + b, + col * 8 + row, + "SCAN_8X4[{k}] is not SCAN_4X8[{k}] transposed" + ); } assert!(seen_a.iter().all(|&s| s) && seen_b.iter().all(|&s| s)); } @@ -48262,7 +54504,7 @@ mod tx4x8_table_tests { /// makes this an asymmetric check rather than a tautology. #[test] fn the_sub8_rect_reach_tables_are_shape_specific() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); let a = Reach::of_rect(4, 8, 4, 8, 64, 64, fctx); let b = Reach::of_rect(8, 4, 8, 4, 64, 64, fctx); assert!( diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index de5cbe2f..e1a578f2 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -1,3 +1,5 @@ +/home/user/Documents/Code/Rust/edith_codecs/crates/ec-av1/src/stream.rs: + //! The stream-level entry point a real decoder needs: walk a raw AV1 OBU //! stream (`Encoded::stream`, or any low-overhead-format bitstream this //! crate's own writers produce) via [`ec_av1_syntax::Av1Parser`] and dispatch @@ -28,12 +30,9 @@ use ec_core::{Error, Result}; use crate::cdf_state::Cdfs; use crate::decode; -use crate::decode::{ - decode_inter_frame_tile_with_cdfs, decode_key_frame_tile_with_cdfs, - q_ctx_of, -}; #[cfg(test)] use crate::decode::decode_key_frame_tile_lr; +use crate::decode::{decode_inter_frame_tile_with_cdfs, decode_key_frame_tile_with_cdfs, q_ctx_of}; use crate::encode::Picture; /// lane-midcut r1: `EC_AV1_NO_GRAIN=1` skips film grain synthesis at output, so a @@ -217,6 +216,22 @@ pub fn intrabc_128rect_hits() -> usize { crate::decode::intrabc_128rect_hits() } +/// lane-av1-ibc128chunk: chroma transform units the 128-root intrabc strip's +/// mu-chunk walk read, one per `read_inter_plane` chroma call. At 4:2:2 a +/// 64x64 mu chunk's chroma plane block is 32x64 and holds TWO STACKED +/// TX_32X32 units per plane; the square-cut walk this gate witnesses read +/// one. Measured on the pinned witness: 8 before, 48 after. +pub fn intrabc_128rect_chroma_chunk_hits() -> usize { + crate::decode::intrabc_128rect_chroma_chunk_hits() +} + +/// lane-av1-ibc128chunk: the 128-root intrabc strip's per-axis chroma chunk +/// extents as `(64 >> ss_x) << 8 | (64 >> ss_y)` on the last chunk walked -- +/// 32|32 at 4:2:0, 32|64 at 4:2:2, 64|64 at 4:4:4. +pub fn intrabc_128rect_chunk_shape() -> usize { + crate::decode::intrabc_128rect_chunk_shape() +} + /// Blocks reconstructed with intra block copy at an 8x8 LEAF specifically /// (lane-kf900 r7's shape); [`crate::decode::intrabc_hits`] counts every shape. pub fn leaf8_intrabc_hits() -> usize { @@ -384,16 +399,19 @@ struct Reorder { } impl Reorder { - fn push(&mut self, seq: usize, picture: std::sync::Arc, decode_idx: usize, shown: bool) { + fn push( + &mut self, + seq: usize, + picture: std::sync::Arc, + decode_idx: usize, + shown: bool, + ) { self.pending.insert(seq, (picture, decode_idx, shown)); } /// Emits every queued picture whose turn has come. An `Err` from `sink` /// aborts the decode, unchanged, exactly as the serial path did. - fn drain( - &mut self, - sink: &mut impl FnMut(&Picture, usize, bool) -> Result<()>, - ) -> Result<()> { + fn drain(&mut self, sink: &mut impl FnMut(&Picture, usize, bool) -> Result<()>) -> Result<()> { while let Some((picture, decode_idx, shown)) = self.pending.remove(&self.next) { self.next += 1; sink(&picture, decode_idx, shown)?; @@ -411,8 +429,7 @@ impl Reorder { /// inline. (lane-thread2 counted only LEAF frames, the only ones it could /// dispatch; lane-thread3 dispatches every non-key, non-`show_existing_frame` /// frame, hence the rename.) -static FRAMES_DISPATCHED: std::sync::atomic::AtomicUsize = - std::sync::atomic::AtomicUsize::new(0); +static FRAMES_DISPATCHED: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); /// Reads [`FRAMES_DISPATCHED`]. pub fn frames_dispatched() -> usize { @@ -724,12 +741,12 @@ pub fn decode_stream_with_threads( let capped = in_flight_shows >= in_flight_cap; while in_flight_shows >= in_flight_cap { collect_one( - &rx, - &mut in_flight_decodes, - &mut in_flight_shows, - &mut reorder, - &mut sink, - )?; + &rx, + &mut in_flight_decodes, + &mut in_flight_shows, + &mut reorder, + &mut sink, + )?; } if capped { crate::timeline::cap_wait("show", cap_t0, crate::timeline::now()); @@ -803,7 +820,8 @@ pub fn decode_stream_with_threads( &picture, &header.film_grain, mc_identity, - bit_depth as u32, fctx, + bit_depth as u32, + fctx, )) } else { picture @@ -1214,8 +1232,7 @@ pub fn decode_stream_with_threads( final_dump.as_deref(), None, )?; - let motion_field = - motion_field.expect("the inline path passes no stage-1 sink"); + let motion_field = motion_field.expect("the inline path passes no stage-1 sink"); pictures_decoded += 1; // lane-pool1: one allocation, then every slot store and the output // itself are refcount bumps instead of plane copies. @@ -1271,7 +1288,8 @@ pub fn decode_stream_with_threads( &picture, &header.film_grain, mc_identity, - bit_depth as u32, fctx, + bit_depth as u32, + fctx, )) } else { picture @@ -1304,8 +1322,6 @@ pub fn decode_stream_with_threads( Ok(()) } - - /// lane-thread2: the sequence-header bits a single frame's decode needs, /// read once on the parsing thread so that [`decode_frame`] never touches the /// [`Av1Parser`] (a worker thread has no access to it). @@ -1394,8 +1410,8 @@ impl<'a> RefSnapshot<'a> { // spec 7.9's own driver, `av1_setup_motion_field`: only run when // this frame's header asks for it, and never for a key frame (which // codes no inter block at all). - let tpl_field = (header.frame_type != FrameType::Key && header.use_ref_frame_mvs).then( - || { + let tpl_field = + (header.frame_type != FrameType::Key && header.use_ref_frame_mvs).then(|| { crate::motion_field::setup_motion_field( motion_field_slots, header.ref_frame_idx, @@ -1404,8 +1420,7 @@ impl<'a> RefSnapshot<'a> { header.mi_rows as usize, header.mi_cols as usize, ) - }, - ); + }); if std::env::var_os("EC_TPL").is_some() { eprintln!( "EC_TPL order_hint={} use_ref_frame_mvs={} cells={}", @@ -1520,7 +1535,8 @@ fn decode_frame( header.segmentation, header.mi_rows as usize, header.mi_cols as usize, - snap.prev_seg_map.as_deref(), fctx, + snap.prev_seg_map.as_deref(), + fctx, ); // lane-superres stage 2/3: `use_superres` adds/removes no per-block // symbol (spec 7.16's upscaling is a pixel-domain post-process @@ -1833,8 +1849,13 @@ fn decode_frame( // the LR unit grid in upscaled coordinates. Cleared (0, 8) on an // unscaled frame so a later frame never inherits it. crate::decode::set_superres( - if header.use_superres { header.upscaled_width } else { 0 }, - u32::from(header.superres_denom), fctx, + if header.use_superres { + header.upscaled_width + } else { + 0 + }, + u32::from(header.superres_denom), + fctx, ); // lane-av1comp: `comp_group_idx`/`compound_idx`'s own gating bits. let enable_masked_compound = seq.enable_masked_compound; @@ -1942,7 +1963,8 @@ fn decode_frame( header.reduced_tx_set, header.allow_screen_content_tools, header.allow_intrabc, - header.delta, fctx, + header.delta, + fctx, )?; // A key frame codes no inter blocks -- its own saved motion // field has no cells set, matching libaom's own "intra frame @@ -2219,9 +2241,8 @@ pub(crate) mod tests { crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap(); seq.seq_profile = profile; let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap(); - stream.extend_from_slice( - &crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap(), - ); + stream + .extend_from_slice(&crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap()); let err = decode_stream(&stream).unwrap_err().to_string(); assert!( err.contains(REFUSAL), @@ -2233,7 +2254,11 @@ pub(crate) mod tests { let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap(); stream.extend_from_slice(&crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap()); let frames = decode_stream(&stream).expect("the 4:2:0 control must decode"); - assert_eq!(frames.len(), 1, "{NAME}: the 4:2:0 control decoded no frame"); + assert_eq!( + frames.len(), + 1, + "{NAME}: the 4:2:0 control decoded no frame" + ); } /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned /// as fixtures (`git add -f`; `fixtures/` is gitignored). @@ -2291,6 +2316,193 @@ pub(crate) mod tests { } } + /// lane-av1-ibc128chunk: the WITNESS for the 128-root intrabc strip's + /// de-square-cut mu-chunk chroma walk, and the byte pin for it. + /// + /// `decode_intrabc_128rect` cut each mu chunk's chroma plane block with + /// `chunk_chroma = cside * 64 / side` -- a `chroma_side`-SQUARE chunk, + /// i.e. the 4:2:0 count on BOTH axes (the same defect lane-av1-422bigblock + /// fixed, and witnessed, in `decode_inter_block` and + /// `decode_block_128rect`; this copy was deferred there as unwitnessed). + /// At 4:2:2 a 64x64 mu chunk's chroma plane block is 32x64, so it holds + /// TWO STACKED TX_32X32 units per plane: the square-cut walk read one per + /// plane per chunk, left the chunk's lower 32 chroma rows with no + /// residual at all, and stamped each unit's entropy context over a + /// 16x16-mi luma span instead of 16x8. + /// + /// Measured red-before on the pinned witness (parent `a7d22aec`, via the + /// local `EC_AV1_ALLOW_422_PROBE` patch-run-restore build): 8 chroma + /// units stamped over the stream's two reached blocks and frames 0 and 3 + /// diverge from `aomdec` (45135 / 44540 of 245760 samples each), the + /// first difference at Y sample 98368 -- frame 0, row 256, col 64, the + /// top-left corner of the first 128x64 intrabc block at mi(64,0). The + /// red build then lost 4 of the stream's 6 intrabc blocks to the desync. + /// Green-after, same fixture: 48 chroma units stamped, all 6 blocks + /// decoded, and ALL FIVE frames byte-identical to `aomdec --rawvideo`. + /// + /// Committed code refuses 4:2:2 at the sequence header, so the decode + /// assertions above are probe-measured and reproducible from the lane + /// report's recipe; what this gate can assert in committed code is the + /// byte pin, the refusal-by-name contract, and -- in the arm below -- + /// that the per-axis walk is still spelled per-axis in the source. + #[test] + fn the_pinned_422_intrabc_sb128_strip_witnesses_refuse_by_name() { + const NAME: &str = "the_pinned_422_intrabc_sb128_strip_witnesses_refuse_by_name"; + const REFUSAL: &str = "a chroma format of 4:2:2"; + for (file, bytes, fp) in [ + ( + "422_intrabc_sb128_strip.obu", + 1672usize, + 0x50f5cfc576e4cd00_u64, + ), + ( + "422_intrabc_sb128_strip_notxsearch.obu", + 1675, + 0xd4936f252ff8cff0, + ), + ] { + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("fixtures") + .join(file); + let data = std::fs::read(&path).unwrap_or_else(|e| { + panic!( + "{NAME}: pinned witness {} is missing ({e}) -- the gate cannot run", + path.display() + ) + }); + assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted"); + assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted"); + let err = decode_stream(&data).unwrap_err().to_string(); + assert!( + err.contains(REFUSAL), + "{NAME}: {file} must refuse by name, got: {err}" + ); + } + } + + /// lane-av1-ibc128chunk: the SOURCE-SCAN arm of the witness gate above. + /// + /// The decode-level half of the red/green evidence cannot run in + /// committed code (the 4:2:2 refusal stands), so this arm pins the thing + /// that would silently bring the defect back: the square-cut + /// `chunk_chroma = cside * 64 / side` expression, and the per-axis + /// replacements that replaced it at BOTH sites in + /// [`decode_intrabc_128rect`] -- the mu-chunk read walk and the + /// `mu_chroma` per-unit context replay. It also pins the per-axis + /// counters' accessors so the arms stay reachable, and the walk's own + /// per-axis extent, derived here from the same `64 >> ss` form the + /// witnesses measured (4:2:0 = one TX_32X32 per plane per chunk, + /// 4:2:2 = two stacked, 4:4:4 = four). + #[test] + fn the_intrabc_128rect_chroma_chunk_walk_stays_per_axis() { + const NAME: &str = "the_intrabc_128rect_chroma_chunk_walk_stays_per_axis"; + let src = include_str!("decode.rs"); + let body = src + .split_once("fn decode_intrabc_128rect(") + .expect("decode_intrabc_128rect must exist") + .1 + .split_once("\nfn ") + .expect("decode_intrabc_128rect must be a top-level fn") + .0; + // Scan CODE only: the fix's own comments quote the old expression to + // say what it was, and a prose mention must not read as a + // reintroduction (nor mask one). + let stripped: Vec<&str> = body + .lines() + .map(|l| l.split_once("//").map_or(l, |(c, _)| c)) + .collect(); + let code = stripped.join("\n"); + let body = code.as_str(); + assert_eq!( + body.matches("cside * 64 / side").count(), + 0, + "{NAME}: the square-cut `cside * 64 / side` chunk extent is BACK in \ + decode_intrabc_128rect -- that expression is the 4:2:2 defect this \ + gate exists for (a 64x64 mu chunk's chroma plane block is \ + (64 >> ss_x) x (64 >> ss_y), not `chroma_side` square)" + ); + // The per-axis chunk extent, declared once at the mu-chunk read walk + // and once at the `mu_chroma` replay -- the two de-square-cut sites. + // + // The replay must ALSO enumerate every unit inside a chunk, not just + // its first: counting mu CHUNKS in `rows`/`cols` and then stepping the + // mi origin and reading the grid per UNIT only agrees when a chunk + // holds exactly one unit (4:2:0). At 4:2:2 and 4:4:4 a chunk holds two + // or four, so the per-unit body alone left the rest of the chunk with + // the composed-grid smearing the replay exists to undo. + for name in [ + "let chunk_chroma_w = (64usize) >> ss_x(fctx);", + "let chunk_chroma_h = (64usize) >> ss_y(fctx);", + ] { + assert_eq!( + body.matches(name).count(), + 2, + "{NAME}: `{name}` must appear at BOTH de-square-cut sites in \ + decode_intrabc_128rect (the mu-chunk read walk and the mu_chroma \ + context replay), found {}", + body.matches(name).count() + ); + } + for name in [ + "let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w / cu);", + "for kr in 0..ur {", + "for kc in 0..uc {", + ] { + assert_eq!( + body.matches(name).count(), + 1, + "{NAME}: `{name}` must appear exactly once in \ + decode_intrabc_128rect -- the mu_chroma replay must walk chunk \ + THEN unit (decode_inter_block's `mu_chroma_units` shape), found {}", + body.matches(name).count() + ); + } + for name in [ + "let unit_luma_w = cu_tx << ss_x(fctx);", + "let unit_luma_h = cu_tx << ss_y(fctx);", + "let (cw, ch) = (bw >> ss_x(fctx), bh >> ss_y(fctx));", + "let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));", + "neighbours.around_mi_rect(unit_mi, unit_luma_w, unit_luma_h)", + ] { + assert_eq!( + body.matches(name).count(), + 1, + "{NAME}: `{name}` must appear exactly once in \ + decode_intrabc_128rect, found {}", + body.matches(name).count() + ); + } + // The replay's own unit luma span is the lossless/lossy `cu << ss` form + // (site 2 spells it separately from the read walk's `cu_tx << ss`). + for name in [ + "let unit_luma_w = cu << ss_x(fctx);", + "let unit_luma_h = cu << ss_y(fctx);", + ] { + assert_eq!( + body.matches(name).count(), + 1, + "{NAME}: `{name}` must appear exactly once in \ + decode_intrabc_128rect, found {}", + body.matches(name).count() + ); + } + // The per-axis chunk extent the geometry demands, spelled out here so + // the scan and the witnesses cannot disagree about it. + let per_axis_units = |ss_x: u32, ss_y: u32| (64 >> ss_x) / 32 * (64 >> ss_y) / 32; + assert_eq!(per_axis_units(1, 1), 1, "{NAME}: 4:2:0 must stay one unit"); + assert_eq!(per_axis_units(1, 0), 2, "{NAME}: 4:2:2 must be two units"); + assert_eq!(per_axis_units(0, 0), 4, "{NAME}: 4:4:4 must be four units"); + // The counters the probe arms read must stay exported. + for name in [ + "pub fn intrabc_128rect_chroma_chunk_hits()", + "pub fn intrabc_128rect_chunk_shape()", + ] { + assert!( + src.contains(name), + "{NAME}: the accessor `{name}` must stay in decode.rs" + ); + } + } /// lane-av1-qmatrix: WITNESS for the lifted `using_qmatrix` refusal (the /// old gate `a_frame_using_quantisation_matrices_is_refused_by_name` is @@ -2376,7 +2588,12 @@ pub(crate) mod tests { .collect(); args.push(format!("--limit={FRAMES}")); args.extend(extra.iter().map(|s| (*s).to_owned())); - args.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]); + args.extend([ + "--obu".to_owned(), + "-o".to_owned(), + "-".to_owned(), + "-".to_owned(), + ]); let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), @@ -2393,13 +2610,23 @@ pub(crate) mod tests { decode_stream(stream).unwrap_or_else(|e| panic!("{NAME}: {label} decode: {e}")); assert_eq!(got.len(), want.len(), "{NAME}: {label} frame count"); for (i, (g, w)) in got.iter().zip(want.iter()).enumerate() { - for (plane, (gp, wp)) in - [(&g.y, &w.y), (&g.u, &w.u), (&g.v, &w.v)].into_iter().enumerate() + for (plane, (gp, wp)) in [(&g.y, &w.y), (&g.u, &w.u), (&g.v, &w.v)] + .into_iter() + .enumerate() { - assert_eq!(gp, wp, + assert_eq!( + gp, + wp, "{NAME}: {label} frame {i} plane {plane} differs from ffmpeg (first mismatching sample: got {}, want {})", - gp.iter().zip(wp.iter()).find(|(a, b)| a != b).map_or(0, |(a, _)| *a), - gp.iter().zip(wp.iter()).find(|(a, b)| a != b).map_or(0, |(_, b)| *b)); + gp.iter() + .zip(wp.iter()) + .find(|(a, b)| a != b) + .map_or(0, |(a, _)| *a), + gp.iter() + .zip(wp.iter()) + .find(|(a, b)| a != b) + .map_or(0, |(_, b)| *b) + ); } } }; @@ -2417,7 +2644,10 @@ pub(crate) mod tests { "{NAME}: the qm-off control decoded no frame" ); for (using, y, u, v) in qm_headers(&control_stream) { - assert!(!using, "{NAME}: the control's frame header set using_qmatrix"); + assert!( + !using, + "{NAME}: the control's frame header set using_qmatrix" + ); assert_eq!( (y, u, v), (0, 0, 0), @@ -2579,7 +2809,7 @@ pub(crate) mod tests { /// never reports this refusal for any of them. #[test] fn a_frame_obu_that_parses_always_carries_at_least_one_tile() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); const REFUSAL: &str = "a frame OBU with no tile group"; let picture = test_card(64, 64); let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); @@ -2635,9 +2865,8 @@ pub(crate) mod tests { /// first, a middle and the last segment id. #[test] fn a_frame_whose_segmentation_overrides_a_block_mode_is_refused_by_name() { - let fctx = &crate::decode::FrameCtx::new(); - const REFUSAL: &str = - "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV"; + let fctx = &crate::decode::FrameCtx::new(); + const REFUSAL: &str = "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV"; let picture = test_card(64, 64); let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap(); @@ -2688,15 +2917,31 @@ pub(crate) mod tests { let src = format!("{source}=size={width}x{height}:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &src, "-t", &duration, "-pix_fmt", "yuv420p", - "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &src, + "-t", + &duration, + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() .expect("ffmpeg failed to run"); - assert!(y4m.status.success(), "ffmpeg refused the {width}x{height} fixture"); + assert!( + y4m.status.success(), + "ffmpeg refused the {width}x{height} fixture" + ); let limit = format!("--limit={frames}"); let mut args: Vec = [ "--codec=av1", @@ -2712,10 +2957,18 @@ pub(crate) mod tests { .collect(); args.push(limit); args.extend(extra.iter().map(|s| (*s).to_owned())); - args.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); - assert!(out.status.success(), "aomenc refused {args:?}: {}", String::from_utf8_lossy(&out.stderr)); + args.extend([ + "--obu".to_owned(), + "-o".to_owned(), + "-".to_owned(), + "-".to_owned(), + ]); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); + assert!( + out.status.success(), + "aomenc refused {args:?}: {}", + String::from_utf8_lossy(&out.stderr) + ); let stream = out.stdout; let result = match decode_stream(&stream) { Ok(pictures) => Ok(pictures.len()), @@ -2740,15 +2993,31 @@ pub(crate) mod tests { let src = format!("{source}=size={width}x{height}:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &src, "-t", &duration, "-pix_fmt", "yuv420p", - "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &src, + "-t", + &duration, + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() .expect("ffmpeg failed to run"); - assert!(y4m.status.success(), "ffmpeg refused the {width}x{height} fixture"); + assert!( + y4m.status.success(), + "ffmpeg refused the {width}x{height} fixture" + ); let limit = format!("--limit={frames}"); let mut args: Vec = [ "--codec=av1", @@ -2764,9 +3033,18 @@ pub(crate) mod tests { .collect(); args.push(limit); args.extend(extra.iter().map(|s| (*s).to_owned())); - args.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]); + args.extend([ + "--obu".to_owned(), + "-o".to_owned(), + "-".to_owned(), + "-".to_owned(), + ]); let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); - assert!(out.status.success(), "aomenc refused {args:?}: {}", String::from_utf8_lossy(&out.stderr)); + assert!( + out.status.success(), + "aomenc refused {args:?}: {}", + String::from_utf8_lossy(&out.stderr) + ); out.stdout } @@ -2787,17 +3065,34 @@ pub(crate) mod tests { let src = format!("{source}=size={width}x{height}:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &src, "-t", &duration, "-pix_fmt", "yuv420p", - "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &src, + "-t", + &duration, + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() .expect("ffmpeg failed to run"); - assert!(y4m.status.success(), "ffmpeg refused the {width}x{height} fixture"); + assert!( + y4m.status.success(), + "ffmpeg refused the {width}x{height} fixture" + ); let limit = format!("--limit={frames}"); - let fpf = std::env::temp_dir().join(format!("ec-av1-segldapass-{}.fpf", std::process::id())); + let fpf = + std::env::temp_dir().join(format!("ec-av1-segldapass-{}.fpf", std::process::id())); let mut base: Vec = [ "--codec=av1", "--passes=2", @@ -2814,15 +3109,33 @@ pub(crate) mod tests { base.extend(extra.iter().map(|s| (*s).to_owned())); let mut pass1 = base.clone(); pass1.extend(["--pass=1".to_owned(), format!("--fpf={}", fpf.display())]); - pass1.extend(["--obu".to_owned(), "-o".to_owned(), "/dev/null".to_owned(), "-".to_owned()]); + pass1.extend([ + "--obu".to_owned(), + "-o".to_owned(), + "/dev/null".to_owned(), + "-".to_owned(), + ]); let out1 = run_with_stdin(Command::new(aomenc_path()).args(&pass1), &y4m.stdout); - assert!(out1.status.success(), "aomenc pass 1 refused {pass1:?}: {}", String::from_utf8_lossy(&out1.stderr)); + assert!( + out1.status.success(), + "aomenc pass 1 refused {pass1:?}: {}", + String::from_utf8_lossy(&out1.stderr) + ); let mut pass2 = base; pass2.extend(["--pass=2".to_owned(), format!("--fpf={}", fpf.display())]); - pass2.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]); + pass2.extend([ + "--obu".to_owned(), + "-o".to_owned(), + "-".to_owned(), + "-".to_owned(), + ]); let out2 = run_with_stdin(Command::new(aomenc_path()).args(&pass2), &y4m.stdout); let _ = std::fs::remove_file(&fpf); - assert!(out2.status.success(), "aomenc pass 2 refused {pass2:?}: {}", String::from_utf8_lossy(&out2.stderr)); + assert!( + out2.status.success(), + "aomenc pass 2 refused {pass2:?}: {}", + String::from_utf8_lossy(&out2.stderr) + ); out2.stdout } @@ -2921,15 +3234,36 @@ pub(crate) mod tests { let arms: [(&str, &[&str]); 3] = [ ( "testsrc2=size=256x192:rate=25", - &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=3", "--sb-size=64"], + &[ + "--end-usage=q", + "--cq-level=0", + "--aq-mode=1", + "--good", + "--cpu-used=3", + "--sb-size=64", + ], ), ( "testsrc2=size=256x192:rate=25", - &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=5", "--sb-size=64"], + &[ + "--end-usage=q", + "--cq-level=0", + "--aq-mode=1", + "--good", + "--cpu-used=5", + "--sb-size=64", + ], ), ( "gradients=size=256x192:rate=25", - &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=6", "--sb-size=64"], + &[ + "--end-usage=q", + "--cq-level=0", + "--aq-mode=1", + "--good", + "--cpu-used=6", + "--sb-size=64", + ], ), ]; let mut mixed_arms = 0usize; @@ -2939,8 +3273,21 @@ pub(crate) mod tests { for (src, extra) in &arms { let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", *src, "-t", "0.16", "-pix_fmt", - "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + *src, + "-t", + "0.16", + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -2949,14 +3296,21 @@ pub(crate) mod tests { .expect("ffmpeg failed to run"); assert!(y4m.status.success(), "{NAME}: ffmpeg failed for {src}"); let limit = format!("--limit={FRAMES}"); - let mut args: Vec = ["--codec=av1", "--passes=1", "--threads=1", "--obu", "-o", "-", "-"] - .iter() - .map(|s| (*s).to_owned()) - .collect(); + let mut args: Vec = [ + "--codec=av1", + "--passes=1", + "--threads=1", + "--obu", + "-o", + "-", + "-", + ] + .iter() + .map(|s| (*s).to_owned()) + .collect(); args.insert(1, limit); args.extend(extra.iter().map(|s| (*s).to_owned())); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused {args:?}: {}", @@ -2986,8 +3340,9 @@ pub(crate) mod tests { // WHT-unit delta proves the per-segment lossless reconstruction // really ran inside a frame that is NOT `CodedLossless`. let before = crate::decode::lossless_wht_units(); - let ours = decode_stream(&stream) - .unwrap_or_else(|e| panic!("{NAME}: a mixed-lossless frame decodes after the per-segment lift: {e}")); + let ours = decode_stream(&stream).unwrap_or_else(|e| { + panic!("{NAME}: a mixed-lossless frame decodes after the per-segment lift: {e}") + }); let wht_units = crate::decode::lossless_wht_units() - before; let refs = ffmpeg_decode_sequence(&stream, WIDTH, HEIGHT, FRAMES); assert_eq!(ours.len(), FRAMES, "{NAME}: frame count"); @@ -2997,10 +3352,16 @@ pub(crate) mod tests { .enumerate() { let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); - assert_eq!(bad, 0, "{NAME}: arm {extra:?} frame {i} plane {plane}: {bad} samples differ"); + assert_eq!( + bad, 0, + "{NAME}: arm {extra:?} frame {i} plane {plane}: {bad} samples differ" + ); } } - assert!(wht_units > 0, "{NAME}: arm {extra:?} reconstructed no Walsh-Hadamard unit -- the mixed census is lying or the lossless path never ran"); + assert!( + wht_units > 0, + "{NAME}: arm {extra:?} reconstructed no Walsh-Hadamard unit -- the mixed census is lying or the lossless path never ran" + ); mixed_arms += 1; eprintln!( "{NAME}: arm {extra:?}: {mixed} mixed frame(s), {FRAMES} frames sample-exact vs ffmpeg, {wht_units} WHT units" @@ -3035,15 +3396,29 @@ pub(crate) mod tests { eprintln!("SKIP a_segmentation_census_over_real_aq_streams: no aomenc"); return; } - const REFUSAL: &str = - "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV"; + const REFUSAL: &str = "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV"; let recipes: [(&str, Vec<&str>); 6] = [ ("baseline", vec!["--cpu-used=4", "--cq-level=40"]), - ("aq-mode=1", vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=40"]), - ("aq-mode=2", vec!["--cpu-used=4", "--aq-mode=2", "--cq-level=40"]), - ("aq-mode=3", vec!["--cpu-used=4", "--aq-mode=3", "--cq-level=40"]), - ("aq-mode=3 cq10", vec!["--cpu-used=4", "--aq-mode=3", "--cq-level=10"]), - ("deltaq-mode=1", vec!["--cpu-used=4", "--deltaq-mode=1", "--cq-level=40"]), + ( + "aq-mode=1", + vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=40"], + ), + ( + "aq-mode=2", + vec!["--cpu-used=4", "--aq-mode=2", "--cq-level=40"], + ), + ( + "aq-mode=3", + vec!["--cpu-used=4", "--aq-mode=3", "--cq-level=40"], + ), + ( + "aq-mode=3 cq10", + vec!["--cpu-used=4", "--aq-mode=3", "--cq-level=10"], + ), + ( + "deltaq-mode=1", + vec!["--cpu-used=4", "--deltaq-mode=1", "--cq-level=40"], + ), ]; // Arrival, not intent (class knob-never-reached-the-tool): a recipe // whose stream is byte-for-byte the baseline's changed nothing, and a @@ -3090,7 +3465,11 @@ pub(crate) mod tests { "SEGCENSUS: {} recipes, {decoded} decoded, {refused} refused for other reasons", recipes.len() ); - assert_eq!(decoded, recipes.len(), "every recipe must decode; {refused} refused"); + assert_eq!( + decoded, + recipes.len(), + "every recipe must decode; {refused} refused" + ); assert!( segment_symbols > 0, "no recipe coded a single segment_id symbol -- segmentation never arrived, so \ @@ -3116,21 +3495,39 @@ pub(crate) mod tests { "mandelbrot", 192, 128, - vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=45", "--lag-in-frames=16", "--auto-alt-ref=1"], + vec![ + "--cpu-used=4", + "--aq-mode=1", + "--cq-level=45", + "--lag-in-frames=16", + "--auto-alt-ref=1", + ], ), ( "aq-mode=1 lag16 screen", "testsrc2", 256, 192, - vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=45", "--lag-in-frames=16", "--auto-alt-ref=1"], + vec![ + "--cpu-used=4", + "--aq-mode=1", + "--cq-level=45", + "--lag-in-frames=16", + "--auto-alt-ref=1", + ], ), ( "aq-mode=1 lag16 cq63 high_q", "mandelbrot", 192, 128, - vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=63", "--lag-in-frames=16", "--auto-alt-ref=1"], + vec![ + "--cpu-used=4", + "--aq-mode=1", + "--cq-level=63", + "--lag-in-frames=16", + "--auto-alt-ref=1", + ], ), // `--aq-mode=2 lag16` (complexity AQ over an alt-ref group) was // measured 2026-09-24: it encodes and decodes cleanly but codes @@ -3167,7 +3564,13 @@ pub(crate) mod tests { 192, 128, 40, - &["--cpu-used=4", "--aq-mode=1", "--cq-level=45", "--lag-in-frames=16", "--auto-alt-ref=1"], + &[ + "--cpu-used=4", + "--aq-mode=1", + "--cq-level=45", + "--lag-in-frames=16", + "--auto-alt-ref=1", + ], ); let (enabled, umap, inherited, alt_q, frames_per_feature) = segmentation_feature_census(&stream); @@ -3239,7 +3642,8 @@ pub(crate) mod tests { /// `SEG_LVL_ALT_Q`, and an inheritance-heavy shape). #[test] fn a_real_aomenc_segmentation_stream_with_map_inheritance_decodes_pixel_exact() { - const NAME: &str = "a_real_aomenc_segmentation_stream_with_map_inheritance_decodes_pixel_exact"; + const NAME: &str = + "a_real_aomenc_segmentation_stream_with_map_inheritance_decodes_pixel_exact"; if !have_aomenc() { eprintln!("SKIP {NAME}: no aomenc"); return; @@ -3350,8 +3754,18 @@ pub(crate) mod tests { "--enable-intrabc=0", ]; let recipes: [(&str, usize, usize, Vec<&str>); 2] = [ - ("obmc dual cq40", 192, 128, [vec!["--cq-level=40"], base.clone()].concat()), - ("obmc dual cq20", 192, 128, [vec!["--cq-level=20"], base.clone()].concat()), + ( + "obmc dual cq40", + 192, + 128, + [vec!["--cq-level=40"], base.clone()].concat(), + ), + ( + "obmc dual cq20", + 192, + 128, + [vec!["--cq-level=20"], base.clone()].concat(), + ), ]; let mut reads = 0usize; let mut decoded = 0usize; @@ -3372,7 +3786,9 @@ pub(crate) mod tests { } Err(e) => { assert!( - !e.contains("an OBMC neighbour whose switchable interp filter was never recorded"), + !e.contains( + "an OBMC neighbour whose switchable interp filter was never recorded" + ), "{name}: a real OBMC stream reached the unrecorded-filter refusal -- \ a publication site is missing: {e}" ); @@ -3380,7 +3796,10 @@ pub(crate) mod tests { } } } - assert!(decoded > 0, "no OBMC recipe decoded -- the witness is vacuous"); + assert!( + decoded > 0, + "no OBMC recipe decoded -- the witness is vacuous" + ); assert!( reads > 0, "every OBMC blend took the fixed-filter path: the band was never read, so this \ @@ -3417,12 +3836,62 @@ pub(crate) mod tests { "--enable-intrabc=0", ]; let recipes: [(&str, usize, usize, Vec<&str>); 6] = [ - ("denom12 320x180 cq32", 320, 180, vec!["--cpu-used=4", "--superres-mode=1", "--superres-denominator=12", "--cq-level=32"]), - ("denom12 320x180 cq50", 320, 180, vec!["--cpu-used=4", "--superres-mode=1", "--superres-denominator=12", "--cq-level=50"]), - ("denom16 320x180 cq32", 320, 180, vec!["--cpu-used=4", "--superres-mode=1", "--superres-denominator=16", "--cq-level=32"]), - ("denom10 192x128 cq32", 192, 128, vec!["--cpu-used=4", "--superres-mode=1", "--superres-denominator=10", "--cq-level=32"]), - ("auto 320x180 cq50", 320, 180, vec!["--cpu-used=4", "--superres-mode=3", "--cq-level=50"]), - ("auto 192x128 cq50", 192, 128, vec!["--cpu-used=4", "--superres-mode=3", "--cq-level=50"]), + ( + "denom12 320x180 cq32", + 320, + 180, + vec![ + "--cpu-used=4", + "--superres-mode=1", + "--superres-denominator=12", + "--cq-level=32", + ], + ), + ( + "denom12 320x180 cq50", + 320, + 180, + vec![ + "--cpu-used=4", + "--superres-mode=1", + "--superres-denominator=12", + "--cq-level=50", + ], + ), + ( + "denom16 320x180 cq32", + 320, + 180, + vec![ + "--cpu-used=4", + "--superres-mode=1", + "--superres-denominator=16", + "--cq-level=32", + ], + ), + ( + "denom10 192x128 cq32", + 192, + 128, + vec![ + "--cpu-used=4", + "--superres-mode=1", + "--superres-denominator=10", + "--cq-level=32", + ], + ), + ( + "auto 320x180 cq50", + 320, + 180, + vec!["--cpu-used=4", "--superres-mode=3", "--cq-level=50"], + ), + ( + "auto 192x128 cq50", + 192, + 128, + vec!["--cpu-used=4", "--superres-mode=3", "--cq-level=50"], + ), ]; let (mut decoded, mut warp, mut sub8, mut leaf8) = (0, 0, 0, 0); // lane-t900 r36 (class [[gate-blind-to-feature]]): unknown refusal @@ -3475,7 +3944,10 @@ pub(crate) mod tests { // front of them: whichever partition path a scaled frame takes, the // leaf guard is reached first. Lifting the leaf gap is what makes the // other two measurable, so this gate pins the ORDER, not just a count. - assert!(decoded > 0, "no superres recipe decoded -- the census is vacuous"); + assert!( + decoded > 0, + "no superres recipe decoded -- the census is vacuous" + ); // lane-t900 r28: all three scaled refusals are LIFTED, so the census // now pins the opposite shape -- every fixed-denominator recipe must // DECODE, and none of the three strings may come back. @@ -3484,7 +3956,10 @@ pub(crate) mod tests { (0, 0, 0), "a scaled-reference refusal came back (warp {warp}, sub8 {sub8}, leaf8 {leaf8})" ); - assert!(decoded > 0, "no superres recipe decoded -- the census is vacuous"); + assert!( + decoded > 0, + "no superres recipe decoded -- the census is vacuous" + ); } /// lane-t900 r25, negative gate: a `show_existing_frame` header naming a @@ -3536,7 +4011,10 @@ pub(crate) mod tests { err.contains(REFUSAL), "slot {slot}: expected {REFUSAL:?}, got: {err}" ); - assert_eq!(shown, 0, "slot {slot}: an empty slot was output as a picture"); + assert_eq!( + shown, 0, + "slot {slot}: an empty slot was output as a picture" + ); } } @@ -3554,7 +4032,7 @@ pub(crate) mod tests { /// tile is decoded. #[test] fn an_inter_frame_opening_a_stream_is_refused_by_name() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); const REFUSAL: &str = "an inter frame with no key frame before it"; let picture = test_card(64, 64); let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); @@ -3581,7 +4059,10 @@ pub(crate) mod tests { .unwrap_err() .to_string(); assert!(err.contains(REFUSAL), "expected {REFUSAL:?}, got: {err}"); - assert_eq!(shown, 0, "an inter frame with no reference produced a picture"); + assert_eq!( + shown, 0, + "an inter frame with no reference produced a picture" + ); } /// lane-t900 r26, negative gate: an inter frame whose own coded size is @@ -3600,7 +4081,7 @@ pub(crate) mod tests { /// fires on the reference's dimensions before a tile symbol is read. #[test] fn an_inter_frame_shorter_than_its_reference_is_refused_by_name() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); const REFUSAL: &str = "a reference picture whose height does not match this frame's own true size"; let picture = test_card(64, 64); @@ -3630,7 +4111,10 @@ pub(crate) mod tests { .unwrap_err() .to_string(); assert!(err.contains(REFUSAL), "expected {REFUSAL:?}, got: {err}"); - assert_eq!(shown, 1, "expected the key frame alone, got {shown} pictures"); + assert_eq!( + shown, 1, + "expected the key frame alone, got {shown} pictures" + ); } /// lane-t900 r26, negative gate: an inter frame naming a @@ -3652,7 +4136,7 @@ pub(crate) mod tests { /// before the reference pictures are looked up. #[test] fn an_inter_frame_naming_an_unrefreshed_primary_ref_slot_is_refused_by_name() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); const REFUSAL: &str = "a frame naming primary_ref_frame at a reference slot with no saved CDF state"; // The invariant above, read off the source: every line that stores a @@ -3708,8 +4192,14 @@ pub(crate) mod tests { }) .unwrap_err() .to_string(); - assert!(err.contains(REFUSAL), "slot {slot}: expected {REFUSAL:?}, got: {err}"); - assert_eq!(shown, 0, "slot {slot}: a frame with no CDF state produced a picture"); + assert!( + err.contains(REFUSAL), + "slot {slot}: expected {REFUSAL:?}, got: {err}" + ); + assert_eq!( + shown, 0, + "slot {slot}: a frame with no CDF state produced a picture" + ); } } @@ -3756,7 +4246,9 @@ pub(crate) mod tests { continue; }; let mut parser = Av1Parser::new(); - parser.parse_obu(&crate::sequence::sequence_header_obu(&seq).unwrap()).unwrap(); + parser + .parse_obu(&crate::sequence::sequence_header_obu(&seq).unwrap()) + .unwrap(); let obu = parser.parse_obu(&stream).unwrap(); let ObuKind::Frame(parsed, _) = &obu.kind else { panic!("{w}x{h}: the written frame OBU did not parse as one"); @@ -3804,11 +4296,28 @@ pub(crate) mod tests { ) -> ([usize; 6], usize, usize) { let duration = format!("{}", frames as f64 / 25.0); let source = format!("mandelbrot=size={width}x{height}:rate=25"); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration, "-pix_fmt", - pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration, + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -3824,34 +4333,58 @@ pub(crate) mod tests { let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let cq_arg = format!("--cq-level={cq}"); let limit_arg = format!("--limit={frames}"); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, // cpu-used >= 1 keeps libaom on 64x64 superblocks at these // sizes (`av1_select_sb_size`). - "--cpu-used=4", "--threads=1", "--row-mt=0", "--kf-max-dist=9999", + "--cpu-used=4", + "--threads=1", + "--row-mt=0", + "--kf-max-dist=9999", &limit_arg, // decode order == display order, so the compare below covers // every frame the stream carries (class gate-blind-to-hidden-frames). - "--lag-in-frames=0", &depth_arg, &input_depth_arg, + "--lag-in-frames=0", + &depth_arg, + &input_depth_arg, // Rect partitions stay ON: the frame-edge strip is a FORCED // (gathered) HORZ/VERT, but with rect coding off the encoder // answers that gathered symbol SPLIT every time and no edge // strip ever fires (lane-oddh r2's finding, re-measured r1). - "--enable-rect-partitions=1", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--min-partition-size=8", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=8", "--max-partition-size=64", // Other lanes' open gaps this recipe must not trip. - "--enable-palette=0", "--enable-intrabc=0", "--enable-warped-motion=0", - "--enable-obmc=0", "--enable-masked-comp=0", "--enable-interintra-comp=0", - "--enable-onesided-comp=0", "--enable-interintra-wedge=0", - "--enable-smooth-interintra=0", "--enable-ref-frame-mvs=0", - "--enable-angle-delta=0", "--enable-cfl-intra=0", - "--enable-directional-intra=0", "--enable-smooth-intra=0", - "--enable-paeth-intra=0", "--enable-filter-intra=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-warped-motion=0", + "--enable-obmc=0", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-onesided-comp=0", + "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", + "--enable-ref-frame-mvs=0", + "--enable-angle-delta=0", + "--enable-cfl-intra=0", + "--enable-directional-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-filter-intra=0", "--enable-tx-size-search=0", - "--obu", "-o", "-", "-", - ]), &y4m.stdout); + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused: {}", @@ -4000,24 +4533,55 @@ pub(crate) mod tests { let (width, height) = (64usize, 72usize); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", - "mandelbrot=size=64x72:rate=25:start_x=-0.6:start_y=-0.4", "-t", "0.04", - "-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + "mandelbrot=size=64x72:rate=25:start_x=-0.6:start_y=-0.4", + "-t", + "0.04", + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() .expect("ffmpeg failed to run"); - assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", - "--cpu-used=0", "--sb-size=128", "--min-partition-size=16", - "--kf-max-dist=0", "--limit=1", - "--threads=1", "--row-mt=0", "--obu", "-o", "-", "-", - ]), &y4m.stdout); - assert!(out.status.success(), "aomenc refused: {}", String::from_utf8_lossy(&out.stderr)); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=32", + "--cpu-used=0", + "--sb-size=128", + "--min-partition-size=16", + "--kf-max-dist=0", + "--limit=1", + "--threads=1", + "--row-mt=0", + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); + assert!( + out.status.success(), + "aomenc refused: {}", + String::from_utf8_lossy(&out.stderr) + ); let stream = out.stdout; // The knob actually arrived: this stream's sequence header codes @@ -4035,19 +4599,19 @@ pub(crate) mod tests { break; } } - assert!(sb128, "aomenc ignored --sb-size=128: this stream is 64x64-superblock"); + assert!( + sb128, + "aomenc ignored --sb-size=128: this stream is 64x64-superblock" + ); let _guard = lock_gate_counters(); - let before = crate::decode::part128_symbols() - + crate::decode::part128_gathered_symbols(); - let (frames, hidden) = - decode_all_frames_vs_oracle(&stream, "sb128-oddh-64x72"); + let before = crate::decode::part128_symbols() + crate::decode::part128_gathered_symbols(); + let (frames, hidden) = decode_all_frames_vs_oracle(&stream, "sb128-oddh-64x72"); assert!(frames > 0, "no frames decoded for {width}x{height}"); // The 128 root actually READ a partition symbol here: at mi_rows=18 // `has_rows` is true, so BLOCK_128X128 is not a forced split. - let part128 = crate::decode::part128_symbols() - + crate::decode::part128_gathered_symbols() - - before; + let part128 = + crate::decode::part128_symbols() + crate::decode::part128_gathered_symbols() - before; assert!( part128 > 0, "{width}x{height} decoded without reading a single BLOCK_128X128 \ @@ -4099,7 +4663,8 @@ pub(crate) mod tests { encoded.screen, // ... and its own `allow_intrabc` (stale-header class). encoded.allow_intrabc, - &encoded.loop_restoration, fctx, + &encoded.loop_restoration, + fctx, ) .unwrap(); let via_stream = decode_stream(&encoded.stream).unwrap(); @@ -4142,7 +4707,7 @@ pub(crate) mod tests { #[test] fn decode_stream_round_trips_a_gop() { - let fctx = &crate::decode::FrameCtx::for_encoder(); + let fctx = &crate::decode::FrameCtx::for_encoder(); gop_round_trips(128, 64, fctx); } @@ -4150,7 +4715,7 @@ pub(crate) mod tests { /// the inter frame's 16x16-leaf split path is exercised too. #[test] fn decode_stream_round_trips_an_odd_size_gop() { - let fctx = &crate::decode::FrameCtx::for_encoder(); + let fctx = &crate::decode::FrameCtx::for_encoder(); gop_round_trips(216, 96, fctx); } @@ -4162,9 +4727,11 @@ pub(crate) mod tests { /// decode indices non-decreasing, and an `Err` from the sink aborting. #[test] fn streaming_decode_matches_the_collecting_one() { - let fctx = &crate::decode::FrameCtx::for_encoder(); + let fctx = &crate::decode::FrameCtx::for_encoder(); let pictures: Vec<_> = (0..4).map(|i| panned_test_card(128, 64, i * 3)).collect(); - let stream = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap().stream; + let stream = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx) + .unwrap() + .stream; let collected = decode_stream(&stream).unwrap(); let mut shown = Vec::new(); @@ -4179,8 +4746,15 @@ pub(crate) mod tests { Ok(()) }) .unwrap(); - assert_eq!(shown.len(), collected.len(), "callback count vs shown frames"); - assert!(live >= shown.len(), "every shown picture is also a callback"); + assert_eq!( + shown.len(), + collected.len(), + "callback count vs shown frames" + ); + assert!( + live >= shown.len(), + "every shown picture is also a callback" + ); assert!( idxs.windows(2).all(|w| w[0] <= w[1]), "decode indices out of order: {idxs:?}" @@ -4301,9 +4875,18 @@ pub(crate) mod tests { Pic { width, height, - y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), - u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), - v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), + y: out.stdout[base..base + luma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + u: out.stdout[base + luma..base + luma + chroma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + v: out.stdout[base + luma + chroma..base + frame_bytes] + .iter() + .map(|&v| u16::from(v)) + .collect(), } }) .collect() @@ -4352,8 +4935,17 @@ pub(crate) mod tests { ) -> Vec { let out = run_with_stdin( Command::new("ffmpeg").args([ - "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", - "yuv420p10le", "-", + "-v", + "error", + "-f", + "obu", + "-i", + "-", + "-f", + "rawvideo", + "-pix_fmt", + "yuv420p10le", + "-", ]), stream, ); @@ -4419,10 +5011,27 @@ pub(crate) mod tests { let (width, height) = (384usize, 152usize); let out = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", + "-v", + "error", + "-f", + "lavfi", + "-i", "smptebars=s=384x152:r=12,drawgrid=w=8:h=8:t=1:c=black", - "-frames:v", "4", "-c:v", "libsvtav1", "-preset", "8", "-crf", "30", - "-svtav1-params", "lp=1:screen-content-mode=1", "-g", "12", "-f", "obu", "-", + "-frames:v", + "4", + "-c:v", + "libsvtav1", + "-preset", + "8", + "-crf", + "30", + "-svtav1-params", + "lp=1:screen-content-mode=1", + "-g", + "12", + "-f", + "obu", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -4511,7 +5120,7 @@ pub(crate) mod tests { /// independent decoder, not just this crate checking its own tile path. #[test] fn decode_stream_agrees_with_ffmpeg_on_a_gop() { - let fctx = &crate::decode::FrameCtx::for_encoder(); + let fctx = &crate::decode::FrameCtx::for_encoder(); if !have_ffmpeg() { eprintln!("SKIP decode_stream_agrees_with_ffmpeg_on_a_gop: no ffmpeg"); return; @@ -4539,9 +5148,18 @@ pub(crate) mod tests { // decoder-side one. for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() { let rec = &frame.reconstruction; - assert_eq!(rec.y, want.y, "{width}x{height} frame {i} luma: reconstruction vs ffmpeg"); - assert_eq!(rec.u, want.u, "{width}x{height} frame {i} U: reconstruction vs ffmpeg"); - assert_eq!(rec.v, want.v, "{width}x{height} frame {i} V: reconstruction vs ffmpeg"); + assert_eq!( + rec.y, want.y, + "{width}x{height} frame {i} luma: reconstruction vs ffmpeg" + ); + assert_eq!( + rec.u, want.u, + "{width}x{height} frame {i} U: reconstruction vs ffmpeg" + ); + assert_eq!( + rec.v, want.v, + "{width}x{height} frame {i} V: reconstruction vs ffmpeg" + ); } } } @@ -4567,7 +5185,9 @@ pub(crate) mod tests { fn a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg() { let fctx = &crate::decode::FrameCtx::for_encoder(); if !have_ffmpeg() { - eprintln!("SKIP a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg: no ffmpeg"); + eprintln!( + "SKIP a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg: no ffmpeg" + ); return; } const FRAMES: usize = 4; @@ -4600,9 +5220,18 @@ pub(crate) mod tests { } for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() { let rec = &frame.reconstruction; - assert_eq!(rec.y, want.y, "{width}x{height} frame {i} luma: recon vs ffmpeg"); - assert_eq!(rec.u, want.u, "{width}x{height} frame {i} U: recon vs ffmpeg"); - assert_eq!(rec.v, want.v, "{width}x{height} frame {i} V: recon vs ffmpeg"); + assert_eq!( + rec.y, want.y, + "{width}x{height} frame {i} luma: recon vs ffmpeg" + ); + assert_eq!( + rec.u, want.u, + "{width}x{height} frame {i} U: recon vs ffmpeg" + ); + assert_eq!( + rec.v, want.v, + "{width}x{height} frame {i} V: recon vs ffmpeg" + ); } } } @@ -4660,18 +5289,40 @@ pub(crate) mod tests { let decoded = decode_stream(&encoded.stream) .unwrap_or_else(|e| panic!("{width}x{height}: our decoder refused: {e}")); let ffmpeg_frames = ffmpeg_decode_sequence(&encoded.stream, width, height, FRAMES); - assert_eq!(ffmpeg_frames.len(), FRAMES, "{width}x{height}: ffmpeg frame count"); + assert_eq!( + ffmpeg_frames.len(), + FRAMES, + "{width}x{height}: ffmpeg frame count" + ); assert_eq!(decoded.len(), FRAMES, "{width}x{height}: frame count"); for (i, (got, want)) in decoded.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{width}x{height} frame {i} luma: ours vs ffmpeg"); - assert_eq!(got.u, want.u, "{width}x{height} frame {i} U: ours vs ffmpeg"); - assert_eq!(got.v, want.v, "{width}x{height} frame {i} V: ours vs ffmpeg"); + assert_eq!( + got.y, want.y, + "{width}x{height} frame {i} luma: ours vs ffmpeg" + ); + assert_eq!( + got.u, want.u, + "{width}x{height} frame {i} U: ours vs ffmpeg" + ); + assert_eq!( + got.v, want.v, + "{width}x{height} frame {i} V: ours vs ffmpeg" + ); } for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() { let rec = &frame.reconstruction; - assert_eq!(rec.y, want.y, "{width}x{height} frame {i} luma: recon vs ffmpeg"); - assert_eq!(rec.u, want.u, "{width}x{height} frame {i} U: recon vs ffmpeg"); - assert_eq!(rec.v, want.v, "{width}x{height} frame {i} V: recon vs ffmpeg"); + assert_eq!( + rec.y, want.y, + "{width}x{height} frame {i} luma: recon vs ffmpeg" + ); + assert_eq!( + rec.u, want.u, + "{width}x{height} frame {i} U: recon vs ffmpeg" + ); + assert_eq!( + rec.v, want.v, + "{width}x{height} frame {i} V: recon vs ffmpeg" + ); } } } @@ -4704,7 +5355,7 @@ pub(crate) mod tests { /// with itself would prove nothing. #[test] fn a_hand_built_golden_reference_decodes_pixel_exact_against_ffmpeg() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); if !have_ffmpeg() { eprintln!( "SKIP a_hand_built_golden_reference_decodes_pixel_exact_against_ffmpeg: no ffmpeg" @@ -4855,7 +5506,9 @@ pub(crate) mod tests { hash_color(seed, 2), hash_color(seed, 3), ); - format!("gradients=size={width}x{height}:c0={c0}:c1={c1}:c2={c2}:c3={c3}:seed={seed}:{tail}") + format!( + "gradients=size={width}x{height}:c0={c0}:c1={c1}:c2={c2}:c3={c3}:seed={seed}:{tail}" + ) } /// The determinism guard: same seed twice must byte-match ffmpeg's own @@ -4870,7 +5523,16 @@ pub(crate) mod tests { fn render_hash(lavfi: &str) -> Vec { let out = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", lavfi, "-frames:v", "1", "-f", "rawvideo", + "-v", + "error", + "-f", + "lavfi", + "-i", + lavfi, + "-frames:v", + "1", + "-f", + "rawvideo", "-", ]) .stdin(Stdio::null()) @@ -5088,7 +5750,17 @@ pub(crate) mod tests { .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) .arg(&src) .args(["-an", "-threads", "1", "-g", "16", "-c:v", "libaom-av1"]) - .args(["-cpu-used", "6", "-b:v", "0", "-crf", "35", "-f", "obu", "-"]) + .args([ + "-cpu-used", + "6", + "-b:v", + "0", + "-crf", + "35", + "-f", + "obu", + "-", + ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -5178,18 +5850,37 @@ pub(crate) mod tests { let load = Command::new("ffmpeg") .args(["-v", "error", "-y", "-i"]) .arg(&clip) - .args(["-frames:v", &frames.to_string(), "-vf", "crop=1920:1024:960:568"]) + .args([ + "-frames:v", + &frames.to_string(), + "-vf", + "crop=1920:1024:960:568", + ]) .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"]) .arg(&src) .output() .expect("ffmpeg failed to run"); - assert!(load.status.success(), "{NAME}: {}", String::from_utf8_lossy(&load.stderr)); + assert!( + load.status.success(), + "{NAME}: {}", + String::from_utf8_lossy(&load.stderr) + ); let out = Command::new("ffmpeg") .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"]) .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) .arg(&src) .args(["-an", "-threads", "1", "-g", "12", "-c:v", "libaom-av1"]) - .args(["-cpu-used", "6", "-b:v", "0", "-crf", "45", "-f", "obu", "-"]) + .args([ + "-cpu-used", + "6", + "-b:v", + "0", + "-crf", + "45", + "-f", + "obu", + "-", + ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -5307,7 +5998,10 @@ pub(crate) mod tests { lossless += 1; } } - assert_eq!(lossless, frames, "{NAME} went blind: libaom coded no lossless key frame at -crf 0"); + assert_eq!( + lossless, frames, + "{NAME} went blind: libaom coded no lossless key frame at -crf 0" + ); let ours = decode_stream(&stream).expect("a lossless key-frame stream decodes"); let refs = ffmpeg_decode_sequence(&stream, w, h, frames); assert_eq!(ours.len(), frames, "{NAME}: frame count"); @@ -5317,7 +6011,10 @@ pub(crate) mod tests { .enumerate() { let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); - assert_eq!(bad, 0, "{NAME}: frame {i} plane {plane}: {bad} samples differ"); + assert_eq!( + bad, 0, + "{NAME}: frame {i} plane {plane}: {bad} samples differ" + ); } } } @@ -5380,7 +6077,11 @@ pub(crate) mod tests { for col in 0..w { let v = if screen { if row % 7 == 0 && col % 3 == 0 { - if (col / 3 + row + f) % 2 == 1 { 16 } else { 235 } + if (col / 3 + row + f) % 2 == 1 { + 16 + } else { + 235 + } } else { PAL[((col + 4 * f) / 16 + row / 16) % PAL.len()] } @@ -5405,10 +6106,16 @@ pub(crate) mod tests { } } } - let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; // [[pid-keyed-temp-path]]: parallel test binaries must not share a name. - let src = std::env::temp_dir() - .join(format!("ec-av1-lossless2-{}-{w}x{h}-{depth}.yuv", std::process::id())); + let src = std::env::temp_dir().join(format!( + "ec-av1-lossless2-{}-{w}x{h}-{depth}.yuv", + std::process::id() + )); std::fs::write(&src, &raw).expect("raw source"); let mut cmd = Command::new("ffmpeg"); cmd.args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", pix]) @@ -5456,7 +6163,10 @@ pub(crate) mod tests { inters += 1; } } - assert!(lossless >= frames, "{NAME} [{tag}] went blind: {lossless} lossless frames"); + assert!( + lossless >= frames, + "{NAME} [{tag}] went blind: {lossless} lossless frames" + ); assert!( screen || inters > 0, "{NAME} [{tag}] went blind: no inter frame at gop {gop}" @@ -5475,7 +6185,10 @@ pub(crate) mod tests { .enumerate() { let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); - assert_eq!(bad, 0, "{NAME} [{tag}]: frame {i} plane {plane}: {bad} samples differ"); + assert_eq!( + bad, 0, + "{NAME} [{tag}]: frame {i} plane {plane}: {bad} samples differ" + ); } } } @@ -5521,7 +6234,10 @@ pub(crate) mod tests { lossless = h.lossless.iter().all(|&l| l); } } - assert!(lossless, "{NAME} went blind: the pinned frame is not lossless"); + assert!( + lossless, + "{NAME} went blind: the pinned frame is not lossless" + ); let before = crate::decode::rect_split_lossless_chroma444_hits(); let ours = decode_stream(&stream).expect("a 444 lossless key-frame stream decodes"); assert_eq!(ours.len(), 1, "{NAME}: frame count"); @@ -5531,7 +6247,9 @@ pub(crate) mod tests { as 4x4 units at subsampling 0/0" ); let refs = Command::new("ffmpeg") - .args(["-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv444p", "-"]) + .args([ + "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv444p", "-", + ]) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -5542,7 +6260,11 @@ pub(crate) mod tests { child.wait_with_output() }) .expect("ffmpeg 444 decode failed"); - assert!(refs.status.success(), "{}", String::from_utf8_lossy(&refs.stderr)); + assert!( + refs.status.success(), + "{}", + String::from_utf8_lossy(&refs.stderr) + ); let frame = &ours[0]; let planes = [ (&frame.y, frame.width * frame.height), @@ -5552,7 +6274,11 @@ pub(crate) mod tests { let mut off = 0usize; for (plane, (g, len)) in planes.iter().enumerate() { let raw = &refs.stdout[off..off + len]; - let bad = g.iter().zip(raw.iter()).filter(|&(&a, &b)| a != u16::from(b)).count(); + let bad = g + .iter() + .zip(raw.iter()) + .filter(|&(&a, &b)| a != u16::from(b)) + .count(); assert_eq!(bad, 0, "{NAME}: plane {plane}: {bad} samples differ"); off += len; } @@ -5592,9 +6318,18 @@ pub(crate) mod tests { Pic { width, height, - y: out.stdout[base..base + plane].iter().map(|&v| u16::from(v)).collect(), - u: out.stdout[base + plane..base + 2 * plane].iter().map(|&v| u16::from(v)).collect(), - v: out.stdout[base + 2 * plane..base + 3 * plane].iter().map(|&v| u16::from(v)).collect(), + y: out.stdout[base..base + plane] + .iter() + .map(|&v| u16::from(v)) + .collect(), + u: out.stdout[base + plane..base + 2 * plane] + .iter() + .map(|&v| u16::from(v)) + .collect(), + v: out.stdout[base + 2 * plane..base + 3 * plane] + .iter() + .map(|&v| u16::from(v)) + .collect(), } }) .collect() @@ -5641,9 +6376,8 @@ pub(crate) mod tests { let _guard = lock_gate_counters(); let before = crate::decode::chroma_split_tx_hits(); - let frames = decode_stream(&stream).unwrap_or_else(|e| { - panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") - }); + let frames = decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); let hits = crate::decode::chroma_split_tx_hits(); assert!( hits > before, @@ -5685,12 +6419,22 @@ pub(crate) mod tests { .zip(["y", "u", "v"]) { let want = &ref_raw[base + off..base + off + W * H]; - let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); - assert_eq!(bad, 0, "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ"); + let bad = plane + .iter() + .zip(want) + .filter(|&(&a, &b)| a as u8 != b) + .count(); + assert_eq!( + bad, 0, + "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ" + ); } } } else { - eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); + eprintln!( + "SKIP {NAME} aomdec arm: no oracle aomdec at {}", + aomdec_path().display() + ); } // ffmpeg's decoder: same frames, full-resolution chroma. @@ -5702,7 +6446,10 @@ pub(crate) mod tests { .enumerate() { let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); - assert_eq!(bad, 0, "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ"); + assert_eq!( + bad, 0, + "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ" + ); } } } else { @@ -5760,9 +6507,8 @@ pub(crate) mod tests { assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); let _guard = lock_gate_counters(); - let frames = decode_stream(&stream).unwrap_or_else(|e| { - panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") - }); + let frames = decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); for f in &frames { assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); @@ -5798,7 +6544,11 @@ pub(crate) mod tests { .zip(["y", "u", "v"]) { let want = &ref_raw[base + off..base + off + W * H]; - let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); + let bad = plane + .iter() + .zip(want) + .filter(|&(&a, &b)| a as u8 != b) + .count(); assert_eq!( bad, 0, "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ @@ -5807,7 +6557,10 @@ pub(crate) mod tests { } } } else { - eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); + eprintln!( + "SKIP {NAME} aomdec arm: no oracle aomdec at {}", + aomdec_path().display() + ); } // ffmpeg's decoder: same frames, full-resolution chroma. @@ -5819,7 +6572,10 @@ pub(crate) mod tests { .enumerate() { let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); - assert_eq!(bad, 0, "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ"); + assert_eq!( + bad, 0, + "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ" + ); } } } else { @@ -5878,9 +6634,8 @@ pub(crate) mod tests { let _guard = lock_gate_counters(); let before = crate::decode::intra_sb128_hits(); let before_replay = crate::decode::sb128rect_chroma_replay_hits(); - let frames = decode_stream(&stream).unwrap_or_else(|e| { - panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") - }); + let frames = decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); let (horz, vert, _) = crate::decode::intra_sb128_hits(); assert!( horz - before.0 + (vert - before.1) > 0, @@ -5937,8 +6692,7 @@ pub(crate) mod tests { // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames. if aomdec_path().is_file() { - let dir = - std::env::temp_dir().join(format!("ec-av1-444sb-{}", std::process::id())); + let dir = std::env::temp_dir().join(format!("ec-av1-444sb-{}", std::process::id())); let _ = std::fs::remove_dir_all(&dir); std::fs::create_dir_all(&dir).expect("scratch dir"); let raw = dir.join("aomdec.raw"); @@ -5961,14 +6715,16 @@ pub(crate) mod tests { assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); for (i, f) in frames.iter().enumerate().take(3) { let base = i * W * H * 3; - for ((plane, off), p) in - [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] - .into_iter() - .zip(["y", "u", "v"]) + for ((plane, off), p) in [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] + .into_iter() + .zip(["y", "u", "v"]) { let want = &ref_raw[base + off..base + off + W * H]; - let bad = - plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); + let bad = plane + .iter() + .zip(want) + .filter(|&(&a, &b)| a as u8 != b) + .count(); assert_eq!( bad, 0, "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ @@ -5977,7 +6733,10 @@ pub(crate) mod tests { } } } else { - eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); + eprintln!( + "SKIP {NAME} aomdec arm: no oracle aomdec at {}", + aomdec_path().display() + ); } // ffmpeg's decoder: same frames, full-resolution chroma. Same @@ -5985,10 +6744,9 @@ pub(crate) mod tests { if have_ffmpeg() { let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate().take(3) { - for (p, (g, r)) in - [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] - .iter() - .enumerate() + for (p, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] + .iter() + .enumerate() { let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); assert_eq!( @@ -6050,8 +6808,8 @@ pub(crate) mod tests { assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); let _guard = lock_gate_counters(); - let serial = decode_stream(&stream) - .unwrap_or_else(|e| panic!("{NAME}: serial decode failed: {e}")); + let serial = + decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME}: serial decode failed: {e}")); assert_eq!(serial.len(), FRAMES, "{NAME}: frame count"); let pipe_before = crate::decode::pipeline_taken_frames(); @@ -6087,8 +6845,9 @@ pub(crate) mod tests { // frame -- including frame 2, the 128-root-rect inter frame the // r2 defect named. for (i, (s, p)) in serial.iter().zip(piped.iter()).enumerate() { - for (pl, (a, b)) in - [(&s.y, &p.y), (&s.u, &p.u), (&s.v, &p.v)].into_iter().enumerate() + for (pl, (a, b)) in [(&s.y, &p.y), (&s.u, &p.u), (&s.v, &p.v)] + .into_iter() + .enumerate() { assert_eq!( a, b, @@ -6123,13 +6882,16 @@ pub(crate) mod tests { assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); for (i, f) in piped.iter().enumerate().take(2) { let base = i * W * H * 3; - for ((plane, off), p) in - [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] - .into_iter() - .zip(["y", "u", "v"]) + for ((plane, off), p) in [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] + .into_iter() + .zip(["y", "u", "v"]) { let want = &ref_raw[base + off..base + off + W * H]; - let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); + let bad = plane + .iter() + .zip(want) + .filter(|&(&a, &b)| a as u8 != b) + .count(); assert_eq!( bad, 0, "{NAME}: aomdec frame {i} plane {p} THROUGH THE PIPELINE: \ @@ -6138,15 +6900,17 @@ pub(crate) mod tests { } } } else { - eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); + eprintln!( + "SKIP {NAME} aomdec arm: no oracle aomdec at {}", + aomdec_path().display() + ); } if have_ffmpeg() { let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); for (i, (got, want)) in piped.iter().zip(refs.iter()).enumerate().take(2) { - for (p, (g, r)) in - [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] - .iter() - .enumerate() + for (p, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] + .iter() + .enumerate() { let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); assert_eq!( @@ -6203,9 +6967,8 @@ pub(crate) mod tests { let _guard = lock_gate_counters(); let strips_before = decode::inter16_rect4_counters(); - let frames = decode_stream(&stream).unwrap_or_else(|e| { - panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") - }); + let frames = decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); let strips_after = decode::inter16_rect4_counters(); assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); for f in &frames { @@ -6256,7 +7019,11 @@ pub(crate) mod tests { .zip(["y", "u", "v"]) { let want = &ref_raw[base + off..base + off + W * H]; - let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); + let bad = plane + .iter() + .zip(want) + .filter(|&(&a, &b)| a as u8 != b) + .count(); assert_eq!( bad, 0, "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ @@ -6265,7 +7032,10 @@ pub(crate) mod tests { } } } else { - eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); + eprintln!( + "SKIP {NAME} aomdec arm: no oracle aomdec at {}", + aomdec_path().display() + ); } } @@ -6335,8 +7105,8 @@ pub(crate) mod tests { const W: usize = 320; const H: usize = 256; const FRAMES: usize = 3; - let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("fixtures/444_leaf8_oob.obu"); + let obu = + std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("fixtures/444_leaf8_oob.obu"); let stream = std::fs::read(&obu).unwrap_or_else(|e| { panic!( "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ @@ -6349,9 +7119,8 @@ pub(crate) mod tests { let _guard = lock_gate_counters(); crate::decode::reset_leaf8_intrabc_hits(); - let frames = decode_stream(&stream).unwrap_or_else(|e| { - panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") - }); + let frames = decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); assert!( crate::decode::leaf8_intrabc_hits() > 0, "{NAME}: gate is vacuous -- no intrabc 8x8 leaf was decoded, so the arm \ @@ -6391,7 +7160,10 @@ pub(crate) mod tests { "{NAME}: aomdec raw fingerprint moved" ); } else { - eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); + eprintln!( + "SKIP {NAME} aomdec arm: no oracle aomdec at {}", + aomdec_path().display() + ); } } /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis @@ -6457,7 +7229,8 @@ pub(crate) mod tests { arm never ran (class gate-blind-to-feature)" ); assert_eq!( - after_replay.1, before_replay.1, + after_replay.1, + before_replay.1, "{NAME}: the tail replay stamped {} unit(s) over a height that was not the \ unit's own luma height (4:2:2 spans leaked into an admitted stream)", after_replay.1 - before_replay.1 @@ -6501,31 +7274,51 @@ pub(crate) mod tests { let out = ff .args(["-v", "error", "-f", "lavfi", "-i"]) .arg(format!("testsrc2=s={width}x{height}:r=25")) - .args(["-frames:v", "1", "-pix_fmt", "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-"]) + .args([ + "-frames:v", + "1", + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", + ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() .expect("ffmpeg failed to run"); - assert!(out.status.success(), "ffmpeg failed for testsrc2 {width}x{height}"); + assert!( + out.status.success(), + "ffmpeg failed for testsrc2 {width}x{height}" + ); let y4m = out.stdout; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(["--codec=av1", "--bit-depth=8", "--input-bit-depth=8"]) - .args([ - "--passes=1", - "--cpu-used=0", - "--lag-in-frames=0", - "--kf-max-dist=1", - "--limit=1", - "--threads=1", - "--tile-columns=0", - "--lossless=1", - "--sb-size=128", - "--enable-1to4-partitions=1", - ]) - .args(extra) - .args(["--obu", "-o", "-", "-"]), &y4m); - assert!(out.status.success(), "aomenc failed: {}", String::from_utf8_lossy(&out.stderr)); + let out = run_with_stdin( + Command::new(aomenc_path()) + .args(["--codec=av1", "--bit-depth=8", "--input-bit-depth=8"]) + .args([ + "--passes=1", + "--cpu-used=0", + "--lag-in-frames=0", + "--kf-max-dist=1", + "--limit=1", + "--threads=1", + "--tile-columns=0", + "--lossless=1", + "--sb-size=128", + "--enable-1to4-partitions=1", + ]) + .args(extra) + .args(["--obu", "-o", "-", "-"]), + &y4m, + ); + assert!( + out.status.success(), + "aomenc failed: {}", + String::from_utf8_lossy(&out.stderr) + ); out.stdout } @@ -6561,14 +7354,18 @@ pub(crate) mod tests { // overhanging 64x64 blocks and both desynced at byte 41120 pre-fix. let arms: [&[&str]; 2] = [ &["--min-partition-size=4"], - &["--min-partition-size=4", "--enable-1to4-partitions=0", "--enable-rect-partitions=0"], + &[ + "--min-partition-size=4", + "--enable-1to4-partitions=0", + "--enable-rect-partitions=0", + ], ]; let mut clips_total = 0usize; for (arm, extra) in arms.iter().enumerate() { let stream = lossless_sb128_testsrc2(320, 240, extra); crate::decode::reset_loss64_hits(); - let ours = decode_stream(&stream) - .unwrap_or_else(|e| panic!("{NAME}: arm {arm} decodes: {e}")); + let ours = + decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME}: arm {arm} decodes: {e}")); let clips = crate::decode::chroma_edge_tu_clip_hits(); assert!( clips > 0, @@ -6578,12 +7375,19 @@ pub(crate) mod tests { clips_total += clips; let refs = ffmpeg_decode_sequence(&stream, 320, 240, 1); assert_eq!(ours.len(), 1, "{NAME}: arm {arm} frame count"); - for (plane, (g, r)) in [(&ours[0].y, &refs[0].y), (&ours[0].u, &refs[0].u), (&ours[0].v, &refs[0].v)] - .iter() - .enumerate() + for (plane, (g, r)) in [ + (&ours[0].y, &refs[0].y), + (&ours[0].u, &refs[0].u), + (&ours[0].v, &refs[0].v), + ] + .iter() + .enumerate() { let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); - assert_eq!(bad, 0, "{NAME}: arm {arm} plane {plane}: {bad} samples differ from ffmpeg"); + assert_eq!( + bad, 0, + "{NAME}: arm {arm} plane {plane}: {bad} samples differ from ffmpeg" + ); } } eprintln!("{NAME}: 2 arms full-frame exact, {clips_total} chroma units clipped"); @@ -6625,8 +7429,7 @@ pub(crate) mod tests { let stream = lossless_sb128_testsrc2(320, 242, &["--min-partition-size=4"]); crate::decode::reset_loss64_hits(); crate::decode::reset_skipped_intrabc_chroma_arm_hits(); - let ours = decode_stream(&stream) - .unwrap_or_else(|e| panic!("{NAME}: decodes: {e}")); + let ours = decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME}: decodes: {e}")); let resets = crate::decode::skip_lossless_band_reset_hits(); let intrabc_skips = crate::decode::skipped_intrabc_chroma_arm_hits(); assert!( @@ -6641,12 +7444,19 @@ pub(crate) mod tests { ); let refs = ffmpeg_decode_sequence(&stream, 320, 242, 1); assert_eq!(ours.len(), 1, "{NAME}: frame count"); - for (plane, (g, r)) in [(&ours[0].y, &refs[0].y), (&ours[0].u, &refs[0].u), (&ours[0].v, &refs[0].v)] - .iter() - .enumerate() + for (plane, (g, r)) in [ + (&ours[0].y, &refs[0].y), + (&ours[0].u, &refs[0].u), + (&ours[0].v, &refs[0].v), + ] + .iter() + .enumerate() { let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); - assert_eq!(bad, 0, "{NAME}: plane {plane}: {bad} samples differ from ffmpeg"); + assert_eq!( + bad, 0, + "{NAME}: plane {plane}: {bad} samples differ from ffmpeg" + ); } eprintln!( "{NAME}: full-frame exact, {resets} band resets, \ @@ -6702,8 +7512,10 @@ pub(crate) mod tests { crate::decode::reset_ibc444rect_hits(); crate::decode::reset_skipped_intrabc_dv_copy_hits(); let frames = decode_stream(&stream).unwrap_or_else(|e| { - panic!("{NAME}: the fixture must decode to completion (the leaf8 \ - chroma buffers were fixed upstream): {e}") + panic!( + "{NAME}: the fixture must decode to completion (the leaf8 \ + chroma buffers were fixed upstream): {e}" + ) }); assert_eq!(frames.len(), 1, "{NAME}: shown frame count"); let luma = crate::decode::intrabc_rect8_lossless_luma_hits(); @@ -6749,11 +7561,17 @@ pub(crate) mod tests { let _ = std::fs::remove_dir_all(&dir); assert_eq!(ref_raw.len(), W * H * 3, "{NAME}: aomdec raw size"); let f = &frames[0]; - for (plane, off, p) in - [(&f.y, 0usize, "Y"), (&f.u, W * H, "U"), (&f.v, 2 * W * H, "V")] - { + for (plane, off, p) in [ + (&f.y, 0usize, "Y"), + (&f.u, W * H, "U"), + (&f.v, 2 * W * H, "V"), + ] { let want = &ref_raw[off..off + W * H]; - let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); + let bad = plane + .iter() + .zip(want) + .filter(|&(&a, &b)| a as u8 != b) + .count(); assert_eq!( bad, 0, "{NAME}: aomdec plane {p}: {bad} samples differ -- a \ @@ -6762,7 +7580,10 @@ pub(crate) mod tests { ); } } else { - eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); + eprintln!( + "SKIP {NAME} aomdec arm: no oracle aomdec at {}", + aomdec_path().display() + ); } eprintln!( "{NAME}: frame sample-exact vs oracle aomdec; {luma}+{chroma} rect \ @@ -6835,7 +7656,17 @@ pub(crate) mod tests { .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) .arg(&src) .args(["-an", "-threads", "1", "-g", "12", "-c:v", "libaom-av1"]) - .args(["-cpu-used", "6", "-b:v", "0", "-crf", "35", "-f", "obu", "-"]) + .args([ + "-cpu-used", + "6", + "-b:v", + "0", + "-crf", + "35", + "-f", + "obu", + "-", + ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -7188,8 +8019,7 @@ pub(crate) mod tests { } let mut arm: Vec<&str> = vec!["--arnr-maxframes=0"]; arm.extend_from_slice(args); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&arm), &y4m); + let out = run_with_stdin(Command::new(aomenc_path()).args(&arm), &y4m); assert!( out.status.success(), "{name} HIDDEN-ARM: aomenc refused its own recipe plus --arnr-maxframes=0: {}", @@ -7206,11 +8036,13 @@ pub(crate) mod tests { eprintln!("{name} HIDDEN-ARM: skipped on a named refusal: {msg}"); None } - Ok(_) => Some(decode_all_frames_vs_oracle(&stream, &format!("{name}-arnr0"))), + Ok(_) => Some(decode_all_frames_vs_oracle( + &stream, + &format!("{name}-arnr0"), + )), } } - /// The repo's first hidden-frame pixel gate. Every other aomenc gate /// here compares `decode_stream`'s output against `ffmpeg -f obu`, and /// both sides emit SHOWN frames only -- so an alt-ref frame that is @@ -7242,11 +8074,28 @@ pub(crate) mod tests { let (width, height, frames) = (64usize, 64usize, 40usize); let duration = frames as f64 / 25.0; let source = format!("testsrc2=size={width}x{height}:duration={duration}:rate=25"); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -7260,8 +8109,8 @@ pub(crate) mod tests { ); let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ // lane-defon r1: the repo's only gate that decodes hidden // frames is also the only place a FORWARD KEYFRAME can be // proven -- a KEY frame with `show_frame == 0`, which is @@ -7320,7 +8169,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "{NAME}: aomenc refused the {bit_depth}-bit fixture: {}", @@ -7415,8 +8266,8 @@ pub(crate) mod tests { "ffmpeg refused to generate the y4m fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -7445,7 +8296,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -7557,8 +8410,8 @@ pub(crate) mod tests { "smptebars must render byte-identical across two runs" ); let y4m = y4m_a; - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -7589,7 +8442,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m); + ]), + &y4m, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -7650,18 +8505,30 @@ pub(crate) mod tests { } let (width, height) = (64usize, 64usize); for depth in [8usize, 10] { - let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let render = || { Command::new("ffmpeg") .args([ - "-v", "error", - "-f", "lavfi", - "-i", "smptebars=size=64x64:rate=25", - "-vf", "hue=s=0", - "-pix_fmt", pix_fmt, - "-strict", "-1", - "-t", "0.04", - "-f", "yuv4mpegpipe", + "-v", + "error", + "-f", + "lavfi", + "-i", + "smptebars=size=64x64:rate=25", + "-vf", + "hue=s=0", + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-t", + "0.04", + "-f", + "yuv4mpegpipe", "-", ]) .stdin(Stdio::null()) @@ -7680,40 +8547,43 @@ pub(crate) mod tests { let y4m = y4m_a; let depth_arg = format!("--bit-depth={depth}"); let input_depth_arg = format!("--input-bit-depth={depth}"); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", - "--passes=1", - "--end-usage=q", - "--cq-level=30", - "--cpu-used=0", - "--threads=1", - "--row-mt=0", - "--sb-size=64", - "--tune-content=screen", - "--enable-palette=1", - "--enable-intrabc=0", - "--enable-rect-partitions=0", - "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", - "--min-partition-size=32", - "--max-partition-size=32", - "--enable-filter-intra=0", - "--enable-smooth-intra=0", - "--enable-paeth-intra=0", - "--enable-directional-intra=0", - "--enable-angle-delta=0", - "--enable-cfl-intra=0", - "--enable-cdef=0", - "--enable-restoration=0", - "--enable-tx-size-search=0", - "--loopfilter-control=0", - "--limit=1", - ]) - // Per-arm overrides go AFTER the base recipe: aomenc keeps the - // LAST occurrence of a repeated flag. - .args([&depth_arg, &input_depth_arg]) - .args(["--obu", "-o", "-", "-"]), &y4m); + let out = run_with_stdin( + Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=30", + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--tune-content=screen", + "--enable-palette=1", + "--enable-intrabc=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=32", + "--max-partition-size=32", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-cfl-intra=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--enable-tx-size-search=0", + "--loopfilter-control=0", + "--limit=1", + ]) + // Per-arm overrides go AFTER the base recipe: aomenc keeps the + // LAST occurrence of a repeated flag. + .args([&depth_arg, &input_depth_arg]) + .args(["--obu", "-o", "-", "-"]), + &y4m, + ); assert!( out.status.success(), "{NAME}: aomenc refused the {depth}-bit fixture: {}", @@ -7734,7 +8604,10 @@ pub(crate) mod tests { } else { ffmpeg_decode_sequence(&stream, width, height, 1) }; - assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma at {depth}-bit"); + assert_eq!( + frames[0].y, ffmpeg_frames[0].y, + "{NAME}: luma at {depth}-bit" + ); assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U at {depth}-bit"); assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V at {depth}-bit"); } @@ -7785,14 +8658,30 @@ pub(crate) mod tests { for txs in [0usize, 1] { for tiles in [0usize, 1] { let arm = format!("{src}-{depth}bit-cq{cq}-txs{txs}-tc{tiles}"); - let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let size = format!("{src}=size={width}x{height}:rate=25"); let render = || { let out = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &size, "-t", "0.04", - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &size, + "-t", + "0.04", + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -7814,29 +8703,38 @@ pub(crate) mod tests { let cq_arg = format!("--cq-level={cq}"); let txs_arg = format!("--enable-tx-size-search={txs}"); let tiles_arg = format!("--tile-columns={tiles}"); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", - "--passes=1", - "--end-usage=q", - "--cpu-used=0", - "--threads=1", - "--row-mt=0", - "--lag-in-frames=0", - "--limit=1", - "--sb-size=64", - "--tune-content=screen", - "--enable-palette=1", - "--enable-intrabc=0", - "--min-partition-size=8", - "--enable-cdef=0", - "--enable-restoration=0", - "--loopfilter-control=0", - ]) - // aomenc keeps the LAST occurrence of a repeated flag, - // so per-arm overrides go after the base recipe. - .args([&depth_arg, &input_depth_arg, &cq_arg, &txs_arg, &tiles_arg]) - .args(["--obu", "-o", "-", "-"]), &y4m); + let out = run_with_stdin( + Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--lag-in-frames=0", + "--limit=1", + "--sb-size=64", + "--tune-content=screen", + "--enable-palette=1", + "--enable-intrabc=0", + "--min-partition-size=8", + "--enable-cdef=0", + "--enable-restoration=0", + "--loopfilter-control=0", + ]) + // aomenc keeps the LAST occurrence of a repeated flag, + // so per-arm overrides go after the base recipe. + .args([ + &depth_arg, + &input_depth_arg, + &cq_arg, + &txs_arg, + &tiles_arg, + ]) + .args(["--obu", "-o", "-", "-"]), + &y4m, + ); assert!( out.status.success(), "{NAME}: aomenc refused {arm}: {}", @@ -7954,7 +8852,10 @@ pub(crate) mod tests { out_of_scope_mismatch, 0, "{NAME}: an out-of-scope arm mismatched ffmpeg -- a defect, never a skip" ); - assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact"); + assert!( + frames_compared > 0, + "{NAME}: no frame was compared pixel-exact" + ); } /// lane-kf900 r5, the gate for the rect-strip `use_intrabc` read. @@ -8011,19 +8912,101 @@ pub(crate) mod tests { // Reconstruction is ported now, so the arm decodes pixel-exact and // the `rect_total` assert below keeps it from quietly falling back // to an ordinary-intra decode of the same block. - ("testsrc2-cq50-txs0", TS, &["--cq-level=50", "--enable-palette=0", "--enable-tx-size-search=0"], false, true), - ("smptebars-cq40-txs0", SB, &["--cq-level=40", "--enable-palette=0", "--enable-tx-size-search=0"], false, false), - ("smptebars-cq45-txs0", SB, &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=0"], false, true), - ("smptebars-cq45-txs1", SB, &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=1"], false, false), - ("smptebars-cq50-txs1", SB, &["--cq-level=50", "--enable-palette=0", "--enable-tx-size-search=1"], false, false), - ("smptebars-cq55-txs0", SB, &["--cq-level=55", "--enable-palette=0", "--enable-tx-size-search=0"], false, false), - ("testsrc2-cq63-txs1", TS, &["--cq-level=63", "--enable-palette=0", "--enable-tx-size-search=1"], false, false), + ( + "testsrc2-cq50-txs0", + TS, + &[ + "--cq-level=50", + "--enable-palette=0", + "--enable-tx-size-search=0", + ], + false, + true, + ), + ( + "smptebars-cq40-txs0", + SB, + &[ + "--cq-level=40", + "--enable-palette=0", + "--enable-tx-size-search=0", + ], + false, + false, + ), + ( + "smptebars-cq45-txs0", + SB, + &[ + "--cq-level=45", + "--enable-palette=0", + "--enable-tx-size-search=0", + ], + false, + true, + ), + ( + "smptebars-cq45-txs1", + SB, + &[ + "--cq-level=45", + "--enable-palette=0", + "--enable-tx-size-search=1", + ], + false, + false, + ), + ( + "smptebars-cq50-txs1", + SB, + &[ + "--cq-level=50", + "--enable-palette=0", + "--enable-tx-size-search=1", + ], + false, + false, + ), + ( + "smptebars-cq55-txs0", + SB, + &[ + "--cq-level=55", + "--enable-palette=0", + "--enable-tx-size-search=0", + ], + false, + false, + ), + ( + "testsrc2-cq63-txs1", + TS, + &[ + "--cq-level=63", + "--enable-palette=0", + "--enable-tx-size-search=1", + ], + false, + false, + ), // lane-kf900 r7: the 8x8-LEAF intrabc arm. Rect and 1:4 // partitions off (so no rect strip refuses first), palette on, // `TxMode::Largest`: aomenc puts exactly one `use_intrabc` block // on a `BLOCK_8X8` leaf here, the shape `decode_leaf8` decoded as // ordinary intra before this round. - ("testsrc2-cq55-leaf8", TS, &["--cq-level=55", "--enable-palette=1", "--enable-tx-size-search=0", "--enable-rect-partitions=0", "--enable-1to4-partitions=0"], false, false), + ( + "testsrc2-cq55-leaf8", + TS, + &[ + "--cq-level=55", + "--enable-palette=1", + "--enable-tx-size-search=0", + "--enable-rect-partitions=0", + "--enable-1to4-partitions=0", + ], + false, + false, + ), ]; let (mut reads_total, mut refused, mut frames_compared) = (0usize, 0u32, 0usize); let (mut blocks_total, mut fired_arms, mut out_of_scope, mut out_of_scope_mismatch) = @@ -8034,8 +9017,21 @@ pub(crate) mod tests { let render = || { let out = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", *src, "-t", "0.2", "-pix_fmt", - "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + *src, + "-t", + "0.2", + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -8047,36 +9043,42 @@ pub(crate) mod tests { }; let y4m_a = render(); let y4m_b = render(); - assert_eq!(y4m_a, y4m_b, "{NAME}: {arm} must render byte-identical across two runs"); + assert_eq!( + y4m_a, y4m_b, + "{NAME}: {arm} must render byte-identical across two runs" + ); let y4m = y4m_a; - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", - "--bit-depth=8", - "--input-bit-depth=8", - "--passes=1", - "--end-usage=q", - "--cpu-used=0", - "--lag-in-frames=0", - "--kf-max-dist=1", - "--limit=1", - "--threads=1", - "--tile-columns=0", - "--enable-rect-partitions=1", - "--enable-1to4-partitions=1", - "--min-partition-size=8", - "--max-partition-size=32", - "--sb-size=64", - // `allow_screen_content_tools` (and with it the frame - // header's `allow_intrabc` bit) comes from here. - "--tune-content=screen", - // Spelled so `gate_coverage` counts the tool as exercised - // rather than defaulted (class `tool-disabled-in-every-gate`). - "--enable-intrabc=1", - ]) - // aomenc keeps the LAST occurrence of a repeated flag. - .args(*extra) - .args(["--obu", "-o", "-", "-"]), &y4m); + let out = run_with_stdin( + Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--bit-depth=8", + "--input-bit-depth=8", + "--passes=1", + "--end-usage=q", + "--cpu-used=0", + "--lag-in-frames=0", + "--kf-max-dist=1", + "--limit=1", + "--threads=1", + "--tile-columns=0", + "--enable-rect-partitions=1", + "--enable-1to4-partitions=1", + "--min-partition-size=8", + "--max-partition-size=32", + "--sb-size=64", + // `allow_screen_content_tools` (and with it the frame + // header's `allow_intrabc` bit) comes from here. + "--tune-content=screen", + // Spelled so `gate_coverage` counts the tool as exercised + // rather than defaulted (class `tool-disabled-in-every-gate`). + "--enable-intrabc=1", + ]) + // aomenc keeps the LAST occurrence of a repeated flag. + .args(*extra) + .args(["--obu", "-o", "-", "-"]), + &y4m, + ); assert!( out.status.success(), "{NAME}: aomenc refused {arm}: {}", @@ -8123,8 +9125,13 @@ pub(crate) mod tests { reconstruction is not ported, it must refuse by name" ); assert!(!frames.is_empty(), "{NAME}: {arm} decoded no frame"); - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len()); - assert_eq!(frames.len(), ffmpeg_frames.len(), "{NAME}: {arm} frame count"); + let ffmpeg_frames = + ffmpeg_decode_sequence(&stream, width, height, frames.len()); + assert_eq!( + frames.len(), + ffmpeg_frames.len(), + "{NAME}: {arm} frame count" + ); // EVERY frame is compared; an arm whose decode never hit an // intrabc block proves nothing about the DV/prediction path, // so it is counted OUT OF SCOPE -- but a mismatch there is @@ -8158,7 +9165,10 @@ pub(crate) mod tests { } Err(e) => { let msg = e.to_string(); - assert!(msg.contains("unsupported"), "{NAME}: {arm} decode failed: {e}"); + assert!( + msg.contains("unsupported"), + "{NAME}: {arm} decode failed: {e}" + ); assert!( *expect_refusal, "{NAME}: {arm} was expected to decode, it refused: {e}" @@ -8181,7 +9191,10 @@ pub(crate) mod tests { eprintln!( "{NAME}: {rect_total} intrabc block(s) on a HORZ/VERT rect strip (decode_intrabc_rect)" ); - assert!(reads_total > 0, "{NAME}: gate is vacuous -- no arm read the symbol"); + assert!( + reads_total > 0, + "{NAME}: gate is vacuous -- no arm read the symbol" + ); assert!( leaf8_total > 0, "{NAME}: no arm decoded an intrabc block at an 8x8 leaf -- lane-kf900 r7's fix is untested" @@ -8200,7 +9213,10 @@ pub(crate) mod tests { // still refuse by name, but no arm HERE reaches that shape; it stays // pinned by `refusal_inventory`'s own gate. assert_eq!(refused, 0, "{NAME}: an arm still refuses by name"); - assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact"); + assert!( + frames_compared > 0, + "{NAME}: no frame was compared pixel-exact" + ); assert_eq!( out_of_scope_mismatch, 0, "{NAME}: an arm without an intrabc block still mismatched ffmpeg" @@ -8226,22 +9242,55 @@ pub(crate) mod tests { let (width, height) = (640usize, 480usize); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", "testsrc2=s=640x480:r=25", "-frames:v", "1", - "-pix_fmt", "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + "testsrc2=s=640x480:r=25", + "-frames:v", + "1", + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .output() .expect("ffmpeg") .stdout; - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", "--bit-depth=8", "--input-bit-depth=8", "--passes=1", - "--end-usage=q", "--cpu-used=0", "--lag-in-frames=0", "--kf-max-dist=1", - "--limit=1", "--threads=1", "--tile-columns=0", - "--enable-rect-partitions=1", "--enable-1to4-partitions=1", - "--min-partition-size=4", "--max-partition-size=64", "--sb-size=64", - "--tune-content=screen", "--enable-intrabc=1", "--cq-level=60", - "--enable-palette=1", "--enable-tx-size-search=0", "--obu", "-o", "-", "-", - ]), &y4m); + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--bit-depth=8", + "--input-bit-depth=8", + "--passes=1", + "--end-usage=q", + "--cpu-used=0", + "--lag-in-frames=0", + "--kf-max-dist=1", + "--limit=1", + "--threads=1", + "--tile-columns=0", + "--enable-rect-partitions=1", + "--enable-1to4-partitions=1", + "--min-partition-size=4", + "--max-partition-size=64", + "--sb-size=64", + "--tune-content=screen", + "--enable-intrabc=1", + "--cq-level=60", + "--enable-palette=1", + "--enable-tx-size-search=0", + "--obu", + "-o", + "-", + "-", + ]), + &y4m, + ); assert!(out.status.success(), "{NAME}: aomenc failed"); crate::decode::reset_rect4_16_pair_hits(); let frames = decode_stream(&out.stdout).unwrap_or_else(|e| panic!("{NAME}: {e}")); @@ -8274,19 +9323,46 @@ pub(crate) mod tests { let (width, height) = (320usize, 240usize); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", "testsrc2=s=320x240:r=25", "-frames:v", "1", - "-pix_fmt", "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + "testsrc2=s=320x240:r=25", + "-frames:v", + "1", + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .output() .expect("ffmpeg") .stdout; - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", "--cpu-used=0", "--lossless=1", "--sb-size=128", - "--lag-in-frames=0", "--kf-max-dist=1", "--limit=1", "--threads=1", - "--passes=1", "--enable-1to4-partitions=1", "--min-partition-size=4", - "--enable-rect-partitions=1", "--obu", "-o", "-", "-", - ]), &y4m); + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--cpu-used=0", + "--lossless=1", + "--sb-size=128", + "--lag-in-frames=0", + "--kf-max-dist=1", + "--limit=1", + "--threads=1", + "--passes=1", + "--enable-1to4-partitions=1", + "--min-partition-size=4", + "--enable-rect-partitions=1", + "--obu", + "-o", + "-", + "-", + ]), + &y4m, + ); assert!(out.status.success(), "{NAME}: aomenc failed"); crate::decode::reset_rect4_16_pair_hits(); let frames = decode_stream(&out.stdout).unwrap_or_else(|e| panic!("{NAME}: {e}")); @@ -8302,11 +9378,22 @@ pub(crate) mod tests { "{NAME}: luma rows 0-127 (the measured col-108 site) diverged" ); let chroma_rows = 64 * (width / 2); - assert_eq!(&frames[0].u[..chroma_rows], &refs[0].u[..chroma_rows], "{NAME}: u"); - assert_eq!(&frames[0].v[..chroma_rows], &refs[0].v[..chroma_rows], "{NAME}: v"); + assert_eq!( + &frames[0].u[..chroma_rows], + &refs[0].u[..chroma_rows], + "{NAME}: u" + ); + assert_eq!( + &frames[0].v[..chroma_rows], + &refs[0].v[..chroma_rows], + "{NAME}: v" + ); // The col-108 byte specifically, so a shift of the old site still fails // even if some other prefix sample happens to match. - assert_eq!(frames[0].y[108], refs[0].y[108], "{NAME}: measured byte 108"); + assert_eq!( + frames[0].y[108], refs[0].y[108], + "{NAME}: measured byte 108" + ); } /// lane-av1-intrabc r4: the reviewer's unblock witness for the rect-strip /// reconstruction -- a CODED `use_intrabc` block (so its residual reader @@ -8356,13 +9443,49 @@ pub(crate) mod tests { let arms: [(&str, &str, usize, usize, &[&str], u8, bool); 3] = [ // HORZ (16x8) coded strip -- the shape the in-gate witness above // already reconstructs, pinned here with its own orientation counter. - ("horz-coded-256-cq45-pal0-txs0", TS256, 256, 192, &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=0"], 0, false), + ( + "horz-coded-256-cq45-pal0-txs0", + TS256, + 256, + 192, + &[ + "--cq-level=45", + "--enable-palette=0", + "--enable-tx-size-search=0", + ], + 0, + false, + ), // VERT (8x16) coded strip AND the DV-predictor regression stream. - ("vert-coded-512-cq45-pal1-txs0", TS512, 512, 384, &["--cq-level=45", "--enable-palette=1", "--enable-tx-size-search=0"], 1, false), + ( + "vert-coded-512-cq45-pal1-txs0", + TS512, + 512, + 384, + &[ + "--cq-level=45", + "--enable-palette=1", + "--enable-tx-size-search=0", + ], + 1, + false, + ), // The `TX_MODE_SELECT` (stream A) shape: `--enable-tx-size-search=1` // makes the frame code `tx_mode == Select`, so the intrabc block's // transform size comes off the INTER var-tx tree. - ("txmode-select-256-cq45-pal0-txs1", TS256, 256, 192, &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=1"], 0, true), + ( + "txmode-select-256-cq45-pal0-txs1", + TS256, + 256, + 192, + &[ + "--cq-level=45", + "--enable-palette=0", + "--enable-tx-size-search=1", + ], + 0, + true, + ), ]; let mut coded_total = [0usize; 2]; let mut frames_compared = 0usize; @@ -8370,8 +9493,21 @@ pub(crate) mod tests { let render = || { let out = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", *src, "-t", "0.2", "-pix_fmt", - "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + *src, + "-t", + "0.2", + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -8382,30 +9518,33 @@ pub(crate) mod tests { out.stdout }; let y4m = render(); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", - "--bit-depth=8", - "--input-bit-depth=8", - "--passes=1", - "--end-usage=q", - "--cpu-used=0", - "--lag-in-frames=0", - "--kf-max-dist=1", - "--limit=1", - "--threads=1", - "--tile-columns=0", - "--enable-rect-partitions=1", - "--enable-1to4-partitions=1", - "--min-partition-size=8", - "--max-partition-size=32", - "--sb-size=64", - "--tune-content=screen", - "--enable-intrabc=1", - ]) - // aomenc keeps the LAST occurrence of a repeated flag. - .args(*extra) - .args(["--obu", "-o", "-", "-"]), &y4m); + let out = run_with_stdin( + Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--bit-depth=8", + "--input-bit-depth=8", + "--passes=1", + "--end-usage=q", + "--cpu-used=0", + "--lag-in-frames=0", + "--kf-max-dist=1", + "--limit=1", + "--threads=1", + "--tile-columns=0", + "--enable-rect-partitions=1", + "--enable-1to4-partitions=1", + "--min-partition-size=8", + "--max-partition-size=32", + "--sb-size=64", + "--tune-content=screen", + "--enable-intrabc=1", + ]) + // aomenc keeps the LAST occurrence of a repeated flag. + .args(*extra) + .args(["--obu", "-o", "-", "-"]), + &y4m, + ); assert!( out.status.success(), "{NAME}: aomenc refused {arm}: {}", @@ -8422,8 +9561,8 @@ pub(crate) mod tests { ); } crate::decode::reset_intrabc_rect_hits(); - let frames = decode_stream(&stream) - .unwrap_or_else(|e| panic!("{NAME}: {arm} refused: {e}")); + let frames = + decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME}: {arm} refused: {e}")); assert!(!frames.is_empty(), "{NAME}: {arm} decoded no frame"); let coded = crate::decode::intrabc_rect_coded_hits(); coded_total[0] += coded[0]; @@ -8456,7 +9595,10 @@ pub(crate) mod tests { coded_total[0], coded_total[1] ); - assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact"); + assert!( + frames_compared > 0, + "{NAME}: no frame was compared pixel-exact" + ); // lane-av1-intrabc r5: the SKIPPED VERT 2:1 strip -- the arm the // reviewer's sweep panicked on (a skipped 8x32 strip passed a @@ -8472,15 +9614,48 @@ pub(crate) mod tests { // process-wide knob. let _par_lock = lock_gate_counters(); let skip_arms: [(&str, &str, usize, usize, &[&str]); 2] = [ - ("vert-skip-512-cq30-pal0-txs0", TS512, 512, 384, &["--cq-level=30", "--enable-palette=0", "--enable-tx-size-search=0"]), - ("vert-skip-512-cq30-pal1-txs0", TS512, 512, 384, &["--cq-level=30", "--enable-palette=1", "--enable-tx-size-search=0"]), + ( + "vert-skip-512-cq30-pal0-txs0", + TS512, + 512, + 384, + &[ + "--cq-level=30", + "--enable-palette=0", + "--enable-tx-size-search=0", + ], + ), + ( + "vert-skip-512-cq30-pal1-txs0", + TS512, + 512, + 384, + &[ + "--cq-level=30", + "--enable-palette=1", + "--enable-tx-size-search=0", + ], + ), ]; for (arm, src, width, height, extra) in &skip_arms { let y4m = { let out = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", *src, "-t", "0.2", "-pix_fmt", - "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + *src, + "-t", + "0.2", + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -8490,18 +9665,33 @@ pub(crate) mod tests { assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}"); out.stdout }; - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", "--bit-depth=8", "--input-bit-depth=8", "--passes=1", - "--end-usage=q", "--cpu-used=0", "--lag-in-frames=0", "--kf-max-dist=1", - "--limit=1", "--threads=1", "--tile-columns=0", - "--enable-rect-partitions=1", "--enable-1to4-partitions=1", - "--min-partition-size=8", "--max-partition-size=32", "--sb-size=64", - "--tune-content=screen", "--enable-intrabc=1", - ]) - // aomenc keeps the LAST occurrence of a repeated flag. - .args(*extra) - .args(["--obu", "-o", "-", "-"]), &y4m); + let out = run_with_stdin( + Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--bit-depth=8", + "--input-bit-depth=8", + "--passes=1", + "--end-usage=q", + "--cpu-used=0", + "--lag-in-frames=0", + "--kf-max-dist=1", + "--limit=1", + "--threads=1", + "--tile-columns=0", + "--enable-rect-partitions=1", + "--enable-1to4-partitions=1", + "--min-partition-size=8", + "--max-partition-size=32", + "--sb-size=64", + "--tune-content=screen", + "--enable-intrabc=1", + ]) + // aomenc keeps the LAST occurrence of a repeated flag. + .args(*extra) + .args(["--obu", "-o", "-", "-"]), + &y4m, + ); assert!( out.status.success(), "{NAME}: aomenc refused {arm}: {}", @@ -8567,7 +9757,13 @@ pub(crate) mod tests { /// the content intra block copy exists for; `square_only` turns the rect /// and 1:4 partitions off so an intrabc block lands on a SQUARE block /// instead of stopping on the rect-strip intrabc refusal first. - fn screen_intrabc_stream(src: &str, cq: &str, txs: &str, tiled: bool, square_only: bool) -> Vec { + fn screen_intrabc_stream( + src: &str, + cq: &str, + txs: &str, + tiled: bool, + square_only: bool, + ) -> Vec { screen_intrabc_stream_with(src, cq, txs, tiled, square_only, &[]) } @@ -8600,14 +9796,26 @@ pub(crate) mod tests { extra: &[&str], ) -> Vec { assert!(depth == 8 || depth == 10, "unsupported bit depth {depth}"); - let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let mut ff = Command::new("ffmpeg"); ff.args(["-v", "error", "-f", "lavfi", "-i", src, "-t", "0.2"]); if tiled { ff.args(["-vf", "tile=2x2"]); } let out = ff - .args(["-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-"]) + .args([ + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", + ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -8615,34 +9823,43 @@ pub(crate) mod tests { .expect("ffmpeg failed to run"); assert!(out.status.success(), "ffmpeg failed for {src}"); let y4m = out.stdout; - let enc = run_with_stdin(Command::new(aomenc_path()) - .args(["--codec=av1"]) - .args([format!("--bit-depth={depth}"), format!("--input-bit-depth={depth}")]) - .args([ - "--passes=1", - "--end-usage=q", - "--cpu-used=0", - "--lag-in-frames=0", - "--kf-max-dist=1", - "--limit=1", - "--threads=1", - "--tile-columns=0", - "--min-partition-size=8", - "--max-partition-size=32", - "--sb-size=64", - "--tune-content=screen", - "--enable-intrabc=1", - "--enable-palette=0", - ]) - .args([format!("--cq-level={cq}"), format!("--enable-tx-size-search={txs}")]) - // aomenc keeps the LAST occurrence of a repeated flag. - .args(if square_only { - &["--enable-rect-partitions=0", "--enable-1to4-partitions=0"][..] - } else { - &[][..] - }) - .args(extra) - .args(["--obu", "-o", "-", "-"]), &y4m); + let enc = run_with_stdin( + Command::new(aomenc_path()) + .args(["--codec=av1"]) + .args([ + format!("--bit-depth={depth}"), + format!("--input-bit-depth={depth}"), + ]) + .args([ + "--passes=1", + "--end-usage=q", + "--cpu-used=0", + "--lag-in-frames=0", + "--kf-max-dist=1", + "--limit=1", + "--threads=1", + "--tile-columns=0", + "--min-partition-size=8", + "--max-partition-size=32", + "--sb-size=64", + "--tune-content=screen", + "--enable-intrabc=1", + "--enable-palette=0", + ]) + .args([ + format!("--cq-level={cq}"), + format!("--enable-tx-size-search={txs}"), + ]) + // aomenc keeps the LAST occurrence of a repeated flag. + .args(if square_only { + &["--enable-rect-partitions=0", "--enable-1to4-partitions=0"][..] + } else { + &[][..] + }) + .args(extra) + .args(["--obu", "-o", "-", "-"]), + &y4m, + ); assert!( enc.status.success(), "aomenc refused {src} cq={cq}: {}", @@ -8749,9 +9966,7 @@ pub(crate) mod tests { assert_eq!(frames.len(), theirs.len(), "{NAME}: {arm} frame count"); for (i, (ours, ref_frame)) in frames.iter().zip(theirs.iter()).enumerate() { assert!( - ours.y == ref_frame.y - && ours.u == ref_frame.u - && ours.v == ref_frame.v, + ours.y == ref_frame.y && ours.u == ref_frame.u && ours.v == ref_frame.v, "{NAME}: {arm} frame {i} does not match ffmpeg" ); frames_compared += 1; @@ -8849,7 +10064,14 @@ pub(crate) mod tests { "128+80*sin((X+3*N)/17)+50*sin(Y/29)+30*sin((X+Y)/13)", false, ), - (3, 384, 320, "32", "128+90*sin((X+2*N)/37)+30*sin(Y/29)", true), + ( + 3, + 384, + 320, + "32", + "128+90*sin((X+2*N)/37)+30*sin(Y/29)", + true, + ), ]; let mut engaged_arms = 0u32; let mut vert_arms = 0u32; @@ -9011,12 +10233,15 @@ pub(crate) mod tests { let _guard = lock_gate_counters(); crate::decode::reset_leaf8_intrabc_hits(); crate::decode::reset_intrabc_tx4_chroma_copy_hits(); - let frames = decode_stream(&stream).unwrap_or_else(|e| { - panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") - }); + let frames = decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); assert_eq!(frames.len(), 1, "{NAME}: frame count"); let frame = &frames[0]; - assert_eq!((frame.width, frame.height), (640, 360), "{NAME}: dimensions"); + assert_eq!( + (frame.width, frame.height), + (640, 360), + "{NAME}: dimensions" + ); // Non-vacuity, both halves: the leaf shape must be reached at all, // and its chroma route must have consulted the ARMED slot (pre-r2 @@ -9073,7 +10298,11 @@ pub(crate) mod tests { raw.extend(plane.iter().map(|&s| s as u8)); } assert_eq!(raw.len(), RAW_LEN, "{NAME}: raw size"); - assert_eq!(fnv1a64(&raw), RAW_FNV, "{NAME}: full-frame fingerprint moved"); + assert_eq!( + fnv1a64(&raw), + RAW_FNV, + "{NAME}: full-frame fingerprint moved" + ); } /// lane-t900 r33, CENSUS for "a sub-8x8 leaf that uses intrabc". @@ -9087,7 +10316,8 @@ pub(crate) mod tests { /// firing 0 times (class `gate-blind-to-feature`). #[test] fn a_sub8_leaf_census_over_intrabc_screen_streams_measures_the_sub8_refusal() { - const NAME: &str = "a_sub8_leaf_census_over_intrabc_screen_streams_measures_the_sub8_refusal"; + const NAME: &str = + "a_sub8_leaf_census_over_intrabc_screen_streams_measures_the_sub8_refusal"; if !have_ffmpeg() || !have_aomenc() { eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); return; @@ -9134,14 +10364,15 @@ pub(crate) mod tests { } Err(e) => { let msg = e.to_string(); - assert!(msg.contains("unsupported"), "{NAME}: {arm} decode failed: {e}"); + assert!( + msg.contains("unsupported"), + "{NAME}: {arm} decode failed: {e}" + ); if msg.contains("a sub-8x8 leaf that uses intrabc") { reached += 1; } sub8_total += crate::decode::sub8_split_hits() - sub8_before; - eprintln!( - "{NAME}: {arm} intrabc_frames={intrabc_frames} REFUSED: {e}" - ); + eprintln!("{NAME}: {arm} intrabc_frames={intrabc_frames} REFUSED: {e}"); } } } @@ -9208,7 +10439,10 @@ pub(crate) mod tests { } Err(e) => { let msg = e.to_string(); - assert!(msg.contains("unsupported"), "{NAME}: {arm} decode failed: {e}"); + assert!( + msg.contains("unsupported"), + "{NAME}: {arm} decode failed: {e}" + ); vartx_total += crate::decode::intrabc_vartx_hits(); if msg.contains("mixed leaf transform sizes") { reached += 1; @@ -9259,7 +10493,8 @@ pub(crate) mod tests { /// tighten this gate to a full pixel-exact assert. #[test] fn a_real_aomenc_intrabc_mixed_vartx_tree_decodes_without_the_mixed_leaf_refusal() { - const NAME: &str = "a_real_aomenc_intrabc_mixed_vartx_tree_decodes_without_the_mixed_leaf_refusal"; + const NAME: &str = + "a_real_aomenc_intrabc_mixed_vartx_tree_decodes_without_the_mixed_leaf_refusal"; if !have_ffmpeg() || !have_aomenc() { eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); return; @@ -9453,9 +10688,7 @@ pub(crate) mod tests { assert_eq!(frames.len(), theirs.len(), "{NAME}: {arm} frame count"); for (i, (ours, ref_frame)) in frames.iter().zip(theirs.iter()).enumerate() { assert!( - ours.y == ref_frame.y - && ours.u == ref_frame.u - && ours.v == ref_frame.v, + ours.y == ref_frame.y && ours.u == ref_frame.u && ours.v == ref_frame.v, "{NAME}: {arm} frame {i} does not match ffmpeg" ); frames_compared += 1; @@ -9468,7 +10701,10 @@ pub(crate) mod tests { } Err(e) => { let msg = e.to_string(); - assert!(msg.contains("unsupported"), "{NAME}: {arm} decode failed: {e}"); + assert!( + msg.contains("unsupported"), + "{NAME}: {arm} decode failed: {e}" + ); if msg.contains("an intrabc block under TxMode::Select") { refused_tx_select += 1; assert!( @@ -9507,7 +10743,10 @@ pub(crate) mod tests { "{NAME}: lane-t900 r32 lifted this refusal -- an intrabc block now reads the \ INTER tx-size syntax, so no arm may reach it again" ); - assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact"); + assert!( + frames_compared > 0, + "{NAME}: no frame was compared pixel-exact" + ); } /// lane-t900 r31, the WAITING witness for the capability @@ -9538,7 +10777,8 @@ pub(crate) mod tests { } let (width, height) = (256usize, 192usize); for cq in ["30", "45"] { - let stream = screen_intrabc_stream("smptebars=size=128x96:rate=25", cq, "1", true, true); + let stream = + screen_intrabc_stream("smptebars=size=128x96:rate=25", cq, "1", true, true); let (select, premise) = tx_select_and_intrabc_frames(&stream); assert!( select > 0 && premise > 0, @@ -9548,9 +10788,14 @@ pub(crate) mod tests { crate::decode::reset_intrabc_hits(); crate::decode::reset_intrabc_vartx_hits(); let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME}: cq={cq}: {e}")); - let (blocks, vartx) = - (crate::decode::intrabc_hits(), crate::decode::intrabc_vartx_hits()); - assert!(blocks > 0, "{NAME}: cq={cq} no longer decodes an intrabc block"); + let (blocks, vartx) = ( + crate::decode::intrabc_hits(), + crate::decode::intrabc_vartx_hits(), + ); + assert!( + blocks > 0, + "{NAME}: cq={cq} no longer decodes an intrabc block" + ); // r31 recorded cq=45's intrabc blocks as ALL skip; that was read // off the desynced decode. With the tx-size read corrected both // arms carry unskipped ones (cq30 1 of 16, cq45 3 of 10), so both @@ -9617,7 +10862,10 @@ pub(crate) mod tests { ); headers += 1; } - assert!(headers >= 3, "{NAME}: only {headers} frame headers in the fixture"); + assert!( + headers >= 3, + "{NAME}: only {headers} frame headers in the fixture" + ); let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME}: {e}")); let theirs = ffmpeg_decode_sequence(&stream, width, height, frames.len()); assert_eq!(frames.len(), theirs.len(), "{NAME}: frame count"); @@ -9683,14 +10931,42 @@ pub(crate) mod tests { "--enable-intrabc=1", "--enable-tx-size-search=1", ]; - let cq40: Vec<&str> = screen_txs.iter().copied().chain(["--cq-level=40"]).collect(); - let cq55: Vec<&str> = screen_txs.iter().copied().chain(["--cq-level=55"]).collect(); + let cq40: Vec<&str> = screen_txs + .iter() + .copied() + .chain(["--cq-level=40"]) + .collect(); + let cq55: Vec<&str> = screen_txs + .iter() + .copied() + .chain(["--cq-level=55"]) + .collect(); let arms: [(&str, String, &[&str]); 5] = [ - ("testsrc2-pinned", "testsrc2=s=256x192:r=25".to_string(), &[]), - ("testsrc2-screen", "testsrc2=s=256x192:r=25".to_string(), screen), - ("smptebars-screen", "smptebars=size=256x192:rate=25".to_string(), screen), - ("smptebars-screen-txs-cq40", "smptebars=size=256x192:rate=25".to_string(), &cq40), - ("smptebars-screen-txs-cq55", "smptebars=size=256x192:rate=25".to_string(), &cq55), + ( + "testsrc2-pinned", + "testsrc2=s=256x192:r=25".to_string(), + &[], + ), + ( + "testsrc2-screen", + "testsrc2=s=256x192:r=25".to_string(), + screen, + ), + ( + "smptebars-screen", + "smptebars=size=256x192:rate=25".to_string(), + screen, + ), + ( + "smptebars-screen-txs-cq40", + "smptebars=size=256x192:rate=25".to_string(), + &cq40, + ), + ( + "smptebars-screen-txs-cq55", + "smptebars=size=256x192:rate=25".to_string(), + &cq55, + ), ]; let (mut fired_arms, mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32, 0u32); let mut refused = 0u32; @@ -9698,12 +10974,29 @@ pub(crate) mod tests { let mut frames_compared = 0usize; for (arm, src, extra) in &arms { for depth in [8usize, 10] { - let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let render = || { let out = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", src.as_str(), "-t", "0.2", - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + src.as_str(), + "-t", + "0.2", + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -9722,35 +11015,42 @@ pub(crate) mod tests { let y4m = y4m_a; let depth_arg = format!("--bit-depth={depth}"); let in_depth_arg = format!("--input-bit-depth={depth}"); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(["--codec=av1"]) - .args([&depth_arg, &in_depth_arg]) - .args([ - "--passes=1", - "--end-usage=q", - "--cq-level=59", - "--cpu-used=0", - "--lag-in-frames=0", - "--kf-max-dist=1", - "--limit=1", - "--threads=1", - "--tile-columns=0", - "--enable-tx-size-search=1", - "--min-partition-size=8", - "--enable-rect-partitions=1", - ]) - // Per-arm overrides go AFTER the base recipe: aomenc keeps - // the LAST occurrence of a repeated flag. - .args(*extra) - // The 8-bit twin of the pinned recipe picks a 128-root - // HORZ partition, which this decoder still refuses by name - // ("a 128x128 superblock HORZ/VERT or AB partition") -- - // an open refusal of another lane, unrelated to palette. - // Pinning the superblock to 64 keeps the 8-bit arm on the - // shape this gate is about; the 10-bit arms are the - // untouched pinned recipe. - .args(if depth == 8 { &["--sb-size=64"][..] } else { &[][..] }) - .args(["--obu", "-o", "-", "-"]), &y4m); + let out = run_with_stdin( + Command::new(aomenc_path()) + .args(["--codec=av1"]) + .args([&depth_arg, &in_depth_arg]) + .args([ + "--passes=1", + "--end-usage=q", + "--cq-level=59", + "--cpu-used=0", + "--lag-in-frames=0", + "--kf-max-dist=1", + "--limit=1", + "--threads=1", + "--tile-columns=0", + "--enable-tx-size-search=1", + "--min-partition-size=8", + "--enable-rect-partitions=1", + ]) + // Per-arm overrides go AFTER the base recipe: aomenc keeps + // the LAST occurrence of a repeated flag. + .args(*extra) + // The 8-bit twin of the pinned recipe picks a 128-root + // HORZ partition, which this decoder still refuses by name + // ("a 128x128 superblock HORZ/VERT or AB partition") -- + // an open refusal of another lane, unrelated to palette. + // Pinning the superblock to 64 keeps the 8-bit arm on the + // shape this gate is about; the 10-bit arms are the + // untouched pinned recipe. + .args(if depth == 8 { + &["--sb-size=64"][..] + } else { + &[][..] + }) + .args(["--obu", "-o", "-", "-"]), + &y4m, + ); assert!( out.status.success(), "{NAME}: aomenc refused {arm} at {depth}-bit: {}", @@ -9782,7 +11082,10 @@ pub(crate) mod tests { ffmpeg_frames.len(), "{NAME}: {arm} at {depth}-bit -- frame count" ); - assert!(!frames.is_empty(), "{NAME}: {arm} at {depth}-bit decoded no frame"); + assert!( + !frames.is_empty(), + "{NAME}: {arm} at {depth}-bit decoded no frame" + ); // EVERY decode-order frame, all three planes. let mut exact = true; for (i, (ours, theirs)) in frames.iter().zip(ffmpeg_frames.iter()).enumerate() { @@ -9879,9 +11182,16 @@ pub(crate) mod tests { for i in 0..W as i64 { let g = (i * 190) / W as i64 + (j * 150) / H as i64; let mut v = (g * 12 - + if (i * 5 + j * 3 + t as i64) % 7 < 3 { 90 } else { 220 } - + if (60..110).contains(&i) && (70..110).contains(&j) { 640 } else { 0 }) - as f64; + + if (i * 5 + j * 3 + t as i64) % 7 < 3 { + 90 + } else { + 220 + } + + if (60..110).contains(&i) && (70..110).contains(&j) { + 640 + } else { + 0 + }) as f64; let c = cov(ax, bx, i) * cov(ay, by, j); if c > 0.0 { v = v * (1.0 - c) + 3500.0 * c; @@ -10005,18 +11315,34 @@ pub(crate) mod tests { let obu = probe.parse_obu(&stream[pos..]).unwrap(); pos += obu.total_size; } - let seq = probe.sequence_header().expect("stream has a sequence header OBU"); + let seq = probe + .sequence_header() + .expect("stream has a sequence header OBU"); assert_eq!( seq.color_config.bit_depth, 12, "{name}: aomenc did not actually write a 12-bit sequence header" ); } - fn ffmpeg_decode_sequence_12bit(stream: &[u8], width: usize, height: usize, frames: usize) -> Vec { + fn ffmpeg_decode_sequence_12bit( + stream: &[u8], + width: usize, + height: usize, + frames: usize, + ) -> Vec { let out = run_with_stdin( Command::new("ffmpeg").args([ - "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", - "yuv420p12le", "-", + "-v", + "error", + "-f", + "obu", + "-i", + "-", + "-f", + "rawvideo", + "-pix_fmt", + "yuv420p12le", + "-", ]), stream, ); @@ -10079,10 +11405,10 @@ pub(crate) mod tests { ); assert_12bit_sequence_header(&stream, NAME); let before_cdef = decode::cdef_idx_hits(); - let before_lr = - crate::restoration::wiener_hits() + crate::restoration::sgrproj_hits(); - let frames = decode_stream(&stream) - .unwrap_or_else(|e| panic!("{NAME}: decode_stream refused a real 12-bit key frame: {e}")); + let before_lr = crate::restoration::wiener_hits() + crate::restoration::sgrproj_hits(); + let frames = decode_stream(&stream).unwrap_or_else(|e| { + panic!("{NAME}: decode_stream refused a real 12-bit key frame: {e}") + }); assert_eq!(frames.len(), 1); assert!( decode::cdef_idx_hits() > before_cdef, @@ -10093,7 +11419,10 @@ pub(crate) mod tests { "{NAME}: no loop restoration unit was decoded -- LR is not exercised" ); let ffmpeg_frames = ffmpeg_decode_sequence_12bit(&stream, 160, 128, 1); - assert_eq!(frames[0].y, ffmpeg_frames[0].y, "luma vs ffmpeg (12-bit key)"); + assert_eq!( + frames[0].y, ffmpeg_frames[0].y, + "luma vs ffmpeg (12-bit key)" + ); assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg (12-bit key)"); assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (12-bit key)"); } @@ -10127,8 +11456,9 @@ pub(crate) mod tests { assert_12bit_sequence_header(&stream, NAME); let before_subpel = crate::mc::mc_subpel_hits(); let before_compound = decode::compound_mode_hits(); - let frames = decode_stream(&stream) - .unwrap_or_else(|e| panic!("{NAME}: decode_stream refused a real 12-bit inter stream: {e}")); + let frames = decode_stream(&stream).unwrap_or_else(|e| { + panic!("{NAME}: decode_stream refused a real 12-bit inter stream: {e}") + }); assert_eq!(frames.len(), 2); assert!( crate::mc::mc_subpel_hits() > before_subpel, @@ -10141,7 +11471,10 @@ pub(crate) mod tests { ); let ffmpeg_frames = ffmpeg_decode_sequence_12bit(&stream, 160, 128, 2); for (i, (ours, reference)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(ours.y, reference.y, "frame {i} luma vs ffmpeg (12-bit inter)"); + assert_eq!( + ours.y, reference.y, + "frame {i} luma vs ffmpeg (12-bit inter)" + ); assert_eq!(ours.u, reference.u, "frame {i} U vs ffmpeg (12-bit inter)"); assert_eq!(ours.v, reference.v, "frame {i} V vs ffmpeg (12-bit inter)"); } @@ -10205,7 +11538,10 @@ pub(crate) mod tests { ); let ffmpeg_frames = ffmpeg_decode_sequence_12bit(&stream, 160, 128, 6); for (i, (ours, reference)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(ours.y, reference.y, "frame {i} luma vs ffmpeg (12-bit warp)"); + assert_eq!( + ours.y, reference.y, + "frame {i} luma vs ffmpeg (12-bit warp)" + ); assert_eq!(ours.u, reference.u, "frame {i} U vs ffmpeg (12-bit warp)"); assert_eq!(ours.v, reference.v, "frame {i} V vs ffmpeg (12-bit warp)"); } @@ -10237,7 +11573,10 @@ pub(crate) mod tests { let y4m = y4m_12bit_subpel_source(6); for (arm, extra) in [ ("dist-wtd", &["--enable-warped-motion=0"][..]), - ("plain-masked", &["--enable-warped-motion=0", "--enable-dist-wtd-comp=0"][..]), + ( + "plain-masked", + &["--enable-warped-motion=0", "--enable-dist-wtd-comp=0"][..], + ), ] { let stream = encode_12bit(&y4m, 6, &extra); assert_12bit_sequence_header(&stream, NAME); @@ -10258,12 +11597,24 @@ pub(crate) mod tests { eprintln!( "{NAME} [{arm}]: compound blocks={comp} masked={masked} diffwtd={diffwtd} wedge={wedge}" ); - assert!(comp > 0, "{NAME} [{arm}]: no compound mode symbol was read -- the compound path is unexercised"); - assert!(masked > 0, "{NAME} [{arm}]: no masked compound block ran -- the masked combine is unexercised"); - assert!(diffwtd > 0, "{NAME} [{arm}]: no diffwtd blend ran -- the diffwtd combine is unexercised"); + assert!( + comp > 0, + "{NAME} [{arm}]: no compound mode symbol was read -- the compound path is unexercised" + ); + assert!( + masked > 0, + "{NAME} [{arm}]: no masked compound block ran -- the masked combine is unexercised" + ); + assert!( + diffwtd > 0, + "{NAME} [{arm}]: no diffwtd blend ran -- the diffwtd combine is unexercised" + ); let ffmpeg_frames = ffmpeg_decode_sequence_12bit(&stream, 160, 128, 6); for (i, (ours, reference)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(ours.y, reference.y, "{NAME} [{arm}] frame {i} luma vs ffmpeg"); + assert_eq!( + ours.y, reference.y, + "{NAME} [{arm}] frame {i} luma vs ffmpeg" + ); assert_eq!(ours.u, reference.u, "{NAME} [{arm}] frame {i} U vs ffmpeg"); assert_eq!(ours.v, reference.v, "{NAME} [{arm}] frame {i} V vs ffmpeg"); } @@ -10345,8 +11696,9 @@ pub(crate) mod tests { } assert_eq!(grain_frames, 2, "{NAME}: expected grain on both frames"); let before = crate::film_grain::grain_hits(); - let frames = decode_stream(&stream) - .unwrap_or_else(|e| panic!("{NAME}: decode_stream refused a real 12-bit grain stream: {e}")); + let frames = decode_stream(&stream).unwrap_or_else(|e| { + panic!("{NAME}: decode_stream refused a real 12-bit grain stream: {e}") + }); assert_eq!(frames.len(), 2); assert!( crate::film_grain::grain_hits() > before, @@ -10354,11 +11706,23 @@ pub(crate) mod tests { ); let ffmpeg_frames = ffmpeg_decode_sequence_12bit(&stream, 160, 128, 2); for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(ours.y, theirs.y, "{NAME}: luma vs ffmpeg (12-bit grain, frame {i})"); - assert_eq!(ours.u, theirs.u, "{NAME}: U vs ffmpeg (12-bit grain, frame {i})"); - assert_eq!(ours.v, theirs.v, "{NAME}: V vs ffmpeg (12-bit grain, frame {i})"); + assert_eq!( + ours.y, theirs.y, + "{NAME}: luma vs ffmpeg (12-bit grain, frame {i})" + ); + assert_eq!( + ours.u, theirs.u, + "{NAME}: U vs ffmpeg (12-bit grain, frame {i})" + ); + assert_eq!( + ours.v, theirs.v, + "{NAME}: V vs ffmpeg (12-bit grain, frame {i})" + ); } - eprintln!("{NAME}: byte-exact, grain_hits={}", crate::film_grain::grain_hits()); + eprintln!( + "{NAME}: byte-exact, grain_hits={}", + crate::film_grain::grain_hits() + ); } /// The 12-bit screen-content refusal: a real `--tune-content=screen @@ -10379,9 +11743,21 @@ pub(crate) mod tests { } let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", "smptebars=s=128x128:r=25", - "-pix_fmt", "yuv420p12le", "-strict", "-1", "-frames:v", "2", - "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + "smptebars=s=128x128:r=25", + "-pix_fmt", + "yuv420p12le", + "-strict", + "-1", + "-frames:v", + "2", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -10396,7 +11772,11 @@ pub(crate) mod tests { let stream = encode_12bit( &y4m.stdout, 1, - &["--tune-content=screen", "--enable-palette=1", "--enable-intrabc=1"], + &[ + "--tune-content=screen", + "--enable-palette=1", + "--enable-intrabc=1", + ], ); let err = decode_stream(&stream).unwrap_err().to_string(); assert!( @@ -10447,8 +11827,8 @@ pub(crate) mod tests { "ffmpeg failed to render the 10-bit fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -10464,7 +11844,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the 10-bit fixture: {}", @@ -10543,8 +11925,8 @@ pub(crate) mod tests { "ffmpeg failed to render the 10-bit fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ // lane-defon r1: explicit on-value (aomenc keeps the FIRST // occurrence, so overrides go before the base list). "--loopfilter-control=1", @@ -10586,7 +11968,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the 10-bit fixture: {}", @@ -10738,7 +12122,10 @@ pub(crate) mod tests { assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg"); assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg"); assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg"); - eprintln!("{NAME}: pixel-exact, grain_hits={}", crate::film_grain::grain_hits()); + eprintln!( + "{NAME}: pixel-exact, grain_hits={}", + crate::film_grain::grain_hits() + ); } /// lane-t900 r29: `fixtures/superres_kf_cdef_lr_64x64.obu` is a real @@ -10857,9 +12244,18 @@ pub(crate) mod tests { assert!(!one.is_empty(), "{NAME}: {fixture} decoded nothing"); assert_eq!(one.len(), four.len(), "{NAME}: {fixture} frame count"); for (i, (a, b)) in one.iter().zip(four.iter()).enumerate() { - assert_eq!(a.y, b.y, "{NAME}: {fixture} frame {i} luma differs at 4 recon threads"); - assert_eq!(a.u, b.u, "{NAME}: {fixture} frame {i} U differs at 4 recon threads"); - assert_eq!(a.v, b.v, "{NAME}: {fixture} frame {i} V differs at 4 recon threads"); + assert_eq!( + a.y, b.y, + "{NAME}: {fixture} frame {i} luma differs at 4 recon threads" + ); + assert_eq!( + a.u, b.u, + "{NAME}: {fixture} frame {i} U differs at 4 recon threads" + ); + assert_eq!( + a.v, b.v, + "{NAME}: {fixture} frame {i} V differs at 4 recon threads" + ); } } } @@ -10900,7 +12296,11 @@ pub(crate) mod tests { } crate::par::set_filter_threads(1); crate::par::set_recon_threads(1); - assert!(frames[0] > 1, "{NAME}: the fixture decoded {} frames, so nothing was threaded", frames[0]); + assert!( + frames[0] > 1, + "{NAME}: the fixture decoded {} frames, so nothing was threaded", + frames[0] + ); // 4 frame workers x (recon 2 + filter 4) plus the two in-flight // slots `stream.rs` allows over the thread count, with room for the // show jobs -- 1038 was three orders past this. @@ -10915,7 +12315,8 @@ pub(crate) mod tests { assert!( counts[1] <= counts[0] + 4, "{NAME}: a second decode of the same stream grew the pool from {} to {} threads", - counts[0], counts[1] + counts[0], + counts[1] ); } @@ -10956,19 +12357,37 @@ pub(crate) mod tests { } }; crate::par::set_filter_threads(1); - assert!(after.0 > before.0, "{NAME}: {fixture} deblocked no edge at all"); + assert!( + after.0 > before.0, + "{NAME}: {fixture} deblocked no edge at all" + ); if wants_lr { - assert!(after.1 > before.1, "{NAME}: {fixture} ran no restoration unit"); + assert!( + after.1 > before.1, + "{NAME}: {fixture} ran no restoration unit" + ); } if wants_grain { - assert!(after.2 > before.2, "{NAME}: {fixture} applied no film grain"); + assert!( + after.2 > before.2, + "{NAME}: {fixture} applied no film grain" + ); } assert_eq!(one.len(), four.len(), "{NAME}: {fixture} frame count"); assert!(!one.is_empty(), "{NAME}: {fixture} decoded nothing"); for (i, (a, b)) in one.iter().zip(four.iter()).enumerate() { - assert_eq!(a.y, b.y, "{NAME}: {fixture} frame {i} luma differs at 4 filter threads"); - assert_eq!(a.u, b.u, "{NAME}: {fixture} frame {i} U differs at 4 filter threads"); - assert_eq!(a.v, b.v, "{NAME}: {fixture} frame {i} V differs at 4 filter threads"); + assert_eq!( + a.y, b.y, + "{NAME}: {fixture} frame {i} luma differs at 4 filter threads" + ); + assert_eq!( + a.u, b.u, + "{NAME}: {fixture} frame {i} U differs at 4 filter threads" + ); + assert_eq!( + a.v, b.v, + "{NAME}: {fixture} frame {i} V differs at 4 filter threads" + ); } } } @@ -11044,8 +12463,8 @@ pub(crate) mod tests { eprintln!("SKIP {NAME}: no ffmpeg"); return; } - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) - .join("fixtures/reelb_head_key_frame.obu"); + let path = + std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/reelb_head_key_frame.obu"); let stream = std::fs::read(&path) .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); let (width, height) = (3840usize, 1608usize); @@ -11181,7 +12600,7 @@ pub(crate) mod tests { /// `EC_PREDOUT`), so this gate pins what is proven and no more. #[test] fn a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact() - { + { const NAME: &str = "a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact"; if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); @@ -11481,7 +12900,10 @@ pub(crate) mod tests { ("filter_intra_hits", decode::filter_intra_hits), ("smooth_pred_hits", crate::intra::smooth_pred_hits), ("paeth_pred_hits", crate::intra::paeth_pred_hits), - ("intra_edge_filter_hits", crate::intra::intra_edge_filter_hits), + ( + "intra_edge_filter_hits", + crate::intra::intra_edge_filter_hits, + ), ], ); } @@ -11552,7 +12974,9 @@ pub(crate) mod tests { /// out of this gate rather than papered over, and reported as open. const OBMC_PAIR_SEEDS: [u32; 5] = [43, 46, 47, 65, 66]; - const LR_SEEDS: [u32; 16] = [42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57]; + const LR_SEEDS: [u32; 16] = [ + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + ]; /// Wiener + SGR + switchable loop-restoration firings, summed. fn ten_bit_lr_hits() -> usize { @@ -11589,8 +13013,11 @@ pub(crate) mod tests { // own `--sb-size=64` (aomenc keeps the LAST occurrence of a repeated // flag, measured 2026-09-02); `--max-partition-size=32` keeps the 128 // root on SPLIT, the only 128-root partition decoded today. - for (width, height, cq) in [(256usize, 152usize, "15"), (384, 216, "15"), (256, 152, "25")] - { + for (width, height, cq) in [ + (256usize, 152usize, "15"), + (384, 216, "15"), + (256, 152, "25"), + ] { ten_bit_tool_gate( &format!("{NAME} {width}x{height} cq{cq}"), width, @@ -11621,7 +13048,10 @@ pub(crate) mod tests { &[ ("lr_hits", ten_bit_lr_hits), ("lr_stripe0_hits", crate::restoration::lr_stripe0_hits), - ("lr_last_stripe_hits", crate::restoration::lr_last_stripe_hits), + ( + "lr_last_stripe_hits", + crate::restoration::lr_last_stripe_hits, + ), ], ); } @@ -11703,7 +13133,8 @@ pub(crate) mod tests { /// next to an OBMC block cannot stand in for it. #[test] fn a_real_aomenc_10bit_obmc_over_1to4_strip_neighbours_decodes_pixel_exact() { - const NAME: &str = "a_real_aomenc_10bit_obmc_over_1to4_strip_neighbours_decodes_pixel_exact"; + const NAME: &str = + "a_real_aomenc_10bit_obmc_over_1to4_strip_neighbours_decodes_pixel_exact"; if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); return; @@ -11858,8 +13289,7 @@ pub(crate) mod tests { ]); args.extend_from_slice(extra); args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "{name}: aomenc refused the 10-bit fixture: {}", @@ -11922,8 +13352,8 @@ pub(crate) mod tests { "testsrc2 must render byte-identical across two runs" ); let y4m = y4m_a; - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -11949,7 +13379,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m); + ]), + &y4m, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -12016,8 +13448,19 @@ pub(crate) mod tests { let source = format!("{src_name}=size={width}x{height}:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", - "-t", "0.04", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-t", + "0.04", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -12030,8 +13473,8 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let cq_arg = format!("--cq-level={cq}"); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -12047,7 +13490,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture ({source} cq={cq}): {}", @@ -12085,9 +13530,11 @@ pub(crate) mod tests { } let frame_count = frames.len(); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); - if frames.iter().zip(&ffmpeg_frames).any(|(got, want)| { - got.y != want.y || got.u != want.u || got.v != want.v - }) && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") + if frames + .iter() + .zip(&ffmpeg_frames) + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v) + && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { std::fs::write(&path, &stream).expect("writing pinned stream"); eprintln!( @@ -12172,8 +13619,19 @@ pub(crate) mod tests { let source = format!("{src_name}=size={width}x{height}:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", - "-t", "0.04", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-t", + "0.04", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -12186,8 +13644,8 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let cq_arg = format!("--cq-level={cq}"); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -12203,7 +13661,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture ({source} cq={cq}): {}", @@ -12238,9 +13698,11 @@ pub(crate) mod tests { } let frame_count = frames.len(); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); - if frames.iter().zip(&ffmpeg_frames).any(|(got, want)| { - got.y != want.y || got.u != want.u || got.v != want.v - }) && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") + if frames + .iter() + .zip(&ffmpeg_frames) + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v) + && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { std::fs::write(&path, &stream).expect("writing pinned stream"); eprintln!( @@ -12331,8 +13793,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ // lane-defon r1: explicit on-value (aomenc keeps the FIRST // occurrence, so overrides go before the base list). "--loopfilter-control=1", @@ -12363,7 +13825,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -12470,8 +13934,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -12510,7 +13974,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -12619,7 +14085,8 @@ pub(crate) mod tests { } fn intra_rect_in_inter_gate(bit_depth: u32) { - const NAME: &str = "a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact"; + const NAME: &str = + "a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact"; if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); return; @@ -12661,7 +14128,11 @@ pub(crate) mod tests { "-vf", "hue=s=0", "-pix_fmt", - if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, + if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }, "-strict", "-1", "-t", @@ -12698,77 +14169,80 @@ pub(crate) mod tests { // walks it too, so "no rect strip fired" cannot be an artefact of // one cq. let cq = format!("--cq-level={}", [30u32, 20, 12][(attempt / 5) as usize % 3]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(depth_args) - .arg(&cpu) - .arg(&cq) - .args([ - // class [[aomenc-first-flag-wins]]: every flag is spelled - // exactly ONCE in this recipe, so there is no override to - // order. These four are what this gate is about. - "--enable-rect-partitions=1", - // MEASURED (r1): the charter's `--min-partition-size=8` - // makes 24/24 attempts stop at a sub-16 AB-partition - // refusal ("a HORZ_A/HORZ_B/VERT_A partition below 16x16", - // "a coded (non-skip) HORZ_B/VERT_B rect strip below - // 16x16") before any intra rect strip is reached -- those - // are other lanes' surfaces. 16 keeps the 16x8/8x16 shape - // reachable (a 16x16 block's own HORZ/VERT children). - "--min-partition-size=16", - "--max-partition-size=64", - // MEASURED (r1): with tx-size search ON, 24/24 attempts stop at - // the SQUARE intra-in-inter arm's own refusal ("an intra - // block in an inter frame whose tx_depth splits its luma - // transform (round 1)", read_block_tx_size) long before a - // rect strip is reached -- that arm is another lane's - // surface. OFF, no tx-depth symbol is coded at all and - // every rect strip here is the unsplit single-transform - // case. The SPLIT rect arm (`depth_to_tx_wh` + - // decode_rect_split's per-unit walk) is wired but stays - // UNGATED on this path until that square refusal lifts. - "--enable-tx-size-search=0", - "--codec=av1", - "--passes=1", - "--end-usage=q", - "--lag-in-frames=0", - "--auto-alt-ref=0", - // One key frame at the head: the frames after the cut must - // stay INTER frames carrying intra blocks, not become a - // new key frame. - "--kf-min-dist=1000", - "--kf-max-dist=1000", - "--threads=1", - "--row-mt=0", - "--enable-order-hint=0", - "--enable-warped-motion=0", - "--enable-obmc=0", - "--enable-masked-comp=0", - "--enable-interintra-comp=0", - "--enable-dist-wtd-comp=0", - "--enable-diff-wtd-comp=0", - "--enable-onesided-comp=0", - "--enable-interintra-wedge=0", - "--enable-smooth-interintra=0", - "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", - // The intra-in-inter arm reads no `use_filter_intra` - // symbol (square OR rect) -- lane-fiinter owns that read. - "--enable-filter-intra=0", - "--enable-smooth-intra=0", - "--enable-paeth-intra=0", - "--enable-directional-intra=0", - "--enable-angle-delta=0", - "--enable-cdef=0", - "--enable-restoration=0", - "--enable-palette=0", - "--enable-intrabc=0", - "--enable-cfl-intra=0", - "--enable-ref-frame-mvs=0", - "--obu", - "-o", - "-", - "-", - ]), &y4m.stdout); + let out = run_with_stdin( + Command::new(aomenc_path()) + .args(depth_args) + .arg(&cpu) + .arg(&cq) + .args([ + // class [[aomenc-first-flag-wins]]: every flag is spelled + // exactly ONCE in this recipe, so there is no override to + // order. These four are what this gate is about. + "--enable-rect-partitions=1", + // MEASURED (r1): the charter's `--min-partition-size=8` + // makes 24/24 attempts stop at a sub-16 AB-partition + // refusal ("a HORZ_A/HORZ_B/VERT_A partition below 16x16", + // "a coded (non-skip) HORZ_B/VERT_B rect strip below + // 16x16") before any intra rect strip is reached -- those + // are other lanes' surfaces. 16 keeps the 16x8/8x16 shape + // reachable (a 16x16 block's own HORZ/VERT children). + "--min-partition-size=16", + "--max-partition-size=64", + // MEASURED (r1): with tx-size search ON, 24/24 attempts stop at + // the SQUARE intra-in-inter arm's own refusal ("an intra + // block in an inter frame whose tx_depth splits its luma + // transform (round 1)", read_block_tx_size) long before a + // rect strip is reached -- that arm is another lane's + // surface. OFF, no tx-depth symbol is coded at all and + // every rect strip here is the unsplit single-transform + // case. The SPLIT rect arm (`depth_to_tx_wh` + + // decode_rect_split's per-unit walk) is wired but stays + // UNGATED on this path until that square refusal lifts. + "--enable-tx-size-search=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--lag-in-frames=0", + "--auto-alt-ref=0", + // One key frame at the head: the frames after the cut must + // stay INTER frames carrying intra blocks, not become a + // new key frame. + "--kf-min-dist=1000", + "--kf-max-dist=1000", + "--threads=1", + "--row-mt=0", + "--enable-order-hint=0", + "--enable-warped-motion=0", + "--enable-obmc=0", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-dist-wtd-comp=0", + "--enable-diff-wtd-comp=0", + "--enable-onesided-comp=0", + "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + // The intra-in-inter arm reads no `use_filter_intra` + // symbol (square OR rect) -- lane-fiinter owns that read. + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -12807,7 +14281,9 @@ pub(crate) mod tests { eprintln!( "intrarect gate {bit_depth}-bit seed={seed} {cpu} {cq}: intra rect strips in inter frames \ 64-level={} 32-level={} 16-level={}, key-frame rect strips this stream={}", - delta[0], delta[1], delta[2], + delta[0], + delta[1], + delta[2], decode::rect_partition_hits() - kf_rect_before ); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { @@ -12946,7 +14422,11 @@ pub(crate) mod tests { "-vf", "hue=s=0", "-pix_fmt", - if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, + if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }, // y4m carries no official 10-bit tag; ffmpeg writes one // only under `-strict -1` (a no-op at 8 bit). "-strict", @@ -12974,9 +14454,8 @@ pub(crate) mod tests { } else { &[] }; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(depth_args) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args(depth_args).args([ // lane-defon r1: explicit on-value (aomenc keeps the FIRST // occurrence, so overrides go before the base list). "--enable-tx-size-search=1", @@ -13025,7 +14504,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -13195,7 +14676,11 @@ pub(crate) mod tests { "-vf", "hue=s=0", "-pix_fmt", - if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, + if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }, "-strict", "-1", "-t", @@ -13221,9 +14706,8 @@ pub(crate) mod tests { } else { &[] }; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(depth_args) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args(depth_args).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -13277,7 +14761,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -13440,7 +14926,11 @@ pub(crate) mod tests { "-vf", "hue=s=0", "-pix_fmt", - if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, + if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }, "-strict", "-1", "-t", @@ -13466,9 +14956,8 @@ pub(crate) mod tests { } else { &[] }; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(depth_args) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args(depth_args).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -13522,7 +15011,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -13560,9 +15051,7 @@ pub(crate) mod tests { ffmpeg_decode_sequence(&stream, width, height, frame_count) }; assert_eq!(frames.len(), frame_count); - eprintln!( - "{name} seed={seed}: filter-intra blocks inside inter frames = {fired}" - ); + eprintln!("{name} seed={seed}: filter-intra blocks inside inter frames = {fired}"); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { for (plane, (g, w)) in [ ("Y", (&got.y, &want.y)), @@ -13638,7 +15127,10 @@ pub(crate) mod tests { fn angle_delta_in_inter_gate(bit_depth: u32, min_partition: &str) { let name = format!("angle_delta_in_inter_gate({bit_depth}, min={min_partition})"); let leaf8 = min_partition.ends_with('8'); - assert!(!leaf8, "the 8x8-leaf arm keeps its refusal; see the module note"); + assert!( + !leaf8, + "the 8x8-leaf arm keeps its refusal; see the module note" + ); if !have_ffmpeg() { eprintln!("SKIP {name}: no ffmpeg"); return; @@ -13682,7 +15174,11 @@ pub(crate) mod tests { "-vf", "hue=s=0", "-pix_fmt", - if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, + if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }, "-strict", "-1", "-t", @@ -13717,9 +15213,8 @@ pub(crate) mod tests { } else { &[] }; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(depth_args) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args(depth_args).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -13773,7 +15268,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -13884,7 +15381,8 @@ pub(crate) mod tests { /// The 10-bit arm (both of the user's films are `yuv420p10le`). #[test] - fn a_real_aomenc_10bit_inter_sequence_with_a_non_dc_chroma_8x8_intra_leaf_decodes_pixel_exact() { + fn a_real_aomenc_10bit_inter_sequence_with_a_non_dc_chroma_8x8_intra_leaf_decodes_pixel_exact() + { uv_mode_in_inter8_gate(10, 1); } @@ -13937,7 +15435,11 @@ pub(crate) mod tests { "-i", &source, "-pix_fmt", - if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, + if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }, "-strict", "-1", "-t", @@ -14062,11 +15564,7 @@ pub(crate) mod tests { // only for an attempt that decoded to the end and is pixel- // compared below. let fired = (now.0 - before.0, now.1 - before.1, now.2 - before.2); - totals = ( - totals.0 + fired.0, - totals.1 + fired.1, - totals.2 + fired.2, - ); + totals = (totals.0 + fired.0, totals.1 + fired.1, totals.2 + fired.2); // class [[gate-skips-on-its-own-failure]]: a decode that succeeded // is ALWAYS pixel-compared; the counter only decides whether the // attempt counts as firing. @@ -14141,7 +15639,6 @@ pub(crate) mod tests { ); } - /// lane-leaf8tx r1: the refusal this round lifts on an INTRA 8x8 leaf /// inside an INTER frame -- a nonzero luma `angle_delta_y` on it /// (`--enable-angle-delta=1`, @@ -14197,7 +15694,11 @@ pub(crate) mod tests { "-i", &source, "-pix_fmt", - if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, + if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }, "-strict", "-1", "-t", @@ -14486,143 +15987,156 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", - "--passes=1", - "--end-usage=q", - "--cq-level=45", - "--cpu-used=0", - "--enable-rect-partitions=0", - "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", - "--enable-filter-intra=0", - "--enable-smooth-intra=1", - // Smooth/paeth chroma is a still-refused, separate - // round-2 gap -- off so no attempt trips it while this - // gate is purely about luma's edge-filter fix. - "--enable-paeth-intra=0", - "--enable-tx-size-search=0", - "--enable-cdef=0", - "--enable-restoration=0", - "--enable-intra-edge-filter=1", - "--max-partition-size=32", - "--min-partition-size=16", - "--enable-palette=0", - "--enable-intrabc=0", - "--enable-cfl-intra=0", - "--enable-ref-frame-mvs=0", - "--obu", - "-o", - "-", - "-", - ]), &y4m.stdout); - assert!( - out.status.success(), - "aomenc refused the fixture: {}", - String::from_utf8_lossy(&out.stderr) - ); - let stream = out.stdout; - let smooth_before = decode::smooth_luma_hits(); - let frames = match decode_stream(&stream) { - Ok(frames) => frames, - Err(e) => { - refusals.push(format!("seed {seed}: {e}")); - continue; - } - }; - // class [[gate-skips-on-its-own-failure]]: a decode that succeeded - // is ALWAYS pixel-compared below; the hit counter only decides whether - // the attempt counts toward the firing total. - let counted = decode::smooth_luma_hits() != smooth_before; - if counted { - fired_runs += 1; - } else { - uncounted_exact += 1; - refusals.push(format!( - "seed {seed}: decoded and pixel-compared, but no smooth-luma-neighbour block \ - fired" - )); - } - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!( - frames[0].y, ffmpeg_frames[0].y, - "luma vs ffmpeg (seed {seed})" - ); - assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg (seed {seed})"); - assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (seed {seed})"); - if fired_runs >= 4 { - gate_buckets( - "a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact", - fired_runs, - uncounted_exact, - refusals.len() - uncounted_exact as usize, - ); - return; - } - } - gate_buckets( - "a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact", - fired_runs, - uncounted_exact, - refusals.len() - uncounted_exact as usize, - ); - assert!( - fired_runs > 0, - "every attempt hit a named refusal or never exercised a smooth luma neighbour:\n{}", - refusals.join("\n") - ); - } - - /// The smooth/paeth-chroma gate (lane-chroma r1/r3): a real aomenc key - /// frame with `--enable-smooth-intra=1 --enable-paeth-intra=1` (the - /// opposite of the directional-chroma gate below, which turns these OFF - /// to keep this gap from firing while directional chroma is under test). - /// Some seeds won't pick smooth/paeth for chroma at all -- retry like - /// every other real-encoder gate here, but the first attempt that - /// actually fires [`decode::smooth_uv_hits`] must decode pixel-exact. - #[test] - fn a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact() { - if !have_ffmpeg() { - eprintln!( - "SKIP a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact: no ffmpeg" - ); - return; - } - if !have_aomenc() { - eprintln!( - "SKIP a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact: no aomenc at {}", - aomenc_path().display() - ); - return; - } - let (width, height) = (64usize, 64usize); - let mut refusals = Vec::new(); - let mut fired_runs = 0u32; - let mut uncounted_exact = 0u32; - for attempt in 0..40u32 { - let seed = 42 + attempt; - let source = format!( - "mandelbrot=size=64x64:start_scale={}:rate=25", - 5.0 - f64::from(attempt) * 0.06 - ); - let y4m = Command::new("ffmpeg") - .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-t", - "0.04", "-f", "yuv4mpegpipe", "-", - ]) - .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .output() - .expect("ffmpeg failed to run"); - assert!( - y4m.status.success(), - "ffmpeg fixture: {}", - String::from_utf8_lossy(&y4m.stderr) - ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=45", + "--cpu-used=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-filter-intra=0", + "--enable-smooth-intra=1", + // Smooth/paeth chroma is a still-refused, separate + // round-2 gap -- off so no attempt trips it while this + // gate is purely about luma's edge-filter fix. + "--enable-paeth-intra=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--enable-intra-edge-filter=1", + "--max-partition-size=32", + "--min-partition-size=16", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let smooth_before = decode::smooth_luma_hits(); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => { + refusals.push(format!("seed {seed}: {e}")); + continue; + } + }; + // class [[gate-skips-on-its-own-failure]]: a decode that succeeded + // is ALWAYS pixel-compared below; the hit counter only decides whether + // the attempt counts toward the firing total. + let counted = decode::smooth_luma_hits() != smooth_before; + if counted { + fired_runs += 1; + } else { + uncounted_exact += 1; + refusals.push(format!( + "seed {seed}: decoded and pixel-compared, but no smooth-luma-neighbour block \ + fired" + )); + } + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); + assert_eq!( + frames[0].y, ffmpeg_frames[0].y, + "luma vs ffmpeg (seed {seed})" + ); + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg (seed {seed})"); + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (seed {seed})"); + if fired_runs >= 4 { + gate_buckets( + "a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact", + fired_runs, + uncounted_exact, + refusals.len() - uncounted_exact as usize, + ); + return; + } + } + gate_buckets( + "a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact", + fired_runs, + uncounted_exact, + refusals.len() - uncounted_exact as usize, + ); + assert!( + fired_runs > 0, + "every attempt hit a named refusal or never exercised a smooth luma neighbour:\n{}", + refusals.join("\n") + ); + } + + /// The smooth/paeth-chroma gate (lane-chroma r1/r3): a real aomenc key + /// frame with `--enable-smooth-intra=1 --enable-paeth-intra=1` (the + /// opposite of the directional-chroma gate below, which turns these OFF + /// to keep this gap from firing while directional chroma is under test). + /// Some seeds won't pick smooth/paeth for chroma at all -- retry like + /// every other real-encoder gate here, but the first attempt that + /// actually fires [`decode::smooth_uv_hits`] must decode pixel-exact. + #[test] + fn a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact() { + if !have_ffmpeg() { + eprintln!( + "SKIP a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact: no ffmpeg" + ); + return; + } + if !have_aomenc() { + eprintln!( + "SKIP a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact: no aomenc at {}", + aomenc_path().display() + ); + return; + } + let (width, height) = (64usize, 64usize); + let mut refusals = Vec::new(); + let mut fired_runs = 0u32; + let mut uncounted_exact = 0u32; + for attempt in 0..40u32 { + let seed = 42 + attempt; + let source = format!( + "mandelbrot=size=64x64:start_scale={}:rate=25", + 5.0 - f64::from(attempt) * 0.06 + ); + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-t", + "0.04", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -14649,7 +16163,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -14766,8 +16282,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ // lane-defon r1: explicit on-value (aomenc keeps the FIRST // occurrence, so overrides go before the base list). "--enable-directional-intra=1", @@ -14809,7 +16325,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -14993,8 +16511,7 @@ pub(crate) mod tests { args.insert(1, "--input-bit-depth=10".to_string()); args.insert(1, "--bit-depth=10".to_string()); } - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "{name}: aomenc refused the fixture: {}", @@ -15007,7 +16524,10 @@ pub(crate) mod tests { Err(e) => { let pin = std::env::temp_dir().join(format!("{name}-refused.obu")); let _ = std::fs::write(&pin, &stream); - panic!("{name}: decode_stream refused a real aomenc stream: {e} (pinned at {})", pin.display()); + panic!( + "{name}: decode_stream refused a real aomenc stream: {e} (pinned at {})", + pin.display() + ); } }; assert!( @@ -15024,7 +16544,10 @@ pub(crate) mod tests { if got.y != want.y || got.u != want.u || got.v != want.v { let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu")); let _ = std::fs::write(&pin, &stream); - panic!("{name}: frame {i} mismatch vs ffmpeg -- stream pinned at {}", pin.display()); + panic!( + "{name}: frame {i} mismatch vs ffmpeg -- stream pinned at {}", + pin.display() + ); } } } @@ -15129,8 +16652,7 @@ pub(crate) mod tests { // zero differences. #[test] fn a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact() { - const NAME: &str = - "a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact"; + const NAME: &str = "a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact"; if !have_ffmpeg() || !have_aomenc() { eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); return; @@ -15318,8 +16840,7 @@ pub(crate) mod tests { args.insert(1, "--input-bit-depth=10".to_string()); args.insert(1, "--bit-depth=10".to_string()); } - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "{name}: aomenc refused the fixture: {}", @@ -15460,11 +16981,28 @@ pub(crate) mod tests { "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ geq=lum='{geq}',format=yuv420p" ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -15480,20 +17018,37 @@ pub(crate) mod tests { let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", - "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", - "--enable-tx-size-search=0", "--lag-in-frames=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", + "--enable-tx-size-search=0", + "--lag-in-frames=0", // Per-arm overrides go LAST: aomenc keeps the last // occurrence of a repeated --enable-* flag. - "--enable-rect-partitions=1", "--enable-ab-partitions=0", - "--enable-1to4-partitions=1", "--min-partition-size=32", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=1", + "--min-partition-size=32", "--max-partition-size=64", - "--obu", "-o", "-", "-", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -15541,9 +17096,18 @@ pub(crate) mod tests { continue; } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); - assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); - assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit)" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit)" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit)" + ); } horz_proved += horz; vert_proved += vert; @@ -15597,9 +17161,9 @@ pub(crate) mod tests { /// SKIPped), attempts that carried no rectangular var-tx leaf counted /// separately and still required pixel-exact. #[test] - fn real_aomenc_1to4_streams_decode_pixel_exact_and_rect_vartx_leaves_fire_before_a_named_refusal() { - const NAME: &str = - "real_aomenc_1to4_streams_decode_pixel_exact_and_rect_vartx_leaves_fire_before_a_named_refusal"; + fn real_aomenc_1to4_streams_decode_pixel_exact_and_rect_vartx_leaves_fire_before_a_named_refusal() + { + const NAME: &str = "real_aomenc_1to4_streams_decode_pixel_exact_and_rect_vartx_leaves_fire_before_a_named_refusal"; let _gate_lock = lock_gate_counters(); if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); @@ -15637,8 +17201,11 @@ pub(crate) mod tests { // transform SPLITS -- 384x256, per-16-column band motion, // cq 32 (16x32 leaves) and cq 38 (32x16 leaves). let firing = attempt >= 16; - let (width, height) = - if firing { (384usize, 256usize) } else { (192usize, 128usize) }; + let (width, height) = if firing { + (384usize, 256usize) + } else { + (192usize, 128usize) + }; let vertical = attempt % 2 == 1; // lane-vartxsplit r2, MEASURED against the oracle // (`EC_VARTX` histogram, ~40 aomenc runs): at cq 10 this @@ -15688,24 +17255,37 @@ pub(crate) mod tests { // inside this gate's attempt list. "128+90*sin((X+N*3)/6)*sin(Y/2)+50*sin((X*Y)/37)".to_string() } else if vertical { - format!( - "128+60*sin((Y+N*({sp}+9*mod(floor(X/16),2)))/7)+25*sin(X/11)" - ) + format!("128+60*sin((Y+N*({sp}+9*mod(floor(X/16),2)))/7)+25*sin(X/11)") } else { - format!( - "128+60*sin((X+N*({sp}+9*mod(floor(Y/16),2)))/7)+25*sin(Y/11)" - ) + format!("128+60*sin((X+N*({sp}+9*mod(floor(Y/16),2)))/7)+25*sin(Y/11)") }; let duration = frame_count as f64 / 25.0; let source = format!( "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ geq=lum='{geq}',format=yuv420p" ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -15723,22 +17303,44 @@ pub(crate) mod tests { // A rectangular var-tx LEAF needs a block whose max rectangular // transform can split: `--min-partition-size=8` is what lets // aomenc's RD reach one (measured); at 16 it never did. - let min_part = - if firing { "--min-partition-size=8" } else { "--min-partition-size=16" }; + let min_part = if firing { + "--min-partition-size=8" + } else { + "--min-partition-size=16" + }; let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", - "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", "--lag-in-frames=0", // Per-arm overrides go LAST: aomenc keeps the last // occurrence of a repeated --enable-* flag. - "--enable-tx64=1", "--enable-rect-partitions=1", - "--enable-ab-partitions=0", "--enable-1to4-partitions=1", - "--enable-dual-filter=0", "--enable-obmc=0", + "--enable-tx64=1", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=1", + "--enable-dual-filter=0", + "--enable-obmc=0", "--enable-tx-size-search=1", - min_part, "--max-partition-size=64", - "--obu", "-o", "-", "-", + min_part, + "--max-partition-size=64", + "--obu", + "-o", + "-", + "-", ]; let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( @@ -15798,9 +17400,18 @@ pub(crate) mod tests { continue; } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); - assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); - assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit)" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit)" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit)" + ); } leaf_32x16 += h32; leaf_16x32 += v32; @@ -15926,11 +17537,28 @@ pub(crate) mod tests { "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ geq=lum='{geq}',format=yuv420p" ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -15946,25 +17574,43 @@ pub(crate) mod tests { let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", - "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", "--lag-in-frames=0", // Per-arm overrides go LAST: aomenc keeps the last // occurrence of a repeated --enable-* flag. - "--enable-tx64=0", "--enable-rect-partitions=1", - "--enable-ab-partitions=0", "--enable-1to4-partitions=1", + "--enable-tx64=0", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=1", "--enable-tx-size-search=1", - "--enable-dual-filter=0", "--enable-obmc=0", + "--enable-dual-filter=0", + "--enable-obmc=0", // aomenc's min-partition-size bounds the SMALLER side of a // 1:4 strip, so 32x8 needs 8 (memory // aomenc-min-partition-bounds-smaller-side). - "--min-partition-size=8", "--max-partition-size=32", - "--obu", "-o", "-", "-", + "--min-partition-size=8", + "--max-partition-size=32", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -16023,9 +17669,18 @@ pub(crate) mod tests { continue; } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); - assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); - assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit)" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit)" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit)" + ); } proved_32x8 += h; proved_8x32 += v; @@ -16135,11 +17790,28 @@ pub(crate) mod tests { "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ geq=lum='{geq}',format=yuv420p" ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -16155,18 +17827,35 @@ pub(crate) mod tests { let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", - "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", - "--enable-tx-size-search=0", "--lag-in-frames=0", - "--enable-rect-partitions=1", "--enable-ab-partitions=0", - "--enable-1to4-partitions=1", "--min-partition-size=32", + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", + "--enable-tx-size-search=0", + "--lag-in-frames=0", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=1", + "--min-partition-size=32", "--max-partition-size=64", - "--obu", "-o", "-", "-", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -16202,9 +17891,18 @@ pub(crate) mod tests { carried_none += 1; } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); - assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); - assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})" + ); } if hits > 0 { matched += 1; @@ -16277,12 +17975,32 @@ pub(crate) mod tests { "mandelbrot=size={width}x{height}:start_scale={start_scale}:\ end_scale=0.004:end_pts=8:rate=25" ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-vf", "hue=s=0", - "-t", &duration.to_string(), "-pix_fmt", pix_fmt, "-strict", "-1", - "-f", "yuv4mpegpipe", "-strict", "-1", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-vf", + "hue=s=0", + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-strict", + "-1", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -16298,26 +18016,53 @@ pub(crate) mod tests { let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=1", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--lag-in-frames=0", "--auto-alt-ref=0", - "--kf-min-dist=1000", "--kf-max-dist=1000", - "--enable-rect-partitions=0", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--min-partition-size=16", - "--max-partition-size=64", "--enable-tx-size-search=0", - "--enable-order-hint=0", "--enable-warped-motion=0", "--enable-obmc=0", - "--enable-masked-comp=0", "--enable-interintra-comp=0", - "--enable-dist-wtd-comp=0", "--enable-diff-wtd-comp=0", - "--enable-onesided-comp=0", "--enable-interintra-wedge=0", - "--enable-smooth-interintra=0", "--enable-filter-intra=0", - "--enable-smooth-intra=0", "--enable-paeth-intra=0", - "--enable-directional-intra=0", "--enable-angle-delta=0", - "--enable-cdef=0", "--enable-restoration=0", "--enable-palette=0", - "--enable-intrabc=0", "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0", - "--obu", "-o", "-", "-", + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=1", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--lag-in-frames=0", + "--auto-alt-ref=0", + "--kf-min-dist=1000", + "--kf-max-dist=1000", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=16", + "--max-partition-size=64", + "--enable-tx-size-search=0", + "--enable-order-hint=0", + "--enable-warped-motion=0", + "--enable-obmc=0", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-dist-wtd-comp=0", + "--enable-diff-wtd-comp=0", + "--enable-onesided-comp=0", + "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -16350,9 +18095,18 @@ pub(crate) mod tests { carried_none += 1; } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); - assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); - assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})" + ); } if hits > 0 { matched += 1; @@ -16397,7 +18151,10 @@ pub(crate) mod tests { "a_pinned_rect_stream_with_a_64x64_intra_block_in_an_inter_frame_decodes_pixel_exact"; let _gate_lock = lock_gate_counters(); if !have_aomenc() { - eprintln!("SKIP {NAME}: no aomenc/aomdec oracle at {}", aomenc_path().display()); + eprintln!( + "SKIP {NAME}: no aomenc/aomdec oracle at {}", + aomenc_path().display() + ); return; } let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) @@ -16407,7 +18164,10 @@ pub(crate) mod tests { let before = crate::decode::nocfl_uv_mode_hits(); let (frames, hidden) = decode_all_frames_vs_oracle(&stream, NAME); let hits = crate::decode::nocfl_uv_mode_hits() - before; - assert_eq!(frames, 6, "{NAME}: expected 6 decode-order frames ({hidden} hidden)"); + assert_eq!( + frames, 6, + "{NAME}: expected 6 decode-order frames ({hidden} hidden)" + ); assert!( hits > 0, "{NAME}: no 64-axis intra block read the no-CFL uv_mode alphabet -- the fixture no \ @@ -16476,11 +18236,28 @@ pub(crate) mod tests { "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ geq=lum='128+58*sin((X+N*3)/6)+18*sin(Y/23)',format=yuv420p" ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -16496,21 +18273,37 @@ pub(crate) mod tests { let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let tx_arg = format!("--enable-tx-size-search={tx_search}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=34", "--cpu-used=0", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", - "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=34", + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", "--lag-in-frames=0", // Per-arm overrides go LAST (aomenc keeps the last // occurrence of a repeated --enable-* flag). &tx_arg, - "--enable-rect-partitions=1", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--min-partition-size=16", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=16", "--max-partition-size=32", - "--obu", "-o", "-", "-", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -16540,9 +18333,18 @@ pub(crate) mod tests { }; assert_eq!(frames.len(), frame_count); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); - assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); - assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit)" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit)" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit)" + ); } compared += 1; tmv_proved += tmv; @@ -16603,11 +18405,28 @@ pub(crate) mod tests { "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ geq=lum='128+58*sin((X+N*3)/6)+18*sin((Y+N*2)/23)',format=yuv420p" ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -16623,22 +18442,43 @@ pub(crate) mod tests { let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let cq_arg = format!("--cq-level={}", if attempt == 0 { 34 } else { 45 }); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", - "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", - "--enable-rect-partitions=1", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--min-partition-size=16", + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=16", "--max-partition-size=32", // Per-arm/feature overrides go LAST (aomenc keeps the LAST // occurrence of a repeated --enable-* flag). - "--enable-order-hint=1", "--enable-ref-frame-mvs=1", - "--enable-fwd-kf=1", "--fwd-kf-dist=8", "--kf-max-dist=1000", - "--lag-in-frames=16", "--auto-alt-ref=1", "--arnr-maxframes=0", - "--obu", "-o", "-", "-", + "--enable-order-hint=1", + "--enable-ref-frame-mvs=1", + "--enable-fwd-kf=1", + "--fwd-kf-dist=8", + "--kf-max-dist=1000", + "--lag-in-frames=16", + "--auto-alt-ref=1", + "--arnr-maxframes=0", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -16750,11 +18590,28 @@ pub(crate) mod tests { "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ geq=lum='{lum}',format=yuv420p" ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -16771,28 +18628,47 @@ pub(crate) mod tests { let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let tx_arg = format!("--enable-tx-size-search={tx_search}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", - "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", "--lag-in-frames=0", // Per-arm overrides go LAST: aomenc keeps the last // occurrence of a repeated --enable-* flag. &tx_arg, - "--enable-rect-partitions=1", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--min-partition-size=16", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=16", "--max-partition-size=32", - "--obu", "-o", "-", "-", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", String::from_utf8_lossy(&out.stderr) ); let stream = out.stdout; - let before = (decode::rect_inter_tu_hits(), decode::rect_inter_txsplit_hits()); + let before = ( + decode::rect_inter_tu_hits(), + decode::rect_inter_txsplit_hits(), + ); let frames = match decode_stream(&stream) { Err(e) => { let msg = e.to_string(); @@ -16807,7 +18683,10 @@ pub(crate) mod tests { } Ok(frames) => frames, }; - let after = (decode::rect_inter_tu_hits(), decode::rect_inter_txsplit_hits()); + let after = ( + decode::rect_inter_tu_hits(), + decode::rect_inter_txsplit_hits(), + ); let (tu, split) = (after.0 - before.0, after.1 - before.1); let ffmpeg_frames = if bit_depth == 10 { ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) @@ -16831,9 +18710,18 @@ pub(crate) mod tests { continue; } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})"); - assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})"); - assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})" + ); } tu_proved += tu; split_proved += split; @@ -16931,12 +18819,23 @@ pub(crate) mod tests { // (14,3)/(20,3)/(32,9), 10-bit (12,3)/(16,3); the rest of the // eight are non-firing neighbours kept so a schedule that // stops firing shows up as out-of-scope, not as a silent pass. - const HORZ_SCHEDULE: [(u32, u32); 8] = - [(14, 3), (20, 3), (32, 9), (12, 3), (16, 3), (12, 9), (14, 9), (26, 3)]; + const HORZ_SCHEDULE: [(u32, u32); 8] = [ + (14, 3), + (20, 3), + (32, 9), + (12, 3), + (16, 3), + (12, 9), + (14, 9), + (26, 3), + ]; let (cq, sp) = if attempt >= 16 { HORZ_SCHEDULE[(attempt - 16) as usize] } else { - ([12, 14][(attempt % 2) as usize], 3 + ((attempt % 8) / 2) * 3) + ( + [12, 14][(attempt % 2) as usize], + 3 + ((attempt % 8) / 2) * 3, + ) }; let duration = frame_count as f64 / 25.0; let source = if attempt >= 16 { @@ -16950,11 +18849,28 @@ pub(crate) mod tests { geq=lum='128+58*sin((X+N*{sp})/6)+18*sin(Y/23)',format=yuv420p" ) }; - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -16970,20 +18886,38 @@ pub(crate) mod tests { let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", - "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", - "--lag-in-frames=0", "--enable-obmc=0", "--enable-tx-size-search=1", + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", + "--lag-in-frames=0", + "--enable-obmc=0", + "--enable-tx-size-search=1", // Per-arm overrides last (aomenc keeps the LAST occurrence). - "--enable-rect-partitions=0", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--min-partition-size=4", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=4", "--max-partition-size=16", &rect_arg, - "--obu", "-o", "-", "-", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -17040,8 +18974,14 @@ pub(crate) mod tests { "luma frame {i} ({bit_depth}-bit attempt {attempt}, {groups} sub-8x8 \ inter split groups)" ); - assert_eq!(got.u, want.u, "U frame {i} ({bit_depth}-bit attempt {attempt})"); - assert_eq!(got.v, want.v, "V frame {i} ({bit_depth}-bit attempt {attempt})"); + assert_eq!( + got.u, want.u, + "U frame {i} ({bit_depth}-bit attempt {attempt})" + ); + assert_eq!( + got.v, want.v, + "V frame {i} ({bit_depth}-bit attempt {attempt})" + ); } fired += 1; if rect_groups > 0 { @@ -17146,7 +19086,11 @@ pub(crate) mod tests { // every pre-filter frame bit-exact, so the arm is a gate now. let mut obmc_leaf_proved = 0usize; for attempt in 0..32u32 { - let obmc_arg = if attempt >= 16 { "--enable-obmc=1" } else { "--enable-obmc=0" }; + let obmc_arg = if attempt >= 16 { + "--enable-obmc=1" + } else { + "--enable-obmc=0" + }; let attempt = attempt % 16; // Two sources (a translating textured ramp, and testsrc2's // natural motion) x two quantisers x two tx-size-search arms x @@ -17178,11 +19122,28 @@ pub(crate) mod tests { "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ geq=lum='{lum}',format=yuv420p" ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -17199,29 +19160,48 @@ pub(crate) mod tests { let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let tx_arg = format!("--enable-tx-size-search={tx_search}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", - "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", "--lag-in-frames=0", // Per-arm overrides go LAST: aomenc keeps the last // occurrence of a repeated --enable-* flag. &tx_arg, - "--enable-rect-partitions=1", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--min-partition-size=8", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=8", "--max-partition-size=16", obmc_arg, - "--obu", "-o", "-", "-", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", String::from_utf8_lossy(&out.stderr) ); let stream = out.stdout; - let before = (decode::rect_inter_tu_hits(), decode::rect_inter_txsplit_hits()); + let before = ( + decode::rect_inter_tu_hits(), + decode::rect_inter_txsplit_hits(), + ); let before_obmc_leaf = decode::obmc_rect_leaf_hits(); let before_leaf = ( decode::inter_leaf16_horz_hits(), @@ -17242,7 +19222,10 @@ pub(crate) mod tests { } Ok(frames) => frames, }; - let after = (decode::rect_inter_tu_hits(), decode::rect_inter_txsplit_hits()); + let after = ( + decode::rect_inter_tu_hits(), + decode::rect_inter_txsplit_hits(), + ); let (tu, split) = (after.0 - before.0, after.1 - before.1); let obmc_leaf = decode::obmc_rect_leaf_hits() - before_obmc_leaf; let (horz, vert, splits16) = ( @@ -17296,9 +19279,18 @@ pub(crate) mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})"); - assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})"); - assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})" + ); } tu_proved += tu; obmc_leaf_proved += obmc_leaf; @@ -17346,7 +19338,6 @@ pub(crate) mod tests { ); } - #[test] // lane-inter16ab r1: the 16x16-level AB partitions on an INTER frame -- // PARTITION_HORZ_A/_HORZ_B/_VERT_A/_VERT_B at 16x16, i.e. two 8x8 inter @@ -17426,11 +19417,28 @@ pub(crate) mod tests { "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ geq=lum='{lum}',format=yuv420p" ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -17448,21 +19456,39 @@ pub(crate) mod tests { let tx_arg = format!("--enable-tx-size-search={tx_search}"); let tile_arg = format!("--tile-columns={tile_cols}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", - "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", - "--lag-in-frames=0", "--kf-max-dist=9999", &tile_arg, + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", + "--lag-in-frames=0", + "--kf-max-dist=9999", + &tile_arg, // Per-arm overrides go LAST: aomenc keeps the last // occurrence of a repeated --enable-* flag. &tx_arg, - "--enable-rect-partitions=1", "--enable-ab-partitions=1", - "--enable-1to4-partitions=0", "--min-partition-size=8", + "--enable-rect-partitions=1", + "--enable-ab-partitions=1", + "--enable-1to4-partitions=0", + "--min-partition-size=8", "--max-partition-size=16", - "--obu", "-o", "-", "-", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -17485,8 +19511,7 @@ pub(crate) mod tests { Ok(frames) => frames, }; let after = decode::ab16_inter_hits_by_arm(); - let fired: Vec = - (0..4).map(|a| after[a] - before[a]).collect(); + let fired: Vec = (0..4).map(|a| after[a] - before[a]).collect(); let ffmpeg_frames = if bit_depth == 10 { ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) } else { @@ -17510,8 +19535,9 @@ pub(crate) mod tests { } if mismatched { for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - let bad: Vec = - (0..got.y.len()).filter(|&k| got.y[k] != want.y[k]).collect(); + let bad: Vec = (0..got.y.len()) + .filter(|&k| got.y[k] != want.y[k]) + .collect(); if !bad.is_empty() { eprintln!( "{NAME}: attempt {attempt} {bit_depth}-bit frame {i}: {} luma \ @@ -17528,9 +19554,18 @@ pub(crate) mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); - assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); - assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})" + ); } for a in 0..4 { if fired[a] > 0 { @@ -17559,8 +19594,6 @@ pub(crate) mod tests { ); } - - #[test] // lane-inter16ab r2: the 16x16-level 1:4 partitions on an INTER frame -- // PARTITION_HORZ_A/_HORZ_B/_VERT_A/_VERT_B at 16x16, i.e. two 8x8 inter @@ -17654,11 +19687,28 @@ pub(crate) mod tests { "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ geq=lum='{lum}',format=yuv420p" ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -17676,21 +19726,39 @@ pub(crate) mod tests { let tx_arg = format!("--enable-tx-size-search={tx_search}"); let tile_arg = format!("--tile-columns={tile_cols}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", - "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", - "--lag-in-frames=0", "--kf-max-dist=9999", &tile_arg, + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", + "--lag-in-frames=0", + "--kf-max-dist=9999", + &tile_arg, // Per-arm overrides go LAST: aomenc keeps the last // occurrence of a repeated --enable-* flag. &tx_arg, - "--enable-rect-partitions=1", "--enable-ab-partitions=1", - "--enable-1to4-partitions=1", "--min-partition-size=4", + "--enable-rect-partitions=1", + "--enable-ab-partitions=1", + "--enable-1to4-partitions=1", + "--min-partition-size=4", "--max-partition-size=16", - "--obu", "-o", "-", "-", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -17762,8 +19830,9 @@ pub(crate) mod tests { } if mismatched { for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - let bad: Vec = - (0..got.y.len()).filter(|&k| got.y[k] != want.y[k]).collect(); + let bad: Vec = (0..got.y.len()) + .filter(|&k| got.y[k] != want.y[k]) + .collect(); if !bad.is_empty() { eprintln!( "{NAME}: attempt {attempt} {bit_depth}-bit frame {i}: {} luma \ @@ -17780,9 +19849,18 @@ pub(crate) mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); - assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); - assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})" + ); } for a in 0..5 { if fired[a] > 0 { @@ -17882,7 +19960,6 @@ pub(crate) mod tests { ); } - #[test] // Un-ignored 2026-09-04: the intra 16x4/4x16-in-inter refusal this recipe stopped at is gone and every arm now decodes pixel-exact. // lane-intra16x4 r1: an INTRA-coded 16x4 / 4x16 strip inside an INTER @@ -17902,9 +19979,9 @@ pub(crate) mod tests { // predict -- a per-frame-random bright bar sweeping the frame (HORZ_4 // strips) and a `X*Y` product sinusoid under temporal noise (VERT_4). // Both sources hash identically twice (report). - fn a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact() { - const NAME: &str = - "a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact"; + fn a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact() + { + const NAME: &str = "a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact"; let _gate_lock = lock_gate_counters(); if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); @@ -17988,11 +20065,28 @@ pub(crate) mod tests { "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ geq=lum='{lum}',format=yuv420p{noise}" ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -18009,21 +20103,40 @@ pub(crate) mod tests { let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", - "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", - "--lag-in-frames=0", "--kf-max-dist=9999", "--tile-columns=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", + "--lag-in-frames=0", + "--kf-max-dist=9999", + "--tile-columns=0", // Per-arm overrides go LAST (aomenc keeps the last // occurrence of a repeated --enable-* flag). - "--enable-tx-size-search=1", "--enable-rect-partitions=1", - "--enable-ab-partitions=1", "--enable-1to4-partitions=1", + "--enable-tx-size-search=1", + "--enable-rect-partitions=1", + "--enable-ab-partitions=1", + "--enable-1to4-partitions=1", "--enable-intra-edge-filter=1", - &min_part_arg, "--max-partition-size=16", - "--obu", "-o", "-", "-", + &min_part_arg, + "--max-partition-size=16", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -18090,8 +20203,9 @@ pub(crate) mod tests { } if mismatched { for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - let bad: Vec = - (0..got.y.len()).filter(|&k| got.y[k] != want.y[k]).collect(); + let bad: Vec = (0..got.y.len()) + .filter(|&k| got.y[k] != want.y[k]) + .collect(); if !bad.is_empty() { eprintln!( "{NAME}: attempt {attempt} {bit_depth}-bit frame {i}: {} luma \ @@ -18168,7 +20282,10 @@ pub(crate) mod tests { ); for (a, what) in [ (0usize, "intra 16x4 strips (PARTITION_HORZ_4)"), - (2, "chroma-reference (odd) intra strips carrying the pair's 8x4/4x8 chroma"), + ( + 2, + "chroma-reference (odd) intra strips carrying the pair's 8x4/4x8 chroma", + ), ] { assert!( arms_total[a] > 0, @@ -18178,7 +20295,6 @@ pub(crate) mod tests { } } - #[test] // lane-sbab r1: the SUPERBLOCK-level (64x64) AB partitions on an INTER // frame -- PARTITION_HORZ_A/_HORZ_B/_VERT_A/_VERT_B at 64x64, i.e. two @@ -18245,11 +20361,28 @@ pub(crate) mod tests { "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ geq=lum='{lum}',format=yuv420p" ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -18266,20 +20399,38 @@ pub(crate) mod tests { let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let tile_arg = format!("--tile-columns={tile_cols}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", - "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, - "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", - "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", - "--lag-in-frames=0", "--kf-max-dist=9999", &tile_arg, + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", + "--lag-in-frames=0", + "--kf-max-dist=9999", + &tile_arg, // Per-arm overrides go LAST: aomenc keeps the last // occurrence of a repeated --enable-* flag. - "--enable-rect-partitions=1", "--enable-ab-partitions=1", - "--enable-1to4-partitions=0", "--min-partition-size=32", + "--enable-rect-partitions=1", + "--enable-ab-partitions=1", + "--enable-1to4-partitions=0", + "--min-partition-size=32", "--max-partition-size=64", - "--obu", "-o", "-", "-", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -18326,8 +20477,9 @@ pub(crate) mod tests { } if mismatched { for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - let bad: Vec = - (0..got.y.len()).filter(|&k| got.y[k] != want.y[k]).collect(); + let bad: Vec = (0..got.y.len()) + .filter(|&k| got.y[k] != want.y[k]) + .collect(); if !bad.is_empty() { eprintln!( "{NAME}: attempt {attempt} {bit_depth}-bit frame {i}: {} luma \ @@ -18344,9 +20496,18 @@ pub(crate) mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); - assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); - assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})" + ); } for a in 0..4 { if fired[a] > 0 { @@ -18395,13 +20556,7 @@ pub(crate) mod tests { let y4m = Command::new("ffmpeg") .args(["-v", "error", "-f", "lavfi", "-i"]) .arg(&source) - .args([ - "-pix_fmt", - "yuv420p", - "-f", - "yuv4mpegpipe", - "-", - ]) + .args(["-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-"]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -18412,8 +20567,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ // lane-defon r1: explicit on-value (aomenc keeps the FIRST // occurrence, so overrides go before the base list). "--loopfilter-control=1", @@ -18465,7 +20620,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -18500,7 +20657,10 @@ pub(crate) mod tests { if !ok { let pin = std::env::temp_dir().join("ec-av1-deblocking-gate-fail.obu"); let _ = std::fs::write(&pin, &stream); - panic!("frame {i} mismatch vs ffmpeg -- stream pinned at {}", pin.display()); + panic!( + "frame {i} mismatch vs ffmpeg -- stream pinned at {}", + pin.display() + ); } } } @@ -18587,8 +20747,8 @@ pub(crate) mod tests { "y4m fixture length mismatch (seed {seed})" ); let y4m_hash = fnv1a64(&y4m.stdout); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -18651,7 +20811,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -18914,8 +21076,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -18992,7 +21154,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -19176,8 +21340,7 @@ pub(crate) mod tests { let tail = args.split_off(args.len() - 3); args.extend_from_slice(extra_args); args.extend_from_slice(&tail); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -19369,8 +21532,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -19432,32 +21594,41 @@ pub(crate) mod tests { .zip(&ffmpeg_frames) .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); if mismatched { - let pin = std::env::temp_dir().join("ec-av1-reference-select-gate-fail.obu"); + let pin = + std::env::temp_dir().join("ec-av1-reference-select-gate-fail.obu"); let _ = std::fs::write(&pin, &stream); if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { std::fs::write(&path, &stream).expect("writing pinned stream"); - eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); + eprintln!( + "EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}" + ); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { assert_eq!( - got.y, want.y, + got.y, + want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed}) -- stream pinned at {}", pin.display() ); assert_eq!( - got.u, want.u, + got.u, + want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed}) -- stream pinned at {}", pin.display() ); assert_eq!( - got.v, want.v, + got.v, + want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed}) -- stream pinned at {}", pin.display() ); } } else { for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -19475,7 +21646,8 @@ pub(crate) mod tests { // libaom's temporal alt-ref filter absorbs this recipe's hidden // frames, so the compare above is vacuous -- re-encode the same // fixture with --arnr-maxframes=0 and compare THOSE. - if let Some((arm_total, arm_hidden)) = hidden_arnr_arm(NAME, &y4m.stdout, &args) { + if let Some((arm_total, arm_hidden)) = hidden_arnr_arm(NAME, &y4m.stdout, &args) + { eprintln!( "{NAME} HIDDEN-ARM(--arnr-maxframes=0): seed {seed}: {arm_total} \ decode-order frames, {arm_hidden} hidden, all pixel-exact vs the oracle" @@ -19599,8 +21771,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -19642,17 +21813,20 @@ pub(crate) mod tests { } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { assert_eq!( - got.y, want.y, + got.y, + want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed}) -- stream pinned at {}", pin.display() ); assert_eq!( - got.u, want.u, + got.u, + want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed}) -- stream pinned at {}", pin.display() ); assert_eq!( - got.v, want.v, + got.v, + want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed}) -- stream pinned at {}", pin.display() ); @@ -19789,8 +21963,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -19830,7 +22003,10 @@ pub(crate) mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -19992,8 +22168,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -20035,7 +22210,10 @@ pub(crate) mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -20178,8 +22356,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -20215,7 +22392,10 @@ pub(crate) mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -20335,8 +22515,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -20346,8 +22525,7 @@ pub(crate) mod tests { if let Ok(path) = std::env::var("EC_SUPERRES_STREAM_DUMP") { std::fs::write(path, &stream).expect("dump stream"); } - let frames = - decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}")); + let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}")); assert_eq!(frames.len(), frame_count); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { @@ -20469,8 +22647,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -20480,8 +22657,7 @@ pub(crate) mod tests { if let Ok(path) = std::env::var("EC_SUPERRES_INTER_STREAM_DUMP") { std::fs::write(&path, &stream).expect("dump stream"); } - let frames = - decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}")); + let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}")); assert_eq!(frames.len(), frame_count); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { @@ -20538,12 +22714,27 @@ pub(crate) mod tests { // off, so a mismatch can only be the lifted paths (the same scoping // the r10 key+inter superres gate uses). let common: [&str; 21] = [ - "--codec=av1", "--passes=1", "--end-usage=q", "--threads=1", "--row-mt=0", - "--kf-max-dist=9999", "--lag-in-frames=0", "--auto-alt-ref=0", "--cpu-used=0", - "--sb-size=64", "--superres-mode=1", "--superres-denominator=12", - "--superres-kf-denominator=12", "--enable-obmc=0", "--enable-masked-comp=0", - "--enable-interintra-comp=0", "--enable-tx-size-search=0", "--enable-cdef=0", - "--enable-restoration=0", "--enable-palette=0", "--enable-intrabc=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--threads=1", + "--row-mt=0", + "--kf-max-dist=9999", + "--lag-in-frames=0", + "--auto-alt-ref=0", + "--cpu-used=0", + "--sb-size=64", + "--superres-mode=1", + "--superres-denominator=12", + "--superres-kf-denominator=12", + "--enable-obmc=0", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--enable-palette=0", + "--enable-intrabc=0", ]; struct Arm { name: &'static str, @@ -20581,8 +22772,21 @@ pub(crate) mod tests { let src = format!("mandelbrot=size={width}x{height}:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &src, "-t", &duration, "-pix_fmt", - "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &src, + "-t", + &duration, + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -20596,8 +22800,7 @@ pub(crate) mod tests { args.push(arm.cq); args.extend_from_slice(&arm.extra); args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME} {}: aomenc refused the recipe: {}", @@ -20613,7 +22816,11 @@ pub(crate) mod tests { assert_eq!(frames.len(), arm.frames, "{NAME} {}", arm.name); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, arm.frames); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} {} frame {i} luma vs ffmpeg", arm.name); + assert_eq!( + got.y, want.y, + "{NAME} {} frame {i} luma vs ffmpeg", + arm.name + ); assert_eq!(got.u, want.u, "{NAME} {} frame {i} U vs ffmpeg", arm.name); assert_eq!(got.v, want.v, "{NAME} {} frame {i} V vs ffmpeg", arm.name); } @@ -20628,7 +22835,11 @@ pub(crate) mod tests { arm.name, arm.frames ); if arm.name == "sub8+leaf8" { - assert!(leaf8 > 0 && sub8 > 0, "{NAME} {}: the lifted paths never ran (leaf8={leaf8} sub8={sub8})", arm.name); + assert!( + leaf8 > 0 && sub8 > 0, + "{NAME} {}: the lifted paths never ran (leaf8={leaf8} sub8={sub8})", + arm.name + ); } else { assert!( warp > 0, @@ -20743,8 +22954,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -20785,7 +22995,10 @@ pub(crate) mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -20823,8 +23036,7 @@ pub(crate) mod tests { "--min-partition-size=8", "--max-partition-size=64", ]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&rect_args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&rect_args), &y4m.stdout); assert!( out.status.success(), "{NAME} RECT-ARM: aomenc refused its own recipe plus the rect overrides: {}", @@ -20895,9 +23107,9 @@ pub(crate) mod tests { /// naming a scaled reference is a hard failure: those are exactly the /// strings this round lifts. Other named capabilities skip that seed. #[test] - fn a_real_aomenc_superres_stream_with_compound_obmc_and_interintra_decodes_pixel_exact() - { - const NAME: &str = "a_real_aomenc_superres_stream_with_compound_obmc_and_interintra_decodes_pixel_exact"; + fn a_real_aomenc_superres_stream_with_compound_obmc_and_interintra_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_superres_stream_with_compound_obmc_and_interintra_decodes_pixel_exact"; let _gate_lock = lock_gate_counters(); if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); @@ -20921,8 +23133,17 @@ pub(crate) mod tests { gradients_source(seed, width, height, &format!("duration={duration}:rate=25")); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -20935,7 +23156,11 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let on = |name: &str| { - if std::env::var(name).as_deref() == Ok("0") { "0" } else { "1" } + if std::env::var(name).as_deref() == Ok("0") { + "0" + } else { + "1" + } }; // lane-scaledref r2: warp is ON. A warp-capable frame header // under a scaled reference is exactly the case r1 got wrong @@ -20957,7 +23182,11 @@ pub(crate) mod tests { let interintra = format!("--enable-interintra-comp={}", on("EC_SCALEDREF_II")); let lag = format!( "--lag-in-frames={}", - if on("EC_SCALEDREF_COMP") == "0" { "0" } else { "25" } + if on("EC_SCALEDREF_COMP") == "0" { + "0" + } else { + "25" + } ); let alt_ref = format!("--auto-alt-ref={}", on("EC_SCALEDREF_COMP")); let args: Vec<&str> = vec![ @@ -21018,8 +23247,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -21057,7 +23285,10 @@ pub(crate) mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -21099,11 +23330,23 @@ pub(crate) mod tests { suppressed by a scaled reference -- the warp arm proves nothing" ); for (hits, what) in [ - (crate::decode::scaled_compound_hits(), "compound with a scaled reference"), - (crate::decode::scaled_obmc_hits(), "OBMC with a scaled reference"), - (crate::decode::scaled_interintra_hits(), "interintra with a scaled reference"), + ( + crate::decode::scaled_compound_hits(), + "compound with a scaled reference", + ), + ( + crate::decode::scaled_obmc_hits(), + "OBMC with a scaled reference", + ), + ( + crate::decode::scaled_interintra_hits(), + "interintra with a scaled reference", + ), ] { - assert!(hits > 0, "{NAME}: {matched} matches but zero blocks took {what}"); + assert!( + hits > 0, + "{NAME}: {matched} matches but zero blocks took {what}" + ); } } @@ -21173,7 +23416,10 @@ pub(crate) mod tests { "--enable-ref-frame-mvs=0", ], &[42, 43, 44, 45, 46, 47, 48, 49], - &[("uni_comp_hits", crate::decode::uni_comp_hits as fn() -> usize)], + &[( + "uni_comp_hits", + crate::decode::uni_comp_hits as fn() -> usize, + )], ); } @@ -21239,7 +23485,10 @@ pub(crate) mod tests { &[42, 43, 44, 45, 46, 47, 48, 49], &[ ("wii_hits", crate::decode::wii_hits as fn() -> usize), - ("interintra_hits", crate::decode::interintra_hits as fn() -> usize), + ( + "interintra_hits", + crate::decode::interintra_hits as fn() -> usize, + ), ], ); } @@ -21354,8 +23603,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -21391,7 +23639,10 @@ pub(crate) mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -21502,9 +23753,14 @@ pub(crate) mod tests { "mandelbrot=size=96x96:rate=25,rotate=a=0.12*t:c=black,\ scale=w='ceil(96*(1+0.03*n)/2)*2':h=96:eval=frame,crop={width}:{height}" ); - let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; - let mut ff_args: Vec<&str> = - vec!["-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", pix_fmt]; + let pix_fmt = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; + let mut ff_args: Vec<&str> = vec![ + "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", pix_fmt, + ]; // y4m has no official 10-bit tag, same as the 10-bit gate above. if depth == 10 { ff_args.extend(["-strict", "-1"]); @@ -21596,7 +23852,9 @@ pub(crate) mod tests { "{NAME} ({depth}-bit): decoded pixel-exact but no block was predicted through a \ 6-parameter global-motion warp -- the AFFINE path is unexercised" ); - eprintln!("{NAME}: {depth}-bit, {frame_count} frames pixel-exact, affine_gm_hits={hits}"); + eprintln!( + "{NAME}: {depth}-bit, {frame_count} frames pixel-exact, affine_gm_hits={hits}" + ); } } @@ -21690,7 +23948,9 @@ pub(crate) mod tests { assert_eq!(ours.u, reference.u, "{NAME} frame {i} U vs ffmpeg"); assert_eq!(ours.v, reference.v, "{NAME} frame {i} V vs ffmpeg"); } - eprintln!("{NAME}: {FRAMES} frames pixel-exact vs ffmpeg, rotzoom_gm_warp_hits={delta_rotzoom}"); + eprintln!( + "{NAME}: {FRAMES} frames pixel-exact vs ffmpeg, rotzoom_gm_warp_hits={delta_rotzoom}" + ); } /// lane-gmaffine r1: the two 8x8-LEAF motion gates. `decode_inter_block8` @@ -21708,11 +23968,7 @@ pub(crate) mod tests { /// motion the encoder can actually model), and the hit counters /// (`globalmv_hits_8` / `warp_hits_8`) are 8x8-leaf-specific: a /// 16x16-leaf GLOBALMV or warp cannot satisfy them. - fn run_8x8_leaf_motion_gate( - name: &str, - global_motion: bool, - counter: fn() -> usize, - ) { + fn run_8x8_leaf_motion_gate(name: &str, global_motion: bool, counter: fn() -> usize) { // 72x64: `decode_inter_block8` is reached ONLY through the // true-edge-straddling 16x16 path (an interior 16x16 // PARTITION_SPLIT is still refused by name), so the frame is 8 @@ -21732,134 +23988,140 @@ pub(crate) mod tests { let mut fired_any = [false; 2]; let mut notes: Vec = Vec::new(); for (di, depth) in [8u32, 10u32].into_iter().enumerate() { - for cq in [32u32, 45, 55] { - let cq_arg = format!("--cq-level={cq}"); - let max_part_arg = format!( - "--max-partition-size={}", - std::env::var("EC_8X8_MAXPART").unwrap_or_else(|_| "8".into()) - ); - let source = format!( - "mandelbrot=size=96x96:rate=25,rotate=a=0.12*t:c=black,\ + for cq in [32u32, 45, 55] { + let cq_arg = format!("--cq-level={cq}"); + let max_part_arg = format!( + "--max-partition-size={}", + std::env::var("EC_8X8_MAXPART").unwrap_or_else(|_| "8".into()) + ); + let source = format!( + "mandelbrot=size=96x96:rate=25,rotate=a=0.12*t:c=black,\ scale=w='ceil(96*(1+0.03*n)/2)*2':h=96:eval=frame,crop={width}:{height}" - ); - let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; - let mut ff_args: Vec<&str> = - vec!["-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", pix_fmt]; - if depth == 10 { - ff_args.extend(["-strict", "-1"]); - } - let duration_arg = duration.to_string(); - ff_args.extend(["-t", &duration_arg, "-f", "yuv4mpegpipe", "-"]); - let y4m = Command::new("ffmpeg") - .args(&ff_args) - .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .output() - .expect("ffmpeg failed to run"); - assert!( - y4m.status.success(), - "ffmpeg fixture: {}", - String::from_utf8_lossy(&y4m.stderr) - ); - let bit_depth = format!("--bit-depth={depth}"); - let input_bit_depth = format!("--input-bit-depth={depth}"); - let gm_arg = format!("--enable-global-motion={}", u8::from(global_motion)); - let warp_arg = format!("--enable-warped-motion={}", u8::from(!global_motion)); - let args: Vec<&str> = vec![ - "--codec=av1", - "--passes=1", - "--end-usage=q", - &cq_arg, - "--cpu-used=0", - "--kf-max-dist=1000", - "--threads=1", - "--row-mt=0", - "--auto-alt-ref=0", - "--lag-in-frames=0", - "--enable-fwd-kf=0", - "--enable-order-hint=1", - &gm_arg, - &warp_arg, - "--enable-obmc=0", - "--tune-content=default", - "--enable-masked-comp=0", - "--enable-interintra-comp=0", - "--enable-onesided-comp=0", - "--enable-rect-partitions=0", - "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", - "--enable-filter-intra=0", - "--enable-smooth-intra=0", - "--enable-paeth-intra=0", - "--enable-directional-intra=0", - "--enable-angle-delta=0", - "--enable-tx-size-search=0", - "--enable-cdef=0", - "--enable-restoration=0", - &max_part_arg, - "--min-partition-size=8", - "--enable-palette=0", - "--enable-intrabc=0", - "--enable-cfl-intra=0", - "--enable-ref-frame-mvs=0", - &bit_depth, - &input_bit_depth, - "--obu", - "-o", - "-", - "-", - ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); - assert!( - out.status.success(), - "aomenc refused the fixture: {}", - String::from_utf8_lossy(&out.stderr) - ); - let stream = out.stdout; - let before = counter(); - let frames = match decode_stream(&stream) { - Ok(f) => f, - Err(e) => { - let msg = e.to_string(); - assert!( - msg.contains("unsupported"), - "{name} ({depth}-bit, cq {cq}) failed outright: {msg}" - ); - notes.push(format!("{depth}-bit cq {cq}: {msg}")); + ); + let pix_fmt = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; + let mut ff_args: Vec<&str> = vec![ + "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", pix_fmt, + ]; + if depth == 10 { + ff_args.extend(["-strict", "-1"]); + } + let duration_arg = duration.to_string(); + ff_args.extend(["-t", &duration_arg, "-f", "yuv4mpegpipe", "-"]); + let y4m = Command::new("ffmpeg") + .args(&ff_args) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let bit_depth = format!("--bit-depth={depth}"); + let input_bit_depth = format!("--input-bit-depth={depth}"); + let gm_arg = format!("--enable-global-motion={}", u8::from(global_motion)); + let warp_arg = format!("--enable-warped-motion={}", u8::from(!global_motion)); + let args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--kf-max-dist=1000", + "--threads=1", + "--row-mt=0", + "--auto-alt-ref=0", + "--lag-in-frames=0", + "--enable-fwd-kf=0", + "--enable-order-hint=1", + &gm_arg, + &warp_arg, + "--enable-obmc=0", + "--tune-content=default", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-onesided-comp=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", + "--enable-restoration=0", + &max_part_arg, + "--min-partition-size=8", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + &bit_depth, + &input_bit_depth, + "--obu", + "-o", + "-", + "-", + ]; + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = counter(); + let frames = match decode_stream(&stream) { + Ok(f) => f, + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{name} ({depth}-bit, cq {cq}) failed outright: {msg}" + ); + notes.push(format!("{depth}-bit cq {cq}: {msg}")); + continue; + } + }; + let ffmpeg_frames = if depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) + } else { + ffmpeg_decode_sequence(&stream, width, height, frame_count) + }; + assert_eq!(frames.len(), frame_count); + let hits = counter() - before; + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "{name} {depth}-bit frame {i} luma vs ffmpeg"); + assert_eq!(got.u, want.u, "{name} {depth}-bit frame {i} U vs ffmpeg"); + assert_eq!(got.v, want.v, "{name} {depth}-bit frame {i} V vs ffmpeg"); + } + if hits == 0 { + notes.push(format!( + "{depth}-bit cq {cq}: {frame_count} frames pixel-exact but 0 8x8-leaf hits" + )); continue; } - }; - let ffmpeg_frames = if depth == 10 { - ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) - } else { - ffmpeg_decode_sequence(&stream, width, height, frame_count) - }; - assert_eq!(frames.len(), frame_count); - let hits = counter() - before; - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{name} {depth}-bit frame {i} luma vs ffmpeg"); - assert_eq!(got.u, want.u, "{name} {depth}-bit frame {i} U vs ffmpeg"); - assert_eq!(got.v, want.v, "{name} {depth}-bit frame {i} V vs ffmpeg"); - } - if hits == 0 { - notes.push(format!( - "{depth}-bit cq {cq}: {frame_count} frames pixel-exact but 0 8x8-leaf hits" - )); - continue; + fired_any[di] = true; + eprintln!( + "{name}: {depth}-bit cq {cq}, {frame_count} frames pixel-exact, 8x8 hits={hits}" + ); } - fired_any[di] = true; - eprintln!( - "{name}: {depth}-bit cq {cq}, {frame_count} frames pixel-exact, 8x8 hits={hits}" - ); - } } assert!( fired_any[0] && fired_any[1], "{name}: no attempt both decoded pixel-exact and fired the 8x8 leaf \ (8-bit fired {}, 10-bit fired {}):\n{}", - fired_any[0], fired_any[1], notes.join("\n") + fired_any[0], + fired_any[1], + notes.join("\n") ); } @@ -21955,8 +24217,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--threads=1", "--row-mt=0", "--sb-size=64", @@ -21968,7 +24230,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -22063,10 +24327,14 @@ pub(crate) mod tests { .stderr(Stdio::piped()) .output() .expect("ffmpeg failed to run"); - assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); let encode = || { - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -22092,7 +24360,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -22102,7 +24372,11 @@ pub(crate) mod tests { }; // The fixture rule: an encoder output is only a pin if it reproduces. let stream = encode(); - assert_eq!(stream, encode(), "{NAME}: aomenc output is not reproducible for this recipe"); + assert_eq!( + stream, + encode(), + "{NAME}: aomenc output is not reproducible for this recipe" + ); let before = crate::decode::rect_leaf_coeff_hits(); let frames = decode_stream(&stream) .unwrap_or_else(|e| panic!("{NAME}: decode failed, not a pixel mismatch: {e}")); @@ -22114,9 +24388,16 @@ pub(crate) mod tests { ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len()); assert_eq!(frames.len(), 1, "{NAME}: expected one key frame"); - assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count"); + assert_eq!( + ffmpeg_frames.len(), + frames.len(), + "{NAME}: ffmpeg frame count" + ); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg ({fired} coded rect leaves)"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg ({fired} coded rect leaves)" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg"); } @@ -22139,8 +24420,7 @@ pub(crate) mod tests { /// override again fails the counter as well as the pixels. #[test] fn a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact() { - const NAME: &str = - "a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact"; + const NAME: &str = "a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact"; let _gate_lock = lock_gate_counters(); if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); @@ -22153,16 +24433,32 @@ pub(crate) mod tests { let (width, height) = (64usize, 64usize); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", + "-v", + "error", + "-f", + "lavfi", + "-i", &format!("rgbtestsrc=size={width}x{height}"), - "-pix_fmt", "yuv420p", "-t", "1", "-vframes", "1", "-f", "yuv4mpegpipe", "-", + "-pix_fmt", + "yuv420p", + "-t", + "1", + "-vframes", + "1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() .expect("ffmpeg failed to run"); - assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); // Two swept cells of the r4 sweep that decoded to completion with // WRONG pixels (1714 and 1650 bytes): `--reduced-tx-type-set` and // `--enable-filter-intra` are the two axes that move which block sizes @@ -22170,19 +24466,34 @@ pub(crate) mod tests { let mut total_overrides = 0usize; for (rtx, filter_intra) in [("1", "0"), ("0", "1")] { let encode = || { - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", - "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64", - "--kf-max-dist=0", "--enable-rect-partitions=1", - "--enable-ab-partitions=0", "--enable-1to4-partitions=0", - "--enable-tx-size-search=0", "--enable-cdef=0", + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=32", + "--cpu-used=4", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--kf-max-dist=0", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", "--enable-restoration=0", &format!("--enable-filter-intra={filter_intra}"), &format!("--reduced-tx-type-set={rtx}"), - "--min-partition-size=8", "--max-partition-size=32", - "--obu", "-o", "-", "-", - ]), &y4m.stdout); + "--min-partition-size=8", + "--max-partition-size=32", + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -22205,7 +24516,11 @@ pub(crate) mod tests { let overrides = crate::decode::mode_mi_override_hits() - before; let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len()); assert_eq!(frames.len(), 1, "{NAME}: expected one key frame"); - assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count"); + assert_eq!( + ffmpeg_frames.len(), + frames.len(), + "{NAME}: ffmpeg frame count" + ); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { assert_eq!( got.y, want.y, @@ -22249,7 +24564,7 @@ pub(crate) mod tests { /// on an attempt that decoded AND is pixel-compared. #[test] fn a_real_aomenc_stream_whose_chroma_edge_filter_reads_a_sub16_neighbours_uv_mode_decodes_pixel_exact() - { + { const NAME: &str = "a_real_aomenc_stream_whose_chroma_edge_filter_reads_a_sub16_neighbours_uv_mode_decodes_pixel_exact"; let _gate_lock = lock_gate_counters(); if !have_ffmpeg() { @@ -22265,13 +24580,30 @@ pub(crate) mod tests { // 8-bit arm = the r5 residue cell ("mandfi161"); 10-bit arm = its // twin through the same recipe at `--bit-depth=10`. for depth in [8usize, 10] { - let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", + "-v", + "error", + "-f", + "lavfi", + "-i", &format!("mandelbrot=size={width}x{height}:start_x=-0.6"), - "-pix_fmt", pix, "-strict", "-1", "-t", "1", "-vframes", "1", - "-f", "yuv4mpegpipe", "-", + "-pix_fmt", + pix, + "-strict", + "-1", + "-t", + "1", + "-vframes", + "1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -22284,19 +24616,34 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let encode = || { - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=16", - "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64", - "--kf-max-dist=0", "--enable-rect-partitions=1", - "--enable-ab-partitions=0", "--enable-1to4-partitions=0", - "--enable-tx-size-search=0", "--enable-filter-intra=1", - "--reduced-tx-type-set=1", "--min-partition-size=8", + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=16", + "--cpu-used=4", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--kf-max-dist=0", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-tx-size-search=0", + "--enable-filter-intra=1", + "--reduced-tx-type-set=1", + "--min-partition-size=8", "--max-partition-size=32", &format!("--input-bit-depth={depth}"), &format!("--bit-depth={depth}"), - "--obu", "-o", "-", "-", - ]), &y4m.stdout); + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture (depth={depth}): {}", @@ -22340,10 +24687,21 @@ pub(crate) mod tests { } else { ffmpeg_decode_sequence(&stream, width, height, frames.len()) }; - assert_eq!(frames.len(), 1, "{NAME}: expected one key frame (depth={depth})"); - assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count"); + assert_eq!( + frames.len(), + 1, + "{NAME}: expected one key frame (depth={depth})" + ); + assert_eq!( + ffmpeg_frames.len(), + frames.len(), + "{NAME}: ffmpeg frame count" + ); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (depth={depth})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (depth={depth})" + ); assert_eq!( got.u, want.u, "{NAME} frame {i} U vs ffmpeg (depth={depth}, {cfl_blocks} CFL blocks, \ @@ -22421,16 +24779,33 @@ pub(crate) mod tests { let mut compared = 0usize; let (width, height) = (256usize, 256usize); for depth in [8usize, 10] { - let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", + "-v", + "error", + "-f", + "lavfi", + "-i", &format!( "mandelbrot=size={width}x{height},\ noise=alls=20:allf=t+u:all_seed=7" ), - "-pix_fmt", pix, "-strict", "-1", "-t", "1", "-vframes", "1", - "-f", "yuv4mpegpipe", "-", + "-pix_fmt", + pix, + "-strict", + "-1", + "-t", + "1", + "-vframes", + "1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -22443,20 +24818,36 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let encode = || { - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=52", - "--cpu-used=0", "--threads=1", "--row-mt=0", "--sb-size=128", - "--kf-max-dist=0", "--enable-rect-partitions=1", - "--enable-ab-partitions=0", "--enable-1to4-partitions=1", - "--enable-cfl-intra=1", "--enable-tx-size-search=0", - "--enable-filter-intra=0", "--enable-intra-edge-filter=1", - "--reduced-tx-type-set=1", "--min-partition-size=4", + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=52", + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=128", + "--kf-max-dist=0", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=1", + "--enable-cfl-intra=1", + "--enable-tx-size-search=0", + "--enable-filter-intra=0", + "--enable-intra-edge-filter=1", + "--reduced-tx-type-set=1", + "--min-partition-size=4", "--max-partition-size=32", &format!("--input-bit-depth={depth}"), &format!("--bit-depth={depth}"), - "--obu", "-o", "-", "-", - ]), &y4m.stdout); + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture (depth={depth}): {}", @@ -22492,7 +24883,11 @@ pub(crate) mod tests { } else { ffmpeg_decode_sequence(&stream, width, height, frames.len()) }; - assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count"); + assert_eq!( + ffmpeg_frames.len(), + frames.len(), + "{NAME}: ffmpeg frame count" + ); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { assert_eq!(got.y, want.y, "{NAME} frame {i} luma (depth={depth})"); assert_eq!( @@ -22584,16 +24979,64 @@ pub(crate) mod tests { // in the failing superblock, i.e. a base tile defect this lane // neither introduced nor owns (reproducer pinned in the r1 report). let attempts = [ - Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 22, ten_bit: false, tile_cols: 0, tx_size_search: false }, - Attempt { src: "rgbtestsrc=size=64x64", w: 64, h: 64, cq: 20, ten_bit: false, tile_cols: 0, tx_size_search: false }, - Attempt { src: "rgbtestsrc=size=64x64", w: 64, h: 64, cq: 50, ten_bit: false, tile_cols: 0, tx_size_search: false }, - Attempt { src: "mandelbrot=size=64x64:start_x=-1.0", w: 64, h: 64, cq: 14, ten_bit: false, tile_cols: 0, tx_size_search: false }, + Attempt { + src: "yuvtestsrc=size=64x64", + w: 64, + h: 64, + cq: 22, + ten_bit: false, + tile_cols: 0, + tx_size_search: false, + }, + Attempt { + src: "rgbtestsrc=size=64x64", + w: 64, + h: 64, + cq: 20, + ten_bit: false, + tile_cols: 0, + tx_size_search: false, + }, + Attempt { + src: "rgbtestsrc=size=64x64", + w: 64, + h: 64, + cq: 50, + ten_bit: false, + tile_cols: 0, + tx_size_search: false, + }, + Attempt { + src: "mandelbrot=size=64x64:start_x=-1.0", + w: 64, + h: 64, + cq: 14, + ten_bit: false, + tile_cols: 0, + tx_size_search: false, + }, // 10-bit: the only two cells of the sweep that are exact at this // depth (HORZ_A and VERT_A); the 10-bit HORZ_B/VERT_B cells all // trip the base chroma defect the r1 report pins, so those two // arms are proven 8-bit only. - Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 30, ten_bit: true, tile_cols: 0, tx_size_search: false }, - Attempt { src: "mandelbrot=size=64x64:start_x=0.4", w: 64, h: 64, cq: 30, ten_bit: true, tile_cols: 0, tx_size_search: false }, + Attempt { + src: "yuvtestsrc=size=64x64", + w: 64, + h: 64, + cq: 30, + ten_bit: true, + tile_cols: 0, + tx_size_search: false, + }, + Attempt { + src: "mandelbrot=size=64x64:start_x=0.4", + w: 64, + h: 64, + cq: 30, + ten_bit: true, + tile_cols: 0, + tx_size_search: false, + }, // `--enable-tx-size-search` at aomenc's default: an 8x8 square of // a VERT_A/VERT_B resolves to a 2x2 grid of TX4 units, which is // the reach lookup that had no table row and panicked (r2). These @@ -22602,29 +25045,82 @@ pub(crate) mod tests { // message is tolerated, a panic or a pixel mismatch is not, and // at least one of them must reach a TX4 unit inside a vertical AB // partition. - Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 55, ten_bit: false, tile_cols: 0, tx_size_search: true }, - Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 22, ten_bit: false, tile_cols: 0, tx_size_search: true }, - Attempt { src: "rgbtestsrc=size=64x64", w: 64, h: 64, cq: 20, ten_bit: false, tile_cols: 0, tx_size_search: true }, - Attempt { src: "mandelbrot=size=64x64:start_x=-1.0", w: 64, h: 64, cq: 14, ten_bit: false, tile_cols: 0, tx_size_search: true }, + Attempt { + src: "yuvtestsrc=size=64x64", + w: 64, + h: 64, + cq: 55, + ten_bit: false, + tile_cols: 0, + tx_size_search: true, + }, + Attempt { + src: "yuvtestsrc=size=64x64", + w: 64, + h: 64, + cq: 22, + ten_bit: false, + tile_cols: 0, + tx_size_search: true, + }, + Attempt { + src: "rgbtestsrc=size=64x64", + w: 64, + h: 64, + cq: 20, + ten_bit: false, + tile_cols: 0, + tx_size_search: true, + }, + Attempt { + src: "mandelbrot=size=64x64:start_x=-1.0", + w: 64, + h: 64, + cq: 14, + ten_bit: false, + tile_cols: 0, + tx_size_search: true, + }, ]; let mut arms = [0usize; 4]; let mut compared = 0usize; let mut tx4_reached = 0usize; let mut tx4_compared = 0usize; for a in &attempts { - let desc = - format!("{} cq={} {}bit tiles={}", a.src, a.cq, if a.ten_bit { 10 } else { 8 }, a.tile_cols); + let desc = format!( + "{} cq={} {}bit tiles={}", + a.src, + a.cq, + if a.ten_bit { 10 } else { 8 }, + a.tile_cols + ); let mut ff: Vec = vec![ - "-v".into(), "error".into(), "-f".into(), "lavfi".into(), "-i".into(), a.src.into(), + "-v".into(), + "error".into(), + "-f".into(), + "lavfi".into(), + "-i".into(), + a.src.into(), "-pix_fmt".into(), - if a.ten_bit { "yuv420p10le".into() } else { "yuv420p".into() }, + if a.ten_bit { + "yuv420p10le".into() + } else { + "yuv420p".into() + }, ]; if a.ten_bit { ff.push("-strict".into()); ff.push("-1".into()); } - ff.extend(["-t".into(), "1".into(), "-vframes".into(), "1".into(), - "-f".into(), "yuv4mpegpipe".into(), "-".into()]); + ff.extend([ + "-t".into(), + "1".into(), + "-vframes".into(), + "1".into(), + "-f".into(), + "yuv4mpegpipe".into(), + "-".into(), + ]); let y4m = Command::new("ffmpeg") .args(&ff) .stdin(Stdio::null()) @@ -22632,21 +25128,33 @@ pub(crate) mod tests { .stderr(Stdio::piped()) .output() .expect("ffmpeg failed to run"); - assert!(y4m.status.success(), "ffmpeg fixture {desc}: {}", String::from_utf8_lossy(&y4m.stderr)); + assert!( + y4m.status.success(), + "ffmpeg fixture {desc}: {}", + String::from_utf8_lossy(&y4m.stderr) + ); let encode = || { let mut args: Vec = vec![ - "--codec=av1".into(), "--passes=1".into(), "--end-usage=q".into(), - format!("--cq-level={}", a.cq), "--cpu-used=4".into(), "--threads=1".into(), - "--row-mt=0".into(), "--sb-size=64".into(), "--kf-max-dist=0".into(), + "--codec=av1".into(), + "--passes=1".into(), + "--end-usage=q".into(), + format!("--cq-level={}", a.cq), + "--cpu-used=4".into(), + "--threads=1".into(), + "--row-mt=0".into(), + "--sb-size=64".into(), + "--kf-max-dist=0".into(), "--limit=1".into(), - "--enable-rect-partitions=1".into(), "--enable-ab-partitions=1".into(), + "--enable-rect-partitions=1".into(), + "--enable-ab-partitions=1".into(), "--enable-1to4-partitions=0".into(), format!("--enable-tx-size-search={}", u8::from(a.tx_size_search)), // Filter intra ON a rect strip is a separate, still-refused // predictor; this gate is about the AB partition wiring. "--enable-filter-intra=0".into(), "--reduced-tx-type-set=1".into(), - "--min-partition-size=8".into(), "--max-partition-size=16".into(), + "--min-partition-size=8".into(), + "--max-partition-size=16".into(), format!("--tile-columns={}", a.tile_cols), ]; if a.ten_bit { @@ -22654,14 +25162,24 @@ pub(crate) mod tests { args.push("--bit-depth=10".into()); } args.extend(["--obu".into(), "-o".into(), "-".into(), "-".into()]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); - assert!(out.status.success(), "aomenc refused {desc}: {}", String::from_utf8_lossy(&out.stderr)); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); + assert!( + out.status.success(), + "aomenc refused {desc}: {}", + String::from_utf8_lossy(&out.stderr) + ); out.stdout }; let stream = encode(); - assert!(!stream.is_empty(), "{NAME}: {desc}: aomenc wrote an empty stream"); - assert_eq!(stream, encode(), "{NAME}: {desc}: aomenc output is not reproducible"); + assert!( + !stream.is_empty(), + "{NAME}: {desc}: aomenc wrote an empty stream" + ); + assert_eq!( + stream, + encode(), + "{NAME}: {desc}: aomenc output is not reproducible" + ); let before = crate::decode::ab16_hits_by_arm(); let tx4_before = crate::decode::vert_ab_tx4_hits(); let decoded = decode_stream(&stream); @@ -22692,7 +25210,11 @@ pub(crate) mod tests { } else { ffmpeg_decode_sequence(&stream, a.w, a.h, frames.len()) }; - assert_eq!(want.len(), frames.len(), "{NAME}: {desc}: ffmpeg frame count"); + assert_eq!( + want.len(), + frames.len(), + "{NAME}: {desc}: ffmpeg frame count" + ); for (i, (got, w)) in frames.iter().zip(&want).enumerate() { assert_eq!(got.y, w.y, "{NAME}: {desc} frame {i} luma vs ffmpeg"); assert_eq!(got.u, w.u, "{NAME}: {desc} frame {i} U vs ffmpeg"); @@ -22726,7 +25248,9 @@ pub(crate) mod tests { // counter-from-refused-stream). The full pixel compare is the stronger // claim and replaces it; the lookup's VALUES stay pinned against libaom // in `of_tu_keeps_the_ordinary_answer_and_uses_the_block_row_under_vert_ab`. - eprintln!("{NAME}: vert-AB TX4 units reached across tx-size-search attempts: {tx4_reached}"); + eprintln!( + "{NAME}: vert-AB TX4 units reached across tx-size-search attempts: {tx4_reached}" + ); let _ = tx4_reached; assert_eq!( tx4_compared, @@ -22737,10 +25261,15 @@ pub(crate) mod tests { `of_tu_keeps_the_ordinary_answer_and_uses_the_block_row_under_vert_ab`" ); for (i, arm) in ["HORZ_A", "HORZ_B", "VERT_A", "VERT_B"].iter().enumerate() { - assert!(arms[i] > 0, "{NAME}: PARTITION_{arm} at 16x16 never fired across {compared} \ - compared streams -- the gate proves nothing about that arm (arms={arms:?})"); + assert!( + arms[i] > 0, + "{NAME}: PARTITION_{arm} at 16x16 never fired across {compared} \ + compared streams -- the gate proves nothing about that arm (arms={arms:?})" + ); } - eprintln!("{NAME}: pixel-exact on {compared} streams, ab16 arms(HORZ_A,HORZ_B,VERT_A,VERT_B)={arms:?}"); + eprintln!( + "{NAME}: pixel-exact on {compared} streams, ab16 arms(HORZ_A,HORZ_B,VERT_A,VERT_B)={arms:?}" + ); } #[test] @@ -22761,41 +25290,85 @@ pub(crate) mod tests { for start_x in srcs { let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", + "-v", + "error", + "-f", + "lavfi", + "-i", &start_x, - "-pix_fmt", "yuv420p", "-t", "1", "-vframes", "1", "-f", "yuv4mpegpipe", "-", + "-pix_fmt", + "yuv420p", + "-t", + "1", + "-vframes", + "1", + "-f", + "yuv4mpegpipe", + "-", ]) - .stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped()) - .output().expect("ffmpeg"); + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg"); assert!(y4m.status.success()); - let (width, height) = if start_x.contains("128x128") { (128usize, 128usize) } else { (64usize, 64usize) }; + let (width, height) = if start_x.contains("128x128") { + (128usize, 128usize) + } else { + (64usize, 64usize) + }; for cq in [16u32, 20, 24, 28, 32, 40, 50] { for rtx in ["0", "1"] { - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", "--passes=1", "--end-usage=q", - &format!("--cq-level={cq}"), "--cpu-used=4", "--threads=1", - "--row-mt=0", "--sb-size=64", "--kf-max-dist=0", - "--enable-rect-partitions=1", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--enable-tx-size-search=0", - "--enable-cdef=0", "--enable-restoration=0", + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &format!("--cq-level={cq}"), + "--cpu-used=4", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--kf-max-dist=0", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", + "--enable-restoration=0", &format!("--reduced-tx-type-set={rtx}"), - "--min-partition-size=8", "--max-partition-size=32", - "--obu", "-o", "-", "-", - ]), &y4m.stdout); + "--min-partition-size=8", + "--max-partition-size=32", + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); assert!(out.status.success()); let stream = out.stdout; let before = crate::decode::rect_leaf_coeff_hits(); let res = decode_stream(&stream); let fired = crate::decode::rect_leaf_coeff_hits() - before; match res { - Err(e) => eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} REFUSED {e}"), + Err(e) => { + eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} REFUSED {e}") + } Ok(frames) => { let want = ffmpeg_decode_sequence(&stream, width, height, frames.len()); - let bad = frames.iter().zip(&want) - .filter(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v).count(); - eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} frames={} mismatched={bad}", frames.len()); - if bad == 0 { continue; } + let bad = frames + .iter() + .zip(&want) + .filter(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v) + .count(); + eprintln!( + "x={start_x} cq={cq} rtx={rtx} fired={fired} frames={} mismatched={bad}", + frames.len() + ); + if bad == 0 { + continue; + } let (g, w) = (&frames[0], &want[0]); for br in 0..height / 8 { let mut line = String::new(); @@ -22945,8 +25518,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -22984,7 +25556,10 @@ pub(crate) mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -23151,8 +25726,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -23192,7 +25766,10 @@ pub(crate) mod tests { let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); assert_eq!(frames.len(), frame_count); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -23342,8 +25919,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture (seed {seed}): {}", @@ -23501,7 +26077,11 @@ pub(crate) mod tests { fn run_compound_global_warp_gate(name: &str, bd: u32, min_part: u32, leaf8_assert: bool) { let _gate_lock = lock_gate_counters(); assert!(have_ffmpeg(), "{name}: ffmpeg required"); - assert!(have_aomenc(), "{name}: no aomenc at {}", aomenc_path().display()); + assert!( + have_aomenc(), + "{name}: no aomenc at {}", + aomenc_path().display() + ); let (width, height, frame_count) = (64usize, 64usize, 24usize); let before = crate::decode::compound_warp_hits(); let before8 = crate::decode::compound_warp_hits_8(); @@ -23529,9 +26109,21 @@ pub(crate) mod tests { }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", - &duration.to_string(), "-pix_fmt", pix_fmt, "-strict", "-1", - "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -23544,8 +26136,10 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let cq_arg = format!("--cq-level={cq}"); - let (in_depth_arg, depth_arg) = - (format!("--input-bit-depth={bd}"), format!("--bit-depth={bd}")); + let (in_depth_arg, depth_arg) = ( + format!("--input-bit-depth={bd}"), + format!("--bit-depth={bd}"), + ); let mut args: Vec<&str> = vec![ "--codec=av1", "--passes=1", @@ -23592,14 +26186,10 @@ pub(crate) mod tests { let min_part_arg = format!("--min-partition-size={min_part}"); args.push(min_part_arg.as_str()); if bd != 8 { - args.extend_from_slice(&[ - in_depth_arg.as_str(), - depth_arg.as_str(), - ]); + args.extend_from_slice(&[in_depth_arg.as_str(), depth_arg.as_str()]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -23666,7 +26256,10 @@ pub(crate) mod tests { ({matched} matches, {named_refusals} refusals of {attempts}) -- gate vacuous" ); } - assert!(matched > 0, "{name}: every attempt refused -- no pixel comparison ran"); + assert!( + matched > 0, + "{name}: every attempt refused -- no pixel comparison ran" + ); } /// lane-fimv r1 (class `wrong-alphabet-same-value`): libaom @@ -23691,7 +26284,11 @@ pub(crate) mod tests { fn run_fimv_motion_mode_gate(name: &str, ten_bit: bool) { let _gate_lock = lock_gate_counters(); assert!(have_ffmpeg(), "{name}: ffmpeg required"); - assert!(have_aomenc(), "{name}: no aomenc at {}", aomenc_path().display()); + assert!( + have_aomenc(), + "{name}: no aomenc at {}", + aomenc_path().display() + ); let (width, height, frame_count) = (64usize, 64usize, 20usize); let fimv_frames_before = crate::decode::fimv_frame_hits(); let alphabet_before = crate::decode::fimv_alphabet_hits(); @@ -23723,9 +26320,21 @@ pub(crate) mod tests { let pix_fmt = if ten_bit { "yuv420p10le" } else { "yuv420p" }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", - &duration.to_string(), "-pix_fmt", pix_fmt, "-strict", "-1", - "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -23791,8 +26400,7 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -23828,9 +26436,18 @@ pub(crate) mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (cq {cq}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&want).enumerate() { - assert_eq!(got.y, want.y, "{name} frame {i} luma vs ffmpeg (cq {cq} step {step})"); - assert_eq!(got.u, want.u, "{name} frame {i} U vs ffmpeg (cq {cq} step {step})"); - assert_eq!(got.v, want.v, "{name} frame {i} V vs ffmpeg (cq {cq} step {step})"); + assert_eq!( + got.y, want.y, + "{name} frame {i} luma vs ffmpeg (cq {cq} step {step})" + ); + assert_eq!( + got.u, want.u, + "{name} frame {i} U vs ffmpeg (cq {cq} step {step})" + ); + assert_eq!( + got.v, want.v, + "{name} frame {i} V vs ffmpeg (cq {cq} step {step})" + ); } assert!( crate::decode::fimv_frame_hits() > attempt_fimv_before, @@ -23855,7 +26472,10 @@ pub(crate) mod tests { force_integer_mv frames={fimv_frames}, forced-2-symbol blocks={alphabet}\n{}", refusals.join("\n") ); - assert!(matched > 0, "{name}: every attempt refused -- no pixel comparison ran"); + assert!( + matched > 0, + "{name}: every attempt refused -- no pixel comparison ran" + ); assert!( fimv_frames > 0, "{name}: no decoded frame header had force_integer_mv=1 \ @@ -23872,7 +26492,10 @@ pub(crate) mod tests { /// 8-bit arm of [`run_fimv_motion_mode_gate`]. #[test] fn a_real_force_integer_mv_warp_stream_decodes_pixel_exact() { - run_fimv_motion_mode_gate("a_real_force_integer_mv_warp_stream_decodes_pixel_exact", false); + run_fimv_motion_mode_gate( + "a_real_force_integer_mv_warp_stream_decodes_pixel_exact", + false, + ); } /// 10-bit arm of [`run_fimv_motion_mode_gate`] -- both of his films are @@ -23972,7 +26595,11 @@ pub(crate) mod tests { fn run_diffwtd_inferred_64x64_gate(name: &str, ten_bit: bool) { let _gate_lock = lock_gate_counters(); assert!(have_ffmpeg(), "{name}: ffmpeg required"); - assert!(have_aomenc(), "{name}: no aomenc at {}", aomenc_path().display()); + assert!( + have_aomenc(), + "{name}: no aomenc at {}", + aomenc_path().display() + ); let (width, height, frame_count) = (128usize, 128usize, 16usize); let mut matched = 0u32; let mut named_refusals = 0u32; @@ -23998,9 +26625,21 @@ pub(crate) mod tests { let pix_fmt = if ten_bit { "yuv420p10le" } else { "yuv420p" }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", - &duration.to_string(), "-pix_fmt", pix_fmt, "-strict", "-1", - "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -24066,8 +26705,7 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -24123,7 +26761,10 @@ pub(crate) mod tests { "{name}: {matched}/{attempts} pixel-exact, {named_refusals} named refusals, \ diffwtd_inferred_hits (decoded+compared attempts only)={fired}" ); - assert!(matched > 0, "{name}: every attempt refused ({refusals:?}) -- no pixel compare ran"); + assert!( + matched > 0, + "{name}: every attempt refused ({refusals:?}) -- no pixel compare ran" + ); assert!( fired > 0, "{name}: no inferred-DIFFWTD 64x64 block fired on a compared attempt \ @@ -24274,8 +26915,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -24325,7 +26965,10 @@ pub(crate) mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -24392,7 +27035,6 @@ pub(crate) mod tests { ); } - /// lane-inter16ab r5: `COMPOUND_WEDGE` on a RECTANGULAR inter block -- /// the shapes `av1_wedge_params_lookup` gives the `hgtw`/`hltw` /// codebooks (8x16/16x32/8x32 and 16x8/32x16/32x8), which this decoder @@ -24441,12 +27083,30 @@ pub(crate) mod tests { sx = -0.6 + 0.01 * (a as f64), sy = -0.4 + 0.01 * (a as f64) ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", - &duration.to_string(), "-pix_fmt", pix_fmt, "-strict", "-1", - "-f", "yuv4mpegpipe", "-strict", "-1", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-strict", + "-1", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -24462,20 +27122,41 @@ pub(crate) mod tests { let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", - &depth_arg, &input_depth_arg, - "--kf-max-dist=1000", "--threads=1", "--row-mt=0", "--auto-alt-ref=1", - "--lag-in-frames=16", "--enable-fwd-kf=0", "--enable-order-hint=1", - "--enable-warped-motion=1", "--enable-global-motion=0", - "--enable-obmc=1", "--enable-diff-wtd-comp=1", - "--enable-interintra-comp=1", "--enable-onesided-comp=0", - "--enable-interintra-wedge=1", "--enable-smooth-interintra=1", - "--enable-ab-partitions=0", "--enable-1to4-partitions=0", - "--enable-filter-intra=0", "--enable-smooth-intra=0", - "--enable-paeth-intra=0", "--enable-directional-intra=0", - "--enable-angle-delta=0", "--enable-tx-size-search=0", - "--enable-cdef=0", "--enable-restoration=0", "--enable-palette=0", - "--enable-intrabc=0", "--enable-cfl-intra=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + &depth_arg, + &input_depth_arg, + "--kf-max-dist=1000", + "--threads=1", + "--row-mt=0", + "--auto-alt-ref=1", + "--lag-in-frames=16", + "--enable-fwd-kf=0", + "--enable-order-hint=1", + "--enable-warped-motion=1", + "--enable-global-motion=0", + "--enable-obmc=1", + "--enable-diff-wtd-comp=1", + "--enable-interintra-comp=1", + "--enable-onesided-comp=0", + "--enable-interintra-wedge=1", + "--enable-smooth-interintra=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0", // Per-arm overrides LAST (aomenc keeps the last // occurrence of a repeated --enable-* flag): masked @@ -24483,13 +27164,17 @@ pub(crate) mod tests { // comp_group_idx==1 slot goes to wedge/diffwtd, and // rectangular partitions ON at 16/32 -- the shapes // the hgtw/hltw codebooks exist for. - "--enable-masked-comp=1", "--enable-dist-wtd-comp=0", + "--enable-masked-comp=1", + "--enable-dist-wtd-comp=0", "--enable-rect-partitions=1", - "--min-partition-size=16", "--max-partition-size=32", - "--obu", "-o", "-", "-", + "--min-partition-size=16", + "--max-partition-size=32", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -24517,8 +27202,7 @@ pub(crate) mod tests { Ok(frames) => frames, }; let after = crate::stream::rect_wedge_hits(); - let fired: Vec = - (0..6).map(|k| after[k] - before[k]).collect(); + let fired: Vec = (0..6).map(|k| after[k] - before[k]).collect(); let ffmpeg_frames = if bit_depth == 10 { ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) } else { @@ -24540,9 +27224,18 @@ pub(crate) mod tests { continue; } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg ({bit_depth}-bit cq{cq} attempt {a}, shapes {fired:?})"); - assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg ({bit_depth}-bit cq{cq} attempt {a}, shapes {fired:?})"); - assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg ({bit_depth}-bit cq{cq} attempt {a}, shapes {fired:?})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg ({bit_depth}-bit cq{cq} attempt {a}, shapes {fired:?})" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg ({bit_depth}-bit cq{cq} attempt {a}, shapes {fired:?})" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg ({bit_depth}-bit cq{cq} attempt {a}, shapes {fired:?})" + ); } // class gate-blind-to-hidden-frames: the shown-frame // compare above cannot see the alt-ref frames this @@ -24582,7 +27275,6 @@ pub(crate) mod tests { ); } - /// lane-lr r3: proves stage 1/2's exit criterion -- a real /// `--enable-restoration=1` aomenc stream must survive the whole /// partition walk (every symbol read entropy-exact) and land on the @@ -24644,8 +27336,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -24687,7 +27379,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -24715,9 +27409,18 @@ pub(crate) mod tests { ); } for (i, (pic, refpic)) in pics.iter().zip(reference.iter()).enumerate() { - assert_eq!(pic.y, refpic.y, "{NAME}: luma mismatch (seed {seed} frame {i})"); - assert_eq!(pic.u, refpic.u, "{NAME}: U mismatch (seed {seed} frame {i})"); - assert_eq!(pic.v, refpic.v, "{NAME}: V mismatch (seed {seed} frame {i})"); + assert_eq!( + pic.y, refpic.y, + "{NAME}: luma mismatch (seed {seed} frame {i})" + ); + assert_eq!( + pic.u, refpic.u, + "{NAME}: U mismatch (seed {seed} frame {i})" + ); + assert_eq!( + pic.v, refpic.v, + "{NAME}: V mismatch (seed {seed} frame {i})" + ); } lr_refusals += 1; // reused below as "attempts that actually exercised LR pixels" } @@ -24941,8 +27644,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -24977,7 +27679,10 @@ pub(crate) mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -25083,11 +27788,28 @@ pub(crate) mod tests { // aomenc stop reading after the first one and the // y4m write then dies on a broken pipe. let dur = format!("{}", frames as f64 / 25.0); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &dur, - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &dur, + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -25103,19 +27825,27 @@ pub(crate) mod tests { let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let cq_arg = format!("--cq-level={cq}"); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, // cpu-used >= 1 keeps libaom on 64x64 // superblocks at these sizes // (`av1_select_sb_size`). - "--cpu-used=4", "--threads=1", "--row-mt=0", + "--cpu-used=4", + "--threads=1", + "--row-mt=0", // --lag-in-frames=0: no hidden alt-ref, so // decode order == display order and the // compare below covers every frame the stream // carries (class gate-blind-to-hidden-frames). - kf_arg, limit_arg, "--lag-in-frames=0", - &depth_arg, &input_depth_arg, + kf_arg, + limit_arg, + "--lag-in-frames=0", + &depth_arg, + &input_depth_arg, // Other lanes' named refusals this recipe must // not trip. The both-cut corner is FORCED down // to 8x8 leaves, which is exactly where the @@ -25128,20 +27858,35 @@ pub(crate) mod tests { // inter-frame leaf" and "an 8x8 intra leaf in // an inter frame whose tx_depth splits it into // 4x4 transform units". - "--enable-rect-partitions=0", "--enable-ab-partitions=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", "--enable-1to4-partitions=0", - "--min-partition-size=8", "--max-partition-size=64", - "--enable-palette=0", "--enable-intrabc=0", - "--enable-warped-motion=0", "--enable-obmc=0", - "--enable-masked-comp=0", "--enable-interintra-comp=0", - "--enable-onesided-comp=0", "--enable-interintra-wedge=0", - "--enable-smooth-interintra=0", "--enable-ref-frame-mvs=0", - "--enable-angle-delta=0", "--enable-cfl-intra=0", - "--enable-directional-intra=0", "--enable-smooth-intra=0", - "--enable-paeth-intra=0", "--enable-filter-intra=0", + "--min-partition-size=8", + "--max-partition-size=64", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-warped-motion=0", + "--enable-obmc=0", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-onesided-comp=0", + "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", + "--enable-ref-frame-mvs=0", + "--enable-angle-delta=0", + "--enable-cfl-intra=0", + "--enable-directional-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-filter-intra=0", "--enable-tx-size-search=0", - "--obu", "-o", "-", "-", - ]), &y4m.stdout); + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused: {}", @@ -25190,8 +27935,9 @@ pub(crate) mod tests { frame count" ); for (i, (ours, theirs)) in decoded.iter().zip(&reference).enumerate() { - let nd = - |a: &[u16], b: &[u16]| a.iter().zip(b).filter(|(x, y)| x != y).count(); + let nd = |a: &[u16], b: &[u16]| { + a.iter().zip(b).filter(|(x, y)| x != y).count() + }; // Where a mismatch lands is the whole diagnosis // here (corner block vs elsewhere), so print the // luma bounding box before the assert kills the run. @@ -25200,7 +27946,8 @@ pub(crate) mod tests { (usize::MAX, usize::MAX, 0usize, 0usize); for row in 0..height { for col in 0..width { - if ours.y[row * width + col] != theirs.y[row * width + col] { + if ours.y[row * width + col] != theirs.y[row * width + col] + { r0 = r0.min(row); c0 = c0.min(col); r1 = r1.max(row); @@ -25310,30 +28057,60 @@ pub(crate) mod tests { ); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", "0.04", "-pix_fmt", - "yuv420p", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + "0.04", + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() .expect("ffmpeg failed to run"); - assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); let max_part = width.max(height).min(64).next_power_of_two(); let min_part = width.min(height).next_power_of_two().max(8).min(max_part); let max_part_arg = format!("--max-partition-size={max_part}"); let min_part_arg = format!("--min-partition-size={min_part}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", - "--cpu-used=4", "--kf-max-dist=0", "--limit=1", "--threads=1", - "--row-mt=0", "--enable-rect-partitions=0", "--enable-ab-partitions=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=32", + "--cpu-used=4", + "--kf-max-dist=0", + "--limit=1", + "--threads=1", + "--row-mt=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", "--enable-1to4-partitions=0", - &max_part_arg, &min_part_arg, - "--obu", "-o", "-", "-", + &max_part_arg, + &min_part_arg, + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); - assert!(out.status.success(), "aomenc refused: {}", String::from_utf8_lossy(&out.stderr)); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); + assert!( + out.status.success(), + "aomenc refused: {}", + String::from_utf8_lossy(&out.stderr) + ); let stream = out.stdout; let frames = match decode_stream(&stream) { Err(e) => { @@ -25436,8 +28213,19 @@ pub(crate) mod tests { ); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", "0.04", "-pix_fmt", "yuv420p", - "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + "0.04", + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -25446,15 +28234,27 @@ pub(crate) mod tests { .expect("ffmpeg failed to run"); assert!(y4m.status.success()); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", "--cpu-used=4", - "--kf-max-dist=0", "--limit=1", "--threads=1", "--row-mt=0", - "--enable-rect-partitions=0", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--max-partition-size=32", "--min-partition-size=32", + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=32", + "--cpu-used=4", + "--kf-max-dist=0", + "--limit=1", + "--threads=1", + "--row-mt=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--max-partition-size=32", + "--min-partition-size=32", "--enable-filter-intra=0", - "--obu", "-o", "-", "-", + "--obu", + "-o", + "-", + "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!(out.status.success()); let stream = out.stdout; let frames = decode_stream(&stream).expect("decode"); @@ -25532,9 +28332,9 @@ pub(crate) mod tests { // below it, blending the wrong OBMC prediction there. "rect-flake-3", ] - .iter() - .map(|n| format!("{fixtures}/{n}.obu")) - .collect(), + .iter() + .map(|n| format!("{fixtures}/{n}.obu")) + .collect(), }; for path in paths { eprintln!("pin: {path}"); @@ -25783,8 +28583,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -25910,7 +28709,11 @@ pub(crate) mod tests { "-i", &source, "-pix_fmt", - if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, + if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }, "-strict", "-1", "-t", @@ -26302,8 +29105,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -26334,7 +29137,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); if !out.status.success() { refusals.push(format!( "cq={cq} period={period}: aomenc itself refused the fixture" @@ -26424,16 +29229,39 @@ pub(crate) mod tests { let mut fired = 0u32; let mut cdef_fired = 0u32; let mut leaf_fired = 0u32; - for (depth, cq, sp) in [(8u32, 8u32, 3u32), (8, 10, 3), (8, 12, 6), (10, 8, 3), (10, 12, 6)] { - let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + for (depth, cq, sp) in [ + (8u32, 8u32, 3u32), + (8, 10, 3), + (8, 12, 6), + (10, 8, 3), + (10, 12, 6), + ] { + let pix = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let src = format!( "color=c=gray:s={width}x{height}:d=0.24:r=25,format=gray,\ geq=lum='128+58*sin((X+N*{sp})/6)+18*sin(Y/23)',format=yuv420p" ); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &src, "-t", "0.24", "-pix_fmt", pix, - "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &src, + "-t", + "0.24", + "-pix_fmt", + pix, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -26445,8 +29273,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -26479,7 +29307,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture (depth={depth} cq={cq})" @@ -26589,15 +29419,32 @@ pub(crate) mod tests { (10, 24, src_a), (8, 24, src_a), ] { - let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let src = format!( "color=c=gray:s={width}x{height}:d=0.24:r=25,format=gray,\ geq=lum='{lum}',format=yuv420p" ); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &src, "-t", "0.24", "-pix_fmt", pix, - "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &src, + "-t", + "0.24", + "-pix_fmt", + pix, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -26609,8 +29456,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -26643,7 +29490,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture (depth={depth} cq={cq})" @@ -26730,10 +29579,7 @@ pub(crate) mod tests { return; } if !have_aomenc() { - let msg = format!( - "no aomenc at {}", - aomenc_path().display() - ); + let msg = format!("no aomenc at {}", aomenc_path().display()); assert!( std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(), "EC_AV1_REQUIRE_AOMENC is set but {msg}" @@ -26768,138 +29614,141 @@ pub(crate) mod tests { (128usize, 64usize, &["--tile-columns=1"][..]), (64usize, 128usize, &["--tile-rows=1"][..]), ] { - let mut refusals = Vec::new(); - let mut fired_runs = 0u32; - for attempt in 0..40u32 { - let seed = 100 + attempt; - let cq = 6 + (attempt % 4) * 2; - let y4m = Command::new("ffmpeg") - .args([ - "-v", - "error", - "-f", - "lavfi", - "-i", - &gradients_source(seed, width, height, "rate=25"), - "-vf", - // `noise` without `all_seed` re-renders differently on - // every run (seeded-fixture-not-reproducible); pinning it - // makes (seed, cq) name one exact stream. - &format!("noise=alls=40:allf=t:all_seed={seed},format=yuv420p"), - "-t", - "0.04", - "-f", - "yuv4mpegpipe", - "-", - ]) - .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .output() - .expect("ffmpeg failed to run"); - assert!( - y4m.status.success(), - "ffmpeg fixture: {}", - String::from_utf8_lossy(&y4m.stderr) - ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", - "--passes=1", - "--end-usage=q", - &format!("--cq-level={cq}"), - "--cpu-used=0", - "--threads=1", - "--row-mt=0", - "--sb-size=64", - "--min-partition-size=4", - "--max-partition-size=8", - // Below 8x8 only PARTITION_NONE/SPLIT are decodable (HORZ/VERT - // need a real rectangular transform, see the module doc above); - // disabling rect partitions entirely -- not just AB -- keeps - // aomenc from picking the still-refused HORZ/VERT arms almost - // every attempt (round 2 measured ~90% HORZ/VERT-below-8x8 - // refusals with --enable-ab-partitions=0 alone). - "--enable-rect-partitions=0", - "--enable-ab-partitions=0", - "--enable-1to4-partitions=1", - "--enable-palette=0", - "--enable-intrabc=0", - "--enable-restoration=0", - "--enable-cdef=0", - "--loopfilter-control=0", - // use_ref_frame_mvs (temporal MV projection) is unimplemented in - // mvstack; this is a key-frame-only fixture, but keep it off for - // safety against a run that emits a second frame. - "--enable-ref-frame-mvs=0", - "--limit=1", - "--obu", - "-o", - "-", - "-", - ]) - .args(tile_args), &y4m.stdout); - if !out.status.success() { - refusals.push(format!( - "seed={seed} cq={cq}: aomenc itself refused the fixture" - )); - continue; - } - let stream = out.stdout; - let before = decode::sub8_split_hits(); - let tiles_before = decode::tile_hits(); - let frames = match decode_stream(&stream) { - Ok(frames) => frames, - Err(e) => { - // Only a named refusal ("unsupported: ...") is a skip - // reason; any other decode error is this decoder failing. - let msg = e.to_string(); - assert!( - msg.starts_with("unsupported: "), - "decode error that is not a named refusal \ - (seed={seed} cq={cq} tiles={tile_args:?}): {msg}" - ); - refusals.push(format!("seed={seed} cq={cq}: {msg}")); + let mut refusals = Vec::new(); + let mut fired_runs = 0u32; + for attempt in 0..40u32 { + let seed = 100 + attempt; + let cq = 6 + (attempt % 4) * 2; + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &gradients_source(seed, width, height, "rate=25"), + "-vf", + // `noise` without `all_seed` re-renders differently on + // every run (seeded-fixture-not-reproducible); pinning it + // makes (seed, cq) name one exact stream. + &format!("noise=alls=40:allf=t:all_seed={seed},format=yuv420p"), + "-t", + "0.04", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let out = run_with_stdin( + Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &format!("--cq-level={cq}"), + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--min-partition-size=4", + "--max-partition-size=8", + // Below 8x8 only PARTITION_NONE/SPLIT are decodable (HORZ/VERT + // need a real rectangular transform, see the module doc above); + // disabling rect partitions entirely -- not just AB -- keeps + // aomenc from picking the still-refused HORZ/VERT arms almost + // every attempt (round 2 measured ~90% HORZ/VERT-below-8x8 + // refusals with --enable-ab-partitions=0 alone). + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=1", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-restoration=0", + "--enable-cdef=0", + "--loopfilter-control=0", + // use_ref_frame_mvs (temporal MV projection) is unimplemented in + // mvstack; this is a key-frame-only fixture, but keep it off for + // safety against a run that emits a second frame. + "--enable-ref-frame-mvs=0", + "--limit=1", + "--obu", + "-o", + "-", + "-", + ]) + .args(tile_args), + &y4m.stdout, + ); + if !out.status.success() { + refusals.push(format!( + "seed={seed} cq={cq}: aomenc itself refused the fixture" + )); continue; } - }; - // gate-blind-to-feature: a tile arm must actually decode more - // than one tile, not merely carry `tile_info.cols > 1`. - assert!( - tile_args.is_empty() || decode::tile_hits() - tiles_before >= 2, - "tiles={tile_args:?} decoded only {} tile(s) (seed={seed} cq={cq})", - decode::tile_hits() - tiles_before - ); - if decode::sub8_split_hits() == before { - refusals.push(format!( + let stream = out.stdout; + let before = decode::sub8_split_hits(); + let tiles_before = decode::tile_hits(); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => { + // Only a named refusal ("unsupported: ...") is a skip + // reason; any other decode error is this decoder failing. + let msg = e.to_string(); + assert!( + msg.starts_with("unsupported: "), + "decode error that is not a named refusal \ + (seed={seed} cq={cq} tiles={tile_args:?}): {msg}" + ); + refusals.push(format!("seed={seed} cq={cq}: {msg}")); + continue; + } + }; + // gate-blind-to-feature: a tile arm must actually decode more + // than one tile, not merely carry `tile_info.cols > 1`. + assert!( + tile_args.is_empty() || decode::tile_hits() - tiles_before >= 2, + "tiles={tile_args:?} decoded only {} tile(s) (seed={seed} cq={cq})", + decode::tile_hits() - tiles_before + ); + if decode::sub8_split_hits() == before { + refusals.push(format!( "seed={seed} cq={cq}: decoded, but no block read a real PARTITION_SPLIT below 8x8" )); - continue; - } - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!( - frames[0].y, ffmpeg_frames[0].y, - "luma vs ffmpeg (seed={seed} cq={cq})" - ); - assert_eq!( - frames[0].u, ffmpeg_frames[0].u, - "U vs ffmpeg (seed={seed} cq={cq})" - ); - assert_eq!( - frames[0].v, ffmpeg_frames[0].v, - "V vs ffmpeg (seed={seed} cq={cq})" - ); - fired_runs += 1; - if fired_runs >= 4 { - break; + continue; + } + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); + assert_eq!( + frames[0].y, ffmpeg_frames[0].y, + "luma vs ffmpeg (seed={seed} cq={cq})" + ); + assert_eq!( + frames[0].u, ffmpeg_frames[0].u, + "U vs ffmpeg (seed={seed} cq={cq})" + ); + assert_eq!( + frames[0].v, ffmpeg_frames[0].v, + "V vs ffmpeg (seed={seed} cq={cq})" + ); + fired_runs += 1; + if fired_runs >= 4 { + break; + } } - } - assert!( - fired_runs >= 4, - "fewer than 4 firing+pixel-exact runs out of 40 attempts \ + assert!( + fired_runs >= 4, + "fewer than 4 firing+pixel-exact runs out of 40 attempts \ ({width}x{height} tiles={tile_args:?}):\n{}", - refusals.join("\n") - ); + refusals.join("\n") + ); } } @@ -26986,223 +29835,243 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", - "--passes=1", - "--end-usage=q", - &format!("--cq-level={cq}"), - "--cpu-used=0", - "--threads=1", - "--row-mt=0", - "--sb-size=64", - "--min-partition-size=4", - "--max-partition-size=8", - // The tool under test: rect partitions ON, at a size - // where the only rect shapes are 4x8 and 8x4. - "--enable-rect-partitions=1", - "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", - "--enable-palette=0", - "--enable-intrabc=0", - "--enable-restoration=0", - "--enable-cdef=0", - "--loopfilter-control=0", - "--enable-ref-frame-mvs=0", - // Filter intra on a 4x8/8x4 leaf is refused by name - // (`predict_filter_intra` is square-only in this - // decoder, the same refusal the 16x16-level strips - // carry); with it on, that refusal -- not this - // lane's path -- is what most attempts hit. - "--enable-filter-intra=0", - "--limit=1", - "--obu", - "-o", - "-", - "-", - ]) - .args(if bit_depth == 10 { - &["--input-bit-depth=10", "--bit-depth=10"][..] - } else { - &[][..] - }) - .args(tile_args), &y4m.stdout); - if !out.status.success() { - refusals.push(format!( - "seed={seed} cq={cq}: aomenc itself refused the fixture" - )); - continue; - } - let stream = out.stdout; - let vert_before = decode::tx4x8_coded_hits(); - let horz_before = decode::tx8x4_coded_hits(); - let split_before = decode::rect8_split_tx_hits(); - let tiles_before = decode::tile_hits(); - let frames = match decode_stream(&stream) { - Ok(frames) => frames, - Err(e) => { - let msg = e.to_string(); - assert!( - msg.starts_with("unsupported: "), - "decode error that is not a named refusal \ - (seed={seed} cq={cq} depth={bit_depth} tiles={tile_args:?}): {msg}" - ); - refusals.push(format!("seed={seed} cq={cq}: {msg}")); - continue; - } - }; - assert!( - tile_args.is_empty() || decode::tile_hits() - tiles_before >= 2, - "tiles={tile_args:?} decoded only {} tile(s) (seed={seed} cq={cq})", - decode::tile_hits() - tiles_before - ); - let vert = decode::tx4x8_coded_hits() - vert_before; - let horz = decode::tx8x4_coded_hits() - horz_before; - if vert == 0 || horz == 0 { - refusals.push(format!( - "seed={seed} cq={cq}: decoded, but coded 4x8={vert} 8x4={horz} leaves" - )); - continue; - } - let ffmpeg_frames = if bit_depth == 10 { - ffmpeg_decode_sequence_10bit(&stream, width, height, 1) - } else { - ffmpeg_decode_sequence(&stream, width, height, 1) - }; - assert_eq!( - frames[0].y, ffmpeg_frames[0].y, - "luma vs ffmpeg (seed={seed} cq={cq} depth={bit_depth} tiles={tile_args:?})" - ); - assert_eq!( - frames[0].u, ffmpeg_frames[0].u, - "U vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})" - ); - assert_eq!( - frames[0].v, ffmpeg_frames[0].v, - "V vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})" - ); - fired_runs += 1; - split_tx += decode::rect8_split_tx_hits() - split_before; - if fired_runs >= 4 { - break; - } - } - assert!( - fired_runs >= 4, - "fewer than 4 firing+pixel-exact runs out of 40 attempts \ - ({width}x{height} depth={bit_depth} tiles={tile_args:?}):\n{}", - refusals.join("\n") - ); - // aomenc's default `--enable-tx-size-search=1` makes TX_MODE_SELECT - // the frame's tx mode, so every sub-8x8 rect leaf carries a - // `tx_depth` symbol; depth 1 (two 4x4 transform units predicted one - // after the other) is the half of that path a whole-leaf transform - // would silently get wrong, so the gate proves it fired. - assert!( - split_tx > 0, - "no sub-8x8 rect leaf used a split (depth-1) transform in the \ - {fired_runs} pixel-exact runs ({width}x{height} depth={bit_depth})" - ); - } - } - - /// lane-fi8 r1: the sub8 rect-leaf gate above with the tool under test - /// turned ON (`--enable-filter-intra=1`, appended AFTER the base recipe - /// -- aomenc takes the FIRST occurrence of a repeated flag, so the base - /// recipe below carries no `--enable-filter-intra` at all). A DC_PRED - /// `BLOCK_4X8`/`BLOCK_8X4` leaf carries a `use_filter_intra` flag - /// (`av1_filter_intra_allowed_bsize` is "both sides <= 32"), which this - /// decoder read from `BLOCK_4X4`'s CDF row until this round -- the same - /// VALUE, a different interval, so it desynced a block or two later - /// ([[wrong-alphabet-same-value]]) -- and then refused the prediction by - /// name. Per attempt, only runs whose [`decode::filter_intra_rect_sub8_hits`] - /// delta is nonzero AND whose three planes match ffmpeg count; the wider - /// `filter_intra_rect_hits` would be satisfied by a 16x8 strip and prove - /// nothing about these shapes. Arms cover both transform depths - /// (`--enable-tx-size-search=1`, where a leaf may split into two 4x4 - /// units each predicted from the previous one's reconstruction, and `=0`, - /// one whole-leaf transform) and both bit depths. - #[test] - fn a_real_aomenc_stream_with_filter_intra_on_a_sub8_rect_leaf_decodes_pixel_exact() { - const NAME: &str = - "a_real_aomenc_stream_with_filter_intra_on_a_sub8_rect_leaf_decodes_pixel_exact"; - if !have_ffmpeg() { - eprintln!("SKIP {NAME}: no ffmpeg"); - return; - } - if !have_aomenc() { - let msg = format!("no aomenc at {}", aomenc_path().display()); - assert!( - std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(), - "EC_AV1_REQUIRE_AOMENC is set but {msg}" - ); - eprintln!("SKIP {NAME}: {msg}"); - return; - } - let (width, height) = (16usize, 16usize); - for (tx_search, bit_depth) in [("1", 8u8), ("0", 8u8), ("1", 10u8)] { - let mut refusals = Vec::new(); - let mut fired_runs = 0u32; - let mut fi_leaves = 0usize; - let mut split_tx = 0usize; - for attempt in 0..80u32 { - let seed = 300 + attempt; - let cq = 6 + (attempt % 8) * 6; - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; - let y4m = Command::new("ffmpeg") - .args([ - "-v", "error", "-f", "lavfi", "-i", - &format!("testsrc2=size={width}x{height}:rate=25"), - "-vf", - &format!("noise=alls=40:allf=t:all_seed={seed},format={pix_fmt}"), - "-strict", "-1", "-t", "0.04", "-f", "yuv4mpegpipe", "-", - ]) - .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .output() - .expect("ffmpeg failed to run"); - assert!( - y4m.status.success(), - "ffmpeg fixture: {}", - String::from_utf8_lossy(&y4m.stderr) + let out = run_with_stdin( + Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &format!("--cq-level={cq}"), + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--min-partition-size=4", + "--max-partition-size=8", + // The tool under test: rect partitions ON, at a size + // where the only rect shapes are 4x8 and 8x4. + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-restoration=0", + "--enable-cdef=0", + "--loopfilter-control=0", + "--enable-ref-frame-mvs=0", + // Filter intra on a 4x8/8x4 leaf is refused by name + // (`predict_filter_intra` is square-only in this + // decoder, the same refusal the 16x16-level strips + // carry); with it on, that refusal -- not this + // lane's path -- is what most attempts hit. + "--enable-filter-intra=0", + "--limit=1", + "--obu", + "-o", + "-", + "-", + ]) + .args(if bit_depth == 10 { + &["--input-bit-depth=10", "--bit-depth=10"][..] + } else { + &[][..] + }) + .args(tile_args), + &y4m.stdout, + ); + if !out.status.success() { + refusals.push(format!( + "seed={seed} cq={cq}: aomenc itself refused the fixture" + )); + continue; + } + let stream = out.stdout; + let vert_before = decode::tx4x8_coded_hits(); + let horz_before = decode::tx8x4_coded_hits(); + let split_before = decode::rect8_split_tx_hits(); + let tiles_before = decode::tile_hits(); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => { + let msg = e.to_string(); + assert!( + msg.starts_with("unsupported: "), + "decode error that is not a named refusal \ + (seed={seed} cq={cq} depth={bit_depth} tiles={tile_args:?}): {msg}" + ); + refusals.push(format!("seed={seed} cq={cq}: {msg}")); + continue; + } + }; + assert!( + tile_args.is_empty() || decode::tile_hits() - tiles_before >= 2, + "tiles={tile_args:?} decoded only {} tile(s) (seed={seed} cq={cq})", + decode::tile_hits() - tiles_before + ); + let vert = decode::tx4x8_coded_hits() - vert_before; + let horz = decode::tx8x4_coded_hits() - horz_before; + if vert == 0 || horz == 0 { + refusals.push(format!( + "seed={seed} cq={cq}: decoded, but coded 4x8={vert} 8x4={horz} leaves" + )); + continue; + } + let ffmpeg_frames = if bit_depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, 1) + } else { + ffmpeg_decode_sequence(&stream, width, height, 1) + }; + assert_eq!( + frames[0].y, ffmpeg_frames[0].y, + "luma vs ffmpeg (seed={seed} cq={cq} depth={bit_depth} tiles={tile_args:?})" + ); + assert_eq!( + frames[0].u, ffmpeg_frames[0].u, + "U vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})" + ); + assert_eq!( + frames[0].v, ffmpeg_frames[0].v, + "V vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})" + ); + fired_runs += 1; + split_tx += decode::rect8_split_tx_hits() - split_before; + if fired_runs >= 4 { + break; + } + } + assert!( + fired_runs >= 4, + "fewer than 4 firing+pixel-exact runs out of 40 attempts \ + ({width}x{height} depth={bit_depth} tiles={tile_args:?}):\n{}", + refusals.join("\n") + ); + // aomenc's default `--enable-tx-size-search=1` makes TX_MODE_SELECT + // the frame's tx mode, so every sub-8x8 rect leaf carries a + // `tx_depth` symbol; depth 1 (two 4x4 transform units predicted one + // after the other) is the half of that path a whole-leaf transform + // would silently get wrong, so the gate proves it fired. + assert!( + split_tx > 0, + "no sub-8x8 rect leaf used a split (depth-1) transform in the \ + {fired_runs} pixel-exact runs ({width}x{height} depth={bit_depth})" + ); + } + } + + /// lane-fi8 r1: the sub8 rect-leaf gate above with the tool under test + /// turned ON (`--enable-filter-intra=1`, appended AFTER the base recipe + /// -- aomenc takes the FIRST occurrence of a repeated flag, so the base + /// recipe below carries no `--enable-filter-intra` at all). A DC_PRED + /// `BLOCK_4X8`/`BLOCK_8X4` leaf carries a `use_filter_intra` flag + /// (`av1_filter_intra_allowed_bsize` is "both sides <= 32"), which this + /// decoder read from `BLOCK_4X4`'s CDF row until this round -- the same + /// VALUE, a different interval, so it desynced a block or two later + /// ([[wrong-alphabet-same-value]]) -- and then refused the prediction by + /// name. Per attempt, only runs whose [`decode::filter_intra_rect_sub8_hits`] + /// delta is nonzero AND whose three planes match ffmpeg count; the wider + /// `filter_intra_rect_hits` would be satisfied by a 16x8 strip and prove + /// nothing about these shapes. Arms cover both transform depths + /// (`--enable-tx-size-search=1`, where a leaf may split into two 4x4 + /// units each predicted from the previous one's reconstruction, and `=0`, + /// one whole-leaf transform) and both bit depths. + #[test] + fn a_real_aomenc_stream_with_filter_intra_on_a_sub8_rect_leaf_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_stream_with_filter_intra_on_a_sub8_rect_leaf_decodes_pixel_exact"; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + let msg = format!("no aomenc at {}", aomenc_path().display()); + assert!( + std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(), + "EC_AV1_REQUIRE_AOMENC is set but {msg}" + ); + eprintln!("SKIP {NAME}: {msg}"); + return; + } + let (width, height) = (16usize, 16usize); + for (tx_search, bit_depth) in [("1", 8u8), ("0", 8u8), ("1", 10u8)] { + let mut refusals = Vec::new(); + let mut fired_runs = 0u32; + let mut fi_leaves = 0usize; + let mut split_tx = 0usize; + for attempt in 0..80u32 { + let seed = 300 + attempt; + let cq = 6 + (attempt % 8) * 6; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &format!("testsrc2=size={width}x{height}:rate=25"), + "-vf", + &format!("noise=alls=40:allf=t:all_seed={seed},format={pix_fmt}"), + "-strict", + "-1", + "-t", + "0.04", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let out = run_with_stdin( + Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &format!("--cq-level={cq}"), + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--min-partition-size=4", + "--max-partition-size=8", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-restoration=0", + "--enable-cdef=0", + "--loopfilter-control=0", + "--enable-ref-frame-mvs=0", + // The tools under test, first occurrence in the + // command line (aomenc keeps the first). + "--enable-filter-intra=1", + &format!("--enable-tx-size-search={tx_search}"), + "--limit=1", + "--obu", + "-o", + "-", + "-", + ]) + .args(if bit_depth == 10 { + &["--input-bit-depth=10", "--bit-depth=10"][..] + } else { + &[][..] + }), + &y4m.stdout, ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", - "--passes=1", - "--end-usage=q", - &format!("--cq-level={cq}"), - "--cpu-used=0", - "--threads=1", - "--row-mt=0", - "--sb-size=64", - "--min-partition-size=4", - "--max-partition-size=8", - "--enable-rect-partitions=1", - "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", - "--enable-palette=0", - "--enable-intrabc=0", - "--enable-restoration=0", - "--enable-cdef=0", - "--loopfilter-control=0", - "--enable-ref-frame-mvs=0", - // The tools under test, first occurrence in the - // command line (aomenc keeps the first). - "--enable-filter-intra=1", - &format!("--enable-tx-size-search={tx_search}"), - "--limit=1", - "--obu", - "-o", - "-", - "-", - ]) - .args(if bit_depth == 10 { - &["--input-bit-depth=10", "--bit-depth=10"][..] - } else { - &[][..] - }), &y4m.stdout); if !out.status.success() { refusals.push(format!("seed={seed} cq={cq}: aomenc itself refused")); continue; @@ -27378,52 +30247,55 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", - "--passes=1", - "--end-usage=q", - &format!("--cq-level={cq}"), - "--cpu-used=0", - "--threads=1", - "--row-mt=0", - "--sb-size=64", - // The tool under test: 16x8/8x16 strips, predicted by - // a mode that reads beyond the block. - // aomenc bounds a RECT shape by its smaller side, so - // `--min-partition-size=16` yields no 16x8 at all - // (measured: 0 strips in 40 attempts); 8 is the - // smallest value that lets a 16x16 split HORZ/VERT. - "--min-partition-size=8", - "--max-partition-size=16", - // Largest transform per block: a split (depth-1) rect - // strip is a named refusal of another lane, and it - // ate every attempt while it was on. - "--enable-tx-size-search=0", - "--enable-rect-partitions=1", - "--enable-directional-intra=1", - "--enable-smooth-intra=0", - "--enable-paeth-intra=0", - "--enable-filter-intra=0", - "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", - "--enable-palette=0", - "--enable-intrabc=0", - "--enable-restoration=0", - "--enable-cdef=0", - "--loopfilter-control=0", - "--enable-ref-frame-mvs=0", - "--limit=1", - "--obu", - "-o", - "-", - "-", - ]) - .args(if bit_depth == 10 { - &["--input-bit-depth=10", "--bit-depth=10"][..] - } else { - &[][..] - }), &y4m.stdout); + let out = run_with_stdin( + Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &format!("--cq-level={cq}"), + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + // The tool under test: 16x8/8x16 strips, predicted by + // a mode that reads beyond the block. + // aomenc bounds a RECT shape by its smaller side, so + // `--min-partition-size=16` yields no 16x8 at all + // (measured: 0 strips in 40 attempts); 8 is the + // smallest value that lets a 16x16 split HORZ/VERT. + "--min-partition-size=8", + "--max-partition-size=16", + // Largest transform per block: a split (depth-1) rect + // strip is a named refusal of another lane, and it + // ate every attempt while it was on. + "--enable-tx-size-search=0", + "--enable-rect-partitions=1", + "--enable-directional-intra=1", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-filter-intra=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-restoration=0", + "--enable-cdef=0", + "--loopfilter-control=0", + "--enable-ref-frame-mvs=0", + "--limit=1", + "--obu", + "-o", + "-", + "-", + ]) + .args(if bit_depth == 10 { + &["--input-bit-depth=10", "--bit-depth=10"][..] + } else { + &[][..] + }), + &y4m.stdout, + ); if !out.status.success() { refusals.push(format!( "seed={seed} cq={cq}: aomenc itself refused the fixture" @@ -27702,7 +30574,7 @@ pub(crate) mod tests { /// the real proof). #[test] fn a_real_aomenc_stream_with_two_tile_columns_decodes_pixel_exact() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); const NAME: &str = "a_real_aomenc_stream_with_two_tile_columns_decodes_pixel_exact"; if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); @@ -27749,8 +30621,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -27797,7 +30669,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -27878,7 +30752,8 @@ pub(crate) mod tests { header.reduced_tx_set, header.allow_screen_content_tools, header.allow_intrabc, - header.delta, fctx, + header.delta, + fctx, ) { Err(e) => { let msg = e.to_string(); @@ -27900,9 +30775,18 @@ pub(crate) mod tests { ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(picture.y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(picture.u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(picture.v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + picture.y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + picture.u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + picture.v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); mode_edge_leaks += crate::decode::mode_tile_edge_coarse_leaks() - before_edge; matched += 1; } @@ -27942,7 +30826,7 @@ pub(crate) mod tests { /// already proved -- this gate is what actually proves it either way. #[test] fn a_real_aomenc_stream_with_two_tile_rows_decodes_pixel_exact() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); const NAME: &str = "a_real_aomenc_stream_with_two_tile_rows_decodes_pixel_exact"; if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); @@ -27982,8 +30866,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -28020,7 +30904,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -28089,7 +30975,8 @@ pub(crate) mod tests { header.reduced_tx_set, header.allow_screen_content_tools, header.allow_intrabc, - header.delta, fctx, + header.delta, + fctx, ) { Err(e) => { let msg = e.to_string(); @@ -28111,9 +30998,18 @@ pub(crate) mod tests { ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(picture.y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(picture.u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(picture.v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + picture.y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + picture.u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + picture.v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -28150,8 +31046,17 @@ pub(crate) mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -28163,8 +31068,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -28197,7 +31102,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -28225,12 +31132,25 @@ pub(crate) mod tests { "{NAME}: tile_hits delta was {hits}, expected >1 -- both tile rows must actually \ decode, not just tile 0 (seed {seed})" ); - assert_eq!(pictures.len(), 1, "{NAME}: expected exactly 1 picture (seed {seed})"); + assert_eq!( + pictures.len(), + 1, + "{NAME}: expected exactly 1 picture (seed {seed})" + ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(pictures[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + pictures[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -28254,7 +31174,7 @@ pub(crate) mod tests { /// 2-column case's boundary-that-is-also-the-frame-edge. #[test] fn a_real_aomenc_stream_with_four_tile_columns_decodes_pixel_exact() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::new(); const NAME: &str = "a_real_aomenc_stream_with_four_tile_columns_decodes_pixel_exact"; if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); @@ -28272,8 +31192,17 @@ pub(crate) mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -28285,8 +31214,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -28319,7 +31248,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -28388,7 +31319,8 @@ pub(crate) mod tests { header.reduced_tx_set, header.allow_screen_content_tools, header.allow_intrabc, - header.delta, fctx, + header.delta, + fctx, ) { Err(e) => { let msg = e.to_string(); @@ -28410,9 +31342,18 @@ pub(crate) mod tests { ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(picture.y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(picture.u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(picture.v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + picture.y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + picture.u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + picture.v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -28462,8 +31403,17 @@ pub(crate) mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -28475,8 +31425,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -28509,7 +31459,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -28555,12 +31507,25 @@ pub(crate) mod tests { "{NAME}: tile_hits delta was {hits}, expected >2 -- all four tile rows must \ actually decode, not just a subset (seed {seed})" ); - assert_eq!(pictures.len(), 1, "{NAME}: expected exactly 1 picture (seed {seed})"); + assert_eq!( + pictures.len(), + 1, + "{NAME}: expected exactly 1 picture (seed {seed})" + ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(pictures[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + pictures[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -28592,7 +31557,8 @@ pub(crate) mod tests { /// comment used to describe are gone from `decode_stream`. #[test] fn a_real_aomenc_stream_with_two_tile_columns_decodes_through_decode_stream() { - const NAME: &str = "a_real_aomenc_stream_with_two_tile_columns_decodes_through_decode_stream"; + const NAME: &str = + "a_real_aomenc_stream_with_two_tile_columns_decodes_through_decode_stream"; if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); return; @@ -28609,8 +31575,17 @@ pub(crate) mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -28622,8 +31597,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -28657,7 +31632,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -28685,12 +31662,25 @@ pub(crate) mod tests { "{NAME}: tile_hits delta was {hits}, expected >1 -- both tiles must actually \ decode, not just tile 0 (seed {seed})" ); - assert_eq!(pictures.len(), 1, "{NAME}: expected exactly 1 picture (seed {seed})"); + assert_eq!( + pictures.len(), + 1, + "{NAME}: expected exactly 1 picture (seed {seed})" + ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(pictures[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + pictures[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -28827,8 +31817,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -28863,7 +31852,10 @@ pub(crate) mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -28955,11 +31947,28 @@ pub(crate) mod tests { sx = -0.6 + 0.005 * (attempt as f64), sy = -0.4 + 0.005 * (attempt as f64) ); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -28972,7 +31981,10 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let depth_args: Vec = if bit_depth == 10 { - vec!["--input-bit-depth=10".to_owned(), "--bit-depth=10".to_owned()] + vec![ + "--input-bit-depth=10".to_owned(), + "--bit-depth=10".to_owned(), + ] } else { Vec::new() }; @@ -29023,8 +32035,7 @@ pub(crate) mod tests { args.extend(rate_args.iter().copied()); args.extend(depth_args.iter().map(String::as_str)); args.extend(["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -29038,7 +32049,9 @@ pub(crate) mod tests { let mut probe = Av1Parser::new(); let mut pos = 0usize; while pos < stream.len() { - let obu = probe.parse_obu(&stream[pos..]).expect("parsing the gate stream"); + let obu = probe + .parse_obu(&stream[pos..]) + .expect("parsing the gate stream"); pos += obu.total_size; match &obu.kind { ObuKind::Frame(h, _) => { @@ -29056,7 +32069,9 @@ pub(crate) mod tests { } } if seg_frames == 0 { - eprintln!("seed {seed}: aomenc wrote no segmentation-enabled frame, skipping attempt"); + eprintln!( + "seed {seed}: aomenc wrote no segmentation-enabled frame, skipping attempt" + ); continue; } let frames = match decode_stream(&stream) { @@ -29091,7 +32106,10 @@ pub(crate) mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{name} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{name} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{name} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{name} frame {i} V vs ffmpeg (seed {seed})"); } @@ -29214,8 +32232,17 @@ pub(crate) mod tests { let source = gradients_source(seed, width, height, "duration=0.08:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -29227,8 +32254,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -29276,7 +32303,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -29327,11 +32356,18 @@ pub(crate) mod tests { "{NAME}: tile_hits delta was {hits}, expected > {frames} -- both tiles of both \ frames must actually decode (seed {seed})" ); - assert_eq!(pictures.len(), frames, "{NAME}: expected {frames} pictures (seed {seed})"); + assert_eq!( + pictures.len(), + frames, + "{NAME}: expected {frames} pictures (seed {seed})" + ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames); for (i, (got, want)) in pictures.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME}: seed {seed} frame {i} luma vs ffmpeg"); + assert_eq!( + got.y, want.y, + "{NAME}: seed {seed} frame {i} luma vs ffmpeg" + ); assert_eq!(got.u, want.u, "{NAME}: seed {seed} frame {i} U vs ffmpeg"); assert_eq!(got.v, want.v, "{NAME}: seed {seed} frame {i} V vs ffmpeg"); } @@ -29383,8 +32419,17 @@ pub(crate) mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -29396,8 +32441,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -29432,7 +32477,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -29473,12 +32520,25 @@ pub(crate) mod tests { hits > 0, "{NAME}: tile_hits delta was {hits}, expected >0 (seed {seed})" ); - assert_eq!(pictures.len(), 1, "{NAME}: expected exactly 1 picture (seed {seed})"); + assert_eq!( + pictures.len(), + 1, + "{NAME}: expected exactly 1 picture (seed {seed})" + ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(pictures[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + pictures[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -29541,8 +32601,17 @@ pub(crate) mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -29554,8 +32623,8 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -29589,7 +32658,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -29642,12 +32713,25 @@ pub(crate) mod tests { hits > 0, "{NAME}: tile_hits delta was {hits}, expected >0 (seed {seed})" ); - assert_eq!(pictures.len(), 1, "{NAME}: expected exactly 1 picture (seed {seed})"); + assert_eq!( + pictures.len(), + 1, + "{NAME}: expected exactly 1 picture (seed {seed})" + ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(pictures[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + pictures[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -29723,8 +32807,7 @@ pub(crate) mod tests { let mut args = base.clone(); args.extend_from_slice(extra); args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -29823,7 +32906,10 @@ pub(crate) mod tests { }; assert_eq!(frames.len(), 1); for (i, (got, want)) in frames.iter().zip(&want).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -29881,10 +32967,21 @@ pub(crate) mod tests { let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; let out = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", + "-v", + "error", + "-f", + "lavfi", + "-i", &gradients_source(seed, width, height, "duration=0.04:rate=25"), - "-pix_fmt", pix, "-strict", "-1", "-t", "0.04", - "-f", "yuv4mpegpipe", "-", + "-pix_fmt", + pix, + "-strict", + "-1", + "-t", + "0.04", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -29912,8 +33009,13 @@ pub(crate) mod tests { for (seed, cq, width, height, ten_bit) in arms { let y4m = render(seed, width, height, ten_bit); let mut args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", cq, - "--cpu-used=0", "--threads=1", "--row-mt=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + cq, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", "--sb-size=128", "--enable-rect-partitions=0", "--enable-ab-partitions=0", @@ -29930,8 +33032,7 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -29967,7 +33068,8 @@ pub(crate) mod tests { let n = a.iter().zip(b.iter()).filter(|(x, y)| x != y).count(); let first = a.iter().zip(b.iter()).position(|(x, y)| x != y); assert_eq!( - n, 0, + n, + 0, "{NAME} frame {i} {name} vs ffmpeg (seed {seed}): {n} differ, first row {} col {} ours {:?} ffmpeg {:?}", first.unwrap_or(0) / w, first.unwrap_or(0) % w, @@ -30012,8 +33114,7 @@ pub(crate) mod tests { /// (hidden alt-refs included) against the instrumented aomdec. #[test] fn a_real_aomenc_sb128_gathered_edge_horz_partition_decodes_pixel_exact() { - const NAME: &str = - "a_real_aomenc_sb128_gathered_edge_horz_partition_decodes_pixel_exact"; + const NAME: &str = "a_real_aomenc_sb128_gathered_edge_horz_partition_decodes_pixel_exact"; let _gate_lock = lock_gate_counters(); if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); @@ -30059,10 +33160,21 @@ pub(crate) mod tests { }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", + "-v", + "error", + "-f", + "lavfi", + "-i", &source, - "-pix_fmt", pix, "-strict", "-1", "-t", "0.2", - "-f", "yuv4mpegpipe", "-", + "-pix_fmt", + pix, + "-strict", + "-1", + "-t", + "0.2", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -30075,20 +33187,29 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let mut args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", cq, - "--cpu-used=0", "--threads=1", "--row-mt=0", - "--sb-size=128", "--min-partition-size=64", - "--enable-rect-partitions=1", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--enable-palette=0", - "--enable-intrabc=0", "--enable-tx-size-search=0", - "--deltaq-mode=0", "--limit=5", + "--codec=av1", + "--passes=1", + "--end-usage=q", + cq, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=128", + "--min-partition-size=64", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-tx-size-search=0", + "--deltaq-mode=0", + "--limit=5", ]; if ten_bit { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -30245,12 +33366,22 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let mut args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", cq, - "--cpu-used=0", "--threads=1", "--row-mt=0", - "--sb-size=128", "--min-partition-size=64", - "--enable-rect-partitions=1", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--enable-palette=0", - "--enable-intrabc=0", "--deltaq-mode=0", "--limit=5", + "--codec=av1", + "--passes=1", + "--end-usage=q", + cq, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=128", + "--min-partition-size=64", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--deltaq-mode=0", + "--limit=5", // EVERY frame a key frame: this gate exists for the INTRA // 128x64/64x128 block, and a mixed stream lands on other // lanes' inter gaps (sub-8 leaves, rect inter residual) @@ -30270,8 +33401,7 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -30297,8 +33427,7 @@ pub(crate) mod tests { assert!(frames > 0, "{NAME}: no frames decoded at {width}x{height}"); let after = intra_sb128_counters(); let (horz, vert_hits) = (after.0 - before.0, after.1 - before.1); - let depth: Vec = - (0..3).map(|i| after.2[i] - before.2[i]).collect(); + let depth: Vec = (0..3).map(|i| after.2[i] - before.2[i]).collect(); eprintln!( "{NAME}: arm {tag} cq {cq} {width}x{height} {}bit {} txsearch={}: \ {frames} frames pixel-exact ({hidden} hidden), \ @@ -30382,7 +33511,11 @@ pub(crate) mod tests { let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", + "-v", + "error", + "-f", + "lavfi", + "-i", // Same DETERMINISTIC sinusoid source that made aomenc pick // the AB shapes in the r8 sweep (lavfi `gradients` ignores // its seed and is not reproducible -- never use it here). @@ -30391,8 +33524,15 @@ pub(crate) mod tests { geq=lum='128+80*sin((X+3*N)/17)+50*sin(Y/29)+30*sin((X+Y)/13)':\ cb='128+30*sin(X/23)':cr='128+30*sin((Y+N)/19)'" ), - "-pix_fmt", pix, "-strict", "-1", "-t", "0.2", - "-f", "yuv4mpegpipe", "-", + "-pix_fmt", + pix, + "-strict", + "-1", + "-t", + "0.2", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -30405,22 +33545,35 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let mut args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", cq, - "--cpu-used=0", "--threads=1", "--row-mt=0", - "--sb-size=128", "--min-partition-size=64", - "--enable-rect-partitions=1", "--enable-ab-partitions=1", - "--enable-1to4-partitions=0", "--enable-palette=0", - "--enable-intrabc=0", "--deltaq-mode=0", "--limit=5", + "--codec=av1", + "--passes=1", + "--end-usage=q", + cq, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=128", + "--min-partition-size=64", + "--enable-rect-partitions=1", + "--enable-ab-partitions=1", + "--enable-1to4-partitions=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--deltaq-mode=0", + "--limit=5", ]; // AOMENC FLAG PRECEDENCE: last occurrence wins, so the per-arm // key-frame cadence goes AFTER the base recipe. - args.push(if inter { "--kf-max-dist=100" } else { "--kf-max-dist=1" }); + args.push(if inter { + "--kf-max-dist=100" + } else { + "--kf-max-dist=1" + }); if ten_bit { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -30439,10 +33592,8 @@ pub(crate) mod tests { eprintln!("{NAME}: arm {tag} {width}x{height} refusal: {msg}"); continue; } - let (frames, hidden) = decode_all_frames_vs_oracle( - &stream, - &format!("sb128c-ab-{tag}-{width}x{height}"), - ); + let (frames, hidden) = + decode_all_frames_vs_oracle(&stream, &format!("sb128c-ab-{tag}-{width}x{height}")); assert!(frames > 0, "{NAME}: no frames decoded at {width}x{height}"); let after = sb128_ab_counters(); let ab: Vec = (0..4).map(|i| after[i] - before[i]).collect(); @@ -30510,27 +33661,54 @@ pub(crate) mod tests { let (width, height) = (256usize, 192usize); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", + "-v", + "error", + "-f", + "lavfi", + "-i", &format!( "{},noise=all_seed=53:alls=12:allf=t", gradients_source(53, width, height, "duration=0.32:rate=25") ), - "-pix_fmt", "yuv420p", "-t", "0.32", "-f", "yuv4mpegpipe", "-", + "-pix_fmt", + "yuv420p", + "-t", + "0.32", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .output() .expect("ffmpeg"); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=40", - "--cpu-used=2", "--threads=1", "--row-mt=0", "--sb-size=64", - "--max-partition-size=64", "--min-partition-size=32", - "--enable-rect-partitions=0", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--enable-palette=0", - "--enable-intrabc=0", "--enable-tx-size-search=0", - "--deltaq-mode=0", "--limit=8", "--obu", "-o", "-", "-", - ]), &y4m.stdout); + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=40", + "--cpu-used=2", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--max-partition-size=64", + "--min-partition-size=32", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-tx-size-search=0", + "--deltaq-mode=0", + "--limit=8", + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); assert!(out.status.success()); let (frames, hidden) = decode_all_frames_vs_oracle(&out.stdout, "sb128-control-64"); eprintln!("control sb64: {frames} frames exact ({hidden} hidden)"); @@ -30628,8 +33806,7 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -30726,7 +33903,9 @@ pub(crate) mod tests { } let (width, height) = (256usize, 256usize); let mut intra128_total = 0usize; - for (ten_bit, tx_search, seed) in [(false, false, 61u32), (true, false, 61), (false, true, 62)] { + for (ten_bit, tx_search, seed) in + [(false, false, 61u32), (true, false, 61), (false, true, 62)] + { let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; let y4m = Command::new("ffmpeg") .args([ @@ -30789,8 +33968,7 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -30823,7 +34001,11 @@ pub(crate) mod tests { ); let (frames, hidden) = decode_all_frames_vs_oracle( &stream, - &format!("sb128c-inter-none-{}-{}", if ten_bit { 10 } else { 8 }, tx_search), + &format!( + "sb128c-inter-none-{}-{}", + if ten_bit { 10 } else { 8 }, + tx_search + ), ); let (none128, chroma_units, intra128) = ( crate::decode::inter_sb128_none_hits() - before.0, @@ -30962,16 +34144,16 @@ pub(crate) mod tests { "{NAME}: the encoder did not write a 128x128-superblock 8-bit sequence header -- \ the flags never arrived" ); - let before = (crate::decode::inter_sb128_none_hits(), crate::decode::chroma_split_tx_hits()); + let before = ( + crate::decode::inter_sb128_none_hits(), + crate::decode::chroma_split_tx_hits(), + ); let (frames, hidden) = decode_all_frames_vs_oracle(&stream, "av1444128-128none-mu-chroma"); let (none128, chroma_units) = ( crate::decode::inter_sb128_none_hits() - before.0, crate::decode::chroma_split_tx_hits() - before.1, ); - assert!( - frames >= 11, - "{NAME}: only {frames} decode-order frames" - ); + assert!(frames >= 11, "{NAME}: only {frames} decode-order frames"); assert!( none128 >= 8, "{NAME}: only {none128} inter 128x128 PARTITION_NONE roots -- the recipe stopped \ @@ -31075,8 +34257,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -31118,7 +34299,10 @@ pub(crate) mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -31226,10 +34410,7 @@ pub(crate) mod tests { /// vacuous for this defect. #[test] fn a_frame_edge_straddling_band_decodes_pixel_exact() { - edge32_gate( - "a_frame_edge_straddling_band_decodes_pixel_exact", - false, - ); + edge32_gate("a_frame_edge_straddling_band_decodes_pixel_exact", false); } fn edge32_gate(name: &str, flat_band: bool) { @@ -31326,8 +34507,16 @@ pub(crate) mod tests { // never fired. `noise` on top keeps screen-content detection // (and its palette-strip refusal) off. let (cw, ch) = ( - if flat_band && width % 64 != 0 { width - 16 } else { width }, - if flat_band && height % 64 != 0 { height - 16 } else { height }, + if flat_band && width % 64 != 0 { + width - 16 + } else { + width + }, + if flat_band && height % 64 != 0 { + height - 16 + } else { + height + }, ); let pad = if flat_band { format!("pad={width}:{height}:0:0:gray,") @@ -31341,8 +34530,21 @@ pub(crate) mod tests { let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", pix, "-strict", - "-1", "-t", &format!("{duration}"), "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + pix, + "-strict", + "-1", + "-t", + &format!("{duration}"), + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -31391,8 +34593,7 @@ pub(crate) mod tests { args.push(&tile_arg); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "{name}: aomenc refused the fixture: {}", @@ -31431,8 +34632,7 @@ pub(crate) mod tests { } }; let after = crate::decode::edge32_hits(); - let delta: Vec = - (0..8).map(|i| after[i] - before[i]).collect(); + let delta: Vec = (0..8).map(|i| after[i] - before[i]).collect(); let reference = if ten_bit { ffmpeg_decode_sequence_10bit(&stream, width, height, decoded.len()) } else { @@ -31598,21 +34798,36 @@ pub(crate) mod tests { let mut args = base_args.clone(); args.extend_from_slice(extra); args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m); assert!( out.status.success(), "aomenc refused the fixture: {}", String::from_utf8_lossy(&out.stderr) ); - assert!(!out.stdout.is_empty(), "{NAME}: aomenc wrote an empty stream"); + assert!( + !out.stdout.is_empty(), + "{NAME}: aomenc wrote an empty stream" + ); out.stdout }; let render = |source: &str, pix_fmt: &str| -> Vec { let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", source, "-t", "0.04", "-pix_fmt", pix_fmt, - "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + source, + "-t", + "0.04", + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -31640,7 +34855,11 @@ pub(crate) mod tests { let seed = 42 + attempt; // Two quantisers per seed: the coarse one keeps most blocks on // one transform, the fine one is what actually splits them. - let cq = if attempt % 2 == 0 { "--cq-level=20" } else { "--cq-level=40" }; + let cq = if attempt % 2 == 0 { + "--cq-level=20" + } else { + "--cq-level=40" + }; let y4m = render( &gradients_source(seed, width, height, "duration=0.04:rate=25"), "yuv420p", @@ -31661,9 +34880,18 @@ pub(crate) mod tests { }; let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); assert_eq!(frames.len(), 1, "{NAME}: expected one frame (seed {seed})"); - assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME} luma vs ffmpeg (seed {seed})"); - assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME} U vs ffmpeg (seed {seed})"); - assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME} V vs ffmpeg (seed {seed})"); + assert_eq!( + frames[0].y, ffmpeg_frames[0].y, + "{NAME} luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + frames[0].u, ffmpeg_frames[0].u, + "{NAME} U vs ffmpeg (seed {seed})" + ); + assert_eq!( + frames[0].v, ffmpeg_frames[0].v, + "{NAME} V vs ffmpeg (seed {seed})" + ); firing += crate::decode::sq_chroma_tx_hits() - before; matched += 1; } @@ -31674,7 +34902,10 @@ pub(crate) mod tests { &gradients_source(42, width, height, "duration=0.04:rate=25"), "yuv420p10le", ); - let stream10 = encode(&y4m10, &["--cq-level=20", "--input-bit-depth=10", "--bit-depth=10"]); + let stream10 = encode( + &y4m10, + &["--cq-level=20", "--input-bit-depth=10", "--bit-depth=10"], + ); let mut probe = Av1Parser::new(); let mut pos = 0usize; while pos < stream10.len() && probe.sequence_header().is_none() { @@ -31696,7 +34927,10 @@ pub(crate) mod tests { Err(e) => panic!("{NAME}: decode_stream refused the 10-bit stream: {e}"), }; let ffmpeg10 = ffmpeg_decode_sequence_10bit(&stream10, width, height, 1); - assert_eq!(frames10[0].y, ffmpeg10[0].y, "{NAME} luma vs ffmpeg (10-bit)"); + assert_eq!( + frames10[0].y, ffmpeg10[0].y, + "{NAME} luma vs ffmpeg (10-bit)" + ); assert_eq!(frames10[0].u, ffmpeg10[0].u, "{NAME} U vs ffmpeg (10-bit)"); assert_eq!(frames10[0].v, ffmpeg10[0].v, "{NAME} V vs ffmpeg (10-bit)"); let firing10 = crate::decode::sq_chroma_tx_hits() - before10; @@ -31734,7 +34968,8 @@ pub(crate) mod tests { /// tool skips. #[test] fn a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_decodes_pixel_exact() { - const NAME: &str = "a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_decodes_pixel_exact"; + const NAME: &str = + "a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_decodes_pixel_exact"; let _gate_lock = lock_gate_counters(); if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); @@ -31767,7 +35002,12 @@ pub(crate) mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, // REAL chroma (lane-sqchroma r1 dropped the `hue=s=0` // guard this recipe carried): the "PRE-EXISTING square-path // chroma defect" that guard named does not reproduce at @@ -31776,8 +35016,11 @@ pub(crate) mod tests { // `--enable-rect-partitions=0`, and this gate is green with // the filter gone. Its own gate is // `a_real_aomenc_intra_stream_with_tx_size_search_and_chroma_decodes_pixel_exact`. - "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -31817,15 +35060,17 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", String::from_utf8_lossy(&out.stderr) ); let stream = out.stdout; - assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); + assert!( + !stream.is_empty(), + "{NAME}: aomenc wrote an empty stream (seed {seed})" + ); let attempt_before = crate::decode::rect_split_tx_hits(); let frames = match decode_stream(&stream) { Err(e) => { @@ -31876,9 +35121,18 @@ pub(crate) mod tests { diffs.len(), ); } - assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + frames[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + frames[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + frames[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); compared_hits += crate::decode::rect_split_tx_hits() - attempt_before; matched += 1; } @@ -31964,14 +35218,33 @@ pub(crate) mod tests { "geq=lum='128+80*sin(2*PI*Y/{period})':cb='128+60*sin(2*PI*X/{period})':cr=128,\ noise=alls=6:allf=t" ); - let cq = if attempt % 4 < 2 { "--cq-level=20" } else { "--cq-level=40" }; + let cq = if attempt % 4 < 2 { + "--cq-level=20" + } else { + "--cq-level=40" + }; let y4m = Command::new("ffmpeg") .args([ // `-strict -1`: y4m calls 10-bit an unofficial pixel // format and refuses to write the header otherwise (no-op // at 8 bit). - "-v", "error", "-f", "lavfi", "-i", &source, "-vf", &filter, "-t", "0.04", - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-vf", + &filter, + "-t", + "0.04", + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -32027,15 +35300,17 @@ pub(crate) mod tests { "-", "-", ]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", String::from_utf8_lossy(&out.stderr) ); let stream = out.stdout; - assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); + assert!( + !stream.is_empty(), + "{NAME}: aomenc wrote an empty stream (seed {seed})" + ); if ten_bit { let mut probe = Av1Parser::new(); let mut pos = 0usize; @@ -32193,18 +35468,30 @@ pub(crate) mod tests { let seed = 42 + attempt; // Diagnosis knob: which content makes RD pick a HORZ/VERT strip // AND filter intra on it is a search (see this round's report). - let source = match std::env::var("EC_RECTSPLIT_SRC").unwrap_or_default().as_str() { + let source = match std::env::var("EC_RECTSPLIT_SRC") + .unwrap_or_default() + .as_str() + { "bars" => format!("smptebars=size={width}x{height}:duration=0.04:rate=25"), "src2" => format!("testsrc2=size={width}x{height}:duration=0.04:rate=25"), _ => gradients_source(seed, width, height, "duration=0.04:rate=25"), }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, // Real chroma: the `hue=s=0` guard gate (a) carried is // gone (lane-sqchroma r1 -- the square-path chroma defect // it named does not reproduce at HEAD). - "-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-", + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -32282,15 +35569,17 @@ pub(crate) mod tests { other => panic!("unknown EC_RECTSPLIT_OFF entry {other}"), }); } - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", String::from_utf8_lossy(&out.stderr) ); let stream = out.stdout; - assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); + assert!( + !stream.is_empty(), + "{NAME}: aomenc wrote an empty stream (seed {seed})" + ); let attempt_before = crate::decode::filter_intra_rect_hits(); let frames = match decode_stream(&stream) { Err(e) => { @@ -32335,9 +35624,18 @@ pub(crate) mod tests { diffs.len(), ); } - assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + frames[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + frames[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + frames[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); compared_hits += crate::decode::filter_intra_rect_hits() - attempt_before; matched += 1; } @@ -32464,8 +35762,8 @@ pub(crate) mod tests { // sub-16 strip with a SPLIT transform) is ported, so the pinned // stream is now a full pixel compare -- what the doc above said this // test should become the round that ceiling lifted. - let frames = decode_stream(&stream) - .unwrap_or_else(|e| panic!("{NAME}: decode refused: {e}")); + let frames = + decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME}: decode refused: {e}")); let hits = crate::decode::filter_intra_rect_sub16_hits() - before; // TWO now, not the one the truncated decode used to see: the frame // no longer stops at the first filter-intra strip, so the second one @@ -32570,8 +35868,17 @@ pub(crate) mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -32624,15 +35931,17 @@ pub(crate) mod tests { other => panic!("unknown EC_FISTRIP_OFF entry {other}"), }); } - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", String::from_utf8_lossy(&out.stderr) ); let stream = out.stdout; - assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); + assert!( + !stream.is_empty(), + "{NAME}: aomenc wrote an empty stream (seed {seed})" + ); let attempt_before = crate::decode::filter_intra_rect_sub16_hits(); let frames = match decode_stream(&stream) { Err(e) => { @@ -32654,9 +35963,18 @@ pub(crate) mod tests { }; let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); assert_eq!(frames.len(), 1, "{NAME}: expected one frame (seed {seed})"); - assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + frames[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + frames[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + frames[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); compared_hits += crate::decode::filter_intra_rect_sub16_hits() - attempt_before; matched += 1; } @@ -32715,7 +36033,8 @@ pub(crate) mod tests { /// seeds 43 and 50 are pixel-exact. #[test] fn a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact() { - const NAME: &str = "a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact"; + const NAME: &str = + "a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact"; let _gate_lock = lock_gate_counters(); if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); @@ -32748,7 +36067,12 @@ pub(crate) mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, // REAL chroma (lane-sqchroma r1 dropped the `hue=s=0` // guard this recipe carried): the "PRE-EXISTING square-path // chroma defect" that guard named does not reproduce at @@ -32757,8 +36081,11 @@ pub(crate) mod tests { // `--enable-rect-partitions=0`, and this gate is green with // the filter gone. Its own gate is // `a_real_aomenc_intra_stream_with_tx_size_search_and_chroma_decodes_pixel_exact`. - "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -32798,15 +36125,17 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", String::from_utf8_lossy(&out.stderr) ); let stream = out.stdout; - assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); + assert!( + !stream.is_empty(), + "{NAME}: aomenc wrote an empty stream (seed {seed})" + ); let attempt_before = crate::decode::rect_split_sb_interior_tu_hits(); let frames = match decode_stream(&stream) { Err(e) => { @@ -32857,9 +36186,18 @@ pub(crate) mod tests { diffs.len(), ); } - assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + frames[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + frames[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + frames[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); compared_hits += crate::decode::rect_split_sb_interior_tu_hits() - attempt_before; matched += 1; } @@ -32964,8 +36302,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -33007,7 +36344,10 @@ pub(crate) mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -33106,9 +36446,8 @@ pub(crate) mod tests { #[test] #[ignore = "gate recipe never fires the feature (40/40 streams pixel-exact); needs a recipe that produces a rect64 dequant call with CURRENT_Q_IDX != base_q_idx -- class gate-blind-to-feature"] fn a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_and_delta_q_decodes_pixel_exact() - { - const NAME: &str = - "a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_and_delta_q_decodes_pixel_exact"; + { + const NAME: &str = "a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_and_delta_q_decodes_pixel_exact"; let _gate_lock = lock_gate_counters(); if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); @@ -33179,8 +36518,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -33213,7 +36551,10 @@ pub(crate) mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -33364,8 +36705,17 @@ pub(crate) mod tests { }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -33404,8 +36754,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -33469,7 +36818,10 @@ pub(crate) mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -33599,11 +36951,28 @@ pub(crate) mod tests { ) }; let cq_level = format!("--cq-level={}", 24 + (attempt % 4) * 8); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -33655,8 +37024,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -33849,11 +37217,28 @@ pub(crate) mod tests { } else { format!("--cq-level={}", if attempt % 4 < 2 { 32 } else { 63 }) }; - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -33899,8 +37284,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -34081,7 +37465,8 @@ pub(crate) mod tests { for bit_depth in [8u32, 10u32] { let mut named_refusals = 0u32; let mut matched = 0u32; - let (mut fi_horz_proved, mut fi_vert_proved, mut strips_proved) = (0usize, 0usize, 0usize); + let (mut fi_horz_proved, mut fi_vert_proved, mut strips_proved) = + (0usize, 0usize, 0usize); let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32); for attempt in 0..n_attempts { let seed = 42 + attempt; @@ -34102,13 +37487,32 @@ pub(crate) mod tests { // lane-band63: 63 joins the rotation -- filter intra ON at a // near-max quantiser is exactly the configuration the stale // cq-63 premise blamed, and it decodes exact. - let cq_level = - format!("--cq-level={}", [32, 45, 55, 63][(attempt / 2 % 4) as usize]); - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let cq_level = format!( + "--cq-level={}", + [32, 45, 55, 63][(attempt / 2 % 4) as usize] + ); + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), - "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + &duration.to_string(), + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -34163,8 +37567,7 @@ pub(crate) mod tests { "-", "-", ]; - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -34336,13 +37739,30 @@ pub(crate) mod tests { let duration = frame_count as f64 / 25.0; let source = match source_override { Some(src) => format!("{src}=size={width}x{height}:duration={duration}:rate=25"), - None => gradients_source(seed, width, height, &format!("duration={duration}:rate=25")), + None => { + gradients_source(seed, width, height, &format!("duration={duration}:rate=25")) + } + }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" }; - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", pix_fmt, "-strict", - "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -34358,7 +37778,10 @@ pub(crate) mod tests { let rows = format!("--tile-rows={tile_rows_log2}"); let limit = format!("--limit={frame_count}"); let depth_args: Vec = if bit_depth == 10 { - vec!["--input-bit-depth=10".to_owned(), "--bit-depth=10".to_owned()] + vec![ + "--input-bit-depth=10".to_owned(), + "--bit-depth=10".to_owned(), + ] } else { Vec::new() }; @@ -34398,8 +37821,7 @@ pub(crate) mod tests { args.extend(extra.iter().copied()); args.extend(depth_args.iter().map(String::as_str)); args.extend(["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -34415,7 +37837,9 @@ pub(crate) mod tests { let mut pos = 0usize; let mut checked = false; while pos < stream.len() { - let obu = probe.parse_obu(&stream[pos..]).expect("parsing the gate stream"); + let obu = probe + .parse_obu(&stream[pos..]) + .expect("parsing the gate stream"); pos += obu.total_size; let header = match &obu.kind { ObuKind::Frame(h, _) => h, @@ -34461,7 +37885,10 @@ pub(crate) mod tests { ); checked = true; } - assert!(checked, "{name}: no frame header in the stream (seed {seed})"); + assert!( + checked, + "{name}: no frame header in the stream (seed {seed})" + ); } let before = crate::decode::tile_hits(); @@ -34501,7 +37928,10 @@ pub(crate) mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{name} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{name} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{name} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{name} frame {i} V vs ffmpeg (seed {seed})"); } @@ -34683,12 +38113,19 @@ pub(crate) mod tests { 0, 8, 1, - &["--enable-palette=1", "--tune-content=screen", "--cq-level=30", "--enable-tx-size-search=0", "--max-partition-size=32", + &[ + "--enable-palette=1", + "--tune-content=screen", + "--cq-level=30", + "--enable-tx-size-search=0", + "--max-partition-size=32", // Screen content + rect strips is a separate, pre-existing // refusal ("palette syntax is consumed for square blocks // only"); this arm owns the palette CACHE at a tile edge, so // it takes the square-only path the other palette gates take. - "--enable-rect-partitions=0", "--enable-ab-partitions=0"], + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + ], true, Some("smptebars"), ); @@ -34738,7 +38175,7 @@ pub(crate) mod tests { /// scan-weights-cross-axis). #[test] fn a_real_aomenc_stream_with_a_coded_strip_whose_chroma_is_a_4to1_or_sub8_rect_decodes_pixel_exact() - { + { const NAME: &str = "a_real_aomenc_stream_with_a_coded_strip_whose_chroma_is_a_4to1_or_sub8_rect_decodes_pixel_exact"; // No seed is excluded any more: seed 46's cq-32 mismatch was the // per-transform-unit reach (lane-band46 / palette2 r12), and the pin @@ -34780,7 +38217,14 @@ pub(crate) mod tests { // counter-from-refused-stream: only attempts that compared exact // count). let mut depth1_decoded = 0usize; - for (bit_depth, cq) in [(8u32, 45u32), (8, 32), (8, 60), (10, 45), (10, 32), (10, 60)] { + for (bit_depth, cq) in [ + (8u32, 45u32), + (8, 32), + (8, 60), + (10, 45), + (10, 32), + (10, 60), + ] { for attempt in 0..n_attempts { let seed = 42 + attempt; if EXCLUDED_SEEDS.contains(&seed) { @@ -34842,9 +38286,11 @@ pub(crate) mod tests { // silently dropped -- selection is on "the stream carries // the feature", never on "the stream decoded correctly". out_of_scope += 1; - if frames.iter().zip(&reference).any(|(g, w)| { - g.y != w.y || g.u != w.u || g.v != w.v - }) { + if frames + .iter() + .zip(&reference) + .any(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v) + { out_of_scope_mismatch += 1; eprintln!( "{NAME}: {bit_depth}-bit cq {cq} seed {seed} MISMATCHES with zero \ @@ -34943,7 +38389,11 @@ pub(crate) mod tests { ) -> Vec { const NAME: &str = "rectchroma_stream"; let seed = 42 + attempt; - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; // `gradients_source`, the content the sibling split-transform // superblock gate uses. A band/noise `geq` fixture was tried // first (r1) and gave 12/12 pixel-exact streams carrying ZERO @@ -34955,14 +38405,25 @@ pub(crate) mod tests { let source = if attempt % 2 == 0 { format!("color=c=black:size={width}x{height}:duration=0.04:rate=25,{bands}") } else { - format!( - "color=c=black:size={height}x{width}:duration=0.04:rate=25,{bands},transpose=1" - ) + format!("color=c=black:size={height}x{width}:duration=0.04:rate=25,{bands},transpose=1") }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", "0.04", "-pix_fmt", - pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + "0.04", + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -34977,8 +38438,8 @@ pub(crate) mod tests { let cq_arg = format!("--cq-level={cq}"); let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -35016,7 +38477,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -35054,14 +38517,22 @@ pub(crate) mod tests { }; assert_eq!(frames.len(), reference.len(), "{NAME}: frame count"); for (i, (got, want)) in frames.iter().zip(&reference).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma ({bit_depth}-bit seed 46)"); - assert_eq!(got.u, want.u, "{NAME} frame {i} U ({bit_depth}-bit seed 46)"); - assert_eq!(got.v, want.v, "{NAME} frame {i} V ({bit_depth}-bit seed 46)"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma ({bit_depth}-bit seed 46)" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U ({bit_depth}-bit seed 46)" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V ({bit_depth}-bit seed 46)" + ); } } } - /// lane-band46 r1: a real `aomenc` band stream whose 16x16 (and 8x8) /// intra blocks SPLIT their transform, so every unit but the first /// answers `has_top_right`/`has_bottom_left` from its `row_off`/`col_off` @@ -35099,7 +38570,11 @@ pub(crate) mod tests { let mut fixed_tus_10bit = 0usize; let mut seed46_compared = [false; 2]; for (di, bit_depth) in [8u32, 10].into_iter().enumerate() { - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; for seed in 42u32..=51 { // Byte-identical recipe to the 1:4-strip sibling gate, whose // seed-46 attempt is what exposed this defect (that gate @@ -35117,8 +38592,21 @@ pub(crate) mod tests { }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", "0.04", "-pix_fmt", - pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + "0.04", + "-pix_fmt", + pix_fmt, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -35132,8 +38620,8 @@ pub(crate) mod tests { ); let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -35162,7 +38650,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -35228,7 +38718,8 @@ pub(crate) mod tests { assert!( seed46_compared[0] && seed46_compared[1], "{NAME}: seed 46 was not compared on both depths (8-bit {}, 10-bit {})", - seed46_compared[0], seed46_compared[1] + seed46_compared[0], + seed46_compared[1] ); assert!( fixed_tus > 0, @@ -35298,107 +38789,142 @@ pub(crate) mod tests { // resolves to TX_4X4 -- whose txfm context this round fixed -- // was unreachable by construction. The second arm turns it on. for tx_search in [0usize, 1] { - for depth in [8usize, 10] { - let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; - let y4m = Command::new("ffmpeg") - .args([ - "-v", "error", "-f", "lavfi", "-i", - &if flat { - format!("color=c=gray:size={width}x{height}") - } else { - format!("mandelbrot=size={width}x{height}:start_x=-0.6") - }, - "-pix_fmt", pix, "-strict", "-1", "-t", "1", "-vframes", "1", - "-f", "yuv4mpegpipe", "-", - ]) - .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .output() - .expect("ffmpeg failed to run"); - assert!( - y4m.status.success(), - "{NAME}: ffmpeg fixture ({width}x{height}, depth={depth}): {}", - String::from_utf8_lossy(&y4m.stderr) - ); - let encode = || { - let out = run_with_stdin(Command::new(aomenc_path()) + for depth in [8usize, 10] { + let pix = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; + let y4m = Command::new("ffmpeg") .args([ - "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", - "--cpu-used=3", "--threads=1", "--row-mt=0", "--sb-size=64", - "--kf-max-dist=0", "--enable-rect-partitions=1", - "--enable-ab-partitions=0", "--enable-1to4-partitions=0", - &format!("--enable-tx-size-search={tx_search}"), - "--reduced-tx-type-set=1", - "--min-partition-size=8", "--max-partition-size=64", - &format!("--input-bit-depth={depth}"), - &format!("--bit-depth={depth}"), - "--obu", "-o", "-", "-", - ]), &y4m.stdout); + "-v", + "error", + "-f", + "lavfi", + "-i", + &if flat { + format!("color=c=gray:size={width}x{height}") + } else { + format!("mandelbrot=size={width}x{height}:start_x=-0.6") + }, + "-pix_fmt", + pix, + "-strict", + "-1", + "-t", + "1", + "-vframes", + "1", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); assert!( - out.status.success(), - "aomenc refused the fixture ({width}x{height}, depth={depth}): {}", - String::from_utf8_lossy(&out.stderr) + y4m.status.success(), + "{NAME}: ffmpeg fixture ({width}x{height}, depth={depth}): {}", + String::from_utf8_lossy(&y4m.stderr) ); - out.stdout - }; - let stream = encode(); - assert_eq!( - stream, - encode(), - "{NAME}: aomenc output is not reproducible ({width}x{height}, depth={depth})" - ); - crate::decode::reset_edge_part_hits(); - crate::decode::reset_skip_split_tx_hits(); - let frames = match decode_stream(&stream) { - Ok(frames) => frames, - Err(e) => { - let msg = e.to_string(); - assert!( - msg.contains("unsupported"), - "{NAME}: decode failed ({width}x{height}, depth={depth}): {msg}" + let encode = || { + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=32", + "--cpu-used=3", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--kf-max-dist=0", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + &format!("--enable-tx-size-search={tx_search}"), + "--reduced-tx-type-set=1", + "--min-partition-size=8", + "--max-partition-size=64", + &format!("--input-bit-depth={depth}"), + &format!("--bit-depth={depth}"), + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, ); - eprintln!( - "{NAME}: {width}x{height} depth={depth} arm refused (not compared): {msg}" + assert!( + out.status.success(), + "aomenc refused the fixture ({width}x{height}, depth={depth}): {}", + String::from_utf8_lossy(&out.stderr) ); - continue; - } - }; - let hits = crate::decode::edge_part_hits(); - let skip_split_tx = crate::decode::skip_split_tx_hits(); - let ffmpeg_frames = if depth == 10 { - ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) - } else { - ffmpeg_decode_sequence(&stream, width, height, frames.len()) - }; - assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count"); - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!( - got.y, want.y, - "{NAME} frame {i} luma vs ffmpeg ({width}x{height}, depth={depth}, \ - edge bits horz/split 64-level {}/{}, sub-level {}/{})", - hits[0], hits[1], hits[2], hits[3] - ); + out.stdout + }; + let stream = encode(); assert_eq!( - got.u, want.u, - "{NAME} frame {i} U vs ffmpeg ({width}x{height}, depth={depth})" + stream, + encode(), + "{NAME}: aomenc output is not reproducible ({width}x{height}, depth={depth})" ); + crate::decode::reset_edge_part_hits(); + crate::decode::reset_skip_split_tx_hits(); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME}: decode failed ({width}x{height}, depth={depth}): {msg}" + ); + eprintln!( + "{NAME}: {width}x{height} depth={depth} arm refused (not compared): {msg}" + ); + continue; + } + }; + let hits = crate::decode::edge_part_hits(); + let skip_split_tx = crate::decode::skip_split_tx_hits(); + let ffmpeg_frames = if depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) + } else { + ffmpeg_decode_sequence(&stream, width, height, frames.len()) + }; assert_eq!( - got.v, want.v, - "{NAME} frame {i} V vs ffmpeg ({width}x{height}, depth={depth})" + ffmpeg_frames.len(), + frames.len(), + "{NAME}: ffmpeg frame count" ); - } - compared += 1; - edge_horz_total += hits[0]; - edge_sub_total += hits[2]; - skip_split_tx_total += skip_split_tx; - eprintln!( - "{NAME}: pixel-exact {width}x{height} at {depth}-bit tx_search={tx_search}, \ + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg ({width}x{height}, depth={depth}, \ + edge bits horz/split 64-level {}/{}, sub-level {}/{})", + hits[0], hits[1], hits[2], hits[3] + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg ({width}x{height}, depth={depth})" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg ({width}x{height}, depth={depth})" + ); + } + compared += 1; + edge_horz_total += hits[0]; + edge_sub_total += hits[2]; + skip_split_tx_total += skip_split_tx; + eprintln!( + "{NAME}: pixel-exact {width}x{height} at {depth}-bit tx_search={tx_search}, \ edge bits 64-level horz/vert={} split={} sub-level horz/vert={} split={}, \ skipped 8x8 leaves with TX_4X4 {skip_split_tx}", - hits[0], hits[1], hits[2], hits[3] - ); - } + hits[0], hits[1], hits[2], hits[3] + ); + } } } assert!( @@ -35423,7 +38949,9 @@ pub(crate) mod tests { // that arm is asserted by the pinned film fixture // `the_reelb_ss600_key_frame_skipped_split_tx_decodes_pixel_exact` // instead; this counter is reported, not gated. - eprintln!("{NAME}: {skip_split_tx_total} skipped 8x8 TX_4X4 leaves across compared attempts"); + eprintln!( + "{NAME}: {skip_split_tx_total} skipped 8x8 TX_4X4 leaves across compared attempts" + ); } /// lane-rectchroma2 r1, the defect this gate exists for: our inter path @@ -35472,13 +39000,28 @@ pub(crate) mod tests { .enumerate() { for (di, depth) in [8usize, 10].into_iter().enumerate() { - let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", + "-v", + "error", + "-f", + "lavfi", + "-i", &format!("mandelbrot=size={width}x{height}:rate=25"), - "-pix_fmt", pix, "-strict", "-1", "-vframes", &FRAMES.to_string(), - "-f", "yuv4mpegpipe", "-", + "-pix_fmt", + pix, + "-strict", + "-1", + "-vframes", + &FRAMES.to_string(), + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -35492,31 +39035,52 @@ pub(crate) mod tests { ); for cq in [20usize, 32, 45] { let encode = || { - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", "--passes=1", "--end-usage=q", + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", &format!("--cq-level={cq}"), - "--cpu-used=4", "--threads=1", "--row-mt=0", - "--kf-max-dist=9999", &format!("--limit={FRAMES}"), + "--cpu-used=4", + "--threads=1", + "--row-mt=0", + "--kf-max-dist=9999", + &format!("--limit={FRAMES}"), "--lag-in-frames=0", &format!("--bit-depth={depth}"), &format!("--input-bit-depth={depth}"), // Rect partitions ON is the whole point; every // other tool below is another lane's open gap // that would refuse before a pixel compare. - "--enable-rect-partitions=1", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--min-partition-size=8", - "--max-partition-size=64", "--enable-palette=0", - "--enable-intrabc=0", "--enable-warped-motion=0", - "--enable-obmc=0", "--enable-masked-comp=0", - "--enable-interintra-comp=0", "--enable-onesided-comp=0", - "--enable-interintra-wedge=0", "--enable-smooth-interintra=0", - "--enable-ref-frame-mvs=0", "--enable-angle-delta=0", - "--enable-cfl-intra=0", "--enable-directional-intra=0", - "--enable-smooth-intra=0", "--enable-paeth-intra=0", - "--enable-filter-intra=0", "--enable-tx-size-search=0", - "--obu", "-o", "-", "-", - ]), &y4m.stdout); + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=8", + "--max-partition-size=64", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-warped-motion=0", + "--enable-obmc=0", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-onesided-comp=0", + "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", + "--enable-ref-frame-mvs=0", + "--enable-angle-delta=0", + "--enable-cfl-intra=0", + "--enable-directional-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-filter-intra=0", + "--enable-tx-size-search=0", + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture ({width}x{height}, depth={depth}, \ @@ -35603,16 +39167,17 @@ pub(crate) mod tests { narrow_by_depth[0] > 0 && narrow_by_depth[1] > 0, "{NAME}: no rect-chroma narrow kernel fired at 8-bit ({}) or 10-bit ({}) -- the \ recipe lost the shape this gate pins", - narrow_by_depth[0], narrow_by_depth[1] + narrow_by_depth[0], + narrow_by_depth[1] ); assert!( narrow_by_shape[0] > 0 && narrow_by_shape[1] > 0, "{NAME}: the shape fired in only one orientation (192x128 {}, 128x192 {})", - narrow_by_shape[0], narrow_by_shape[1] + narrow_by_shape[0], + narrow_by_shape[1] ); } - /// lane-intra14 r1's decisive gate: a real aomenc INTER sequence with /// `--enable-1to4-partitions=1`, whose fast-zooming content makes aomenc /// code INTRA blocks inside inter frames on 1:4 strip shapes (32x8/8x32 at @@ -35712,9 +39277,29 @@ pub(crate) mod tests { ); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-vf", "hue=s=0", "-pix_fmt", - if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, - "-strict", "-1", "-t", "0.32", "-f", "yuv4mpegpipe", "-strict", "-1", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-vf", + "hue=s=0", + "-pix_fmt", + if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }, + "-strict", + "-1", + "-t", + "0.32", + "-f", + "yuv4mpegpipe", + "-strict", + "-1", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -35737,82 +39322,89 @@ pub(crate) mod tests { let cpu = format!("--cpu-used={}", 1 + attempt % 4); // The higher the quantiser the more 1:4 intra strips inside inter // frames, so the sweep walks cq 63 first. - let cq = format!("--cq-level={}", [63u32, 55, 45, 35][(attempt / 4) as usize % 4]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(depth_args) - .arg(&cpu) - .arg(&cq) - .args([ - // Every flag spelled exactly once (class - // [[aomenc-last-flag-wins]]). These are what the gate is - // about: 1:4 partitions ON, min size 16 so the 16x16-level - // 1:4 (refused elsewhere) is out of reach. - "--enable-rect-partitions=1", - "--enable-1to4-partitions=1", - // MEASURED (r1): at `--min-partition-size=16` aomenc codes - // 16x16-level 1:4 partitions (16x4/4x16 strips), which the - // inter partition path refuses by name (another lane's - // surface) in 12/40 attempts. 32 keeps this gate's two - // reachable levels -- the 32-level 32x8/8x32 and the - // superblock-level 64x16/16x64 -- and nothing else. - "--min-partition-size=32", - "--max-partition-size=64", - // MEASURED (r1): with tx-size search ON, 8/40 attempts stop - // at the 2:1 strip's own split-tx refusal (merge-cross-product, - // another lane's surface) before a 1:4 strip is reached. - "--enable-tx-size-search=0", - "--enable-filter-intra=1", - "--enable-intra-edge-filter=1", - "--codec=av1", - "--passes=1", - "--end-usage=q", - "--lag-in-frames=0", - "--auto-alt-ref=0", - "--kf-min-dist=1000", - "--kf-max-dist=1000", - "--threads=1", - "--row-mt=0", - "--enable-order-hint=0", - "--enable-warped-motion=0", - "--enable-obmc=0", - "--enable-masked-comp=0", - "--enable-interintra-comp=0", - "--enable-dist-wtd-comp=0", - "--enable-diff-wtd-comp=0", - "--enable-onesided-comp=0", - "--enable-interintra-wedge=0", - "--enable-smooth-interintra=0", - "--enable-ab-partitions=0", - "--enable-smooth-intra=0", - "--enable-paeth-intra=0", - "--enable-directional-intra=0", - "--enable-angle-delta=0", - "--enable-cdef=0", - "--enable-restoration=0", - // Ledger dead-end (lane-r14): a NEW gate spelling - // `--enable-cfl-intra=1` retires that tool from - // `NEVER_EXERCISED_8BIT` on the flag alone while no CfL - // hit counter exists to assert -- so it stays 0 here. - // Palette stays 0 for the same class of reason: this arm - // refuses a screen-content frame whole, so a palette flag - // would buy no coverage. - "--enable-palette=0", - "--enable-intrabc=0", - "--enable-cfl-intra=0", - "--enable-ref-frame-mvs=0", - "--obu", - "-o", - "-", - "-", - ]), &y4m.stdout); + let cq = format!( + "--cq-level={}", + [63u32, 55, 45, 35][(attempt / 4) as usize % 4] + ); + let out = run_with_stdin( + Command::new(aomenc_path()) + .args(depth_args) + .arg(&cpu) + .arg(&cq) + .args([ + // Every flag spelled exactly once (class + // [[aomenc-last-flag-wins]]). These are what the gate is + // about: 1:4 partitions ON, min size 16 so the 16x16-level + // 1:4 (refused elsewhere) is out of reach. + "--enable-rect-partitions=1", + "--enable-1to4-partitions=1", + // MEASURED (r1): at `--min-partition-size=16` aomenc codes + // 16x16-level 1:4 partitions (16x4/4x16 strips), which the + // inter partition path refuses by name (another lane's + // surface) in 12/40 attempts. 32 keeps this gate's two + // reachable levels -- the 32-level 32x8/8x32 and the + // superblock-level 64x16/16x64 -- and nothing else. + "--min-partition-size=32", + "--max-partition-size=64", + // MEASURED (r1): with tx-size search ON, 8/40 attempts stop + // at the 2:1 strip's own split-tx refusal (merge-cross-product, + // another lane's surface) before a 1:4 strip is reached. + "--enable-tx-size-search=0", + "--enable-filter-intra=1", + "--enable-intra-edge-filter=1", + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--lag-in-frames=0", + "--auto-alt-ref=0", + "--kf-min-dist=1000", + "--kf-max-dist=1000", + "--threads=1", + "--row-mt=0", + "--enable-order-hint=0", + "--enable-warped-motion=0", + "--enable-obmc=0", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-dist-wtd-comp=0", + "--enable-diff-wtd-comp=0", + "--enable-onesided-comp=0", + "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", + "--enable-ab-partitions=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-cdef=0", + "--enable-restoration=0", + // Ledger dead-end (lane-r14): a NEW gate spelling + // `--enable-cfl-intra=1` retires that tool from + // `NEVER_EXERCISED_8BIT` on the flag alone while no CfL + // hit counter exists to assert -- so it stays 0 here. + // Palette stays 0 for the same class of reason: this arm + // refuses a screen-content frame whole, so a palette flag + // would buy no coverage. + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", String::from_utf8_lossy(&out.stderr) ); let stream = out.stdout; - let before: Vec = - (0..4).map(decode::intra_rect4_strip_in_inter_hits).collect(); + let before: Vec = (0..4) + .map(decode::intra_rect4_strip_in_inter_hits) + .collect(); let frames = match decode_stream(&stream) { Ok(frames) => frames, Err(e) => { @@ -35993,7 +39585,11 @@ pub(crate) mod tests { "-vf", "hue=s=0", "-pix_fmt", - if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, + if bit_depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }, "-strict", "-1", "-t", @@ -36021,9 +39617,8 @@ pub(crate) mod tests { }; let cq_arg = format!("--cq-level={cq}"); let cpu_arg = format!("--cpu-used={cpu}"); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(depth_args) - .args([ + let out = run_with_stdin( + Command::new(aomenc_path()).args(depth_args).args([ "--codec=av1", "--passes=1", "--end-usage=q", @@ -36070,7 +39665,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]), &y4m.stdout); + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -36137,7 +39734,10 @@ pub(crate) mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed} cq {cq})"); + assert_eq!( + got.y, want.y, + "frame {i} luma vs ffmpeg (seed {seed} cq {cq})" + ); assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed} cq {cq})"); assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed} cq {cq})"); } @@ -36158,7 +39758,10 @@ pub(crate) mod tests { uncounted_exact, refusals.len() - uncounted_exact as usize, ); - eprintln!("{name}: split strips seen depth1={} depth2={}", seen[1], seen[2]); + eprintln!( + "{name}: split strips seen depth1={} depth2={}", + seen[1], seen[2] + ); assert!( seen[1] + seen[2] != 0, "{name} never observed a split-transform intra strip in an inter frame:\n{}", @@ -36217,46 +39820,66 @@ pub(crate) mod tests { let (width, height, frame_count) = (256usize, 192usize, 10usize); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", "testsrc2=s=256x192:r=25", "-t", "0.4", - "-pix_fmt", "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + "testsrc2=s=256x192:r=25", + "-t", + "0.4", + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() .expect("ffmpeg failed to run"); - assert!(y4m.status.success(), "{name}: ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); + assert!( + y4m.status.success(), + "{name}: ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); // The source stays 8-bit for both arms: `--bit-depth=10 // --input-bit-depth=8` is the recipe that was measured to reach the // refusal, and the arm's point is the coded syntax, not the input. let depth_arg = format!("--bit-depth={bit_depth}"); let cq_arg = format!("--cq-level={}", if bit_depth == 10 { 45 } else { 40 }); - let out = run_with_stdin(Command::new(aomenc_path()) - .args([ - "--codec=av1", - "--passes=1", - "--end-usage=q", - "--cpu-used=0", - "--lag-in-frames=0", - "--kf-max-dist=30", - "--limit=10", - "--threads=1", - "--tile-columns=0", - "--enable-rect-partitions=1", - "--enable-1to4-partitions=1", - "--min-partition-size=8", - "--sb-size=64", - "--input-bit-depth=8", - // `allow_screen_content_tools` in every frame header comes - // from here; the two searches below stay off so the KEY frame - // does not stop on a palette/intrabc RECONSTRUCTION refusal - // before an inter frame exists. - "--tune-content=screen", - "--enable-palette=0", - "--enable-intrabc=0", - ]) - .args([&depth_arg, &cq_arg]) - .args(["--obu", "-o", "-", "-"]), &y4m.stdout); + let out = run_with_stdin( + Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cpu-used=0", + "--lag-in-frames=0", + "--kf-max-dist=30", + "--limit=10", + "--threads=1", + "--tile-columns=0", + "--enable-rect-partitions=1", + "--enable-1to4-partitions=1", + "--min-partition-size=8", + "--sb-size=64", + "--input-bit-depth=8", + // `allow_screen_content_tools` in every frame header comes + // from here; the two searches below stay off so the KEY frame + // does not stop on a palette/intrabc RECONSTRUCTION refusal + // before an inter frame exists. + "--tune-content=screen", + "--enable-palette=0", + "--enable-intrabc=0", + ]) + .args([&depth_arg, &cq_arg]) + .args(["--obu", "-o", "-", "-"]), + &y4m.stdout, + ); assert!( out.status.success(), "{name}: aomenc refused the fixture: {}", @@ -36268,7 +39891,10 @@ pub(crate) mod tests { panic!("{name}: decode failed -- the case this gate exists for: {e}") }); let strips = decode::intra_rect_in_inter_screen_hits(); - eprintln!("{name}: {} frames, {strips} rect intra strip(s) read the palette syntax", frames.len()); + eprintln!( + "{name}: {} frames, {strips} rect intra strip(s) read the palette syntax", + frames.len() + ); assert_eq!(frames.len(), frame_count, "{name}: frame count"); let ffmpeg_frames = if bit_depth == 10 { ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) @@ -36342,7 +39968,8 @@ pub(crate) mod tests { Err(e) => panic!("{NAME}: decode_stream refused: {e}"), }; let now = intra_rect4_in_inter_counters(); - let fired = (now.0 - before.0) + (now.1 - before.1) + (now.2 - before.2) + (now.3 - before.3); + let fired = + (now.0 - before.0) + (now.1 - before.1) + (now.2 - before.2) + (now.3 - before.3); assert!( fired > 0, "{NAME}: zero intra 1:4 strips in an inter frame (64x16/16x64/32x8/8x32 = \ @@ -36358,7 +39985,11 @@ pub(crate) mod tests { // 18524160 bytes, one 3840x1608 10-bit frame, so the second is a // no-show frame and `frames.len() == 2` was never true. The compare is // not vacuous: ffmpeg's own frame count is asserted equal to ours. - assert_eq!(frames.len(), 1, "{NAME}: one shown frame (the second frame OBU is a no-show)"); + assert_eq!( + frames.len(), + 1, + "{NAME}: one shown frame (the second frame OBU is a no-show)" + ); assert_eq!((frames[0].width, frames[0].height), (width, height)); let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()); assert_eq!( @@ -36373,7 +40004,9 @@ pub(crate) mod tests { assert_eq!(ours.u, theirs.u, "{NAME}: frame {i} U vs ffmpeg"); assert_eq!(ours.v, theirs.v, "{NAME}: frame {i} V vs ffmpeg"); } - eprintln!("{NAME}: {fired} intra 1:4 strips in an inter frame, the shown frame pixel-exact"); + eprintln!( + "{NAME}: {fired} intra 1:4 strips in an inter frame, the shown frame pixel-exact" + ); } /// lane-sub8x4 r3 / lane-wit16x4 r1: the FILM witness for the un-split @@ -36540,7 +40173,10 @@ pub(crate) mod tests { assert_eq!(a.2.u, b.2.u, "{NAME}: {fixture} sink {i} U"); assert_eq!(a.2.v, b.2.v, "{NAME}: {fixture} sink {i} V"); } - eprintln!("{NAME}: {fixture} {} sink calls identical, {dispatched} decoded on workers", serial.len()); + eprintln!( + "{NAME}: {fixture} {} sink calls identical, {dispatched} decoded on workers", + serial.len() + ); } } @@ -36574,8 +40210,8 @@ pub(crate) mod tests { eprintln!("SKIP {NAME}: no ffmpeg"); return; } - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) - .join("fixtures/reelb_arf_witness.obu"); + let path = + std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/reelb_arf_witness.obu"); let stream = std::fs::read(&path) .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); let (width, height) = (3840usize, 1608usize); @@ -36822,7 +40458,8 @@ pub(crate) mod tests { /// #[test] fn a_128_superblock_stream_whose_skipped_blocks_are_var_tx_decodes_pixel_exact() { - const NAME: &str = "a_128_superblock_stream_whose_skipped_blocks_are_var_tx_decodes_pixel_exact"; + const NAME: &str = + "a_128_superblock_stream_whose_skipped_blocks_are_var_tx_decodes_pixel_exact"; if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); return; @@ -36918,8 +40555,7 @@ pub(crate) mod tests { /// byte-exact against ffmpeg (class `counter-from-refused-stream`). #[test] fn an_intra_coded_128_half_inside_an_inter_frame_decodes_pixel_exact() { - const NAME: &str = - "an_intra_coded_128_half_inside_an_inter_frame_decodes_pixel_exact"; + const NAME: &str = "an_intra_coded_128_half_inside_an_inter_frame_decodes_pixel_exact"; if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); return; @@ -37037,7 +40673,11 @@ pub(crate) mod tests { assert_eq!(frames.len(), 15, "{NAME}: 15 shown frames"); assert_eq!((frames[0].width, frames[0].height), (width, height)); let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()); - assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: frame count vs ffmpeg"); + assert_eq!( + ffmpeg_frames.len(), + frames.len(), + "{NAME}: frame count vs ffmpeg" + ); for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() { assert_eq!(ours.y, theirs.y, "{NAME}: frame {i} luma vs ffmpeg"); assert_eq!(ours.u, theirs.u, "{NAME}: frame {i} U vs ffmpeg"); @@ -37077,8 +40717,7 @@ pub(crate) mod tests { /// different range). #[test] fn a_real_aomenc_screen_stream_with_palette_blocks_decodes_pixel_exact() { - const NAME: &str = - "a_real_aomenc_screen_stream_with_palette_blocks_decodes_pixel_exact"; + const NAME: &str = "a_real_aomenc_screen_stream_with_palette_blocks_decodes_pixel_exact"; if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); return; @@ -37115,9 +40754,18 @@ pub(crate) mod tests { "{NAME} [{fixture}]: frame count" ); for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(ours.y, theirs.y, "{NAME} [{fixture}]: frame {i} luma vs ffmpeg"); - assert_eq!(ours.u, theirs.u, "{NAME} [{fixture}]: frame {i} U vs ffmpeg"); - assert_eq!(ours.v, theirs.v, "{NAME} [{fixture}]: frame {i} V vs ffmpeg"); + assert_eq!( + ours.y, theirs.y, + "{NAME} [{fixture}]: frame {i} luma vs ffmpeg" + ); + assert_eq!( + ours.u, theirs.u, + "{NAME} [{fixture}]: frame {i} U vs ffmpeg" + ); + assert_eq!( + ours.v, theirs.v, + "{NAME} [{fixture}]: frame {i} V vs ffmpeg" + ); } eprintln!( "{NAME} [{fixture}]: 15 frames pixel-exact on every plane; \ @@ -37251,8 +40899,7 @@ pub(crate) mod tests { /// 0 refusals. #[test] fn a_block_shape_census_over_three_real_streams_leaves_the_rect_residual_refusal_unreachable() { - const NAME: &str = - "a_block_shape_census_over_three_real_streams_leaves_the_rect_residual_refusal_unreachable"; + const NAME: &str = "a_block_shape_census_over_three_real_streams_leaves_the_rect_residual_refusal_unreachable"; const REFUSAL: &str = "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding"; let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures"); @@ -37330,8 +40977,7 @@ pub(crate) mod tests { #[test] fn a_sub8_footprint_census_over_real_streams_leaves_the_intra_16x4_pairing_refusal_unreachable() { - const NAME: &str = - "a_sub8_footprint_census_over_real_streams_leaves_the_intra_16x4_pairing_refusal_unreachable"; + const NAME: &str = "a_sub8_footprint_census_over_real_streams_leaves_the_intra_16x4_pairing_refusal_unreachable"; const REFUSAL: &str = "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition"; let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures"); let before = crate::decode::intra16x4_in_inter_hits(); @@ -37473,7 +41119,6 @@ pub(crate) mod tests { ); } - /// lane-t900 r11: the frame-edge MV clamp witness. /// /// `crates/ec-av1/fixtures/reelb_head_mvclamp_witness.obu` (72158 bytes, @@ -37564,7 +41209,8 @@ pub(crate) mod tests { /// rests on a stream that never carried its shape. #[test] fn a_real_aomenc_inter_sequence_with_intra_sub8x8_leaves_decodes_pixel_exact() { - const NAME: &str = "a_real_aomenc_inter_sequence_with_intra_sub8x8_leaves_decodes_pixel_exact"; + const NAME: &str = + "a_real_aomenc_inter_sequence_with_intra_sub8x8_leaves_decodes_pixel_exact"; if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); return; @@ -37582,7 +41228,11 @@ pub(crate) mod tests { // One arm's stream, byte for byte: the lavfi source (a moving 24-row // random band over `128+50*sin(x/7)`) feeds aomenc through a pipe. let encode = |depth: u32, cq: u32, width: usize, height: usize, tiles: bool| -> Vec { - let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let pix = if depth == 10 { + "yuv420p10le" + } else { + "yuv420p" + }; let source = format!( "color=c=gray:s={width}x{height}:d=0.24:r=25,format=gray,\ geq=lum='if(lt(mod(Y+N*37\\,{height})\\,24)\\,random(N*100+X+Y)*255\\,128+50*sin(X/7))',\ @@ -37590,8 +41240,21 @@ pub(crate) mod tests { ); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", "0.24", "-pix_fmt", pix, - "-strict", "-1", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + "0.24", + "-pix_fmt", + pix, + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -37633,10 +41296,13 @@ pub(crate) mod tests { args.push("--input-bit-depth=10"); } // AOMENC FLAG PRECEDENCE (COMMON): the per-arm override goes last. - args.push(if tiles { "--tile-columns=1" } else { "--tile-columns=0" }); + args.push(if tiles { + "--tile-columns=1" + } else { + "--tile-columns=0" + }); args.extend(["--obu", "-o", "-", "-"]); - let out = run_with_stdin(Command::new(aomenc_path()) - .args(&args), &y4m.stdout); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture (depth={depth} cq={cq} {width}x{height}): {}", @@ -37672,7 +41338,8 @@ pub(crate) mod tests { // stream before any measurement rests on it. let again = encode(depth, cq, width, height, tiles); assert_eq!( - stream, again, + stream, + again, "{NAME}: the fixture recipe is not reproducible ({arm}, {} vs {} bytes)", stream.len(), again.len() @@ -37693,7 +41360,12 @@ pub(crate) mod tests { continue; } }; - assert_eq!(frames.len(), FRAMES, "{NAME}: {arm} decoded {} frames", frames.len()); + assert_eq!( + frames.len(), + FRAMES, + "{NAME}: {arm} decoded {} frames", + frames.len() + ); assert!( !tiles || decode::tile_hits() - tiles_before >= 2, "{NAME}: {arm} decoded only {} tile(s)", @@ -37749,7 +41421,6 @@ pub(crate) mod tests { ); } - /// lane-thread1: every per-frame/per-stream decode state now lives in /// [`crate::decode::FrameCtx`], not in a `thread_local!`. A static that /// comes back would silently re-break frame-parallel decoding (a worker @@ -37758,14 +41429,43 @@ pub(crate) mod tests { #[test] fn no_per_frame_state_is_thread_local_any_more() { const MOVED: [&str; 38] = [ - "SB128", "CDEF_BITS", "BIT_DEPTH", "SUPERRES", "CDEF_TRANSMITTED", "CDEF_SB_COLS", - "CDEF_IDX_GRID", "DELTA_Q_PRESENT", "DELTA_Q_RES", "CURRENT_Q_IDX", "QUANT_DELTAS", - "DELTA_LF_PRESENT", "DELTA_LF_RES", "DELTA_LF_MULTI", "CURRENT_DELTA_LF", "SEG", - "SEG_IDS", "PREV_SEG_IDS", "SEG_MI_DIMS", "ABOVE_SEG_PRED", "LEFT_SEG_PRED", - "CUR_SEGMENT_ID", "SEG_TILE_ORIGIN", "TX_SELECT_INTER", "REDUCED_TX_SET_INTER", - "ENABLE_FILTER_INTRA_INTER", "PALETTE_PRED", "INTRABC_MI_GRID", "INTRABC_DV", - "LUMA_TX_TYPE", "INTRABC_CHROMA_TX", "INTRA_IN_INTER_MODE", "INTER_STRIP_CHROMA", - "INTER_LAST_MC", "ENABLE_EDGE_FILTER", "LAST_FRAME_WIDE_MARGIN", "REACH_SB_PX", + "SB128", + "CDEF_BITS", + "BIT_DEPTH", + "SUPERRES", + "CDEF_TRANSMITTED", + "CDEF_SB_COLS", + "CDEF_IDX_GRID", + "DELTA_Q_PRESENT", + "DELTA_Q_RES", + "CURRENT_Q_IDX", + "QUANT_DELTAS", + "DELTA_LF_PRESENT", + "DELTA_LF_RES", + "DELTA_LF_MULTI", + "CURRENT_DELTA_LF", + "SEG", + "SEG_IDS", + "PREV_SEG_IDS", + "SEG_MI_DIMS", + "ABOVE_SEG_PRED", + "LEFT_SEG_PRED", + "CUR_SEGMENT_ID", + "SEG_TILE_ORIGIN", + "TX_SELECT_INTER", + "REDUCED_TX_SET_INTER", + "ENABLE_FILTER_INTRA_INTER", + "PALETTE_PRED", + "INTRABC_MI_GRID", + "INTRABC_DV", + "LUMA_TX_TYPE", + "INTRABC_CHROMA_TX", + "INTRA_IN_INTER_MODE", + "INTER_STRIP_CHROMA", + "INTER_LAST_MC", + "ENABLE_EDGE_FILTER", + "LAST_FRAME_WIDE_MARGIN", + "REACH_SB_PX", "GRAIN_BIT_DEPTH", ]; let sources = [ @@ -37797,7 +41497,6 @@ pub(crate) mod tests { ); } - /// lane-d792: a frame whose height the superblock grid CUTS, decoded /// against ffmpeg on every ladder point of BOTH reference encoders. /// @@ -37843,13 +41542,41 @@ pub(crate) mod tests { let flat = format!("color=c=gray:s={half}x{h}:r=25:d=1"); let busy = format!("{flat},noise=alls=80:all_seed=7:allf=t+u"); let args: Vec = [ - "-v", "error", "-f", "lavfi", "-i", &flat, "-f", "lavfi", "-i", &busy, - "-filter_complex", "[0:v][1:v]hstack=inputs=2,format=yuv420p", - "-frames:v", &FRAMES.to_string(), "-pix_fmt", "yuv420p", "-an", - "-threads", "1", "-g", &FRAMES.to_string(), "-c:v", "libaom-av1", - "-cpu-used", "6", "-b:v", "0", "-crf", crf, + "-v", + "error", + "-f", + "lavfi", + "-i", + &flat, + "-f", + "lavfi", + "-i", + &busy, + "-filter_complex", + "[0:v][1:v]hstack=inputs=2,format=yuv420p", + "-frames:v", + &FRAMES.to_string(), + "-pix_fmt", + "yuv420p", + "-an", + "-threads", + "1", + "-g", + &FRAMES.to_string(), + "-c:v", + "libaom-av1", + "-cpu-used", + "6", + "-b:v", + "0", + "-crf", + crf, // libaom's activity segmentation, i.e. `SEG_LVL_ALT_Q`. - "-aq-mode", "1", "-f", "obu", "-", + "-aq-mode", + "1", + "-f", + "obu", + "-", ] .iter() .map(|s| (*s).to_string()) @@ -37864,7 +41591,10 @@ pub(crate) mod tests { if !out.status.success() { eprintln!( "SKIP {NAME}: ffmpeg cannot encode the segmented {w}x{h} recipe ({})", - String::from_utf8_lossy(&out.stderr).lines().last().unwrap_or("") + String::from_utf8_lossy(&out.stderr) + .lines() + .last() + .unwrap_or("") ); continue; } @@ -37882,7 +41612,11 @@ pub(crate) mod tests { would pass with the rect dequant defect back in ({} segment ids seen)", crate::decode::segment_ids_seen() ); - assert_eq!(got.len(), want.len(), "{NAME}: segmented {w}x{h} frame count"); + assert_eq!( + got.len(), + want.len(), + "{NAME}: segmented {w}x{h} frame count" + ); for (f, (o, r)) in got.iter().zip(&want).enumerate() { for (plane, a, b) in [("Y", &o.y, &r.y), ("U", &o.u, &r.u), ("V", &o.v, &r.v)] { if let Some(i) = a.iter().zip(b.iter()).position(|(x, y)| x != y) { @@ -37898,9 +41632,7 @@ pub(crate) mod tests { } } } - eprintln!( - "{NAME}: segmented {w}x{h} crf {crf} exact, block q span {lo}..{hi}" - ); + eprintln!("{NAME}: segmented {w}x{h} crf {crf} exact, block q span {lo}..{hi}"); checked += 1; } } @@ -37954,9 +41686,18 @@ pub(crate) mod tests { // `-aq-mode 1`: libaom's activity segmentation, // i.e. `SEG_LVL_ALT_Q` -- the feature the rect // dequant path used to drop. - ["-cpu-used", "6", "-b:v", "0", "-crf", point, "-aq-mode", "1"] - .iter() - .map(|s| (*s).to_string()), + [ + "-cpu-used", + "6", + "-b:v", + "0", + "-crf", + point, + "-aq-mode", + "1", + ] + .iter() + .map(|s| (*s).to_string()), ); } args.extend(["-f", "obu", "-"].iter().map(|s| (*s).to_string())); @@ -37970,7 +41711,10 @@ pub(crate) mod tests { if !out.status.success() { eprintln!( "SKIP {NAME}: ffmpeg cannot encode {w}x{h} with {encoder} ({})", - String::from_utf8_lossy(&out.stderr).lines().last().unwrap_or("") + String::from_utf8_lossy(&out.stderr) + .lines() + .last() + .unwrap_or("") ); continue; } @@ -38005,7 +41749,10 @@ pub(crate) mod tests { } } } - assert!(checked > 0, "{NAME}: neither reference encoder was available"); + assert!( + checked > 0, + "{NAME}: neither reference encoder was available" + ); eprintln!("{NAME}: {checked} straddling reference points decoded sample-exact"); } @@ -38038,13 +41785,36 @@ pub(crate) mod tests { } const FRAMES: usize = 4; let (w, h) = (384usize, 152usize); - let src = format!( - "color=c=gray:s={w}x{h}:r=25,noise=alls=80:all_seed=7:allf=t+u" - ); + let src = format!("color=c=gray:s={w}x{h}:r=25,noise=alls=80:all_seed=7:allf=t+u"); let args: Vec = [ - "-v", "error", "-f", "lavfi", "-i", &src, "-frames:v", "4", "-pix_fmt", "yuv420p", - "-an", "-threads", "1", "-g", "4", "-c:v", "libaom-av1", "-cpu-used", "2", "-b:v", - "0", "-crf", "5", "-aq-mode", "1", "-f", "obu", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &src, + "-frames:v", + "4", + "-pix_fmt", + "yuv420p", + "-an", + "-threads", + "1", + "-g", + "4", + "-c:v", + "libaom-av1", + "-cpu-used", + "2", + "-b:v", + "0", + "-crf", + "5", + "-aq-mode", + "1", + "-f", + "obu", + "-", ] .iter() .map(|s| (*s).to_string()) @@ -38059,7 +41829,10 @@ pub(crate) mod tests { if !out.status.success() { eprintln!( "SKIP {NAME}: ffmpeg cannot encode with libaom-av1 ({})", - String::from_utf8_lossy(&out.stderr).lines().last().unwrap_or("") + String::from_utf8_lossy(&out.stderr) + .lines() + .last() + .unwrap_or("") ); return; } @@ -38095,5 +41868,4 @@ pub(crate) mod tests { crate::decode::segment_ids_seen() ); } - } diff --git a/lanes/av1ibc128chunk.report.md b/lanes/av1ibc128chunk.report.md new file mode 100644 index 00000000..a9fbb18f --- /dev/null +++ b/lanes/av1ibc128chunk.report.md @@ -0,0 +1,327 @@ +# lane-av1-ibc128chunk — the 128-root intrabc strip's square-cut mu-chunk chroma walk, de-square-cut and WITNESSED + +Branch `lane-av1-ibc128chunk`, parent `a7d22aec`. Target dir +`$HOME/.cache/cargo-target-av1ibc128chunk` throughout. No push. + +## Verdict + +The deferred copy is fixed **and witnessed** — this is not a defensive fix. +`decode_intrabc_128rect` cut each mu chunk's chroma plane block with +`chunk_chroma = cside * 64 / side` (two sites, decode.rs:12663 and decode.rs:12896 +at the parent), the same square-cut defect lane-av1-422bigblock fixed and +witnessed in `decode_inter_block` and `decode_block_128rect`. Red before: a real +4:2:2 `aomenc --enable-intrabc` sb128 stream loses half of every mu chunk's +chroma units and its frames 0 and 3 diverge from `aomdec`, first difference at +the top-left corner of the very first 128x64 intrabc block. Green after: the +same stream decodes all five frames byte-identical to `aomdec --rawvideo`, and +the red build's 4 lost blocks are recovered. + +Both pinned witnesses are committed; committed code still refuses 4:2:2 at the +sequence header and the `EC_AV1_ALLOW_422_PROBE` bypass was applied and +reverted per probe run (`git diff` on the refusal line is empty; the only +`EC_AV1_ALLOW_422_PROBE` strings left in the tree are two doc-comment mentions +of the recipe). + +## The defect (both sites) + +`decode_intrabc_128rect` is the intrabc arm of `decode_block_128rect`: a +128x64 / 64x128 / 128x128 strip coded with `use_intrabc`, predicted from this +frame's own reconstruction, reconstructed through the INTER residual walk +(`decode_token_recon_block`'s else arm). + +A 64x64 mu chunk's chroma plane block is **per-axis** `(64 >> ss_x) x +(64 >> ss_y)`: 32x32 at 4:2:0 (one TX_32X32 per plane per chunk), **32x64 at +4:2:2 (TWO STACKED TX_32X32 per plane per chunk)**, 64x64 at 4:4:4 (four). +`av1_get_max_uv_txsize` caps the unit at 32 on each axis. The square-cut model +walked a `chroma_side`-square chunk, i.e. the 4:2:0 count on both axes. + +Measured consequences at 4:2:2 (witness below): + +1. **Half the units.** One chroma unit per plane per chunk instead of two + stacked — the chunk's lower 32 chroma rows got no residual at all. +2. **Wrong extent, twice.** The block's own chroma plane block was still + `bw / 2 x bh / 2` (`cpx, cpy = px / 2, py / 2`), i.e. 4:2:0-shaped, even + though the same function's two `mv_to_q4(cpy, dv_row, ss_y(fctx))` calls + already scaled the DV on the y axis by **its own** subsampling — the + prediction window was half as tall as the motion vector asked for. +3. **Wrong entropy spans.** `around_mi` / `record_mi_chroma` stamped every unit + over a `unit_luma = cu_tx * (side / cside)` = 16x16-mi luma square instead + of the per-axis 16x8 at 4:2:2, and the `mu_chroma` per-unit replay walked a + 32-row step down a 64-row chunk. +4. **Entropy lock lost.** The halved unit count desynced the tile: the red build + decoded 2 of the stream's 6 intrabc blocks; the fixed build decodes all 6. + +## The fix (mirror of the two witnessed twins) + +Both sites, per-axis, in the same expression shape +`decode_inter_block` already carries: + +| old | new | +|---|---| +| `let (cpx, cpy) = (px / 2, py / 2);` | `(px >> ss_x(fctx), py >> ss_y(fctx))` | +| `let (cw, ch) = (bw / 2, bh / 2);` | `(bw >> ss_x(fctx), bh >> ss_y(fctx))` | +| `let chunk_chroma = cside * 64 / side;` | `chunk_chroma_w = (64usize) >> ss_x(fctx)` / `chunk_chroma_h = (64usize) >> ss_y(fctx)` | +| `let unit_luma = cu_tx * (side / cside);` | `unit_luma_w = cu_tx << ss_x(fctx)` / `unit_luma_h = cu_tx << ss_y(fctx)` | +| `units_x/y = chunk_*_mi / (unit_luma / MI)` | same, on `unit_luma_w` / `unit_luma_h` | +| `around_mi(unit_mi, unit_luma)` | `around_mi_rect(unit_mi, unit_luma_w, unit_luma_h)` | +| `record_mi_chroma(unit_mi, unit_luma, unit_luma, ..)` | `.. unit_luma_w, unit_luma_h, ..` | +| `cu_x = cpx + cc * chunk_chroma + uc * cu_tx` | `.. cc * chunk_chroma_w + ..` | +| `cu_y = cpy + cr * chunk_chroma + ur * cu_tx` | `.. cr * chunk_chroma_h + ..` | +| `cu_pred` / composed-grid `dst` offsets | per-axis offsets at the square `cside` stride | +| `read_inter_chroma_lossless(.., (cc*cc_, cr*cc_), (cc_, cc_), ..)` | per-axis org and region | +| replay `unit_luma = cu * 2` | `unit_luma_w = cu << ss_x(fctx)` / `unit_luma_h = cu << ss_y(fctx)` | +| replay `ch / chunk_chroma`, `cw / chunk_chroma` | `ch / chunk_chroma_h`, `cw / chunk_chroma_w` | +| `EC_IBC128_BANDS` trace spans | per-axis | + +New counters (both exported from `stream` and printed by `decode_probe`): +`INTRABC_128RECT_CHROMA_CHUNK_HITS` (one bump per chroma `read_inter_plane` of +this walk) and `INTRABC_128RECT_CHUNK_SHAPE` +(`(64 >> ss_x) << 8 | (64 >> ss_y)` of the last chunk walked). + +## Fixtures (pinned, `git add -f`; `fixtures/` is gitignored) + +| fixture | bytes | sha256 | fnv1a64 | +|---|---|---|---| +| `422_intrabc_sb128_strip.obu` | 1672 | `f92000db86df7acc577d60dd1d0d97454bff4705799ea59d9de34eb5a71dbbcd` | `0x50f5cfc576e4cd00` | +| `422_intrabc_sb128_strip_notxsearch.obu` | 1675 | `80dd0d4e93fd6c3d4b7188a43e69d9638f2bece38edfab60ff3582628314b5ec` | `0xd4936f252ff8cff0` | + +Source (the deterministic `geq` sinusoid the tree's own sb128 intrabc-rect gate +uses, re-cut at `yuv422p` — the 4:2:2 twin of that gate's arm 1): + + ffmpeg -v error -f lavfi -i "nullsrc=size=384x320:rate=25,format=yuv420p,\ + geq=lum='128+90*sin((X+2*N)/37)+30*sin(Y/29)':\ + cb='128+30*sin(X/23)':cr='128+30*sin((Y+N)/19)'" \ + -pix_fmt yuv422p -strict -1 -t 0.2 -f yuv4mpegpipe -y geq/384x320.y4m + + ~/.cache/aom-oracle/build/aomenc --codec=av1 --i422 --profile=2 --passes=1 \ + --end-usage=q --cq-level=32 --cpu-used=0 --threads=1 --row-mt=0 \ + --lag-in-frames=0 --kf-max-dist=1 --limit=5 --tile-columns=0 --sb-size=128 \ + --min-partition-size=64 --enable-rect-partitions=1 --enable-ab-partitions=0 \ + --enable-1to4-partitions=0 --enable-palette=0 --tune-content=screen \ + --enable-intrabc=1 --deltaq-mode=0 --enable-tx-size-search=1 \ + --obu -o geq/384x320_cq32_ts1.obu geq/384x320.y4m + +`_notxsearch` is the same command with `--enable-tx-size-search=0`. Both are +pinned and both are red-before / green-after (the tx-size-search arm is not +required — a mis-signed flag on a witness is a coin flip, so both went in). + +## Red before / green after (measured) + +`aomdec` is `~/.cache/aom-oracle/build/aomdec`; ours is `decode_probe` (debug, +`--features gate-counters`) on the `EC_AV1_ALLOW_422_PROBE` patch-run-restore +build, compared with `cmp` on the full raw output. + +| fixture | build | 128-root blocks | chroma units stamped | vs `aomdec` | +|---|---|---|---|---| +| `422_intrabc_sb128_strip.obu` | parent `a7d22aec` | **2** | **8** | **DIFF** | +| `422_intrabc_sb128_strip.obu` | this lane | **6** | **48** | **EXACT** (5/5 frames) | +| `422_intrabc_sb128_strip_notxsearch.obu` | parent `a7d22aec` | **2** | **8** | **DIFF** | +| `422_intrabc_sb128_strip_notxsearch.obu` | this lane | **6** | **48** | **EXACT** | + +Frame-level detail, per fixture (245760 samples/frame: 384x320 Y + 2 x 192x320 +chroma), re-measured per fixture after review — the first cut of this section +reported the `_notxsearch` arm's counts under the primary witness: + +| fixture | build | f0 | f1 | f2 | f3 | f4 | +|---|---|---|---|---|---|---| +| `422_intrabc_sb128_strip.obu` (primary) | parent `a7d22aec` | **46891** | 0 | 0 | **44842** | 0 | +| `422_intrabc_sb128_strip.obu` (primary) | this lane | 0 | 0 | 0 | 0 | 0 | +| `422_intrabc_sb128_strip_notxsearch.obu` | parent `a7d22aec` | **45135** | 0 | 0 | **44540** | 0 | +| `422_intrabc_sb128_strip_notxsearch.obu` | this lane | 0 | 0 | 0 | 0 | 0 | + +Both fixtures' red first difference is byte 98368 = frame 0, Y **row 256, +col 64** — the top-left of the first 128x64 intrabc block (traced at +`mi_row=64 mi_col=0`, `py = 64*4 = 256`). Frames 1, 2, 4 carry no intrabc +block and are exact in every build. Green: `cmp` identical on all +245760 x 5 bytes, 5 frames decoded, 0 hidden. + +The red build reached only 2 of the 6 blocks: reading 4 chroma units where +libaom codes 8 desynced the tile, and the remaining 4 blocks were misparsed. +Recovering them is the green signal, not just the pixel count. + +`EC_ECDUMP` per-unit stamps on the primary witness, red vs fixed, same entropy +position (`rng=49296` at the first block in both): + + red 4 stamps (1 per plane per chunk, 2 chunks) + fixed 8 stamps (2 per plane per chunk, 2 chunks) + +## Rework after review (r2) — the `mu_chroma` replay's chunk/unit step + +Review r1 FAILed the first cut on a real coverage regression I introduced, and +corrected this report's red counts (done above; the 45135/44540 pair was the +`_notxsearch` arm, the primary's are 46891/44842). + +**The defect.** The first cut gave the replay per-axis *extents* but kept the +old *step*: `rows`/`cols` count mu CHUNKS (`ch / chunk_chroma_h`), while the +loop body advanced the mi origin and read the grid PER UNIT +(`cr * (unit_luma_h / MI)`, grid `(cr * chunk_chroma_h)`). Those agree only when +a chunk holds exactly one unit. At 4:2:0 (`chunk_chroma == cu == 32`) it is +line-identical to the parent, so nothing measured it; at 4:2:2 +(`chunk_chroma_h = 64 = 2 * cu`) the body reached only the FIRST of the two +stacked units per chunk, so rows `mi_r+8 .. mi_r+16` kept the composed-grid +smearing the replay exists to undo. The parent reached those rows (with a wrong +span but full coverage), so this was a coverage regression *my* patch added, +not a pre-existing gap. + +**The reshape**, in the twin's chunk-then-unit loop +(`decode_inter_block`'s `mu_chroma_units`, decode.rs:37456-37494, +lane-av1-444 c8): + + let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w / cu); + for cr in 0..rows { for cc in 0..cols { + for kr in 0..ur { for kc in 0..uc { + unit_mi = (mi_r + (cr * 64 + kr * unit_luma_h) / MI, + mi_c + (cc * 64 + kc * unit_luma_w) / MI); + (cy, cx) = (cr * chunk_chroma_h + kr * cu, cc * chunk_chroma_w + kc * cu); + ... let start = (cy + rr) * cside + cx; + +`cr * 64` is the mu chunk's LUMA-px step, which is 64 on both axes at every +subsampling — that is why the twin can write it unshifted. At 4:2:0 `ur`/`uc` +are 1, so `kr`/`kc` are 0, `unit_mi` collapses to `mi_r + cr*16`, and the grid +origin to `(cr*32, cc*32)`: **line-identical to the pre-rework walk**. The new +gate pins the shape, and the mutation proof below shows it is load-bearing. + +**The LOSSLESS arm is pre-existing and deliberately untouched.** On a lossless +frame `cu` is 4 and the composed grid is a raster of TX_4x4 units, so the +chunk-counted `rows`/`cols` do not enumerate it at all: that arm re-stamps only +the 4x4 at each chunk's top-left with a 2x2-mi span. The twin raster-walks the +whole plane block instead (lane-av1-llinter). It is left as-is on purpose: it is +a **4:2:0** defect, not a subsampling square-cut, so it is out of this lane's +class, and fixing it would change 4:2:0 LOSSLESS output — which this lane's +byte-identity requirement forbids doing on a reconstruction I have no witness +to verify. Measured unreachability: a temporary env-gated counter in the arm +records **0 hits across the whole `lossless` and `intrabc` gate battery** +(13 + 19 tests). Unblock: one lossless sb128 4:2:0 stream coding a NON-SKIP +128-root intrabc strip (`--lossless=1 --sb-size=128 --min-partition-size=64 +--enable-rect-partitions=1 --enable-intrabc=1` over near-match screen +content), then the twin's raster reshape plus a witness. Carried as a named pre-existing, +not as a silent skip. + +**Re-measured after the reshape (r2):** both witnesses byte-identical to +`a7d22aec`-relative tip r1's output (6 blocks, 48 chroma units, 5/5 frames exact +vs `aomdec`) — the reshape is a pure coverage repair, no output change on any +witness. `an_sb128_rect_strip_with_intrabc_decodes_pixel_exact`, +`an_sb128_screen_stream_with_intrabc_decodes_pixel_exact`, +`a_lossless_sb128_rect_intra_block_decodes_sample_exact`, +`a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact`, +`the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name` and both new +gates: **7 passed / 0 failed**. Two mutation proofs on the source-scan arm, +both FAILING it: forcing `let (ur, uc) = (1, 1);` (the per-chunk-only shape) +gives `found 0`; re-introducing `cside * 64 / side` at the read-walk site gives +`left: 1, right: 0`. Restored, the gate passes. + +## Reproduce (patch-run-restore, local only) + + python3 - <<'EOF' + p='crates/ec-av1/src/stream.rs'; s=open(p).read() + s=s.replace(" if seq.subsampling_x != seq.subsampling_y {", + " if seq.subsampling_x != seq.subsampling_y && !crate::envflags::env_flag!(\"EC_AV1_ALLOW_422_PROBE\") {",1) + open(p,'w').write(s) + EOF + CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1ibc128chunk \ + cargo build -p ec-av1 --example decode_probe --features gate-counters + EC_AV1_ALLOW_422_PROBE=1 EC_ECDUMP=1 \ + $HOME/.cache/cargo-target-av1ibc128chunk/debug/examples/decode_probe \ + crates/ec-av1/fixtures/422_intrabc_sb128_strip.obu 2>&1 | grep -c EC_IBC128_STAMP + -> 48 (parent: 8) + EC_AV1_ALLOW_422_PROBE=1 EC_PROBE_OUT=/tmp/ours.raw \ + $HOME/.cache/cargo-target-av1ibc128chunk/debug/examples/decode_probe \ + crates/ec-av1/fixtures/422_intrabc_sb128_strip.obu + ~/.cache/aom-oracle/build/aomdec --rawvideo -o /tmp/oracle.raw \ + crates/ec-av1/fixtures/422_intrabc_sb128_strip.obu + cmp /tmp/ours.raw /tmp/oracle.raw # identical + git checkout -- crates/ec-av1/src/stream.rs + +## Gates + +- `the_pinned_422_intrabc_sb128_strip_witnesses_refuse_by_name` (stream.rs) — + both fixtures' byte pins (`len` + `fnv1a64`) and the unconditional + refusal-by-name contract. The decode-level assertions above cannot run in + committed code (the 4:2:2 refusal stands), so they are probe-measured and + reproducible from the recipe; this is the same split + `the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name` uses. +- `the_intrabc_128rect_chroma_chunk_walk_stays_per_axis` (stream.rs) — the + source-scan arm. Scans `decode_intrabc_128rect`'s body **with comments + stripped** (the fix's own comments quote the old expression to say what it + was) and pins: zero `cside * 64 / side`; the `chunk_chroma_w/h` pair at + **both** de-square-cut sites (read walk and `mu_chroma` replay); the replay's + chunk-then-unit shape (`let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w / + cu);`, `for kr in 0..ur {`, `for kc in 0..uc {` — the r2 coverage fix); the + `unit_luma_w/h`, `cw/ch`, `cpx/cpy` and `around_mi_rect` forms once each; the + replay's own `cu << ss` pair; the per-axis unit arithmetic + (`(64>>ss_x)/32 * (64>>ss_y)/32` = 1 / 2 / 4 at 4:2:0 / 4:2:2 / 4:4:4); and + both new counter accessors. **Non-vacuity measured twice**: forcing + `let (ur, uc) = (1, 1);` (the per-chunk-only shape) fails it with + `found 0`, and re-introducing `let chunk_chroma_w = cside * 64 / side;` at + the read-walk site fails it with `left: 1, right: 0`; restored, it passes. + +## Byte-identity outside 4:2:2 + +- `an_sb128_rect_strip_with_intrabc_decodes_pixel_exact` — **green**, and it + is the right gate: same deterministic `geq` recipe as the witness, at + `yuv420p` / `yuv420p10le`, all three arms decode-order pixel-exact vs the + oracle with `intrabc_128rect_hits=+14 / +1 / +15` (30 blocks through the + changed walk, `skip=false`, real residual reads). At ss (1,1) every new + expression reduces to the old constant: `64 >> 1 = 32`, `32 << 1 = 64`, + `bw >> 1 = bw / 2`, 16x16-mi spans. +- `an_sb128_screen_stream_with_intrabc_decodes_pixel_exact` — green (8 arms, + 4-6 intrabc blocks each). +- `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact` — green. +- `a_lossless_sb128_rect_intra_block_decodes_sample_exact` — green. +- `a_real_aomenc_intrabc_mixed_vartx_tree_decodes_without_the_mixed_leaf_refusal` + and `a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips` — green. +- `the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name` — green + (the twin lane's fixtures are untouched). +- Scoped battery: `intrabc` filter 19 passed / 0 failed / 1 ignored; + `422` + `444` filters 12 passed / 0 failed. `cargo check -p ec-av1 + --all-targets`: 0 warnings. + +**DISCLOSED 4:4:4 behavior change.** At ss (0,0) the walk now codes FOUR +TX_32X32 units per mu chunk per plane (1x1 -> 2x2) where the parent coded one, +and the block's chroma plane block is now luma-sized (`bw x bh`) instead of +`bw/2 x bh/2`. This is the same disclosure lane-av1-422bigblock made for +`decode_block_128rect`: the parent's walk was **provably wrong** at ss (0,0) — +`cside = (side/2).max(...)` is the 4:2:0 half-side, so the old 32x32 chunk +covered a quarter of a 64x64 4:4:4 chroma chunk and the origin `px/2` was off by +half a superblock. Unlike that lane, this one also changes the *block* shape at +4:4:4 (`cw/ch`, `cpx/cpy`), so the ticket's "spans are equal at (0,0)" +premise does not hold for this function, whose extents were 4:2:0-hardcoded +throughout. Measured unreachability: **no committed 4:4:4 fixture engages +`decode_intrabc_128rect` at all** (`ibc128=0` on all six 4:4:4 fixtures +including `444_sb128rect_lr_witness.obu` and `ll444_ibc_rect.obu`), so no +green gate covers or contradicts the change; it is landed on the same geometry +argument that the two reviewed twins landed on, and the 4:4:4 route needs its +own witness (`aomenc --i444 --profile=1 --sb-size=128 --enable-rect-partitions=1 +--enable-intrabc=1` over content that makes aomenc take a 128-root PARTITION_NONE +or HORZ/VERT strip — no committed 4:4:4 fixture does). + +## Hunt recipe sweep (what was tried before the hit) + +`--profile=2 --sb-size=128 --enable-intrabc=1` at 4:2:2, all with +`--i422`, `--tune-content=screen`, `--enable-palette=0`, `--passes=1`, +`--lag-in-frames=0`, `--kf-max-dist=1`, `--min-partition-size=8`, +`--max-partition-size=128`, `--enable-rect-partitions=1`, +`--enable-1to4-partitions=1`: + +- **lavfi `testsrc2 / smptebars / mandelbrot / life / rgbtestsrc / + smptehdbars`, 128x128 and 256x256/384x256/512x256/128x128, `cpu-used` 0/2/3/4, + `cq-level` 15-60, 2x2/3x2/4x4 `tile=`** (24 encodes + 24 x 2 x 8 = ~400 + encodes): 9 streams reached `decode_intrabc_128rect`; **all 9 reached it with + a frame that was ALREADY desynced** before the block. The blocker is + pre-existing and unrelated: at 4:2:2 a chroma tx unit goes non-square + (TX_16X8 etc.) and the merged tree does not read the `tx_type` the oracle + codes for it — first divergence on `c_testsrc2_cq40.obu` at coefficient unit + **4** (plane 1, `mi_row=0 mi_col=0`, `tx_size=5` = TX_16X8: the oracle emits + `tx_type` after `all_zero` where ours goes straight to `eob`, rng 55680 / + 34568 identical up to that point). **Named for its owning lane, not chased + here.** +- **the tree's own gate recipe re-cut at `yuv422p`** (the `geq` sinusoid + sources, 384x320 cq32 and 512x512 cq45, `enable-tx-size-search` 0/1): the + smooth-chroma `geq` content avoids the non-square-chroma-tx defect, and both + cq32 arms are the red/green witnesses above. cq20/45/55 code no 128-root + intrabc block at all (`ibc128=0`), so the hit is a cq32 window, not a + content accident. + +Control that clean 4:2:2 witnesses do exist on this tree (so the "already +desynced" arms above were a content choice, not a tree-wide wall): +`422_sb128_3f.obu` decodes byte-exact vs `aomdec` here.