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

Behavior of NaNs and Infinities passed as float/double #466

Closed
kainino0x opened this issue Dec 9, 2024 · 6 comments
Closed

Behavior of NaNs and Infinities passed as float/double #466

kainino0x opened this issue Dec 9, 2024 · 6 comments
Assignees

Comments

@kainino0x
Copy link
Collaborator

kainino0x commented Dec 9, 2024

The JS API throws an exception (or rejects a promise with an exception) if NaN or Infinity is passed into any float/double (this rule comes from WebIDL; we don't use unrestricted which would lift it).

What should webgpu.h do when NaN or Infinity is passed to a required float/double, or Infinity is passed to an optional float/double (depthClearValue)?

The obvious answer is to produce a regular validation error, but Wasm implementations would technically need to detect these and inject them into the error scope. In practice, this is really unnecessary and impractical, so Wasm implementations would probably just crash by hitting the aforementioned JS exception. We could maybe say "may crash, and if not produces a validation error" I guess?

Forked from isnan question on #427.

@kainino0x kainino0x added the !discuss Needs discussion (at meeting or online) label Dec 9, 2024
@eliemichel
Copy link
Collaborator

Could be deemed as "undefined behavior", which in practice throws in JS and does whatever in native? Or do we want to avoid UB as much as possible?

@kainino0x
Copy link
Collaborator Author

We have been mostly avoiding UB as much as possible, however in this case I think it's unreasonable to fully define the behavior. Even trying to specify it as a crash gets into too many details (what if you catch the Wasm trap and handle it somehow, what if you re-enter Wasm from a new entrypoint; in native, what if you have signal handlers, etc.)

@kainino0x
Copy link
Collaborator Author

Dec 12 meeting:

  • What happens if you pass infinity/nan to a required float, or infinity to an optional float?
  • KN: Only problem is for wasm, otherwise validation error makes most sense.
  • CF: Can we just say exactly that it will cause an exception in wasm? Not make it more undefined than necessary.
  • Do that.

@kainino0x kainino0x self-assigned this Dec 12, 2024
@kainino0x kainino0x removed the !discuss Needs discussion (at meeting or online) label Dec 12, 2024
@kainino0x
Copy link
Collaborator Author

kainino0x commented Dec 13, 2024

I should make a list of what this applies to exactly. depthClearValue, WGPUColor, ...?

@kainino0x
Copy link
Collaborator Author

Here's the list of all floats and doubles:

  • Can we just say exactly that it will cause an exception in wasm?

To be more precise we should say it may cause an exception in wasm. On the off chance that either the JS spec changes or some wasm implementation wants to avoid crashing on non-finite inputs.

@kainino0x kainino0x added the needs docs Non-trivial API contract needs to be documented. Orthogonal to open vs closed; remove when doc'd. label Dec 19, 2024
@kainino0x
Copy link
Collaborator Author

Needs only docs.

@kainino0x kainino0x removed the needs docs Non-trivial API contract needs to be documented. Orthogonal to open vs closed; remove when doc'd. label Dec 21, 2024
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

No branches or pull requests

2 participants