wgpu: Allow infinite floating point literals in Naga
Is your feature request related to a problem? Please describe. I recently started updating my path tracer to use wgpu 0.19. One of the issues I’ve run into is that it seems an additional validation has been added to Naga - infinite floating point literals are not allowed. I get an error like this
Shader validation error:
┌─ compute:1:1
│
1 │
│ naga::Expression [102]
Constant expression [102] is invalid
Float literal is infinite
Describe the solution you’d like Remove this validation or let the user turn it off. There are several valid reasons to want an infinite floating point literal. My use case is as to represent bounding boxes with infinite extent.
Describe alternatives you’ve considered Perhaps add an intrinsic for creating infinite literals?
Additional context
About this issue
- Original URL
- State: open
- Created 5 months ago
- Comments: 15 (10 by maintainers)
As far as I know one of the blockers here is the fact that Vulkan doesn’t guarantee it will preserve NaNs and Infinities unless the device supports one of the
shaderSignedZeroInfNanPreserveFloatXX
features.https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkPhysicalDeviceFloatControlsPropertiesKHR.html
Feature availability (compared to base WebGPU requirements)
generated via https://github.com/kainino0x/gpuinfo-vulkan-queryI haven’t checked how D3D12 & Metal behave (if they have similar optional features).
Related spec issues: https://github.com/gpuweb/gpuweb/issues/3749, https://github.com/gpuweb/gpuweb/issues/2259.
This will most likely have to be an optional feature and requires more research to spec and implement properly.
Two reasons:
rust-gpu
/ use rust as the source of truth for their shaders.rust-gpu
. Theoretically we can run a shader, translate to rust via naga, and then run the resulting rust code and compare output.I don’t know what exactly @LegNeato has in mind, but now that I’ve heard of the idea, I think it would be useful to be able to output Rust code even outside of rust-gpu applications. It would allow translating selected functions written in any shader language to run on the CPU side too, for those situations where an algorithm or formula is needed both places, or for testing.
This should be rolled back and moved out of the validator and into the individual frontends and backends, no? I have a WIP PR for a backend target/format that can use infinity and it is incorrect for the validation to fail for that case as infinity is valid in both the frontend and the backend. I can ignore the error in my backend (I think) but it really seems this behavior ties naga frontend validation to specific backend target semantics.
(btw, love this project!)
True, i confirm this is an issue. and also NaN, which f32::signum uses: