Skip to content

Commit

Permalink
Merge 7ccf959 into 924a999
Browse files Browse the repository at this point in the history
  • Loading branch information
rom1v committed Feb 28, 2019
2 parents 924a999 + 7ccf959 commit d5cb169
Show file tree
Hide file tree
Showing 11 changed files with 584 additions and 477 deletions.
69 changes: 31 additions & 38 deletions benches/predict.rs
Expand Up @@ -11,12 +11,16 @@ use criterion::*;
use rand::{ChaChaRng, Rng, RngCore, SeedableRng};
use rav1e::partition::BlockSize;
use rav1e::predict::{Block4x4, Intra};
use crate::plane::*;
use crate::util::*;

pub const BLOCK_SIZE: BlockSize = BlockSize::BLOCK_32X32;

pub fn generate_block(rng: &mut ChaChaRng) -> (Vec<u16>, Vec<u16>, Vec<u16>) {
let block = vec![0u16; BLOCK_SIZE.width() * BLOCK_SIZE.height()];
pub fn generate_block(rng: &mut ChaChaRng) -> (Plane<u16>, Vec<u16>, Vec<u16>) {
let block = Plane::wrap(
vec![0u16; BLOCK_SIZE.width() * BLOCK_SIZE.height()],
BLOCK_SIZE.width(),
);
let above_context: Vec<u16> =
(0..BLOCK_SIZE.height()).map(|_| rng.gen()).collect();
let left_context: Vec<u16> =
Expand All @@ -27,8 +31,11 @@ pub fn generate_block(rng: &mut ChaChaRng) -> (Vec<u16>, Vec<u16>, Vec<u16>) {

pub fn generate_block_u8<'a>(
rng: &mut ChaChaRng, edge_buf: &'a mut AlignedArray<[u8; 65]>
) -> (Vec<u8>, &'a [u8], &'a [u8]) {
let block = vec![0u8; BLOCK_SIZE.width() * BLOCK_SIZE.height()];
) -> (Plane<u8>, &'a [u8], &'a [u8]) {
let block = Plane::wrap(
vec![0u8; BLOCK_SIZE.width() * BLOCK_SIZE.height()],
BLOCK_SIZE.width(),
);
rng.fill_bytes(&mut edge_buf.array);
let above_context = &edge_buf.array[33..];
let left_context = &edge_buf.array[..32];
Expand Down Expand Up @@ -81,7 +88,7 @@ pub fn intra_dc_4x4(b: &mut Bencher) {
let (mut block, above, left) = generate_block(&mut rng);

b.iter(|| {
Block4x4::pred_dc(&mut block, BLOCK_SIZE.width(), &above[..4], &left[..4]);
Block4x4::pred_dc(&mut block.as_mut_slice(), &above[..4], &left[..4]);
})
}

Expand All @@ -91,8 +98,7 @@ pub fn intra_dc_left_4x4(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_dc_left(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&above[..4],
&left[..4]
);
Expand All @@ -105,8 +111,7 @@ pub fn intra_dc_top_4x4(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_dc_top(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&above[..4],
&left[..4]
);
Expand All @@ -118,7 +123,7 @@ pub fn intra_h_4x4(b: &mut Bencher) {
let (mut block, _above, left) = generate_block(&mut rng);

b.iter(|| {
Block4x4::pred_h(&mut block, BLOCK_SIZE.width(), &left[..4]);
Block4x4::pred_h(&mut block.as_mut_slice(), &left[..4]);
})
}

Expand All @@ -127,7 +132,7 @@ pub fn intra_v_4x4(b: &mut Bencher) {
let (mut block, above, _left) = generate_block(&mut rng);

b.iter(|| {
Block4x4::pred_v(&mut block, BLOCK_SIZE.width(), &above[..4]);
Block4x4::pred_v(&mut block.as_mut_slice(), &above[..4]);
})
}

Expand All @@ -138,8 +143,7 @@ pub fn intra_paeth_4x4(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_paeth(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&above[..4],
&left[..4],
above_left
Expand All @@ -153,8 +157,7 @@ pub fn intra_smooth_4x4(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_smooth(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&above[..4],
&left[..4]
);
Expand All @@ -167,8 +170,7 @@ pub fn intra_smooth_h_4x4(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_smooth_h(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&above[..4],
&left[..4]
);
Expand All @@ -181,8 +183,7 @@ pub fn intra_smooth_v_4x4(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_smooth_v(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&above[..4],
&left[..4]
);
Expand All @@ -197,8 +198,7 @@ pub fn intra_cfl_4x4(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_cfl(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&ac,
alpha,
8,
Expand All @@ -215,8 +215,7 @@ pub fn intra_dc_4x4_u8(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_dc(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&above[..4],
&left[32 - 4..]
);
Expand All @@ -229,7 +228,7 @@ pub fn intra_dc_128_4x4_u8(b: &mut Bencher) {
let (mut block, _above, _left) = generate_block_u8(&mut rng, &mut edge_buf);

b.iter(|| {
Block4x4::pred_dc_128(&mut block, BLOCK_SIZE.width(), 8);
Block4x4::pred_dc_128(&mut block.as_mut_slice(), 8);
})
}

Expand All @@ -240,8 +239,7 @@ pub fn intra_dc_left_4x4_u8(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_dc_left(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&above[..4],
&left[32 - 4..]
);
Expand All @@ -255,8 +253,7 @@ pub fn intra_dc_top_4x4_u8(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_dc_top(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&above[..4],
&left[32 - 4..]
);
Expand All @@ -269,7 +266,7 @@ pub fn intra_h_4x4_u8(b: &mut Bencher) {
let (mut block, _above, left) = generate_block_u8(&mut rng, &mut edge_buf);

b.iter(|| {
Block4x4::pred_h(&mut block, BLOCK_SIZE.width(), &left[32 - 4..]);
Block4x4::pred_h(&mut block.as_mut_slice(), &left[32 - 4..]);
})
}

Expand All @@ -279,7 +276,7 @@ pub fn intra_v_4x4_u8(b: &mut Bencher) {
let (mut block, above, _left) = generate_block_u8(&mut rng, &mut edge_buf);

b.iter(|| {
Block4x4::pred_v(&mut block, BLOCK_SIZE.width(), &above[..4]);
Block4x4::pred_v(&mut block.as_mut_slice(), &above[..4]);
})
}

Expand All @@ -291,8 +288,7 @@ pub fn intra_paeth_4x4_u8(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_paeth(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&above[..4],
&left[32 - 4..],
above_left
Expand All @@ -307,8 +303,7 @@ pub fn intra_smooth_4x4_u8(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_smooth(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&above[..4],
&left[32 - 4..]
);
Expand All @@ -322,8 +317,7 @@ pub fn intra_smooth_h_4x4_u8(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_smooth_h(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&above[..4],
&left[32 - 4..]
);
Expand All @@ -337,8 +331,7 @@ pub fn intra_smooth_v_4x4_u8(b: &mut Bencher) {

b.iter(|| {
Block4x4::pred_smooth_v(
&mut block,
BLOCK_SIZE.width(),
&mut block.as_mut_slice(),
&above[..4],
&left[32 - 4..]
);
Expand Down
38 changes: 18 additions & 20 deletions src/cdef.rs
Expand Up @@ -55,12 +55,12 @@ fn first_max_element(elems: &[i32]) -> (usize, i32) {
// in a particular direction. Since each direction have the same sum(x^2) term,
// that term is never computed. See Section 2, step 2, of:
// http://jmvalin.ca/notes/intra_paint.pdf
fn cdef_find_dir<T: Pixel>(img: &[T], stride: usize, var: &mut i32, coeff_shift: usize) -> i32 {
fn cdef_find_dir<'a, T: Pixel>(img: &PlaneSlice<'a, T>, var: &mut i32, coeff_shift: usize) -> i32 {
let mut cost: [i32; 8] = [0; 8];
let mut partial: [[i32; 15]; 8] = [[0; 15]; 8];
for i in 0..8 {
for j in 0..8 {
let p: i32 = img[i * stride + j].as_();
let p: i32 = img[i][j].as_();
// We subtract 128 here to reduce the maximum range of the squared
// partial sums.
debug_assert!(p >> coeff_shift <= 255);
Expand Down Expand Up @@ -236,10 +236,10 @@ pub fn cdef_analyze_superblock<T: Pixel>(
let mut var: i32 = 0;
let in_plane = &mut in_frame.planes[0];
let in_po = sbo.plane_offset(&in_plane.cfg);
let in_stride = in_plane.cfg.stride;
let in_slice = &in_plane.mut_slice(&in_po);
dir.dir[bx][by] = cdef_find_dir(in_slice.offset(8*bx+2,8*by+2),
in_stride, &mut var, coeff_shift) as u8;
let in_slice = in_plane.slice(&in_po);
dir.dir[bx][by] = cdef_find_dir(&in_slice.reslice(8 * bx as isize + 2,
8 * by as isize + 2),
&mut var, coeff_shift) as u8;
dir.var[bx][by] = var;
}
}
Expand Down Expand Up @@ -289,8 +289,8 @@ pub fn cdef_sb_padded_frame_copy<T: Pixel>(
let w = f.planes[p].cfg.width as isize;
let offset = sbo.plane_offset(&f.planes[p].cfg);
for y in 0..((sb_size>>ydec) + pad*2) as isize {
let mut out_slice = out.planes[p].mut_slice(&PlaneOffset {x:0, y});
let out_row = out_slice.as_mut_slice();
let mut out_slice = out.planes[p].as_mut_slice();
let out_row = &mut out_slice[y as usize];
if offset.y + y < ipad || offset.y+y >= h + ipad {
// above or below the frame, fill with flag
for x in 0..(sb_size>>xdec) + pad*2 {
Expand Down Expand Up @@ -404,13 +404,13 @@ pub fn cdef_filter_superblock<T: Pixel>(
unsafe {
let xsize = 8 >> xdec;
let ysize = 8 >> ydec;
let dst = out_slice.offset_as_mutable(8 * bx >> xdec, 8 * by >> ydec);
let input = in_slice.offset(8 * bx >> xdec, 8 * by >> ydec);
assert!(dst.len() >= (ysize - 1) * out_stride + xsize);
assert!(input.len() >= ((ysize + 3) * in_stride + xsize + 4) as usize);
cdef_filter_block(dst.as_mut_ptr(),
assert!(out_slice.rows_iter().len() >= (8 * by >> ydec) + ysize);
assert!(in_slice.rows_iter().len() >= (8 * by >> ydec) + ysize + 4);
let dst = out_slice[8 * by >> ydec][8 * bx >> xdec..].as_mut_ptr();
let input = in_slice[8 * by >> ydec][8 * bx >> xdec..].as_ptr();
cdef_filter_block(dst,
out_stride as isize,
input.as_ptr(),
input,
in_stride as isize,
local_pri_strength, local_sec_strength, local_dir,
local_damping, local_damping,
Expand Down Expand Up @@ -452,27 +452,25 @@ pub fn cdef_filter_frame<T: Pixel>(fi: &FrameInvariants<T>, rec: &mut Frame<T>,
for p in 0..3 {
let rec_w = rec.planes[p].cfg.width;
let rec_h = rec.planes[p].cfg.height;
let mut cdef_slice = cdef_frame.planes[p].as_mut_slice();
for row in 0..padded_px[p][1] {
// pad first two elements of current row
{
let mut cdef_slice = cdef_frame.planes[p].mut_slice(&PlaneOffset { x: 0, y: row as isize });
let cdef_row = &mut cdef_slice.as_mut_slice()[..2];
let cdef_row = &mut cdef_slice[row][..2];
// FIXME this is just to make it compile, but it's incorrect if T == u8
cdef_row[0] = T::cast_from(CDEF_VERY_LARGE);
cdef_row[1] = T::cast_from(CDEF_VERY_LARGE);
}
// pad out end of current row
{
let mut cdef_slice = cdef_frame.planes[p].mut_slice(&PlaneOffset { x: rec_w as isize + 2, y: row as isize });
let cdef_row = &mut cdef_slice.as_mut_slice()[..padded_px[p][0]-rec_w-2];
let cdef_row = &mut cdef_slice[row][rec_w + 2..padded_px[p][0]];
for x in cdef_row {
*x = T::cast_from(CDEF_VERY_LARGE);
}
}
// copy current row from rec if we're in data, or pad if we're in first two rows/last N rows
{
let mut cdef_slice = cdef_frame.planes[p].mut_slice(&PlaneOffset { x: 2, y: row as isize });
let cdef_row = &mut cdef_slice.as_mut_slice()[..rec_w];
let cdef_row = &mut cdef_slice[row][2..rec_w + 2];
if row < 2 || row >= rec_h+2 {
for x in cdef_row {
*x = T::cast_from(CDEF_VERY_LARGE);
Expand Down

0 comments on commit d5cb169

Please sign in to comment.