SGPU-Compute
Simple GPU-Compute using WebGPU
This crate aims to provide a simple and easy-to-use interface to run compute shaders with WGPU and WGSL. It is designed to be as simple as possible to use, while still providing a lot of flexibility for performance reason.
Quickstart
use *;
let my_shader = "
@group(0) @binding(0) var<uniform> coefficient: u32;
@group(0) @binding(1) var<storage, read> in: array<u32>;
@group(0) @binding(2) var<storage, read_write> out: array<u32>;
@compute
@workgroup_size(8, 1, 1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
out[global_id.x] = coefficient * in[global_id.x];
}
";
const N_ELEMENT: usize = 64;
const WORKGROUP_SIZE: usize = 8;
const N_WORKGROUP: u32 = as u32;
let gpu = new;
let mut pipeline = gpu.gen_pipeline;
const COEFFICIENT: u32 = 42;
let input: = from_fn;
pipeline.write_uniform;
let result_gpu = pipeline.run;
let result_cpu = input.map;
assert_eq!;
Features
- Quick setup for using WGPU for computing
- Blocking and async API are available
- Multi-stage shader are possible
Examples
Example are provided inside the examples directory