typegpu 0.12.8 → 0.12.10

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 (119) hide show
  1. package/common/attachAutoResizer.d.ts +33 -0
  2. package/common/attachAutoResizer.js +83 -0
  3. package/common/index.d.ts +1 -0
  4. package/common/index.js +1 -0
  5. package/common/writeSoA.js +4 -3
  6. package/core/commandEncoder/commandEncoder.d.ts +1 -1
  7. package/core/declare/tgpuDeclare.d.ts +10 -7
  8. package/core/declare/tgpuDeclare.js +25 -10
  9. package/core/function/comptime.d.ts +2 -0
  10. package/core/function/comptime.js +29 -24
  11. package/core/function/createCallableSchema.js +32 -37
  12. package/core/function/dualImpl.js +45 -44
  13. package/core/function/tgpuComputeFn.d.ts +0 -3
  14. package/core/function/tgpuFn.d.ts +1 -0
  15. package/core/function/tgpuFn.js +14 -4
  16. package/core/function/tgpuFragmentFn.d.ts +1 -1
  17. package/core/function/tgpuVertexFn.d.ts +1 -1
  18. package/core/pipeline/computePipeline.js +5 -2
  19. package/core/pipeline/drawState.js +1 -1
  20. package/core/pipeline/renderPipeline.js +5 -2
  21. package/core/pipeline/webgpuLimitations.js +11 -3
  22. package/core/resolve/externals.js +4 -0
  23. package/core/resolve/namespace.d.ts +4 -0
  24. package/core/resolve/namespace.js +1 -2
  25. package/core/resolve/stitch.js +13 -8
  26. package/core/root/init.d.ts +3 -3
  27. package/core/root/init.js +12 -13
  28. package/core/root/rootTypes.d.ts +44 -37
  29. package/core/slot/accessor.js +4 -4
  30. package/core/texture/texture.d.ts +3 -3
  31. package/core/texture/texture.js +60 -44
  32. package/core/texture/textureFormats.d.ts +4 -3
  33. package/core/texture/textureFormats.js +17 -6
  34. package/core/texture/textureWrite.d.ts +9 -0
  35. package/core/texture/textureWrite.js +21 -0
  36. package/core/unroll/tgpuUnroll.js +2 -4
  37. package/core/vertexLayout/vertexAttribute.d.ts +1 -4
  38. package/core/vertexLayout/vertexLayout.js +11 -30
  39. package/data/alignmentOf.d.ts +1 -1
  40. package/data/alignmentOf.js +5 -12
  41. package/data/array.js +34 -2
  42. package/data/attributes.d.ts +16 -3
  43. package/data/attributes.js +11 -2
  44. package/data/compiledIO.js +3 -3
  45. package/data/dataIO.js +77 -111
  46. package/data/dataTypes.d.ts +0 -2
  47. package/data/dataTypes.js +3 -3
  48. package/data/disarray.js +2 -0
  49. package/data/index.d.ts +4 -3
  50. package/data/index.js +3 -2
  51. package/data/offsetUtils.js +23 -13
  52. package/data/offsets.js +1 -2
  53. package/data/partialIO.js +2 -3
  54. package/data/ref.js +35 -37
  55. package/data/schemaCallWrapper.js +2 -2
  56. package/data/schemaMemoryLayout.d.ts +6 -1
  57. package/data/schemaMemoryLayout.js +23 -14
  58. package/data/schemasEqual.d.ts +37 -0
  59. package/data/schemasEqual.js +122 -0
  60. package/data/sizeOf.d.ts +1 -1
  61. package/data/sizeOf.js +2 -3
  62. package/data/snippet.d.ts +1 -1
  63. package/data/struct.js +27 -1
  64. package/data/unstruct.js +2 -0
  65. package/data/vectorImpl.js +45 -21
  66. package/data/vertexFormatData.js +7 -9
  67. package/data/wgslTypes.d.ts +28 -13
  68. package/data/wgslTypes.js +33 -39
  69. package/extension.d.ts +0 -4
  70. package/package.json +2 -2
  71. package/resolutionCtx.d.ts +1 -1
  72. package/resolutionCtx.js +26 -7
  73. package/serial/restore.d.ts +4 -3
  74. package/serial/restore.js +2 -1
  75. package/shared/meta.js +1 -1
  76. package/shared/symbols.d.ts +5 -0
  77. package/shared/symbols.js +6 -1
  78. package/shared/utilityTypes.d.ts +0 -6
  79. package/std/bitcast.d.ts +1 -1
  80. package/std/comptime.d.ts +67 -0
  81. package/std/comptime.js +88 -0
  82. package/std/environment.js +2 -4
  83. package/std/index.d.ts +2 -0
  84. package/std/index.js +2 -0
  85. package/std/matrix.js +5 -5
  86. package/std/numeric.d.ts +2 -1
  87. package/std/numeric.js +47 -10
  88. package/std/typeOf.d.ts +31 -0
  89. package/std/typeOf.js +54 -0
  90. package/tgpu.d.ts +1 -1
  91. package/tgpu.js +1 -1
  92. package/tgpuBindGroupLayout.d.ts +6 -3
  93. package/tgpuBindGroupLayout.js +15 -2
  94. package/tgpuLogger.d.ts +3 -0
  95. package/tgpuLogger.js +3 -0
  96. package/tgpuUnstableNamespace.d.ts +1 -0
  97. package/tgpuUnstableNamespace.js +5 -0
  98. package/tgsl/accessIndex.js +10 -7
  99. package/tgsl/accessProp.js +5 -57
  100. package/tgsl/consoleLog/serializers.d.ts +1 -8
  101. package/tgsl/consoleLog/serializers.js +53 -37
  102. package/tgsl/consoleLog/types.d.ts +1 -1
  103. package/tgsl/conversion.js +21 -0
  104. package/tgsl/forOfUtils.js +1 -1
  105. package/tgsl/generationHelpers.d.ts +0 -1
  106. package/tgsl/generationHelpers.js +1 -4
  107. package/tgsl/shaderGenerator.d.ts +5 -0
  108. package/tgsl/shellless.js +3 -20
  109. package/tgsl/swizzle.d.ts +24 -0
  110. package/tgsl/swizzle.js +112 -0
  111. package/tgsl/wgslGenerator.d.ts +13 -3
  112. package/tgsl/wgslGenerator.js +150 -152
  113. package/types.d.ts +10 -10
  114. package/types.js +1 -1
  115. package/unwrapper.d.ts +2 -2
  116. package/data/deepEqual.d.ts +0 -21
  117. package/data/deepEqual.js +0 -93
  118. package/taskQueue.d.ts +0 -6
  119. package/taskQueue.js +0 -30
package/data/wgslTypes.js CHANGED
@@ -66,22 +66,19 @@ export const wgslTypeLiterals = [
66
66
  // #endregion
67
67
  export function isVecInstance(value) {
68
68
  const v = value;
69
- return isMarkedInternal(v) && typeof v.kind === 'string' && v.kind.startsWith('vec');
70
- }
71
- export function isVecBoolInstance(value) {
72
- return isVecInstance(value) && value.kind.includes('b');
69
+ return typeof v?.kind === 'string' && v.kind.startsWith('vec') && isMarkedInternal(v);
73
70
  }
74
71
  export function isVec2(value) {
75
72
  const v = value;
76
- return isMarkedInternal(v) && typeof v.type === 'string' && v.type.startsWith('vec2');
73
+ return typeof v?.type === 'string' && v.type.startsWith('vec2') && isMarkedInternal(v);
77
74
  }
78
75
  export function isVec3(value) {
79
76
  const v = value;
80
- return isMarkedInternal(v) && typeof v.type === 'string' && v.type.startsWith('vec3');
77
+ return typeof v?.type === 'string' && v.type.startsWith('vec3') && isMarkedInternal(v);
81
78
  }
82
79
  export function isVec4(value) {
83
80
  const v = value;
84
- return isMarkedInternal(v) && typeof v.type === 'string' && v.type.startsWith('vec4');
81
+ return typeof v?.type === 'string' && v.type.startsWith('vec4') && isMarkedInternal(v);
85
82
  }
86
83
  export function isVec(value) {
87
84
  return isVec2(value) || isVec3(value) || isVec4(value);
@@ -91,22 +88,22 @@ export function isVecBool(value) {
91
88
  }
92
89
  export function isMatInstance(value) {
93
90
  const v = value;
94
- return (isMarkedInternal(v) && typeof v.kind?.startsWith === 'function' && v.kind.startsWith('mat'));
91
+ return (typeof v?.kind?.startsWith === 'function' && v.kind.startsWith('mat') && isMarkedInternal(v));
95
92
  }
96
93
  export function isMat2x2f(value) {
97
- return isMarkedInternal(value) && value?.type === 'mat2x2f';
94
+ return value?.type === 'mat2x2f' && isMarkedInternal(value);
98
95
  }
99
96
  export function isMat3x3f(value) {
100
- return isMarkedInternal(value) && value?.type === 'mat3x3f';
97
+ return value?.type === 'mat3x3f' && isMarkedInternal(value);
101
98
  }
102
99
  export function isMat4x4f(value) {
103
- return isMarkedInternal(value) && value?.type === 'mat4x4f';
100
+ return value?.type === 'mat4x4f' && isMarkedInternal(value);
104
101
  }
105
102
  export function isMat(value) {
106
103
  return isMat2x2f(value) || isMat3x3f(value) || isMat4x4f(value);
107
104
  }
108
105
  export function isInteger(value) {
109
- return (isMarkedInternal(value) && ['abstractInt', 'i32', 'u32'].includes(value?.type));
106
+ return (['abstractInt', 'i32', 'u32'].includes(value?.type) && isMarkedInternal(value));
110
107
  }
111
108
  export function isIntegerVec(value) {
112
109
  return isVec(value) && isInteger(value.primitive);
@@ -136,7 +133,7 @@ export function isWgslData(value) {
136
133
  * isWgslArray(d.vec3f) // false
137
134
  */
138
135
  export function isWgslArray(schema) {
139
- return isMarkedInternal(schema) && schema?.type === 'array';
136
+ return schema?.type === 'array' && isMarkedInternal(schema);
140
137
  }
141
138
  /**
142
139
  * Checks whether passed in value is a struct schema,
@@ -151,7 +148,7 @@ export function isWgslArray(schema) {
151
148
  * isWgslStruct(d.vec3f) // false
152
149
  */
153
150
  export function isWgslStruct(schema) {
154
- return isMarkedInternal(schema) && schema?.type === 'struct';
151
+ return schema?.type === 'struct' && isMarkedInternal(schema);
155
152
  }
156
153
  /**
157
154
  * Checks whether passed in value is a pointer schema.
@@ -162,7 +159,7 @@ export function isWgslStruct(schema) {
162
159
  * isPtr(d.f32) // false
163
160
  */
164
161
  export function isPtr(schema) {
165
- return isMarkedInternal(schema) && schema?.type === 'ptr';
162
+ return schema?.type === 'ptr' && isMarkedInternal(schema);
166
163
  }
167
164
  /**
168
165
  * Checks whether the passed in value is an atomic schema.
@@ -172,61 +169,58 @@ export function isPtr(schema) {
172
169
  * isAtomic(d.u32) // false
173
170
  */
174
171
  export function isAtomic(schema) {
175
- return isMarkedInternal(schema) && schema?.type === 'atomic';
172
+ return schema?.type === 'atomic' && isMarkedInternal(schema);
176
173
  }
177
174
  export function isAlignAttrib(value) {
178
- return isMarkedInternal(value) && value?.type === '@align';
175
+ return value?.type === '@align' && isMarkedInternal(value);
179
176
  }
180
177
  export function isSizeAttrib(value) {
181
- return isMarkedInternal(value) && value?.type === '@size';
178
+ return value?.type === '@size' && isMarkedInternal(value);
182
179
  }
183
180
  export function isLocationAttrib(value) {
184
- return isMarkedInternal(value) && value?.type === '@location';
181
+ return value?.type === '@location' && isMarkedInternal(value);
185
182
  }
186
183
  export function isInterpolateAttrib(value) {
187
- return isMarkedInternal(value) && value?.type === '@interpolate';
184
+ return value?.type === '@interpolate' && isMarkedInternal(value);
188
185
  }
189
186
  export function isBuiltinAttrib(value) {
190
- return isMarkedInternal(value) && value?.type === '@builtin';
187
+ return value?.type === '@builtin' && isMarkedInternal(value);
191
188
  }
192
189
  export function isInvariantAttrib(value) {
193
- return isMarkedInternal(value) && value?.type === '@invariant';
190
+ return value?.type === '@invariant' && isMarkedInternal(value);
194
191
  }
195
192
  export function isDecorated(value) {
196
- return isMarkedInternal(value) && value?.type === 'decorated';
193
+ return value?.type === 'decorated' && isMarkedInternal(value);
197
194
  }
198
195
  export function isAbstractFloat(value) {
199
- return isMarkedInternal(value) && value.type === 'abstractFloat';
196
+ return value?.type === 'abstractFloat' && isMarkedInternal(value);
200
197
  }
201
198
  export function isAbstractInt(value) {
202
- return isMarkedInternal(value) && value.type === 'abstractInt';
199
+ return value?.type === 'abstractInt' && isMarkedInternal(value);
203
200
  }
204
201
  export function isAbstract(value) {
205
202
  return isAbstractFloat(value) || isAbstractInt(value);
206
203
  }
207
- export function isConcrete(value) {
208
- return !isAbstract(value);
209
- }
210
204
  export function isVoid(value) {
211
- return isMarkedInternal(value) && value.type === 'void';
205
+ return value?.type === 'void' && isMarkedInternal(value);
212
206
  }
213
207
  export function isBool(value) {
214
- return isMarkedInternal(value) && value.type === 'bool';
208
+ return value?.type === 'bool' && isMarkedInternal(value);
215
209
  }
216
210
  export function isNumericSchema(schema) {
217
211
  const type = schema?.type;
218
- return (isMarkedInternal(schema) &&
219
- (type === 'abstractInt' ||
220
- type === 'abstractFloat' ||
221
- type === 'f32' ||
222
- type === 'f16' ||
223
- type === 'i32' ||
224
- type === 'u32'));
212
+ return ((type === 'abstractInt' ||
213
+ type === 'abstractFloat' ||
214
+ type === 'f32' ||
215
+ type === 'f16' ||
216
+ type === 'i32' ||
217
+ type === 'u32') &&
218
+ isMarkedInternal(schema));
225
219
  }
226
220
  export function isHalfPrecisionSchema(schema) {
227
221
  const type = schema?.type;
228
- return (isMarkedInternal(schema) &&
229
- (type === 'f16' || type === 'vec2h' || type === 'vec3h' || type === 'vec4h'));
222
+ return ((type === 'f16' || type === 'vec2h' || type === 'vec3h' || type === 'vec4h') &&
223
+ isMarkedInternal(schema));
230
224
  }
231
225
  const ephemeralTypes = ['abstractInt', 'abstractFloat', 'f32', 'f16', 'i32', 'u32', 'bool'];
232
226
  /**
package/extension.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- export interface NotAllowed<TMsg> {
2
- reason: TMsg;
3
- }
4
- export type ExtensionGuard<TFlag, TMsg, TAllowed> = boolean extends TFlag ? NotAllowed<TMsg> | TAllowed : TAllowed;
5
1
  export interface StorageFlag {
6
2
  usableAsStorage: true;
7
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typegpu",
3
- "version": "0.12.8",
3
+ "version": "0.12.10",
4
4
  "description": "A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.",
5
5
  "keywords": [
6
6
  "compute",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "tsover-runtime": "^0.0.7",
52
- "typed-binary": "^4.3.3",
52
+ "typed-binary": "^4.3.4",
53
53
  "tinyest": "~0.3.4"
54
54
  },
55
55
  "engines": {
@@ -107,7 +107,7 @@ export declare class ResolutionCtxImpl implements ResolutionCtx {
107
107
  popBlockScope(): void;
108
108
  setBlockExternals(externals: Record<string, Snippet>): void;
109
109
  clearBlockExternals(): void;
110
- generateLog(op: SupportedLogOp, args: Snippet[]): Snippet;
110
+ generateLog(op: SupportedLogOp, args: readonly Snippet[]): Snippet;
111
111
  get logResources(): LogResources | undefined;
112
112
  resolveFunction(options: ResolveFunctionOptions): {
113
113
  code: string;
package/resolutionCtx.js CHANGED
@@ -24,7 +24,7 @@ import { isShelllessImpl } from "./core/function/shelllessImpl.js";
24
24
  import { isTgpuFn } from "./core/function/tgpuFn.js";
25
25
  import { AutoStruct } from "./data/autoStruct.js";
26
26
  import { EntryInputRouter } from "./core/function/entryInputRouter.js";
27
- import { validateIdentifier, sanitizePrimer, bannedTokens } from "./nameUtils.js";
27
+ import { validateIdentifier, sanitizePrimer, bannedTokens, builtins, templateEnumerants, } from "./nameUtils.js";
28
28
  import { minify } from "./minify.js";
29
29
  /**
30
30
  * Inserted into bind group entry definitions that belong
@@ -88,6 +88,7 @@ class ItemStateStackImpl {
88
88
  argAccess,
89
89
  returnType,
90
90
  externalMap,
91
+ externalSnippets: new Map(),
91
92
  reportedReturnTypes: new Set(),
92
93
  placeholderForVariable: new Map(),
93
94
  modifiedVariables: new Set(),
@@ -144,12 +145,18 @@ class ItemStateStackImpl {
144
145
  if (access) {
145
146
  return access();
146
147
  }
148
+ const cached = layer.externalSnippets.get(id);
149
+ if (cached) {
150
+ return cached;
151
+ }
147
152
  if (Object.hasOwn(layer.externalMap, id)) {
148
153
  const external = layer.externalMap[id];
149
154
  if (isNamable(external) && getName(external) === undefined) {
150
155
  setName(external, id.replaceAll('.', '_'));
151
156
  }
152
- return coerceToSnippet(external);
157
+ const snippet = coerceToSnippet(external);
158
+ layer.externalSnippets.set(id, snippet);
159
+ return snippet;
153
160
  }
154
161
  return undefined;
155
162
  }
@@ -359,7 +366,10 @@ export class ResolutionCtxImpl {
359
366
  return bannedTokens.has(name);
360
367
  }
361
368
  isIdentifierTaken(name, scope) {
362
- return (this.#namespaceInternal.takenGlobalIdentifiers.has(name) ||
369
+ return (bannedTokens.has(name) ||
370
+ builtins.has(name) ||
371
+ templateEnumerants.has(name) ||
372
+ this.#namespaceInternal.takenGlobalIdentifiers.has(name) ||
363
373
  (scope === 'block'
364
374
  ? this._itemStateStack.isIdentifierTakenLocally(name)
365
375
  : this._itemStateStack.isIdentifierTakenInCallStack(name)));
@@ -700,14 +710,24 @@ export class ResolutionCtxImpl {
700
710
  }
701
711
  return maybeEventual;
702
712
  }
713
+ /**
714
+ * Whether every slot in the map currently has a value equal to the one recorded in it.
715
+ */
716
+ #slotsHaveValues(slotToValueMap) {
717
+ for (const [slot, expectedValue] of slotToValueMap) {
718
+ if (!slot.areEqual(this._itemStateStack.readSlot(slot), expectedValue)) {
719
+ return false;
720
+ }
721
+ }
722
+ return true;
723
+ }
703
724
  _getOrCompute(lazy) {
704
725
  // All memoized versions of `lazy`
705
726
  const instances = this.#namespaceInternal.memoizedLazy.get(lazy) ?? [];
706
727
  this._itemStateStack.pushItem();
707
728
  try {
708
729
  for (const instance of instances) {
709
- const slotValuePairs = [...instance.slotToValueMap.entries()];
710
- if (slotValuePairs.every(([slot, expectedValue]) => slot.areEqual(this._itemStateStack.readSlot(slot), expectedValue))) {
730
+ if (this.#slotsHaveValues(instance.slotToValueMap)) {
711
731
  return instance.result;
712
732
  }
713
733
  }
@@ -749,8 +769,7 @@ export class ResolutionCtxImpl {
749
769
  this._itemStateStack.pushItem();
750
770
  try {
751
771
  for (const instance of instances) {
752
- const slotValuePairs = [...instance.slotToValueMap.entries()];
753
- if (slotValuePairs.every(([slot, expectedValue]) => slot.areEqual(this._itemStateStack.readSlot(slot), expectedValue))) {
772
+ if (this.#slotsHaveValues(instance.slotToValueMap)) {
754
773
  return instance.result;
755
774
  }
756
775
  }
@@ -9,7 +9,7 @@ import type { TgpuQuerySetSoul } from '../core/querySet/querySet.ts';
9
9
  import type { TgpuGuardedComputePipelineSoul, TgpuRootSoul } from '../core/root/rootTypes.ts';
10
10
  import type { TgpuSamplerSoul } from '../core/sampler/sampler.ts';
11
11
  import type { TgpuAccessorSoul, TgpuMutableAccessor, TgpuSlotSoul } from '../core/slot/slotTypes.ts';
12
- import { type TgpuTextureSoul } from '../core/texture/texture.ts';
12
+ import { INTERNAL_restoreTextureView, type TgpuTextureSoul, type TgpuTextureViewSoul } from '../core/texture/texture.ts';
13
13
  import { type TgpuVertexLayoutSoul } from '../core/vertexLayout/vertexLayout.ts';
14
14
  import type { AnyData } from '../data/dataTypes.ts';
15
15
  import { type AnyWgslData } from '../data/wgslTypes.ts';
@@ -18,9 +18,9 @@ import { type TgpuBindGroupLayoutSoul, type TgpuBindGroupSoul } from '../tgpuBin
18
18
  import type { TgpuSoul } from '../shared/soul.ts';
19
19
  import type { RestoreContext } from './types.ts';
20
20
  /** Every soul that can cross a device boundary, discriminated by `type` */
21
- export type TgpuResourceSoul = TgpuBufferSoul | TgpuBufferBindingSoul | TgpuTextureSoul | TgpuSamplerSoul | TgpuQuerySetSoul | TgpuBindGroupLayoutSoul | TgpuBindGroupSoul | TgpuVertexLayoutSoul | TgpuConstSoul | TgpuImmediateVarSoul | TgpuSlotSoul | TgpuAccessorSoul | TgpuComputePipelineSoul | TgpuRenderPipelineSoul | TgpuGuardedComputePipelineSoul | TgpuRootSoul;
21
+ export type TgpuResourceSoul = TgpuBufferSoul | TgpuBufferBindingSoul | TgpuTextureSoul | TgpuTextureViewSoul | TgpuSamplerSoul | TgpuQuerySetSoul | TgpuBindGroupLayoutSoul | TgpuBindGroupSoul | TgpuVertexLayoutSoul | TgpuConstSoul | TgpuImmediateVarSoul | TgpuSlotSoul | TgpuAccessorSoul | TgpuComputePipelineSoul | TgpuRenderPipelineSoul | TgpuGuardedComputePipelineSoul | TgpuRootSoul;
22
22
  type Restorer<TSoul extends TgpuSoul> = (soul: TSoul, ctx: RestoreContext) => unknown;
23
- declare function restoreBufferBinding(soul: TgpuBufferBindingSoul): TgpuBufferBindingImpl<"uniform" | "mutable" | "readonly", BaseData>;
23
+ declare function restoreBufferBinding(soul: TgpuBufferBindingSoul): TgpuBufferBindingImpl<"uniform" | "readonly" | "mutable", BaseData>;
24
24
  /**
25
25
  * The one place a soul turns back into a resource. Importing this module opts
26
26
  * into every restorer, so it is kept out of the resources themselves
@@ -31,6 +31,7 @@ export declare const soulRestorers: {
31
31
  mutable: typeof restoreBufferBinding;
32
32
  readonly: typeof restoreBufferBinding;
33
33
  texture: (soul: TgpuTextureSoul, ctx: RestoreContext) => import("../indexNamedExports.ts").TgpuTexture<TextureProps>;
34
+ 'texture-view': typeof INTERNAL_restoreTextureView;
34
35
  sampler: (soul: TgpuSamplerSoul, ctx: RestoreContext) => import("../indexNamedExports.ts").TgpuFixedSampler;
35
36
  'sampler-comparison': (soul: TgpuSamplerSoul, ctx: RestoreContext) => import("../indexNamedExports.ts").TgpuFixedComparisonSampler;
36
37
  'query-set': (soul: TgpuQuerySetSoul, ctx: RestoreContext) => import("../indexNamedExports.ts").TgpuQuerySet<GPUQueryType>;
package/serial/restore.js CHANGED
@@ -7,7 +7,7 @@ import { INTERNAL_restoreRenderPipeline, } from "../core/pipeline/renderPipeline
7
7
  import { INTERNAL_restoreGuardedComputePipeline, INTERNAL_restoreRoot } from "../core/root/init.js";
8
8
  import { accessor, mutableAccessor } from "../core/slot/accessor.js";
9
9
  import { slot } from "../core/slot/slot.js";
10
- import { INTERNAL_createTexture } from "../core/texture/texture.js";
10
+ import { INTERNAL_createTexture, INTERNAL_restoreTextureView, } from "../core/texture/texture.js";
11
11
  import { vertexLayout } from "../core/vertexLayout/vertexLayout.js";
12
12
  import { arrayOf } from "../data/array.js";
13
13
  import { disarrayOf } from "../data/disarray.js";
@@ -40,6 +40,7 @@ export const soulRestorers = {
40
40
  }
41
41
  return texture;
42
42
  },
43
+ 'texture-view': INTERNAL_restoreTextureView,
43
44
  sampler: (soul, ctx) => ctx.getRoot(soul.device).createSampler(soul.props),
44
45
  'sampler-comparison': (soul, ctx) => ctx.getRoot(soul.device).createComparisonSampler(soul.props),
45
46
  'query-set': (soul, ctx) => ctx.getRoot(soul.device).createQuerySet(soul.queryType, soul.count, soul.raw),
package/shared/meta.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = "0.12.8";
1
+ const version = "0.12.10";
2
2
  import { DEV, TEST } from "./env.js";
3
3
  import { $getNameForward, $soul, isMarkedInternal } from "./symbols.js";
4
4
  import { normalizeMetadata } from "./normalizeMetadata.js";
@@ -33,6 +33,11 @@ export declare const $cast: unique symbol;
33
33
  * Can be called on the GPU
34
34
  */
35
35
  export declare const $gpuCallable: unique symbol;
36
+ /**
37
+ * Optional strict signature metadata for GPU-callable values, used for argument
38
+ * type hints and validation.
39
+ */
40
+ export declare const $gpuCallableStrictSignature: unique symbol;
36
41
  /**
37
42
  * Type token for the inferred (CPU & GPU) representation of a resource
38
43
  */
package/shared/symbols.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = "0.12.8";
1
+ const version = "0.12.10";
2
2
  export const $internal = Symbol(`typegpu:${version}:$internal`);
3
3
  /** A plain record of all definitional state of a resource, surviving transfer between runtimes */
4
4
  export const $soul = Symbol(`typegpu:${version}:$soul`);
@@ -34,6 +34,11 @@ export const $cast = Symbol(`typegpu:${version}:$cast`);
34
34
  * Can be called on the GPU
35
35
  */
36
36
  export const $gpuCallable = Symbol(`typegpu:${version}:$gpuCallable`);
37
+ /**
38
+ * Optional strict signature metadata for GPU-callable values, used for argument
39
+ * type hints and validation.
40
+ */
41
+ export const $gpuCallableStrictSignature = Symbol(`typegpu:${version}:$gpuCallableStrictSignature`);
37
42
  //
38
43
  // Type tokens
39
44
  //
@@ -15,12 +15,6 @@ export type WithDefaults<TPartial, TDefaults> = Omit<TDefaults, keyof TPartial>
15
15
  export type OmitProps<T extends Record<string, unknown>, Prop> = Pick<T, {
16
16
  [Key in keyof T]: T[Key] extends Prop ? never : Key;
17
17
  }[keyof T]>;
18
- /**
19
- * Removes properties from record type that equal `Prop`
20
- */
21
- export type OmitPropsExact<T extends Record<string, unknown>, Prop> = Pick<T, {
22
- [Key in keyof T]: [T[Key], Prop] extends [Prop, T[Key]] ? never : Key;
23
- }[keyof T]>;
24
18
  export type NullableToOptional<T> = {
25
19
  [K in keyof T as T[K] extends null ? K : never]?: T[K];
26
20
  } & {
package/std/bitcast.d.ts CHANGED
@@ -188,6 +188,6 @@ declare function getBitcast<FromType extends keyof typeof casts, ToType extends
188
188
  readonly vec4i: (value: v4u) => v4i;
189
189
  readonly vec4u: (value: v4u) => v4u;
190
190
  };
191
- }[FromType][(ToType & "bool") | (ToType & "f32") | (ToType & "f16") | (ToType & "i32") | (ToType & "u32") | (ToType & "u16") | (ToType & "vec2f") | (ToType & "vec2h") | (ToType & "vec2i") | (ToType & "vec2u") | (ToType & "vec2<bool>") | (ToType & "vec3f") | (ToType & "vec3h") | (ToType & "vec3i") | (ToType & "vec3u") | (ToType & "vec3<bool>") | (ToType & "vec4f") | (ToType & "vec4h") | (ToType & "vec4i") | (ToType & "vec4u") | (ToType & "vec4<bool>") | (ToType & "mat2x2f") | (ToType & "mat3x3f") | (ToType & "mat4x4f") | (ToType & "struct") | (ToType & "array") | (ToType & "ptr") | (ToType & "atomic") | (ToType & "decorated") | (ToType & "abstractInt") | (ToType & "abstractFloat") | (ToType & "void") | (ToType & ("texture_1d" | "texture_2d" | "texture_multisampled_2d" | "texture_depth_2d" | "texture_depth_multisampled_2d" | "texture_2d_array" | "texture_depth_2d_array" | "texture_cube" | "texture_depth_cube" | "texture_cube_array" | "texture_depth_cube_array" | "texture_3d")) | (ToType & ("texture_storage_1d" | "texture_storage_2d" | "texture_storage_2d_array" | "texture_storage_3d")) | (ToType & "texture_external") | (ToType & "sampler") | (ToType & "sampler_comparison")];
191
+ }[FromType][(ToType & "abstractFloat") | (ToType & "abstractInt") | (ToType & "f32") | (ToType & "i32") | (ToType & "bool") | (ToType & "f16") | (ToType & "u32") | (ToType & "u16") | (ToType & "vec2f") | (ToType & "vec2h") | (ToType & "vec2i") | (ToType & "vec2u") | (ToType & "vec2<bool>") | (ToType & "vec3f") | (ToType & "vec3h") | (ToType & "vec3i") | (ToType & "vec3u") | (ToType & "vec3<bool>") | (ToType & "vec4f") | (ToType & "vec4h") | (ToType & "vec4i") | (ToType & "vec4u") | (ToType & "vec4<bool>") | (ToType & "mat2x2f") | (ToType & "mat3x3f") | (ToType & "mat4x4f") | (ToType & "struct") | (ToType & "array") | (ToType & "ptr") | (ToType & "atomic") | (ToType & "decorated") | (ToType & "void") | (ToType & ("texture_1d" | "texture_2d" | "texture_2d_array" | "texture_3d" | "texture_cube" | "texture_cube_array" | "texture_multisampled_2d" | "texture_depth_multisampled_2d" | "texture_depth_2d" | "texture_depth_2d_array" | "texture_depth_cube" | "texture_depth_cube_array")) | (ToType & ("texture_storage_1d" | "texture_storage_2d" | "texture_storage_2d_array" | "texture_storage_3d")) | (ToType & "texture_external") | (ToType & "sampler") | (ToType & "sampler_comparison")];
192
192
  export declare const bitcast: import("../indexNamedExports.ts").TgpuComptime<typeof getBitcast>;
193
193
  export {};
@@ -0,0 +1,67 @@
1
+ import { type DualFn } from '../types.ts';
2
+ /**
3
+ * Returns `true` if the value passed into it is statically known at comptime (during shader
4
+ * generation), and `false` if the value is determined by shader execution.
5
+ * During normal JavaScript execution every value is available right away, so it always
6
+ * returns `true`.
7
+ *
8
+ * Note that shader constants are NOT considered statically known at comptime, therefore
9
+ * `isKnownAtComptime()` returns `false` for them.
10
+ *
11
+ * A good example of where this is useful is opting into optimizations that are
12
+ * only valid when a value is statically known, like unrolling a loop whose iteration count
13
+ * depends on the size of an array:
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const layout = tgpu.bindGroupLayout({
18
+ * // Swapping this for `d.arrayOf(d.vec2f)` (a runtime-sized array)
19
+ * // makes the loop below stay a loop.
20
+ * boids: { storage: d.arrayOf(d.vec2f, 3) },
21
+ * });
22
+ *
23
+ * function centroid() {
24
+ * 'use gpu';
25
+ * let sum = d.vec2f();
26
+ *
27
+ * for (
28
+ * const boid of std.isKnownAtComptime(layout.$.boids.length)
29
+ * ? tgpu.unroll(layout.$.boids)
30
+ * : layout.$.boids
31
+ * ) {
32
+ * sum += boid;
33
+ * }
34
+ *
35
+ * return sum / d.f32(layout.$.boids.length);
36
+ * }
37
+ * ```
38
+ *
39
+ * Generates:
40
+ *
41
+ * ```wgsl
42
+ * @group(0) @binding(0) var<storage, read> boids: array<vec2f, 3>;
43
+ *
44
+ * fn centroid() -> vec2f {
45
+ * var sum = vec2f();
46
+ * // unrolled iteration #0
47
+ * sum += boids[0u];
48
+ * // unrolled iteration #1
49
+ * sum += boids[1u];
50
+ * // unrolled iteration #2
51
+ * sum += boids[2u];
52
+ * // ---
53
+ * return (sum / 3f);
54
+ * }
55
+ * ```
56
+ *
57
+ * @note
58
+ * Only the *value* of the argument is inspected, the expression itself is never emitted into
59
+ * the generated shader. Passing an expression with possible side effects (e.g. a call to a
60
+ * `tgpu.fn`) throws during shader generation, because those side effects would run in JS but
61
+ * silently not happen on the GPU.
62
+ *
63
+ * Such an expression is determined by shader execution, so it is never known at comptime and
64
+ * the check would always yield `false`. Remove the check, and if the side effect itself is
65
+ * needed, run it as a separate statement.
66
+ */
67
+ export declare const isKnownAtComptime: DualFn<(value: unknown) => boolean>;
@@ -0,0 +1,88 @@
1
+ import { bool } from "../data/numeric.js";
2
+ import { snip } from "../data/snippet.js";
3
+ import { WgslTypeError } from "../errors.js";
4
+ import { setName } from "../shared/meta.js";
5
+ import { $gpuCallable } from "../shared/symbols.js";
6
+ import { asComptime } from "../types.js";
7
+ /**
8
+ * Returns `true` if the value passed into it is statically known at comptime (during shader
9
+ * generation), and `false` if the value is determined by shader execution.
10
+ * During normal JavaScript execution every value is available right away, so it always
11
+ * returns `true`.
12
+ *
13
+ * Note that shader constants are NOT considered statically known at comptime, therefore
14
+ * `isKnownAtComptime()` returns `false` for them.
15
+ *
16
+ * A good example of where this is useful is opting into optimizations that are
17
+ * only valid when a value is statically known, like unrolling a loop whose iteration count
18
+ * depends on the size of an array:
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const layout = tgpu.bindGroupLayout({
23
+ * // Swapping this for `d.arrayOf(d.vec2f)` (a runtime-sized array)
24
+ * // makes the loop below stay a loop.
25
+ * boids: { storage: d.arrayOf(d.vec2f, 3) },
26
+ * });
27
+ *
28
+ * function centroid() {
29
+ * 'use gpu';
30
+ * let sum = d.vec2f();
31
+ *
32
+ * for (
33
+ * const boid of std.isKnownAtComptime(layout.$.boids.length)
34
+ * ? tgpu.unroll(layout.$.boids)
35
+ * : layout.$.boids
36
+ * ) {
37
+ * sum += boid;
38
+ * }
39
+ *
40
+ * return sum / d.f32(layout.$.boids.length);
41
+ * }
42
+ * ```
43
+ *
44
+ * Generates:
45
+ *
46
+ * ```wgsl
47
+ * @group(0) @binding(0) var<storage, read> boids: array<vec2f, 3>;
48
+ *
49
+ * fn centroid() -> vec2f {
50
+ * var sum = vec2f();
51
+ * // unrolled iteration #0
52
+ * sum += boids[0u];
53
+ * // unrolled iteration #1
54
+ * sum += boids[1u];
55
+ * // unrolled iteration #2
56
+ * sum += boids[2u];
57
+ * // ---
58
+ * return (sum / 3f);
59
+ * }
60
+ * ```
61
+ *
62
+ * @note
63
+ * Only the *value* of the argument is inspected, the expression itself is never emitted into
64
+ * the generated shader. Passing an expression with possible side effects (e.g. a call to a
65
+ * `tgpu.fn`) throws during shader generation, because those side effects would run in JS but
66
+ * silently not happen on the GPU.
67
+ *
68
+ * Such an expression is determined by shader execution, so it is never known at comptime and
69
+ * the check would always yield `false`. Remove the check, and if the side effect itself is
70
+ * needed, run it as a separate statement.
71
+ */
72
+ export const isKnownAtComptime = /* @__PURE__ */ (() => {
73
+ const impl = ((_value) => true);
74
+ impl.toString = () => 'isKnownAtComptime';
75
+ setName(impl, 'isKnownAtComptime');
76
+ impl[$gpuCallable] = (_ctx, [value]) => {
77
+ if (!value) {
78
+ throw new WgslTypeError('`std.isKnownAtComptime` was called without any arguments');
79
+ }
80
+ if (value.possibleSideEffects) {
81
+ throw new WgslTypeError('`std.isKnownAtComptime` received an argument with possible side effects. The expression is never emitted into the shader, so its side effects would silently not happen, and a side-effectful expression is never known at comptime anyway, so the result would always be `false`. Remove the check, and run the side effect as a separate statement if it is needed.');
82
+ }
83
+ return snip(asComptime(value) !== undefined, bool,
84
+ /* origin */ 'constant',
85
+ /* possibleSideEffects */ false);
86
+ };
87
+ return impl;
88
+ })();
@@ -5,10 +5,8 @@ import { $gpuCallable } from "../shared/symbols.js";
5
5
  import { coerceToSnippet } from "../tgsl/generationHelpers.js";
6
6
  const impl = (() => false);
7
7
  impl.toString = () => 'isBeingTranspiled';
8
- impl[$gpuCallable] = {
9
- call(_ctx, _args) {
10
- return coerceToSnippet(true);
11
- },
8
+ impl[$gpuCallable] = (_ctx, _args) => {
9
+ return coerceToSnippet(true);
12
10
  };
13
11
  /**
14
12
  * Returns `true` when the direct callee is being transpiled for GPU, otherwise `false`.
package/std/index.d.ts CHANGED
@@ -18,3 +18,5 @@ export { extensionEnabled } from './extensions.ts';
18
18
  export { bitcastU32toF32, bitcastU32toI32, bitcastF32toU32, bitcast } from './bitcast.ts';
19
19
  export { range } from './range.ts';
20
20
  export { isBeingTranspiled, getTargetShaderLanguage, getShaderStage } from './environment.ts';
21
+ export { typeOf } from './typeOf.ts';
22
+ export { isKnownAtComptime } from './comptime.ts';
package/std/index.js CHANGED
@@ -30,3 +30,5 @@ export { extensionEnabled } from "./extensions.js";
30
30
  export { bitcastU32toF32, bitcastU32toI32, bitcastF32toU32, bitcast } from "./bitcast.js";
31
31
  export { range } from "./range.js";
32
32
  export { isBeingTranspiled, getTargetShaderLanguage, getShaderStage } from "./environment.js";
33
+ export { typeOf } from "./typeOf.js";
34
+ export { isKnownAtComptime } from "./comptime.js";
package/std/matrix.js CHANGED
@@ -5,11 +5,11 @@ import { mul } from "./operators.js";
5
5
  import { $gpuCallable } from "../shared/symbols.js";
6
6
  import { vec3f } from "../data/vector.js";
7
7
  import { f32 } from "../data/numeric.js";
8
- const gpuTranslation4 = translation4[$gpuCallable].call.bind(translation4);
9
- const gpuScaling4 = scaling4[$gpuCallable].call.bind(scaling4);
10
- const gpuRotationX4 = rotationX4[$gpuCallable].call.bind(rotationX4);
11
- const gpuRotationY4 = rotationY4[$gpuCallable].call.bind(rotationY4);
12
- const gpuRotationZ4 = rotationZ4[$gpuCallable].call.bind(rotationZ4);
8
+ const gpuTranslation4 = translation4[$gpuCallable].bind(translation4);
9
+ const gpuScaling4 = scaling4[$gpuCallable].bind(scaling4);
10
+ const gpuRotationX4 = rotationX4[$gpuCallable].bind(rotationX4);
11
+ const gpuRotationY4 = rotationY4[$gpuCallable].bind(rotationY4);
12
+ const gpuRotationZ4 = rotationZ4[$gpuCallable].bind(rotationZ4);
13
13
  /**
14
14
  * Translates the given 4-by-4 matrix by the given vector.
15
15
  * @param {m4x4f} matrix - The matrix to be modified.
package/std/numeric.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type AnyFloat32VecInstance, type AnyFloatVecInstance, type AnyIntegerVecInstance, type AnyMatInstance, type AnyNumericVecInstance, type AnySignedVecInstance, type BaseData, type v2f, type v2h, type v2i, type v3f, type v3h, type v3i, type v4f, type v4h, type v4i, type Vec2f } from '../data/wgslTypes.ts';
2
2
  import type { Infer } from '../shared/repr.ts';
3
3
  type NumVec = AnyNumericVecInstance;
4
- export declare const unifyRestrictedSignature: (restrict: BaseData[]) => (...args: BaseData[]) => {
4
+ export declare function unifyRestrictedSignature(restrict: BaseData[]): (...args: BaseData[]) => {
5
5
  argTypes: BaseData[];
6
6
  returnType: BaseData;
7
7
  };
@@ -206,6 +206,7 @@ export declare const normalize: import("../types.ts").DualFn<(<T extends AnyFloa
206
206
  declare function powCpu(base: number, exponent: number): number;
207
207
  declare function powCpu<T extends AnyFloatVecInstance>(base: T, exponent: T): T;
208
208
  export declare const pow: import("../types.ts").DualFn<typeof powCpu>;
209
+ export declare const powOperator: import("../types.ts").DualFn<typeof powCpu>;
209
210
  declare function cpuQuantizeToF16(value: number): number;
210
211
  declare function cpuQuantizeToF16<T extends AnyFloat32VecInstance>(value: T): T;
211
212
  export declare const quantizeToF16: import("../types.ts").DualFn<typeof cpuQuantizeToF16>;