-
Notifications
You must be signed in to change notification settings - Fork 308
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
Clarify behavior of (norm) packing built-in functions #4159
Comments
The rounding mode is not specified. It may round up or down. The conformance tests are written to allow either rounding. |
Hi, I'm the person that ran into this while implementing HLSL polyfills for the bitpacking/unpacking ops for naga/wgpu. The pack2x16snorm and pack4x8snorm tests only include a single result, but in my testing the polyfills from #1189 (comment) give different results for any of the -0.5 tests. edit: eg. for |
WGSL 2023-06-06 Minutes
|
It seems like there are two tests for pack4x8snorm in the CTS. There's one test in webgpu/execution/expression/call/builtin/pack4x8snorm which is properly written to respect rounding mode, and there's a separate test in unittests/conversion, which assumes a certain rounding mode. Should the tests in unittests/conversion.spec.ts be ignored? |
I believe this is just a test bug then! |
According to the comment #1189 (comment) on the PR that initially added those to the spec, they are supposed to map to operations in SPIR-V's GLSL.std.450 extended instruction set, MSL built-in functions and only need to be polyfilled on HLSL.
However, there is discrepancy between the comment and what got landed as part of the PR.
The behavior of the SPIR-V operations and the HLSL polyfill in the comment use
round(x)
instead offloor(0.5 + x)
as dictated by the contents of the PR (and current version of the spec).For SPIR-V, the definition of
round
one should use is not explicitly stated in the sections of each of the packing functions but I would assume theRound
op in the same file is what should be used? If so, it states that:which sounds like bad news since it's implementation defined.
from https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html
The behavior of HLSL's
round
intrinsic is:which sounds the same as SPIR-V's
RoundEven
.from https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-round
Regarding MSL, its spec doesn't say how the f32 -> norm16 conversion happens. We can of course test the behavior on the range of hardware we are targeting but it would be nice to have a guarantee for a specific behavior.
Questions
floor
intended? If so, it sounds like only MSL could? have a fast path for these functions.round
behavior being implementation defined? Or is it alwaysRoundEven
in practice (and how do we make sure)?The text was updated successfully, but these errors were encountered: