1
1
import TempNode from '../core/TempNode.js' ;
2
2
import { addMethodChaining , nodeProxy } from '../tsl/TSLCore.js' ;
3
3
4
+
5
+ /**
6
+ * This class represents a set of built in WGSL shader functions that sync
7
+ * synchronously execute an operation across a subgroup, or 'wave', of compute
8
+ * or fragment shader invocations within a workgroup. Typically, these functions
9
+ * will synchronously execute an operation using data from all active invocations
10
+ * within the subgroup, then broadcast that result to all active invocations. In
11
+ * other graphics APIs, subgroup functions are also referred to as wave intrinsics
12
+ * (DirectX/HLSL) or warp intrinsics (CUDA).
13
+ *
14
+ * @augments TempNode
15
+ */
4
16
class SubgroupFunctionNode extends TempNode {
5
17
6
18
static get type ( ) {
@@ -9,13 +21,36 @@ class SubgroupFunctionNode extends TempNode {
9
21
10
22
}
11
23
24
+ /**
25
+ * Constructs a new function node.
26
+ *
27
+ * @param {String } method - The subgroup/wave intrinsic method to construct.
28
+ * @param {Node } [aNode=null] - The method's first argument.
29
+ * @param {Node } [bNode=null] - The method's second argument.
30
+ */
12
31
constructor ( method , aNode = null , bNode = null ) {
13
32
14
33
super ( ) ;
15
34
35
+ /**
36
+ * The subgroup/wave intrinsic method to construct.
37
+ *
38
+ * @type {String }
39
+ */
16
40
this . method = method ;
17
41
42
+ /**
43
+ * The method's first argument.
44
+ *
45
+ * @type {Node }
46
+ */
18
47
this . aNode = aNode ;
48
+
49
+ /**
50
+ * The method's second argument.
51
+ *
52
+ * @type {Node }
53
+ */
19
54
this . bNode = bNode ;
20
55
21
56
}
@@ -162,30 +197,236 @@ SubgroupFunctionNode.QUAD_BROADCAST = 'quadBroadcast';
162
197
163
198
export default SubgroupFunctionNode ;
164
199
200
+
201
+
202
+ /**
203
+ * Returns true if this invocation has the lowest subgroup_invocation_id
204
+ * among active invocations in the subgroup.
205
+ *
206
+ * @method
207
+ * @return {bool } The result of the computation.
208
+ */
165
209
export const subgroupElect = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_ELECT ) ;
210
+
211
+ /**
212
+ * Returns a set of bitfields where the bit corresponding to subgroup_invocation_id
213
+ * is 1 if pred is true for that active invocation and 0 otherwise.
214
+ *
215
+ * @method
216
+ * @param {bool } pred - A boolean that sets the bit corresponding to the invocations subgroup invocation id.
217
+ * @return {vec4<u32> }- A bitfield corresponding to the pred value of each subgroup invocation.
218
+ */
166
219
export const subgroupBallot = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_BALLOT ) ;
220
+
221
+ /**
222
+ * A reduction that adds e among all active invocations and returns that result.
223
+ *
224
+ * @method
225
+ * @param {number } e - The value provided to the reduction by the current invocation.
226
+ * @return {number } The accumulated result of the reduction operation.
227
+ */
167
228
export const subgroupAdd = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_ADD ) ;
229
+
230
+ /**
231
+ * An inclusive scan returning the sum of e for all active invocations with subgroup_invocation_id less than or equal to this invocation.
232
+ *
233
+ * @method
234
+ * @param {number } e - The value provided to the inclusive scan by the current invocation.
235
+ * @return {number } The accumulated result of the inclusive scan operation.
236
+ */
168
237
export const subgroupInclusiveAdd = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_INCLUSIVE_ADD ) ;
238
+
239
+ /**
240
+ * An exclusive scan that returns the sum of e for all active invocations with subgroup_invocation_id less than this invocation.
241
+ *
242
+ * @method
243
+ * @param {number } e - The value provided to the exclusive scan by the current invocation.
244
+ * @return {number } The accumulated result of the exclusive scan operation.
245
+ */
169
246
export const subgroupExclusiveAdd = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_EXCLUSIVE_AND ) ;
247
+
248
+ /**
249
+ * A reduction that multiplies e among all active invocations and returns that result.
250
+ *
251
+ * @method
252
+ * @param {number } e - The value provided to the reduction by the current invocation.
253
+ * @return {number } The accumulated result of the reduction operation.
254
+ */
170
255
export const subgroupMul = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_MUL ) ;
256
+
257
+ /**
258
+ * An inclusive scan returning the product of e for all active invocations with subgroup_invocation_id less than or equal to this invocation.
259
+ *
260
+ * @method
261
+ * @param {number } e - The value provided to the inclusive scan by the current invocation.
262
+ * @return {number } The accumulated result of the inclusive scan operation.
263
+ */
171
264
export const subgroupInclusiveMul = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_INCLUSIVE_MUL ) ;
265
+
266
+ /**
267
+ * An exclusive scan that returns the product of e for all active invocations with subgroup_invocation_id less than this invocation.
268
+ *
269
+ * @method
270
+ * @param {number } e - The value provided to the exclusive scan by the current invocation.
271
+ * @return {number } The accumulated result of the exclusive scan operation.
272
+ */
172
273
export const subgroupExclusiveMul = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_EXCLUSIVE_MUL ) ;
274
+
275
+ /**
276
+ * A reduction that performs a bitwise and of e among all active invocations and returns that result.
277
+ *
278
+ * @method
279
+ * @param {number } e - The value provided to the reduction by the current invocation.
280
+ * @return {number } The result of the reduction operation.
281
+ */
173
282
export const subgroupAnd = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_AND ) ;
283
+
284
+ /**
285
+ * A reduction that performs a bitwise or of e among all active invocations and returns that result.
286
+ *
287
+ * @method
288
+ * @param {number } e - The value provided to the reduction by the current invocation.
289
+ * @return {number } The result of the reduction operation.
290
+ */
174
291
export const subgroupOr = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_OR ) ;
292
+
293
+ /**
294
+ * A reduction that performs a bitwise xor of e among all active invocations and returns that result.
295
+ *
296
+ * @method
297
+ * @param {number } e - The value provided to the reduction by the current invocation.
298
+ * @return {number } The result of the reduction operation.
299
+ */
175
300
export const subgroupXor = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_XOR ) ;
301
+
302
+ /**
303
+ * A reduction that performs a min of e among all active invocations and returns that result.
304
+ *
305
+ * @method
306
+ * @param {number } e - The value provided to the reduction by the current invocation.
307
+ * @return {number } The result of the reduction operation.
308
+ */
176
309
export const subgroupMin = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_MIN ) ;
310
+
311
+ /**
312
+ * A reduction that performs a max of e among all active invocations and returns that result.
313
+ *
314
+ * @method
315
+ * @param {number } e - The value provided to the reduction by the current invocation.
316
+ * @return {number } The result of the reduction operation.
317
+ */
177
318
export const subgroupMax = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_MAX ) ;
319
+
320
+ /**
321
+ * Returns true if e is true for all active invocations in the subgroup.
322
+ *
323
+ * @method
324
+ * @return {bool } The result of the computation.
325
+ */
178
326
export const subgroupAll = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_ALL ) ;
327
+
328
+ /**
329
+ * Returns true if e is true for any active invocation in the subgroup
330
+ *
331
+ * @method
332
+ * @return {bool } The result of the computation.
333
+ */
179
334
export const subgroupAny = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_ANY ) ;
335
+
336
+ /**
337
+ * Broadcasts e from the active invocation with the lowest subgroup_invocation_id in the subgroup to all other active invocations.
338
+ *
339
+ * @method
340
+ * @param {number } e - The value to broadcast from the lowest subgroup invocation.
341
+ * @param {number } id - The subgroup invocation to broadcast from.
342
+ * @return {number } The broadcast value.
343
+ */
180
344
export const subgroupBroadcastFirst = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_BROADCAST_FIRST ) ;
345
+
346
+ /**
347
+ * Swaps e between invocations in the quad in the X direction.
348
+ *
349
+ * @method
350
+ * @param {number } e - The value to swap from the current invocation.
351
+ * @return {number } The value received from the swap operation.
352
+ */
181
353
export const quadSwapX = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . QUAD_SWAP_X ) ;
354
+
355
+ /**
356
+ * Swaps e between invocations in the quad in the Y direction.
357
+ *
358
+ * @method
359
+ * @param {number } e - The value to swap from the current invocation.
360
+ * @return {number } The value received from the swap operation.
361
+ */
182
362
export const quadSwapY = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . QUAD_SWAP_Y ) ;
363
+
364
+ /**
365
+ * Swaps e between invocations in the quad diagonally.
366
+ *
367
+ * @method
368
+ * @param {number } e - The value to swap from the current invocation.
369
+ * @return {number } The value received from the swap operation.
370
+ */
183
371
export const quadSwapDiagonal = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . QUAD_SWAP_DIAGONAL ) ;
372
+
373
+ /**
374
+ * Broadcasts e from the invocation whose subgroup_invocation_id matches id, to all active invocations.
375
+ *
376
+ * @method
377
+ * @param {number } e - The value to broadcast from subgroup invocation 'id'.
378
+ * @param {number } id - The subgroup invocation to broadcast from.
379
+ * @return {number } The broadcast value.
380
+ */
184
381
export const subgroupBroadcast = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_BROADCAST ) ;
382
+
383
+ /**
384
+ * Returns v from the active invocation whose subgroup_invocation_id matches id
385
+ *
386
+ * @method
387
+ * @param {number } v - The value to return from subgroup invocation id^mask.
388
+ * @param {number } id - The subgroup invocation which returns the value v.
389
+ * @return {number } The broadcast value.
390
+ */
185
391
export const subgroupShuffle = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_SHUFFLE ) ;
392
+
393
+ /**
394
+ * Returns v from the active invocation whose subgroup_invocation_id matches subgroup_invocation_id ^ mask.
395
+ *
396
+ * @method
397
+ * @param {number } v - The value to return from subgroup invocation id^mask.
398
+ * @param {number } mask - A bitmask that determines the target invocation via a XOR operation.
399
+ * @return {number } The broadcast value.
400
+ */
186
401
export const subgroupShuffleXor = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_SHUFFLE_XOR ) ;
402
+
403
+ /**
404
+ * Returns v from the active invocation whose subgroup_invocation_id matches subgroup_invocation_id - delta
405
+ *
406
+ * @method
407
+ * @param {number } v - The value to return from subgroup invocation id^mask.
408
+ * @param {number } delta - A value that offsets the current in.
409
+ * @return {number } The broadcast value.
410
+ */
187
411
export const subgroupShuffleUp = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_SHUFFLE_UP ) ;
412
+
413
+ /**
414
+ * Returns v from the active invocation whose subgroup_invocation_id matches subgroup_invocation_id + delta
415
+ *
416
+ * @method
417
+ * @param {number } v - The value to return from subgroup invocation id^mask.
418
+ * @param {number } delta - A value that offsets the current subgroup invocation.
419
+ * @return {number } The broadcast value.
420
+ */
188
421
export const subgroupShuffleDown = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . SUBGROUP_SHUFFLE_DOWN ) ;
422
+
423
+ /**
424
+ * Broadcasts e from the quad invocation with id equal to id.
425
+ *
426
+ * @method
427
+ * @param {number } e - The value to broadcast.
428
+ * @return {number } The broadcast value.
429
+ */
189
430
export const quadBroadcast = /*@__PURE__ */ nodeProxy ( SubgroupFunctionNode , SubgroupFunctionNode . QUAD_BROADCAST ) ;
190
431
191
432
addMethodChaining ( 'subgroupElect' , subgroupElect ) ;
0 commit comments