juj/wasm_webgpu

System headers for interfacing WebGPU from C programs compiled via Emscripten to WebAssembly

What it solves

This project provides a system library for C/C++ developers to use WebGPU directly from WebAssembly (Wasm) via Emscripten. It allows developers to write high-performance graphics and compute code in C++ while targeting the official browser-based WebGPU JavaScript API, avoiding the need to write JavaScript glue code manually.

How it works

The library creates a 1:1 mapping between the C/C++ API and the browser's WebGPU JS API. It uses a naming convention (e.g., GPUAdapter becomes WGpuAdapter) and a prefix system (wgpu_*) to expose the JavaScript functions to the WebAssembly side. To ensure maximum performance and minimal binary size, it is implemented in a C-like style without high-level abstractions, making it compatible with the Closure Compiler for further minification.

Who it’s for

C/C++ developers who want to leverage WebGPU for browser-based applications, specifically those who need extreme code size constraints or prefer the official WebGPU specification IDL over the Dawn C++ API.

Highlights

  • 1:1 JS API Mapping: Directly mirrors the browser's WebGPU specification for a predictable transition between C++ and JS.
  • Minimal Overhead: Designed for the smallest possible generated code size and fastest runtime speed.
  • Garbage Reduction: Specifically tuned to minimize the generation of temporary JavaScript garbage during rendering frames.
  • Synchronous API Support: Provides synchronous variants of async functions via JSPI (JavaScript Promise Integration) for easier prototyping.
  • OffscreenCanvas Support: Enables WebGPU rendering from background Worker threads, pthreads, or proxy-to-pthread abstractions.
  • Memory Model Flexibility: Supports 2GB, 4GB, and Wasm64 memory models.

Related

  • Project
  • Project
  • Project
  • Project
  • Project