forge
Explore
Log in

Don't you dare go Hollow

wip(leaf8tx): partial from the interrupted round

Browse files at this commit

d7c8428cc7c79206e0445005067e2c33480c5ed7Ahmet Kaan GümüşParent: ca1ea86
crates/ec-av1/src/decode.rsmodified+111 -39
@@ -181,6 +181,16 @@ thread_local! {
181181 static INTRA_IN_INTER8_UV_CFL_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
182182 }
183183
184+thread_local! {
185+ static INTRA_IN_INTER8_ANGLE_DELTA_Y_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
186+}
187+
188+/// Nonzero luma angle deltas coded by an intra 8x8 leaf inside an inter frame
189+/// (lane-leaf8tx r1) -- counted only in [`decode_inter_block8`]'s intra arm.
190+pub(crate) fn intra_in_inter8_angle_delta_y_hits() -> usize {
191+ INTRA_IN_INTER8_ANGLE_DELTA_Y_HITS.with(|c| c.get())
192+}
193+
184194 /// `(directional, smooth/paeth, CfL)` chroma modes coded by an intra 8x8 leaf
185195 /// inside an inter frame -- see [`INTRA_IN_INTER8_UV_DIR_HITS`].
186196 pub(crate) fn intra_in_inter8_uv_hits() -> (usize, usize, usize) {
@@ -21819,18 +21829,16 @@ fn decode_inter_block8(
2181921829 };
2182021830 if angle_delta_y != 0 {
2182121831 INTRA_IN_INTER_ANGLE_DELTA_Y_HITS.with(|c| c.set(c.get() + 1));
21822- // lane-angleinter r1: the >=16x16 arm's lift is gated by a real
21823- // aomenc stream; this leaf's is NOT -- 80 attempts across two
21824- // sizes and five quantisers never produced an 8x8 intra leaf with
21825- // a nonzero delta (the leaf's own sibling refusals -- non-DC
21826- // chroma, the TX_4X4 split, sub-16 rect inter leaves -- fire
21827- // first). The prediction below would handle it; refusing keeps
21828- // the rule that no lift ships ungated. Note the claim is about
21829- // THIS DECODER's gate coverage, not about what an encoder writes.
21830- return Err(unsupported(
21831- "a nonzero angle delta on an 8x8 intra leaf in an inter frame (no gate reaches \
21832- this leaf with one; the >=16x16 arm decodes deltas)",
21833- ));
21832+ // lane-leaf8tx r1: `av1_use_angle_delta(BLOCK_8X8)` is true
21833+ // (`bsize >= BLOCK_8X8`), so this leaf codes `angle_delta_y` off
21834+ // `angle_delta_cdf[mode - V_PRED]` exactly as a key-frame block
21835+ // does (libaom `read_intra_angle_info` inside
21836+ // `read_intra_block_mode_info`, decodemv.c), and the delta feeds
21837+ // the directional predictor + the edge filter/upsample decision
21838+ // through the same `reconstruct` argument below. Counted
21839+ // separately from the >=16x16 arm so the gate cannot be satisfied
21840+ // by a bigger block.
21841+ INTRA_IN_INTER8_ANGLE_DELTA_Y_HITS.with(|c| c.set(c.get() + 1));
2183421842 }
2183521843 // lane-uv8 r1: the delta'd angle decides the intra edge filter, and a
2183621844 // directional luma mode is already legal on this leaf -- the arm
@@ -21974,11 +21982,15 @@ fn decode_inter_block8(
2197421982 }
2197521983 }
2197621984
21977- // lane-intrainter r1: the 8x8 leaf's own intra `tx_depth` can only
21978- // resolve to TX_4X4, whose 2x2 unit grid this leaf path has no
21979- // prediction loop for (the >=16x16 square path above does). Refuse by
21980- // name rather than mis-reconstruct.
21981- if read_block_tx_size(
21985+ // lane-leaf8tx r1: the 8x8 leaf's own intra `tx_depth` (libaom
21986+ // `read_tx_size` -> `read_selected_tx_size`, max depth 1 at
21987+ // BLOCK_8X8) resolves to TX_4X4, and `decode_block`
21988+ // (`decodeframe.c`) then codes one intra prediction + one
21989+ // coefficient set PER 4x4 transform unit in raster order, each unit
21990+ // predicting off the units reconstructed before it -- the same loop
21991+ // the >=16x16 intra-in-inter arm runs. Chroma stays one 4x4 unit
21992+ // (`av1_get_max_uv_txsize`).
21993+ let intra_leaves = read_block_tx_size(
2198221994 dec,
2198321995 cdfs,
2198421996 neighbours,
@@ -21988,28 +22000,81 @@ fn decode_inter_block8(
2198822000 false,
2198922001 skip,
2199022002 )?
21991- .1
21992- .is_some()
21993- {
21994- return Err(unsupported(
21995- "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 \
21996- transform units",
21997- ));
21998- }
22003+ .1;
22004+ split8 = intra_leaves.is_some();
2199922005 let reach = Reach::of(SIDE, px, py, y.width, y.height);
22006+ if let Some(leaves) = intra_leaves {
22007+ for &(row, col, tx_px, _) in &leaves {
22008+ let tu_mi = (leaf_mi.0 + row, leaf_mi.1 + col);
22009+ let (tu_px, tu_py) = (px + col * MI, py + row * MI);
22010+ // A transform unit inside a block is not a block at that
22011+ // position: top-right / bottom-left availability is the
22012+ // block's, narrowed by the unit's offset inside it.
22013+ let tu_reach = Reach::of_tu(SIDE, SIDE, col * MI, row * MI, tx_px, tx_px, reach);
22014+ let tu_grid = if skip {
22015+ y.reconstruct(
22016+ tu_px,
22017+ tu_py,
22018+ tx_px,
22019+ mode,
22020+ angle_delta_y,
22021+ tu_reach,
22022+ &vec![0i32; tx_px * tx_px],
22023+ None,
22024+ filter_intra,
22025+ smooth_neighbor,
22026+ );
22027+ vec![0i32; tx_px * tx_px]
22028+ } else {
22029+ // The unit is smaller than the block it sits in, so
22030+ // `txb_skip_ctx` is the neighbour-magnitude table, not
22031+ // the lone-TU 0 (`get_txb_ctx_general`).
22032+ let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI);
22033+ read_plane(
22034+ dec,
22035+ cdfs,
22036+ // Intra 4x4 luma: seven-type
22037+ // `EXT_TX_SET_DTT4_IDTX_1DDCT` unless reduced, whose
22038+ // CDF row is the intra dir (`fi_tx_row` inside
22039+ // `read_plane` maps a filter-intra block's).
22040+ txbset_for(tx_px, reduced_tx_set),
22041+ &default_scan(tx_px),
22042+ 0,
22043+ neighbours.around_mi(tu_mi, tx_px)[0],
22044+ mode,
22045+ mode,
22046+ angle_delta_y,
22047+ tu_reach,
22048+ y,
22049+ tu_px,
22050+ tu_py,
22051+ tx_px,
22052+ tx_px,
22053+ base_q_idx,
22054+ None,
22055+ filter_intra,
22056+ Some(tu_skip_ctx),
22057+ smooth_neighbor,
22058+ )?
22059+ };
22060+ neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid);
22061+ }
22062+ }
2200022063 if skip {
22001- y.reconstruct(
22002- px,
22003- py,
22004- SIDE,
22005- mode,
22006- angle_delta_y,
22007- reach,
22008- &vec![0i32; SIDE * SIDE],
22009- None,
22010- filter_intra,
22011- smooth_neighbor,
22012- );
22064+ if !split8 {
22065+ y.reconstruct(
22066+ px,
22067+ py,
22068+ SIDE,
22069+ mode,
22070+ angle_delta_y,
22071+ reach,
22072+ &vec![0i32; SIDE * SIDE],
22073+ None,
22074+ filter_intra,
22075+ smooth_neighbor,
22076+ );
22077+ }
2201322078 // CfL's AC contribution is the luma this leaf just reconstructed,
2201422079 // averaged over the 4x4 chroma block (`cfl_ac_q3`, spec 7.11.5).
2201522080 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE));
@@ -22042,7 +22107,13 @@ fn decode_inter_block8(
2204222107 v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
2204322108 } else {
2204422109 let around = neighbours.around_mi(leaf_mi, 8);
22045- luma_grid = read_plane(
22110+ luma_grid = if split8 {
22111+ // Already coded and reconstructed unit by unit above; the
22112+ // block-level grid only feeds the neighbour write-back,
22113+ // which the `saved_luma_ctx` restore below keeps per-TU.
22114+ vec![0i32; SIDE * SIDE]
22115+ } else {
22116+ read_plane(
2204622117 dec,
2204722118 cdfs,
2204822119 // lane-uv8 r3: an intra leaf inside an inter frame is
@@ -22071,7 +22142,8 @@ fn decode_inter_block8(
2207122142 filter_intra,
2207222143 None,
2207322144 smooth_neighbor,
22074- )?;
22145+ )?
22146+ };
2207522147 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE));
2207622148 u_grid = read_plane(
2207722149 dec,
crates/ec-av1/src/refusal_inventory.rsmodified+0 -2
@@ -29,7 +29,6 @@ const CAPABILITY_CLAIMS: &[&str] = &[
2929
3030 #[cfg(test)]
3131 const REFUSALS: &[&str] = &[
32- "a nonzero angle delta on an 8x8 intra leaf in an inter frame (no gate reaches this leaf with one; the >=16x16 arm decodes deltas)",
3332 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
3433 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",
3534 "an OBMC neighbour whose interp filter was never recorded (no switchable symbol for that block)",
@@ -69,7 +68,6 @@ const REFUSALS: &[&str] = &[
6968 // prediction + coefficients, gate
7069 // `a_real_aomenc_inter_sequence_with_a_split_transform_intra_block_decodes_pixel_exact`);
7170 // the 8x8 leaf's TX_4X4 2x2 grid is still refused here.
72- "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 transform units",
7371 "an inter frame with no key frame before it",
7472 "an inter SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B; this decoder's inter tile path codes a superblock as NONE, SPLIT, HORZ, VERT, HORZ_4 or VERT_4)",
7573 // lane-inter16ab r1 lifted the AB half (HORZ_A/HORZ_B/VERT_A/VERT_B at
crates/ec-av1/src/stream.rsmodified+241 -0
@@ -5962,6 +5962,247 @@ mod tests {
59625962 }
59635963
59645964
5965+ /// lane-leaf8tx r1: the two remaining refusals on an INTRA 8x8 leaf
5966+ /// inside an INTER frame -- its `tx_depth` splitting the luma transform
5967+ /// into four TX_4X4 units (`--enable-tx-size-search=1`), and a nonzero
5968+ /// luma `angle_delta_y` on it (`--enable-angle-delta=1`,
5969+ /// `av1_use_angle_delta(BLOCK_8X8)`). Both counters are per-attempt
5970+ /// deltas on an attempt that decoded to the end and is pixel-compared
5971+ /// (class [[counter-from-refused-stream]]); a decode error or a mismatch
5972+ /// is a FAILURE, never a SKIP.
5973+ #[test]
5974+ fn a_real_aomenc_inter_sequence_with_a_split_tx_8x8_intra_leaf_decodes_pixel_exact() {
5975+ tx_split_angle_in_inter8_gate(8);
5976+ }
5977+
5978+ /// The 10-bit arm (both of the user's films are `yuv420p10le`).
5979+ #[test]
5980+ fn a_real_aomenc_10bit_inter_sequence_with_a_split_tx_8x8_intra_leaf_decodes_pixel_exact() {
5981+ tx_split_angle_in_inter8_gate(10);
5982+ }
5983+
5984+ fn tx_split_angle_in_inter8_gate(bit_depth: u32) {
5985+ let name = format!("tx_split_angle_in_inter8_gate({bit_depth})");
5986+ if !have_ffmpeg() {
5987+ eprintln!("SKIP {name}: no ffmpeg");
5988+ return;
5989+ }
5990+ if !have_aomenc() {
5991+ eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display());
5992+ return;
5993+ }
5994+ let (width, height, frame_count) = (192usize, 128usize, 6usize);
5995+ let mut refusals = Vec::new();
5996+ let mut uncounted_exact = 0u32;
5997+ let mut totals = (0usize, 0usize);
5998+ for attempt in 0..30u32 {
5999+ let seed = 42 + attempt;
6000+ // Same zoom + hard-cut fractal source the sibling uv_mode gate
6001+ // uses (a cut is what makes aomenc code INTRA blocks inside an
6002+ // inter frame); `noise` carries an explicit seed (class
6003+ // [[seeded-fixture-not-reproducible]]).
6004+ let source = format!(
6005+ "mandelbrot=size={width}x{height}:start_scale={}:rate=25[a];\
6006+ mandelbrot=size={width}x{height}:start_scale={}:rate=25[b];\
6007+ [a][b]overlay=enable='gte(n,3)',noise=alls=12:allf=t+u:all_seed={seed}",
6008+ 5.0 - f64::from(attempt) * 0.06,
6009+ 0.9 + f64::from(attempt) * 0.11
6010+ );
6011+ let y4m = Command::new("ffmpeg")
6012+ .args([
6013+ "-v",
6014+ "error",
6015+ "-f",
6016+ "lavfi",
6017+ "-i",
6018+ &source,
6019+ "-pix_fmt",
6020+ if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" },
6021+ "-strict",
6022+ "-1",
6023+ "-t",
6024+ "0.24",
6025+ "-f",
6026+ "yuv4mpegpipe",
6027+ "-strict",
6028+ "-1",
6029+ "-",
6030+ ])
6031+ .stdin(Stdio::null())
6032+ .stdout(Stdio::piped())
6033+ .stderr(Stdio::piped())
6034+ .output()
6035+ .expect("ffmpeg failed to run");
6036+ assert!(
6037+ y4m.status.success(),
6038+ "ffmpeg fixture: {}",
6039+ String::from_utf8_lossy(&y4m.stderr)
6040+ );
6041+ let cq = format!("--cq-level={}", 12 + (attempt % 5) * 7);
6042+ let depth_args: &[&str] = if bit_depth == 10 {
6043+ &["-b", "10", "--input-bit-depth=10"]
6044+ } else {
6045+ &[]
6046+ };
6047+ // The y4m goes through a PID-keyed FILE, never aomenc's stdin
6048+ // (pipe deadlock, class [[gate-loader-slurps-whole-file]]).
6049+ let y4m_path = std::env::temp_dir().join(format!(
6050+ "ec-av1-leaf8tx-{}-{bit_depth}-{seed}.y4m",
6051+ std::process::id()
6052+ ));
6053+ std::fs::write(&y4m_path, &y4m.stdout).expect("writing the y4m fixture");
6054+ let child = Command::new(aomenc_path())
6055+ .args(depth_args)
6056+ .args([
6057+ "--codec=av1",
6058+ "--passes=1",
6059+ "--end-usage=q",
6060+ &cq,
6061+ "--cpu-used=0",
6062+ "--lag-in-frames=0",
6063+ "--auto-alt-ref=0",
6064+ "--kf-max-dist=9999",
6065+ "--kf-min-dist=9999",
6066+ "--threads=1",
6067+ "--row-mt=0",
6068+ "--tile-columns=0",
6069+ "--enable-order-hint=0",
6070+ "--enable-warped-motion=0",
6071+ "--enable-obmc=0",
6072+ "--enable-masked-comp=0",
6073+ "--enable-interintra-comp=0",
6074+ "--enable-dist-wtd-comp=0",
6075+ "--enable-diff-wtd-comp=0",
6076+ "--enable-onesided-comp=0",
6077+ "--enable-interintra-wedge=0",
6078+ "--enable-smooth-interintra=0",
6079+ "--enable-ab-partitions=0",
6080+ "--enable-1to4-partitions=0",
6081+ "--enable-cdef=0",
6082+ "--enable-restoration=0",
6083+ "--enable-palette=0",
6084+ "--enable-intrabc=0",
6085+ "--enable-ref-frame-mvs=0",
6086+ // Per-arm overrides LAST (aomenc keeps the last
6087+ // occurrence of a repeated --enable-* flag). Rect
6088+ // partitions stay off so the leaf's unrelated sub-16 rect
6089+ // inter refusal never fires.
6090+ "--enable-rect-partitions=0",
6091+ "--enable-tx-size-search=1",
6092+ "--enable-angle-delta=1",
6093+ "--enable-directional-intra=1",
6094+ "--min-partition-size=8",
6095+ "--max-partition-size=32",
6096+ "--obu",
6097+ "-o",
6098+ "-",
6099+ ])
6100+ .arg(&y4m_path)
6101+ .stdin(Stdio::null())
6102+ .stdout(Stdio::piped())
6103+ .stderr(Stdio::piped())
6104+ .spawn()
6105+ .expect("aomenc failed to start");
6106+ let out = child.wait_with_output().expect("aomenc failed to run");
6107+ let _ = std::fs::remove_file(&y4m_path);
6108+ assert!(
6109+ out.status.success(),
6110+ "aomenc refused the fixture: {}",
6111+ String::from_utf8_lossy(&out.stderr)
6112+ );
6113+ let stream = out.stdout;
6114+ let before = (
6115+ decode::intra_in_inter_split_tx_hits()[0],
6116+ decode::intra_in_inter8_angle_delta_y_hits(),
6117+ );
6118+ let frames = match decode_stream(&stream) {
6119+ Ok(frames) => frames,
6120+ Err(e) => {
6121+ let msg = e.to_string();
6122+ assert!(
6123+ msg.contains("unsupported"),
6124+ "{name} decode failed outright (seed {seed}): {msg}"
6125+ );
6126+ refusals.push(format!("seed {seed}: {msg}"));
6127+ continue;
6128+ }
6129+ };
6130+ let now = (
6131+ decode::intra_in_inter_split_tx_hits()[0],
6132+ decode::intra_in_inter8_angle_delta_y_hits(),
6133+ );
6134+ let fired = (now.0 - before.0, now.1 - before.1);
6135+ totals = (totals.0 + fired.0, totals.1 + fired.1);
6136+ // Both lifted capabilities must fire on the SAME pixel-compared
6137+ // attempt.
6138+ let counted = fired.0 > 0 && fired.1 > 0;
6139+ if !counted {
6140+ uncounted_exact += 1;
6141+ refusals.push(format!(
6142+ "seed {seed}: decoded and pixel-compared, but split-tx {} / angle-delta {} \
6143+ 8x8 intra-in-inter leaves",
6144+ fired.0, fired.1
6145+ ));
6146+ }
6147+ let ffmpeg_frames = if bit_depth == 10 {
6148+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
6149+ } else {
6150+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
6151+ };
6152+ assert_eq!(frames.len(), frame_count);
6153+ eprintln!(
6154+ "{name} seed={seed} {cq}: 8x8 intra-in-inter leaves with tx_depth=1 {}, with a \
6155+ nonzero angle_delta_y {}",
6156+ fired.0, fired.1
6157+ );
6158+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
6159+ for (plane, (g, w)) in [
6160+ ("Y", (&got.y, &want.y)),
6161+ ("U", (&got.u, &want.u)),
6162+ ("V", (&got.v, &want.v)),
6163+ ] {
6164+ let stride = if plane == "Y" { width } else { width / 2 };
6165+ if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) {
6166+ eprintln!(
6167+ "{name} seed={seed}: frame {i} {plane} first diff at ({}, {}) got {} \
6168+ want {} ({} samples differ)",
6169+ at % stride,
6170+ at / stride,
6171+ g[at],
6172+ w[at],
6173+ g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(),
6174+ );
6175+ }
6176+ }
6177+ }
6178+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
6179+ assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})");
6180+ assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})");
6181+ assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})");
6182+ }
6183+ if counted {
6184+ gate_buckets(
6185+ &name,
6186+ 1,
6187+ uncounted_exact,
6188+ refusals.len() - uncounted_exact as usize,
6189+ );
6190+ return;
6191+ }
6192+ }
6193+ gate_buckets(
6194+ &name,
6195+ 0,
6196+ uncounted_exact,
6197+ refusals.len() - uncounted_exact as usize,
6198+ );
6199+ panic!(
6200+ "{name} never observed BOTH a tx_depth split and a nonzero angle delta on an 8x8 \
6201+ intra leaf in an inter frame (totals split/angle {totals:?}):\n{}",
6202+ refusals.join("\n")
6203+ );
6204+ }
6205+
59656206 /// lane-chroma r2 stage 1: a real aomenc key frame with
59666207 /// `--enable-smooth-intra=1` (opposite of every sibling recipe's `=0`)
59676208 /// and `--enable-paeth-intra=0` -- paeth chroma stays off so the still-