These are some advanced optimization tricks I've discovered while @stonerl and I have been cooking the full-speed gameboy emulator. These are not the typical tips for optimizing games you can find elsewhere, so if you…

78 points•ibobev•about 2 months ago•14 comments•

14 comments

boricjabout 2 months ago
That reminds me of some of the tricks I've used while tinkering with a voxel space rendering tech demo on the PlayStation.

The quirks of that console for this is that the CPU takes a 6 cycle stall on any read from main RAM (it's not even stall-on-use) and doesn't have a data cache. That would make it a very poor fit for this, so I had to improvise a bunch of tricks to reclaim performance:

- Made all of my hot loop fit within one function, so that it fits entirely in the 4 KiB direct-mapped instruction cache (so less than 1024 instructions)

- Wrote a C++ template that can trampoline a function call into the 2 KiB scratchpad

- Used the rest of the scratchpad for a CLUT table because it doesn't stall on read

- Used the GTE to transform the N set of coordinates while the CPU stalls fetching the N+1 set of heightmap data

- Figured ways to abuse the GTE into transforming more points per instructions than it theoretically can, taking advantage of simplified formulas compared to real 3D projection

- Write the rectangle primitives straight to the GPU registers instead of going through a display list

It's such an abuse of the PlayStation that PCSX-Redux and DuckStation disagree on its performance by up to a factor of two. I should finish it someday and see how it runs on real hardware...

omoikaneabout 2 months ago
These optimizations are part of what makes Playdate development fun, since they are more rewarding on the Playdate than on other platforms with higher specs.

(If you are the kind of person that finds optimizations fun, of course. There is a puzzle solving element of optimizing code that I really enjoy.)

nxobjectabout 2 months ago
The tips about laying out and carefully segmenting code are a blast from the past!
ahartmetzabout 2 months ago
The tips about mitigating unpredictable performance due to minor layout changes are unfortunately up to date.
maxlinabout 2 months ago
I just wish someone released a clone. The "computer" is worth like 5$. I've enjoyed programming and porting my 3D game engine to 20$ ESP32 devkits among others, and am looking for more "crazy" platforms. But I don't even want to touch playdate due to its pricing stance, even though my office has an unused one in the store room.
Wowfunhappyabout 2 months ago
Do you mean the SOC costs $5? The Playdate comes with a screen, buttons, battery, OS, and 24 (admittedly small-ish) pack-in games.

I haven't looked into how that all nets out, but when I think about how much a Raspberry Pi costs by itself vs the Pi + a case, screen, and peripherals... I don't know, I can see how you'd end up around $230.

Heck, even just a set of Switch 2 Joycons costs $100.

maxlinabout 2 months ago
Your math is off ~10x. The devkits I've developed for are literally 20-30$, both in 3.5 inch screen format, or smartwatch format, with a case, touchscreen, buttons, battery, realtime OS, RTC, wifi, tons of GPIO's etc. Only hardware things playdate has on top is marginally higher build quality, the swivel (that most games don't use) 10-20MB more RAM. Their decision to have a greyscale screen also saves them money, instead of a common full color one like those 30$ devkits have.

So it is beyond obvious that Playdate's price does not even closely match their bill of materials.

Even if you went up in power to a full Linux machine with 1GB+ of ram, there are obvious examples of devices like that like the RG3588 class. I have one, and it works nicely as a linux box running any software one can get running on aarch64 linux. Mine is relatively fancy and with postage cost me ~100$, but you can get a more "basic" one that is still way beyond Playdate on a hardware level, for about 40$.

What playdate has is a walled garden. I don't like walled gardens. Especially this far from release.

You comparing to Nintendo's first-party joycon pricing, I'm not sure you understand how deep walled gardens can be.

Read the full thread on Hacker News →

Related stories