@orkestrel/wgsl 0.0.2 → 0.0.7
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.
- package/README.md +55 -0
- package/dist/src/core/index.cjs +10055 -1336
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +3297 -458
- package/dist/src/core/index.d.ts +3297 -458
- package/dist/src/core/index.js +9964 -1338
- package/dist/src/core/index.js.map +1 -1
- package/package.json +5 -5
package/dist/src/core/index.d.ts
CHANGED
|
@@ -19,15 +19,80 @@
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function collectWGSLFragments(roots: readonly WGSLFragment[]): readonly WGSLFragment[];
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Collects the sections of a program's rendered WGSL text, each with its role, its producer, and its line range.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* The sections follow `WGSL_SECTION_ROLES` order: `requires` language-extension directives in
|
|
27
|
+
* `WGSL_LANGUAGES` order; `enable` extension directives in `WGSL_EXTENSIONS` order (including `f16`
|
|
28
|
+
* whenever any storage slot declares `f16`, `vec2h`, or `vec4h`, and `subgroups` whenever
|
|
29
|
+
* `subgroup_id` is active); `override` pipeline-overridable
|
|
30
|
+
* constant declarations; the uniform struct declaration; the `Dispatch` struct (adding
|
|
31
|
+
* `subgroup_size` when `subgroups` is enabled and `num_subgroups` when `subgroup_id` is required);
|
|
32
|
+
* the `Invocation` struct (adding `subgroup_invocation_id` when `subgroups` is enabled and
|
|
33
|
+
* `subgroup_id` when `subgroup_id` is required); the binding lines; one `fragment` section per
|
|
34
|
+
* linked fragment whose active body is non-empty; and the entry function. Variant linearity holds
|
|
35
|
+
* only when `(options?.linear ?? true) && program.entry.size[1] === 1 && program.entry.size[2] === 1`.
|
|
36
|
+
*
|
|
37
|
+
* @param program - The program to render
|
|
38
|
+
* @param options - The active extensions, language extensions, subgroup bounds, and linearity flag
|
|
39
|
+
* @returns The sections in render order, each frozen, in a frozen list
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* collectWGSLSections(program)[0]?.role // 'struct'
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function collectWGSLSections(program: WGSLProgram, options?: WGSLRenderOptions): readonly WGSLSection[];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Computes the Gauss error function `erf(value)` to IEEE-754 `f64` accuracy, pairing with `computeErf` in `WGSL_SPECIAL`.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* Uses Cody's rational Chebyshev approximation directly for `|value| <= 0.46875` and delegates
|
|
53
|
+
* larger magnitudes to `computeWGSLErfc` so `erf(x)` keeps full double precision and preserves `-0`,
|
|
54
|
+
* `±Infinity`, and `NaN`. Thrown with code `ARGUMENT` when `value` is not a number.
|
|
55
|
+
*
|
|
56
|
+
* @param value - The real input
|
|
57
|
+
* @returns The value of `erf(value)` in `[-1, 1]`
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* computeWGSLErf(0) // 0
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function computeWGSLErf(value: number): number;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Computes the complementary error function `erfc(value)` without tail cancellation, pairing with `computeErfc` in `WGSL_SPECIAL`.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* Uses Cody's rational Chebyshev approximation with exact `1/16` exponential range splitting so
|
|
71
|
+
* `erfc(value)` stays accurate into the subnormal tail (`value <= 27.3`), returns `1` at `±0`, `0`
|
|
72
|
+
* at `+Infinity`, `2` at `-Infinity`, and `NaN` for `NaN`. Thrown with code `ARGUMENT` when `value`
|
|
73
|
+
* is not a number.
|
|
74
|
+
*
|
|
75
|
+
* @param value - The real input
|
|
76
|
+
* @returns The value of `erfc(value)` in `[0, 2]`
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* computeWGSLErfc(0) // 1
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function computeWGSLErfc(value: number): number;
|
|
84
|
+
|
|
22
85
|
/**
|
|
23
86
|
* Computes a dispatch's workgroup counts for a total: the x axis up to the limit, then the y axis.
|
|
24
87
|
*
|
|
25
88
|
* @remarks
|
|
26
89
|
* A program reads its workgroup's index as
|
|
27
|
-
* `
|
|
28
|
-
*
|
|
90
|
+
* `dispatch.workgroup_id.x + dispatch.workgroup_id.y * dispatch.num_workgroups.x`, which the
|
|
91
|
+
* `WGSL_PLACE` fragment declares as `readPlace(dispatch: Dispatch)`, so a workgroup past the total
|
|
92
|
+
* finds no work. A total of 0 gives one workgroup. Thrown with code
|
|
29
93
|
* `ARGUMENT` when `total` is not a non-negative safe integer, `-0` included, or `limit` is not a
|
|
30
|
-
* positive safe integer, and with code `LIMIT` when the
|
|
94
|
+
* positive safe integer, and with code `LIMIT` when the grid exceeds `limit` on `y`, exceeds a
|
|
95
|
+
* `u32` axis count, or makes `x * y` exceed `2^32` (which would wrap `readPlace`).
|
|
31
96
|
*
|
|
32
97
|
* @param total - The number of workgroups
|
|
33
98
|
* @param limit - The device's `maxComputeWorkgroupsPerDimension`
|
|
@@ -40,6 +105,43 @@ export declare function collectWGSLFragments(roots: readonly WGSLFragment[]): re
|
|
|
40
105
|
*/
|
|
41
106
|
export declare function computeWGSLGrid(total: number, limit: number): WGSLGrid;
|
|
42
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Computes the inverse Gauss error function `erfinv(value)` to IEEE-754 `f64` accuracy, pairing with `computeInverseErf` in `WGSL_SPECIAL`.
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* Seeds with Giles's minimax approximation and polishes with two cubic Halley steps using
|
|
113
|
+
* `computeWGSLErf` and `computeWGSLErfc`. Preserves `-0`, returns `±Infinity` at `±1`, and returns
|
|
114
|
+
* `NaN` for `|value| > 1` or `NaN`. Thrown with code `ARGUMENT` when `value` is not a number.
|
|
115
|
+
*
|
|
116
|
+
* @param value - The probability-domain input in `[-1, 1]`
|
|
117
|
+
* @returns The real value `x` satisfying `erf(x) = value`
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* computeWGSLInverseErf(0) // 0
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare function computeWGSLInverseErf(value: number): number;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Computes `ln(|Gamma(value)|)` to IEEE-754 `f64` accuracy, pairing with `computeLogGamma` in `WGSL_SPECIAL`.
|
|
128
|
+
*
|
|
129
|
+
* @remarks
|
|
130
|
+
* Uses a zeta-series expansion near the zeros `1` and `2`, Lanczos `g = 7` on moderate positive
|
|
131
|
+
* values, Stirling's asymptotic series above `1e8`, and Euler's reflection formula on negative
|
|
132
|
+
* non-integers. Returns `+Infinity` at `±Infinity`, `±0`, and negative integers, `0` at `1` and
|
|
133
|
+
* `2`, and `NaN` for `NaN`. Thrown with code `ARGUMENT` when `value` is not a number.
|
|
134
|
+
*
|
|
135
|
+
* @param value - The real input
|
|
136
|
+
* @returns The natural logarithm of `|Gamma(value)|`
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* computeWGSLLogGamma(1) // 0
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare function computeWGSLLogGamma(value: number): number;
|
|
144
|
+
|
|
43
145
|
/**
|
|
44
146
|
* Computes the smallest multiple of an alignment at or above an offset.
|
|
45
147
|
*
|
|
@@ -59,476 +161,2203 @@ export declare function computeWGSLGrid(total: number, limit: number): WGSLGrid;
|
|
|
59
161
|
export declare function computeWGSLOffset(offset: number, alignment: number): number;
|
|
60
162
|
|
|
61
163
|
/**
|
|
62
|
-
*
|
|
164
|
+
* Computes one 10-round Random123 Philox4x32 output block, as `computePhilox` in `WGSL_RANDOM` does.
|
|
63
165
|
*
|
|
64
166
|
* @remarks
|
|
65
|
-
*
|
|
66
|
-
*
|
|
167
|
+
* Uses exact 32-by-32-to-64-bit multiplication (`0xd2511f53` and `0xcd9e8d57`) and Weyl key schedule
|
|
168
|
+
* (`0x9e3779b9` and `0xbb67ae85`), matching the official Random123 known-answer vectors bit-for-bit.
|
|
169
|
+
* Thrown with code `ARGUMENT` when `counter` is not 4 unsigned 32-bit integers or `key` is not 2
|
|
170
|
+
* unsigned 32-bit integers.
|
|
67
171
|
*
|
|
68
|
-
* @param
|
|
69
|
-
* @
|
|
172
|
+
* @param counter - The 4-word 128-bit counter
|
|
173
|
+
* @param key - The 2-word 64-bit key
|
|
174
|
+
* @returns The 4 unsigned 32-bit output words, frozen
|
|
70
175
|
*
|
|
71
176
|
* @example
|
|
72
177
|
* ```ts
|
|
73
|
-
*
|
|
178
|
+
* computeWGSLPhilox([0, 0, 0, 0], [0, 0])[0] // 0x6627e8d5
|
|
74
179
|
* ```
|
|
75
180
|
*/
|
|
76
|
-
export declare function
|
|
181
|
+
export declare function computeWGSLPhilox(counter: readonly [number, number, number, number], key: readonly [number, number]): readonly [number, number, number, number];
|
|
77
182
|
|
|
78
183
|
/**
|
|
79
|
-
* Creates a frozen
|
|
184
|
+
* Creates a frozen workgroup arg-reduction fragment returning both the winning value and its index.
|
|
80
185
|
*
|
|
81
186
|
* @remarks
|
|
82
|
-
*
|
|
83
|
-
* `
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
187
|
+
* Declares `struct {Stem}Result { value: {element}, index: u32 }`, one workgroup variable
|
|
188
|
+
* `{stem}Shared`, and `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element},
|
|
189
|
+
* index: u32) -> {Stem}Result`. Ties always resolve to the lowest `index`, `f32` comparisons use
|
|
190
|
+
* bit-level subnormal-safe total-order keys (`-0.0` ties `+0.0` by index while preserving original
|
|
191
|
+
* bits, and finite or infinite values always beat `NaN`), and both the 2D-safe base and the
|
|
192
|
+
* `linear: true` `subgroups` variant return through `workgroupUniformLoad`. When padding inactive
|
|
193
|
+
* `f32` lanes with a `NaN` or `±Infinity` sentinel, mask the bit pattern with a runtime input such
|
|
194
|
+
* as `bitcast<f32>(0x7fc00000u | (invocation.local_invocation_index & 0u))` (`0xff800000u` for
|
|
195
|
+
* `-Infinity`, `0x7f800000u` for `+Infinity`), because Tint rejects const-expression `NaN` and
|
|
196
|
+
* `Infinity` bitcasts. Thrown with code `ARGUMENT` for malformed options or an invalid `name`.
|
|
197
|
+
*
|
|
198
|
+
* @param input - The arg-reduction's workgroup count, selecting operation, element type, and optional name
|
|
199
|
+
* @returns The frozen arg-reduction fragment
|
|
90
200
|
*
|
|
91
201
|
* @example
|
|
92
202
|
* ```ts
|
|
93
|
-
*
|
|
203
|
+
* createWGSLArgReduce({ workgroup: 128, operation: 'max', element: 'f32' }).name // 'argReduceMaxF32128'
|
|
94
204
|
* ```
|
|
95
205
|
*/
|
|
96
|
-
export declare function
|
|
206
|
+
export declare function createWGSLArgReduce(input: WGSLArgReduceInput): WGSLFragment;
|
|
97
207
|
|
|
98
208
|
/**
|
|
99
|
-
* Creates
|
|
209
|
+
* Creates a frozen workgroup broadcast fragment returning one selected lane's value uniformly.
|
|
100
210
|
*
|
|
101
211
|
* @remarks
|
|
102
|
-
*
|
|
103
|
-
*
|
|
212
|
+
* Declares an 8-byte `struct {Stem}Slot { lane: u32, value: {element} }`,
|
|
213
|
+
* `var<workgroup> {stem}Shared: {Stem}Slot`, and
|
|
214
|
+
* `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}, lane: u32) -> {element}`.
|
|
215
|
+
* Invocation `0` supplies the winning `lane`, clamped to `workgroup - 1`, and the selected element
|
|
216
|
+
* is loaded with `workgroupUniformLoad` (3 total barriers), so Tint treats the returned scalar as
|
|
217
|
+
* workgroup-uniform even when `lane` varies across invocations. Thrown with code `ARGUMENT` for
|
|
218
|
+
* malformed options or an invalid `name`.
|
|
104
219
|
*
|
|
105
|
-
* @param
|
|
106
|
-
* @
|
|
107
|
-
* @returns The session
|
|
220
|
+
* @param input - The broadcast's workgroup count, element type, and optional name
|
|
221
|
+
* @returns The frozen broadcast fragment
|
|
108
222
|
*
|
|
109
223
|
* @example
|
|
110
224
|
* ```ts
|
|
111
|
-
*
|
|
112
|
-
* session.status // 'open'
|
|
225
|
+
* createWGSLBroadcast({ workgroup: 64, element: 'f32' }).name // 'broadcastF3264'
|
|
113
226
|
* ```
|
|
114
227
|
*/
|
|
115
|
-
export declare function
|
|
228
|
+
export declare function createWGSLBroadcast(input: WGSLBroadcastInput): WGSLFragment;
|
|
116
229
|
|
|
117
230
|
/**
|
|
118
|
-
* Creates a frozen
|
|
231
|
+
* Creates a frozen workgroup stream-compaction fragment returning each lane's exclusive kept offset and workgroup-wide total.
|
|
119
232
|
*
|
|
120
233
|
* @remarks
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
234
|
+
* Declares `struct {Stem}Result { offset: u32, total: u32 }`, one workgroup scratch variable
|
|
235
|
+
* `{stem}Shared`, and `fn {stem}(invocation: Invocation, dispatch: Dispatch, keep: bool) -> {Stem}Result`.
|
|
236
|
+
* `offset` holds the `0`-based count of preceding lanes with `keep == true`, and every lane
|
|
237
|
+
* receives the same workgroup-wide `total` count of kept lanes (`sgCount` when `num_subgroups == 1`
|
|
238
|
+
* on the 1D ballot path, `workgroupUniformLoad` otherwise). Because WGSL static uniformity analysis
|
|
239
|
+
* taints a returned `struct` carrying per-lane `offset`, callers branching before a barrier must
|
|
240
|
+
* reload `total` through `workgroupUniformLoad`, or pair with `WGSL_JOIN` or `createWGSLBroadcast`.
|
|
241
|
+
* Attaches both a 1D `linear: true` direct `subgroupBallot` variant (`0` barriers when
|
|
242
|
+
* `num_subgroups == 1`) and a 2D-safe remapped `subgroupBallot` variant requiring `subgroup_id`,
|
|
243
|
+
* clamping every ballot mask to `activeSg = min(dispatch.subgroup_size, workgroup)` across
|
|
244
|
+
* `subgroup_size <= 32` and `vec4u` paths. Thrown with code `ARGUMENT` for malformed options or an
|
|
245
|
+
* invalid `name`.
|
|
246
|
+
*
|
|
247
|
+
* @param input - The compaction's workgroup count and optional name
|
|
248
|
+
* @returns The frozen stream-compaction fragment
|
|
130
249
|
*
|
|
131
250
|
* @example
|
|
132
251
|
* ```ts
|
|
133
|
-
*
|
|
252
|
+
* createWGSLCompact({ workgroup: 256 }).name // 'compact256'
|
|
134
253
|
* ```
|
|
135
254
|
*/
|
|
136
|
-
export declare function
|
|
255
|
+
export declare function createWGSLCompact(input: WGSLCompactInput): WGSLFragment;
|
|
137
256
|
|
|
138
257
|
/**
|
|
139
|
-
*
|
|
258
|
+
* Creates a frozen fragment from author-written WGSL text, its used fragments, and its conditional variants.
|
|
140
259
|
*
|
|
141
|
-
* @
|
|
142
|
-
*
|
|
260
|
+
* @remarks
|
|
261
|
+
* The text reaches the compiler unchanged. The fragment always carries a frozen `variants` list and
|
|
262
|
+
* carries `workgroup` only when the input declares it. Each variant must declare at least one active
|
|
263
|
+
* constraint (a non-empty `extensions` or `languages` list, a `subgroup` bound, or `linear: true`)
|
|
264
|
+
* so no unconstrained variant shadows `source`. Thrown with code `ARGUMENT` when `name` is empty,
|
|
265
|
+
* when a source is not a string, when `uses` or `variants` is not an array, when any variant names
|
|
266
|
+
* an extension outside `WGSL_EXTENSIONS`, a language outside `WGSL_LANGUAGES`, an invalid subgroup
|
|
267
|
+
* range outside `[4, 128]` or with `minimum > maximum`, `'subgroup_id'` in `languages` or
|
|
268
|
+
* `subgroup` bounds without `'subgroups'` in `extensions`, a non-boolean `linear`, or no active
|
|
269
|
+
* constraint, and when `workgroup` is declared and is not a positive safe integer.
|
|
270
|
+
*
|
|
271
|
+
* @param input - The fragment's name, text, used fragments, optional variants, and optional workgroup count
|
|
272
|
+
* @returns The fragment, frozen
|
|
143
273
|
*
|
|
144
274
|
* @example
|
|
145
275
|
* ```ts
|
|
146
|
-
*
|
|
147
|
-
* isWGSLAccess('write') // false
|
|
276
|
+
* createWGSLFragment({ name: 'square', source: 'fn square(value: f32) -> f32 { return value * value; }' }).variants // []
|
|
148
277
|
* ```
|
|
149
278
|
*/
|
|
150
|
-
export declare function
|
|
279
|
+
export declare function createWGSLFragment(input: WGSLFragmentInput): WGSLFragment;
|
|
151
280
|
|
|
152
281
|
/**
|
|
153
|
-
*
|
|
282
|
+
* Creates a frozen workgroup atomic histogram fragment with strided clear, weighted tally, bounds-checked read, and single-call convenience collective.
|
|
154
283
|
*
|
|
155
284
|
* @remarks
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
285
|
+
* Declares `var<workgroup> {stem}Shared: array<atomic<u32>, {bins}>` and four functions:
|
|
286
|
+
* `clear{Stem}(invocation)`, `record{Stem}(bin, weight)`, `read{Stem}(bin)`, and
|
|
287
|
+
* `{stem}(invocation, dispatch, bin, valid)`. Supports `bins` independent of `workgroup`, including
|
|
288
|
+
* `bins > workgroup`, and uses direct `atomicAdd` without subgroup coalescing. The single-call
|
|
289
|
+
* `{stem}` function returns bin `local` for `local < bins` (`0u` for `local >= bins`), so when
|
|
290
|
+
* `bins > workgroup`, bins `workgroup .. bins - 1` are read through `clear{Stem}`, `record{Stem}`,
|
|
291
|
+
* and `read{Stem}`. Thrown with code `ARGUMENT` for malformed options or an invalid `name`.
|
|
161
292
|
*
|
|
162
|
-
* @param
|
|
163
|
-
* @returns
|
|
293
|
+
* @param input - The histogram's workgroup count, bin count, and optional name
|
|
294
|
+
* @returns The frozen histogram fragment
|
|
164
295
|
*
|
|
165
296
|
* @example
|
|
166
297
|
* ```ts
|
|
167
|
-
*
|
|
168
|
-
* isWGSLError(new Error('The batch was aborted.')) // false
|
|
298
|
+
* createWGSLHistogram({ workgroup: 64, bins: 256 }).name // 'histogram256W64'
|
|
169
299
|
* ```
|
|
170
300
|
*/
|
|
171
|
-
export declare function
|
|
301
|
+
export declare function createWGSLHistogram(input: WGSLHistogramInput): WGSLFragment;
|
|
172
302
|
|
|
173
303
|
/**
|
|
174
|
-
*
|
|
304
|
+
* Creates a frozen workgroup or partitioned online monoid reduction fragment for `exp`, `moments`, or `compensated`.
|
|
175
305
|
*
|
|
176
306
|
* @remarks
|
|
177
|
-
*
|
|
307
|
+
* Links `WGSL_MATH` (`OnlineExp` / `mergeOnlineExp`), `WGSL_WELFORD` (`OnlineMoments` /
|
|
308
|
+
* `mergeOnlineMoments`), or `WGSL_COMPENSATED` (`CompensatedSum` / `mergeCompensatedSum`), declares
|
|
309
|
+
* `var<workgroup> {stem}Shared`, and exposes
|
|
310
|
+
* `fn {stem}(invocation: Invocation, dispatch: Dispatch, state: {State}) -> {State}`. Attaches a
|
|
311
|
+
* `linear: true` `subgroups` variant running an exact `0`-ULP top-down `subgroupShuffleXor`
|
|
312
|
+
* butterfly over the state's scalar fields (`0` barriers when `subgroup_size >= width`). Thrown
|
|
313
|
+
* with code `ARGUMENT` for malformed options, an invalid `name`, or `width > workgroup`.
|
|
178
314
|
*
|
|
179
|
-
* @param
|
|
180
|
-
* @returns
|
|
315
|
+
* @param input - The monoid reduction's workgroup count, optional partition width, monoid kind, and optional name
|
|
316
|
+
* @returns The frozen monoid reduction fragment
|
|
181
317
|
*
|
|
182
318
|
* @example
|
|
183
319
|
* ```ts
|
|
184
|
-
*
|
|
185
|
-
* isWGSLExtension('shader-f16') // false
|
|
320
|
+
* createWGSLMonoidReduce({ workgroup: 64, monoid: 'exp' }).name // 'monoidReduceExp64'
|
|
186
321
|
* ```
|
|
187
322
|
*/
|
|
188
|
-
export declare function
|
|
323
|
+
export declare function createWGSLMonoidReduce(input: WGSLMonoidReduceInput): WGSLFragment;
|
|
189
324
|
|
|
190
325
|
/**
|
|
191
|
-
*
|
|
326
|
+
* Creates a frozen workgroup or partitioned key-index pair sort fragment with deterministic ascending-index tie-breaking.
|
|
192
327
|
*
|
|
193
328
|
* @remarks
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
329
|
+
* Declares `struct {Stem}Result { value: {element}, index: u32 }`, one workgroup scratch variable
|
|
330
|
+
* `{stem}Shared`, and
|
|
331
|
+
* `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}, index: u32) -> {Stem}Result`.
|
|
332
|
+
* `width` defaults to `workgroup` and must not exceed `workgroup`; when `width < workgroup`, each
|
|
333
|
+
* contiguous `width`-lane partition sorts independently using `lane = local & (width - 1)`. Equal
|
|
334
|
+
* keys always break ties by ascending `u32` index in both `'ascending'` and `'descending'` orders.
|
|
335
|
+
* For `'f32'`, links `WGSL_ORDER`, treats `-0.0` and `+0.0` as equal keys while preserving each
|
|
336
|
+
* element's original bits in `result.value`, and places `NaN` at the end in both orders. When
|
|
337
|
+
* padding inactive `f32` lanes with a `NaN` or `±Infinity` sentinel, mask the bit pattern with a
|
|
338
|
+
* runtime input such as `bitcast<f32>(0x7fc00000u | (invocation.local_invocation_index & 0u))`
|
|
339
|
+
* (`0xff800000u` for `-Infinity`, `0x7f800000u` for `+Infinity`), because Tint rejects
|
|
340
|
+
* const-expression `NaN` and `Infinity` bitcasts. Attaches a `linear: true` `subgroups` variant
|
|
341
|
+
* running strides `< subgroup_size` in registers through `subgroupShuffleXor` (`0` barriers when
|
|
342
|
+
* `subgroup_size >= width`). Thrown with code `ARGUMENT` for malformed options, an invalid `name`,
|
|
343
|
+
* or `width > workgroup`.
|
|
344
|
+
*
|
|
345
|
+
* @param input - The pair sort's workgroup count, optional partition width, direction, key element type, and optional name
|
|
346
|
+
* @returns The frozen key-index pair sort fragment
|
|
199
347
|
*
|
|
200
348
|
* @example
|
|
201
349
|
* ```ts
|
|
202
|
-
*
|
|
203
|
-
* isWGSLGrid([0, 1, 1]) // false
|
|
350
|
+
* createWGSLPairSort({ workgroup: 128, order: 'descending', element: 'f32' }).name // 'pairSortDescendingF32128'
|
|
204
351
|
* ```
|
|
205
352
|
*/
|
|
206
|
-
export declare function
|
|
353
|
+
export declare function createWGSLPairSort(input: WGSLPairSortInput): WGSLFragment;
|
|
207
354
|
|
|
208
355
|
/**
|
|
209
|
-
*
|
|
356
|
+
* Creates a frozen workgroup stable-partition fragment returning each lane's output offset and workgroup-wide pivot.
|
|
210
357
|
*
|
|
211
|
-
* @
|
|
212
|
-
*
|
|
358
|
+
* @remarks
|
|
359
|
+
* Declares `struct {Stem}Result { offset: u32, pivot: u32 }`, one workgroup scratch variable
|
|
360
|
+
* `{stem}Shared`, and `fn {stem}(invocation: Invocation, dispatch: Dispatch, keep: bool) -> {Stem}Result`.
|
|
361
|
+
* Every lane receives the same workgroup-wide `pivot` count of kept lanes (`sgCount` when
|
|
362
|
+
* `num_subgroups == 1` on the 1D ballot path, `workgroupUniformLoad` otherwise), and `offset` maps
|
|
363
|
+
* `keep == true` lanes stably into `0 .. pivot - 1` and `keep == false` lanes stably into
|
|
364
|
+
* `pivot .. workgroup - 1`. Because WGSL static uniformity analysis taints a returned `struct`
|
|
365
|
+
* carrying per-lane `offset`, callers branching before a barrier must reload `pivot` through
|
|
366
|
+
* `workgroupUniformLoad`, or pair with `WGSL_JOIN` or `createWGSLBroadcast`. Attaches both a 1D
|
|
367
|
+
* `linear: true` direct `subgroupBallot` variant (`0` barriers when `num_subgroups == 1`) and a
|
|
368
|
+
* 2D-safe remapped `subgroupBallot` variant requiring `subgroup_id`, clamping every ballot mask to
|
|
369
|
+
* `activeSg = min(dispatch.subgroup_size, workgroup)` across `subgroup_size <= 32` and `vec4u`
|
|
370
|
+
* paths. Thrown with code `ARGUMENT` for malformed options or an invalid `name`.
|
|
371
|
+
*
|
|
372
|
+
* @param input - The partition's workgroup count and optional name
|
|
373
|
+
* @returns The frozen stable-partition fragment
|
|
213
374
|
*
|
|
214
375
|
* @example
|
|
215
376
|
* ```ts
|
|
216
|
-
*
|
|
217
|
-
* isWGSLScalar('f64') // false
|
|
377
|
+
* createWGSLPartition({ workgroup: 256 }).name // 'partition256'
|
|
218
378
|
* ```
|
|
219
379
|
*/
|
|
220
|
-
export declare function
|
|
380
|
+
export declare function createWGSLPartition(input: WGSLPartitionInput): WGSLFragment;
|
|
221
381
|
|
|
222
382
|
/**
|
|
223
|
-
*
|
|
383
|
+
* Creates a frozen workgroup lane-gather permutation fragment.
|
|
224
384
|
*
|
|
225
385
|
* @remarks
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* `
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
* the input struct as `invocation`. A fragment's variant is active when `extensions` switches its
|
|
233
|
-
* extension on.
|
|
386
|
+
* Declares `var<workgroup> {stem}Shared: array<{element}, {workgroup}>` and
|
|
387
|
+
* `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}, index: u32) -> {element}`.
|
|
388
|
+
* Clamps `index` with `min(index, workgroup - 1)`. Attaches a `linear: true` `subgroups` variant
|
|
389
|
+
* returning `subgroupShuffle(value, min(index, workgroup - 1))` in `0` barriers when
|
|
390
|
+
* `dispatch.subgroup_size >= workgroup` and falling back to a 2-barrier shared-memory gather
|
|
391
|
+
* otherwise. Thrown with code `ARGUMENT` for malformed options or an invalid `name`.
|
|
234
392
|
*
|
|
235
|
-
* @param
|
|
236
|
-
* @
|
|
237
|
-
* @returns The WGSL text, ending in a line feed
|
|
393
|
+
* @param input - The permutation's workgroup count, element type, and optional name
|
|
394
|
+
* @returns The frozen lane-gather fragment
|
|
238
395
|
*
|
|
239
396
|
* @example
|
|
240
397
|
* ```ts
|
|
241
|
-
*
|
|
398
|
+
* createWGSLPermute({ workgroup: 128, element: 'f32' }).name // 'permuteF32128'
|
|
242
399
|
* ```
|
|
243
400
|
*/
|
|
244
|
-
export declare function
|
|
401
|
+
export declare function createWGSLPermute(input: WGSLPermuteInput): WGSLFragment;
|
|
245
402
|
|
|
246
403
|
/**
|
|
247
|
-
*
|
|
404
|
+
* Creates a frozen compute program and links every fragment its entry body reaches.
|
|
248
405
|
*
|
|
249
406
|
* @remarks
|
|
250
|
-
*
|
|
407
|
+
* The slots keep their declaration order, which is their binding order. Module-scope WGSL names
|
|
408
|
+
* (`entry.name`, `uniform.name`, every slot key, and every override key) must pass
|
|
409
|
+
* `isWGSLIdentifier`. Atomic storage elements (`'atomic<u32>'` and `'atomic<i32>'`) require
|
|
410
|
+
* `'read_write'` access. Pipeline-overridable constants validate their scalar type, optional default
|
|
411
|
+
* value, and optional unique `@id(N)` integer from `0` to `65535`. Thrown with code `ARGUMENT` for
|
|
412
|
+
* any invalid declaration and with code `VALIDATION` for duplicate fragment names, cycles, or
|
|
413
|
+
* mismatched fragment `workgroup` counts.
|
|
414
|
+
*
|
|
415
|
+
* @param input - The program's name, entry, slots, uniform, optional overrides, and used fragments
|
|
416
|
+
* @returns The program, frozen
|
|
251
417
|
*
|
|
252
418
|
* @example
|
|
253
419
|
* ```ts
|
|
254
|
-
*
|
|
420
|
+
* createWGSLProgram({ name: 'clear', entry, slots, uniform }).fragments // []
|
|
255
421
|
* ```
|
|
256
422
|
*/
|
|
257
|
-
export declare
|
|
423
|
+
export declare function createWGSLProgram<S extends WGSLSlotMap, F extends WGSLFieldMap, O extends WGSLOverrideMap = Readonly<Record<never, WGSLOverride>>>(input: WGSLProgramInput<S, F, O>): WGSLProgram<S, F, O>;
|
|
258
424
|
|
|
259
425
|
/**
|
|
260
|
-
*
|
|
426
|
+
* Creates a frozen workgroup 4-bit radix-rank fragment returning each lane's sorted offset, in-digit rank, and per-digit count.
|
|
261
427
|
*
|
|
262
428
|
* @remarks
|
|
263
|
-
*
|
|
264
|
-
*
|
|
429
|
+
* Declares `struct {Stem}Result { offset: u32, rank: u32, count: u32 }`, one workgroup scratch
|
|
430
|
+
* variable `{stem}Shared`, and
|
|
431
|
+
* `fn {stem}(invocation: Invocation, dispatch: Dispatch, digit: u32) -> {Stem}Result`. Masks
|
|
432
|
+
* `digit` with `& 15u`; `offset` and `rank` belong to the lane's own masked digit, while `count`
|
|
433
|
+
* holds the workgroup's total count for digit `local & 15u` (giving lanes `0..15` the 16-bin
|
|
434
|
+
* histogram directly). The 2D-safe base runs a deterministic `16`-lane tile scan (`4` barriers, `0`
|
|
435
|
+
* atomics); the `linear: true` `subgroups` + `subgroup_id` variant uses 4-bit `subgroupBallot`
|
|
436
|
+
* warp-level multi-split (WLMS) peer masks clamped to `activeSg = min(dispatch.subgroup_size, workgroup)`
|
|
437
|
+
* across `subgroup_size <= 32` and `vec4u` paths. Thrown with code `ARGUMENT` for malformed options
|
|
438
|
+
* or an invalid `name`.
|
|
439
|
+
*
|
|
440
|
+
* @param input - The radix rank's workgroup count and optional name
|
|
441
|
+
* @returns The frozen 4-bit radix-rank fragment
|
|
265
442
|
*
|
|
266
443
|
* @example
|
|
267
444
|
* ```ts
|
|
268
|
-
*
|
|
445
|
+
* createWGSLRadixRank({ workgroup: 256 }).name // 'radixRank256'
|
|
269
446
|
* ```
|
|
270
447
|
*/
|
|
271
|
-
export declare
|
|
448
|
+
export declare function createWGSLRadixRank(input: WGSLRadixRankInput): WGSLFragment;
|
|
272
449
|
|
|
273
450
|
/**
|
|
274
|
-
*
|
|
451
|
+
* Creates a frozen workgroup or partitioned reduction fragment for `sum`, `max`, `min`, `and`, `or`, `xor`, or `mul`.
|
|
275
452
|
*
|
|
276
453
|
* @remarks
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
* `
|
|
454
|
+
* Declares `var<workgroup> {stem}Shared` and
|
|
455
|
+
* `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}) -> {element}`, setting
|
|
456
|
+
* `workgroup` so `createWGSLProgram` refuses an entry of another invocation count. When `reordered`
|
|
457
|
+
* is `false` (the default), attaches a `linear: true` `subgroups` variant running an exact top-down
|
|
458
|
+
* `subgroupShuffleXor` butterfly (`0` ULP vs the 2D-safe halving tree, `0` barriers when
|
|
459
|
+
* `subgroup_size >= width`). When `reordered` is `true`, attaches a `linear: true` `subgroups`
|
|
460
|
+
* collective variant (and a 2D-safe `subgroup_id` variant when `width === workgroup`) seeded from
|
|
461
|
+
* lane 0 without synthetic identity constants, preserving `±Infinity` and `-0.0`. Thrown with code
|
|
462
|
+
* `ARGUMENT` for malformed options, a non-identifier `name`, `width > workgroup`, or bitwise
|
|
463
|
+
* operations (`and`, `or`, `xor`) paired with floating-point elements (`f32`, `vec2f`, `vec4f`).
|
|
464
|
+
*
|
|
465
|
+
* @param input - The reduction's workgroup count, optional partition width, operation, element type, and optional name and reordering flag
|
|
466
|
+
* @returns The frozen reduction fragment
|
|
280
467
|
*
|
|
281
468
|
* @example
|
|
282
469
|
* ```ts
|
|
283
|
-
*
|
|
470
|
+
* createWGSLReduce({ workgroup: 256, width: 32, operation: 'sum', element: 'f32' }).name // 'reduceSumF32256Width32'
|
|
284
471
|
* ```
|
|
285
472
|
*/
|
|
286
|
-
export declare
|
|
473
|
+
export declare function createWGSLReduce(input: WGSLReduceInput): WGSLFragment;
|
|
287
474
|
|
|
288
475
|
/**
|
|
289
|
-
*
|
|
476
|
+
* Creates a frozen work-efficient workgroup prefix or suffix scan fragment for any reduction operation.
|
|
290
477
|
*
|
|
291
478
|
* @remarks
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
479
|
+
* Declares one workgroup variable `{stem}Shared` and
|
|
480
|
+
* `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}) -> {element}`. The
|
|
481
|
+
* 2D-safe base uses trimmed Blelloch (removing the dead final up-sweep iteration and zeroing
|
|
482
|
+
* barrier). For associative exact scans (`u32` and `i32` on all operations, `f32` on `max`/`min`),
|
|
483
|
+
* attaches both a 1D `linear: true` direct subgroup variant and a 2D-safe remapped subgroup variant
|
|
484
|
+
* requiring `subgroup_id`; for floating-point `sum` and `mul`, attaches those variants only when
|
|
485
|
+
* `reordered: true`. For `f32` `max` and `min` scans, neutral carry slots use runtime `±Infinity`
|
|
486
|
+
* and exclusive logical slot `0` maps to the finite `WGSL_REDUCE_IDENTITIES` boundary so the base
|
|
487
|
+
* Blelloch, 1D direct, and 2D remapped variants stay bit-identical on `±Infinity` prefixes. Thrown
|
|
488
|
+
* with code `ARGUMENT` for malformed options, an invalid `name`, or bitwise operations (`and`,
|
|
489
|
+
* `or`, `xor`) paired with `'f32'`.
|
|
490
|
+
*
|
|
491
|
+
* @param input - The scan's workgroup count, element type, and optional operation, direction, exclusivity, reordering, and name
|
|
492
|
+
* @returns The frozen scan fragment
|
|
295
493
|
*
|
|
296
494
|
* @example
|
|
297
495
|
* ```ts
|
|
298
|
-
*
|
|
496
|
+
* createWGSLScan({ workgroup: 256, element: 'u32', exclusive: true }).name // 'scanExclusiveU32256'
|
|
299
497
|
* ```
|
|
300
498
|
*/
|
|
301
|
-
export declare
|
|
302
|
-
readonly f16: 'shader-f16';
|
|
303
|
-
readonly subgroups: 'subgroups';
|
|
304
|
-
}>;
|
|
499
|
+
export declare function createWGSLScan(input: WGSLScanInput): WGSLFragment;
|
|
305
500
|
|
|
306
501
|
/**
|
|
307
|
-
*
|
|
502
|
+
* Creates a frozen workgroup segmented reduction fragment delivering each segment's total at its head lane.
|
|
308
503
|
*
|
|
309
504
|
* @remarks
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
505
|
+
* Declares `struct {Stem}Result { value: {element}, valid: bool }`, one workgroup scratch variable
|
|
506
|
+
* `{stem}Shared`, and
|
|
507
|
+
* `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}, head: bool) -> {Stem}Result`.
|
|
508
|
+
* Lane `0` always starts a segment (`local == 0u || head`). Every segment head receives its full
|
|
509
|
+
* segment reduction with `valid: true`, and non-head lanes receive their own input with
|
|
510
|
+
* `valid: false`, using `0` synthetic identity constants so `±Infinity`, `-0.0`, `vec2f`, and
|
|
511
|
+
* `vec4f` remain exact. When padding inactive `f32` lanes with a `NaN` or `±Infinity` sentinel,
|
|
512
|
+
* mask the bit pattern with a runtime input such as
|
|
513
|
+
* `bitcast<f32>(0x7fc00000u | (invocation.local_invocation_index & 0u))` (`0xff800000u` for
|
|
514
|
+
* `-Infinity`, `0x7f800000u` for `+Infinity`), because Tint rejects const-expression `NaN` and
|
|
515
|
+
* `Infinity` bitcasts. For associative exact operations (`u32` and `i32` on all operations,
|
|
516
|
+
* floating-point elements on `max`/`min`), attaches both a 1D `linear: true` direct subgroup
|
|
517
|
+
* variant and a 2D-safe remapped subgroup variant requiring `subgroup_id`; for floating-point `sum`
|
|
518
|
+
* and `mul`, attaches those variants only when `reordered: true`. Thrown with code `ARGUMENT` for
|
|
519
|
+
* malformed options, an invalid `name`, or bitwise operations (`and`, `or`, `xor`) paired with
|
|
520
|
+
* floating-point elements (`f32`, `vec2f`, `vec4f`).
|
|
521
|
+
*
|
|
522
|
+
* @param input - The segmented reduction's workgroup count, operation, element type, and optional reordering and name
|
|
523
|
+
* @returns The frozen segmented reduction fragment
|
|
316
524
|
*
|
|
317
525
|
* @example
|
|
318
526
|
* ```ts
|
|
319
|
-
*
|
|
527
|
+
* createWGSLSegmentedReduce({ workgroup: 256, operation: 'sum', element: 'f32' }).name // 'segmentedReduceSumF32256'
|
|
320
528
|
* ```
|
|
321
529
|
*/
|
|
322
|
-
export declare
|
|
530
|
+
export declare function createWGSLSegmentedReduce(input: WGSLSegmentedReduceInput): WGSLFragment;
|
|
323
531
|
|
|
324
532
|
/**
|
|
325
|
-
*
|
|
533
|
+
* Creates a frozen workgroup segmented prefix scan fragment for any reduction operation.
|
|
326
534
|
*
|
|
327
535
|
* @remarks
|
|
328
|
-
*
|
|
536
|
+
* Declares one workgroup scratch variable `{stem}Shared` and
|
|
537
|
+
* `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}, head: bool) -> {element}`.
|
|
538
|
+
* Lane `0` always starts a segment (`local == 0u || head`). When `exclusive` is `true`, every
|
|
539
|
+
* segment head returns its finite identity from `WGSL_REDUCE_IDENTITIES` (finite `±FLT_MAX`,
|
|
540
|
+
* `±3.4028234663852886e38`, for `f32` `max` and `min`), while internal neutral carry slots use
|
|
541
|
+
* runtime `±Infinity` across reductions so all-`±Infinity` segments remain exact. When padding
|
|
542
|
+
* inactive `f32` lanes with a `NaN` or `±Infinity` sentinel, mask the bit pattern with a runtime
|
|
543
|
+
* input such as `bitcast<f32>(0x7fc00000u | (invocation.local_invocation_index & 0u))`
|
|
544
|
+
* (`0xff800000u` for `-Infinity`, `0x7f800000u` for `+Infinity`), because Tint rejects
|
|
545
|
+
* const-expression `NaN` and `Infinity` bitcasts. For associative exact operations (`u32` and `i32`
|
|
546
|
+
* on all operations, `f32` on `max`/`min`), attaches both a 1D `linear: true` direct subgroup
|
|
547
|
+
* variant and a 2D-safe remapped subgroup variant requiring `subgroup_id`; for floating-point `sum`
|
|
548
|
+
* and `mul`, attaches those variants only when `reordered: true`. Thrown with code `ARGUMENT` for
|
|
549
|
+
* malformed options, an invalid `name`, or bitwise operations (`and`, `or`, `xor`) paired with
|
|
550
|
+
* `'f32'`.
|
|
551
|
+
*
|
|
552
|
+
* @param input - The segmented scan's workgroup count, element type, and optional operation, exclusivity, reordering, and name
|
|
553
|
+
* @returns The frozen segmented scan fragment
|
|
329
554
|
*
|
|
330
555
|
* @example
|
|
331
556
|
* ```ts
|
|
332
|
-
*
|
|
557
|
+
* createWGSLSegmentedScan({ workgroup: 256, element: 'f32', exclusive: true }).name // 'segmentedScanExclusiveF32256'
|
|
333
558
|
* ```
|
|
334
559
|
*/
|
|
335
|
-
export declare
|
|
336
|
-
readonly read: 1;
|
|
337
|
-
readonly write: 2;
|
|
338
|
-
}>;
|
|
560
|
+
export declare function createWGSLSegmentedScan(input: WGSLSegmentedScanInput): WGSLFragment;
|
|
339
561
|
|
|
340
562
|
/**
|
|
341
|
-
*
|
|
563
|
+
* Creates an open session that prepares programs and runs batches on a borrowed device.
|
|
342
564
|
*
|
|
343
565
|
* @remarks
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
566
|
+
* The session never requests or destroys the device; its `destroy` releases only the buffers it
|
|
567
|
+
* created. Thrown with code `ARGUMENT` when `options` is malformed, when `uniform.size` is not a
|
|
568
|
+
* positive safe multiple of 4, when `trace.mode` is outside `WGSL_TRACE_MODES`, or when
|
|
569
|
+
* `trace.capacity` is outside integers 1 to 2048.
|
|
570
|
+
*
|
|
571
|
+
* @param device - The device the session borrows
|
|
572
|
+
* @param options - The extensions to switch off, host language features, uniform slab size, and optional tracer settings
|
|
573
|
+
* @returns The session
|
|
352
574
|
*
|
|
353
575
|
* @example
|
|
354
576
|
* ```ts
|
|
355
|
-
*
|
|
577
|
+
* const session = createWGSLSession(device, { extensions: { f16: false } })
|
|
578
|
+
* session.status // 'open'
|
|
356
579
|
* ```
|
|
357
580
|
*/
|
|
358
|
-
export declare
|
|
581
|
+
export declare function createWGSLSession(device: GPUDevice, options?: WGSLSessionOptions): WGSLSessionInterface;
|
|
359
582
|
|
|
360
583
|
/**
|
|
361
|
-
*
|
|
584
|
+
* Creates a frozen workgroup or partitioned bitonic sort fragment in `'ascending'` or `'descending'` order.
|
|
362
585
|
*
|
|
363
586
|
* @remarks
|
|
364
|
-
*
|
|
365
|
-
* `invocation
|
|
366
|
-
*
|
|
367
|
-
* `
|
|
368
|
-
*
|
|
587
|
+
* Declares one 4-byte-per-lane shared array `var<workgroup> {stem}Shared` and
|
|
588
|
+
* `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}) -> {element}`. `width`
|
|
589
|
+
* defaults to `workgroup` and must not exceed `workgroup`; when `width < workgroup`, each
|
|
590
|
+
* contiguous `width`-lane partition sorts independently using `lane = local & (width - 1)`. For
|
|
591
|
+
* `'f32'`, links `WGSL_ORDER` and sorts invertible total-order `u32` keys so `-0.0` stays distinct
|
|
592
|
+
* from `+0.0` and `NaN` always lands at the end of both `'ascending'` and `'descending'` outputs.
|
|
593
|
+
* When padding inactive `f32` lanes with a `NaN` or `±Infinity` sentinel, mask the bit pattern with
|
|
594
|
+
* a runtime input such as `bitcast<f32>(0x7fc00000u | (invocation.local_invocation_index & 0u))`
|
|
595
|
+
* (`0xff800000u` for `-Infinity`, `0x7f800000u` for `+Infinity`), because Tint rejects
|
|
596
|
+
* const-expression `NaN` and `Infinity` bitcasts. Attaches a `linear: true` `subgroups` variant
|
|
597
|
+
* running all strides `< subgroup_size` in registers through `subgroupShuffleXor` (`0` barriers
|
|
598
|
+
* when `subgroup_size >= width`). Thrown with code `ARGUMENT` for malformed options, an invalid
|
|
599
|
+
* `name`, or `width > workgroup`.
|
|
600
|
+
*
|
|
601
|
+
* @param input - The sort's workgroup count, optional partition width, direction, element type, and optional name
|
|
602
|
+
* @returns The frozen sort fragment
|
|
369
603
|
*
|
|
370
604
|
* @example
|
|
371
605
|
* ```ts
|
|
372
|
-
*
|
|
606
|
+
* createWGSLSort({ workgroup: 128, order: 'ascending', element: 'u32' }).name // 'sortAscendingU32128'
|
|
373
607
|
* ```
|
|
374
608
|
*/
|
|
375
|
-
export declare
|
|
609
|
+
export declare function createWGSLSort(input: WGSLSortInput): WGSLFragment;
|
|
376
610
|
|
|
377
611
|
/**
|
|
378
|
-
*
|
|
612
|
+
* Creates a frozen uniform struct with its scalar layout and its rendered WGSL declaration.
|
|
379
613
|
*
|
|
380
614
|
* @remarks
|
|
381
|
-
* Each
|
|
615
|
+
* Each `u32`, `i32`, and `f32` member aligns to 4 bytes and takes 4 bytes in the `uniform` address
|
|
616
|
+
* space, so members sit in declaration order and the struct's size is the member count times 4.
|
|
617
|
+
* The struct `name` must pass `isWGSLIdentifier`; field names sit in struct member scope rather than
|
|
618
|
+
* module scope, so member names such as `length` are admitted without module-scope identifier
|
|
619
|
+
* rejection. Thrown with code `ARGUMENT` when `name` is not a valid WGSL identifier, when `fields`
|
|
620
|
+
* is not a plain record or declares no field, and when a field names a type outside `WGSL_SCALARS`;
|
|
621
|
+
* `context.fields` lists each such field.
|
|
622
|
+
*
|
|
623
|
+
* @param name - The struct's WGSL name
|
|
624
|
+
* @param fields - Each field's scalar type, in declaration order
|
|
625
|
+
* @returns The struct, frozen
|
|
382
626
|
*
|
|
383
627
|
* @example
|
|
384
628
|
* ```ts
|
|
385
|
-
*
|
|
629
|
+
* createWGSLStruct('Shape', { rows: 'u32', epsilon: 'f32' }).offsets // { rows: 0, epsilon: 4 }
|
|
386
630
|
* ```
|
|
387
631
|
*/
|
|
388
|
-
export declare
|
|
632
|
+
export declare function createWGSLStruct<F extends WGSLFieldMap>(name: string, fields: F): WGSLStruct<F>;
|
|
389
633
|
|
|
390
634
|
/**
|
|
391
|
-
*
|
|
635
|
+
* Creates a frozen shared-memory tile transpose fragment linking `WGSL_TILE`.
|
|
392
636
|
*
|
|
393
637
|
* @remarks
|
|
394
|
-
* `
|
|
638
|
+
* Always sets `workgroup: 256` and takes `(invocation: Invocation, dispatch: Dispatch, ...)`:
|
|
639
|
+
* `tile: 16` uses `swizzleTileIndex` over a 256-element shared array (1 element per invocation),
|
|
640
|
+
* while `tile: 32` uses `computeTileIndex` over a 1056-element padded shared array (`vec4<{element}>`
|
|
641
|
+
* carrying 4 rows per invocation across 8 bands). Thrown with code `ARGUMENT` for malformed options
|
|
642
|
+
* or an invalid `name`.
|
|
643
|
+
*
|
|
644
|
+
* @param input - The transpose's tile side length (`16 | 32`), element type, and optional name
|
|
645
|
+
* @returns The frozen tile transpose fragment, linking `WGSL_TILE`
|
|
395
646
|
*
|
|
396
647
|
* @example
|
|
397
648
|
* ```ts
|
|
398
|
-
*
|
|
649
|
+
* createWGSLTranspose({ tile: 32, element: 'f32' }).workgroup // 256
|
|
399
650
|
* ```
|
|
400
651
|
*/
|
|
401
|
-
export declare
|
|
402
|
-
readonly compute: 4;
|
|
403
|
-
}>;
|
|
652
|
+
export declare function createWGSLTranspose(input: WGSLTransposeInput): WGSLFragment;
|
|
404
653
|
|
|
405
654
|
/**
|
|
406
|
-
*
|
|
655
|
+
* Decodes a `WGSLFloatPair` back into an IEEE-754 `f64` number as `pair.head + pair.tail`.
|
|
407
656
|
*
|
|
408
657
|
* @remarks
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
* and `0.0` elsewhere, and invocation 0 adds the 64 entries in index order between 2 barriers, so
|
|
415
|
-
* its rounding order differs from the default body's. It reads no binding and no uniform member.
|
|
658
|
+
* Validates `pair` with `isWGSLFloatPair` so non-records, missing or extra keys, non-numbers, and
|
|
659
|
+
* finite values past `±3.4028234663852886e38` throw with code `ARGUMENT`.
|
|
660
|
+
*
|
|
661
|
+
* @param pair - The float pair to sum
|
|
662
|
+
* @returns The combined `f64` value
|
|
416
663
|
*
|
|
417
664
|
* @example
|
|
418
665
|
* ```ts
|
|
419
|
-
*
|
|
666
|
+
* decodeWGSLDouble(encodeWGSLDouble(Math.PI)) // 3.1415926535897967
|
|
420
667
|
* ```
|
|
421
668
|
*/
|
|
422
|
-
export declare
|
|
669
|
+
export declare function decodeWGSLDouble(pair: WGSLFloatPair): number;
|
|
423
670
|
|
|
424
671
|
/**
|
|
425
|
-
*
|
|
672
|
+
* Decodes an order-preserving `u32` key back to its `f32` value, as `decodeFloatOrder` in `WGSL_ORDER` does.
|
|
426
673
|
*
|
|
427
674
|
* @remarks
|
|
428
|
-
*
|
|
429
|
-
*
|
|
675
|
+
* Inverts `encodeWGSLFloatOrder` bit-for-bit across all non-NaN `f32` values (including `-0` and
|
|
676
|
+
* `+0`) and returns `NaN` for NaN keys. Thrown with code `ARGUMENT` when `bits` is not an integer
|
|
677
|
+
* from `0` to `0xffffffff`.
|
|
678
|
+
*
|
|
679
|
+
* @param bits - The order-preserving unsigned 32-bit key
|
|
680
|
+
* @returns The decoded `f32` value
|
|
430
681
|
*
|
|
431
682
|
* @example
|
|
432
683
|
* ```ts
|
|
433
|
-
*
|
|
684
|
+
* decodeWGSLFloatOrder(encodeWGSLFloatOrder(-1.5)) // -1.5
|
|
434
685
|
* ```
|
|
435
686
|
*/
|
|
436
|
-
export declare
|
|
687
|
+
export declare function decodeWGSLFloatOrder(bits: number): number;
|
|
437
688
|
|
|
438
689
|
/**
|
|
439
|
-
*
|
|
690
|
+
* Decodes a 32-bit Morton Z-order code into 16-bit 2D grid coordinates, as `decodeMorton2` in `WGSL_MORTON` does.
|
|
440
691
|
*
|
|
441
692
|
* @remarks
|
|
442
|
-
* `
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
693
|
+
* Inverts `encodeWGSLMorton2` across all 32-bit codes. Thrown with code `ARGUMENT` when `code` is
|
|
694
|
+
* not an unsigned 32-bit integer from `0` to `0xffffffff`, `-0` included.
|
|
695
|
+
*
|
|
696
|
+
* @param code - The 32-bit unsigned Morton code
|
|
697
|
+
* @returns The decoded `[x, y]` coordinate pair, frozen
|
|
446
698
|
*
|
|
447
699
|
* @example
|
|
448
700
|
* ```ts
|
|
449
|
-
*
|
|
701
|
+
* decodeWGSLMorton2(9) // [1, 2]
|
|
450
702
|
* ```
|
|
451
703
|
*/
|
|
452
|
-
export declare
|
|
453
|
-
readonly read: 1;
|
|
454
|
-
readonly write: 2;
|
|
455
|
-
readonly source: 4;
|
|
456
|
-
readonly destination: 8;
|
|
457
|
-
readonly uniform: 64;
|
|
458
|
-
readonly storage: 128;
|
|
459
|
-
readonly indirect: 256;
|
|
460
|
-
readonly query: 512;
|
|
461
|
-
}>;
|
|
704
|
+
export declare function decodeWGSLMorton2(code: number): readonly [number, number];
|
|
462
705
|
|
|
463
706
|
/**
|
|
464
|
-
*
|
|
707
|
+
* Decodes a 32-bit Morton Z-order code into 10-bit 3D grid coordinates, as `decodeMorton3` in `WGSL_MORTON` does.
|
|
708
|
+
*
|
|
709
|
+
* @remarks
|
|
710
|
+
* Reads the low 30 interleaved bits into `[x, y, z]`, inverting `encodeWGSLMorton3`. Thrown with
|
|
711
|
+
* code `ARGUMENT` when `code` is not an unsigned 32-bit integer from `0` to `0xffffffff`, `-0`
|
|
712
|
+
* included.
|
|
713
|
+
*
|
|
714
|
+
* @param code - The 32-bit unsigned Morton code
|
|
715
|
+
* @returns The decoded `[x, y, z]` coordinate triple, frozen
|
|
465
716
|
*
|
|
466
717
|
* @example
|
|
467
718
|
* ```ts
|
|
468
|
-
*
|
|
719
|
+
* decodeWGSLMorton3(53) // [1, 2, 3]
|
|
469
720
|
* ```
|
|
470
721
|
*/
|
|
471
|
-
export declare
|
|
722
|
+
export declare function decodeWGSLMorton3(code: number): readonly [number, number, number];
|
|
472
723
|
|
|
473
724
|
/**
|
|
474
|
-
*
|
|
725
|
+
* Divides two complex numbers using overflow-safe Smith division, as `divideComplex` in `WGSL_COMPLEX` does.
|
|
475
726
|
*
|
|
476
727
|
* @remarks
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
* moves the session to `failed` with code `VALIDATION`. `read` resolves after the submission to a
|
|
485
|
-
* caller-owned copy of the bytes. Thrown with code `VALIDATION` when a call other than `abort` or
|
|
486
|
-
* `execute` arrives after `submit` or `abort`; with code `ARGUMENT` for a malformed grid or read
|
|
487
|
-
* range; and with code `LIMIT` when a grid axis passes the device's
|
|
488
|
-
* `maxComputeWorkgroupsPerDimension`. Open a batch through `session.batch()`, which supplies the
|
|
489
|
-
* options.
|
|
728
|
+
* Prescales operands near the `f64` overflow threshold so finite quotients up to `±Number.MAX_VALUE`
|
|
729
|
+
* avoid intermediate overflow. Thrown with code `ARGUMENT` when `left` or `right` is not a dense
|
|
730
|
+
* 2-tuple of numbers.
|
|
731
|
+
*
|
|
732
|
+
* @param left - The dividend `(real, imaginary)`
|
|
733
|
+
* @param right - The divisor `(real, imaginary)`
|
|
734
|
+
* @returns The quotient `(real, imaginary)`, frozen
|
|
490
735
|
*
|
|
491
736
|
* @example
|
|
492
737
|
* ```ts
|
|
493
|
-
*
|
|
494
|
-
* batch.encode(binding, { count: 64 }, [1, 1, 1])
|
|
495
|
-
* const bytes = batch.read(buffer, 0, 256)
|
|
496
|
-
* await batch.execute()
|
|
497
|
-
* new Uint32Array(await bytes)[0] // the first word the dispatch wrote
|
|
738
|
+
* divideWGSLComplex([4, 2], [1, 1]) // [3, -1]
|
|
498
739
|
* ```
|
|
499
740
|
*/
|
|
500
|
-
export declare
|
|
501
|
-
#private;
|
|
502
|
-
/**
|
|
503
|
-
* Creates an open batch with a fresh command encoder.
|
|
504
|
-
*
|
|
505
|
-
* @param device - The device whose encoder records the commands and whose queue runs them
|
|
506
|
-
* @param options - The session's slab and the session hooks
|
|
507
|
-
*/
|
|
508
|
-
constructor(device: GPUDevice, options: WGSLBatchOptions);
|
|
509
|
-
get submitted(): boolean;
|
|
510
|
-
encode<S extends WGSLSlotMap, F extends WGSLFieldMap>(binding: WGSLBinding<S, F>, values: WGSLValueMap<F>, grid: WGSLGrid): void;
|
|
511
|
-
read(buffer: GPUBuffer, offset: number, size: number): Promise<ArrayBuffer>;
|
|
512
|
-
submit(): void;
|
|
513
|
-
execute(signal?: AbortSignal): Promise<void>;
|
|
514
|
-
abort(): void;
|
|
515
|
-
}
|
|
741
|
+
export declare function divideWGSLComplex(left: readonly [number, number], right: readonly [number, number]): readonly [number, number];
|
|
516
742
|
|
|
517
743
|
/**
|
|
518
|
-
*
|
|
744
|
+
* Encodes an IEEE-754 `f64` number into a frozen `WGSLFloatPair` (`head`, `tail`) for `WGSL_DOUBLE`.
|
|
745
|
+
*
|
|
746
|
+
* @remarks
|
|
747
|
+
* Sets `head = Math.fround(value)` and `tail = Math.fround(value - head)` for finite `f32` heads.
|
|
748
|
+
* Non-finite heads (`±Infinity`, `NaN`, and finite values past the `f32` overflow threshold) set
|
|
749
|
+
* `tail` to `0` so `decodeWGSLDouble` recovers `head` without `Infinity - Infinity` cancellation;
|
|
750
|
+
* `-0` encodes as `{ head: -0, tail: -0 }` so `-0` round-trips through `decodeWGSLDouble`. Thrown
|
|
751
|
+
* with code `ARGUMENT` when `value` is not a number.
|
|
752
|
+
*
|
|
753
|
+
* @param value - The double-precision number to split
|
|
754
|
+
* @returns The frozen `{ head, tail }` pair
|
|
519
755
|
*
|
|
520
756
|
* @example
|
|
521
757
|
* ```ts
|
|
522
|
-
*
|
|
758
|
+
* encodeWGSLDouble(1.5) // { head: 1.5, tail: 0 }
|
|
523
759
|
* ```
|
|
524
760
|
*/
|
|
525
|
-
export declare
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
761
|
+
export declare function encodeWGSLDouble(value: number): WGSLFloatPair;
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Encodes an `f32` value into an order-preserving `u32` key, as `encodeFloatOrder` in `WGSL_ORDER` does.
|
|
765
|
+
*
|
|
766
|
+
* @remarks
|
|
767
|
+
* Rounds `value` to `f32`, canonicalizes every `NaN` to quiet `0x7fc00000` (encoded as
|
|
768
|
+
* `0xffc00000`), and maps IEEE-754 total order (`-Infinity < ... < -0.0 < +0.0 < ... < +Infinity`)
|
|
769
|
+
* bijectively into `u32` unsigned order. Thrown with code `ARGUMENT` when `value` is not a number.
|
|
770
|
+
*
|
|
771
|
+
* @param value - The floating-point value to encode
|
|
772
|
+
* @returns The order-preserving unsigned 32-bit key
|
|
773
|
+
*
|
|
774
|
+
* @example
|
|
775
|
+
* ```ts
|
|
776
|
+
* encodeWGSLFloatOrder(-0) < encodeWGSLFloatOrder(0) // true
|
|
777
|
+
* ```
|
|
778
|
+
*/
|
|
779
|
+
export declare function encodeWGSLFloatOrder(value: number): number;
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Encodes a 16-bit 2D grid coordinate into a 32-bit Morton Z-order code, as `encodeMorton2` in `WGSL_MORTON` does.
|
|
783
|
+
*
|
|
784
|
+
* @remarks
|
|
785
|
+
* Interleaves `x` into even bits and `y` into odd bits. Thrown with code `ARGUMENT` when `x` or
|
|
786
|
+
* `y` is not a non-negative integer from `0` to `65535`, `-0` included.
|
|
787
|
+
*
|
|
788
|
+
* @param x - The 16-bit unsigned x coordinate
|
|
789
|
+
* @param y - The 16-bit unsigned y coordinate
|
|
790
|
+
* @returns The 32-bit unsigned Morton code
|
|
791
|
+
*
|
|
792
|
+
* @example
|
|
793
|
+
* ```ts
|
|
794
|
+
* encodeWGSLMorton2(1, 2) // 9
|
|
795
|
+
* ```
|
|
796
|
+
*/
|
|
797
|
+
export declare function encodeWGSLMorton2(x: number, y: number): number;
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* Encodes a 10-bit 3D grid coordinate into a 30-bit Morton Z-order code, as `encodeMorton3` in `WGSL_MORTON` does.
|
|
801
|
+
*
|
|
802
|
+
* @remarks
|
|
803
|
+
* Interleaves `x`, `y`, and `z` into bit lanes `3k`, `3k + 1`, and `3k + 2`. Thrown with code
|
|
804
|
+
* `ARGUMENT` when `x`, `y`, or `z` is not a non-negative integer from `0` to `1023`, `-0` included.
|
|
805
|
+
*
|
|
806
|
+
* @param x - The 10-bit unsigned x coordinate
|
|
807
|
+
* @param y - The 10-bit unsigned y coordinate
|
|
808
|
+
* @param z - The 10-bit unsigned z coordinate
|
|
809
|
+
* @returns The 30-bit unsigned Morton code
|
|
810
|
+
*
|
|
811
|
+
* @example
|
|
812
|
+
* ```ts
|
|
813
|
+
* encodeWGSLMorton3(1, 2, 3) // 53
|
|
814
|
+
* ```
|
|
815
|
+
*/
|
|
816
|
+
export declare function encodeWGSLMorton3(x: number, y: number, z: number): number;
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* Inverts a column-major `3x3` matrix, as `invertMatrix3` in `WGSL_MATRIX` does.
|
|
820
|
+
*
|
|
821
|
+
* @remarks
|
|
822
|
+
* Reads the 9-tuple in WGSL `mat3x3f` column-major order (`[c0.x, c0.y, c0.z, c1.x, c1.y, c1.z,
|
|
823
|
+
* c2.x, c2.y, c2.z]`). Singular inputs produce non-finite components from division by zero,
|
|
824
|
+
* matching `invertMatrix3`. Thrown with code `ARGUMENT` when `elements` is not a dense 9-tuple of
|
|
825
|
+
* numbers.
|
|
826
|
+
*
|
|
827
|
+
* @param elements - The column-major 9-tuple of matrix entries
|
|
828
|
+
* @returns The column-major 9-tuple of inverse matrix entries, frozen
|
|
829
|
+
*
|
|
830
|
+
* @example
|
|
831
|
+
* ```ts
|
|
832
|
+
* invertWGSLMatrix3([2, 0, 0, 0, 4, 0, 0, 0, 8])[0] // 0.5
|
|
833
|
+
* ```
|
|
834
|
+
*/
|
|
835
|
+
export declare function invertWGSLMatrix3(elements: readonly [number, number, number, number, number, number, number, number, number]): readonly [number, number, number, number, number, number, number, number, number];
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Checks whether a value names a storage slot access mode.
|
|
839
|
+
*
|
|
840
|
+
* @param value - The value to inspect
|
|
841
|
+
* @returns True if the value is one of the `WGSL_ACCESSES` members; false otherwise
|
|
842
|
+
*
|
|
843
|
+
* @example
|
|
844
|
+
* ```ts
|
|
845
|
+
* isWGSLAccess('read_write') // true
|
|
846
|
+
* isWGSLAccess('write') // false
|
|
847
|
+
* ```
|
|
848
|
+
*/
|
|
849
|
+
export declare function isWGSLAccess(value: unknown): value is WGSLAccess;
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Checks whether an unknown value is a WGSL error.
|
|
853
|
+
*
|
|
854
|
+
* @remarks
|
|
855
|
+
* Recognition requires a native `Error` whose prototype is not `Error.prototype`, an own brand
|
|
856
|
+
* property holding the tested value itself, a declared condition code, and an object, callable, or
|
|
857
|
+
* absent context. It recognizes an error from another installed copy of this package, and refuses a
|
|
858
|
+
* look-alike with the same code and no brand, a proxy over a branded error, and a plain object that
|
|
859
|
+
* only carries the brand.
|
|
860
|
+
*
|
|
861
|
+
* @param value - The value to inspect
|
|
862
|
+
* @returns True if the value is a `WGSLError`; false otherwise
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```ts
|
|
866
|
+
* isWGSLError(new WGSLError('The batch was aborted.', { code: 'ABORT' })) // true
|
|
867
|
+
* isWGSLError(new Error('The batch was aborted.')) // false
|
|
868
|
+
* ```
|
|
869
|
+
*/
|
|
870
|
+
export declare function isWGSLError(value: unknown): value is WGSLError;
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Checks whether a value names a WGSL extension a fragment variant can enable.
|
|
874
|
+
*
|
|
875
|
+
* @remarks
|
|
876
|
+
* Only an own key of `WGSL_EXTENSIONS` passes, so an inherited name such as `toString` fails.
|
|
877
|
+
*
|
|
878
|
+
* @param value - The value to inspect
|
|
879
|
+
* @returns True if the value is a key of `WGSL_EXTENSIONS`; false otherwise
|
|
880
|
+
*
|
|
881
|
+
* @example
|
|
882
|
+
* ```ts
|
|
883
|
+
* isWGSLExtension('subgroups') // true
|
|
884
|
+
* isWGSLExtension('shader-f16') // false
|
|
885
|
+
* ```
|
|
886
|
+
*/
|
|
887
|
+
export declare function isWGSLExtension(value: unknown): value is WGSLExtension;
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Checks whether a value is a plain float-pair record whose `head` and `tail` members lie within IEEE-754 `f32` bounds.
|
|
891
|
+
*
|
|
892
|
+
* @remarks
|
|
893
|
+
* Requires a plain record whose only own keys are the enumerable numeric properties `head` and
|
|
894
|
+
* `tail`. Finite components must satisfy `Math.abs(component) <= 3.4028234663852886e38` (the
|
|
895
|
+
* largest finite `f32`); `±Infinity` and `NaN` pass as valid IEEE-754 `f32` patterns, while finite
|
|
896
|
+
* `f64` values past `±3.4028234663852886e38`, missing keys, non-enumerable `head`/`tail`, extra
|
|
897
|
+
* string or symbol own keys, throwing accessors, and revoked proxies return `false`.
|
|
898
|
+
*
|
|
899
|
+
* @param value - The value to inspect
|
|
900
|
+
* @returns True if the value is a `WGSLFloatPair`; false otherwise
|
|
901
|
+
*
|
|
902
|
+
* @example
|
|
903
|
+
* ```ts
|
|
904
|
+
* isWGSLFloatPair({ head: 1, tail: 0 }) // true
|
|
905
|
+
* isWGSLFloatPair({ head: 1e39, tail: 0 }) // false
|
|
906
|
+
* ```
|
|
907
|
+
*/
|
|
908
|
+
export declare function isWGSLFloatPair(value: unknown): value is WGSLFloatPair;
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* Checks whether a value holds a positive safe integer count on each of three axes.
|
|
912
|
+
*
|
|
913
|
+
* @remarks
|
|
914
|
+
* The value must be a dense array of length 3, and each of its indices must hold a safe integer of
|
|
915
|
+
* at least 1, so a sparse array, a zero count, and a fraction fail.
|
|
916
|
+
*
|
|
917
|
+
* @param value - The value to inspect
|
|
918
|
+
* @returns True if the value is a `WGSLGrid`; false otherwise
|
|
919
|
+
*
|
|
920
|
+
* @example
|
|
921
|
+
* ```ts
|
|
922
|
+
* isWGSLGrid([64, 1, 1]) // true
|
|
923
|
+
* isWGSLGrid([0, 1, 1]) // false
|
|
924
|
+
* ```
|
|
925
|
+
*/
|
|
926
|
+
export declare function isWGSLGrid(value: unknown): value is WGSLGrid;
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* Checks whether a value is a non-reserved WGSL identifier starting with a letter.
|
|
930
|
+
*
|
|
931
|
+
* @remarks
|
|
932
|
+
* Accepts ASCII letters followed by letters, digits, or underscores, and refuses every entry in
|
|
933
|
+
* `WGSL_RESERVED_WORDS`.
|
|
934
|
+
*
|
|
935
|
+
* @param value - The value to inspect
|
|
936
|
+
* @returns True if the value is a valid WGSL identifier outside `WGSL_RESERVED_WORDS`; false otherwise
|
|
937
|
+
*
|
|
938
|
+
* @example
|
|
939
|
+
* ```ts
|
|
940
|
+
* isWGSLIdentifier('reduceSum') // true
|
|
941
|
+
* isWGSLIdentifier('class') // false
|
|
942
|
+
* ```
|
|
943
|
+
*/
|
|
944
|
+
export declare function isWGSLIdentifier(value: unknown): value is string;
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* Checks whether a value names a WGSL language extension a fragment variant can require.
|
|
948
|
+
*
|
|
949
|
+
* @param value - The value to inspect
|
|
950
|
+
* @returns True if the value is one of the `WGSL_LANGUAGES` members; false otherwise
|
|
951
|
+
*
|
|
952
|
+
* @example
|
|
953
|
+
* ```ts
|
|
954
|
+
* isWGSLLanguage('subgroup_id') // true
|
|
955
|
+
* isWGSLLanguage('subgroups') // false
|
|
956
|
+
* ```
|
|
957
|
+
*/
|
|
958
|
+
export declare function isWGSLLanguage(value: unknown): value is WGSLLanguage;
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Checks whether a value names a scalar type a pipeline-overridable constant can declare.
|
|
962
|
+
*
|
|
963
|
+
* @param value - The value to inspect
|
|
964
|
+
* @returns True if the value is one of the `WGSL_OVERRIDE_SCALARS` members; false otherwise
|
|
965
|
+
*
|
|
966
|
+
* @example
|
|
967
|
+
* ```ts
|
|
968
|
+
* isWGSLOverrideScalar('bool') // true
|
|
969
|
+
* isWGSLOverrideScalar('f16') // false
|
|
970
|
+
* ```
|
|
971
|
+
*/
|
|
972
|
+
export declare function isWGSLOverrideScalar(value: unknown): value is WGSLOverrideScalar;
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Checks whether a value names a scalar type a uniform struct member can hold.
|
|
976
|
+
*
|
|
977
|
+
* @param value - The value to inspect
|
|
978
|
+
* @returns True if the value is one of the `WGSL_SCALARS` members; false otherwise
|
|
979
|
+
*
|
|
980
|
+
* @example
|
|
981
|
+
* ```ts
|
|
982
|
+
* isWGSLScalar('f32') // true
|
|
983
|
+
* isWGSLScalar('f64') // false
|
|
984
|
+
* ```
|
|
985
|
+
*/
|
|
986
|
+
export declare function isWGSLScalar(value: unknown): value is WGSLScalar;
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* Checks whether a value names an element type a storage slot array can hold.
|
|
990
|
+
*
|
|
991
|
+
* @param value - The value to inspect
|
|
992
|
+
* @returns True if the value is one of the `WGSL_STORAGE_ELEMENTS` members; false otherwise
|
|
993
|
+
*
|
|
994
|
+
* @example
|
|
995
|
+
* ```ts
|
|
996
|
+
* isWGSLStorageElement('vec4f') // true
|
|
997
|
+
* isWGSLStorageElement('vec3f') // false
|
|
998
|
+
* ```
|
|
999
|
+
*/
|
|
1000
|
+
export declare function isWGSLStorageElement(value: unknown): value is WGSLStorageElement;
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Multiplies two scalar-last (`xyzw`) Hamilton quaternions, as `multiplyQuaternion` in `WGSL_QUATERNION` does.
|
|
1004
|
+
*
|
|
1005
|
+
* @remarks
|
|
1006
|
+
* Thrown with code `ARGUMENT` when `left` or `right` is not a dense 4-tuple of numbers.
|
|
1007
|
+
*
|
|
1008
|
+
* @param left - The left quaternion `[x, y, z, w]`
|
|
1009
|
+
* @param right - The right quaternion `[x, y, z, w]`
|
|
1010
|
+
* @returns The product quaternion `[x, y, z, w]`, frozen
|
|
1011
|
+
*
|
|
1012
|
+
* @example
|
|
1013
|
+
* ```ts
|
|
1014
|
+
* multiplyWGSLQuaternion([1, 0, 0, 0], [0, 1, 0, 0]) // [0, 0, 1, 0]
|
|
1015
|
+
* ```
|
|
1016
|
+
*/
|
|
1017
|
+
export declare function multiplyWGSLQuaternion(left: readonly [number, number, number, number], right: readonly [number, number, number, number]): readonly [number, number, number, number];
|
|
1018
|
+
|
|
1019
|
+
/**
|
|
1020
|
+
* Narrows a number to bfloat16 bits, as `narrowBFloat` in `WGSL_BFLOAT` does.
|
|
1021
|
+
*
|
|
1022
|
+
* @remarks
|
|
1023
|
+
* The number first rounds to the nearest `f32`, as a `Float32Array` store rounds it, and then to the
|
|
1024
|
+
* nearest bfloat16, ties to even: `-0` and both infinities keep their patterns, a finite value past
|
|
1025
|
+
* the largest bfloat16 gives an infinity, and `NaN` gives `0x7fc0`, the quiet pattern of the
|
|
1026
|
+
* canonical `f32` NaN. Thrown with code `ARGUMENT` when `value` is not a number.
|
|
1027
|
+
*
|
|
1028
|
+
* @param value - The value to narrow
|
|
1029
|
+
* @returns The bfloat16 bits, from `0` to `0xffff`
|
|
1030
|
+
*
|
|
1031
|
+
* @example
|
|
1032
|
+
* ```ts
|
|
1033
|
+
* narrowWGSLBFloat(1) // 0x3f80
|
|
1034
|
+
* ```
|
|
1035
|
+
*/
|
|
1036
|
+
export declare function narrowWGSLBFloat(value: number): number;
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* Narrows a number to OCP FP8 `E4M3FN` bits with round-to-nearest-even and finite saturation, as `narrowE4M3` in `WGSL_FP8` does.
|
|
1040
|
+
*
|
|
1041
|
+
* @remarks
|
|
1042
|
+
* Rounds first to `f32`, then rounds ties to even into `E4M3FN`: `-0` maps to `0x80`, magnitudes
|
|
1043
|
+
* at or above `448` (including `±Infinity`) saturate to `0x7e`/`0xfe`, and `NaN` maps to `0x7f`.
|
|
1044
|
+
* Thrown with code `ARGUMENT` when `value` is not a number.
|
|
1045
|
+
*
|
|
1046
|
+
* @param value - The value to narrow
|
|
1047
|
+
* @returns The 8-bit `E4M3FN` pattern, from `0` to `255`
|
|
1048
|
+
*
|
|
1049
|
+
* @example
|
|
1050
|
+
* ```ts
|
|
1051
|
+
* narrowWGSLE4M3(448) // 0x7e
|
|
1052
|
+
* ```
|
|
1053
|
+
*/
|
|
1054
|
+
export declare function narrowWGSLE4M3(value: number): number;
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* Narrows a number to OCP FP8 `E5M2` bits with IEEE-754 round-to-nearest-even, as `narrowE5M2` in `WGSL_FP8` does.
|
|
1058
|
+
*
|
|
1059
|
+
* @remarks
|
|
1060
|
+
* Rounds first to `f32`, then rounds ties to even into `E5M2`: `-0` maps to `0x80`, magnitudes at
|
|
1061
|
+
* or above `61440` overflow to `±Infinity` (`0x7c`/`0xfc`), and `NaN` maps to `0x7e`. Thrown with
|
|
1062
|
+
* code `ARGUMENT` when `value` is not a number.
|
|
1063
|
+
*
|
|
1064
|
+
* @param value - The value to narrow
|
|
1065
|
+
* @returns The 8-bit `E5M2` pattern, from `0` to `255`
|
|
1066
|
+
*
|
|
1067
|
+
* @example
|
|
1068
|
+
* ```ts
|
|
1069
|
+
* narrowWGSLE5M2(61_440) // 0x7c
|
|
1070
|
+
* ```
|
|
1071
|
+
*/
|
|
1072
|
+
export declare function narrowWGSLE5M2(value: number): number;
|
|
1073
|
+
|
|
1074
|
+
/**
|
|
1075
|
+
* Narrows a number to IEEE 754 half-precision bits, as `narrowHalf` in `WGSL_FLOAT` does.
|
|
1076
|
+
*
|
|
1077
|
+
* @remarks
|
|
1078
|
+
* The number first rounds to the nearest `f32`, as a `Float32Array` store rounds it, and then to the
|
|
1079
|
+
* nearest half, ties to even: `-0` keeps its sign, a magnitude from `65520` up gives an infinity, and
|
|
1080
|
+
* `NaN` gives `0x7e00`, the quiet pattern of the canonical `f32` NaN. Thrown with code `ARGUMENT`
|
|
1081
|
+
* when `value` is not a number.
|
|
1082
|
+
*
|
|
1083
|
+
* @param value - The value to narrow
|
|
1084
|
+
* @returns The half-precision bits, from `0` to `0xffff`
|
|
1085
|
+
*
|
|
1086
|
+
* @example
|
|
1087
|
+
* ```ts
|
|
1088
|
+
* narrowWGSLHalf(1) // 0x3c00
|
|
1089
|
+
* ```
|
|
1090
|
+
*/
|
|
1091
|
+
export declare function narrowWGSLHalf(value: number): number;
|
|
1092
|
+
|
|
1093
|
+
/**
|
|
1094
|
+
* Packs 4 signed bytes into a `u32` word, as `packSignedBytes` in `WGSL_BYTES` does.
|
|
1095
|
+
*
|
|
1096
|
+
* @remarks
|
|
1097
|
+
* The first value lands in byte 0, the lowest, so it inverts `unpackWGSLBytes`. Thrown with code
|
|
1098
|
+
* `ARGUMENT` when `values` is not an array of 4 integers, each from `-128` to `127`.
|
|
1099
|
+
*
|
|
1100
|
+
* @param values - The 4 signed bytes, byte 0 first
|
|
1101
|
+
* @returns The packed word, from `0` to `0xffffffff`
|
|
1102
|
+
*
|
|
1103
|
+
* @example
|
|
1104
|
+
* ```ts
|
|
1105
|
+
* packWGSLBytes([1, 127, -1, -128]) // 0x80ff7f01
|
|
1106
|
+
* ```
|
|
1107
|
+
*/
|
|
1108
|
+
export declare function packWGSLBytes(values: readonly [number, number, number, number]): number;
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* Renders one fragment and every fragment it reaches as WGSL text a tool or a test can compile beside its own entry.
|
|
1112
|
+
*
|
|
1113
|
+
* @remarks
|
|
1114
|
+
* Builds a synthetic program whose entry size is `[fragment.workgroup ?? 1, 1, 1]` when
|
|
1115
|
+
* `options?.linear !== false` or `[1, fragment.workgroup ?? 1, 1]` when `options?.linear === false`,
|
|
1116
|
+
* delegates to `collectWGSLSections`, and keeps only `requires`, `enable`, `dispatch`, `invocation`,
|
|
1117
|
+
* and `fragment` sections. Leaves out the uniform struct, overrides, bindings, and entry function.
|
|
1118
|
+
* Thrown with code `VALIDATION` when the linker finds two distinct fragments of one name or a cycle.
|
|
1119
|
+
*
|
|
1120
|
+
* @param fragment - The fragment to render
|
|
1121
|
+
* @param options - The active extensions, language extensions, subgroup bounds, and linearity flag
|
|
1122
|
+
* @returns The WGSL text, ending in a line feed
|
|
1123
|
+
*
|
|
1124
|
+
* @example
|
|
1125
|
+
* ```ts
|
|
1126
|
+
* renderWGSLFragment(WGSL_HALF).endsWith('}\n') // true
|
|
1127
|
+
* ```
|
|
1128
|
+
*/
|
|
1129
|
+
export declare function renderWGSLFragment(fragment: WGSLFragment, options?: WGSLRenderOptions): string;
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* Renders a program's complete WGSL text for one render capability set.
|
|
1133
|
+
*
|
|
1134
|
+
* @remarks
|
|
1135
|
+
* Joins the `source` of each `collectWGSLSections` section with one blank line and terminates with
|
|
1136
|
+
* a line feed, so `renderWGSLProgram` and `collectWGSLSections` never disagree.
|
|
1137
|
+
*
|
|
1138
|
+
* @param program - The program to render
|
|
1139
|
+
* @param options - The active extensions, language extensions, subgroup bounds, and linearity flag
|
|
1140
|
+
* @returns The WGSL text, ending in a line feed
|
|
1141
|
+
*
|
|
1142
|
+
* @example
|
|
1143
|
+
* ```ts
|
|
1144
|
+
* renderWGSLProgram(program).startsWith('struct Shape {') // true
|
|
1145
|
+
* ```
|
|
1146
|
+
*/
|
|
1147
|
+
export declare function renderWGSLProgram(program: WGSLProgram, options?: WGSLRenderOptions): string;
|
|
1148
|
+
|
|
1149
|
+
/**
|
|
1150
|
+
* Resolves the first matching conditional variant of a fragment for one render capability set.
|
|
1151
|
+
*
|
|
1152
|
+
* @remarks
|
|
1153
|
+
* Evaluates `fragment.variants` in declaration order and returns the first variant whose
|
|
1154
|
+
* `extensions`, `languages`, `subgroup` bounds (`options.subgroup.minimum >= (variant.subgroup.minimum ?? 4)`
|
|
1155
|
+
* and `options.subgroup.maximum <= (variant.subgroup.maximum ?? 128)`), and `linear` requirement
|
|
1156
|
+
* (`options?.linear !== false` when `variant.linear === true`) all hold, or `undefined` when none
|
|
1157
|
+
* matches. A variant declaring `'subgroup_id'` in `languages` or `subgroup` bounds also requires
|
|
1158
|
+
* `options?.extensions?.subgroups === true`.
|
|
1159
|
+
*
|
|
1160
|
+
* @param fragment - The fragment whose variants are checked
|
|
1161
|
+
* @param options - The active extensions, language extensions, subgroup bounds, and linearity flag
|
|
1162
|
+
* @returns The first matching variant, or `undefined` to fall back to `fragment.source`
|
|
1163
|
+
*
|
|
1164
|
+
* @example
|
|
1165
|
+
* ```ts
|
|
1166
|
+
* resolveWGSLVariant(WGSL_JOIN, { extensions: { subgroups: true }, linear: true }) !== undefined // true
|
|
1167
|
+
* ```
|
|
1168
|
+
*/
|
|
1169
|
+
export declare function resolveWGSLVariant(fragment: WGSLFragment, options?: WGSLRenderOptions): WGSLVariant | undefined;
|
|
1170
|
+
|
|
1171
|
+
/**
|
|
1172
|
+
* Rotates a 3D vector by a scalar-last (`xyzw`) unit quaternion, as `rotateVector` in `WGSL_QUATERNION` does.
|
|
1173
|
+
*
|
|
1174
|
+
* @remarks
|
|
1175
|
+
* Evaluates `vector + w * t + cross(q.xyz, t)` with `t = 2 * cross(q.xyz, vector)`. Thrown with
|
|
1176
|
+
* code `ARGUMENT` when `rotation` is not a dense 4-tuple of numbers or `vector` is not a dense
|
|
1177
|
+
* 3-tuple of numbers.
|
|
1178
|
+
*
|
|
1179
|
+
* @param rotation - The unit quaternion `[x, y, z, w]`
|
|
1180
|
+
* @param vector - The 3D vector `[x, y, z]`
|
|
1181
|
+
* @returns The rotated 3D vector `[x, y, z]`, frozen
|
|
1182
|
+
*
|
|
1183
|
+
* @example
|
|
1184
|
+
* ```ts
|
|
1185
|
+
* rotateWGSLVector([0, 0, 0, 1], [1, 2, 3]) // [1, 2, 3]
|
|
1186
|
+
* ```
|
|
1187
|
+
*/
|
|
1188
|
+
export declare function rotateWGSLVector(rotation: readonly [number, number, number, number], vector: readonly [number, number, number]): readonly [number, number, number];
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Samples one radical-inverse Halton coordinate strictly in `[0, 1)`, as `sampleHalton` in `WGSL_QUASI` does.
|
|
1192
|
+
*
|
|
1193
|
+
* @remarks
|
|
1194
|
+
* Base `2` takes the top 24 reversed bits scaled by `2^-24`, matching `sampleVanDerCorput`
|
|
1195
|
+
* bit-for-bit; larger bases clamp at `1 - 2^-24` (`0.9999999403953552`) so rounding never reaches
|
|
1196
|
+
* `1.0`. Thrown with code `ARGUMENT` when `index` is not an unsigned 32-bit integer (`-0` refused)
|
|
1197
|
+
* or `base` is not an integer from `2` to `0xffffffff` (`-0` refused).
|
|
1198
|
+
*
|
|
1199
|
+
* @param index - The 0-based sequence index (`0` to `0xffffffff`)
|
|
1200
|
+
* @param base - The integer radix (`2` to `0xffffffff`)
|
|
1201
|
+
* @returns The sample strictly in `[0, 1)`
|
|
1202
|
+
*
|
|
1203
|
+
* @example
|
|
1204
|
+
* ```ts
|
|
1205
|
+
* sampleWGSLHalton(1, 2) // 0.5
|
|
1206
|
+
* ```
|
|
1207
|
+
*/
|
|
1208
|
+
export declare function sampleWGSLHalton(index: number, base: number): number;
|
|
1209
|
+
|
|
1210
|
+
/**
|
|
1211
|
+
* Samples one 2D plastic-constant (`R2`) quasi-random point strictly in `[0, 1)^2`, as `samplePlastic2` in `WGSL_QUASI` does.
|
|
1212
|
+
*
|
|
1213
|
+
* @remarks
|
|
1214
|
+
* Uses 32-bit fixed-point Weyl recurrence (`0x80000000 + index * 0xc13fa9a9`,
|
|
1215
|
+
* `0x80000000 + index * 0x91e10da5`) truncated to the top 24 bits and scaled by `2^-24`, matching
|
|
1216
|
+
* `samplePlastic2` bit-for-bit up to `index = 0xffffffff`. Thrown with code `ARGUMENT` when `index`
|
|
1217
|
+
* is not an unsigned 32-bit integer, `-0` included.
|
|
1218
|
+
*
|
|
1219
|
+
* @param index - The 0-based sequence index (`0` to `0xffffffff`)
|
|
1220
|
+
* @returns The 2D sample strictly in `[0, 1)^2`, frozen
|
|
1221
|
+
*
|
|
1222
|
+
* @example
|
|
1223
|
+
* ```ts
|
|
1224
|
+
* sampleWGSLPlastic2(0) // [0.5, 0.5]
|
|
1225
|
+
* ```
|
|
1226
|
+
*/
|
|
1227
|
+
export declare function sampleWGSLPlastic2(index: number): readonly [number, number];
|
|
1228
|
+
|
|
1229
|
+
/**
|
|
1230
|
+
* Samples one 2D Sobol quasi-random point strictly in `[0, 1)^2`, as `sampleSobol2` in `WGSL_QUASI` does.
|
|
1231
|
+
*
|
|
1232
|
+
* @remarks
|
|
1233
|
+
* Computes dimension 0 from reversed index bits and dimension 1 from the Sobol primitive-polynomial
|
|
1234
|
+
* direction recurrence `v = v ^ (v >> 1)`, truncating both to the top 24 bits scaled by `2^-24` so
|
|
1235
|
+
* every output matches `sampleSobol2` bit-for-bit and stays strictly in `[0, 1)`. Thrown with code
|
|
1236
|
+
* `ARGUMENT` when `index` is not an unsigned 32-bit integer, `-0` included.
|
|
1237
|
+
*
|
|
1238
|
+
* @param index - The 0-based sequence index (`0` to `0xffffffff`)
|
|
1239
|
+
* @returns The 2D sample strictly in `[0, 1)^2`, frozen
|
|
1240
|
+
*
|
|
1241
|
+
* @example
|
|
1242
|
+
* ```ts
|
|
1243
|
+
* sampleWGSLSobol2(1) // [0.5, 0.5]
|
|
1244
|
+
* ```
|
|
1245
|
+
*/
|
|
1246
|
+
export declare function sampleWGSLSobol2(index: number): readonly [number, number];
|
|
1247
|
+
|
|
1248
|
+
/**
|
|
1249
|
+
* Unpacks the 4 bytes of a `u32` word as signed integers, as `unpackSignedBytes` in `WGSL_BYTES` does.
|
|
1250
|
+
*
|
|
1251
|
+
* @remarks
|
|
1252
|
+
* Byte 0, the lowest, comes first. Thrown with code `ARGUMENT` when `word` is not an integer from
|
|
1253
|
+
* `0` to `0xffffffff`.
|
|
1254
|
+
*
|
|
1255
|
+
* @param word - The packed word
|
|
1256
|
+
* @returns The 4 signed bytes, each from `-128` to `127`, frozen
|
|
1257
|
+
*
|
|
1258
|
+
* @example
|
|
1259
|
+
* ```ts
|
|
1260
|
+
* unpackWGSLBytes(0x80ff_7f01) // [1, 127, -1, -128]
|
|
1261
|
+
* ```
|
|
1262
|
+
*/
|
|
1263
|
+
export declare function unpackWGSLBytes(word: number): readonly [number, number, number, number];
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* Lists the access modes a storage slot can declare.
|
|
1267
|
+
*
|
|
1268
|
+
* @remarks
|
|
1269
|
+
* Each member mirrors the WGSL `var<storage, ACCESS>` access mode of the same spelling.
|
|
1270
|
+
*
|
|
1271
|
+
* @example
|
|
1272
|
+
* ```ts
|
|
1273
|
+
* WGSL_ACCESSES.includes('read_write') // true
|
|
1274
|
+
* ```
|
|
1275
|
+
*/
|
|
1276
|
+
export declare const WGSL_ACCESSES: readonly ["read", "read_write"];
|
|
1277
|
+
|
|
1278
|
+
/**
|
|
1279
|
+
* Lists the extrema selecting operations supported by `createWGSLArgReduce`.
|
|
1280
|
+
*
|
|
1281
|
+
* @example
|
|
1282
|
+
* ```ts
|
|
1283
|
+
* WGSL_ARG_REDUCE_OPERATIONS.includes('max') // true
|
|
1284
|
+
* ```
|
|
1285
|
+
*/
|
|
1286
|
+
export declare const WGSL_ARG_REDUCE_OPERATIONS: readonly ["max", "min"];
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* Holds the fragment that widens and narrows scalar and packed-pair bfloat16 values in `u32` words.
|
|
1290
|
+
*
|
|
1291
|
+
* @remarks
|
|
1292
|
+
* Declares `widenBFloat`, `narrowBFloat`, `widenBFloatPair`, and `narrowBFloatPair`. All bodies use
|
|
1293
|
+
* integer bit operations on `bitcast` words so subnormals, signed zeros, infinities, and quiet NaNs
|
|
1294
|
+
* stay exact. `widenWGSLBFloat` and `narrowWGSLBFloat` are its TypeScript twins.
|
|
1295
|
+
*
|
|
1296
|
+
* @example
|
|
1297
|
+
* ```ts
|
|
1298
|
+
* WGSL_BFLOAT.name // 'bfloat'
|
|
1299
|
+
* ```
|
|
1300
|
+
*/
|
|
1301
|
+
export declare const WGSL_BFLOAT: WGSLFragment;
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* Holds the fragment that reads, writes, and takes dot products of bytes, nibbles, and halves packed in a `u32` word.
|
|
1305
|
+
*
|
|
1306
|
+
* @remarks
|
|
1307
|
+
* Declares `signByte`, `readWordByte`, `readWordHalf`, `unpackSignedBytes`, `packSignedBytes`,
|
|
1308
|
+
* `unpackSignedNibbles`, `unpackUnsignedNibbles`, `packNibbles`, `dotSignedBytes`, and
|
|
1309
|
+
* `dotUnsignedBytes`. The `packed_4x8_integer_dot_product` variant delegates `dotSignedBytes` and
|
|
1310
|
+
* `dotUnsignedBytes` to `dot4I8Packed` and `dot4U8Packed` with bit-identical (`exact`) results.
|
|
1311
|
+
* `unpackWGSLBytes` and `packWGSLBytes` are its TypeScript twins.
|
|
1312
|
+
*
|
|
1313
|
+
* @example
|
|
1314
|
+
* ```ts
|
|
1315
|
+
* WGSL_BYTES.name // 'bytes'
|
|
1316
|
+
* ```
|
|
1317
|
+
*/
|
|
1318
|
+
export declare const WGSL_BYTES: WGSLFragment;
|
|
1319
|
+
|
|
1320
|
+
/**
|
|
1321
|
+
* Holds the fragment that tracks a Neumaier compensated `f32` sum and merges compensated states.
|
|
1322
|
+
*
|
|
1323
|
+
* @remarks
|
|
1324
|
+
* It declares `struct CompensatedSum { sum: f32, error: f32 }` and three pure helper functions:
|
|
1325
|
+
* `fn emptyCompensatedSum() -> CompensatedSum`, `fn pushCompensatedSum(state: CompensatedSum,
|
|
1326
|
+
* value: f32) -> CompensatedSum`, and `fn mergeCompensatedSum(left: CompensatedSum, right:
|
|
1327
|
+
* CompensatedSum) -> CompensatedSum`. Preserves low-order bits across large cancellations when the
|
|
1328
|
+
* final total is read as `state.sum + state.error`. Inputs are assumed finite; an `Infinity` or `NaN`
|
|
1329
|
+
* value propagates `NaN`. It takes neither `Invocation` nor `Dispatch`, declares no workgroup
|
|
1330
|
+
* storage, and reads no binding and no uniform member.
|
|
1331
|
+
*
|
|
1332
|
+
* @example
|
|
1333
|
+
* ```ts
|
|
1334
|
+
* WGSL_COMPENSATED.name // 'compensated'
|
|
1335
|
+
* ```
|
|
1336
|
+
*/
|
|
1337
|
+
export declare const WGSL_COMPENSATED: WGSLFragment;
|
|
1338
|
+
|
|
1339
|
+
/**
|
|
1340
|
+
* Holds the fragment of complex arithmetic (`vec2f` as real and imaginary) and radix-2 FFT butterfly helpers.
|
|
1341
|
+
*
|
|
1342
|
+
* @remarks
|
|
1343
|
+
* Declares `uses: [WGSL_MATH, WGSL_SPECIAL]` (`computeHypot`, `computeCosPi`, `computeSinPi`),
|
|
1344
|
+
* executes `0` `fma()` calls, declares `struct ComplexPair { even: vec2f, odd: vec2f }`, and
|
|
1345
|
+
* provides `conjugateComplex`, `multiplyComplex`, overflow-safe Smith `divideComplex`,
|
|
1346
|
+
* `computeComplexSqrt`, `computeComplexExp`, `computeComplexLog`, `computeTwiddle`, and
|
|
1347
|
+
* `computeRadixButterfly`. Callers compute magnitude directly with `computeHypot(value.x, value.y)`.
|
|
1348
|
+
* Domain boundaries: `divideComplex` prescales magnitudes `> 1.0e37` to avoid intermediate
|
|
1349
|
+
* overflow, returns `vec2f(0.0, 0.0)` for finite dividends over `(±Infinity, ±Infinity)`, and
|
|
1350
|
+
* produces IEEE division-by-zero components at `(0.0, 0.0)`; `computeComplexSqrt` prescales tiny
|
|
1351
|
+
* and subnormal inputs (`2^64`, post-scaled by `2^-32`) and large finite inputs (`> 1.0e37`,
|
|
1352
|
+
* `0.25`, post-scaled by `2.0`), taking the principal branch on the negative real axis;
|
|
1353
|
+
* `computeComplexLog` prescales large finite inputs (`> 2^60`, `2^-66`) and tiny nonzero inputs
|
|
1354
|
+
* (`2^64`) to avoid intermediate `computeHypot` and `atan2` overflow or FTZ underflow, yielding
|
|
1355
|
+
* `(-Infinity, atan2)` at zero; and `computeTwiddle` returns `vec2f(1.0, 0.0)` when `count == 0u`.
|
|
1356
|
+
* `divideWGSLComplex` is the TypeScript twin of `divideComplex`.
|
|
1357
|
+
*
|
|
1358
|
+
* @example
|
|
1359
|
+
* ```ts
|
|
1360
|
+
* WGSL_COMPLEX.name // 'complex'
|
|
1361
|
+
* ```
|
|
1362
|
+
*/
|
|
1363
|
+
export declare const WGSL_COMPLEX: WGSLFragment;
|
|
1364
|
+
|
|
1365
|
+
/**
|
|
1366
|
+
* Holds the fragment of extended-precision double-float arithmetic over `FloatPair` without `fma`.
|
|
1367
|
+
*
|
|
1368
|
+
* @remarks
|
|
1369
|
+
* Declares `uses: [WGSL_EFT]` (`FloatPair`, `computeExactSum`, `computeExactProduct`), executes
|
|
1370
|
+
* `0` `fma()` calls, and provides `normalizeDouble`, `negateDouble`, `addDouble`,
|
|
1371
|
+
* `subtractDouble`, `multiplyDouble`, `divideDouble`, `computeDoubleSqrt`, and `compareDouble`.
|
|
1372
|
+
* Uses an unprovable-zero guard bit in `addDouble` so optimizing compilers do not fold
|
|
1373
|
+
* `computeExactSum` error residuals away, and `computeExactSum` cross terms in `multiplyDouble`,
|
|
1374
|
+
* holding `<= 2.0` double-float ULP (`2^-47` relative error) across finite `f32` products through
|
|
1375
|
+
* `computeExactProduct` prescaling on hardware and software backends. Non-finite `head` values
|
|
1376
|
+
* propagate as `FloatPair(head, 0.0)`, `divideDouble` preserves `(±0.0, 0.0)` for finite dividends
|
|
1377
|
+
* over `(±Infinity, 0.0)` and yields IEEE division-by-zero non-finites at `(0.0, 0.0)`,
|
|
1378
|
+
* `computeDoubleSqrt` returns `NaN` for negative values, and `compareDouble` returns `0i` when
|
|
1379
|
+
* either operand is `NaN`. `encodeWGSLDouble`, `decodeWGSLDouble`, and `isWGSLFloatPair` are its
|
|
1380
|
+
* TypeScript twins.
|
|
1381
|
+
*
|
|
1382
|
+
* @example
|
|
1383
|
+
* ```ts
|
|
1384
|
+
* WGSL_DOUBLE.name // 'double'
|
|
1385
|
+
* ```
|
|
1386
|
+
*/
|
|
1387
|
+
export declare const WGSL_DOUBLE: WGSLFragment;
|
|
1388
|
+
|
|
1389
|
+
/**
|
|
1390
|
+
* Holds the fragment of forward-mode dual-number automatic differentiation (`vec2f` as primal and tangent).
|
|
1391
|
+
*
|
|
1392
|
+
* @remarks
|
|
1393
|
+
* Declares `uses: [WGSL_MATH]` (`computeSigmoid`), executes `0` `fma()` calls, and provides
|
|
1394
|
+
* `multiplyDual`, `divideDual`, `computeDualSqrt`, `computeDualExp`, `computeDualLog`,
|
|
1395
|
+
* `computeDualPow`, `computeDualSin`, `computeDualCos`, and `computeDualSigmoid`. Domain
|
|
1396
|
+
* boundaries: requires finite inputs inside each elementary function's differentiable domain
|
|
1397
|
+
* (`right.x != 0.0` for `divideDual`, `value.x > 0.0` for `computeDualSqrt` and `computeDualLog`,
|
|
1398
|
+
* `base.x > 0.0` for `computeDualPow` with every `exponent` other than `0.0` and `1.0`, matching
|
|
1399
|
+
* WGSL `pow`; `exponent == 0.0` returns `vec2f(1.0, 0.0)` and `exponent == 1.0` returns `base`). Takes neither `Invocation` nor `Dispatch` and declares no
|
|
1400
|
+
* workgroup storage.
|
|
1401
|
+
*
|
|
1402
|
+
* @example
|
|
1403
|
+
* ```ts
|
|
1404
|
+
* WGSL_DUAL.name // 'dual'
|
|
1405
|
+
* ```
|
|
1406
|
+
*/
|
|
1407
|
+
export declare const WGSL_DUAL: WGSLFragment;
|
|
1408
|
+
|
|
1409
|
+
/**
|
|
1410
|
+
* Holds the fragment of error-free floating-point sum and product transformations without `fma`.
|
|
1411
|
+
*
|
|
1412
|
+
* @remarks
|
|
1413
|
+
* Declares `struct FloatPair { head: f32, tail: f32 }`, Knuth's 6-FLOP `computeExactSum`,
|
|
1414
|
+
* `computeOrderedSum` (for `abs(left) >= abs(right)`), Veltkamp's `4097.0` `splitFloat` (exact
|
|
1415
|
+
* for `|value| <= 8.305646e34`), and Dekker's `computeExactProduct` (which prescales large and
|
|
1416
|
+
* tiny finite operands automatically so every finite `f32` product avoids intermediate overflow
|
|
1417
|
+
* and FTZ underflow, returning `FloatPair(product, 0.0)` on zero or non-finite products). Avoids
|
|
1418
|
+
* `fma` so residuals survive software and hardware backends without double rounding.
|
|
1419
|
+
*
|
|
1420
|
+
* @example
|
|
1421
|
+
* ```ts
|
|
1422
|
+
* WGSL_EFT.name // 'eft'
|
|
1423
|
+
* ```
|
|
1424
|
+
*/
|
|
1425
|
+
export declare const WGSL_EFT: WGSLFragment;
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* Keys the global brand a `WGSLError` carries, so another installed copy recognizes it.
|
|
1429
|
+
*
|
|
1430
|
+
* @remarks
|
|
1431
|
+
* The key follows the package-and-class form, `Symbol.for('<package>.<ClassName>')`. The brand is
|
|
1432
|
+
* a recognition marker and never proof that the class's constructor ran.
|
|
1433
|
+
*
|
|
1434
|
+
* @example
|
|
1435
|
+
* ```ts
|
|
1436
|
+
* WGSL_ERROR_BRAND === Symbol.for('@orkestrel/wgsl.WGSLError') // true
|
|
1437
|
+
* ```
|
|
1438
|
+
*/
|
|
1439
|
+
export declare const WGSL_ERROR_BRAND: unique symbol;
|
|
1440
|
+
|
|
1441
|
+
/**
|
|
1442
|
+
* Lists the condition codes a `WGSLError` carries.
|
|
1443
|
+
*
|
|
1444
|
+
* @remarks
|
|
1445
|
+
* `ARGUMENT` marks a malformed argument, `COMPILE` a shader the compiler refuses, `VALIDATION` a
|
|
1446
|
+
* declaration or command the package or the device refuses, `LIMIT` an exceeded device limit,
|
|
1447
|
+
* `HOST` a lost device, `DESTROYED` a call after `destroy`, and `ABORT` an aborted signal or batch.
|
|
1448
|
+
*
|
|
1449
|
+
* @example
|
|
1450
|
+
* ```ts
|
|
1451
|
+
* WGSL_ERROR_CODES.includes('VALIDATION') // true
|
|
1452
|
+
* ```
|
|
1453
|
+
*/
|
|
1454
|
+
export declare const WGSL_ERROR_CODES: readonly ["ARGUMENT", "COMPILE", "VALIDATION", "LIMIT", "HOST", "DESTROYED", "ABORT"];
|
|
1455
|
+
|
|
1456
|
+
/**
|
|
1457
|
+
* Maps each WGSL extension a fragment variant can enable to the device feature that admits it.
|
|
1458
|
+
*
|
|
1459
|
+
* @remarks
|
|
1460
|
+
* Each key mirrors the WGSL `enable` directive of the same spelling, and each value mirrors the
|
|
1461
|
+
* WebGPU `GPUFeatureName` a device reports in `device.features`. The key order is the order in
|
|
1462
|
+
* which a rendered program emits its `enable` directives.
|
|
1463
|
+
*
|
|
1464
|
+
* @example
|
|
1465
|
+
* ```ts
|
|
1466
|
+
* WGSL_EXTENSIONS.f16 // 'shader-f16'
|
|
1467
|
+
* ```
|
|
1468
|
+
*/
|
|
1469
|
+
export declare const WGSL_EXTENSIONS: Readonly<{
|
|
1470
|
+
readonly f16: 'shader-f16';
|
|
1471
|
+
readonly subgroups: 'subgroups';
|
|
1472
|
+
}>;
|
|
1473
|
+
|
|
1474
|
+
/**
|
|
1475
|
+
* Holds the fragment that narrows an `f32` to half-precision bits, clamps scalar and quad half ranges, and classifies `f32` bit patterns.
|
|
1476
|
+
*
|
|
1477
|
+
* @remarks
|
|
1478
|
+
* Declares `narrowHalf`, `clampHalf`, `clampHalfQuad`, `isFiniteFloat`, and `isNaNFloat`. Every body
|
|
1479
|
+
* uses integer bit operations so NaN patterns and subnormals are preserved. `narrowWGSLHalf` is the
|
|
1480
|
+
* TypeScript twin of `narrowHalf`.
|
|
1481
|
+
*
|
|
1482
|
+
* @example
|
|
1483
|
+
* ```ts
|
|
1484
|
+
* WGSL_FLOAT.name // 'float'
|
|
1485
|
+
* ```
|
|
1486
|
+
*/
|
|
1487
|
+
export declare const WGSL_FLOAT: WGSLFragment;
|
|
1488
|
+
|
|
1489
|
+
/**
|
|
1490
|
+
* Holds the fragment that widens and narrows scalar and packed-quad OCP FP8 `E4M3FN` and `E5M2` values in `u32` words.
|
|
1491
|
+
*
|
|
1492
|
+
* @remarks
|
|
1493
|
+
* Declares `uses: []`, executes `0` `fma()` calls (pure integer bit operations), and provides
|
|
1494
|
+
* `widenE4M3`, `narrowE4M3`, `widenE4M3Quad`, `narrowE4M3Quad`, `widenE5M2`, `narrowE5M2`,
|
|
1495
|
+
* `widenE5M2Quad`, and `narrowE5M2Quad`. Domain boundaries: `widenE4M3` and `widenE5M2` mask `bits`
|
|
1496
|
+
* to `0..255`. `E4M3FN` spans subnormals `2^-9` to `7 * 2^-9` and normals up to `±448.0`, rounds
|
|
1497
|
+
* ties to even, flushes magnitudes `<= 2^-10` to signed zero, saturates magnitudes `>= 448.0`
|
|
1498
|
+
* (including `±Infinity`) to `0x7e`/`0xfe`, and encodes `NaN` as `0x7f`/`0xff` with no infinities.
|
|
1499
|
+
* `E5M2` spans subnormals `2^-16` to `3 * 2^-16` and normals up to `±57344.0`, rounds ties to even,
|
|
1500
|
+
* flushes magnitudes `<= 2^-17` to signed zero, overflows at `>= 61440.0` to `±Infinity`
|
|
1501
|
+
* (`0x7c`/`0xfc`), and quiets `NaN` to `0x7e`/`0xfe` while preserving the 2-bit payload.
|
|
1502
|
+
* `widenWGSLE4M3`, `narrowWGSLE4M3`, `widenWGSLE5M2`, and `narrowWGSLE5M2` are its TypeScript
|
|
1503
|
+
* twins.
|
|
1504
|
+
*
|
|
1505
|
+
* @example
|
|
1506
|
+
* ```ts
|
|
1507
|
+
* WGSL_FP8.name // 'fp8'
|
|
1508
|
+
* ```
|
|
1509
|
+
*/
|
|
1510
|
+
export declare const WGSL_FP8: WGSLFragment;
|
|
1511
|
+
|
|
1512
|
+
/**
|
|
1513
|
+
* Holds the fragment that widens the IEEE 754 half-precision bits in the low 16 bits of a `u32` to an `f32`.
|
|
1514
|
+
*
|
|
1515
|
+
* @remarks
|
|
1516
|
+
* It declares `fn widenHalf(bits: u32) -> f32`, which takes neither `Invocation` nor `Dispatch`
|
|
1517
|
+
* and builds the result from integer bit operations, so
|
|
1518
|
+
* signed zeros, subnormals, infinities, and NaN payloads widen exactly and no `f16` extension is
|
|
1519
|
+
* needed. An exponent of `0x1f` keeps the fraction under an all-ones `f32` exponent, so infinities
|
|
1520
|
+
* stay infinite and NaN payloads survive. A subnormal half rebuilds its `f32` bits from
|
|
1521
|
+
* `firstLeadingBit(fraction)`: the leading bit sets the exponent and the bits under it shift into
|
|
1522
|
+
* the `f32` fraction, with no float arithmetic. It reads no binding and no uniform member.
|
|
1523
|
+
*
|
|
1524
|
+
* @example
|
|
1525
|
+
* ```ts
|
|
1526
|
+
* WGSL_HALF.name // 'widenHalf'
|
|
1527
|
+
* ```
|
|
1528
|
+
*/
|
|
1529
|
+
export declare const WGSL_HALF: WGSLFragment;
|
|
1530
|
+
|
|
1531
|
+
/**
|
|
1532
|
+
* Holds the fragment of deterministic 32-bit integer hashing helpers `hashWord` and `hashPair`.
|
|
1533
|
+
*
|
|
1534
|
+
* @remarks
|
|
1535
|
+
* It declares `fn hashWord(value: u32) -> u32` (32-bit finalizer mix) and
|
|
1536
|
+
* `fn hashPair(left: u32, right: u32) -> u32` (order-sensitive two-word mix). All operations use
|
|
1537
|
+
* wrapping `u32` arithmetic. It takes neither `Invocation` nor `Dispatch`, declares no workgroup
|
|
1538
|
+
* storage, and reads no binding and no uniform member.
|
|
1539
|
+
*
|
|
1540
|
+
* @example
|
|
1541
|
+
* ```ts
|
|
1542
|
+
* WGSL_HASH.name // 'hash'
|
|
1543
|
+
* ```
|
|
1544
|
+
*/
|
|
1545
|
+
export declare const WGSL_HASH: WGSLFragment;
|
|
1546
|
+
|
|
1547
|
+
/**
|
|
1548
|
+
* Lists the bin counts supported by `createWGSLHistogram`.
|
|
1549
|
+
*
|
|
1550
|
+
* @remarks
|
|
1551
|
+
* `WGSLHistogramSize` derives from this list.
|
|
1552
|
+
*
|
|
1553
|
+
* @example
|
|
1554
|
+
* ```ts
|
|
1555
|
+
* WGSL_HISTOGRAM_SIZES.includes(64) // true
|
|
1556
|
+
* ```
|
|
1557
|
+
*/
|
|
1558
|
+
export declare const WGSL_HISTOGRAM_SIZES: readonly [16, 32, 64, 128, 256];
|
|
1559
|
+
|
|
1560
|
+
/**
|
|
1561
|
+
* Holds the fragment that votes a `bool` across the invocations of a 64-invocation workgroup.
|
|
1562
|
+
*
|
|
1563
|
+
* @remarks
|
|
1564
|
+
* The default body declares an 8-byte `JoinSlot { vote: atomic<u32>, flag: u32 }` in `joinShared`
|
|
1565
|
+
* and runs 4 barriers (2D-safe, avoiding `workgroupUniformLoad` on an atomic). The `subgroups`
|
|
1566
|
+
* `linear: true` variant declares a 68-byte `JoinSlot { partials: array<u32, 16>, flag: u32 }` and
|
|
1567
|
+
* runs 3 barriers with `exact` parity. Both end with `workgroupUniformLoad(&joinShared.flag) != 0u`,
|
|
1568
|
+
* so callers may branch and return early before a later barrier.
|
|
1569
|
+
*
|
|
1570
|
+
* @example
|
|
1571
|
+
* ```ts
|
|
1572
|
+
* WGSL_JOIN.workgroup // 64
|
|
1573
|
+
* ```
|
|
1574
|
+
*/
|
|
1575
|
+
export declare const WGSL_JOIN: WGSLFragment;
|
|
1576
|
+
|
|
1577
|
+
/**
|
|
1578
|
+
* Lists the WGSL language extensions a fragment variant can require.
|
|
1579
|
+
*
|
|
1580
|
+
* @remarks
|
|
1581
|
+
* Each member mirrors the W3C WGSL `requires` directive name and the corresponding entry in
|
|
1582
|
+
* `navigator.gpu.wgslLanguageFeatures`. Order matches the order in which a rendered program emits
|
|
1583
|
+
* its `requires` directives. `WGSLLanguage` derives from this list.
|
|
1584
|
+
*
|
|
1585
|
+
* @example
|
|
1586
|
+
* ```ts
|
|
1587
|
+
* WGSL_LANGUAGES.includes('subgroup_id') // true
|
|
1588
|
+
* ```
|
|
1589
|
+
*/
|
|
1590
|
+
export declare const WGSL_LANGUAGES: readonly ["packed_4x8_integer_dot_product", "subgroup_id"];
|
|
1591
|
+
|
|
1592
|
+
/**
|
|
1593
|
+
* Mirrors the WebGPU `GPUMapMode` bit values under one-word members.
|
|
1594
|
+
*
|
|
1595
|
+
* @remarks
|
|
1596
|
+
* `read` mirrors `READ` and `write` mirrors `WRITE`.
|
|
1597
|
+
*
|
|
1598
|
+
* @example
|
|
1599
|
+
* ```ts
|
|
1600
|
+
* WGSL_MAP.read // 1
|
|
1601
|
+
* ```
|
|
1602
|
+
*/
|
|
1603
|
+
export declare const WGSL_MAP: Readonly<{
|
|
1604
|
+
readonly read: 1;
|
|
1605
|
+
readonly write: 2;
|
|
1606
|
+
}>;
|
|
1607
|
+
|
|
1608
|
+
/**
|
|
1609
|
+
* Holds the fragment of numerically stable scalar elementary helpers and streaming log-sum-exp and Euclidean norm monoids.
|
|
1610
|
+
*
|
|
1611
|
+
* @remarks
|
|
1612
|
+
* Declares `OnlineExp` (`emptyOnlineExp`, `pushOnlineExp`, `mergeOnlineExp`), `OnlineNorm`
|
|
1613
|
+
* (`emptyOnlineNorm`, `pushOnlineNorm`, `mergeOnlineNorm`, `finishOnlineNorm`), and the pure scalar
|
|
1614
|
+
* helpers `computeLogOnePlus`, `computeExpMinusOne`, `computeHypot`, `computeLogAddExp`,
|
|
1615
|
+
* `computeLogOneMinusExp`, `computeSigmoid`, and `computeSoftplus`.
|
|
1616
|
+
*
|
|
1617
|
+
* @example
|
|
1618
|
+
* ```ts
|
|
1619
|
+
* WGSL_MATH.name // 'math'
|
|
1620
|
+
* ```
|
|
1621
|
+
*/
|
|
1622
|
+
export declare const WGSL_MATH: WGSLFragment;
|
|
1623
|
+
|
|
1624
|
+
/**
|
|
1625
|
+
* Holds the fragment of small dense column-major matrix inversion (`2x2`, `3x3`, `4x4`), partial-pivoted `3x3` linear solve, and `3x3` Cholesky factorization.
|
|
1626
|
+
*
|
|
1627
|
+
* @remarks
|
|
1628
|
+
* Declares `uses: []`, executes `0` `fma()` calls, and provides `invertMatrix2`, `invertMatrix3`,
|
|
1629
|
+
* `invertMatrix4`, `solveMatrix3`, and `factorCholesky3`. Domain boundaries: `invertMatrix2`,
|
|
1630
|
+
* `invertMatrix3`, `invertMatrix4`, and `solveMatrix3` require non-singular column-major matrices
|
|
1631
|
+
* (singular inputs produce IEEE division-by-zero non-finite entries); `factorCholesky3` reads the
|
|
1632
|
+
* lower triangle and diagonal and returns a lower-triangular factor `L` with runtime-masked `NaN`
|
|
1633
|
+
* on the diagonal when the input is not symmetric positive definite. `invertWGSLMatrix3` is the
|
|
1634
|
+
* TypeScript twin of `invertMatrix3`.
|
|
1635
|
+
*
|
|
1636
|
+
* @example
|
|
1637
|
+
* ```ts
|
|
1638
|
+
* WGSL_MATRIX.name // 'matrix'
|
|
1639
|
+
* ```
|
|
1640
|
+
*/
|
|
1641
|
+
export declare const WGSL_MATRIX: WGSLFragment;
|
|
1642
|
+
|
|
1643
|
+
/**
|
|
1644
|
+
* Lists the online monoid states supported by `createWGSLMonoidReduce`.
|
|
1645
|
+
*
|
|
1646
|
+
* @remarks
|
|
1647
|
+
* `'exp'` reduces `OnlineExp` from `WGSL_MATH`, `'moments'` reduces `OnlineMoments` from
|
|
1648
|
+
* `WGSL_WELFORD`, and `'compensated'` reduces `CompensatedSum` from `WGSL_COMPENSATED`.
|
|
1649
|
+
* `WGSLMonoid` derives from this list.
|
|
1650
|
+
*
|
|
1651
|
+
* @example
|
|
1652
|
+
* ```ts
|
|
1653
|
+
* WGSL_MONOIDS.includes('exp') // true
|
|
1654
|
+
* ```
|
|
1655
|
+
*/
|
|
1656
|
+
export declare const WGSL_MONOIDS: readonly ["exp", "moments", "compensated"];
|
|
1657
|
+
|
|
1658
|
+
/**
|
|
1659
|
+
* Holds the fragment of 2D (`16` bits per axis) and 3D (`10` bits per axis) Morton Z-order curve bit-interleaving helpers.
|
|
1660
|
+
*
|
|
1661
|
+
* @remarks
|
|
1662
|
+
* Declares `uses: []`, executes `0` `fma()` calls (pure integer bit operations), and provides
|
|
1663
|
+
* `encodeMorton2`, `decodeMorton2`, `encodeMorton3`, and `decodeMorton3`, together with
|
|
1664
|
+
* `spreadMorton2`, `compactMorton2`, `spreadMorton3`, and `compactMorton3`. Domain boundaries:
|
|
1665
|
+
* `encodeMorton2` masks each `point` component to `0..65535` and `decodeMorton2` inverts every
|
|
1666
|
+
* 32-bit `code`; `encodeMorton3` masks each `point` component to `0..1023` into a 30-bit code and
|
|
1667
|
+
* `decodeMorton3` reads the low 30 bits of `code`. `encodeWGSLMorton2`, `decodeWGSLMorton2`,
|
|
1668
|
+
* `encodeWGSLMorton3`, and `decodeWGSLMorton3` are its TypeScript twins.
|
|
1669
|
+
*
|
|
1670
|
+
* @example
|
|
1671
|
+
* ```ts
|
|
1672
|
+
* WGSL_MORTON.name // 'morton'
|
|
1673
|
+
* ```
|
|
1674
|
+
*/
|
|
1675
|
+
export declare const WGSL_MORTON: WGSLFragment;
|
|
1676
|
+
|
|
1677
|
+
/**
|
|
1678
|
+
* Holds the fragment that maps `f32` and `i32` values bijectively to order-preserving `u32` keys.
|
|
1679
|
+
*
|
|
1680
|
+
* @remarks
|
|
1681
|
+
* Declares `encodeFloatOrder`, `decodeFloatOrder`, `encodeSignedOrder`, and `decodeSignedOrder`.
|
|
1682
|
+
* `encodeFloatOrder` canonicalizes every NaN to quiet `0x7fc00000u` (`0xffc00000u` encoded) and
|
|
1683
|
+
* maps every non-NaN `f32` (`-Infinity < ... < -0.0 < +0.0 < ... < +Infinity`) bijectively to `u32`
|
|
1684
|
+
* order so wait-free `atomicMax`/`atomicMin` and integer sorts agree with IEEE-754 total order.
|
|
1685
|
+
* `encodeWGSLFloatOrder` and `decodeWGSLFloatOrder` are its TypeScript twins.
|
|
1686
|
+
*
|
|
1687
|
+
* @example
|
|
1688
|
+
* ```ts
|
|
1689
|
+
* WGSL_ORDER.name // 'order'
|
|
1690
|
+
* ```
|
|
1691
|
+
*/
|
|
1692
|
+
export declare const WGSL_ORDER: WGSLFragment;
|
|
1693
|
+
|
|
1694
|
+
/**
|
|
1695
|
+
* Lists the scalar types a pipeline-overridable constant can declare.
|
|
1696
|
+
*
|
|
1697
|
+
* @remarks
|
|
1698
|
+
* Mirrors the W3C WGSL `override` scalar types (`bool`, `u32`, `i32`, and `f32`).
|
|
1699
|
+
* `WGSLOverrideScalar` derives from this list.
|
|
1700
|
+
*
|
|
1701
|
+
* @example
|
|
1702
|
+
* ```ts
|
|
1703
|
+
* WGSL_OVERRIDE_SCALARS.includes('bool') // true
|
|
1704
|
+
* ```
|
|
1705
|
+
*/
|
|
1706
|
+
export declare const WGSL_OVERRIDE_SCALARS: readonly ["bool", "u32", "i32", "f32"];
|
|
1707
|
+
|
|
1708
|
+
/**
|
|
1709
|
+
* Holds the fragment that finds the largest `f32` value across the invocations of a 64-invocation workgroup.
|
|
1710
|
+
*
|
|
1711
|
+
* @remarks
|
|
1712
|
+
* It declares `var<workgroup> peakShared: array<f32, 64>`, 256 bytes, and
|
|
1713
|
+
* `fn peakPartials(invocation: Invocation, value: f32) -> f32`, which returns the workgroup's
|
|
1714
|
+
* maximum to every invocation. The entry's workgroup size must hold 64 invocations, and every
|
|
1715
|
+
* invocation must call it from uniform control flow. It takes `Invocation` and never `Dispatch`. The
|
|
1716
|
+
* default body reduces with `max` in a tree of halving strides. The `subgroups` variant is
|
|
1717
|
+
* `reordered`: it stores each subgroup's `subgroupMax` partial at its first invocation's index and
|
|
1718
|
+
* the lowest finite `f32` (`-3.4028234663852886e38`) elsewhere, and invocation 0 folds the 64 entries
|
|
1719
|
+
* with `max` across four accumulators in strides of 4 between 2 barriers (matching `@orkestrel/infer`,
|
|
1720
|
+
* so it returns `-3.4028234663852886e38` rather than `-Infinity` when every input is `-Infinity`).
|
|
1721
|
+
* Programs taking `(invocation, dispatch)` parameters can adopt
|
|
1722
|
+
* `createWGSLReduce({ workgroup: 64, operation: 'max', element: 'f32', reordered: true })` for
|
|
1723
|
+
* strided `64 / subgroup_size` folds, while `WGSL_PEAK` remains frozen on the `(invocation, value)`
|
|
1724
|
+
* signature for sealed digests. It reads no binding and no uniform member.
|
|
1725
|
+
*
|
|
1726
|
+
* @example
|
|
1727
|
+
* ```ts
|
|
1728
|
+
* WGSL_PEAK.variants[0]?.extensions // ['subgroups']
|
|
1729
|
+
* ```
|
|
1730
|
+
*/
|
|
1731
|
+
export declare const WGSL_PEAK: WGSLFragment;
|
|
1732
|
+
|
|
1733
|
+
/**
|
|
1734
|
+
* Holds the fragment that reads a workgroup's two-axis index from the entry's `Dispatch` struct.
|
|
1735
|
+
*
|
|
1736
|
+
* @remarks
|
|
1737
|
+
* It declares `fn readPlace(dispatch: Dispatch) -> u32`, which returns
|
|
1738
|
+
* `dispatch.workgroup_id.x + dispatch.workgroup_id.y * dispatch.num_workgroups.x`, the statement of
|
|
1739
|
+
* `@orkestrel/infer`'s `readPlace`. `Dispatch` holds only values that stay uniform across a
|
|
1740
|
+
* workgroup, so a call that returns early on the result stays in uniform control flow before a
|
|
1741
|
+
* later `workgroupBarrier()`. `Invocation` holds the per-lane builtins and is not a parameter. Pair
|
|
1742
|
+
* the fragment with `computeWGSLGrid`, and multiply by the workgroup size and add
|
|
1743
|
+
* `invocation.local_invocation_index` for an invocation's index. It reads no binding and no uniform
|
|
1744
|
+
* member.
|
|
1745
|
+
*
|
|
1746
|
+
* @example
|
|
1747
|
+
* ```ts
|
|
1748
|
+
* createWGSLProgram({ name: 'clear', entry, slots, uniform, uses: [WGSL_PLACE] }).fragments // [WGSL_PLACE]
|
|
1749
|
+
* ```
|
|
1750
|
+
*/
|
|
1751
|
+
export declare const WGSL_PLACE: WGSLFragment;
|
|
1752
|
+
|
|
1753
|
+
/**
|
|
1754
|
+
* Holds the fragment of low-discrepancy quasi-random sequence samplers on the half-open unit interval `[0, 1)`.
|
|
1755
|
+
*
|
|
1756
|
+
* @remarks
|
|
1757
|
+
* Declares `uses: []`, executes `0` `fma()` calls, and provides `sampleVanDerCorput`,
|
|
1758
|
+
* `sampleHalton`, `samplePlastic2`, `samplePlastic3`, and `sampleSobol2`. Uses `u32` fixed-point
|
|
1759
|
+
* arithmetic with top-24-bit truncation scaled by `2^-24` (`(bits >> 8u) * 5.960464477539063e-8`)
|
|
1760
|
+
* so every output stays strictly in `[0, 1)` up to `index = 0xffffffffu`, avoiding the `1.0`
|
|
1761
|
+
* rounding edge of `f32(u32) * 2^-32`. Domain boundaries: `sampleHalton` returns `0.0` for
|
|
1762
|
+
* `base < 2u`, delegates `base == 2u` to `sampleVanDerCorput`, and clamps larger bases to
|
|
1763
|
+
* `bitcast<f32>(0x3f7fffffu)` (`1 - 2^-24`). `sampleWGSLHalton`, `sampleWGSLPlastic2`, and
|
|
1764
|
+
* `sampleWGSLSobol2` are its TypeScript twins.
|
|
1765
|
+
*
|
|
1766
|
+
* @example
|
|
1767
|
+
* ```ts
|
|
1768
|
+
* WGSL_QUASI.name // 'quasi'
|
|
1769
|
+
* ```
|
|
1770
|
+
*/
|
|
1771
|
+
export declare const WGSL_QUASI: WGSLFragment;
|
|
1772
|
+
|
|
1773
|
+
/**
|
|
1774
|
+
* Holds the fragment of scalar-last (`xyzw`) unit quaternion algebra, vector rotation, shortest-path slerp, and rotation matrix conversion.
|
|
1775
|
+
*
|
|
1776
|
+
* @remarks
|
|
1777
|
+
* Declares `uses: []`, executes `0` `fma()` calls, and provides `conjugateQuaternion`,
|
|
1778
|
+
* `invertQuaternion`, `multiplyQuaternion`, `rotateVector`, `buildAxisQuaternion`,
|
|
1779
|
+
* `interpolateQuaternion`, and `computeRotationMatrix`. Domain boundaries: `rotateVector`,
|
|
1780
|
+
* `interpolateQuaternion`, and `computeRotationMatrix` expect unit quaternions; `invertQuaternion`
|
|
1781
|
+
* rescales by the max component and returns `vec4f(0.0)` on a zero input; `buildAxisQuaternion`
|
|
1782
|
+
* returns identity `vec4f(0.0, 0.0, 0.0, 1.0)` when `axis` has zero length; and
|
|
1783
|
+
* `interpolateQuaternion` takes the shortest path (`dot < 0.0` flips `end`) and switches to
|
|
1784
|
+
* normalized linear blending when `cosTheta > 0.9995`. Takes neither `Invocation` nor `Dispatch`
|
|
1785
|
+
* and declares no workgroup storage. `multiplyWGSLQuaternion` and `rotateWGSLVector` are its
|
|
1786
|
+
* TypeScript twins.
|
|
1787
|
+
*
|
|
1788
|
+
* @example
|
|
1789
|
+
* ```ts
|
|
1790
|
+
* WGSL_QUATERNION.name // 'quaternion'
|
|
1791
|
+
* ```
|
|
1792
|
+
*/
|
|
1793
|
+
export declare const WGSL_QUATERNION: WGSLFragment;
|
|
1794
|
+
|
|
1795
|
+
/**
|
|
1796
|
+
* Holds the fragment of stateless Philox4x32-10 random generation, distribution sampling, and stochastic rounding.
|
|
1797
|
+
*
|
|
1798
|
+
* @remarks
|
|
1799
|
+
* Declares `computePhilox` (exact 10-round Random123 Philox4x32), `computeUnitFloat` (`[0, 1)`),
|
|
1800
|
+
* `computeOpenFloat` (23-bit `(0, 1)` never reaching `0.0` or `1.0`), `sampleNormalPair`,
|
|
1801
|
+
* `sampleExponential`, `sampleGumbel`, `narrowStochasticHalf`, and `narrowStochasticBFloat`.
|
|
1802
|
+
* `computeWGSLPhilox` is the TypeScript twin of `computePhilox`.
|
|
1803
|
+
*
|
|
1804
|
+
* @example
|
|
1805
|
+
* ```ts
|
|
1806
|
+
* WGSL_RANDOM.name // 'random'
|
|
1807
|
+
* ```
|
|
1808
|
+
*/
|
|
1809
|
+
export declare const WGSL_RANDOM: WGSLFragment;
|
|
1810
|
+
|
|
1811
|
+
/**
|
|
1812
|
+
* Lists the element types supported by `createWGSLReduce`.
|
|
1813
|
+
*
|
|
1814
|
+
* @remarks
|
|
1815
|
+
* `WGSLReduceElement` derives from this list.
|
|
1816
|
+
*
|
|
1817
|
+
* @example
|
|
1818
|
+
* ```ts
|
|
1819
|
+
* WGSL_REDUCE_ELEMENTS.includes('vec4f') // true
|
|
1820
|
+
* ```
|
|
1821
|
+
*/
|
|
1822
|
+
export declare const WGSL_REDUCE_ELEMENTS: readonly ["u32", "i32", "f32", "vec2f", "vec4f"];
|
|
1823
|
+
|
|
1824
|
+
/**
|
|
1825
|
+
* Maps each reduction or scan operation and element type to its finite WGSL identity literal.
|
|
1826
|
+
*
|
|
1827
|
+
* @remarks
|
|
1828
|
+
* `max` and `min` on floating-point elements use finite IEEE-754 extremes
|
|
1829
|
+
* (`±3.4028234663852886e38`), used for exclusive scan seeding and caller lane masking.
|
|
1830
|
+
*
|
|
1831
|
+
* @example
|
|
1832
|
+
* ```ts
|
|
1833
|
+
* WGSL_REDUCE_IDENTITIES.sum.f32 // '0.0'
|
|
1834
|
+
* ```
|
|
1835
|
+
*/
|
|
1836
|
+
export declare const WGSL_REDUCE_IDENTITIES: Readonly<{
|
|
1837
|
+
readonly sum: Readonly<Record<WGSLReduceElement, string>>;
|
|
1838
|
+
readonly max: Readonly<Record<WGSLReduceElement, string>>;
|
|
1839
|
+
readonly min: Readonly<Record<WGSLReduceElement, string>>;
|
|
1840
|
+
readonly and: Readonly<Record<Exclude<WGSLScalar, 'f32'>, string>>;
|
|
1841
|
+
readonly or: Readonly<Record<Exclude<WGSLScalar, 'f32'>, string>>;
|
|
1842
|
+
readonly xor: Readonly<Record<Exclude<WGSLScalar, 'f32'>, string>>;
|
|
1843
|
+
readonly mul: Readonly<Record<WGSLReduceElement, string>>;
|
|
1844
|
+
}>;
|
|
1845
|
+
|
|
1846
|
+
/**
|
|
1847
|
+
* Lists the combining operations supported by `createWGSLReduce` and `createWGSLScan`.
|
|
1848
|
+
*
|
|
1849
|
+
* @remarks
|
|
1850
|
+
* `and`, `or`, and `xor` operate bit-wise on `u32` and `i32` values and are refused for
|
|
1851
|
+
* floating-point elements. `WGSLReduceOperation` derives from this list.
|
|
1852
|
+
*
|
|
1853
|
+
* @example
|
|
1854
|
+
* ```ts
|
|
1855
|
+
* WGSL_REDUCE_OPERATIONS.includes('sum') // true
|
|
1856
|
+
* ```
|
|
1857
|
+
*/
|
|
1858
|
+
export declare const WGSL_REDUCE_OPERATIONS: readonly ["sum", "max", "min", "and", "or", "xor", "mul"];
|
|
1859
|
+
|
|
1860
|
+
/**
|
|
1861
|
+
* Lists the partition widths supported by `createWGSLReduce`, `createWGSLMonoidReduce`, `createWGSLSort`, and `createWGSLPairSort`.
|
|
1862
|
+
*
|
|
1863
|
+
* @remarks
|
|
1864
|
+
* `WGSLReduceWidth` derives from this list. A chosen width must not exceed the fragment's
|
|
1865
|
+
* workgroup invocation count.
|
|
1866
|
+
*
|
|
1867
|
+
* @example
|
|
1868
|
+
* ```ts
|
|
1869
|
+
* WGSL_REDUCE_WIDTHS.includes(32) // true
|
|
1870
|
+
* ```
|
|
1871
|
+
*/
|
|
1872
|
+
export declare const WGSL_REDUCE_WIDTHS: readonly [16, 32, 64, 128, 256];
|
|
1873
|
+
|
|
1874
|
+
/**
|
|
1875
|
+
* Lists the W3C WGSL keywords, reserved words (§16.3), predeclared enumerants, predeclared types,
|
|
1876
|
+
* predeclared builtin functions (§17 and `subgroups`), and rendered entry struct names refused as
|
|
1877
|
+
* identifiers.
|
|
1878
|
+
*
|
|
1879
|
+
* @example
|
|
1880
|
+
* ```ts
|
|
1881
|
+
* WGSL_RESERVED_WORDS.includes('struct') // true
|
|
1882
|
+
* ```
|
|
1883
|
+
*/
|
|
1884
|
+
export declare const WGSL_RESERVED_WORDS: readonly string[];
|
|
1885
|
+
|
|
1886
|
+
/**
|
|
1887
|
+
* Lists the scalar types a uniform struct member can hold.
|
|
1888
|
+
*
|
|
1889
|
+
* @remarks
|
|
1890
|
+
* Each scalar aligns to 4 bytes and takes 4 bytes in the `uniform` and `storage` address spaces.
|
|
1891
|
+
*
|
|
1892
|
+
* @example
|
|
1893
|
+
* ```ts
|
|
1894
|
+
* WGSL_SCALARS.includes('f32') // true
|
|
1895
|
+
* ```
|
|
1896
|
+
*/
|
|
1897
|
+
export declare const WGSL_SCALARS: readonly ["u32", "i32", "f32"];
|
|
1898
|
+
|
|
1899
|
+
/**
|
|
1900
|
+
* Lists the roles a rendered program section can hold, in the order a rendered program emits them.
|
|
1901
|
+
*
|
|
1902
|
+
* @remarks
|
|
1903
|
+
* `requires` marks language-extension directives, `enable` marks extension directives, `override`
|
|
1904
|
+
* marks pipeline-overridable constant declarations, `struct` marks the uniform `struct`
|
|
1905
|
+
* declaration, `dispatch` marks the `Dispatch` entry input struct, `invocation` marks the
|
|
1906
|
+
* `Invocation` entry input struct, `bindings` marks the `@group`/`@binding` lines, `fragment`
|
|
1907
|
+
* marks one linked fragment's body, and `entry` marks the compute entry point. A `WGSLSection`
|
|
1908
|
+
* carries one of these roles so a compiler message maps back to the section whose text produced
|
|
1909
|
+
* it.
|
|
1910
|
+
*
|
|
1911
|
+
* @example
|
|
1912
|
+
* ```ts
|
|
1913
|
+
* WGSL_SECTION_ROLES.includes('fragment') // true
|
|
1914
|
+
* ```
|
|
1915
|
+
*/
|
|
1916
|
+
export declare const WGSL_SECTION_ROLES: readonly ["requires", "enable", "override", "struct", "dispatch", "invocation", "bindings", "fragment", "entry"];
|
|
1917
|
+
|
|
1918
|
+
/**
|
|
1919
|
+
* Lists the sort directions supported by `createWGSLSort` and `createWGSLPairSort`.
|
|
1920
|
+
*
|
|
1921
|
+
* @remarks
|
|
1922
|
+
* `WGSLSortOrder` derives from this list.
|
|
1923
|
+
*
|
|
1924
|
+
* @example
|
|
1925
|
+
* ```ts
|
|
1926
|
+
* WGSL_SORT_ORDERS.includes('ascending') // true
|
|
1927
|
+
* ```
|
|
1928
|
+
*/
|
|
1929
|
+
export declare const WGSL_SORT_ORDERS: readonly ["ascending", "descending"];
|
|
1930
|
+
|
|
1931
|
+
/**
|
|
1932
|
+
* Holds the fragment of special mathematical functions (`erf`, `erfc`, `inverseErf`, `logGamma`, `gamma`, `logBeta`, `sinc`, `sinPi`, `cosPi`, and `I_0`) without `fma`.
|
|
1933
|
+
*
|
|
1934
|
+
* @remarks
|
|
1935
|
+
* Declares `uses: [WGSL_EFT, WGSL_DOUBLE]`, executes `0` `fma()` calls, and provides `computeErf`,
|
|
1936
|
+
* `computeErfc`, `computeInverseErf`, `computeLogGamma`, `computeGamma`, `computeLogBeta`,
|
|
1937
|
+
* `computeSinc` (unnormalized `sin(x) / x`), `computeSinPi`, `computeCosPi`, `computeBesselZero`,
|
|
1938
|
+
* and `computeScaledBesselZero`, together with `scaleSpecial*` and `computeSpecial*` internal
|
|
1939
|
+
* helpers for FTZ-proof subnormal scaling, Cody-Waite exponential and trigonometric range
|
|
1940
|
+
* reduction, and `FloatPair` log-gamma and log-beta evaluation. Accuracy bounds: `<= 2` ULP on
|
|
1941
|
+
* `computeErf` (saturating to `±1.0` for `|x| >= 4.0`), `computeInverseErf` (`[-1.0, 1.0]`,
|
|
1942
|
+
* returning `±Infinity` at `±1.0` and runtime `NaN` for `|x| > 1.0`), `computeSinc` (`1.0` at
|
|
1943
|
+
* `±0.0`, `0.0` at `±Infinity`), `computeSinPi`, and `computeCosPi` (exact `0.0`/`±1.0` at integer
|
|
1944
|
+
* and half-integer multiples); `<= 3` ULP on `computeErfc` (`0.0` for `x >= 10.1`, `2.0` for
|
|
1945
|
+
* `x <= -4.0`), `computeLogGamma` (`+Infinity` at `±0.0`, `±Infinity`, and negative integers),
|
|
1946
|
+
* `computeGamma` (`NaN` at negative integers and `-Infinity`, `+Infinity` for `x > 35.041`),
|
|
1947
|
+
* `computeLogBeta` (`NaN` when `left` or `right` is non-positive or `NaN`, `-Infinity` when either
|
|
1948
|
+
* positive argument is `+Infinity`, supporting positive subnormals under FTZ and finite pairs up to
|
|
1949
|
+
* `3.4028234663852886e38`), `computeBesselZero` (`+Infinity` for `|x| > 92.0`), and
|
|
1950
|
+
* `computeScaledBesselZero` (`1.0` at `±0.0`, `0.0` at `±Infinity`). `computeWGSLErf`,
|
|
1951
|
+
* `computeWGSLErfc`, `computeWGSLInverseErf`, and `computeWGSLLogGamma` are its TypeScript twins.
|
|
1952
|
+
*
|
|
1953
|
+
* @example
|
|
1954
|
+
* ```ts
|
|
1955
|
+
* WGSL_SPECIAL.name // 'special'
|
|
1956
|
+
* ```
|
|
1957
|
+
*/
|
|
1958
|
+
export declare const WGSL_SPECIAL: WGSLFragment;
|
|
1959
|
+
|
|
1960
|
+
/**
|
|
1961
|
+
* Mirrors the WebGPU `GPUShaderStage` bit value of the compute stage.
|
|
1962
|
+
*
|
|
1963
|
+
* @remarks
|
|
1964
|
+
* `compute` mirrors `COMPUTE`.
|
|
1965
|
+
*
|
|
1966
|
+
* @example
|
|
1967
|
+
* ```ts
|
|
1968
|
+
* WGSL_STAGE.compute // 4
|
|
1969
|
+
* ```
|
|
1970
|
+
*/
|
|
1971
|
+
export declare const WGSL_STAGE: Readonly<{
|
|
1972
|
+
readonly compute: 4;
|
|
1973
|
+
}>;
|
|
1974
|
+
|
|
1975
|
+
/**
|
|
1976
|
+
* Lists the element types a storage slot array can hold.
|
|
1977
|
+
*
|
|
1978
|
+
* @remarks
|
|
1979
|
+
* Covers 32-bit and 16-bit scalars, 2-lane and 4-lane vectors whose WGSL alignment matches their
|
|
1980
|
+
* byte stride, and 32-bit atomic integers. Three-lane vectors are excluded because their 16-byte
|
|
1981
|
+
* alignment pads 12-byte values in storage arrays. `WGSLStorageElement` derives from this list.
|
|
1982
|
+
*
|
|
1983
|
+
* @example
|
|
1984
|
+
* ```ts
|
|
1985
|
+
* WGSL_STORAGE_ELEMENTS.includes('vec4f') // true
|
|
1986
|
+
* ```
|
|
1987
|
+
*/
|
|
1988
|
+
export declare const WGSL_STORAGE_ELEMENTS: readonly ["u32", "i32", "f32", "f16", "vec2u", "vec2i", "vec2f", "vec2h", "vec4u", "vec4i", "vec4f", "vec4h", "atomic<u32>", "atomic<i32>"];
|
|
1989
|
+
|
|
1990
|
+
/**
|
|
1991
|
+
* Maps each storage slot element type to its WGSL array stride in bytes.
|
|
1992
|
+
*
|
|
1993
|
+
* @remarks
|
|
1994
|
+
* Every key matches a member of `WGSL_STORAGE_ELEMENTS`, and each stride equals the element's
|
|
1995
|
+
* host-shareable size and alignment in the `storage` address space.
|
|
1996
|
+
*
|
|
1997
|
+
* @example
|
|
1998
|
+
* ```ts
|
|
1999
|
+
* WGSL_STORAGE_STRIDES.vec4f // 16
|
|
2000
|
+
* ```
|
|
2001
|
+
*/
|
|
2002
|
+
export declare const WGSL_STORAGE_STRIDES: Readonly<Record<WGSLStorageElement, number>>;
|
|
2003
|
+
|
|
2004
|
+
/**
|
|
2005
|
+
* Holds the fragment that sums one `f32` value from each invocation of a 64-invocation workgroup.
|
|
2006
|
+
*
|
|
2007
|
+
* @remarks
|
|
2008
|
+
* It declares `var<workgroup> sumShared: array<f32, 64>`, 256 bytes, and
|
|
2009
|
+
* `fn sumPartials(invocation: Invocation, value: f32) -> f32`, which returns the workgroup's total
|
|
2010
|
+
* to every invocation. The entry's workgroup size must hold 64 invocations, and every invocation
|
|
2011
|
+
* must call it from uniform control flow. It takes `Invocation` and never `Dispatch`, because it
|
|
2012
|
+
* reads only `local_invocation_index` and, in the variant, `subgroup_invocation_id`. The default
|
|
2013
|
+
* body reduces in a tree of halving strides. The
|
|
2014
|
+
* `subgroups` variant stores each subgroup's `subgroupAdd` partial at its first invocation's index
|
|
2015
|
+
* and `0.0` elsewhere, and invocation 0 folds the 64 entries with four accumulators in strides of 4
|
|
2016
|
+
* between 2 barriers; the variant is `reordered`, so its rounding order differs from the default
|
|
2017
|
+
* body's. Programs taking `(invocation, dispatch)` parameters can adopt
|
|
2018
|
+
* `createWGSLReduce({ workgroup: 64, operation: 'sum', element: 'f32', reordered: true })` for
|
|
2019
|
+
* strided `64 / subgroup_size` folds, while `WGSL_SUM` remains frozen on the `(invocation, value)`
|
|
2020
|
+
* signature for sealed digests. It reads no binding and no uniform member.
|
|
2021
|
+
*
|
|
2022
|
+
* @example
|
|
2023
|
+
* ```ts
|
|
2024
|
+
* WGSL_SUM.variants[0]?.extensions // ['subgroups']
|
|
2025
|
+
* ```
|
|
2026
|
+
*/
|
|
2027
|
+
export declare const WGSL_SUM: WGSLFragment;
|
|
2028
|
+
|
|
2029
|
+
/**
|
|
2030
|
+
* Holds the fragment that indexes a shared-memory tile with a padded stride or XOR bank swizzle.
|
|
2031
|
+
*
|
|
2032
|
+
* @remarks
|
|
2033
|
+
* Declares `computeTileIndex(row, column, side)` (`row * (side + 1u) + column`) and
|
|
2034
|
+
* `swizzleTileIndex(row, column, side)` (`row * side + (column ^ (row & (side - 1u)))`, for
|
|
2035
|
+
* power-of-two `side`). Takes neither `Invocation` nor `Dispatch`, declares no workgroup storage,
|
|
2036
|
+
* and reads no binding or uniform member.
|
|
2037
|
+
*
|
|
2038
|
+
* @example
|
|
2039
|
+
* ```ts
|
|
2040
|
+
* WGSL_TILE.name // 'tile'
|
|
2041
|
+
* ```
|
|
2042
|
+
*/
|
|
2043
|
+
export declare const WGSL_TILE: WGSLFragment;
|
|
2044
|
+
|
|
2045
|
+
/**
|
|
2046
|
+
* Lists the square tile dimensions supported by `createWGSLTranspose`.
|
|
2047
|
+
*
|
|
2048
|
+
* @example
|
|
2049
|
+
* ```ts
|
|
2050
|
+
* WGSL_TILE_SIZES.includes(16) // true
|
|
2051
|
+
* ```
|
|
2052
|
+
*/
|
|
2053
|
+
export declare const WGSL_TILE_SIZES: readonly [16, 32];
|
|
2054
|
+
|
|
2055
|
+
/**
|
|
2056
|
+
* Holds the default number of compute passes a traced batch records.
|
|
2057
|
+
*
|
|
2058
|
+
* @remarks
|
|
2059
|
+
* The session's `trace.capacity` option replaces it, from 1 to 2048. Each pass takes 2 entries of
|
|
2060
|
+
* the session's timestamp query set, and each pass past the capacity counts in
|
|
2061
|
+
* `WGSLTraceRecord.dropped`.
|
|
2062
|
+
*
|
|
2063
|
+
* @example
|
|
2064
|
+
* ```ts
|
|
2065
|
+
* WGSL_TRACE_CAPACITY // 512
|
|
2066
|
+
* ```
|
|
2067
|
+
*/
|
|
2068
|
+
export declare const WGSL_TRACE_CAPACITY = 512;
|
|
2069
|
+
|
|
2070
|
+
/**
|
|
2071
|
+
* Lists the causes that can end a recorded compute pass in a batch trace.
|
|
2072
|
+
*
|
|
2073
|
+
* @remarks
|
|
2074
|
+
* `WGSLTraceCause` derives from this list.
|
|
2075
|
+
*
|
|
2076
|
+
* @example
|
|
2077
|
+
* ```ts
|
|
2078
|
+
* WGSL_TRACE_CAUSES.includes('write') // true
|
|
2079
|
+
* ```
|
|
2080
|
+
*/
|
|
2081
|
+
export declare const WGSL_TRACE_CAUSES: readonly ["copy", "clear", "write", "read", "flush", "statement", "submit"];
|
|
2082
|
+
|
|
2083
|
+
/**
|
|
2084
|
+
* Lists the modes a session's tracer runs in.
|
|
2085
|
+
*
|
|
2086
|
+
* @remarks
|
|
2087
|
+
* `off` records nothing, `pass` records each compute pass the batch would open anyway, and
|
|
2088
|
+
* `statement` ends the compute pass after every dispatch so each pass's GPU time belongs to one
|
|
2089
|
+
* program. `WGSLTraceMode` derives from this list.
|
|
2090
|
+
*
|
|
2091
|
+
* @example
|
|
2092
|
+
* ```ts
|
|
2093
|
+
* WGSL_TRACE_MODES.includes('pass') // true
|
|
2094
|
+
* ```
|
|
2095
|
+
*/
|
|
2096
|
+
export declare const WGSL_TRACE_MODES: readonly ["off", "pass", "statement"];
|
|
2097
|
+
|
|
2098
|
+
/**
|
|
2099
|
+
* Holds the default byte capacity of a session's uniform slab.
|
|
2100
|
+
*
|
|
2101
|
+
* @remarks
|
|
2102
|
+
* The session's `uniform.size` option replaces it. At a 256-byte offset alignment the default
|
|
2103
|
+
* holds 256 dispatches before a batch flushes.
|
|
2104
|
+
*
|
|
2105
|
+
* @example
|
|
2106
|
+
* ```ts
|
|
2107
|
+
* WGSL_UNIFORM_SIZE // 65536
|
|
2108
|
+
* ```
|
|
2109
|
+
*/
|
|
2110
|
+
export declare const WGSL_UNIFORM_SIZE = 65536;
|
|
2111
|
+
|
|
2112
|
+
/**
|
|
2113
|
+
* Mirrors the WebGPU `GPUBufferUsage` bit values under one-word members.
|
|
2114
|
+
*
|
|
2115
|
+
* @remarks
|
|
2116
|
+
* `read` mirrors `MAP_READ`, `write` mirrors `MAP_WRITE`, `source` mirrors `COPY_SRC`,
|
|
2117
|
+
* `destination` mirrors `COPY_DST`, `uniform` mirrors `UNIFORM`, `storage` mirrors `STORAGE`,
|
|
2118
|
+
* `indirect` mirrors `INDIRECT`, and `query` mirrors `QUERY_RESOLVE`. The library declares
|
|
2119
|
+
* `GPUBufferUsage` only as a type, so `src/core` reads these values instead.
|
|
2120
|
+
*
|
|
2121
|
+
* @example
|
|
2122
|
+
* ```ts
|
|
2123
|
+
* WGSL_USAGE.uniform | WGSL_USAGE.destination // 72
|
|
2124
|
+
* ```
|
|
2125
|
+
*/
|
|
2126
|
+
export declare const WGSL_USAGE: Readonly<{
|
|
2127
|
+
readonly read: 1;
|
|
2128
|
+
readonly write: 2;
|
|
2129
|
+
readonly source: 4;
|
|
2130
|
+
readonly destination: 8;
|
|
2131
|
+
readonly uniform: 64;
|
|
2132
|
+
readonly storage: 128;
|
|
2133
|
+
readonly indirect: 256;
|
|
2134
|
+
readonly query: 512;
|
|
2135
|
+
}>;
|
|
2136
|
+
|
|
2137
|
+
/**
|
|
2138
|
+
* Holds the fragment that accumulates and merges online mean and sum-of-squared-deviations moments.
|
|
2139
|
+
*
|
|
2140
|
+
* @remarks
|
|
2141
|
+
* It declares `struct OnlineMoments { count: f32, mean: f32, square: f32 }` and three pure helper
|
|
2142
|
+
* functions: `fn emptyOnlineMoments() -> OnlineMoments`, `fn pushOnlineMoments(state: OnlineMoments,
|
|
2143
|
+
* value: f32) -> OnlineMoments`, and `fn mergeOnlineMoments(left: OnlineMoments, right:
|
|
2144
|
+
* OnlineMoments) -> OnlineMoments`. The `f32` `count` field stays exact for integer sample counts up
|
|
2145
|
+
* to `2^24` (`16,777,216`). Inputs are assumed finite; an `Infinity` or `NaN` value propagates `NaN`.
|
|
2146
|
+
* It takes neither `Invocation` nor `Dispatch`, declares no workgroup storage, and reads no binding
|
|
2147
|
+
* and no uniform member.
|
|
2148
|
+
*
|
|
2149
|
+
* @example
|
|
2150
|
+
* ```ts
|
|
2151
|
+
* WGSL_WELFORD.name // 'welford'
|
|
2152
|
+
* ```
|
|
2153
|
+
*/
|
|
2154
|
+
export declare const WGSL_WELFORD: WGSLFragment;
|
|
2155
|
+
|
|
2156
|
+
/**
|
|
2157
|
+
* Lists the workgroup invocation counts supported by collective fragment factories.
|
|
2158
|
+
*
|
|
2159
|
+
* @example
|
|
2160
|
+
* ```ts
|
|
2161
|
+
* WGSL_WORKGROUPS.includes(64) // true
|
|
2162
|
+
* ```
|
|
2163
|
+
*/
|
|
2164
|
+
export declare const WGSL_WORKGROUPS: readonly [64, 128, 256];
|
|
2165
|
+
|
|
2166
|
+
/**
|
|
2167
|
+
* Names the access mode of a storage slot.
|
|
2168
|
+
*
|
|
2169
|
+
* @example
|
|
2170
|
+
* ```ts
|
|
2171
|
+
* const access: WGSLAccess = 'read_write'
|
|
2172
|
+
* ```
|
|
2173
|
+
*/
|
|
2174
|
+
export declare type WGSLAccess = (typeof WGSL_ACCESSES)[number];
|
|
2175
|
+
|
|
2176
|
+
/**
|
|
2177
|
+
* Carries the input `createWGSLArgReduce` builds an index-of-extreme fragment from.
|
|
2178
|
+
*
|
|
2179
|
+
* @remarks
|
|
2180
|
+
* A tie resolves to the lowest index.
|
|
2181
|
+
*
|
|
2182
|
+
* @example
|
|
2183
|
+
* ```ts
|
|
2184
|
+
* const input: WGSLArgReduceInput = { workgroup: 128, operation: 'max', element: 'f32' }
|
|
2185
|
+
* ```
|
|
2186
|
+
*/
|
|
2187
|
+
export declare interface WGSLArgReduceInput {
|
|
2188
|
+
/** Names the fragment. Default: a name built from `operation`, `element`, and `workgroup`. */
|
|
2189
|
+
readonly name?: string;
|
|
2190
|
+
/** Holds the workgroup invocation count the reduction needs. */
|
|
2191
|
+
readonly workgroup: WGSLWorkgroup;
|
|
2192
|
+
/** Names whether the largest or the smallest value wins. */
|
|
2193
|
+
readonly operation: WGSLArgReduceOperation;
|
|
2194
|
+
/** Names the element type compared. */
|
|
2195
|
+
readonly element: WGSLScalar;
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
/**
|
|
2199
|
+
* Names the selecting operation of an arg-reduction.
|
|
2200
|
+
*
|
|
2201
|
+
* @example
|
|
2202
|
+
* ```ts
|
|
2203
|
+
* const operation: WGSLArgReduceOperation = 'max'
|
|
2204
|
+
* ```
|
|
2205
|
+
*/
|
|
2206
|
+
export declare type WGSLArgReduceOperation = (typeof WGSL_ARG_REDUCE_OPERATIONS)[number];
|
|
2207
|
+
|
|
2208
|
+
/**
|
|
2209
|
+
* Records one command encoder's worth of dispatches, writes, copies, clears, and reads, then submits them together.
|
|
2210
|
+
*
|
|
2211
|
+
* @remarks
|
|
2212
|
+
* The batch owns its command encoder and its compute pass, and keeps one pass open across
|
|
2213
|
+
* consecutive `encode` calls, skipping a `setPipeline` or a `setBindGroup(0, ...)` that repeats the
|
|
2214
|
+
* previous one. Each dispatch writes its uniform values to the session's slab and binds them through
|
|
2215
|
+
* the 5-argument `setBindGroup(1, group, offsets, 0, 1)` overload. When the slab is full, the batch
|
|
2216
|
+
* ends its pass, uploads the slab, submits, clears the slab, and opens a fresh encoder. The pass
|
|
2217
|
+
* ends before each `read`, `write`, `copy`, `clear`, and `flush`; `write` flushes earlier recorded
|
|
2218
|
+
* commands before invoking `queue.writeBuffer` so subsequent commands observe the uploaded bytes in
|
|
2219
|
+
* recording order. Every upload, write, and submit sits between a synchronous push and pop of a
|
|
2220
|
+
* `validation` and an `out-of-memory` error scope; a device error moves the session to `failed`
|
|
2221
|
+
* with code `VALIDATION`. `read` accepts either one `(buffer, offset, size)` range or an array of
|
|
2222
|
+
* `WGSLSpan` ranges copied into one coalesced staging buffer, maps its staging buffer alongside
|
|
2223
|
+
* submission settlement, and resolves after submission to caller-owned `ArrayBuffer` copies. Each
|
|
2224
|
+
* `read`, `write`, `copy`, and `clear` checks the session, the batch, its buffers' usages, and its
|
|
2225
|
+
* offsets, sizes, and ranges before it records anything, so a refused call leaves the open pass in
|
|
2226
|
+
* place. `abort` restores unsubmitted staging buffers synchronously and defers restoring flushed
|
|
2227
|
+
* staging buffers until earlier submissions finish draining.
|
|
2228
|
+
* Thrown with code `VALIDATION` when a call other than `abort` or `execute` arrives after `submit`
|
|
2229
|
+
* or `abort`; with code `ARGUMENT` for a malformed grid, a malformed `read`, `write`, `copy`, or
|
|
2230
|
+
* `clear` argument, a buffer without the usage the call needs, or a `copy` between one buffer and
|
|
2231
|
+
* itself; with code `DESTROYED` after the session's `destroy`; and with code `LIMIT` when a grid
|
|
2232
|
+
* axis passes `maxComputeWorkgroupsPerDimension` or a read total passes `maxBufferSize`. Open a
|
|
2233
|
+
* batch through `session.batch()`, which supplies the options.
|
|
2234
|
+
*
|
|
2235
|
+
* @example
|
|
2236
|
+
* ```ts
|
|
2237
|
+
* const batch = session.batch()
|
|
2238
|
+
* batch.encode(binding, { count: 64 }, [1, 1, 1])
|
|
2239
|
+
* const bytes = batch.read(buffer, 0, 256)
|
|
2240
|
+
* await batch.execute()
|
|
2241
|
+
* new Uint32Array(await bytes)[0] // the first word the dispatch wrote
|
|
2242
|
+
* ```
|
|
2243
|
+
*/
|
|
2244
|
+
export declare class WGSLBatch implements WGSLBatchInterface {
|
|
2245
|
+
#private;
|
|
2246
|
+
/**
|
|
2247
|
+
* Creates an open batch with a fresh command encoder.
|
|
2248
|
+
*
|
|
2249
|
+
* @param device - The device whose encoder records the commands and whose queue runs them
|
|
2250
|
+
* @param options - The session's slab, the session hooks, and the session's tracer
|
|
2251
|
+
*/
|
|
2252
|
+
constructor(device: GPUDevice, options: WGSLBatchOptions);
|
|
2253
|
+
get submitted(): boolean;
|
|
2254
|
+
get trace(): WGSLTraceRecord | undefined;
|
|
2255
|
+
encode<S extends WGSLSlotMap, F extends WGSLFieldMap, O extends WGSLOverrideMap>(binding: WGSLBinding<S, F, O>, values: WGSLValueMap<F>, grid: WGSLGrid): void;
|
|
531
2256
|
read(buffer: GPUBuffer, offset: number, size: number): Promise<ArrayBuffer>;
|
|
2257
|
+
read(spans: readonly WGSLSpan[]): Promise<readonly ArrayBuffer[]>;
|
|
2258
|
+
write(destination: WGSLSlice, bytes: WGSLByteSource): void;
|
|
2259
|
+
copy(source: WGSLSlice, destination: WGSLSlice, size: number): void;
|
|
2260
|
+
clear(buffer: GPUBuffer, offset?: number, size?: number): void;
|
|
2261
|
+
flush(): void;
|
|
2262
|
+
submit(): void;
|
|
2263
|
+
execute(signal?: AbortSignal): Promise<void>;
|
|
2264
|
+
abort(): void;
|
|
2265
|
+
}
|
|
2266
|
+
|
|
2267
|
+
/**
|
|
2268
|
+
* Records dispatches, writes, copies, clears, and reads into one or more submissions.
|
|
2269
|
+
*
|
|
2270
|
+
* @remarks
|
|
2271
|
+
* Each `write`, `copy`, `clear`, `read`, and `flush` ends the open compute pass, and the next
|
|
2272
|
+
* `encode` begins a fresh one, so the commands run in the order the batch recorded them.
|
|
2273
|
+
*
|
|
2274
|
+
* @example
|
|
2275
|
+
* ```ts
|
|
2276
|
+
* const batch: WGSLBatchInterface = session.batch()
|
|
2277
|
+
* ```
|
|
2278
|
+
*/
|
|
2279
|
+
export declare interface WGSLBatchInterface {
|
|
2280
|
+
/** Reports whether the batch has been submitted. */
|
|
2281
|
+
readonly submitted: boolean;
|
|
2282
|
+
/**
|
|
2283
|
+
* Holds the trace of the batch after it settles, or `undefined` before settlement, when aborted
|
|
2284
|
+
* before submission, on fault, or when tracing is `'off'`.
|
|
2285
|
+
*/
|
|
2286
|
+
readonly trace: WGSLTraceRecord | undefined;
|
|
2287
|
+
/** Records one dispatch of a bound statement. */
|
|
2288
|
+
encode<S extends WGSLSlotMap, F extends WGSLFieldMap, O extends WGSLOverrideMap>(binding: WGSLBinding<S, F, O>, values: WGSLValueMap<F>, grid: WGSLGrid): void;
|
|
2289
|
+
/** Records a copy of a buffer range and resolves to its bytes after submission. */
|
|
2290
|
+
read(buffer: GPUBuffer, offset: number, size: number): Promise<ArrayBuffer>;
|
|
2291
|
+
/** Records copies of one or more buffer spans into one coalesced staging buffer and resolves to their bytes after submission. */
|
|
2292
|
+
read(spans: readonly WGSLSpan[]): Promise<readonly ArrayBuffer[]>;
|
|
2293
|
+
/**
|
|
2294
|
+
* Uploads caller bytes into `destination`, ordered after earlier recorded commands on the batch.
|
|
2295
|
+
*
|
|
2296
|
+
* @remarks
|
|
2297
|
+
* Flushes earlier recorded commands before invoking `GPUQueue.writeBuffer` so subsequent
|
|
2298
|
+
* dispatches and copies observe the uploaded bytes in recording order. Issuing a `batch.write`
|
|
2299
|
+
* call at segment start before dispatches, copies, or clears avoids flushing an empty command
|
|
2300
|
+
* encoder. Callers that need a
|
|
2301
|
+
* subrange slice their typed array with `subarray` or construct a `Uint8Array`/`DataView` view
|
|
2302
|
+
* over the `ArrayBuffer` without copying. The destination buffer needs `WGSL_USAGE.destination`,
|
|
2303
|
+
* `destination.offset` defaults to `0` and must be a non-negative safe multiple of 4, and
|
|
2304
|
+
* `bytes.byteLength` must be a safe multiple of 4 and at least 4 and fit inside the buffer.
|
|
2305
|
+
* Thrown with code `ARGUMENT` for a malformed slice, byte source, offset, or byte length; with
|
|
2306
|
+
* code `VALIDATION` when the batch is `submitted` or `aborted`; with code `DESTROYED` when the
|
|
2307
|
+
* session is destroyed; and with the failure's own code when the session has failed.
|
|
2308
|
+
*
|
|
2309
|
+
* @param destination - The buffer and byte offset to write into
|
|
2310
|
+
* @param bytes - The caller bytes to upload
|
|
2311
|
+
*/
|
|
2312
|
+
write(destination: WGSLSlice, bytes: WGSLByteSource): void;
|
|
2313
|
+
/**
|
|
2314
|
+
* Records a buffer-to-buffer copy of `size` bytes from `source` to `destination` outside any compute pass.
|
|
2315
|
+
*
|
|
2316
|
+
* @remarks
|
|
2317
|
+
* Mirrors `GPUCommandEncoder.copyBufferToBuffer`. The source buffer needs `WGSL_USAGE.source`, the
|
|
2318
|
+
* destination buffer needs `WGSL_USAGE.destination`, and the two must be distinct buffers. Default:
|
|
2319
|
+
* `0` for each slice's `offset`. Thrown when a slice is not an object, a buffer lacks its usage,
|
|
2320
|
+
* both slices hold one buffer, an offset is not a non-negative safe multiple of 4, `size` is not a
|
|
2321
|
+
* safe multiple of 4 and at least 4, or either range passes its buffer's end, with code `ARGUMENT`.
|
|
2322
|
+
* Thrown when the batch is `submitted` or `aborted`, with code `VALIDATION`. Thrown when the
|
|
2323
|
+
* session is destroyed, with code `DESTROYED`, and when the session has failed, with the failure's
|
|
2324
|
+
* own code.
|
|
2325
|
+
*
|
|
2326
|
+
* @param source - The buffer and byte offset to copy from
|
|
2327
|
+
* @param destination - The buffer and byte offset to copy to
|
|
2328
|
+
* @param size - The byte count to copy
|
|
2329
|
+
*/
|
|
2330
|
+
copy(source: WGSLSlice, destination: WGSLSlice, size: number): void;
|
|
2331
|
+
/**
|
|
2332
|
+
* Records a zero fill of a range of `buffer` outside any compute pass.
|
|
2333
|
+
*
|
|
2334
|
+
* @remarks
|
|
2335
|
+
* Mirrors `GPUCommandEncoder.clearBuffer`. The buffer needs `WGSL_USAGE.destination`. Default: `0`
|
|
2336
|
+
* for `offset`, and `buffer.size - offset` for `size`, so `clear(buffer)` zeroes the whole buffer.
|
|
2337
|
+
* Thrown when the buffer lacks its usage, `offset` is not a non-negative safe multiple of 4, the
|
|
2338
|
+
* resolved size is not a safe multiple of 4 and at least 4, or the range passes the buffer's end,
|
|
2339
|
+
* with code `ARGUMENT`; `clear(buffer, buffer.size)` resolves a size of `0` and throws with code
|
|
2340
|
+
* `ARGUMENT`. Thrown when the batch is `submitted` or `aborted`, with code `VALIDATION`. Thrown
|
|
2341
|
+
* when the session is destroyed, with code `DESTROYED`, and when the session has failed, with the
|
|
2342
|
+
* failure's own code.
|
|
2343
|
+
*
|
|
2344
|
+
* @param buffer - The buffer to zero
|
|
2345
|
+
* @param offset - The byte offset where the zero fill starts
|
|
2346
|
+
* @param size - The byte count to zero
|
|
2347
|
+
*/
|
|
2348
|
+
clear(buffer: GPUBuffer, offset?: number, size?: number): void;
|
|
2349
|
+
/**
|
|
2350
|
+
* Submits the commands recorded after the batch opened or after the previous flush, outside any
|
|
2351
|
+
* open compute pass, and continues on a fresh encoder.
|
|
2352
|
+
*
|
|
2353
|
+
* @remarks
|
|
2354
|
+
* Uploads and clears the uniform slab beside the encoder submission so a long batch can flush at
|
|
2355
|
+
* chunk boundaries while settling once at `execute`. When nothing was recorded after the batch
|
|
2356
|
+
* opened or after the previous `flush`, it returns without submitting. Thrown when the batch is
|
|
2357
|
+
* `submitted` or `aborted`, with code `VALIDATION`; when the session is destroyed, with code
|
|
2358
|
+
* `DESTROYED`; and when the session has failed, with the failure's own code.
|
|
2359
|
+
*/
|
|
2360
|
+
flush(): void;
|
|
532
2361
|
/** Hands the recorded commands to the device queue. */
|
|
533
2362
|
submit(): void;
|
|
534
2363
|
/** Submits the batch and resolves when the device finishes it. */
|
|
@@ -538,332 +2367,934 @@ export declare interface WGSLBatchInterface {
|
|
|
538
2367
|
}
|
|
539
2368
|
|
|
540
2369
|
/**
|
|
541
|
-
* Configures a batch: the session's slab and the session hooks the batch reports its lifecycle to.
|
|
2370
|
+
* Configures a batch: the session's slab and the session hooks the batch reports its lifecycle to.
|
|
2371
|
+
*
|
|
2372
|
+
* @remarks
|
|
2373
|
+
* `check` throws when the session can no longer run commands. `lease` hands out a staging buffer of
|
|
2374
|
+
* at least `size` bytes and `restore` takes it back. `release` frees the session's open-batch slot
|
|
2375
|
+
* when the batch is submitted or aborted. `fail` records a submitted batch's device failure as the
|
|
2376
|
+
* session's terminal failure. `track` registers a settling promise that `destroy` waits for; the
|
|
2377
|
+
* promise never rejects. `trace` sets the tracer's mode and pass capacity. `queries` and
|
|
2378
|
+
* `timestamps` are the session's timestamp query set and the buffer it resolves into, both
|
|
2379
|
+
* `undefined` when tracing is `'off'` or the device lacks `'timestamp-query'`. `record` receives a
|
|
2380
|
+
* traced batch's record when the batch settles.
|
|
2381
|
+
*
|
|
2382
|
+
* @example
|
|
2383
|
+
* ```ts
|
|
2384
|
+
* const batch = new WGSLBatch(device, {
|
|
2385
|
+
* slab,
|
|
2386
|
+
* check,
|
|
2387
|
+
* lease,
|
|
2388
|
+
* restore,
|
|
2389
|
+
* release,
|
|
2390
|
+
* fail,
|
|
2391
|
+
* track,
|
|
2392
|
+
* trace: { mode: 'off', capacity: 512 },
|
|
2393
|
+
* queries: undefined,
|
|
2394
|
+
* timestamps: undefined,
|
|
2395
|
+
* record,
|
|
2396
|
+
* })
|
|
2397
|
+
* ```
|
|
2398
|
+
*/
|
|
2399
|
+
export declare interface WGSLBatchOptions {
|
|
2400
|
+
/** Holds the session's uniform slab. */
|
|
2401
|
+
readonly slab: WGSLSlabInterface;
|
|
2402
|
+
/** Throws when the session is failed or destroyed. */
|
|
2403
|
+
readonly check: () => void;
|
|
2404
|
+
/** Hands out an idle staging buffer of at least `size` bytes. */
|
|
2405
|
+
readonly lease: (size: number) => GPUBuffer;
|
|
2406
|
+
/** Takes back a staging buffer `lease` handed out. */
|
|
2407
|
+
readonly restore: (buffer: GPUBuffer) => void;
|
|
2408
|
+
/** Frees the session's open-batch slot. */
|
|
2409
|
+
readonly release: (batch: WGSLBatchInterface) => void;
|
|
2410
|
+
/** Records a submitted batch's device failure as the session's terminal failure. */
|
|
2411
|
+
readonly fail: (error: WGSLError) => void;
|
|
2412
|
+
/** Registers a promise that settles when the batch's device work and reads finish. */
|
|
2413
|
+
readonly track: (work: Promise<unknown>) => void;
|
|
2414
|
+
/** Holds the tracer's mode and the most passes one batch records. */
|
|
2415
|
+
readonly trace: Required<WGSLTraceOptions>;
|
|
2416
|
+
/** Holds the session's timestamp query set, or `undefined` when the batch records no GPU time. */
|
|
2417
|
+
readonly queries: GPUQuerySet | undefined;
|
|
2418
|
+
/** Holds the buffer the query set resolves into, or `undefined` when the batch records no GPU time. */
|
|
2419
|
+
readonly timestamps: GPUBuffer | undefined;
|
|
2420
|
+
/** Receives a traced batch's record when the batch settles. */
|
|
2421
|
+
readonly record: (record: WGSLTraceRecord) => void;
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
/**
|
|
2425
|
+
* Names the lifecycle status of a batch.
|
|
2426
|
+
*
|
|
2427
|
+
* @remarks
|
|
2428
|
+
* `open` records dispatches, writes, reads, copies, and clears, `submitted` has handed its
|
|
2429
|
+
* commands to the queue, and `aborted` discarded its unsubmitted commands. A `write`, `copy`, or
|
|
2430
|
+
* `clear` on a `submitted` or `aborted` batch throws with code `VALIDATION`.
|
|
2431
|
+
*
|
|
2432
|
+
* @example
|
|
2433
|
+
* ```ts
|
|
2434
|
+
* const status: WGSLBatchStatus = 'submitted'
|
|
2435
|
+
* ```
|
|
2436
|
+
*/
|
|
2437
|
+
export declare type WGSLBatchStatus = 'open' | 'submitted' | 'aborted';
|
|
2438
|
+
|
|
2439
|
+
/**
|
|
2440
|
+
* Holds a statement's storage bind group for one set of slot buffers.
|
|
2441
|
+
*
|
|
2442
|
+
* @example
|
|
2443
|
+
* ```ts
|
|
2444
|
+
* const binding: WGSLBinding<typeof slots, { rows: 'u32' }> = statement.bind({ destination: { buffer } })
|
|
2445
|
+
* ```
|
|
2446
|
+
*/
|
|
2447
|
+
export declare interface WGSLBinding<S extends WGSLSlotMap, F extends WGSLFieldMap, O extends WGSLOverrideMap = WGSLOverrideMap> {
|
|
2448
|
+
/** Holds the statement the binding belongs to. */
|
|
2449
|
+
readonly statement: WGSLStatementInterface<S, F, O>;
|
|
2450
|
+
/** Holds the storage bind group. */
|
|
2451
|
+
readonly group: GPUBindGroup;
|
|
2452
|
+
}
|
|
2453
|
+
|
|
2454
|
+
/**
|
|
2455
|
+
* Holds one level of a statement's bind cache: the next level for each slot's buffer, offset, and size, and the binding a complete path reaches.
|
|
2456
|
+
*
|
|
2457
|
+
* @remarks
|
|
2458
|
+
* Level `N` keys slot `N`'s range, so a path of one entry per slot ends at the node whose `binding`
|
|
2459
|
+
* is set; every inner node's `binding` is `undefined`. The outer `WeakMap` lets a buffer's entries
|
|
2460
|
+
* leave with the buffer.
|
|
2461
|
+
*
|
|
2462
|
+
* @example
|
|
2463
|
+
* ```ts
|
|
2464
|
+
* const node: WGSLBindingNode<typeof slots, { rows: 'u32' }> = { next: new WeakMap(), binding: undefined }
|
|
2465
|
+
* ```
|
|
2466
|
+
*/
|
|
2467
|
+
export declare interface WGSLBindingNode<S extends WGSLSlotMap, F extends WGSLFieldMap, O extends WGSLOverrideMap = WGSLOverrideMap> {
|
|
2468
|
+
/** Maps each slot buffer, then its byte offset, then its byte size, to the next level. */
|
|
2469
|
+
readonly next: WeakMap<GPUBuffer, Map<number, Map<number, WGSLBindingNode<S, F, O>>>>;
|
|
2470
|
+
/** Holds the binding a complete path reaches, or `undefined` on an inner level. */
|
|
2471
|
+
readonly binding: WGSLBinding<S, F, O> | undefined;
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
/**
|
|
2475
|
+
* Carries the input `createWGSLBroadcast` builds a workgroup-broadcast fragment from.
|
|
2476
|
+
*
|
|
2477
|
+
* @example
|
|
2478
|
+
* ```ts
|
|
2479
|
+
* const input: WGSLBroadcastInput = { workgroup: 64, element: 'f32' }
|
|
2480
|
+
* ```
|
|
2481
|
+
*/
|
|
2482
|
+
export declare interface WGSLBroadcastInput {
|
|
2483
|
+
/** Names the fragment. Default: a name built from `element` and `workgroup`. */
|
|
2484
|
+
readonly name?: string;
|
|
2485
|
+
/** Holds the workgroup invocation count the broadcast needs. */
|
|
2486
|
+
readonly workgroup: WGSLWorkgroup;
|
|
2487
|
+
/** Names the element type broadcast. */
|
|
2488
|
+
readonly element: WGSLScalar;
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
/**
|
|
2492
|
+
* Carries caller bytes uploaded to a GPU buffer.
|
|
2493
|
+
*
|
|
2494
|
+
* @example
|
|
2495
|
+
* ```ts
|
|
2496
|
+
* const bytes: WGSLByteSource = new Float32Array([1, 2, 3, 4])
|
|
2497
|
+
* ```
|
|
2498
|
+
*/
|
|
2499
|
+
export declare type WGSLByteSource = ArrayBuffer | ArrayBufferView;
|
|
2500
|
+
|
|
2501
|
+
/**
|
|
2502
|
+
* Carries the input `createWGSLCompact` builds a workgroup stream-compaction fragment from.
|
|
2503
|
+
*
|
|
2504
|
+
* @remarks
|
|
2505
|
+
* The emitted function returns each lane's `0`-based exclusive `offset` count of preceding kept
|
|
2506
|
+
* lanes and the workgroup-wide `total` count of kept lanes. Every lane receives the same `total`
|
|
2507
|
+
* value (the `sgCount` value when `num_subgroups == 1` on the 1D ballot path, or a
|
|
2508
|
+
* `workgroupUniformLoad` read otherwise). Because WGSL static uniformity analysis taints a
|
|
2509
|
+
* returned `struct` carrying a per-lane `offset` field, callers branching before a barrier must
|
|
2510
|
+
* reload the `total` count through a `workgroupUniformLoad` call, or pair with the `WGSL_JOIN`
|
|
2511
|
+
* fragment or the `createWGSLBroadcast` factory.
|
|
2512
|
+
*
|
|
2513
|
+
* @example
|
|
2514
|
+
* ```ts
|
|
2515
|
+
* const input: WGSLCompactInput = { workgroup: 256 }
|
|
2516
|
+
* ```
|
|
2517
|
+
*/
|
|
2518
|
+
export declare interface WGSLCompactInput {
|
|
2519
|
+
/** Names the fragment. Default: a name built from `workgroup`. */
|
|
2520
|
+
readonly name?: string;
|
|
2521
|
+
/** Holds the workgroup invocation count the compaction needs. */
|
|
2522
|
+
readonly workgroup: WGSLWorkgroup;
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
/**
|
|
2526
|
+
* Maps declared pipeline-overridable constant names of a program to element-matched specialization values.
|
|
2527
|
+
*
|
|
2528
|
+
* @remarks
|
|
2529
|
+
* Each `'bool'` override maps to `boolean` and each numeric override maps to `number`. Overrides
|
|
2530
|
+
* declared without a default `value` are required keys; overrides with a default `value` are
|
|
2531
|
+
* optional. A program with no overrides admits only `{}` and refuses undeclared keys.
|
|
2532
|
+
*
|
|
2533
|
+
* @example
|
|
2534
|
+
* ```ts
|
|
2535
|
+
* const constants: WGSLConstantMap<{ SCALE: { element: 'f32'; value: 1 }; COUNT: { element: 'u32' } }> = { COUNT: 64, SCALE: 0.5 }
|
|
2536
|
+
* ```
|
|
2537
|
+
*/
|
|
2538
|
+
export declare type WGSLConstantMap<O extends WGSLOverrideMap = WGSLOverrideMap> = [
|
|
2539
|
+
keyof O & string
|
|
2540
|
+
] extends [never] ? Readonly<Record<string, never>> : {
|
|
2541
|
+
readonly [K in keyof O & string as 'value' extends keyof O[K] ? never : K]: O[K] extends infer D ? (D extends {
|
|
2542
|
+
readonly element: 'bool';
|
|
2543
|
+
} ? boolean : number) : never;
|
|
2544
|
+
} & {
|
|
2545
|
+
readonly [K in keyof O & string as 'value' extends keyof O[K] ? K : never]?: O[K] extends infer D ? (D extends {
|
|
2546
|
+
readonly element: 'bool';
|
|
2547
|
+
} ? boolean : number) : never;
|
|
2548
|
+
};
|
|
2549
|
+
|
|
2550
|
+
/**
|
|
2551
|
+
* Declares a program's compute entry point: its function name, its workgroup size, and its body.
|
|
2552
|
+
*
|
|
2553
|
+
* @example
|
|
2554
|
+
* ```ts
|
|
2555
|
+
* const entry: WGSLEntry = { name: 'main', size: [64, 1, 1], source: 'destination[invocation.local_invocation_index] = 0.0;' }
|
|
2556
|
+
* ```
|
|
2557
|
+
*/
|
|
2558
|
+
export declare interface WGSLEntry {
|
|
2559
|
+
/** Names the entry point function. */
|
|
2560
|
+
readonly name: string;
|
|
2561
|
+
/** Holds the workgroup size on each axis. */
|
|
2562
|
+
readonly size: WGSLGrid;
|
|
2563
|
+
/** Holds the entry point's WGSL body. */
|
|
2564
|
+
readonly source: string;
|
|
2565
|
+
}
|
|
2566
|
+
|
|
2567
|
+
/**
|
|
2568
|
+
* Reports one WGSL failure under a stable condition code.
|
|
2569
|
+
*
|
|
2570
|
+
* @remarks
|
|
2571
|
+
* Every refusal the factories, the linker, the helpers, and the slab raise arrives as one of these,
|
|
2572
|
+
* so a caller branches on `code` rather than on message text. Narrow a caught value with
|
|
2573
|
+
* `isWGSLError` before reading `code`.
|
|
2574
|
+
*
|
|
2575
|
+
* @example
|
|
2576
|
+
* ```ts
|
|
2577
|
+
* const error = new WGSLError('The slab capacity must be a multiple of 4.', { code: 'ARGUMENT' })
|
|
2578
|
+
* error.code // 'ARGUMENT'
|
|
2579
|
+
* ```
|
|
2580
|
+
*/
|
|
2581
|
+
export declare class WGSLError extends Error {
|
|
2582
|
+
readonly name = "WGSLError";
|
|
2583
|
+
readonly code: WGSLErrorCode;
|
|
2584
|
+
readonly context: Readonly<Record<string, unknown>> | undefined;
|
|
2585
|
+
/**
|
|
2586
|
+
* Creates one classified WGSL failure.
|
|
2587
|
+
*
|
|
2588
|
+
* @param message - Human-readable description of what failed
|
|
2589
|
+
* @param options - The condition, optional structured context, and optional cause
|
|
2590
|
+
*/
|
|
2591
|
+
constructor(message: string, options: WGSLErrorOptions);
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
/**
|
|
2595
|
+
* Names the condition a `WGSLError` reports.
|
|
2596
|
+
*
|
|
2597
|
+
* @example
|
|
2598
|
+
* ```ts
|
|
2599
|
+
* const code: WGSLErrorCode = 'VALIDATION'
|
|
2600
|
+
* ```
|
|
2601
|
+
*/
|
|
2602
|
+
export declare type WGSLErrorCode = (typeof WGSL_ERROR_CODES)[number];
|
|
2603
|
+
|
|
2604
|
+
/**
|
|
2605
|
+
* Configures one WGSL failure's condition, optional context, and optional cause.
|
|
2606
|
+
*
|
|
2607
|
+
* @example
|
|
2608
|
+
* ```ts
|
|
2609
|
+
* const options: WGSLErrorOptions = { code: 'LIMIT', context: { total: 70000 } }
|
|
2610
|
+
* ```
|
|
2611
|
+
*/
|
|
2612
|
+
export declare interface WGSLErrorOptions {
|
|
2613
|
+
/** Names the failure's condition. */
|
|
2614
|
+
readonly code: WGSLErrorCode;
|
|
2615
|
+
/** Holds the values that locate the failure. */
|
|
2616
|
+
readonly context?: Readonly<Record<string, unknown>>;
|
|
2617
|
+
/** Holds the failure this one wraps, kept without coercion. */
|
|
2618
|
+
readonly cause?: unknown;
|
|
2619
|
+
}
|
|
2620
|
+
|
|
2621
|
+
/**
|
|
2622
|
+
* Names a WGSL extension a fragment variant can enable.
|
|
2623
|
+
*
|
|
2624
|
+
* @example
|
|
2625
|
+
* ```ts
|
|
2626
|
+
* const extension: WGSLExtension = 'subgroups'
|
|
2627
|
+
* ```
|
|
2628
|
+
*/
|
|
2629
|
+
export declare type WGSLExtension = keyof typeof WGSL_EXTENSIONS;
|
|
2630
|
+
|
|
2631
|
+
/**
|
|
2632
|
+
* Maps each uniform struct field name to its scalar type, in declaration order.
|
|
2633
|
+
*
|
|
2634
|
+
* @example
|
|
2635
|
+
* ```ts
|
|
2636
|
+
* const fields: WGSLFieldMap = { rows: 'u32', epsilon: 'f32' }
|
|
2637
|
+
* ```
|
|
2638
|
+
*/
|
|
2639
|
+
export declare type WGSLFieldMap = Readonly<Record<string, WGSLScalar>>;
|
|
2640
|
+
|
|
2641
|
+
/**
|
|
2642
|
+
* Holds a pair of `f32` numbers whose sum `head + tail` represents an extended-precision value.
|
|
2643
|
+
*
|
|
2644
|
+
* @remarks
|
|
2645
|
+
* Mirrors `struct FloatPair { head: f32, tail: f32 }` in `WGSL_EFT` for `WGSL_DOUBLE`,
|
|
2646
|
+
* `encodeWGSLDouble`, and `decodeWGSLDouble`. `head` holds the leading `f32` component and `tail`
|
|
2647
|
+
* holds the residual `f32` component.
|
|
2648
|
+
*
|
|
2649
|
+
* @example
|
|
2650
|
+
* ```ts
|
|
2651
|
+
* const pair: WGSLFloatPair = { head: 1, tail: 0 }
|
|
2652
|
+
* ```
|
|
2653
|
+
*/
|
|
2654
|
+
export declare interface WGSLFloatPair {
|
|
2655
|
+
/** Holds the leading `f32` component. */
|
|
2656
|
+
readonly head: number;
|
|
2657
|
+
/** Holds the residual `f32` component. */
|
|
2658
|
+
readonly tail: number;
|
|
2659
|
+
}
|
|
2660
|
+
|
|
2661
|
+
/**
|
|
2662
|
+
* Describes a named piece of author-written WGSL text, its dependencies, and its conditional variants.
|
|
2663
|
+
*
|
|
2664
|
+
* @example
|
|
2665
|
+
* ```ts
|
|
2666
|
+
* const fragment: WGSLFragment = createWGSLFragment({ name: 'square', source: 'fn square(value: f32) -> f32 { return value * value; }' })
|
|
2667
|
+
* ```
|
|
2668
|
+
*/
|
|
2669
|
+
export declare interface WGSLFragment {
|
|
2670
|
+
/** Names the fragment; a linked program holds one fragment per name. */
|
|
2671
|
+
readonly name: string;
|
|
2672
|
+
/** Holds the fragment's default WGSL text. */
|
|
2673
|
+
readonly source: string;
|
|
2674
|
+
/** Lists the fragments this fragment's text calls. */
|
|
2675
|
+
readonly uses: readonly WGSLFragment[];
|
|
2676
|
+
/** Lists the conditional bodies evaluated in order before falling back to `source`. */
|
|
2677
|
+
readonly variants: readonly WGSLVariant[];
|
|
2678
|
+
/** Holds the exact workgroup invocation count (`x * y * z`) the fragment's shared memory requires, if any. */
|
|
2679
|
+
readonly workgroup?: number;
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2682
|
+
/**
|
|
2683
|
+
* Carries the input `createWGSLFragment` builds a fragment from.
|
|
542
2684
|
*
|
|
543
2685
|
* @remarks
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
* when the batch is submitted or aborted. `fail` records a submitted batch's device failure as the
|
|
547
|
-
* session's terminal failure. `track` registers a settling promise that `destroy` waits for; the
|
|
548
|
-
* promise never rejects.
|
|
2686
|
+
* Each entry in `variants` must declare at least one of `extensions`, `languages`, `subgroup`, or
|
|
2687
|
+
* `linear`; `createWGSLFragment` refuses an unconstrained variant with code `ARGUMENT`.
|
|
549
2688
|
*
|
|
550
2689
|
* @example
|
|
551
2690
|
* ```ts
|
|
552
|
-
* const
|
|
2691
|
+
* const input: WGSLFragmentInput = { name: 'square', source: 'fn square(value: f32) -> f32 { return value * value; }' }
|
|
553
2692
|
* ```
|
|
554
2693
|
*/
|
|
555
|
-
export declare interface
|
|
556
|
-
/**
|
|
557
|
-
readonly
|
|
558
|
-
/**
|
|
559
|
-
readonly
|
|
560
|
-
/**
|
|
561
|
-
readonly
|
|
562
|
-
/**
|
|
563
|
-
readonly
|
|
564
|
-
/**
|
|
565
|
-
readonly
|
|
566
|
-
/** Records a submitted batch's device failure as the session's terminal failure. */
|
|
567
|
-
readonly fail: (error: WGSLError) => void;
|
|
568
|
-
/** Registers a promise that settles when the batch's device work and reads finish. */
|
|
569
|
-
readonly track: (work: Promise<unknown>) => void;
|
|
2694
|
+
export declare interface WGSLFragmentInput {
|
|
2695
|
+
/** Names the fragment. */
|
|
2696
|
+
readonly name: string;
|
|
2697
|
+
/** Holds the fragment's default WGSL text. */
|
|
2698
|
+
readonly source: string;
|
|
2699
|
+
/** Lists the fragments this fragment's text calls. Default: none. */
|
|
2700
|
+
readonly uses?: readonly WGSLFragment[];
|
|
2701
|
+
/** Lists the conditional bodies evaluated in order before falling back to `source`. Default: none. */
|
|
2702
|
+
readonly variants?: readonly WGSLVariant[];
|
|
2703
|
+
/** Holds the exact workgroup invocation count (`x * y * z`) the fragment's shared memory requires, if any. */
|
|
2704
|
+
readonly workgroup?: number;
|
|
570
2705
|
}
|
|
571
2706
|
|
|
572
2707
|
/**
|
|
573
|
-
*
|
|
2708
|
+
* Holds a count on each of the x, y, and z axes: a workgroup size or a dispatch's workgroup counts.
|
|
2709
|
+
*
|
|
2710
|
+
* @example
|
|
2711
|
+
* ```ts
|
|
2712
|
+
* const grid: WGSLGrid = [64, 1, 1]
|
|
2713
|
+
* ```
|
|
2714
|
+
*/
|
|
2715
|
+
export declare type WGSLGrid = readonly [x: number, y: number, z: number];
|
|
2716
|
+
|
|
2717
|
+
/**
|
|
2718
|
+
* Carries the input `createWGSLHistogram` builds a workgroup histogram fragment from.
|
|
574
2719
|
*
|
|
575
2720
|
* @remarks
|
|
576
|
-
*
|
|
577
|
-
* `aborted` discarded its unsubmitted commands.
|
|
2721
|
+
* Supports bin counts independent of `workgroup`, including `bins` greater than `workgroup`.
|
|
578
2722
|
*
|
|
579
2723
|
* @example
|
|
580
2724
|
* ```ts
|
|
581
|
-
* const
|
|
2725
|
+
* const input: WGSLHistogramInput = { workgroup: 64, bins: 256 }
|
|
582
2726
|
* ```
|
|
583
2727
|
*/
|
|
584
|
-
export declare
|
|
2728
|
+
export declare interface WGSLHistogramInput {
|
|
2729
|
+
/** Names the fragment. Default: a name built from `bins` and `workgroup`. */
|
|
2730
|
+
readonly name?: string;
|
|
2731
|
+
/** Holds the workgroup invocation count the histogram needs. */
|
|
2732
|
+
readonly workgroup: WGSLWorkgroup;
|
|
2733
|
+
/** Holds the number of histogram bins allocated in workgroup memory. */
|
|
2734
|
+
readonly bins: WGSLHistogramSize;
|
|
2735
|
+
}
|
|
585
2736
|
|
|
586
2737
|
/**
|
|
587
|
-
* Holds a
|
|
2738
|
+
* Holds a bin count supported by `createWGSLHistogram`.
|
|
588
2739
|
*
|
|
589
2740
|
* @example
|
|
590
2741
|
* ```ts
|
|
591
|
-
* const
|
|
2742
|
+
* const bins: WGSLHistogramSize = 64
|
|
592
2743
|
* ```
|
|
593
2744
|
*/
|
|
594
|
-
export declare
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
2745
|
+
export declare type WGSLHistogramSize = (typeof WGSL_HISTOGRAM_SIZES)[number];
|
|
2746
|
+
|
|
2747
|
+
/**
|
|
2748
|
+
* Names a WGSL language extension a fragment variant can require.
|
|
2749
|
+
*
|
|
2750
|
+
* @example
|
|
2751
|
+
* ```ts
|
|
2752
|
+
* const language: WGSLLanguage = 'subgroup_id'
|
|
2753
|
+
* ```
|
|
2754
|
+
*/
|
|
2755
|
+
export declare type WGSLLanguage = (typeof WGSL_LANGUAGES)[number];
|
|
2756
|
+
|
|
2757
|
+
/**
|
|
2758
|
+
* Describes one uniform struct member: its name, its scalar type, and its offset in 32-bit words.
|
|
2759
|
+
*
|
|
2760
|
+
* @example
|
|
2761
|
+
* ```ts
|
|
2762
|
+
* const member: WGSLMember = { name: 'epsilon', element: 'f32', word: 1 }
|
|
2763
|
+
* ```
|
|
2764
|
+
*/
|
|
2765
|
+
export declare interface WGSLMember {
|
|
2766
|
+
/** Names the member. */
|
|
2767
|
+
readonly name: string;
|
|
2768
|
+
/** Names the member's scalar type. */
|
|
2769
|
+
readonly element: WGSLScalar;
|
|
2770
|
+
/** Holds the member's offset from the struct's start, in 32-bit words. */
|
|
2771
|
+
readonly word: number;
|
|
599
2772
|
}
|
|
600
2773
|
|
|
601
2774
|
/**
|
|
602
|
-
*
|
|
2775
|
+
* Names the online monoid state a monoid reduction merges.
|
|
2776
|
+
*
|
|
2777
|
+
* @example
|
|
2778
|
+
* ```ts
|
|
2779
|
+
* const monoid: WGSLMonoid = 'exp'
|
|
2780
|
+
* ```
|
|
2781
|
+
*/
|
|
2782
|
+
export declare type WGSLMonoid = (typeof WGSL_MONOIDS)[number];
|
|
2783
|
+
|
|
2784
|
+
/**
|
|
2785
|
+
* Carries the input `createWGSLMonoidReduce` builds an online monoid reduction fragment from.
|
|
603
2786
|
*
|
|
604
2787
|
* @remarks
|
|
605
|
-
*
|
|
606
|
-
* is set; every inner node's `binding` is `undefined`. The outer `WeakMap` lets a buffer's entries
|
|
607
|
-
* leave with the buffer.
|
|
2788
|
+
* `width` defaults to `workgroup` and must not exceed `workgroup`.
|
|
608
2789
|
*
|
|
609
2790
|
* @example
|
|
610
2791
|
* ```ts
|
|
611
|
-
* const
|
|
2792
|
+
* const input: WGSLMonoidReduceInput = { workgroup: 64, monoid: 'exp' }
|
|
612
2793
|
* ```
|
|
613
2794
|
*/
|
|
614
|
-
export declare interface
|
|
615
|
-
/**
|
|
616
|
-
readonly
|
|
617
|
-
/** Holds the
|
|
618
|
-
readonly
|
|
2795
|
+
export declare interface WGSLMonoidReduceInput {
|
|
2796
|
+
/** Names the fragment. Default: a name built from `monoid`, `workgroup`, and `width`. */
|
|
2797
|
+
readonly name?: string;
|
|
2798
|
+
/** Holds the workgroup invocation count the reduction needs. */
|
|
2799
|
+
readonly workgroup: WGSLWorkgroup;
|
|
2800
|
+
/** Holds the partition width reduced independently inside each workgroup. Default: `workgroup`. */
|
|
2801
|
+
readonly width?: WGSLReduceWidth;
|
|
2802
|
+
/** Names the online monoid state reduced (`'exp'`, `'moments'`, or `'compensated'`). */
|
|
2803
|
+
readonly monoid: WGSLMonoid;
|
|
619
2804
|
}
|
|
620
2805
|
|
|
621
2806
|
/**
|
|
622
|
-
* Declares
|
|
2807
|
+
* Declares one pipeline-overridable constant of a program: its scalar type, optional default value, and optional numeric id.
|
|
2808
|
+
*
|
|
2809
|
+
* @remarks
|
|
2810
|
+
* A `'bool'` override takes a `boolean` default; `'u32'`, `'i32'`, and `'f32'` overrides take a
|
|
2811
|
+
* `number` default. Omitting `value` requires callers to supply that constant at `prepare`.
|
|
623
2812
|
*
|
|
624
2813
|
* @example
|
|
625
2814
|
* ```ts
|
|
626
|
-
* const
|
|
2815
|
+
* const constant: WGSLOverride = { element: 'f32', value: 1.0, id: 0 }
|
|
627
2816
|
* ```
|
|
628
2817
|
*/
|
|
629
|
-
export declare
|
|
630
|
-
/** Names the
|
|
631
|
-
readonly
|
|
632
|
-
/** Holds the
|
|
633
|
-
readonly
|
|
634
|
-
/** Holds the
|
|
635
|
-
readonly
|
|
636
|
-
}
|
|
2818
|
+
export declare type WGSLOverride = {
|
|
2819
|
+
/** Names the boolean WGSL scalar type. */
|
|
2820
|
+
readonly element: Extract<WGSLOverrideScalar, 'bool'>;
|
|
2821
|
+
/** Holds the default boolean value rendered in WGSL, or omitted when pipeline preparation must supply one. */
|
|
2822
|
+
readonly value?: boolean;
|
|
2823
|
+
/** Holds the optional `@id(N)` numeric constant identifier (0 to 65535). */
|
|
2824
|
+
readonly id?: number;
|
|
2825
|
+
} | {
|
|
2826
|
+
/** Names a numeric WGSL scalar type. */
|
|
2827
|
+
readonly element: Exclude<WGSLOverrideScalar, 'bool'>;
|
|
2828
|
+
/** Holds the default numeric value rendered in WGSL, or omitted when pipeline preparation must supply one. */
|
|
2829
|
+
readonly value?: number;
|
|
2830
|
+
/** Holds the optional `@id(N)` numeric constant identifier (0 to 65535). */
|
|
2831
|
+
readonly id?: number;
|
|
2832
|
+
};
|
|
637
2833
|
|
|
638
2834
|
/**
|
|
639
|
-
*
|
|
2835
|
+
* Maps each pipeline-overridable constant name of a program to its declaration, in render order.
|
|
2836
|
+
*
|
|
2837
|
+
* @example
|
|
2838
|
+
* ```ts
|
|
2839
|
+
* const overrides: WGSLOverrideMap = { SCALE: { element: 'f32', value: 1.0 } }
|
|
2840
|
+
* ```
|
|
2841
|
+
*/
|
|
2842
|
+
export declare type WGSLOverrideMap = Readonly<Record<string, WGSLOverride>>;
|
|
2843
|
+
|
|
2844
|
+
/**
|
|
2845
|
+
* Names a scalar type a pipeline-overridable constant can declare.
|
|
2846
|
+
*
|
|
2847
|
+
* @example
|
|
2848
|
+
* ```ts
|
|
2849
|
+
* const scalar: WGSLOverrideScalar = 'bool'
|
|
2850
|
+
* ```
|
|
2851
|
+
*/
|
|
2852
|
+
export declare type WGSLOverrideScalar = (typeof WGSL_OVERRIDE_SCALARS)[number];
|
|
2853
|
+
|
|
2854
|
+
/**
|
|
2855
|
+
* Carries the input `createWGSLPairSort` builds a workgroup key-index pair sort fragment from.
|
|
640
2856
|
*
|
|
641
2857
|
* @remarks
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
* `isWGSLError` before reading `code`.
|
|
2858
|
+
* Equal keys resolve ties by ascending `u32` index. `width` defaults to `workgroup` and must not
|
|
2859
|
+
* exceed `workgroup`.
|
|
645
2860
|
*
|
|
646
2861
|
* @example
|
|
647
2862
|
* ```ts
|
|
648
|
-
* const
|
|
649
|
-
* error.code // 'ARGUMENT'
|
|
2863
|
+
* const input: WGSLPairSortInput = { workgroup: 128, order: 'descending', element: 'f32' }
|
|
650
2864
|
* ```
|
|
651
2865
|
*/
|
|
652
|
-
export declare
|
|
653
|
-
|
|
654
|
-
readonly
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
2866
|
+
export declare interface WGSLPairSortInput {
|
|
2867
|
+
/** Names the fragment. Default: a name built from `order`, `element`, `workgroup`, and `width`. */
|
|
2868
|
+
readonly name?: string;
|
|
2869
|
+
/** Holds the workgroup invocation count the sort needs. */
|
|
2870
|
+
readonly workgroup: WGSLWorkgroup;
|
|
2871
|
+
/** Holds the partition width sorted independently inside each workgroup. Default: `workgroup`. */
|
|
2872
|
+
readonly width?: WGSLReduceWidth;
|
|
2873
|
+
/** Names the sort direction for keys. */
|
|
2874
|
+
readonly order: WGSLSortOrder;
|
|
2875
|
+
/** Names the key element type sorted beside each `u32` index. */
|
|
2876
|
+
readonly element: WGSLScalar;
|
|
663
2877
|
}
|
|
664
2878
|
|
|
665
2879
|
/**
|
|
666
|
-
*
|
|
2880
|
+
* Carries the input `createWGSLPartition` builds a workgroup stable-partition fragment from.
|
|
2881
|
+
*
|
|
2882
|
+
* @remarks
|
|
2883
|
+
* The emitted function returns each lane's stable output `offset` index and the workgroup-wide
|
|
2884
|
+
* `pivot` count separating kept lanes (`0 .. pivot - 1`) from unkept lanes
|
|
2885
|
+
* (`pivot .. workgroup - 1`). Every lane receives the same `pivot` value (the `sgCount` value when
|
|
2886
|
+
* `num_subgroups == 1` on the 1D ballot path, or a `workgroupUniformLoad` read otherwise). Because
|
|
2887
|
+
* WGSL static uniformity analysis taints a returned `struct` carrying a per-lane `offset` field,
|
|
2888
|
+
* callers branching before a barrier must reload the `pivot` count through a
|
|
2889
|
+
* `workgroupUniformLoad` call, or pair with the `WGSL_JOIN` fragment or the `createWGSLBroadcast`
|
|
2890
|
+
* factory.
|
|
667
2891
|
*
|
|
668
2892
|
* @example
|
|
669
2893
|
* ```ts
|
|
670
|
-
* const
|
|
2894
|
+
* const input: WGSLPartitionInput = { workgroup: 256 }
|
|
671
2895
|
* ```
|
|
672
2896
|
*/
|
|
673
|
-
export declare
|
|
2897
|
+
export declare interface WGSLPartitionInput {
|
|
2898
|
+
/** Names the fragment. Default: a name built from `workgroup`. */
|
|
2899
|
+
readonly name?: string;
|
|
2900
|
+
/** Holds the workgroup invocation count the partition needs. */
|
|
2901
|
+
readonly workgroup: WGSLWorkgroup;
|
|
2902
|
+
}
|
|
674
2903
|
|
|
675
2904
|
/**
|
|
676
|
-
*
|
|
2905
|
+
* Carries the input `createWGSLPermute` builds a workgroup lane-gather fragment from.
|
|
2906
|
+
*
|
|
2907
|
+
* @remarks
|
|
2908
|
+
* Each lane gathers the value contributed by lane `min(index, workgroup - 1)`.
|
|
677
2909
|
*
|
|
678
2910
|
* @example
|
|
679
2911
|
* ```ts
|
|
680
|
-
* const
|
|
2912
|
+
* const input: WGSLPermuteInput = { workgroup: 128, element: 'f32' }
|
|
681
2913
|
* ```
|
|
682
2914
|
*/
|
|
683
|
-
export declare interface
|
|
684
|
-
/** Names the
|
|
685
|
-
readonly
|
|
686
|
-
/** Holds the
|
|
687
|
-
readonly
|
|
688
|
-
/**
|
|
689
|
-
readonly
|
|
2915
|
+
export declare interface WGSLPermuteInput {
|
|
2916
|
+
/** Names the fragment. Default: a name built from `element` and `workgroup`. */
|
|
2917
|
+
readonly name?: string;
|
|
2918
|
+
/** Holds the workgroup invocation count the permute needs. */
|
|
2919
|
+
readonly workgroup: WGSLWorkgroup;
|
|
2920
|
+
/** Names the element type gathered across lanes. */
|
|
2921
|
+
readonly element: WGSLReduceElement;
|
|
690
2922
|
}
|
|
691
2923
|
|
|
692
2924
|
/**
|
|
693
|
-
*
|
|
2925
|
+
* Configures per-pipeline extension overrides and pipeline-overridable constant values during `prepare`.
|
|
2926
|
+
*
|
|
2927
|
+
* @remarks
|
|
2928
|
+
* `extensions` switches a session-active extension off for one pipeline when `false` and keeps the
|
|
2929
|
+
* session's active state when `true` or omitted; it never switches an inactive extension on.
|
|
2930
|
+
* WebGPU converts `-0.0` to `+0.0` when passing `GPUProgrammableStage.constants` to the driver;
|
|
2931
|
+
* the session still keeps `-0` distinct from `0` in its pipeline cache key.
|
|
694
2932
|
*
|
|
695
2933
|
* @example
|
|
696
2934
|
* ```ts
|
|
697
|
-
* const
|
|
2935
|
+
* const options: WGSLPrepareOptions<{ SCALE: { element: 'f32'; value: 1 } }> = { extensions: { f16: false }, constants: { SCALE: 0.5 } }
|
|
698
2936
|
* ```
|
|
699
2937
|
*/
|
|
700
|
-
export declare
|
|
2938
|
+
export declare interface WGSLPrepareOptions<O extends WGSLOverrideMap = WGSLOverrideMap> {
|
|
2939
|
+
/** Switches each named extension off for this pipeline when `false`; keeps the session state when `true` or omitted. */
|
|
2940
|
+
readonly extensions?: Partial<Readonly<Record<WGSLExtension, boolean>>>;
|
|
2941
|
+
/** Supplies pipeline-overridable constant values specialized at pipeline creation. */
|
|
2942
|
+
readonly constants?: WGSLConstantMap<O>;
|
|
2943
|
+
}
|
|
701
2944
|
|
|
702
2945
|
/**
|
|
703
|
-
*
|
|
2946
|
+
* Describes one compute program: its entry point, its slots, its uniform, its overrides, and its linked fragments.
|
|
2947
|
+
*
|
|
2948
|
+
* @remarks
|
|
2949
|
+
* `fragments` lists every fragment the program reaches, each once, in dependency order.
|
|
704
2950
|
*
|
|
705
2951
|
* @example
|
|
706
2952
|
* ```ts
|
|
707
|
-
* const
|
|
2953
|
+
* const program: WGSLProgram = createWGSLProgram({ name: 'clear', entry, slots, uniform })
|
|
708
2954
|
* ```
|
|
709
2955
|
*/
|
|
710
|
-
export declare
|
|
2956
|
+
export declare interface WGSLProgram<S extends WGSLSlotMap = WGSLSlotMap, F extends WGSLFieldMap = WGSLFieldMap, O extends WGSLOverrideMap = WGSLOverrideMap> {
|
|
2957
|
+
/** Names the program. */
|
|
2958
|
+
readonly name: string;
|
|
2959
|
+
/** Declares the program's entry point. */
|
|
2960
|
+
readonly entry: WGSLEntry;
|
|
2961
|
+
/** Declares the program's storage slots. */
|
|
2962
|
+
readonly slots: S;
|
|
2963
|
+
/** Declares the program's uniform. */
|
|
2964
|
+
readonly uniform: WGSLUniform<F>;
|
|
2965
|
+
/** Declares the program's pipeline-overridable constants. */
|
|
2966
|
+
readonly overrides: O;
|
|
2967
|
+
/** Lists the linked fragments, each once, in dependency order. */
|
|
2968
|
+
readonly fragments: readonly WGSLFragment[];
|
|
2969
|
+
}
|
|
711
2970
|
|
|
712
2971
|
/**
|
|
713
|
-
*
|
|
2972
|
+
* Carries the input `createWGSLProgram` builds a program from.
|
|
714
2973
|
*
|
|
715
2974
|
* @example
|
|
716
2975
|
* ```ts
|
|
717
|
-
* const
|
|
2976
|
+
* const input: WGSLProgramInput<typeof slots, { rows: 'u32' }> = { name: 'clear', entry, slots, uniform }
|
|
718
2977
|
* ```
|
|
719
2978
|
*/
|
|
720
|
-
export declare interface
|
|
721
|
-
/** Names the
|
|
2979
|
+
export declare interface WGSLProgramInput<S extends WGSLSlotMap, F extends WGSLFieldMap, O extends WGSLOverrideMap = Readonly<Record<never, WGSLOverride>>> {
|
|
2980
|
+
/** Names the program. */
|
|
722
2981
|
readonly name: string;
|
|
723
|
-
/**
|
|
724
|
-
readonly
|
|
725
|
-
/**
|
|
726
|
-
readonly
|
|
727
|
-
/**
|
|
728
|
-
readonly
|
|
2982
|
+
/** Declares the program's entry point. */
|
|
2983
|
+
readonly entry: WGSLEntry;
|
|
2984
|
+
/** Declares the program's storage slots. */
|
|
2985
|
+
readonly slots: S;
|
|
2986
|
+
/** Declares the program's uniform. */
|
|
2987
|
+
readonly uniform: WGSLUniform<F>;
|
|
2988
|
+
/** Declares the program's pipeline-overridable constants. Default: none. */
|
|
2989
|
+
readonly overrides?: O;
|
|
2990
|
+
/** Lists the fragments the entry body calls. Default: none. */
|
|
2991
|
+
readonly uses?: readonly WGSLFragment[];
|
|
2992
|
+
}
|
|
2993
|
+
|
|
2994
|
+
/**
|
|
2995
|
+
* Carries the input `createWGSLRadixRank` builds a workgroup 4-bit radix-rank fragment from.
|
|
2996
|
+
*
|
|
2997
|
+
* @remarks
|
|
2998
|
+
* The emitted function masks each lane's `digit` to `0..15` and returns its stable sorted `offset`
|
|
2999
|
+
* across the workgroup, its `0`-based `rank` within that digit, and the workgroup's total count in
|
|
3000
|
+
* `count` for digit `local & 15`.
|
|
3001
|
+
*
|
|
3002
|
+
* @example
|
|
3003
|
+
* ```ts
|
|
3004
|
+
* const input: WGSLRadixRankInput = { workgroup: 256 }
|
|
3005
|
+
* ```
|
|
3006
|
+
*/
|
|
3007
|
+
export declare interface WGSLRadixRankInput {
|
|
3008
|
+
/** Names the fragment. Default: a name built from `workgroup`. */
|
|
3009
|
+
readonly name?: string;
|
|
3010
|
+
/** Holds the workgroup invocation count the radix rank needs. */
|
|
3011
|
+
readonly workgroup: WGSLWorkgroup;
|
|
3012
|
+
}
|
|
3013
|
+
|
|
3014
|
+
/**
|
|
3015
|
+
* Holds one pending read a batch recorded: its staging buffer, its mapped byte size, its copied ranges, and its promise callbacks.
|
|
3016
|
+
*
|
|
3017
|
+
* @example
|
|
3018
|
+
* ```ts
|
|
3019
|
+
* const read: WGSLRead = { buffer, size: 256, ranges: [{ offset: 0, size: 256 }], resolve, reject }
|
|
3020
|
+
* ```
|
|
3021
|
+
*/
|
|
3022
|
+
export declare interface WGSLRead {
|
|
3023
|
+
/** Holds the staging buffer the batch copies the read spans into. */
|
|
3024
|
+
readonly buffer: GPUBuffer;
|
|
3025
|
+
/** Holds the mapped byte count across all ranges in this read. */
|
|
3026
|
+
readonly size: number;
|
|
3027
|
+
/** Lists each copied span's offset and size inside `buffer`, in caller order. */
|
|
3028
|
+
readonly ranges: readonly WGSLReadRange[];
|
|
3029
|
+
/** Resolves the caller's read promise with one owned `ArrayBuffer` per range. */
|
|
3030
|
+
readonly resolve: (buffers: readonly ArrayBuffer[]) => void;
|
|
3031
|
+
/** Rejects the caller's read promise with the failure that aborted or faulted the batch. */
|
|
3032
|
+
readonly reject: (reason: WGSLError) => void;
|
|
3033
|
+
}
|
|
3034
|
+
|
|
3035
|
+
/**
|
|
3036
|
+
* Locates one copied span inside a coalesced staging buffer.
|
|
3037
|
+
*
|
|
3038
|
+
* @example
|
|
3039
|
+
* ```ts
|
|
3040
|
+
* const range: WGSLReadRange = { offset: 0, size: 256 }
|
|
3041
|
+
* ```
|
|
3042
|
+
*/
|
|
3043
|
+
export declare interface WGSLReadRange {
|
|
3044
|
+
/** Holds the span's byte offset inside the staging buffer. */
|
|
3045
|
+
readonly offset: number;
|
|
3046
|
+
/** Holds the span's byte count. */
|
|
3047
|
+
readonly size: number;
|
|
3048
|
+
}
|
|
3049
|
+
|
|
3050
|
+
/**
|
|
3051
|
+
* Names an element type a reduction fragment can reduce.
|
|
3052
|
+
*
|
|
3053
|
+
* @example
|
|
3054
|
+
* ```ts
|
|
3055
|
+
* const element: WGSLReduceElement = 'vec4f'
|
|
3056
|
+
* ```
|
|
3057
|
+
*/
|
|
3058
|
+
export declare type WGSLReduceElement = (typeof WGSL_REDUCE_ELEMENTS)[number];
|
|
3059
|
+
|
|
3060
|
+
/**
|
|
3061
|
+
* Carries the input `createWGSLReduce` builds a reduction fragment from.
|
|
3062
|
+
*
|
|
3063
|
+
* @remarks
|
|
3064
|
+
* `'and'`, `'or'`, and `'xor'` take `'u32'` or `'i32'` only; `createWGSLReduce` refuses
|
|
3065
|
+
* floating-point elements with them under code `ARGUMENT`. `width` defaults to `workgroup` and
|
|
3066
|
+
* must not exceed `workgroup`. When `reordered` is `false` (the default), the base tree keeps all
|
|
3067
|
+
* partition lanes active and the exact subgroup butterfly uses no synthetic identity; when
|
|
3068
|
+
* `reordered` is `true`, the subgroup collective variant seeds its cross-subgroup fold from lane 0
|
|
3069
|
+
* without synthetic identity constants, preserving `±Infinity` and `-0.0`.
|
|
3070
|
+
*
|
|
3071
|
+
* @example
|
|
3072
|
+
* ```ts
|
|
3073
|
+
* const input: WGSLReduceInput = { workgroup: 256, width: 32, operation: 'max', element: 'f32' }
|
|
3074
|
+
* ```
|
|
3075
|
+
*/
|
|
3076
|
+
export declare interface WGSLReduceInput {
|
|
3077
|
+
/** Names the fragment. Default: a name built from `operation`, `element`, `workgroup`, and `width`. */
|
|
3078
|
+
readonly name?: string;
|
|
3079
|
+
/** Holds the workgroup invocation count the reduction needs. */
|
|
3080
|
+
readonly workgroup: WGSLWorkgroup;
|
|
3081
|
+
/** Holds the partition width reduced independently inside each workgroup. Default: `workgroup`. */
|
|
3082
|
+
readonly width?: WGSLReduceWidth;
|
|
3083
|
+
/** Names the combining operation. */
|
|
3084
|
+
readonly operation: WGSLReduceOperation;
|
|
3085
|
+
/** Names the element type reduced. */
|
|
3086
|
+
readonly element: WGSLReduceElement;
|
|
3087
|
+
/** Permits subgroup reordering during reduction when `true`; keeps a fixed binary tree combine order when `false`. Default: `false`. */
|
|
3088
|
+
readonly reordered?: boolean;
|
|
729
3089
|
}
|
|
730
3090
|
|
|
731
3091
|
/**
|
|
732
|
-
*
|
|
3092
|
+
* Names the combining operation of a reduction or scan.
|
|
3093
|
+
*
|
|
3094
|
+
* @example
|
|
3095
|
+
* ```ts
|
|
3096
|
+
* const operation: WGSLReduceOperation = 'sum'
|
|
3097
|
+
* ```
|
|
3098
|
+
*/
|
|
3099
|
+
export declare type WGSLReduceOperation = (typeof WGSL_REDUCE_OPERATIONS)[number];
|
|
3100
|
+
|
|
3101
|
+
/**
|
|
3102
|
+
* Holds a partition width supported by `createWGSLReduce`, `createWGSLMonoidReduce`, `createWGSLSort`, and `createWGSLPairSort`.
|
|
3103
|
+
*
|
|
3104
|
+
* @example
|
|
3105
|
+
* ```ts
|
|
3106
|
+
* const width: WGSLReduceWidth = 32
|
|
3107
|
+
* ```
|
|
3108
|
+
*/
|
|
3109
|
+
export declare type WGSLReduceWidth = (typeof WGSL_REDUCE_WIDTHS)[number];
|
|
3110
|
+
|
|
3111
|
+
/**
|
|
3112
|
+
* Configures active extensions, WGSL language extensions, subgroup bounds, and workgroup linearity during rendering.
|
|
3113
|
+
*
|
|
3114
|
+
* @remarks
|
|
3115
|
+
* Passed to `resolveWGSLVariant`, `collectWGSLSections`, `renderWGSLProgram`, and
|
|
3116
|
+
* `renderWGSLFragment`. Matches the shapes reported by `session.extensions`, `session.languages`,
|
|
3117
|
+
* and `session.subgroup` so a session's active capabilities forward directly. When omitted, no
|
|
3118
|
+
* extension or language extension is active, `subgroup` is `undefined`, and `linear` defaults to
|
|
3119
|
+
* `true`.
|
|
733
3120
|
*
|
|
734
3121
|
* @example
|
|
735
3122
|
* ```ts
|
|
736
|
-
* const
|
|
3123
|
+
* const options: WGSLRenderOptions = { extensions: { subgroups: true }, languages: { subgroup_id: true }, subgroup: { minimum: 32, maximum: 32 } }
|
|
737
3124
|
* ```
|
|
738
3125
|
*/
|
|
739
|
-
export declare interface
|
|
740
|
-
/**
|
|
741
|
-
readonly
|
|
742
|
-
/**
|
|
743
|
-
readonly
|
|
744
|
-
/**
|
|
745
|
-
readonly
|
|
746
|
-
/**
|
|
747
|
-
readonly
|
|
3126
|
+
export declare interface WGSLRenderOptions {
|
|
3127
|
+
/** Reports whether each extension is active. */
|
|
3128
|
+
readonly extensions?: Partial<Readonly<Record<WGSLExtension, boolean>>>;
|
|
3129
|
+
/** Reports whether each WGSL language extension is active. */
|
|
3130
|
+
readonly languages?: Partial<Readonly<Record<WGSLLanguage, boolean>>>;
|
|
3131
|
+
/** Bounds the subgroup size interval supported by the host. */
|
|
3132
|
+
readonly subgroup?: Required<WGSLSubgroupRange>;
|
|
3133
|
+
/** Permits one-dimensional workgroup variants on 1D entries when `true` or omitted; skips them when `false`. Default: `true`. */
|
|
3134
|
+
readonly linear?: boolean;
|
|
748
3135
|
}
|
|
749
3136
|
|
|
750
3137
|
/**
|
|
751
|
-
*
|
|
3138
|
+
* Names a scalar type a uniform struct member holds.
|
|
752
3139
|
*
|
|
753
3140
|
* @example
|
|
754
3141
|
* ```ts
|
|
755
|
-
* const
|
|
3142
|
+
* const element: WGSLScalar = 'f32'
|
|
756
3143
|
* ```
|
|
757
3144
|
*/
|
|
758
|
-
export declare type
|
|
3145
|
+
export declare type WGSLScalar = (typeof WGSL_SCALARS)[number];
|
|
759
3146
|
|
|
760
3147
|
/**
|
|
761
|
-
*
|
|
3148
|
+
* Carries the input `createWGSLScan` builds a workgroup scan fragment from.
|
|
3149
|
+
*
|
|
3150
|
+
* @remarks
|
|
3151
|
+
* `'and'`, `'or'`, and `'xor'` take `'u32'` or `'i32'` only; `createWGSLScan` refuses `'f32'` with
|
|
3152
|
+
* them under code `ARGUMENT`. For `'f32'` `'sum'` scans, subgroup reordering attaches only when
|
|
3153
|
+
* `reordered` is `true`.
|
|
762
3154
|
*
|
|
763
3155
|
* @example
|
|
764
3156
|
* ```ts
|
|
765
|
-
* const
|
|
3157
|
+
* const input: WGSLScanInput = { workgroup: 256, element: 'u32', exclusive: true }
|
|
766
3158
|
* ```
|
|
767
3159
|
*/
|
|
768
|
-
export declare interface
|
|
769
|
-
/** Names the
|
|
770
|
-
readonly name
|
|
771
|
-
/**
|
|
3160
|
+
export declare interface WGSLScanInput {
|
|
3161
|
+
/** Names the fragment. Default: a name built from `reverse`, `exclusive`, `operation`, `element`, and `workgroup`. */
|
|
3162
|
+
readonly name?: string;
|
|
3163
|
+
/** Holds the workgroup invocation count the scan needs. */
|
|
3164
|
+
readonly workgroup: WGSLWorkgroup;
|
|
3165
|
+
/** Names the combining operation. Default: `'sum'`. */
|
|
3166
|
+
readonly operation?: WGSLReduceOperation;
|
|
3167
|
+
/** Names the element type scanned. */
|
|
772
3168
|
readonly element: WGSLScalar;
|
|
773
|
-
/**
|
|
774
|
-
readonly
|
|
3169
|
+
/** Omits each lane's own input from its scan result when `true`; includes it when `false`. Default: `false`. */
|
|
3170
|
+
readonly exclusive?: boolean;
|
|
3171
|
+
/** Scans from the last lane toward lane 0 when `true`; scans from lane 0 upward when `false`. Default: `false`. */
|
|
3172
|
+
readonly reverse?: boolean;
|
|
3173
|
+
/** Permits subgroup reordering on floating-point scans when `true`; keeps Blelloch tree order when `false`. Default: `false`. */
|
|
3174
|
+
readonly reordered?: boolean;
|
|
775
3175
|
}
|
|
776
3176
|
|
|
777
3177
|
/**
|
|
778
|
-
*
|
|
3178
|
+
* Locates one section of a rendered program: its role, its producer, its text, and its line range.
|
|
779
3179
|
*
|
|
780
3180
|
* @remarks
|
|
781
|
-
* `
|
|
3181
|
+
* `collectWGSLSections` returns the sections in render order. Joining their `source` values with
|
|
3182
|
+
* `\n\n` and ending the text with `\n` equals `renderWGSLProgram` for the same program and render
|
|
3183
|
+
* options, and `line` and `end` index that rendered text.
|
|
782
3184
|
*
|
|
783
3185
|
* @example
|
|
784
3186
|
* ```ts
|
|
785
|
-
* const
|
|
3187
|
+
* const section: WGSLSection = { role: 'fragment', name: 'sumPartials', source: 'fn sumPartials() {}', line: 12, end: 12 }
|
|
786
3188
|
* ```
|
|
787
3189
|
*/
|
|
788
|
-
export declare interface
|
|
789
|
-
/** Names
|
|
3190
|
+
export declare interface WGSLSection {
|
|
3191
|
+
/** Names which rendered section this record holds. */
|
|
3192
|
+
readonly role: WGSLSectionRole;
|
|
3193
|
+
/**
|
|
3194
|
+
* Names what produced the section, by role: `'requires'` for the language-extension directives,
|
|
3195
|
+
* `'enable'` for the extension directives, `'override'` for the pipeline-overridable constant
|
|
3196
|
+
* declarations, the struct's name for `struct`, `'Dispatch'` for `dispatch`, `'Invocation'` for
|
|
3197
|
+
* `invocation`, `'bindings'` for `bindings`, the fragment's `name` for `fragment`, and the
|
|
3198
|
+
* entry's `name` for `entry`.
|
|
3199
|
+
*/
|
|
790
3200
|
readonly name: string;
|
|
791
|
-
/**
|
|
792
|
-
readonly
|
|
793
|
-
/**
|
|
794
|
-
readonly
|
|
795
|
-
/**
|
|
796
|
-
readonly
|
|
797
|
-
/** Lists the linked fragments, each once, in dependency order. */
|
|
798
|
-
readonly fragments: readonly WGSLFragment[];
|
|
3201
|
+
/** Holds the exact section WGSL text, without separator line feeds. */
|
|
3202
|
+
readonly source: string;
|
|
3203
|
+
/** Holds the 1-based start line of this section in `renderWGSLProgram` output. */
|
|
3204
|
+
readonly line: number;
|
|
3205
|
+
/** Holds the 1-based inclusive end line of this section in `renderWGSLProgram` output. */
|
|
3206
|
+
readonly end: number;
|
|
799
3207
|
}
|
|
800
3208
|
|
|
801
3209
|
/**
|
|
802
|
-
*
|
|
3210
|
+
* Names the role of one rendered program section.
|
|
803
3211
|
*
|
|
804
3212
|
* @example
|
|
805
3213
|
* ```ts
|
|
806
|
-
* const
|
|
3214
|
+
* const role: WGSLSectionRole = 'fragment'
|
|
807
3215
|
* ```
|
|
808
3216
|
*/
|
|
809
|
-
export declare
|
|
810
|
-
/** Names the program. */
|
|
811
|
-
readonly name: string;
|
|
812
|
-
/** Declares the program's entry point. */
|
|
813
|
-
readonly entry: WGSLEntry;
|
|
814
|
-
/** Declares the program's storage slots. */
|
|
815
|
-
readonly slots: S;
|
|
816
|
-
/** Declares the program's uniform. */
|
|
817
|
-
readonly uniform: WGSLUniform<F>;
|
|
818
|
-
/** Lists the fragments the entry body calls. Default: none. */
|
|
819
|
-
readonly uses?: readonly WGSLFragment[];
|
|
820
|
-
}
|
|
3217
|
+
export declare type WGSLSectionRole = (typeof WGSL_SECTION_ROLES)[number];
|
|
821
3218
|
|
|
822
3219
|
/**
|
|
823
|
-
*
|
|
3220
|
+
* Carries the input `createWGSLSegmentedReduce` builds a workgroup segmented-reduction fragment from.
|
|
3221
|
+
*
|
|
3222
|
+
* @remarks
|
|
3223
|
+
* `'and'`, `'or'`, and `'xor'` take `'u32'` or `'i32'` only; `createWGSLSegmentedReduce` refuses
|
|
3224
|
+
* floating-point elements with them under code `ARGUMENT`. The emitted function delivers each
|
|
3225
|
+
* segment's total with `valid: true` at its head lane (`local == 0` or `head == true`) and
|
|
3226
|
+
* `valid: false` elsewhere.
|
|
824
3227
|
*
|
|
825
3228
|
* @example
|
|
826
3229
|
* ```ts
|
|
827
|
-
* const
|
|
3230
|
+
* const input: WGSLSegmentedReduceInput = { workgroup: 256, operation: 'sum', element: 'f32' }
|
|
828
3231
|
* ```
|
|
829
3232
|
*/
|
|
830
|
-
export declare
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
3233
|
+
export declare interface WGSLSegmentedReduceInput {
|
|
3234
|
+
/** Names the fragment. Default: a name built from `operation`, `element`, and `workgroup`. */
|
|
3235
|
+
readonly name?: string;
|
|
3236
|
+
/** Holds the workgroup invocation count the reduction needs. */
|
|
3237
|
+
readonly workgroup: WGSLWorkgroup;
|
|
3238
|
+
/** Names the combining operation. */
|
|
3239
|
+
readonly operation: WGSLReduceOperation;
|
|
3240
|
+
/** Names the element type reduced. */
|
|
3241
|
+
readonly element: WGSLReduceElement;
|
|
3242
|
+
/** Permits subgroup reordering on floating-point reductions when `true`; keeps deterministic tree order when `false`. Default: `false`. */
|
|
3243
|
+
readonly reordered?: boolean;
|
|
3244
|
+
}
|
|
835
3245
|
|
|
836
3246
|
/**
|
|
837
|
-
*
|
|
3247
|
+
* Carries the input `createWGSLSegmentedScan` builds a workgroup segmented-scan fragment from.
|
|
3248
|
+
*
|
|
3249
|
+
* @remarks
|
|
3250
|
+
* `'and'`, `'or'`, and `'xor'` take `'u32'` or `'i32'` only; `createWGSLSegmentedScan` refuses
|
|
3251
|
+
* `'f32'` with them under code `ARGUMENT`. Lane `0` always starts a segment; when `exclusive` is
|
|
3252
|
+
* `true`, each segment head receives the operation's identity from `WGSL_REDUCE_IDENTITIES`.
|
|
838
3253
|
*
|
|
839
3254
|
* @example
|
|
840
3255
|
* ```ts
|
|
841
|
-
* const
|
|
3256
|
+
* const input: WGSLSegmentedScanInput = { workgroup: 256, element: 'f32', exclusive: true }
|
|
842
3257
|
* ```
|
|
843
3258
|
*/
|
|
844
|
-
export declare
|
|
3259
|
+
export declare interface WGSLSegmentedScanInput {
|
|
3260
|
+
/** Names the fragment. Default: a name built from `exclusive`, `operation`, `element`, and `workgroup`. */
|
|
3261
|
+
readonly name?: string;
|
|
3262
|
+
/** Holds the workgroup invocation count the scan needs. */
|
|
3263
|
+
readonly workgroup: WGSLWorkgroup;
|
|
3264
|
+
/** Names the combining operation. Default: `'sum'`. */
|
|
3265
|
+
readonly operation?: WGSLReduceOperation;
|
|
3266
|
+
/** Names the element type scanned. */
|
|
3267
|
+
readonly element: WGSLScalar;
|
|
3268
|
+
/** Omits each lane's own input from its segment scan result when `true`; includes it when `false`. Default: `false`. */
|
|
3269
|
+
readonly exclusive?: boolean;
|
|
3270
|
+
/** Permits subgroup reordering on floating-point scans when `true`; keeps deterministic tree order when `false`. Default: `false`. */
|
|
3271
|
+
readonly reordered?: boolean;
|
|
3272
|
+
}
|
|
845
3273
|
|
|
846
3274
|
/**
|
|
847
3275
|
* Prepares programs as statements on a borrowed device and opens one batch of dispatches at a time.
|
|
848
3276
|
*
|
|
849
3277
|
* @remarks
|
|
850
|
-
* The session reads its limits and
|
|
851
|
-
*
|
|
852
|
-
* does not switch it off
|
|
853
|
-
*
|
|
854
|
-
*
|
|
855
|
-
*
|
|
856
|
-
*
|
|
857
|
-
*
|
|
858
|
-
*
|
|
859
|
-
*
|
|
860
|
-
*
|
|
861
|
-
*
|
|
862
|
-
*
|
|
863
|
-
*
|
|
864
|
-
*
|
|
865
|
-
*
|
|
866
|
-
*
|
|
3278
|
+
* The session reads its limits, features, and subgroup size bounds from the borrowed device and
|
|
3279
|
+
* reads no host global. An extension is active when the device reports its feature and the
|
|
3280
|
+
* `extensions` option does not switch it off; WGSL language extensions derive once at construction
|
|
3281
|
+
* from the caller-supplied `languages` set or list intersected with `WGSL_LANGUAGES`. Shader
|
|
3282
|
+
* modules sit in a cache keyed on rendered WGSL text, separate from the ready and pending pipeline
|
|
3283
|
+
* tables keyed on rendered text plus canonical override constants (keeping `-0` distinct from `0`),
|
|
3284
|
+
* so specializing one program with distinct override values compiles its shader module once. A
|
|
3285
|
+
* pending pipeline or module entry that fails with any code but `COMPILE` leaves its table, so a
|
|
3286
|
+
* later `prepare` retries it. Shader compilation and pipeline layout creation each run inside one
|
|
3287
|
+
* synchronous push and pop of a `validation` error scope; a compiler error rejects that `prepare`
|
|
3288
|
+
* with code `COMPILE` and its `line`, `column`, and section attribution in `context` while the
|
|
3289
|
+
* session stays `open`. Thrown with code `LIMIT` when `uniform.size`, a staging allocation, a
|
|
3290
|
+
* uniform struct size, a workgroup size, or a slot count passes the device's limits; with code
|
|
3291
|
+
* `VALIDATION` when half-precision storage slots lack an active `f16` extension or `batch()` is
|
|
3292
|
+
* called while another batch is open; and with code `ARGUMENT` for malformed options or invalid
|
|
3293
|
+
* override constants. Staging buffers lease through a best-fit power-of-two pool that retains up to
|
|
3294
|
+
* 8 idle buffers. A device failure on a submitted batch, or `device.lost`, moves the session to
|
|
3295
|
+
* `failed`; `destroy` moves the session to `destroyed` at once, aborts the open batch, waits for
|
|
3296
|
+
* submitted work and reads, and destroys every session-owned buffer and query set while leaving the
|
|
3297
|
+
* borrowed device open.
|
|
867
3298
|
*
|
|
868
3299
|
* @example
|
|
869
3300
|
* ```ts
|
|
@@ -879,13 +3310,16 @@ export declare class WGSLSession implements WGSLSessionInterface {
|
|
|
879
3310
|
* Creates an open session over a borrowed device, with its uniform slab and uniform layout.
|
|
880
3311
|
*
|
|
881
3312
|
* @param device - The device the session borrows
|
|
882
|
-
* @param options - The extensions to switch off
|
|
3313
|
+
* @param options - The extensions to switch off, host language extensions, slab byte size, and tracer mode and capacity
|
|
883
3314
|
*/
|
|
884
3315
|
constructor(device: GPUDevice, options?: WGSLSessionOptions);
|
|
885
3316
|
get device(): GPUDevice;
|
|
886
3317
|
get extensions(): Readonly<Record<WGSLExtension, boolean>>;
|
|
3318
|
+
get languages(): Readonly<Record<WGSLLanguage, boolean>>;
|
|
3319
|
+
get subgroup(): Required<WGSLSubgroupRange> | undefined;
|
|
887
3320
|
get status(): WGSLSessionStatus;
|
|
888
|
-
|
|
3321
|
+
get trace(): WGSLTraceRecord | undefined;
|
|
3322
|
+
prepare<S extends WGSLSlotMap, F extends WGSLFieldMap, O extends WGSLOverrideMap>(program: WGSLProgram<S, F, O>, options?: WGSLPrepareOptions<O>): Promise<WGSLStatementInterface<S, F, O>>;
|
|
889
3323
|
batch(): WGSLBatchInterface;
|
|
890
3324
|
destroy(): Promise<void>;
|
|
891
3325
|
}
|
|
@@ -903,10 +3337,19 @@ export declare interface WGSLSessionInterface {
|
|
|
903
3337
|
readonly device: GPUDevice;
|
|
904
3338
|
/** Reports whether each extension is active on this session. */
|
|
905
3339
|
readonly extensions: Readonly<Record<WGSLExtension, boolean>>;
|
|
3340
|
+
/** Reports whether each WGSL language extension is active on this session. */
|
|
3341
|
+
readonly languages: Readonly<Record<WGSLLanguage, boolean>>;
|
|
3342
|
+
/** Reports the device's subgroup size bounds when `'subgroups'` is active, or `undefined` otherwise. */
|
|
3343
|
+
readonly subgroup: Required<WGSLSubgroupRange> | undefined;
|
|
906
3344
|
/** Reports the session's lifecycle status. */
|
|
907
3345
|
readonly status: WGSLSessionStatus;
|
|
3346
|
+
/**
|
|
3347
|
+
* Holds the trace of the last settled traced batch, or `undefined` when tracing is `'off'` or no
|
|
3348
|
+
* traced batch has settled.
|
|
3349
|
+
*/
|
|
3350
|
+
readonly trace: WGSLTraceRecord | undefined;
|
|
908
3351
|
/** Prepares a program as a statement on the session's device. */
|
|
909
|
-
prepare<S extends WGSLSlotMap, F extends WGSLFieldMap>(program: WGSLProgram<S, F>): Promise<WGSLStatementInterface<S, F>>;
|
|
3352
|
+
prepare<S extends WGSLSlotMap, F extends WGSLFieldMap, O extends WGSLOverrideMap>(program: WGSLProgram<S, F, O>, options?: WGSLPrepareOptions<O>): Promise<WGSLStatementInterface<S, F, O>>;
|
|
910
3353
|
/** Opens the session's one batch. */
|
|
911
3354
|
batch(): WGSLBatchInterface;
|
|
912
3355
|
/** Releases every resource the session created, leaving the device open. */
|
|
@@ -914,24 +3357,36 @@ export declare interface WGSLSessionInterface {
|
|
|
914
3357
|
}
|
|
915
3358
|
|
|
916
3359
|
/**
|
|
917
|
-
* Configures a session's extensions
|
|
3360
|
+
* Configures a session's extensions, WGSL language extensions, uniform slab, and batch tracer.
|
|
918
3361
|
*
|
|
919
3362
|
* @remarks
|
|
920
3363
|
* `extensions` switches an extension the device supports off; it never switches one on.
|
|
921
|
-
* `
|
|
3364
|
+
* `languages` supplies host-reported WGSL language features (such as
|
|
3365
|
+
* `navigator.gpu.wgslLanguageFeatures`), intersected with `WGSL_LANGUAGES` once at construction.
|
|
3366
|
+
* `uniform.size` sets the slab's byte capacity. Default: `WGSL_UNIFORM_SIZE`. `trace` enables
|
|
3367
|
+
* per-batch recording under `'pass'` or `'statement'` mode and sets pass capacity. The session
|
|
3368
|
+
* constructor reads these options through `resolveOptions` and throws with code `ARGUMENT` for an
|
|
3369
|
+
* unknown key at any level, an `extensions` value that is not a boolean, a `languages` value that
|
|
3370
|
+
* is neither a `Set` nor an array of strings, a `uniform.size` that is `null` or not a positive
|
|
3371
|
+
* safe multiple of 4, a `trace.mode` outside `WGSL_TRACE_MODES`, a `trace.capacity` outside
|
|
3372
|
+
* integers 1 to 2048, and an `options` value that is not a record.
|
|
922
3373
|
*
|
|
923
3374
|
* @example
|
|
924
3375
|
* ```ts
|
|
925
|
-
* const options: WGSLSessionOptions = { extensions: { f16: false }, uniform: { size: 16384 } }
|
|
3376
|
+
* const options: WGSLSessionOptions = { extensions: { f16: false }, languages: ['subgroup_id'], uniform: { size: 16384 } }
|
|
926
3377
|
* ```
|
|
927
3378
|
*/
|
|
928
3379
|
export declare interface WGSLSessionOptions {
|
|
929
3380
|
/** Switches each named extension off when `false`. */
|
|
930
3381
|
readonly extensions?: Partial<Readonly<Record<WGSLExtension, boolean>>>;
|
|
3382
|
+
/** Lists the WGSL language extensions available on the host. */
|
|
3383
|
+
readonly languages?: ReadonlySet<string> | readonly string[];
|
|
931
3384
|
/** Configures the uniform slab. */
|
|
932
3385
|
readonly uniform?: {
|
|
933
3386
|
readonly size?: number;
|
|
934
3387
|
};
|
|
3388
|
+
/** Configures the session's tracer. */
|
|
3389
|
+
readonly trace?: WGSLTraceOptions;
|
|
935
3390
|
}
|
|
936
3391
|
|
|
937
3392
|
/**
|
|
@@ -949,7 +3404,8 @@ export declare type WGSLSessionStatus = 'open' | 'failed' | 'destroyed';
|
|
|
949
3404
|
*
|
|
950
3405
|
* @remarks
|
|
951
3406
|
* The slab owns one `ArrayBuffer` with a `Uint32Array` view and a `Float32Array` view over it, and
|
|
952
|
-
*
|
|
3407
|
+
* caches a split integer/float field plan per `WGSLStruct` so multi-field writes step directly into
|
|
3408
|
+
* each typed view without per-field type branching. An `f32` member writes through the float view,
|
|
953
3409
|
* so `-0` and subnormals keep their binary32 patterns; a `u32` or `i32` member writes through the
|
|
954
3410
|
* unsigned view, so `-5` stores `0xFFFFFFFB`. Each write starts at the next multiple of the
|
|
955
3411
|
* device's `minUniformBufferOffsetAlignment`. A write that meets a missing value zeroes the span it
|
|
@@ -1022,20 +3478,48 @@ export declare interface WGSLSlabOptions {
|
|
|
1022
3478
|
readonly capacity: number;
|
|
1023
3479
|
}
|
|
1024
3480
|
|
|
3481
|
+
/**
|
|
3482
|
+
* Locates a byte range's start inside a buffer.
|
|
3483
|
+
*
|
|
3484
|
+
* @remarks
|
|
3485
|
+
* `offset` defaults to `0` and must be a non-negative safe multiple of 4 bytes. A slice carries no
|
|
3486
|
+
* length; the operation that takes it supplies the byte count.
|
|
3487
|
+
*
|
|
3488
|
+
* @example
|
|
3489
|
+
* ```ts
|
|
3490
|
+
* const slice: WGSLSlice = { buffer, offset: 256 }
|
|
3491
|
+
* ```
|
|
3492
|
+
*/
|
|
3493
|
+
export declare interface WGSLSlice {
|
|
3494
|
+
/** Holds the buffer the range sits in. */
|
|
3495
|
+
readonly buffer: GPUBuffer;
|
|
3496
|
+
/** Holds the range's byte offset from the buffer's start. Default: `0`. */
|
|
3497
|
+
readonly offset?: number;
|
|
3498
|
+
}
|
|
3499
|
+
|
|
1025
3500
|
/**
|
|
1026
3501
|
* Declares one storage slot of a program: its access mode and its array element type.
|
|
1027
3502
|
*
|
|
3503
|
+
* @remarks
|
|
3504
|
+
* Atomic elements (`'atomic<u32>'` and `'atomic<i32>'`) require `'read_write'` access in WGSL and
|
|
3505
|
+
* are refused on `'read'` slots both at compile time and at runtime under code `ARGUMENT`.
|
|
3506
|
+
*
|
|
1028
3507
|
* @example
|
|
1029
3508
|
* ```ts
|
|
1030
3509
|
* const slot: WGSLSlot = { access: 'read_write', element: 'f32' }
|
|
1031
3510
|
* ```
|
|
1032
3511
|
*/
|
|
1033
|
-
export declare
|
|
1034
|
-
/** Names the
|
|
1035
|
-
readonly access: WGSLAccess
|
|
1036
|
-
/** Names the
|
|
1037
|
-
readonly element:
|
|
1038
|
-
}
|
|
3512
|
+
export declare type WGSLSlot = {
|
|
3513
|
+
/** Names the read-only storage access mode, which refuses atomic elements. */
|
|
3514
|
+
readonly access: Extract<WGSLAccess, 'read'>;
|
|
3515
|
+
/** Names the non-atomic element type of the slot's storage array. */
|
|
3516
|
+
readonly element: Exclude<WGSLStorageElement, `atomic<${string}>`>;
|
|
3517
|
+
} | {
|
|
3518
|
+
/** Names the read-write storage access mode. */
|
|
3519
|
+
readonly access: Extract<WGSLAccess, 'read_write'>;
|
|
3520
|
+
/** Names the element type of the slot's storage array. */
|
|
3521
|
+
readonly element: WGSLStorageElement;
|
|
3522
|
+
};
|
|
1039
3523
|
|
|
1040
3524
|
/**
|
|
1041
3525
|
* Maps each storage slot name of a program to its declaration, in binding order.
|
|
@@ -1047,19 +3531,73 @@ export declare interface WGSLSlot {
|
|
|
1047
3531
|
*/
|
|
1048
3532
|
export declare type WGSLSlotMap = Readonly<Record<string, WGSLSlot>>;
|
|
1049
3533
|
|
|
3534
|
+
/**
|
|
3535
|
+
* Carries the input `createWGSLSort` builds a workgroup sort fragment from.
|
|
3536
|
+
*
|
|
3537
|
+
* @remarks
|
|
3538
|
+
* `width` defaults to `workgroup` and must not exceed `workgroup`.
|
|
3539
|
+
*
|
|
3540
|
+
* @example
|
|
3541
|
+
* ```ts
|
|
3542
|
+
* const input: WGSLSortInput = { workgroup: 128, order: 'ascending', element: 'u32' }
|
|
3543
|
+
* ```
|
|
3544
|
+
*/
|
|
3545
|
+
export declare interface WGSLSortInput {
|
|
3546
|
+
/** Names the fragment. Default: a name built from `order`, `element`, `workgroup`, and `width`. */
|
|
3547
|
+
readonly name?: string;
|
|
3548
|
+
/** Holds the workgroup invocation count the sort needs. */
|
|
3549
|
+
readonly workgroup: WGSLWorkgroup;
|
|
3550
|
+
/** Holds the partition width sorted independently inside each workgroup. Default: `workgroup`. */
|
|
3551
|
+
readonly width?: WGSLReduceWidth;
|
|
3552
|
+
/** Names the sort direction. */
|
|
3553
|
+
readonly order: WGSLSortOrder;
|
|
3554
|
+
/** Names the element type sorted. */
|
|
3555
|
+
readonly element: WGSLScalar;
|
|
3556
|
+
}
|
|
3557
|
+
|
|
3558
|
+
/**
|
|
3559
|
+
* Names the sort direction of a workgroup sort or key-index pair sort.
|
|
3560
|
+
*
|
|
3561
|
+
* @example
|
|
3562
|
+
* ```ts
|
|
3563
|
+
* const order: WGSLSortOrder = 'ascending'
|
|
3564
|
+
* ```
|
|
3565
|
+
*/
|
|
3566
|
+
export declare type WGSLSortOrder = (typeof WGSL_SORT_ORDERS)[number];
|
|
3567
|
+
|
|
3568
|
+
/**
|
|
3569
|
+
* Locates a bounded byte range inside a buffer for a coalesced batch read.
|
|
3570
|
+
*
|
|
3571
|
+
* @remarks
|
|
3572
|
+
* Extends `WGSLSlice` with `size`. `offset` defaults to `0` and must be a non-negative safe
|
|
3573
|
+
* multiple of 4 bytes, and `size` must be a safe multiple of 4 bytes and at least 4.
|
|
3574
|
+
*
|
|
3575
|
+
* @example
|
|
3576
|
+
* ```ts
|
|
3577
|
+
* const span: WGSLSpan = { buffer, offset: 0, size: 256 }
|
|
3578
|
+
* ```
|
|
3579
|
+
*/
|
|
3580
|
+
export declare interface WGSLSpan extends WGSLSlice {
|
|
3581
|
+
/** Holds the byte count to read. */
|
|
3582
|
+
readonly size: number;
|
|
3583
|
+
}
|
|
3584
|
+
|
|
1050
3585
|
/**
|
|
1051
3586
|
* Runs one prepared program on its session's device and caches a storage bind group per set of slot ranges.
|
|
1052
3587
|
*
|
|
1053
3588
|
* @remarks
|
|
1054
|
-
* `bind` walks a per-statement `WeakMap` trie keyed on
|
|
1055
|
-
* size, so a repeated range set returns the same
|
|
1056
|
-
* buffer's entries leave with the buffer. A range
|
|
1057
|
-
* group is created: thrown with code `ARGUMENT` when
|
|
1058
|
-
*
|
|
1059
|
-
* `
|
|
1060
|
-
*
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
3589
|
+
* `bind` verifies the owning session is open, then walks a per-statement `WeakMap` trie keyed on
|
|
3590
|
+
* each slot's buffer, byte offset, and byte size, so a repeated exact range set returns the same
|
|
3591
|
+
* `WGSLBinding` without allocating, and a destroyed buffer's entries leave with the buffer. A range
|
|
3592
|
+
* set the trie lacks is checked before its bind group is created: thrown with code `ARGUMENT` when
|
|
3593
|
+
* `buffers` is not a plain record, when the slot names differ from the program's, when a buffer
|
|
3594
|
+
* lacks the `storage` usage, when an offset is not a multiple of the device's
|
|
3595
|
+
* `minStorageBufferOffsetAlignment`, when a size is under `Math.max(4, stride)` or not a multiple
|
|
3596
|
+
* of that element stride, and when a range passes its buffer's end; with code `LIMIT` when a size
|
|
3597
|
+
* passes the device's `maxStorageBufferBindingSize`; with code `VALIDATION` when a `read_write`
|
|
3598
|
+
* slot shares its `GPUBuffer` with any other slot, even over disjoint ranges, because Dawn refuses
|
|
3599
|
+
* that pair; with code `DESTROYED` after the session's `destroy`; and with the session's recorded
|
|
3600
|
+
* failure when the session has failed.
|
|
1063
3601
|
* `execute` opens a batch on the session, records one dispatch, and resolves when the device
|
|
1064
3602
|
* finishes it.
|
|
1065
3603
|
*
|
|
@@ -1070,22 +3608,22 @@ export declare type WGSLSlotMap = Readonly<Record<string, WGSLSlot>>;
|
|
|
1070
3608
|
* await statement.execute(binding, { count: 64 }, [1, 1, 1])
|
|
1071
3609
|
* ```
|
|
1072
3610
|
*/
|
|
1073
|
-
export declare class WGSLStatement<S extends WGSLSlotMap, F extends WGSLFieldMap> implements WGSLStatementInterface<S, F> {
|
|
3611
|
+
export declare class WGSLStatement<S extends WGSLSlotMap, F extends WGSLFieldMap, O extends WGSLOverrideMap = WGSLOverrideMap> implements WGSLStatementInterface<S, F, O> {
|
|
1074
3612
|
#private;
|
|
1075
|
-
readonly program: WGSLProgram<S, F>;
|
|
3613
|
+
readonly program: WGSLProgram<S, F, O>;
|
|
1076
3614
|
readonly pipeline: GPUComputePipeline;
|
|
1077
3615
|
readonly uniform: GPUBindGroup;
|
|
1078
3616
|
/**
|
|
1079
3617
|
* Creates a statement over a pipeline its session prepared.
|
|
1080
3618
|
*
|
|
1081
3619
|
* @param session - The session whose device creates the bind groups and whose batches run the dispatches
|
|
1082
|
-
* @param options - The program, the pipeline, the storage layout,
|
|
3620
|
+
* @param options - The program, the pipeline, the storage layout, the uniform bind group, and the session guard
|
|
1083
3621
|
*/
|
|
1084
|
-
constructor(session: WGSLSessionInterface, options: WGSLStatementOptions<S, F>);
|
|
3622
|
+
constructor(session: WGSLSessionInterface, options: WGSLStatementOptions<S, F, O>);
|
|
1085
3623
|
bind(buffers: {
|
|
1086
3624
|
readonly [K in keyof S]: GPUBufferBinding;
|
|
1087
|
-
}): WGSLBinding<S, F>;
|
|
1088
|
-
execute(binding: WGSLBinding<S, F>, values: WGSLValueMap<F>, grid: WGSLGrid, signal?: AbortSignal): Promise<void>;
|
|
3625
|
+
}): WGSLBinding<S, F, O>;
|
|
3626
|
+
execute(binding: WGSLBinding<S, F, O>, values: WGSLValueMap<F>, grid: WGSLGrid, signal?: AbortSignal): Promise<void>;
|
|
1089
3627
|
}
|
|
1090
3628
|
|
|
1091
3629
|
/**
|
|
@@ -1096,9 +3634,9 @@ export declare class WGSLStatement<S extends WGSLSlotMap, F extends WGSLFieldMap
|
|
|
1096
3634
|
* const statement: WGSLStatementInterface<typeof slots, { rows: 'u32' }> = await session.prepare(program)
|
|
1097
3635
|
* ```
|
|
1098
3636
|
*/
|
|
1099
|
-
export declare interface WGSLStatementInterface<S extends WGSLSlotMap, F extends WGSLFieldMap> {
|
|
3637
|
+
export declare interface WGSLStatementInterface<S extends WGSLSlotMap, F extends WGSLFieldMap, O extends WGSLOverrideMap = WGSLOverrideMap> {
|
|
1100
3638
|
/** Holds the prepared program. */
|
|
1101
|
-
readonly program: WGSLProgram<S, F>;
|
|
3639
|
+
readonly program: WGSLProgram<S, F, O>;
|
|
1102
3640
|
/** Holds the compute pipeline. */
|
|
1103
3641
|
readonly pipeline: GPUComputePipeline;
|
|
1104
3642
|
/** Holds the uniform bind group over the session's slab. */
|
|
@@ -1106,34 +3644,47 @@ export declare interface WGSLStatementInterface<S extends WGSLSlotMap, F extends
|
|
|
1106
3644
|
/** Binds one buffer range to each slot. */
|
|
1107
3645
|
bind(buffers: {
|
|
1108
3646
|
readonly [K in keyof S]: GPUBufferBinding;
|
|
1109
|
-
}): WGSLBinding<S, F>;
|
|
3647
|
+
}): WGSLBinding<S, F, O>;
|
|
1110
3648
|
/** Dispatches the statement once and resolves when the device finishes it. */
|
|
1111
|
-
execute(binding: WGSLBinding<S, F>, values: WGSLValueMap<F>, grid: WGSLGrid, signal?: AbortSignal): Promise<void>;
|
|
3649
|
+
execute(binding: WGSLBinding<S, F, O>, values: WGSLValueMap<F>, grid: WGSLGrid, signal?: AbortSignal): Promise<void>;
|
|
1112
3650
|
}
|
|
1113
3651
|
|
|
1114
3652
|
/**
|
|
1115
|
-
* Configures a statement: its program, its compute pipeline, its storage bind-group layout,
|
|
3653
|
+
* Configures a statement: its program, its compute pipeline, its storage bind-group layout, its uniform bind group, and its session guard.
|
|
1116
3654
|
*
|
|
1117
3655
|
* @remarks
|
|
1118
|
-
* `layout` is the `@group(0)` storage layout the pipeline was created with,
|
|
1119
|
-
* session's `@group(1)` bind group over the slab for the program's struct size
|
|
3656
|
+
* `layout` is the `@group(0)` storage layout the pipeline was created with, `uniform` is the
|
|
3657
|
+
* session's `@group(1)` bind group over the slab for the program's struct size, and `check` throws
|
|
3658
|
+
* when the owning session has failed or been destroyed.
|
|
1120
3659
|
*
|
|
1121
3660
|
* @example
|
|
1122
3661
|
* ```ts
|
|
1123
|
-
* const options: WGSLStatementOptions<typeof slots, { rows: 'u32' }> = { program, pipeline, layout, uniform }
|
|
3662
|
+
* const options: WGSLStatementOptions<typeof slots, { rows: 'u32' }> = { program, pipeline, layout, uniform, check }
|
|
1124
3663
|
* ```
|
|
1125
3664
|
*/
|
|
1126
|
-
export declare interface WGSLStatementOptions<S extends WGSLSlotMap, F extends WGSLFieldMap> {
|
|
3665
|
+
export declare interface WGSLStatementOptions<S extends WGSLSlotMap, F extends WGSLFieldMap, O extends WGSLOverrideMap = WGSLOverrideMap> {
|
|
1127
3666
|
/** Holds the prepared program. */
|
|
1128
|
-
readonly program: WGSLProgram<S, F>;
|
|
3667
|
+
readonly program: WGSLProgram<S, F, O>;
|
|
1129
3668
|
/** Holds the compute pipeline. */
|
|
1130
3669
|
readonly pipeline: GPUComputePipeline;
|
|
1131
3670
|
/** Holds the storage bind-group layout of the pipeline's `@group(0)`. */
|
|
1132
3671
|
readonly layout: GPUBindGroupLayout;
|
|
1133
3672
|
/** Holds the uniform bind group of the pipeline's `@group(1)`. */
|
|
1134
3673
|
readonly uniform: GPUBindGroup;
|
|
3674
|
+
/** Throws when the session is failed or destroyed. */
|
|
3675
|
+
readonly check: () => void;
|
|
1135
3676
|
}
|
|
1136
3677
|
|
|
3678
|
+
/**
|
|
3679
|
+
* Names an element type a storage slot array can hold.
|
|
3680
|
+
*
|
|
3681
|
+
* @example
|
|
3682
|
+
* ```ts
|
|
3683
|
+
* const element: WGSLStorageElement = 'vec4f'
|
|
3684
|
+
* ```
|
|
3685
|
+
*/
|
|
3686
|
+
export declare type WGSLStorageElement = (typeof WGSL_STORAGE_ELEMENTS)[number];
|
|
3687
|
+
|
|
1137
3688
|
/**
|
|
1138
3689
|
* Describes a uniform struct: its fields, its byte layout, and its rendered WGSL declaration.
|
|
1139
3690
|
*
|
|
@@ -1162,6 +3713,199 @@ export declare interface WGSLStruct<F extends WGSLFieldMap = WGSLFieldMap> {
|
|
|
1162
3713
|
readonly source: string;
|
|
1163
3714
|
}
|
|
1164
3715
|
|
|
3716
|
+
/**
|
|
3717
|
+
* Bounds a subgroup size interval supported by a device or required by a fragment variant.
|
|
3718
|
+
*
|
|
3719
|
+
* @remarks
|
|
3720
|
+
* Variant resolution tests interval containment: an adapter's `[minimum, maximum]` must lie inside
|
|
3721
|
+
* the variant's `[minimum ?? 4, maximum ?? 128]`.
|
|
3722
|
+
*
|
|
3723
|
+
* @example
|
|
3724
|
+
* ```ts
|
|
3725
|
+
* const subgroup: WGSLSubgroupRange = { minimum: 32, maximum: 32 }
|
|
3726
|
+
* ```
|
|
3727
|
+
*/
|
|
3728
|
+
export declare interface WGSLSubgroupRange {
|
|
3729
|
+
/** Holds the inclusive lower bound on subgroup size. */
|
|
3730
|
+
readonly minimum?: number;
|
|
3731
|
+
/** Holds the inclusive upper bound on subgroup size. */
|
|
3732
|
+
readonly maximum?: number;
|
|
3733
|
+
}
|
|
3734
|
+
|
|
3735
|
+
/**
|
|
3736
|
+
* Holds a square tile side length supported by `createWGSLTranspose`.
|
|
3737
|
+
*
|
|
3738
|
+
* @example
|
|
3739
|
+
* ```ts
|
|
3740
|
+
* const tile: WGSLTileSize = 16
|
|
3741
|
+
* ```
|
|
3742
|
+
*/
|
|
3743
|
+
export declare type WGSLTileSize = (typeof WGSL_TILE_SIZES)[number];
|
|
3744
|
+
|
|
3745
|
+
/**
|
|
3746
|
+
* Names what ended a compute pass.
|
|
3747
|
+
*
|
|
3748
|
+
* @example
|
|
3749
|
+
* ```ts
|
|
3750
|
+
* const cause: WGSLTraceCause = 'flush'
|
|
3751
|
+
* ```
|
|
3752
|
+
*/
|
|
3753
|
+
export declare type WGSLTraceCause = (typeof WGSL_TRACE_CAUSES)[number];
|
|
3754
|
+
|
|
3755
|
+
/**
|
|
3756
|
+
* Names how much a session's tracer records.
|
|
3757
|
+
*
|
|
3758
|
+
* @remarks
|
|
3759
|
+
* `'off'` records nothing and costs the default path nothing. `'pass'` records one record per compute
|
|
3760
|
+
* pass. `'statement'` records one compute pass per dispatch and totals them by program name.
|
|
3761
|
+
*
|
|
3762
|
+
* @example
|
|
3763
|
+
* ```ts
|
|
3764
|
+
* const mode: WGSLTraceMode = 'pass'
|
|
3765
|
+
* ```
|
|
3766
|
+
*/
|
|
3767
|
+
export declare type WGSLTraceMode = (typeof WGSL_TRACE_MODES)[number];
|
|
3768
|
+
|
|
3769
|
+
/**
|
|
3770
|
+
* Configures a session's tracer.
|
|
3771
|
+
*
|
|
3772
|
+
* @remarks
|
|
3773
|
+
* `mode` defaults to `'off'`. `capacity` defaults to `512` and is bounded by `2048` (each compute
|
|
3774
|
+
* pass uses two entries of WebGPU's 4096-entry timestamp query set); any pass past `capacity`
|
|
3775
|
+
* increments `WGSLTraceRecord.dropped`.
|
|
3776
|
+
*
|
|
3777
|
+
* @example
|
|
3778
|
+
* ```ts
|
|
3779
|
+
* const options: WGSLTraceOptions = { mode: 'pass', capacity: 256 }
|
|
3780
|
+
* ```
|
|
3781
|
+
*/
|
|
3782
|
+
export declare interface WGSLTraceOptions {
|
|
3783
|
+
/** Names how much the tracer records. Default: `'off'`. */
|
|
3784
|
+
readonly mode?: WGSLTraceMode;
|
|
3785
|
+
/** Holds the most passes one submission records (1 to 2048). Default: `512`. */
|
|
3786
|
+
readonly capacity?: number;
|
|
3787
|
+
}
|
|
3788
|
+
|
|
3789
|
+
/**
|
|
3790
|
+
* Records one compute pass of a submission: its dispatches, its pipeline switches, what ended it, and its GPU time.
|
|
3791
|
+
*
|
|
3792
|
+
* @remarks
|
|
3793
|
+
* `index` counts the submission's passes from `0`. `duration` is in nanoseconds and is `undefined`
|
|
3794
|
+
* when the device lacks `'timestamp-query'` or when timestamp readback fails.
|
|
3795
|
+
*
|
|
3796
|
+
* @example
|
|
3797
|
+
* ```ts
|
|
3798
|
+
* const pass: WGSLTracePass = { index: 0, dispatches: 12, switches: 3, cause: 'read', duration: 48_000 }
|
|
3799
|
+
* ```
|
|
3800
|
+
*/
|
|
3801
|
+
export declare interface WGSLTracePass {
|
|
3802
|
+
/** Holds the pass's position in the submission, from `0`. */
|
|
3803
|
+
readonly index: number;
|
|
3804
|
+
/** Counts the dispatches the pass holds. */
|
|
3805
|
+
readonly dispatches: number;
|
|
3806
|
+
/** Counts the pipeline switches inside the pass. */
|
|
3807
|
+
readonly switches: number;
|
|
3808
|
+
/** Names what ended the pass. */
|
|
3809
|
+
readonly cause: WGSLTraceCause;
|
|
3810
|
+
/** Holds the pass's GPU time in nanoseconds, or `undefined` when the device lacks `'timestamp-query'` or readback fails. */
|
|
3811
|
+
readonly duration?: number;
|
|
3812
|
+
}
|
|
3813
|
+
|
|
3814
|
+
/**
|
|
3815
|
+
* Holds the trace of one settled traced batch.
|
|
3816
|
+
*
|
|
3817
|
+
* @remarks
|
|
3818
|
+
* `passes` lists the recorded compute passes in recording order and `statements` totals the
|
|
3819
|
+
* dispatches by program name. `dropped` counts the passes past the tracer's `capacity`. `bytes`
|
|
3820
|
+
* counts the bytes the batch's copies, clears, writes, and reads moved.
|
|
3821
|
+
*
|
|
3822
|
+
* @example
|
|
3823
|
+
* ```ts
|
|
3824
|
+
* const record: WGSLTraceRecord = {
|
|
3825
|
+
* mode: 'pass',
|
|
3826
|
+
* flushes: 0,
|
|
3827
|
+
* dispatches: 12,
|
|
3828
|
+
* copies: 0,
|
|
3829
|
+
* clears: 0,
|
|
3830
|
+
* writes: 0,
|
|
3831
|
+
* bytes: 0,
|
|
3832
|
+
* switches: 3,
|
|
3833
|
+
* dropped: 0,
|
|
3834
|
+
* passes: [],
|
|
3835
|
+
* statements: [],
|
|
3836
|
+
* }
|
|
3837
|
+
* ```
|
|
3838
|
+
*/
|
|
3839
|
+
export declare interface WGSLTraceRecord {
|
|
3840
|
+
/** Names the mode the record was taken in. */
|
|
3841
|
+
readonly mode: Exclude<WGSLTraceMode, 'off'>;
|
|
3842
|
+
/** Counts slab flushes and explicit `flush` calls that split the submission. */
|
|
3843
|
+
readonly flushes: number;
|
|
3844
|
+
/** Counts the dispatches. */
|
|
3845
|
+
readonly dispatches: number;
|
|
3846
|
+
/** Counts the buffer-to-buffer copies. */
|
|
3847
|
+
readonly copies: number;
|
|
3848
|
+
/** Counts the buffer clears. */
|
|
3849
|
+
readonly clears: number;
|
|
3850
|
+
/** Counts the ordered buffer writes. */
|
|
3851
|
+
readonly writes: number;
|
|
3852
|
+
/** Counts the bytes copied, cleared, written, and read. */
|
|
3853
|
+
readonly bytes: number;
|
|
3854
|
+
/** Counts the pipeline switches across all passes. */
|
|
3855
|
+
readonly switches: number;
|
|
3856
|
+
/** Counts the passes past the tracer's capacity. */
|
|
3857
|
+
readonly dropped: number;
|
|
3858
|
+
/** Lists the recorded compute passes in recording order. */
|
|
3859
|
+
readonly passes: readonly WGSLTracePass[];
|
|
3860
|
+
/** Totals the dispatches by program name. */
|
|
3861
|
+
readonly statements: readonly WGSLTraceStatement[];
|
|
3862
|
+
}
|
|
3863
|
+
|
|
3864
|
+
/**
|
|
3865
|
+
* Totals the dispatches of one program inside a submission.
|
|
3866
|
+
*
|
|
3867
|
+
* @remarks
|
|
3868
|
+
* `name` is the program's name. `duration` is in nanoseconds and is `undefined` when `mode` is
|
|
3869
|
+
* `'pass'`, when the device lacks `'timestamp-query'`, when timestamp readback fails, or when every
|
|
3870
|
+
* pass for that program exceeded `capacity`; when `dropped > 0`, it sums only the passes recorded
|
|
3871
|
+
* within `capacity`.
|
|
3872
|
+
*
|
|
3873
|
+
* @example
|
|
3874
|
+
* ```ts
|
|
3875
|
+
* const statement: WGSLTraceStatement = { name: 'sumPartials', dispatches: 40, switches: 0, duration: 910_000 }
|
|
3876
|
+
* ```
|
|
3877
|
+
*/
|
|
3878
|
+
export declare interface WGSLTraceStatement {
|
|
3879
|
+
/** Names the program. */
|
|
3880
|
+
readonly name: string;
|
|
3881
|
+
/** Counts the program's dispatches. */
|
|
3882
|
+
readonly dispatches: number;
|
|
3883
|
+
/** Counts the times the program's pipeline replaced another inside a pass. */
|
|
3884
|
+
readonly switches: number;
|
|
3885
|
+
/** Holds the program's GPU time in nanoseconds for recorded `'statement'` passes, or `undefined` otherwise. */
|
|
3886
|
+
readonly duration?: number;
|
|
3887
|
+
}
|
|
3888
|
+
|
|
3889
|
+
/**
|
|
3890
|
+
* Carries the input `createWGSLTranspose` builds a tiled transpose fragment from.
|
|
3891
|
+
*
|
|
3892
|
+
* @remarks
|
|
3893
|
+
* The returned fragment's `workgroup` guard holds the invocation count its tile needs (256 for both `16` and `32` tiles).
|
|
3894
|
+
*
|
|
3895
|
+
* @example
|
|
3896
|
+
* ```ts
|
|
3897
|
+
* const input: WGSLTransposeInput = { tile: 16, element: 'f32' }
|
|
3898
|
+
* ```
|
|
3899
|
+
*/
|
|
3900
|
+
export declare interface WGSLTransposeInput {
|
|
3901
|
+
/** Names the fragment. Default: a name built from `element` and `tile`. */
|
|
3902
|
+
readonly name?: string;
|
|
3903
|
+
/** Holds the tile's side length in elements. */
|
|
3904
|
+
readonly tile: WGSLTileSize;
|
|
3905
|
+
/** Names the element type transposed. */
|
|
3906
|
+
readonly element: WGSLScalar;
|
|
3907
|
+
}
|
|
3908
|
+
|
|
1165
3909
|
/**
|
|
1166
3910
|
* Declares a program's uniform: the variable name its text reads and the struct it holds.
|
|
1167
3911
|
*
|
|
@@ -1190,18 +3934,113 @@ export declare type WGSLValueMap<F extends WGSLFieldMap> = {
|
|
|
1190
3934
|
};
|
|
1191
3935
|
|
|
1192
3936
|
/**
|
|
1193
|
-
* Describes a fragment body that replaces the default body when its
|
|
3937
|
+
* Describes a conditional fragment body that replaces the default body when its requirements hold.
|
|
3938
|
+
*
|
|
3939
|
+
* @remarks
|
|
3940
|
+
* `resolveWGSLVariant` checks `extensions`, `languages`, `subgroup`, and `linear` against the
|
|
3941
|
+
* session or render options and chooses the first matching variant in declaration order.
|
|
3942
|
+
* `createWGSLFragment` refuses a variant that declares none of `extensions`, `languages`,
|
|
3943
|
+
* `subgroup`, or `linear` with code `ARGUMENT`, because an unconstrained variant would always
|
|
3944
|
+
* shadow `source`.
|
|
1194
3945
|
*
|
|
1195
3946
|
* @example
|
|
1196
3947
|
* ```ts
|
|
1197
|
-
* const variant: WGSLVariant = {
|
|
3948
|
+
* const variant: WGSLVariant = { extensions: ['subgroups'], linear: true, source: 'fn total(value: f32) -> f32 { return subgroupAdd(value); }' }
|
|
1198
3949
|
* ```
|
|
1199
3950
|
*/
|
|
1200
3951
|
export declare interface WGSLVariant {
|
|
1201
|
-
/**
|
|
1202
|
-
readonly
|
|
3952
|
+
/** Lists the WGSL extensions the variant enables. */
|
|
3953
|
+
readonly extensions?: readonly WGSLExtension[];
|
|
3954
|
+
/** Lists the WGSL language extensions the variant requires. */
|
|
3955
|
+
readonly languages?: readonly WGSLLanguage[];
|
|
3956
|
+
/** Bounds the subgroup size interval the variant needs. */
|
|
3957
|
+
readonly subgroup?: WGSLSubgroupRange;
|
|
3958
|
+
/** Requires a one-dimensional workgroup (`y === 1` and `z === 1`) when `true`; admits any workgroup geometry when `false` or omitted. */
|
|
3959
|
+
readonly linear?: boolean;
|
|
1203
3960
|
/** Holds the variant's WGSL text, with the same signatures as the default body. */
|
|
1204
3961
|
readonly source: string;
|
|
1205
3962
|
}
|
|
1206
3963
|
|
|
3964
|
+
/**
|
|
3965
|
+
* Holds a workgroup invocation count supported by collective fragment factories.
|
|
3966
|
+
*
|
|
3967
|
+
* @example
|
|
3968
|
+
* ```ts
|
|
3969
|
+
* const workgroup: WGSLWorkgroup = 64
|
|
3970
|
+
* ```
|
|
3971
|
+
*/
|
|
3972
|
+
export declare type WGSLWorkgroup = (typeof WGSL_WORKGROUPS)[number];
|
|
3973
|
+
|
|
3974
|
+
/**
|
|
3975
|
+
* Widens bfloat16 bits to the number they hold, as `widenBFloat` in `WGSL_BFLOAT` does.
|
|
3976
|
+
*
|
|
3977
|
+
* @remarks
|
|
3978
|
+
* The bits become the top half of an `f32` word, so every pattern widens exactly; a NaN pattern
|
|
3979
|
+
* returns `NaN`, whose payload a number does not carry. Thrown with code `ARGUMENT` when `bits` is
|
|
3980
|
+
* not an integer from `0` to `0xffff`.
|
|
3981
|
+
*
|
|
3982
|
+
* @param bits - The bfloat16 bits
|
|
3983
|
+
* @returns The value
|
|
3984
|
+
*
|
|
3985
|
+
* @example
|
|
3986
|
+
* ```ts
|
|
3987
|
+
* widenWGSLBFloat(0x3f80) // 1
|
|
3988
|
+
* ```
|
|
3989
|
+
*/
|
|
3990
|
+
export declare function widenWGSLBFloat(bits: number): number;
|
|
3991
|
+
|
|
3992
|
+
/**
|
|
3993
|
+
* Widens OCP FP8 `E4M3FN` bits to the `f32` value they hold, as `widenE4M3` in `WGSL_FP8` does.
|
|
3994
|
+
*
|
|
3995
|
+
* @remarks
|
|
3996
|
+
* Decodes signed zeros (`0x00`/`0x80`), subnormals (`2^-9` to `7 * 2^-9`), normals up to `±448`,
|
|
3997
|
+
* and `NaN` (`0x7f`/`0xff`). Thrown with code `ARGUMENT` when `bits` is not a non-negative integer
|
|
3998
|
+
* from `0` to `255`, `-0` included.
|
|
3999
|
+
*
|
|
4000
|
+
* @param bits - The 8-bit `E4M3FN` pattern
|
|
4001
|
+
* @returns The widened numeric value
|
|
4002
|
+
*
|
|
4003
|
+
* @example
|
|
4004
|
+
* ```ts
|
|
4005
|
+
* widenWGSLE4M3(0x38) // 1
|
|
4006
|
+
* ```
|
|
4007
|
+
*/
|
|
4008
|
+
export declare function widenWGSLE4M3(bits: number): number;
|
|
4009
|
+
|
|
4010
|
+
/**
|
|
4011
|
+
* Widens OCP FP8 `E5M2` bits to the `f32` value they hold, as `widenE5M2` in `WGSL_FP8` does.
|
|
4012
|
+
*
|
|
4013
|
+
* @remarks
|
|
4014
|
+
* Decodes signed zeros (`0x00`/`0x80`), subnormals (`2^-16` to `3 * 2^-16`), normals up to
|
|
4015
|
+
* `±57344`, `±Infinity` (`0x7c`/`0xfc`), and `NaN` (`0x7d..0x7f`, `0xfd..0xff`). Thrown with code
|
|
4016
|
+
* `ARGUMENT` when `bits` is not a non-negative integer from `0` to `255`, `-0` included.
|
|
4017
|
+
*
|
|
4018
|
+
* @param bits - The 8-bit `E5M2` pattern
|
|
4019
|
+
* @returns The widened numeric value
|
|
4020
|
+
*
|
|
4021
|
+
* @example
|
|
4022
|
+
* ```ts
|
|
4023
|
+
* widenWGSLE5M2(0x3c) // 1
|
|
4024
|
+
* ```
|
|
4025
|
+
*/
|
|
4026
|
+
export declare function widenWGSLE5M2(bits: number): number;
|
|
4027
|
+
|
|
4028
|
+
/**
|
|
4029
|
+
* Widens IEEE 754 half-precision bits to the number they hold, as `widenHalf` in `WGSL_HALF` does.
|
|
4030
|
+
*
|
|
4031
|
+
* @remarks
|
|
4032
|
+
* The result is the `f32` value `widenHalf` returns for the same bits, so signed zeros, subnormals,
|
|
4033
|
+
* and infinities widen exactly; a NaN pattern returns `NaN`, whose payload a number does not carry.
|
|
4034
|
+
* Thrown with code `ARGUMENT` when `bits` is not an integer from `0` to `0xffff`.
|
|
4035
|
+
*
|
|
4036
|
+
* @param bits - The half-precision bits
|
|
4037
|
+
* @returns The value
|
|
4038
|
+
*
|
|
4039
|
+
* @example
|
|
4040
|
+
* ```ts
|
|
4041
|
+
* widenWGSLHalf(0x3c00) // 1
|
|
4042
|
+
* ```
|
|
4043
|
+
*/
|
|
4044
|
+
export declare function widenWGSLHalf(bits: number): number;
|
|
4045
|
+
|
|
1207
4046
|
export { }
|