R17 bisect -- falsify loop-filter hypothesis for the masked compound blend
Browse files at this commit80caed57ac349992e54c1d30d9a009e0510c5365Parent: 232e604- fix
- r17 bisect -- falsify loop-filter hypothesis for the masked compound blend
2 changed files +66 -14
- crates/ec-av1/src/decode.rs +50 -14
- crates/ec-av1/src/stream.rs +16 -0
crates/ec-av1/src/decode.rsmodified+50 -14
| @@ -2495,6 +2495,27 @@ fn cdef_filter_block( | |||
| 2495 | /// | 2495 | /// |
| 2496 | /// Ported from libaom's `av1/common/av1_loopfilter.c` (edge/level decision) | 2496 | /// Ported from libaom's `av1/common/av1_loopfilter.c` (edge/level decision) |
| 2497 | /// and `aom_dsp/loopfilter.c` (the `aom_lpf_*` pixel kernels). | 2497 | /// and `aom_dsp/loopfilter.c` (the `aom_lpf_*` pixel kernels). |
| 2498 | +// r17 bisect scratch: dump this frame's true-extent Y/U/V (same layout as | ||
| 2499 | +// aomdec's EC_AV1_PREFILT_DUMP/EC_AV1_POSTFILT_DUMP) to `$var.f$idx` when | ||
| 2500 | +// `var` is set. Remove with the rest of the r17 bisect scaffolding. | ||
| 2501 | +static R17_DUMP_FRAME_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | ||
| 2502 | +fn r17_dump(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, idx: usize) { | ||
| 2503 | + let Ok(base) = std::env::var(var) else { | ||
| 2504 | + return; | ||
| 2505 | + }; | ||
| 2506 | + let mut out = Vec::new(); | ||
| 2507 | + for r in 0..y.true_height { | ||
| 2508 | + out.extend_from_slice(&y.data[r * y.width..r * y.width + y.true_width]); | ||
| 2509 | + } | ||
| 2510 | + for r in 0..u.true_height { | ||
| 2511 | + out.extend_from_slice(&u.data[r * u.width..r * u.width + u.true_width]); | ||
| 2512 | + } | ||
| 2513 | + for r in 0..v.true_height { | ||
| 2514 | + out.extend_from_slice(&v.data[r * v.width..r * v.width + v.true_width]); | ||
| 2515 | + } | ||
| 2516 | + let _ = std::fs::write(format!("{base}.f{idx}"), out); | ||
| 2517 | +} | ||
| 2518 | + | ||
| 2498 | fn apply_deblock( | 2519 | fn apply_deblock( |
| 2499 | y: &mut PlaneBuf, | 2520 | y: &mut PlaneBuf, |
| 2500 | u: &mut PlaneBuf, | 2521 | u: &mut PlaneBuf, |
| @@ -4445,18 +4466,28 @@ fn decode_inter_block( | |||
| 4445 | weighted/simple-average combine only, lane-av1comp", | 4466 | weighted/simple-average combine only, lane-av1comp", |
| 4446 | )); | 4467 | )); |
| 4447 | } | 4468 | } |
| 4448 | - // corner-cut (lane-av1comp r16): a real aomenc stream (fixtures/ | 4469 | + // corner-cut (lane-av1comp r16/r17): a real aomenc stream |
| 4449 | - // av1comp-r16-compound-mismatch.obu, seed 42) proved | 4470 | + // (fixtures/av1comp-r16-compound-mismatch.obu, seed 42) proved |
| 4450 | // predict_compound_intermediate/combine_compound wrong by up to | 4471 | // predict_compound_intermediate/combine_compound wrong by up to |
| 4451 | - // 4/255 in a ~30x32 patch of one 32x32 quadrant, spilling a few | 4472 | + // 4/255 in a 32x32 quadrant, spilling a few pixels into |
| 4452 | - // pixels into neighbours (loop-filter-shaped, not a desync -- | 4473 | + // neighbours. r16 called this "loop-filter-shaped"; r17 |
| 4453 | - // DRL/assign_compound_mv/dist_wtd_comp_weight_assign all cross- | 4474 | + // FALSIFIED that -- dumping this decoder's own pre-deblock |
| 4454 | - // checked bit-for-bit against libaom decodemv.c/reconinter.c and | 4475 | + // frame buffer (`r17_dump`, `EC_AV1_PREFILT_DUMP`) against |
| 4455 | - // matched). Root cause not yet isolated; refuse by name rather | 4476 | + // aomdec's own `EC_AV1_PREFILT_DUMP` shows the same 32x32- |
| 4456 | - // than ship a non-pixel-exact compound blend. Ceiling: r13/r14's | 4477 | + // quadrant mismatch already present *before* either decoder's |
| 4457 | - // MC plumbing above this line stays -- only the plain-average | 4478 | + // loop filter runs (898/1024 px, rows 32-63 cols 32-63 of a |
| 4458 | - // reconstruct is masked off again. Upgrade: bisect against the | 4479 | + // 64x64 luma plane, frame index 2 zero-based / this decoder's |
| 4459 | - // pinned fixture (frame 1, rows 16-31 cols 32-63). | 4480 | + // 3rd frame) -- this is a `predict_compound_intermediate`/ |
| 4481 | + // `combine_compound` reconstruction defect, not a deblock | ||
| 4482 | + // interaction. DRL/assign_compound_mv/dist_wtd_comp_weight_assign | ||
| 4483 | + // stay cross-checked bit-for-bit against libaom decodemv.c/ | ||
| 4484 | + // reconinter.c (r16). Root cause still not isolated within this | ||
| 4485 | + // arithmetic; refuse by name rather than ship a non-pixel-exact | ||
| 4486 | + // compound blend. Ceiling: r13/r14's MC plumbing above this line | ||
| 4487 | + // stays -- only the plain-average reconstruct is masked off | ||
| 4488 | + // again. Upgrade: bisect predict_compound_intermediate itself | ||
| 4489 | + // (subpel filter taps / rounding) against the pinned fixture's | ||
| 4490 | + // 3rd frame, quadrant rows 32-63 cols 32-63. | ||
| 4460 | return Err(unsupported( | 4491 | return Err(unsupported( |
| 4461 | "a COMPOUND_REFERENCE block using the plain/distance-weighted \ | 4492 | "a COMPOUND_REFERENCE block using the plain/distance-weighted \ |
| 4462 | average blend (comp_group_idx == 0) -- proven non-pixel-exact \ | 4493 | average blend (comp_group_idx == 0) -- proven non-pixel-exact \ |
| @@ -5296,9 +5327,11 @@ fn decode_inter_block8( | |||
| 5296 | weighted/simple-average combine only, lane-av1comp", | 5327 | weighted/simple-average combine only, lane-av1comp", |
| 5297 | )); | 5328 | )); |
| 5298 | } | 5329 | } |
| 5299 | - // corner-cut (lane-av1comp r16): same non-pixel-exact plain- | 5330 | + // corner-cut (lane-av1comp r16/r17): same non-pixel-exact |
| 5300 | - // average defect as the 16x16 leaf's own mask above -- see | 5331 | + // plain-average reconstruction defect as the 16x16 leaf's |
| 5301 | - // that comment. | 5332 | + // own mask above (r17: falsified as loop-filter-shaped, |
| 5333 | + // isolated to predict_compound_intermediate/combine_compound | ||
| 5334 | + // itself) -- see that comment. | ||
| 5302 | return Err(unsupported( | 5335 | return Err(unsupported( |
| 5303 | "a COMPOUND_REFERENCE 8x8 leaf using the plain/distance-weighted \ | 5336 | "a COMPOUND_REFERENCE 8x8 leaf using the plain/distance-weighted \ |
| 5304 | average blend (comp_group_idx == 0) -- proven non-pixel-exact \ | 5337 | average blend (comp_group_idx == 0) -- proven non-pixel-exact \ |
| @@ -6348,7 +6381,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 6348 | } | 6381 | } |
| 6349 | } | 6382 | } |
| 6350 | 6383 | ||
| 6384 | + let r17_idx = R17_DUMP_FRAME_IDX.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
| 6385 | + r17_dump("EC_AV1_PREFILT_DUMP", &y, &u, &v, r17_idx); | ||
| 6351 | apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); | 6386 | apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); |
| 6387 | + r17_dump("EC_AV1_POSTFILT_DUMP", &y, &u, &v, r17_idx); | ||
| 6352 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); | 6388 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); |
| 6353 | 6389 | ||
| 6354 | let motion_field = build_motion_field( | 6390 | let motion_field = build_motion_field( |
crates/ec-av1/src/stream.rsmodified+16 -0
| @@ -3090,6 +3090,22 @@ mod tests { | |||
| 3090 | a_real_aomenc_temporal_mv_gate(42, 40); | 3090 | a_real_aomenc_temporal_mv_gate(42, 40); |
| 3091 | } | 3091 | } |
| 3092 | 3092 | ||
| 3093 | + /// r17 bisect scratch: decode a pinned stream exactly once, so | ||
| 3094 | + /// `decode::r17_dump`'s frame index (a process-wide counter) lines up | ||
| 3095 | + /// with `aomdec`'s own per-frame `EC_AV1_PREFILT_DUMP`/ | ||
| 3096 | + /// `EC_AV1_POSTFILT_DUMP` numbering. Remove with the rest of the r17 | ||
| 3097 | + /// scaffolding. | ||
| 3098 | + #[test] | ||
| 3099 | + #[ignore] | ||
| 3100 | + fn scratch_decode_pinned_stream_once() { | ||
| 3101 | + let path = std::env::var("EC_AV1_PIN").expect("set EC_AV1_PIN to the .obu path"); | ||
| 3102 | + let stream = std::fs::read(&path).expect("read pinned stream"); | ||
| 3103 | + match decode_stream(&stream) { | ||
| 3104 | + Ok(frames) => eprintln!("OK: {} frames", frames.len()), | ||
| 3105 | + Err(e) => eprintln!("ERR: {e}"), | ||
| 3106 | + } | ||
| 3107 | + } | ||
| 3108 | + | ||
| 3093 | /// scratch: decode a pinned stream end to end and report where/why it | 3109 | /// scratch: decode a pinned stream end to end and report where/why it |
| 3094 | /// refuses, plus `non_last_ref_hits` progression. | 3110 | /// refuses, plus `non_last_ref_hits` progression. |
| 3095 | #[test] | 3111 | #[test] |