@orkestrel/wgsl 0.0.1 → 0.0.3
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/dist/src/core/index.cjs +198 -98
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +129 -44
- package/dist/src/core/index.d.ts +129 -44
- package/dist/src/core/index.js +199 -99
- package/dist/src/core/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -24,8 +24,9 @@ export declare function collectWGSLFragments(roots: readonly WGSLFragment[]): re
|
|
|
24
24
|
*
|
|
25
25
|
* @remarks
|
|
26
26
|
* A program reads its workgroup's index as
|
|
27
|
-
* `
|
|
28
|
-
*
|
|
27
|
+
* `dispatch.workgroup_id.x + dispatch.workgroup_id.y * dispatch.num_workgroups.x`, which the
|
|
28
|
+
* `WGSL_PLACE` fragment declares as `readPlace(dispatch: Dispatch)`, so a workgroup past the total
|
|
29
|
+
* finds no work. A total of 0 gives one workgroup. Thrown with code
|
|
29
30
|
* `ARGUMENT` when `total` is not a non-negative safe integer, `-0` included, or `limit` is not a
|
|
30
31
|
* positive safe integer, and with code `LIMIT` when the total passes `limit * limit`.
|
|
31
32
|
*
|
|
@@ -224,13 +225,15 @@ export declare function isWGSLScalar(value: unknown): value is WGSLScalar;
|
|
|
224
225
|
*
|
|
225
226
|
* @remarks
|
|
226
227
|
* The text holds, in order: an `enable` directive for each extension a linked fragment's active
|
|
227
|
-
* variant names, in `WGSL_EXTENSIONS` order; the uniform struct declaration; the `
|
|
228
|
-
*
|
|
228
|
+
* variant names, in `WGSL_EXTENSIONS` order; the uniform struct declaration; the `Dispatch` struct,
|
|
229
|
+
* which carries the workgroup-uniform builtins `workgroup_id` and `num_workgroups`; the
|
|
230
|
+
* `Invocation` struct, which carries the per-lane builtin `local_invocation_index`, plus
|
|
229
231
|
* `subgroup_invocation_id` and `subgroup_size` when `enable subgroups;` is emitted; one
|
|
230
232
|
* `@group(0) @binding(N)` storage line per slot in declaration order and the `@group(1) @binding(0)`
|
|
231
|
-
* uniform line; each linked fragment's active body, unchanged; and the entry function
|
|
232
|
-
*
|
|
233
|
-
*
|
|
233
|
+
* uniform line; each linked fragment's active body, unchanged; and the entry function
|
|
234
|
+
* `fn <entry>(invocation: Invocation, dispatch: Dispatch)`. The split lets a helper that takes only
|
|
235
|
+
* `dispatch` return early before a barrier without a per-lane value reaching that condition. A
|
|
236
|
+
* fragment's variant is active when `extensions` switches its extension on.
|
|
234
237
|
*
|
|
235
238
|
* @param program - The program to render
|
|
236
239
|
* @param extensions - Whether each extension is active
|
|
@@ -307,7 +310,8 @@ export declare const WGSL_EXTENSIONS: Readonly<{
|
|
|
307
310
|
* Holds the fragment that widens the IEEE 754 half-precision bits in the low 16 bits of a `u32` to an `f32`.
|
|
308
311
|
*
|
|
309
312
|
* @remarks
|
|
310
|
-
* It declares `fn
|
|
313
|
+
* It declares `fn widenHalf(bits: u32) -> f32`, which takes neither `Invocation` nor `Dispatch`
|
|
314
|
+
* and builds the result from integer bit operations, so
|
|
311
315
|
* signed zeros, subnormals, infinities, and NaN payloads widen exactly and no `f16` extension is
|
|
312
316
|
* needed. An exponent of `0x1f` keeps the fraction under an all-ones `f32` exponent, so infinities
|
|
313
317
|
* stay infinite and NaN payloads survive. A subnormal half rebuilds its `f32` bits from
|
|
@@ -316,7 +320,7 @@ export declare const WGSL_EXTENSIONS: Readonly<{
|
|
|
316
320
|
*
|
|
317
321
|
* @example
|
|
318
322
|
* ```ts
|
|
319
|
-
* WGSL_HALF.name // '
|
|
323
|
+
* WGSL_HALF.name // 'widenHalf'
|
|
320
324
|
* ```
|
|
321
325
|
*/
|
|
322
326
|
export declare const WGSL_HALF: WGSLFragment;
|
|
@@ -341,13 +345,14 @@ export declare const WGSL_MAP: Readonly<{
|
|
|
341
345
|
* Holds the fragment that finds the largest `f32` value across the invocations of a 64-invocation workgroup.
|
|
342
346
|
*
|
|
343
347
|
* @remarks
|
|
344
|
-
* It declares `var<workgroup>
|
|
345
|
-
* `fn
|
|
346
|
-
* every invocation. The entry's workgroup size must hold 64 invocations, and every
|
|
347
|
-
* call it from uniform control flow.
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
* the
|
|
348
|
+
* It declares `var<workgroup> peakShared: array<f32, 64>`, 256 bytes, and
|
|
349
|
+
* `fn peakPartials(invocation: Invocation, value: f32) -> f32`, which returns the workgroup's
|
|
350
|
+
* maximum to every invocation. The entry's workgroup size must hold 64 invocations, and every
|
|
351
|
+
* invocation must call it from uniform control flow. It takes `Invocation` and never `Dispatch`. The
|
|
352
|
+
* default body reduces with `max` in a tree of halving strides. The `subgroups` variant is
|
|
353
|
+
* `reordered`: it stores each subgroup's `subgroupMax` partial at its first invocation's index and
|
|
354
|
+
* the lowest finite `f32` (`-3.4028234663852886e38`) elsewhere, and invocation 0 folds the 64 entries
|
|
355
|
+
* with `max` between 2 barriers (matching `@orkestrel/infer`, so it returns `-3.4028234663852886e38`
|
|
351
356
|
* rather than `-Infinity` when every input is `-Infinity`). It reads no binding and no uniform member.
|
|
352
357
|
*
|
|
353
358
|
* @example
|
|
@@ -358,14 +363,17 @@ export declare const WGSL_MAP: Readonly<{
|
|
|
358
363
|
export declare const WGSL_PEAK: WGSLFragment;
|
|
359
364
|
|
|
360
365
|
/**
|
|
361
|
-
* Holds the fragment that reads a workgroup's two-axis index from the entry
|
|
366
|
+
* Holds the fragment that reads a workgroup's two-axis index from the entry's `Dispatch` struct.
|
|
362
367
|
*
|
|
363
368
|
* @remarks
|
|
364
|
-
* It declares `fn
|
|
365
|
-
* `
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
+
* It declares `fn readPlace(dispatch: Dispatch) -> u32`, which returns
|
|
370
|
+
* `dispatch.workgroup_id.x + dispatch.workgroup_id.y * dispatch.num_workgroups.x`, the statement of
|
|
371
|
+
* `@orkestrel/infer`'s `readPlace`. `Dispatch` holds only values that stay uniform across a
|
|
372
|
+
* workgroup, so a call that returns early on the result stays in uniform control flow before a
|
|
373
|
+
* later `workgroupBarrier()`. `Invocation` holds the per-lane builtins and is not a parameter. Pair
|
|
374
|
+
* the fragment with `computeWGSLGrid`, and multiply by the workgroup size and add
|
|
375
|
+
* `invocation.local_invocation_index` for an invocation's index. It reads no binding and no uniform
|
|
376
|
+
* member.
|
|
369
377
|
*
|
|
370
378
|
* @example
|
|
371
379
|
* ```ts
|
|
@@ -406,13 +414,16 @@ export declare const WGSL_STAGE: Readonly<{
|
|
|
406
414
|
* Holds the fragment that sums one `f32` value from each invocation of a 64-invocation workgroup.
|
|
407
415
|
*
|
|
408
416
|
* @remarks
|
|
409
|
-
* It declares `var<workgroup>
|
|
410
|
-
* `fn
|
|
411
|
-
* invocation. The entry's workgroup size must hold 64 invocations, and every invocation
|
|
412
|
-
* it from uniform control flow.
|
|
417
|
+
* It declares `var<workgroup> sumShared: array<f32, 64>`, 256 bytes, and
|
|
418
|
+
* `fn sumPartials(invocation: Invocation, value: f32) -> f32`, which returns the workgroup's total
|
|
419
|
+
* to every invocation. The entry's workgroup size must hold 64 invocations, and every invocation
|
|
420
|
+
* must call it from uniform control flow. It takes `Invocation` and never `Dispatch`, because it
|
|
421
|
+
* reads only `local_invocation_index` and, in the variant, `subgroup_invocation_id`. The default
|
|
422
|
+
* body reduces in a tree of halving strides. The
|
|
413
423
|
* `subgroups` variant stores each subgroup's `subgroupAdd` partial at its first invocation's index
|
|
414
|
-
* and `0.0` elsewhere, and invocation 0 adds the 64 entries in index order between 2 barriers
|
|
415
|
-
* its rounding order differs from the default body's. It reads no
|
|
424
|
+
* and `0.0` elsewhere, and invocation 0 adds the 64 entries in index order between 2 barriers; the
|
|
425
|
+
* variant is `reordered`, so its rounding order differs from the default body's. It reads no
|
|
426
|
+
* binding and no uniform member.
|
|
416
427
|
*
|
|
417
428
|
* @example
|
|
418
429
|
* ```ts
|
|
@@ -471,7 +482,7 @@ export declare const WGSL_USAGE: Readonly<{
|
|
|
471
482
|
export declare type WGSLAccess = (typeof WGSL_ACCESSES)[number];
|
|
472
483
|
|
|
473
484
|
/**
|
|
474
|
-
* Records one command encoder's worth of dispatches and
|
|
485
|
+
* Records one command encoder's worth of dispatches, copies, clears, and reads, then submits them together.
|
|
475
486
|
*
|
|
476
487
|
* @remarks
|
|
477
488
|
* The batch owns its command encoder and its compute pass, and keeps one pass open across
|
|
@@ -479,14 +490,19 @@ export declare type WGSLAccess = (typeof WGSL_ACCESSES)[number];
|
|
|
479
490
|
* previous one. Each dispatch writes its uniform values to the session's slab and binds them through
|
|
480
491
|
* the 5-argument `setBindGroup(1, group, offsets, 0, 1)` overload. When the slab is full, the batch
|
|
481
492
|
* ends its pass, uploads the slab, submits, clears the slab, and opens a fresh encoder. The pass
|
|
482
|
-
* ends before each `read`
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
* `
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
493
|
+
* ends before each `read`, `copy`, and `clear`, which record `copyBufferToBuffer` and `clearBuffer`
|
|
494
|
+
* on the encoder; the next `encode` begins a new pass and sets its pipeline and groups again. Every
|
|
495
|
+
* upload and submit sits between a synchronous push and pop of a `validation` and an `out-of-memory`
|
|
496
|
+
* error scope; a device error on a submitted command buffer moves the session to `failed` with code
|
|
497
|
+
* `VALIDATION`. `read` resolves after the submission to a caller-owned copy of the bytes. Each
|
|
498
|
+
* `read`, `copy`, and `clear` checks the session, the batch, its buffers' usages, and its offsets,
|
|
499
|
+
* sizes, and ranges before it records anything, so a refused call leaves the open pass in place.
|
|
500
|
+
* Thrown with code `VALIDATION` when a call other than `abort` or `execute` arrives after `submit`
|
|
501
|
+
* or `abort`; with code `ARGUMENT` for a malformed grid, a malformed `read`, `copy`, or `clear`
|
|
502
|
+
* range, a buffer without the usage the call needs, or a `copy` between one buffer and itself; with
|
|
503
|
+
* code `DESTROYED` after the session's `destroy`; and with code `LIMIT` when a grid axis passes the
|
|
504
|
+
* device's `maxComputeWorkgroupsPerDimension`. Open a batch through `session.batch()`, which
|
|
505
|
+
* supplies the options.
|
|
490
506
|
*
|
|
491
507
|
* @example
|
|
492
508
|
* ```ts
|
|
@@ -509,13 +525,19 @@ export declare class WGSLBatch implements WGSLBatchInterface {
|
|
|
509
525
|
get submitted(): boolean;
|
|
510
526
|
encode<S extends WGSLSlotMap, F extends WGSLFieldMap>(binding: WGSLBinding<S, F>, values: WGSLValueMap<F>, grid: WGSLGrid): void;
|
|
511
527
|
read(buffer: GPUBuffer, offset: number, size: number): Promise<ArrayBuffer>;
|
|
528
|
+
copy(source: WGSLSlice, destination: WGSLSlice, size: number): void;
|
|
529
|
+
clear(buffer: GPUBuffer, offset?: number, size?: number): void;
|
|
512
530
|
submit(): void;
|
|
513
531
|
execute(signal?: AbortSignal): Promise<void>;
|
|
514
532
|
abort(): void;
|
|
515
533
|
}
|
|
516
534
|
|
|
517
535
|
/**
|
|
518
|
-
* Records dispatches and
|
|
536
|
+
* Records dispatches, copies, clears, and reads into one submission.
|
|
537
|
+
*
|
|
538
|
+
* @remarks
|
|
539
|
+
* Each `copy`, `clear`, and `read` ends the open compute pass, and the next `encode` begins a new
|
|
540
|
+
* one, so the commands run in the order the batch recorded them.
|
|
519
541
|
*
|
|
520
542
|
* @example
|
|
521
543
|
* ```ts
|
|
@@ -529,6 +551,42 @@ export declare interface WGSLBatchInterface {
|
|
|
529
551
|
encode<S extends WGSLSlotMap, F extends WGSLFieldMap>(binding: WGSLBinding<S, F>, values: WGSLValueMap<F>, grid: WGSLGrid): void;
|
|
530
552
|
/** Records a copy of a buffer range and resolves to its bytes after submission. */
|
|
531
553
|
read(buffer: GPUBuffer, offset: number, size: number): Promise<ArrayBuffer>;
|
|
554
|
+
/**
|
|
555
|
+
* Records a buffer-to-buffer copy of `size` bytes from `source` to `destination` outside any compute pass.
|
|
556
|
+
*
|
|
557
|
+
* @remarks
|
|
558
|
+
* Mirrors `GPUCommandEncoder.copyBufferToBuffer`. The source buffer needs `WGSL_USAGE.source`, the
|
|
559
|
+
* destination buffer needs `WGSL_USAGE.destination`, and the two must be distinct buffers. Default:
|
|
560
|
+
* `0` for each slice's `offset`. Thrown when a slice is not an object, a buffer lacks its usage,
|
|
561
|
+
* both slices hold one buffer, an offset is not a non-negative safe multiple of 4, `size` is not a
|
|
562
|
+
* safe multiple of 4 and at least 4, or either range passes its buffer's end, with code `ARGUMENT`.
|
|
563
|
+
* Thrown when the batch is `submitted` or `aborted`, with code `VALIDATION`. Thrown when the
|
|
564
|
+
* session is destroyed, with code `DESTROYED`, and when the session has failed, with the failure's
|
|
565
|
+
* own code.
|
|
566
|
+
*
|
|
567
|
+
* @param source - The buffer and byte offset to copy from
|
|
568
|
+
* @param destination - The buffer and byte offset to copy to
|
|
569
|
+
* @param size - The byte count to copy
|
|
570
|
+
*/
|
|
571
|
+
copy(source: WGSLSlice, destination: WGSLSlice, size: number): void;
|
|
572
|
+
/**
|
|
573
|
+
* Records a zero fill of a range of `buffer` outside any compute pass.
|
|
574
|
+
*
|
|
575
|
+
* @remarks
|
|
576
|
+
* Mirrors `GPUCommandEncoder.clearBuffer`. The buffer needs `WGSL_USAGE.destination`. Default: `0`
|
|
577
|
+
* for `offset`, and `buffer.size - offset` for `size`, so `clear(buffer)` zeroes the whole buffer.
|
|
578
|
+
* Thrown when the buffer lacks its usage, `offset` is not a non-negative safe multiple of 4, the
|
|
579
|
+
* resolved size is not a safe multiple of 4 and at least 4, or the range passes the buffer's end,
|
|
580
|
+
* with code `ARGUMENT`; `clear(buffer, buffer.size)` resolves a size of `0` and throws with code
|
|
581
|
+
* `ARGUMENT`. Thrown when the batch is `submitted` or `aborted`, with code `VALIDATION`. Thrown
|
|
582
|
+
* when the session is destroyed, with code `DESTROYED`, and when the session has failed, with the
|
|
583
|
+
* failure's own code.
|
|
584
|
+
*
|
|
585
|
+
* @param buffer - The buffer to zero
|
|
586
|
+
* @param offset - The byte offset where the zero fill starts
|
|
587
|
+
* @param size - The byte count to zero
|
|
588
|
+
*/
|
|
589
|
+
clear(buffer: GPUBuffer, offset?: number, size?: number): void;
|
|
532
590
|
/** Hands the recorded commands to the device queue. */
|
|
533
591
|
submit(): void;
|
|
534
592
|
/** Submits the batch and resolves when the device finishes it. */
|
|
@@ -573,8 +631,9 @@ export declare interface WGSLBatchOptions {
|
|
|
573
631
|
* Names the lifecycle status of a batch.
|
|
574
632
|
*
|
|
575
633
|
* @remarks
|
|
576
|
-
* `open` records dispatches and
|
|
577
|
-
* `aborted` discarded its unsubmitted commands.
|
|
634
|
+
* `open` records dispatches, reads, copies, and clears, `submitted` has handed its commands to the
|
|
635
|
+
* queue, and `aborted` discarded its unsubmitted commands. A `copy` or `clear` on a `submitted` or
|
|
636
|
+
* `aborted` batch throws with code `VALIDATION`.
|
|
578
637
|
*
|
|
579
638
|
* @example
|
|
580
639
|
* ```ts
|
|
@@ -857,13 +916,17 @@ export declare type WGSLScalar = (typeof WGSL_SCALARS)[number];
|
|
|
857
916
|
* `open`. Thrown with code `LIMIT` when a program's workgroup size or slot count passes the device's
|
|
858
917
|
* limits, and with code `VALIDATION` from `batch()` while another batch is open. A device failure on
|
|
859
918
|
* a submitted batch, or the device's `lost` promise, moves the session to `failed`, making
|
|
860
|
-
* `prepare`, `batch`, and any open batch's `encode`, `read`, and `submit` throw that failure while
|
|
919
|
+
* `prepare`, `batch`, and any open batch's `encode`, `read`, `copy`, `clear`, and `submit` throw that failure while
|
|
861
920
|
* `destroy` resolves. `destroy` moves the session to `destroyed` at once, aborts the open batch,
|
|
862
921
|
* waits for submitted work and reads, and destroys the uniform buffer and the staging buffers the
|
|
863
922
|
* session created; a repeated `destroy` returns the same promise, settled `abort` and `execute`
|
|
864
923
|
* replay their batch's own settlement, and `prepare`, `batch`, `encode`, `read`, and `submit` throw
|
|
865
|
-
* with code `DESTROYED
|
|
866
|
-
*
|
|
924
|
+
* with code `DESTROYED`, and so do `copy` and `clear` on its batch. The constructor reads its options
|
|
925
|
+
* through `resolveOptions` and throws with code `ARGUMENT`, carrying the option fault as `cause`,
|
|
926
|
+
* when `options` is not a record, when a key is not `extensions` or `uniform` at the top level, `f16`
|
|
927
|
+
* or `subgroups` inside `extensions`, or `size` inside `uniform`, when an `extensions` value is not a
|
|
928
|
+
* boolean, and when `uniform.size` is `null` or not a number. It throws with code `ARGUMENT` and the
|
|
929
|
+
* received `size` in `context` when `uniform.size` is not a positive safe multiple of 4.
|
|
867
930
|
*
|
|
868
931
|
* @example
|
|
869
932
|
* ```ts
|
|
@@ -918,7 +981,10 @@ export declare interface WGSLSessionInterface {
|
|
|
918
981
|
*
|
|
919
982
|
* @remarks
|
|
920
983
|
* `extensions` switches an extension the device supports off; it never switches one on.
|
|
921
|
-
* `uniform.size` sets the slab's byte capacity. Default: `WGSL_UNIFORM_SIZE`.
|
|
984
|
+
* `uniform.size` sets the slab's byte capacity. Default: `WGSL_UNIFORM_SIZE`. The session
|
|
985
|
+
* constructor reads these options through `resolveOptions` and throws with code `ARGUMENT` for an
|
|
986
|
+
* unknown key at any level, an `extensions` value that is not a boolean, a `uniform.size` that is
|
|
987
|
+
* `null` or not a positive safe multiple of 4, and an `options` value that is not a record.
|
|
922
988
|
*
|
|
923
989
|
* @example
|
|
924
990
|
* ```ts
|
|
@@ -1022,6 +1088,25 @@ export declare interface WGSLSlabOptions {
|
|
|
1022
1088
|
readonly capacity: number;
|
|
1023
1089
|
}
|
|
1024
1090
|
|
|
1091
|
+
/**
|
|
1092
|
+
* Locates a byte range's start inside a buffer.
|
|
1093
|
+
*
|
|
1094
|
+
* @remarks
|
|
1095
|
+
* `offset` defaults to `0` and must be a non-negative safe multiple of 4 bytes. A slice carries no
|
|
1096
|
+
* length; the operation that takes it supplies the byte count.
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* ```ts
|
|
1100
|
+
* const slice: WGSLSlice = { buffer, offset: 256 }
|
|
1101
|
+
* ```
|
|
1102
|
+
*/
|
|
1103
|
+
export declare interface WGSLSlice {
|
|
1104
|
+
/** Holds the buffer the range sits in. */
|
|
1105
|
+
readonly buffer: GPUBuffer;
|
|
1106
|
+
/** Holds the range's byte offset from the buffer's start. Default: `0`. */
|
|
1107
|
+
readonly offset?: number;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1025
1110
|
/**
|
|
1026
1111
|
* Declares one storage slot of a program: its access mode and its array element type.
|
|
1027
1112
|
*
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -24,8 +24,9 @@ export declare function collectWGSLFragments(roots: readonly WGSLFragment[]): re
|
|
|
24
24
|
*
|
|
25
25
|
* @remarks
|
|
26
26
|
* A program reads its workgroup's index as
|
|
27
|
-
* `
|
|
28
|
-
*
|
|
27
|
+
* `dispatch.workgroup_id.x + dispatch.workgroup_id.y * dispatch.num_workgroups.x`, which the
|
|
28
|
+
* `WGSL_PLACE` fragment declares as `readPlace(dispatch: Dispatch)`, so a workgroup past the total
|
|
29
|
+
* finds no work. A total of 0 gives one workgroup. Thrown with code
|
|
29
30
|
* `ARGUMENT` when `total` is not a non-negative safe integer, `-0` included, or `limit` is not a
|
|
30
31
|
* positive safe integer, and with code `LIMIT` when the total passes `limit * limit`.
|
|
31
32
|
*
|
|
@@ -224,13 +225,15 @@ export declare function isWGSLScalar(value: unknown): value is WGSLScalar;
|
|
|
224
225
|
*
|
|
225
226
|
* @remarks
|
|
226
227
|
* The text holds, in order: an `enable` directive for each extension a linked fragment's active
|
|
227
|
-
* variant names, in `WGSL_EXTENSIONS` order; the uniform struct declaration; the `
|
|
228
|
-
*
|
|
228
|
+
* variant names, in `WGSL_EXTENSIONS` order; the uniform struct declaration; the `Dispatch` struct,
|
|
229
|
+
* which carries the workgroup-uniform builtins `workgroup_id` and `num_workgroups`; the
|
|
230
|
+
* `Invocation` struct, which carries the per-lane builtin `local_invocation_index`, plus
|
|
229
231
|
* `subgroup_invocation_id` and `subgroup_size` when `enable subgroups;` is emitted; one
|
|
230
232
|
* `@group(0) @binding(N)` storage line per slot in declaration order and the `@group(1) @binding(0)`
|
|
231
|
-
* uniform line; each linked fragment's active body, unchanged; and the entry function
|
|
232
|
-
*
|
|
233
|
-
*
|
|
233
|
+
* uniform line; each linked fragment's active body, unchanged; and the entry function
|
|
234
|
+
* `fn <entry>(invocation: Invocation, dispatch: Dispatch)`. The split lets a helper that takes only
|
|
235
|
+
* `dispatch` return early before a barrier without a per-lane value reaching that condition. A
|
|
236
|
+
* fragment's variant is active when `extensions` switches its extension on.
|
|
234
237
|
*
|
|
235
238
|
* @param program - The program to render
|
|
236
239
|
* @param extensions - Whether each extension is active
|
|
@@ -307,7 +310,8 @@ export declare const WGSL_EXTENSIONS: Readonly<{
|
|
|
307
310
|
* Holds the fragment that widens the IEEE 754 half-precision bits in the low 16 bits of a `u32` to an `f32`.
|
|
308
311
|
*
|
|
309
312
|
* @remarks
|
|
310
|
-
* It declares `fn
|
|
313
|
+
* It declares `fn widenHalf(bits: u32) -> f32`, which takes neither `Invocation` nor `Dispatch`
|
|
314
|
+
* and builds the result from integer bit operations, so
|
|
311
315
|
* signed zeros, subnormals, infinities, and NaN payloads widen exactly and no `f16` extension is
|
|
312
316
|
* needed. An exponent of `0x1f` keeps the fraction under an all-ones `f32` exponent, so infinities
|
|
313
317
|
* stay infinite and NaN payloads survive. A subnormal half rebuilds its `f32` bits from
|
|
@@ -316,7 +320,7 @@ export declare const WGSL_EXTENSIONS: Readonly<{
|
|
|
316
320
|
*
|
|
317
321
|
* @example
|
|
318
322
|
* ```ts
|
|
319
|
-
* WGSL_HALF.name // '
|
|
323
|
+
* WGSL_HALF.name // 'widenHalf'
|
|
320
324
|
* ```
|
|
321
325
|
*/
|
|
322
326
|
export declare const WGSL_HALF: WGSLFragment;
|
|
@@ -341,13 +345,14 @@ export declare const WGSL_MAP: Readonly<{
|
|
|
341
345
|
* Holds the fragment that finds the largest `f32` value across the invocations of a 64-invocation workgroup.
|
|
342
346
|
*
|
|
343
347
|
* @remarks
|
|
344
|
-
* It declares `var<workgroup>
|
|
345
|
-
* `fn
|
|
346
|
-
* every invocation. The entry's workgroup size must hold 64 invocations, and every
|
|
347
|
-
* call it from uniform control flow.
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
* the
|
|
348
|
+
* It declares `var<workgroup> peakShared: array<f32, 64>`, 256 bytes, and
|
|
349
|
+
* `fn peakPartials(invocation: Invocation, value: f32) -> f32`, which returns the workgroup's
|
|
350
|
+
* maximum to every invocation. The entry's workgroup size must hold 64 invocations, and every
|
|
351
|
+
* invocation must call it from uniform control flow. It takes `Invocation` and never `Dispatch`. The
|
|
352
|
+
* default body reduces with `max` in a tree of halving strides. The `subgroups` variant is
|
|
353
|
+
* `reordered`: it stores each subgroup's `subgroupMax` partial at its first invocation's index and
|
|
354
|
+
* the lowest finite `f32` (`-3.4028234663852886e38`) elsewhere, and invocation 0 folds the 64 entries
|
|
355
|
+
* with `max` between 2 barriers (matching `@orkestrel/infer`, so it returns `-3.4028234663852886e38`
|
|
351
356
|
* rather than `-Infinity` when every input is `-Infinity`). It reads no binding and no uniform member.
|
|
352
357
|
*
|
|
353
358
|
* @example
|
|
@@ -358,14 +363,17 @@ export declare const WGSL_MAP: Readonly<{
|
|
|
358
363
|
export declare const WGSL_PEAK: WGSLFragment;
|
|
359
364
|
|
|
360
365
|
/**
|
|
361
|
-
* Holds the fragment that reads a workgroup's two-axis index from the entry
|
|
366
|
+
* Holds the fragment that reads a workgroup's two-axis index from the entry's `Dispatch` struct.
|
|
362
367
|
*
|
|
363
368
|
* @remarks
|
|
364
|
-
* It declares `fn
|
|
365
|
-
* `
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
+
* It declares `fn readPlace(dispatch: Dispatch) -> u32`, which returns
|
|
370
|
+
* `dispatch.workgroup_id.x + dispatch.workgroup_id.y * dispatch.num_workgroups.x`, the statement of
|
|
371
|
+
* `@orkestrel/infer`'s `readPlace`. `Dispatch` holds only values that stay uniform across a
|
|
372
|
+
* workgroup, so a call that returns early on the result stays in uniform control flow before a
|
|
373
|
+
* later `workgroupBarrier()`. `Invocation` holds the per-lane builtins and is not a parameter. Pair
|
|
374
|
+
* the fragment with `computeWGSLGrid`, and multiply by the workgroup size and add
|
|
375
|
+
* `invocation.local_invocation_index` for an invocation's index. It reads no binding and no uniform
|
|
376
|
+
* member.
|
|
369
377
|
*
|
|
370
378
|
* @example
|
|
371
379
|
* ```ts
|
|
@@ -406,13 +414,16 @@ export declare const WGSL_STAGE: Readonly<{
|
|
|
406
414
|
* Holds the fragment that sums one `f32` value from each invocation of a 64-invocation workgroup.
|
|
407
415
|
*
|
|
408
416
|
* @remarks
|
|
409
|
-
* It declares `var<workgroup>
|
|
410
|
-
* `fn
|
|
411
|
-
* invocation. The entry's workgroup size must hold 64 invocations, and every invocation
|
|
412
|
-
* it from uniform control flow.
|
|
417
|
+
* It declares `var<workgroup> sumShared: array<f32, 64>`, 256 bytes, and
|
|
418
|
+
* `fn sumPartials(invocation: Invocation, value: f32) -> f32`, which returns the workgroup's total
|
|
419
|
+
* to every invocation. The entry's workgroup size must hold 64 invocations, and every invocation
|
|
420
|
+
* must call it from uniform control flow. It takes `Invocation` and never `Dispatch`, because it
|
|
421
|
+
* reads only `local_invocation_index` and, in the variant, `subgroup_invocation_id`. The default
|
|
422
|
+
* body reduces in a tree of halving strides. The
|
|
413
423
|
* `subgroups` variant stores each subgroup's `subgroupAdd` partial at its first invocation's index
|
|
414
|
-
* and `0.0` elsewhere, and invocation 0 adds the 64 entries in index order between 2 barriers
|
|
415
|
-
* its rounding order differs from the default body's. It reads no
|
|
424
|
+
* and `0.0` elsewhere, and invocation 0 adds the 64 entries in index order between 2 barriers; the
|
|
425
|
+
* variant is `reordered`, so its rounding order differs from the default body's. It reads no
|
|
426
|
+
* binding and no uniform member.
|
|
416
427
|
*
|
|
417
428
|
* @example
|
|
418
429
|
* ```ts
|
|
@@ -471,7 +482,7 @@ export declare const WGSL_USAGE: Readonly<{
|
|
|
471
482
|
export declare type WGSLAccess = (typeof WGSL_ACCESSES)[number];
|
|
472
483
|
|
|
473
484
|
/**
|
|
474
|
-
* Records one command encoder's worth of dispatches and
|
|
485
|
+
* Records one command encoder's worth of dispatches, copies, clears, and reads, then submits them together.
|
|
475
486
|
*
|
|
476
487
|
* @remarks
|
|
477
488
|
* The batch owns its command encoder and its compute pass, and keeps one pass open across
|
|
@@ -479,14 +490,19 @@ export declare type WGSLAccess = (typeof WGSL_ACCESSES)[number];
|
|
|
479
490
|
* previous one. Each dispatch writes its uniform values to the session's slab and binds them through
|
|
480
491
|
* the 5-argument `setBindGroup(1, group, offsets, 0, 1)` overload. When the slab is full, the batch
|
|
481
492
|
* ends its pass, uploads the slab, submits, clears the slab, and opens a fresh encoder. The pass
|
|
482
|
-
* ends before each `read`
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
* `
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
493
|
+
* ends before each `read`, `copy`, and `clear`, which record `copyBufferToBuffer` and `clearBuffer`
|
|
494
|
+
* on the encoder; the next `encode` begins a new pass and sets its pipeline and groups again. Every
|
|
495
|
+
* upload and submit sits between a synchronous push and pop of a `validation` and an `out-of-memory`
|
|
496
|
+
* error scope; a device error on a submitted command buffer moves the session to `failed` with code
|
|
497
|
+
* `VALIDATION`. `read` resolves after the submission to a caller-owned copy of the bytes. Each
|
|
498
|
+
* `read`, `copy`, and `clear` checks the session, the batch, its buffers' usages, and its offsets,
|
|
499
|
+
* sizes, and ranges before it records anything, so a refused call leaves the open pass in place.
|
|
500
|
+
* Thrown with code `VALIDATION` when a call other than `abort` or `execute` arrives after `submit`
|
|
501
|
+
* or `abort`; with code `ARGUMENT` for a malformed grid, a malformed `read`, `copy`, or `clear`
|
|
502
|
+
* range, a buffer without the usage the call needs, or a `copy` between one buffer and itself; with
|
|
503
|
+
* code `DESTROYED` after the session's `destroy`; and with code `LIMIT` when a grid axis passes the
|
|
504
|
+
* device's `maxComputeWorkgroupsPerDimension`. Open a batch through `session.batch()`, which
|
|
505
|
+
* supplies the options.
|
|
490
506
|
*
|
|
491
507
|
* @example
|
|
492
508
|
* ```ts
|
|
@@ -509,13 +525,19 @@ export declare class WGSLBatch implements WGSLBatchInterface {
|
|
|
509
525
|
get submitted(): boolean;
|
|
510
526
|
encode<S extends WGSLSlotMap, F extends WGSLFieldMap>(binding: WGSLBinding<S, F>, values: WGSLValueMap<F>, grid: WGSLGrid): void;
|
|
511
527
|
read(buffer: GPUBuffer, offset: number, size: number): Promise<ArrayBuffer>;
|
|
528
|
+
copy(source: WGSLSlice, destination: WGSLSlice, size: number): void;
|
|
529
|
+
clear(buffer: GPUBuffer, offset?: number, size?: number): void;
|
|
512
530
|
submit(): void;
|
|
513
531
|
execute(signal?: AbortSignal): Promise<void>;
|
|
514
532
|
abort(): void;
|
|
515
533
|
}
|
|
516
534
|
|
|
517
535
|
/**
|
|
518
|
-
* Records dispatches and
|
|
536
|
+
* Records dispatches, copies, clears, and reads into one submission.
|
|
537
|
+
*
|
|
538
|
+
* @remarks
|
|
539
|
+
* Each `copy`, `clear`, and `read` ends the open compute pass, and the next `encode` begins a new
|
|
540
|
+
* one, so the commands run in the order the batch recorded them.
|
|
519
541
|
*
|
|
520
542
|
* @example
|
|
521
543
|
* ```ts
|
|
@@ -529,6 +551,42 @@ export declare interface WGSLBatchInterface {
|
|
|
529
551
|
encode<S extends WGSLSlotMap, F extends WGSLFieldMap>(binding: WGSLBinding<S, F>, values: WGSLValueMap<F>, grid: WGSLGrid): void;
|
|
530
552
|
/** Records a copy of a buffer range and resolves to its bytes after submission. */
|
|
531
553
|
read(buffer: GPUBuffer, offset: number, size: number): Promise<ArrayBuffer>;
|
|
554
|
+
/**
|
|
555
|
+
* Records a buffer-to-buffer copy of `size` bytes from `source` to `destination` outside any compute pass.
|
|
556
|
+
*
|
|
557
|
+
* @remarks
|
|
558
|
+
* Mirrors `GPUCommandEncoder.copyBufferToBuffer`. The source buffer needs `WGSL_USAGE.source`, the
|
|
559
|
+
* destination buffer needs `WGSL_USAGE.destination`, and the two must be distinct buffers. Default:
|
|
560
|
+
* `0` for each slice's `offset`. Thrown when a slice is not an object, a buffer lacks its usage,
|
|
561
|
+
* both slices hold one buffer, an offset is not a non-negative safe multiple of 4, `size` is not a
|
|
562
|
+
* safe multiple of 4 and at least 4, or either range passes its buffer's end, with code `ARGUMENT`.
|
|
563
|
+
* Thrown when the batch is `submitted` or `aborted`, with code `VALIDATION`. Thrown when the
|
|
564
|
+
* session is destroyed, with code `DESTROYED`, and when the session has failed, with the failure's
|
|
565
|
+
* own code.
|
|
566
|
+
*
|
|
567
|
+
* @param source - The buffer and byte offset to copy from
|
|
568
|
+
* @param destination - The buffer and byte offset to copy to
|
|
569
|
+
* @param size - The byte count to copy
|
|
570
|
+
*/
|
|
571
|
+
copy(source: WGSLSlice, destination: WGSLSlice, size: number): void;
|
|
572
|
+
/**
|
|
573
|
+
* Records a zero fill of a range of `buffer` outside any compute pass.
|
|
574
|
+
*
|
|
575
|
+
* @remarks
|
|
576
|
+
* Mirrors `GPUCommandEncoder.clearBuffer`. The buffer needs `WGSL_USAGE.destination`. Default: `0`
|
|
577
|
+
* for `offset`, and `buffer.size - offset` for `size`, so `clear(buffer)` zeroes the whole buffer.
|
|
578
|
+
* Thrown when the buffer lacks its usage, `offset` is not a non-negative safe multiple of 4, the
|
|
579
|
+
* resolved size is not a safe multiple of 4 and at least 4, or the range passes the buffer's end,
|
|
580
|
+
* with code `ARGUMENT`; `clear(buffer, buffer.size)` resolves a size of `0` and throws with code
|
|
581
|
+
* `ARGUMENT`. Thrown when the batch is `submitted` or `aborted`, with code `VALIDATION`. Thrown
|
|
582
|
+
* when the session is destroyed, with code `DESTROYED`, and when the session has failed, with the
|
|
583
|
+
* failure's own code.
|
|
584
|
+
*
|
|
585
|
+
* @param buffer - The buffer to zero
|
|
586
|
+
* @param offset - The byte offset where the zero fill starts
|
|
587
|
+
* @param size - The byte count to zero
|
|
588
|
+
*/
|
|
589
|
+
clear(buffer: GPUBuffer, offset?: number, size?: number): void;
|
|
532
590
|
/** Hands the recorded commands to the device queue. */
|
|
533
591
|
submit(): void;
|
|
534
592
|
/** Submits the batch and resolves when the device finishes it. */
|
|
@@ -573,8 +631,9 @@ export declare interface WGSLBatchOptions {
|
|
|
573
631
|
* Names the lifecycle status of a batch.
|
|
574
632
|
*
|
|
575
633
|
* @remarks
|
|
576
|
-
* `open` records dispatches and
|
|
577
|
-
* `aborted` discarded its unsubmitted commands.
|
|
634
|
+
* `open` records dispatches, reads, copies, and clears, `submitted` has handed its commands to the
|
|
635
|
+
* queue, and `aborted` discarded its unsubmitted commands. A `copy` or `clear` on a `submitted` or
|
|
636
|
+
* `aborted` batch throws with code `VALIDATION`.
|
|
578
637
|
*
|
|
579
638
|
* @example
|
|
580
639
|
* ```ts
|
|
@@ -857,13 +916,17 @@ export declare type WGSLScalar = (typeof WGSL_SCALARS)[number];
|
|
|
857
916
|
* `open`. Thrown with code `LIMIT` when a program's workgroup size or slot count passes the device's
|
|
858
917
|
* limits, and with code `VALIDATION` from `batch()` while another batch is open. A device failure on
|
|
859
918
|
* a submitted batch, or the device's `lost` promise, moves the session to `failed`, making
|
|
860
|
-
* `prepare`, `batch`, and any open batch's `encode`, `read`, and `submit` throw that failure while
|
|
919
|
+
* `prepare`, `batch`, and any open batch's `encode`, `read`, `copy`, `clear`, and `submit` throw that failure while
|
|
861
920
|
* `destroy` resolves. `destroy` moves the session to `destroyed` at once, aborts the open batch,
|
|
862
921
|
* waits for submitted work and reads, and destroys the uniform buffer and the staging buffers the
|
|
863
922
|
* session created; a repeated `destroy` returns the same promise, settled `abort` and `execute`
|
|
864
923
|
* replay their batch's own settlement, and `prepare`, `batch`, `encode`, `read`, and `submit` throw
|
|
865
|
-
* with code `DESTROYED
|
|
866
|
-
*
|
|
924
|
+
* with code `DESTROYED`, and so do `copy` and `clear` on its batch. The constructor reads its options
|
|
925
|
+
* through `resolveOptions` and throws with code `ARGUMENT`, carrying the option fault as `cause`,
|
|
926
|
+
* when `options` is not a record, when a key is not `extensions` or `uniform` at the top level, `f16`
|
|
927
|
+
* or `subgroups` inside `extensions`, or `size` inside `uniform`, when an `extensions` value is not a
|
|
928
|
+
* boolean, and when `uniform.size` is `null` or not a number. It throws with code `ARGUMENT` and the
|
|
929
|
+
* received `size` in `context` when `uniform.size` is not a positive safe multiple of 4.
|
|
867
930
|
*
|
|
868
931
|
* @example
|
|
869
932
|
* ```ts
|
|
@@ -918,7 +981,10 @@ export declare interface WGSLSessionInterface {
|
|
|
918
981
|
*
|
|
919
982
|
* @remarks
|
|
920
983
|
* `extensions` switches an extension the device supports off; it never switches one on.
|
|
921
|
-
* `uniform.size` sets the slab's byte capacity. Default: `WGSL_UNIFORM_SIZE`.
|
|
984
|
+
* `uniform.size` sets the slab's byte capacity. Default: `WGSL_UNIFORM_SIZE`. The session
|
|
985
|
+
* constructor reads these options through `resolveOptions` and throws with code `ARGUMENT` for an
|
|
986
|
+
* unknown key at any level, an `extensions` value that is not a boolean, a `uniform.size` that is
|
|
987
|
+
* `null` or not a positive safe multiple of 4, and an `options` value that is not a record.
|
|
922
988
|
*
|
|
923
989
|
* @example
|
|
924
990
|
* ```ts
|
|
@@ -1022,6 +1088,25 @@ export declare interface WGSLSlabOptions {
|
|
|
1022
1088
|
readonly capacity: number;
|
|
1023
1089
|
}
|
|
1024
1090
|
|
|
1091
|
+
/**
|
|
1092
|
+
* Locates a byte range's start inside a buffer.
|
|
1093
|
+
*
|
|
1094
|
+
* @remarks
|
|
1095
|
+
* `offset` defaults to `0` and must be a non-negative safe multiple of 4 bytes. A slice carries no
|
|
1096
|
+
* length; the operation that takes it supplies the byte count.
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* ```ts
|
|
1100
|
+
* const slice: WGSLSlice = { buffer, offset: 256 }
|
|
1101
|
+
* ```
|
|
1102
|
+
*/
|
|
1103
|
+
export declare interface WGSLSlice {
|
|
1104
|
+
/** Holds the buffer the range sits in. */
|
|
1105
|
+
readonly buffer: GPUBuffer;
|
|
1106
|
+
/** Holds the range's byte offset from the buffer's start. Default: `0`. */
|
|
1107
|
+
readonly offset?: number;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1025
1110
|
/**
|
|
1026
1111
|
* Declares one storage slot of a program: its access mode and its array element type.
|
|
1027
1112
|
*
|