ZST's in structs cause invalid pointer casts
TrueDoctor opened this issue · 1 comments
TrueDoctor commented
Expected Behaviour
The code should compile
Example & Steps To Reproduce
code:
#[spirv(fragment)]
pub fn main(x: (usize, ())) {
drop(&x.1);
}
result:
error: Cannot cast between pointer types
--> examples/shaders/simplest-shader/src/lib.rs:44:55
|
44 | #[spirv(fragment)] pub fn main(x: (usize, ())) { drop(&x.1); }
| ^^^^
|
= note: from: *u32
= note: to: *u8
error: Cannot offset a pointer to an arbitrary element
--> examples/shaders/simplest-shader/src/lib.rs:44:55
|
44 | #[spirv(fragment)] pub fn main(x: (usize, ())) { drop(&x.1); }
| ^^^^
error: Cannot cast between pointer types
--> examples/shaders/simplest-shader/src/lib.rs:44:50
|
44 | #[spirv(fragment)] pub fn main(x: (usize, ())) { drop(&x.1); }
| ^^^^^^^^^^
|
= note: from: *u8
= note: to: *struct () { }
System Info
- Rust: [e.g. 1.49.0-nightly (1eaadebb3 2020-10-21)]
- OS: linux 6.2.9-arch1-1
- GPU: Intel Iris Plus Graphics G7
eddyb commented
Noting Discord discussion outcome on here just so nobody wastes their time: the problem here is not that the SPIR-V type lacks the ZSTs, and the solution is not to add them.
Instead, the thing to remember is that Rust ZSTs are not data, and pointers to them cannot be used for memory accesses. The only reason we even need to cast a pointer is because we're using SPIR-V pointer types.
qptr
(#1020 / EmbarkStudios/spirt#24) should help a lot here.