-
Notifications
You must be signed in to change notification settings - Fork 247
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
Support Option<T> #234
Comments
Option
s make rust-gpu sad :(
@termhn This error is identical to the one I intended to create an issue for following #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 😁 |
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. |
Updated title to reflect that this currently affects all pub fn foo () -> Option<u8> { Some(5u8) }
|
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
|
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! |
(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) |
Any updates on this? I'd love to be able to use Option in shaders. |
EmbarkStudios/spirt#24 doesn't unlock Option? |
This issue is now being tracked at: Rust-GPU/rust-gpu#139 |
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: