Skip to content

renzora/wgpu-webxr-webgpu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wgpu + WebXR + WebGPU

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.

How it works

  • 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 the XRGPUBinding, XRProjectionLayer, and XRGPUSubImage APIs that aren't in web-sys yet
  • A wgpu fork adds three things:
    • Device::as_webgpu() — exposes the underlying GpuDevice for XRGPUBinding
    • Device::create_texture_from_webgpu() — wraps XR textures into wgpu with zero copy
    • RequestAdapterOptions::xr_compatible — requests a VR-compatible GPU adapter

Requirements

  • Rust with wasm32-unknown-unknown target (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

Build

$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.wasm

Or 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.wasm

Run

npx 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.

Project structure

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

Browser support

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+

About

first working example of wgpu + WebXR + WebGPU in Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors