Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug (IN-55445) Severe Shader Performance Regression in URP 14

Discussion in 'Universal Render Pipeline' started by Peter77, Sep 21, 2023.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,571
    The performance of fragment shaders in Unity 2022.3.7f1 compared to 2022.1.7f1 has significantly worsened, affecting both custom and Unity shaders.

    In our game, shading performance in 2022.3 runs at half the speed compared to 2022.1. In the provided test project, it's not as severe, but still noticeably slower.

    The project is using Universal RP, and due to the Unity upgrade from 2022.1 to 2022.3, URP has been automatically upgraded from version 13 to version 14. I found the following note in the URP 14 changelog:
    Perhaps this change is causing the degradation in shader performance?

    This issue primarily affects low- to mid-tier Android devices. I used a Xiaomi Redmi 5 with Android 8 to measure performance for this bug report, representing our low-tier device.

    In Unity 2022.1.7f1, our custom Terrain shader runs at 50ms on the Redmi 5.
    In Unity 2022.3.7f1, our custom Terrain shader runs at 68ms.
    This is 18ms slower than before or a 34% decrease in performance.

    The more complex the shader, the greater the performance difference when comparing Unity 2022.1 to 2022.3. Cheap shaders, such as the Unlit shader, also show worse performance, although not as severe as complex ones.

    I submitted bug-report IN-55445 with a project to reproduce this issue.
     
    Last edited: Nov 27, 2023
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,571
    The most recent Unity version that performs as fast as 2022.1.7f1 is 2022.1.24f1. Upgrading to 2022.2.0 and newer versions leads to a degradation in shader performance as mentioned in the post above.

    2022.2.0 and newer versions utilize Universal RP 14, whereas 2022.2.24 utilizes URP 13.

    I proceeded to upgrade the test project to Unity 2022.3.7f1 but switched from URP 14 to URP 13, which is used in 2022.1, and the performance degradation disappeared.

    All evidence suggests that URP 14 is the cause of the performance issue.
     
    Last edited: Sep 22, 2023
  3. kotbrain

    kotbrain

    Joined:
    Oct 13, 2019
    Posts:
    25
    Yeah, I also sent a report (IN-49712) about this and have been waiting for a response for 2 months…
     
    Peter77 likes this.
  4. Jonathan-Westfall-8Bits

    Jonathan-Westfall-8Bits

    Joined:
    Sep 17, 2013
    Posts:
    229

    Out of curiosity are you using multiple non-cinemachine cameras.
    Also was is the memory snapshot from the shaders compared to both versions.

    Asking because of known memory leaks and issues that have a fix coming down the pipeline related to
    RTHandles that were introduced into more areas of URP 14.
     
    Peter77 likes this.
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,571
    The test project that I sent to Unity uses a single non-Cinemachine camera.
    Our actual game uses multiple non-Cinemachine cameras, primarily one for the world and one for UI.

    It seems shader memory doubled in 2022.3, but other than that, it looks pretty much the same in the test project.

    2022-1.png

    2022-3.png
     
  6. Jonathan-Westfall-8Bits

    Jonathan-Westfall-8Bits

    Joined:
    Sep 17, 2013
    Posts:
    229
    Than you might be in luck because it actually sounds like this is related to a couple bugs relating to SRP implementation of RT Handles that is not only known but some are fixed and being backported already. As long as it is related you should see your performance come back and better soon.

    Literally just last week the first couple fixes for these started being push into the new versions. Testing the versions with the fixes in 2023.3 alp[ha there is a nice performance boost related to this.

    So your issue might already be solved and being backported soon.

    For reference it sounds like this is related to RT Handles not being cleaned from memory during certain render steps in the render pipeline. In the step where RT handles are used to blit the results to the camera let's just say some slight memory leaks were found and they were causing extra draws and I mean a lot more draws.

    Multiple cameras even with just two one being used for UI caused a stupid amount of performance hits that can be seen when profiling and looking at memory used by shaders.

    Another bug that was fixed is Shader branches not properly stripping certain things causing extra hits to performance with stupid generation of shader variants. Sadly there are three more known URP bugs being worked on and backported, but so far the fixes they already have released for SRP have been really noticeable.

    For the first time since I think 2021.1 Unity actually got better compilation time and performance in 2023.3 on blank projects.
     
    Peter77 likes this.
  7. ElliotB

    ElliotB

    Joined:
    Aug 11, 2013
    Posts:
    256
    Do you happen to have the bug number for branches not being stripped? It sounds like a promising culprit. The RTHandle memory leak was awful, but I'm not sure it affected the number of draw calls. I'd be glad if they found a way to reduce draw calls further.
     
  8. Jonathan-Westfall-8Bits

    Jonathan-Westfall-8Bits

    Joined:
    Sep 17, 2013
    Posts:
    229
    I would have to check after a work meeting, but it also involves issues with Shader Keywords. There were several bugs with Shader Keywords and I do mean several. Due note there are several bugs involving keywords over the last couple months. Some are fixed, some are already fixed, but not released in a version yet, and some known that haven't had bug fixing started on it them yet.

    Basically keywords, RTHandles, and shader variant generation has had a lot of bugs that were causing several performance issues. Below are just some I know I kept an eye on, but there are more I can't think of off the top of my head.

    Here is one that is related to an ongoing set of fixes
    (UUM-37468)

    Here are just a few over the last couples weeks.
    (UUM-44739)
    (UUM-35111)
    (UUM-33301)
    (UUM-39831)

    From some release notes, but no bug report for the following.
    • Asset Bundles: Fixed an issue where shaders in asset bundles built with older Unity versions treated material keywords as invalid when using SubShaders.
    • Universal RP: Fixed an issue where keywords used in Post Processing were also stripped in other shaders.

    Also for the draw calls batching was broken in some cases for SRPs. Thankfully they are focusing on fixing all of them in 2023.2 and 2023.3 while backporting what is possible to older versions.
     
    ElliotB likes this.
  9. Jonathan-Westfall-8Bits

    Jonathan-Westfall-8Bits

    Joined:
    Sep 17, 2013
    Posts:
    229
    I forgot to mention something about the draw calls. Can't remember where I saw it on the forums originally, but was actually able to reproduce it in my work project very easily today.

    With the camera thing in some cases you could have the second camera culling layers to not render, but they would render still than be cleared before being passed. So the value were rendering, calculated, and put together, but discarded before moving to the final render pass.

    So I say extra draw calls what I should of said is extra calculated draws that are never actually drawn.
    Using the frame debugger with URP I can actual isolate and see the extra calls. On my UI camera it even tried to calculate Post processing still with the option off.

    While profiling see if there seems to be extra allocations for your real cameras.
    I say real because technically cinemachine cameras are just data holder that attach and sync up with a real Camera.
     
    Gasimo likes this.
  10. kotbrain

    kotbrain

    Joined:
    Oct 13, 2019
    Posts:
    25
    Did they respond to your bug report?
     
  11. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,571
  12. ekakiya

    ekakiya

    Joined:
    Jul 25, 2011
    Posts:
    79
    If extra cameras makes allocations every frame, you or your asset may be using beginFrameRendering, endFrameRendering delegates instead of beginContextRendering, endContextRendering.
    Those delegates receive camera array instead of camera list, that causes allocation. That allocation starts from 2021.1.