Merge lane-av1-ibc128chunk: per-axis chroma chunk walk in decode_intrabc_128rect
Browse files at this commit6 changed files +14428 -4078
- crates/ec-av1/examples/decode_probe.rs +9 -0
- crates/ec-av1/fixtures/422_intrabc_sb128_strip.obu +0 -0
- crates/ec-av1/fixtures/422_intrabc_sb128_strip_notxsearch.obu +0 -0
- crates/ec-av1/src/decode.rs +8712 -2470
- crates/ec-av1/src/stream.rs +5380 -1608
- lanes/av1ibc128chunk.report.md +327 -0
crates/ec-av1/examples/decode_probe.rsmodified+9 -0
| @@ -1,3 +1,5 @@ | |||
| 1 | +/home/user/Documents/Code/Rust/edith_codecs/crates/ec-av1/examples/decode_probe.rs: | ||
| 2 | + | ||
| 1 | //! Where does a real stream stop? Decode one AV1 file and print the answer. | 3 | //! Where does a real stream stop? Decode one AV1 file and print the answer. |
| 2 | //! | 4 | //! |
| 3 | //! The gates in [`ec_av1::stream`] each pin one capability against one encoder | 5 | //! The gates in [`ec_av1::stream`] each pin one capability against one encoder |
| @@ -91,6 +93,13 @@ fn main() { | |||
| 91 | "intrabc_128rect: {}", | 93 | "intrabc_128rect: {}", |
| 92 | ec_av1::stream::intrabc_128rect_hits() | 94 | ec_av1::stream::intrabc_128rect_hits() |
| 93 | ); | 95 | ); |
| 96 | + // lane-av1-ibc128chunk: the 128-root intrabc strip's per-axis chroma | ||
| 97 | + // mu-chunk walk -- unit count and the `(64>>ss_x)|(64>>ss_y)` extent. | ||
| 98 | + println!( | ||
| 99 | + "intrabc_128rect_chroma_chunk: units={} shape=0x{:x}", | ||
| 100 | + ec_av1::stream::intrabc_128rect_chroma_chunk_hits(), | ||
| 101 | + ec_av1::stream::intrabc_128rect_chunk_shape() | ||
| 102 | + ); | ||
| 94 | let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); | 103 | let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); |
| 95 | println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); | 104 | println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); |
| 96 | println!( | 105 | println!( |
crates/ec-av1/fixtures/422_intrabc_sb128_strip.obuadded+0 -0
Binary file changed
crates/ec-av1/fixtures/422_intrabc_sb128_strip_notxsearch.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+8712 -2470
Diff too large; view file
| @@ -1,3 +1,5 @@ | |||
| 1 | +/home/user/Documents/Code/Rust/edith_codecs/crates/ec-av1/src/decode.rs: | ||
| 2 | + | ||
| 1 | //! Software decoder for this crate's own key-frame tile payloads (spec 5.11), | 3 | //! Software decoder for this crate's own key-frame tile payloads (spec 5.11), |
| 2 | //! the reader half of [`crate::tile`]'s writer. | 4 | //! the reader half of [`crate::tile`]'s writer. |
| 3 | //! | 5 | //! |
| @@ -305,7 +307,8 @@ impl FrameCtx { | |||
| 305 | let ctx = Self::new(); | 307 | let ctx = Self::new(); |
| 306 | let on = crate::encode::sb128_on(); | 308 | let on = crate::encode::sb128_on(); |
| 307 | ctx.sb128_flag.set(on); | 309 | ctx.sb128_flag.set(on); |
| 308 | - ctx.reach_sb_px.set(if on { 128 } else { crate::encode::SUPERBLOCK }); | 310 | + ctx.reach_sb_px |
| 311 | + .set(if on { 128 } else { crate::encode::SUPERBLOCK }); | ||
| 309 | ctx | 312 | ctx |
| 310 | } | 313 | } |
| 311 | } | 314 | } |
| @@ -362,9 +365,9 @@ use crate::msac::SymbolDecoder; | |||
| 362 | use crate::mvstack::{ | 365 | use crate::mvstack::{ |
| 363 | ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST_FRAME, LAST2_FRAME, LAST3_FRAME, | 366 | ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST_FRAME, LAST2_FRAME, LAST3_FRAME, |
| 364 | MiGrid, MiInfo, NO_REF1, NO_SIGN_BIAS, NeighbourRef, SignBiasTable, comp_reference_type_ctx, | 367 | MiGrid, MiInfo, NO_REF1, NO_SIGN_BIAS, NeighbourRef, SignBiasTable, comp_reference_type_ctx, |
| 365 | - find_mv_stack_with_sign_bias, mv16, mv32, reference_mode_ctx, | 368 | + find_mv_stack_with_sign_bias, mv16, mv32, reference_mode_ctx, single_ref_p1_ctx, |
| 366 | - single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, | 369 | + single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx, |
| 367 | - single_ref_p6_ctx, uni_comp_ref_p1_ctx, | 370 | + uni_comp_ref_p1_ctx, |
| 368 | }; | 371 | }; |
| 369 | use crate::tile::{INTRA_MODE_CTX, block_grid, has_half}; | 372 | use crate::tile::{INTRA_MODE_CTX, block_grid, has_half}; |
| 370 | use crate::transform::{TxType, dequant_and_inverse_typed_wh}; | 373 | use crate::transform::{TxType, dequant_and_inverse_typed_wh}; |
| @@ -429,7 +432,6 @@ pub(crate) fn coeff_trace_on() -> bool { | |||
| 429 | } | 432 | } |
| 430 | } | 433 | } |
| 431 | 434 | ||
| 432 | - | ||
| 433 | /// Sets [`SB128`] for this thread (called once per frame from `stream.rs`). | 435 | /// Sets [`SB128`] for this thread (called once per frame from `stream.rs`). |
| 434 | pub(crate) fn set_sb128(v: bool, fctx: &crate::decode::FrameCtx) { | 436 | pub(crate) fn set_sb128(v: bool, fctx: &crate::decode::FrameCtx) { |
| 435 | fctx.sb128_flag.with(|c| c.set(v)); | 437 | fctx.sb128_flag.with(|c| c.set(v)); |
| @@ -438,10 +440,7 @@ pub(crate) fn set_sb128(v: bool, fctx: &crate::decode::FrameCtx) { | |||
| 438 | 440 | ||
| 439 | /// lane-av1mixloss: sets [`FrameCtx::lossless_per_seg`] (called once per frame | 441 | /// lane-av1mixloss: sets [`FrameCtx::lossless_per_seg`] (called once per frame |
| 440 | /// from `stream.rs`). | 442 | /// from `stream.rs`). |
| 441 | -pub(crate) fn set_lossless_per_seg( | 443 | +pub(crate) fn set_lossless_per_seg(table: [bool; MAX_SEGMENTS], fctx: &crate::decode::FrameCtx) { |
| 442 | - table: [bool; MAX_SEGMENTS], | ||
| 443 | - fctx: &crate::decode::FrameCtx, | ||
| 444 | -) { | ||
| 445 | fctx.lossless_per_seg.with(|c| c.set(table)); | 444 | fctx.lossless_per_seg.with(|c| c.set(table)); |
| 446 | } | 445 | } |
| 447 | 446 | ||
| @@ -701,7 +700,6 @@ pub(crate) fn round_ss(dim: usize, ss: usize) -> usize { | |||
| 701 | (dim + ((1usize << ss) >> 1)) >> ss | 700 | (dim + ((1usize << ss) >> 1)) >> ss |
| 702 | } | 701 | } |
| 703 | 702 | ||
| 704 | - | ||
| 705 | /// This frame's superres state: `(upscaled_width, superres_denom)`, or | 703 | /// This frame's superres state: `(upscaled_width, superres_denom)`, or |
| 706 | /// `(0, 8)` when the frame is not scaled. Spec 7.16's upscale runs | 704 | /// `(0, 8)` when the frame is not scaled. Spec 7.16's upscale runs |
| 707 | /// between CDEF and loop restoration, so LOOP RESTORATION -- unit grid, | 705 | /// between CDEF and loop restoration, so LOOP RESTORATION -- unit grid, |
| @@ -902,7 +900,15 @@ fn block_iqmatrix( | |||
| 902 | /// top-left leaf is the only block that can ever land there), or when that | 900 | /// top-left leaf is the only block that can ever land there), or when that |
| 903 | /// leaf both *is* the whole superblock and is `skip` (the one case libaom | 901 | /// leaf both *is* the whole superblock and is `skip` (the one case libaom |
| 904 | /// itself skips the read, state carrying over unchanged). | 902 | /// itself skips the read, state carrying over unchanged). |
| 905 | -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) { | 903 | +fn maybe_read_delta_q( |
| 904 | + dec: &mut SymbolDecoder, | ||
| 905 | + cdfs: &mut Cdfs, | ||
| 906 | + mi_r: usize, | ||
| 907 | + mi_c: usize, | ||
| 908 | + is_whole_sb: bool, | ||
| 909 | + skip: bool, | ||
| 910 | + fctx: &crate::decode::FrameCtx, | ||
| 911 | +) { | ||
| 906 | if !fctx.delta_q_present.with(|c| c.get()) { | 912 | if !fctx.delta_q_present.with(|c| c.get()) { |
| 907 | return; | 913 | return; |
| 908 | } | 914 | } |
| @@ -929,7 +935,8 @@ fn maybe_read_delta_q(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_ | |||
| 929 | let reduced = if sign_negative { -abs } else { abs }; | 935 | let reduced = if sign_negative { -abs } else { abs }; |
| 930 | hit!(DELTA_Q_HITS); | 936 | hit!(DELTA_Q_HITS); |
| 931 | let res = fctx.delta_q_res.with(|c| c.get()); | 937 | let res = fctx.delta_q_res.with(|c| c.get()); |
| 932 | - fctx.current_q_idx.with(|c| c.set((c.get() + reduced * res).clamp(1, 255))); | 938 | + fctx.current_q_idx |
| 939 | + .with(|c| c.set((c.get() + reduced * res).clamp(1, 255))); | ||
| 933 | } | 940 | } |
| 934 | 941 | ||
| 935 | // lane-realworld r5: this frame's `delta.lf_present`/`lf_res`/`lf_multi` | 942 | // lane-realworld r5: this frame's `delta.lf_present`/`lf_res`/`lf_multi` |
| @@ -956,7 +963,15 @@ pub(crate) fn delta_lf_hits() -> usize { | |||
| 956 | /// [`maybe_read_delta_q`] (spec order `delta_q -> delta_lf`), looped over | 963 | /// [`maybe_read_delta_q`] (spec order `delta_q -> delta_lf`), looped over |
| 957 | /// `FRAME_LF_COUNT = 4` planes/directions when `delta_lf_multi` is set, or | 964 | /// `FRAME_LF_COUNT = 4` planes/directions when `delta_lf_multi` is set, or |
| 958 | /// read once into index 0 otherwise. | 965 | /// read once into index 0 otherwise. |
| 959 | -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) { | 966 | +fn maybe_read_delta_lf( |
| 967 | + dec: &mut SymbolDecoder, | ||
| 968 | + cdfs: &mut Cdfs, | ||
| 969 | + mi_r: usize, | ||
| 970 | + mi_c: usize, | ||
| 971 | + is_whole_sb: bool, | ||
| 972 | + skip: bool, | ||
| 973 | + fctx: &crate::decode::FrameCtx, | ||
| 974 | +) { | ||
| 960 | if !fctx.delta_lf_present.with(|c| c.get()) { | 975 | if !fctx.delta_lf_present.with(|c| c.get()) { |
| 961 | return; | 976 | return; |
| 962 | } | 977 | } |
| @@ -1091,17 +1106,24 @@ pub(crate) fn set_segmentation( | |||
| 1091 | seg: SegmentationParams, | 1106 | seg: SegmentationParams, |
| 1092 | mi_rows: usize, | 1107 | mi_rows: usize, |
| 1093 | mi_cols: usize, | 1108 | mi_cols: usize, |
| 1094 | - prev: Option<&[u8]>, fctx: &crate::decode::FrameCtx, | 1109 | + prev: Option<&[u8]>, |
| 1110 | + fctx: &crate::decode::FrameCtx, | ||
| 1095 | ) { | 1111 | ) { |
| 1096 | if crate::envflags::env_flag!("EC_HDR") { | 1112 | if crate::envflags::env_flag!("EC_HDR") { |
| 1097 | eprintln!( | 1113 | eprintln!( |
| 1098 | "EC_SEGHDR enabled={} update_map={} temporal={} preskip={} last_active={} data={:?}", | 1114 | "EC_SEGHDR enabled={} update_map={} temporal={} preskip={} last_active={} data={:?}", |
| 1099 | - seg.enabled, seg.update_map, seg.temporal_update, seg.seg_id_pre_skip, seg.last_active_seg_id, seg.feature_data | 1115 | + seg.enabled, |
| 1116 | + seg.update_map, | ||
| 1117 | + seg.temporal_update, | ||
| 1118 | + seg.seg_id_pre_skip, | ||
| 1119 | + seg.last_active_seg_id, | ||
| 1120 | + seg.feature_data | ||
| 1100 | ); | 1121 | ); |
| 1101 | } | 1122 | } |
| 1102 | fctx.seg.with(|s| *s.borrow_mut() = seg); | 1123 | fctx.seg.with(|s| *s.borrow_mut() = seg); |
| 1103 | fctx.seg_mi_dims.with(|c| c.set((mi_rows, mi_cols))); | 1124 | fctx.seg_mi_dims.with(|c| c.set((mi_rows, mi_cols))); |
| 1104 | - fctx.seg_ids.with(|m| *m.borrow_mut() = vec![0u8; mi_rows * mi_cols]); | 1125 | + fctx.seg_ids |
| 1126 | + .with(|m| *m.borrow_mut() = vec![0u8; mi_rows * mi_cols]); | ||
| 1105 | fctx.prev_seg_ids.with(|m| { | 1127 | fctx.prev_seg_ids.with(|m| { |
| 1106 | let mut m = m.borrow_mut(); | 1128 | let mut m = m.borrow_mut(); |
| 1107 | m.clear(); | 1129 | m.clear(); |
| @@ -1111,8 +1133,10 @@ pub(crate) fn set_segmentation( | |||
| 1111 | } | 1133 | } |
| 1112 | } | 1134 | } |
| 1113 | }); | 1135 | }); |
| 1114 | - fctx.above_seg_pred.with(|m| *m.borrow_mut() = vec![0u8; mi_cols]); | 1136 | + fctx.above_seg_pred |
| 1115 | - fctx.left_seg_pred.with(|m| *m.borrow_mut() = vec![0u8; mi_rows]); | 1137 | + .with(|m| *m.borrow_mut() = vec![0u8; mi_cols]); |
| 1138 | + fctx.left_seg_pred | ||
| 1139 | + .with(|m| *m.borrow_mut() = vec![0u8; mi_rows]); | ||
| 1116 | fctx.cur_segment_id.with(|c| c.set(0)); | 1140 | fctx.cur_segment_id.with(|c| c.set(0)); |
| 1117 | } | 1141 | } |
| 1118 | 1142 | ||
| @@ -1200,9 +1224,19 @@ fn segment_id_at(mi_r: usize, mi_c: usize, fctx: &crate::decode::FrameCtx) -> u8 | |||
| 1200 | } | 1224 | } |
| 1201 | 1225 | ||
| 1202 | /// `set_segment_id`: stamps `id` over every mi cell this block covers. | 1226 | /// `set_segment_id`: stamps `id` over every mi cell this block covers. |
| 1203 | -fn write_segment_id(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, id: u8, fctx: &crate::decode::FrameCtx) { | 1227 | +fn write_segment_id( |
| 1228 | + mi_r: usize, | ||
| 1229 | + mi_c: usize, | ||
| 1230 | + w_mi: usize, | ||
| 1231 | + h_mi: usize, | ||
| 1232 | + id: u8, | ||
| 1233 | + fctx: &crate::decode::FrameCtx, | ||
| 1234 | +) { | ||
| 1204 | let (mi_rows, mi_cols) = fctx.seg_mi_dims.with(|c| c.get()); | 1235 | let (mi_rows, mi_cols) = fctx.seg_mi_dims.with(|c| c.get()); |
| 1205 | - let (x_mis, y_mis) = (w_mi.min(mi_cols.saturating_sub(mi_c)), h_mi.min(mi_rows.saturating_sub(mi_r))); | 1236 | + let (x_mis, y_mis) = ( |
| 1237 | + w_mi.min(mi_cols.saturating_sub(mi_c)), | ||
| 1238 | + h_mi.min(mi_rows.saturating_sub(mi_r)), | ||
| 1239 | + ); | ||
| 1206 | fctx.seg_ids.with(|m| { | 1240 | fctx.seg_ids.with(|m| { |
| 1207 | let mut m = m.borrow_mut(); | 1241 | let mut m = m.borrow_mut(); |
| 1208 | for y in 0..y_mis { | 1242 | 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, | |||
| 1219 | /// inherited VERBATIM over this block's own mi footprint -- per-cell copies, | 1253 | /// inherited VERBATIM over this block's own mi footprint -- per-cell copies, |
| 1220 | /// not the minified id [`predicted_segment_id`] hands the block. Without a | 1254 | /// not the minified id [`predicted_segment_id`] hands the block. Without a |
| 1221 | /// previous map the footprint is zeroed, exactly as the C NULL branch does. | 1255 | /// previous map the footprint is zeroed, exactly as the C NULL branch does. |
| 1222 | -fn copy_segment_ids(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, fctx: &crate::decode::FrameCtx) { | 1256 | +fn copy_segment_ids( |
| 1257 | + mi_r: usize, | ||
| 1258 | + mi_c: usize, | ||
| 1259 | + w_mi: usize, | ||
| 1260 | + h_mi: usize, | ||
| 1261 | + fctx: &crate::decode::FrameCtx, | ||
| 1262 | +) { | ||
| 1223 | let (mi_rows, mi_cols) = fctx.seg_mi_dims.with(|c| c.get()); | 1263 | let (mi_rows, mi_cols) = fctx.seg_mi_dims.with(|c| c.get()); |
| 1224 | - let (x_mis, y_mis) = (w_mi.min(mi_cols.saturating_sub(mi_c)), h_mi.min(mi_rows.saturating_sub(mi_r))); | 1264 | + let (x_mis, y_mis) = ( |
| 1265 | + w_mi.min(mi_cols.saturating_sub(mi_c)), | ||
| 1266 | + h_mi.min(mi_rows.saturating_sub(mi_r)), | ||
| 1267 | + ); | ||
| 1225 | fctx.seg_ids.with(|m| { | 1268 | fctx.seg_ids.with(|m| { |
| 1226 | let mut m = m.borrow_mut(); | 1269 | let mut m = m.borrow_mut(); |
| 1227 | fctx.prev_seg_ids.with(|p| { | 1270 | 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 | |||
| 1239 | /// `get_predicted_segment_id` (libaom `dec_get_segment_id` over | 1282 | /// `get_predicted_segment_id` (libaom `dec_get_segment_id` over |
| 1240 | /// `last_frame_seg_map`): the minimum previous-frame segment id over the | 1283 | /// `last_frame_seg_map`): the minimum previous-frame segment id over the |
| 1241 | /// block's own mi footprint. `0` when there is no previous map. | 1284 | /// block's own mi footprint. `0` when there is no previous map. |
| 1242 | -fn predicted_segment_id(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, fctx: &crate::decode::FrameCtx) -> u8 { | 1285 | +fn predicted_segment_id( |
| 1286 | + mi_r: usize, | ||
| 1287 | + mi_c: usize, | ||
| 1288 | + w_mi: usize, | ||
| 1289 | + h_mi: usize, | ||
| 1290 | + fctx: &crate::decode::FrameCtx, | ||
| 1291 | +) -> u8 { | ||
| 1243 | let (mi_rows, mi_cols) = fctx.seg_mi_dims.with(|c| c.get()); | 1292 | let (mi_rows, mi_cols) = fctx.seg_mi_dims.with(|c| c.get()); |
| 1244 | fctx.prev_seg_ids.with(|m| { | 1293 | fctx.prev_seg_ids.with(|m| { |
| 1245 | let m = m.borrow(); | 1294 | let m = m.borrow(); |
| 1246 | if m.is_empty() { | 1295 | if m.is_empty() { |
| 1247 | return 0; | 1296 | return 0; |
| 1248 | } | 1297 | } |
| 1249 | - let (x_mis, y_mis) = (w_mi.min(mi_cols.saturating_sub(mi_c)), h_mi.min(mi_rows.saturating_sub(mi_r))); | 1298 | + let (x_mis, y_mis) = ( |
| 1299 | + w_mi.min(mi_cols.saturating_sub(mi_c)), | ||
| 1300 | + h_mi.min(mi_rows.saturating_sub(mi_r)), | ||
| 1301 | + ); | ||
| 1250 | let mut id = u8::MAX; | 1302 | let mut id = u8::MAX; |
| 1251 | for y in 0..y_mis { | 1303 | for y in 0..y_mis { |
| 1252 | for x in 0..x_mis { | 1304 | for x in 0..x_mis { |
| @@ -1277,7 +1329,11 @@ fn neg_deinterleave(diff: i32, reference: i32, max: i32) -> i32 { | |||
| 1277 | reference - (diff >> 1) | 1329 | reference - (diff >> 1) |
| 1278 | }; | 1330 | }; |
| 1279 | } | 1331 | } |
| 1280 | - if 2 * reference < max { diff } else { max - (diff + 1) } | 1332 | + if 2 * reference < max { |
| 1333 | + diff | ||
| 1334 | + } else { | ||
| 1335 | + max - (diff + 1) | ||
| 1336 | + } | ||
| 1281 | } | 1337 | } |
| 1282 | 1338 | ||
| 1283 | /// `av1_get_spatial_seg_pred`: `(prediction, cdf_index)` from the current | 1339 | /// `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) -> | |||
| 1311 | /// `read_segment_id` (libaom `decodemv.c:280`): the spatially predicted id | 1367 | /// `read_segment_id` (libaom `decodemv.c:280`): the spatially predicted id |
| 1312 | /// when `skip`, otherwise one `segment_id` symbol de-interleaved against | 1368 | /// when `skip`, otherwise one `segment_id` symbol de-interleaved against |
| 1313 | /// that prediction. Does NOT write the map -- callers do. | 1369 | /// that prediction. Does NOT write the map -- callers do. |
| 1314 | -fn read_segment_id(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: usize, skip: bool, fctx: &crate::decode::FrameCtx) -> u8 { | 1370 | +fn read_segment_id( |
| 1371 | + dec: &mut SymbolDecoder, | ||
| 1372 | + cdfs: &mut Cdfs, | ||
| 1373 | + mi_r: usize, | ||
| 1374 | + mi_c: usize, | ||
| 1375 | + skip: bool, | ||
| 1376 | + fctx: &crate::decode::FrameCtx, | ||
| 1377 | +) -> u8 { | ||
| 1315 | let (pred, ctx) = spatial_seg_pred(mi_r, mi_c, fctx); | 1378 | let (pred, ctx) = spatial_seg_pred(mi_r, mi_c, fctx); |
| 1316 | if skip { | 1379 | if skip { |
| 1317 | return pred as u8; | 1380 | return pred as u8; |
| @@ -1323,7 +1386,10 @@ fn read_segment_id(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: | |||
| 1323 | // Mirrors the oracle's own `EC_SEG mi_row=.. cdf=.. pred=.. coded=.. id=..` | 1386 | // Mirrors the oracle's own `EC_SEG mi_row=.. cdf=.. pred=.. coded=.. id=..` |
| 1324 | // (libaom `decodemv.c:read_segment_id`), for a cross-decoder segment diff. | 1387 | // (libaom `decodemv.c:read_segment_id`), for a cross-decoder segment diff. |
| 1325 | if crate::envflags::env_flag!("EC_TRACE_SEG") { | 1388 | if crate::envflags::env_flag!("EC_TRACE_SEG") { |
| 1326 | - eprintln!("EC_SEG mi_row={mi_r} mi_col={mi_c} cdf={ctx} pred={pred} coded={coded} id={id} rng={}", dec.debug_state().0); | 1389 | + eprintln!( |
| 1390 | + "EC_SEG mi_row={mi_r} mi_col={mi_c} cdf={ctx} pred={pred} coded={coded} id={id} rng={}", | ||
| 1391 | + dec.debug_state().0 | ||
| 1392 | + ); | ||
| 1327 | } | 1393 | } |
| 1328 | id as u8 | 1394 | id as u8 |
| 1329 | } | 1395 | } |
| @@ -1338,7 +1404,8 @@ fn intra_segment_id( | |||
| 1338 | mi_c: usize, | 1404 | mi_c: usize, |
| 1339 | w_mi: usize, | 1405 | w_mi: usize, |
| 1340 | h_mi: usize, | 1406 | h_mi: usize, |
| 1341 | - skip: bool, fctx: &crate::decode::FrameCtx, | 1407 | + skip: bool, |
| 1408 | + fctx: &crate::decode::FrameCtx, | ||
| 1342 | ) { | 1409 | ) { |
| 1343 | if !fctx.seg.with(|s| s.borrow().enabled) { | 1410 | if !fctx.seg.with(|s| s.borrow().enabled) { |
| 1344 | return; | 1411 | return; |
| @@ -1367,11 +1434,17 @@ fn inter_segment_id( | |||
| 1367 | w_mi: usize, | 1434 | w_mi: usize, |
| 1368 | h_mi: usize, | 1435 | h_mi: usize, |
| 1369 | skip: bool, | 1436 | skip: bool, |
| 1370 | - pre_skip: bool, fctx: &crate::decode::FrameCtx, | 1437 | + pre_skip: bool, |
| 1438 | + fctx: &crate::decode::FrameCtx, | ||
| 1371 | ) { | 1439 | ) { |
| 1372 | let (enabled, update_map, temporal_update, pre_skip_frame) = fctx.seg.with(|s| { | 1440 | let (enabled, update_map, temporal_update, pre_skip_frame) = fctx.seg.with(|s| { |
| 1373 | let s = s.borrow(); | 1441 | let s = s.borrow(); |
| 1374 | - (s.enabled, s.update_map, s.temporal_update, s.seg_id_pre_skip) | 1442 | + ( |
| 1443 | + s.enabled, | ||
| 1444 | + s.update_map, | ||
| 1445 | + s.temporal_update, | ||
| 1446 | + s.seg_id_pre_skip, | ||
| 1447 | + ) | ||
| 1375 | }); | 1448 | }); |
| 1376 | if !enabled { | 1449 | if !enabled { |
| 1377 | return; | 1450 | return; |
| @@ -1426,12 +1499,14 @@ fn seg_pred_ctx(mi_r: usize, mi_c: usize, fctx: &crate::decode::FrameCtx) -> usi | |||
| 1426 | // what keeps a previous tile's stamps out of this tile's context. | 1499 | // what keeps a previous tile's stamps out of this tile's context. |
| 1427 | let (row0, col0) = fctx.seg_tile_origin.with(|c| c.get()); | 1500 | let (row0, col0) = fctx.seg_tile_origin.with(|c| c.get()); |
| 1428 | let above = if mi_r > row0 { | 1501 | let above = if mi_r > row0 { |
| 1429 | - fctx.above_seg_pred.with(|m| m.borrow().get(mi_c).copied().unwrap_or(0)) | 1502 | + fctx.above_seg_pred |
| 1503 | + .with(|m| m.borrow().get(mi_c).copied().unwrap_or(0)) | ||
| 1430 | } else { | 1504 | } else { |
| 1431 | 0 | 1505 | 0 |
| 1432 | }; | 1506 | }; |
| 1433 | let left = if mi_c > col0 { | 1507 | let left = if mi_c > col0 { |
| 1434 | - fctx.left_seg_pred.with(|m| m.borrow().get(mi_r).copied().unwrap_or(0)) | 1508 | + fctx.left_seg_pred |
| 1509 | + .with(|m| m.borrow().get(mi_r).copied().unwrap_or(0)) | ||
| 1435 | } else { | 1510 | } else { |
| 1436 | 0 | 1511 | 0 |
| 1437 | }; | 1512 | }; |
| @@ -1439,7 +1514,14 @@ fn seg_pred_ctx(mi_r: usize, mi_c: usize, fctx: &crate::decode::FrameCtx) -> usi | |||
| 1439 | } | 1514 | } |
| 1440 | 1515 | ||
| 1441 | /// Spec 5.11.9's `AboveSegPredContext`/`LeftSegPredContext` update. | 1516 | /// Spec 5.11.9's `AboveSegPredContext`/`LeftSegPredContext` update. |
| 1442 | -fn stamp_seg_pred(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, value: u8, fctx: &crate::decode::FrameCtx) { | 1517 | +fn stamp_seg_pred( |
| 1518 | + mi_r: usize, | ||
| 1519 | + mi_c: usize, | ||
| 1520 | + w_mi: usize, | ||
| 1521 | + h_mi: usize, | ||
| 1522 | + value: u8, | ||
| 1523 | + fctx: &crate::decode::FrameCtx, | ||
| 1524 | +) { | ||
| 1443 | fctx.above_seg_pred.with(|m| { | 1525 | fctx.above_seg_pred.with(|m| { |
| 1444 | let mut m = m.borrow_mut(); | 1526 | let mut m = m.borrow_mut(); |
| 1445 | for i in 0..w_mi { | 1527 | for i in 0..w_mi { |
| @@ -1507,7 +1589,8 @@ fn tu_reach( | |||
| 1507 | px: usize, | 1589 | px: usize, |
| 1508 | py: usize, | 1590 | py: usize, |
| 1509 | width: usize, | 1591 | width: usize, |
| 1510 | - height: usize, fctx: &crate::decode::FrameCtx, | 1592 | + height: usize, |
| 1593 | + fctx: &crate::decode::FrameCtx, | ||
| 1511 | ) -> Reach { | 1594 | ) -> Reach { |
| 1512 | let fixed = Reach::of_tu(bw, bh, col_off, row_off, tx, tx, block); | 1595 | let fixed = Reach::of_tu(bw, bh, col_off, row_off, tx, tx, block); |
| 1513 | let standalone = Reach::of(tx, px + col_off, py + row_off, width, height, fctx); | 1596 | let standalone = Reach::of(tx, px + col_off, py + row_off, width, height, fctx); |
| @@ -1535,7 +1618,8 @@ fn tu_reach_rect( | |||
| 1535 | px: usize, | 1618 | px: usize, |
| 1536 | py: usize, | 1619 | py: usize, |
| 1537 | width: usize, | 1620 | width: usize, |
| 1538 | - height: usize, fctx: &crate::decode::FrameCtx, | 1621 | + height: usize, |
| 1622 | + fctx: &crate::decode::FrameCtx, | ||
| 1539 | ) -> Reach { | 1623 | ) -> Reach { |
| 1540 | let fixed = Reach::of_tu(bw, bh, col_off, row_off, tx_w, tx_h, block); | 1624 | let fixed = Reach::of_tu(bw, bh, col_off, row_off, tx_w, tx_h, block); |
| 1541 | if tx_w == tx_h { | 1625 | if tx_w == tx_h { |
| @@ -1589,8 +1673,7 @@ thread_local! { | |||
| 1589 | /// lane-comppin r4: decode-order picture counter for `EC_AV1_PREFILT_DUMP`, | 1673 | /// lane-comppin r4: decode-order picture counter for `EC_AV1_PREFILT_DUMP`, |
| 1590 | /// mirroring stream.rs's `pictures_decoded` so the two dumps index | 1674 | /// mirroring stream.rs's `pictures_decoded` so the two dumps index |
| 1591 | /// identically against aomdec's own `ec_frame_idx` in decodeframe.c. | 1675 | /// identically against aomdec's own `ec_frame_idx` in decodeframe.c. |
| 1592 | -static PREFILT_PICTURE_IDX: std::sync::atomic::AtomicUsize = | 1676 | +static PREFILT_PICTURE_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 1593 | - std::sync::atomic::AtomicUsize::new(0); | ||
| 1594 | 1677 | ||
| 1595 | /// Current value of [`DEBLOCK_HITS`]. | 1678 | /// Current value of [`DEBLOCK_HITS`]. |
| 1596 | #[allow(dead_code)] // read only from the `#[cfg(test)]` gates | 1679 | #[allow(dead_code)] // read only from the `#[cfg(test)]` gates |
| @@ -1802,7 +1885,11 @@ fn vartx_rect_leaf_hit(tw: usize, th: usize) { | |||
| 1802 | if crate::envflags::env_flag!("EC_VARTXLEAF") { | 1885 | if crate::envflags::env_flag!("EC_VARTXLEAF") { |
| 1803 | eprintln!("EC_VARTXLEAF tw={tw} th={th}"); | 1886 | eprintln!("EC_VARTXLEAF tw={tw} th={th}"); |
| 1804 | } | 1887 | } |
| 1805 | - let cell = if tw.min(th) == 4 { &VARTX_RECT_LEAF4_HITS } else { &VARTX_RECT_LEAF_HITS }; | 1888 | + let cell = if tw.min(th) == 4 { |
| 1889 | + &VARTX_RECT_LEAF4_HITS | ||
| 1890 | + } else { | ||
| 1891 | + &VARTX_RECT_LEAF_HITS | ||
| 1892 | + }; | ||
| 1806 | cell.with(|c| { | 1893 | cell.with(|c| { |
| 1807 | let mut h = c.get(); | 1894 | let mut h = c.get(); |
| 1808 | h[usize::from(th > tw)] += 1; | 1895 | h[usize::from(th > tw)] += 1; |
| @@ -1815,13 +1902,15 @@ fn vartx_rect_leaf_hit(tw: usize, th: usize) { | |||
| 1815 | pub(crate) fn set_inter_tx_mode( | 1902 | pub(crate) fn set_inter_tx_mode( |
| 1816 | tx_select: bool, | 1903 | tx_select: bool, |
| 1817 | reduced_tx_set: bool, | 1904 | reduced_tx_set: bool, |
| 1818 | - enable_filter_intra: bool, fctx: &crate::decode::FrameCtx, | 1905 | + enable_filter_intra: bool, |
| 1906 | + fctx: &crate::decode::FrameCtx, | ||
| 1819 | ) { | 1907 | ) { |
| 1820 | fctx.tx_select_inter.with(|c| c.set(tx_select)); | 1908 | fctx.tx_select_inter.with(|c| c.set(tx_select)); |
| 1821 | fctx.intra_only.with(|c| c.set(false)); | 1909 | fctx.intra_only.with(|c| c.set(false)); |
| 1822 | fctx.tx_select_frame.with(|c| c.set(tx_select)); | 1910 | fctx.tx_select_frame.with(|c| c.set(tx_select)); |
| 1823 | fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set)); | 1911 | fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set)); |
| 1824 | - fctx.enable_filter_intra_inter.with(|c| c.set(enable_filter_intra)); | 1912 | + fctx.enable_filter_intra_inter |
| 1913 | + .with(|c| c.set(enable_filter_intra)); | ||
| 1825 | } | 1914 | } |
| 1826 | 1915 | ||
| 1827 | // How many `partition_w16` reads (a 16x16 block's own partition symbol, key | 1916 | // How many `partition_w16` reads (a 16x16 block's own partition symbol, key |
| @@ -2568,7 +2657,6 @@ pub(crate) fn intra_in_inter_split_tx_hits() -> [usize; 4] { | |||
| 2568 | /// it (`.take()`), so a non-palette block's own `reconstruct` call never | 2657 | /// it (`.take()`), so a non-palette block's own `reconstruct` call never |
| 2569 | /// sees stale state. | 2658 | /// sees stale state. |
| 2570 | 2659 | ||
| 2571 | - | ||
| 2572 | /// Arms the pending [`PALETTE_PRED`] override for the next `reconstruct` | 2660 | /// Arms the pending [`PALETTE_PRED`] override for the next `reconstruct` |
| 2573 | /// (`set`) / consumes it (`take`). Set and take MUST pair: a buffer armed at a | 2661 | /// (`set`) / consumes it (`take`). Set and take MUST pair: a buffer armed at a |
| 2574 | /// site whose reconstruct never runs would be picked up by the NEXT block's | 2662 | /// site whose reconstruct never runs would be picked up by the NEXT block's |
| @@ -2579,7 +2667,14 @@ pub(crate) fn intra_in_inter_split_tx_hits() -> [usize; 4] { | |||
| 2579 | /// top-left corner (the luma split-transform paths already window; the chroma | 2667 | /// top-left corner (the luma split-transform paths already window; the chroma |
| 2580 | /// ones did not, which is invisible until a lossless frame codes a palette | 2668 | /// ones did not, which is invisible until a lossless frame codes a palette |
| 2581 | /// block as 4x4 chroma units). | 2669 | /// block as 4x4 chroma units). |
| 2582 | -fn palette_window(buf: &[u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize) -> Vec<u16> { | 2670 | +fn palette_window( |
| 2671 | + buf: &[u16], | ||
| 2672 | + stride: usize, | ||
| 2673 | + ox: usize, | ||
| 2674 | + oy: usize, | ||
| 2675 | + w: usize, | ||
| 2676 | + h: usize, | ||
| 2677 | +) -> Vec<u16> { | ||
| 2583 | (0..h) | 2678 | (0..h) |
| 2584 | .flat_map(|r| buf[(oy + r) * stride + ox..][..w].iter().copied()) | 2679 | .flat_map(|r| buf[(oy + r) * stride + ox..][..w].iter().copied()) |
| 2585 | .collect() | 2680 | .collect() |
| @@ -2624,7 +2719,12 @@ pub(crate) struct CflSrc { | |||
| 2624 | } | 2719 | } |
| 2625 | 2720 | ||
| 2626 | fn cfl_src(px: usize, py: usize, side: usize) -> CflSrc { | 2721 | fn cfl_src(px: usize, py: usize, side: usize) -> CflSrc { |
| 2627 | - CflSrc { px, py, bw: side, bh: side } | 2722 | + CflSrc { |
| 2723 | + px, | ||
| 2724 | + py, | ||
| 2725 | + bw: side, | ||
| 2726 | + bh: side, | ||
| 2727 | + } | ||
| 2628 | } | 2728 | } |
| 2629 | 2729 | ||
| 2630 | fn cfl_src_rect(px: usize, py: usize, bw: usize, bh: usize) -> CflSrc { | 2730 | fn cfl_src_rect(px: usize, py: usize, bw: usize, bh: usize) -> CflSrc { |
| @@ -2670,8 +2770,7 @@ pub(crate) struct TxParams { | |||
| 2670 | /// The mixed-lossless witness's proof the per-segment lossless path really | 2770 | /// The mixed-lossless witness's proof the per-segment lossless path really |
| 2671 | /// ran on a frame that is NOT `CodedLossless`. Atomic because the wavefront | 2771 | /// ran on a frame that is NOT `CodedLossless`. Atomic because the wavefront |
| 2672 | /// workers run this on their own threads. | 2772 | /// workers run this on their own threads. |
| 2673 | -static LOSSLESS_WHT_UNITS: std::sync::atomic::AtomicUsize = | 2773 | +static LOSSLESS_WHT_UNITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 2674 | - std::sync::atomic::AtomicUsize::new(0); | ||
| 2675 | 2774 | ||
| 2676 | /// [`LOSSLESS_WHT_UNITS`] -- total over the process, read as a before/after | 2775 | /// [`LOSSLESS_WHT_UNITS`] -- total over the process, read as a before/after |
| 2677 | /// delta around one decode. | 2776 | /// delta around one decode. |
| @@ -2690,11 +2789,21 @@ impl TxParams { | |||
| 2690 | debug_assert_eq!((self.w, self.h), (4, 4)); | 2789 | debug_assert_eq!((self.w, self.h), (4, 4)); |
| 2691 | debug_assert_eq!(self.tx_type, TxType::DctDct); | 2790 | debug_assert_eq!(self.tx_type, TxType::DctDct); |
| 2692 | crate::transform::dequant_and_inverse_wht4x4( | 2791 | crate::transform::dequant_and_inverse_wht4x4( |
| 2693 | - grid, self.bit_depth, self.q_idx, self.dc_delta, self.ac_delta, | 2792 | + grid, |
| 2793 | + self.bit_depth, | ||
| 2794 | + self.q_idx, | ||
| 2795 | + self.dc_delta, | ||
| 2796 | + self.ac_delta, | ||
| 2694 | ) | 2797 | ) |
| 2695 | } else { | 2798 | } else { |
| 2696 | dequant_and_inverse_typed_wh( | 2799 | dequant_and_inverse_typed_wh( |
| 2697 | - grid, self.w, self.h, self.bit_depth, self.q_idx, self.dc_delta, self.ac_delta, | 2800 | + grid, |
| 2801 | + self.w, | ||
| 2802 | + self.h, | ||
| 2803 | + self.bit_depth, | ||
| 2804 | + self.q_idx, | ||
| 2805 | + self.dc_delta, | ||
| 2806 | + self.ac_delta, | ||
| 2698 | self.tx_type, | 2807 | self.tx_type, |
| 2699 | self.qm, | 2808 | self.qm, |
| 2700 | ) | 2809 | ) |
| @@ -2836,7 +2945,11 @@ pub(crate) fn is_zero_grid(grid: &[i32]) -> bool { | |||
| 2836 | 2945 | ||
| 2837 | /// `residual`, or `n` zeros when it is the empty all-zero marker. | 2946 | /// `residual`, or `n` zeros when it is the empty all-zero marker. |
| 2838 | fn dense_residual(residual: &[i32], n: usize) -> &[i32] { | 2947 | fn dense_residual(residual: &[i32], n: usize) -> &[i32] { |
| 2839 | - if residual.is_empty() { &ZERO_RESIDUAL[..n] } else { residual } | 2948 | + if residual.is_empty() { |
| 2949 | + &ZERO_RESIDUAL[..n] | ||
| 2950 | + } else { | ||
| 2951 | + residual | ||
| 2952 | + } | ||
| 2840 | } | 2953 | } |
| 2841 | 2954 | ||
| 2842 | /// Where a recorded motion-compensated write reads its prediction from. | 2955 | /// Where a recorded motion-compensated write reads its prediction from. |
| @@ -2854,7 +2967,11 @@ pub(crate) enum Pred<'a> { | |||
| 2854 | Inline(&'a [u16], usize), | 2967 | Inline(&'a [u16], usize), |
| 2855 | /// The current block's deferred prediction: plane, its stride, and this | 2968 | /// The current block's deferred prediction: plane, its stride, and this |
| 2856 | /// unit's offset into it. | 2969 | /// unit's offset into it. |
| 2857 | - Cur { plane: usize, stride: usize, off: usize }, | 2970 | + Cur { |
| 2971 | + plane: usize, | ||
| 2972 | + stride: usize, | ||
| 2973 | + off: usize, | ||
| 2974 | + }, | ||
| 2858 | } | 2975 | } |
| 2859 | 2976 | ||
| 2860 | impl<'a> Pred<'a> { | 2977 | impl<'a> Pred<'a> { |
| @@ -2878,7 +2995,11 @@ impl<'a> Pred<'a> { | |||
| 2878 | fn offset(self, n: usize) -> Self { | 2995 | fn offset(self, n: usize) -> Self { |
| 2879 | match self { | 2996 | match self { |
| 2880 | Self::Inline(b, s) => Self::Inline(&b[n..], s), | 2997 | Self::Inline(b, s) => Self::Inline(&b[n..], s), |
| 2881 | - Self::Cur { plane, stride, off } => Self::Cur { plane, stride, off: off + n }, | 2998 | + Self::Cur { plane, stride, off } => Self::Cur { |
| 2999 | + plane, | ||
| 3000 | + stride, | ||
| 3001 | + off: off + n, | ||
| 3002 | + }, | ||
| 2882 | } | 3003 | } |
| 2883 | } | 3004 | } |
| 2884 | } | 3005 | } |
| @@ -2891,7 +3012,11 @@ pub(crate) enum PredSrc { | |||
| 2891 | /// stride it is read at -- which is the block's, not necessarily the | 3012 | /// stride it is read at -- which is the block's, not necessarily the |
| 2892 | /// op's (a transform unit's residual stays dense, so the worker takes | 3013 | /// op's (a transform unit's residual stays dense, so the worker takes |
| 2893 | /// its window out of the block prediction itself). | 3014 | /// its window out of the block prediction itself). |
| 2894 | - Cur { plane: usize, off: usize, src: usize }, | 3015 | + Cur { |
| 3016 | + plane: usize, | ||
| 3017 | + off: usize, | ||
| 3018 | + src: usize, | ||
| 3019 | + }, | ||
| 2895 | } | 3020 | } |
| 2896 | 3021 | ||
| 2897 | /// One block's whole-block prediction build, deferred to a recon worker. | 3022 | /// One block's whole-block prediction build, deferred to a recon worker. |
| @@ -3090,7 +3215,16 @@ fn push_op(fctx: &crate::decode::FrameCtx, op: ReconOp) { | |||
| 3090 | // The inline path never records coefficients (the transform runs at | 3215 | // The inline path never records coefficients (the transform runs at |
| 3091 | // the push site), so the arena is not read here. | 3216 | // the push site), so the arena is not read here. |
| 3092 | unsafe { | 3217 | unsafe { |
| 3093 | - exec_op(op, &mut *y, &mut *u, &mut *v, &mut Default::default(), &[], &[], fctx) | 3218 | + exec_op( |
| 3219 | + op, | ||
| 3220 | + &mut *y, | ||
| 3221 | + &mut *u, | ||
| 3222 | + &mut *v, | ||
| 3223 | + &mut Default::default(), | ||
| 3224 | + &[], | ||
| 3225 | + &[], | ||
| 3226 | + fctx, | ||
| 3227 | + ) | ||
| 3094 | }; | 3228 | }; |
| 3095 | return; | 3229 | return; |
| 3096 | } | 3230 | } |
| @@ -3172,11 +3306,7 @@ type JobBufs = (Vec<ReconOp>, Vec<i32>, Vec<u16>); | |||
| 3172 | impl WaveQueue { | 3306 | impl WaveQueue { |
| 3173 | /// The lowest-row queued job whose wavefront dependencies are satisfied, | 3307 | /// The lowest-row queued job whose wavefront dependencies are satisfied, |
| 3174 | /// or `None` (with the blocking condition counted when instrumented). | 3308 | /// or `None` (with the blocking condition counted when instrumented). |
| 3175 | - fn take_runnable( | 3309 | + fn take_runnable(&mut self, last_col: usize, stats: bool) -> Option<(usize, usize, ReconJob)> { |
| 3176 | - &mut self, | ||
| 3177 | - last_col: usize, | ||
| 3178 | - stats: bool, | ||
| 3179 | - ) -> Option<(usize, usize, ReconJob)> { | ||
| 3180 | let mut blocked: Option<bool> = None; | 3310 | let mut blocked: Option<bool> = None; |
| 3181 | for r in 0..self.rows.len() { | 3311 | for r in 0..self.rows.len() { |
| 3182 | let Some(front) = self.rows[r].front() else { | 3312 | let Some(front) = self.rows[r].front() else { |
| @@ -3312,10 +3442,16 @@ fn wave_worker(st: &WaveState, idx: usize) { | |||
| 3312 | // every superblock that could have written or be reading them is | 3442 | // every superblock that could have written or be reading them is |
| 3313 | // complete by the wavefront rule above. | 3443 | // complete by the wavefront rule above. |
| 3314 | let mut cur: [Vec<u16>; 3] = Default::default(); | 3444 | let mut cur: [Vec<u16>; 3] = Default::default(); |
| 3315 | - let ReconJob { mut ops, mut coeffs, mut preds } = job; | 3445 | + let ReconJob { |
| 3446 | + mut ops, | ||
| 3447 | + mut coeffs, | ||
| 3448 | + mut preds, | ||
| 3449 | + } = job; | ||
| 3316 | unsafe { | 3450 | unsafe { |
| 3317 | for op in ops.drain(..) { | 3451 | for op in ops.drain(..) { |
| 3318 | - exec_op(op, &mut *y, &mut *u, &mut *v, &mut cur, &coeffs, &preds, &fctx); | 3452 | + exec_op( |
| 3453 | + op, &mut *y, &mut *u, &mut *v, &mut cur, &coeffs, &preds, &fctx, | ||
| 3454 | + ); | ||
| 3319 | } | 3455 | } |
| 3320 | } | 3456 | } |
| 3321 | if stats { | 3457 | if stats { |
| @@ -3361,7 +3497,9 @@ impl<'a> WaveGuard<'a> { | |||
| 3361 | } | 3497 | } |
| 3362 | let st = std::sync::Arc::new(WaveState { | 3498 | let st = std::sync::Arc::new(WaveState { |
| 3363 | q: std::sync::Mutex::new(WaveQueue { | 3499 | q: std::sync::Mutex::new(WaveQueue { |
| 3364 | - rows: (0..rows).map(|_| std::collections::VecDeque::new()).collect(), | 3500 | + rows: (0..rows) |
| 3501 | + .map(|_| std::collections::VecDeque::new()) | ||
| 3502 | + .collect(), | ||
| 3365 | queued: 0, | 3503 | queued: 0, |
| 3366 | done: vec![-1; rows], | 3504 | done: vec![-1; rows], |
| 3367 | last_sub: vec![-1; rows], | 3505 | last_sub: vec![-1; rows], |
| @@ -3393,7 +3531,8 @@ impl<'a> WaveGuard<'a> { | |||
| 3393 | batch.submit(move || wave_worker(&st, idx)); | 3531 | batch.submit(move || wave_worker(&st, idx)); |
| 3394 | } | 3532 | } |
| 3395 | fctx.wave.with(|w| *w.borrow_mut() = Some(st)); | 3533 | fctx.wave.with(|w| *w.borrow_mut() = Some(st)); |
| 3396 | - fctx.wave_mark.with(|c| c.set(Some(std::time::Instant::now()))); | 3534 | + fctx.wave_mark |
| 3535 | + .with(|c| c.set(Some(std::time::Instant::now()))); | ||
| 3397 | Some(Self(fctx, Some(batch))) | 3536 | Some(Self(fctx, Some(batch))) |
| 3398 | } | 3537 | } |
| 3399 | } | 3538 | } |
| @@ -3527,8 +3666,24 @@ fn inline_intra( | |||
| 3527 | // SAFETY: see [`ReconPlanes`]. | 3666 | // SAFETY: see [`ReconPlanes`]. |
| 3528 | unsafe { | 3667 | unsafe { |
| 3529 | exec_intra( | 3668 | exec_intra( |
| 3530 | - &mut *y, &mut *u, &mut *v, plane, x, oy, bw, bh, rect, mode, angle_delta, reach, | 3669 | + &mut *y, |
| 3531 | - residual, cfl, filter_intra, smooth_neighbor, pred, fctx, | 3670 | + &mut *u, |
| 3671 | + &mut *v, | ||
| 3672 | + plane, | ||
| 3673 | + x, | ||
| 3674 | + oy, | ||
| 3675 | + bw, | ||
| 3676 | + bh, | ||
| 3677 | + rect, | ||
| 3678 | + mode, | ||
| 3679 | + angle_delta, | ||
| 3680 | + reach, | ||
| 3681 | + residual, | ||
| 3682 | + cfl, | ||
| 3683 | + filter_intra, | ||
| 3684 | + smooth_neighbor, | ||
| 3685 | + pred, | ||
| 3686 | + fctx, | ||
| 3532 | ); | 3687 | ); |
| 3533 | } | 3688 | } |
| 3534 | true | 3689 | true |
| @@ -3553,7 +3708,9 @@ fn inline_mc( | |||
| 3553 | }; | 3708 | }; |
| 3554 | // SAFETY: see [`ReconPlanes`]. | 3709 | // SAFETY: see [`ReconPlanes`]. |
| 3555 | unsafe { | 3710 | unsafe { |
| 3556 | - exec_mc(&mut *y, &mut *u, &mut *v, plane, x, oy, stride, w, h, prediction, residual, fctx); | 3711 | + exec_mc( |
| 3712 | + &mut *y, &mut *u, &mut *v, plane, x, oy, stride, w, h, prediction, residual, fctx, | ||
| 3713 | + ); | ||
| 3557 | } | 3714 | } |
| 3558 | true | 3715 | true |
| 3559 | } | 3716 | } |
| @@ -3571,19 +3728,47 @@ fn push_intra( | |||
| 3571 | residual: &[i32], | 3728 | residual: &[i32], |
| 3572 | cfl: Option<(i32, CflSrc)>, | 3729 | cfl: Option<(i32, CflSrc)>, |
| 3573 | filter_intra: Option<usize>, | 3730 | filter_intra: Option<usize>, |
| 3574 | - smooth_neighbor: bool, fctx: &crate::decode::FrameCtx, | 3731 | + smooth_neighbor: bool, |
| 3732 | + fctx: &crate::decode::FrameCtx, | ||
| 3575 | ) { | 3733 | ) { |
| 3576 | if inline_intra( | 3734 | if inline_intra( |
| 3577 | - plane, x, y, side, side, false, mode, angle_delta, reach, residual, cfl, filter_intra, | 3735 | + plane, |
| 3578 | - smooth_neighbor, fctx, | 3736 | + x, |
| 3737 | + y, | ||
| 3738 | + side, | ||
| 3739 | + side, | ||
| 3740 | + false, | ||
| 3741 | + mode, | ||
| 3742 | + angle_delta, | ||
| 3743 | + reach, | ||
| 3744 | + residual, | ||
| 3745 | + cfl, | ||
| 3746 | + filter_intra, | ||
| 3747 | + smooth_neighbor, | ||
| 3748 | + fctx, | ||
| 3579 | ) { | 3749 | ) { |
| 3580 | return; | 3750 | return; |
| 3581 | } | 3751 | } |
| 3582 | let pred = take_palette_pred(fctx); | 3752 | let pred = take_palette_pred(fctx); |
| 3583 | - push_op(fctx, ReconOp::Intra { | 3753 | + push_op( |
| 3584 | - plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach, | 3754 | + fctx, |
| 3585 | - residual: Residual::done(residual, fctx), cfl, filter_intra, smooth_neighbor, pred, | 3755 | + ReconOp::Intra { |
| 3586 | - }); | 3756 | + plane, |
| 3757 | + x, | ||
| 3758 | + y, | ||
| 3759 | + bw: side, | ||
| 3760 | + bh: side, | ||
| 3761 | + rect: false, | ||
| 3762 | + mode, | ||
| 3763 | + angle_delta, | ||
| 3764 | + reach, | ||
| 3765 | + residual: Residual::done(residual, fctx), | ||
| 3766 | + cfl, | ||
| 3767 | + filter_intra, | ||
| 3768 | + smooth_neighbor, | ||
| 3769 | + pred, | ||
| 3770 | + }, | ||
| 3771 | + ); | ||
| 3587 | } | 3772 | } |
| 3588 | 3773 | ||
| 3589 | /// [`PlaneBuf::reconstruct_rect`], recorded (lane-wave1 step (i)). | 3774 | /// [`PlaneBuf::reconstruct_rect`], recorded (lane-wave1 step (i)). |
| @@ -3600,19 +3785,47 @@ fn push_intra_rect( | |||
| 3600 | residual: &[i32], | 3785 | residual: &[i32], |
| 3601 | cfl: Option<(i32, CflSrc)>, | 3786 | cfl: Option<(i32, CflSrc)>, |
| 3602 | filter_intra: Option<usize>, | 3787 | filter_intra: Option<usize>, |
| 3603 | - smooth_neighbor: bool, fctx: &crate::decode::FrameCtx, | 3788 | + smooth_neighbor: bool, |
| 3789 | + fctx: &crate::decode::FrameCtx, | ||
| 3604 | ) { | 3790 | ) { |
| 3605 | if inline_intra( | 3791 | if inline_intra( |
| 3606 | - plane, x, y, bw, bh, true, mode, angle_delta, reach, residual, cfl, filter_intra, | 3792 | + plane, |
| 3607 | - smooth_neighbor, fctx, | 3793 | + x, |
| 3794 | + y, | ||
| 3795 | + bw, | ||
| 3796 | + bh, | ||
| 3797 | + true, | ||
| 3798 | + mode, | ||
| 3799 | + angle_delta, | ||
| 3800 | + reach, | ||
| 3801 | + residual, | ||
| 3802 | + cfl, | ||
| 3803 | + filter_intra, | ||
| 3804 | + smooth_neighbor, | ||
| 3805 | + fctx, | ||
| 3608 | ) { | 3806 | ) { |
| 3609 | return; | 3807 | return; |
| 3610 | } | 3808 | } |
| 3611 | let pred = take_palette_pred(fctx); | 3809 | let pred = take_palette_pred(fctx); |
| 3612 | - push_op(fctx, ReconOp::Intra { | 3810 | + push_op( |
| 3613 | - plane, x, y, bw, bh, rect: true, mode, angle_delta, reach, | 3811 | + fctx, |
| 3614 | - residual: Residual::done(residual, fctx), cfl, filter_intra, smooth_neighbor, pred, | 3812 | + ReconOp::Intra { |
| 3615 | - }); | 3813 | + plane, |
| 3814 | + x, | ||
| 3815 | + y, | ||
| 3816 | + bw, | ||
| 3817 | + bh, | ||
| 3818 | + rect: true, | ||
| 3819 | + mode, | ||
| 3820 | + angle_delta, | ||
| 3821 | + reach, | ||
| 3822 | + residual: Residual::done(residual, fctx), | ||
| 3823 | + cfl, | ||
| 3824 | + filter_intra, | ||
| 3825 | + smooth_neighbor, | ||
| 3826 | + pred, | ||
| 3827 | + }, | ||
| 3828 | + ); | ||
| 3616 | } | 3829 | } |
| 3617 | 3830 | ||
| 3618 | /// [`PlaneBuf::reconstruct_mc_rect`] at `stride == w == h == side`, recorded. | 3831 | /// [`PlaneBuf::reconstruct_mc_rect`] at `stride == w == h == side`, recorded. |
| @@ -3622,7 +3835,8 @@ fn push_mc( | |||
| 3622 | y: usize, | 3835 | y: usize, |
| 3623 | side: usize, | 3836 | side: usize, |
| 3624 | prediction: Pred<'_>, | 3837 | prediction: Pred<'_>, |
| 3625 | - residual: &[i32], fctx: &crate::decode::FrameCtx, | 3838 | + residual: &[i32], |
| 3839 | + fctx: &crate::decode::FrameCtx, | ||
| 3626 | ) { | 3840 | ) { |
| 3627 | push_mc_rect(plane, x, y, side, side, side, prediction, residual, fctx); | 3841 | push_mc_rect(plane, x, y, side, side, side, prediction, residual, fctx); |
| 3628 | } | 3842 | } |
| @@ -3637,30 +3851,58 @@ fn push_mc_rect( | |||
| 3637 | w: usize, | 3851 | w: usize, |
| 3638 | h: usize, | 3852 | h: usize, |
| 3639 | prediction: Pred<'_>, | 3853 | prediction: Pred<'_>, |
| 3640 | - residual: &[i32], fctx: &crate::decode::FrameCtx, | 3854 | + residual: &[i32], |
| 3855 | + fctx: &crate::decode::FrameCtx, | ||
| 3641 | ) { | 3856 | ) { |
| 3642 | let (src, stride) = match prediction.inline(stride) { | 3857 | let (src, stride) = match prediction.inline(stride) { |
| 3643 | Some(v) => v, | 3858 | Some(v) => v, |
| 3644 | None => { | 3859 | None => { |
| 3645 | - let Pred::Cur { plane: sp, stride: ss, off } = prediction else { unreachable!() }; | 3860 | + let Pred::Cur { |
| 3646 | - push_op(fctx, ReconOp::Mc { | 3861 | + plane: sp, |
| 3647 | - plane, x, y, stride: ss, w, h, | 3862 | + stride: ss, |
| 3648 | - prediction: PredSrc::Cur { plane: sp, off, src: ss }, | 3863 | + off, |
| 3864 | + } = prediction | ||
| 3865 | + else { | ||
| 3866 | + unreachable!() | ||
| 3867 | + }; | ||
| 3868 | + push_op( | ||
| 3869 | + fctx, | ||
| 3870 | + ReconOp::Mc { | ||
| 3871 | + plane, | ||
| 3872 | + x, | ||
| 3873 | + y, | ||
| 3874 | + stride: ss, | ||
| 3875 | + w, | ||
| 3876 | + h, | ||
| 3877 | + prediction: PredSrc::Cur { | ||
| 3878 | + plane: sp, | ||
| 3879 | + off, | ||
| 3880 | + src: ss, | ||
| 3881 | + }, | ||
| 3649 | residual: Residual::done(residual, fctx), | 3882 | residual: Residual::done(residual, fctx), |
| 3650 | - }); | 3883 | + }, |
| 3884 | + ); | ||
| 3651 | return; | 3885 | return; |
| 3652 | } | 3886 | } |
| 3653 | }; | 3887 | }; |
| 3654 | if inline_mc(plane, x, y, stride, w, h, src, residual, fctx) { | 3888 | if inline_mc(plane, x, y, stride, w, h, src, residual, fctx) { |
| 3655 | return; | 3889 | return; |
| 3656 | } | 3890 | } |
| 3657 | - push_op(fctx, ReconOp::Mc { | 3891 | + push_op( |
| 3658 | - plane, x, y, stride, w, h, | 3892 | + fctx, |
| 3893 | + ReconOp::Mc { | ||
| 3894 | + plane, | ||
| 3895 | + x, | ||
| 3896 | + y, | ||
| 3897 | + stride, | ||
| 3898 | + w, | ||
| 3899 | + h, | ||
| 3659 | // The whole window `reconstruct_mc_rect` reads at `stride`, not | 3900 | // The whole window `reconstruct_mc_rect` reads at `stride`, not |
| 3660 | // `w * h`: the record keeps exactly what `src.to_vec()` carried. | 3901 | // `w * h`: the record keeps exactly what `src.to_vec()` carried. |
| 3661 | prediction: PredSrc::Owned(push_pred_samples(src, fctx), src.len() as u32), | 3902 | prediction: PredSrc::Owned(push_pred_samples(src, fctx), src.len() as u32), |
| 3662 | residual: Residual::done(residual, fctx), | 3903 | residual: Residual::done(residual, fctx), |
| 3663 | - }); | 3904 | + }, |
| 3905 | + ); | ||
| 3664 | } | 3906 | } |
| 3665 | 3907 | ||
| 3666 | /// [`push_intra_rect`] carrying the transform's INPUTS: at one reconstruction | 3908 | /// [`push_intra_rect`] carrying the transform's INPUTS: at one reconstruction |
| @@ -3686,16 +3928,43 @@ fn push_intra_tx( | |||
| 3686 | ) { | 3928 | ) { |
| 3687 | if fctx.recon_planes.with(std::cell::Cell::get).is_some() { | 3929 | if fctx.recon_planes.with(std::cell::Cell::get).is_some() { |
| 3688 | inline_intra( | 3930 | inline_intra( |
| 3689 | - plane, x, y, bw, bh, rect, mode, angle_delta, reach, &tx.run(grid), cfl, filter_intra, | 3931 | + plane, |
| 3690 | - smooth_neighbor, fctx, | 3932 | + x, |
| 3933 | + y, | ||
| 3934 | + bw, | ||
| 3935 | + bh, | ||
| 3936 | + rect, | ||
| 3937 | + mode, | ||
| 3938 | + angle_delta, | ||
| 3939 | + reach, | ||
| 3940 | + &tx.run(grid), | ||
| 3941 | + cfl, | ||
| 3942 | + filter_intra, | ||
| 3943 | + smooth_neighbor, | ||
| 3944 | + fctx, | ||
| 3691 | ); | 3945 | ); |
| 3692 | return; | 3946 | return; |
| 3693 | } | 3947 | } |
| 3694 | let pred = take_palette_pred(fctx); | 3948 | let pred = take_palette_pred(fctx); |
| 3695 | - push_op(fctx, ReconOp::Intra { | 3949 | + push_op( |
| 3696 | - plane, x, y, bw, bh, rect, mode, angle_delta, reach, | 3950 | + fctx, |
| 3697 | - residual: Residual::coeffs(tx, grid, fctx), cfl, filter_intra, smooth_neighbor, pred, | 3951 | + ReconOp::Intra { |
| 3698 | - }); | 3952 | + plane, |
| 3953 | + x, | ||
| 3954 | + y, | ||
| 3955 | + bw, | ||
| 3956 | + bh, | ||
| 3957 | + rect, | ||
| 3958 | + mode, | ||
| 3959 | + angle_delta, | ||
| 3960 | + reach, | ||
| 3961 | + residual: Residual::coeffs(tx, grid, fctx), | ||
| 3962 | + cfl, | ||
| 3963 | + filter_intra, | ||
| 3964 | + smooth_neighbor, | ||
| 3965 | + pred, | ||
| 3966 | + }, | ||
| 3967 | + ); | ||
| 3699 | } | 3968 | } |
| 3700 | 3969 | ||
| 3701 | /// [`push_mc_rect`] carrying the transform's inputs -- see [`push_intra_tx`]. | 3970 | /// [`push_mc_rect`] carrying the transform's inputs -- see [`push_intra_tx`]. |
| @@ -3719,14 +3988,33 @@ fn push_mc_rect_tx( | |||
| 3719 | let (prediction, stride) = match prediction.inline(stride) { | 3988 | let (prediction, stride) = match prediction.inline(stride) { |
| 3720 | Some(v) => v, | 3989 | Some(v) => v, |
| 3721 | None => { | 3990 | None => { |
| 3722 | - let Pred::Cur { plane: sp, stride: ss, off } = prediction else { unreachable!() }; | 3991 | + let Pred::Cur { |
| 3992 | + plane: sp, | ||
| 3993 | + stride: ss, | ||
| 3994 | + off, | ||
| 3995 | + } = prediction | ||
| 3996 | + else { | ||
| 3997 | + unreachable!() | ||
| 3998 | + }; | ||
| 3723 | let mut tx = tx; | 3999 | let mut tx = tx; |
| 3724 | tx.stride = 0; | 4000 | tx.stride = 0; |
| 3725 | - push_op(fctx, ReconOp::Mc { | 4001 | + push_op( |
| 3726 | - plane, x, y, stride: w, w, h, | 4002 | + fctx, |
| 3727 | - prediction: PredSrc::Cur { plane: sp, off, src: ss }, | 4003 | + ReconOp::Mc { |
| 4004 | + plane, | ||
| 4005 | + x, | ||
| 4006 | + y, | ||
| 4007 | + stride: w, | ||
| 4008 | + w, | ||
| 4009 | + h, | ||
| 4010 | + prediction: PredSrc::Cur { | ||
| 4011 | + plane: sp, | ||
| 4012 | + off, | ||
| 4013 | + src: ss, | ||
| 4014 | + }, | ||
| 3728 | residual: Residual::coeffs(tx, grid, fctx), | 4015 | residual: Residual::coeffs(tx, grid, fctx), |
| 3729 | - }); | 4016 | + }, |
| 4017 | + ); | ||
| 3730 | return; | 4018 | return; |
| 3731 | } | 4019 | } |
| 3732 | }; | 4020 | }; |
| @@ -3768,10 +4056,19 @@ fn push_mc_rect_tx( | |||
| 3768 | }); | 4056 | }); |
| 3769 | let mut tx = tx; | 4057 | let mut tx = tx; |
| 3770 | tx.stride = 0; | 4058 | tx.stride = 0; |
| 3771 | - push_op(fctx, ReconOp::Mc { | 4059 | + push_op( |
| 3772 | - plane, x, y, stride: w, w, h, prediction: PredSrc::Owned(off, (w * h) as u32), | 4060 | + fctx, |
| 4061 | + ReconOp::Mc { | ||
| 4062 | + plane, | ||
| 4063 | + x, | ||
| 4064 | + y, | ||
| 4065 | + stride: w, | ||
| 4066 | + w, | ||
| 4067 | + h, | ||
| 4068 | + prediction: PredSrc::Owned(off, (w * h) as u32), | ||
| 3773 | residual: Residual::coeffs(tx, grid, fctx), | 4069 | residual: Residual::coeffs(tx, grid, fctx), |
| 3774 | - }); | 4070 | + }, |
| 4071 | + ); | ||
| 3775 | } | 4072 | } |
| 3776 | 4073 | ||
| 3777 | /// Replays every recorded [`ReconOp`] into the frame's planes, in push order, | 4074 | /// Replays every recorded [`ReconOp`] into the frame's planes, in push order, |
| @@ -3791,12 +4088,21 @@ fn flush_recon( | |||
| 3791 | // lane-wave1 step (ii): a parse-time pixel READ needs every worker's | 4088 | // lane-wave1 step (ii): a parse-time pixel READ needs every worker's |
| 3792 | // writes in place, not just this superblock's queue. | 4089 | // writes in place, not just this superblock's queue. |
| 3793 | wave_barrier(fctx); | 4090 | wave_barrier(fctx); |
| 3794 | - let mut ops = fctx.recon_spare.with(|c| std::mem::take(&mut *c.borrow_mut())); | 4091 | + let mut ops = fctx |
| 3795 | - fctx.recon_ops.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut ops)); | 4092 | + .recon_spare |
| 3796 | - let mut coeffs = fctx.coeff_spare.with(|c| std::mem::take(&mut *c.borrow_mut())); | 4093 | + .with(|c| std::mem::take(&mut *c.borrow_mut())); |
| 3797 | - fctx.coeff_arena.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut coeffs)); | 4094 | + fctx.recon_ops |
| 3798 | - let mut preds = fctx.pred_spare.with(|c| std::mem::take(&mut *c.borrow_mut())); | 4095 | + .with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut ops)); |
| 3799 | - fctx.pred_arena.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut preds)); | 4096 | + let mut coeffs = fctx |
| 4097 | + .coeff_spare | ||
| 4098 | + .with(|c| std::mem::take(&mut *c.borrow_mut())); | ||
| 4099 | + fctx.coeff_arena | ||
| 4100 | + .with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut coeffs)); | ||
| 4101 | + let mut preds = fctx | ||
| 4102 | + .pred_spare | ||
| 4103 | + .with(|c| std::mem::take(&mut *c.borrow_mut())); | ||
| 4104 | + fctx.pred_arena | ||
| 4105 | + .with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut preds)); | ||
| 3800 | let mut cur: [Vec<u16>; 3] = Default::default(); | 4106 | let mut cur: [Vec<u16>; 3] = Default::default(); |
| 3801 | for op in ops.drain(..) { | 4107 | for op in ops.drain(..) { |
| 3802 | exec_op(op, y, u, v, &mut cur, &coeffs, &preds, fctx); | 4108 | exec_op(op, y, u, v, &mut cur, &coeffs, &preds, fctx); |
| @@ -3838,24 +4144,77 @@ fn exec_op( | |||
| 3838 | match op { | 4144 | match op { |
| 3839 | ReconOp::Pred(b) => (b.0)(y, u, v, fctx, cur), | 4145 | ReconOp::Pred(b) => (b.0)(y, u, v, fctx, cur), |
| 3840 | ReconOp::Intra { | 4146 | ReconOp::Intra { |
| 3841 | - plane, x, y: oy, bw, bh, rect, mode, angle_delta, reach, residual, cfl, | 4147 | + plane, |
| 3842 | - filter_intra, smooth_neighbor, pred, | 4148 | + x, |
| 4149 | + y: oy, | ||
| 4150 | + bw, | ||
| 4151 | + bh, | ||
| 4152 | + rect, | ||
| 4153 | + mode, | ||
| 4154 | + angle_delta, | ||
| 4155 | + reach, | ||
| 4156 | + residual, | ||
| 4157 | + cfl, | ||
| 4158 | + filter_intra, | ||
| 4159 | + smooth_neighbor, | ||
| 4160 | + pred, | ||
| 3843 | } => exec_intra( | 4161 | } => exec_intra( |
| 3844 | - y, u, v, plane, x, oy, bw, bh, rect, mode, angle_delta, reach, | 4162 | + y, |
| 4163 | + u, | ||
| 4164 | + v, | ||
| 4165 | + plane, | ||
| 4166 | + x, | ||
| 4167 | + oy, | ||
| 4168 | + bw, | ||
| 4169 | + bh, | ||
| 4170 | + rect, | ||
| 4171 | + mode, | ||
| 4172 | + angle_delta, | ||
| 4173 | + reach, | ||
| 3845 | residual.resolve(coeffs, &mut scratch), | 4174 | residual.resolve(coeffs, &mut scratch), |
| 3846 | - cfl, filter_intra, smooth_neighbor, pred, fctx, | 4175 | + cfl, |
| 4176 | + filter_intra, | ||
| 4177 | + smooth_neighbor, | ||
| 4178 | + pred, | ||
| 4179 | + fctx, | ||
| 3847 | ), | 4180 | ), |
| 3848 | - ReconOp::Mc { plane, x, y: oy, stride, w, h, prediction, residual } => { | 4181 | + ReconOp::Mc { |
| 4182 | + plane, | ||
| 4183 | + x, | ||
| 4184 | + y: oy, | ||
| 4185 | + stride, | ||
| 4186 | + w, | ||
| 4187 | + h, | ||
| 4188 | + prediction, | ||
| 4189 | + residual, | ||
| 4190 | + } => { | ||
| 3849 | let residual = residual.resolve(coeffs, &mut scratch); | 4191 | let residual = residual.resolve(coeffs, &mut scratch); |
| 3850 | match prediction { | 4192 | match prediction { |
| 3851 | PredSrc::Owned(off, len) => { | 4193 | PredSrc::Owned(off, len) => { |
| 3852 | let p = &preds[off as usize..][..len as usize]; | 4194 | let p = &preds[off as usize..][..len as usize]; |
| 3853 | exec_mc(y, u, v, plane, x, oy, stride, w, h, p, residual, fctx); | 4195 | exec_mc(y, u, v, plane, x, oy, stride, w, h, p, residual, fctx); |
| 3854 | } | 4196 | } |
| 3855 | - PredSrc::Cur { plane: sp, off, src } => { | 4197 | + PredSrc::Cur { |
| 4198 | + plane: sp, | ||
| 4199 | + off, | ||
| 4200 | + src, | ||
| 4201 | + } => { | ||
| 3856 | let block = std::mem::take(&mut cur[sp]); | 4202 | let block = std::mem::take(&mut cur[sp]); |
| 3857 | if src == stride { | 4203 | if src == stride { |
| 3858 | - exec_mc(y, u, v, plane, x, oy, stride, w, h, &block[off..], residual, fctx); | 4204 | + exec_mc( |
| 4205 | + y, | ||
| 4206 | + u, | ||
| 4207 | + v, | ||
| 4208 | + plane, | ||
| 4209 | + x, | ||
| 4210 | + oy, | ||
| 4211 | + stride, | ||
| 4212 | + w, | ||
| 4213 | + h, | ||
| 4214 | + &block[off..], | ||
| 4215 | + residual, | ||
| 4216 | + fctx, | ||
| 4217 | + ); | ||
| 3859 | } else { | 4218 | } else { |
| 3860 | // A transform unit's residual is dense, so its window | 4219 | // A transform unit's residual is dense, so its window |
| 3861 | // of the block prediction is taken out dense too -- | 4220 | // of the block prediction is taken out dense too -- |
| @@ -3906,16 +4265,41 @@ fn exec_intra( | |||
| 3906 | (alpha, sig) | 4265 | (alpha, sig) |
| 3907 | }); | 4266 | }); |
| 3908 | let cfl = ac.as_ref().map(|(a, sig)| (*a, sig.as_slice())); | 4267 | let cfl = ac.as_ref().map(|(a, sig)| (*a, sig.as_slice())); |
| 3909 | - let target: &mut PlaneBuf<'static> = match plane { 0 => &mut *y, 1 => &mut *u, _ => &mut *v }; | 4268 | + let target: &mut PlaneBuf<'static> = match plane { |
| 4269 | + 0 => &mut *y, | ||
| 4270 | + 1 => &mut *u, | ||
| 4271 | + _ => &mut *v, | ||
| 4272 | + }; | ||
| 3910 | if rect { | 4273 | if rect { |
| 3911 | target.reconstruct_rect( | 4274 | target.reconstruct_rect( |
| 3912 | - x, oy, bw, bh, mode, angle_delta, reach, residual, cfl, filter_intra, | 4275 | + x, |
| 3913 | - smooth_neighbor, pred, fctx, | 4276 | + oy, |
| 4277 | + bw, | ||
| 4278 | + bh, | ||
| 4279 | + mode, | ||
| 4280 | + angle_delta, | ||
| 4281 | + reach, | ||
| 4282 | + residual, | ||
| 4283 | + cfl, | ||
| 4284 | + filter_intra, | ||
| 4285 | + smooth_neighbor, | ||
| 4286 | + pred, | ||
| 4287 | + fctx, | ||
| 3914 | ); | 4288 | ); |
| 3915 | } else { | 4289 | } else { |
| 3916 | target.reconstruct( | 4290 | target.reconstruct( |
| 3917 | - x, oy, bw, mode, angle_delta, reach, residual, cfl, filter_intra, | 4291 | + x, |
| 3918 | - smooth_neighbor, pred, fctx, | 4292 | + oy, |
| 4293 | + bw, | ||
| 4294 | + mode, | ||
| 4295 | + angle_delta, | ||
| 4296 | + reach, | ||
| 4297 | + residual, | ||
| 4298 | + cfl, | ||
| 4299 | + filter_intra, | ||
| 4300 | + smooth_neighbor, | ||
| 4301 | + pred, | ||
| 4302 | + fctx, | ||
| 3919 | ); | 4303 | ); |
| 3920 | } | 4304 | } |
| 3921 | } | 4305 | } |
| @@ -3936,7 +4320,11 @@ fn exec_mc( | |||
| 3936 | residual: &[i32], | 4320 | residual: &[i32], |
| 3937 | fctx: &crate::decode::FrameCtx, | 4321 | fctx: &crate::decode::FrameCtx, |
| 3938 | ) { | 4322 | ) { |
| 3939 | - let target: &mut PlaneBuf<'static> = match plane { 0 => &mut *y, 1 => &mut *u, _ => &mut *v }; | 4323 | + let target: &mut PlaneBuf<'static> = match plane { |
| 4324 | + 0 => &mut *y, | ||
| 4325 | + 1 => &mut *u, | ||
| 4326 | + _ => &mut *v, | ||
| 4327 | + }; | ||
| 3940 | target.reconstruct_mc_rect(x, oy, stride, w, h, prediction, residual, fctx); | 4328 | target.reconstruct_mc_rect(x, oy, stride, w, h, prediction, residual, fctx); |
| 3941 | } | 4329 | } |
| 3942 | 4330 | ||
| @@ -4179,6 +4567,21 @@ thread_local! { | |||
| 4179 | /// guard (`decode_block_128rect`). A refused block bumps | 4567 | /// guard (`decode_block_128rect`). A refused block bumps |
| 4180 | /// [`INTRABC_HITS`] but never this one. | 4568 | /// [`INTRABC_HITS`] but never this one. |
| 4181 | static INTRABC_128RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 4569 | static INTRABC_128RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 4570 | + /// lane-av1-ibc128chunk: chroma transform units the 128-root intrabc | ||
| 4571 | + /// strip's mu-chunk walk read, one per `read_inter_plane` chroma call. | ||
| 4572 | + /// At 4:2:0 a 64x64 mu chunk's chroma plane block is 32x32, so one | ||
| 4573 | + /// TX_32X32 per plane per chunk; at 4:2:2 it is 32x64 and holds TWO | ||
| 4574 | + /// STACKED units per plane. The square-cut `chunk_chroma = cside * 64 / | ||
| 4575 | + /// side` model walked the 4:2:0 count on every axis, so this counter is | ||
| 4576 | + /// the reach/arm witness for the per-axis walk. | ||
| 4577 | + static INTRABC_128RECT_CHROMA_CHUNK_HITS: std::cell::Cell<usize> = | ||
| 4578 | + const { std::cell::Cell::new(0) }; | ||
| 4579 | + /// lane-av1-ibc128chunk: the mu-chunk walk's per-axis chroma extents, as | ||
| 4580 | + /// `(64 >> ss_x) << 8 | (64 >> ss_y)` on the LAST chunk -- the pair the | ||
| 4581 | + /// per-axis walk used. A 4:2:2 run and a 4:2:0 run of the same block | ||
| 4582 | + /// differ here (32|64 vs 32|32), which is what the de-square-cut fixes. | ||
| 4583 | + static INTRABC_128RECT_CHUNK_SHAPE: std::cell::Cell<usize> = | ||
| 4584 | + const { std::cell::Cell::new(0) }; | ||
| 4182 | } | 4585 | } |
| 4183 | 4586 | ||
| 4184 | /// Current value of [`INTRABC_128RECT_HITS`]. | 4587 | /// Current value of [`INTRABC_128RECT_HITS`]. |
| @@ -4193,6 +4596,26 @@ pub(crate) fn reset_intrabc_128rect_hits() { | |||
| 4193 | INTRABC_128RECT_HITS.with(|c| c.set(0)); | 4596 | INTRABC_128RECT_HITS.with(|c| c.set(0)); |
| 4194 | } | 4597 | } |
| 4195 | 4598 | ||
| 4599 | +/// Current value of [`INTRABC_128RECT_CHROMA_CHUNK_HITS`]. | ||
| 4600 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 4601 | +pub fn intrabc_128rect_chroma_chunk_hits() -> usize { | ||
| 4602 | + INTRABC_128RECT_CHROMA_CHUNK_HITS.with(|c| c.get()) | ||
| 4603 | +} | ||
| 4604 | + | ||
| 4605 | +/// Current value of [`INTRABC_128RECT_CHUNK_SHAPE`]. | ||
| 4606 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 4607 | +pub fn intrabc_128rect_chunk_shape() -> usize { | ||
| 4608 | + INTRABC_128RECT_CHUNK_SHAPE.with(|c| c.get()) | ||
| 4609 | +} | ||
| 4610 | + | ||
| 4611 | +/// Zeroes [`INTRABC_128RECT_CHROMA_CHUNK_HITS`] and | ||
| 4612 | +/// [`INTRABC_128RECT_CHUNK_SHAPE`]. | ||
| 4613 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 4614 | +pub(crate) fn reset_intrabc_128rect_chroma_chunk_hits() { | ||
| 4615 | + INTRABC_128RECT_CHROMA_CHUNK_HITS.with(|c| c.set(0)); | ||
| 4616 | + INTRABC_128RECT_CHUNK_SHAPE.with(|c| c.set(0)); | ||
| 4617 | +} | ||
| 4618 | + | ||
| 4196 | /// Current value of [`INTRABC_VARTX_HITS`]. | 4619 | /// Current value of [`INTRABC_VARTX_HITS`]. |
| 4197 | pub fn intrabc_vartx_hits() -> usize { | 4620 | pub fn intrabc_vartx_hits() -> usize { |
| 4198 | INTRABC_VARTX_HITS.with(|c| c.get()) | 4621 | INTRABC_VARTX_HITS.with(|c| c.get()) |
| @@ -4226,7 +4649,14 @@ pub fn rect_intrabc_vartx_hits() -> usize { | |||
| 4226 | /// its size (libaom's `scan_row_mbmi` advances `processed_rows` off any | 4649 | /// its size (libaom's `scan_row_mbmi` advances `processed_rows` off any |
| 4227 | /// candidate's `bsize`, ref-match or not), an intrabc one also its DV as an | 4650 | /// candidate's `bsize`, ref-match or not), an intrabc one also its DV as an |
| 4228 | /// `INTRA_FRAME` candidate (libaom treats intrabc as `is_inter_block`). | 4651 | /// `INTRA_FRAME` candidate (libaom treats intrabc as `is_inter_block`). |
| 4229 | -fn record_intrabc_mi(mi_r: usize, mi_c: usize, n4: usize, dv: Option<(i32, i32)>, n: &mut Neighbours, fctx: &crate::decode::FrameCtx) { | 4652 | +fn record_intrabc_mi( |
| 4653 | + mi_r: usize, | ||
| 4654 | + mi_c: usize, | ||
| 4655 | + n4: usize, | ||
| 4656 | + dv: Option<(i32, i32)>, | ||
| 4657 | + n: &mut Neighbours, | ||
| 4658 | + fctx: &crate::decode::FrameCtx, | ||
| 4659 | +) { | ||
| 4230 | record_intrabc_mi_rect(mi_r, mi_c, n4, n4, dv, n, fctx); | 4660 | record_intrabc_mi_rect(mi_r, mi_c, n4, n4, dv, n, fctx); |
| 4231 | } | 4661 | } |
| 4232 | 4662 | ||
| @@ -5820,7 +6250,11 @@ pub(crate) fn build_motion_field( | |||
| 5820 | let i = rf.wrapping_sub(LAST_FRAME as usize); | 6250 | let i = rf.wrapping_sub(LAST_FRAME as usize); |
| 5821 | order_hint_bits != 0 | 6251 | order_hint_bits != 0 |
| 5822 | && i < 7 | 6252 | && i < 7 |
| 5823 | - && (crate::motion_field::get_relative_dist(order_hint_bits, ref_order_hints[i], order_hint) > 0 | 6253 | + && (crate::motion_field::get_relative_dist( |
| 6254 | + order_hint_bits, | ||
| 6255 | + ref_order_hints[i], | ||
| 6256 | + order_hint, | ||
| 6257 | + ) > 0 | ||
| 5824 | || ref_order_hints[i] == order_hint) | 6258 | || ref_order_hints[i] == order_hint) |
| 5825 | }); | 6259 | }); |
| 5826 | // libaom `REFMVS_LIMIT` (`mvref_common.h`): a stored motion field mv is | 6260 | // libaom `REFMVS_LIMIT` (`mvref_common.h`): a stored motion field mv is |
| @@ -6496,9 +6930,7 @@ fn br_ctx(grid: &[u8], stride: usize, row: usize, col: usize, class: TxClass) -> | |||
| 6496 | TxClass::Horiz => neighbour(grid, stride, row, col + 2), | 6930 | TxClass::Horiz => neighbour(grid, stride, row, col + 2), |
| 6497 | TxClass::Vert => neighbour(grid, stride, row + 2, col), | 6931 | TxClass::Vert => neighbour(grid, stride, row + 2, col), |
| 6498 | }; | 6932 | }; |
| 6499 | - let mag = neighbour(grid, stride, row + 1, col) | 6933 | + let mag = neighbour(grid, stride, row + 1, col) + neighbour(grid, stride, row, col + 1) + extra; |
| 6500 | - + neighbour(grid, stride, row, col + 1) | ||
| 6501 | - + extra; | ||
| 6502 | let mag = (((mag + 1) >> 1).min(6)) as usize; | 6934 | let mag = (((mag + 1) >> 1).min(6)) as usize; |
| 6503 | if row == 0 && col == 0 { | 6935 | if row == 0 && col == 0 { |
| 6504 | return mag; | 6936 | return mag; |
| @@ -6517,33 +6949,33 @@ fn br_ctx(grid: &[u8], stride: usize, row: usize, col: usize, class: TxClass) -> | |||
| 6517 | /// against the real table). Not the square zigzag formula generalized to | 6949 | /// against the real table). Not the square zigzag formula generalized to |
| 6518 | /// unequal `w`/`h` -- checked and that does NOT reproduce this table. | 6950 | /// unequal `w`/`h` -- checked and that does NOT reproduce this table. |
| 6519 | const SCAN_32X16: [u16; 512] = [ | 6951 | const SCAN_32X16: [u16; 512] = [ |
| 6520 | - 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, | 6952 | + 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, 130, |
| 6521 | - 130, 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 256, 225, 194, 163, 132, 101, 70, 39, | 6953 | + 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 256, 225, 194, 163, 132, 101, 70, 39, 8, |
| 6522 | - 8, 288, 257, 226, 195, 164, 133, 102, 71, 40, 9, 320, 289, 258, 227, 196, 165, 134, 103, 72, | 6954 | + 288, 257, 226, 195, 164, 133, 102, 71, 40, 9, 320, 289, 258, 227, 196, 165, 134, 103, 72, 41, |
| 6523 | - 41, 10, 352, 321, 290, 259, 228, 197, 166, 135, 104, 73, 42, 11, 384, 353, 322, 291, 260, 229, | 6955 | + 10, 352, 321, 290, 259, 228, 197, 166, 135, 104, 73, 42, 11, 384, 353, 322, 291, 260, 229, 198, |
| 6524 | - 198, 167, 136, 105, 74, 43, 12, 416, 385, 354, 323, 292, 261, 230, 199, 168, 137, 106, 75, 44, | 6956 | + 167, 136, 105, 74, 43, 12, 416, 385, 354, 323, 292, 261, 230, 199, 168, 137, 106, 75, 44, 13, |
| 6525 | - 13, 448, 417, 386, 355, 324, 293, 262, 231, 200, 169, 138, 107, 76, 45, 14, 480, 449, 418, | 6957 | + 448, 417, 386, 355, 324, 293, 262, 231, 200, 169, 138, 107, 76, 45, 14, 480, 449, 418, 387, |
| 6526 | - 387, 356, 325, 294, 263, 232, 201, 170, 139, 108, 77, 46, 15, 481, 450, 419, 388, 357, 326, | 6958 | + 356, 325, 294, 263, 232, 201, 170, 139, 108, 77, 46, 15, 481, 450, 419, 388, 357, 326, 295, |
| 6527 | - 295, 264, 233, 202, 171, 140, 109, 78, 47, 16, 482, 451, 420, 389, 358, 327, 296, 265, 234, | 6959 | + 264, 233, 202, 171, 140, 109, 78, 47, 16, 482, 451, 420, 389, 358, 327, 296, 265, 234, 203, |
| 6528 | - 203, 172, 141, 110, 79, 48, 17, 483, 452, 421, 390, 359, 328, 297, 266, 235, 204, 173, 142, | 6960 | + 172, 141, 110, 79, 48, 17, 483, 452, 421, 390, 359, 328, 297, 266, 235, 204, 173, 142, 111, 80, |
| 6529 | - 111, 80, 49, 18, 484, 453, 422, 391, 360, 329, 298, 267, 236, 205, 174, 143, 112, 81, 50, 19, | 6961 | + 49, 18, 484, 453, 422, 391, 360, 329, 298, 267, 236, 205, 174, 143, 112, 81, 50, 19, 485, 454, |
| 6530 | - 485, 454, 423, 392, 361, 330, 299, 268, 237, 206, 175, 144, 113, 82, 51, 20, 486, 455, 424, | 6962 | + 423, 392, 361, 330, 299, 268, 237, 206, 175, 144, 113, 82, 51, 20, 486, 455, 424, 393, 362, |
| 6531 | - 393, 362, 331, 300, 269, 238, 207, 176, 145, 114, 83, 52, 21, 487, 456, 425, 394, 363, 332, | 6963 | + 331, 300, 269, 238, 207, 176, 145, 114, 83, 52, 21, 487, 456, 425, 394, 363, 332, 301, 270, |
| 6532 | - 301, 270, 239, 208, 177, 146, 115, 84, 53, 22, 488, 457, 426, 395, 364, 333, 302, 271, 240, | 6964 | + 239, 208, 177, 146, 115, 84, 53, 22, 488, 457, 426, 395, 364, 333, 302, 271, 240, 209, 178, |
| 6533 | - 209, 178, 147, 116, 85, 54, 23, 489, 458, 427, 396, 365, 334, 303, 272, 241, 210, 179, 148, | 6965 | + 147, 116, 85, 54, 23, 489, 458, 427, 396, 365, 334, 303, 272, 241, 210, 179, 148, 117, 86, 55, |
| 6534 | - 117, 86, 55, 24, 490, 459, 428, 397, 366, 335, 304, 273, 242, 211, 180, 149, 118, 87, 56, 25, | 6966 | + 24, 490, 459, 428, 397, 366, 335, 304, 273, 242, 211, 180, 149, 118, 87, 56, 25, 491, 460, 429, |
| 6535 | - 491, 460, 429, 398, 367, 336, 305, 274, 243, 212, 181, 150, 119, 88, 57, 26, 492, 461, 430, | 6967 | + 398, 367, 336, 305, 274, 243, 212, 181, 150, 119, 88, 57, 26, 492, 461, 430, 399, 368, 337, |
| 6536 | - 399, 368, 337, 306, 275, 244, 213, 182, 151, 120, 89, 58, 27, 493, 462, 431, 400, 369, 338, | 6968 | + 306, 275, 244, 213, 182, 151, 120, 89, 58, 27, 493, 462, 431, 400, 369, 338, 307, 276, 245, |
| 6537 | - 307, 276, 245, 214, 183, 152, 121, 90, 59, 28, 494, 463, 432, 401, 370, 339, 308, 277, 246, | 6969 | + 214, 183, 152, 121, 90, 59, 28, 494, 463, 432, 401, 370, 339, 308, 277, 246, 215, 184, 153, |
| 6538 | - 215, 184, 153, 122, 91, 60, 29, 495, 464, 433, 402, 371, 340, 309, 278, 247, 216, 185, 154, | 6970 | + 122, 91, 60, 29, 495, 464, 433, 402, 371, 340, 309, 278, 247, 216, 185, 154, 123, 92, 61, 30, |
| 6539 | - 123, 92, 61, 30, 496, 465, 434, 403, 372, 341, 310, 279, 248, 217, 186, 155, 124, 93, 62, 31, | 6971 | + 496, 465, 434, 403, 372, 341, 310, 279, 248, 217, 186, 155, 124, 93, 62, 31, 497, 466, 435, |
| 6540 | - 497, 466, 435, 404, 373, 342, 311, 280, 249, 218, 187, 156, 125, 94, 63, 498, 467, 436, 405, | 6972 | + 404, 373, 342, 311, 280, 249, 218, 187, 156, 125, 94, 63, 498, 467, 436, 405, 374, 343, 312, |
| 6541 | - 374, 343, 312, 281, 250, 219, 188, 157, 126, 95, 499, 468, 437, 406, 375, 344, 313, 282, 251, | 6973 | + 281, 250, 219, 188, 157, 126, 95, 499, 468, 437, 406, 375, 344, 313, 282, 251, 220, 189, 158, |
| 6542 | - 220, 189, 158, 127, 500, 469, 438, 407, 376, 345, 314, 283, 252, 221, 190, 159, 501, 470, 439, | 6974 | + 127, 500, 469, 438, 407, 376, 345, 314, 283, 252, 221, 190, 159, 501, 470, 439, 408, 377, 346, |
| 6543 | - 408, 377, 346, 315, 284, 253, 222, 191, 502, 471, 440, 409, 378, 347, 316, 285, 254, 223, 503, | 6975 | + 315, 284, 253, 222, 191, 502, 471, 440, 409, 378, 347, 316, 285, 254, 223, 503, 472, 441, 410, |
| 6544 | - 472, 441, 410, 379, 348, 317, 286, 255, 504, 473, 442, 411, 380, 349, 318, 287, 505, 474, 443, | 6976 | + 379, 348, 317, 286, 255, 504, 473, 442, 411, 380, 349, 318, 287, 505, 474, 443, 412, 381, 350, |
| 6545 | - 412, 381, 350, 319, 506, 475, 444, 413, 382, 351, 507, 476, 445, 414, 383, 508, 477, 446, 415, | 6977 | + 319, 506, 475, 444, 413, 382, 351, 507, 476, 445, 414, 383, 508, 477, 446, 415, 509, 478, 447, |
| 6546 | - 509, 478, 447, 510, 479, 511, | 6978 | + 510, 479, 511, |
| 6547 | ]; | 6979 | ]; |
| 6548 | 6980 | ||
| 6549 | /// `Default_Scan_16x32`, this decoder's own row-major transcription (see | 6981 | /// `Default_Scan_16x32`, this decoder's own row-major transcription (see |
| @@ -6623,18 +7055,18 @@ const SCAN_8X16: [u16; 128] = [ | |||
| 6623 | /// are byte-identical to this decoder's [`SCAN_8X16`]. | 7055 | /// are byte-identical to this decoder's [`SCAN_8X16`]. |
| 6624 | const SCAN_32X8: [u16; 256] = [ | 7056 | const SCAN_32X8: [u16; 256] = [ |
| 6625 | 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, 130, | 7057 | 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, 130, |
| 6626 | - 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 225, 194, 163, 132, 101, 70, 39, 8, 226, 195, | 7058 | + 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 225, 194, 163, 132, 101, 70, 39, 8, 226, |
| 6627 | - 164, 133, 102, 71, 40, 9, 227, 196, 165, 134, 103, 72, 41, 10, 228, 197, 166, 135, 104, 73, 42, | 7059 | + 195, 164, 133, 102, 71, 40, 9, 227, 196, 165, 134, 103, 72, 41, 10, 228, 197, 166, 135, 104, |
| 6628 | - 11, 229, 198, 167, 136, 105, 74, 43, 12, 230, 199, 168, 137, 106, 75, 44, 13, 231, 200, 169, | 7060 | + 73, 42, 11, 229, 198, 167, 136, 105, 74, 43, 12, 230, 199, 168, 137, 106, 75, 44, 13, 231, 200, |
| 6629 | - 138, 107, 76, 45, 14, 232, 201, 170, 139, 108, 77, 46, 15, 233, 202, 171, 140, 109, 78, 47, 16, | 7061 | + 169, 138, 107, 76, 45, 14, 232, 201, 170, 139, 108, 77, 46, 15, 233, 202, 171, 140, 109, 78, |
| 6630 | - 234, 203, 172, 141, 110, 79, 48, 17, 235, 204, 173, 142, 111, 80, 49, 18, 236, 205, 174, 143, | 7062 | + 47, 16, 234, 203, 172, 141, 110, 79, 48, 17, 235, 204, 173, 142, 111, 80, 49, 18, 236, 205, |
| 6631 | - 112, 81, 50, 19, 237, 206, 175, 144, 113, 82, 51, 20, 238, 207, 176, 145, 114, 83, 52, 21, 239, | 7063 | + 174, 143, 112, 81, 50, 19, 237, 206, 175, 144, 113, 82, 51, 20, 238, 207, 176, 145, 114, 83, |
| 6632 | - 208, 177, 146, 115, 84, 53, 22, 240, 209, 178, 147, 116, 85, 54, 23, 241, 210, 179, 148, 117, | 7064 | + 52, 21, 239, 208, 177, 146, 115, 84, 53, 22, 240, 209, 178, 147, 116, 85, 54, 23, 241, 210, |
| 6633 | - 86, 55, 24, 242, 211, 180, 149, 118, 87, 56, 25, 243, 212, 181, 150, 119, 88, 57, 26, 244, 213, | 7065 | + 179, 148, 117, 86, 55, 24, 242, 211, 180, 149, 118, 87, 56, 25, 243, 212, 181, 150, 119, 88, |
| 6634 | - 182, 151, 120, 89, 58, 27, 245, 214, 183, 152, 121, 90, 59, 28, 246, 215, 184, 153, 122, 91, | 7066 | + 57, 26, 244, 213, 182, 151, 120, 89, 58, 27, 245, 214, 183, 152, 121, 90, 59, 28, 246, 215, |
| 6635 | - 60, 29, 247, 216, 185, 154, 123, 92, 61, 30, 248, 217, 186, 155, 124, 93, 62, 31, 249, 218, 187, | 7067 | + 184, 153, 122, 91, 60, 29, 247, 216, 185, 154, 123, 92, 61, 30, 248, 217, 186, 155, 124, 93, |
| 6636 | - 156, 125, 94, 63, 250, 219, 188, 157, 126, 95, 251, 220, 189, 158, 127, 252, 221, 190, 159, 253, | 7068 | + 62, 31, 249, 218, 187, 156, 125, 94, 63, 250, 219, 188, 157, 126, 95, 251, 220, 189, 158, 127, |
| 6637 | - 222, 191, 254, 223, 255, | 7069 | + 252, 221, 190, 159, 253, 222, 191, 254, 223, 255, |
| 6638 | ]; | 7070 | ]; |
| 6639 | /// `Default_Scan_8x32`, [`SCAN_32X8`]'s transpose (the chroma plane of a | 7071 | /// `Default_Scan_8x32`, [`SCAN_32X8`]'s transpose (the chroma plane of a |
| 6640 | /// 16x64 `PARTITION_VERT_4` strip). | 7072 | /// 16x64 `PARTITION_VERT_4` strip). |
| @@ -6737,13 +7169,7 @@ fn base_ctx_rect( | |||
| 6737 | /// its body was character-for-character [`br_ctx`]'s, which | 7169 | /// its body was character-for-character [`br_ctx`]'s, which |
| 6738 | /// `flat_taps_match_the_row_col_neighbour_reads` now asserts. | 7170 | /// `flat_taps_match_the_row_col_neighbour_reads` now asserts. |
| 6739 | #[cfg(test)] | 7171 | #[cfg(test)] |
| 6740 | -fn br_ctx_rect( | 7172 | +fn br_ctx_rect(grid: &[u8], stride: usize, row: usize, col: usize, class: TxClass) -> usize { |
| 6741 | - grid: &[u8], | ||
| 6742 | - stride: usize, | ||
| 6743 | - row: usize, | ||
| 6744 | - col: usize, | ||
| 6745 | - class: TxClass, | ||
| 6746 | -) -> usize { | ||
| 6747 | let extra = match class { | 7173 | let extra = match class { |
| 6748 | TxClass::TwoD => neighbour_rect(grid, stride, row + 1, col + 1), | 7174 | TxClass::TwoD => neighbour_rect(grid, stride, row + 1, col + 1), |
| 6749 | TxClass::Horiz => neighbour_rect(grid, stride, row, col + 2), | 7175 | TxClass::Horiz => neighbour_rect(grid, stride, row, col + 2), |
| @@ -6933,7 +7359,9 @@ fn is_smooth_mode(mode: usize) -> bool { | |||
| 6933 | #[cold] | 7359 | #[cold] |
| 6934 | #[inline(never)] | 7360 | #[inline(never)] |
| 6935 | fn trace_base_eob(scan_idx: usize, pos: usize, row: usize, col: usize, ctx: usize, v: i32) { | 7361 | fn trace_base_eob(scan_idx: usize, pos: usize, row: usize, col: usize, ctx: usize, v: i32) { |
| 6936 | - eprintln!("TRACE base_eob scan_idx={scan_idx} pos={pos} row={row} col={col} ctx={ctx} value={v}"); | 7362 | + eprintln!( |
| 7363 | + "TRACE base_eob scan_idx={scan_idx} pos={pos} row={row} col={col} ctx={ctx} value={v}" | ||
| 7364 | + ); | ||
| 6937 | } | 7365 | } |
| 6938 | 7366 | ||
| 6939 | #[cold] | 7367 | #[cold] |
| @@ -6966,7 +7394,10 @@ fn coeff_step_br(dec: &SymbolDecoder, scan_idx: usize, apos: usize, ctx: usize, | |||
| 6966 | #[inline(never)] | 7394 | #[inline(never)] |
| 6967 | fn coeff_step_sign(dec: &SymbolDecoder, c: usize, negative: bool) { | 7395 | fn coeff_step_sign(dec: &SymbolDecoder, c: usize, negative: bool) { |
| 6968 | let (rng, _) = dec.debug_state(); | 7396 | let (rng, _) = dec.debug_state(); |
| 6969 | - eprintln!("EC_COEFF_STEP tag=sign c={c} sign={} rng={rng}", negative as i32); | 7397 | + eprintln!( |
| 7398 | + "EC_COEFF_STEP tag=sign c={c} sign={} rng={rng}", | ||
| 7399 | + negative as i32 | ||
| 7400 | + ); | ||
| 6970 | } | 7401 | } |
| 6971 | 7402 | ||
| 6972 | #[cold] | 7403 | #[cold] |
| @@ -7026,14 +7457,15 @@ fn read_coeffs( | |||
| 7026 | let (rng, _) = dec.debug_state(); | 7457 | let (rng, _) = dec.debug_state(); |
| 7027 | eprintln!( | 7458 | eprintln!( |
| 7028 | "EC_COEFF_STEP tag=all_zero side={} ctx={skip_ctx} dcctx={sign_ctx} cdf={dbg_txbskip:?} all_zero={} rng={rng}", | 7459 | "EC_COEFF_STEP tag=all_zero side={} ctx={skip_ctx} dcctx={sign_ctx} cdf={dbg_txbskip:?} all_zero={} rng={rng}", |
| 7029 | - coding.side, | 7460 | + coding.side, all_zero as i32 |
| 7030 | - all_zero as i32 | ||
| 7031 | ); | 7461 | ); |
| 7032 | } | 7462 | } |
| 7033 | if crate::envflags::env_flag!("EC_AV1_TELL") { | 7463 | if crate::envflags::env_flag!("EC_AV1_TELL") { |
| 7034 | eprintln!( | 7464 | eprintln!( |
| 7035 | "TELL label=post_txb_skip ctx={skip_ctx} all_zero={} tell={} range={}", | 7465 | "TELL label=post_txb_skip ctx={skip_ctx} all_zero={} tell={} range={}", |
| 7036 | - all_zero as u8, dec.debug_bitpos(), dec.debug_state().0 | 7466 | + all_zero as u8, |
| 7467 | + dec.debug_bitpos(), | ||
| 7468 | + dec.debug_state().0 | ||
| 7037 | ); | 7469 | ); |
| 7038 | } | 7470 | } |
| 7039 | if trace { | 7471 | if trace { |
| @@ -7076,8 +7508,9 @@ fn read_coeffs( | |||
| 7076 | if trace { | 7508 | if trace { |
| 7077 | eprintln!("TRACE tx_type value={t} len={len}"); | 7509 | eprintln!("TRACE tx_type value={t} len={len}"); |
| 7078 | } | 7510 | } |
| 7079 | - tx_type = tx_type_from_symbol(len, t) | 7511 | + tx_type = tx_type_from_symbol(len, t).ok_or_else(|| { |
| 7080 | - .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; | 7512 | + unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")) |
| 7513 | + })?; | ||
| 7081 | } | 7514 | } |
| 7082 | 7515 | ||
| 7083 | let class = TxClass::of(tx_type); | 7516 | let class = TxClass::of(tx_type); |
| @@ -7092,7 +7525,11 @@ fn read_coeffs( | |||
| 7092 | let ec_trace_coeff = coeff_trace_on(); | 7525 | let ec_trace_coeff = coeff_trace_on(); |
| 7093 | if ec_trace_coeff { | 7526 | if ec_trace_coeff { |
| 7094 | let (rng, _) = dec.debug_state(); | 7527 | let (rng, _) = dec.debug_state(); |
| 7095 | - let cls = match class { TxClass::TwoD => "2d", TxClass::Horiz => "horiz", TxClass::Vert => "vert" }; | 7528 | + let cls = match class { |
| 7529 | + TxClass::TwoD => "2d", | ||
| 7530 | + TxClass::Horiz => "horiz", | ||
| 7531 | + TxClass::Vert => "vert", | ||
| 7532 | + }; | ||
| 7096 | eprintln!("EC_COEFF_STEP tag=eob eob={eob} tx={tx_type:?} class={cls} rng={rng}"); | 7533 | eprintln!("EC_COEFF_STEP tag=eob eob={eob} tx={tx_type:?} class={cls} rng={rng}"); |
| 7097 | } | 7534 | } |
| 7098 | let class_scan; | 7535 | let class_scan; |
| @@ -7297,10 +7734,14 @@ fn read_coeffs_rect( | |||
| 7297 | let len = tx_type_cdf.len(); | 7734 | let len = tx_type_cdf.len(); |
| 7298 | let t = dec.symbol(tx_type_cdf); | 7735 | let t = dec.symbol(tx_type_cdf); |
| 7299 | crate::census::tx_type(len, t); | 7736 | crate::census::tx_type(len, t); |
| 7300 | - tx_type = tx_type_from_symbol(len, t) | 7737 | + tx_type = tx_type_from_symbol(len, t).ok_or_else(|| { |
| 7301 | - .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; | 7738 | + unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")) |
| 7739 | + })?; | ||
| 7302 | if rect_trace { | 7740 | if rect_trace { |
| 7303 | - eprintln!("EC_COEFF_STEP tag=tx_type plane=0 rng={}", dec.debug_state().0); | 7741 | + eprintln!( |
| 7742 | + "EC_COEFF_STEP tag=tx_type plane=0 rng={}", | ||
| 7743 | + dec.debug_state().0 | ||
| 7744 | + ); | ||
| 7304 | } | 7745 | } |
| 7305 | } | 7746 | } |
| 7306 | let class = TxClass::of(tx_type); | 7747 | let class = TxClass::of(tx_type); |
| @@ -7309,7 +7750,10 @@ fn read_coeffs_rect( | |||
| 7309 | } | 7750 | } |
| 7310 | let eob = read_eob(dec, coding, class); | 7751 | let eob = read_eob(dec, coding, class); |
| 7311 | if rect_trace { | 7752 | if rect_trace { |
| 7312 | - eprintln!("EC_COEFF_STEP tag=eob eob={eob} rng={}", dec.debug_state().0); | 7753 | + eprintln!( |
| 7754 | + "EC_COEFF_STEP tag=eob eob={eob} rng={}", | ||
| 7755 | + dec.debug_state().0 | ||
| 7756 | + ); | ||
| 7313 | } | 7757 | } |
| 7314 | let class_scan; | 7758 | let class_scan; |
| 7315 | let scan: &[u16] = if class == TxClass::TwoD { | 7759 | let scan: &[u16] = if class == TxClass::TwoD { |
| @@ -7449,7 +7893,10 @@ fn read_coeffs_rect( | |||
| 7449 | }; | 7893 | }; |
| 7450 | if rect_trace { | 7894 | if rect_trace { |
| 7451 | let (rng, _) = dec.debug_state(); | 7895 | let (rng, _) = dec.debug_state(); |
| 7452 | - eprintln!("EC_COEFF_STEP tag=sign_rect pos={pos} sign={} dcctx={sign_ctx} rng={rng}", u8::from(negative)); | 7896 | + eprintln!( |
| 7897 | + "EC_COEFF_STEP tag=sign_rect pos={pos} sign={} dcctx={sign_ctx} rng={rng}", | ||
| 7898 | + u8::from(negative) | ||
| 7899 | + ); | ||
| 7453 | } | 7900 | } |
| 7454 | let level = if level > MAX_BR_LEVEL { | 7901 | let level = if level > MAX_BR_LEVEL { |
| 7455 | let g = read_golomb(dec)?; | 7902 | let g = read_golomb(dec)?; |
| @@ -7470,7 +7917,10 @@ fn read_coeffs_rect( | |||
| 7470 | .filter(|&(_, &v)| v != 0) | 7917 | .filter(|&(_, &v)| v != 0) |
| 7471 | .map(|(i, &v)| format!("{}/{}:{v}", i / w, i % w)) | 7918 | .map(|(i, &v)| format!("{}/{}:{v}", i / w, i % w)) |
| 7472 | .collect(); | 7919 | .collect(); |
| 7473 | - eprintln!("OUR_LEVELS w={w} h={h} eob={eob} tx={tx_type:?} nz={}", nz.join(",")); | 7920 | + eprintln!( |
| 7921 | + "OUR_LEVELS w={w} h={h} eob={eob} tx={tx_type:?} nz={}", | ||
| 7922 | + nz.join(",") | ||
| 7923 | + ); | ||
| 7474 | } | 7924 | } |
| 7475 | Ok((Grid::Own(grid), tx_type)) | 7925 | Ok((Grid::Own(grid), tx_type)) |
| 7476 | } | 7926 | } |
| @@ -7813,7 +8263,13 @@ struct Neighbours { | |||
| 7813 | impl Neighbours { | 8263 | impl Neighbours { |
| 7814 | /// `cols`/`rows` are in [`SUB`] units; `mi_cols`/`mi_rows` are the frame's | 8264 | /// `cols`/`rows` are in [`SUB`] units; `mi_cols`/`mi_rows` are the frame's |
| 7815 | /// true (unpadded) size in 4x4 mode-info units. | 8265 | /// true (unpadded) size in 4x4 mode-info units. |
| 7816 | - fn new(cols: usize, rows: usize, mi_cols: usize, mi_rows: usize, fctx: &crate::decode::FrameCtx) -> Self { | 8266 | + fn new( |
| 8267 | + cols: usize, | ||
| 8268 | + rows: usize, | ||
| 8269 | + mi_cols: usize, | ||
| 8270 | + mi_rows: usize, | ||
| 8271 | + fctx: &crate::decode::FrameCtx, | ||
| 8272 | + ) -> Self { | ||
| 7817 | // lane-sb128c r7: a 128x64 block at the bottom frame edge records its | 8273 | // lane-sb128c r7: a 128x64 block at the bottom frame edge records its |
| 7818 | // neighbour state over the whole 64-row extent, past the frame's last | 8274 | // neighbour state over the whole 64-row extent, past the frame's last |
| 7819 | // mi row (mi_rows 198, block rows 192..208). libaom's own context | 8275 | // mi row (mi_rows 198, block rows 192..208). libaom's own context |
| @@ -7822,10 +8278,7 @@ impl Neighbours { | |||
| 7822 | // side arrays to a superblock multiple and leave those cells unread -- | 8278 | // side arrays to a superblock multiple and leave those cells unread -- |
| 7823 | // every availability check uses the true `mi_rows`/`mi_cols` below. | 8279 | // every availability check uses the true `mi_rows`/`mi_cols` below. |
| 7824 | let sb_sub = (sb_mi_cur(fctx) as usize) / (SUB / MI); | 8280 | let sb_sub = (sb_mi_cur(fctx) as usize) / (SUB / MI); |
| 7825 | - let (cols, rows) = ( | 8281 | + let (cols, rows) = (cols.next_multiple_of(sb_sub), rows.next_multiple_of(sb_sub)); |
| 7826 | - cols.next_multiple_of(sb_sub), | ||
| 7827 | - rows.next_multiple_of(sb_sub), | ||
| 7828 | - ); | ||
| 7829 | Self { | 8282 | Self { |
| 7830 | above: vec![[Neighbour::default(); 3]; cols * (SUB / MI)], | 8283 | above: vec![[Neighbour::default(); 3]; cols * (SUB / MI)], |
| 7831 | left: vec![[Neighbour::default(); 3]; rows * (SUB / MI)], | 8284 | left: vec![[Neighbour::default(); 3]; rows * (SUB / MI)], |
| @@ -7868,7 +8321,12 @@ impl Neighbours { | |||
| 7868 | mi_cols, | 8321 | mi_cols, |
| 7869 | mi_rows, | 8322 | mi_rows, |
| 7870 | blk_grid: vec![ | 8323 | blk_grid: vec![ |
| 7871 | - BlkCell { skip: false, written: false, org: [0; 2], dim: [1; 2] }; | 8324 | + BlkCell { |
| 8325 | + skip: false, | ||
| 8326 | + written: false, | ||
| 8327 | + org: [0; 2], | ||
| 8328 | + dim: [1; 2] | ||
| 8329 | + }; | ||
| 7872 | cols * (SUB / MI) * rows * (SUB / MI) | 8330 | cols * (SUB / MI) * rows * (SUB / MI) |
| 7873 | ], | 8331 | ], |
| 7874 | skip_grid_cols_mi: cols * (SUB / MI), | 8332 | skip_grid_cols_mi: cols * (SUB / MI), |
| @@ -7897,7 +8355,13 @@ impl Neighbours { | |||
| 7897 | /// availability check below. Left context resets every superblock row | 8355 | /// availability check below. Left context resets every superblock row |
| 7898 | /// regardless of tile ([`Self::start_row`], already called once per SB | 8356 | /// regardless of tile ([`Self::start_row`], already called once per SB |
| 7899 | /// row by every caller) so it needs no tile-specific reset here. | 8357 | /// row by every caller) so it needs no tile-specific reset here. |
| 7900 | - fn start_tile(&mut self, row0_mi: usize, col0_mi: usize, col1_mi: usize, fctx: &crate::decode::FrameCtx) { | 8358 | + fn start_tile( |
| 8359 | + &mut self, | ||
| 8360 | + row0_mi: usize, | ||
| 8361 | + col0_mi: usize, | ||
| 8362 | + col1_mi: usize, | ||
| 8363 | + fctx: &crate::decode::FrameCtx, | ||
| 8364 | + ) { | ||
| 7901 | // lane-seg: `AvailU`/`AvailL` for the segment-id neighbour prediction | 8365 | // lane-seg: `AvailU`/`AvailL` for the segment-id neighbour prediction |
| 7902 | // are tile-relative, same as every other neighbour lookup here. | 8366 | // are tile-relative, same as every other neighbour lookup here. |
| 7903 | fctx.seg_tile_origin.with(|c| c.set((row0_mi, col0_mi))); | 8367 | fctx.seg_tile_origin.with(|c| c.set((row0_mi, col0_mi))); |
| @@ -7953,7 +8417,13 @@ impl Neighbours { | |||
| 7953 | /// mirrors [`Self::record_rect`]'s loop shape, square-only (this lane's | 8417 | /// mirrors [`Self::record_rect`]'s loop shape, square-only (this lane's |
| 7954 | /// call sites are all square blocks). | 8418 | /// call sites are all square blocks). |
| 7955 | fn record_palette_y(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { | 8419 | fn record_palette_y(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { |
| 7956 | - self.record_palette_y_rect((at.0 * (SUB / MI), at.1 * (SUB / MI)), side, side, size, colors); | 8420 | + self.record_palette_y_rect( |
| 8421 | + (at.0 * (SUB / MI), at.1 * (SUB / MI)), | ||
| 8422 | + side, | ||
| 8423 | + side, | ||
| 8424 | + size, | ||
| 8425 | + colors, | ||
| 8426 | + ); | ||
| 7957 | } | 8427 | } |
| 7958 | 8428 | ||
| 7959 | /// [`Self::record_palette_y`] with independent above (`w`)/left (`h`) | 8429 | /// [`Self::record_palette_y`] with independent above (`w`)/left (`h`) |
| @@ -8029,7 +8499,10 @@ impl Neighbours { | |||
| 8029 | // `xd->above_mbmi` exists for every row but the tile's own first. | 8499 | // `xd->above_mbmi` exists for every row but the tile's own first. |
| 8030 | let above_is_palette = r > self.tile_row0_mi && self.above_palette_size[c] > 0; | 8500 | let above_is_palette = r > self.tile_row0_mi && self.above_palette_size[c] > 0; |
| 8031 | let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 { | 8501 | let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 { |
| 8032 | - (usize::from(self.above_palette_size[c]), self.above_palette_colors[c]) | 8502 | + ( |
| 8503 | + usize::from(self.above_palette_size[c]), | ||
| 8504 | + self.above_palette_colors[c], | ||
| 8505 | + ) | ||
| 8033 | } else { | 8506 | } else { |
| 8034 | (0, [0u16; 8]) | 8507 | (0, [0u16; 8]) |
| 8035 | }; | 8508 | }; |
| @@ -8040,7 +8513,10 @@ impl Neighbours { | |||
| 8040 | // and its `palette_y_mode` ctx. | 8513 | // and its `palette_y_mode` ctx. |
| 8041 | let left_ok = c > self.tile_col0_mi; | 8514 | let left_ok = c > self.tile_col0_mi; |
| 8042 | let (left_n, left_colors) = if left_ok && self.left_palette_size[r] > 0 { | 8515 | let (left_n, left_colors) = if left_ok && self.left_palette_size[r] > 0 { |
| 8043 | - (usize::from(self.left_palette_size[r]), self.left_palette_colors[r]) | 8516 | + ( |
| 8517 | + usize::from(self.left_palette_size[r]), | ||
| 8518 | + self.left_palette_colors[r], | ||
| 8519 | + ) | ||
| 8044 | } else { | 8520 | } else { |
| 8045 | (0, [0u16; 8]) | 8521 | (0, [0u16; 8]) |
| 8046 | }; | 8522 | }; |
| @@ -8079,7 +8555,13 @@ impl Neighbours { | |||
| 8079 | /// As [`Self::record_palette_y`], for a just-decoded block's own chroma | 8555 | /// As [`Self::record_palette_y`], for a just-decoded block's own chroma |
| 8080 | /// (U-channel) palette size/colours -- `size == 0` clears stale state the | 8556 | /// (U-channel) palette size/colours -- `size == 0` clears stale state the |
| 8081 | /// same way (lane-palette2 r1). | 8557 | /// same way (lane-palette2 r1). |
| 8082 | - fn record_palette_uv(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { | 8558 | + fn record_palette_uv( |
| 8559 | + &mut self, | ||
| 8560 | + at: (usize, usize), | ||
| 8561 | + side: usize, | ||
| 8562 | + size: usize, | ||
| 8563 | + colors: [u16; 8], | ||
| 8564 | + ) { | ||
| 8083 | self.record_palette_uv_rect( | 8565 | self.record_palette_uv_rect( |
| 8084 | (at.0 * (SUB / MI), at.1 * (SUB / MI)), | 8566 | (at.0 * (SUB / MI), at.1 * (SUB / MI)), |
| 8085 | side, | 8567 | side, |
| @@ -8136,14 +8618,20 @@ impl Neighbours { | |||
| 8136 | let (r, c) = mi; | 8618 | let (r, c) = mi; |
| 8137 | let above_ok = r % 16 != 0; | 8619 | let above_ok = r % 16 != 0; |
| 8138 | let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 { | 8620 | let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 { |
| 8139 | - (usize::from(self.above_palette_uv_size[c]), self.above_palette_uv_colors[c]) | 8621 | + ( |
| 8622 | + usize::from(self.above_palette_uv_size[c]), | ||
| 8623 | + self.above_palette_uv_colors[c], | ||
| 8624 | + ) | ||
| 8140 | } else { | 8625 | } else { |
| 8141 | (0, [0u16; 8]) | 8626 | (0, [0u16; 8]) |
| 8142 | }; | 8627 | }; |
| 8143 | // Same tile-relative left availability as the luma cache above. | 8628 | // Same tile-relative left availability as the luma cache above. |
| 8144 | let left_ok = c > self.tile_col0_mi; | 8629 | let left_ok = c > self.tile_col0_mi; |
| 8145 | let (left_n, left_colors) = if left_ok && self.left_palette_uv_size[r] > 0 { | 8630 | let (left_n, left_colors) = if left_ok && self.left_palette_uv_size[r] > 0 { |
| 8146 | - (usize::from(self.left_palette_uv_size[r]), self.left_palette_uv_colors[r]) | 8631 | + ( |
| 8632 | + usize::from(self.left_palette_uv_size[r]), | ||
| 8633 | + self.left_palette_uv_colors[r], | ||
| 8634 | + ) | ||
| 8147 | } else { | 8635 | } else { |
| 8148 | (0, [0u16; 8]) | 8636 | (0, [0u16; 8]) |
| 8149 | }; | 8637 | }; |
| @@ -8182,7 +8670,14 @@ impl Neighbours { | |||
| 8182 | /// transform width (in pixels) and `is_inter` flag -- the loop filter's | 8670 | /// transform width (in pixels) and `is_inter` flag -- the loop filter's |
| 8183 | /// per-edge lookup (`apply_deblock`), filled at the same call sites and | 8671 | /// per-edge lookup (`apply_deblock`), filled at the same call sites and |
| 8184 | /// units as [`Self::fill_skip_grid`]. | 8672 | /// units as [`Self::fill_skip_grid`]. |
| 8185 | - fn fill_lf_grid(&mut self, at_mi: (usize, usize), side_mi: usize, tx_px: u8, ref_frame: i8, fctx: &crate::decode::FrameCtx) { | 8673 | + fn fill_lf_grid( |
| 8674 | + &mut self, | ||
| 8675 | + at_mi: (usize, usize), | ||
| 8676 | + side_mi: usize, | ||
| 8677 | + tx_px: u8, | ||
| 8678 | + ref_frame: i8, | ||
| 8679 | + fctx: &crate::decode::FrameCtx, | ||
| 8680 | + ) { | ||
| 8186 | self.fill_lf_grid_rect(at_mi, side_mi, side_mi, tx_px, tx_px, ref_frame, fctx); | 8681 | self.fill_lf_grid_rect(at_mi, side_mi, side_mi, tx_px, tx_px, ref_frame, fctx); |
| 8187 | } | 8682 | } |
| 8188 | 8683 | ||
| @@ -8218,7 +8713,8 @@ impl Neighbours { | |||
| 8218 | h_mi: usize, | 8713 | h_mi: usize, |
| 8219 | tx_px: u8, | 8714 | tx_px: u8, |
| 8220 | tx_h_px: u8, | 8715 | tx_h_px: u8, |
| 8221 | - ref_frame: i8, fctx: &crate::decode::FrameCtx, | 8716 | + ref_frame: i8, |
| 8717 | + fctx: &crate::decode::FrameCtx, | ||
| 8222 | ) { | 8718 | ) { |
| 8223 | let (mi_r, mi_c) = at_mi; | 8719 | let (mi_r, mi_c) = at_mi; |
| 8224 | // `av1_get_max_uv_txsize` under 4:2:0: the block's chroma extent is | 8720 | // `av1_get_max_uv_txsize` under 4:2:0: the block's chroma extent is |
| @@ -8227,7 +8723,9 @@ impl Neighbours { | |||
| 8227 | let uv_tx_w = (((w_mi * MI) >> ss_x(fctx)).max(4).min(32)) as u8; | 8723 | let uv_tx_w = (((w_mi * MI) >> ss_x(fctx)).max(4).min(32)) as u8; |
| 8228 | let uv_tx_h = (((h_mi * MI) >> ss_y(fctx)).max(4).min(32)) as u8; | 8724 | let uv_tx_h = (((h_mi * MI) >> ss_y(fctx)).max(4).min(32)) as u8; |
| 8229 | if crate::envflags::env_flag!("EC_TXGRID_TRACE") { | 8725 | if crate::envflags::env_flag!("EC_TXGRID_TRACE") { |
| 8230 | - 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}"); | 8726 | + eprintln!( |
| 8727 | + "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}" | ||
| 8728 | + ); | ||
| 8231 | } | 8729 | } |
| 8232 | crate::census::tx(tx_px, tx_h_px); | 8730 | crate::census::tx(tx_px, tx_h_px); |
| 8233 | let cur = fctx.current_delta_lf.with(|c| c.get()); | 8731 | let cur = fctx.current_delta_lf.with(|c| c.get()); |
| @@ -8313,7 +8811,9 @@ impl Neighbours { | |||
| 8313 | ) { | 8811 | ) { |
| 8314 | let (mi_r, mi_c) = at_mi; | 8812 | let (mi_r, mi_c) = at_mi; |
| 8315 | if crate::envflags::env_flag!("EC_TXGRID_TRACE") { | 8813 | if crate::envflags::env_flag!("EC_TXGRID_TRACE") { |
| 8316 | - 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}"); | 8814 | + eprintln!( |
| 8815 | + "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}" | ||
| 8816 | + ); | ||
| 8317 | } | 8817 | } |
| 8318 | for rr in 0..h_mi { | 8818 | for rr in 0..h_mi { |
| 8319 | let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c; | 8819 | let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c; |
| @@ -8394,8 +8894,12 @@ impl Neighbours { | |||
| 8394 | self.left.iter_mut().for_each(|l| *l = Default::default()); | 8894 | self.left.iter_mut().for_each(|l| *l = Default::default()); |
| 8395 | self.left_mode.iter_mut().for_each(|m| *m = DC_PRED); | 8895 | self.left_mode.iter_mut().for_each(|m| *m = DC_PRED); |
| 8396 | self.left_uv_mode.iter_mut().for_each(|m| *m = DC_PRED); | 8896 | self.left_uv_mode.iter_mut().for_each(|m| *m = DC_PRED); |
| 8397 | - self.left_side.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE); | 8897 | + self.left_side |
| 8398 | - self.left_side_mi.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE as u8); | 8898 | + .iter_mut() |
| 8899 | + .for_each(|s| *s = NO_NEIGHBOUR_SIDE); | ||
| 8900 | + self.left_side_mi | ||
| 8901 | + .iter_mut() | ||
| 8902 | + .for_each(|s| *s = NO_NEIGHBOUR_SIDE as u8); | ||
| 8399 | self.left_skip.iter_mut().for_each(|s| *s = false); | 8903 | self.left_skip.iter_mut().for_each(|s| *s = false); |
| 8400 | self.left_skip_mode.iter_mut().for_each(|s| *s = false); | 8904 | self.left_skip_mode.iter_mut().for_each(|s| *s = false); |
| 8401 | self.left_inter.iter_mut().for_each(|i| *i = false); | 8905 | self.left_inter.iter_mut().for_each(|i| *i = false); |
| @@ -8406,16 +8910,22 @@ impl Neighbours { | |||
| 8406 | self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]); | 8910 | self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]); |
| 8407 | // lane-sub8 r6: mi-granular row maps reset with the rest of the left | 8911 | // lane-sub8 r6: mi-granular row maps reset with the rest of the left |
| 8408 | // context (a tile/SB-row boundary has no left neighbour). | 8912 | // context (a tile/SB-row boundary has no left neighbour). |
| 8409 | - self.sub8_mode_row.iter_mut().for_each(|s| *s = (u16::MAX, 0)); | 8913 | + self.sub8_mode_row |
| 8914 | + .iter_mut() | ||
| 8915 | + .for_each(|s| *s = (u16::MAX, 0)); | ||
| 8410 | self.uv_mode_row.iter_mut().for_each(|s| *s = (u16::MAX, 0)); | 8916 | self.uv_mode_row.iter_mut().for_each(|s| *s = (u16::MAX, 0)); |
| 8411 | // lane-tiles r11 (COMMON's NEIGHBOUR MAPS rule): the palette side bands | 8917 | // lane-tiles r11 (COMMON's NEIGHBOUR MAPS rule): the palette side bands |
| 8412 | // are per-mi maps like every other one here, so they reset with the | 8918 | // are per-mi maps like every other one here, so they reset with the |
| 8413 | // row too -- the left guard above is what actually stops a cross-tile | 8919 | // row too -- the left guard above is what actually stops a cross-tile |
| 8414 | // read, this keeps a stale colour out of the arrays at all. | 8920 | // read, this keeps a stale colour out of the arrays at all. |
| 8415 | self.left_palette_size.iter_mut().for_each(|s| *s = 0); | 8921 | self.left_palette_size.iter_mut().for_each(|s| *s = 0); |
| 8416 | - self.left_palette_colors.iter_mut().for_each(|c| *c = [0u16; 8]); | 8922 | + self.left_palette_colors |
| 8923 | + .iter_mut() | ||
| 8924 | + .for_each(|c| *c = [0u16; 8]); | ||
| 8417 | self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0); | 8925 | self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0); |
| 8418 | - self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]); | 8926 | + self.left_palette_uv_colors |
| 8927 | + .iter_mut() | ||
| 8928 | + .for_each(|c| *c = [0u16; 8]); | ||
| 8419 | // lane-mergefix r2: `av1_zero_left_context` memsets | 8929 | // lane-mergefix r2: `av1_zero_left_context` memsets |
| 8420 | // `left_txfm_context_buffer` to `tx_size_high[TX_SIZES_LARGEST]` at | 8930 | // `left_txfm_context_buffer` to `tx_size_high[TX_SIZES_LARGEST]` at |
| 8421 | // every superblock row of every tile -- the var-tx left context does | 8931 | // every superblock row of every tile -- the var-tx left context does |
| @@ -8710,12 +9220,28 @@ impl Neighbours { | |||
| 8710 | let vote = o.2; | 9220 | let vote = o.2; |
| 8711 | let ab: Vec<String> = (0..above_mi) | 9221 | let ab: Vec<String> = (0..above_mi) |
| 8712 | .step_by(2) | 9222 | .step_by(2) |
| 8713 | - .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level)) | 9223 | + .map(|k| { |
| 9224 | + format!( | ||
| 9225 | + "{:?}/{}", | ||
| 9226 | + self.above[mi_c + k][plane].dc, | ||
| 9227 | + self.above[mi_c + k][plane].level | ||
| 9228 | + ) | ||
| 9229 | + }) | ||
| 8714 | .collect(); | 9230 | .collect(); |
| 8715 | let lf: Vec<String> = (0..left_mi) | 9231 | let lf: Vec<String> = (0..left_mi) |
| 8716 | - .map(|k| format!("{:?}/{}", self.left[mi_r + k][plane].dc, self.left[mi_r + k][plane].level)) | 9232 | + .map(|k| { |
| 9233 | + format!( | ||
| 9234 | + "{:?}/{}", | ||
| 9235 | + self.left[mi_r + k][plane].dc, | ||
| 9236 | + self.left[mi_r + k][plane].level | ||
| 9237 | + ) | ||
| 9238 | + }) | ||
| 8717 | .collect(); | 9239 | .collect(); |
| 8718 | - eprintln!("EC_DCDUMP422 mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(",")); | 9240 | + eprintln!( |
| 9241 | + "EC_DCDUMP422 mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", | ||
| 9242 | + ab.join(","), | ||
| 9243 | + lf.join(",") | ||
| 9244 | + ); | ||
| 8719 | } | 9245 | } |
| 8720 | } | 9246 | } |
| 8721 | out | 9247 | out |
| @@ -8730,7 +9256,12 @@ impl Neighbours { | |||
| 8730 | 9256 | ||
| 8731 | /// [`Self::around_rect`] taking the block's position directly in 4x4 | 9257 | /// [`Self::around_rect`] taking the block's position directly in 4x4 |
| 8732 | /// mode-info units, mirroring [`Self::around_mi`]. | 9258 | /// mode-info units, mirroring [`Self::around_mi`]. |
| 8733 | - fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] { | 9259 | + fn around_mi_rect( |
| 9260 | + &self, | ||
| 9261 | + (mi_r, mi_c): (usize, usize), | ||
| 9262 | + w: usize, | ||
| 9263 | + h: usize, | ||
| 9264 | + ) -> [(bool, bool, i32); 3] { | ||
| 8734 | let (w_mi, h_mi) = (w / MI, h / MI); | 9265 | let (w_mi, h_mi) = (w / MI, h / MI); |
| 8735 | let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c)); | 9266 | let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c)); |
| 8736 | let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r)); | 9267 | let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r)); |
| @@ -8754,12 +9285,28 @@ impl Neighbours { | |||
| 8754 | for (plane, o) in out.iter().enumerate() { | 9285 | for (plane, o) in out.iter().enumerate() { |
| 8755 | let vote = o.2; | 9286 | let vote = o.2; |
| 8756 | let ab: Vec<String> = (0..above_mi) | 9287 | let ab: Vec<String> = (0..above_mi) |
| 8757 | - .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level)) | 9288 | + .map(|k| { |
| 9289 | + format!( | ||
| 9290 | + "{:?}/{}", | ||
| 9291 | + self.above[mi_c + k][plane].dc, | ||
| 9292 | + self.above[mi_c + k][plane].level | ||
| 9293 | + ) | ||
| 9294 | + }) | ||
| 8758 | .collect(); | 9295 | .collect(); |
| 8759 | let lf: Vec<String> = (0..left_mi) | 9296 | let lf: Vec<String> = (0..left_mi) |
| 8760 | - .map(|k| format!("{:?}/{}", self.left[mi_r + k][plane].dc, self.left[mi_r + k][plane].level)) | 9297 | + .map(|k| { |
| 9298 | + format!( | ||
| 9299 | + "{:?}/{}", | ||
| 9300 | + self.left[mi_r + k][plane].dc, | ||
| 9301 | + self.left[mi_r + k][plane].level | ||
| 9302 | + ) | ||
| 9303 | + }) | ||
| 8761 | .collect(); | 9304 | .collect(); |
| 8762 | - eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(",")); | 9305 | + eprintln!( |
| 9306 | + "EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", | ||
| 9307 | + ab.join(","), | ||
| 9308 | + lf.join(",") | ||
| 9309 | + ); | ||
| 8763 | } | 9310 | } |
| 8764 | } | 9311 | } |
| 8765 | out | 9312 | out |
| @@ -8779,12 +9326,7 @@ impl Neighbours { | |||
| 8779 | /// [`Self::luma_skip_ctx`] with the unit's own width and height in mi | 9326 | /// [`Self::luma_skip_ctx`] with the unit's own width and height in mi |
| 8780 | /// units (lane-rectsplitx r1) -- `get_txb_ctx_general` ORs the above | 9327 | /// units (lane-rectsplitx r1) -- `get_txb_ctx_general` ORs the above |
| 8781 | /// context over `tx_size_wide` and the left one over `tx_size_high`. | 9328 | /// context over `tx_size_wide` and the left one over `tx_size_high`. |
| 8782 | - fn luma_skip_ctx_rect( | 9329 | + fn luma_skip_ctx_rect(&self, (mi_r, mi_c): (usize, usize), w_mi: usize, h_mi: usize) -> usize { |
| 8783 | - &self, | ||
| 8784 | - (mi_r, mi_c): (usize, usize), | ||
| 8785 | - w_mi: usize, | ||
| 8786 | - h_mi: usize, | ||
| 8787 | - ) -> usize { | ||
| 8788 | let side_mi = w_mi; | 9330 | let side_mi = w_mi; |
| 8789 | let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c)); | 9331 | let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c)); |
| 8790 | let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r)); | 9332 | let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r)); |
| @@ -8798,10 +9340,12 @@ impl Neighbours { | |||
| 8798 | } | 9340 | } |
| 8799 | let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)]; | 9341 | let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)]; |
| 8800 | if crate::envflags::env_flag!("EC_ECDUMP") { | 9342 | if crate::envflags::env_flag!("EC_ECDUMP") { |
| 8801 | - let ab: Vec<String> = | 9343 | + let ab: Vec<String> = (0..above_mi) |
| 8802 | - (0..above_mi).map(|k| self.above[mi_c + k][0].level.to_string()).collect(); | 9344 | + .map(|k| self.above[mi_c + k][0].level.to_string()) |
| 8803 | - let lf: Vec<String> = | 9345 | + .collect(); |
| 8804 | - (0..left_mi).map(|k| self.left[mi_r + k][0].level.to_string()).collect(); | 9346 | + let lf: Vec<String> = (0..left_mi) |
| 9347 | + .map(|k| self.left[mi_r + k][0].level.to_string()) | ||
| 9348 | + .collect(); | ||
| 8805 | // lane-av1mix: the last few msac register states, so the | 9349 | // lane-av1mix: the last few msac register states, so the |
| 8806 | // byte-position of the `all_zero` read can be matched against | 9350 | // byte-position of the `all_zero` read can be matched against |
| 8807 | // aomdec's `EC=(value,rng,bytepos)` dump (decodetxb.c) without a | 9351 | // aomdec's `EC=(value,rng,bytepos)` dump (decodetxb.c) without a |
| @@ -8813,7 +9357,9 @@ impl Neighbours { | |||
| 8813 | .join(" "); | 9357 | .join(" "); |
| 8814 | eprintln!( | 9358 | eprintln!( |
| 8815 | "EC_ECDUMP plane=0 mi=({mi_r},{mi_c}) wh=({w_mi},{h_mi}) ctx={ctx} above=[{},] left=[{},] recentEC=[{}]", | 9359 | "EC_ECDUMP plane=0 mi=({mi_r},{mi_c}) wh=({w_mi},{h_mi}) ctx={ctx} above=[{},] left=[{},] recentEC=[{}]", |
| 8816 | - ab.join(","), lf.join(","), recent | 9360 | + ab.join(","), |
| 9361 | + lf.join(","), | ||
| 9362 | + recent | ||
| 8817 | ); | 9363 | ); |
| 8818 | } | 9364 | } |
| 8819 | if crate::envflags::env_flag!("EC_AV1_TRACE") { | 9365 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| @@ -8856,14 +9402,7 @@ impl Neighbours { | |||
| 8856 | /// block to the right reads via `mi(row, col-1)`). Only sub-8x8 leaves | 9402 | /// block to the right reads via `mi(row, col-1)`). Only sub-8x8 leaves |
| 8857 | /// read these back, and only when the recorded position is exactly their | 9403 | /// read these back, and only when the recorded position is exactly their |
| 8858 | /// own neighbour -- see [`Self::sub8_mode_col`]'s doc. | 9404 | /// own neighbour -- see [`Self::sub8_mode_col`]'s doc. |
| 8859 | - fn record_mode_mi( | 9405 | + fn record_mode_mi(&mut self, mi_r: usize, mi_c: usize, mi_w: usize, mi_h: usize, mode: usize) { |
| 8860 | - &mut self, | ||
| 8861 | - mi_r: usize, | ||
| 8862 | - mi_c: usize, | ||
| 8863 | - mi_w: usize, | ||
| 8864 | - mi_h: usize, | ||
| 8865 | - mode: usize, | ||
| 8866 | - ) { | ||
| 8867 | let (last_r, last_c) = ((mi_r + mi_h - 1) as u16, (mi_c + mi_w - 1) as u16); | 9406 | let (last_r, last_c) = ((mi_r + mi_h - 1) as u16, (mi_c + mi_w - 1) as u16); |
| 8868 | let mode = mode as u8; | 9407 | let mode = mode as u8; |
| 8869 | for cell in 0..mi_w { | 9408 | for cell in 0..mi_w { |
| @@ -8884,14 +9423,18 @@ impl Neighbours { | |||
| 8884 | /// construction). See [`Self::record_mode_mi`]. | 9423 | /// construction). See [`Self::record_mode_mi`]. |
| 8885 | fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { | 9424 | fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { |
| 8886 | match self.sub8_mode_col.get(mi_c) { | 9425 | match self.sub8_mode_col.get(mi_c) { |
| 8887 | - Some(&(row, m)) if mi_r > self.tile_row0_mi && usize::from(row) == mi_r - 1 => Some(usize::from(m)), | 9426 | + Some(&(row, m)) if mi_r > self.tile_row0_mi && usize::from(row) == mi_r - 1 => { |
| 9427 | + Some(usize::from(m)) | ||
| 9428 | + } | ||
| 8888 | _ => None, | 9429 | _ => None, |
| 8889 | } | 9430 | } |
| 8890 | } | 9431 | } |
| 8891 | 9432 | ||
| 8892 | fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { | 9433 | fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { |
| 8893 | match self.sub8_mode_row.get(mi_r) { | 9434 | match self.sub8_mode_row.get(mi_r) { |
| 8894 | - Some(&(col, m)) if mi_c > self.tile_col0_mi && usize::from(col) == mi_c - 1 => Some(usize::from(m)), | 9435 | + Some(&(col, m)) if mi_c > self.tile_col0_mi && usize::from(col) == mi_c - 1 => { |
| 9436 | + Some(usize::from(m)) | ||
| 9437 | + } | ||
| 8895 | _ => None, | 9438 | _ => None, |
| 8896 | } | 9439 | } |
| 8897 | } | 9440 | } |
| @@ -8907,14 +9450,29 @@ impl Neighbours { | |||
| 8907 | uv_mode: usize, | 9450 | uv_mode: usize, |
| 8908 | ) { | 9451 | ) { |
| 8909 | let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1); | 9452 | let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1); |
| 8910 | - fill_span(&mut self.uv_mode_col, mi_c, mi_w, (last_r as u16, uv_mode as u8)); | 9453 | + fill_span( |
| 8911 | - fill_span(&mut self.uv_mode_row, mi_r, mi_h, (last_c as u16, uv_mode as u8)); | 9454 | + &mut self.uv_mode_col, |
| 9455 | + mi_c, | ||
| 9456 | + mi_w, | ||
| 9457 | + (last_r as u16, uv_mode as u8), | ||
| 9458 | + ); | ||
| 9459 | + fill_span( | ||
| 9460 | + &mut self.uv_mode_row, | ||
| 9461 | + mi_r, | ||
| 9462 | + mi_h, | ||
| 9463 | + (last_c as u16, uv_mode as u8), | ||
| 9464 | + ); | ||
| 8912 | // libaom writes one `MB_MODE_INFO` pointer into every mi cell a block | 9465 | // libaom writes one `MB_MODE_INFO` pointer into every mi cell a block |
| 8913 | // covers, so the chroma neighbour read below is a plain grid read. | 9466 | // covers, so the chroma neighbour read below is a plain grid read. |
| 8914 | let stride = self.uv_grid_cols; | 9467 | let stride = self.uv_grid_cols; |
| 8915 | let n = stride.saturating_sub(mi_c).min(last_c + 1 - mi_c); | 9468 | let n = stride.saturating_sub(mi_c).min(last_c + 1 - mi_c); |
| 8916 | for row in mi_r..=last_r { | 9469 | for row in mi_r..=last_r { |
| 8917 | - fill_span(&mut self.uv_mode_grid, row * stride + mi_c, n, uv_mode as u8); | 9470 | + fill_span( |
| 9471 | + &mut self.uv_mode_grid, | ||
| 9472 | + row * stride + mi_c, | ||
| 9473 | + n, | ||
| 9474 | + uv_mode as u8, | ||
| 9475 | + ); | ||
| 8918 | } | 9476 | } |
| 8919 | } | 9477 | } |
| 8920 | 9478 | ||
| @@ -8961,13 +9519,7 @@ impl Neighbours { | |||
| 8961 | /// counter wants this: it measures how often the snap CHANGES the answer, | 9519 | /// counter wants this: it measures how often the snap CHANGES the answer, |
| 8962 | /// which is what the lane-kf1200/kf900 chroma-reference fix buys. Every | 9520 | /// which is what the lane-kf1200/kf900 chroma-reference fix buys. Every |
| 8963 | /// decode path uses the snapping form. | 9521 | /// decode path uses the snapping form. |
| 8964 | - fn smooth_uv_neighbour_unsnapped( | 9522 | + fn smooth_uv_neighbour_unsnapped(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool { |
| 8965 | - &self, | ||
| 8966 | - mi_r: usize, | ||
| 8967 | - mi_c: usize, | ||
| 8968 | - r: usize, | ||
| 8969 | - c: usize, | ||
| 8970 | - ) -> bool { | ||
| 8971 | // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the | 9523 | // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the |
| 8972 | // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid | 9524 | // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid |
| 8973 | // array that `start_tile` does not clear, so a block on a tile's first | 9525 | // array that `start_tile` does not clear, so a block on a tile's first |
| @@ -9152,18 +9704,15 @@ impl Neighbours { | |||
| 9152 | 9704 | ||
| 9153 | /// [`Self::record_mi`] with independent above (`w`)/left (`h`) extents, | 9705 | /// [`Self::record_mi`] with independent above (`w`)/left (`h`) extents, |
| 9154 | /// in pixels (lane-partitions r1, mirroring [`Self::record_rect`]). | 9706 | /// in pixels (lane-partitions r1, mirroring [`Self::record_rect`]). |
| 9155 | - fn record_mi_rect( | 9707 | + fn record_mi_rect(&mut self, at_mi: (usize, usize), w: usize, h: usize, grids: &[&[i32]; 3]) { |
| 9156 | - &mut self, | ||
| 9157 | - at_mi: (usize, usize), | ||
| 9158 | - w: usize, | ||
| 9159 | - h: usize, | ||
| 9160 | - grids: &[&[i32]; 3], | ||
| 9161 | - ) { | ||
| 9162 | let (mi_r, mi_c) = at_mi; | 9708 | let (mi_r, mi_c) = at_mi; |
| 9163 | let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(grids[plane])); | 9709 | let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(grids[plane])); |
| 9164 | let (w_mi, h_mi) = (w / MI, h / MI); | 9710 | let (w_mi, h_mi) = (w / MI, h / MI); |
| 9165 | if crate::envflags::env_flag!("EC_ECPUB") { | 9711 | if crate::envflags::env_flag!("EC_ECPUB") { |
| 9166 | - eprintln!("EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", states[0].level); | 9712 | + eprintln!( |
| 9713 | + "EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", | ||
| 9714 | + states[0].level | ||
| 9715 | + ); | ||
| 9167 | } | 9716 | } |
| 9168 | fill_span(&mut self.left_side_mi, mi_r, h_mi, h as u8); | 9717 | fill_span(&mut self.left_side_mi, mi_r, h_mi, h as u8); |
| 9169 | fill_span(&mut self.above_side_mi, mi_c, w_mi, w as u8); | 9718 | fill_span(&mut self.above_side_mi, mi_c, w_mi, w as u8); |
| @@ -9271,7 +9820,10 @@ impl Neighbours { | |||
| 9271 | ) { | 9820 | ) { |
| 9272 | let state = neighbour_state(grid); | 9821 | let state = neighbour_state(grid); |
| 9273 | if crate::envflags::env_flag!("EC_ECPUB") { | 9822 | if crate::envflags::env_flag!("EC_ECPUB") { |
| 9274 | - eprintln!("EC_ECPUB tu mi=({mi_r},{mi_c}) wh=({w_px},{h_px}) lvl={}", state.level); | 9823 | + eprintln!( |
| 9824 | + "EC_ECPUB tu mi=({mi_r},{mi_c}) wh=({w_px},{h_px}) lvl={}", | ||
| 9825 | + state.level | ||
| 9826 | + ); | ||
| 9275 | } | 9827 | } |
| 9276 | for cell in 0..h_px / MI { | 9828 | for cell in 0..h_px / MI { |
| 9277 | if mi_r + cell < self.mi_rows { | 9829 | if mi_r + cell < self.mi_rows { |
| @@ -9509,7 +10061,11 @@ struct PaletteUv { | |||
| 9509 | /// `get_unsigned_bits`, which is the same formula): smallest `n` with | 10061 | /// `get_unsigned_bits`, which is the same formula): smallest `n` with |
| 9510 | /// `2^n >= x`, `0` for `x <= 1`. | 10062 | /// `2^n >= x`, `0` for `x <= 1`. |
| 9511 | pub(crate) fn ceil_log2(x: u32) -> u32 { | 10063 | pub(crate) fn ceil_log2(x: u32) -> u32 { |
| 9512 | - if x < 2 { 0 } else { 32 - (x - 1).leading_zeros() } | 10064 | + if x < 2 { |
| 10065 | + 0 | ||
| 10066 | + } else { | ||
| 10067 | + 32 - (x - 1).leading_zeros() | ||
| 10068 | + } | ||
| 9513 | } | 10069 | } |
| 9514 | 10070 | ||
| 9515 | /// `av1_read_uniform` (decoder.h:425): a uniform `0..n` value coded as | 10071 | /// `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<u16> { | |||
| 9560 | /// (one flag bit each, in cache order), then delta-codes the remainder | 10116 | /// (one flag bit each, in cache order), then delta-codes the remainder |
| 9561 | /// (first value raw, each following delta `>= 1` off a shrinking bit width), | 10117 | /// (first value raw, each following delta `>= 1` off a shrinking bit width), |
| 9562 | /// and merges the two ascending lists back together. | 10118 | /// and merges the two ascending lists back together. |
| 9563 | -fn read_palette_colors_y(dec: &mut SymbolDecoder, n: usize, cache: &[u16], fctx: &crate::decode::FrameCtx) -> [u16; 8] { | 10119 | +fn read_palette_colors_y( |
| 10120 | + dec: &mut SymbolDecoder, | ||
| 10121 | + n: usize, | ||
| 10122 | + cache: &[u16], | ||
| 10123 | + fctx: &crate::decode::FrameCtx, | ||
| 10124 | +) -> [u16; 8] { | ||
| 9564 | let mut cached = Vec::with_capacity(n); | 10125 | let mut cached = Vec::with_capacity(n); |
| 9565 | for &c in cache { | 10126 | for &c in cache { |
| 9566 | if cached.len() >= n { | 10127 | if cached.len() >= n { |
| @@ -9607,7 +10168,12 @@ fn read_palette_colors_y(dec: &mut SymbolDecoder, n: usize, cache: &[u16], fctx: | |||
| 9607 | /// side by side). V never uses a cache: a leading bit picks either `n` raw | 10168 | /// side by side). V never uses a cache: a leading bit picks either `n` raw |
| 9608 | /// literals, or a first raw value plus `n-1` signed deltas that wrap mod 256 | 10169 | /// literals, or a first raw value plus `n-1` signed deltas that wrap mod 256 |
| 9609 | /// rather than clamp. | 10170 | /// rather than clamp. |
| 9610 | -fn read_palette_colors_uv(dec: &mut SymbolDecoder, n: usize, cache: &[u16], fctx: &crate::decode::FrameCtx) -> ([u16; 8], [u16; 8]) { | 10171 | +fn read_palette_colors_uv( |
| 10172 | + dec: &mut SymbolDecoder, | ||
| 10173 | + n: usize, | ||
| 10174 | + cache: &[u16], | ||
| 10175 | + fctx: &crate::decode::FrameCtx, | ||
| 10176 | +) -> ([u16; 8], [u16; 8]) { | ||
| 9611 | let mut cached = Vec::with_capacity(n); | 10177 | let mut cached = Vec::with_capacity(n); |
| 9612 | for &c in cache { | 10178 | for &c in cache { |
| 9613 | if cached.len() >= n { | 10179 | if cached.len() >= n { |
| @@ -9689,13 +10255,21 @@ pub(crate) fn palette_color_index_context( | |||
| 9689 | col: usize, | 10255 | col: usize, |
| 9690 | n: usize, | 10256 | n: usize, |
| 9691 | ) -> (usize, [u8; 8]) { | 10257 | ) -> (usize, [u8; 8]) { |
| 9692 | - let left = if col >= 1 { Some(map[row * side + col - 1]) } else { None }; | 10258 | + let left = if col >= 1 { |
| 10259 | + Some(map[row * side + col - 1]) | ||
| 10260 | + } else { | ||
| 10261 | + None | ||
| 10262 | + }; | ||
| 9693 | let up_left = if col >= 1 && row >= 1 { | 10263 | let up_left = if col >= 1 && row >= 1 { |
| 9694 | Some(map[(row - 1) * side + col - 1]) | 10264 | Some(map[(row - 1) * side + col - 1]) |
| 9695 | } else { | 10265 | } else { |
| 9696 | None | 10266 | None |
| 9697 | }; | 10267 | }; |
| 9698 | - let up = if row >= 1 { Some(map[(row - 1) * side + col]) } else { None }; | 10268 | + let up = if row >= 1 { |
| 10269 | + Some(map[(row - 1) * side + col]) | ||
| 10270 | + } else { | ||
| 10271 | + None | ||
| 10272 | + }; | ||
| 9699 | let mut scores = [0i32; 8]; | 10273 | let mut scores = [0i32; 8]; |
| 9700 | for (neighbour, weight) in [(left, 2), (up_left, 1), (up, 2)] { | 10274 | for (neighbour, weight) in [(left, 2), (up_left, 1), (up, 2)] { |
| 9701 | if let Some(v) = neighbour { | 10275 | if let Some(v) = neighbour { |
| @@ -9847,7 +10421,10 @@ fn decode_color_index_map_wh( | |||
| 9847 | } else { | 10421 | } else { |
| 9848 | &cdfs.palette_y_color_index[n - 2][ctx] | 10422 | &cdfs.palette_y_color_index[n - 2][ctx] |
| 9849 | }; | 10423 | }; |
| 9850 | - eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} cdf0={} cnt={} rng={rng}", row_cdf[0], row_cdf[n]); | 10424 | + eprintln!( |
| 10425 | + "EC_PAL row={row} col={col} ctx={ctx} n={n} cdf0={} cnt={} rng={rng}", | ||
| 10426 | + row_cdf[0], row_cdf[n] | ||
| 10427 | + ); | ||
| 9851 | } | 10428 | } |
| 9852 | let symbol = if uv { | 10429 | let symbol = if uv { |
| 9853 | dec.symbol(&mut cdfs.palette_uv_color_index[n - 2][ctx][..=n]) | 10430 | dec.symbol(&mut cdfs.palette_uv_color_index[n - 2][ctx][..=n]) |
| @@ -9914,7 +10491,8 @@ fn read_intra_mode_rect( | |||
| 9914 | palette: Option<(usize, &[u16])>, | 10491 | palette: Option<(usize, &[u16])>, |
| 9915 | palette_uv_cache: &[u16], | 10492 | palette_uv_cache: &[u16], |
| 9916 | mi_r: usize, | 10493 | mi_r: usize, |
| 9917 | - mi_c: usize, fctx: &crate::decode::FrameCtx, | 10494 | + mi_c: usize, |
| 10495 | + fctx: &crate::decode::FrameCtx, | ||
| 9918 | ) -> Result<( | 10496 | ) -> Result<( |
| 9919 | bool, | 10497 | bool, |
| 9920 | usize, | 10498 | usize, |
| @@ -9946,7 +10524,12 @@ fn read_intra_mode_rect( | |||
| 9946 | // (decodemv.c:818), printed at the same point: before the first | 10524 | // (decodemv.c:818), printed at the same point: before the first |
| 9947 | // mode-info symbol of the block, so a cross-decoder range ladder can | 10525 | // mode-info symbol of the block, so a cross-decoder range ladder can |
| 9948 | // be keyed on the BLOCK, not just on the symbol sequence. | 10526 | // be keyed on the BLOCK, not just on the symbol sequence. |
| 9949 | - 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); | 10527 | + eprintln!( |
| 10528 | + "EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=rect bw={bw} bh={bh} efi={} cls={:?} rng={}", | ||
| 10529 | + enable_filter_intra as i32, | ||
| 10530 | + filter_intra_size_class_rect(bw, bh), | ||
| 10531 | + dec.debug_state().0 | ||
| 10532 | + ); | ||
| 9950 | } | 10533 | } |
| 9951 | macro_rules! istep { | 10534 | macro_rules! istep { |
| 9952 | ($name:literal, $val:expr) => { | 10535 | ($name:literal, $val:expr) => { |
| @@ -10092,9 +10675,7 @@ fn read_intra_mode_rect( | |||
| 10092 | // runs from the caller, after the whole mode-info read). | 10675 | // runs from the caller, after the whole mode-info read). |
| 10093 | let mut palette_y_pending: Option<(usize, [u16; 8])> = None; | 10676 | let mut palette_y_pending: Option<(usize, [u16; 8])> = None; |
| 10094 | let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None; | 10677 | let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None; |
| 10095 | - if allow_screen_content_tools | 10678 | + if allow_screen_content_tools && let Some(bsize_ctx) = palette_bsize_ctx_wh(bw, bh) { |
| 10096 | - && let Some(bsize_ctx) = palette_bsize_ctx_wh(bw, bh) | ||
| 10097 | - { | ||
| 10098 | // r6: this is the exact site the removed blanket refusal used to | 10679 | // r6: this is the exact site the removed blanket refusal used to |
| 10099 | // guard -- reached for EVERY rect strip in a screen-content frame, | 10680 | // guard -- reached for EVERY rect strip in a screen-content frame, |
| 10100 | // independent of whether the block ends up using a palette. | 10681 | // independent of whether the block ends up using a palette. |
| @@ -10150,11 +10731,22 @@ fn read_intra_mode_rect( | |||
| 10150 | // `av1_visit_palette`: plane 0 (Y) then plane 1 (chroma, shared U/V map), | 10731 | // `av1_visit_palette`: plane 0 (Y) then plane 1 (chroma, shared U/V map), |
| 10151 | // same order as [`read_intra_mode`]'s own square path. | 10732 | // same order as [`read_intra_mode`]'s own square path. |
| 10152 | let palette_y = palette_y_pending.map(|(n, colors)| { | 10733 | let palette_y = palette_y_pending.map(|(n, colors)| { |
| 10153 | - let map = | 10734 | + let map = decode_color_index_map_wh( |
| 10154 | - decode_color_index_map_wh(dec, cdfs, n, bw, bh, palette_onscreen(mi_r, mi_c, bw, bh, fctx), false); | 10735 | + dec, |
| 10736 | + cdfs, | ||
| 10737 | + n, | ||
| 10738 | + bw, | ||
| 10739 | + bh, | ||
| 10740 | + palette_onscreen(mi_r, mi_c, bw, bh, fctx), | ||
| 10741 | + false, | ||
| 10742 | + ); | ||
| 10155 | hit!(PALETTE_HITS); | 10743 | hit!(PALETTE_HITS); |
| 10156 | hit!(PALETTE_RECT_HITS); | 10744 | hit!(PALETTE_RECT_HITS); |
| 10157 | - PaletteY { size: n, colors, map } | 10745 | + PaletteY { |
| 10746 | + size: n, | ||
| 10747 | + colors, | ||
| 10748 | + map, | ||
| 10749 | + } | ||
| 10158 | }); | 10750 | }); |
| 10159 | let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { | 10751 | let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { |
| 10160 | // `av1_get_plane_block_size(bsize, 1, 1)` (`ss_size_lookup`), NOT a | 10752 | // `av1_get_plane_block_size(bsize, 1, 1)` (`ss_size_lookup`), NOT a |
| @@ -10163,10 +10755,20 @@ fn read_intra_mode_rect( | |||
| 10163 | // axis to 2 read HALF the colour-index symbols of a 1:4 strip's | 10755 | // axis to 2 read HALF the colour-index symbols of a 1:4 strip's |
| 10164 | // chroma palette and desynced the tile from there. | 10756 | // chroma palette and desynced the tile from there. |
| 10165 | let (cw, ch) = ((bw >> ss_x(fctx)).max(4), (bh >> ss_y(fctx)).max(4)); | 10757 | let (cw, ch) = ((bw >> ss_x(fctx)).max(4), (bh >> ss_y(fctx)).max(4)); |
| 10166 | - let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch), (ss_x(fctx), ss_y(fctx))); | 10758 | + let on = palette_onscreen_uv( |
| 10759 | + (bw, bh), | ||
| 10760 | + palette_onscreen(mi_r, mi_c, bw, bh, fctx), | ||
| 10761 | + (cw, ch), | ||
| 10762 | + (ss_x(fctx), ss_y(fctx)), | ||
| 10763 | + ); | ||
| 10167 | let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true); | 10764 | let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true); |
| 10168 | hit!(PALETTE_UV_HITS); | 10765 | hit!(PALETTE_UV_HITS); |
| 10169 | - PaletteUv { size: n, u_colors, v_colors, map } | 10766 | + PaletteUv { |
| 10767 | + size: n, | ||
| 10768 | + u_colors, | ||
| 10769 | + v_colors, | ||
| 10770 | + map, | ||
| 10771 | + } | ||
| 10170 | }); | 10772 | }); |
| 10171 | Ok(( | 10773 | Ok(( |
| 10172 | skip, | 10774 | skip, |
| @@ -10246,7 +10848,9 @@ fn record_strip_palette( | |||
| 10246 | 10848 | ||
| 10247 | /// [`cfl_ac_q3`] for a true `bw`x`bh` rect strip (lane-intradisp r1). | 10849 | /// [`cfl_ac_q3`] for a true `bw`x`bh` rect strip (lane-intradisp r1). |
| 10248 | fn cfl_ac_q3_rect(y: &PlaneBuf<'_>, px: usize, py: usize, bw: usize, bh: usize) -> Vec<i32> { | 10850 | fn cfl_ac_q3_rect(y: &PlaneBuf<'_>, px: usize, py: usize, bw: usize, bh: usize) -> Vec<i32> { |
| 10249 | - cfl_ac_q3_at(px, py, bw, bh, |lx, ly| i32::from(y.data[ly * y.width + lx])) | 10851 | + cfl_ac_q3_at(px, py, bw, bh, |lx, ly| { |
| 10852 | + i32::from(y.data[ly * y.width + lx]) | ||
| 10853 | + }) | ||
| 10250 | } | 10854 | } |
| 10251 | 10855 | ||
| 10252 | /// Everything a rect strip already read out of the stream before its luma | 10856 | /// Everything a rect strip already read out of the stream before its luma |
| @@ -10375,7 +10979,8 @@ fn decode_rect_split( | |||
| 10375 | u: &mut PlaneBuf<'static>, | 10979 | u: &mut PlaneBuf<'static>, |
| 10376 | v: &mut PlaneBuf<'static>, | 10980 | v: &mut PlaneBuf<'static>, |
| 10377 | base_q_idx: u8, | 10981 | base_q_idx: u8, |
| 10378 | - reduced_tx_set: bool, fctx: &crate::decode::FrameCtx, | 10982 | + reduced_tx_set: bool, |
| 10983 | + fctx: &crate::decode::FrameCtx, | ||
| 10379 | ) -> Result<()> { | 10984 | ) -> Result<()> { |
| 10380 | let (mi_r, mi_c) = at_mi; | 10985 | let (mi_r, mi_c) = at_mi; |
| 10381 | let (px, py) = (mi_c * MI, mi_r * MI); | 10986 | let (px, py) = (mi_c * MI, mi_r * MI); |
| @@ -10409,8 +11014,8 @@ fn decode_rect_split( | |||
| 10409 | // needs. | 11014 | // needs. |
| 10410 | let chroma422_pair = chroma422_pair_plane(ss_x(fctx) == 1, ss_y(fctx) == 0, mi_c, bw, bh); | 11015 | let chroma422_pair = chroma422_pair_plane(ss_x(fctx) == 1, ss_y(fctx) == 0, mi_c, bw, bh); |
| 10411 | let chroma_422_pair_wide = chroma422_pair.is_some(); | 11016 | let chroma_422_pair_wide = chroma422_pair.is_some(); |
| 10412 | - let (chroma_block_w, chroma_block_h, chroma_x) = chroma422_pair | 11017 | + let (chroma_block_w, chroma_block_h, chroma_x) = |
| 10413 | - .map_or((chroma_w, chroma_h, cpx), |(w, h, x, _)| (w, h, x)); | 11018 | + chroma422_pair.map_or((chroma_w, chroma_h, cpx), |(w, h, x, _)| (w, h, x)); |
| 10414 | // The chroma transform is picked before any symbol is read, so an | 11019 | // The chroma transform is picked before any symbol is read, so an |
| 10415 | // unsupported chroma shape refuses before this strip desyncs the tile. | 11020 | // unsupported chroma shape refuses before this strip desyncs the tile. |
| 10416 | let chroma: Option<(TxbSet, &[u16])> = match (chroma_w, chroma_h) { | 11021 | let chroma: Option<(TxbSet, &[u16])> = match (chroma_w, chroma_h) { |
| @@ -10506,7 +11111,11 @@ fn decode_rect_split( | |||
| 10506 | } else { | 11111 | } else { |
| 10507 | TxbSet::LumaRect16x8Set1 | 11112 | TxbSet::LumaRect16x8Set1 |
| 10508 | }, | 11113 | }, |
| 10509 | - if tx_w == 16 { &SCAN_16X8[..] } else { &SCAN_8X16[..] }, | 11114 | + if tx_w == 16 { |
| 11115 | + &SCAN_16X8[..] | ||
| 11116 | + } else { | ||
| 11117 | + &SCAN_8X16[..] | ||
| 11118 | + }, | ||
| 10510 | )), | 11119 | )), |
| 10511 | (32, 16) => Some((TxbSet::LumaRect32x16, &SCAN_32X16[..])), | 11120 | (32, 16) => Some((TxbSet::LumaRect32x16, &SCAN_32X16[..])), |
| 10512 | (16, 32) => Some((TxbSet::LumaRect32x16, &SCAN_16X32[..])), | 11121 | (16, 32) => Some((TxbSet::LumaRect32x16, &SCAN_16X32[..])), |
| @@ -10532,7 +11141,7 @@ fn decode_rect_split( | |||
| 10532 | return Err(unsupported(format!( | 11141 | return Err(unsupported(format!( |
| 10533 | "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma \ | 11142 | "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma \ |
| 10534 | coefficient tables for that shape here)" | 11143 | coefficient tables for that shape here)" |
| 10535 | - ))) | 11144 | + ))); |
| 10536 | } | 11145 | } |
| 10537 | }; | 11146 | }; |
| 10538 | // The `None` above that is NOT the square arm. | 11147 | // The `None` above that is NOT the square arm. |
| @@ -10592,7 +11201,8 @@ fn decode_rect_split( | |||
| 10592 | set_palette_pred(tu_buf, fctx); | 11201 | set_palette_pred(tu_buf, fctx); |
| 10593 | } | 11202 | } |
| 10594 | if m.skip { | 11203 | if m.skip { |
| 10595 | - push_intra_rect(0, | 11204 | + push_intra_rect( |
| 11205 | + 0, | ||
| 10596 | tu_px, | 11206 | tu_px, |
| 10597 | tu_py, | 11207 | tu_py, |
| 10598 | tx_w, | 11208 | tx_w, |
| @@ -10603,7 +11213,8 @@ fn decode_rect_split( | |||
| 10603 | &zero_tu, | 11213 | &zero_tu, |
| 10604 | None, | 11214 | None, |
| 10605 | m.filter_intra, | 11215 | m.filter_intra, |
| 10606 | - m.smooth_neighbor, fctx, | 11216 | + m.smooth_neighbor, |
| 11217 | + fctx, | ||
| 10607 | ); | 11218 | ); |
| 10608 | neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &zero_tu); | 11219 | neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &zero_tu); |
| 10609 | } else if luma_64corner && luma_rect.is_none() { | 11220 | } else if luma_64corner && luma_rect.is_none() { |
| @@ -10653,7 +11264,8 @@ fn decode_rect_split( | |||
| 10653 | tu_tx_type, | 11264 | tu_tx_type, |
| 10654 | block_iqmatrix(fctx, 0, tx_w, tx_h, tu_tx_type), | 11265 | block_iqmatrix(fctx, 0, tx_w, tx_h, tu_tx_type), |
| 10655 | ); | 11266 | ); |
| 10656 | - push_intra_rect(0, | 11267 | + push_intra_rect( |
| 11268 | + 0, | ||
| 10657 | tu_px, | 11269 | tu_px, |
| 10658 | tu_py, | 11270 | tu_py, |
| 10659 | tx_w, | 11271 | tx_w, |
| @@ -10664,7 +11276,8 @@ fn decode_rect_split( | |||
| 10664 | &residual, | 11276 | &residual, |
| 10665 | None, | 11277 | None, |
| 10666 | m.filter_intra, | 11278 | m.filter_intra, |
| 10667 | - m.smooth_neighbor, fctx, | 11279 | + m.smooth_neighbor, |
| 11280 | + fctx, | ||
| 10668 | ); | 11281 | ); |
| 10669 | neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &tu_grid); | 11282 | neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &tu_grid); |
crates/ec-av1/src/stream.rsmodified+5380 -1608
Diff too large; view file
| @@ -1,3 +1,5 @@ | |||
| 1 | +/home/user/Documents/Code/Rust/edith_codecs/crates/ec-av1/src/stream.rs: | ||
| 2 | + | ||
| 1 | //! The stream-level entry point a real decoder needs: walk a raw AV1 OBU | 3 | //! The stream-level entry point a real decoder needs: walk a raw AV1 OBU |
| 2 | //! stream (`Encoded::stream`, or any low-overhead-format bitstream this | 4 | //! stream (`Encoded::stream`, or any low-overhead-format bitstream this |
| 3 | //! crate's own writers produce) via [`ec_av1_syntax::Av1Parser`] and dispatch | 5 | //! crate's own writers produce) via [`ec_av1_syntax::Av1Parser`] and dispatch |
| @@ -28,12 +30,9 @@ use ec_core::{Error, Result}; | |||
| 28 | 30 | ||
| 29 | use crate::cdf_state::Cdfs; | 31 | use crate::cdf_state::Cdfs; |
| 30 | use crate::decode; | 32 | use crate::decode; |
| 31 | -use crate::decode::{ | ||
| 32 | - decode_inter_frame_tile_with_cdfs, decode_key_frame_tile_with_cdfs, | ||
| 33 | - q_ctx_of, | ||
| 34 | -}; | ||
| 35 | #[cfg(test)] | 33 | #[cfg(test)] |
| 36 | use crate::decode::decode_key_frame_tile_lr; | 34 | use crate::decode::decode_key_frame_tile_lr; |
| 35 | +use crate::decode::{decode_inter_frame_tile_with_cdfs, decode_key_frame_tile_with_cdfs, q_ctx_of}; | ||
| 37 | use crate::encode::Picture; | 36 | use crate::encode::Picture; |
| 38 | 37 | ||
| 39 | /// lane-midcut r1: `EC_AV1_NO_GRAIN=1` skips film grain synthesis at output, so a | 38 | /// 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 { | |||
| 217 | crate::decode::intrabc_128rect_hits() | 216 | crate::decode::intrabc_128rect_hits() |
| 218 | } | 217 | } |
| 219 | 218 | ||
| 219 | +/// lane-av1-ibc128chunk: chroma transform units the 128-root intrabc strip's | ||
| 220 | +/// mu-chunk walk read, one per `read_inter_plane` chroma call. At 4:2:2 a | ||
| 221 | +/// 64x64 mu chunk's chroma plane block is 32x64 and holds TWO STACKED | ||
| 222 | +/// TX_32X32 units per plane; the square-cut walk this gate witnesses read | ||
| 223 | +/// one. Measured on the pinned witness: 8 before, 48 after. | ||
| 224 | +pub fn intrabc_128rect_chroma_chunk_hits() -> usize { | ||
| 225 | + crate::decode::intrabc_128rect_chroma_chunk_hits() | ||
| 226 | +} | ||
| 227 | + | ||
| 228 | +/// lane-av1-ibc128chunk: the 128-root intrabc strip's per-axis chroma chunk | ||
| 229 | +/// extents as `(64 >> ss_x) << 8 | (64 >> ss_y)` on the last chunk walked -- | ||
| 230 | +/// 32|32 at 4:2:0, 32|64 at 4:2:2, 64|64 at 4:4:4. | ||
| 231 | +pub fn intrabc_128rect_chunk_shape() -> usize { | ||
| 232 | + crate::decode::intrabc_128rect_chunk_shape() | ||
| 233 | +} | ||
| 234 | + | ||
| 220 | /// Blocks reconstructed with intra block copy at an 8x8 LEAF specifically | 235 | /// Blocks reconstructed with intra block copy at an 8x8 LEAF specifically |
| 221 | /// (lane-kf900 r7's shape); [`crate::decode::intrabc_hits`] counts every shape. | 236 | /// (lane-kf900 r7's shape); [`crate::decode::intrabc_hits`] counts every shape. |
| 222 | pub fn leaf8_intrabc_hits() -> usize { | 237 | pub fn leaf8_intrabc_hits() -> usize { |
| @@ -384,16 +399,19 @@ struct Reorder { | |||
| 384 | } | 399 | } |
| 385 | 400 | ||
| 386 | impl Reorder { | 401 | impl Reorder { |
| 387 | - fn push(&mut self, seq: usize, picture: std::sync::Arc<Picture>, decode_idx: usize, shown: bool) { | 402 | + fn push( |
| 403 | + &mut self, | ||
| 404 | + seq: usize, | ||
| 405 | + picture: std::sync::Arc<Picture>, | ||
| 406 | + decode_idx: usize, | ||
| 407 | + shown: bool, | ||
| 408 | + ) { | ||
| 388 | self.pending.insert(seq, (picture, decode_idx, shown)); | 409 | self.pending.insert(seq, (picture, decode_idx, shown)); |
| 389 | } | 410 | } |
| 390 | 411 | ||
| 391 | /// Emits every queued picture whose turn has come. An `Err` from `sink` | 412 | /// Emits every queued picture whose turn has come. An `Err` from `sink` |
| 392 | /// aborts the decode, unchanged, exactly as the serial path did. | 413 | /// aborts the decode, unchanged, exactly as the serial path did. |
| 393 | - fn drain( | 414 | + fn drain(&mut self, sink: &mut impl FnMut(&Picture, usize, bool) -> Result<()>) -> Result<()> { |
| 394 | - &mut self, | ||
| 395 | - sink: &mut impl FnMut(&Picture, usize, bool) -> Result<()>, | ||
| 396 | - ) -> Result<()> { | ||
| 397 | while let Some((picture, decode_idx, shown)) = self.pending.remove(&self.next) { | 415 | while let Some((picture, decode_idx, shown)) = self.pending.remove(&self.next) { |
| 398 | self.next += 1; | 416 | self.next += 1; |
| 399 | sink(&picture, decode_idx, shown)?; | 417 | sink(&picture, decode_idx, shown)?; |
| @@ -411,8 +429,7 @@ impl Reorder { | |||
| 411 | /// inline. (lane-thread2 counted only LEAF frames, the only ones it could | 429 | /// inline. (lane-thread2 counted only LEAF frames, the only ones it could |
| 412 | /// dispatch; lane-thread3 dispatches every non-key, non-`show_existing_frame` | 430 | /// dispatch; lane-thread3 dispatches every non-key, non-`show_existing_frame` |
| 413 | /// frame, hence the rename.) | 431 | /// frame, hence the rename.) |
| 414 | -static FRAMES_DISPATCHED: std::sync::atomic::AtomicUsize = | 432 | +static FRAMES_DISPATCHED: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 415 | - std::sync::atomic::AtomicUsize::new(0); | ||
| 416 | 433 | ||
| 417 | /// Reads [`FRAMES_DISPATCHED`]. | 434 | /// Reads [`FRAMES_DISPATCHED`]. |
| 418 | pub fn frames_dispatched() -> usize { | 435 | pub fn frames_dispatched() -> usize { |
| @@ -803,7 +820,8 @@ pub fn decode_stream_with_threads( | |||
| 803 | &picture, | 820 | &picture, |
| 804 | &header.film_grain, | 821 | &header.film_grain, |
| 805 | mc_identity, | 822 | mc_identity, |
| 806 | - bit_depth as u32, fctx, | 823 | + bit_depth as u32, |
| 824 | + fctx, | ||
| 807 | )) | 825 | )) |
| 808 | } else { | 826 | } else { |
| 809 | picture | 827 | picture |
| @@ -1214,8 +1232,7 @@ pub fn decode_stream_with_threads( | |||
| 1214 | final_dump.as_deref(), | 1232 | final_dump.as_deref(), |
| 1215 | None, | 1233 | None, |
| 1216 | )?; | 1234 | )?; |
| 1217 | - let motion_field = | 1235 | + let motion_field = motion_field.expect("the inline path passes no stage-1 sink"); |
| 1218 | - motion_field.expect("the inline path passes no stage-1 sink"); | ||
| 1219 | pictures_decoded += 1; | 1236 | pictures_decoded += 1; |
| 1220 | // lane-pool1: one allocation, then every slot store and the output | 1237 | // lane-pool1: one allocation, then every slot store and the output |
| 1221 | // itself are refcount bumps instead of plane copies. | 1238 | // itself are refcount bumps instead of plane copies. |
| @@ -1271,7 +1288,8 @@ pub fn decode_stream_with_threads( | |||
| 1271 | &picture, | 1288 | &picture, |
| 1272 | &header.film_grain, | 1289 | &header.film_grain, |
| 1273 | mc_identity, | 1290 | mc_identity, |
| 1274 | - bit_depth as u32, fctx, | 1291 | + bit_depth as u32, |
| 1292 | + fctx, | ||
| 1275 | )) | 1293 | )) |
| 1276 | } else { | 1294 | } else { |
| 1277 | picture | 1295 | picture |
| @@ -1304,8 +1322,6 @@ pub fn decode_stream_with_threads( | |||
| 1304 | Ok(()) | 1322 | Ok(()) |
| 1305 | } | 1323 | } |
| 1306 | 1324 | ||
| 1307 | - | ||
| 1308 | - | ||
| 1309 | /// lane-thread2: the sequence-header bits a single frame's decode needs, | 1325 | /// lane-thread2: the sequence-header bits a single frame's decode needs, |
| 1310 | /// read once on the parsing thread so that [`decode_frame`] never touches the | 1326 | /// read once on the parsing thread so that [`decode_frame`] never touches the |
| 1311 | /// [`Av1Parser`] (a worker thread has no access to it). | 1327 | /// [`Av1Parser`] (a worker thread has no access to it). |
| @@ -1394,8 +1410,8 @@ impl<'a> RefSnapshot<'a> { | |||
| 1394 | // spec 7.9's own driver, `av1_setup_motion_field`: only run when | 1410 | // spec 7.9's own driver, `av1_setup_motion_field`: only run when |
| 1395 | // this frame's header asks for it, and never for a key frame (which | 1411 | // this frame's header asks for it, and never for a key frame (which |
| 1396 | // codes no inter block at all). | 1412 | // codes no inter block at all). |
| 1397 | - let tpl_field = (header.frame_type != FrameType::Key && header.use_ref_frame_mvs).then( | 1413 | + let tpl_field = |
| 1398 | - || { | 1414 | + (header.frame_type != FrameType::Key && header.use_ref_frame_mvs).then(|| { |
| 1399 | crate::motion_field::setup_motion_field( | 1415 | crate::motion_field::setup_motion_field( |
| 1400 | motion_field_slots, | 1416 | motion_field_slots, |
| 1401 | header.ref_frame_idx, | 1417 | header.ref_frame_idx, |
| @@ -1404,8 +1420,7 @@ impl<'a> RefSnapshot<'a> { | |||
| 1404 | header.mi_rows as usize, | 1420 | header.mi_rows as usize, |
| 1405 | header.mi_cols as usize, | 1421 | header.mi_cols as usize, |
| 1406 | ) | 1422 | ) |
| 1407 | - }, | 1423 | + }); |
| 1408 | - ); | ||
| 1409 | if std::env::var_os("EC_TPL").is_some() { | 1424 | if std::env::var_os("EC_TPL").is_some() { |
| 1410 | eprintln!( | 1425 | eprintln!( |
| 1411 | "EC_TPL order_hint={} use_ref_frame_mvs={} cells={}", | 1426 | "EC_TPL order_hint={} use_ref_frame_mvs={} cells={}", |
| @@ -1520,7 +1535,8 @@ fn decode_frame( | |||
| 1520 | header.segmentation, | 1535 | header.segmentation, |
| 1521 | header.mi_rows as usize, | 1536 | header.mi_rows as usize, |
| 1522 | header.mi_cols as usize, | 1537 | header.mi_cols as usize, |
| 1523 | - snap.prev_seg_map.as_deref(), fctx, | 1538 | + snap.prev_seg_map.as_deref(), |
| 1539 | + fctx, | ||
| 1524 | ); | 1540 | ); |
| 1525 | // lane-superres stage 2/3: `use_superres` adds/removes no per-block | 1541 | // lane-superres stage 2/3: `use_superres` adds/removes no per-block |
| 1526 | // symbol (spec 7.16's upscaling is a pixel-domain post-process | 1542 | // symbol (spec 7.16's upscaling is a pixel-domain post-process |
| @@ -1833,8 +1849,13 @@ fn decode_frame( | |||
| 1833 | // the LR unit grid in upscaled coordinates. Cleared (0, 8) on an | 1849 | // the LR unit grid in upscaled coordinates. Cleared (0, 8) on an |
| 1834 | // unscaled frame so a later frame never inherits it. | 1850 | // unscaled frame so a later frame never inherits it. |
| 1835 | crate::decode::set_superres( | 1851 | crate::decode::set_superres( |
| 1836 | - if header.use_superres { header.upscaled_width } else { 0 }, | 1852 | + if header.use_superres { |
| 1837 | - u32::from(header.superres_denom), fctx, | 1853 | + header.upscaled_width |
| 1854 | + } else { | ||
| 1855 | + 0 | ||
| 1856 | + }, | ||
| 1857 | + u32::from(header.superres_denom), | ||
| 1858 | + fctx, | ||
| 1838 | ); | 1859 | ); |
| 1839 | // lane-av1comp: `comp_group_idx`/`compound_idx`'s own gating bits. | 1860 | // lane-av1comp: `comp_group_idx`/`compound_idx`'s own gating bits. |
| 1840 | let enable_masked_compound = seq.enable_masked_compound; | 1861 | let enable_masked_compound = seq.enable_masked_compound; |
| @@ -1942,7 +1963,8 @@ fn decode_frame( | |||
| 1942 | header.reduced_tx_set, | 1963 | header.reduced_tx_set, |
| 1943 | header.allow_screen_content_tools, | 1964 | header.allow_screen_content_tools, |
| 1944 | header.allow_intrabc, | 1965 | header.allow_intrabc, |
| 1945 | - header.delta, fctx, | 1966 | + header.delta, |
| 1967 | + fctx, | ||
| 1946 | )?; | 1968 | )?; |
| 1947 | // A key frame codes no inter blocks -- its own saved motion | 1969 | // A key frame codes no inter blocks -- its own saved motion |
| 1948 | // field has no cells set, matching libaom's own "intra frame | 1970 | // field has no cells set, matching libaom's own "intra frame |
| @@ -2219,9 +2241,8 @@ pub(crate) mod tests { | |||
| 2219 | crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap(); | 2241 | crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap(); |
| 2220 | seq.seq_profile = profile; | 2242 | seq.seq_profile = profile; |
| 2221 | let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap(); | 2243 | let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap(); |
| 2222 | - stream.extend_from_slice( | 2244 | + stream |
| 2223 | - &crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap(), | 2245 | + .extend_from_slice(&crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap()); |
| 2224 | - ); | ||
| 2225 | let err = decode_stream(&stream).unwrap_err().to_string(); | 2246 | let err = decode_stream(&stream).unwrap_err().to_string(); |
| 2226 | assert!( | 2247 | assert!( |
| 2227 | err.contains(REFUSAL), | 2248 | err.contains(REFUSAL), |
| @@ -2233,7 +2254,11 @@ pub(crate) mod tests { | |||
| 2233 | let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap(); | 2254 | let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap(); |
| 2234 | stream.extend_from_slice(&crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap()); | 2255 | stream.extend_from_slice(&crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap()); |
| 2235 | let frames = decode_stream(&stream).expect("the 4:2:0 control must decode"); | 2256 | let frames = decode_stream(&stream).expect("the 4:2:0 control must decode"); |
| 2236 | - assert_eq!(frames.len(), 1, "{NAME}: the 4:2:0 control decoded no frame"); | 2257 | + assert_eq!( |
| 2258 | + frames.len(), | ||
| 2259 | + 1, | ||
| 2260 | + "{NAME}: the 4:2:0 control decoded no frame" | ||
| 2261 | + ); | ||
| 2237 | } | 2262 | } |
| 2238 | /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned | 2263 | /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned |
| 2239 | /// as fixtures (`git add -f`; `fixtures/` is gitignored). | 2264 | /// as fixtures (`git add -f`; `fixtures/` is gitignored). |
| @@ -2291,6 +2316,193 @@ pub(crate) mod tests { | |||
| 2291 | } | 2316 | } |
| 2292 | } | 2317 | } |
| 2293 | 2318 | ||
| 2319 | + /// lane-av1-ibc128chunk: the WITNESS for the 128-root intrabc strip's | ||
| 2320 | + /// de-square-cut mu-chunk chroma walk, and the byte pin for it. | ||
| 2321 | + /// | ||
| 2322 | + /// `decode_intrabc_128rect` cut each mu chunk's chroma plane block with | ||
| 2323 | + /// `chunk_chroma = cside * 64 / side` -- a `chroma_side`-SQUARE chunk, | ||
| 2324 | + /// i.e. the 4:2:0 count on BOTH axes (the same defect lane-av1-422bigblock | ||
| 2325 | + /// fixed, and witnessed, in `decode_inter_block` and | ||
| 2326 | + /// `decode_block_128rect`; this copy was deferred there as unwitnessed). | ||
| 2327 | + /// At 4:2:2 a 64x64 mu chunk's chroma plane block is 32x64, so it holds | ||
| 2328 | + /// TWO STACKED TX_32X32 units per plane: the square-cut walk read one per | ||
| 2329 | + /// plane per chunk, left the chunk's lower 32 chroma rows with no | ||
| 2330 | + /// residual at all, and stamped each unit's entropy context over a | ||
| 2331 | + /// 16x16-mi luma span instead of 16x8. | ||
| 2332 | + /// | ||
| 2333 | + /// Measured red-before on the pinned witness (parent `a7d22aec`, via the | ||
| 2334 | + /// local `EC_AV1_ALLOW_422_PROBE` patch-run-restore build): 8 chroma | ||
| 2335 | + /// units stamped over the stream's two reached blocks and frames 0 and 3 | ||
| 2336 | + /// diverge from `aomdec` (45135 / 44540 of 245760 samples each), the | ||
| 2337 | + /// first difference at Y sample 98368 -- frame 0, row 256, col 64, the | ||
| 2338 | + /// top-left corner of the first 128x64 intrabc block at mi(64,0). The | ||
| 2339 | + /// red build then lost 4 of the stream's 6 intrabc blocks to the desync. | ||
| 2340 | + /// Green-after, same fixture: 48 chroma units stamped, all 6 blocks | ||
| 2341 | + /// decoded, and ALL FIVE frames byte-identical to `aomdec --rawvideo`. | ||
| 2342 | + /// | ||
| 2343 | + /// Committed code refuses 4:2:2 at the sequence header, so the decode | ||
| 2344 | + /// assertions above are probe-measured and reproducible from the lane | ||
| 2345 | + /// report's recipe; what this gate can assert in committed code is the | ||
| 2346 | + /// byte pin, the refusal-by-name contract, and -- in the arm below -- | ||
| 2347 | + /// that the per-axis walk is still spelled per-axis in the source. | ||
| 2348 | + #[test] | ||
| 2349 | + fn the_pinned_422_intrabc_sb128_strip_witnesses_refuse_by_name() { | ||
| 2350 | + const NAME: &str = "the_pinned_422_intrabc_sb128_strip_witnesses_refuse_by_name"; | ||
| 2351 | + const REFUSAL: &str = "a chroma format of 4:2:2"; | ||
| 2352 | + for (file, bytes, fp) in [ | ||
| 2353 | + ( | ||
| 2354 | + "422_intrabc_sb128_strip.obu", | ||
| 2355 | + 1672usize, | ||
| 2356 | + 0x50f5cfc576e4cd00_u64, | ||
| 2357 | + ), | ||
| 2358 | + ( | ||
| 2359 | + "422_intrabc_sb128_strip_notxsearch.obu", | ||
| 2360 | + 1675, | ||
| 2361 | + 0xd4936f252ff8cff0, | ||
| 2362 | + ), | ||
| 2363 | + ] { | ||
| 2364 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 2365 | + .join("fixtures") | ||
| 2366 | + .join(file); | ||
| 2367 | + let data = std::fs::read(&path).unwrap_or_else(|e| { | ||
| 2368 | + panic!( | ||
| 2369 | + "{NAME}: pinned witness {} is missing ({e}) -- the gate cannot run", | ||
| 2370 | + path.display() | ||
| 2371 | + ) | ||
| 2372 | + }); | ||
| 2373 | + assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted"); | ||
| 2374 | + assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted"); | ||
| 2375 | + let err = decode_stream(&data).unwrap_err().to_string(); | ||
| 2376 | + assert!( | ||
| 2377 | + err.contains(REFUSAL), | ||
| 2378 | + "{NAME}: {file} must refuse by name, got: {err}" | ||
| 2379 | + ); | ||
| 2380 | + } | ||
| 2381 | + } | ||
| 2382 | + | ||
| 2383 | + /// lane-av1-ibc128chunk: the SOURCE-SCAN arm of the witness gate above. | ||
| 2384 | + /// | ||
| 2385 | + /// The decode-level half of the red/green evidence cannot run in | ||
| 2386 | + /// committed code (the 4:2:2 refusal stands), so this arm pins the thing | ||
| 2387 | + /// that would silently bring the defect back: the square-cut | ||
| 2388 | + /// `chunk_chroma = cside * 64 / side` expression, and the per-axis | ||
| 2389 | + /// replacements that replaced it at BOTH sites in | ||
| 2390 | + /// [`decode_intrabc_128rect`] -- the mu-chunk read walk and the | ||
| 2391 | + /// `mu_chroma` per-unit context replay. It also pins the per-axis | ||
| 2392 | + /// counters' accessors so the arms stay reachable, and the walk's own | ||
| 2393 | + /// per-axis extent, derived here from the same `64 >> ss` form the | ||
| 2394 | + /// witnesses measured (4:2:0 = one TX_32X32 per plane per chunk, | ||
| 2395 | + /// 4:2:2 = two stacked, 4:4:4 = four). | ||
| 2396 | + #[test] | ||
| 2397 | + fn the_intrabc_128rect_chroma_chunk_walk_stays_per_axis() { | ||
| 2398 | + const NAME: &str = "the_intrabc_128rect_chroma_chunk_walk_stays_per_axis"; | ||
| 2399 | + let src = include_str!("decode.rs"); | ||
| 2400 | + let body = src | ||
| 2401 | + .split_once("fn decode_intrabc_128rect(") | ||
| 2402 | + .expect("decode_intrabc_128rect must exist") | ||
| 2403 | + .1 | ||
| 2404 | + .split_once("\nfn ") | ||
| 2405 | + .expect("decode_intrabc_128rect must be a top-level fn") | ||
| 2406 | + .0; | ||
| 2407 | + // Scan CODE only: the fix's own comments quote the old expression to | ||
| 2408 | + // say what it was, and a prose mention must not read as a | ||
| 2409 | + // reintroduction (nor mask one). | ||
| 2410 | + let stripped: Vec<&str> = body | ||
| 2411 | + .lines() | ||
| 2412 | + .map(|l| l.split_once("//").map_or(l, |(c, _)| c)) | ||
| 2413 | + .collect(); | ||
| 2414 | + let code = stripped.join("\n"); | ||
| 2415 | + let body = code.as_str(); | ||
| 2416 | + assert_eq!( | ||
| 2417 | + body.matches("cside * 64 / side").count(), | ||
| 2418 | + 0, | ||
| 2419 | + "{NAME}: the square-cut `cside * 64 / side` chunk extent is BACK in \ | ||
| 2420 | + decode_intrabc_128rect -- that expression is the 4:2:2 defect this \ | ||
| 2421 | + gate exists for (a 64x64 mu chunk's chroma plane block is \ | ||
| 2422 | + (64 >> ss_x) x (64 >> ss_y), not `chroma_side` square)" | ||
| 2423 | + ); | ||
| 2424 | + // The per-axis chunk extent, declared once at the mu-chunk read walk | ||
| 2425 | + // and once at the `mu_chroma` replay -- the two de-square-cut sites. | ||
| 2426 | + // | ||
| 2427 | + // The replay must ALSO enumerate every unit inside a chunk, not just | ||
| 2428 | + // its first: counting mu CHUNKS in `rows`/`cols` and then stepping the | ||
| 2429 | + // mi origin and reading the grid per UNIT only agrees when a chunk | ||
| 2430 | + // holds exactly one unit (4:2:0). At 4:2:2 and 4:4:4 a chunk holds two | ||
| 2431 | + // or four, so the per-unit body alone left the rest of the chunk with | ||
| 2432 | + // the composed-grid smearing the replay exists to undo. | ||
| 2433 | + for name in [ | ||
| 2434 | + "let chunk_chroma_w = (64usize) >> ss_x(fctx);", | ||
| 2435 | + "let chunk_chroma_h = (64usize) >> ss_y(fctx);", | ||
| 2436 | + ] { | ||
| 2437 | + assert_eq!( | ||
| 2438 | + body.matches(name).count(), | ||
| 2439 | + 2, | ||
| 2440 | + "{NAME}: `{name}` must appear at BOTH de-square-cut sites in \ | ||
| 2441 | + decode_intrabc_128rect (the mu-chunk read walk and the mu_chroma \ | ||
| 2442 | + context replay), found {}", | ||
| 2443 | + body.matches(name).count() | ||
| 2444 | + ); | ||
| 2445 | + } | ||
| 2446 | + for name in [ | ||
| 2447 | + "let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w / cu);", | ||
| 2448 | + "for kr in 0..ur {", | ||
| 2449 | + "for kc in 0..uc {", | ||
| 2450 | + ] { | ||
| 2451 | + assert_eq!( | ||
| 2452 | + body.matches(name).count(), | ||
| 2453 | + 1, | ||
| 2454 | + "{NAME}: `{name}` must appear exactly once in \ | ||
| 2455 | + decode_intrabc_128rect -- the mu_chroma replay must walk chunk \ | ||
| 2456 | + THEN unit (decode_inter_block's `mu_chroma_units` shape), found {}", | ||
| 2457 | + body.matches(name).count() | ||
| 2458 | + ); | ||
| 2459 | + } | ||
| 2460 | + for name in [ | ||
| 2461 | + "let unit_luma_w = cu_tx << ss_x(fctx);", | ||
| 2462 | + "let unit_luma_h = cu_tx << ss_y(fctx);", | ||
| 2463 | + "let (cw, ch) = (bw >> ss_x(fctx), bh >> ss_y(fctx));", | ||
| 2464 | + "let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));", | ||
| 2465 | + "neighbours.around_mi_rect(unit_mi, unit_luma_w, unit_luma_h)", | ||
| 2466 | + ] { | ||
| 2467 | + assert_eq!( | ||
| 2468 | + body.matches(name).count(), | ||
| 2469 | + 1, | ||
| 2470 | + "{NAME}: `{name}` must appear exactly once in \ | ||
| 2471 | + decode_intrabc_128rect, found {}", | ||
| 2472 | + body.matches(name).count() | ||
| 2473 | + ); | ||
| 2474 | + } | ||
| 2475 | + // The replay's own unit luma span is the lossless/lossy `cu << ss` form | ||
| 2476 | + // (site 2 spells it separately from the read walk's `cu_tx << ss`). | ||
| 2477 | + for name in [ | ||
| 2478 | + "let unit_luma_w = cu << ss_x(fctx);", | ||
| 2479 | + "let unit_luma_h = cu << ss_y(fctx);", | ||
| 2480 | + ] { | ||
| 2481 | + assert_eq!( | ||
| 2482 | + body.matches(name).count(), | ||
| 2483 | + 1, | ||
| 2484 | + "{NAME}: `{name}` must appear exactly once in \ | ||
| 2485 | + decode_intrabc_128rect, found {}", | ||
| 2486 | + body.matches(name).count() | ||
| 2487 | + ); | ||
| 2488 | + } | ||
| 2489 | + // The per-axis chunk extent the geometry demands, spelled out here so | ||
| 2490 | + // the scan and the witnesses cannot disagree about it. | ||
| 2491 | + let per_axis_units = |ss_x: u32, ss_y: u32| (64 >> ss_x) / 32 * (64 >> ss_y) / 32; | ||
| 2492 | + assert_eq!(per_axis_units(1, 1), 1, "{NAME}: 4:2:0 must stay one unit"); | ||
| 2493 | + assert_eq!(per_axis_units(1, 0), 2, "{NAME}: 4:2:2 must be two units"); | ||
| 2494 | + assert_eq!(per_axis_units(0, 0), 4, "{NAME}: 4:4:4 must be four units"); | ||
| 2495 | + // The counters the probe arms read must stay exported. | ||
| 2496 | + for name in [ | ||
| 2497 | + "pub fn intrabc_128rect_chroma_chunk_hits()", | ||
| 2498 | + "pub fn intrabc_128rect_chunk_shape()", | ||
| 2499 | + ] { | ||
| 2500 | + assert!( | ||
| 2501 | + src.contains(name), | ||
| 2502 | + "{NAME}: the accessor `{name}` must stay in decode.rs" | ||
| 2503 | + ); | ||
| 2504 | + } | ||
| 2505 | + } | ||
| 2294 | 2506 | ||
| 2295 | /// lane-av1-qmatrix: WITNESS for the lifted `using_qmatrix` refusal (the | 2507 | /// lane-av1-qmatrix: WITNESS for the lifted `using_qmatrix` refusal (the |
| 2296 | /// old gate `a_frame_using_quantisation_matrices_is_refused_by_name` is | 2508 | /// old gate `a_frame_using_quantisation_matrices_is_refused_by_name` is |
| @@ -2376,7 +2588,12 @@ pub(crate) mod tests { | |||
| 2376 | .collect(); | 2588 | .collect(); |
| 2377 | args.push(format!("--limit={FRAMES}")); | 2589 | args.push(format!("--limit={FRAMES}")); |
| 2378 | args.extend(extra.iter().map(|s| (*s).to_owned())); | 2590 | args.extend(extra.iter().map(|s| (*s).to_owned())); |
| 2379 | - args.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]); | 2591 | + args.extend([ |
| 2592 | + "--obu".to_owned(), | ||
| 2593 | + "-o".to_owned(), | ||
| 2594 | + "-".to_owned(), | ||
| 2595 | + "-".to_owned(), | ||
| 2596 | + ]); | ||
| 2380 | let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); | 2597 | let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); |
| 2381 | assert!( | 2598 | assert!( |
| 2382 | out.status.success(), | 2599 | out.status.success(), |
| @@ -2393,13 +2610,23 @@ pub(crate) mod tests { | |||
| 2393 | decode_stream(stream).unwrap_or_else(|e| panic!("{NAME}: {label} decode: {e}")); | 2610 | decode_stream(stream).unwrap_or_else(|e| panic!("{NAME}: {label} decode: {e}")); |
| 2394 | assert_eq!(got.len(), want.len(), "{NAME}: {label} frame count"); | 2611 | assert_eq!(got.len(), want.len(), "{NAME}: {label} frame count"); |
| 2395 | for (i, (g, w)) in got.iter().zip(want.iter()).enumerate() { | 2612 | for (i, (g, w)) in got.iter().zip(want.iter()).enumerate() { |
| 2396 | - for (plane, (gp, wp)) in | 2613 | + for (plane, (gp, wp)) in [(&g.y, &w.y), (&g.u, &w.u), (&g.v, &w.v)] |
| 2397 | - [(&g.y, &w.y), (&g.u, &w.u), (&g.v, &w.v)].into_iter().enumerate() | 2614 | + .into_iter() |
| 2615 | + .enumerate() | ||
| 2398 | { | 2616 | { |
| 2399 | - assert_eq!(gp, wp, | 2617 | + assert_eq!( |
| 2618 | + gp, | ||
| 2619 | + wp, | ||
| 2400 | "{NAME}: {label} frame {i} plane {plane} differs from ffmpeg (first mismatching sample: got {}, want {})", | 2620 | "{NAME}: {label} frame {i} plane {plane} differs from ffmpeg (first mismatching sample: got {}, want {})", |
| 2401 | - gp.iter().zip(wp.iter()).find(|(a, b)| a != b).map_or(0, |(a, _)| *a), | 2621 | + gp.iter() |
| 2402 | - gp.iter().zip(wp.iter()).find(|(a, b)| a != b).map_or(0, |(_, b)| *b)); | 2622 | + .zip(wp.iter()) |
| 2623 | + .find(|(a, b)| a != b) | ||
| 2624 | + .map_or(0, |(a, _)| *a), | ||
| 2625 | + gp.iter() | ||
| 2626 | + .zip(wp.iter()) | ||
| 2627 | + .find(|(a, b)| a != b) | ||
| 2628 | + .map_or(0, |(_, b)| *b) | ||
| 2629 | + ); | ||
| 2403 | } | 2630 | } |
| 2404 | } | 2631 | } |
| 2405 | }; | 2632 | }; |
| @@ -2417,7 +2644,10 @@ pub(crate) mod tests { | |||
| 2417 | "{NAME}: the qm-off control decoded no frame" | 2644 | "{NAME}: the qm-off control decoded no frame" |
| 2418 | ); | 2645 | ); |
| 2419 | for (using, y, u, v) in qm_headers(&control_stream) { | 2646 | for (using, y, u, v) in qm_headers(&control_stream) { |
| 2420 | - assert!(!using, "{NAME}: the control's frame header set using_qmatrix"); | 2647 | + assert!( |
| 2648 | + !using, | ||
| 2649 | + "{NAME}: the control's frame header set using_qmatrix" | ||
| 2650 | + ); | ||
| 2421 | assert_eq!( | 2651 | assert_eq!( |
| 2422 | (y, u, v), | 2652 | (y, u, v), |
| 2423 | (0, 0, 0), | 2653 | (0, 0, 0), |
| @@ -2636,8 +2866,7 @@ pub(crate) mod tests { | |||
| 2636 | #[test] | 2866 | #[test] |
| 2637 | fn a_frame_whose_segmentation_overrides_a_block_mode_is_refused_by_name() { | 2867 | fn a_frame_whose_segmentation_overrides_a_block_mode_is_refused_by_name() { |
| 2638 | let fctx = &crate::decode::FrameCtx::new(); | 2868 | let fctx = &crate::decode::FrameCtx::new(); |
| 2639 | - const REFUSAL: &str = | 2869 | + const REFUSAL: &str = "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV"; |
| 2640 | - "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV"; | ||
| 2641 | let picture = test_card(64, 64); | 2870 | let picture = test_card(64, 64); |
| 2642 | let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); | 2871 | let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); |
| 2643 | let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap(); | 2872 | let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap(); |
| @@ -2688,15 +2917,31 @@ pub(crate) mod tests { | |||
| 2688 | let src = format!("{source}=size={width}x{height}:rate=25"); | 2917 | let src = format!("{source}=size={width}x{height}:rate=25"); |
| 2689 | let y4m = Command::new("ffmpeg") | 2918 | let y4m = Command::new("ffmpeg") |
| 2690 | .args([ | 2919 | .args([ |
| 2691 | - "-v", "error", "-f", "lavfi", "-i", &src, "-t", &duration, "-pix_fmt", "yuv420p", | 2920 | + "-v", |
| 2692 | - "-strict", "-1", "-f", "yuv4mpegpipe", "-", | 2921 | + "error", |
| 2922 | + "-f", | ||
| 2923 | + "lavfi", | ||
| 2924 | + "-i", | ||
| 2925 | + &src, | ||
| 2926 | + "-t", | ||
| 2927 | + &duration, | ||
| 2928 | + "-pix_fmt", | ||
| 2929 | + "yuv420p", | ||
| 2930 | + "-strict", | ||
| 2931 | + "-1", | ||
| 2932 | + "-f", | ||
| 2933 | + "yuv4mpegpipe", | ||
| 2934 | + "-", | ||
| 2693 | ]) | 2935 | ]) |
| 2694 | .stdin(Stdio::null()) | 2936 | .stdin(Stdio::null()) |
| 2695 | .stdout(Stdio::piped()) | 2937 | .stdout(Stdio::piped()) |
| 2696 | .stderr(Stdio::piped()) | 2938 | .stderr(Stdio::piped()) |
| 2697 | .output() | 2939 | .output() |
| 2698 | .expect("ffmpeg failed to run"); | 2940 | .expect("ffmpeg failed to run"); |
| 2699 | - assert!(y4m.status.success(), "ffmpeg refused the {width}x{height} fixture"); | 2941 | + assert!( |
| 2942 | + y4m.status.success(), | ||
| 2943 | + "ffmpeg refused the {width}x{height} fixture" | ||
| 2944 | + ); | ||
| 2700 | let limit = format!("--limit={frames}"); | 2945 | let limit = format!("--limit={frames}"); |
| 2701 | let mut args: Vec<String> = [ | 2946 | let mut args: Vec<String> = [ |
| 2702 | "--codec=av1", | 2947 | "--codec=av1", |
| @@ -2712,10 +2957,18 @@ pub(crate) mod tests { | |||
| 2712 | .collect(); | 2957 | .collect(); |
| 2713 | args.push(limit); | 2958 | args.push(limit); |
| 2714 | args.extend(extra.iter().map(|s| (*s).to_owned())); | 2959 | args.extend(extra.iter().map(|s| (*s).to_owned())); |
| 2715 | - args.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]); | 2960 | + args.extend([ |
| 2716 | - let out = run_with_stdin(Command::new(aomenc_path()) | 2961 | + "--obu".to_owned(), |
| 2717 | - .args(&args), &y4m.stdout); | 2962 | + "-o".to_owned(), |
| 2718 | - assert!(out.status.success(), "aomenc refused {args:?}: {}", String::from_utf8_lossy(&out.stderr)); | 2963 | + "-".to_owned(), |
| 2964 | + "-".to_owned(), | ||
| 2965 | + ]); | ||
| 2966 | + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); | ||
| 2967 | + assert!( | ||
| 2968 | + out.status.success(), | ||
| 2969 | + "aomenc refused {args:?}: {}", | ||
| 2970 | + String::from_utf8_lossy(&out.stderr) | ||
| 2971 | + ); | ||
| 2719 | let stream = out.stdout; | 2972 | let stream = out.stdout; |
| 2720 | let result = match decode_stream(&stream) { | 2973 | let result = match decode_stream(&stream) { |
| 2721 | Ok(pictures) => Ok(pictures.len()), | 2974 | Ok(pictures) => Ok(pictures.len()), |
| @@ -2740,15 +2993,31 @@ pub(crate) mod tests { | |||
| 2740 | let src = format!("{source}=size={width}x{height}:rate=25"); | 2993 | let src = format!("{source}=size={width}x{height}:rate=25"); |
| 2741 | let y4m = Command::new("ffmpeg") | 2994 | let y4m = Command::new("ffmpeg") |
| 2742 | .args([ | 2995 | .args([ |
| 2743 | - "-v", "error", "-f", "lavfi", "-i", &src, "-t", &duration, "-pix_fmt", "yuv420p", | 2996 | + "-v", |
| 2744 | - "-strict", "-1", "-f", "yuv4mpegpipe", "-", | 2997 | + "error", |
| 2998 | + "-f", | ||
| 2999 | + "lavfi", | ||
| 3000 | + "-i", | ||
| 3001 | + &src, | ||
| 3002 | + "-t", | ||
| 3003 | + &duration, | ||
| 3004 | + "-pix_fmt", | ||
| 3005 | + "yuv420p", | ||
| 3006 | + "-strict", | ||
| 3007 | + "-1", | ||
| 3008 | + "-f", | ||
| 3009 | + "yuv4mpegpipe", | ||
| 3010 | + "-", | ||
| 2745 | ]) | 3011 | ]) |
| 2746 | .stdin(Stdio::null()) | 3012 | .stdin(Stdio::null()) |
| 2747 | .stdout(Stdio::piped()) | 3013 | .stdout(Stdio::piped()) |
| 2748 | .stderr(Stdio::piped()) | 3014 | .stderr(Stdio::piped()) |
| 2749 | .output() | 3015 | .output() |
| 2750 | .expect("ffmpeg failed to run"); | 3016 | .expect("ffmpeg failed to run"); |
| 2751 | - assert!(y4m.status.success(), "ffmpeg refused the {width}x{height} fixture"); | 3017 | + assert!( |
| 3018 | + y4m.status.success(), | ||
| 3019 | + "ffmpeg refused the {width}x{height} fixture" | ||
| 3020 | + ); | ||
| 2752 | let limit = format!("--limit={frames}"); | 3021 | let limit = format!("--limit={frames}"); |
| 2753 | let mut args: Vec<String> = [ | 3022 | let mut args: Vec<String> = [ |
| 2754 | "--codec=av1", | 3023 | "--codec=av1", |
| @@ -2764,9 +3033,18 @@ pub(crate) mod tests { | |||
| 2764 | .collect(); | 3033 | .collect(); |
| 2765 | args.push(limit); | 3034 | args.push(limit); |
| 2766 | args.extend(extra.iter().map(|s| (*s).to_owned())); | 3035 | args.extend(extra.iter().map(|s| (*s).to_owned())); |
| 2767 | - args.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]); | 3036 | + args.extend([ |
| 3037 | + "--obu".to_owned(), | ||
| 3038 | + "-o".to_owned(), | ||
| 3039 | + "-".to_owned(), | ||
| 3040 | + "-".to_owned(), | ||
| 3041 | + ]); | ||
| 2768 | let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); | 3042 | let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); |
| 2769 | - assert!(out.status.success(), "aomenc refused {args:?}: {}", String::from_utf8_lossy(&out.stderr)); | 3043 | + assert!( |
| 3044 | + out.status.success(), | ||
| 3045 | + "aomenc refused {args:?}: {}", | ||
| 3046 | + String::from_utf8_lossy(&out.stderr) | ||
| 3047 | + ); | ||
| 2770 | out.stdout | 3048 | out.stdout |
| 2771 | } | 3049 | } |
| 2772 | 3050 | ||
| @@ -2787,17 +3065,34 @@ pub(crate) mod tests { | |||
| 2787 | let src = format!("{source}=size={width}x{height}:rate=25"); | 3065 | let src = format!("{source}=size={width}x{height}:rate=25"); |
| 2788 | let y4m = Command::new("ffmpeg") | 3066 | let y4m = Command::new("ffmpeg") |
| 2789 | .args([ | 3067 | .args([ |
| 2790 | - "-v", "error", "-f", "lavfi", "-i", &src, "-t", &duration, "-pix_fmt", "yuv420p", | 3068 | + "-v", |
| 2791 | - "-strict", "-1", "-f", "yuv4mpegpipe", "-", | 3069 | + "error", |
| 3070 | + "-f", | ||
| 3071 | + "lavfi", | ||
| 3072 | + "-i", | ||
| 3073 | + &src, | ||
| 3074 | + "-t", | ||
| 3075 | + &duration, | ||
| 3076 | + "-pix_fmt", | ||
| 3077 | + "yuv420p", | ||
| 3078 | + "-strict", | ||
| 3079 | + "-1", | ||
| 3080 | + "-f", | ||
| 3081 | + "yuv4mpegpipe", | ||
| 3082 | + "-", | ||
| 2792 | ]) | 3083 | ]) |
| 2793 | .stdin(Stdio::null()) | 3084 | .stdin(Stdio::null()) |
| 2794 | .stdout(Stdio::piped()) | 3085 | .stdout(Stdio::piped()) |
| 2795 | .stderr(Stdio::piped()) | 3086 | .stderr(Stdio::piped()) |
| 2796 | .output() | 3087 | .output() |
| 2797 | .expect("ffmpeg failed to run"); | 3088 | .expect("ffmpeg failed to run"); |
| 2798 | - assert!(y4m.status.success(), "ffmpeg refused the {width}x{height} fixture"); | 3089 | + assert!( |
| 3090 | + y4m.status.success(), | ||
| 3091 | + "ffmpeg refused the {width}x{height} fixture" | ||
| 3092 | + ); | ||
| 2799 | let limit = format!("--limit={frames}"); | 3093 | let limit = format!("--limit={frames}"); |
| 2800 | - let fpf = std::env::temp_dir().join(format!("ec-av1-segldapass-{}.fpf", std::process::id())); | 3094 | + let fpf = |
| 3095 | + std::env::temp_dir().join(format!("ec-av1-segldapass-{}.fpf", std::process::id())); | ||
| 2801 | let mut base: Vec<String> = [ | 3096 | let mut base: Vec<String> = [ |
| 2802 | "--codec=av1", | 3097 | "--codec=av1", |
| 2803 | "--passes=2", | 3098 | "--passes=2", |
| @@ -2814,15 +3109,33 @@ pub(crate) mod tests { | |||
| 2814 | base.extend(extra.iter().map(|s| (*s).to_owned())); | 3109 | base.extend(extra.iter().map(|s| (*s).to_owned())); |
| 2815 | let mut pass1 = base.clone(); | 3110 | let mut pass1 = base.clone(); |
| 2816 | pass1.extend(["--pass=1".to_owned(), format!("--fpf={}", fpf.display())]); | 3111 | pass1.extend(["--pass=1".to_owned(), format!("--fpf={}", fpf.display())]); |
| 2817 | - pass1.extend(["--obu".to_owned(), "-o".to_owned(), "/dev/null".to_owned(), "-".to_owned()]); | 3112 | + pass1.extend([ |
| 3113 | + "--obu".to_owned(), | ||
| 3114 | + "-o".to_owned(), | ||
| 3115 | + "/dev/null".to_owned(), | ||
| 3116 | + "-".to_owned(), | ||
| 3117 | + ]); | ||
| 2818 | let out1 = run_with_stdin(Command::new(aomenc_path()).args(&pass1), &y4m.stdout); | 3118 | let out1 = run_with_stdin(Command::new(aomenc_path()).args(&pass1), &y4m.stdout); |
| 2819 | - assert!(out1.status.success(), "aomenc pass 1 refused {pass1:?}: {}", String::from_utf8_lossy(&out1.stderr)); | 3119 | + assert!( |
| 3120 | + out1.status.success(), | ||
| 3121 | + "aomenc pass 1 refused {pass1:?}: {}", | ||
| 3122 | + String::from_utf8_lossy(&out1.stderr) | ||
| 3123 | + ); | ||
| 2820 | let mut pass2 = base; | 3124 | let mut pass2 = base; |
| 2821 | pass2.extend(["--pass=2".to_owned(), format!("--fpf={}", fpf.display())]); | 3125 | pass2.extend(["--pass=2".to_owned(), format!("--fpf={}", fpf.display())]); |
| 2822 | - pass2.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]); | 3126 | + pass2.extend([ |
| 3127 | + "--obu".to_owned(), | ||
| 3128 | + "-o".to_owned(), | ||
| 3129 | + "-".to_owned(), | ||
| 3130 | + "-".to_owned(), | ||
| 3131 | + ]); | ||
| 2823 | let out2 = run_with_stdin(Command::new(aomenc_path()).args(&pass2), &y4m.stdout); | 3132 | let out2 = run_with_stdin(Command::new(aomenc_path()).args(&pass2), &y4m.stdout); |
| 2824 | let _ = std::fs::remove_file(&fpf); | 3133 | let _ = std::fs::remove_file(&fpf); |
| 2825 | - assert!(out2.status.success(), "aomenc pass 2 refused {pass2:?}: {}", String::from_utf8_lossy(&out2.stderr)); | 3134 | + assert!( |
| 3135 | + out2.status.success(), | ||
| 3136 | + "aomenc pass 2 refused {pass2:?}: {}", | ||
| 3137 | + String::from_utf8_lossy(&out2.stderr) | ||
| 3138 | + ); | ||
| 2826 | out2.stdout | 3139 | out2.stdout |
| 2827 | } | 3140 | } |
| 2828 | 3141 | ||
| @@ -2921,15 +3234,36 @@ pub(crate) mod tests { | |||
| 2921 | let arms: [(&str, &[&str]); 3] = [ | 3234 | let arms: [(&str, &[&str]); 3] = [ |
| 2922 | ( | 3235 | ( |
| 2923 | "testsrc2=size=256x192:rate=25", | 3236 | "testsrc2=size=256x192:rate=25", |
| 2924 | - &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=3", "--sb-size=64"], | 3237 | + &[ |
| 3238 | + "--end-usage=q", | ||
| 3239 | + "--cq-level=0", | ||
| 3240 | + "--aq-mode=1", | ||
| 3241 | + "--good", | ||
| 3242 | + "--cpu-used=3", | ||
| 3243 | + "--sb-size=64", | ||
| 3244 | + ], | ||
| 2925 | ), | 3245 | ), |
| 2926 | ( | 3246 | ( |
| 2927 | "testsrc2=size=256x192:rate=25", | 3247 | "testsrc2=size=256x192:rate=25", |
| 2928 | - &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=5", "--sb-size=64"], | 3248 | + &[ |
| 3249 | + "--end-usage=q", | ||
| 3250 | + "--cq-level=0", | ||
| 3251 | + "--aq-mode=1", | ||
| 3252 | + "--good", | ||
| 3253 | + "--cpu-used=5", | ||
| 3254 | + "--sb-size=64", | ||
| 3255 | + ], | ||
| 2929 | ), | 3256 | ), |
| 2930 | ( | 3257 | ( |
| 2931 | "gradients=size=256x192:rate=25", | 3258 | "gradients=size=256x192:rate=25", |
| 2932 | - &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=6", "--sb-size=64"], | 3259 | + &[ |
| 3260 | + "--end-usage=q", | ||
| 3261 | + "--cq-level=0", | ||
| 3262 | + "--aq-mode=1", | ||
| 3263 | + "--good", | ||
| 3264 | + "--cpu-used=6", | ||
| 3265 | + "--sb-size=64", | ||
| 3266 | + ], | ||
| 2933 | ), | 3267 | ), |
| 2934 | ]; | 3268 | ]; |
| 2935 | let mut mixed_arms = 0usize; | 3269 | let mut mixed_arms = 0usize; |
| @@ -2939,8 +3273,21 @@ pub(crate) mod tests { | |||
| 2939 | for (src, extra) in &arms { | 3273 | for (src, extra) in &arms { |
| 2940 | let y4m = Command::new("ffmpeg") | 3274 | let y4m = Command::new("ffmpeg") |
| 2941 | .args([ | 3275 | .args([ |
| 2942 | - "-v", "error", "-f", "lavfi", "-i", *src, "-t", "0.16", "-pix_fmt", | 3276 | + "-v", |
| 2943 | - "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", | 3277 | + "error", |
| 3278 | + "-f", | ||
| 3279 | + "lavfi", | ||
| 3280 | + "-i", | ||
| 3281 | + *src, | ||
| 3282 | + "-t", | ||
| 3283 | + "0.16", | ||
| 3284 | + "-pix_fmt", | ||
| 3285 | + "yuv420p", | ||
| 3286 | + "-strict", | ||
| 3287 | + "-1", | ||
| 3288 | + "-f", | ||
| 3289 | + "yuv4mpegpipe", | ||
| 3290 | + "-", | ||
| 2944 | ]) | 3291 | ]) |
| 2945 | .stdin(Stdio::null()) | 3292 | .stdin(Stdio::null()) |
| 2946 | .stdout(Stdio::piped()) | 3293 | .stdout(Stdio::piped()) |
| @@ -2949,14 +3296,21 @@ pub(crate) mod tests { | |||
| 2949 | .expect("ffmpeg failed to run"); | 3296 | .expect("ffmpeg failed to run"); |
| 2950 | assert!(y4m.status.success(), "{NAME}: ffmpeg failed for {src}"); | 3297 | assert!(y4m.status.success(), "{NAME}: ffmpeg failed for {src}"); |
| 2951 | let limit = format!("--limit={FRAMES}"); | 3298 | let limit = format!("--limit={FRAMES}"); |
| 2952 | - let mut args: Vec<String> = ["--codec=av1", "--passes=1", "--threads=1", "--obu", "-o", "-", "-"] | 3299 | + let mut args: Vec<String> = [ |
| 3300 | + "--codec=av1", | ||
| 3301 | + "--passes=1", | ||
| 3302 | + "--threads=1", | ||
| 3303 | + "--obu", | ||
| 3304 | + "-o", | ||
| 3305 | + "-", | ||
| 3306 | + "-", | ||
| 3307 | + ] | ||
| 2953 | .iter() | 3308 | .iter() |
| 2954 | .map(|s| (*s).to_owned()) | 3309 | .map(|s| (*s).to_owned()) |
| 2955 | .collect(); | 3310 | .collect(); |
| 2956 | args.insert(1, limit); | 3311 | args.insert(1, limit); |
| 2957 | args.extend(extra.iter().map(|s| (*s).to_owned())); | 3312 | args.extend(extra.iter().map(|s| (*s).to_owned())); |
| 2958 | - let out = run_with_stdin(Command::new(aomenc_path()) | 3313 | + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); |
| 2959 | - .args(&args), &y4m.stdout); | ||
| 2960 | assert!( | 3314 | assert!( |
| 2961 | out.status.success(), | 3315 | out.status.success(), |
| 2962 | "{NAME}: aomenc refused {args:?}: {}", | 3316 | "{NAME}: aomenc refused {args:?}: {}", |
| @@ -2986,8 +3340,9 @@ pub(crate) mod tests { | |||
| 2986 | // WHT-unit delta proves the per-segment lossless reconstruction | 3340 | // WHT-unit delta proves the per-segment lossless reconstruction |
| 2987 | // really ran inside a frame that is NOT `CodedLossless`. | 3341 | // really ran inside a frame that is NOT `CodedLossless`. |
| 2988 | let before = crate::decode::lossless_wht_units(); | 3342 | let before = crate::decode::lossless_wht_units(); |
| 2989 | - let ours = decode_stream(&stream) | 3343 | + let ours = decode_stream(&stream).unwrap_or_else(|e| { |
| 2990 | - .unwrap_or_else(|e| panic!("{NAME}: a mixed-lossless frame decodes after the per-segment lift: {e}")); | 3344 | + panic!("{NAME}: a mixed-lossless frame decodes after the per-segment lift: {e}") |
| 3345 | + }); | ||
| 2991 | let wht_units = crate::decode::lossless_wht_units() - before; | 3346 | let wht_units = crate::decode::lossless_wht_units() - before; |
| 2992 | let refs = ffmpeg_decode_sequence(&stream, WIDTH, HEIGHT, FRAMES); | 3347 | let refs = ffmpeg_decode_sequence(&stream, WIDTH, HEIGHT, FRAMES); |
| 2993 | assert_eq!(ours.len(), FRAMES, "{NAME}: frame count"); | 3348 | assert_eq!(ours.len(), FRAMES, "{NAME}: frame count"); |
| @@ -2997,10 +3352,16 @@ pub(crate) mod tests { | |||
| 2997 | .enumerate() | 3352 | .enumerate() |
| 2998 | { | 3353 | { |
| 2999 | let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); | 3354 | let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); |
| 3000 | - assert_eq!(bad, 0, "{NAME}: arm {extra:?} frame {i} plane {plane}: {bad} samples differ"); | 3355 | + assert_eq!( |
| 3356 | + bad, 0, | ||
| 3357 | + "{NAME}: arm {extra:?} frame {i} plane {plane}: {bad} samples differ" | ||
| 3358 | + ); | ||
| 3001 | } | 3359 | } |
| 3002 | } | 3360 | } |
| 3003 | - assert!(wht_units > 0, "{NAME}: arm {extra:?} reconstructed no Walsh-Hadamard unit -- the mixed census is lying or the lossless path never ran"); | 3361 | + assert!( |
| 3362 | + wht_units > 0, | ||
| 3363 | + "{NAME}: arm {extra:?} reconstructed no Walsh-Hadamard unit -- the mixed census is lying or the lossless path never ran" | ||
| 3364 | + ); | ||
| 3004 | mixed_arms += 1; | 3365 | mixed_arms += 1; |
| 3005 | eprintln!( | 3366 | eprintln!( |
| 3006 | "{NAME}: arm {extra:?}: {mixed} mixed frame(s), {FRAMES} frames sample-exact vs ffmpeg, {wht_units} WHT units" | 3367 | "{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 { | |||
| 3035 | eprintln!("SKIP a_segmentation_census_over_real_aq_streams: no aomenc"); | 3396 | eprintln!("SKIP a_segmentation_census_over_real_aq_streams: no aomenc"); |
| 3036 | return; | 3397 | return; |
| 3037 | } | 3398 | } |
| 3038 | - const REFUSAL: &str = | 3399 | + const REFUSAL: &str = "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV"; |
| 3039 | - "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV"; | ||
| 3040 | let recipes: [(&str, Vec<&str>); 6] = [ | 3400 | let recipes: [(&str, Vec<&str>); 6] = [ |
| 3041 | ("baseline", vec!["--cpu-used=4", "--cq-level=40"]), | 3401 | ("baseline", vec!["--cpu-used=4", "--cq-level=40"]), |
| 3042 | - ("aq-mode=1", vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=40"]), | 3402 | + ( |
| 3043 | - ("aq-mode=2", vec!["--cpu-used=4", "--aq-mode=2", "--cq-level=40"]), | 3403 | + "aq-mode=1", |
| 3044 | - ("aq-mode=3", vec!["--cpu-used=4", "--aq-mode=3", "--cq-level=40"]), | 3404 | + vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=40"], |
| 3045 | - ("aq-mode=3 cq10", vec!["--cpu-used=4", "--aq-mode=3", "--cq-level=10"]), | 3405 | + ), |
| 3046 | - ("deltaq-mode=1", vec!["--cpu-used=4", "--deltaq-mode=1", "--cq-level=40"]), | 3406 | + ( |
| 3407 | + "aq-mode=2", | ||
| 3408 | + vec!["--cpu-used=4", "--aq-mode=2", "--cq-level=40"], | ||
| 3409 | + ), | ||
| 3410 | + ( | ||
| 3411 | + "aq-mode=3", | ||
| 3412 | + vec!["--cpu-used=4", "--aq-mode=3", "--cq-level=40"], | ||
| 3413 | + ), | ||
| 3414 | + ( | ||
| 3415 | + "aq-mode=3 cq10", | ||
| 3416 | + vec!["--cpu-used=4", "--aq-mode=3", "--cq-level=10"], | ||
| 3417 | + ), | ||
| 3418 | + ( | ||
| 3419 | + "deltaq-mode=1", | ||
| 3420 | + vec!["--cpu-used=4", "--deltaq-mode=1", "--cq-level=40"], | ||
| 3421 | + ), | ||
| 3047 | ]; | 3422 | ]; |
| 3048 | // Arrival, not intent (class knob-never-reached-the-tool): a recipe | 3423 | // Arrival, not intent (class knob-never-reached-the-tool): a recipe |
| 3049 | // whose stream is byte-for-byte the baseline's changed nothing, and a | 3424 | // whose stream is byte-for-byte the baseline's changed nothing, and a |
| @@ -3090,7 +3465,11 @@ pub(crate) mod tests { | |||
| 3090 | "SEGCENSUS: {} recipes, {decoded} decoded, {refused} refused for other reasons", | 3465 | "SEGCENSUS: {} recipes, {decoded} decoded, {refused} refused for other reasons", |
| 3091 | recipes.len() | 3466 | recipes.len() |
| 3092 | ); | 3467 | ); |
| 3093 | - assert_eq!(decoded, recipes.len(), "every recipe must decode; {refused} refused"); | 3468 | + assert_eq!( |
| 3469 | + decoded, | ||
| 3470 | + recipes.len(), | ||
| 3471 | + "every recipe must decode; {refused} refused" | ||
| 3472 | + ); | ||
| 3094 | assert!( | 3473 | assert!( |
| 3095 | segment_symbols > 0, | 3474 | segment_symbols > 0, |
| 3096 | "no recipe coded a single segment_id symbol -- segmentation never arrived, so \ | 3475 | "no recipe coded a single segment_id symbol -- segmentation never arrived, so \ |
| @@ -3116,21 +3495,39 @@ pub(crate) mod tests { | |||
| 3116 | "mandelbrot", | 3495 | "mandelbrot", |
| 3117 | 192, | 3496 | 192, |
| 3118 | 128, | 3497 | 128, |
| 3119 | - vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=45", "--lag-in-frames=16", "--auto-alt-ref=1"], | 3498 | + vec![ |
| 3499 | + "--cpu-used=4", | ||
| 3500 | + "--aq-mode=1", | ||
| 3501 | + "--cq-level=45", | ||
| 3502 | + "--lag-in-frames=16", | ||
| 3503 | + "--auto-alt-ref=1", | ||
| 3504 | + ], | ||
| 3120 | ), | 3505 | ), |
| 3121 | ( | 3506 | ( |
| 3122 | "aq-mode=1 lag16 screen", | 3507 | "aq-mode=1 lag16 screen", |
| 3123 | "testsrc2", | 3508 | "testsrc2", |
| 3124 | 256, | 3509 | 256, |
| 3125 | 192, | 3510 | 192, |
| 3126 | - vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=45", "--lag-in-frames=16", "--auto-alt-ref=1"], | 3511 | + vec![ |
| 3512 | + "--cpu-used=4", | ||
| 3513 | + "--aq-mode=1", | ||
| 3514 | + "--cq-level=45", | ||
| 3515 | + "--lag-in-frames=16", | ||
| 3516 | + "--auto-alt-ref=1", | ||
| 3517 | + ], | ||
| 3127 | ), | 3518 | ), |
| 3128 | ( | 3519 | ( |
| 3129 | "aq-mode=1 lag16 cq63 high_q", | 3520 | "aq-mode=1 lag16 cq63 high_q", |
| 3130 | "mandelbrot", | 3521 | "mandelbrot", |
| 3131 | 192, | 3522 | 192, |
| 3132 | 128, | 3523 | 128, |
| 3133 | - vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=63", "--lag-in-frames=16", "--auto-alt-ref=1"], | 3524 | + vec![ |
| 3525 | + "--cpu-used=4", | ||
| 3526 | + "--aq-mode=1", | ||
| 3527 | + "--cq-level=63", | ||
| 3528 | + "--lag-in-frames=16", | ||
| 3529 | + "--auto-alt-ref=1", | ||
| 3530 | + ], | ||
| 3134 | ), | 3531 | ), |
| 3135 | // `--aq-mode=2 lag16` (complexity AQ over an alt-ref group) was | 3532 | // `--aq-mode=2 lag16` (complexity AQ over an alt-ref group) was |
| 3136 | // measured 2026-09-24: it encodes and decodes cleanly but codes | 3533 | // measured 2026-09-24: it encodes and decodes cleanly but codes |
| @@ -3167,7 +3564,13 @@ pub(crate) mod tests { | |||
| 3167 | 192, | 3564 | 192, |
| 3168 | 128, | 3565 | 128, |
| 3169 | 40, | 3566 | 40, |
| 3170 | - &["--cpu-used=4", "--aq-mode=1", "--cq-level=45", "--lag-in-frames=16", "--auto-alt-ref=1"], | 3567 | + &[ |
| 3568 | + "--cpu-used=4", | ||
| 3569 | + "--aq-mode=1", | ||
| 3570 | + "--cq-level=45", | ||
| 3571 | + "--lag-in-frames=16", | ||
| 3572 | + "--auto-alt-ref=1", | ||
| 3573 | + ], | ||
| 3171 | ); | 3574 | ); |
| 3172 | let (enabled, umap, inherited, alt_q, frames_per_feature) = | 3575 | let (enabled, umap, inherited, alt_q, frames_per_feature) = |
| 3173 | segmentation_feature_census(&stream); | 3576 | segmentation_feature_census(&stream); |
| @@ -3239,7 +3642,8 @@ pub(crate) mod tests { | |||
| 3239 | /// `SEG_LVL_ALT_Q`, and an inheritance-heavy shape). | 3642 | /// `SEG_LVL_ALT_Q`, and an inheritance-heavy shape). |
| 3240 | #[test] | 3643 | #[test] |
| 3241 | fn a_real_aomenc_segmentation_stream_with_map_inheritance_decodes_pixel_exact() { | 3644 | fn a_real_aomenc_segmentation_stream_with_map_inheritance_decodes_pixel_exact() { |
| 3242 | - const NAME: &str = "a_real_aomenc_segmentation_stream_with_map_inheritance_decodes_pixel_exact"; | 3645 | + const NAME: &str = |
| 3646 | + "a_real_aomenc_segmentation_stream_with_map_inheritance_decodes_pixel_exact"; | ||
| 3243 | if !have_aomenc() { | 3647 | if !have_aomenc() { |
| 3244 | eprintln!("SKIP {NAME}: no aomenc"); | 3648 | eprintln!("SKIP {NAME}: no aomenc"); |
| 3245 | return; | 3649 | return; |
| @@ -3350,8 +3754,18 @@ pub(crate) mod tests { | |||
| 3350 | "--enable-intrabc=0", | 3754 | "--enable-intrabc=0", |
| 3351 | ]; | 3755 | ]; |
| 3352 | let recipes: [(&str, usize, usize, Vec<&str>); 2] = [ | 3756 | let recipes: [(&str, usize, usize, Vec<&str>); 2] = [ |
| 3353 | - ("obmc dual cq40", 192, 128, [vec!["--cq-level=40"], base.clone()].concat()), | 3757 | + ( |
| 3354 | - ("obmc dual cq20", 192, 128, [vec!["--cq-level=20"], base.clone()].concat()), | 3758 | + "obmc dual cq40", |
| 3759 | + 192, | ||
| 3760 | + 128, | ||
| 3761 | + [vec!["--cq-level=40"], base.clone()].concat(), | ||
| 3762 | + ), | ||
| 3763 | + ( | ||
| 3764 | + "obmc dual cq20", | ||
| 3765 | + 192, | ||
| 3766 | + 128, | ||
| 3767 | + [vec!["--cq-level=20"], base.clone()].concat(), | ||
| 3768 | + ), | ||
| 3355 | ]; | 3769 | ]; |
| 3356 | let mut reads = 0usize; | 3770 | let mut reads = 0usize; |
| 3357 | let mut decoded = 0usize; | 3771 | let mut decoded = 0usize; |
| @@ -3372,7 +3786,9 @@ pub(crate) mod tests { | |||
| 3372 | } | 3786 | } |
| 3373 | Err(e) => { | 3787 | Err(e) => { |
| 3374 | assert!( | 3788 | assert!( |
| 3375 | - !e.contains("an OBMC neighbour whose switchable interp filter was never recorded"), | 3789 | + !e.contains( |
| 3790 | + "an OBMC neighbour whose switchable interp filter was never recorded" | ||
| 3791 | + ), | ||
| 3376 | "{name}: a real OBMC stream reached the unrecorded-filter refusal -- \ | 3792 | "{name}: a real OBMC stream reached the unrecorded-filter refusal -- \ |
| 3377 | a publication site is missing: {e}" | 3793 | a publication site is missing: {e}" |
| 3378 | ); | 3794 | ); |
| @@ -3380,7 +3796,10 @@ pub(crate) mod tests { | |||
| 3380 | } | 3796 | } |
| 3381 | } | 3797 | } |
| 3382 | } | 3798 | } |
| 3383 | - assert!(decoded > 0, "no OBMC recipe decoded -- the witness is vacuous"); | 3799 | + assert!( |
| 3800 | + decoded > 0, | ||
| 3801 | + "no OBMC recipe decoded -- the witness is vacuous" | ||
| 3802 | + ); | ||
| 3384 | assert!( | 3803 | assert!( |
| 3385 | reads > 0, | 3804 | reads > 0, |
| 3386 | "every OBMC blend took the fixed-filter path: the band was never read, so this \ | 3805 | "every OBMC blend took the fixed-filter path: the band was never read, so this \ |
| @@ -3417,12 +3836,62 @@ pub(crate) mod tests { | |||
| 3417 | "--enable-intrabc=0", | 3836 | "--enable-intrabc=0", |
| 3418 | ]; | 3837 | ]; |
| 3419 | let recipes: [(&str, usize, usize, Vec<&str>); 6] = [ | 3838 | let recipes: [(&str, usize, usize, Vec<&str>); 6] = [ |
| 3420 | - ("denom12 320x180 cq32", 320, 180, vec!["--cpu-used=4", "--superres-mode=1", "--superres-denominator=12", "--cq-level=32"]), | 3839 | + ( |
| 3421 | - ("denom12 320x180 cq50", 320, 180, vec!["--cpu-used=4", "--superres-mode=1", "--superres-denominator=12", "--cq-level=50"]), | 3840 | + "denom12 320x180 cq32", |
| 3422 | - ("denom16 320x180 cq32", 320, 180, vec!["--cpu-used=4", "--superres-mode=1", "--superres-denominator=16", "--cq-level=32"]), | 3841 | + 320, |
| 3423 | - ("denom10 192x128 cq32", 192, 128, vec!["--cpu-used=4", "--superres-mode=1", "--superres-denominator=10", "--cq-level=32"]), | 3842 | + 180, |
| 3424 | - ("auto 320x180 cq50", 320, 180, vec!["--cpu-used=4", "--superres-mode=3", "--cq-level=50"]), | 3843 | + vec![ |
| 3425 | - ("auto 192x128 cq50", 192, 128, vec!["--cpu-used=4", "--superres-mode=3", "--cq-level=50"]), | 3844 | + "--cpu-used=4", |
| 3845 | + "--superres-mode=1", | ||
| 3846 | + "--superres-denominator=12", | ||
| 3847 | + "--cq-level=32", | ||
| 3848 | + ], | ||
| 3849 | + ), | ||
| 3850 | + ( | ||
| 3851 | + "denom12 320x180 cq50", | ||
| 3852 | + 320, | ||
| 3853 | + 180, | ||
| 3854 | + vec![ | ||
| 3855 | + "--cpu-used=4", | ||
| 3856 | + "--superres-mode=1", | ||
| 3857 | + "--superres-denominator=12", | ||
| 3858 | + "--cq-level=50", | ||
| 3859 | + ], | ||
| 3860 | + ), | ||
| 3861 | + ( | ||
| 3862 | + "denom16 320x180 cq32", | ||
| 3863 | + 320, | ||
| 3864 | + 180, | ||
| 3865 | + vec![ | ||
| 3866 | + "--cpu-used=4", | ||
| 3867 | + "--superres-mode=1", | ||
| 3868 | + "--superres-denominator=16", | ||
| 3869 | + "--cq-level=32", | ||
| 3870 | + ], | ||
| 3871 | + ), | ||
| 3872 | + ( | ||
| 3873 | + "denom10 192x128 cq32", | ||
| 3874 | + 192, | ||
| 3875 | + 128, | ||
| 3876 | + vec![ | ||
| 3877 | + "--cpu-used=4", | ||
| 3878 | + "--superres-mode=1", | ||
| 3879 | + "--superres-denominator=10", | ||
| 3880 | + "--cq-level=32", | ||
| 3881 | + ], | ||
| 3882 | + ), | ||
| 3883 | + ( | ||
| 3884 | + "auto 320x180 cq50", | ||
| 3885 | + 320, | ||
| 3886 | + 180, | ||
| 3887 | + vec!["--cpu-used=4", "--superres-mode=3", "--cq-level=50"], | ||
| 3888 | + ), | ||
| 3889 | + ( | ||
| 3890 | + "auto 192x128 cq50", | ||
| 3891 | + 192, | ||
| 3892 | + 128, | ||
| 3893 | + vec!["--cpu-used=4", "--superres-mode=3", "--cq-level=50"], | ||
| 3894 | + ), | ||
| 3426 | ]; | 3895 | ]; |
| 3427 | let (mut decoded, mut warp, mut sub8, mut leaf8) = (0, 0, 0, 0); | 3896 | let (mut decoded, mut warp, mut sub8, mut leaf8) = (0, 0, 0, 0); |
| 3428 | // lane-t900 r36 (class [[gate-blind-to-feature]]): unknown refusal | 3897 | // lane-t900 r36 (class [[gate-blind-to-feature]]): unknown refusal |
| @@ -3475,7 +3944,10 @@ pub(crate) mod tests { | |||
| 3475 | // front of them: whichever partition path a scaled frame takes, the | 3944 | // front of them: whichever partition path a scaled frame takes, the |
| 3476 | // leaf guard is reached first. Lifting the leaf gap is what makes the | 3945 | // leaf guard is reached first. Lifting the leaf gap is what makes the |
| 3477 | // other two measurable, so this gate pins the ORDER, not just a count. | 3946 | // other two measurable, so this gate pins the ORDER, not just a count. |
| 3478 | - assert!(decoded > 0, "no superres recipe decoded -- the census is vacuous"); | 3947 | + assert!( |
| 3948 | + decoded > 0, | ||
| 3949 | + "no superres recipe decoded -- the census is vacuous" | ||
| 3950 | + ); | ||
| 3479 | // lane-t900 r28: all three scaled refusals are LIFTED, so the census | 3951 | // lane-t900 r28: all three scaled refusals are LIFTED, so the census |
| 3480 | // now pins the opposite shape -- every fixed-denominator recipe must | 3952 | // now pins the opposite shape -- every fixed-denominator recipe must |
| 3481 | // DECODE, and none of the three strings may come back. | 3953 | // DECODE, and none of the three strings may come back. |
| @@ -3484,7 +3956,10 @@ pub(crate) mod tests { | |||
| 3484 | (0, 0, 0), | 3956 | (0, 0, 0), |
| 3485 | "a scaled-reference refusal came back (warp {warp}, sub8 {sub8}, leaf8 {leaf8})" | 3957 | "a scaled-reference refusal came back (warp {warp}, sub8 {sub8}, leaf8 {leaf8})" |
| 3486 | ); | 3958 | ); |
| 3487 | - assert!(decoded > 0, "no superres recipe decoded -- the census is vacuous"); | 3959 | + assert!( |
| 3960 | + decoded > 0, | ||
| 3961 | + "no superres recipe decoded -- the census is vacuous" | ||
| 3962 | + ); | ||
| 3488 | } | 3963 | } |
| 3489 | 3964 | ||
| 3490 | /// lane-t900 r25, negative gate: a `show_existing_frame` header naming a | 3965 | /// lane-t900 r25, negative gate: a `show_existing_frame` header naming a |
| @@ -3536,7 +4011,10 @@ pub(crate) mod tests { | |||
| 3536 | err.contains(REFUSAL), | 4011 | err.contains(REFUSAL), |
| 3537 | "slot {slot}: expected {REFUSAL:?}, got: {err}" | 4012 | "slot {slot}: expected {REFUSAL:?}, got: {err}" |
| 3538 | ); | 4013 | ); |
| 3539 | - assert_eq!(shown, 0, "slot {slot}: an empty slot was output as a picture"); | 4014 | + assert_eq!( |
| 4015 | + shown, 0, | ||
| 4016 | + "slot {slot}: an empty slot was output as a picture" | ||
| 4017 | + ); | ||
| 3540 | } | 4018 | } |
| 3541 | } | 4019 | } |
| 3542 | 4020 | ||
| @@ -3581,7 +4059,10 @@ pub(crate) mod tests { | |||
| 3581 | .unwrap_err() | 4059 | .unwrap_err() |
| 3582 | .to_string(); | 4060 | .to_string(); |
| 3583 | assert!(err.contains(REFUSAL), "expected {REFUSAL:?}, got: {err}"); | 4061 | assert!(err.contains(REFUSAL), "expected {REFUSAL:?}, got: {err}"); |
| 3584 | - assert_eq!(shown, 0, "an inter frame with no reference produced a picture"); | 4062 | + assert_eq!( |
| 4063 | + shown, 0, | ||
| 4064 | + "an inter frame with no reference produced a picture" | ||
| 4065 | + ); | ||
| 3585 | } | 4066 | } |
| 3586 | 4067 | ||
| 3587 | /// lane-t900 r26, negative gate: an inter frame whose own coded size is | 4068 | /// lane-t900 r26, negative gate: an inter frame whose own coded size is |
| @@ -3630,7 +4111,10 @@ pub(crate) mod tests { | |||
| 3630 | .unwrap_err() | 4111 | .unwrap_err() |
| 3631 | .to_string(); | 4112 | .to_string(); |
| 3632 | assert!(err.contains(REFUSAL), "expected {REFUSAL:?}, got: {err}"); | 4113 | assert!(err.contains(REFUSAL), "expected {REFUSAL:?}, got: {err}"); |
| 3633 | - assert_eq!(shown, 1, "expected the key frame alone, got {shown} pictures"); | 4114 | + assert_eq!( |
| 4115 | + shown, 1, | ||
| 4116 | + "expected the key frame alone, got {shown} pictures" | ||
| 4117 | + ); | ||
| 3634 | } | 4118 | } |
| 3635 | 4119 | ||
| 3636 | /// lane-t900 r26, negative gate: an inter frame naming a | 4120 | /// lane-t900 r26, negative gate: an inter frame naming a |
| @@ -3708,8 +4192,14 @@ pub(crate) mod tests { | |||
| 3708 | }) | 4192 | }) |
| 3709 | .unwrap_err() | 4193 | .unwrap_err() |
| 3710 | .to_string(); | 4194 | .to_string(); |
| 3711 | - assert!(err.contains(REFUSAL), "slot {slot}: expected {REFUSAL:?}, got: {err}"); | 4195 | + assert!( |
| 3712 | - assert_eq!(shown, 0, "slot {slot}: a frame with no CDF state produced a picture"); | 4196 | + err.contains(REFUSAL), |
| 4197 | + "slot {slot}: expected {REFUSAL:?}, got: {err}" | ||
| 4198 | + ); | ||
| 4199 | + assert_eq!( | ||
| 4200 | + shown, 0, | ||
| 4201 | + "slot {slot}: a frame with no CDF state produced a picture" | ||
| 4202 | + ); | ||
| 3713 | } | 4203 | } |
| 3714 | } | 4204 | } |
| 3715 | 4205 | ||
| @@ -3756,7 +4246,9 @@ pub(crate) mod tests { | |||
| 3756 | continue; | 4246 | continue; |
| 3757 | }; | 4247 | }; |
| 3758 | let mut parser = Av1Parser::new(); | 4248 | let mut parser = Av1Parser::new(); |
| 3759 | - parser.parse_obu(&crate::sequence::sequence_header_obu(&seq).unwrap()).unwrap(); | 4249 | + parser |
| 4250 | + .parse_obu(&crate::sequence::sequence_header_obu(&seq).unwrap()) | ||
| 4251 | + .unwrap(); | ||
| 3760 | let obu = parser.parse_obu(&stream).unwrap(); | 4252 | let obu = parser.parse_obu(&stream).unwrap(); |
| 3761 | let ObuKind::Frame(parsed, _) = &obu.kind else { | 4253 | let ObuKind::Frame(parsed, _) = &obu.kind else { |
| 3762 | panic!("{w}x{h}: the written frame OBU did not parse as one"); | 4254 | panic!("{w}x{h}: the written frame OBU did not parse as one"); |
| @@ -3804,11 +4296,28 @@ pub(crate) mod tests { | |||
| 3804 | ) -> ([usize; 6], usize, usize) { | 4296 | ) -> ([usize; 6], usize, usize) { |
| 3805 | let duration = format!("{}", frames as f64 / 25.0); | 4297 | let duration = format!("{}", frames as f64 / 25.0); |
| 3806 | let source = format!("mandelbrot=size={width}x{height}:rate=25"); | 4298 | let source = format!("mandelbrot=size={width}x{height}:rate=25"); |
| 3807 | - let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | 4299 | + let pix_fmt = if bit_depth == 10 { |
| 4300 | + "yuv420p10le" | ||
| 4301 | + } else { | ||
| 4302 | + "yuv420p" | ||
| 4303 | + }; | ||
| 3808 | let y4m = Command::new("ffmpeg") | 4304 | let y4m = Command::new("ffmpeg") |
| 3809 | .args([ | 4305 | .args([ |
| 3810 | - "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration, "-pix_fmt", | 4306 | + "-v", |
| 3811 | - pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | 4307 | + "error", |
| 4308 | + "-f", | ||
| 4309 | + "lavfi", | ||
| 4310 | + "-i", | ||
| 4311 | + &source, | ||
| 4312 | + "-t", | ||
| 4313 | + &duration, | ||
| 4314 | + "-pix_fmt", | ||
| 4315 | + pix_fmt, | ||
| 4316 | + "-strict", | ||
| 4317 | + "-1", | ||
| 4318 | + "-f", | ||
| 4319 | + "yuv4mpegpipe", | ||
| 4320 | + "-", | ||
| 3812 | ]) | 4321 | ]) |
| 3813 | .stdin(Stdio::null()) | 4322 | .stdin(Stdio::null()) |
| 3814 | .stdout(Stdio::piped()) | 4323 | .stdout(Stdio::piped()) |
| @@ -3824,34 +4333,58 @@ pub(crate) mod tests { | |||
| 3824 | let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | 4333 | let input_depth_arg = format!("--input-bit-depth={bit_depth}"); |
| 3825 | let cq_arg = format!("--cq-level={cq}"); | 4334 | let cq_arg = format!("--cq-level={cq}"); |
| 3826 | let limit_arg = format!("--limit={frames}"); | 4335 | let limit_arg = format!("--limit={frames}"); |
| 3827 | - let out = run_with_stdin(Command::new(aomenc_path()) | 4336 | + let out = run_with_stdin( |
| 3828 | - .args([ | 4337 | + Command::new(aomenc_path()).args([ |
| 3829 | - "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, | 4338 | + "--codec=av1", |
| 4339 | + "--passes=1", | ||
| 4340 | + "--end-usage=q", | ||
| 4341 | + &cq_arg, | ||
| 3830 | // cpu-used >= 1 keeps libaom on 64x64 superblocks at these | 4342 | // cpu-used >= 1 keeps libaom on 64x64 superblocks at these |
| 3831 | // sizes (`av1_select_sb_size`). | 4343 | // sizes (`av1_select_sb_size`). |
| 3832 | - "--cpu-used=4", "--threads=1", "--row-mt=0", "--kf-max-dist=9999", | 4344 | + "--cpu-used=4", |
| 4345 | + "--threads=1", | ||
| 4346 | + "--row-mt=0", | ||
| 4347 | + "--kf-max-dist=9999", | ||
| 3833 | &limit_arg, | 4348 | &limit_arg, |
| 3834 | // decode order == display order, so the compare below covers | 4349 | // decode order == display order, so the compare below covers |
| 3835 | // every frame the stream carries (class gate-blind-to-hidden-frames). | 4350 | // every frame the stream carries (class gate-blind-to-hidden-frames). |
| 3836 | - "--lag-in-frames=0", &depth_arg, &input_depth_arg, | 4351 | + "--lag-in-frames=0", |
| 4352 | + &depth_arg, | ||
| 4353 | + &input_depth_arg, | ||
| 3837 | // Rect partitions stay ON: the frame-edge strip is a FORCED | 4354 | // Rect partitions stay ON: the frame-edge strip is a FORCED |
| 3838 | // (gathered) HORZ/VERT, but with rect coding off the encoder | 4355 | // (gathered) HORZ/VERT, but with rect coding off the encoder |
| 3839 | // answers that gathered symbol SPLIT every time and no edge | 4356 | // answers that gathered symbol SPLIT every time and no edge |
| 3840 | // strip ever fires (lane-oddh r2's finding, re-measured r1). | 4357 | // strip ever fires (lane-oddh r2's finding, re-measured r1). |
| 3841 | - "--enable-rect-partitions=1", "--enable-ab-partitions=0", | 4358 | + "--enable-rect-partitions=1", |
| 3842 | - "--enable-1to4-partitions=0", "--min-partition-size=8", | 4359 | + "--enable-ab-partitions=0", |
| 4360 | + "--enable-1to4-partitions=0", | ||
| 4361 | + "--min-partition-size=8", | ||
| 3843 | "--max-partition-size=64", | 4362 | "--max-partition-size=64", |
| 3844 | // Other lanes' open gaps this recipe must not trip. | 4363 | // Other lanes' open gaps this recipe must not trip. |
| 3845 | - "--enable-palette=0", "--enable-intrabc=0", "--enable-warped-motion=0", | 4364 | + "--enable-palette=0", |
| 3846 | - "--enable-obmc=0", "--enable-masked-comp=0", "--enable-interintra-comp=0", | 4365 | + "--enable-intrabc=0", |
| 3847 | - "--enable-onesided-comp=0", "--enable-interintra-wedge=0", | 4366 | + "--enable-warped-motion=0", |
| 3848 | - "--enable-smooth-interintra=0", "--enable-ref-frame-mvs=0", | 4367 | + "--enable-obmc=0", |
| 3849 | - "--enable-angle-delta=0", "--enable-cfl-intra=0", | 4368 | + "--enable-masked-comp=0", |
| 3850 | - "--enable-directional-intra=0", "--enable-smooth-intra=0", | 4369 | + "--enable-interintra-comp=0", |
| 3851 | - "--enable-paeth-intra=0", "--enable-filter-intra=0", | 4370 | + "--enable-onesided-comp=0", |
| 4371 | + "--enable-interintra-wedge=0", | ||
| 4372 | + "--enable-smooth-interintra=0", | ||
| 4373 | + "--enable-ref-frame-mvs=0", | ||
| 4374 | + "--enable-angle-delta=0", | ||
| 4375 | + "--enable-cfl-intra=0", | ||
| 4376 | + "--enable-directional-intra=0", | ||
| 4377 | + "--enable-smooth-intra=0", | ||
| 4378 | + "--enable-paeth-intra=0", | ||
| 4379 | + "--enable-filter-intra=0", | ||
| 3852 | "--enable-tx-size-search=0", | 4380 | "--enable-tx-size-search=0", |
| 3853 | - "--obu", "-o", "-", "-", | 4381 | + "--obu", |
| 3854 | - ]), &y4m.stdout); | 4382 | + "-o", |
| 4383 | + "-", | ||
| 4384 | + "-", | ||
| 4385 | + ]), | ||
| 4386 | + &y4m.stdout, | ||
| 4387 | + ); | ||
| 3855 | assert!( | 4388 | assert!( |
| 3856 | out.status.success(), | 4389 | out.status.success(), |
| 3857 | "aomenc refused: {}", | 4390 | "aomenc refused: {}", |
| @@ -4000,24 +4533,55 @@ pub(crate) mod tests { | |||
| 4000 | let (width, height) = (64usize, 72usize); | 4533 | let (width, height) = (64usize, 72usize); |
| 4001 | let y4m = Command::new("ffmpeg") | 4534 | let y4m = Command::new("ffmpeg") |
| 4002 | .args([ | 4535 | .args([ |
| 4003 | - "-v", "error", "-f", "lavfi", "-i", | 4536 | + "-v", |
| 4004 | - "mandelbrot=size=64x72:rate=25:start_x=-0.6:start_y=-0.4", "-t", "0.04", | 4537 | + "error", |
| 4005 | - "-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-", | 4538 | + "-f", |
| 4539 | + "lavfi", | ||
| 4540 | + "-i", | ||
| 4541 | + "mandelbrot=size=64x72:rate=25:start_x=-0.6:start_y=-0.4", | ||
| 4542 | + "-t", | ||
| 4543 | + "0.04", | ||
| 4544 | + "-pix_fmt", | ||
| 4545 | + "yuv420p", | ||
| 4546 | + "-f", | ||
| 4547 | + "yuv4mpegpipe", | ||
| 4548 | + "-", | ||
| 4006 | ]) | 4549 | ]) |
| 4007 | .stdin(Stdio::null()) | 4550 | .stdin(Stdio::null()) |
| 4008 | .stdout(Stdio::piped()) | 4551 | .stdout(Stdio::piped()) |
| 4009 | .stderr(Stdio::piped()) | 4552 | .stderr(Stdio::piped()) |
| 4010 | .output() | 4553 | .output() |
| 4011 | .expect("ffmpeg failed to run"); | 4554 | .expect("ffmpeg failed to run"); |
| 4012 | - assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); | 4555 | + assert!( |
| 4013 | - let out = run_with_stdin(Command::new(aomenc_path()) | 4556 | + y4m.status.success(), |
| 4014 | - .args([ | 4557 | + "ffmpeg fixture: {}", |
| 4015 | - "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", | 4558 | + String::from_utf8_lossy(&y4m.stderr) |
| 4016 | - "--cpu-used=0", "--sb-size=128", "--min-partition-size=16", | 4559 | + ); |
| 4017 | - "--kf-max-dist=0", "--limit=1", | 4560 | + let out = run_with_stdin( |
| 4018 | - "--threads=1", "--row-mt=0", "--obu", "-o", "-", "-", | 4561 | + Command::new(aomenc_path()).args([ |
| 4019 | - ]), &y4m.stdout); | 4562 | + "--codec=av1", |
| 4020 | - assert!(out.status.success(), "aomenc refused: {}", String::from_utf8_lossy(&out.stderr)); | 4563 | + "--passes=1", |
| 4564 | + "--end-usage=q", | ||
| 4565 | + "--cq-level=32", | ||
| 4566 | + "--cpu-used=0", | ||
| 4567 | + "--sb-size=128", | ||
| 4568 | + "--min-partition-size=16", | ||
| 4569 | + "--kf-max-dist=0", | ||
| 4570 | + "--limit=1", | ||
| 4571 | + "--threads=1", | ||
| 4572 | + "--row-mt=0", | ||
| 4573 | + "--obu", | ||
| 4574 | + "-o", | ||
| 4575 | + "-", | ||
| 4576 | + "-", | ||
| 4577 | + ]), | ||
| 4578 | + &y4m.stdout, | ||
| 4579 | + ); | ||
| 4580 | + assert!( | ||
| 4581 | + out.status.success(), | ||
| 4582 | + "aomenc refused: {}", | ||
| 4583 | + String::from_utf8_lossy(&out.stderr) | ||
| 4584 | + ); | ||
| 4021 | let stream = out.stdout; | 4585 | let stream = out.stdout; |
| 4022 | 4586 | ||
| 4023 | // The knob actually arrived: this stream's sequence header codes | 4587 | // The knob actually arrived: this stream's sequence header codes |
| @@ -4035,19 +4599,19 @@ pub(crate) mod tests { | |||
| 4035 | break; | 4599 | break; |
| 4036 | } | 4600 | } |
| 4037 | } | 4601 | } |
| 4038 | - assert!(sb128, "aomenc ignored --sb-size=128: this stream is 64x64-superblock"); | 4602 | + assert!( |
| 4603 | + sb128, | ||
| 4604 | + "aomenc ignored --sb-size=128: this stream is 64x64-superblock" | ||
| 4605 | + ); | ||
| 4039 | 4606 | ||
| 4040 | let _guard = lock_gate_counters(); | 4607 | let _guard = lock_gate_counters(); |
| 4041 | - let before = crate::decode::part128_symbols() | 4608 | + let before = crate::decode::part128_symbols() + crate::decode::part128_gathered_symbols(); |
| 4042 | - + crate::decode::part128_gathered_symbols(); | 4609 | + let (frames, hidden) = decode_all_frames_vs_oracle(&stream, "sb128-oddh-64x72"); |
| 4043 | - let (frames, hidden) = | ||
| 4044 | - decode_all_frames_vs_oracle(&stream, "sb128-oddh-64x72"); | ||
| 4045 | assert!(frames > 0, "no frames decoded for {width}x{height}"); | 4610 | assert!(frames > 0, "no frames decoded for {width}x{height}"); |
| 4046 | // The 128 root actually READ a partition symbol here: at mi_rows=18 | 4611 | // The 128 root actually READ a partition symbol here: at mi_rows=18 |
| 4047 | // `has_rows` is true, so BLOCK_128X128 is not a forced split. | 4612 | // `has_rows` is true, so BLOCK_128X128 is not a forced split. |
| 4048 | - let part128 = crate::decode::part128_symbols() | 4613 | + let part128 = |
| 4049 | - + crate::decode::part128_gathered_symbols() | 4614 | + crate::decode::part128_symbols() + crate::decode::part128_gathered_symbols() - before; |
| 4050 | - - before; | ||
| 4051 | assert!( | 4615 | assert!( |
| 4052 | part128 > 0, | 4616 | part128 > 0, |
| 4053 | "{width}x{height} decoded without reading a single BLOCK_128X128 \ | 4617 | "{width}x{height} decoded without reading a single BLOCK_128X128 \ |
| @@ -4099,7 +4663,8 @@ pub(crate) mod tests { | |||
| 4099 | encoded.screen, | 4663 | encoded.screen, |
| 4100 | // ... and its own `allow_intrabc` (stale-header class). | 4664 | // ... and its own `allow_intrabc` (stale-header class). |
| 4101 | encoded.allow_intrabc, | 4665 | encoded.allow_intrabc, |
| 4102 | - &encoded.loop_restoration, fctx, | 4666 | + &encoded.loop_restoration, |
| 4667 | + fctx, | ||
| 4103 | ) | 4668 | ) |
| 4104 | .unwrap(); | 4669 | .unwrap(); |
| 4105 | let via_stream = decode_stream(&encoded.stream).unwrap(); | 4670 | let via_stream = decode_stream(&encoded.stream).unwrap(); |
| @@ -4164,7 +4729,9 @@ pub(crate) mod tests { | |||
| 4164 | fn streaming_decode_matches_the_collecting_one() { | 4729 | fn streaming_decode_matches_the_collecting_one() { |
| 4165 | let fctx = &crate::decode::FrameCtx::for_encoder(); | 4730 | let fctx = &crate::decode::FrameCtx::for_encoder(); |
| 4166 | let pictures: Vec<_> = (0..4).map(|i| panned_test_card(128, 64, i * 3)).collect(); | 4731 | let pictures: Vec<_> = (0..4).map(|i| panned_test_card(128, 64, i * 3)).collect(); |
| 4167 | - let stream = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap().stream; | 4732 | + let stream = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx) |
| 4733 | + .unwrap() | ||
| 4734 | + .stream; | ||
| 4168 | let collected = decode_stream(&stream).unwrap(); | 4735 | let collected = decode_stream(&stream).unwrap(); |
| 4169 | 4736 | ||
| 4170 | let mut shown = Vec::new(); | 4737 | let mut shown = Vec::new(); |
| @@ -4179,8 +4746,15 @@ pub(crate) mod tests { | |||
| 4179 | Ok(()) | 4746 | Ok(()) |
| 4180 | }) | 4747 | }) |
| 4181 | .unwrap(); | 4748 | .unwrap(); |
| 4182 | - assert_eq!(shown.len(), collected.len(), "callback count vs shown frames"); | 4749 | + assert_eq!( |
| 4183 | - assert!(live >= shown.len(), "every shown picture is also a callback"); | 4750 | + shown.len(), |
| 4751 | + collected.len(), | ||
| 4752 | + "callback count vs shown frames" | ||
| 4753 | + ); | ||
| 4754 | + assert!( | ||
| 4755 | + live >= shown.len(), | ||
| 4756 | + "every shown picture is also a callback" | ||
| 4757 | + ); | ||
| 4184 | assert!( | 4758 | assert!( |
| 4185 | idxs.windows(2).all(|w| w[0] <= w[1]), | 4759 | idxs.windows(2).all(|w| w[0] <= w[1]), |
| 4186 | "decode indices out of order: {idxs:?}" | 4760 | "decode indices out of order: {idxs:?}" |
| @@ -4301,9 +4875,18 @@ pub(crate) mod tests { | |||
| 4301 | Pic { | 4875 | Pic { |
| 4302 | width, | 4876 | width, |
| 4303 | height, | 4877 | height, |
| 4304 | - y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), | 4878 | + y: out.stdout[base..base + luma] |
| 4305 | - u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), | 4879 | + .iter() |
| 4306 | - v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), | 4880 | + .map(|&v| u16::from(v)) |
| 4881 | + .collect(), | ||
| 4882 | + u: out.stdout[base + luma..base + luma + chroma] | ||
| 4883 | + .iter() | ||
| 4884 | + .map(|&v| u16::from(v)) | ||
| 4885 | + .collect(), | ||
| 4886 | + v: out.stdout[base + luma + chroma..base + frame_bytes] | ||
| 4887 | + .iter() | ||
| 4888 | + .map(|&v| u16::from(v)) | ||
| 4889 | + .collect(), | ||
| 4307 | } | 4890 | } |
| 4308 | }) | 4891 | }) |
| 4309 | .collect() | 4892 | .collect() |
| @@ -4352,8 +4935,17 @@ pub(crate) mod tests { | |||
| 4352 | ) -> Vec<Pic> { | 4935 | ) -> Vec<Pic> { |
| 4353 | let out = run_with_stdin( | 4936 | let out = run_with_stdin( |
| 4354 | Command::new("ffmpeg").args([ | 4937 | Command::new("ffmpeg").args([ |
| 4355 | - "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", | 4938 | + "-v", |
| 4356 | - "yuv420p10le", "-", | 4939 | + "error", |
| 4940 | + "-f", | ||
| 4941 | + "obu", | ||
| 4942 | + "-i", | ||
| 4943 | + "-", | ||
| 4944 | + "-f", | ||
| 4945 | + "rawvideo", | ||
| 4946 | + "-pix_fmt", | ||
| 4947 | + "yuv420p10le", | ||
| 4948 | + "-", | ||
| 4357 | ]), | 4949 | ]), |
| 4358 | stream, | 4950 | stream, |
| 4359 | ); | 4951 | ); |
| @@ -4419,10 +5011,27 @@ pub(crate) mod tests { | |||
| 4419 | let (width, height) = (384usize, 152usize); | 5011 | let (width, height) = (384usize, 152usize); |
| 4420 | let out = Command::new("ffmpeg") | 5012 | let out = Command::new("ffmpeg") |
| 4421 | .args([ | 5013 | .args([ |
| 4422 | - "-v", "error", "-f", "lavfi", "-i", | 5014 | + "-v", |
| 5015 | + "error", | ||
| 5016 | + "-f", | ||
| 5017 | + "lavfi", | ||
| 5018 | + "-i", | ||
| 4423 | "smptebars=s=384x152:r=12,drawgrid=w=8:h=8:t=1:c=black", | 5019 | "smptebars=s=384x152:r=12,drawgrid=w=8:h=8:t=1:c=black", |
| 4424 | - "-frames:v", "4", "-c:v", "libsvtav1", "-preset", "8", "-crf", "30", | 5020 | + "-frames:v", |
| 4425 | - "-svtav1-params", "lp=1:screen-content-mode=1", "-g", "12", "-f", "obu", "-", | 5021 | + "4", |
| 5022 | + "-c:v", | ||
| 5023 | + "libsvtav1", | ||
| 5024 | + "-preset", | ||
| 5025 | + "8", | ||
| 5026 | + "-crf", | ||
| 5027 | + "30", | ||
| 5028 | + "-svtav1-params", | ||
| 5029 | + "lp=1:screen-content-mode=1", | ||
| 5030 | + "-g", | ||
| 5031 | + "12", | ||
| 5032 | + "-f", | ||
| 5033 | + "obu", | ||
| 5034 | + "-", | ||
| 4426 | ]) | 5035 | ]) |
| 4427 | .stdin(Stdio::null()) | 5036 | .stdin(Stdio::null()) |
| 4428 | .stdout(Stdio::piped()) | 5037 | .stdout(Stdio::piped()) |
| @@ -4539,9 +5148,18 @@ pub(crate) mod tests { | |||
| 4539 | // decoder-side one. | 5148 | // decoder-side one. |
| 4540 | for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() { | 5149 | for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() { |
| 4541 | let rec = &frame.reconstruction; | 5150 | let rec = &frame.reconstruction; |
| 4542 | - assert_eq!(rec.y, want.y, "{width}x{height} frame {i} luma: reconstruction vs ffmpeg"); | 5151 | + assert_eq!( |
| 4543 | - assert_eq!(rec.u, want.u, "{width}x{height} frame {i} U: reconstruction vs ffmpeg"); | 5152 | + rec.y, want.y, |
| 4544 | - assert_eq!(rec.v, want.v, "{width}x{height} frame {i} V: reconstruction vs ffmpeg"); | 5153 | + "{width}x{height} frame {i} luma: reconstruction vs ffmpeg" |
| 5154 | + ); | ||
| 5155 | + assert_eq!( | ||
| 5156 | + rec.u, want.u, | ||
| 5157 | + "{width}x{height} frame {i} U: reconstruction vs ffmpeg" | ||
| 5158 | + ); | ||
| 5159 | + assert_eq!( | ||
| 5160 | + rec.v, want.v, | ||
| 5161 | + "{width}x{height} frame {i} V: reconstruction vs ffmpeg" | ||
| 5162 | + ); | ||
| 4545 | } | 5163 | } |
| 4546 | } | 5164 | } |
| 4547 | } | 5165 | } |
| @@ -4567,7 +5185,9 @@ pub(crate) mod tests { | |||
| 4567 | fn a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg() { | 5185 | fn a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg() { |
| 4568 | let fctx = &crate::decode::FrameCtx::for_encoder(); | 5186 | let fctx = &crate::decode::FrameCtx::for_encoder(); |
| 4569 | if !have_ffmpeg() { | 5187 | if !have_ffmpeg() { |
| 4570 | - eprintln!("SKIP a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg: no ffmpeg"); | 5188 | + eprintln!( |
| 5189 | + "SKIP a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg: no ffmpeg" | ||
| 5190 | + ); | ||
| 4571 | return; | 5191 | return; |
| 4572 | } | 5192 | } |
| 4573 | const FRAMES: usize = 4; | 5193 | const FRAMES: usize = 4; |
| @@ -4600,9 +5220,18 @@ pub(crate) mod tests { | |||
| 4600 | } | 5220 | } |
| 4601 | for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() { | 5221 | for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() { |
| 4602 | let rec = &frame.reconstruction; | 5222 | let rec = &frame.reconstruction; |
| 4603 | - assert_eq!(rec.y, want.y, "{width}x{height} frame {i} luma: recon vs ffmpeg"); | 5223 | + assert_eq!( |
| 4604 | - assert_eq!(rec.u, want.u, "{width}x{height} frame {i} U: recon vs ffmpeg"); | 5224 | + rec.y, want.y, |
| 4605 | - assert_eq!(rec.v, want.v, "{width}x{height} frame {i} V: recon vs ffmpeg"); | 5225 | + "{width}x{height} frame {i} luma: recon vs ffmpeg" |
| 5226 | + ); | ||
| 5227 | + assert_eq!( | ||
| 5228 | + rec.u, want.u, | ||
| 5229 | + "{width}x{height} frame {i} U: recon vs ffmpeg" | ||
| 5230 | + ); | ||
| 5231 | + assert_eq!( | ||
| 5232 | + rec.v, want.v, | ||
| 5233 | + "{width}x{height} frame {i} V: recon vs ffmpeg" | ||
| 5234 | + ); | ||
| 4606 | } | 5235 | } |
| 4607 | } | 5236 | } |
| 4608 | } | 5237 | } |
| @@ -4660,18 +5289,40 @@ pub(crate) mod tests { | |||
| 4660 | let decoded = decode_stream(&encoded.stream) | 5289 | let decoded = decode_stream(&encoded.stream) |
| 4661 | .unwrap_or_else(|e| panic!("{width}x{height}: our decoder refused: {e}")); | 5290 | .unwrap_or_else(|e| panic!("{width}x{height}: our decoder refused: {e}")); |
| 4662 | let ffmpeg_frames = ffmpeg_decode_sequence(&encoded.stream, width, height, FRAMES); | 5291 | let ffmpeg_frames = ffmpeg_decode_sequence(&encoded.stream, width, height, FRAMES); |
| 4663 | - assert_eq!(ffmpeg_frames.len(), FRAMES, "{width}x{height}: ffmpeg frame count"); | 5292 | + assert_eq!( |
| 5293 | + ffmpeg_frames.len(), | ||
| 5294 | + FRAMES, | ||
| 5295 | + "{width}x{height}: ffmpeg frame count" | ||
| 5296 | + ); | ||
| 4664 | assert_eq!(decoded.len(), FRAMES, "{width}x{height}: frame count"); | 5297 | assert_eq!(decoded.len(), FRAMES, "{width}x{height}: frame count"); |
| 4665 | for (i, (got, want)) in decoded.iter().zip(&ffmpeg_frames).enumerate() { | 5298 | for (i, (got, want)) in decoded.iter().zip(&ffmpeg_frames).enumerate() { |
| 4666 | - assert_eq!(got.y, want.y, "{width}x{height} frame {i} luma: ours vs ffmpeg"); | 5299 | + assert_eq!( |
| 4667 | - assert_eq!(got.u, want.u, "{width}x{height} frame {i} U: ours vs ffmpeg"); | 5300 | + got.y, want.y, |
| 4668 | - assert_eq!(got.v, want.v, "{width}x{height} frame {i} V: ours vs ffmpeg"); | 5301 | + "{width}x{height} frame {i} luma: ours vs ffmpeg" |
| 5302 | + ); | ||
| 5303 | + assert_eq!( | ||
| 5304 | + got.u, want.u, | ||
| 5305 | + "{width}x{height} frame {i} U: ours vs ffmpeg" | ||
| 5306 | + ); | ||
| 5307 | + assert_eq!( | ||
| 5308 | + got.v, want.v, | ||
| 5309 | + "{width}x{height} frame {i} V: ours vs ffmpeg" | ||
| 5310 | + ); | ||
| 4669 | } | 5311 | } |
| 4670 | for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() { | 5312 | for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() { |
| 4671 | let rec = &frame.reconstruction; | 5313 | let rec = &frame.reconstruction; |
| 4672 | - assert_eq!(rec.y, want.y, "{width}x{height} frame {i} luma: recon vs ffmpeg"); | 5314 | + assert_eq!( |
| 4673 | - assert_eq!(rec.u, want.u, "{width}x{height} frame {i} U: recon vs ffmpeg"); | 5315 | + rec.y, want.y, |
| 4674 | - assert_eq!(rec.v, want.v, "{width}x{height} frame {i} V: recon vs ffmpeg"); | 5316 | + "{width}x{height} frame {i} luma: recon vs ffmpeg" |
| 5317 | + ); | ||
| 5318 | + assert_eq!( | ||
| 5319 | + rec.u, want.u, | ||
| 5320 | + "{width}x{height} frame {i} U: recon vs ffmpeg" | ||
| 5321 | + ); | ||
| 5322 | + assert_eq!( | ||
| 5323 | + rec.v, want.v, | ||
| 5324 | + "{width}x{height} frame {i} V: recon vs ffmpeg" | ||
| 5325 | + ); | ||
| 4675 | } | 5326 | } |
| 4676 | } | 5327 | } |
| 4677 | } | 5328 | } |
| @@ -4855,7 +5506,9 @@ pub(crate) mod tests { | |||
| 4855 | hash_color(seed, 2), | 5506 | hash_color(seed, 2), |
| 4856 | hash_color(seed, 3), | 5507 | hash_color(seed, 3), |
| 4857 | ); | 5508 | ); |
| 4858 | - format!("gradients=size={width}x{height}:c0={c0}:c1={c1}:c2={c2}:c3={c3}:seed={seed}:{tail}") | 5509 | + format!( |
| 5510 | + "gradients=size={width}x{height}:c0={c0}:c1={c1}:c2={c2}:c3={c3}:seed={seed}:{tail}" | ||
| 5511 | + ) | ||
| 4859 | } | 5512 | } |
| 4860 | 5513 | ||
| 4861 | /// The determinism guard: same seed twice must byte-match ffmpeg's own | 5514 | /// The determinism guard: same seed twice must byte-match ffmpeg's own |
| @@ -4870,7 +5523,16 @@ pub(crate) mod tests { | |||
| 4870 | fn render_hash(lavfi: &str) -> Vec<u8> { | 5523 | fn render_hash(lavfi: &str) -> Vec<u8> { |
| 4871 | let out = Command::new("ffmpeg") | 5524 | let out = Command::new("ffmpeg") |
| 4872 | .args([ | 5525 | .args([ |
| 4873 | - "-v", "error", "-f", "lavfi", "-i", lavfi, "-frames:v", "1", "-f", "rawvideo", | 5526 | + "-v", |
| 5527 | + "error", | ||
| 5528 | + "-f", | ||
| 5529 | + "lavfi", | ||
| 5530 | + "-i", | ||
| 5531 | + lavfi, | ||
| 5532 | + "-frames:v", | ||
| 5533 | + "1", | ||
| 5534 | + "-f", | ||
| 5535 | + "rawvideo", | ||
| 4874 | "-", | 5536 | "-", |
| 4875 | ]) | 5537 | ]) |
| 4876 | .stdin(Stdio::null()) | 5538 | .stdin(Stdio::null()) |
| @@ -5088,7 +5750,17 @@ pub(crate) mod tests { | |||
| 5088 | .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) | 5750 | .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) |
| 5089 | .arg(&src) | 5751 | .arg(&src) |
| 5090 | .args(["-an", "-threads", "1", "-g", "16", "-c:v", "libaom-av1"]) | 5752 | .args(["-an", "-threads", "1", "-g", "16", "-c:v", "libaom-av1"]) |
| 5091 | - .args(["-cpu-used", "6", "-b:v", "0", "-crf", "35", "-f", "obu", "-"]) | 5753 | + .args([ |
| 5754 | + "-cpu-used", | ||
| 5755 | + "6", | ||
| 5756 | + "-b:v", | ||
| 5757 | + "0", | ||
| 5758 | + "-crf", | ||
| 5759 | + "35", | ||
| 5760 | + "-f", | ||
| 5761 | + "obu", | ||
| 5762 | + "-", | ||
| 5763 | + ]) | ||
| 5092 | .stdin(Stdio::null()) | 5764 | .stdin(Stdio::null()) |
| 5093 | .stdout(Stdio::piped()) | 5765 | .stdout(Stdio::piped()) |
| 5094 | .stderr(Stdio::piped()) | 5766 | .stderr(Stdio::piped()) |
| @@ -5178,18 +5850,37 @@ pub(crate) mod tests { | |||
| 5178 | let load = Command::new("ffmpeg") | 5850 | let load = Command::new("ffmpeg") |
| 5179 | .args(["-v", "error", "-y", "-i"]) | 5851 | .args(["-v", "error", "-y", "-i"]) |
| 5180 | .arg(&clip) | 5852 | .arg(&clip) |
| 5181 | - .args(["-frames:v", &frames.to_string(), "-vf", "crop=1920:1024:960:568"]) | 5853 | + .args([ |
| 5854 | + "-frames:v", | ||
| 5855 | + &frames.to_string(), | ||
| 5856 | + "-vf", | ||
| 5857 | + "crop=1920:1024:960:568", | ||
| 5858 | + ]) | ||
| 5182 | .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"]) | 5859 | .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"]) |
| 5183 | .arg(&src) | 5860 | .arg(&src) |
| 5184 | .output() | 5861 | .output() |
| 5185 | .expect("ffmpeg failed to run"); | 5862 | .expect("ffmpeg failed to run"); |
| 5186 | - assert!(load.status.success(), "{NAME}: {}", String::from_utf8_lossy(&load.stderr)); | 5863 | + assert!( |
| 5864 | + load.status.success(), | ||
| 5865 | + "{NAME}: {}", | ||
| 5866 | + String::from_utf8_lossy(&load.stderr) | ||
| 5867 | + ); | ||
| 5187 | let out = Command::new("ffmpeg") | 5868 | let out = Command::new("ffmpeg") |
| 5188 | .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"]) | 5869 | .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"]) |
| 5189 | .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) | 5870 | .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) |
| 5190 | .arg(&src) | 5871 | .arg(&src) |
| 5191 | .args(["-an", "-threads", "1", "-g", "12", "-c:v", "libaom-av1"]) | 5872 | .args(["-an", "-threads", "1", "-g", "12", "-c:v", "libaom-av1"]) |
| 5192 | - .args(["-cpu-used", "6", "-b:v", "0", "-crf", "45", "-f", "obu", "-"]) | 5873 | + .args([ |
| 5874 | + "-cpu-used", | ||
| 5875 | + "6", | ||
| 5876 | + "-b:v", | ||
| 5877 | + "0", | ||
| 5878 | + "-crf", | ||
| 5879 | + "45", | ||
| 5880 | + "-f", | ||
| 5881 | + "obu", | ||
| 5882 | + "-", | ||
| 5883 | + ]) | ||
| 5193 | .stdin(Stdio::null()) | 5884 | .stdin(Stdio::null()) |
| 5194 | .stdout(Stdio::piped()) | 5885 | .stdout(Stdio::piped()) |
| 5195 | .stderr(Stdio::piped()) | 5886 | .stderr(Stdio::piped()) |
| @@ -5307,7 +5998,10 @@ pub(crate) mod tests { | |||
| 5307 | lossless += 1; | 5998 | lossless += 1; |
| 5308 | } | 5999 | } |
| 5309 | } | 6000 | } |
| 5310 | - assert_eq!(lossless, frames, "{NAME} went blind: libaom coded no lossless key frame at -crf 0"); | 6001 | + assert_eq!( |
| 6002 | + lossless, frames, | ||
| 6003 | + "{NAME} went blind: libaom coded no lossless key frame at -crf 0" | ||
| 6004 | + ); | ||
| 5311 | let ours = decode_stream(&stream).expect("a lossless key-frame stream decodes"); | 6005 | let ours = decode_stream(&stream).expect("a lossless key-frame stream decodes"); |
| 5312 | let refs = ffmpeg_decode_sequence(&stream, w, h, frames); | 6006 | let refs = ffmpeg_decode_sequence(&stream, w, h, frames); |
| 5313 | assert_eq!(ours.len(), frames, "{NAME}: frame count"); | 6007 | assert_eq!(ours.len(), frames, "{NAME}: frame count"); |
| @@ -5317,7 +6011,10 @@ pub(crate) mod tests { | |||
| 5317 | .enumerate() | 6011 | .enumerate() |
| 5318 | { | 6012 | { |
| 5319 | let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); | 6013 | let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); |
| 5320 | - assert_eq!(bad, 0, "{NAME}: frame {i} plane {plane}: {bad} samples differ"); | 6014 | + assert_eq!( |
| 6015 | + bad, 0, | ||
| 6016 | + "{NAME}: frame {i} plane {plane}: {bad} samples differ" | ||
| 6017 | + ); | ||
| 5321 | } | 6018 | } |
| 5322 | } | 6019 | } |
| 5323 | } | 6020 | } |
| @@ -5380,7 +6077,11 @@ pub(crate) mod tests { | |||
| 5380 | for col in 0..w { | 6077 | for col in 0..w { |
| 5381 | let v = if screen { | 6078 | let v = if screen { |
| 5382 | if row % 7 == 0 && col % 3 == 0 { | 6079 | if row % 7 == 0 && col % 3 == 0 { |
| 5383 | - if (col / 3 + row + f) % 2 == 1 { 16 } else { 235 } | 6080 | + if (col / 3 + row + f) % 2 == 1 { |
| 6081 | + 16 | ||
| 6082 | + } else { | ||
| 6083 | + 235 | ||
| 6084 | + } | ||
| 5384 | } else { | 6085 | } else { |
| 5385 | PAL[((col + 4 * f) / 16 + row / 16) % PAL.len()] | 6086 | PAL[((col + 4 * f) / 16 + row / 16) % PAL.len()] |
| 5386 | } | 6087 | } |
| @@ -5405,10 +6106,16 @@ pub(crate) mod tests { | |||
| 5405 | } | 6106 | } |
| 5406 | } | 6107 | } |
| 5407 | } | 6108 | } |
| 5408 | - let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; | 6109 | + let pix = if depth == 10 { |
| 6110 | + "yuv420p10le" | ||
| 6111 | + } else { | ||
| 6112 | + "yuv420p" | ||
| 6113 | + }; | ||
| 5409 | // [[pid-keyed-temp-path]]: parallel test binaries must not share a name. | 6114 | // [[pid-keyed-temp-path]]: parallel test binaries must not share a name. |
| 5410 | - let src = std::env::temp_dir() | 6115 | + let src = std::env::temp_dir().join(format!( |
| 5411 | - .join(format!("ec-av1-lossless2-{}-{w}x{h}-{depth}.yuv", std::process::id())); | 6116 | + "ec-av1-lossless2-{}-{w}x{h}-{depth}.yuv", |
| 6117 | + std::process::id() | ||
| 6118 | + )); | ||
| 5412 | std::fs::write(&src, &raw).expect("raw source"); | 6119 | std::fs::write(&src, &raw).expect("raw source"); |
| 5413 | let mut cmd = Command::new("ffmpeg"); | 6120 | let mut cmd = Command::new("ffmpeg"); |
| 5414 | cmd.args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", pix]) | 6121 | cmd.args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", pix]) |
| @@ -5456,7 +6163,10 @@ pub(crate) mod tests { | |||
| 5456 | inters += 1; | 6163 | inters += 1; |
| 5457 | } | 6164 | } |
| 5458 | } | 6165 | } |
| 5459 | - assert!(lossless >= frames, "{NAME} [{tag}] went blind: {lossless} lossless frames"); | 6166 | + assert!( |
| 6167 | + lossless >= frames, | ||
| 6168 | + "{NAME} [{tag}] went blind: {lossless} lossless frames" | ||
| 6169 | + ); | ||
| 5460 | assert!( | 6170 | assert!( |
| 5461 | screen || inters > 0, | 6171 | screen || inters > 0, |
| 5462 | "{NAME} [{tag}] went blind: no inter frame at gop {gop}" | 6172 | "{NAME} [{tag}] went blind: no inter frame at gop {gop}" |
| @@ -5475,7 +6185,10 @@ pub(crate) mod tests { | |||
| 5475 | .enumerate() | 6185 | .enumerate() |
| 5476 | { | 6186 | { |
| 5477 | let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); | 6187 | let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); |
| 5478 | - assert_eq!(bad, 0, "{NAME} [{tag}]: frame {i} plane {plane}: {bad} samples differ"); | 6188 | + assert_eq!( |
| 6189 | + bad, 0, | ||
| 6190 | + "{NAME} [{tag}]: frame {i} plane {plane}: {bad} samples differ" | ||
| 6191 | + ); | ||
| 5479 | } | 6192 | } |
| 5480 | } | 6193 | } |
| 5481 | } | 6194 | } |
| @@ -5521,7 +6234,10 @@ pub(crate) mod tests { | |||
| 5521 | lossless = h.lossless.iter().all(|&l| l); | 6234 | lossless = h.lossless.iter().all(|&l| l); |
| 5522 | } | 6235 | } |
| 5523 | } | 6236 | } |
| 5524 | - assert!(lossless, "{NAME} went blind: the pinned frame is not lossless"); | 6237 | + assert!( |
| 6238 | + lossless, | ||
| 6239 | + "{NAME} went blind: the pinned frame is not lossless" | ||
| 6240 | + ); | ||
| 5525 | let before = crate::decode::rect_split_lossless_chroma444_hits(); | 6241 | let before = crate::decode::rect_split_lossless_chroma444_hits(); |
| 5526 | let ours = decode_stream(&stream).expect("a 444 lossless key-frame stream decodes"); | 6242 | let ours = decode_stream(&stream).expect("a 444 lossless key-frame stream decodes"); |
| 5527 | assert_eq!(ours.len(), 1, "{NAME}: frame count"); | 6243 | assert_eq!(ours.len(), 1, "{NAME}: frame count"); |
| @@ -5531,7 +6247,9 @@ pub(crate) mod tests { | |||
| 5531 | as 4x4 units at subsampling 0/0" | 6247 | as 4x4 units at subsampling 0/0" |
| 5532 | ); | 6248 | ); |
| 5533 | let refs = Command::new("ffmpeg") | 6249 | let refs = Command::new("ffmpeg") |
| 5534 | - .args(["-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv444p", "-"]) | 6250 | + .args([ |
| 6251 | + "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv444p", "-", | ||
| 6252 | + ]) | ||
| 5535 | .stdin(Stdio::piped()) | 6253 | .stdin(Stdio::piped()) |
| 5536 | .stdout(Stdio::piped()) | 6254 | .stdout(Stdio::piped()) |
| 5537 | .stderr(Stdio::piped()) | 6255 | .stderr(Stdio::piped()) |
| @@ -5542,7 +6260,11 @@ pub(crate) mod tests { | |||
| 5542 | child.wait_with_output() | 6260 | child.wait_with_output() |
| 5543 | }) | 6261 | }) |
| 5544 | .expect("ffmpeg 444 decode failed"); | 6262 | .expect("ffmpeg 444 decode failed"); |
| 5545 | - assert!(refs.status.success(), "{}", String::from_utf8_lossy(&refs.stderr)); | 6263 | + assert!( |
| 6264 | + refs.status.success(), | ||
| 6265 | + "{}", | ||
| 6266 | + String::from_utf8_lossy(&refs.stderr) | ||
| 6267 | + ); | ||
| 5546 | let frame = &ours[0]; | 6268 | let frame = &ours[0]; |
| 5547 | let planes = [ | 6269 | let planes = [ |
| 5548 | (&frame.y, frame.width * frame.height), | 6270 | (&frame.y, frame.width * frame.height), |
| @@ -5552,7 +6274,11 @@ pub(crate) mod tests { | |||
| 5552 | let mut off = 0usize; | 6274 | let mut off = 0usize; |
| 5553 | for (plane, (g, len)) in planes.iter().enumerate() { | 6275 | for (plane, (g, len)) in planes.iter().enumerate() { |
| 5554 | let raw = &refs.stdout[off..off + len]; | 6276 | let raw = &refs.stdout[off..off + len]; |
| 5555 | - let bad = g.iter().zip(raw.iter()).filter(|&(&a, &b)| a != u16::from(b)).count(); | 6277 | + let bad = g |
| 6278 | + .iter() | ||
| 6279 | + .zip(raw.iter()) | ||
| 6280 | + .filter(|&(&a, &b)| a != u16::from(b)) | ||
| 6281 | + .count(); | ||
| 5556 | assert_eq!(bad, 0, "{NAME}: plane {plane}: {bad} samples differ"); | 6282 | assert_eq!(bad, 0, "{NAME}: plane {plane}: {bad} samples differ"); |
| 5557 | off += len; | 6283 | off += len; |
| 5558 | } | 6284 | } |
| @@ -5592,9 +6318,18 @@ pub(crate) mod tests { | |||
| 5592 | Pic { | 6318 | Pic { |
| 5593 | width, | 6319 | width, |
| 5594 | height, | 6320 | height, |
| 5595 | - y: out.stdout[base..base + plane].iter().map(|&v| u16::from(v)).collect(), | 6321 | + y: out.stdout[base..base + plane] |
| 5596 | - u: out.stdout[base + plane..base + 2 * plane].iter().map(|&v| u16::from(v)).collect(), | 6322 | + .iter() |
| 5597 | - v: out.stdout[base + 2 * plane..base + 3 * plane].iter().map(|&v| u16::from(v)).collect(), | 6323 | + .map(|&v| u16::from(v)) |
| 6324 | + .collect(), | ||
| 6325 | + u: out.stdout[base + plane..base + 2 * plane] | ||
| 6326 | + .iter() | ||
| 6327 | + .map(|&v| u16::from(v)) | ||
| 6328 | + .collect(), | ||
| 6329 | + v: out.stdout[base + 2 * plane..base + 3 * plane] | ||
| 6330 | + .iter() | ||
| 6331 | + .map(|&v| u16::from(v)) | ||
| 6332 | + .collect(), | ||
| 5598 | } | 6333 | } |
| 5599 | }) | 6334 | }) |
| 5600 | .collect() | 6335 | .collect() |
| @@ -5641,9 +6376,8 @@ pub(crate) mod tests { | |||
| 5641 | 6376 | ||
| 5642 | let _guard = lock_gate_counters(); | 6377 | let _guard = lock_gate_counters(); |
| 5643 | let before = crate::decode::chroma_split_tx_hits(); | 6378 | let before = crate::decode::chroma_split_tx_hits(); |
| 5644 | - let frames = decode_stream(&stream).unwrap_or_else(|e| { | 6379 | + let frames = decode_stream(&stream) |
| 5645 | - panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") | 6380 | + .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); |
| 5646 | - }); | ||
| 5647 | let hits = crate::decode::chroma_split_tx_hits(); | 6381 | let hits = crate::decode::chroma_split_tx_hits(); |
| 5648 | assert!( | 6382 | assert!( |
| 5649 | hits > before, | 6383 | hits > before, |
| @@ -5685,12 +6419,22 @@ pub(crate) mod tests { | |||
| 5685 | .zip(["y", "u", "v"]) | 6419 | .zip(["y", "u", "v"]) |
| 5686 | { | 6420 | { |
| 5687 | let want = &ref_raw[base + off..base + off + W * H]; | 6421 | let want = &ref_raw[base + off..base + off + W * H]; |
| 5688 | - let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); | 6422 | + let bad = plane |
| 5689 | - assert_eq!(bad, 0, "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ"); | 6423 | + .iter() |
| 6424 | + .zip(want) | ||
| 6425 | + .filter(|&(&a, &b)| a as u8 != b) | ||
| 6426 | + .count(); | ||
| 6427 | + assert_eq!( | ||
| 6428 | + bad, 0, | ||
| 6429 | + "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ" | ||
| 6430 | + ); | ||
| 5690 | } | 6431 | } |
| 5691 | } | 6432 | } |
| 5692 | } else { | 6433 | } else { |
| 5693 | - eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); | 6434 | + eprintln!( |
| 6435 | + "SKIP {NAME} aomdec arm: no oracle aomdec at {}", | ||
| 6436 | + aomdec_path().display() | ||
| 6437 | + ); | ||
| 5694 | } | 6438 | } |
| 5695 | 6439 | ||
| 5696 | // ffmpeg's decoder: same frames, full-resolution chroma. | 6440 | // ffmpeg's decoder: same frames, full-resolution chroma. |
| @@ -5702,7 +6446,10 @@ pub(crate) mod tests { | |||
| 5702 | .enumerate() | 6446 | .enumerate() |
| 5703 | { | 6447 | { |
| 5704 | let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); | 6448 | let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); |
| 5705 | - assert_eq!(bad, 0, "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ"); | 6449 | + assert_eq!( |
| 6450 | + bad, 0, | ||
| 6451 | + "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ" | ||
| 6452 | + ); | ||
| 5706 | } | 6453 | } |
| 5707 | } | 6454 | } |
| 5708 | } else { | 6455 | } else { |
| @@ -5760,9 +6507,8 @@ pub(crate) mod tests { | |||
| 5760 | assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | 6507 | assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); |
| 5761 | 6508 | ||
| 5762 | let _guard = lock_gate_counters(); | 6509 | let _guard = lock_gate_counters(); |
| 5763 | - let frames = decode_stream(&stream).unwrap_or_else(|e| { | 6510 | + let frames = decode_stream(&stream) |
| 5764 | - panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") | 6511 | + .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); |
| 5765 | - }); | ||
| 5766 | assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); | 6512 | assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); |
| 5767 | for f in &frames { | 6513 | for f in &frames { |
| 5768 | assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); | 6514 | assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); |
| @@ -5798,7 +6544,11 @@ pub(crate) mod tests { | |||
| 5798 | .zip(["y", "u", "v"]) | 6544 | .zip(["y", "u", "v"]) |
| 5799 | { | 6545 | { |
| 5800 | let want = &ref_raw[base + off..base + off + W * H]; | 6546 | let want = &ref_raw[base + off..base + off + W * H]; |
| 5801 | - let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); | 6547 | + let bad = plane |
| 6548 | + .iter() | ||
| 6549 | + .zip(want) | ||
| 6550 | + .filter(|&(&a, &b)| a as u8 != b) | ||
| 6551 | + .count(); | ||
| 5802 | assert_eq!( | 6552 | assert_eq!( |
| 5803 | bad, 0, | 6553 | bad, 0, |
| 5804 | "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ | 6554 | "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ |
| @@ -5807,7 +6557,10 @@ pub(crate) mod tests { | |||
| 5807 | } | 6557 | } |
| 5808 | } | 6558 | } |
| 5809 | } else { | 6559 | } else { |
| 5810 | - eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); | 6560 | + eprintln!( |
| 6561 | + "SKIP {NAME} aomdec arm: no oracle aomdec at {}", | ||
| 6562 | + aomdec_path().display() | ||
| 6563 | + ); | ||
| 5811 | } | 6564 | } |
| 5812 | 6565 | ||
| 5813 | // ffmpeg's decoder: same frames, full-resolution chroma. | 6566 | // ffmpeg's decoder: same frames, full-resolution chroma. |
| @@ -5819,7 +6572,10 @@ pub(crate) mod tests { | |||
| 5819 | .enumerate() | 6572 | .enumerate() |
| 5820 | { | 6573 | { |
| 5821 | let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); | 6574 | let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); |
| 5822 | - assert_eq!(bad, 0, "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ"); | 6575 | + assert_eq!( |
| 6576 | + bad, 0, | ||
| 6577 | + "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ" | ||
| 6578 | + ); | ||
| 5823 | } | 6579 | } |
| 5824 | } | 6580 | } |
| 5825 | } else { | 6581 | } else { |
| @@ -5878,9 +6634,8 @@ pub(crate) mod tests { | |||
| 5878 | let _guard = lock_gate_counters(); | 6634 | let _guard = lock_gate_counters(); |
| 5879 | let before = crate::decode::intra_sb128_hits(); | 6635 | let before = crate::decode::intra_sb128_hits(); |
| 5880 | let before_replay = crate::decode::sb128rect_chroma_replay_hits(); | 6636 | let before_replay = crate::decode::sb128rect_chroma_replay_hits(); |
| 5881 | - let frames = decode_stream(&stream).unwrap_or_else(|e| { | 6637 | + let frames = decode_stream(&stream) |
| 5882 | - panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") | 6638 | + .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); |
| 5883 | - }); | ||
| 5884 | let (horz, vert, _) = crate::decode::intra_sb128_hits(); | 6639 | let (horz, vert, _) = crate::decode::intra_sb128_hits(); |
| 5885 | assert!( | 6640 | assert!( |
| 5886 | horz - before.0 + (vert - before.1) > 0, | 6641 | horz - before.0 + (vert - before.1) > 0, |
| @@ -5937,8 +6692,7 @@ pub(crate) mod tests { | |||
| 5937 | 6692 | ||
| 5938 | // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames. | 6693 | // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames. |
| 5939 | if aomdec_path().is_file() { | 6694 | if aomdec_path().is_file() { |
| 5940 | - let dir = | 6695 | + let dir = std::env::temp_dir().join(format!("ec-av1-444sb-{}", std::process::id())); |
| 5941 | - std::env::temp_dir().join(format!("ec-av1-444sb-{}", std::process::id())); | ||
| 5942 | let _ = std::fs::remove_dir_all(&dir); | 6696 | let _ = std::fs::remove_dir_all(&dir); |
| 5943 | std::fs::create_dir_all(&dir).expect("scratch dir"); | 6697 | std::fs::create_dir_all(&dir).expect("scratch dir"); |
| 5944 | let raw = dir.join("aomdec.raw"); | 6698 | let raw = dir.join("aomdec.raw"); |
| @@ -5961,14 +6715,16 @@ pub(crate) mod tests { | |||
| 5961 | assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); | 6715 | assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); |
| 5962 | for (i, f) in frames.iter().enumerate().take(3) { | 6716 | for (i, f) in frames.iter().enumerate().take(3) { |
| 5963 | let base = i * W * H * 3; | 6717 | let base = i * W * H * 3; |
| 5964 | - for ((plane, off), p) in | 6718 | + for ((plane, off), p) in [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] |
| 5965 | - [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] | ||
| 5966 | .into_iter() | 6719 | .into_iter() |
| 5967 | .zip(["y", "u", "v"]) | 6720 | .zip(["y", "u", "v"]) |
| 5968 | { | 6721 | { |
| 5969 | let want = &ref_raw[base + off..base + off + W * H]; | 6722 | let want = &ref_raw[base + off..base + off + W * H]; |
| 5970 | - let bad = | 6723 | + let bad = plane |
| 5971 | - plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); | 6724 | + .iter() |
| 6725 | + .zip(want) | ||
| 6726 | + .filter(|&(&a, &b)| a as u8 != b) | ||
| 6727 | + .count(); | ||
| 5972 | assert_eq!( | 6728 | assert_eq!( |
| 5973 | bad, 0, | 6729 | bad, 0, |
| 5974 | "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ | 6730 | "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ |
| @@ -5977,7 +6733,10 @@ pub(crate) mod tests { | |||
| 5977 | } | 6733 | } |
| 5978 | } | 6734 | } |
| 5979 | } else { | 6735 | } else { |
| 5980 | - eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); | 6736 | + eprintln!( |
| 6737 | + "SKIP {NAME} aomdec arm: no oracle aomdec at {}", | ||
| 6738 | + aomdec_path().display() | ||
| 6739 | + ); | ||
| 5981 | } | 6740 | } |
| 5982 | 6741 | ||
| 5983 | // ffmpeg's decoder: same frames, full-resolution chroma. Same | 6742 | // ffmpeg's decoder: same frames, full-resolution chroma. Same |
| @@ -5985,8 +6744,7 @@ pub(crate) mod tests { | |||
| 5985 | if have_ffmpeg() { | 6744 | if have_ffmpeg() { |
| 5986 | let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); | 6745 | let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); |
| 5987 | for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate().take(3) { | 6746 | for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate().take(3) { |
| 5988 | - for (p, (g, r)) in | 6747 | + for (p, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] |
| 5989 | - [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] | ||
| 5990 | .iter() | 6748 | .iter() |
| 5991 | .enumerate() | 6749 | .enumerate() |
| 5992 | { | 6750 | { |
| @@ -6050,8 +6808,8 @@ pub(crate) mod tests { | |||
| 6050 | assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | 6808 | assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); |
| 6051 | 6809 | ||
| 6052 | let _guard = lock_gate_counters(); | 6810 | let _guard = lock_gate_counters(); |
| 6053 | - let serial = decode_stream(&stream) | 6811 | + let serial = |
| 6054 | - .unwrap_or_else(|e| panic!("{NAME}: serial decode failed: {e}")); | 6812 | + decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME}: serial decode failed: {e}")); |
| 6055 | assert_eq!(serial.len(), FRAMES, "{NAME}: frame count"); | 6813 | assert_eq!(serial.len(), FRAMES, "{NAME}: frame count"); |
| 6056 | 6814 | ||
| 6057 | let pipe_before = crate::decode::pipeline_taken_frames(); | 6815 | let pipe_before = crate::decode::pipeline_taken_frames(); |
| @@ -6087,8 +6845,9 @@ pub(crate) mod tests { | |||
| 6087 | // frame -- including frame 2, the 128-root-rect inter frame the | 6845 | // frame -- including frame 2, the 128-root-rect inter frame the |
| 6088 | // r2 defect named. | 6846 | // r2 defect named. |
| 6089 | for (i, (s, p)) in serial.iter().zip(piped.iter()).enumerate() { | 6847 | for (i, (s, p)) in serial.iter().zip(piped.iter()).enumerate() { |
| 6090 | - for (pl, (a, b)) in | 6848 | + for (pl, (a, b)) in [(&s.y, &p.y), (&s.u, &p.u), (&s.v, &p.v)] |
| 6091 | - [(&s.y, &p.y), (&s.u, &p.u), (&s.v, &p.v)].into_iter().enumerate() | 6849 | + .into_iter() |
| 6850 | + .enumerate() | ||
| 6092 | { | 6851 | { |
| 6093 | assert_eq!( | 6852 | assert_eq!( |
| 6094 | a, b, | 6853 | a, b, |
| @@ -6123,13 +6882,16 @@ pub(crate) mod tests { | |||
| 6123 | assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); | 6882 | assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); |
| 6124 | for (i, f) in piped.iter().enumerate().take(2) { | 6883 | for (i, f) in piped.iter().enumerate().take(2) { |
| 6125 | let base = i * W * H * 3; | 6884 | let base = i * W * H * 3; |
| 6126 | - for ((plane, off), p) in | 6885 | + for ((plane, off), p) in [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] |
| 6127 | - [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] | ||
| 6128 | .into_iter() | 6886 | .into_iter() |
| 6129 | .zip(["y", "u", "v"]) | 6887 | .zip(["y", "u", "v"]) |
| 6130 | { | 6888 | { |
| 6131 | let want = &ref_raw[base + off..base + off + W * H]; | 6889 | let want = &ref_raw[base + off..base + off + W * H]; |
| 6132 | - let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); | 6890 | + let bad = plane |
| 6891 | + .iter() | ||
| 6892 | + .zip(want) | ||
| 6893 | + .filter(|&(&a, &b)| a as u8 != b) | ||
| 6894 | + .count(); | ||
| 6133 | assert_eq!( | 6895 | assert_eq!( |
| 6134 | bad, 0, | 6896 | bad, 0, |
| 6135 | "{NAME}: aomdec frame {i} plane {p} THROUGH THE PIPELINE: \ | 6897 | "{NAME}: aomdec frame {i} plane {p} THROUGH THE PIPELINE: \ |
| @@ -6138,13 +6900,15 @@ pub(crate) mod tests { | |||
| 6138 | } | 6900 | } |
| 6139 | } | 6901 | } |
| 6140 | } else { | 6902 | } else { |
| 6141 | - eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); | 6903 | + eprintln!( |
| 6904 | + "SKIP {NAME} aomdec arm: no oracle aomdec at {}", | ||
| 6905 | + aomdec_path().display() | ||
| 6906 | + ); | ||
| 6142 | } | 6907 | } |
| 6143 | if have_ffmpeg() { | 6908 | if have_ffmpeg() { |
| 6144 | let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); | 6909 | let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); |
| 6145 | for (i, (got, want)) in piped.iter().zip(refs.iter()).enumerate().take(2) { | 6910 | for (i, (got, want)) in piped.iter().zip(refs.iter()).enumerate().take(2) { |
| 6146 | - for (p, (g, r)) in | 6911 | + for (p, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] |
| 6147 | - [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] | ||
| 6148 | .iter() | 6912 | .iter() |
| 6149 | .enumerate() | 6913 | .enumerate() |
| 6150 | { | 6914 | { |
| @@ -6203,9 +6967,8 @@ pub(crate) mod tests { | |||
| 6203 | 6967 | ||
| 6204 | let _guard = lock_gate_counters(); | 6968 | let _guard = lock_gate_counters(); |
| 6205 | let strips_before = decode::inter16_rect4_counters(); | 6969 | let strips_before = decode::inter16_rect4_counters(); |
| 6206 | - let frames = decode_stream(&stream).unwrap_or_else(|e| { | 6970 | + let frames = decode_stream(&stream) |
| 6207 | - panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") | 6971 | + .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); |
| 6208 | - }); | ||
| 6209 | let strips_after = decode::inter16_rect4_counters(); | 6972 | let strips_after = decode::inter16_rect4_counters(); |
| 6210 | assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); | 6973 | assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); |
| 6211 | for f in &frames { | 6974 | for f in &frames { |
| @@ -6256,7 +7019,11 @@ pub(crate) mod tests { | |||
| 6256 | .zip(["y", "u", "v"]) | 7019 | .zip(["y", "u", "v"]) |
| 6257 | { | 7020 | { |
| 6258 | let want = &ref_raw[base + off..base + off + W * H]; | 7021 | let want = &ref_raw[base + off..base + off + W * H]; |
| 6259 | - let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); | 7022 | + let bad = plane |
| 7023 | + .iter() | ||
| 7024 | + .zip(want) | ||
| 7025 | + .filter(|&(&a, &b)| a as u8 != b) | ||
| 7026 | + .count(); | ||
| 6260 | assert_eq!( | 7027 | assert_eq!( |
| 6261 | bad, 0, | 7028 | bad, 0, |
| 6262 | "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ | 7029 | "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ |
| @@ -6265,7 +7032,10 @@ pub(crate) mod tests { | |||
| 6265 | } | 7032 | } |
| 6266 | } | 7033 | } |
| 6267 | } else { | 7034 | } else { |
| 6268 | - eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); | 7035 | + eprintln!( |
| 7036 | + "SKIP {NAME} aomdec arm: no oracle aomdec at {}", | ||
| 7037 | + aomdec_path().display() | ||
| 7038 | + ); | ||
| 6269 | } | 7039 | } |
| 6270 | } | 7040 | } |
| 6271 | 7041 | ||
| @@ -6335,8 +7105,8 @@ pub(crate) mod tests { | |||
| 6335 | const W: usize = 320; | 7105 | const W: usize = 320; |
| 6336 | const H: usize = 256; | 7106 | const H: usize = 256; |
| 6337 | const FRAMES: usize = 3; | 7107 | const FRAMES: usize = 3; |
| 6338 | - let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | 7108 | + let obu = |
| 6339 | - .join("fixtures/444_leaf8_oob.obu"); | 7109 | + std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("fixtures/444_leaf8_oob.obu"); |
| 6340 | let stream = std::fs::read(&obu).unwrap_or_else(|e| { | 7110 | let stream = std::fs::read(&obu).unwrap_or_else(|e| { |
| 6341 | panic!( | 7111 | panic!( |
| 6342 | "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ | 7112 | "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ |
| @@ -6349,9 +7119,8 @@ pub(crate) mod tests { | |||
| 6349 | 7119 | ||
| 6350 | let _guard = lock_gate_counters(); | 7120 | let _guard = lock_gate_counters(); |
| 6351 | crate::decode::reset_leaf8_intrabc_hits(); | 7121 | crate::decode::reset_leaf8_intrabc_hits(); |
| 6352 | - let frames = decode_stream(&stream).unwrap_or_else(|e| { | 7122 | + let frames = decode_stream(&stream) |
| 6353 | - panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") | 7123 | + .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); |
| 6354 | - }); | ||
| 6355 | assert!( | 7124 | assert!( |
| 6356 | crate::decode::leaf8_intrabc_hits() > 0, | 7125 | crate::decode::leaf8_intrabc_hits() > 0, |
| 6357 | "{NAME}: gate is vacuous -- no intrabc 8x8 leaf was decoded, so the arm \ | 7126 | "{NAME}: gate is vacuous -- no intrabc 8x8 leaf was decoded, so the arm \ |
| @@ -6391,7 +7160,10 @@ pub(crate) mod tests { | |||
| 6391 | "{NAME}: aomdec raw fingerprint moved" | 7160 | "{NAME}: aomdec raw fingerprint moved" |
| 6392 | ); | 7161 | ); |
| 6393 | } else { | 7162 | } else { |
| 6394 | - eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); | 7163 | + eprintln!( |
| 7164 | + "SKIP {NAME} aomdec arm: no oracle aomdec at {}", | ||
| 7165 | + aomdec_path().display() | ||
| 7166 | + ); | ||
| 6395 | } | 7167 | } |
| 6396 | } | 7168 | } |
| 6397 | /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis | 7169 | /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis |
| @@ -6457,7 +7229,8 @@ pub(crate) mod tests { | |||
| 6457 | arm never ran (class gate-blind-to-feature)" | 7229 | arm never ran (class gate-blind-to-feature)" |
| 6458 | ); | 7230 | ); |
| 6459 | assert_eq!( | 7231 | assert_eq!( |
| 6460 | - after_replay.1, before_replay.1, | 7232 | + after_replay.1, |
| 7233 | + before_replay.1, | ||
| 6461 | "{NAME}: the tail replay stamped {} unit(s) over a height that was not the \ | 7234 | "{NAME}: the tail replay stamped {} unit(s) over a height that was not the \ |
| 6462 | unit's own luma height (4:2:2 spans leaked into an admitted stream)", | 7235 | unit's own luma height (4:2:2 spans leaked into an admitted stream)", |
| 6463 | after_replay.1 - before_replay.1 | 7236 | after_replay.1 - before_replay.1 |
| @@ -6501,15 +7274,29 @@ pub(crate) mod tests { | |||
| 6501 | let out = ff | 7274 | let out = ff |
| 6502 | .args(["-v", "error", "-f", "lavfi", "-i"]) | 7275 | .args(["-v", "error", "-f", "lavfi", "-i"]) |
| 6503 | .arg(format!("testsrc2=s={width}x{height}:r=25")) | 7276 | .arg(format!("testsrc2=s={width}x{height}:r=25")) |
| 6504 | - .args(["-frames:v", "1", "-pix_fmt", "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-"]) | 7277 | + .args([ |
| 7278 | + "-frames:v", | ||
| 7279 | + "1", | ||
| 7280 | + "-pix_fmt", | ||
| 7281 | + "yuv420p", | ||
| 7282 | + "-strict", | ||
| 7283 | + "-1", | ||
| 7284 | + "-f", | ||
| 7285 | + "yuv4mpegpipe", | ||
| 7286 | + "-", | ||
| 7287 | + ]) | ||
| 6505 | .stdin(Stdio::null()) | 7288 | .stdin(Stdio::null()) |
| 6506 | .stdout(Stdio::piped()) | 7289 | .stdout(Stdio::piped()) |
| 6507 | .stderr(Stdio::piped()) | 7290 | .stderr(Stdio::piped()) |
| 6508 | .output() | 7291 | .output() |
| 6509 | .expect("ffmpeg failed to run"); | 7292 | .expect("ffmpeg failed to run"); |
| 6510 | - assert!(out.status.success(), "ffmpeg failed for testsrc2 {width}x{height}"); | 7293 | + assert!( |
| 7294 | + out.status.success(), | ||
| 7295 | + "ffmpeg failed for testsrc2 {width}x{height}" | ||
| 7296 | + ); | ||
| 6511 | let y4m = out.stdout; | 7297 | let y4m = out.stdout; |
| 6512 | - let out = run_with_stdin(Command::new(aomenc_path()) | 7298 | + let out = run_with_stdin( |
| 7299 | + Command::new(aomenc_path()) | ||
| 6513 | .args(["--codec=av1", "--bit-depth=8", "--input-bit-depth=8"]) | 7300 | .args(["--codec=av1", "--bit-depth=8", "--input-bit-depth=8"]) |
| 6514 | .args([ | 7301 | .args([ |
| 6515 | "--passes=1", | 7302 | "--passes=1", |
| @@ -6524,8 +7311,14 @@ pub(crate) mod tests { | |||
| 6524 | "--enable-1to4-partitions=1", | 7311 | "--enable-1to4-partitions=1", |
| 6525 | ]) | 7312 | ]) |
| 6526 | .args(extra) | 7313 | .args(extra) |
| 6527 | - .args(["--obu", "-o", "-", "-"]), &y4m); | 7314 | + .args(["--obu", "-o", "-", "-"]), |
| 6528 | - assert!(out.status.success(), "aomenc failed: {}", String::from_utf8_lossy(&out.stderr)); | 7315 | + &y4m, |
| 7316 | + ); | ||
| 7317 | + assert!( | ||
| 7318 | + out.status.success(), | ||
| 7319 | + "aomenc failed: {}", | ||
| 7320 | + String::from_utf8_lossy(&out.stderr) | ||
| 7321 | + ); | ||
lanes/av1ibc128chunk.report.mdadded+327 -0
| @@ -0,0 +1,327 @@ | |||
| 1 | +# lane-av1-ibc128chunk — the 128-root intrabc strip's square-cut mu-chunk chroma walk, de-square-cut and WITNESSED | ||
| 2 | + | ||
| 3 | +Branch `lane-av1-ibc128chunk`, parent `a7d22aec`. Target dir | ||
| 4 | +`$HOME/.cache/cargo-target-av1ibc128chunk` throughout. No push. | ||
| 5 | + | ||
| 6 | +## Verdict | ||
| 7 | + | ||
| 8 | +The deferred copy is fixed **and witnessed** — this is not a defensive fix. | ||
| 9 | +`decode_intrabc_128rect` cut each mu chunk's chroma plane block with | ||
| 10 | +`chunk_chroma = cside * 64 / side` (two sites, decode.rs:12663 and decode.rs:12896 | ||
| 11 | +at the parent), the same square-cut defect lane-av1-422bigblock fixed and | ||
| 12 | +witnessed in `decode_inter_block` and `decode_block_128rect`. Red before: a real | ||
| 13 | +4:2:2 `aomenc --enable-intrabc` sb128 stream loses half of every mu chunk's | ||
| 14 | +chroma units and its frames 0 and 3 diverge from `aomdec`, first difference at | ||
| 15 | +the top-left corner of the very first 128x64 intrabc block. Green after: the | ||
| 16 | +same stream decodes all five frames byte-identical to `aomdec --rawvideo`, and | ||
| 17 | +the red build's 4 lost blocks are recovered. | ||
| 18 | + | ||
| 19 | +Both pinned witnesses are committed; committed code still refuses 4:2:2 at the | ||
| 20 | +sequence header and the `EC_AV1_ALLOW_422_PROBE` bypass was applied and | ||
| 21 | +reverted per probe run (`git diff` on the refusal line is empty; the only | ||
| 22 | +`EC_AV1_ALLOW_422_PROBE` strings left in the tree are two doc-comment mentions | ||
| 23 | +of the recipe). | ||
| 24 | + | ||
| 25 | +## The defect (both sites) | ||
| 26 | + | ||
| 27 | +`decode_intrabc_128rect` is the intrabc arm of `decode_block_128rect`: a | ||
| 28 | +128x64 / 64x128 / 128x128 strip coded with `use_intrabc`, predicted from this | ||
| 29 | +frame's own reconstruction, reconstructed through the INTER residual walk | ||
| 30 | +(`decode_token_recon_block`'s else arm). | ||
| 31 | + | ||
| 32 | +A 64x64 mu chunk's chroma plane block is **per-axis** `(64 >> ss_x) x | ||
| 33 | +(64 >> ss_y)`: 32x32 at 4:2:0 (one TX_32X32 per plane per chunk), **32x64 at | ||
| 34 | +4:2:2 (TWO STACKED TX_32X32 per plane per chunk)**, 64x64 at 4:4:4 (four). | ||
| 35 | +`av1_get_max_uv_txsize` caps the unit at 32 on each axis. The square-cut model | ||
| 36 | +walked a `chroma_side`-square chunk, i.e. the 4:2:0 count on both axes. | ||
| 37 | + | ||
| 38 | +Measured consequences at 4:2:2 (witness below): | ||
| 39 | + | ||
| 40 | +1. **Half the units.** One chroma unit per plane per chunk instead of two | ||
| 41 | + stacked — the chunk's lower 32 chroma rows got no residual at all. | ||
| 42 | +2. **Wrong extent, twice.** The block's own chroma plane block was still | ||
| 43 | + `bw / 2 x bh / 2` (`cpx, cpy = px / 2, py / 2`), i.e. 4:2:0-shaped, even | ||
| 44 | + though the same function's two `mv_to_q4(cpy, dv_row, ss_y(fctx))` calls | ||
| 45 | + already scaled the DV on the y axis by **its own** subsampling — the | ||
| 46 | + prediction window was half as tall as the motion vector asked for. | ||
| 47 | +3. **Wrong entropy spans.** `around_mi` / `record_mi_chroma` stamped every unit | ||
| 48 | + over a `unit_luma = cu_tx * (side / cside)` = 16x16-mi luma square instead | ||
| 49 | + of the per-axis 16x8 at 4:2:2, and the `mu_chroma` per-unit replay walked a | ||
| 50 | + 32-row step down a 64-row chunk. | ||
| 51 | +4. **Entropy lock lost.** The halved unit count desynced the tile: the red build | ||
| 52 | + decoded 2 of the stream's 6 intrabc blocks; the fixed build decodes all 6. | ||
| 53 | + | ||
| 54 | +## The fix (mirror of the two witnessed twins) | ||
| 55 | + | ||
| 56 | +Both sites, per-axis, in the same expression shape | ||
| 57 | +`decode_inter_block` already carries: | ||
| 58 | + | ||
| 59 | +| old | new | | ||
| 60 | +|---|---| | ||
| 61 | +| `let (cpx, cpy) = (px / 2, py / 2);` | `(px >> ss_x(fctx), py >> ss_y(fctx))` | | ||
| 62 | +| `let (cw, ch) = (bw / 2, bh / 2);` | `(bw >> ss_x(fctx), bh >> ss_y(fctx))` | | ||
| 63 | +| `let chunk_chroma = cside * 64 / side;` | `chunk_chroma_w = (64usize) >> ss_x(fctx)` / `chunk_chroma_h = (64usize) >> ss_y(fctx)` | | ||
| 64 | +| `let unit_luma = cu_tx * (side / cside);` | `unit_luma_w = cu_tx << ss_x(fctx)` / `unit_luma_h = cu_tx << ss_y(fctx)` | | ||
| 65 | +| `units_x/y = chunk_*_mi / (unit_luma / MI)` | same, on `unit_luma_w` / `unit_luma_h` | | ||
| 66 | +| `around_mi(unit_mi, unit_luma)` | `around_mi_rect(unit_mi, unit_luma_w, unit_luma_h)` | | ||
| 67 | +| `record_mi_chroma(unit_mi, unit_luma, unit_luma, ..)` | `.. unit_luma_w, unit_luma_h, ..` | | ||
| 68 | +| `cu_x = cpx + cc * chunk_chroma + uc * cu_tx` | `.. cc * chunk_chroma_w + ..` | | ||
| 69 | +| `cu_y = cpy + cr * chunk_chroma + ur * cu_tx` | `.. cr * chunk_chroma_h + ..` | | ||
| 70 | +| `cu_pred` / composed-grid `dst` offsets | per-axis offsets at the square `cside` stride | | ||
| 71 | +| `read_inter_chroma_lossless(.., (cc*cc_, cr*cc_), (cc_, cc_), ..)` | per-axis org and region | | ||
| 72 | +| replay `unit_luma = cu * 2` | `unit_luma_w = cu << ss_x(fctx)` / `unit_luma_h = cu << ss_y(fctx)` | | ||
| 73 | +| replay `ch / chunk_chroma`, `cw / chunk_chroma` | `ch / chunk_chroma_h`, `cw / chunk_chroma_w` | | ||
| 74 | +| `EC_IBC128_BANDS` trace spans | per-axis | | ||
| 75 | + | ||
| 76 | +New counters (both exported from `stream` and printed by `decode_probe`): | ||
| 77 | +`INTRABC_128RECT_CHROMA_CHUNK_HITS` (one bump per chroma `read_inter_plane` of | ||
| 78 | +this walk) and `INTRABC_128RECT_CHUNK_SHAPE` | ||
| 79 | +(`(64 >> ss_x) << 8 | (64 >> ss_y)` of the last chunk walked). | ||
| 80 | + | ||
| 81 | +## Fixtures (pinned, `git add -f`; `fixtures/` is gitignored) | ||
| 82 | + | ||
| 83 | +| fixture | bytes | sha256 | fnv1a64 | | ||
| 84 | +|---|---|---|---| | ||
| 85 | +| `422_intrabc_sb128_strip.obu` | 1672 | `f92000db86df7acc577d60dd1d0d97454bff4705799ea59d9de34eb5a71dbbcd` | `0x50f5cfc576e4cd00` | | ||
| 86 | +| `422_intrabc_sb128_strip_notxsearch.obu` | 1675 | `80dd0d4e93fd6c3d4b7188a43e69d9638f2bece38edfab60ff3582628314b5ec` | `0xd4936f252ff8cff0` | | ||
| 87 | + | ||
| 88 | +Source (the deterministic `geq` sinusoid the tree's own sb128 intrabc-rect gate | ||
| 89 | +uses, re-cut at `yuv422p` — the 4:2:2 twin of that gate's arm 1): | ||
| 90 | + | ||
| 91 | + ffmpeg -v error -f lavfi -i "nullsrc=size=384x320:rate=25,format=yuv420p,\ | ||
| 92 | + geq=lum='128+90*sin((X+2*N)/37)+30*sin(Y/29)':\ | ||
| 93 | + cb='128+30*sin(X/23)':cr='128+30*sin((Y+N)/19)'" \ | ||
| 94 | + -pix_fmt yuv422p -strict -1 -t 0.2 -f yuv4mpegpipe -y geq/384x320.y4m | ||
| 95 | + | ||
| 96 | + ~/.cache/aom-oracle/build/aomenc --codec=av1 --i422 --profile=2 --passes=1 \ | ||
| 97 | + --end-usage=q --cq-level=32 --cpu-used=0 --threads=1 --row-mt=0 \ | ||
| 98 | + --lag-in-frames=0 --kf-max-dist=1 --limit=5 --tile-columns=0 --sb-size=128 \ | ||
| 99 | + --min-partition-size=64 --enable-rect-partitions=1 --enable-ab-partitions=0 \ | ||
| 100 | + --enable-1to4-partitions=0 --enable-palette=0 --tune-content=screen \ | ||
| 101 | + --enable-intrabc=1 --deltaq-mode=0 --enable-tx-size-search=1 \ | ||
| 102 | + --obu -o geq/384x320_cq32_ts1.obu geq/384x320.y4m | ||
| 103 | + | ||
| 104 | +`_notxsearch` is the same command with `--enable-tx-size-search=0`. Both are | ||
| 105 | +pinned and both are red-before / green-after (the tx-size-search arm is not | ||
| 106 | +required — a mis-signed flag on a witness is a coin flip, so both went in). | ||
| 107 | + | ||
| 108 | +## Red before / green after (measured) | ||
| 109 | + | ||
| 110 | +`aomdec` is `~/.cache/aom-oracle/build/aomdec`; ours is `decode_probe` (debug, | ||
| 111 | +`--features gate-counters`) on the `EC_AV1_ALLOW_422_PROBE` patch-run-restore | ||
| 112 | +build, compared with `cmp` on the full raw output. | ||
| 113 | + | ||
| 114 | +| fixture | build | 128-root blocks | chroma units stamped | vs `aomdec` | | ||
| 115 | +|---|---|---|---|---| | ||
| 116 | +| `422_intrabc_sb128_strip.obu` | parent `a7d22aec` | **2** | **8** | **DIFF** | | ||
| 117 | +| `422_intrabc_sb128_strip.obu` | this lane | **6** | **48** | **EXACT** (5/5 frames) | | ||
| 118 | +| `422_intrabc_sb128_strip_notxsearch.obu` | parent `a7d22aec` | **2** | **8** | **DIFF** | | ||
| 119 | +| `422_intrabc_sb128_strip_notxsearch.obu` | this lane | **6** | **48** | **EXACT** | | ||
| 120 | + | ||
| 121 | +Frame-level detail, per fixture (245760 samples/frame: 384x320 Y + 2 x 192x320 | ||
| 122 | +chroma), re-measured per fixture after review — the first cut of this section | ||
| 123 | +reported the `_notxsearch` arm's counts under the primary witness: | ||
| 124 | + | ||
| 125 | +| fixture | build | f0 | f1 | f2 | f3 | f4 | | ||
| 126 | +|---|---|---|---|---|---|---| | ||
| 127 | +| `422_intrabc_sb128_strip.obu` (primary) | parent `a7d22aec` | **46891** | 0 | 0 | **44842** | 0 | | ||
| 128 | +| `422_intrabc_sb128_strip.obu` (primary) | this lane | 0 | 0 | 0 | 0 | 0 | | ||
| 129 | +| `422_intrabc_sb128_strip_notxsearch.obu` | parent `a7d22aec` | **45135** | 0 | 0 | **44540** | 0 | | ||
| 130 | +| `422_intrabc_sb128_strip_notxsearch.obu` | this lane | 0 | 0 | 0 | 0 | 0 | | ||
| 131 | + | ||
| 132 | +Both fixtures' red first difference is byte 98368 = frame 0, Y **row 256, | ||
| 133 | +col 64** — the top-left of the first 128x64 intrabc block (traced at | ||
| 134 | +`mi_row=64 mi_col=0`, `py = 64*4 = 256`). Frames 1, 2, 4 carry no intrabc | ||
| 135 | +block and are exact in every build. Green: `cmp` identical on all | ||
| 136 | +245760 x 5 bytes, 5 frames decoded, 0 hidden. | ||
| 137 | + | ||
| 138 | +The red build reached only 2 of the 6 blocks: reading 4 chroma units where | ||
| 139 | +libaom codes 8 desynced the tile, and the remaining 4 blocks were misparsed. | ||
| 140 | +Recovering them is the green signal, not just the pixel count. | ||
| 141 | + | ||
| 142 | +`EC_ECDUMP` per-unit stamps on the primary witness, red vs fixed, same entropy | ||
| 143 | +position (`rng=49296` at the first block in both): | ||
| 144 | + | ||
| 145 | + red 4 stamps (1 per plane per chunk, 2 chunks) | ||
| 146 | + fixed 8 stamps (2 per plane per chunk, 2 chunks) | ||
| 147 | + | ||
| 148 | +## Rework after review (r2) — the `mu_chroma` replay's chunk/unit step | ||
| 149 | + | ||
| 150 | +Review r1 FAILed the first cut on a real coverage regression I introduced, and | ||
| 151 | +corrected this report's red counts (done above; the 45135/44540 pair was the | ||
| 152 | +`_notxsearch` arm, the primary's are 46891/44842). | ||
| 153 | + | ||
| 154 | +**The defect.** The first cut gave the replay per-axis *extents* but kept the | ||
| 155 | +old *step*: `rows`/`cols` count mu CHUNKS (`ch / chunk_chroma_h`), while the | ||
| 156 | +loop body advanced the mi origin and read the grid PER UNIT | ||
| 157 | +(`cr * (unit_luma_h / MI)`, grid `(cr * chunk_chroma_h)`). Those agree only when | ||
| 158 | +a chunk holds exactly one unit. At 4:2:0 (`chunk_chroma == cu == 32`) it is | ||
| 159 | +line-identical to the parent, so nothing measured it; at 4:2:2 | ||
| 160 | +(`chunk_chroma_h = 64 = 2 * cu`) the body reached only the FIRST of the two | ||
| 161 | +stacked units per chunk, so rows `mi_r+8 .. mi_r+16` kept the composed-grid | ||
| 162 | +smearing the replay exists to undo. The parent reached those rows (with a wrong | ||
| 163 | +span but full coverage), so this was a coverage regression *my* patch added, | ||
| 164 | +not a pre-existing gap. | ||
| 165 | + | ||
| 166 | +**The reshape**, in the twin's chunk-then-unit loop | ||
| 167 | +(`decode_inter_block`'s `mu_chroma_units`, decode.rs:37456-37494, | ||
| 168 | +lane-av1-444 c8): | ||
| 169 | + | ||
| 170 | + let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w / cu); | ||
| 171 | + for cr in 0..rows { for cc in 0..cols { | ||
| 172 | + for kr in 0..ur { for kc in 0..uc { | ||
| 173 | + unit_mi = (mi_r + (cr * 64 + kr * unit_luma_h) / MI, | ||
| 174 | + mi_c + (cc * 64 + kc * unit_luma_w) / MI); | ||
| 175 | + (cy, cx) = (cr * chunk_chroma_h + kr * cu, cc * chunk_chroma_w + kc * cu); | ||
| 176 | + ... let start = (cy + rr) * cside + cx; | ||
| 177 | + | ||
| 178 | +`cr * 64` is the mu chunk's LUMA-px step, which is 64 on both axes at every | ||
| 179 | +subsampling — that is why the twin can write it unshifted. At 4:2:0 `ur`/`uc` | ||
| 180 | +are 1, so `kr`/`kc` are 0, `unit_mi` collapses to `mi_r + cr*16`, and the grid | ||
| 181 | +origin to `(cr*32, cc*32)`: **line-identical to the pre-rework walk**. The new | ||
| 182 | +gate pins the shape, and the mutation proof below shows it is load-bearing. | ||
| 183 | + | ||
| 184 | +**The LOSSLESS arm is pre-existing and deliberately untouched.** On a lossless | ||
| 185 | +frame `cu` is 4 and the composed grid is a raster of TX_4x4 units, so the | ||
| 186 | +chunk-counted `rows`/`cols` do not enumerate it at all: that arm re-stamps only | ||
| 187 | +the 4x4 at each chunk's top-left with a 2x2-mi span. The twin raster-walks the | ||
| 188 | +whole plane block instead (lane-av1-llinter). It is left as-is on purpose: it is | ||
| 189 | +a **4:2:0** defect, not a subsampling square-cut, so it is out of this lane's | ||
| 190 | +class, and fixing it would change 4:2:0 LOSSLESS output — which this lane's | ||
| 191 | +byte-identity requirement forbids doing on a reconstruction I have no witness | ||
| 192 | +to verify. Measured unreachability: a temporary env-gated counter in the arm | ||
| 193 | +records **0 hits across the whole `lossless` and `intrabc` gate battery** | ||
| 194 | +(13 + 19 tests). Unblock: one lossless sb128 4:2:0 stream coding a NON-SKIP | ||
| 195 | +128-root intrabc strip (`--lossless=1 --sb-size=128 --min-partition-size=64 | ||
| 196 | +--enable-rect-partitions=1 --enable-intrabc=1` over near-match screen | ||
| 197 | +content), then the twin's raster reshape plus a witness. Carried as a named pre-existing, | ||
| 198 | +not as a silent skip. | ||
| 199 | + | ||
| 200 | +**Re-measured after the reshape (r2):** both witnesses byte-identical to | ||
| 201 | +`a7d22aec`-relative tip r1's output (6 blocks, 48 chroma units, 5/5 frames exact | ||
| 202 | +vs `aomdec`) — the reshape is a pure coverage repair, no output change on any | ||
| 203 | +witness. `an_sb128_rect_strip_with_intrabc_decodes_pixel_exact`, | ||
| 204 | +`an_sb128_screen_stream_with_intrabc_decodes_pixel_exact`, | ||
| 205 | +`a_lossless_sb128_rect_intra_block_decodes_sample_exact`, | ||
| 206 | +`a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact`, | ||
| 207 | +`the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name` and both new | ||
| 208 | +gates: **7 passed / 0 failed**. Two mutation proofs on the source-scan arm, | ||
| 209 | +both FAILING it: forcing `let (ur, uc) = (1, 1);` (the per-chunk-only shape) | ||
| 210 | +gives `found 0`; re-introducing `cside * 64 / side` at the read-walk site gives | ||
| 211 | +`left: 1, right: 0`. Restored, the gate passes. | ||
| 212 | + | ||
| 213 | +## Reproduce (patch-run-restore, local only) | ||
| 214 | + | ||
| 215 | + python3 - <<'EOF' | ||
| 216 | + p='crates/ec-av1/src/stream.rs'; s=open(p).read() | ||
| 217 | + s=s.replace(" if seq.subsampling_x != seq.subsampling_y {", | ||
| 218 | + " if seq.subsampling_x != seq.subsampling_y && !crate::envflags::env_flag!(\"EC_AV1_ALLOW_422_PROBE\") {",1) | ||
| 219 | + open(p,'w').write(s) | ||
| 220 | + EOF | ||
| 221 | + CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1ibc128chunk \ | ||
| 222 | + cargo build -p ec-av1 --example decode_probe --features gate-counters | ||
| 223 | + EC_AV1_ALLOW_422_PROBE=1 EC_ECDUMP=1 \ | ||
| 224 | + $HOME/.cache/cargo-target-av1ibc128chunk/debug/examples/decode_probe \ | ||
| 225 | + crates/ec-av1/fixtures/422_intrabc_sb128_strip.obu 2>&1 | grep -c EC_IBC128_STAMP | ||
| 226 | + -> 48 (parent: 8) | ||
| 227 | + EC_AV1_ALLOW_422_PROBE=1 EC_PROBE_OUT=/tmp/ours.raw \ | ||
| 228 | + $HOME/.cache/cargo-target-av1ibc128chunk/debug/examples/decode_probe \ | ||
| 229 | + crates/ec-av1/fixtures/422_intrabc_sb128_strip.obu | ||
| 230 | + ~/.cache/aom-oracle/build/aomdec --rawvideo -o /tmp/oracle.raw \ | ||
| 231 | + crates/ec-av1/fixtures/422_intrabc_sb128_strip.obu | ||
| 232 | + cmp /tmp/ours.raw /tmp/oracle.raw # identical | ||
| 233 | + git checkout -- crates/ec-av1/src/stream.rs | ||
| 234 | + | ||
| 235 | +## Gates | ||
| 236 | + | ||
| 237 | +- `the_pinned_422_intrabc_sb128_strip_witnesses_refuse_by_name` (stream.rs) — | ||
| 238 | + both fixtures' byte pins (`len` + `fnv1a64`) and the unconditional | ||
| 239 | + refusal-by-name contract. The decode-level assertions above cannot run in | ||
| 240 | + committed code (the 4:2:2 refusal stands), so they are probe-measured and | ||
| 241 | + reproducible from the recipe; this is the same split | ||
| 242 | + `the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name` uses. | ||
| 243 | +- `the_intrabc_128rect_chroma_chunk_walk_stays_per_axis` (stream.rs) — the | ||
| 244 | + source-scan arm. Scans `decode_intrabc_128rect`'s body **with comments | ||
| 245 | + stripped** (the fix's own comments quote the old expression to say what it | ||
| 246 | + was) and pins: zero `cside * 64 / side`; the `chunk_chroma_w/h` pair at | ||
| 247 | + **both** de-square-cut sites (read walk and `mu_chroma` replay); the replay's | ||
| 248 | + chunk-then-unit shape (`let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w / | ||
| 249 | + cu);`, `for kr in 0..ur {`, `for kc in 0..uc {` — the r2 coverage fix); the | ||
| 250 | + `unit_luma_w/h`, `cw/ch`, `cpx/cpy` and `around_mi_rect` forms once each; the | ||
| 251 | + replay's own `cu << ss` pair; the per-axis unit arithmetic | ||
| 252 | + (`(64>>ss_x)/32 * (64>>ss_y)/32` = 1 / 2 / 4 at 4:2:0 / 4:2:2 / 4:4:4); and | ||
| 253 | + both new counter accessors. **Non-vacuity measured twice**: forcing | ||
| 254 | + `let (ur, uc) = (1, 1);` (the per-chunk-only shape) fails it with | ||
| 255 | + `found 0`, and re-introducing `let chunk_chroma_w = cside * 64 / side;` at | ||
| 256 | + the read-walk site fails it with `left: 1, right: 0`; restored, it passes. | ||
| 257 | + | ||
| 258 | +## Byte-identity outside 4:2:2 | ||
| 259 | + | ||
| 260 | +- `an_sb128_rect_strip_with_intrabc_decodes_pixel_exact` — **green**, and it | ||
| 261 | + is the right gate: same deterministic `geq` recipe as the witness, at | ||
| 262 | + `yuv420p` / `yuv420p10le`, all three arms decode-order pixel-exact vs the | ||
| 263 | + oracle with `intrabc_128rect_hits=+14 / +1 / +15` (30 blocks through the | ||
| 264 | + changed walk, `skip=false`, real residual reads). At ss (1,1) every new | ||
| 265 | + expression reduces to the old constant: `64 >> 1 = 32`, `32 << 1 = 64`, | ||
| 266 | + `bw >> 1 = bw / 2`, 16x16-mi spans. | ||
| 267 | +- `an_sb128_screen_stream_with_intrabc_decodes_pixel_exact` — green (8 arms, | ||
| 268 | + 4-6 intrabc blocks each). | ||
| 269 | +- `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact` — green. | ||
| 270 | +- `a_lossless_sb128_rect_intra_block_decodes_sample_exact` — green. | ||
| 271 | +- `a_real_aomenc_intrabc_mixed_vartx_tree_decodes_without_the_mixed_leaf_refusal` | ||
| 272 | + and `a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips` — green. | ||
| 273 | +- `the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name` — green | ||
| 274 | + (the twin lane's fixtures are untouched). | ||
| 275 | +- Scoped battery: `intrabc` filter 19 passed / 0 failed / 1 ignored; | ||
| 276 | + `422` + `444` filters 12 passed / 0 failed. `cargo check -p ec-av1 | ||
| 277 | + --all-targets`: 0 warnings. | ||
| 278 | + | ||
| 279 | +**DISCLOSED 4:4:4 behavior change.** At ss (0,0) the walk now codes FOUR | ||
| 280 | +TX_32X32 units per mu chunk per plane (1x1 -> 2x2) where the parent coded one, | ||
| 281 | +and the block's chroma plane block is now luma-sized (`bw x bh`) instead of | ||
| 282 | +`bw/2 x bh/2`. This is the same disclosure lane-av1-422bigblock made for | ||
| 283 | +`decode_block_128rect`: the parent's walk was **provably wrong** at ss (0,0) — | ||
| 284 | +`cside = (side/2).max(...)` is the 4:2:0 half-side, so the old 32x32 chunk | ||
| 285 | +covered a quarter of a 64x64 4:4:4 chroma chunk and the origin `px/2` was off by | ||
| 286 | +half a superblock. Unlike that lane, this one also changes the *block* shape at | ||
| 287 | +4:4:4 (`cw/ch`, `cpx/cpy`), so the ticket's "spans are equal at (0,0)" | ||
| 288 | +premise does not hold for this function, whose extents were 4:2:0-hardcoded | ||
| 289 | +throughout. Measured unreachability: **no committed 4:4:4 fixture engages | ||
| 290 | +`decode_intrabc_128rect` at all** (`ibc128=0` on all six 4:4:4 fixtures | ||
| 291 | +including `444_sb128rect_lr_witness.obu` and `ll444_ibc_rect.obu`), so no | ||
| 292 | +green gate covers or contradicts the change; it is landed on the same geometry | ||
| 293 | +argument that the two reviewed twins landed on, and the 4:4:4 route needs its | ||
| 294 | +own witness (`aomenc --i444 --profile=1 --sb-size=128 --enable-rect-partitions=1 | ||
| 295 | +--enable-intrabc=1` over content that makes aomenc take a 128-root PARTITION_NONE | ||
| 296 | +or HORZ/VERT strip — no committed 4:4:4 fixture does). | ||
| 297 | + | ||
| 298 | +## Hunt recipe sweep (what was tried before the hit) | ||
| 299 | + | ||
| 300 | +`--profile=2 --sb-size=128 --enable-intrabc=1` at 4:2:2, all with | ||
| 301 | +`--i422`, `--tune-content=screen`, `--enable-palette=0`, `--passes=1`, | ||
| 302 | +`--lag-in-frames=0`, `--kf-max-dist=1`, `--min-partition-size=8`, | ||
| 303 | +`--max-partition-size=128`, `--enable-rect-partitions=1`, | ||
| 304 | +`--enable-1to4-partitions=1`: | ||
| 305 | + | ||
| 306 | +- **lavfi `testsrc2 / smptebars / mandelbrot / life / rgbtestsrc / | ||
| 307 | + smptehdbars`, 128x128 and 256x256/384x256/512x256/128x128, `cpu-used` 0/2/3/4, | ||
| 308 | + `cq-level` 15-60, 2x2/3x2/4x4 `tile=`** (24 encodes + 24 x 2 x 8 = ~400 | ||
| 309 | + encodes): 9 streams reached `decode_intrabc_128rect`; **all 9 reached it with | ||
| 310 | + a frame that was ALREADY desynced** before the block. The blocker is | ||
| 311 | + pre-existing and unrelated: at 4:2:2 a chroma tx unit goes non-square | ||
| 312 | + (TX_16X8 etc.) and the merged tree does not read the `tx_type` the oracle | ||
| 313 | + codes for it — first divergence on `c_testsrc2_cq40.obu` at coefficient unit | ||
| 314 | + **4** (plane 1, `mi_row=0 mi_col=0`, `tx_size=5` = TX_16X8: the oracle emits | ||
| 315 | + `tx_type` after `all_zero` where ours goes straight to `eob`, rng 55680 / | ||
| 316 | + 34568 identical up to that point). **Named for its owning lane, not chased | ||
| 317 | + here.** | ||
| 318 | +- **the tree's own gate recipe re-cut at `yuv422p`** (the `geq` sinusoid | ||
| 319 | + sources, 384x320 cq32 and 512x512 cq45, `enable-tx-size-search` 0/1): the | ||
| 320 | + smooth-chroma `geq` content avoids the non-square-chroma-tx defect, and both | ||
| 321 | + cq32 arms are the red/green witnesses above. cq20/45/55 code no 128-root | ||
| 322 | + intrabc block at all (`ibc128=0`), so the hit is a cq32 window, not a | ||
| 323 | + content accident. | ||
| 324 | + | ||
| 325 | +Control that clean 4:2:2 witnesses do exist on this tree (so the "already | ||
| 326 | +desynced" arms above were a content choice, not a tree-wide wall): | ||
| 327 | +`422_sb128_3f.obu` decodes byte-exact vs `aomdec` here. | ||