wip(av1): r2 -- interp filter ctx matches neighbour's SECOND ref too
Browse files at this commit49ec72b6b32af8d54efd5c61b577e3fbe8c65834Parent: 3ab7e162 changed files +74 -19
- crates/ec-av1/src/decode.rs +67 -19
- crates/ec-av1/src/stream.rs +7 -0
crates/ec-av1/src/decode.rsmodified+67 -19
| @@ -4437,12 +4437,24 @@ fn decode_inter_block( | ||
| 4437 | 4437 | let is_globalmv = compound_mode == 6; // GLOBAL_GLOBALMV |
| 4438 | 4438 | let (py0, pu0, pv0) = ref_planes(ref0, ref_y, ref_u, ref_v, other_refs)?; |
| 4439 | 4439 | let (py1, pu1, pv1) = ref_planes(ref1, ref_y, ref_u, ref_v, other_refs)?; |
| 4440 | - let above_filter_ctx = if neighbours.above_ref[c] == ref0 { | |
| 4440 | + // spec `get_ref_filter_type`: matches when EITHER of the | |
| 4441 | + // neighbour's two references equals this block's own ref0 -- | |
| 4442 | + // `above_ref1`/`left_ref1` is the neighbour's real second | |
| 4443 | + // reference (`record_compound_ctx`) when it was itself a | |
| 4444 | + // compound block; checking `above_ref`/`left_ref` alone drops a | |
| 4445 | + // real filter match down to the "no neighbour" sentinel | |
| 4446 | + // whenever the shared reference sits in the neighbour's SECOND | |
| 4447 | + // slot (lane-av1idx r2). | |
| 4448 | + let above_filter_ctx = if neighbours.above_ref[c] == ref0 | |
| 4449 | + || neighbours.above_ref1[c] == Some(ref0) | |
| 4450 | + { | |
| 4441 | 4451 | neighbours.above_filter[c] |
| 4442 | 4452 | } else { |
| 4443 | 4453 | [3, 3] |
| 4444 | 4454 | }; |
| 4445 | - let left_filter_ctx = if neighbours.left_ref[r] == ref0 { | |
| 4455 | + let left_filter_ctx = if neighbours.left_ref[r] == ref0 | |
| 4456 | + || neighbours.left_ref1[r] == Some(ref0) | |
| 4457 | + { | |
| 4446 | 4458 | neighbours.left_filter[r] |
| 4447 | 4459 | } else { |
| 4448 | 4460 | [3, 3] |
| @@ -4684,13 +4696,6 @@ fn decode_inter_block( | ||
| 4684 | 4696 | // Re-masking: see that fixture + `scratch_isolate_pinned_mismatch` |
| 4685 | 4697 | // (`EC_AV1_PIN=fixtures/av1idx-refsel-pin.obu EC_AV1_PIN_N=20`) |
| 4686 | 4698 | // for the next round's starting point. |
| 4687 | - return Err(unsupported( | |
| 4688 | - "a COMPOUND_REFERENCE 16x16 leaf using the plain/distance-weighted \ | |
| 4689 | - average blend (comp_group_idx == 0) -- proven non-pixel-exact against \ | |
| 4690 | - real aomenc streams beyond the bugs lane-av1blend r6/r7 and lane-av1idx \ | |
| 4691 | - r1 fixed (wide gate sweep, fixtures/av1idx-refsel-pin.obu)", | |
| 4692 | - )); | |
| 4693 | - #[allow(unreachable_code)] | |
| 4694 | 4699 | let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { |
| 4695 | 4700 | let idx_ctx = get_comp_index_context( |
| 4696 | 4701 | neighbours, |
| @@ -4750,6 +4755,20 @@ fn decode_inter_block( | ||
| 4750 | 4755 | interp_fixed |
| 4751 | 4756 | ); |
| 4752 | 4757 | } |
| 4758 | + if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { | |
| 4759 | + let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); | |
| 4760 | + eprintln!( | |
| 4761 | + "CREF fidx={fidx} mi_row={} mi_col={} side={side} ref0={ref0} ref1={ref1} \ | |
| 4762 | + above_ref={} left_ref={} above_ref1={:?} left_ref1={:?} \ | |
| 4763 | + above_filter_ctx={above_filter_ctx:?} left_filter_ctx={left_filter_ctx:?}", | |
| 4764 | + py / 4, | |
| 4765 | + px / 4, | |
| 4766 | + neighbours.above_ref[c], | |
| 4767 | + neighbours.left_ref[r], | |
| 4768 | + neighbours.above_ref1[c], | |
| 4769 | + neighbours.left_ref1[r], | |
| 4770 | + ); | |
| 4771 | + } | |
| 4753 | 4772 | let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( |
| 4754 | 4773 | dec, |
| 4755 | 4774 | cdfs, |
| @@ -4761,6 +4780,14 @@ fn decode_inter_block( | ||
| 4761 | 4780 | true, |
| 4762 | 4781 | ); |
| 4763 | 4782 | block_filter = resolved_filter; |
| 4783 | + if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { | |
| 4784 | + let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); | |
| 4785 | + eprintln!( | |
| 4786 | + "CREF_RESOLVED fidx={fidx} mi_row={} mi_col={} resolved={resolved_filter:?}", | |
| 4787 | + py / 4, | |
| 4788 | + px / 4, | |
| 4789 | + ); | |
| 4790 | + } | |
| 4764 | 4791 | |
| 4765 | 4792 | let mut inter0_y = vec![0i32; side * side]; |
| 4766 | 4793 | mc::predict_compound_intermediate( |
| @@ -5064,16 +5091,37 @@ fn decode_inter_block( | ||
| 5064 | 5091 | // exactly like an intra neighbour. Without this gate, a GOLDEN_FRAME |
| 5065 | 5092 | // block next to a LAST_FRAME one inherits that neighbour's filter |
| 5066 | 5093 | // choice into its own context, corrupting the symbol it reads. |
| 5067 | - let above_filter_ctx = if neighbours.above_ref[c] == ref_frame { | |
| 5094 | + // lane-av1idx r2: also match on the neighbour's SECOND reference | |
| 5095 | + // (`above_ref1`/`left_ref1`, real for a compound neighbour) -- | |
| 5096 | + // see the 16x16 leaf's own comment above for the spec citation. | |
| 5097 | + let above_filter_ctx = if neighbours.above_ref[c] == ref_frame | |
| 5098 | + || neighbours.above_ref1[c] == Some(ref_frame) | |
| 5099 | + { | |
| 5068 | 5100 | neighbours.above_filter[c] |
| 5069 | 5101 | } else { |
| 5070 | 5102 | [3, 3] |
| 5071 | 5103 | }; |
| 5072 | - let left_filter_ctx = if neighbours.left_ref[r] == ref_frame { | |
| 5104 | + let left_filter_ctx = if neighbours.left_ref[r] == ref_frame | |
| 5105 | + || neighbours.left_ref1[r] == Some(ref_frame) | |
| 5106 | + { | |
| 5073 | 5107 | neighbours.left_filter[r] |
| 5074 | 5108 | } else { |
| 5075 | 5109 | [3, 3] |
| 5076 | 5110 | }; |
| 5111 | + if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { | |
| 5112 | + let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); | |
| 5113 | + eprintln!( | |
| 5114 | + "SREF fidx={fidx} mi_row={} mi_col={} side={side} ref_frame={ref_frame} \ | |
| 5115 | + above_ref={} left_ref={} above_ref1={:?} left_ref1={:?} \ | |
| 5116 | + above_filter_ctx={above_filter_ctx:?} left_filter_ctx={left_filter_ctx:?}", | |
| 5117 | + py / 4, | |
| 5118 | + px / 4, | |
| 5119 | + neighbours.above_ref[c], | |
| 5120 | + neighbours.left_ref[r], | |
| 5121 | + neighbours.above_ref1[c], | |
| 5122 | + neighbours.left_ref1[r], | |
| 5123 | + ); | |
| 5124 | + } | |
| 5077 | 5125 | let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( |
| 5078 | 5126 | dec, |
| 5079 | 5127 | cdfs, |
| @@ -5084,6 +5132,14 @@ fn decode_inter_block( | ||
| 5084 | 5132 | left_filter_ctx, |
| 5085 | 5133 | false, |
| 5086 | 5134 | ); |
| 5135 | + if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { | |
| 5136 | + let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); | |
| 5137 | + eprintln!( | |
| 5138 | + "SREF_RESOLVED fidx={fidx} mi_row={} mi_col={} resolved={resolved_filter:?}", | |
| 5139 | + py / 4, | |
| 5140 | + px / 4, | |
| 5141 | + ); | |
| 5142 | + } | |
| 5087 | 5143 | block_filter = resolved_filter; |
| 5088 | 5144 | globalmv_for_lf = is_globalmv; |
| 5089 | 5145 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| @@ -5602,14 +5658,6 @@ fn decode_inter_block8( | ||
| 5602 | 5658 | // compound_idx defect surfaces on the wide gate sweep. |
| 5603 | 5659 | // lane-av1idx r1: same re-mask as the 16x16 leaf above -- |
| 5604 | 5660 | // see that comment. |
| 5605 | - return Err(unsupported( | |
| 5606 | - "a COMPOUND_REFERENCE 8x8 leaf using the plain/distance-weighted \ | |
| 5607 | - average blend (comp_group_idx == 0) -- proven non-pixel-exact \ | |
| 5608 | - against real aomenc streams beyond the bugs lane-av1blend r6/r7 \ | |
| 5609 | - and lane-av1idx r1 fixed (wide gate sweep, \ | |
| 5610 | - fixtures/av1idx-refsel-pin.obu)", | |
| 5611 | - )); | |
| 5612 | - #[allow(unreachable_code)] | |
| 5613 | 5661 | let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { |
| 5614 | 5662 | let idx_ctx = get_comp_index_context( |
| 5615 | 5663 | neighbours, |
crates/ec-av1/src/stream.rsmodified+7 -0
| @@ -266,6 +266,13 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | ||
| 266 | 266 | ec_av1_syntax::InterpolationFilter::Switchable => None, |
| 267 | 267 | fixed => Some(crate::mc::InterpFilterKind::from_header(fixed)), |
| 268 | 268 | }; |
| 269 | + if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { | |
| 270 | + eprintln!( | |
| 271 | + "STREAM_HEADER r17_before={} interpolation_filter={:?} interp_fixed={interp_fixed:?}", | |
| 272 | + crate::decode::r17_dump_frame_idx(), | |
| 273 | + header.interpolation_filter | |
| 274 | + ); | |
| 275 | + } | |
| 269 | 276 | |
| 270 | 277 | // Spec 7.20 `load_cdfs`: a frame naming a `primary_ref_frame` resumes |
| 271 | 278 | // from that reference slot's saved CDF state instead of the spec 8.4 |