use super::arena::CoeffArena;
use super::ledger::StillSearchLedger;
use crate::contexts::Contexts;
use crate::rdoq::RdoqScratch;
use crate::residual::ResidualPricingScratch;
#[derive(Clone, Copy, Debug, Default)]
pub(super) struct SsimRdNorm {
pub(super) valid: bool,
pub(super) qp: i32,
pub(super) f_dc_den: u64,
pub(super) f_ac_den: u64,
}
#[derive(Clone, Copy, Debug, Default)]
pub(super) struct PsyRdWeight {
pub(super) valid: bool,
pub(super) qp: i32,
pub(super) weight: f64,
}
#[derive(Clone, Copy, Debug, Default)]
pub(super) struct SubstageProfile {
pub border_ns: u64,
pub predict_ns: u64,
pub forward_xform_ns: u64,
pub quant_ns: u64,
pub recon_dist_ns: u64,
pub residual_price_ns: u64,
pub calls: u64,
}
pub(super) struct CtuWorkspace {
pub(super) coeffs: CoeffArena,
pub(super) ledger: StillSearchLedger,
pub(super) block_scratch: BlockScratch,
pub(super) price_base: Contexts,
pub(super) price_cur: Contexts,
pub(super) commit_ctx: bool,
pub(super) commit_ctx_skip_chroma: bool,
pub(super) price_scratch: ResidualPricingScratch,
pub(super) rdoq_scratch: RdoqScratch,
pub(super) last_8x8_rough_satd: f64,
pub(super) last_rough_best_cost: f64,
pub(super) substage: SubstageProfile,
pub(super) ssim_rd_norm: [SsimRdNorm; 3],
pub(super) psy_rd_weight: [PsyRdWeight; 3],
pub(super) tu_split_early_terminations: u64,
pub(super) tu_split_bound_aborts: u64,
pub(super) tu_leaf_by_log2: [u64; 7],
pub(super) tu_split_by_log2: [u64; 7],
pub(super) root_tu_capture: bool,
pub(super) root_tu_candidates: Vec<RootTuCandidate>,
pub(super) root_tu_cache: Option<RootTuCache>,
pub(super) root_tu_reuse_hits: u64,
}
#[derive(Default, Debug)]
pub(super) struct RootTuCandidate {
pub(super) cbf: bool,
pub(super) cost: f64,
pub(super) dist: u64,
pub(super) frac_bits: u64,
pub(super) rd_frac_bits: u64,
pub(super) push_block: Vec<u8>,
pub(super) levels: Vec<i16>,
}
impl RootTuCandidate {
#[allow(clippy::too_many_arguments)]
pub(super) fn set(
&mut self,
cbf: bool,
cost: f64,
dist: u64,
frac_bits: u64,
rd_frac_bits: u64,
push_block: &[u8],
levels: &[i16],
) {
self.cbf = cbf;
self.cost = cost;
self.dist = dist;
self.frac_bits = frac_bits;
self.rd_frac_bits = rd_frac_bits;
self.push_block.clear();
self.push_block.extend_from_slice(push_block);
self.levels.clear();
self.levels.extend_from_slice(levels);
}
}
pub(super) struct RootTuCache {
pub(super) x0: u32,
pub(super) y0: u32,
pub(super) log2_size: u8,
pub(super) mode: u8,
pub(super) qp: i32,
pub(super) lambda_bits: u64,
pub(super) quant: super::eval::QuantMode,
pub(super) sdh: bool,
pub(super) ctx: Contexts,
pub(super) cand: RootTuCandidate,
}
impl Default for CtuWorkspace {
fn default() -> Self {
Self {
coeffs: CoeffArena::default(),
ledger: StillSearchLedger::default(),
block_scratch: BlockScratch::default(),
price_base: Contexts::new(0),
price_cur: Contexts::new(0),
commit_ctx: false,
commit_ctx_skip_chroma: false,
price_scratch: ResidualPricingScratch::default(),
rdoq_scratch: RdoqScratch::default(),
last_8x8_rough_satd: f64::INFINITY,
last_rough_best_cost: f64::INFINITY,
substage: SubstageProfile::default(),
ssim_rd_norm: [SsimRdNorm::default(); 3],
psy_rd_weight: [PsyRdWeight::default(); 3],
tu_split_early_terminations: 0,
tu_split_bound_aborts: 0,
tu_leaf_by_log2: [0; 7],
tu_split_by_log2: [0; 7],
root_tu_capture: false,
root_tu_candidates: Vec::new(),
root_tu_cache: None,
root_tu_reuse_hits: 0,
}
}
}
impl CtuWorkspace {
pub(super) fn reset(&mut self) {
self.coeffs.clear();
self.ledger.clear_ctu();
self.block_scratch.clear_ctu();
self.substage = SubstageProfile::default();
self.ssim_rd_norm = [SsimRdNorm::default(); 3];
self.psy_rd_weight = [PsyRdWeight::default(); 3];
self.tu_split_early_terminations = 0;
self.tu_split_bound_aborts = 0;
self.tu_leaf_by_log2 = [0; 7];
self.tu_split_by_log2 = [0; 7];
self.root_tu_capture = false;
self.root_tu_cache = None;
self.root_tu_reuse_hits = 0;
}
pub(super) fn set_price_context(&mut self, ctxs: &Contexts) {
self.price_base = ctxs.clone();
self.price_cur = ctxs.clone();
self.commit_ctx = false;
self.commit_ctx_skip_chroma = false;
}
}
#[derive(Default, Debug)]
pub(super) struct BlockScratch {
pub(super) residual_i16_4x4: Vec<i16>,
pub(super) residual_i16_8x8: Vec<i16>,
pub(super) residual_i16_16x16: Vec<i16>,
pub(super) residual_i16_32x32: Vec<i16>,
pub(super) coeff_i16: Vec<i16>,
pub(super) transform_tmp_i16: Vec<i16>,
pub(super) levels_i16: Vec<i16>,
pub(super) dequant_coeff_i16: Vec<i16>,
pub(super) recon_residual_i16: Vec<i16>,
pub(super) rough_angular_batch_u16: Vec<u16>,
pub(super) rough_pred_u8: Vec<u8>,
pub(super) component_src_u8: Vec<u8>,
pub(super) component_pred_u8: Vec<u8>,
pub(super) component_recon_u8: Vec<u8>,
pub(super) component_src_u16: Vec<u16>,
pub(super) component_pred_u16: Vec<u16>,
pub(super) component_recon_u16: Vec<u16>,
pub(super) component_pred_tmp_u16: Vec<u16>,
pub(super) psy_src_i16: Vec<i16>,
pub(super) psy_dct_i16: Vec<i16>,
pub(super) simple_rdo_accum: Vec<super::tu::SimpleRdoAccum>,
}
impl BlockScratch {
pub(super) fn clear_ctu(&mut self) {
self.residual_i16_4x4.clear();
self.residual_i16_8x8.clear();
self.residual_i16_16x16.clear();
self.residual_i16_32x32.clear();
self.coeff_i16.clear();
self.transform_tmp_i16.clear();
self.levels_i16.clear();
self.dequant_coeff_i16.clear();
self.recon_residual_i16.clear();
self.rough_angular_batch_u16.clear();
self.rough_pred_u8.clear();
self.component_src_u8.clear();
self.component_pred_u8.clear();
self.component_recon_u8.clear();
self.component_src_u16.clear();
self.component_pred_u16.clear();
self.component_recon_u16.clear();
self.component_pred_tmp_u16.clear();
self.psy_src_i16.clear();
self.psy_dct_i16.clear();
self.simple_rdo_accum.clear();
}
}