Commit d57e7fc3 authored by Romain Vimont's avatar Romain Vimont Committed by Thomas Daede

Replace multirows mutable slices in predict

parent d7fa101e
......@@ -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> =
......@@ -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];
......@@ -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]);
})
}
......@@ -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]
);
......@@ -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]
);
......@@ -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]);
})
}
......@@ -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]);
})
}
......@@ -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
......@@ -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]
);
......@@ -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]
);
......@@ -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]
);
......@@ -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,
......@@ -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..]
);
......@@ -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);
})
}
......@@ -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..]
);
......@@ -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..]
);
......@@ -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..]);
})
}
......@@ -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]);
})
}
......@@ -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
......@@ -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..]
);
......@@ -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..]
);
......@@ -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..]
);
......
......@@ -1041,7 +1041,6 @@ impl PredictionMode {
let (left, not_left) = edge_buf.array.split_at(2*MAX_TX_SIZE);
let (top_left, above) = not_left.split_at(1);
let stride = dst.plane.cfg.stride;
let x = dst.x;
let y = dst.y;
......@@ -1061,23 +1060,21 @@ impl PredictionMode {
_ => self
};
let slice = dst.as_mut_slice();
let above_slice = &above[..B::W + B::H];
let left_slice = &left[2 * MAX_TX_SIZE - B::H..];
let left_and_left_below_slice = &left[2 * MAX_TX_SIZE - B::H - B::W..];
match mode {
PredictionMode::DC_PRED => match (x, y) {
(0, 0) => B::pred_dc_128(slice, stride, bit_depth),
(_, 0) => B::pred_dc_left(slice, stride, above_slice, left_slice),
(0, _) => B::pred_dc_top(slice, stride, above_slice, left_slice),
_ => B::pred_dc(slice, stride, above_slice, left_slice)
(0, 0) => B::pred_dc_128(dst, bit_depth),
(_, 0) => B::pred_dc_left(dst, above_slice, left_slice),
(0, _) => B::pred_dc_top(dst, above_slice, left_slice),
_ => B::pred_dc(dst, above_slice, left_slice)
},
PredictionMode::UV_CFL_PRED => match (x, y) {
(0, 0) => B::pred_cfl_128(slice, stride, &ac, alpha, bit_depth),
(0, 0) => B::pred_cfl_128(dst, &ac, alpha, bit_depth),
(_, 0) => B::pred_cfl_left(
slice,
stride,
dst,
&ac,
alpha,
bit_depth,
......@@ -1085,8 +1082,7 @@ impl PredictionMode {
left_slice
),
(0, _) => B::pred_cfl_top(
slice,
stride,
dst,
&ac,
alpha,
bit_depth,
......@@ -1094,8 +1090,7 @@ impl PredictionMode {
left_slice
),
_ => B::pred_cfl(
slice,
stride,
dst,
&ac,
alpha,
bit_depth,
......@@ -1103,28 +1098,28 @@ impl PredictionMode {
left_slice
)
},
PredictionMode::H_PRED => B::pred_h(slice, stride, left_slice),
PredictionMode::V_PRED => B::pred_v(slice, stride, above_slice),
PredictionMode::H_PRED => B::pred_h(dst, left_slice),
PredictionMode::V_PRED => B::pred_v(dst, above_slice),
PredictionMode::PAETH_PRED =>
B::pred_paeth(slice, stride, above_slice, left_slice, top_left[0]),
B::pred_paeth(dst, above_slice, left_slice, top_left[0]),
PredictionMode::SMOOTH_PRED =>
B::pred_smooth(slice, stride, above_slice, left_slice),
B::pred_smooth(dst, above_slice, left_slice),
PredictionMode::SMOOTH_H_PRED =>
B::pred_smooth_h(slice, stride, above_slice, left_slice),
B::pred_smooth_h(dst, above_slice, left_slice),
PredictionMode::SMOOTH_V_PRED =>
B::pred_smooth_v(slice, stride, above_slice, left_slice),
B::pred_smooth_v(dst, above_slice, left_slice),
PredictionMode::D45_PRED =>
B::pred_directional(slice, stride, above_slice, left_and_left_below_slice, top_left, 45, bit_depth),
B::pred_directional(dst, above_slice, left_and_left_below_slice, top_left, 45, bit_depth),
PredictionMode::D135_PRED =>
B::pred_directional(slice, stride, above_slice, left_and_left_below_slice, top_left, 135, bit_depth),
B::pred_directional(dst, above_slice, left_and_left_below_slice, top_left, 135, bit_depth),
PredictionMode::D117_PRED =>
B::pred_directional(slice, stride, above_slice, left_and_left_below_slice, top_left, 113, bit_depth),
B::pred_directional(dst, above_slice, left_and_left_below_slice, top_left, 113, bit_depth),
PredictionMode::D153_PRED =>
B::pred_directional(slice, stride, above_slice, left_and_left_below_slice, top_left, 157, bit_depth),
B::pred_directional(dst, above_slice, left_and_left_below_slice, top_left, 157, bit_depth),
PredictionMode::D207_PRED =>
B::pred_directional(slice, stride, above_slice, left_and_left_below_slice, top_left, 203, bit_depth),
B::pred_directional(dst, above_slice, left_and_left_below_slice, top_left, 203, bit_depth),
PredictionMode::D63_PRED =>
B::pred_directional(slice, stride, above_slice, left_and_left_below_slice, top_left, 67, bit_depth),
B::pred_directional(dst, above_slice, left_and_left_below_slice, top_left, 67, bit_depth),
_ => unimplemented!()
}
}
......
......@@ -16,7 +16,7 @@ use std::ops::{Index, IndexMut, Range};
use crate::util::*;
/// Plane-specific configuration.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PlaneConfig {
pub stride: usize,
pub alloc_height: usize,
......@@ -37,7 +37,7 @@ pub struct PlaneOffset {
pub y: isize
}
#[derive(Clone)]
#[derive(Clone, PartialEq, Eq)]
pub struct Plane<T: Pixel> {
pub data: Vec<T>,
pub cfg: PlaneConfig
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment