typegpu 0.12.4 → 0.12.6

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 (78) hide show
  1. package/bin.mjs +39 -67
  2. package/common/index.d.ts +1 -0
  3. package/common/index.js +1 -0
  4. package/common/writeChannels.d.ts +31 -0
  5. package/common/writeChannels.js +32 -0
  6. package/core/commandEncoder/computePass.d.ts +13 -0
  7. package/core/commandEncoder/computePass.js +5 -2
  8. package/core/commandEncoder/renderPass.d.ts +18 -4
  9. package/core/commandEncoder/renderPass.js +6 -2
  10. package/core/declare/tgpuDeclare.d.ts +11 -0
  11. package/core/declare/tgpuDeclare.js +1 -1
  12. package/core/immediate/immediateVar.d.ts +52 -0
  13. package/core/immediate/immediateVar.js +149 -0
  14. package/core/pipeline/computePipeline.d.ts +23 -0
  15. package/core/pipeline/computePipeline.js +26 -9
  16. package/core/pipeline/drawState.d.ts +8 -4
  17. package/core/pipeline/drawState.js +41 -51
  18. package/core/pipeline/priors.js +1 -0
  19. package/core/pipeline/renderPipeline.d.ts +24 -1
  20. package/core/pipeline/renderPipeline.js +18 -1
  21. package/core/root/init.js +3 -0
  22. package/core/root/rootTypes.d.ts +11 -0
  23. package/core/slot/slotTypes.d.ts +2 -1
  24. package/core/texture/texture.d.ts +20 -14
  25. package/core/texture/texture.js +70 -65
  26. package/core/texture/textureUtils.d.ts +3 -6
  27. package/core/texture/textureUtils.js +142 -165
  28. package/core/texture/textureWrite.d.ts +61 -0
  29. package/core/texture/textureWrite.js +59 -0
  30. package/data/dataIO.d.ts +2 -2
  31. package/data/generalizeFn.d.ts +17 -1
  32. package/data/generalizeFn.js +39 -2
  33. package/data/snippet.d.ts +5 -1
  34. package/data/snippet.js +1 -0
  35. package/data/wgslTypes.d.ts +1 -1
  36. package/errors.d.ts +7 -0
  37. package/errors.js +15 -0
  38. package/indexNamedExports.d.ts +5 -2
  39. package/indexNamedExports.js +2 -1
  40. package/internal.d.ts +1 -1
  41. package/internal.js +1 -1
  42. package/package.json +2 -2
  43. package/resolutionCtx.d.ts +5 -0
  44. package/resolutionCtx.js +11 -0
  45. package/serial/restore.d.ts +3 -1
  46. package/serial/restore.js +2 -0
  47. package/shared/meta.js +1 -1
  48. package/shared/symbols.js +1 -1
  49. package/shared/tseynit.d.ts +1 -0
  50. package/shared/tseynit.js +39 -7
  51. package/shared/utilityTypes.d.ts +1 -1
  52. package/std/atomic.d.ts +13 -0
  53. package/std/atomic.js +63 -29
  54. package/std/bitcast.js +4 -0
  55. package/std/boolean.d.ts +1 -1
  56. package/std/boolean.js +35 -21
  57. package/std/derivative.js +17 -12
  58. package/std/index.d.ts +4 -4
  59. package/std/index.js +5 -5
  60. package/std/numeric.d.ts +5 -1
  61. package/std/numeric.js +75 -8
  62. package/std/operators.d.ts +2 -2
  63. package/std/operators.js +29 -17
  64. package/std/packing.d.ts +61 -1
  65. package/std/packing.js +214 -25
  66. package/std/subgroup.d.ts +4 -0
  67. package/std/subgroup.js +34 -0
  68. package/std/texture.d.ts +13 -0
  69. package/std/texture.js +48 -0
  70. package/tgpuUnstable.d.ts +1 -0
  71. package/tgpuUnstable.js +1 -0
  72. package/tgsl/conversion.d.ts +2 -0
  73. package/tgsl/conversion.js +3 -0
  74. package/tgsl/shaderGenerator.d.ts +1 -1
  75. package/tgsl/wgslGenerator.d.ts +5 -0
  76. package/tgsl/wgslGenerator.js +218 -50
  77. package/types.d.ts +9 -1
  78. package/types.js +5 -0
package/std/packing.js CHANGED
@@ -2,8 +2,25 @@ import * as TB from 'typed-binary';
2
2
  import { dualImpl } from "../core/function/dualImpl.js";
3
3
  import { stitch } from "../core/resolve/stitch.js";
4
4
  import { u32 } from "../data/numeric.js";
5
- import { vec2f, vec4f } from "../data/vector.js";
5
+ import { clampScalar } from "../data/numberOps.js";
6
+ import { vec2f, vec4f, vec4i, vec4u } from "../data/vector.js";
6
7
  import { readFloat16, writeFloat16 } from "../data/float16Conversion.js";
8
+ const littleEndian = { endianness: 'little' };
9
+ const packedBuffer = new ArrayBuffer(4);
10
+ const packedWriter = new TB.BufferWriter(packedBuffer, littleEndian);
11
+ const packedReader = new TB.BufferReader(packedBuffer, littleEndian);
12
+ function readPacked(value) {
13
+ packedWriter.seekTo(0);
14
+ packedWriter.writeUint32(value);
15
+ packedReader.seekTo(0);
16
+ return packedReader;
17
+ }
18
+ function writePacked(write) {
19
+ packedWriter.seekTo(0);
20
+ write(packedWriter);
21
+ packedReader.seekTo(0);
22
+ return u32(packedReader.readUint32());
23
+ }
7
24
  /**
8
25
  * @privateRemarks
9
26
  * https://gpuweb.github.io/gpuweb/wgsl/#unpack2x16float-builtin
@@ -11,10 +28,7 @@ import { readFloat16, writeFloat16 } from "../data/float16Conversion.js";
11
28
  export const unpack2x16float = dualImpl({
12
29
  name: 'unpack2x16float',
13
30
  normalImpl: (e) => {
14
- const buffer = new ArrayBuffer(4);
15
- const writer = new TB.BufferWriter(buffer);
16
- writer.writeUint32(e);
17
- const reader = new TB.BufferReader(buffer);
31
+ const reader = readPacked(e);
18
32
  return vec2f(readFloat16(reader), readFloat16(reader));
19
33
  },
20
34
  signature: { argTypes: [u32], returnType: vec2f },
@@ -27,18 +41,50 @@ export const unpack2x16float = dualImpl({
27
41
  */
28
42
  export const pack2x16float = dualImpl({
29
43
  name: 'pack2x16float',
30
- normalImpl: (e) => {
31
- const buffer = new ArrayBuffer(4);
32
- const writer = new TB.BufferWriter(buffer);
44
+ normalImpl: (e) => writePacked((writer) => {
33
45
  writeFloat16(writer, e.x);
34
46
  writeFloat16(writer, e.y);
35
- const reader = new TB.BufferReader(buffer);
36
- return u32(reader.readUint32());
37
- },
47
+ }),
38
48
  signature: { argTypes: [vec2f], returnType: u32 },
39
49
  codegenImpl: (_ctx, [e]) => stitch `pack2x16float(${e})`,
40
50
  sideEffects: false,
41
51
  });
52
+ /**
53
+ * @privateRemarks
54
+ * https://www.w3.org/TR/WGSL/#pack2x16snorm-builtin
55
+ */
56
+ export const pack2x16snorm = dualImpl({
57
+ name: 'pack2x16snorm',
58
+ normalImpl: (e) => {
59
+ const x = Math.floor(0.5 + 32767 * clampScalar(e.x, -1, 1));
60
+ const y = Math.floor(0.5 + 32767 * clampScalar(e.y, -1, 1));
61
+ return writePacked((writer) => {
62
+ writer.writeInt16(x);
63
+ writer.writeInt16(y);
64
+ });
65
+ },
66
+ signature: { argTypes: [vec2f], returnType: u32 },
67
+ codegenImpl: (_ctx, [e]) => stitch `pack2x16snorm(${e})`,
68
+ sideEffects: false,
69
+ });
70
+ /**
71
+ * @privateRemarks
72
+ * https://www.w3.org/TR/WGSL/#pack2x16unorm-builtin
73
+ */
74
+ export const pack2x16unorm = dualImpl({
75
+ name: 'pack2x16unorm',
76
+ normalImpl: (e) => {
77
+ const x = Math.floor(0.5 + 65535 * clampScalar(e.x, 0, 1));
78
+ const y = Math.floor(0.5 + 65535 * clampScalar(e.y, 0, 1));
79
+ return writePacked((writer) => {
80
+ writer.writeUint16(x);
81
+ writer.writeUint16(y);
82
+ });
83
+ },
84
+ signature: { argTypes: [vec2f], returnType: u32 },
85
+ codegenImpl: (_ctx, [e]) => stitch `pack2x16unorm(${e})`,
86
+ sideEffects: false,
87
+ });
42
88
  /**
43
89
  * @privateRemarks
44
90
  * https://gpuweb.github.io/gpuweb/wgsl/#unpack4x8unorm-builtin
@@ -46,33 +92,176 @@ export const pack2x16float = dualImpl({
46
92
  export const unpack4x8unorm = dualImpl({
47
93
  name: 'unpack4x8unorm',
48
94
  normalImpl: (e) => {
49
- const buffer = new ArrayBuffer(4);
50
- const writer = new TB.BufferWriter(buffer);
51
- writer.writeUint32(e);
52
- const reader = new TB.BufferReader(buffer);
95
+ const reader = readPacked(e);
53
96
  return vec4f(reader.readUint8() / 255, reader.readUint8() / 255, reader.readUint8() / 255, reader.readUint8() / 255);
54
97
  },
55
98
  signature: { argTypes: [u32], returnType: vec4f },
56
99
  codegenImpl: (_ctx, [e]) => stitch `unpack4x8unorm(${e})`,
57
100
  sideEffects: false,
58
101
  });
102
+ /**
103
+ * @privateRemarks
104
+ * https://www.w3.org/TR/WGSL/#unpack4x8snorm-builtin
105
+ */
106
+ export const unpack4x8snorm = dualImpl({
107
+ name: 'unpack4x8snorm',
108
+ normalImpl: (e) => {
109
+ const reader = readPacked(e);
110
+ return vec4f(Math.max(reader.readInt8() / 127, -1), Math.max(reader.readInt8() / 127, -1), Math.max(reader.readInt8() / 127, -1), Math.max(reader.readInt8() / 127, -1));
111
+ },
112
+ signature: { argTypes: [u32], returnType: vec4f },
113
+ codegenImpl: (_ctx, [e]) => stitch `unpack4x8snorm(${e})`,
114
+ sideEffects: false,
115
+ });
116
+ /**
117
+ * @privateRemarks
118
+ * https://www.w3.org/TR/WGSL/#unpack4xi8-builtin
119
+ */
120
+ export const unpack4xI8 = dualImpl({
121
+ name: 'unpack4xI8',
122
+ normalImpl: (e) => {
123
+ const reader = readPacked(e);
124
+ return vec4i(reader.readInt8(), reader.readInt8(), reader.readInt8(), reader.readInt8());
125
+ },
126
+ signature: { argTypes: [u32], returnType: vec4i },
127
+ codegenImpl: (_ctx, [e]) => stitch `unpack4xI8(${e})`,
128
+ sideEffects: false,
129
+ });
130
+ /**
131
+ * @privateRemarks
132
+ * https://www.w3.org/TR/WGSL/#unpack4xu8-builtin
133
+ */
134
+ export const unpack4xU8 = dualImpl({
135
+ name: 'unpack4xU8',
136
+ normalImpl: (e) => {
137
+ const reader = readPacked(e);
138
+ return vec4u(reader.readUint8(), reader.readUint8(), reader.readUint8(), reader.readUint8());
139
+ },
140
+ signature: { argTypes: [u32], returnType: vec4u },
141
+ codegenImpl: (_ctx, [e]) => stitch `unpack4xU8(${e})`,
142
+ sideEffects: false,
143
+ });
144
+ /**
145
+ * @privateRemarks
146
+ * https://www.w3.org/TR/WGSL/#unpack2x16snorm-builtin
147
+ */
148
+ export const unpack2x16snorm = dualImpl({
149
+ name: 'unpack2x16snorm',
150
+ normalImpl: (e) => {
151
+ const reader = readPacked(e);
152
+ return vec2f(Math.max(reader.readInt16() / 32767, -1), Math.max(reader.readInt16() / 32767, -1));
153
+ },
154
+ signature: { argTypes: [u32], returnType: vec2f },
155
+ codegenImpl: (_ctx, [e]) => stitch `unpack2x16snorm(${e})`,
156
+ sideEffects: false,
157
+ });
158
+ /**
159
+ * @privateRemarks
160
+ * https://www.w3.org/TR/WGSL/#unpack2x16unorm-builtin
161
+ */
162
+ export const unpack2x16unorm = dualImpl({
163
+ name: 'unpack2x16unorm',
164
+ normalImpl: (e) => {
165
+ const reader = readPacked(e);
166
+ return vec2f(reader.readUint16() / 65535, reader.readUint16() / 65535);
167
+ },
168
+ signature: { argTypes: [u32], returnType: vec2f },
169
+ codegenImpl: (_ctx, [e]) => stitch `unpack2x16unorm(${e})`,
170
+ sideEffects: false,
171
+ });
59
172
  /**
60
173
  * @privateRemarks
61
174
  * https://gpuweb.github.io/gpuweb/wgsl/#pack4x8unorm-builtin
62
175
  */
63
176
  export const pack4x8unorm = dualImpl({
64
177
  name: 'pack4x8unorm',
65
- normalImpl: (e) => {
66
- const buffer = new ArrayBuffer(4);
67
- const writer = new TB.BufferWriter(buffer);
68
- writer.writeUint8(e.x * 255);
69
- writer.writeUint8(e.y * 255);
70
- writer.writeUint8(e.z * 255);
71
- writer.writeUint8(e.w * 255);
72
- const reader = new TB.BufferReader(buffer);
73
- return u32(reader.readUint32());
74
- },
178
+ normalImpl: (e) => writePacked((writer) => {
179
+ writer.writeUint8(Math.floor(0.5 + 255 * clampScalar(e.x, 0, 1)));
180
+ writer.writeUint8(Math.floor(0.5 + 255 * clampScalar(e.y, 0, 1)));
181
+ writer.writeUint8(Math.floor(0.5 + 255 * clampScalar(e.z, 0, 1)));
182
+ writer.writeUint8(Math.floor(0.5 + 255 * clampScalar(e.w, 0, 1)));
183
+ }),
75
184
  signature: { argTypes: [vec4f], returnType: u32 },
76
185
  codegenImpl: (_ctx, [e]) => stitch `pack4x8unorm(${e})`,
77
186
  sideEffects: false,
78
187
  });
188
+ /**
189
+ * @privateRemarks
190
+ * https://www.w3.org/TR/WGSL/#pack4x8snorm-builtin
191
+ */
192
+ export const pack4x8snorm = dualImpl({
193
+ name: 'pack4x8snorm',
194
+ normalImpl: (e) => writePacked((writer) => {
195
+ writer.writeInt8(Math.floor(0.5 + 127 * clampScalar(e.x, -1, 1)));
196
+ writer.writeInt8(Math.floor(0.5 + 127 * clampScalar(e.y, -1, 1)));
197
+ writer.writeInt8(Math.floor(0.5 + 127 * clampScalar(e.z, -1, 1)));
198
+ writer.writeInt8(Math.floor(0.5 + 127 * clampScalar(e.w, -1, 1)));
199
+ }),
200
+ signature: { argTypes: [vec4f], returnType: u32 },
201
+ codegenImpl: (_ctx, [e]) => stitch `pack4x8snorm(${e})`,
202
+ sideEffects: false,
203
+ });
204
+ /**
205
+ * @privateRemarks
206
+ * https://www.w3.org/TR/WGSL/#pack4xi8-builtin
207
+ */
208
+ export const pack4xI8 = dualImpl({
209
+ name: 'pack4xI8',
210
+ normalImpl: (e) => writePacked((writer) => {
211
+ writer.writeInt8(e.x);
212
+ writer.writeInt8(e.y);
213
+ writer.writeInt8(e.z);
214
+ writer.writeInt8(e.w);
215
+ }),
216
+ signature: { argTypes: [vec4i], returnType: u32 },
217
+ codegenImpl: (_ctx, [e]) => stitch `pack4xI8(${e})`,
218
+ sideEffects: false,
219
+ });
220
+ /**
221
+ * @privateRemarks
222
+ * https://www.w3.org/TR/WGSL/#pack4xu8-builtin
223
+ */
224
+ export const pack4xU8 = dualImpl({
225
+ name: 'pack4xU8',
226
+ normalImpl: (e) => writePacked((writer) => {
227
+ writer.writeUint8(e.x);
228
+ writer.writeUint8(e.y);
229
+ writer.writeUint8(e.z);
230
+ writer.writeUint8(e.w);
231
+ }),
232
+ signature: { argTypes: [vec4u], returnType: u32 },
233
+ codegenImpl: (_ctx, [e]) => stitch `pack4xU8(${e})`,
234
+ sideEffects: false,
235
+ });
236
+ /**
237
+ * @privateRemarks
238
+ * https://www.w3.org/TR/WGSL/#pack4xi8clamp-builtin
239
+ */
240
+ export const pack4xI8Clamp = dualImpl({
241
+ name: 'pack4xI8Clamp',
242
+ normalImpl: (e) => writePacked((writer) => {
243
+ writer.writeInt8(clampScalar(e.x, -128, 127));
244
+ writer.writeInt8(clampScalar(e.y, -128, 127));
245
+ writer.writeInt8(clampScalar(e.z, -128, 127));
246
+ writer.writeInt8(clampScalar(e.w, -128, 127));
247
+ }),
248
+ signature: { argTypes: [vec4i], returnType: u32 },
249
+ codegenImpl: (_ctx, [e]) => stitch `pack4xI8Clamp(${e})`,
250
+ sideEffects: false,
251
+ });
252
+ /**
253
+ * @privateRemarks
254
+ * https://www.w3.org/TR/WGSL/#pack4xu8clamp-builtin
255
+ */
256
+ export const pack4xU8Clamp = dualImpl({
257
+ name: 'pack4xU8Clamp',
258
+ normalImpl: (e) => writePacked((writer) => {
259
+ writer.writeUint8(clampScalar(e.x, 0, 255));
260
+ writer.writeUint8(clampScalar(e.y, 0, 255));
261
+ writer.writeUint8(clampScalar(e.z, 0, 255));
262
+ writer.writeUint8(clampScalar(e.w, 0, 255));
263
+ }),
264
+ signature: { argTypes: [vec4u], returnType: u32 },
265
+ codegenImpl: (_ctx, [e]) => stitch `pack4xU8Clamp(${e})`,
266
+ sideEffects: false,
267
+ });
package/std/subgroup.d.ts CHANGED
@@ -40,4 +40,8 @@ export declare const subgroupShuffleDown: import("../types.ts").DualFn<IdentityN
40
40
  export declare const subgroupShuffleUp: import("../types.ts").DualFn<IdentityNumOrVecWithDelta>;
41
41
  export declare const subgroupShuffleXor: import("../types.ts").DualFn<IdentityNumOrVecWithMask>;
42
42
  export declare const subgroupXor: import("../types.ts").DualFn<IdentityIntNumOrVec>;
43
+ export declare const quadBroadcast: import("../types.ts").DualFn<IdentityNumOrVecWithIdx>;
44
+ export declare const quadSwapDiagonal: import("../types.ts").DualFn<IdentityNumOrVec>;
45
+ export declare const quadSwapX: import("../types.ts").DualFn<IdentityNumOrVec>;
46
+ export declare const quadSwapY: import("../types.ts").DualFn<IdentityNumOrVec>;
43
47
  export {};
package/std/subgroup.js CHANGED
@@ -181,3 +181,37 @@ export const subgroupXor = dualImpl({
181
181
  codegenImpl: (_ctx, [e]) => stitch `subgroupXor(${e})`,
182
182
  sideEffects: false,
183
183
  });
184
+ export const quadBroadcast = dualImpl({
185
+ name: 'quadBroadcast',
186
+ signature: (...args) => {
187
+ const id = unify([args[1]], [i32, u32]);
188
+ if (!id) {
189
+ throw new Error(`quadBroadcast's second argument has to be compatible with i32 or u32. Got: ${args[1].type}`);
190
+ }
191
+ return { argTypes: [args[0], id[0]], returnType: args[0] };
192
+ },
193
+ normalImpl: errorMessage,
194
+ codegenImpl: (_ctx, [e, id]) => stitch `quadBroadcast(${e}, ${id})`,
195
+ sideEffects: false,
196
+ });
197
+ export const quadSwapDiagonal = dualImpl({
198
+ name: 'quadSwapDiagonal',
199
+ signature: (arg) => ({ argTypes: [arg], returnType: arg }),
200
+ normalImpl: errorMessage,
201
+ codegenImpl: (_ctx, [e]) => stitch `quadSwapDiagonal(${e})`,
202
+ sideEffects: false,
203
+ });
204
+ export const quadSwapX = dualImpl({
205
+ name: 'quadSwapX',
206
+ signature: (arg) => ({ argTypes: [arg], returnType: arg }),
207
+ normalImpl: errorMessage,
208
+ codegenImpl: (_ctx, [e]) => stitch `quadSwapX(${e})`,
209
+ sideEffects: false,
210
+ });
211
+ export const quadSwapY = dualImpl({
212
+ name: 'quadSwapY',
213
+ signature: (arg) => ({ argTypes: [arg], returnType: arg }),
214
+ normalImpl: errorMessage,
215
+ codegenImpl: (_ctx, [e]) => stitch `quadSwapY(${e})`,
216
+ sideEffects: false,
217
+ });
package/std/texture.d.ts CHANGED
@@ -66,6 +66,14 @@ declare function textureDimensionsCpu<T extends texture2d | texture2dArray | tex
66
66
  declare function textureDimensionsCpu<T extends texture3d | textureStorage3d>(texture: T): v3u;
67
67
  declare function textureDimensionsCpu<T extends texture3d>(texture: T, level: number): v3u;
68
68
  export declare const textureDimensions: import("../types.ts").DualFn<typeof textureDimensionsCpu>;
69
+ type ArrayTexture = texture2dArray | textureCubeArray | textureDepth2dArray | textureDepthCubeArray | textureStorage2dArray;
70
+ declare function textureNumLayersCpu<T extends ArrayTexture>(_texture: T): number;
71
+ export declare const textureNumLayers: import("../types.ts").DualFn<typeof textureNumLayersCpu>;
72
+ type MipmappedTexture = texture1d | texture2d | texture2dArray | texture3d | textureCube | textureCubeArray | textureDepth2d | textureDepth2dArray | textureDepthCube | textureDepthCubeArray;
73
+ declare function textureNumLevelsCpu<T extends MipmappedTexture>(_texture: T): number;
74
+ export declare const textureNumLevels: import("../types.ts").DualFn<typeof textureNumLevelsCpu>;
75
+ declare function textureNumSamplesCpu<T extends textureMultisampled2d | textureDepthMultisampled2d>(_texture: T): number;
76
+ export declare const textureNumSamples: import("../types.ts").DualFn<typeof textureNumSamplesCpu>;
69
77
  type Gather2dArgs<T extends texture2d = texture2d> = [
70
78
  component: number,
71
79
  texture: T,
@@ -121,6 +129,11 @@ type TextureGatherCpuFn = {
121
129
  };
122
130
  export declare const textureGatherCpu: TextureGatherCpuFn;
123
131
  export declare const textureGather: import("../types.ts").DualFn<TextureGatherCpuFn>;
132
+ declare function textureGatherCompareCpu<T extends textureDepth2d>(texture: T, sampler: comparisonSampler, coords: v2f, depthRef: number, offset?: v2i): v4f;
133
+ declare function textureGatherCompareCpu<T extends textureDepth2dArray>(texture: T, sampler: comparisonSampler, coords: v2f, arrayIndex: number, depthRef: number, offset?: v2i): v4f;
134
+ declare function textureGatherCompareCpu<T extends textureDepthCube>(texture: T, sampler: comparisonSampler, coords: v3f, depthRef: number): v4f;
135
+ declare function textureGatherCompareCpu<T extends textureDepthCubeArray>(texture: T, sampler: comparisonSampler, coords: v3f, arrayIndex: number, depthRef: number): v4f;
136
+ export declare const textureGatherCompare: import("../types.ts").DualFn<typeof textureGatherCompareCpu>;
124
137
  declare function textureSampleCompareCpu<T extends textureDepth2d>(texture: T, sampler: comparisonSampler, coords: v2f, depthRef: number): number;
125
138
  declare function textureSampleCompareCpu<T extends textureDepth2d>(texture: T, sampler: comparisonSampler, coords: v2f, depthRef: number, offset: v2i): number;
126
139
  declare function textureSampleCompareCpu<T extends textureDepth2dArray>(texture: T, sampler: comparisonSampler, coords: v2f, arrayIndex: number, depthRef: number): number;
package/std/texture.js CHANGED
@@ -129,6 +129,36 @@ export const textureDimensions = dualImpl({
129
129
  },
130
130
  sideEffects: false,
131
131
  });
132
+ function textureNumLayersCpu(_texture) {
133
+ throw new MissingCpuImplError('`textureNumLayers` relies on GPU resources and cannot be executed outside of a draw call');
134
+ }
135
+ export const textureNumLayers = dualImpl({
136
+ name: 'textureNumLayers',
137
+ normalImpl: textureNumLayersCpu,
138
+ codegenImpl: (_ctx, [texture]) => stitch `textureNumLayers(${texture})`,
139
+ signature: (texture) => ({ argTypes: [texture], returnType: u32 }),
140
+ sideEffects: false,
141
+ });
142
+ function textureNumLevelsCpu(_texture) {
143
+ throw new MissingCpuImplError('`textureNumLevels` relies on GPU resources and cannot be executed outside of a draw call');
144
+ }
145
+ export const textureNumLevels = dualImpl({
146
+ name: 'textureNumLevels',
147
+ normalImpl: textureNumLevelsCpu,
148
+ codegenImpl: (_ctx, [texture]) => stitch `textureNumLevels(${texture})`,
149
+ signature: (texture) => ({ argTypes: [texture], returnType: u32 }),
150
+ sideEffects: false,
151
+ });
152
+ function textureNumSamplesCpu(_texture) {
153
+ throw new MissingCpuImplError('`textureNumSamples` relies on GPU resources and cannot be executed outside of a draw call');
154
+ }
155
+ export const textureNumSamples = dualImpl({
156
+ name: 'textureNumSamples',
157
+ normalImpl: textureNumSamplesCpu,
158
+ codegenImpl: (_ctx, [texture]) => stitch `textureNumSamples(${texture})`,
159
+ signature: (texture) => ({ argTypes: [texture], returnType: u32 }),
160
+ sideEffects: false,
161
+ });
132
162
  export const textureGatherCpu = (..._args) => {
133
163
  throw new Error('Texture gather relies on GPU resources and cannot be executed outside of a draw call');
134
164
  };
@@ -162,6 +192,24 @@ export const textureGather = dualImpl({
162
192
  },
163
193
  sideEffects: false,
164
194
  });
195
+ function textureGatherCompareCpu(_texture, _sampler, _coords, _depthRefOrArrayIndex, _depthRefOrOffset, _maybeOffset) {
196
+ throw new MissingCpuImplError('`textureGatherCompare` relies on GPU resources and cannot be executed outside of a draw call');
197
+ }
198
+ export const textureGatherCompare = dualImpl({
199
+ name: 'textureGatherCompare',
200
+ normalImpl: textureGatherCompareCpu,
201
+ codegenImpl: (_ctx, args) => stitch `textureGatherCompare(${args})`,
202
+ signature: (...args) => {
203
+ const texture = args[0];
204
+ const isArrayTexture = texture.type === 'texture_depth_2d_array' || texture.type === 'texture_depth_cube_array';
205
+ const [tex, sampler, coords, _arrayIndex, ...rest] = args;
206
+ return {
207
+ argTypes: isArrayTexture ? [tex, sampler, coords, [u32, i32], ...rest] : args,
208
+ returnType: vec4f,
209
+ };
210
+ },
211
+ sideEffects: false,
212
+ });
165
213
  function textureSampleCompareCpu(_texture, _sampler, _coords, _depthRefOrArrayIndex, _depthRefOrOffset, _maybeOffset) {
166
214
  throw new MissingCpuImplError('Texture comparison sampling relies on GPU resources and cannot be executed outside of a draw call');
167
215
  }
package/tgpuUnstable.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { declare } from './core/declare/tgpuDeclare.ts';
2
+ export { immediateVar } from './core/immediate/immediateVar.ts';
2
3
  export { rawCodeSnippet } from './core/rawCodeSnippet/tgpuRawCodeSnippet.ts';
3
4
  export { namespace } from './core/resolve/namespace.ts';
4
5
  export { simulate } from './core/simulate/tgpuSimulate.ts';
package/tgpuUnstable.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // NOTE: This is a barrel file, internal files should not import things from this file
2
2
  export { declare } from "./core/declare/tgpuDeclare.js";
3
+ export { immediateVar } from "./core/immediate/immediateVar.js";
3
4
  export { rawCodeSnippet } from "./core/rawCodeSnippet/tgpuRawCodeSnippet.js";
4
5
  export { namespace } from "./core/resolve/namespace.js";
5
6
  export { simulate } from "./core/simulate/tgpuSimulate.js";
@@ -16,6 +16,7 @@ export type ConversionResult = {
16
16
  export declare function getBestConversion(types: BaseData[], targetTypes?: BaseData[]): ConversionResult | undefined;
17
17
  /**
18
18
  * Unifies input types to a common type.
19
+ * Ties between equally good `restrictTo` candidates go to the one listed first.
19
20
  */
20
21
  export declare function unify<T extends (BaseData | UnknownData)[] | []>(inTypes: T, restrictTo?: BaseData[]): {
21
22
  [K in keyof T]: BaseData;
@@ -23,6 +24,7 @@ export declare function unify<T extends (BaseData | UnknownData)[] | []>(inTypes
23
24
  /**
24
25
  * Unifies input types to a common type.
25
26
  * Unlike `unify`, it does not allow implicit conversions.
27
+ * Ties between equally good `restrictTo` candidates go to the one listed first.
26
28
  */
27
29
  export declare function unifyStrict<T extends (BaseData | UnknownData)[] | []>(inTypes: T, restrictTo?: BaseData[]): {
28
30
  [K in keyof T]: BaseData;
@@ -131,6 +131,7 @@ function findBestType(types, uniqueTypes, allowImplicit) {
131
131
  destType = conversion.targetType;
132
132
  }
133
133
  }
134
+ // Ties keep the earlier candidate, so callers order their target types by preference.
134
135
  if (sum < (bestResult?.sum ?? Number.POSITIVE_INFINITY)) {
135
136
  bestResult = { type: destType, details, sum };
136
137
  }
@@ -209,6 +210,7 @@ function applyActionToSnippet(ctx, snippet, action, targetType) {
209
210
  }
210
211
  /**
211
212
  * Unifies input types to a common type.
213
+ * Ties between equally good `restrictTo` candidates go to the one listed first.
212
214
  */
213
215
  export function unify(inTypes, restrictTo) {
214
216
  if (inTypes.some((type) => type === UnknownData)) {
@@ -223,6 +225,7 @@ export function unify(inTypes, restrictTo) {
223
225
  /**
224
226
  * Unifies input types to a common type.
225
227
  * Unlike `unify`, it does not allow implicit conversions.
228
+ * Ties between equally good `restrictTo` candidates go to the one listed first.
226
229
  */
227
230
  export function unifyStrict(inTypes, restrictTo) {
228
231
  if (inTypes.some((type) => type === UnknownData)) {
@@ -17,7 +17,7 @@ export interface ConstantDefinitionOptions {
17
17
  readonly init: Snippet;
18
18
  }
19
19
  export interface VariableDefinitionOptions {
20
- readonly scope: VariableScope | BindableBufferUsage | 'handle';
20
+ readonly scope: VariableScope | BindableBufferUsage | 'handle' | 'immediate';
21
21
  readonly id: string;
22
22
  readonly dataType: BaseData;
23
23
  readonly init: Snippet | undefined;
@@ -19,6 +19,7 @@ export declare class WgslGenerator implements ShaderGenerator {
19
19
  */
20
20
  protected _emitVarDecl(keyword: 'var' | 'let' | 'const' | `#VAR_${number}#`, name: string, _dataType: wgsl.BaseData, rhsStr: string): string;
21
21
  protected _identifier(id: string): Snippet;
22
+ protected _emitSwitchStatement(discriminantExpr: Snippet, groupedCaseExprs: [tests: Snippet[], consequent: ResolvedStatement[]][]): string;
22
23
  protected _callShellless(callee: AnyFn, args: readonly Snippet[]): ResolvedSnippet | undefined;
23
24
  /**
24
25
  * A wrapper for `generateExpression` that updates `ctx.expectedType`
@@ -51,6 +52,10 @@ export declare class WgslGenerator implements ShaderGenerator {
51
52
  */
52
53
  protected _aliasConstStatement(rawId: string, eqNode: tinyest.Expression, eq: Snippet): ResolvedStatement;
53
54
  protected _statement(statement: tinyest.Statement): ResolvedStatement;
55
+ /**
56
+ * Resolves the key of an object property. Handles both computed and non-computed keys.
57
+ */
58
+ protected _resolveObjectPropertyKey(property: tinyest.ObjectProperty): string;
54
59
  /**
55
60
  * Attempts a member access lookup to mark a variable as modified.
56
61
  * @example