How are we supposed to transition to Metal?

Apple is deprecating OpenGL ES in the near future from iOS, tvOS and even MacOS X. We are supposed to use Metal instead. Yet both SpriteKit and SceneKit are broken and buggy when it comes to Metal support.


As an example, an SKTransition will take a screenshot of the source and target scenes and eg. fade between them. The problem? If you enable Metal, these screenshots will be shown upside down. (With OpenGL they look just fine.)


Dealing with shaders, especially when it comes to SceneKit materials, is a nightmare. Supposedly SceneKit transparently detects and translates glsl shaders to the Metal equivalent, but this functionality is buggy. This cross-compiler seems to be buggy and very nitpicky about syntax, and doesn't support glsl 100%. The worst part is that if compiling the shader at runtime fails, there's absolutely no way of knowing where the problem might be because Xcode outputs absolutely nothing. No error message, no logs, nothing. (If there is a way to make it output an error log message, I haven't found it.) The only way to know that your shader failed to compile is that it isn't working on screen. Essentially you would need to hunt the problem completely blindly.


"Well, just write the shader directly using Metal syntax, then." Except that it's still possible that your app will be run using OpenGL (eg. on the simulator, and possibly on older devices), and there's no way of distinguishing at runtime between the two. Obviously if you try to compile a Metal shader that uses something that glsl doesn't support (which is pretty inevitable), it will once again fail, and your shader won't work, breaking the game.


The only way to make sure that your game will run properly is to always force OpenGL. Which is being deprecated soon! Yet, if you try to support Metal, chances are your game will be broken and not function correctly, because of the poor support in both SpriteKit and SceneKit.


What exactly are we supposed to do?

Replies

Never mind any of the above. There's an even bigger problem:


I got my game working for both OpenGL and Metal (except for that SKTransition problem, which flips the screen vertically if an SK3DNode is being used). The bigger problem is: When I run the game on an iPad Mini 2, when using OpenGL it runs at a very stable 60 FPS, but when using Metal, it runs at a relatively stable... 45 FPS.


Needless to say, it looks horrible. All movement is very jittery and unbearable.


I thought Metal was supposed to be more efficient than OpenGL.

While it is very relevant to bring up such issues I'd also like to say Don't Panic! There's no way that the OpenGL support will go away anytime soon, the deprecation is mainly a strong signal that continuing development using the old technologies is not recommended. In this case there's even a define that will silence the deprecation warnings related to OpenGL and OpenCL

Greetings carstengp,


Does there exist any indication of when OpenCL and OpenGL will officially drop from macOS?

The Metal framework exists as an upgrade path for macOS native applications, but what about software that requires GPU on macOS and Linux?


Should we start creating an alternative code path or perhaps an entirely separate fork for macOS?

Ideally, I hope that OpenCL 1.2 support remains on macOS for legacy support with cross-platform applications.

What are your thoughts?


Thanks,

Robert