typegpu 0.10.1 → 0.11.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/_virtual/_rolldown/runtime.js +13 -0
  2. package/builtin.d.ts +50 -0
  3. package/builtin.js +35 -0
  4. package/common/fullScreenTriangle.d.ts +22 -0
  5. package/common/fullScreenTriangle.js +34 -0
  6. package/common/index.d.ts +4 -4
  7. package/common/index.js +8 -7
  8. package/common/writeSoA.d.ts +16 -0
  9. package/common/writeSoA.js +90 -0
  10. package/core/buffer/buffer.d.ts +79 -0
  11. package/core/buffer/buffer.js +246 -0
  12. package/core/buffer/bufferShorthand.d.ts +48 -0
  13. package/core/buffer/bufferShorthand.js +53 -0
  14. package/core/buffer/bufferUsage.d.ts +43 -0
  15. package/core/buffer/bufferUsage.js +165 -0
  16. package/core/constant/tgpuConstant.d.ts +29 -0
  17. package/core/constant/tgpuConstant.js +68 -0
  18. package/core/declare/tgpuDeclare.d.ts +18 -0
  19. package/core/declare/tgpuDeclare.js +39 -0
  20. package/core/function/autoIO.d.ts +38 -0
  21. package/core/function/autoIO.js +85 -0
  22. package/core/function/comptime.d.ts +39 -0
  23. package/core/function/comptime.js +49 -0
  24. package/core/function/createCallableSchema.js +40 -0
  25. package/core/function/dualImpl.js +52 -0
  26. package/core/function/entryInputRouter.js +39 -0
  27. package/core/function/extractArgs.js +204 -0
  28. package/core/function/fnCore.js +90 -0
  29. package/core/function/fnTypes.d.ts +40 -0
  30. package/core/function/ioSchema.d.ts +10 -0
  31. package/core/function/ioSchema.js +51 -0
  32. package/core/function/shelllessImpl.d.ts +28 -0
  33. package/core/function/shelllessImpl.js +21 -0
  34. package/core/function/templateUtils.js +12 -0
  35. package/core/function/tgpuComputeFn.d.ts +48 -0
  36. package/core/function/tgpuComputeFn.js +55 -0
  37. package/core/function/tgpuFn.d.ts +52 -0
  38. package/core/function/tgpuFn.js +168 -0
  39. package/core/function/tgpuFragmentFn.d.ts +72 -0
  40. package/core/function/tgpuFragmentFn.js +63 -0
  41. package/core/function/tgpuVertexFn.d.ts +59 -0
  42. package/core/function/tgpuVertexFn.js +59 -0
  43. package/core/pipeline/applyPipelineState.js +35 -0
  44. package/core/pipeline/computePipeline.d.ts +54 -0
  45. package/core/pipeline/computePipeline.js +227 -0
  46. package/core/pipeline/connectAttachmentToShader.js +24 -0
  47. package/core/pipeline/connectTargetsToShader.js +27 -0
  48. package/core/pipeline/limitsOverflow.js +12 -0
  49. package/core/pipeline/pipelineUtils.js +29 -0
  50. package/core/pipeline/renderPipeline.d.ts +284 -0
  51. package/core/pipeline/renderPipeline.js +489 -0
  52. package/core/pipeline/timeable.d.ts +20 -0
  53. package/core/pipeline/timeable.js +55 -0
  54. package/core/pipeline/typeGuards.js +27 -0
  55. package/core/querySet/querySet.d.ts +20 -0
  56. package/core/querySet/querySet.js +104 -0
  57. package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +59 -0
  58. package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +94 -0
  59. package/core/resolve/externals.d.ts +8 -0
  60. package/core/resolve/externals.js +56 -0
  61. package/core/resolve/namespace.d.ts +38 -0
  62. package/core/resolve/namespace.js +39 -0
  63. package/core/resolve/resolveData.js +144 -0
  64. package/core/resolve/stitch.js +23 -0
  65. package/core/resolve/tgpuResolve.d.ts +153 -0
  66. package/core/resolve/tgpuResolve.js +66 -0
  67. package/core/root/configurableImpl.js +17 -0
  68. package/core/root/init.d.ts +64 -0
  69. package/core/root/init.js +464 -0
  70. package/core/root/rootTypes.d.ts +642 -0
  71. package/core/sampler/sampler.d.ts +31 -0
  72. package/core/sampler/sampler.js +116 -0
  73. package/core/simulate/tgpuSimulate.d.ts +36 -0
  74. package/core/simulate/tgpuSimulate.js +74 -0
  75. package/core/slot/accessor.d.ts +9 -0
  76. package/core/slot/accessor.js +95 -0
  77. package/core/slot/internalSlots.js +5 -0
  78. package/core/slot/lazy.d.ts +6 -0
  79. package/core/slot/lazy.js +40 -0
  80. package/core/slot/slot.d.ts +6 -0
  81. package/core/slot/slot.js +39 -0
  82. package/core/slot/slotTypes.d.ts +92 -0
  83. package/core/slot/slotTypes.js +19 -0
  84. package/core/texture/externalTexture.d.ts +6 -0
  85. package/core/texture/externalTexture.js +47 -0
  86. package/core/texture/texture.d.ts +114 -0
  87. package/core/texture/texture.js +314 -0
  88. package/core/texture/textureFormats.d.ts +29 -0
  89. package/core/texture/textureFormats.js +97 -0
  90. package/core/texture/textureProps.d.ts +11 -0
  91. package/core/texture/textureUtils.js +222 -0
  92. package/core/texture/usageExtension.d.ts +21 -0
  93. package/core/texture/usageExtension.js +19 -0
  94. package/core/unroll/tgpuUnroll.d.ts +68 -0
  95. package/core/unroll/tgpuUnroll.js +94 -0
  96. package/core/valueProxyUtils.js +42 -0
  97. package/core/variable/tgpuVariable.d.ts +38 -0
  98. package/core/variable/tgpuVariable.js +99 -0
  99. package/core/vertexLayout/connectAttributesToShader.js +57 -0
  100. package/core/vertexLayout/vertexAttribute.d.ts +29 -0
  101. package/core/vertexLayout/vertexLayout.d.ts +19 -0
  102. package/core/vertexLayout/vertexLayout.js +103 -0
  103. package/data/alignIO.js +14 -0
  104. package/data/alignmentOf.d.ts +9 -0
  105. package/data/alignmentOf.js +86 -0
  106. package/data/array.d.ts +26 -0
  107. package/data/array.js +46 -0
  108. package/data/atomic.d.ts +15 -0
  109. package/data/atomic.js +24 -0
  110. package/data/attributes.d.ts +121 -0
  111. package/data/attributes.js +145 -0
  112. package/data/autoStruct.d.ts +1 -0
  113. package/data/autoStruct.js +81 -0
  114. package/data/compiledIO.js +228 -0
  115. package/data/dataIO.js +556 -0
  116. package/data/dataTypes.d.ts +115 -0
  117. package/data/dataTypes.js +100 -0
  118. package/data/deepEqual.d.ts +25 -0
  119. package/data/deepEqual.js +56 -0
  120. package/data/disarray.d.ts +32 -0
  121. package/data/disarray.js +50 -0
  122. package/data/getLongestContiguousPrefix.d.ts +9 -0
  123. package/data/getLongestContiguousPrefix.js +13 -0
  124. package/data/index.d.ts +26 -4
  125. package/data/index.js +36 -9
  126. package/data/instanceToSchema.d.ts +33 -0
  127. package/data/isContiguous.d.ts +9 -0
  128. package/data/isContiguous.js +13 -0
  129. package/data/matrix.d.ts +124 -0
  130. package/data/matrix.js +531 -0
  131. package/data/numberOps.js +23 -0
  132. package/data/numeric.d.ts +81 -0
  133. package/data/numeric.js +221 -0
  134. package/data/offsetUtils.d.ts +33 -0
  135. package/data/offsetUtils.js +165 -0
  136. package/data/offsets.js +34 -0
  137. package/data/partialIO.js +113 -0
  138. package/data/ptr.d.ts +11 -0
  139. package/data/ptr.js +44 -0
  140. package/data/ref.d.ts +34 -0
  141. package/data/ref.js +94 -0
  142. package/data/sampler.d.ts +107 -0
  143. package/data/sampler.js +24 -0
  144. package/data/schemaCallWrapper.js +30 -0
  145. package/data/schemaMemoryLayout.js +198 -0
  146. package/data/sizeOf.d.ts +9 -0
  147. package/data/sizeOf.js +13 -0
  148. package/data/snippet.d.ts +26 -0
  149. package/data/snippet.js +70 -0
  150. package/data/struct.d.ts +17 -0
  151. package/data/struct.js +44 -0
  152. package/data/texture.d.ts +292 -0
  153. package/{texture-BagDrrks.js → data/texture.js} +6 -5
  154. package/data/unstruct.d.ts +24 -0
  155. package/data/unstruct.js +41 -0
  156. package/data/vector.d.ts +191 -0
  157. package/data/vector.js +239 -0
  158. package/data/vectorImpl.js +515 -0
  159. package/data/vectorOps.js +681 -0
  160. package/data/vertexFormatData.d.ts +190 -0
  161. package/data/vertexFormatData.js +109 -0
  162. package/data/wgslTypes.d.ts +924 -0
  163. package/data/wgslTypes.js +222 -0
  164. package/errors.d.ts +44 -0
  165. package/errors.js +131 -0
  166. package/execMode.js +49 -0
  167. package/extension.d.ts +11 -0
  168. package/extension.js +16 -0
  169. package/getGPUValue.js +7 -0
  170. package/index.d.ts +42 -243
  171. package/index.js +21 -6320
  172. package/indexNamedExports.d.ts +40 -0
  173. package/mathUtils.js +12 -0
  174. package/memo.js +22 -0
  175. package/nameRegistry.d.ts +30 -0
  176. package/nameRegistry.js +447 -0
  177. package/package.js +4 -0
  178. package/package.json +26 -26
  179. package/resolutionCtx.d.ts +19 -0
  180. package/resolutionCtx.js +612 -0
  181. package/shared/env.js +12 -0
  182. package/shared/generators.js +13 -0
  183. package/shared/meta.d.ts +39 -0
  184. package/shared/meta.js +61 -0
  185. package/shared/repr.d.ts +138 -0
  186. package/shared/stringify.js +20 -0
  187. package/shared/symbols.d.ts +70 -0
  188. package/shared/symbols.js +48 -0
  189. package/shared/utilityTypes.d.ts +33 -0
  190. package/shared/utilityTypes.js +6 -0
  191. package/shared/vertexFormat.d.ts +70 -0
  192. package/shared/vertexFormat.js +63 -0
  193. package/std/array.d.ts +7 -0
  194. package/std/array.js +25 -0
  195. package/std/atomic.d.ts +19 -0
  196. package/std/atomic.js +111 -0
  197. package/std/bitcast.d.ts +10 -0
  198. package/std/bitcast.js +41 -0
  199. package/std/boolean.d.ts +141 -0
  200. package/std/boolean.js +299 -0
  201. package/std/derivative.d.ts +16 -0
  202. package/std/derivative.js +87 -0
  203. package/std/discard.d.ts +6 -0
  204. package/std/discard.js +14 -0
  205. package/std/extensions.d.ts +6 -0
  206. package/std/extensions.js +12 -0
  207. package/std/index.d.ts +17 -4
  208. package/std/index.js +21 -7
  209. package/std/matrix.d.ts +41 -0
  210. package/std/matrix.js +85 -0
  211. package/std/numeric.d.ts +200 -0
  212. package/std/numeric.js +845 -0
  213. package/std/operators.d.ts +56 -0
  214. package/std/operators.js +227 -0
  215. package/std/packing.d.ts +26 -0
  216. package/std/packing.js +84 -0
  217. package/std/range.d.ts +24 -0
  218. package/std/range.js +38 -0
  219. package/std/subgroup.d.ts +47 -0
  220. package/std/subgroup.js +218 -0
  221. package/std/texture.d.ts +117 -0
  222. package/std/texture.js +207 -0
  223. package/tgpu.js +42 -0
  224. package/tgpuBindGroupLayout.d.ts +161 -0
  225. package/tgpuBindGroupLayout.js +272 -0
  226. package/tgpuUnstable.d.ts +48 -0
  227. package/tgpuUnstable.js +64 -0
  228. package/tgsl/accessIndex.js +43 -0
  229. package/tgsl/accessProp.js +115 -0
  230. package/tgsl/consoleLog/deserializers.js +115 -0
  231. package/tgsl/consoleLog/logGenerator.js +84 -0
  232. package/tgsl/consoleLog/serializers.js +223 -0
  233. package/tgsl/consoleLog/types.d.ts +52 -0
  234. package/tgsl/consoleLog/types.js +11 -0
  235. package/tgsl/conversion.js +198 -0
  236. package/tgsl/forOfUtils.js +71 -0
  237. package/tgsl/generationHelpers.d.ts +37 -0
  238. package/tgsl/generationHelpers.js +67 -0
  239. package/tgsl/math.js +43 -0
  240. package/tgsl/shaderGenerator.d.ts +20 -0
  241. package/tgsl/shaderGenerator_members.d.ts +2 -0
  242. package/tgsl/shaderGenerator_members.js +6 -0
  243. package/tgsl/shellless.d.ts +11 -0
  244. package/tgsl/shellless.js +46 -0
  245. package/tgsl/wgslGenerator.d.ts +36 -0
  246. package/tgsl/wgslGenerator.js +639 -0
  247. package/types.d.ts +265 -0
  248. package/types.js +43 -0
  249. package/unwrapper.d.ts +27 -0
  250. package/wgslExtensions.d.ts +5 -0
  251. package/wgslExtensions.js +17 -0
  252. package/builtin-DdtWpk2t.js +0 -818
  253. package/builtin-DdtWpk2t.js.map +0 -1
  254. package/chunk-BYypO7fO.js +0 -18
  255. package/common/index.d.ts.map +0 -1
  256. package/common/index.js.map +0 -1
  257. package/data/index.d.ts.map +0 -1
  258. package/data/index.js.map +0 -1
  259. package/deepEqual-DQxK4vdp.js +0 -413
  260. package/deepEqual-DQxK4vdp.js.map +0 -1
  261. package/extensions-DIVuAfBM.js +0 -2032
  262. package/extensions-DIVuAfBM.js.map +0 -1
  263. package/fullScreenTriangle-CfFyQd_0.js +0 -543
  264. package/fullScreenTriangle-CfFyQd_0.js.map +0 -1
  265. package/index.d.ts.map +0 -1
  266. package/index.js.map +0 -1
  267. package/indexNamedExports-oL6tyaJ9.d.ts +0 -5697
  268. package/indexNamedExports-oL6tyaJ9.d.ts.map +0 -1
  269. package/operators-d-PMVTo7.js +0 -4158
  270. package/operators-d-PMVTo7.js.map +0 -1
  271. package/std/index.d.ts.map +0 -1
  272. package/std/index.js.map +0 -1
  273. package/texture-BagDrrks.js.map +0 -1
@@ -0,0 +1,161 @@
1
+ import { TgpuNamable } from "./shared/meta.js";
2
+ import { $gpuValueOf, $internal } from "./shared/symbols.js";
3
+ import { Default, NullableToOptional, Prettify } from "./shared/utilityTypes.js";
4
+ import { WgslComparisonSampler, WgslSampler } from "./data/sampler.js";
5
+ import { StorageFlag } from "./extension.js";
6
+ import { TgpuBufferMutable, TgpuBufferReadonly, TgpuBufferUniform } from "./core/buffer/bufferUsage.js";
7
+ import { SampledFlag } from "./core/texture/usageExtension.js";
8
+ import { Unwrapper } from "./unwrapper.js";
9
+ import { TgpuComparisonSampler, TgpuSampler } from "./core/sampler/sampler.js";
10
+ import { TgpuExternalTexture } from "./core/texture/externalTexture.js";
11
+ import { TgpuBuffer, UniformFlag } from "./core/buffer/buffer.js";
12
+ import { TgpuShaderStage } from "./types.js";
13
+ import { AnyWgslData, BaseData, F32, I32, U32 } from "./data/wgslTypes.js";
14
+ import { StorageTextureFormats } from "./core/texture/textureFormats.js";
15
+ import { StorageTextureDimension, TextureSchemaForDescriptor, WgslExternalTexture, WgslStorageTexture, WgslTexture } from "./data/texture.js";
16
+ import { PropsForSchema, TgpuTexture, TgpuTextureView } from "./core/texture/texture.js";
17
+ import { InferGPU, MemIdentity } from "./shared/repr.js";
18
+
19
+ //#region src/tgpuBindGroupLayout.d.ts
20
+ type TgpuLayoutEntryBase = {
21
+ /**
22
+ * Limits this resource's visibility to specific shader stages.
23
+ *
24
+ * By default, each resource is visible to all shader stage types, but
25
+ * depending on the underlying implementation, this may have performance implications.
26
+ *
27
+ * @default ['compute','fragment'] for mutable resources
28
+ * @default ['compute','vertex','fragment'] for everything else
29
+ */
30
+ visibility?: TgpuShaderStage[];
31
+ };
32
+ type TgpuLayoutUniform = TgpuLayoutEntryBase & {
33
+ uniform: BaseData;
34
+ };
35
+ type TgpuLayoutStorage = TgpuLayoutEntryBase & {
36
+ storage: BaseData | ((arrayLength: number) => BaseData); /** @default 'readonly' */
37
+ access?: 'mutable' | 'readonly';
38
+ };
39
+ type TgpuLayoutSampler = TgpuLayoutEntryBase & {
40
+ sampler: 'filtering' | 'non-filtering';
41
+ };
42
+ type TgpuLayoutComparisonSampler = TgpuLayoutEntryBase & {
43
+ sampler: 'comparison';
44
+ };
45
+ type TgpuLayoutTexture<TSchema extends WgslTexture = WgslTexture> = TgpuLayoutEntryBase & {
46
+ texture: TSchema;
47
+ sampleType?: GPUTextureSampleType;
48
+ };
49
+ type TgpuLayoutStorageTexture<TSchema extends WgslStorageTexture = WgslStorageTexture> = TgpuLayoutEntryBase & {
50
+ storageTexture: TSchema;
51
+ };
52
+ type TgpuLayoutExternalTexture = TgpuLayoutEntryBase & {
53
+ externalTexture: WgslExternalTexture;
54
+ };
55
+ type TgpuLegacyLayoutTexture<TSampleType extends GPUTextureSampleType = GPUTextureSampleType> = TgpuLayoutEntryBase & {
56
+ /**
57
+ * - 'float' - f32
58
+ * - 'unfilterable-float' - f32, cannot be used with filtering samplers
59
+ * - 'depth' - f32
60
+ * - 'sint' - i32
61
+ * - 'uint' - u32
62
+ */
63
+ texture: TSampleType;
64
+ /**
65
+ * @default '2d'
66
+ */
67
+ viewDimension?: GPUTextureViewDimension;
68
+ /**
69
+ * @default false
70
+ */
71
+ multisampled?: boolean;
72
+ };
73
+ type TgpuLegacyLayoutStorageTexture<TFormat extends StorageTextureFormats = StorageTextureFormats> = TgpuLayoutEntryBase & {
74
+ storageTexture: TFormat; /** @default 'writeonly' */
75
+ access?: 'readonly' | 'writeonly' | 'mutable'; /** @default '2d' */
76
+ viewDimension?: StorageTextureDimension;
77
+ };
78
+ type TgpuLegacyLayoutExternalTexture = TgpuLayoutEntryBase & {
79
+ externalTexture: Record<string, never>;
80
+ };
81
+ type TgpuLegacyLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler | TgpuLayoutComparisonSampler | TgpuLegacyLayoutTexture | TgpuLegacyLayoutStorageTexture | TgpuLegacyLayoutExternalTexture;
82
+ type TgpuLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler | TgpuLayoutComparisonSampler | TgpuLayoutTexture | TgpuLayoutStorageTexture | TgpuLayoutExternalTexture;
83
+ type SampleTypeToPrimitive = {
84
+ float: F32;
85
+ 'unfilterable-float': F32;
86
+ depth: F32;
87
+ sint: I32;
88
+ uint: U32;
89
+ };
90
+ type LeagcyAccessToAccess = {
91
+ writeonly: 'write-only';
92
+ readonly: 'read-only';
93
+ mutable: 'read-write';
94
+ };
95
+ type MapLegacyTextureToUpToDate<T extends Record<string, TgpuLegacyLayoutEntry | TgpuLayoutEntry | null>> = { [K in keyof T]: T[K] extends TgpuLayoutEntry | null ? T[K] : T[K] extends TgpuLegacyLayoutTexture<infer SampleType> ? TgpuLayoutTexture<TextureSchemaForDescriptor<{
96
+ dimension: Default<T[K]['viewDimension'], '2d'>;
97
+ sampleType: SampleTypeToPrimitive[SampleType];
98
+ multisampled: Default<T[K]['multisampled'], false>;
99
+ }>> : T[K] extends TgpuLegacyLayoutStorageTexture<infer Format> ? TgpuLayoutStorageTexture<TextureSchemaForDescriptor<{
100
+ access: LeagcyAccessToAccess[Default<T[K]['access'], 'writeonly'>];
101
+ format: Format;
102
+ dimension: Default<T[K]['viewDimension'], '2d'>;
103
+ }>> : T[K] extends TgpuLegacyLayoutExternalTexture ? TgpuLayoutExternalTexture : never };
104
+ type UnwrapRuntimeConstructorInner<T extends BaseData | ((_: number) => BaseData)> = T extends ((_: number) => BaseData) ? ReturnType<T> : T;
105
+ type UnwrapRuntimeConstructor<T extends BaseData | ((_: number) => BaseData)> = T extends unknown ? UnwrapRuntimeConstructorInner<T> : never;
106
+ interface BindGroupLayoutInternals<Entries extends Record<string, TgpuLayoutEntry | null>> {
107
+ bound: { [K in keyof Entries]: BindLayoutEntry<Entries[K]> };
108
+ }
109
+ interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> extends TgpuNamable {
110
+ readonly [$internal]: BindGroupLayoutInternals<Entries>;
111
+ readonly resourceType: 'bind-group-layout';
112
+ readonly entries: Entries;
113
+ /**
114
+ * @deprecated Use `layout.$.foo` instead of `layout.bound.foo.$`
115
+ */
116
+ readonly bound: { [K in keyof Entries]: BindLayoutEntry<Entries[K]> };
117
+ readonly [$gpuValueOf]: { [K in keyof Entries]: InferLayoutEntry<Entries[K]> };
118
+ /**
119
+ * @deprecated Use `.$` instead, works the same way.
120
+ */
121
+ readonly value: { [K in keyof Entries]: InferLayoutEntry<Entries[K]> };
122
+ readonly $: { [K in keyof Entries]: InferLayoutEntry<Entries[K]> };
123
+ /**
124
+ * An explicit numeric index assigned to this bind group layout. If undefined, a unique
125
+ * index is assigned automatically during resolution. This can be changed with the
126
+ * `.$idx()` method.
127
+ */
128
+ readonly index: number | undefined;
129
+ /**
130
+ * Associates this bind group layout with an explicit numeric index. When a call to this
131
+ * method is omitted, a unique numeric index is assigned to it automatically.
132
+ *
133
+ * Used when generating WGSL code: `@group(${index}) @binding(...) ...;`
134
+ */
135
+ $idx(index?: number): this;
136
+ /**
137
+ * Creates a raw WebGPU resource based on the typed descriptor.
138
+ * NOTE: This creates a new resource every time, better to use `root.unwrap(...)` instead.
139
+ * @param unwrapper Used to unwrap any resources that this resource depends on.
140
+ */
141
+ unwrap(unwrapper: Unwrapper): GPUBindGroupLayout;
142
+ }
143
+ type StorageUsageForEntry<T extends TgpuLayoutStorage> = T extends {
144
+ access?: infer Access;
145
+ } ? 'mutable' | 'readonly' extends Access ? TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> | TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : 'readonly' extends Access ? TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> : 'mutable' extends Access ? TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> | TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>>;
146
+ type LayoutEntryToInput<T extends TgpuLayoutEntry | null> = TgpuLayoutEntry | null extends T ? TgpuBuffer<AnyWgslData> | GPUBuffer | TgpuSampler | GPUSampler | TgpuComparisonSampler | TgpuTexture | GPUTextureView | GPUExternalTexture : T extends TgpuLayoutUniform ? (TgpuBuffer<MemIdentity<UnwrapRuntimeConstructor<T['uniform']>>> & UniformFlag) | GPUBuffer : T extends TgpuLayoutStorage ? (TgpuBuffer<MemIdentity<UnwrapRuntimeConstructor<T['storage']>>> & StorageFlag) | GPUBuffer : T extends TgpuLayoutSampler ? TgpuSampler | GPUSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler | GPUSampler : T extends TgpuLayoutTexture ? GPUTextureView | GPUTexture | (SampledFlag & TgpuTexture<Prettify<PropsForSchema<T['texture']>>>) | TgpuTextureView<WgslTexture> : T extends TgpuLayoutStorageTexture ? GPUTextureView | GPUTexture | (StorageFlag & TgpuTexture<Prettify<PropsForSchema<T['storageTexture']>>>) | TgpuTextureView<WgslStorageTexture> : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
147
+ type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform<T['uniform']> : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> : T extends TgpuLayoutSampler ? TgpuSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler : T extends TgpuLayoutTexture<infer TSchema> ? TgpuTextureView<TSchema> : T extends TgpuLayoutStorageTexture<infer TSchema> ? TgpuTextureView<TSchema> : T extends TgpuLayoutExternalTexture ? TgpuExternalTexture : never;
148
+ type InferLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? InferGPU<T['uniform']> : T extends TgpuLayoutStorage ? InferGPU<UnwrapRuntimeConstructor<T['storage']>> : T extends TgpuLayoutSampler ? InferGPU<WgslSampler> : T extends TgpuLayoutComparisonSampler ? InferGPU<WgslComparisonSampler> : T extends TgpuLayoutTexture<infer TSchema> ? InferGPU<TSchema> : T extends TgpuLayoutStorageTexture<infer TSchema> ? InferGPU<TSchema> : T extends TgpuLayoutExternalTexture ? InferGPU<T['externalTexture']> : never;
149
+ type ExtractBindGroupInputFromLayout<T extends Record<string, TgpuLayoutEntry | null>> = NullableToOptional<{ [K in keyof T]: LayoutEntryToInput<T[K]> }>;
150
+ type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
151
+ readonly resourceType: 'bind-group';
152
+ readonly layout: TgpuBindGroupLayout<Entries>;
153
+ unwrap(unwrapper: Unwrapper): GPUBindGroup;
154
+ };
155
+ declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Prettify<Entries>>;
156
+ /**
157
+ * @deprecated Layouts containing the legacy texture api entries are deprecated and will be removed in future versions. Please use the up-to-date texture api entries instead.
158
+ */
159
+ declare function bindGroupLayout<Entries extends Record<string, TgpuLegacyLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Prettify<MapLegacyTextureToUpToDate<Entries>>>;
160
+ //#endregion
161
+ export { BindLayoutEntry, ExtractBindGroupInputFromLayout, LayoutEntryToInput, TgpuBindGroup, TgpuBindGroupLayout, TgpuLayoutComparisonSampler, TgpuLayoutEntry, TgpuLayoutExternalTexture, TgpuLayoutSampler, TgpuLayoutStorage, TgpuLayoutTexture, TgpuLayoutUniform, UnwrapRuntimeConstructor, bindGroupLayout };
@@ -0,0 +1,272 @@
1
+ import { $gpuValueOf, $internal } from "./shared/symbols.js";
2
+ import { getName, setName } from "./shared/meta.js";
3
+ import { NotUniformError } from "./errors.js";
4
+ import { safeStringify } from "./shared/stringify.js";
5
+ import { f32, i32, u32 } from "./data/numeric.js";
6
+ import { NotStorageError, isUsableAsStorage } from "./extension.js";
7
+ import { TgpuLaidOutBufferImpl, isUsableAsUniform } from "./core/buffer/bufferUsage.js";
8
+ import { isBuffer } from "./core/buffer/buffer.js";
9
+ import { comparisonSampler, sampler } from "./data/sampler.js";
10
+ import { TgpuLaidOutSamplerImpl, isComparisonSampler, isSampler } from "./core/sampler/sampler.js";
11
+ import { textureDescriptorToSchema } from "./data/texture.js";
12
+ import { TgpuExternalTextureImpl } from "./core/texture/externalTexture.js";
13
+ import { TgpuLaidOutTextureViewImpl, isTexture, isTextureView } from "./core/texture/texture.js";
14
+ import { NotSampledError, isUsableAsSampled } from "./core/texture/usageExtension.js";
15
+ //#region src/tgpuBindGroupLayout.ts
16
+ /**
17
+ * Converts legacy entries to new API format
18
+ */
19
+ function convertLegacyEntries(entries) {
20
+ const result = {};
21
+ for (const [key, entry] of Object.entries(entries)) {
22
+ if (entry === null) {
23
+ result[key] = null;
24
+ continue;
25
+ }
26
+ if ("texture" in entry && typeof entry.texture === "string") {
27
+ const sampleType = entry.texture;
28
+ result[key] = {
29
+ ...entry,
30
+ texture: textureDescriptorToSchema({
31
+ dimension: entry.viewDimension ?? "2d",
32
+ sampleType: sampleType === "sint" ? i32 : sampleType === "uint" ? u32 : f32,
33
+ multisampled: entry.multisampled ?? false
34
+ })
35
+ };
36
+ } else if ("storageTexture" in entry && typeof entry.storageTexture === "string") {
37
+ const accessMap = {
38
+ readonly: "read-only",
39
+ writeonly: "write-only",
40
+ mutable: "read-write"
41
+ };
42
+ result[key] = {
43
+ ...entry,
44
+ storageTexture: textureDescriptorToSchema({
45
+ access: accessMap[entry.access ?? "writeonly"],
46
+ format: entry.storageTexture,
47
+ dimension: entry.viewDimension ?? "2d"
48
+ })
49
+ };
50
+ } else if ("externalTexture" in entry && Object.keys(entry.externalTexture).length === 0) result[key] = {
51
+ ...entry,
52
+ externalTexture: {
53
+ type: "texture_external",
54
+ dimension: "2d"
55
+ }
56
+ };
57
+ else result[key] = entry;
58
+ }
59
+ return result;
60
+ }
61
+ function bindGroupLayout(entries) {
62
+ return new TgpuBindGroupLayoutImpl(convertLegacyEntries(entries));
63
+ }
64
+ function isBindGroupLayout(value) {
65
+ return !!value && value.resourceType === "bind-group-layout";
66
+ }
67
+ function isBindGroup(value) {
68
+ return !!value && value.resourceType === "bind-group";
69
+ }
70
+ /**
71
+ * @category Errors
72
+ */
73
+ var MissingBindingError = class MissingBindingError extends Error {
74
+ constructor(groupLabel, key) {
75
+ super(`Bind group '${groupLabel ?? "<unnamed>"}' is missing a required binding '${key}'`);
76
+ Object.setPrototypeOf(this, MissingBindingError.prototype);
77
+ }
78
+ };
79
+ const DEFAULT_MUTABLE_VISIBILITY = ["compute", "fragment"];
80
+ const DEFAULT_READONLY_VISIBILITY = [
81
+ "compute",
82
+ "vertex",
83
+ "fragment"
84
+ ];
85
+ var TgpuBindGroupLayoutImpl = class {
86
+ #index;
87
+ [$internal];
88
+ resourceType = "bind-group-layout";
89
+ value = {};
90
+ $ = this.value;
91
+ entries;
92
+ get [$gpuValueOf]() {
93
+ return this.$;
94
+ }
95
+ constructor(entries) {
96
+ this.entries = entries;
97
+ let idx = 0;
98
+ const bound = {};
99
+ this[$internal] = { bound };
100
+ for (const [key, entry] of Object.entries(entries)) {
101
+ if (entry === null) {
102
+ idx++;
103
+ continue;
104
+ }
105
+ const membership = {
106
+ layout: this,
107
+ key,
108
+ idx
109
+ };
110
+ if ("uniform" in entry) bound[key] = new TgpuLaidOutBufferImpl("uniform", entry.uniform, membership);
111
+ if ("storage" in entry) {
112
+ const dataType = "type" in entry.storage ? entry.storage : entry.storage(0);
113
+ bound[key] = new TgpuLaidOutBufferImpl(entry.access ?? "readonly", dataType, membership);
114
+ }
115
+ if ("texture" in entry) bound[key] = new TgpuLaidOutTextureViewImpl(entry.texture, membership);
116
+ if ("storageTexture" in entry) bound[key] = new TgpuLaidOutTextureViewImpl(entry.storageTexture, membership);
117
+ if ("externalTexture" in entry) bound[key] = new TgpuExternalTextureImpl(entry.externalTexture, membership);
118
+ if ("sampler" in entry) bound[key] = new TgpuLaidOutSamplerImpl(entry.sampler === "comparison" ? comparisonSampler() : sampler(), membership);
119
+ Object.defineProperty(this.value, key, { get: () => {
120
+ return bound[key].value;
121
+ } });
122
+ idx++;
123
+ }
124
+ }
125
+ toString() {
126
+ return `bindGroupLayout:${getName(this) ?? "<unnamed>"}`;
127
+ }
128
+ get index() {
129
+ return this.#index;
130
+ }
131
+ $name(label) {
132
+ setName(this, label);
133
+ return this;
134
+ }
135
+ get bound() {
136
+ return this[$internal].bound;
137
+ }
138
+ $idx(index) {
139
+ this.#index = index;
140
+ return this;
141
+ }
142
+ unwrap(unwrapper) {
143
+ return unwrapper.device.createBindGroupLayout({
144
+ label: getName(this) ?? "<unnamed>",
145
+ entries: Object.values(this.entries).map((entry, idx) => {
146
+ if (entry === null) return null;
147
+ let visibility = entry.visibility;
148
+ const binding = {
149
+ binding: idx,
150
+ visibility: 0
151
+ };
152
+ if ("uniform" in entry) {
153
+ visibility = visibility ?? DEFAULT_READONLY_VISIBILITY;
154
+ binding.buffer = { type: "uniform" };
155
+ } else if ("storage" in entry) {
156
+ visibility = visibility ?? (entry.access === "mutable" ? DEFAULT_MUTABLE_VISIBILITY : DEFAULT_READONLY_VISIBILITY);
157
+ binding.buffer = { type: entry.access === "mutable" ? "storage" : "read-only-storage" };
158
+ } else if ("sampler" in entry) {
159
+ visibility = visibility ?? DEFAULT_READONLY_VISIBILITY;
160
+ binding.sampler = { type: entry.sampler };
161
+ } else if ("texture" in entry) {
162
+ visibility = visibility ?? DEFAULT_READONLY_VISIBILITY;
163
+ const { multisampled, dimension, bindingSampleType } = entry.texture;
164
+ binding.texture = {
165
+ sampleType: entry.sampleType ?? bindingSampleType[0],
166
+ viewDimension: dimension,
167
+ multisampled
168
+ };
169
+ } else if ("storageTexture" in entry) {
170
+ visibility = visibility ?? DEFAULT_MUTABLE_VISIBILITY;
171
+ const { dimension, access, format } = entry.storageTexture;
172
+ binding.storageTexture = {
173
+ access,
174
+ format,
175
+ viewDimension: dimension
176
+ };
177
+ } else if ("externalTexture" in entry) {
178
+ visibility = visibility ?? DEFAULT_READONLY_VISIBILITY;
179
+ binding.externalTexture = {};
180
+ }
181
+ if (visibility?.includes("compute")) binding.visibility |= GPUShaderStage.COMPUTE;
182
+ if (visibility?.includes("vertex")) binding.visibility |= GPUShaderStage.VERTEX;
183
+ if (visibility?.includes("fragment")) binding.visibility |= GPUShaderStage.FRAGMENT;
184
+ return binding;
185
+ }).filter((v) => v !== null)
186
+ });
187
+ }
188
+ };
189
+ var TgpuBindGroupImpl = class {
190
+ resourceType = "bind-group";
191
+ layout;
192
+ entries;
193
+ constructor(layout, entries) {
194
+ this.layout = layout;
195
+ this.entries = entries;
196
+ for (const key of Object.keys(layout.entries)) if (layout.entries[key] !== null && !(key in entries)) throw new MissingBindingError(getName(layout), key);
197
+ }
198
+ unwrap(unwrapper) {
199
+ return unwrapper.device.createBindGroup({
200
+ label: getName(this.layout) ?? "<unnamed>",
201
+ layout: unwrapper.unwrap(this.layout),
202
+ entries: Object.entries(this.layout.entries).map(([key, entry], idx) => {
203
+ if (entry === null) return null;
204
+ const value = this.entries[key];
205
+ if (value === void 0) throw new Error(`'${key}' is a resource required to populate bind group layout '${getName(this.layout) ?? "<unnamed>"}'.`);
206
+ if ("uniform" in entry) {
207
+ let resource;
208
+ if (isBuffer(value)) {
209
+ if (!isUsableAsUniform(value)) throw new NotUniformError(value);
210
+ resource = { buffer: unwrapper.unwrap(value) };
211
+ } else resource = { buffer: value };
212
+ return {
213
+ binding: idx,
214
+ resource
215
+ };
216
+ }
217
+ if ("storage" in entry) {
218
+ let resource;
219
+ if (isBuffer(value)) {
220
+ if (!isUsableAsStorage(value)) throw new NotStorageError(value);
221
+ resource = { buffer: unwrapper.unwrap(value) };
222
+ } else resource = { buffer: value };
223
+ return {
224
+ binding: idx,
225
+ resource
226
+ };
227
+ }
228
+ if ("texture" in entry) {
229
+ let resource;
230
+ if (isTexture(value)) {
231
+ if (!isUsableAsSampled(value)) throw new NotSampledError(value);
232
+ resource = unwrapper.unwrap(value.createView(entry.texture));
233
+ } else if (isTextureView(value)) resource = unwrapper.unwrap(value);
234
+ else resource = value;
235
+ return {
236
+ binding: idx,
237
+ resource
238
+ };
239
+ }
240
+ if ("storageTexture" in entry) {
241
+ let resource;
242
+ if (isTexture(value)) {
243
+ if (!isUsableAsStorage(value)) throw new NotStorageError(value);
244
+ resource = unwrapper.unwrap(value.createView(entry.storageTexture));
245
+ } else if (isTextureView(value)) resource = unwrapper.unwrap(value);
246
+ else resource = value;
247
+ return {
248
+ binding: idx,
249
+ resource
250
+ };
251
+ }
252
+ if ("sampler" in entry) {
253
+ if (isComparisonSampler(value) || isSampler(value)) return {
254
+ binding: idx,
255
+ resource: unwrapper.unwrap(value)
256
+ };
257
+ return {
258
+ binding: idx,
259
+ resource: value
260
+ };
261
+ }
262
+ if ("externalTexture" in entry) return {
263
+ binding: idx,
264
+ resource: value
265
+ };
266
+ throw new Error(`Malformed bind group entry: ${safeStringify(value)}`);
267
+ }).filter((v) => v !== null)
268
+ });
269
+ }
270
+ };
271
+ //#endregion
272
+ export { TgpuBindGroupImpl, bindGroupLayout, isBindGroup, isBindGroupLayout };
@@ -0,0 +1,48 @@
1
+ import { computeFn } from "./core/function/tgpuComputeFn.js";
2
+ import { privateVar, workgroupVar } from "./core/variable/tgpuVariable.js";
3
+ import { fragmentFn } from "./core/function/tgpuFragmentFn.js";
4
+ import { vertexFn } from "./core/function/tgpuVertexFn.js";
5
+ import { vertexLayout } from "./core/vertexLayout/vertexLayout.js";
6
+ import { declare } from "./core/declare/tgpuDeclare.js";
7
+ import { fn } from "./core/function/tgpuFn.js";
8
+ import { constant } from "./core/constant/tgpuConstant.js";
9
+ import { comptime } from "./core/function/comptime.js";
10
+ import { namespace } from "./core/resolve/namespace.js";
11
+ import { slot } from "./core/slot/slot.js";
12
+ import { lazy } from "./core/slot/lazy.js";
13
+ import { accessor, mutableAccessor } from "./core/slot/accessor.js";
14
+ import { rawCodeSnippet } from "./core/rawCodeSnippet/tgpuRawCodeSnippet.js";
15
+ import { simulate } from "./core/simulate/tgpuSimulate.js";
16
+
17
+ //#region src/tgpuUnstable.d.ts
18
+ declare namespace tgpuUnstable_d_exports {
19
+ export { _accessor as accessor, _comptime as comptime, _computeFn as computeFn, _constant as const, declare, _lazy as derived, _fn as fn, _fragmentFn as fragmentFn, _mutableAccessor as mutableAccessor, namespace, _privateVar as privateVar, rawCodeSnippet, simulate, _slot as slot, _vertexFn as vertexFn, _vertexLayout as vertexLayout, _workgroupVar as workgroupVar };
20
+ }
21
+ /** @deprecated This feature is now stable, use tgpu.const. */
22
+ declare const _constant: typeof constant;
23
+ /** @deprecated This feature is now stable, use tgpu.comptime. */
24
+ declare const _comptime: typeof comptime;
25
+ /** @deprecated This feature is now stable, use tgpu.computeFn. */
26
+ declare const _computeFn: typeof computeFn;
27
+ /** @deprecated This feature is now stable, use tgpu.fn. */
28
+ declare const _fn: typeof fn;
29
+ /** @deprecated This feature is now stable, use tgpu.fragmentFn. */
30
+ declare const _fragmentFn: typeof fragmentFn;
31
+ /** @deprecated This feature is now stable, use tgpu.vertexFn. */
32
+ declare const _vertexFn: typeof vertexFn;
33
+ /** @deprecated This feature is now stable, use tgpu.accessor. */
34
+ declare const _accessor: typeof accessor;
35
+ /** @deprecated This feature is now stable, use tgpu.mutableAccessor. */
36
+ declare const _mutableAccessor: typeof mutableAccessor;
37
+ /** @deprecated This feature is now stable, use tgpu.lazy. */
38
+ declare const _lazy: typeof lazy;
39
+ /** @deprecated This feature is now stable, use tgpu.slot. */
40
+ declare const _slot: typeof slot;
41
+ /** @deprecated This feature is now stable, use tgpu.privateVar. */
42
+ declare const _privateVar: typeof privateVar;
43
+ /** @deprecated This feature is now stable, use tgpu.workgroupVar. */
44
+ declare const _workgroupVar: typeof workgroupVar;
45
+ /** @deprecated This feature is now stable, use tgpu.vertexLayout. */
46
+ declare const _vertexLayout: typeof vertexLayout;
47
+ //#endregion
48
+ export { tgpuUnstable_d_exports };
@@ -0,0 +1,64 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { comptime } from "./core/function/comptime.js";
3
+ import { constant } from "./core/constant/tgpuConstant.js";
4
+ import { fn } from "./core/function/tgpuFn.js";
5
+ import { namespace } from "./core/resolve/namespace.js";
6
+ import { slot } from "./core/slot/slot.js";
7
+ import { privateVar, workgroupVar } from "./core/variable/tgpuVariable.js";
8
+ import { computeFn } from "./core/function/tgpuComputeFn.js";
9
+ import { vertexLayout } from "./core/vertexLayout/vertexLayout.js";
10
+ import { lazy } from "./core/slot/lazy.js";
11
+ import { accessor, mutableAccessor } from "./core/slot/accessor.js";
12
+ import { fragmentFn } from "./core/function/tgpuFragmentFn.js";
13
+ import { vertexFn } from "./core/function/tgpuVertexFn.js";
14
+ import { declare } from "./core/declare/tgpuDeclare.js";
15
+ import { rawCodeSnippet } from "./core/rawCodeSnippet/tgpuRawCodeSnippet.js";
16
+ import { simulate } from "./core/simulate/tgpuSimulate.js";
17
+ //#region src/tgpuUnstable.ts
18
+ var tgpuUnstable_exports = /* @__PURE__ */ __exportAll({
19
+ accessor: () => _accessor,
20
+ comptime: () => _comptime,
21
+ computeFn: () => _computeFn,
22
+ const: () => _constant,
23
+ declare: () => declare,
24
+ derived: () => _lazy,
25
+ fn: () => _fn,
26
+ fragmentFn: () => _fragmentFn,
27
+ mutableAccessor: () => _mutableAccessor,
28
+ namespace: () => namespace,
29
+ privateVar: () => _privateVar,
30
+ rawCodeSnippet: () => rawCodeSnippet,
31
+ simulate: () => simulate,
32
+ slot: () => _slot,
33
+ vertexFn: () => _vertexFn,
34
+ vertexLayout: () => _vertexLayout,
35
+ workgroupVar: () => _workgroupVar
36
+ });
37
+ /** @deprecated This feature is now stable, use tgpu.const. */
38
+ const _constant = constant;
39
+ /** @deprecated This feature is now stable, use tgpu.comptime. */
40
+ const _comptime = comptime;
41
+ /** @deprecated This feature is now stable, use tgpu.computeFn. */
42
+ const _computeFn = computeFn;
43
+ /** @deprecated This feature is now stable, use tgpu.fn. */
44
+ const _fn = fn;
45
+ /** @deprecated This feature is now stable, use tgpu.fragmentFn. */
46
+ const _fragmentFn = fragmentFn;
47
+ /** @deprecated This feature is now stable, use tgpu.vertexFn. */
48
+ const _vertexFn = vertexFn;
49
+ /** @deprecated This feature is now stable, use tgpu.accessor. */
50
+ const _accessor = accessor;
51
+ /** @deprecated This feature is now stable, use tgpu.mutableAccessor. */
52
+ const _mutableAccessor = mutableAccessor;
53
+ /** @deprecated This feature is now stable, use tgpu.lazy. */
54
+ const _lazy = lazy;
55
+ /** @deprecated This feature is now stable, use tgpu.slot. */
56
+ const _slot = slot;
57
+ /** @deprecated This feature is now stable, use tgpu.privateVar. */
58
+ const _privateVar = privateVar;
59
+ /** @deprecated This feature is now stable, use tgpu.workgroupVar. */
60
+ const _workgroupVar = workgroupVar;
61
+ /** @deprecated This feature is now stable, use tgpu.vertexLayout. */
62
+ const _vertexLayout = vertexLayout;
63
+ //#endregion
64
+ export { tgpuUnstable_exports };
@@ -0,0 +1,43 @@
1
+ import { isNaturallyEphemeral, isPtr, isVec, isWgslArray, isWgslStruct } from "../data/wgslTypes.js";
2
+ import { MatrixColumnsAccess, UnknownData, isDisarray } from "../data/dataTypes.js";
3
+ import { isEphemeralSnippet, snip } from "../data/snippet.js";
4
+ import { isKnownAtComptime } from "../types.js";
5
+ import { stitch } from "../core/resolve/stitch.js";
6
+ import { derefSnippet } from "../data/ref.js";
7
+ import { coerceToSnippet } from "./generationHelpers.js";
8
+ import { vec2f, vec3f, vec4f } from "../data/vector.js";
9
+ import { accessProp } from "./accessProp.js";
10
+ //#region src/tgsl/accessIndex.ts
11
+ const indexableTypeToResult = {
12
+ mat2x2f: vec2f,
13
+ mat3x3f: vec3f,
14
+ mat4x4f: vec4f
15
+ };
16
+ function accessIndex(target, indexArg) {
17
+ const index = typeof indexArg === "number" ? coerceToSnippet(indexArg) : indexArg;
18
+ if (isWgslArray(target.dataType) || isDisarray(target.dataType)) {
19
+ const elementType = target.dataType.elementType;
20
+ const isElementNatEph = isNaturallyEphemeral(elementType);
21
+ const isTargetEphemeral = isEphemeralSnippet(target);
22
+ const isIndexConstant = index.origin === "constant";
23
+ let origin;
24
+ if (target.origin === "constant-tgpu-const-ref") if (isIndexConstant) origin = isElementNatEph ? "constant" : "constant-tgpu-const-ref";
25
+ else origin = isElementNatEph ? "runtime" : "runtime-tgpu-const-ref";
26
+ else if (target.origin === "runtime-tgpu-const-ref") origin = isElementNatEph ? "runtime" : "runtime-tgpu-const-ref";
27
+ else if (!isTargetEphemeral && !isElementNatEph) origin = target.origin;
28
+ else if (isIndexConstant && target.origin === "constant") origin = "constant";
29
+ else origin = "runtime";
30
+ return snip(isKnownAtComptime(target) && isKnownAtComptime(index) ? target.value[index.value] : stitch`${target}[${index}]`, elementType, origin);
31
+ }
32
+ if (isVec(target.dataType)) return snip(isKnownAtComptime(target) && isKnownAtComptime(index) ? target.value[index.value] : stitch`${target}[${index}]`, target.dataType.primitive, target.origin === "constant" || target.origin === "constant-tgpu-const-ref" ? "constant" : "runtime");
33
+ if (isPtr(target.dataType)) return accessIndex(derefSnippet(target), index);
34
+ if (target.value instanceof MatrixColumnsAccess) {
35
+ const propType = indexableTypeToResult[target.value.matrix.dataType.type];
36
+ return snip(stitch`${target.value.matrix}[${index}]`, propType, target.origin);
37
+ }
38
+ if (target.dataType.type in indexableTypeToResult) throw new Error("The only way of accessing matrix elements in TypeGPU functions is through the 'columns' property.");
39
+ if (isKnownAtComptime(target) && isKnownAtComptime(index) || target.dataType === UnknownData) return coerceToSnippet(target.value[index.value]);
40
+ if (isWgslStruct(target.dataType) && isKnownAtComptime(index) && typeof index.value === "string") return accessProp(target, index.value);
41
+ }
42
+ //#endregion
43
+ export { accessIndex };