Merge lane-rectchroma2 48216c2 into lane-leaf8tx: the 4-tap MC kernel decision came from the square buffer, causing chroma +-1 on rect/8x8 inter leaves
Browse files at this commit4 changed files +438 -17
- crates/ec-av1/src/decode.rs +36 -12
- crates/ec-av1/src/mc.rs +117 -5
- crates/ec-av1/src/stream.rs +198 -0
- lanes/rectchroma2-r1.report.md +87 -0
crates/ec-av1/src/decode.rsmodified+36 -12
| @@ -18049,7 +18049,7 @@ fn decode_inter_block( | ||
| 18049 | 18049 | } |
| 18050 | 18050 | |
| 18051 | 18051 | let mut inter0_y = vec![0i32; side * side]; |
| 18052 | - mc::predict_compound_intermediate( | |
| 18052 | + mc::predict_compound_intermediate_kern( | |
| 18053 | 18053 | &py0.data, |
| 18054 | 18054 | py0.width, |
| 18055 | 18055 | py0.true_width, |
| @@ -18059,6 +18059,8 @@ fn decode_inter_block( | ||
| 18059 | 18059 | scale0, |
| 18060 | 18060 | side, |
| 18061 | 18061 | side, |
| 18062 | + write_w, | |
| 18063 | + write_h, | |
| 18062 | 18064 | h_filter, |
| 18063 | 18065 | v_filter, |
| 18064 | 18066 | &mut inter0_y, |
| @@ -18074,7 +18076,7 @@ fn decode_inter_block( | ||
| 18074 | 18076 | ); |
| 18075 | 18077 | } |
| 18076 | 18078 | let mut inter1_y = vec![0i32; side * side]; |
| 18077 | - mc::predict_compound_intermediate( | |
| 18079 | + mc::predict_compound_intermediate_kern( | |
| 18078 | 18080 | &py1.data, |
| 18079 | 18081 | py1.width, |
| 18080 | 18082 | py1.true_width, |
| @@ -18084,6 +18086,8 @@ fn decode_inter_block( | ||
| 18084 | 18086 | scale1, |
| 18085 | 18087 | side, |
| 18086 | 18088 | side, |
| 18089 | + write_w, | |
| 18090 | + write_h, | |
| 18087 | 18091 | h_filter, |
| 18088 | 18092 | v_filter, |
| 18089 | 18093 | &mut inter1_y, |
| @@ -18121,7 +18125,7 @@ fn decode_inter_block( | ||
| 18121 | 18125 | } |
| 18122 | 18126 | |
| 18123 | 18127 | let mut inter0_u = vec![0i32; chroma_side * chroma_side]; |
| 18124 | - mc::predict_compound_intermediate( | |
| 18128 | + mc::predict_compound_intermediate_kern( | |
| 18125 | 18129 | &pu0.data, |
| 18126 | 18130 | pu0.width, |
| 18127 | 18131 | pu0.true_width, |
| @@ -18131,6 +18135,8 @@ fn decode_inter_block( | ||
| 18131 | 18135 | scale0, |
| 18132 | 18136 | chroma_side, |
| 18133 | 18137 | chroma_side, |
| 18138 | + write_chroma_w, | |
| 18139 | + write_chroma_h, | |
| 18134 | 18140 | h_filter, |
| 18135 | 18141 | v_filter, |
| 18136 | 18142 | &mut inter0_u, |
| @@ -18148,7 +18154,7 @@ fn decode_inter_block( | ||
| 18148 | 18154 | } |
| 18149 | 18155 | } |
| 18150 | 18156 | let mut inter1_u = vec![0i32; chroma_side * chroma_side]; |
| 18151 | - mc::predict_compound_intermediate( | |
| 18157 | + mc::predict_compound_intermediate_kern( | |
| 18152 | 18158 | &pu1.data, |
| 18153 | 18159 | pu1.width, |
| 18154 | 18160 | pu1.true_width, |
| @@ -18158,6 +18164,8 @@ fn decode_inter_block( | ||
| 18158 | 18164 | scale1, |
| 18159 | 18165 | chroma_side, |
| 18160 | 18166 | chroma_side, |
| 18167 | + write_chroma_w, | |
| 18168 | + write_chroma_h, | |
| 18161 | 18169 | h_filter, |
| 18162 | 18170 | v_filter, |
| 18163 | 18171 | &mut inter1_u, |
| @@ -18191,7 +18199,7 @@ fn decode_inter_block( | ||
| 18191 | 18199 | } |
| 18192 | 18200 | |
| 18193 | 18201 | let mut inter0_v = vec![0i32; chroma_side * chroma_side]; |
| 18194 | - mc::predict_compound_intermediate( | |
| 18202 | + mc::predict_compound_intermediate_kern( | |
| 18195 | 18203 | &pv0.data, |
| 18196 | 18204 | pv0.width, |
| 18197 | 18205 | pv0.true_width, |
| @@ -18201,6 +18209,8 @@ fn decode_inter_block( | ||
| 18201 | 18209 | scale0, |
| 18202 | 18210 | chroma_side, |
| 18203 | 18211 | chroma_side, |
| 18212 | + write_chroma_w, | |
| 18213 | + write_chroma_h, | |
| 18204 | 18214 | h_filter, |
| 18205 | 18215 | v_filter, |
| 18206 | 18216 | &mut inter0_v, |
| @@ -18218,7 +18228,7 @@ fn decode_inter_block( | ||
| 18218 | 18228 | } |
| 18219 | 18229 | } |
| 18220 | 18230 | let mut inter1_v = vec![0i32; chroma_side * chroma_side]; |
| 18221 | - mc::predict_compound_intermediate( | |
| 18231 | + mc::predict_compound_intermediate_kern( | |
| 18222 | 18232 | &pv1.data, |
| 18223 | 18233 | pv1.width, |
| 18224 | 18234 | pv1.true_width, |
| @@ -18228,6 +18238,8 @@ fn decode_inter_block( | ||
| 18228 | 18238 | scale1, |
| 18229 | 18239 | chroma_side, |
| 18230 | 18240 | chroma_side, |
| 18241 | + write_chroma_w, | |
| 18242 | + write_chroma_h, | |
| 18231 | 18243 | h_filter, |
| 18232 | 18244 | v_filter, |
| 18233 | 18245 | &mut inter1_v, |
| @@ -19115,7 +19127,7 @@ fn decode_inter_block( | ||
| 19115 | 19127 | let mut pred_u = vec![0u16; chroma_side * chroma_side]; |
| 19116 | 19128 | let mut pred_v = vec![0u16; chroma_side * chroma_side]; |
| 19117 | 19129 | if luma_scale == mc::REF_NO_SCALE { |
| 19118 | - mc::predict_with_filters( | |
| 19130 | + mc::predict_with_filters_kern( | |
| 19119 | 19131 | &py_ref.data, |
| 19120 | 19132 | py_ref.width, |
| 19121 | 19133 | py_ref.true_width, |
| @@ -19124,11 +19136,13 @@ fn decode_inter_block( | ||
| 19124 | 19136 | mv_to_q4(py, mv.0, true), |
| 19125 | 19137 | side, |
| 19126 | 19138 | side, |
| 19139 | + write_w, | |
| 19140 | + write_h, | |
| 19127 | 19141 | h_filter, |
| 19128 | 19142 | v_filter, |
| 19129 | 19143 | &mut pred_y, |
| 19130 | 19144 | ); |
| 19131 | - mc::predict_with_filters( | |
| 19145 | + mc::predict_with_filters_kern( | |
| 19132 | 19146 | &pu_ref.data, |
| 19133 | 19147 | pu_ref.width, |
| 19134 | 19148 | pu_ref.true_width, |
| @@ -19137,11 +19151,13 @@ fn decode_inter_block( | ||
| 19137 | 19151 | mv_to_q4(cpy, mv.0, false), |
| 19138 | 19152 | chroma_side, |
| 19139 | 19153 | chroma_side, |
| 19154 | + write_chroma_w, | |
| 19155 | + write_chroma_h, | |
| 19140 | 19156 | h_filter, |
| 19141 | 19157 | v_filter, |
| 19142 | 19158 | &mut pred_u, |
| 19143 | 19159 | ); |
| 19144 | - mc::predict_with_filters( | |
| 19160 | + mc::predict_with_filters_kern( | |
| 19145 | 19161 | &pv_ref.data, |
| 19146 | 19162 | pv_ref.width, |
| 19147 | 19163 | pv_ref.true_width, |
| @@ -19150,12 +19166,14 @@ fn decode_inter_block( | ||
| 19150 | 19166 | mv_to_q4(cpy, mv.0, false), |
| 19151 | 19167 | chroma_side, |
| 19152 | 19168 | chroma_side, |
| 19169 | + write_chroma_w, | |
| 19170 | + write_chroma_h, | |
| 19153 | 19171 | h_filter, |
| 19154 | 19172 | v_filter, |
| 19155 | 19173 | &mut pred_v, |
| 19156 | 19174 | ); |
| 19157 | 19175 | } else { |
| 19158 | - mc::predict_scaled( | |
| 19176 | + mc::predict_scaled_kern( | |
| 19159 | 19177 | &py_ref.data, |
| 19160 | 19178 | py_ref.width, |
| 19161 | 19179 | py_ref.true_width, |
| @@ -19165,11 +19183,13 @@ fn decode_inter_block( | ||
| 19165 | 19183 | luma_scale, |
| 19166 | 19184 | side, |
| 19167 | 19185 | side, |
| 19186 | + write_w, | |
| 19187 | + write_h, | |
| 19168 | 19188 | h_filter, |
| 19169 | 19189 | v_filter, |
| 19170 | 19190 | &mut pred_y, |
| 19171 | 19191 | ); |
| 19172 | - mc::predict_scaled( | |
| 19192 | + mc::predict_scaled_kern( | |
| 19173 | 19193 | &pu_ref.data, |
| 19174 | 19194 | pu_ref.width, |
| 19175 | 19195 | pu_ref.true_width, |
| @@ -19179,11 +19199,13 @@ fn decode_inter_block( | ||
| 19179 | 19199 | luma_scale, |
| 19180 | 19200 | chroma_side, |
| 19181 | 19201 | chroma_side, |
| 19202 | + write_chroma_w, | |
| 19203 | + write_chroma_h, | |
| 19182 | 19204 | h_filter, |
| 19183 | 19205 | v_filter, |
| 19184 | 19206 | &mut pred_u, |
| 19185 | 19207 | ); |
| 19186 | - mc::predict_scaled( | |
| 19208 | + mc::predict_scaled_kern( | |
| 19187 | 19209 | &pv_ref.data, |
| 19188 | 19210 | pv_ref.width, |
| 19189 | 19211 | pv_ref.true_width, |
| @@ -19193,6 +19215,8 @@ fn decode_inter_block( | ||
| 19193 | 19215 | luma_scale, |
| 19194 | 19216 | chroma_side, |
| 19195 | 19217 | chroma_side, |
| 19218 | + write_chroma_w, | |
| 19219 | + write_chroma_h, | |
| 19196 | 19220 | h_filter, |
| 19197 | 19221 | v_filter, |
| 19198 | 19222 | &mut pred_v, |
crates/ec-av1/src/mc.rsmodified+117 -5
| @@ -333,6 +333,36 @@ pub fn predict_with_filters( | ||
| 333 | 333 | h_kind: InterpFilterKind, |
| 334 | 334 | v_kind: InterpFilterKind, |
| 335 | 335 | dst: &mut [u16], |
| 336 | +) { | |
| 337 | + predict_with_filters_kern( | |
| 338 | + reference, stride, true_width, true_height, x_q4, y_q4, block_w, | |
| 339 | + block_h, block_w, block_h, h_kind, v_kind, dst, | |
| 340 | + ); | |
| 341 | +} | |
| 342 | + | |
| 343 | +/// [`predict_with_filters`] with the 4-tap decision taken from the block's | |
| 344 | +/// TRUE width/height (`kern_w`/`kern_h`) rather than the destination buffer's. | |
| 345 | +/// libaom's `av1_get_interp_filter_params_with_block_size` (reconinter.h, | |
| 346 | +/// called per axis from `inter_predictor` with `w` then `h`) picks the narrow | |
| 347 | +/// kernel from the PREDICTION block's own dimensions; our inter path predicts | |
| 348 | +/// a rectangular block over its enclosing square buffer, so a rect block whose | |
| 349 | +/// chroma is 4 wide or 4 tall (luma 8x16 / 16x8 and taller kin) must still ask | |
| 350 | +/// for the 4-tap kernel on that axis -- lane-rectchroma2 r1. | |
| 351 | +#[allow(clippy::too_many_arguments)] | |
| 352 | +pub fn predict_with_filters_kern( | |
| 353 | + reference: &[u16], | |
| 354 | + stride: usize, | |
| 355 | + true_width: usize, | |
| 356 | + true_height: usize, | |
| 357 | + x_q4: i32, | |
| 358 | + y_q4: i32, | |
| 359 | + block_w: usize, | |
| 360 | + block_h: usize, | |
| 361 | + kern_w: usize, | |
| 362 | + kern_h: usize, | |
| 363 | + h_kind: InterpFilterKind, | |
| 364 | + v_kind: InterpFilterKind, | |
| 365 | + dst: &mut [u16], | |
| 336 | 366 | ) { |
| 337 | 367 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); |
| 338 | 368 | assert!(!reference.is_empty(), "a reference plane has samples"); |
| @@ -374,12 +404,13 @@ pub fn predict_with_filters( | ||
| 374 | 404 | |
| 375 | 405 | let (h_wide, h_narrow) = h_kind.tables(); |
| 376 | 406 | let (v_wide, v_narrow) = v_kind.tables(); |
| 377 | - let h_filter = if block_w <= 4 { | |
| 407 | + note_narrow_kern(block_w, block_h, kern_w, kern_h); | |
| 408 | + let h_filter = if kern_w <= 4 { | |
| 378 | 409 | &h_narrow[xfrac] |
| 379 | 410 | } else { |
| 380 | 411 | &h_wide[xfrac] |
| 381 | 412 | }; |
| 382 | - let v_filter = if block_h <= 4 { | |
| 413 | + let v_filter = if kern_h <= 4 { | |
| 383 | 414 | &v_narrow[yfrac] |
| 384 | 415 | } else { |
| 385 | 416 | &v_wide[yfrac] |
| @@ -452,6 +483,32 @@ thread_local! { | ||
| 452 | 483 | /// only intra blocks cannot pass it by construction (class |
| 453 | 484 | /// `gate-blind-to-feature`). |
| 454 | 485 | static INTER_PRED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 486 | + | |
| 487 | + /// lane-rectchroma2 r1: how often the 4-tap decision came out DIFFERENT | |
| 488 | + /// from what the destination buffer's own dimensions would have given -- | |
| 489 | + /// i.e. how often a rectangular block predicted over its enclosing square | |
| 490 | + /// buffer asked for libaom's narrow kernel on an axis. Zero means a gate | |
| 491 | + /// never exercised the rect-chroma shape at all. | |
| 492 | + static RECT_NARROW_KERN_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 493 | +} | |
| 494 | + | |
| 495 | +/// Current value of [`RECT_NARROW_KERN_HITS`]. | |
| 496 | +pub fn rect_narrow_kern_hits() -> usize { | |
| 497 | + RECT_NARROW_KERN_HITS.with(|c| c.get()) | |
| 498 | +} | |
| 499 | + | |
| 500 | +/// Resets [`RECT_NARROW_KERN_HITS`] (per-attempt counting, class | |
| 501 | +/// `counter-from-refused-stream`). | |
| 502 | +pub fn reset_rect_narrow_kern_hits() { | |
| 503 | + RECT_NARROW_KERN_HITS.with(|c| c.set(0)); | |
| 504 | +} | |
| 505 | + | |
| 506 | +/// Bumps [`RECT_NARROW_KERN_HITS`] when the block's true dims pick a kernel | |
| 507 | +/// the destination buffer's dims would not have. | |
| 508 | +fn note_narrow_kern(block_w: usize, block_h: usize, kern_w: usize, kern_h: usize) { | |
| 509 | + if (kern_w <= 4) != (block_w <= 4) || (kern_h <= 4) != (block_h <= 4) { | |
| 510 | + RECT_NARROW_KERN_HITS.with(|c| c.set(c.get() + 1)); | |
| 511 | + } | |
| 455 | 512 | } |
| 456 | 513 | |
| 457 | 514 | /// Current value of [`INTER_PRED_HITS`]. |
| @@ -498,6 +555,7 @@ fn horizontal_scaled_pass( | ||
| 498 | 555 | y0: i32, |
| 499 | 556 | x_scale_fp: i64, |
| 500 | 557 | block_w: usize, |
| 558 | + kern_w: usize, | |
| 501 | 559 | rows: usize, |
| 502 | 560 | h_kind: InterpFilterKind, |
| 503 | 561 | intermediate: &mut [i32], |
| @@ -510,7 +568,7 @@ fn horizontal_scaled_pass( | ||
| 510 | 568 | let x_qn = pos_x_q10 + c as i64 * x_step_qn; |
| 511 | 569 | let int_pel = (x_qn >> 10) as i32; |
| 512 | 570 | let filter_idx = ((x_qn & 1023) >> 6) as usize; |
| 513 | - let h_filter = if block_w <= 4 { | |
| 571 | + let h_filter = if kern_w <= 4 { | |
| 514 | 572 | &h_narrow[filter_idx] |
| 515 | 573 | } else { |
| 516 | 574 | &h_wide[filter_idx] |
| @@ -555,6 +613,31 @@ pub fn predict_scaled( | ||
| 555 | 613 | h_kind: InterpFilterKind, |
| 556 | 614 | v_kind: InterpFilterKind, |
| 557 | 615 | dst: &mut [u16], |
| 616 | +) { | |
| 617 | + predict_scaled_kern( | |
| 618 | + reference, stride, true_width, true_height, x_q4, y_q4, x_scale_fp, | |
| 619 | + block_w, block_h, block_w, block_h, h_kind, v_kind, dst, | |
| 620 | + ); | |
| 621 | +} | |
| 622 | + | |
| 623 | +/// [`predict_scaled`] with the 4-tap decision from the block's true dims | |
| 624 | +/// (see [`predict_with_filters_kern`]). | |
| 625 | +#[allow(clippy::too_many_arguments)] | |
| 626 | +pub fn predict_scaled_kern( | |
| 627 | + reference: &[u16], | |
| 628 | + stride: usize, | |
| 629 | + true_width: usize, | |
| 630 | + true_height: usize, | |
| 631 | + x_q4: i32, | |
| 632 | + y_q4: i32, | |
| 633 | + x_scale_fp: i64, | |
| 634 | + block_w: usize, | |
| 635 | + block_h: usize, | |
| 636 | + kern_w: usize, | |
| 637 | + kern_h: usize, | |
| 638 | + h_kind: InterpFilterKind, | |
| 639 | + v_kind: InterpFilterKind, | |
| 640 | + dst: &mut [u16], | |
| 558 | 641 | ) { |
| 559 | 642 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); |
| 560 | 643 | assert!(!reference.is_empty(), "a reference plane has samples"); |
| @@ -568,7 +651,8 @@ pub fn predict_scaled( | ||
| 568 | 651 | // Q10; off/pos_x_q10 fold the block's own x_q4 (Q4) into that same Q10 |
| 569 | 652 | // grid (spec 7.11.3.3's `dec_calc_subpel_params`). |
| 570 | 653 | let (v_wide, v_narrow) = v_kind.tables(); |
| 571 | - let v_filter = if block_h <= 4 { | |
| 654 | + note_narrow_kern(block_w, block_h, kern_w, kern_h); | |
| 655 | + let v_filter = if kern_h <= 4 { | |
| 572 | 656 | &v_narrow[yfrac] |
| 573 | 657 | } else { |
| 574 | 658 | &v_wide[yfrac] |
| @@ -585,6 +669,7 @@ pub fn predict_scaled( | ||
| 585 | 669 | y0, |
| 586 | 670 | x_scale_fp, |
| 587 | 671 | block_w, |
| 672 | + kern_w, | |
| 588 | 673 | rows, |
| 589 | 674 | h_kind, |
| 590 | 675 | &mut intermediate, |
| @@ -648,6 +733,31 @@ pub fn predict_compound_intermediate( | ||
| 648 | 733 | h_kind: InterpFilterKind, |
| 649 | 734 | v_kind: InterpFilterKind, |
| 650 | 735 | dst: &mut [i32], |
| 736 | +) { | |
| 737 | + predict_compound_intermediate_kern( | |
| 738 | + reference, stride, true_width, true_height, x_q4, y_q4, x_scale_fp, | |
| 739 | + block_w, block_h, block_w, block_h, h_kind, v_kind, dst, | |
| 740 | + ); | |
| 741 | +} | |
| 742 | + | |
| 743 | +/// [`predict_compound_intermediate`] with the 4-tap decision from the block's | |
| 744 | +/// true dims (see [`predict_with_filters_kern`]). | |
| 745 | +#[allow(clippy::too_many_arguments)] | |
| 746 | +pub fn predict_compound_intermediate_kern( | |
| 747 | + reference: &[u16], | |
| 748 | + stride: usize, | |
| 749 | + true_width: usize, | |
| 750 | + true_height: usize, | |
| 751 | + x_q4: i32, | |
| 752 | + y_q4: i32, | |
| 753 | + x_scale_fp: i64, | |
| 754 | + block_w: usize, | |
| 755 | + block_h: usize, | |
| 756 | + kern_w: usize, | |
| 757 | + kern_h: usize, | |
| 758 | + h_kind: InterpFilterKind, | |
| 759 | + v_kind: InterpFilterKind, | |
| 760 | + dst: &mut [i32], | |
| 651 | 761 | ) { |
| 652 | 762 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); |
| 653 | 763 | assert!(!reference.is_empty(), "a reference plane has samples"); |
| @@ -661,7 +771,8 @@ pub fn predict_compound_intermediate( | ||
| 661 | 771 | let yfrac = y_q4.rem_euclid(16) as usize; |
| 662 | 772 | |
| 663 | 773 | let (v_wide, v_narrow) = v_kind.tables(); |
| 664 | - let v_filter = if block_h <= 4 { | |
| 774 | + note_narrow_kern(block_w, block_h, kern_w, kern_h); | |
| 775 | + let v_filter = if kern_h <= 4 { | |
| 665 | 776 | &v_narrow[yfrac] |
| 666 | 777 | } else { |
| 667 | 778 | &v_wide[yfrac] |
| @@ -678,6 +789,7 @@ pub fn predict_compound_intermediate( | ||
| 678 | 789 | y0, |
| 679 | 790 | x_scale_fp, |
| 680 | 791 | block_w, |
| 792 | + kern_w, | |
| 681 | 793 | rows, |
| 682 | 794 | h_kind, |
| 683 | 795 | &mut intermediate, |
crates/ec-av1/src/stream.rsmodified+198 -0
| @@ -25960,4 +25960,202 @@ mod tests { | ||
| 25960 | 25960 | // instead; this counter is reported, not gated. |
| 25961 | 25961 | eprintln!("{NAME}: {skip_split_tx_total} skipped 8x8 TX_4X4 leaves across compared attempts"); |
| 25962 | 25962 | } |
| 25963 | + | |
| 25964 | + /// lane-rectchroma2 r1, the defect this gate exists for: our inter path | |
| 25965 | + /// predicts a RECTANGULAR block over its enclosing SQUARE buffer | |
| 25966 | + /// (`side`x`side`, `chroma_side`x`chroma_side` -- see | |
| 25967 | + /// [`crate::decode`]'s `write_w`/`write_h` corner-cut), and | |
| 25968 | + /// [`crate::mc::predict_with_filters`] took libaom's narrow-block 4-tap | |
| 25969 | + /// decision from that buffer's dimensions. libaom | |
| 25970 | + /// (`av1_get_interp_filter_params_with_block_size`, called per axis from | |
| 25971 | + /// `inter_predictor` with `w` then `h`) takes it from the PREDICTION | |
| 25972 | + /// block's own dimensions, so an 8x16 / 16x8 inter block -- whose chroma | |
| 25973 | + /// is 4x8 / 8x4 -- must use the 4-tap kernel on the short axis. Luma is | |
| 25974 | + /// never <= 4 wide here, which is exactly why every such stream decoded | |
| 25975 | + /// LUMA EXACT and differed by +-1 on scattered chroma samples of those | |
| 25976 | + /// blocks (lane-interedge r1's 192x128 control, a size with no frame-edge | |
| 25977 | + /// node at all). | |
| 25978 | + /// | |
| 25979 | + /// Full-plane (Y+U+V) compare of EVERY decode-order frame | |
| 25980 | + /// (`--lag-in-frames=0`), both orientations (192x128 and its transposed | |
| 25981 | + /// twin, so the 4x8 and 8x4 chroma shapes both fire -- class | |
| 25982 | + /// `scan-weights-cross-axis`), 8 AND 10 bit (his films are yuv420p10le), | |
| 25983 | + /// cq 20/32/45, CDEF and loop restoration left ON. The counter is reset | |
| 25984 | + /// per attempt and read only on an attempt that decoded and compared | |
| 25985 | + /// (class `counter-from-refused-stream`); it counts predictions whose | |
| 25986 | + /// kernel choice DIFFERS from what the square buffer would have given, so | |
| 25987 | + /// a zero means the recipe lost the shape this gate pins. | |
| 25988 | + #[test] | |
| 25989 | + fn a_real_aomenc_rect_inter_block_predicts_chroma_with_the_narrow_kernel_pixel_exact() { | |
| 25990 | + const NAME: &str = | |
| 25991 | + "a_real_aomenc_rect_inter_block_predicts_chroma_with_the_narrow_kernel_pixel_exact"; | |
| 25992 | + let _gate_lock = lock_gate_counters(); | |
| 25993 | + if !have_ffmpeg() { | |
| 25994 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 25995 | + return; | |
| 25996 | + } | |
| 25997 | + if !have_aomenc() { | |
| 25998 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 25999 | + return; | |
| 26000 | + } | |
| 26001 | + const FRAMES: usize = 6; | |
| 26002 | + let mut compared = 0usize; | |
| 26003 | + let mut narrow_by_depth = [0usize; 2]; | |
| 26004 | + let mut narrow_by_shape = [0usize; 2]; | |
| 26005 | + for (si, (width, height)) in [(192usize, 128usize), (128usize, 192usize)] | |
| 26006 | + .into_iter() | |
| 26007 | + .enumerate() | |
| 26008 | + { | |
| 26009 | + for (di, depth) in [8usize, 10].into_iter().enumerate() { | |
| 26010 | + let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; | |
| 26011 | + let y4m = Command::new("ffmpeg") | |
| 26012 | + .args([ | |
| 26013 | + "-v", "error", "-f", "lavfi", "-i", | |
| 26014 | + &format!("mandelbrot=size={width}x{height}:rate=25"), | |
| 26015 | + "-pix_fmt", pix, "-strict", "-1", "-vframes", &FRAMES.to_string(), | |
| 26016 | + "-f", "yuv4mpegpipe", "-", | |
| 26017 | + ]) | |
| 26018 | + .stdin(Stdio::null()) | |
| 26019 | + .stdout(Stdio::piped()) | |
| 26020 | + .stderr(Stdio::piped()) | |
| 26021 | + .output() | |
| 26022 | + .expect("ffmpeg failed to run"); | |
| 26023 | + assert!( | |
| 26024 | + y4m.status.success(), | |
| 26025 | + "{NAME}: ffmpeg fixture ({width}x{height}, depth={depth}): {}", | |
| 26026 | + String::from_utf8_lossy(&y4m.stderr) | |
| 26027 | + ); | |
| 26028 | + for cq in [20usize, 32, 45] { | |
| 26029 | + let encode = || { | |
| 26030 | + let mut child = Command::new(aomenc_path()) | |
| 26031 | + .args([ | |
| 26032 | + "--codec=av1", "--passes=1", "--end-usage=q", | |
| 26033 | + &format!("--cq-level={cq}"), | |
| 26034 | + "--cpu-used=4", "--threads=1", "--row-mt=0", | |
| 26035 | + "--kf-max-dist=9999", &format!("--limit={FRAMES}"), | |
| 26036 | + "--lag-in-frames=0", | |
| 26037 | + &format!("--bit-depth={depth}"), | |
| 26038 | + &format!("--input-bit-depth={depth}"), | |
| 26039 | + // Rect partitions ON is the whole point; every | |
| 26040 | + // other tool below is another lane's open gap | |
| 26041 | + // that would refuse before a pixel compare. | |
| 26042 | + "--enable-rect-partitions=1", "--enable-ab-partitions=0", | |
| 26043 | + "--enable-1to4-partitions=0", "--min-partition-size=8", | |
| 26044 | + "--max-partition-size=64", "--enable-palette=0", | |
| 26045 | + "--enable-intrabc=0", "--enable-warped-motion=0", | |
| 26046 | + "--enable-obmc=0", "--enable-masked-comp=0", | |
| 26047 | + "--enable-interintra-comp=0", "--enable-onesided-comp=0", | |
| 26048 | + "--enable-interintra-wedge=0", "--enable-smooth-interintra=0", | |
| 26049 | + "--enable-ref-frame-mvs=0", "--enable-angle-delta=0", | |
| 26050 | + "--enable-cfl-intra=0", "--enable-directional-intra=0", | |
| 26051 | + "--enable-smooth-intra=0", "--enable-paeth-intra=0", | |
| 26052 | + "--enable-filter-intra=0", "--enable-tx-size-search=0", | |
| 26053 | + "--obu", "-o", "-", "-", | |
| 26054 | + ]) | |
| 26055 | + .stdin(Stdio::piped()) | |
| 26056 | + .stdout(Stdio::piped()) | |
| 26057 | + .stderr(Stdio::piped()) | |
| 26058 | + .spawn() | |
| 26059 | + .expect("aomenc failed to start"); | |
| 26060 | + child | |
| 26061 | + .stdin | |
| 26062 | + .take() | |
| 26063 | + .expect("aomenc stdin") | |
| 26064 | + .write_all(&y4m.stdout) | |
| 26065 | + .expect("writing y4m to aomenc"); | |
| 26066 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 26067 | + assert!( | |
| 26068 | + out.status.success(), | |
| 26069 | + "aomenc refused the fixture ({width}x{height}, depth={depth}, \ | |
| 26070 | + cq={cq}): {}", | |
| 26071 | + String::from_utf8_lossy(&out.stderr) | |
| 26072 | + ); | |
| 26073 | + out.stdout | |
| 26074 | + }; | |
| 26075 | + let stream = encode(); | |
| 26076 | + assert_eq!( | |
| 26077 | + stream, | |
| 26078 | + encode(), | |
| 26079 | + "{NAME}: aomenc output is not reproducible ({width}x{height}, \ | |
| 26080 | + depth={depth}, cq={cq})" | |
| 26081 | + ); | |
| 26082 | + crate::mc::reset_rect_narrow_kern_hits(); | |
| 26083 | + let frames = match decode_stream(&stream) { | |
| 26084 | + Ok(frames) => frames, | |
| 26085 | + Err(e) => { | |
| 26086 | + let msg = e.to_string(); | |
| 26087 | + assert!( | |
| 26088 | + msg.contains("unsupported"), | |
| 26089 | + "{NAME}: decode failed ({width}x{height}, depth={depth}, \ | |
| 26090 | + cq={cq}): {msg}" | |
| 26091 | + ); | |
| 26092 | + eprintln!( | |
| 26093 | + "{NAME}: {width}x{height} depth={depth} cq={cq} arm refused \ | |
| 26094 | + (not compared): {msg}" | |
| 26095 | + ); | |
| 26096 | + continue; | |
| 26097 | + } | |
| 26098 | + }; | |
| 26099 | + let narrow = crate::mc::rect_narrow_kern_hits(); | |
| 26100 | + let ffmpeg_frames = if depth == 10 { | |
| 26101 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) | |
| 26102 | + } else { | |
| 26103 | + ffmpeg_decode_sequence(&stream, width, height, frames.len()) | |
| 26104 | + }; | |
| 26105 | + assert_eq!( | |
| 26106 | + ffmpeg_frames.len(), | |
| 26107 | + frames.len(), | |
| 26108 | + "{NAME}: ffmpeg frame count ({width}x{height}, depth={depth}, cq={cq})" | |
| 26109 | + ); | |
| 26110 | + assert_eq!( | |
| 26111 | + frames.len(), | |
| 26112 | + FRAMES, | |
| 26113 | + "{NAME}: not every coded frame was decoded ({width}x{height}, \ | |
| 26114 | + depth={depth}, cq={cq})" | |
| 26115 | + ); | |
| 26116 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 26117 | + assert_eq!( | |
| 26118 | + got.y, want.y, | |
| 26119 | + "{NAME} frame {i} luma vs ffmpeg ({width}x{height}, depth={depth}, \ | |
| 26120 | + cq={cq}, narrow-kernel hits {narrow})" | |
| 26121 | + ); | |
| 26122 | + assert_eq!( | |
| 26123 | + got.u, want.u, | |
| 26124 | + "{NAME} frame {i} U vs ffmpeg ({width}x{height}, depth={depth}, \ | |
| 26125 | + cq={cq}, narrow-kernel hits {narrow})" | |
| 26126 | + ); | |
| 26127 | + assert_eq!( | |
| 26128 | + got.v, want.v, | |
| 26129 | + "{NAME} frame {i} V vs ffmpeg ({width}x{height}, depth={depth}, \ | |
| 26130 | + cq={cq}, narrow-kernel hits {narrow})" | |
| 26131 | + ); | |
| 26132 | + } | |
| 26133 | + compared += 1; | |
| 26134 | + narrow_by_depth[di] += narrow; | |
| 26135 | + narrow_by_shape[si] += narrow; | |
| 26136 | + eprintln!( | |
| 26137 | + "{NAME}: {width}x{height} depth={depth} cq={cq} {} frames full-plane \ | |
| 26138 | + exact, narrow-kernel hits {narrow}", | |
| 26139 | + frames.len() | |
| 26140 | + ); | |
| 26141 | + } | |
| 26142 | + } | |
| 26143 | + } | |
| 26144 | + assert_eq!( | |
| 26145 | + compared, 12, | |
| 26146 | + "{NAME}: only {compared} of 12 arms were pixel-compared -- a refusal makes this \ | |
| 26147 | + gate vacuous" | |
| 26148 | + ); | |
| 26149 | + assert!( | |
| 26150 | + narrow_by_depth[0] > 0 && narrow_by_depth[1] > 0, | |
| 26151 | + "{NAME}: no rect-chroma narrow kernel fired at 8-bit ({}) or 10-bit ({}) -- the \ | |
| 26152 | + recipe lost the shape this gate pins", | |
| 26153 | + narrow_by_depth[0], narrow_by_depth[1] | |
| 26154 | + ); | |
| 26155 | + assert!( | |
| 26156 | + narrow_by_shape[0] > 0 && narrow_by_shape[1] > 0, | |
| 26157 | + "{NAME}: the shape fired in only one orientation (192x128 {}, 128x192 {})", | |
| 26158 | + narrow_by_shape[0], narrow_by_shape[1] | |
| 26159 | + ); | |
| 26160 | + } | |
| 25963 | 26161 | } |
lanes/rectchroma2-r1.report.mdadded+87 -0
| @@ -0,0 +1,87 @@ | ||
| 1 | +# lane-rectchroma2 r1 -- rect INTER blocks predicted chroma with the WIDE kernel | |
| 2 | + | |
| 3 | +## Premise re-measured first | |
| 4 | + | |
| 5 | +lane-interedge r1's residue reproduced on this tree (main 2c04819 + lane-cdef + lane-golomb | |
| 6 | +173b793): mandelbrot 192x128 (the CONTROL size -- zero frame-edge nodes), 6 frames, | |
| 7 | +`--enable-rect-partitions=1 --min-partition-size=8 --enable-tx-size-search=0 --lag-in-frames=0`, | |
| 8 | +intra tools off, cq 20/32/45, 8- and 10-bit: **luma exact, chroma differs on frames 2..5 in all | |
| 9 | +six arms**. Streams hashed twice, identical. | |
| 10 | + | |
| 11 | +EVIDENCE: `~/.cache/rectchroma2-tmp/c192-128-{8,10}-{20,32,45}.obu` (each sha256 twice, equal) | |
| 12 | +| `decode_probe` with `EC_AV1_FINAL_DUMP` vs `ffmpeg -pix_fmt yuv420p[10le]`, every decode-order | |
| 13 | +frame, per plane | e.g. cq32 8-bit: `[(2,'chroma (0,32)..(1,40) n=17'), (4,...), (5,...)]`, luma | |
| 14 | +exact in all 6 arms. | |
| 15 | + | |
| 16 | +## Stage bisect | |
| 17 | + | |
| 18 | +Regenerated the same recipe with `--loopfilter-control=0` (deblock off; CDEF/LR already off in | |
| 19 | +that recipe): **the chroma mismatch survives unchanged** -> not a filter-stage defect, so the | |
| 20 | +charter's suspect (d) (chroma deblock levels / uv tx grid for rect inter blocks) is exonerated. | |
| 21 | +The surviving diffs are +-1 on scattered samples inside 4-wide-by-8-tall and 8-wide-by-4-tall | |
| 22 | +CHROMA regions (e.g. frame 4: chroma x32..35 rows 26..39, and x48..55 rows 16..19) -- i.e. the | |
| 23 | +chroma halves of 8x16 and 16x8 LUMA blocks. | |
| 24 | + | |
| 25 | +EVIDENCE: `~/.cache/rectchroma2-tmp/n192-128-8-32.obu` (`gen_nolf.sh`) | decode + full-plane | |
| 26 | +compare | `MISMATCH [(2,'chroma ... n=15'), (4,...n=36), (5,...n=45)]`, luma exact. | |
| 27 | + | |
| 28 | +## Root cause (charter suspect (a), confirmed) | |
| 29 | + | |
| 30 | +`crates/ec-av1/src/decode.rs` `decode_inter_block` predicts a RECTANGULAR block over its | |
| 31 | +enclosing SQUARE buffer (`side`x`side`, chroma `chroma_side`x`chroma_side`; `write_w`/`write_h` | |
| 32 | +govern only the pixel write -- the lane-partitions r1 corner-cut). The 4-tap decision lived | |
| 33 | +inside `mc::predict_with_filters` and read that BUFFER's dimensions. libaom | |
| 34 | +`av1_get_interp_filter_params_with_block_size` (reconinter.h, called per axis from | |
| 35 | +`inter_predictor` with `w` then `h`) reads the PREDICTION BLOCK's dimensions: `w <= 4` -> | |
| 36 | +`av1_interp_4tap[0]` (SHARP and REGULAR both) / `[1]` (SMOOTH). Luma is never <= 4 wide on this | |
| 37 | +path, so only chroma of a rect block (4x8 / 8x4 / 4x16 ...) was affected -- exactly the | |
| 38 | +"luma exact, chroma wrong" signature. | |
| 39 | + | |
| 40 | +- `crates/ec-av1/src/mc.rs`: `predict_with_filters_kern` / `predict_scaled_kern` / | |
| 41 | + `predict_compound_intermediate_kern` -- the existing three entry points keep their signatures | |
| 42 | + and delegate with `kern = block dims`; `horizontal_scaled_pass` takes `kern_w`. | |
| 43 | +- `crates/ec-av1/src/mc.rs`: `RECT_NARROW_KERN_HITS` + `rect_narrow_kern_hits()` / | |
| 44 | + `reset_rect_narrow_kern_hits()` / `note_narrow_kern()` -- counts predictions whose kernel | |
| 45 | + choice DIFFERS from what the square buffer would have given (one bump per prediction). | |
| 46 | +- `crates/ec-av1/src/decode.rs`: the 12 prediction calls inside `decode_inter_block` now pass | |
| 47 | + `write_w/write_h` (luma) and `write_chroma_w/write_chroma_h` (chroma) as the kernel dims. | |
| 48 | + | |
| 49 | +Class sweep: every other `mc::predict*` call site passes a buffer whose dims ARE the block's | |
| 50 | +(`obmc_neighbour_pred` takes the neighbour's true w/h; the 8x8 leaf path is square, chroma 4x4; | |
| 51 | +the CfL bilinear path is unrelated), so no sibling site needed the change. | |
| 52 | + | |
| 53 | +## Gate (GREEN) | |
| 54 | + | |
| 55 | +``` | |
| 56 | +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-rectchroma2 EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 \ | |
| 57 | +PATH="$HOME/.cache/aom-oracle/build:$PATH" cargo test -p ec-av1 --lib narrow_kernel -- --nocapture | |
| 58 | +``` | |
| 59 | +`a_real_aomenc_rect_inter_block_predicts_chroma_with_the_narrow_kernel_pixel_exact` | |
| 60 | +(`crates/ec-av1/src/stream.rs`): real aomenc, mandelbrot 192x128 AND its transposed twin | |
| 61 | +128x192 (so 4x8 and 8x4 chroma both fire), 8- and 10-bit, cq 20/32/45, 6 frames, | |
| 62 | +`--lag-in-frames=0` so decode order == display order and EVERY frame is compared on Y, U AND V | |
| 63 | +against ffmpeg. CDEF and loop restoration left ON. Streams encoded twice and asserted equal. | |
| 64 | +`compared == 12` is a hard assert (a refusal fails the gate, never SKIPs), and the narrow-kernel | |
| 65 | +counter -- reset per attempt, read only on compared attempts -- must be nonzero at BOTH depths | |
| 66 | +and in BOTH orientations. | |
| 67 | + | |
| 68 | +EVIDENCE: gate stdout | 12 aomenc -> ec-av1 -> ffmpeg attempts, 6 frames each, all three planes | |
| 69 | +| `12/12 arms 6 frames full-plane exact; narrow-kernel hits 24/4/16 (192x128 8-bit cq20/32/45), | |
| 70 | +18/26/36 (10-bit), 42/20/18 and 36/36/34 for 128x192` -- 0 refusals, 0 out-of-scope mismatches. | |
| 71 | + | |
| 72 | +Before the fix the SAME recipe mismatched chroma in every arm (the premise sweep above), so the | |
| 73 | +gate is not vacuous. | |
| 74 | + | |
| 75 | +## Refusals | |
| 76 | +None lifted (no inventory string covers this defect -- it was a wrong-pixels defect behind an | |
| 77 | +already-accepted path). `refusal_inventory.rs`/`gate_coverage.rs` untouched by intent, both green | |
| 78 | +in the suite below. | |
| 79 | + | |
| 80 | +## Suite | |
| 81 | +`$HOME/.cache/rectchroma2-suite-r1.log`: **388 passed, 0 failed, 35 ignored** (1668s), including the new gate. Baseline before this round on the same tree shape was 387/0/35 (this round adds one gate). | |
| 82 | + | |
| 83 | +## Residue | |
| 84 | +- accepted: `predict_scaled_kern` (scaled reference / superres) got the same fix by construction | |
| 85 | + but is not exercised by this gate -- superres rect-chroma has no aomenc recipe on this lane. | |
| 86 | +- deferred(lane-interedge merge): that lane's frame-edge gate can now become a FULL-PLANE arm; | |
| 87 | + its luma-only compare was a workaround for exactly this defect. |