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

Toggle effects on/off in Single pass render expensive

Discussion in 'Image Effects' started by AndersMalmgren, Aug 29, 2016.

  1. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Hi, we notice huge spikes on VR.WaitForGPU when enabling and disabling effects like Vignette, Color correction and greyscale when Single pass render is being used. If I turn off Single pass render all is fine spikes_gpu.png

    We toggle all 3 effects on and off, Color correction indicates damage taken, greyscale death and Vignette we use to reduce FOV when moving for people that are known to get VR sickness
     
  2. robinb-u3d

    robinb-u3d

    Unity Technologies

    Joined:
    Jul 13, 2015
    Posts:
    20
    Hi

    Some random ideas in case they are helpful.

    VR.WaitForGPU will probably be the main thread waiting for the render thread and GPU to finish working on the last frame. Do you get frame spikes when the post effects are on or just in the sections where you enable/disable them? The spikes from the graph look like they could be drops from 90fps to 45fps, which I think would make sense if the VR device you are running on doesn't support async timewarp/reprojection. The questions is what is causing the extra time here, it could just be a small spike which takes it over the 11ms for a 90Hz frame and then it would drop to 45Hz.

    If you look at the GPU profile during this time does that also spike or if you look at the timeline view during those spikes you might be able to see if it is caused by the render thread spiking. This might give a hint as where to look further.

    If the spikes occurs when the post effects are on then it could just be that the GPU time is going over 11ms and causing this. Turning off single pass VR in this case might hide your extra GPU time as the CPU cost would go up but you would still have a bad frame rate in this case.

    If the spike occurs just when you enable and disable the effect then it could be caused by allocating extra RenderTextures needed to run the post effects, when running all the time they will tend to re-use buffers from the previous frames but on the first frame a new post effect is enabled it may well need to allocate some extra Render Textures. These RenderTextures would be twice the width when single pass VR is enabled which might cause the driver to have more trouble allocating them and so cause some extra time to be taken up than when non single pass vr is used. In non single pass vr mode then it's possible that temporary post effect RenderTextures will be shared between the left eye render and right eye render and so the total amount of VRAM required would be less in total as well. In this case you could just run all three post effects all the time but instead of disabling them tweak their parameters to perform no processing. You might also be able to reduce the amount of VRAM required by collapsing the three effects you use into one effect that does all the work as this might reduce the number of temporary buffers required.

    Hope some of this helps.

    Robin
     
  3. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Yeah, its only when turning it on that it spikes. It returns to normal in next frame and stays at normal FPS until youy enable it again
    Thanks for the input, for Vignette setting intensity = 0 works, but for Color correction and Grayscale its not as obvious, any tips?
     
  4. robinb-u3d

    robinb-u3d

    Unity Technologies

    Joined:
    Jul 13, 2015
    Posts:
    20
    For GrayScale you would probably need to add an extra shader variable which you can then use to control an extra lerp between the greyscale version and the original colour version at the end of the shader. It should add only a very small amount of extra cost (on a desktop class GPU).

    For colour correction it would depend on the code for the particular shader/effect was doing, the standard assets have at least 3 different versions I think.

    Hope this helps.

    Robin
     
  5. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Will look in to that, thanks. We go live todo so I had to let color and grayscale be, it was vignettte that was the biggest perfomance hogger. However I found a strange bug when vignette is enabled all the time, when quitting the game from SteamVR homescreen or from pressing the X icon in windows desktop I get a access violation error, I back tracked our git history back to the enabling of vignette. It seems Unity will crash if vignette is on when quitting (using SteamVR atleast). I found a ugly hack around it


    Code (CSharp):
    1.         private bool quiting;
    2.         private void OnApplicationQuit() {
    3.             if (quiting) return;
    4.  
    5.             Application.CancelQuit ();
    6.             StartCoroutine (DestroyVignette());
    7.         }
    8.  
    9.         private IEnumerator DestroyVignette() {
    10.             quiting = true;
    11.             vignette.gameObject.SetActive (false);
    12.             DestroyImmediate (vignette);
    13.  
    14.             yield return new WaitForSeconds (0.5f);
    15.             Application.Quit ();
    16.         }