30 FPS milestone achieved for high-quality 3D graphics on the ESP32-P4*

· 9 min read

By Phil · building Legitsauce

It happened. The Saucelet, my handheld built around a tiny ESP32-P4 chip, now runs a level from Godot's third-person shooter demo at 30 FPS*. The full level, with the robot running, jumping and turning, on a chip with no graphics card.

*Using machine learning to fine-tune Gaussian splats, NOT triangle rasterization. The 30 FPS is the average over my benchmark clip: 30.4 FPS, and the slowest frame still hits about 27.

Two square frames of the same hallway corner, side by side: red and white chevron barriers, a metal railing and a lit pillar. The left one is the ESP32-P4's Gaussian splat render, the right one is Godot's
Left: the ESP32-P4 board. Right: Godot on a PC. Same camera, robot left out of both. Spot the difference, then remember the left one comes from a chip with no graphics card. Godot TPS demo by Juan Linietsky and Fernando Miguel Calabró, CC-BY 3.0.

Why splats: the pearl necklace trick

Look at a painting of someone wearing a pearl necklace. From across the room the pearls look perfect: round, shiny, glowing. Walk up close and they're just a few splotches of white and grey paint. Your eyes do the rest.

That's how we see. We don't see hard edges and perfect geometry, we see light and colour that blend into a picture. Gaussian splats work the same way. A splat is a soft, coloured blob in 3D space. Pile up tens of thousands of them and they add up to a clean image, the same way the paint adds up to pearls.

Games today get jagged edges. Stair-steps on every railing, shimmer on every thin bar. The real world doesn't look like that. Enter the Gaussian splat.

Why not triangles

Triangles are how nearly every game is drawn, so I started there. I couldn't get the clean look I wanted on this chip. To hit any reasonable frame rate, the edges came out jagged. Yuck. Drawing at a higher resolution and shrinking the picture cleans the edges up, but then the frame rate falls off a cliff (the last splats post has the gory details).

Standard triangle rasterization also doesn't take advantage of modern graphics techniques out of the box. The lighting, the fog, the soft bounced light: all of that is extra work on top of every triangle, and a small chip has no time for extra work.

Why not ray tracing

I tried ray tracing too, with triangles and with ray-cast splats. The speed just wasn't there.

The P4 has a vector unit called PIE. It's a bulk worker: one instruction does the same operation on every lane of a 128-bit register at once. That's fantastic when you have a pile of identical jobs. It isn't built for lots of independent threads each doing their own thing, and that's exactly what ray tracing is. Rays bounce off in all directions, hit different things and finish at different times, so they don't fit the "same operation on every lane" model.

Even casting a single ray per pixel couldn't get anywhere near 20 FPS. My best ray caster on the board managed under 10 FPS, and that was on a tiny 64 by 64 picture.

Teaching splats to look like the level

The splats aren't modelled by hand. They're trained, which is where the machine learning comes in.

Godot renders the level from thousands of camera spots: everywhere the robot can walk, looking every which way, plus close-ups at the walls. Then a GPU on my PC nudges every splat's position, size, shape, colour and opacity until the splats reproduce those real Godot frames. Training happens in two rounds:

  1. As detailed as possible. The first round builds the best-looking level it can, with no limits. It's gorgeous, and about ten times too big for the chip.
  2. Trimmed to what the chip can draw. The second round removes the splats that matter least, a little at a time, and lets the neighbours fine-tune to cover each gap. After every step it checks views it has never trained on, and if a step made things noticeably worse, it backs up and takes a smaller one. It stops at about 33,000 splats, the budget the P4 can draw in real time.

Fitting a whole level into that budget took tons of tuning of the training itself: which cameras to train on, how much the edges count, what to score against, how fast to trim. Here's the same spot of the level as the training improved.

Two square frames of a dark hallway with a cyan sign: on the left the board's early splat level, a mess of dark smears and stray streaks of colour; on the right Godot's clean render of railings, pillars and floor
The early days. Left, the board; right, Godot. Great near where the demo starts, but walk off to this spot and it's modern art. I called it "the abstract painting." Godot TPS demo by Juan Linietsky and Fernando Miguel Calabró, CC-BY 3.0.
The same two frames with the board's middle splat level on the left: the railing and pillars are now there but streaky and smeared, next to Godot's clean render on the right
The two-round method arrives. Train big, then trim. The railing shows up for work, the pillars are still melting. Godot TPS demo by Juan Linietsky and Fernando Miguel Calabró, CC-BY 3.0.
The same two frames with today's splat level on the left: the railing, pillars, wall panels and cyan sign closely match Godot's render on the right, only softer
Today's level, trained against the exact frames it's judged by. About the same number of splats as the first picture, a different world. Softer than Godot, but on a 1.54-inch screen? Chef's kiss. Godot TPS demo by Juan Linietsky and Fernando Miguel Calabró, CC-BY 3.0.

All three run on the same chip at about the same speed. The only thing that changed is the training. The recipe has now reached a quality bar I'm happy with, so it's versioned: every level records exactly which recipe built it, and the fine-tuning goes on from there.

Making it fast

Good looks don't count if the game runs like a slideshow. Real-time speed came from three things:

  • Judicious profiling. I time every stage of every frame on the real board, then go after the biggest number. Guessing where the time goes is almost always wrong.
  • Heavy use of PIE. Splats are the bulk work PIE loves: the same maths on eight splats or eight pixels at once, in its 128-bit registers. Nearly everything that runs per splat or per pixel is written for those eight lanes.
  • Fixed-point maths. Integers standing in for fractions. For this kind of large-scale, real-time work, floating point was always slower than PIE.
The benchmark clip, frame for frame from the board and played at the board's own frame times. The corner shows each frame's FPS and the resolution it drew at. Three frames got lost on the way to my PC and repeat the one before. Godot TPS demo by Juan Linietsky and Fernando Miguel Calabró, CC-BY 3.0.

The clip is the hard part of the level. Walking around it with the D-pad, the board averages about 43 FPS, almost always at the full 240.

What's next

The Saucelet's software 3D rendering tech is proven. A simple 128-bit register and 360 MHz give awesome graphics* (*on a small screen). And that's not even on the new 400 MHz revision of the chip yet.

The hardware

Now on to the hardware. I just started Legit Circuits, where you can follow the Saucelet's hardware journey in a lot more detail: how the controller was built, how the screen attaches to the M5Stack Stamp-P4 (the ESP32-P4 board inside), and so on. Legitsauce stays focused on the games and the software.

The games

The graphics part is about done. Now for the GAME part:

  • Ka'Zhurn: The Unbinding. I'm finishing Act I, with AAA quality as the benchmark. The gameplay is fast, and it has cinematics and audio. (Catch up on it in the latest Ka'Zhurn update.)
  • Godot's full TPS demo. The whole game, not just this level, as a second game benchmark.

Both will be exported automatically* by Squeeze, my exporter that turns Godot games into Saucelet games, and then be playable on the ESP32-P4. The game logic gets the P4's little low-power core, so the two big cores can keep drawing.

*That's the goal. It isn't done yet.

Got a Godot game? Let's put it on a keychain

If you have a Godot game you'd like to see running on the Gaussian splat engine, join me on Discord.

I'm working on launch titles for the Saucelet and I'd love to feature yours. At the very least, you'll help me improve Squeeze, which converts high-quality 3D games into a Gaussian splat version that runs on tiny chips. What I'm after most: games that are AAA quality visually. I want to prove that splat training and rendering can give "PS3+" graphics on a budget device, viewed on a small screen. I'll blog about the process too, which means some nice visibility for you and your game.

Here's my bet: splats are going to upset the triangle pipeline. On tiny devices they look way better than jagged graphics, and I think they should become the new way to do 3D there. Come help me prove it.

Credits

The level and the robot come from Godot's Third Person Shooter demo. Its art is © 2018 Juan Linietsky and Fernando Miguel Calabró, licensed under CC BY 3.0. Many of its original materials were provided by GameTextures.com. Every board picture and the clip in this post are my own Gaussian splat version of that scene, trained from Godot's renders and drawn on the ESP32-P4. The Godot pictures are Godot's own renders of the demo.