EmbarkStudios / rust-gpu

🐉 Making Rust a first-class language and ecosystem for GPU shaders 🚧
https://shader.rs
Apache License 2.0
7.29k stars 246 forks source link

spirv-std: only enable `glam`&`num-traits`'s `libm` features on SPIR-V targets. #1122

Closed eddyb closed 7 months ago

eddyb commented 8 months ago

Draft because I'm not sure if we should do some kind of automated testing for this, I can't think of an obvious way to know "slower floating-point algorithms are being used" (also there's https://github.com/EmbarkStudios/rust-gpu/pull/1115 which may conflict).

Testing-wise the best we can do is probably likely this:

$ cargo tree -e features -p spirv-std | rg libm
├── glam feature "libm"
│       └── libm v0.2.8
├── num-traits feature "libm"
│       └── libm feature "default"
│           └── libm v0.2.8

(the above is before this PR, and there are no libm results after this PR)

eddyb commented 7 months ago

Accidentally found that this is really broken without resolver = "2"/edition = "2021". The ability itself to have per-target feature controls was added then (I now remember struggling in 2020 etc.).

Not sure how to control the resolver from spirv-builder but I will look around for a solution.

EDIT: one very important data point is that this problem is inevitable - you can't really have target-controlled dependencies before resolver = "2" without constant massive issues, and spirv-std may eventually want to e.g. emulate image sampling when used on CPU. (this is something that has been requested for over a year but I didn't manage to get back to. it would also massively help with testing, and outside of weird anisotropic stuff, the sampling math is defined by Vulkan and it should be possible to check GPU against CPU)