wip(scaledref): session restart -- uncommitted builder state preserved by orchestrator
Browse files at this commitc551af173daeee183e141f3e28b1499a06d5a1fbParent: d21774e4 changed files +507 -121
- crates/ec-av1/src/decode.rs +210 -76
- crates/ec-av1/src/mc.rs +80 -43
- crates/ec-av1/src/refusal_inventory.rs +1 -2
- crates/ec-av1/src/stream.rs +216 -0
crates/ec-av1/src/decode.rsmodified+210 -76
| @@ -614,6 +614,46 @@ pub(crate) fn obmc_hits() -> usize { | ||
| 614 | 614 | OBMC_HITS.with(|c| c.get()) |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | +// lane-scaledref r1: per-case firing counts for the scaled-reference gate | |
| 618 | +// (class `gate-blind-to-feature`) -- a pixel match under an UNSCALED | |
| 619 | +// reference would pass just as well and prove nothing, so the gate | |
| 620 | +// hard-asserts each combination this round lifts actually occurred: | |
| 621 | +// a compound block with a scaled tap, a warp block whose warp libaom | |
| 622 | +// suppresses because the reference is scaled, an OBMC block, an interintra | |
| 623 | +// block, and an 8x8 leaf. | |
| 624 | +thread_local! { | |
| 625 | + static SCALED_COMPOUND_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 626 | + static SCALED_WARP_FALLBACK_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 627 | + static SCALED_OBMC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 628 | + static SCALED_INTERINTRA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 629 | + static SCALED_BLOCK8_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 630 | +} | |
| 631 | + | |
| 632 | +/// Current value of [`SCALED_COMPOUND_HITS`]. | |
| 633 | +pub(crate) fn scaled_compound_hits() -> usize { | |
| 634 | + SCALED_COMPOUND_HITS.with(|c| c.get()) | |
| 635 | +} | |
| 636 | + | |
| 637 | +/// Current value of [`SCALED_WARP_FALLBACK_HITS`]. | |
| 638 | +pub(crate) fn scaled_warp_fallback_hits() -> usize { | |
| 639 | + SCALED_WARP_FALLBACK_HITS.with(|c| c.get()) | |
| 640 | +} | |
| 641 | + | |
| 642 | +/// Current value of [`SCALED_OBMC_HITS`]. | |
| 643 | +pub(crate) fn scaled_obmc_hits() -> usize { | |
| 644 | + SCALED_OBMC_HITS.with(|c| c.get()) | |
| 645 | +} | |
| 646 | + | |
| 647 | +/// Current value of [`SCALED_INTERINTRA_HITS`]. | |
| 648 | +pub(crate) fn scaled_interintra_hits() -> usize { | |
| 649 | + SCALED_INTERINTRA_HITS.with(|c| c.get()) | |
| 650 | +} | |
| 651 | + | |
| 652 | +/// Current value of [`SCALED_BLOCK8_HITS`]. | |
| 653 | +pub(crate) fn scaled_block8_hits() -> usize { | |
| 654 | + SCALED_BLOCK8_HITS.with(|c| c.get()) | |
| 655 | +} | |
| 656 | + | |
| 617 | 657 | // lane-motionmode round 3: same proof as [`OBMC_HITS`], narrowed to |
| 618 | 658 | // `decode_inter_block8`'s own 8x8-leaf `read_motion_mode` -- a subset of |
| 619 | 659 | // [`OBMC_HITS`] (both fire together on an 8x8 hit), lets the gate tell an |
| @@ -8180,21 +8220,43 @@ fn obmc_neighbour_pred( | ||
| 8180 | 8220 | luma: bool, |
| 8181 | 8221 | h_kind: mc::InterpFilterKind, |
| 8182 | 8222 | v_kind: mc::InterpFilterKind, |
| 8223 | + // lane-scaledref r1: spec 7.11.3.3's x_scale_fp for THIS neighbour's own | |
| 8224 | + // reference (derived from luma widths, applied unchanged to chroma whose | |
| 8225 | + // x_q4 is already in its own plane's pixel units). `REF_NO_SCALE` takes | |
| 8226 | + // the ordinary stride-1 path bit-exact. | |
| 8227 | + x_scale_fp: i64, | |
| 8183 | 8228 | ) -> Vec<u16> { |
| 8184 | 8229 | let mut out = vec![0u16; w * h]; |
| 8185 | - mc::predict_with_filters( | |
| 8186 | - &refplane.data, | |
| 8187 | - refplane.width, | |
| 8188 | - refplane.true_width, | |
| 8189 | - refplane.true_height, | |
| 8190 | - mv_to_q4(x, mv.1, luma), | |
| 8191 | - mv_to_q4(y, mv.0, luma), | |
| 8192 | - w, | |
| 8193 | - h, | |
| 8194 | - h_kind, | |
| 8195 | - v_kind, | |
| 8196 | - &mut out, | |
| 8197 | - ); | |
| 8230 | + if x_scale_fp == mc::REF_NO_SCALE { | |
| 8231 | + mc::predict_with_filters( | |
| 8232 | + &refplane.data, | |
| 8233 | + refplane.width, | |
| 8234 | + refplane.true_width, | |
| 8235 | + refplane.true_height, | |
| 8236 | + mv_to_q4(x, mv.1, luma), | |
| 8237 | + mv_to_q4(y, mv.0, luma), | |
| 8238 | + w, | |
| 8239 | + h, | |
| 8240 | + h_kind, | |
| 8241 | + v_kind, | |
| 8242 | + &mut out, | |
| 8243 | + ); | |
| 8244 | + } else { | |
| 8245 | + mc::predict_scaled( | |
| 8246 | + &refplane.data, | |
| 8247 | + refplane.width, | |
| 8248 | + refplane.true_width, | |
| 8249 | + refplane.true_height, | |
| 8250 | + mv_to_q4(x, mv.1, luma), | |
| 8251 | + mv_to_q4(y, mv.0, luma), | |
| 8252 | + x_scale_fp, | |
| 8253 | + w, | |
| 8254 | + h, | |
| 8255 | + h_kind, | |
| 8256 | + v_kind, | |
| 8257 | + &mut out, | |
| 8258 | + ); | |
| 8259 | + } | |
| 8198 | 8260 | out |
| 8199 | 8261 | } |
| 8200 | 8262 | |
| @@ -8355,6 +8417,12 @@ fn obmc_blend( | ||
| 8355 | 8417 | ref_v: &PlaneBuf, |
| 8356 | 8418 | other_refs: &RefSlots, |
| 8357 | 8419 | interp_fixed: Option<mc::InterpFilterKind>, |
| 8420 | + // lane-scaledref r1: this frame's own coded luma width -- each OBMC | |
| 8421 | + // neighbour is re-predicted against ITS OWN reference, which may be | |
| 8422 | + // scaled differently from this block's (spec 7.11.3.3 / libaom | |
| 8423 | + // `av1_setup_build_prediction_by_above_pred` passing that ref's own | |
| 8424 | + // `scale_factors`). | |
| 8425 | + frame_width: usize, | |
| 8358 | 8426 | pred_y: &mut [u16], |
| 8359 | 8427 | pred_u: &mut [u16], |
| 8360 | 8428 | pred_v: &mut [u16], |
| @@ -8382,13 +8450,14 @@ fn obmc_blend( | ||
| 8382 | 8450 | neighbours.above_filter[(mi_col + off4) / SUB_MI as usize], |
| 8383 | 8451 | ); |
| 8384 | 8452 | let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; |
| 8453 | + let nb_scale = mc::scale_factor(ny.width, frame_width); | |
| 8385 | 8454 | let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4); |
| 8386 | - let tmp_y = obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, h_kind, v_kind); | |
| 8455 | + let tmp_y = obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, h_kind, v_kind, nb_scale); | |
| 8387 | 8456 | obmc_blend_v(pred_y, side, ox, 0, bw, bh, &tmp_y); |
| 8388 | 8457 | let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2); |
| 8389 | - let tmp_u = obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind); | |
| 8458 | + let tmp_u = obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale); | |
| 8390 | 8459 | obmc_blend_v(pred_u, chroma_side, cox, 0, cbw, cbh, &tmp_u); |
| 8391 | - let tmp_v = obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind); | |
| 8460 | + let tmp_v = obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale); | |
| 8392 | 8461 | obmc_blend_v(pred_v, chroma_side, cox, 0, cbw, cbh, &tmp_v); |
| 8393 | 8462 | } |
| 8394 | 8463 | |
| @@ -8398,13 +8467,14 @@ fn obmc_blend( | ||
| 8398 | 8467 | neighbours.left_filter[(mi_row + off4) / SUB_MI as usize], |
| 8399 | 8468 | ); |
| 8400 | 8469 | let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; |
| 8470 | + let nb_scale = mc::scale_factor(ny.width, frame_width); | |
| 8401 | 8471 | let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4); |
| 8402 | - let tmp_y = obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, h_kind, v_kind); | |
| 8472 | + let tmp_y = obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, h_kind, v_kind, nb_scale); | |
| 8403 | 8473 | obmc_blend_h(pred_y, side, 0, oy, bw, bh, &tmp_y); |
| 8404 | 8474 | let (cbw, cbh, coy) = (overlap_left / 2, bh / 2, oy / 2); |
| 8405 | - let tmp_u = obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind); | |
| 8475 | + let tmp_u = obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale); | |
| 8406 | 8476 | obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, cbh, &tmp_u); |
| 8407 | - let tmp_v = obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind); | |
| 8477 | + let tmp_v = obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale); | |
| 8408 | 8478 | obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, cbh, &tmp_v); |
| 8409 | 8479 | } |
| 8410 | 8480 | Ok(()) |
| @@ -9398,14 +9468,17 @@ fn decode_inter_block( | ||
| 9398 | 9468 | ); |
| 9399 | 9469 | block_filter = resolved_filter; |
| 9400 | 9470 | |
| 9401 | - // lane-superres r9: a scaled reference in a COMPOUND_REFERENCE | |
| 9402 | - // block (either tap) is not wired -- mc::predict_compound_intermediate | |
| 9403 | - // has no scaled counterpart yet -- refuse by name rather than | |
| 9404 | - // silently sample it unscaled. | |
| 9405 | - if py0.width != frame_width || py1.width != frame_width { | |
| 9406 | - return Err(unsupported( | |
| 9407 | - "a compound-reference block with a scaled reference (superres, unimplemented)", | |
| 9408 | - )); | |
| 9471 | + // lane-scaledref r1: each compound tap scales INDEPENDENTLY off | |
| 9472 | + // its own stored reference's luma width (spec 7.11.3.3 derives | |
| 9473 | + // x_scale_fp per reference; libaom `av1_setup_pre_planes` builds | |
| 9474 | + // one `scale_factors` per `ref_frame`), so the two taps can carry | |
| 9475 | + // different ratios in the same block. `REF_NO_SCALE` reduces | |
| 9476 | + // `predict_compound_intermediate`'s walk to the ordinary | |
| 9477 | + // stride-1 one, so the unscaled case is unchanged. | |
| 9478 | + let scale0 = mc::scale_factor(py0.width, frame_width); | |
| 9479 | + let scale1 = mc::scale_factor(py1.width, frame_width); | |
| 9480 | + if scale0 != mc::REF_NO_SCALE || scale1 != mc::REF_NO_SCALE { | |
| 9481 | + SCALED_COMPOUND_HITS.with(|c| c.set(c.get() + 1)); | |
| 9409 | 9482 | } |
| 9410 | 9483 | |
| 9411 | 9484 | let mut inter0_y = vec![0i32; side * side]; |
| @@ -9416,6 +9489,7 @@ fn decode_inter_block( | ||
| 9416 | 9489 | py0.true_height, |
| 9417 | 9490 | mv_to_q4(px, mv0.1, true), |
| 9418 | 9491 | mv_to_q4(py, mv0.0, true), |
| 9492 | + scale0, | |
| 9419 | 9493 | side, |
| 9420 | 9494 | side, |
| 9421 | 9495 | h_filter, |
| @@ -9430,6 +9504,7 @@ fn decode_inter_block( | ||
| 9430 | 9504 | py1.true_height, |
| 9431 | 9505 | mv_to_q4(px, mv1.1, true), |
| 9432 | 9506 | mv_to_q4(py, mv1.0, true), |
| 9507 | + scale1, | |
| 9433 | 9508 | side, |
| 9434 | 9509 | side, |
| 9435 | 9510 | h_filter, |
| @@ -9465,6 +9540,7 @@ fn decode_inter_block( | ||
| 9465 | 9540 | pu0.true_height, |
| 9466 | 9541 | mv_to_q4(cpx, mv0.1, false), |
| 9467 | 9542 | mv_to_q4(cpy, mv0.0, false), |
| 9543 | + scale0, | |
| 9468 | 9544 | chroma_side, |
| 9469 | 9545 | chroma_side, |
| 9470 | 9546 | h_filter, |
| @@ -9479,6 +9555,7 @@ fn decode_inter_block( | ||
| 9479 | 9555 | pu1.true_height, |
| 9480 | 9556 | mv_to_q4(cpx, mv1.1, false), |
| 9481 | 9557 | mv_to_q4(cpy, mv1.0, false), |
| 9558 | + scale1, | |
| 9482 | 9559 | chroma_side, |
| 9483 | 9560 | chroma_side, |
| 9484 | 9561 | h_filter, |
| @@ -9509,6 +9586,7 @@ fn decode_inter_block( | ||
| 9509 | 9586 | pv0.true_height, |
| 9510 | 9587 | mv_to_q4(cpx, mv0.1, false), |
| 9511 | 9588 | mv_to_q4(cpy, mv0.0, false), |
| 9589 | + scale0, | |
| 9512 | 9590 | chroma_side, |
| 9513 | 9591 | chroma_side, |
| 9514 | 9592 | h_filter, |
| @@ -9523,6 +9601,7 @@ fn decode_inter_block( | ||
| 9523 | 9601 | pv1.true_height, |
| 9524 | 9602 | mv_to_q4(cpx, mv1.1, false), |
| 9525 | 9603 | mv_to_q4(cpy, mv1.0, false), |
| 9604 | + scale1, | |
| 9526 | 9605 | chroma_side, |
| 9527 | 9606 | chroma_side, |
| 9528 | 9607 | h_filter, |
| @@ -10091,12 +10170,29 @@ fn decode_inter_block( | ||
| 10091 | 10170 | // (warp_params/obmc_selected/interintra_mode are all resolved by |
| 10092 | 10171 | // this point, every symbol for this block already read). |
| 10093 | 10172 | let luma_scale = mc::scale_factor(py_ref.width, frame_width); |
| 10094 | - if luma_scale != mc::REF_NO_SCALE | |
| 10095 | - && (warp_params.is_some() || obmc_selected || interintra_mode.is_some()) | |
| 10096 | - { | |
| 10097 | - return Err(unsupported( | |
| 10098 | - "warp/OBMC/interintra prediction with a scaled reference (superres, unimplemented)", | |
| 10099 | - )); | |
| 10173 | + if luma_scale != mc::REF_NO_SCALE { | |
| 10174 | + // lane-scaledref r1: libaom `allow_warp` | |
| 10175 | + // (av1/common/reconinter.c:41) suppresses BOTH local and | |
| 10176 | + // global warp under a scaled reference and predicts | |
| 10177 | + // translationally instead -- that fallback is implemented | |
| 10178 | + // below, but the one real aomenc stream this round found | |
| 10179 | + // that reaches it (`--enable-warped-motion=1`, | |
| 10180 | + // `--superres-denominator=16`, seed 47) still mismatches | |
| 10181 | + // ffmpeg at frame 2 luma, so the case stays refused by name | |
| 10182 | + // until it has a green gate rather than shipping wrong | |
| 10183 | + // pixels behind a lifted refusal. | |
| 10184 | + if warp_params.is_some() { | |
| 10185 | + SCALED_WARP_FALLBACK_HITS.with(|c| c.set(c.get() + 1)); | |
| 10186 | + return Err(unsupported( | |
| 10187 | + "warp prediction with a scaled reference (superres, unimplemented)", | |
| 10188 | + )); | |
| 10189 | + } | |
| 10190 | + if obmc_selected { | |
| 10191 | + SCALED_OBMC_HITS.with(|c| c.set(c.get() + 1)); | |
| 10192 | + } | |
| 10193 | + if interintra_mode.is_some() { | |
| 10194 | + SCALED_INTERINTRA_HITS.with(|c| c.set(c.get() + 1)); | |
| 10195 | + } | |
| 10100 | 10196 | } |
| 10101 | 10197 | |
| 10102 | 10198 | let mut pred_y = vec![0u16; side * side]; |
| @@ -10187,7 +10283,13 @@ fn decode_inter_block( | ||
| 10187 | 10283 | ); |
| 10188 | 10284 | } |
| 10189 | 10285 | |
| 10190 | - if let Some(params) = &warp_params { | |
| 10286 | + // lane-scaledref r1: libaom `allow_warp` (av1/common/reconinter.c:41) | |
| 10287 | + // opens with `if (av1_is_scaled(sf)) return 0;` -- BOTH local | |
| 10288 | + // (`wm_params`) and global warp fall back to the translational | |
| 10289 | + // prediction above when the reference is scaled, even though the | |
| 10290 | + // motion_mode symbol was still read and warp_params still | |
| 10291 | + // resolved. Suppress the warp, keep every symbol read. | |
| 10292 | + if let Some(params) = warp_params.as_ref().filter(|_| luma_scale == mc::REF_NO_SCALE) { | |
| 10191 | 10293 | crate::warp::warp_affine( |
| 10192 | 10294 | params, &py_ref.data, py_ref.true_width as i32, py_ref.true_height as i32, |
| 10193 | 10295 | py_ref.width as i32, &mut pred_y, px as i32, py as i32, side as i32, |
| @@ -10228,6 +10330,7 @@ fn decode_inter_block( | ||
| 10228 | 10330 | ref_v, |
| 10229 | 10331 | other_refs, |
| 10230 | 10332 | interp_fixed, |
| 10333 | + frame_width, | |
| 10231 | 10334 | &mut pred_y, |
| 10232 | 10335 | &mut pred_u, |
| 10233 | 10336 | &mut pred_v, |
| @@ -10688,6 +10791,11 @@ fn decode_inter_block8( | ||
| 10688 | 10791 | // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`- |
| 10689 | 10792 | // eligible (`bsize >= BLOCK_8X8`). |
| 10690 | 10793 | allow_screen_content_tools: bool, |
| 10794 | + // lane-scaledref r1: this frame's own coded luma width (spec 7.11.3.3), | |
| 10795 | + // for the scaled-reference MC this leaf's own single-ref/compound/OBMC | |
| 10796 | + // predictions take when a stored reference was coded at another width | |
| 10797 | + // (`use_superres`) -- mirrors [`decode_inter_block`]'s own param. | |
| 10798 | + frame_width: usize, | |
| 10691 | 10799 | ) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>)> { |
| 10692 | 10800 | const LAST_FRAME: i8 = 1; |
| 10693 | 10801 | /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`). |
| @@ -10903,6 +11011,12 @@ fn decode_inter_block8( | ||
| 10903 | 11011 | |
| 10904 | 11012 | let (py0, pu0, pv0) = ref_planes(ref0, ref_y, ref_u, ref_v, other_refs)?; |
| 10905 | 11013 | let (py1, pu1, pv1) = ref_planes(ref1, ref_y, ref_u, ref_v, other_refs)?; |
| 11014 | + let scale0 = mc::scale_factor(py0.width, frame_width); | |
| 11015 | + let scale1 = mc::scale_factor(py1.width, frame_width); | |
| 11016 | + if scale0 != mc::REF_NO_SCALE || scale1 != mc::REF_NO_SCALE { | |
| 11017 | + SCALED_COMPOUND_HITS.with(|c| c.set(c.get() + 1)); | |
| 11018 | + SCALED_BLOCK8_HITS.with(|c| c.set(c.get() + 1)); | |
| 11019 | + } | |
| 10906 | 11020 | |
| 10907 | 11021 | for dr in 0..2 { |
| 10908 | 11022 | for dc in 0..2 { |
| @@ -10939,6 +11053,7 @@ fn decode_inter_block8( | ||
| 10939 | 11053 | py0.true_height, |
| 10940 | 11054 | mv_to_q4(px, mv0.1, true), |
| 10941 | 11055 | mv_to_q4(py, mv0.0, true), |
| 11056 | + scale0, | |
| 10942 | 11057 | SIDE, |
| 10943 | 11058 | SIDE, |
| 10944 | 11059 | Regular, |
| @@ -10953,6 +11068,7 @@ fn decode_inter_block8( | ||
| 10953 | 11068 | py1.true_height, |
| 10954 | 11069 | mv_to_q4(px, mv1.1, true), |
| 10955 | 11070 | mv_to_q4(py, mv1.0, true), |
| 11071 | + scale1, | |
| 10956 | 11072 | SIDE, |
| 10957 | 11073 | SIDE, |
| 10958 | 11074 | Regular, |
| @@ -10984,6 +11100,7 @@ fn decode_inter_block8( | ||
| 10984 | 11100 | pu0.true_height, |
| 10985 | 11101 | mv_to_q4(cpx, mv0.1, false), |
| 10986 | 11102 | mv_to_q4(cpy, mv0.0, false), |
| 11103 | + scale0, | |
| 10987 | 11104 | CHROMA_SIDE, |
| 10988 | 11105 | CHROMA_SIDE, |
| 10989 | 11106 | Regular, |
| @@ -10998,6 +11115,7 @@ fn decode_inter_block8( | ||
| 10998 | 11115 | pu1.true_height, |
| 10999 | 11116 | mv_to_q4(cpx, mv1.1, false), |
| 11000 | 11117 | mv_to_q4(cpy, mv1.0, false), |
| 11118 | + scale1, | |
| 11001 | 11119 | CHROMA_SIDE, |
| 11002 | 11120 | CHROMA_SIDE, |
| 11003 | 11121 | Regular, |
| @@ -11028,6 +11146,7 @@ fn decode_inter_block8( | ||
| 11028 | 11146 | pv0.true_height, |
| 11029 | 11147 | mv_to_q4(cpx, mv0.1, false), |
| 11030 | 11148 | mv_to_q4(cpy, mv0.0, false), |
| 11149 | + scale0, | |
| 11031 | 11150 | CHROMA_SIDE, |
| 11032 | 11151 | CHROMA_SIDE, |
| 11033 | 11152 | Regular, |
| @@ -11042,6 +11161,7 @@ fn decode_inter_block8( | ||
| 11042 | 11161 | pv1.true_height, |
| 11043 | 11162 | mv_to_q4(cpx, mv1.1, false), |
| 11044 | 11163 | mv_to_q4(cpy, mv1.0, false), |
| 11164 | + scale1, | |
| 11045 | 11165 | CHROMA_SIDE, |
| 11046 | 11166 | CHROMA_SIDE, |
| 11047 | 11167 | Regular, |
| @@ -11315,42 +11435,51 @@ fn decode_inter_block8( | ||
| 11315 | 11435 | } |
| 11316 | 11436 | mode_for_tx = 0; |
| 11317 | 11437 | |
| 11438 | + // lane-scaledref r1: this leaf's own prediction is always `Regular` | |
| 11439 | + // (documented corner-cut above); under a scaled reference the same | |
| 11440 | + // fixed kernel runs through spec 7.11.3.3's scaled walk instead. | |
| 11441 | + let luma_scale = mc::scale_factor(ref_y.width, frame_width); | |
| 11442 | + if luma_scale != mc::REF_NO_SCALE { | |
| 11443 | + SCALED_BLOCK8_HITS.with(|c| c.set(c.get() + 1)); | |
| 11444 | + } | |
| 11318 | 11445 | let mut pred_y = vec![0u16; SIDE * SIDE]; |
| 11319 | - mc::predict( | |
| 11320 | - &ref_y.data, | |
| 11321 | - ref_y.width, | |
| 11322 | - ref_y.true_width, | |
| 11323 | - ref_y.true_height, | |
| 11324 | - mv_to_q4(px, mv.1, true), | |
| 11325 | - mv_to_q4(py, mv.0, true), | |
| 11326 | - SIDE, | |
| 11327 | - SIDE, | |
| 11328 | - &mut pred_y, | |
| 11329 | - ); | |
| 11330 | 11446 | let mut pred_u = vec![0u16; CHROMA_SIDE * CHROMA_SIDE]; |
| 11331 | - mc::predict( | |
| 11332 | - &ref_u.data, | |
| 11333 | - ref_u.width, | |
| 11334 | - ref_u.true_width, | |
| 11335 | - ref_u.true_height, | |
| 11336 | - mv_to_q4(cpx, mv.1, false), | |
| 11337 | - mv_to_q4(cpy, mv.0, false), | |
| 11338 | - CHROMA_SIDE, | |
| 11339 | - CHROMA_SIDE, | |
| 11340 | - &mut pred_u, | |
| 11341 | - ); | |
| 11342 | 11447 | let mut pred_v = vec![0u16; CHROMA_SIDE * CHROMA_SIDE]; |
| 11343 | - mc::predict( | |
| 11344 | - &ref_v.data, | |
| 11345 | - ref_v.width, | |
| 11346 | - ref_v.true_width, | |
| 11347 | - ref_v.true_height, | |
| 11348 | - mv_to_q4(cpx, mv.1, false), | |
| 11349 | - mv_to_q4(cpy, mv.0, false), | |
| 11350 | - CHROMA_SIDE, | |
| 11351 | - CHROMA_SIDE, | |
| 11352 | - &mut pred_v, | |
| 11353 | - ); | |
| 11448 | + for (plane, x, y, dim, dst) in [ | |
| 11449 | + (ref_y, px, py, SIDE, &mut pred_y), | |
| 11450 | + (ref_u, cpx, cpy, CHROMA_SIDE, &mut pred_u), | |
| 11451 | + (ref_v, cpx, cpy, CHROMA_SIDE, &mut pred_v), | |
| 11452 | + ] { | |
| 11453 | + let luma = std::ptr::eq(plane, ref_y); | |
| 11454 | + if luma_scale == mc::REF_NO_SCALE { | |
| 11455 | + mc::predict( | |
| 11456 | + &plane.data, | |
| 11457 | + plane.width, | |
| 11458 | + plane.true_width, | |
| 11459 | + plane.true_height, | |
| 11460 | + mv_to_q4(x, mv.1, luma), | |
| 11461 | + mv_to_q4(y, mv.0, luma), | |
| 11462 | + dim, | |
| 11463 | + dim, | |
| 11464 | + dst, | |
| 11465 | + ); | |
| 11466 | + } else { | |
| 11467 | + mc::predict_scaled( | |
| 11468 | + &plane.data, | |
| 11469 | + plane.width, | |
| 11470 | + plane.true_width, | |
| 11471 | + plane.true_height, | |
| 11472 | + mv_to_q4(x, mv.1, luma), | |
| 11473 | + mv_to_q4(y, mv.0, luma), | |
| 11474 | + luma_scale, | |
| 11475 | + dim, | |
| 11476 | + dim, | |
| 11477 | + mc::InterpFilterKind::Regular, | |
| 11478 | + mc::InterpFilterKind::Regular, | |
| 11479 | + dst, | |
| 11480 | + ); | |
| 11481 | + } | |
| 11482 | + } | |
| 11354 | 11483 | |
| 11355 | 11484 | if obmc_selected { |
| 11356 | 11485 | obmc_blend( |
| @@ -11375,6 +11504,7 @@ fn decode_inter_block8( | ||
| 11375 | 11504 | ref_v, |
| 11376 | 11505 | other_refs, |
| 11377 | 11506 | interp_fixed, |
| 11507 | + frame_width, | |
| 11378 | 11508 | &mut pred_y, |
| 11379 | 11509 | &mut pred_u, |
| 11380 | 11510 | &mut pred_v, |
| @@ -12282,15 +12412,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 12282 | 12412 | .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) |
| 12283 | 12413 | .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) |
| 12284 | 12414 | .collect(); |
| 12285 | - // lane-superres r9: decode_inter_block8's own | |
| 12286 | - // MC (below) is not threaded for a scaled | |
| 12287 | - // reference (unlike decode_inter_block's 19 | |
| 12288 | - // sites) -- refuse the whole 8x8-leaf split | |
| 12289 | - // up front when ANY live reference this leaf | |
| 12290 | - // could pick has a different width than this | |
| 12291 | - // frame, rather than thread frame_width | |
| 12292 | - // through its own single-ref/compound MC | |
| 12293 | - // calls to reach the same block this round. | |
| 12415 | + // lane-scaledref r1: `decode_inter_block8` IS | |
| 12416 | + // threaded for a scaled reference now (its | |
| 12417 | + // single-ref, compound and OBMC MC all take | |
| 12418 | + // spec 7.11.3.3's scaled walk), but no aomenc | |
| 12419 | + // recipe this round produced a single 8x8 | |
| 12420 | + // inter leaf -- gradients never splits below | |
| 12421 | + // 16x16 (same wall as | |
| 12422 | + // `a_real_aomenc_stream_with_obmc_8x8_decodes_pixel_exact`). | |
| 12423 | + // An ungated lift is a capability claim | |
| 12424 | + // nothing exercises, so the refusal stays | |
| 12425 | + // until a firing fixture exists; deleting | |
| 12426 | + // these six lines is then the whole change. | |
| 12294 | 12427 | if ref_y.width != frame_width as usize |
| 12295 | 12428 | || ref_slots.iter().flatten().any(|(py, _, _)| { |
| 12296 | 12429 | py.width != frame_width as usize |
| @@ -12349,6 +12482,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 12349 | 12482 | switchable_motion_mode, |
| 12350 | 12483 | allow_warped_motion, |
| 12351 | 12484 | allow_screen_content_tools, |
| 12485 | + frame_width as usize, | |
| 12352 | 12486 | )?; |
| 12353 | 12487 | prev_leaf = Some((leaf_mi, skip, is_inter)); |
| 12354 | 12488 | last_skip_mode = skip_mode_leaf; |
crates/ec-av1/src/mc.rsmodified+80 -43
| @@ -461,6 +461,54 @@ fn round_pow2_signed_64(value: i64, shift: u32) -> i64 { | ||
| 461 | 461 | } |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | +/// Spec 7.11.3.3's horizontal pass on a (possibly) scaled reference, shared | |
| 465 | +/// by [`predict_scaled`] and [`predict_compound_intermediate`] -- the two | |
| 466 | +/// differ only in their VERTICAL rounding ([`INTER_ROUND_1`] vs | |
| 467 | +/// [`INTER_ROUND_1_COMPOUND`]), never here. Each output column walks the | |
| 468 | +/// reference by `x_step_qn` (the Q14 scale rounded down to the Q10 | |
| 469 | +/// `SCALE_SUBPEL_BITS` grid) and picks its own filter phase from the low | |
| 470 | +/// bits, so `x_scale_fp == REF_NO_SCALE` reduces to the ordinary stride-1 | |
| 471 | +/// whole-pel walk with one fixed phase (pinned by | |
| 472 | +/// `predict_scaled_at_no_scale_matches_predict_with_filters`). | |
| 473 | +#[allow(clippy::too_many_arguments)] | |
| 474 | +fn horizontal_scaled_pass( | |
| 475 | + reference: &[u16], | |
| 476 | + stride: usize, | |
| 477 | + true_width: usize, | |
| 478 | + true_height: usize, | |
| 479 | + x_q4: i32, | |
| 480 | + y0: i32, | |
| 481 | + x_scale_fp: i64, | |
| 482 | + block_w: usize, | |
| 483 | + rows: usize, | |
| 484 | + h_kind: InterpFilterKind, | |
| 485 | + intermediate: &mut [i32], | |
| 486 | +) { | |
| 487 | + let x_step_qn = round_pow2_64(x_scale_fp, 4); | |
| 488 | + let off = (x_scale_fp - REF_NO_SCALE) * 8; | |
| 489 | + let pos_x_q10 = round_pow2_signed_64(x_q4 as i64 * x_scale_fp + off, 8) + 32; | |
| 490 | + let (h_wide, h_narrow) = h_kind.tables(); | |
| 491 | + for c in 0..block_w { | |
| 492 | + let x_qn = pos_x_q10 + c as i64 * x_step_qn; | |
| 493 | + let int_pel = (x_qn >> 10) as i32; | |
| 494 | + let filter_idx = ((x_qn & 1023) >> 6) as usize; | |
| 495 | + let h_filter = if block_w <= 4 { | |
| 496 | + &h_narrow[filter_idx] | |
| 497 | + } else { | |
| 498 | + &h_wide[filter_idx] | |
| 499 | + }; | |
| 500 | + for r in 0..rows { | |
| 501 | + let y = y0 - 3 + r as i32; | |
| 502 | + let mut sum = 0; | |
| 503 | + for (t, &tap) in h_filter.iter().enumerate() { | |
| 504 | + let x = int_pel + t as i32 - 3; | |
| 505 | + sum += tap * sample(reference, stride, true_width, true_height, x, y); | |
| 506 | + } | |
| 507 | + intermediate[r * block_w + c] = round2(sum, INTER_ROUND_0); | |
| 508 | + } | |
| 509 | + } | |
| 510 | +} | |
| 511 | + | |
| 464 | 512 | /// [`predict_with_filters`]'s scaled-reference counterpart (spec 7.11.3.3): |
| 465 | 513 | /// used only when the stored reference's luma width differs from the current |
| 466 | 514 | /// frame's (`use_superres` on a non-key frame). `x_scale_fp` is |
| @@ -500,11 +548,6 @@ pub fn predict_scaled( | ||
| 500 | 548 | // SCALE_SUBPEL_BITS == 10: x_step_qn is x_scale_fp (Q14) rounded down to |
| 501 | 549 | // Q10; off/pos_x_q10 fold the block's own x_q4 (Q4) into that same Q10 |
| 502 | 550 | // grid (spec 7.11.3.3's `dec_calc_subpel_params`). |
| 503 | - let x_step_qn = round_pow2_64(x_scale_fp, 4); | |
| 504 | - let off = (x_scale_fp - REF_NO_SCALE) * 8; | |
| 505 | - let pos_x_q10 = round_pow2_signed_64(x_q4 as i64 * x_scale_fp + off, 8) + 32; | |
| 506 | - | |
| 507 | - let (h_wide, h_narrow) = h_kind.tables(); | |
| 508 | 551 | let (v_wide, v_narrow) = v_kind.tables(); |
| 509 | 552 | let v_filter = if block_h <= 4 { |
| 510 | 553 | &v_narrow[yfrac] |
| @@ -514,25 +557,19 @@ pub fn predict_scaled( | ||
| 514 | 557 | |
| 515 | 558 | let rows = block_h + 7; |
| 516 | 559 | let mut intermediate = vec![0i32; rows * block_w]; |
| 517 | - for c in 0..block_w { | |
| 518 | - let x_qn = pos_x_q10 + c as i64 * x_step_qn; | |
| 519 | - let int_pel = (x_qn >> 10) as i32; | |
| 520 | - let filter_idx = ((x_qn & 1023) >> 6) as usize; | |
| 521 | - let h_filter = if block_w <= 4 { | |
| 522 | - &h_narrow[filter_idx] | |
| 523 | - } else { | |
| 524 | - &h_wide[filter_idx] | |
| 525 | - }; | |
| 526 | - for r in 0..rows { | |
| 527 | - let y = y0 - 3 + r as i32; | |
| 528 | - let mut sum = 0; | |
| 529 | - for (t, &tap) in h_filter.iter().enumerate() { | |
| 530 | - let x = int_pel + t as i32 - 3; | |
| 531 | - sum += tap * sample(reference, stride, true_width, true_height, x, y); | |
| 532 | - } | |
| 533 | - intermediate[r * block_w + c] = round2(sum, INTER_ROUND_0); | |
| 534 | - } | |
| 535 | - } | |
| 560 | + horizontal_scaled_pass( | |
| 561 | + reference, | |
| 562 | + stride, | |
| 563 | + true_width, | |
| 564 | + true_height, | |
| 565 | + x_q4, | |
| 566 | + y0, | |
| 567 | + x_scale_fp, | |
| 568 | + block_w, | |
| 569 | + rows, | |
| 570 | + h_kind, | |
| 571 | + &mut intermediate, | |
| 572 | + ); | |
| 536 | 573 | |
| 537 | 574 | for row in 0..block_h { |
| 538 | 575 | for col in 0..block_w { |
| @@ -586,6 +623,7 @@ pub fn predict_compound_intermediate( | ||
| 586 | 623 | true_height: usize, |
| 587 | 624 | x_q4: i32, |
| 588 | 625 | y_q4: i32, |
| 626 | + x_scale_fp: i64, | |
| 589 | 627 | block_w: usize, |
| 590 | 628 | block_h: usize, |
| 591 | 629 | h_kind: InterpFilterKind, |
| @@ -595,18 +633,14 @@ pub fn predict_compound_intermediate( | ||
| 595 | 633 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); |
| 596 | 634 | assert!(!reference.is_empty(), "a reference plane has samples"); |
| 597 | 635 | |
| 598 | - let x0 = x_q4.div_euclid(16); | |
| 599 | - let xfrac = x_q4.rem_euclid(16) as usize; | |
| 636 | + if x_scale_fp != REF_NO_SCALE { | |
| 637 | + PREDICT_SCALED_HITS.with(|c| c.set(c.get() + 1)); | |
| 638 | + } | |
| 639 | + | |
| 600 | 640 | let y0 = y_q4.div_euclid(16); |
| 601 | 641 | let yfrac = y_q4.rem_euclid(16) as usize; |
| 602 | 642 | |
| 603 | - let (h_wide, h_narrow) = h_kind.tables(); | |
| 604 | 643 | let (v_wide, v_narrow) = v_kind.tables(); |
| 605 | - let h_filter = if block_w <= 4 { | |
| 606 | - &h_narrow[xfrac] | |
| 607 | - } else { | |
| 608 | - &h_wide[xfrac] | |
| 609 | - }; | |
| 610 | 644 | let v_filter = if block_h <= 4 { |
| 611 | 645 | &v_narrow[yfrac] |
| 612 | 646 | } else { |
| @@ -615,17 +649,19 @@ pub fn predict_compound_intermediate( | ||
| 615 | 649 | |
| 616 | 650 | let rows = block_h + 7; |
| 617 | 651 | let mut intermediate = vec![0i32; rows * block_w]; |
| 618 | - for r in 0..rows { | |
| 619 | - let y = y0 - 3 + r as i32; | |
| 620 | - for c in 0..block_w { | |
| 621 | - let mut sum = 0; | |
| 622 | - for (t, &tap) in h_filter.iter().enumerate() { | |
| 623 | - let x = x0 + c as i32 + t as i32 - 3; | |
| 624 | - sum += tap * sample(reference, stride, true_width, true_height, x, y); | |
| 625 | - } | |
| 626 | - intermediate[r * block_w + c] = round2(sum, INTER_ROUND_0); | |
| 627 | - } | |
| 628 | - } | |
| 652 | + horizontal_scaled_pass( | |
| 653 | + reference, | |
| 654 | + stride, | |
| 655 | + true_width, | |
| 656 | + true_height, | |
| 657 | + x_q4, | |
| 658 | + y0, | |
| 659 | + x_scale_fp, | |
| 660 | + block_w, | |
| 661 | + rows, | |
| 662 | + h_kind, | |
| 663 | + &mut intermediate, | |
| 664 | + ); | |
| 629 | 665 | |
| 630 | 666 | for row in 0..block_h { |
| 631 | 667 | for col in 0..block_w { |
| @@ -744,6 +780,7 @@ fn compound_intermediate_whole_pel_identity_round_trips_through_combine() { | ||
| 744 | 780 | 16, |
| 745 | 781 | 0, |
| 746 | 782 | 0, |
| 783 | + REF_NO_SCALE, | |
| 747 | 784 | 4, |
| 748 | 785 | 4, |
| 749 | 786 | InterpFilterKind::Regular, |
crates/ec-av1/src/refusal_inventory.rsmodified+1 -2
| @@ -72,8 +72,7 @@ const REFUSALS: &[&str] = &[ | ||
| 72 | 72 | "an intra mode this decoder does not code (round 2)", |
| 73 | 73 | "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet", |
| 74 | 74 | "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", |
| 75 | - "a compound-reference block with a scaled reference (superres, unimplemented)", | |
| 76 | - "warp/OBMC/interintra prediction with a scaled reference (superres, unimplemented)", | |
| 75 | + "warp prediction with a scaled reference (superres, unimplemented)", | |
| 77 | 76 | "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", |
| 78 | 77 | ]; |
| 79 | 78 |
crates/ec-av1/src/stream.rsmodified+216 -0
| @@ -5025,6 +5025,222 @@ mod tests { | ||
| 5025 | 5025 | ); |
| 5026 | 5026 | } |
| 5027 | 5027 | |
| 5028 | + /// lane-scaledref r1: a real aomenc `--superres-mode=1` sequence with | |
| 5029 | + /// compound, OBMC, interintra and 8x8 leaves ALL enabled must decode | |
| 5030 | + /// pixel-exact -- these are the combinations the three | |
| 5031 | + /// "... with a scaled reference (superres, unimplemented)" refusals used | |
| 5032 | + /// to cover. Each combination gets its OWN hard-asserted hit counter | |
| 5033 | + /// (`crate::decode::scaled_*_hits`), because an unscaled reference would | |
| 5034 | + /// pass the pixels and prove nothing (class `gate-blind-to-feature`), and | |
| 5035 | + /// a stream that scales but never takes compound/OBMC/interintra/8x8 | |
| 5036 | + /// would prove nothing about the code this round adds either. A refusal | |
| 5037 | + /// naming a scaled reference is a hard failure: those are exactly the | |
| 5038 | + /// strings this round lifts. Other named capabilities skip that seed. | |
| 5039 | + #[test] | |
| 5040 | + fn a_real_aomenc_superres_stream_with_compound_obmc_and_interintra_decodes_pixel_exact() | |
| 5041 | + { | |
| 5042 | + const NAME: &str = "a_real_aomenc_superres_stream_with_compound_obmc_and_interintra_decodes_pixel_exact"; | |
| 5043 | + let _gate_lock = lock_gate_counters(); | |
| 5044 | + if !have_ffmpeg() { | |
| 5045 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 5046 | + return; | |
| 5047 | + } | |
| 5048 | + if !have_aomenc() { | |
| 5049 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 5050 | + return; | |
| 5051 | + } | |
| 5052 | + let (width, height, frame_count) = (64usize, 64usize, 24usize); | |
| 5053 | + let mut named_refusals = 0u32; | |
| 5054 | + let mut matched = 0u32; | |
| 5055 | + let n_attempts: u32 = std::env::var("EC_SCALEDREF_GATE_ATTEMPTS") | |
| 5056 | + .ok() | |
| 5057 | + .and_then(|s| s.parse().ok()) | |
| 5058 | + .unwrap_or(12); | |
| 5059 | + for attempt in 0..n_attempts { | |
| 5060 | + let seed = 42 + attempt; | |
| 5061 | + let duration = frame_count as f64 / 25.0; | |
| 5062 | + let source = | |
| 5063 | + gradients_source(seed, width, height, &format!("duration={duration}:rate=25")); | |
| 5064 | + let y4m = Command::new("ffmpeg") | |
| 5065 | + .args([ | |
| 5066 | + "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", | |
| 5067 | + "yuv4mpegpipe", "-", | |
| 5068 | + ]) | |
| 5069 | + .stdin(Stdio::null()) | |
| 5070 | + .stdout(Stdio::piped()) | |
| 5071 | + .stderr(Stdio::piped()) | |
| 5072 | + .output() | |
| 5073 | + .expect("ffmpeg failed to run"); | |
| 5074 | + assert!( | |
| 5075 | + y4m.status.success(), | |
| 5076 | + "ffmpeg fixture: {}", | |
| 5077 | + String::from_utf8_lossy(&y4m.stderr) | |
| 5078 | + ); | |
| 5079 | + let on = |name: &str| { | |
| 5080 | + if std::env::var(name).as_deref() == Ok("0") { "0" } else { "1" } | |
| 5081 | + }; | |
| 5082 | + // warp stays OFF: warp under a scaled reference is still refused | |
| 5083 | + // (its own fallback mismatches, see decode.rs) -- set | |
| 5084 | + // EC_SCALEDREF_WARP=1 to reproduce that residue. | |
| 5085 | + let warp = format!( | |
| 5086 | + "--enable-warped-motion={}", | |
| 5087 | + if std::env::var("EC_SCALEDREF_WARP").as_deref() == Ok("1") { "1" } else { "0" } | |
| 5088 | + ); | |
| 5089 | + let obmc = format!("--enable-obmc={}", on("EC_SCALEDREF_OBMC")); | |
| 5090 | + let interintra = format!("--enable-interintra-comp={}", on("EC_SCALEDREF_II")); | |
| 5091 | + let lag = format!( | |
| 5092 | + "--lag-in-frames={}", | |
| 5093 | + if on("EC_SCALEDREF_COMP") == "0" { "0" } else { "25" } | |
| 5094 | + ); | |
| 5095 | + let alt_ref = format!("--auto-alt-ref={}", on("EC_SCALEDREF_COMP")); | |
| 5096 | + let args: Vec<&str> = vec![ | |
| 5097 | + "--codec=av1", | |
| 5098 | + "--passes=1", | |
| 5099 | + "--end-usage=q", | |
| 5100 | + "--cq-level=45", | |
| 5101 | + "--cpu-used=0", | |
| 5102 | + "--kf-max-dist=1000", | |
| 5103 | + "--threads=1", | |
| 5104 | + "--row-mt=0", | |
| 5105 | + "--sb-size=64", | |
| 5106 | + // superres on every frame, key and inter alike -- the scaled | |
| 5107 | + // reference this gate is about. | |
| 5108 | + // denominator 16 (the maximum) keeps the CODED frame | |
| 5109 | + // 32x64 -- a multiple of 16 both ways, so no frame-edge | |
| 5110 | + // 16x16 straddle forces a sub-16x16 partition this decoder | |
| 5111 | + // still refuses on the aligned path ("an inter partition | |
| 5112 | + // below 16x16"). Denominator 12 codes 43 columns and every | |
| 5113 | + // seed refused there. | |
| 5114 | + "--superres-mode=1", | |
| 5115 | + "--superres-denominator=16", | |
| 5116 | + "--superres-kf-denominator=16", | |
| 5117 | + // the four combinations this round lifts (each switchable | |
| 5118 | + // by env for bisecting a mismatch without a rebuild) | |
| 5119 | + &alt_ref, | |
| 5120 | + &lag, | |
| 5121 | + "--enable-order-hint=1", | |
| 5122 | + &warp, | |
| 5123 | + &obmc, | |
| 5124 | + &interintra, | |
| 5125 | + "--enable-smooth-interintra=1", | |
| 5126 | + "--enable-interintra-wedge=0", | |
| 5127 | + "--enable-masked-comp=0", | |
| 5128 | + "--enable-onesided-comp=0", | |
| 5129 | + "--enable-fwd-kf=0", | |
| 5130 | + "--tune-content=default", | |
| 5131 | + "--max-partition-size=32", | |
| 5132 | + "--min-partition-size=32", | |
| 5133 | + // everything this decoder still refuses under any reference | |
| 5134 | + "--enable-rect-partitions=0", | |
| 5135 | + "--enable-ab-partitions=0", | |
| 5136 | + "--enable-1to4-partitions=0", | |
| 5137 | + "--enable-filter-intra=0", | |
| 5138 | + "--enable-smooth-intra=0", | |
| 5139 | + "--enable-paeth-intra=0", | |
| 5140 | + "--enable-directional-intra=0", | |
| 5141 | + "--enable-angle-delta=0", | |
| 5142 | + "--enable-tx-size-search=0", | |
| 5143 | + "--enable-cdef=0", | |
| 5144 | + "--enable-restoration=0", | |
| 5145 | + "--enable-palette=0", | |
| 5146 | + "--enable-intrabc=0", | |
| 5147 | + "--enable-cfl-intra=0", | |
| 5148 | + "--enable-ref-frame-mvs=0", | |
| 5149 | + "--obu", | |
| 5150 | + "-o", | |
| 5151 | + "-", | |
| 5152 | + "-", | |
| 5153 | + ]; | |
| 5154 | + let mut child = Command::new(aomenc_path()) | |
| 5155 | + .args(&args) | |
| 5156 | + .stdin(Stdio::piped()) | |
| 5157 | + .stdout(Stdio::piped()) | |
| 5158 | + .stderr(Stdio::piped()) | |
| 5159 | + .spawn() | |
| 5160 | + .expect("aomenc failed to start"); | |
| 5161 | + child | |
| 5162 | + .stdin | |
| 5163 | + .take() | |
| 5164 | + .expect("aomenc stdin") | |
| 5165 | + .write_all(&y4m.stdout) | |
| 5166 | + .expect("writing y4m to aomenc"); | |
| 5167 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 5168 | + assert!( | |
| 5169 | + out.status.success(), | |
| 5170 | + "aomenc refused the fixture: {}", | |
| 5171 | + String::from_utf8_lossy(&out.stderr) | |
| 5172 | + ); | |
| 5173 | + let stream = out.stdout; | |
| 5174 | + let frames = match decode_stream(&stream) { | |
| 5175 | + Err(e) => { | |
| 5176 | + let msg = e.to_string(); | |
| 5177 | + assert!( | |
| 5178 | + msg.contains("unsupported"), | |
| 5179 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | |
| 5180 | + ); | |
| 5181 | + assert!( | |
| 5182 | + !msg.contains("scaled reference"), | |
| 5183 | + "{NAME} refused on a scaled reference (seed {seed}) -- those refusals \ | |
| 5184 | + are exactly what this round lifts: {msg}" | |
| 5185 | + ); | |
| 5186 | + named_refusals += 1; | |
| 5187 | + eprintln!("seed {seed} refusal (other capability): {msg}"); | |
| 5188 | + continue; | |
| 5189 | + } | |
| 5190 | + Ok(frames) => frames, | |
| 5191 | + }; | |
| 5192 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | |
| 5193 | + assert_eq!(frames.len(), frame_count); | |
| 5194 | + if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { | |
| 5195 | + let mismatched = frames | |
| 5196 | + .iter() | |
| 5197 | + .zip(&ffmpeg_frames) | |
| 5198 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | |
| 5199 | + if mismatched { | |
| 5200 | + std::fs::write(&path, &stream).expect("writing pinned stream"); | |
| 5201 | + eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); | |
| 5202 | + } | |
| 5203 | + } | |
| 5204 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 5205 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); | |
| 5206 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); | |
| 5207 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); | |
| 5208 | + } | |
| 5209 | + matched += 1; | |
| 5210 | + } | |
| 5211 | + eprintln!( | |
| 5212 | + "{NAME}: {named_refusals} other-capability refusals, {matched}/{n_attempts} pixel-exact, \ | |
| 5213 | + superres_hits={} predict_scaled_hits={} scaled_compound={} scaled_warp_fallback={} \ | |
| 5214 | + scaled_obmc={} scaled_interintra={} scaled_block8={}", | |
| 5215 | + crate::superres::superres_hits(), | |
| 5216 | + crate::mc::predict_scaled_hits(), | |
| 5217 | + crate::decode::scaled_compound_hits(), | |
| 5218 | + crate::decode::scaled_warp_fallback_hits(), | |
| 5219 | + crate::decode::scaled_obmc_hits(), | |
| 5220 | + crate::decode::scaled_interintra_hits(), | |
| 5221 | + crate::decode::scaled_block8_hits(), | |
| 5222 | + ); | |
| 5223 | + assert!( | |
| 5224 | + matched > 0, | |
| 5225 | + "{NAME}: every attempt refused on other capabilities; the gate proves nothing" | |
| 5226 | + ); | |
| 5227 | + assert!( | |
| 5228 | + crate::mc::predict_scaled_hits() > 0, | |
| 5229 | + "{NAME}: matched but zero predict_scaled_hits -- no block took the scaled MC path" | |
| 5230 | + ); | |
| 5231 | + // Warp and the 8x8 leaf are NOT asserted here: both stay refused this | |
| 5232 | + // round (warp's own fallback mismatches at seed 47, and no recipe | |
| 5233 | + // produced an 8x8 inter leaf at all), so their counters are | |
| 5234 | + // diagnostics only -- see this gate's own doc and decode.rs. | |
| 5235 | + for (hits, what) in [ | |
| 5236 | + (crate::decode::scaled_compound_hits(), "compound with a scaled reference"), | |
| 5237 | + (crate::decode::scaled_obmc_hits(), "OBMC with a scaled reference"), | |
| 5238 | + (crate::decode::scaled_interintra_hits(), "interintra with a scaled reference"), | |
| 5239 | + ] { | |
| 5240 | + assert!(hits > 0, "{NAME}: {matched} matches but zero blocks took {what}"); | |
| 5241 | + } | |
| 5242 | + } | |
| 5243 | + | |
| 5028 | 5244 | /// lane-wii r2: `--enable-interintra-wedge=1` streams must DECODE |
| 5029 | 5245 | /// pixel-exact -- the wedge-interintra syntax (adapting `wedge_index` |
| 5030 | 5246 | /// CDF symbol, fixed sign 0) and the wedge mask blend are ported over |