-
Notifications
You must be signed in to change notification settings - Fork 80
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
Helper for robust texture content checking #1055
Conversation
20404bf
to
c08d618
Compare
df87f13
to
f88294b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've integrated the PR and running it locally. After fixing some bugs, most cases in copy_to_texture
works fine, except for ColorSpaceConversion
cases, which requires fix asserts in floatAsNormalizedInteger
and have some ULP tolerance.
src/webgpu/util/copy_to_texture.ts
Outdated
{ texture: dstTextureCopyView.texture }, | ||
copySize, | ||
{ | ||
maxDiffULPs: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will fail the color space conversion
cases.
The error comes from different precision in CPU color space conversion algorithm and the implementation.
Maybe we could provide maxDiffULPs
in doTestAndCheckResult
and set the value case by case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, I've put a fixed 0.001 threshold on all of these tests. I found that even the 0.0002 from the original code for float16 wasn't enough, and I didn't dig enough to find out why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be the color space conversion matrix precision issue. The matrix CPU used is here (https://github.com/gpuweb/cts/blob/main/src/webgpu/util/color_space_conversion.ts#L63). Even the comments said it is copied from ( http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html) but they're different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old commit here (f9158e4#diff-0781362fbbe96f1c4922e18e4ccead52e6c15573ed9bfa091c5b039c940e4d08R270) shows that for fp16, if we handle around 0 values, the other values could be in 1 ULP diff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be the color space conversion matrix precision issue.
I suspected this as well, especially because the G channel in some test cases is way farther off than the others.
That old commit is exactly why I'm confused I needed a larger threshold than before. Will see what I can figure out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shaoboyan would you be able to look into the implementation to find out if the relatively-large diff in the G channel is due to a precision issue in the implementation? It's not very important though, so only if you're able to check easily.
// Mask only the mantissa, and discard the lower bits. | ||
const newMantissa = (bits & 0x7fffff) >> mantissaBitsToDiscard; | ||
return (sign << (exponentBits + mantissaBits)) | (newBiasedExp << mantissaBits) | newMantissa; | ||
if (newBiasedExp <= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we throw errors or add assert for this instead of reset it to 0? I'm not sure whether this means bugs in the test cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the best would be to actually handle conversion from normal number
s to subnormal f16, but for the purpose of ULP checks, we don't care about subnormal - we round all subnormal numbers to 0. And generally GPUs don't guarantee results in the subnormal range anyway for a lot of operations. So I think it's unlikely to be a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code asserted, but that assertion was hit because we generated small number
s in color space conversion and then tried to convert to f16.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also recalled that on chromium implementaion, we always convert the White to D50 config (in this case D65 -> D50). This also introduce some precision difference.
src/webgpu/util/copy_to_texture.ts
Outdated
{ texture: dstTextureCopyView.texture }, | ||
copySize, | ||
{ | ||
maxDiffULPs: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old commit here (f9158e4#diff-0781362fbbe96f1c4922e18e4ccead52e6c15573ed9bfa091c5b039c940e4d08R270) shows that for fp16, if we handle around 0 values, the other values could be in 1 ULP diff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Hope we can get rid of the frac compare for fp16.
I'm going to do a big reshuffle of the commits in this PR so that they're nicely grouped (no separate commits for revisions so it's easier for a new reviewer). For posterity, here's the log at this moment, prior to squashing (note a few fixes went in after this, and #1089 was split out). |
a5f3280
to
ae33f39
Compare
@austinEng PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments after a first pass - I'll need to look again.
Overall though, this is super cool! great example of how a bunch of small utility functions can be put together to make something quite nuanced and complex
src/webgpu/util/check_contents.ts
Outdated
@@ -1,3 +1,7 @@ | |||
// MAINTENANCE_TODO: The "checkThingTrue" naming is confusing; these must be used with `expectOK` | |||
// or the result is dropped on the floor. Rename these to things like `typedArrayIsOK`(??) to | |||
// make it clearer. Also, audit to make sure we aren't dropping any on the floor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if only typescript could error if a result is unused (maybe it's a thing :o)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
474bf97
to
764bcf4
Compare
b3b56f1
to
29870bb
Compare
Previews, as seen when this build job started (b3b56f1): |
29870bb
to
759728c
Compare
Previews, as seen when this build job started (759728c): |
Small unreviewed changes: |
dc82768
to
81ca4e4
Compare
refactor colorspace/premul conversion into a standalone helper; fix computation of require{Unpremultiply,Premultiply}Alpha
…r_space_conversion tests work without it
81ca4e4
to
048dae5
Compare
Previews, as seen when this build job started (dc82768): |
Previews, as seen when this build job started (048dae5): |
The commits in this PR can be reviewed separately (likely helpful for some of them).
Issue: #881
Dry run against Chromium:
https://chromium-review.googlesource.com/c/chromium/src/+/3531550/5
(The only failures are a flake and a simple precision issue, fixed in 759728c...dc82768)
Requirements for PR author:
.unimplemented()
./** documented */
and new helper files are found inhelper_index.txt
.Requirements for reviewer sign-off:
When landing this PR, be sure to make any necessary issue status updates.