Merge lane-av1pixprobe: EC_AV1_PIXPROBE write probe + the byte-identical diffwtd_mask cast move
Browse files at this commit3 changed files +620 -8
- crates/ec-av1/src/decode.rs +64 -4
- crates/ec-av1/src/mc.rs +218 -4
- lanes/av1pixprobe.report.md +338 -0
crates/ec-av1/src/decode.rsmodified+64 -4
| @@ -20432,6 +20432,42 @@ struct PlaneBuf<'a> { | ||
| 20432 | 20432 | /// (lane-av1refs: the same "empty slot" case `GOLDEN_FRAME` already |
| 20433 | 20433 | /// refused by name, now generic across `LAST2`/`LAST3`/`GOLDEN`/`BWDREF`/ |
| 20434 | 20434 | /// `ALTREF2`/`ALTREF`). |
| 20435 | +// lane-av1pixprobe: env-gated one-sample write probe -- `EC_AV1_PIXPROBE=x,y` | |
| 20436 | +// prints one PIXWRITE line per reconstruction store landing on that sample, | |
| 20437 | +// naming the store site, the value it replaces and the one it leaves. Re-anchored | |
| 20438 | +// from `lane-av1-ibcwrite` @ 25f5c729 onto the main-shape sites (the two mc stores | |
| 20439 | +// now live in `reconstruct_mc_rect`). | |
| 20440 | +static PIXPROBE_ON: std::sync::LazyLock<bool> = | |
| 20441 | + std::sync::LazyLock::new(|| std::env::var_os("EC_AV1_PIXPROBE").is_some()); | |
| 20442 | + | |
| 20443 | +static PIXPROBE: std::sync::LazyLock<Option<(usize, usize)>> = std::sync::LazyLock::new(|| { | |
| 20444 | + crate::envflags::var("EC_AV1_PIXPROBE").ok().and_then(|v| { | |
| 20445 | + let (x, y) = v.split_once(',')?; | |
| 20446 | + Some(( | |
| 20447 | + x.trim().parse::<usize>().ok()?, | |
| 20448 | + y.trim().parse::<usize>().ok()?, | |
| 20449 | + )) | |
| 20450 | + }) | |
| 20451 | +}); | |
| 20452 | + | |
| 20453 | +#[inline] | |
| 20454 | +fn pix_write( | |
| 20455 | + site: &str, | |
| 20456 | + bx: usize, | |
| 20457 | + by: usize, | |
| 20458 | + bside: usize, | |
| 20459 | + x: usize, | |
| 20460 | + y: usize, | |
| 20461 | + prev: u16, | |
| 20462 | + val: u16, | |
| 20463 | +) { | |
| 20464 | + if *PIXPROBE_ON && Some((x, y)) == *PIXPROBE { | |
| 20465 | + eprintln!( | |
| 20466 | + "PIXWRITE {site} block=({bx},{by})+{bside} px=({x},{y}) prev={prev} val={val} at {}", | |
| 20467 | + std::panic::Location::caller() | |
| 20468 | + ); | |
| 20469 | + } | |
| 20470 | +} | |
| 20435 | 20471 | |
| 20436 | 20472 | impl PlaneBuf<'_> { |
| 20437 | 20473 | /// Sets this plane's own tile pixel origin ([`Self::tile_x0`]/ |
| @@ -20636,6 +20672,16 @@ impl PlaneBuf<'_> { | ||
| 20636 | 20672 | base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, sample_max(fctx)); |
| 20637 | 20673 | } |
| 20638 | 20674 | let sample = (base + residual[idx]).clamp(0, sample_max(fctx)) as u16; |
| 20675 | + pix_write( | |
| 20676 | + "reconstruct_rect", | |
| 20677 | + x, | |
| 20678 | + y, | |
| 20679 | + bw, | |
| 20680 | + x + col, | |
| 20681 | + y + row, | |
| 20682 | + self.data[(y + row) * self.width + x + col], | |
| 20683 | + sample, | |
| 20684 | + ); | |
| 20639 | 20685 | self.data.to_mut()[(y + row) * self.width + x + col] = sample; |
| 20640 | 20686 | } |
| 20641 | 20687 | } |
| @@ -20782,6 +20828,16 @@ impl PlaneBuf<'_> { | ||
| 20782 | 20828 | base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, sample_max(fctx)); |
| 20783 | 20829 | } |
| 20784 | 20830 | let sample = (base + residual[idx]).clamp(0, sample_max(fctx)) as u16; |
| 20831 | + pix_write( | |
| 20832 | + "reconstruct", | |
| 20833 | + x, | |
| 20834 | + y, | |
| 20835 | + side, | |
| 20836 | + x + col, | |
| 20837 | + y + row, | |
| 20838 | + self.data[(y + row) * self.width + x + col], | |
| 20839 | + sample, | |
| 20840 | + ); | |
| 20785 | 20841 | self.data.to_mut()[(y + row) * self.width + x + col] = sample; |
| 20786 | 20842 | } |
| 20787 | 20843 | } |
| @@ -36521,8 +36577,10 @@ impl PlaneBuf<'_> { | ||
| 36521 | 36577 | let dst = (y + row) * self.width + x; |
| 36522 | 36578 | let pred = &prediction[src..src + w]; |
| 36523 | 36579 | let out = &mut self.data.to_mut()[dst..dst + w]; |
| 36524 | - for (o, &p) in out.iter_mut().zip(pred) { | |
| 36525 | - *o = i32::from(p).clamp(0, max) as u16; | |
| 36580 | + for (col, (o, &p)) in out.iter_mut().zip(pred).enumerate() { | |
| 36581 | + let v = i32::from(p).clamp(0, max) as u16; | |
| 36582 | + pix_write("mc_copy", x, y, w, x + col, y + row, *o, v); | |
| 36583 | + *o = v; | |
| 36526 | 36584 | } |
| 36527 | 36585 | } |
| 36528 | 36586 | return; |
| @@ -36534,8 +36592,10 @@ impl PlaneBuf<'_> { | ||
| 36534 | 36592 | let pred = &prediction[src..src + w]; |
| 36535 | 36593 | let res = &residual[src..src + w]; |
| 36536 | 36594 | let out = &mut self.data.to_mut()[dst..dst + w]; |
| 36537 | - for ((o, &p), &r) in out.iter_mut().zip(pred).zip(res) { | |
| 36538 | - *o = (i32::from(p) + r).clamp(0, max) as u16; | |
| 36595 | + for (col, ((o, &p), &r)) in out.iter_mut().zip(pred).zip(res).enumerate() { | |
| 36596 | + let v = (i32::from(p) + r).clamp(0, max) as u16; | |
| 36597 | + pix_write("mc_add", x, y, w, x + col, y + row, *o, v); | |
| 36598 | + *o = v; | |
| 36539 | 36599 | } |
| 36540 | 36600 | } |
| 36541 | 36601 | } |
crates/ec-av1/src/mc.rsmodified+218 -4
| @@ -1984,7 +1984,9 @@ pub(crate) fn predict_compound_intermediate_kern( | ||
| 1984 | 1984 | let y0 = y_q4.div_euclid(16); |
| 1985 | 1985 | let yfrac = y_q4.rem_euclid(16) as usize; |
| 1986 | 1986 | if crate::envflags::env_flag!("EC_MC_TRACE") { |
| 1987 | - eprintln!("EC_MC_COMP x_q4={x_q4} y_q4={y_q4} w={block_w} h={block_h} hk={h_kind:?} vk={v_kind:?}"); | |
| 1987 | + eprintln!( | |
| 1988 | + "EC_MC_COMP x_q4={x_q4} y_q4={y_q4} w={block_w} h={block_h} hk={h_kind:?} vk={v_kind:?}" | |
| 1989 | + ); | |
| 1988 | 1990 | } |
| 1989 | 1991 | |
| 1990 | 1992 | let (v_wide, v_narrow) = v_kind.tables(); |
| @@ -2129,7 +2131,7 @@ pub(crate) fn diffwtd_mask( | ||
| 2129 | 2131 | let round = INTER_POST_ROUND + bd.saturating_sub(8) - round_delta(bd); |
| 2130 | 2132 | for i in 0..mask.len() { |
| 2131 | 2133 | let diff = round2((pred0[i] - pred1[i]).abs(), round); |
| 2132 | - let m = (38 + diff / 16).clamp(0, 64); | |
| 2134 | + let m = (38 + diff / 16).clamp(0, 64) as u8; | |
| 2133 | 2135 | mask[i] = if inv { (64 - m) as u8 } else { m as u8 }; |
| 2134 | 2136 | } |
| 2135 | 2137 | } |
| @@ -2239,11 +2241,223 @@ fn compound_intermediate_whole_pel_identity_round_trips_through_combine() { | ||
| 2239 | 2241 | assert!(dst.iter().all(|&v| v == 100), "{dst:?}"); |
| 2240 | 2242 | } |
| 2241 | 2243 | |
| 2244 | +/// lane-av1c10: the whole compound pipeline -- two | |
| 2245 | +/// [`predict_compound_intermediate`] taps through every combine this crate | |
| 2246 | +/// ships ([`combine_compound`] dist-wtd and (8,8), [`diffwtd_mask`] both | |
| 2247 | +/// inverses, [`blend_masked_compound`]) -- vs faithful transcriptions of the | |
| 2248 | +/// libaom C at the same inputs, over all 16x16 phase pairs at 8 and 10 bits. | |
| 2249 | +/// | |
| 2250 | +/// The C twins keep the CONV_BUF biased (`sum = dot + (1 << (bd + FILTER_BITS | |
| 2251 | +/// - 1))` horizontally, `1 << offset_bits` vertically -- `convolve.c` | |
| 2252 | +/// `av1_highbd_dist_wtd_convolve_2d_c`); this crate's intermediates are | |
| 2253 | +/// unbiased, so each transcription adds the constant bias | |
| 2254 | +/// `(1 << (bd + 4)) + (1 << (bd + 3))` (= `(1 << (offset_bits - round_1)) + | |
| 2255 | +/// (1 << (offset_bits - round_1 - 1))`) before its combine and subtracts it | |
| 2256 | +/// where libaom does. The diffwtd transcription is `diffwtd_mask_d16` | |
| 2257 | +/// (reconinter.c:301): `round = 2*FILTER_BITS - round_0 - round_1 + (bd-8)`; | |
| 2258 | +/// the blend is `aom_highbd_blend_a64_d16_mask_c` (blend_a64_mask.c): | |
| 2259 | +/// `((m*c0 + (64-m)*c1) >> 6) - bias`, one `ROUND_POWER_OF_TWO` by | |
| 2260 | +/// `round_bits`, `negative_to_zero`, clip. A 10-bit-only wrong constant in | |
| 2261 | +/// any of the three -- the exact shape of the compound rounding defect the | |
| 2262 | +/// cwarp-r1 charter named (and of the `(bd - 8)` diffwtd term that landed | |
| 2263 | +/// without a 10-bit gate behind it) -- fails here per phase, no aomenc stream | |
| 2264 | +/// needed. | |
| 2265 | +#[cfg(test)] | |
| 2266 | +mod libaom_transcription { | |
| 2267 | + use super::{ | |
| 2268 | + InterpFilterKind, REF_NO_SCALE, blend_masked_compound, combine_compound, diffwtd_mask, | |
| 2269 | + predict_compound_intermediate, | |
| 2270 | + }; | |
| 2271 | + | |
| 2272 | + fn lcg(state: &mut u64) -> u32 { | |
| 2273 | + *state = state | |
| 2274 | + .wrapping_mul(6364136223846793005) | |
| 2275 | + .wrapping_add(1442695040888963407); | |
| 2276 | + (*state >> 33) as u32 | |
| 2277 | + } | |
| 2278 | + | |
| 2279 | + /// `ROUND_POWER_OF_TWO` on the C `int` domain: arithmetic shift of | |
| 2280 | + /// `value + half` (halves round toward +inf, negatives included). | |
| 2281 | + fn c_round(value: i32, shift: u32) -> i32 { | |
| 2282 | + (value + (1 << (shift - 1))) >> shift | |
| 2283 | + } | |
| 2284 | + | |
| 2285 | + /// `av1_highbd_dist_wtd_convolve_2d_c` for both taps (biased domain) plus | |
| 2286 | + /// its `do_average` finish: dist-wtd two-weight split, or the plain | |
| 2287 | + /// `>> 1` average. | |
| 2288 | + #[allow(clippy::too_many_arguments)] | |
| 2289 | + fn libaom_compound_2d( | |
| 2290 | + reference: &[u16], | |
| 2291 | + stride: usize, | |
| 2292 | + (x0_q4, y0_q4): (i32, i32), | |
| 2293 | + (x1_q4, y1_q4): (i32, i32), | |
| 2294 | + w: usize, | |
| 2295 | + h: usize, | |
| 2296 | + hf: &[i32; 8], | |
| 2297 | + vf: &[i32; 8], | |
| 2298 | + fwd: i32, | |
| 2299 | + bck: i32, | |
| 2300 | + bd: u32, | |
| 2301 | + dist_wtd: bool, | |
| 2302 | + ) -> Vec<u16> { | |
| 2303 | + let rd = if bd > 10 { bd - 10 } else { 0 }; | |
| 2304 | + let round_0 = 3 + rd; | |
| 2305 | + let round_1 = 7u32; | |
| 2306 | + let offset_bits = (bd + 14 - round_0) as i32; | |
| 2307 | + let bias = | |
| 2308 | + (1 << (offset_bits - round_1 as i32)) + (1 << (offset_bits - round_1 as i32 - 1)); | |
| 2309 | + let round_bits = 14 - round_0 - round_1; | |
| 2310 | + let mut out = vec![0u16; w * h]; | |
| 2311 | + let mut conv = vec![0i32; w * h]; | |
| 2312 | + for (tap, (x_q4, y_q4)) in [(0usize, (x0_q4, y0_q4)), (1usize, (x1_q4, y1_q4))] { | |
| 2313 | + // horizontal, biased | |
| 2314 | + let mut im = vec![0i32; (h + 7) * w]; | |
| 2315 | + for y in 0..h + 7 { | |
| 2316 | + for x in 0..w { | |
| 2317 | + let mut sum = 1i32 << (bd + 7 - 1); | |
| 2318 | + for (k, &t) in hf.iter().enumerate() { | |
| 2319 | + let sx = (x_q4.div_euclid(16) + x as i32 + k as i32 - 3) as usize; | |
| 2320 | + let sy = (y_q4.div_euclid(16) + y as i32 - 3) as usize; | |
| 2321 | + sum += t * i32::from(reference[sy * stride + sx]); | |
| 2322 | + } | |
| 2323 | + im[y * w + x] = c_round(sum, round_0); | |
| 2324 | + } | |
| 2325 | + } | |
| 2326 | + for y in 0..h { | |
| 2327 | + for x in 0..w { | |
| 2328 | + let mut sum = 1i32 << offset_bits; | |
| 2329 | + for (k, &t) in vf.iter().enumerate() { | |
| 2330 | + sum += t * im[(y + k) * w + x]; | |
| 2331 | + } | |
| 2332 | + let res = c_round(sum, round_1); | |
| 2333 | + if tap == 0 { | |
| 2334 | + conv[y * w + x] = res; | |
| 2335 | + } else { | |
| 2336 | + let mut tmp = if dist_wtd { | |
| 2337 | + (conv[y * w + x] * fwd + res * bck) >> 4 // DIST_PRECISION_BITS | |
| 2338 | + } else { | |
| 2339 | + (conv[y * w + x] + res) >> 1 | |
| 2340 | + }; | |
| 2341 | + tmp -= bias; | |
| 2342 | + let v = c_round(tmp, round_bits).max(0) as u32; | |
| 2343 | + out[y * w + x] = v.min((1u32 << bd) - 1) as u16; | |
| 2344 | + } | |
| 2345 | + } | |
| 2346 | + } | |
| 2347 | + } | |
| 2348 | + out | |
| 2349 | + } | |
| 2350 | + | |
| 2351 | + /// `diffwtd_mask_d16` on the biased conv bufs. | |
| 2352 | + fn libaom_diffwtd(c0: &[i32], c1: &[i32], inv: bool, bd: u32, round_0: u32) -> Vec<u8> { | |
| 2353 | + let round = (14 - round_0 - 7 + (bd - 8)) as i32; | |
| 2354 | + c0.iter() | |
| 2355 | + .zip(c1) | |
| 2356 | + .map(|(&a, &b)| { | |
| 2357 | + let diff = c_round((a - b).abs(), round.unsigned_abs()); | |
| 2358 | + let m = (38 + diff / 16).clamp(0, 64) as u8; | |
| 2359 | + if inv { 64 - m } else { m } | |
| 2360 | + }) | |
| 2361 | + .collect() | |
| 2362 | + } | |
| 2363 | + | |
| 2364 | + /// `aom_highbd_blend_a64_d16_mask_c`, subw == subh == 0, biased domain. | |
| 2365 | + fn libaom_blend(c0: &[i32], c1: &[i32], mask: &[u8], bd: u32, round_0: u32) -> Vec<u16> { | |
| 2366 | + let bias = (1i32 << (bd + 4)) + (1i32 << (bd + 3)); | |
| 2367 | + let round_bits = 14 - round_0 - 7; | |
| 2368 | + c0.iter() | |
| 2369 | + .zip(c1) | |
| 2370 | + .zip(mask) | |
| 2371 | + .map(|((&a, &b), &m)| { | |
| 2372 | + let res = ((i32::from(m) * a + (64 - i32::from(m)) * b) >> 6) - bias; | |
| 2373 | + let v = c_round(res, round_bits).max(0) as u32; | |
| 2374 | + v.min((1u32 << bd) - 1) as u16 | |
| 2375 | + }) | |
| 2376 | + .collect() | |
| 2377 | + } | |
| 2378 | + | |
| 2379 | + #[test] | |
| 2380 | + fn compound_pipeline_matches_the_libaom_transcription_at_8_and_10_bits() { | |
| 2381 | + let fctx = &crate::decode::FrameCtx::new(); | |
| 2382 | + for bd in [8u32, 10u32] { | |
| 2383 | + crate::decode::set_bit_depth(bd as u8, fctx); | |
| 2384 | + let max = (1u16 << bd) - 1; | |
| 2385 | + let (wide, _narrow) = InterpFilterKind::Regular.tables(); | |
| 2386 | + let mut state = 0x9e37_79b9_7f4a_7c15u64 ^ u64::from(bd); | |
| 2387 | + let reference: Vec<u16> = (0..48 * 48) | |
| 2388 | + .map(|_| (lcg(&mut state) % (u32::from(max) + 1)) as u16) | |
| 2389 | + .collect(); | |
| 2390 | + let rd = if bd > 10 { bd - 10 } else { 0 }; | |
| 2391 | + let round_0 = 3 + rd; | |
| 2392 | + let bias = (1i32 << (bd + 4)) + (1i32 << (bd + 3)); | |
| 2393 | + for &dist_wtd in &[false, true] { | |
| 2394 | + let (fwd, bck) = if dist_wtd { (9, 7) } else { (8, 8) }; | |
| 2395 | + for xf in 0..16i32 { | |
| 2396 | + for yf in 0..16i32 { | |
| 2397 | + let (mv0, mv1) = ((16 * 8 + xf, 16 * 8 + yf), (16 * 10 + xf, 16 * 7 + yf)); | |
| 2398 | + let (hf, vf) = (&wide[xf as usize], &wide[yf as usize]); | |
| 2399 | + let mut p0 = vec![0i32; 64]; | |
| 2400 | + let mut p1 = vec![0i32; 64]; | |
| 2401 | + for (mv, dst) in [(mv0, &mut p0), (mv1, &mut p1)] { | |
| 2402 | + predict_compound_intermediate( | |
| 2403 | + &reference, | |
| 2404 | + 48, | |
| 2405 | + 48, | |
| 2406 | + 48, | |
| 2407 | + mv.0, | |
| 2408 | + mv.1, | |
| 2409 | + REF_NO_SCALE, | |
| 2410 | + 8, | |
| 2411 | + 8, | |
| 2412 | + InterpFilterKind::Regular, | |
| 2413 | + InterpFilterKind::Regular, | |
| 2414 | + dst, | |
| 2415 | + fctx, | |
| 2416 | + ); | |
| 2417 | + } | |
| 2418 | + let mut got = vec![0u16; 64]; | |
| 2419 | + combine_compound(&p0, &p1, fwd, bck, &mut got, fctx); | |
| 2420 | + let want = libaom_compound_2d( | |
| 2421 | + &reference, 48, mv0, mv1, 8, 8, hf, vf, fwd, bck, bd, dist_wtd, | |
| 2422 | + ); | |
| 2423 | + assert_eq!( | |
| 2424 | + got, want, | |
| 2425 | + "combine bd {bd} dist_wtd {dist_wtd} phase ({xf},{yf})" | |
| 2426 | + ); | |
| 2427 | + | |
| 2428 | + let c0: Vec<i32> = p0.iter().map(|&v| v + bias).collect(); | |
| 2429 | + let c1: Vec<i32> = p1.iter().map(|&v| v + bias).collect(); | |
| 2430 | + for inv in [false, true] { | |
| 2431 | + let mut mask = vec![0u8; 64]; | |
| 2432 | + diffwtd_mask(&p0, &p1, inv, &mut mask, fctx); | |
| 2433 | + assert_eq!( | |
| 2434 | + mask, | |
| 2435 | + libaom_diffwtd(&c0, &c1, inv, bd, round_0), | |
| 2436 | + "diffwtd bd {bd} inv {inv} phase ({xf},{yf})" | |
| 2437 | + ); | |
| 2438 | + } | |
| 2439 | + let mask: Vec<u8> = (0..64).map(|_| (lcg(&mut state) % 65) as u8).collect(); | |
| 2440 | + let mut blended = vec![0u16; 64]; | |
| 2441 | + // main shape: the branch's `subsampled: bool` split into | |
| 2442 | + // the plane's own `subw`/`subh` shifts; luma is (0, 0). | |
| 2443 | + blend_masked_compound(&p0, &p1, &mask, 8, 8, 8, 0, 0, &mut blended, fctx); | |
| 2444 | + assert_eq!( | |
| 2445 | + blended, | |
| 2446 | + libaom_blend(&c0, &c1, &mask, bd, round_0), | |
| 2447 | + "blend bd {bd} phase ({xf},{yf})" | |
| 2448 | + ); | |
| 2449 | + } | |
| 2450 | + } | |
| 2451 | + } | |
| 2452 | + } | |
| 2453 | + } | |
| 2454 | +} | |
| 2455 | + | |
| 2242 | 2456 | #[cfg(test)] |
| 2243 | 2457 | mod tests { |
| 2244 | 2458 | use super::{ |
| 2245 | - predict, predict_scaled, predict_with_filter, predict_with_filters, InterpFilterKind, | |
| 2246 | - REF_NO_SCALE, | |
| 2459 | + InterpFilterKind, REF_NO_SCALE, predict, predict_scaled, predict_with_filter, | |
| 2460 | + predict_with_filters, | |
| 2247 | 2461 | }; |
| 2248 | 2462 | |
| 2249 | 2463 | /// Regression pin for the lane-av1flake ±1 defect: a real aomenc chroma |
lanes/av1pixprobe.report.mdadded+338 -0
| @@ -0,0 +1,338 @@ | ||
| 1 | +# lane-av1pixprobe — the two `av1cheapwins` §C "land after rebase" items | |
| 2 | + | |
| 3 | +Base: `1d47ff54` (main). Two independent pieces, landed: | |
| 4 | + | |
| 5 | +* **A** — `EC_AV1_PIXPROBE=x,y`, the env-gated one-sample write probe from | |
| 6 | + `lane-av1-ibcwrite` @ `25f5c729`, **re-anchored by hand** onto main's | |
| 7 | + reconstruction-store sites (the branch's two mc hunks no longer attach: the | |
| 8 | + mc stores live in `reconstruct_mc_rect` now, and its block extent is `w`, | |
| 9 | + not `side`). | |
| 10 | +* **B** — the substance behind `lane-av1-c10`: ancestor commit **`295dc3fe`**'s | |
| 11 | + byte-identical `u8` cast move in `diffwtd_mask` **plus** its 8/10-bit libaom | |
| 12 | + transcription gate `mc::libaom_transcription::compound_pipeline_matches_the_libaom_transcription_at_8_and_10_bits` | |
| 13 | + (adapted, not cherry-picked — see "B" below). | |
| 14 | + | |
| 15 | +Defect **C** is recorded, not chased — and it does **not** reproduce on merged | |
| 16 | +main; see "C". | |
| 17 | + | |
| 18 | +`cargo check --all-targets -p ec-av1` clean, gate green, rung fires and is | |
| 19 | +inert when unset. | |
| 20 | + | |
| 21 | +--- | |
| 22 | + | |
| 23 | +## A — the write probe, re-anchored | |
| 24 | + | |
| 25 | +### Why the cherry-pick does not apply | |
| 26 | + | |
| 27 | +`git show 25f5c729 -- crates/ec-av1/src/decode.rs` has four store hunks. Two of | |
| 28 | +them (the intra pair) still attach: `reconstruct_rect` and `reconstruct` both | |
| 29 | +exist on main with the same | |
| 30 | +`self.data.to_mut()[(y + row) * self.width + x + col] = sample;` line inside | |
| 31 | +the same `let sample = (base + residual[idx]).clamp(...)` store. The two mc | |
| 32 | +hunks do **not**: they were written against the pre-restructure | |
| 33 | +`mc_copy`/`mc_add` loops; on `1d47ff54` both stores are inside | |
| 34 | +`PlaneBuf::reconstruct_mc_rect` (`decode.rs:36454` onward), which | |
| 35 | +lane-perf4/lane-recoparse reshaped (row-at-a-time `pred`/`out` slice pairs, an | |
| 36 | +early `residual.is_empty()` return for the prediction-only path, and a | |
| 37 | +`w`/`h` block extent with `side` demoted to the prediction stride). So the | |
| 38 | +loops were re-located by grep and re-written in place. | |
| 39 | + | |
| 40 | +Two deliberate deviations from the branch's text, both forced by main's shape: | |
| 41 | + | |
| 42 | +1. `pix_write("mc_copy", x, y, w, …)` / `pix_write("mc_add", x, y, w, …)` — the | |
| 43 | + branch passed `side`. In `reconstruct_mc_rect` `side` is the *prediction | |
| 44 | + stride*, not the block width (a rect block is `w` wide and `side`-strided), | |
| 45 | + so reporting `side` in the `block=(bx,by)+SIDE` field would misreport the | |
| 46 | + block extent for every rectangular inter block. `w` is what the field means. | |
| 47 | +2. **Formatting.** The branch wrote the two intra `pix_write` calls as single | |
| 48 | + long lines. This repo does have a formatting hook, but not where I first | |
| 49 | + looked: `core.hooksPath` is `/home/user/omp/omp/agent/hooks/git`, so | |
| 50 | + `$(git rev-parse --git-common-dir)/hooks/pre-commit` is absent and says | |
| 51 | + nothing. The commit-time rustfmt reflowed the four call sites and the | |
| 52 | + `pix_write` signature across lines (semantic-only; the diff grew from the | |
| 53 | + branch's +33/-4 to +64/-4 and every extra line is reflow). Accepted, not | |
| 54 | + reverted. | |
| 55 | + | |
| 56 | +### The landed diff (`decode.rs +64/-4`; the +31 over the branch's +33 is pure reflow) | |
| 57 | + | |
| 58 | +(shown in the branch's single-line form for readability; as committed the | |
| 59 | +`pix_write` signature and the two intra call sites are rustfmt-reflowed, which | |
| 60 | +is where the extra 31 lines are — no token changed) | |
| 61 | + | |
| 62 | +``` | |
| 63 | + @@ -20395,6 +20395,31 @@ struct PlaneBuf<'a> { | |
| 64 | + +// lane-av1pixprobe: env-gated one-sample write probe -- `EC_AV1_PIXPROBE=x,y` | |
| 65 | + +// prints one PIXWRITE line per reconstruction store landing on that sample, | |
| 66 | + +// naming the store site, the value it replaces and the one it leaves. Re-anchored | |
| 67 | + +// from `lane-av1-ibcwrite` @ 25f5c729 onto the main-shape sites (the two mc stores | |
| 68 | + +// now live in `reconstruct_mc_rect`). | |
| 69 | + +static PIXPROBE_ON: std::sync::LazyLock<bool> = | |
| 70 | + + std::sync::LazyLock::new(|| std::env::var_os("EC_AV1_PIXPROBE").is_some()); | |
| 71 | + +static PIXPROBE: std::sync::LazyLock<Option<(usize, usize)>> = LazyLock::new(|| { … }); | |
| 72 | + +#[inline] | |
| 73 | + +fn pix_write(site: &str, bx: usize, by: usize, bside: usize, x: usize, y: usize, prev: u16, val: u16) { | |
| 74 | + + if *PIXPROBE_ON && Some((x, y)) == *PIXPROBE { | |
| 75 | + + eprintln!("PIXWRITE {site} block=({bx},{by})+{bside} px=({x},{y}) prev={prev} val={val} at {}", Location::caller()); | |
| 76 | + + } | |
| 77 | + +} | |
| 78 | + @@ -20599,6 +20624,7 @@ (reconstruct_rect store) | |
| 79 | + + pix_write("reconstruct_rect", x, y, bw, x + col, y + row, self.data[…], sample); | |
| 80 | + @@ -20745,6 +20771,7 @@ (reconstruct store) | |
| 81 | + + pix_write("reconstruct", x, y, side, x + col, y + row, self.data[…], sample); | |
| 82 | + @@ -36485,8 +36512,10 @@ (reconstruct_mc_rect, residual.is_empty() path) | |
| 83 | + - for (o, &p) in out.iter_mut().zip(pred) { | |
| 84 | + - *o = i32::from(p).clamp(0, max) as u16; | |
| 85 | + + for (col, (o, &p)) in out.iter_mut().zip(pred).enumerate() { | |
| 86 | + + let v = i32::from(p).clamp(0, max) as u16; | |
| 87 | + + pix_write("mc_copy", x, y, w, x + col, y + row, *o, v); | |
| 88 | + + *o = v; | |
| 89 | + @@ -36498,8 +36527,10 @@ (reconstruct_mc_rect, dense-residual path) | |
| 90 | + - for ((o, &p), &r) in out.iter_mut().zip(pred).zip(res) { | |
| 91 | + - *o = (i32::from(p) + r).clamp(0, max) as u16; | |
| 92 | + + for (col, ((o, &p), &r)) in out.iter_mut().zip(pred).zip(res).enumerate() { | |
| 93 | + + let v = (i32::from(p) + r).clamp(0, max) as u16; | |
| 94 | + + pix_write("mc_add", x, y, w, x + col, y + row, *o, v); | |
| 95 | + + *o = v; | |
| 96 | +``` | |
| 97 | + | |
| 98 | +Inertness is structural, not incidental: `PIXPROBE_ON` is a `LazyLock<bool>` over | |
| 99 | +`std::env::var_os(..).is_some()`, so with the variable unset the whole body | |
| 100 | +compiles to one atomic load per store and the `eprintln!` is behind a `false` | |
| 101 | +that the branch's own envflags note (lane-perf1) shows is free. Nothing in the | |
| 102 | +crate calls `set_var` (`grep -rn set_var crates/ec-av1` = 0 hits), so the | |
| 103 | +snapshot cannot change under a run. | |
| 104 | + | |
| 105 | +### Proof it fires — the pinned fixture, re-encoded here | |
| 106 | + | |
| 107 | +The `lane-av1ibcwrite` / `lane-av1ibcpix` recipe, re-run verbatim | |
| 108 | +(`testsrc2=size=320x180:rate=25 -t 0.2 -vf tile=2x2` y4m → | |
| 109 | +`aomenc --passes=1 --end-usage=q --cpu-used=0 --lag-in-frames=0 --kf-max-dist=1 | |
| 110 | +--limit=1 --threads=1 --tile-columns=0 --min-partition-size=8 | |
| 111 | +--max-partition-size=32 --sb-size=64 --tune-content=screen --enable-intrabc=1 | |
| 112 | +--enable-palette=0 --cq-level=20 --enable-tx-size-search=1 | |
| 113 | +--enable-rect-partitions=0 --enable-1to4-partitions=0 --max-partition-size=64 | |
| 114 | +--obu`): | |
| 115 | + | |
| 116 | +``` | |
| 117 | +$ sha256sum out.obu | |
| 118 | +bc699af4a6e7c1c5657f041e8cbdf2d3d899ddb80ec2a549a950b7cebb5b41bd out.obu | |
| 119 | +``` | |
| 120 | + | |
| 121 | +— byte-identical to the sha both parked reports pin. | |
| 122 | + | |
| 123 | +Set: | |
| 124 | + | |
| 125 | +``` | |
| 126 | +$ EC_AV1_PIXPROBE=296,128 decode_probe out.obu | |
| 127 | +PIXWRITE reconstruct block=(288,128)+32 px=(296,128) prev=0 val=170 at crates/ec-av1/src/decode.rs:20418:13 | |
| 128 | +PIXWRITE reconstruct block=(288,128)+16 px=(296,128) prev=0 val=167 at crates/ec-av1/src/decode.rs:20418:13 | |
| 129 | +PIXWRITE reconstruct block=(288,128)+16 px=(296,128) prev=0 val=15 at crates/ec-av1/src/decode.rs:20418:13 | |
| 130 | +OK: 1 frames decoded, 640x360 | |
| 131 | +``` | |
| 132 | + | |
| 133 | +Three stores, one per plane (luma `val=170`, U `val=167`, V `val=15`) — the | |
| 134 | +same three-stores-one-per-plane shape the branch reported, at the sample the | |
| 135 | +branch named. Unset: | |
| 136 | + | |
| 137 | +``` | |
| 138 | +$ env -u EC_AV1_PIXPROBE decode_probe out.obu 2>&1 | grep -c PIXWRITE | |
| 139 | +0 | |
| 140 | +``` | |
| 141 | + | |
| 142 | +Build: | |
| 143 | + | |
| 144 | +``` | |
| 145 | +$ CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1pixprobe cargo check --all-targets -p ec-av1 | |
| 146 | + Finished `dev` profile [optimized + debuginfo] target(s) in 1.76s (exit 0) | |
| 147 | +``` | |
| 148 | + | |
| 149 | +--- | |
| 150 | + | |
| 151 | +## B — `diffwtd_mask`'s `u8` cast move + its 8/10-bit gate | |
| 152 | + | |
| 153 | +### The cast move is byte-identical — argued from the clamp, not asserted | |
| 154 | + | |
| 155 | +```rust | |
| 156 | +let diff = round2((pred0[i] - pred1[i]).abs(), round); | |
| 157 | +let m = (38 + diff / 16).clamp(0, 64) as u8; // was: (… .clamp(0, 64); with `m as u8` at the use | |
| 158 | +mask[i] = if inv { (64 - m) as u8 } else { m as u8 }; | |
| 159 | +``` | |
| 160 | + | |
| 161 | +`clamp(0, 64)` on an integer leaves `m ∈ {0,…,64}` — 65 values, all | |
| 162 | +representable in `u8` — so `as u8` is value-preserving and the two forms bind | |
| 163 | +the *same* integer. Every use is a narrowing of a value already in range: | |
| 164 | + | |
| 165 | +* forward: `m as u8` (old) vs `m` already `u8` (new) — identical byte. | |
| 166 | +* inverse: `64 - m` is in `1..=64` for `m ∈ 0..=64`, so it is non-negative and | |
| 167 | + `u8`-representable; `64u8 - m_u8` cannot wrap, and `(64 - m_i32) as u8` is the | |
| 168 | + same value. Identical byte. | |
| 169 | + | |
| 170 | +The only behavioural difference between the two bindings is the *domain* of the | |
| 171 | +subtraction (`u8` vs `i32`), and since neither operand can leave `[0,64]` there | |
| 172 | +is no value for which the two domains differ. The mask array is `&mut [u8]`, so | |
| 173 | +the stored bytes are the same in both. This is a type-tightening only: it moves | |
| 174 | +the range proof to the binding and deletes two now-redundant casts. | |
| 175 | + | |
| 176 | +### The gate — landed, and proven non-vacuous at BOTH depths | |
| 177 | + | |
| 178 | +`mc::libaom_transcription::compound_pipeline_matches_the_libaom_transcription_at_8_and_10_bits` | |
| 179 | +(213 lines, from `295dc3fe`) pins the whole compound path — two | |
| 180 | +`predict_compound_intermediate` taps through `combine_compound` (dist-wtd 9/7 | |
| 181 | +and simple 8/8), `diffwtd_mask` both inverses, and `blend_masked_compound` — | |
| 182 | +against faithful transcriptions of `av1_highbd_dist_wtd_convolve_2d_c`, | |
| 183 | +`diffwtd_mask_d16` and `aom_highbd_blend_a64_d16_mask_c`, over **all 256 phase | |
| 184 | +pairs at 8 and 10 bits**, with no aomenc stream and no fixture. That is | |
| 185 | +precisely the 10-bit coverage the `(bd - 8)` term in `diffwtd_mask` landed | |
| 186 | +without (cwarp-r1's `accepted` residue). | |
| 187 | + | |
| 188 | +Adaptation, because main's `blend_masked_compound` signature has drifted: the | |
| 189 | +branch's `subsampled: bool` is now the plane's own `subw`/`subh` shift pair, so | |
| 190 | +the call is | |
| 191 | + | |
| 192 | +```rust | |
| 193 | +blend_masked_compound(&p0, &p1, &mask, 8, 8, 8, 0, 0, &mut blended, fctx); | |
| 194 | +``` | |
| 195 | + | |
| 196 | +(luma, `(subw, subh) = (0, 0)`), and the transcription is unchanged — the | |
| 197 | +branch's transcription was already the `subw == subh == 0` luma case. Every | |
| 198 | +other identifier and signature (`predict_compound_intermediate`, | |
| 199 | +`combine_compound`, `InterpFilterKind::Regular.tables()`, `FrameCtx::new`, | |
| 200 | +`set_bit_depth`, `REF_NO_SCALE`) still matches main unchanged. One | |
| 201 | +`#[allow(clippy::too_many_arguments)]` was added to the transcription helper, | |
| 202 | +which main's lints require and the branch's tree did not. | |
| 203 | + | |
| 204 | +Run: | |
| 205 | + | |
| 206 | +``` | |
| 207 | +$ cargo test -p ec-av1 --lib compound_pipeline_matches_the_libaom_transcription | |
| 208 | +running 1 test | |
| 209 | +test mc::libaom_transcription::compound_pipeline_matches_the_libaom_transcription_at_8_and_10_bits ... ok | |
| 210 | +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 764 filtered out; finished in 0.06s | |
| 211 | +``` | |
| 212 | + | |
| 213 | +Non-vacuity, two counterfactuals on `diffwtd_mask`'s own `round` line, each | |
| 214 | +reverted immediately: | |
| 215 | + | |
| 216 | +| mutation | result | | |
| 217 | +|---|---| | |
| 218 | +| `… - round_delta(bd) + 1` (bites at 8-bit) | `FAILED … assertion left == right failed: diffwtd bd 8 inv false phase (0,0)` | | |
| 219 | +| `INTER_POST_ROUND + bd.saturating_sub(8) * 2 - round_delta(bd)` — **zero at 8-bit, nonzero at 10-bit only** | `FAILED … assertion left == right failed: diffwtd bd 10 inv false phase (0,0)` | | |
| 220 | + | |
| 221 | +The second is the load-bearing one: it is inert at 8-bit and only the 10-bit arm | |
| 222 | +catches it, so the 10-bit coverage is real, not a duplicate of the 8-bit arm. | |
| 223 | +Both reverted; the green run above is the reverted tree. | |
| 224 | + | |
| 225 | +--- | |
| 226 | + | |
| 227 | +## C — the defect the branch named: RECORDED, NOT INVESTIGATED | |
| 228 | + | |
| 229 | +**Not investigated by contract.** Re-measured only to the extent needed to say | |
| 230 | +whether the recorded numbers still describe merged main, which changes what a | |
| 231 | +charter must start from. That re-measurement is itself the most important line | |
| 232 | +in this section. | |
| 233 | + | |
| 234 | +### The recorded defect (verbatim from `lane-av1ibcwrite.report.md`, `25f5c729`) | |
| 235 | + | |
| 236 | +> An 8x8 intra-BC leaf at px **(296, 128)** stores **prediction 170 + residual | |
| 237 | +> 19 = 189** where the oracle's single all-zero `TX_32X32` unit stores **170**. | |
| 238 | +> First value divergence upstream: at mi **(row 32, col 72)** (the owning 32x32 | |
| 239 | +> luma TU at px (288,128), the 64x64 at x 256..320 / y 128..192) ours reads | |
| 240 | +> `skip=1` where the oracle reads `skip=0`; the oracle codes that quadrant | |
| 241 | +> `PARTITION_NONE` as one 32x32 with `all_zero=1`, ours splits it into 8x8/16x16 | |
| 242 | +> leaves, and from that symbol the arithmetic streams desync. Our desynced 8x8 | |
| 243 | +> leaf at (296,128) then reads `all_zero=0` with one DC level 2 → dequant 19 → | |
| 244 | +> the 189 store. Oracle output at that sample: **170**; the class repeats **301 | |
| 245 | +> times** per frame (independent roots with a clean left/above/above-left), | |
| 246 | +> 127,862 differing samples (Y 84,510 / U 21,005 / V 22,347), rows y 128..359. | |
| 247 | +> Fixture: the R5 encode above, sha256 | |
| 248 | +> `bc699af4a6e7c1c5657f041e8cbdf2d3d899ddb80ec2a549a950b7cebb5b41bd`. The | |
| 249 | +> named home is the partition-context / leaf8 intrabc neighbour stamping | |
| 250 | +> (`leaf8_intrabc_hits` territory), upstream of the whole decode tail. | |
| 251 | + | |
| 252 | +### What merged main does with the same fixture today | |
| 253 | + | |
| 254 | +The branch tip `37a64d99` is **not** an ancestor of main; its merge-base with | |
| 255 | +`1d47ff54` is `7f863c5f`, i.e. the measurement tree is **439 commits behind** | |
| 256 | +main with one commit of its own on top. Re-encoding the recipe reproduces the | |
| 257 | +pinned sha byte-for-byte, and on this tree: | |
| 258 | + | |
| 259 | +``` | |
| 260 | +$ dump_yuv out.obu /tmp/ours ; ffmpeg -i out.obu -pix_fmt yuv420p -f rawvideo ref.yuv | |
| 261 | +$ cmp ours.f0.yuv ref.yuv | |
| 262 | +$ # python: total differing samples vs ffmpeg: 0 Y differing: 0 | |
| 263 | +$ # Y(296,128): ours 170 ref 170 | |
| 264 | +``` | |
| 265 | + | |
| 266 | +**The frame is byte-exact against ffmpeg on `1d47ff54`**, so the 189 store is | |
| 267 | +**not reproducible on merged main** for this fixture: Y(296,128) is 170 in both | |
| 268 | +frames, and the probe above prints `val=170` for the luma plane at that | |
| 269 | +coordinate. Luma still contains four samples equal to 189 in total — at | |
| 270 | +**(70,218), (70,219), (70,223), (389,225)** — but they match the oracle | |
| 271 | +byte-for-byte, so they are picture content, not residues of this class. | |
| 272 | + | |
| 273 | +### Hand-off row | |
| 274 | + | |
| 275 | +> **OPEN, un-reproduced on merged main.** Class: partition-tree divergence | |
| 276 | +> around skipped intrabc leaves (entropy desync, not a write bug — the | |
| 277 | +> reconstruction arithmetic is correct and the write site is exonerated). The | |
| 278 | +> original numbers: 8x8 intrabc leaf at px **(296,128)** storing | |
| 279 | +> **pred 170 + res 19 = 189** where the oracle's all-zero `TX_32X32` stores | |
| 280 | +> **170**; first divergent symbol at mi **(32,72)** — `skip=1` vs `skip=0`, | |
| 281 | +> `PARTITION_NONE` vs an 8x8/16x16 split; **301** independent roots per frame; | |
| 282 | +> **127,862** differing samples (Y 84,510 / U 21,005 / V 22,347), y 128..359; | |
| 283 | +> fixture sha256 `bc699af4a6e7c1c5657f041e8cbdf2d3d899ddb80ec2a549a950b7cebb5b41bd` | |
| 284 | +> (recipe reproduced here, byte-identical). **On `1d47ff54` the fixture decodes | |
| 285 | +> byte-exact vs ffmpeg (0 differing samples)** — the measuring tree `37a64d99` | |
| 286 | +> is 439 commits stale (merge-base `7f863c5f`), so either a later lane closed | |
| 287 | +> it on this input or the tree it was measured on is not the tree it was | |
| 288 | +> reported against. **A charter must start by re-bisecting on merged main, not | |
| 289 | +> by trusting these coordinates**; `EC_AV1_PIXPROBE=x,y` (this branch) is the | |
| 290 | +> re-measurement instrument, and the owning area named by the original report | |
| 291 | +> is the partition-context / leaf8 intrabc neighbour stamping. | |
| 292 | + | |
| 293 | +**Not investigated:** I did not trace the partition path, did not run the | |
| 294 | +oracle's `EC_ISTEP`/`EC_TRACE_COEFF` rungs against main, did not try to find | |
| 295 | +which of the 439 commits changed the outcome, and did not confirm or deny that | |
| 296 | +the class still exists anywhere. The 301-root / 127,862-sample figures are the | |
| 297 | +branch's, quoted for provenance; they are **not** re-measured numbers. | |
| 298 | + | |
| 299 | +--- | |
| 300 | + | |
| 301 | +## What I deliberately did not do | |
| 302 | + | |
| 303 | +- **Did not cherry-pick.** Both commits were re-anchored/re-adapted by hand; | |
| 304 | + `git cherry-pick` was never run against either, because both would conflict | |
| 305 | + (`decode.rs` sites moved; `blend_masked_compound`'s signature changed). | |
| 306 | +- **Did not land `lane-av1c10` @ `a2806383`** (the report-only disclosure | |
| 307 | + correction at that tip). §C triaged it "record only" and its content | |
| 308 | + duplicates this report; only the ancestor `295dc3fe` substance landed. | |
| 309 | +- **Did not land `lanes/av1ibcwrite.report.md` / `lanes/av1c10.report.md`** | |
| 310 | + verbatim. The ibcwrite report's "the write is named" narrative is superseded | |
| 311 | + for merged main by the re-measurement above; C quotes it as a record instead. | |
| 312 | +- **Did not investigate the C defect.** See the hand-off row: one fixture | |
| 313 | + re-encode + one `cmp` against ffmpeg to establish non-reproduction, nothing | |
| 314 | + further. | |
| 315 | +- **Did not touch the main checkout.** It is clean after every batch; the | |
| 316 | + absolute-path discipline held (see below). | |
| 317 | +- **Did not run any full suite.** Scoped to one named test in one crate, one | |
| 318 | + example build, one one-frame fixture probe. Box was loaded. | |
| 319 | +- **Did not run rustfmt myself.** The commit hook reflowed the new lines | |
| 320 | + (`core.hooksPath=/home/user/omp/omp/agent/hooks/git`); the reflow is | |
| 321 | + semantic-only and was left in place rather than fought. | |
| 322 | +- **Did not add a gate for the pixprobe rung itself** (e.g. a | |
| 323 | + fires-when-set assertion). A test that would have to spawn a process with the | |
| 324 | + env set is out of proportion to an inert debug rung, and the repo's | |
| 325 | + convention for these is the example-binary probe quoted above. | |
| 326 | +- **Did not push.** | |
| 327 | + | |
| 328 | +### One process note worth carrying forward | |
| 329 | + | |
| 330 | +The `edit` tool resolved a **relative** path header against the session's cwd | |
| 331 | +(the main checkout), not the worktree, and silently wrote the first insertion | |
| 332 | +into `main`'s `decode.rs`. Caught immediately by | |
| 333 | +`git status --porcelain` in the main checkout showing | |
| 334 | +` M crates/ec-av1/src/decode.rs`, reverted with `git checkout --`, and every | |
| 335 | +later edit used an absolute `/home/user/.cache/wt/av1pixprobe/…` path. The | |
| 336 | +contract's "relative edits land in the main checkout" is not a warning about a | |
| 337 | +*different* worktree arrangement — it is literally what happens, on the first | |
| 338 | +edit, with a relative path. |