About Store Forum Documentation Contact



Post Reply 
WebGPU Browser renderer
Author Message
Fex Offline
Gold Supporter

Post: #1
WebGPU Browser renderer
Play it in your browser (Chrome, Edge, Safari 26+, Firefox on Windows):
https://play.questforterritory.com

[Image: Screenshot-From-2026-11-25-22-22-40.png]

[Image: Screenshot-From-2026-11-25-22-25-59.png]





My fork of Esenthel Engine now runs in the web browser. It has a native WebGPU renderer, and the whole engine is compiled to WebAssembly. The renderer, materials, world streaming, PhysX, animation, RmlUi and the GUI are all the same engine code that runs on Windows, Linux, Android, macOS and iOS.

Quest for Territory, the online fantasy RPG I am building on this fork, is playable this way at the link above: sign in, enter the world and play online. Everything below is the engine itself; the game is just the biggest test case.

How it works
  • WebAssembly. The engine and its third-party libraries (PhysX, FreeType, RmlUi, zstd and the rest) are compiled with Emscripten into one wasm32 module, with real threads (pthreads on SharedArrayBuffer).
  • The engine runs in a Web Worker, not on the page's thread. It draws to an OffscreenCanvas, so a blocking wait inside the engine (a file read, a lock) never freezes the page.
  • WebGPU, used directly. The backend implements the same explicit-GPU interface the Metal backend uses, so most of the shared rendering code needed no browser-specific changes. Engine/Source/Graphics/WebGPU and Platforms/Web are new.
  • No separate shader sources. The engine's existing HLSL is compiled to SPIR-V once, as for Vulkan. A build step translates that SPIR-V to WGSL offline with Tint, Chrome's shader compiler, and keys every result by the SHA-256 of its SPIR-V. 4,706 of the 4,720 shader modules translate. The 14 that don't use features WebGPU lacks, and they report unavailable. One set of shader sources now serves six platforms.
  • The same backend also builds natively on Linux, on Dawn (Chrome's WebGPU implementation). That is where the renderer is debugged: gdb, RenderDoc, Dawn's validation messages, and a tutorial sweep that compares every WebGPU screenshot with Vulkan's.
  • Sound: the engine mixes in software and writes into a ring buffer in wasm memory that an AudioWorklet plays directly. No per-frame messages cross threads, so sound keeps going while the engine thread is busy.
  • Files: /assets is streamed over HTTP, read-only. /data is a writable folder in the browser's private storage (OPFS) for settings and saves, and it persists between visits.
  • Plays well with a strict web host: no eval anywhere, so the page can run under a tight Content-Security-Policy. The page can catch the engine's errors (no WebGPU adapter, device lost, fatal error) and show its own message.

Streaming: the game is never downloaded up front

A browser cannot install a game's tens of gigabytes before you can play, so the engine reads its data from the network as it needs it.
  • Streamed file system. /assets is a WasmFS backend that reads files with HTTP Range requests. A manifest lists every file's size and date, so checking whether a file exists or how big it is costs no request. The 94,000 files of the game mount in under a second.
  • Content store on a CDN. Files are stored compressed in 1 MiB zstd blocks; any block can be fetched alone with a Range request and decompressed in wasm. Every block's SHA-256 is checked before the engine sees it, and the manifest itself is pinned by hash or RSA signature. Sequential reads ramp up from 1 to 16 blocks per request. Blocks are kept on disk in the browser's Cache Storage, so a second visit reads them from there instead of the network.
  • Warm list. The browser records which files a session reads, in order. Later visits fetch those in the background, at low priority, a few hundred MB ahead of the engine. The list is split into phases (boot, sign-in, world...), and the game starts each phase when it gets there. Entering the game world over a 30 ms connection went from 12.2 s to 2.1 s.
  • Texture stand-ins. A material's textures first load only their small mips (256 pixels on the longest edge). The residency manager then raises each texture to the mip level its size on screen calls for, the first time something draws it. Texture files are cut at their mip boundaries in the store, so a stand-in costs one small request. A texture you never see up close is never downloaded whole. This works on every platform but is off by default outside the browser.
  • Fonts on demand. A new RmlUi hook tells the application which characters no loaded font can draw, so big fonts (CJK, Thai, Arabic...) load only when text first needs them.

Multithreading: no frame waits for the network

On a desktop a file read takes microseconds. In a browser it can take a whole round trip, or seconds on a slow link. Anything that waits on a lock while a file downloads stalls every thread behind it, so these engine paths changed:
  • Caches no longer hold their lock during a load. Images, Materials, Meshes, Objects and the other engine caches used to hold one lock for a whole load, nested loads included. Natively that costs milliseconds, but in the browser a background loader could freeze the engine thread for 8-9 seconds. Now the lock only guards the container: a loaded element is returned at once, whatever is loading, and loaders of one cache still never run at the same time. With one build, switched in the URL, the game's first visit went from frames of 8-9 s to no frame over 1 s, downloading the same 442 MB. A native stress test, six threads on three nested caches, measures the longest wait of a "frame" thread at 995 ms before and 0.05 ms after. It is the default in the browser and can be turned on natively.
  • Prefetch. WebPrefetch() asks for files on background threads and returns at once. A later read finds the bytes already there. A material's textures are all requested together as soon as their names are read, so one material costs one round trip instead of five. The shaders every scene needs are fetched the same way at startup.
  • Interface images pop in. RmlUi images load on their own threads and appear when ready, instead of freezing the frame while they download.
  • Sound decoding and opening happen outside the sound lock, so loading a sound never starves playback.
  • A wait log for finding stalls: every wait over a chosen length is logged, on any thread, with what it waited for (which cache lock, held by which thread, or which file it was downloading) and the waiter's stack. A hitch becomes one log line that names its cause.

Browsers
  • Chrome and Edge on Windows, macOS and ChromeOS; Safari 26 or newer; Firefox 141 or newer on Windows.
  • Played on the live site in Chrome (Linux, Windows), Firefox 160 (Windows) and Safari 27.2 (macOS).
  • Linux: Chrome works, though on some GPUs only after turning on WebGPU in chrome://flags. Firefox for Linux does not ship WebGPU yet.
  • The host must send two headers (Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy) for wasm threads to work. The fork's local test server sends them, and Cloudflare Pages can.

What works in the browser

Renderer
  • The deferred renderer with the engine's PBR materials
  • Cascaded shadow maps, local lights, day/night lighting, sky with a dynamic ambient
  • Volumetric and object clouds, ocean and mirror water, particles, decals
  • Post effects (TAA, depth of field, motion blur, bloom, ambient occlusion...)
  • RmlUi (HTML/CSS UI) and the engine's own GUI
  • Bind groups are cached and per-draw buffers use dynamic offsets: in the Benchmark tutorial this cut the engine's CPU time per frame from 5.5-7.3 ms to 1.5-2.9 ms

Everything else in the engine
  • PhysX 4.1, animation, world streaming, terrain, pathfinding, saving and loading
  • Networking: the engine's downloads (HTTPS) go through fetch(). The game connects to its own servers through WebTransport, in its own code.
  • Sound through Web Audio
  • Mouse (pointer lock), keyboard, wheel, copy and paste with the system clipboard; the browser's own shortcuts (F1, F3, F5, Ctrl+F/S/P, Firefox quick find) stay off while the game has the keys
  • Fullscreen and a page-sized canvas

Tutorial coverage: 207 of the 214 tutorials run in the browser with 0 WebGPU validation errors and match Vulkan. The other 7 need a game server or a running Titan Editor, on Vulkan too. One known difference is still open: the Holographic Images tutorial.

Testing tools: the fork includes scripts that drive a real browser from the command line: headless Chrome (over the DevTools protocol) and Firefox (WebDriver BiDi). Each one runs a page, prints the engine's console and WebGPU stats, takes screenshots and records CPU profiles. A local server stands in for a CDN with added latency and a bandwidth limit, so loading can be measured the way a player experiences it.

What is not supported (yet)
  • Things WebGPU itself does not have: mesh shaders (meshlets, GPU grass), hardware ray tracing (RT shadows, reflections, GI), tessellation, bindless textures. The engine reports them unavailable and takes its classic paths: materials are bound one by one, the world is drawn without GPU culling.
  • Dynamic GI and async compute: Vulkan (and partly Metal) only.
  • 14 shader modules: 9 write float storage textures that core WebGPU only allows for 32-bit single-channel formats, 4 are ray-query GI kernels, and Tint cannot parse 1.
  • Reading a GPU texture back on the CPU synchronously is impossible in a browser. The engine reads CPU pixels from the file instead.
  • No EFX reverb or HRTF: those come from OpenAL Soft, which the browser build does not use.
  • Exit() in a browser is a modal alert; a page should take the engine's errors itself (above).
  • The Titan Editor does not run in the browser. Content is still authored on Windows/Linux.
  • Shader generation still happens on Linux. The browser build only translates and packs the result.

Available in this fork:
https://github.com/DrewGilpin/EsenthelEngine
(build instructions in README.md under "Browser — WebGPU", details and the full list of traps in docs/web-webgpu.md)
11-26-2026 04:33 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: WebGPU Browser renderer
oh wow!
11-26-2026 04:53 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: WebGPU Browser renderer
I checked some of your codes:

I see that the engine had problem with DivCeil DivRound DivFloor overflowing, I just fixed that.

Also I saw your comments:
Code:
File    Change
Engine/Source/Memory/Cache.cpp (_Cache::require, ~line 321)    When _mode==CACHE_EXIT and the asset is missing, switch the cache to CACHE_DUMMY and emit a LogN with the missing file/path, instead of calling Exit(). Subsequent require() calls on the same cache hand back dummy objects so the caller keeps running.
Engine/Source/Memory/Cache.cpp (_Cache::get, ~line 222)    On non-Windows, normalize Windows-style \ separators to / on the incoming file parameter before cache lookup. Material files baked by the Windows Editor contain paths like Tex\foo as literal strings (via File::getStr(), not via MergePath/tailSlash), so without normalization the cache never gets a hit — creates a new dummy every frame and the process bloats.
Engine/Source/Memory/Cache.cpp (HelperPath, ~line 211)    Same normalization, applied to the constructed helper path. Redundant with the MergePath fix below but kept as a safety net.
String — platform-aware path separators

File    Change
Engine/Source/Misc/String.cpp (MergePath, ~lines 600 + 606)    Use PLATFORM('\\', '/') instead of always appending '\\', so directory-component joins produce Linux-native paths that match the real filesystem layout.
Engine/Source/Misc/String.cpp (Str::tailSlash + Str8::tailSlash, ~lines 3653 + 3664)    Same treatment — the engine's trailing-slash helper now appends / on Linux. Many callers (Game::World.dataPath() etc.) were producing paths with backslashes that then failed cache lookups.
why? engine already handles that internally, and it shouldn't be needed.
check this code:
Code:
Images.mode(CACHE_ALL_DUMMY);
   ImagePtr a, b;
   a.require("test\\a.img", u"D:\\");
   b.require("test/a.img", u"D:/");
   Bool same=(a==b);
same is true.

_Cache::findElm
_Cache::findExact
use 'ComparePath' function which handles slashes in smart way.

In the engine you can use both \ or /, it doesn't matter, it should always work well.
11-26-2026 12:16 PM
Find all posts by this user Quote this message in a reply
Fex Offline
Gold Supporter

Post: #4
RE: WebGPU Browser renderer
Thanks for looking at this, and you are right about the engine.

Slashes

I built three variants of my fork and ran each one (Linux, release, my game's servers and client on top):
  • A: My fork as it was (names rewritten in _Cache::get / HelperPath, '/' appended by MergePath and tailSlash)
  • B: your behaviour (no rewriting, '\' appended)
  • C: no rewriting, but '/' still appended by MergePath and tailSlash

A small test program, with your snippet in it, passes on all three:

Code:
Images.mode(CACHE_ALL_DUMMY);
ImagePtr a, b;
a.require("test\\a.img", u"D:\\");
b.require("test/a.img" , u"D:/" );   // a==b: true, with and without my changes

It also asks for 200 names in 6 spellings each (slashes mixed in the name and in the path) and gets 200 cache elements, checks that missing files in CACHE_DUMMY make one placeholder each however often they are requested, that FExist / File::read / FileFind / FCopyDir accept '\' on Linux, and that every file in a folder of the mounted paks is found with either slash. All of that works on your code. So the rewriting in the cache was never needed, and I have removed it from my fork.

The explanation in my README ("without normalization the cache never gets a hit") was simply wrong. It came from a debugging session when I first got a headless physics server running, and nobody reverted the change to see if the problem came back. What that session most likely saw is ordinary: on a physics server the PhysBody cache shows 217 requests, 0 hits and 57 elements with or without the rewriting, because areas unload and reload. Names with '\' do exist in my data: material files that the Windows editor wrote in 2020 store their textures as "Tex\<id>", which gives 25 such texture requests per client session. All 25 load fine without any rewriting, on Linux and in the browser.

The one thing I kept

MergePath and tailSlash still append '/' instead of '\' on non-Windows platforms in my fork. That is not for the engine. It is for my own game code, which hands engine-built paths to code that is not the engine's (std::filesystem, mostly). On Linux '\' is an ordinary file-name character there. With your tailSlash, DataPath() ends in "GameData\" and my content check then looks for "GameData\/<file>", fails, and the servers refuse to start. That is variant B, and it is the only thing that broke.

So this is my problem, not the engine's: calling UnixPath() at those call sites would fix it just as well. Nothing needs to change upstream. I have rewritten the README section so it says this instead of blaming the cache.

Cache::require switching CACHE_EXIT to CACHE_DUMMY

That one is intentional but blunt. It exists so a headless server keeps running when an asset that needs a GPU cannot be loaded. As written it switches the cache on the first require(), whether the file is missing or not, which the README did not say (it does now). Setting the mode from the application, as I already do for Images, is the cleaner way, and I will probably move to that.

DivFloor / DivCeil / DivRound

Thank you for that fix. I had only fixed DivCeil on my side. I copied your versions (d7a6d78, plus the call sites of b76f71c that exist in my fork) and checked them against 128-bit arithmetic: every x in -400..400 with y in 1..400 for the four types, plus the limits of each type, about 2.9 million comparisons under the undefined-behaviour sanitizer, with no failure. The same test over the old functions fails 347 cases, for example DivFloor(INT_MIN, 32) returning +67108863. It builds on Clang (Linux, Android, macOS, iOS, wasm) and on MSVC.
11-26-2026 03:27 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #5
RE: WebGPU Browser renderer
Dude, you do not have paste your LLM chat in here.. you can just talk yourself..
11-26-2026 08:44 PM
Find all posts by this user Quote this message in a reply
Post Reply