Expand description
WebGPU (wgpu) compute backend for the OxiPhysics GPU acceleration layer.
This module provides WgpuBackend which implements ComputeBackend using
the wgpu crate for cross-platform GPU compute (Vulkan, Metal, DX12, WebGPU).
§Feature flag
This module is gated behind the wgpu-backend Cargo feature:
[dependencies]
oxiphysics-gpu = { features = ["wgpu-backend"] }When the feature is disabled the module compiles to an empty stub. This allows
the crate to compile without the wgpu dependency on platforms or toolchains
where GPU support is not required.
§Enabling the dependency
To activate the wgpu backend, add wgpu to the crate’s Cargo.toml:
[features]
wgpu-backend = ["wgpu"]
[dependencies]
wgpu = { version = "0.20", optional = true }§Architecture
WgpuBackend
├── wgpu::Device / wgpu::Queue ← GPU device & command queue
├── Vec<WgpuBufferEntry> ← Registered GPU buffers
│ ├── wgpu::Buffer (device memory)
│ └── size, usage flags
└── ShaderRegistry ← Compiled WGSL compute shaders
Compute pipeline:
write_buffer → [upload via staging] → dispatch(kernel) → [readback via staging] → read_buffer§Usage (when feature is enabled)
ⓘ
use oxiphysics_gpu::compute::wgpu_backend::WgpuBackend;
use oxiphysics_gpu::compute::ComputeBackend;
let backend = WgpuBackend::new_async().await?;
let handle = backend.create_buffer(1024);
backend.write_buffer(handle, &vec![1.0_f64; 128]);
// ... dispatch kernel ...
let data = backend.read_buffer(handle);Modules§
- real
- Real wgpu compute backend, enabled only with the
wgpu-backendfeature.
Structs§
- Wgpu
Backend - WebGPU compute backend.
- Wgpu
Buffer Handle - Opaque handle to a GPU buffer allocated by a
ComputeBackend. - Wgpu
Device Info - Information about the GPU device selected by the wgpu adapter.
Enums§
- Wgpu
Init Error - Error returned when the wgpu backend cannot be initialised.
Constants§
- WGSL_
BVH_ TRAVERSAL - WGSL source for parallel BVH ray traversal.
- WGSL_
PARALLEL_ SCAN - WGSL source for a parallel prefix sum (exclusive scan) kernel.
- WGSL_
SPH_ DENSITY - WGSL source for a simple SPH density kernel.