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

Replace "zombie" system with post-legalization SPIR-T validation.

Open eddyb opened this issue 1 year ago • 0 comments

"Zombies" are a form of deferred errors (mostly to ignore errors caused in unused code), for both:

  • concepts representable in SPIR-V, but not legal (e.g. OpenCL-only pointer operations)
  • concepts not even representable (often implemented as "zombie"-annotated OpUndef values)
    • this is often not a true spec limitation, only an implementation one, e.g. an Intel OpenCL extension could be used for function pointers, and OpSpecConstantOp can express non-trivial constant pointers (in both cases, these would only serve as inputs to legalization, which is expected to rewrite them away - see below)

However, a primary goal of Rust-GPU is to legalize the Rust dynamic semantics into legal SPIR-V, and we're currently inconsistent, where some aspects are not checked before legalization (e.g. variables containing pointers) so that legalization has a chance to rewrite them away - but others use "zombies" and can only compile if "actually unused".

In the past, I've considered making further compromises to keep this system around (perhaps for a bit of nostalgia?), but if I try to be objective about this, Rust-GPU has a better chance at supporting more Rust code if the validation is deferred, and our post-legalization error reporting nowadays is arguably lossless (as e.g. inlining generates custom debuginfo now, for both this usecase, and panic "backtraces").

So I think what we can do is replicate the same checks we have for zombies, but as something more akin to "spirv-val for SPIR-T" (with only the few rules we care about for now)

  • see also: https://github.com/EmbarkStudios/spirt/issues/2

(I did start on something like this a month or two ago, but it was slowed down and overcomplicated by trying to do it piecemeal, and it should be quicker if zombies are all going away)

eddyb avatar Oct 12 '23 10:10 eddyb