Skip to content

Commit

Permalink
Cleanup pass
Browse files Browse the repository at this point in the history
  • Loading branch information
randomPoison committed Apr 23, 2024
1 parent d9c666c commit 012114f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 38 deletions.
52 changes: 17 additions & 35 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ pub struct ScratchCompinter {
pub seg_mask: [u8; 16384],
}

// Larger of the two between `ScratchCompinter` and `[BD::Pixel; 128 * 32]`.
const SCRATCH_COMPINTER_SIZE: usize = mem::size_of::<ScratchCompinter>();

#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
Expand All @@ -954,15 +955,14 @@ impl ScratchLapInter {
}
}

const EMU_EDGE_SIZE: usize = 320 * (256 + 7);
const EMU_EDGE_LEN: usize = 320 * (256 + 7);
// stride=192 for non-SVC, or 320 for SVC
// Contains `320 * (256 + 7)` elements of either `u8` or `u16` depending on bitdepth.
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
#[repr(C, align(32))]
pub struct EmuEdge([u8; EMU_EDGE_SIZE * 2]);
pub struct ScratchEmuEdge([u8; EMU_EDGE_LEN * 2]);

impl EmuEdge {
pub fn buf_mut<BD: BitDepth>(&mut self) -> &mut [BD::Pixel; EMU_EDGE_SIZE] {
impl ScratchEmuEdge {
pub fn buf_mut<BD: BitDepth>(&mut self) -> &mut [BD::Pixel; EMU_EDGE_LEN] {
FromBytes::mut_from_prefix(&mut self.0).unwrap()
}
}
Expand All @@ -971,7 +971,7 @@ impl EmuEdge {
#[repr(C)]
pub struct ScratchInter {
pub lap_inter: ScratchLapInter,
pub emu_edge: EmuEdge,
pub emu_edge: ScratchEmuEdge,
}

#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
Expand All @@ -981,25 +981,10 @@ pub struct ScratchPal {
pub pal_ctx: [u8; 64],
}

impl Default for ScratchPal {
fn default() -> Self {
Self {
pal_order: [[0; 8]; 64],
pal_ctx: [0; 64],
}
}
}

#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
#[repr(C, align(64))]
pub struct ScratchLevelsPal([u8; 1088]);

impl Default for ScratchLevelsPal {
fn default() -> Self {
Self([0; 1088])
}
}

impl ScratchLevelsPal {
pub fn levels_mut(&mut self) -> &mut [u8; 1088] {
&mut self.0
Expand All @@ -1012,30 +997,29 @@ impl ScratchLevelsPal {

#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
#[repr(C, align(64))]
pub struct InterIntraEdgePalInterintra([u8; 64 * 64 * 2]);
pub struct ScratchInterintraBuf([u8; 64 * 64 * 2]);

impl InterIntraEdgePalInterintra {
impl ScratchInterintraBuf {
pub fn buf_mut<BD: BitDepth>(&mut self) -> &mut [BD::Pixel; 64 * 64] {
FromBytes::mut_from_prefix(&mut self.0).unwrap()
}
}

#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
#[repr(C, align(32))]
pub struct InterIntraEdgePalEdge([u8; 257 * 2 + 30]); // 257 Pixel elements + 30 padding bytes
pub struct ScratchEdgeBuf([u8; 257 * 2 + 30]); // 257 Pixel elements + 30 padding bytes

impl InterIntraEdgePalEdge {
impl ScratchEdgeBuf {
pub fn buf_mut<BD: BitDepth>(&mut self) -> &mut [BD::Pixel; 257] {
FromBytes::mut_from_prefix(&mut self.0).unwrap()
}
}

#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
#[repr(C, align(16))]
pub struct InterIntraEdgePalPal([u8; 8 * 3 * 2]); /* [3 plane][8 palette_idx] */

pub struct ScratchPalBuf([u8; 8 * 3 * 2]); /* [3 plane][8 palette_idx] */

impl InterIntraEdgePalPal {
impl ScratchPalBuf {
pub fn buf<BD: BitDepth>(&self) -> &[[BD::Pixel; 8]; 3] {
FromBytes::ref_from_prefix(&self.0).unwrap()
}
Expand All @@ -1047,10 +1031,10 @@ impl InterIntraEdgePalPal {

#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
#[repr(C)]
pub struct InterIntraEdgePal {
pub interintra: InterIntraEdgePalInterintra,
pub edge: InterIntraEdgePalEdge,
pub pal: InterIntraEdgePalPal,
pub struct ScratchInterintraEdgePal {
pub interintra: ScratchInterintraBuf,
pub edge: ScratchEdgeBuf,
pub pal: ScratchPalBuf,
_padding: [u8; 48],
}

Expand All @@ -1069,7 +1053,6 @@ impl ScratchAcTxtpMap {
FromBytes::mut_from_prefix(&mut self.0).unwrap()
}

#[track_caller]
pub fn txtp_map(&self) -> &[TxfmType; 1024] {
FromBytes::ref_from_prefix(&self.0).unwrap()
}
Expand All @@ -1085,7 +1068,7 @@ pub struct ScratchInterIntra {
pub levels_pal: ScratchLevelsPal,
pub ac_txtp_map: ScratchAcTxtpMap,
pub pal_idx: [u8; 8192],
pub interintra_edge_pal: InterIntraEdgePal,
pub interintra_edge_pal: ScratchInterintraEdgePal,
}

// Larger of the two between `ScratchInter` and `ScratchInterIntra`.
Expand All @@ -1099,7 +1082,6 @@ impl TaskContextScratch {
FromBytes::mut_from_prefix(&mut self.0).unwrap()
}

#[track_caller]
pub fn inter_intra(&self) -> &ScratchInterIntra {
FromBytes::ref_from_prefix(&self.0).unwrap()
}
Expand Down
6 changes: 3 additions & 3 deletions src/recon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ use crate::src::env::get_uv_inter_txtp;
use crate::src::internal::Bxy;
use crate::src::internal::Cf;
use crate::src::internal::CodedBlockInfo;
use crate::src::internal::EmuEdge;
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::ScratchEmuEdge;
use crate::src::internal::TileStateRef;
use crate::src::intra_edge::EdgeFlags;
use crate::src::ipred_prepare::rav1d_prepare_intra_edges;
Expand Down Expand Up @@ -2117,7 +2117,7 @@ pub(crate) unsafe fn rav1d_read_coef_blocks<BD: BitDepth>(

unsafe fn mc<BD: BitDepth>(
f: &Rav1dFrameData,
emu_edge: &mut EmuEdge,
emu_edge: &mut ScratchEmuEdge,
b: Bxy,
dst8: *mut BD::Pixel,
dst16: *mut i16,
Expand Down Expand Up @@ -2404,7 +2404,7 @@ unsafe fn obmc<BD: BitDepth>(

unsafe fn warp_affine<BD: BitDepth>(
f: &Rav1dFrameData,
emu_edge: &mut EmuEdge,
emu_edge: &mut ScratchEmuEdge,
b: Bxy,
mut dst8: *mut BD::Pixel,
mut dst16: *mut i16,
Expand Down

0 comments on commit 012114f

Please sign in to comment.