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
replace #[repr(SIMD)] with #[rust_gpu::vector::v1]
allows rust-gpu to remove hacks around allowing old glam-style #[repr(SIMD)]
#[rust_gpu::vector::v1] is a custom rust-gpu attribute that marks structs to be compiled into spirv OpTypeVector instead of OpTypeStruct, vector primitives are needed for many intrinsics
What are the alignment implications of rust_gpu::vector::v1? One of the reasons I avoided repr(align) on spirv is that repr(simd) vectors had their own alignment and I felt that repr(align) could be misleading if it didn't happen to match the alignment on repr(simd). Ultimately this is only really going to be an issue for people working on spriv, so I don't really mind how it works but if rust_gpu::vector::v1 alignment is different to what is specified by repr(align) here it might confuse people.
What are the alignment implications of rust_gpu::vector::v1?
None, and that's amazing! We can just leave the layout calculations to rustc and just copy whatever size, alignment and offsets it gives us to spirv. The attribute merely tells our backend to emit the struct as an OpTypeVector instead of an OpTypeStruct, which only requires that the members are 2..4 primitive types.
In fact, spirv types like OpTypeStruct or OpTypeVector don't necessarily need any layout, it only needs an "explicit layout" if it is read from or written to an external buffer, that may be viewed by other shaders or the CPU. And "explicit layout" only requires the struct to be "sane", like all members have offsets and no overlapping offsets, otherwise it does not care. So we can have our Vec3 and Vec3A be distinct OpTypeVectors with varying layouts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
#[repr(SIMD)]with#[rust_gpu::vector::v1]#[repr(SIMD)]#[rust_gpu::vector::v1]is a custom rust-gpu attribute that marks structs to be compiled into spirvOpTypeVectorinstead ofOpTypeStruct, vector primitives are needed for many intrinsics