UNPKG

typegpu

Version:

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

34 lines (33 loc) 1.15 kB
import type { BaseData } from '../../data/wgslTypes.ts'; import type { TgpuBuffer } from '../buffer/buffer.ts'; import type { TgpuVar } from '../variable/tgpuVariable.ts'; interface SimulationResult<T> { value: T; buffers: Map<TgpuBuffer<BaseData>, unknown>; privateVars: Map<TgpuVar<'private'>, unknown>[][][]; workgroupVars: Map<TgpuVar<'workgroup'>, unknown>[][][]; } /** * Runs the provided callback in a simulated environment, giving * it access to buffers and variables as if it were running on the GPU. * * The result of the simulation is returned, and does not affect the actual GPU state, * nor does it carry over to other simulations. * * @param callback The callback to run in the simulated environment. * @returns An object containing the result of the simulation, and * the final state of the environment. * * @example * const counter = tgpu.privateVar(d.u32); * * const result = tgpu.simulate(() => { * counter.$ += 1; * counter.$ += 2; * return counter.$; * }); * * console.log(result.value); // 3 */ export declare function simulate<T>(callback: () => T): SimulationResult<T>; export {};