Yet another "gfx.waitforpresent" thread

Hi Everyone,
after two weeks of running into the same problem, reading every forum post, watching ever unity optimisation video tutorial and so on - I’ve finally turned to the community.

Situation: building a seated VR game as a learning experience/exercise in frustration.

I had been on holidays, so using my trusty 2013 Macbook air, I bought some assets and started building my simple environment and was able to get about 30 frames per second, with the occassional wait for present spike - pushing up over 100ms. I wasn’t too worried because this old machine wasn’t my target hardware, but it was fine for some of the early scripting stuff I wanted to get out of the way. When I got home, I fired up the big laptop - Alienware powered with a 1060, turned off v-sync and tried to run my scene. While I got better performance - I’m still getting “wait for present” spikes up to about 25ms.

To my eyes, it looks like the render thread is causing the mess - but I just don’t know. I’ve uploaded a screenshot from the profiler, looking for a way to upload the raw data next.

I have tried literally everything I could find on the topic, with no joy. Hoping someone here can see what I’m missing.

Here is another frame - after rebaking light maps and culling.

Does the same thing happen with a completely empty scene?
If not, then at what point does it start happening (meaning after which assets get added to the scene)

Here it is in a completely empty scene - just the default skybox - no controller, no assets

I thought this could be the nVidia overlay, so I signed up for an nVidia account specifically to turn it off :wink:

Ignoring the spikes for a second, you mentioned that you have VSync off, but it looks like that you are still capped at 60fps in that empty scene.
If you have really turned it off in unity, then the only thing that can force vsync is the driver, so maybe take a look at that as well.

Anyway, even if you get the expected 5000 fps or so with a completely empty scene, the spikes are still strange.
Even with a fixed 60fps you shouldn’t get them.

They look really periodic, so something must cause the WaitForPresent thing based on time.
Unfortunately I don’t know what else to suggest. I’m using 2017.3.0f3 and when I disable everything in my scene (yes, I know, its not truly empty then) the profiler looks like this: Imgur: The magic of the Internet

I’m using Unity 2017.3.0f3

Unless I’ve made a mistake - VSync is off

I’ve also manually turned it off in the video card driver - no change

I’d accept the argument that it’s the driver, except that I’m also getting these spikes on the Mac and a third computer - so that implies it’s either Unity or the project itself.

And, with VSync on the “delay” shows up in a different colour in the Profiler… Incidentally, the spikes are lower too - by about 1/3

I’ve gone through all the threads again, and can’t find anything helpful. Does anyone have any ideas?

1 Like

just random guesses,
still same on a completely separate empty project?
if you build empty scene and profile that, is it still the same?

Empty project with empty scene and vsync on (default)

Empty project, vsync off

Building an empty project fails. Here are the build settings:

and the three errors are:

ArgumentException: The Assembly UnityEngine is referenced by UnityEngine.UI (‘C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/Standalone/UnityEngine.UI.dll’). But the dll is not allowed to be included or could not be found.
UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List1 alreadyFoundAssemblies, System.String[ ] allAssemblyPaths, System.String[ ] foldersToSearch, System.Collections.Generic.Dictionary2 cache, BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:156)
UnityEditor.AssemblyHelper.FindAssembliesReferencedBy (System.String[ ] paths, System.String[ ] foldersToSearch, BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:196)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Build completed with a result of ‘Failed’
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

UnityEditor.BuildPlayerWindow+BuildMethodException: 3 errors
at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (BuildPlayerOptions options) [0x0020e] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:181
at UnityEditor.BuildPlayerWindow.CallBuildMethods (Boolean askForBuildLocation, BuildOptions defaultBuildOptions) [0x00065] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:88
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Uninstall and reinstall of unity hasn’t fixed the build errors.

reinstall of Windows hasn’t fixed the build problem. Seriously frustrating.

1 Like

you tried these, force opengl, and removing extra bloatware apps?

does the laptop has integrated gfx card, tried running on that also?
(although since it happens in your other computers too then it shouldnt be those…)

for me, building completely empty pc.exe project, without scenes or anything, works…
(tried using 2017.3.0p1, havent got it installed on c drive though… but shouldnt matter)

You should report a bug! That’s a big problem - Unity should find it’s own assemblies when building.

Yes - as I say, clean build - no joy - now rebuilt two computers - no joy. Builds stuff fine on both Macs. Looks like i’m reporting a bug for the build issue. But it doesn’t help me explain the wiatforpresent thing.

Ok - bug report submitted for the build problem. Any ideas on the framerate issue - this wait for present thing that is happening on a few computers? (both my crappy old laptop and my shiny new one?)

Well, the usual advice is to debug a build, to see if it’s an editor-only issue. Kinda hard when builds are crashing, though.

hahaha - fair enough. Well I’ll go down fixing the build rabbit hole and come back :slight_smile:

Ok - I have fixed the build problem - you can read about it and it’s solution here - Unity won't build any projects at all. Missing DLL? - Unity Engine - Unity Discussions

Now, I have no idea why this might be, but fixing this problem seems to have had an impact on the framerate and waitforpresent thing.

Here is the empty scene, profiled as a build - this spike comes immediately after switching back to the running build from the Unity editor, things slow down to 91fps in arguably the worst case scenario.


The scene in question profiled in the editor is staying above 100fps, which is most gratifying.

And the scene when profiled from a development build seems to bottom out around 183fps

In the next post I’ll attach the raw profiler outputs for anyone who is curious :slight_smile:

3341163–260856–profile-scene-build.zip (1.92 MB)

1 Like

Last post had the raw profiler output for the scene as built. This post has the profiler output for the empty project build and the scene as profiled in the editor. No idea why deleting a Unity index file might fix this - but why worry when I can get back to working on things that matter.

Thank you all for your help and ideas :slight_smile:

3341169–260858–profile-emptyprojectbuild.zip (483 KB)
3341169–260859–profile-scene-in-editor.zip (2.6 MB)