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 4, 2024
1 parent 89bdb22 commit 015eddb
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/cdef_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,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 @@ -3286,7 +3291,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 @@ -3359,7 +3364,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 @@ -3520,7 +3527,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 @@ -3573,7 +3582,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 @@ -357,7 +357,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 @@ -399,7 +399,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 @@ -410,7 +410,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 @@ -420,7 +420,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 @@ -587,7 +587,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 @@ -754,7 +754,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
52 changes: 29 additions & 23 deletions src/recon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,22 @@ macro_rules! debug_block_info {
pub(crate) use debug_block_info;

pub(crate) type recon_b_intra_fn =
unsafe fn(&mut Rav1dFrameData, &mut Rav1dTaskContext, BlockSize, EdgeFlags, &Av1Block) -> ();
unsafe fn(&Rav1dFrameData, &mut Rav1dTaskContext, BlockSize, EdgeFlags, &Av1Block) -> ();

pub(crate) type recon_b_inter_fn =
unsafe fn(&mut Rav1dFrameData, &mut Rav1dTaskContext, BlockSize, &Av1Block) -> Result<(), ()>;
unsafe fn(&Rav1dFrameData, &mut Rav1dTaskContext, BlockSize, &Av1Block) -> Result<(), ()>;

pub(crate) type filter_sbrow_fn =
unsafe fn(&Rav1dContext, &mut Rav1dFrameData, &mut Rav1dTaskContext, c_int) -> ();
unsafe fn(&Rav1dContext, &Rav1dFrameData, &mut Rav1dTaskContext, c_int) -> ();

pub(crate) type backup_ipred_edge_fn = unsafe fn(&Rav1dFrameData, &mut Rav1dTaskContext) -> ();

pub(crate) type read_coef_blocks_fn =
unsafe fn(&mut Rav1dFrameData, &mut Rav1dTaskContext, BlockSize, &Av1Block) -> ();
unsafe fn(&Rav1dFrameData, &mut Rav1dTaskContext, BlockSize, &Av1Block) -> ();

pub(crate) type copy_pal_block_fn = unsafe fn(
t: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
bx4: usize,
by4: usize,
bw4: usize,
Expand All @@ -155,7 +155,7 @@ pub(crate) type copy_pal_block_fn = unsafe fn(

pub(crate) type read_pal_plane_fn = unsafe fn(
t: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
b: &mut Av1Block,
pl: bool,
sz_ctx: u8,
Expand All @@ -165,7 +165,7 @@ pub(crate) type read_pal_plane_fn = unsafe fn(

pub(crate) type read_pal_uv_fn = unsafe fn(
t: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
b: &mut Av1Block,
sz_ctx: u8,
bx4: usize,
Expand Down Expand Up @@ -475,7 +475,7 @@ fn get_lo_ctx(
}

unsafe fn decode_coefs<BD: BitDepth>(
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
t: *mut Rav1dTaskContext,
a: &mut [u8],
l: &mut [u8],
Expand Down Expand Up @@ -1659,7 +1659,7 @@ impl CfSelect {
}

unsafe fn read_coef_tree<BD: BitDepth>(
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
t: *mut Rav1dTaskContext,
bs: BlockSize,
b: &Av1Block,
Expand Down Expand Up @@ -1864,7 +1864,7 @@ unsafe fn read_coef_tree<BD: BitDepth>(
}

pub(crate) unsafe fn rav1d_read_coef_blocks<BD: BitDepth>(
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
t: &mut Rav1dTaskContext,
bs: BlockSize,
b: &Av1Block,
Expand Down Expand Up @@ -2463,7 +2463,7 @@ unsafe fn warp_affine<BD: BitDepth>(
}

pub(crate) unsafe fn rav1d_recon_b_intra<BD: BitDepth>(
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
t: &mut Rav1dTaskContext,
bs: BlockSize,
intra_edge_flags: EdgeFlags,
Expand Down Expand Up @@ -3232,7 +3232,7 @@ pub(crate) unsafe fn rav1d_recon_b_intra<BD: BitDepth>(
}

pub(crate) unsafe fn rav1d_recon_b_inter<BD: BitDepth>(
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
t: &mut Rav1dTaskContext,
bs: BlockSize,
b: &Av1Block,
Expand Down Expand Up @@ -3669,6 +3669,8 @@ pub(crate) unsafe fn rav1d_recon_b_inter<BD: BitDepth>(
* f.b4_stride as usize
+ t.b.x as usize
- 1]
.try_lock()
.unwrap()
.filter2d()
},
)?;
Expand Down Expand Up @@ -3702,7 +3704,9 @@ pub(crate) unsafe fn rav1d_recon_b_inter<BD: BitDepth>(
left_filter_2d
} else {
f.frame_thread.b
[t.b.y as usize * f.b4_stride as usize + t.b.x as usize - 1]
[(t.b.y as isize * f.b4_stride + t.b.x as isize - 1) as usize]
.try_lock()
.unwrap()
.filter2d()
},
)?;
Expand Down Expand Up @@ -3735,6 +3739,8 @@ pub(crate) unsafe fn rav1d_recon_b_inter<BD: BitDepth>(
} else {
f.frame_thread.b
[(t.b.y as usize - 1) * f.b4_stride as usize + t.b.x as usize]
.try_lock()
.unwrap()
.filter2d()
},
)?;
Expand Down Expand Up @@ -4117,7 +4123,7 @@ pub(crate) unsafe fn rav1d_recon_b_inter<BD: BitDepth>(

pub(crate) unsafe fn rav1d_filter_sbrow_deblock_cols<BD: BitDepth>(
c: &Rav1dContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
_t: &mut Rav1dTaskContext,
sby: c_int,
) {
Expand Down Expand Up @@ -4181,7 +4187,7 @@ pub(crate) unsafe fn rav1d_filter_sbrow_deblock_cols<BD: BitDepth>(

pub(crate) unsafe fn rav1d_filter_sbrow_deblock_rows<BD: BitDepth>(
c: &Rav1dContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
_t: &mut Rav1dTaskContext,
sby: c_int,
) {
Expand Down Expand Up @@ -4242,7 +4248,7 @@ pub(crate) unsafe fn rav1d_filter_sbrow_deblock_rows<BD: BitDepth>(

pub(crate) unsafe fn rav1d_filter_sbrow_cdef<BD: BitDepth>(
c: &Rav1dContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
tc: &mut Rav1dTaskContext,
sby: c_int,
) {
Expand Down Expand Up @@ -4285,7 +4291,7 @@ pub(crate) unsafe fn rav1d_filter_sbrow_cdef<BD: BitDepth>(

pub(crate) unsafe fn rav1d_filter_sbrow_resize<BD: BitDepth>(
_c: &Rav1dContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
_t: &mut Rav1dTaskContext,
sby: c_int,
) {
Expand Down Expand Up @@ -4353,7 +4359,7 @@ pub(crate) unsafe fn rav1d_filter_sbrow_resize<BD: BitDepth>(

pub(crate) unsafe fn rav1d_filter_sbrow_lr<BD: BitDepth>(
c: &Rav1dContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
_t: &mut Rav1dTaskContext,
sby: c_int,
) {
Expand Down Expand Up @@ -4389,7 +4395,7 @@ pub(crate) unsafe fn rav1d_filter_sbrow_lr<BD: BitDepth>(

pub(crate) unsafe fn rav1d_filter_sbrow<BD: BitDepth>(
c: &Rav1dContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
t: &mut Rav1dTaskContext,
sby: c_int,
) {
Expand Down Expand Up @@ -4462,7 +4468,7 @@ pub(crate) unsafe fn rav1d_backup_ipred_edge<BD: BitDepth>(

pub(crate) unsafe fn rav1d_copy_pal_block_y<BD: BitDepth>(
t: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
bx4: usize,
by4: usize,
bw4: usize,
Expand All @@ -4488,7 +4494,7 @@ pub(crate) unsafe fn rav1d_copy_pal_block_y<BD: BitDepth>(

pub(crate) unsafe fn rav1d_copy_pal_block_uv<BD: BitDepth>(
t: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
bx4: usize,
by4: usize,
bw4: usize,
Expand Down Expand Up @@ -4517,7 +4523,7 @@ pub(crate) unsafe fn rav1d_copy_pal_block_uv<BD: BitDepth>(

pub(crate) unsafe fn rav1d_read_pal_plane<BD: BitDepth>(
t: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
b: &mut Av1Block,
pl: bool,
sz_ctx: u8,
Expand Down Expand Up @@ -4708,7 +4714,7 @@ pub(crate) unsafe fn rav1d_read_pal_plane<BD: BitDepth>(

pub(crate) unsafe fn rav1d_read_pal_uv<BD: BitDepth>(
t: &mut Rav1dTaskContext,
f: &mut Rav1dFrameData,
f: &Rav1dFrameData,
b: &mut Av1Block,
sz_ctx: u8,
bx4: usize,
Expand Down

0 comments on commit 015eddb

Please sign in to comment.