16 ms·
Overhauling Mario 64's code to reach 30 FPS and render 6x faster on N64 [video]
- Gravyness 5y agoIts absolutely amazing the level of expertise and dedication a single person can have on the inner workings of something.
- Forgeties79 5y agoMario 64 has to be one of the most dissected games ever. It’s kind of wild what speed runners, modders, etc. have uncovered.
- modeless 5y agoDoes this mean that Nintendo could have theoretically shipped Mario 64 as a 60 Hz game on N64? I know some of this stuff requires the RAM expansion, but not all of it.
- IntelMiner 5y agoI know they don't "owe" anyone anything. But it is disappointing they've apparently declined to release their code changes It's also apparently unclear if the overhauled version will run on a real N64 or if it only runs in an emulator
- Quillbert182 5y agoHe is planning to release the source code at a later date. He is waiting because the source code is intertwined with a ROM Hack he made, and he is unable to release the improvements without releasing the ROM Hack in an unfinished state. The overhauled version will run on a real N64 as long as it has the RAM expansion pack.
- sonicggg 5y agoHe has patreons backing this project, so he may actually owe them something.
- tedunangst 5y agoHe owes them a credit at the end of the video, which they have received.
- sonicggg 5y agoWell, then as they say "a sucker is born everyday"
- AnIdiotOnTheNet 5y agoI'm a patron of Kaze, and all I want is to keep seeing amazing N64 romhacks. Though having my name appear in the video credits is kinda nice too.
- djmips 5y agoIt will run on a real N64 but it needs the memory expansion. So that's one thing he mentioned but people do gloss over. It (the extra memory) helped a lot in reducing memory contention between the CPU and the GPU.
- amatecha 5y agoWow, this is amazing! Plus he's adding split-screen co-op mode??! Mind blown. Impressive work, seriously.
- andai 5y agoApparently the original game was meant to include it, but it was scrapped because it made the game run too slowly. Now that the game has been almost entirely rewritten for performance, this feature can be backported in :)
- deleted 5y ago[deleted]
- ydnaclementine 5y agoAt some point, these older games should be open source. They can follow the doom/quake model where textures/art aren't included, and Nintendo can also still sell the games on newer consoles for convenience because not everyone will want to compile it themselves I guess you could argue a mario 64 custom levels mod competes directly with a new mario game. But halo and cod sell fine. Maybe I have a bias that thinks Nintendo is fearful that custom mods for old games will be more popular than anything new and official
- makotech221 5y agoOnly under an economic system that abolishes private property. Won't ever happen under capitalist governments, unfortunately.
- flatearth22 5y ago[dead]
- tenebrisalietum 5y agoIntellectual property is imaginary property, private or not. it's not a real thing until committed to a medium. Upkeep of the fiction that intellectual property is real property has societal benefits for a limited time insofar as works of art - and the original idea of copyright was reasonably limited. Over 100 years is inhumane.
- makotech221 5y agoNo it has benefits only for the private property owner, never for society at large. All private property is this way. Capitalism is a system that deifies private property, so it will only ever get more and more 'private'
- bscphil 5y agoIf capitalism is the nail, private property is the hammer. Quite a lot of development that the United States wanted to see happen in the west (which enriched it immensely) was done because it was willing to make grants of private property to the companies (largely railroads) doing the development. You can debate whether capitalism is (or should have been) the only method for getting things done, but the use of private property as a viable incentive for driving innovation within that system is not really debatable.
- vmception 5y agois there any part of this video that is a side by side comparison? didn't see any obvious marks in the description or comments
- noobermin 5y agoSmall thing but I hate how a lot of the modding community (and retro gaming) has turned to videos and youtube, I just don't have time to watch a 20 minute video on these things. I'm often searching high and low for basic documentation and descriptions of things and google always recommends some 20 minute video, it's infuriating.
- tiborsaas 5y ago- Speeding up the video saves you time - Listen to the audio only, occasionally take a peek, don't tell me you are being productive 16 hours a day - VideoGames are visual so it's a natural to present them with video, hardly a blame for the authors
- butwhywhyoh 5y agoHe's not presenting a video game -- he's presenting the technical details of speeding up a video game. 90% of the video is just stock footage in the background while he talks about the technical details. A better approach would be a written article supported by a video demonstrating the speed up.
- RicoElectrico 5y agoYeah, being to the point is crucial in these days of abundant content. Sometimes I wish they reinstated the 10-minute limit.
- pasmat 5y agoThe good thing is that a platform like YouTube can support creators like him spending so much time on thing that wouldn't otherwise perhaps be financially feasible, even if his contributions to the modding community aren't as easily digestible.
- CrazedGeek 5y agoAt least for Super Mario 64, Ukikipedia is a good text-based resource: https://ukikipedia.net/wiki/Main_Page https://ukikipedia.net/wiki/Main_Page
- phillipcarter 5y ago"roll those loops back up and don't compile in debug mode to achieve significant performance gains" is not the takeaway I thought I'd have going in, heh.
- infogulch 5y agoUnrolled loops trade instruction cache for cycles. Whether it's good depends on what your bottleneck is, in this case ram access is a bigger bottleneck than cpu due to being shared with the rendering coprocessor. I wonder if we'll hit this crossover point again in the future.
- monocasa 5y agoAnd the code N64 was particularly unrolled for whatever reason. IIRC, there was one game that bit me when writing a JIT N64 emulator because there was a single code stream with no branches that was larger than multiple MMU pages. My JIT kind of assumed that actual code in practice wouldn't be larger than the actual N64 I$ without branching. Womp womp. But hey, I guess I don't want to be judged on my mid-90s code either.
- phire 5y agoFrom what I understand (as I didn't start writing code until the mid-2000s), loop unrolling was a very highly regarded optimisation of the early 90s. And it was a very long time before programmers (and compilers) realised just how bad of an idea loop unrolling was once we entered the era of superscalar processors with instruction caches and half-decent branch prediction.
- hugey010 5y agoIt never occurred to me that loop unrolling could end up being a de-optimization due to compiler optimizations!
- quietbritishjim 5y ago
- arriu 5y agoThis is a serious amount of effort for what I imagine is little payout. I really enjoy work like this and hope that he is able to make a living off it. Anyone have thoughts on how to make projects like this more sustainable?
- jandrese 5y agoHe does have a Patreon so it's not entirely volunteer work.
- tantalor 5y agoArt doesn't need to have a payout or be sustainable.
- eigenvalue 5y agoThis seems to clearly be a passion project. The author is being paid in the satisfaction that he gets in improving this famous game way beyond what the original creators managed to do, all while being bound by the same technical limitations. He also gets to show off his skills to a fairly large (in absolute numbers at least) global audience of people who are also really into this particular game. I doubt you would see someone going to such great lengths for an obscure title that few other people would appreciate or care about.
- magpi3 5y agoSomeone on HN once said, if you want to build a reputation and a brand, do interesting things and talk about it. This is the perfect example. No, this will not make him money because there is not a large market for superior Mario 64 performance, but you sure as hell know who he is now, don't you? And I will say his youtube skills are top notch. The video is very entertaining and informative. I just cannot imagine this person will have trouble making money in the future. EDIT: Added a missing word
- panic 5y agoYou can give him money using Patreon: https://www.patreon.com/Kazestuff https://www.patreon.com/Kazestuff
- colechristensen 5y ago
- vmception 5y agopretty amazing what you can do when you push the release deadline back by 26 years.
- iforgotpassword 5y agoHeh, but even then, 6x is still impressive. I doubt in 26 years you could optimize a tripe A title from today to the same extent. It seems that the vast majority of optimizations is actually achieved manually and not through Compiler magic and other modern tools. But then again maybe in 26 years we will have magic tools that will get the job done. ;)
- NobodyNada 5y ago> I doubt in 26 years you could optimize a tripe A title from today to the same extent. Well... https://news.ycombinator.com/item?id=26296339 https://news.ycombinator.com/item?id=26296339
- dmix 5y agoWow Rockstar released his optimization. That's awesome.
- iforgotpassword 5y agoI knew this would come up :-) Doesn't improve overall game performance though.
- Hikikomori 5y agoLoading times were however the main reason I couldn't enjoy that game. Took like 15 minutes from starting it to joining some MP game with friends, then 5-10 minutes between each game looking at loading screens.
- maccard 5y ago> I doubt in 26 years you could optimize a tripe A title from today to the same extent. It helps that in this very particular case it was made much easier for him by basically enabling optimizations in gameplay code (it's fairly unlikely you'd get that one for free these days). But look at the difference in quality of launch titles for the PS4 vs what's being released today - that's 7-8 years worth of development. It's not unreasonable to expect that with another 2x that we could make similar gains. I've worked on a few AAA games and seen the codebases (and more importantly the issue trackers and profiling data). Today lots of these problems are "known" but it's a tradeoff - do you spend a person-week on fixing a frame drop in an awkward area or do you spend it on an incremental improvement across the board.
- pupppet 5y agoI always wonder if the original devs ever find these videos and are like oh shit we should've done that.
- MBCook 5y agoIt would certainly be interesting to see their reaction. Mario 64 is a bit of a worst case as the game was being developed at the same time as the hardware and had to get out on day one no matter what. Between the Japanese and US releases I believe they even fixed some bugs. Some of the things he did seem quite obvious, like cutting down the repeated calculations for every single coin on the screen. You have to think they would’ve thought of that if they have the time. It would be interesting to see a series like this on a number of games over the console’s lifetime. Especially if it highlighted the tips and tricks the developers started to learn to get more out of the hardware over time.
- munk-a 5y agoSpeedrunners famously need to hunt down first press cartridges on the US release because the Shindou release fixed the bug that allows BLJs (backwards long jumps).
- SLWW 5y agoThis explains a lot for me; since I kept trying to achieve a BLJ but for whatever reason I couldn't. Now, years later, you comment explains a lot O_O
- satsuma 5y agoit's worth noting that the virtual console (wii, wii u) releases are built off of the original nstc edition, meaning backwards long jumping is in play. but the most recent 3d all stars edition is based off of shindou, meaning blj's are not possible.
- orblivion 5y ago> You have to think they would’ve thought of that if they have the time. Stuck forever in the issue tracker as "priority: low"
- Lerc 5y agoThis is a good lesson about the benefit of time when it comes to software development. Mario 64 could have been a much much better game on the same hardware, but the time cost would have resulted in a release late enough that the entire game might have been considered irrelevant. Game consoles have had the benefit of the platform freezing for a few years allowing improvements to accumulate and later titles utilizing knowledge gained from the earlier titles. Much of the software we use every day could benefit from this level of scrutiny but the pressure to deliver on time means we won't get to see such benefits unless it becomes a crazy persons labour of love.
- ChrisRR 5y agoIt's not completely about time, and as much the benefit of 25 years of experience, not writing for brand new prototype hardware, not writing a brand new 3D engine when 2D had been the norm for decades.
- AstralStorm 5y agoThat's the part about batch rendering. Everything else there is architecture specific and typically not a problem on modern hardware anymore, unless you really force it to its limits. The coders accidentally optimizing to reduce GPU compute load when there's GPU compute to spare and memory bandwith is limited, for example.
- noobermin 5y agoThis is why honestly developers need to stop seeing issues as technical problems and more as being social ones (which they often are).
- nomel 5y agoThis is why we have product software engineers, and UI designers. The UI is a social problem and the purpose/goal of the product usually is. The guts that make that UI and achieve that purpose are very rarely social.
- finnh 5y ago
- YesBox 5y agoHow would one learn about this depth of C and its optimizations? I'm interested in it as an art form, something to do in my spare time.
- bfz 5y agoapt-get install linux-tools perf record -g myapp perf report Play with the output for a few weeks. "Why is this slow?" is a never-ending question leading down infinite corridors and weird specialist tools. Cachegrind and VTune are also instructive to play with
- joshspankit 5y agoStart with assembly
- Maursault 5y agoMachine code is only moderately less convenient.
- panic 5y agoFamiliarize yourself with the tools for measuring performance on whatever platform you want to optimize for. Then you can just start messing around and seeing what kinds of things make the number go down.
- nomel 5y ago> Then you can just start messing around and seeing what kinds of things make the number go down. And this will almost certainly require a deep understanding of the instruction set, and dropping into inline ASM, periodically.
- panic 5y agoOptimizing memory layout and reducing allocations are pretty ISA-independent. But yeah, at some point you will have to start looking at the assembly to optimize further (even if only to know when to tell the compiler to stop inlining a function that causes tons of register spilling inside a tight loop).
- soulbadguy 5y agoNaive question : how did we get access to the source ? Is that from a disassembler or did the source code leaks at some points
- BizarroLand 5y agoIIRC from an earlier read about this, the code is from a disassembler.
- sonicggg 5y agoWhy wouldn't Nintendo release the source, considering they're is little commercial value in this particular game now?
- shadowofneptune 5y agoVirtual Console (or whatever Nintendo calls it now) releases mean that the game can be a moneymaker decades past the end of retail sales. You also see this with MS-DOS games, sometimes modders will voluntarily stop making their fan patches if an official rerelease makes it to Steam.
- charcircuit 5y agoNintendo, like many other Japanese companies, are very protective of their IP.
- mook 5y agoThat assumes they even still have it. Not sure about Nintendo in particular, but many other games of the era are known to have lost source code. Nintendo did (supposedly) use an emulator for the N64 games in Nintendo Online (for the Switch); so it's possible that they don't have the source (or maybe it had enough machine-specific code that doing a source port would be more effort). Of course, if they can re-sell it as a subscription service they probably would want to avoid releasing the source anyway…
- 5y ago
- tambourine_man 5y ago> I don’t fault them for making most of these mistakes. C was a rather new language at the time. In the 90s? It was 20 years old by then and mostly ruling the world already.
- kibwen 5y agoNot on game consoles, and perhaps not even for PC games more generally (hedging my bets in case Walter Bright waltzes in and starts talking about how he wrote Empire in C in 1972 or something :P ). It wasn't until the mid-90s that C ate the game industry. Recall that C wasn't standardized until 1989, that C compilers weren't free or ubiquitous or good, that plenty of now-forgotten contemporaneous languages existed, and that making entire games in assembly was still quite popular and liable to get you better performance anyway.
- tambourine_man 5y agoInteresting. I didn’t know console’s market was so different. 90s PCs were dominated by pascal and C variants on the OS and app front, with a tiny bit of assembly sprinkled here and there.
- MBCook 5y agoI believe the Nintendo 64 is the first Nintendo console where using C started to become prevalent. I’m not sure about the Saturn or PlayStation. But I know the 16 bit consoles were usually assembly because they had such a limited resources.
- lynguist 5y agoI don’t know about the Saturn, but the PlayStation is the first mainline console that I know that had a C SDK and games were written in C on it. The first Nintendo handheld to use C was the GameBoy Advance which was also the first Nintendo console that had an ARM processor. It’s true that C only really took off in the 90s while the 70s and 80s are more of a proto-C era which still built the entire Unix system.
- midnightclubbed 5y agoWow, so, ok. Former N64 programmer here, so my take is certainly biased but here goes. This guys has clearly done a lot of work, building on top of the existing reverse disassembly of the Mario 64 codebase and has a great understanding of the heavily dissected 25 year old hardware. And that's where my paise stops. The level of snark here is outstanding. Maybe its a cultural thing, maybe he's trying to hype up his Patreon, but he comes across to me as a complete egotistical a-hole. Does he really think the Nintendo programmers were 'smelling the grass' rather working 24/7 to get a ground-breaking game shipped. He does his best to call the team who made several of the most influential and important video games of all time incompetent. Breaking down his snark: - The RSP/RDP co-processor had microcode that the game programmers interacted with (you generated a rendering command list on the CPU and called a library function to start the RSP processing that scene). So any criticisms of things the Mario team could have moved to the RSP (ie billboard calculations) are short-comings of the microcode made available by the NCL driver/hardware team - post launch there were regular revisions to the microcode and optimizations made available. - A lot of the matrix operations were provided in library form to game teams and you were encouraged (forced) to use them rather than rolling your own - there was probably a concern that an overly aggressive optimization would send bad data to the RSP/RDP and cause issues on current or future hardware revisions. The divide by zero checks were likely there for similar reasons - the RSP microcode could run in a mode that skipped near-plain clipping of triangles, which was faster but would blow up spectacularly (huge jaggie triangles all over the screen) if you had triangles that did indeed clip into the near plain. - I have not seen the Mario 64 source but I imagine some of the lowest level code was written in mips assembly but has been decompiled into C. I may be wrong here, but if that is the case there were likely branch-delay-slot optimizations and cycle counted operations that have been trampled by the reverse engineering. I may be off-base here so would love to know if that is the case? - Yes the gameplay code has unused variables, duplicated code, etc. But this was a brand new genre of game, there would have been a lot of experimentation, tuning, things would have been in flux until shipping and there certainly was no time to refactor and run the risk of breaking something. - I suspect the debug flags in gameplay code were to avoid compiler bugs. The mips compiler would sometimes emit some back-back floating point operations that caused the N64 mips cpu to hang (but was fine for all other mips processors). That may have affected the gameplay code with optimizations enabled. Later there was a command-line tool you had to run on your game elf that would look for this bad combination of instructions (and you would then change the offending code until the compiler did not emit the 'bad' instruction combination). Gcc was not allowed by Nintendo until much later, and had its own issues. - Older floating point units were less predicable with numerical accuracy, rounding errors etc. If early testing showed differences in game control/feel between the debug and optimized builds then I can see why the team would be more comfortable shipping with debug code rather than risking a bug that was not picked up until after you manufactured a million or two cartridges. - The memory bank conflicts were well documented and games worked around/with that knowledge. Mario 64 was likely well under development before that information was known. As others have pointed out, using the memory expansion module is cheating - that gives you a whole bunch of un-conflicted memory banks to use. 2x the memory also gives a lot of optimization oppertunities. - I don't see a 6x speedup. I see ~10% gains in most systems and a best case frame time improvement from 29 fps to 41 fps. Which is pointless. An NTSC tv runs at 60Hz, you either hit 60fps or 30fps, anything in-between results in horrible tearing of the screen or your frames bounce between 60 and 30 and movement feels horrific. The game was optimized to hit targets and to ship. - His split screen optimization is crap! Reducing load on the RDP (rasterizer) by killing rendering area (big black bars on the screen) is lazier than most everything he snarked on. The slightly better approach would be to ab-use the TV output timing registers so that the screen buffer can be less than 320x240 but still fill the screen. You trade black bars for smeary sludge but on the target NTSC TV that was generally the way to go if you didn't want your game rejected by Nintendo QA. Or actually re-write the renderer and reduce the amount of pixel fill. - And a minor nit pick, the sound processing was not done on the CPU (as he claimed). The cpu built audio command lists that the RCP then used to generate the output waveforms.
- jart 5y agoNow that's a 10x programmer if I ever saw one. I'm sure the compiler helped too. The generated code of C compilers from the 80's and 90's versus the generated code created by something like modern GCC -- it's like night and day. We're able to build faster tinier software than we ever have before, and it really helps to illuminate the impact modern tools have had when we apply that advantage to something old we already know.
- jpgvm 5y agoIronically part of the problem was that the optimising compilers of today make different space and memory throughput tradeoffs vs CPU execution speed that don't hold for the slower memory architecture of the N64. Namely optimisations like loop unrolling that benefit modern CPUs are a detriment to the N64. I think most of the cool stuff he did here is around restructuring the code to remove contention on the RAMBUS as it can do operations on different banks in parallel when servicing reads/writes from different components vs causing contention if they wish to read from the same bank. Also writing directly into the bank that will be used by the graphics unit from the CPU while disabling cache features of the RAMBUS, freeing up the cache for more code pages for the CPU to use. Moving more of the code to execute on the "maxed out" GPU and actually cutting execution time because of the reduced memory bandwidth requirements was also pretty neat.
- wiz21c 5y agoAfter 20 years not coding (or coding in python, ruby, R, that sort of thing), I started up writing code in rust that needs performance (emulator). I was absolutely amazed by the quality of the compiler today compared to what I had 20 years ago. It's really amazing to see how clever it has become.
- djmips 5y ago10x in one dimension. But not by the modern definition of 10x since this actually took a lot of time. This is more like a craftsman or artisan who toils away until they are ready and the result is perfect.
- jasinjames 5y ago
- randomifcpfan 5y agoGreat work, but a significant fraction of the improvement comes from installing and using the 4MB RAM expansion pak, which isn’t really a fair comparison.
- itsgrimetime 5y agoInstalling and optimizing the code to make use of the 4MB expansion pak*
- rincebrain 5y agoMy understanding, which may be incorrect, is that while one of the base optimizations he performed requires the second 4MB, most of the rest of the optimizations definitely do not. So while I would not be surprised if he made some changes that assume more RAM is available in total beyond what was mentioned in the video, I believe most of the refinements covered could still be applied without.
- fareesh 5y agoWould be nice if it became the norm that the source code and assets for games were available as an open source purchase after X years
- lynguist 5y ago25 years ought to be enough, no?
- Timpy 5y agoNone of the games I play these days are CPU intensive so while I understand FPS is important to a large group of gamers I have never paid attention to it. Before clicking I thought "does frame rate really matter for Mario 64? How big of a difference can it make?" I'm absolutely blown away, I can't believe how smooth this looks. I don't know what else to say, I'm speechless. Stellar job. Vroom vroom.
- simooooo 5y agoEver played on a 144hz+ monitor?
- antifa 5y agoHigh framerates are cool but often I wish more games had the option to cap framerate at 30/40/45 and use less battery/produce less heat instead of racing to 120fps.
- wilg 5y agoI'm the opposite - I need the framerate to be as fast as possible. I can't even look at a 30fps game!
- darepublic 5y agoVery interesting video and it brought back a lot of nostalgia. At the time this came out I was blown away by it. Remember watching some kid play the bbomb level at the department store. Looking back as an adult I no longer feel the awe, but have the greater satisfaction of learning about the ram bus and low level programming considerations
- gnutrino 5y agoI remember playing it at the store thinking we had reached the pinnacle of computer graphics, and that there was no way they could get better. Boy was I wrong! Still one of my favorite games of all time.
- Cloudef 5y agoSubmitted this few days ago but did not get any points. I have no idea how HN works
- namrog84 5y agoTime of day and day of the week can impact such things. Lastly, that's just the fickleness of social media sometimes. Sometimes a thing will take off and sometimes it won't. A recent example is Among Us was released for 1+ year as almost a 'failure' with very little players. Received no major updates and just went by unnoticed until the right people pushed for a thing and now it's seeped into so many other things. e.g. Among us player count https://i.imgur.com/M1j0UOw.png https://i.imgur.com/M1j0UOw.png