git.lucas.co / cce-ui
GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git

examples/compute_web.rs (814B)

 1 //! The compute probe on WebGPU (`web::ComputeDevice`), in a browser: the
 2 //! shared jobs (`compute_probe/jobs.rs`), one line each, returned to the
 3 //! page. A cdylib for wasm-bindgen; natively it is empty.
 4 
 5 #[cfg(target_arch = "wasm32")]
 6 #[path = "compute_probe/jobs.rs"]
 7 mod jobs;
 8 
 9 #[cfg(target_arch = "wasm32")]
10 mod web {
11     use super::jobs;
12     use wasm_bindgen::prelude::*;
13 
14     /// The device's name and every job's line, newline-separated.
15     #[wasm_bindgen]
16     pub async fn run_jobs() -> Result<String, JsValue> {
17         std::panic::set_hook(Box::new(|info| web_sys::console::error_1(&info.to_string().into())));
18         let mut dev = cce_ui::web::ComputeDevice::new().await?;
19         web_sys::console::log_1(&dev.device_name().into());
20         Ok(crate::compute_jobs!(dev, .await).join("\n"))
21     }
22 }