Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question [Solved] UWP build runs terribly slow but standalone run perfectly

Discussion in 'Windows' started by Surya_SK, Jan 1, 2022.

  1. Surya_SK

    Surya_SK

    Joined:
    May 22, 2021
    Posts:
    12
    Hi folks, I'm trying to build my Unity game for UWP. I've done that before for a game I made using 2019.2 and had no issues. But for my new game, I'm using 2021.2 and HDRP. The game runs smoothly in editor and when I do a Standalone build and generate a .exe. But when I do a UWP build, the game runs terribly, with an FPS of <5. I have no idea why this is. I've been trying to profile it but can't get that to work, but surely there should be something I'm missing if the game runs smoothly in editor and standalone. This feels really strange and I would really appreciate some help.
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    Are you by any chance running your game in "Debug" configuration?
     
  3. Surya_SK

    Surya_SK

    Joined:
    May 22, 2021
    Posts:
    12
    Nope, running it in Master
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    That is unexpected. Profiling should work using "Release" build. Did you try using IL2CPP to build for Windows Standalone to see if it has similar issues to UWP?
     
  5. Surya_SK

    Surya_SK

    Joined:
    May 22, 2021
    Posts:
    12
    The Windows standalone build uses IL2CPP by default right? The Standalone build runs pretty smooth, this only seems to happen with UWP
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    No, Windows Standalone does not use IL2CPP by default. It uses Mono.

    Which build type are you using with UWP?
     
  7. Surya_SK

    Surya_SK

    Joined:
    May 22, 2021
    Posts:
    12
    This is my configuration
     

    Attached Files:

  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    If you hit build, it will ignore the configuration selection in that settings page because it will spit out a Visual Studio project which will have that selection available in it. When using "D3D Project" build type, the "Build Configuration" setting is only relevant if you use the "Build & Run" option. Did you by any chance not change the build configuration in Visual Studio to something other than "Debug"?
     
  9. Surya_SK

    Surya_SK

    Joined:
    May 22, 2021
    Posts:
    12
    No, I'm building using Master in VS too
     
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    Okay, so two things to try:

    1. Build Standalone player with IL2CPP to see if it has the issue;
    2. Use the profiler to figure out why it's running slow.
     
  11. Surya_SK

    Surya_SK

    Joined:
    May 22, 2021
    Posts:
    12
    There doesn't seem to be an option to change it to IL2CPP? I swear this was possible in a previous version. Is there somewhere else I should be looking?
     

    Attached Files:

  12. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    It's in player settings under "Other Settings":

    upload_2022-1-11_9-39-36.png
     
  13. Surya_SK

    Surya_SK

    Joined:
    May 22, 2021
    Posts:
    12
    Just tried it with IL2CPP and the performance in Standalone is still good. I'm now trying to figure out how to get the Profile to run with the UWP build
     
  14. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    There are a couple gotchas with attaching a profiler to a UWP build:

    1. You need to enable Internet Client, Internet Client & Server and Private Networks capabilities in the application manifest;
    2. Build the player with "Autoconnect profiler" option.
     
    Surya_SK likes this.
  15. Surya_SK

    Surya_SK

    Joined:
    May 22, 2021
    Posts:
    12
    Thanks, I was able to connect the profiler. I'm not entirely sure what to make for this. It seems the CPU is handling everything and I don't see what the GPU is doing. Is that normal?
     

    Attached Files:

  16. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    Under "Profiler Modules" on the top left you can add GPU view. Until you do that, you won't know how busy the GPU is. That said, this screenshot looks incredibly suspicious. It seems to suggest it's waiting for 120 ms for rendering to be complete. I wonder if it somehow ends up rendering on a wrong GPU (or perhaps even the CPU). A couple questions:

    1. Did you intend to run it on D3D12 and is your game on Windows Standalone also using D3D12?
    2. Can you attach the player log? It should tell which GPU the game is using. You can find it under %localappdata%\Packages\<GamePackageName>\TempState.
     
  17. Surya_SK

    Surya_SK

    Joined:
    May 22, 2021
    Posts:
    12
    1. I changed to D3D12 recently hoping that would improve performance. The Standalone version is also using D3D12, yes.
    2 I've attached the player log. Looks like it's using the right GPU
     

    Attached Files:

  18. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    Can you show what the GPU looks like in the profiler?

    The log you attached is from Windows Standalone build. Can you find the one from UWP build in the path I mentioned above?
     
  19. Surya_SK

    Surya_SK

    Joined:
    May 22, 2021
    Posts:
    12
    Yep, it's using the wrong graphics card. How do I make sure it uses the dedicated graphics card?
     

    Attached Files:

  20. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    Add this code to Main.cpp in generated Visual Studio project:

    Code (csharp):
    1. extern "C"
    2. {
    3.     __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
    4.     __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
    5. }
    Could you report a bug report on this so we could fix it?
     
    Surya_SK likes this.
  21. Surya_SK

    Surya_SK

    Joined:
    May 22, 2021
    Posts:
    12
    That does it, thank you so much! I've sent a bug report. Hope you have a great day
     
  22. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    Great thank you! Could post the bug number so I could track it?
     
  23. Surya_SK

    Surya_SK

    Joined:
    May 22, 2021
    Posts:
    12
    Sorry for the late response. Here's the case number: 1394866
     
  24. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
  25. QFord

    QFord

    Joined:
    Nov 9, 2013
    Posts:
    17
    // http://developer.download.nvidia.co...megraphics/files/OptimusRenderingPolicies.pdf
    // The following line is to favor the high performance NVIDIA GPU if there are multiple GPUs
    // Has to be .exe module to be correctly detected.
    extern "C" { _declspec(dllexport) uint32 NvOptimusEnablement = 0x00000001; }

    // And the AMD equivalent
    // Also has to be .exe module to be correctly detected.
    extern "C" { _declspec(dllexport) uint32 AmdPowerXpressRequestHighPerformance = 0x00000001; }
     
  26. ofirudwork

    ofirudwork

    Joined:
    Nov 3, 2021
    Posts:
    17
    This happens to me too. Following this thread.
     
  27. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644