Directional intra hoists the zone, the derivative and the blend out of the pixel loop
Browse files at this commite7ac08e9648f5494a1b2a3945a5e75e6b9d345eeParent: 29faade- perf
- directional intra hoists the zone, the derivative and the blend out of the pixel loop
1 changed file +58 -43
- crates/ec-av1/src/intra.rs +58 -43
crates/ec-av1/src/intra.rsmodified+58 -43
| @@ -591,57 +591,72 @@ fn directional( | ||
| 591 | 591 | let left_at = |p: i32| left_buf[(p + left_off) as usize]; |
| 592 | 592 | let up_a = i32::from(upsample_above); |
| 593 | 593 | let up_l = i32::from(upsample_left); |
| 594 | - let blend = |edge: &dyn Fn(i32) -> i32, base: i32, shift: i32| { | |
| 595 | - round2(edge(base) * (32 - shift) + edge(base + 1) * shift, 5) | |
| 594 | + let max = crate::decode::sample_max(fctx); | |
| 595 | + // lane-intra: the zone test, the derivative lookup (a 27-arm match) and | |
| 596 | + // the blend's `&dyn Fn` indirection all used to sit inside the pixel | |
| 597 | + // loop; they are per-block (per-row for the shift) constants. | |
| 598 | + let blend = |edge: &[i32], off: i32, base: i32, shift: i32| { | |
| 599 | + round2(edge[(base + off) as usize] * (32 - shift) + edge[(base + off + 1) as usize] * shift, 5) | |
| 596 | 600 | }; |
| 597 | - | |
| 598 | - for row in 0..h { | |
| 599 | - for col in 0..w { | |
| 600 | - let value = if angle < 90 { | |
| 601 | - let dx = dr_intra_derivative(angle); | |
| 602 | - let max_base = (reach - 1) << up_a; | |
| 603 | - let frac_bits = 6 - up_a; | |
| 604 | - let x = dx * (row + 1); | |
| 605 | - let base = (x >> frac_bits) + (col << up_a); | |
| 606 | - let shift = ((x << up_a) & 0x3F) >> 1; | |
| 607 | - if base < max_base { | |
| 608 | - blend(&above_at, base, shift) | |
| 601 | + if angle < 90 { | |
| 602 | + let dx = dr_intra_derivative(angle); | |
| 603 | + let max_base = (reach - 1) << up_a; | |
| 604 | + let frac_bits = 6 - up_a; | |
| 605 | + for (row, dstrow) in dst.chunks_exact_mut(bw).enumerate() { | |
| 606 | + let x = dx * (row as i32 + 1); | |
| 607 | + let base0 = x >> frac_bits; | |
| 608 | + let shift = ((x << up_a) & 0x3F) >> 1; | |
| 609 | + for (col, d) in dstrow.iter_mut().enumerate() { | |
| 610 | + let base = base0 + ((col as i32) << up_a); | |
| 611 | + let value = if base < max_base { | |
| 612 | + blend(above_buf, above_off, base, shift) | |
| 609 | 613 | } else { |
| 610 | 614 | above_at(max_base) |
| 611 | - } | |
| 612 | - } else if angle > 180 { | |
| 613 | - let dy = dr_intra_derivative(270 - angle); | |
| 614 | - let max_base = (reach - 1) << up_l; | |
| 615 | - let frac_bits = 6 - up_l; | |
| 616 | - let y = dy * (col + 1); | |
| 617 | - let base = (y >> frac_bits) + (row << up_l); | |
| 615 | + }; | |
| 616 | + *d = value.clamp(0, max) as u16; | |
| 617 | + } | |
| 618 | + } | |
| 619 | + } else if angle > 180 { | |
| 620 | + let dy = dr_intra_derivative(270 - angle); | |
| 621 | + let max_base = (reach - 1) << up_l; | |
| 622 | + let frac_bits = 6 - up_l; | |
| 623 | + for (row, dstrow) in dst.chunks_exact_mut(bw).enumerate() { | |
| 624 | + let r = (row as i32) << up_l; | |
| 625 | + for (col, d) in dstrow.iter_mut().enumerate() { | |
| 626 | + let y = dy * (col as i32 + 1); | |
| 627 | + let base = (y >> frac_bits) + r; | |
| 618 | 628 | let shift = ((y << up_l) & 0x3F) >> 1; |
| 619 | - if base < max_base { | |
| 620 | - blend(&left_at, base, shift) | |
| 629 | + let value = if base < max_base { | |
| 630 | + blend(left_buf, left_off, base, shift) | |
| 621 | 631 | } else { |
| 622 | 632 | left_at(max_base) |
| 623 | - } | |
| 624 | - } else { | |
| 625 | - // The two zones meet here: a ray that leaves through the row | |
| 626 | - // above is read there, and one that leaves through the column | |
| 627 | - // to the left is read there instead. | |
| 628 | - let dx = dr_intra_derivative(180 - angle); | |
| 629 | - let min_base = -(1 << up_a); | |
| 630 | - let frac_bits_x = 6 - up_a; | |
| 631 | - let y = row + 1; | |
| 632 | - let x = (col << 6) - y * dx; | |
| 633 | + }; | |
| 634 | + *d = value.clamp(0, max) as u16; | |
| 635 | + } | |
| 636 | + } | |
| 637 | + } else { | |
| 638 | + // The two zones meet here: a ray that leaves through the row above is | |
| 639 | + // read there, and one that leaves through the column to the left is | |
| 640 | + // read there instead. | |
| 641 | + let dx = dr_intra_derivative(180 - angle); | |
| 642 | + let dy = dr_intra_derivative(angle - 90); | |
| 643 | + let min_base = -(1 << up_a); | |
| 644 | + let frac_bits_x = 6 - up_a; | |
| 645 | + let frac_bits_y = 6 - up_l; | |
| 646 | + for (row, dstrow) in dst.chunks_exact_mut(bw).enumerate() { | |
| 647 | + let ydx = (row as i32 + 1) * dx; | |
| 648 | + let yrow = (row as i32) << 6; | |
| 649 | + for (col, d) in dstrow.iter_mut().enumerate() { | |
| 650 | + let x = ((col as i32) << 6) - ydx; | |
| 633 | 651 | let base = x >> frac_bits_x; |
| 634 | - if base >= min_base { | |
| 635 | - blend(&above_at, base, ((x << up_a) & 0x3F) >> 1) | |
| 652 | + let value = if base >= min_base { | |
| 653 | + blend(above_buf, above_off, base, ((x << up_a) & 0x3F) >> 1) | |
| 636 | 654 | } else { |
| 637 | - let dy = dr_intra_derivative(angle - 90); | |
| 638 | - let frac_bits_y = 6 - up_l; | |
| 639 | - let x2 = col + 1; | |
| 640 | - let y2 = (row << 6) - x2 * dy; | |
| 641 | - blend(&left_at, y2 >> frac_bits_y, ((y2 << up_l) & 0x3F) >> 1) | |
| 642 | - } | |
| 643 | - }; | |
| 644 | - dst[(row * w + col) as usize] = value.clamp(0, crate::decode::sample_max(fctx)) as u16; | |
| 655 | + let y2 = yrow - (col as i32 + 1) * dy; | |
| 656 | + blend(left_buf, left_off, y2 >> frac_bits_y, ((y2 << up_l) & 0x3F) >> 1) | |
| 657 | + }; | |
| 658 | + *d = value.clamp(0, max) as u16; | |
| 659 | + } | |
| 645 | 660 | } |
| 646 | 661 | } |
| 647 | 662 | } |