-
Notifications
You must be signed in to change notification settings - Fork 245
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
Add ScalarOrVector<S>
trait
#1030
base: main
Are you sure you want to change the base?
Add ScalarOrVector<S>
trait
#1030
Conversation
type Scalar; | ||
|
||
/// The dimension of the vector, or 1 if it is a scalar | ||
const DIM: usize; |
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.
Can you use std::num::NonZeroUsize here?
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.
Yes, theoretically you could do it, but I am not sure if it is currently supported in Rust-Gpu.
I like the general idea but if rust-gpu doesn't use it internally I'm not really seeing why it should add these things, rather than putting them in a separate crate for people to use? |
@oisyn Yea the thing is, my plan is to add support for subgroup operations after this PR has been merged, and there are some ops like |
Right! I would suggest adding this trait as part of that work. |
impl_vector_or_scalar! { | ||
for bool, 2: unsafe impl ScalarOrVector for glam::BVec2; | ||
for bool, 3: unsafe impl ScalarOrVector for glam::BVec3; | ||
for bool, 4: unsafe impl ScalarOrVector for glam::BVec4; | ||
|
||
for f32, 2: unsafe impl ScalarOrVector for glam::Vec2; | ||
for f32, 3: unsafe impl ScalarOrVector for glam::Vec3; | ||
for f32, 4: unsafe impl ScalarOrVector for glam::Vec4; | ||
|
||
for f64, 2: unsafe impl ScalarOrVector for glam::DVec2; | ||
for f64, 3: unsafe impl ScalarOrVector for glam::DVec3; | ||
for f64, 4: unsafe impl ScalarOrVector for glam::DVec4; | ||
|
||
for u32, 2: unsafe impl ScalarOrVector for glam::UVec2; | ||
for u32, 3: unsafe impl ScalarOrVector for glam::UVec3; | ||
for u32, 4: unsafe impl ScalarOrVector for glam::UVec4; | ||
|
||
for i32, 2: unsafe impl ScalarOrVector for glam::IVec2; | ||
for i32, 3: unsafe impl ScalarOrVector for glam::IVec3; | ||
for i32, 4: unsafe impl ScalarOrVector for glam::IVec4; | ||
} |
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.
It would be nicer to make this one per line, like i32: IVec2 => 2, IVec3 => 3, IVec4 => 4;
Also, you can make the macro implement both Vector
and ScalarOrVector
at the same time.
* subgroup: add trait VectorOrScalar, representing either a vector or a scalar type * subgroup: added all non-uniform subgroup operations * subgroup: remove all target_feature cfgs, replaced with docs * subgroup: added all subgroupBarrier*() functions from glsl * subgroup: added non group-op tests * subgroup: fixed asm for instructions taking GROUP_OP generic * subgroup: added tests for group-op instructions * gitignore: added rustc-ice* error reports * subgroup: added test for subgroup buildins * subgroup: make SubgroupMask a struct to prevent implicit casts to and from UVec4 * subgroup: fixed clippy lints * subgroup: drop the `non_uniform` from all subgroup functions, matching glsl * changelog: add subgroup intrinsics PR * subgroup: make VectorOrScalar trait match discussions in EmbarkStudios/rust-gpu#1030 * cleanup: remove internal type F32x2 for glam::Vec2 --------- Co-authored-by: Firestar99 <[email protected]>
This PR adds the
ScalarOrVector<S>
trait which represents types that can be either a scalar or a vector!Motivation:
I am currently adding support for subgroup operations, and for example
OpGroupNonUniformIAdd
s result type must be scalar or vector of integer type, so it would be useful to have this trait.