Crates.io | wrgpgpu |
lib.rs | wrgpgpu |
version | |
source | src |
created_at | 2024-11-18 04:15:52.53077 |
updated_at | 2024-11-20 21:54:03.064323 |
description | Wren's library for GPGPU compute shaders, based on WGPU |
homepage | https://gitlab.101100.ca/veda/wrgpgpu |
repository | https://gitlab.101100.ca/veda/wrgpgpu |
max_upload_size | |
id | 1451761 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Wren's library for GPGPU compute shaders, based on WGPU.
This minimal example dispatches a compute shader that squares some values
use wrgpgpu::{include_wgsl, Bind, BindGroup, Device, ShaderArgs, StorageBufferBind};
#[tokio::main]
async fn main() {
let device = Device::auto_high_performance().await;
// Create the shader...
let shader = device.create_shader::<BindGroup<StorageBufferBind<[f32; 256]>>>(ShaderArgs {
label: "Square",
shader: include_wgsl!("simple.wgsl"),
entrypoint: "square",
});
// Create and upload a buffer of data to work on...
let mut n = 0.0;
let buffer = StorageBufferBind::new_init(
&device,
[0.0; 256].map(|_| {
n += 1.0;
n
}),
);
let bind_group = device.bind(&buffer);
// Dispatch the compute shader, this assumes a workgroup size of (256, 1, 1) in the shader...
device.dispatch(&shader, &bind_group, (1, 1, 1));
// Wait until it is complete
while !device.is_complete() {
tokio::time::sleep(Duration::from_millis(1)).await;
}
// Download the squared data
let data = buffer.download(&device);
// do something with the data...
}
And the corresponding gpu code:
@group(0) @binding(0)
var<storage, read_write> buffer: array<f32, 256>;
@compute @workgroup_size(256)
fn square(@builtin(global_invocation_id) global_id: vec3<u32>) {
buffer[global_id.x] = buffer[global_id.x]*buffer[global_id.x];
}