Global-warp prediction for single-ref GLOBALMV (allow_warp's global_warp_allowed branch)
Browse files at this commiteed6f8ced761e64754c31ca305ae41f55a5b7a3eParent: 4fc67a0- feat
- global-warp prediction for single-ref GLOBALMV (allow_warp's global_warp_allowed branch)
3 changed files +70 -2
- crates/ec-av1/src/decode.rs +20 -0
- crates/ec-av1/src/stream.rs +35 -2
- crates/ec-av1/src/warp.rs +15 -0
crates/ec-av1/src/decode.rsmodified+20 -0
| @@ -6372,6 +6372,26 @@ fn decode_inter_block( | |||
| 6372 | } | 6372 | } |
| 6373 | } | 6373 | } |
| 6374 | } | 6374 | } |
| 6375 | + // lane-gm r4: `allow_warp`'s `global_warp_allowed` branch | ||
| 6376 | + // (`reconinter.c:33-55`), gated INDEPENDENTLY of `motion_mode` -- | ||
| 6377 | + // libaom's `av1_init_warp_params` runs for every inter | ||
| 6378 | + // predictor build, not just a `WARPED_CAUSAL`-selected one. Only | ||
| 6379 | + // reachable when `warp_params` is still `None` here: a block | ||
| 6380 | + // that read (and got) local `WARPED_CAUSAL` above already has | ||
| 6381 | + // `local_warp_allowed && !wm_params.invalid`, which `allow_warp` | ||
| 6382 | + // checks FIRST and short-circuits on -- the global branch is an | ||
| 6383 | + // `else if`, never layered on top. `is_global_mv_block` already | ||
| 6384 | + // encodes `allow_warp`'s size bound (`min(bw4,bh4) >= 2`, i.e. | ||
| 6385 | + // >=8px both dims, matching `av1_init_warp_params`'s | ||
| 6386 | + // `block_height < 8 || block_width < 8` early return) and, via | ||
| 6387 | + // `motion_mode_eligible`'s own suppression above, the | ||
| 6388 | + // `force_integer_mv` case never reads a motion_mode symbol at | ||
| 6389 | + // all -- checked again here directly since this branch fires | ||
| 6390 | + // independent of `motion_mode_eligible`. | ||
| 6391 | + let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize]; | ||
| 6392 | + if warp_params.is_none() && is_global_mv_block && !force_integer_mv && !gm_ref.invalid { | ||
| 6393 | + warp_params = crate::warp::global_warp_params(gm_ref.params); | ||
| 6394 | + } | ||
| 6375 | if std::env::var_os("EC_AV1_TELL").is_some() { | 6395 | if std::env::var_os("EC_AV1_TELL").is_some() { |
| 6376 | eprintln!( | 6396 | eprintln!( |
| 6377 | "TELL mi_row={mi_row} mi_col={mi_col} label=post_motion_mode eligible={} tell={} range={}", | 6397 | "TELL mi_row={mi_row} mi_col={mi_col} label=post_motion_mode eligible={} tell={} range={}", |
crates/ec-av1/src/stream.rsmodified+35 -2
| @@ -235,14 +235,47 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 235 | // to plain translational MC with the block-centre mv for every | 235 | // to plain translational MC with the block-centre mv for every |
| 236 | // other GLOBALMV block, which is only a centre-point approximation | 236 | // other GLOBALMV block, which is only a centre-point approximation |
| 237 | // of the true per-pixel warp. That is the entire remaining gap. | 237 | // of the true per-pixel warp. That is the entire remaining gap. |
| 238 | + // lane-gm r4: `decode.rs` now feeds `global_motion[ref]` into | ||
| 239 | + // `crate::warp::global_warp_params` for every single-ref | ||
| 240 | + // `is_global_mv_block` (ROTZOOM/AFFINE), matching `allow_warp`'s | ||
| 241 | + // `global_warp_allowed` branch -- ROTZOOM is pin-verified | ||
| 242 | + // (`gm-seed43.obu`, frame 1 luma MATCH) and TRANSLATION already | ||
| 243 | + // worked (`gm_get_motion_vector`'s translation-only mv, no warp | ||
| 244 | + // needed). AFFINE is untested this round (no aomenc fixture in the | ||
| 245 | + // wedge gate reached a 6-parameter model) -- keep refusing it by | ||
| 246 | + // name rather than shipping an unverified decode. | ||
| 238 | if header.frame_type != FrameType::Key | 247 | if header.frame_type != FrameType::Key |
| 239 | && header.global_motion[..7] | 248 | && header.global_motion[..7] |
| 240 | .iter() | 249 | .iter() |
| 241 | - .any(|gm| gm.model != WarpModel::Identity) | 250 | + .any(|gm| gm.model == WarpModel::Affine) |
| 242 | { | 251 | { |
| 243 | return Err(Error::unsupported( | 252 | return Err(Error::unsupported( |
| 244 | "AV1 decode_stream", | 253 | "AV1 decode_stream", |
| 245 | - "an inter frame whose global motion for a single-reference frame is not IDENTITY (GLOBALMV needs the full warp derivation this decoder does not carry)", | 254 | + "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)", |
| 255 | + )); | ||
| 256 | + } | ||
| 257 | + // lane-gm r4: a NEW mismatch, distinct from the one this round | ||
| 258 | + // fixed and NOT explained by `reference_select`/compound (traced | ||
| 259 | + // live: the mismatched frame of the seed-43 pin has | ||
| 260 | + // `reference_select == false`) -- localized instead to the one | ||
| 261 | + // property that DOES distinguish it from every frame that already | ||
| 262 | + // matches: TWO different ref slots (`GOLDEN_FRAME`, `BWDREF_FRAME`) | ||
| 263 | + // carry a non-translation model AT THE SAME TIME. The pin-verified | ||
| 264 | + // fix (frame 1) only ever exercised a single active non-identity | ||
| 265 | + // slot (`LAST_FRAME` alone). Root cause not yet found within this | ||
| 266 | + // round's budget (do not guess-fix): refuse the untested shape by | ||
| 267 | + // name -- more than one concurrently active ROTZOOM/AFFINE ref -- | ||
| 268 | + // rather than ship it silently wrong. | ||
| 269 | + if header.frame_type != FrameType::Key | ||
| 270 | + && header.global_motion[..7] | ||
| 271 | + .iter() | ||
| 272 | + .filter(|gm| gm.model != WarpModel::Identity && gm.model != WarpModel::Translation) | ||
| 273 | + .count() | ||
| 274 | + > 1 | ||
| 275 | + { | ||
| 276 | + return Err(Error::unsupported( | ||
| 277 | + "AV1 decode_stream", | ||
| 278 | + "an inter frame with more than one concurrently active ROTZOOM/AFFINE global-motion ref slot (single-active-slot ROTZOOM is pin-verified; this shape is not)", | ||
| 246 | )); | 279 | )); |
| 247 | } | 280 | } |
| 248 | // lane-av1comp: `decode_inter_block`/`decode_inter_block8` now read | 281 | // lane-av1comp: `decode_inter_block`/`decode_inter_block8` now read |
crates/ec-av1/src/warp.rsmodified+15 -0
| @@ -400,6 +400,21 @@ pub fn find_projection( | |||
| 400 | }) | 400 | }) |
| 401 | } | 401 | } |
| 402 | 402 | ||
| 403 | +/// lane-gm r4: `allow_warp`'s `global_warp_allowed` branch | ||
| 404 | +/// (`reconinter.c:50`) -- reuses the SAME shear decomposition | ||
| 405 | +/// [`find_projection`]'s local-warp path calls (`get_shear_params`), just | ||
| 406 | +/// keyed on the frame's already-coded `global_motion[ref]` model instead of | ||
| 407 | +/// a per-block least-squares fit. Caller gates this on `is_global_mv_block | ||
| 408 | +/// && !global_motion[ref].invalid` (matching `allow_warp` exactly); `None` | ||
| 409 | +/// here means the model's own shear is not filter-representable even though | ||
| 410 | +/// the frame header's `warpValid` bit said otherwise for a `mat[2] <= 0` | ||
| 411 | +/// edge `get_shear_params` additionally rejects -- caller keeps its | ||
| 412 | +/// translational fallback in that rare case. | ||
| 413 | +pub fn global_warp_params(wmmat: [i32; 6]) -> Option<WarpParams> { | ||
| 414 | + let (alpha, beta, gamma, delta) = get_shear_params(wmmat)?; | ||
| 415 | + Some(WarpParams { wmmat, alpha, beta, gamma, delta }) | ||
| 416 | +} | ||
| 417 | + | ||
| 403 | fn clip_pixel(v: i32) -> u8 { | 418 | fn clip_pixel(v: i32) -> u8 { |
| 404 | v.clamp(0, 255) as u8 | 419 | v.clamp(0, 255) as u8 |
| 405 | } | 420 | } |