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,108 @@
1
+ import { $gpuRepr, $gpuValueOf, $invalidSchemaReason, $memIdent, $repr, $reprPartial, $validStorageSchema, $validUniformSchema, $validVertexSchema } from "./symbols.js";
2
+ import { Default } from "./utilityTypes.js";
3
+ import { U16, U32, WgslArray } from "../data/wgslTypes.js";
4
+ import { ViewDimensionToDimension } from "../core/texture/textureFormats.js";
5
+ import { WgslStorageTexture, WgslTexture } from "../data/texture.js";
6
+ import { TgpuTexture } from "../core/texture/texture.js";
7
+ import { Disarray, Undecorate } from "../data/dataTypes.js";
8
+
9
+ //#region src/shared/repr.d.ts
10
+ /**
11
+ * Extracts the inferred representation of a resource.
12
+ * For inferring types as seen by the GPU, see {@link InferGPU}
13
+ *
14
+ * @example
15
+ * type A = Infer<F32> // => number
16
+ * type B = Infer<WgslArray<F32>> // => number[]
17
+ * type C = Infer<Atomic<U32>> // => number
18
+ */
19
+ type Infer<T> = T extends {
20
+ readonly [$repr]: infer TRepr;
21
+ } ? TRepr : T;
22
+ /**
23
+ * Extracts a sparse/partial inferred representation of a resource.
24
+ * Used by the `buffer.writePartial` API.
25
+ *
26
+ * @example
27
+ * type A = InferPartial<F32> // => number | undefined
28
+ * type B = InferPartial<WgslStruct<{ a: F32 }>> // => { a?: number | undefined }
29
+ * type C = InferPartial<WgslArray<F32>> // => { idx: number; value: number | undefined }[] | undefined
30
+ */
31
+ type InferPartial<T> = T extends {
32
+ readonly [$reprPartial]: infer TRepr;
33
+ } ? TRepr : T extends {
34
+ readonly [$repr]: infer TRepr;
35
+ } ? TRepr | undefined : T;
36
+ /**
37
+ * Extracts the inferred representation of a resource (as seen by the GPU).
38
+ *
39
+ * @example
40
+ * type A = InferGPU<F32> // => number
41
+ * type B = InferGPU<WgslArray<F32>> // => number[]
42
+ * type C = InferGPU<Atomic<U32>> // => atomicU32
43
+ */
44
+ type InferGPU<T> = T extends {
45
+ readonly [$gpuRepr]: infer TRepr;
46
+ } ? TRepr : Infer<T>;
47
+ type InferRecord<T extends Record<string | number | symbol, unknown>> = { [Key in keyof T]: Infer<T[Key]> };
48
+ type InferPartialRecord<T extends Record<string | number | symbol, unknown>> = { [Key in keyof T]?: InferPartial<T[Key]> };
49
+ type InferGPURecord<T extends Record<string | number | symbol, unknown>> = { [Key in keyof T]: InferGPU<T[Key]> };
50
+ type GPUValueOf<T> = T extends {
51
+ readonly [$gpuValueOf]: infer TValue;
52
+ } ? TValue : T;
53
+ type MemIdentity<T> = T extends {
54
+ readonly [$memIdent]: infer TMemIdent;
55
+ } ? TMemIdent : T;
56
+ type MemIdentityRecord<T extends Record<string | number | symbol, unknown>> = { [Key in keyof T]: MemIdentity<T[Key]> };
57
+ type IsValidStorageSchema<T> = (T extends {
58
+ readonly [$validStorageSchema]: true;
59
+ } ? true : false) extends false ? false : true;
60
+ type IsValidUniformSchema<T> = (T extends {
61
+ readonly [$validUniformSchema]: true;
62
+ } ? true : false) extends false ? false : true;
63
+ type IsValidVertexSchema<T> = (T extends {
64
+ readonly [$validVertexSchema]: true;
65
+ } ? true : false) extends false ? false : true;
66
+ /**
67
+ * Accepts only arrays (or disarrays) of u32 or u16.
68
+ */
69
+ type IsValidIndexSchema<T> = Undecorate<T> extends WgslArray | Disarray ? Undecorate<Undecorate<T>['elementType']> extends U32 | U16 ? true : false : false;
70
+ /**
71
+ * Checks if a schema can be used in a buffer at all
72
+ */
73
+ type IsValidBufferSchema<T> = IsValidStorageSchema<T> | IsValidUniformSchema<T> | IsValidVertexSchema<T> | IsValidIndexSchema<T> extends false ? false : true;
74
+ /**
75
+ * Validates if a texture can be used as sampled texture
76
+ */
77
+ type IsValidSampledTextureUsage<TTexture extends TgpuTexture> = TTexture['usableAsSampled'] extends true ? true : {
78
+ readonly invalidSampled: "Texture not usable as sampled, call $usage('sampled') first";
79
+ };
80
+ /**
81
+ * Validates if a texture can be used as storage texture
82
+ */
83
+ type IsValidStorageTextureUsage<TTexture extends TgpuTexture> = TTexture['usableAsStorage'] extends true ? true : {
84
+ readonly invalidStorage: "Texture not usable as storage, call $usage('storage') first";
85
+ };
86
+ /**
87
+ * Validates if a texture view dimension is compatible with the texture dimension
88
+ */
89
+ type IsValidSubdimension<TTexture extends TgpuTexture, TSchema extends WgslTexture | WgslStorageTexture> = ViewDimensionToDimension[TSchema['dimension']] extends infer TVDim ? TVDim extends Default<TTexture['props']['dimension'], '2d'> ? true : {
90
+ readonly invalidViewDim: `Texture dimension '${Default<TTexture['props']['dimension'], '2d'>}' incompatible with view dimension '${TSchema['dimension']}'`;
91
+ } : never;
92
+ type IsValidStorageFormat<TTexture extends TgpuTexture, TSchema extends WgslStorageTexture> = TSchema['format'] extends TTexture['props']['format'] ? true : TTexture['props']['viewFormats'] extends readonly unknown[] ? TSchema['format'] extends TTexture['props']['viewFormats'][number] ? true : FormatError<TSchema, TTexture> : FormatError<TSchema, TTexture>;
93
+ type FormatError<TSchema extends WgslStorageTexture, TTexture extends TgpuTexture> = {
94
+ readonly invalidFormat: `Storage texture format '${TSchema['format']}' incompatible with texture format '${TTexture['props']['format']}'`;
95
+ };
96
+ type IsExactly<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false;
97
+ type SelfOrErrors<TSelf, T> = IsExactly<T, true> extends true ? TSelf : `(Error) ${T[Extract<keyof T, `invalid${string}`>] & string}`;
98
+ type ValidStorageUsage<TTexture extends TgpuTexture, TSchema extends WgslStorageTexture> = IsValidStorageTextureUsage<TTexture> & IsValidSubdimension<TTexture, TSchema> & IsValidStorageFormat<TTexture, TSchema>;
99
+ type ValidSampledUsage<TTexture extends TgpuTexture, TSchema extends WgslTexture> = IsValidSampledTextureUsage<TTexture> & IsValidSubdimension<TTexture, TSchema>;
100
+ /**
101
+ * Validates texture view schema against texture usage
102
+ */
103
+ type ValidateTextureViewSchema<TTexture extends TgpuTexture, TSchema extends WgslTexture | WgslStorageTexture> = TSchema extends WgslStorageTexture ? SelfOrErrors<TSchema, ValidStorageUsage<TTexture, TSchema>> : TSchema extends WgslTexture ? SelfOrErrors<TSchema, ValidSampledUsage<TTexture, TSchema>> : never;
104
+ type ExtractInvalidSchemaError<T, TPrefix extends string = ''> = [T] extends [{
105
+ readonly [$invalidSchemaReason]: string;
106
+ }] ? `${TPrefix}${T[typeof $invalidSchemaReason]}` : never;
107
+ //#endregion
108
+ export { ExtractInvalidSchemaError, GPUValueOf, Infer, InferGPU, InferGPURecord, InferPartial, InferPartialRecord, InferRecord, IsValidBufferSchema, IsValidIndexSchema, IsValidStorageSchema, IsValidUniformSchema, IsValidVertexSchema, MemIdentity, MemIdentityRecord, ValidateTextureViewSchema };
@@ -0,0 +1,22 @@
1
+ import { isMatInstance, isVecInstance } from "../data/wgslTypes.js";
2
+
3
+ //#region src/shared/stringify.ts
4
+ function safeStringify(item) {
5
+ const asString = String(item);
6
+ if (asString !== "[object Object]") return asString;
7
+ try {
8
+ return JSON.stringify(item);
9
+ } catch (error) {
10
+ console.error("Error parsing JSON:", error);
11
+ return "<invalid json>";
12
+ }
13
+ }
14
+ function niceStringify(item) {
15
+ if (isVecInstance(item) || isMatInstance(item)) return item.toString();
16
+ if (Array.isArray(item)) return `[${item.map(niceStringify).join(", ")}]`;
17
+ if (item && typeof item === "object") return `{ ${Object.entries(item).map(([key, value]) => `${key}: ${niceStringify(value)}`).join(", ")} }`;
18
+ return String(item);
19
+ }
20
+
21
+ //#endregion
22
+ export { niceStringify, safeStringify };
@@ -0,0 +1,61 @@
1
+ //#region src/shared/symbols.d.ts
2
+ declare const $internal: unique symbol;
3
+ /**
4
+ * The getter to the value of this resource, accessible on the GPU
5
+ */
6
+ declare const $gpuValueOf: unique symbol;
7
+ /**
8
+ * If this symbol is present, this means that getName and setName
9
+ * will refer to object behind this property instead.
10
+ */
11
+ declare const $getNameForward: unique symbol;
12
+ /**
13
+ * Marks an object with slot-value bindings
14
+ */
15
+ declare const $providing: unique symbol;
16
+ declare const $resolve: unique symbol;
17
+ /**
18
+ * A way for a schema to provide casting behavior, without the need to be explicitly
19
+ * callable by the end-user (e.g. vertex formats)
20
+ */
21
+ declare const $cast: unique symbol;
22
+ /**
23
+ * Can be called on the GPU
24
+ */
25
+ declare const $gpuCallable: unique symbol;
26
+ /**
27
+ * Type token for the inferred (CPU & GPU) representation of a resource
28
+ */
29
+ declare const $repr: unique symbol;
30
+ /**
31
+ * Type token for the inferred (GPU-side) representation of a resource
32
+ * If present, it shadows the value of `$repr` for GPU-side inference.
33
+ */
34
+ declare const $gpuRepr: unique symbol;
35
+ /**
36
+ * Type token for the inferred partial representation of a resource.
37
+ * If present, it shadows the value of `$repr` for use in partial IO.
38
+ */
39
+ declare const $reprPartial: unique symbol;
40
+ /**
41
+ * Type token holding schemas that are identical in memory layout.
42
+ */
43
+ declare const $memIdent: unique symbol;
44
+ /**
45
+ * Type token, signaling that a schema can be used in a storage buffer.
46
+ */
47
+ declare const $validStorageSchema: unique symbol;
48
+ /**
49
+ * Type token, signaling that a schema can be used in a uniform buffer.
50
+ */
51
+ declare const $validUniformSchema: unique symbol;
52
+ /**
53
+ * Type token, signaling that a schema can be used in a vertex buffer.
54
+ */
55
+ declare const $validVertexSchema: unique symbol;
56
+ /**
57
+ * Type token, containing a reason for why the schema is invalid (if it is).
58
+ */
59
+ declare const $invalidSchemaReason: unique symbol;
60
+ //#endregion
61
+ export { $cast, $getNameForward, $gpuCallable, $gpuRepr, $gpuValueOf, $internal, $invalidSchemaReason, $memIdent, $providing, $repr, $reprPartial, $resolve, $validStorageSchema, $validUniformSchema, $validVertexSchema };
@@ -0,0 +1,71 @@
1
+ import { version } from "../package.js";
2
+
3
+ //#region src/shared/symbols.ts
4
+ const $internal = Symbol(`typegpu:${version}:$internal`);
5
+ /**
6
+ * The getter to the value of this resource, accessible on the GPU
7
+ */
8
+ const $gpuValueOf = Symbol(`typegpu:${version}:$gpuValueOf`);
9
+ /**
10
+ * If this symbol is present, this means that getName and setName
11
+ * will refer to object behind this property instead.
12
+ */
13
+ const $getNameForward = Symbol(`typegpu:${version}:$getNameForward`);
14
+ /**
15
+ * Marks an object with slot-value bindings
16
+ */
17
+ const $providing = Symbol(`typegpu:${version}:$providing`);
18
+ /**
19
+ * Objects can provide the snippet that represents them.
20
+ */
21
+ const $ownSnippet = Symbol(`typegpu:${version}:$ownSnippet`);
22
+ const $resolve = Symbol(`typegpu:${version}:$resolve`);
23
+ /**
24
+ * A way for a schema to provide casting behavior, without the need to be explicitly
25
+ * callable by the end-user (e.g. vertex formats)
26
+ */
27
+ const $cast = Symbol(`typegpu:${version}:$cast`);
28
+ /**
29
+ * Can be called on the GPU
30
+ */
31
+ const $gpuCallable = Symbol(`typegpu:${version}:$gpuCallable`);
32
+ /**
33
+ * Type token for the inferred (CPU & GPU) representation of a resource
34
+ */
35
+ const $repr = Symbol(`typegpu:${version}:$repr`);
36
+ /**
37
+ * Type token for the inferred (GPU-side) representation of a resource
38
+ * If present, it shadows the value of `$repr` for GPU-side inference.
39
+ */
40
+ const $gpuRepr = Symbol(`typegpu:${version}:$gpuRepr`);
41
+ /**
42
+ * Type token for the inferred partial representation of a resource.
43
+ * If present, it shadows the value of `$repr` for use in partial IO.
44
+ */
45
+ const $reprPartial = Symbol(`typegpu:${version}:$reprPartial`);
46
+ /**
47
+ * Type token holding schemas that are identical in memory layout.
48
+ */
49
+ const $memIdent = Symbol(`typegpu:${version}:$memIdent`);
50
+ /**
51
+ * Type token, signaling that a schema can be used in a storage buffer.
52
+ */
53
+ const $validStorageSchema = Symbol(`typegpu:${version}:$invalidStorageSchema`);
54
+ /**
55
+ * Type token, signaling that a schema can be used in a uniform buffer.
56
+ */
57
+ const $validUniformSchema = Symbol(`typegpu:${version}:$validUniformSchema`);
58
+ /**
59
+ * Type token, signaling that a schema can be used in a vertex buffer.
60
+ */
61
+ const $validVertexSchema = Symbol(`typegpu:${version}:$validVertexSchema`);
62
+ /**
63
+ * Type token, containing a reason for why the schema is invalid (if it is).
64
+ */
65
+ const $invalidSchemaReason = Symbol(`typegpu:${version}:$invalidSchemaReason`);
66
+ function isMarkedInternal(value) {
67
+ return !!value?.[$internal];
68
+ }
69
+
70
+ //#endregion
71
+ export { $cast, $getNameForward, $gpuCallable, $gpuValueOf, $internal, $ownSnippet, $providing, $repr, $resolve, isMarkedInternal };
@@ -0,0 +1,29 @@
1
+ //#region src/shared/utilityTypes.d.ts
2
+ type Default<T, TDefault> = unknown extends T ? TDefault : T extends undefined ? TDefault : T;
3
+ type SwapNever<T, Replacement> = [T] extends [never] ? Replacement : T;
4
+ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
5
+ type Prettify<T> = { [K in keyof T]: T[K] } & {};
6
+ /**
7
+ * Utility type that merges a partial type with defaults, where defaults are used
8
+ * for properties not present in the partial type.
9
+ */
10
+ type WithDefaults<TPartial, TDefaults> = Omit<TDefaults, keyof TPartial> & TPartial;
11
+ /**
12
+ * Removes properties from record type that extend `Prop`
13
+ */
14
+ type OmitProps<T extends Record<string, unknown>, Prop> = Pick<T, { [Key in keyof T]: T[Key] extends Prop ? never : Key }[keyof T]>;
15
+ type NullableToOptional<T> = { [K in keyof T as T[K] extends null ? K : never]?: T[K] } & { [K in keyof T as T[K] extends null ? never : K]: T[K] };
16
+ /**
17
+ * The opposite of Readonly<T>
18
+ */
19
+ type Mutable<T> = { -readonly [P in keyof T]: T[P] };
20
+ /**
21
+ * Source: https://code.lol/post/programming/higher-kinded-types/
22
+ */
23
+ type Assume<T, U> = T extends U ? T : U;
24
+ /**
25
+ * Any typed array
26
+ */
27
+ type TypedArray = Uint8Array | Uint16Array | Uint32Array | Int32Array | Float32Array | Float64Array;
28
+ //#endregion
29
+ export { Assume, Default, Mutable, NullableToOptional, OmitProps, Prettify, SwapNever, TypedArray, UnionToIntersection, WithDefaults };
@@ -0,0 +1,7 @@
1
+ //#region src/shared/utilityTypes.ts
2
+ function assertExhaustive(x, location) {
3
+ throw new Error(`Failed to handle ${x} at ${location}`);
4
+ }
5
+
6
+ //#endregion
7
+ export { assertExhaustive };
@@ -0,0 +1,70 @@
1
+ //#region src/shared/vertexFormat.d.ts
2
+ declare const vertexFormats: readonly ["uint8", "uint8x2", "uint8x4", "sint8", "sint8x2", "sint8x4", "unorm8", "unorm8x2", "unorm8x4", "snorm8", "snorm8x2", "snorm8x4", "uint16", "uint16x2", "uint16x4", "sint16", "sint16x2", "sint16x4", "unorm16", "unorm16x2", "unorm16x4", "snorm16", "snorm16x2", "snorm16x4", "float16", "float16x2", "float16x4", "float32", "float32x2", "float32x3", "float32x4", "uint32", "uint32x2", "uint32x3", "uint32x4", "sint32", "sint32x2", "sint32x3", "sint32x4", "unorm10-10-10-2", "unorm8x4-bgra"];
3
+ type VertexFormat = (typeof vertexFormats)[number];
4
+ declare const kindToDefaultFormatMap: {
5
+ readonly f32: "float32";
6
+ readonly vec2f: "float32x2";
7
+ readonly vec3f: "float32x3";
8
+ readonly vec4f: "float32x4";
9
+ readonly f16: "float16";
10
+ readonly vec2h: "float16x2";
11
+ readonly vec4h: "float16x4";
12
+ readonly u32: "uint32";
13
+ readonly vec2u: "uint32x2";
14
+ readonly vec3u: "uint32x3";
15
+ readonly vec4u: "uint32x4";
16
+ readonly i32: "sint32";
17
+ readonly vec2i: "sint32x2";
18
+ readonly vec3i: "sint32x3";
19
+ readonly vec4i: "sint32x4";
20
+ };
21
+ type KindToDefaultFormatMap = typeof kindToDefaultFormatMap;
22
+ interface TgpuVertexAttrib<TFormat extends VertexFormat = VertexFormat> {
23
+ readonly format: TFormat;
24
+ readonly offset: number;
25
+ }
26
+ type AnyVertexAttribs = Record<string, TgpuVertexAttrib> | TgpuVertexAttrib;
27
+ /**
28
+ * All vertex attribute formats that can be interpreted as
29
+ * an single or multi component u32 in a shader.
30
+ * https://www.w3.org/TR/webgpu/#vertex-formats
31
+ */
32
+ type U32CompatibleFormats = TgpuVertexAttrib<'uint8'> | TgpuVertexAttrib<'uint8x2'> | TgpuVertexAttrib<'uint8x4'> | TgpuVertexAttrib<'uint16'> | TgpuVertexAttrib<'uint16x2'> | TgpuVertexAttrib<'uint16x4'> | TgpuVertexAttrib<'uint32'> | TgpuVertexAttrib<'uint32x2'> | TgpuVertexAttrib<'uint32x3'> | TgpuVertexAttrib<'uint32x4'>;
33
+ /**
34
+ * All vertex attribute formats that can be interpreted as
35
+ * an single or multi component i32 in a shader.
36
+ * https://www.w3.org/TR/webgpu/#vertex-formats
37
+ */
38
+ type I32CompatibleFormats = TgpuVertexAttrib<'sint8'> | TgpuVertexAttrib<'sint8x2'> | TgpuVertexAttrib<'sint8x4'> | TgpuVertexAttrib<'sint16'> | TgpuVertexAttrib<'sint16x2'> | TgpuVertexAttrib<'sint16x4'> | TgpuVertexAttrib<'sint32'> | TgpuVertexAttrib<'sint32x2'> | TgpuVertexAttrib<'sint32x3'> | TgpuVertexAttrib<'sint32x4'>;
39
+ /**
40
+ * All vertex attribute formats that can be interpreted as
41
+ * an single or multi component f32 in a shader.
42
+ * https://www.w3.org/TR/webgpu/#vertex-formats
43
+ */
44
+ type F32CompatibleFormats = TgpuVertexAttrib<'unorm8'> | TgpuVertexAttrib<'unorm8x2'> | TgpuVertexAttrib<'unorm8x4'> | TgpuVertexAttrib<'snorm8'> | TgpuVertexAttrib<'snorm8x2'> | TgpuVertexAttrib<'snorm8x4'> | TgpuVertexAttrib<'unorm16'> | TgpuVertexAttrib<'unorm16x2'> | TgpuVertexAttrib<'unorm16x4'> | TgpuVertexAttrib<'snorm16'> | TgpuVertexAttrib<'snorm16x2'> | TgpuVertexAttrib<'snorm16x4'> | TgpuVertexAttrib<'float16'> | TgpuVertexAttrib<'float16x2'> | TgpuVertexAttrib<'float16x4'> | TgpuVertexAttrib<'float32'> | TgpuVertexAttrib<'float32x2'> | TgpuVertexAttrib<'float32x3'> | TgpuVertexAttrib<'float32x4'> | TgpuVertexAttrib<'unorm10-10-10-2'> | TgpuVertexAttrib<'unorm8x4-bgra'>;
45
+ /**
46
+ * All vertex attribute formats that can be interpreted as
47
+ * a single or multi component f16 in a shader. (same as f32 on the shader side)
48
+ * https://www.w3.org/TR/webgpu/#vertex-formats
49
+ */
50
+ type F16CompatibleFormats = F32CompatibleFormats;
51
+ type KindToAcceptedAttribMap = {
52
+ u32: U32CompatibleFormats;
53
+ vec2u: U32CompatibleFormats;
54
+ vec3u: U32CompatibleFormats;
55
+ vec4u: U32CompatibleFormats;
56
+ i32: I32CompatibleFormats;
57
+ vec2i: I32CompatibleFormats;
58
+ vec3i: I32CompatibleFormats;
59
+ vec4i: I32CompatibleFormats;
60
+ f16: F16CompatibleFormats;
61
+ vec2h: F16CompatibleFormats;
62
+ vec3h: F16CompatibleFormats;
63
+ vec4h: F16CompatibleFormats;
64
+ f32: F32CompatibleFormats;
65
+ vec2f: F32CompatibleFormats;
66
+ vec3f: F32CompatibleFormats;
67
+ vec4f: F32CompatibleFormats;
68
+ };
69
+ //#endregion
70
+ export { AnyVertexAttribs, KindToAcceptedAttribMap, KindToDefaultFormatMap, TgpuVertexAttrib, VertexFormat };
@@ -0,0 +1,64 @@
1
+ //#region src/shared/vertexFormat.ts
2
+ const vertexFormats = [
3
+ "uint8",
4
+ "uint8x2",
5
+ "uint8x4",
6
+ "sint8",
7
+ "sint8x2",
8
+ "sint8x4",
9
+ "unorm8",
10
+ "unorm8x2",
11
+ "unorm8x4",
12
+ "snorm8",
13
+ "snorm8x2",
14
+ "snorm8x4",
15
+ "uint16",
16
+ "uint16x2",
17
+ "uint16x4",
18
+ "sint16",
19
+ "sint16x2",
20
+ "sint16x4",
21
+ "unorm16",
22
+ "unorm16x2",
23
+ "unorm16x4",
24
+ "snorm16",
25
+ "snorm16x2",
26
+ "snorm16x4",
27
+ "float16",
28
+ "float16x2",
29
+ "float16x4",
30
+ "float32",
31
+ "float32x2",
32
+ "float32x3",
33
+ "float32x4",
34
+ "uint32",
35
+ "uint32x2",
36
+ "uint32x3",
37
+ "uint32x4",
38
+ "sint32",
39
+ "sint32x2",
40
+ "sint32x3",
41
+ "sint32x4",
42
+ "unorm10-10-10-2",
43
+ "unorm8x4-bgra"
44
+ ];
45
+ const kindToDefaultFormatMap = {
46
+ f32: "float32",
47
+ vec2f: "float32x2",
48
+ vec3f: "float32x3",
49
+ vec4f: "float32x4",
50
+ f16: "float16",
51
+ vec2h: "float16x2",
52
+ vec4h: "float16x4",
53
+ u32: "uint32",
54
+ vec2u: "uint32x2",
55
+ vec3u: "uint32x3",
56
+ vec4u: "uint32x4",
57
+ i32: "sint32",
58
+ vec2i: "sint32x2",
59
+ vec3i: "sint32x3",
60
+ vec4i: "sint32x4"
61
+ };
62
+
63
+ //#endregion
64
+ export { kindToDefaultFormatMap, vertexFormats };
package/std/array.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { DualFn } from "../types.js";
2
+ import { _ref } from "../data/ref.js";
3
+
4
+ //#region src/std/array.d.ts
5
+ declare const arrayLength: DualFn<(a: unknown[] | _ref<unknown[]>) => number>;
6
+ //#endregion
7
+ export { arrayLength };
package/std/array.js ADDED
@@ -0,0 +1,27 @@
1
+ import { isPtr, isWgslArray } from "../data/wgslTypes.js";
2
+ import { stitch } from "../core/resolve/stitch.js";
3
+ import { ptrFn } from "../data/ptr.js";
4
+ import { isRef } from "../data/ref.js";
5
+ import { abstractInt, u32 } from "../data/numeric.js";
6
+ import { dualImpl } from "../core/function/dualImpl.js";
7
+
8
+ //#region src/std/array.ts
9
+ const sizeOfPointedToArray = (dataType) => isPtr(dataType) && isWgslArray(dataType.inner) ? dataType.inner.elementCount : 0;
10
+ const arrayLength = dualImpl({
11
+ name: "arrayLength",
12
+ signature: (arg) => {
13
+ const ptrArg = isPtr(arg) ? arg : ptrFn(arg);
14
+ return {
15
+ argTypes: [ptrArg],
16
+ returnType: sizeOfPointedToArray(ptrArg) > 0 ? abstractInt : u32
17
+ };
18
+ },
19
+ normalImpl: (a) => isRef(a) ? a.$.length : a.length,
20
+ codegenImpl(_ctx, [a]) {
21
+ const length = sizeOfPointedToArray(a.dataType);
22
+ return length > 0 ? `${length}` : stitch`arrayLength(${a})`;
23
+ }
24
+ });
25
+
26
+ //#endregion
27
+ export { arrayLength };
@@ -0,0 +1,19 @@
1
+ import { DualFn } from "../types.js";
2
+ import { atomicI32, atomicU32 } from "../data/wgslTypes.js";
3
+
4
+ //#region src/std/atomic.d.ts
5
+ type AnyAtomic = atomicI32 | atomicU32;
6
+ declare const workgroupBarrier: DualFn<(...args: never[]) => unknown>;
7
+ declare const storageBarrier: DualFn<(...args: never[]) => unknown>;
8
+ declare const textureBarrier: DualFn<(...args: never[]) => unknown>;
9
+ declare const atomicLoad: DualFn<(<T extends AnyAtomic>(a: T) => number)>;
10
+ declare const atomicStore: DualFn<(<T extends AnyAtomic>(a: T, value: number) => void)>;
11
+ declare const atomicAdd: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
12
+ declare const atomicSub: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
13
+ declare const atomicMax: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
14
+ declare const atomicMin: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
15
+ declare const atomicAnd: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
16
+ declare const atomicOr: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
17
+ declare const atomicXor: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
18
+ //#endregion
19
+ export { atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, storageBarrier, textureBarrier, workgroupBarrier };
package/std/atomic.js ADDED
@@ -0,0 +1,113 @@
1
+ import { Void, isAtomic } from "../data/wgslTypes.js";
2
+ import { stitch } from "../core/resolve/stitch.js";
3
+ import { safeStringify } from "../shared/stringify.js";
4
+ import { i32, u32 } from "../data/numeric.js";
5
+ import { dualImpl } from "../core/function/dualImpl.js";
6
+
7
+ //#region src/std/atomic.ts
8
+ const workgroupBarrier = dualImpl({
9
+ name: "workgroupBarrier",
10
+ normalImpl: "workgroupBarrier is a no-op outside of CODEGEN mode.",
11
+ signature: {
12
+ argTypes: [],
13
+ returnType: Void
14
+ },
15
+ codegenImpl: () => "workgroupBarrier()"
16
+ });
17
+ const storageBarrier = dualImpl({
18
+ name: "storageBarrier",
19
+ normalImpl: "storageBarrier is a no-op outside of CODEGEN mode.",
20
+ signature: {
21
+ argTypes: [],
22
+ returnType: Void
23
+ },
24
+ codegenImpl: () => "storageBarrier()"
25
+ });
26
+ const textureBarrier = dualImpl({
27
+ name: "textureBarrier",
28
+ normalImpl: "textureBarrier is a no-op outside of CODEGEN mode.",
29
+ signature: {
30
+ argTypes: [],
31
+ returnType: Void
32
+ },
33
+ codegenImpl: () => "textureBarrier()"
34
+ });
35
+ const atomicNormalError = "Atomic operations are not supported outside of CODEGEN mode.";
36
+ const atomicLoad = dualImpl({
37
+ name: "atomicLoad",
38
+ normalImpl: atomicNormalError,
39
+ signature: (a) => {
40
+ if (!isAtomic(a)) throw new Error(`Invalid atomic type: ${safeStringify(a)}`);
41
+ return {
42
+ argTypes: [a],
43
+ returnType: a.inner
44
+ };
45
+ },
46
+ codegenImpl: (_ctx, [a]) => stitch`atomicLoad(&${a})`
47
+ });
48
+ const atomicActionSignature = (a) => {
49
+ if (!isAtomic(a)) throw new Error(`Invalid atomic type: ${safeStringify(a)}`);
50
+ return {
51
+ argTypes: [a, a.inner.type === "u32" ? u32 : i32],
52
+ returnType: Void
53
+ };
54
+ };
55
+ const atomicOpSignature = (a) => {
56
+ if (!isAtomic(a)) throw new Error(`Invalid atomic type: ${safeStringify(a)}`);
57
+ const paramType = a.inner.type === "u32" ? u32 : i32;
58
+ return {
59
+ argTypes: [a, paramType],
60
+ returnType: paramType
61
+ };
62
+ };
63
+ const atomicStore = dualImpl({
64
+ name: "atomicStore",
65
+ normalImpl: atomicNormalError,
66
+ signature: atomicActionSignature,
67
+ codegenImpl: (_ctx, [a, value]) => stitch`atomicStore(&${a}, ${value})`
68
+ });
69
+ const atomicAdd = dualImpl({
70
+ name: "atomicAdd",
71
+ normalImpl: atomicNormalError,
72
+ signature: atomicOpSignature,
73
+ codegenImpl: (_ctx, [a, value]) => stitch`atomicAdd(&${a}, ${value})`
74
+ });
75
+ const atomicSub = dualImpl({
76
+ name: "atomicSub",
77
+ normalImpl: atomicNormalError,
78
+ signature: atomicOpSignature,
79
+ codegenImpl: (_ctx, [a, value]) => stitch`atomicSub(&${a}, ${value})`
80
+ });
81
+ const atomicMax = dualImpl({
82
+ name: "atomicMax",
83
+ normalImpl: atomicNormalError,
84
+ signature: atomicOpSignature,
85
+ codegenImpl: (_ctx, [a, value]) => stitch`atomicMax(&${a}, ${value})`
86
+ });
87
+ const atomicMin = dualImpl({
88
+ name: "atomicMin",
89
+ normalImpl: atomicNormalError,
90
+ signature: atomicOpSignature,
91
+ codegenImpl: (_ctx, [a, value]) => stitch`atomicMin(&${a}, ${value})`
92
+ });
93
+ const atomicAnd = dualImpl({
94
+ name: "atomicAnd",
95
+ normalImpl: atomicNormalError,
96
+ signature: atomicOpSignature,
97
+ codegenImpl: (_ctx, [a, value]) => stitch`atomicAnd(&${a}, ${value})`
98
+ });
99
+ const atomicOr = dualImpl({
100
+ name: "atomicOr",
101
+ normalImpl: atomicNormalError,
102
+ signature: atomicOpSignature,
103
+ codegenImpl: (_ctx, [a, value]) => stitch`atomicOr(&${a}, ${value})`
104
+ });
105
+ const atomicXor = dualImpl({
106
+ name: "atomicXor",
107
+ normalImpl: atomicNormalError,
108
+ signature: atomicOpSignature,
109
+ codegenImpl: (_ctx, [a, value]) => stitch`atomicXor(&${a}, ${value})`
110
+ });
111
+
112
+ //#endregion
113
+ export { atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, storageBarrier, textureBarrier, workgroupBarrier };
@@ -0,0 +1,10 @@
1
+ import { DualFn } from "../types.js";
2
+ import { v2f, v2i, v2u, v3f, v3i, v3u, v4f, v4i, v4u } from "../data/wgslTypes.js";
3
+
4
+ //#region src/std/bitcast.d.ts
5
+ type BitcastU32toF32Overload = ((value: number) => number) & ((value: v2u) => v2f) & ((value: v3u) => v3f) & ((value: v4u) => v4f);
6
+ declare const bitcastU32toF32: DualFn<BitcastU32toF32Overload>;
7
+ type BitcastU32toI32Overload = ((value: number) => number) & ((value: v2u) => v2i) & ((value: v3u) => v3i) & ((value: v4u) => v4i);
8
+ declare const bitcastU32toI32: DualFn<BitcastU32toI32Overload>;
9
+ //#endregion
10
+ export { bitcastU32toF32, bitcastU32toI32 };
package/std/bitcast.js ADDED
@@ -0,0 +1,43 @@
1
+ import { isVec } from "../data/wgslTypes.js";
2
+ import { stitch } from "../core/resolve/stitch.js";
3
+ import { unify } from "../tgsl/conversion.js";
4
+ import { f32, i32, u32 } from "../data/numeric.js";
5
+ import { vec2f, vec2i, vec3f, vec3i, vec4f, vec4i } from "../data/vector.js";
6
+ import { dualImpl } from "../core/function/dualImpl.js";
7
+ import { bitcastU32toF32Impl, bitcastU32toI32Impl } from "../data/numberOps.js";
8
+ import { VectorOps } from "../data/vectorOps.js";
9
+
10
+ //#region src/std/bitcast.ts
11
+ const bitcastU32toF32 = dualImpl({
12
+ name: "bitcastU32toF32",
13
+ normalImpl: ((value) => {
14
+ if (typeof value === "number") return bitcastU32toF32Impl(value);
15
+ return VectorOps.bitcastU32toF32[value.kind](value);
16
+ }),
17
+ codegenImpl: (_ctx, [n]) => stitch`bitcast<f32>(${n})`,
18
+ signature: (...arg) => {
19
+ const uargs = unify(arg, [u32]) ?? arg;
20
+ return {
21
+ argTypes: uargs,
22
+ returnType: isVec(uargs[0]) ? uargs[0].type === "vec2u" ? vec2f : uargs[0].type === "vec3u" ? vec3f : vec4f : f32
23
+ };
24
+ }
25
+ });
26
+ const bitcastU32toI32 = dualImpl({
27
+ name: "bitcastU32toI32",
28
+ normalImpl: ((value) => {
29
+ if (typeof value === "number") return bitcastU32toI32Impl(value);
30
+ return VectorOps.bitcastU32toI32[value.kind](value);
31
+ }),
32
+ codegenImpl: (_ctx, [n]) => stitch`bitcast<i32>(${n})`,
33
+ signature: (...arg) => {
34
+ const uargs = unify(arg, [u32]) ?? arg;
35
+ return {
36
+ argTypes: uargs,
37
+ returnType: isVec(uargs[0]) ? uargs[0].type === "vec2u" ? vec2i : uargs[0].type === "vec3u" ? vec3i : vec4i : i32
38
+ };
39
+ }
40
+ });
41
+
42
+ //#endregion
43
+ export { bitcastU32toF32, bitcastU32toI32 };