typegpu 0.10.1 → 0.11.0-rc.1

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 (273) hide show
  1. package/_virtual/_rolldown/runtime.js +13 -0
  2. package/builtin.d.ts +50 -0
  3. package/builtin.js +35 -0
  4. package/common/fullScreenTriangle.d.ts +22 -0
  5. package/common/fullScreenTriangle.js +34 -0
  6. package/common/index.d.ts +4 -4
  7. package/common/index.js +8 -7
  8. package/common/writeSoA.d.ts +16 -0
  9. package/common/writeSoA.js +90 -0
  10. package/core/buffer/buffer.d.ts +79 -0
  11. package/core/buffer/buffer.js +246 -0
  12. package/core/buffer/bufferShorthand.d.ts +48 -0
  13. package/core/buffer/bufferShorthand.js +53 -0
  14. package/core/buffer/bufferUsage.d.ts +43 -0
  15. package/core/buffer/bufferUsage.js +165 -0
  16. package/core/constant/tgpuConstant.d.ts +29 -0
  17. package/core/constant/tgpuConstant.js +68 -0
  18. package/core/declare/tgpuDeclare.d.ts +18 -0
  19. package/core/declare/tgpuDeclare.js +39 -0
  20. package/core/function/autoIO.d.ts +38 -0
  21. package/core/function/autoIO.js +85 -0
  22. package/core/function/comptime.d.ts +39 -0
  23. package/core/function/comptime.js +49 -0
  24. package/core/function/createCallableSchema.js +40 -0
  25. package/core/function/dualImpl.js +52 -0
  26. package/core/function/entryInputRouter.js +39 -0
  27. package/core/function/extractArgs.js +204 -0
  28. package/core/function/fnCore.js +90 -0
  29. package/core/function/fnTypes.d.ts +40 -0
  30. package/core/function/ioSchema.d.ts +10 -0
  31. package/core/function/ioSchema.js +51 -0
  32. package/core/function/shelllessImpl.d.ts +28 -0
  33. package/core/function/shelllessImpl.js +21 -0
  34. package/core/function/templateUtils.js +12 -0
  35. package/core/function/tgpuComputeFn.d.ts +48 -0
  36. package/core/function/tgpuComputeFn.js +55 -0
  37. package/core/function/tgpuFn.d.ts +52 -0
  38. package/core/function/tgpuFn.js +168 -0
  39. package/core/function/tgpuFragmentFn.d.ts +72 -0
  40. package/core/function/tgpuFragmentFn.js +63 -0
  41. package/core/function/tgpuVertexFn.d.ts +59 -0
  42. package/core/function/tgpuVertexFn.js +59 -0
  43. package/core/pipeline/applyPipelineState.js +35 -0
  44. package/core/pipeline/computePipeline.d.ts +54 -0
  45. package/core/pipeline/computePipeline.js +227 -0
  46. package/core/pipeline/connectAttachmentToShader.js +24 -0
  47. package/core/pipeline/connectTargetsToShader.js +27 -0
  48. package/core/pipeline/limitsOverflow.js +12 -0
  49. package/core/pipeline/pipelineUtils.js +29 -0
  50. package/core/pipeline/renderPipeline.d.ts +284 -0
  51. package/core/pipeline/renderPipeline.js +489 -0
  52. package/core/pipeline/timeable.d.ts +20 -0
  53. package/core/pipeline/timeable.js +55 -0
  54. package/core/pipeline/typeGuards.js +27 -0
  55. package/core/querySet/querySet.d.ts +20 -0
  56. package/core/querySet/querySet.js +104 -0
  57. package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +59 -0
  58. package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +94 -0
  59. package/core/resolve/externals.d.ts +8 -0
  60. package/core/resolve/externals.js +56 -0
  61. package/core/resolve/namespace.d.ts +38 -0
  62. package/core/resolve/namespace.js +39 -0
  63. package/core/resolve/resolveData.js +144 -0
  64. package/core/resolve/stitch.js +23 -0
  65. package/core/resolve/tgpuResolve.d.ts +153 -0
  66. package/core/resolve/tgpuResolve.js +66 -0
  67. package/core/root/configurableImpl.js +17 -0
  68. package/core/root/init.d.ts +64 -0
  69. package/core/root/init.js +464 -0
  70. package/core/root/rootTypes.d.ts +642 -0
  71. package/core/sampler/sampler.d.ts +31 -0
  72. package/core/sampler/sampler.js +116 -0
  73. package/core/simulate/tgpuSimulate.d.ts +36 -0
  74. package/core/simulate/tgpuSimulate.js +74 -0
  75. package/core/slot/accessor.d.ts +9 -0
  76. package/core/slot/accessor.js +95 -0
  77. package/core/slot/internalSlots.js +5 -0
  78. package/core/slot/lazy.d.ts +6 -0
  79. package/core/slot/lazy.js +40 -0
  80. package/core/slot/slot.d.ts +6 -0
  81. package/core/slot/slot.js +39 -0
  82. package/core/slot/slotTypes.d.ts +92 -0
  83. package/core/slot/slotTypes.js +19 -0
  84. package/core/texture/externalTexture.d.ts +6 -0
  85. package/core/texture/externalTexture.js +47 -0
  86. package/core/texture/texture.d.ts +114 -0
  87. package/core/texture/texture.js +314 -0
  88. package/core/texture/textureFormats.d.ts +29 -0
  89. package/core/texture/textureFormats.js +97 -0
  90. package/core/texture/textureProps.d.ts +11 -0
  91. package/core/texture/textureUtils.js +222 -0
  92. package/core/texture/usageExtension.d.ts +21 -0
  93. package/core/texture/usageExtension.js +19 -0
  94. package/core/unroll/tgpuUnroll.d.ts +68 -0
  95. package/core/unroll/tgpuUnroll.js +94 -0
  96. package/core/valueProxyUtils.js +42 -0
  97. package/core/variable/tgpuVariable.d.ts +38 -0
  98. package/core/variable/tgpuVariable.js +99 -0
  99. package/core/vertexLayout/connectAttributesToShader.js +57 -0
  100. package/core/vertexLayout/vertexAttribute.d.ts +29 -0
  101. package/core/vertexLayout/vertexLayout.d.ts +19 -0
  102. package/core/vertexLayout/vertexLayout.js +103 -0
  103. package/data/alignIO.js +14 -0
  104. package/data/alignmentOf.d.ts +9 -0
  105. package/data/alignmentOf.js +86 -0
  106. package/data/array.d.ts +26 -0
  107. package/data/array.js +46 -0
  108. package/data/atomic.d.ts +15 -0
  109. package/data/atomic.js +24 -0
  110. package/data/attributes.d.ts +121 -0
  111. package/data/attributes.js +145 -0
  112. package/data/autoStruct.d.ts +1 -0
  113. package/data/autoStruct.js +81 -0
  114. package/data/compiledIO.js +228 -0
  115. package/data/dataIO.js +556 -0
  116. package/data/dataTypes.d.ts +115 -0
  117. package/data/dataTypes.js +100 -0
  118. package/data/deepEqual.d.ts +25 -0
  119. package/data/deepEqual.js +56 -0
  120. package/data/disarray.d.ts +32 -0
  121. package/data/disarray.js +50 -0
  122. package/data/getLongestContiguousPrefix.d.ts +9 -0
  123. package/data/getLongestContiguousPrefix.js +13 -0
  124. package/data/index.d.ts +26 -4
  125. package/data/index.js +36 -9
  126. package/data/instanceToSchema.d.ts +33 -0
  127. package/data/isContiguous.d.ts +9 -0
  128. package/data/isContiguous.js +13 -0
  129. package/data/matrix.d.ts +124 -0
  130. package/data/matrix.js +531 -0
  131. package/data/numberOps.js +23 -0
  132. package/data/numeric.d.ts +81 -0
  133. package/data/numeric.js +221 -0
  134. package/data/offsetUtils.d.ts +33 -0
  135. package/data/offsetUtils.js +165 -0
  136. package/data/offsets.js +34 -0
  137. package/data/partialIO.js +113 -0
  138. package/data/ptr.d.ts +11 -0
  139. package/data/ptr.js +44 -0
  140. package/data/ref.d.ts +34 -0
  141. package/data/ref.js +94 -0
  142. package/data/sampler.d.ts +107 -0
  143. package/data/sampler.js +24 -0
  144. package/data/schemaCallWrapper.js +30 -0
  145. package/data/schemaMemoryLayout.js +198 -0
  146. package/data/sizeOf.d.ts +9 -0
  147. package/data/sizeOf.js +13 -0
  148. package/data/snippet.d.ts +26 -0
  149. package/data/snippet.js +70 -0
  150. package/data/struct.d.ts +17 -0
  151. package/data/struct.js +44 -0
  152. package/data/texture.d.ts +292 -0
  153. package/{texture-BagDrrks.js → data/texture.js} +6 -5
  154. package/data/unstruct.d.ts +24 -0
  155. package/data/unstruct.js +41 -0
  156. package/data/vector.d.ts +191 -0
  157. package/data/vector.js +239 -0
  158. package/data/vectorImpl.js +515 -0
  159. package/data/vectorOps.js +681 -0
  160. package/data/vertexFormatData.d.ts +190 -0
  161. package/data/vertexFormatData.js +109 -0
  162. package/data/wgslTypes.d.ts +924 -0
  163. package/data/wgslTypes.js +222 -0
  164. package/errors.d.ts +44 -0
  165. package/errors.js +131 -0
  166. package/execMode.js +49 -0
  167. package/extension.d.ts +11 -0
  168. package/extension.js +16 -0
  169. package/getGPUValue.js +7 -0
  170. package/index.d.ts +42 -243
  171. package/index.js +21 -6320
  172. package/indexNamedExports.d.ts +40 -0
  173. package/mathUtils.js +12 -0
  174. package/memo.js +22 -0
  175. package/nameRegistry.d.ts +30 -0
  176. package/nameRegistry.js +447 -0
  177. package/package.js +4 -0
  178. package/package.json +26 -26
  179. package/resolutionCtx.d.ts +19 -0
  180. package/resolutionCtx.js +612 -0
  181. package/shared/env.js +12 -0
  182. package/shared/generators.js +13 -0
  183. package/shared/meta.d.ts +39 -0
  184. package/shared/meta.js +61 -0
  185. package/shared/repr.d.ts +138 -0
  186. package/shared/stringify.js +20 -0
  187. package/shared/symbols.d.ts +70 -0
  188. package/shared/symbols.js +48 -0
  189. package/shared/utilityTypes.d.ts +33 -0
  190. package/shared/utilityTypes.js +6 -0
  191. package/shared/vertexFormat.d.ts +70 -0
  192. package/shared/vertexFormat.js +63 -0
  193. package/std/array.d.ts +7 -0
  194. package/std/array.js +25 -0
  195. package/std/atomic.d.ts +19 -0
  196. package/std/atomic.js +111 -0
  197. package/std/bitcast.d.ts +10 -0
  198. package/std/bitcast.js +41 -0
  199. package/std/boolean.d.ts +141 -0
  200. package/std/boolean.js +299 -0
  201. package/std/derivative.d.ts +16 -0
  202. package/std/derivative.js +87 -0
  203. package/std/discard.d.ts +6 -0
  204. package/std/discard.js +14 -0
  205. package/std/extensions.d.ts +6 -0
  206. package/std/extensions.js +12 -0
  207. package/std/index.d.ts +17 -4
  208. package/std/index.js +21 -7
  209. package/std/matrix.d.ts +41 -0
  210. package/std/matrix.js +85 -0
  211. package/std/numeric.d.ts +200 -0
  212. package/std/numeric.js +845 -0
  213. package/std/operators.d.ts +56 -0
  214. package/std/operators.js +227 -0
  215. package/std/packing.d.ts +26 -0
  216. package/std/packing.js +84 -0
  217. package/std/range.d.ts +24 -0
  218. package/std/range.js +38 -0
  219. package/std/subgroup.d.ts +47 -0
  220. package/std/subgroup.js +218 -0
  221. package/std/texture.d.ts +117 -0
  222. package/std/texture.js +207 -0
  223. package/tgpu.js +42 -0
  224. package/tgpuBindGroupLayout.d.ts +161 -0
  225. package/tgpuBindGroupLayout.js +272 -0
  226. package/tgpuUnstable.d.ts +48 -0
  227. package/tgpuUnstable.js +64 -0
  228. package/tgsl/accessIndex.js +43 -0
  229. package/tgsl/accessProp.js +115 -0
  230. package/tgsl/consoleLog/deserializers.js +115 -0
  231. package/tgsl/consoleLog/logGenerator.js +84 -0
  232. package/tgsl/consoleLog/serializers.js +223 -0
  233. package/tgsl/consoleLog/types.d.ts +52 -0
  234. package/tgsl/consoleLog/types.js +11 -0
  235. package/tgsl/conversion.js +198 -0
  236. package/tgsl/forOfUtils.js +71 -0
  237. package/tgsl/generationHelpers.d.ts +37 -0
  238. package/tgsl/generationHelpers.js +67 -0
  239. package/tgsl/math.js +43 -0
  240. package/tgsl/shaderGenerator.d.ts +20 -0
  241. package/tgsl/shaderGenerator_members.d.ts +2 -0
  242. package/tgsl/shaderGenerator_members.js +6 -0
  243. package/tgsl/shellless.d.ts +11 -0
  244. package/tgsl/shellless.js +46 -0
  245. package/tgsl/wgslGenerator.d.ts +36 -0
  246. package/tgsl/wgslGenerator.js +639 -0
  247. package/types.d.ts +265 -0
  248. package/types.js +43 -0
  249. package/unwrapper.d.ts +27 -0
  250. package/wgslExtensions.d.ts +5 -0
  251. package/wgslExtensions.js +17 -0
  252. package/builtin-DdtWpk2t.js +0 -818
  253. package/builtin-DdtWpk2t.js.map +0 -1
  254. package/chunk-BYypO7fO.js +0 -18
  255. package/common/index.d.ts.map +0 -1
  256. package/common/index.js.map +0 -1
  257. package/data/index.d.ts.map +0 -1
  258. package/data/index.js.map +0 -1
  259. package/deepEqual-DQxK4vdp.js +0 -413
  260. package/deepEqual-DQxK4vdp.js.map +0 -1
  261. package/extensions-DIVuAfBM.js +0 -2032
  262. package/extensions-DIVuAfBM.js.map +0 -1
  263. package/fullScreenTriangle-CfFyQd_0.js +0 -543
  264. package/fullScreenTriangle-CfFyQd_0.js.map +0 -1
  265. package/index.d.ts.map +0 -1
  266. package/index.js.map +0 -1
  267. package/indexNamedExports-oL6tyaJ9.d.ts +0 -5697
  268. package/indexNamedExports-oL6tyaJ9.d.ts.map +0 -1
  269. package/operators-d-PMVTo7.js +0 -4158
  270. package/operators-d-PMVTo7.js.map +0 -1
  271. package/std/index.d.ts.map +0 -1
  272. package/std/index.js.map +0 -1
  273. package/texture-BagDrrks.js.map +0 -1
@@ -0,0 +1,48 @@
1
+ import { TgpuNamable } from "../../shared/meta.js";
2
+ import { $gpuValueOf, $internal } from "../../shared/symbols.js";
3
+ import { StorageFlag } from "../../extension.js";
4
+ import { BufferWriteOptions, TgpuBuffer, UniformFlag } from "./buffer.js";
5
+ import { BaseData } from "../../data/wgslTypes.js";
6
+ import { Infer, InferGPU, InferInput, InferPartial, InferPatch } from "../../shared/repr.js";
7
+
8
+ //#region src/core/buffer/bufferShorthand.d.ts
9
+ interface TgpuBufferShorthandBase<TData extends BaseData> extends TgpuNamable {
10
+ readonly [$internal]: true;
11
+ write(data: InferInput<TData>, options?: BufferWriteOptions): void;
12
+ /** @deprecated Use {@link patch} instead. */
13
+ writePartial(data: InferPartial<TData>): void;
14
+ patch(data: InferPatch<TData>): void;
15
+ read(): Promise<Infer<TData>>;
16
+ readonly [$gpuValueOf]: InferGPU<TData>;
17
+ }
18
+ interface TgpuMutable<out TData extends BaseData> extends TgpuBufferShorthandBase<TData> {
19
+ readonly resourceType: 'mutable';
20
+ readonly buffer: TgpuBuffer<TData> & StorageFlag;
21
+ /**
22
+ * @deprecated Use `.$` instead, works the same way.
23
+ */
24
+ value: InferGPU<TData>;
25
+ $: InferGPU<TData>;
26
+ }
27
+ interface TgpuReadonly<out TData extends BaseData> extends TgpuBufferShorthandBase<TData> {
28
+ readonly resourceType: 'readonly';
29
+ readonly buffer: TgpuBuffer<TData> & StorageFlag;
30
+ /**
31
+ * @deprecated Use `.$` instead, works the same way.
32
+ */
33
+ readonly value: InferGPU<TData>;
34
+ readonly $: InferGPU<TData>;
35
+ }
36
+ interface TgpuUniform<out TData extends BaseData> extends TgpuBufferShorthandBase<TData> {
37
+ readonly resourceType: 'uniform';
38
+ readonly buffer: TgpuBuffer<TData> & UniformFlag;
39
+ /**
40
+ * @deprecated Use `.$` instead, works the same way.
41
+ */
42
+ readonly value: InferGPU<TData>;
43
+ readonly $: InferGPU<TData>;
44
+ }
45
+ type TgpuBufferShorthand<TData extends BaseData> = TgpuMutable<TData> | TgpuReadonly<TData> | TgpuUniform<TData>;
46
+ declare function isBufferShorthand<TData extends BaseData>(value: unknown): value is TgpuBufferShorthand<TData>;
47
+ //#endregion
48
+ export { TgpuBufferShorthand, TgpuMutable, TgpuReadonly, TgpuUniform, isBufferShorthand };
@@ -0,0 +1,53 @@
1
+ import { $getNameForward, $gpuValueOf, $internal, $resolve } from "../../shared/symbols.js";
2
+ import { getName, setName } from "../../shared/meta.js";
3
+ //#region src/core/buffer/bufferShorthand.ts
4
+ function isBufferShorthand(value) {
5
+ return value instanceof TgpuBufferShorthandImpl;
6
+ }
7
+ var TgpuBufferShorthandImpl = class {
8
+ [$internal] = true;
9
+ [$getNameForward];
10
+ resourceType;
11
+ buffer;
12
+ #usage;
13
+ constructor(resourceType, buffer) {
14
+ this.resourceType = resourceType;
15
+ this.buffer = buffer;
16
+ this[$getNameForward] = buffer;
17
+ this.#usage = this.buffer.as(this.resourceType);
18
+ }
19
+ $name(label) {
20
+ setName(this, label);
21
+ return this;
22
+ }
23
+ write(data, options) {
24
+ this.buffer.write(data, options);
25
+ }
26
+ /** @deprecated Use {@link patch} instead. */
27
+ writePartial(data) {
28
+ this.buffer.writePartial(data);
29
+ }
30
+ patch(data) {
31
+ this.buffer.patch(data);
32
+ }
33
+ read() {
34
+ return this.buffer.read();
35
+ }
36
+ get [$gpuValueOf]() {
37
+ return this.#usage.$;
38
+ }
39
+ get $() {
40
+ return this.#usage.$;
41
+ }
42
+ get value() {
43
+ return this.$;
44
+ }
45
+ toString() {
46
+ return `${this.resourceType}BufferShorthand:${getName(this) ?? "<unnamed>"}`;
47
+ }
48
+ [$resolve](ctx) {
49
+ return ctx.resolve(this.#usage);
50
+ }
51
+ };
52
+ //#endregion
53
+ export { TgpuBufferShorthandImpl, isBufferShorthand };
@@ -0,0 +1,43 @@
1
+ import { TgpuNamable } from "../../shared/meta.js";
2
+ import { $gpuValueOf, $internal, $repr } from "../../shared/symbols.js";
3
+ import { TgpuBuffer, UniformFlag } from "./buffer.js";
4
+ import { BindableBufferUsage } from "../../types.js";
5
+ import { BaseData } from "../../data/wgslTypes.js";
6
+ import { Infer, InferGPU } from "../../shared/repr.js";
7
+
8
+ //#region src/core/buffer/bufferUsage.d.ts
9
+ interface TgpuBufferUsage<TData extends BaseData = BaseData, TUsage extends BindableBufferUsage = BindableBufferUsage> {
10
+ readonly resourceType: 'buffer-usage';
11
+ readonly usage: TUsage;
12
+ readonly [$repr]: Infer<TData>;
13
+ readonly [$gpuValueOf]: InferGPU<TData>;
14
+ /**
15
+ * @deprecated Use `.$` instead, works the same way.
16
+ */
17
+ value: InferGPU<TData>;
18
+ $: InferGPU<TData>;
19
+ readonly [$internal]: {
20
+ readonly dataType: TData;
21
+ };
22
+ }
23
+ interface TgpuBufferUniform<TData extends BaseData> extends TgpuBufferUsage<TData, 'uniform'> {
24
+ /**
25
+ * @deprecated Use `.$` instead, works the same way.
26
+ */
27
+ readonly value: InferGPU<TData>;
28
+ readonly $: InferGPU<TData>;
29
+ }
30
+ interface TgpuBufferReadonly<TData extends BaseData> extends TgpuBufferUsage<TData, 'readonly'> {
31
+ /**
32
+ * @deprecated Use `.$` instead, works the same way.
33
+ */
34
+ readonly value: InferGPU<TData>;
35
+ readonly $: InferGPU<TData>;
36
+ }
37
+ interface TgpuFixedBufferUsage<TData extends BaseData> extends TgpuNamable {
38
+ readonly buffer: TgpuBuffer<TData>;
39
+ }
40
+ interface TgpuBufferMutable<TData extends BaseData> extends TgpuBufferUsage<TData, 'mutable'> {}
41
+ declare function isUsableAsUniform<T extends TgpuBuffer<BaseData>>(buffer: T): buffer is T & UniformFlag;
42
+ //#endregion
43
+ export { TgpuBufferMutable, TgpuBufferReadonly, TgpuBufferUniform, TgpuBufferUsage, TgpuFixedBufferUsage, isUsableAsUniform };
@@ -0,0 +1,165 @@
1
+ import { $getNameForward, $gpuValueOf, $internal, $ownSnippet, $resolve } from "../../shared/symbols.js";
2
+ import { getName, setName } from "../../shared/meta.js";
3
+ import { isNaturallyEphemeral } from "../../data/wgslTypes.js";
4
+ import { snip } from "../../data/snippet.js";
5
+ import { IllegalBufferAccessError } from "../../errors.js";
6
+ import { getExecMode, inCodegenMode, isInsideTgpuFn } from "../../execMode.js";
7
+ import { schemaCallWrapper } from "../../data/schemaCallWrapper.js";
8
+ import { assertExhaustive } from "../../shared/utilityTypes.js";
9
+ import { valueProxyHandler } from "../valueProxyUtils.js";
10
+ import { isUsableAsStorage } from "../../extension.js";
11
+ //#region src/core/buffer/bufferUsage.ts
12
+ function isUsableAsUniform(buffer) {
13
+ return !!buffer.usableAsUniform;
14
+ }
15
+ const usageToVarTemplateMap = {
16
+ uniform: "uniform",
17
+ mutable: "storage, read_write",
18
+ readonly: "storage, read"
19
+ };
20
+ var TgpuFixedBufferImpl = class {
21
+ resourceType = "buffer-usage";
22
+ usage;
23
+ buffer;
24
+ [$internal];
25
+ [$getNameForward];
26
+ constructor(usage, buffer) {
27
+ this.usage = usage;
28
+ this.buffer = buffer;
29
+ this[$internal] = { dataType: buffer.dataType };
30
+ this[$getNameForward] = buffer;
31
+ }
32
+ $name(label) {
33
+ setName(this, label);
34
+ return this;
35
+ }
36
+ [$resolve](ctx) {
37
+ const dataType = this.buffer.dataType;
38
+ const id = ctx.getUniqueName(this);
39
+ const { group, binding } = ctx.allocateFixedEntry(this.usage === "uniform" ? { uniform: dataType } : {
40
+ storage: dataType,
41
+ access: this.usage
42
+ }, this.buffer);
43
+ const usage = usageToVarTemplateMap[this.usage];
44
+ ctx.addDeclaration(`@group(${group}) @binding(${binding}) var<${usage}> ${id}: ${ctx.resolve(dataType).value};`);
45
+ return snip(id, dataType, isNaturallyEphemeral(dataType) ? "runtime" : this.usage);
46
+ }
47
+ toString() {
48
+ return `${this.usage}:${getName(this) ?? "<unnamed>"}`;
49
+ }
50
+ get [$gpuValueOf]() {
51
+ const dataType = this.buffer.dataType;
52
+ const usage = this.usage;
53
+ return new Proxy({
54
+ [$internal]: true,
55
+ get [$ownSnippet]() {
56
+ return snip(this, dataType, isNaturallyEphemeral(dataType) ? "runtime" : usage);
57
+ },
58
+ [$resolve]: (ctx) => ctx.resolve(this),
59
+ toString: () => `${this.usage}:${getName(this) ?? "<unnamed>"}.$`
60
+ }, valueProxyHandler);
61
+ }
62
+ get $() {
63
+ const mode = getExecMode();
64
+ const insideTgpuFn = isInsideTgpuFn();
65
+ if (mode.type === "normal") throw new IllegalBufferAccessError(insideTgpuFn ? `Cannot access ${String(this.buffer)}. TypeGPU functions that depends on GPU resources need to be part of a compute dispatch, draw call or simulation` : ".$ is inaccessible during normal JS execution. Try `.read()`");
66
+ if (mode.type === "codegen") return this[$gpuValueOf];
67
+ if (mode.type === "simulate") {
68
+ if (!mode.buffers.has(this.buffer)) mode.buffers.set(this.buffer, schemaCallWrapper(this.buffer.dataType, this.buffer.initial));
69
+ return mode.buffers.get(this.buffer);
70
+ }
71
+ return assertExhaustive(mode, "bufferUsage.ts#TgpuFixedBufferImpl/$");
72
+ }
73
+ get value() {
74
+ return this.$;
75
+ }
76
+ set $(value) {
77
+ const mode = getExecMode();
78
+ const insideTgpuFn = isInsideTgpuFn();
79
+ if (mode.type === "normal") throw new IllegalBufferAccessError(insideTgpuFn ? `Cannot access ${String(this.buffer)}. TypeGPU functions that depends on GPU resources need to be part of a compute dispatch, draw call or simulation` : ".$ is inaccessible during normal JS execution. Try `.write()`");
80
+ if (mode.type === "codegen") throw new Error("Unreachable bufferUsage.ts#TgpuFixedBufferImpl/$");
81
+ if (mode.type === "simulate") {
82
+ mode.buffers.set(this.buffer, value);
83
+ return;
84
+ }
85
+ assertExhaustive(mode, "bufferUsage.ts#TgpuFixedBufferImpl/$");
86
+ }
87
+ set value(value) {
88
+ this.$ = value;
89
+ }
90
+ };
91
+ var TgpuLaidOutBufferImpl = class {
92
+ [$internal];
93
+ resourceType = "buffer-usage";
94
+ usage;
95
+ dataType;
96
+ #membership;
97
+ constructor(usage, dataType, membership) {
98
+ this[$internal] = { dataType };
99
+ this.usage = usage;
100
+ this.dataType = dataType;
101
+ this.#membership = membership;
102
+ setName(this, membership.key);
103
+ }
104
+ [$resolve](ctx) {
105
+ const id = ctx.getUniqueName(this);
106
+ const group = ctx.allocateLayoutEntry(this.#membership.layout);
107
+ const usage = usageToVarTemplateMap[this.usage];
108
+ ctx.addDeclaration(`@group(${group}) @binding(${this.#membership.idx}) var<${usage}> ${id}: ${ctx.resolve(this.dataType).value};`);
109
+ return snip(id, this.dataType, isNaturallyEphemeral(this.dataType) ? "runtime" : this.usage);
110
+ }
111
+ toString() {
112
+ return `${this.usage}:${getName(this) ?? "<unnamed>"}`;
113
+ }
114
+ get [$gpuValueOf]() {
115
+ const schema = this.dataType;
116
+ const usage = this.usage;
117
+ return new Proxy({
118
+ [$internal]: true,
119
+ get [$ownSnippet]() {
120
+ return snip(this, schema, isNaturallyEphemeral(schema) ? "runtime" : usage);
121
+ },
122
+ [$resolve]: (ctx) => ctx.resolve(this),
123
+ toString: () => `${this.usage}:${getName(this) ?? "<unnamed>"}.$`
124
+ }, valueProxyHandler);
125
+ }
126
+ get $() {
127
+ if (inCodegenMode()) return this[$gpuValueOf];
128
+ throw new Error("Direct access to buffer values is possible only as part of a compute dispatch or draw call. Try .read() or .write() instead");
129
+ }
130
+ get value() {
131
+ return this.$;
132
+ }
133
+ };
134
+ const mutableUsageMap = /* @__PURE__ */ new WeakMap();
135
+ function mutable(buffer) {
136
+ if (!isUsableAsStorage(buffer)) throw new Error(`Cannot call as('mutable') on ${buffer}, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);
137
+ let usage = mutableUsageMap.get(buffer);
138
+ if (!usage) {
139
+ usage = new TgpuFixedBufferImpl("mutable", buffer);
140
+ mutableUsageMap.set(buffer, usage);
141
+ }
142
+ return usage;
143
+ }
144
+ const readonlyUsageMap = /* @__PURE__ */ new WeakMap();
145
+ function readonly(buffer) {
146
+ if (!isUsableAsStorage(buffer)) throw new Error(`Cannot call as('readonly') on ${buffer}, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);
147
+ let usage = readonlyUsageMap.get(buffer);
148
+ if (!usage) {
149
+ usage = new TgpuFixedBufferImpl("readonly", buffer);
150
+ readonlyUsageMap.set(buffer, usage);
151
+ }
152
+ return usage;
153
+ }
154
+ const uniformUsageMap = /* @__PURE__ */ new WeakMap();
155
+ function uniform(buffer) {
156
+ if (!isUsableAsUniform(buffer)) throw new Error(`Cannot call as('uniform') on ${buffer}, as it is not allowed to be used as a uniform. To allow it, call .$usage('uniform') when creating the buffer.`);
157
+ let usage = uniformUsageMap.get(buffer);
158
+ if (!usage) {
159
+ usage = new TgpuFixedBufferImpl("uniform", buffer);
160
+ uniformUsageMap.set(buffer, usage);
161
+ }
162
+ return usage;
163
+ }
164
+ //#endregion
165
+ export { TgpuLaidOutBufferImpl, isUsableAsUniform, mutable, readonly, uniform };
@@ -0,0 +1,29 @@
1
+ import { TgpuNamable } from "../../shared/meta.js";
2
+ import { $gpuValueOf, $internal } from "../../shared/symbols.js";
3
+ import { AnyWgslData, BaseData, WgslArray } from "../../data/wgslTypes.js";
4
+ import { InferGPU } from "../../shared/repr.js";
5
+ import { AnyData } from "../../data/dataTypes.js";
6
+
7
+ //#region src/core/constant/tgpuConstant.d.ts
8
+ type DeepReadonly<T> = T extends {
9
+ [$internal]: unknown;
10
+ } ? T : T extends unknown[] ? ReadonlyArray<DeepReadonly<T[number]>> : T extends Record<string, unknown> ? { readonly [K in keyof T]: DeepReadonly<T[K]> } : T;
11
+ interface TgpuConst<TDataType extends BaseData = BaseData> extends TgpuNamable {
12
+ readonly resourceType: 'const';
13
+ readonly [$gpuValueOf]: DeepReadonly<InferGPU<TDataType>>;
14
+ /**
15
+ * @deprecated Use `.$` instead, works the same way.
16
+ */
17
+ readonly value: DeepReadonly<InferGPU<TDataType>>;
18
+ readonly $: DeepReadonly<InferGPU<TDataType>>;
19
+ readonly [$internal]: {
20
+ /** Makes it differentiable on the type level. Does not exist at runtime. */dataType?: TDataType;
21
+ };
22
+ }
23
+ /**
24
+ * Creates a module constant with specified value.
25
+ */
26
+ declare function constant<TDataType extends AnyData>(dataType: TDataType, value: InferGPU<TDataType>): TgpuConst<TDataType>;
27
+ declare function constant<TElement extends AnyWgslData>(dataType: (elementCount: number) => WgslArray<TElement>, value: InferGPU<WgslArray<TElement>>): TgpuConst<WgslArray<TElement>>;
28
+ //#endregion
29
+ export { TgpuConst, constant };
@@ -0,0 +1,68 @@
1
+ import { $gpuValueOf, $internal, $ownSnippet, $resolve } from "../../shared/symbols.js";
2
+ import { getName, setName } from "../../shared/meta.js";
3
+ import { isNaturallyEphemeral } from "../../data/wgslTypes.js";
4
+ import { isData } from "../../data/dataTypes.js";
5
+ import { snip } from "../../data/snippet.js";
6
+ import { inCodegenMode } from "../../execMode.js";
7
+ import { valueProxyHandler } from "../valueProxyUtils.js";
8
+ //#region src/core/constant/tgpuConstant.ts
9
+ function constant(dataType, value) {
10
+ if (!isData(dataType)) {
11
+ if (!Array.isArray(value)) throw new Error(`Expected an array value for a partially-applied array schema, but received: ${typeof value}.`);
12
+ return new TgpuConstImpl(dataType(value.length), value);
13
+ }
14
+ return new TgpuConstImpl(dataType, value);
15
+ }
16
+ function deepFreeze(object) {
17
+ const propNames = Reflect.ownKeys(object);
18
+ for (const name of propNames) {
19
+ const value = object[name];
20
+ if (value && typeof value === "object" || typeof value === "function") deepFreeze(value);
21
+ }
22
+ return Object.freeze(object);
23
+ }
24
+ var TgpuConstImpl = class {
25
+ [$internal] = {};
26
+ resourceType;
27
+ dataType;
28
+ #value;
29
+ constructor(dataType, value) {
30
+ this.resourceType = "const";
31
+ this.dataType = dataType;
32
+ this.#value = value && typeof value === "object" ? deepFreeze(value) : value;
33
+ }
34
+ $name(label) {
35
+ setName(this, label);
36
+ return this;
37
+ }
38
+ [$resolve](ctx) {
39
+ const id = ctx.getUniqueName(this);
40
+ const resolvedDataType = ctx.resolve(this.dataType).value;
41
+ const resolvedValue = ctx.resolve(this.#value, this.dataType).value;
42
+ ctx.addDeclaration(`const ${id}: ${resolvedDataType} = ${resolvedValue};`);
43
+ return snip(id, this.dataType, isNaturallyEphemeral(this.dataType) ? "constant" : "constant-tgpu-const-ref");
44
+ }
45
+ toString() {
46
+ return `const:${getName(this) ?? "<unnamed>"}`;
47
+ }
48
+ get [$gpuValueOf]() {
49
+ const dataType = this.dataType;
50
+ return new Proxy({
51
+ [$internal]: true,
52
+ get [$ownSnippet]() {
53
+ return snip(this, dataType, isNaturallyEphemeral(dataType) ? "constant" : "constant-tgpu-const-ref");
54
+ },
55
+ [$resolve]: (ctx) => ctx.resolve(this),
56
+ toString: () => `const:${getName(this) ?? "<unnamed>"}.$`
57
+ }, valueProxyHandler);
58
+ }
59
+ get $() {
60
+ if (inCodegenMode()) return this[$gpuValueOf];
61
+ return this.#value;
62
+ }
63
+ get value() {
64
+ return this.$;
65
+ }
66
+ };
67
+ //#endregion
68
+ export { constant };
@@ -0,0 +1,18 @@
1
+ //#region src/core/declare/tgpuDeclare.d.ts
2
+ /**
3
+ * Extra declaration that shall be included in final WGSL code,
4
+ * when resolving objects that use it.
5
+ */
6
+ interface TgpuDeclare {
7
+ $uses(dependencyMap: Record<string, unknown>): this;
8
+ }
9
+ /**
10
+ * Allows defining extra declarations that shall be included in the final WGSL code,
11
+ * when resolving objects that use them.
12
+ *
13
+ * Using this API is generally discouraged, as it shouldn't be necessary in any common scenario.
14
+ * It was developed to ensure full compatibility of TypeGPU programs with current and future versions of WGSL.
15
+ */
16
+ declare function declare(declaration: string): TgpuDeclare;
17
+ //#endregion
18
+ export { TgpuDeclare, declare };
@@ -0,0 +1,39 @@
1
+ import { $internal, $resolve } from "../../shared/symbols.js";
2
+ import { Void } from "../../data/wgslTypes.js";
3
+ import { snip } from "../../data/snippet.js";
4
+ import { applyExternals, replaceExternalsInWgsl } from "../resolve/externals.js";
5
+ //#region src/core/declare/tgpuDeclare.ts
6
+ /**
7
+ * Allows defining extra declarations that shall be included in the final WGSL code,
8
+ * when resolving objects that use them.
9
+ *
10
+ * Using this API is generally discouraged, as it shouldn't be necessary in any common scenario.
11
+ * It was developed to ensure full compatibility of TypeGPU programs with current and future versions of WGSL.
12
+ */
13
+ function declare(declaration) {
14
+ return new TgpuDeclareImpl(declaration);
15
+ }
16
+ var TgpuDeclareImpl = class {
17
+ [$internal] = true;
18
+ #externalsToApply = [];
19
+ #declaration;
20
+ constructor(declaration) {
21
+ this.#declaration = declaration;
22
+ }
23
+ $uses(dependencyMap) {
24
+ this.#externalsToApply.push(dependencyMap);
25
+ return this;
26
+ }
27
+ [$resolve](ctx) {
28
+ const externalMap = {};
29
+ for (const externals of this.#externalsToApply) applyExternals(externalMap, externals);
30
+ const replacedDeclaration = replaceExternalsInWgsl(ctx, externalMap, this.#declaration);
31
+ ctx.addDeclaration(replacedDeclaration);
32
+ return snip("", Void, "constant");
33
+ }
34
+ toString() {
35
+ return `declare: ${this.#declaration}`;
36
+ }
37
+ };
38
+ //#endregion
39
+ export { declare };
@@ -0,0 +1,38 @@
1
+ import { Assume, RemoveIndexSignature } from "../../shared/utilityTypes.js";
2
+ import { BuiltinClipDistances, BuiltinFragDepth, BuiltinFrontFacing, BuiltinInstanceIndex, BuiltinPosition, BuiltinPrimitiveIndex, BuiltinSampleIndex, BuiltinSampleMask, BuiltinSubgroupInvocationId, BuiltinSubgroupSize, BuiltinVertexIndex, OmitBuiltins } from "../../builtin.js";
3
+ import { BaseIOData } from "./fnTypes.js";
4
+ import { TgpuVertexAttrib } from "../../shared/vertexFormat.js";
5
+ import { FormatToWGSLType } from "../../data/vertexFormatData.js";
6
+ import { v4f } from "../../data/wgslTypes.js";
7
+ import { InferGPU, InferGPURecord, InferRecord } from "../../shared/repr.js";
8
+
9
+ //#region src/core/function/autoIO.d.ts
10
+ type AnyAutoCustoms = Record<string, InferGPU<BaseIOData>>;
11
+ declare const builtinVertexIn: {
12
+ readonly $vertexIndex: BuiltinVertexIndex;
13
+ readonly $instanceIndex: BuiltinInstanceIndex;
14
+ };
15
+ type AutoVertexIn<T extends AnyAutoCustoms> = RemoveIndexSignature<T> & InferRecord<typeof builtinVertexIn>;
16
+ type _AutoVertexIn<T> = AutoVertexIn<{ [Key in keyof T]: T[Key] extends TgpuVertexAttrib ? InferGPU<FormatToWGSLType<T[Key]['format']>> : Assume<T[Key], InferGPU<BaseIOData>> }>;
17
+ declare const builtinVertexOut: {
18
+ readonly $clipDistances: BuiltinClipDistances;
19
+ readonly $position: BuiltinPosition;
20
+ };
21
+ type AutoVertexOut<T extends AnyAutoCustoms> = OmitBuiltins<T> & Partial<InferGPURecord<typeof builtinVertexOut>>;
22
+ declare const builtinFragmentIn: {
23
+ readonly $position: BuiltinPosition;
24
+ readonly $frontFacing: BuiltinFrontFacing;
25
+ readonly $primitiveIndex: BuiltinPrimitiveIndex;
26
+ readonly $sampleIndex: BuiltinSampleIndex;
27
+ readonly $sampleMask: BuiltinSampleMask;
28
+ readonly $subgroupInvocationId: BuiltinSubgroupInvocationId;
29
+ readonly $subgroupSize: BuiltinSubgroupSize;
30
+ };
31
+ type AutoFragmentIn<T extends AnyAutoCustoms> = RemoveIndexSignature<T> & InferRecord<typeof builtinFragmentIn>;
32
+ declare const builtinFragmentOut: {
33
+ readonly $fragDepth: BuiltinFragDepth;
34
+ readonly $sampleMask: BuiltinSampleMask;
35
+ };
36
+ type AutoFragmentOut<T extends undefined | v4f | AnyAutoCustoms> = T extends undefined | v4f ? T : T & Partial<InferGPURecord<typeof builtinFragmentOut>>;
37
+ //#endregion
38
+ export { AnyAutoCustoms, AutoFragmentIn, AutoFragmentOut, AutoVertexIn, AutoVertexOut, _AutoVertexIn };
@@ -0,0 +1,85 @@
1
+ import { $internal, $resolve } from "../../shared/symbols.js";
2
+ import { getName, setName } from "../../shared/meta.js";
3
+ import { vec4f } from "../../data/vector.js";
4
+ import { AutoStruct } from "../../data/autoStruct.js";
5
+ import { createFnCore } from "./fnCore.js";
6
+ import { shaderStageSlot } from "../slot/internalSlots.js";
7
+ import { builtin } from "../../builtin.js";
8
+ //#region src/core/function/autoIO.ts
9
+ const builtinVertexIn = {
10
+ $vertexIndex: builtin.vertexIndex,
11
+ $instanceIndex: builtin.instanceIndex
12
+ };
13
+ const builtinVertexOut = {
14
+ $clipDistances: builtin.clipDistances,
15
+ $position: builtin.position
16
+ };
17
+ const builtinFragmentIn = {
18
+ $position: builtin.position,
19
+ $frontFacing: builtin.frontFacing,
20
+ $primitiveIndex: builtin.primitiveIndex,
21
+ $sampleIndex: builtin.sampleIndex,
22
+ $sampleMask: builtin.sampleMask,
23
+ $subgroupInvocationId: builtin.subgroupInvocationId,
24
+ $subgroupSize: builtin.subgroupSize
25
+ };
26
+ const builtinFragmentOut = {
27
+ $fragDepth: builtin.fragDepth,
28
+ $sampleMask: builtin.sampleMask
29
+ };
30
+ /**
31
+ * Only used internally. Meant to be recreated on every resolution.
32
+ */
33
+ var AutoFragmentFn = class {
34
+ #core;
35
+ autoIn;
36
+ autoOut;
37
+ constructor(impl, varyings, locations) {
38
+ if (!getName(impl)) setName(impl, "fragmentFn");
39
+ this.#core = createFnCore(impl, "@fragment ");
40
+ this.autoIn = new AutoStruct({
41
+ ...builtinFragmentIn,
42
+ ...varyings
43
+ }, void 0, locations);
44
+ setName(this.autoIn, "FragmentIn");
45
+ this.autoOut = new AutoStruct(builtinFragmentOut, vec4f);
46
+ setName(this.autoOut, "FragmentOut");
47
+ }
48
+ toString() {
49
+ return "autoFragmentFn";
50
+ }
51
+ [$resolve](ctx) {
52
+ return ctx.withSlots([[shaderStageSlot, "fragment"]], () => this.#core.resolve(ctx, [this.autoIn], this.autoOut));
53
+ }
54
+ };
55
+ AutoFragmentFn.prototype[$internal] = true;
56
+ AutoFragmentFn.prototype.resourceType = "auto-fragment-fn";
57
+ /**
58
+ * Only used internally. Meant to be recreated on every resolution.
59
+ */
60
+ var AutoVertexFn = class {
61
+ #core;
62
+ autoIn;
63
+ autoOut;
64
+ constructor(impl, attribs, locations) {
65
+ if (!getName(impl)) setName(impl, "vertexFn");
66
+ this.#core = createFnCore(impl, "@vertex ");
67
+ this.autoIn = new AutoStruct({
68
+ ...builtinVertexIn,
69
+ ...attribs
70
+ }, void 0, locations);
71
+ setName(this.autoIn, "VertexIn");
72
+ this.autoOut = new AutoStruct(builtinVertexOut, void 0);
73
+ setName(this.autoOut, "VertexOut");
74
+ }
75
+ toString() {
76
+ return "autoVertexFn";
77
+ }
78
+ [$resolve](ctx) {
79
+ return ctx.withSlots([[shaderStageSlot, "vertex"]], () => this.#core.resolve(ctx, [this.autoIn], this.autoOut));
80
+ }
81
+ };
82
+ AutoVertexFn.prototype[$internal] = true;
83
+ AutoVertexFn.prototype.resourceType = "auto-vertex-fn";
84
+ //#endregion
85
+ export { AutoFragmentFn, AutoVertexFn };
@@ -0,0 +1,39 @@
1
+ import { TgpuNamable } from "../../shared/meta.js";
2
+ import { $getNameForward, $internal } from "../../shared/symbols.js";
3
+ import { DualFn } from "../../types.js";
4
+
5
+ //#region src/core/function/comptime.d.ts
6
+ type AnyFn = (...args: never[]) => unknown;
7
+ type TgpuComptime<T extends AnyFn = AnyFn> = DualFn<T> & TgpuNamable & {
8
+ [$getNameForward]: unknown;
9
+ [$internal]: {
10
+ isComptime: true;
11
+ };
12
+ };
13
+ /**
14
+ * Creates a version of `func` that can called safely in a TypeGPU function to
15
+ * precompute and inject a value into the final shader code.
16
+ *
17
+ * Note how the function passed into `comptime` doesn't have to be marked with
18
+ * 'use gpu'. That's because the function doesn't execute on the GPU, it gets
19
+ * executed before the shader code gets sent to the GPU.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const color = tgpu.comptime((int: number) => {
24
+ * const r = (int >> 16) & 0xff;
25
+ * const g = (int >> 8) & 0xff;
26
+ * const b = int & 0xff;
27
+ * return d.vec3f(r / 255, g / 255, b / 255);
28
+ * });
29
+ *
30
+ * const material = (diffuse: d.v3f): d.v3f => {
31
+ * 'use gpu';
32
+ * const albedo = color(0xff00ff);
33
+ * return albedo.mul(diffuse);
34
+ * };
35
+ * ```
36
+ */
37
+ declare function comptime<T extends (...args: never[]) => unknown>(func: T): TgpuComptime<T>;
38
+ //#endregion
39
+ export { TgpuComptime, comptime };