recommendFp64Flavor
이 페이지에서

recommendFp64Flavor()

함수, f64 에뮬레이션 분류

Pick the df64 flavour a device needs for correct results, from whatever identifying signals a host has.

import { recommendFp64Flavor } from 'typeshade'

시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.

구문

function recommendFp64Flavor(s: Fp64FlavorSignals): Fp64Flavor

매개변수

s Fp64FlavorSignals

the device signals the host was able to collect.

반환값

Fp64Flavor

'integer' on an Apple or Metal-backed context, 'float' everywhere else.

설명

Pass the result as EmitOptions.fp64Flavor.

The flavour differs by device because of one operation. The df64 multiply relies on error terms that are algebraically zero, and a compiler allowed to reassociate can cancel them. On Apple GPUs, where Metal runs underneath whether the path is WebGPU or WebGL2 through ANGLE, the shader compiler defaults to fast math and collapses that multiply at any large-magnitude cancellation, and no in-shader barrier prevents it. sin and cos are built on that multiply, so they inherit the same fragility there. An Apple signal therefore selects 'integer', which does the same arithmetic through integer primitives fast math cannot touch, and every other device gets 'float', which is correct on those devices and cheaper.

D3D11 through ANGLE gets 'float' as well. Its compiler can fold very deep synthetic df64 expression trees, but the float flavour’s renormalisation holds on the chains that occur in practice, and compiling the fully inlined integer bodies there is expensive enough to reset the device.

The library cannot see a GPU, so the signals come from the caller: a WebGPU adapter’s info, a WebGL2 UNMASKED_RENDERER_WEBGL string, a user agent. All are optional, any single Apple signal selects 'integer', and passing none returns 'float'.

예제

예제

import { recommendFp64Flavor, emitModule } from 'typeshade'
const fp64Flavor = recommendFp64Flavor({ adapterInfo: adapter.info, userAgent: navigator.userAgent })
const wgsl = emitModule(MODULE, { fp64Flavor })

관련 가이드

함께 보기

소스

src/core/fp64/flavor-select.ts, 102행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고