Pedal to the Metal: Inside Apple's new graphics technology
Amidst a particularly busy presentation of new technologies at this year’s Worldwide Developers Conference, Apple’s new graphics technology Metal probably had the most attractive demo, even if its exact benefits were among the most difficult to really understand.
In short: Metal is Apple’s new method of programming its graphics processors. The company claims performance gains without hardware changes and also says that games will be more detailed while still rendering at 60 frames per second. It sounds like magic, but it’s not: It’s the real deal.
The old state of the art
The summary of Metal is that does what it says on the tin—it unlocks the hardware, the “metal,” of the A7.
Graphics processors are essentially giant “state machines.” Picture a huge board of 1970s-style switches and dials, each labeled with a particular feature. Not all combinations of features are supported by the machine, but you’re free to flip the switches anyway. The combination of switches that you’ve flipped and dials you’ve tweaked determines the “state of the system.”
The job of the graphics programmer is to flip the right switches, turn the dials just so, and then feed the processor with geometry. This is the sequence that Apple is referring to when it mentions how many more “draw calls” per frame Metal is capable of.
With OpenGL, the current standard for creating graphics, programmers would flip each of these switches and tweak each of these dials individually. Each time they did so, the graphics processor would have to check that the state of the giant machine was still valid.
On the other hand, by using Metal, a programmer can instead define the state they need the machine to be in and then simply apply that state. Rather than tweaking each dial, flipping each switch, and jumping through the correct hoops, the process becomes more like checking off your sushi order from a menu.
From a user’s perspective, none of these particular details matter. The ramifications, however, will definitely be noticed.
The magic of Metal
Metal is designed around how GPUs and CPUs work today, especially (and specifically) when it comes to Apple’s A7. The A7 combines the GPU and CPU into one chip, and they also share a single memory pool.
Much of OpenGL is predicated on the notion that the GPU is (or could be) sitting on a separate card. By recognizing the fact that the GPU and CPU can access the same memory Metal unlocks a lot of power. Managing resources needed for drawing becomes vastly easier and faster. Many effects, such as reflections, require drawing the scene into an image and then using that image as an input in the final scene. Metal makes that far easier.
Modern GPUs and CPUs both have multiple cores—they can walk, talk, chew gum, and juggle all at the same time—and Metal provides a way to unlock all of that power by allowing for multiprocessing of graphics commands. OpenGL, by comparison, was always single-threaded and so couldn’t achieve a similarly adept usage of the actual hardware.
It isn’t just better graphics performance that Metal unlocks. It also supports a model of what’s called “general purpose graphics unit computing”—that is, using the GPU to run software that’s not necessarily graphics-related. OpenCL, which may be familiar to Mac users, is the open standard for writing software that executes on GPUs. Metal brings this kind of general purpose graphics programming ability to iOS. As the name suggests, OpenCL is very similar to OpenGL and so the design of Metal offers benefits for OpenCL similar to the ones it does for OpenGL. The baked-in idea that memory is shared between processors is a big win here too.
It’s the same story for multithreaded access. With the general purpose computing capabilities of Metal we’ll start to see the A7 really shine in unexpected ways. Apps like Capo will be able to leverage the GPU on iOS as it does on OS X in order to accomplish software tasks that previously hadn’t been possible.
Benefits for all
Which is all well and good, of course, but what does this all mean from the perspective of an iOS device user? In some ways, advancements like Metal are similar to building the Large Hadron Collider—we actually don’t know exactly what kind of opportunities we’ll discover, but it’s a brave new world and one that’s full of possibilities.
In a more practical sense there are concrete benefits that users will certainly appreciate, including faster load times (due to better resource management, pre-compiled shaders, etc.), more detailed worlds (due to the faster draw calls, more stuff can happen or be drawn), and likely a ton of applications that can use the GPU as a computational platform.
Of course, none of these apps simply appear because Metal has been introduced. Developers will need to adopt the new system and write their software specifically for it. But, the good news on that front is that the major game companies on the iOS platform have already demonstrated their commitment. Both Unreal and Unity, the two biggest game engines, have announced support for Metal. So, even without developers investing in understanding and implementing an engine with Metal, many big games that use those systems will benefit from its improvements anyway.
Taking a step back from the technical details Metal also has interesting political implications. Apple is, as it often does when it can, taking its destiny into its own hands. Rather than be tied up with The Khronos Group (the body responsible for OpenGL and OpenCL), Apple is free to make changes to Metal as quickly as it would like, in order to continue to best address its hardware.
This is a big strategic move, because it signals that the company believes it has the developer base and enough devices in the field to forge its own path. It’d be hard to argue that it’s wrong about that. It also signals that Apple’s taking gaming more seriously than ever before. Apple has famously never had a great platform for gaming, but with iOS that has changed—and it appears that Apple is changing too. Metal and the investment Apple’s made in its development and support shows that the company’s now taking gaming very seriously, indeed.
None of this is to say that OpenGL (or OpenCL) will be going away or won’t serve their own purposes. There are still many, many applications for which they’re perfectly well suited. But Metal is a lower level, more accurate, model of modern chips like the A7. And once we start seeing apps that use Metal we’ll start to see what the A7 is really capable of.