WebGPU compute shader for audio and graphics (C64 - 8 bit emulation)

I have an old project of mine I’m aiming to resurrect, to make a 3D emulation of a C64. I initially tried using WebAssembly (AssemblyScript) for the emulation, but ran into roadblocks I can’t even recall now, so I switched back to JS, deciding to forego cycle accuracy. But now I’m thinking of trying WebGPU compute shaders for the emulation.

So the idea is that the emulator would simply accept C64 memory buffers for RAM and ROM, passed from JS, and accept user inputs from keyboard and joysticks, then output video (texture) and audio. So, emulating MOS 6510 CPU, MOS 6569 VIC-II (PAL & NTSC) and MOS 6581 SID synced by some kind of cycle-accurate timer for C64 color, dot and system clocks.

Babylon.js would render the interactive 3D “breadbox” C64, 1702 monitor, joysticks, tape & floppy drives.

Anyway, that’s the ambition. I have some of this but there’s a ways to go …

I started playing around with WebGPU compute shaders for audio and migrated JolifantoBambla/webgpu-audio.html into a Babylon PG. It works, but is not integrated with Babylon’s API as well as it could be. For instance, I didn’t find how to get the device from Babylon, create buffers with size & usage or create a compute pipeline with parameters.

Eventually I’d like to have one big shader (even if comprised of separate files for manageability) that takes the aforementioned inputs and executes each chip cycle at the appropriate timing, continually updating audio and video out buffers.

This is way outside my current capabilities, so I have a bunch to learn :slight_smile: Any help or advice is appreciated!

Here’s part of where I got to - working C64 keyboard, accurate keycaps and key mappings, basic video out, minus the static classic “breadbin” and C64C cases and 1702 monitor I’ve modelled but not depicted here.

3 Likes

Here’s a little video of typing on the keyboard and auto switching between classic breadbin keycaps and C64C keycaps.

1 Like

There’s plenty of prior art - lots of other C64 emulators out there, written in various languages (so I’m not flying completely blind here), but few if any in 3D, let alone web 3D … and it’d be cool and nostalgic, which are my primary motivations :sunglasses: :older_man:

The “easy road” would be simply leveraging one of the existing, open-source JS/TS emulators out there, but who wants “easy” :slight_smile: . I’m keen to make it fast and cycle accurate, thus the exploration of WebAssembly and now WebGPU compute.

Regarding compute shaders, you should start with:

https://doc.babylonjs.com/features/featuresDeepDive/materials/shaders/computeShader/

You don’t have to deal with devices or compute pipelines, everything is hidden from you and handled by the ComputeShader class in Babylon.

3 Likes

Thanks @Evgeni_Popov . Yes I’d seen that documentation already, which is why I wanted to try compute shaders in the first place, but I wasn’t sure exactly how to migrate my example to use Babylon’s ComputeShader API. I’ll keep trying.

1 Like

So cool!!

1 Like

This thread went to my favorites as soon as I have seen the title :slight_smile:

3 Likes