GfxDeviceMetal.WaitForLastPresent

Hey, I'm working on optimization, and my game runs actually good, but the spikes I get are because of this "GfxDeviceMetal.WaitForLastPresent". In the Unity Docs it is explained with "Samples with this marker appear when the main thread waited for the GPU to flip the frame number to the screen (Time.frameCount - QualitySettings.maxQueuedFrames + 1). This means that if QualitySettings.maxQueuedFrames is greater than one, this time is spent waiting for the GPU to flip a frame that your application requested to render in a previous main thread frame."(https://docs.unity3d.com/Manual/profiler-markers.html), but I don't really understand how to fix that. Any Tipps?

I'm using Unity 2021.2.12f1, URP, Mixed Lighting(subtractive), low poly models, low res Textures and I am using Occlusion Culling.

Have a nice day :)

Would it be possible to set QualitySettings.maxQueuedFrames = 3(or higher), so that I have a bigger buffer of time amount for rendering the frames? Because on https://blog.unity.com/technology/fixing-time-deltatime-in-unity-2020-2-for-smoother-gameplay-what-did-it-take is explained that, if QualitySettings.maxQueuedFrames = 1 every frame needs to be finished, before rendering the next frame, which could have negativ impact on the frame rate, so I should can get around the impact of the spikes, if I increase QualitySettings.maxQueuedFrames, right?

Forgot to update it: The Game runs smoother and more stable, but a bit slower(45-50FPS in average and not 60FPS anymore), but I'm not happy with that. I will search for a better solution and post it here

I'm also seeing constant blips of GfxDeviceMetal.WaitForLastPresent taking 300-400% more time than usual. My graph looks like a saw wave with these intervals of Rendering peaks where GfxDeviceMetal.WaitForLastPresent and Semaphore.WaitForSignal are eating up all this extra time. Unity 2020.3.33f1 and also URP

I'm seeing some evidence that this is caused largely by having the Unity Editor open with the Inspector tab visible. It seems to throw off profiling and create these spikes. If I profile the game while it is fullscreen and the Inspector is not visible, it seems like these GfxDeviceMetal.WaitForLastPresent blips stop happening.

You can try profiling standalone. Editor has some issues with presentation of the editor windows themselves that can cause spikes like this. While it's not 100% certain that this particular one is precisely due to that but there are spikes like that commonly when running in Editor.

Reason for this is that all of the drawing in Editor goes through single OpenGL-esque drawing thread. And it also waits for present in a fashion as if everything was a single swapchain. This means if an editor window is redrawn it will cause a stall in drawing the player window.

[quote=“tvirolai”, post:5, topic: 875046]
You can try profiling standalone. Editor has some issues with presentation of the editor windows themselves that can cause spikes like this. While it’s not 100% certain that this particular one is precisely due to that but there are spikes like that commonly when running in Editor.

Reason for this is that all of the drawing in Editor goes through single OpenGL-esque drawing thread. And it also waits for present in a fashion as if everything was a single swapchain. This means if an editor window is redrawn it will cause a stall in drawing the player window.
[/quote]

Yes, absolutely! However, the GfxDeviceMetal.WaitForLastPresent saw wave spikes I am seeing seem specifically due to Inspector window being visible, even if I’m profiling a standalone build instead of in editor play mode.

[quote=“tvirolai”, post:5, topic: 875046]
You can try profiling standalone. Editor has some issues with presentation of the editor windows themselves that can cause spikes like this. While it’s not 100% certain that this particular one is precisely due to that but there are spikes like that commonly when running in Editor.

Reason for this is that all of the drawing in Editor goes through single OpenGL-esque drawing thread. And it also waits for present in a fashion as if everything was a single swapchain. This means if an editor window is redrawn it will cause a stall in drawing the player window.
[/quote]

Hey, thanks for you answer, but I was already profiling the standalone build, but I found out the problem. It was the UI, changed to TMP and now I don’t have the Frame Drops anymore :slight_smile:

2 Likes