typegpu 0.11.1 → 0.11.3

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 (216) hide show
  1. package/_virtual/{_rolldown/runtime.js → rolldown_runtime.js} +4 -4
  2. package/builtin.js +3 -1
  3. package/common/fullScreenTriangle.d.ts +6 -1
  4. package/common/fullScreenTriangle.js +3 -1
  5. package/common/index.js +5 -3
  6. package/common/writeSoA.js +3 -1
  7. package/core/buffer/buffer.d.ts +3 -0
  8. package/core/buffer/buffer.js +5 -3
  9. package/core/buffer/bufferShorthand.d.ts +2 -0
  10. package/core/buffer/bufferShorthand.js +3 -1
  11. package/core/buffer/bufferUsage.d.ts +2 -0
  12. package/core/buffer/bufferUsage.js +3 -1
  13. package/core/constant/tgpuConstant.d.ts +2 -1
  14. package/core/constant/tgpuConstant.js +3 -1
  15. package/core/declare/tgpuDeclare.js +3 -1
  16. package/core/function/autoIO.d.ts +3 -0
  17. package/core/function/autoIO.js +5 -3
  18. package/core/function/comptime.js +3 -1
  19. package/core/function/createCallableSchema.js +3 -1
  20. package/core/function/dualImpl.js +3 -1
  21. package/core/function/entryInputRouter.js +13 -17
  22. package/core/function/extractArgs.js +2 -1
  23. package/core/function/fnCore.js +17 -11
  24. package/core/function/fnTypes.d.ts +2 -0
  25. package/core/function/ioSchema.d.ts +1 -0
  26. package/core/function/ioSchema.js +3 -1
  27. package/core/function/shelllessImpl.d.ts +1 -0
  28. package/core/function/shelllessImpl.js +4 -2
  29. package/core/function/templateUtils.js +2 -1
  30. package/core/function/tgpuComputeFn.d.ts +1 -0
  31. package/core/function/tgpuComputeFn.js +4 -2
  32. package/core/function/tgpuFn.d.ts +1 -0
  33. package/core/function/tgpuFn.js +17 -15
  34. package/core/function/tgpuFragmentFn.js +4 -2
  35. package/core/function/tgpuVertexFn.js +4 -2
  36. package/core/pipeline/applyPipelineState.js +3 -1
  37. package/core/pipeline/computePipeline.d.ts +4 -0
  38. package/core/pipeline/computePipeline.js +8 -6
  39. package/core/pipeline/connectAttachmentToShader.js +3 -1
  40. package/core/pipeline/connectTargetsToShader.js +3 -1
  41. package/core/pipeline/limitsOverflow.js +2 -1
  42. package/core/pipeline/pipelineUtils.js +6 -4
  43. package/core/pipeline/renderPipeline.js +21 -19
  44. package/core/pipeline/timeable.d.ts +2 -0
  45. package/core/pipeline/timeable.js +3 -1
  46. package/core/pipeline/typeGuards.js +3 -1
  47. package/core/querySet/querySet.d.ts +2 -0
  48. package/core/querySet/querySet.js +3 -1
  49. package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +1 -0
  50. package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +3 -1
  51. package/core/resolve/externals.d.ts +3 -0
  52. package/core/resolve/externals.js +7 -5
  53. package/core/resolve/namespace.js +6 -4
  54. package/core/resolve/resolveData.js +3 -1
  55. package/core/resolve/stitch.js +3 -1
  56. package/core/resolve/tgpuResolve.js +7 -5
  57. package/core/root/configurableImpl.js +3 -1
  58. package/core/root/init.d.ts +10 -2
  59. package/core/root/init.js +4 -2
  60. package/core/root/rootTypes.d.ts +11 -11
  61. package/core/sampler/sampler.d.ts +4 -0
  62. package/core/sampler/sampler.js +3 -1
  63. package/core/simulate/tgpuSimulate.js +6 -4
  64. package/core/slot/accessor.d.ts +4 -0
  65. package/core/slot/accessor.js +3 -1
  66. package/core/slot/internalSlots.js +3 -1
  67. package/core/slot/lazy.js +3 -1
  68. package/core/slot/slot.js +3 -1
  69. package/core/slot/slotTypes.js +3 -1
  70. package/core/texture/externalTexture.d.ts +6 -0
  71. package/core/texture/externalTexture.js +3 -1
  72. package/core/texture/texture.d.ts +4 -0
  73. package/core/texture/texture.js +6 -4
  74. package/core/texture/textureFormats.js +3 -1
  75. package/core/texture/textureUtils.js +3 -1
  76. package/core/texture/usageExtension.js +3 -1
  77. package/core/unroll/tgpuUnroll.d.ts +3 -1
  78. package/core/unroll/tgpuUnroll.js +3 -1
  79. package/core/valueProxyUtils.js +7 -5
  80. package/core/variable/tgpuVariable.d.ts +3 -1
  81. package/core/variable/tgpuVariable.js +3 -1
  82. package/core/vertexLayout/connectAttributesToShader.js +3 -1
  83. package/core/vertexLayout/vertexAttribute.d.ts +1 -0
  84. package/core/vertexLayout/vertexLayout.js +7 -5
  85. package/data/alignIO.js +3 -1
  86. package/data/alignmentOf.d.ts +2 -0
  87. package/data/alignmentOf.js +3 -1
  88. package/data/array.js +3 -1
  89. package/data/atomic.d.ts +1 -0
  90. package/data/atomic.js +3 -1
  91. package/data/attributes.js +7 -5
  92. package/data/autoStruct.d.ts +3 -1
  93. package/data/autoStruct.js +3 -1
  94. package/data/compiledIO.js +39 -37
  95. package/data/dataIO.js +22 -20
  96. package/data/dataTypes.d.ts +9 -4
  97. package/data/dataTypes.js +3 -1
  98. package/data/deepEqual.d.ts +1 -0
  99. package/data/deepEqual.js +3 -1
  100. package/data/disarray.d.ts +3 -1
  101. package/data/disarray.js +3 -1
  102. package/data/getLongestContiguousPrefix.d.ts +2 -0
  103. package/data/getLongestContiguousPrefix.js +3 -1
  104. package/data/index.d.ts +3 -3
  105. package/data/index.js +5 -6
  106. package/data/isContiguous.d.ts +2 -0
  107. package/data/isContiguous.js +3 -1
  108. package/data/matrix.d.ts +11 -8
  109. package/data/matrix.js +3 -1
  110. package/data/numberOps.js +2 -1
  111. package/data/numeric.d.ts +1 -0
  112. package/data/numeric.js +19 -15
  113. package/data/offsetUtils.d.ts +1 -0
  114. package/data/offsetUtils.js +3 -1
  115. package/data/offsets.js +5 -3
  116. package/data/partialIO.js +3 -1
  117. package/data/ptr.d.ts +1 -0
  118. package/data/ptr.js +3 -1
  119. package/data/ref.d.ts +3 -0
  120. package/data/ref.js +5 -3
  121. package/data/sampler.js +3 -1
  122. package/data/schemaCallWrapper.js +3 -1
  123. package/data/schemaMemoryLayout.js +3 -1
  124. package/data/sizeOf.d.ts +2 -0
  125. package/data/sizeOf.js +3 -1
  126. package/data/snippet.d.ts +1 -6
  127. package/data/snippet.js +3 -1
  128. package/data/struct.d.ts +1 -0
  129. package/data/struct.js +3 -1
  130. package/data/texture.js +3 -1
  131. package/data/unstruct.d.ts +1 -0
  132. package/data/unstruct.js +3 -1
  133. package/data/vector.d.ts +1 -0
  134. package/data/vector.js +3 -1
  135. package/data/vectorImpl.js +3 -1
  136. package/data/vectorOps.js +3 -1
  137. package/data/vertexFormatData.js +3 -1
  138. package/data/wgslTypes.d.ts +4 -0
  139. package/data/wgslTypes.js +3 -1
  140. package/errors.d.ts +1 -0
  141. package/errors.js +3 -1
  142. package/execMode.js +3 -1
  143. package/extension.d.ts +1 -0
  144. package/extension.js +3 -1
  145. package/getGPUValue.js +3 -1
  146. package/index.js +3 -4
  147. package/indexNamedExports.d.ts +1 -0
  148. package/mathUtils.js +2 -1
  149. package/memo.js +2 -1
  150. package/nameRegistry.js +3 -1
  151. package/package.js +3 -2
  152. package/package.json +1 -1
  153. package/resolutionCtx.d.ts +11 -0
  154. package/resolutionCtx.js +86 -87
  155. package/shared/env.js +2 -1
  156. package/shared/generators.js +2 -1
  157. package/shared/meta.js +3 -1
  158. package/shared/repr.d.ts +1 -0
  159. package/shared/stringify.js +3 -1
  160. package/shared/symbols.js +42 -10
  161. package/shared/utilityTypes.js +2 -1
  162. package/shared/vertexFormat.js +2 -1
  163. package/std/array.d.ts +1 -1
  164. package/std/array.js +3 -1
  165. package/std/atomic.d.ts +12 -12
  166. package/std/atomic.js +3 -1
  167. package/std/bitcast.d.ts +2 -2
  168. package/std/bitcast.js +3 -1
  169. package/std/boolean.d.ts +15 -14
  170. package/std/boolean.js +3 -1
  171. package/std/derivative.d.ts +9 -9
  172. package/std/derivative.js +3 -1
  173. package/std/discard.d.ts +1 -1
  174. package/std/discard.js +3 -1
  175. package/std/extensions.d.ts +3 -1
  176. package/std/extensions.js +3 -1
  177. package/std/index.js +5 -3
  178. package/std/matrix.d.ts +6 -5
  179. package/std/matrix.js +3 -1
  180. package/std/numeric.d.ts +132 -78
  181. package/std/numeric.js +7 -5
  182. package/std/operators.d.ts +8 -8
  183. package/std/operators.js +7 -5
  184. package/std/packing.d.ts +5 -4
  185. package/std/packing.js +3 -1
  186. package/std/range.d.ts +3 -1
  187. package/std/range.js +3 -1
  188. package/std/subgroup.d.ts +21 -21
  189. package/std/subgroup.js +3 -1
  190. package/std/texture.d.ts +11 -11
  191. package/std/texture.js +9 -7
  192. package/tgpu.js +5 -3
  193. package/tgpuBindGroupLayout.d.ts +11 -7
  194. package/tgpuBindGroupLayout.js +3 -1
  195. package/tgpuUnstable.js +5 -3
  196. package/tgsl/accessIndex.js +5 -3
  197. package/tgsl/accessProp.js +10 -3
  198. package/tgsl/consoleLog/deserializers.js +3 -1
  199. package/tgsl/consoleLog/logGenerator.js +18 -9
  200. package/tgsl/consoleLog/serializers.js +3 -1
  201. package/tgsl/consoleLog/types.d.ts +3 -0
  202. package/tgsl/consoleLog/types.js +2 -1
  203. package/tgsl/conversion.js +18 -6
  204. package/tgsl/forOfUtils.js +17 -7
  205. package/tgsl/generationHelpers.d.ts +1 -0
  206. package/tgsl/generationHelpers.js +3 -4
  207. package/tgsl/math.js +3 -1
  208. package/tgsl/shaderGenerator.d.ts +3 -2
  209. package/tgsl/shaderGenerator_members.d.ts +15 -2
  210. package/tgsl/shaderGenerator_members.js +5 -3
  211. package/tgsl/shellless.js +3 -1
  212. package/tgsl/wgslGenerator.d.ts +3 -1
  213. package/tgsl/wgslGenerator.js +54 -44
  214. package/types.d.ts +11 -7
  215. package/types.js +3 -1
  216. package/wgslExtensions.js +2 -1
package/tgsl/shellless.js CHANGED
@@ -5,6 +5,7 @@ import { WgslTypeError } from "../errors.js";
5
5
  import { RefOperator } from "../data/ref.js";
6
6
  import { concretize } from "./generationHelpers.js";
7
7
  import { createShelllessImpl } from "../core/function/shelllessImpl.js";
8
+
8
9
  //#region src/tgsl/shellless.ts
9
10
  function shallowEqualSchemas(a, b) {
10
11
  if (a.type !== b.type) return false;
@@ -42,5 +43,6 @@ var ShelllessRepository = class {
42
43
  return shellless;
43
44
  }
44
45
  };
46
+
45
47
  //#endregion
46
- export { ShelllessRepository };
48
+ export { ShelllessRepository };
@@ -1,5 +1,6 @@
1
1
  import { Origin, ResolvedSnippet, Snippet } from "../data/snippet.js";
2
2
  import { GenerationCtx } from "./generationHelpers.js";
3
+ import { FunctionDefinitionOptions } from "./shaderGenerator_members.js";
3
4
  import { ShaderGenerator } from "./shaderGenerator.js";
4
5
  import { BaseData, StorableData } from "../data/wgslTypes.js";
5
6
  import { UnknownData } from "../data/dataTypes.js";
@@ -22,7 +23,7 @@ declare class WgslGenerator implements ShaderGenerator {
22
23
  */
23
24
  _typedExpression(expression: tinyest.Expression, expectedType: BaseData | BaseData[]): Snippet;
24
25
  _expression(expression: tinyest.Expression): Snippet;
25
- functionDefinition(body: tinyest.Block): string;
26
+ functionDefinition(options: FunctionDefinitionOptions): string;
26
27
  /**
27
28
  * Generates a WGSL type string for the given data type, and adds necessary
28
29
  * definitions to the shader preamble. This shouldn't be called directly, only
@@ -30,6 +31,7 @@ declare class WgslGenerator implements ShaderGenerator {
30
31
  */
31
32
  typeAnnotation(data: BaseData): string;
32
33
  typeInstantiation(schema: BaseData, args: readonly Snippet[]): ResolvedSnippet;
34
+ _return(statement: tinyest.Return): string;
33
35
  _statement(statement: tinyest.Statement): string;
34
36
  }
35
37
  //#endregion
@@ -13,6 +13,7 @@ import { convertStructValues, convertToCommonType, tryConvertSnippet } from "./c
13
13
  import { bool, i32, u32 } from "../data/numeric.js";
14
14
  import { ArrayExpression, coerceToSnippet, concretize, numericLiteralToSnippet } from "./generationHelpers.js";
15
15
  import { vec2u, vec3u, vec4u } from "../data/vector.js";
16
+ import { getAttributesString } from "../data/attributes.js";
16
17
  import { AutoStruct } from "../data/autoStruct.js";
17
18
  import { add, div, mul, neg, sub } from "../std/operators.js";
18
19
  import { accessProp } from "./accessProp.js";
@@ -27,6 +28,7 @@ import { mathToStd } from "./math.js";
27
28
  import { isTgpuRange } from "../std/range.js";
28
29
  import { getElementSnippet, getElementType, getLoopVarKind, getRangeSnippets } from "./forOfUtils.js";
29
30
  import * as tinyest from "tinyest";
31
+
30
32
  //#region src/tgsl/wgslGenerator.ts
31
33
  const { NodeTypeCatalog: NODE } = tinyest;
32
34
  const parenthesizedOps = [
@@ -215,12 +217,12 @@ ${this.ctx.pre}}`;
215
217
  const lhsExpr = this._expression(lhs);
216
218
  if ((op === "||" || op === "&&") && isKnownAtComptime(lhsExpr)) {
217
219
  if (!(op === "&&" ? lhsExpr.value : !lhsExpr.value)) return snip(op === "||", bool, "constant");
218
- const rhsExpr = this._expression(rhs);
219
- if (rhsExpr.dataType === UnknownData) throw new WgslTypeError(`Right-hand side of '${op}' is of unknown type`);
220
- if (isKnownAtComptime(rhsExpr)) return snip(!!rhsExpr.value, bool, "constant");
221
- const convRhs = tryConvertSnippet(this.ctx, rhsExpr, bool, false);
222
- const rhsStr = this.ctx.resolve(convRhs.value, convRhs.dataType).value;
223
- return snip(rhsStr, bool, "runtime");
220
+ const rhsExpr$1 = this._expression(rhs);
221
+ if (rhsExpr$1.dataType === UnknownData) throw new WgslTypeError(`Right-hand side of '${op}' is of unknown type`);
222
+ if (isKnownAtComptime(rhsExpr$1)) return snip(!!rhsExpr$1.value, bool, "constant");
223
+ const convRhs$1 = tryConvertSnippet(this.ctx, rhsExpr$1, bool, false);
224
+ const rhsStr$1 = this.ctx.resolve(convRhs$1.value, convRhs$1.dataType).value;
225
+ return snip(rhsStr$1, bool, "runtime");
224
226
  }
225
227
  const rhsExpr = this._expression(rhs);
226
228
  if (rhsExpr.value instanceof RefOperator) throw new WgslTypeError(stitch`Cannot assign a ref to an existing variable '${lhsExpr}', define a new variable instead.`);
@@ -291,7 +293,7 @@ ${this.ctx.pre}}`;
291
293
  if (!accessed) {
292
294
  const targetStr = this.ctx.resolve(target.value, target.dataType).value;
293
295
  const propertyStr = this.ctx.resolve(property.value, property.dataType).value;
294
- throw new Error(`Unable to index value ${targetStr} of unknown type with index ${propertyStr}. If the value is an array, to address this, consider one of the following approaches: (1) declare the array using 'tgpu.const', (2) store the array in a buffer, or (3) define the array within the GPU function scope.`);
296
+ throw new Error(`Index access '${targetStr}[${propertyStr}]' is invalid. If the value is an array, to address this, consider one of the following approaches: (1) declare the array using 'tgpu.const', (2) store the array in a buffer, or (3) define the array within the GPU function scope.`);
295
297
  }
296
298
  return accessed;
297
299
  }
@@ -421,8 +423,13 @@ ${this.ctx.pre}}`;
421
423
  if (expression[0] === NODE.preUpdate) throw new Error("Cannot use pre-updates in TypeGPU functions.");
422
424
  assertExhaustive(expression);
423
425
  }
424
- functionDefinition(body) {
425
- return this._block(body);
426
+ functionDefinition(options) {
427
+ const body = this._block(options.body);
428
+ const returnType = options.determineReturnType();
429
+ const argList = options.args.filter((arg) => arg.used || options.functionType === "normal").map((arg) => {
430
+ return `${getAttributesString(arg.decoratedType)}${arg.name}: ${this.ctx.resolve(arg.decoratedType).value}`;
431
+ }).join(", ");
432
+ return `${returnType.type !== "void" ? `(${argList}) -> ${getAttributesString(returnType)}${this.ctx.resolve(returnType).value} ` : `(${argList}) `}${body}`;
426
433
  }
427
434
  /**
428
435
  * Generates a WGSL type string for the given data type, and adds necessary
@@ -436,35 +443,36 @@ ${this.ctx.pre}}`;
436
443
  if (args.length === 1 && args[0]?.dataType === schema) return snip(stitch`${args[0]}`, schema, fallthroughCopyOrigin(args[0].origin));
437
444
  return snip(stitch`${this.ctx.resolve(schema).value}(${args})`, schema, "runtime");
438
445
  }
439
- _statement(statement) {
440
- if (typeof statement === "string") {
441
- const id = this._identifier(statement);
442
- const resolved = id.value && this.ctx.resolve(id.value).value;
443
- return resolved ? `${this.ctx.pre}${resolved};` : "";
444
- }
445
- if (typeof statement === "boolean") return `${this.ctx.pre}${statement ? "true" : "false"};`;
446
- if (statement[0] === NODE.return) {
447
- const returnNode = statement[1];
448
- if (returnNode !== void 0) {
449
- const expectedReturnType = this.ctx.topFunctionReturnType;
450
- let returnSnippet = expectedReturnType ? this._typedExpression(returnNode, expectedReturnType) : this._expression(returnNode);
451
- if (returnSnippet.value instanceof RefOperator) throw new WgslTypeError(stitch`Cannot return references, returning '${returnSnippet.value.snippet}'`);
452
- if (returnSnippet.origin === "argument" && !isNaturallyEphemeral(returnSnippet.dataType) && this.ctx.topFunctionScope?.functionType === "normal") throw new WgslTypeError(stitch`Cannot return references to arguments, returning '${returnSnippet}'. Copy the argument before returning it.`);
453
- if (!expectedReturnType && !isEphemeralSnippet(returnSnippet) && returnSnippet.origin !== "this-function") {
454
- const str = this.ctx.resolve(returnSnippet.value, returnSnippet.dataType).value;
455
- const typeStr = this.ctx.resolve(unptr(returnSnippet.dataType)).value;
456
- throw new WgslTypeError(`'return ${str};' is invalid, cannot return references.
446
+ _return(statement) {
447
+ const returnNode = statement[1];
448
+ if (returnNode !== void 0) {
449
+ const expectedReturnType = this.ctx.topFunctionReturnType;
450
+ let returnSnippet = expectedReturnType ? this._typedExpression(returnNode, expectedReturnType) : this._expression(returnNode);
451
+ if (returnSnippet.value instanceof RefOperator) throw new WgslTypeError(stitch`Cannot return references, returning '${returnSnippet.value.snippet}'`);
452
+ if (returnSnippet.origin === "argument" && !isNaturallyEphemeral(returnSnippet.dataType) && this.ctx.topFunctionScope?.functionType === "normal") throw new WgslTypeError(stitch`Cannot return references to arguments, returning '${returnSnippet}'. Copy the argument before returning it.`);
453
+ if (!expectedReturnType && !isEphemeralSnippet(returnSnippet) && returnSnippet.origin !== "this-function") {
454
+ const str = this.ctx.resolve(returnSnippet.value, returnSnippet.dataType).value;
455
+ const typeStr = this.ctx.resolve(unptr(returnSnippet.dataType)).value;
456
+ throw new WgslTypeError(`'return ${str};' is invalid, cannot return references.
457
457
  -----
458
458
  Try 'return ${typeStr}(${str});' instead.
459
459
  -----`);
460
- }
461
- returnSnippet = tryConvertSnippet(this.ctx, returnSnippet, unptr(returnSnippet.dataType), false);
462
- invariant(returnSnippet.dataType !== UnknownData, "Return type should be known");
463
- this.ctx.reportReturnType(returnSnippet.dataType);
464
- return stitch`${this.ctx.pre}return ${returnSnippet};`;
465
460
  }
466
- return `${this.ctx.pre}return;`;
461
+ returnSnippet = tryConvertSnippet(this.ctx, returnSnippet, unptr(returnSnippet.dataType), false);
462
+ invariant(returnSnippet.dataType !== UnknownData, "Return type should be known");
463
+ this.ctx.reportReturnType(returnSnippet.dataType);
464
+ return stitch`${this.ctx.pre}return ${returnSnippet};`;
467
465
  }
466
+ return `${this.ctx.pre}return;`;
467
+ }
468
+ _statement(statement) {
469
+ if (typeof statement === "string") {
470
+ const id = this._identifier(statement);
471
+ const resolved$1 = id.value && this.ctx.resolve(id.value).value;
472
+ return resolved$1 ? `${this.ctx.pre}${resolved$1};` : "";
473
+ }
474
+ if (typeof statement === "boolean") return `${this.ctx.pre}${statement ? "true" : "false"};`;
475
+ if (statement[0] === NODE.return) return this._return(statement);
468
476
  if (statement[0] === NODE.if) {
469
477
  const [_, condNode, consNode, altNode] = statement;
470
478
  const condition = this._typedExpression(condNode, bool);
@@ -500,12 +508,12 @@ ${this.ctx.pre}else ${alternate}`;
500
508
  }
501
509
  if (!ephemeral) {
502
510
  if (stmtType === NODE.let) {
503
- const rhsStr = this.ctx.resolve(eq.value).value;
511
+ const rhsStr$1 = this.ctx.resolve(eq.value).value;
504
512
  const rhsTypeStr = this.ctx.resolve(unptr(eq.dataType)).value;
505
- throw new WgslTypeError(`'let ${rawId} = ${rhsStr}' is invalid, because references cannot be assigned to 'let' variable declarations.
513
+ throw new WgslTypeError(`'let ${rawId} = ${rhsStr$1}' is invalid, because references cannot be assigned to 'let' variable declarations.
506
514
  -----
507
- - Try 'let ${rawId} = ${rhsTypeStr}(${rhsStr})' if you need to reassign '${rawId}' later
508
- - Try 'const ${rawId} = ${rhsStr}' if you won't reassign '${rawId}' later.
515
+ - Try 'let ${rawId} = ${rhsTypeStr}(${rhsStr$1})' if you need to reassign '${rawId}' later
516
+ - Try 'const ${rawId} = ${rhsStr$1}' if you won't reassign '${rawId}' later.
509
517
  -----`);
510
518
  }
511
519
  if (eq.origin === "constant-tgpu-const-ref") varType = "const";
@@ -524,12 +532,12 @@ ${this.ctx.pre}else ${alternate}`;
524
532
  else if (naturallyEphemeral) varType = eq.origin === "constant" ? "const" : "let";
525
533
  } else if (eq.origin === "argument") {
526
534
  if (!naturallyEphemeral) {
527
- const rhsStr = this.ctx.resolve(eq.value).value;
535
+ const rhsStr$1 = this.ctx.resolve(eq.value).value;
528
536
  const rhsTypeStr = this.ctx.resolve(unptr(eq.dataType)).value;
529
- throw new WgslTypeError(`'let ${rawId} = ${rhsStr}' is invalid, because references to arguments cannot be assigned to 'let' variable declarations.
537
+ throw new WgslTypeError(`'let ${rawId} = ${rhsStr$1}' is invalid, because references to arguments cannot be assigned to 'let' variable declarations.
530
538
  -----
531
- - Try 'let ${rawId} = ${rhsTypeStr}(${rhsStr})' if you need to reassign '${rawId}' later
532
- - Try 'const ${rawId} = ${rhsStr}' if you won't reassign '${rawId}' later.
539
+ - Try 'let ${rawId} = ${rhsTypeStr}(${rhsStr$1})' if you need to reassign '${rawId}' later
540
+ - Try 'const ${rawId} = ${rhsStr$1}' if you won't reassign '${rawId}' later.
533
541
  -----`);
534
542
  }
535
543
  }
@@ -591,7 +599,7 @@ ${this.ctx.pre}else ${alternate}`;
591
599
  const length = range.end.value;
592
600
  if (length === 0) return "";
593
601
  const { value } = iterableSnippet;
594
- const elements = isTgpuRange(value) ? value.map((i) => coerceToSnippet(i)) : value instanceof ArrayExpression ? value.elements : Array.from({ length }, (_, i) => getElementSnippet(iterableSnippet, snip(i, u32, "constant")));
602
+ const elements = isTgpuRange(value) ? value.map((i) => coerceToSnippet(i)) : value instanceof ArrayExpression ? value.elements : Array.from({ length }, (_$1, i) => getElementSnippet(iterableSnippet, snip(i, u32, "constant")));
595
603
  if (isEphemeralSnippet(elements[0]) && !isNaturallyEphemeral(elements[0]?.dataType)) throw new WgslTypeError("Cannot unroll loop. The elements of iterable are emphemeral but not naturally ephemeral.");
596
604
  return elements.map((e, i) => `${this.ctx.pre}// unrolled iteration #${i}\n${this.ctx.pre}${this._block(blockified, { [originalLoopVarName]: e })}`).join("\n");
597
605
  }
@@ -599,7 +607,7 @@ ${this.ctx.pre}else ${alternate}`;
599
607
  const index = this.ctx.makeNameValid("i");
600
608
  const forHeaderStr = stitch`${this.ctx.pre}for (var ${index} = ${range.start}; ${index} ${range.comparison} ${range.end}; ${index} += ${range.step})`;
601
609
  let bodyStr = "";
602
- if (isTgpuRange(iterableSnippet.value)) bodyStr = this._block(blockified, { [originalLoopVarName]: snip(index, u32, "runtime") });
610
+ if (isTgpuRange(iterableSnippet.value)) bodyStr = this._block(blockified, { [originalLoopVarName]: snip(index, range.start.dataType, "runtime") });
603
611
  else {
604
612
  this.ctx.indent();
605
613
  ctxIndent = true;
@@ -644,5 +652,7 @@ function blockifySingleStatement(statement) {
644
652
  return typeof statement !== "object" || statement[0] !== NODE.block ? [NODE.block, [statement]] : statement;
645
653
  }
646
654
  const wgslGenerator = new WgslGenerator();
655
+ var wgslGenerator_default = wgslGenerator;
656
+
647
657
  //#endregion
648
- export { WgslGenerator, wgslGenerator as default };
658
+ export { WgslGenerator, wgslGenerator_default as default };
package/types.d.ts CHANGED
@@ -49,11 +49,17 @@ type ItemLayer = {
49
49
  type: 'item';
50
50
  usedSlots: Set<TgpuSlot<unknown>>;
51
51
  };
52
+ type FunctionArgumentAccess = () => Snippet | undefined;
53
+ interface FunctionArgument {
54
+ name: string;
55
+ access: FunctionArgumentAccess;
56
+ decoratedType: BaseData;
57
+ used: boolean;
58
+ }
52
59
  type FunctionScopeLayer = {
53
60
  type: 'functionScope';
54
61
  functionType: 'normal' | 'compute' | 'vertex' | 'fragment';
55
- args: Snippet[];
56
- argAliases: Record<string, Snippet>;
62
+ argAccess: Record<string, FunctionArgumentAccess>;
57
63
  externalMap: Record<string, unknown>;
58
64
  /**
59
65
  * The return type of the function. If undefined, the type should be inferred
@@ -81,12 +87,11 @@ interface ItemStateStack {
81
87
  readonly topFunctionScope: FunctionScopeLayer | undefined;
82
88
  pushItem(): void;
83
89
  pushSlotBindings(pairs: SlotValuePair[]): void;
84
- pushFunctionScope(functionType: 'normal' | TgpuShaderStage, args: Snippet[], argAliases: Record<string, Snippet>,
90
+ pushFunctionScope(functionType: 'normal' | TgpuShaderStage, argAccess: Record<string, FunctionArgumentAccess>,
85
91
  /**
86
92
  * The return type of the function. If undefined, the type should be inferred
87
93
  * from the implementation (relevant for shellless functions).
88
94
  */
89
-
90
95
  returnType: BaseData | undefined, externalMap: Record<string, unknown>): FunctionScopeLayer;
91
96
  pushBlockScope(): void;
92
97
  setBlockExternals(externals: Record<string, Snippet>): void;
@@ -218,8 +223,7 @@ interface ResolutionCtx {
218
223
  */
219
224
  resolveSnippet(snippet: Snippet): ResolvedSnippet;
220
225
  fnToWgsl(options: FnToWgslOptions): {
221
- head: Wgsl;
222
- body: Wgsl;
226
+ code: string;
223
227
  returnType: BaseData;
224
228
  };
225
229
  withVaryingLocations<T>(locations: Record<string, number>, callback: () => T): T;
@@ -262,4 +266,4 @@ type AnyFn = (...args: never[]) => unknown;
262
266
  type DualFn<T extends AnyFn> = T & GPUCallable<Parameters<T>>;
263
267
  type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
264
268
  //#endregion
265
- export { BindableBufferUsage, DualFn, FunctionScopeLayer, GPUCallable, ResolutionCtx, ResolvableObject, SelfResolvable, TgpuShaderStage, Wgsl, WithCast };
269
+ export { BindableBufferUsage, DualFn, FunctionArgument, FunctionScopeLayer, GPUCallable, ResolutionCtx, ResolvableObject, SelfResolvable, TgpuShaderStage, Wgsl, WithCast };
package/types.js CHANGED
@@ -2,6 +2,7 @@ import { $cast, $gpuCallable, $ownSnippet, $resolve } from "./shared/symbols.js"
2
2
  import { isWgslData } from "./data/wgslTypes.js";
3
3
  import { UnknownData } from "./data/dataTypes.js";
4
4
  import { isLazy, isProviding, isSlot } from "./core/slot/slotTypes.js";
5
+
5
6
  //#region src/types.ts
6
7
  var NormalState = class {
7
8
  type = "normal";
@@ -39,5 +40,6 @@ function isWgsl(value) {
39
40
  function isGPUBuffer(value) {
40
41
  return !!value && typeof value === "object" && "getMappedRange" in value && "mapAsync" in value;
41
42
  }
43
+
42
44
  //#endregion
43
- export { CodegenState, NormalState, SimulationState, getOwnSnippet, hasCast, isGPUBuffer, isGPUCallable, isKnownAtComptime, isSelfResolvable, isWgsl };
45
+ export { CodegenState, NormalState, SimulationState, getOwnSnippet, hasCast, isGPUBuffer, isGPUCallable, isKnownAtComptime, isSelfResolvable, isWgsl };
package/wgslExtensions.js CHANGED
@@ -13,5 +13,6 @@ const wgslExtensionToFeatureName = {
13
13
  subgroups: "subgroups",
14
14
  primitive_index: "primitive-index"
15
15
  };
16
+
16
17
  //#endregion
17
- export { wgslExtensionToFeatureName, wgslExtensions };
18
+ export { wgslExtensionToFeatureName, wgslExtensions };