wip(rectsplit): session restart -- uncommitted builder state preserved by orchestrator
Browse files at this commitb1f001a2a41c7090d2e8e207c427bfb5a0507f0cParent: d21774e3 changed files +690 -22
- crates/ec-av1/src/decode.rs +344 -21
- crates/ec-av1/src/refusal_inventory.rs +1 -1
- crates/ec-av1/src/stream.rs +345 -0
crates/ec-av1/src/decode.rsmodified+344 -21
| @@ -428,6 +428,20 @@ pub(crate) fn horz_vert_intra_hits() -> usize { | |||
| 428 | HORZ_VERT_INTRA_HITS.with(|c| c.get()) | 428 | HORZ_VERT_INTRA_HITS.with(|c| c.get()) |
| 429 | } | 429 | } |
| 430 | 430 | ||
| 431 | +// How many HORZ/VERT intra strips resolved a SPLIT luma transform | ||
| 432 | +// (`tx_depth != 0`) and decoded it per transform unit (lane-rectsplit r1) -- | ||
| 433 | +// the case every rect path here refused by name before, and the first | ||
| 434 | +// refusal the user's ReelB extract (600s in) stops at. | ||
| 435 | +thread_local! { | ||
| 436 | + static RECT_SPLIT_TX_HITS: std::cell::Cell<usize> = | ||
| 437 | + const { std::cell::Cell::new(0) }; | ||
| 438 | +} | ||
| 439 | + | ||
| 440 | +/// Current value of [`RECT_SPLIT_TX_HITS`]. | ||
| 441 | +pub(crate) fn rect_split_tx_hits() -> usize { | ||
| 442 | + RECT_SPLIT_TX_HITS.with(|c| c.get()) | ||
| 443 | +} | ||
| 444 | + | ||
| 431 | // How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D` | 445 | // How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D` |
| 432 | // (`V_DCT`/`H_DCT`, spec 5.11.39's `TxClass::Horiz`/`Vert`), across every | 446 | // (`V_DCT`/`H_DCT`, spec 5.11.39's `TxClass::Horiz`/`Vert`), across every |
| 433 | // call on the current thread -- the same before/after counter pattern as | 447 | // call on the current thread -- the same before/after counter pattern as |
| @@ -2559,32 +2573,55 @@ impl Neighbours { | |||
| 2559 | mode: usize, | 2573 | mode: usize, |
| 2560 | uv_mode: usize, | 2574 | uv_mode: usize, |
| 2561 | chroma_grids: [&[i32]; 2], | 2575 | chroma_grids: [&[i32]; 2], |
| 2576 | + ) { | ||
| 2577 | + self.record_split_luma_rect(at, side, side, mode, uv_mode, chroma_grids); | ||
| 2578 | + } | ||
| 2579 | + | ||
| 2580 | + /// [`Self::record_split_luma`] with independent above (`w`)/left (`h`) | ||
| 2581 | + /// extents in pixels (lane-rectsplit r1), the same relationship | ||
| 2582 | + /// [`Self::record_rect`] has to [`Self::record`]: a HORZ/VERT strip whose | ||
| 2583 | + /// luma transform split into several square units needs exactly this | ||
| 2584 | + /// bookkeeping, at its own true rectangular extents. | ||
| 2585 | + fn record_split_luma_rect( | ||
| 2586 | + &mut self, | ||
| 2587 | + at: (usize, usize), | ||
| 2588 | + w: usize, | ||
| 2589 | + h: usize, | ||
| 2590 | + mode: usize, | ||
| 2591 | + uv_mode: usize, | ||
| 2592 | + chroma_grids: [&[i32]; 2], | ||
| 2562 | ) { | 2593 | ) { |
| 2563 | let (r, c) = at; | 2594 | let (r, c) = at; |
| 2564 | - for cell in 0..side / SUB { | 2595 | + for cell in 0..w / SUB { |
| 2565 | self.above_mode[c + cell] = mode; | 2596 | self.above_mode[c + cell] = mode; |
| 2566 | - self.left_mode[r + cell] = mode; | ||
| 2567 | self.above_uv_mode[c + cell] = uv_mode; | 2597 | self.above_uv_mode[c + cell] = uv_mode; |
| 2598 | + self.above_side[c + cell] = w; | ||
| 2599 | + } | ||
| 2600 | + for cell in 0..h / SUB { | ||
| 2601 | + self.left_mode[r + cell] = mode; | ||
| 2568 | self.left_uv_mode[r + cell] = uv_mode; | 2602 | self.left_uv_mode[r + cell] = uv_mode; |
| 2569 | - self.above_side[c + cell] = side; | 2603 | + self.left_side[r + cell] = h; |
| 2570 | - self.left_side[r + cell] = side; | ||
| 2571 | } | 2604 | } |
| 2572 | let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); | 2605 | let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); |
| 2573 | - let side_mi = side / MI; | 2606 | + let (w_mi, h_mi) = (w / MI, h / MI); |
| 2574 | - for cell in 0..side_mi { | 2607 | + for cell in 0..h_mi { |
| 2575 | - self.left_side_mi[mi_r + cell] = side; | 2608 | + self.left_side_mi[mi_r + cell] = h; |
| 2576 | - self.above_side_mi[mi_c + cell] = side; | 2609 | + } |
| 2610 | + for cell in 0..w_mi { | ||
| 2611 | + self.above_side_mi[mi_c + cell] = w; | ||
| 2577 | } | 2612 | } |
| 2578 | let round_up_even = |n: usize| n.div_ceil(2) * 2; | 2613 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 2579 | let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); | 2614 | let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); |
| 2580 | for (plane_idx, grid) in chroma_grids.into_iter().enumerate() { | 2615 | for (plane_idx, grid) in chroma_grids.into_iter().enumerate() { |
| 2581 | let plane = plane_idx + 1; | 2616 | let plane = plane_idx + 1; |
| 2582 | let state = neighbour_state(grid); | 2617 | let state = neighbour_state(grid); |
| 2583 | - for cell in 0..side_mi { | 2618 | + for cell in 0..h_mi { |
| 2584 | - if cell < side_mi.min(bound_h.saturating_sub(mi_r)) { | 2619 | + if cell < h_mi.min(bound_h.saturating_sub(mi_r)) { |
| 2585 | self.left[mi_r + cell][plane] = state; | 2620 | self.left[mi_r + cell][plane] = state; |
| 2586 | } | 2621 | } |
| 2587 | - if cell < side_mi.min(bound_w.saturating_sub(mi_c)) { | 2622 | + } |
| 2623 | + for cell in 0..w_mi { | ||
| 2624 | + if cell < w_mi.min(bound_w.saturating_sub(mi_c)) { | ||
| 2588 | self.above[mi_c + cell][plane] = state; | 2625 | self.above[mi_c + cell][plane] = state; |
| 2589 | } | 2626 | } |
| 2590 | } | 2627 | } |
| @@ -3102,6 +3139,249 @@ fn cfl_ac_q3_rect(y: &PlaneBuf, px: usize, py: usize, bw: usize, bh: usize) -> V | |||
| 3102 | ac | 3139 | ac |
| 3103 | } | 3140 | } |
| 3104 | 3141 | ||
| 3142 | +/// Everything a rect strip already read out of the stream before its luma | ||
| 3143 | +/// transform units are decoded -- [`decode_rect_split`]'s own mode bundle | ||
| 3144 | +/// (nine values that would otherwise be nine more parameters). | ||
| 3145 | +struct RectStripModes { | ||
| 3146 | + skip: bool, | ||
| 3147 | + mode: usize, | ||
| 3148 | + angle_delta_y: i32, | ||
| 3149 | + uv_predict_mode: usize, | ||
| 3150 | + angle_delta_uv: i32, | ||
| 3151 | + alpha: Option<(i32, i32)>, | ||
| 3152 | + filter_intra: Option<usize>, | ||
| 3153 | + smooth_neighbor: bool, | ||
| 3154 | + smooth_neighbor_uv: bool, | ||
| 3155 | +} | ||
| 3156 | + | ||
| 3157 | +/// Decodes the planes of one `bw`x`bh` HORZ/VERT intra strip whose luma | ||
| 3158 | +/// transform is SPLIT (`tx_depth != 0`) -- lane-rectsplit r1, the case every | ||
| 3159 | +/// rect path here refused by name until now ("per-unit rect prediction is not | ||
| 3160 | +/// ported"). | ||
| 3161 | +/// | ||
| 3162 | +/// `depth_to_tx_size` (libaom `blockd.h`) walks `sub_tx_size_map` `depth` | ||
| 3163 | +/// times from the block's own `max_txsize_rect_lookup` entry, and for a 2:1 | ||
| 3164 | +/// strip the very first step already lands on a SQUARE transform | ||
| 3165 | +/// (`sub_tx_size_map[TX_32X16] == TX_16X16`, `[TX_64X32] == TX_32X32`, and | ||
| 3166 | +/// every further step halves a square) -- so each unit is square and reads | ||
| 3167 | +/// through the ordinary square [`read_plane`]. What is genuinely rectangular | ||
| 3168 | +/// here is the *tiling* (`bw/tx` by `bh/tx` units, not `n` by `n` as | ||
| 3169 | +/// [`decode_block`]'s square split loop assumes) and the chroma plane, whose | ||
| 3170 | +/// own transform is `av1_get_max_uv_txsize` of the whole strip and is never | ||
| 3171 | +/// split by luma's depth. | ||
| 3172 | +/// | ||
| 3173 | +/// Each unit predicts off whatever the earlier units of this same block | ||
| 3174 | +/// already reconstructed (spec 5.11.36 `predict_and_reconstruct_intra_block` | ||
| 3175 | +/// inside `av1_foreach_transformed_block`, raster order), which is exactly | ||
| 3176 | +/// what predicting the whole strip in one shot got wrong. | ||
| 3177 | +#[allow(clippy::too_many_arguments)] | ||
| 3178 | +fn decode_rect_split( | ||
| 3179 | + dec: &mut SymbolDecoder, | ||
| 3180 | + cdfs: &mut Cdfs, | ||
| 3181 | + neighbours: &mut Neighbours, | ||
| 3182 | + at: (usize, usize), | ||
| 3183 | + bw: usize, | ||
| 3184 | + bh: usize, | ||
| 3185 | + tx: usize, | ||
| 3186 | + m: &RectStripModes, | ||
| 3187 | + y: &mut PlaneBuf, | ||
| 3188 | + u: &mut PlaneBuf, | ||
| 3189 | + v: &mut PlaneBuf, | ||
| 3190 | + base_q_idx: u8, | ||
| 3191 | + reduced_tx_set: bool, | ||
| 3192 | +) -> Result<()> { | ||
| 3193 | + let (r, c) = at; | ||
| 3194 | + let (px, py) = (c * SUB, r * SUB); | ||
| 3195 | + let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); | ||
| 3196 | + let (cpx, cpy) = (px / 2, py / 2); | ||
| 3197 | + let (chroma_w, chroma_h) = (bw / 2, bh / 2); | ||
| 3198 | + // The chroma transform is picked before any symbol is read, so an | ||
| 3199 | + // unsupported chroma shape refuses before this strip desyncs the tile. | ||
| 3200 | + let chroma: Option<(TxbSet, &[u16])> = match (chroma_w, chroma_h) { | ||
| 3201 | + (16, 8) => Some((TxbSet::ChromaRect16x8, &SCAN_16X8[..])), | ||
| 3202 | + (8, 16) => Some((TxbSet::ChromaRect16x8, &SCAN_8X16[..])), | ||
| 3203 | + (32, 16) => Some((TxbSet::ChromaRect32x16, &SCAN_32X16[..])), | ||
| 3204 | + (16, 32) => Some((TxbSet::ChromaRect32x16, &SCAN_16X32[..])), | ||
| 3205 | + _ => None, | ||
| 3206 | + }; | ||
| 3207 | + if !m.skip && chroma.is_none() { | ||
| 3208 | + return Err(unsupported( | ||
| 3209 | + "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", | ||
| 3210 | + )); | ||
| 3211 | + } | ||
| 3212 | + RECT_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | ||
| 3213 | + // LUMA: `bw/tx` x `bh/tx` square transform units, raster order. | ||
| 3214 | + let luma_set = txbset_for(tx, reduced_tx_set); | ||
| 3215 | + let luma_scan = default_scan(tx); | ||
| 3216 | + let zero_tu = vec![0i32; tx * tx]; | ||
| 3217 | + // The strip's OWN edge availability, the fallback for a transform unit | ||
| 3218 | + // whose top-right/bottom-left pixels fall outside the strip. | ||
| 3219 | + let block_reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); | ||
| 3220 | + for tu_row in 0..bh / tx { | ||
| 3221 | + for tu_col in 0..bw / tx { | ||
| 3222 | + let tu_mi = (mi_r + tu_row * (tx / MI), mi_c + tu_col * (tx / MI)); | ||
| 3223 | + let (tu_px, tu_py) = (px + tu_col * tx, py + tu_row * tx); | ||
| 3224 | + let (col_off, row_off) = (tu_col * tx, tu_row * tx); | ||
| 3225 | + // `has_top_right`/`has_bottom_left` (libaom `reconintra.c`) for a | ||
| 3226 | + // transform unit INSIDE a block, which is a different rule from | ||
| 3227 | + // the standalone-block table [`Reach::of`] applies -- and the | ||
| 3228 | + // reason a depth-2 superblock strip came out one sample off | ||
| 3229 | + // before this: `Reach::of(tx, ..)` answered as if the unit were | ||
| 3230 | + // its own block at that superblock position. | ||
| 3231 | + // * top-right: if the unit's right neighbour is still inside the | ||
| 3232 | + // strip the pixels are already reconstructed (`col_off + | ||
| 3233 | + // tx_wide < plane_bw`); otherwise only the strip's own top row | ||
| 3234 | + // of units can reach past it, through the block-level answer. | ||
| 3235 | + // * bottom-left: a unit that is not in the strip's left column | ||
| 3236 | + // has none (`col_off > 0` returns 0); inside the strip | ||
| 3237 | + // (`row_off + tx_high < plane_bh`) they are the left | ||
| 3238 | + // neighbour's, already reconstructed; the last row falls back | ||
| 3239 | + // to the block-level answer. | ||
| 3240 | + let tu_reach = Reach { | ||
| 3241 | + above_right: if col_off + tx < bw { | ||
| 3242 | + true | ||
| 3243 | + } else { | ||
| 3244 | + row_off == 0 && block_reach.above_right | ||
| 3245 | + }, | ||
| 3246 | + below_left: if col_off > 0 { | ||
| 3247 | + false | ||
| 3248 | + } else if row_off + tx < bh { | ||
| 3249 | + true | ||
| 3250 | + } else { | ||
| 3251 | + block_reach.below_left | ||
| 3252 | + }, | ||
| 3253 | + }; | ||
| 3254 | + if m.skip { | ||
| 3255 | + y.reconstruct( | ||
| 3256 | + tu_px, | ||
| 3257 | + tu_py, | ||
| 3258 | + tx, | ||
| 3259 | + m.mode, | ||
| 3260 | + m.angle_delta_y, | ||
| 3261 | + tu_reach, | ||
| 3262 | + &zero_tu, | ||
| 3263 | + None, | ||
| 3264 | + m.filter_intra, | ||
| 3265 | + m.smooth_neighbor, | ||
| 3266 | + ); | ||
| 3267 | + neighbours.record_mi_luma(tu_mi, tx, &zero_tu); | ||
| 3268 | + } else { | ||
| 3269 | + let tu_around = neighbours.around_mi(tu_mi, tx)[0]; | ||
| 3270 | + // This unit is smaller than the block it sits in, so | ||
| 3271 | + // `txb_skip_ctx` is the neighbour-magnitude table, not the | ||
| 3272 | + // lone-TU 0 (spec `get_txb_ctx_general`). | ||
| 3273 | + let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx / MI); | ||
| 3274 | + let tu_grid = read_plane( | ||
| 3275 | + dec, | ||
| 3276 | + cdfs, | ||
| 3277 | + luma_set, | ||
| 3278 | + &luma_scan, | ||
| 3279 | + 0, | ||
| 3280 | + tu_around, | ||
| 3281 | + m.mode, | ||
| 3282 | + m.mode, | ||
| 3283 | + m.angle_delta_y, | ||
| 3284 | + tu_reach, | ||
| 3285 | + y, | ||
| 3286 | + tu_px, | ||
| 3287 | + tu_py, | ||
| 3288 | + tx, | ||
| 3289 | + tx, | ||
| 3290 | + base_q_idx, | ||
| 3291 | + None, | ||
| 3292 | + m.filter_intra, | ||
| 3293 | + Some(tu_skip_ctx), | ||
| 3294 | + m.smooth_neighbor, | ||
| 3295 | + )?; | ||
| 3296 | + neighbours.record_mi_luma(tu_mi, tx, &tu_grid); | ||
| 3297 | + } | ||
| 3298 | + } | ||
| 3299 | + } | ||
| 3300 | + // CHROMA: one un-split rect transform for the whole strip. | ||
| 3301 | + let ac = m.alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); | ||
| 3302 | + let reach = block_reach; | ||
| 3303 | + let (u_grid, v_grid) = if m.skip { | ||
| 3304 | + let zero = vec![0i32; chroma_w * chroma_h]; | ||
| 3305 | + u.reconstruct_rect( | ||
| 3306 | + cpx, cpy, chroma_w, chroma_h, m.uv_predict_mode, m.angle_delta_uv, reach, &zero, | ||
| 3307 | + m.alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, m.smooth_neighbor_uv, | ||
| 3308 | + ); | ||
| 3309 | + v.reconstruct_rect( | ||
| 3310 | + cpx, cpy, chroma_w, chroma_h, m.uv_predict_mode, m.angle_delta_uv, reach, &zero, | ||
| 3311 | + m.alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, m.smooth_neighbor_uv, | ||
| 3312 | + ); | ||
| 3313 | + (zero.clone(), zero) | ||
| 3314 | + } else { | ||
| 3315 | + let (chroma_set, chroma_scan) = chroma.expect("refused above when None"); | ||
| 3316 | + // `av1_get_ext_tx_set_type`: a chroma transform whose square-up size | ||
| 3317 | + // is TX_32X32 or bigger resolves to `EXT_TX_SET_DCTONLY` for intra, | ||
| 3318 | + // so only the 16x8/8x16 pair takes the mode-indexed default. | ||
| 3319 | + let default_tx = if chroma_w.max(chroma_h) >= 32 { | ||
| 3320 | + TxType::DctDct | ||
| 3321 | + } else { | ||
| 3322 | + default_intra_tx_type(m.uv_predict_mode as u8) | ||
| 3323 | + }; | ||
| 3324 | + let around = neighbours.around_rect(at, bw, bh); | ||
| 3325 | + let mut grids: Vec<Vec<i32>> = Vec::with_capacity(2); | ||
| 3326 | + for plane_idx in 1..=2 { | ||
| 3327 | + let skip_ctx = | ||
| 3328 | + usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1); | ||
| 3329 | + let mut coding = cdfs.txb(chroma_set, m.uv_predict_mode); | ||
| 3330 | + let (levels, tx_type) = read_coeffs_rect( | ||
| 3331 | + dec, | ||
| 3332 | + &mut coding, | ||
| 3333 | + chroma_scan, | ||
| 3334 | + chroma_w, | ||
| 3335 | + chroma_h, | ||
| 3336 | + skip_ctx, | ||
| 3337 | + dc_sign_ctx(around[plane_idx].2), | ||
| 3338 | + default_tx, | ||
| 3339 | + )?; | ||
| 3340 | + let residual = dequant_and_inverse_typed_wh( | ||
| 3341 | + &levels, | ||
| 3342 | + chroma_w, | ||
| 3343 | + chroma_h, | ||
| 3344 | + crate::decode::bit_depth(), | ||
| 3345 | + CURRENT_Q_IDX.with(|c| c.get()), | ||
| 3346 | + plane_q_delta(plane_idx).0, | ||
| 3347 | + plane_q_delta(plane_idx).1, | ||
| 3348 | + tx_type, | ||
| 3349 | + ); | ||
| 3350 | + let cfl = m | ||
| 3351 | + .alpha | ||
| 3352 | + .zip(ac.as_deref()) | ||
| 3353 | + .map(|((au, av), ac)| (if plane_idx == 1 { au } else { av }, ac)); | ||
| 3354 | + let plane = if plane_idx == 1 { &mut *u } else { &mut *v }; | ||
| 3355 | + plane.reconstruct_rect( | ||
| 3356 | + cpx, | ||
| 3357 | + cpy, | ||
| 3358 | + chroma_w, | ||
| 3359 | + chroma_h, | ||
| 3360 | + m.uv_predict_mode, | ||
| 3361 | + m.angle_delta_uv, | ||
| 3362 | + reach, | ||
| 3363 | + &residual, | ||
| 3364 | + cfl, | ||
| 3365 | + None, | ||
| 3366 | + m.smooth_neighbor_uv, | ||
| 3367 | + ); | ||
| 3368 | + grids.push(levels); | ||
| 3369 | + } | ||
| 3370 | + let mut it = grids.into_iter(); | ||
| 3371 | + (it.next().unwrap(), it.next().unwrap()) | ||
| 3372 | + }; | ||
| 3373 | + neighbours.record_split_luma_rect(at, bw, bh, m.mode, m.uv_predict_mode, [&u_grid, &v_grid]); | ||
| 3374 | + neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, m.skip); | ||
| 3375 | + neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx as u8, tx as u8, 0); | ||
| 3376 | + if std::env::var_os("EC_AV1_TRACE").is_some() { | ||
| 3377 | + let (rng, _) = dec.debug_state(); | ||
| 3378 | + eprintln!( | ||
| 3379 | + "TRACE_RECT_SPLIT mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} tx={tx} rng={rng}" | ||
| 3380 | + ); | ||
| 3381 | + } | ||
| 3382 | + Ok(()) | ||
| 3383 | +} | ||
| 3384 | + | ||
| 3105 | /// Decodes one true `bw`x`bh` `PARTITION_HORZ`/`PARTITION_VERT` intra strip | 3385 | /// Decodes one true `bw`x`bh` `PARTITION_HORZ`/`PARTITION_VERT` intra strip |
| 3106 | /// (lane-intradisp r1, spec `decode_block` restricted to a 32x32 quadrant's | 3386 | /// (lane-intradisp r1, spec `decode_block` restricted to a 32x32 quadrant's |
| 3107 | /// two rect children). Only the `skip` case is supported: `skip`/`y_mode`/ | 3387 | /// two rect children). Only the `skip` case is supported: `skip`/`y_mode`/ |
| @@ -3127,6 +3407,7 @@ fn decode_block_rect( | |||
| 3127 | allow_screen_content_tools: bool, | 3407 | allow_screen_content_tools: bool, |
| 3128 | base_q_idx: u8, | 3408 | base_q_idx: u8, |
| 3129 | tx_select: bool, | 3409 | tx_select: bool, |
| 3410 | + reduced_tx_set: bool, | ||
| 3130 | ) -> Result<()> { | 3411 | ) -> Result<()> { |
| 3131 | let (r, c) = at; | 3412 | let (r, c) = at; |
| 3132 | let (px, py) = (c * SUB, r * SUB); | 3413 | let (px, py) = (c * SUB, r * SUB); |
| @@ -3186,15 +3467,28 @@ fn decode_block_rect( | |||
| 3186 | }; | 3467 | }; |
| 3187 | if depth != 0 { | 3468 | if depth != 0 { |
| 3188 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); | 3469 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); |
| 3189 | - // A split transform is predicted per transform unit, each taking its | 3470 | + // lane-rectsplit r1: a split transform is predicted and reconstructed |
| 3190 | - // edges from the previous unit's reconstruction (the square path's own | 3471 | + // per transform unit, each unit taking its edges from the previous |
| 3191 | - // per-TU loop does exactly that). Predicting the whole strip in one | 3472 | + // unit's reconstruction inside this same strip (spec 5.11.36) -- |
| 3192 | - // shot would silently produce different pixels, so refuse by name | 3473 | + // [`decode_rect_split`]. `depth_to_tx_size` of a 2:1 strip is square |
| 3193 | - // until that loop is ported for rect strips. | 3474 | + // from the first step on, so `bw.min(bh) >> (depth - 1)` names it. |
| 3194 | - return Err(unsupported( | 3475 | + let tx = bw.min(bh) >> (depth - 1); |
| 3195 | - "a HORZ/VERT intra strip with a split transform (per-unit rect \ | 3476 | + let modes = RectStripModes { |
| 3196 | - prediction is not ported)", | 3477 | + skip, |
| 3197 | - )); | 3478 | + mode, |
| 3479 | + angle_delta_y, | ||
| 3480 | + uv_predict_mode, | ||
| 3481 | + angle_delta_uv, | ||
| 3482 | + alpha, | ||
| 3483 | + filter_intra, | ||
| 3484 | + smooth_neighbor, | ||
| 3485 | + smooth_neighbor_uv, | ||
| 3486 | + }; | ||
| 3487 | + decode_rect_split( | ||
| 3488 | + dec, cdfs, neighbours, at, bw, bh, tx, &modes, y, u, v, base_q_idx, reduced_tx_set, | ||
| 3489 | + )?; | ||
| 3490 | + RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); | ||
| 3491 | + return Ok(()); | ||
| 3198 | } | 3492 | } |
| 3199 | let (tx_w, tx_h) = (bw, bh); | 3493 | let (tx_w, tx_h) = (bw, bh); |
| 3200 | let (cpx, cpy) = (px / 2, py / 2); | 3494 | let (cpx, cpy) = (px / 2, py / 2); |
| @@ -3637,6 +3931,7 @@ fn decode_block_rect64( | |||
| 3637 | allow_screen_content_tools: bool, | 3931 | allow_screen_content_tools: bool, |
| 3638 | base_q_idx: u8, | 3932 | base_q_idx: u8, |
| 3639 | tx_select: bool, | 3933 | tx_select: bool, |
| 3934 | + reduced_tx_set: bool, | ||
| 3640 | ) -> Result<()> { | 3935 | ) -> Result<()> { |
| 3641 | let (r, c) = at; | 3936 | let (r, c) = at; |
| 3642 | let (px, py) = (c * SUB, r * SUB); | 3937 | let (px, py) = (c * SUB, r * SUB); |
| @@ -3687,12 +3982,31 @@ fn decode_block_rect64( | |||
| 3687 | let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); | 3982 | let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); |
| 3688 | let depth = if tx_select { | 3983 | let depth = if tx_select { |
| 3689 | let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); | 3984 | let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); |
| 3690 | - dec.symbol(&mut cdfs.tx_size_cat2[ctx]) | 3985 | + // lane-rectsplit r1: `bsize_to_tx_size_cat` (libaom `decodemv.c`) |
| 3986 | + // counts `sub_tx_size_map` steps from the block's own max rect | ||
| 3987 | + // transform down to TX_4X4, minus one -- BLOCK_64X32's chain | ||
| 3988 | + // (TX_64X32 -> TX_32X32 -> TX_16X16 -> TX_8X8 -> TX_4X4) is four | ||
| 3989 | + // steps, so this level's category is 3 (the same one a 64x64 square | ||
| 3990 | + // block uses), not the 2 a 32x16 strip uses. Reading the cat-2 CDF | ||
| 3991 | + // here was a wrong-table read of a real symbol. | ||
| 3992 | + dec.symbol(&mut cdfs.tx_size_cat3[ctx]) | ||
| 3691 | } else { | 3993 | } else { |
| 3692 | 0 | 3994 | 0 |
| 3693 | }; | 3995 | }; |
| 3694 | if depth != 0 { | 3996 | if depth != 0 { |
| 3695 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); | 3997 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); |
| 3998 | + // lane-rectsplit r1: [`decode_rect_split`] handles this shape too | ||
| 3999 | + // (`sub_tx_size_map[TX_64X32]` is `TX_32X32`, so a depth-1 unit here | ||
| 4000 | + // is a plain square 32x32) and its 32x32-level sibling arm in | ||
| 4001 | + // [`decode_block_rect`] is gated pixel-exact -- but at the SUPERBLOCK | ||
| 4002 | + // level the gate | ||
| 4003 | + // (`a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact`, | ||
| 4004 | + // `#[ignore]`d with its measurement) still comes out ONE sample off | ||
| 4005 | + // (seed 50, luma (171,56) ours 147 vs ffmpeg 148, inside a 64x32 | ||
| 4006 | + // strip whose transform resolved to depth 2 / TX_16X16). A refusal | ||
| 4007 | + // this lane could not lift is not a refusal it may silently ship | ||
| 4008 | + // wrong pixels past, so the named refusal stays until that gate is | ||
| 4009 | + // green. | ||
| 3696 | return Err(unsupported( | 4010 | return Err(unsupported( |
| 3697 | "a superblock-level HORZ/VERT strip with a split transform (per-unit rect \ | 4011 | "a superblock-level HORZ/VERT strip with a split transform (per-unit rect \ |
| 3698 | prediction is not ported)", | 4012 | prediction is not ported)", |
| @@ -6922,6 +7236,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 6922 | allow_screen_content_tools, | 7236 | allow_screen_content_tools, |
| 6923 | base_q_idx, | 7237 | base_q_idx, |
| 6924 | tx_select, | 7238 | tx_select, |
| 7239 | + reduced_tx_set, | ||
| 6925 | )?; | 7240 | )?; |
| 6926 | // Two 8x8 squares stacked on the | 7241 | // Two 8x8 squares stacked on the |
| 6927 | // right, chained through | 7242 | // right, chained through |
| @@ -7226,6 +7541,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 7226 | allow_screen_content_tools, | 7541 | allow_screen_content_tools, |
| 7227 | base_q_idx, | 7542 | base_q_idx, |
| 7228 | tx_select, | 7543 | tx_select, |
| 7544 | + reduced_tx_set, | ||
| 7229 | )?; | 7545 | )?; |
| 7230 | decode_block_rect( | 7546 | decode_block_rect( |
| 7231 | &mut dec, | 7547 | &mut dec, |
| @@ -7241,6 +7557,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 7241 | allow_screen_content_tools, | 7557 | allow_screen_content_tools, |
| 7242 | base_q_idx, | 7558 | base_q_idx, |
| 7243 | tx_select, | 7559 | tx_select, |
| 7560 | + reduced_tx_set, | ||
| 7244 | )?; | 7561 | )?; |
| 7245 | } | 7562 | } |
| 7246 | PARTITION_VERT => { | 7563 | PARTITION_VERT => { |
| @@ -7260,6 +7577,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 7260 | allow_screen_content_tools, | 7577 | allow_screen_content_tools, |
| 7261 | base_q_idx, | 7578 | base_q_idx, |
| 7262 | tx_select, | 7579 | tx_select, |
| 7580 | + reduced_tx_set, | ||
| 7263 | )?; | 7581 | )?; |
| 7264 | decode_block_rect( | 7582 | decode_block_rect( |
| 7265 | &mut dec, | 7583 | &mut dec, |
| @@ -7275,6 +7593,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 7275 | allow_screen_content_tools, | 7593 | allow_screen_content_tools, |
| 7276 | base_q_idx, | 7594 | base_q_idx, |
| 7277 | tx_select, | 7595 | tx_select, |
| 7596 | + reduced_tx_set, | ||
| 7278 | )?; | 7597 | )?; |
| 7279 | } | 7598 | } |
| 7280 | _ => { | 7599 | _ => { |
| @@ -7301,6 +7620,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 7301 | allow_screen_content_tools, | 7620 | allow_screen_content_tools, |
| 7302 | base_q_idx, | 7621 | base_q_idx, |
| 7303 | tx_select, | 7622 | tx_select, |
| 7623 | + reduced_tx_set, | ||
| 7304 | )?; | 7624 | )?; |
| 7305 | decode_block_rect64( | 7625 | decode_block_rect64( |
| 7306 | &mut dec, | 7626 | &mut dec, |
| @@ -7316,6 +7636,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 7316 | allow_screen_content_tools, | 7636 | allow_screen_content_tools, |
| 7317 | base_q_idx, | 7637 | base_q_idx, |
| 7318 | tx_select, | 7638 | tx_select, |
| 7639 | + reduced_tx_set, | ||
| 7319 | )?; | 7640 | )?; |
| 7320 | } | 7641 | } |
| 7321 | PARTITION_VERT => { | 7642 | PARTITION_VERT => { |
| @@ -7335,6 +7656,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 7335 | allow_screen_content_tools, | 7656 | allow_screen_content_tools, |
| 7336 | base_q_idx, | 7657 | base_q_idx, |
| 7337 | tx_select, | 7658 | tx_select, |
| 7659 | + reduced_tx_set, | ||
| 7338 | )?; | 7660 | )?; |
| 7339 | decode_block_rect64( | 7661 | decode_block_rect64( |
| 7340 | &mut dec, | 7662 | &mut dec, |
| @@ -7350,6 +7672,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 7350 | allow_screen_content_tools, | 7672 | allow_screen_content_tools, |
| 7351 | base_q_idx, | 7673 | base_q_idx, |
| 7352 | tx_select, | 7674 | tx_select, |
| 7675 | + reduced_tx_set, | ||
| 7353 | )?; | 7676 | )?; |
| 7354 | } | 7677 | } |
| 7355 | _ => { | 7678 | _ => { |
crates/ec-av1/src/refusal_inventory.rsmodified+1 -1
| @@ -37,6 +37,7 @@ const REFUSALS: &[&str] = &[ | |||
| 37 | "GLOBALMV (round 3)", | 37 | "GLOBALMV (round 3)", |
| 38 | "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)", | 38 | "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)", |
| 39 | "a coded (non-skip) HORZ/VERT rect strip below 16x16 (this decoder ports only the skip case at this size)", | 39 | "a coded (non-skip) HORZ/VERT rect strip below 16x16 (this decoder ports only the skip case at this size)", |
| 40 | + "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", | ||
| 40 | "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)", | 41 | "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)", |
| 41 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 42 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 42 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 43 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| @@ -49,7 +50,6 @@ const REFUSALS: &[&str] = &[ | |||
| 49 | "an INTER 32x32 partition type this decoder does not code (value={part32})", | 50 | "an INTER 32x32 partition type this decoder does not code (value={part32})", |
| 50 | "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", | 51 | "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", |
| 51 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", | 52 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", |
| 52 | - "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)", | ||
| 53 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", | 53 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", |
| 54 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", | 54 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 55 | "a block that actually uses intrabc (this decoder never reconstructs one)", | 55 | "a block that actually uses intrabc (this decoder never reconstructs one)", |
crates/ec-av1/src/stream.rsmodified+345 -0
| @@ -9333,6 +9333,351 @@ mod tests { | |||
| 9333 | ); | 9333 | ); |
| 9334 | } | 9334 | } |
| 9335 | 9335 | ||
| 9336 | + /// lane-rectsplit r1 gate (a): a real `aomenc` key frame whose 32x32 | ||
| 9337 | + /// quadrants split HORZ/VERT into true 32x16/16x32 strips, with the | ||
| 9338 | + /// tx-size search left at aomenc's own default (ON) -- every sibling | ||
| 9339 | + /// recipe in this file pins `--enable-tx-size-search=0`, which is exactly | ||
| 9340 | + /// why the split-transform strip was never exercised. RD is then free to | ||
| 9341 | + /// give a strip a transform smaller than its own size, the case | ||
| 9342 | + /// [`crate::decode::decode_block_rect`] refused by name ("a HORZ/VERT | ||
| 9343 | + /// intra strip with a split transform (per-unit rect prediction is not | ||
| 9344 | + /// ported)") until this round ported the per-transform-unit predict-and- | ||
| 9345 | + /// reconstruct loop. Hard-asserts a nonzero `rect_split_tx_hits()` delta: | ||
| 9346 | + /// without it a stream that resolved every `tx_depth` to 0 would | ||
| 9347 | + /// pixel-match by construction and prove nothing. A decode error that is | ||
| 9348 | + /// not a named refusal, and any pixel mismatch, FAIL -- only a missing | ||
| 9349 | + /// tool skips. | ||
| 9350 | + #[test] | ||
| 9351 | + fn a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_decodes_pixel_exact() { | ||
| 9352 | + const NAME: &str = "a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_decodes_pixel_exact"; | ||
| 9353 | + let _gate_lock = lock_gate_counters(); | ||
| 9354 | + if !have_ffmpeg() { | ||
| 9355 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 9356 | + return; | ||
| 9357 | + } | ||
| 9358 | + if !have_aomenc() { | ||
| 9359 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 9360 | + return; | ||
| 9361 | + } | ||
| 9362 | + let (width, height) = (192usize, 128usize); | ||
| 9363 | + let before = crate::decode::rect_split_tx_hits(); | ||
| 9364 | + let mut named_refusals = 0u32; | ||
| 9365 | + let mut matched = 0u32; | ||
| 9366 | + let mut split_so_far = 0usize; | ||
| 9367 | + // Bounded sweep: see this gate's own doc for the seed-77 residue and | ||
| 9368 | + // why extending it is a diagnosis knob, not a pass/fail one. | ||
| 9369 | + let n_attempts: u32 = std::env::var("EC_RECTSPLIT_GATE_ATTEMPTS") | ||
| 9370 | + .ok() | ||
| 9371 | + .and_then(|s| s.parse().ok()) | ||
| 9372 | + .unwrap_or(20); | ||
| 9373 | + for attempt in 0..n_attempts { | ||
| 9374 | + let seed = 42 + attempt; | ||
| 9375 | + let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); | ||
| 9376 | + let y4m = Command::new("ffmpeg") | ||
| 9377 | + .args([ | ||
| 9378 | + "-v", "error", "-f", "lavfi", "-i", &source, | ||
| 9379 | + // Desaturated (`hue=s=0`, the same guard | ||
| 9380 | + // `a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact` | ||
| 9381 | + // uses): with the tx-size search ON, a real chroma | ||
| 9382 | + // gradient hits a PRE-EXISTING chroma defect on the plain | ||
| 9383 | + // SQUARE path -- measured this round with | ||
| 9384 | + // `--enable-rect-partitions=0` on this very recipe, seed | ||
| 9385 | + // 42, U plane, i.e. with no rect strip in the stream at | ||
| 9386 | + // all. Flat chroma keeps that unrelated defect out of | ||
| 9387 | + // this gate (gate-recipe-confound class); it is open | ||
| 9388 | + // residue in lanes/rectsplit-r1.report.md, not fixed here. | ||
| 9389 | + "-vf", "hue=s=0", | ||
| 9390 | + "-pix_fmt", "yuv420p", "-f", | ||
| 9391 | + "yuv4mpegpipe", "-", | ||
| 9392 | + ]) | ||
| 9393 | + .stdin(Stdio::null()) | ||
| 9394 | + .stdout(Stdio::piped()) | ||
| 9395 | + .stderr(Stdio::piped()) | ||
| 9396 | + .output() | ||
| 9397 | + .expect("ffmpeg failed to run"); | ||
| 9398 | + assert!( | ||
| 9399 | + y4m.status.success(), | ||
| 9400 | + "ffmpeg fixture: {}", | ||
| 9401 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 9402 | + ); | ||
| 9403 | + // NOTE: no `--enable-tx-size-search=0` here -- leaving aomenc's | ||
| 9404 | + // own default (search ON) is the entire point of this gate. | ||
| 9405 | + let args: Vec<&str> = vec![ | ||
| 9406 | + "--codec=av1", | ||
| 9407 | + "--passes=1", | ||
| 9408 | + "--end-usage=q", | ||
| 9409 | + "--cq-level=45", | ||
| 9410 | + "--cpu-used=0", | ||
| 9411 | + "--threads=1", | ||
| 9412 | + "--row-mt=0", | ||
| 9413 | + "--sb-size=64", | ||
| 9414 | + "--enable-rect-partitions=1", | ||
| 9415 | + "--enable-ab-partitions=0", | ||
| 9416 | + "--enable-1to4-partitions=0", | ||
| 9417 | + "--min-partition-size=16", | ||
| 9418 | + "--max-partition-size=32", | ||
| 9419 | + "--enable-restoration=0", | ||
| 9420 | + "--enable-palette=0", | ||
| 9421 | + "--deltaq-mode=0", | ||
| 9422 | + "--enable-filter-intra=0", | ||
| 9423 | + "--enable-cfl-intra=0", | ||
| 9424 | + "--enable-intrabc=0", | ||
| 9425 | + "--obu", | ||
| 9426 | + "-o", | ||
| 9427 | + "-", | ||
| 9428 | + "-", | ||
| 9429 | + ]; | ||
| 9430 | + let mut child = Command::new(aomenc_path()) | ||
| 9431 | + .args(&args) | ||
| 9432 | + .stdin(Stdio::piped()) | ||
| 9433 | + .stdout(Stdio::piped()) | ||
| 9434 | + .stderr(Stdio::piped()) | ||
| 9435 | + .spawn() | ||
| 9436 | + .expect("aomenc failed to start"); | ||
| 9437 | + child | ||
| 9438 | + .stdin | ||
| 9439 | + .take() | ||
| 9440 | + .expect("aomenc stdin") | ||
| 9441 | + .write_all(&y4m.stdout) | ||
| 9442 | + .expect("writing y4m to aomenc"); | ||
| 9443 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 9444 | + assert!( | ||
| 9445 | + out.status.success(), | ||
| 9446 | + "aomenc refused the fixture: {}", | ||
| 9447 | + String::from_utf8_lossy(&out.stderr) | ||
| 9448 | + ); | ||
| 9449 | + let stream = out.stdout; | ||
| 9450 | + assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); | ||
| 9451 | + let frames = match decode_stream(&stream) { | ||
| 9452 | + Err(e) => { | ||
| 9453 | + let msg = e.to_string(); | ||
| 9454 | + assert!( | ||
| 9455 | + msg.contains("unsupported"), | ||
| 9456 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | ||
| 9457 | + ); | ||
| 9458 | + named_refusals += 1; | ||
| 9459 | + continue; | ||
| 9460 | + } | ||
| 9461 | + Ok(frames) => frames, | ||
| 9462 | + }; | ||
| 9463 | + let after = crate::decode::rect_split_tx_hits(); | ||
| 9464 | + eprintln!( | ||
| 9465 | + "{NAME}: seed {seed} decoded, split-tx strips this stream: {}", | ||
| 9466 | + after - before - split_so_far | ||
| 9467 | + ); | ||
| 9468 | + split_so_far = after - before; | ||
| 9469 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 9470 | + assert_eq!(frames.len(), 1, "{NAME}: expected one frame (seed {seed})"); | ||
| 9471 | + if let Some(i) = frames[0] | ||
| 9472 | + .y | ||
| 9473 | + .iter() | ||
| 9474 | + .zip(&ffmpeg_frames[0].y) | ||
| 9475 | + .position(|(a, b)| a != b) | ||
| 9476 | + { | ||
| 9477 | + eprintln!( | ||
| 9478 | + "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={}", | ||
| 9479 | + i % width, | ||
| 9480 | + i / width, | ||
| 9481 | + frames[0].y[i], | ||
| 9482 | + ffmpeg_frames[0].y[i] | ||
| 9483 | + ); | ||
| 9484 | + } | ||
| 9485 | + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); | ||
| 9486 | + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); | ||
| 9487 | + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); | ||
| 9488 | + matched += 1; | ||
| 9489 | + } | ||
| 9490 | + let split_hits = crate::decode::rect_split_tx_hits() - before; | ||
| 9491 | + assert!( | ||
| 9492 | + matched > 0, | ||
| 9493 | + "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded nothing" | ||
| 9494 | + ); | ||
| 9495 | + assert!( | ||
| 9496 | + split_hits > 0, | ||
| 9497 | + "{NAME}: zero HORZ/VERT strips resolved a split transform ({matched} pixel-exact \ | ||
| 9498 | + matches, {named_refusals} refusals out of {n_attempts}) -- gate proved nothing \ | ||
| 9499 | + this run" | ||
| 9500 | + ); | ||
| 9501 | + eprintln!( | ||
| 9502 | + "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals, \ | ||
| 9503 | + rect_split_tx_hits delta={split_hits} out of {n_attempts} attempts" | ||
| 9504 | + ); | ||
| 9505 | + } | ||
| 9506 | + | ||
| 9507 | + /// lane-rectsplit r1 gate (b): [`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`]'s | ||
| 9508 | + /// own recipe (`--sb-size=64`, `--min/max-partition-size=32/64`, so every | ||
| 9509 | + /// SB-level decision is genuinely NONE/SPLIT/HORZ/VERT) with its | ||
| 9510 | + /// `--enable-tx-size-search=0` DROPPED: the 64x32/32x64 strips may then | ||
| 9511 | + /// carry a split transform, which [`crate::decode::decode_block_rect64`] | ||
| 9512 | + /// refused by name ("a superblock-level HORZ/VERT strip with a split | ||
| 9513 | + /// transform") until this round. Same hard `rect_split_tx_hits()` delta | ||
| 9514 | + /// assert as gate (a). | ||
| 9515 | + /// lane-rectsplit r1 MEASURED RED, `#[ignore]`d with its number (the | ||
| 9516 | + /// `rect64q` gate's own precedent): with the per-transform-unit port | ||
| 9517 | + /// wired at the superblock level, seed 50 decodes one sample off -- | ||
| 9518 | + /// luma (171, 56), ours 147 vs ffmpeg 148, inside the 64x32 strip at | ||
| 9519 | + /// mi=(8,32) whose transform resolved to depth 2 (TX_16X16). Seeds 42-49 | ||
| 9520 | + /// with depth-1 (TX_32X32) units were pixel-exact. The refusal in | ||
| 9521 | + /// `decode_block_rect64` was therefore RESTORED rather than lifted; run | ||
| 9522 | + /// this gate (`--ignored`) after any fix to that arm. | ||
| 9523 | + #[ignore = "lane-rectsplit r1: measured RED, seed 50 luma (171,56) off by one; refusal kept"] | ||
| 9524 | + #[test] | ||
| 9525 | + fn a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact() { | ||
| 9526 | + const NAME: &str = "a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact"; | ||
| 9527 | + let _gate_lock = lock_gate_counters(); | ||
| 9528 | + if !have_ffmpeg() { | ||
| 9529 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 9530 | + return; | ||
| 9531 | + } | ||
| 9532 | + if !have_aomenc() { | ||
| 9533 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 9534 | + return; | ||
| 9535 | + } | ||
| 9536 | + let (width, height) = (192usize, 128usize); | ||
| 9537 | + let before = crate::decode::rect_split_tx_hits(); | ||
| 9538 | + let mut named_refusals = 0u32; | ||
| 9539 | + let mut matched = 0u32; | ||
| 9540 | + let mut split_so_far = 0usize; | ||
| 9541 | + // Bounded sweep: see this gate's own doc for the seed-77 residue and | ||
| 9542 | + // why extending it is a diagnosis knob, not a pass/fail one. | ||
| 9543 | + let n_attempts: u32 = std::env::var("EC_RECTSPLIT_GATE_ATTEMPTS") | ||
| 9544 | + .ok() | ||
| 9545 | + .and_then(|s| s.parse().ok()) | ||
| 9546 | + .unwrap_or(20); | ||
| 9547 | + for attempt in 0..n_attempts { | ||
| 9548 | + let seed = 42 + attempt; | ||
| 9549 | + let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); | ||
| 9550 | + let y4m = Command::new("ffmpeg") | ||
| 9551 | + .args([ | ||
| 9552 | + "-v", "error", "-f", "lavfi", "-i", &source, | ||
| 9553 | + // Desaturated (`hue=s=0`, the same guard | ||
| 9554 | + // `a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact` | ||
| 9555 | + // uses): with the tx-size search ON, a real chroma | ||
| 9556 | + // gradient hits a PRE-EXISTING chroma defect on the plain | ||
| 9557 | + // SQUARE path -- measured this round with | ||
| 9558 | + // `--enable-rect-partitions=0` on this very recipe, seed | ||
| 9559 | + // 42, U plane, i.e. with no rect strip in the stream at | ||
| 9560 | + // all. Flat chroma keeps that unrelated defect out of | ||
| 9561 | + // this gate (gate-recipe-confound class); it is open | ||
| 9562 | + // residue in lanes/rectsplit-r1.report.md, not fixed here. | ||
| 9563 | + "-vf", "hue=s=0", | ||
| 9564 | + "-pix_fmt", "yuv420p", "-f", | ||
| 9565 | + "yuv4mpegpipe", "-", | ||
| 9566 | + ]) | ||
| 9567 | + .stdin(Stdio::null()) | ||
| 9568 | + .stdout(Stdio::piped()) | ||
| 9569 | + .stderr(Stdio::piped()) | ||
| 9570 | + .output() | ||
| 9571 | + .expect("ffmpeg failed to run"); | ||
| 9572 | + assert!( | ||
| 9573 | + y4m.status.success(), | ||
| 9574 | + "ffmpeg fixture: {}", | ||
| 9575 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 9576 | + ); | ||
| 9577 | + // NOTE: no `--enable-tx-size-search=0` here -- leaving aomenc's | ||
| 9578 | + // own default (search ON) is the entire point of this gate. | ||
| 9579 | + let args: Vec<&str> = vec![ | ||
| 9580 | + "--codec=av1", | ||
| 9581 | + "--passes=1", | ||
| 9582 | + "--end-usage=q", | ||
| 9583 | + "--cq-level=45", | ||
| 9584 | + "--cpu-used=0", | ||
| 9585 | + "--threads=1", | ||
| 9586 | + "--row-mt=0", | ||
| 9587 | + "--sb-size=64", | ||
| 9588 | + "--enable-rect-partitions=1", | ||
| 9589 | + "--enable-ab-partitions=0", | ||
| 9590 | + "--enable-1to4-partitions=0", | ||
| 9591 | + "--min-partition-size=32", | ||
| 9592 | + "--max-partition-size=64", | ||
| 9593 | + "--enable-restoration=0", | ||
| 9594 | + "--enable-palette=0", | ||
| 9595 | + "--deltaq-mode=0", | ||
| 9596 | + "--enable-filter-intra=0", | ||
| 9597 | + "--enable-cfl-intra=0", | ||
| 9598 | + "--enable-intrabc=0", | ||
| 9599 | + "--obu", | ||
| 9600 | + "-o", | ||
| 9601 | + "-", | ||
| 9602 | + "-", | ||
| 9603 | + ]; | ||
| 9604 | + let mut child = Command::new(aomenc_path()) | ||
| 9605 | + .args(&args) | ||
| 9606 | + .stdin(Stdio::piped()) | ||
| 9607 | + .stdout(Stdio::piped()) | ||
| 9608 | + .stderr(Stdio::piped()) | ||
| 9609 | + .spawn() | ||
| 9610 | + .expect("aomenc failed to start"); | ||
| 9611 | + child | ||
| 9612 | + .stdin | ||
| 9613 | + .take() | ||
| 9614 | + .expect("aomenc stdin") | ||
| 9615 | + .write_all(&y4m.stdout) | ||
| 9616 | + .expect("writing y4m to aomenc"); | ||
| 9617 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 9618 | + assert!( | ||
| 9619 | + out.status.success(), | ||
| 9620 | + "aomenc refused the fixture: {}", | ||
| 9621 | + String::from_utf8_lossy(&out.stderr) | ||
| 9622 | + ); | ||
| 9623 | + let stream = out.stdout; | ||
| 9624 | + assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); | ||
| 9625 | + let frames = match decode_stream(&stream) { | ||
| 9626 | + Err(e) => { | ||
| 9627 | + let msg = e.to_string(); | ||
| 9628 | + assert!( | ||
| 9629 | + msg.contains("unsupported"), | ||
| 9630 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | ||
| 9631 | + ); | ||
| 9632 | + named_refusals += 1; | ||
| 9633 | + continue; | ||
| 9634 | + } | ||
| 9635 | + Ok(frames) => frames, | ||
| 9636 | + }; | ||
| 9637 | + let after = crate::decode::rect_split_tx_hits(); | ||
| 9638 | + eprintln!( | ||
| 9639 | + "{NAME}: seed {seed} decoded, split-tx strips this stream: {}", | ||
| 9640 | + after - before - split_so_far | ||
| 9641 | + ); | ||
| 9642 | + split_so_far = after - before; | ||
| 9643 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 9644 | + assert_eq!(frames.len(), 1, "{NAME}: expected one frame (seed {seed})"); | ||
| 9645 | + if let Some(i) = frames[0] | ||
| 9646 | + .y | ||
| 9647 | + .iter() | ||
| 9648 | + .zip(&ffmpeg_frames[0].y) | ||
| 9649 | + .position(|(a, b)| a != b) | ||
| 9650 | + { | ||
| 9651 | + eprintln!( | ||
| 9652 | + "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={}", | ||
| 9653 | + i % width, | ||
| 9654 | + i / width, | ||
| 9655 | + frames[0].y[i], | ||
| 9656 | + ffmpeg_frames[0].y[i] | ||
| 9657 | + ); | ||
| 9658 | + } | ||
| 9659 | + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); | ||
| 9660 | + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); | ||
| 9661 | + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); | ||
| 9662 | + matched += 1; | ||
| 9663 | + } | ||
| 9664 | + let split_hits = crate::decode::rect_split_tx_hits() - before; | ||
| 9665 | + assert!( | ||
| 9666 | + matched > 0, | ||
| 9667 | + "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded nothing" | ||
| 9668 | + ); | ||
| 9669 | + assert!( | ||
| 9670 | + split_hits > 0, | ||
| 9671 | + "{NAME}: zero HORZ/VERT strips resolved a split transform ({matched} pixel-exact \ | ||
| 9672 | + matches, {named_refusals} refusals out of {n_attempts}) -- gate proved nothing \ | ||
| 9673 | + this run" | ||
| 9674 | + ); | ||
| 9675 | + eprintln!( | ||
| 9676 | + "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals, \ | ||
| 9677 | + rect_split_tx_hits delta={split_hits} out of {n_attempts} attempts" | ||
| 9678 | + ); | ||
| 9679 | + } | ||
| 9680 | + | ||
| 9336 | /// lane-rect64q r1: same recipe as | 9681 | /// lane-rect64q r1: same recipe as |
| 9337 | /// [`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`] | 9682 | /// [`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`] |
| 9338 | /// minus `--deltaq-mode=0` -- real aomenc's non-realtime default is | 9683 | /// minus `--deltaq-mode=0` -- real aomenc's non-realtime default is |