Commit 8e063aaf authored by Romain Vimont's avatar Romain Vimont Committed by Romain Vimont

Move FrameBlocks out of BlockContext

With tiling, the lifetime of FrameBlocks will exceed that of
BlockContext (which will exist only during tile encoding).

Therefore, create it separately, and make BlockContext reference it.
parent 0c9c2c04
......@@ -44,7 +44,8 @@ fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
let mut fi = FrameInvariants::<u16>::new(config, sequence);
let mut w = ec::WriterEncoder::new();
let fc = CDFContext::new(fi.base_q_idx);
let bc = BlockContext::new(fi.sb_width * 16, fi.sb_height * 16);
let mut fb = FrameBlocks::new(fi.sb_width * 16, fi.sb_height * 16);
let bc = BlockContext::new(&mut fb);
let mut fs = FrameState::new(&fi);
// For now, restoration unit size is locked to superblock size.
let mut cw = ContextWriter::new(fc, bc);
......@@ -113,7 +114,8 @@ fn cdef_frame_bench(b: &mut Bencher, width: usize, height: usize) {
};
let sequence = Sequence::new(&Default::default());
let fi = FrameInvariants::<u16>::new(config, sequence);
let bc = BlockContext::new(fi.sb_width * 16, fi.sb_height * 16);
let mut fb = FrameBlocks::new(fi.sb_width * 16, fi.sb_height * 16);
let bc = BlockContext::new(&mut fb);
let mut fs = FrameState::new(&fi);
b.iter(|| cdef_filter_frame(&fi, &mut fs.rec, &bc.blocks));
......
......@@ -1444,8 +1444,7 @@ pub struct BlockContextCheckpoint {
left_coeff_context: [[u8; MAX_MIB_SIZE]; PLANES],
}
#[derive(Clone)]
pub struct BlockContext {
pub struct BlockContext<'a> {
pub cdef_coded: bool,
pub code_deltas: bool,
pub update_seg: bool,
......@@ -1456,16 +1455,16 @@ pub struct BlockContext {
left_tx_context: [u8; MAX_MIB_SIZE],
above_coeff_context: [Vec<u8>; PLANES],
left_coeff_context: [[u8; MAX_MIB_SIZE]; PLANES],
pub blocks: FrameBlocks,
pub blocks: &'a mut FrameBlocks,
}
impl BlockContext {
pub fn new(cols: usize, rows: usize) -> BlockContext {
impl<'a> BlockContext<'a> {
pub fn new(blocks: &'a mut FrameBlocks) -> Self {
// Align power of two
let aligned_cols = (cols + ((1 << MAX_MIB_SIZE_LOG2) - 1))
let aligned_cols = (blocks.cols + ((1 << MAX_MIB_SIZE_LOG2) - 1))
& !((1 << MAX_MIB_SIZE_LOG2) - 1);
let above_coeff_context_size =
cols << (MI_SIZE_LOG2 - TxSize::width_log2(TxSize::TX_4X4));
blocks.cols << (MI_SIZE_LOG2 - TxSize::width_log2(TxSize::TX_4X4));
BlockContext {
cdef_coded: false,
......@@ -1482,7 +1481,7 @@ impl BlockContext {
vec![0; above_coeff_context_size]
],
left_coeff_context: [[0; MAX_MIB_SIZE]; PLANES],
blocks: FrameBlocks::new(cols, rows),
blocks,
}
}
......@@ -1908,17 +1907,16 @@ pub struct ContextWriterCheckpoint {
pub bc: BlockContextCheckpoint,
}
#[derive(Clone)]
pub struct ContextWriter {
pub bc: BlockContext,
pub struct ContextWriter<'a> {
pub bc: BlockContext<'a>,
pub fc: CDFContext,
#[cfg(debug)]
fc_map: Option<FieldMap> // For debugging purposes
}
impl ContextWriter {
impl<'a> ContextWriter<'a> {
#[allow(clippy::let_and_return)]
pub fn new(fc: CDFContext, bc: BlockContext) -> Self {
pub fn new(fc: CDFContext, bc: BlockContext<'a>) -> Self {
#[allow(unused_mut)]
let mut cw = ContextWriter {
fc,
......
......@@ -2031,7 +2031,8 @@ fn encode_tile<T: Pixel>(fi: &FrameInvariants<T>, fs: &mut FrameState<T>) -> Vec
}
};
let bc = BlockContext::new(fi.w_in_b, fi.h_in_b);
let mut blocks = FrameBlocks::new(fi.w_in_b, fi.h_in_b);
let bc = BlockContext::new(&mut blocks);
// For now, restoration unit size is locked to superblock size.
let mut cw = ContextWriter::new(fc, bc);
......
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