fp64Guard
On this page

fp64Guard()

Function in Emulated f64

Pin the slot of the fp64 guard texture.

import { fp64Guard } from 'typeshade'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

function fp64Guard(at: { group: number; binding: number }): Fp64GuardHandle

Parameters

at { group: number; binding: number }

the group and binding to pin the guard texture to.

Return value

Fp64GuardHandle

the Fp64GuardHandle: .binding for module({ uses }), and .type.

Exceptions

SD0042

A module declaring its own fp64 binding with a different type or space fails emit with SD0042, and a declaration whose name starts with df64 or is one of the emitted DF64Vec2, DF64Vec3, DF64Vec4 structs collides with the emulation and fails with SD0043.

SD0043

A module declaring its own fp64 binding with a different type or space fails emit with SD0042, and a declaration whose name starts with df64 or is one of the emitted DF64Vec2, DF64Vec3, DF64Vec4 structs collides with the emulation and fails with SD0043.

Description

Most modules never call this: the guard is injected for you, and this exists for a fixed bind-group layout that needs it at a chosen (group, binding).

Every module whose lowered code calls a guarded df64 helper gets a texture_2d<f32> binding named _fp64 added by fp64Lower, deterministically at group 0 in the first free binding. A module whose only f64 work is comparisons, widening and narrowing, negation, or scaling by a power-of-two literal calls none and gets no binding; a host that binds _fp64 unconditionally should look for it in reflect() first. The host must bind a 1 by 1 texture whose single texel reads back exactly 1.0, an RGBA8 white texel or an R32F 1.0, and the shader multiplies the error-compensation terms by that texel.

It is a texture for a reason. WGSL permits reassociation, and Metal defaults to fast math, so without a value the compiler cannot see through, a downstream compiler can legally fold the emulation’s terms back to f32 precision. A uniform is not enough either: some drivers specialize pipelines on observed uniform values and hot-swap a re-optimized variant that folds the terms anyway. No compiler treats a texel as a compile-time constant.

Either way the binding appears in reflect as an ordinary 2D texture, so a host building its bind group from the reflection creates it without special-casing.

The names around it are reserved. A module declaring its own _fp64 binding with a different type or space fails emit with SD0042, and a declaration whose name starts with df64_ or is one of the emitted DF64Vec2, DF64Vec3, DF64Vec4 structs collides with the emulation and fails with SD0043.

Examples

Example

import { fp64Guard, module } from 'typeshade'
// Only needed when the host's bind-group layout fixes the slot.
const m = module({ uses: [U, fp64Guard({ group: 0, binding: 3 })], funcs: [k] })

In the guide

See also

Source

src/core/fp64/df64-lib.ts, line 197, at commit 26de7be8

Edit this page Report a problem