Skip to content

Commit

Permalink
struct Rav1dFrameContext_frame_thread: Add inner mutability to b
Browse files Browse the repository at this point in the history
  • Loading branch information
rinon committed Apr 20, 2024
1 parent 0477ec2 commit 8971042
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 81 deletions.
2 changes: 1 addition & 1 deletion include/common/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ where
println!("{}", what);
for y in 0..h {
for x in 0..w {
print!(" {:0len$}", get(x * y), len = len);
print!(" {:0len$}", get(x + y * w), len = len);
}
println!();
}
Expand Down
2 changes: 1 addition & 1 deletion src/cdef_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn adjust_strength(strength: c_int, var: c_uint) -> c_int {
pub(crate) unsafe fn rav1d_cdef_brow<BD: BitDepth>(
c: &Rav1dContext,
tc: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
p: &[*mut BD::Pixel; 3],
lflvl_offset: i32,
by_start: c_int,
Expand Down
68 changes: 30 additions & 38 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ unsafe fn read_pal_indices(

unsafe fn read_vartx_tree(
t: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
b: &mut Av1Block,
bs: BlockSize,
bx4: c_int,
Expand Down Expand Up @@ -1108,40 +1108,11 @@ unsafe fn obmc_lowest_px(
unsafe fn decode_b(
c: &Rav1dContext,
t: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
bl: BlockLevel,
bs: BlockSize,
bp: BlockPartition,
intra_edge_flags: EdgeFlags,
) -> Result<(), ()> {
// Pull out the current block from Rav1dFrameData so that we can operate on
// it without borrow check errors.
let (mut b_mem, b_idx) = if t.frame_thread.pass != 0 {
let b_idx = (t.b.y as isize * f.b4_stride + t.b.x as isize) as usize;
(mem::take(&mut f.frame_thread.b[b_idx]), Some(b_idx))
} else {
(Default::default(), None)
};
let b = &mut b_mem;
let res = decode_b_inner(c, t, f, bl, bs, bp, intra_edge_flags, b);
if let Some(i) = b_idx {
let _old_b = mem::replace(&mut f.frame_thread.b[i], b_mem);
// TODO(SJC): We should be able to compare Av1Blocks, but there are C
// unions in them.
// assert_eq!(old_b, Default::default());
}
res
}

unsafe fn decode_b_inner(
c: &Rav1dContext,
t: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
bl: BlockLevel,
bs: BlockSize,
bp: BlockPartition,
intra_edge_flags: EdgeFlags,
b: &mut Av1Block,
) -> Result<(), ()> {
use std::fmt;

Expand All @@ -1155,6 +1126,18 @@ unsafe fn decode_b_inner(
}
}

let mut b_guard;
let mut b_mem = Av1Block::default();
let b = if t.frame_thread.pass != 0 {
b_guard = f
.frame_thread
.b
.index_mut((t.b.y as isize * f.b4_stride + t.b.x as isize) as usize);
&mut *b_guard
} else {
&mut b_mem
};

let ts = &mut *f.ts.offset(t.ts as isize);
let bd_fn = f.bd_fn();
let b_dim = &dav1d_block_dimensions[bs as usize];
Expand Down Expand Up @@ -1887,7 +1870,7 @@ unsafe fn decode_b_inner(
TileStateRef::Local => &ts.lflvlmem,
};
rav1d_create_lf_mask_intra(
&mut f.lf.mask[t.lf_mask.unwrap()],
&f.lf.mask[t.lf_mask.unwrap()],
&f.lf.level,
f.b4_stride,
&lflvl[b.seg_id as usize],
Expand Down Expand Up @@ -2905,7 +2888,7 @@ unsafe fn decode_b_inner(
TileStateRef::Local => &ts.lflvlmem,
};
rav1d_create_lf_mask_inter(
&mut f.lf.mask[t.lf_mask.unwrap()],
&f.lf.mask[t.lf_mask.unwrap()],
&f.lf.level,
f.b4_stride,
// In C, the inner dimensions (`ref`, `is_gmv`) are offset,
Expand Down Expand Up @@ -2997,7 +2980,7 @@ unsafe fn decode_b_inner(
if b.skip == 0 {
let mask = !0u32 >> 32 - bw4 << (bx4 & 15);
let bx_idx = (bx4 & 16) >> 4;
for noskip_mask in &mut f.lf.mask[t.lf_mask.unwrap()].noskip_mask[by4 as usize >> 1..]
for noskip_mask in &f.lf.mask[t.lf_mask.unwrap()].noskip_mask[by4 as usize >> 1..]
[..(bh4 as usize + 1) / 2]
{
noskip_mask[bx_idx as usize].fetch_or(mask as u16, Ordering::Relaxed);
Expand Down Expand Up @@ -3245,7 +3228,7 @@ unsafe fn decode_b_inner(
unsafe fn decode_sb(
c: &Rav1dContext,
t: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
bl: BlockLevel,
edge_index: EdgeIndex,
) -> Result<(), ()> {
Expand Down Expand Up @@ -3318,7 +3301,10 @@ unsafe fn decode_sb(
);
}
} else {
let b = &f.frame_thread.b[(t.b.y as isize * f.b4_stride + t.b.x as isize) as usize];
let b = f
.frame_thread
.b
.index((t.b.y as isize * f.b4_stride + t.b.x as isize) as usize);
bp = if b.bl == bl {
b.bp
} else {
Expand Down Expand Up @@ -3479,7 +3465,10 @@ unsafe fn decode_sb(
);
}
} else {
let b = &f.frame_thread.b[(t.b.y as isize * f.b4_stride + t.b.x as isize) as usize];
let b = &f
.frame_thread
.b
.index((t.b.y as isize * f.b4_stride + t.b.x as isize) as usize);
is_split = b.bl != bl;
}

Expand Down Expand Up @@ -3532,7 +3521,10 @@ unsafe fn decode_sb(
);
}
} else {
let b = &f.frame_thread.b[(t.b.y as isize * f.b4_stride + t.b.x as isize) as usize];
let b = &f
.frame_thread
.b
.index((t.b.y as isize * f.b4_stride + t.b.x as isize) as usize);
is_split = b.bl != bl;
}

Expand Down
10 changes: 5 additions & 5 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ pub(crate) struct Rav1dFrameContext_bd_fn {
pub filter_sbrow_deblock_cols: filter_sbrow_fn,
pub filter_sbrow_deblock_rows: filter_sbrow_fn,
pub filter_sbrow_cdef:
unsafe fn(&Rav1dContext, &mut Rav1dFrameData, &mut Rav1dTaskContext, c_int) -> (),
unsafe fn(&Rav1dContext, &Rav1dFrameData, &mut Rav1dTaskContext, c_int) -> (),
pub filter_sbrow_resize: filter_sbrow_fn,
pub filter_sbrow_lr: filter_sbrow_fn,
pub backup_ipred_edge: backup_ipred_edge_fn,
Expand Down Expand Up @@ -444,7 +444,7 @@ impl Rav1dFrameContext_bd_fn {

pub unsafe fn recon_b_intra(
&self,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
context: &mut Rav1dTaskContext,
block_size: BlockSize,
flags: EdgeFlags,
Expand All @@ -455,7 +455,7 @@ impl Rav1dFrameContext_bd_fn {

pub unsafe fn recon_b_inter(
&self,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
context: &mut Rav1dTaskContext,
block_size: BlockSize,
block: &Av1Block,
Expand All @@ -465,7 +465,7 @@ impl Rav1dFrameContext_bd_fn {

pub unsafe fn read_coef_blocks(
&self,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
context: &mut Rav1dTaskContext,
block_size: BlockSize,
block: &Av1Block,
Expand Down Expand Up @@ -548,7 +548,7 @@ pub struct Rav1dFrameContext_frame_thread {
pub next_tile_row: [AtomicI32; 2],

/// Indexed using `t.b.y * f.b4_stride + t.b.x`.
pub b: Vec<Av1Block>,
pub b: DisjointMut<Vec<Av1Block>>,

pub cbi: Vec<[Atomic<CodedBlockInfo>; 3]>,

Expand Down
6 changes: 3 additions & 3 deletions src/lf_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,14 @@ unsafe fn filter_plane_rows_uv<BD: BitDepth>(
}

pub(crate) unsafe fn rav1d_loopfilter_sbrow_cols<BD: BitDepth>(
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
p: &mut [&mut [BD::Pixel]; 3],
p_offset: &[usize; 2],
lflvl_offset: usize,
sby: c_int,
start_of_tile_row: c_int,
) {
let lflvl = &mut f.lf.mask[lflvl_offset..];
let lflvl = &f.lf.mask[lflvl_offset..];
let mut have_left; // Don't filter outside the frame
let seq_hdr = &***f.seq_hdr.as_ref().unwrap();
let is_sb64 = (seq_hdr.sb128 == 0) as c_int;
Expand Down Expand Up @@ -751,7 +751,7 @@ pub(crate) unsafe fn rav1d_loopfilter_sbrow_cols<BD: BitDepth>(
}

pub(crate) unsafe fn rav1d_loopfilter_sbrow_rows<BD: BitDepth>(
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
p: &mut [&mut [BD::Pixel]; 3],
p_offset: &[usize; 2],
lflvl_offset: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/lr_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ unsafe fn lr_sbrow<BD: BitDepth>(

pub(crate) unsafe fn rav1d_lr_sbrow<BD: BitDepth>(
c: &Rav1dContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
dst: &mut [&mut [BD::Pixel]; 3],
dst_offset: &[usize; 2],
sby: c_int,
Expand Down
Loading

0 comments on commit 8971042

Please sign in to comment.