Question

I have an app that uses a large collection of fragment shaders. The shaders are all compiled (on a background queue) on app launch. I tested the app on an iPhone 5S recently, and everything works, but the shaders take MUCH longer to compile. On the 5, compilation takes 0.8 seconds. On the 5S, it takes over 10 seconds. Does anyone have any idea what is going on here?

On an iPhone 5 (running iOS 7.0.2):

   2013-10-16 16:53:41.949 Socialcam[1096:1603] -[EffectCaptureController compileShaders]: start
   2013-10-16 16:53:42.753 Socialcam[1096:1603] -[EffectCaptureController compileShaders]: end

On an iPhone 5S (running iOS 7.0.2):

   2013-10-16 16:46:52.856 Socialcam[9757:1603] -[EffectCaptureController compileShaders]: start
   2013-10-16 16:47:03.303 Socialcam[9757:1603] -[EffectCaptureController compileShaders]: end  

EDIT WITH MORE INFO

Looking into the issue more, it looks like the iPhone 5S can not handle as many uniforms as previous devices. It's not actually a compilation issue. For one of my shaders, the link phase hangs for 10 seconds, then fails. For all the other shaders, there is no issue, and compilation and linking take only a few milliseconds. The shader in question uses a uniform array of 768 vec4s, and also three textures. If I remove any of the textures, or reduce the size of the array, it links without issue.

Was it helpful?

Solution

Since it sounds like large uniforms are the issue, here's some alternatives:

  • If you use OpenGL ES 3.0 when running on iPhone 5s, you can take advantage of Uniform Buffer Objects (UBOs), which allow much larger storage than uniform arrays. Also note that even if you don't really leverage ES3 features when running on an ES3-capable device, using an ES3 context gives you bigger limits (MAX_TEXTURE_IMAGE_UNITS, etc.).

  • Another good place for bulk data is textures. You're using three texture units in that shader, so you've got plenty of room to add a fourth, which can hold a 32x32 image with the same data as your uniform array, and probably be sampled faster. (The general advice would be to watch out for dependent texture fetches here, but there's no penalty for that on A7 so you're okay doing this in code specific to the new GPU.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top