wip(av1): wedge mask codebook (square 8x8/16x16/32x32), checksum-verified vs independent C dump
Browse files at this commit99ff3913e8300c7e2fa7809fbc2b1bdedb93bea5Parent: 9cec3a25 changed files +567 -0
- crates/ec-av1/src/lib.rs +1 -0
- crates/ec-av1/src/wedge.rs +287 -0
- lanes/wedge-r3.charter.md +55 -0
- lanes/wedge_dump.c +128 -0
- lanes/wedge_dump.expected.txt +96 -0
crates/ec-av1/src/lib.rsmodified+1 -0
| @@ -34,3 +34,4 @@ pub mod stream; | |||
| 34 | pub mod tile; | 34 | pub mod tile; |
| 35 | pub mod transform; | 35 | pub mod transform; |
| 36 | mod warp; | 36 | mod warp; |
| 37 | +mod wedge; | ||
crates/ec-av1/src/wedge.rsadded+287 -0
| @@ -0,0 +1,287 @@ | |||
| 1 | +//! lane-wedge r3: `COMPOUND_WEDGE` mask codebook -- libaom | ||
| 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 this | ||
| 4 | +//! decoder's masked-compound leaves reach: square 8x8/16x16/32x32 | ||
| 5 | +//! (`decode.rs`'s `wedge_bsize` match on `side`). Every reachable square | ||
| 6 | +//! bsize uses the same libaom codebook row (`wedge_codebook_16_heqw`) and | ||
| 7 | +//! the same `wedge_signflip_lookup` row, so only ONE codebook/signflip | ||
| 8 | +//! table is ported (rect bsizes are not reachable yet -- charter scope). | ||
| 9 | +//! | ||
| 10 | +//! VERIFICATION (class shared-oracle-blindness): `lanes/wedge_dump.c` is a | ||
| 11 | +//! standalone C reimplementation of the same libaom source, compiled and | ||
| 12 | +//! run independently with `gcc` (not linked against this Rust code, not | ||
| 13 | +//! linked against libaom) -- it catches translation bugs (indexing, shift | ||
| 14 | +//! direction/sign, offset order) that a hand-transcribed-only table would | ||
| 15 | +//! not. `checksum()` below reproduces its exact per-block checksum | ||
| 16 | +//! formula; `wedge_codebook_matches_c_dump` asserts every (bsize, sign, | ||
| 17 | +//! index) checksum against `lanes/wedge_dump.expected.txt`. | ||
| 18 | + | ||
| 19 | +const MASK_MASTER_SIZE: usize = 64; | ||
| 20 | +const WEDGE_WEIGHT_BITS: u32 = 6; | ||
| 21 | +pub const MAX_WEDGE_TYPES: usize = 16; | ||
| 22 | + | ||
| 23 | +#[derive(Clone, Copy)] | ||
| 24 | +enum Dir { | ||
| 25 | + Horizontal = 0, | ||
| 26 | + Vertical = 1, | ||
| 27 | + Oblique27 = 2, | ||
| 28 | + Oblique63 = 3, | ||
| 29 | + Oblique117 = 4, | ||
| 30 | + Oblique153 = 5, | ||
| 31 | +} | ||
| 32 | +const N_DIR: usize = 6; | ||
| 33 | + | ||
| 34 | +const WEDGE_MASTER_OBLIQUE_ODD: [u8; MASK_MASTER_SIZE] = [ | ||
| 35 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 6, | ||
| 36 | + 18, 37, 53, 60, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
| 37 | + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
| 38 | +]; | ||
| 39 | +const WEDGE_MASTER_OBLIQUE_EVEN: [u8; MASK_MASTER_SIZE] = [ | ||
| 40 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 11, | ||
| 41 | + 27, 46, 58, 62, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
| 42 | + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
| 43 | +]; | ||
| 44 | +const WEDGE_MASTER_VERTICAL: [u8; MASK_MASTER_SIZE] = [ | ||
| 45 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 7, | ||
| 46 | + 21, 43, 57, 62, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
| 47 | + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
| 48 | +]; | ||
| 49 | + | ||
| 50 | +/// `wedge_codebook_16_heqw` (reconinter.c) -- (direction, x_offset, y_offset). | ||
| 51 | +const HEQW: [(Dir, i32, i32); MAX_WEDGE_TYPES] = [ | ||
| 52 | + (Dir::Oblique27, 4, 4), | ||
| 53 | + (Dir::Oblique63, 4, 4), | ||
| 54 | + (Dir::Oblique117, 4, 4), | ||
| 55 | + (Dir::Oblique153, 4, 4), | ||
| 56 | + (Dir::Horizontal, 4, 2), | ||
| 57 | + (Dir::Horizontal, 4, 6), | ||
| 58 | + (Dir::Vertical, 2, 4), | ||
| 59 | + (Dir::Vertical, 6, 4), | ||
| 60 | + (Dir::Oblique27, 4, 2), | ||
| 61 | + (Dir::Oblique27, 4, 6), | ||
| 62 | + (Dir::Oblique153, 4, 2), | ||
| 63 | + (Dir::Oblique153, 4, 6), | ||
| 64 | + (Dir::Oblique63, 2, 4), | ||
| 65 | + (Dir::Oblique63, 6, 4), | ||
| 66 | + (Dir::Oblique117, 2, 4), | ||
| 67 | + (Dir::Oblique117, 6, 4), | ||
| 68 | +]; | ||
| 69 | +/// `wedge_signflip_lookup` row shared by `BLOCK_8X8`/`BLOCK_16X16`/`BLOCK_32X32`. | ||
| 70 | +const SIGNFLIP: [u8; MAX_WEDGE_TYPES] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1]; | ||
| 71 | + | ||
| 72 | +/// `shift_copy` (reconinter.c) -- shift a `MASK_MASTER_SIZE`-wide row right | ||
| 73 | +/// (`shift >= 0`) or left, replicating the edge sample into the gap. | ||
| 74 | +fn shift_copy(src: &[u8; MASK_MASTER_SIZE], dst: &mut [u8], shift: i32) { | ||
| 75 | + let w = MASK_MASTER_SIZE; | ||
| 76 | + if shift >= 0 { | ||
| 77 | + let shift = shift as usize; | ||
| 78 | + dst[shift..w].copy_from_slice(&src[..w - shift]); | ||
| 79 | + dst[..shift].fill(src[0]); | ||
| 80 | + } else { | ||
| 81 | + let shift = (-shift) as usize; | ||
| 82 | + dst[..w - shift].copy_from_slice(&src[shift..]); | ||
| 83 | + dst[w - shift..].fill(src[w - 1]); | ||
| 84 | + } | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +/// `wedge_mask_obl[neg][direction]`, a flat `MASK_MASTER_SIZE`-square plane | ||
| 88 | +/// per (neg, direction). Built once by [`init_wedge_master_masks`]. | ||
| 89 | +struct MasterMasks { | ||
| 90 | + /// `[neg][direction] -> MASK_MASTER_SIZE * MASK_MASTER_SIZE` bytes. | ||
| 91 | + obl: [[Vec<u8>; N_DIR]; 2], | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +/// `init_wedge_master_masks` (reconinter.c) ported verbatim. | ||
| 95 | +fn init_wedge_master_masks() -> MasterMasks { | ||
| 96 | + let w = MASK_MASTER_SIZE; | ||
| 97 | + let stride = MASK_MASTER_SIZE; | ||
| 98 | + let mut obl: [[Vec<u8>; N_DIR]; 2] = Default::default(); | ||
| 99 | + for neg in 0..2 { | ||
| 100 | + for d in 0..N_DIR { | ||
| 101 | + obl[neg][d] = vec![0u8; w * w]; | ||
| 102 | + } | ||
| 103 | + } | ||
| 104 | + let mut shift = (w / 4) as i32; | ||
| 105 | + for i in (0..w).step_by(2) { | ||
| 106 | + { | ||
| 107 | + let row_start = i * stride; | ||
| 108 | + shift_copy( | ||
| 109 | + &WEDGE_MASTER_OBLIQUE_EVEN, | ||
| 110 | + &mut obl[0][Dir::Oblique63 as usize][row_start..row_start + w], | ||
| 111 | + shift, | ||
| 112 | + ); | ||
| 113 | + } | ||
| 114 | + shift -= 1; | ||
| 115 | + { | ||
| 116 | + let row_start = (i + 1) * stride; | ||
| 117 | + shift_copy( | ||
| 118 | + &WEDGE_MASTER_OBLIQUE_ODD, | ||
| 119 | + &mut obl[0][Dir::Oblique63 as usize][row_start..row_start + w], | ||
| 120 | + shift, | ||
| 121 | + ); | ||
| 122 | + } | ||
| 123 | + obl[0][Dir::Vertical as usize][i * stride..i * stride + w] | ||
| 124 | + .copy_from_slice(&WEDGE_MASTER_VERTICAL); | ||
| 125 | + obl[0][Dir::Vertical as usize][(i + 1) * stride..(i + 1) * stride + w] | ||
| 126 | + .copy_from_slice(&WEDGE_MASTER_VERTICAL); | ||
| 127 | + } | ||
| 128 | + for i in 0..w { | ||
| 129 | + for j in 0..w { | ||
| 130 | + let msk = obl[0][Dir::Oblique63 as usize][i * stride + j] as i32; | ||
| 131 | + obl[0][Dir::Oblique27 as usize][j * stride + i] = msk as u8; | ||
| 132 | + let flip = ((1i32 << WEDGE_WEIGHT_BITS) - msk) as u8; | ||
| 133 | + obl[0][Dir::Oblique117 as usize][i * stride + w - 1 - j] = flip; | ||
| 134 | + obl[0][Dir::Oblique153 as usize][(w - 1 - j) * stride + i] = flip; | ||
| 135 | + obl[1][Dir::Oblique63 as usize][i * stride + j] = flip; | ||
| 136 | + obl[1][Dir::Oblique27 as usize][j * stride + i] = flip; | ||
| 137 | + obl[1][Dir::Oblique117 as usize][i * stride + w - 1 - j] = msk as u8; | ||
| 138 | + obl[1][Dir::Oblique153 as usize][(w - 1 - j) * stride + i] = msk as u8; | ||
| 139 | + let mskx = obl[0][Dir::Vertical as usize][i * stride + j] as i32; | ||
| 140 | + obl[0][Dir::Horizontal as usize][j * stride + i] = mskx as u8; | ||
| 141 | + let flipx = ((1i32 << WEDGE_WEIGHT_BITS) - mskx) as u8; | ||
| 142 | + obl[1][Dir::Vertical as usize][i * stride + j] = flipx; | ||
| 143 | + obl[1][Dir::Horizontal as usize][j * stride + i] = flipx; | ||
| 144 | + } | ||
| 145 | + } | ||
| 146 | + MasterMasks { obl } | ||
| 147 | +} | ||
| 148 | + | ||
| 149 | +/// `get_wedge_mask_inplace` (reconinter.c): the `bw x bh` window of the | ||
| 150 | +/// master plane for this `(wedge_index, neg, bw, bh)`, still in | ||
| 151 | +/// `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) { | ||
| 153 | + let (dir, xo, yo) = HEQW[wedge_index]; | ||
| 154 | + let wsignflip = SIGNFLIP[wedge_index] as usize; | ||
| 155 | + let woff = (xo as usize * bw) >> 3; | ||
| 156 | + let hoff = (yo as usize * bh) >> 3; | ||
| 157 | + let _ = &master.obl[neg ^ wsignflip][dir as usize]; | ||
| 158 | + let row0 = MASK_MASTER_SIZE / 2 - hoff; | ||
| 159 | + let col0 = MASK_MASTER_SIZE / 2 - woff; | ||
| 160 | + (neg ^ wsignflip, dir as usize, row0 * MASK_MASTER_SIZE + col0) | ||
| 161 | +} | ||
| 162 | + | ||
| 163 | +/// Per-`(sign, wedge_index)` `bw x bh` mask, contiguous stride `bw`. | ||
| 164 | +pub struct WedgeCodebook { | ||
| 165 | + /// `[sign][wedge_index] -> bw*bh` bytes, row stride `bw`. | ||
| 166 | + masks: [[Vec<u8>; MAX_WEDGE_TYPES]; 2], | ||
| 167 | + pub bw: usize, | ||
| 168 | + pub bh: usize, | ||
| 169 | +} | ||
| 170 | + | ||
| 171 | +impl WedgeCodebook { | ||
| 172 | + fn build(master: &MasterMasks, bw: usize, bh: usize) -> Self { | ||
| 173 | + let mut masks: [[Vec<u8>; MAX_WEDGE_TYPES]; 2] = Default::default(); | ||
| 174 | + for sign in 0..2 { | ||
| 175 | + for idx in 0..MAX_WEDGE_TYPES { | ||
| 176 | + let (neg_idx, dir, off) = wedge_window(master, idx, sign, bw, bh); | ||
| 177 | + let plane = &master.obl[neg_idx][dir]; | ||
| 178 | + let mut m = vec![0u8; bw * bh]; | ||
| 179 | + for i in 0..bh { | ||
| 180 | + let src = off + i * MASK_MASTER_SIZE; | ||
| 181 | + m[i * bw..i * bw + bw].copy_from_slice(&plane[src..src + bw]); | ||
| 182 | + } | ||
| 183 | + masks[sign][idx] = m; | ||
| 184 | + } | ||
| 185 | + } | ||
| 186 | + WedgeCodebook { masks, bw, bh } | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + /// `wedge_sign` in `{0,1}` (spec `wedge_sign`), `wedge_index` in | ||
| 190 | + /// `0..MAX_WEDGE_TYPES`. Mask is luma-resolution, row stride `bw`. | ||
| 191 | + pub fn mask(&self, wedge_sign: usize, wedge_index: usize) -> &[u8] { | ||
| 192 | + &self.masks[wedge_sign][wedge_index] | ||
| 193 | + } | ||
| 194 | +} | ||
| 195 | + | ||
| 196 | +/// One codebook per reachable square leaf side (8/16/32), built once. | ||
| 197 | +pub struct WedgeMasks { | ||
| 198 | + pub side8: WedgeCodebook, | ||
| 199 | + pub side16: WedgeCodebook, | ||
| 200 | + pub side32: WedgeCodebook, | ||
| 201 | +} | ||
| 202 | + | ||
| 203 | +impl WedgeMasks { | ||
| 204 | + fn new() -> Self { | ||
| 205 | + let master = init_wedge_master_masks(); | ||
| 206 | + WedgeMasks { | ||
| 207 | + side8: WedgeCodebook::build(&master, 8, 8), | ||
| 208 | + side16: WedgeCodebook::build(&master, 16, 16), | ||
| 209 | + side32: WedgeCodebook::build(&master, 32, 32), | ||
| 210 | + } | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + /// `side` is the square leaf side (8/16/32); panics otherwise (same | ||
| 214 | + /// invariant `decode.rs`'s `wedge_bsize` match already enforces). | ||
| 215 | + pub fn codebook(&self, side: usize) -> &WedgeCodebook { | ||
| 216 | + match side { | ||
| 217 | + 8 => &self.side8, | ||
| 218 | + 16 => &self.side16, | ||
| 219 | + 32 => &self.side32, | ||
| 220 | + _ => unreachable!("wedge codebook side is 8/16/32"), | ||
| 221 | + } | ||
| 222 | + } | ||
| 223 | +} | ||
| 224 | + | ||
| 225 | +static WEDGE_MASKS: std::sync::OnceLock<WedgeMasks> = std::sync::OnceLock::new(); | ||
| 226 | + | ||
| 227 | +pub fn wedge_masks() -> &'static WedgeMasks { | ||
| 228 | + WEDGE_MASKS.get_or_init(WedgeMasks::new) | ||
| 229 | +} | ||
| 230 | + | ||
| 231 | +/// Reproduces `lanes/wedge_dump.c`'s `dump_bsize` checksum formula exactly. | ||
| 232 | +#[cfg(test)] | ||
| 233 | +fn checksum(mask: &[u8], bw: usize, bh: usize) -> u64 { | ||
| 234 | + let mut sum: u64 = 0; | ||
| 235 | + for i in 0..bh { | ||
| 236 | + for j in 0..bw { | ||
| 237 | + sum += mask[i * bw + j] as u64 * (i * bw + j + 1) as u64; | ||
| 238 | + } | ||
| 239 | + } | ||
| 240 | + sum | ||
| 241 | +} | ||
| 242 | + | ||
| 243 | +#[cfg(test)] | ||
| 244 | +mod tests { | ||
| 245 | + use super::*; | ||
| 246 | + | ||
| 247 | + /// lane-wedge r3: checksum-verify every (bsize, sign, wedge_index) mask | ||
| 248 | + /// this decoder can produce against `lanes/wedge_dump.c`'s independent | ||
| 249 | + /// C computation (`lanes/wedge_dump.expected.txt`, generated by | ||
| 250 | + /// `gcc -O2 lanes/wedge_dump.c -o lanes/wedge_dump && ./lanes/wedge_dump`). | ||
| 251 | + #[test] | ||
| 252 | + fn wedge_codebook_matches_c_dump() { | ||
| 253 | + let expected_txt = std::fs::read_to_string( | ||
| 254 | + concat!(env!("CARGO_MANIFEST_DIR"), "/../../lanes/wedge_dump.expected.txt"), | ||
| 255 | + ) | ||
| 256 | + .expect("run gcc -O2 lanes/wedge_dump.c -o lanes/wedge_dump && ./lanes/wedge_dump > lanes/wedge_dump.expected.txt first"); | ||
| 257 | + let mut expected = std::collections::HashMap::new(); | ||
| 258 | + for line in expected_txt.lines() { | ||
| 259 | + // "8x8 sign=0 idx=0 checksum=39141" | ||
| 260 | + let parts: Vec<&str> = line.split_whitespace().collect(); | ||
| 261 | + let name = parts[0]; | ||
| 262 | + let sign: usize = parts[1]["sign=".len()..].parse().unwrap(); | ||
| 263 | + let idx: usize = parts[2]["idx=".len()..].parse().unwrap(); | ||
| 264 | + let cs: u64 = parts[3]["checksum=".len()..].parse().unwrap(); | ||
| 265 | + expected.insert((name, sign, idx), cs); | ||
| 266 | + } | ||
| 267 | + let masks = wedge_masks(); | ||
| 268 | + let mut checked = 0; | ||
| 269 | + for (name, side) in [("8x8", 8usize), ("16x16", 16), ("32x32", 32)] { | ||
| 270 | + let cb = masks.codebook(side); | ||
| 271 | + for sign in 0..2 { | ||
| 272 | + for idx in 0..MAX_WEDGE_TYPES { | ||
| 273 | + let got = checksum(cb.mask(sign, idx), side, side); | ||
| 274 | + let want = *expected.get(&(name, sign, idx)).unwrap_or_else(|| { | ||
| 275 | + panic!("missing expected entry for {name} sign={sign} idx={idx}") | ||
| 276 | + }); | ||
| 277 | + assert_eq!( | ||
| 278 | + got, want, | ||
| 279 | + "{name} sign={sign} idx={idx}: rust checksum {got} != C dump {want}" | ||
| 280 | + ); | ||
| 281 | + checked += 1; | ||
| 282 | + } | ||
| 283 | + } | ||
| 284 | + } | ||
| 285 | + assert_eq!(checked, 3 * 2 * MAX_WEDGE_TYPES, "checked every (bsize,sign,index) triple"); | ||
| 286 | + } | ||
| 287 | +} | ||
lanes/wedge-r3.charter.mdadded+55 -0
| @@ -0,0 +1,55 @@ | |||
| 1 | +# lane-wedge r3 charter — wedge mask codebook: masked-compound COMPOUND_WEDGE blend | ||
| 2 | + | ||
| 3 | +## Where you are | ||
| 4 | +Worktree /home/user/Documents/Code/Rust/edith_codecs-wedge, branch lane-wedge @ f9f9767. | ||
| 5 | +Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-wedge cargo test -p ec-av1 --release --lib <name> -- --nocapture` | ||
| 6 | +FOREGROUND, `nice -n 19`, `CARGO_BUILD_JOBS=4`. Never push; never touch other worktrees; fixtures/ is a symlink. | ||
| 7 | +BUDGET: ~75 calls. Commit compiling WIP + report by call 60. Read only what is named. | ||
| 8 | + | ||
| 9 | +## Read first | ||
| 10 | +1. lanes/maskcomp-r2.report.md — DIFFWTD blend landed (mc.rs diffwtd_mask/ | ||
| 11 | + blend_masked_compound on the unbiased i32 intermediate domain; the libaom | ||
| 12 | + round_offset bias cancels — REUSE blend_masked_compound, only the MASK differs). | ||
| 13 | +2. crates/ec-av1/src/decode.rs — the two comp_group_idx==1 sites (grep | ||
| 14 | + COMPOUND_WEDGE): wedge_idx/wedge_sign are already consumed; the WEDGE branch | ||
| 15 | + refuses by name. That refusal is what you replace. | ||
| 16 | +3. libaom /tmp/libaom-src/av1/common/reconinter.c: av1_wedge_params_lookup, | ||
| 17 | + init_wedge_master_masks, init_wedge_masks, get_wedge_mask_inplace, | ||
| 18 | + wedge_master_oblique_odd/even + the smoother; av1_get_compound_type_mask. | ||
| 19 | + Chroma: av1_build_compound_diffwtd_mask usage in reconinter decode path shows how | ||
| 20 | + chroma reads the mask — check whether chroma SUBSAMPLES the luma-size mask | ||
| 21 | + (aom_blend_a64_mask with subw/subh) vs builds its own; port exactly. | ||
| 22 | + | ||
| 23 | +## VERIFICATION IS THE LANE (class shared-oracle-blindness) | ||
| 24 | +A hand-transcribed wedge codebook is worthless unverified. BEFORE wiring the blend: | ||
| 25 | +patch a dump into libaom (e.g. in av1_get_compound_type_mask or init_wedge_masks) | ||
| 26 | +printing mask bytes for (bsize, wedge_index, wedge_sign) triples, rebuild | ||
| 27 | +/tmp/libaom-build (ninja -C /tmp/libaom-build aomdec), and diff your Rust masks | ||
| 28 | +against it for EVERY (bsize in the used set) x (16 indices) x (2 signs) — a unit | ||
| 29 | +test embedding a hash/checksum of the C dump per bsize is the deliverable proving it. | ||
| 30 | + | ||
| 31 | +## Scope | ||
| 32 | +1. Build the master masks + per-bsize codebook (8x8..32x32 wedge-used bsizes; check | ||
| 33 | + av1_is_wedge_used for the exact set this decoder reaches — 16x16/32x32 today, | ||
| 34 | + plus 8x8 leaf, plus rect bsizes ONLY if reachable, which they are not yet). | ||
| 35 | +2. Replace the COMPOUND_WEDGE refusal at both sites with the blend | ||
| 36 | + (blend_masked_compound with the wedge mask; chroma per libaom subsampling). | ||
| 37 | +3. Gate: a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact currently | ||
| 38 | + never saw aomenc pick COMPOUND_WEDGE (640 attempts, gradients recipe). Find a | ||
| 39 | + recipe that fires it: try --enable-dist-wtd-comp=0 (forces masked choice toward | ||
| 40 | + wedge), noisier/structured content (the y4m synth in the gate — check what lavfi | ||
| 41 | + source it uses; a hard diagonal edge favors wedge), or higher cq. Prove arrival | ||
| 42 | + with a WEDGE_HITS atomic (add it). Then: wedge refusal FORBIDDEN, hits asserted | ||
| 43 | + (soft-skip on zero-hit runs like the maskcomp gate does), hammer 6x with | ||
| 44 | + EC_AV1_GATE_DUMP self-pin (/tmp/claude-1000/wedge-flake-N.obu). Mismatch → pin + | ||
| 45 | + localize (recon dump → range ladder exact ⇒ your mask; dump mask bytes both sides). | ||
| 46 | +4. 11-pin default list + full lib suite stay green. | ||
| 47 | + | ||
| 48 | +## Done criteria | ||
| 49 | +1. Codebook checksum-verified vs C dump (unit test); gate green with wedge hits | ||
| 50 | + actually fired, 6/6; pins green; lib green. | ||
| 51 | +2. Committed to lane-wedge (wip commits after every green milestone); REPORT | ||
| 52 | + lanes/wedge-r3.report.md, verdict FIRST line. | ||
| 53 | +If no recipe fires COMPOUND_WEDGE live: land the checksum-verified codebook + blend | ||
| 54 | +with the gate's soft path and report the recipe search as the residue — verified- | ||
| 55 | +but-unfired is honest; unverified is not landable. | ||
lanes/wedge_dump.cadded+128 -0
| @@ -0,0 +1,128 @@ | |||
| 1 | +/* lane-wedge r3: standalone C reimplementation of libaom | ||
| 2 | + * av1/common/reconinter.c's wedge master-mask + per-block codebook | ||
| 3 | + * derivation (wedge_master_oblique_odd/even, wedge_master_vertical, | ||
| 4 | + * shift_copy, init_wedge_master_masks, get_wedge_mask_inplace, | ||
| 5 | + * init_wedge_masks), transcribed verbatim from the source read this round. | ||
| 6 | + * Compiled and run independently of the Rust port to catch translation | ||
| 7 | + * bugs (indexing, shift direction, sign) even though the table DATA is | ||
| 8 | + * shared with the source -- see charter's shared-oracle-blindness note. | ||
| 9 | + */ | ||
| 10 | +#include <stdio.h> | ||
| 11 | +#include <stdint.h> | ||
| 12 | +#include <string.h> | ||
| 13 | + | ||
| 14 | +#define MASK_MASTER_SIZE 64 | ||
| 15 | +#define MASK_MASTER_STRIDE 64 | ||
| 16 | +#define WEDGE_WEIGHT_BITS 6 | ||
| 17 | +#define MAX_WEDGE_TYPES 16 | ||
| 18 | + | ||
| 19 | +enum { WEDGE_HORIZONTAL = 0, WEDGE_VERTICAL, WEDGE_OBLIQUE27, WEDGE_OBLIQUE63, | ||
| 20 | + WEDGE_OBLIQUE117, WEDGE_OBLIQUE153, WEDGE_DIRECTIONS }; | ||
| 21 | + | ||
| 22 | +static const uint8_t wedge_master_oblique_odd[MASK_MASTER_SIZE] = { | ||
| 23 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 24 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 6, 18, | ||
| 25 | + 37, 53, 60, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
| 26 | + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
| 27 | +}; | ||
| 28 | +static const uint8_t wedge_master_oblique_even[MASK_MASTER_SIZE] = { | ||
| 29 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 30 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 11, 27, | ||
| 31 | + 46, 58, 62, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
| 32 | + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
| 33 | +}; | ||
| 34 | +static const uint8_t wedge_master_vertical[MASK_MASTER_SIZE] = { | ||
| 35 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 36 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 7, 21, | ||
| 37 | + 43, 57, 62, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
| 38 | + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
| 39 | +}; | ||
| 40 | + | ||
| 41 | +static void shift_copy(const uint8_t *src, uint8_t *dst, int shift, int width) { | ||
| 42 | + if (shift >= 0) { | ||
| 43 | + memcpy(dst + shift, src, width - shift); | ||
| 44 | + memset(dst, src[0], shift); | ||
| 45 | + } else { | ||
| 46 | + shift = -shift; | ||
| 47 | + memcpy(dst, src + shift, width - shift); | ||
| 48 | + memset(dst + width - shift, src[width - 1], shift); | ||
| 49 | + } | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +static uint8_t wedge_mask_obl[2][WEDGE_DIRECTIONS][MASK_MASTER_SIZE * MASK_MASTER_SIZE]; | ||
| 53 | + | ||
| 54 | +static void init_wedge_master_masks(void) { | ||
| 55 | + int i, j; | ||
| 56 | + const int w = MASK_MASTER_SIZE, h = MASK_MASTER_SIZE, stride = MASK_MASTER_STRIDE; | ||
| 57 | + int shift = h / 4; | ||
| 58 | + for (i = 0; i < h; i += 2) { | ||
| 59 | + shift_copy(wedge_master_oblique_even, &wedge_mask_obl[0][WEDGE_OBLIQUE63][i * stride], shift, MASK_MASTER_SIZE); | ||
| 60 | + shift--; | ||
| 61 | + shift_copy(wedge_master_oblique_odd, &wedge_mask_obl[0][WEDGE_OBLIQUE63][(i + 1) * stride], shift, MASK_MASTER_SIZE); | ||
| 62 | + memcpy(&wedge_mask_obl[0][WEDGE_VERTICAL][i * stride], wedge_master_vertical, MASK_MASTER_SIZE); | ||
| 63 | + memcpy(&wedge_mask_obl[0][WEDGE_VERTICAL][(i + 1) * stride], wedge_master_vertical, MASK_MASTER_SIZE); | ||
| 64 | + } | ||
| 65 | + for (i = 0; i < h; ++i) { | ||
| 66 | + for (j = 0; j < w; ++j) { | ||
| 67 | + const int msk = wedge_mask_obl[0][WEDGE_OBLIQUE63][i * stride + j]; | ||
| 68 | + wedge_mask_obl[0][WEDGE_OBLIQUE27][j * stride + i] = msk; | ||
| 69 | + wedge_mask_obl[0][WEDGE_OBLIQUE117][i * stride + w - 1 - j] = | ||
| 70 | + wedge_mask_obl[0][WEDGE_OBLIQUE153][(w - 1 - j) * stride + i] = (1 << WEDGE_WEIGHT_BITS) - msk; | ||
| 71 | + wedge_mask_obl[1][WEDGE_OBLIQUE63][i * stride + j] = | ||
| 72 | + wedge_mask_obl[1][WEDGE_OBLIQUE27][j * stride + i] = (1 << WEDGE_WEIGHT_BITS) - msk; | ||
| 73 | + wedge_mask_obl[1][WEDGE_OBLIQUE117][i * stride + w - 1 - j] = | ||
| 74 | + wedge_mask_obl[1][WEDGE_OBLIQUE153][(w - 1 - j) * stride + i] = msk; | ||
| 75 | + const int mskx = wedge_mask_obl[0][WEDGE_VERTICAL][i * stride + j]; | ||
| 76 | + wedge_mask_obl[0][WEDGE_HORIZONTAL][j * stride + i] = mskx; | ||
| 77 | + wedge_mask_obl[1][WEDGE_VERTICAL][i * stride + j] = | ||
| 78 | + wedge_mask_obl[1][WEDGE_HORIZONTAL][j * stride + i] = (1 << WEDGE_WEIGHT_BITS) - mskx; | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +typedef struct { int direction, x_offset, y_offset; } wedge_code_type; | ||
| 84 | + | ||
| 85 | +/* wedge_codebook_16_heqw -- the ONLY codebook this decoder's reachable | ||
| 86 | + * (square 8x8/16x16/32x32) leaves use. */ | ||
| 87 | +static const wedge_code_type heqw[16] = { | ||
| 88 | + { WEDGE_OBLIQUE27, 4, 4 }, { WEDGE_OBLIQUE63, 4, 4 }, | ||
| 89 | + { WEDGE_OBLIQUE117, 4, 4 }, { WEDGE_OBLIQUE153, 4, 4 }, | ||
| 90 | + { WEDGE_HORIZONTAL, 4, 2 }, { WEDGE_HORIZONTAL, 4, 6 }, | ||
| 91 | + { WEDGE_VERTICAL, 2, 4 }, { WEDGE_VERTICAL, 6, 4 }, | ||
| 92 | + { WEDGE_OBLIQUE27, 4, 2 }, { WEDGE_OBLIQUE27, 4, 6 }, | ||
| 93 | + { WEDGE_OBLIQUE153, 4, 2 }, { WEDGE_OBLIQUE153, 4, 6 }, | ||
| 94 | + { WEDGE_OBLIQUE63, 2, 4 }, { WEDGE_OBLIQUE63, 6, 4 }, | ||
| 95 | + { WEDGE_OBLIQUE117, 2, 4 }, { WEDGE_OBLIQUE117, 6, 4 }, | ||
| 96 | +}; | ||
| 97 | +/* wedge_signflip_lookup rows for BLOCK_8X8/16X16/32X32 -- identical row. */ | ||
| 98 | +static const uint8_t signflip[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1 }; | ||
| 99 | + | ||
| 100 | +static const uint8_t *get_wedge_mask_inplace(int wedge_index, int neg, int bw, int bh) { | ||
| 101 | + const wedge_code_type *a = &heqw[wedge_index]; | ||
| 102 | + const uint8_t wsignflip = signflip[wedge_index]; | ||
| 103 | + int woff = (a->x_offset * bw) >> 3; | ||
| 104 | + int hoff = (a->y_offset * bh) >> 3; | ||
| 105 | + return wedge_mask_obl[neg ^ wsignflip][a->direction] + | ||
| 106 | + MASK_MASTER_STRIDE * (MASK_MASTER_SIZE / 2 - hoff) + MASK_MASTER_SIZE / 2 - woff; | ||
| 107 | +} | ||
| 108 | + | ||
| 109 | +static void dump_bsize(const char *name, int bw, int bh) { | ||
| 110 | + for (int sign = 0; sign < 2; ++sign) { | ||
| 111 | + for (int w = 0; w < MAX_WEDGE_TYPES; ++w) { | ||
| 112 | + const uint8_t *mask = get_wedge_mask_inplace(w, sign, bw, bh); | ||
| 113 | + uint64_t sum = 0; | ||
| 114 | + for (int i = 0; i < bh; ++i) | ||
| 115 | + for (int j = 0; j < bw; ++j) | ||
| 116 | + sum += (uint64_t)mask[i * MASK_MASTER_STRIDE + j] * (uint64_t)(i * bw + j + 1); | ||
| 117 | + printf("%s sign=%d idx=%d checksum=%llu\n", name, sign, w, (unsigned long long)sum); | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | +} | ||
| 121 | + | ||
| 122 | +int main(void) { | ||
| 123 | + init_wedge_master_masks(); | ||
| 124 | + dump_bsize("8x8", 8, 8); | ||
| 125 | + dump_bsize("16x16", 16, 16); | ||
| 126 | + dump_bsize("32x32", 32, 32); | ||
| 127 | + return 0; | ||
| 128 | +} | ||
lanes/wedge_dump.expected.txtadded+96 -0
| @@ -0,0 +1,96 @@ | |||
| 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 | +16x16 sign=0 idx=0 checksum=578432 | ||
| 34 | +16x16 sign=0 idx=1 checksum=849632 | ||
| 35 | +16x16 sign=0 idx=2 checksum=1197792 | ||
| 36 | +16x16 sign=0 idx=3 checksum=600192 | ||
| 37 | +16x16 sign=0 idx=4 checksum=146432 | ||
| 38 | +16x16 sign=0 idx=5 checksum=1199104 | ||
| 39 | +16x16 sign=0 idx=6 checksum=502592 | ||
| 40 | +16x16 sign=0 idx=7 checksum=1555264 | ||
| 41 | +16x16 sign=0 idx=8 checksum=182696 | ||
| 42 | +16x16 sign=0 idx=9 checksum=1219434 | ||
| 43 | +16x16 sign=0 idx=10 checksum=1901674 | ||
| 44 | +16x16 sign=0 idx=11 checksum=1240408 | ||
| 45 | +16x16 sign=0 idx=12 checksum=345191 | ||
| 46 | +16x16 sign=0 idx=13 checksum=1381929 | ||
| 47 | +16x16 sign=0 idx=14 checksum=1424569 | ||
| 48 | +16x16 sign=0 idx=15 checksum=1717513 | ||
| 49 | +16x16 sign=1 idx=0 checksum=1526912 | ||
| 50 | +16x16 sign=1 idx=1 checksum=1255712 | ||
| 51 | +16x16 sign=1 idx=2 checksum=907552 | ||
| 52 | +16x16 sign=1 idx=3 checksum=1505152 | ||
| 53 | +16x16 sign=1 idx=4 checksum=1958912 | ||
| 54 | +16x16 sign=1 idx=5 checksum=906240 | ||
| 55 | +16x16 sign=1 idx=6 checksum=1602752 | ||
| 56 | +16x16 sign=1 idx=7 checksum=550080 | ||
| 57 | +16x16 sign=1 idx=8 checksum=1922648 | ||
| 58 | +16x16 sign=1 idx=9 checksum=885910 | ||
| 59 | +16x16 sign=1 idx=10 checksum=203670 | ||
| 60 | +16x16 sign=1 idx=11 checksum=864936 | ||
| 61 | +16x16 sign=1 idx=12 checksum=1760153 | ||
| 62 | +16x16 sign=1 idx=13 checksum=723415 | ||
| 63 | +16x16 sign=1 idx=14 checksum=680775 | ||
| 64 | +16x16 sign=1 idx=15 checksum=387831 | ||
| 65 | +32x32 sign=0 idx=0 checksum=9085696 | ||
| 66 | +32x32 sign=0 idx=1 checksum=13761984 | ||
| 67 | +32x32 sign=0 idx=2 checksum=19348928 | ||
| 68 | +32x32 sign=0 idx=3 checksum=9260288 | ||
| 69 | +32x32 sign=0 idx=4 checksum=2158592 | ||
| 70 | +32x32 sign=0 idx=5 checksum=18952192 | ||
| 71 | +32x32 sign=0 idx=6 checksum=8201856 | ||
| 72 | +32x32 sign=0 idx=7 checksum=24995456 | ||
| 73 | +32x32 sign=0 idx=8 checksum=2785176 | ||
| 74 | +32x32 sign=0 idx=9 checksum=19515226 | ||
| 75 | +32x32 sign=0 idx=10 checksum=30629210 | ||
| 76 | +32x32 sign=0 idx=11 checksum=19688040 | ||
| 77 | +32x32 sign=0 idx=12 checksum=5489895 | ||
| 78 | +32x32 sign=0 idx=13 checksum=22219945 | ||
| 79 | +32x32 sign=0 idx=14 checksum=22567257 | ||
| 80 | +32x32 sign=0 idx=15 checksum=27749993 | ||
| 81 | +32x32 sign=1 idx=0 checksum=24501504 | ||
| 82 | +32x32 sign=1 idx=1 checksum=19825216 | ||
| 83 | +32x32 sign=1 idx=2 checksum=14238272 | ||
| 84 | +32x32 sign=1 idx=3 checksum=24326912 | ||
| 85 | +32x32 sign=1 idx=4 checksum=31428608 | ||
| 86 | +32x32 sign=1 idx=5 checksum=14635008 | ||
| 87 | +32x32 sign=1 idx=6 checksum=25385344 | ||
| 88 | +32x32 sign=1 idx=7 checksum=8591744 | ||
| 89 | +32x32 sign=1 idx=8 checksum=30802024 | ||
| 90 | +32x32 sign=1 idx=9 checksum=14071974 | ||
| 91 | +32x32 sign=1 idx=10 checksum=2957990 | ||
| 92 | +32x32 sign=1 idx=11 checksum=13899160 | ||
| 93 | +32x32 sign=1 idx=12 checksum=28097305 | ||
| 94 | +32x32 sign=1 idx=13 checksum=11367255 | ||
| 95 | +32x32 sign=1 idx=14 checksum=11019943 | ||
| 96 | +32x32 sign=1 idx=15 checksum=5837207 | ||