UNPKG

typegpu

Version:

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

186 lines (176 loc) 7.78 kB
import { W as Wgsl, J as JitTranspiler, T as TgpuRoot, A as AnyWgslData, a as TgpuFn, b as TgpuBufferUsage, I as Infer, c as TgpuAccessor, d as TgpuDerived, e as TgpuSlot, f as TgpuBindGroupLayout, g as TgpuVertexLayout, h as WgslArray, D as Disarray, i as TgpuBuffer, j as AnyData, k as bindGroupLayout, v as vertexLayout, l as fn, m as fragmentFn, n as vertexFn, o as computeFn, p as privateVar, w as workgroupVar, q as constant, r as declare, s as sampler, t as comparisonSampler } from './tgpuComputeFn-S61HxwW-.js'; export { am as BindLayoutEntry, a8 as Eventual, an as ExtractBindGroupInputFromLayout, ao as LayoutEntryToInput, R as RandomNameRegistry, ag as Render, ah as Sampled, Z as Storage, _ as StorageFlag, S as StrictNameRegistry, af as TextureProps, a9 as TgpuAnyTextureView, ap as TgpuBindGroup, a5 as TgpuBufferMutable, a6 as TgpuBufferReadonly, a7 as TgpuBufferUniform, aD as TgpuComputeFn, aE as TgpuComputeFnShell, a0 as TgpuComputePipeline, ai as TgpuConst, aF as TgpuDeclare, ay as TgpuFnShell, aB as TgpuFragmentFn, aC as TgpuFragmentFnShell, aq as TgpuLayoutComparisonSampler, ar as TgpuLayoutEntry, as as TgpuLayoutExternalTexture, at as TgpuLayoutSampler, au as TgpuLayoutStorage, av as TgpuLayoutStorageTexture, aw as TgpuLayoutTexture, ax as TgpuLayoutUniform, aa as TgpuMutableTexture, ab as TgpuReadonlyTexture, $ as TgpuRenderPipeline, ac as TgpuSampledTexture, al as TgpuSampler, ad as TgpuTexture, aj as TgpuVar, az as TgpuVertexFn, aA as TgpuVertexFnShell, ae as TgpuWriteonlyTexture, a1 as Uniform, a2 as UniformFlag, ak as VariableScope, a3 as Vertex, a4 as VertexFlag, U as WithBinding, V as WithCompute, X as WithFragment, Y as WithVertex, u as isBuffer, B as isComparisonSampler, y as isDerived, E as isSampledTextureView, C as isSampler, z as isSlot, F as isStorageTextureView, G as isTexture, Q as isTgpuFn, H as isUsableAsRender, K as isUsableAsSampled, L as isUsableAsStorage, P as isUsableAsUniform, x as isUsableAsVertex, M as unstable_asMutable, N as unstable_asReadonly, O as unstable_asUniform } from './tgpuComputeFn-S61HxwW-.js'; import 'tinyest'; interface TgpuResolveOptions { /** * Map of external names to their resolvable values. */ externals: Record<string, Wgsl | object>; /** * The code template to use for the resolution. All external names will be replaced with their resolved values. * @default '' */ template?: string | undefined; /** * The naming strategy used for generating identifiers for resolved externals and their dependencies. * @default 'random' */ names?: 'strict' | 'random' | undefined; /** * Optional JIT transpiler for resolving TGSL functions. * @experimental */ unstable_jitTranspiler?: JitTranspiler | undefined; } /** * Resolves a template with external values. Each external will get resolved to a code string and replaced in the template. * Any dependencies of the externals will also be resolved and included in the output. * @param options - The options for the resolution. * * @returns The resolved code. * * @example * ```ts * const Gradient = d.struct({ * from: d.vec3f, * to: d.vec3f, * }); * * const resolved = tgpu.resolve({ * template: ` * fn getGradientAngle(gradient: Gradient) -> f32 { * return atan(gradient.to.y - gradient.from.y, gradient.to.x - gradient.from.x); * } * `, * externals: { * Gradient, * }, * }); * * console.log(resolved); * // struct Gradient_0 { * // from: vec3f, * // to: vec3f, * // } * // fn getGradientAngle(gradient: Gradient_0) -> f32 { * // return atan(gradient.to.y - gradient.from.y, gradient.to.x - gradient.from.x); * // } * ``` */ declare function resolve(options: TgpuResolveOptions): string; /** * Options passed into {@link init}. */ type InitOptions = { adapter?: GPURequestAdapterOptions | undefined; device?: GPUDeviceDescriptor | undefined; /** @default 'random' */ unstable_names?: 'random' | 'strict' | undefined; unstable_jitTranspiler?: JitTranspiler | undefined; }; /** * Options passed into {@link initFromDevice}. */ type InitFromDeviceOptions = { device: GPUDevice; /** @default 'random' */ unstable_names?: 'random' | 'strict' | undefined; unstable_jitTranspiler?: JitTranspiler | undefined; }; /** * Requests a new GPU device and creates a root around it. * If a specific device should be used instead, use @see initFromDevice. * * @example * When given no options, the function will ask the browser for a suitable GPU device. * ```ts * const root = await tgpu.init(); * ``` * * @example * If there are specific options that should be used when requesting a device, you can pass those in. * ```ts * const adapterOptions: GPURequestAdapterOptions = ...; * const deviceDescriptor: GPUDeviceDescriptor = ...; * const root = await tgpu.init({ adapter: adapterOptions, device: deviceDescriptor }); * ``` */ declare function init(options?: InitOptions): Promise<TgpuRoot>; /** * Creates a root from the given device, instead of requesting it like @see init. * * @example * ```ts * const device: GPUDevice = ...; * const root = tgpu.initFromDevice({ device }); * ``` */ declare function initFromDevice(options: InitFromDeviceOptions): TgpuRoot; declare function accessor<T extends AnyWgslData>(schema: T, defaultValue?: TgpuFn<[], T> | TgpuBufferUsage<T> | Infer<T>): TgpuAccessor<T>; declare function derived<T>(compute: () => T): TgpuDerived<T>; declare function slot<T>(defaultValue?: T): TgpuSlot<T>; /** * An error that happens during resolution of WGSL code. * Contains a trace of all ancestor resolvables in * which this error originated. * * @category Errors */ declare class ResolutionError extends Error { readonly cause: unknown; readonly trace: unknown[]; constructor(cause: unknown, trace: unknown[]); appendToTrace(ancestor: unknown): ResolutionError; } /** * @category Errors */ declare class MissingSlotValueError extends Error { readonly slot: TgpuSlot<unknown>; constructor(slot: TgpuSlot<unknown>); } /** * @category Errors */ declare class NotUniformError extends Error { constructor(value: TgpuBuffer<AnyData>); } declare class MissingLinksError extends Error { constructor(fnLabel: string | undefined, externalNames: string[]); } declare class MissingBindGroupsError extends Error { constructor(layouts: Iterable<TgpuBindGroupLayout>); } declare class MissingVertexBuffersError extends Error { constructor(layouts: Iterable<TgpuVertexLayout<WgslArray | Disarray>>); } /** * @module typegpu */ declare const tgpu: { bindGroupLayout: typeof bindGroupLayout; vertexLayout: typeof vertexLayout; init: typeof init; initFromDevice: typeof initFromDevice; resolve: typeof resolve; '~unstable': { fn: typeof fn; fragmentFn: typeof fragmentFn; vertexFn: typeof vertexFn; computeFn: typeof computeFn; /** * @deprecated This feature is now stable, use tgpu.vertexLayout. */ vertexLayout: typeof vertexLayout; derived: typeof derived; slot: typeof slot; accessor: typeof accessor; privateVar: typeof privateVar; workgroupVar: typeof workgroupVar; const: typeof constant; declare: typeof declare; sampler: typeof sampler; comparisonSampler: typeof comparisonSampler; }; }; export { type InitFromDeviceOptions, type InitOptions, MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, ResolutionError, TgpuAccessor, TgpuBindGroupLayout, TgpuBuffer, TgpuDerived, TgpuFn, TgpuRoot, TgpuSlot, TgpuVertexLayout, tgpu as default, tgpu };