Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: PlaneRegion extension, deployment, buffer work, and fix for #2360 #2390

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions src/asm/x86/cdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

use crate::cdef::*;
use crate::cpu_features::CpuFeatureLevel;
use crate::frame::*;
use crate::tiling::PlaneRegionMut;
use crate::tiling::{PlaneRegion, PlaneRegionMut};
use crate::util::*;

type CdefFilterFn = unsafe extern fn(
Expand Down Expand Up @@ -41,16 +40,15 @@ const fn decimate_index(xdec: usize, ydec: usize) -> usize {
((ydec << 1) | xdec) & 3
}

pub(crate) unsafe fn cdef_filter_block<T: Pixel>(
dst: &mut PlaneRegionMut<'_, T>, src: *const u16, src_stride: isize,
pub(crate) fn cdef_filter_block<T: Pixel>(
dst: &mut PlaneRegionMut<'_, T>, src: &PlaneRegion<'_, u16>,
pri_strength: i32, sec_strength: i32, dir: usize, damping: i32,
bit_depth: usize, xdec: usize, ydec: usize, cpu: CpuFeatureLevel,
) {
let call_rust = |dst: &mut PlaneRegionMut<T>| {
rust::cdef_filter_block(
dst,
src,
src_stride,
pri_strength,
sec_strength,
dir,
Expand All @@ -67,40 +65,42 @@ pub(crate) unsafe fn cdef_filter_block<T: Pixel>(
call_rust(&mut copy.as_region_mut());
copy
};
match T::type_enum() {
PixelType::U8 => {
match CDEF_FILTER_FNS[cpu.as_index()][decimate_index(xdec, ydec)] {
Some(func) => {
(func)(
dst.data_ptr_mut() as *mut _,
T::to_asm_stride(dst.plane_cfg.stride),
src,
src_stride,
pri_strength,
sec_strength,
dir as i32,
damping,
);
unsafe {
match T::type_enum() {
PixelType::U8 => {
match CDEF_FILTER_FNS[cpu.as_index()][decimate_index(xdec, ydec)] {
Some(func) => {
(func)(
dst.data_ptr_mut() as *mut _,
T::to_asm_stride(dst.plane_cfg.stride),
src.data_ptr() as *const _,
T::to_asm_stride(src.plane_cfg.stride),
pri_strength,
sec_strength,
dir as i32,
damping,
);
}
None => call_rust(dst),
}
None => call_rust(dst),
}
}
PixelType::U16 => {
match CDEF_FILTER_HBD_FNS[cpu.as_index()][decimate_index(xdec, ydec)] {
Some(func) => {
(func)(
dst.data_ptr_mut() as *mut _,
T::to_asm_stride(dst.plane_cfg.stride),
src,
src_stride,
pri_strength,
sec_strength,
dir as i32,
damping,
(1 << bit_depth) - 1,
PixelType::U16 => {
match CDEF_FILTER_HBD_FNS[cpu.as_index()][decimate_index(xdec, ydec)] {
Some(func) => {
(func)(
dst.data_ptr_mut() as *mut _,
T::to_asm_stride(dst.plane_cfg.stride),
src.data_ptr() as *const _,
T::to_asm_stride(src.plane_cfg.stride),
pri_strength,
sec_strength,
dir as i32,
damping,
(1 << bit_depth) - 1,
);
}
None => call_rust(dst),
}
None => call_rust(dst),
}
}
}
Expand Down Expand Up @@ -159,7 +159,7 @@ type CdefDirFn =
#[inline(always)]
#[allow(clippy::let_and_return)]
pub(crate) fn cdef_find_dir<T: Pixel>(
img: &PlaneSlice<'_, u16>, var: &mut u32, coeff_shift: usize,
img: &PlaneRegion<'_, u16>, var: &mut u32, coeff_shift: usize,
cpu: CpuFeatureLevel,
) -> i32 {
let call_rust =
Expand All @@ -180,8 +180,8 @@ pub(crate) fn cdef_find_dir<T: Pixel>(
// input, even when working with 8 bit input. Mostly done to limit
// the amount of code being impacted.
(func)(
img.as_ptr() as *const u16,
u16::to_asm_stride(img.plane.cfg.stride),
img.data_ptr() as *const u16,
u16::to_asm_stride(img.plane_cfg.stride),
var as *mut u32,
)
}
Expand Down
36 changes: 18 additions & 18 deletions src/asm/x86/lrf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.

use crate::cpu_features::CpuFeatureLevel;
use crate::frame::PlaneSlice;
use crate::tiling::PlaneRegion;
use crate::lrf::*;
use crate::util::Pixel;
#[cfg(target_arch = "x86")]
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn sgrproj_box_ab_r2(

#[inline]
pub fn sgrproj_box_f_r0<T: Pixel>(
f: &mut [u32], y: usize, w: usize, cdeffed: &PlaneSlice<T>,
f: &mut [u32], y: usize, w: usize, cdeffed: &PlaneRegion<'_, T>,
cpu: CpuFeatureLevel,
) {
if cpu >= CpuFeatureLevel::AVX2 {
Expand All @@ -108,7 +108,7 @@ pub fn sgrproj_box_f_r0<T: Pixel>(
#[inline]
pub fn sgrproj_box_f_r1<T: Pixel>(
af: &[&[u32]; 3], bf: &[&[u32]; 3], f: &mut [u32], y: usize, w: usize,
cdeffed: &PlaneSlice<T>, cpu: CpuFeatureLevel,
cdeffed: &PlaneRegion<'_, T>, cpu: CpuFeatureLevel,
) {
if cpu >= CpuFeatureLevel::AVX2 {
return unsafe {
Expand All @@ -122,7 +122,7 @@ pub fn sgrproj_box_f_r1<T: Pixel>(
#[inline]
pub fn sgrproj_box_f_r2<T: Pixel>(
af: &[&[u32]; 2], bf: &[&[u32]; 2], f0: &mut [u32], f1: &mut [u32],
y: usize, w: usize, cdeffed: &PlaneSlice<T>, cpu: CpuFeatureLevel,
y: usize, w: usize, cdeffed: &PlaneRegion<'_, T>, cpu: CpuFeatureLevel,
) {
if cpu >= CpuFeatureLevel::AVX2 {
return unsafe {
Expand Down Expand Up @@ -353,18 +353,18 @@ pub(crate) unsafe fn sgrproj_box_ab_r2_avx2(
#[inline]
#[target_feature(enable = "avx2")]
unsafe fn sgrproj_box_f_r0_8_avx2<T: Pixel>(
f: &mut [u32], x: usize, y: usize, cdeffed: &PlaneSlice<T>,
f: &mut [u32], x: usize, y: usize, cdeffed: &PlaneRegion<'_, T>,
) {
_mm256_storeu_si256(
f.as_mut_ptr().add(x) as *mut _,
_mm256_slli_epi32(
if mem::size_of::<T>() == 1 {
_mm256_cvtepu8_epi32(_mm_loadl_epi64(
cdeffed.subslice(x, y).as_ptr() as *const _
cdeffed[y][x..].as_ptr() as *const _
))
} else {
_mm256_cvtepu16_epi32(_mm_loadu_si128(
cdeffed.subslice(x, y).as_ptr() as *const _
cdeffed[y][x..].as_ptr() as *const _
))
},
SGRPROJ_RST_BITS as i32,
Expand All @@ -374,7 +374,7 @@ unsafe fn sgrproj_box_f_r0_8_avx2<T: Pixel>(

#[target_feature(enable = "avx2")]
pub(crate) unsafe fn sgrproj_box_f_r0_avx2<T: Pixel>(
f: &mut [u32], y: usize, w: usize, cdeffed: &PlaneSlice<T>,
f: &mut [u32], y: usize, w: usize, cdeffed: &PlaneRegion<'_, T>,
) {
for x in (0..w).step_by(8) {
if x + 8 <= w {
Expand All @@ -397,7 +397,7 @@ pub(crate) unsafe fn sgrproj_box_f_r0_avx2<T: Pixel>(
#[target_feature(enable = "avx2")]
unsafe fn sgrproj_box_f_r1_8_avx2<T: Pixel>(
af: &[&[u32]; 3], bf: &[&[u32]; 3], f: &mut [u32], x: usize, y: usize,
cdeffed: &PlaneSlice<T>,
cdeffed: &PlaneRegion<'_, T>,
) {
let three = _mm256_set1_epi32(3);
let four = _mm256_set1_epi32(4);
Expand Down Expand Up @@ -474,11 +474,11 @@ unsafe fn sgrproj_box_f_r1_8_avx2<T: Pixel>(
a,
if mem::size_of::<T>() == 1 {
_mm256_cvtepu8_epi32(_mm_loadl_epi64(
cdeffed.subslice(x, y).as_ptr() as *const _
cdeffed[y][x..].as_ptr() as *const _
))
} else {
_mm256_cvtepu16_epi32(_mm_loadu_si128(
cdeffed.subslice(x, y).as_ptr() as *const _
cdeffed[y][x..].as_ptr() as *const _
))
},
),
Expand All @@ -497,7 +497,7 @@ unsafe fn sgrproj_box_f_r1_8_avx2<T: Pixel>(
#[target_feature(enable = "avx2")]
pub(crate) unsafe fn sgrproj_box_f_r1_avx2<T: Pixel>(
af: &[&[u32]; 3], bf: &[&[u32]; 3], f: &mut [u32], y: usize, w: usize,
cdeffed: &PlaneSlice<T>,
cdeffed: &PlaneRegion<'_, T>,
) {
for x in (0..w).step_by(8) {
if x + 8 <= w {
Expand All @@ -520,7 +520,7 @@ pub(crate) unsafe fn sgrproj_box_f_r1_avx2<T: Pixel>(
#[target_feature(enable = "avx2")]
unsafe fn sgrproj_box_f_r2_8_avx2<T: Pixel>(
af: &[&[u32]; 2], bf: &[&[u32]; 2], f0: &mut [u32], f1: &mut [u32],
x: usize, y: usize, cdeffed: &PlaneSlice<T>,
x: usize, y: usize, cdeffed: &PlaneRegion<'_, T>,
) {
let five = _mm256_set1_epi32(5);
let six = _mm256_set1_epi32(6);
Expand Down Expand Up @@ -573,11 +573,11 @@ unsafe fn sgrproj_box_f_r2_8_avx2<T: Pixel>(
_mm256_add_epi32(a, ao),
if mem::size_of::<T>() == 1 {
_mm256_cvtepu8_epi32(_mm_loadl_epi64(
cdeffed.subslice(x, y).as_ptr() as *const _
cdeffed[y][x..].as_ptr() as *const _
))
} else {
_mm256_cvtepu16_epi32(_mm_loadu_si128(
cdeffed.subslice(x, y).as_ptr() as *const _
cdeffed[y][x..].as_ptr() as *const _
))
},
),
Expand All @@ -588,11 +588,11 @@ unsafe fn sgrproj_box_f_r2_8_avx2<T: Pixel>(
ao,
if mem::size_of::<T>() == 1 {
_mm256_cvtepu8_epi32(_mm_loadl_epi64(
cdeffed.subslice(x, y + 1).as_ptr() as *const _,
cdeffed[y+1][x..].as_ptr() as *const _,
))
} else {
_mm256_cvtepu16_epi32(_mm_loadu_si128(
cdeffed.subslice(x, y + 1).as_ptr() as *const _,
cdeffed[y+1][x..].as_ptr() as *const _,
))
},
),
Expand All @@ -619,7 +619,7 @@ unsafe fn sgrproj_box_f_r2_8_avx2<T: Pixel>(
#[target_feature(enable = "avx2")]
pub(crate) unsafe fn sgrproj_box_f_r2_avx2<T: Pixel>(
af: &[&[u32]; 2], bf: &[&[u32]; 2], f0: &mut [u32], f1: &mut [u32],
y: usize, w: usize, cdeffed: &PlaneSlice<T>,
y: usize, w: usize, cdeffed: &PlaneRegion<'_, T>,
) {
for x in (0..w).step_by(8) {
if x + 8 <= w {
Expand Down
Loading