Search Unity

Shader GPU Instancing. Not work on android ???

Discussion in 'General Graphics' started by unity_5fpsmegasupergiperprogramer, Aug 9, 2019.

  1. unity_5fpsmegasupergiperprogramer

    unity_5fpsmegasupergiperprogramer

    Joined:
    Dec 1, 2017
    Posts:
    101
    Hi, everybody.

    I noticed that when you set the "GPU Instancing" flag for the material, it does not work on all mobile platforms.

    Of the 3 modern phones, only 1.

    What are the device requirements?
    OpenGL 3.0+
    what else? Because on two phones does not work with it.

    Will something be done in Unity that works fine? Or will it be all crooked ? Prompt the owner of the PRO version which pays money.
     
  2. unity_5fpsmegasupergiperprogramer

    unity_5fpsmegasupergiperprogramer

    Joined:
    Dec 1, 2017
    Posts:
    101
  3. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,019
    What are the devices that it doesn't work on?
    Which render pipeline?
    Which Unity version?

    Instancing is disabled on Adreno 3xx, otherwise OpenGL ES 3.0+ is all that's needed.
     
  4. unity_5fpsmegasupergiperprogramer

    unity_5fpsmegasupergiperprogramer

    Joined:
    Dec 1, 2017
    Posts:
    101
    I noticed that the increase in FPS (20-30) gives only if the device has 8 cores, if 4 cores then the increase in FPS is almost zero. (I have tested it on 8 devices).

    Conclusion: "GPU Instancing" and "Vulcan" are ONLY for the most modern devices.
     
  5. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    184
    What's the particular reason for this? Our minimum target device has an Adreno 320 gpu, which is necessary as we need to support older devices. Not being able to have instancing reliably is a problem though. We're not supporting GLES 2, but this means our game will still show on the Play Store for GLES 3 devices, even if they don't support instancing. Which will mean terrible performance and bad reviews.

    On the subject, do you know if Texture arrays are supported on all GLES 3 devices, or is it a similar case to instancing, where it's disabled or not supported on some devices?
     
  6. unity_5fpsmegasupergiperprogramer

    unity_5fpsmegasupergiperprogramer

    Joined:
    Dec 1, 2017
    Posts:
    101
    On Google Play, there can be put ban on download. For example, according to GLES.
     
  7. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,019
    @Arycama On Adreno 3xx uniform buffer objects are terribly slow, so we disabled them and all functionality that relies on this feature. Our instancing implementation relies on uniform buffer objects.
    Texture arrays (2D) work on all ES3 GPUs except for Vivante.
     
  8. pixelR

    pixelR

    Joined:
    Sep 16, 2013
    Posts:
    58
    Hi, this is very useful info. One question though: what happens if I use instancing for my tree shaders but then run the game e.g. on a Moto G 3rd gen device, which has OpenGL Es 3.0 but an Adreno 306 GPU? Could it happen that performance will be worse than without instancing and using only standard static batching? I ask because I hope I can use instancing with the modern devices in mind, but don't have any penalty for users with older devices either.

    Additional details, that may influence your answer: developing now with Unity 2019.3 latest beta, URP and in some materials with Lux LWRP shaders, otherwise the Universal ones provided by Unity.
     
    Zhibiao likes this.
  9. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,019
    Instancing requires UBO, so it's not enabled on Adreno 3xx at all. I suppose static batching will not happen in this case, but I'd need to double-check that.
    It doesn't matter if it's Universal RP or anything else.
     
  10. newlife

    newlife

    Joined:
    Jan 20, 2010
    Posts:
    1,081
    So, at the end of the day, does it makes sense to use GPU instancing and Android / iOS now? It seems that there still several Open GL 2.0 devices around and also devices that doesn't support uniform buffer objects.
     
  11. hojjat-reyhane

    hojjat-reyhane

    Joined:
    Feb 4, 2014
    Posts:
    49
    Is there any way to find out if the device supports instancing or not?
    Setting require ES3.1 doesn't prevent from installing. So player will face empty scene!
    If I can check that, I can show a message box to them or change the functionality of game.
     
  12. xgonzal2

    xgonzal2

    Joined:
    Jul 3, 2012
    Posts:
    62
    I think SystemInfo.supportsInstancing is what you're looking for.
     
    Hurri04 and hojjat-reyhane like this.
  13. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Using unity terrain with standard Tree Creator. In built in render pipeline. I enable GPU instancing on the material of the trees... no instancing whatsoever going on. Literally drawing the barks and leafs one by one. I searched the forum and it's known issue and broken since 2017 at least. I mean, the main usage of GPU instancing would be on terrain trees. So... what gives?
     
  14. hojjat-reyhane

    hojjat-reyhane

    Joined:
    Feb 4, 2014
    Posts:
    49
    @aleksandrk Is there any consistent alternatives to instancing?
    I published a game using instancing, but about 20% of the players devices doesn't support instancing.
    My game is a 2d RTS which has thousands of animated soldiers in the scene.
    I have about 30 materials with different texture atlases(1024×512). Each atlas has 128 sprites.
    Normally if I use drawMesh() or sprite renderer, the setPassCall and Batches will increase significantly.
    What is the best solution for me?
     
  15. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,019
    Not really. You could try to decrease the number of batches.
     
  16. hojjat-reyhane

    hojjat-reyhane

    Joined:
    Feb 4, 2014
    Posts:
    49
    @aleksandrk That's really a bad news.
    How can I reduce the number of batches in a 2d game with thousands of units?
    The problem is when different units are separated from each other, the batches and setPassCall will be low.
    But when they are close to each other, the batches and setPassCall will be up to number of units.

    See the example with 2 texture and 10 units.
    When units are separated => batches: 2, setPassCall: 2
    Screenshot 2021-04-21 150940.png

    When units are closed => batches: 10, setPassCall: 10
    Screenshot 2021-04-21 151049.png

    I had this problem before, but I fixed it with drawMeshInstanced.
    Please check this post for more details.
     
    Last edited: Apr 21, 2021
  17. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,019
    If you make a 4Kx4K texture atlas, you can fit up to 32 1024x512 textures into it, so all your sprites could fit into one texture. Do you have anything else that breaks batching?
     
  18. hojjat-reyhane

    hojjat-reyhane

    Joined:
    Feb 4, 2014
    Posts:
    49
    Thanks @aleksandrk . I'm concerned about memory on mobile devices. Is it ok to load a 4K texture? And what if I have more units or need to increase the texture quality in the future?
    I have buildings and decorations in the scene but I have to test that how much they break batching in real gamePlay as they are not crowded.

    I'm using ECS, maybe RenderMesh is another option. I tested it with the 10 units example. With both close or separated units the result was 2 setPassCalls and 10 batches. If I can find a way to reduce the batches I think it is the best.
     
    Last edited: Apr 21, 2021
  19. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,019
    It's just 64MB if it's RGBA32 uncompressed. If you have 30 1024x512 textures right now, it's just 1MB more.
     
  20. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,019
  21. hojjat-reyhane

    hojjat-reyhane

    Joined:
    Feb 4, 2014
    Posts:
    49