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 6, 2024
1 parent 143abd2 commit 35c1153
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 56 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 @@ -159,7 +159,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
51 changes: 31 additions & 20 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,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 @@ -1151,35 +1151,40 @@ unsafe fn obmc_lowest_px(
unsafe fn decode_b(
c: &Rav1dContext,
t: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
f: &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))
let mut b_mem = Av1Block::default();
let mut b = if t.frame_thread.pass != 0 {
Some(
f.frame_thread.b[(t.b.y as isize * f.b4_stride + t.b.x as isize) as usize]
.try_lock()
.unwrap(),
)
} else {
(Default::default(), None)
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
decode_b_inner(
c,
t,
f,
bl,
bs,
bp,
intra_edge_flags,
b.as_deref_mut().unwrap_or(&mut b_mem),
)
}

unsafe fn decode_b_inner(
c: &Rav1dContext,
t: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
bl: BlockLevel,
bs: BlockSize,
bp: BlockPartition,
Expand Down Expand Up @@ -3285,7 +3290,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 @@ -3358,7 +3363,9 @@ 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[(t.b.y as isize * f.b4_stride + t.b.x as isize) as usize]
.try_lock()
.unwrap();
bp = if b.bl == bl {
b.bp
} else {
Expand Down Expand Up @@ -3519,7 +3526,9 @@ 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[(t.b.y as isize * f.b4_stride + t.b.x as isize) as usize]
.try_lock()
.unwrap();
is_split = b.bl != bl;
}

Expand Down Expand Up @@ -3572,7 +3581,9 @@ 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[(t.b.y as isize * f.b4_stride + t.b.x as isize) as usize]
.try_lock()
.unwrap();
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 @@ -355,7 +355,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 @@ -397,7 +397,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 @@ -408,7 +408,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 @@ -418,7 +418,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 @@ -511,7 +511,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: Vec<Mutex<Av1Block>>,

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

Expand Down
4 changes: 2 additions & 2 deletions src/lf_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ 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,
Expand Down Expand Up @@ -762,7 +762,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 @@ -261,7 +261,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 35c1153

Please sign in to comment.