-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor bevy_mikktspace to entirely safe rust #9050
base: main
Are you sure you want to change the base?
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
A couple of results from my prior attempt (#4932) - this really needs proper testing. That is, comparisons that it gets exactly the same results as the original C library. I also don't particularly like that we own this code, although I also realise that there's not really any other potential steward. |
I definitely agree with this, we need a test bench that validates the Rust port against references with non-trivial models generated using the original C library. |
I have just now added a reference generator to the PR, including result files from said generator. |
Regression tests validated against the original C are now included! |
Squashed and cleaned, this should now be ready for review and merge! |
do you have an idea perf-wise how it compares to the unsafe version? |
I have not done a benchmark check against either the unsafe translation, or the original C. I'd imagine it's not a huge difference given that the implementation hasn't actually changed at all. There will be additional checks as array accesses are bounds checked. |
fn set_tangent( | ||
&mut self, | ||
tangent: [f32; 3], | ||
_bi_tangent: [f32; 3], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better (or more "bevy native" or w/e) to use glam Vec2/Vec3/Vec4s instead of [f32; 2/3/4] for the stuff in this trait? I'm not sure if it really matters, but the crate already relies on glam so it's not like that'd increase potential dependencies for non-bevy library users (who also aren't using glam).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really like to get this moving forward, and ideally land this early in the 0.15 cycle. Considering that it's tested to be byte equivalent to the reference implementation, and only adds costs on startup/asset-load I think it's pretty much ready.
The only hitch is that this introduces several large binary blobs for testing, which I personally am against including in the repo. Is there a way we could commit this without the blobs?
Fully agree with @NthTensor. It would be a shame to let this accumulate more merge conflicts. |
I also want this, but we need to do some requirements gathering and collaboration. IMO a working group is likely to be the best way to get this into shape. |
@alice-i-cecile hmm? I fail to see why we wouldn't just want to merge it. The version in this PR is
This seems like a straight-up complete upgrade. Am I missing something? |
Hmm, okay. I remember @superdump expressing reluctance in the past, but byte-identical behavior is very hard to argue with. |
I'm not sure I understand what the blobs are used for in this circumstance. Does the |
That's correct, the tests check that the code generates byte-identical results. I figured that's the most appropriate test for this conversion, which should perform where possible identical floating point operations in identical orders, and thus produce byte-identical results. |
do we want to fuzz test this to check nan and infinity handling is identical with C? also, do we want to commit C into the bevy repo? |
I'm surprised that adding clang/cmake stuff is "uncontroversial". |
This is mainly the reason I included the binary files in git tree rather than generating them at test time, so as to not include CMake into the actual build at any point. Those files are only there to generate the comparison files, and do not take part in the regular build. |
Objective
4 years ago, with a heavy amount of hand-translation, I converted mikktspace.c to pure-rust so I could load GLTF files in-browser. I had intended this to be a quick and hacky conversion, to be gradually refactored over time, but to my surprise it's still in use in almost its original unsafe form! No more!
Fixes #7372
Solution
This pull requests finally converts the remaining unsafe code to safe rust, fixes rustc warnings, and most clippy warnings. I also re-added some comments that had gotten lost in the translation, and re-added flags.
The algorithm is still the same, the biggest changes made change it to use relative offsets into buffers instead of direct pointers.