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,226 @@
1
+ import { $getNameForward, $internal, $resolve } from "../../shared/symbols.js";
2
+ import { PERF, getName, setName } from "../../shared/meta.js";
3
+ import { Void } from "../../data/wgslTypes.js";
4
+ import { snip } from "../../data/snippet.js";
5
+ import { sizeOf } from "../../data/sizeOf.js";
6
+ import { namespace } from "../resolve/namespace.js";
7
+ import { isBindGroup } from "../../tgpuBindGroupLayout.js";
8
+ import { resolve } from "../../resolutionCtx.js";
9
+ import { isGPUCommandEncoder, isGPUComputePassEncoder } from "./typeGuards.js";
10
+ import { applyBindGroups } from "./applyPipelineState.js";
11
+ import { logDataFromGPU } from "../../tgsl/consoleLog/deserializers.js";
12
+ import { wgslExtensionToFeatureName, wgslExtensions } from "../../wgslExtensions.js";
13
+ import { memoryLayoutOf } from "../../data/offsetUtils.js";
14
+ import { createWithPerformanceCallback, createWithTimestampWrites, setupTimestampWrites, triggerPerformanceCallback } from "./timeable.js";
15
+
16
+ //#region src/core/pipeline/computePipeline.ts
17
+ function INTERNAL_createComputePipeline(branch, slotBindings, descriptor) {
18
+ return new TgpuComputePipelineImpl(new ComputePipelineCore(branch, slotBindings, descriptor), {});
19
+ }
20
+ function validateIndirectBufferSize(bufferSize, offset, requiredBytes, operation) {
21
+ if (offset + requiredBytes > bufferSize) throw new Error(`Buffer too small for ${operation}. Required: ${requiredBytes} bytes at offset ${offset}, but buffer is only ${bufferSize} bytes.`);
22
+ if (offset % 4 !== 0) throw new Error(`Indirect buffer offset must be a multiple of 4. Got: ${offset}`);
23
+ }
24
+ const _lastAppliedCompute = /* @__PURE__ */ new WeakMap();
25
+ var TgpuComputePipelineImpl = class TgpuComputePipelineImpl {
26
+ [$internal];
27
+ resourceType = "compute-pipeline";
28
+ [$getNameForward];
29
+ constructor(_core, _priors) {
30
+ this._core = _core;
31
+ this._priors = _priors;
32
+ this[$internal] = {
33
+ get rawPipeline() {
34
+ return _core.unwrap().pipeline;
35
+ },
36
+ get priors() {
37
+ return _priors;
38
+ },
39
+ get root() {
40
+ return _core.root;
41
+ }
42
+ };
43
+ this[$getNameForward] = _core;
44
+ }
45
+ [$resolve](ctx) {
46
+ return ctx.resolve(this._core);
47
+ }
48
+ toString() {
49
+ return `computePipeline:${getName(this) ?? "<unnamed>"}`;
50
+ }
51
+ get rawPipeline() {
52
+ return this._core.unwrap().pipeline;
53
+ }
54
+ with(first, bindGroup) {
55
+ if (isGPUComputePassEncoder(first)) return new TgpuComputePipelineImpl(this._core, {
56
+ ...this._priors,
57
+ externalPass: first,
58
+ externalEncoder: void 0
59
+ });
60
+ if (isGPUCommandEncoder(first)) return new TgpuComputePipelineImpl(this._core, {
61
+ ...this._priors,
62
+ externalEncoder: first,
63
+ externalPass: void 0
64
+ });
65
+ if (isBindGroup(first)) return new TgpuComputePipelineImpl(this._core, {
66
+ ...this._priors,
67
+ bindGroupLayoutMap: new Map([...this._priors.bindGroupLayoutMap ?? [], [first.layout, first]])
68
+ });
69
+ return new TgpuComputePipelineImpl(this._core, {
70
+ ...this._priors,
71
+ bindGroupLayoutMap: new Map([...this._priors.bindGroupLayoutMap ?? [], [first, bindGroup]])
72
+ });
73
+ }
74
+ withPerformanceCallback(callback) {
75
+ const newPriors = createWithPerformanceCallback(this._priors, callback, this._core.root);
76
+ return new TgpuComputePipelineImpl(this._core, newPriors);
77
+ }
78
+ withTimestampWrites(options) {
79
+ const newPriors = createWithTimestampWrites(this._priors, options, this._core.root);
80
+ return new TgpuComputePipelineImpl(this._core, newPriors);
81
+ }
82
+ dispatchWorkgroups(x, y, z) {
83
+ this._executeComputePass((pass) => pass.dispatchWorkgroups(x, y, z));
84
+ }
85
+ dispatchWorkgroupsIndirect(indirectBuffer, start) {
86
+ const DISPATCH_SIZE = 12;
87
+ let offsetInfo = start ?? memoryLayoutOf(indirectBuffer.dataType);
88
+ if (typeof offsetInfo === "number") if (offsetInfo === 0) offsetInfo = memoryLayoutOf(indirectBuffer.dataType);
89
+ else {
90
+ console.warn(`dispatchWorkgroupsIndirect: Provided start offset ${offsetInfo} as a raw number. Use d.memoryLayoutOf(...) to include contiguous padding info for safer validation.`);
91
+ offsetInfo = {
92
+ offset: offsetInfo,
93
+ contiguous: DISPATCH_SIZE
94
+ };
95
+ }
96
+ const { offset, contiguous } = offsetInfo;
97
+ validateIndirectBufferSize(sizeOf(indirectBuffer.dataType), offset, DISPATCH_SIZE, "dispatchWorkgroupsIndirect");
98
+ if (contiguous < DISPATCH_SIZE) console.warn(`dispatchWorkgroupsIndirect: Starting at offset ${offset}, only ${contiguous} contiguous bytes are available before padding. Dispatch requires ${DISPATCH_SIZE} bytes (3 x u32). Reading across padding may result in undefined behavior.`);
99
+ this._executeComputePass((pass) => pass.dispatchWorkgroupsIndirect(indirectBuffer.buffer, offset));
100
+ }
101
+ _applyComputeState(pass) {
102
+ const memo = this._core.unwrap();
103
+ const { root } = this._core;
104
+ pass.setPipeline(memo.pipeline);
105
+ applyBindGroups(pass, root, memo.usedBindGroupLayouts, memo.catchall, (layout) => this._priors.bindGroupLayoutMap?.get(layout));
106
+ }
107
+ _executeComputePass(dispatch) {
108
+ const { root } = this._core;
109
+ if (this._priors.externalPass) {
110
+ if (_lastAppliedCompute.get(this._priors.externalPass) !== this) {
111
+ this._applyComputeState(this._priors.externalPass);
112
+ _lastAppliedCompute.set(this._priors.externalPass, this);
113
+ }
114
+ dispatch(this._priors.externalPass);
115
+ return;
116
+ }
117
+ if (this._priors.externalEncoder) {
118
+ const passDescriptor = {
119
+ label: getName(this._core) ?? "<unnamed>",
120
+ ...setupTimestampWrites(this._priors, root)
121
+ };
122
+ const pass = this._priors.externalEncoder.beginComputePass(passDescriptor);
123
+ this._applyComputeState(pass);
124
+ dispatch(pass);
125
+ pass.end();
126
+ return;
127
+ }
128
+ const memo = this._core.unwrap();
129
+ const passDescriptor = {
130
+ label: getName(this._core) ?? "<unnamed>",
131
+ ...setupTimestampWrites(this._priors, root)
132
+ };
133
+ const commandEncoder = root.device.createCommandEncoder();
134
+ const pass = commandEncoder.beginComputePass(passDescriptor);
135
+ this._applyComputeState(pass);
136
+ dispatch(pass);
137
+ pass.end();
138
+ root.device.queue.submit([commandEncoder.finish()]);
139
+ if (memo.logResources) logDataFromGPU(memo.logResources);
140
+ if (this._priors.performanceCallback) triggerPerformanceCallback({
141
+ root,
142
+ priors: this._priors
143
+ });
144
+ }
145
+ $name(label) {
146
+ setName(this, label);
147
+ return this;
148
+ }
149
+ };
150
+ var ComputePipelineCore = class {
151
+ [$internal] = true;
152
+ _memo;
153
+ #slotBindings;
154
+ #descriptor;
155
+ constructor(root, slotBindings, descriptor) {
156
+ this.root = root;
157
+ this.#slotBindings = slotBindings;
158
+ this.#descriptor = descriptor;
159
+ }
160
+ [$resolve](ctx) {
161
+ return ctx.withSlots(this.#slotBindings, () => {
162
+ ctx.resolve(this.#descriptor.compute);
163
+ return snip("", Void, "runtime");
164
+ });
165
+ }
166
+ toString() {
167
+ return "computePipelineCore";
168
+ }
169
+ unwrap() {
170
+ if (this._memo === void 0) {
171
+ const device = this.root.device;
172
+ const enableExtensions = wgslExtensions.filter((extension) => this.root.enabledFeatures.has(wgslExtensionToFeatureName[extension]));
173
+ let resolutionResult;
174
+ let resolveMeasure;
175
+ const ns = namespace({ names: this.root.nameRegistrySetting });
176
+ if (PERF?.enabled) {
177
+ const resolveStart = performance.mark("typegpu:resolution:start");
178
+ resolutionResult = resolve(this, {
179
+ namespace: ns,
180
+ enableExtensions,
181
+ shaderGenerator: this.root.shaderGenerator,
182
+ root: this.root
183
+ });
184
+ resolveMeasure = performance.measure("typegpu:resolution", { start: resolveStart.name });
185
+ } else resolutionResult = resolve(this, {
186
+ namespace: ns,
187
+ enableExtensions,
188
+ shaderGenerator: this.root.shaderGenerator,
189
+ root: this.root
190
+ });
191
+ const { code, usedBindGroupLayouts, catchall, logResources } = resolutionResult;
192
+ if (catchall !== void 0) usedBindGroupLayouts[catchall[0]]?.$name(`${getName(this) ?? "<unnamed>"} - Automatic Bind Group & Layout`);
193
+ const module = device.createShaderModule({
194
+ label: `${getName(this) ?? "<unnamed>"} - Shader`,
195
+ code
196
+ });
197
+ this._memo = {
198
+ pipeline: device.createComputePipeline({
199
+ label: getName(this) ?? "<unnamed>",
200
+ layout: device.createPipelineLayout({
201
+ label: `${getName(this) ?? "<unnamed>"} - Pipeline Layout`,
202
+ bindGroupLayouts: usedBindGroupLayouts.map((l) => this.root.unwrap(l))
203
+ }),
204
+ compute: { module }
205
+ }),
206
+ usedBindGroupLayouts,
207
+ catchall,
208
+ logResources
209
+ };
210
+ if (PERF?.enabled) (async () => {
211
+ const start = performance.mark("typegpu:compile-start");
212
+ await device.queue.onSubmittedWorkDone();
213
+ const compileMeasure = performance.measure("typegpu:compiled", { start: start.name });
214
+ PERF?.record("resolution", {
215
+ resolveDuration: resolveMeasure?.duration,
216
+ compileDuration: compileMeasure.duration,
217
+ wgslSize: code.length
218
+ });
219
+ })();
220
+ }
221
+ return this._memo;
222
+ }
223
+ };
224
+
225
+ //#endregion
226
+ export { INTERNAL_createComputePipeline };
@@ -0,0 +1,26 @@
1
+ import { isWgslStruct } from "../../data/wgslTypes.js";
2
+ import { isBuiltin } from "../../data/attributes.js";
3
+
4
+ //#region src/core/pipeline/connectAttachmentToShader.ts
5
+ function isColorAttachment(value) {
6
+ return !!value?.view;
7
+ }
8
+ function connectAttachmentToShader(fragmentOut, attachment) {
9
+ if (isBuiltin(fragmentOut)) return [];
10
+ if (isWgslStruct(fragmentOut)) {
11
+ const result = [];
12
+ for (const key of Object.keys(fragmentOut.propTypes)) {
13
+ const outputValue = fragmentOut.propTypes[key];
14
+ if (isBuiltin(outputValue)) continue;
15
+ const matching = attachment[key];
16
+ if (!matching) throw new Error(`A color attachment by the name of '${key}' was not provided to the shader.`);
17
+ result.push(matching);
18
+ }
19
+ return result;
20
+ }
21
+ if (!isColorAttachment(attachment)) throw new Error("Expected a single color attachment, not a record.");
22
+ return [attachment];
23
+ }
24
+
25
+ //#endregion
26
+ export { connectAttachmentToShader };
@@ -0,0 +1,29 @@
1
+ import { isVoid, isWgslStruct } from "../../data/wgslTypes.js";
2
+ import { isBuiltin } from "../../data/attributes.js";
3
+
4
+ //#region src/core/pipeline/connectTargetsToShader.ts
5
+ function connectTargetsToShader(fragmentOut, targets) {
6
+ let presentationFormat;
7
+ if (isVoid(fragmentOut) || isBuiltin(fragmentOut)) return [null];
8
+ if (isWgslStruct(fragmentOut)) {
9
+ const result = [];
10
+ for (const key of Object.keys(fragmentOut.propTypes)) {
11
+ const outputValue = fragmentOut.propTypes[key];
12
+ if (isBuiltin(outputValue)) continue;
13
+ const matchingTarget = targets[key];
14
+ result.push({
15
+ ...matchingTarget,
16
+ format: matchingTarget?.format ?? (presentationFormat ??= navigator.gpu.getPreferredCanvasFormat())
17
+ });
18
+ }
19
+ return result;
20
+ }
21
+ const singleTarget = targets;
22
+ return [{
23
+ ...singleTarget,
24
+ format: singleTarget?.format ?? (presentationFormat ??= navigator.gpu.getPreferredCanvasFormat())
25
+ }];
26
+ }
27
+
28
+ //#endregion
29
+ export { connectTargetsToShader };
@@ -0,0 +1,13 @@
1
+ //#region src/core/pipeline/limitsOverflow.ts
2
+ function warnIfOverflow(layouts, limits) {
3
+ const entries = Object.values(layouts).flatMap((layout) => Object.values(layout.entries)).filter((entry) => entry !== null);
4
+ const uniform = entries.filter((entry) => "uniform" in entry).length;
5
+ const storage = entries.filter((entry) => "storage" in entry).length;
6
+ if (uniform > limits.maxUniformBuffersPerShaderStage) console.warn(`Total number of uniform buffers (${uniform}) exceeds maxUniformBuffersPerShaderStage (${limits.maxUniformBuffersPerShaderStage}). Consider:
7
+ 1. Grouping some of the uniforms into one using 'd.struct',
8
+ 2. Increasing the limit when requesting a device or creating a root.`);
9
+ if (storage > limits.maxStorageBuffersPerShaderStage) console.warn(`Total number of storage buffers (${storage}) exceeds maxStorageBuffersPerShaderStage (${limits.maxStorageBuffersPerShaderStage}).`);
10
+ }
11
+
12
+ //#endregion
13
+ export { warnIfOverflow };
@@ -0,0 +1,266 @@
1
+ import { TgpuNamable } from "../../shared/meta.js";
2
+ import { $internal, $resolve } from "../../shared/symbols.js";
3
+ import { AnyBuiltin, OmitBuiltins } from "../../builtin.js";
4
+ import "../querySet/querySet.js";
5
+ import { ResolvedSnippet } from "../../data/snippet.js";
6
+ import { LogResources } from "../../tgsl/consoleLog/types.js";
7
+ import { TgpuSlot } from "../slot/slotTypes.js";
8
+ import { Timeable, TimestampWritesPriors } from "./timeable.js";
9
+ import { AnyVertexAttribs } from "../../shared/vertexFormat.js";
10
+ import { AnyAutoCustoms, AutoFragmentIn, AutoFragmentOut, AutoVertexIn, AutoVertexOut } from "../function/autoIO.js";
11
+ import { TgpuFragmentFn } from "../function/tgpuFragmentFn.js";
12
+ import { TgpuVertexFn } from "../function/tgpuVertexFn.js";
13
+ import { RenderFlag } from "../texture/usageExtension.js";
14
+ import { TgpuVertexLayout } from "../vertexLayout/vertexLayout.js";
15
+ import { TgpuBindGroup, TgpuBindGroupLayout, TgpuLayoutEntry } from "../../tgpuBindGroupLayout.js";
16
+ import { ExperimentalTgpuRoot } from "../root/rootTypes.js";
17
+ import { IndexFlag, TgpuBuffer, VertexFlag } from "../buffer/buffer.js";
18
+ import { ResolutionCtx, SelfResolvable } from "../../types.js";
19
+ import { AnyVecInstance, BaseData, U16, U32, Void, WgslArray, v4f } from "../../data/wgslTypes.js";
20
+ import { WgslTexture, WgslTextureDepth2d, WgslTextureDepthMultisampled2d } from "../../data/texture.js";
21
+ import { TextureInternals, TgpuTextureRenderView, TgpuTextureView } from "../texture/texture.js";
22
+ import { Disarray, UndecorateRecord } from "../../data/dataTypes.js";
23
+
24
+ //#region src/core/pipeline/renderPipeline.d.ts
25
+ interface RenderPipelineInternals {
26
+ readonly core: RenderPipelineCore;
27
+ readonly priors: TgpuRenderPipelinePriors & TimestampWritesPriors;
28
+ readonly root: ExperimentalTgpuRoot;
29
+ }
30
+ type TgpuPrimitiveState = GPUPrimitiveState | (Omit<GPUPrimitiveState, 'stripIndexFormat'> & {
31
+ stripIndexFormat?: U32 | U16;
32
+ }) | undefined;
33
+ type TgpuColorTargetState = (Omit<GPUColorTargetState, 'format'> & {
34
+ /**
35
+ * The {@link GPUTextureFormat} of this color target. The pipeline will only be compatible with
36
+ * {@link GPURenderPassEncoder}s which use a {@link GPUTextureView} of this format in the
37
+ * corresponding color attachment.
38
+ *
39
+ * @default navigator.gpu.getPreferredCanvasFormat()
40
+ */
41
+ format?: GPUTextureFormat | undefined;
42
+ }) | undefined;
43
+ interface HasIndexBuffer {
44
+ readonly hasIndexBuffer: true;
45
+ drawIndexed(indexCount: number, instanceCount?: number, firstIndex?: number, baseVertex?: number, firstInstance?: number): void;
46
+ }
47
+ interface TgpuRenderPipeline<in Targets = never> extends TgpuNamable, SelfResolvable, Timeable {
48
+ readonly [$internal]: RenderPipelineInternals;
49
+ readonly resourceType: 'render-pipeline';
50
+ readonly hasIndexBuffer: boolean;
51
+ with<TData extends WgslArray | Disarray>(vertexLayout: TgpuVertexLayout<TData>, buffer: (TgpuBuffer<TData> & VertexFlag) | GPUBuffer): this;
52
+ /**
53
+ * @deprecated This overload is outdated.
54
+ * Call `pipeline.with(bindGroup)` instead.
55
+ */
56
+ with<Entries extends Record<string, TgpuLayoutEntry | null>>(bindGroupLayout: TgpuBindGroupLayout<Entries>, bindGroup: TgpuBindGroup<Entries>): this;
57
+ with(bindGroupLayout: TgpuBindGroupLayout, bindGroup: GPUBindGroup): this;
58
+ with(bindGroup: TgpuBindGroup): this;
59
+ with(encoder: GPUCommandEncoder): this;
60
+ with(pass: GPURenderPassEncoder): this;
61
+ with(bundleEncoder: GPURenderBundleEncoder): this;
62
+ /**
63
+ * Attaches texture views to the pipeline's targets (outputs).
64
+ *
65
+ * @example
66
+ * // Draw 3 vertices onto the context's canvas
67
+ * pipeline
68
+ * .withColorAttachment({ view: context })
69
+ * .draw(3)
70
+ *
71
+ * @param attachment The object should match the shape
72
+ * returned by the fragment shader, with values matching the {@link ColorAttachment} type.
73
+ */
74
+ withColorAttachment(attachment: FragmentOutToColorAttachment<Targets>): this;
75
+ withDepthStencilAttachment(attachment: DepthStencilAttachment): this;
76
+ withStencilReference(reference: GPUStencilValue): this;
77
+ withIndexBuffer(buffer: TgpuBuffer<BaseData> & IndexFlag, offsetElements?: number, sizeElements?: number): this & HasIndexBuffer;
78
+ withIndexBuffer(buffer: GPUBuffer, indexFormat: GPUIndexFormat, offsetBytes?: number, sizeBytes?: number): this & HasIndexBuffer;
79
+ draw(vertexCount: number, instanceCount?: number, firstVertex?: number, firstInstance?: number): void;
80
+ drawIndirect(indirectBuffer: TgpuBuffer<BaseData> | GPUBuffer, indirectOffset?: GPUSize64): void;
81
+ drawIndexedIndirect(indirectBuffer: TgpuBuffer<BaseData> | GPUBuffer, indirectOffset?: GPUSize64): void;
82
+ }
83
+ declare namespace TgpuRenderPipeline {
84
+ interface DescriptorBase {
85
+ /**
86
+ * Describes the primitive-related properties of the pipeline.
87
+ */
88
+ primitive?: TgpuPrimitiveState | undefined;
89
+ /**
90
+ * Describes the optional depth-stencil properties, including the testing, operations, and bias.
91
+ */
92
+ depthStencil?: GPUDepthStencilState | undefined;
93
+ /**
94
+ * Describes the multi-sampling properties of the pipeline.
95
+ */
96
+ multisample?: GPUMultisampleState | undefined;
97
+ }
98
+ interface Descriptor extends DescriptorBase {
99
+ vertex: TgpuVertexFn | ((input: AutoVertexIn<Record<string, never>>) => AutoVertexOut<AnyAutoCustoms>);
100
+ fragment?: TgpuFragmentFn | ((input: AutoFragmentIn<Record<string, never>>) => AutoFragmentOut<undefined | v4f | AnyAutoCustoms>) | undefined;
101
+ attribs?: AnyVertexAttribs | undefined;
102
+ targets?: AnyFragmentTargets | undefined;
103
+ }
104
+ }
105
+ type FragmentOutToTargets<T> = T extends undefined | AnyBuiltin | Void | Record<string, never> ? Record<string, never> | undefined : T extends {
106
+ readonly [$internal]: unknown;
107
+ } | number | boolean | AnyVecInstance ? TgpuColorTargetState : T extends Record<string, unknown> ? { [Key in keyof OmitBuiltins<T>]?: TgpuColorTargetState } | undefined : TgpuColorTargetState | Record<string, TgpuColorTargetState>;
108
+ type FragmentOutToColorAttachment<T> = T extends {
109
+ readonly [$internal]: unknown;
110
+ } ? ColorAttachment : T extends Record<string, unknown> ? { [Key in keyof UndecorateRecord<T>]: ColorAttachment } : Record<string, never>;
111
+ type AnyFragmentTargets = TgpuColorTargetState | Record<string, TgpuColorTargetState>;
112
+ interface ColorTextureConstraint {
113
+ readonly [$internal]: TextureInternals;
114
+ readonly resourceType: 'texture';
115
+ readonly props: {
116
+ format: GPUTextureFormat;
117
+ };
118
+ }
119
+ interface ColorAttachment {
120
+ /**
121
+ * A {@link GPUTextureView} describing the texture subresource that will be output to for this
122
+ * color attachment.
123
+ */
124
+ view: (ColorTextureConstraint & RenderFlag) | GPUTextureView | TgpuTextureView<WgslTexture> | TgpuTextureRenderView | GPUCanvasContext;
125
+ /**
126
+ * Indicates the depth slice index of {@link GPUTextureViewDimension#"3d"} {@link GPURenderPassColorAttachment#view}
127
+ * that will be output to for this color attachment.
128
+ */
129
+ depthSlice?: GPUIntegerCoordinate;
130
+ /**
131
+ * A {@link GPUTextureView} describing the texture subresource that will receive the resolved
132
+ * output for this color attachment if {@link GPURenderPassColorAttachment#view} is
133
+ * multisampled.
134
+ */
135
+ resolveTarget?: (ColorTextureConstraint & RenderFlag) | GPUTextureView | TgpuTextureView<WgslTexture> | TgpuTextureRenderView | GPUCanvasContext;
136
+ /**
137
+ * Indicates the value to clear {@link GPURenderPassColorAttachment#view} to prior to executing the
138
+ * render pass. If not map/exist|provided, defaults to `{r: 0, g: 0, b: 0, a: 0}`. Ignored
139
+ * if {@link GPURenderPassColorAttachment#loadOp} is not {@link GPULoadOp#"clear"}.
140
+ * The components of {@link GPURenderPassColorAttachment#clearValue} are all double values.
141
+ * They are converted to a texel value of texture format matching the render attachment.
142
+ * If conversion fails, a validation error is generated.
143
+ */
144
+ clearValue?: GPUColor;
145
+ /**
146
+ * Indicates the load operation to perform on {@link GPURenderPassColorAttachment#view} prior to
147
+ * executing the render pass.
148
+ * Note: It is recommended to prefer clearing; see {@link GPULoadOp#"clear"} for details.
149
+ *
150
+ * @default 'clear'
151
+ */
152
+ loadOp?: GPULoadOp | undefined;
153
+ /**
154
+ * The store operation to perform on {@link GPURenderPassColorAttachment#view}
155
+ * after executing the render pass.
156
+ *
157
+ * @default 'store'
158
+ */
159
+ storeOp?: GPUStoreOp | undefined;
160
+ }
161
+ type DepthStencilFormat = 'stencil8' | 'depth16unorm' | 'depth24plus' | 'depth24plus-stencil8' | 'depth32float' | 'depth32float-stencil8';
162
+ interface DepthStencilTextureConstraint {
163
+ readonly [$internal]: TextureInternals;
164
+ readonly resourceType: 'texture';
165
+ readonly props: {
166
+ format: DepthStencilFormat;
167
+ };
168
+ }
169
+ interface DepthStencilAttachment {
170
+ /**
171
+ * A {@link GPUTextureView} | ({@link TgpuTexture} & {@link RenderFlag}) describing the texture subresource that will be output to
172
+ * and read from for this depth/stencil attachment.
173
+ */
174
+ view: (DepthStencilTextureConstraint & RenderFlag) | TgpuTextureView<WgslTextureDepth2d | WgslTextureDepthMultisampled2d> | TgpuTextureRenderView | GPUTextureView;
175
+ /**
176
+ * Indicates the value to clear {@link GPURenderPassDepthStencilAttachment#view}'s depth component
177
+ * to prior to executing the render pass. Ignored if {@link GPURenderPassDepthStencilAttachment#depthLoadOp}
178
+ * is not {@link GPULoadOp#"clear"}. Must be between 0.0 and 1.0, inclusive (unless unrestricted depth is enabled).
179
+ */
180
+ depthClearValue?: number;
181
+ /**
182
+ * Indicates the load operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s
183
+ * depth component prior to executing the render pass.
184
+ * Note: It is recommended to prefer clearing; see {@link GPULoadOp#"clear"} for details.
185
+ */
186
+ depthLoadOp?: GPULoadOp;
187
+ /**
188
+ * The store operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s
189
+ * depth component after executing the render pass.
190
+ */
191
+ depthStoreOp?: GPUStoreOp;
192
+ /**
193
+ * Indicates that the depth component of {@link GPURenderPassDepthStencilAttachment#view}
194
+ * is read only.
195
+ */
196
+ depthReadOnly?: boolean;
197
+ /**
198
+ * Indicates the value to clear {@link GPURenderPassDepthStencilAttachment#view}'s stencil component
199
+ * to prior to executing the render pass. Ignored if {@link GPURenderPassDepthStencilAttachment#stencilLoadOp}
200
+ * is not {@link GPULoadOp#"clear"}.
201
+ * The value will be converted to the type of the stencil aspect of `view` by taking the same
202
+ * number of LSBs as the number of bits in the stencil aspect of one texel block|texel of `view`.
203
+ */
204
+ stencilClearValue?: GPUStencilValue;
205
+ /**
206
+ * Indicates the load operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s
207
+ * stencil component prior to executing the render pass.
208
+ * Note: It is recommended to prefer clearing; see {@link GPULoadOp#"clear"} for details.
209
+ */
210
+ stencilLoadOp?: GPULoadOp;
211
+ /**
212
+ * The store operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s
213
+ * stencil component after executing the render pass.
214
+ */
215
+ stencilStoreOp?: GPUStoreOp;
216
+ /**
217
+ * Indicates that the stencil component of {@link GPURenderPassDepthStencilAttachment#view}
218
+ * is read only.
219
+ */
220
+ stencilReadOnly?: boolean;
221
+ }
222
+ type AnyFragmentColorAttachment = ColorAttachment | Record<string, ColorAttachment>;
223
+ type RenderPipelineCoreOptions = {
224
+ root: ExperimentalTgpuRoot;
225
+ slotBindings: [TgpuSlot<unknown>, unknown][];
226
+ descriptor: TgpuRenderPipeline.Descriptor;
227
+ };
228
+ type TgpuRenderPipelinePriors = {
229
+ readonly vertexLayoutMap?: Map<TgpuVertexLayout, (TgpuBuffer<BaseData> & VertexFlag) | GPUBuffer> | undefined;
230
+ readonly bindGroupLayoutMap?: Map<TgpuBindGroupLayout, TgpuBindGroup | GPUBindGroup> | undefined;
231
+ readonly colorAttachment?: AnyFragmentColorAttachment | undefined;
232
+ readonly depthStencilAttachment?: DepthStencilAttachment | undefined;
233
+ readonly stencilReference?: GPUStencilValue | undefined;
234
+ readonly indexBuffer?: {
235
+ buffer: (TgpuBuffer<BaseData> & IndexFlag) | GPUBuffer;
236
+ indexFormat: GPUIndexFormat;
237
+ offsetBytes?: number | undefined;
238
+ sizeBytes?: number | undefined;
239
+ } | undefined;
240
+ readonly externalEncoder?: GPUCommandEncoder | undefined;
241
+ readonly externalRenderEncoder?: GPURenderPassEncoder | GPURenderBundleEncoder | undefined;
242
+ } & TimestampWritesPriors;
243
+ type Memo = {
244
+ pipeline: GPURenderPipeline;
245
+ usedBindGroupLayouts: TgpuBindGroupLayout[];
246
+ catchall: [number, TgpuBindGroup] | undefined;
247
+ logResources: LogResources | undefined;
248
+ usedVertexLayouts: TgpuVertexLayout[];
249
+ fragmentOut: BaseData;
250
+ };
251
+ declare class RenderPipelineCore implements SelfResolvable {
252
+ #private;
253
+ readonly options: RenderPipelineCoreOptions;
254
+ readonly [$internal] = true;
255
+ private _memo;
256
+ constructor(options: RenderPipelineCoreOptions);
257
+ [$resolve](ctx: ResolutionCtx): ResolvedSnippet;
258
+ toString(): string;
259
+ unwrap(): Memo;
260
+ }
261
+ /**
262
+ * Assumes vertexOut and fragmentIn are matching when it comes to the keys, that is fragmentIn's keyset is a subset of vertexOut's
263
+ * Logs a warning, when they don't match in terms of custom locations
264
+ */
265
+ //#endregion
266
+ export { ColorAttachment, FragmentOutToTargets, TgpuPrimitiveState, TgpuRenderPipeline };