cljrs kernels running in your browser
This page runs cljrs GPU kernels directly on your GPU via WebGPU.
The exact same defn-gpu-pixel source compiles to WGSL once,
and that WGSL is loaded here and dispatched by the browser's WebGPU
implementation. Same kernel, same output, native and web.
Requires a WebGPU-capable browser (Chrome 113+, Edge, Safari TP, or recent Firefox Nightly with the flag). On unsupported browsers you'll see an error below and the static video gallery on Demos still works.
Parameters
Side-by-side
Left: the cljrs source (~50 lines). Right: the WGSL it compiled to. The WGSL is what your browser is running right now.
cljrs source
loading…
compiled WGSL
loading…
How it works
-
The
defn-gpu-pixelin the .clj file is parsed by the cljrs reader, macro-expanded, and run through the GPU DSL emitter (src/gpu/emit.rs), producing a WGSL compute shader. - That WGSL is saved as a static asset alongside this docs page. No runtime cljrs required in the browser for GPU demos.
-
JavaScript (
_gpu_runner.js) loads the WGSL, creates a WebGPU pipeline, dispatches one workgroup per 8×8 pixel tile, reads back the framebuffer, and draws it to a canvas. -
The native app (
cargo run --features gpu-demo --bin gpu-demo) does the same thing viawgpu. different runtime, same kernel.
Next: in-browser defn-gpu-pixel . edit the cljrs source in
the live REPL, compile to WGSL in-browser, re-upload to WebGPU, all
without a round-trip. Blocked on running the MLIR/GPU pipeline in wasm.
For now, precompiling is simpler and tells the same story.