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
package/types.d.ts ADDED
@@ -0,0 +1,265 @@
1
+ import { $cast, $gpuCallable, $internal } from "./shared/symbols.js";
2
+ import { MapValueToSnippet, ResolvedSnippet, Snippet } from "./data/snippet.js";
3
+ import { TgpuBufferUsage } from "./core/buffer/bufferUsage.js";
4
+ import { SeparatedEntryArgs } from "./core/function/fnTypes.js";
5
+ import { TgpuComputeFn } from "./core/function/tgpuComputeFn.js";
6
+ import { TgpuVar } from "./core/variable/tgpuVariable.js";
7
+ import { Eventual, SlotValuePair, TgpuAccessor, TgpuSlot } from "./core/slot/slotTypes.js";
8
+ import { TgpuComputePipeline } from "./core/pipeline/computePipeline.js";
9
+ import { TgpuFragmentFn } from "./core/function/tgpuFragmentFn.js";
10
+ import { TgpuVertexFn } from "./core/function/tgpuVertexFn.js";
11
+ import { TgpuRenderPipeline } from "./core/pipeline/renderPipeline.js";
12
+ import { TgpuSampler } from "./core/sampler/sampler.js";
13
+ import { TgpuExternalTexture } from "./core/texture/externalTexture.js";
14
+ import { TgpuBindGroupLayout, TgpuLayoutEntry } from "./tgpuBindGroupLayout.js";
15
+ import { ShaderGenerator } from "./tgsl/shaderGenerator.js";
16
+ import { TgpuBuffer } from "./core/buffer/buffer.js";
17
+ import { TgpuDeclare } from "./core/declare/tgpuDeclare.js";
18
+ import { TgpuFn } from "./core/function/tgpuFn.js";
19
+ import { WgslExtension } from "./wgslExtensions.js";
20
+ import { AnyMatInstance, AnyVecInstance, BaseData } from "./data/wgslTypes.js";
21
+ import { TgpuTexture, TgpuTextureView } from "./core/texture/texture.js";
22
+ import { Infer } from "./shared/repr.js";
23
+ import { AnyData, UnknownData } from "./data/dataTypes.js";
24
+ import { TgpuConst } from "./core/constant/tgpuConstant.js";
25
+ import { Block, FuncParameter } from "tinyest";
26
+
27
+ //#region src/types.d.ts
28
+ type ResolvableObject = SelfResolvable | TgpuBufferUsage | TgpuConst | TgpuDeclare | TgpuBindGroupLayout | TgpuFn | TgpuComputeFn | TgpuFragmentFn | TgpuComputePipeline | TgpuRenderPipeline | TgpuVertexFn | TgpuSampler | TgpuAccessor | TgpuExternalTexture | TgpuTexture | TgpuTextureView | TgpuVar | AnyVecInstance | AnyMatInstance | AnyData | ((...args: never[]) => unknown);
29
+ type Wgsl = Eventual<string | number | boolean | ResolvableObject>;
30
+ type TgpuShaderStage = 'compute' | 'vertex' | 'fragment';
31
+ interface FnToWgslOptions {
32
+ functionType: 'normal' | TgpuShaderStage;
33
+ argTypes: BaseData[];
34
+ /**
35
+ * The return type of the function. If undefined, the type should be inferred
36
+ * from the implementation (relevant for shellless functions).
37
+ */
38
+ returnType: BaseData | undefined;
39
+ body: Block;
40
+ params: FuncParameter[];
41
+ externalMap: Record<string, unknown>;
42
+ /**
43
+ * For entry functions: positional args and optional data struct.
44
+ * When provided, takes precedence over `argTypes` for WGSL header generation.
45
+ */
46
+ entryInput?: SeparatedEntryArgs | undefined;
47
+ }
48
+ type ItemLayer = {
49
+ type: 'item';
50
+ usedSlots: Set<TgpuSlot<unknown>>;
51
+ };
52
+ type FunctionScopeLayer = {
53
+ type: 'functionScope';
54
+ functionType: 'normal' | 'compute' | 'vertex' | 'fragment';
55
+ args: Snippet[];
56
+ argAliases: Record<string, Snippet>;
57
+ externalMap: Record<string, unknown>;
58
+ /**
59
+ * The return type of the function. If undefined, the type should be inferred
60
+ * from the implementation (relevant for shellless functions).
61
+ */
62
+ returnType: BaseData | undefined;
63
+ /**
64
+ * All types used in `return` statements.
65
+ */
66
+ reportedReturnTypes: Set<BaseData>;
67
+ };
68
+ type SlotBindingLayer = {
69
+ type: 'slotBinding';
70
+ bindingMap: WeakMap<TgpuSlot<unknown>, unknown>;
71
+ };
72
+ type BlockScopeLayer = {
73
+ type: 'blockScope';
74
+ declarations: Map<string, Snippet>;
75
+ externals: Map<string, Snippet>;
76
+ };
77
+ type StackLayer = ItemLayer | SlotBindingLayer | FunctionScopeLayer | BlockScopeLayer;
78
+ interface ItemStateStack {
79
+ readonly itemDepth: number;
80
+ readonly topItem: ItemLayer;
81
+ readonly topFunctionScope: FunctionScopeLayer | undefined;
82
+ pushItem(): void;
83
+ pushSlotBindings(pairs: SlotValuePair[]): void;
84
+ pushFunctionScope(functionType: 'normal' | TgpuShaderStage, args: Snippet[], argAliases: Record<string, Snippet>,
85
+ /**
86
+ * The return type of the function. If undefined, the type should be inferred
87
+ * from the implementation (relevant for shellless functions).
88
+ */
89
+
90
+ returnType: BaseData | undefined, externalMap: Record<string, unknown>): FunctionScopeLayer;
91
+ pushBlockScope(): void;
92
+ setBlockExternals(externals: Record<string, Snippet>): void;
93
+ clearBlockExternals(): void;
94
+ pop<T extends StackLayer['type']>(type: T): Extract<StackLayer, {
95
+ type: T;
96
+ }>;
97
+ pop(): StackLayer | undefined;
98
+ readSlot<T>(slot: TgpuSlot<T>): T | undefined;
99
+ getSnippetById(id: string): Snippet | undefined;
100
+ defineBlockVariable(id: string, snippet: Snippet): void;
101
+ }
102
+ /**
103
+ * # What are execution modes/states? 🤷
104
+ * They're used to control how each TypeGPU resource reacts
105
+ * to actions upon them.
106
+ *
107
+ * ## Normal mode
108
+ * This is the default mode, where resources are acted upon
109
+ * by code either:
110
+ * - Not wrapped inside any of our execution-altering APIs
111
+ * like tgpu.resolve or tgpu.simulate.
112
+ * - Inside tgpu.lazy definitions, where we're taking a break
113
+ * from codegen/simulation to create resources on-demand.
114
+ *
115
+ * ```ts
116
+ * const count = tgpu.privateVar(d.f32);
117
+ * count.$ += 1; // Illegal in top-level
118
+ *
119
+ * const root = await tgpu.init();
120
+ * const countMutable = root.createMutable(d.f32);
121
+ * countMutable.$ = [1, 2, 3]; // Illegal in top-level
122
+ * countMutable.write([1, 2, 3]); // OK!
123
+ * ```
124
+ *
125
+ * ## Codegen mode
126
+ * Brought upon by `tgpu.resolve()` (or higher-level APIs using it like our pipelines).
127
+ * Resources are expected to generate WGSL code that represents them, instead of
128
+ * fulfilling their task in JS.
129
+ *
130
+ * ```ts
131
+ * const foo = tgpu.fn([], d.f32)(() => 123);
132
+ * // The following is running in `codegen` mode
133
+ * console.log(foo()); // Prints `foo_0()`
134
+ * ```
135
+ *
136
+ * ## Simulate mode
137
+ * Callbacks passed to `tgpu.simulate()` are executed in this mode. Each 'simulation'
138
+ * is isolated, and does not share state with other simulations (even nested ones).
139
+ * Variables and buffers can be accessed and mutated directly, and their state
140
+ * is returned at the end of the simulation.
141
+ *
142
+ * ```ts
143
+ * const var = tgpu.privateVar(d.f32, 0);
144
+ *
145
+ * const result = tgpu.simulate(() => {
146
+ * // This is running in `simulate` mode
147
+ * var.$ += 1; // Direct access is legal
148
+ * return var.$; // Returns 1
149
+ * });
150
+ *
151
+ * console.log(result.value); // Prints 1
152
+ * ```
153
+ */
154
+ type ExecMode = 'normal' | 'codegen' | 'simulate';
155
+ declare class NormalState {
156
+ readonly type: "normal";
157
+ }
158
+ declare class CodegenState {
159
+ readonly type: "codegen";
160
+ }
161
+ declare class SimulationState {
162
+ readonly type: "simulate";
163
+ readonly buffers: Map<TgpuBuffer<BaseData>, unknown>;
164
+ readonly vars: {
165
+ private: Map<TgpuVar, unknown>;
166
+ workgroup: Map<TgpuVar, unknown>;
167
+ };
168
+ constructor(buffers: Map<TgpuBuffer<BaseData>, unknown>, vars: {
169
+ private: Map<TgpuVar, unknown>;
170
+ workgroup: Map<TgpuVar, unknown>;
171
+ });
172
+ }
173
+ type ExecState = NormalState | CodegenState | SimulationState;
174
+ /**
175
+ * Passed into each resolvable item. All items in a tree share a resolution ctx,
176
+ * but there can be layers added and removed from the item stack when going down
177
+ * and up the tree.
178
+ */
179
+ interface ResolutionCtx {
180
+ [$internal]: {
181
+ itemStateStack: ItemStateStack;
182
+ };
183
+ readonly mode: ExecState;
184
+ readonly enableExtensions: WgslExtension[] | undefined;
185
+ readonly gen: ShaderGenerator;
186
+ addDeclaration(declaration: string): void;
187
+ withResetIndentLevel<T>(callback: () => T): T;
188
+ /**
189
+ * Reserves a bind group number, and returns a placeholder that will be replaced
190
+ * with a concrete number at the end of the resolution process.
191
+ */
192
+ allocateLayoutEntry(layout: TgpuBindGroupLayout): string;
193
+ /**
194
+ * Reserves a spot in the catch-all bind group, without the indirection of a bind-group.
195
+ * This means the resource is 'fixed', and cannot be swapped between code execution.
196
+ */
197
+ allocateFixedEntry(layoutEntry: TgpuLayoutEntry, resource: object): {
198
+ group: string;
199
+ binding: number;
200
+ };
201
+ withSlots<T>(pairs: SlotValuePair[], callback: () => T): T;
202
+ pushMode(state: ExecState): void;
203
+ popMode(expected?: ExecMode): void;
204
+ /**
205
+ * Unwraps all layers of slot/lazy indirection and returns the concrete value if available.
206
+ * @throws {MissingSlotValueError}
207
+ */
208
+ unwrap<T>(eventual: Eventual<T>): T;
209
+ /**
210
+ * Returns the snippet representing `item`.
211
+ *
212
+ * @param item The value to resolve
213
+ * @param schema Additional information about the item's data type
214
+ */
215
+ resolve(item: unknown, schema?: BaseData | UnknownData): ResolvedSnippet;
216
+ /**
217
+ * Equivalent to `snip(ctx.resolve(snippet.value, snippet.dataType).value, snippet.dataType, snippet.origin)`.
218
+ */
219
+ resolveSnippet(snippet: Snippet): ResolvedSnippet;
220
+ fnToWgsl(options: FnToWgslOptions): {
221
+ head: Wgsl;
222
+ body: Wgsl;
223
+ returnType: BaseData;
224
+ };
225
+ withVaryingLocations<T>(locations: Record<string, number>, callback: () => T): T;
226
+ get varyingLocations(): Record<string, number> | undefined;
227
+ /**
228
+ * Temporarily renames the item.
229
+ * Useful for resolutions with slots,
230
+ * since functions with different slots should have different names,
231
+ * and all hold the same inner function that is being resolved multiple times.
232
+ * @param item the item to rename
233
+ * @param name the temporary name to assign to the item (if missing, just returns `callback()`)
234
+ */
235
+ withRenamed<T>(item: object, name: string | undefined, callback: () => T): T;
236
+ getUniqueName(resource: object): string;
237
+ makeNameValid(name: string): string;
238
+ }
239
+ /**
240
+ * Houses a method on the symbol '$resolve` that returns a
241
+ * code string representing it, as opposed to offloading the
242
+ * resolution to another mechanism.
243
+ */
244
+ interface SelfResolvable {
245
+ [$internal]: unknown;
246
+ [$resolve](ctx: ResolutionCtx): ResolvedSnippet;
247
+ toString(): string;
248
+ }
249
+ interface GPUCallable<TArgs extends unknown[] = unknown[]> {
250
+ [$gpuCallable]: {
251
+ strictSignature?: {
252
+ argTypes: (BaseData | BaseData[])[];
253
+ returnType: BaseData;
254
+ } | undefined;
255
+ call(ctx: ResolutionCtx, args: MapValueToSnippet<TArgs>): Snippet;
256
+ };
257
+ }
258
+ type WithCast<T = BaseData> = GPUCallable<[v?: Infer<T>]> & {
259
+ readonly [$cast]: (v?: Infer<T>) => Infer<T>;
260
+ };
261
+ type AnyFn = (...args: never[]) => unknown;
262
+ type DualFn<T extends AnyFn> = T & GPUCallable<Parameters<T>>;
263
+ type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
264
+ //#endregion
265
+ export { BindableBufferUsage, DualFn, FunctionScopeLayer, GPUCallable, ResolutionCtx, ResolvableObject, SelfResolvable, TgpuShaderStage, Wgsl, WithCast };
package/types.js ADDED
@@ -0,0 +1,43 @@
1
+ import { $cast, $gpuCallable, $ownSnippet, $resolve } from "./shared/symbols.js";
2
+ import { isWgslData } from "./data/wgslTypes.js";
3
+ import { UnknownData } from "./data/dataTypes.js";
4
+ import { isLazy, isProviding, isSlot } from "./core/slot/slotTypes.js";
5
+ //#region src/types.ts
6
+ var NormalState = class {
7
+ type = "normal";
8
+ };
9
+ var CodegenState = class {
10
+ type = "codegen";
11
+ };
12
+ var SimulationState = class {
13
+ type = "simulate";
14
+ buffers;
15
+ vars;
16
+ constructor(buffers, vars) {
17
+ this.buffers = buffers;
18
+ this.vars = vars;
19
+ }
20
+ };
21
+ function isSelfResolvable(value) {
22
+ return !!value?.[$resolve];
23
+ }
24
+ function getOwnSnippet(value) {
25
+ return value?.[$ownSnippet];
26
+ }
27
+ function isGPUCallable(value) {
28
+ return !!value?.[$gpuCallable];
29
+ }
30
+ function hasCast(value) {
31
+ return !!value?.[$cast];
32
+ }
33
+ function isKnownAtComptime(snippet) {
34
+ return (typeof snippet.value !== "string" || snippet.dataType === UnknownData) && getOwnSnippet(snippet.value) === void 0;
35
+ }
36
+ function isWgsl(value) {
37
+ return typeof value === "number" || typeof value === "boolean" || typeof value === "string" || isSelfResolvable(value) || isWgslData(value) || isSlot(value) || isLazy(value) || isProviding(value);
38
+ }
39
+ function isGPUBuffer(value) {
40
+ return !!value && typeof value === "object" && "getMappedRange" in value && "mapAsync" in value;
41
+ }
42
+ //#endregion
43
+ export { CodegenState, NormalState, SimulationState, getOwnSnippet, hasCast, isGPUBuffer, isGPUCallable, isKnownAtComptime, isSelfResolvable, isWgsl };
package/unwrapper.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { TgpuQuerySet } from "./core/querySet/querySet.js";
2
+ import { TgpuComputePipeline } from "./core/pipeline/computePipeline.js";
3
+ import { TgpuVertexLayout } from "./core/vertexLayout/vertexLayout.js";
4
+ import { TgpuRenderPipeline } from "./core/pipeline/renderPipeline.js";
5
+ import { TgpuComparisonSampler, TgpuSampler } from "./core/sampler/sampler.js";
6
+ import { TgpuBindGroup, TgpuBindGroupLayout } from "./tgpuBindGroupLayout.js";
7
+ import { TgpuBuffer } from "./core/buffer/buffer.js";
8
+ import { BaseData } from "./data/wgslTypes.js";
9
+ import { TgpuTexture, TgpuTextureView } from "./core/texture/texture.js";
10
+
11
+ //#region src/unwrapper.d.ts
12
+ interface Unwrapper {
13
+ readonly device: GPUDevice;
14
+ unwrap(resource: TgpuComputePipeline): GPUComputePipeline;
15
+ unwrap(resource: TgpuRenderPipeline): GPURenderPipeline;
16
+ unwrap(resource: TgpuBindGroupLayout): GPUBindGroupLayout;
17
+ unwrap(resource: TgpuBindGroup): GPUBindGroup;
18
+ unwrap(resource: TgpuBuffer<BaseData>): GPUBuffer;
19
+ unwrap(resource: TgpuTextureView): GPUTextureView;
20
+ unwrap(resource: TgpuVertexLayout): GPUVertexBufferLayout;
21
+ unwrap(resource: TgpuSampler): GPUSampler;
22
+ unwrap(resource: TgpuComparisonSampler): GPUSampler;
23
+ unwrap(resource: TgpuQuerySet<GPUQueryType>): GPUQuerySet;
24
+ unwrap(resource: TgpuTexture): GPUTexture;
25
+ }
26
+ //#endregion
27
+ export { Unwrapper };
@@ -0,0 +1,5 @@
1
+ //#region src/wgslExtensions.d.ts
2
+ declare const wgslExtensions: readonly ["f16", "clip_distances", "dual_source_blending", "subgroups", "primitive_index"];
3
+ type WgslExtension = (typeof wgslExtensions)[number];
4
+ //#endregion
5
+ export { WgslExtension };
@@ -0,0 +1,17 @@
1
+ //#region src/wgslExtensions.ts
2
+ const wgslExtensions = [
3
+ "f16",
4
+ "clip_distances",
5
+ "dual_source_blending",
6
+ "subgroups",
7
+ "primitive_index"
8
+ ];
9
+ const wgslExtensionToFeatureName = {
10
+ f16: "shader-f16",
11
+ clip_distances: "clip-distances",
12
+ dual_source_blending: "dual-source-blending",
13
+ subgroups: "subgroups",
14
+ primitive_index: "primitive-index"
15
+ };
16
+ //#endregion
17
+ export { wgslExtensionToFeatureName, wgslExtensions };