mod launch_shader;
mod shader_cache;
mod wgpu_buffer;
mod wgpu_device;
use core::fmt::Debug;
pub use launch_shader::*;
pub use wgpu_device::*;
use crate::{Buffer, Shape};
pub fn wgpu_clear<T: Default + Debug, S: Shape>(device: &WGPU, buf: &mut Buffer<T, WGPU, S>) {
let src = format!(
"@group(0)
@binding(0)
var<storage, read_write> buf: array<{datatype}>;
@compute
@workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {{
buf[global_id.x] = {zero:?};
}}
",
datatype = std::any::type_name::<T>(),
zero = T::default()
);
launch_shader(device, &src, [buf.len() as u32, 1, 1], &[buf])
}
#[cfg(test)]
mod tests {
use crate::{Buffer, WGPU};
#[test]
fn test_wgpu_clear() -> crate::Result<()> {
let device = WGPU::new(wgpu::Backends::all())?;
let mut buf = Buffer::from((&device, [1, 4, 2, 1, 9]));
buf.clear();
assert_eq!(buf.read(), [0, 0, 0, 0, 0]);
Ok(())
}
}