# Tiny WebGPU prototype to Rust game on eight platforms in two months

> Source: <https://saltedcaramelgames.com/blog/loot-hole-rust-threejs-wgpu/>
> Published: 2026-11-22 14:01:58+00:00

**Key takeaway:** Compiling the shared Rust core to WebAssembly for the browser and natively elsewhere let one codebase ship on eight platforms, while a Galaxy A40 benchmark justified keeping three.js's WebGL 2 renderer in the browser instead of wgpu.

[← All posts](https://saltedcaramelgames.com/blog)

# Tiny WebGPU prototype to one Rust game on eight platforms in two months

Loot Hole began as a small WebGPU page and launched on Steam 55 days later as one Rust game that runs in the browser, on Windows, macOS, Linux, Android, iOS, Meta Quest and PC VR. The phone measurements behind each switch, the byte-exact world that co-op and saves depend on, and the AI tooling that made it possible for one person.

Loot Hole is a game about digging up your front yard. It started on 25 September as a small WebGPU page and launched in [Early Access on Steam](https://store.steampowered.com/app/5389630) on 19 November, 55 days after the first commit. In between it moved to WebGL 2, then to a shared Rust core, and that core now runs on eight platforms. three.js draws it in the browser; wgpu draws it everywhere else.

|  | Distribution | Status | 
|---|---|---|
| Browser | desktop and phone browsers, [on Playgama](https://playgama.com/game/loot-hole) | Live | 
| Windows, macOS, Linux, Steam Deck | [Steam](https://store.steampowered.com/app/5389630) | Live, Early Access | 
| Android | [Google Play](https://play.google.com/store/apps/details?id=com.saltedcaramelgames.loothole) | Live | 
| iPhone and iPad | App Store | In TestFlight | 
| Meta Quest, PC VR | Meta’s store, Steam (planned) | Development builds | 

Along the way a phone benchmark kept three.js in the browser after the game had moved to Rust, and co-op and saves came to depend on every build generating the same terrain, down to the byte. I built it alone, with AI models writing most of the code, which took tooling of its own.

## From WebGPU to WebGL 2

I started with Babylon Lite and WebGPU because a small scene with glTF models and shadows came to about 100 KB.<sup>[1](#user-content-fn-x-lite)</sup> I knew WebGPU would leave some browsers out and accepted that for a prototype. From the first day I wanted the game to start before you notice it loading, with the yard and the first swing ready first and everything else streaming in later.

Then a playtest on Poki came back with strong playtime and engagement, which made reaching as many players as possible worth more than WebGPU.<sup>[2](#user-content-fn-s-poki)</sup> Nothing in the game needed it. Its two compute passes, grass culling and the AO’s depth mips, had WebGL 2 versions. So on 2 October the game moved to three.js’s WebGL 2 renderer, behind a thin adapter so the yard could be ported piece by piece. The first working port had 247 KiB of entry JavaScript (gzip); trimming three.js at build time brought it to 202 KiB.<sup>[3](#user-content-fn-x-trim)</sup> Reaching more players is also what later took it to cheap Android phones, the Steam Deck and VR headsets.

## Moving the game into Rust

Terrain went first. World generation, the voxel field, carving, meshing and the sky light became a Rust kernel compiled to WebAssembly, and the same source builds natively. Then the gameplay followed: movement, digging, the economy, progression, saves and every rule the hosts have to agree on. Once Rust was the authority, the TypeScript game was a test oracle for a few days and was then deleted, because keeping it would have meant maintaining two games. Tests now compare against traces Rust records itself.[4](#user-content-fn-x-traces)

By 7 October wgpu drew the real terrain, skinned characters, instancing, shadows and the same look natively, and on 8 October the game ran on a Quest 3. OpenXR takes part in creating the Vulkan instance and device and owns the swapchain images, and the Quest port turned up two bugs whose fixes are now merged in wgpu.[5](#user-content-fn-s-wgpu)[6](#user-content-fn-x-vulkan)

## Why the browser kept three.js

wgpu runs in the browser too, and one renderer and one UI everywhere was tempting. So I measured three builds on an ordinary phone, a Galaxy A40. Each build started six times in balanced order and I took the medians, with the HTTP cache off and the network throttled to 9 Mbps with 150 ms latency.[7](#user-content-fn-x-firstframe)

| Galaxy A40, 10 October | TypeScript + three.js | Early Rust core + three.js | Rust + wgpu | 
|---|---|---|---|
| First game frame | 1.65 s | 1.84 s | 2.82 s | 
| Play button ready | 4.39 s | 4.58 s | 5.84 s | 
| Downloaded by the first frame | 0.40 MB | 0.51 MB | 1.05 MB | 

The early Rust core under three.js (a prototype, with some orchestration still in TypeScript) reached its first frame 0.19 s after the TypeScript build and kept the browser’s DOM UI; the full wgpu build was a second slower. The browser now runs the shared Rust core as WebAssembly under three.js and DOM/CSS. The native builds compile the same core and draw it with wgpu and a native GUI.[8](#user-content-fn-x-backend)

The game has grown since. Today’s build needs about 1.1 MB compressed before its first frame, by the build’s own accounting, most of it the Rust core, and the build fails above 1.5 MB. Everything else streams in once the yard is on screen.

## Measuring on cheap phones

A desktop GPU hides most problems, so I measured on the A40 and a Redmi 9C instead.

- On the Redmi’s PowerVR GPU, any update to a 3D texture that a shader samples stalled the GPU for about a quarter of a second, even a 10 KB layer. The sky light was a 3D texture updated on every dig, so every swing stuttered. A 2D texture array with the blend done by hand removed it.
- Dig debris asked Rust for the field’s gradient once per piece per step, across the WebAssembly boundary. Moving the debris simulation into Rust next to the field took it from 13.8 to 0.45 ms a frame on the A40.<sup>[9](#user-content-fn-x-debris)</sup>
- A review of every terrain stage, under the rule that no output byte may change, took the A40’s terrain worker from 33.7 to 14.1 ms per dig. The hole’s real mesh now appears 37 ms after the swing at the median (53 ms at the 90th percentile).
- On the A40’s Mali GPU every extra framebuffer pass was expensive however small, so the low tier draws straight to the canvas.

## The same world on every build

The Rust port matched the TypeScript terrain exactly, and the requirement stayed after the TypeScript was gone. The kernel avoids fused multiply-add and approximate square roots, and its SIMD build must write exactly the bytes its scalar build writes; a test digs the same pit with both and compares every chunk. Every carve is snapped to a 1/32 m grid first, so a dig is 11 bytes of whole numbers instead of 42 bytes of floats.[10](#user-content-fn-x-grid)

### Co-op sends digs, not terrain

A dig sets each sample of the field to the lower of its current value and the brush’s. Taking a minimum doesn’t depend on order, so two players’ digs give the same ground whichever arrives first, and the host relays guests’ digs in the order it applied them.<sup>[11](#user-content-fn-x-order)</sup> Every two seconds the host sends checksums of recently dug chunks, and if a guest’s checksum differs, the host sends a replacement chunk. The browser connects through Netlib and the native builds through Epic Online Services.<sup>[12](#user-content-fn-s-net)</sup> Before launch, a one-hour session with four bot players and a Steam Deck hosting had no disconnects except the scripted ones; the host averaged 2.1 KB/s of game data up.

### Saves keep the digs

Every save keeps the log the ground is rebuilt from, so losing the log means losing the player’s hole. An earlier size cap on the log could reset a player’s hole after less than two hours of solo drilling in a portal’s 1 MiB save store. The log is now stored in columns, each field delta-coded from the previous record and deflated, and it decodes to the exact original. A four-hour hand-drill log went from 1.37 MB to 133 KB, so the roughly 512 KB of history a 1 MiB portal store has room for now holds about 16 hours of drilling instead of under two. Replay time turned out to matter more than size in deciding when a save should store a snapshot instead. A store full of records would take about 25 seconds to replay at the rate measured on the A40, while a snapshot of the same yard loads seven times faster but needs more room. One portal store still drops the history once it fills completely, and fixing that is next on my list.[13](#user-content-fn-x-saves)

## Keeping the renderers and hosts in step

The lighting, wind, sky and terrain shading are written once in Slang and compiled to GLSL for three.js and SPIR-V for wgpu.<sup>[14](#user-content-fn-s-slang)</sup> Every UI colour, size and shadow lives in one config both sides read. A comparison tool screenshots every screen in both builds and fails when a pair differs more than its entry in a list of accepted differences allows.

On 12 October an audit found that starting a new dig at bedrock did three different things on five hosts, and that Rebirth hung on Android and iOS, because each host had its own copy of those flows. They now live once in shared Rust, Android and iOS share one touch host, and the build fails when 12 or more lines are copied between host crates. A host now only reports platform facts such as the window, input and storage, and Rust makes every gameplay decision.

Keeping the hosts thin also made most of the engine reusable. On 8 November the code another game could use moved into kit crates, with a check that fails when the game leaks into them, and a small fishing game built on the kit ran on the desktop, an iPhone, Android and the web the same day.[15](#user-content-fn-x-kit)

## How one person built it with AI

I designed the game and made the decisions; the models wrote most of the code, and I reviewed it. Most of it was done with Claude Opus 5.5 on high effort, with regular reviews by GPT-6.1 Sol and, for the hardest problems, a few sessions with Claude Fable 5.2 and GPT-6 Astra. Like most people who’ve used it, I found Opus 5.5 a fantastic model to work with, and it gets a lot done.

Review rounds still find significant problems in its implementations, though. Four rounds on one portal’s save code kept finding bugs in the previous round’s fixes, each fix a new flag, until a review asked what was too complicated rather than what was broken, and found about eight pieces of state to delete. Reviews by other models were worth it too. Fable 5.2 and GPT-6 Astra each proposed the columnar dig log on their own.

The Claude Code transcripts on my desktop and laptop hold 315 sessions and 458 subagent runs. Between them they made about 139,000 model calls and 165,000 tool calls, nearly two thirds of those shell commands, from about 3,300 prompts of mine. The logs record 51.2 billion input tokens, 50.8 billion of them prompt-cache hits (the cached context counts again on every call), and 82 million output tokens. At API list prices, input and output together, that would be about $14,700,<sup>[16](#user-content-fn-x-usage)</sup> but I didn’t pay API prices: the work ran on a Claude Ultra subscription, and the 161 Codex runs on top of it on ChatGPT’s $100 Pro plan.

### Gameplay leaking into the browser

Keeping three.js in the browser left a second place where the game could be written, and deleting the TypeScript game didn’t close it. When a feature started on the page, the models tended to write its rules right there beside the three.js code: when the Watch ad offers appear, the opening’s course, the autosave clock. The native builds then missed those rules or grew their own copies, and each had to be moved back into Rust; the last batch moved on 6 November. Keeping them out took repeated corrections, a table in the agents’ rules file saying which crate owns what, and checks. The build rejects TypeScript that doesn’t ship, the page’s wiring file has a line budget, and tests of the page compare against answers Rust recorded.

### Builds that filled the disk

One worktree’s Rust build folder takes 5 to 20 GB, since every target (desktop, WebAssembly, Android, iOS) builds its own, so a few agents in parallel, each in its own git worktree, filled the disk. A shared compile cache didn’t help: sccache keys Rust builds by absolute path and got 0 hits out of 130 across worktrees. What worked was seeding each new worktree with an existing build’s compiled dependencies (a quick build in about 20 seconds instead of 90), a cleanup script for Cargo’s incremental caches, which are never trimmed and had reached 32 GB, and, most of all, running fewer agents at once. Most work now happens in one checkout, with one or two worktrees beside it at most.

### Tools for the models

- Every 3D pack I own, about 55,000 models, is rendered from the front and back and searchable by appearance with SigLIP 2, so “chunky cartoon shovel” finds the right model even when it’s named Tools_03. About 42,000 sound files are searchable by sound with CLAP and ranked by Audiobox’s quality scores, and 2,446 Mixamo animations have measured filters such as looping or in place.<sup>[17](#user-content-fn-s-models)</sup>
- A model viewer draws every model the game ships with the game’s own renderer and flags the triangle budget, flipped faces, the origin and the collision shapes.
- The game films its own trailer. A played session records only its inputs, and the game replays it off screen at 4K with the best quality settings, checking every 30 frames that position, view, coins and tool still match. Gemini scored candidate clips while I edited.<sup>[18](#user-content-fn-x-trailer)</sup>
- To check their work without watching the screen, the models have golden traces that may only be regenerated for an intended rule change, a headless bot harness that plays the real game, the screenshot comparisons, and measurements on real phones.

Everything else lives in a rules file with one lesson for each mistake that cost real time. The most useful one came from the save story above: remove states rather than add them. As the Steam page discloses, some 2D art (the key art, the logo, the interface’s icons) was made with AI image generation and edited by hand; the 3D models, animations, sounds and music weren’t.

Loot Hole is in [Early Access on Steam](https://store.steampowered.com/app/5389630) (Windows, macOS, Linux, Steam Deck, online co-op for up to four), [free in the browser](https://playgama.com/game/loot-hole) and [on Google Play](https://play.google.com/store/apps/details?id=com.saltedcaramelgames.loothole). The upstream fixes this work produced are merged in wgpu and in the Rust Opus decoder opus-rs.<sup>[19](#user-content-fn-s-opus)</sup> For the next game, I’d measure the first frame and a usable game separately, on an ordinary phone and on a second one with a different GPU, before choosing a graphics API.

## Footnotes

1. 
In the same early comparison, the smallest three.js WebGPU sample with its renderer, GLTFLoader and shadows was 863 KB raw (237 KB gzip). Those were renderer samples, not versions of the game, so they explain the first choice and not much more. [↩](#user-content-fnref-x-lite)
2. 
Poki’s playtest of 2 October recorded 731 WebGPU support checks. About 15% failed: 13% of the browsers had no WebGPU adapter and 1.6% no WebGPU API at all. Another 12% only got WebGPU’s compatibility mode. [↩](#user-content-fnref-s-poki)
3. 
Source modules instead of the prebuilt bundle (247 → 214 KiB), the game’s own shaders instead of three’s (207), and a build pass that deletes methods nothing calls (202). That last pass has to leave alone the methods JavaScript or the browser call implicitly. Every patch fails the build loudly if a three.js upgrade moves the line it expects. [↩](#user-content-fnref-x-trim)
4. 
The golden traces are Rust’s own recordings of scripted play. Regenerating one is allowed only for an intended rule change, and the commit has to say what moved and why, so a failing replay can’t be “fixed” by recording the bug. [↩](#user-content-fnref-x-traces)
5. 
wgpu [#10566](https://github.com/gfx-rs/wgpu/pull/10566) (Vulkan’s depth-bias clamp) and[#10568](https://github.com/gfx-rs/wgpu/pull/10568) (a signed`ViewIndex` in Naga’s SPIR-V reader), both merged on 16 October.[↩](#user-content-fnref-s-wgpu)
6. 
The third pull request, capping the device’s Vulkan API version at the instance’s, I closed: I didn’t know that part of wgpu well enough to defend the broader changes it needed. [The bug report](https://github.com/gfx-rs/wgpu/issues/10564) is still open, and creating the instance at Vulkan 1.3 works around it.[↩](#user-content-fnref-x-vulkan)
7. 
“First game frame” is the first animation frame that issued game drawing, not a hardware presentation timestamp. The OS, driver and WebAssembly caches were kept, as a returning player would have them. [↩](#user-content-fnref-x-firstframe)
8. 
I also tried a small custom WebGL 2 backend behind wgpu’s public custom-backend interface. It cut some startup machinery, but its apparent frame-rate lead mostly disappeared once runs were compared at the same device clock state, and it still carried the native GUI into the browser. [↩](#user-content-fnref-x-backend)
9. 
The median frame during repeated debris bursts went from 33.4 to 16.7 ms. The win came from the number of calls across the boundary more than from Rust being faster. [↩](#user-content-fnref-x-debris)
10. 
The centre goes on a 1/32 m grid (a hole moves at most 16 mm along each axis), the radius on 1/1024 m. In play nobody could tell the grid from exact positions, and saves, co-op messages and replays all carve through the same rounding, so live play and a replay can’t disagree. [↩](#user-content-fnref-x-grid)
11. 
The exception is the cleanup that removes clumps of dirt cut loose from the walls: it depends on the ground as it is, so the order of two digs can matter there. That’s what the checksums catch. [↩](#user-content-fnref-x-order)
12. 
Poki’s [Netlib](https://github.com/poki/netlib) (WebRTC) for the browser builds, self-hosted from a fork;[Epic Online Services](https://dev.epicgames.com/docs/epic-online-services) for every native build.[↩](#user-content-fnref-s-net)
13. 
Once players had saves, every format change needed a migration and a frozen fixture from the version before. Where the store allows it, a save also keeps the dug chunks themselves, so only the digs since then are replayed. [↩](#user-content-fnref-x-saves)
14. 
[Slang](https://shader-slang.org) , compiled with one pinned release; a check compares freshly generated GLSL with the checked-in output.[↩](#user-content-fnref-s-slang)
15. 
Before the split I read the Bevy and miniquad source and took shapes from them rather than the dependencies: no ECS, no plugin registry, an explicit lifecycle order. The kit check reads the Cargo metadata and the TypeScript imports and keeps a list of known exceptions that may only shrink; it went from 21 on the day of the split to none. [↩](#user-content-fnref-x-kit)
16. 
Counted from the usage record of every model response in the transcripts, subagents included, deduplicated by response ID. Claude Opus 5.5 made 95% of the calls, priced at $4 per million input tokens, $20 output and $0.20 for cache reads, with cache writes at 1.25 or 2 times the input rate. Cache reads make up 68% of the estimated cost and output 11%. [↩](#user-content-fnref-x-usage)
17. 
[SigLIP 2](https://arxiv.org/abs/2502.14786) for image search,[CLAP](https://github.com/LAION-AI/CLAP) for text-to-audio search, Meta’s[Audiobox Aesthetics](https://github.com/facebookresearch/audiobox-aesthetics) for quality scores.[↩](#user-content-fnref-s-models)
18. 
The bot harness, which plays the real game headless to find problems, filmed some of the shots too. The replay needs the exact build the session was played with, so every capture build is kept. [↩](#user-content-fnref-x-trailer)
19. 
opus-rs [#58](https://github.com/restsend/opus-rs/pull/58) ,[#59](https://github.com/restsend/opus-rs/pull/59) ,[#60](https://github.com/restsend/opus-rs/pull/60) and[#61](https://github.com/restsend/opus-rs/pull/61) , merged on 20 October. The bugs showed up only when the game’s sounds were compared with libopus in 20 ms windows; whole-clip averages hid them.[↩](#user-content-fnref-s-opus)
