WASM GPU Blue Sky

This is a proposal for building a virtual GPU that runs in the browser via WebAssembly, plus a compatibility shim so existing WebGL apps can target it.

1) Goals

2) Architecture choices

There are two good starting paths.

Write the GPU simulator as software components (Rust or C++) and compile to WASM.

Pros:

Cons:

Path B: RTL-first (Verilog/Chisel -> simulator)

Use Verilog or Chisel for RTL, then generate a browser-usable simulator.

Common flow:

  1. Chisel/Verilog -> Verilator C++ model
  2. Compile the C++ model to WASM (Emscripten)
  3. Wrap with JS APIs for command submission and framebuffer reads

Pros:

Cons:

3) A hybrid strategy that usually wins

Use a two-layer model:

This gives:

4) Core simulator design

Define a stable command processor boundary.

For browser responsiveness:

4.1) Validate the toolchain first

Yes, using one or more RISC-V 32-bit cores as an early validation target is a good idea.

It is a clean way to prove the toolchain before committing to the full GPU:

If you already have a simple Hazard-style core plus your own core, that is even better. Two implementations let you separate concerns:

What to test

Keep the first programs boring and deterministic:

Why multiple cores help

Multiple cores are useful if you want to validate more than the compiler:

Suggested sequencing

  1. Get one core running natively.
  2. Compile that same core to WASM.
  3. Add a second 32-bit core and run the same test corpus against both.
  4. Only then start plugging in GPU-specific blocks.

The point is not to build a complete RISC-V product. The point is to establish a trustworthy execution and build pipeline that will carry over to the GPU simulator.

5) Compiling to WASM

If you build in Rust

If you build in C/C++

If you start from Verilator

6) Performance model in browser

Do not chase full hardware realism first. Define quality levels.

Use tile-based raster by default for cache locality in WASM linear memory.

7) How to shim WebGL apps to your virtual GPU

Use an interposition layer that mimics WebGLRenderingContext and WebGL2RenderingContext.

Shim shape

What to support first

  1. Core draw path: createBuffer, bufferData, vertexAttribPointer, useProgram, drawArrays, drawElements
  2. Basic textures: texImage2D, nearest/linear, clamp/repeat
  3. Core blend/depth states
  4. GLSL subset with a translator to your shader IR

Shader handling options

State virtualization

Maintain a WebGL-like state machine inside the shim:

Each draw call snapshots needed state and emits a compact internal packet.

8) Practical compatibility plan

Phase 1:

Phase 2:

Phase 3:

9) Suggested stack

If RTL is a must-have:

10) Risks and mitigations

11) Minimal proof-of-concept target

A good first milestone is:

If you can hit that with command tracing and deterministic replay, you have a real platform to iterate from.

12) Bottom line

Yes, this is achievable. Use software-model-first for speed, keep RTL/Chisel/Verilog as a validation path, and expose a WebGL-compatible shim that translates API calls into your own command stream. That gives immediate browser usability while preserving a path toward deeper hardware realism.