R5 -- interp_filter read-order spec bug (real, inert on this fixture)
Browse files at this commit4d7335c0fd41bf6b3a83d45d4fa256b1bf1052ceParent: dc3404f- fix
- r5 -- interp_filter read-order spec bug (real, inert on this fixture)
- re-mask leaf16 blend, deepen compound_idx trace
1 changed file +85 -11
- crates/ec-av1/src/decode.rs +85 -11
crates/ec-av1/src/decode.rsmodified+85 -11
| @@ -4299,6 +4299,14 @@ fn decode_inter_block( | |||
| 4299 | let (cpx, cpy) = (px / 2, py / 2); | 4299 | let (cpx, cpy) = (px / 2, py / 2); |
| 4300 | let chroma_side = side / 2; | 4300 | let chroma_side = side / 2; |
| 4301 | 4301 | ||
| 4302 | + if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { | ||
| 4303 | + eprintln!( | ||
| 4304 | + "BITPOS_BLK_START mi_row={} mi_col={} bitpos={}", | ||
| 4305 | + py / 4, | ||
| 4306 | + px / 4, | ||
| 4307 | + dec.debug_bitpos() | ||
| 4308 | + ); | ||
| 4309 | + } | ||
| 4302 | let skip_mode_ctx = | 4310 | let skip_mode_ctx = |
| 4303 | usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]); | 4311 | usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]); |
| 4304 | let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; | 4312 | let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; |
| @@ -4418,16 +4426,6 @@ fn decode_inter_block( | |||
| 4418 | } else { | 4426 | } else { |
| 4419 | [3, 3] | 4427 | [3, 3] |
| 4420 | }; | 4428 | }; |
| 4421 | - let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( | ||
| 4422 | - dec, | ||
| 4423 | - cdfs, | ||
| 4424 | - interp_fixed, | ||
| 4425 | - enable_dual_filter, | ||
| 4426 | - is_globalmv, | ||
| 4427 | - above_filter_ctx, | ||
| 4428 | - left_filter_ctx, | ||
| 4429 | - ); | ||
| 4430 | - block_filter = resolved_filter; | ||
| 4431 | globalmv_for_lf = is_globalmv; | 4429 | globalmv_for_lf = is_globalmv; |
| 4432 | ref_frame_for_lf = ref0; | 4430 | ref_frame_for_lf = ref0; |
| 4433 | mode_for_tx = 0; | 4431 | mode_for_tx = 0; |
| @@ -4600,6 +4598,52 @@ fn decode_inter_block( | |||
| 4600 | // read specifically, not just the surrounding mode/mv/skip | 4598 | // read specifically, not just the surrounding mode/mv/skip |
| 4601 | // trace which does match -- the desync (if any) is local to | 4599 | // trace which does match -- the desync (if any) is local to |
| 4602 | // this one read, not a wider stream desync. | 4600 | // this one read, not a wider stream desync. |
| 4601 | + // | ||
| 4602 | + // r5 (this round): the `resolve_interp_filter` call used to sit | ||
| 4603 | + // right here, ahead of `comp_group_idx`/`compound_idx` -- spec | ||
| 4604 | + // 5.11.19/libaom `decodemv.c:1575` reads `interp_filter` AFTER | ||
| 4605 | + // `read_compound_type`, not before, so that was a genuine | ||
| 4606 | + // ordering bug for a Switchable-filter frame (moved below, past | ||
| 4607 | + // the `compound_ctx = Some(...)` line). It does NOT explain this | ||
| 4608 | + // fixture's own mismatch, though: `av1blend-r1-mismatch.obu`'s | ||
| 4609 | + // header carries a *fixed* interpolation filter | ||
| 4610 | + // (`interp_fixed = Some(Regular)`, confirmed live via a | ||
| 4611 | + // one-off dump), so `resolve_interp_filter` never read a symbol | ||
| 4612 | + // in either position -- zero bits moved, decoded values | ||
| 4613 | + // unchanged before and after the reorder. Kept anyway: it is a | ||
| 4614 | + // real spec-order fix for the next Switchable-filter compound | ||
| 4615 | + // stream, independently correct regardless of this fixture. | ||
| 4616 | + // | ||
| 4617 | + // Also ruled out this round: comparing this crate's own | ||
| 4618 | + // `SymbolDecoder::debug_bitpos()` against aomdec's | ||
| 4619 | + // `aom_reader_tell()` at the block boundary is NOT a valid | ||
| 4620 | + // desync probe -- they are different quantities (raw consumed | ||
| 4621 | + // input bits vs. an entropy-cost estimate that advances without | ||
| 4622 | + // a literal byte fetch), so equal/unequal bitpos proves nothing | ||
| 4623 | + // either way. Do not repeat that comparison; instead trace | ||
| 4624 | + // `range`/`value` (this crate) against libaom's own internal | ||
| 4625 | + // `dif`/`rng` (needs new instrumentation in both) immediately | ||
| 4626 | + // after each read *upstream* of this one in the same block: | ||
| 4627 | + // `read_comp_mode`, `read_compound_ref_frames` (comp_ref_type/ | ||
| 4628 | + // uni_comp_ref/comp_ref/comp_bwdref), `read_inter_compound_mode`, | ||
| 4629 | + // and the DRL loop. All of those independently decoded the SAME | ||
| 4630 | + // values this crate and aomdec both show (ref0=1, ref1=5, mode | ||
| 4631 | + // NEAREST_NEARESTMV, mv=(0,0)) -- but an upstream *context* | ||
| 4632 | + // miscomputation can still decode the identical symbol value off | ||
| 4633 | + // a slightly different CDF, narrowing `range` by a different | ||
| 4634 | + // amount than aomdec without changing the decoded value itself, | ||
| 4635 | + // and only surface as a wrong decode a few reads later exactly | ||
| 4636 | + // like this. `get_comp_index_context` and the `COMPOUND_IDX` | ||
| 4637 | + // table were independently re-verified again this round and are | ||
| 4638 | + // still correct; the four candidates above were not re-audited | ||
| 4639 | + // this round. Refusing here (rather than shipping a value-exact- | ||
| 4640 | + // most-of-the-time blend) until one of them is found wrong. | ||
| 4641 | + return Err(unsupported( | ||
| 4642 | + "a COMPOUND_REFERENCE 16x16 leaf using the plain/distance-weighted average \ | ||
| 4643 | + blend (comp_group_idx == 0) -- proven non-pixel-exact against a real aomenc \ | ||
| 4644 | + stream (lane-av1blend r1/r3/r5, see av1blend-r1-mismatch.obu)", | ||
| 4645 | + )); | ||
| 4646 | + #[allow(unreachable_code)] | ||
| 4603 | let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { | 4647 | let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { |
| 4604 | let idx_ctx = get_comp_index_context( | 4648 | let idx_ctx = get_comp_index_context( |
| 4605 | neighbours, | 4649 | neighbours, |
| @@ -4622,7 +4666,12 @@ fn decode_inter_block( | |||
| 4622 | } | 4666 | } |
| 4623 | let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); | 4667 | let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); |
| 4624 | if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { | 4668 | if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { |
| 4625 | - eprintln!("COMPIDX_VAL mi_row={} mi_col={} decoded={idx}", py / 4, px / 4); | 4669 | + eprintln!( |
| 4670 | + "COMPIDX_VAL mi_row={} mi_col={} decoded={idx} bitpos={}", | ||
| 4671 | + py / 4, | ||
| 4672 | + px / 4, | ||
| 4673 | + dec.debug_bitpos() | ||
| 4674 | + ); | ||
| 4626 | } | 4675 | } |
| 4627 | if idx == 1 { | 4676 | if idx == 1 { |
| 4628 | (8, 8, 1u8) | 4677 | (8, 8, 1u8) |
| @@ -4640,6 +4689,31 @@ fn decode_inter_block( | |||
| 4640 | }; | 4689 | }; |
| 4641 | compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx)); | 4690 | compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx)); |
| 4642 | 4691 | ||
| 4692 | + // spec 5.11.19/libaom `decodemv.c` 1575: `read_mb_interp_filter` | ||
| 4693 | + // comes AFTER `read_compound_type` (the `comp_group_idx`/ | ||
| 4694 | + // `compound_idx` reads just above), not before -- moved here | ||
| 4695 | + // (lane-av1blend r5) from its old position ahead of those reads, | ||
| 4696 | + // which stole their bits for a Switchable-filter compound block | ||
| 4697 | + // and desynced every symbol read after it in the tile. | ||
| 4698 | + if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { | ||
| 4699 | + eprintln!( | ||
| 4700 | + "IFILTER_PRE mi_row={} mi_col={} interp_fixed={:?} is_globalmv={is_globalmv}", | ||
| 4701 | + py / 4, | ||
| 4702 | + px / 4, | ||
| 4703 | + interp_fixed | ||
| 4704 | + ); | ||
| 4705 | + } | ||
| 4706 | + let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( | ||
| 4707 | + dec, | ||
| 4708 | + cdfs, | ||
| 4709 | + interp_fixed, | ||
| 4710 | + enable_dual_filter, | ||
| 4711 | + is_globalmv, | ||
| 4712 | + above_filter_ctx, | ||
| 4713 | + left_filter_ctx, | ||
| 4714 | + ); | ||
| 4715 | + block_filter = resolved_filter; | ||
| 4716 | + | ||
| 4643 | let mut inter0_y = vec![0i32; side * side]; | 4717 | let mut inter0_y = vec![0i32; side * side]; |
| 4644 | mc::predict_compound_intermediate( | 4718 | mc::predict_compound_intermediate( |
| 4645 | &py0.data, | 4719 | &py0.data, |