wip(superres): builder's in-flight edits, committed verbatim at the 75-turn cap (state unverified by me)
Browse files at this commitddad1b5d1bd70d73f99c4b10cf1456b38685e979Parent: 00d13c35 changed files +188 -74
- crates/ec-av1/src/decode.rs +41 -12
- crates/ec-av1/src/mc.rs +15 -0
- crates/ec-av1/src/refusal_inventory.rs +1 -2
- crates/ec-av1/src/stream.rs +129 -58
- crates/ec-av1/src/superres.rs +2 -2
crates/ec-av1/src/decode.rsmodified+41 -12
| @@ -5457,18 +5457,21 @@ pub fn decode_key_frame_tile( | |||
| 5457 | thread_local! { | 5457 | thread_local! { |
| 5458 | /// lane-superres r3: the real decoded margin beyond `frame_width` up to | 5458 | /// lane-superres r3: the real decoded margin beyond `frame_width` up to |
| 5459 | /// the mi-aligned `true_width`, set by the most recent | 5459 | /// the mi-aligned `true_width`, set by the most recent |
| 5460 | - /// [`decode_key_frame_tile_with_cdfs`] call. See that function's own | 5460 | + /// [`decode_key_frame_tile_with_cdfs`] OR (lane-superres r10) |
| 5461 | - /// comment at the write site. `None` when there was no margin to save. | 5461 | + /// [`decode_inter_frame_tile_with_cdfs`] call -- both frame kinds crop |
| 5462 | - static LAST_KEY_FRAME_WIDE_MARGIN: std::cell::RefCell<Option<Picture>> = | 5462 | + /// their reconstructed buffer down from the same mi-aligned extent, so |
| 5463 | + /// they share this one slot. See each function's own comment at its | ||
| 5464 | + /// write site. `None` when there was no margin to save. | ||
| 5465 | + static LAST_FRAME_WIDE_MARGIN: std::cell::RefCell<Option<Picture>> = | ||
| 5463 | const { std::cell::RefCell::new(None) }; | 5466 | const { std::cell::RefCell::new(None) }; |
| 5464 | } | 5467 | } |
| 5465 | 5468 | ||
| 5466 | -/// The margin [`decode_key_frame_tile_with_cdfs`] most recently stashed | 5469 | +/// The margin the most recent key- or inter-frame tile decode stashed |
| 5467 | -/// (see [`LAST_KEY_FRAME_WIDE_MARGIN`]) -- `stream.rs`'s superres path | 5470 | +/// (see [`LAST_FRAME_WIDE_MARGIN`]) -- `stream.rs`'s superres path |
| 5468 | -/// reads this immediately after the call, before any other key frame | 5471 | +/// reads this immediately after the call, before any other frame |
| 5469 | /// decode can overwrite it. | 5472 | /// decode can overwrite it. |
| 5470 | -pub(crate) fn take_last_key_frame_wide_margin() -> Option<Picture> { | 5473 | +pub(crate) fn take_last_frame_wide_margin() -> Option<Picture> { |
| 5471 | - LAST_KEY_FRAME_WIDE_MARGIN.with(|m| m.borrow_mut().take()) | 5474 | + LAST_FRAME_WIDE_MARGIN.with(|m| m.borrow_mut().take()) |
| 5472 | } | 5475 | } |
| 5473 | 5476 | ||
| 5474 | /// [`decode_key_frame_tile`], threading a cross-frame CDF forward (spec | 5477 | /// [`decode_key_frame_tile`], threading a cross-frame CDF forward (spec |
| @@ -6102,7 +6105,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 6102 | 6105 | ||
| 6103 | let (fw, fh) = (frame_width as usize, frame_height as usize); | 6106 | let (fw, fh) = (frame_width as usize, frame_height as usize); |
| 6104 | if fw == width && fh == height { | 6107 | if fw == width && fh == height { |
| 6105 | - LAST_KEY_FRAME_WIDE_MARGIN.with(|m| *m.borrow_mut() = None); | 6108 | + LAST_FRAME_WIDE_MARGIN.with(|m| *m.borrow_mut() = None); |
| 6106 | return Ok(( | 6109 | return Ok(( |
| 6107 | Picture { | 6110 | Picture { |
| 6108 | width, | 6111 | width, |
| @@ -6135,7 +6138,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 6135 | // reaches into that real margin; `None` when there is no margin (this | 6138 | // reaches into that real margin; `None` when there is no margin (this |
| 6136 | // frame's `true_width`/`true_height` already equal `fw`/`fh`, e.g. a | 6139 | // frame's `true_width`/`true_height` already equal `fw`/`fh`, e.g. a |
| 6137 | // non-superres frame whose width just isn't 32-block aligned). | 6140 | // non-superres frame whose width just isn't 32-block aligned). |
| 6138 | - LAST_KEY_FRAME_WIDE_MARGIN.with(|m| { | 6141 | + LAST_FRAME_WIDE_MARGIN.with(|m| { |
| 6139 | *m.borrow_mut() = if true_width > fw || true_height > fh { | 6142 | *m.borrow_mut() = if true_width > fw || true_height > fh { |
| 6140 | let yc = crop(&y, true_width, true_height); | 6143 | let yc = crop(&y, true_width, true_height); |
| 6141 | if let Ok(path) = std::env::var("EC_AV1_MARGIN_DUMP") { | 6144 | if let Ok(path) = std::env::var("EC_AV1_MARGIN_DUMP") { |
| @@ -10479,9 +10482,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 10479 | return Err(unsupported("a frame with no mode-info grid")); | 10482 | return Err(unsupported("a frame with no mode-info grid")); |
| 10480 | } | 10483 | } |
| 10481 | let (true_width, true_height) = ((mi_cols * 4) as usize, (mi_rows * 4) as usize); | 10484 | let (true_width, true_height) = ((mi_cols * 4) as usize, (mi_rows * 4) as usize); |
| 10482 | - if reference.width != true_width || reference.height != true_height { | 10485 | + // lane-superres r10: a width mismatch alone is no longer refused here -- |
| 10486 | + // `mc::predict_scaled` (spec 7.11.3.3, threaded through | ||
| 10487 | + // `decode_inter_block`'s single-ref branch) exists precisely for a | ||
| 10488 | + // `use_superres` reference at a different width than this frame's own | ||
| 10489 | + // true size. Height must still match: AV1 superres never scales height | ||
| 10490 | + // (r8's derivation, `mc.rs`'s own doc), and nothing in this decode path | ||
| 10491 | + // has a vertical scaling pass. | ||
| 10492 | + if reference.height != true_height { | ||
| 10483 | return Err(unsupported( | 10493 | return Err(unsupported( |
| 10484 | - "a reference picture that is not this frame's own true size", | 10494 | + "a reference picture whose height does not match this frame's own true size", |
| 10485 | )); | 10495 | )); |
| 10486 | } | 10496 | } |
| 10487 | let (cols, rows) = block_grid(mi_cols, mi_rows); | 10497 | let (cols, rows) = block_grid(mi_cols, mi_rows); |
| @@ -11987,6 +11997,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 11987 | 11997 | ||
| 11988 | let (fw, fh) = (frame_width as usize, frame_height as usize); | 11998 | let (fw, fh) = (frame_width as usize, frame_height as usize); |
| 11989 | if fw == width && fh == height { | 11999 | if fw == width && fh == height { |
| 12000 | + LAST_FRAME_WIDE_MARGIN.with(|m| *m.borrow_mut() = None); | ||
| 11990 | return Ok(( | 12001 | return Ok(( |
| 11991 | Picture { | 12002 | Picture { |
| 11992 | width, | 12003 | width, |
| @@ -12006,6 +12017,24 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 12006 | } | 12017 | } |
| 12007 | out | 12018 | out |
| 12008 | }; | 12019 | }; |
| 12020 | + // lane-superres r10: same real-margin stash as | ||
| 12021 | + // `decode_key_frame_tile_with_cdfs` (see that function's comment) -- an | ||
| 12022 | + // inter frame under `use_superres` crops from the same mi-aligned | ||
| 12023 | + // `width`/`height` down to `fw`/`fh`, and `stream.rs`'s upscale needs | ||
| 12024 | + // the same real border-extension columns, not a synthetic replicate. | ||
| 12025 | + LAST_FRAME_WIDE_MARGIN.with(|m| { | ||
| 12026 | + *m.borrow_mut() = if width > fw || height > fh { | ||
| 12027 | + Some(Picture { | ||
| 12028 | + width, | ||
| 12029 | + height, | ||
| 12030 | + y: crop(&y, width, height), | ||
| 12031 | + u: crop(&u, width.div_ceil(2), height.div_ceil(2)), | ||
| 12032 | + v: crop(&v, width.div_ceil(2), height.div_ceil(2)), | ||
| 12033 | + }) | ||
| 12034 | + } else { | ||
| 12035 | + None | ||
| 12036 | + } | ||
| 12037 | + }); | ||
| 12009 | Ok(( | 12038 | Ok(( |
| 12010 | Picture { | 12039 | Picture { |
| 12011 | width: fw, | 12040 | width: fw, |
crates/ec-av1/src/mc.rsmodified+15 -0
| @@ -427,6 +427,20 @@ pub fn scale_factor(other_width: usize, this_width: usize) -> i64 { | |||
| 427 | (((other_width as i64) << 14) + this_width as i64 / 2) / this_width as i64 | 427 | (((other_width as i64) << 14) + this_width as i64 / 2) / this_width as i64 |
| 428 | } | 428 | } |
| 429 | 429 | ||
| 430 | +thread_local! { | ||
| 431 | + /// lane-superres r10: firing count for the bypass gate (class | ||
| 432 | + /// `gate-blind-to-feature`) -- how many times [`predict_scaled`] itself | ||
| 433 | + /// ran, so the gate can hard-assert the scaled MC path actually fired | ||
| 434 | + /// rather than trust a pixel match alone (an unscaled reference would | ||
| 435 | + /// pass the pixels and prove nothing). | ||
| 436 | + static PREDICT_SCALED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 437 | +} | ||
| 438 | + | ||
| 439 | +/// Current value of [`PREDICT_SCALED_HITS`]. | ||
| 440 | +pub fn predict_scaled_hits() -> usize { | ||
| 441 | + PREDICT_SCALED_HITS.with(|c| c.get()) | ||
| 442 | +} | ||
| 443 | + | ||
| 430 | fn round_pow2_64(value: i64, shift: u32) -> i64 { | 444 | fn round_pow2_64(value: i64, shift: u32) -> i64 { |
| 431 | if shift == 0 { | 445 | if shift == 0 { |
| 432 | value | 446 | value |
| @@ -478,6 +492,7 @@ pub fn predict_scaled( | |||
| 478 | ) { | 492 | ) { |
| 479 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); | 493 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); |
| 480 | assert!(!reference.is_empty(), "a reference plane has samples"); | 494 | assert!(!reference.is_empty(), "a reference plane has samples"); |
| 495 | + PREDICT_SCALED_HITS.with(|c| c.set(c.get() + 1)); | ||
| 481 | 496 | ||
| 482 | let y0 = y_q4.div_euclid(16); | 497 | let y0 = y_q4.div_euclid(16); |
| 483 | let yfrac = y_q4.rem_euclid(16) as usize; | 498 | let yfrac = y_q4.rem_euclid(16) as usize; |
crates/ec-av1/src/refusal_inventory.rsmodified+1 -2
| @@ -42,7 +42,6 @@ const REFUSALS: &[&str] = &[ | |||
| 42 | "a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)", | 42 | "a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)", |
| 43 | "a tx_type symbol outside its CDF's own set: {t}", | 43 | "a tx_type symbol outside its CDF's own set: {t}", |
| 44 | "an INTER 32x32 partition type this decoder does not code (value={part32})", | 44 | "an INTER 32x32 partition type this decoder does not code (value={part32})", |
| 45 | - "an inter frame with use_superres set (this decoder never scales its motion-compensated reference to match the current frame's downscaled size, spec 7.11.3.3)", | ||
| 46 | "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", | 45 | "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", |
| 47 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", | 46 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", |
| 48 | "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)", | 47 | "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)", |
| @@ -57,7 +56,7 @@ const REFUSALS: &[&str] = &[ | |||
| 57 | "a palette block with a split luma transform (round 1)", | 56 | "a palette block with a split luma transform (round 1)", |
| 58 | "a reference frame other than LAST_FRAME (round 2)", | 57 | "a reference frame other than LAST_FRAME (round 2)", |
| 59 | "a reference frame selected with no picture at this frame's own ref_frame_idx slot for it", | 58 | "a reference frame selected with no picture at this frame's own ref_frame_idx slot for it", |
| 60 | - "a reference picture that is not this frame's own true size", | 59 | + "a reference picture whose height does not match this frame's own true size", |
| 61 | "a show_existing_frame header naming an empty reference slot", | 60 | "a show_existing_frame header naming an empty reference slot", |
| 62 | "an 8x8 leaf that coded WARPED_CAUSAL (motion_mode == 2): av1_find_projection/the affine warp filter are not ported, only motion_mode_allowed's alphabet choice is", | 61 | "an 8x8 leaf that coded WARPED_CAUSAL (motion_mode == 2): av1_find_projection/the affine warp filter are not ported, only motion_mode_allowed's alphabet choice is", |
| 63 | "an inter frame using TxMode::Select (this decoder's inter path never reads a tx_depth symbol, so it desyncs after the first block's mode)", | 62 | "an inter frame using TxMode::Select (this decoder's inter path never reads a tx_depth symbol, so it desyncs after the first block's mode)", |
crates/ec-av1/src/stream.rsmodified+129 -58
| @@ -254,19 +254,16 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 254 | // reads stay bit-exact in sync and `crate::superres::upscale_picture` | 254 | // reads stay bit-exact in sync and `crate::superres::upscale_picture` |
| 255 | // (below, after decode) makes its `Picture` the spec-correct | 255 | // (below, after decode) makes its `Picture` the spec-correct |
| 256 | // `upscaled_width` instead of silently staying at `frame_width`. | 256 | // `upscaled_width` instead of silently staying at `frame_width`. |
| 257 | - // An INTER frame under `use_superres` still refuses: its reference | 257 | + // lane-superres r10: an INTER frame under `use_superres` no longer |
| 258 | - // is stored upscaled while the current frame decodes at the | 258 | + // refuses at the frame level. `mc::predict_scaled` (spec 7.11.3.3) |
| 259 | - // downscaled `frame_width`, so `decode_inter_frame_tile_with_cdfs`'s | 259 | + // is wired into `decode_inter_block`'s single-ref, non-warp/OBMC/ |
| 260 | - // motion compensation would sample a reference at the wrong scale | 260 | + // interintra branch, and `decode_inter_frame_tile_with_cdfs` decodes |
| 261 | - // (spec 7.11.3.3's scaled-reference path is not ported) -- | 261 | + // at the downscaled `frame_width` and upscales its own output the |
| 262 | - // SILENT WRONGNESS, not a desync, same as the key-frame case used | 262 | + // same way the key-frame branch above does (see the inter branch |
| 263 | - // to be. Left for a later stage of this lane. | 263 | + // below). The combinations `predict_scaled` does not cover |
| 264 | - if header.use_superres && header.frame_type != FrameType::Key { | 264 | + // (compound MC, warp/OBMC/interintra, `decode_inter_block8`'s 8x8 |
| 265 | - return Err(Error::unsupported( | 265 | + // leaf) still refuse by name, deep in `decode.rs`, rather than |
| 266 | - "AV1 decode_stream", | 266 | + // silently mispredicting -- see `refusal_inventory.rs`. |
| 267 | - "an inter frame with use_superres set (this decoder never scales its motion-compensated reference to match the current frame's downscaled size, spec 7.11.3.3)", | ||
| 268 | - )); | ||
| 269 | - } | ||
| 270 | // Loop restoration carries per-restoration-unit symbols in the tile | 267 | // Loop restoration carries per-restoration-unit symbols in the tile |
| 271 | // (spec 5.11.57 `read_lr`, one group per LR unit reached from the | 268 | // (spec 5.11.57 `read_lr`, one group per LR unit reached from the |
| 272 | // superblock walk) -- lane-lr r2 ported the reader | 269 | // superblock walk) -- lane-lr r2 ported the reader |
| @@ -490,8 +487,8 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 490 | // no LR step here for the upscale to precede. | 487 | // no LR step here for the upscale to precede. |
| 491 | // r3: the real decoded margin beyond `frame_width` (set by the | 488 | // r3: the real decoded margin beyond `frame_width` (set by the |
| 492 | // call above, right before anything else can overwrite it) -- | 489 | // call above, right before anything else can overwrite it) -- |
| 493 | - // see `decode::take_last_key_frame_wide_margin`'s doc. | 490 | + // see `decode::take_last_frame_wide_margin`'s doc. |
| 494 | - let wide_margin = crate::decode::take_last_key_frame_wide_margin(); | 491 | + let wide_margin = crate::decode::take_last_frame_wide_margin(); |
| 495 | let picture = if header.use_superres { | 492 | let picture = if header.use_superres { |
| 496 | crate::superres::upscale_picture( | 493 | crate::superres::upscale_picture( |
| 497 | &picture, | 494 | &picture, |
| @@ -551,7 +548,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 551 | header.mi_cols as usize, | 548 | header.mi_cols as usize, |
| 552 | ) | 549 | ) |
| 553 | }); | 550 | }); |
| 554 | - decode_inter_frame_tile_with_cdfs( | 551 | + let (picture, end_cdfs, motion_field) = decode_inter_frame_tile_with_cdfs( |
| 555 | &tile_bufs, | 552 | &tile_bufs, |
| 556 | &header.tile_info, | 553 | &header.tile_info, |
| 557 | header.mi_cols, | 554 | header.mi_cols, |
| @@ -586,7 +583,26 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 586 | header.allow_warped_motion, | 583 | header.allow_warped_motion, |
| 587 | header.allow_screen_content_tools, | 584 | header.allow_screen_content_tools, |
| 588 | header.delta, | 585 | header.delta, |
| 589 | - )? | 586 | + )?; |
| 587 | + // lane-superres r10: mirrors the key-frame branch above -- | ||
| 588 | + // `decode_inter_frame_tile_with_cdfs` decodes at the downscaled | ||
| 589 | + // `frame_width`/`frame_height` and crops to it; upscale AFTER | ||
| 590 | + // (deblock/CDEF/LR already applied inside that call) BEFORE this | ||
| 591 | + // picture is stored as a reference or shown, same margin | ||
| 592 | + // mechanism (`take_last_frame_wide_margin`, read immediately | ||
| 593 | + // after the call, before any other frame decode can overwrite | ||
| 594 | + // it). | ||
| 595 | + let wide_margin = crate::decode::take_last_frame_wide_margin(); | ||
| 596 | + let picture = if header.use_superres { | ||
| 597 | + crate::superres::upscale_picture( | ||
| 598 | + &picture, | ||
| 599 | + header.upscaled_width as usize, | ||
| 600 | + wide_margin.as_ref(), | ||
| 601 | + ) | ||
| 602 | + } else { | ||
| 603 | + picture | ||
| 604 | + }; | ||
| 605 | + (picture, end_cdfs, motion_field) | ||
| 590 | }; | 606 | }; |
| 591 | // lane-lr r4: the Wiener/self-guided pixel filters are wired | 607 | // lane-lr r4: the Wiener/self-guided pixel filters are wired |
| 592 | // (`decode.rs::apply_loop_restoration`) -- no more refusal here, | 608 | // (`decode.rs::apply_loop_restoration`) -- no more refusal here, |
| @@ -4223,18 +4239,17 @@ mod tests { | |||
| 4223 | ); | 4239 | ); |
| 4224 | } | 4240 | } |
| 4225 | 4241 | ||
| 4226 | - /// lane-superres Step 0/stage 1: a real aomenc `--superres-mode=1` | 4242 | + /// lane-superres stage 3: a real aomenc `--superres-mode=1` key-frame |
| 4227 | - /// stream must refuse BY NAME (`use_superres`), never desync into a | 4243 | + /// sequence must decode pixel-exact vs ffmpeg/dav1d's own upscaled |
| 4228 | - /// different error and never silently decode a wrong-sized picture. | 4244 | + /// output, and must actually run [`crate::superres::upscale_picture`] |
| 4229 | - /// `use_superres` adds no per-block symbol (spec 7.16's upscaler is a | 4245 | + /// (`superres_hits > 0`) -- a decoder that silently stopped upscaling |
| 4230 | - /// pixel-domain post-process), so before the stream.rs refusal landed | 4246 | + /// would otherwise pass vacuously (class `gate-blind-to-feature`). |
| 4231 | - /// this crate's tile readers stayed bit-exact in sync but stored the | 4247 | + /// `--kf-max-dist` set to the frame count keeps every frame a key |
| 4232 | - /// `Picture` at the downscaled `frame_width` instead of | 4248 | + /// frame: inter-frame superres (a differently-scaled reference) is a |
| 4233 | - /// `upscaled_width` -- exactly the SILENT WRONGNESS the charter's Step 0 | 4249 | + /// later stage of this lane, refused by name today. |
| 4234 | - /// called for turning into an explicit refusal first. | ||
| 4235 | #[test] | 4250 | #[test] |
| 4236 | - fn a_real_aomenc_stream_with_superres_refuses_by_name() { | 4251 | + fn a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact() { |
| 4237 | - const NAME: &str = "a_real_aomenc_stream_with_superres_refuses_by_name"; | 4252 | + const NAME: &str = "a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact"; |
| 4238 | let _gate_lock = lock_gate_counters(); | 4253 | let _gate_lock = lock_gate_counters(); |
| 4239 | if !have_ffmpeg() { | 4254 | if !have_ffmpeg() { |
| 4240 | eprintln!("SKIP {NAME}: no ffmpeg"); | 4255 | eprintln!("SKIP {NAME}: no ffmpeg"); |
| @@ -4244,9 +4259,9 @@ mod tests { | |||
| 4244 | eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | 4259 | eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); |
| 4245 | return; | 4260 | return; |
| 4246 | } | 4261 | } |
| 4247 | - let (width, height, frame_count) = (64usize, 64usize, 4usize); | 4262 | + let (width, height, frame_count) = (64usize, 64usize, 3usize); |
| 4248 | let duration = frame_count as f64 / 25.0; | 4263 | let duration = frame_count as f64 / 25.0; |
| 4249 | - let source = gradients_source(42, width, height, &format!("duration={duration}:rate=25")); | 4264 | + let source = gradients_source(7, width, height, &format!("duration={duration}:rate=25")); |
| 4250 | let y4m = Command::new("ffmpeg") | 4265 | let y4m = Command::new("ffmpeg") |
| 4251 | .args([ | 4266 | .args([ |
| 4252 | "-v", | 4267 | "-v", |
| @@ -4277,11 +4292,28 @@ mod tests { | |||
| 4277 | "--end-usage=q", | 4292 | "--end-usage=q", |
| 4278 | "--cq-level=32", | 4293 | "--cq-level=32", |
| 4279 | "--cpu-used=0", | 4294 | "--cpu-used=0", |
| 4280 | - "--kf-max-dist=1000", | 4295 | + "--kf-max-dist=0", |
| 4281 | "--threads=1", | 4296 | "--threads=1", |
| 4282 | "--row-mt=0", | 4297 | "--row-mt=0", |
| 4283 | "--superres-mode=1", | 4298 | "--superres-mode=1", |
| 4284 | "--superres-denominator=12", | 4299 | "--superres-denominator=12", |
| 4300 | + "--superres-kf-denominator=12", | ||
| 4301 | + "--enable-rect-partitions=0", | ||
| 4302 | + "--enable-ab-partitions=0", | ||
| 4303 | + "--enable-1to4-partitions=0", | ||
| 4304 | + "--enable-filter-intra=0", | ||
| 4305 | + "--enable-smooth-intra=0", | ||
| 4306 | + "--enable-paeth-intra=0", | ||
| 4307 | + "--enable-directional-intra=0", | ||
| 4308 | + "--enable-angle-delta=0", | ||
| 4309 | + "--enable-tx-size-search=0", | ||
| 4310 | + "--enable-cdef=0", | ||
| 4311 | + "--enable-restoration=0", | ||
| 4312 | + "--max-partition-size=32", | ||
| 4313 | + "--min-partition-size=32", | ||
| 4314 | + "--enable-palette=0", | ||
| 4315 | + "--enable-intrabc=0", | ||
| 4316 | + "--enable-cfl-intra=0", | ||
| 4285 | "--obu", | 4317 | "--obu", |
| 4286 | "-o", | 4318 | "-o", |
| 4287 | "-", | 4319 | "-", |
| @@ -4307,30 +4339,42 @@ mod tests { | |||
| 4307 | String::from_utf8_lossy(&out.stderr) | 4339 | String::from_utf8_lossy(&out.stderr) |
| 4308 | ); | 4340 | ); |
| 4309 | let stream = out.stdout; | 4341 | let stream = out.stdout; |
| 4310 | - let err = decode_stream(&stream).expect_err( | 4342 | + if let Ok(path) = std::env::var("EC_SUPERRES_STREAM_DUMP") { |
| 4311 | - "a real --superres-mode=1 stream must refuse -- superres decode is not implemented \ | 4343 | + std::fs::write(path, &stream).expect("dump stream"); |
| 4312 | - and silently produces a wrong-sized picture otherwise", | 4344 | + } |
| 4313 | - ); | 4345 | + let frames = |
| 4314 | - let msg = err.to_string(); | 4346 | + decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}")); |
| 4347 | + assert_eq!(frames.len(), frame_count); | ||
| 4348 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | ||
| 4349 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 4350 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg"); | ||
| 4351 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg"); | ||
| 4352 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg"); | ||
| 4353 | + } | ||
| 4315 | assert!( | 4354 | assert!( |
| 4316 | - msg.contains("use_superres"), | 4355 | + crate::superres::superres_hits() > 0, |
| 4317 | - "{NAME}: refused, but not by the superres name -- this stream desynced into a \ | 4356 | + "{NAME}: matched but zero superres_hits -- the gate never actually exercised the \ |
| 4318 | - different refusal instead: {msg}" | 4357 | + upscaler, it proves nothing" |
| 4358 | + ); | ||
| 4359 | + eprintln!( | ||
| 4360 | + "{NAME}: {frame_count} frames pixel-exact, superres_hits={}", | ||
| 4361 | + crate::superres::superres_hits() | ||
| 4319 | ); | 4362 | ); |
| 4320 | - eprintln!("{NAME}: refused by name: {msg}"); | ||
| 4321 | } | 4363 | } |
| 4322 | 4364 | ||
| 4323 | - /// lane-superres stage 3: a real aomenc `--superres-mode=1` key-frame | 4365 | + /// lane-superres r10: a real aomenc key+inter `--superres-mode=1` |
| 4324 | - /// sequence must decode pixel-exact vs ffmpeg/dav1d's own upscaled | 4366 | + /// sequence must DECODE pixel-exact vs ffmpeg, with the frame-level |
| 4325 | - /// output, and must actually run [`crate::superres::upscale_picture`] | 4367 | + /// `use_superres` refusal LIFTED for inter frames -- `mc::predict_scaled` |
| 4326 | - /// (`superres_hits > 0`) -- a decoder that silently stopped upscaling | 4368 | + /// (spec 7.11.3.3) is the only path this recipe can reach (warp/OBMC/ |
| 4327 | - /// would otherwise pass vacuously (class `gate-blind-to-feature`). | 4369 | + /// compound/interintra/palette/intrabc/CDEF/LR are all off, matching the |
| 4328 | - /// `--kf-max-dist` set to the frame count keeps every frame a key | 4370 | + /// scoped refusals' own unimplemented list). A pixel match alone would |
| 4329 | - /// frame: inter-frame superres (a differently-scaled reference) is a | 4371 | + /// pass just as well with an unscaled reference and prove nothing |
| 4330 | - /// later stage of this lane, refused by name today. | 4372 | + /// (class `gate-blind-to-feature`) -- hard-assert |
| 4373 | + /// `crate::mc::predict_scaled_hits() > 0` so the gate can only pass if the | ||
| 4374 | + /// scaled MC path actually ran. | ||
| 4331 | #[test] | 4375 | #[test] |
| 4332 | - fn a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact() { | 4376 | + fn a_real_aomenc_key_and_inter_superres_sequence_decodes_pixel_exact() { |
| 4333 | - const NAME: &str = "a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact"; | 4377 | + const NAME: &str = "a_real_aomenc_key_and_inter_superres_sequence_decodes_pixel_exact"; |
| 4334 | let _gate_lock = lock_gate_counters(); | 4378 | let _gate_lock = lock_gate_counters(); |
| 4335 | if !have_ffmpeg() { | 4379 | if !have_ffmpeg() { |
| 4336 | eprintln!("SKIP {NAME}: no ffmpeg"); | 4380 | eprintln!("SKIP {NAME}: no ffmpeg"); |
| @@ -4342,7 +4386,7 @@ mod tests { | |||
| 4342 | } | 4386 | } |
| 4343 | let (width, height, frame_count) = (64usize, 64usize, 3usize); | 4387 | let (width, height, frame_count) = (64usize, 64usize, 3usize); |
| 4344 | let duration = frame_count as f64 / 25.0; | 4388 | let duration = frame_count as f64 / 25.0; |
| 4345 | - let source = gradients_source(7, width, height, &format!("duration={duration}:rate=25")); | 4389 | + let source = gradients_source(11, width, height, &format!("duration={duration}:rate=25")); |
| 4346 | let y4m = Command::new("ffmpeg") | 4390 | let y4m = Command::new("ffmpeg") |
| 4347 | .args([ | 4391 | .args([ |
| 4348 | "-v", | 4392 | "-v", |
| @@ -4373,12 +4417,33 @@ mod tests { | |||
| 4373 | "--end-usage=q", | 4417 | "--end-usage=q", |
| 4374 | "--cq-level=32", | 4418 | "--cq-level=32", |
| 4375 | "--cpu-used=0", | 4419 | "--cpu-used=0", |
| 4376 | - "--kf-max-dist=0", | 4420 | + // `--kf-max-dist` above `frame_count` keeps only frame 0 a key |
| 4421 | + // frame -- frames 1/2 are the inter frames whose `use_superres` | ||
| 4422 | + // refusal this round lifts. | ||
| 4423 | + "--kf-max-dist=1000", | ||
| 4424 | + "--lag-in-frames=0", | ||
| 4425 | + "--auto-alt-ref=0", | ||
| 4377 | "--threads=1", | 4426 | "--threads=1", |
| 4378 | "--row-mt=0", | 4427 | "--row-mt=0", |
| 4428 | + "--sb-size=64", | ||
| 4379 | "--superres-mode=1", | 4429 | "--superres-mode=1", |
| 4380 | "--superres-denominator=12", | 4430 | "--superres-denominator=12", |
| 4381 | "--superres-kf-denominator=12", | 4431 | "--superres-kf-denominator=12", |
| 4432 | + // Forces every inter block onto the single-ref, non-warp/OBMC/ | ||
| 4433 | + // interintra branch `decode_inter_block` threads `predict_scaled` | ||
| 4434 | + // through -- the only branch this round's scoped refusals leave | ||
| 4435 | + // unrefused under a scaled reference. | ||
| 4436 | + "--enable-warped-motion=0", | ||
| 4437 | + "--enable-obmc=0", | ||
| 4438 | + "--enable-masked-comp=0", | ||
| 4439 | + "--enable-interintra-comp=0", | ||
| 4440 | + "--enable-dist-wtd-comp=0", | ||
| 4441 | + "--enable-diff-wtd-comp=0", | ||
| 4442 | + "--enable-onesided-comp=0", | ||
| 4443 | + "--enable-interintra-wedge=0", | ||
| 4444 | + "--enable-smooth-interintra=0", | ||
| 4445 | + "--enable-order-hint=0", | ||
| 4446 | + "--enable-ref-frame-mvs=0", | ||
| 4382 | "--enable-rect-partitions=0", | 4447 | "--enable-rect-partitions=0", |
| 4383 | "--enable-ab-partitions=0", | 4448 | "--enable-ab-partitions=0", |
| 4384 | "--enable-1to4-partitions=0", | 4449 | "--enable-1to4-partitions=0", |
| @@ -4420,8 +4485,8 @@ mod tests { | |||
| 4420 | String::from_utf8_lossy(&out.stderr) | 4485 | String::from_utf8_lossy(&out.stderr) |
| 4421 | ); | 4486 | ); |
| 4422 | let stream = out.stdout; | 4487 | let stream = out.stdout; |
| 4423 | - if let Ok(path) = std::env::var("EC_SUPERRES_STREAM_DUMP") { | 4488 | + if let Ok(path) = std::env::var("EC_SUPERRES_INTER_STREAM_DUMP") { |
| 4424 | - std::fs::write(path, &stream).expect("dump stream"); | 4489 | + std::fs::write(&path, &stream).expect("dump stream"); |
| 4425 | } | 4490 | } |
| 4426 | let frames = | 4491 | let frames = |
| 4427 | decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}")); | 4492 | decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}")); |
| @@ -4434,12 +4499,18 @@ mod tests { | |||
| 4434 | } | 4499 | } |
| 4435 | assert!( | 4500 | assert!( |
| 4436 | crate::superres::superres_hits() > 0, | 4501 | crate::superres::superres_hits() > 0, |
| 4437 | - "{NAME}: matched but zero superres_hits -- the gate never actually exercised the \ | 4502 | + "{NAME}: matched but zero superres_hits -- the upscaler never ran" |
| 4438 | - upscaler, it proves nothing" | 4503 | + ); |
| 4504 | + assert!( | ||
| 4505 | + crate::mc::predict_scaled_hits() > 0, | ||
| 4506 | + "{NAME}: matched but zero predict_scaled_hits -- every block took the unscaled MC \ | ||
| 4507 | + path, which proves nothing about the scaled-reference code this round adds \ | ||
| 4508 | + (class gate-blind-to-feature)" | ||
| 4439 | ); | 4509 | ); |
| 4440 | eprintln!( | 4510 | eprintln!( |
| 4441 | - "{NAME}: {frame_count} frames pixel-exact, superres_hits={}", | 4511 | + "{NAME}: {frame_count} frames pixel-exact, superres_hits={}, predict_scaled_hits={}", |
| 4442 | - crate::superres::superres_hits() | 4512 | + crate::superres::superres_hits(), |
| 4513 | + crate::mc::predict_scaled_hits() | ||
| 4443 | ); | 4514 | ); |
| 4444 | } | 4515 | } |
| 4445 | 4516 | ||
crates/ec-av1/src/superres.rsmodified+2 -2
| @@ -103,7 +103,7 @@ pub(crate) fn upscale_row(row: &[u8], real_right_margin: &[u8], out_width: usize | |||
| 103 | // mi-aligned `true_width` (the coding block straddling the frame edge) | 103 | // mi-aligned `true_width` (the coding block straddling the frame edge) |
| 104 | // -- libaom's border extension replicates from THAT last real column, | 104 | // -- libaom's border extension replicates from THAT last real column, |
| 105 | // not from `frame_width - 1`. `real_right_margin` (from | 105 | // not from `frame_width - 1`. `real_right_margin` (from |
| 106 | - // `decode::take_last_key_frame_wide_margin`) supplies those real | 106 | + // `decode::take_last_frame_wide_margin`) supplies those real |
| 107 | // pixels first; only once it runs out (or is empty, e.g. `fw` was | 107 | // pixels first; only once it runs out (or is empty, e.g. `fw` was |
| 108 | // already mi-aligned) does this fall back to r1's replicate. Pinned | 108 | // already mi-aligned) does this fall back to r1's replicate. Pinned |
| 109 | // column-by-column against real libaom via `scripts/superres-pin- | 109 | // column-by-column against real libaom via `scripts/superres-pin- |
| @@ -178,7 +178,7 @@ pub(crate) fn superres_hits() -> usize { | |||
| 178 | /// `frame_width`/`frame_height` (4:2:0 chroma) to `upscaled_width` at the | 178 | /// `frame_width`/`frame_height` (4:2:0 chroma) to `upscaled_width` at the |
| 179 | /// same height -- spec 7.16 is horizontal-only. Increments | 179 | /// same height -- spec 7.16 is horizontal-only. Increments |
| 180 | /// [`SUPERRES_HITS`] once per call. `margin`, when set (r3, from | 180 | /// [`SUPERRES_HITS`] once per call. `margin`, when set (r3, from |
| 181 | -/// `decode::take_last_key_frame_wide_margin`), is the real decoded pixels | 181 | +/// `decode::take_last_frame_wide_margin`), is the real decoded pixels |
| 182 | /// beyond `picture`'s own width out to the mi-aligned `true_width` -- see | 182 | /// beyond `picture`'s own width out to the mi-aligned `true_width` -- see |
| 183 | /// [`upscale_row`]'s doc for why the right-edge padding needs it. | 183 | /// [`upscale_row`]'s doc for why the right-edge padding needs it. |
| 184 | pub(crate) fn upscale_picture( | 184 | pub(crate) fn upscale_picture( |