Kimbatt / unity-deterministic-physics

Cross-platform deterministic physics simulation in Unity, using DOTS physics and soft floats
491 stars 64 forks source link

How is this different from the Unity DOTS Physics? #1

Open nightrise opened 3 years ago

nightrise commented 3 years ago

Hi there,

You reference the Units DOTS Physics package in your readme, which claims to be deterministic in its description.

Is the difference here that the Unity DOTS Physics package is only deterministic on the same platform/processor, while this project is deterministic across platforms/processors?

Looks like a cool project!

Kimbatt commented 3 years ago

Exactly, DOTS physics is only deterministic on the same machine, so it's not guaranteed that the physics simulation will be the same on PC, Android, WebGL, etc. This project guarantees that the physics simulation will run exactly the same on every single platform. See this reddit post for details.

tigershan1130 commented 2 years ago

from my test, it seems to be deterministic on different platforms. I mean at least all 64-bit architecture would work, why would it be different when they are all using burst compiler. Is this proven? The Reddit post also doesn't explain on this matter.

Kimbatt commented 2 years ago

from my test, it seems to be deterministic on different platforms.

The video in the reddit post shows that they are different on pc, webgl, and android. It's possible that it's deterministic on most of the platforms, but the goal of this project is to be deterministic on all platforms, no matter what hardware is used.

why would it be different when they are all using burst compiler

Different platforms might implement low-level floating point operations differently. For example, Floating point rounding mode may be different on different platforms. This means that a multiplication/division might be rounded differently on different machines, which breaks determinism. In the burst compiler, there is an option for this (FloatMode.Deterministic), but it's still not implemented. Even if the burst compiler generated deterministic floating point operations, the mathematical functions (e.g. sqrt, trigonometry) would still not be deterministic, because those are usually implemented as hardware instructions or system calls. Also, they are usually implemented as an approximation (for performance reasons), which is good enough in 99.9% of the time (but not when trying to be deterministic).

tigershan1130 commented 2 years ago

from my test, it seems to be deterministic on different platforms.

The video in the reddit post shows that they are different on pc, webgl, and android. It's possible that it's deterministic on most of the platforms, but the goal of this project is to be deterministic on all platforms, no matter what hardware is used.

why would it be different when they are all using burst compiler

Different platforms might implement low-level floating point operations differently. For example, Floating point rounding mode may be different on different platforms. This means that a multiplication/division might be rounded differently on different machines, which breaks determinism. In the burst compiler, there is an option for this (FloatMode.Deterministic), but it's still not implemented. Even if the burst compiler generated deterministic floating point operations, the mathematical functions (e.g. sqrt, trigonometry) would still not be deterministic, because those are usually implemented as hardware instructions or system calls. Also, they are usually implemented as an approximation (for performance reasons), which is good enough in 99.9% of the time (but not when trying to be deterministic).

That's totally understandable, I used math.sin operation over ECS testing, as long as burst compiler use the same IL2CPP on either X86 or ARM architecture, the result seems to be deterministic for me(this sorta opposite of what you said). The editor returns different results as it skips IL2CPP compiler and uses mono. (even on the same platform I get different results).

tigershan1130 commented 2 years ago

Hi, Is it possible to release the auto generation unity code tool?