Repository navigation
Closed
Labels
wgslWebGPU Shading Language Issues
Description
Proposal
Follow IEEE-754 except:
- No signalling NaNs
- No floating-point exceptions
- Implementations may flush denormals on arithmetic instructions
- we can either define the arithmetic instructions that flush them or the data movement instructions that must preserve them
- Implementation may assume that NaNs and infinities are not present
- Implementations may ignore the sign of a zero
- Use Vulkan accuracy
- Min and max on zeroes can return either operand
- No rounding mode is specified
The spec will need to define ULP and correctly rounded. Min and max definitions should be updated. Perhaps notes added about tests like isNan, isInf, etc that may not provide the expected results.
Survey
HLSL
HLSL appears to be quite strict in terms of numerical accuracy (see docs). Honours IEEE-754 generally. Uses round to even rounding mode.
Exceptions:
- No floating-point exceptions
- Denorms are flushed to appropriate signed zero, except for data movement
- Min/max on denorms flush inputs, but may not flush outputs
- Accuracy is generally 0.5 ULP, except:
- sqrt is 1 ULP (shader assembly sqrt is absolute error of 2-21)
- 1/x is 1 ULP (x/y must be at least as accurate as x * (1/y))
- rcp has absolute error of 2-21
- Following formulae must result in x (modulo denorm flushing):
- x * 1.0f must be x
- x / 1.0f must be x
- x +/- 0.0f must be x
- min(-0.0, +0.0) and min(+0.0, -0.0) , may be +/-0.0 (same for max)
- NaN on input produces NaN on output (though bit pattern may change), except for:
- min/max(SNaN, x) == nan, min/max(x, SNan) == nan
- min/max(QNaN, x) == x, min/max(x, QNaN) == x
MSL
The MSL compiler defaults to using fast relaxed math, so those conditions are documented here. I think fast relaxed math is what we should be aiming for in MVP. Uses round-to-even or round-to-zero rounding modes.
IEEE-754 Exceptions:
- May assume NaNs and infinities are not present
- Denormals may be flushed to zero on arithmetic inputs and outputs
- No floating-point exceptions
- Accuracy is given in table 7.2
- Some are ULP, some are derived
- Very similar to Vulkan, but a bit stricter in some cases
Vulkan
Vulkan basically assumes fast relaxed math.
IEEE-754 Exceptions
- May assume nans and infinities are not present
- Denorms may be flushed (except for data movement)
- No floating-point exceptions
- Signed zeroes and infinities are generated, but optimizations can ignore them so effectively not supported
- Accuracy defined or derived in tables 85 and 86
Metadata
Metadata
Assignees
Labels
wgslWebGPU Shading Language Issues
Activity
mmgeorge commentedon May 7, 2021
Somewhat related to this, is there any plan to add precision specifiers to WebGPU? Seems like maybe this is being discussed in #674? If so, it would be great if these were also well-defined types.
Related Section 4.5.2 of the GLSL Spec which states that:
It is strongly advised that the vertex language provide a floating point range and precision matching that
of an IEEE single precision floating point number, or better
It is useful, but not required, for the fragment language to provide the same floating point range and
precision as is required for the vertex shader.
alan-baker commentedon May 7, 2021
I believe mediump and the like are out of scope for MVP. I would anticipate separate extensions for both fp16 and relaxed precision after MVP.
mmgeorge commentedon May 7, 2021
@alan-baker does that mean that all implementations will be required to have FP32, or will certain implementations (e.g. mobile) be allowed to have less precision?
alan-baker commentedon May 10, 2021
Yes, all implementations will be 32-bit float only for MVP.
mmgeorge commentedon May 10, 2021
Thanks @alan-baker for the response! That was my only main concern.
litherum commentedon May 11, 2021
The group agreed (a while ago) to have a FP16 extension in MVP. I just haven't written the PR yet.
kdashg commentedon May 17, 2021
WGSL meeting minutes 2021-05-11
Add floating point execution rules
Add floating point execution rules (#1743)