PCSX2 is an open-source PlayStation 2 emulator that allows users to play PS2 games on modern hardware. The emulator is remarkable for simulating the complex architecture of the PS2, which includes the Emotion Engine CPU, Graphic Synthesizer, and specialized subsystems. The emulator just hit a major milestone with the release of PCSX2 version 2.0. The release brings many changes including a QT-based interface, big picture mode, auto-selection of graphics, APIs, and native support for macOS. Tello Krinkle is a developer for PCSX2 who ported the emulator to macOS, among other contributions.
In addition to his work on PS2 emulation, he has also worked on Dolphin, which emulates the Nintendo GameCube and Wii. Tello joins the podcast with Joe Nash to talk about how he got started in emulation, the PS2 architecture, the challenges of rendering PS2 games on modern GPUs, and more. Joe Nash is a developer, educator, and award-winning community builder who has worked at companies including GitHub, Twilio, Unity, and PayPal. Joe got his start in software development by creating mods and running servers for Garry's Mod, and game development remains his favorite way to experience and explore new technologies and concepts. Welcome, Tello. How are you doing today? Pretty good. I'm happy to be here. Wonderful. So I want to start by asking you, we've spoken to folks in the emulator scene before, and it seems people come in to this whole thing from many different varied paths. How did you get started building emulators? Yeah, I think my path is probably maybe one of the weirder ones. Well, to start, I guess I looked up a lot to emulators and emulator development when I was younger. And so for a long time, I kind of wanted to try to work on the dolphin emulator. And I never ended up getting around to it for a long time. But then I guess after graduating college, I took a part-time job for a while and I had some extra time. And I was like, maybe I can work on an emulator.
I, at that point, kind of looked around, and I was like, hey, look, it would be cool to the PCSX2 emulator. At the time, it didn't support macOS, and I was using macOS as my main operating system at the time. I guess I still am at the moment. And I was like, it would be cool to have a Mac version of that, right? And so that was just kind of my plan. I was like, hey, I'll just, I mean, I knew they previously had a macOS interface. Like, they had old builds from probably like, you know, four or five years ago, maybe even older at the time. And so I was like, oh, well, you know, I'll just, you know, it must be at least somewhat.
Compatible? Not compatible, but like, you know. There's some legacy of it working on that form there. Yeah, exactly. And I was like, okay, well, we'll just try to get it working. And yeah, so I started that. It turns out it wasn't too bad to at least get like, you know, the interface showing up, not the actual emulation or anything, but just like, oh, you know, we want to have an interface. There were some minor bugs with some of the, at the time, on Windows, they were using a mixture of WX widgets and like direct Win32 stuff. And then on Linux, they used WX widgets with where Windows had Win32 stuff, they used GTK. And so I just like, there is a GTK version for Mac OS. It's not amazing. It's kind of.
Terrible, actually, but it does technically work. And so I just used that on macOS for the initial build, and we got some Windows working. And from there, well, there were two things that mainly stood out. The first is that macOS, so at the time, PCSX2 supported two graphics APIs, OpenGL and DirectX 11. Yeah, 11 at the time. And macOS had, obviously, DirectX 11 is just a Microsoft thing, so no one else supports that. And then OpenGL, macOS had kind of abandoned it probably about three years before and completely stopped.
updating it to stay up to date with the latest features and stuff. And so there were a whole bunch of PCSX2 had workarounds for lack of various features, and a whole bunch of them had been deleted from the emulator about four years before. My first attempt, and I had at this time no graphics programming experience whatsoever, was to attempt to undo the deletion of all of these fallback paths for lack of various features. So yeah, so I was like, oh, well, just PCSX2, as pretty much all emulators are pretty much, and software projects in general are under a system called version control, where every change to the emulator is kind of tracked as like a sequence of changes. And so you can go back to the old one and just be like, can I just undo that one, please? So I started by just trying to undo all of the commits that had been there that were removing these feature workarounds. And a few of them, the code has changed too much since then to just directly undo it. So I kind of tried to fix it directly. And it didn't fully work. So I was still kind of stuck with the black screen. And so at that point, I brought it to a Linux computer. And I artificially disabled all of the features that weren't supported on macOS and then enabled them one by one to figure out which one might attempt to bring back the workaround.
was broken on and eventually through that was able to get at least an image showing up on mac os that's a really interesting way to get into an open source project like getting into the git blame and bringing back some old features that's really interesting also fascinating to hear that you weren't into graphics programming before you got into the emulator because you know having looked a little bit about some of the stuff you work on some of the things you work on outside the project it seems very much now that graphics is your world yeah yeah since then i've done a lot of graphic stuff but yeah when i started on emulator that was actually my first usage of open gl and i kind of was like blindly going through there being like oh well you know they had this before so it probably works something like this we'll just try this that's how i had like no clue what i was doing and didn't know how to fix my black screen without just trying to compare it to it running on linux to just figure out which was breaking amazing okay so i want to get into talking about the amount itself and how it works and you know your work on especially on the graphic synthesizer but i guess first because i know it's a fairly wild platform i guess to talk about the emulator we should talk about the playstation 2 as a system and architecture can you tell us a little bit about how the playstation 2 worked and i guess all the pieces yeah so the playstation 2 it's like three or four
processors all kind of connected via a DMA, a memory copy engine. So there's the main CPU, which is known as the EE or emotion engine. And that's like a 300 megahertz MIPS CPU with a few weird instructions on it. But then they have attached to that CPU, or I guess sitting nearby, two vector units, which are each this custom instruction set that is just used for processing. If you've heard of SSE on Intel CPUs, which allow the CPU to operate on four values at once with each instruction, they're kind of similar to that, except for it's a very dedicated instruction set.
that doesn't really have much else outside of being able to do these vector float operations. Is it kind of like the kind of thing you choose CUDA for? Sorry to interrupt, but is it like kind of that? Yeah, okay, cool. Yeah, so those VUs, so there were two VUs. There's VU0, which is kind of meant to be used as like a coprocessor for the CPU, for the EE. And so the EE can kind of like just reach into its register. It can actually use it like as a coprocessor. It can just like execute single instructions on it directly, or you can send it like a little micro program that'll just like run through for like, you know, 20 or 50 instructions long.
usually something like that. And then VU1. So the two VUs have the same architecture, but they're just kind of like attached to different things and therefore expected to be used differently. So VU1 is slightly further, I guess, from the CPU. And it's kind of meant to be used in similar to what in a modern graphics card would be the vertex shaders. So it's got a thing that allows it to load stuff from memory into its internal working memory. And then it would run the program over that. And then there's an instruction in it that just takes whatever's in the internal working memory and just sends it to the next chip on the PlayStation 2, which is the GS, the graphics synthesizer. So you can think of that as the like, well, the PlayStation 2 is
old enough that it doesn't have actual shaders, but you can think of it as doing the part of the graphics workload that would now be done by fragment shaders. So it starts by receiving just like lists of triangles that have already been like transformed and are in coordinates that are just like 2D coordinates on the screen with a Z value only for like depth testing and nothing else. So the coordinates are already like in 2D and it just like rasterizes the triangles and then colors them in with the texture and that's about it. Right. God, there's a lot going on.
I guess the console really came... You just said that it doesn't have actual shaders. The development of this console is at such a point where so much of what we now take for going to a 3D game is still being decided that the architecture is all over the place. Yeah, pretty much. It has something you could think of as similar to a vertex shader, but no fragment shaders, which is kind of funny. It's kind of like the opposite of the GameCube, where they have fixed-function vertex processing, and then they have a semi-programmable fragment processing. Interesting. Okay. I guess this is just very PC-brained of me, but it's also really interesting how...
the various parts of the graphics processing is split across so many different pieces of hardware. I guess we're so used to now being like, there's the big one with the graphics card, right? Yeah, there's just the GPU, and it just processes things. Yeah, no, back then, even, like, the split was kind of different, and so the vertex shaders are much closer to the CPU, in fact, so close to that when we emulate it. I know we've heard people asking us, like, why can't you put the VU stuff into vertex shaders? And it's like, the VU can so much more easily communicate with the EE than a modern computer's vertex shaders can communicate with the CPU, that, like, that just wouldn't work. Okay, so yeah, that, I guess, brings me to my next question, which was, like...
what is it like to emulate this architecture? I imagine there's trade-offs with the fact that you're working on this. I imagine there's a lot of stuff going on in parallel in that architecture, right? That's really difficult to catch. So that tends to cause a lot of fun for us. Actually, I think with the exception of a few games that really abused the ability to very tightly synchronize between the EE and the VUs. And there are a few games like that that we just can't emulate properly because they expect ridiculously accurate cycle timings between the various coprocessors. So we try pretty hard to track cycle timing within a single processor. So the EE maybe a little less so, but the VUs, we vary.
tightly track it because they actually kind of reveal some of their internal timings to the program since you kind of have to. Which I can go into a bit more later if you want. Yeah, that's fascinating. Yeah, we'll come back to that. Yeah. But outside of that, there are only a few games that really abuse that hard enough that we break on those. The other fun ones are some of the instructions themselves on some of these things do things in weird ways that are hard to at least quickly emulate. So as an example, I think one of the more famous ones is the PlayStation 2's floating point map. So nowadays, even like the GameCube, I remember Dolphin had a blog post on one instruction that was slightly
off from the way you're supposed to do according to the standard and it was you know breaking all their replays of mario kart stuff or whatever but that was about it and that was like one teeny little difference in how they were handling i think a fuse multiply out in that in the playstation 2's case the floating point math just like completely ignores the like what's now standardized as how to represent a 32-bit floating point yeah i saw an off-hand comment about this might have been on the pc but like their floating points not to the ieee standard at all yeah yeah so it's kind of amazing so the first thing so in PC floating point, right? So the way it's set up, right, the 32 bits are split into a single sign bit to say whether it's negative or positive, then 8 bits for an exponent, and then 23 bits for what is usually called, I think, a mantissa. And so pretty much it's the computer equivalent of scientific notations. You say it's like, instead of saying a number, it's like, oh, it's 57. You instead say it's like 1 point something times 2 to the 32, right? And that's how floating point values are able to represent both really large values, like 10 to the 300-ish, as well as ridiculously small values, like, well, 10 to the negative 300-ish.
So that's kind of the representation. But on the standardized floating point, they have a whole bunch of extra things to handle edge cases. So as you go up near the very top of the floating point area, the highest exponent field value that can go into that field is used for storing infinity and not a number, where infinity indicates that if you go above a certain value, it's there to kind of stick around. So if you go above the maximum float, it'll go to infinity. And then even if you try to divide that in half, it'll stay infinity. And if you try to divide it more, it'll stay infinity. And then not a number is for things that go even more offhand. So if you try to take infinity and multiply it by zero.
that's even more ridiculous. And it's like, OK, that turns into not a number. And then once you have a not a number, it just kind of spreads around. Because any operation that includes not a number spreads the not a number to indicate to you, hopefully, by the end that, oh, by the way, something went wrong in this calculation. It's now not a number. We have no clue, right? And the PlayStation 2, they were just like, who needs that? And so the highest exponent value is not for infinities and not a number. It's just one higher exponent than the previous, which means that you can represent floating point values that are twice the size of, because remember, this is exponential, twice the size of the maximum PC floating point can be represented by PlayStation 2 in their floating point.
So that's like the first part of the issue is that it's like any number that goes slightly higher than the maximum PC floating point is now accidentally on PC becomes infinity. And it's kind of a minor issue when it's just, oh, they're big numbers. But when you remember that infinity is meant to kind of like spread, that's when things get really messy. Because like if you multiply by zero on a PlayStation 2, you're guaranteed to get zero back, right? Like every number being a not infinity number, you multiply by zero, you get zero. But on a PC, you multiply by infinity by zero and you get not a number at NAN.
You've just opened a door to me. I feel like PlayStation consoles in the past have been the source of more... PlayStation to PC porting has been the source of some really cursed ports. And I didn't know that this was an issue. And now I'm just like, oh God, the amount of errors this brings up. If you want some fun on that specifically, the Dolphin blog has a blog post about a game that was ported from PlayStation 2 to GameCube. It was whatever, I think, True Crime New York City, I think, where they mentioned that this is one of the games that in Dolphin ended up making them have to emulate floating point exceptions because, of course...
This was right back to the PlayStation 2 float so that if you multiply by zero, you know, whatever. And so in their case, I think they added a, when they ported to the GameCube, their AI must have like broken. And so they added a division by zero exception handler that would just say, oh, oh wait, you just divided by zero. Let me replace it. The correct answer there was, I think it's just zero. I don't, or maybe it's, I don't remember what the exact number is, but whenever they accidentally divided by zero, they just catch the exception and replace the number with a like benign thing that wouldn't blow up their thing. And then Dolphin had to make sure that they could actually emulate these division by zero exceptions all because of a game that was like scooted over from a PlayStation where division by zero didn't result in.
I guess in this case, it would be infinities or not a numbers that stuck around. Incredible. Okay, so that was one. So sorry, I interrupted you mid-play. So we had the issue of numbers can be much bigger on PlayStation. And then, of course, you don't get when you are working on the platform, you've got the propagating infinities. And then I think you were about to say there's another issue that rose in this. So I guess I'll just mention some of the things we do to work around that. So yeah, so because of that, PCSX2 just has, if you look through, I think the advanced settings or something, there's a number of like clamping modes. And so what that is, is after every calculation we do with these floating point values, if you have the clamping modes enabled, it will just do like a min and max with a PC min and max floats to just remove all the infinities and turn them into just large numbers.
which will at least multiply by zero properly in the PS2's opinion of properly, even if they aren't quite the same number. So that's how we try to deal with it. And it doesn't work for every game. And so I think we have a bunch of things to enable various modes on our thing for specific games that when we know that they prefer, break less. But there are still games that the AI just doesn't quite work correctly because we aren't quite doing the math correctly. So then going on the once last fun with the PlayStation 2 floats, it comes down to... So that problem was with the really big numbers. And so the other problem we have is...
with little small changes in the like low bits of a number, right? So like low bits being like the ones that make the least difference, right? When you have 1.0034, you know, whatever, that last digit. When the PlayStation 2 does math, the IEEE standard, the standard behind PC floating point, has a thing where they're like, oh, you should, or at least for the default mode, when you do math, like adding or subtracting values, you should round the result to like as if you had infinite precision when you did the calculation and then rounded it to the nearest float. And to do that, they employ, I think, three extra bits of precision when they're doing the calculation, one of which is...
I think one tracks like if you're right below or above 50%, and then one tracks if anything below that has ever gone above zero. So pretty much it's to be able to do a round even rounding, right? So if you think of doing a round even, right, it's like if it's below 0.5, you round down. If it's above 0.5, you round up. But you have to know if it's exactly 0.5, at which point you, in the case of floating point math, you round towards the even number. And so that requires like an extra three bits in every calculation. And apparently whoever was designing the PS2 is like, that's too many bits to keep track of, right? And so they just don't. So I think we have figured out that their addition uses just one.
guard bit is what they're called. And we had to do that because apparently some game does like decryption of its game binary using the floating point math unit. And so if you do it even slightly wrong, it just breaks everything because they're like decrypting data or something like that. So we specifically have a thing in there to like truncate the numbers before we do math with them to make sure that these extra bits of precision are just deleted. And then the other one is multiplication. I don't think anyone's actually like fully looked into exactly what it does in its math. But what we do know is that if you multiply a number by one, usually you'd expect that multiplying a number by one will get you that number back.
But according to a PlayStation 2, there are certain numbers that if you multiply by one, they will change slightly. How many certain numbers are we talking here? Are we talking like ranges are very big or weird? One specific, very precise number will mutate. I think ranges, but one of the other PCSX2 devs named Phobes went over this on their blog. I think they were actually going to be in the interview, but they couldn't make it in the end. So it would have been cool to have them explain that because I'm not quite as familiar with it other than the fact that there are definitely numbers that you can multiply by one and they'll just lose a bit. They'll just shrink by one bit. Oops.
So you mentioned the Graphics Simpsons earlier as an area that you've worked a lot on. How did you get into that in particular? Was that an accident because of this starting up the OpenGL thing? Was there something about that chip in particular that interested you? Yeah. So initially I worked a little bit on it to get OpenGL working and stuff. And then I was like, oh, hey, it works, yay. And I kind of set it down and went to work on it. Actually, I guess I didn't mention this earlier, but the next thing I worked on was Apple had just wiped 32-bit support off of their operating system the year I started working on this. And so I'd done a lot of my work originally by just using an older computer that hadn't gotten a 32-bit support wiped off of it. But then to actually get it working on my main laptop, the next thing was like, oh, let's actually...
get this working on 64-bit. So I kind of like went over there for a while. And that's actually when I, my first ever PR to the project was actually on for the getting 64-bit support. Mac stuff came later mostly because it was kind of like, well, you know, that was a project that didn't affect everyone outside of Mac OS, right? And also because the developers were like, you know, we deleted all these things four years ago because we were kind of sick of maintaining them. We're not sure we want those back. We're not sure we want all those hacks for like really old OpenGL stuff. We're not sure we want those back. And so one of the things that was on the back of my mind at that time was like, oh, well.
The reason Apple's abandoned OpenGL is because they want everyone to use their new API, Metal. So maybe I should consider writing a Metal renderer for PCSX2. So that was kind of like on the back of my mind for a while. So that was kind of, I guess, part of it. And then the other was during my time working on the 64-bit support, that's when I kind of got brought into like the rest of the PCSX2 team and, you know, joined the Discord, whatever, said hi, got to know everyone pretty well by the time the 64-bit stuff actually got merged because that took a little while. And so one of the other people, you know, in the Discord did a lot of their work on the graphics stuff in it. Oh, you know, it looks kind of fun, right? And so...
I think I played around with some small fixes to the thing before I attempted to write a metal renderer for PCS 6.2. And yeah, the first attempt didn't actually go especially well. So the one that's now in PCS 6.2 was attempt number two. So it kind of went from there. During my first attempt at writing the metal renderer, where I found a lot of things that I kind of wanted to change about the graphics thing to make it more friendly to adding new renderers. And so a little while later, I went through and tried to do a overhaul to make it easier to add new renderers, and then added the metal renderer, the final version of the actual published version.
Yeah, that's always a very satisfying genre of project, like making something extensible, I think it's a nice area to work on. So you mentioned a bunch of Apple graphics as we've gone along, and a bunch of it's been very surprising to me. I knew they had the Metal API, I guess I didn't realize how quickly they deprecated everything else. I know very little about the world of Apple graphics, and especially now that they're completely over in custom chip land, I feel like it's completely invisible. Can you tell us a little bit about, I guess, how Apple approached graphics processing, I guess? Yeah. So from the API standpoint, especially earlier, when they were still running Metal on the same graphics chips that everyone else was using, and so it was like, obviously, the hardware could do the things that OpenGL.
supports because that's why they're in OpenGL. And so obviously, the feature set was kind of similar to newer OpenGL. The OpenGL Apple supported was just missing major features. You've probably heard of compute shaders, right? The ability to run random things that's not graphics on your GPU. Yeah, Apple's just missing that from its OpenGL because it got introduced after, I think, Apple abandoned OpenGL in 2009. So pretty much everything since then they don't have. So yeah, Metals, if I had to describe it, I'd say it's most similar to a modernized DirectX 11.
So if you think of Vulkan and DirectX 12 are very different from DirectX 11, Metal's kind of like if you tried to bring the important things that are in Vulkan and DirectX 12, you tried to bring those to DirectX 11 instead of doing a whole new API. That would be my description of Metal. Yeah, so that sounds very Apple-y to me. Yeah. The other very Apple thing that they did is they just were like, anything legacy, goodbye. And so everything that you're kind of recommended not to use in the future from DirectX, things like geometry shaders is a really big one. Thankfully, this doesn't really affect PCS 6.2 too much. But yeah, geometry shaders is the big one at Metal. It's like, nope, no geometry shaders.
Previously, everyone was like, right, they added geometry shaders, and they turned out to be really slow. And so they were like, don't use geometry shaders, but they're still here. And so Apple was like, no geometry shaders, sorry, which caused a lot of people a lot of pain, including us for a bit. Because PCSX2, while we didn't use geometry shaders for too much, we did use them for a few things. And so that was probably the last things. That's what took the longest to come to the Metal Renderer for a long time. We didn't have the ability to upscale points and lines in the Metal Renderer because that required geometry shaders for a long time. And by required, I mean our code for it was using geometry shaders. We obviously didn't require it because we
Not as in like an immutable law, like the only way to implement that was geometry shaders. That's what you were doing. Yeah, yeah. It was a very common thing, especially because it's like the straightforward things, right? Like you have a point and then you send your point to the geometry shader, which turns your point into four vertices of a triangle. And that sounds like the kind of thing that a geometry shader would be good for because like that's what they were for, right? But it turns out apparently they just weren't that fast at it, even simple things like that. It was still faster to, if you're wondering, the new version, which I actually learned from a AMD presentation on how to doing this faster than using geometry shaders on like all GPUs. It's like you send your vertex shader, you take advantage of the fact that newer GPUs can just kind of load from memory.
however they want. And so instead of using the hardware, so modern GPUs either have or pretend to have dedicated hardware for loading vertex data. And so then you just ignore that hardware, or the pretending of that hardware, as it may be on, I think, AMD GPUs only pretend to have it. I'm not sure. Apple GPUs definitely only pretend to have it. You ignore that hardware, if it even exists, and just manually fetch the vertices. And so instead of using a shader to expand one point into four vertices, you say there's four vertices, and then you divide the vertex index by four, and so have the four adjacent vertices load from the same single pixel's data, and then just offset it.
And it ends up working out and being faster than Geometry Traders, at least according to AMD's presentation that I watched. I never actually benchmarked it personally. All the low-level details of graphical techniques always just seem like witchcraft. That's awesome. And yeah, good to understand the whole Apple API journey. It's a very objective scene to me, what you said about going with, like, you know, making something new that's kind of the old thing with all the things that are ported. So one of the things we've heard from emulator devs in the past, and I think that you mentioned when we first started talking, was in your journey in working on the emulator, and especially on the GS, you obviously come across weird ways the games have used it. What are your favorite cursed games that you've had to deal with on the emulator? Yeah, let's see. I think...
We'll go with SOTC, SOTC, Shadow of the Colossus. There we go. Shadow of the Colossus, yes. So they have this bloom effect that they run on the GS. And the way they do it is they, over each frame, they accumulate this texture by, I think, I don't remember exactly, but I think what they do is they take a silhouette of all of the things they want to put this bloom effect on, and they make that white. And then they spread it around by just render it up slightly above, slightly to the left, slightly to the right, slightly down. Because remember, they don't have shaders, right? So they don't have shaders. You can't just sample this texture in three places. So they just render it four or five times over the same image.
The GS had a lot of, it didn't have shaders, but it had a lot of fill rate. So the ability to render a lot of pixels for the time very quickly. And so that's just what they did. But the fun part is, so they'd accumulate this texture and their calculation was set up so that it would write together a bloom effect, right? The white part would just kind of, because they're each frame, they blur it slightly more. It would come out in kind of like a halo, right? Because that's the fact you want, right? But as it turns out, the thing preventing its spread from continuing too far was the fact that the PlayStation 2's blending rounds down. OK.
Right. So when you do the blend, right. So remember, they're spreading this by taking the image and just rendering it with like 10% opacity many, many times. And so each time you do that calculation for like, oh, 10% of this one plus 90% of this one, put them together, right? Most PC GPUs, as far as I know, they'll round nearest, right? They'll round to the nearest. So if it's above 50%, they round up. And if it's below 50% of the way to the next value down, they round down. But on the PlayStation 2, it truncates. So if it's any less than, even if it's 99% of the way to the next pixel, all the way back down. And so the only thing preventing this bloom from just like exploding across the screen and turning the entire thing white.
is the fact that the blending here between these values, that it rounds down. And the fun part is that PC GPUs, these days, everything's shaders. Everything's shaders. It's all programmable, except the blending. The blending is not programmable, except for on Apple GPUs, as it turns out, and Intel ones. But on AMD and video GPUs, the blending is not part of the shader. The shader outputs a color, and then it goes into a special hardware unit that combines the color from the shader with the color that's already in the texture, which means that it's not very easy to modify. Everything in the shader, we can just be like, oh, we'll just calculate it slightly differently. But once it's sent to the hardware blend unit.
The hardware-bound unit is now in charge, and we can't really do much about it. And so Shadow of the Colossus is, I think, one of the more. famous games but we have lots of fun with blending on the ps2 and so we actually had a whole bunch of like attempts at trying to make this work better so like one of the things was like the pc blending right it allows you to the main calculation right is the alpha value one you want would mean fully opaque so that would be alpha value times the source's color plus the one minus alpha times the destination color right of the texture and so one of the things we tried was like well what if we did we can't mess with the value once it's gone to the blend unit where it because the big issue here is that the shaders run in super in parallel right you're A modern NVIDIA or big AMD GPU has like 10,000, something like that. CUDA cores or stream processors or whatever each manufacturer calls it. So like 10,000 of these mini CPU-ish things. They're not really a full CPU. I mean, they're closer to a single lane of SMD. But anyway, like 10,000 things that'll be calculating on pixels at once. And then the way GPUs handle their like...
getting good memory bandwidth is by just running a whole bunch of things at the same time on each one of those. So not only is it there like 10,000 calculations happening at once, but there are also probably about 10 times that many pixels that are just waiting for their memory accesses to finish. So you're looking at like 100,000 or something pixels that are like in flight at once. And if your triangles overlap and they need to blend with each other, that needs to happen in a specific order, right? If you put the first pixel down and then the second on top of that, if you're blending with each other, that'll look different from if you put the second pixel first and the first one on top. And so this is...
reason that you that they don't want your shaders being able to try to load from the texture that you're rendering to because then they're going to have to order themselves which would be not great and so this is the reason that you can kind of do whatever you want as long as you're not looking at the texture you're rendering to but once you need something that looks at it you have to send it to this special hardware blend unit that figures out what order everything needed to be in you know fixes up you know reorders them if it needs to or however it does it who knows that's the manufacturer's deal not ours and then blends them in order and so we can do whatever we want up until then and so we're like well What if we do that first source texture times source alpha multiplication in the shader? And then we can subtract it a little offset to do the opposite of what the PC, right? So the PC rounds at 50%. So what if we subtract half a texture value? So we just bring it slightly lower so that when it does the 50% rounding, it now is actually rounding on a value that's slightly smaller than what it originally would have. And then it'll hopefully round closer to the correct way. And that was the hope. The hope that that worked out? It worked on AMD GPUs. Right. It turns out there's no requirement that the shader output.
have any more bits in it than the actual texture it's going to. And so on NVIDIA GPUs, it turns out they were half precision floating point, 16 bits of data with like 11 bits of precision or something like that. And they were tracking it right back down to eight before they sent it to the blend unit to save a little bit. I'm sure it saves a little bit of bandwidth, right? But it completely undid everything we were trying to do. It just undid it. So we do have SOTC looking nice on AMD and Intel. But I think NVIDIA, you have to raise the blending accuracy setting. We have a PCS-62. The big hammer for this is there's a blending accuracy toggle. And as you bring it up, we like...
switch more and more draws to software rendering, where we really do actually load the value that's currently in the texture, look at it, combine them, and put it back. And we make GPUs really, really unhappy. Because to do that, we, of course, now have to order all of these pixels. And as a software, we don't really know which pixels are and aren't ordered relative to each other. So our big hammer approach to this is that after every, we draw one triangle at a time. And after every triangle, we tell the GPU, please flush all of your caches and make sure that the sheet can read the value that it was just rendered to. OK, one more triangle. All right, flush all the caches ahead.
So it's very expensive. GPUs hate it, but it does get you the correct pixel values. Incredible. And so we have this big blending accuracy slider. It's a dropdown menu, but with like six different options. And the only thing those different options do is they increase the number of triangles that we apply our big hammer to. So yeah, the basic mode, we like track down what most games tend to do that ends up requiring the software blending approach. And we only do it for those. And that usually only adds a very small overhead because we were, you know, when you're only doing it for like 50 triangles, like, oh well.
But then you go to medium and then high. And then on high, some games are looking at like 10,000 of these single triangle followed by a barrier followed by a single triangle followed by a barrier. And that's when like AMD GPUs especially hate this. And you get like 10 FPS or something, you know, some terrible, terrible frame rate on even like big, powerful GPUs. And they use very little power while they're doing it because like most of the GPUs are just sitting there waiting. It always looks kind of funny. It's like, oh yeah, my massive GPU is using like 30 watts. But it's trying really hard, but it's only using 30 watts. It's really suffering, but it's using no power to do it. Yeah. Okay, so I guess with all that in mind, it seems like...
you know, emulating the PlayStation is just, like, really hard. Like, how close is, like, true to original console? Like, would you say we are, like, overall on PlayStation 2 emulation? It really depends on how true you need, right? Yeah, yeah, yeah. One of the things we do have, we have a software renderer, which is where we do all of the pixel everything. We do the work that you would normally do on a GPU. We just do it on the CPU. And because...
Especially for a long time, it's gotten a lot better now. We properly detect a lot more games, weird things. We properly detect a lot more games, weird things now, so that we're a bit better. But in PCSX2 1.6, there were so many games that just wouldn't work well on the hardware renderer that, unlike, for example, Dolphin software renderer, it's kind of meant for developers to just verify things. But PCSX2 software renderer is meant for actual users to use, which means it's not actually fully accurate, which is a bit funny. But it uses memory the same way that the real GS does, and that helps a lot of things. And so that's one of the ways you can get a bit closer, is that use the software renderer. It runs full speed in many games, especially on modern, like.
Ryzen 5000 series, most games will run full speed on the software render, which is pretty cool. And that gives you much better support. These days, they're a lot closer. But there's still definitely games that run better on the software render. Then from the EE side of things, where we have the synchronization of whatever, there's a specific game. The engine is, I think it's called the Blue Shift engine. Is it Marvel Rise of something something? There's a specific game that will kick off the calculation that happens in cycle time in parallel between the EE and both of the two VUs. And on the issue for this game, we were discussing it. And one of the developers from that game came over and posted.
the code that they had written that we were screaming about internally. They posted it to their Twitter. They posted a link on our thing. So I got to actually go look at the actual source code for that game. And it was like, wow. So yeah, so it runs on the EE on a single cycle. So the EE is a superscalar MIPS processor. And it is able to run two instructions at once, which I'm sure at the time was amazing. Nowadays, like CPUs run like 12, or maybe not quite 12, but like eight-ish instructions at once now. But at the time, two instructions at once, right? Can run two instructions at once as long as they don't conflict with each other. And so they start by running.
one instruction to start VU0 and one instruction to start VU1, making sure that they happen on the exact same cycle. And then they counted the cycles for every instruction from there. So they know exactly which instruction on the CPU is running at the time of each instruction on running each of the VU programs. And so then the CPU, they can just kind of be like, oh, I know the VU will be done with this. Let me just yoink that right over there. And then have VU0 just yoink from the VU1 registers because VU0 can kind of just reach into VU1's registers if it really wants to. Right, right. And so this is when you mentioned earlier that the VU exposes its timings to programs. That's where that comes in.
Yeah, so they kind of just like reach into each other's stuff. And then they expect to obviously be running two instructions from the EE, one from VU0, one from VU1. Two more instructions for the EE, one from VU0, one from VU1. And we currently, our best is like to synchronize after like every eight instructions or whatever. And even that's like really slow or something. So the current opinion on that one that one of our other developers was like, I don't think maybe in 10 years, probably not in 10 years. But yeah, so there's always going to be some games that are too timing sensitive for us. Yeah, absolutely. Yeah. All right. So weird VU timing stuff.
Right, yes. So on most CPUs, so I mentioned like modern CPUs, they can run eight, 10 instructions at once, right? The way they do this is they kind of like inspect your program pretty much like as they're running it. And they're like, oh, hey, you know, you wanted to do this instruction and this other instruction. And, you know, this instruction is multiplying the values from, you know, register two and register three and putting the result in register four. This one's multiplying the values from three and five and putting it in six. Well, there's no reason I couldn't just run both of those at once, right? And so it just does. And it just does this up across like, I think.
modern CPUs are tracking hundreds of instructions at the same time to figure out which ones are ready to run based on having all of their inputs ready. But the important thing that they try to make sure is that no matter what they do internally to make developers not go crazy, they act as if they ran each instruction one at a time in order. So they only run instructions out of order if they are able to undo everything if something explodes or whatever, to make sure that they act as if they were running each instruction one at a time in order. And from a developer standpoint, that's nice because I don't have to think about what my CPU is going to be running out of order. As I write the instructions for it, if I were writing assembly, obviously, most people aren't writing assembly these days, but the compiler doesn't have to worry about this thing, you know, whatever. Everyone's happy. But, you know, there's a lot of circuits being used to track all that stuff, right? So if you just, you know, didn't have that. So the PS2, they have a pipelined thing that can vector, you know, that can do operations on four floating pipe values at once. And so for the most part, they actually do have this kind of tracking on it. And so if you say, right, you're like, oh, let me multiply from...
you know, the values and registers two and three and put the result in four. And then you say, instead of three and five and put the result in six, what if you said three and four and put the result in six? Well, now you have to wait for the first one to finish before the next one can start because it needs the output of the previous one. And so for multiplication on a VU, that does happen. But then you go to division and you're like, okay, let me divide this by this input. And there's actually only one division output register Q. And so the result goes in Q. And then what if you read Q and use that for something else? Well, it says, go ahead. You can just read it. The value in there is the one from the division that happened, the last division to have actually finished.
By the way, divisions take seven cycles. So seven cycles after you start a divide, the new division result will appear in that division register and overwrite the old one. But until then, you can just go out the previous value. Hey, why not, right? It saves them some circuitry to track this. And it also means that you kind of have one extra register's worth of data because you can start the calculation that targets the division and then take the result instead of having to take it first and then having to store it somewhere. And so everyone's happy except for all of the people who are trying to actually write code and schedule things because they realize now that they have to kind of like, it makes things.
painful when you're writing code because right now you're like, OK, I start my division and then I do some other stuff and then I get my division result, which means I have to have something else to do while I'm waiting for that division, right? So from a programmer standpoint, you can get more performance, but you have to work a lot more on your programmer. But then from an emulator standpoint, we now have to track all of the things that are in flight because, of course, the people who are writing the code clearly were tracking in their heads or in a helper program or something how many cycles everything was doing and how many cycles it had left before it appeared in the division result register and overwrote the previous thing. We have to make sure that we do the same thing now, right? And so, yeah, the solution for that, when we do our recompiler for the VUs, we store it as a part of the, like, when you're like, you know, normally when you're doing it, you're like, oh, well, I'm going to recompile the code at this address in the code, right? But now you're like, I'm going to recompile at this address with five cycles left on the Q register and, you know, three cycles left on the, there's a like sine cosine thing, and that has its own output register, right? So three cycles left on that one. And then we will compile a different version of the code if you enter that block with a different number of cycles remaining, the various registers. And so that kind of works out fairly well for the VU only code. But remember how I mentioned that the EE can just execute VU instructions on VU0?
Well, as it turns out, we don't have quite that much coordination between our EE recompiler and the VU recompiler. So at the moment, that just doesn't work. And at the moment, our best solution is that we detect when we have something that's able to at least detect when it might be happening. And then we put up a big warning message and say, if your game breaks, you should contact the PCSX2 devs and they'll make a patch for your game to reorder the instructions. So it won't work on a PS2, but it will work on PCSX2. So hopefully at some point, we'll get that actually working. But at the moment, that's how things are going. Yeah, actually, that brings me around to another question I had, which I guess is just about how you work as a team, which is like, I feel like emulators are in this really weird space where your users aren't necessarily...
They don't necessarily understand the console. They're not necessarily technical. They just want to play PlayStation 2 games. They're kind of treating you as a product, but it's a very technically intense case-by-case basis. How do you, I guess, go about thinking about progress of the emulator as a team? You're very driven by what game issues are being reported. Is it overall accuracy to the platform? How do you approach this? Yeah. One of the big things about this is a lot of people are working on this because they enjoy working on it, right? And not because they're being paid to work on it or something. In fact, a lot of the PCSs do that specifically or explicitly don't want to accept money because they don't want to feel like they have to...
It becomes a different thing when you're paid for it. Yeah, they don't want the responsibility that comes with that. So yeah, so part of it is kind of just like a people work on the things that they're interested in working on. And so some people care more or less about making sure that bug report comes up and making sure that it gets, we do have a bunch of people who are at least like, you know, triaging those for us. But like trying to choose which actual games to prioritize, trying to make them work is kind of up to each developer of like, you know, what games they care about. There's bigger issues, you know, how many games are affected by that. It's kind of like each person will decide for themselves.
how they want to do that. So yeah, we communicate in a Discord server. We know each other pretty well, or at least as well as we would, you know, as a bunch of people on the internet, right? And I feel like we usually get along pretty well, and so that's at least good. Yeah, that makes a lot of sense. Yeah, I guess, yeah. I think it's particularly interesting with this PCSX2, because I think the project website makes it look like such a, like, a professionally run project. Right. So it's always fun to hear how, like, you know, the resource projects actually happen behind the scenes. Even that, though, that website's, like, pretty new, these, and then, like, up to, like, two years ago, it was a website that looked kind of like it came out in 2005, probably, because it did. So yeah, we have one of the...
I don't actually know if they're newer on the team. I think they've been on the team longer than I am, which means I don't know. Actually, I don't think they were someone who worked too much on the emulator, but they're like, hey, you know what? I want to work on the website. And they made this fancy website for us. And now our website looks at least somewhat modern. It looks very modern. It looks very nice. Do you have, along the way, aside from the core emulator, is there like a suite of tools that you all have built out internally to, I guess, debug or work towards progress in the emulator? Yeah, I think each person kind of used their different things.
Since I'm on Mac OS, there's really only one, I guess I should mention, this is from the perspective of debugging graphics stuff specifically. So Apple has a general graphics debugger for their Metal API, and so I often use that. And then I know a lot of people on the Windows side will use a program called RenderDoc, which does a very similar thing. That can be used with any game that's using RenderDoc, Vulkan, DirectX 11, yeah, 11 or 12. It kind of just, like, you capture a frame, it takes all of the draw calls that made up that frame and kind of puts them in a list, and then you can kind of just go through them and look at each one in turn and be like, oh, here's a draw call that did this. But PS2 games tend to be kind of
unruly in how they do this because of the way the PlayStation 2 works. And so another alternative we have is we have a draw dumping system where you can check a bunch of boxes in emulator and it will, for every single draw the game does, it will create a new PNG in a folder and it'll just number them. And in fact, it'll make not just a single PNG, but it'll, I think, make like seven PNGs and maybe two text files saying stuff about the draw. Because, you know, it's the kind of stuff that you would see in Renderduck except for all of the screens from Renderduck is PNGs and text files. And it just fills your folder with like gigabytes of PNGs and then you scroll through them with the like icon view of your file browser and go through. So I've used that a bunch as well. It's useful for like
tracking down lower level things of what the game right it's like the question is like is the game doing something really weird or oops i did a dumb thing in my graphics code and if it's the x code or render doc is better for the oops i did a dumb thing in my graphics code whereas if the game is doing something especially weird it's often easier to use the draw dumping because that's closer to the ps2 side of things and so different people use different amounts of like draw dumping versus the third party tools like render doc yeah i've not heard of render doc that looks awesome yeah render doc is very cool and then from a cpu perspective i think each person who is kind of working on like especially with like the recompilers and stuff would kind of do their own thing, which for better of course, I think most of them didn't actually make their way into the emulators, like the things for debugging the stuff. Some of it did, but not all of it. Yeah, so I know we have some integration with some of the Intel profiler tools as well. So we have a thing where if you flip on a compiler switch, it'll try to send information about the recompile. We emulate the CPUs by taking the instructions for that, the MIPS instructions, and generating equivalent for the computer it's running on, which tends to confuse tools and so the tools like profilers and things. And so we have a thing to call a special method on Intel's profiler and tell it, oh, by the way, we just made a new function over here.
here's its name and that way the profiler can actually name it properly. make things look nice nice awesome very cool final question is there anything coming out for them or anything you're working on for them that you're excited about or anything you're able to tell us is coming up in the future i think more recently i've been trying to do some stuff with the interface and like we just got the ability to i guess we always had it but it's actually working well to translate the ui into lots of different languages now but there are a few things that are currently missing from some of the on-screen stuff doesn't work very well with with like arabic or stuff so that's definitely something i would like to work on is try and get that to be able to show japanese and arabic characters in the on-screen ui which we currently can't Awesome. Yeah, I imagine Japanese, especially for a Sony console, will be very impactful. That's awesome. Cool. Wotelo, thank you so much for joining me today. What a piece of hardware. Thank you for running me for everything. Yeah, thank you for working on such a wonderful emulator. Well, it was a pleasure doing this interview.