这是indexloc提供的服务,不要输入任何密码
Skip to content

Handling of NaNs with Clamp (max/min) #5192

@petermcneeleychromium

Description

@petermcneeleychromium

Review of handling of nans for Clamp function.

For min,max in wgsl the behavior for nan is called out explicitly
This behavior comes from the extended instructions of NMin, NMax SPIRV

if one operand is a NaN, the other is returned.
If both operands are NaNs, a NaN is returned.

This means you can trivially sanitize nan with these functions.

For wgsl Clamp we have either the min(max(... behavior or

"the median of the three values e, low, high."

This variant comes from AMD (GCN) but what is there anything specific that it says about nans. Any sort (implied by the median) might place the nan in a different location based on the the fact evaluation of comparison of nan being false.

The implementation of clamp in gecko is FClamp which works for all cases except for Nan.
The implementation min,max in tint is also Fmin,Fmax again doesnt work for Nan.

Adreno has significant bugs with NClamp having to do with vec2 and modification of the y component when x is nan. These have been worked around for the time being.
Spir-v extended ops

Metadata

Metadata

Assignees

No one assigned

    Labels

    copyeditingPure editorial stuff (copyediting, *.bs file syntax, etc.)wgslWebGPU Shading Language Issues

    Type

    Projects

    Status

    Waiting for PR

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions