typegpu 0.11.8 → 0.12.0

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 (362) hide show
  1. package/builtin.d.ts +51 -53
  2. package/builtin.js +30 -34
  3. package/common/fullScreenTriangle.d.ts +2 -10
  4. package/common/fullScreenTriangle.js +20 -28
  5. package/common/index.d.ts +2 -9
  6. package/common/index.js +3 -12
  7. package/common/writeSoA.d.ts +11 -12
  8. package/common/writeSoA.js +88 -76
  9. package/core/buffer/buffer.d.ts +79 -62
  10. package/core/buffer/buffer.js +279 -205
  11. package/core/buffer/bufferBinding.d.ts +71 -0
  12. package/core/buffer/bufferBinding.js +154 -0
  13. package/core/buffer/bufferUsage.d.ts +14 -45
  14. package/core/buffer/bufferUsage.js +1 -171
  15. package/core/buffer/laidOutBuffer.d.ts +25 -0
  16. package/core/buffer/laidOutBuffer.js +55 -0
  17. package/core/commandEncoder/attachments.d.ts +125 -0
  18. package/core/commandEncoder/attachments.js +29 -0
  19. package/core/commandEncoder/commandEncoder.d.ts +53 -0
  20. package/core/commandEncoder/commandEncoder.js +56 -0
  21. package/core/commandEncoder/computePass.d.ts +58 -0
  22. package/core/commandEncoder/computePass.js +63 -0
  23. package/core/commandEncoder/renderPass.d.ts +121 -0
  24. package/core/commandEncoder/renderPass.js +196 -0
  25. package/core/constant/tgpuConstant.d.ts +26 -26
  26. package/core/constant/tgpuConstant.js +76 -65
  27. package/core/declare/tgpuDeclare.d.ts +3 -6
  28. package/core/declare/tgpuDeclare.js +37 -38
  29. package/core/function/autoIO.d.ts +61 -33
  30. package/core/function/autoIO.js +68 -73
  31. package/core/function/comptime.d.ts +11 -13
  32. package/core/function/comptime.js +60 -52
  33. package/core/function/createCallableSchema.d.ts +16 -0
  34. package/core/function/createCallableSchema.js +50 -40
  35. package/core/function/dualImpl.d.ts +44 -0
  36. package/core/function/dualImpl.js +71 -50
  37. package/core/function/entryInputRouter.d.ts +26 -0
  38. package/core/function/entryInputRouter.js +31 -33
  39. package/core/function/extractArgs.d.ts +38 -0
  40. package/core/function/extractArgs.js +202 -200
  41. package/core/function/fnCore.d.ts +44 -0
  42. package/core/function/fnCore.js +148 -92
  43. package/core/function/fnTypes.d.ts +31 -29
  44. package/core/function/fnTypes.js +1 -0
  45. package/core/function/ioSchema.d.ts +12 -10
  46. package/core/function/ioSchema.js +65 -47
  47. package/core/function/shelllessImpl.d.ts +9 -12
  48. package/core/function/shelllessImpl.js +18 -20
  49. package/core/function/templateUtils.d.ts +2 -0
  50. package/core/function/templateUtils.js +9 -8
  51. package/core/function/tgpuComputeFn.d.ts +26 -28
  52. package/core/function/tgpuComputeFn.js +47 -48
  53. package/core/function/tgpuFn.d.ts +34 -37
  54. package/core/function/tgpuFn.js +179 -153
  55. package/core/function/tgpuFragmentFn.d.ts +52 -53
  56. package/core/function/tgpuFragmentFn.js +63 -56
  57. package/core/function/tgpuVertexFn.d.ts +36 -39
  58. package/core/function/tgpuVertexFn.js +56 -53
  59. package/core/pipeline/computePipeline.d.ts +141 -53
  60. package/core/pipeline/computePipeline.js +291 -225
  61. package/core/pipeline/connectAttachmentToShader.d.ts +4 -0
  62. package/core/pipeline/connectAttachmentToShader.js +25 -22
  63. package/core/pipeline/connectTargetsToShader.d.ts +3 -0
  64. package/core/pipeline/connectTargetsToShader.js +29 -27
  65. package/core/pipeline/drawState.d.ts +52 -0
  66. package/core/pipeline/drawState.js +225 -0
  67. package/core/pipeline/limitsOverflow.d.ts +2 -0
  68. package/core/pipeline/limitsOverflow.js +13 -10
  69. package/core/pipeline/performanceTracker.d.ts +14 -0
  70. package/core/pipeline/performanceTracker.js +34 -0
  71. package/core/pipeline/pipelineUtils.d.ts +18 -0
  72. package/core/pipeline/pipelineUtils.js +54 -25
  73. package/core/pipeline/priors.d.ts +1 -0
  74. package/core/pipeline/priors.js +12 -0
  75. package/core/pipeline/renderPipeline.d.ts +246 -261
  76. package/core/pipeline/renderPipeline.js +487 -480
  77. package/core/pipeline/timeable.d.ts +28 -18
  78. package/core/pipeline/timeable.js +90 -52
  79. package/core/pipeline/typeGuards.d.ts +17 -0
  80. package/core/pipeline/typeGuards.js +52 -22
  81. package/core/querySet/querySet.d.ts +26 -21
  82. package/core/querySet/querySet.js +127 -103
  83. package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +13 -18
  84. package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +90 -93
  85. package/core/resolve/externals.d.ts +25 -7
  86. package/core/resolve/externals.js +79 -62
  87. package/core/resolve/namespace.d.ts +22 -25
  88. package/core/resolve/namespace.js +16 -21
  89. package/core/resolve/resolvableString.d.ts +7 -0
  90. package/core/resolve/resolvableString.js +13 -0
  91. package/core/resolve/resolveData.d.ts +10 -0
  92. package/core/resolve/resolveData.js +162 -121
  93. package/core/resolve/stitch.d.ts +8 -0
  94. package/core/resolve/stitch.js +23 -21
  95. package/core/resolve/tgpuResolve.d.ts +55 -53
  96. package/core/resolve/tgpuResolve.js +106 -55
  97. package/core/root/configurableImpl.d.ts +10 -0
  98. package/core/root/configurableImpl.js +17 -19
  99. package/core/root/init.d.ts +76 -38
  100. package/core/root/init.js +346 -454
  101. package/core/root/rootTypes.d.ts +461 -627
  102. package/core/root/rootTypes.js +1 -0
  103. package/core/sampler/sampler.d.ts +50 -31
  104. package/core/sampler/sampler.js +120 -113
  105. package/core/simulate/tgpuSimulate.d.ts +9 -12
  106. package/core/simulate/tgpuSimulate.js +68 -71
  107. package/core/slot/accessor.d.ts +36 -13
  108. package/core/slot/accessor.js +138 -91
  109. package/core/slot/internalSlots.d.ts +2 -0
  110. package/core/slot/internalSlots.js +1 -6
  111. package/core/slot/lazy.d.ts +2 -6
  112. package/core/slot/lazy.js +71 -39
  113. package/core/slot/slot.d.ts +2 -6
  114. package/core/slot/slot.js +45 -38
  115. package/core/slot/slotTypes.d.ts +78 -80
  116. package/core/slot/slotTypes.js +11 -16
  117. package/core/texture/externalTexture.d.ts +20 -11
  118. package/core/texture/externalTexture.js +46 -46
  119. package/core/texture/texture.d.ts +152 -97
  120. package/core/texture/texture.js +407 -314
  121. package/core/texture/textureFormats.d.ts +42 -23
  122. package/core/texture/textureFormats.js +104 -75
  123. package/core/texture/textureProps.d.ts +7 -10
  124. package/core/texture/textureProps.js +1 -0
  125. package/core/texture/textureUtils.d.ts +8 -0
  126. package/core/texture/textureUtils.js +185 -179
  127. package/core/texture/usageExtension.d.ts +21 -18
  128. package/core/texture/usageExtension.js +13 -17
  129. package/core/unroll/tgpuUnroll.d.ts +20 -19
  130. package/core/unroll/tgpuUnroll.js +82 -91
  131. package/core/valueProxyUtils.d.ts +3 -0
  132. package/core/valueProxyUtils.js +52 -41
  133. package/core/variable/tgpuVariable.d.ts +26 -27
  134. package/core/variable/tgpuVariable.js +93 -96
  135. package/core/vertexLayout/connectAttributesToShader.d.ts +9 -0
  136. package/core/vertexLayout/connectAttributesToShader.js +61 -56
  137. package/core/vertexLayout/vertexAttribute.d.ts +21 -17
  138. package/core/vertexLayout/vertexAttribute.js +1 -0
  139. package/core/vertexLayout/vertexLayout.d.ts +24 -18
  140. package/core/vertexLayout/vertexLayout.js +130 -99
  141. package/core/whitespaces.d.ts +2 -0
  142. package/core/whitespaces.js +16 -0
  143. package/data/alignIO.d.ts +7 -0
  144. package/data/alignIO.js +13 -13
  145. package/data/alignmentOf.d.ts +5 -8
  146. package/data/alignmentOf.js +90 -75
  147. package/data/array.d.ts +6 -9
  148. package/data/array.js +48 -40
  149. package/data/atomic.d.ts +2 -7
  150. package/data/atomic.js +26 -23
  151. package/data/attributes.d.ts +19 -21
  152. package/data/attributes.js +192 -132
  153. package/data/autoStruct.d.ts +36 -3
  154. package/data/autoStruct.js +84 -81
  155. package/data/compiledIO.d.ts +5 -0
  156. package/data/compiledIO.js +231 -214
  157. package/data/dataIO.d.ts +13 -11
  158. package/data/dataIO.js +643 -589
  159. package/data/dataTypes.d.ts +83 -65
  160. package/data/dataTypes.js +66 -68
  161. package/data/deepEqual.d.ts +2 -7
  162. package/data/deepEqual.js +80 -55
  163. package/data/disarray.d.ts +6 -10
  164. package/data/disarray.js +52 -46
  165. package/data/float16Conversion.d.ts +4 -0
  166. package/data/float16Conversion.js +7 -0
  167. package/data/getLongestContiguousPrefix.d.ts +4 -8
  168. package/data/getLongestContiguousPrefix.js +6 -11
  169. package/data/index.d.ts +30 -31
  170. package/data/index.js +39 -172
  171. package/data/instanceToSchema.d.ts +24 -27
  172. package/data/instanceToSchema.js +1 -0
  173. package/data/isContiguous.d.ts +4 -8
  174. package/data/isContiguous.js +6 -11
  175. package/data/matrix.d.ts +21 -21
  176. package/data/matrix.js +513 -505
  177. package/data/numberOps.d.ts +6 -0
  178. package/data/numberOps.js +26 -20
  179. package/data/numeric.d.ts +21 -12
  180. package/data/numeric.js +287 -192
  181. package/data/offsetUtils.d.ts +9 -13
  182. package/data/offsetUtils.js +204 -144
  183. package/data/offsets.d.ts +8 -0
  184. package/data/offsets.js +33 -33
  185. package/data/partialIO.d.ts +13 -8
  186. package/data/partialIO.js +124 -113
  187. package/data/ptr.d.ts +12 -12
  188. package/data/ptr.js +42 -44
  189. package/data/ref.d.ts +40 -27
  190. package/data/ref.js +125 -95
  191. package/data/sampler.d.ts +99 -101
  192. package/data/sampler.js +17 -21
  193. package/data/schemaCallWrapper.d.ts +19 -0
  194. package/data/schemaCallWrapper.js +31 -26
  195. package/data/schemaMemoryLayout.d.ts +8 -0
  196. package/data/schemaMemoryLayout.js +213 -185
  197. package/data/sizeOf.d.ts +4 -8
  198. package/data/sizeOf.js +6 -11
  199. package/data/snippet.d.ts +96 -20
  200. package/data/snippet.js +75 -86
  201. package/data/struct.d.ts +4 -7
  202. package/data/struct.js +51 -39
  203. package/data/texture.d.ts +253 -250
  204. package/data/texture.js +238 -200
  205. package/data/unstruct.d.ts +2 -7
  206. package/data/unstruct.js +43 -37
  207. package/data/vector.d.ts +33 -21
  208. package/data/vector.js +234 -221
  209. package/data/vectorImpl.d.ts +231 -0
  210. package/data/vectorImpl.js +563 -515
  211. package/data/vectorOps.d.ts +63 -0
  212. package/data/vectorOps.js +642 -630
  213. package/data/vertexFormatData.d.ts +181 -184
  214. package/data/vertexFormatData.js +104 -106
  215. package/data/wgslTypes.d.ts +665 -600
  216. package/data/wgslTypes.js +220 -198
  217. package/errors.d.ts +50 -24
  218. package/errors.js +146 -120
  219. package/execMode.d.ts +16 -0
  220. package/execMode.js +47 -40
  221. package/extension.d.ts +13 -8
  222. package/extension.js +10 -16
  223. package/getGPUValue.d.ts +1 -0
  224. package/getGPUValue.js +2 -7
  225. package/index.d.ts +28 -68
  226. package/index.js +8 -28
  227. package/indexNamedExports.d.ts +69 -42
  228. package/indexNamedExports.js +25 -0
  229. package/internal.d.ts +16 -0
  230. package/internal.js +12 -0
  231. package/mathUtils.d.ts +5 -0
  232. package/mathUtils.js +7 -11
  233. package/memo.d.ts +11 -0
  234. package/memo.js +20 -22
  235. package/minify.d.ts +5 -0
  236. package/minify.js +93 -0
  237. package/nameUtils.d.ts +29 -0
  238. package/nameUtils.js +428 -398
  239. package/package.json +9 -3
  240. package/resolutionCtx.d.ts +162 -22
  241. package/resolutionCtx.js +911 -624
  242. package/serial/registry.d.ts +15 -0
  243. package/serial/registry.js +106 -0
  244. package/serial/restore.d.ts +49 -0
  245. package/serial/restore.js +68 -0
  246. package/serial/schema.d.ts +58 -0
  247. package/serial/schema.js +209 -0
  248. package/serial/types.d.ts +5 -0
  249. package/serial/types.js +1 -0
  250. package/shared/env.d.ts +9 -0
  251. package/shared/env.js +9 -12
  252. package/shared/generators.d.ts +4 -0
  253. package/shared/generators.js +10 -12
  254. package/shared/meta.d.ts +29 -14
  255. package/shared/meta.js +71 -55
  256. package/shared/normalizeMetadata.d.ts +32 -27
  257. package/shared/normalizeMetadata.js +23 -36
  258. package/shared/repr.d.ts +73 -55
  259. package/shared/repr.js +1 -0
  260. package/shared/soul.d.ts +17 -0
  261. package/shared/soul.js +1 -0
  262. package/shared/stringify.d.ts +2 -0
  263. package/shared/stringify.js +29 -20
  264. package/shared/symbols.d.ts +26 -20
  265. package/shared/symbols.js +79 -79
  266. package/shared/tseynit.d.ts +2 -0
  267. package/shared/tseynit.js +160 -75
  268. package/shared/utilityTypes.d.ts +30 -14
  269. package/shared/utilityTypes.js +2 -6
  270. package/shared/vertexFormat.d.ts +41 -43
  271. package/shared/vertexFormat.js +59 -62
  272. package/std/array.d.ts +2 -7
  273. package/std/array.js +18 -23
  274. package/std/atomic.d.ts +14 -18
  275. package/std/atomic.js +96 -95
  276. package/std/bitcast.d.ts +193 -10
  277. package/std/bitcast.js +309 -39
  278. package/std/boolean.d.ts +19 -33
  279. package/std/boolean.js +296 -288
  280. package/std/copy.d.ts +2 -7
  281. package/std/copy.js +27 -24
  282. package/std/derivative.d.ts +11 -15
  283. package/std/derivative.js +56 -79
  284. package/std/discard.d.ts +1 -6
  285. package/std/discard.js +7 -14
  286. package/std/environment.d.ts +19 -14
  287. package/std/environment.js +71 -51
  288. package/std/extensions.d.ts +2 -8
  289. package/std/extensions.js +10 -11
  290. package/std/index.d.ts +20 -24
  291. package/std/index.js +32 -187
  292. package/std/matrix.d.ts +6 -12
  293. package/std/matrix.js +60 -69
  294. package/std/numeric.d.ts +143 -146
  295. package/std/numeric.js +858 -749
  296. package/std/operators.d.ts +19 -27
  297. package/std/operators.js +227 -193
  298. package/std/packing.d.ts +5 -11
  299. package/std/packing.js +67 -75
  300. package/std/range.d.ts +6 -11
  301. package/std/range.js +48 -36
  302. package/std/subgroup.d.ts +33 -37
  303. package/std/subgroup.js +180 -217
  304. package/std/texture.d.ts +70 -38
  305. package/std/texture.js +176 -172
  306. package/taskQueue.d.ts +6 -0
  307. package/taskQueue.js +30 -0
  308. package/tgpu.d.ts +16 -0
  309. package/tgpu.js +17 -44
  310. package/tgpuBindGroupLayout.d.ts +132 -152
  311. package/tgpuBindGroupLayout.js +346 -268
  312. package/tgpuLogger.d.ts +34 -0
  313. package/tgpuLogger.js +63 -0
  314. package/tgpuUnstable.d.ts +16 -22
  315. package/tgpuUnstable.js +13 -35
  316. package/tgsl/accessIndex.d.ts +2 -0
  317. package/tgsl/accessIndex.js +76 -33
  318. package/tgsl/accessProp.d.ts +2 -0
  319. package/tgsl/accessProp.js +142 -100
  320. package/tgsl/accessStructProp.d.ts +5 -0
  321. package/tgsl/accessStructProp.js +18 -0
  322. package/tgsl/consoleLog/deserializers.d.ts +13 -0
  323. package/tgsl/consoleLog/deserializers.js +119 -103
  324. package/tgsl/consoleLog/logGenerator.d.ts +21 -0
  325. package/tgsl/consoleLog/logGenerator.js +85 -80
  326. package/tgsl/consoleLog/serializers.d.ts +21 -0
  327. package/tgsl/consoleLog/serializers.js +119 -100
  328. package/tgsl/consoleLog/types.d.ts +40 -39
  329. package/tgsl/consoleLog/types.js +1 -0
  330. package/tgsl/conversion.d.ts +33 -0
  331. package/tgsl/conversion.js +272 -193
  332. package/tgsl/forOfUtils.d.ts +15 -0
  333. package/tgsl/forOfUtils.js +85 -70
  334. package/tgsl/generationHelpers.d.ts +22 -39
  335. package/tgsl/generationHelpers.js +85 -58
  336. package/tgsl/infixDispatch.d.ts +70 -0
  337. package/tgsl/infixDispatch.js +48 -46
  338. package/tgsl/jsPolyfills.d.ts +16 -19
  339. package/tgsl/jsPolyfills.js +44 -42
  340. package/tgsl/makeDereferenceable.d.ts +48 -0
  341. package/tgsl/makeDereferenceable.js +86 -0
  342. package/tgsl/makeResolvable.d.ts +22 -0
  343. package/tgsl/makeResolvable.js +33 -0
  344. package/tgsl/shaderGenerator.d.ts +77 -17
  345. package/tgsl/shaderGenerator.js +1 -0
  346. package/tgsl/shellless.d.ts +6 -9
  347. package/tgsl/shellless.js +73 -43
  348. package/tgsl/wgslGenerator.d.ts +66 -59
  349. package/tgsl/wgslGenerator.js +1344 -747
  350. package/types.d.ts +287 -221
  351. package/types.js +61 -44
  352. package/unwrapper.d.ts +31 -26
  353. package/unwrapper.js +1 -0
  354. package/wgslExtensions.d.ts +3 -5
  355. package/wgslExtensions.js +12 -16
  356. package/_virtual/rolldown_runtime.js +0 -13
  357. package/core/buffer/bufferShorthand.d.ts +0 -50
  358. package/core/buffer/bufferShorthand.js +0 -55
  359. package/core/pipeline/applyPipelineState.js +0 -37
  360. package/package.js +0 -5
  361. package/tgsl/shaderGenerator_members.d.ts +0 -33
  362. package/tgsl/shaderGenerator_members.js +0 -12
package/std/numeric.js CHANGED
@@ -1,847 +1,956 @@
1
- import { isHalfPrecisionSchema, isVecInstance } from "../data/wgslTypes.js";
2
- import { SignatureNotSupportedError } from "../errors.js";
1
+ import { dualImpl, MissingCpuImplError } from "../core/function/dualImpl.js";
3
2
  import { stitch } from "../core/resolve/stitch.js";
4
- import { unify } from "../tgsl/conversion.js";
5
- import { abstractFloat, abstractInt, f16, f32, i32, u32 } from "../data/numeric.js";
6
- import { vec2f, vec2h, vec2i, vec2u, vec3f, vec3h, vec3i, vec3u, vec4f, vec4h, vec4i, vec4u } from "../data/vector.js";
7
- import { abstruct } from "../data/struct.js";
8
- import { MissingCpuImplError, dualImpl } from "../core/function/dualImpl.js";
9
3
  import { mat2x2f, mat3x3f, mat4x4f } from "../data/matrix.js";
10
4
  import { smoothstepScalar } from "../data/numberOps.js";
5
+ import { abstractFloat, abstractInt, f16, f32, i32, u32 } from "../data/numeric.js";
6
+ import { abstruct } from "../data/struct.js";
7
+ import { vec2f, vec2h, vec2i, vec2u, vec3f, vec3h, vec3i, vec3u, vec4f, vec4h, vec4i, vec4u, } from "../data/vector.js";
11
8
  import { VectorOps } from "../data/vectorOps.js";
9
+ import { isHalfPrecisionSchema, isVecInstance, WORKAROUND_getSchema, } from "../data/wgslTypes.js";
10
+ import { SignatureNotSupportedError } from "../errors.js";
11
+ import { assertExhaustive } from "../shared/utilityTypes.js";
12
+ import { unify } from "../tgsl/conversion.js";
12
13
  import { mul, sub } from "./operators.js";
13
-
14
- //#region src/std/numeric.ts
14
+ // helpers
15
15
  const unaryIdentitySignature = (arg) => {
16
- return {
17
- argTypes: [arg],
18
- returnType: arg
19
- };
16
+ return {
17
+ argTypes: [arg],
18
+ returnType: arg,
19
+ };
20
20
  };
21
21
  const variadicUnifySignature = (...args) => {
22
- const uargs = unify(args) ?? args;
23
- return {
24
- argTypes: uargs,
25
- returnType: uargs[0]
26
- };
22
+ const uargs = unify(args) ?? args;
23
+ return {
24
+ argTypes: uargs,
25
+ returnType: uargs[0],
26
+ };
27
27
  };
28
28
  const unifyRestrictedSignature = (restrict) => (...args) => {
29
- const uargs = unify(args, restrict);
30
- if (!uargs) throw new SignatureNotSupportedError(args, restrict);
31
- return {
32
- argTypes: uargs,
33
- returnType: uargs[0]
34
- };
29
+ const uargs = unify(args, restrict);
30
+ if (!uargs) {
31
+ throw new SignatureNotSupportedError(args, restrict);
32
+ }
33
+ return {
34
+ argTypes: uargs,
35
+ returnType: uargs[0],
36
+ };
35
37
  };
36
38
  function variadicReduce(fn) {
37
- return (fst, ...rest) => {
38
- let acc = fst;
39
- for (const r of rest) acc = fn(acc, r);
40
- return acc;
41
- };
39
+ return (fst, ...rest) => {
40
+ let acc = fst;
41
+ for (const r of rest) {
42
+ acc = fn(acc, r);
43
+ }
44
+ return acc;
45
+ };
42
46
  }
43
47
  function variadicStitch(wrapper) {
44
- return (_ctx, [fst, ...rest]) => {
45
- let acc = stitch`${fst}`;
46
- for (const r of rest) acc = stitch`${wrapper}(${acc}, ${r})`;
47
- return acc;
48
- };
49
- }
50
- const anyFloatPrimitive = [
51
- f32,
52
- f16,
53
- abstractFloat
54
- ];
55
- const anyFloatVec = [
56
- vec2f,
57
- vec3f,
58
- vec4f,
59
- vec2h,
60
- vec3h,
61
- vec4h
62
- ];
48
+ return (_ctx, [fst, ...rest]) => {
49
+ let acc = stitch `${fst}`;
50
+ for (const r of rest) {
51
+ acc = stitch `${wrapper}(${acc}, ${r})`;
52
+ }
53
+ return acc;
54
+ };
55
+ }
56
+ const anyFloatPrimitive = [f32, f16, abstractFloat];
57
+ const anyFloatVec = [vec2f, vec3f, vec4f, vec2h, vec3h, vec4h];
63
58
  const anyFloat = [...anyFloatPrimitive, ...anyFloatVec];
64
59
  const anyConcreteIntegerPrimitive = [i32, u32];
65
- const anyConcreteIntegerVec = [
66
- vec2i,
67
- vec3i,
68
- vec4i,
69
- vec2u,
70
- vec3u,
71
- vec4u
72
- ];
60
+ const anyConcreteIntegerVec = [vec2i, vec3i, vec4i, vec2u, vec3u, vec4u];
73
61
  const anyConcreteInteger = [...anyConcreteIntegerPrimitive, ...anyConcreteIntegerVec];
74
62
  function cpuAbs(value) {
75
- if (typeof value === "number") return Math.abs(value);
76
- return VectorOps.abs[value.kind](value);
77
- }
78
- const abs = dualImpl({
79
- name: "abs",
80
- signature: unaryIdentitySignature,
81
- normalImpl: cpuAbs,
82
- codegenImpl: (_ctx, [value]) => stitch`abs(${value})`
63
+ if (typeof value === 'number') {
64
+ return Math.abs(value);
65
+ }
66
+ return VectorOps.abs[value.kind](value);
67
+ }
68
+ export const abs = dualImpl({
69
+ name: 'abs',
70
+ signature: unaryIdentitySignature,
71
+ normalImpl: cpuAbs,
72
+ codegenImpl: (_ctx, [value]) => stitch `abs(${value})`,
73
+ sideEffects: false,
83
74
  });
84
75
  function cpuAcos(value) {
85
- if (typeof value === "number") return Math.acos(value);
86
- return VectorOps.acos[value.kind](value);
87
- }
88
- const acos = dualImpl({
89
- name: "acos",
90
- signature: unifyRestrictedSignature(anyFloat),
91
- normalImpl: cpuAcos,
92
- codegenImpl: (_ctx, [value]) => stitch`acos(${value})`
76
+ if (typeof value === 'number') {
77
+ return Math.acos(value);
78
+ }
79
+ return VectorOps.acos[value.kind](value);
80
+ }
81
+ export const acos = dualImpl({
82
+ name: 'acos',
83
+ signature: unifyRestrictedSignature(anyFloat),
84
+ normalImpl: cpuAcos,
85
+ codegenImpl: (_ctx, [value]) => stitch `acos(${value})`,
86
+ sideEffects: false,
93
87
  });
94
88
  function cpuAcosh(value) {
95
- if (typeof value === "number") return Math.acosh(value);
96
- return VectorOps.acosh[value.kind](value);
97
- }
98
- const acosh = dualImpl({
99
- name: "acosh",
100
- signature: unifyRestrictedSignature(anyFloat),
101
- normalImpl: cpuAcosh,
102
- codegenImpl: (_ctx, [value]) => stitch`acosh(${value})`
89
+ if (typeof value === 'number') {
90
+ return Math.acosh(value);
91
+ }
92
+ return VectorOps.acosh[value.kind](value);
93
+ }
94
+ export const acosh = dualImpl({
95
+ name: 'acosh',
96
+ signature: unifyRestrictedSignature(anyFloat),
97
+ normalImpl: cpuAcosh,
98
+ codegenImpl: (_ctx, [value]) => stitch `acosh(${value})`,
99
+ sideEffects: false,
103
100
  });
104
101
  function cpuAsin(value) {
105
- if (typeof value === "number") return Math.asin(value);
106
- return VectorOps.asin[value.kind](value);
107
- }
108
- const asin = dualImpl({
109
- name: "asin",
110
- signature: unifyRestrictedSignature(anyFloat),
111
- normalImpl: cpuAsin,
112
- codegenImpl: (_ctx, [value]) => stitch`asin(${value})`
102
+ if (typeof value === 'number') {
103
+ return Math.asin(value);
104
+ }
105
+ return VectorOps.asin[value.kind](value);
106
+ }
107
+ export const asin = dualImpl({
108
+ name: 'asin',
109
+ signature: unifyRestrictedSignature(anyFloat),
110
+ normalImpl: cpuAsin,
111
+ codegenImpl: (_ctx, [value]) => stitch `asin(${value})`,
112
+ sideEffects: false,
113
113
  });
114
114
  function cpuAsinh(value) {
115
- if (typeof value === "number") return Math.asinh(value);
116
- return VectorOps.asinh[value.kind](value);
117
- }
118
- const asinh = dualImpl({
119
- name: "asinh",
120
- signature: unifyRestrictedSignature(anyFloat),
121
- normalImpl: cpuAsinh,
122
- codegenImpl: (_ctx, [value]) => stitch`asinh(${value})`
115
+ if (typeof value === 'number') {
116
+ return Math.asinh(value);
117
+ }
118
+ return VectorOps.asinh[value.kind](value);
119
+ }
120
+ export const asinh = dualImpl({
121
+ name: 'asinh',
122
+ signature: unifyRestrictedSignature(anyFloat),
123
+ normalImpl: cpuAsinh,
124
+ codegenImpl: (_ctx, [value]) => stitch `asinh(${value})`,
125
+ sideEffects: false,
123
126
  });
124
127
  function cpuAtan(value) {
125
- if (typeof value === "number") return Math.atan(value);
126
- return VectorOps.atan[value.kind](value);
127
- }
128
- const atan = dualImpl({
129
- name: "atan",
130
- signature: unifyRestrictedSignature(anyFloat),
131
- normalImpl: cpuAtan,
132
- codegenImpl: (_ctx, [value]) => stitch`atan(${value})`
128
+ if (typeof value === 'number') {
129
+ return Math.atan(value);
130
+ }
131
+ return VectorOps.atan[value.kind](value);
132
+ }
133
+ export const atan = dualImpl({
134
+ name: 'atan',
135
+ signature: unifyRestrictedSignature(anyFloat),
136
+ normalImpl: cpuAtan,
137
+ codegenImpl: (_ctx, [value]) => stitch `atan(${value})`,
138
+ sideEffects: false,
133
139
  });
134
140
  function cpuAtanh(value) {
135
- if (typeof value === "number") return Math.atanh(value);
136
- return VectorOps.atanh[value.kind](value);
137
- }
138
- const atanh = dualImpl({
139
- name: "atanh",
140
- signature: unifyRestrictedSignature(anyFloat),
141
- normalImpl: cpuAtanh,
142
- codegenImpl: (_ctx, [value]) => stitch`atanh(${value})`
141
+ if (typeof value === 'number') {
142
+ return Math.atanh(value);
143
+ }
144
+ return VectorOps.atanh[value.kind](value);
145
+ }
146
+ export const atanh = dualImpl({
147
+ name: 'atanh',
148
+ signature: unifyRestrictedSignature(anyFloat),
149
+ normalImpl: cpuAtanh,
150
+ codegenImpl: (_ctx, [value]) => stitch `atanh(${value})`,
151
+ sideEffects: false,
143
152
  });
144
153
  function cpuAtan2(y, x) {
145
- if (typeof y === "number" && typeof x === "number") return Math.atan2(y, x);
146
- return VectorOps.atan2[y.kind](y, x);
147
- }
148
- const atan2 = dualImpl({
149
- name: "atan2",
150
- signature: unifyRestrictedSignature(anyFloat),
151
- normalImpl: cpuAtan2,
152
- codegenImpl: (_ctx, [y, x]) => stitch`atan2(${y}, ${x})`
154
+ if (typeof y === 'number' && typeof x === 'number') {
155
+ return Math.atan2(y, x);
156
+ }
157
+ return VectorOps.atan2[y.kind](y, x);
158
+ }
159
+ export const atan2 = dualImpl({
160
+ name: 'atan2',
161
+ signature: unifyRestrictedSignature(anyFloat),
162
+ normalImpl: cpuAtan2,
163
+ codegenImpl: (_ctx, [y, x]) => stitch `atan2(${y}, ${x})`,
164
+ sideEffects: false,
153
165
  });
154
166
  function cpuCeil(value) {
155
- if (typeof value === "number") return Math.ceil(value);
156
- return VectorOps.ceil[value.kind](value);
157
- }
158
- const ceil = dualImpl({
159
- name: "ceil",
160
- signature: unifyRestrictedSignature(anyFloat),
161
- normalImpl: cpuCeil,
162
- codegenImpl: (_ctx, [value]) => stitch`ceil(${value})`
167
+ if (typeof value === 'number') {
168
+ return Math.ceil(value);
169
+ }
170
+ return VectorOps.ceil[value.kind](value);
171
+ }
172
+ export const ceil = dualImpl({
173
+ name: 'ceil',
174
+ signature: unifyRestrictedSignature(anyFloat),
175
+ normalImpl: cpuCeil,
176
+ codegenImpl: (_ctx, [value]) => stitch `ceil(${value})`,
177
+ sideEffects: false,
163
178
  });
164
179
  function cpuClamp(value, low, high) {
165
- if (typeof value === "number") return Math.min(Math.max(low, value), high);
166
- return VectorOps.clamp[value.kind](value, low, high);
167
- }
168
- const clamp = dualImpl({
169
- name: "clamp",
170
- signature: variadicUnifySignature,
171
- normalImpl: cpuClamp,
172
- codegenImpl: (_ctx, [value, low, high]) => stitch`clamp(${value}, ${low}, ${high})`
180
+ if (typeof value === 'number') {
181
+ return Math.min(Math.max(low, value), high);
182
+ }
183
+ return VectorOps.clamp[value.kind](value, low, high);
184
+ }
185
+ export const clamp = dualImpl({
186
+ name: 'clamp',
187
+ signature: variadicUnifySignature,
188
+ normalImpl: cpuClamp,
189
+ codegenImpl: (_ctx, [value, low, high]) => stitch `clamp(${value}, ${low}, ${high})`,
190
+ sideEffects: false,
173
191
  });
174
192
  function cpuCos(value) {
175
- if (typeof value === "number") return Math.cos(value);
176
- return VectorOps.cos[value.kind](value);
177
- }
178
- const cos = dualImpl({
179
- name: "cos",
180
- signature: unifyRestrictedSignature(anyFloat),
181
- normalImpl: cpuCos,
182
- codegenImpl: (_ctx, [value]) => stitch`cos(${value})`
193
+ if (typeof value === 'number') {
194
+ return Math.cos(value);
195
+ }
196
+ return VectorOps.cos[value.kind](value);
197
+ }
198
+ export const cos = dualImpl({
199
+ name: 'cos',
200
+ signature: unifyRestrictedSignature(anyFloat),
201
+ normalImpl: cpuCos,
202
+ codegenImpl: (_ctx, [value]) => stitch `cos(${value})`,
203
+ sideEffects: false,
183
204
  });
184
205
  function cpuCosh(value) {
185
- if (typeof value === "number") return Math.cosh(value);
186
- return VectorOps.cosh[value.kind](value);
187
- }
188
- const cosh = dualImpl({
189
- name: "cosh",
190
- signature: unifyRestrictedSignature(anyFloat),
191
- normalImpl: cpuCosh,
192
- codegenImpl: (_ctx, [value]) => stitch`cosh(${value})`
193
- });
194
- const countLeadingZeros = dualImpl({
195
- name: "countLeadingZeros",
196
- signature: unifyRestrictedSignature(anyConcreteInteger),
197
- normalImpl: "CPU implementation for countLeadingZeros not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
198
- codegenImpl: (_ctx, [value]) => stitch`countLeadingZeros(${value})`
199
- });
200
- const countOneBits = dualImpl({
201
- name: "countOneBits",
202
- signature: unifyRestrictedSignature(anyConcreteInteger),
203
- normalImpl: "CPU implementation for countOneBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
204
- codegenImpl: (_ctx, [value]) => stitch`countOneBits(${value})`
205
- });
206
- const countTrailingZeros = dualImpl({
207
- name: "countTrailingZeros",
208
- signature: unifyRestrictedSignature(anyConcreteInteger),
209
- normalImpl: "CPU implementation for countTrailingZeros not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
210
- codegenImpl: (_ctx, [value]) => stitch`countTrailingZeros(${value})`
211
- });
212
- const cross = dualImpl({
213
- name: "cross",
214
- signature: unifyRestrictedSignature([vec3f, vec3h]),
215
- normalImpl: (a, b) => VectorOps.cross[a.kind](a, b),
216
- codegenImpl: (_ctx, [a, b]) => stitch`cross(${a}, ${b})`
206
+ if (typeof value === 'number') {
207
+ return Math.cosh(value);
208
+ }
209
+ return VectorOps.cosh[value.kind](value);
210
+ }
211
+ export const cosh = dualImpl({
212
+ name: 'cosh',
213
+ signature: unifyRestrictedSignature(anyFloat),
214
+ normalImpl: cpuCosh,
215
+ codegenImpl: (_ctx, [value]) => stitch `cosh(${value})`,
216
+ sideEffects: false,
217
+ });
218
+ function cpuCountLeadingZeros(_value) {
219
+ throw new Error('Unreachable code. The function is only used for the type.');
220
+ }
221
+ export const countLeadingZeros = dualImpl({
222
+ name: 'countLeadingZeros',
223
+ signature: unifyRestrictedSignature(anyConcreteInteger),
224
+ normalImpl: 'CPU implementation for countLeadingZeros not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
225
+ codegenImpl: (_ctx, [value]) => stitch `countLeadingZeros(${value})`,
226
+ sideEffects: false,
227
+ });
228
+ function cpuCountOneBits(_value) {
229
+ throw new Error('Unreachable code. The function is only used for the type.');
230
+ }
231
+ export const countOneBits = dualImpl({
232
+ name: 'countOneBits',
233
+ signature: unifyRestrictedSignature(anyConcreteInteger),
234
+ normalImpl: 'CPU implementation for countOneBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
235
+ codegenImpl: (_ctx, [value]) => stitch `countOneBits(${value})`,
236
+ sideEffects: false,
237
+ });
238
+ function cpuCountTrailingZeros(_value) {
239
+ throw new Error('Unreachable code. The function is only used for the type.');
240
+ }
241
+ export const countTrailingZeros = dualImpl({
242
+ name: 'countTrailingZeros',
243
+ signature: unifyRestrictedSignature(anyConcreteInteger),
244
+ normalImpl: 'CPU implementation for countTrailingZeros not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
245
+ codegenImpl: (_ctx, [value]) => stitch `countTrailingZeros(${value})`,
246
+ sideEffects: false,
247
+ });
248
+ export const cross = dualImpl({
249
+ name: 'cross',
250
+ signature: unifyRestrictedSignature([vec3f, vec3h]),
251
+ normalImpl: (a, b) => VectorOps.cross[a.kind](a, b),
252
+ codegenImpl: (_ctx, [a, b]) => stitch `cross(${a}, ${b})`,
253
+ sideEffects: false,
217
254
  });
218
255
  function cpuDegrees(value) {
219
- if (typeof value === "number") return value * 180 / Math.PI;
220
- throw new MissingCpuImplError("CPU implementation for degrees on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
221
- }
222
- const degrees = dualImpl({
223
- name: "degrees",
224
- signature: unifyRestrictedSignature(anyFloat),
225
- normalImpl: cpuDegrees,
226
- codegenImpl: (_ctx, [value]) => stitch`degrees(${value})`
227
- });
228
- const determinant = dualImpl({
229
- name: "determinant",
230
- signature: (arg) => {
231
- if (!(arg.type === "mat2x2f" || arg.type === "mat3x3f" || arg.type === "mat4x4f")) throw new SignatureNotSupportedError([arg], [
232
- mat2x2f,
233
- mat3x3f,
234
- mat4x4f
235
- ]);
236
- return {
237
- argTypes: [arg],
238
- returnType: f32
239
- };
240
- },
241
- normalImpl: "CPU implementation for determinant not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
242
- codegenImpl: (_ctx, [value]) => stitch`determinant(${value})`
256
+ if (typeof value === 'number') {
257
+ return ((value * 180) / Math.PI);
258
+ }
259
+ throw new MissingCpuImplError('CPU implementation for degrees on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
260
+ }
261
+ export const degrees = dualImpl({
262
+ name: 'degrees',
263
+ signature: unifyRestrictedSignature(anyFloat),
264
+ normalImpl: cpuDegrees,
265
+ codegenImpl: (_ctx, [value]) => stitch `degrees(${value})`,
266
+ sideEffects: false,
267
+ });
268
+ export const determinant = dualImpl({
269
+ name: 'determinant',
270
+ signature: (arg) => {
271
+ if (!(arg.type === 'mat2x2f' || arg.type === 'mat3x3f' || arg.type === 'mat4x4f')) {
272
+ throw new SignatureNotSupportedError([arg], [mat2x2f, mat3x3f, mat4x4f]);
273
+ }
274
+ return { argTypes: [arg], returnType: f32 };
275
+ },
276
+ normalImpl: 'CPU implementation for determinant not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
277
+ codegenImpl: (_ctx, [value]) => stitch `determinant(${value})`,
278
+ sideEffects: false,
243
279
  });
244
280
  function cpuDistance(a, b) {
245
- if (typeof a === "number" && typeof b === "number") return Math.abs(a - b);
246
- return length(sub(a, b));
247
- }
248
- const distance = dualImpl({
249
- name: "distance",
250
- signature: (...args) => {
251
- const uargs = unify(args, anyFloat);
252
- if (!uargs) throw new SignatureNotSupportedError(args, anyFloat);
253
- return {
254
- argTypes: uargs,
255
- returnType: isHalfPrecisionSchema(uargs[0]) ? f16 : f32
256
- };
257
- },
258
- normalImpl: cpuDistance,
259
- codegenImpl: (_ctx, [a, b]) => stitch`distance(${a}, ${b})`
260
- });
261
- const dot = dualImpl({
262
- name: "dot",
263
- signature: (...args) => ({
264
- argTypes: args,
265
- returnType: args[0].primitive
266
- }),
267
- normalImpl: (lhs, rhs) => VectorOps.dot[lhs.kind](lhs, rhs),
268
- codegenImpl: (_ctx, [lhs, rhs]) => stitch`dot(${lhs}, ${rhs})`
269
- });
270
- const dot4U8Packed = dualImpl({
271
- name: "dot4U8Packed",
272
- signature: {
273
- argTypes: [u32, u32],
274
- returnType: u32
275
- },
276
- normalImpl: "CPU implementation for dot4U8Packed not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
277
- codegenImpl: (_ctx, [e1, e2]) => stitch`dot4U8Packed(${e1}, ${e2})`
278
- });
279
- const dot4I8Packed = dualImpl({
280
- name: "dot4I8Packed",
281
- signature: {
282
- argTypes: [u32, u32],
283
- returnType: i32
284
- },
285
- normalImpl: "CPU implementation for dot4I8Packed not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
286
- codegenImpl: (_ctx, [e1, e2]) => stitch`dot4I8Packed(${e1}, ${e2})`
281
+ if (typeof a === 'number' && typeof b === 'number') {
282
+ return Math.abs(a - b);
283
+ }
284
+ return length(sub(a, b));
285
+ }
286
+ export const distance = dualImpl({
287
+ name: 'distance',
288
+ signature: (...args) => {
289
+ const uargs = unify(args, anyFloat);
290
+ if (!uargs) {
291
+ throw new SignatureNotSupportedError(args, anyFloat);
292
+ }
293
+ return {
294
+ argTypes: uargs,
295
+ returnType: isHalfPrecisionSchema(uargs[0]) ? f16 : f32,
296
+ };
297
+ },
298
+ normalImpl: cpuDistance,
299
+ codegenImpl: (_ctx, [a, b]) => stitch `distance(${a}, ${b})`,
300
+ sideEffects: false,
301
+ });
302
+ export const dot = dualImpl({
303
+ name: 'dot',
304
+ signature: (...args) => ({
305
+ argTypes: args,
306
+ returnType: args[0].primitive,
307
+ }),
308
+ normalImpl: (lhs, rhs) => VectorOps.dot[lhs.kind](lhs, rhs),
309
+ codegenImpl: (_ctx, [lhs, rhs]) => stitch `dot(${lhs}, ${rhs})`,
310
+ sideEffects: false,
311
+ });
312
+ export const dot4U8Packed = dualImpl({
313
+ name: 'dot4U8Packed',
314
+ signature: { argTypes: [u32, u32], returnType: u32 },
315
+ normalImpl: 'CPU implementation for dot4U8Packed not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
316
+ codegenImpl: (_ctx, [e1, e2]) => stitch `dot4U8Packed(${e1}, ${e2})`,
317
+ sideEffects: false,
318
+ });
319
+ export const dot4I8Packed = dualImpl({
320
+ name: 'dot4I8Packed',
321
+ signature: { argTypes: [u32, u32], returnType: i32 },
322
+ normalImpl: 'CPU implementation for dot4I8Packed not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
323
+ codegenImpl: (_ctx, [e1, e2]) => stitch `dot4I8Packed(${e1}, ${e2})`,
324
+ sideEffects: false,
287
325
  });
288
326
  function cpuExp(value) {
289
- if (typeof value === "number") return Math.exp(value);
290
- return VectorOps.exp[value.kind](value);
291
- }
292
- const exp = dualImpl({
293
- name: "exp",
294
- signature: unifyRestrictedSignature(anyFloat),
295
- normalImpl: cpuExp,
296
- codegenImpl: (_ctx, [value]) => stitch`exp(${value})`
327
+ if (typeof value === 'number') {
328
+ return Math.exp(value);
329
+ }
330
+ return VectorOps.exp[value.kind](value);
331
+ }
332
+ export const exp = dualImpl({
333
+ name: 'exp',
334
+ signature: unifyRestrictedSignature(anyFloat),
335
+ normalImpl: cpuExp,
336
+ codegenImpl: (_ctx, [value]) => stitch `exp(${value})`,
337
+ sideEffects: false,
297
338
  });
298
339
  function cpuExp2(value) {
299
- if (typeof value === "number") return 2 ** value;
300
- return VectorOps.exp2[value.kind](value);
301
- }
302
- const exp2 = dualImpl({
303
- name: "exp2",
304
- signature: unifyRestrictedSignature(anyFloat),
305
- normalImpl: cpuExp2,
306
- codegenImpl: (_ctx, [value]) => stitch`exp2(${value})`
307
- });
308
- const extractBits = dualImpl({
309
- name: "extractBits",
310
- signature: (arg, _offset, _count) => {
311
- const argRestricted = unify([arg], anyConcreteInteger)?.[0];
312
- if (!argRestricted) throw new SignatureNotSupportedError([arg], anyConcreteInteger);
313
- return {
314
- argTypes: [
315
- argRestricted,
316
- u32,
317
- u32
318
- ],
319
- returnType: argRestricted
320
- };
321
- },
322
- normalImpl: "CPU implementation for extractBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
323
- codegenImpl: (_ctx, [e, offset, count]) => stitch`extractBits(${e}, ${offset}, ${count})`
324
- });
325
- const faceForward = dualImpl({
326
- name: "faceForward",
327
- signature: unifyRestrictedSignature(anyFloatVec),
328
- normalImpl: "CPU implementation for faceForward not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
329
- codegenImpl: (_ctx, [e1, e2, e3]) => stitch`faceForward(${e1}, ${e2}, ${e3})`
330
- });
331
- const firstLeadingBit = dualImpl({
332
- name: "firstLeadingBit",
333
- signature: unaryIdentitySignature,
334
- normalImpl: "CPU implementation for firstLeadingBit not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
335
- codegenImpl: (_ctx, [value]) => stitch`firstLeadingBit(${value})`
336
- });
337
- const firstTrailingBit = dualImpl({
338
- name: "firstTrailingBit",
339
- signature: unifyRestrictedSignature(anyConcreteInteger),
340
- normalImpl: "CPU implementation for firstTrailingBit not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
341
- codegenImpl: (_ctx, [value]) => stitch`firstTrailingBit(${value})`
340
+ if (typeof value === 'number') {
341
+ return (2 ** value);
342
+ }
343
+ return VectorOps.exp2[value.kind](value);
344
+ }
345
+ export const exp2 = dualImpl({
346
+ name: 'exp2',
347
+ signature: unifyRestrictedSignature(anyFloat),
348
+ normalImpl: cpuExp2,
349
+ codegenImpl: (_ctx, [value]) => stitch `exp2(${value})`,
350
+ sideEffects: false,
351
+ });
352
+ function cpuExtractBits(_e, _offset, _count) {
353
+ throw new Error('Unreachable code. The function is only used for the type.');
354
+ }
355
+ export const extractBits = dualImpl({
356
+ name: 'extractBits',
357
+ signature: (arg, _offset, _count) => {
358
+ const argRestricted = unify([arg], anyConcreteInteger)?.[0];
359
+ if (!argRestricted) {
360
+ throw new SignatureNotSupportedError([arg], anyConcreteInteger);
361
+ }
362
+ return {
363
+ argTypes: [argRestricted, u32, u32],
364
+ returnType: argRestricted,
365
+ };
366
+ },
367
+ normalImpl: 'CPU implementation for extractBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
368
+ codegenImpl: (_ctx, [e, offset, count]) => stitch `extractBits(${e}, ${offset}, ${count})`,
369
+ sideEffects: false,
370
+ });
371
+ export const faceForward = dualImpl({
372
+ name: 'faceForward',
373
+ signature: unifyRestrictedSignature(anyFloatVec),
374
+ normalImpl: 'CPU implementation for faceForward not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
375
+ codegenImpl: (_ctx, [e1, e2, e3]) => stitch `faceForward(${e1}, ${e2}, ${e3})`,
376
+ sideEffects: false,
377
+ });
378
+ function cpuFirstLeadingBit(_value) {
379
+ throw new Error('Unreachable code. The function is only used for the type.');
380
+ }
381
+ export const firstLeadingBit = dualImpl({
382
+ name: 'firstLeadingBit',
383
+ signature: unaryIdentitySignature,
384
+ normalImpl: 'CPU implementation for firstLeadingBit not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
385
+ codegenImpl: (_ctx, [value]) => stitch `firstLeadingBit(${value})`,
386
+ sideEffects: false,
387
+ });
388
+ function cpuFirstTrailingBit(_value) {
389
+ throw new Error('Unreachable code. The function is only used for the type.');
390
+ }
391
+ export const firstTrailingBit = dualImpl({
392
+ name: 'firstTrailingBit',
393
+ signature: unifyRestrictedSignature(anyConcreteInteger),
394
+ normalImpl: 'CPU implementation for firstTrailingBit not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
395
+ codegenImpl: (_ctx, [value]) => stitch `firstTrailingBit(${value})`,
396
+ sideEffects: false,
342
397
  });
343
398
  function cpuFloor(value) {
344
- if (typeof value === "number") return Math.floor(value);
345
- return VectorOps.floor[value.kind](value);
346
- }
347
- const floor = dualImpl({
348
- name: "floor",
349
- signature: unifyRestrictedSignature(anyFloat),
350
- normalImpl: cpuFloor,
351
- codegenImpl: (_ctx, [arg]) => stitch`floor(${arg})`
399
+ if (typeof value === 'number') {
400
+ return Math.floor(value);
401
+ }
402
+ return VectorOps.floor[value.kind](value);
403
+ }
404
+ export const floor = dualImpl({
405
+ name: 'floor',
406
+ signature: unifyRestrictedSignature(anyFloat),
407
+ normalImpl: cpuFloor,
408
+ codegenImpl: (_ctx, [arg]) => stitch `floor(${arg})`,
409
+ sideEffects: false,
352
410
  });
353
411
  function cpuFma(e1, e2, e3) {
354
- if (typeof e1 === "number") return e1 * e2 + e3;
355
- throw new MissingCpuImplError("CPU implementation for fma on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
356
- }
357
- const fma = dualImpl({
358
- name: "fma",
359
- signature: unifyRestrictedSignature(anyFloat),
360
- normalImpl: cpuFma,
361
- codegenImpl: (_ctx, [e1, e2, e3]) => stitch`fma(${e1}, ${e2}, ${e3})`
412
+ if (typeof e1 === 'number') {
413
+ return (e1 * e2 + e3);
414
+ }
415
+ throw new MissingCpuImplError('CPU implementation for fma on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
416
+ }
417
+ export const fma = dualImpl({
418
+ name: 'fma',
419
+ signature: unifyRestrictedSignature(anyFloat),
420
+ normalImpl: cpuFma,
421
+ codegenImpl: (_ctx, [e1, e2, e3]) => stitch `fma(${e1}, ${e2}, ${e3})`,
422
+ sideEffects: false,
362
423
  });
363
424
  function cpuFract(value) {
364
- if (typeof value === "number") return value - Math.floor(value);
365
- return VectorOps.fract[value.kind](value);
366
- }
367
- const fract = dualImpl({
368
- name: "fract",
369
- signature: unifyRestrictedSignature(anyFloat),
370
- normalImpl: cpuFract,
371
- codegenImpl: (_ctx, [a]) => stitch`fract(${a})`
425
+ if (typeof value === 'number') {
426
+ return (value - Math.floor(value));
427
+ }
428
+ return VectorOps.fract[value.kind](value);
429
+ }
430
+ export const fract = dualImpl({
431
+ name: 'fract',
432
+ signature: unifyRestrictedSignature(anyFloat),
433
+ normalImpl: cpuFract,
434
+ codegenImpl: (_ctx, [a]) => stitch `fract(${a})`,
435
+ sideEffects: false,
372
436
  });
373
437
  const FrexpResults = {
374
- f32: abstruct({
375
- fract: f32,
376
- exp: i32
377
- }),
378
- f16: abstruct({
379
- fract: f16,
380
- exp: i32
381
- }),
382
- abstractFloat: abstruct({
383
- fract: abstractFloat,
384
- exp: abstractInt
385
- }),
386
- vec2f: abstruct({
387
- fract: vec2f,
388
- exp: vec2i
389
- }),
390
- vec3f: abstruct({
391
- fract: vec3f,
392
- exp: vec3i
393
- }),
394
- vec4f: abstruct({
395
- fract: vec4f,
396
- exp: vec4i
397
- }),
398
- vec2h: abstruct({
399
- fract: vec2h,
400
- exp: vec2i
401
- }),
402
- vec3h: abstruct({
403
- fract: vec3h,
404
- exp: vec3i
405
- }),
406
- vec4h: abstruct({
407
- fract: vec4h,
408
- exp: vec4i
409
- })
438
+ f32: abstruct({ fract: f32, exp: i32 }),
439
+ f16: abstruct({ fract: f16, exp: i32 }),
440
+ abstractFloat: abstruct({ fract: abstractFloat, exp: abstractInt }),
441
+ vec2f: abstruct({ fract: vec2f, exp: vec2i }),
442
+ vec3f: abstruct({ fract: vec3f, exp: vec3i }),
443
+ vec4f: abstruct({ fract: vec4f, exp: vec4i }),
444
+ vec2h: abstruct({ fract: vec2h, exp: vec2i }),
445
+ vec3h: abstruct({ fract: vec3h, exp: vec3i }),
446
+ vec4h: abstruct({ fract: vec4h, exp: vec4i }),
410
447
  };
411
- const frexp = dualImpl({
412
- name: "frexp",
413
- normalImpl: "CPU implementation for frexp not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
414
- signature: (value) => {
415
- const returnType = FrexpResults[value.type];
416
- if (!returnType) throw new SignatureNotSupportedError([value], anyFloat);
417
- return {
418
- argTypes: [value],
419
- returnType
420
- };
421
- },
422
- codegenImpl: (_ctx, [value]) => stitch`frexp(${value})`
423
- });
424
- const insertBits = dualImpl({
425
- name: "insertBits",
426
- signature: (e, newbits, _offset, _count) => {
427
- const uargs = unify([e, newbits], anyConcreteInteger);
428
- if (!uargs) throw new SignatureNotSupportedError([e, newbits], anyConcreteInteger);
429
- return {
430
- argTypes: [
431
- ...uargs,
432
- u32,
433
- u32
434
- ],
435
- returnType: uargs[0]
436
- };
437
- },
438
- normalImpl: "CPU implementation for insertBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
439
- codegenImpl: (_ctx, [e, newbits, offset, count]) => stitch`insertBits(${e}, ${newbits}, ${offset}, ${count})`
448
+ export const frexp = dualImpl({
449
+ name: 'frexp',
450
+ normalImpl: 'CPU implementation for frexp not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
451
+ signature: (value) => {
452
+ const returnType = FrexpResults[value.type];
453
+ if (!returnType) {
454
+ throw new SignatureNotSupportedError([value], anyFloat);
455
+ }
456
+ return { argTypes: [value], returnType };
457
+ },
458
+ codegenImpl: (_ctx, [value]) => stitch `frexp(${value})`,
459
+ sideEffects: false,
460
+ });
461
+ function cpuInsertBits(_e, _newbits, _offset, _count) {
462
+ throw new Error('Unreachable code. The function is only used for the type.');
463
+ }
464
+ export const insertBits = dualImpl({
465
+ name: 'insertBits',
466
+ signature: (e, newbits, _offset, _count) => {
467
+ const uargs = unify([e, newbits], anyConcreteInteger);
468
+ if (!uargs) {
469
+ throw new SignatureNotSupportedError([e, newbits], anyConcreteInteger);
470
+ }
471
+ return {
472
+ argTypes: [...uargs, u32, u32],
473
+ returnType: uargs[0],
474
+ };
475
+ },
476
+ normalImpl: 'CPU implementation for insertBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
477
+ codegenImpl: (_ctx, [e, newbits, offset, count]) => stitch `insertBits(${e}, ${newbits}, ${offset}, ${count})`,
478
+ sideEffects: false,
440
479
  });
441
480
  function cpuInverseSqrt(value) {
442
- if (typeof value === "number") return 1 / Math.sqrt(value);
443
- throw new MissingCpuImplError("CPU implementation for inverseSqrt on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
444
- }
445
- const inverseSqrt = dualImpl({
446
- name: "inverseSqrt",
447
- signature: unifyRestrictedSignature(anyFloat),
448
- normalImpl: cpuInverseSqrt,
449
- codegenImpl: (_ctx, [value]) => stitch`inverseSqrt(${value})`
450
- });
451
- const ldexp = dualImpl({
452
- name: "ldexp",
453
- signature: (e1, _e2) => {
454
- switch (e1.type) {
455
- case "abstractFloat": return {
456
- argTypes: [e1, abstractInt],
457
- returnType: e1
458
- };
459
- case "f32":
460
- case "f16": return {
461
- argTypes: [e1, i32],
462
- returnType: e1
463
- };
464
- case "vec2f":
465
- case "vec2h": return {
466
- argTypes: [e1, vec2i],
467
- returnType: e1
468
- };
469
- case "vec3f":
470
- case "vec3h": return {
471
- argTypes: [e1, vec3i],
472
- returnType: e1
473
- };
474
- case "vec4f":
475
- case "vec4h": return {
476
- argTypes: [e1, vec4i],
477
- returnType: e1
478
- };
479
- default: throw new Error(`Unsupported data type for ldexp: ${e1.type}. Supported types are abstractFloat, f32, f16, vec2f, vec2h, vec3f, vec3h, vec4f, vec4h.`);
480
- }
481
- },
482
- normalImpl: "CPU implementation for ldexp not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
483
- codegenImpl: (_ctx, [e1, e2]) => stitch`ldexp(${e1}, ${e2})`
481
+ if (typeof value === 'number') {
482
+ return (1 / Math.sqrt(value));
483
+ }
484
+ throw new MissingCpuImplError('CPU implementation for inverseSqrt on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
485
+ }
486
+ export const inverseSqrt = dualImpl({
487
+ name: 'inverseSqrt',
488
+ signature: unifyRestrictedSignature(anyFloat),
489
+ normalImpl: cpuInverseSqrt,
490
+ codegenImpl: (_ctx, [value]) => stitch `inverseSqrt(${value})`,
491
+ sideEffects: false,
492
+ });
493
+ function cpuLdexp(_e1, _e2) {
494
+ throw new Error('Unreachable code. The function is only used for the type.');
495
+ }
496
+ export const ldexp = dualImpl({
497
+ name: 'ldexp',
498
+ signature: (e1, _e2) => {
499
+ switch (e1.type) {
500
+ case 'abstractFloat':
501
+ return { argTypes: [e1, abstractInt], returnType: e1 };
502
+ case 'f32':
503
+ case 'f16':
504
+ return { argTypes: [e1, i32], returnType: e1 };
505
+ case 'vec2f':
506
+ case 'vec2h':
507
+ return { argTypes: [e1, vec2i], returnType: e1 };
508
+ case 'vec3f':
509
+ case 'vec3h':
510
+ return { argTypes: [e1, vec3i], returnType: e1 };
511
+ case 'vec4f':
512
+ case 'vec4h':
513
+ return { argTypes: [e1, vec4i], returnType: e1 };
514
+ default:
515
+ throw new Error(`Unsupported data type for ldexp: ${e1.type}. Supported types are abstractFloat, f32, f16, vec2f, vec2h, vec3f, vec3h, vec4f, vec4h.`);
516
+ }
517
+ },
518
+ normalImpl: 'CPU implementation for ldexp not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
519
+ codegenImpl: (_ctx, [e1, e2]) => stitch `ldexp(${e1}, ${e2})`,
520
+ sideEffects: false,
484
521
  });
485
522
  function cpuLength(value) {
486
- if (typeof value === "number") return Math.abs(value);
487
- return VectorOps.length[value.kind](value);
488
- }
489
- const length = dualImpl({
490
- name: "length",
491
- signature: (arg) => {
492
- const uarg = unify([arg], anyFloat);
493
- if (!uarg) throw new SignatureNotSupportedError([arg], anyFloat);
494
- return {
495
- argTypes: uarg,
496
- returnType: isHalfPrecisionSchema(uarg[0]) ? f16 : f32
497
- };
498
- },
499
- normalImpl: cpuLength,
500
- codegenImpl: (_ctx, [arg]) => stitch`length(${arg})`
523
+ if (typeof value === 'number') {
524
+ return Math.abs(value);
525
+ }
526
+ return VectorOps.length[value.kind](value);
527
+ }
528
+ export const length = dualImpl({
529
+ name: 'length',
530
+ signature: (arg) => {
531
+ const uarg = unify([arg], anyFloat);
532
+ if (!uarg) {
533
+ throw new SignatureNotSupportedError([arg], anyFloat);
534
+ }
535
+ return {
536
+ argTypes: uarg,
537
+ returnType: isHalfPrecisionSchema(uarg[0]) ? f16 : f32,
538
+ };
539
+ },
540
+ normalImpl: cpuLength,
541
+ codegenImpl: (_ctx, [arg]) => stitch `length(${arg})`,
542
+ sideEffects: false,
501
543
  });
502
544
  function cpuLog(value) {
503
- if (typeof value === "number") return Math.log(value);
504
- return VectorOps.log[value.kind](value);
505
- }
506
- const log = dualImpl({
507
- name: "log",
508
- signature: unifyRestrictedSignature(anyFloat),
509
- normalImpl: cpuLog,
510
- codegenImpl: (_ctx, [value]) => stitch`log(${value})`
545
+ if (typeof value === 'number') {
546
+ return Math.log(value);
547
+ }
548
+ return VectorOps.log[value.kind](value);
549
+ }
550
+ export const log = dualImpl({
551
+ name: 'log',
552
+ signature: unifyRestrictedSignature(anyFloat),
553
+ normalImpl: cpuLog,
554
+ codegenImpl: (_ctx, [value]) => stitch `log(${value})`,
555
+ sideEffects: false,
511
556
  });
512
557
  function cpuLog2(value) {
513
- if (typeof value === "number") return Math.log2(value);
514
- return VectorOps.log2[value.kind](value);
515
- }
516
- const log2 = dualImpl({
517
- name: "log2",
518
- signature: unifyRestrictedSignature(anyFloat),
519
- normalImpl: cpuLog2,
520
- codegenImpl: (_ctx, [value]) => stitch`log2(${value})`
558
+ if (typeof value === 'number') {
559
+ return Math.log2(value);
560
+ }
561
+ return VectorOps.log2[value.kind](value);
562
+ }
563
+ export const log2 = dualImpl({
564
+ name: 'log2',
565
+ signature: unifyRestrictedSignature(anyFloat),
566
+ normalImpl: cpuLog2,
567
+ codegenImpl: (_ctx, [value]) => stitch `log2(${value})`,
568
+ sideEffects: false,
521
569
  });
522
570
  function cpuMax(a, b) {
523
- if (typeof a === "number") return Math.max(a, b);
524
- return VectorOps.max[a.kind](a, b);
525
- }
526
- const max = dualImpl({
527
- name: "max",
528
- signature: variadicUnifySignature,
529
- normalImpl: variadicReduce(cpuMax),
530
- codegenImpl: variadicStitch("max")
571
+ if (typeof a === 'number') {
572
+ return Math.max(a, b);
573
+ }
574
+ return VectorOps.max[a.kind](a, b);
575
+ }
576
+ export const max = dualImpl({
577
+ name: 'max',
578
+ signature: variadicUnifySignature,
579
+ normalImpl: variadicReduce(cpuMax),
580
+ codegenImpl: variadicStitch('max'),
581
+ sideEffects: false,
531
582
  });
532
583
  function cpuMin(a, b) {
533
- if (typeof a === "number") return Math.min(a, b);
534
- return VectorOps.min[a.kind](a, b);
535
- }
536
- const min = dualImpl({
537
- name: "min",
538
- signature: variadicUnifySignature,
539
- normalImpl: variadicReduce(cpuMin),
540
- codegenImpl: variadicStitch("min")
584
+ if (typeof a === 'number') {
585
+ return Math.min(a, b);
586
+ }
587
+ return VectorOps.min[a.kind](a, b);
588
+ }
589
+ export const min = dualImpl({
590
+ name: 'min',
591
+ signature: variadicUnifySignature,
592
+ normalImpl: variadicReduce(cpuMin),
593
+ codegenImpl: variadicStitch('min'),
594
+ sideEffects: false,
541
595
  });
542
596
  function cpuMix(e1, e2, e3) {
543
- if (typeof e1 === "number") {
544
- if (typeof e3 !== "number" || typeof e2 !== "number") throw new Error("When e1 and e2 are numbers, the blend factor must be a number.");
545
- return e1 * (1 - e3) + e2 * e3;
546
- }
547
- if (typeof e1 === "number" || typeof e2 === "number") throw new Error("e1 and e2 need to both be vectors of the same kind.");
548
- return VectorOps.mix[e1.kind](e1, e2, e3);
549
- }
550
- const mix = dualImpl({
551
- name: "mix",
552
- signature: (e1, e2, e3) => {
553
- if (e1.type.startsWith("vec") && !e3.type.startsWith("vec")) {
554
- const uarg = unify([e3], [e1.primitive]);
555
- if (!uarg) throw new SignatureNotSupportedError([e3], [e1.primitive]);
556
- return {
557
- argTypes: [
558
- e1,
559
- e2,
560
- uarg[0]
561
- ],
562
- returnType: e1
563
- };
564
- }
565
- const uargs = unify([
566
- e1,
567
- e2,
568
- e3
569
- ], anyFloat);
570
- if (!uargs) throw new SignatureNotSupportedError([
571
- e1,
572
- e2,
573
- e3
574
- ], anyFloat);
575
- return {
576
- argTypes: uargs,
577
- returnType: uargs[0]
578
- };
579
- },
580
- normalImpl: cpuMix,
581
- codegenImpl: (_ctx, [e1, e2, e3]) => stitch`mix(${e1}, ${e2}, ${e3})`
597
+ if (typeof e1 === 'number') {
598
+ if (typeof e3 !== 'number' || typeof e2 !== 'number') {
599
+ throw new Error('When e1 and e2 are numbers, the blend factor must be a number.');
600
+ }
601
+ return (e1 * (1 - e3) + e2 * e3);
602
+ }
603
+ if (typeof e1 === 'number' || typeof e2 === 'number') {
604
+ throw new Error('e1 and e2 need to both be vectors of the same kind.');
605
+ }
606
+ return VectorOps.mix[e1.kind](e1, e2, e3);
607
+ }
608
+ export const mix = dualImpl({
609
+ name: 'mix',
610
+ signature: (e1, e2, e3) => {
611
+ if (e1.type.startsWith('vec') && !e3.type.startsWith('vec')) {
612
+ const uarg = unify([e3], [e1.primitive]);
613
+ if (!uarg) {
614
+ throw new SignatureNotSupportedError([e3], [e1.primitive]);
615
+ }
616
+ return { argTypes: [e1, e2, uarg[0]], returnType: e1 };
617
+ }
618
+ const uargs = unify([e1, e2, e3], anyFloat);
619
+ if (!uargs) {
620
+ throw new SignatureNotSupportedError([e1, e2, e3], anyFloat);
621
+ }
622
+ return { argTypes: uargs, returnType: uargs[0] };
623
+ },
624
+ normalImpl: cpuMix,
625
+ codegenImpl: (_ctx, [e1, e2, e3]) => stitch `mix(${e1}, ${e2}, ${e3})`,
626
+ sideEffects: false,
582
627
  });
583
628
  const ModfResult = {
584
- f32: abstruct({
585
- fract: f32,
586
- whole: f32
587
- }),
588
- f16: abstruct({
589
- fract: f16,
590
- whole: f16
591
- }),
592
- abstractFloat: abstruct({
593
- fract: abstractFloat,
594
- whole: abstractFloat
595
- }),
596
- vec2f: abstruct({
597
- fract: vec2f,
598
- whole: vec2f
599
- }),
600
- vec3f: abstruct({
601
- fract: vec3f,
602
- whole: vec3f
603
- }),
604
- vec4f: abstruct({
605
- fract: vec4f,
606
- whole: vec4f
607
- }),
608
- vec2h: abstruct({
609
- fract: vec2h,
610
- whole: vec2h
611
- }),
612
- vec3h: abstruct({
613
- fract: vec3h,
614
- whole: vec3h
615
- }),
616
- vec4h: abstruct({
617
- fract: vec4h,
618
- whole: vec4h
619
- })
629
+ f32: abstruct({ fract: f32, whole: f32 }),
630
+ f16: abstruct({ fract: f16, whole: f16 }),
631
+ abstractFloat: abstruct({ fract: abstractFloat, whole: abstractFloat }),
632
+ vec2f: abstruct({ fract: vec2f, whole: vec2f }),
633
+ vec3f: abstruct({ fract: vec3f, whole: vec3f }),
634
+ vec4f: abstruct({ fract: vec4f, whole: vec4f }),
635
+ vec2h: abstruct({ fract: vec2h, whole: vec2h }),
636
+ vec3h: abstruct({ fract: vec3h, whole: vec3h }),
637
+ vec4h: abstruct({ fract: vec4h, whole: vec4h }),
620
638
  };
621
- const modf = dualImpl({
622
- name: "modf",
623
- signature: (e) => {
624
- const returnType = ModfResult[e.type];
625
- if (!returnType) throw new Error(`Unsupported data type for modf: ${e.type}. Supported types are f32, f16, abstractFloat, vec2f, vec3f, vec4f, vec2h, vec3h, vec4h.`);
626
- return {
627
- argTypes: [e],
628
- returnType
629
- };
630
- },
631
- normalImpl: "CPU implementation for modf not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
632
- codegenImpl: (_ctx, [value]) => stitch`modf(${value})`
633
- });
634
- const normalize = dualImpl({
635
- name: "normalize",
636
- signature: unifyRestrictedSignature(anyFloatVec),
637
- normalImpl: (v) => VectorOps.normalize[v.kind](v),
638
- codegenImpl: (_ctx, [value]) => stitch`normalize(${value})`
639
+ function cpuModf(_value) {
640
+ throw new Error('Unreachable code. The function is only used for the type.');
641
+ }
642
+ export const modf = dualImpl({
643
+ name: 'modf',
644
+ signature: (e) => {
645
+ const returnType = ModfResult[e.type];
646
+ if (!returnType) {
647
+ throw new Error(`Unsupported data type for modf: ${e.type}. Supported types are f32, f16, abstractFloat, vec2f, vec3f, vec4f, vec2h, vec3h, vec4h.`);
648
+ }
649
+ return { argTypes: [e], returnType };
650
+ },
651
+ normalImpl: 'CPU implementation for modf not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
652
+ codegenImpl: (_ctx, [value]) => stitch `modf(${value})`,
653
+ sideEffects: false,
654
+ });
655
+ export const normalize = dualImpl({
656
+ name: 'normalize',
657
+ signature: unifyRestrictedSignature(anyFloatVec),
658
+ normalImpl: (v) => VectorOps.normalize[v.kind](v),
659
+ codegenImpl: (_ctx, [value]) => stitch `normalize(${value})`,
660
+ sideEffects: false,
639
661
  });
640
662
  function powCpu(base, exponent) {
641
- if (typeof base === "number" && typeof exponent === "number") return base ** exponent;
642
- if (isVecInstance(base) && isVecInstance(exponent)) return VectorOps.pow[base.kind](base, exponent);
643
- throw new Error(`Invalid arguments to pow(): '${base}' '${exponent}'`);
644
- }
645
- const pow = dualImpl({
646
- name: "pow",
647
- signature: unifyRestrictedSignature(anyFloat),
648
- normalImpl: powCpu,
649
- codegenImpl: (_ctx, [lhs, rhs]) => stitch`pow(${lhs}, ${rhs})`
650
- });
651
- const quantizeToF16 = dualImpl({
652
- name: "quantizeToF16",
653
- signature: (arg) => {
654
- const candidates = [
655
- vec2f,
656
- vec3f,
657
- vec4f,
658
- f32
659
- ];
660
- const uarg = unify([arg], candidates)?.[0];
661
- if (!uarg) throw new SignatureNotSupportedError([arg], candidates);
662
- return {
663
- argTypes: [uarg],
664
- returnType: uarg
665
- };
666
- },
667
- normalImpl: "CPU implementation for quantizeToF16 not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
668
- codegenImpl: (_ctx, [value]) => stitch`quantizeToF16(${value})`
663
+ if (typeof base === 'number' && typeof exponent === 'number') {
664
+ return (base ** exponent);
665
+ }
666
+ if (isVecInstance(base) && isVecInstance(exponent)) {
667
+ return VectorOps.pow[base.kind](base, exponent);
668
+ }
669
+ throw new Error(`Invalid arguments to pow(): '${base}' '${exponent}'`);
670
+ }
671
+ export const pow = dualImpl({
672
+ name: 'pow',
673
+ signature: unifyRestrictedSignature(anyFloat),
674
+ normalImpl: powCpu,
675
+ codegenImpl: (_ctx, [lhs, rhs]) => stitch `pow(${lhs}, ${rhs})`,
676
+ sideEffects: false,
677
+ });
678
+ function cpuQuantizeToF16(_value) {
679
+ throw new Error('Unreachable code. The function is only used for the type.');
680
+ }
681
+ export const quantizeToF16 = dualImpl({
682
+ name: 'quantizeToF16',
683
+ signature: (arg) => {
684
+ const candidates = [vec2f, vec3f, vec4f, f32];
685
+ const uarg = unify([arg], candidates)?.[0];
686
+ if (!uarg) {
687
+ throw new SignatureNotSupportedError([arg], candidates);
688
+ }
689
+ return { argTypes: [uarg], returnType: uarg };
690
+ },
691
+ normalImpl: 'CPU implementation for quantizeToF16 not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
692
+ codegenImpl: (_ctx, [value]) => stitch `quantizeToF16(${value})`,
693
+ sideEffects: false,
669
694
  });
670
695
  function cpuRadians(value) {
671
- if (typeof value === "number") return value * Math.PI / 180;
672
- throw new MissingCpuImplError("CPU implementation for radians on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
673
- }
674
- const radians = dualImpl({
675
- name: "radians",
676
- signature: unifyRestrictedSignature(anyFloat),
677
- normalImpl: cpuRadians,
678
- codegenImpl: (_ctx, [value]) => stitch`radians(${value})`
679
- });
680
- const reflect = dualImpl({
681
- name: "reflect",
682
- signature: (...args) => {
683
- const uargs = unify(args, anyFloatVec);
684
- if (!uargs) throw new SignatureNotSupportedError(args, anyFloatVec);
685
- return {
686
- argTypes: uargs,
687
- returnType: uargs[0]
688
- };
689
- },
690
- normalImpl: (e1, e2) => sub(e1, mul(2 * dot(e2, e1), e2)),
691
- codegenImpl: (_ctx, [e1, e2]) => stitch`reflect(${e1}, ${e2})`
692
- });
693
- const refract = dualImpl({
694
- name: "refract",
695
- normalImpl: "CPU implementation for refract not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
696
- codegenImpl: (_ctx, [e1, e2, e3]) => stitch`refract(${e1}, ${e2}, ${e3})`,
697
- signature: (e1, e2, _e3) => ({
698
- argTypes: [
699
- e1,
700
- e2,
701
- isHalfPrecisionSchema(e1) ? f16 : f32
702
- ],
703
- returnType: e1
704
- })
705
- });
706
- const reverseBits = dualImpl({
707
- name: "reverseBits",
708
- signature: unifyRestrictedSignature(anyConcreteInteger),
709
- normalImpl: "CPU implementation for reverseBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
710
- codegenImpl: (_ctx, [value]) => stitch`reverseBits(${value})`
696
+ if (typeof value === 'number') {
697
+ return ((value * Math.PI) / 180);
698
+ }
699
+ throw new MissingCpuImplError('CPU implementation for radians on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
700
+ }
701
+ export const radians = dualImpl({
702
+ name: 'radians',
703
+ signature: unifyRestrictedSignature(anyFloat),
704
+ normalImpl: cpuRadians,
705
+ codegenImpl: (_ctx, [value]) => stitch `radians(${value})`,
706
+ sideEffects: false,
707
+ });
708
+ export const reflect = dualImpl({
709
+ name: 'reflect',
710
+ signature: (...args) => {
711
+ const uargs = unify(args, anyFloatVec);
712
+ if (!uargs) {
713
+ throw new SignatureNotSupportedError(args, anyFloatVec);
714
+ }
715
+ return {
716
+ argTypes: uargs,
717
+ returnType: uargs[0],
718
+ };
719
+ },
720
+ normalImpl: (e1, e2) => sub(e1, mul(2 * dot(e2, e1), e2)),
721
+ codegenImpl: (_ctx, [e1, e2]) => stitch `reflect(${e1}, ${e2})`,
722
+ sideEffects: false,
723
+ });
724
+ export const refract = dualImpl({
725
+ name: 'refract',
726
+ normalImpl: 'CPU implementation for refract not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
727
+ codegenImpl: (_ctx, [e1, e2, e3]) => stitch `refract(${e1}, ${e2}, ${e3})`,
728
+ signature: (e1, e2, _e3) => ({
729
+ argTypes: [e1, e2, isHalfPrecisionSchema(e1) ? f16 : f32],
730
+ returnType: e1,
731
+ }),
732
+ sideEffects: false,
733
+ });
734
+ function cpuReverseBits(_value) {
735
+ throw new Error('Unreachable code. The function is only used for the type.');
736
+ }
737
+ export const reverseBits = dualImpl({
738
+ name: 'reverseBits',
739
+ signature: unifyRestrictedSignature(anyConcreteInteger),
740
+ normalImpl: 'CPU implementation for reverseBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
741
+ codegenImpl: (_ctx, [value]) => stitch `reverseBits(${value})`,
742
+ sideEffects: false,
711
743
  });
712
744
  function cpuRound(value) {
713
- if (typeof value === "number") {
714
- const floor$1 = Math.floor(value);
715
- if (value === floor$1 + .5) {
716
- if (floor$1 % 2 === 0) return floor$1;
717
- return floor$1 + 1;
718
- }
719
- return Math.round(value);
720
- }
721
- throw new MissingCpuImplError("CPU implementation for round on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
722
- }
723
- const round = dualImpl({
724
- name: "round",
725
- signature: unifyRestrictedSignature(anyFloat),
726
- normalImpl: cpuRound,
727
- codegenImpl: (_ctx, [value]) => stitch`round(${value})`
745
+ if (typeof value === 'number') {
746
+ const floor = Math.floor(value);
747
+ if (value === floor + 0.5) {
748
+ if (floor % 2 === 0) {
749
+ return floor;
750
+ }
751
+ return (floor + 1);
752
+ }
753
+ return Math.round(value);
754
+ }
755
+ throw new MissingCpuImplError('CPU implementation for round on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
756
+ }
757
+ export const round = dualImpl({
758
+ name: 'round',
759
+ signature: unifyRestrictedSignature(anyFloat),
760
+ normalImpl: cpuRound,
761
+ codegenImpl: (_ctx, [value]) => stitch `round(${value})`,
762
+ sideEffects: false,
728
763
  });
729
764
  function cpuSaturate(value) {
730
- if (typeof value === "number") return Math.max(0, Math.min(1, value));
731
- throw new MissingCpuImplError("CPU implementation for saturate on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
732
- }
733
- const saturate = dualImpl({
734
- name: "saturate",
735
- signature: unifyRestrictedSignature(anyFloat),
736
- normalImpl: cpuSaturate,
737
- codegenImpl: (_ctx, [value]) => stitch`saturate(${value})`
765
+ if (typeof value === 'number') {
766
+ return Math.max(0, Math.min(1, value));
767
+ }
768
+ throw new MissingCpuImplError('CPU implementation for saturate on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
769
+ }
770
+ export const saturate = dualImpl({
771
+ name: 'saturate',
772
+ signature: unifyRestrictedSignature(anyFloat),
773
+ normalImpl: cpuSaturate,
774
+ codegenImpl: (ctx, [value]) => ctx.gen.emitCall('saturate', [], [value]),
775
+ sideEffects: false,
738
776
  });
739
777
  function cpuSign(e) {
740
- if (typeof e === "number") return Math.sign(e);
741
- return VectorOps.sign[e.kind](e);
742
- }
743
- const sign = dualImpl({
744
- name: "sign",
745
- signature: (arg) => {
746
- const candidates = [
747
- ...anyFloat,
748
- i32,
749
- vec2i,
750
- vec3i,
751
- vec4i
752
- ];
753
- const uarg = unify([arg], candidates)?.[0];
754
- if (!uarg) throw new SignatureNotSupportedError([arg], candidates);
755
- return {
756
- argTypes: [uarg],
757
- returnType: uarg
758
- };
759
- },
760
- normalImpl: cpuSign,
761
- codegenImpl: (_ctx, [e]) => stitch`sign(${e})`
778
+ if (typeof e === 'number') {
779
+ return Math.sign(e);
780
+ }
781
+ return VectorOps.sign[e.kind](e);
782
+ }
783
+ export const sign = dualImpl({
784
+ name: 'sign',
785
+ signature: (arg) => {
786
+ const candidates = [...anyFloat, i32, vec2i, vec3i, vec4i];
787
+ const uarg = unify([arg], candidates)?.[0];
788
+ if (!uarg) {
789
+ throw new SignatureNotSupportedError([arg], candidates);
790
+ }
791
+ return { argTypes: [uarg], returnType: uarg };
792
+ },
793
+ normalImpl: cpuSign,
794
+ codegenImpl: (_ctx, [e]) => stitch `sign(${e})`,
795
+ sideEffects: false,
762
796
  });
763
797
  function cpuSin(value) {
764
- if (typeof value === "number") return Math.sin(value);
765
- return VectorOps.sin[value.kind](value);
766
- }
767
- const sin = dualImpl({
768
- name: "sin",
769
- signature: unifyRestrictedSignature(anyFloat),
770
- normalImpl: cpuSin,
771
- codegenImpl: (_ctx, [value]) => stitch`sin(${value})`
798
+ if (typeof value === 'number') {
799
+ return Math.sin(value);
800
+ }
801
+ return VectorOps.sin[value.kind](value);
802
+ }
803
+ export const sin = dualImpl({
804
+ name: 'sin',
805
+ signature: unifyRestrictedSignature(anyFloat),
806
+ normalImpl: cpuSin,
807
+ codegenImpl: (_ctx, [value]) => stitch `sin(${value})`,
808
+ sideEffects: false,
772
809
  });
773
810
  function cpuSinh(value) {
774
- if (typeof value === "number") return Math.sinh(value);
775
- throw new MissingCpuImplError("CPU implementation for sinh on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
776
- }
777
- const sinh = dualImpl({
778
- name: "sinh",
779
- signature: unifyRestrictedSignature(anyFloat),
780
- normalImpl: cpuSinh,
781
- codegenImpl: (_ctx, [value]) => stitch`sinh(${value})`
811
+ if (typeof value === 'number') {
812
+ return Math.sinh(value);
813
+ }
814
+ throw new MissingCpuImplError('CPU implementation for sinh on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
815
+ }
816
+ export const sinh = dualImpl({
817
+ name: 'sinh',
818
+ signature: unifyRestrictedSignature(anyFloat),
819
+ normalImpl: cpuSinh,
820
+ codegenImpl: (_ctx, [value]) => stitch `sinh(${value})`,
821
+ sideEffects: false,
782
822
  });
783
823
  function cpuSmoothstep(edge0, edge1, x) {
784
- if (typeof x === "number") return smoothstepScalar(edge0, edge1, x);
785
- return VectorOps.smoothstep[x.kind](edge0, edge1, x);
786
- }
787
- const smoothstep = dualImpl({
788
- name: "smoothstep",
789
- signature: unifyRestrictedSignature(anyFloat),
790
- normalImpl: cpuSmoothstep,
791
- codegenImpl: (_ctx, [edge0, edge1, x]) => stitch`smoothstep(${edge0}, ${edge1}, ${x})`
824
+ if (typeof x === 'number') {
825
+ return smoothstepScalar(edge0, edge1, x);
826
+ }
827
+ return VectorOps.smoothstep[x.kind](edge0, edge1, x);
828
+ }
829
+ export const smoothstep = dualImpl({
830
+ name: 'smoothstep',
831
+ signature: unifyRestrictedSignature(anyFloat),
832
+ normalImpl: cpuSmoothstep,
833
+ codegenImpl: (_ctx, [edge0, edge1, x]) => stitch `smoothstep(${edge0}, ${edge1}, ${x})`,
834
+ sideEffects: false,
792
835
  });
793
836
  function cpuSqrt(value) {
794
- if (typeof value === "number") return Math.sqrt(value);
795
- return VectorOps.sqrt[value.kind](value);
796
- }
797
- const sqrt = dualImpl({
798
- name: "sqrt",
799
- signature: unifyRestrictedSignature(anyFloat),
800
- normalImpl: cpuSqrt,
801
- codegenImpl: (_ctx, [value]) => stitch`sqrt(${value})`
837
+ if (typeof value === 'number') {
838
+ return Math.sqrt(value);
839
+ }
840
+ return VectorOps.sqrt[value.kind](value);
841
+ }
842
+ export const sqrt = dualImpl({
843
+ name: 'sqrt',
844
+ signature: unifyRestrictedSignature(anyFloat),
845
+ normalImpl: cpuSqrt,
846
+ codegenImpl: (_ctx, [value]) => stitch `sqrt(${value})`,
847
+ sideEffects: false,
802
848
  });
803
849
  function cpuStep(edge, x) {
804
- if (typeof edge === "number") return edge <= x ? 1 : 0;
805
- throw new MissingCpuImplError("CPU implementation for step on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
806
- }
807
- const step = dualImpl({
808
- name: "step",
809
- signature: unifyRestrictedSignature(anyFloat),
810
- normalImpl: cpuStep,
811
- codegenImpl: (_ctx, [edge, x]) => stitch`step(${edge}, ${x})`
850
+ if (typeof edge === 'number') {
851
+ return (edge <= x ? 1.0 : 0.0);
852
+ }
853
+ throw new MissingCpuImplError('CPU implementation for step on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
854
+ }
855
+ export const step = dualImpl({
856
+ name: 'step',
857
+ signature: unifyRestrictedSignature(anyFloat),
858
+ normalImpl: cpuStep,
859
+ codegenImpl: (_ctx, [edge, x]) => stitch `step(${edge}, ${x})`,
860
+ sideEffects: false,
812
861
  });
813
862
  function cpuTan(value) {
814
- if (typeof value === "number") return Math.tan(value);
815
- throw new MissingCpuImplError("CPU implementation for tan on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
816
- }
817
- const tan = dualImpl({
818
- name: "tan",
819
- signature: unifyRestrictedSignature(anyFloat),
820
- normalImpl: cpuTan,
821
- codegenImpl: (_ctx, [value]) => stitch`tan(${value})`
863
+ if (typeof value === 'number') {
864
+ return Math.tan(value);
865
+ }
866
+ throw new MissingCpuImplError('CPU implementation for tan on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
867
+ }
868
+ export const tan = dualImpl({
869
+ name: 'tan',
870
+ signature: unifyRestrictedSignature(anyFloat),
871
+ normalImpl: cpuTan,
872
+ codegenImpl: (_ctx, [value]) => stitch `tan(${value})`,
873
+ sideEffects: false,
822
874
  });
823
875
  function cpuTanh(value) {
824
- if (typeof value === "number") return Math.tanh(value);
825
- return VectorOps.tanh[value.kind](value);
826
- }
827
- const tanh = dualImpl({
828
- name: "tanh",
829
- signature: unifyRestrictedSignature(anyFloat),
830
- normalImpl: cpuTanh,
831
- codegenImpl: (_ctx, [value]) => stitch`tanh(${value})`
832
- });
833
- const transpose = dualImpl({
834
- name: "transpose",
835
- signature: unaryIdentitySignature,
836
- normalImpl: "CPU implementation for transpose not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
837
- codegenImpl: (_ctx, [e]) => stitch`transpose(${e})`
838
- });
839
- const trunc = dualImpl({
840
- name: "trunc",
841
- signature: unifyRestrictedSignature(anyFloat),
842
- normalImpl: "CPU implementation for trunc not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
843
- codegenImpl: (_ctx, [value]) => stitch`trunc(${value})`
844
- });
845
-
846
- //#endregion
847
- export { abs, acos, acosh, asin, asinh, atan, atan2, atanh, ceil, clamp, cos, cosh, countLeadingZeros, countOneBits, countTrailingZeros, cross, degrees, determinant, distance, dot, dot4I8Packed, dot4U8Packed, exp, exp2, extractBits, faceForward, firstLeadingBit, firstTrailingBit, floor, fma, fract, frexp, insertBits, inverseSqrt, ldexp, length, log, log2, max, min, mix, modf, normalize, pow, quantizeToF16, radians, reflect, refract, reverseBits, round, saturate, sign, sin, sinh, smoothstep, sqrt, step, tan, tanh, transpose, trunc };
876
+ if (typeof value === 'number') {
877
+ return Math.tanh(value);
878
+ }
879
+ return VectorOps.tanh[value.kind](value);
880
+ }
881
+ export const tanh = dualImpl({
882
+ name: 'tanh',
883
+ signature: unifyRestrictedSignature(anyFloat),
884
+ normalImpl: cpuTanh,
885
+ codegenImpl: (_ctx, [value]) => stitch `tanh(${value})`,
886
+ sideEffects: false,
887
+ });
888
+ function cpuTranspose(value) {
889
+ const schema = WORKAROUND_getSchema(value);
890
+ // NOTE: This assumes all matrices are square
891
+ const transposed = schema();
892
+ const src = value.columns;
893
+ const dst = transposed.columns;
894
+ if (src.length === 2) {
895
+ dst[0][0] = src[0][0];
896
+ dst[0][1] = src[1][0];
897
+ dst[1][0] = src[0][1];
898
+ dst[1][1] = src[1][1];
899
+ }
900
+ else if (src.length === 3) {
901
+ dst[0][0] = src[0][0];
902
+ dst[0][1] = src[1][0];
903
+ dst[0][2] = src[2][0];
904
+ dst[1][0] = src[0][1];
905
+ dst[1][1] = src[1][1];
906
+ dst[1][2] = src[2][1];
907
+ // oxlint-disable-next-line typescript/no-non-null-assertion
908
+ const dst2 = dst[2];
909
+ dst2[0] = src[0][2];
910
+ dst2[1] = src[1][2];
911
+ dst2[2] = src[2][2];
912
+ }
913
+ else if (src.length === 4) {
914
+ dst[0][0] = src[0][0];
915
+ dst[0][1] = src[1][0];
916
+ dst[0][2] = src[2][0];
917
+ dst[0][3] = src[3][0];
918
+ dst[1][0] = src[0][1];
919
+ dst[1][1] = src[1][1];
920
+ dst[1][2] = src[2][1];
921
+ dst[1][3] = src[3][1];
922
+ // oxlint-disable-next-line typescript/no-non-null-assertion
923
+ const dst2 = dst[2];
924
+ dst2[0] = src[0][2];
925
+ dst2[1] = src[1][2];
926
+ dst2[2] = src[2][2];
927
+ dst2[3] = src[3][2];
928
+ // oxlint-disable-next-line typescript/no-non-null-assertion
929
+ const dst3 = dst[3];
930
+ dst3[0] = src[0][3];
931
+ dst3[1] = src[1][3];
932
+ dst3[2] = src[2][3];
933
+ dst3[3] = src[3][3];
934
+ }
935
+ else {
936
+ assertExhaustive(src, 'std/numeric.ts#cpuTranspose');
937
+ }
938
+ return transposed;
939
+ }
940
+ export const transpose = dualImpl({
941
+ name: 'transpose',
942
+ signature: unaryIdentitySignature,
943
+ normalImpl: cpuTranspose,
944
+ codegenImpl: (_ctx, [e]) => stitch `transpose(${e})`,
945
+ sideEffects: false,
946
+ });
947
+ function cpuTrunc(_value) {
948
+ throw new Error('Unreachable code. The function is only used for the type.');
949
+ }
950
+ export const trunc = dualImpl({
951
+ name: 'trunc',
952
+ signature: unifyRestrictedSignature(anyFloat),
953
+ normalImpl: 'CPU implementation for trunc not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
954
+ codegenImpl: (_ctx, [value]) => stitch `trunc(${value})`,
955
+ sideEffects: false,
956
+ });