Uh oh!
There was an error while loading. Please reload this page.
derive spirv vector on user structs - #411
Conversation
Firestar99
commented
Sep 24, 2025
Still a bit TBD around the proc macro name |
nazar-pc
commented
Sep 24, 2025
Does it need to be a proc macro vs derive macro that would be more natural? |
Firestar99
commented
Sep 24, 2025
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
2021262CompareI 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
9ed3407CompareFirestar99
commented
Sep 25, 2025
What exactly do you mean? Manually implementing rust-gpu/crates/spirv-std/src/vector.rs Lines 19 to 61 in 9ed3407 |
nazar-pc
commented
Sep 25, 2025
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)]pubstructNew(u32,u32);If Then macro would fail to compile if the struct or one of its fields doesn't have the necessary |
Firestar99
commented
Sep 26, 2025
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 |
nazar-pc
commented
Sep 26, 2025
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
0bae80eCompareFirestar99
commented
Oct 2, 2025
I can see how
So types really should be |
nazar-pc
commented
Oct 3, 2025
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 |
db60a40 to
ce5d860Comparecef67b3 to
cfaed2dCompareI've been thinking about this PR a bit more while waiting for #380 to be reviewed, and I have to say I may prefer the derive macro alternative. Specifically, I like that we can I think this can coexist with the "subgroup trait + macro" I mentioned at #410 (comment), since there are subgroup APIs that specifically require a float or int Scalar or Vector. Whereas the other would be better for shuffles, boardcasts and the like. |
cfaed2d to
1aec6ebCompareThis PR needs a rethink on how it relates to #441.
|
1aec6eb to
538b474Compare538b474 to
eb6f917CompareFirestar99
commented
Feb 23, 2026
I'll close for now until someone comes around that really wants custom vectors for whatever reason |
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_vectorproc macro expands to the samerust_gpu::vector::v1glam uses, but additionally implementsspirv_std::vector::Vectorandspirv_std::vector::VectorOrScalaron 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