Skip to content

Commit 62fc41a

Browse files
committed
document SubgroupFunctionNode
1 parent db93ec6 commit 62fc41a

File tree

1 file changed

+241
-0
lines changed

1 file changed

+241
-0
lines changed

src/nodes/gpgpu/SubgroupFunctionNode.js

+241
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import TempNode from '../core/TempNode.js';
22
import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
33

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+
*/
416
class SubgroupFunctionNode extends TempNode {
517

618
static get type() {
@@ -9,13 +21,36 @@ class SubgroupFunctionNode extends TempNode {
921

1022
}
1123

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+
*/
1231
constructor( method, aNode = null, bNode = null ) {
1332

1433
super();
1534

35+
/**
36+
* The subgroup/wave intrinsic method to construct.
37+
*
38+
* @type {String}
39+
*/
1640
this.method = method;
1741

42+
/**
43+
* The method's first argument.
44+
*
45+
* @type {Node}
46+
*/
1847
this.aNode = aNode;
48+
49+
/**
50+
* The method's second argument.
51+
*
52+
* @type {Node}
53+
*/
1954
this.bNode = bNode;
2055

2156
}
@@ -162,30 +197,236 @@ SubgroupFunctionNode.QUAD_BROADCAST = 'quadBroadcast';
162197

163198
export default SubgroupFunctionNode;
164199

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+
*/
165209
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+
*/
166219
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+
*/
167228
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+
*/
168237
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+
*/
169246
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+
*/
170255
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+
*/
171264
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+
*/
172273
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+
*/
173282
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+
*/
174291
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+
*/
175300
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+
*/
176309
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+
*/
177318
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+
*/
178326
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+
*/
179334
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+
*/
180344
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+
*/
181353
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+
*/
182362
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+
*/
183371
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+
*/
184381
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+
*/
185391
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+
*/
186401
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+
*/
187411
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+
*/
188421
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+
*/
189430
export const quadBroadcast = /*@__PURE__*/ nodeProxy( SubgroupFunctionNode, SubgroupFunctionNode.QUAD_BROADCAST );
190431

191432
addMethodChaining( 'subgroupElect', subgroupElect );

0 commit comments

Comments
 (0)