Decode the 128 root's gathered frame-edge HORZ/VERT arm on the inter path
Browse files at this commit83a30cac0134090da6ddc153ac23b8fe13461782Parent: 386c0a8- feat
- decode the 128 root's gathered frame-edge HORZ/VERT arm on the inter path
4 changed files +219 -3
- crates/ec-av1/examples/decode_probe.rs +5 -0
- crates/ec-av1/src/decode.rs +34 -2
- crates/ec-av1/src/refusal_inventory.rs +2 -1
- crates/ec-av1/src/stream.rs +178 -0
crates/ec-av1/examples/decode_probe.rsmodified+5 -0
| @@ -37,6 +37,11 @@ fn main() { | |||
| 37 | println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); | 37 | println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); |
| 38 | let leaf = ec_av1::stream::vartx_rect_leaf_hits(); | 38 | let leaf = ec_av1::stream::vartx_rect_leaf_hits(); |
| 39 | println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]); | 39 | println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]); |
| 40 | + let sb = ec_av1::stream::sb128_rect_counters(); | ||
| 41 | + println!( | ||
| 42 | + "sb128_rect: edge_horz={} edge_vert={} inter_128x64={} inter_64x128={}", | ||
| 43 | + sb.0, sb.1, sb.2, sb.3 | ||
| 44 | + ); | ||
| 40 | let ir = ec_av1::stream::inter_rect_counters(); | 45 | let ir = ec_av1::stream::inter_rect_counters(); |
| 41 | println!( | 46 | println!( |
| 42 | "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}", | 47 | "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}", |
crates/ec-av1/src/decode.rsmodified+34 -2
| @@ -3946,6 +3946,18 @@ impl Neighbours { | |||
| 3946 | /// `cols`/`rows` are in [`SUB`] units; `mi_cols`/`mi_rows` are the frame's | 3946 | /// `cols`/`rows` are in [`SUB`] units; `mi_cols`/`mi_rows` are the frame's |
| 3947 | /// true (unpadded) size in 4x4 mode-info units. | 3947 | /// true (unpadded) size in 4x4 mode-info units. |
| 3948 | fn new(cols: usize, rows: usize, mi_cols: usize, mi_rows: usize) -> Self { | 3948 | fn new(cols: usize, rows: usize, mi_cols: usize, mi_rows: usize) -> Self { |
| 3949 | + // lane-sb128c r7: a 128x64 block at the bottom frame edge records its | ||
| 3950 | + // neighbour state over the whole 64-row extent, past the frame's last | ||
| 3951 | + // mi row (mi_rows 198, block rows 192..208). libaom's own context | ||
| 3952 | + // buffers are superblock-aligned for exactly that reason | ||
| 3953 | + // (`av1_alloc_context_buffers` rounds to `MAX_MIB_SIZE`), so pad the | ||
| 3954 | + // side arrays to a superblock multiple and leave those cells unread -- | ||
| 3955 | + // every availability check uses the true `mi_rows`/`mi_cols` below. | ||
| 3956 | + let sb_sub = (sb_mi_cur() as usize) / (SUB / MI); | ||
| 3957 | + let (cols, rows) = ( | ||
| 3958 | + cols.next_multiple_of(sb_sub), | ||
| 3959 | + rows.next_multiple_of(sb_sub), | ||
| 3960 | + ); | ||
| 3949 | Self { | 3961 | Self { |
| 3950 | above: vec![[Neighbour::default(); 3]; cols * (SUB / MI)], | 3962 | above: vec![[Neighbour::default(); 3]; cols * (SUB / MI)], |
| 3951 | left: vec![[Neighbour::default(); 3]; rows * (SUB / MI)], | 3963 | left: vec![[Neighbour::default(); 3]; rows * (SUB / MI)], |
| @@ -5015,7 +5027,14 @@ impl Neighbours { | |||
| 5015 | round_up_even(self.mi_cols), | 5027 | round_up_even(self.mi_cols), |
| 5016 | ]; | 5028 | ]; |
| 5017 | for cell in 0..h_mi { | 5029 | for cell in 0..h_mi { |
| 5018 | - self.left[mi_r + cell] = std::array::from_fn(|plane| { | 5030 | + // lane-sb128c r7: a 128x64 at the bottom frame edge names mi rows |
| 5031 | + // past the padded side arrays (mi_rows 198, block rows 192..208); | ||
| 5032 | + // libaom's own arrays are superblock-sized, so those cells simply | ||
| 5033 | + // have no reader. Same guard the `left_side_mi` loop above uses. | ||
| 5034 | + let Some(left_slot) = self.left.get_mut(mi_r + cell) else { | ||
| 5035 | + break; | ||
| 5036 | + }; | ||
| 5037 | + *left_slot = std::array::from_fn(|plane| { | ||
| 5019 | if cell < h_mi.min(bound_h[plane].saturating_sub(mi_r)) { | 5038 | if cell < h_mi.min(bound_h[plane].saturating_sub(mi_r)) { |
| 5020 | states[plane] | 5039 | states[plane] |
| 5021 | } else { | 5040 | } else { |
| @@ -5024,7 +5043,10 @@ impl Neighbours { | |||
| 5024 | }); | 5043 | }); |
| 5025 | } | 5044 | } |
| 5026 | for cell in 0..w_mi { | 5045 | for cell in 0..w_mi { |
| 5027 | - self.above[mi_c + cell] = std::array::from_fn(|plane| { | 5046 | + let Some(above_slot) = self.above.get_mut(mi_c + cell) else { |
| 5047 | + break; | ||
| 5048 | + }; | ||
| 5049 | + *above_slot = std::array::from_fn(|plane| { | ||
| 5028 | if cell < w_mi.min(bound_w[plane].saturating_sub(mi_c)) { | 5050 | if cell < w_mi.min(bound_w[plane].saturating_sub(mi_c)) { |
| 5029 | states[plane] | 5051 | states[plane] |
| 5030 | } else { | 5052 | } else { |
| @@ -13675,6 +13697,16 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 13675 | mi_cols, | 13697 | mi_cols, |
| 13676 | mi_rows, | 13698 | mi_rows, |
| 13677 | )?; | 13699 | )?; |
| 13700 | + if matches!(part128, PARTITION_HORZ | PARTITION_VERT) { | ||
| 13701 | + // lane-sb128c r7: the INTER path decodes these (two 128x64 | ||
| 13702 | + // / two 64x128 blocks, the film's own bottom-edge shape); | ||
| 13703 | + // the key path's `decode_block` is square-only, so an | ||
| 13704 | + // intra 128x64 would silently decode as four 64x64 | ||
| 13705 | + // quadrants. Refuse by name instead of corrupting. | ||
| 13706 | + return Err(unsupported( | ||
| 13707 | + "a 128x128 superblock HORZ/VERT partition on an intra frame (the inter path decodes it; the intra one is square-block only)", | ||
| 13708 | + )); | ||
| 13709 | + } | ||
| 13678 | if part128 == PARTITION_NONE { | 13710 | if part128 == PARTITION_NONE { |
| 13679 | // One 128x128 intra block: four TX_64X64 luma units and a | 13711 | // One 128x128 intra block: four TX_64X64 luma units and a |
| 13680 | // single 64x64 chroma unit per plane (`av1_get_max_uv_txsize` | 13712 | // single 64x64 chroma unit per plane (`av1_get_max_uv_txsize` |
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
| @@ -43,7 +43,8 @@ const REFUSALS: &[&str] = &[ | |||
| 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 | "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", | 45 | "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", |
| 46 | - "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)", | 46 | + "a 128x128 superblock AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B at the 128 root)", |
| 47 | + "a 128x128 superblock HORZ/VERT partition on an intra frame (the inter path decodes it; the intra one is square-block only)", | ||
| 47 | "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", | 48 | "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", |
| 48 | "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)", | 49 | "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)", |
| 49 | "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", | 50 | "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", |
crates/ec-av1/src/stream.rsmodified+178 -0
| @@ -81,6 +81,17 @@ pub fn vartx_rect_leaf_hits() -> [usize; 2] { | |||
| 81 | crate::decode::vartx_rect_leaf_hits() | 81 | crate::decode::vartx_rect_leaf_hits() |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | +/// lane-sb128c r7: the 128 root's rect arms -- (gathered edge HORZ, gathered | ||
| 85 | +/// edge VERT, inter 128x64 blocks, inter 64x128 blocks). | ||
| 86 | +pub fn sb128_rect_counters() -> (usize, usize, usize, usize) { | ||
| 87 | + ( | ||
| 88 | + crate::decode::part128_edge_horz_hits(), | ||
| 89 | + crate::decode::part128_edge_vert_hits(), | ||
| 90 | + crate::decode::inter_sb128_horz_hits(), | ||
| 91 | + crate::decode::inter_sb128_vert_hits(), | ||
| 92 | + ) | ||
| 93 | +} | ||
| 94 | + | ||
| 84 | pub fn rect4_32_counters() -> (usize, usize, usize) { | 95 | pub fn rect4_32_counters() -> (usize, usize, usize) { |
| 85 | ( | 96 | ( |
| 86 | crate::decode::rect4_32_horz_hits(), | 97 | crate::decode::rect4_32_horz_hits(), |
| @@ -18953,6 +18964,173 @@ mod tests { | |||
| 18953 | ); | 18964 | ); |
| 18954 | } | 18965 | } |
| 18955 | 18966 | ||
| 18967 | + /// lane-sb128c r7 GATE: the 128 root's GATHERED bottom/right-edge arm -- | ||
| 18968 | + /// the only 128-partition shape the user's 1080p AV1 film reaches | ||
| 18969 | + /// (`mi_rows = 270`, so every bottom 128 row has `has_rows128 == false`, | ||
| 18970 | + /// one gathered bit, and the film codes `PARTITION_HORZ`: a 128x64 block | ||
| 18971 | + /// whose bottom half is outside the frame and never decoded). Frame sizes | ||
| 18972 | + /// here are chosen so the LAST superblock row (or column, for the VERT | ||
| 18973 | + /// twin at 192x256) is partial, which is what forces the gathered symbol. | ||
| 18974 | + /// Both the key frame and the inter frames of each stream carry the arm; | ||
| 18975 | + /// `part128_edge_*_hits` and `inter_sb128_*_hits` HARD-assert it fired, | ||
| 18976 | + /// and `decode_all_frames_vs_oracle` compares EVERY decode-order frame | ||
| 18977 | + /// (hidden alt-refs included) against the instrumented aomdec. | ||
| 18978 | + #[test] | ||
| 18979 | + fn a_real_aomenc_sb128_gathered_edge_horz_partition_decodes_pixel_exact() { | ||
| 18980 | + const NAME: &str = | ||
| 18981 | + "a_real_aomenc_sb128_gathered_edge_horz_partition_decodes_pixel_exact"; | ||
| 18982 | + let _gate_lock = lock_gate_counters(); | ||
| 18983 | + if !have_ffmpeg() { | ||
| 18984 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 18985 | + return; | ||
| 18986 | + } | ||
| 18987 | + if !have_aomenc() { | ||
| 18988 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 18989 | + return; | ||
| 18990 | + } | ||
| 18991 | + // (seed, cq, width, height, 10-bit, vertical twin). Every size has a | ||
| 18992 | + // PARTIAL last superblock row (or column, for the VERT twin): 320 px | ||
| 18993 | + // = 80 mi rows, two full 128 rows and a 64-px remainder; 256 px = 64 | ||
| 18994 | + // mi = two full rows and none, so the VERT arm uses 192 px = 48 mi on | ||
| 18995 | + // the column axis. A smooth `gradients` source makes the KEY frame | ||
| 18996 | + // take the arm too, which is still refused by name (square-block | ||
| 18997 | + // intra), so this gate's source is `mandelbrot`: its key frames split | ||
| 18998 | + // and its inter frames keep the 128x64/64x128 edge block. | ||
| 18999 | + let arms: Vec<(u32, &str, usize, usize, bool, bool)> = vec![ | ||
| 19000 | + (42, "--cq-level=55", 384, 320, false, false), | ||
| 19001 | + (43, "--cq-level=55", 384, 320, true, false), | ||
| 19002 | + (44, "--cq-level=32", 192, 256, false, true), | ||
| 19003 | + (45, "--cq-level=45", 192, 256, true, true), | ||
| 19004 | + ]; | ||
| 19005 | + let (mut matched, mut named_refusals) = (0u32, 0u32); | ||
| 19006 | + let (mut edge_arms, mut inter_arms) = (0u32, 0u32); | ||
| 19007 | + for (seed, cq, width, height, ten_bit, vert) in arms { | ||
| 19008 | + let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; | ||
| 19009 | + let y4m = Command::new("ffmpeg") | ||
| 19010 | + .args([ | ||
| 19011 | + "-v", "error", "-f", "lavfi", "-i", | ||
| 19012 | + &format!( | ||
| 19013 | + "mandelbrot=size={width}x{height}:rate=25:start_x=-0.6:start_y=-0.4" | ||
| 19014 | + ), | ||
| 19015 | + "-pix_fmt", pix, "-strict", "-1", "-t", "0.2", | ||
| 19016 | + "-f", "yuv4mpegpipe", "-", | ||
| 19017 | + ]) | ||
| 19018 | + .stdin(Stdio::null()) | ||
| 19019 | + .stdout(Stdio::piped()) | ||
| 19020 | + .stderr(Stdio::piped()) | ||
| 19021 | + .output() | ||
| 19022 | + .expect("ffmpeg failed to run"); | ||
| 19023 | + assert!( | ||
| 19024 | + y4m.status.success(), | ||
| 19025 | + "{NAME}: ffmpeg fixture: {}", | ||
| 19026 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 19027 | + ); | ||
| 19028 | + let mut args: Vec<&str> = vec![ | ||
| 19029 | + "--codec=av1", "--passes=1", "--end-usage=q", cq, | ||
| 19030 | + "--cpu-used=0", "--threads=1", "--row-mt=0", | ||
| 19031 | + "--sb-size=128", "--min-partition-size=64", | ||
| 19032 | + "--enable-rect-partitions=1", "--enable-ab-partitions=0", | ||
| 19033 | + "--enable-1to4-partitions=0", "--enable-palette=0", | ||
| 19034 | + "--enable-intrabc=0", "--enable-tx-size-search=0", | ||
| 19035 | + "--deltaq-mode=0", "--limit=5", | ||
| 19036 | + ]; | ||
| 19037 | + if ten_bit { | ||
| 19038 | + args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); | ||
| 19039 | + } | ||
| 19040 | + args.extend_from_slice(&["--obu", "-o", "-", "-"]); | ||
| 19041 | + let mut child = Command::new(aomenc_path()) | ||
| 19042 | + .args(&args) | ||
| 19043 | + .stdin(Stdio::piped()) | ||
| 19044 | + .stdout(Stdio::piped()) | ||
| 19045 | + .stderr(Stdio::piped()) | ||
| 19046 | + .spawn() | ||
| 19047 | + .expect("aomenc failed to start"); | ||
| 19048 | + child | ||
| 19049 | + .stdin | ||
| 19050 | + .take() | ||
| 19051 | + .expect("aomenc stdin") | ||
| 19052 | + .write_all(&y4m.stdout) | ||
| 19053 | + .expect("writing y4m to aomenc"); | ||
| 19054 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 19055 | + assert!( | ||
| 19056 | + out.status.success(), | ||
| 19057 | + "{NAME}: aomenc refused the fixture: {}", | ||
| 19058 | + String::from_utf8_lossy(&out.stderr) | ||
| 19059 | + ); | ||
| 19060 | + let stream = out.stdout; | ||
| 19061 | + let (before_edge, before_inter) = if vert { | ||
| 19062 | + ( | ||
| 19063 | + crate::decode::part128_edge_vert_hits(), | ||
| 19064 | + crate::decode::inter_sb128_vert_hits(), | ||
| 19065 | + ) | ||
| 19066 | + } else { | ||
| 19067 | + ( | ||
| 19068 | + crate::decode::part128_edge_horz_hits(), | ||
| 19069 | + crate::decode::inter_sb128_horz_hits(), | ||
| 19070 | + ) | ||
| 19071 | + }; | ||
| 19072 | + // A refusal is still a legal outcome for an arm whose stream hits | ||
| 19073 | + // some OTHER lane's gap, but never for all of them (asserted | ||
| 19074 | + // below), and never as a silent skip. | ||
| 19075 | + if let Err(e) = decode_stream(&stream) { | ||
| 19076 | + let msg = e.to_string(); | ||
| 19077 | + assert!( | ||
| 19078 | + msg.contains("unsupported"), | ||
| 19079 | + "{NAME} failed outright, not a named refusal \ | ||
| 19080 | + (seed {seed} {width}x{height}): {msg}" | ||
| 19081 | + ); | ||
| 19082 | + named_refusals += 1; | ||
| 19083 | + eprintln!("{NAME}: seed {seed} {width}x{height} refusal: {msg}"); | ||
| 19084 | + continue; | ||
| 19085 | + } | ||
| 19086 | + let (frames, hidden) = decode_all_frames_vs_oracle( | ||
| 19087 | + &stream, | ||
| 19088 | + &format!("sb128c-edge-{seed}-{width}x{height}"), | ||
| 19089 | + ); | ||
| 19090 | + assert!(frames > 0, "{NAME}: no frames decoded at {width}x{height}"); | ||
| 19091 | + let (edge, inter) = if vert { | ||
| 19092 | + ( | ||
| 19093 | + crate::decode::part128_edge_vert_hits() - before_edge, | ||
| 19094 | + crate::decode::inter_sb128_vert_hits() - before_inter, | ||
| 19095 | + ) | ||
| 19096 | + } else { | ||
| 19097 | + ( | ||
| 19098 | + crate::decode::part128_edge_horz_hits() - before_edge, | ||
| 19099 | + crate::decode::inter_sb128_horz_hits() - before_inter, | ||
| 19100 | + ) | ||
| 19101 | + }; | ||
| 19102 | + eprintln!( | ||
| 19103 | + "{NAME}: seed {seed} cq {cq} {width}x{height} {}bit {}: \ | ||
| 19104 | + {frames} frames pixel-exact ({hidden} hidden), \ | ||
| 19105 | + edge_hits +{edge} inter_128rect_blocks +{inter}", | ||
| 19106 | + if ten_bit { 10 } else { 8 }, | ||
| 19107 | + if vert { "VERT" } else { "HORZ" }, | ||
| 19108 | + ); | ||
| 19109 | + if edge > 0 { | ||
| 19110 | + edge_arms += 1; | ||
| 19111 | + } | ||
| 19112 | + if inter > 0 { | ||
| 19113 | + inter_arms += 1; | ||
| 19114 | + } | ||
| 19115 | + matched += 1; | ||
| 19116 | + } | ||
| 19117 | + assert!( | ||
| 19118 | + matched > 0, | ||
| 19119 | + "{NAME}: every attempt refused ({named_refusals}); the gate never \ | ||
| 19120 | + decoded a stream" | ||
| 19121 | + ); | ||
| 19122 | + assert!( | ||
| 19123 | + edge_arms > 0, | ||
| 19124 | + "{NAME}: {matched} stream(s) decoded pixel-exact but NOT ONE 128 root \ | ||
| 19125 | + took the gathered frame-edge HORZ/VERT arm this gate exists for" | ||
| 19126 | + ); | ||
| 19127 | + assert!( | ||
| 19128 | + inter_arms > 0, | ||
| 19129 | + "{NAME}: the gathered arm fired only on key frames -- no INTER \ | ||
| 19130 | + 128x64/64x128 block was decoded, which is the film's own shape" | ||
| 19131 | + ); | ||
| 19132 | + } | ||
| 19133 | + | ||
| 18956 | #[test] | 19134 | #[test] |
| 18957 | #[ignore = "lane-sb128 r2 diagnostic: is the frame-6 mismatch sb128-specific?"] | 19135 | #[ignore = "lane-sb128 r2 diagnostic: is the frame-6 mismatch sb128-specific?"] |
| 18958 | fn sb128_r2_control_sb64() { | 19136 | fn sb128_r2_control_sb64() { |