R1 bisect -- falsify the compound-blend arithmetic hypothesis
Browse files at this commit793125d846e0658fe5d5ac663ef90b5051b25adbParent: 0b7c477- fix
- r1 bisect -- falsify the compound-blend arithmetic hypothesis
2 changed files +103 -30
- crates/ec-av1/src/decode.rs +85 -30
- crates/ec-av1/src/stream.rs +18 -0
crates/ec-av1/src/decode.rsmodified+85 -30
| @@ -2499,6 +2499,12 @@ fn cdef_filter_block( | |||
| 2499 | // aomdec's EC_AV1_PREFILT_DUMP/EC_AV1_POSTFILT_DUMP) to `$var.f$idx` when | 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. | 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); | 2501 | static R17_DUMP_FRAME_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 2502 | +// r17 bisect scratch accessor for stream.rs's own debug prints -- shares the | ||
| 2503 | +// same counter block-decode already reads. Remove with the rest of the r17 | ||
| 2504 | +// bisect scaffolding. | ||
| 2505 | +pub fn r17_dump_frame_idx() -> usize { | ||
| 2506 | + R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed) | ||
| 2507 | +} | ||
| 2502 | fn r17_dump(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, idx: usize) { | 2508 | fn r17_dump(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, idx: usize) { |
| 2503 | let Ok(base) = std::env::var(var) else { | 2509 | let Ok(base) = std::env::var(var) else { |
| 2504 | return; | 2510 | return; |
| @@ -4466,33 +4472,59 @@ fn decode_inter_block( | |||
| 4466 | weighted/simple-average combine only, lane-av1comp", | 4472 | weighted/simple-average combine only, lane-av1comp", |
| 4467 | )); | 4473 | )); |
| 4468 | } | 4474 | } |
| 4469 | - // corner-cut (lane-av1comp r16/r17): a real aomenc stream | 4475 | + // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17 |
| 4470 | - // (fixtures/av1comp-r16-compound-mismatch.obu, seed 42) proved | 4476 | + // called this a `predict_compound_intermediate`/`combine_compound` |
| 4471 | - // predict_compound_intermediate/combine_compound wrong by up to | 4477 | + // reconstruction defect. r1 FALSIFIED that hypothesis outright: |
| 4472 | - // 4/255 in a 32x32 quadrant, spilling a few pixels into | 4478 | + // unmasking and running the real gates |
| 4473 | - // neighbours. r16 called this "loop-filter-shaped"; r17 | 4479 | + // (a_real_aomenc_stream_with_reference_select_reads_comp_mode_correctly, |
| 4474 | - // FALSIFIED that -- dumping this decoder's own pre-deblock | 4480 | + // a_real_aomenc_stream_with_compound_references_decodes_pixel_exact) |
| 4475 | - // frame buffer (`r17_dump`, `EC_AV1_PREFILT_DUMP`) against | 4481 | + // shows the plain-average blend is bit-exact *most of the time* |
| 4476 | - // aomdec's own `EC_AV1_PREFILT_DUMP` shows the same 32x32- | 4482 | + // -- `combine_compound`'s two-shift-in-one round2 was proven |
| 4477 | - // quadrant mismatch already present *before* either decoder's | 4483 | + // algebraically identical to libaom's separate |
| 4478 | - // loop filter runs (898/1024 px, rows 32-63 cols 32-63 of a | 4484 | + // `>>DIST_PRECISION_BITS`-then-`ROUND_POWER_OF_TWO` sequence |
| 4479 | - // 64x64 luma plane, frame index 2 zero-based / this decoder's | 4485 | + // (av1_dist_wtd_convolve_2d_c, convolve.c:402-415) for every |
| 4480 | - // 3rd frame) -- this is a `predict_compound_intermediate`/ | 4486 | + // input, and a whole-pel zero-MV compound block (mv0=mv1=(0,0), |
| 4481 | - // `combine_compound` reconstruction defect, not a deblock | 4487 | + // the common case a lag-in-frames GOP's hidden altref frames |
| 4482 | - // interaction. DRL/assign_compound_mv/dist_wtd_comp_weight_assign | 4488 | + // hit) reproduces aomdec's own pre-deblock `EC_AV1_PREFILT_DUMP` |
| 4483 | - // stay cross-checked bit-for-bit against libaom decodemv.c/ | 4489 | + // byte-for-byte for several consecutive frames. |
| 4484 | - // reconinter.c (r16). Root cause still not isolated within this | 4490 | + // |
| 4485 | - // arithmetic; refuse by name rather than ship a non-pixel-exact | 4491 | + // The real defect a live gate run isolated (seed 49, |
| 4486 | - // compound blend. Ceiling: r13/r14's MC plumbing above this line | 4492 | + // `fixtures/av1blend-r1-mismatch.obu`): decode-order frame 0 |
| 4493 | + // (keyframe) and frame 1 (first hidden altref, `ref1 == | ||
| 4494 | + // ALTREF_FRAME`) match aomdec's own pre-deblock dump byte for | ||
| 4495 | + // byte; decode-order frame 2 -- same shape, same zero MV, only | ||
| 4496 | + // difference `ref1 == BWDREF_FRAME` instead of `ALTREF_FRAME` -- | ||
| 4497 | + // is the *first* frame to diverge (881/6144 luma+chroma bytes). | ||
| 4498 | + // Every later frame up through decode-order 9 also mismatches, | ||
| 4499 | + // *including* frame 8, whose four blocks are back to | ||
| 4500 | + // `ref1 == ALTREF_FRAME` only -- ruling out "BWDREF_FRAME's MC | ||
| 4501 | + // math is wrong" (that block's own math is proven exact) in | ||
| 4502 | + // favour of "the picture sitting in some DPB slot is already | ||
| 4503 | + // wrong by the time frame 2 reads it, and the corruption | ||
| 4504 | + // propagates through refresh_frame_flags into every later | ||
| 4505 | + // reference regardless of which named ref a later block picks". | ||
| 4506 | + // Frames 10 through 18 (once the GOP's lineage stops tracing | ||
| 4507 | + // back through the bad slot) are bit-exact again. This points at | ||
| 4508 | + // reference-slot bookkeeping (`ref_slots`/`refresh_frame_flags` | ||
| 4509 | + // in `stream.rs`'s `decode_stream`, or `ref_order_hints`/DPB | ||
| 4510 | + // indexing feeding `dist_wtd_comp_weight_assign`) around | ||
| 4511 | + // BWDREF_FRAME specifically, not at the MC/blend arithmetic in | ||
| 4512 | + // mc.rs. Not isolated further within lane-av1blend's budget -- | ||
| 4513 | + // refuse by name rather than ship a blend that is right only | ||
| 4514 | + // sometimes. Ceiling: r13/r14's MC plumbing above this line | ||
| 4487 | // stays -- only the plain-average reconstruct is masked off | 4515 | // stays -- only the plain-average reconstruct is masked off |
| 4488 | - // again. Upgrade: bisect predict_compound_intermediate itself | 4516 | + // again. Upgrade: instrument `ref_slots`/`refresh_frame_flags` |
| 4489 | - // (subpel filter taps / rounding) against the pinned fixture's | 4517 | + // per decode-order frame (which slot each `Frame` OBU refreshes, |
| 4490 | - // 3rd frame, quadrant rows 32-63 cols 32-63. | 4518 | + // and which slot each `ref_frame_idx[BWDREF_FRAME - LAST_FRAME]` |
| 4519 | + // reads) against aomdec's own `RefCntBuffer` bookkeeping on | ||
| 4520 | + // `fixtures/av1blend-r1-mismatch.obu`, starting at decode-order | ||
| 4521 | + // frame 2. | ||
| 4491 | return Err(unsupported( | 4522 | return Err(unsupported( |
| 4492 | "a COMPOUND_REFERENCE block using the plain/distance-weighted \ | 4523 | "a COMPOUND_REFERENCE block using the plain/distance-weighted \ |
| 4493 | average blend (comp_group_idx == 0) -- proven non-pixel-exact \ | 4524 | average blend (comp_group_idx == 0) -- proven non-pixel-exact \ |
| 4494 | - against a real aomenc stream (lane-av1comp r16, see \ | 4525 | + against a real aomenc stream (lane-av1blend r1, see \ |
| 4495 | - av1comp-r16-compound-mismatch.obu)", | 4526 | + av1blend-r1-mismatch.obu: a reference-slot bug, not an MC/blend \ |
| 4527 | + arithmetic bug -- see the comment above)", | ||
| 4496 | )); | 4528 | )); |
| 4497 | #[allow(unreachable_code)] | 4529 | #[allow(unreachable_code)] |
| 4498 | let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { | 4530 | let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { |
| @@ -4553,6 +4585,20 @@ fn decode_inter_block( | |||
| 4553 | let mut pred_y = vec![0u8; side * side]; | 4585 | let mut pred_y = vec![0u8; side * side]; |
| 4554 | mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | 4586 | mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); |
| 4555 | 4587 | ||
| 4588 | + // r17 bisect scratch: dump per-block compound state when this | ||
| 4589 | + // block overlaps the pinned fixture's bad quadrant (frame 2, | ||
| 4590 | + // rows 32-63 cols 32-63). Remove with the rest of the scaffolding. | ||
| 4591 | + if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { | ||
| 4592 | + let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); | ||
| 4593 | + eprintln!( | ||
| 4594 | + "leaf16 fidx={fidx} px={px} py={py} side={side} ref0={ref0} ref1={ref1} \ | ||
| 4595 | + mv0={mv0:?} mv1={mv1:?} filter={resolved_filter:?} \ | ||
| 4596 | + fwd={fwd_offset} bck={bck_offset} compound_idx={compound_idx} \ | ||
| 4597 | + pred_y[0..4]={:?}", | ||
| 4598 | + &pred_y[0..4.min(pred_y.len())] | ||
| 4599 | + ); | ||
| 4600 | + } | ||
| 4601 | + | ||
| 4556 | let mut inter0_u = vec![0i32; chroma_side * chroma_side]; | 4602 | let mut inter0_u = vec![0i32; chroma_side * chroma_side]; |
| 4557 | mc::predict_compound_intermediate( | 4603 | mc::predict_compound_intermediate( |
| 4558 | &pu0.data, | 4604 | &pu0.data, |
| @@ -5327,16 +5373,16 @@ fn decode_inter_block8( | |||
| 5327 | weighted/simple-average combine only, lane-av1comp", | 5373 | weighted/simple-average combine only, lane-av1comp", |
| 5328 | )); | 5374 | )); |
| 5329 | } | 5375 | } |
| 5330 | - // corner-cut (lane-av1comp r16/r17): same non-pixel-exact | 5376 | + // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same |
| 5331 | - // plain-average reconstruction defect as the 16x16 leaf's | 5377 | + // reference-slot defect as the 16x16 leaf's own mask above |
| 5332 | - // own mask above (r17: falsified as loop-filter-shaped, | 5378 | + // (r1: falsified as an MC/blend math bug, isolated to a DPB |
| 5333 | - // isolated to predict_compound_intermediate/combine_compound | 5379 | + // slot/refresh_frame_flags issue around BWDREF_FRAME) -- see |
| 5334 | - // itself) -- see that comment. | 5380 | + // that comment. |
| 5335 | return Err(unsupported( | 5381 | return Err(unsupported( |
| 5336 | "a COMPOUND_REFERENCE 8x8 leaf using the plain/distance-weighted \ | 5382 | "a COMPOUND_REFERENCE 8x8 leaf using the plain/distance-weighted \ |
| 5337 | average blend (comp_group_idx == 0) -- proven non-pixel-exact \ | 5383 | average blend (comp_group_idx == 0) -- proven non-pixel-exact \ |
| 5338 | - against a real aomenc stream (lane-av1comp r16, see \ | 5384 | + against a real aomenc stream (lane-av1blend r1, see \ |
| 5339 | - av1comp-r16-compound-mismatch.obu)", | 5385 | + av1blend-r1-mismatch.obu)", |
| 5340 | )); | 5386 | )); |
| 5341 | #[allow(unreachable_code)] | 5387 | #[allow(unreachable_code)] |
| 5342 | let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { | 5388 | let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { |
| @@ -5424,6 +5470,15 @@ fn decode_inter_block8( | |||
| 5424 | let mut pred_y = vec![0u8; SIDE * SIDE]; | 5470 | let mut pred_y = vec![0u8; SIDE * SIDE]; |
| 5425 | mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | 5471 | mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); |
| 5426 | 5472 | ||
| 5473 | + if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { | ||
| 5474 | + let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); | ||
| 5475 | + eprintln!( | ||
| 5476 | + "leaf8 fidx={fidx} px={px} py={py} ref0={ref0} ref1={ref1} \ | ||
| 5477 | + mv0={mv0:?} mv1={mv1:?} fwd={fwd_offset} bck={bck_offset} \ | ||
| 5478 | + compound_idx={compound_idx} pred_y={pred_y:?}" | ||
| 5479 | + ); | ||
| 5480 | + } | ||
| 5481 | + | ||
| 5427 | let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | 5482 | let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; |
| 5428 | mc::predict_compound_intermediate( | 5483 | mc::predict_compound_intermediate( |
| 5429 | &pu0.data, | 5484 | &pu0.data, |
crates/ec-av1/src/stream.rsmodified+18 -0
| @@ -114,6 +114,12 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 114 | picture | 114 | picture |
| 115 | }; | 115 | }; |
| 116 | pictures.push(output); | 116 | pictures.push(output); |
| 117 | + if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { | ||
| 118 | + eprintln!( | ||
| 119 | + "PUSH (show_existing_frame slot {slot}) pictures.len()={}", | ||
| 120 | + pictures.len() | ||
| 121 | + ); | ||
| 122 | + } | ||
| 117 | continue; | 123 | continue; |
| 118 | } | 124 | } |
| 119 | let ObuKind::Frame(header, tiles) = obu.kind else { | 125 | let ObuKind::Frame(header, tiles) = obu.kind else { |
| @@ -434,6 +440,18 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 434 | picture | 440 | picture |
| 435 | }; | 441 | }; |
| 436 | pictures.push(output); | 442 | pictures.push(output); |
| 443 | + if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { | ||
| 444 | + eprintln!( | ||
| 445 | + "PUSH (shown-direct) pictures.len()={} <- decode.rs r17 fidx {}", | ||
| 446 | + pictures.len(), | ||
| 447 | + crate::decode::r17_dump_frame_idx() | ||
| 448 | + ); | ||
| 449 | + } | ||
| 450 | + } else if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { | ||
| 451 | + eprintln!( | ||
| 452 | + "HIDDEN frame decoded, not pushed <- decode.rs r17 fidx {}", | ||
| 453 | + crate::decode::r17_dump_frame_idx() | ||
| 454 | + ); | ||
| 437 | } | 455 | } |
| 438 | } | 456 | } |
| 439 | Ok(pictures) | 457 | Ok(pictures) |