Whole-pel axes skip the pass they do not need
Browse files at this commitc8bf4a0588e7d34225784d6fae2db9758af11b84Parent: dcac6b3- perf
- whole-pel axes skip the pass they do not need
1 changed file +52 -14
- crates/ec-av1/src/mc.rs +52 -14
crates/ec-av1/src/mc.rsmodified+52 -14
| @@ -299,16 +299,30 @@ fn horizontal_pass_unscaled( | |||
| 299 | rows: usize, | 299 | rows: usize, |
| 300 | intermediate: &mut [i32], | 300 | intermediate: &mut [i32], |
| 301 | ) { | 301 | ) { |
| 302 | + // Fraction 0 is the identity tap (`128` at slot 3), and `Round2(128 * s, | ||
| 303 | + // InterRound0) == 16 * s` exactly, so a whole-pel horizontal position | ||
| 304 | + // needs no filter at all -- one widened row read. | ||
| 305 | + let identity = taps[3] == 128 && taps.iter().enumerate().all(|(i, &t)| i == 3 || t == 0); | ||
| 302 | for r in 0..rows { | 306 | for r in 0..rows { |
| 303 | let y = (y0 - 3 + r as i32).clamp(0, true_height as i32 - 1) as usize; | 307 | let y = (y0 - 3 + r as i32).clamp(0, true_height as i32 - 1) as usize; |
| 304 | - hpass_row( | 308 | + let out = &mut intermediate[r * block_w..(r + 1) * block_w]; |
| 305 | - reference, | 309 | + if identity { |
| 306 | - y * stride, | 310 | + let gain = 128 >> INTER_ROUND_0; |
| 307 | - true_width, | 311 | + if x0 >= 0 && x0 as usize + block_w <= true_width { |
| 308 | - x0, | 312 | + if let Some(src) = reference.get(y * stride + x0 as usize..y * stride + x0 as usize + block_w) { |
| 309 | - taps, | 313 | + for (o, &s) in out.iter_mut().zip(src) { |
| 310 | - &mut intermediate[r * block_w..(r + 1) * block_w], | 314 | + *o = gain * i32::from(s); |
| 311 | - ); | 315 | + } |
| 316 | + continue; | ||
| 317 | + } | ||
| 318 | + } | ||
| 319 | + for (c, o) in out.iter_mut().enumerate() { | ||
| 320 | + let x = (x0 + c as i32).clamp(0, true_width as i32 - 1) as usize; | ||
| 321 | + *o = gain * i32::from(reference[y * stride + x]); | ||
| 322 | + } | ||
| 323 | + continue; | ||
| 324 | + } | ||
| 325 | + hpass_row(reference, y * stride, true_width, x0, taps, out); | ||
| 312 | } | 326 | } |
| 313 | } | 327 | } |
| 314 | 328 | ||
| @@ -543,13 +557,24 @@ pub fn predict_with_filters_kern( | |||
| 543 | 557 | ||
| 544 | // The vertical pass reads 3 rows above and 4 below the block, so the | 558 | // The vertical pass reads 3 rows above and 4 below the block, so the |
| 545 | // horizontal pass must produce that many extra intermediate rows. | 559 | // horizontal pass must produce that many extra intermediate rows. |
| 546 | - let rows = block_h + 7; | 560 | + // A whole-pel vertical position needs neither the 3 rows above nor the 4 |
| 561 | + // below, and its vertical pass is the identity tap: `Round2(128 * a, | ||
| 562 | + // InterRound1) == Round2(a, InterRound1 - 7)`. Passing `y0 + 3` puts the | ||
| 563 | + // block's own first row where the pass would have put the 4th. | ||
| 564 | + let rows = if yfrac == 0 { block_h } else { block_h + 7 }; | ||
| 547 | let max = crate::decode::sample_max(); | 565 | let max = crate::decode::sample_max(); |
| 548 | with_scratch(rows, block_w, |intermediate, acc| { | 566 | with_scratch(rows, block_w, |intermediate, acc| { |
| 549 | horizontal_pass_unscaled( | 567 | horizontal_pass_unscaled( |
| 550 | - reference, stride, true_width, true_height, x0, y0, h_filter, block_w, rows, | 568 | + reference, stride, true_width, true_height, x0, |
| 569 | + if yfrac == 0 { y0 + 3 } else { y0 }, h_filter, block_w, rows, | ||
| 551 | intermediate, | 570 | intermediate, |
| 552 | ); | 571 | ); |
| 572 | + if yfrac == 0 { | ||
| 573 | + for (d, &a) in dst.iter_mut().zip(intermediate.iter()) { | ||
| 574 | + *d = round2(a, INTER_ROUND_1 - 7).clamp(0, max) as u16; | ||
| 575 | + } | ||
| 576 | + return; | ||
| 577 | + } | ||
| 553 | for row in 0..block_h { | 578 | for row in 0..block_h { |
| 554 | vpass_row(intermediate, block_w, row, v_filter, acc); | 579 | vpass_row(intermediate, block_w, row, v_filter, acc); |
| 555 | for (d, &a) in dst[row * block_w..(row + 1) * block_w].iter_mut().zip(acc.iter()) { | 580 | for (d, &a) in dst[row * block_w..(row + 1) * block_w].iter_mut().zip(acc.iter()) { |
| @@ -826,13 +851,20 @@ pub fn predict_scaled_kern( | |||
| 826 | &v_wide[yfrac] | 851 | &v_wide[yfrac] |
| 827 | }; | 852 | }; |
| 828 | 853 | ||
| 829 | - let rows = block_h + 7; | 854 | + let rows = if yfrac == 0 { block_h } else { block_h + 7 }; |
| 830 | let max = crate::decode::sample_max(); | 855 | let max = crate::decode::sample_max(); |
| 831 | with_scratch(rows, block_w, |intermediate, acc| { | 856 | with_scratch(rows, block_w, |intermediate, acc| { |
| 832 | horizontal_pass( | 857 | horizontal_pass( |
| 833 | - reference, stride, true_width, true_height, x_q4, y0, x_scale_fp, block_w, | 858 | + reference, stride, true_width, true_height, x_q4, |
| 859 | + if yfrac == 0 { y0 + 3 } else { y0 }, x_scale_fp, block_w, | ||
| 834 | kern_w, rows, h_kind, intermediate, | 860 | kern_w, rows, h_kind, intermediate, |
| 835 | ); | 861 | ); |
| 862 | + if yfrac == 0 { | ||
| 863 | + for (d, &a) in dst.iter_mut().zip(intermediate.iter()) { | ||
| 864 | + *d = round2(a, INTER_ROUND_1 - 7).clamp(0, max) as u16; | ||
| 865 | + } | ||
| 866 | + return; | ||
| 867 | + } | ||
| 836 | for row in 0..block_h { | 868 | for row in 0..block_h { |
| 837 | vpass_row(intermediate, block_w, row, v_filter, acc); | 869 | vpass_row(intermediate, block_w, row, v_filter, acc); |
| 838 | for (d, &a) in dst[row * block_w..(row + 1) * block_w].iter_mut().zip(acc.iter()) { | 870 | for (d, &a) in dst[row * block_w..(row + 1) * block_w].iter_mut().zip(acc.iter()) { |
| @@ -936,12 +968,18 @@ pub fn predict_compound_intermediate_kern( | |||
| 936 | &v_wide[yfrac] | 968 | &v_wide[yfrac] |
| 937 | }; | 969 | }; |
| 938 | 970 | ||
| 939 | - let rows = block_h + 7; | 971 | + let rows = if yfrac == 0 { block_h } else { block_h + 7 }; |
| 940 | with_scratch(rows, block_w, |intermediate, acc| { | 972 | with_scratch(rows, block_w, |intermediate, acc| { |
| 941 | horizontal_pass( | 973 | horizontal_pass( |
| 942 | - reference, stride, true_width, true_height, x_q4, y0, x_scale_fp, block_w, | 974 | + reference, stride, true_width, true_height, x_q4, |
| 975 | + if yfrac == 0 { y0 + 3 } else { y0 }, x_scale_fp, block_w, | ||
| 943 | kern_w, rows, h_kind, intermediate, | 976 | kern_w, rows, h_kind, intermediate, |
| 944 | ); | 977 | ); |
| 978 | + if yfrac == 0 { | ||
| 979 | + // `Round2(128 * a, INTER_ROUND_1_COMPOUND) == a`. | ||
| 980 | + dst.copy_from_slice(&intermediate[..dst.len()]); | ||
| 981 | + return; | ||
| 982 | + } | ||
| 945 | for row in 0..block_h { | 983 | for row in 0..block_h { |
| 946 | vpass_row(intermediate, block_w, row, v_filter, acc); | 984 | vpass_row(intermediate, block_w, row, v_filter, acc); |
| 947 | for (d, &a) in dst[row * block_w..(row + 1) * block_w].iter_mut().zip(acc.iter()) { | 985 | for (d, &a) in dst[row * block_w..(row + 1) * block_w].iter_mut().zip(acc.iter()) { |