-
Notifications
You must be signed in to change notification settings - Fork 86
Fix location assignment #482
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: main
Are you sure you want to change the base?
Conversation
…s due to overlapping locations
d00ba02 to
2e4b08e
Compare
2e4b08e to
aacd739
Compare
|
Note: I do use scalar-block-layouts if that matters - both enabled in Vulkan1.2, and I pass the command line argument for spirv-builder |
|
We don't care about scalar block layout or std430, we're just using whatever layout rustc gives us to ensure it's the same if you're using the same struct on shader and CPU side (at least since #380). If someone needs higher alignment (for silly wgpu uniform buffers or so), they should just I'm not actually too sure how scalar block layout and spirv-val interact precisely. Even though it's not enabled by default, we've never experienced any issues wrt layout with it being disabled. Even though Note that you are technically required to |
|
Even more minified code: #[repr(C)]
#[derive(Copy, Clone, Default)]
pub struct ManyFloats {
a: f32,
b: f32,
c: f32,
}
#[spirv(vertex)]
pub fn main(out1: &mut ManyFloats, #[spirv(location = 3)] out2: &mut f32) {
const {
assert!(size_of::<ManyFloats>() == 12);
}
*out1 = Default::default();
*out2 = Default::default();
}This fails as well, as according to spec array elements can't share slots, each array element has to get their own slot. #[spirv(vertex)]
pub fn main(out1: &mut [f32; 3], out2: &mut f32) {
*out1 = Default::default();
*out2 = Default::default();
} |
|
I've reread the Vulkan spec on location assignment and noticed that locations are not assigned for every 16 bytes, but there's a totally custom algorithm on how locations are assigned. Implemented the layout algorithm in |
4123eda to
c2dfffe
Compare
|
Success! 🥳
Fun fact: I actually had it enabled only on the Vulkan12 feature side, and the spirv compiler threw an error and I had to enable it. |
|
I'll let @eddyb review this one as I am not qualified. |

Locations for Input, Output (and UniformConstant, where I have no idea how they work without explicit descriptor_set and binding) were assigned one per declaration, whereas they should have been assigned
one per 16 bytesfollowing the Vulkan spec on 16.1.4. Location and Component Assignment.close #481.
Also adds an explicit location assignment, that keeps on counting from the last assigned value, just like glsl does:
rust-gpu/tests/compiletests/ui/spirv-attr/location_assignment_explicit.rs
Lines 25 to 32 in d00ba02
We don't check for overlaps when locations are manually assigned, leaving that for spirv-val:
rust-gpu/tests/compiletests/ui/spirv-attr/location_assignment_explicit_overlap.stderr
Lines 44 to 48 in d00ba02
See vulkan spec on 16.1.4. Location and Component Assignment and on 16.9.4. Offset and Stride Assignment of structs. spirv spec is irrelevant here, it simply declares the Location decoration exists, and leaves all further spec for the client APIs to handle.