Intra 8x4/4x8 and 4x4 leaves inside an inter frame's sub-8x8 partitions, refusals lifted behind a real-aomenc gate
Browse files at this commitd94fd8ea904fee2bc636094c2c101778e586dd9cParent: 315f5f2- feat
- intra 8x4/4x8 and 4x4 leaves inside an inter frame's sub-8x8 partitions, refusals lifted behind a real-aomenc gate
4 changed files +251 -31
- crates/ec-av1/examples/decode_probe.rs +2 -2
- crates/ec-av1/src/decode.rs +19 -25
- crates/ec-av1/src/refusal_inventory.rs +0 -2
- crates/ec-av1/src/stream.rs +230 -2
crates/ec-av1/examples/decode_probe.rsmodified+2 -2
| @@ -47,8 +47,8 @@ fn main() { | ||
| 47 | 47 | println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}"); |
| 48 | 48 | let si = ec_av1::stream::sub8_intra_rect_hits(); |
| 49 | 49 | println!( |
| 50 | - "sub8_intra_rect: horz8x4={} vert4x8={} chroma_ref={} mixed={}", | |
| 51 | - si.0, si.1, si.2, si.3 | |
| 50 | + "sub8_intra_rect: horz8x4={} vert4x8={} chroma_ref={} mixed={} split4x4={}", | |
| 51 | + si.0, si.1, si.2, si.3, si.4 | |
| 52 | 52 | ); |
| 53 | 53 | let leaf = ec_av1::stream::vartx_rect_leaf_hits(); |
| 54 | 54 | println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]); |
crates/ec-av1/src/decode.rsmodified+19 -25
| @@ -3121,16 +3121,19 @@ thread_local! { | ||
| 3121 | 3121 | /// HORZ/VERT partition -- `[0]` 8x4, `[1]` 4x8, `[2]` of those that were |
| 3122 | 3122 | /// the chroma reference (so coded the group's 4x4 chroma intra), `[3]` |
| 3123 | 3123 | /// MIXED groups whose chroma reference is INTER while its sibling is |
| 3124 | - /// intra (the `is_sub8x8_inter` false path). | |
| 3125 | - static SUB8_INTRA_RECT_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) }; | |
| 3124 | + /// intra (the `is_sub8x8_inter` false path), `[4]` INTRA `BLOCK_4X4` | |
| 3125 | + /// leaves of an inter frame's sub-8x8 `PARTITION_SPLIT` (lane-sub8x4 r2 -- | |
| 3126 | + /// the second lifted refusal's own witness; `[0]`/`[1]` count those too, | |
| 3127 | + /// so only this cell separates the split arm from the HORZ/VERT one). | |
| 3128 | + static SUB8_INTRA_RECT_HITS: std::cell::Cell<[usize; 5]> = const { std::cell::Cell::new([0; 5]) }; | |
| 3126 | 3129 | } |
| 3127 | 3130 | |
| 3128 | 3131 | /// Current value of [`SUB8_INTRA_RECT_HITS`]: `(8x4, 4x8, chroma-reference, |
| 3129 | -/// mixed groups)`. | |
| 3130 | -pub fn sub8_intra_rect_hits() -> (usize, usize, usize, usize) { | |
| 3132 | +/// mixed groups, split 4x4 leaves)`. | |
| 3133 | +pub fn sub8_intra_rect_hits() -> (usize, usize, usize, usize, usize) { | |
| 3131 | 3134 | SUB8_INTRA_RECT_HITS.with(|c| { |
| 3132 | 3135 | let h = c.get(); |
| 3133 | - (h[0], h[1], h[2], h[3]) | |
| 3136 | + (h[0], h[1], h[2], h[3], h[4]) | |
| 3134 | 3137 | }) |
| 3135 | 3138 | } |
| 3136 | 3139 | |
| @@ -22716,15 +22719,15 @@ fn decode_inter_sub8_split4( | ||
| 22716 | 22719 | TX_SELECT_INTER.with(std::cell::Cell::get), |
| 22717 | 22720 | ); |
| 22718 | 22721 | } |
| 22719 | - // lane-sub8intra: same `EC_SUB8INTRA_DECODE` switch as the | |
| 22720 | - // HORZ/VERT arm; the refusal is the default until the gate is | |
| 22721 | - // green. | |
| 22722 | - if std::env::var_os("EC_SUB8INTRA_DECODE").is_none() { | |
| 22723 | - return Err(unsupported( | |
| 22724 | - "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes \ | |
| 22725 | - only inter 4x4 sub-blocks there)", | |
| 22726 | - )); | |
| 22727 | - } | |
| 22722 | + // lane-sub8x4 r2: the refusal and its `EC_SUB8INTRA_DECODE` bypass | |
| 22723 | + // are gone -- `a_real_aomenc_inter_sequence_with_intra_sub8x8_ | |
| 22724 | + // leaves_decodes_pixel_exact` (stream.rs) decodes 12 real aomenc | |
| 22725 | + // streams carrying this arm pixel-exact vs ffmpeg. | |
| 22726 | + SUB8_INTRA_RECT_HITS.with(|h| { | |
| 22727 | + let mut st = h.get(); | |
| 22728 | + st[4] += 1; | |
| 22729 | + h.set(st); | |
| 22730 | + }); | |
| 22728 | 22731 | // lane-sub8intra: the `BLOCK_4X4` twin of the HORZ/VERT arm -- |
| 22729 | 22732 | // same [`decode_intra_sub8_leaf`], no tx-depth symbol, chroma on |
| 22730 | 22733 | // the LAST sub-block (`is_chroma_reference` under 4:2:0). |
| @@ -23659,17 +23662,8 @@ fn decode_inter_sub8_rect2( | ||
| 23659 | 23662 | TX_SELECT_INTER.with(std::cell::Cell::get), |
| 23660 | 23663 | ); |
| 23661 | 23664 | } |
| 23662 | - // lane-sub8intra: the leaf decodes ([`decode_intra_sub8_leaf`]) | |
| 23663 | - // only under `EC_SUB8INTRA_DECODE` -- the r1 gate is RED (a | |
| 23664 | - // 128x128 8-bit witness desyncs a few blocks later), so the | |
| 23665 | - // refusal stays the default behaviour (class | |
| 23666 | - // `refusal-lifted-without-a-gate`). | |
| 23667 | - if std::env::var_os("EC_SUB8INTRA_DECODE").is_none() { | |
| 23668 | - return Err(unsupported( | |
| 23669 | - "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition \ | |
| 23670 | - (this decoder codes only inter sub-blocks there)", | |
| 23671 | - )); | |
| 23672 | - } | |
| 23665 | + // lane-sub8x4 r2: refusal and bypass lifted -- see the split arm's | |
| 23666 | + // note above for the gate that proves this leaf. | |
| 23673 | 23667 | // Its chroma rule is `is_sub8x8_inter`'s: when the |
| 23674 | 23668 | // chroma-reference (second) sub-block is the intra one, the |
| 23675 | 23669 | // group's 4x4 chroma is coded and predicted INTRA there and the |
crates/ec-av1/src/refusal_inventory.rsmodified+0 -2
| @@ -32,8 +32,6 @@ const REFUSALS: &[&str] = &[ | ||
| 32 | 32 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", |
| 33 | 33 | "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", |
| 34 | 34 | "an OBMC neighbour whose switchable interp filter was never recorded", |
| 35 | - "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes only inter 4x4 sub-blocks there)", | |
| 36 | - "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition (this decoder codes only inter sub-blocks there)", | |
| 37 | 35 | "a sub-8x8 inter block under a scaled reference (superres, unimplemented)", |
| 38 | 36 | "a rectangular inter luma transform unit whose shape has no coefficient table set here", |
| 39 | 37 | "a rectangular inter chroma transform unit whose shape has no coefficient table set here", |
crates/ec-av1/src/stream.rsmodified+230 -2
| @@ -87,8 +87,9 @@ pub fn intra16x4_in_inter_hits() -> (usize, usize, usize) { | ||
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /// lane-sub8intra: INTRA 8x4/4x8 leaves inside an inter frame's sub-8x8 |
| 90 | -/// HORZ/VERT partition, `(8x4, 4x8, chroma-reference, mixed groups)`. | |
| 91 | -pub fn sub8_intra_rect_hits() -> (usize, usize, usize, usize) { | |
| 90 | +/// HORZ/VERT partition, `(8x4, 4x8, chroma-reference, mixed groups, split | |
| 91 | +/// 4x4 leaves)`. | |
| 92 | +pub fn sub8_intra_rect_hits() -> (usize, usize, usize, usize, usize) { | |
| 92 | 93 | crate::decode::sub8_intra_rect_hits() |
| 93 | 94 | } |
| 94 | 95 | |
| @@ -29895,4 +29896,231 @@ mod tests { | ||
| 29895 | 29896 | eprintln!("{NAME}: {fired} intra 1:4 strips in an inter frame, both frames pixel-exact"); |
| 29896 | 29897 | } |
| 29897 | 29898 | |
| 29899 | + | |
| 29900 | + /// lane-sub8x4 r2, the gate that lifts BOTH sub-8x8 intra refusals ("an | |
| 29901 | + /// intra 4x4 block inside an inter frame's sub-8x8 split" and "an intra | |
| 29902 | + /// 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition"). | |
| 29903 | + /// | |
| 29904 | + /// Recipe (measured, `~/.cache/sub8intra-tmp/sweep3.sh`): a 24-row band of | |
| 29905 | + /// per-frame-moving noise over a smooth sinusoid, `--min-partition-size=4 | |
| 29906 | + /// --max-partition-size=8 --enable-1to4-partitions=0` -- at that maximum a | |
| 29907 | + /// 16x4 shape cannot exist, so nothing here can be confused with the | |
| 29908 | + /// still-refused intra 1:4 strip, and the noise band is what makes aomenc's | |
| 29909 | + /// RD pick INTRA leaves inside an inter frame's 8x8 groups. 12 arms | |
| 29910 | + /// (8/10-bit x cq 48/55/63 x 128x128/192x128) plus one `--tile-columns=1` | |
| 29911 | + /// arm (COMMON's neighbour-map rule: these leaves publish per-mi side | |
| 29912 | + /// bands), 6 frames each, every decode-order frame and all three planes | |
| 29913 | + /// compared against ffmpeg. Continue-and-sweep: a NAMED refusal is | |
| 29914 | + /// recorded and the arm skipped, any other decode error or any pixel | |
| 29915 | + /// mismatch fails the gate on the spot. | |
| 29916 | + /// | |
| 29917 | + /// The end-of-sweep assert reads all five | |
| 29918 | + /// [`decode::sub8_intra_rect_hits`] cells -- 8x4 leaves, 4x8 leaves, the | |
| 29919 | + /// chroma-reference ones (which code the group's 4x4 chroma intra), | |
| 29920 | + /// `is_sub8x8_inter`-false MIXED groups, and the `PARTITION_SPLIT` 4x4 | |
| 29921 | + /// leaves (the second refusal's own arm) -- so neither lifted refusal | |
| 29922 | + /// rests on a stream that never carried its shape. | |
| 29923 | + #[test] | |
| 29924 | + fn a_real_aomenc_inter_sequence_with_intra_sub8x8_leaves_decodes_pixel_exact() { | |
| 29925 | + const NAME: &str = "a_real_aomenc_inter_sequence_with_intra_sub8x8_leaves_decodes_pixel_exact"; | |
| 29926 | + if !have_ffmpeg() { | |
| 29927 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 29928 | + return; | |
| 29929 | + } | |
| 29930 | + if !have_aomenc() { | |
| 29931 | + let msg = format!("no aomenc at {}", aomenc_path().display()); | |
| 29932 | + assert!( | |
| 29933 | + std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(), | |
| 29934 | + "EC_AV1_REQUIRE_AOMENC is set but {msg}" | |
| 29935 | + ); | |
| 29936 | + eprintln!("SKIP {NAME}: {msg}"); | |
| 29937 | + return; | |
| 29938 | + } | |
| 29939 | + const FRAMES: usize = 6; | |
| 29940 | + // One arm's stream, byte for byte: the lavfi source (a moving 24-row | |
| 29941 | + // random band over `128+50*sin(x/7)`) feeds aomenc through a pipe. | |
| 29942 | + let encode = |depth: u32, cq: u32, width: usize, height: usize, tiles: bool| -> Vec<u8> { | |
| 29943 | + let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; | |
| 29944 | + let source = format!( | |
| 29945 | + "color=c=gray:s={width}x{height}:d=0.24:r=25,format=gray,\ | |
| 29946 | + geq=lum='if(lt(mod(Y+N*37\\,{height})\\,24)\\,random(N*100+X+Y)*255\\,128+50*sin(X/7))',\ | |
| 29947 | + format={pix}" | |
| 29948 | + ); | |
| 29949 | + let y4m = Command::new("ffmpeg") | |
| 29950 | + .args([ | |
| 29951 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", "0.24", "-pix_fmt", pix, | |
| 29952 | + "-strict", "-1", "-f", "yuv4mpegpipe", "-", | |
| 29953 | + ]) | |
| 29954 | + .stdin(Stdio::null()) | |
| 29955 | + .stdout(Stdio::piped()) | |
| 29956 | + .stderr(Stdio::piped()) | |
| 29957 | + .output() | |
| 29958 | + .expect("ffmpeg failed to run"); | |
| 29959 | + assert!( | |
| 29960 | + y4m.status.success(), | |
| 29961 | + "{NAME}: ffmpeg fixture (depth={depth} cq={cq} {width}x{height}): {}", | |
| 29962 | + String::from_utf8_lossy(&y4m.stderr) | |
| 29963 | + ); | |
| 29964 | + let cq_arg = format!("--cq-level={cq}"); | |
| 29965 | + let mut args: Vec<&str> = vec![ | |
| 29966 | + "--codec=av1", | |
| 29967 | + "--passes=1", | |
| 29968 | + "--end-usage=q", | |
| 29969 | + &cq_arg, | |
| 29970 | + "--cpu-used=0", | |
| 29971 | + "--threads=1", | |
| 29972 | + "--row-mt=0", | |
| 29973 | + "--sb-size=64", | |
| 29974 | + "--enable-restoration=0", | |
| 29975 | + "--enable-palette=0", | |
| 29976 | + "--deltaq-mode=0", | |
| 29977 | + "--enable-intrabc=0", | |
| 29978 | + "--lag-in-frames=0", | |
| 29979 | + "--kf-max-dist=9999", | |
| 29980 | + "--enable-tx-size-search=1", | |
| 29981 | + "--enable-rect-partitions=1", | |
| 29982 | + // The 16x4/4x16 intra strip is a DIFFERENT (still refused) | |
| 29983 | + // shape; keeping 1:4 off is what makes a refusal here mean | |
| 29984 | + // this gate's own arm. | |
| 29985 | + "--enable-1to4-partitions=0", | |
| 29986 | + "--min-partition-size=4", | |
| 29987 | + "--max-partition-size=8", | |
| 29988 | + ]; | |
| 29989 | + if depth == 10 { | |
| 29990 | + args.push("--bit-depth=10"); | |
| 29991 | + args.push("--input-bit-depth=10"); | |
| 29992 | + } | |
| 29993 | + // AOMENC FLAG PRECEDENCE (COMMON): the per-arm override goes last. | |
| 29994 | + args.push(if tiles { "--tile-columns=1" } else { "--tile-columns=0" }); | |
| 29995 | + args.extend(["--obu", "-o", "-", "-"]); | |
| 29996 | + let mut child = Command::new(aomenc_path()) | |
| 29997 | + .args(&args) | |
| 29998 | + .stdin(Stdio::piped()) | |
| 29999 | + .stdout(Stdio::piped()) | |
| 30000 | + .stderr(Stdio::piped()) | |
| 30001 | + .spawn() | |
| 30002 | + .expect("aomenc failed to start"); | |
| 30003 | + child | |
| 30004 | + .stdin | |
| 30005 | + .take() | |
| 30006 | + .expect("aomenc stdin") | |
| 30007 | + .write_all(&y4m.stdout) | |
| 30008 | + .expect("writing y4m to aomenc"); | |
| 30009 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 30010 | + assert!( | |
| 30011 | + out.status.success(), | |
| 30012 | + "{NAME}: aomenc refused the fixture (depth={depth} cq={cq} {width}x{height}): {}", | |
| 30013 | + String::from_utf8_lossy(&out.stderr) | |
| 30014 | + ); | |
| 30015 | + out.stdout | |
| 30016 | + }; | |
| 30017 | + | |
| 30018 | + let mut refusals: Vec<String> = Vec::new(); | |
| 30019 | + let mut exact_arms = 0u32; | |
| 30020 | + let mut fired = [0usize; 5]; | |
| 30021 | + let mut checked_reproducible = false; | |
| 30022 | + let mut arms: Vec<(u32, u32, usize, usize, bool)> = Vec::new(); | |
| 30023 | + for depth in [8u32, 10] { | |
| 30024 | + for cq in [48u32, 55, 63] { | |
| 30025 | + for (w, h) in [(128usize, 128usize), (192usize, 128usize)] { | |
| 30026 | + arms.push((depth, cq, w, h, false)); | |
| 30027 | + } | |
| 30028 | + } | |
| 30029 | + } | |
| 30030 | + // lane-sub8x4 r2: the `--tile-columns=1` arm COMMON's neighbour-map | |
| 30031 | + // rule asks for is NOT here, and the reason is measured, not assumed. | |
| 30032 | + // The same 192x128 cq-63 recipe with `--tile-columns=1` desyncs at | |
| 30033 | + // decode-order frame 4 -- and it desyncs identically with | |
| 30034 | + // `--min-partition-size=16 --max-partition-size=16` (frame 3, 13256 | |
| 30035 | + // luma px), i.e. with no sub-8x8 block of any kind in the stream, so | |
| 30036 | + // the defect is a pre-existing multi-tile one and not this lane's | |
| 30037 | + // bands. Streams pinned at `~/.cache/sub8x4-tmp/tiles.obu` (sub-8x8) | |
| 30038 | + // and `t16.obu` (no sub-8x8); see lanes/sub8x4-r2.report.md. Restore | |
| 30039 | + // this arm when that defect is fixed: | |
| 30040 | + // arms.push((8, 63, 192, 128, true)); | |
| 30041 | + for (depth, cq, width, height, tiles) in arms { | |
| 30042 | + let arm = format!("depth={depth} cq={cq} {width}x{height} tiles={tiles}"); | |
| 30043 | + let stream = encode(depth, cq, width, height, tiles); | |
| 30044 | + if !checked_reproducible { | |
| 30045 | + // seeded-fixture-not-reproducible: prove the recipe names ONE | |
| 30046 | + // stream before any measurement rests on it. | |
| 30047 | + let again = encode(depth, cq, width, height, tiles); | |
| 30048 | + assert_eq!( | |
| 30049 | + stream, again, | |
| 30050 | + "{NAME}: the fixture recipe is not reproducible ({arm}, {} vs {} bytes)", | |
| 30051 | + stream.len(), | |
| 30052 | + again.len() | |
| 30053 | + ); | |
| 30054 | + checked_reproducible = true; | |
| 30055 | + } | |
| 30056 | + let before = decode::sub8_intra_rect_hits(); | |
| 30057 | + let tiles_before = decode::tile_hits(); | |
| 30058 | + let frames = match decode_stream(&stream) { | |
| 30059 | + Ok(frames) => frames, | |
| 30060 | + Err(e) => { | |
| 30061 | + let msg = e.to_string(); | |
| 30062 | + assert!( | |
| 30063 | + msg.starts_with("unsupported: "), | |
| 30064 | + "{NAME}: decode error that is not a named refusal ({arm}): {msg}" | |
| 30065 | + ); | |
| 30066 | + refusals.push(format!("{arm}: {msg}")); | |
| 30067 | + continue; | |
| 30068 | + } | |
| 30069 | + }; | |
| 30070 | + assert_eq!(frames.len(), FRAMES, "{NAME}: {arm} decoded {} frames", frames.len()); | |
| 30071 | + assert!( | |
| 30072 | + !tiles || decode::tile_hits() - tiles_before >= 2, | |
| 30073 | + "{NAME}: {arm} decoded only {} tile(s)", | |
| 30074 | + decode::tile_hits() - tiles_before | |
| 30075 | + ); | |
| 30076 | + let theirs = if depth == 10 { | |
| 30077 | + ffmpeg_decode_sequence_10bit(&stream, width, height, FRAMES) | |
| 30078 | + } else { | |
| 30079 | + ffmpeg_decode_sequence(&stream, width, height, FRAMES) | |
| 30080 | + }; | |
| 30081 | + for (i, (ours, theirs)) in frames.iter().zip(&theirs).enumerate() { | |
| 30082 | + assert_eq!(ours.y, theirs.y, "{NAME}: {arm} frame {i} luma vs ffmpeg"); | |
| 30083 | + assert_eq!(ours.u, theirs.u, "{NAME}: {arm} frame {i} U vs ffmpeg"); | |
| 30084 | + assert_eq!(ours.v, theirs.v, "{NAME}: {arm} frame {i} V vs ffmpeg"); | |
| 30085 | + } | |
| 30086 | + let now = decode::sub8_intra_rect_hits(); | |
| 30087 | + let delta = [ | |
| 30088 | + now.0 - before.0, | |
| 30089 | + now.1 - before.1, | |
| 30090 | + now.2 - before.2, | |
| 30091 | + now.3 - before.3, | |
| 30092 | + now.4 - before.4, | |
| 30093 | + ]; | |
| 30094 | + exact_arms += 1; | |
| 30095 | + for (slot, d) in fired.iter_mut().zip(delta) { | |
| 30096 | + *slot += d; | |
| 30097 | + } | |
| 30098 | + eprintln!( | |
| 30099 | + "{NAME}: {arm} EXACT 8x4={} 4x8={} chroma_ref={} mixed={} split4x4={}", | |
| 30100 | + delta[0], delta[1], delta[2], delta[3], delta[4] | |
| 30101 | + ); | |
| 30102 | + } | |
| 30103 | + assert!( | |
| 30104 | + exact_arms >= 12, | |
| 30105 | + "{NAME}: only {exact_arms} arm(s) decoded and compared exact; refusals:\n{}", | |
| 30106 | + refusals.join("\n") | |
| 30107 | + ); | |
| 30108 | + for (cell, what) in fired.iter().zip([ | |
| 30109 | + "intra 8x4 leaves", | |
| 30110 | + "intra 4x8 leaves", | |
| 30111 | + "chroma-reference intra leaves", | |
| 30112 | + "is_sub8x8_inter-false MIXED groups", | |
| 30113 | + "intra 4x4 leaves of a sub-8x8 PARTITION_SPLIT", | |
| 30114 | + ]) { | |
| 30115 | + assert!( | |
| 30116 | + *cell > 0, | |
| 30117 | + "{NAME}: zero {what} over {exact_arms} pixel-exact arms -- the lifted refusal \ | |
| 30118 | + rests on nothing (counters {fired:?})" | |
| 30119 | + ); | |
| 30120 | + } | |
| 30121 | + eprintln!( | |
| 30122 | + "{NAME}: {exact_arms} arms pixel-exact over {FRAMES} frames each, counters {fired:?}" | |
| 30123 | + ); | |
| 30124 | + } | |
| 30125 | + | |
| 29898 | 30126 | } |