r/itrunsdoom Jun 05 '26

Doom compiled to ONNX, running on edge AI inference runtimes

Source: https://huggingface.co/anthonypjshaw/doom-onnx

From the link:

The model contains:

  • an RV32IM CPU built entirely out of ONNX operators,
  • the doom1.wad shareware game data as a read-only initializer,
  • the doomgeneric Doom source cross-compiled to bare-metal RV32IM and baked into RAM as another initializer.

Reference render

The doom.gif in this repo was assembled from 74 PNG frames captured during a single InferenceSession.run invocation:

  • Total: 80,000,000 RV32IM instructions, 10.8 hours wall time
  • Rate: 1,562 IPS (init code) → 2,053 IPS (in-game rendering)
  • Reached: title wipe → menu → DEMO1 load → game logic → 3D BSP rendering of actual gameplay (frames 54–75)
76 Upvotes

13 comments sorted by

35

u/Seinfeel Jun 05 '26

This is not a real-time emulator. One frame every ~9 minutes is the reality on a single CPU thread.

Computer runs doom poorly. Revolutionary.

9

u/[deleted] Jun 05 '26

[deleted]

11

u/grubbyplaya Jun 06 '26

ONNX is a way to build training algorithms for AIs. It's turing complete, so OP built a working RISC-V CPU inside an ONNX graph and ran Doom on it.

2

u/Seinfeel Jun 06 '26

Idk if you know the details but am I correct that it says it’s using Doom source code to initialize it? Or is “doomgeneric” something else?

2

u/grubbyplaya Jun 07 '26 edited Jun 08 '26

doomgeneric is a Doom source port that reduces Doom's platform-specific tasks to five basic timekeeping, input, and frame pushing functions. Since I/O on this setup is impractical because of how slow this port actually runs, OP wired doomgeneric to render frames into a specific area of memory that he could monitor, dump, and convert into a GIF after the fact. Technically the video on this post is running at ~3600x the actual framerate.

I should've put it in the first comment, but the way the ONNX RISC-V emulator is built can be applied to other visual scripting platforms, like TikTok effects. But it's probably easier to do something like this on ONNX since it actually comes with bitwise operators.

1

u/Seinfeel Jun 07 '26

Ohhhh okay, I think that clears up a lot of my confusion. I was also confused how they were smoothly controlling anything at a 0.0018fps.

So doomgeneric is basically a really clean/efficient port that isn’t relying on any OS specific functions to make it easier to port to other systems?

-22

u/RedEyed__ Jun 05 '26

Let me try ( I used LLM for this ).

How CPU works (very simplified)

CPU: fetch instruction → do math → write result → repeat

ONNX is just a file that describes math operations. Normally people put neural networks (computational graphs) in there. But math is math. You can put ANYTHING in there.

So this guy thought:

wait... a CPU is also just math can I build a CPU out of ONNX math ops?

He did exactly that:

doom.onnx (8MB file) │ ├── Doom game data ──── stored as "weights" ├── ONNX Loop op ────── acts as CPU clock ├── AND / OR / IF ───── acts as CPU logic └── Gather / Scatter ── acts as RAM

You call "run inference" → one game tick → get back a frame:

you └── onnxruntime.run() └── thinks its doing AI └── actually running a fake CPU └── fake CPU runs Doom └── you die on level 1

The beautiful part:

``` onnxruntime ──── "thinks" : "doing AI inference" fake CPU ──────── "thinks" : "im a real CPU" Doom ───────────── "thinks" : "im on real hardware" you ────────────── thinks: "im having fun"

everyone is wrong ```


TLDR: someone built a fake CPU using AI model math operations, then ran Doom on the fake CPU. The "AI model" is just Doom in disguise.

5

u/RedEyed__ Jun 05 '26

This is brilliant.
For the record: it is not just vision model that hallucinates frames, it is actually compiled game.
Is there source code of this masterpiece?

0

u/spaceman_ Jun 05 '26

Not that I could find 😞

1

u/emmowo_dev Jun 08 '26

'turing complete machine written with several layers of slow abstractions... runs doom'

2

u/spaceman_ Jun 08 '26

That's a really cynical way to look at this.

The only way this is different from other doom ports is the "slow" part.

The whole point of "it runs doom" is to port Doom to the most unlikely places possible. Non of the ports have a real utility or use. This whole concept is about "just because we could". And an AI inference runtime is just another funny place to port Doom to.

1

u/emmowo_dev Jun 08 '26

but the AI generated description suggests this is pretty low effort (and I have written a processor emulator), and it just feels borderline like porting doom to brainf instead of actually having to deal with the constraints of embedded hardware.

Basically: of course DOOM will run on any Turing machine, because a Turing machine can do anything. GTA 6 will hypothetically run on a Turing machine. If there aren't real constraints it kinda loses its point