Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Performance on IOS Metal with unity 4.6.2p2

Discussion in 'iOS and tvOS' started by sfjohansson, Feb 15, 2015.

  1. sfjohansson

    sfjohansson

    Joined:
    Mar 12, 2013
    Posts:
    368
    I was really looking forward to try this but my to my surprise the performance was dreadful.

    I have a frame rate counter in the game( based on 1/Time.deltaTime )which is happily displaying 60fps even though it certainly doesn't feel like that in game.

    The game is running fine with 64bit 4.6.2p1 il2cpp...so unless there is something else in the patch release that affects the performance...this seems to be related to metal...either directly or maybe through some of my shaders that might not play nicely with it.

    How has this performed for you guys?
     
  2. CodeMonke234

    CodeMonke234

    Joined:
    Oct 13, 2010
    Posts:
    181
    Have you run and compared results with the flag enabled and disabled?

    I tried it enabled and didn't notice a change - good or bad - but this app pegged at 60 anyway...
     
  3. sfjohansson

    sfjohansson

    Joined:
    Mar 12, 2013
    Posts:
    368
    Just tried it...so enabling openGL instead gives back the frames so seems to be something with metal...xcode frame rate counter gives me between 39-60 fps with metal.

    Disabled the metal frame debugger which is enabled by default.. as according this apple article:

    https://developer.apple.com/library...rammingGuide/Dev-Technique/Dev-Technique.html

    That gave me some more frames but still there seems to be some apparent slow downs especially when rendering the semi transparent particles like smoke.
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Metal doesn't help with transparency, it helps with draw calls and stuff like that. You get more CPU time back.

    If your performance is bad, file a bug. Forum can't help.
     
  5. sfjohansson

    sfjohansson

    Joined:
    Mar 12, 2013
    Posts:
    368
    I was curious about the impact metal had on another users projects before starting to dig deeper.. and yeah... if I find out that there is no general issue and I'm not doing anything weird on my end I'd file a bug.
     
  6. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    My initial observation with 4.6.2p2 was a very stuttery camera movement when Everyplay is enabled, although the frame rate is still 60fps. So, I switched back to 4.6.2p1 which is fine right now.
     
  7. sfjohansson

    sfjohansson

    Joined:
    Mar 12, 2013
    Posts:
    368
    Did you also try the switching from metal to OpenGL in player settings?
     
  8. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    ok, so quick update: i've seen one bug report (with cool repro - thx to whoever reported it) - the big hit in 4.x metal is static batching (it actually slows things down a bit) - though it should be better in 5.x (we rewrote the static batching system). We are currently looking into it, and waiting for more small repro projects ;-)
     
  9. sfjohansson

    sfjohansson

    Joined:
    Mar 12, 2013
    Posts:
    368
    That could certainly explain the sluggishness as my environment uses static batching, my project is quite big but I could split of an environment slice and put a camera on path or something if that would be of help.
     
  10. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    @sfjohansson nah, if it is heavy on static batching side - we already have all we need to investigate, so just move on for now 8)
     
  11. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    328
    @Alexey so are you saying that the game will run better if we turn off static batching completely in Unity 4.6.x?
     
  12. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    >>so are you saying that the game will run better if we turn off static batching completely in Unity 4.6.x?
    it depends - most likely no (as you will start paying unity-draw-call price). It is just something that is unnecessary slow on metal
     
  13. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,960
    Is it because of something inherent to the way metal works, or something with Unity's implementation?

    (in other words, to get it fixed, do we need to bug Apple, or you? :p )
     
  14. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    375
    My game appeared to have slightly lower fps/performance when set to metal on my iPhone6.
    Where as the default settings/automatic which works for iPhone4 and 6 provided better performance on the iPhone 6 >_< ?
    Isn't metal supposed to be better, if not a lot better at least not worser? O_O

    Edit : Just read all the posts above, summary : looking forward to Unity 5 and its metal improvements ^_^ keep up the good work Unity team!
     
    Last edited: Feb 18, 2015
  15. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    Just heads up: we prepped some update to the way we handle dynamic geometry and static batching in 4.x (now the idea of bringing it to 5.x gives me a huge headache, but who cares about us, unity devs, right? ;-))
    I cannot yet give you an ETA but i will post here when there are more details (and sure release notes will show it in clear sight).
    Also - if you used internal profiler to check for performance - some issue was also fixed (it seems that [CAMetalLayer nextDrawable] actually waits for vsync, or smth similar, and this was accounted in cpu player time, giving a bit wrong picture). Anyway, for all the repros i saw the hitches are gone
     
  16. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    Last edited: Feb 26, 2015
  17. sfjohansson

    sfjohansson

    Joined:
    Mar 12, 2013
    Posts:
    368
    Awesome.. I took it out for a spin and it still seems like metal is still lagging behind... =(

    This is the open GL performance:


    And the metal:


    The scene is running on iPad mini with retina display and has about 130 Draw calls..I'm using ngui for the GUI.

    I can clearly see that one of the biggest cost is the trig functions (sin/cos( Time) ) in the ocean shader.. If that is what ultimately sinks it or is something else in the metal rendering that makes the difference.

    One interesting thing is that the combined time is pretty much the same...just that the gpu is doing more work while the cpu is having a cup of tea for 2 milliseconds or so..
     
    Last edited: Mar 1, 2015
  18. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    well thats not exactly fair to compare it this way. first of all it seems that metal does indeed what it is supposed to do: cpu is faster (yay)
    as for gpu - there are several issues with metal gpu performance (known both to us and apple) and we are looking into it. Can you please bug report with small repro project so we can dig into it and try to advise on possible optimizations (well, and to look into what we could handle better 8))
     
  19. sfjohansson

    sfjohansson

    Joined:
    Mar 12, 2013
    Posts:
    368
    It certainly does give the CPU more time... :) I have saved the GPU traces grabbed with the frame capture inside Xcode..is that enough for repro or should I do the extract mini project?

    I guess the good thing here is that if I can manage to knock back the ocean shader I'll be hopefully fine...unless there are other issues at play.. I read about caching trig functions in lookup textures so I'm just writing a small script to render out sin/cos functions onto a texture..see how that helps
     
  20. Gwl

    Gwl

    Joined:
    Feb 10, 2013
    Posts:
    13
    Submitted new bug with repro (676404). The performance has improved in 4.6.3p1 for some of our scenes but the spikes still make it generally worse than ES2/ES3.
     
  21. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    quickly glancing through it it seems that it is exactly the issue i was planning to look at - we are doing [CAMetalLayer nextDrawable] at the very beginning of unity frame - and this is really bad as it involves "kinda" vsync - so we plan to first defer it till doing actual rendering (well - there are still scripts/physics/whatever to run - so no need to sync to gpu right away) and then be more flexible at it (as in - research more approaches and give you possibility to make informed decision if there is no clear winner).

    that really depends but if we speak about A8 (well A7 is more complicated) - they are freaking ALU beasts so it might happen that reading from texture would make stuff slower 8). What you CAN try though is to forcibly use *floats* with sin/cosine - we found some strange issue when metal math builtins involving half could be unnecessary slower than float ones
     
  22. sfjohansson

    sfjohansson

    Joined:
    Mar 12, 2013
    Posts:
    368
    Yes, seems like the sine functions are not killing it as I tried an even harsher optimisation which was removing the ocean altogether...weirdly that didn't save the day, based on the frame capture where xcode showed my the shader and percentage of time spent on the sine/cosine functions as shown below



    Performance remained still poor without the ocean, around the same mark, then I attacked the fillrate by testing lowering the resolution ( 768p ) instead of the native retina. Still no happiness...
     
  23. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    and, thanks again for awesome repro. After doing quick tests the issue seems to be indeed about [CAMetalLayer nextDrawable]. After deferring all this to happen after update (or, well, when you first draw smth in the frame) i can totally see rock-stable 60 fps (yes, i was seeing hiccups before, no worries). It should go into next patch release, so keep calm and continue rocking on your game 8)
     
  24. Gwl

    Gwl

    Joined:
    Feb 10, 2013
    Posts:
    13
    Did the fix land in 4.6.3p2? I see no mention in release notes.
     
  25. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    >>Did the fix land in 4.6.3p2? I see no mention in release notes.
    no, sorry - we found some issues last minute and it was pulled out to not stall other fixes. I am working on it, no worries
     
  26. Paul_PS

    Paul_PS

    Joined:
    Nov 27, 2013
    Posts:
    5
    Hi Alexey, we are in desperate need for a Metal fix this week. We are getting major framerate spikes with Metal on (and use static batching heavily in our game). Any chance this is coming out this week?
     
  27. Metron

    Metron

    Joined:
    Aug 24, 2009
    Posts:
    1,137
    Subsidiary question from me: Will this be pulled over to Unity 5?

    We're currently dropping to 60% of the framerate when switching from ES 3 to Metal...
     
  28. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    >>Subsidiary question from me: Will this be pulled over to Unity 5?
    yes, though currently 5.0 is lagging a bit (4.x was priority before this week, as 5.0 was not released yet)
     
  29. JamesMobot

    JamesMobot

    Joined:
    Jul 8, 2010
    Posts:
    170
    I posted this in another area because it was specific to unity5 but check this out.
    In unity 5 it gets even weirder. I know they are working on it.

    from other post below here:

    The Huge problem is it's very difficult to even release right now with unity5.
    Automatic breaks A7 chip performance. 3.0 is great but cuts off alot of devices like iphone5 iPad mini (which is popular still)

    This part gets even weirder.
    On unity 5 force openGL 3.0:
    will run on non openGL 3.0 devices. Looks amazing but i can't release on older devices.

    On unity 4.6.xxx forcing openGL 3.0:
    will run on older devices and honestly is the best framrate I have ever seen with unity period. No jitters at all.This makes no sense since it's making the framerate amazing on even a 4s. Ive been using since it came out and I have never gotten such good results.


    If "automatic" could use 3.0 instead of metal as an additional option I feel this would be simply amazing!
     
  30. JamesMobot

    JamesMobot

    Joined:
    Jul 8, 2010
    Posts:
    170
    With unity 4 forcing openGL3.0 still lets you at least install on all devices(in fact runs better than selecting 2.0 even a iPhone 4s). On unity 5 if you select 3.0 it blocks anything under an A7 from installing.


    -And I know you guys (Unity) are on it. Im just sharing my experience for others to compare. I know i thought i was losing it at first.
     
  31. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    ok, i'll keep replying here as it is "huge goto post already"
    well - standard shader + A7 + metal will be fixed soon
    yes, starting with 5.0 we do update UIRequiredDeviceCapabilities if you pick forced graphics api. Also, on 4.x even you pick gles3 and it is not supported - it will be switched to gles2 - maybe thats why you see best framerate EVAH? 8)
    http://forum.unity3d.com/threads/tw...ction-in-unity-4-6-3-and-upcoming-5-0.299415/

    Also, if you see gles appearing to jitter after update - bug report with small repro - it is unexpected
     
  32. JamesMobot

    JamesMobot

    Joined:
    Jul 8, 2010
    Posts:
    170
    Right, that makes sense. But Its clearly not just falling back on older devices.
    On unity 4.6.xxx, Even on somethign like an ipad 2 or iphone 4s if you select "froce 3.0" the frame rate is about double than selecting 2.0

    I know those devices don't even support 3.0.
    So, what else is happening when you select force opengl 3.0 that boosts framerate so much on devices that dont even support it? It's like Unity's full potential has been locked until i selected force 3.0.
     
  33. Paul_PS

    Paul_PS

    Joined:
    Nov 27, 2013
    Posts:
    5
    Hey Alexey, any updates on the metal fix? We are in a tough spot and just looking for an ETA on when we can get this fixed. Thanks!
     
  34. Paul_PS

    Paul_PS

    Joined:
    Nov 27, 2013
    Posts:
    5
    Hey Alexey, I just testing the lastest 4.6.3p3 release and we are still having major Metal performance problems. Are there any other fixes coming soon? We are in pretty desperate need to get Metal enabled in our build.

    Thanks,
    Paul
     
  35. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    >>I just testing the lastest 4.6.3p3 release and we are still having major Metal performance problems. Are there any other fixes coming soon?
    well did you submit bug report with repro project? otherwise we cannot fix stuff we dont see
     
  36. Paul_PS

    Paul_PS

    Joined:
    Nov 27, 2013
    Posts:
    5
  37. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    go to product->scheme->run->options
    change GPU frame capture to Metal
    if it doesnt help - recheck xcode log to make sure that unity actually runs on metal
    ARGH, can you please check if their shaders sample cubemaps with lod? If so - do you see metal being slower on A7 or A8 device?[thats important - in 5.0 we fixed huge perf regression (metal vs gles) on gpu-side on A7 with standard shaders - i didnt backport to 4.x because no 5.0 standard shader - but it might be i forgot about some fancy marmoset ones]
     
  38. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,681
    Marmoset shaders use texCUBElod()
     
  39. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    >>Marmoset shaders use texCUBElod()
    ARGH FFS (facepalm) at me
    will backport, thx for heads up
     
  40. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,681
    btw: I don't know if that is an issue in 4.6 too but lod of a render texture does not work in Unity 5 when metal is used.
     
  41. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    >>I don't know if that is an issue in 4.6 too but lod of a render texture does not work in Unity 5 when metal is used.
    woah - should work - please bug report with small repro project
     
  42. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    >>Marmoset shaders use texCUBElod()
    >>will backport, thx for heads up
    actually - i rechecked and in 4.x we dont do magic on gles neither - so in that specific case performance should be same (also that was more about compressed cubemaps, which are not supported on 4.x iirc)
    so, yes - please bug report with small repro project - otherwise we will be just wasting time playing guessing game
     
  43. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,681
    Actually I can't see anymore who started to talk about marmoset in this thread, I just answered that they indeed use texCUBElod() ;)

    Just uploaded it - Case 681081 - it looks like the mip maps are somehow lost in metal, using tex2Dlod() only the original texture size works and mips result in black.

    Difference OpenGL ES 3 vs Metal:

     
  44. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,600
    You managed to hit quite a corner case here. On both gles/metal we generate mipmaps when we are "changing" RT (that's a good point, right?) - but on metal we missed case of "lets read pixels from there" - which is exactly your case. I will fix it in patch release but for now your workaround would be:
    Code (csharp):
    1.  
    2. if (createIBLtextureMap) {
    3.    Graphics.Blit (RenTexCube, RenTexIBL, cubemapToIBLtextureMateral);
    4.    // here goes workaround: grab temp rt and clear it
    5.    {
    6.      var rtTemp = RenderTexture.GetTemporary(8,8);
    7.      rtTemp.DiscardContents();
    8.      var currentActiveRT = RenderTexture.active;
    9.      RenderTexture.active = rtTemp;
    10.      GL.Clear(false, true, new Color(0,0,0,0));
    11.      RenderTexture.active = currentActiveRT;
    12.      RenderTexture.ReleaseTemporary(rtTemp);
    13.    }
    14.    // here ends the workaround
    15.    GetRTPixels(RenTexIBL);
    16.  
     
  45. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,681
    Thanks, that works.
     
  46. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    148
    Just my two cents here. We are using 4.6.4p4 and we get 15fps less with metal than OpenGL on iPad Air 2. Metal is still behind in our case, so we will keep using OpenGLES 2.0.
     
  47. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    It seems metal seems to be working not consistently on Apple devices - you would expect get same results on devices throughout but this is not the case, also using 4.6.4p4 - We need a status update on if there further plans to tweak Metal.
    Not tested with Unity 5.