• RuntimesUnity
  • GPU Stalling When Disabling SkeletonAnimation

Hello,
I noticed something interesting in my Unity testing and was hoping someone could explain it. My game can have hundreds of SkeletonAnimation instances on screen at once, but most remain static unless interacted with. To optimize performance by reducing Update, LateUpdate, and mesh rebuilding costs, I wrote a script that disables SkeletonAnimation when it's not needed. From what I’ve read in forum posts, this is the recommended approach.
I tested on two machines:
• Development PC – i9 13900K, RTX 4090, Windows 11
• Steam Deck – Running Windows 11
In an extreme test case with 1,000 SkeletonAnimation instances, my script improved FPS from 100 to 180 on my PC. However, I noticed a 1.5ms increase in the following call stack:
• TimeUpdate.WaitForLastPresentationAndUpdateTime
• GfxDeviceD3D11.WaitForLastPresent
• DXGI.WaitOnSwapChain
Since performance improved overall, I didn’t think much of it. However, on the Steam Deck, FPS dropped from 45 to 5 instead. Profiling revealed that WaitOnSwapChain was now adding 90ms per frame.
From my understanding, this happens when the GPU is waiting on the CPU, often due to VSync, but VSync is disabled in this case. My best guess is that the GPU is stalling while waiting for a mesh update that never happens because SkeletonAnimation is disabled. Unfortunately, this is where my knowledge of graphic rendering and hardware ends.
I was hoping someone might be able to explain what’s going on here and what I could possibly to do signal to the GPU not to stall. I’m willing to try anything here because this is a performance optimization that my game really needs.
Thanks!

  • Harald ответили на это сообщение.
    Related Discussions
    ...

    rumham However, I noticed a 1.5ms increase in the following call stack:
    • TimeUpdate.WaitForLastPresentationAndUpdateTime
    • GfxDeviceD3D11.WaitForLastPresent
    • DXGI.WaitOnSwapChain

    That's (usually) waiting for VSync.

    rumham However, on the Steam Deck, FPS dropped from 45 to 5 instead.

    Do you mean that FPS dropped from 45 to 5 if disabling SkeletonAnimation components when they are not needed? That's very strange indeed. Could you verify that removing the disable/enable code brings everything back to 45 FPS and it's really this change that causes the FPS drop?

    Note that there is an Advanced - Update When Invisible property available at the SkeletonAnimation component (and SkeletonRenderer in general). If you don't want to utilize this feature and manually want to disable updates, you could also change skeletonAnimation.UpdateMode from UpdateMode.FullUpdate to e.g. UpdateMode.OnlyAnimationStatus or UpdateMode.Nothing.

    Could you please try if setting skeletonAnimation.UpdateMode to Nothing and back to FullUpdate instead of disabling and re-enabling the component makes any difference?

    rumham but VSync is disabled in this case.

    Are you sure that nothing (the OS, when being in Desktop instead of Game Mode) is overriding your
    vsync settings to on? Can you see screen tearing? Otherwise I would assume that vsync is still on.

    rumham My best guess is that the GPU is stalling while waiting for a mesh update that never happens because SkeletonAnimation is disabled.
    Unfortunately, this is where my knowledge of graphic rendering and hardware ends.

    That can't be the cause, as a different mesh is only modified and assigned if it is changed. If nothing is changed, nothing is done at all, so no buffer being locked and waiting to be unlocked or anything like that. There is no such low-level buffer access happening for mesh updates.