Search Unity

Gfx.WaitForPresent spikes - only on first run (iOS) - shader variants and preload shaders is active.

Discussion in 'Editor & General Support' started by havchr, Jan 4, 2019.

  1. havchr

    havchr

    Joined:
    Jun 18, 2009
    Posts:
    75
    Hi - I'm having some problems with what most likely is the GPU using extra time on the very first run of our game. I'm having trouble profiling and finding the answer as to what is actually the root cause of the spikes, but here's the data I've gathered so far :



    There's quite an increase in setPass calls, draw calls and batches as the camera pans a bit out.


    But the huge spikes as seen here - only happens on the first run.
    I am not seeing any shader compilation referenced in the cpu usage nor in the logs. Does unity log shader variant compilation? Would be very helpful.

    In the metal profiler on mac - profiling the iPhone - I see these types of spikes -
    shader compilation vertex&fragment and unknown. The unknown part is shown in the fragment part of the metal instruments..

    I'm guessing even with a shader variants file and preload shaders, they still have to be compiled on the device on the first run - but I was under the impression that this would happen prior to the scenes being active.

    Does anyone have good ways to hunt and test which things are affecting and creating these spikes? Logging shaders becoming active with the frame number for instance?

    This is on Unity 5.4.3

    Edit :
    I've disabled shadows to rule out any shadows-related stuff.
    I've profiled a bit more - quite sure shader compiling is the main cause.

    How I "captured" our shader variants is by playing the game and accessing every scene and then saving all of it to a shader-variant file that is set to be loaded- and turned on pre-load shaders.

    So I guess a huge part of it is figuring out this,
    How do I get unity to log out shaders that are being used/compiled? It seems I'm missing things in my shader-variants file, but I can't find out which.
     
    Last edited: Jan 4, 2019
  2. havchr

    havchr

    Joined:
    Jun 18, 2009
    Posts:
    75