diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index b16f0fcf..af0c9b82 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -28,15 +28,18 @@ use ec_av1_syntax::{ }; use ec_core::{Error, Result}; -// lane-av112bit: the 12-bit warp refusals below are inline literals -// (refusal_inventory.rs extracts them from the decode source); each names the -// witness gap that keeps the path refused -- warp's reduce bits inherit the -// 12-bit `conv_params->round_0` (warped_motion.c:295, convolve.h:81..86). -// lane-av112bitc lifted the compound pair of the same family: the compound -// combines absorb the CONV_BUF gain drop (`INTER_POST_ROUND - delta`, see -// `mc::combine_compound`) and the six-frame 12-bit compound witness is -// byte-exact vs ffmpeg. All sites are PARSE-time: a refused stream never -// builds a warp predictor. +// lane-av112bit: the 12-bit warp refusal that used to stand at all three +// warp decision sites (compound, 16x16+, 8x8 leaf) was an inline literal +// (refusal_inventory.rs extracts refusal strings from the decode source); +// it named the real gap: warp's reduce bits inherited the 12-bit +// `conv_params->round_0` (warped_motion.c:295, convolve.h:81..86) and no +// witness existed. +// lane-av112bitw lifted it from all three sites: `warp::warp_round_0` +// implements the bump (`round_0 += max(bd + FILTER_BITS - round_0 - 14, 0)`, +// 5 at 12 bits), and the single-ref witness plus the rotating-mandelbrot +// compound-warp witness are both byte-exact vs ffmpeg. Compound inter +// itself was lifted by lane-av112bitc before that (the combines absorb the +// CONV_BUF gain drop, `INTER_POST_ROUND - delta`, see `mc::combine_compound`). /// Per-frame decode state, one instance per decoded stream (lane-thread1). /// @@ -29093,13 +29096,12 @@ fn decode_inter_block( let warp1 = compound_warp(ref1, is_global_mv1).filter(|_| ref_unscaled(ref1)); if warp0.is_some() || warp1.is_some() { hit!(COMPOUND_WARP_HITS); - // lane-av112bit: refused by name -- see `WARP_12BIT_REFUSAL`. - if bit_depth(fctx) == 12 { - return Err(Error::unsupported( - "AV1 tile decode", - "warped motion at 12 bits (warp's reduce bits inherit the 12-bit round_0 and no 12-bit warp witness exists)", - )); - } + // lane-av112bitw: the 12-bit refusal that stood here is + // LIFTED with the compound-warp witness: the rotating- + // mandelbrot 12-bit recipe refused exactly here pre-lift and + // now decodes byte-exact vs ffmpeg through the same bumped + // `warp::warp_round_0` shifts + // (`a_real_compound_global_warp_12bit_stream_decodes_pixel_exact`). } // spec `get_ref_filter_type`: matches when EITHER of the // neighbour's two references equals this block's own ref0 -- @@ -30676,15 +30678,13 @@ fn decode_inter_block( hit!(AFFINE_GM_HITS); } } - // lane-av112bit: a local `WARPED_CAUSAL` projection (set above) or - // a global warp model both land here with `warp_params` set -- - // refused by name at 12 bits (see `WARP_12BIT_REFUSAL`). - if bit_depth(fctx) == 12 && warp_params.is_some() { - return Err(Error::unsupported( - "AV1 tile decode", - "warped motion at 12 bits (warp's reduce bits inherit the 12-bit round_0 and no 12-bit warp witness exists)", - )); - } + // lane-av112bitw: a local `WARPED_CAUSAL` projection (set above) + // or a global warp model both land here with `warp_params` set -- + // the 12-bit refusal that used to stand here is LIFTED: warp.rs's + // rounding is parameterised on the bumped `conv_params->round_0` + // (`warp::warp_round_0`, 5 at 12 bits) and the six-frame 12-bit + // warp stream decodes byte-exact vs ffmpeg + // (`a_12bit_warped_motion_stream_decodes_pixel_exact`). if crate::envflags::env_flag!("EC_AV1_TELL") { eprintln!( "TELL mi_row={mi_row} mi_col={mi_col} label=post_motion_mode eligible={} tell={} range={}", @@ -35527,15 +35527,11 @@ fn decode_inter_block8( hit!(AFFINE_GM_HITS); } } - // lane-av112bit: same 12-bit refusal as the 16x16+ leaf -- a local + // lane-av112bitw: same lift as the 16x16+ leaf -- a local // `WARPED_CAUSAL` projection or a global model both leave - // `warp_params` set here (see `WARP_12BIT_REFUSAL`). - if bit_depth(fctx) == 12 && warp_params.is_some() { - return Err(Error::unsupported( - "AV1 tile decode", - "warped motion at 12 bits (warp's reduce bits inherit the 12-bit round_0 and no 12-bit warp witness exists)", - )); - } + // `warp_params` set here; the 12-bit refusal that stood here is + // lifted with the same witness (`warp::warp_round_0` moved the + // filter's shifts; the same stream decodes byte-exact vs ffmpeg). if crate::envflags::env_flag!("EC_TRACE_MODE") { eprintln!( "EC_WARP8 mi_row={} mi_col={} warp={} globalblk={is_global_mv_block}", diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index e5ef31e2..547f2699 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -80,7 +80,14 @@ const REFUSALS: &[&str] = &[ // lane-av112bitc: compound joined the witnessed set (six-frame 12-bit // compound stream byte-exact vs ffmpeg; the combines already absorbed // the CONV_BUF gain drop through `INTER_POST_ROUND - delta`). - "warped motion at 12 bits (warp's reduce bits inherit the 12-bit round_0 and no 12-bit warp witness exists)", + // lane-av112bitw: warp joined too -- the refusal left all three decision + // sites (compound, 16x16+, 8x8 leaf): `warp::warp_round_0` implements + // convolve.h's 12-bit `round_0` bump (3 -> 5), and both the single-ref + // witness (`a_12bit_warped_motion_stream_decodes_pixel_exact`, the exact + // recipe that refused pre-lift) and the rotating-mandelbrot + // compound-warp witness + // (`a_real_compound_global_warp_12bit_stream_decodes_pixel_exact`, 28 + // compound warp blocks) are byte-exact vs ffmpeg. "film grain synthesis at 12 bits (no byte-exact 12-bit grain witness exists: the 12-bit gates encode with grain off)", "a 12-bit frame with screen content tools (allow_screen_content_tools=1: neither palette nor intrabc has a 12-bit witness)", // lane-av1txr: the silent-garbage guard. A 4:4:4/4:2:2 stream used to @@ -363,10 +370,11 @@ const PROVEN: &[(&str, &str)] = &[ // lane-av112bitc: the compound pair left with its refusal -- the // six-frame compound stream now DECODES byte-exact // (`a_real_aomenc_12bit_compound_inter_sequence_decodes_pixel_exact`). - ( - "warped motion at 12 bits (warp's reduce bits inherit the 12-bit round_0 and no 12-bit warp witness exists)", - "a_12bit_warped_motion_stream_is_refused_by_name", - ), + // lane-av112bitw: the warp pair left too -- its gate now WITNESSES + // (`a_12bit_warped_motion_stream_decodes_pixel_exact`, the same recipe + // that refused pre-lift) and the compound-warp arm witnesses through + // `a_real_compound_global_warp_12bit_stream_decodes_pixel_exact` + // (hard `compound_warp_hits > 0`). ( "film grain synthesis at 12 bits (no byte-exact 12-bit grain witness exists: the 12-bit gates encode with grain off)", "a_12bit_film_grain_stream_is_refused_by_name", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 99fb48d4..8a365834 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -8037,31 +8037,68 @@ pub(crate) mod tests { } } - /// The 12-bit warp refusal, exercised on a REAL stream: the same source - /// and recipe with the warp tools ON -- aomenc picks a global warp model - /// on this content (measured: the decode refuses at the first warped - /// block) -- is refused by name. + /// The 12-bit WARP witness (lane-av112bitw): the same source and recipe + /// with the warp tools ON -- aomenc picks warp models on this content + /// (measured pre-lift: the warp model fires at the third frame, and the + /// decode refused by name at exactly that block) -- now decodes + /// BYTE-EXACT against ffmpeg. The warp filter's shifts are the bumped + /// `conv_params->round_0` (`warp::warp_round_0`, 5 at 12 bits, feeding + /// `reduce_bits_horiz`, the derived non-compound + /// `reduce_bits_vert = 2*FILTER_BITS - round_0` and both `offset_bits`), + /// the whole libaom `get_conv_params_no_round` 12-bit bump. + /// + /// Non-vacuous: the same recipe refused by name before the lift, the + /// gate hard-asserts a warp predictor was really resolved (a warpless + /// stream would pass the pixel compare and prove nothing), and every + /// plane of every frame compares against ffmpeg's decode. #[test] - fn a_12bit_warped_motion_stream_is_refused_by_name() { - const NAME: &str = "a_12bit_warped_motion_stream_is_refused_by_name"; + fn a_12bit_warped_motion_stream_decodes_pixel_exact() { + const NAME: &str = "a_12bit_warped_motion_stream_decodes_pixel_exact"; let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } if !have_aomenc() { eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); return; } let y4m = y4m_12bit_subpel_source(6); - // Exactly the recipe measured to refuse at warp: warp ON, global - // motion NOT spelled (spelling it ON makes a GLOBAL_GLOBALMV - // compound block reach the compound refusal first), six frames -- - // the warp model fires at the third frame. + // Exactly the recipe measured to refuse at warp pre-lift: warp ON, + // global motion NOT spelled (spelling it ON drives a GLOBAL_GLOBALMV + // compound block into the compound-warp arm -- see the compound gate + // below), six frames -- the warp model fires at the third frame. let stream = encode_12bit(&y4m, 6, &["--enable-warped-motion=1"]); - let err = decode_stream(&stream).unwrap_err().to_string(); + assert_12bit_sequence_header(&stream, NAME); + let (before_selected, before_warp8, before_affine) = ( + decode::warp_selected_hits(), + decode::warp_hits_8(), + decode::affine_gm_hits(), + ); + let frames = decode_stream(&stream).unwrap_or_else(|e| { + panic!("{NAME}: decode_stream refused a real 12-bit warp stream: {e}") + }); + assert_eq!(frames.len(), 6); + let (delta_selected, delta_warp8, delta_affine) = ( + decode::warp_selected_hits() - before_selected, + decode::warp_hits_8() - before_warp8, + decode::affine_gm_hits() - before_affine, + ); + eprintln!( + "{NAME}: warp_engagement selected(16x16+ symbol)={delta_selected} \ + warped8(usable 8x8 model)={delta_warp8} affine_gm(6-param model)={delta_affine}" + ); assert!( - err.contains( - "warped motion at 12 bits (warp's reduce bits inherit the 12-bit round_0 and no 12-bit warp witness exists)" - ), - "{NAME}: expected the 12-bit warp refusal, got: {err}" + delta_selected + delta_warp8 + delta_affine > 0, + "{NAME}: no warp predictor was resolved -- the stream carries no \ + warp model and the pixel compare would prove nothing" ); + let ffmpeg_frames = ffmpeg_decode_sequence_12bit(&stream, 160, 128, 6); + for (i, (ours, reference)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(ours.y, reference.y, "frame {i} luma vs ffmpeg (12-bit warp)"); + assert_eq!(ours.u, reference.u, "frame {i} U vs ffmpeg (12-bit warp)"); + assert_eq!(ours.v, reference.v, "frame {i} V vs ffmpeg (12-bit warp)"); + } } /// The 12-bit COMPOUND witness (lane-av112bitc): the parent's source @@ -21181,7 +21218,7 @@ pub(crate) mod tests { /// `mc::predict_compound_intermediate`. `compound_warp_hits() > 0` is a /// hard assert: a run where the encoder never emitted one proves nothing. /// A decode error or a pixel mismatch is a FAILURE, never a skip. - fn run_compound_global_warp_gate(name: &str, ten_bit: bool) { + fn run_compound_global_warp_gate(name: &str, bd: u32) { let _gate_lock = lock_gate_counters(); assert!(have_ffmpeg(), "{name}: ffmpeg required"); assert!(have_aomenc(), "{name}: no aomenc at {}", aomenc_path().display()); @@ -21204,7 +21241,11 @@ pub(crate) mod tests { h = height * 2, sx = -0.6 + 0.01 * (i as f64), ); - let pix_fmt = if ten_bit { "yuv420p10le" } else { "yuv420p" }; + let pix_fmt = match bd { + 8 => "yuv420p", + 10 => "yuv420p10le", + _ => "yuv420p12le", + }; let y4m = Command::new("ffmpeg") .args([ "-v", "error", "-f", "lavfi", "-i", &source, "-t", @@ -21222,6 +21263,8 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let cq_arg = format!("--cq-level={cq}"); + let (in_depth_arg, depth_arg) = + (format!("--input-bit-depth={bd}"), format!("--bit-depth={bd}")); let mut args: Vec<&str> = vec![ "--codec=av1", "--passes=1", @@ -21266,8 +21309,11 @@ pub(crate) mod tests { "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0", ]; - if ten_bit { - args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); + if bd != 8 { + args.extend_from_slice(&[ + in_depth_arg.as_str(), + depth_arg.as_str(), + ]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); let out = run_with_stdin(Command::new(aomenc_path()) @@ -21295,10 +21341,10 @@ pub(crate) mod tests { } Ok(frames) => frames, }; - let want = if ten_bit { - ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) - } else { - ffmpeg_decode_sequence(&stream, width, height, frame_count) + let want = match bd { + 8 => ffmpeg_decode_sequence(&stream, width, height, frame_count), + 10 => ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count), + _ => ffmpeg_decode_sequence_12bit(&stream, width, height, frame_count), }; assert_eq!(frames.len(), frame_count); if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") @@ -21550,7 +21596,7 @@ pub(crate) mod tests { /// 8-bit arm of [`run_compound_global_warp_gate`]. #[test] fn a_real_compound_global_warp_stream_decodes_pixel_exact() { - run_compound_global_warp_gate("a_real_compound_global_warp_stream_decodes_pixel_exact", false); + run_compound_global_warp_gate("a_real_compound_global_warp_stream_decodes_pixel_exact", 8); } /// 10-bit arm of [`run_compound_global_warp_gate`] -- both of his films are @@ -21569,7 +21615,22 @@ pub(crate) mod tests { fn a_real_compound_global_warp_10bit_stream_decodes_pixel_exact() { run_compound_global_warp_gate( "a_real_compound_global_warp_10bit_stream_decodes_pixel_exact", - true, + 10, + ); + } + + /// 12-bit arm of [`run_compound_global_warp_gate`] (lane-av112bitw): the + /// same rotating-mandelbrot recipe at `--bit-depth=12`. Pre-lift the + /// first `GLOBAL_GLOBALMV` block under a ROTZOOM model refused ("warped + /// motion at 12 bits"); the lift runs the same `warp::warp_round_0` bump + /// through `warp_affine_compound` (`reduce_bits_horiz` 5, compound + /// `reduce_bits_vert` stays 7, the CONV_BUF blend bias one octave down: + /// `(1 << (bd + 2)) + (1 << (bd + 1))`). + #[test] + fn a_real_compound_global_warp_12bit_stream_decodes_pixel_exact() { + run_compound_global_warp_gate( + "a_real_compound_global_warp_12bit_stream_decodes_pixel_exact", + 12, ); } diff --git a/crates/ec-av1/src/warp.rs b/crates/ec-av1/src/warp.rs index b93dc8fe..589ab603 100644 --- a/crates/ec-av1/src/warp.rs +++ b/crates/ec-av1/src/warp.rs @@ -328,12 +328,20 @@ fn get_shear_params(wmmat: [i32; 6]) -> Option<(i16, i16, i16, i16)> { return None; } let mat = wmmat.map(|v| v as i64); - let mut alpha = clamp(mat[2] - (1 << WARPEDMODEL_PREC_BITS), i16::MIN as i64, i16::MAX as i64); + let mut alpha = clamp( + mat[2] - (1 << WARPEDMODEL_PREC_BITS), + i16::MIN as i64, + i16::MAX as i64, + ); let beta = clamp(mat[3], i16::MIN as i64, i16::MAX as i64); let (y_mag, shift) = resolve_divisor_32(mat[2].unsigned_abs() as u32); let y = if mat[2] < 0 { -y_mag } else { y_mag }; let v = (mat[4] * (1 << WARPEDMODEL_PREC_BITS)) * y; - let mut gamma = clamp(round2_signed(v, shift as u32), i16::MIN as i64, i16::MAX as i64); + let mut gamma = clamp( + round2_signed(v, shift as u32), + i16::MIN as i64, + i16::MAX as i64, + ); let v = (mat[3] * mat[4]) * y; let mut delta = clamp( mat[5] - round2_signed(v, shift as u32) - (1 << WARPEDMODEL_PREC_BITS), @@ -414,7 +422,13 @@ pub fn find_projection( /// translational fallback in that rare case. pub fn global_warp_params(wmmat: [i32; 6]) -> Option { let (alpha, beta, gamma, delta) = get_shear_params(wmmat)?; - Some(WarpParams { wmmat, alpha, beta, gamma, delta }) + Some(WarpParams { + wmmat, + alpha, + beta, + gamma, + delta, + }) } fn clip_pixel(v: i32, fctx: &crate::decode::FrameCtx) -> u16 { @@ -442,17 +456,30 @@ pub(crate) fn warp_affine( p_height: i32, p_stride: i32, subsampling_x: i32, - subsampling_y: i32, fctx: &crate::decode::FrameCtx, + subsampling_y: i32, + fctx: &crate::decode::FrameCtx, ) { if crate::envflags::env_flag!("EC_MC_TRACE") { eprintln!("EC_MC_WARP x={p_col} y={p_row} w={p_width} h={p_height}"); } let bd = i32::from(crate::decode::bit_depth(fctx)); - // `reduce_bits_vert`, non-compound: `2 * FILTER_BITS - round_0`. - let reduce_bits_vert = 2 * FILTER_BITS - REDUCE_BITS_HORIZ; + // `reduce_bits_vert`, non-compound: `2 * FILTER_BITS - round_0` (the + // bumped `conv_params->round_0`, [`warp_round_0`]). + let reduce_bits_vert = 2 * FILTER_BITS - warp_round_0(bd); warp_inner( - params, reference, width, height, stride, p_col, p_row, p_width, p_height, - subsampling_x, subsampling_y, bd, reduce_bits_vert, + params, + reference, + width, + height, + stride, + p_col, + p_row, + p_width, + p_height, + subsampling_x, + subsampling_y, + bd, + reduce_bits_vert, |row, col, sum| { dst[row * p_stride as usize + col] = clip_pixel(sum - (1 << (bd - 1)) - (1 << bd), fctx); @@ -471,8 +498,8 @@ pub(crate) fn warp_affine( /// both roundings exactly because both exceed their shift) and subtracts /// `(1 << (offset_bits - round_1)) + (1 << (offset_bits - round_1 - 1))` /// at the blend; this crate's intermediates are UNBIASED (see -/// [`mc::diffwtd_mask`]'s derivation), so the identical constant -- -/// `(1 << (bd + 4)) + (1 << (bd + 3))` -- is removed here instead, making +/// [`mc::diffwtd_mask`]'s derivation), so the identical constant, derived +/// from the bumped `round_0` below, is removed here instead, making /// the output directly interchangeable with /// [`mc::predict_compound_intermediate`]'s for /// [`mc::combine_compound`]/[`mc::blend_masked_compound`]. @@ -490,27 +517,61 @@ pub(crate) fn warp_affine_compound( p_height: i32, p_stride: i32, subsampling_x: i32, - subsampling_y: i32, fctx: &crate::decode::FrameCtx, + subsampling_y: i32, + fctx: &crate::decode::FrameCtx, ) { let bd = i32::from(crate::decode::bit_depth(fctx)); - let bias = (1 << (bd + 4)) + (1 << (bd + 3)); + // The CONV_BUF bias libaom subtracts at the blend: + // `(1 << (offset_bits - round_1)) + (1 << (offset_bits - round_1 - 1))` + // with `offset_bits = bd + 2 * FILTER_BITS - round_0` (round_0 the bumped + // [`warp_round_0`], round_1 [`COMPOUND_ROUND1_BITS`], unbumped for + // compound): `(1 << (bd + 4)) + (1 << (bd + 3))` at 8/10-bit, one octave + // less at 12-bit. + let offset_bits = bd + 2 * FILTER_BITS - warp_round_0(bd); + let bias = (1 << (offset_bits - COMPOUND_ROUND1_BITS)) + + (1 << (offset_bits - COMPOUND_ROUND1_BITS - 1)); warp_inner( - params, reference, width, height, stride, p_col, p_row, p_width, p_height, - subsampling_x, subsampling_y, bd, COMPOUND_ROUND1_BITS, + params, + reference, + width, + height, + stride, + p_col, + p_row, + p_width, + p_height, + subsampling_x, + subsampling_y, + bd, + COMPOUND_ROUND1_BITS, |row, col, sum| { dst[row * p_stride as usize + col] = sum - bias; }, ); } -/// `conv_params->round_0` (`ROUND0_BITS`), the warp filter's horizontal -/// rounding -- `InterRound0`, bit-depth independent for 8/10-bit content -/// (libaom only raises it at `bd == 12`, which this decoder refuses). -const REDUCE_BITS_HORIZ: i32 = 3; +/// `ROUND0_BITS` (`convolve.h`): `conv_params->round_0` before +/// `get_conv_params_no_round`'s high-bitdepth buffer-range bump. +const ROUND0_BITS: i32 = 3; /// `COMPOUND_ROUND1_BITS` (`convolve.h`): `conv_params->round_1` when -/// `is_compound`. +/// `is_compound` (NOT bumped at 12 bits -- the bump moves `round_0` and, for +/// non-compound, `round_1` by the same delta, keeping the filter gain +/// constant). const COMPOUND_ROUND1_BITS: i32 = 7; +/// `conv_params->round_0` after `get_conv_params_no_round`'s bump +/// (`convolve.h`): `round_0 += max(bd + FILTER_BITS - round_0 - 14, 0)` -- +/// 3 at 8/10-bit, 5 at 12-bit (`intbufrange = bd + FILTER_BITS - round_0 + +/// 2` overflows 16 bits from bd 12 on). The warp filter's +/// `reduce_bits_horiz` IS `conv_params->round_0` (`warped_motion.c:295`), +/// and the non-compound `reduce_bits_vert` plus both `offset_bits_*` terms +/// read back through it, so this one parameter moves every shift the warp +/// filter runs (lane-av112bitw: the 12-bit warp witness decodes byte-exact +/// through it). +fn warp_round_0(bd: i32) -> i32 { + ROUND0_BITS + (bd + FILTER_BITS - ROUND0_BITS - 14).max(0) +} + /// The shared body of [`warp_affine`]/[`warp_affine_compound`] /// (`av1_highbd_warp_affine_c`): everything up to and including the /// vertical `ROUND_POWER_OF_TWO(sum, reduce_bits_vert)`, with `store` @@ -539,7 +600,7 @@ fn warp_inner( params.gamma as i64, params.delta as i64, ); - let reduce_bits_horiz = REDUCE_BITS_HORIZ; + let reduce_bits_horiz = warp_round_0(bd); let offset_bits_horiz = bd + FILTER_BITS - 1; let offset_bits_vert = bd + 2 * FILTER_BITS - reduce_bits_horiz; @@ -570,8 +631,8 @@ fn warp_inner( let mut sx = sx4 + beta * (k as i64 + 4); for l in -4..4i32 { let ix = ix4 + l - 3; - let offs = - (round2(sx, WARPEDDIFF_PREC_BITS) as i32 + WARPEDPIXEL_PREC_SHIFTS) as usize; + let offs = (round2(sx, WARPEDDIFF_PREC_BITS) as i32 + WARPEDPIXEL_PREC_SHIFTS) + as usize; let coeffs = &AV1_WARPED_FILTER[offs]; let mut sum: i32 = 1 << offset_bits_horiz; for (m, &c) in coeffs.iter().enumerate() { @@ -591,12 +652,13 @@ fn warp_inner( let l_hi = (4i32).min(p_col + p_width - j - 4); let mut l = -4i32; while l < l_hi { - let offs = - (round2(sy, WARPEDDIFF_PREC_BITS) as i32 + WARPEDPIXEL_PREC_SHIFTS) as usize; + let offs = (round2(sy, WARPEDDIFF_PREC_BITS) as i32 + WARPEDPIXEL_PREC_SHIFTS) + as usize; let coeffs = &AV1_WARPED_FILTER[offs]; let mut sum: i32 = 1 << offset_bits_vert; for m in 0..8i32 { - sum += tmp[(k + m + 4) as usize][(l + 4) as usize] * coeffs[m as usize] as i32; + sum += + tmp[(k + m + 4) as usize][(l + 4) as usize] * coeffs[m as usize] as i32; } sum = round2(sum as i64, reduce_bits_vert as u32) as i32; store( diff --git a/lanes/av112bitw.report.md b/lanes/av112bitw.report.md new file mode 100644 index 00000000..3c343ddf --- /dev/null +++ b/lanes/av112bitw.report.md @@ -0,0 +1,123 @@ +# lane-av112bitw — the 12-bit warp lift + +Base 786c15b6 (lane-av112bitc's merged tree), worktree `edith_codecs-av112bw`, +branch `lane-av1-12bit-warp`. The charter: lift the named 12-bit warp refusal +("warped motion at 12 bits (warp's reduce bits inherit the 12-bit round_0 and +no 12-bit warp witness exists)") exactly as far as real `aomenc --bit-depth=12` +warp witnesses prove byte-exactness against ffmpeg, and keep grain and screen +content refused by name. + +## Reaching the path (encode budget: 3 probes + 6 gate encodes pre-lift + 6 post-lift) + +1. **Recipe 1 (the parent's refusal recipe, re-proven on this base)**: the + 12-bit sub-pel source (160x128 C420p12, gradient + texture, travelling + box), six frames, `--enable-warped-motion=1` (global motion NOT spelled). + The unmodified tree's gate `a_12bit_warped_motion_stream_is_refused_by_name` + encoded it live and refused by name — warp emits, refusal fires. Post-lift + the same recipe is the single-ref witness. +2. **Recipe 2 (negative result, reported per charter)**: same source, warp ON + **and** `--enable-global-motion=1`. It decodes byte-exact post-lift but + `compound_warp_hits` delta is **0**: pan/box content only fits TRANSLATION + global models, and the compound-warp site needs model > TRANSLATION per + slot (`is_global_mv_block`, blockd.h:421-429, pinned by lane-cwarp r1). + NOT a compound-warp witness; the throwaway probe gate was deleted again. +3. **Recipe 3 (the lever)**: the lane-cwarp gate's rotating-mandelbrot recipe + (`mandelbrot` + `rotate=a=rate*n`, 128x128 -> 64x64, 24 frames, 3 cq x 2 + rate) already hard-asserts `compound_warp_hits > 0` at 8/10 bits. Its + 12-bit arm refused pre-lift at the compound-warp site on the FIRST attempt + (`refused on warp (cq 32)` — reachability + non-vacuity in one run), and + post-lift it is the compound-warp witness. + +## What changed + +- **warp.rs** — the hard `REDUCE_BITS_HORIZ: i32 = 3` became + `warp_round_0(bd)` = `ROUND0_BITS + max(bd + FILTER_BITS - ROUND0_BITS - + 14, 0)`, the exact `get_conv_params_no_round` bump (convolve.h: + `intbufrange = bd + FILTER_BITS - round_0 + 2`; overflows 16 bits from + bd 12 on, so `round_0` 3 -> 5). 3 at 8/10-bit (identical to before), 5 at + 12-bit. Everything else derives from it exactly as warped_motion.c:295-301 + reads: `reduce_bits_horiz` IS `conv_params->round_0`; the non-compound + `reduce_bits_vert = 2*FILTER_BITS - round_0` (11 -> 9 at 12 bits, filter + gain constant); `offset_bits_horiz`/`offset_bits_vert` keep their formulas. + `warp_affine_compound`'s CONV_BUF blend bias is now derived + (`(1 << (offset_bits - round_1)) + (1 << (offset_bits - round_1 - 1))`) — + `(1 << (bd+4)) + (1 << (bd+3))` at 8/10 bits (identical to before), one + octave down at 12 bits; compound `reduce_bits_vert` stays + `COMPOUND_ROUND1_BITS = 7` (the bump never moves compound round_1). +- **decode.rs** — all three 12-bit warp refusal sites deleted: the + compound-warp arm (`COMPOUND_WARP_HITS`, 16x16+ path), the 16x16+ + single-ref site and the 8x8-leaf site (both guarded + `bit_depth == 12 && warp_params.is_some()`, covering the local + WARPED_CAUSAL arm AND the single-ref global-warp arm — the filter is the + same `warp_affine`, and the model source is bit-depth independent and + 10-bit-pinned). Header comment over the 12-bit family updated: the family + is now grain + screen content only. +- **Found during the lift (recorded, closed by it)**: the 8x8-leaf + compound-warp arm (`decode_inter_block8`'s `COMPOUND_WARP_HITS_8` site) + had NO 12-bit refusal at all — a 12-bit stream whose first warp block was + an 8x8 compound leaf would have decoded silently through the wrong + shifts. The refusal map was incomplete, not just unlifted; post-lift the + site runs the witnessed parameterised path like every other warp site. +- **refusal_inventory.rs** — the warp string left `REFUSALS` (38 -> 37) and + its pair left `PROVEN`; both slots carry lane-av112bitw notes pointing at + the witnesses. `the_decode_path_refuses_exactly_the_listed_cases` and + `every_proven_refusal_names_a_test_that_exists` both green. +- **stream.rs** — the refusal gate was REPLACED by the single-ref witness + (below), and `run_compound_global_warp_gate` was generalised + `ten_bit: bool` -> `bd: u32` with a third caller. The 8/10-bit arms are + byte-identical recipes (8-bit still passes NO depth flags). + +## The witnesses + +Encoder: the local aom oracle build (`~/.cache/aom-oracle/build/aomenc`, +libaom src `92d4c37fbdd08944a0e721bbaeb13318f10aebb0`); reference decode +ffmpeg 8.1.2 (`yuv420p12le` rawvideo). Gates encode live; the committed +fixtures are untouched (no new fixture needed). + +1. **Single-ref** `a_12bit_warped_motion_stream_decodes_pixel_exact` — the + exact recipe that refused pre-lift, 6 frames, byte-exact vs ffmpeg on + every plane of every frame. Engagement: `warp_selected_hits` 7 (16x16+ + WARPED_CAUSAL), `warp_hits_8` 1 (usable 8x8 local model), + `affine_gm_hits` 0 (content fits no >TRANSLATION global model — the + single-ref global-warp arm rides on the same filter + the composition + argument, not its own stream). Hard counter assert so a warpless stream + cannot pass vacuously. +2. **Compound** `a_real_compound_global_warp_12bit_stream_decodes_pixel_exact` + — the cwarp rotating-mandelbrot recipe at `--bit-depth=12`: **6/6 + attempts pixel-exact, 0 named refusals, compound_warp_hits = 28**, with + the gate's own hard asserts (`hits > 0`, `matched > 0`, no refusal may + contain "warp"). Pre-lift the same gate FAILED with the warp refusal on + attempt 1 — non-vacuity both directions. + +## Results + +- 12-bit battery: key, inter, compound (parent fixtures) all still + byte-exact; `a_12bit_screen_content_stream_is_refused_by_name` and + `a_12bit_film_grain_stream_is_refused_by_name` still refuse by name. +- Warp family: 8-bit and 10-bit cwarp gates green (the parameterisation is + a no-op at bd <= 10, proven not just claimed), both fimv + force-integer-mv warp-alphabet gates green, both 10-bit film fixture + gates with warp green (`a_10bit_128sb_film_frames_with_warp_cdef_and_interintra...`, + `a_10bit_film_frames_with_small_side_globalmv_and_rect_warp_reach...`). +- `refusal_inventory` + `gate_coverage` suites green. +- `cargo check -p ec-av1 --all-targets`: 0 warnings. + +## Open halves (recorded, not silently dropped) + +1. **Single-ref GLOBAL-warp at 12 bits has no stream of its own** (engagement + 0 on this content): lifted on the composition argument — identical + `warp_affine` filter, bit-depth-independent model source, both pieces + witnessed. A stream whose single-ref blocks warp under a ROTZOOM global + model would close it outright; the mandelbrot content produces those + models only on compound blocks here. +2. **Grain and screen content stay refused by name** (untouched, per + charter): `film grain synthesis at 12 bits ...` and + `a 12-bit frame with screen content tools ...` with their real-stream + refusal gates. + +## Create-list audit + +Exactly one new file: this report. Touched: `warp.rs` (the parameterisation), +`decode.rs` (three refusal deletions + header comment), `stream.rs` (witness +gate swap + gate generalisation), `refusal_inventory.rs` (two row removals + +notes). No fixture, no junk file.