From c9e134fcc87bba9137c20dc175be4de516e696c1 Mon Sep 17 00:00:00 2001 From: Nicole L Date: Tue, 23 Apr 2024 08:59:39 -0700 Subject: [PATCH] `Rav1dTaskContext::a`: Make into offset and give `BlockContext` interior mutability (#958) --- src/align.rs | 12 ++ src/ctx.rs | 16 +++ src/decode.rs | 317 +++++++++++++++++++++++-------------------- src/env.rs | 263 ++++++++++++++++++----------------- src/internal.rs | 6 +- src/ipred_prepare.rs | 6 +- src/lf_apply.rs | 4 +- src/recon.rs | 217 ++++++++++++++++++----------- 8 files changed, 486 insertions(+), 355 deletions(-) diff --git a/src/align.rs b/src/align.rs index 4eebe681f..3b93af86e 100644 --- a/src/align.rs +++ b/src/align.rs @@ -100,6 +100,18 @@ macro_rules! def_align { } impl AlignedByteChunk for $name<[u8; $align]> {} + + unsafe impl AsMutPtr for $name<[V; N]> { + type Target = V; + + unsafe fn as_mut_ptr(ptr: *mut Self) -> *mut V { + (*ptr).0.as_mut_ptr() + } + + fn len(&self) -> usize { + N + } + } }; } diff --git a/src/ctx.rs b/src/ctx.rs index 0589466f5..5dbb32927 100644 --- a/src/ctx.rs +++ b/src/ctx.rs @@ -37,6 +37,8 @@ //! * is far simpler than the `case_set*` implementation, consisting of a `match` and array writes //! //! [`BlockContext`]: crate::src::env::BlockContext +use crate::src::disjoint_mut::AsMutPtr; +use crate::src::disjoint_mut::DisjointMut; use std::iter::zip; /// Perform a `memset` optimized for lengths that are small powers of 2. @@ -83,6 +85,20 @@ impl CaseSetter(&self, buf: &mut [T], val: T) { small_memset::(&mut buf[self.offset..][..self.len], val); } + + /// # Safety + /// + /// Caller must ensure that no elements of the written range are concurrently + /// borrowed (immutably or mutably) at all during the call to `set_disjoint`. + #[inline] + pub unsafe fn set_disjoint(&self, buf: &DisjointMut, val: V) + where + T: AsMutPtr, + V: Clone + Copy, + { + let mut buf = unsafe { buf.index_mut(self.offset..self.offset + self.len) }; + small_memset::(&mut *buf, val); + } } /// The entrypoint to the [`CaseSet`] API. diff --git a/src/decode.rs b/src/decode.rs index a6ce08f48..8646d1264 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -315,8 +315,8 @@ unsafe fn read_tx_tree( if depth < 2 && from > TX_4X4 { let cat = 2 * (TX_64X64 as c_int - t_dim.max as c_int) - depth; - let a = ((*t.a).tx.0[bx4 as usize] < txw) as c_int; - let l = (t.l.tx.0[by4 as usize] < txh) as c_int; + let a = (*f.a[t.a].tx.index(bx4 as usize) < txw) as c_int; + let l = (*t.l.tx.index(by4 as usize) < txh) as c_int; is_split = rav1d_msac_decode_bool_adapt( &mut ts.msac, @@ -352,11 +352,11 @@ unsafe fn read_tx_tree( t.b.y -= txsh; } else { CaseSet::<16, false>::many( - [(&mut t.l, txh), (&mut *t.a, txw)], + [(&t.l, txh), (&f.a[t.a], txw)], [t_dim.h as usize, t_dim.w as usize], [by4 as usize, bx4 as usize], |case, (dir, val)| { - case.set(&mut dir.tx.0, if is_split { TX_4X4 } else { val }); + case.set_disjoint(&dir.tx, if is_split { TX_4X4 } else { val }); }, ); }; @@ -778,22 +778,22 @@ unsafe fn read_vartx_tree( *b.max_ytx_mut() = b.uvtx; if txfm_mode == Rav1dTxfmMode::Switchable { CaseSet::<32, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [bh4 as usize, bw4 as usize], [by4 as usize, bx4 as usize], |case, dir| { - case.set(&mut dir.tx.0, TX_4X4); + case.set_disjoint(&dir.tx, TX_4X4); }, ); } } else if txfm_mode != Rav1dTxfmMode::Switchable || b.skip != 0 { if txfm_mode == Rav1dTxfmMode::Switchable { CaseSet::<32, false>::many( - [(&mut t.l, 1), (&mut *t.a, 0)], + [(&t.l, 1), (&f.a[t.a], 0)], [bh4 as usize, bw4 as usize], [by4 as usize, bx4 as usize], |case, (dir, dir_index)| { - case.set(&mut dir.tx.0, b_dim[2 + dir_index]); + case.set_disjoint(&dir.tx, b_dim[2 + dir_index]); }, ); } @@ -1171,12 +1171,12 @@ unsafe fn decode_b( y_mode }; CaseSet::<32, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [bh4 as usize, bw4 as usize], [by4 as usize, bx4 as usize], |case, dir| { - case.set(&mut dir.mode.0, y_mode_nofilt); - case.set(&mut dir.intra.0, 1); + case.set_disjoint(&dir.mode, y_mode_nofilt); + case.set_disjoint(&dir.intra, 1); }, ); if frame_type.is_inter_or_switch() { @@ -1196,11 +1196,11 @@ unsafe fn decode_b( if has_chroma { CaseSet::<32, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [cbh4 as usize, cbw4 as usize], [cby4 as usize, cbx4 as usize], |case, dir| { - case.set(&mut dir.uvmode.0, b.uv_mode()); + case.set_disjoint(&dir.uvmode, b.uv_mode()); }, ); } @@ -1243,13 +1243,13 @@ unsafe fn decode_b( let filter = &dav1d_filter_dir[b.filter2d() as usize]; CaseSet::<32, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [bh4 as usize, bw4 as usize], [by4 as usize, bx4 as usize], |case, dir| { - case.set(&mut dir.filter.0[0], filter[0].into()); - case.set(&mut dir.filter.0[1], filter[1].into()); - case.set(&mut dir.intra.0, 0); + case.set_disjoint(&dir.filter[0], filter[0].into()); + case.set_disjoint(&dir.filter[1], filter[1].into()); + case.set_disjoint(&dir.intra, 0); }, ); @@ -1272,11 +1272,11 @@ unsafe fn decode_b( if has_chroma { CaseSet::<32, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [cbh4 as usize, cbw4 as usize], [cby4 as usize, cbx4 as usize], |case, dir| { - case.set(&mut dir.uvmode.0, DC_PRED); + case.set_disjoint(&dir.uvmode, DC_PRED); }, ); } @@ -1312,7 +1312,8 @@ unsafe fn decode_b( seg = Some(&frame_hdr.segmentation.seg_data.d[b.seg_id as usize]); } else if frame_hdr.segmentation.seg_data.preskip != 0 { if frame_hdr.segmentation.temporal != 0 && { - let index = (*t.a).seg_pred.0[bx4 as usize] + t.l.seg_pred.0[by4 as usize]; + let index = + *f.a[t.a].seg_pred.index(bx4 as usize) + *t.l.seg_pred.index(by4 as usize); seg_pred = rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.seg_pred.0[index as usize], @@ -1378,7 +1379,7 @@ unsafe fn decode_b( && frame_hdr.skip_mode.enabled != 0 && cmp::min(bw4, bh4) > 1 { - let smctx = (*t.a).skip_mode.0[bx4 as usize] + t.l.skip_mode.0[by4 as usize]; + let smctx = *f.a[t.a].skip_mode.index(bx4 as usize) + *t.l.skip_mode.index(by4 as usize); b.skip_mode = rav1d_msac_decode_bool_adapt(&mut ts.msac, &mut ts.cdf.m.skip_mode.0[smctx as usize]) as u8; @@ -1393,7 +1394,7 @@ unsafe fn decode_b( if b.skip_mode != 0 || seg.map(|seg| seg.skip != 0).unwrap_or(false) { b.skip = 1; } else { - let sctx = (*t.a).skip[bx4 as usize] + t.l.skip[by4 as usize]; + let sctx = *f.a[t.a].skip.index(bx4 as usize) + *t.l.skip.index(by4 as usize); b.skip = rav1d_msac_decode_bool_adapt(&mut ts.msac, &mut ts.cdf.m.skip[sctx as usize]) as u8; if debug_block_info!(f, t.b) { @@ -1407,7 +1408,7 @@ unsafe fn decode_b( && frame_hdr.segmentation.seg_data.preskip == 0 { if b.skip == 0 && frame_hdr.segmentation.temporal != 0 && { - let index = (*t.a).seg_pred.0[bx4 as usize] + t.l.seg_pred.0[by4 as usize]; + let index = *f.a[t.a].seg_pred.index(bx4 as usize) + *t.l.seg_pred.index(by4 as usize); seg_pred = rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.seg_pred.0[index as usize], @@ -1593,7 +1594,7 @@ unsafe fn decode_b( if let Some(seg) = seg.filter(|seg| seg.r#ref >= 0 || seg.globalmv != 0) { b.intra = (seg.r#ref == 0) as u8; } else { - let ictx = get_intra_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + let ictx = get_intra_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); b.intra = (!rav1d_msac_decode_bool_adapt(&mut ts.msac, &mut ts.cdf.m.intra[ictx.into()])) as u8; @@ -1616,8 +1617,8 @@ unsafe fn decode_b( &mut ts.cdf.m.y_mode[dav1d_ymode_size_context[bs as usize] as usize] } else { &mut ts.cdf.kfym - [dav1d_intra_mode_context[(*t.a).mode.0[bx4 as usize] as usize] as usize] - [dav1d_intra_mode_context[t.l.mode.0[by4 as usize] as usize] as usize] + [dav1d_intra_mode_context[*f.a[t.a].mode.index(bx4 as usize) as usize] as usize] + [dav1d_intra_mode_context[*t.l.mode.index(by4 as usize) as usize] as usize] }; *b.y_mode_mut() = rav1d_msac_decode_symbol_adapt16( &mut ts.msac, @@ -1710,8 +1711,8 @@ unsafe fn decode_b( if frame_hdr.allow_screen_content_tools && cmp::max(bw4, bh4) <= 16 && bw4 + bh4 >= 4 { let sz_ctx = b_dim[2] + b_dim[3] - 2; if b.y_mode() == DC_PRED { - let pal_ctx = ((*t.a).pal_sz.0[bx4 as usize] > 0) as usize - + (t.l.pal_sz.0[by4 as usize] > 0) as usize; + let pal_ctx = (*f.a[t.a].pal_sz.index(bx4 as usize) > 0) as usize + + (*t.l.pal_sz.index(by4 as usize) > 0) as usize; let use_y_pal = rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.pal_y[sz_ctx as usize][pal_ctx], @@ -1838,7 +1839,7 @@ unsafe fn decode_b( b.uvtx = dav1d_max_txfm_size_for_bs[bs as usize][f.cur.p.layout as usize]; let mut t_dim = &dav1d_txfm_dimensions[b.tx() as usize]; if frame_hdr.txfm_mode == Rav1dTxfmMode::Switchable && t_dim.max > TX_4X4 as u8 { - let tctx = get_tx_ctx(&*t.a, &t.l, &*t_dim, by4, bx4); + let tctx = get_tx_ctx(&f.a[t.a], &t.l, &*t_dim, by4, bx4); let tx_cdf = &mut ts.cdf.m.txsz[(t_dim.max - 1) as usize][tctx as usize]; let depth = rav1d_msac_decode_symbol_adapt4( &mut ts.msac, @@ -1869,6 +1870,8 @@ unsafe fn decode_b( TileStateRef::Frame => &f.lf.lvl, TileStateRef::Local => &ts.lflvlmem, }; + let mut a_uv_guard; + let mut l_uv_guard; rav1d_create_lf_mask_intra( &f.lf.mask[t.lf_mask.unwrap()], &f.lf.level, @@ -1881,13 +1884,18 @@ unsafe fn decode_b( b.tx() as RectTxfmSize, b.uvtx as RectTxfmSize, f.cur.p.layout, - &mut (*t.a).tx_lpf_y.0[bx4 as usize..], - &mut t.l.tx_lpf_y.0[by4 as usize..], + &mut f.a[t.a] + .tx_lpf_y + .index_mut(bx4 as usize..(bx4 + bw4) as usize), + &mut t.l.tx_lpf_y.index_mut(by4 as usize..(by4 + bh4) as usize), if has_chroma { - Some(( - &mut (*t.a).tx_lpf_uv.0[cbx4 as usize..], - &mut t.l.tx_lpf_uv.0[cby4 as usize..], - )) + a_uv_guard = f.a[t.a] + .tx_lpf_uv + .index_mut(cbx4 as usize..(cbx4 + cbw4) as usize); + l_uv_guard = + t.l.tx_lpf_uv + .index_mut(cby4 as usize..(cby4 + cbh4) as usize); + Some((&mut a_uv_guard, &mut l_uv_guard)) } else { None }, @@ -1900,30 +1908,31 @@ unsafe fn decode_b( } else { b.y_mode() }; + let is_inter_or_switch = f.frame_hdr().frame_type.is_inter_or_switch(); CaseSet::<32, false>::many( - [(&mut t.l, t_dim.lh, 1), (&mut *t.a, t_dim.lw, 0)], + [(&t.l, t_dim.lh, 1), (&f.a[t.a], t_dim.lw, 0)], [bh4 as usize, bw4 as usize], [by4 as usize, bx4 as usize], |case, (dir, lw_lh, dir_index)| { - case.set(&mut dir.tx_intra.0, lw_lh as i8); - case.set(&mut dir.tx.0, lw_lh); - case.set(&mut dir.mode.0, y_mode_nofilt); - case.set(&mut dir.pal_sz.0, b.pal_sz()[0]); - case.set(&mut dir.seg_pred.0, seg_pred.into()); - case.set(&mut dir.skip_mode.0, 0); - case.set(&mut dir.intra.0, 1); - case.set(&mut dir.skip.0, b.skip); + case.set_disjoint(&dir.tx_intra, lw_lh as i8); + case.set_disjoint(&dir.tx, lw_lh); + case.set_disjoint(&dir.mode, y_mode_nofilt); + case.set_disjoint(&dir.pal_sz, b.pal_sz()[0]); + case.set_disjoint(&dir.seg_pred, seg_pred.into()); + case.set_disjoint(&dir.skip_mode, 0); + case.set_disjoint(&dir.intra, 1); + case.set_disjoint(&dir.skip, b.skip); // see aomedia bug 2183 for why we use luma coordinates here case.set( &mut t.pal_sz_uv[dir_index], if has_chroma { b.pal_sz()[1] } else { 0 }, ); - if f.frame_hdr().frame_type.is_inter_or_switch() { - case.set(&mut dir.comp_type.0, None); - case.set(&mut dir.r#ref[0], -1); - case.set(&mut dir.r#ref[1], -1); - case.set(&mut dir.filter.0[0], Rav1dFilterMode::N_SWITCHABLE_FILTERS); - case.set(&mut dir.filter.0[1], Rav1dFilterMode::N_SWITCHABLE_FILTERS); + if is_inter_or_switch { + case.set_disjoint(&dir.comp_type, None); + case.set_disjoint(&dir.r#ref[0], -1); + case.set_disjoint(&dir.r#ref[1], -1); + case.set_disjoint(&dir.filter[0], Rav1dFilterMode::N_SWITCHABLE_FILTERS); + case.set_disjoint(&dir.filter[1], Rav1dFilterMode::N_SWITCHABLE_FILTERS); } }, ); @@ -1932,11 +1941,11 @@ unsafe fn decode_b( } if has_chroma { CaseSet::<32, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [cbh4 as usize, cbw4 as usize], [cby4 as usize, cbx4 as usize], |case, dir| { - case.set(&mut dir.uvmode.0, b.uv_mode()); + case.set_disjoint(&dir.uvmode, b.uv_mode()); }, ); if b.pal_sz()[1] != 0 { @@ -2072,28 +2081,28 @@ unsafe fn decode_b( splat_intrabc_mv(c, t, &f.rf, bs, b, bw4 as usize, bh4 as usize); CaseSet::<32, false>::many( - [(&mut t.l, 1), (&mut *t.a, 0)], + [(&t.l, 1), (&f.a[t.a], 0)], [bh4 as usize, bw4 as usize], [by4 as usize, bx4 as usize], |case, (dir, dir_index)| { - case.set(&mut dir.tx_intra.0, b_dim[2 + dir_index] as i8); - case.set(&mut dir.mode.0, DC_PRED); - case.set(&mut dir.pal_sz.0, 0); + case.set_disjoint(&dir.tx_intra, b_dim[2 + dir_index] as i8); + case.set_disjoint(&dir.mode, DC_PRED); + case.set_disjoint(&dir.pal_sz, 0); // see aomedia bug 2183 for why this is outside `if has_chroma {}` case.set(&mut t.pal_sz_uv[dir_index], 0); - case.set(&mut dir.seg_pred.0, seg_pred.into()); - case.set(&mut dir.skip_mode.0, 0); - case.set(&mut dir.intra.0, 0); - case.set(&mut dir.skip.0, b.skip); + case.set_disjoint(&dir.seg_pred, seg_pred.into()); + case.set_disjoint(&dir.skip_mode, 0); + case.set_disjoint(&dir.intra, 0); + case.set_disjoint(&dir.skip, b.skip); }, ); if has_chroma { CaseSet::<32, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [cbh4 as usize, cbw4 as usize], [cby4 as usize, cbx4 as usize], |case, dir| { - case.set(&mut dir.uvmode.0, DC_PRED); + case.set_disjoint(&dir.uvmode, DC_PRED); }, ); } @@ -2109,7 +2118,7 @@ unsafe fn decode_b( && frame_hdr.switchable_comp_refs != 0 && cmp::min(bw4, bh4) > 1 { - let ctx = get_comp_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + let ctx = get_comp_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); let is_comp = rav1d_msac_decode_bool_adapt(&mut ts.msac, &mut ts.cdf.m.comp[ctx as usize]); if debug_block_info!(f, t.b) { @@ -2162,22 +2171,24 @@ unsafe fn decode_b( ); } } else if is_comp { - let dir_ctx = get_comp_dir_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + let dir_ctx = get_comp_dir_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); if rav1d_msac_decode_bool_adapt(&mut ts.msac, &mut ts.cdf.m.comp_dir[dir_ctx as usize]) { // bidir - first reference (fw) - let ctx1 = av1_get_fwd_ref_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + let ctx1 = av1_get_fwd_ref_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); if rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.comp_fwd_ref[0][ctx1 as usize], ) { - let ctx2 = av1_get_fwd_ref_2_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + let ctx2 = + av1_get_fwd_ref_2_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); b.ref_mut()[0] = 2 + rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.comp_fwd_ref[2][ctx2 as usize], ) as i8; } else { - let ctx2 = av1_get_fwd_ref_1_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + let ctx2 = + av1_get_fwd_ref_1_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); b.ref_mut()[0] = rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.comp_fwd_ref[1][ctx2 as usize], @@ -2185,14 +2196,15 @@ unsafe fn decode_b( } // second reference (bw) - let ctx3 = av1_get_bwd_ref_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + let ctx3 = av1_get_bwd_ref_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); if rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.comp_bwd_ref[0][ctx3 as usize], ) { b.ref_mut()[1] = 6; } else { - let ctx4 = av1_get_bwd_ref_1_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + let ctx4 = + av1_get_bwd_ref_1_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); b.ref_mut()[1] = 4 + rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.comp_bwd_ref[1][ctx4 as usize], @@ -2200,14 +2212,15 @@ unsafe fn decode_b( } } else { // unidir - let uctx_p = av1_get_ref_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + let uctx_p = av1_get_ref_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); if rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.comp_uni_ref[0][uctx_p as usize], ) { *b.ref_mut() = [4, 6]; } else { - let uctx_p1 = av1_get_uni_p1_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + let uctx_p1 = + av1_get_uni_p1_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); *b.ref_mut() = [ 0, 1 + rav1d_msac_decode_bool_adapt( @@ -2218,7 +2231,7 @@ unsafe fn decode_b( if b.r#ref()[1] == 2 { let uctx_p2 = - av1_get_fwd_ref_2_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + av1_get_fwd_ref_2_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); b.ref_mut()[1] += rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.comp_uni_ref[2][uctx_p2 as usize], @@ -2376,7 +2389,7 @@ unsafe fn decode_b( // jnt_comp vs. seg vs. wedge let mut is_segwedge = false; if seq_hdr.masked_compound != 0 { - let mask_ctx = get_mask_comp_ctx(&*t.a, &t.l, by4, bx4); + let mask_ctx = get_mask_comp_ctx(&f.a[t.a], &t.l, by4, bx4); is_segwedge = rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.mask_comp[mask_ctx as usize], @@ -2404,7 +2417,7 @@ unsafe fn decode_b( f.cur.frame_hdr.as_ref().unwrap().frame_offset as c_uint, ref0poc, ref1poc, - &*t.a, + &f.a[t.a], &t.l, by4, bx4, @@ -2419,14 +2432,16 @@ unsafe fn decode_b( }; *b.comp_type_mut() = Some(comp_type); if debug_block_info!(f, t.b) { + let a = &f.a[t.a]; + let l = &t.l; println!( "Post-jnt_comp[{},ctx={}[ac:{:?},ar:{},lc:{:?},lr:{}]]: r={}", comp_type == CompInterType::Avg, jnt_ctx, - (*t.a).comp_type[bx4 as usize], - (*t.a).r#ref[0][bx4 as usize], - t.l.comp_type[by4 as usize], - t.l.r#ref[0][by4 as usize], + *a.comp_type.index(bx4 as usize), + *a.r#ref[0].index(bx4 as usize), + *l.comp_type.index(by4 as usize), + *l.r#ref[0].index(by4 as usize), ts.msac.rng, ); } @@ -2475,10 +2490,10 @@ unsafe fn decode_b( } else if let Some(_) = seg.filter(|seg| seg.globalmv != 0 || seg.skip != 0) { b.ref_mut()[0] = 0; } else { - let ctx1 = av1_get_ref_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + let ctx1 = av1_get_ref_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); if rav1d_msac_decode_bool_adapt(&mut ts.msac, &mut ts.cdf.m.r#ref[0][ctx1 as usize]) { - let ctx2 = av1_get_bwd_ref_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + let ctx2 = av1_get_bwd_ref_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); if rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.r#ref[1][ctx2 as usize], @@ -2486,27 +2501,27 @@ unsafe fn decode_b( b.ref_mut()[0] = 6; } else { let ctx3 = - av1_get_bwd_ref_1_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + av1_get_bwd_ref_1_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); b.ref_mut()[0] = 4 + rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.r#ref[5][ctx3 as usize], ) as i8; } } else { - let ctx2 = av1_get_fwd_ref_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + let ctx2 = av1_get_fwd_ref_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); if rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.r#ref[2][ctx2 as usize], ) { let ctx3 = - av1_get_fwd_ref_2_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + av1_get_fwd_ref_2_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); b.ref_mut()[0] = 2 + rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.r#ref[4][ctx3 as usize], ) as i8; } else { let ctx3 = - av1_get_fwd_ref_1_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left); + av1_get_fwd_ref_1_ctx(&f.a[t.a], &t.l, by4, bx4, have_top, have_left); b.ref_mut()[0] = rav1d_msac_decode_bool_adapt( &mut ts.msac, &mut ts.cdf.m.r#ref[3][ctx3 as usize], @@ -2733,8 +2748,8 @@ unsafe fn decode_b( && b.inter_mode() == GLOBALMV && frame_hdr.gmv[b.r#ref()[0] as usize].r#type > Rav1dWarpedMotionType::Translation) // has overlappable neighbours - && (have_left && findoddzero(&t.l.intra.0[by4 as usize..][..h4 as usize]) - || have_top && findoddzero(&(*t.a).intra.0[bx4 as usize..][..w4 as usize])) + && (have_left && findoddzero(&t.l.intra.index(by4 as usize..(by4 + h4) as usize)) + || have_top && findoddzero(&f.a[t.a].intra.index(bx4 as usize..(bx4 + w4) as usize))) { // reaching here means the block allows obmc - check warp by // finding matching-ref blocks in top/left edges @@ -2820,14 +2835,14 @@ unsafe fn decode_b( let filter = if frame_hdr.subpel_filter_mode == Rav1dFilterMode::Switchable { if has_subpel_filter { let comp = b.comp_type().is_some(); - let ctx1 = get_filter_ctx(&*t.a, &t.l, comp, false, b.r#ref()[0], by4, bx4); + let ctx1 = get_filter_ctx(&f.a[t.a], &t.l, comp, false, b.r#ref()[0], by4, bx4); let filter0 = rav1d_msac_decode_symbol_adapt4( &mut ts.msac, &mut ts.cdf.m.filter.0[0][ctx1 as usize], Rav1dFilterMode::N_SWITCHABLE_FILTERS as usize - 1, ) as Dav1dFilterMode; if seq_hdr.dual_filter != 0 { - let ctx2 = get_filter_ctx(&*t.a, &t.l, comp, true, b.r#ref()[0], by4, bx4); + let ctx2 = get_filter_ctx(&f.a[t.a], &t.l, comp, true, b.r#ref()[0], by4, bx4); if debug_block_info!(f, t.b) { println!( "Post-subpel_filter1[{},ctx={}]: r={}", @@ -2887,6 +2902,8 @@ unsafe fn decode_b( TileStateRef::Frame => &f.lf.lvl, TileStateRef::Local => &ts.lflvlmem, }; + let mut a_uv_guard; + let mut l_uv_guard; rav1d_create_lf_mask_inter( &f.lf.mask[t.lf_mask.unwrap()], &f.lf.level, @@ -2908,13 +2925,18 @@ unsafe fn decode_b( &tx_split, uvtx, f.cur.p.layout, - &mut (*t.a).tx_lpf_y.0[bx4 as usize..], - &mut t.l.tx_lpf_y.0[by4 as usize..], + &mut f.a[t.a] + .tx_lpf_y + .index_mut(bx4 as usize..(bx4 + bw4) as usize), + &mut t.l.tx_lpf_y.index_mut(by4 as usize..(by4 + bh4) as usize), if has_chroma { - Some(( - &mut (*t.a).tx_lpf_uv.0[cbx4 as usize..], - &mut t.l.tx_lpf_uv.0[cby4 as usize..], - )) + a_uv_guard = f.a[t.a] + .tx_lpf_uv + .index_mut(cbx4 as usize..(cbx4 + cbw4) as usize); + l_uv_guard = + t.l.tx_lpf_uv + .index_mut(cby4 as usize..(cby4 + cbh4) as usize); + Some((&mut *a_uv_guard, &mut *l_uv_guard)) } else { None }, @@ -2929,34 +2951,34 @@ unsafe fn decode_b( } CaseSet::<32, false>::many( - [(&mut t.l, 1), (&mut *t.a, 0)], + [(&t.l, 1), (&f.a[t.a], 0)], [bh4 as usize, bw4 as usize], [by4 as usize, bx4 as usize], |case, (dir, dir_index)| { - case.set(&mut dir.seg_pred.0, seg_pred.into()); - case.set(&mut dir.skip_mode.0, b.skip_mode); - case.set(&mut dir.intra.0, 0); - case.set(&mut dir.skip.0, b.skip); - case.set(&mut dir.pal_sz.0, 0); + case.set_disjoint(&dir.seg_pred, seg_pred.into()); + case.set_disjoint(&dir.skip_mode, b.skip_mode); + case.set_disjoint(&dir.intra, 0); + case.set_disjoint(&dir.skip, b.skip); + case.set_disjoint(&dir.pal_sz, 0); // see aomedia bug 2183 for why this is outside if (has_chroma) case.set(&mut t.pal_sz_uv[dir_index], 0); - case.set(&mut dir.tx_intra.0, b_dim[2 + dir_index] as i8); - case.set(&mut dir.comp_type.0, b.comp_type()); - case.set(&mut dir.filter.0[0], filter[0]); - case.set(&mut dir.filter.0[1], filter[1]); - case.set(&mut dir.mode.0, b.inter_mode()); - case.set(&mut dir.r#ref.0[0], b.r#ref()[0]); - case.set(&mut dir.r#ref.0[1], b.r#ref()[1]); + case.set_disjoint(&dir.tx_intra, b_dim[2 + dir_index] as i8); + case.set_disjoint(&dir.comp_type, b.comp_type()); + case.set_disjoint(&dir.filter[0], filter[0]); + case.set_disjoint(&dir.filter[1], filter[1]); + case.set_disjoint(&dir.mode, b.inter_mode()); + case.set_disjoint(&dir.r#ref[0], b.r#ref()[0]); + case.set_disjoint(&dir.r#ref[1], b.r#ref()[1]); }, ); if has_chroma { CaseSet::<32, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [cbh4 as usize, cbw4 as usize], [cby4 as usize, cbx4 as usize], |case, dir| { - case.set(&mut dir.uvmode.0, DC_PRED); + case.set_disjoint(&dir.uvmode, DC_PRED); }, ); } @@ -3271,7 +3293,7 @@ unsafe fn decode_sb( } bx8 = (t.b.x & 31) >> 1; by8 = (t.b.y & 31) >> 1; - ctx = get_partition_ctx(&*t.a, &t.l, bl, by8, bx8); + ctx = get_partition_ctx(&f.a[t.a], &t.l, bl, by8, bx8); Some(&mut ts.cdf.m.partition[bl as usize][ctx as usize]) }; @@ -3556,12 +3578,12 @@ unsafe fn decode_sb( if t.frame_thread.pass != 2 && (bp != BlockPartition::Split || bl == BlockLevel::Bl8x8) { CaseSet::<16, false>::many( - [(&mut *t.a, 0), (&mut t.l, 1)], + [(&f.a[t.a], 0), (&t.l, 1)], [hsz as usize; 2], [bx8 as usize, by8 as usize], |case, (dir, dir_index)| { - case.set( - &mut dir.partition.0, + case.set_disjoint( + &dir.partition, dav1d_al_part_ctx[dir_index][bl as usize][bp as usize], ); }, @@ -3572,39 +3594,42 @@ unsafe fn decode_sb( } fn reset_context(ctx: &mut BlockContext, keyframe: bool, pass: c_int) { - ctx.intra.0.fill(keyframe.into()); - ctx.uvmode.0.fill(DC_PRED); + ctx.intra.get_mut().0.fill(keyframe.into()); + ctx.uvmode.get_mut().0.fill(DC_PRED); if keyframe { - ctx.mode.0.fill(DC_PRED); + ctx.mode.get_mut().0.fill(DC_PRED); } if pass == 2 { return; } - ctx.partition.0.fill(0); - ctx.skip.0.fill(0); - ctx.skip_mode.0.fill(0); - ctx.tx_lpf_y.0.fill(2); - ctx.tx_lpf_uv.0.fill(1); - ctx.tx_intra.0.fill(-1); - ctx.tx.0.fill(TX_64X64); + ctx.partition.get_mut().0.fill(0); + ctx.skip.get_mut().0.fill(0); + ctx.skip_mode.get_mut().0.fill(0); + ctx.tx_lpf_y.get_mut().0.fill(2); + ctx.tx_lpf_uv.get_mut().0.fill(1); + ctx.tx_intra.get_mut().0.fill(-1); + ctx.tx.get_mut().0.fill(TX_64X64); if !keyframe { - for r#ref in &mut ctx.r#ref.0 { - r#ref.fill(-1); + for r#ref in &mut ctx.r#ref { + r#ref.get_mut().0.fill(-1); } - ctx.comp_type.0.fill(None); - ctx.mode.0.fill(NEARESTMV); + ctx.comp_type.get_mut().0.fill(None); + ctx.mode.get_mut().0.fill(NEARESTMV); } - ctx.lcoef.0.fill(0x40); - for ccoef in &mut ctx.ccoef.0 { - ccoef.fill(0x40); + ctx.lcoef.get_mut().0.fill(0x40); + for ccoef in &mut ctx.ccoef { + ccoef.get_mut().0.fill(0x40); } - for filter in &mut ctx.filter.0 { - filter.fill(Rav1dFilterMode::N_SWITCHABLE_FILTERS as u8); + for filter in &mut ctx.filter { + filter + .get_mut() + .0 + .fill(Rav1dFilterMode::N_SWITCHABLE_FILTERS as u8); } - ctx.seg_pred.0.fill(0); - ctx.pal_sz.0.fill(0); + ctx.seg_pred.get_mut().0.fill(0); + ctx.pal_sz.get_mut().0.fill(0); } impl DefaultValue for [u8; 2] { @@ -3875,9 +3900,7 @@ pub(crate) unsafe fn rav1d_decode_tile_sbrow( } else { 0 }; - t.a = - f.a.as_mut_ptr() - .offset((off_2pass + col_sb128_start + tile_row * f.sb128w) as isize); + t.a = (off_2pass + col_sb128_start + tile_row * f.sb128w) as usize; for bx in (ts.tiling.col_start..ts.tiling.col_end).step_by(sb_step as usize) { t.b.x = bx; if c.flush.load(Ordering::Acquire) != 0 { @@ -3885,7 +3908,7 @@ pub(crate) unsafe fn rav1d_decode_tile_sbrow( } decode_sb(c, t, f, root_bl, EdgeIndex::root())?; if t.b.x & 16 != 0 || f.seq_hdr().sb128 != 0 { - t.a = (t.a).offset(1); + t.a += 1; } } (f.bd_fn().backup_ipred_edge)(f, t); @@ -3911,9 +3934,7 @@ pub(crate) unsafe fn rav1d_decode_tile_sbrow( } t.pal_sz_uv[1] = Default::default(); let sb128y = t.b.y >> 5; - t.a = - f.a.as_mut_ptr() - .offset((col_sb128_start + tile_row * f.sb128w) as isize); + t.a = (col_sb128_start + tile_row * f.sb128w) as usize; t.lf_mask = Some((sb128y * f.sb128w + col_sb128_start) as usize); for bx in (ts.tiling.col_start..ts.tiling.col_end).step_by(sb_step as usize) { t.b.x = bx; @@ -4000,7 +4021,7 @@ pub(crate) unsafe fn rav1d_decode_tile_sbrow( } decode_sb(c, t, f, root_bl, EdgeIndex::root())?; if t.b.x & 16 != 0 || f.seq_hdr().sb128 != 0 { - t.a = (t.a).offset(1); + t.a += 1; t.lf_mask = t.lf_mask.map(|i| i + 1); } } @@ -4029,16 +4050,20 @@ pub(crate) unsafe fn rav1d_decode_tile_sbrow( // up the initial value in neighbour tiles when running the loopfilter let mut align_h = f.bh + 31 & !31; let start_y = (align_h * tile_col + t.b.y) as usize; + let len_y = sb_step as usize; + let start_lpf_y = (t.b.y & 16) as usize; f.lf.tx_lpf_right_edge.copy_from_slice_y( - start_y..start_y + sb_step as usize, - &t.l.tx_lpf_y.0[(t.b.y & 16) as usize..][..sb_step as usize], + start_y..start_y + len_y, + &t.l.tx_lpf_y.index(start_lpf_y..start_lpf_y + len_y), ); let ss_ver = (f.cur.p.layout == Rav1dPixelLayout::I420) as c_int; align_h >>= ss_ver; let start_uv = (align_h * tile_col + (t.b.y >> ss_ver)) as usize; + let len_uv = (sb_step >> ss_ver) as usize; + let lpf_uv_start = ((t.b.y & 16) >> ss_ver) as usize; f.lf.tx_lpf_right_edge.copy_from_slice_uv( - start_uv..start_uv + (sb_step >> ss_ver) as usize, - &t.l.tx_lpf_uv.0[((t.b.y & 16) >> ss_ver) as usize..][..(sb_step >> ss_ver) as usize], + start_uv..start_uv + len_uv, + &t.l.tx_lpf_uv.index(lpf_uv_start..lpf_uv_start + len_uv), ); Ok(()) diff --git a/src/env.rs b/src/env.rs index d6dfa2d4e..999f6287e 100644 --- a/src/env.rs +++ b/src/env.rs @@ -4,6 +4,7 @@ use crate::include::dav1d::headers::Rav1dFrameHeader; use crate::include::dav1d::headers::Rav1dWarpedMotionParams; use crate::include::dav1d::headers::Rav1dWarpedMotionType; use crate::src::align::Align8; +use crate::src::disjoint_mut::DisjointMut; use crate::src::disjoint_mut::DisjointMutSlice; use crate::src::internal::Bxy; use crate::src::levels::mv; @@ -28,25 +29,24 @@ use std::ffi::c_int; use std::ffi::c_uint; #[derive(Default)] -#[repr(C)] pub struct BlockContext { - pub mode: Align8<[u8; 32]>, - pub lcoef: Align8<[u8; 32]>, - pub ccoef: Align8<[[u8; 32]; 2]>, - pub seg_pred: Align8<[u8; 32]>, - pub skip: Align8<[u8; 32]>, - pub skip_mode: Align8<[u8; 32]>, - pub intra: Align8<[u8; 32]>, - pub comp_type: Align8<[Option; 32]>, - pub r#ref: Align8<[[i8; 32]; 2]>, - pub filter: Align8<[[u8; 32]; 2]>, - pub tx_intra: Align8<[i8; 32]>, - pub tx: Align8<[u8; 32]>, - pub tx_lpf_y: Align8<[u8; 32]>, - pub tx_lpf_uv: Align8<[u8; 32]>, - pub partition: Align8<[u8; 16]>, - pub uvmode: Align8<[u8; 32]>, - pub pal_sz: Align8<[u8; 32]>, + pub mode: DisjointMut>, + pub lcoef: DisjointMut>, + pub ccoef: [DisjointMut>; 2], + pub seg_pred: DisjointMut>, + pub skip: DisjointMut>, + pub skip_mode: DisjointMut>, + pub intra: DisjointMut>, + pub comp_type: DisjointMut; 32]>>, + pub r#ref: [DisjointMut>; 2], + pub filter: [DisjointMut>; 2], + pub tx_intra: DisjointMut>, + pub tx: DisjointMut>, + pub tx_lpf_y: DisjointMut>, + pub tx_lpf_uv: DisjointMut>, + pub partition: DisjointMut>, + pub uvmode: DisjointMut>, + pub pal_sz: DisjointMut>, } #[inline] @@ -60,14 +60,14 @@ pub fn get_intra_ctx( ) -> u8 { if have_left { if have_top { - let ctx = l.intra[yb4 as usize] + a.intra[xb4 as usize]; + let ctx = *l.intra.index(yb4 as usize) + *a.intra.index(xb4 as usize); ctx + (ctx == 2) as u8 } else { - l.intra[yb4 as usize] * 2 + *l.intra.index(yb4 as usize) * 2 } } else { if have_top { - a.intra[xb4 as usize] * 2 + *a.intra.index(xb4 as usize) * 2 } else { 0 } @@ -82,8 +82,8 @@ pub fn get_tx_ctx( yb4: c_int, xb4: c_int, ) -> u8 { - (l.tx_intra[yb4 as usize] as i32 >= max_tx.lh as i32) as u8 - + (a.tx_intra[xb4 as usize] as i32 >= max_tx.lw as i32) as u8 + (*l.tx_intra.index(yb4 as usize) as i32 >= max_tx.lh as i32) as u8 + + (*a.tx_intra.index(xb4 as usize) as i32 >= max_tx.lw as i32) as u8 } #[inline] @@ -98,7 +98,7 @@ pub fn get_partition_ctx( // but the BlockLevel enum represents the variants numerically in the opposite order // (128x128 = 0, 8x8 = 4). The shift reverses the ordering. let has_bl = |x| (x >> (4 - bl as u8)) & 1; - has_bl(a.partition[xb8 as usize]) + 2 * has_bl(l.partition[yb8 as usize]) + has_bl(*a.partition.index(xb8 as usize)) + 2 * has_bl(*l.partition.index(yb8 as usize)) } #[inline] @@ -160,8 +160,8 @@ pub fn get_filter_ctx( xb4: c_int, ) -> u8 { let [a_filter, l_filter] = [(a, xb4), (l, yb4)].map(|(al, b4)| { - if al.r#ref[0][b4 as usize] == r#ref || al.r#ref[1][b4 as usize] == r#ref { - al.filter[dir as usize][b4 as usize] + if *al.r#ref[0].index(b4 as usize) == r#ref || *al.r#ref[1].index(b4 as usize) == r#ref { + *al.filter[dir as usize].index(b4 as usize) } else { Rav1dFilterMode::N_SWITCHABLE_FILTERS } @@ -190,31 +190,32 @@ pub fn get_comp_ctx( ) -> u8 { if have_top { if have_left { - if a.comp_type[xb4 as usize].is_some() { - if l.comp_type[yb4 as usize].is_some() { + if a.comp_type.index(xb4 as usize).is_some() { + if l.comp_type.index(yb4 as usize).is_some() { 4 } else { // 4U means intra (-1) or bwd (>= 4) - 2 + (l.r#ref[0][yb4 as usize] as c_uint >= 4) as u8 + 2 + (*l.r#ref[0].index(yb4 as usize) as c_uint >= 4) as u8 } - } else if l.comp_type[yb4 as usize].is_some() { + } else if l.comp_type.index(yb4 as usize).is_some() { // 4U means intra (-1) or bwd (>= 4) - 2 + (a.r#ref[0][xb4 as usize] as c_uint >= 4) as u8 + 2 + (*a.r#ref[0].index(xb4 as usize) as c_uint >= 4) as u8 } else { - ((l.r#ref[0][yb4 as usize] >= 4) ^ (a.r#ref[0][xb4 as usize] >= 4)) as u8 + ((*l.r#ref[0].index(yb4 as usize) >= 4) ^ (*a.r#ref[0].index(xb4 as usize) >= 4)) + as u8 } } else { - if a.comp_type[xb4 as usize].is_some() { + if a.comp_type.index(xb4 as usize).is_some() { 3 } else { - (a.r#ref[0][xb4 as usize] >= 4) as u8 + (*a.r#ref[0].index(xb4 as usize) >= 4) as u8 } } } else if have_left { - if l.comp_type[yb4 as usize].is_some() { + if l.comp_type.index(yb4 as usize).is_some() { 3 } else { - (l.r#ref[0][yb4 as usize] >= 4) as u8 + (*l.r#ref[0].index(yb4 as usize) >= 4) as u8 } } else { 1 @@ -231,35 +232,35 @@ pub fn get_comp_dir_ctx( have_left: bool, ) -> u8 { let has_uni_comp = |edge: &BlockContext, off| { - (edge.r#ref[0][off as usize] < 4) == (edge.r#ref[1][off as usize] < 4) + (*edge.r#ref[0].index(off as usize) < 4) == (*edge.r#ref[1].index(off as usize) < 4) }; if have_top && have_left { - let a_intra = a.intra[xb4 as usize] != 0; - let l_intra = l.intra[yb4 as usize] != 0; + let a_intra = *a.intra.index(xb4 as usize) != 0; + let l_intra = *l.intra.index(yb4 as usize) != 0; if a_intra && l_intra { return 2; } if a_intra || l_intra { - let edge = if a_intra { l } else { a }; + let edge = if a_intra { &l } else { &a }; let off = if a_intra { yb4 } else { xb4 }; - if edge.comp_type[off as usize].is_none() { + if edge.comp_type.index(off as usize).is_none() { return 2; } return 1 + 2 * has_uni_comp(edge, off) as u8; } - let a_comp = a.comp_type[xb4 as usize].is_some(); - let l_comp = l.comp_type[yb4 as usize].is_some(); - let a_ref0 = a.r#ref[0][xb4 as usize]; - let l_ref0 = l.r#ref[0][yb4 as usize]; + let a_comp = a.comp_type.index(xb4 as usize).is_some(); + let l_comp = l.comp_type.index(yb4 as usize).is_some(); + let a_ref0 = *a.r#ref[0].index(xb4 as usize); + let l_ref0 = *l.r#ref[0].index(yb4 as usize); if !a_comp && !l_comp { return 1 + 2 * ((a_ref0 >= 4) == (l_ref0 >= 4)) as u8; } else if !a_comp || !l_comp { - let edge = if a_comp { a } else { l }; + let edge = if a_comp { &a } else { &l }; let off = if a_comp { xb4 } else { yb4 }; if !has_uni_comp(edge, off) { @@ -267,8 +268,8 @@ pub fn get_comp_dir_ctx( } return 3 + ((a_ref0 >= 4) == (l_ref0 >= 4)) as u8; } else { - let a_uni = has_uni_comp(a, xb4); - let l_uni = has_uni_comp(l, yb4); + let a_uni = has_uni_comp(&a, xb4); + let l_uni = has_uni_comp(&l, yb4); if !a_uni && !l_uni { return 0; @@ -282,13 +283,13 @@ pub fn get_comp_dir_ctx( let edge = if have_left { l } else { a }; let off = if have_left { yb4 } else { xb4 }; - if edge.intra[off as usize] != 0 { + if *edge.intra.index(off as usize) != 0 { return 2; } - if edge.comp_type[off as usize].is_none() { + if edge.comp_type.index(off as usize).is_none() { return 2; } - return 4 * has_uni_comp(edge, off) as u8; + return 4 * has_uni_comp(&edge, off) as u8; } else { return 2; }; @@ -319,8 +320,8 @@ pub fn get_jnt_comp_ctx( let d1 = get_poc_diff(order_hint_n_bits, poc as c_int, ref1poc as c_int).abs(); let offset = (d0 == d1) as u8; let [a_ctx, l_ctx] = [(a, xb4), (l, yb4)].map(|(al, b4)| { - (al.comp_type[b4 as usize] >= Some(CompInterType::Avg) || al.r#ref[0][b4 as usize] == 6) - as u8 + (*al.comp_type.index(b4 as usize) >= Some(CompInterType::Avg) + || *al.r#ref[0].index(b4 as usize) == 6) as u8 }); 3 * offset + a_ctx + l_ctx @@ -329,9 +330,9 @@ pub fn get_jnt_comp_ctx( #[inline] pub fn get_mask_comp_ctx(a: &BlockContext, l: &BlockContext, yb4: c_int, xb4: c_int) -> u8 { let [a_ctx, l_ctx] = [(a, xb4), (l, yb4)].map(|(al, b4)| { - if al.comp_type[b4 as usize] >= Some(CompInterType::Seg) { + if *al.comp_type.index(b4 as usize) >= Some(CompInterType::Seg) { 1 - } else if al.r#ref[0][b4 as usize] == 6 { + } else if *al.r#ref[0].index(b4 as usize) == 6 { 3 } else { 0 @@ -361,17 +362,17 @@ pub fn av1_get_ref_ctx( ) -> u8 { let mut cnt = [0; 2]; - if have_top && a.intra[xb4 as usize] == 0 { - cnt[(a.r#ref[0][xb4 as usize] >= 4) as usize] += 1; - if a.comp_type[xb4 as usize].is_some() { - cnt[(a.r#ref[1][xb4 as usize] >= 4) as usize] += 1; + if have_top && *a.intra.index(xb4 as usize) == 0 { + cnt[(*a.r#ref[0].index(xb4 as usize) >= 4) as usize] += 1; + if a.comp_type.index(xb4 as usize).is_some() { + cnt[(*a.r#ref[1].index(xb4 as usize) >= 4) as usize] += 1; } } - if have_left && l.intra[yb4 as usize] == 0 { - cnt[(l.r#ref[0][yb4 as usize] >= 4) as usize] += 1; - if l.comp_type[yb4 as usize].is_some() { - cnt[(l.r#ref[1][yb4 as usize] >= 4) as usize] += 1; + if have_left && *l.intra.index(yb4 as usize) == 0 { + cnt[(*l.r#ref[0].index(yb4 as usize) >= 4) as usize] += 1; + if l.comp_type.index(yb4 as usize).is_some() { + cnt[(*l.r#ref[1].index(yb4 as usize) >= 4) as usize] += 1; } } @@ -389,21 +390,25 @@ pub fn av1_get_fwd_ref_ctx( ) -> u8 { let mut cnt = [0; 4]; - if have_top && a.intra[xb4 as usize] == 0 { - if a.r#ref[0][xb4 as usize] < 4 { - cnt[a.r#ref[0][xb4 as usize] as usize] += 1; + if have_top && *a.intra.index(xb4 as usize) == 0 { + let ref0 = *a.r#ref[0].index(xb4 as usize); + if ref0 < 4 { + cnt[ref0 as usize] += 1; } - if a.comp_type[xb4 as usize].is_some() && a.r#ref[1][xb4 as usize] < 4 { - cnt[a.r#ref[1][xb4 as usize] as usize] += 1; + let ref1 = *a.r#ref[1].index(xb4 as usize); + if a.comp_type.index(xb4 as usize).is_some() && ref1 < 4 { + cnt[ref1 as usize] += 1; } } - if have_left && l.intra[yb4 as usize] == 0 { - if l.r#ref[0][yb4 as usize] < 4 { - cnt[l.r#ref[0][yb4 as usize] as usize] += 1; + if have_left && *l.intra.index(yb4 as usize) == 0 { + let ref0 = *l.r#ref[0].index(yb4 as usize); + if ref0 < 4 { + cnt[ref0 as usize] += 1; } - if l.comp_type[yb4 as usize].is_some() && l.r#ref[1][yb4 as usize] < 4 { - cnt[l.r#ref[1][yb4 as usize] as usize] += 1; + let ref1 = *l.r#ref[1].index(yb4 as usize); + if l.comp_type.index(yb4 as usize).is_some() && ref1 < 4 { + cnt[ref1 as usize] += 1; } } @@ -424,21 +429,25 @@ pub fn av1_get_fwd_ref_1_ctx( ) -> u8 { let mut cnt = [0; 2]; - if have_top && a.intra[xb4 as usize] == 0 { - if a.r#ref[0][xb4 as usize] < 2 { - cnt[a.r#ref[0][xb4 as usize] as usize] += 1; + if have_top && *a.intra.index(xb4 as usize) == 0 { + let ref0 = *a.r#ref[0].index(xb4 as usize); + if ref0 < 2 { + cnt[ref0 as usize] += 1; } - if a.comp_type[xb4 as usize].is_some() && a.r#ref[1][xb4 as usize] < 2 { - cnt[a.r#ref[1][xb4 as usize] as usize] += 1; + let ref1 = *a.r#ref[1].index(xb4 as usize); + if a.comp_type.index(xb4 as usize).is_some() && ref1 < 2 { + cnt[ref1 as usize] += 1; } } - if have_left && l.intra[yb4 as usize] == 0 { - if l.r#ref[0][yb4 as usize] < 2 { - cnt[l.r#ref[0][yb4 as usize] as usize] += 1; + if have_left && *l.intra.index(yb4 as usize) == 0 { + let ref0 = *l.r#ref[0].index(yb4 as usize); + if ref0 < 2 { + cnt[ref0 as usize] += 1; } - if l.comp_type[yb4 as usize].is_some() && l.r#ref[1][yb4 as usize] < 2 { - cnt[l.r#ref[1][yb4 as usize] as usize] += 1; + let ref1 = *l.r#ref[1].index(yb4 as usize); + if l.comp_type.index(yb4 as usize).is_some() && ref1 < 2 { + cnt[ref1 as usize] += 1; } } @@ -456,21 +465,25 @@ pub fn av1_get_fwd_ref_2_ctx( ) -> u8 { let mut cnt = [0; 2]; - if have_top && a.intra[xb4 as usize] == 0 { - if (a.r#ref[0][xb4 as usize] ^ 2) < 2 { - cnt[(a.r#ref[0][xb4 as usize] - 2) as usize] += 1; + if have_top && *a.intra.index(xb4 as usize) == 0 { + let ref0 = *a.r#ref[0].index(xb4 as usize); + if (ref0 ^ 2) < 2 { + cnt[(ref0 - 2) as usize] += 1; } - if a.comp_type[xb4 as usize].is_some() && (a.r#ref[1][xb4 as usize] ^ 2) < 2 { - cnt[(a.r#ref[1][xb4 as usize] - 2) as usize] += 1; + let ref1 = *a.r#ref[1].index(xb4 as usize); + if a.comp_type.index(xb4 as usize).is_some() && (ref1 ^ 2) < 2 { + cnt[(ref1 - 2) as usize] += 1; } } - if have_left && l.intra[yb4 as usize] == 0 { - if (l.r#ref[0][yb4 as usize] ^ 2) < 2 { - cnt[(l.r#ref[0][yb4 as usize] - 2) as usize] += 1; + if have_left && *l.intra.index(yb4 as usize) == 0 { + let ref0 = *l.r#ref[0].index(yb4 as usize); + if (ref0 ^ 2) < 2 { + cnt[(ref0 - 2) as usize] += 1; } - if l.comp_type[yb4 as usize].is_some() && (l.r#ref[1][yb4 as usize] ^ 2) < 2 { - cnt[(l.r#ref[1][yb4 as usize] - 2) as usize] += 1; + let ref1 = *l.r#ref[1].index(yb4 as usize); + if l.comp_type.index(yb4 as usize).is_some() && (ref1 ^ 2) < 2 { + cnt[(ref1 - 2) as usize] += 1; } } @@ -488,21 +501,25 @@ pub fn av1_get_bwd_ref_ctx( ) -> u8 { let mut cnt = [0; 3]; - if have_top && a.intra[xb4 as usize] == 0 { - if a.r#ref[0][xb4 as usize] >= 4 { - cnt[(a.r#ref[0][xb4 as usize] - 4) as usize] += 1; + if have_top && *a.intra.index(xb4 as usize) == 0 { + let ref0 = *a.r#ref[0].index(xb4 as usize); + if ref0 >= 4 { + cnt[(ref0 - 4) as usize] += 1; } - if a.comp_type[xb4 as usize].is_some() && a.r#ref[1][xb4 as usize] >= 4 { - cnt[(a.r#ref[1][xb4 as usize] - 4) as usize] += 1; + let ref1 = *a.r#ref[1].index(xb4 as usize); + if a.comp_type.index(xb4 as usize).is_some() && ref1 >= 4 { + cnt[(ref1 - 4) as usize] += 1; } } - if have_left && l.intra[yb4 as usize] == 0 { - if l.r#ref[0][yb4 as usize] >= 4 { - cnt[(l.r#ref[0][yb4 as usize] - 4) as usize] += 1; + if have_left && *l.intra.index(yb4 as usize) == 0 { + let ref0 = *l.r#ref[0].index(yb4 as usize); + if ref0 >= 4 { + cnt[(ref0 - 4) as usize] += 1; } - if l.comp_type[yb4 as usize].is_some() && l.r#ref[1][yb4 as usize] >= 4 { - cnt[(l.r#ref[1][yb4 as usize] - 4) as usize] += 1; + let ref1 = *l.r#ref[1].index(yb4 as usize); + if l.comp_type.index(yb4 as usize).is_some() && ref1 >= 4 { + cnt[(ref1 - 4) as usize] += 1; } } @@ -522,21 +539,25 @@ pub fn av1_get_bwd_ref_1_ctx( ) -> u8 { let mut cnt = [0; 3]; - if have_top && a.intra[xb4 as usize] == 0 { - if a.r#ref[0][xb4 as usize] >= 4 { - cnt[(a.r#ref[0][xb4 as usize] - 4) as usize] += 1; + if have_top && *a.intra.index(xb4 as usize) == 0 { + let ref0 = *a.r#ref[0].index(xb4 as usize); + if ref0 >= 4 { + cnt[(ref0 - 4) as usize] += 1; } - if a.comp_type[xb4 as usize].is_some() && a.r#ref[1][xb4 as usize] >= 4 { - cnt[(a.r#ref[1][xb4 as usize] - 4) as usize] += 1; + let ref1 = *a.r#ref[1].index(xb4 as usize); + if a.comp_type.index(xb4 as usize).is_some() && ref1 >= 4 { + cnt[(ref1 - 4) as usize] += 1; } } - if have_left && l.intra[yb4 as usize] == 0 { - if l.r#ref[0][yb4 as usize] >= 4 { - cnt[(l.r#ref[0][yb4 as usize] - 4) as usize] += 1; + if have_left && *l.intra.index(yb4 as usize) == 0 { + let ref0 = *l.r#ref[0].index(yb4 as usize); + if ref0 >= 4 { + cnt[(ref0 - 4) as usize] += 1; } - if l.comp_type[yb4 as usize].is_some() && l.r#ref[1][yb4 as usize] >= 4 { - cnt[(l.r#ref[1][yb4 as usize] - 4) as usize] += 1; + let ref1 = *l.r#ref[1].index(yb4 as usize); + if l.comp_type.index(yb4 as usize).is_some() && ref1 >= 4 { + cnt[(ref1 - 4) as usize] += 1; } } @@ -554,23 +575,23 @@ pub fn av1_get_uni_p1_ctx( ) -> u8 { let mut cnt = [0; 3]; - if have_top && a.intra[xb4 as usize] == 0 { - if let Some(cnt) = cnt.get_mut((a.r#ref[0][xb4 as usize] - 1) as usize) { + if have_top && *a.intra.index(xb4 as usize) == 0 { + if let Some(cnt) = cnt.get_mut((*a.r#ref[0].index(xb4 as usize) - 1) as usize) { *cnt += 1; } - if a.comp_type[xb4 as usize].is_some() { - if let Some(cnt) = cnt.get_mut((a.r#ref[1][xb4 as usize] - 1) as usize) { + if a.comp_type.index(xb4 as usize).is_some() { + if let Some(cnt) = cnt.get_mut((*a.r#ref[1].index(xb4 as usize) - 1) as usize) { *cnt += 1; } } } - if have_left && l.intra[yb4 as usize] == 0 { - if let Some(cnt) = cnt.get_mut((l.r#ref[0][yb4 as usize] - 1) as usize) { + if have_left && *l.intra.index(yb4 as usize) == 0 { + if let Some(cnt) = cnt.get_mut((*l.r#ref[0].index(yb4 as usize) - 1) as usize) { *cnt += 1; } - if l.comp_type[yb4 as usize].is_some() { - if let Some(cnt) = cnt.get_mut((l.r#ref[1][yb4 as usize] - 1) as usize) { + if l.comp_type.index(yb4 as usize).is_some() { + if let Some(cnt) = cnt.get_mut((*l.r#ref[1].index(yb4 as usize) - 1) as usize) { *cnt += 1; } } diff --git a/src/internal.rs b/src/internal.rs index 4d01fec23..da70a1d60 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -1049,7 +1049,7 @@ pub(crate) struct Rav1dTaskContext { pub ts: usize, // Index into `f.ts` pub b: Bxy, pub l: BlockContext, - pub a: *mut BlockContext, + pub a: usize, // Offset into `f.a` pub rt: refmvs_tile, pub cf: BitDepthUnion, pub al_pal: BitDepthUnion, @@ -1074,8 +1074,8 @@ impl Rav1dTaskContext { Self { ts: 0, b: Default::default(), - l: mem::zeroed(), - a: ptr::null_mut(), + l: Default::default(), + a: 0, rt: mem::zeroed(), cf: Default::default(), al_pal: Default::default(), diff --git a/src/ipred_prepare.rs b/src/ipred_prepare.rs index 3bf581e50..66266b596 100644 --- a/src/ipred_prepare.rs +++ b/src/ipred_prepare.rs @@ -28,10 +28,10 @@ use std::ffi::c_int; #[inline] pub fn sm_flag(b: &BlockContext, idx: usize) -> c_int { - if b.intra[idx] == 0 { + if *b.intra.index(idx) == 0 { return 0; } - let m = b.mode[idx]; + let m = *b.mode.index(idx); if m == SMOOTH_PRED || m == SMOOTH_H_PRED || m == SMOOTH_V_PRED { 512 } else { @@ -41,7 +41,7 @@ pub fn sm_flag(b: &BlockContext, idx: usize) -> c_int { #[inline] pub fn sm_uv_flag(b: &BlockContext, idx: usize) -> c_int { - let m = b.uvmode[idx]; + let m = *b.uvmode.index(idx); if m == SMOOTH_PRED || m == SMOOTH_H_PRED || m == SMOOTH_V_PRED { 512 } else { diff --git a/src/lf_apply.rs b/src/lf_apply.rs index 9bffb7212..6f9d62c20 100644 --- a/src/lf_apply.rs +++ b/src/lf_apply.rs @@ -672,7 +672,7 @@ pub(crate) unsafe fn rav1d_loopfilter_sbrow_cols( y_vmask[2][sidx].fetch_and(!smask, Ordering::Relaxed); y_vmask[1][sidx].fetch_and(!smask, Ordering::Relaxed); y_vmask[0][sidx].fetch_and(!smask, Ordering::Relaxed); - y_vmask[cmp::min(idx, a[0].tx_lpf_y[i as usize] as usize)][sidx] + y_vmask[cmp::min(idx, *a[0].tx_lpf_y.index(i as usize) as usize)][sidx] .fetch_or(smask, Ordering::Relaxed); } if f.cur.p.layout != Rav1dPixelLayout::I400 { @@ -686,7 +686,7 @@ pub(crate) unsafe fn rav1d_loopfilter_sbrow_cols( let idx = (uv_vmask[1][sidx].load(Ordering::Relaxed) & smask != 0) as usize; uv_vmask[1][sidx].fetch_and(!smask, Ordering::Relaxed); uv_vmask[0][sidx].fetch_and(!smask, Ordering::Relaxed); - uv_vmask[cmp::min(idx, a[0].tx_lpf_uv[i as usize] as usize)][sidx] + uv_vmask[cmp::min(idx, *a[0].tx_lpf_uv.index(i as usize) as usize)][sidx] .fetch_or(smask, Ordering::Relaxed); } } diff --git a/src/recon.rs b/src/recon.rs index f7af96813..cac0cf67d 100644 --- a/src/recon.rs +++ b/src/recon.rs @@ -25,6 +25,7 @@ use crate::src::internal::Rav1dContext; use crate::src::internal::Rav1dDSPContext; use crate::src::internal::Rav1dFrameData; use crate::src::internal::Rav1dTaskContext; +use crate::src::internal::Rav1dTaskContext_scratch; use crate::src::internal::TileStateRef; use crate::src::intra_edge::EdgeFlags; use crate::src::ipred_prepare::rav1d_prepare_intra_edges; @@ -479,7 +480,10 @@ fn get_lo_ctx( unsafe fn decode_coefs( f: &Rav1dFrameData, - t: *mut Rav1dTaskContext, + ts: usize, + dbg_block_info: bool, + scratch: &mut Rav1dTaskContext_scratch, + t_cf: &mut BitDepthUnion, a: &mut [u8], l: &mut [u8], tx: RectTxfmSize, @@ -495,12 +499,12 @@ unsafe fn decode_coefs( let dc_sign; let mut dc_dq; let current_block: u64; - let ts = &mut *f.ts.offset((*t).ts as isize); + let ts = &mut *f.ts.offset(ts as isize); let chroma = (plane != 0) as c_int; let frame_hdr = &***f.frame_hdr.as_ref().unwrap(); let lossless = frame_hdr.segmentation.lossless[b.seg_id as usize]; let t_dim = &dav1d_txfm_dimensions[tx as usize]; - let dbg = debug_block_info!(f, (*t).b) && plane != 0 && false; + let dbg = dbg_block_info && plane != 0 && false; if dbg { println!("Start: r={}", ts.msac.rng); } @@ -699,7 +703,7 @@ unsafe fn decode_coefs( if eob != 0 { let lo_cdf: *mut [u16; 4] = (ts.cdf.coef.base_tok[(*t_dim).ctx as usize][chroma as usize]).as_mut_ptr(); - let levels = &mut (*t).scratch.c2rust_unnamed_0.c2rust_unnamed.levels; + let levels = &mut scratch.c2rust_unnamed_0.c2rust_unnamed.levels; let sw = cmp::min((*t_dim).w as c_int, 8 as c_int); let sh = cmp::min((*t_dim).h as c_int, 8 as c_int); let mut ctx: c_uint = @@ -789,7 +793,7 @@ unsafe fn decode_coefs( ); } } - cf.set::(f, &mut (*t).cf, rc as usize, (tok << 11).as_::()); + cf.set::(f, t_cf, rc as usize, (tok << 11).as_::()); levels[(x as isize * stride + y as isize) as usize] = level_tok as u8; let mut i = eob - 1; while i > 0 { @@ -873,7 +877,7 @@ unsafe fn decode_coefs( level[0] = (tok + ((3 as c_int) << 6)) as u8; cf.set::( f, - &mut (*t).cf, + t_cf, rc_i as usize, ((tok << 11) as c_uint | rc).as_::(), ); @@ -885,7 +889,7 @@ unsafe fn decode_coefs( if tok != 0 { rc = rc_i; } - cf.set::(f, &mut (*t).cf, rc_i as usize, tok.as_::()); + cf.set::(f, t_cf, rc_i as usize, tok.as_::()); } i -= 1; } @@ -1008,7 +1012,7 @@ unsafe fn decode_coefs( ); } } - cf.set::(f, &mut (*t).cf, rc as usize, (tok << 11).as_::()); + cf.set::(f, t_cf, rc as usize, (tok << 11).as_::()); levels[(x as isize * stride + y as isize) as usize] = level_tok as u8; let mut i = eob - 1; while i > 0 { @@ -1092,7 +1096,7 @@ unsafe fn decode_coefs( level[0] = (tok + ((3 as c_int) << 6)) as u8; cf.set::( f, - &mut (*t).cf, + t_cf, rc_i as usize, ((tok << 11) as c_uint | rc).as_::(), ); @@ -1104,7 +1108,7 @@ unsafe fn decode_coefs( if tok != 0 { rc = rc_i; } - cf.set::(f, &mut (*t).cf, rc_i as usize, tok.as_::()); + cf.set::(f, t_cf, rc_i as usize, tok.as_::()); } i -= 1; } @@ -1227,7 +1231,7 @@ unsafe fn decode_coefs( ); } } - cf.set::(f, &mut (*t).cf, rc as usize, (tok << 11).as_::()); + cf.set::(f, t_cf, rc as usize, (tok << 11).as_::()); levels[(x as isize * stride + y as isize) as usize] = level_tok as u8; let mut i = eob - 1; while i > 0 { @@ -1311,7 +1315,7 @@ unsafe fn decode_coefs( level[0] = (tok + ((3 as c_int) << 6)) as u8; cf.set::( f, - &mut (*t).cf, + t_cf, rc_i as usize, ((tok << 11) as c_uint | rc).as_::(), ); @@ -1323,7 +1327,7 @@ unsafe fn decode_coefs( if tok != 0 { rc = rc_i; } - cf.set::(f, &mut (*t).cf, rc_i as usize, tok.as_::()); + cf.set::(f, t_cf, rc_i as usize, tok.as_::()); } i -= 1; } @@ -1475,7 +1479,7 @@ unsafe fn decode_coefs( dc_dq = cmp::min(dc_dq as c_uint, (cf_max + dc_sign) as c_uint) as c_int; cf.set::( f, - &mut (*t).cf, + t_cf, 0, (if dc_sign != 0 { -dc_dq } else { dc_dq }).as_::(), ); @@ -1506,7 +1510,7 @@ unsafe fn decode_coefs( cul_level = dc_tok; cf.set::( f, - &mut (*t).cf, + t_cf, 0, (if dc_sign != 0 { -dc_dq } else { dc_dq }).as_::(), ); @@ -1525,7 +1529,7 @@ unsafe fn decode_coefs( if dbg { println!("Post-sign[{}={}]: r={}", rc, sign, ts.msac.rng); } - let rc_tok: c_uint = cf.get::(f, &*t, rc as usize).as_::(); + let rc_tok: c_uint = cf.get::(f, t_cf, rc as usize).as_::(); let mut tok: c_uint; let mut dq: c_uint = ac_dq // TODO: Remove `unwrap` once state machine control flow is cleaned up. @@ -1556,7 +1560,7 @@ unsafe fn decode_coefs( dq_sat = cmp::min(dq, (cf_max + sign) as c_uint) as c_int; cf.set::( f, - &mut (*t).cf, + t_cf, rc as usize, (if sign != 0 { -dq_sat } else { dq_sat }).as_::(), ); @@ -1573,7 +1577,7 @@ unsafe fn decode_coefs( if dbg { println!("Post-sign[{}={}]: r={}", rc, sign, ts.msac.rng); } - let rc_tok: c_uint = cf.get::(f, &*t, rc as usize).as_::(); + let rc_tok: c_uint = cf.get::(f, t_cf, rc as usize).as_::(); let mut tok: c_uint; let mut dq; if rc_tok >= ((15 as c_int) << 11) as c_uint { @@ -1599,7 +1603,7 @@ unsafe fn decode_coefs( cul_level = cul_level.wrapping_add(tok); cf.set::( f, - &mut (*t).cf, + t_cf, rc as usize, (if sign != 0 { -dq } else { dq }).as_::(), ); @@ -1644,10 +1648,15 @@ impl CfSelect { }; } - fn get(self, f: &Rav1dFrameData, t: &Rav1dTaskContext, index: usize) -> BD::Coef { + fn get( + self, + f: &Rav1dFrameData, + t_cf: &BitDepthUnion, + index: usize, + ) -> BD::Coef { match self { CfSelect::Frame(offset) => *f.frame_thread.cf.element_as(offset + index), - CfSelect::Task => unsafe { BD::select(&t.cf).0[index] }, + CfSelect::Task => unsafe { BD::select(&t_cf).0[index] }, } } } @@ -1769,9 +1778,14 @@ unsafe fn read_coef_tree( if (*t).frame_thread.pass != 2 as c_int { eob = decode_coefs::( f, - t, - &mut (*(*t).a).lcoef.0[bx4 as usize..], - &mut (*t).l.lcoef.0[by4 as usize..], + (*t).ts, + debug_block_info!(f, (*t).b), + &mut (*t).scratch, + &mut (*t).cf, + &mut f.a[(*t).a] + .lcoef + .index_mut(bx4 as usize..(bx4 + txw) as usize), + &mut (*t).l.lcoef.index_mut(by4 as usize..(by4 + txh) as usize), ytx, bs, b, @@ -1788,14 +1802,14 @@ unsafe fn read_coef_tree( ); } CaseSet::<16, true>::many( - [&mut (*t).l, &mut *(*t).a], + [&(*t).l.lcoef, &f.a[(*t).a].lcoef], [ cmp::min(txh, f.bh - (*t).b.y) as usize, cmp::min(txw, f.bw - (*t).b.x) as usize, ], [by4 as usize, bx4 as usize], |case, dir| { - case.set(&mut dir.lcoef.0, cf_ctx); + case.set_disjoint(dir, cf_ctx); }, ); let txtp_map = &mut (*t).scratch.c2rust_unnamed_0.ac_txtp_map.txtp_map @@ -1884,21 +1898,22 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( && (bh4 > ss_ver || t.b.y & 1 != 0)) as c_int; if b.skip != 0 { CaseSet::<32, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [bh4 as usize, bw4 as usize], [by4 as usize, bx4 as usize], |case, dir| { - case.set(&mut dir.lcoef.0, 0x40); + case.set_disjoint(&dir.lcoef, 0x40); }, ); if has_chroma != 0 { CaseSet::<32, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [cbh4 as usize, cbw4 as usize], [cby4 as usize, cbx4 as usize], |case, dir| { - case.set(&mut dir.ccoef.0[0], 0x40); - case.set(&mut dir.ccoef.0[1], 0x40); + for ccoef in &dir.ccoef { + case.set_disjoint(ccoef, 0x40) + } }, ); } @@ -1957,11 +1972,18 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( } else { let mut cf_ctx: u8 = 0x40 as c_int as u8; let mut txtp: TxfmType = DCT_DCT; + let a_start = (bx4 + x) as usize; + let a_len = (*t_dim).w as usize; + let l_start = (by4 + y) as usize; + let l_len = (*t_dim).h as usize; let eob = decode_coefs::( f, - t, - &mut (*t.a).lcoef.0[(bx4 + x) as usize..], - &mut t.l.lcoef.0[(by4 + y) as usize..], + t.ts, + debug_block_info!(f, t.b), + &mut t.scratch, + &mut t.cf, + &mut f.a[t.a].lcoef.index_mut(a_start..a_start + a_len), + &mut t.l.lcoef.index_mut(l_start..l_start + l_len), b.c2rust_unnamed.c2rust_unnamed.tx as RectTxfmSize, bs, b, @@ -1988,14 +2010,14 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( * cmp::min((*t_dim).h, 8) as usize * 16; CaseSet::<16, true>::many( - [&mut t.l, &mut *t.a], + [&t.l.lcoef, &f.a[t.a].lcoef], [ cmp::min((*t_dim).h as i32, f.bh - t.b.y) as usize, cmp::min((*t_dim).w as i32, f.bw - t.b.x) as usize, ], [(by4 + y) as usize, (bx4 + x) as usize], |case, dir| { - case.set(&mut dir.lcoef.0, cf_ctx); + case.set_disjoint(dir, cf_ctx); }, ); } @@ -2028,16 +2050,25 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( [((by4 + (y << ss_ver)) * 32 + bx4 + (x << ss_hor)) as usize] as TxfmType; } + let a_start = (cbx4 + x) as usize; + let a_len = (*uv_t_dim).w as usize; + let a_ccoef = &f.a[t.a].ccoef[pl]; + let l_start = (cby4 + y) as usize; + let l_len = (*uv_t_dim).h as usize; + let l_ccoef = &t.l.ccoef[pl]; let eob = decode_coefs::( f, - t, - &mut (*t.a).ccoef.0[pl as usize][(cbx4 + x) as usize..], - &mut t.l.ccoef.0[pl as usize][(cby4 + y) as usize..], + t.ts, + debug_block_info!(f, t.b), + &mut t.scratch, + &mut t.cf, + &mut a_ccoef.index_mut(a_start..a_start + a_len), + &mut l_ccoef.index_mut(l_start..l_start + l_len), b.uvtx as RectTxfmSize, bs, b, b.intra as c_int, - 1 + pl, + 1 + pl as c_int, CfSelect::Frame(ts.frame_thread[1].cf), &mut txtp, &mut cf_ctx, @@ -2055,7 +2086,7 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( ts.frame_thread[1].cf += (*uv_t_dim).w as usize * (*uv_t_dim).h as usize * 16; CaseSet::<16, true>::many( - [&mut t.l, &mut *t.a], + [l_ccoef, a_ccoef], [ cmp::min((*uv_t_dim).h as i32, f.bh - t.b.y + ss_ver >> ss_ver) as usize, @@ -2064,7 +2095,7 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( ], [(cby4 + y) as usize, (cbx4 + x) as usize], |case, dir| { - case.set(&mut dir.ccoef.0[pl as usize], cf_ctx); + case.set_disjoint(dir, cf_ctx); }, ); x += (*uv_t_dim).w as c_int; @@ -2311,8 +2342,8 @@ unsafe fn obmc( a_r.mv.mv[0], &f.refp[a_r.r#ref.r#ref[0] as usize - 1], a_r.r#ref.r#ref[0] as usize - 1, - dav1d_filter_2d[(*t.a).filter[1][(bx4 + x + 1) as usize] as usize] - [(*t.a).filter[0][(bx4 + x + 1) as usize] as usize], + dav1d_filter_2d[*f.a[t.a].filter[1].index((bx4 + x + 1) as usize) as usize] + [*f.a[t.a].filter[0].index((bx4 + x + 1) as usize) as usize], )?; (f.dsp.mc.blend_h)( dst.offset((x * h_mul) as isize).cast(), @@ -2351,8 +2382,8 @@ unsafe fn obmc( l_r.mv.mv[0], &f.refp[l_r.r#ref.r#ref[0] as usize - 1], l_r.r#ref.r#ref[0] as usize - 1, - dav1d_filter_2d[t.l.filter[1][(by4 + y + 1) as usize] as usize] - [t.l.filter[0][(by4 + y + 1) as usize] as usize], + dav1d_filter_2d[*t.l.filter[1].index((by4 + y + 1) as usize) as usize] + [*t.l.filter[0].index((by4 + y + 1) as usize) as usize], )?; (f.dsp.mc.blend_v)( dst.offset((y * v_mul) as isize * BD::pxstride(dst_stride)) @@ -2552,7 +2583,7 @@ pub(crate) unsafe fn rav1d_recon_b_intra( ); } } - let intra_flags = sm_flag(&*t.a, bx4 as usize) + let intra_flags = sm_flag(&f.a[t.a], bx4 as usize) | sm_flag(&mut t.l, by4 as usize) | intra_edge_filter_flag; let sb_has_tr = if (init_x + 16) < w4 { @@ -2698,11 +2729,18 @@ pub(crate) unsafe fn rav1d_recon_b_intra( txtp = cbi.txtp(); } else { let mut cf_ctx: u8 = 0; + let a_start = (bx4 + x) as usize; + let l_start = (by4 + y) as usize; eob = decode_coefs::( f, - t, - &mut (*t.a).lcoef.0[(bx4 + x) as usize..], - &mut t.l.lcoef.0[(by4 + y) as usize..], + t.ts, + debug_block_info!(f, t.b), + &mut t.scratch, + &mut t.cf, + &mut f.a[t.a] + .lcoef + .index_mut(a_start..a_start + (*t_dim).w as usize), + &mut t.l.lcoef.index_mut(l_start..l_start + (*t_dim).h as usize), b.c2rust_unnamed.c2rust_unnamed.tx as RectTxfmSize, bs, b, @@ -2723,14 +2761,14 @@ pub(crate) unsafe fn rav1d_recon_b_intra( ); } CaseSet::<16, true>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [ cmp::min((*t_dim).h as i32, f.bh - t.b.y) as usize, cmp::min((*t_dim).w as i32, f.bw - t.b.x) as usize, ], [(by4 + y) as usize, (bx4 + x) as usize], |case, dir| { - case.set(&mut dir.lcoef.0, cf_ctx); + case.set_disjoint(&dir.lcoef, cf_ctx); }, ); } @@ -2765,11 +2803,11 @@ pub(crate) unsafe fn rav1d_recon_b_intra( } } else if t.frame_thread.pass == 0 { CaseSet::<16, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [(*t_dim).h as usize, (*t_dim).w as usize], [(by4 + y) as usize, (bx4 + x) as usize], |case, dir| { - case.set(&mut dir.lcoef.0, 0x40); + case.set_disjoint(&dir.lcoef, 0x40); }, ); } @@ -2958,7 +2996,7 @@ pub(crate) unsafe fn rav1d_recon_b_intra( } } let sm_uv_fl = - sm_uv_flag(&*t.a, cbx4 as usize) | sm_uv_flag(&mut t.l, cby4 as usize); + sm_uv_flag(&f.a[t.a], cbx4 as usize) | sm_uv_flag(&mut t.l, cby4 as usize); let uv_sb_has_tr = if init_x + 16 >> ss_hor < cw4 { true } else if init_y != 0 { @@ -3139,16 +3177,25 @@ pub(crate) unsafe fn rav1d_recon_b_intra( txtp = cbi.txtp(); } else { let mut cf_ctx: u8 = 0; + let a_start = (cbx4 + x) as usize; + let a_ccoef = &f.a[t.a].ccoef[pl]; + let l_start = (cby4 + y) as usize; + let l_ccoef = &t.l.ccoef[pl]; eob = decode_coefs::( f, - t, - &mut (*t.a).ccoef.0[pl as usize][(cbx4 + x) as usize..], - &mut t.l.ccoef.0[pl as usize][(cby4 + y) as usize..], + t.ts, + debug_block_info!(f, t.b), + &mut t.scratch, + &mut t.cf, + &mut a_ccoef + .index_mut(a_start..a_start + (*uv_t_dim).w as usize), + &mut l_ccoef + .index_mut(l_start..l_start + (*uv_t_dim).h as usize), b.uvtx as RectTxfmSize, bs, b, 1 as c_int, - 1 + pl, + 1 + pl as c_int, CfSelect::Task, &mut txtp, &mut cf_ctx, @@ -3167,7 +3214,7 @@ pub(crate) unsafe fn rav1d_recon_b_intra( ); } CaseSet::<16, true>::many( - [&mut t.l, &mut *t.a], + [l_ccoef, a_ccoef], [ cmp::min( (*uv_t_dim).h as i32, @@ -3180,7 +3227,7 @@ pub(crate) unsafe fn rav1d_recon_b_intra( ], [(cby4 + y) as usize, (cbx4 + x) as usize], |case, dir| { - case.set(&mut dir.ccoef.0[pl as usize], cf_ctx); + case.set_disjoint(dir, cf_ctx); }, ); } @@ -3214,11 +3261,11 @@ pub(crate) unsafe fn rav1d_recon_b_intra( } } else if t.frame_thread.pass == 0 { CaseSet::<16, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [(*uv_t_dim).h as usize, (*uv_t_dim).w as usize], [(cby4 + y) as usize, (cbx4 + x) as usize], |case, dir| { - case.set(&mut dir.ccoef.0[pl as usize], 0x40); + case.set_disjoint(&dir.ccoef[pl as usize], 0x40); }, ); } @@ -3694,8 +3741,9 @@ pub(crate) unsafe fn rav1d_recon_b_inter( h_off = 2; } if bw4 == 1 { - let left_filter_2d = dav1d_filter_2d[t.l.filter[1][by4 as usize] as usize] - [t.l.filter[0][by4 as usize] as usize]; + let left_filter_2d = dav1d_filter_2d + [*t.l.filter[1].index(by4 as usize) as usize] + [*t.l.filter[0].index(by4 as usize) as usize]; for pl in 0..2 { let r = *f.rf.r.index(r[1] + t.b.x as usize - 1); mc::( @@ -3731,8 +3779,9 @@ pub(crate) unsafe fn rav1d_recon_b_inter( h_off = 2; } if bh4 == ss_ver { - let top_filter_2d = dav1d_filter_2d[(*t.a).filter[1][bx4 as usize] as usize] - [(*t.a).filter[0][bx4 as usize] as usize]; + let top_filter_2d = dav1d_filter_2d + [*f.a[t.a].filter[1].index(bx4 as usize) as usize] + [*f.a[t.a].filter[0].index(bx4 as usize) as usize]; for pl in 0..2 { let r = *f.rf.r.index(r[0] + t.b.x as usize); mc::( @@ -3971,21 +4020,22 @@ pub(crate) unsafe fn rav1d_recon_b_inter( let ch4 = h4 + ss_ver >> ss_ver; if b.skip != 0 { CaseSet::<32, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [bh4 as usize, bw4 as usize], [by4 as usize, bx4 as usize], |case, dir| { - case.set(&mut dir.lcoef.0, 0x40); + case.set_disjoint(&dir.lcoef, 0x40); }, ); if has_chroma { CaseSet::<32, false>::many( - [&mut t.l, &mut *t.a], + [&t.l, &f.a[t.a]], [cbh4 as usize, cbw4 as usize], [cby4 as usize, cbx4 as usize], |case, dir| { - case.set(&mut dir.ccoef.0[0], 0x40); - case.set(&mut dir.ccoef.0[1], 0x40); + for ccoef in &dir.ccoef { + case.set_disjoint(ccoef, 0x40); + } }, ); } @@ -4066,16 +4116,23 @@ pub(crate) unsafe fn rav1d_recon_b_inter( let mut cf_ctx = 0; txtp = t.scratch.c2rust_unnamed_0.ac_txtp_map.txtp_map [((by4 + (y << ss_ver)) * 32 + bx4 + (x << ss_hor)) as usize]; + let a_ccoef = &f.a[t.a].ccoef[pl]; + let a_start = (cbx4 + x) as usize; + let l_ccoef = &t.l.ccoef[pl]; + let l_start = (cby4 + y) as usize; eob = decode_coefs::( f, - t, - &mut (*t.a).ccoef.0[pl as usize][(cbx4 + x) as usize..], - &mut t.l.ccoef.0[pl as usize][(cby4 + y) as usize..], + t.ts, + debug_block_info!(f, t.b), + &mut t.scratch, + &mut t.cf, + &mut a_ccoef.index_mut(a_start..a_start + uvtx.w as usize), + &mut l_ccoef.index_mut(l_start..l_start + uvtx.h as usize), b.uvtx, bs, b, 0, - 1 + pl, + 1 + pl as c_int, CfSelect::Task, &mut txtp, &mut cf_ctx, @@ -4088,7 +4145,7 @@ pub(crate) unsafe fn rav1d_recon_b_inter( ); } CaseSet::<16, true>::many( - [&mut t.l, &mut *t.a], + [l_ccoef, a_ccoef], [ cmp::min(uvtx.h as i32, f.bh - t.b.y + ss_ver >> ss_ver) as usize, @@ -4097,7 +4154,7 @@ pub(crate) unsafe fn rav1d_recon_b_inter( ], [(cby4 + y) as usize, (cbx4 + x) as usize], |case, dir| { - case.set(&mut dir.ccoef.0[pl as usize], cf_ctx); + case.set_disjoint(dir, cf_ctx); }, ); } @@ -4572,7 +4629,7 @@ pub(crate) unsafe fn rav1d_read_pal_plane( let mut l_cache = if pl { t.pal_sz_uv[1][by4] } else { - t.l.pal_sz.0[by4] + *t.l.pal_sz.index(by4) }; let mut n_cache = 0; // don't reuse above palette outside SB64 boundaries @@ -4580,7 +4637,7 @@ pub(crate) unsafe fn rav1d_read_pal_plane( if pl { t.pal_sz_uv[0][bx4] } else { - (*t.a).pal_sz.0[bx4] + *f.a[t.a].pal_sz.index(bx4) } } else { 0