Emulating Nintendo Switch Games on Linux
boilingsteam.com
boilingsteam.com
Wait, really? Are you sure?
I ask primarily because, this sounds a little too close to "Downloading roms you don't own is legal as long you delete them within 24 hours." ;)
but specifically excludes software
https://en.wikisource.org/wiki/Polish_Copyright_Law#Chapter_...
Art. 23. Copyright The scope of the work's own personal use 1. Without the author's permission, you may use an already disseminated work for your own personal use free of charge. This provision does not authorize to build on the basis of someone else's architectural and urban planning work and to use electronic databases that meet the features of the work, unless it concerns own scientific use not related to profit-making purposes. 2. The scope of personal use includes the use of single copies of works by the circle of persons remaining in a personal relationship, in particular kinship, affinity or social relationship.
But software is explicitly excluded by 77:
Art. 77.[32] does not apply to computer programs art. 16 pkt 3-5, art. 20, art. 23, art. 23 ....
Personal use defined in article 23 might have something to do with copy tax we get on computer media like CDRs, USB drives and even ordinary HDDs.
Yes, you can get microSD cards but there's still not enough space and I'd rather avoid swaps entirely.
https://www.amazon.com/dp/B0887GP791
There are 512GB and 1TB cards too if you want to pay for them.
Though I agree it'd be nice to have network storage support, it's a niche feature that goes against the mobility aspect of the switch.
Plus, there's an explicit statutory carveout for archival/backup copies of computer programs, which would apply to games.
Companies are likely not that bothered by legacy systems being emulated, but this is the current Nintendo flagship console. Thankfully the Switch seems to be selling amazingly, which should mean Nintendo don't really care that much.
Another factor is that you will likely need a pretty beefy PC to play games in full speed, and compatible controllers.
Now if you're talking about trying to run one of these emulators on an ARM build of Linux, you wouldn't see these performance improvements since their designs are optimized around x86 CPUs, not ARM.
Edit: Several far more informed comments than mine have mentioned that running on ARM is only one small piece of the performance coming from DraStic.
Its really fast because of the tons of optimization that went into the application. It does many cool things to cut out overhead on the CPU side, but also it does a lot on the graphics emulation side, including hand rolled ARM NEON code for SIMD processing polygons. I'm not very familiar with DS emulation, but one of the devs for Drastic contributed to another project I worked on, so I had some chats here and there about these sort of things.
In any case, DraStic is a completely different style of emulator compared to Yuzu. The Nintendo DS is nothing more than a pair of microcontrollers with (from a modern perspective) primitive 2D+3D acceleration hardware, whereas the Nintendo Switch is a multiprocessor system with a modern GPU and mulitasking operating system. The DS CPUs are actually quite far removed from modern smartphone chips, whereas the Switch chip should be mostly standard ARMv8. Things that apply to one don't necessarily apply to the other.
Compare this to Dolphin, which has been wildly successful in emulating the Nintendo GameCube. Besides the big popularity of Nintendo games, the GameCube was comparable in complexity and sales figures to the OG Xbox. But since it had a relatively non-standard CPU architecture and a non-standard GPU setup, it guided emulation developers to not put too much effort in shortcuts and tackle the emulation problem head on.
It's worth noting some recent progress has been made in OG Xbox emulation by the Xqemu and Cxbx-reloaded projects. The former tries to use qemu for x86 emulation (or even virtualization?) while "low level" emulating the rest of the Xbox hardware, whereas the latter started life as an extreme high level emulator that is going more and more low level over time.
Yeah, more a POC that a full emulator but I can assure you that it works, assuming you can decrypt the supported titles, so you'll need an exploitable PS4 or find a dump on the Interweb...
Edit: link https://github.com/devofspine/spinedemo
It's also perfectly fine to want to play things in the intended way, of course.
People like you aren't vocal in gaming communities or anything but boy do you buy games.
The disconnect becomes obvious in cases like Pokemon Sword/Shield where the community was OUTRAGED about a number of things (some complaints valid, some less so), threatening boycott... then the game comes out and sells millions in the first day. Do you realize that most people don't go to r/switch, r/nintendo or r/pokemon daily? Who knew!
You should try Zelda: Breath of the Wild or Mario vs Rabbids: Kingdom Battle, they're single player games and a lot of fun.
Although I don't play much games, I like to read about them for some weird reason. I was browsing the eShop today and saw Crysis listed there. Isn't that notorious for being very heavy on computing resources? I wonder how that'd run on a portable device like Switch.
I was actually under the impression that BOTW ran at 60fps when docked, but I probably got my wires crossed and I'm thinking of resolution.
This is mostly in jest though, the convenience of just using the switch wherever I want rather than futzing around with emulators still mostly trumps wanting it to look prettier.
That said, it's trivial to use any other control or input device. You just might run into issues if a game requires motion control. I'm not sure but you might even get away with using a Wiimote, but I'm not sure what the controller support looks like there.
So what you've said doesn't make much sense to me.
Just because you bought a cartridge with a binary and a license to execute that binary on a switch doesn’t mean you have the legal right to back it up and play it on your PC.
Do you in fact! As long as it is your cartridge and you backed it up yourself, you can legally emulate it. (You cannot use someone else's dump, nor can you share yours.)
[0] https://journal.stuffwithstuff.com/2009/01/03/debunking-c-vs...
[0]: https://mattwarren.org/2019/03/01/Is-CSharp-a-low-level-lang...
C# allows to optimise memory allocation when that matters and to rely on the GC for less critical parts.
There does seem to be this odd semi-subconscious idea in the "GCs aren't appropriate for any high-performance" world that they intrinsically work by stopping the world for 50ms several times per second or something, but that does not have to be the case.
[1]: I actually have a number of servers in Go that run on about this schedule. If you eliminated 100% of my GC cost for these servers, I wouldn't care at all, or even notice.
Things work a bit differently for "modern" emulators, where the emulators recreate the kernel/OS at a high level. In these emulators, the games will call into the system, and the kernel will be expected to do all thats necessary for the call. In the high level approach, this means that if a call allocates, so does the emulator (edit: note that this is a simplified view, as both emulators map a 4GB page that they work in for the guest system memory, but theres still a ton of side allocations that happen "outside" of the guest kernel). There is a lot of work that goes on in this layer of emulation, and theres going to be objects that the emulator allocates and later destroys. Process tables, thread lists, scheduler information, timing events, kernel synchronization primitives like mutexs, and so on to name some. I'm not intimately familiar with Ryujinx to make any statements about how they handle GC of course, but its something that they'll need to take into consideration. That said, there's plenty of other things like JIT compilation, shader compilation, caches filling up, and on and on that all also cause micro stuttering, so its not uncommon for even C or C++ emulators to have annoying pauses too.
https://www.cs.rice.edu/~javaplt/411/15-spring/Readings/wils...
https://web.archive.org/web/20191108025442/http://home.pipel...
https://web.archive.org/web/20191008134612/http://home.pipel...
https://web.archive.org/web/20191231120253/http://home.pipel...
Real-time garbage collectors are a thing. Maybe not common, but they have existed for at least 20+ years.
Of course, there's always performance left on the table when you write in a language like C# or Java (and even a little performance matters a lot when it comes to emulation), but the memory safety that C# can provide over C++ can save the developers a lot of debugging.
I think such an application can perform perfectly well in a hardware generation or two and until that point compatibility matters more than speed anyway; that's where ease of development will shine. Running an unplayable game well is not a very interesting project for end users.
When the project reaches significant compatibility, other emulators can take ideas from its code and port them to C/C++/Rust/assembly if they desire to do so.
It really doesn't matter how much headache it saves you in debugging. The problem simply cannot be solved at the required level of performance if you use C#.
>When the project reaches significant compatibility, other emulators can take ideas from its code and port them to C/C++/Rust/assembly if they desire to do so.
The only legitimate use of this project is as a research bed for future emulators, so I agree with you there.
It's not just that. Basic patterns in C# are known to have pathological performance problems (implicit boxing, implicit heap allocations) that you simply don't run into programming in C or C++. These are things that tank performance in day-to-day programming that do not show up in carefully tuned benchmarks.
Source: Helped profile lots of C# games (not IL2CPP with Unity, although that's pretty bad IMO as well), not pleased with what I saw.
This is a bold claim. Please provide evidence that the most current .NET implementation (.NET Core 3.1) is slower than any JavaScript implementation.
This doesn't pass the smell test since you're comparing an ahead-of-time statically typed approach to a dynamic scripting language, both of which have had highly tuned JIT implementations, both of which are using garbage collection. You can implement things poorly in C#, sure, but you're making a much stronger claim of consistently poor performance.
Saying 'dude trust me' is not a source.
C# currently 1st place in this webserver benchmark. Ahead of C/C++/Go/Java/D.
No offense to JavaScript, I like it and it has its uses. But surely your OP is joking when saying JavaScript is faster than C#. Even after all the performance improvements that V8 received.
I feel like it's possible to write careful C# for performance. It just won't be entirely idiomatic. Things like buffer re-use, ordinary techniques you'd need to apply manually for C and C++ in similar domains too.
The main emulators off the top of my head, MAME, bsnes (and the related higan) and dolphin, are all in C++.
Why?
Let's start off by breaking the core performance portions of emulation into a few broad categories. There's CPU emulation, for running the actual guest exe, Kernel and OS emulation for handling the system calls that games make, and GPU emulation for translating the guest's GPU work into modern graphics API that your PC can use. Now let's compare how language overhead will affect each of these main scopes.
CPU Emulation - Both yuzu and Ryujinx use JIT compilation to recompile the guest ARMv8 instructions into x64 at runtime. The specifics of the two emulators JITs are pretty different, and it'd be cool to go into more details, but the mile high view is a comparison of C# vs C++ isn't going to have much of an effect on the runtime difference. At least not near as much performance gap between techniques and optimization levels that the JIT is capable of. The goal of JIT compilation for CPU code is to remove as much interpreter overhead as possible, so if your choice of programming language is slowing down the JIT, that suggests that you have somewhere else to improve in the JIT ;)
Kernel/OS - This is the area that will have the largest performance difference between implementation languages, but with the major caveat that Kernel and OS emulation requires the least amount of processing power out of the 3 categories mentioned here. The Kernel and OS are responsible for managing and scheduling threads, handling network connections, and etc, but really most of these things have fairly low impact on final application performance in comparison to CPU and GPU emulation. As a side note, emulators aren't the only groups interested in switch OS/Kernel work. The open source Atmosphere custom firmware for the switch is working through recreating an open source kernel/os for the switch, and the two emulators benefit from their work too. (See the licensing exemptions here https://github.com/Atmosphere-NX/Atmosphere#licensing)
GPU Emulation - This is probably the trickiest part of Switch emulation, and once again, it comes down to how you emulate it, and not the language you use to write the emulator. The biggest performance differences between the GPU emulation of the two emulators will boil down to technique differences, and not the programming language. GPU emulation performance can be roughly broken into two parts, the "actual" gpu running time, and the state management/conversion. There's only so much an emulator can do about the actual GPU running time since at some level, you are going to need to run the game's GPU code, but the other half is a whole lotta code to avoid doing more work, and much of the GPU performance optimizations goes here. Things like managing the game's GPU memory, avoiding changing or querying GPU state unless necessary, converting nvidia shader ASM into SPIR-V or GLSL, and so on, are not generally going to be bottlenecked on the emulator's language of choice, but on the algorithms and designs that you use. Also a side note, the average comment about how "easy" switch emulation is because of "off the shelf nvidia parts" really misunderstands just how much work goes into this part. Switch emulation benefits greatly from the open source nvidia reverse engineering efforts from teams like nouveau, and others working on open source GPU acceleration on the switch like https://github.com/devkitPro/deko3d but also a great deal of effort from the switch emu devs themselves, writing tests cases to run on the switch to find edge cases and document behavior. It definitely is not easy work.
At the end of the day, every drop of performance counts, but some drops are much much larger than others. As such, the advantages of any language's performance characteristics will be heavily offset by the design choices the emulator uses. The creator of ryujinx is very comfortable with C#, and with good development practices, there's no intrinsic reason that one cannot achieve good performance in a C# emulator. And if one decides that it's worth the tradeoff to do some extra work for performance in exchange for a more comfortable development environment, then I say let them do what they want.
Shoutouts to both the yuzu and Ryujinx teams for all their hard work. I loved working on emulators a lot, and highly recommend anyone who's interested in contributing to give it a shot, its a really challenging and rewarding kind of project where there's always something new to learn about in a broad array of subjects.