RawTexture.update() is very slow on IOS 15

Hi guys, my game development is close to an end, so I am testing on some mobile devices.

One big problem is RawTexture.update() on IOS 15 is much slower than on Android. Here is my playground and experiments:

Update Raw Texture Time
iPhoneX(IOS 15): 18ms
iPhone11(IOS 15): 13ms
iPhone13(IOS 15): 9ms

The time on Android is less than 1ms.

I guess this problem is not due to babylon, but I don’t know where and how to ask the issue. :worried:

According to Slow performance on iPhone 12/Pro/… | Apple Developer Forums (notably see last post) it could be because sometimes textures are stored compressed on the GPU (even if the texture was not compressed in the beginning) and it takes time to uncompress it when reading back.

The post is for a readPixel/getBytes but I think it’s the same problem in your case where you are doing an update: the updated data must be compressed (on the CPU) before being uploaded to the GPU.

Unfortunately, I think none of the 3 solutions of the last post is possible in WebGL…


So I guess I can compress these raw data(comes from remote server) in other worker thread and then transfer compressed data into texture using engine.updateRawTexture() with compression on.

I don’t think so, the compression is done internally by Metal, from the outside (your code) the texture is uncompressed. Even if you compress it yourself, Metal won’t know it is compressed (there’s not a “compressed on” flag on updateRawTexture) and will re-compress it. Also, you don’t know which compression method Metal is applying (if any, as it seems it depends on the hardware / version of iOS). I’m afraid there’s not a lot of solution available…

updateRawTexture does have compression as its input parameter. In updateRawTexture, if you give a compression type, it will use gl.compressedTexImage2D with this type. So Metal can know which type of compression you are using. BTW, IOS supports ASTC compression.

I did a simple experiment to confirm: I have two array, one is raw, another is astc compressed. I feed raw
array into gl.texImage2D and astc array into gl.compressedTexImage2D. The latter one is much faster.

My bad, I thought you were speaking of the update method of the RawTexture class and not the updateRawTexture method of the engine.

I’m glad you found a way to make things faster!

1 Like