Browse Source

Added section on determinism

Jorrit Rouwe 3 years ago
parent
commit
ea1470c737
1 changed files with 12 additions and 0 deletions
  1. 12 0
      Docs/Architecture.md

+ 12 - 0
Docs/Architecture.md

@@ -192,6 +192,18 @@ Data needs to be converted into an optimized format in order to be usable in the
 
 As the library does not offer an exporter from content creation packages and since most games will have their own content pipeline, we encourage you to store data in your own format, cook data while cooking the game data and store the result using the SaveBinaryState interface (and provide a way to force a re-cook when the library is updated).
 
+## Deterministic Simulation
+
+The physics simulation is deterministic provided that:
+
+* The APIs that modify the simulation are called in exactly the same order. For example, bodies and constraints need to be added/removed/modified in exactly the same order so that the state at the beginning of a simulation step is exactly the same for both simulations.
+* The simulation uses the exact same version of the library.
+* The simulation runs on the same CPU model and is compiled to the same binary code.
+
+If you're willing to sacrifice some performance, the last point can be mitigated. The library doesn't use any SIMD intrinsics that return an approximate result (e.g. 1/sqrt(x) or 1/x) which will differ between e.g. Intel and AMD. Furthermore, by default we compile with 'fast math' and 'fused multiply add' enabled, these will also result in differences across CPUs. You'll need to compile with 'strict math' enabled (-ffp-model=strict in clang) and disable 'fused multiply add' (see JPH_USE_FMADD). Deterministic simulation across platforms is even less likely to happen, you may need to turn off optimization altogether. There is a unit test that checks determinism, but it does not test for determinism across CPU models / platforms so no guarantees are made here.
+
+When running the Samples Application you can press ESC, Physics Settings and check the 'Check Determinism' checkbox. Before every simulation step we will record the state using the [StateRecorder](@ref JPH::StateRecorder) interface, rewind the simulation and do the step again to validate that the simulation runs deterministically. Some of the tests (e.g. the MultiThreaded) test will explicitly disable the check because they randomly add/remove bodies from different threads. This violates the first rule so will not result in a deterministic simulation.
+
 ## The Simulation Step in Detail
 
 The job graph looks like this: