-
Notifications
You must be signed in to change notification settings - Fork 53
[Migrated] Support Option<T> #139
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
Comments
Comment from MarijnS95 (CONTRIBUTOR) on 2020-11-12T22:17:38Z @termhn This error is identical to the one I intended to create an issue for following EmbarkStudios/rust-gpu#220 (comment), thanks for waking me up 😄 error: Cannot cast between pointer types
--> examples/shaders/sky-shader/src/lib.rs:156:19
|
156 | let sun_pos = const_vec3!([0.0, 75.0, -1000.0]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: from: *{Function} [u8; 16]
= note: to: *{Function} [f32; 3]
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
The union Foo {
a: u64,
b: i64,
}
let x = unsafe { Foo { a: 1 }.b }; This compiles without errors. Turning it into a statically sized array (internal representation in glam), no matter how small surfaces this error: union Foo {
a: [u8; 1],
b: [i8; 1],
}
let x = unsafe { Foo { a: [1] }.b }; error: Cannot cast between pointer types
--> examples/shaders/sky-shader/src/lib.rs:163:22
|
163 | let x = unsafe { Foo { a: [1] }.b };
| ^^^^^^^^^^^^^^^^
|
= note: from: *{Function} [u8; 1]
= note: to: *{Function} [i8; 1] Bonus, attempting to "get" a union Foo {
a: (u64, u64),
b: (i64, u64),
}
let x = unsafe { Foo { a: (1, 1) }.b }; error: Cannot use this pointer directly, it must be dereferenced first
--> examples/shaders/sky-shader/src/lib.rs:163:22
|
163 | let x = unsafe { Foo { a: (1, 1) }.b };
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error I'm not enough of a compiler engineer to take the plunge and understand + solve this issue (despite that I assume these statically sized arrays should be taken and reinterpreted "by value") but this mini-investigation might give someone else a head-start 😁 |
Comment from khyperia (CONTRIBUTOR) on 2020-11-13T08:51:23Z Unfortunately these are far from different errors, they merely fail with the same compiler error message. Enums we can fix via the approach that RLSL took and generate an "exploded" data representation, where each enum kind is stored as separate field (and disallow interaction with host-rust). This will remove the need to bitcast pointers, fixing the compiler error reported here. However, arbitrary bitcasting between pointers is impossible to do on the GPU, and will never be supported. |
Comment from XAMPPRocky (MEMBER) on 2021-01-07T11:46:18Z Updated title to reflect that this currently affects all pub fn foo () -> Option<u8> { Some(5u8) }
|
Comment from XAMPPRocky (MEMBER) on 2021-02-15T15:50:32Z Adding this as another thing that needs options, which is #[test]
fn powi() {
val(r#"
fn powi(x: f32) -> f32 {
x.powi(80)
}
#[allow(unused_attributes)]
#[spirv(fragment)]
pub fn main() {
assert!(powi(1.0) == 80.0);
}
"#);
} Error
|
Comment from DavidTruby on 2021-09-11T22:59:44Z This issue also seems to prevent num-complex compiling in shader crates. I'd be interested in having a deeper look at this if it's possible to fix. I have a couple of questions though. Firstly, why is it that pointer bitcasts aren't possible on the GPU? I worked (briefly) on the GPU OpenMP backend in clang and am pretty sure I remember that we allowed arbitrary Secondly, specifically what I'm seeing is pointer casts like If anyone can point me in the right direction here I'd be happy to take a look! |
Comment from khyperia (CONTRIBUTOR) on 2021-09-13T07:35:01Z (meta note: I believe you discussed those questions on discord with eddyb after you posted this, so I won't answer again here - let me know if I'm mistaken and I can give answers here) |
Comment from Lucky4Luuk on 2023-04-20T08:34:00Z Any updates on this? I'd love to be able to use Option in shaders. |
Comment from reinismu on 2024-10-12T14:47:12Z EmbarkStudios/spirt#24 doesn't unlock Option? |
Issue automatically imported from old repo: EmbarkStudios/rust-gpu#234
Old labels: t: bug,c: rustc_codegen_spirv,s: qptr may fix
Originally creatd by fu5ha on 2020-11-12T18:04:17Z
Expected Behaviour
Be able to use
Option<Mat4>
Example & Steps To Reproduce
Use an
Option
that contains a value larger than some thresholdThe text was updated successfully, but these errors were encountered: