-
Notifications
You must be signed in to change notification settings - Fork 52
Expose Luau 3-vectors support #41
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
This change is pending for #38 to go in. Once that's done, I'll clean this up and it should become pretty straightforward. |
a66d254
to
c2f7954
Compare
@natecraddock phew, this should be more or less ready too. It's worth taking a look as you might have some opinions about it. It got a little tricky with the addition of built-time choice for vector length (.xyz or .xyzw). It's pretty cool that Zig conditional compilation can support a choice like this so well. I abandoned the use of |
PR updated based on your insightful code review, @natecraddock! |
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.
Other than one small comment I left, everything looks great! Do you still consider this WIP?
src/libluau.zig
Outdated
} else if (luau_vector_size == 4) { | ||
return [_]f32{ r[0], r[1], r[2], r[3] }; | ||
} else { | ||
@compileError("luau_vector_size must be 3 or 4"); |
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 think this compile error can be removed now
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 changed this to
switch (luau_vector_size) {
3 => return [_]f32{ r[0], r[1], r[2] },
4 => return [_]f32{ r[0], r[1], r[2], r[3] },
else => @compileError("invalid luau_vector size - should not happen"),
}
IMO it reads better with the @compileError
as that documents better that only 3 or 4 are legal here.
Good to go now! |
The Luau VM supports native f32 3- or 4-vectors so that typical linear algebra operations are fast in game code. Both the 3- and 4-vector flavors are supported. Use -Dluau_vector_size=N to choose which. This must be configured at build time, as the native Luau VM must be re-compiled for this setting.
Added a tiny test case change to document use of vectors better. Still good to go. |
The Luau VM supports native f32 3-vectors so that typical linear algebra operations are fast in game code.
Supports both 3-vectors and 4-vectors.