Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Discussion How about SIMD ?

Discussion in 'Web' started by OceanX000, Sep 7, 2023.

  1. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    121
    The compatibility of SIMD in browsers is relatively good. We have tested both chome and safari. In some engine functions, such as animation and mathematical calculation, can this technology be used to improve the current CPU computing performance of WebGL? This can improve fluency and reduce power consumption to a certain extent (especially iOS).
     
    KamilCSPS likes this.
  2. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    It's been only six months since Safari finally added webassembly SIMD support and Unity moves at a glacial pace.
     
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,420
    If you consider that in relation to how web technologies evolve in general, I'd say Apple is the glacier in the room. ;)
     
    KamilCSPS likes this.
  4. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    121
    I think SIMD support should not be as uncontrollable as multi-threading. Can support be considered as a priority?
     
    Zarbuz and KamilCSPS like this.
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,488
  6. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    121
    There is no SIMD in the Unity Web roadmap, but I think this technology is a very cost-effective thing
     
  7. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    449
    Suggestion was to post it.
     
  8. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    121
    I've post this suggestion. The power consumption of the mobile is too high. After Apple's powerlog diagnostic tool, it is found that on WebGL platform the main bottleneck is CPU.
    CPU > DRAM >> GPU
     
  9. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    I authored SSE support into the compiler toolchain: https://github.com/emscripten-core/emscripten/pulls?q=is:pr+author:juj+sse+is:closed+ . You can find the documentation at https://emscripten.org/docs/porting/simd.html

    Since 2021.2, if you're an author of a native C++ plugin to Unity's web builds, you can target SIMD by enabling the relevant Emscripten compiler and linker flags. (one of -msse*, -mneon*, -msimd128, and then -sSIMD in general)

    You're probably familiar that the performance benefit of SIMD in "general purpose" code is diminishing, and instead it works best in very specific arithmetically computation heavy tasks.

    In Unity codebase, I see three locations where SIMD could benefit web builds:
    - Burst jobs
    - CPU skinning
    - Texture format conversion

    Today Burst jobs are supported by web builds in limited fashion, and CPU skinning is actually being tackled in a better way by WebGPU, by moving the skinning over to GPU's compute shaders, like all other Unity platforms currently do. (Web has been the only odd one out that had software skinning, due to WebGL not supporting compute shaders) Last, the texture format conversion is something that should generally be avoided by choosing the appropriate compressed texture formats that would not need conversion.

    In game engines there are a lot of places where SIMD could help, but the situation with Unity is that there has been a massive shift to migrating compiled code from C++ to C#, and C# code has less opportunity to utilize SIMD. (well, this has recently been changing at https://learn.microsoft.com/en-us/dotnet/standard/simd )

    We might enable LLVM's autovectorization across the codebase at some point, although these can be a bit of a hit or miss. If you'd like, you can already try it by setting a global environment flag `EMCC_CFLAGS=-msimd128 -sSIMD`, and then restarting Unity, and doing a full rebuild of the project.
     
  10. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    449
    I'll make the argument that, in Web particularly, the situation is more nuanced. For us, we have to do quite a bit of texture conversion as we use a CMS to populate the content being shown by the WebGL Unity Player. This content is uploaded by clients so it can be difficult to enforce specific formats.

    I am willing to bet that other such uses-cases for more professional uses of Unity Web platform are not rare as user-uploaded content often does not match WebGL optimized formats. And the web platform is the only platform Unity supports, that to my knowledge, leveraging user uploaded content is a common core driver of the platform.
     
  11. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    That is a very good point, and currently true, the GPU hardware base on the web is much more fragmented than on other platforms. Though that is something that we have plans to address by means of doing multi-deployment of compressed texture formats as a primary solution.