Unity 2d andoird bottleneck gfx-waitforpresentongfxthread

I have a problem than I can seem to solve for a long time.

Randomly my build on Android has this massive bottlenecks, and a frame starts taking 1000ms

Because of gfx-waitforpresentongfxthread. I have read through multiple articles on this issue and nothing seems to work for me.

One of the things I have observed is that, an object, of which I can only have 50 instances at one time in my game (capped with a ObjectPool), starts having more than 100 instances when the bottleneck happens, but I am not sure if this is the “cause” or just a result of the bottleneck. But as you can see in the image below, it doesn’t take that much time anyway, even with more than 100 instances…

Important: It happens RANDOMLY, I have tried to recreate it multiple times, but it doesn’t seem to have something to do with the logic of the game or a bug per se, but who knows. The only thing I know is, it happens very randomly, even if the game is just running and I don’t even play.

Something after a few seconds every thing gets back to normal, but usually it just bottlenecks and is just “froze” (I have to restart the game)

I have this performance settings:

Application.targetFrameRate = 60;

If someone has some ideas, I will be very grateful!

Your CPU is ready to start rendering the next frame, but it’s waiting for the GPU to present the previous frame. This is what the Gfx.WaitForPresentOnGfxThread marker on the main thread and the Gfx.PresentFrame marker on the render thread are indicating. When these markers appear in this way, it is a classic symptom of being GPU-bound, i.e. your GPU cannot complete its work in time and at some point the CPU has to wait to avoid getting too many frames ahead.

Firstly, the situation you describe sounds like a bug that you should probably investigate - if you are only expecting 50 objects to exist and when this issue happens you have 100 objects, something isn’t behaving as expected. I expect this may be the cause of the issue and the sudden increase in the number of objects you are trying to render.

If you do wish to investigate the GPU bottleneck more, you might consider how expensive each object is to draw on the GPU; does it have expensive shaders for example? Using something like the Unity Frame Debugger could be helpful to give you an idea of the draw calls the GPU is executing. This resource might also help: Managing GPU usage for PC and console games | Unity.

1 Like

I have investigating for a bit, and I observed, that I can recreate the bug very often by just letting the game idle… it dosn’t make any sense.

I have rewrite the behaivor for the objects that had more instances than expected, and it dosent have anyting to do with the logic, for some reasone during the bottelneck unity exectues the “fixedupdate” for more instances that in the scene, but the object are not dynamicly instanciated, so it dosent make any sense.

my game is very lighweight, with sprites around 100kb, no shadows, no nothing, so I have no idea what this problem is related to the GPU.

some questions:

  • my sprites have the setting: 1000 pixels per unit (can this effect in anyway the performace ?)
  • my canvas has 300 reference pixels per unit (can this combination cause problems?)

The question remains, why doese the GPU randomly gets bottelnecked if the game is idling?

Thank you very much for your time, I know this is kinda weird, and I am very aware it is hard to help me because it can be sometihing very specific in my game, but I am very gratefull for any tips :slight_smile: