Skip to content
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

[Migrated] ZST's in structs cause invalid pointer casts #89

Open
rust-gpu-bot opened this issue Nov 13, 2024 · 1 comment
Open

[Migrated] ZST's in structs cause invalid pointer casts #89

rust-gpu-bot opened this issue Nov 13, 2024 · 1 comment

Comments

@rust-gpu-bot
Copy link

Issue automatically imported from old repo: EmbarkStudios/rust-gpu#1037
Old labels: t: bug,s: qptr may fix
Originally creatd by TrueDoctor on 2023-04-18T16:53:55Z


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

@rust-gpu-bot
Copy link
Author

Comment from eddyb (CONTRIBUTOR) on 2023-04-18T20:07:37Z


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant