forge
Explore
Log in

Don't you dare go Hollow

vp9kf: d153 row, idct32 stage 8, flat2 q0, chroma tx-grid — Y byte-exact

Browse files at this commit

82ca712e6d5c42a165016ddb1ef4ad9aba4e2cd2Ahmet Kaan GümüşParent: 9769de2
generic d153 no longer skips row 1; idct32 runs vpx stage 8; flat_mask5
compares q4..q7 to q0 (not p0). Pre-LF Y matches libvpx; post-LF Y matches
ffmpeg. Chroma still 16 U + 20 V off (HANDOFF #6). Not pushed.
crates/ec-vp9/src/decode.rsmodified+15 -15
@@ -242,8 +242,7 @@ impl Decoder {
242242 let mut ti = 0usize;
243243 for tr in 0..tile_rows {
244244 let row_lo = ((sb64_rows * tr) >> hdr.tile_info.rows_log2) * SB_MI;
245- let row_hi =
246- (((sb64_rows * (tr + 1)) >> hdr.tile_info.rows_log2) * SB_MI).min(mi_rows);
245+ let row_hi = (((sb64_rows * (tr + 1)) >> hdr.tile_info.rows_log2) * SB_MI).min(mi_rows);
247246 for tc in 0..tile_cols {
248247 let col_lo = ((sb64_cols * tc) >> hdr.tile_info.cols_log2) * SB_MI;
249248 let col_hi =
@@ -709,19 +708,7 @@ impl Decoder {
709708 // 1. Intra prediction (reads reconstructed neighbours).
710709 {
711710 let (data, _) = planes.plane(plane);
712- build_intra_predictors(
713- data,
714- stride,
715- pw,
716- ph,
717- x0,
718- y0,
719- mode,
720- bs,
721- up,
722- lft,
723- rgt,
724- );
711+ build_intra_predictors(data, stride, pw, ph, x0, y0, mode, bs, up, lft, rgt);
725712 }
726713
727714 if info.skip {
@@ -764,6 +751,19 @@ impl Decoder {
764751 ctx_in
765752 );
766753 }
754+ if crate::trace_enabled() {
755+ eprintln!(
756+ "TXB p={} x={} y={} tx={} a={} l={} deq={},{}",
757+ plane,
758+ x0,
759+ y0,
760+ tx_size,
761+ ectx[plane].above[ax],
762+ ectx[plane].left[ay],
763+ dequant[0],
764+ dequant[1]
765+ );
766+ }
767767 let coef = decode_coefs(
768768 r,
769769 ptype,
crates/ec-vp9/src/intra.rsmodified+15 -2
@@ -158,13 +158,26 @@ pub(crate) fn build_intra_predictors(
158158 "STAGE x0={x0} y0={y0} mode={mode} bs={bs} above={:?} cor={} left={:?}",
159159 &above_data[A..A + 8],
160160 above_data[A - 1],
161- &left_col[..4]
161+ &left_col[..8]
162162 );
163163 }
164164 let dst = &mut data[y0 * stride + x0..];
165165 dispatch(
166166 mode, bs, dst, stride, &above_data, &left_col, up_available, left_available,
167167 );
168+ if crate::trace_enabled()
169+ && std::env::var("EC_VP9_PROBE_TU")
170+ .ok()
171+ .and_then(|s| {
172+ let mut it = s.split(',');
173+ Some((it.next()?.parse::<usize>().ok()?, it.next()?.parse().ok()?))
174+ })
175+ .is_some_and(|(px, py)| x0 == px && y0 == py)
176+ {
177+ for rr in 0..bs {
178+ eprintln!("PRED r={rr} {:?}", &dst[rr * stride..rr * stride + bs]);
179+ }
180+ }
168181 }
169182
170183 fn dispatch(
@@ -325,7 +338,7 @@ fn dispatch(
325338 }
326339 for r in 1..bs {
327340 for c in 0..bs - 2 {
328- dst[(r + 1) * stride + 2 + c] = dst[r * stride + c];
341+ dst[r * stride + 2 + c] = dst[(r - 1) * stride + c];
329342 }
330343 }
331344 }
crates/ec-vp9/src/loopfilter.rsmodified+35 -28
@@ -69,16 +69,14 @@ fn lpf_edge(
6969 blimit: i32,
7070 limit: i32,
7171 thresh: i32,
72+ nlines: isize,
7273 ) {
7374 // `dir` 0 = horizontal edges (rows step by stride), 1 = vertical
7475 // (columns step by 1). `taps` in {4, 8, 16}.
7576 let step: isize = if dir == 0 { stride as isize } else { 1 };
7677 let line_step: isize = if dir == 0 { 1 } else { stride as isize };
77- // The kernel filters a single pixel-line; one call covers a 4-pixel
78- // chunk, so run it on each of the four lines crossing the edge
79- // (every row for a vertical edge, every column for a horizontal one)
80- // — this is the per-row `s += pitch` walk inside vpx_lpf_*_c.
81- for line in 0..4isize {
78+ // luma: 4 lines per 4x4; chroma ss11: 8 lines matching vpx_lpf_*_c.
79+ for line in 0..nlines {
8280 let edge = off as isize + line * line_step;
8381 macro_rules! rd {
8482 ($k:expr) => {
@@ -144,17 +142,16 @@ fn lpf_edge(
144142 put!(2, ((p0 + q0 + q1 + q2 * 2 + q3 + q3 + q3 + 4) >> 3) as u8);
145143 continue;
146144 }
147- // flat2 = flat_mask5(1, s[-8..-5], p0, q0, s[4..7]) with the C
148- // call's shifted parameter names: p7..p4 and q4..q6 compare
149- // against p0, while the outermost q7 compares against q0; q0..q3
150- // and p1..p3 are not tested at all.
145+ // flat_mask5(1, s[-8], s[-7], s[-6], s[-5], p0, q0, s[4], s[5], s[6], s[7]):
146+ // |p7..p4 - p0| and |q4..q7 - q0| (the C names are shifted; q4..q6
147+ // are the q1..q3 args of the inner flat_mask4 and compare to q0).
151148 let flat2 = (rd!(-8) - rd!(-1)).abs() <= 1
152149 && (rd!(-7) - rd!(-1)).abs() <= 1
153150 && (rd!(-6) - rd!(-1)).abs() <= 1
154151 && (rd!(-5) - rd!(-1)).abs() <= 1
155- && (rd!(4) - rd!(-1)).abs() <= 1
156- && (rd!(5) - rd!(-1)).abs() <= 1
157- && (rd!(6) - rd!(-1)).abs() <= 1
152+ && (rd!(4) - rd!(0)).abs() <= 1
153+ && (rd!(5) - rd!(0)).abs() <= 1
154+ && (rd!(6) - rd!(0)).abs() <= 1
158155 && (rd!(7) - rd!(0)).abs() <= 1;
159156 if !flat2 {
160157 let (p3, p2, p1, p0, q0, q1, q2, q3) = (
@@ -348,7 +345,7 @@ impl LfGrids {
348345 let (bl, li, th) = limits(level, sharpness);
349346 let off = r4 * 4 * stride + c4 * 4;
350347 if y_w >= c4 * 4 + 4 {
351- lpf_edge(y, off, stride, 1, taps, bl, li, th);
348+ lpf_edge(y, off, stride, 1, taps, bl, li, th, 4);
352349 if std::env::var_os("LFTRACE").is_some() {
353350 let kind = match taps {
354351 16 => "V16",
@@ -406,7 +403,7 @@ impl LfGrids {
406403 let (bl, li, th) = limits(level, sharpness);
407404 let off = r4 * 4 * stride + c4 * 4;
408405 if y_h >= r4 * 4 + 4 {
409- lpf_edge(y, off, stride, 0, taps, bl, li, th);
406+ lpf_edge(y, off, stride, 0, taps, bl, li, th, 4);
410407 if std::env::var_os("LFTRACE").is_some() {
411408 let kind = match taps {
412409 16 => "H16",
@@ -418,13 +415,15 @@ impl LfGrids {
418415 }
419416 }
420417 }
421- // Chroma (4:2:0): one 4x4 chroma TU per MI, so the only filtered
422- // edges are the MI boundaries (vp9_filter_block_plane_ss11):
423- // vertical on every MI column boundary, horizontal on every MI
424- // row boundary, taps from the plane's uv transform size.
418+ // Chroma 4:2:0 (vp9_filter_block_plane_ss11): MI is 4 chroma
419+ // pixels. Edges follow uv tx size, not every MI — TX_8 every 8
420+ // chroma px (2 MI), TX_16/32 every 16/32. TX_4 hits every MI
421+ // (int_4x4_uv is those odd columns).
425422 for data in [&mut *u, &mut *v] {
426- // Vertical: left edge of each MI (except the leftmost column).
427423 for r in 0..self.mi_rows {
424+ if r % 2 != 0 {
425+ continue;
426+ }
428427 for c in 1..self.mi_cols {
429428 let cell = r * self.mi_cols + c;
430429 let (bsize, _bor, _boc) = self.blk[cell];
@@ -433,22 +432,27 @@ impl LfGrids {
433432 continue;
434433 }
435434 let uv_tx = uv_txsize_lookup(bsize as usize, self.otx[cell] as usize);
435+ let step = 1usize << uv_tx;
436+ if c % step != 0 {
437+ continue;
438+ }
436439 let taps = match uv_tx {
437- TX_16X16 if c * 4 >= 8 && c * 4 + 8 <= uv_w => 16,
438- TX_16X16 => 8,
439- TX_8X8 => 8,
440+ TX_16X16 | TX_32X32 if c * 4 >= 8 && c * 4 + 8 <= uv_w => 16,
441+ TX_16X16 | TX_32X32 | TX_8X8 => 8,
440442 _ => 4,
441443 };
442444 let (bl, li, th) = limits(level, sharpness);
443445 let off = r * 4 * uv_stride + c * 4;
444446 if uv_w >= c * 4 + 4 {
445- lpf_edge(data, off, uv_stride, 1, taps, bl, li, th);
447+ lpf_edge(data, off, uv_stride, 1, taps, bl, li, th, 8);
446448 }
447449 }
448450 }
449- // Horizontal: top edge of each MI (except the top row).
450451 for r in 1..self.mi_rows {
451452 for c in 0..self.mi_cols {
453+ if c % 2 != 0 {
454+ continue;
455+ }
452456 let cell = r * self.mi_cols + c;
453457 let (bsize, _bor, _boc) = self.blk[cell];
454458 let level = self.level8[cell];
@@ -456,16 +460,19 @@ impl LfGrids {
456460 continue;
457461 }
458462 let uv_tx = uv_txsize_lookup(bsize as usize, self.otx[cell] as usize);
463+ let step = 1usize << uv_tx;
464+ if r % step != 0 {
465+ continue;
466+ }
459467 let taps = match uv_tx {
460- TX_16X16 if r * 4 >= 8 && r * 4 + 8 <= uv_h => 16,
461- TX_16X16 => 8,
462- TX_8X8 => 8,
468+ TX_16X16 | TX_32X32 if r * 4 >= 8 && r * 4 + 8 <= uv_h => 16,
469+ TX_16X16 | TX_32X32 | TX_8X8 => 8,
463470 _ => 4,
464471 };
465472 let (bl, li, th) = limits(level, sharpness);
466473 let off = r * 4 * uv_stride + c * 4;
467474 if uv_h >= r * 4 + 4 {
468- lpf_edge(data, off, uv_stride, 0, taps, bl, li, th);
475+ lpf_edge(data, off, uv_stride, 0, taps, bl, li, th, 8);
469476 }
470477 }
471478 }
crates/ec-vp9/src/modes.rsmodified+6 -0
@@ -262,5 +262,11 @@ pub(crate) fn read_intra_frame_mode_info(
262262 // uv mode: `vp9_kf_uv_mode_prob` indexed by y mode, decoded with the
263263 // SAME intra_mode_tree (decodemv.c:232 calls read_intra_mode).
264264 mi.uv_mode = r.read_tree(&INTRA_MODE_TREE, &kf_uv_probs(mi.mode));
265+ if crate::trace_enabled() {
266+ eprintln!(
267+ "MODE row={} col={} bsize={} skip={} tx={} y={} uv={}",
268+ row, col, sb_type, mi.skip as u8, mi.tx_size, mi.mode, mi.uv_mode
269+ );
270+ }
265271 Ok(mi)
266272 }
crates/ec-vp9/src/tokens.rsmodified+4 -1
@@ -80,6 +80,9 @@ pub(crate) fn decode_coefs(
8080 }
8181
8282 while c < max_eob {
83+ if crate::trace_enabled() {
84+ eprintln!("TOK c={c} band={band} ctx={ctx} p0={},{},{}", prob[0], prob[1], prob[2]);
85+ }
8386 if !r.read_bool(prob[0]) {
8487 break;
8588 }
@@ -146,7 +149,7 @@ pub(crate) fn decode_coefs(
146149 coef.eob = c;
147150 if crate::trace_enabled() {
148151 eprintln!(
149- "C p={} x={} y={} tx={} eob={} c0={}",
152+ "EOB p={} x={} y={} tx={} eob={} c0={}",
150153 plane, pos.0, pos.1, tx_size, c, coef.coeffs[0]
151154 );
152155 }
crates/ec-vp9/src/transform.rsmodified+18 -1
@@ -417,7 +417,24 @@ pub(crate) fn idct32(input: &[i32], output: &mut [i32]) {
417417 step1[13] = step2[2] - step2[13];
418418 step1[14] = step2[1] - step2[14];
419419 step1[15] = step2[0] - step2[15];
420- step1[16..32].copy_from_slice(&step2[16..32]);
420+ // stage 8 (inv_txfm.c:1120): cospi_16 rotation of 20..27 before the
421+ // final combine — omitting it desyncs every 32x32 residual.
422+ step1[16] = step2[16];
423+ step1[17] = step2[17];
424+ step1[18] = step2[18];
425+ step1[19] = step2[19];
426+ step1[20] = dcrs((-g(step2[20]) + g(step2[27])) * C16);
427+ step1[27] = dcrs((g(step2[20]) + g(step2[27])) * C16);
428+ step1[21] = dcrs((-g(step2[21]) + g(step2[26])) * C16);
429+ step1[26] = dcrs((g(step2[21]) + g(step2[26])) * C16);
430+ step1[22] = dcrs((-g(step2[22]) + g(step2[25])) * C16);
431+ step1[25] = dcrs((g(step2[22]) + g(step2[25])) * C16);
432+ step1[23] = dcrs((-g(step2[23]) + g(step2[24])) * C16);
433+ step1[24] = dcrs((g(step2[23]) + g(step2[24])) * C16);
434+ step1[28] = step2[28];
435+ step1[29] = step2[29];
436+ step1[30] = step2[30];
437+ step1[31] = step2[31];
421438 for i in 0..16 {
422439 output[i] = step1[i] + step1[31 - i];
423440 output[31 - i] = step1[i] - step1[31 - i];
crates/ec-vp9/tests/scratch_lfdump.rsmodified+31 -8
@@ -18,8 +18,8 @@ fn ffmpeg_raw_yuv(path: &std::path::Path) -> Vec<u8> {
1818
1919 #[test]
2020 fn dump_lf_diff_map() {
21- let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
22- .join("../../fixtures/vp9/key-320.ivf");
21+ let path =
22+ std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vp9/key-320.ivf");
2323 let bytes = std::fs::read(&path).unwrap();
2424 let (_f, _w, _h, frames) = ivf::parse_ivf(&bytes);
2525 let reference = ffmpeg_raw_yuv(&path);
@@ -44,12 +44,9 @@ fn dump_lf_diff_map() {
4444 let pre = &pic_pre.y[..ysz];
4545 let post = &pic_post.y[..ysz];
4646
47- let pre_diffs: Vec<usize> =
48- (0..ysz).filter(|&i| pre[i] != ff[i]).collect();
49- let post_diffs: Vec<usize> =
50- (0..ysz).filter(|&i| post[i] != ff[i]).collect();
51- let lf_changed_ours: Vec<usize> =
52- (0..ysz).filter(|&i| pre[i] != post[i]).collect();
47+ let pre_diffs: Vec<usize> = (0..ysz).filter(|&i| pre[i] != ff[i]).collect();
48+ let post_diffs: Vec<usize> = (0..ysz).filter(|&i| post[i] != ff[i]).collect();
49+ let lf_changed_ours: Vec<usize> = (0..ysz).filter(|&i| pre[i] != post[i]).collect();
5350 println!("pre-LF diffs vs ffmpeg : {}", pre_diffs.len());
5451 println!("post-LF diffs vs ffmpeg: {}", post_diffs.len());
5552 println!("pixels our LF changed : {}", lf_changed_ours.len());
@@ -107,4 +104,30 @@ fn dump_lf_diff_map() {
107104 "diff rows>0 : {:?}",
108105 (0..h).filter(|&r| rows[r] > 0).take(24).collect::<Vec<_>>()
109106 );
107+ let uv = (w / 2) * (h / 2);
108+ let ff_u = &reference[ysz..ysz + uv];
109+ let ff_v = &reference[ysz + uv..ysz + 2 * uv];
110+ let uw = w / 2;
111+ let u_d: Vec<_> = (0..uv).filter(|&i| pic_post.u[i] != ff_u[i]).collect();
112+ let v_d: Vec<_> = (0..uv).filter(|&i| pic_post.v[i] != ff_v[i]).collect();
113+ println!("U post diffs: {}", u_d.len());
114+ for &i in u_d.iter().take(12) {
115+ println!(
116+ " U ({}, {}) ours {} ff {}",
117+ i % uw,
118+ i / uw,
119+ pic_post.u[i],
120+ ff_u[i]
121+ );
122+ }
123+ println!("V post diffs: {}", v_d.len());
124+ for &i in v_d.iter().take(12) {
125+ println!(
126+ " V ({}, {}) ours {} ff {}",
127+ i % uw,
128+ i / uw,
129+ pic_post.v[i],
130+ ff_v[i]
131+ );
132+ }
110133 }
lanes/vp9kf.report.mdmodified+18 -0
@@ -321,3 +321,21 @@ block ~207 (MI row 3, col 11 area).
321321 profile1_444 all PASS; keyframes_match_ffmpeg FAIL, first diff (76,2)
322322 ours 47 ref 48. NOT pushed (gate not green). Branch lane-vp9-kf has the
323323 three loopfilter fixes + probe hooks + scratch_lfdump.
324+
325+## HANDOFF #6 (main session after flash 429, 2026-09-14)
326+
327+Pre-LF Y vs libvpx SKIPLF: **0 diffs** (the 684 figure was ffmpeg-with-LF vs our SKIP_LF).
328+Post-LF Y vs ffmpeg: **0 diffs**.
329+
330+Fixes this round:
331+1. generic d153 wrote `dst[(r+1)*stride + 2+c]` so row 1 leaked 128s. Now `dst[r*stride+2+c] = dst[(r-1)*stride+c]` (vpx `dst[r][2+c] = dst[r-1][c]`).
332+2. idct32 was missing vpx stage 8 (`inv_txfm.c:1120`) cospi_16 rotation of 20..27.
333+3. **flat2 was wrong.** `flat_mask5(1, s[-8]..s[-5], p0, q0, s[4]..s[7])` compares q4..q7 to **q0**, not p0. HANDOFF #5's "q4..q6 vs p0" misread the C parameter names. That was the 8 Y pixels at row 2 cols 76-86 (V16 at x=80 fell into filter8).
334+4. Chroma was filtering every MI (4 px) regardless of uv tx. Now step `1<<uv_tx` (TX_8 every 2 MI, TX_16/32 every 4/8) and 8-line kernels. U 179→16, V 100→20.
335+
336+**Still FAIL:** `keyframes_match_ffmpeg` first miss U(31,11) 111 vs 110. 16 U + 20 V left. Y exact. lossless_64 PASS. inter named-Error PASS. lib 8/8.
337+
338+Next: chroma ss11 at U(31,11) — likely remaining 4-vs-8 dual threshold or TX_32 uv bucket (ss11 never reads `left_uv[TX_32]`). Do not touch luma LF; it is byte-exact.
339+
340+Flash 429 until 2026-09-18 19:27. Continue on main grok.
341+