| 1 |
// Copyright (c) 2020-2022, The rav1e contributors. All rights reserved |
| 2 |
// |
| 3 |
// This source code is subject to the terms of the BSD 2 Clause License and |
| 4 |
// the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 5 |
// was not distributed with this source code in the LICENSE file, you can |
| 6 |
// obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 7 |
// Media Patent License 1.0 was not distributed with this source code in the |
| 8 |
// PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
| 9 |
|
| 10 |
#[cfg(test)] |
| 11 |
mod test { |
| 12 |
use interpolate_name::interpolate_test; |
| 13 |
use rand::random; |
| 14 |
use std::mem::MaybeUninit; |
| 15 |
|
| 16 |
use crate::context::MAX_TX_SIZE; |
| 17 |
use crate::cpu_features::CpuFeatureLevel; |
| 18 |
use crate::frame::{AsRegion, Plane}; |
| 19 |
use crate::partition::{BlockSize, IntraEdge}; |
| 20 |
use crate::predict::dispatch_predict_intra; |
| 21 |
use crate::predict::pred_cfl_ac; |
| 22 |
use crate::predict::rust; |
| 23 |
use crate::predict::{ |
| 24 |
IntraEdgeFilterParameters, PredictionMode, PredictionVariant, |
| 25 |
}; |
| 26 |
use crate::transform::TxSize; |
| 27 |
use crate::util::{slice_assume_init_mut, Aligned}; |
| 28 |
use crate::Pixel; |
| 29 |
|
| 30 |
#[test] |
| 31 |
fn pred_matches() { |
| 32 |
for cpu in |
| 33 |
&CpuFeatureLevel::all()[..=CpuFeatureLevel::default().as_index()] |
| 34 |
{ |
| 35 |
pred_matches_inner::<u8>(*cpu, 8); |
| 36 |
pred_matches_inner::<u16>(*cpu, 10); |
| 37 |
pred_matches_inner::<u16>(*cpu, 12); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
fn pred_matches_inner<T: Pixel>(cpu: CpuFeatureLevel, bit_depth: usize) { |
| 42 |
let tx_size = TxSize::TX_4X4; |
| 43 |
let ac: Aligned<[i16; 32 * 32]> = Aligned::from_fn(|i| i as i16 - 16 * 32); |
| 44 |
let edge_buf = Aligned::from_fn(|i| { |
| 45 |
T::cast_from(((i ^ 1) + 32).saturating_sub(2 * MAX_TX_SIZE)) |
| 46 |
}); |
| 47 |
let edge_buf = IntraEdge::mock(&edge_buf); |
| 48 |
|
| 49 |
let ief_params_all = [ |
| 50 |
None, |
| 51 |
Some(IntraEdgeFilterParameters::default()), |
| 52 |
Some(IntraEdgeFilterParameters { |
| 53 |
above_mode: Some(PredictionMode::SMOOTH_PRED), |
| 54 |
left_mode: Some(PredictionMode::SMOOTH_PRED), |
| 55 |
..Default::default() |
| 56 |
}), |
| 57 |
]; |
| 58 |
|
| 59 |
for (mode, variant) in [ |
| 60 |
(PredictionMode::DC_PRED, PredictionVariant::BOTH), |
| 61 |
(PredictionMode::DC_PRED, PredictionVariant::TOP), |
| 62 |
(PredictionMode::DC_PRED, PredictionVariant::LEFT), |
| 63 |
(PredictionMode::DC_PRED, PredictionVariant::NONE), |
| 64 |
(PredictionMode::V_PRED, PredictionVariant::BOTH), |
| 65 |
(PredictionMode::H_PRED, PredictionVariant::BOTH), |
| 66 |
(PredictionMode::D45_PRED, PredictionVariant::BOTH), |
| 67 |
(PredictionMode::D135_PRED, PredictionVariant::BOTH), |
| 68 |
(PredictionMode::D113_PRED, PredictionVariant::BOTH), |
| 69 |
(PredictionMode::D157_PRED, PredictionVariant::BOTH), |
| 70 |
(PredictionMode::D203_PRED, PredictionVariant::BOTH), |
| 71 |
(PredictionMode::D67_PRED, PredictionVariant::BOTH), |
| 72 |
(PredictionMode::SMOOTH_PRED, PredictionVariant::BOTH), |
| 73 |
(PredictionMode::SMOOTH_V_PRED, PredictionVariant::BOTH), |
| 74 |
(PredictionMode::SMOOTH_H_PRED, PredictionVariant::BOTH), |
| 75 |
(PredictionMode::PAETH_PRED, PredictionVariant::BOTH), |
| 76 |
(PredictionMode::UV_CFL_PRED, PredictionVariant::BOTH), |
| 77 |
(PredictionMode::UV_CFL_PRED, PredictionVariant::TOP), |
| 78 |
(PredictionMode::UV_CFL_PRED, PredictionVariant::LEFT), |
| 79 |
(PredictionMode::UV_CFL_PRED, PredictionVariant::NONE), |
| 80 |
] |
| 81 |
.iter() |
| 82 |
{ |
| 83 |
let angles = match mode { |
| 84 |
PredictionMode::V_PRED => [81, 84, 87, 90, 93, 96, 99].iter(), |
| 85 |
PredictionMode::H_PRED => [171, 174, 177, 180, 183, 186, 189].iter(), |
| 86 |
PredictionMode::D45_PRED => [36, 39, 42, 45, 48, 51, 54].iter(), |
| 87 |
PredictionMode::D135_PRED => { |
| 88 |
[126, 129, 132, 135, 138, 141, 144].iter() |
| 89 |
} |
| 90 |
PredictionMode::D113_PRED => { |
| 91 |
[104, 107, 110, 113, 116, 119, 122].iter() |
| 92 |
} |
| 93 |
PredictionMode::D157_PRED => { |
| 94 |
[148, 151, 154, 157, 160, 163, 166].iter() |
| 95 |
} |
| 96 |
PredictionMode::D203_PRED => { |
| 97 |
[194, 197, 200, 203, 206, 209, 212].iter() |
| 98 |
} |
| 99 |
PredictionMode::D67_PRED => [58, 61, 64, 67, 70, 73, 76].iter(), |
| 100 |
PredictionMode::UV_CFL_PRED => [ |
| 101 |
-15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 1, |
| 102 |
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, |
| 103 |
] |
| 104 |
.iter(), |
| 105 |
_ => [0].iter(), |
| 106 |
}; |
| 107 |
for angle in angles { |
| 108 |
for ief_params in match mode { |
| 109 |
PredictionMode::V_PRED if *angle == 90 => [None].iter(), |
| 110 |
PredictionMode::H_PRED if *angle == 180 => [None].iter(), |
| 111 |
PredictionMode::V_PRED |
| 112 |
| PredictionMode::H_PRED |
| 113 |
| PredictionMode::D45_PRED |
| 114 |
| PredictionMode::D135_PRED |
| 115 |
| PredictionMode::D113_PRED |
| 116 |
| PredictionMode::D157_PRED |
| 117 |
| PredictionMode::D203_PRED |
| 118 |
| PredictionMode::D67_PRED => ief_params_all.iter(), |
| 119 |
_ => [None].iter(), |
| 120 |
} { |
| 121 |
let expected = { |
| 122 |
let mut plane = Plane::from_slice(&[T::zero(); 4 * 4], 4); |
| 123 |
rust::dispatch_predict_intra( |
| 124 |
*mode, |
| 125 |
*variant, |
| 126 |
&mut plane.as_region_mut(), |
| 127 |
tx_size, |
| 128 |
bit_depth, |
| 129 |
&ac.data, |
| 130 |
*angle, |
| 131 |
*ief_params, |
| 132 |
&edge_buf, |
| 133 |
cpu, |
| 134 |
); |
| 135 |
let mut data = [T::zero(); 4 * 4]; |
| 136 |
for (v, d) in data.iter_mut().zip(plane.data[..].iter()) { |
| 137 |
*v = *d; |
| 138 |
} |
| 139 |
data |
| 140 |
}; |
| 141 |
|
| 142 |
let mut output = Plane::from_slice(&[T::zero(); 4 * 4], 4); |
| 143 |
dispatch_predict_intra( |
| 144 |
*mode, |
| 145 |
*variant, |
| 146 |
&mut output.as_region_mut(), |
| 147 |
tx_size, |
| 148 |
bit_depth, |
| 149 |
&ac.data, |
| 150 |
*angle, |
| 151 |
*ief_params, |
| 152 |
&edge_buf, |
| 153 |
cpu, |
| 154 |
); |
| 155 |
assert_eq!( |
| 156 |
expected, |
| 157 |
&output.data[..], |
| 158 |
"mode={:?} variant={:?} angle={} ief_params.use_smooth_filter={:?} bit_depth={} cpu={:?}", |
| 159 |
*mode, |
| 160 |
*variant, |
| 161 |
*angle, |
| 162 |
ief_params.map(|p| p.use_smooth_filter()), |
| 163 |
bit_depth, |
| 164 |
cpu |
| 165 |
); |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
#[interpolate_test(444, 0, 0)] |
| 172 |
#[interpolate_test(422, 1, 0)] |
| 173 |
#[interpolate_test(420, 1, 1)] |
| 174 |
fn pred_cfl_ac_matches(xdec: usize, ydec: usize) { |
| 175 |
pred_cfl_ac_matches_inner::<u8>(xdec, ydec, 8); |
| 176 |
pred_cfl_ac_matches_inner::<u16>(xdec, ydec, 10); |
| 177 |
pred_cfl_ac_matches_inner::<u16>(xdec, ydec, 12); |
| 178 |
} |
| 179 |
|
| 180 |
fn pred_cfl_ac_matches_inner<T: Pixel>( |
| 181 |
xdec: usize, ydec: usize, bit_depth: usize, |
| 182 |
) { |
| 183 |
let h_pad = 0; |
| 184 |
let w_pad = 0; |
| 185 |
let plane_bsize = BlockSize::BLOCK_16X16; |
| 186 |
|
| 187 |
let mut plane = Plane::from_slice(&[T::zero(); 32 * 32], 32); |
| 188 |
for p in plane.data_origin_mut() { |
| 189 |
*p = T::cast_from(random::<u16>() >> (16 - bit_depth)); |
| 190 |
} |
| 191 |
let luma = &plane.as_region(); |
| 192 |
|
| 193 |
let mut ac_ref = Aligned::new([MaybeUninit::new(0x3333i16); 32 * 32]); |
| 194 |
let ac_ref = &mut ac_ref.data[..plane_bsize.area()]; |
| 195 |
|
| 196 |
let cpu = CpuFeatureLevel::RUST; |
| 197 |
(match (xdec, ydec) { |
| 198 |
(0, 0) => rust::pred_cfl_ac::<T, 0, 0>, |
| 199 |
(1, 0) => rust::pred_cfl_ac::<T, 1, 0>, |
| 200 |
(_, _) => rust::pred_cfl_ac::<T, 1, 1>, |
| 201 |
})(ac_ref, luma, plane_bsize, w_pad, h_pad, cpu); |
| 202 |
|
| 203 |
for &cpu in |
| 204 |
&CpuFeatureLevel::all()[..=CpuFeatureLevel::default().as_index()] |
| 205 |
{ |
| 206 |
let mut ac = Aligned::new([MaybeUninit::new(0x7FFFi16); 32 * 32]); |
| 207 |
let ac = &mut ac.data[..plane_bsize.area()]; |
| 208 |
|
| 209 |
(match (xdec, ydec) { |
| 210 |
(0, 0) => pred_cfl_ac::<T, 0, 0>, |
| 211 |
(1, 0) => pred_cfl_ac::<T, 1, 0>, |
| 212 |
(_, _) => pred_cfl_ac::<T, 1, 1>, |
| 213 |
})(ac, luma, plane_bsize, w_pad, h_pad, cpu); |
| 214 |
|
| 215 |
unsafe { |
| 216 |
let ac_ref = slice_assume_init_mut(ac_ref); |
| 217 |
let ac = slice_assume_init_mut(ac); |
| 218 |
|
| 219 |
assert_eq!(&ac_ref, &ac); |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
} |