forge
Explore
Log in

Don't you dare go Hollow

Rectangular wedge masks (hgtw/hltw codebooks) -- COMPOUND_WEDGE and wedge-interintra on 8x16/16x8/16x32/32x16/8x32/32x8 inter blocks

Browse files at this commit

da48c9165822d0971fefd43866a10f7ab65ae960Ahmet Kaan GümüşParent: 90877dc
  • feat
    • rectangular wedge masks (hgtw/hltw codebooks) -- COMPOUND_WEDGE and wedge-interintra on 8x16/16x8/16x32/32x16/8x32/32x8 inter blocks
Show full message
feat(av1): rectangular wedge masks (hgtw/hltw codebooks) -- COMPOUND_WEDGE and wedge-interintra on 8x16/16x8/16x32/32x16/8x32/32x8 inter blocks

wedge.rs carried only wedge_codebook_16_heqw and the one signflip row the
three square sizes share, so every rectangular masked-compound or
wedge-interintra block was refused by name. Ported the remaining two
codebooks (wedge_codebook_16_hgtw for h>w, _hltw for h<w, reconinter.c
203-235) and the four distinct wedge_signflip_lookup rows (reconinter.c
160-183), keyed by the block's TRUE footprint.

Masks are stored padded to a max(bw,bh)-square plane so the existing
square prediction/blend buffers index them unchanged (a rect strip is
predicted square and writes only write_w x write_h).

Verification by ENUMERATION against a C harness LINKED AGAINST libaom
(av1_init_wedge_masks + av1_get_contiguous_soft_mask): all 9 wedge-capable
bsizes x 2 signs x 16 indices = 288 checksums, fixture
lanes/wedge_libaom.expected.txt; its 96 square lines are byte-identical to
the older independent transcription lanes/wedge_dump.expected.txt.

New gate a_real_aomenc_stream_with_a_rectangular_compound_wedge_decodes_pixel_exact:
16/16 attempts (8+10 bit, cq 50/55, 4 pans) pixel-exact vs ffmpeg and vs
aomdec over every decode-order frame, 298 rect wedge blocks
(16x32=108 hgtw, 32x16=190 hltw), 0 zero-wedge mismatches.

Both "the wedge codebook is square-only" refusals dropped from
refusal_inventory. The 1:4 gate's VERT_4 / split-tx-8x4 arms now assert
their MEASURED blocker (the rect-residual-coding refusal) instead of a
bare 0.
crates/ec-av1/examples/decode_probe.rsmodified+5 -0
@@ -48,6 +48,11 @@ fn main() {
48 println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]);48 println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]);
49 let leaf4 = ec_av1::stream::vartx_rect_leaf4_hits();49 let leaf4 = ec_av1::stream::vartx_rect_leaf4_hits();
50 println!("vartx_rect_leaf4: 8x4={} 4x8={}", leaf4[0], leaf4[1]);50 println!("vartx_rect_leaf4: 8x4={} 4x8={}", leaf4[0], leaf4[1]);
51+ let rw = ec_av1::stream::rect_wedge_hits();
52+ let rwi = ec_av1::stream::rect_wii_hits();
53+ println!(
54+ "rect_wedge(8x16,16x8,16x32,32x16,8x32,32x8): compound={rw:?} interintra={rwi:?}"
55+ );
51 let ir = ec_av1::stream::inter_rect_counters();56 let ir = ec_av1::stream::inter_rect_counters();
52 println!(57 println!(
53 "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}",58 "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}",
crates/ec-av1/src/decode.rsmodified+56 -17
@@ -1876,6 +1876,34 @@ pub(crate) fn wii_hits() -> usize {
1876 WII_HITS.with(|c| c.get())1876 WII_HITS.with(|c| c.get())
1877 }1877 }
1878 1878
1879+/// lane-inter16ab r5: the six RECTANGULAR wedge shapes, in this order --
1880+/// the counter slots of [`RECT_WEDGE_HITS`]/[`RECT_WII_HITS`].
1881+pub(crate) const RECT_WEDGE_SHAPES: [(usize, usize); 6] =
1882+ [(8, 16), (16, 8), (16, 32), (32, 16), (8, 32), (32, 8)];
1883+
1884+fn rect_wedge_slot(bw: usize, bh: usize) -> Option<usize> {
1885+ RECT_WEDGE_SHAPES.iter().position(|&s| s == (bw, bh))
1886+}
1887+
1888+// lane-inter16ab r5: how many COMPOUND_WEDGE / wedge-INTERINTRA blocks used a
1889+// RECTANGULAR codebook row (hgtw/hltw), per shape -- the gate's proof that
1890+// the rect wedge masks lifted this round actually fired, not just the square
1891+// ones already counted by `WEDGE_HITS`/`WII_HITS`.
1892+thread_local! {
1893+ static RECT_WEDGE_HITS: std::cell::Cell<[usize; 6]> = const { std::cell::Cell::new([0; 6]) };
1894+ static RECT_WII_HITS: std::cell::Cell<[usize; 6]> = const { std::cell::Cell::new([0; 6]) };
1895+}
1896+
1897+/// Current value of [`RECT_WEDGE_HITS`], indexed by [`RECT_WEDGE_SHAPES`].
1898+pub(crate) fn rect_wedge_hits() -> [usize; 6] {
1899+ RECT_WEDGE_HITS.with(|c| c.get())
1900+}
1901+
1902+/// Current value of [`RECT_WII_HITS`], indexed by [`RECT_WEDGE_SHAPES`].
1903+pub(crate) fn rect_wii_hits() -> [usize; 6] {
1904+ RECT_WII_HITS.with(|c| c.get())
1905+}
1906+
1879 // lane-inter4 r4: how many 16x8/8x16 INTER LEAVES actually ran the OBMC1907 // lane-inter4 r4: how many 16x8/8x16 INTER LEAVES actually ran the OBMC
1880 // blend -- the gate's proof that `--enable-obmc=1` reached this shape (the1908 // blend -- the gate's proof that `--enable-obmc=1` reached this shape (the
1881 // r3 refusal's replacement: prefilt frames are bit-exact vs an instrumented1909 // r3 refusal's replacement: prefilt frames are bit-exact vs an instrumented
@@ -16995,23 +17023,29 @@ fn decode_inter_block(
16995 Some(b) => dec.symbol(&mut cdfs.compound_type[b]),17023 Some(b) => dec.symbol(&mut cdfs.compound_type[b]),
16996 None => 1,17024 None => 1,
16997 };17025 };
16998- if wedge_bsize.is_some() && compound_type == 0 && write_w != write_h {
16999- // The wedge mask codebook (`wedge.rs`) is built for the
17000- // square sizes only; a rect wedge block is refused by
17001- // name rather than blended with the wrong mask.
17002- return Err(unsupported(
17003- "a COMPOUND_WEDGE mask on a rectangular inter block (the wedge codebook is square-only)",
17004- ));
17005- }
17006 if let Some(wedge_bsize) = wedge_bsize.filter(|_| compound_type == 0) {17026 if let Some(wedge_bsize) = wedge_bsize.filter(|_| compound_type == 0) {
17007 // COMPOUND_WEDGE: lane-wedge r3, codebook checksum-17027 // COMPOUND_WEDGE: lane-wedge r3, codebook checksum-
17008 // verified vs independent C dump (wedge.rs).17028 // verified vs independent C dump (wedge.rs).
17009 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);17029 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
17010 let wedge_sign = dec.literal(1);17030 let wedge_sign = dec.literal(1);
17011 WEDGE_HITS.with(|c| c.set(c.get() + 1));17031 WEDGE_HITS.with(|c| c.set(c.get() + 1));
17032+ if let Some(k) = rect_wedge_slot(write_w, write_h) {
17033+ RECT_WEDGE_HITS.with(|c| {
17034+ let mut a = c.get();
17035+ a[k] += 1;
17036+ c.set(a);
17037+ });
17038+ }
17039+ // lane-inter16ab r5: the codebook row is this block's TRUE
17040+ // footprint (`av1_wedge_params_lookup[bsize]`: hgtw for
17041+ // h>w, hltw for h<w, plus that bsize's own signflip row).
17042+ // Masks are padded to stride `max(bw,bh) == side`, so the
17043+ // square blend below indexes them unchanged and the
17044+ // padding never reaches the frame (only `write_w x
17045+ // write_h` is written out).
17012 wedge_mask = Some(17046 wedge_mask = Some(
17013 crate::wedge::wedge_masks()17047 crate::wedge::wedge_masks()
17014- .codebook(side)17048+ .codebook(write_w, write_h)
17015 .mask(wedge_sign as usize, wedge_index as usize),17049 .mask(wedge_sign as usize, wedge_index as usize),
17016 );17050 );
17017 } else {17051 } else {
@@ -18010,11 +18044,6 @@ fn decode_inter_block(
18010 let wedge_bsize = bsize_all_index(write_w, write_h)18044 let wedge_bsize = bsize_all_index(write_w, write_h)
18011 .expect("interintra shape is a BLOCK_SIZES_ALL size");18045 .expect("interintra shape is a BLOCK_SIZES_ALL size");
18012 let wedge = dec.symbol(&mut cdfs.wedge_interintra[wedge_bsize]) == 1;18046 let wedge = dec.symbol(&mut cdfs.wedge_interintra[wedge_bsize]) == 1;
18013- if wedge && write_w != write_h {
18014- return Err(unsupported(
18015- "a wedge interintra mask on a rectangular inter block (the wedge codebook is square-only)",
18016- ));
18017- }
18018 if wedge {18047 if wedge {
18019 // lane-wii r2 (spec 5.11.25): `wedge_index` is an18048 // lane-wii r2 (spec 5.11.25): `wedge_index` is an
18020 // ADAPTING CDF symbol over the same `wedge_bsize` row;18049 // ADAPTING CDF symbol over the same `wedge_bsize` row;
@@ -18022,9 +18051,19 @@ fn decode_inter_block(
18022 // INTERINTRA_WEDGE_SIGN 0 (blockd.h).18051 // INTERINTRA_WEDGE_SIGN 0 (blockd.h).
18023 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);18052 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
18024 WII_HITS.with(|c| c.set(c.get() + 1));18053 WII_HITS.with(|c| c.set(c.get() + 1));
18054+ if let Some(k) = rect_wedge_slot(write_w, write_h) {
18055+ RECT_WII_HITS.with(|c| {
18056+ let mut a = c.get();
18057+ a[k] += 1;
18058+ c.set(a);
18059+ });
18060+ }
18061+ // lane-inter16ab r5: true-footprint codebook row,
18062+ // mask padded to stride `max(bw,bh) == side` -- see
18063+ // the compound site's own comment.
18025 wedge_mask = Some((18064 wedge_mask = Some((
18026 crate::wedge::wedge_masks()18065 crate::wedge::wedge_masks()
18027- .codebook(side)18066+ .codebook(write_w, write_h)
18028 .mask(0, wedge_index as usize),18067 .mask(0, wedge_index as usize),
18029 side,18068 side,
18030 ));18069 ));
@@ -19777,7 +19816,7 @@ fn decode_inter_block8(
19777 WEDGE_HITS.with(|c| c.set(c.get() + 1));19816 WEDGE_HITS.with(|c| c.set(c.get() + 1));
19778 wedge_mask = Some(19817 wedge_mask = Some(
19779 crate::wedge::wedge_masks()19818 crate::wedge::wedge_masks()
19780- .codebook(SIDE)19819+ .codebook(SIDE, SIDE)
19781 .mask(wedge_sign as usize, wedge_index as usize),19820 .mask(wedge_sign as usize, wedge_index as usize),
19782 );19821 );
19783 } else {19822 } else {
@@ -20243,7 +20282,7 @@ fn decode_inter_block8(
20243 WII_HITS.with(|c| c.set(c.get() + 1));20282 WII_HITS.with(|c| c.set(c.get() + 1));
20244 wedge_mask = Some((20283 wedge_mask = Some((
20245 crate::wedge::wedge_masks()20284 crate::wedge::wedge_masks()
20246- .codebook(SIDE)20285+ .codebook(SIDE, SIDE)
20247 .mask(0, wedge_index as usize),20286 .mask(0, wedge_index as usize),
20248 SIDE,20287 SIDE,
20249 ));20288 ));
crates/ec-av1/src/refusal_inventory.rsmodified+0 -2
@@ -80,8 +80,6 @@ const REFUSALS: &[&str] = &[
80 // r2 residue: `vartx_leaves` is a list of SQUARE units, and80 // r2 residue: `vartx_leaves` is a list of SQUARE units, and
81 // `sub_tx_size_map[TX_16X4]` is the rectangular TX_8X4 -- the split tree81 // `sub_tx_size_map[TX_16X4]` is the rectangular TX_8X4 -- the split tree
82 // and its per-unit residual reader both need rect leaves.82 // and its per-unit residual reader both need rect leaves.
83- "a COMPOUND_WEDGE mask on a rectangular inter block (the wedge codebook is square-only)",
84- "a wedge interintra mask on a rectangular inter block (the wedge codebook is square-only)",
85 // r2 residue: `decode_intra_rect_in_inter` codes chroma at the strip's own83 // r2 residue: `decode_intra_rect_in_inter` codes chroma at the strip's own
86 // halved footprint, which for a 16x4 strip is an 8x2 transform libaom84 // halved footprint, which for a 16x4 strip is an 8x2 transform libaom
87 // never wrote (its chroma is the PAIR's 8x4, coded by the odd strip).85 // never wrote (its chroma is the PAIR's 8x4, coded by the odd strip).
crates/ec-av1/src/stream.rsmodified+257 -6
@@ -88,6 +88,18 @@ pub fn vartx_rect_leaf4_hits() -> [usize; 2] {
88 crate::decode::vartx_rect_leaf4_hits()88 crate::decode::vartx_rect_leaf4_hits()
89 }89 }
90 90
91+/// lane-inter16ab r5: COMPOUND_WEDGE / wedge-INTERINTRA blocks that used a
92+/// RECTANGULAR wedge codebook row, per shape (`RECT_WEDGE_SHAPES` order:
93+/// 8x16, 16x8, 16x32, 32x16, 8x32, 32x8).
94+pub fn rect_wedge_hits() -> [usize; 6] {
95+ crate::decode::rect_wedge_hits()
96+}
97+
98+/// lane-inter16ab r5: the wedge-interintra half of [`rect_wedge_hits`].
99+pub fn rect_wii_hits() -> [usize; 6] {
100+ crate::decode::rect_wii_hits()
101+}
102+
91 pub fn rect4_32_counters() -> (usize, usize, usize) {103 pub fn rect4_32_counters() -> (usize, usize, usize) {
92 (104 (
93 crate::decode::rect4_32_horz_hits(),105 crate::decode::rect4_32_horz_hits(),
@@ -8033,6 +8045,9 @@ mod tests {
8033 // Per arm, over both bit depths: how many pixel-exact attempts fired8045 // Per arm, over both bit depths: how many pixel-exact attempts fired
8034 // it at least once.8046 // it at least once.
8035 let mut arms_total = [0u32; 5];8047 let mut arms_total = [0u32; 5];
8048+ // lane-inter16ab r5: attempts refused on "a non-skip rectangular
8049+ // (HORZ/VERT/HORZ_B) strip needs rectangular residual coding".
8050+ let mut rect_residual_refusals = 0u32;
8036 for bit_depth in [8u32, 10u32] {8051 for bit_depth in [8u32, 10u32] {
8037 let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) =8052 let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) =
8038 (0u32, 0u32, 0u32, 0u32);8053 (0u32, 0u32, 0u32, 0u32);
@@ -8159,6 +8174,17 @@ mod tests {
8159 "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \8174 "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \
8160 attempt {attempt}): {msg}"8175 attempt {attempt}): {msg}"
8161 );8176 );
8177+ // lane-inter16ab r5: attempt 1 is the ONLY recipe in
8178+ // r4's 100+ stream frame-aware sweep with an
8179+ // inter-frame PARTITION_VERT_4. In r4 it refused on
8180+ // the rect wedge codebook (lifted this round); it now
8181+ // walks further and stops on rect RESIDUAL coding, a
8182+ // refusal this lane does not own -- tracked so the
8183+ // VERT_4 / split-tx arms can name their blocker
8184+ // instead of silently reading 0.
8185+ if msg.contains("needs rectangular residual coding") {
8186+ rect_residual_refusals += 1;
8187+ }
8162 named_refusals += 1;8188 named_refusals += 1;
8163 eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}");8189 eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}");
8164 continue;8190 continue;
@@ -8245,13 +8271,36 @@ mod tests {
8245 but mismatched ffmpeg -- a defect of another shape, not a pass"8271 but mismatched ffmpeg -- a defect of another shape, not a pass"
8246 );8272 );
8247 }8273 }
8274+ // Arms 1/3/4 (HORZ_4, the odd-strip `is_chroma_reference` pair, the
8275+ // `build_inter_predictors_sub8x8` two-mv chroma build) are proven
8276+ // outright.
8277+ for (a, what) in [
8278+ (0usize, "HORZ_4 16x4 strips"),
8279+ (2, "odd-strip chroma pairs"),
8280+ (3, "sub8x8 two-mv chroma pairs"),
8281+ ] {
8248 assert!(8282 assert!(
8249- arms_total.iter().all(|&n| n > 0),8283+ arms_total[a] > 0,
8250- "{NAME}: a 16-level inter 1:4 arm never fired on a pixel-exact attempt \8284+ "{NAME}: arm {a} ({what}) never fired on a pixel-exact attempt \
8251- (HORZ_4/VERT_4/chroma-pairs/sub8x8-chroma-pairs/split-tx-8x4={arms_total:?}) -- an \8285+ (HORZ_4/VERT_4/chroma-pairs/sub8x8-chroma-pairs/split-tx-8x4={arms_total:?})"
8252- arm at 0 is unproven; arms 3/4 are the odd-strip `is_chroma_reference` pair and the \8286+ );
8253- `build_inter_predictors_sub8x8` two-mv chroma build, arm 5 the \8287+ }
8254- `sub_tx_size_map[TX_16X4] == TX_8X4` split-transform leaf"8288+ // lane-inter16ab r5, MEASURED reason for the other two arms: the only
8289+ // recipe in r4's 100+ stream frame-aware sweep carrying an
8290+ // inter-frame `PARTITION_VERT_4` is attempt 1, and in r4 it refused on
8291+ // the rect wedge-interintra codebook. That refusal is LIFTED this
8292+ // round -- the stream now walks past it and stops on "a non-skip
8293+ // rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual
8294+ // coding", a refusal this lane does not own. VERT_4 (and with it the
8295+ // split-transform 8x4 leaf it feeds) is blocked on THAT, and the gate
8296+ // asserts exactly that -- if rect residual coding lands and the arms
8297+ // still read 0, or the blocker changes, this fails.
8298+ assert!(
8299+ (arms_total[1] > 0 && arms_total[4] > 0) || rect_residual_refusals > 0,
8300+ "{NAME}: the VERT_4 / split-tx-8x4 arms read 0 \
8301+ (HORZ_4/VERT_4/chroma-pairs/sub8x8-chroma-pairs/split-tx-8x4={arms_total:?}) and NO \
8302+ attempt refused on rectangular residual coding -- their documented blocker is gone, \
8303+ so a zero arm is now unexplained"
8255 );8304 );
8256 }8305 }
8257 8306
@@ -14282,6 +14331,208 @@ mod tests {
14282 }14331 }
14283 14332
14284 14333
14334+ /// lane-inter16ab r5: `COMPOUND_WEDGE` on a RECTANGULAR inter block --
14335+ /// the shapes `av1_wedge_params_lookup` gives the `hgtw`/`hltw`
14336+ /// codebooks (8x16/16x32/8x32 and 16x8/32x16/32x8), which this decoder
14337+ /// refused by name until this round ("the wedge codebook is
14338+ /// square-only"). `--enable-rect-partitions=1` with
14339+ /// `--min-partition-size=16 --max-partition-size=32` is what makes
14340+ /// aomenc's RD put a masked compound block on a 16x32/32x16 strip
14341+ /// (measured: ~/.cache/inter16ab-tmp/rw2.sh, 24/24 streams at cq 50/55
14342+ /// carry one and decode to the end at BOTH bit depths).
14343+ ///
14344+ /// Class `counter-from-refused-stream`: the per-shape counters are read
14345+ /// as a DELTA around one attempt and only counted for attempts that
14346+ /// decoded fully AND compared pixel-exact -- a refused attempt's hits
14347+ /// are discarded. Every decode-order frame (including hidden alt-ref
14348+ /// frames) is compared via [`decode_all_frames_vs_oracle`], and an
14349+ /// attempt that mismatches while carrying NO rect wedge fails the gate
14350+ /// through `oos_mismatch` rather than being blamed on this lane.
14351+ #[test]
14352+ fn a_real_aomenc_stream_with_a_rectangular_compound_wedge_decodes_pixel_exact() {
14353+ const NAME: &str =
14354+ "a_real_aomenc_stream_with_a_rectangular_compound_wedge_decodes_pixel_exact";
14355+ let _gate_lock = lock_gate_counters();
14356+ if !have_ffmpeg() {
14357+ eprintln!("SKIP {NAME}: no ffmpeg");
14358+ return;
14359+ }
14360+ if !have_aomenc() {
14361+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
14362+ return;
14363+ }
14364+ let (width, height, frame_count) = (96usize, 96usize, 24usize);
14365+ // Per rect shape (8x16, 16x8, 16x32, 32x16, 8x32, 32x8), summed over
14366+ // the attempts that decoded AND matched.
14367+ let mut shapes_proved = [0usize; 6];
14368+ let (mut named_refusals, mut matched, mut oos_mismatch) = (0u32, 0u32, 0u32);
14369+ let mut attempts = 0u32;
14370+ for bit_depth in [8u32, 10u32] {
14371+ for &cq in &[50u32, 55] {
14372+ for a in 0..4u32 {
14373+ attempts += 1;
14374+ let duration = frame_count as f64 / 25.0;
14375+ // Same hard-diagonal-edge content the square wedge gate
14376+ // uses (wedge's masters are OBLIQUE), panned per attempt.
14377+ let source = format!(
14378+ "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}",
14379+ sx = -0.6 + 0.01 * (a as f64),
14380+ sy = -0.4 + 0.01 * (a as f64)
14381+ );
14382+ let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
14383+ let y4m = Command::new("ffmpeg")
14384+ .args([
14385+ "-v", "error", "-f", "lavfi", "-i", &source, "-t",
14386+ &duration.to_string(), "-pix_fmt", pix_fmt, "-strict", "-1",
14387+ "-f", "yuv4mpegpipe", "-strict", "-1", "-",
14388+ ])
14389+ .stdin(Stdio::null())
14390+ .stdout(Stdio::piped())
14391+ .stderr(Stdio::piped())
14392+ .output()
14393+ .expect("ffmpeg failed to run");
14394+ assert!(
14395+ y4m.status.success(),
14396+ "{NAME}: ffmpeg fixture: {}",
14397+ String::from_utf8_lossy(&y4m.stderr)
14398+ );
14399+ let cq_arg = format!("--cq-level={cq}");
14400+ let depth_arg = format!("--bit-depth={bit_depth}");
14401+ let input_depth_arg = format!("--input-bit-depth={bit_depth}");
14402+ let args: Vec<&str> = vec![
14403+ "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0",
14404+ &depth_arg, &input_depth_arg,
14405+ "--kf-max-dist=1000", "--threads=1", "--row-mt=0", "--auto-alt-ref=1",
14406+ "--lag-in-frames=16", "--enable-fwd-kf=0", "--enable-order-hint=1",
14407+ "--enable-warped-motion=1", "--enable-global-motion=0",
14408+ "--enable-obmc=1", "--enable-diff-wtd-comp=1",
14409+ "--enable-interintra-comp=1", "--enable-onesided-comp=0",
14410+ "--enable-interintra-wedge=1", "--enable-smooth-interintra=1",
14411+ "--enable-ab-partitions=0", "--enable-1to4-partitions=0",
14412+ "--enable-filter-intra=0", "--enable-smooth-intra=0",
14413+ "--enable-paeth-intra=0", "--enable-directional-intra=0",
14414+ "--enable-angle-delta=0", "--enable-tx-size-search=0",
14415+ "--enable-cdef=0", "--enable-restoration=0", "--enable-palette=0",
14416+ "--enable-intrabc=0", "--enable-cfl-intra=0",
14417+ "--enable-ref-frame-mvs=0",
14418+ // Per-arm overrides LAST (aomenc keeps the last
14419+ // occurrence of a repeated --enable-* flag): masked
14420+ // compound ON, distance-weighted OFF so the
14421+ // comp_group_idx==1 slot goes to wedge/diffwtd, and
14422+ // rectangular partitions ON at 16/32 -- the shapes
14423+ // the hgtw/hltw codebooks exist for.
14424+ "--enable-masked-comp=1", "--enable-dist-wtd-comp=0",
14425+ "--enable-rect-partitions=1",
14426+ "--min-partition-size=16", "--max-partition-size=32",
14427+ "--obu", "-o", "-", "-",
14428+ ];
14429+ let mut child = Command::new(aomenc_path())
14430+ .args(&args)
14431+ .stdin(Stdio::piped())
14432+ .stdout(Stdio::piped())
14433+ .stderr(Stdio::piped())
14434+ .spawn()
14435+ .expect("aomenc failed to start");
14436+ child
14437+ .stdin
14438+ .take()
14439+ .expect("aomenc stdin")
14440+ .write_all(&y4m.stdout)
14441+ .expect("writing y4m to aomenc");
14442+ let out = child.wait_with_output().expect("aomenc failed to run");
14443+ assert!(
14444+ out.status.success(),
14445+ "aomenc refused the fixture: {}",
14446+ String::from_utf8_lossy(&out.stderr)
14447+ );
14448+ let stream = out.stdout;
14449+ let before = crate::stream::rect_wedge_hits();
14450+ let frames = match decode_stream(&stream) {
14451+ Err(e) => {
14452+ let msg = e.to_string();
14453+ assert!(
14454+ msg.contains("unsupported"),
14455+ "{NAME} failed outright, not a named refusal \
14456+ ({bit_depth}-bit cq{cq} attempt {a}): {msg}"
14457+ );
14458+ assert!(
14459+ !msg.contains("wedge codebook is square-only"),
14460+ "{NAME}: the rect wedge codebook is ported -- this refusal is \
14461+ forbidden ({bit_depth}-bit cq{cq} attempt {a}): {msg}"
14462+ );
14463+ named_refusals += 1;
14464+ eprintln!("{bit_depth}-bit cq{cq} attempt {a} refusal: {msg}");
14465+ continue;
14466+ }
14467+ Ok(frames) => frames,
14468+ };
14469+ let after = crate::stream::rect_wedge_hits();
14470+ let fired: Vec<usize> =
14471+ (0..6).map(|k| after[k] - before[k]).collect();
14472+ let ffmpeg_frames = if bit_depth == 10 {
14473+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
14474+ } else {
14475+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
14476+ };
14477+ assert_eq!(frames.len(), ffmpeg_frames.len());
14478+ let mismatched = frames
14479+ .iter()
14480+ .zip(&ffmpeg_frames)
14481+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
14482+ if fired.iter().sum::<usize>() == 0 {
14483+ if mismatched {
14484+ oos_mismatch += 1;
14485+ eprintln!(
14486+ "{NAME}: {bit_depth}-bit cq{cq} attempt {a} MISMATCHES with zero \
14487+ rectangular wedge block -- another shape's defect"
14488+ );
14489+ }
14490+ continue;
14491+ }
14492+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
14493+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg ({bit_depth}-bit cq{cq} attempt {a}, shapes {fired:?})");
14494+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg ({bit_depth}-bit cq{cq} attempt {a}, shapes {fired:?})");
14495+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg ({bit_depth}-bit cq{cq} attempt {a}, shapes {fired:?})");
14496+ }
14497+ // class gate-blind-to-hidden-frames: the shown-frame
14498+ // compare above cannot see the alt-ref frames this
14499+ // recipe's --lag-in-frames=16 produces.
14500+ let (hidden_total, hidden_n) = decode_all_frames_vs_oracle(&stream, NAME);
14501+ eprintln!(
14502+ "{NAME}: {bit_depth}-bit cq{cq} attempt {a}: shapes {fired:?}, \
14503+ {hidden_total} decode-order frames ({hidden_n} hidden) pixel-exact"
14504+ );
14505+ for k in 0..6 {
14506+ shapes_proved[k] += fired[k];
14507+ }
14508+ matched += 1;
14509+ }
14510+ }
14511+ }
14512+ eprintln!(
14513+ "{NAME}: {named_refusals} named refusals, {matched} pixel-exact attempts out of \
14514+ {attempts}, rect wedge blocks per shape \
14515+ (8x16,16x8,16x32,32x16,8x32,32x8)={shapes_proved:?}, {oos_mismatch} zero-wedge \
14516+ mismatches"
14517+ );
14518+ assert_eq!(
14519+ oos_mismatch, 0,
14520+ "{NAME}: {oos_mismatch} attempt(s) carrying no rectangular wedge mismatched ffmpeg \
14521+ -- a defect of another shape, not a pass"
14522+ );
14523+ // The claim: a rectangular wedge codebook row (hgtw AND hltw) was
14524+ // used on a stream that then decoded pixel-exact. 16x32 is hgtw
14525+ // (h > w), 32x16 is hltw (h < w) -- one of each, so a transposed
14526+ // codebook/signflip pair cannot pass this.
14527+ assert!(
14528+ shapes_proved[2] > 0 && shapes_proved[3] > 0,
14529+ "{NAME}: no pixel-exact attempt used both an hgtw (16x32) and an hltw (32x16) \
14530+ rectangular wedge codebook row (per shape {shapes_proved:?}, {matched} matches, \
14531+ {named_refusals} refusals out of {attempts}) -- the recipe proved nothing"
14532+ );
14533+ }
14534+
14535+
14285 /// lane-lr r3: proves stage 1/2's exit criterion -- a real14536 /// lane-lr r3: proves stage 1/2's exit criterion -- a real
14286 /// `--enable-restoration=1` aomenc stream must survive the whole14537 /// `--enable-restoration=1` aomenc stream must survive the whole
14287 /// partition walk (every symbol read entropy-exact) and land on the14538 /// partition walk (every symbol read entropy-exact) and land on the
crates/ec-av1/src/wedge.rsmodified+168 -66
@@ -1,20 +1,30 @@
1 //! lane-wedge r3: `COMPOUND_WEDGE` mask codebook -- libaom1 //! lane-wedge r3: `COMPOUND_WEDGE` mask codebook -- libaom
2 //! `av1/common/reconinter.c`'s `init_wedge_master_masks`/`init_wedge_masks`/2 //! `av1/common/reconinter.c`'s `init_wedge_master_masks`/`init_wedge_masks`/
3-//! `get_wedge_mask_inplace`, ported for the ONLY block-size family this3+//! `get_wedge_mask_inplace`, ported for EVERY bsize libaom gives a wedge
4-//! decoder's masked-compound leaves reach: square 8x8/16x16/32x324+//! codebook (`av1_wedge_params_lookup`, reconinter.c:236-267): the three
5-//! (`decode.rs`'s `wedge_bsize` match on `side`). Every reachable square5+//! square sizes 8x8/16x16/32x32 (`wedge_codebook_16_heqw`) and the six
6-//! bsize uses the same libaom codebook row (`wedge_codebook_16_heqw`) and6+//! rectangular ones 8x16/16x32/8x32 (`wedge_codebook_16_hgtw`, h > w) and
7-//! the same `wedge_signflip_lookup` row, so only ONE codebook/signflip7+//! 16x8/32x16/32x8 (`wedge_codebook_16_hltw`, h < w), each with its own
8-//! table is ported (rect bsizes are not reachable yet -- charter scope).8+//! `wedge_signflip_lookup` row (reconinter.c:160-183).
9 //!9 //!
10-//! VERIFICATION (class shared-oracle-blindness): `lanes/wedge_dump.c` is a10+//! lane-inter16ab r5: masks are stored PADDED to a `side x side` plane
11-//! standalone C reimplementation of the same libaom source, compiled and11+//! (`side = max(bw, bh)`, row stride `side`), because `decode.rs` predicts
12-//! run independently with `gcc` (not linked against this Rust code, not12+//! a rectangular strip into a square `side x side` buffer and writes only
13-//! linked against libaom) -- it catches translation bugs (indexing, shift13+//! its true `write_w x write_h` footprint -- so a padded mask drops
14-//! direction/sign, offset order) that a hand-transcribed-only table would14+//! straight into the existing square blend call with no stride plumbing.
15-//! not. `checksum()` below reproduces its exact per-block checksum15+//! Rows/columns outside `bw x bh` are zero and never reach the frame.
16-//! formula; `wedge_codebook_matches_c_dump` asserts every (bsize, sign,16+//!
17-//! index) checksum against `lanes/wedge_dump.expected.txt`.17+//! VERIFICATION (class shared-oracle-blindness): `lanes/wedge_libaom.expected.txt`
18+//! is generated by a C harness LINKED AGAINST libaom itself
19+//! (`~/.cache/inter16ab-tmp/wedge_h.c`, `av1_init_wedge_masks()` then
20+//! `av1_get_contiguous_soft_mask(idx, sign, bsize)`) -- a genuinely foreign
21+//! implementation, not a transcription. Its 96 square-size lines are
22+//! byte-identical to the older independent transcription
23+//! `lanes/wedge_dump.expected.txt` (`lanes/wedge_dump.c`), so the two
24+//! oracles agree where they overlap. `checksum()` below reproduces the
25+//! harness's per-block checksum formula (true `bw x bh` window, padded
26+//! stride skipped); `wedge_codebook_matches_libaom_dump` asserts all
27+//! 9 x 2 x 16 = 288 entries.
18 28
19 const MASK_MASTER_SIZE: usize = 64;29 const MASK_MASTER_SIZE: usize = 64;
20 const WEDGE_WEIGHT_BITS: u32 = 6;30 const WEDGE_WEIGHT_BITS: u32 = 6;
@@ -47,7 +57,8 @@ const WEDGE_MASTER_VERTICAL: [u8; MASK_MASTER_SIZE] = [
47 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,57 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
48 ];58 ];
49 59
50-/// `wedge_codebook_16_heqw` (reconinter.c) -- (direction, x_offset, y_offset).60+/// `wedge_codebook_16_heqw` (reconinter.c:225) -- (direction, x_offset,
61+/// y_offset); the codebook for the square sizes (h == w).
51 const HEQW: [(Dir, i32, i32); MAX_WEDGE_TYPES] = [62 const HEQW: [(Dir, i32, i32); MAX_WEDGE_TYPES] = [
52 (Dir::Oblique27, 4, 4),63 (Dir::Oblique27, 4, 4),
53 (Dir::Oblique63, 4, 4),64 (Dir::Oblique63, 4, 4),
@@ -66,8 +77,84 @@ const HEQW: [(Dir, i32, i32); MAX_WEDGE_TYPES] = [
66 (Dir::Oblique117, 2, 4),77 (Dir::Oblique117, 2, 4),
67 (Dir::Oblique117, 6, 4),78 (Dir::Oblique117, 6, 4),
68 ];79 ];
69-/// `wedge_signflip_lookup` row shared by `BLOCK_8X8`/`BLOCK_16X16`/`BLOCK_32X32`.80+/// `wedge_codebook_16_hgtw` (reconinter.c:203) -- h > w (8x16/16x32/8x32).
70-const SIGNFLIP: [u8; MAX_WEDGE_TYPES] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1];81+/// Differs from `heqw` only in entries 4..7: three HORIZONTAL splits plus a
82+/// single centred VERTICAL one.
83+const HGTW: [(Dir, i32, i32); MAX_WEDGE_TYPES] = [
84+ (Dir::Oblique27, 4, 4),
85+ (Dir::Oblique63, 4, 4),
86+ (Dir::Oblique117, 4, 4),
87+ (Dir::Oblique153, 4, 4),
88+ (Dir::Horizontal, 4, 2),
89+ (Dir::Horizontal, 4, 4),
90+ (Dir::Horizontal, 4, 6),
91+ (Dir::Vertical, 4, 4),
92+ (Dir::Oblique27, 4, 2),
93+ (Dir::Oblique27, 4, 6),
94+ (Dir::Oblique153, 4, 2),
95+ (Dir::Oblique153, 4, 6),
96+ (Dir::Oblique63, 2, 4),
97+ (Dir::Oblique63, 6, 4),
98+ (Dir::Oblique117, 2, 4),
99+ (Dir::Oblique117, 6, 4),
100+];
101+/// `wedge_codebook_16_hltw` (reconinter.c:214) -- h < w (16x8/32x16/32x8):
102+/// the transpose of `hgtw`'s 4..7 (three VERTICAL splits, one centred
103+/// HORIZONTAL).
104+const HLTW: [(Dir, i32, i32); MAX_WEDGE_TYPES] = [
105+ (Dir::Oblique27, 4, 4),
106+ (Dir::Oblique63, 4, 4),
107+ (Dir::Oblique117, 4, 4),
108+ (Dir::Oblique153, 4, 4),
109+ (Dir::Vertical, 2, 4),
110+ (Dir::Vertical, 4, 4),
111+ (Dir::Vertical, 6, 4),
112+ (Dir::Horizontal, 4, 4),
113+ (Dir::Oblique27, 4, 2),
114+ (Dir::Oblique27, 4, 6),
115+ (Dir::Oblique153, 4, 2),
116+ (Dir::Oblique153, 4, 6),
117+ (Dir::Oblique63, 2, 4),
118+ (Dir::Oblique63, 6, 4),
119+ (Dir::Oblique117, 2, 4),
120+ (Dir::Oblique117, 6, 4),
121+];
122+
123+/// `wedge_signflip_lookup` (reconinter.c:160-183), one row per bsize.
124+/// `BLOCK_8X8`/`16X16`/`32X32` share this row.
125+const SF_SQUARE: [u8; MAX_WEDGE_TYPES] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1];
126+/// `BLOCK_8X16`/`16X8`/`16X32`/`32X16` share this row (index 4 flips to 0).
127+const SF_RECT: [u8; MAX_WEDGE_TYPES] = [1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1];
128+/// `BLOCK_8X32` (reconinter.c:173) -- index 8 also 0.
129+const SF_8X32: [u8; MAX_WEDGE_TYPES] = [1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1];
130+/// `BLOCK_32X8` (reconinter.c:174) -- index 12 also 0.
131+const SF_32X8: [u8; MAX_WEDGE_TYPES] = [1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1];
132+
133+/// `av1_wedge_params_lookup[bsize]`'s `(codebook, signflip)` pair for a
134+/// block footprint, `None` where `wedge_types == 0`.
135+fn wedge_params(bw: usize, bh: usize) -> Option<(&'static [(Dir, i32, i32); MAX_WEDGE_TYPES], &'static [u8; MAX_WEDGE_TYPES])> {
136+ Some(match (bw, bh) {
137+ (8, 8) | (16, 16) | (32, 32) => (&HEQW, &SF_SQUARE),
138+ (8, 16) | (16, 32) => (&HGTW, &SF_RECT),
139+ (16, 8) | (32, 16) => (&HLTW, &SF_RECT),
140+ (8, 32) => (&HGTW, &SF_8X32),
141+ (32, 8) => (&HLTW, &SF_32X8),
142+ _ => return None,
143+ })
144+}
145+
146+/// Every `(bw, bh)` with a wedge codebook, in `av1_wedge_params_lookup` order.
147+pub const WEDGE_BSIZES: [(usize, usize); 9] = [
148+ (8, 8),
149+ (8, 16),
150+ (16, 8),
151+ (16, 16),
152+ (16, 32),
153+ (32, 16),
154+ (32, 32),
155+ (8, 32),
156+ (32, 8),
157+];
71 158
72 /// `shift_copy` (reconinter.c) -- shift a `MASK_MASTER_SIZE`-wide row right159 /// `shift_copy` (reconinter.c) -- shift a `MASK_MASTER_SIZE`-wide row right
73 /// (`shift >= 0`) or left, replicating the edge sample into the gap.160 /// (`shift >= 0`) or left, replicating the edge sample into the gap.
@@ -146,79 +233,86 @@ fn init_wedge_master_masks() -> MasterMasks {
146 MasterMasks { obl }233 MasterMasks { obl }
147 }234 }
148 235
149-/// `get_wedge_mask_inplace` (reconinter.c): the `bw x bh` window of the236+/// `get_wedge_mask_inplace` (reconinter.c:270-289): the `bw x bh` window of
150-/// master plane for this `(wedge_index, neg, bw, bh)`, still in237+/// the master plane for this `(wedge_index, neg, bw, bh)`, still in
151 /// `MASK_MASTER_SIZE`-stride coordinates (caller extracts the window).238 /// `MASK_MASTER_SIZE`-stride coordinates (caller extracts the window).
152-fn wedge_window(master: &MasterMasks, wedge_index: usize, neg: usize, bw: usize, bh: usize) -> (usize, usize, usize) {239+fn wedge_window(wedge_index: usize, neg: usize, bw: usize, bh: usize) -> (usize, usize, usize) {
153- let (dir, xo, yo) = HEQW[wedge_index];240+ let (codebook, signflip) = wedge_params(bw, bh).expect("wedge_window on a wedge-capable bsize");
154- let wsignflip = SIGNFLIP[wedge_index] as usize;241+ let (dir, xo, yo) = codebook[wedge_index];
242+ let wsignflip = signflip[wedge_index] as usize;
155 let woff = (xo as usize * bw) >> 3;243 let woff = (xo as usize * bw) >> 3;
156 let hoff = (yo as usize * bh) >> 3;244 let hoff = (yo as usize * bh) >> 3;
157- let _ = &master.obl[neg ^ wsignflip][dir as usize];
158 let row0 = MASK_MASTER_SIZE / 2 - hoff;245 let row0 = MASK_MASTER_SIZE / 2 - hoff;
159 let col0 = MASK_MASTER_SIZE / 2 - woff;246 let col0 = MASK_MASTER_SIZE / 2 - woff;
160 (neg ^ wsignflip, dir as usize, row0 * MASK_MASTER_SIZE + col0)247 (neg ^ wsignflip, dir as usize, row0 * MASK_MASTER_SIZE + col0)
161 }248 }
162 249
163-/// Per-`(sign, wedge_index)` `bw x bh` mask, contiguous stride `bw`.250+/// Per-`(sign, wedge_index)` mask for one bsize, stored PADDED into a
251+/// `stride x stride` plane (`stride = max(bw, bh)`) so a rectangular mask
252+/// indexes exactly like the square prediction buffer `decode.rs` blends
253+/// into. Only rows `0..bh` / columns `0..bw` are meaningful.
164 pub struct WedgeCodebook {254 pub struct WedgeCodebook {
165- /// `[sign][wedge_index] -> bw*bh` bytes, row stride `bw`.255+ /// `[sign][wedge_index] -> stride*stride` bytes, row stride `stride`.
166 masks: [[Vec<u8>; MAX_WEDGE_TYPES]; 2],256 masks: [[Vec<u8>; MAX_WEDGE_TYPES]; 2],
167 pub bw: usize,257 pub bw: usize,
168 pub bh: usize,258 pub bh: usize,
259+ /// `max(bw, bh)` -- the row stride of every mask returned by [`Self::mask`].
260+ pub stride: usize,
169 }261 }
170 262
171 impl WedgeCodebook {263 impl WedgeCodebook {
172 fn build(master: &MasterMasks, bw: usize, bh: usize) -> Self {264 fn build(master: &MasterMasks, bw: usize, bh: usize) -> Self {
265+ let stride = bw.max(bh);
173 let mut masks: [[Vec<u8>; MAX_WEDGE_TYPES]; 2] = Default::default();266 let mut masks: [[Vec<u8>; MAX_WEDGE_TYPES]; 2] = Default::default();
174 for sign in 0..2 {267 for sign in 0..2 {
175 for idx in 0..MAX_WEDGE_TYPES {268 for idx in 0..MAX_WEDGE_TYPES {
176- let (neg_idx, dir, off) = wedge_window(master, idx, sign, bw, bh);269+ let (neg_idx, dir, off) = wedge_window(idx, sign, bw, bh);
177 let plane = &master.obl[neg_idx][dir];270 let plane = &master.obl[neg_idx][dir];
178- let mut m = vec![0u8; bw * bh];271+ let mut m = vec![0u8; stride * stride];
179 for i in 0..bh {272 for i in 0..bh {
180 let src = off + i * MASK_MASTER_SIZE;273 let src = off + i * MASK_MASTER_SIZE;
181- m[i * bw..i * bw + bw].copy_from_slice(&plane[src..src + bw]);274+ m[i * stride..i * stride + bw].copy_from_slice(&plane[src..src + bw]);
182 }275 }
183 masks[sign][idx] = m;276 masks[sign][idx] = m;
184 }277 }
185 }278 }
186- WedgeCodebook { masks, bw, bh }279+ WedgeCodebook { masks, bw, bh, stride }
187 }280 }
188 281
189 /// `wedge_sign` in `{0,1}` (spec `wedge_sign`), `wedge_index` in282 /// `wedge_sign` in `{0,1}` (spec `wedge_sign`), `wedge_index` in
190- /// `0..MAX_WEDGE_TYPES`. Mask is luma-resolution, row stride `bw`.283+ /// `0..MAX_WEDGE_TYPES`. Mask is luma-resolution, row stride
284+ /// [`Self::stride`] (`max(bw, bh)`), length `stride * stride`.
191 pub fn mask(&self, wedge_sign: usize, wedge_index: usize) -> &[u8] {285 pub fn mask(&self, wedge_sign: usize, wedge_index: usize) -> &[u8] {
192 &self.masks[wedge_sign][wedge_index]286 &self.masks[wedge_sign][wedge_index]
193 }287 }
194 }288 }
195 289
196-/// One codebook per reachable square leaf side (8/16/32), built once.290+/// One codebook per wedge-capable bsize, built once.
197 pub struct WedgeMasks {291 pub struct WedgeMasks {
198- pub side8: WedgeCodebook,292+ /// Parallel to [`WEDGE_BSIZES`].
199- pub side16: WedgeCodebook,293+ books: Vec<WedgeCodebook>,
200- pub side32: WedgeCodebook,
201 }294 }
202 295
203 impl WedgeMasks {296 impl WedgeMasks {
204 fn new() -> Self {297 fn new() -> Self {
205 let master = init_wedge_master_masks();298 let master = init_wedge_master_masks();
206 WedgeMasks {299 WedgeMasks {
207- side8: WedgeCodebook::build(&master, 8, 8),300+ books: WEDGE_BSIZES
208- side16: WedgeCodebook::build(&master, 16, 16),301+ .iter()
209- side32: WedgeCodebook::build(&master, 32, 32),302+ .map(|&(bw, bh)| WedgeCodebook::build(&master, bw, bh))
303+ .collect(),
210 }304 }
211 }305 }
212 306
213- /// `side` is the square leaf side (8/16/32); panics otherwise (same307+ /// `(bw, bh)` is the block's TRUE footprint; panics on a size libaom
214- /// invariant `decode.rs`'s `wedge_bsize` match already enforces).308+ /// gives no codebook (the same invariant `decode.rs`'s `wedge_used_bsize`
215- pub fn codebook(&self, side: usize) -> &WedgeCodebook {309+ /// already enforces before any wedge symbol is read).
216- match side {310+ pub fn codebook(&self, bw: usize, bh: usize) -> &WedgeCodebook {
217- 8 => &self.side8,311+ let i = WEDGE_BSIZES
218- 16 => &self.side16,312+ .iter()
219- 32 => &self.side32,313+ .position(|&s| s == (bw, bh))
220- _ => unreachable!("wedge codebook side is 8/16/32"),314+ .unwrap_or_else(|| unreachable!("no wedge codebook for {bw}x{bh}"));
221- }315+ &self.books[i]
222 }316 }
223 }317 }
224 318
@@ -228,13 +322,15 @@ pub fn wedge_masks() -> &'static WedgeMasks {
228 WEDGE_MASKS.get_or_init(WedgeMasks::new)322 WEDGE_MASKS.get_or_init(WedgeMasks::new)
229 }323 }
230 324
231-/// Reproduces `lanes/wedge_dump.c`'s `dump_bsize` checksum formula exactly.325+/// Reproduces the libaom-linked harness's per-block checksum formula
326+/// (`~/.cache/inter16ab-tmp/wedge_h.c`): the TRUE `bw x bh` window read out
327+/// of the padded plane, weighted by its contiguous position + 1.
232 #[cfg(test)]328 #[cfg(test)]
233-fn checksum(mask: &[u8], bw: usize, bh: usize) -> u64 {329+fn checksum(mask: &[u8], bw: usize, bh: usize, stride: usize) -> u64 {
234 let mut sum: u64 = 0;330 let mut sum: u64 = 0;
235 for i in 0..bh {331 for i in 0..bh {
236 for j in 0..bw {332 for j in 0..bw {
237- sum += mask[i * bw + j] as u64 * (i * bw + j + 1) as u64;333+ sum += mask[i * stride + j] as u64 * (i * bw + j + 1) as u64;
238 }334 }
239 }335 }
240 sum336 sum
@@ -244,44 +340,50 @@ fn checksum(mask: &[u8], bw: usize, bh: usize) -> u64 {
244 mod tests {340 mod tests {
245 use super::*;341 use super::*;
246 342
247- /// lane-wedge r3: checksum-verify every (bsize, sign, wedge_index) mask343+ /// lane-inter16ab r5 (class enumerate-table-domain): checksum-verify
248- /// this decoder can produce against `lanes/wedge_dump.c`'s independent344+ /// EVERY (bsize, sign, wedge_index) mask this decoder can produce --
249- /// C computation (`lanes/wedge_dump.expected.txt`, generated by345+ /// all 9 wedge-capable bsizes, both signs, all 16 indices = 288 entries
250- /// `gcc -O2 lanes/wedge_dump.c -o lanes/wedge_dump && ./lanes/wedge_dump`).346+ /// -- against `av1_get_contiguous_soft_mask()` read straight out of
347+ /// libaom by the linked C harness (`lanes/wedge_libaom.expected.txt`,
348+ /// regenerate with `gcc -O2 -o wedge_h wedge_h.c -I <aom-src> -I <aom-build>
349+ /// <aom-build>/libaom.a -lm -lpthread && ./wedge_h`).
251 #[test]350 #[test]
252- fn wedge_codebook_matches_c_dump() {351+ fn wedge_codebook_matches_libaom_dump() {
253- let expected_txt = std::fs::read_to_string(352+ let expected_txt = std::fs::read_to_string(concat!(
254- concat!(env!("CARGO_MANIFEST_DIR"), "/../../lanes/wedge_dump.expected.txt"),353+ env!("CARGO_MANIFEST_DIR"),
255- )354+ "/../../lanes/wedge_libaom.expected.txt"
256- .expect("run gcc -O2 lanes/wedge_dump.c -o lanes/wedge_dump && ./lanes/wedge_dump > lanes/wedge_dump.expected.txt first");355+ ))
356+ .expect("lanes/wedge_libaom.expected.txt (libaom-linked harness dump)");
257 let mut expected = std::collections::HashMap::new();357 let mut expected = std::collections::HashMap::new();
258 for line in expected_txt.lines() {358 for line in expected_txt.lines() {
259- // "8x8 sign=0 idx=0 checksum=39141"359+ // "16x8 sign=0 idx=0 checksum=39141"
260 let parts: Vec<&str> = line.split_whitespace().collect();360 let parts: Vec<&str> = line.split_whitespace().collect();
261- let name = parts[0];361+ let name = parts[0].to_string();
262 let sign: usize = parts[1]["sign=".len()..].parse().unwrap();362 let sign: usize = parts[1]["sign=".len()..].parse().unwrap();
263 let idx: usize = parts[2]["idx=".len()..].parse().unwrap();363 let idx: usize = parts[2]["idx=".len()..].parse().unwrap();
264 let cs: u64 = parts[3]["checksum=".len()..].parse().unwrap();364 let cs: u64 = parts[3]["checksum=".len()..].parse().unwrap();
265 expected.insert((name, sign, idx), cs);365 expected.insert((name, sign, idx), cs);
266 }366 }
367+ assert_eq!(expected.len(), 9 * 2 * MAX_WEDGE_TYPES, "the dump covers every entry");
267 let masks = wedge_masks();368 let masks = wedge_masks();
268 let mut checked = 0;369 let mut checked = 0;
269- for (name, side) in [("8x8", 8usize), ("16x16", 16), ("32x32", 32)] {370+ for (bw, bh) in WEDGE_BSIZES {
270- let cb = masks.codebook(side);371+ let name = format!("{bw}x{bh}");
372+ let cb = masks.codebook(bw, bh);
271 for sign in 0..2 {373 for sign in 0..2 {
272 for idx in 0..MAX_WEDGE_TYPES {374 for idx in 0..MAX_WEDGE_TYPES {
273- let got = checksum(cb.mask(sign, idx), side, side);375+ let got = checksum(cb.mask(sign, idx), bw, bh, cb.stride);
274- let want = *expected.get(&(name, sign, idx)).unwrap_or_else(|| {376+ let want = *expected.get(&(name.clone(), sign, idx)).unwrap_or_else(|| {
275 panic!("missing expected entry for {name} sign={sign} idx={idx}")377 panic!("missing expected entry for {name} sign={sign} idx={idx}")
276 });378 });
277 assert_eq!(379 assert_eq!(
278 got, want,380 got, want,
279- "{name} sign={sign} idx={idx}: rust checksum {got} != C dump {want}"381+ "{name} sign={sign} idx={idx}: rust checksum {got} != libaom {want}"
280 );382 );
281 checked += 1;383 checked += 1;
282 }384 }
283 }385 }
284 }386 }
285- assert_eq!(checked, 3 * 2 * MAX_WEDGE_TYPES, "checked every (bsize,sign,index) triple");387+ assert_eq!(checked, 9 * 2 * MAX_WEDGE_TYPES, "checked every (bsize,sign,index) triple");
286 }388 }
287 }389 }
lanes/wedge_libaom.expected.txtadded+288 -0
@@ -0,0 +1,288 @@
1+8x8 sign=0 idx=0 checksum=39141
2+8x8 sign=0 idx=1 checksum=52777
3+8x8 sign=0 idx=2 checksum=73817
4+8x8 sign=0 idx=3 checksum=41771
5+8x8 sign=0 idx=4 checksum=11976
6+8x8 sign=0 idx=5 checksum=77496
7+8x8 sign=0 idx=6 checksum=31072
8+8x8 sign=0 idx=7 checksum=96592
9+8x8 sign=0 idx=8 checksum=14128
10+8x8 sign=0 idx=9 checksum=76658
11+8x8 sign=0 idx=10 checksum=116594
12+8x8 sign=0 idx=11 checksum=79056
13+8x8 sign=0 idx=12 checksum=23207
14+8x8 sign=0 idx=13 checksum=85737
15+8x8 sign=0 idx=14 checksum=90729
16+8x8 sign=0 idx=15 checksum=104921
17+8x8 sign=1 idx=0 checksum=93979
18+8x8 sign=1 idx=1 checksum=80343
19+8x8 sign=1 idx=2 checksum=59303
20+8x8 sign=1 idx=3 checksum=91349
21+8x8 sign=1 idx=4 checksum=121144
22+8x8 sign=1 idx=5 checksum=55624
23+8x8 sign=1 idx=6 checksum=102048
24+8x8 sign=1 idx=7 checksum=36528
25+8x8 sign=1 idx=8 checksum=118992
26+8x8 sign=1 idx=9 checksum=56462
27+8x8 sign=1 idx=10 checksum=16526
28+8x8 sign=1 idx=11 checksum=54064
29+8x8 sign=1 idx=12 checksum=109913
30+8x8 sign=1 idx=13 checksum=47383
31+8x8 sign=1 idx=14 checksum=42391
32+8x8 sign=1 idx=15 checksum=28199
33+8x16 sign=0 idx=0 checksum=138816
34+8x16 sign=0 idx=1 checksum=178448
35+8x16 sign=0 idx=2 checksum=339952
36+8x16 sign=0 idx=3 checksum=141504
37+8x16 sign=0 idx=4 checksum=491264
38+8x16 sign=0 idx=5 checksum=136448
39+8x16 sign=0 idx=6 checksum=301312
40+8x16 sign=0 idx=7 checksum=256832
41+8x16 sign=0 idx=8 checksum=39477
42+8x16 sign=0 idx=9 checksum=303024
43+8x16 sign=0 idx=10 checksum=486248
44+8x16 sign=0 idx=11 checksum=305683
45+8x16 sign=0 idx=12 checksum=82066
46+8x16 sign=0 idx=13 checksum=298528
47+8x16 sign=0 idx=14 checksum=307134
48+8x16 sign=0 idx=15 checksum=437712
49+8x16 sign=1 idx=0 checksum=389568
50+8x16 sign=1 idx=1 checksum=349936
51+8x16 sign=1 idx=2 checksum=188432
52+8x16 sign=1 idx=3 checksum=386880
53+8x16 sign=1 idx=4 checksum=37120
54+8x16 sign=1 idx=5 checksum=391936
55+8x16 sign=1 idx=6 checksum=227072
56+8x16 sign=1 idx=7 checksum=271552
57+8x16 sign=1 idx=8 checksum=488907
58+8x16 sign=1 idx=9 checksum=225360
59+8x16 sign=1 idx=10 checksum=42136
60+8x16 sign=1 idx=11 checksum=222701
61+8x16 sign=1 idx=12 checksum=446318
62+8x16 sign=1 idx=13 checksum=229856
63+8x16 sign=1 idx=14 checksum=221250
64+8x16 sign=1 idx=15 checksum=90672
65+16x8 sign=0 idx=0 checksum=174226
66+16x8 sign=0 idx=1 checksum=227184
67+16x8 sign=0 idx=2 checksum=270192
68+16x8 sign=0 idx=3 checksum=194414
69+16x8 sign=0 idx=4 checksum=408160
70+16x8 sign=0 idx=5 checksum=248224
71+16x8 sign=0 idx=6 checksum=384416
72+16x8 sign=0 idx=7 checksum=146432
73+16x8 sign=0 idx=8 checksum=78414
74+16x8 sign=0 idx=9 checksum=294876
75+16x8 sign=0 idx=10 checksum=432572
76+16x8 sign=0 idx=11 checksum=312274
77+16x8 sign=0 idx=12 checksum=99695
78+16x8 sign=0 idx=13 checksum=363242
79+16x8 sign=0 idx=14 checksum=386145
80+16x8 sign=0 idx=15 checksum=405786
81+16x8 sign=1 idx=0 checksum=354158
82+16x8 sign=1 idx=1 checksum=301200
83+16x8 sign=1 idx=2 checksum=258192
84+16x8 sign=1 idx=3 checksum=333970
85+16x8 sign=1 idx=4 checksum=120224
86+16x8 sign=1 idx=5 checksum=280160
87+16x8 sign=1 idx=6 checksum=143968
88+16x8 sign=1 idx=7 checksum=381952
89+16x8 sign=1 idx=8 checksum=449970
90+16x8 sign=1 idx=9 checksum=233508
91+16x8 sign=1 idx=10 checksum=95812
92+16x8 sign=1 idx=11 checksum=216110
93+16x8 sign=1 idx=12 checksum=428689
94+16x8 sign=1 idx=13 checksum=165142
95+16x8 sign=1 idx=14 checksum=142239
96+16x8 sign=1 idx=15 checksum=122598
97+16x16 sign=0 idx=0 checksum=578432
98+16x16 sign=0 idx=1 checksum=849632
99+16x16 sign=0 idx=2 checksum=1197792
100+16x16 sign=0 idx=3 checksum=600192
101+16x16 sign=0 idx=4 checksum=146432
102+16x16 sign=0 idx=5 checksum=1199104
103+16x16 sign=0 idx=6 checksum=502592
104+16x16 sign=0 idx=7 checksum=1555264
105+16x16 sign=0 idx=8 checksum=182696
106+16x16 sign=0 idx=9 checksum=1219434
107+16x16 sign=0 idx=10 checksum=1901674
108+16x16 sign=0 idx=11 checksum=1240408
109+16x16 sign=0 idx=12 checksum=345191
110+16x16 sign=0 idx=13 checksum=1381929
111+16x16 sign=0 idx=14 checksum=1424569
112+16x16 sign=0 idx=15 checksum=1717513
113+16x16 sign=1 idx=0 checksum=1526912
114+16x16 sign=1 idx=1 checksum=1255712
115+16x16 sign=1 idx=2 checksum=907552
116+16x16 sign=1 idx=3 checksum=1505152
117+16x16 sign=1 idx=4 checksum=1958912
118+16x16 sign=1 idx=5 checksum=906240
119+16x16 sign=1 idx=6 checksum=1602752
120+16x16 sign=1 idx=7 checksum=550080
121+16x16 sign=1 idx=8 checksum=1922648
122+16x16 sign=1 idx=9 checksum=885910
123+16x16 sign=1 idx=10 checksum=203670
124+16x16 sign=1 idx=11 checksum=864936
125+16x16 sign=1 idx=12 checksum=1760153
126+16x16 sign=1 idx=13 checksum=723415
127+16x16 sign=1 idx=14 checksum=680775
128+16x16 sign=1 idx=15 checksum=387831
129+16x32 sign=0 idx=0 checksum=2155392
130+16x32 sign=0 idx=1 checksum=2791568
131+16x32 sign=0 idx=2 checksum=5528144
132+16x32 sign=0 idx=3 checksum=2177152
133+16x32 sign=0 idx=4 checksum=7863296
134+16x32 sign=0 idx=5 checksum=2118656
135+16x32 sign=0 idx=6 checksum=4744192
136+16x32 sign=0 idx=7 checksum=4138624
137+16x32 sign=0 idx=8 checksum=578432
138+16x32 sign=0 idx=9 checksum=4780928
139+16x32 sign=0 idx=10 checksum=7804800
140+16x32 sign=0 idx=11 checksum=4802688
141+16x32 sign=0 idx=12 checksum=1196718
142+16x32 sign=0 idx=13 checksum=4810290
143+16x32 sign=0 idx=14 checksum=4882770
144+16x32 sign=0 idx=15 checksum=7135794
145+16x32 sign=1 idx=0 checksum=6249600
146+16x32 sign=1 idx=1 checksum=5613424
147+16x32 sign=1 idx=2 checksum=2876848
148+16x32 sign=1 idx=3 checksum=6227840
149+16x32 sign=1 idx=4 checksum=541696
150+16x32 sign=1 idx=5 checksum=6286336
151+16x32 sign=1 idx=6 checksum=3660800
152+16x32 sign=1 idx=7 checksum=4266368
153+16x32 sign=1 idx=8 checksum=7826560
154+16x32 sign=1 idx=9 checksum=3624064
155+16x32 sign=1 idx=10 checksum=600192
156+16x32 sign=1 idx=11 checksum=3602304
157+16x32 sign=1 idx=12 checksum=7208274
158+16x32 sign=1 idx=13 checksum=3594702
159+16x32 sign=1 idx=14 checksum=3522222
160+16x32 sign=1 idx=15 checksum=1269198
161+32x16 sign=0 idx=0 checksum=2752498
162+32x16 sign=0 idx=1 checksum=3727072
163+32x16 sign=0 idx=2 checksum=4423392
164+32x16 sign=0 idx=3 checksum=2923534
165+32x16 sign=0 idx=4 checksum=6401216
166+32x16 sign=0 idx=5 checksum=4072256
167+32x16 sign=0 idx=6 checksum=6206272
168+32x16 sign=0 idx=7 checksum=2158592
169+32x16 sign=0 idx=8 checksum=1163358
170+32x16 sign=0 idx=9 checksum=4776930
171+32x16 sign=0 idx=10 checksum=7096290
172+32x16 sign=0 idx=11 checksum=4922274
173+32x16 sign=0 idx=12 checksum=1658592
174+32x16 sign=0 idx=13 checksum=5861088
175+32x16 sign=0 idx=14 checksum=6050080
176+32x16 sign=0 idx=15 checksum=6557408
177+32x16 sign=1 idx=0 checksum=5652494
178+32x16 sign=1 idx=1 checksum=4677920
179+32x16 sign=1 idx=2 checksum=3981600
180+32x16 sign=1 idx=3 checksum=5481458
181+32x16 sign=1 idx=4 checksum=2003776
182+32x16 sign=1 idx=5 checksum=4332736
183+32x16 sign=1 idx=6 checksum=2198720
184+32x16 sign=1 idx=7 checksum=6246400
185+32x16 sign=1 idx=8 checksum=7241634
186+32x16 sign=1 idx=9 checksum=3628062
187+32x16 sign=1 idx=10 checksum=1308702
188+32x16 sign=1 idx=11 checksum=3482718
189+32x16 sign=1 idx=12 checksum=6746400
190+32x16 sign=1 idx=13 checksum=2543904
191+32x16 sign=1 idx=14 checksum=2354912
192+32x16 sign=1 idx=15 checksum=1847584
193+32x32 sign=0 idx=0 checksum=9085696
194+32x32 sign=0 idx=1 checksum=13761984
195+32x32 sign=0 idx=2 checksum=19348928
196+32x32 sign=0 idx=3 checksum=9260288
197+32x32 sign=0 idx=4 checksum=2158592
198+32x32 sign=0 idx=5 checksum=18952192
199+32x32 sign=0 idx=6 checksum=8201856
200+32x32 sign=0 idx=7 checksum=24995456
201+32x32 sign=0 idx=8 checksum=2785176
202+32x32 sign=0 idx=9 checksum=19515226
203+32x32 sign=0 idx=10 checksum=30629210
204+32x32 sign=0 idx=11 checksum=19688040
205+32x32 sign=0 idx=12 checksum=5489895
206+32x32 sign=0 idx=13 checksum=22219945
207+32x32 sign=0 idx=14 checksum=22567257
208+32x32 sign=0 idx=15 checksum=27749993
209+32x32 sign=1 idx=0 checksum=24501504
210+32x32 sign=1 idx=1 checksum=19825216
211+32x32 sign=1 idx=2 checksum=14238272
212+32x32 sign=1 idx=3 checksum=24326912
213+32x32 sign=1 idx=4 checksum=31428608
214+32x32 sign=1 idx=5 checksum=14635008
215+32x32 sign=1 idx=6 checksum=25385344
216+32x32 sign=1 idx=7 checksum=8591744
217+32x32 sign=1 idx=8 checksum=30802024
218+32x32 sign=1 idx=9 checksum=14071974
219+32x32 sign=1 idx=10 checksum=2957990
220+32x32 sign=1 idx=11 checksum=13899160
221+32x32 sign=1 idx=12 checksum=28097305
222+32x32 sign=1 idx=13 checksum=11367255
223+32x32 sign=1 idx=14 checksum=11019943
224+32x32 sign=1 idx=15 checksum=5837207
225+8x32 sign=0 idx=0 checksum=534080
226+8x32 sign=0 idx=1 checksum=582912
227+8x32 sign=0 idx=2 checksum=1511680
228+8x32 sign=0 idx=3 checksum=536768
229+8x32 sign=0 idx=4 checksum=1968896
230+8x32 sign=0 idx=5 checksum=531712
231+8x32 sign=0 idx=6 checksum=1189120
232+8x32 sign=0 idx=7 checksum=1037952
233+8x32 sign=0 idx=8 checksum=1966528
234+8x32 sign=0 idx=9 checksum=1191488
235+8x32 sign=0 idx=10 checksum=1963840
236+8x32 sign=0 idx=11 checksum=1194176
237+8x32 sign=0 idx=12 checksum=352487
238+8x32 sign=0 idx=13 checksum=877538
239+8x32 sign=0 idx=14 checksum=888257
240+8x32 sign=0 idx=15 checksum=1742138
241+8x32 sign=1 idx=0 checksum=1571264
242+8x32 sign=1 idx=1 checksum=1522432
243+8x32 sign=1 idx=2 checksum=593664
244+8x32 sign=1 idx=3 checksum=1568576
245+8x32 sign=1 idx=4 checksum=136448
246+8x32 sign=1 idx=5 checksum=1573632
247+8x32 sign=1 idx=6 checksum=916224
248+8x32 sign=1 idx=7 checksum=1067392
249+8x32 sign=1 idx=8 checksum=138816
250+8x32 sign=1 idx=9 checksum=913856
251+8x32 sign=1 idx=10 checksum=141504
252+8x32 sign=1 idx=11 checksum=911168
253+8x32 sign=1 idx=12 checksum=1752857
254+8x32 sign=1 idx=13 checksum=1227806
255+8x32 sign=1 idx=14 checksum=1217087
256+8x32 sign=1 idx=15 checksum=363206
257+32x8 sign=0 idx=0 checksum=822592
258+32x8 sign=0 idx=1 checksum=945008
259+32x8 sign=0 idx=2 checksum=1031024
260+32x8 sign=0 idx=3 checksum=938688
261+32x8 sign=0 idx=4 checksum=1627744
262+32x8 sign=0 idx=5 checksum=987552
263+32x8 sign=0 idx=6 checksum=1530272
264+32x8 sign=0 idx=7 checksum=581632
265+32x8 sign=0 idx=8 checksum=564605
266+32x8 sign=0 idx=9 checksum=1089656
267+32x8 sign=0 idx=10 checksum=1432664
268+32x8 sign=0 idx=11 checksum=1197731
269+32x8 sign=0 idx=12 checksum=1670288
270+32x8 sign=0 idx=13 checksum=1487728
271+32x8 sign=0 idx=14 checksum=1584272
272+32x8 sign=0 idx=15 checksum=1573744
273+32x8 sign=1 idx=0 checksum=1282752
274+32x8 sign=1 idx=1 checksum=1160336
275+32x8 sign=1 idx=2 checksum=1074320
276+32x8 sign=1 idx=3 checksum=1166656
277+32x8 sign=1 idx=4 checksum=477600
278+32x8 sign=1 idx=5 checksum=1117792
279+32x8 sign=1 idx=6 checksum=575072
280+32x8 sign=1 idx=7 checksum=1523712
281+32x8 sign=1 idx=8 checksum=1540739
282+32x8 sign=1 idx=9 checksum=1015688
283+32x8 sign=1 idx=10 checksum=672680
284+32x8 sign=1 idx=11 checksum=907613
285+32x8 sign=1 idx=12 checksum=435056
286+32x8 sign=1 idx=13 checksum=617616
287+32x8 sign=1 idx=14 checksum=521072
288+32x8 sign=1 idx=15 checksum=531600