Repository navigation
Conversation
2 of 3 tasks
PaulHax
force-pushed
the
webgpu-finite-uint16-sampling
branch
from
November 7, 2026 19:13
b511d0a to
c18aec4
Compare
3 tasks done
PaulHax
force-pushed
the
webgpu-finite-uint16-sampling
branch
2 times, most recently
from
November 11, 2026 13:20
2bdf985 to
b5d305e
Compare
PaulHax
force-pushed
the
webgpu-finite-uint16-sampling
branch
from
November 12, 2026 13:41
b5d305e to
328c147
Compare
sankhesh
requested changes
Nov 17, 2026
Comment on lines
+14
to
+25
| // Prevent finite inputs such as Uint16 65535 from becoming infinite texels, | ||
| // which can contaminate interpolation with neighboring values. | ||
| function toHalfForUpload(value) { | ||
| let uploadValue = value; | ||
| if (Number.isFinite(value)) { | ||
| uploadValue = Math.max( | ||
| -MAX_FINITE_HALF_FLOAT, | ||
| Math.min(value, MAX_FINITE_HALF_FLOAT) | ||
| ); | ||
| } | ||
| return HalfFloat.toHalf(uploadValue); | ||
| } |
Collaborator
There was a problem hiding this comment.
With the clamp, finite values no longer reach HalfFloat.toHalf's overflow branch. Could we fix that in HalfFloat and move this clamp there as well? #3707 adds an identical toHalfForUpload for OpenGL, so both backends could share one helper.
Collaborator
Author
There was a problem hiding this comment.
toHalf's overflow branch now returns infinity of the same sign and keeps NaN. There's a new HalfFloat.toHalfClamped that clamps finite values to ±65504 and passes Infinity/NaN through, plus needsHalfFloatClamp for detecting when it clamps. WebGPU uses both, and #3707 can switch its toHalfForUpload to them once this lands.
| outArray[outOffset + i] = HalfFloat.toHalf( | ||
| inputArray[inOffset + i] | ||
| ); | ||
| outArray[outOffset + i] = toHalfForUpload(inputArray[inOffset + i]); |
Collaborator
There was a problem hiding this comment.
Could we warn once per texture when a value is clamped?
PaulHax
force-pushed
the
webgpu-finite-uint16-sampling
branch
3 times, most recently
from
November 17, 2026 16:56
f409333 to
3b895e7
Compare
Clamp finite values beyond the half float range to the largest finite half float when uploading to 16float textures, instead of letting them become infinity. Warn the first time a texture clamps a value, since devices without float32-filterable use half float without being asked to. Fix HalfFloat.toHalf so finite values beyond the half float range become infinity of the same sign and NaN stays NaN. JavaScript && returns its operand rather than 0 or 1, so the overflow branch ORed the whole float mantissa into the result. Add HalfFloat.toHalfClamped and needsHalfFloatClamp so texture uploads can share the clamp.
PaulHax
force-pushed
the
webgpu-finite-uint16-sampling
branch
from
November 17, 2026 20:02
3b895e7 to
9d25aae
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Uint16 values from 65520 through 65535 round to infinity in a half-float texture, and finite floating-point inputs beyond ±65504 can overflow too. A non-finite texel can affect interpolation with its neighbors. WebGPU uses half-float storage when
preferSizeOverAccuracyis set or when the device lacksfloat32-filterable.HalfFloat.toHalfalso mishandled overflow. JavaScript&&returns its operand rather than 0 or 1, so the overflow branch ORed the float mantissa into the result: 70000 converted to -Infinity, 1e38 to NaN, and NaN to +Infinity.Results
toHalfreturns infinity of the same sign for finite values beyond the range and keeps NaN. This also applies to the OpenGL half-float upload path, where NaN previously uploaded as +Infinity.Changes
HalfFloat.toHalf: fix the sign of overflowing values and keep NaN.HalfFloat.toHalfClamped(new): liketoHalf, but converts finite values beyond the range to ±65504. Infinity and NaN convert unchanged.HalfFloat.needsHalfFloatClamp(new): whethertoHalfClampedclamps a value.HalfFloat.MAX_FINITE_HALF_FLOAT(new): 65504.Texture: full and partial half-float uploads usetoHalfClampedand warn once per texture when they clamp.PR Checklist