typegpu 0.5.2 → 0.5.4

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 (45) hide show
  1. package/README.md +1 -1
  2. package/attributes-BdU8hyQq.d.cts +435 -0
  3. package/attributes-CAsvE5Z9.d.ts +435 -0
  4. package/chunk-5PJ3H5OR.js +2 -0
  5. package/chunk-5PJ3H5OR.js.map +1 -0
  6. package/chunk-7UUBX6MC.cjs +4 -0
  7. package/chunk-7UUBX6MC.cjs.map +1 -0
  8. package/chunk-AKBL6GDL.js +4 -0
  9. package/chunk-AKBL6GDL.js.map +1 -0
  10. package/chunk-URJCMUTT.cjs +2 -0
  11. package/chunk-URJCMUTT.cjs.map +1 -0
  12. package/data/index.cjs +1 -1
  13. package/data/index.cjs.map +1 -1
  14. package/data/index.d.cts +51 -4
  15. package/data/index.d.ts +51 -4
  16. package/data/index.js +1 -1
  17. package/index.cjs +17 -17
  18. package/index.cjs.map +1 -1
  19. package/index.d.cts +92 -53
  20. package/index.d.ts +92 -53
  21. package/index.js +17 -17
  22. package/index.js.map +1 -1
  23. package/package.json +2 -2
  24. package/std/index.cjs +1 -1
  25. package/std/index.cjs.map +1 -1
  26. package/std/index.d.cts +141 -33
  27. package/std/index.d.ts +141 -33
  28. package/std/index.js +1 -1
  29. package/std/index.js.map +1 -1
  30. package/{wgslTypes-VtSRoe90.d.ts → wgslTypes-Bh2dG5qv.d.cts} +213 -405
  31. package/{wgslTypes-VtSRoe90.d.cts → wgslTypes-Bh2dG5qv.d.ts} +213 -405
  32. package/attributes-B4JpvOTz.d.ts +0 -159
  33. package/attributes-DSOqT8yA.d.cts +0 -159
  34. package/chunk-3JTP2ATR.cjs +0 -2
  35. package/chunk-3JTP2ATR.cjs.map +0 -1
  36. package/chunk-3QXCKMEJ.cjs +0 -2
  37. package/chunk-3QXCKMEJ.cjs.map +0 -1
  38. package/chunk-DR55IHDD.js +0 -4
  39. package/chunk-DR55IHDD.js.map +0 -1
  40. package/chunk-KVOFUY5A.js +0 -2
  41. package/chunk-KVOFUY5A.js.map +0 -1
  42. package/chunk-QRLTUOBJ.cjs +0 -4
  43. package/chunk-QRLTUOBJ.cjs.map +0 -1
  44. package/chunk-VOFHV4Z6.js +0 -2
  45. package/chunk-VOFHV4Z6.js.map +0 -1
package/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { A as AnyWgslData, T as TgpuNamable, I as Infer, F as F32, a as F16, b as I32, U as U32, V as Vec2f, c as Vec3f, d as Vec4f, e as Vec2h, f as Vec3h, g as Vec4h, h as Vec2i, i as Vec3i, j as Vec4i, k as Vec2u, l as Vec3u, m as Vec4u, D as Decorated, n as AnyWgslStruct, B as BaseData, L as Location, W as WgslStruct, o as Default, p as UnionToIntersection, q as WgslArray, r as Disarray, s as Unstruct, t as VertexFormat, u as TgpuVertexAttrib, K as KindToDefaultFormatMap, v as KindToAcceptedAttribMap, w as AnyData, O as OmitProps, P as Prettify, M as Mutable, x as WgslTypeLiteral, y as InferPartial, z as MemIdentity, C as InferGPU, E as AbstractInt, G as AbstractFloat, H as AnyVecInstance, J as AnyMatInstance } from './wgslTypes-VtSRoe90.cjs';
2
- import { A as AnyAttribute, a as AnyComputeBuiltin, D as Decorate, I as IsBuiltin, H as HasCustomLocation, b as AnyFragmentInputBuiltin, c as AnyFragmentOutputBuiltin, O as OmitBuiltins } from './attributes-DSOqT8yA.cjs';
1
+ import { A as AnyWgslData, T as TgpuNamable, I as Infer, F as F32, a as F16, b as I32, U as U32, V as Vec2f, c as Vec3f, d as Vec4f, e as Vec2h, f as Vec3h, g as Vec4h, h as Vec2i, i as Vec3i, j as Vec4i, k as Vec2u, l as Vec3u, m as Vec4u, D as Decorated, n as AnyWgslStruct, $ as $repr, B as BaseData, L as Location, W as WgslStruct, o as Default, p as UnionToIntersection, q as WgslArray, O as OmitProps, P as Prettify, M as Mutable, r as WgslTypeLiteral, s as InferPartial, t as MemIdentity, u as InferGPU, v as AbstractInt, w as AbstractFloat, x as AnyVecInstance, y as AnyMatInstance } from './wgslTypes-Bh2dG5qv.cjs';
2
+ import { A as AnyAttribute, a as AnyComputeBuiltin, D as Decorate, I as IsBuiltin, H as HasCustomLocation, b as AnyFragmentInputBuiltin, c as AnyFragmentOutputBuiltin, O as OmitBuiltins, d as Disarray, U as Unstruct, V as VertexFormat, T as TgpuVertexAttrib, K as KindToDefaultFormatMap, e as KindToAcceptedAttribMap, f as AnyData } from './attributes-BdU8hyQq.cjs';
3
3
  import * as smol from 'tinyest';
4
- import { Block } from 'tinyest';
4
+ import { ArgNames, Block } from 'tinyest';
5
5
 
6
6
  declare const $internal: unique symbol;
7
7
 
@@ -36,7 +36,7 @@ declare function declare(declaration: string): TgpuDeclare;
36
36
  * Information extracted from transpiling a JS function.
37
37
  */
38
38
  type TranspilationResult = {
39
- argNames: string[];
39
+ argNames: smol.ArgNames;
40
40
  body: smol.Block;
41
41
  /**
42
42
  * All identifiers found in the function code that are not declared in the
@@ -63,24 +63,40 @@ type InferIO<T> = T extends {
63
63
  } : T;
64
64
 
65
65
  /**
66
- * Describes a compute entry function signature (its arguments and return type)
66
+ * Describes a compute entry function signature (its arguments, return type and workgroup size)
67
67
  */
68
- interface TgpuComputeFnShell<ComputeIn extends Record<string, AnyComputeBuiltin>> {
68
+ type TgpuComputeFnShellHeader<ComputeIn extends Record<string, AnyComputeBuiltin>> = {
69
69
  readonly argTypes: [AnyWgslStruct];
70
70
  readonly returnType: undefined;
71
71
  readonly workgroupSize: [number, number, number];
72
+ };
73
+ /**
74
+ * Describes a compute entry function signature (its arguments, return type and workgroup size).
75
+ * Allows creating tgpu compute functions by calling this shell
76
+ * and passing the implementation (as WGSL string or JS function) as the argument.
77
+ */
78
+ type TgpuComputeFnShell<ComputeIn extends Record<string, AnyComputeBuiltin>> = TgpuComputeFnShellHeader<ComputeIn> /**
79
+ * Creates a type-safe implementation of this signature
80
+ */ & ((implementation: (input: InferIO<ComputeIn>) => undefined) => TgpuComputeFn<ComputeIn>) &
81
+ /**
82
+ * @param implementation
83
+ * Raw WGSL function implementation with header and body
84
+ * without `fn` keyword and function name
85
+ * e.g. `"(x: f32) -> f32 { return x; }"`;
86
+ */
87
+ ((implementation: string) => TgpuComputeFn<ComputeIn>) & {
72
88
  /**
73
- * Creates a type-safe implementation of this signature
89
+ * @deprecated Invoke the shell as a function instead.
74
90
  */
75
- does(implementation: (input: InferIO<ComputeIn>) => undefined): TgpuComputeFn<ComputeIn>;
91
+ does: ((implementation: (input: InferIO<ComputeIn>) => undefined) => TgpuComputeFn<ComputeIn>) &
76
92
  /**
77
93
  * @param implementation
78
94
  * Raw WGSL function implementation with header and body
79
95
  * without `fn` keyword and function name
80
96
  * e.g. `"(x: f32) -> f32 { return x; }"`;
81
97
  */
82
- does(implementation: string): TgpuComputeFn<ComputeIn>;
83
- }
98
+ ((implementation: string) => TgpuComputeFn<ComputeIn>);
99
+ };
84
100
  interface TgpuComputeFn<ComputeIn extends Record<string, AnyComputeBuiltin> = Record<string, AnyComputeBuiltin>> extends TgpuNamable {
85
101
  readonly shell: TgpuComputeFnShell<ComputeIn>;
86
102
  $uses(dependencyMap: Record<string, unknown>): this;
@@ -132,7 +148,7 @@ declare class StrictNameRegistry implements NameRegistry {
132
148
 
133
149
  interface TgpuSlot<T> extends TgpuNamable, Labelled {
134
150
  readonly resourceType: 'slot';
135
- '~repr': Infer<T>;
151
+ [$repr]: Infer<T>;
136
152
  readonly defaultValue: T | undefined;
137
153
  /**
138
154
  * Used to determine if code generated using either value `a` or `b` in place
@@ -144,7 +160,7 @@ interface TgpuSlot<T> extends TgpuNamable, Labelled {
144
160
  interface TgpuDerived<T> {
145
161
  readonly resourceType: 'derived';
146
162
  readonly value: Infer<T>;
147
- '~repr': Infer<T>;
163
+ [$repr]: Infer<T>;
148
164
  readonly '~providing'?: Providing | undefined;
149
165
  with<TValue>(slot: TgpuSlot<TValue>, value: Eventual<TValue>): TgpuDerived<T>;
150
166
  /**
@@ -154,7 +170,7 @@ interface TgpuDerived<T> {
154
170
  }
155
171
  interface TgpuAccessor<T extends AnyWgslData = AnyWgslData> extends TgpuNamable, Labelled {
156
172
  readonly resourceType: 'accessor';
157
- '~repr': Infer<T>;
173
+ [$repr]: Infer<T>;
158
174
  readonly schema: T;
159
175
  readonly defaultValue: TgpuFn<[], T> | TgpuBufferUsage<T> | Infer<T> | undefined;
160
176
  readonly slot: TgpuSlot<TgpuFn<[], T> | TgpuBufferUsage<T> | Infer<T>>;
@@ -187,26 +203,42 @@ type IOLayoutToSchema<T extends IOLayout> = T extends BaseData ? Decorate<T, Loc
187
203
  type FragmentOutConstrained = Vec4f | Decorated<Vec4f, [Location<number>]> | AnyFragmentOutputBuiltin | IORecord<Vec4f | Decorated<Vec4f, [Location<number>]> | AnyFragmentOutputBuiltin>;
188
204
  type FragmentInConstrained = IORecord<BaseIOData | Decorated<BaseIOData, AnyAttribute<never>[]> | AnyFragmentInputBuiltin>;
189
205
  /**
190
- * Describes a fragment entry function signature (its arguments and return type)
206
+ * Describes a fragment entry function signature (its arguments, return type and targets)
191
207
  */
192
- interface TgpuFragmentFnShell<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained> {
208
+ type TgpuFragmentFnShellHeader<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained> = {
193
209
  readonly argTypes: [AnyWgslStruct];
194
210
  readonly targets: FragmentOut;
195
211
  readonly returnType: FragmentOut;
212
+ };
213
+ /**
214
+ * Describes a fragment entry function signature (its arguments, return type and targets).
215
+ * Allows creating tgpu fragment functions by calling this shell
216
+ * and passing the implementation (as WGSL string or JS function) as the argument.
217
+ */
218
+ type TgpuFragmentFnShell<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained> = TgpuFragmentFnShellHeader<FragmentIn, FragmentOut> /**
219
+ * Creates a type-safe implementation of this signature
220
+ */ & ((implementation: (input: InferIO<FragmentIn>) => InferIO<FragmentOut>) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>) &
221
+ /**
222
+ * @param implementation
223
+ * Raw WGSL function implementation with header and body
224
+ * without `fn` keyword and function name
225
+ * e.g. `"(x: f32) -> f32 { return x; }"`;
226
+ */
227
+ ((implementation: string) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>) & {
196
228
  /**
197
- * Creates a type-safe implementation of this signature
229
+ * @deprecated Invoke the shell as a function instead.
198
230
  */
199
- does(implementation: (input: InferIO<FragmentIn>) => InferIO<FragmentOut>): TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>;
231
+ does: ((implementation: (input: InferIO<FragmentIn>) => InferIO<FragmentOut>) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>) &
200
232
  /**
201
233
  * @param implementation
202
234
  * Raw WGSL function implementation with header and body
203
235
  * without `fn` keyword and function name
204
236
  * e.g. `"(x: f32) -> f32 { return x; }"`;
205
237
  */
206
- does(implementation: string): TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>;
207
- }
238
+ ((implementation: string) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>);
239
+ };
208
240
  interface TgpuFragmentFn<Varying extends FragmentInConstrained = FragmentInConstrained, Output extends FragmentOutConstrained = FragmentOutConstrained> extends TgpuNamable {
209
- readonly shell: TgpuFragmentFnShell<Varying, Output>;
241
+ readonly shell: TgpuFragmentFnShellHeader<Varying, Output>;
210
242
  readonly outputType: IOLayoutToSchema<Output>;
211
243
  $uses(dependencyMap: Record<string, unknown>): this;
212
244
  }
@@ -219,26 +251,26 @@ declare function fragmentFn<FragmentIn extends FragmentInConstrained, FragmentOu
219
251
  }): TgpuFragmentFnShell<FragmentIn, FragmentOut>;
220
252
 
221
253
  /**
222
- * Describes a vertex entry function signature (its arguments and return type)
254
+ * Describes a vertex entry function signature (its arguments, return type and attributes)
223
255
  */
224
- interface TgpuVertexFnShell<VertexIn extends IOLayout, VertexOut extends IOLayout> {
256
+ type TgpuVertexFnShellHeader<VertexIn extends IOLayout, VertexOut extends IOLayout> = {
225
257
  readonly argTypes: [AnyWgslStruct];
226
258
  readonly returnType: VertexOut;
227
259
  readonly attributes: [VertexIn];
260
+ };
261
+ /**
262
+ * Describes a vertex entry function signature (its arguments, return type and attributes).
263
+ * Allows creating tgpu vertex functions by calling this shell
264
+ * and passing the implementation (as WGSL string or JS function) as the argument.
265
+ */
266
+ type TgpuVertexFnShell<VertexIn extends IOLayout, VertexOut extends IOLayout> = TgpuVertexFnShellHeader<VertexIn, VertexOut> & ((implementation: (input: InferIO<VertexIn>) => InferIO<VertexOut>) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & ((implementation: string) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & {
228
267
  /**
229
- * Creates a type-safe implementation of this signature
230
- */
231
- does(implementation: (input: InferIO<VertexIn>) => InferIO<VertexOut>): TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>;
232
- /**
233
- * @param implementation
234
- * Raw WGSL function implementation with header and body
235
- * without `fn` keyword and function name
236
- * e.g. `"(x: f32) -> f32 { return x; }"`;
268
+ * @deprecated Invoke the shell as a function instead.
237
269
  */
238
- does(implementation: string): TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>;
239
- }
270
+ does: ((implementation: (input: InferIO<VertexIn>) => InferIO<VertexOut>) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & ((implementation: string) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>);
271
+ };
240
272
  interface TgpuVertexFn<VertexIn extends IOLayout = IOLayout, VertexOut extends IOLayout = IOLayout> extends TgpuNamable {
241
- readonly shell: TgpuVertexFnShell<VertexIn, VertexOut>;
273
+ readonly shell: TgpuVertexFnShellHeader<VertexIn, VertexOut>;
242
274
  readonly outputType: IOLayoutToSchema<VertexOut>;
243
275
  readonly inputType: IOLayoutToSchema<VertexIn>;
244
276
  $uses(dependencyMap: Record<string, unknown>): this;
@@ -1126,6 +1158,12 @@ interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | n
1126
1158
  readonly bound: {
1127
1159
  [K in keyof Entries]: BindLayoutEntry<Entries[K]>;
1128
1160
  };
1161
+ readonly value: {
1162
+ [K in keyof Entries]: InferLayoutEntry<Entries[K]>;
1163
+ };
1164
+ readonly $: {
1165
+ [K in keyof Entries]: InferLayoutEntry<Entries[K]>;
1166
+ };
1129
1167
  /**
1130
1168
  * An explicit numeric index assigned to this bind group layout. If undefined, a unique
1131
1169
  * index is assigned automatically during resolution. This can be changed with the
@@ -1177,7 +1215,8 @@ type GetStorageTextureRestriction<T extends TgpuLayoutStorageTexture> = Default<
1177
1215
  dimension: Dimension;
1178
1216
  } : never;
1179
1217
  type LayoutEntryToInput<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? (TgpuBuffer<UnwrapRuntimeConstructor<T['uniform']>> & UniformFlag) | GPUBuffer : T extends TgpuLayoutStorage ? (TgpuBuffer<UnwrapRuntimeConstructor<T['storage']>> & StorageFlag) | GPUBuffer : T extends TgpuLayoutSampler ? TgpuSampler | GPUSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler | GPUSampler : T extends TgpuLayoutTexture ? GPUTextureView | (Sampled & TgpuTexture<Prettify<TextureProps & GetTextureRestriction<T>>>) | TgpuSampledTexture<Default<T['viewDimension'], '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? GPUTextureView | (StorageFlag & TgpuTexture<Prettify<TextureProps & GetStorageTextureRestriction<T>>>) | StorageTextureUsageForEntry<T> : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
1180
- type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform<UnwrapRuntimeConstructor<T['uniform']>> : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> : T extends TgpuLayoutSampler ? TgpuSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler : T extends TgpuLayoutTexture ? TgpuSampledTexture<Default<GetDimension<T['viewDimension']>, '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
1218
+ type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform<T['uniform']> : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> : T extends TgpuLayoutSampler ? TgpuSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler : T extends TgpuLayoutTexture ? TgpuSampledTexture<Default<GetDimension<T['viewDimension']>, '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
1219
+ type InferLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? Infer<T['uniform']> : T extends TgpuLayoutStorage ? Infer<UnwrapRuntimeConstructor<T['storage']>> : T extends TgpuLayoutSampler ? TgpuSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler : T extends TgpuLayoutTexture ? TgpuSampledTexture<Default<GetDimension<T['viewDimension']>, '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
1181
1220
  type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
1182
1221
  readonly resourceType: 'bind-group';
1183
1222
  readonly layout: TgpuBindGroupLayout<Entries>;
@@ -1188,7 +1227,7 @@ declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry
1188
1227
  interface TgpuBufferUsage<TData extends BaseData = BaseData, TUsage extends BindableBufferUsage = BindableBufferUsage> {
1189
1228
  readonly resourceType: 'buffer-usage';
1190
1229
  readonly usage: TUsage;
1191
- readonly '~repr': Infer<TData>;
1230
+ readonly [$repr]: Infer<TData>;
1192
1231
  value: InferGPU<TData>;
1193
1232
  readonly [$internal]: {
1194
1233
  readonly dataType: TData;
@@ -1315,7 +1354,7 @@ interface ResolutionCtx {
1315
1354
  resolve(item: unknown): string;
1316
1355
  resolveValue<T extends BaseData>(value: Infer<T>, schema: T): string;
1317
1356
  transpileFn(fn: string): {
1318
- argNames: string[];
1357
+ argNames: ArgNames;
1319
1358
  body: Block;
1320
1359
  externalNames: string[];
1321
1360
  };
@@ -1344,36 +1383,36 @@ type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
1344
1383
  /**
1345
1384
  * Describes a function signature (its arguments and return type)
1346
1385
  */
1347
- interface TgpuFnShell<Args extends AnyWgslData[] = AnyWgslData[], Return extends AnyWgslData | undefined = AnyWgslData | undefined> {
1386
+ type TgpuFnShellHeader<Args extends AnyWgslData[] | Record<string, AnyWgslData>, Return extends AnyWgslData | undefined = AnyWgslData | undefined> = {
1348
1387
  readonly argTypes: Args;
1349
1388
  readonly returnType: Return | undefined;
1389
+ };
1390
+ /**
1391
+ * Describes a function signature (its arguments and return type).
1392
+ * Allows creating tgpu functions by calling this shell
1393
+ * and passing the implementation (as WGSL string or JS function) as the argument.
1394
+ */
1395
+ type TgpuFnShell<Args extends AnyWgslData[] | Record<string, AnyWgslData>, Return extends AnyWgslData | undefined = AnyWgslData | undefined> = TgpuFnShellHeader<Args, Return> & ((implementation: (...args: Args extends AnyWgslData[] ? InferArgs<Args> : [InferIO<Args>]) => InferReturn<Return>) => TgpuFn<Args, Return>) & ((implementation: string) => TgpuFn<Args, Return>) & {
1350
1396
  /**
1351
- * Creates a type-safe implementation of this signature
1352
- */
1353
- does(implementation: (...args: InferArgs<Args>) => InferReturn<Return>): TgpuFn<Args, Return>;
1354
- /**
1355
- * @param implementation
1356
- * Raw WGSL function implementation with header and body
1357
- * without `fn` keyword and function name
1358
- * e.g. `"(x: f32) -> f32 { return x; }"`;
1397
+ * @deprecated Invoke the shell as a function instead.
1359
1398
  */
1360
- does(implementation: string): TgpuFn<Args, Return>;
1361
- }
1362
- interface TgpuFnBase<Args extends AnyWgslData[], Return extends AnyWgslData | undefined = undefined> extends TgpuNamable, Labelled {
1399
+ does: ((implementation: (...args: Args extends AnyWgslData[] ? InferArgs<Args> : [InferIO<Args>]) => InferReturn<Return>) => TgpuFn<Args, Return>) & ((implementation: string) => TgpuFn<Args, Return>);
1400
+ };
1401
+ interface TgpuFnBase<Args extends AnyWgslData[] | Record<string, AnyWgslData>, Return extends AnyWgslData | undefined = undefined> extends TgpuNamable, Labelled {
1363
1402
  readonly resourceType: 'function';
1364
- readonly shell: TgpuFnShell<Args, Return>;
1403
+ readonly shell: TgpuFnShellHeader<Args, Return>;
1365
1404
  readonly '~providing'?: Providing | undefined;
1366
1405
  $uses(dependencyMap: Record<string, unknown>): this;
1367
1406
  with<T>(slot: TgpuSlot<T>, value: Eventual<T>): TgpuFn<Args, Return>;
1368
1407
  with<T extends AnyWgslData>(accessor: TgpuAccessor<T>, value: TgpuFn<[], T> | TgpuBufferUsage<T> | Infer<T>): TgpuFn<Args, Return>;
1369
1408
  }
1370
- type TgpuFn<Args extends AnyWgslData[] = AnyWgslData[], Return extends AnyWgslData | undefined = AnyWgslData | undefined> = TgpuFnBase<Args, Return> & ((...args: InferArgs<Args>) => InferReturn<Return>) & {
1409
+ type TgpuFn<Args extends AnyWgslData[] | Record<string, AnyWgslData> = AnyWgslData[], Return extends AnyWgslData | undefined = AnyWgslData | undefined> = TgpuFnBase<Args, Return> & ((...args: Args extends AnyWgslData[] ? InferArgs<Args> : Args extends Record<string, never> ? [] : [InferIO<Args>]) => InferReturn<Return>) & {
1371
1410
  readonly [$internal]: {
1372
- implementation: Implementation<InferArgs<Args>, InferReturn<Return>>;
1411
+ implementation: Implementation<Args extends AnyWgslData[] ? InferArgs<Args> : Args extends Record<string, never> ? [] : [InferIO<Args>], InferReturn<Return>>;
1373
1412
  };
1374
1413
  };
1375
- declare function fn<Args extends AnyWgslData[] | []>(argTypes: Args, returnType?: undefined): TgpuFnShell<Args, undefined>;
1376
- declare function fn<Args extends AnyWgslData[] | [], Return extends AnyWgslData>(argTypes: Args, returnType: Return): TgpuFnShell<Args, Return>;
1414
+ declare function fn<Args extends AnyWgslData[] | Record<string, AnyWgslData> | []>(argTypes: Args, returnType?: undefined): TgpuFnShell<Args, undefined>;
1415
+ declare function fn<Args extends AnyWgslData[] | Record<string, AnyWgslData> | [], Return extends AnyWgslData>(argTypes: Args, returnType: Return): TgpuFnShell<Args, Return>;
1377
1416
  declare function isTgpuFn<Args extends AnyWgslData[], Return extends AnyWgslData | undefined = undefined>(value: unknown | TgpuFn<Args, Return>): value is TgpuFn<Args, Return>;
1378
1417
 
1379
1418
  interface TgpuResolveOptions {
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { A as AnyWgslData, T as TgpuNamable, I as Infer, F as F32, a as F16, b as I32, U as U32, V as Vec2f, c as Vec3f, d as Vec4f, e as Vec2h, f as Vec3h, g as Vec4h, h as Vec2i, i as Vec3i, j as Vec4i, k as Vec2u, l as Vec3u, m as Vec4u, D as Decorated, n as AnyWgslStruct, B as BaseData, L as Location, W as WgslStruct, o as Default, p as UnionToIntersection, q as WgslArray, r as Disarray, s as Unstruct, t as VertexFormat, u as TgpuVertexAttrib, K as KindToDefaultFormatMap, v as KindToAcceptedAttribMap, w as AnyData, O as OmitProps, P as Prettify, M as Mutable, x as WgslTypeLiteral, y as InferPartial, z as MemIdentity, C as InferGPU, E as AbstractInt, G as AbstractFloat, H as AnyVecInstance, J as AnyMatInstance } from './wgslTypes-VtSRoe90.js';
2
- import { A as AnyAttribute, a as AnyComputeBuiltin, D as Decorate, I as IsBuiltin, H as HasCustomLocation, b as AnyFragmentInputBuiltin, c as AnyFragmentOutputBuiltin, O as OmitBuiltins } from './attributes-B4JpvOTz.js';
1
+ import { A as AnyWgslData, T as TgpuNamable, I as Infer, F as F32, a as F16, b as I32, U as U32, V as Vec2f, c as Vec3f, d as Vec4f, e as Vec2h, f as Vec3h, g as Vec4h, h as Vec2i, i as Vec3i, j as Vec4i, k as Vec2u, l as Vec3u, m as Vec4u, D as Decorated, n as AnyWgslStruct, $ as $repr, B as BaseData, L as Location, W as WgslStruct, o as Default, p as UnionToIntersection, q as WgslArray, O as OmitProps, P as Prettify, M as Mutable, r as WgslTypeLiteral, s as InferPartial, t as MemIdentity, u as InferGPU, v as AbstractInt, w as AbstractFloat, x as AnyVecInstance, y as AnyMatInstance } from './wgslTypes-Bh2dG5qv.js';
2
+ import { A as AnyAttribute, a as AnyComputeBuiltin, D as Decorate, I as IsBuiltin, H as HasCustomLocation, b as AnyFragmentInputBuiltin, c as AnyFragmentOutputBuiltin, O as OmitBuiltins, d as Disarray, U as Unstruct, V as VertexFormat, T as TgpuVertexAttrib, K as KindToDefaultFormatMap, e as KindToAcceptedAttribMap, f as AnyData } from './attributes-CAsvE5Z9.js';
3
3
  import * as smol from 'tinyest';
4
- import { Block } from 'tinyest';
4
+ import { ArgNames, Block } from 'tinyest';
5
5
 
6
6
  declare const $internal: unique symbol;
7
7
 
@@ -36,7 +36,7 @@ declare function declare(declaration: string): TgpuDeclare;
36
36
  * Information extracted from transpiling a JS function.
37
37
  */
38
38
  type TranspilationResult = {
39
- argNames: string[];
39
+ argNames: smol.ArgNames;
40
40
  body: smol.Block;
41
41
  /**
42
42
  * All identifiers found in the function code that are not declared in the
@@ -63,24 +63,40 @@ type InferIO<T> = T extends {
63
63
  } : T;
64
64
 
65
65
  /**
66
- * Describes a compute entry function signature (its arguments and return type)
66
+ * Describes a compute entry function signature (its arguments, return type and workgroup size)
67
67
  */
68
- interface TgpuComputeFnShell<ComputeIn extends Record<string, AnyComputeBuiltin>> {
68
+ type TgpuComputeFnShellHeader<ComputeIn extends Record<string, AnyComputeBuiltin>> = {
69
69
  readonly argTypes: [AnyWgslStruct];
70
70
  readonly returnType: undefined;
71
71
  readonly workgroupSize: [number, number, number];
72
+ };
73
+ /**
74
+ * Describes a compute entry function signature (its arguments, return type and workgroup size).
75
+ * Allows creating tgpu compute functions by calling this shell
76
+ * and passing the implementation (as WGSL string or JS function) as the argument.
77
+ */
78
+ type TgpuComputeFnShell<ComputeIn extends Record<string, AnyComputeBuiltin>> = TgpuComputeFnShellHeader<ComputeIn> /**
79
+ * Creates a type-safe implementation of this signature
80
+ */ & ((implementation: (input: InferIO<ComputeIn>) => undefined) => TgpuComputeFn<ComputeIn>) &
81
+ /**
82
+ * @param implementation
83
+ * Raw WGSL function implementation with header and body
84
+ * without `fn` keyword and function name
85
+ * e.g. `"(x: f32) -> f32 { return x; }"`;
86
+ */
87
+ ((implementation: string) => TgpuComputeFn<ComputeIn>) & {
72
88
  /**
73
- * Creates a type-safe implementation of this signature
89
+ * @deprecated Invoke the shell as a function instead.
74
90
  */
75
- does(implementation: (input: InferIO<ComputeIn>) => undefined): TgpuComputeFn<ComputeIn>;
91
+ does: ((implementation: (input: InferIO<ComputeIn>) => undefined) => TgpuComputeFn<ComputeIn>) &
76
92
  /**
77
93
  * @param implementation
78
94
  * Raw WGSL function implementation with header and body
79
95
  * without `fn` keyword and function name
80
96
  * e.g. `"(x: f32) -> f32 { return x; }"`;
81
97
  */
82
- does(implementation: string): TgpuComputeFn<ComputeIn>;
83
- }
98
+ ((implementation: string) => TgpuComputeFn<ComputeIn>);
99
+ };
84
100
  interface TgpuComputeFn<ComputeIn extends Record<string, AnyComputeBuiltin> = Record<string, AnyComputeBuiltin>> extends TgpuNamable {
85
101
  readonly shell: TgpuComputeFnShell<ComputeIn>;
86
102
  $uses(dependencyMap: Record<string, unknown>): this;
@@ -132,7 +148,7 @@ declare class StrictNameRegistry implements NameRegistry {
132
148
 
133
149
  interface TgpuSlot<T> extends TgpuNamable, Labelled {
134
150
  readonly resourceType: 'slot';
135
- '~repr': Infer<T>;
151
+ [$repr]: Infer<T>;
136
152
  readonly defaultValue: T | undefined;
137
153
  /**
138
154
  * Used to determine if code generated using either value `a` or `b` in place
@@ -144,7 +160,7 @@ interface TgpuSlot<T> extends TgpuNamable, Labelled {
144
160
  interface TgpuDerived<T> {
145
161
  readonly resourceType: 'derived';
146
162
  readonly value: Infer<T>;
147
- '~repr': Infer<T>;
163
+ [$repr]: Infer<T>;
148
164
  readonly '~providing'?: Providing | undefined;
149
165
  with<TValue>(slot: TgpuSlot<TValue>, value: Eventual<TValue>): TgpuDerived<T>;
150
166
  /**
@@ -154,7 +170,7 @@ interface TgpuDerived<T> {
154
170
  }
155
171
  interface TgpuAccessor<T extends AnyWgslData = AnyWgslData> extends TgpuNamable, Labelled {
156
172
  readonly resourceType: 'accessor';
157
- '~repr': Infer<T>;
173
+ [$repr]: Infer<T>;
158
174
  readonly schema: T;
159
175
  readonly defaultValue: TgpuFn<[], T> | TgpuBufferUsage<T> | Infer<T> | undefined;
160
176
  readonly slot: TgpuSlot<TgpuFn<[], T> | TgpuBufferUsage<T> | Infer<T>>;
@@ -187,26 +203,42 @@ type IOLayoutToSchema<T extends IOLayout> = T extends BaseData ? Decorate<T, Loc
187
203
  type FragmentOutConstrained = Vec4f | Decorated<Vec4f, [Location<number>]> | AnyFragmentOutputBuiltin | IORecord<Vec4f | Decorated<Vec4f, [Location<number>]> | AnyFragmentOutputBuiltin>;
188
204
  type FragmentInConstrained = IORecord<BaseIOData | Decorated<BaseIOData, AnyAttribute<never>[]> | AnyFragmentInputBuiltin>;
189
205
  /**
190
- * Describes a fragment entry function signature (its arguments and return type)
206
+ * Describes a fragment entry function signature (its arguments, return type and targets)
191
207
  */
192
- interface TgpuFragmentFnShell<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained> {
208
+ type TgpuFragmentFnShellHeader<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained> = {
193
209
  readonly argTypes: [AnyWgslStruct];
194
210
  readonly targets: FragmentOut;
195
211
  readonly returnType: FragmentOut;
212
+ };
213
+ /**
214
+ * Describes a fragment entry function signature (its arguments, return type and targets).
215
+ * Allows creating tgpu fragment functions by calling this shell
216
+ * and passing the implementation (as WGSL string or JS function) as the argument.
217
+ */
218
+ type TgpuFragmentFnShell<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained> = TgpuFragmentFnShellHeader<FragmentIn, FragmentOut> /**
219
+ * Creates a type-safe implementation of this signature
220
+ */ & ((implementation: (input: InferIO<FragmentIn>) => InferIO<FragmentOut>) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>) &
221
+ /**
222
+ * @param implementation
223
+ * Raw WGSL function implementation with header and body
224
+ * without `fn` keyword and function name
225
+ * e.g. `"(x: f32) -> f32 { return x; }"`;
226
+ */
227
+ ((implementation: string) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>) & {
196
228
  /**
197
- * Creates a type-safe implementation of this signature
229
+ * @deprecated Invoke the shell as a function instead.
198
230
  */
199
- does(implementation: (input: InferIO<FragmentIn>) => InferIO<FragmentOut>): TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>;
231
+ does: ((implementation: (input: InferIO<FragmentIn>) => InferIO<FragmentOut>) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>) &
200
232
  /**
201
233
  * @param implementation
202
234
  * Raw WGSL function implementation with header and body
203
235
  * without `fn` keyword and function name
204
236
  * e.g. `"(x: f32) -> f32 { return x; }"`;
205
237
  */
206
- does(implementation: string): TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>;
207
- }
238
+ ((implementation: string) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>);
239
+ };
208
240
  interface TgpuFragmentFn<Varying extends FragmentInConstrained = FragmentInConstrained, Output extends FragmentOutConstrained = FragmentOutConstrained> extends TgpuNamable {
209
- readonly shell: TgpuFragmentFnShell<Varying, Output>;
241
+ readonly shell: TgpuFragmentFnShellHeader<Varying, Output>;
210
242
  readonly outputType: IOLayoutToSchema<Output>;
211
243
  $uses(dependencyMap: Record<string, unknown>): this;
212
244
  }
@@ -219,26 +251,26 @@ declare function fragmentFn<FragmentIn extends FragmentInConstrained, FragmentOu
219
251
  }): TgpuFragmentFnShell<FragmentIn, FragmentOut>;
220
252
 
221
253
  /**
222
- * Describes a vertex entry function signature (its arguments and return type)
254
+ * Describes a vertex entry function signature (its arguments, return type and attributes)
223
255
  */
224
- interface TgpuVertexFnShell<VertexIn extends IOLayout, VertexOut extends IOLayout> {
256
+ type TgpuVertexFnShellHeader<VertexIn extends IOLayout, VertexOut extends IOLayout> = {
225
257
  readonly argTypes: [AnyWgslStruct];
226
258
  readonly returnType: VertexOut;
227
259
  readonly attributes: [VertexIn];
260
+ };
261
+ /**
262
+ * Describes a vertex entry function signature (its arguments, return type and attributes).
263
+ * Allows creating tgpu vertex functions by calling this shell
264
+ * and passing the implementation (as WGSL string or JS function) as the argument.
265
+ */
266
+ type TgpuVertexFnShell<VertexIn extends IOLayout, VertexOut extends IOLayout> = TgpuVertexFnShellHeader<VertexIn, VertexOut> & ((implementation: (input: InferIO<VertexIn>) => InferIO<VertexOut>) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & ((implementation: string) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & {
228
267
  /**
229
- * Creates a type-safe implementation of this signature
230
- */
231
- does(implementation: (input: InferIO<VertexIn>) => InferIO<VertexOut>): TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>;
232
- /**
233
- * @param implementation
234
- * Raw WGSL function implementation with header and body
235
- * without `fn` keyword and function name
236
- * e.g. `"(x: f32) -> f32 { return x; }"`;
268
+ * @deprecated Invoke the shell as a function instead.
237
269
  */
238
- does(implementation: string): TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>;
239
- }
270
+ does: ((implementation: (input: InferIO<VertexIn>) => InferIO<VertexOut>) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & ((implementation: string) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>);
271
+ };
240
272
  interface TgpuVertexFn<VertexIn extends IOLayout = IOLayout, VertexOut extends IOLayout = IOLayout> extends TgpuNamable {
241
- readonly shell: TgpuVertexFnShell<VertexIn, VertexOut>;
273
+ readonly shell: TgpuVertexFnShellHeader<VertexIn, VertexOut>;
242
274
  readonly outputType: IOLayoutToSchema<VertexOut>;
243
275
  readonly inputType: IOLayoutToSchema<VertexIn>;
244
276
  $uses(dependencyMap: Record<string, unknown>): this;
@@ -1126,6 +1158,12 @@ interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | n
1126
1158
  readonly bound: {
1127
1159
  [K in keyof Entries]: BindLayoutEntry<Entries[K]>;
1128
1160
  };
1161
+ readonly value: {
1162
+ [K in keyof Entries]: InferLayoutEntry<Entries[K]>;
1163
+ };
1164
+ readonly $: {
1165
+ [K in keyof Entries]: InferLayoutEntry<Entries[K]>;
1166
+ };
1129
1167
  /**
1130
1168
  * An explicit numeric index assigned to this bind group layout. If undefined, a unique
1131
1169
  * index is assigned automatically during resolution. This can be changed with the
@@ -1177,7 +1215,8 @@ type GetStorageTextureRestriction<T extends TgpuLayoutStorageTexture> = Default<
1177
1215
  dimension: Dimension;
1178
1216
  } : never;
1179
1217
  type LayoutEntryToInput<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? (TgpuBuffer<UnwrapRuntimeConstructor<T['uniform']>> & UniformFlag) | GPUBuffer : T extends TgpuLayoutStorage ? (TgpuBuffer<UnwrapRuntimeConstructor<T['storage']>> & StorageFlag) | GPUBuffer : T extends TgpuLayoutSampler ? TgpuSampler | GPUSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler | GPUSampler : T extends TgpuLayoutTexture ? GPUTextureView | (Sampled & TgpuTexture<Prettify<TextureProps & GetTextureRestriction<T>>>) | TgpuSampledTexture<Default<T['viewDimension'], '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? GPUTextureView | (StorageFlag & TgpuTexture<Prettify<TextureProps & GetStorageTextureRestriction<T>>>) | StorageTextureUsageForEntry<T> : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
1180
- type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform<UnwrapRuntimeConstructor<T['uniform']>> : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> : T extends TgpuLayoutSampler ? TgpuSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler : T extends TgpuLayoutTexture ? TgpuSampledTexture<Default<GetDimension<T['viewDimension']>, '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
1218
+ type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform<T['uniform']> : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> : T extends TgpuLayoutSampler ? TgpuSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler : T extends TgpuLayoutTexture ? TgpuSampledTexture<Default<GetDimension<T['viewDimension']>, '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
1219
+ type InferLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? Infer<T['uniform']> : T extends TgpuLayoutStorage ? Infer<UnwrapRuntimeConstructor<T['storage']>> : T extends TgpuLayoutSampler ? TgpuSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler : T extends TgpuLayoutTexture ? TgpuSampledTexture<Default<GetDimension<T['viewDimension']>, '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
1181
1220
  type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
1182
1221
  readonly resourceType: 'bind-group';
1183
1222
  readonly layout: TgpuBindGroupLayout<Entries>;
@@ -1188,7 +1227,7 @@ declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry
1188
1227
  interface TgpuBufferUsage<TData extends BaseData = BaseData, TUsage extends BindableBufferUsage = BindableBufferUsage> {
1189
1228
  readonly resourceType: 'buffer-usage';
1190
1229
  readonly usage: TUsage;
1191
- readonly '~repr': Infer<TData>;
1230
+ readonly [$repr]: Infer<TData>;
1192
1231
  value: InferGPU<TData>;
1193
1232
  readonly [$internal]: {
1194
1233
  readonly dataType: TData;
@@ -1315,7 +1354,7 @@ interface ResolutionCtx {
1315
1354
  resolve(item: unknown): string;
1316
1355
  resolveValue<T extends BaseData>(value: Infer<T>, schema: T): string;
1317
1356
  transpileFn(fn: string): {
1318
- argNames: string[];
1357
+ argNames: ArgNames;
1319
1358
  body: Block;
1320
1359
  externalNames: string[];
1321
1360
  };
@@ -1344,36 +1383,36 @@ type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
1344
1383
  /**
1345
1384
  * Describes a function signature (its arguments and return type)
1346
1385
  */
1347
- interface TgpuFnShell<Args extends AnyWgslData[] = AnyWgslData[], Return extends AnyWgslData | undefined = AnyWgslData | undefined> {
1386
+ type TgpuFnShellHeader<Args extends AnyWgslData[] | Record<string, AnyWgslData>, Return extends AnyWgslData | undefined = AnyWgslData | undefined> = {
1348
1387
  readonly argTypes: Args;
1349
1388
  readonly returnType: Return | undefined;
1389
+ };
1390
+ /**
1391
+ * Describes a function signature (its arguments and return type).
1392
+ * Allows creating tgpu functions by calling this shell
1393
+ * and passing the implementation (as WGSL string or JS function) as the argument.
1394
+ */
1395
+ type TgpuFnShell<Args extends AnyWgslData[] | Record<string, AnyWgslData>, Return extends AnyWgslData | undefined = AnyWgslData | undefined> = TgpuFnShellHeader<Args, Return> & ((implementation: (...args: Args extends AnyWgslData[] ? InferArgs<Args> : [InferIO<Args>]) => InferReturn<Return>) => TgpuFn<Args, Return>) & ((implementation: string) => TgpuFn<Args, Return>) & {
1350
1396
  /**
1351
- * Creates a type-safe implementation of this signature
1352
- */
1353
- does(implementation: (...args: InferArgs<Args>) => InferReturn<Return>): TgpuFn<Args, Return>;
1354
- /**
1355
- * @param implementation
1356
- * Raw WGSL function implementation with header and body
1357
- * without `fn` keyword and function name
1358
- * e.g. `"(x: f32) -> f32 { return x; }"`;
1397
+ * @deprecated Invoke the shell as a function instead.
1359
1398
  */
1360
- does(implementation: string): TgpuFn<Args, Return>;
1361
- }
1362
- interface TgpuFnBase<Args extends AnyWgslData[], Return extends AnyWgslData | undefined = undefined> extends TgpuNamable, Labelled {
1399
+ does: ((implementation: (...args: Args extends AnyWgslData[] ? InferArgs<Args> : [InferIO<Args>]) => InferReturn<Return>) => TgpuFn<Args, Return>) & ((implementation: string) => TgpuFn<Args, Return>);
1400
+ };
1401
+ interface TgpuFnBase<Args extends AnyWgslData[] | Record<string, AnyWgslData>, Return extends AnyWgslData | undefined = undefined> extends TgpuNamable, Labelled {
1363
1402
  readonly resourceType: 'function';
1364
- readonly shell: TgpuFnShell<Args, Return>;
1403
+ readonly shell: TgpuFnShellHeader<Args, Return>;
1365
1404
  readonly '~providing'?: Providing | undefined;
1366
1405
  $uses(dependencyMap: Record<string, unknown>): this;
1367
1406
  with<T>(slot: TgpuSlot<T>, value: Eventual<T>): TgpuFn<Args, Return>;
1368
1407
  with<T extends AnyWgslData>(accessor: TgpuAccessor<T>, value: TgpuFn<[], T> | TgpuBufferUsage<T> | Infer<T>): TgpuFn<Args, Return>;
1369
1408
  }
1370
- type TgpuFn<Args extends AnyWgslData[] = AnyWgslData[], Return extends AnyWgslData | undefined = AnyWgslData | undefined> = TgpuFnBase<Args, Return> & ((...args: InferArgs<Args>) => InferReturn<Return>) & {
1409
+ type TgpuFn<Args extends AnyWgslData[] | Record<string, AnyWgslData> = AnyWgslData[], Return extends AnyWgslData | undefined = AnyWgslData | undefined> = TgpuFnBase<Args, Return> & ((...args: Args extends AnyWgslData[] ? InferArgs<Args> : Args extends Record<string, never> ? [] : [InferIO<Args>]) => InferReturn<Return>) & {
1371
1410
  readonly [$internal]: {
1372
- implementation: Implementation<InferArgs<Args>, InferReturn<Return>>;
1411
+ implementation: Implementation<Args extends AnyWgslData[] ? InferArgs<Args> : Args extends Record<string, never> ? [] : [InferIO<Args>], InferReturn<Return>>;
1373
1412
  };
1374
1413
  };
1375
- declare function fn<Args extends AnyWgslData[] | []>(argTypes: Args, returnType?: undefined): TgpuFnShell<Args, undefined>;
1376
- declare function fn<Args extends AnyWgslData[] | [], Return extends AnyWgslData>(argTypes: Args, returnType: Return): TgpuFnShell<Args, Return>;
1414
+ declare function fn<Args extends AnyWgslData[] | Record<string, AnyWgslData> | []>(argTypes: Args, returnType?: undefined): TgpuFnShell<Args, undefined>;
1415
+ declare function fn<Args extends AnyWgslData[] | Record<string, AnyWgslData> | [], Return extends AnyWgslData>(argTypes: Args, returnType: Return): TgpuFnShell<Args, Return>;
1377
1416
  declare function isTgpuFn<Args extends AnyWgslData[], Return extends AnyWgslData | undefined = undefined>(value: unknown | TgpuFn<Args, Return>): value is TgpuFn<Args, Return>;
1378
1417
 
1379
1418
  interface TgpuResolveOptions {