typegpu 0.10.0 → 0.10.2

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 (263) hide show
  1. package/{chunk-BYypO7fO.js → _virtual/_rolldown/runtime.js} +1 -1
  2. package/builtin.d.ts +50 -0
  3. package/builtin.js +37 -0
  4. package/common/fullScreenTriangle.d.ts +26 -0
  5. package/common/fullScreenTriangle.js +36 -0
  6. package/common/index.d.ts +2 -3
  7. package/common/index.js +3 -4
  8. package/core/buffer/buffer.d.ts +74 -0
  9. package/core/buffer/buffer.js +197 -0
  10. package/core/buffer/bufferShorthand.d.ts +48 -0
  11. package/core/buffer/bufferShorthand.js +49 -0
  12. package/core/buffer/bufferUsage.d.ts +45 -0
  13. package/core/buffer/bufferUsage.js +163 -0
  14. package/core/constant/tgpuConstant.d.ts +28 -0
  15. package/core/constant/tgpuConstant.js +67 -0
  16. package/core/declare/tgpuDeclare.d.ts +18 -0
  17. package/core/declare/tgpuDeclare.js +40 -0
  18. package/core/function/autoIO.d.ts +37 -0
  19. package/core/function/autoIO.js +87 -0
  20. package/core/function/comptime.d.ts +39 -0
  21. package/core/function/comptime.js +51 -0
  22. package/core/function/createCallableSchema.js +42 -0
  23. package/core/function/dualImpl.js +54 -0
  24. package/core/function/extractArgs.js +204 -0
  25. package/core/function/fnCore.js +79 -0
  26. package/core/function/fnTypes.d.ts +34 -0
  27. package/core/function/ioSchema.d.ts +10 -0
  28. package/core/function/ioSchema.js +30 -0
  29. package/core/function/shelllessImpl.d.ts +28 -0
  30. package/core/function/shelllessImpl.js +23 -0
  31. package/core/function/templateUtils.js +13 -0
  32. package/core/function/tgpuComputeFn.d.ts +49 -0
  33. package/core/function/tgpuComputeFn.js +62 -0
  34. package/core/function/tgpuFn.d.ts +52 -0
  35. package/core/function/tgpuFn.js +170 -0
  36. package/core/function/tgpuFragmentFn.d.ts +68 -0
  37. package/core/function/tgpuFragmentFn.js +68 -0
  38. package/core/function/tgpuVertexFn.d.ts +55 -0
  39. package/core/function/tgpuVertexFn.js +65 -0
  40. package/core/pipeline/applyPipelineState.js +37 -0
  41. package/core/pipeline/computePipeline.d.ts +58 -0
  42. package/core/pipeline/computePipeline.js +226 -0
  43. package/core/pipeline/connectAttachmentToShader.js +26 -0
  44. package/core/pipeline/connectTargetsToShader.js +29 -0
  45. package/core/pipeline/limitsOverflow.js +13 -0
  46. package/core/pipeline/renderPipeline.d.ts +266 -0
  47. package/core/pipeline/renderPipeline.js +471 -0
  48. package/core/pipeline/timeable.d.ts +23 -0
  49. package/core/pipeline/timeable.js +61 -0
  50. package/core/pipeline/typeGuards.js +29 -0
  51. package/core/querySet/querySet.d.ts +22 -0
  52. package/core/querySet/querySet.js +103 -0
  53. package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +59 -0
  54. package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +96 -0
  55. package/core/resolve/externals.d.ts +10 -0
  56. package/core/resolve/externals.js +58 -0
  57. package/core/resolve/namespace.d.ts +38 -0
  58. package/core/resolve/namespace.js +41 -0
  59. package/core/resolve/resolveData.js +146 -0
  60. package/core/resolve/stitch.js +25 -0
  61. package/core/resolve/tgpuResolve.d.ts +151 -0
  62. package/core/resolve/tgpuResolve.js +68 -0
  63. package/core/root/configurableImpl.js +18 -0
  64. package/core/root/init.d.ts +69 -0
  65. package/core/root/init.js +457 -0
  66. package/core/root/rootTypes.d.ts +622 -0
  67. package/core/sampler/sampler.d.ts +35 -0
  68. package/core/sampler/sampler.js +116 -0
  69. package/core/simulate/tgpuSimulate.d.ts +36 -0
  70. package/core/simulate/tgpuSimulate.js +76 -0
  71. package/core/slot/accessor.d.ts +13 -0
  72. package/core/slot/accessor.js +97 -0
  73. package/core/slot/internalSlots.js +7 -0
  74. package/core/slot/lazy.d.ts +6 -0
  75. package/core/slot/lazy.js +42 -0
  76. package/core/slot/slot.d.ts +6 -0
  77. package/core/slot/slot.js +40 -0
  78. package/core/slot/slotTypes.d.ts +92 -0
  79. package/core/slot/slotTypes.js +21 -0
  80. package/core/texture/externalTexture.d.ts +12 -0
  81. package/core/texture/externalTexture.js +48 -0
  82. package/core/texture/texture.d.ts +118 -0
  83. package/core/texture/texture.js +312 -0
  84. package/core/texture/textureFormats.d.ts +29 -0
  85. package/core/texture/textureFormats.js +99 -0
  86. package/core/texture/textureProps.d.ts +11 -0
  87. package/core/texture/textureUtils.js +224 -0
  88. package/core/texture/usageExtension.d.ts +21 -0
  89. package/core/texture/usageExtension.js +21 -0
  90. package/core/unroll/tgpuUnroll.d.ts +13 -0
  91. package/core/unroll/tgpuUnroll.js +36 -0
  92. package/core/valueProxyUtils.js +44 -0
  93. package/core/variable/tgpuVariable.d.ts +38 -0
  94. package/core/variable/tgpuVariable.js +101 -0
  95. package/core/vertexLayout/connectAttributesToShader.js +59 -0
  96. package/core/vertexLayout/vertexAttribute.d.ts +29 -0
  97. package/core/vertexLayout/vertexLayout.d.ts +19 -0
  98. package/core/vertexLayout/vertexLayout.js +103 -0
  99. package/data/alignIO.js +15 -0
  100. package/data/alignmentOf.d.ts +10 -0
  101. package/data/alignmentOf.js +88 -0
  102. package/data/array.d.ts +28 -0
  103. package/data/array.js +48 -0
  104. package/data/atomic.d.ts +15 -0
  105. package/data/atomic.js +25 -0
  106. package/data/attributes.d.ts +121 -0
  107. package/data/attributes.js +145 -0
  108. package/data/autoStruct.d.ts +3 -0
  109. package/data/autoStruct.js +83 -0
  110. package/data/compiledIO.js +231 -0
  111. package/data/dataIO.js +549 -0
  112. package/data/dataTypes.d.ts +115 -0
  113. package/data/dataTypes.js +97 -0
  114. package/data/deepEqual.d.ts +25 -0
  115. package/data/deepEqual.js +58 -0
  116. package/data/disarray.d.ts +34 -0
  117. package/data/disarray.js +52 -0
  118. package/data/getLongestContiguousPrefix.d.ts +10 -0
  119. package/data/getLongestContiguousPrefix.js +15 -0
  120. package/data/index.d.ts +26 -4
  121. package/data/index.js +27 -7
  122. package/data/instanceToSchema.d.ts +33 -0
  123. package/data/isContiguous.d.ts +10 -0
  124. package/data/isContiguous.js +15 -0
  125. package/data/matrix.d.ts +126 -0
  126. package/data/matrix.js +517 -0
  127. package/data/numberOps.js +24 -0
  128. package/data/numeric.d.ts +81 -0
  129. package/data/numeric.js +234 -0
  130. package/data/offsetUtils.d.ts +33 -0
  131. package/data/offsetUtils.js +167 -0
  132. package/data/offsets.js +36 -0
  133. package/data/partialIO.js +68 -0
  134. package/data/ptr.d.ts +12 -0
  135. package/data/ptr.js +46 -0
  136. package/data/ref.d.ts +37 -0
  137. package/data/ref.js +96 -0
  138. package/data/sampler.d.ts +107 -0
  139. package/data/sampler.js +26 -0
  140. package/data/schemaCallWrapper.js +32 -0
  141. package/data/schemaMemoryLayout.js +200 -0
  142. package/data/sizeOf.d.ts +10 -0
  143. package/data/sizeOf.js +15 -0
  144. package/data/snippet.d.ts +26 -0
  145. package/data/snippet.js +61 -0
  146. package/data/struct.d.ts +17 -0
  147. package/data/struct.js +46 -0
  148. package/data/texture.d.ts +292 -0
  149. package/{texture-Dg5ybJro.js → data/texture.js} +6 -3
  150. package/data/unstruct.d.ts +24 -0
  151. package/data/unstruct.js +43 -0
  152. package/data/vector.d.ts +191 -0
  153. package/data/vector.js +247 -0
  154. package/data/vectorImpl.js +516 -0
  155. package/data/vectorOps.js +664 -0
  156. package/data/vertexFormatData.d.ts +190 -0
  157. package/data/vertexFormatData.js +110 -0
  158. package/data/wgslTypes.d.ts +896 -0
  159. package/data/wgslTypes.js +215 -0
  160. package/errors.d.ts +44 -0
  161. package/errors.js +128 -0
  162. package/execMode.js +51 -0
  163. package/extension.d.ts +11 -0
  164. package/extension.js +18 -0
  165. package/getGPUValue.js +9 -0
  166. package/index.d.ts +40 -243
  167. package/index.js +19 -6318
  168. package/indexNamedExports.d.ts +38 -0
  169. package/mathUtils.js +13 -0
  170. package/memo.js +22 -0
  171. package/nameRegistry.d.ts +30 -0
  172. package/nameRegistry.js +449 -0
  173. package/package.js +5 -0
  174. package/package.json +23 -23
  175. package/resolutionCtx.d.ts +29 -0
  176. package/resolutionCtx.js +546 -0
  177. package/shared/env.js +13 -0
  178. package/shared/generators.js +14 -0
  179. package/shared/meta.d.ts +39 -0
  180. package/shared/meta.js +63 -0
  181. package/shared/repr.d.ts +108 -0
  182. package/shared/stringify.js +22 -0
  183. package/shared/symbols.d.ts +61 -0
  184. package/shared/symbols.js +71 -0
  185. package/shared/utilityTypes.d.ts +29 -0
  186. package/shared/utilityTypes.js +7 -0
  187. package/shared/vertexFormat.d.ts +70 -0
  188. package/shared/vertexFormat.js +64 -0
  189. package/std/array.d.ts +7 -0
  190. package/std/array.js +27 -0
  191. package/std/atomic.d.ts +19 -0
  192. package/std/atomic.js +113 -0
  193. package/std/bitcast.d.ts +10 -0
  194. package/std/bitcast.js +43 -0
  195. package/std/boolean.d.ts +127 -0
  196. package/std/boolean.js +274 -0
  197. package/std/derivative.d.ts +16 -0
  198. package/std/derivative.js +89 -0
  199. package/std/discard.d.ts +6 -0
  200. package/std/discard.js +16 -0
  201. package/std/extensions.d.ts +8 -0
  202. package/std/extensions.js +14 -0
  203. package/std/index.d.ts +15 -3
  204. package/std/index.js +16 -5
  205. package/std/matrix.d.ts +41 -0
  206. package/std/matrix.js +87 -0
  207. package/std/numeric.d.ts +254 -0
  208. package/std/numeric.js +847 -0
  209. package/std/operators.d.ts +48 -0
  210. package/std/operators.js +153 -0
  211. package/std/packing.d.ts +26 -0
  212. package/std/packing.js +86 -0
  213. package/std/subgroup.d.ts +47 -0
  214. package/std/subgroup.js +220 -0
  215. package/std/texture.d.ts +108 -0
  216. package/std/texture.js +197 -0
  217. package/tgpu.js +44 -0
  218. package/tgpuBindGroupLayout.d.ts +161 -0
  219. package/tgpuBindGroupLayout.js +271 -0
  220. package/tgpuUnstable.d.ts +48 -0
  221. package/tgpuUnstable.js +66 -0
  222. package/tgsl/accessIndex.js +45 -0
  223. package/tgsl/accessProp.js +113 -0
  224. package/tgsl/consoleLog/deserializers.js +117 -0
  225. package/tgsl/consoleLog/logGenerator.js +86 -0
  226. package/tgsl/consoleLog/serializers.js +225 -0
  227. package/tgsl/consoleLog/types.d.ts +54 -0
  228. package/tgsl/consoleLog/types.js +12 -0
  229. package/tgsl/conversion.js +200 -0
  230. package/tgsl/forOfUtils.js +45 -0
  231. package/tgsl/generationHelpers.d.ts +37 -0
  232. package/tgsl/generationHelpers.js +67 -0
  233. package/tgsl/math.js +45 -0
  234. package/tgsl/shaderGenerator.d.ts +18 -0
  235. package/tgsl/shellless.d.ts +11 -0
  236. package/tgsl/shellless.js +53 -0
  237. package/tgsl/wgslGenerator.js +585 -0
  238. package/types.d.ts +255 -0
  239. package/types.js +43 -0
  240. package/unwrapper.d.ts +27 -0
  241. package/wgslExtensions.d.ts +5 -0
  242. package/wgslExtensions.js +18 -0
  243. package/builtin-ClEnM-Ye.js +0 -818
  244. package/builtin-ClEnM-Ye.js.map +0 -1
  245. package/common/index.d.ts.map +0 -1
  246. package/common/index.js.map +0 -1
  247. package/data/index.d.ts.map +0 -1
  248. package/data/index.js.map +0 -1
  249. package/deepEqual-yZXvaV2C.js +0 -413
  250. package/deepEqual-yZXvaV2C.js.map +0 -1
  251. package/extensions-0SFbU9FH.js +0 -2032
  252. package/extensions-0SFbU9FH.js.map +0 -1
  253. package/fullScreenTriangle-MdLGaAMR.js +0 -543
  254. package/fullScreenTriangle-MdLGaAMR.js.map +0 -1
  255. package/index.d.ts.map +0 -1
  256. package/index.js.map +0 -1
  257. package/indexNamedExports-Cdy7USiY.d.ts +0 -5696
  258. package/indexNamedExports-Cdy7USiY.d.ts.map +0 -1
  259. package/operators-HTxa_0k9.js +0 -4156
  260. package/operators-HTxa_0k9.js.map +0 -1
  261. package/std/index.d.ts.map +0 -1
  262. package/std/index.js.map +0 -1
  263. package/texture-Dg5ybJro.js.map +0 -1
@@ -0,0 +1,170 @@
1
+ import { $getNameForward, $internal, $providing, $resolve, isMarkedInternal } from "../../shared/symbols.js";
2
+ import { getName, setName } from "../../shared/meta.js";
3
+ import { Void } from "../../data/wgslTypes.js";
4
+ import { ExecutionError } from "../../errors.js";
5
+ import { isAccessor, isMutableAccessor } from "../slot/slotTypes.js";
6
+ import { provideInsideTgpuFn } from "../../execMode.js";
7
+ import { stitch } from "../resolve/stitch.js";
8
+ import { schemaCallWrapper } from "../../data/schemaCallWrapper.js";
9
+ import { dualImpl } from "./dualImpl.js";
10
+ import { comptime } from "./comptime.js";
11
+ import { addArgTypesToExternals, addReturnTypeToExternals } from "../resolve/externals.js";
12
+ import { createFnCore } from "./fnCore.js";
13
+ import { stripTemplate } from "./templateUtils.js";
14
+
15
+ //#region src/core/function/tgpuFn.ts
16
+ function fn(argTypesOrCallback, returnType) {
17
+ if (typeof argTypesOrCallback === "function") return createGenericFn(argTypesOrCallback, []);
18
+ const argTypes = argTypesOrCallback;
19
+ const shell = {
20
+ [$internal]: true,
21
+ argTypes,
22
+ returnType: returnType ?? Void
23
+ };
24
+ const call = (arg, ...values) => createFn(shell, stripTemplate(arg, ...values));
25
+ return Object.assign(call, shell);
26
+ }
27
+ function isTgpuFn(value) {
28
+ return isMarkedInternal(value) && value?.resourceType === "function";
29
+ }
30
+ function isGenericFn(value) {
31
+ return isMarkedInternal(value) && value?.resourceType === "generic-function";
32
+ }
33
+ function stringifyPair([slot, value]) {
34
+ return `${getName(slot) ?? "<unnamed>"}=${value}`;
35
+ }
36
+ function createFn(shell, _implementation) {
37
+ let pairs = [];
38
+ let implementation;
39
+ if (isGenericFn(_implementation)) {
40
+ pairs = _implementation[$providing]?.pairs ?? [];
41
+ implementation = _implementation[$internal].inner;
42
+ } else implementation = _implementation;
43
+ const core = createFnCore(implementation, "");
44
+ const fnBase = {
45
+ shell,
46
+ resourceType: "function",
47
+ [$internal]: { implementation },
48
+ $uses(newExternals) {
49
+ core.applyExternals(newExternals);
50
+ return this;
51
+ },
52
+ [$getNameForward]: core,
53
+ $name(label) {
54
+ setName(this, label);
55
+ return this;
56
+ },
57
+ with: comptime((slot, value) => {
58
+ return createBoundFunction(fn, [[isAccessor(slot) || isMutableAccessor(slot) ? slot.slot : slot, value]]);
59
+ }),
60
+ [$resolve](ctx) {
61
+ if (typeof implementation === "string") {
62
+ addArgTypesToExternals(implementation, shell.argTypes, core.applyExternals);
63
+ addReturnTypeToExternals(implementation, shell.returnType, core.applyExternals);
64
+ }
65
+ return core.resolve(ctx, shell.argTypes, shell.returnType);
66
+ }
67
+ };
68
+ const call = dualImpl({
69
+ name: void 0,
70
+ noComptime: true,
71
+ signature: {
72
+ argTypes: shell.argTypes,
73
+ returnType: shell.returnType
74
+ },
75
+ normalImpl: (...args) => provideInsideTgpuFn(() => {
76
+ try {
77
+ if (typeof implementation === "string") throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");
78
+ const castAndCopiedArgs = args.map((arg, index) => schemaCallWrapper(shell.argTypes[index], arg));
79
+ const result = implementation(...castAndCopiedArgs);
80
+ return schemaCallWrapper(shell.returnType, result);
81
+ } catch (err) {
82
+ if (err instanceof ExecutionError) throw err.appendToTrace(fn);
83
+ throw new ExecutionError(err, [fn]);
84
+ }
85
+ }),
86
+ codegenImpl: (ctx, args) => ctx.withResetIndentLevel(() => stitch`${ctx.resolve(fn).value}(${args})`)
87
+ });
88
+ const fn = Object.assign(call, fnBase);
89
+ Object.defineProperty(fn, "toString", { value() {
90
+ return `fn:${getName(core) ?? "<unnamed>"}`;
91
+ } });
92
+ if (pairs.length > 0) return createBoundFunction(fn, pairs);
93
+ return fn;
94
+ }
95
+ function createBoundFunction(innerFn, pairs) {
96
+ const fnBase = {
97
+ resourceType: "function",
98
+ shell: innerFn.shell,
99
+ [$internal]: { implementation: innerFn[$internal].implementation },
100
+ [$providing]: {
101
+ inner: innerFn,
102
+ pairs
103
+ },
104
+ $uses(newExternals) {
105
+ innerFn.$uses(newExternals);
106
+ return this;
107
+ },
108
+ $name(label) {
109
+ setName(this, label);
110
+ return this;
111
+ },
112
+ with: comptime((slot, value) => {
113
+ const s = isAccessor(slot) || isMutableAccessor(slot) ? slot.slot : slot;
114
+ return createBoundFunction(innerFn, [...pairs, [s, value]]);
115
+ })
116
+ };
117
+ const call = dualImpl({
118
+ name: void 0,
119
+ noComptime: true,
120
+ signature: {
121
+ argTypes: innerFn.shell.argTypes,
122
+ returnType: innerFn.shell.returnType
123
+ },
124
+ normalImpl: innerFn,
125
+ codegenImpl: (ctx, args) => ctx.withResetIndentLevel(() => stitch`${ctx.resolve(fn).value}(${args})`)
126
+ });
127
+ const fn = Object.assign(call, fnBase);
128
+ Object.defineProperty(fn, "toString", { value() {
129
+ return `fn:${getName(this) ?? "<unnamed>"}[${pairs.map(stringifyPair).join(", ")}]`;
130
+ } });
131
+ const innerName = getName(innerFn);
132
+ if (innerName) setName(fn, innerName);
133
+ return fn;
134
+ }
135
+ function createGenericFn(inner, pairs) {
136
+ const fnBase = {
137
+ [$internal]: { inner },
138
+ resourceType: "generic-function",
139
+ [$providing]: pairs.length > 0 ? {
140
+ inner,
141
+ pairs
142
+ } : void 0,
143
+ $name(label) {
144
+ setName(this, label);
145
+ if (!getName(inner)) setName(inner, label);
146
+ return this;
147
+ },
148
+ [$resolve](ctx) {
149
+ return ctx.resolve(inner);
150
+ },
151
+ with(slot, value) {
152
+ const s = isAccessor(slot) || isMutableAccessor(slot) ? slot.slot : slot;
153
+ return createGenericFn(inner, [...pairs, [s, value]]);
154
+ }
155
+ };
156
+ const call = (...args) => {
157
+ return inner(...args);
158
+ };
159
+ const genericFn = Object.assign(call, fnBase);
160
+ if (getName(inner)) setName(genericFn, getName(inner));
161
+ Object.defineProperty(genericFn, "toString", { value() {
162
+ const fnLabel = getName(genericFn) ?? "<unnamed>";
163
+ if (pairs.length > 0) return `fn*:${fnLabel}[${pairs.map(stringifyPair).join(", ")}]`;
164
+ return `fn*:${fnLabel}`;
165
+ } });
166
+ return genericFn;
167
+ }
168
+
169
+ //#endregion
170
+ export { fn, isGenericFn, isTgpuFn };
@@ -0,0 +1,68 @@
1
+ import { TgpuNamable } from "../../shared/meta.js";
2
+ import { $internal } from "../../shared/symbols.js";
3
+ import { Prettify } from "../../shared/utilityTypes.js";
4
+ import { AnyFragmentInputBuiltin, AnyFragmentOutputBuiltin, OmitBuiltins } from "../../builtin.js";
5
+ import { BaseIOData, IOLayout, IORecord, InferIO } from "./fnTypes.js";
6
+ import { IOLayoutToSchema } from "./ioSchema.js";
7
+ import { InstanceToSchema } from "../../data/instanceToSchema.js";
8
+ import { BaseData, Decorated, Interpolate, Location, Vec4f, Vec4i, Vec4u, WgslStruct } from "../../data/wgslTypes.js";
9
+ import { UndecorateRecord } from "../../data/dataTypes.js";
10
+
11
+ //#region src/core/function/tgpuFragmentFn.d.ts
12
+ type FragmentInConstrained = IORecord<BaseIOData | Decorated<BaseIOData, (Location | Interpolate)[]> | AnyFragmentInputBuiltin>;
13
+ type VertexOutToVarying<T> = OmitBuiltins<{ [K in keyof T]: InstanceToSchema<T[K]> }>;
14
+ type FragmentColorValue = Vec4f | Vec4i | Vec4u;
15
+ type FragmentOutConstrained = IOLayout<FragmentColorValue | Decorated<FragmentColorValue, (Location | Interpolate)[]> | AnyFragmentOutputBuiltin>;
16
+ /**
17
+ * Describes a fragment entry function signature (its arguments, return type and targets)
18
+ */
19
+ type TgpuFragmentFnShellHeader<FragmentIn extends TgpuFragmentFn.In = TgpuFragmentFn.In, FragmentOut extends TgpuFragmentFn.Out = TgpuFragmentFn.Out> = {
20
+ readonly in: FragmentIn | undefined;
21
+ readonly out: FragmentOut;
22
+ readonly returnType: IOLayoutToSchema<FragmentOut>;
23
+ readonly entryPoint: 'fragment';
24
+ };
25
+ type CleanIO<T> = T extends Record<string, BaseData> ? Prettify<UndecorateRecord<OmitBuiltins<T>>> : Prettify<UndecorateRecord<OmitBuiltins<{
26
+ a: T;
27
+ }>>> extends {
28
+ a: infer Result;
29
+ } ? Result : Record<string, never>;
30
+ /**
31
+ * Describes a fragment entry function signature (its arguments, return type and targets).
32
+ * Allows creating tgpu fragment functions by calling this shell
33
+ * and passing the implementation (as WGSL string or JS function) as the argument.
34
+ */
35
+ interface TgpuFragmentFnShell<out TIn extends TgpuFragmentFn.In = TgpuFragmentFn.In, out TOut extends TgpuFragmentFn.Out = TgpuFragmentFn.Out> extends TgpuFragmentFnShellHeader<TIn, TOut> {
36
+ /**
37
+ * Creates a type-safe implementation of this signature
38
+ */
39
+ (implementation: (input: InferIO<TIn>, out: TOut extends IORecord ? WgslStruct<TOut> : TOut) => InferIO<TOut>): TgpuFragmentFn<CleanIO<TIn>, CleanIO<TOut>>;
40
+ /**
41
+ * @param implementation
42
+ * Raw WGSL function implementation with header and body
43
+ * without `fn` keyword and function name
44
+ * e.g. `"(x: f32) -> f32 { return x; }"`;
45
+ */
46
+ (implementation: string): TgpuFragmentFn<CleanIO<TIn>, CleanIO<TOut>>;
47
+ (strings: TemplateStringsArray, ...values: unknown[]): TgpuFragmentFn<CleanIO<TIn>, CleanIO<TOut>>;
48
+ }
49
+ interface TgpuFragmentFn<in Varying extends TgpuFragmentFn.In = Record<string, never>, out Output extends TgpuFragmentFn.Out = TgpuFragmentFn.Out> extends TgpuNamable {
50
+ readonly [$internal]: true;
51
+ readonly shell: TgpuFragmentFnShellHeader<Varying, Output>;
52
+ readonly outputType: IOLayoutToSchema<Output>;
53
+ $uses(dependencyMap: Record<string, unknown>): this;
54
+ }
55
+ declare namespace TgpuFragmentFn {
56
+ type In = Record<string, BaseData>;
57
+ type Out = Record<string, BaseData> | BaseData;
58
+ }
59
+ declare function fragmentFn<FragmentOut extends FragmentOutConstrained>(options: {
60
+ out: FragmentOut;
61
+ }): TgpuFragmentFnShell<{}, FragmentOut>;
62
+ declare function fragmentFn<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained>(options: {
63
+ in: FragmentIn;
64
+ out: FragmentOut;
65
+ }): TgpuFragmentFnShell<FragmentIn, FragmentOut>;
66
+ declare function isTgpuFragmentFn<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained>(value: unknown): value is TgpuFragmentFn<FragmentIn, FragmentOut>;
67
+ //#endregion
68
+ export { FragmentInConstrained, FragmentOutConstrained, TgpuFragmentFn, TgpuFragmentFnShell, VertexOutToVarying, fragmentFn, isTgpuFragmentFn };
@@ -0,0 +1,68 @@
1
+ import { $getNameForward, $internal, $resolve } from "../../shared/symbols.js";
2
+ import { getName, isNamable, setName } from "../../shared/meta.js";
3
+ import { createIoSchema } from "./ioSchema.js";
4
+ import { addReturnTypeToExternals } from "../resolve/externals.js";
5
+ import { createFnCore } from "./fnCore.js";
6
+ import { stripTemplate } from "./templateUtils.js";
7
+ import { shaderStageSlot } from "../slot/internalSlots.js";
8
+
9
+ //#region src/core/function/tgpuFragmentFn.ts
10
+ /**
11
+ * Creates a shell of a typed entry function for the fragment shader stage. Any function
12
+ * that implements this shell can run for each fragment (pixel), allowing the inner code
13
+ * to process information received from the vertex shader stage and builtins to determine
14
+ * the final color of the pixel (many pixels in case of multiple targets).
15
+ *
16
+ * @param options.in
17
+ * Values computed in the vertex stage and builtins to be made available to functions that implement this shell.
18
+ * @param options.out
19
+ * A `vec4f`, signaling this function outputs a color for one target, or a record containing colors for multiple targets.
20
+ */
21
+ function fragmentFn(options) {
22
+ const shell = {
23
+ in: options.in,
24
+ out: options.out,
25
+ returnType: createIoSchema(options.out),
26
+ entryPoint: "fragment"
27
+ };
28
+ const call = (arg, ...values) => createFragmentFn(shell, stripTemplate(arg, ...values));
29
+ return Object.assign(call, shell);
30
+ }
31
+ function isTgpuFragmentFn(value) {
32
+ return value?.shell?.entryPoint === "fragment";
33
+ }
34
+ function createFragmentFn(shell, implementation) {
35
+ const core = createFnCore(implementation, "@fragment ");
36
+ const outputType = shell.returnType;
37
+ if (typeof implementation === "string") addReturnTypeToExternals(implementation, outputType, (externals) => core.applyExternals(externals));
38
+ return {
39
+ shell,
40
+ outputType,
41
+ $uses(newExternals) {
42
+ core.applyExternals(newExternals);
43
+ return this;
44
+ },
45
+ [$internal]: true,
46
+ [$getNameForward]: core,
47
+ $name(newLabel) {
48
+ setName(this, newLabel);
49
+ if (isNamable(outputType)) outputType.$name(`${newLabel}_Output`);
50
+ return this;
51
+ },
52
+ [$resolve](ctx) {
53
+ const inputWithLocation = shell.in ? createIoSchema(shell.in, ctx.varyingLocations) : void 0;
54
+ if (inputWithLocation) {
55
+ inputWithLocation.$name(`${getName(this) ?? ""}_Input`);
56
+ core.applyExternals({ In: inputWithLocation });
57
+ }
58
+ core.applyExternals({ Out: outputType });
59
+ return ctx.withSlots([[shaderStageSlot, "fragment"]], () => core.resolve(ctx, inputWithLocation ? [inputWithLocation] : [], shell.returnType));
60
+ },
61
+ toString() {
62
+ return `fragmentFn:${getName(core) ?? "<unnamed>"}`;
63
+ }
64
+ };
65
+ }
66
+
67
+ //#endregion
68
+ export { fragmentFn, isTgpuFragmentFn };
@@ -0,0 +1,55 @@
1
+ import { TgpuNamable } from "../../shared/meta.js";
2
+ import { $internal } from "../../shared/symbols.js";
3
+ import { Prettify } from "../../shared/utilityTypes.js";
4
+ import { AnyVertexInputBuiltin, AnyVertexOutputBuiltin, OmitBuiltins } from "../../builtin.js";
5
+ import { BaseIOData, IORecord, InferIO } from "./fnTypes.js";
6
+ import { IOLayoutToSchema } from "./ioSchema.js";
7
+ import { BaseData, Decorated, Interpolate, Location } from "../../data/wgslTypes.js";
8
+ import { UndecorateRecord } from "../../data/dataTypes.js";
9
+
10
+ //#region src/core/function/tgpuVertexFn.d.ts
11
+ type VertexInConstrained = IORecord<BaseIOData | Decorated<BaseIOData, Location[]> | AnyVertexInputBuiltin>;
12
+ type VertexOutConstrained = IORecord<BaseIOData | Decorated<BaseIOData, (Location | Interpolate)[]> | AnyVertexOutputBuiltin>;
13
+ /**
14
+ * Describes a vertex entry function signature (its arguments, return type and attributes)
15
+ */
16
+ type TgpuVertexFnShellHeader<VertexIn extends TgpuVertexFn.In, VertexOut extends TgpuVertexFn.Out> = {
17
+ readonly in: VertexIn | undefined;
18
+ readonly out: VertexOut;
19
+ readonly argTypes: [IOLayoutToSchema<VertexIn>] | [];
20
+ readonly entryPoint: 'vertex';
21
+ };
22
+ type CleanIO<T> = T extends Record<string, BaseData> ? Prettify<UndecorateRecord<OmitBuiltins<T>>> : Prettify<UndecorateRecord<OmitBuiltins<{
23
+ a: T;
24
+ }>>> extends {
25
+ a: infer Result;
26
+ } ? Result : never;
27
+ /**
28
+ * Describes a vertex entry function signature (its arguments, return type and attributes).
29
+ * Allows creating tgpu vertex functions by calling this shell
30
+ * and passing the implementation (as WGSL string or JS function) as the argument.
31
+ */
32
+ interface TgpuVertexFnShell<out TIn extends TgpuVertexFn.In, out TOut extends TgpuVertexFn.Out> extends TgpuVertexFnShellHeader<TIn, TOut> {
33
+ (implementation: (input: InferIO<TIn>, out: IOLayoutToSchema<TOut>) => InferIO<TOut>): TgpuVertexFn<CleanIO<TIn>, CleanIO<TOut>>;
34
+ (implementation: string): TgpuVertexFn<CleanIO<TIn>, CleanIO<TOut>>;
35
+ (strings: TemplateStringsArray, ...values: unknown[]): TgpuVertexFn<CleanIO<TIn>, CleanIO<TOut>>;
36
+ }
37
+ interface TgpuVertexFn<in VertexIn extends TgpuVertexFn.In = Record<string, never>, out VertexOut extends TgpuVertexFn.Out = TgpuVertexFn.Out> extends TgpuNamable {
38
+ readonly [$internal]: true;
39
+ readonly shell: TgpuVertexFnShellHeader<VertexIn, VertexOut>;
40
+ $uses(dependencyMap: Record<string, unknown>): this;
41
+ }
42
+ declare namespace TgpuVertexFn {
43
+ type In = BaseData | Record<string, BaseData>;
44
+ type Out = Record<string, BaseData>;
45
+ }
46
+ declare function vertexFn<VertexOut extends VertexOutConstrained>(options: {
47
+ out: VertexOut;
48
+ }): TgpuVertexFnShell<{}, VertexOut>;
49
+ declare function vertexFn<VertexIn extends VertexInConstrained, VertexOut extends VertexOutConstrained>(options: {
50
+ in: VertexIn;
51
+ out: VertexOut;
52
+ }): TgpuVertexFnShell<VertexIn, VertexOut>;
53
+ declare function isTgpuVertexFn<VertexIn extends VertexInConstrained, VertexOut extends VertexOutConstrained>(value: unknown): value is TgpuVertexFn<VertexIn, VertexOut>;
54
+ //#endregion
55
+ export { TgpuVertexFn, TgpuVertexFnShell, isTgpuVertexFn, vertexFn };
@@ -0,0 +1,65 @@
1
+ import { $getNameForward, $internal, $resolve } from "../../shared/symbols.js";
2
+ import { getName, isNamable, setName } from "../../shared/meta.js";
3
+ import { createIoSchema } from "./ioSchema.js";
4
+ import { createFnCore } from "./fnCore.js";
5
+ import { stripTemplate } from "./templateUtils.js";
6
+ import { shaderStageSlot } from "../slot/internalSlots.js";
7
+
8
+ //#region src/core/function/tgpuVertexFn.ts
9
+ /**
10
+ * Creates a shell of a typed entry function for the vertex shader stage. Any function
11
+ * that implements this shell can run for each vertex, allowing the inner code to process
12
+ * attributes and determine the final position of the vertex.
13
+ *
14
+ * @param options.in
15
+ * Vertex attributes and builtins to be made available to functions that implement this shell.
16
+ * @param options.out
17
+ * A record containing the final position of the vertex, and any information
18
+ * passed onto the fragment shader stage.
19
+ */
20
+ function vertexFn(options) {
21
+ if (Object.keys(options.out).length === 0) throw new Error(`A vertexFn output cannot be empty since it must include the 'position' builtin.`);
22
+ const shell = {
23
+ in: options.in,
24
+ out: options.out,
25
+ argTypes: options.in && Object.keys(options.in).length !== 0 ? [createIoSchema(options.in)] : [],
26
+ entryPoint: "vertex"
27
+ };
28
+ const call = (arg, ...values) => createVertexFn(shell, stripTemplate(arg, ...values));
29
+ return Object.assign(call, shell);
30
+ }
31
+ function isTgpuVertexFn(value) {
32
+ return value?.shell?.entryPoint === "vertex";
33
+ }
34
+ function createVertexFn(shell, implementation) {
35
+ const core = createFnCore(implementation, "@vertex ");
36
+ const inputType = shell.argTypes[0];
37
+ return {
38
+ shell,
39
+ $uses(newExternals) {
40
+ core.applyExternals(newExternals);
41
+ return this;
42
+ },
43
+ [$internal]: true,
44
+ [$getNameForward]: core,
45
+ $name(newLabel) {
46
+ setName(this, newLabel);
47
+ if (isNamable(inputType)) inputType.$name(`${newLabel}_Input`);
48
+ return this;
49
+ },
50
+ [$resolve](ctx) {
51
+ const outputWithLocation = createIoSchema(shell.out, ctx.varyingLocations).$name(`${getName(this) ?? ""}_Output`);
52
+ if (typeof implementation === "string") {
53
+ if (inputType) core.applyExternals({ In: inputType });
54
+ core.applyExternals({ Out: outputWithLocation });
55
+ }
56
+ return ctx.withSlots([[shaderStageSlot, "vertex"]], () => core.resolve(ctx, shell.argTypes, outputWithLocation));
57
+ },
58
+ toString() {
59
+ return `vertexFn:${getName(core) ?? "<unnamed>"}`;
60
+ }
61
+ };
62
+ }
63
+
64
+ //#endregion
65
+ export { isTgpuVertexFn, vertexFn };
@@ -0,0 +1,37 @@
1
+ import { MissingBindGroupsError, MissingVertexBuffersError } from "../../errors.js";
2
+ import { isBuffer } from "../buffer/buffer.js";
3
+ import { isBindGroup } from "../../tgpuBindGroupLayout.js";
4
+ import { warnIfOverflow } from "./limitsOverflow.js";
5
+
6
+ //#region src/core/pipeline/applyPipelineState.ts
7
+ function applyBindGroups(encoder, root, usedBindGroupLayouts, catchall, resolveBindGroup) {
8
+ const missingBindGroups = new Set(usedBindGroupLayouts);
9
+ warnIfOverflow(usedBindGroupLayouts, root.device.limits);
10
+ usedBindGroupLayouts.forEach((layout, idx) => {
11
+ if (catchall && idx === catchall[0]) {
12
+ encoder.setBindGroup(idx, root.unwrap(catchall[1]));
13
+ missingBindGroups.delete(layout);
14
+ } else {
15
+ const bindGroup = resolveBindGroup(layout);
16
+ if (bindGroup !== void 0) {
17
+ missingBindGroups.delete(layout);
18
+ if (isBindGroup(bindGroup)) encoder.setBindGroup(idx, root.unwrap(bindGroup));
19
+ else encoder.setBindGroup(idx, bindGroup);
20
+ }
21
+ }
22
+ });
23
+ if (missingBindGroups.size > 0) throw new MissingBindGroupsError(missingBindGroups);
24
+ }
25
+ function applyVertexBuffers(encoder, root, usedVertexLayouts, resolveVertexBuffer) {
26
+ const missingVertexLayouts = /* @__PURE__ */ new Set();
27
+ usedVertexLayouts.forEach((vertexLayout, idx) => {
28
+ const entry = resolveVertexBuffer(vertexLayout);
29
+ if (!entry || !entry.buffer) missingVertexLayouts.add(vertexLayout);
30
+ else if (isBuffer(entry.buffer)) encoder.setVertexBuffer(idx, root.unwrap(entry.buffer), entry.offset, entry.size);
31
+ else encoder.setVertexBuffer(idx, entry.buffer, entry.offset, entry.size);
32
+ });
33
+ if (missingVertexLayouts.size > 0) throw new MissingVertexBuffersError(missingVertexLayouts);
34
+ }
35
+
36
+ //#endregion
37
+ export { applyBindGroups, applyVertexBuffers };
@@ -0,0 +1,58 @@
1
+ import { TgpuNamable } from "../../shared/meta.js";
2
+ import { $internal } from "../../shared/symbols.js";
3
+ import { AnyComputeBuiltin } from "../../builtin.js";
4
+ import "../querySet/querySet.js";
5
+ import "../../data/snippet.js";
6
+ import "../../tgsl/consoleLog/types.js";
7
+ import { IORecord } from "../function/fnTypes.js";
8
+ import { TgpuComputeFn } from "../function/tgpuComputeFn.js";
9
+ import "../slot/slotTypes.js";
10
+ import { PrimitiveOffsetInfo } from "../../data/offsetUtils.js";
11
+ import { Timeable, TimestampWritesPriors } from "./timeable.js";
12
+ import { TgpuBindGroup, TgpuBindGroupLayout, TgpuLayoutEntry } from "../../tgpuBindGroupLayout.js";
13
+ import { ExperimentalTgpuRoot } from "../root/rootTypes.js";
14
+ import { IndirectFlag, TgpuBuffer } from "../buffer/buffer.js";
15
+ import { SelfResolvable } from "../../types.js";
16
+ import { AnyWgslData } from "../../data/wgslTypes.js";
17
+
18
+ //#region src/core/pipeline/computePipeline.d.ts
19
+ interface ComputePipelineInternals {
20
+ readonly rawPipeline: GPUComputePipeline;
21
+ readonly priors: TgpuComputePipelinePriors & TimestampWritesPriors;
22
+ readonly root: ExperimentalTgpuRoot;
23
+ }
24
+ interface TgpuComputePipeline extends TgpuNamable, SelfResolvable, Timeable {
25
+ readonly [$internal]: ComputePipelineInternals;
26
+ readonly resourceType: 'compute-pipeline';
27
+ /**
28
+ * @deprecated This overload is outdated.
29
+ * Call `pipeline.with(bindGroup)` instead.
30
+ */
31
+ with<Entries extends Record<string, TgpuLayoutEntry | null>>(bindGroupLayout: TgpuBindGroupLayout<Entries>, bindGroup: TgpuBindGroup<Entries>): this;
32
+ with(bindGroupLayout: TgpuBindGroupLayout, bindGroup: GPUBindGroup): this;
33
+ with(bindGroup: TgpuBindGroup): this;
34
+ with(encoder: GPUCommandEncoder): this;
35
+ with(pass: GPUComputePassEncoder): this;
36
+ dispatchWorkgroups(x: number, y?: number, z?: number): void;
37
+ /**
38
+ * Dispatches compute workgroups using parameters read from a buffer.
39
+ * The buffer must contain 3 consecutive u32 values (x, y, z workgroup counts).
40
+ * To get the correct offset within complex data structures, use `d.memoryLayoutOf(...)`.
41
+ *
42
+ * @param indirectBuffer - Buffer marked with 'indirect' usage containing dispatch parameters
43
+ * @param start - PrimitiveOffsetInfo pointing to the first dispatch parameter. If not provided, starts at offset 0. To obtain safe offsets, use `d.memoryLayoutOf(...)`.
44
+ */
45
+ dispatchWorkgroupsIndirect<T extends AnyWgslData>(indirectBuffer: TgpuBuffer<T> & IndirectFlag, start?: PrimitiveOffsetInfo | number): void;
46
+ }
47
+ declare namespace TgpuComputePipeline {
48
+ type Descriptor<Input extends IORecord<AnyComputeBuiltin> = IORecord<AnyComputeBuiltin>> = {
49
+ compute: TgpuComputeFn<Input>;
50
+ };
51
+ }
52
+ type TgpuComputePipelinePriors = {
53
+ readonly bindGroupLayoutMap?: Map<TgpuBindGroupLayout, TgpuBindGroup | GPUBindGroup>;
54
+ readonly externalEncoder?: GPUCommandEncoder | undefined;
55
+ readonly externalPass?: GPUComputePassEncoder | undefined;
56
+ } & TimestampWritesPriors;
57
+ //#endregion
58
+ export { TgpuComputePipeline };