You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implementing this trait on non-scalar or non-vector types may break assumptions about other unsafe code, and should not be done.
Fair enough, but not particularly useful for someone who would like to implement it.
It'd be great if there was a way to derive its implementation with a derive macro. Very helpful for new types, structs with two numeric fields, etc. Without this capability things like subgroup_shuffle() currently require substantial boilerplate.
Luckily, #380 get us 90% there already. Just need to wrap that in a derive attribute macro that also implements spirv_std::vector::Vector and spirv_std::vector::VectorOrScalar.
BTW, would it be difficult to implement this trait on things like [u32; 2] or more generally <const N: usize> [T; N] where T: Scalar?
It'd simplify some of the code I'm writing a lot.
[u32; 2] is an OpTypeArray %u32 2, not an OpTypeVector %u32 2, so it wouldn't work unless we change arrays to vectors for small array sizes.
I've been thinking about maybe a trait + derive macro specifically for subgroup intrinsics that would allow decomposing arbitrary types into the plain primitives and then apply the operation for each of those. That should be relatively easy to implement, next to what #411 offers. That would also solve the array case, since it's just a bunch of primitives.
Activity
Firestar99 commentedon Sep 24, 2025
Luckily, #380 get us 90% there already. Just need to wrap that in a
deriveattribute macro that also implementsspirv_std::vector::Vectorandspirv_std::vector::VectorOrScalar.See #411
nazar-pc commentedon Oct 10, 2025
BTW, would it be difficult to implement this trait on things like
[u32; 2]or more generally<const N: usize> [T; N] where T: Scalar?It'd simplify some of the code I'm writing a lot.
Firestar99 commentedon Oct 13, 2025
[u32; 2]is anOpTypeArray %u32 2, not anOpTypeVector %u32 2, so it wouldn't work unless we change arrays to vectors for small array sizes.I've been thinking about maybe a trait + derive macro specifically for subgroup intrinsics that would allow decomposing arbitrary types into the plain primitives and then apply the operation for each of those. That should be relatively easy to implement, next to what #411 offers. That would also solve the array case, since it's just a bunch of primitives.
Firestar99 commentedon Oct 14, 2025
@nazar-pc Made you #441 with a new
trait ScalarOrVectorComposite:rust-gpu/tests/compiletests/ui/arch/subgroup/subgroup_composite.rs
Lines 10 to 46 in ce822f1
Just be careful of the breaking changes in #380 and #440