Search Unity

Feature Request Soft floating points calculations and determinism

Discussion in 'Physics for ECS' started by Opeth001, Apr 18, 2022.

  1. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    Hello Unity :)

    I'm very interested in Unity DOTS physics, but I'm facing a problem where cross-platform simulation is not deterministic.
    This seems a bit obvious since floating point calculations are quite hardware bound.
    the fix has already been implemented by someone on the internet and posted a modified version of the package using soft floating point which seems to work as expected.
    the problem here is that it needs to be officially supported, so we don't have to modify the full package by replacing floats with soft floats on every update.

    it will be amazing if unity team can integrate it and give us the option to enable it using something like define symbols.

    this is a video showing the difference betwee using standard floats and soft floats


    modified physics engine repo:
    https://github.com/Kimbatt/unity-deterministic-physics

    Thanks!
     
  2. JMPM-UNITY

    JMPM-UNITY

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    93
    @Opeth001, thanks for posting this here. I will present this during the next meeting with the engineering team.
    Will get back to you soon.
    JosepM.
     
    Volshar and Opeth001 like this.
  3. JMPM-UNITY

    JMPM-UNITY

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    93
    brunocoimbra likes this.
  4. JMPM-UNITY

    JMPM-UNITY

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    93
    In addition to that, the main goal of the unity physics package is to keep it as high performance as possible, thus adding soft floats will come at the expense of lower FPS and the capacity of dealing with fewer entities.
     
    Opeth001 likes this.
  5. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    I think that's a compromise some people are willing to accept, because determinism is key for some projects.
     
    Volshar, JesOb and Edy like this.
  6. JMPM-UNITY

    JMPM-UNITY

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    93
    I agree with you.
     
    Volshar likes this.
  7. JMPM-UNITY

    JMPM-UNITY

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    93
    We talked about it in some of our latest team meetings. Yet, the solution must come from the burst package rather than the physics one. With that being said, I have logged your feature request into a ticket so we can keep track of it. Thank you for your feedback. Appreciate it.
     
    Volshar, XELF, Occuros and 2 others like this.
  8. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    thank you for your reactivity :)
     
    JMPM-UNITY likes this.
  9. FuzzyShan

    FuzzyShan

    Joined:
    Jul 30, 2012
    Posts:
    182
    This is interesting, the burst compiler seems to be pretty stable across arm and x86 chips when comes to simulation. Currently, the problem is sometimes we need to pass in values from mono behaviour(Input). this breaks certain system which requires withoutburst().run(). Thus breaking the deterministic simulation.

    Wouldn't it more feasible just have the mathematics floating library can switch in and out between softfloat and regular float library?
     
  10. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    866
    Did you try adding the input as a singleton entity with a dynamic buffer? And set the dynamic buffer from a separate default world. You should be able to burst all your sim code. For networking just pass bytes around.
     
    Last edited: Aug 31, 2022
  11. FuzzyShan

    FuzzyShan

    Joined:
    Jul 30, 2012
    Posts:
    182
    Your approach sounds feasible. This requires all logic code done inside ECS. I was wondering if it is possible for certain system withoutBurst().Run() be calculated in soft floats, then when reading and writing, I will cast between soft float and float.
     
  12. msfredb7

    msfredb7

    Joined:
    Nov 1, 2012
    Posts:
    163
    Your entity components would store floats or soft floats? Since soft floats are software, casting would probably be much more expensive than traditional float/double/int conversion. I haven't measured anything though, so maybe I'm off.

    EDIT:
    If you want simulation determinism with soft float, you need to convert the user inputs to soft floats before sending them over the network / into your simulation. That way, all players have their simulation 100% in soft float.
     
  13. FuzzyShan

    FuzzyShan

    Joined:
    Jul 30, 2012
    Posts:
    182
    No Need for Soft float on my parts, Arm8 and x86 follows IEEE 754 standards, with burst compiler keeping everything in check, Currently I do get Determinstic simulation. I just need to follow what TheOtherMonarch said about the dynamic buffer.
     
    msfredb7 likes this.