typegpu 0.5.9 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/chunk-3K53YJSU.cjs +10 -0
  2. package/chunk-3K53YJSU.cjs.map +1 -0
  3. package/chunk-BF35NEOX.cjs +43 -0
  4. package/chunk-BF35NEOX.cjs.map +1 -0
  5. package/chunk-IH2QU6TV.js +43 -0
  6. package/chunk-IH2QU6TV.js.map +1 -0
  7. package/chunk-S27MYQ6U.js +10 -0
  8. package/chunk-S27MYQ6U.js.map +1 -0
  9. package/data/index.cjs +1 -1
  10. package/data/index.cjs.map +1 -1
  11. package/data/index.d.cts +30 -4
  12. package/data/index.d.ts +30 -4
  13. package/data/index.js +1 -1
  14. package/index.cjs +18 -29
  15. package/index.cjs.map +1 -1
  16. package/index.d.cts +95 -9
  17. package/index.d.ts +95 -9
  18. package/index.js +18 -29
  19. package/index.js.map +1 -1
  20. package/{matrix-BULDDGYa.d.ts → matrix-BXuR-7-A.d.ts} +1 -1
  21. package/{matrix-BnXitNJ7.d.cts → matrix-DzXuhOr3.d.cts} +1 -1
  22. package/package.json +1 -1
  23. package/std/index.cjs +1 -1
  24. package/std/index.cjs.map +1 -1
  25. package/std/index.d.cts +22 -9
  26. package/std/index.d.ts +22 -9
  27. package/std/index.js +1 -1
  28. package/std/index.js.map +1 -1
  29. package/{tgpuComputeFn-BxPDI5hQ.d.ts → tgpuConstant-BAmV6caN.d.cts} +3254 -2840
  30. package/{tgpuComputeFn-BxPDI5hQ.d.cts → tgpuConstant-BAmV6caN.d.ts} +3254 -2840
  31. package/chunk-734H4JWF.js +0 -2
  32. package/chunk-734H4JWF.js.map +0 -1
  33. package/chunk-BJSN5UVV.cjs +0 -41
  34. package/chunk-BJSN5UVV.cjs.map +0 -1
  35. package/chunk-BZVU4Q6A.cjs +0 -2
  36. package/chunk-BZVU4Q6A.cjs.map +0 -1
  37. package/chunk-CDUKTYES.cjs +0 -2
  38. package/chunk-CDUKTYES.cjs.map +0 -1
  39. package/chunk-CGVYLGBG.js +0 -2
  40. package/chunk-CGVYLGBG.js.map +0 -1
  41. package/chunk-SWJVYRFM.js +0 -41
  42. package/chunk-SWJVYRFM.js.map +0 -1
  43. /package/{LICENSE.md → LICENSE} +0 -0
package/index.d.cts CHANGED
@@ -1,7 +1,20 @@
1
- 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-BxPDI5hQ.cjs';
2
- 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-BxPDI5hQ.cjs';
1
+ import { T as TgpuBindGroupLayout, a as TgpuBindGroup, W as Wgsl, C as Configurable, b as TgpuBuffer, A as AnyData, c as TgpuVar, d as TgpuRoot, e as AnyWgslData, f as TgpuFn, g as TgpuBufferUsage, I as Infer, h as TgpuAccessor, i as TgpuDerived, j as TgpuSlot, k as TgpuVertexLayout, l as WgslArray, D as Disarray, m as fn, n as bindGroupLayout, v as vertexLayout, o as fragmentFn, p as vertexFn, q as computeFn, r as privateVar, w as workgroupVar, s as constant, t as declare, u as sampler, x as comparisonSampler } from './tgpuConstant-BAmV6caN.cjs';
2
+ export { aq as BindLayoutEntry, ac as Eventual, ar as ExtractBindGroupInputFromLayout, aJ as INTERNAL_GlobalExt, a0 as IndexFlag, as as LayoutEntryToInput, ak as Render, al as Sampled, Y as Storage, Z as StorageFlag, aj as TextureProps, ad as TgpuAnyTextureView, a6 as TgpuBufferMutable, a7 as TgpuBufferReadonly, a8 as TgpuBufferUniform, aG as TgpuComputeFn, aH as TgpuComputeFnShell, $ as TgpuComputePipeline, am as TgpuConst, aI as TgpuDeclare, aB as TgpuFnShell, aE as TgpuFragmentFn, aF as TgpuFragmentFnShell, at as TgpuLayoutComparisonSampler, au as TgpuLayoutEntry, av as TgpuLayoutExternalTexture, aw as TgpuLayoutSampler, ax as TgpuLayoutStorage, ay as TgpuLayoutStorageTexture, az as TgpuLayoutTexture, aA as TgpuLayoutUniform, a9 as TgpuMutable, ae as TgpuMutableTexture, ap as TgpuQuerySet, aa as TgpuReadonly, af as TgpuReadonlyTexture, _ as TgpuRenderPipeline, ag as TgpuSampledTexture, ao as TgpuSampler, ah as TgpuTexture, ab as TgpuUniform, aC as TgpuVertexFn, aD as TgpuVertexFnShell, ai as TgpuWriteonlyTexture, a1 as Uniform, a2 as UniformFlag, a3 as ValidUsagesFor, V as ValidateBufferSchema, an as VariableScope, a4 as Vertex, a5 as VertexFlag, R as WithBinding, S as WithCompute, U as WithFragment, X as WithVertex, y as isBuffer, P as isBufferShorthand, F as isComparisonSampler, B as isDerived, H as isSampledTextureView, G as isSampler, E as isSlot, J as isStorageTextureView, K as isTexture, Q as isTgpuFn, L as isUsableAsRender, M as isUsableAsSampled, N as isUsableAsStorage, O as isUsableAsUniform, z as isUsableAsVertex } from './tgpuConstant-BAmV6caN.cjs';
3
3
  import 'tinyest';
4
4
 
5
+ /**
6
+ * The results of a WGSL resolution.
7
+ *
8
+ * @param code - The resolved code.
9
+ * @param usedBindGroupLayouts - List of used `tgpu.bindGroupLayout`s.
10
+ * @param catchall - Automatically constructed bind group for buffer usages and buffer shorthands, preceded by its index.
11
+ */
12
+ interface ResolutionResult {
13
+ code: string;
14
+ usedBindGroupLayouts: TgpuBindGroupLayout[];
15
+ catchall: [number, TgpuBindGroup] | undefined;
16
+ }
17
+
5
18
  interface TgpuResolveOptions {
6
19
  /**
7
20
  * Map of external names to their resolvable values.
@@ -18,11 +31,46 @@ interface TgpuResolveOptions {
18
31
  */
19
32
  names?: 'strict' | 'random' | undefined;
20
33
  /**
21
- * Optional JIT transpiler for resolving TGSL functions.
22
- * @experimental
34
+ * A function to configure the resolution context.
23
35
  */
24
- unstable_jitTranspiler?: JitTranspiler | undefined;
36
+ config?: ((cfg: Configurable) => Configurable) | undefined;
25
37
  }
38
+ /**
39
+ * Resolves a template with external values. Each external will get resolved to a code string and replaced in the template.
40
+ * Any dependencies of the externals will also be resolved and included in the output.
41
+ * @param options - The options for the resolution.
42
+ *
43
+ * @returns {ResolutionResult}
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const Gradient = d.struct({
48
+ * from: d.vec3f,
49
+ * to: d.vec3f,
50
+ * });
51
+ *
52
+ * const { code, usedBindGroupLayouts, catchall } = tgpu.resolveWithContext({
53
+ * template: `
54
+ * fn getGradientAngle(gradient: Gradient) -> f32 {
55
+ * return atan(gradient.to.y - gradient.from.y, gradient.to.x - gradient.from.x);
56
+ * }
57
+ * `,
58
+ * externals: {
59
+ * Gradient,
60
+ * },
61
+ * });
62
+ *
63
+ * console.log(code);
64
+ * // struct Gradient_0 {
65
+ * // from: vec3f,
66
+ * // to: vec3f,
67
+ * // }
68
+ * // fn getGradientAngle(gradient: Gradient_0) -> f32 {
69
+ * // return atan(gradient.to.y - gradient.from.y, gradient.to.x - gradient.from.x);
70
+ * // }
71
+ * ```
72
+ */
73
+ declare function resolveWithContext(options: TgpuResolveOptions): ResolutionResult;
26
74
  /**
27
75
  * Resolves a template with external values. Each external will get resolved to a code string and replaced in the template.
28
76
  * Any dependencies of the externals will also be resolved and included in the output.
@@ -60,6 +108,36 @@ interface TgpuResolveOptions {
60
108
  */
61
109
  declare function resolve(options: TgpuResolveOptions): string;
62
110
 
111
+ interface SimulationResult<T> {
112
+ value: T;
113
+ buffers: Map<TgpuBuffer<AnyData>, unknown>;
114
+ privateVars: Map<TgpuVar<'private', AnyData>, unknown>[][][];
115
+ workgroupVars: Map<TgpuVar<'workgroup', AnyData>, unknown>[][][];
116
+ }
117
+ /**
118
+ * Runs the provided callback in a simulated environment, giving
119
+ * it access to buffers and variables as if it were running on the GPU.
120
+ *
121
+ * The result of the simulation is returned, and does not affect the actual GPU state,
122
+ * nor does it carry over to other simulations.
123
+ *
124
+ * @param callback The callback to run in the simulated environment.
125
+ * @returns An object containing the result of the simulation, and
126
+ * the final state of the environment.
127
+ *
128
+ * @example
129
+ * const counter = tgpu.privateVar(d.u32);
130
+ *
131
+ * const result = tgpu.simulate(() => {
132
+ * counter.$ += 1;
133
+ * counter.$ += 2;
134
+ * return counter.$;
135
+ * });
136
+ *
137
+ * console.log(result.value); // 3
138
+ */
139
+ declare function simulate<T>(callback: () => T): SimulationResult<T>;
140
+
63
141
  /**
64
142
  * Options passed into {@link init}.
65
143
  */
@@ -70,7 +148,6 @@ type InitOptions = {
70
148
  } | undefined;
71
149
  /** @default 'random' */
72
150
  unstable_names?: 'random' | 'strict' | undefined;
73
- unstable_jitTranspiler?: JitTranspiler | undefined;
74
151
  };
75
152
  /**
76
153
  * Options passed into {@link initFromDevice}.
@@ -79,7 +156,6 @@ type InitFromDeviceOptions = {
79
156
  device: GPUDevice;
80
157
  /** @default 'random' */
81
158
  unstable_names?: 'random' | 'strict' | undefined;
82
- unstable_jitTranspiler?: JitTranspiler | undefined;
83
159
  };
84
160
  /**
85
161
  * Requests a new GPU device and creates a root around it.
@@ -111,7 +187,7 @@ declare function init(options?: InitOptions): Promise<TgpuRoot>;
111
187
  */
112
188
  declare function initFromDevice(options: InitFromDeviceOptions): TgpuRoot;
113
189
 
114
- declare function accessor<T extends AnyWgslData>(schema: T, defaultValue?: TgpuFn<[], T> | TgpuBufferUsage<T> | Infer<T>): TgpuAccessor<T>;
190
+ declare function accessor<T extends AnyWgslData>(schema: T, defaultValue?: TgpuFn<() => T> | TgpuBufferUsage<T> | Infer<T>): TgpuAccessor<T>;
115
191
 
116
192
  declare function derived<T>(compute: () => T): TgpuDerived<T>;
117
193
 
@@ -158,12 +234,18 @@ declare class MissingVertexBuffersError extends Error {
158
234
  */
159
235
 
160
236
  declare const tgpu: {
237
+ fn: typeof fn;
161
238
  bindGroupLayout: typeof bindGroupLayout;
162
239
  vertexLayout: typeof vertexLayout;
240
+ slot: typeof slot;
163
241
  init: typeof init;
164
242
  initFromDevice: typeof initFromDevice;
165
243
  resolve: typeof resolve;
244
+ resolveWithContext: typeof resolveWithContext;
166
245
  '~unstable': {
246
+ /**
247
+ * @deprecated This feature is now stable, use tgpu.fn.
248
+ */
167
249
  fn: typeof fn;
168
250
  fragmentFn: typeof fragmentFn;
169
251
  vertexFn: typeof vertexFn;
@@ -173,6 +255,9 @@ declare const tgpu: {
173
255
  */
174
256
  vertexLayout: typeof vertexLayout;
175
257
  derived: typeof derived;
258
+ /**
259
+ * @deprecated This feature is now stable, use tgpu.slot.
260
+ */
176
261
  slot: typeof slot;
177
262
  accessor: typeof accessor;
178
263
  privateVar: typeof privateVar;
@@ -181,7 +266,8 @@ declare const tgpu: {
181
266
  declare: typeof declare;
182
267
  sampler: typeof sampler;
183
268
  comparisonSampler: typeof comparisonSampler;
269
+ simulate: typeof simulate;
184
270
  };
185
271
  };
186
272
 
187
- export { type InitFromDeviceOptions, type InitOptions, MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, ResolutionError, TgpuAccessor, TgpuBindGroupLayout, TgpuBuffer, TgpuDerived, TgpuFn, TgpuRoot, TgpuSlot, TgpuVertexLayout, tgpu as default, tgpu };
273
+ export { Configurable, type InitFromDeviceOptions, type InitOptions, MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, ResolutionError, TgpuAccessor, TgpuBindGroup, TgpuBindGroupLayout, TgpuBuffer, TgpuDerived, TgpuFn, TgpuRoot, TgpuSlot, TgpuVar, TgpuVertexLayout, tgpu as default, tgpu };
package/index.d.ts CHANGED
@@ -1,7 +1,20 @@
1
- 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-BxPDI5hQ.js';
2
- 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-BxPDI5hQ.js';
1
+ import { T as TgpuBindGroupLayout, a as TgpuBindGroup, W as Wgsl, C as Configurable, b as TgpuBuffer, A as AnyData, c as TgpuVar, d as TgpuRoot, e as AnyWgslData, f as TgpuFn, g as TgpuBufferUsage, I as Infer, h as TgpuAccessor, i as TgpuDerived, j as TgpuSlot, k as TgpuVertexLayout, l as WgslArray, D as Disarray, m as fn, n as bindGroupLayout, v as vertexLayout, o as fragmentFn, p as vertexFn, q as computeFn, r as privateVar, w as workgroupVar, s as constant, t as declare, u as sampler, x as comparisonSampler } from './tgpuConstant-BAmV6caN.js';
2
+ export { aq as BindLayoutEntry, ac as Eventual, ar as ExtractBindGroupInputFromLayout, aJ as INTERNAL_GlobalExt, a0 as IndexFlag, as as LayoutEntryToInput, ak as Render, al as Sampled, Y as Storage, Z as StorageFlag, aj as TextureProps, ad as TgpuAnyTextureView, a6 as TgpuBufferMutable, a7 as TgpuBufferReadonly, a8 as TgpuBufferUniform, aG as TgpuComputeFn, aH as TgpuComputeFnShell, $ as TgpuComputePipeline, am as TgpuConst, aI as TgpuDeclare, aB as TgpuFnShell, aE as TgpuFragmentFn, aF as TgpuFragmentFnShell, at as TgpuLayoutComparisonSampler, au as TgpuLayoutEntry, av as TgpuLayoutExternalTexture, aw as TgpuLayoutSampler, ax as TgpuLayoutStorage, ay as TgpuLayoutStorageTexture, az as TgpuLayoutTexture, aA as TgpuLayoutUniform, a9 as TgpuMutable, ae as TgpuMutableTexture, ap as TgpuQuerySet, aa as TgpuReadonly, af as TgpuReadonlyTexture, _ as TgpuRenderPipeline, ag as TgpuSampledTexture, ao as TgpuSampler, ah as TgpuTexture, ab as TgpuUniform, aC as TgpuVertexFn, aD as TgpuVertexFnShell, ai as TgpuWriteonlyTexture, a1 as Uniform, a2 as UniformFlag, a3 as ValidUsagesFor, V as ValidateBufferSchema, an as VariableScope, a4 as Vertex, a5 as VertexFlag, R as WithBinding, S as WithCompute, U as WithFragment, X as WithVertex, y as isBuffer, P as isBufferShorthand, F as isComparisonSampler, B as isDerived, H as isSampledTextureView, G as isSampler, E as isSlot, J as isStorageTextureView, K as isTexture, Q as isTgpuFn, L as isUsableAsRender, M as isUsableAsSampled, N as isUsableAsStorage, O as isUsableAsUniform, z as isUsableAsVertex } from './tgpuConstant-BAmV6caN.js';
3
3
  import 'tinyest';
4
4
 
5
+ /**
6
+ * The results of a WGSL resolution.
7
+ *
8
+ * @param code - The resolved code.
9
+ * @param usedBindGroupLayouts - List of used `tgpu.bindGroupLayout`s.
10
+ * @param catchall - Automatically constructed bind group for buffer usages and buffer shorthands, preceded by its index.
11
+ */
12
+ interface ResolutionResult {
13
+ code: string;
14
+ usedBindGroupLayouts: TgpuBindGroupLayout[];
15
+ catchall: [number, TgpuBindGroup] | undefined;
16
+ }
17
+
5
18
  interface TgpuResolveOptions {
6
19
  /**
7
20
  * Map of external names to their resolvable values.
@@ -18,11 +31,46 @@ interface TgpuResolveOptions {
18
31
  */
19
32
  names?: 'strict' | 'random' | undefined;
20
33
  /**
21
- * Optional JIT transpiler for resolving TGSL functions.
22
- * @experimental
34
+ * A function to configure the resolution context.
23
35
  */
24
- unstable_jitTranspiler?: JitTranspiler | undefined;
36
+ config?: ((cfg: Configurable) => Configurable) | undefined;
25
37
  }
38
+ /**
39
+ * Resolves a template with external values. Each external will get resolved to a code string and replaced in the template.
40
+ * Any dependencies of the externals will also be resolved and included in the output.
41
+ * @param options - The options for the resolution.
42
+ *
43
+ * @returns {ResolutionResult}
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const Gradient = d.struct({
48
+ * from: d.vec3f,
49
+ * to: d.vec3f,
50
+ * });
51
+ *
52
+ * const { code, usedBindGroupLayouts, catchall } = tgpu.resolveWithContext({
53
+ * template: `
54
+ * fn getGradientAngle(gradient: Gradient) -> f32 {
55
+ * return atan(gradient.to.y - gradient.from.y, gradient.to.x - gradient.from.x);
56
+ * }
57
+ * `,
58
+ * externals: {
59
+ * Gradient,
60
+ * },
61
+ * });
62
+ *
63
+ * console.log(code);
64
+ * // struct Gradient_0 {
65
+ * // from: vec3f,
66
+ * // to: vec3f,
67
+ * // }
68
+ * // fn getGradientAngle(gradient: Gradient_0) -> f32 {
69
+ * // return atan(gradient.to.y - gradient.from.y, gradient.to.x - gradient.from.x);
70
+ * // }
71
+ * ```
72
+ */
73
+ declare function resolveWithContext(options: TgpuResolveOptions): ResolutionResult;
26
74
  /**
27
75
  * Resolves a template with external values. Each external will get resolved to a code string and replaced in the template.
28
76
  * Any dependencies of the externals will also be resolved and included in the output.
@@ -60,6 +108,36 @@ interface TgpuResolveOptions {
60
108
  */
61
109
  declare function resolve(options: TgpuResolveOptions): string;
62
110
 
111
+ interface SimulationResult<T> {
112
+ value: T;
113
+ buffers: Map<TgpuBuffer<AnyData>, unknown>;
114
+ privateVars: Map<TgpuVar<'private', AnyData>, unknown>[][][];
115
+ workgroupVars: Map<TgpuVar<'workgroup', AnyData>, unknown>[][][];
116
+ }
117
+ /**
118
+ * Runs the provided callback in a simulated environment, giving
119
+ * it access to buffers and variables as if it were running on the GPU.
120
+ *
121
+ * The result of the simulation is returned, and does not affect the actual GPU state,
122
+ * nor does it carry over to other simulations.
123
+ *
124
+ * @param callback The callback to run in the simulated environment.
125
+ * @returns An object containing the result of the simulation, and
126
+ * the final state of the environment.
127
+ *
128
+ * @example
129
+ * const counter = tgpu.privateVar(d.u32);
130
+ *
131
+ * const result = tgpu.simulate(() => {
132
+ * counter.$ += 1;
133
+ * counter.$ += 2;
134
+ * return counter.$;
135
+ * });
136
+ *
137
+ * console.log(result.value); // 3
138
+ */
139
+ declare function simulate<T>(callback: () => T): SimulationResult<T>;
140
+
63
141
  /**
64
142
  * Options passed into {@link init}.
65
143
  */
@@ -70,7 +148,6 @@ type InitOptions = {
70
148
  } | undefined;
71
149
  /** @default 'random' */
72
150
  unstable_names?: 'random' | 'strict' | undefined;
73
- unstable_jitTranspiler?: JitTranspiler | undefined;
74
151
  };
75
152
  /**
76
153
  * Options passed into {@link initFromDevice}.
@@ -79,7 +156,6 @@ type InitFromDeviceOptions = {
79
156
  device: GPUDevice;
80
157
  /** @default 'random' */
81
158
  unstable_names?: 'random' | 'strict' | undefined;
82
- unstable_jitTranspiler?: JitTranspiler | undefined;
83
159
  };
84
160
  /**
85
161
  * Requests a new GPU device and creates a root around it.
@@ -111,7 +187,7 @@ declare function init(options?: InitOptions): Promise<TgpuRoot>;
111
187
  */
112
188
  declare function initFromDevice(options: InitFromDeviceOptions): TgpuRoot;
113
189
 
114
- declare function accessor<T extends AnyWgslData>(schema: T, defaultValue?: TgpuFn<[], T> | TgpuBufferUsage<T> | Infer<T>): TgpuAccessor<T>;
190
+ declare function accessor<T extends AnyWgslData>(schema: T, defaultValue?: TgpuFn<() => T> | TgpuBufferUsage<T> | Infer<T>): TgpuAccessor<T>;
115
191
 
116
192
  declare function derived<T>(compute: () => T): TgpuDerived<T>;
117
193
 
@@ -158,12 +234,18 @@ declare class MissingVertexBuffersError extends Error {
158
234
  */
159
235
 
160
236
  declare const tgpu: {
237
+ fn: typeof fn;
161
238
  bindGroupLayout: typeof bindGroupLayout;
162
239
  vertexLayout: typeof vertexLayout;
240
+ slot: typeof slot;
163
241
  init: typeof init;
164
242
  initFromDevice: typeof initFromDevice;
165
243
  resolve: typeof resolve;
244
+ resolveWithContext: typeof resolveWithContext;
166
245
  '~unstable': {
246
+ /**
247
+ * @deprecated This feature is now stable, use tgpu.fn.
248
+ */
167
249
  fn: typeof fn;
168
250
  fragmentFn: typeof fragmentFn;
169
251
  vertexFn: typeof vertexFn;
@@ -173,6 +255,9 @@ declare const tgpu: {
173
255
  */
174
256
  vertexLayout: typeof vertexLayout;
175
257
  derived: typeof derived;
258
+ /**
259
+ * @deprecated This feature is now stable, use tgpu.slot.
260
+ */
176
261
  slot: typeof slot;
177
262
  accessor: typeof accessor;
178
263
  privateVar: typeof privateVar;
@@ -181,7 +266,8 @@ declare const tgpu: {
181
266
  declare: typeof declare;
182
267
  sampler: typeof sampler;
183
268
  comparisonSampler: typeof comparisonSampler;
269
+ simulate: typeof simulate;
184
270
  };
185
271
  };
186
272
 
187
- export { type InitFromDeviceOptions, type InitOptions, MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, ResolutionError, TgpuAccessor, TgpuBindGroupLayout, TgpuBuffer, TgpuDerived, TgpuFn, TgpuRoot, TgpuSlot, TgpuVertexLayout, tgpu as default, tgpu };
273
+ export { Configurable, type InitFromDeviceOptions, type InitOptions, MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, ResolutionError, TgpuAccessor, TgpuBindGroup, TgpuBindGroupLayout, TgpuBuffer, TgpuDerived, TgpuFn, TgpuRoot, TgpuSlot, TgpuVar, TgpuVertexLayout, tgpu as default, tgpu };