Switch emulation, MoltenVK, and Metal

KingOfPain

Site Champ
Posts
250
Reaction score
327
Some of you may have already heard that there is now a port of the Nintendo Switch emulator Ryujinx that runs natively on Apple Silicon.
I don't really want to start a discussion about the grey zone of emulation (especially of a current system) and I have to admit that I haven't tested the software yet.

But I find the technical background rather interesting.
Frankly, I would have expected a port of Yuzu, because it is written in C++. But I guess there is a capable C# compiler for macOS (Mono?).
It's impressive that they've added the option for virtualization, which obviously only works for software that doesn't use 32 bit ARM code, since Apple Silicon removed AArch32, but the Tegra X1 in the Switch still has it.

The biggest work probably went into circumventing some limitations of MoltenVK and/or Metal. A lot of this is mentioned on the following page:

GPUs or graphics API aren't my forte, so I hope some of the more knowledgable readers provide their 2 cents here.
My impression is that Metal 3 isn't going to provide a solution for a lot of these incompatibilities, but some of the work-arounds might find their way into MoltenVK.

When talking about game engines it's easier to say, they should properly adapt their engine to Metal, but in this case that isn't really an option. From what I've seen in videos so far, the Ryujink developers really seem to have taken the lemons they were provided with and made lemonade. Here is a video of some games running on a M1 MacBook Air:
 

Nycturne

Elite Member
Posts
1,108
Reaction score
1,417
Frankly, I would have expected a port of Yuzu, because it is written in C++. But I guess there is a capable C# compiler for macOS (Mono?).

Microsoft bought Mono a while back, and so the Mono team is now part of the .NET Core team. Which means, Microsoft today officially supports .NET Core on platforms like Linux and macOS: https://dotnet.microsoft.com/en-us/download/dotnet/6.0

It also depends on where all the C# is used. It’s performance isn’t too bad, but when you can use the hypervisor, the fact that you have C# code doesn’t matter that much to the CPU side.

It's impressive that they've added the option for virtualization, which obviously only works for software that doesn't use 32 bit ARM code, since Apple Silicon removed AArch32, but the Tegra X1 in the Switch still has it.

They do note that certain games don’t work with the hypervisor because they use 32-bit ARM. There is a JIT that translates 32-bit ARM to 64-bit ARM, but comes with the expected performance overhead.

The biggest work probably went into circumventing some limitations of MoltenVK and/or Metal. A lot of this is mentioned on the following page:

GPUs or graphics API aren't my forte, so I hope some of the more knowledgable readers provide their 2 cents here.
My impression is that Metal 3 isn't going to provide a solution for a lot of these incompatibilities, but some of the work-arounds might find their way into MoltenVK.

What’s interesting is that their changes to make things work with MoltenVK and Metal have resulted in speed-ups for Linux and Windows in some cases. So it hasn’t been all bad on that front.

Many of these are not so much incompatibilities, but rather things that Apple’s GPUs and Metal don’t necessarily have explicit support for, so you are left to build the thing you need yourself. Which they did. Since they are working at the driver layer on the Switch side, this doesn’t surprise me too much here. I’m not 100% sure what stack the Switch uses, and a quick Google seems to bring up both Nvidia NVN and Vulkan/OpenGL/OGLES. Assuming it’s NVN, the emulator is translating from that API to the platform’s underlying API. So I would expect a good chunk of the work to be related to this, as that’s where the biggest differences lie between the platforms involved.

When talking about game engines it's easier to say, they should properly adapt their engine to Metal, but in this case that isn't really an option.

To be honest, I think they kinda did that here. They did adapt their engine to Metal (via MoltenVK), with more success in some areas than others. It’s not a perfect port, but at least at a surface level, it sounds like they did the right thing in many of these cases.
 

KingOfPain

Site Champ
Posts
250
Reaction score
327
I must have missed that Microsoft acquired Mono. But I have to admit that I lost track of C# after I didn't need it for work anymore.

I also noticed that they write that some changes led to improvements on other platforms as well, but forgot to mention it. At least not all the work was just for Apple Silicon compatibility and might have led to overall more efficient code.

While a JIT/dynarec exists for ARM32 and those ARM64 games that don't work with the hypervisor for some reason, this video shows that those games run a lot slower (at least on the basic M1):



But it's still impressive.
I read some comments in the Yuzu repository that an Apple Silicon version would be impossible without major MoltenVK changes. I guess Ryujinx proved them wrong.
 
Top Bottom
1 2