rust-gpu icon indicating copy to clipboard operation
rust-gpu copied to clipboard

Rust Language Support

Open XAMPPRocky opened this issue 3 years ago • 8 comments

This is a tracking issue for adding support for using Rust language features and the core library with rustc_codegen_spirv.

Language Support

  • [x] Closures
  • [ ] Enums
    • [x] Data-less enums. enum Foo { A, B }
    • [ ] Algebraic data types. enum Option<T> { Some(T), None }
  • [x] Loops
    • [x] loop
    • [x] while
    • [x] for
  • [x] if
  • [x] match
  • [x] Proc macros
  • [ ] Try (?) operator
  • [ ] 128 bit integers
  • [ ] union
  • [ ] Compiles on stable
    • Blocked on stabilisation of -Z codegen-backend, also see https://github.com/rust-lang/rust/issues/77933

Compiler & Library Support

  • [ ] Debug builds
    • Blocked on #81, #186
  • [ ] Iterators
  • [ ] Option<T>

Features that don't work

About Tracking Issues

Tracking issues are meant for providing status updates on the progress of a feature, it's not meant for bug reports or discussions on a feature. Please instead file a new issue or join the #rust-gpu channel on Discord.

XAMPPRocky avatar Oct 21 '20 09:10 XAMPPRocky

Will closures be supported as well?

jarble avatar Jan 15 '21 21:01 jarble

@jarble Closures are currently supported.

XAMPPRocky avatar Jan 18 '21 08:01 XAMPPRocky

Should we update README.md and/or docs to indicate that e.g. for loops are now supported?

eddyb avatar Mar 22 '21 17:03 eddyb

Hi folks! Is it possible that rust-gpu may one day support trait objects? I'm currently implementing "ray tracing in one weekend" with rust-gpu and there are a couple cases like Hittable and Material where a trait allows for abstracting them nicely and a trait object would allow to work with collections of each with a little more ease. Being able to have world be a [&dyn Hittable; N] e.g. would allow for easily adding new objects to the world. I think support for ADTs would get us a lot of these same benefits where we specify different implementations under variants of an enum, though would lack the benefit of adding new variants in downstream crates.

I realise what we can achieve when targeting SPIR-V is far more limited and that it might not be possible to achieve use of &dyn Trait, though my understanding of these limitations is limited, so just thought I'd ask!

(edit: accidentally tapped "Comment" before finishing!)

mitchmindtree avatar Jun 10 '21 12:06 mitchmindtree

Hi folks! Is it possible that rust-gpu may one day support trait objects?

I think at some point in the future, it may - however, we'd first have to get through a SPIR-V spec change to be able to support dynamic dispatch. The Slang folks are considering doing this (we've discussed a bit about what rust-gpu's needs would be if a SPIR-V feature for dynamic dispatch was proposed), but it's likely a ways off (if it happens at all), and then even further beyond that to let drivers implement it, and beyond that rust-gpu can start implementing it. So, I wouldn't hold your breath.

(impl Trait and friends all work 100% today, but yeah, unfortunately I don't think that's what you're asking)

khyperia avatar Jun 10 '21 12:06 khyperia

What about plain function pointers then? AFAIK spirv doesn't support these at all.

tema3210 avatar Dec 30 '21 21:12 tema3210

What about plain function pointers then? AFAIK spirv doesn't support these at all.

Yep, SPIR-V doesn't support them at all right now. With the Slang folks considering pushing through an implementation for dynamic dispatch in SPIR-V, plain function pointers may be able to piggyback on the same infrastructure as well, we'll see (probably more likely than not some hack would make it work). However, we haven't heard any updates in a while (and our unrelated requests for changes/clarifications to the SPIR-V spec have not made much progress at all), so I wouldn't hold your breath.

khyperia avatar Jan 03 '22 08:01 khyperia

Hey! Is lifetimes supported in enums?

pub enum MyEnum<'a> {
    A {
        tmp: &'a Foo,
    },
    B {},
}

Im not sure if its Data-less enums or Algebraic data types

pyranota avatar Jan 05 '24 13:01 pyranota