Unscaled compound MC leaves the scaled walk
Browse files at this commit8c7cbe4d3a6d4fa26cc5c7d60292a9ca49be56bdParent: 62f159c- perf
- unscaled compound MC leaves the scaled walk
1 changed file +73 -47
- crates/ec-av1/src/mc.rs +73 -47
crates/ec-av1/src/mc.rsmodified+73 -47
| @@ -694,6 +694,58 @@ fn horizontal_scaled_pass( | |||
| 694 | } | 694 | } |
| 695 | } | 695 | } |
| 696 | 696 | ||
| 697 | +/// lane-perf2: the horizontal pass every two-pass entry point takes. | ||
| 698 | +/// `horizontal_scaled_pass` was carrying the UNSCALED work too (every | ||
| 699 | +/// compound prediction goes through it whatever the reference's scale), and | ||
| 700 | +/// its per-column walk re-derives an integer position and a filter phase | ||
| 701 | +/// that are constant at `REF_NO_SCALE`, reads the reference column-major, | ||
| 702 | +/// and clamps per tap -- 14% of decode self time. At `REF_NO_SCALE` the | ||
| 703 | +/// scaled walk reduces algebraically to `x0 = x_q4 / 16`, phase `x_q4 % 16` | ||
| 704 | +/// (`pos_x_q10 == x_q4 * 64 + 32`, so `int_pel == x0` and | ||
| 705 | +/// `(x_qn & 1023) >> 6 == xfrac` for every column), which is exactly | ||
| 706 | +/// [`horizontal_pass_unscaled`] -- and | ||
| 707 | +/// `predict_scaled_at_no_scale_matches_predict_with_filters` pins that | ||
| 708 | +/// equality end to end. A genuinely scaled reference (superres) still takes | ||
| 709 | +/// the general path. | ||
| 710 | +#[allow(clippy::too_many_arguments)] | ||
| 711 | +fn horizontal_pass( | ||
| 712 | + reference: &[u16], | ||
| 713 | + stride: usize, | ||
| 714 | + true_width: usize, | ||
| 715 | + true_height: usize, | ||
| 716 | + x_q4: i32, | ||
| 717 | + y0: i32, | ||
| 718 | + x_scale_fp: i64, | ||
| 719 | + block_w: usize, | ||
| 720 | + kern_w: usize, | ||
| 721 | + rows: usize, | ||
| 722 | + h_kind: InterpFilterKind, | ||
| 723 | + intermediate: &mut [i32], | ||
| 724 | +) { | ||
| 725 | + if x_scale_fp == REF_NO_SCALE { | ||
| 726 | + let (h_wide, h_narrow) = h_kind.tables(); | ||
| 727 | + let xfrac = x_q4.rem_euclid(16) as usize; | ||
| 728 | + let taps = if kern_w <= 4 { &h_narrow[xfrac] } else { &h_wide[xfrac] }; | ||
| 729 | + horizontal_pass_unscaled( | ||
| 730 | + reference, | ||
| 731 | + stride, | ||
| 732 | + true_width, | ||
| 733 | + true_height, | ||
| 734 | + x_q4.div_euclid(16), | ||
| 735 | + y0, | ||
| 736 | + taps, | ||
| 737 | + block_w, | ||
| 738 | + rows, | ||
| 739 | + intermediate, | ||
| 740 | + ); | ||
| 741 | + return; | ||
| 742 | + } | ||
| 743 | + horizontal_scaled_pass( | ||
| 744 | + reference, stride, true_width, true_height, x_q4, y0, x_scale_fp, block_w, kern_w, | ||
| 745 | + rows, h_kind, intermediate, | ||
| 746 | + ); | ||
| 747 | +} | ||
| 748 | + | ||
| 697 | /// [`predict_with_filters`]'s scaled-reference counterpart (spec 7.11.3.3): | 749 | /// [`predict_with_filters`]'s scaled-reference counterpart (spec 7.11.3.3): |
| 698 | /// used only when the stored reference's luma width differs from the current | 750 | /// used only when the stored reference's luma width differs from the current |
| 699 | /// frame's (`use_superres` on a non-key frame). `x_scale_fp` is | 751 | /// frame's (`use_superres` on a non-key frame). `x_scale_fp` is |
| @@ -768,32 +820,19 @@ pub fn predict_scaled_kern( | |||
| 768 | }; | 820 | }; |
| 769 | 821 | ||
| 770 | let rows = block_h + 7; | 822 | let rows = block_h + 7; |
| 771 | - let mut intermediate = vec![0i32; rows * block_w]; | 823 | + let max = crate::decode::sample_max(); |
| 772 | - horizontal_scaled_pass( | 824 | + with_scratch(rows, block_w, |intermediate, acc| { |
| 773 | - reference, | 825 | + horizontal_pass( |
| 774 | - stride, | 826 | + reference, stride, true_width, true_height, x_q4, y0, x_scale_fp, block_w, |
| 775 | - true_width, | 827 | + kern_w, rows, h_kind, intermediate, |
| 776 | - true_height, | 828 | + ); |
| 777 | - x_q4, | 829 | + for row in 0..block_h { |
| 778 | - y0, | 830 | + vpass_row(intermediate, block_w, row, v_filter, acc); |
| 779 | - x_scale_fp, | 831 | + for (d, &a) in dst[row * block_w..(row + 1) * block_w].iter_mut().zip(acc.iter()) { |
| 780 | - block_w, | 832 | + *d = round2(a, INTER_ROUND_1).clamp(0, max) as u16; |
| 781 | - kern_w, | ||
| 782 | - rows, | ||
| 783 | - h_kind, | ||
| 784 | - &mut intermediate, | ||
| 785 | - ); | ||
| 786 | - | ||
| 787 | - for row in 0..block_h { | ||
| 788 | - for col in 0..block_w { | ||
| 789 | - let mut sum = 0; | ||
| 790 | - for (t, &tap) in v_filter.iter().enumerate() { | ||
| 791 | - sum += tap * intermediate[(row + t) * block_w + col]; | ||
| 792 | } | 833 | } |
| 793 | - dst[row * block_w + col] = | ||
| 794 | - round2(sum, INTER_ROUND_1).clamp(0, crate::decode::sample_max()) as u16; | ||
| 795 | } | 834 | } |
| 796 | - } | 835 | + }); |
| 797 | } | 836 | } |
| 798 | 837 | ||
| 799 | /// `InterRound1` for a compound ref (spec 7.11.3.2's `isCompound` branch, | 838 | /// `InterRound1` for a compound ref (spec 7.11.3.2's `isCompound` branch, |
| @@ -891,31 +930,18 @@ pub fn predict_compound_intermediate_kern( | |||
| 891 | }; | 930 | }; |
| 892 | 931 | ||
| 893 | let rows = block_h + 7; | 932 | let rows = block_h + 7; |
| 894 | - let mut intermediate = vec![0i32; rows * block_w]; | 933 | + with_scratch(rows, block_w, |intermediate, acc| { |
| 895 | - horizontal_scaled_pass( | 934 | + horizontal_pass( |
| 896 | - reference, | 935 | + reference, stride, true_width, true_height, x_q4, y0, x_scale_fp, block_w, |
| 897 | - stride, | 936 | + kern_w, rows, h_kind, intermediate, |
| 898 | - true_width, | 937 | + ); |
| 899 | - true_height, | 938 | + for row in 0..block_h { |
| 900 | - x_q4, | 939 | + vpass_row(intermediate, block_w, row, v_filter, acc); |
| 901 | - y0, | 940 | + for (d, &a) in dst[row * block_w..(row + 1) * block_w].iter_mut().zip(acc.iter()) { |
| 902 | - x_scale_fp, | 941 | + *d = round2(a, INTER_ROUND_1_COMPOUND); |
| 903 | - block_w, | ||
| 904 | - kern_w, | ||
| 905 | - rows, | ||
| 906 | - h_kind, | ||
| 907 | - &mut intermediate, | ||
| 908 | - ); | ||
| 909 | - | ||
| 910 | - for row in 0..block_h { | ||
| 911 | - for col in 0..block_w { | ||
| 912 | - let mut sum = 0; | ||
| 913 | - for (t, &tap) in v_filter.iter().enumerate() { | ||
| 914 | - sum += tap * intermediate[(row + t) * block_w + col]; | ||
| 915 | } | 942 | } |
| 916 | - dst[row * block_w + col] = round2(sum, INTER_ROUND_1_COMPOUND); | ||
| 917 | } | 943 | } |
| 918 | - } | 944 | + }); |
| 919 | } | 945 | } |
| 920 | 946 | ||
| 921 | /// Blends two [`predict_compound_intermediate`] outputs into a finished | 947 | /// Blends two [`predict_compound_intermediate`] outputs into a finished |