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

Numeric conversion rules wording is inconsistent #4538

Open
zoddicus opened this issue Mar 26, 2024 · 5 comments
Open

Numeric conversion rules wording is inconsistent #4538

zoddicus opened this issue Mar 26, 2024 · 5 comments
Assignees
Labels
copyediting Pure editorial stuff (copyediting, *.bs file syntax, etc.) wgsl resolved Resolved - waiting for a change to the WGSL specification wgsl WebGPU Shading Language Issues
Milestone

Comments

@zoddicus
Copy link
Contributor

zoddicus commented Mar 26, 2024

This originates from writing CTS tests for u32 & i32, and finding them failing for Dawn/Tint, issue.

There is some subtly inconsistancies in the language used for numeric conversions, which causes unexpected behaviours.

Specifically f16(e: T), i32(e: T), and u32(e: T) say 'T is a scalar type', where as f32(e: T) says 'T is a concrete scalar type'.

So for f32, AbstractInt and AbstractFloat go through conversion to a concrete type before being converted to the destination type, where as the others go directly. u32 and i32 have explicit language about how to handle AbstractInt, so this doesn't appear to be a simple typo.

Where this gets weird is when passing an out of range abstract floating point value into u32(). Conversion rules means that it will be rounded towards 0 to the nearest u32 (either 0 or max) instead of erroring, which multiple people have mentioned is unexpected.

@zoddicus zoddicus added the wgsl WebGPU Shading Language Issues label Mar 26, 2024
@dneto0
Copy link
Contributor

dneto0 commented Apr 30, 2024

Related to #4569

@kdashg
Copy link
Contributor

kdashg commented May 14, 2024

WGSL 2024-04-30 Minutes

@kdashg kdashg added this to the Milestone 1 milestone May 14, 2024
@dneto0
Copy link
Contributor

dneto0 commented May 14, 2024

Where this gets weird is when passing an out of range abstract floating point value into u32(). Conversion rules means that it will be rounded towards 0 to the nearest u32 (either 0 or max) instead of erroring, which multiple people have mentioned is unexpected.

The resolution to #4569 confirmed that truncate-to-zero-then-clamp is the intentional behaviour for u32(x) where x is out of bounds for u32.

The same set of rules apply to i32(x).

And completing the thought:

  • f16(x)
    • The finite range of f16 is roughly +/- 65K, so the same overflow cases occur when x is AbstractInt or i32.
    • Similarly, the same overflow cases occur for x in AbstractFloat or f32.

So no spec change is required. Closing.

@dneto0 dneto0 closed this as completed May 14, 2024
@dneto0
Copy link
Contributor

dneto0 commented May 14, 2024

Reopen to make f16 and f32 wording consistent. My preference is to separate the f16 cases into abstract and concrete cases.

@dneto0 dneto0 reopened this May 14, 2024
@dneto0 dneto0 added wgsl resolved Resolved - waiting for a change to the WGSL specification copyediting Pure editorial stuff (copyediting, *.bs file syntax, etc.) labels May 14, 2024
@kdashg
Copy link
Contributor

kdashg commented May 14, 2024

WGSL 2024-05-14 Minutes
  • DN: Alan and I verified the key issue is overflow behavior for u32(x) and i32(x), and that was resolved in #4569 in the last meeting. Also I verified that the f16(x) cases do the correct thing across all scalar argument types. I closed the issue as no-change-to-spec.
  • JB: Mozilla’s main concern now after 4569 was that f32 was different from f16, as the most surprising thing here
  • DN: We’re happy to resolve to clarify (though they are behaviorally the same) that f16 behaves the same as f32.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
copyediting Pure editorial stuff (copyediting, *.bs file syntax, etc.) wgsl resolved Resolved - waiting for a change to the WGSL specification wgsl WebGPU Shading Language Issues
Projects
None yet
Development

No branches or pull requests

3 participants