The DamagedHelmet glTF model drawn by Eskiu GPU

Eskiu GPU: compute, rendering,
3D models and ML over WebGPU

Eskiu GPU is the Eskiu language's package for the GPU. It is built on wgpu-native, so one API runs on Metal, Vulkan and DirectX 12, with shaders in WGSL. It loads glTF, GLB and OBJ models and draws them with physically based shading and animation, and it runs transformer inference and training on the GPU.

twice.esk
import <io>;
import <gpu>;

string twice = "@group(0) @binding(0) var<storage, read_write> v: array<f32>;\n"
    "@compute @workgroup_size(64)\n"
    "fn main(@builtin(global_invocation_id) id: vec3<u32>) { v[id.x] = v[id.x] * 2.0; }\n";

Result<int, string> run() {
    float[256] data;
    for (i in 0..256) data[i] = (float)i;
    Gpu gpu = gpu_open()?;
    defer gpu.release();
    GpuBuffer v = gpu.storage(&data, sizeof(data))?;
    defer v.release();
    GpuKernel k = gpu.kernel(twice, "main")?;
    defer k.release();
    k.bind(0, &v);
    k.dispatch(4, 1, 1)?;
    v.read(&data, sizeof(data))?;
    printf("%.1f\n", (double)data[255]);
    return Ok<int, string>(0);
}

v0.1.0, MIT licensed, early release. Part of the Eskiu project.


What the package covers

Everything from a single compute dispatch to an animated glTF model in a window, with the idiomatic layer on top and the raw WebGPU C API underneath.

Compute

Storage buffers, WGSL kernels and dispatches, with results read straight back into Eskiu memory.

WGSL

Rendering

Textures, samplers, depth buffers, vertex, index and uniform buffers, render pipelines and passes, to an offscreen texture or a window opened over SDL3.

3D models

Loads glTF 2.0 (.gltf and .glb) and Wavefront OBJ with MTL materials, and draws either with physically based shading, normal maps, alpha modes, skinning and animation.

glTFGLBOBJ

Machine learning

Transformer inference from GGUF, safetensors or llama2.c files, with quantized Q4_0 and Q8_0 kernels, and network training with automatic differentiation and Adam.

Images in pure Eskiu

PNG and JPEG (baseline and progressive) decoding written in Eskiu itself, with sRGB and mipmapped textures.

Errors as Result, and the whole API underneath

Every call that can fail returns a Result with the WebGPU validation message, and a WGSL error comes with its line and column. Drop down to all of webgpu.h through <gpu/raw> whenever you need to.

3D models, the format of AR and VR

glTF and GLB are how 3D content moves between tools, the Editor and ViroReact apps. Eskiu GPU loads them, with their materials, skins and animations, and draws them with glTF's metallic-roughness model.

The DamagedHelmet glTF model drawn by Eskiu GPU's model rendererA textured cube rendered offscreen by the Eskiu GPU test suite
Rendered by Eskiu GPU. DamagedHelmet by theblueturtle_ (CC BY 4.0), from the Khronos glTF sample assets.
model.esk
Gltf data = model_load("helmet.glb")?;   // or a .gltf, or an .obj
defer data.free();
GpuModel model = gpu.model(&data, surface.format)?;
defer model.release();

// every frame
data.animate(0, seconds);
model.update(mat4_identity());
GpuCamera cam = model.camera(aspect);
GpuPass pass = gpu.pass(frame.view, GpuColor{0.1, 0.1, 0.1, 1.0}, &depth);
model.draw(&pass, &cam);
pass.end()?;

Not supported yet: morph targets, image-based lighting and shadows, Draco and meshopt compression, and KTX2 textures.

Machine learning on the GPU

The Llama 2 example records the forward pass once and replays it as one compute pass per token, with matrix-vector products in f32, f16, Q8_0 and Q4_0. Its outputs match llama2.c byte for byte, and llama.cpp and Hugging Face transformers token for token, on the prompts tested.

ModelEskiu GPUReference
stories110M (llama2.c, f16)350 tokens/sllama2.c on the CPU: 22 tokens/s
TinyLlama 1.1B Q4_0 (GGUF)178 tokens/sllama.cpp (Metal): 260 tokens/s
Llama 2 7B Q4_0 (GGUF)45 tokens/sllama.cpp (Metal): 58 tokens/s

Apple M4 Pro, greedy decoding. Figures from the repository README.

mnist.esk
NnGraph g = gpu.nn_graph(100)?;
NnVar x = g.input(784);
NnVar labels = g.labels();
NnVar h = g.relu(g.bias(g.matmul(x, g.param(784, 128, 0.05)), g.param(1, 128, 0.0)));
NnVar logits = g.bias(g.matmul(h, g.param(128, 10, 0.125)), g.param(1, 10, 0.0));
NnVar loss = g.cross_entropy(logits, labels);
g.backward(loss)?;   // records the gradients of every operation
g.adam(0.001);       // and the optimizer step

The MNIST example trains a two-layer network to 97% test accuracy in three epochs, about 0.4 s each, and saves weights as safetensors that PyTorch loads with the same accuracy.

Where it runs

The WebGPU modules run on desktop today. The plain Eskiu modules already run everywhere Eskiu does, and phone and browser support for the GPU modules is planned.

macOS arm64
Metal
Linux x86-64
Vulkan
Windows x86-64
DirectX 12, Vulkan
iOS, Android, WebAssembly
Plain Eskiu modules today; GPU modules planned

Get started

The package needs wgpu-native 29, and SDL3 for windows. On macOS,brew install wgpu-native sdl3 covers both. Then add it to an Eskiu package (Eskiu 0.12 or newer).

Add the package

$eskiuc add gpu --git https://github.com/eskiu-lang/gpu --rev v0.1.0

Then build with eskiuc build -L/opt/homebrew/lib, pointing -L at the directory that holds libwgpu_native. On Linux and Windows, wgpu-native comes from its release archives.

Learn more

  • GitHub →
    Source, module reference, tests and issues. v0.1.0, MIT.
  • Examples →
    A triangle, a textured cube, a glTF and OBJ viewer, Llama 2 and MNIST.
  • The Eskiu language →
    The systems language behind ReactVision's AR engine.

Frequently asked questions

What is Eskiu GPU?
Eskiu GPU (the gpu package) is a library for the Eskiu programming language that runs compute kernels and draws on the GPU. It is built on wgpu-native, so one API runs on Metal on macOS, Vulkan on Linux and DirectX 12 on Windows, with shaders written in WGSL. It covers compute, rendering, glTF and OBJ models, image decoding, and machine learning inference and training. It is MIT licensed.
How does it relate to ReactVision?
Eskiu is ReactVision's own systems language, already in production inside the ViroCore engine behind ViroReact. Eskiu GPU is part of the Eskiu project and a ReactVision Labs project: research into GPU rendering, 3D model loading and on-device machine learning in Eskiu. It is not a ReactVision product commitment, and you do not need it to build with ViroReact or the Editor.
Which 3D model formats does it load?
glTF 2.0, as .gltf files with external or embedded buffers or as .glb, and Wavefront OBJ with its MTL materials and textures. The glTF loader reads meshes, PBR materials, the node hierarchy, skins and animations, and supports KHR_mesh_quantization, KHR_materials_unlit and KHR_materials_emissive_strength. Morph targets, image-based lighting, shadows, Draco and meshopt compression, and KTX2 textures are not supported yet.
Does it run on iOS, Android or the web?
Not yet for the WebGPU modules. Today they run on macOS arm64, Linux x86-64 and Windows x86-64. The plain Eskiu modules (math, image decoding, glTF, OBJ, GGUF and safetensors loading) already work on every target, including iOS, Android and WebAssembly. Phone and browser support for the GPU modules is planned.
How fast is the machine learning?
On an Apple M4 Pro with greedy decoding, the Llama 2 inference example runs Llama 2 7B Q4_0 at 45 tokens per second, against 58 for llama.cpp on Metal, and its outputs match llama2.c byte for byte and llama.cpp and Hugging Face transformers token for token on the prompts tested. The MNIST training example reaches 97% test accuracy in three epochs.
How do I install it?
Install wgpu-native 29, and SDL3 if you want windows (brew install wgpu-native sdl3 on macOS). Then, in an Eskiu package on Eskiu 0.12 or newer, run eskiuc add gpu --git https://github.com/eskiu-lang/gpu --rev v0.1.0 and build with eskiuc build, pointing -L at the directory that holds libwgpu_native.

Follow the work

Eskiu GPU is early and moving fast. Star the repository, try the examples, and bring questions and bug reports to the team.