Metal online/offline compiler inconsistencies

Somewhere on the way from iOS 8.x to 9.x it would appear the online/offline compiler have diverted significantly and became a little .. unstable?


With both iOS 9.0.2/Xcode 7.01 and 9.1/Xcode 7.1 some shaders will compile at runtime but not offline or the other way round. For example they disagree if [[ buffer/texture(..) ]] attributes are required (documentation says no, online works without, offline requires it), they disagree on which math functions are available (sinpi for example, documentation says yes, online compiler/SDK yes, offline compiler/SDK no), and the online compiler is very easy to crash where the offline compiler reports errors in some of those cases and in others compiles just fine.


I'm further observing differences in which data types are compatible with which pixel format on texture attributes, depending on the device type I run on! On iPad Air half works fine to read from R16 whereas on iPad Air 2 float is listed as the only compatible format (both are on same iOS version 9.0.2). According to the documentation iPad Air would be correct. On a side note it would be useful if the compatible formats could be inspected form the API rather than finding out about these things by trial and error.


For context: I'm working on a live-coding environment for Metal which means I must compile online. The compiler differences mentioned above are observed by writing out the shader code right before passing it to newLibraryWithSource (there are no pre-processor macros) and pasting that into a .metal file in Xcode for hopes of more insights into what may be going wrong.


Any suggestions?


Thanks!

Replies

For example I can crash the MTLCompilerService on any of my Metal code by adding this ...


constant float size = 128;

constant float3 center((size - 1.0) / 2);


... then referencing 'center' in any function!


The same code works perfectly fine when compiled offline.

In direct response to your final question: "Any suggestions?"


Wait.


The potential and promise of Metal is somewhere magical, wonderful and ideal. The reality is something else, entirely.


But this is not limited to Metal. Sprite Kit is a bug ridden mess in all versions of iOS 9, and folks have been complaining about the many consistent and simple (almost foundational) problems since the beginning of the betas, with zero response from Apple.


Scene Kit has similar issues.


Both these frameworks have these problems regardless of choice to use OpenGL ES or Metal.


However SceneKit has definitely gotten extra issues and differences/problems when using Metal vs OpenGL ES.


Metal doesn't blend as well/correctly, nor does it perform as well as OpenGL ES in Scene Kit. Which is at odds with all the claims about it and particularly vexing because it defaults to using Metal.


Given Apple has not replied to, acknowledged or otherwise dealt with the issues seemingly all of the 20 Sprite Kit users of the world have discovered, I doubt you're going to get much headway on Metal from them, particularly as you're noting a raft of issues.


What's most fascinating is the alignment of these issues across all game rendering technologies. You are more right than you know when you say this: "Somewhere on the way from iOS 8.x to 9.x it would appear [[-- insert game rendering tech of choice --]] has diverted significantly and became a little .. unstable?"


There could be similar issues and extents of problems in other frameworks and APIs. I simply don't know because I haven't looked to see what other users of Apple's technology are experiencing.


Unfortunately there's nowhere sensible and organised for developers interested in pushing/playing at the envelope of what's possible with Apple's technologies (regardless of API/Framework choices) to discuss discoveries and record observations and learnings.


But what's really sad is that there's a genuine need for this.

There are too many annoying issues that we first blame ourselves for, then spend hours, days, weeks assessing the source of... only to find the APIs aren't doing as they're claimed to, or suffering some other more serious bugs.


Apple has more money than any entity that's ever been involved in making platforms. They have more control than any previous platfrom creator. They claim to value quality of production more than any other major platform creator. They've highly publisized "polishing of iOS" for version 9... yet that's simply not the case.


I can't suggest anything other than waiting.