scry_gpu/lib.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2//! # scry-gpu
3//!
4//! Lightweight GPU compute for Rust — dispatch shaders without the graphics baggage.
5//!
6//! scry-gpu is a compute-only GPU abstraction. No render passes, no swapchains,
7//! no framebuffers. Upload data, dispatch a WGSL shader, read results back.
8//!
9//! ## Quick start
10//!
11//! ```ignore
12//! use scry_gpu::Device;
13//!
14//! let gpu = Device::auto()?;
15//!
16//! let input = gpu.upload(&[1.0f32, 2.0, 3.0, 4.0])?;
17//! let output = gpu.alloc::<f32>(4)?;
18//!
19//! gpu.dispatch("@group(0) @binding(0) var<storage, read> input: array<f32>;
20//! @group(0) @binding(1) var<storage, read_write> output: array<f32>;
21//! @compute @workgroup_size(64)
22//! fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
23//! let i = gid.x;
24//! if i < arrayLength(&input) {
25//! output[i] = input[i] * 2.0;
26//! }
27//! }", &[&input, &output], 4)?;
28//!
29//! let result: Vec<f32> = output.download()?;
30//! assert_eq!(result, vec![2.0, 4.0, 6.0, 8.0]);
31//! ```
32//!
33//! ## Design principles
34//!
35//! - **Compute only.** No graphics API surface. This keeps the dependency tree
36//! small and the API surface minimal.
37//! - **Auto-dispatch.** Workgroup dimensions are calculated from your invocation
38//! count and the shader's `@workgroup_size`. No manual `ceil(n / 64)`.
39//! - **Typed buffers.** `Buffer<f32>` uploads `&[f32]` and downloads `Vec<f32>`.
40//! Staging, alignment, and synchronization are handled internally.
41//! - **Backend abstraction.** Vulkan today, Metal tomorrow. The public API
42//! doesn't change.
43
44mod backend;
45mod batch;
46mod buffer;
47mod device;
48mod dispatch;
49mod error;
50mod kernel;
51mod shader;
52pub mod shaders;
53mod ticket;
54
55pub use batch::Batch;
56pub use buffer::{Buffer, GpuBuf};
57pub use device::{BackendKind, Device};
58pub use dispatch::DispatchConfig;
59pub use error::{BackendOp, GpuError, Result};
60pub use kernel::Kernel;
61pub use ticket::Ticket;