rust-gpu
rust-gpu copied to clipboard
Enums MVP.
Supported cases:
- non-repr-C enums without non-null optimization;
- repr-C enums that are dataless / have the same layout for every case
- enums with non-null optimization that don't use pointers (e.g. Option<NonZeroUsize>).
Future work directions:
- Option<&_> and such - currently emits zombies/invalid SPIR-V, likely requires adaptations in mem2reg
- repr(C) enums that can be represented as (discriminant, union) - some of the groundwork is already there
Would this mean that one can use things like Option<T> or algebraic enums, e.g.?
As long as T is not a pointer?
I didn't get to play around with rust-gpu that much yet, my understanding was that so far only data-less enums work (#78).
@joeftiger yes. With pointers, it can generate incorrect SPIR-V, because operations on pointers are heavily restricted and amending that would require basically a full-program analysis that I haven't come up with.
This has been open for nearly a year. Is it still ready and just waiting for a review?
i've roughly merged this into latest version here
i compiled this code
struct Nah {
a: u32
}
enum Foo {
A(Nah),
B,
}
#[spirv(compute(threads(64)))]
pub fn main(
#[spirv(global_invocation_id)] id: UVec3,
#[spirv(storage_buffer, descriptor_set = 0, binding = 1)] output: &mut [u32],
) {
let aa = Foo::A(Nah { a: 0xffffffff });
if let Foo::A(a) = aa {
output[id.x as usize] = a.a;
} else {
output[id.x as usize] = 99;
}
}
it fails to compile
however if i revert providers.layout_of changes it works
need further research
@djdisodo do you mean the deoverlay_enum_fields change etc?
@Keavon there were some unresolved issues with this code, and ultimately, not much desire from Embark to do this. No-one wanted to do a massive code review, I guess.
@eddyb there seems to still be interest in this feature - I can probably bring it up to date, write some more tests, etc. Unfortunately I never did summon the courage required to make it work with pointers.
@ElectronicRU that would be awesome if you could return to this and get it landed now that the project seems to be picking back up on Embark's end. Our project https://github.com/GraphiteEditor/Graphite needs it for our node graph compositing shaders, which are written in Rust, to work with (some degree of) generic types in our node graph system.
This is fundamental Rust, we need some form of this feature; if not, this.
What is the status on this feature? I'm running into issues with Option that I feel are related to this, specifically with Option<T> where T is a struct.
@Lucky4Luuk sorry - life & work take up a lot of time, I don't have any to work on this and won't for the foreseeable future :( Someone else would need to push it through for now, sorry.