UNPKG

typegpu

Version:

A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.

63 lines (62 loc) 1.84 kB
import { isLazy, isProviding, isSlot, } from "./core/slot/slotTypes.js"; import { UnknownData } from "./data/dataTypes.js"; import { isWgslData, } from "./data/wgslTypes.js"; import { $cast, $gpuCallable, $gpuValueOf, $internal, $ownSnippet, $resolve, } from "./shared/symbols.js"; export class NormalState { type = 'normal'; } export class CodegenState { type = 'codegen'; } export class SimulationState { type = 'simulate'; buffers; vars; constructor(buffers, vars) { this.buffers = buffers; this.vars = vars; } } export function isSelfResolvable(value) { return !!value?.[$resolve]; } export function getOwnSnippet(value) { return value?.[$ownSnippet]; } export function isGPUCallable(value) { return !!value?.[$gpuCallable]; } export function hasCast(value) { return !!value?.[$cast]; } export function isKnownAtComptime(snippet) { return ((typeof snippet.value !== 'string' || snippet.dataType === UnknownData) && getOwnSnippet(snippet.value) === undefined); } export function isWgsl(value) { return (typeof value === 'number' || typeof value === 'boolean' || isSelfResolvable(value) || isWgslData(value) || isSlot(value) || isLazy(value) || isProviding(value)); } export function isGPUBuffer(value) { return !!value && typeof value === 'object' && 'getMappedRange' in value && 'mapAsync' in value; } export function isBuffer(value) { return value.resourceType === 'buffer'; } export function isUsableAsVertex(buffer) { return !!buffer.usableAsVertex; } export function isUsableAsIndex(buffer) { return !!buffer.usableAsIndex; } export function isUsableAsUniform(buffer) { return !!buffer.usableAsUniform; } export function isUsableAsStorage(value) { return !!value?.usableAsStorage; }