Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[valid] Disallow NaNs and infinities #2508

Merged
merged 2 commits into from
Oct 5, 2023

Conversation

teoxoy
Copy link
Member

@teoxoy teoxoy commented Sep 25, 2023

WGSL doesn't currently allow NaNs and infinities.

Resolves #2461.

Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also document that Literal::F32 and Literal::F64 must not be nan or infinity.

Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - could we also get some coverage in tests/wgsl-errors.rs?

@teoxoy
Copy link
Member Author

teoxoy commented Sep 25, 2023

It's not possible to spell out NaNs or infinities in WGSL though.

I did run a manual test here: #2461 (comment).

We should also document that Literal::F32 and Literal::F64 must not be nan or infinity.

Should we? I keep going back and forth on what's best for IR documentation.
On the one hand we have code in the validator that enforces the invariants of the IR which is usually self-explanatory but sometimes quite involved.
On the other, it would be nice to see at a glance what those invariants are on the IR itself but I worry they will get out of sync or might be too lengthy.

So far I've been of the opinion that if validation covers it there is no need to document what the validation is already doing but let me know what you think!

In this case we'll also most likely get an extension + capability which will allow NaNs and infinities.
gpuweb/gpuweb#2259 (SPIR-V has SPV_KHR_float_controls; haven't looked into the other languages).

@jimblandy
Copy link
Member

jimblandy commented Sep 25, 2023

It's not possible to spell out NaNs or infinities in WGSL though.

Oh, that's true. If this change were more involved I would want to imitate the unit tests from analyzer.rs, but that doesn't seem worth it in this case. Maybe in the future we will be able to implement some coverage requirements!

On the other, it would be nice to see at a glance what those invariants are on the IR itself but I worry they will get out of sync or might be too lengthy.

Yes, this is a risk. On the balance, though, I think it's really valuable to have the lib.rs docs be everything one needs to work with the IR. They're not there yet, but it's not too much trouble to avoid losing ground as we make new changes.

@teoxoy teoxoy requested a review from jimblandy September 26, 2023 10:42
@jimblandy jimblandy merged commit 4d6e000 into gfx-rs:master Oct 5, 2023
@teoxoy teoxoy deleted the disallow-nan-inf branch October 5, 2023 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WGSL backend writes invalid WGSL in some cases
2 participants