NFSU.cc / Devlog

DirectX 9 to WebGPU & WebGL 2: Native BC1/2/3 Textures and a Zero-Waste Draw Pipeline

Translating a 2003 DirectX 9 renderer to WebGPU (with automatic WebGL 2 fallback) is easy to make correct and hard to make fast. Two rendering passes removed the biggest CPU and VRAM bottlenecks.

WebGPUWebGL2DirectX 9S3TCGraphics
Commits: deb8f28 · 00e474c View raw Markdown (.md)

Keeping DXT1/3/5 textures compressed as BC1/2/3 (00e474c)

Need for Speed Underground ships its car liveries, road surfaces, and Olympic City environment textures as DirectX DXT1, DXT3, and DXT5 blocks. Earlier browser builds decoded those blocks to uncompressed RGBA8 on the CPU before uploading them, multiplying VRAM usage by 4x to 8x and stalling frame times during streaming.

Commit 00e474c introduced RN_S3TC end-to-end:

Zero-waste draw pipeline, compact dynamic UBO, and post bindGroup cache (deb8f28)

DirectX 9 games issue hundreds of small stateful draw calls per frame (changing a single transform matrix, light constant, or texture stage). In WebGPU, naively allocating a fresh uniform buffer or GPUBindGroup per draw call creates severe JS garbage-collection pressure.

Commit deb8f28 overhauled host/d3d9.c, host/gpu.c, host/sm1.c, and web/gpu.js:

Files in repo: host/d3d9.c · host/gpu.c · host/sm1.c · web/gpu.js · web/webgpu_gl.js