use std::sync::OnceLock;
pub use wrgpgpu::*;
pub mod bind {
pub use wrgpgpu::bindings::buffer::*;
pub use wrgpgpu::bindings::texture::*;
pub use wrgpgpu::bindings::{Bind, BindGroup, BindGroupData, BindGroups};
}
pub use bind::{BindableImage, PlainTextureBind, RgbaStorageTextureBind, StorageTextureBind};
pub use bind::{StorageBufferBind, StorageReadBufferBind, UniformBufferBind};
static COMPUTE_DEVICE: OnceLock<wrgpgpu::Device> = OnceLock::new();
fn new_compute_device() -> wrgpgpu::Device {
#[cfg(feature = "graphics")]
{
wrgpgpu::Device::from_wgpu(crate::graphics::GRAPHICS_STATE.device.clone(), crate::graphics::GRAPHICS_STATE.queue.clone())
}
#[cfg(not(feature = "graphics"))]
wrgpgpu::Device::auto_high_performance()
}
pub fn create_shader<B: wrgpgpu::bindings::BindGroups>(args: ShaderArgs<'_>) -> ComputeShader<B> {
let device = COMPUTE_DEVICE.get_or_init(new_compute_device);
device.create_shader(args)
}
pub fn empty_bind<B: wrgpgpu::bindings::Bind>(create_info: B::CreateInfo) -> B {
let device = COMPUTE_DEVICE.get_or_init(new_compute_device);
B::new_empty(device, create_info)
}
pub fn init_bind<B: wrgpgpu::bindings::Bind>(data: B::Data) -> B {
let device = COMPUTE_DEVICE.get_or_init(new_compute_device);
B::new_init(device, data)
}
pub fn download<B: wrgpgpu::bindings::Bind>(bind: &B) -> B::Data {
let device = COMPUTE_DEVICE.get_or_init(new_compute_device);
bind.download(device)
}
pub fn bind<B: wrgpgpu::bindings::BindGroupData>(data: &B) -> wrgpgpu::BindGroup<B> {
let device = COMPUTE_DEVICE.get_or_init(new_compute_device);
device.bind(data)
}
pub fn dispatch<B: wrgpgpu::bindings::BindGroups>(
shader: &ComputeShader<B>,
bindings: &B,
workgroups: (u32, u32, u32),
) {
let device = COMPUTE_DEVICE.get_or_init(new_compute_device);
device.dispatch(shader, bindings, workgroups);
}
pub fn is_complete() -> bool {
let device = COMPUTE_DEVICE.get_or_init(new_compute_device);
device.is_complete()
}
#[cfg(feature = "graphics")]
pub fn get_texture_from_binding<T: wrgpgpu::bindings::texture::TextureBindType>(
binding: wrgpgpu::TextureBind<image::RgbaImage, T>,
) -> crate::graphics::Texture {
crate::graphics::Texture::new_from_wgpu(binding.texture)
}