validateVariantsWgsl()
함수, 배리언트 분류
Validate every variant of a family through a real WGSL compiler.
import { validateVariantsWgsl } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
async function validateVariantsWgsl<A extends Record<string, readonly unknown[]>>( device: WgslValidator, family: VariantFamily<A>, opts?: EmitOptions,): Promise<readonly VariantWgslResult[]>매개변수
deviceWgslValidatora
GPUDevice, or anything satisfyingWgslValidator.familyVariantFamily<A>the family to enumerate; every key in
family.keysis attempted.opts선택 사항EmitOptionsemit options, applied to every variant equally.
반환값
Promise<readonly VariantWgslResult[]>
one result per key, in family.keys order.
설명
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.
함께 보기
소스
src/core/variant-link.ts, 238행, 커밋 c66579bf 기준