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
@@ -1,13 +1,13 @@
1
- //#region \0rolldown/runtime.js
1
+ //#region rolldown:runtime
2
2
  var __defProp = Object.defineProperty;
3
- var __exportAll = (all, no_symbols) => {
3
+ var __export = (all) => {
4
4
  let target = {};
5
5
  for (var name in all) __defProp(target, name, {
6
6
  get: all[name],
7
7
  enumerable: true
8
8
  });
9
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
9
  return target;
11
10
  };
11
+
12
12
  //#endregion
13
- export { __exportAll };
13
+ export { __export };
package/builtin.js CHANGED
@@ -3,6 +3,7 @@ import { bool, f32, u32 } from "./data/numeric.js";
3
3
  import { vec3u, vec4f } from "./data/vector.js";
4
4
  import { attribute } from "./data/attributes.js";
5
5
  import { arrayOf } from "./data/array.js";
6
+
6
7
  //#region src/builtin.ts
7
8
  function defineBuiltin(dataType, value) {
8
9
  return attribute(dataType, {
@@ -31,5 +32,6 @@ const builtin = {
31
32
  subgroupId: defineBuiltin(u32, "subgroup_id"),
32
33
  numSubgroups: defineBuiltin(u32, "num_subgroups")
33
34
  };
35
+
34
36
  //#endregion
35
- export { builtin };
37
+ export { builtin };
@@ -1,6 +1,9 @@
1
1
  import { TgpuVertexFn } from "../core/function/tgpuVertexFn.js";
2
2
  import { Vec2f } from "../data/wgslTypes.js";
3
+ import "../indexNamedExports.js";
4
+
3
5
  //#region src/common/fullScreenTriangle.d.ts
6
+
4
7
  /**
5
8
  * A vertex function that defines a single full-screen triangle out
6
9
  * of three points.
@@ -17,6 +20,8 @@ import { Vec2f } from "../data/wgslTypes.js";
17
20
  * pipeline.draw(3);
18
21
  * ```
19
22
  */
20
- declare const fullScreenTriangle: TgpuVertexFn;
23
+ declare const fullScreenTriangle: TgpuVertexFn<{}, {
24
+ uv: Vec2f;
25
+ }>;
21
26
  //#endregion
22
27
  export { fullScreenTriangle };
@@ -1,6 +1,7 @@
1
1
  import { vec2f } from "../data/vector.js";
2
2
  import { builtin } from "../builtin.js";
3
3
  import { vertexFn } from "../core/function/tgpuVertexFn.js";
4
+
4
5
  //#region src/common/fullScreenTriangle.ts
5
6
  /**
6
7
  * A vertex function that defines a single full-screen triangle out
@@ -30,5 +31,6 @@ const fullScreenTriangle = vertexFn({
30
31
 
31
32
  return Out(vec4f(pos[in.vertexIndex], 0, 1), uv[in.vertexIndex]);
32
33
  }`;
34
+
33
35
  //#endregion
34
- export { fullScreenTriangle };
36
+ export { fullScreenTriangle };
package/common/index.js CHANGED
@@ -1,10 +1,12 @@
1
- import { __exportAll } from "../_virtual/_rolldown/runtime.js";
1
+ import { __export } from "../_virtual/rolldown_runtime.js";
2
2
  import { fullScreenTriangle } from "./fullScreenTriangle.js";
3
3
  import { writeSoA } from "./writeSoA.js";
4
+
4
5
  //#region src/common/index.ts
5
- var common_exports = /* @__PURE__ */ __exportAll({
6
+ var common_exports = /* @__PURE__ */ __export({
6
7
  fullScreenTriangle: () => fullScreenTriangle,
7
8
  writeSoA: () => writeSoA
8
9
  });
10
+
9
11
  //#endregion
10
- export { common_exports, fullScreenTriangle, writeSoA };
12
+ export { common_exports, fullScreenTriangle, writeSoA };
@@ -5,6 +5,7 @@ import { alignmentOf } from "../data/alignmentOf.js";
5
5
  import { roundUp } from "../mathUtils.js";
6
6
  import { sizeOf } from "../data/sizeOf.js";
7
7
  import { offsetsForProps } from "../data/offsets.js";
8
+
8
9
  //#region src/common/writeSoA.ts
9
10
  function packedSchemaOf(schema) {
10
11
  const unpackedSchema = undecorate(schema);
@@ -86,5 +87,6 @@ function writeSoA(buffer, data, options) {
86
87
  endOffset
87
88
  });
88
89
  }
90
+
89
91
  //#endregion
90
- export { writeSoA };
92
+ export { writeSoA };
@@ -3,8 +3,11 @@ import { $internal } from "../../shared/symbols.js";
3
3
  import { Prettify, UnionToIntersection } from "../../shared/utilityTypes.js";
4
4
  import { StorageFlag } from "../../extension.js";
5
5
  import { TgpuBufferMutable, TgpuBufferReadonly, TgpuBufferUniform, TgpuFixedBufferUsage } from "./bufferUsage.js";
6
+ import "../root/rootTypes.js";
6
7
  import { BaseData } from "../../data/wgslTypes.js";
7
8
  import { Infer, InferInput, InferPartial, InferPatch, IsValidIndexSchema, IsValidStorageSchema, IsValidUniformSchema, IsValidVertexSchema, MemIdentity } from "../../shared/repr.js";
9
+ import "../../data/dataTypes.js";
10
+
8
11
  //#region src/core/buffer/buffer.d.ts
9
12
  interface UniformFlag {
10
13
  usableAsUniform: true;
@@ -10,6 +10,7 @@ import { readData, writeData } from "../../data/dataIO.js";
10
10
  import { convertPartialToPatch, getPatchInstructions } from "../../data/partialIO.js";
11
11
  import { mutable, readonly, uniform } from "./bufferUsage.js";
12
12
  import { BufferReader, BufferWriter, getSystemEndianness } from "typed-binary";
13
+
13
14
  //#region src/core/buffer/buffer.ts
14
15
  const usageToUsageConstructor = {
15
16
  uniform,
@@ -212,9 +213,9 @@ var TgpuBufferImpl = class {
212
213
  if (gpuBuffer.mapState === "mapped") return readData(new BufferReader(this.#getMappedRange()), this.dataType);
213
214
  if (gpuBuffer.usage & GPUBufferUsage.MAP_READ) {
214
215
  await gpuBuffer.mapAsync(GPUMapMode.READ);
215
- const res = readData(new BufferReader(this.#getMappedRange()), this.dataType);
216
+ const res$1 = readData(new BufferReader(this.#getMappedRange()), this.dataType);
216
217
  this.#unmapBuffer();
217
- return res;
218
+ return res$1;
218
219
  }
219
220
  const stagingBuffer = this.#device.createBuffer({
220
221
  size: sizeOf(this.dataType),
@@ -242,5 +243,6 @@ var TgpuBufferImpl = class {
242
243
  return `buffer:${getName(this) ?? "<unnamed>"}`;
243
244
  }
244
245
  };
246
+
245
247
  //#endregion
246
- export { INTERNAL_createBuffer, isBuffer, isUsableAsVertex };
248
+ export { INTERNAL_createBuffer, isBuffer, isUsableAsVertex };
@@ -1,7 +1,9 @@
1
1
  import { TgpuNamable } from "../../shared/meta.js";
2
2
  import { $gpuValueOf, $internal } from "../../shared/symbols.js";
3
3
  import { StorageFlag } from "../../extension.js";
4
+ import "../../data/snippet.js";
4
5
  import { BufferWriteOptions, TgpuBuffer, UniformFlag } from "./buffer.js";
6
+ import "../../types.js";
5
7
  import { BaseData } from "../../data/wgslTypes.js";
6
8
  import { Infer, InferGPU, InferInput, InferPartial, InferPatch } from "../../shared/repr.js";
7
9
 
@@ -1,5 +1,6 @@
1
1
  import { $getNameForward, $gpuValueOf, $internal, $resolve } from "../../shared/symbols.js";
2
2
  import { getName, setName } from "../../shared/meta.js";
3
+
3
4
  //#region src/core/buffer/bufferShorthand.ts
4
5
  function isBufferShorthand(value) {
5
6
  return value instanceof TgpuBufferShorthandImpl;
@@ -49,5 +50,6 @@ var TgpuBufferShorthandImpl = class {
49
50
  return ctx.resolve(this.#usage);
50
51
  }
51
52
  };
53
+
52
54
  //#endregion
53
- export { TgpuBufferShorthandImpl, isBufferShorthand };
55
+ export { TgpuBufferShorthandImpl, isBufferShorthand };
@@ -1,5 +1,7 @@
1
1
  import { TgpuNamable } from "../../shared/meta.js";
2
2
  import { $gpuValueOf, $internal, $repr } from "../../shared/symbols.js";
3
+ import "../../data/snippet.js";
4
+ import "../../tgpuBindGroupLayout.js";
3
5
  import { TgpuBuffer, UniformFlag } from "./buffer.js";
4
6
  import { BindableBufferUsage } from "../../types.js";
5
7
  import { BaseData } from "../../data/wgslTypes.js";
@@ -8,6 +8,7 @@ import { schemaCallWrapper } from "../../data/schemaCallWrapper.js";
8
8
  import { assertExhaustive } from "../../shared/utilityTypes.js";
9
9
  import { valueProxyHandler } from "../valueProxyUtils.js";
10
10
  import { isUsableAsStorage } from "../../extension.js";
11
+
11
12
  //#region src/core/buffer/bufferUsage.ts
12
13
  function isUsableAsUniform(buffer) {
13
14
  return !!buffer.usableAsUniform;
@@ -161,5 +162,6 @@ function uniform(buffer) {
161
162
  }
162
163
  return usage;
163
164
  }
165
+
164
166
  //#endregion
165
- export { TgpuLaidOutBufferImpl, isUsableAsUniform, mutable, readonly, uniform };
167
+ export { TgpuLaidOutBufferImpl, isUsableAsUniform, mutable, readonly, uniform };
@@ -17,7 +17,8 @@ interface TgpuConst<TDataType extends BaseData = BaseData> extends TgpuNamable {
17
17
  readonly value: DeepReadonly<InferGPU<TDataType>>;
18
18
  readonly $: DeepReadonly<InferGPU<TDataType>>;
19
19
  readonly [$internal]: {
20
- /** Makes it differentiable on the type level. Does not exist at runtime. */dataType?: TDataType;
20
+ /** Makes it differentiable on the type level. Does not exist at runtime. */
21
+ dataType?: TDataType;
21
22
  };
22
23
  }
23
24
  /**
@@ -5,6 +5,7 @@ import { isData } from "../../data/dataTypes.js";
5
5
  import { snip } from "../../data/snippet.js";
6
6
  import { inCodegenMode } from "../../execMode.js";
7
7
  import { valueProxyHandler } from "../valueProxyUtils.js";
8
+
8
9
  //#region src/core/constant/tgpuConstant.ts
9
10
  function constant(dataType, value) {
10
11
  if (!isData(dataType)) {
@@ -64,5 +65,6 @@ var TgpuConstImpl = class {
64
65
  return this.$;
65
66
  }
66
67
  };
68
+
67
69
  //#endregion
68
- export { constant };
70
+ export { constant };
@@ -2,6 +2,7 @@ import { $internal, $resolve } from "../../shared/symbols.js";
2
2
  import { Void } from "../../data/wgslTypes.js";
3
3
  import { snip } from "../../data/snippet.js";
4
4
  import { applyExternals, replaceExternalsInWgsl } from "../resolve/externals.js";
5
+
5
6
  //#region src/core/declare/tgpuDeclare.ts
6
7
  /**
7
8
  * Allows defining extra declarations that shall be included in the final WGSL code,
@@ -35,5 +36,6 @@ var TgpuDeclareImpl = class {
35
36
  return `declare: ${this.#declaration}`;
36
37
  }
37
38
  };
39
+
38
40
  //#endregion
39
- export { declare };
41
+ export { declare };
@@ -1,8 +1,11 @@
1
1
  import { Assume, RemoveIndexSignature } from "../../shared/utilityTypes.js";
2
2
  import { BuiltinClipDistances, BuiltinFragDepth, BuiltinFrontFacing, BuiltinInstanceIndex, BuiltinPosition, BuiltinPrimitiveIndex, BuiltinSampleIndex, BuiltinSampleMask, BuiltinSubgroupInvocationId, BuiltinSubgroupSize, BuiltinVertexIndex, OmitBuiltins } from "../../builtin.js";
3
+ import "../../data/snippet.js";
3
4
  import { BaseIOData } from "./fnTypes.js";
4
5
  import { TgpuVertexAttrib } from "../../shared/vertexFormat.js";
6
+ import "../../data/autoStruct.js";
5
7
  import { FormatToWGSLType } from "../../data/vertexFormatData.js";
8
+ import "../../types.js";
6
9
  import { v4f } from "../../data/wgslTypes.js";
7
10
  import { InferGPU, InferGPURecord, InferRecord } from "../../shared/repr.js";
8
11
 
@@ -5,6 +5,7 @@ import { AutoStruct } from "../../data/autoStruct.js";
5
5
  import { createFnCore } from "./fnCore.js";
6
6
  import { shaderStageSlot } from "../slot/internalSlots.js";
7
7
  import { builtin } from "../../builtin.js";
8
+
8
9
  //#region src/core/function/autoIO.ts
9
10
  const builtinVertexIn = {
10
11
  $vertexIndex: builtin.vertexIndex,
@@ -36,7 +37,7 @@ var AutoFragmentFn = class {
36
37
  autoOut;
37
38
  constructor(impl, varyings, locations) {
38
39
  if (!getName(impl)) setName(impl, "fragmentFn");
39
- this.#core = createFnCore(impl, "@fragment ");
40
+ this.#core = createFnCore(impl, "fragment");
40
41
  this.autoIn = new AutoStruct({
41
42
  ...builtinFragmentIn,
42
43
  ...varyings
@@ -63,7 +64,7 @@ var AutoVertexFn = class {
63
64
  autoOut;
64
65
  constructor(impl, attribs, locations) {
65
66
  if (!getName(impl)) setName(impl, "vertexFn");
66
- this.#core = createFnCore(impl, "@vertex ");
67
+ this.#core = createFnCore(impl, "vertex");
67
68
  this.autoIn = new AutoStruct({
68
69
  ...builtinVertexIn,
69
70
  ...attribs
@@ -81,5 +82,6 @@ var AutoVertexFn = class {
81
82
  };
82
83
  AutoVertexFn.prototype[$internal] = true;
83
84
  AutoVertexFn.prototype.resourceType = "auto-vertex-fn";
85
+
84
86
  //#endregion
85
- export { AutoFragmentFn, AutoVertexFn };
87
+ export { AutoFragmentFn, AutoVertexFn };
@@ -3,6 +3,7 @@ import { setName } from "../../shared/meta.js";
3
3
  import { WgslTypeError } from "../../errors.js";
4
4
  import { isKnownAtComptime } from "../../types.js";
5
5
  import { coerceToSnippet } from "../../tgsl/generationHelpers.js";
6
+
6
7
  //#region src/core/function/comptime.ts
7
8
  /**
8
9
  * Creates a version of `func` that can called safely in a TypeGPU function to
@@ -45,5 +46,6 @@ function comptime(func) {
45
46
  Object.defineProperty(impl, $internal, { value: { isComptime: true } });
46
47
  return impl;
47
48
  }
49
+
48
50
  //#endregion
49
- export { comptime };
51
+ export { comptime };
@@ -4,6 +4,7 @@ import { isPtr } from "../../data/wgslTypes.js";
4
4
  import { snip } from "../../data/snippet.js";
5
5
  import { NormalState, isKnownAtComptime } from "../../types.js";
6
6
  import { tryConvertSnippet } from "../../tgsl/conversion.js";
7
+
7
8
  //#region src/core/function/createCallableSchema.ts
8
9
  function callableSchema(options) {
9
10
  const impl = ((...args) => {
@@ -36,5 +37,6 @@ function callableSchema(options) {
36
37
  };
37
38
  return impl;
38
39
  }
40
+
39
41
  //#endregion
40
- export { callableSchema };
42
+ export { callableSchema };
@@ -5,6 +5,7 @@ import { snip } from "../../data/snippet.js";
5
5
  import { NormalState, isKnownAtComptime } from "../../types.js";
6
6
  import { tryConvertSnippet } from "../../tgsl/conversion.js";
7
7
  import { concretize } from "../../tgsl/generationHelpers.js";
8
+
8
9
  //#region src/core/function/dualImpl.ts
9
10
  var MissingCpuImplError = class extends Error {
10
11
  constructor(message) {
@@ -48,5 +49,6 @@ function dualImpl(options) {
48
49
  };
49
50
  return impl;
50
51
  }
52
+
51
53
  //#endregion
52
- export { MissingCpuImplError, dualImpl };
54
+ export { MissingCpuImplError, dualImpl };
@@ -1,7 +1,6 @@
1
1
  import { $internal } from "../../shared/symbols.js";
2
2
  import { isWgslStruct } from "../../data/wgslTypes.js";
3
- import { undecorate } from "../../data/dataTypes.js";
4
- import { snip } from "../../data/snippet.js";
3
+
5
4
  //#region src/core/function/entryInputRouter.ts
6
5
  /**
7
6
  * Routes `(input) => { input.x }` style property access to the correct WGSL
@@ -11,29 +10,26 @@ import { snip } from "../../data/snippet.js";
11
10
  var EntryInputRouter = class {
12
11
  [$internal] = {};
13
12
  type = "entry-input-router";
14
- structArgName;
15
- dataSchema;
13
+ structArg;
16
14
  /** Maps schemaKey → { WGSL arg name, type } */
17
15
  positionalArgsMap;
18
- constructor(structArgName, dataSchema, positionalArgs) {
19
- this.structArgName = structArgName;
20
- this.dataSchema = dataSchema;
21
- this.positionalArgsMap = new Map(positionalArgs.map((a) => [a.schemaKey, {
22
- argName: a.argName,
23
- type: a.type
24
- }]));
16
+ constructor(structArg, positionalArgs) {
17
+ this.structArg = structArg;
18
+ this.positionalArgsMap = new Map(positionalArgs.map((a) => [a.schemaKey, a.arg]));
25
19
  }
26
20
  toString() {
27
21
  return "entry-input-router";
28
22
  }
29
23
  accessProp(propName) {
30
24
  const positionalEntry = this.positionalArgsMap.get(propName);
31
- if (positionalEntry) return snip(positionalEntry.argName, positionalEntry.type, "argument");
32
- if (this.dataSchema && isWgslStruct(this.dataSchema)) {
33
- const propType = this.dataSchema.propTypes[propName];
34
- if (propType) return snip(`${this.structArgName}.${propName}`, undecorate(propType), "argument");
35
- }
25
+ if (positionalEntry) return positionalEntry();
26
+ const structSnippet = this.structArg?.();
27
+ if (structSnippet && isWgslStruct(structSnippet.dataType)) return {
28
+ target: structSnippet,
29
+ prop: propName
30
+ };
36
31
  }
37
32
  };
33
+
38
34
  //#endregion
39
- export { EntryInputRouter };
35
+ export { EntryInputRouter };
@@ -200,5 +200,6 @@ const openingCommentBlock = new Set(["*/"]);
200
200
  const parentheses = ["(", ")"];
201
201
  const angleBrackets = ["<", ">"];
202
202
  const commentBlocks = ["/*", "*/"];
203
+
203
204
  //#endregion
204
- export { extractArgs };
205
+ export { extractArgs };
@@ -7,8 +7,9 @@ import { MissingLinksError } from "../../errors.js";
7
7
  import { getAttributesString } from "../../data/attributes.js";
8
8
  import { applyExternals, replaceExternalsInWgsl } from "../resolve/externals.js";
9
9
  import { extractArgs } from "./extractArgs.js";
10
+
10
11
  //#region src/core/function/fnCore.ts
11
- function createFnCore(implementation, fnAttribute = "") {
12
+ function createFnCore(implementation, functionType, workgroupSize) {
12
13
  /**
13
14
  * External application has to be deferred until resolution because
14
15
  * some externals can reference the owner function which has not been
@@ -23,6 +24,10 @@ function createFnCore(implementation, fnAttribute = "") {
23
24
  },
24
25
  resolve(ctx, argTypes, returnType, entryInput) {
25
26
  const externalMap = {};
27
+ let attributes = "";
28
+ if (functionType === "compute") attributes = `@compute @workgroup_size(${workgroupSize?.join(", ")}) `;
29
+ else if (functionType === "vertex") attributes = `@vertex `;
30
+ else if (functionType === "fragment") attributes = `@fragment `;
26
31
  for (const externals of externalsToApply) applyExternals(externalMap, externals);
27
32
  const id = ctx.getUniqueName(this);
28
33
  if (typeof implementation === "string") {
@@ -32,7 +37,7 @@ function createFnCore(implementation, fnAttribute = "") {
32
37
  const replacedImpl = replaceExternalsInWgsl(ctx, externalMap, implementation);
33
38
  let header = "";
34
39
  let body = "";
35
- if (fnAttribute !== "" && entryInput && validArgNames) {
40
+ if (functionType !== "normal" && entryInput && validArgNames) {
36
41
  const { dataSchema, positionalArgs } = entryInput;
37
42
  const parts = [];
38
43
  if (dataSchema && isArgUsedInBody("in", replacedImpl)) parts.push(`in: ${ctx.resolve(dataSchema).value}`);
@@ -41,8 +46,8 @@ function createFnCore(implementation, fnAttribute = "") {
41
46
  if (argName !== "" && isArgUsedInBody(argName, replacedImpl)) parts.push(`${getAttributesString(a.type)}${argName}: ${ctx.resolve(a.type).value}`);
42
47
  }
43
48
  const input = `(${parts.join(", ")})`;
44
- const attributes = isWgslData(returnType) ? getAttributesString(returnType) : "";
45
- header = `${input}${returnType !== Void ? isWgslStruct(returnType) ? ` -> ${ctx.resolve(returnType).value} ` : ` -> ${attributes !== "" ? attributes : "@location(0)"} ${ctx.resolve(returnType).value} ` : " "}`;
49
+ const attributes$1 = isWgslData(returnType) ? getAttributesString(returnType) : "";
50
+ header = `${input}${returnType !== Void ? isWgslStruct(returnType) ? ` -> ${ctx.resolve(returnType).value} ` : ` -> ${attributes$1 !== "" ? attributes$1 : "@location(0)"} ${ctx.resolve(returnType).value} ` : " "}`;
46
51
  body = replacedImpl;
47
52
  } else {
48
53
  const providedArgs = extractArgs(replacedImpl);
@@ -50,7 +55,7 @@ function createFnCore(implementation, fnAttribute = "") {
50
55
  header = `(${providedArgs.args.map((argInfo, i) => `${argInfo.identifier}: ${checkAndReturnType(ctx, `parameter ${argInfo.identifier}`, argInfo.type, argTypes[i])}`).join(", ")})${returnType === Void ? " " : ` -> ${checkAndReturnType(ctx, "return type", providedArgs.ret?.type, returnType)} `}`;
51
56
  body = replacedImpl.slice(providedArgs.range.end);
52
57
  }
53
- ctx.addDeclaration(`${fnAttribute}fn ${id}${header}${body}`);
58
+ ctx.addDeclaration(`${attributes}fn ${id}${header}${body}`);
54
59
  return snip(id, returnType, "runtime");
55
60
  }
56
61
  const pluginData = getMetaData(implementation);
@@ -61,9 +66,9 @@ function createFnCore(implementation, fnAttribute = "") {
61
66
  const missingExternals = ast.externalNames.filter((name) => !(name in externalMap));
62
67
  if (missingExternals.length > 0) throw new MissingLinksError(getName(this), missingExternals);
63
68
  const maybeSecondArg = ast.params[1];
64
- if (maybeSecondArg && maybeSecondArg.type === "i" && fnAttribute !== "") applyExternals(externalMap, { [maybeSecondArg.name]: undecorate(returnType) });
65
- const { head, body, returnType: actualReturnType } = ctx.fnToWgsl({
66
- functionType: fnAttribute.includes("@compute") ? "compute" : fnAttribute.includes("@vertex") ? "vertex" : fnAttribute.includes("@fragment") ? "fragment" : "normal",
69
+ if (maybeSecondArg && maybeSecondArg.type === "i" && functionType !== "normal") applyExternals(externalMap, { [maybeSecondArg.name]: undecorate(returnType) });
70
+ const { code, returnType: actualReturnType } = ctx.fnToWgsl({
71
+ functionType,
67
72
  argTypes,
68
73
  entryInput,
69
74
  params: ast.params,
@@ -71,13 +76,13 @@ function createFnCore(implementation, fnAttribute = "") {
71
76
  body: ast.body,
72
77
  externalMap
73
78
  });
74
- ctx.addDeclaration(`${fnAttribute}fn ${id}${ctx.resolve(head).value}${ctx.resolve(body).value}`);
79
+ ctx.addDeclaration(`${attributes}fn ${id}${code}`);
75
80
  return snip(id, actualReturnType, "runtime");
76
81
  }
77
82
  };
78
83
  }
79
84
  function isArgUsedInBody(argName, body) {
80
- return new RegExp(`\\b${argName}\\b`).test(body);
85
+ return (/* @__PURE__ */ new RegExp(`\\b${argName}\\b`)).test(body);
81
86
  }
82
87
  function checkAndReturnType(ctx, name, wgslType, jsType) {
83
88
  const resolvedJsType = ctx.resolve(jsType).value.replace(/\s/g, "");
@@ -86,5 +91,6 @@ function checkAndReturnType(ctx, name, wgslType, jsType) {
86
91
  if (resolvedWgslType !== resolvedJsType) throw new Error(`Type mismatch between TGPU shell and WGSL code string: ${name}, JS type "${resolvedJsType}", WGSL type "${resolvedWgslType}".`);
87
92
  return wgslType;
88
93
  }
94
+
89
95
  //#endregion
90
- export { createFnCore };
96
+ export { createFnCore };
@@ -2,6 +2,8 @@ import { BuiltinClipDistances } from "../../builtin.js";
2
2
  import { AnyAttribute } from "../../data/attributes.js";
3
3
  import { BaseData, Bool, Decorated, F16, F32, I32, U32, Vec2f, Vec2h, Vec2i, Vec2u, Vec3f, Vec3h, Vec3i, Vec3u, Vec4f, Vec4h, Vec4i, Vec4u, Void } from "../../data/wgslTypes.js";
4
4
  import { InferGPU } from "../../shared/repr.js";
5
+ import "tinyest";
6
+
5
7
  //#region src/core/function/fnTypes.d.ts
6
8
  type AnyFn = (...args: never[]) => unknown;
7
9
  type InferArgs<T extends unknown[]> = { [Idx in keyof T]: InferGPU<T[Idx]> };
@@ -1,4 +1,5 @@
1
1
  import { Decorate, HasCustomLocation, IsBuiltin } from "../../data/attributes.js";
2
+ import "./fnTypes.js";
2
3
  import { BaseData, Location, WgslStruct } from "../../data/wgslTypes.js";
3
4
 
4
5
  //#region src/core/function/ioSchema.d.ts
@@ -2,6 +2,7 @@ import { isVoid } from "../../data/wgslTypes.js";
2
2
  import { getCustomLocation, isData } from "../../data/dataTypes.js";
3
3
  import { isBuiltin, location } from "../../data/attributes.js";
4
4
  import { INTERNAL_createStruct } from "../../data/struct.js";
5
+
5
6
  //#region src/core/function/ioSchema.ts
6
7
  function withLocations(members, locations = {}) {
7
8
  let nextLocation = 0;
@@ -47,5 +48,6 @@ function separateAllAsPositional(schema) {
47
48
  function createIoSchema(layout, locations = {}) {
48
49
  return isData(layout) ? isVoid(layout) ? layout : isBuiltin(layout) ? layout : getCustomLocation(layout) !== void 0 ? layout : location(0, layout) : INTERNAL_createStruct(withLocations(layout, locations), false);
49
50
  }
51
+
50
52
  //#endregion
51
- export { createIoSchema, separateAllAsPositional, separateBuiltins };
53
+ export { createIoSchema, separateAllAsPositional, separateBuiltins };
@@ -3,6 +3,7 @@ import { SelfResolvable } from "../../types.js";
3
3
  import { BaseData } from "../../data/wgslTypes.js";
4
4
 
5
5
  //#region src/core/function/shelllessImpl.d.ts
6
+
6
7
  /**
7
8
  * Shell-less functions are possible because we can infer the signature based solely on the context
8
9
  * around the function.
@@ -1,9 +1,10 @@
1
1
  import { $getNameForward, $internal, $resolve } from "../../shared/symbols.js";
2
2
  import { getName } from "../../shared/meta.js";
3
3
  import { createFnCore } from "./fnCore.js";
4
+
4
5
  //#region src/core/function/shelllessImpl.ts
5
6
  function createShelllessImpl(argTypes, implementation) {
6
- const core = createFnCore(implementation, "");
7
+ const core = createFnCore(implementation, "normal");
7
8
  return {
8
9
  [$internal]: true,
9
10
  [$getNameForward]: core,
@@ -17,5 +18,6 @@ function createShelllessImpl(argTypes, implementation) {
17
18
  }
18
19
  };
19
20
  }
21
+
20
22
  //#endregion
21
- export { createShelllessImpl };
23
+ export { createShelllessImpl };
@@ -8,5 +8,6 @@ function isTemplateStringsArray(value) {
8
8
  function templateLiteralIdentity(strings, ...values) {
9
9
  return strings.slice(1).reduce((acc, elem, index) => `${acc}${values[index]}${elem}`, strings[0]);
10
10
  }
11
+
11
12
  //#endregion
12
- export { stripTemplate };
13
+ export { stripTemplate };
@@ -5,6 +5,7 @@ import { IORecord, InferIO } from "./fnTypes.js";
5
5
  import { Void } from "../../data/wgslTypes.js";
6
6
 
7
7
  //#region src/core/function/tgpuComputeFn.d.ts
8
+
8
9
  /**
9
10
  * Describes a compute entry function signature (its arguments, return type and workgroup size)
10
11
  */
@@ -5,6 +5,7 @@ import { separateBuiltins } from "./ioSchema.js";
5
5
  import { createFnCore } from "./fnCore.js";
6
6
  import { stripTemplate } from "./templateUtils.js";
7
7
  import { shaderStageSlot } from "../slot/internalSlots.js";
8
+
8
9
  //#region src/core/function/tgpuComputeFn.ts
9
10
  /**
10
11
  * Creates a shell of a typed entry function for the compute shader stage. Any function
@@ -30,7 +31,7 @@ function isTgpuComputeFn(value) {
30
31
  return value?.shell?.entryPoint === "compute";
31
32
  }
32
33
  function createComputeFn(shell, workgroupSize, implementation, entryInput) {
33
- const core = createFnCore(implementation, `@compute @workgroup_size(${workgroupSize.join(", ")}) `);
34
+ const core = createFnCore(implementation, "compute", workgroupSize);
34
35
  return {
35
36
  shell,
36
37
  $uses(newExternals) {
@@ -51,5 +52,6 @@ function createComputeFn(shell, workgroupSize, implementation, entryInput) {
51
52
  }
52
53
  };
53
54
  }
55
+
54
56
  //#endregion
55
- export { computeFn, isTgpuComputeFn };
57
+ export { computeFn, isTgpuComputeFn };
@@ -9,6 +9,7 @@ import { BaseData, Void } from "../../data/wgslTypes.js";
9
9
  import { InferGPU } from "../../shared/repr.js";
10
10
 
11
11
  //#region src/core/function/tgpuFn.d.ts
12
+
12
13
  /**
13
14
  * Describes a function signature (its arguments and return type)
14
15
  */