First working example of wgpu (Rust) rendering in VR via WebXR and WebGPU — no WebGL, no texture copies.
Renders a spinning cube with a ground plane in stereo VR. wgpu renders directly into the XR compositor's textures through a small fork that exposes the underlying GPUDevice and allows wrapping external GPUTexture objects.
- wgpu compiles to WASM and targets the browser's WebGPU API
- WebXR manages the VR session, head tracking, and provides per-eye projection textures
- Custom
#[wasm_bindgen]bindings bridge theXRGPUBinding,XRProjectionLayer, andXRGPUSubImageAPIs that aren't inweb-sysyet - A wgpu fork adds three things:
Device::as_webgpu()— exposes the underlyingGpuDeviceforXRGPUBindingDevice::create_texture_from_webgpu()— wraps XR textures into wgpu with zero copyRequestAdapterOptions::xr_compatible— requests a VR-compatible GPU adapter
- Rust with
wasm32-unknown-unknowntarget (rustup target add wasm32-unknown-unknown) wasm-bindgen-cli(cargo install wasm-bindgen-cli)- Chrome or Edge with a VR headset connected via SteamVR or Horizon Link
- Chrome flags enabled:
chrome://flags/#webxr-incubations
$env:RUSTFLAGS='--cfg=web_sys_unstable_apis'
cargo build --target wasm32-unknown-unknown --release
wasm-bindgen --target web --out-dir pkg target/wasm32-unknown-unknown/release/wgpu_webxr_example.wasmOr on Linux/macOS:
RUSTFLAGS='--cfg=web_sys_unstable_apis' cargo build --target wasm32-unknown-unknown --release
wasm-bindgen --target web --out-dir pkg target/wasm32-unknown-unknown/release/wgpu_webxr_example.wasmnpx serve .
Open http://localhost:3000/web/ in Chrome. You'll see a spinning cube on a canvas. If a VR headset is detected, an "Enter VR" button appears.
src/
lib.rs — WASM entry, flat + XR render loops
renderer.rs — wgpu pipeline, cube + ground mesh, MVP rendering
shader.wgsl — vertex/fragment shader with diffuse lighting
xr_bindings.rs — wasm_bindgen bindings for XRGPUBinding, XRProjectionLayer, XRGPUSubImage
web/
index.html — UI with canvas and Enter VR button
| Platform | Status |
|---|---|
| Chrome/Edge + SteamVR or Horizon Link | Working |
| Quest Browser (standalone) | No WebGPU+WebXR binding support yet |
| Firefox | No WebXR+WebGPU binding support yet |
| Safari + Vision Pro | Untested, may work with Safari 26.2+ |