Skip to content

joltc-sys: add cross-platform-deterministic cargo feature#15

Open
Solidor777 wants to merge 1 commit into
SecondHalfGames:mainfrom
Solidor777:cross-platform-deterministic
Open

joltc-sys: add cross-platform-deterministic cargo feature#15
Solidor777 wants to merge 1 commit into
SecondHalfGames:mainfrom
Solidor777:cross-platform-deterministic

Conversation

@Solidor777
Copy link
Copy Markdown
Contributor

JoltPhysics gates three FP-determinism decisions on the
CROSS_PLATFORM_DETERMINISTIC CMake variable
(Build/CMakeLists.txt:185-198, 226-244 + Jolt/Jolt.cmake:615-678):

  • MSVC: /fp:fast (default) → /fp:precise
  • Clang ≥14: + -ffp-contract=off (so mul+add doesn't fold into FMA inside JPH_PRECISE_MATH_OFF blocks)
  • x86: USE_FMADD AND NOT CROSS_PLATFORM_DETERMINISTIC flips FMADD off

joltc-sys's build.rs never plumbed this through, so the C++ build picked the platform default — most acutely problematic on Windows MSVC where /fp:fast meant the same git SHA produced non-deterministic floating-point output across machines / runs / toolchain versions. P2P-deterministic netcode and rollback-replayable simulation can't reliably build on top of joltc-sys without a workaround.

This PR adds a new cross-platform-deterministic cargo feature on joltc-sys (default-off; ~10% perf cost) that defines CROSS_PLATFORM_DETERMINISTIC=ON during the joltc CMake build. Mirrors the enhanced-determinism shape on rapier3d.

Verification

Downstream consumer (Solidor777/Titan's tools/titan-determinism harness) ran a 4-platform CI sweep with the feature on:

  • Windows-x64 MSVC
  • Linux-x64 Clang
  • macOS-ARM64 Apple Clang
  • Linux-ARM64 Clang

All four platforms produced bit-identical output for a fixed scene (5 dynamic bodies + halfspace ground) stepped 60 frames at fixed 1/60s timestep. Determinism contract holds.

Default-off rationale

P2P-deterministic netcode is opt-in (most projects ship server-authoritative or single-player). The ~10% perf cost (FMA disabled, more conservative FP rules) shouldn't be paid by projects that don't need it.

JoltPhysics gates three FP-determinism decisions on the
`CROSS_PLATFORM_DETERMINISTIC` CMake variable
(Build/CMakeLists.txt:185-198, 226-244 + Jolt/Jolt.cmake:615-678):
- MSVC: /fp:fast (default) → /fp:precise
- Clang ≥14: + -ffp-contract=off (so mul+add doesn't fold into FMA
  inside JPH_PRECISE_MATH_OFF blocks)
- x86: USE_FMADD AND NOT CROSS_PLATFORM_DETERMINISTIC flips FMADD off

joltc-sys's build.rs never plumbed this through, so the C++ build
picked the platform default — most acutely problematic on Windows
MSVC where /fp:fast meant the same git SHA produced non-deterministic
floating-point output across machines / runs / toolchain versions.
P2P-deterministic netcode + rollback-replayable simulation can't
build on top of joltc-sys without a workaround.

Adds a new `cross-platform-deterministic` cargo feature on joltc-sys
(default-off; ~10% perf cost) that defines `CROSS_PLATFORM_DETERMINISTIC=ON`
during the joltc CMake build. Mirrors the `enhanced-determinism`
shape on rapier3d. With the feature on, four-platform CI tests
(Win-x64 MSVC + Linux-x64 Clang + macOS-ARM64 Apple Clang + Linux-ARM64
Clang) produce bit-identical output for a fixed scene/step count —
verified empirically downstream.
Solidor777 added a commit to Solidor777/Titan that referenced this pull request May 9, 2026
…ture

PR filed 2026-05-09 from Solidor777:cross-platform-deterministic
against SecondHalfGames/jolt-rust:main:
SecondHalfGames/jolt-rust#15

TODO.md + VENDORING.md updated to reference the PR. When upstream
merges, sync our vendored crates/third_party/joltc-sys/ from upstream
+ drop the TITAN PATCH entry from VENDORING.md "Local patches".

Patch shape unchanged from the in-repo version: ~14 lines (Cargo.toml
feature entry + build.rs CMake var). Body of the upstream PR
references our 4-platform CI sweep (Win-x64 MSVC + Linux-x64 Clang
+ macOS-ARM64 Apple Clang + Linux-ARM64 Clang) as bit-identical
verification of the determinism contract.
Solidor777 added a commit to Solidor777/Titan that referenced this pull request May 17, 2026
…ture

PR filed 2026-05-09 from Solidor777:cross-platform-deterministic
against SecondHalfGames/jolt-rust:main:
SecondHalfGames/jolt-rust#15

TODO.md + VENDORING.md updated to reference the PR. When upstream
merges, sync our vendored crates/third_party/joltc-sys/ from upstream
+ drop the TITAN PATCH entry from VENDORING.md "Local patches".

Patch shape unchanged from the in-repo version: ~14 lines (Cargo.toml
feature entry + build.rs CMake var). Body of the upstream PR
references our 4-platform CI sweep (Win-x64 MSVC + Linux-x64 Clang
+ macOS-ARM64 Apple Clang + Linux-ARM64 Clang) as bit-identical
verification of the determinism contract.
Solidor777 added a commit to Solidor777/Titan that referenced this pull request Jun 4, 2026
…ture

PR filed 2026-05-09 from Solidor777:cross-platform-deterministic
against SecondHalfGames/jolt-rust:main:
SecondHalfGames/jolt-rust#15

TODO.md + VENDORING.md updated to reference the PR. When upstream
merges, sync our vendored crates/third_party/joltc-sys/ from upstream
+ drop the TITAN PATCH entry from VENDORING.md "Local patches".

Patch shape unchanged from the in-repo version: ~14 lines (Cargo.toml
feature entry + build.rs CMake var). Body of the upstream PR
references our 4-platform CI sweep (Win-x64 MSVC + Linux-x64 Clang
+ macOS-ARM64 Apple Clang + Linux-ARM64 Clang) as bit-identical
verification of the determinism contract.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant