Skip to content

Commit

Permalink
Rav1dTileState::lowest_pixel: Make into offset
Browse files Browse the repository at this point in the history
  • Loading branch information
randomPoison committed Mar 21, 2024
1 parent d393291 commit 77fc97d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
62 changes: 43 additions & 19 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,29 +1312,30 @@ fn affine_lowest_px_luma(
#[inline(never)]
unsafe fn affine_lowest_px_chroma(
t: &Rav1dTaskContext,
f: &Rav1dFrameData,
layout: Rav1dPixelLayout,
dst: &mut c_int,
b_dim: &[u8; 4],
wmp: &Rav1dWarpedMotionParams,
) {
assert!(f.cur.p.layout != Rav1dPixelLayout::I400);
if f.cur.p.layout == Rav1dPixelLayout::I444 {
assert!(layout != Rav1dPixelLayout::I400);
if layout == Rav1dPixelLayout::I444 {
affine_lowest_px_luma(t, dst, b_dim, wmp);
} else {
affine_lowest_px(
t,
dst,
b_dim,
wmp,
(f.cur.p.layout & Rav1dPixelLayout::I420) as c_int,
(layout & Rav1dPixelLayout::I420) as c_int,
1,
);
};
}

unsafe fn obmc_lowest_px(
t: &mut Rav1dTaskContext,
f: &Rav1dFrameData,
layout: Rav1dPixelLayout,
svc: &[[ScalableMotionParams; 2]; 7],
dst: &mut [[c_int; 2]; 7],
is_chroma: bool,
b_dim: &[u8; 4],
Expand All @@ -1345,8 +1346,8 @@ unsafe fn obmc_lowest_px(
) {
assert!(t.bx & 1 == 0 && t.by & 1 == 0);
let r = &t.rt.r[(t.by as usize & 31) + 5 - 1..];
let ss_ver = (is_chroma && f.cur.p.layout == Rav1dPixelLayout::I420) as c_int;
let ss_hor = (is_chroma && f.cur.p.layout != Rav1dPixelLayout::I444) as c_int;
let ss_ver = (is_chroma && layout == Rav1dPixelLayout::I420) as c_int;
let ss_hor = (is_chroma && layout != Rav1dPixelLayout::I444) as c_int;
let h_mul = 4 >> ss_hor;
let v_mul = 4 >> ss_ver;
if t.by > (*t.ts).tiling.row_start
Expand All @@ -1365,7 +1366,7 @@ unsafe fn obmc_lowest_px(
oh4 * 3 + 3 >> 2,
a_r.0.mv.mv[0].y,
ss_ver,
&f.svc[a_r.0.r#ref.r#ref[0] as usize - 1][1],
&svc[a_r.0.r#ref.r#ref[0] as usize - 1][1],
);
i += 1;
}
Expand All @@ -1386,7 +1387,7 @@ unsafe fn obmc_lowest_px(
oh4,
l_r.0.mv.mv[0].y,
ss_ver,
&f.svc[l_r.0.r#ref.r#ref[0] as usize - 1][1],
&svc[l_r.0.r#ref.r#ref[0] as usize - 1][1],
);
i += 1;
}
Expand Down Expand Up @@ -3227,7 +3228,7 @@ unsafe fn decode_b_inner(
}

// update contexts
let frame_hdr = f.frame_hdr();
let frame_hdr = &***f.frame_hdr.as_ref().unwrap();
if frame_hdr.segmentation.enabled != 0 && frame_hdr.segmentation.update_map != 0 {
// Need checked casts here because we're using `from_raw_parts_mut` and an overflow would be UB.
let [by, bx, bh4, bw4] = [t.by, t.bx, bh4, bw4].map(|it| usize::try_from(it).unwrap());
Expand Down Expand Up @@ -3263,7 +3264,7 @@ unsafe fn decode_b_inner(

if t.frame_thread.pass == 1 && b.intra == 0 && frame_hdr.frame_type.is_inter_or_switch() {
let sby = t.by - ts.tiling.row_start >> f.sb_shift;
let lowest_px = &mut *ts.lowest_pixel.offset(sby as isize);
let lowest_px = &mut f.lowest_pixel_mem[ts.lowest_pixel + sby as usize];
// keep track of motion vectors for each reference
if b.comp_type() == COMP_INTER_NONE {
// y
Expand Down Expand Up @@ -3292,7 +3293,18 @@ unsafe fn decode_b_inner(
&f.svc[b.r#ref()[0] as usize][1],
);
if b.motion_mode() == MM_OBMC as u8 {
obmc_lowest_px(t, f, lowest_px, false, b_dim, bx4, by4, w4, h4);
obmc_lowest_px(
t,
f.cur.p.layout,
&f.svc,
lowest_px,
false,
b_dim,
bx4,
by4,
w4,
h4,
);
}
}

Expand Down Expand Up @@ -3372,7 +3384,7 @@ unsafe fn decode_b_inner(
{
affine_lowest_px_chroma(
t,
f,
f.cur.p.layout,
&mut lowest_px[b.r#ref()[0] as usize][1],
b_dim,
if b.motion_mode() == MM_WARP as u8 {
Expand All @@ -3391,7 +3403,18 @@ unsafe fn decode_b_inner(
&f.svc[b.r#ref()[0] as usize][1],
);
if b.motion_mode() == MM_OBMC as u8 {
obmc_lowest_px(t, f, lowest_px, true, b_dim, bx4, by4, w4, h4);
obmc_lowest_px(
t,
f.cur.p.layout,
&f.svc,
lowest_px,
true,
b_dim,
bx4,
by4,
w4,
h4,
);
}
}
}
Expand Down Expand Up @@ -3447,7 +3470,7 @@ unsafe fn decode_b_inner(
{
affine_lowest_px_chroma(
t,
f,
f.cur.p.layout,
&mut lowest_px[r#ref][1],
b_dim,
&frame_hdr.gmv[r#ref],
Expand Down Expand Up @@ -4087,7 +4110,7 @@ pub(crate) unsafe fn rav1d_decode_tile_sbrow(

if frame_hdr.frame_type.is_inter_or_switch() && c.n_fc > 1 {
let sby = t.by - ts.tiling.row_start >> f.sb_shift;
*ts.lowest_pixel.offset(sby as isize) = [[i32::MIN; 2]; 7];
f.lowest_pixel_mem[ts.lowest_pixel + sby as usize] = [[i32::MIN; 2]; 7];
}

reset_context(
Expand Down Expand Up @@ -4328,14 +4351,15 @@ pub(crate) unsafe fn rav1d_decode_frame_init(
f.lowest_pixel_mem
.resize(lowest_pixel_mem_sz as usize, Default::default());

let mut lowest_pixel_ptr = f.lowest_pixel_mem.as_mut_ptr();
let mut lowest_pixel_offset = 0;
for tile_row in 0..frame_hdr.tiling.rows {
let tile_row_base = tile_row * frame_hdr.tiling.cols;
let tile_row_sb_h = frame_hdr.tiling.row_start_sb[(tile_row + 1) as usize] as c_int
- frame_hdr.tiling.row_start_sb[tile_row as usize] as c_int;
for tile_col in 0..frame_hdr.tiling.cols {
(*f.ts.offset((tile_row_base + tile_col) as isize)).lowest_pixel = lowest_pixel_ptr;
lowest_pixel_ptr = lowest_pixel_ptr.offset(tile_row_sb_h as isize);
(*f.ts.offset((tile_row_base + tile_col) as isize)).lowest_pixel =
lowest_pixel_offset;
lowest_pixel_offset += tile_row_sb_h as usize;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ pub struct Rav1dTileState {

// in fullpel units, [0] = Y, [1] = UV, used for progress requirements
// each entry is one tile-sbrow; middle index is refidx
pub lowest_pixel: *mut [[c_int; 2]; 7],
pub lowest_pixel: usize,

pub dqmem: [[[u16; 2]; 3]; RAV1D_MAX_SEGMENTS as usize], /* [RAV1D_MAX_SEGMENTS][3 plane][2 dc/ac] */
pub dq: *const [[u16; 2]; 3],
Expand Down
11 changes: 5 additions & 6 deletions src/thread_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,7 @@ unsafe fn check_tile(t: *mut Rav1dTask, f: &mut Rav1dFrameData, frame_mt: c_int)
((*p).p.p.layout as c_uint == Rav1dPixelLayout::I420 as c_int as c_uint) as c_int;
let p_b: c_uint = (((*t).sby + 1) << f.sb_shift + 2) as c_uint;
let tile_sby = (*t).sby - ((*ts).tiling.row_start >> f.sb_shift);
let lowest_px: *const [c_int; 2] =
(*((*ts).lowest_pixel).offset(tile_sby as isize)).as_mut_ptr() as *const [c_int; 2];
let lowest_px = &f.lowest_pixel_mem[(*ts).lowest_pixel + tile_sby as usize];
let mut current_block_14: u64;
let mut n = (*t).deps_skip;
while n < 7 {
Expand All @@ -568,15 +567,15 @@ unsafe fn check_tile(t: *mut Rav1dTask, f: &mut Rav1dFrameData, frame_mt: c_int)
lowest = p_b;
current_block_14 = 2370887241019905314;
} else {
let y = if (*lowest_px.offset(n as isize))[0] == i32::MIN {
let y = if lowest_px[n as usize][0] == i32::MIN {
i32::MIN
} else {
(*lowest_px.offset(n as isize))[0] + 8
lowest_px[n as usize][0] + 8
};
let uv = if (*lowest_px.offset(n as isize))[1] == i32::MIN {
let uv = if lowest_px[n as usize][1] == i32::MIN {
i32::MIN
} else {
(*lowest_px.offset(n as isize))[1] * ((1 as c_int) << ss_ver) + 8
lowest_px[n as usize][1] * ((1 as c_int) << ss_ver) + 8
};
let max = cmp::max(y, uv);
if max == i32::MIN {
Expand Down

0 comments on commit 77fc97d

Please sign in to comment.