use after_effects as ae;
use crate::cpu::render::{CpuDispatchFn, CpuDispatchTileFn};
use crate::kernel::params::KernelParams;
use crate::types::Configuration;
pub type GpuDispatchFn<P> = unsafe fn(&Configuration, P) -> Result<(), &'static str>;
pub type CpuRenderFn<P> = fn(&ae::InData, &ae::Layer, &mut ae::Layer, &Configuration, P) -> Result<(), ae::Error>;
pub struct Kernel<P: KernelParams> {
name: &'static str,
shader_src: &'static [u8],
entry_point: &'static str,
cpu_dispatch: CpuDispatchFn,
cpu_dispatch_tile: CpuDispatchTileFn,
gpu_dispatch: GpuDispatchFn<P>,
cpu_render: CpuRenderFn<P>,
}
impl<P: KernelParams> Kernel<P> {
pub const fn new(
name: &'static str,
shader_src: &'static [u8],
entry_point: &'static str,
cpu_dispatch: CpuDispatchFn,
cpu_dispatch_tile: CpuDispatchTileFn,
gpu_dispatch: GpuDispatchFn<P>,
cpu_render: CpuRenderFn<P>,
) -> Self {
Self {
name,
shader_src,
entry_point,
cpu_dispatch,
cpu_dispatch_tile,
gpu_dispatch,
cpu_render,
}
}
#[inline]
pub const fn name(&self) -> &'static str {
self.name
}
#[inline]
pub const fn shader_src(&self) -> &'static [u8] {
self.shader_src
}
#[inline]
pub const fn entry_point(&self) -> &'static str {
self.entry_point
}
#[inline]
pub const fn cpu_dispatch(&self) -> CpuDispatchFn {
self.cpu_dispatch
}
#[inline]
pub const fn cpu_dispatch_tile(&self) -> CpuDispatchTileFn {
self.cpu_dispatch_tile
}
#[inline]
pub unsafe fn dispatch_gpu(&self, config: &Configuration, params: P) -> Result<(), &'static str> {
unsafe { (self.gpu_dispatch)(config, params) }
}
#[inline]
pub fn dispatch_cpu(
&self,
in_data: &ae::InData,
in_layer: &ae::Layer,
out_layer: &mut ae::Layer,
config: &Configuration,
params: P,
) -> Result<(), ae::Error> {
(self.cpu_render)(in_data, in_layer, out_layer, config, params)
}
#[inline]
pub unsafe fn dispatch_cpu_direct(&self, config: &Configuration, params: P) {
unsafe {
crate::cpu::render::render_cpu_direct(self.name, config, self.cpu_dispatch_tile, ¶ms);
}
}
}