Skip to content

enhanced-determinism feature does not guarantee cross-platform determinism for 3D (missing glamx/scalar-math)#426

Open
RaphaelLEMAS wants to merge 2 commits into
dimforge:masterfrom
RaphaelLEMAS:bugfixes/3D-is-not-cross-platform-deterministic
Open

enhanced-determinism feature does not guarantee cross-platform determinism for 3D (missing glamx/scalar-math)#426
RaphaelLEMAS wants to merge 2 commits into
dimforge:masterfrom
RaphaelLEMAS:bugfixes/3D-is-not-cross-platform-deterministic

Conversation

@RaphaelLEMAS

Copy link
Copy Markdown

The enhanced-determinism feature in parry3d enables glamx/libm to ensure transcendental functions (sin, cos, sqrt, etc.) produce identical results across platforms. However, it does not enable glamx/scalar-math, which means glam still uses architecture-specific SIMD backends for basic vector and quaternion operations.

This causes cross-platform divergence in 3D computations between arm64 and x86_64 due to floating-point non-associativity in the dot product implementation:

arm64 (NEON): Vec4::dot uses vmulq_f32 + vaddvq_f32 — sums all 4 products in one reduction
x86_64 (SSE2): Vec4::dot uses _mm_mul_ps + pairwise _mm_add_ps via shuffles
Since (a+b)+(c+d) ≠ ((a+b)+c)+d at the floating-point ULP level, any operation involving Vec3/Vec4/Quat normalization or dot products produces slightly different results on arm64 vs x86_64. This affects all parry3d consumers relying on enhanced-determinism for cross-platform reproducibility.

The 2D case (parry2d) is unaffected because Vec2 in glam always uses scalar code — there are no SIMD optimizations for 2-component vectors.

Ughuuu pushed a commit to appsinacup/godot-rapier-physics that referenced this pull request Jun 20, 2026
…inism for 3D (#564)

3D version of this plugin is not really cross deterministic even with
enhanced-determinism flag for these reasons:
- Non cross platform deterministic math was used (sqrt, length,
normalize, quaternion manipulations).
- Parry dependency coming from Rapier3D dependency also has a bug with
3D cross platform determinism.

What I did:
- Used only cross platform deterministic maths
- Added the glamx/scalar-math under the enhanced-determinism flag

_Note:_
_The glamx/scalar-math is only a temporary fix. It can be removed once
the [Rapier](https://github.com/dimforge/rapier) repository includes the
[Parry](https://github.com/dimforge/parry) dependency with this
[fix](dimforge/parry#426

- Fixes #562

---------

Co-authored-by: Raphael <raphael.lemas.e@thalesdigital.io>
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