validateVariantsWgsl
On this page

validateVariantsWgsl()

Function in Variants

Validate every variant of a family through a real WGSL compiler.

import { validateVariantsWgsl } from 'typeshade'

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

Syntax

async function validateVariantsWgsl<A extends Record<string, readonly unknown[]>>(
device: WgslValidator,
family: VariantFamily<A>,
opts?: EmitOptions,
): Promise<readonly VariantWgslResult[]>

Parameters

device WgslValidator

a GPUDevice, or anything satisfying WgslValidator.

family VariantFamily<A>

the family to enumerate; every key in family.keys is attempted.

optsoptional EmitOptions

emit options, applied to every variant equally.

Return value

Promise<readonly VariantWgslResult[]>

one result per key, in family.keys order.

Description

The WGSL counterpart of linkVariants: the same enumeration, the same rule that every variant is attempted even after one fails, and the same per-key result shape. One WGSL module carries both entry points, so createShaderModule() followed by getCompilationInfo() is the whole check. getCompilationInfo() is asynchronous, which is why this function returns a promise while linkVariants does not.

const device = await (await navigator.gpu.requestAdapter())!.requestDevice()
const failed = (await validateVariantsWgsl(device, family)).filter((r) => !r.ok)
expect(failed, failed.map((r) => `${r.key}: ${r.errors?.join('; ')}`).join('\n')).toEqual([])

createShaderModule() does not throw on invalid WGSL; the errors arrive through getCompilationInfo(). This function reads those messages, so a shader that compiles without throwing but reports errors is still a failure.

See also

Source

src/core/variant-link.ts, line 238, at commit 26de7be8

Edit this page Report a problem