Binding Metal textures to a shader using SCNProgram bug in ios 9.3

August 30, 2016

I’ve been moving an iOS app from OpenGL to Metal recently and ran into some undocumented issues with SceneKit, Metal and iOS 9.

A common way to bind Metal textures is to use SCNMaterialProperty objects referencing UIImages as in this SO post. This works fine except the UIImages take up a chunk of your app’s CPU memory. Binding GPU textures directly reduces the memory usage of your app. Unfortunately, there’s a bug with iOS 9.3 and SceneKit when trying to bind MTLTextures to a SCNProgram or SCNTechnique directly using either setValue or SCNMaterialProperty objects. The textures are uploaded to the GPU as seen in the GPU frame debugger but they are not being bound to the SCNProgram’s metal shader with either method.

With OpenGL I was using the handleBindingOfSymbol block of the SCNShadable class to manually bind the texture but I don’t see a corresponding function for Metal.

This is fixed in iOS 10