Enabling both std
and libm
APIs at the same time
#388
Replies: 5 comments 8 replies
-
I think that sounds reasonable. There were some other suggestions around being able to swap out trig functions for something more precise I'll try to find and link to this thread. Currently glam has a fast-math option which is less deterministic on the premise that out of the box glam should be deterministic. However as you point out, users may need to use libm for more deterministic math functions, which would suggest making the fast-math behaviour the default and enhanced determinism opt in (which was originally suggested by the contributor to introduce fast-math but at the time I disagreed). |
Beta Was this translation helpful? Give feedback.
-
Which of the two options from the edit would you prefer then? 'glam' having both APIs exposed, or making the 'std' feature the default (remove the flag) and 'libm' one the one that has precedence if enabled (and possibly rename it to 'enhanced-determinism')? |
Beta Was this translation helpful? Give feedback.
-
I had a draft PR for this #389. If the libm feature is enabled, those methods are used regardless of whether or not std is enabled. |
Beta Was this translation helpful? Give feedback.
-
I've merged that change to main now so libm will override std if building with std. I haven't added any other determinism flags. I think for cross platform determinism you will probably also need to build with |
Beta Was this translation helpful? Give feedback.
-
Wow, you work fast! After overriding the I'll have to delve a bit deeper into the cross-platform determinism problem in order to understand what more needs to be added for the |
Beta Was this translation helpful? Give feedback.
-
Would it be feasible to have both the
std
andlibm
functionalities enabled at the same time, so that users of this library can choose which implementation to use on their own? As far as I understand, at the moment only one or the other can be used which is problematic in certain scenarios.As an example, I am currently working on an issue in a multiplayer game demo that uses the Bevy engine, GGRS rollback networking and Rapier physics. In it, it is required for most physics-related operations to be deterministic across hardware, but currently two networked instances desynchronize at some point because of
sin_cos
function results. The specific call in question is happening inglam
'sQuat::from_rotation_z
method, which when replaced with thelibm
implementation behaves consistently across an M1 and x86 machine. However, I cannot enable the usage oflibm
functions from outsideglam
because if any other crate in the dependency tree is usingglam
with thestd
feature turned on it overrides the usage oflibm
. If both APIs would be exposed then the crates that need the deterministic functionality could offer anenhanced-determinism
feature without affecting crates that want faster hardware-dependent functions.Another benefit of offering both implementations at the same time would be that the crate features would better conform to cargo's "additive features" guidline. Quoting from the cargo book:
Of course, while this would certainly benefit me (and others that wish to build a rollback networking based game on top of Bevy), I might be missing important insight into why things are the way they are right now so I would greatly appreciate any feedback regarding this proposal.
Edit:
Updating with some more information based on a related discussion in bevy engine's discord. The following quote presents two different, mutually exclusive changes to
glam
which, if either of these were implemented, would enable building games such as the one mentioned above:My personal concern regarding the second approach would be that it would be possible to unintentionally introduce a crate which depends on the
libm
feature for some minor deterministic calculations to a large dependency tree which would turn on the slower math operations for the entire project which might not need deterministic operations. However, as I stated in the discord discussion, I might be overestimating the performance hit of enablinglibm
.Beta Was this translation helpful? Give feedback.
All reactions