spirv: cpu: inline most of this step logic

This commit is contained in:
2022-07-27 12:42:44 -07:00
parent d0afca7e3f
commit 6b51fcea02

View File

@@ -23,58 +23,17 @@ impl<R: Real, M: Material<R>> SimBackend<R, M> for CpuBackend {
m: &mut [Vec3<R>], m: &mut [Vec3<R>],
) { ) {
for _ in 0..num_steps { for _ in 0..num_steps {
step_e(meta, stim_e, mat, e, h, m); // step E field
step_h(meta, stim_h, mat, e, h, m);
}
}
}
fn step_e<R: Real, M: Material<R>>(
meta: SimMeta<R>,
stim_e: &[Vec3<R>],
mat: &[M],
e: &mut [Vec3<R>],
h: &[Vec3<R>],
m: &[Vec3<R>],
) {
apply_all_cells(meta.dim, |idx| { apply_all_cells(meta.dim, |idx| {
step_e_cell(idx, meta, stim_e, mat, e, h, m);
});
}
fn step_h<R: Real, M: Material<R>>(
meta: SimMeta<R>,
stim_h: &[Vec3<R>],
mat: &[M],
e: &[Vec3<R>],
h: &mut [Vec3<R>],
m: &mut [Vec3<R>],
) {
apply_all_cells(meta.dim, |idx| {
step_h_cell(idx, meta, stim_h, mat, e, h, m);
});
}
fn step_e_cell<R: Real, M: Material<R>>(
idx: Vec3u,
meta: SimMeta<R>,
stim_e: &[Vec3<R>],
mat: &[M],
e: &mut [Vec3<R>],
h: &[Vec3<R>],
m: &[Vec3<R>],
) {
StepEContext::step_flat_view(meta, mat, stim_e, e, h, idx); StepEContext::step_flat_view(meta, mat, stim_e, e, h, idx);
} });
fn step_h_cell<R: Real, M: Material<R>>(
idx: Vec3u, // step H field
meta: SimMeta<R>, apply_all_cells(meta.dim, |idx| {
stim_h: &[Vec3<R>],
mat: &[M],
e: &[Vec3<R>],
h: &mut [Vec3<R>],
m: &mut [Vec3<R>],
) {
StepHContext::step_flat_view(meta, mat, stim_h, e, h, m, idx); StepHContext::step_flat_view(meta, mat, stim_h, e, h, m, idx);
});
}
}
} }
fn apply_all_cells<F: FnMut(Vec3u)>(dim: Vec3u, mut f: F) { fn apply_all_cells<F: FnMut(Vec3u)>(dim: Vec3u, mut f: F) {