Search Unity

Bug Pointlight Kills Safari Performance| 2020.3.25 | URP

Discussion in 'Web' started by matt-nexus, Dec 24, 2021.

  1. matt-nexus

    matt-nexus

    Joined:
    Aug 4, 2021
    Posts:
    10
    Last edited: Dec 28, 2021
  2. matt-nexus

    matt-nexus

    Joined:
    Aug 4, 2021
    Posts:
    10
    After realising it was a point light issue with webGL+URP rather than anything else, I've made a much simpler reproduction:

    https://matt-newcombe.github.io/webgl-simple-urp-pointlights/

    Simple Unity cube + point lights. Safari ~15-20fps with 1-3 PLs, Chrome solid 60fps, 1-3 PLs

    Safari:
    safar_pl.gif

    Chrome:
    chrome_pl.gif

    I don't think I can update my original bug ticket, but the new simple unity project can be found in the GitHub repo:

    https://github.com/matt-newcombe/webgl-simple-urp-pointlights
    https://github.com/matt-newcombe/webgl-simple-urp-pointlights/tree/master/unity-proj-2020_3_25f1
     
  3. matt-nexus

    matt-nexus

    Joined:
    Aug 4, 2021
    Posts:
    10
    Additionally this problem is much worse with URP than built-in, here's a test with the built in render pipeline on safari still and it has a performance drop (45 vs.55 fps) but the drop is no where near as severe as the URP pipeline that has been bugged:

    Built-In RP Safari:
    birp-safari.gif
     
  4. matt-nexus

    matt-nexus

    Joined:
    Aug 4, 2021
    Posts:
    10
  5. matt_cauldron

    matt_cauldron

    Joined:
    Dec 17, 2021
    Posts:
    48
    Okay I've figured out where the performance issue is in the package:

    Lighting.hlsl
    Code (CSharp):
    1. half4 UniversalFragmentBlinnPhong(InputData inputData, half3 diffuse, half4 specularGloss, half smoothness, half3 emission, half alpha)
    2.  
    The for loop that iterates over the lights is the issue:
    Code (CSharp):
    1.     for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex)
    2.     {
    3. ...
    4. }
    If I replace this for loop with static calls to get lights 1-4 (and therefore pay 4x pixel lighting calc cost regardless of how many lights are actually affecting an object) the performance is much better.

    My assumption is loops are not correctly supported for apples implementation of WebGL 2.0.

    However, I'm now left with the how to best re-write it performantly.

    I can just run lighting calculations for max light count that can affect an object, but this is paying the pixel cost across all objects.

    Planning to switch it to '?' if-statements in the shader, however this will add branching, which I think will trip up parallel gpu warps, so feels less than ideal.

    I'll x-post this to the URP forum as it feels like it might fall under their work more directly than the WebGL team.
     
    Last edited: Jan 17, 2022