-
Notifications
You must be signed in to change notification settings - Fork 73
derive spirv vector on user structs #411
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
base: vec3-12-bytes
Are you sure you want to change the base?
Conversation
Still a bit TBD around the proc macro name |
Does it need to be a proc macro vs derive macro that would be more natural? |
It's an attribute macro as we need to expand into another attribute macro that is placed on the struct directly, that our codegen backend can pick up. |
6be1bff
to
2021262
Compare
I see, what about requiring a user to specify it directly? Or maybe it is unnecessary in certain cases (like when I have a scalar new type rather than a vector)? |
2021262
to
9ed3407
Compare
What exactly do you mean? Manually implementing rust-gpu/crates/spirv-std/src/vector.rs Lines 19 to 61 in 9ed3407
|
I guess there is a reason it works that way right now, but that is (generally) not the only way. First of all, I not only may want to derive an impl of a trait for vectors, but also for single-field structs, in which case I would not call it a vector. Second, I'd expect it to look something like this for the case when multiple fields are present instead: #[derive(VectorOrScalar)]
#[repr(C)]
pub struct New(u32, u32); If Then macro would fail to compile if the struct or one of its fields doesn't have the necessary |
On single-field structs: I've recently noticed that structs with a single scalar member and
attribute vs derive macro: It's mainly a technical reason it's an attribute macro. If we wanted to have the |
My point is that the information for codegen should not be a proc macro either. If As for the derive, it is also idiomatic to have the name of the trait and derive macro be the same and re-exported together. Having a separate proc macro looks more unusual, implicitly indicating complexity and is not as clear about what does it actually do. While derive macros look absolutely normal since everyone uses them all the time. The derive macro could be called |
a769043
to
0bae80e
Compare
9ed3407
to
9a8b4d1
Compare
I can see how
So types really should be |
Thanks for explaining! The reason I imagined it as derive macro is because APIs require I'm now wondering if there is an API to do something like parsing the file with As for derive macro, I still don't fully get why it can't be a thing. Derive macro should literally just implement a trait properly. If there are extra requirements for that trait to be derivable (like |
Requires #380
Since #380 already implements all the infrastructure to declare spirv vectors properly in glam, may as well expose it to our end users and allow them to declare their own vector types. The
spirv_vector
proc macro expands to the samerust_gpu::vector::v1
glam uses, but additionally implementsspirv_std::vector::Vector
andspirv_std::vector::VectorOrScalar
on the type, so it can be used in eg. subgroup intrinsics.Example:
rust-gpu/tests/compiletests/ui/glam/spirv_vector_macro.rs
Lines 13 to 33 in 6be1bff
First two commits just move some code around, so best reviewed commit by commit.
close #410