TL;DR version: we’re not dropping any operating systems; we may add one or more new APIs while continuing to support OpenGL in the future. The new APIs are similar to each other in design.
About two minutes after WWDC announced that Metal (Apple’s new low-level high performance 3-d graphics API) is coming to OS X, I received a bunch of questions about whether we would support it, and what this means for X-Plane. Now that I’ve had time to watch the WWDC Metal videos (and read the Direct3D 12 preliminary documentation and the Mantle programming guide and watch the Vulkan introductory talk) I’ll try to clarify a little bit about Metal, Mantle, Vulkan, Direct3D 12, and what we might do with them someday.
So Many APIs, So Little Time
Recently there has been an explosion of new graphics APIs. Here’s the list. It’s long, so get coffee first:
- Metal is Apple’s new 3-d graphics API; it shipped on iOS last year and will run on the next major release of OS X. Metal’s API is actually objective C, which means you’re almost certainly not going to see it on a non-Apple platform. Metal runs on iOS devices with an A7 chip or newer; I don’t know what GPUs OS X 10.11 will support.
- Mantle is AMD’s low level 3-d graphics API. I don’t know what kind of weird state it’s in; drivers have been available for a while and there are shipping games using it, but it’s still a beta or something. Mantle is AMD and Windows specific (but could be ported in theory), and requires a GCN architecture GPU or newer (e.g. a Radeon HD 7nnnn or the new RX290s.)
- Direct3D 12 is the next version of Direct3D, coming out with Windows 10. I think it’s in beta right now. It is Windows only and I think will run on a mix of DirectX 11 and 12 hardware. (This isn’t that different from Mantle.) I think Direct3D 12 will be available for the X-Box One in the future, but I didn’t investigate consoles carefully.
- Vulkan is a proposed new cross-platform open low level API from Khronos, the group that manages the OpenGL spec. Vulkan’s rough design goals were announced a few months ago, in a joint announcement that featured developers from AMD, Intel, NVidia, Qualcomm, ARM, and Imagination – that is, almost the entire set of GPU vendors from the mobile and desktop space. AMD is apparently letting Khronos use Mantle as a starting point, and most of the sample code shown as Vulkan looks like Mantle code with the prefixes renamed from gr to vk. Vulkan would potentially run on Windows, Linux, and Android – it is the only candidate next-gen API for Android. So far Apple has said nothing about Vulkan support that I am aware of. Vulkan is thus simultaneously both the logical successor to OpenGL and the least developed of the four APIs. (The other three are either shipping or in beta.)
It should be noted that we care about all of the operating systems mentioned above:
- We are working on the Android port of X-Plane 10 Mobile now, so we care about iOS and Android for the mobile space.
- On desktop, Windows is our majority platform – last I checked we were at least 65% Windows, and this number has been growing. Windows is also the most heavily used OS where a user can build a true “gaming” machine (that is, a machine that uses a lot of watts to generate a lot of compute power), so having good graphics on Windows really matters.
- We are not dropping OS X – it’s still a significant platform, and as long as people want to fly X-Plane on OS X, we’ll let them. Mac hardware doesn’t really qualify as gaming hardware – every current Mac is a power-constrained by the standards of core gamers, but the machines are also not slow either – Apple makes viable machines for flight simulation.
- Linux Desktop support is always the question mark – by sales volume it is a platform we could drop, so we evaluate it each time we ship a new major version basis. But with the Linux port already done, help from Linux users on platform-specific code, and Linux running the same drivers as Windows, it’s not that hard to keep it working. If we can run the same next-gen API on Windows and Linux, that would be great. We don’t have the resources to do a port to a new graphics API only for Linux.
(In other words, whatever OS you care about, we’re not looking to drop it.)
How Am I Different?
The next question to answer is: how are these new APIs better than OpenGL? How are they different from OpenGL? How are they different from each other?
All four new APIs aim to provide higher graphics performance and fewer driver bugs, and they all do so with a few basic architectural changes that make them different from OpenGL:
- Threading, synchronization and queuing are all explicitly handled by applications with new APIs, rather than having OpenGL do these tasks implicitly without app intervention. This makes it possible to write 3-d code that leverages multicore, and also makes performance more predictable. (With OpenGL, synchronization is done for you, sometimes not efficiently.)
- Expensive operations are explicitly identified, so apps can perform them ahead of time or in background threads. This lets an app programmer know that the app’s rendering loop doesn’t contain any expensive (or sometimes-expensive) operations. (With OpenGL, expensive work sometimes just has to happen in the middle of rendering.)
- The new APIs let applications manage memory with more control than OpenGL. Here Metal differs from the other three APIs: Metal’s memory management is really “a better OpenGL” in terms of design (the driver still does a lot of work, but the rules for memory management are very clear),while Mantle, Vulkan and D3D12 all give applications control at a much lower level – basically with these three, apps manage graphics memory entirely by themselves.
A key observation: these four new APIs are all a lot more like each other than any of them are like OpenGL. If you ask me to write a rendering engine that supports any two of OpenGL, Mantle, Vulkan, Metal, or D3D12, my job is pretty easy until you add OpenGL into the mix. This is because OpenGL is missing fundamental operations possible in all of these new APIs, e.g. preparing a GPU workload on two threads in parallel.
Supporting Multiple APIs
In the future, I think it is possible that X-Plane could support more than one 3-D API. This is not an uncommon thing in the game engine world – lots of game engines support multiple back-end APIs; pretty much any title available for Playstation, Windows and X-Box is already doing this, as are many games ported to the mobile space. Typically the game engine abstracts the rendering API behind some kind of general purpose drawing layer.
To a limited extent, X-Plane already does this, and has been doing it for a while: we support three different rendering paths within the sim (HDR, no-HDR, and no-HDR with volumetric fog disabled). X-Plane 9 supported three paths as well (fixed function, shaders, and the in-development HDR mode, which was not accessible to users, but was in process for at least the last two years of X-Plane 9). Game engines often have to do this when the difference in capability between their high and low-end hardware is extreme.
We’re Not Going to Drop OpenGL
If we ever adopt a next-generation API, I do not think we would drop OpenGL support. All of the new APIs have something in else in common: they don’t run on old hardware. If we want to capture higher performance on DirectX 11+ hardware before we are prepared to drop anything before it, we’ll need to support OpenGL as well.
- In the mobile space, the iPhone 5 is very capable but can’t run Metal.
- In the Android world it may be that users have modern hardware and old drivers incapable of running Vulkan (due to carriers not updating their OS).
- We support Intel GPUs because they are very often the only GPU a user trying X-Plane for the first time has access to, and some of these may not be able to run modern APIs. (For example, a Sandy Bridge i5 is still a nice CPU with a usable embedded GPU, but it’s not a DX11 part.)
Which API Will You Choose?
The short answer is: it’s too soon to tell, and it might not just be one API. The real cost will be supporting any graphics API other than OpenGL. Our preference is for as few APIs as possible covering as many operating systems as possible, so if Vulkan ends up having wide platform coverage, that’ll be great. But if it turns out that we need to go to a few places to get high performance, we may have to swallow that pill.
It’ll Be Done Tuesday, Right?
This isn’t something that I’m going to start coding tomorrow. Vulkan isn’t even released as a spec, OS X 10.11 and Windows 10 haven’t shipped, and there are plenty of things I can do now with the existing OpenGL rendering engine to make X-Plane faster for everybody.
The process of supporting a new API will probably also start with a cleanup exercise designed to limit how much code is talking to OpenGL directly. So this is a long term architectural change in the sim, not something we bang out in a few weeks.
What About Plugins?
Plugin developers may be wondering: how is my plugin going to work if you move to another graphics API? Right now, plugins use OpenGL directly.
I think the answer is that an X-Plane running on a next-generation graphics API may have to also be running OpenGL, just for plugins; the app would have to create an OpenGL environment that looks believable for plugins to render into, then composite the results with X-Plane’s work. This implies having some kind of interop facility as part of the 3-D API. (This almost certainly exists on Metal via IOSurface; I don’t know about the other APIs.) It’s too soon to know what interoperability options will look like between OpenGL and next-gen APIs – that’s something where the devil is in the details.
An OpenGL sandbox for plugins is actually what we planned to do to support a Core-only OpenGL profile on OS X; going forward we may decide to target Metal instead of Core OpenGL; if we’re going to go to the work of sandboxing plugins in an OS X specific way, we might as well get the fastest API possible.