File size: 2,547 Bytes
eae424a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
//! DINOv3 inference on Meta Quest, via Blade for graphics and Meganeura
//! for the network.
//!
//! The camera image is encoded to DINOv3 patch features and those features
//! are turned back into something viewable, so the user sees the world
//! through a DINO roundtrip.
//!
//! # Layout
//!
//! * [`dinov3`] — the encoder as a meganeura graph, plus its config.
//! * [`preprocess`] — image to patch tensor, with the flattening order the
//!   folded patch-embedding matmul requires.
//! * [`weights`] — binding a HuggingFace checkpoint to graph parameters.
//! * [`bench`] — throughput measurement, shared by the desktop and
//!   on-device entry points.
//!
//! # Sharing one GPU context
//!
//! The renderer and the network run on a *single*
//! `blade_graphics::Context`, created here and handed to meganeura through
//! `SessionConfig::gpu`. That is why this crate pins the same
//! blade-graphics revision meganeura does — two copies of the crate would
//! make the `Arc<Context>` types incompatible. It also means no
//! external-memory interop is needed: `Session::input_buffer` hands back a
//! `BufferPiece` a render pass can write to directly.

pub mod bench;
#[cfg(target_os = "android")]
pub mod camera;
pub mod decoder;
pub mod dinov3;
pub mod inference;
pub mod pca;
pub mod preprocess;
pub mod render;
pub mod source;
pub mod weights;

use std::sync::Arc;

/// Create the GPU context that both the renderer and inference will share.
///
/// `xr` stays `None` for headless compute (the benchmark); the XR path
/// fills in an `XrDesc` and everything downstream is unchanged.
pub fn init_context(
    xr: Option<blade_graphics::XrDesc>,
) -> Result<Arc<blade_graphics::Context>, blade_graphics::NotSupportedError> {
    let context = unsafe {
        blade_graphics::Context::init(blade_graphics::ContextDesc {
            presentation: false,
            xr,
            ray_tracing: false,
            // Validation layers are not present on a retail Quest, and
            // they cost real time where we can least afford it.
            validation: cfg!(debug_assertions) && !cfg!(target_os = "android"),
            timing: false,
            capture: false,
            overlay: false,
            device_id: None,
        })
    }?;
    let info = context.device_information();
    log::info!(
        "GPU: {} ({}), driver {}",
        info.device_name,
        info.driver_name,
        info.driver_info
    );
    Ok(Arc::new(context))
}