+++
date = "2016-03-09T15:30:00-05:00"
title = "Citra Progress Report - 2015 P2"
tags = [ "progress-report" ]
author = "bunnei"
forum = 36
+++
This month we bring you the second installment of our two-part progress report on Citra in 2015! With this part, we discuss the evolution from Citra being able to barely run a few commercial games at a few frames-per-second, to where it is in 2016: Running many retail games at reasonable speeds, some of which are fully playable with near flawless graphics! We discuss Citra's new "dyncom" CPU core, the OpenGL renderer, per-pixel lighting, and various bug fixes. Lastly, we wrap up with an outlook for 2016, and a special thanks to everyone who has helped make Citra what it is today!
## Spring 2015: A New CPU, Renderer and More
The arms race to get games booting ran into a wall. Often, testing games and getting to crash points would be incredibly painful because of how slow the emulator ran. Instead of measuring frames-per-second, testers often referred to seconds-per-frame. Donkey Kong Country Returns 3D would sometimes require three realtime seconds to render a single in-game frame in the software renderer! It took over 90 minutes to capture all of the footage for a three minute video of Super Monkey Ball 3D!
{{< youtube t0TGSeQe1wE >}}
Within the next few months, [bunnei](https://github.com/bunnei) and [Lioncash](https://github.com/lioncash) replaced the old "ARMULATOR" CPU core in Citra with a better implementation that was both several times faster and much more accurate. Despite the fact that it was still an interpreter, this new core was still efficient enough that the performance implications were huge. With this new core, games that were light on graphics could reach above half-speed on very strong processors.
Shortly thereafter, a new developer joined the Citra team – [tfarley](https://github.com/tfarley) – with the ambitious goal of implementing a hardware renderer using OpenGL. Up until this point, Citra had used a software renderer primarily developed by [neobrain](http://github.com/neobrain) to render graphics. While a software renderer is great for development and achieving pixel-perfect accuracy, Citra’s GPU emulation had become the major performance bottleneck. Even with infinitely fast CPU emulation, the software renderer was so slow that no games would run full speed despite this.
While the rest of the team continued with other development efforts, [tfarley](https://github.com/tfarley) went on a month-long battle developing this new OpenGL renderer. All of this resulted in Ocarina of Time 3D running nearly perfect in Citra using OpenGL while running at a fairly decent speed! Below is a very early video of Ocarina of Time, before the renderer was completed and merged into CItra's mainline repository.
{{< youtube Hj8sPsB5qXQ >}}
## Summer: More Accuracy, More Performance
With the summer, development slowed down a bit – but several additional improvements were made. By this point, the team had already made lots of incremental advances in 3DS emulation, resulting in a significant number of retail games booting, such as Super Mario 3D Land, Fire Emblem: Awakening, The Legend of Zelda: A Link Between Worlds, Mario Kart 7, and many more.
{{< img src="entry/citra-progress-report-2015-p2/earlyunknown1.png" center="true" >}}
{{< img src="entry/citra-progress-report-2015-p2/earlyunknown2.png" center="true" >}}
{{< img src="entry/citra-progress-report-2015-p2/earlycrush3d.png" center="true" >}}
{{< img src="entry/citra-progress-report-2015-p2/earlymario3dland.png" center="true" >}}
{{< img src="entry/citra-progress-report-2015-p2/earlysteeldiver.png" center="true" >}}
{{< img src="entry/citra-progress-report-2015-p2/earlyluigi.png" center="true" >}}
{{< img src="entry/citra-progress-report-2015-p2/earlylinkbetweenworlds.png" center="true" >}}
{{< img src="entry/citra-progress-report-2015-p2/earlymajorasmask.png" center="true" >}}
{{< img src="entry/citra-progress-report-2015-p2/earlymk7.png" center="true" >}}
{{< img src="entry/citra-progress-report-2015-p2/earlyfireemblem.png" center="true" >}}
But there was still one major issue that was blocking many games: video playback. 3DS games use a proprietary format known as “MOFLEX” to play video clips, which are commonly used for intro logos, cut scenes, and more. Not only was the video format unknown, but any time a MOFLEX video was used, Citra would hang in an infinite loop for unknown reasons. However, this issue proved to be no match for our team – within a matter of weeks, Citra developers [yuriks](https://github.com/yuriks) and [Subv](https://github.com/Subv) reverse-engineered and implemented all of the mechanisms necessary to prevent hanging and play MOFLEX videos!
{{< img src="entry/citra-progress-report-2015-p2/3.png" center="true" >}}
Bravely Default's intro sequence relies on MOFLEX video support
With many games now running stable with fairly accurate rendering, it became evident that with a bit more speed some titles would not only be playable in Citra, but enjoyable to play. On top of this, more speed would make testing even easier, so with a huge library of games now working, the task again came to making things faster.
The cause of the slowdown was very obvious: Citra’s emulation of 3DS vertex shaders. With emulators like Dolphin and PPSSPP, your GPU uses shaders to emulate the target system’s GPU, which does not actually use any shaders of its own. The 3DS, on the other hand, has a more modern GPU that natively supports its own shaders – which are not as trivial to emulate in the same manner. The approach that we took was similar to CPU emulation – and we were using a pure interpreter for the job. As such, the solution was pretty obvious; Even a naively implemented Just-In-Time (JIT) compiler would make our shader emulation scream. With that in mind, [bunnei](https://github.com/bunnei) set out to implement a vertex shader JIT.
While it took several weeks to develop, the difference in speed was very obvious. Vertex heavy games were sometimes two or three times as fast, allowing some games like Ocarina of Time 3D to near full speed in many areas!
{{< youtube yhLEs4yEmlU >}}
## Autumn: Closing out the Year with a Bang!
After a brief summer hiatus, development on Citra began to pick up again with autumn 2015. While Citra now had a library of games running without severe problems, many still relied on more advanced graphics features that had yet to be reverse-engineered. One of these more widely used features is fragment lighting – a feature that enables complex lighting calculations to be performed on a per-pixel basis. A major breakthrough was made when hacker and homebrew developer fincs made major strides in figuring out the 3DS fragment lighting implementation. Immediately, [bunnei](https://github.com/bunnei) began embodying this work into Citra.
{{< img src="entry/citra-progress-report-2015-p2/rotatecube.gif" center="true" >}}
An early fragment lighting demo running in Citra
Despite that it’s not a fully complete implementation of fragment lighting, the results have significantly improved Citra’s visuals!