burn_reconstruction 0.1.1

burn feed-forward gaussian splatting
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
use std::path::{Path, PathBuf};
#[cfg(target_arch = "wasm32")]
use std::time::Duration;

use crate::backend::{default_device, BackendDevice, BackendImpl};
use crate::bootstrap::{
    resolve_or_bootstrap_yono_weights_with_config,
    resolve_or_bootstrap_yono_weights_with_precision,
    resolve_or_bootstrap_yono_weights_with_precision_and_progress, ModelBootstrapError,
    YonoBootstrapConfig,
};
use burn::tensor::Tensor;
use burn_yono::{
    glb::{GlbExportOptions, GlbSortMode},
    inference::{ApplySummary, ForwardTimings, YonoModelBundle, YonoPipelineError},
    model::gaussian::FlatGaussians,
    YonoWeightFormat, YonoWeightPrecision, YonoWeights,
};

/// Model families supported by the outer multi-view pipeline.
///
/// Kept as an enum so additional multi-view -> 3DGS methods can be added
/// without changing call sites.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum PipelineModel {
    Yono,
}

/// Export/inference quality presets.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum PipelineQuality {
    Fast,
    #[default]
    Balanced,
    High,
}

impl PipelineQuality {
    /// Maps quality presets to GLB export policy.
    pub fn export_options(self) -> GlbExportOptions {
        match self {
            Self::Fast => GlbExportOptions {
                max_gaussians: 2048,
                opacity_threshold: 0.05,
                sort_mode: GlbSortMode::Opacity,
            },
            Self::Balanced => GlbExportOptions::default(),
            Self::High => GlbExportOptions {
                max_gaussians: 200_000,
                opacity_threshold: 0.0,
                sort_mode: GlbSortMode::Index,
            },
        }
    }
}

/// High-level model/runtime settings for image -> gaussian inference.
#[derive(Debug, Clone)]
pub struct PipelineConfig {
    pub model: PipelineModel,
    pub quality: PipelineQuality,
    pub image_size: usize,
}

impl Default for PipelineConfig {
    fn default() -> Self {
        Self {
            model: PipelineModel::Yono,
            quality: PipelineQuality::Balanced,
            image_size: 224,
        }
    }
}

/// Weight configuration for loading the active model family.
#[derive(Debug, Clone)]
pub struct PipelineWeights {
    pub yono: YonoWeights,
}

impl PipelineWeights {
    /// Uses repository default safetensor checkpoint paths.
    pub fn default_yono_safetensors() -> Self {
        Self {
            yono: YonoWeights::safetensors(
                "assets/models/yono_backbone_weights.safetensors",
                "assets/models/yono_head_weights.safetensors",
            ),
        }
    }

    /// Uses repository default burnpack checkpoint paths.
    pub fn default_yono_burnpack() -> Self {
        Self {
            yono: YonoWeights::burnpack(
                "assets/models/yono_backbone.bpk",
                "assets/models/yono_head.bpk",
            ),
        }
    }

    /// Creates weights from explicit backbone/head paths.
    pub fn from_paths(backbone: impl Into<PathBuf>, head: impl Into<PathBuf>) -> Self {
        Self {
            yono: YonoWeights::new(backbone, head),
        }
    }

    /// Creates weights from prebuilt YoNoSplat weight settings.
    pub fn from_yono(yono: YonoWeights) -> Self {
        Self { yono }
    }

    /// Overrides checkpoint format for the YoNoSplat weights.
    pub fn with_format(mut self, format: YonoWeightFormat) -> Self {
        self.yono = self.yono.with_format(format);
        self
    }

    /// Sets preferred burnpack precision for YoNo model loading.
    pub fn with_precision(mut self, precision: YonoWeightPrecision) -> Self {
        self.yono = self.yono.with_precision(precision);
        self
    }

    /// Resolves YoNoSplat model files from cache, downloading from remote when missing.
    pub fn resolve_or_bootstrap_yono(
        format: YonoWeightFormat,
    ) -> Result<Self, ModelBootstrapError> {
        Self::resolve_or_bootstrap_yono_with_precision(format, YonoWeightPrecision::F16)
    }

    /// Resolves YoNoSplat model files with explicit precision selection.
    pub fn resolve_or_bootstrap_yono_with_precision(
        format: YonoWeightFormat,
        precision: YonoWeightPrecision,
    ) -> Result<Self, ModelBootstrapError> {
        Ok(Self {
            yono: resolve_or_bootstrap_yono_weights_with_precision(format, precision)?,
        })
    }

    /// Resolves YoNoSplat model files with explicit precision and progress callbacks.
    pub fn resolve_or_bootstrap_yono_with_precision_and_progress<F>(
        format: YonoWeightFormat,
        precision: YonoWeightPrecision,
        progress: F,
    ) -> Result<Self, ModelBootstrapError>
    where
        F: Fn(String) + Send + Sync + 'static,
    {
        Ok(Self {
            yono: resolve_or_bootstrap_yono_weights_with_precision_and_progress(
                format, precision, progress,
            )?,
        })
    }

    /// Resolves YoNoSplat model files with explicit bootstrap configuration.
    pub fn resolve_or_bootstrap_yono_with_config(
        format: YonoWeightFormat,
        bootstrap_cfg: &YonoBootstrapConfig,
    ) -> Result<Self, ModelBootstrapError> {
        Self::resolve_or_bootstrap_yono_with_config_and_precision(
            format,
            bootstrap_cfg,
            bootstrap_cfg.burnpack_precision,
        )
    }

    /// Resolves YoNoSplat model files with explicit bootstrap configuration and precision.
    pub fn resolve_or_bootstrap_yono_with_config_and_precision(
        format: YonoWeightFormat,
        bootstrap_cfg: &YonoBootstrapConfig,
        precision: YonoWeightPrecision,
    ) -> Result<Self, ModelBootstrapError> {
        let mut cfg = bootstrap_cfg.clone();
        cfg.burnpack_precision = precision;
        Ok(Self {
            yono: resolve_or_bootstrap_yono_weights_with_config(format, &cfg)?,
        })
    }
}

/// Canonical gaussian tensor output type for this crate.
pub type PipelineGaussians = FlatGaussians<BackendImpl>;

/// Timed inference result.
#[derive(Debug)]
pub struct PipelineRunOutput {
    pub gaussians: PipelineGaussians,
    pub timings: ForwardTimings,
}

/// In-memory image input for image -> gaussian inference.
#[derive(Debug, Clone, Copy)]
pub struct PipelineInputImage<'a> {
    pub name: &'a str,
    pub bytes: &'a [u8],
}

/// Timed inference result with predicted camera poses.
#[derive(Debug)]
pub struct PipelineRunWithCameras {
    pub gaussians: PipelineGaussians,
    pub timings: ForwardTimings,
    pub camera_poses: Vec<[[f32; 4]; 4]>,
}

/// End-to-end `infer + export` report.
#[derive(Debug, Clone)]
pub struct PipelineExportReport {
    pub selected_gaussians: usize,
    pub select_millis: f64,
    pub write_millis: f64,
}

/// Model load metadata for transparency/debugging.
#[derive(Debug, Clone)]
pub struct PipelineLoadReport {
    pub backbone: ComponentLoadReport,
    pub head: ComponentLoadReport,
}

/// Per-component checkpoint application report.
#[derive(Debug, Clone)]
pub struct ComponentLoadReport {
    pub applied: usize,
    pub missing: Vec<String>,
    pub unused: Vec<String>,
    pub skipped: Vec<String>,
}

#[derive(Debug, thiserror::Error)]
pub enum PipelineError {
    #[error("unsupported model selection")]
    UnsupportedModel,
    #[error("failed to resolve/bootstrap model weights: {0}")]
    Bootstrap(#[from] ModelBootstrapError),
    #[error("yono pipeline error: {0}")]
    Yono(#[from] YonoPipelineError),
    #[error("failed to read debug tensor from backend: {0}")]
    TensorData(String),
    #[error("gaussian glb export failed: {0}")]
    Export(#[from] burn_yono::glb::GlbExportError),
}

/// High-level, WGPU-native multi-view pipeline.
///
/// This type intentionally locks the outer API to the validated WGPU path.
#[derive(Debug)]
pub struct ImageToGaussianPipeline {
    cfg: PipelineConfig,
    device: BackendDevice,
    yono: YonoModelBundle<BackendImpl>,
}

impl ImageToGaussianPipeline {
    /// Loads model weights on a user-provided WGPU device.
    pub fn load(
        device: BackendDevice,
        cfg: PipelineConfig,
        weights: PipelineWeights,
    ) -> Result<(Self, PipelineLoadReport), PipelineError> {
        Self::load_with_progress(device, cfg, weights, |_| {})
    }

    /// Loads model weights on a user-provided WGPU device and reports progress.
    pub fn load_with_progress<F>(
        device: BackendDevice,
        cfg: PipelineConfig,
        weights: PipelineWeights,
        progress: F,
    ) -> Result<(Self, PipelineLoadReport), PipelineError>
    where
        F: Fn(String),
    {
        match cfg.model {
            PipelineModel::Yono => {
                let (yono, report) = YonoModelBundle::load_from_weights_with_progress(
                    &device,
                    &weights.yono,
                    progress,
                )?;
                Ok((
                    Self { cfg, device, yono },
                    PipelineLoadReport {
                        backbone: from_apply_summary(&report.backbone),
                        head: from_apply_summary(&report.head),
                    },
                ))
            }
        }
    }

    /// Loads model weights on the default WGPU device.
    pub fn load_default(
        cfg: PipelineConfig,
        weights: PipelineWeights,
    ) -> Result<(Self, PipelineLoadReport), PipelineError> {
        Self::load_with_progress(default_device(), cfg, weights, |_| {})
    }

    /// Loads model weights on the default WGPU device and reports progress.
    pub fn load_default_with_progress<F>(
        cfg: PipelineConfig,
        weights: PipelineWeights,
        progress: F,
    ) -> Result<(Self, PipelineLoadReport), PipelineError>
    where
        F: Fn(String),
    {
        Self::load_with_progress(default_device(), cfg, weights, progress)
    }

    /// Loads YoNo models directly from burnpack parts bytes.
    ///
    /// This is primarily intended for wasm/web runtimes that fetch
    /// `*.bpk.parts.json` + `*.bpk.part-*` assets from HTTP storage.
    pub fn load_from_yono_parts(
        device: BackendDevice,
        cfg: PipelineConfig,
        backbone_parts: &[Vec<u8>],
        head_parts: &[Vec<u8>],
    ) -> Result<(Self, PipelineLoadReport), PipelineError> {
        Self::load_from_yono_parts_with_progress(device, cfg, backbone_parts, head_parts, |_| {})
    }

    /// Loads YoNo models directly from burnpack parts bytes and reports progress.
    pub fn load_from_yono_parts_with_progress<F>(
        device: BackendDevice,
        cfg: PipelineConfig,
        backbone_parts: &[Vec<u8>],
        head_parts: &[Vec<u8>],
        progress: F,
    ) -> Result<(Self, PipelineLoadReport), PipelineError>
    where
        F: Fn(String),
    {
        match cfg.model {
            PipelineModel::Yono => {
                let (yono, report) = YonoModelBundle::load_from_burnpack_part_bytes_with_progress(
                    &device,
                    backbone_parts,
                    head_parts,
                    progress,
                )?;
                Ok((
                    Self { cfg, device, yono },
                    PipelineLoadReport {
                        backbone: from_apply_summary(&report.backbone),
                        head: from_apply_summary(&report.head),
                    },
                ))
            }
        }
    }

    /// Loads the pipeline using cache-first, auto-downloaded default weights.
    pub fn load_default_bootstrapped(
        cfg: PipelineConfig,
        format: YonoWeightFormat,
    ) -> Result<(Self, PipelineLoadReport), PipelineError> {
        let weights = PipelineWeights::resolve_or_bootstrap_yono_with_precision(
            format,
            YonoWeightPrecision::F16,
        )?;
        Self::load_default(cfg, weights)
    }

    /// Loads the pipeline using cache-first auto-downloaded default weights and explicit precision.
    pub fn load_default_bootstrapped_with_precision(
        cfg: PipelineConfig,
        format: YonoWeightFormat,
        precision: YonoWeightPrecision,
    ) -> Result<(Self, PipelineLoadReport), PipelineError> {
        let weights = PipelineWeights::resolve_or_bootstrap_yono_with_precision(format, precision)?;
        Self::load_default(cfg, weights)
    }

    /// Loads the pipeline using explicit bootstrap configuration.
    pub fn load_default_bootstrapped_with_config(
        cfg: PipelineConfig,
        format: YonoWeightFormat,
        bootstrap_cfg: &YonoBootstrapConfig,
    ) -> Result<(Self, PipelineLoadReport), PipelineError> {
        let weights = PipelineWeights::resolve_or_bootstrap_yono_with_config_and_precision(
            format,
            bootstrap_cfg,
            bootstrap_cfg.burnpack_precision,
        )?;
        Self::load_default(cfg, weights)
    }

    /// Loads the pipeline using explicit bootstrap configuration and precision.
    pub fn load_default_bootstrapped_with_config_and_precision(
        cfg: PipelineConfig,
        format: YonoWeightFormat,
        bootstrap_cfg: &YonoBootstrapConfig,
        precision: YonoWeightPrecision,
    ) -> Result<(Self, PipelineLoadReport), PipelineError> {
        let weights = PipelineWeights::resolve_or_bootstrap_yono_with_config_and_precision(
            format,
            bootstrap_cfg,
            precision,
        )?;
        Self::load_default(cfg, weights)
    }

    /// Returns the loaded runtime configuration.
    pub fn config(&self) -> &PipelineConfig {
        &self.cfg
    }

    /// Returns the internal WGPU device used for inference.
    pub fn device(&self) -> &BackendDevice {
        &self.device
    }

    /// Runs multi-view inference from image paths.
    pub fn run_images<P: AsRef<Path>>(
        &self,
        image_paths: &[P],
    ) -> Result<PipelineGaussians, PipelineError> {
        let paths = normalize_paths(image_paths);
        let output = self.yono.forward_from_image_paths(
            paths.as_slice(),
            self.cfg.image_size,
            &self.device,
        )?;
        Ok(output.gaussians_flat)
    }

    /// Runs multi-view inference from in-memory image bytes.
    pub fn run_image_bytes(
        &self,
        images: &[PipelineInputImage<'_>],
    ) -> Result<PipelineGaussians, PipelineError> {
        let named_images = normalize_input_images(images);
        let output = self.yono.forward_from_image_bytes(
            named_images.as_slice(),
            self.cfg.image_size,
            &self.device,
        )?;
        Ok(output.gaussians_flat)
    }

    /// Runs multi-view inference with timing information.
    pub fn run_images_timed<P: AsRef<Path>>(
        &self,
        image_paths: &[P],
        synchronize: bool,
    ) -> Result<PipelineRunOutput, PipelineError> {
        let paths = normalize_paths(image_paths);
        let (output, timings) = self.yono.forward_from_image_paths_timed_with_sync(
            paths.as_slice(),
            self.cfg.image_size,
            &self.device,
            synchronize,
        )?;
        Ok(PipelineRunOutput {
            gaussians: output.gaussians_flat,
            timings,
        })
    }

    /// Runs in-memory multi-view inference with timing information.
    pub fn run_image_bytes_timed(
        &self,
        images: &[PipelineInputImage<'_>],
        synchronize: bool,
    ) -> Result<PipelineRunOutput, PipelineError> {
        let named_images = normalize_input_images(images);
        let (output, timings) = self.yono.forward_from_image_bytes_timed_with_sync(
            named_images.as_slice(),
            self.cfg.image_size,
            &self.device,
            synchronize,
        )?;
        Ok(PipelineRunOutput {
            gaussians: output.gaussians_flat,
            timings,
        })
    }

    /// Runs path-based inference and returns camera poses for visualization/debugging.
    pub fn run_images_timed_with_cameras<P: AsRef<Path>>(
        &self,
        image_paths: &[P],
        synchronize: bool,
    ) -> Result<PipelineRunWithCameras, PipelineError> {
        let paths = normalize_paths(image_paths);
        let (output, timings) = self.yono.forward_from_image_paths_timed_with_sync(
            paths.as_slice(),
            self.cfg.image_size,
            &self.device,
            synchronize,
        )?;
        let camera_poses = decode_camera_poses(output.camera_poses)?;
        Ok(PipelineRunWithCameras {
            gaussians: output.gaussians_flat,
            timings,
            camera_poses,
        })
    }

    /// Runs in-memory inference and returns camera poses for visualization/debugging.
    pub fn run_image_bytes_timed_with_cameras(
        &self,
        images: &[PipelineInputImage<'_>],
        synchronize: bool,
    ) -> Result<PipelineRunWithCameras, PipelineError> {
        let named_images = normalize_input_images(images);
        let (output, timings) = self.yono.forward_from_image_bytes_timed_with_sync(
            named_images.as_slice(),
            self.cfg.image_size,
            &self.device,
            synchronize,
        )?;
        let camera_poses = decode_camera_poses(output.camera_poses)?;
        Ok(PipelineRunWithCameras {
            gaussians: output.gaussians_flat,
            timings,
            camera_poses,
        })
    }

    /// Runs in-memory inference and returns camera poses for visualization/debugging.
    #[cfg(target_arch = "wasm32")]
    pub async fn run_image_bytes_timed_with_cameras_async(
        &self,
        images: &[PipelineInputImage<'_>],
        _synchronize: bool,
    ) -> Result<PipelineRunWithCameras, PipelineError> {
        let named_images = normalize_input_images(images);
        let total_start_ms = wasm_now_ms();
        let output = self.yono.forward_from_image_bytes(
            named_images.as_slice(),
            self.cfg.image_size,
            &self.device,
        )?;
        let camera_poses = decode_camera_poses_async(output.camera_poses).await?;
        let mut timings = ForwardTimings::default();
        let total_secs = ((wasm_now_ms() - total_start_ms) / 1000.0).max(0.0);
        if total_secs.is_finite() {
            timings.total = Duration::from_secs_f64(total_secs);
        }
        Ok(PipelineRunWithCameras {
            gaussians: output.gaussians_flat,
            timings,
            camera_poses,
        })
    }

    /// Saves gaussian tensors to GLB with `KHR_gaussian_splatting`.
    pub fn save_glb(
        &self,
        output: impl AsRef<Path>,
        gaussians: &PipelineGaussians,
        options: &GlbExportOptions,
    ) -> Result<burn_yono::glb::GlbExportReport, PipelineError> {
        Ok(burn_yono::glb::save_gaussians_to_glb_timed(
            output.as_ref(),
            gaussians,
            options,
        )?)
    }

    /// Converts gaussian tensors into a host-side export bundle.
    pub fn select_export_gaussians(
        &self,
        gaussians: &PipelineGaussians,
        options: &GlbExportOptions,
    ) -> Result<burn_yono::glb::ExportGaussians, PipelineError> {
        Ok(burn_yono::glb::select_export_gaussians(gaussians, options)?)
    }

    /// Converts gaussian tensors into a host-side export bundle.
    #[cfg(target_arch = "wasm32")]
    pub async fn select_export_gaussians_async(
        &self,
        gaussians: &PipelineGaussians,
        options: &GlbExportOptions,
    ) -> Result<burn_yono::glb::ExportGaussians, PipelineError> {
        Ok(burn_yono::glb::select_export_gaussians_async(gaussians, options).await?)
    }

    /// One-shot helper that runs inference then writes a GLB using quality defaults.
    pub fn run_images_to_glb<P: AsRef<Path>>(
        &self,
        image_paths: &[P],
        output: impl AsRef<Path>,
    ) -> Result<PipelineExportReport, PipelineError> {
        let gaussians = self.run_images(image_paths)?;
        let report = self.save_glb(output, &gaussians, &self.cfg.quality.export_options())?;
        Ok(PipelineExportReport {
            selected_gaussians: report.selected_gaussians,
            select_millis: report.select_millis,
            write_millis: report.write_millis,
        })
    }
}

fn normalize_paths<P: AsRef<Path>>(image_paths: &[P]) -> Vec<PathBuf> {
    image_paths
        .iter()
        .map(|path| path.as_ref().to_path_buf())
        .collect()
}

fn normalize_input_images<'a>(images: &'a [PipelineInputImage<'a>]) -> Vec<(&'a str, &'a [u8])> {
    images
        .iter()
        .map(|image| (image.name, image.bytes))
        .collect()
}

fn decode_camera_poses(poses: Tensor<BackendImpl, 4>) -> Result<Vec<[[f32; 4]; 4]>, PipelineError> {
    let [batch, views, _, _] = poses.shape().dims::<4>();
    let values = poses
        .into_data()
        .to_vec::<f32>()
        .map_err(|err| PipelineError::TensorData(format!("{err:?}")))?;
    Ok(decode_camera_poses_values(values.as_slice(), batch, views))
}

#[cfg(target_arch = "wasm32")]
async fn decode_camera_poses_async(
    poses: Tensor<BackendImpl, 4>,
) -> Result<Vec<[[f32; 4]; 4]>, PipelineError> {
    let [batch, views, _, _] = poses.shape().dims::<4>();
    let values = poses
        .into_data_async()
        .await
        .to_vec::<f32>()
        .map_err(|err| PipelineError::TensorData(format!("{err:?}")))?;
    Ok(decode_camera_poses_values(values.as_slice(), batch, views))
}

fn decode_camera_poses_values(values: &[f32], batch: usize, views: usize) -> Vec<[[f32; 4]; 4]> {
    let mut out = Vec::with_capacity(batch * views);
    for idx in 0..(batch * views) {
        let off = idx * 16;
        out.push([
            [
                values[off],
                values[off + 1],
                values[off + 2],
                values[off + 3],
            ],
            [
                values[off + 4],
                values[off + 5],
                values[off + 6],
                values[off + 7],
            ],
            [
                values[off + 8],
                values[off + 9],
                values[off + 10],
                values[off + 11],
            ],
            [
                values[off + 12],
                values[off + 13],
                values[off + 14],
                values[off + 15],
            ],
        ]);
    }
    out
}

#[cfg(target_arch = "wasm32")]
fn wasm_now_ms() -> f64 {
    js_sys::Date::now()
}

fn from_apply_summary(summary: &ApplySummary) -> ComponentLoadReport {
    ComponentLoadReport {
        applied: summary.applied,
        missing: summary.missing.clone(),
        unused: summary.unused.clone(),
        skipped: summary.skipped.clone(),
    }
}