Skip to content

Commit a403fa5

Browse files
authored
struct Rav1dContext: Remove n_tc field (#734)
Removes `n_tc` and replaces it with tc.len() now that tc is a slice.
2 parents c16ee55 + 0f5bbf5 commit a403fa5

6 files changed

Lines changed: 30 additions & 29 deletions

File tree

‎src/cdef_apply.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub(crate) unsafe fn rav1d_cdef_brow<BD: BitDepth>(
219219
let uv_dir: *const u8 = (uv_dirs
220220
[(layout as c_uint == Rav1dPixelLayout::I422 as c_int as c_uint) as c_int as usize])
221221
.as_ptr();
222-
let have_tt = (c.n_tc > 1 as c_uint) as c_int;
222+
let have_tt = (c.tc.len() > 1) as c_int;
223223
let sb128 = (*f).seq_hdr.as_ref().unwrap().sb128;
224224
let resize = (frame_hdr.size.width[0] != frame_hdr.size.width[1]) as c_int;
225225
let y_stride: ptrdiff_t = BD::pxstride((*f).cur.stride[0] as usize) as isize;

‎src/decode.rs‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3922,7 +3922,7 @@ unsafe fn setup_tile(
39223922
ts.lr_ref[p] = *lr_ref;
39233923
}
39243924

3925-
if c.n_tc > 1 {
3925+
if c.tc.len() > 1 {
39263926
ts.progress.fill_with(|| AtomicI32::new(row_sb_start));
39273927
}
39283928
}
@@ -4071,7 +4071,7 @@ pub(crate) unsafe fn rav1d_decode_tile_sbrow(
40714071
t.frame_thread.pass,
40724072
);
40734073
if t.frame_thread.pass == 2 {
4074-
let off_2pass = if c.n_tc > 1 {
4074+
let off_2pass = if c.tc.len() > 1 {
40754075
f.sb128w * frame_hdr.tiling.rows
40764076
} else {
40774077
0
@@ -4097,7 +4097,7 @@ pub(crate) unsafe fn rav1d_decode_tile_sbrow(
40974097
return Err(());
40984098
}
40994099

4100-
if c.n_tc > 1 && frame_hdr.use_ref_frame_mvs != 0 {
4100+
if c.tc.len() > 1 && frame_hdr.use_ref_frame_mvs != 0 {
41014101
c.refmvs_dsp.load_tmvs.expect("non-null function pointer")(
41024102
&f.rf,
41034103
ts.tiling.row,
@@ -4197,7 +4197,7 @@ pub(crate) unsafe fn rav1d_decode_tile_sbrow(
41974197
}
41984198
}
41994199

4200-
if seq_hdr.ref_frame_mvs != 0 && c.n_tc > 1 && frame_hdr.frame_type.is_inter_or_switch() {
4200+
if seq_hdr.ref_frame_mvs != 0 && c.tc.len() > 1 && frame_hdr.frame_type.is_inter_or_switch() {
42014201
rav1d_refmvs_save_tmvs(
42024202
&c.refmvs_dsp,
42034203
&mut t.rt,
@@ -4282,7 +4282,7 @@ pub(crate) unsafe fn rav1d_decode_frame_init(
42824282
f.n_ts = n_ts;
42834283
}
42844284

4285-
let a_sz = f.sb128w * frame_hdr.tiling.rows * (1 + (c.n_fc > 1 && c.n_tc > 1) as c_int);
4285+
let a_sz = f.sb128w * frame_hdr.tiling.rows * (1 + (c.n_fc > 1 && c.tc.len() > 1) as c_int);
42864286
if a_sz != f.a_sz {
42874287
freep(&mut f.a as *mut *mut BlockContext as *mut c_void);
42884288
f.a = malloc(::core::mem::size_of::<BlockContext>() * a_sz as usize) as *mut BlockContext;
@@ -4401,7 +4401,7 @@ pub(crate) unsafe fn rav1d_decode_frame_init(
44014401
let mut y_stride = f.cur.stride[0];
44024402
let mut uv_stride = f.cur.stride[1];
44034403
let has_resize = (frame_hdr.size.width[0] != frame_hdr.size.width[1]) as c_int;
4404-
let need_cdef_lpf_copy = (c.n_tc > 1 && has_resize != 0) as c_int;
4404+
let need_cdef_lpf_copy = (c.tc.len() > 1 && has_resize != 0) as c_int;
44054405
if y_stride * f.sbh as isize * 4 != f.lf.cdef_buf_plane_sz[0] as isize
44064406
|| uv_stride * f.sbh as isize * 8 != f.lf.cdef_buf_plane_sz[1] as isize
44074407
|| need_cdef_lpf_copy != f.lf.need_cdef_lpf_copy
@@ -4473,7 +4473,11 @@ pub(crate) unsafe fn rav1d_decode_frame_init(
44734473
}
44744474

44754475
let sb128 = seq_hdr.sb128;
4476-
let num_lines = if c.n_tc > 1 { (f.sbh * 4) << sb128 } else { 12 };
4476+
let num_lines = if c.tc.len() > 1 {
4477+
(f.sbh * 4) << sb128
4478+
} else {
4479+
12
4480+
};
44774481
y_stride = f.sr_cur.p.stride[0];
44784482
uv_stride = f.sr_cur.p.stride[1];
44794483
if y_stride * num_lines as isize != f.lf.lr_buf_plane_sz[0] as isize
@@ -4607,7 +4611,7 @@ pub(crate) unsafe fn rav1d_decode_frame_init(
46074611
f.mvs,
46084612
f.refrefpoc.as_ptr(),
46094613
f.ref_mvs.as_ptr(),
4610-
c.n_tc as c_int,
4614+
c.tc.len() as c_int,
46114615
c.n_fc as c_int,
46124616
);
46134617
if ret.is_err() {
@@ -4756,7 +4760,7 @@ pub(crate) unsafe fn rav1d_decode_frame_init_cdf(
47564760
}
47574761
}
47584762

4759-
if c.n_tc > 1 {
4763+
if c.tc.len() > 1 {
47604764
for (n, ctx) in slice::from_raw_parts_mut(f.a, sb128w * rows * (1 + uses_2pass as usize))
47614765
.iter_mut()
47624766
.enumerate()
@@ -4777,7 +4781,7 @@ pub(crate) unsafe fn rav1d_decode_frame_init_cdf(
47774781
}
47784782

47794783
unsafe fn rav1d_decode_frame_main(c: &Rav1dContext, f: &mut Rav1dFrameContext) -> Rav1dResult {
4780-
assert!(c.n_tc == 1);
4784+
assert!(c.tc.len() == 1);
47814785

47824786
let Rav1dContextTaskType::Single(t) = &c.tc[0].task else {
47834787
panic!("Expected a single-threaded context");
@@ -4891,15 +4895,15 @@ pub(crate) unsafe fn rav1d_decode_frame(
48914895
f: &mut Rav1dFrameContext,
48924896
) -> Rav1dResult {
48934897
assert!(c.n_fc == 1);
4894-
// if n_tc > 1 (but n_fc == 1), we could run init/exit in the task
4898+
// if.tc.len() > 1 (but n_fc == 1), we could run init/exit in the task
48954899
// threads also. Not sure it makes a measurable difference.
48964900
let mut res = rav1d_decode_frame_init(c, f);
48974901
if res.is_ok() {
48984902
res = rav1d_decode_frame_init_cdf(c, f);
48994903
}
49004904
// wait until all threads have completed
49014905
if res.is_ok() {
4902-
if c.n_tc > 1 {
4906+
if c.tc.len() > 1 {
49034907
res = rav1d_task_create_tile_sbrow(c, f, 0, 1);
49044908
let mut task_thread_lock = (*f.task_thread.ttd).delayed_fg.lock().unwrap();
49054909
(*f.task_thread.ttd).cond.notify_one();

‎src/internal.rs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,9 @@ pub struct Rav1dContext {
240240
pub(crate) fc: *mut Rav1dFrameContext,
241241
pub(crate) n_fc: c_uint,
242242

243-
/// Worker thread join handles and communication, or single thread task
244-
/// context if n_tc == 1
243+
/// Worker thread join handles and communication, or main thread task
244+
/// context if single-threaded
245245
pub(crate) tc: Box<[Rav1dContextTaskThread]>,
246-
/// Number of worker threads
247-
pub(crate) n_tc: c_uint,
248246

249247
/// Cache of OBUs that make up a single frame before we submit them
250248
/// to a frame worker to be decoded.

‎src/lf_apply.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ unsafe fn backup_lpf<BD: BitDepth>(
4444
// The first stripe of the frame is shorter by 8 luma pixel rows.
4545
let mut stripe_h = ((64 as c_int) << (cdef_backup & sb128)) - 8 * (row == 0) as c_int >> ss_ver;
4646
src = src.offset((stripe_h - 2) as isize * BD::pxstride(src_stride as usize) as isize);
47-
if c.n_tc == 1 as c_uint {
47+
if c.tc.len() == 1 {
4848
if row != 0 {
4949
let top = (4 as c_int) << sb128;
5050
// Copy the top part of the stored loop filtered pixels from the
@@ -175,7 +175,7 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
175175
src: *const *mut BD::Pixel,
176176
sby: c_int,
177177
) {
178-
let have_tt = (c.n_tc > 1 as c_uint) as c_int;
178+
let have_tt = (c.tc.len() > 1) as c_int;
179179
let frame_hdr = &***(*f).frame_hdr.as_ref().unwrap();
180180
let resize = (frame_hdr.size.width[0] != frame_hdr.size.width[1]) as c_int;
181181
let offset = 8 * (sby != 0) as c_int;

‎src/lib.rs‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ pub(crate) unsafe fn rav1d_open(c_out: &mut *mut Rav1dContext, s: &Rav1dSettings
295295
}
296296
(*c).flush = AtomicI32::new(0);
297297
let NumThreads { n_tc, n_fc } = get_num_threads(s);
298-
(*c).n_tc = n_tc as c_uint;
299298
(*c).n_fc = n_fc as c_uint;
300299
(*c).fc = rav1d_alloc_aligned(
301300
::core::mem::size_of::<Rav1dFrameContext>().wrapping_mul((*c).n_fc as usize),
@@ -329,7 +328,7 @@ pub(crate) unsafe fn rav1d_open(c_out: &mut *mut Rav1dContext, s: &Rav1dSettings
329328
while n < (*c).n_fc {
330329
let f: *mut Rav1dFrameContext =
331330
&mut *((*c).fc).offset(n as isize) as *mut Rav1dFrameContext;
332-
if (*c).n_tc > 1 as c_uint {
331+
if n_tc > 1 {
333332
(*f).task_thread.lock = Mutex::new(());
334333
(*f).task_thread.cond = Condvar::new();
335334
(*f).task_thread.pending_tasks = Default::default();
@@ -340,12 +339,12 @@ pub(crate) unsafe fn rav1d_open(c_out: &mut *mut Rav1dContext, s: &Rav1dSettings
340339
rav1d_refmvs_init(&mut (*f).rf);
341340
n = n.wrapping_add(1);
342341
}
343-
(*c).tc = (0..(*c).n_tc)
342+
(*c).tc = (0..n_tc)
344343
.map(|_| {
345344
let thread_data = Arc::new(Rav1dTaskContext_task_thread::new(Arc::clone(
346345
&(*c).task_thread,
347346
)));
348-
if (*c).n_tc > 1 {
347+
if n_tc > 1 {
349348
// TODO(SJC): can be removed when c is not a raw pointer
350349
let context_borrow = &*c;
351350
let thread_data_copy = Arc::clone(&thread_data);
@@ -710,7 +709,7 @@ pub(crate) unsafe fn rav1d_apply_grain(
710709
rav1d_picture_unref_internal(out);
711710
return res;
712711
} else {
713-
if c.n_tc > 1 as c_uint {
712+
if c.tc.len() > 1 {
714713
rav1d_task_delayed_fg(c, out, in_0);
715714
} else {
716715
match out.p.bpc {
@@ -789,11 +788,11 @@ pub(crate) unsafe fn rav1d_flush(c: *mut Rav1dContext) {
789788
let _ = mem::take(&mut (*c).mastering_display);
790789
let _ = mem::take(&mut (*c).itut_t35);
791790
let _ = mem::take(&mut (*c).cached_error_props);
792-
if (*c).n_fc == 1 as c_uint && (*c).n_tc == 1 as c_uint {
791+
if (*c).n_fc == 1 as c_uint && (*c).tc.len() == 1 {
793792
return;
794793
}
795794
(*c).flush.store(1, Ordering::SeqCst);
796-
if (*c).n_tc > 1 as c_uint {
795+
if (*c).tc.len() > 1 {
797796
let mut task_thread_lock = (*c).task_thread.delayed_fg.lock().unwrap();
798797
for tc in (*c).tc.iter() {
799798
while !tc.flushed() {
@@ -886,7 +885,7 @@ impl Drop for Rav1dContext {
886885
// remove all pointers from the structure. We can't make the drop
887886
// function unsafe because the Drop trait requires a safe function.
888887
unsafe {
889-
if self.n_tc > 1 {
888+
if self.tc.len() > 1 {
890889
let ttd: &TaskThreadData = &*self.task_thread;
891890
let task_thread_lock = ttd.delayed_fg.lock().unwrap();
892891
for tc in self.tc.iter() {
@@ -923,7 +922,7 @@ impl Drop for Rav1dContext {
923922
);
924923
let _ = mem::take(&mut (*f).frame_thread.cbi); // TODO: remove when context is owned
925924
}
926-
if self.n_tc > 1 as c_uint {
925+
if self.tc.len() > 1 {
927926
let _ = mem::take(&mut (*f).task_thread.pending_tasks); // TODO: remove when context is owned
928927
}
929928
mem::take(&mut (*f).frame_thread.frame_progress); // TODO: remove when context is owned

‎src/lr_apply.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ unsafe fn lr_stripe<BD: BitDepth>(
5252
} else {
5353
0 as c_int
5454
}) >> 6 - ss_ver + seq_hdr.sb128;
55-
let have_tt = (c.n_tc > 1 as c_uint) as c_int;
55+
let have_tt = (c.tc.len() > 1) as c_int;
5656
let mut lpf: *const BD::Pixel = ((*f).lf.lr_lpf_line[plane as usize] as *mut BD::Pixel)
5757
.offset(
5858
(have_tt * (sby * ((4 as c_int) << seq_hdr.sb128) - 4)) as isize

0 commit comments

Comments
 (0)