-
Notifications
You must be signed in to change notification settings - Fork 345
Description
The WGSL spec isn't very clear about whether any of the derivatives are guaranteed to be fine or guaranteed to be coarse.
The default derivatives (dpdx/dpdy/fwidth) and coarse derivatives (dpdxCoarse/dpdyCoarse/fwidthCoarse) are definitely not guaranteed to be either coarse or fine, as that's not guaranteed by backends. For example, SPIR-V.
I'm unsure about the fine derivatives (dpdxFine/dpdyFine/fwidthFine). My reading of the underlying specs is:
-
Vulkan guarantees it:
OpDPdxFineis always fine, the others may be either coarse or fine.SPIR-V might guarantee it?OpDPdxFine is unclear:
Uses local differencing based on the value of P for the current fragment and its immediate neighbor(s).
But contrast this with the definition for OpDPdxCoarse:
Uses local differencing based on the value of P for the current fragment’s neighbors, and possibly, but not necessarily, includes the value of P for the current fragment. That is, over a given area, the implementation can compute x derivatives in fewer unique locations than would be allowed for OpDPdxFine.
-
D3D guarantees it? It reads like ddx_fine is always fine, and ddx_coarse is always coarse.
Fine:
Computes a high precision partial derivative with respect to the screen-space x-coordinate.
Coarse:
Computes a low precision partial derivative with respect to the screen-space x-coordinate.
-
Metal guarantees it? Metal only has one derivative, and it sounds like it's fine (but it's not totally clear that "high precision" means "high spatial precision" (fine)):
Returns a high precision partial derivative of the specified value with respect to the screen space x coordinate.
-
Desktop OpenGL 4.5+ probably guarantees it? The OpenGL API spec says nothing, but GLSL 4.50/4.60 uses the same language as SPIR-V.
Fine:
Returns the partial derivative of p with respect to the window x coordinate. Will use local differencing based on the value of p for the current fragment and its immediate neighbor(s).
Coarse:
Returns the partial derivative of p with respect to the window x coordinate. Will use local differencing based on the value of p for the current fragment’s neighbors, and will possibly, but not necessarily, include the value of p for the current fragment. That is, over a given area, the implementation can x compute derivatives in fewer unique locations than would be allowed for dFdxFine(p).
-
OpenGL ES and desktop OpenGL ≤4.4 are unclear. GLSL 4.40 and GLSL ES 3.20 don't have coarse/fine variants, and both have the same language:
Returns the derivative in x using local differencing for the input argument p.
Aside from clarifying the spec, the motivating question here is: does the WebGPU Compat spec need to loosen the guarantee for what dpdxFine does?
| Core WGSL | OpenGL ES | Compat | ||
|---|---|---|---|---|
| If | core 'fine' may be coarse | then | no need to add a caveat | |
| If | core 'fine' must be fine | and ES 'fine' may be coarse | then | need to add a caveat |
| If | core 'fine' must be fine | and ES 'fine' is always fine (at least in practice) | then | no need to add a caveat |