@orkestrel/wgsl 0.0.0-stage → 0.0.1
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/LICENSE +21 -0
- package/README.md +9 -2
- package/dist/src/core/index.cjs +1836 -0
- package/dist/src/core/index.cjs.map +1 -0
- package/dist/src/core/index.d.cts +1207 -0
- package/dist/src/core/index.d.ts +1207 -0
- package/dist/src/core/index.js +1805 -0
- package/dist/src/core/index.js.map +1 -0
- package/package.json +99 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["INTRINSICS","holds","isError","isObject","isFunction","isString","isArray","isSafeInteger","preview","isNonNegativeInteger","isSafeInteger","isNonNegativeInteger","isSafeInteger","preview","errorToMessage","isSafeInteger","preview","isObject","preview","isNonNegativeInteger","isSafeInteger","isSafeInteger","preview","errorToMessage","isNonEmptyString","preview","isRecord","isString"],"sources":["../../../src/core/constants.ts","../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/helpers.ts","../../../src/core/WGSLBatch.ts","../../../src/core/WGSLSlab.ts","../../../src/core/WGSLStatement.ts","../../../src/core/WGSLSession.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { WGSLFragment } from './types.js'\n\n/**\n * Lists the condition codes a `WGSLError` carries.\n *\n * @remarks\n * `ARGUMENT` marks a malformed argument, `COMPILE` a shader the compiler refuses, `VALIDATION` a\n * declaration or command the package or the device refuses, `LIMIT` an exceeded device limit,\n * `HOST` a lost device, `DESTROYED` a call after `destroy`, and `ABORT` an aborted signal or batch.\n *\n * @example\n * ```ts\n * WGSL_ERROR_CODES.includes('VALIDATION') // true\n * ```\n */\nexport const WGSL_ERROR_CODES = Object.freeze([\n\t'ARGUMENT',\n\t'COMPILE',\n\t'VALIDATION',\n\t'LIMIT',\n\t'HOST',\n\t'DESTROYED',\n\t'ABORT',\n] as const)\n\n/**\n * Keys the global brand a `WGSLError` carries, so another installed copy recognizes it.\n *\n * @remarks\n * The key follows the package-and-class form, `Symbol.for('<package>.<ClassName>')`. The brand is\n * a recognition marker and never proof that the class's constructor ran.\n *\n * @example\n * ```ts\n * WGSL_ERROR_BRAND === Symbol.for('@orkestrel/wgsl.WGSLError') // true\n * ```\n */\nexport const WGSL_ERROR_BRAND: unique symbol = Symbol.for('@orkestrel/wgsl.WGSLError')\n\n/**\n * Lists the scalar types a uniform struct member can hold.\n *\n * @remarks\n * Each scalar aligns to 4 bytes and takes 4 bytes in the `uniform` and `storage` address spaces.\n *\n * @example\n * ```ts\n * WGSL_SCALARS.includes('f32') // true\n * ```\n */\nexport const WGSL_SCALARS = Object.freeze(['u32', 'i32', 'f32'] as const)\n\n/**\n * Lists the access modes a storage slot can declare.\n *\n * @remarks\n * Each member mirrors the WGSL `var<storage, ACCESS>` access mode of the same spelling.\n *\n * @example\n * ```ts\n * WGSL_ACCESSES.includes('read_write') // true\n * ```\n */\nexport const WGSL_ACCESSES = Object.freeze(['read', 'read_write'] as const)\n\n/**\n * Maps each WGSL extension a fragment variant can enable to the device feature that admits it.\n *\n * @remarks\n * Each key mirrors the WGSL `enable` directive of the same spelling, and each value mirrors the\n * WebGPU `GPUFeatureName` a device reports in `device.features`. The key order is the order in\n * which a rendered program emits its `enable` directives.\n *\n * @example\n * ```ts\n * WGSL_EXTENSIONS.f16 // 'shader-f16'\n * ```\n */\nexport const WGSL_EXTENSIONS = Object.freeze({ f16: 'shader-f16', subgroups: 'subgroups' } as const)\n\n/**\n * Mirrors the WebGPU `GPUBufferUsage` bit values under one-word members.\n *\n * @remarks\n * `read` mirrors `MAP_READ`, `write` mirrors `MAP_WRITE`, `source` mirrors `COPY_SRC`,\n * `destination` mirrors `COPY_DST`, `uniform` mirrors `UNIFORM`, `storage` mirrors `STORAGE`,\n * `indirect` mirrors `INDIRECT`, and `query` mirrors `QUERY_RESOLVE`. The library declares\n * `GPUBufferUsage` only as a type, so `src/core` reads these values instead.\n *\n * @example\n * ```ts\n * WGSL_USAGE.uniform | WGSL_USAGE.destination // 72\n * ```\n */\nexport const WGSL_USAGE = Object.freeze({\n\tread: 0x0001,\n\twrite: 0x0002,\n\tsource: 0x0004,\n\tdestination: 0x0008,\n\tuniform: 0x0040,\n\tstorage: 0x0080,\n\tindirect: 0x0100,\n\tquery: 0x0200,\n} as const)\n\n/**\n * Mirrors the WebGPU `GPUMapMode` bit values under one-word members.\n *\n * @remarks\n * `read` mirrors `READ` and `write` mirrors `WRITE`.\n *\n * @example\n * ```ts\n * WGSL_MAP.read // 1\n * ```\n */\nexport const WGSL_MAP = Object.freeze({ read: 0x0001, write: 0x0002 } as const)\n\n/**\n * Mirrors the WebGPU `GPUShaderStage` bit value of the compute stage.\n *\n * @remarks\n * `compute` mirrors `COMPUTE`.\n *\n * @example\n * ```ts\n * WGSL_STAGE.compute // 4\n * ```\n */\nexport const WGSL_STAGE = Object.freeze({ compute: 0x0004 } as const)\n\n/**\n * Holds the default byte capacity of a session's uniform slab.\n *\n * @remarks\n * The session's `uniform.size` option replaces it. At a 256-byte offset alignment the default\n * holds 256 dispatches before a batch flushes.\n *\n * @example\n * ```ts\n * WGSL_UNIFORM_SIZE // 65536\n * ```\n */\nexport const WGSL_UNIFORM_SIZE = 65_536\n\n/**\n * Holds the fragment that reads a workgroup's two-axis index from the entry input struct.\n *\n * @remarks\n * It declares `fn place(invocation: Invocation) -> u32`, which returns\n * `invocation.workgroup_id.x + invocation.workgroup_id.y * invocation.num_workgroups.x`, the\n * statement of infer's `readPlace` recast onto the `Invocation` struct. Pair it with\n * `computeWGSLGrid`, and multiply by the workgroup size and add `local_invocation_index` for an\n * invocation's index. It reads no binding and no uniform member.\n *\n * @example\n * ```ts\n * createWGSLProgram({ name: 'clear', entry, slots, uniform, uses: [WGSL_PLACE] }).fragments // [WGSL_PLACE]\n * ```\n */\nexport const WGSL_PLACE: WGSLFragment = Object.freeze({\n\tname: 'place',\n\tsource: [\n\t\t'fn place(invocation: Invocation) -> u32 {',\n\t\t'\\treturn invocation.workgroup_id.x + invocation.workgroup_id.y * invocation.num_workgroups.x;',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n})\n\n/**\n * Holds the fragment that sums one `f32` value from each invocation of a 64-invocation workgroup.\n *\n * @remarks\n * It declares `var<workgroup> sums: array<f32, 64>` and\n * `fn sum(invocation: Invocation, value: f32) -> f32`, which returns the workgroup's total to every\n * invocation. The entry's workgroup size must hold 64 invocations, and every invocation must call\n * it from uniform control flow. The default body reduces in a tree of halving strides. The\n * `subgroups` variant stores each subgroup's `subgroupAdd` partial at its first invocation's index\n * and `0.0` elsewhere, and invocation 0 adds the 64 entries in index order between 2 barriers, so\n * its rounding order differs from the default body's. It reads no binding and no uniform member.\n *\n * @example\n * ```ts\n * WGSL_SUM.variant?.extension // 'subgroups'\n * ```\n */\nexport const WGSL_SUM: WGSLFragment = Object.freeze({\n\tname: 'sum',\n\tsource: [\n\t\t'var<workgroup> sums: array<f32, 64>;',\n\t\t'',\n\t\t'fn sum(invocation: Invocation, value: f32) -> f32 {',\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tsums[local] = value;',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tfor (var stride = 32u; stride > 0u; stride = stride >> 1u) {',\n\t\t'\\t\\tif (local < stride) {',\n\t\t'\\t\\t\\tsums[local] = sums[local] + sums[local + stride];',\n\t\t'\\t\\t}',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t'\\t}',\n\t\t'\\tlet total = sums[0];',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn total;',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariant: Object.freeze({\n\t\textension: 'subgroups',\n\t\tsource: [\n\t\t\t'var<workgroup> sums: array<f32, 64>;',\n\t\t\t'',\n\t\t\t'fn sum(invocation: Invocation, value: f32) -> f32 {',\n\t\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t\t'\\tlet partial = subgroupAdd(value);',\n\t\t\t'\\tsums[local] = select(0.0, partial, invocation.subgroup_invocation_id == 0u);',\n\t\t\t'\\tworkgroupBarrier();',\n\t\t\t'\\tif (local == 0u) {',\n\t\t\t'\\t\\tvar acc = 0.0;',\n\t\t\t'\\t\\tfor (var i = 0u; i < 64u; i += 1u) {',\n\t\t\t'\\t\\t\\tacc = acc + sums[i];',\n\t\t\t'\\t\\t}',\n\t\t\t'\\t\\tsums[0] = acc;',\n\t\t\t'\\t}',\n\t\t\t'\\tworkgroupBarrier();',\n\t\t\t'\\tlet total = sums[0];',\n\t\t\t'\\tworkgroupBarrier();',\n\t\t\t'\\treturn total;',\n\t\t\t'}',\n\t\t].join('\\n'),\n\t}),\n})\n\n/**\n * Holds the fragment that finds the largest `f32` value across the invocations of a 64-invocation workgroup.\n *\n * @remarks\n * It declares `var<workgroup> peaks: array<f32, 64>` and\n * `fn peak(invocation: Invocation, value: f32) -> f32`, which returns the workgroup's maximum to\n * every invocation. The entry's workgroup size must hold 64 invocations, and every invocation must\n * call it from uniform control flow. The default body reduces with `max` in a tree of halving\n * strides. The `subgroups` variant stores each subgroup's `subgroupMax` partial at its first\n * invocation's index and the lowest finite `f32` (`-3.4028234663852886e38`) elsewhere, and invocation 0 folds\n * the 64 entries with `max` between 2 barriers (matching `@orkestrel/infer`, so it returns `-3.4028234663852886e38`\n * rather than `-Infinity` when every input is `-Infinity`). It reads no binding and no uniform member.\n *\n * @example\n * ```ts\n * WGSL_PEAK.variant?.extension // 'subgroups'\n * ```\n */\nexport const WGSL_PEAK: WGSLFragment = Object.freeze({\n\tname: 'peak',\n\tsource: [\n\t\t'var<workgroup> peaks: array<f32, 64>;',\n\t\t'',\n\t\t'fn peak(invocation: Invocation, value: f32) -> f32 {',\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tpeaks[local] = value;',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tfor (var stride = 32u; stride > 0u; stride = stride >> 1u) {',\n\t\t'\\t\\tif (local < stride) {',\n\t\t'\\t\\t\\tpeaks[local] = max(peaks[local], peaks[local + stride]);',\n\t\t'\\t\\t}',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t'\\t}',\n\t\t'\\tlet largest = peaks[0];',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn largest;',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariant: Object.freeze({\n\t\textension: 'subgroups',\n\t\tsource: [\n\t\t\t'var<workgroup> peaks: array<f32, 64>;',\n\t\t\t'',\n\t\t\t'fn peak(invocation: Invocation, value: f32) -> f32 {',\n\t\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t\t'\\tlet partial = subgroupMax(value);',\n\t\t\t'\\tpeaks[local] = select(-3.4028234663852886e38, partial, invocation.subgroup_invocation_id == 0u);',\n\t\t\t'\\tworkgroupBarrier();',\n\t\t\t'\\tif (local == 0u) {',\n\t\t\t'\\t\\tvar acc = -3.4028234663852886e38;',\n\t\t\t'\\t\\tfor (var i = 0u; i < 64u; i += 1u) {',\n\t\t\t'\\t\\t\\tacc = max(acc, peaks[i]);',\n\t\t\t'\\t\\t}',\n\t\t\t'\\t\\tpeaks[0] = acc;',\n\t\t\t'\\t}',\n\t\t\t'\\tworkgroupBarrier();',\n\t\t\t'\\tlet largest = peaks[0];',\n\t\t\t'\\tworkgroupBarrier();',\n\t\t\t'\\treturn largest;',\n\t\t\t'}',\n\t\t].join('\\n'),\n\t}),\n})\n\n/**\n * Holds the fragment that widens the IEEE 754 half-precision bits in the low 16 bits of a `u32` to an `f32`.\n *\n * @remarks\n * It declares `fn widen(bits: u32) -> f32`, which builds the result from integer bit operations, so\n * signed zeros, subnormals, infinities, and NaN payloads widen exactly and no `f16` extension is\n * needed. An exponent of `0x1f` keeps the fraction under an all-ones `f32` exponent, so infinities\n * stay infinite and NaN payloads survive. A subnormal half rebuilds its `f32` bits from\n * `firstLeadingBit(fraction)`: the leading bit sets the exponent and the bits under it shift into\n * the `f32` fraction, with no float arithmetic. It reads no binding and no uniform member.\n *\n * @example\n * ```ts\n * WGSL_HALF.name // 'half'\n * ```\n */\nexport const WGSL_HALF: WGSLFragment = Object.freeze({\n\tname: 'half',\n\tsource: [\n\t\t'fn widen(bits: u32) -> f32 {',\n\t\t'\\tlet sign = (bits & 0x8000u) << 16u;',\n\t\t'\\tlet exponent = (bits >> 10u) & 0x1fu;',\n\t\t'\\tlet fraction = bits & 0x3ffu;',\n\t\t'\\tif (exponent == 0x1fu) {',\n\t\t'\\t\\treturn bitcast<f32>(sign | 0x7f800000u | (fraction << 13u));',\n\t\t'\\t}',\n\t\t'\\tif (exponent != 0u) {',\n\t\t'\\t\\treturn bitcast<f32>(sign | ((exponent + 112u) << 23u) | (fraction << 13u));',\n\t\t'\\t}',\n\t\t'\\tif (fraction == 0u) {',\n\t\t'\\t\\treturn bitcast<f32>(sign);',\n\t\t'\\t}',\n\t\t'\\tlet top = firstLeadingBit(fraction);',\n\t\t'\\treturn bitcast<f32>(sign | ((top + 103u) << 23u) | ((fraction << (23u - top)) & 0x7fffffu));',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n})\n","import type { WGSLErrorCode, WGSLErrorOptions } from './types.js'\nimport { holds, INTRINSICS, isError, isFunction, isObject } from '@orkestrel/contract'\nimport { WGSL_ERROR_BRAND, WGSL_ERROR_CODES } from './constants.js'\n\n/**\n * Reports one WGSL failure under a stable condition code.\n *\n * @remarks\n * Every refusal the factories, the linker, the helpers, and the slab raise arrives as one of these,\n * so a caller branches on `code` rather than on message text. Narrow a caught value with\n * `isWGSLError` before reading `code`.\n *\n * @example\n * ```ts\n * const error = new WGSLError('The slab capacity must be a multiple of 4.', { code: 'ARGUMENT' })\n * error.code // 'ARGUMENT'\n * ```\n */\nexport class WGSLError extends Error {\n\toverride readonly name = 'WGSLError'\n\treadonly code: WGSLErrorCode\n\treadonly context: Readonly<Record<string, unknown>> | undefined\n\n\t/**\n\t * Creates one classified WGSL failure.\n\t *\n\t * @param message - Human-readable description of what failed\n\t * @param options - The condition, optional structured context, and optional cause\n\t */\n\tconstructor(message: string, options: WGSLErrorOptions) {\n\t\tsuper(message, 'cause' in options ? { cause: options.cause } : undefined)\n\t\tINTRINSICS.define(this, WGSL_ERROR_BRAND, { value: this })\n\t\tthis.code = options.code\n\t\tthis.context = options.context\n\t}\n}\n\n/**\n * Checks whether an unknown value is a WGSL error.\n *\n * @remarks\n * Recognition requires a native `Error` whose prototype is not `Error.prototype`, an own brand\n * property holding the tested value itself, a declared condition code, and an object, callable, or\n * absent context. It recognizes an error from another installed copy of this package, and refuses a\n * look-alike with the same code and no brand, a proxy over a branded error, and a plain object that\n * only carries the brand.\n *\n * @param value - The value to inspect\n * @returns True if the value is a `WGSLError`; false otherwise\n *\n * @example\n * ```ts\n * isWGSLError(new WGSLError('The batch was aborted.', { code: 'ABORT' })) // true\n * isWGSLError(new Error('The batch was aborted.')) // false\n * ```\n */\nexport function isWGSLError(value: unknown): value is WGSLError {\n\treturn holds(() => {\n\t\tif (!isError(value) || INTRINSICS.prototype(value) === INTRINSICS.error.prototype) return false\n\t\tif (INTRINSICS.describe(value, WGSL_ERROR_BRAND)?.value !== value) return false\n\t\tconst code: unknown = INTRINSICS.reflect.read(value, 'code')\n\t\tconst context: unknown = INTRINSICS.reflect.read(value, 'context')\n\t\treturn (\n\t\t\tWGSL_ERROR_CODES.some((declared) => declared === code) &&\n\t\t\t(context === undefined || isObject(context) || isFunction(context))\n\t\t)\n\t})\n}\n","import type { WGSLAccess, WGSLExtension, WGSLGrid, WGSLScalar } from './types.js'\nimport { isArray, isSafeInteger, isString } from '@orkestrel/contract'\nimport { WGSL_ACCESSES, WGSL_EXTENSIONS, WGSL_SCALARS } from './constants.js'\n\n/**\n * Checks whether a value names a scalar type a uniform struct member can hold.\n *\n * @param value - The value to inspect\n * @returns True if the value is one of the `WGSL_SCALARS` members; false otherwise\n *\n * @example\n * ```ts\n * isWGSLScalar('f32') // true\n * isWGSLScalar('f64') // false\n * ```\n */\nexport function isWGSLScalar(value: unknown): value is WGSLScalar {\n\treturn WGSL_SCALARS.some((scalar) => scalar === value)\n}\n\n/**\n * Checks whether a value names a storage slot access mode.\n *\n * @param value - The value to inspect\n * @returns True if the value is one of the `WGSL_ACCESSES` members; false otherwise\n *\n * @example\n * ```ts\n * isWGSLAccess('read_write') // true\n * isWGSLAccess('write') // false\n * ```\n */\nexport function isWGSLAccess(value: unknown): value is WGSLAccess {\n\treturn WGSL_ACCESSES.some((access) => access === value)\n}\n\n/**\n * Checks whether a value names a WGSL extension a fragment variant can enable.\n *\n * @remarks\n * Only an own key of `WGSL_EXTENSIONS` passes, so an inherited name such as `toString` fails.\n *\n * @param value - The value to inspect\n * @returns True if the value is a key of `WGSL_EXTENSIONS`; false otherwise\n *\n * @example\n * ```ts\n * isWGSLExtension('subgroups') // true\n * isWGSLExtension('shader-f16') // false\n * ```\n */\nexport function isWGSLExtension(value: unknown): value is WGSLExtension {\n\treturn isString(value) && Object.hasOwn(WGSL_EXTENSIONS, value)\n}\n\n/**\n * Checks whether a value holds a positive safe integer count on each of three axes.\n *\n * @remarks\n * The value must be an array of length 3, and each of its indices must hold a safe integer of at\n * least 1, so a sparse array, a zero count, and a fraction fail.\n *\n * @param value - The value to inspect\n * @returns True if the value is a `WGSLGrid`; false otherwise\n *\n * @example\n * ```ts\n * isWGSLGrid([64, 1, 1]) // true\n * isWGSLGrid([0, 1, 1]) // false\n * ```\n */\nexport function isWGSLGrid(value: unknown): value is WGSLGrid {\n\tif (!isArray(value) || value.length !== 3) return false\n\ttry {\n\t\tconst [x, y, z] = value\n\t\treturn isSafeInteger(x) && x >= 1 && isSafeInteger(y) && y >= 1 && isSafeInteger(z) && z >= 1\n\t} catch {\n\t\treturn false\n\t}\n}\n","import type { WGSLExtension, WGSLFragment, WGSLGrid, WGSLProgram } from './types.js'\nimport { isNonNegativeInteger, isSafeInteger, preview } from '@orkestrel/contract'\nimport { WGSL_EXTENSIONS } from './constants.js'\nimport { WGSLError } from './errors.js'\n\n/**\n * Collects every fragment the roots reach, each once, in dependency order.\n *\n * @remarks\n * The walk is an iterative postorder over each fragment's `uses`, so a fragment follows every\n * fragment it uses. A fragment reached twice, as in a diamond, appears once, keyed on identity.\n * Thrown with code `VALIDATION` when two distinct fragments share one name, and when a fragment\n * reaches itself, with the cycle's names in order in `context.cycle`.\n *\n * @param roots - The fragments an entry body calls, in the order they are listed\n * @returns The reached fragments, frozen\n *\n * @example\n * ```ts\n * const square = createWGSLFragment({ name: 'square', source: 'fn square(value: f32) -> f32 { return value * value; }' })\n * const cube = createWGSLFragment({ name: 'cube', source: 'fn cube(value: f32) -> f32 { return square(value) * value; }', uses: [square] })\n * collectWGSLFragments([cube, square]).map((fragment) => fragment.name) // ['square', 'cube']\n * ```\n */\nexport function collectWGSLFragments(roots: readonly WGSLFragment[]): readonly WGSLFragment[] {\n\tconst order: WGSLFragment[] = []\n\tconst linked = new Set<WGSLFragment>()\n\tconst names = new Set<string>()\n\tconst path: WGSLFragment[] = []\n\tconst stack = roots\n\t\t.toReversed()\n\t\t.map((root): readonly [fragment: WGSLFragment, exit: boolean] => [root, false])\n\twhile (stack.length > 0) {\n\t\tconst frame = stack.pop()\n\t\tif (frame === undefined) break\n\t\tconst [fragment, exit] = frame\n\t\tif (exit) {\n\t\t\tpath.pop()\n\t\t\tlinked.add(fragment)\n\t\t\torder.push(fragment)\n\t\t\tcontinue\n\t\t}\n\t\tif (linked.has(fragment)) continue\n\t\tconst start = path.indexOf(fragment)\n\t\tif (start !== -1) {\n\t\t\tconst cycle = [...path.slice(start), fragment].map((member) => member.name)\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The fragment ${preview(fragment.name)} reaches itself through ${cycle.join(' -> ')}; remove one of these uses.`,\n\t\t\t\t{ code: 'VALIDATION', context: { cycle } },\n\t\t\t)\n\t\t}\n\t\tif (names.has(fragment.name)) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`Two distinct fragments are named ${preview(fragment.name)}; a linked program holds one fragment per name, so rename one or pass the same fragment object.`,\n\t\t\t\t{ code: 'VALIDATION', context: { name: fragment.name } },\n\t\t\t)\n\t\t}\n\t\tnames.add(fragment.name)\n\t\tpath.push(fragment)\n\t\tstack.push(\n\t\t\t[fragment, true],\n\t\t\t...fragment.uses\n\t\t\t\t.toReversed()\n\t\t\t\t.map((used): readonly [fragment: WGSLFragment, exit: boolean] => [used, false]),\n\t\t)\n\t}\n\treturn Object.freeze(order)\n}\n\n/**\n * Renders a program's complete WGSL text for one set of active extensions.\n *\n * @remarks\n * The text holds, in order: an `enable` directive for each extension a linked fragment's active\n * variant names, in `WGSL_EXTENSIONS` order; the uniform struct declaration; the `Invocation` entry\n * input struct, which carries `local_invocation_index`, `workgroup_id`, and `num_workgroups`, plus\n * `subgroup_invocation_id` and `subgroup_size` when `enable subgroups;` is emitted; one\n * `@group(0) @binding(N)` storage line per slot in declaration order and the `@group(1) @binding(0)`\n * uniform line; each linked fragment's active body, unchanged; and the entry function, which takes\n * the input struct as `invocation`. A fragment's variant is active when `extensions` switches its\n * extension on.\n *\n * @param program - The program to render\n * @param extensions - Whether each extension is active\n * @returns The WGSL text, ending in a line feed\n *\n * @example\n * ```ts\n * renderWGSLProgram(program, { f16: false, subgroups: false }).startsWith('struct Shape {') // true\n * ```\n */\nexport function renderWGSLProgram(\n\tprogram: WGSLProgram,\n\textensions: Readonly<Record<WGSLExtension, boolean>>,\n): string {\n\tconst variants = program.fragments.map((fragment) =>\n\t\tfragment.variant !== undefined && extensions[fragment.variant.extension]\n\t\t\t? fragment.variant\n\t\t\t: undefined,\n\t)\n\tconst enabled = Object.keys(WGSL_EXTENSIONS).filter((name) =>\n\t\tvariants.some((variant) => variant?.extension === name),\n\t)\n\tconst subgroups = enabled.includes('subgroups')\n\t\t? [\n\t\t\t\t'\\t@builtin(subgroup_invocation_id) subgroup_invocation_id: u32,',\n\t\t\t\t'\\t@builtin(subgroup_size) subgroup_size: u32,',\n\t\t\t]\n\t\t: []\n\tconst invocation = [\n\t\t'struct Invocation {',\n\t\t'\\t@builtin(local_invocation_index) local_invocation_index: u32,',\n\t\t'\\t@builtin(workgroup_id) workgroup_id: vec3u,',\n\t\t'\\t@builtin(num_workgroups) num_workgroups: vec3u,',\n\t\t...subgroups,\n\t\t'}',\n\t]\n\tconst bindings = [\n\t\t...Object.entries(program.slots).map(\n\t\t\t([name, slot], index) =>\n\t\t\t\t`@group(0) @binding(${index}) var<storage, ${slot.access}> ${name}: array<${slot.element}>;`,\n\t\t),\n\t\t`@group(1) @binding(0) var<uniform> ${program.uniform.name}: ${program.uniform.struct.name};`,\n\t]\n\tconst bodies = program.fragments.map(\n\t\t(fragment, index) => variants[index]?.source ?? fragment.source,\n\t)\n\tconst [x, y, z] = program.entry.size\n\tconst entry = [\n\t\t`@compute @workgroup_size(${x}, ${y}, ${z})`,\n\t\t`fn ${program.entry.name}(invocation: Invocation) {`,\n\t\tprogram.entry.source,\n\t\t'}',\n\t]\n\tconst sections = [\n\t\tenabled.map((name) => `enable ${name};`).join('\\n'),\n\t\tprogram.uniform.struct.source,\n\t\tinvocation.join('\\n'),\n\t\tbindings.join('\\n'),\n\t\t...bodies,\n\t\tentry.join('\\n'),\n\t]\n\treturn `${sections.filter((section) => section.length > 0).join('\\n\\n')}\\n`\n}\n\n/**\n * Computes a dispatch's workgroup counts for a total: the x axis up to the limit, then the y axis.\n *\n * @remarks\n * A program reads its workgroup's index as\n * `invocation.workgroup_id.x + invocation.workgroup_id.y * invocation.num_workgroups.x`, so a\n * workgroup past the total finds no work. A total of 0 gives one workgroup. Thrown with code\n * `ARGUMENT` when `total` is not a non-negative safe integer, `-0` included, or `limit` is not a\n * positive safe integer, and with code `LIMIT` when the total passes `limit * limit`.\n *\n * @param total - The number of workgroups\n * @param limit - The device's `maxComputeWorkgroupsPerDimension`\n * @returns The counts on the x, y, and z axes\n *\n * @example\n * ```ts\n * computeWGSLGrid(70_000, 65_535) // [65535, 2, 1]\n * ```\n */\nexport function computeWGSLGrid(total: number, limit: number): WGSLGrid {\n\tif (!isNonNegativeInteger(total) || !isSafeInteger(total)) {\n\t\tthrow new WGSLError(\n\t\t\t`A workgroup total must be a non-negative safe integer; received ${preview(total)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { total } },\n\t\t)\n\t}\n\tif (!isSafeInteger(limit) || limit < 1) {\n\t\tthrow new WGSLError(\n\t\t\t`A per-axis workgroup limit must be a positive safe integer; received ${preview(limit)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { limit } },\n\t\t)\n\t}\n\tconst x = Math.max(1, Math.min(total, limit))\n\tconst y = Math.max(1, Math.ceil(total / x))\n\tif (y > limit) {\n\t\tthrow new WGSLError(\n\t\t\t`A dispatch of ${total} workgroups passes the limit of ${limit} on each of two axes; split it into dispatches of at most ${limit * limit} workgroups.`,\n\t\t\t{ code: 'LIMIT', context: { total, limit } },\n\t\t)\n\t}\n\tconst grid: WGSLGrid = [x, y, 1]\n\treturn Object.freeze(grid)\n}\n\n/**\n * Computes the smallest multiple of an alignment at or above an offset.\n *\n * @remarks\n * Thrown with code `ARGUMENT` when `offset` is not a non-negative safe integer, `-0` included, or\n * `alignment` is not a positive safe integer.\n *\n * @param offset - The byte offset to align\n * @param alignment - The byte alignment\n * @returns The aligned byte offset\n *\n * @example\n * ```ts\n * computeWGSLOffset(36, 256) // 256\n * ```\n */\nexport function computeWGSLOffset(offset: number, alignment: number): number {\n\tif (!isNonNegativeInteger(offset) || !isSafeInteger(offset)) {\n\t\tthrow new WGSLError(\n\t\t\t`A byte offset must be a non-negative safe integer; received ${preview(offset)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { offset } },\n\t\t)\n\t}\n\tif (!isSafeInteger(alignment) || alignment < 1) {\n\t\tthrow new WGSLError(\n\t\t\t`A byte alignment must be a positive safe integer; received ${preview(alignment)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { alignment } },\n\t\t)\n\t}\n\treturn Math.ceil(offset / alignment) * alignment\n}\n","import type {\n\tWGSLBatchInterface,\n\tWGSLBatchOptions,\n\tWGSLBatchStatus,\n\tWGSLBinding,\n\tWGSLFieldMap,\n\tWGSLGrid,\n\tWGSLRead,\n\tWGSLSlabInterface,\n\tWGSLSlotMap,\n\tWGSLStruct,\n\tWGSLValueMap,\n} from './types.js'\nimport { errorToMessage, isNonNegativeInteger, isSafeInteger, preview } from '@orkestrel/contract'\nimport { WGSL_MAP, WGSL_USAGE } from './constants.js'\nimport { WGSLError } from './errors.js'\n\n/**\n * Records one command encoder's worth of dispatches and buffer reads, then submits them together.\n *\n * @remarks\n * The batch owns its command encoder and its compute pass, and keeps one pass open across\n * consecutive `encode` calls, skipping a `setPipeline` or a `setBindGroup(0, ...)` that repeats the\n * previous one. Each dispatch writes its uniform values to the session's slab and binds them through\n * the 5-argument `setBindGroup(1, group, offsets, 0, 1)` overload. When the slab is full, the batch\n * ends its pass, uploads the slab, submits, clears the slab, and opens a fresh encoder. The pass\n * ends before each `read` copy. Every upload and submit sits between a synchronous push and pop of a\n * `validation` and an `out-of-memory` error scope; a device error on a submitted command buffer\n * moves the session to `failed` with code `VALIDATION`. `read` resolves after the submission to a\n * caller-owned copy of the bytes. Thrown with code `VALIDATION` when a call other than `abort` or\n * `execute` arrives after `submit` or `abort`; with code `ARGUMENT` for a malformed grid or read\n * range; and with code `LIMIT` when a grid axis passes the device's\n * `maxComputeWorkgroupsPerDimension`. Open a batch through `session.batch()`, which supplies the\n * options.\n *\n * @example\n * ```ts\n * const batch = session.batch()\n * batch.encode(binding, { count: 64 }, [1, 1, 1])\n * const bytes = batch.read(buffer, 0, 256)\n * await batch.execute()\n * new Uint32Array(await bytes)[0] // the first word the dispatch wrote\n * ```\n */\nexport class WGSLBatch implements WGSLBatchInterface {\n\treadonly #device: GPUDevice\n\treadonly #limit: number\n\treadonly #options: WGSLBatchOptions\n\treadonly #checkSession: () => void\n\treadonly #slab: WGSLSlabInterface\n\treadonly #offsets = new Uint32Array(1)\n\treadonly #submissions: Array<Promise<WGSLError | undefined>> = []\n\treadonly #reads: WGSLRead[] = []\n\treadonly #result = Promise.withResolvers<WGSLError | undefined>()\n\t#encoder: GPUCommandEncoder\n\t#pass: GPUComputePassEncoder | undefined\n\t#pipeline: GPUComputePipeline | undefined\n\t#group: GPUBindGroup | undefined\n\t#binding: unknown\n\t#uniform: GPUBindGroup | undefined\n\t#status: WGSLBatchStatus = 'open'\n\n\t/**\n\t * Creates an open batch with a fresh command encoder.\n\t *\n\t * @param device - The device whose encoder records the commands and whose queue runs them\n\t * @param options - The session's slab and the session hooks\n\t */\n\tconstructor(device: GPUDevice, options: WGSLBatchOptions) {\n\t\tthis.#device = device\n\t\tthis.#limit = device.limits.maxComputeWorkgroupsPerDimension\n\t\tthis.#options = options\n\t\tthis.#checkSession = options.check\n\t\tthis.#slab = options.slab\n\t\tthis.#encoder = device.createCommandEncoder()\n\t}\n\n\tget submitted(): boolean {\n\t\treturn this.#status === 'submitted'\n\t}\n\n\tencode<S extends WGSLSlotMap, F extends WGSLFieldMap>(\n\t\tbinding: WGSLBinding<S, F>,\n\t\tvalues: WGSLValueMap<F>,\n\t\tgrid: WGSLGrid,\n\t): void {\n\t\tthis.#checkSession()\n\t\tif (this.#status !== 'open') this.#check()\n\t\tif (!Array.isArray(grid) || grid.length !== 3) this.#refuseGrid(grid)\n\t\tconst x = grid[0]\n\t\tconst y = grid[1]\n\t\tconst z = grid[2]\n\t\tif (\n\t\t\ttypeof x !== 'number' ||\n\t\t\ttypeof y !== 'number' ||\n\t\t\ttypeof z !== 'number' ||\n\t\t\tx < 1 ||\n\t\t\ty < 1 ||\n\t\t\tz < 1 ||\n\t\t\t((x | 0) !== x && !Number.isSafeInteger(x)) ||\n\t\t\t((y | 0) !== y && !Number.isSafeInteger(y)) ||\n\t\t\t((z | 0) !== z && !Number.isSafeInteger(z))\n\t\t) {\n\t\t\tthis.#refuseGrid(grid)\n\t\t}\n\t\tconst limit = this.#limit\n\t\tif (x > limit || y > limit || z > limit) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The grid [${x}, ${y}, ${z}] passes the device's ${limit} workgroups per axis; compute the grid with computeWGSLGrid or split the dispatch.`,\n\t\t\t\t{ code: 'LIMIT', context: { grid: [x, y, z], limit } },\n\t\t\t)\n\t\t}\n\t\tconst { statement } = binding\n\t\tconst struct = statement.program.uniform.struct\n\t\tconst written = this.#slab.write(struct, values)\n\t\tconst offset = written === undefined ? this.#flushWrite(struct, values) : written\n\t\tif (this.#binding === binding && this.#pass !== undefined && this.#uniform !== undefined) {\n\t\t\tthis.#offsets[0] = offset\n\t\t\tthis.#pass.setBindGroup(1, this.#uniform, this.#offsets, 0, 1)\n\t\t\tthis.#pass.dispatchWorkgroups(x, y, z)\n\t\t\treturn\n\t\t}\n\t\tconst pass = this.#pass ?? this.#open()\n\t\tif (this.#pipeline !== statement.pipeline) {\n\t\t\tpass.setPipeline(statement.pipeline)\n\t\t\tthis.#pipeline = statement.pipeline\n\t\t}\n\t\tif (this.#group !== binding.group) {\n\t\t\tpass.setBindGroup(0, binding.group)\n\t\t\tthis.#group = binding.group\n\t\t}\n\t\tthis.#binding = binding\n\t\tthis.#uniform = statement.uniform\n\t\tthis.#offsets[0] = offset\n\t\tpass.setBindGroup(1, statement.uniform, this.#offsets, 0, 1)\n\t\tpass.dispatchWorkgroups(x, y, z)\n\t}\n\n\tread(buffer: GPUBuffer, offset: number, size: number): Promise<ArrayBuffer> {\n\t\tthis.#check()\n\t\tif ((buffer.usage & WGSL_USAGE.source) === 0) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`A read needs a buffer with the source usage (WGSL_USAGE.source), so the batch can copy it; its usage is ${buffer.usage}.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { usage: buffer.usage } },\n\t\t\t)\n\t\t}\n\t\tif (!isNonNegativeInteger(offset) || !isSafeInteger(offset) || offset % 4 !== 0) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`A read starts at ${preview(offset)}; a read offset must be a non-negative safe multiple of 4 bytes.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { offset } },\n\t\t\t)\n\t\t}\n\t\tif (!isSafeInteger(size) || size < 4 || size % 4 !== 0) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`A read spans ${preview(size)} bytes; a read size must be a safe multiple of 4 bytes, at least 4.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { size } },\n\t\t\t)\n\t\t}\n\t\tif (offset + size > buffer.size) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`A read ends at byte ${offset + size}, past its buffer's ${buffer.size} bytes; shorten the range.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { offset, size, length: buffer.size } },\n\t\t\t)\n\t\t}\n\t\tthis.#close()\n\t\tconst staging = this.#options.lease(size)\n\t\tthis.#encoder.copyBufferToBuffer(buffer, offset, staging, 0, size)\n\t\tconst result = Promise.withResolvers<ArrayBuffer>()\n\t\t// Marks the rejection handled, so an aborted read nobody awaits raises no unhandled rejection; an awaiting caller still receives it.\n\t\tresult.promise.catch(() => undefined)\n\t\tthis.#reads.push([staging, size, result])\n\t\treturn result.promise\n\t}\n\n\tsubmit(): void {\n\t\tthis.#check()\n\t\tthis.#close()\n\t\tthis.#commit()\n\t\tthis.#status = 'submitted'\n\t\tthis.#options.release(this)\n\t\tthis.#result.resolve(this.#finish())\n\t\tthis.#options.track(this.#result.promise)\n\t}\n\n\tasync execute(signal?: AbortSignal): Promise<void> {\n\t\tif (signal?.aborted === true) {\n\t\t\tthis.abort()\n\t\t\tthrow new WGSLError('The signal aborted the batch before it finished.', {\n\t\t\t\tcode: 'ABORT',\n\t\t\t\tcause: signal.reason,\n\t\t\t})\n\t\t}\n\t\tif (this.#status === 'open') this.submit()\n\t\tconst failure = signal === undefined ? await this.#result.promise : await this.#race(signal)\n\t\tif (failure !== undefined) throw failure\n\t}\n\n\tabort(): void {\n\t\tconst error = new WGSLError('The batch was aborted, and its pending reads were rejected.', {\n\t\t\tcode: 'ABORT',\n\t\t})\n\t\tfor (const [, , result] of this.#reads) result.reject(error)\n\t\tif (this.#status !== 'open') return\n\t\tthis.#status = 'aborted'\n\t\tthis.#slab.clear()\n\t\tfor (const [staging] of this.#reads) this.#options.restore(staging)\n\t\tthis.#options.release(this)\n\t\tthis.#result.resolve(this.#discard(error))\n\t\tthis.#options.track(this.#result.promise)\n\t}\n\n\t// Throws when the session refuses commands or the batch has ended.\n\t#check(): void {\n\t\tthis.#options.check()\n\t\tif (this.#status !== 'open') {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The batch is ${this.#status} and takes no more commands; open another with session.batch().`,\n\t\t\t\t{ code: 'VALIDATION', context: { status: this.#status } },\n\t\t\t)\n\t\t}\n\t}\n\n\t// Throws an ARGUMENT error for a malformed dispatch grid.\n\t#refuseGrid(grid: unknown): never {\n\t\tthrow new WGSLError(\n\t\t\t`A dispatch grid must hold three positive safe integer workgroup counts, such as [4, 1, 1]; received ${preview(grid)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { grid } },\n\t\t)\n\t}\n\n\t// Flushes the current batch and retries one slab write on the cleared slab.\n\t#flushWrite<F extends WGSLFieldMap>(struct: WGSLStruct<F>, values: WGSLValueMap<F>): number {\n\t\tthis.#flush()\n\t\tconst retry = this.#slab.write(struct, values)\n\t\tif (retry === undefined) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The struct ${preview(struct.name)} does not fit an empty slab of ${this.#slab.capacity} bytes; raise the session's uniform size.`,\n\t\t\t\t{ code: 'LIMIT', context: { name: struct.name, size: struct.size } },\n\t\t\t)\n\t\t}\n\t\treturn retry\n\t}\n\n\t// Returns the open compute pass, beginning one when none is open.\n\t#open(): GPUComputePassEncoder {\n\t\tif (this.#pass !== undefined) return this.#pass\n\t\tconst pass = this.#encoder.beginComputePass()\n\t\tthis.#pass = pass\n\t\treturn pass\n\t}\n\n\t// Ends the open compute pass and forgets the pipeline, storage group, and uniform cache it set.\n\t#close(): void {\n\t\tthis.#pass?.end()\n\t\tthis.#pass = undefined\n\t\tthis.#pipeline = undefined\n\t\tthis.#group = undefined\n\t\tthis.#binding = undefined\n\t\tthis.#uniform = undefined\n\t}\n\n\t// Submits the commands recorded so far and continues on a fresh encoder.\n\t#flush(): void {\n\t\tthis.#close()\n\t\tthis.#commit()\n\t\tthis.#encoder = this.#device.createCommandEncoder()\n\t}\n\n\t// Uploads the slab and submits the encoder inside one synchronous pair of error scopes.\n\t#commit(): void {\n\t\tconst device = this.#device\n\t\tdevice.pushErrorScope('out-of-memory')\n\t\tdevice.pushErrorScope('validation')\n\t\tthis.#options.slab.upload()\n\t\tdevice.queue.submit([this.#encoder.finish()])\n\t\tconst validation = device.popErrorScope()\n\t\tconst memory = device.popErrorScope()\n\t\tthis.#slab.clear()\n\t\tthis.#submissions.push(this.#scope(validation, memory))\n\t}\n\n\t// Maps one submission's popped error scopes to its device failure; it never rejects.\n\tasync #scope(\n\t\tvalidation: Promise<GPUError | null>,\n\t\tmemory: Promise<GPUError | null>,\n\t): Promise<WGSLError | undefined> {\n\t\ttry {\n\t\t\tconst [invalid, exhausted] = await Promise.all([validation, memory])\n\t\t\tconst error = invalid ?? exhausted\n\t\t\tif (error === null) return undefined\n\t\t\tconst filter = invalid === null ? 'out-of-memory' : 'validation'\n\t\t\treturn new WGSLError(`The device refused a submitted batch (${filter}): ${error.message}`, {\n\t\t\t\tcode: 'VALIDATION',\n\t\t\t\tcontext: { filter, message: error.message },\n\t\t\t})\n\t\t} catch (cause) {\n\t\t\treturn new WGSLError(\n\t\t\t\t`The device stopped reporting a submitted batch's errors: ${errorToMessage(cause)}`,\n\t\t\t\t{ code: 'HOST', cause },\n\t\t\t)\n\t\t}\n\t}\n\n\t// Waits for every submission, records the first device failure on the session, and returns it.\n\tasync #drain(): Promise<WGSLError | undefined> {\n\t\ttry {\n\t\t\tconst done = this.#device.queue.onSubmittedWorkDone()\n\t\t\tconst [errors] = await Promise.all([Promise.all(this.#submissions), done])\n\t\t\tconst failure = errors.find((error) => error !== undefined)\n\t\t\tif (failure !== undefined) this.#options.fail(failure)\n\t\t\treturn failure\n\t\t} catch (cause) {\n\t\t\tconst failure = new WGSLError(\n\t\t\t\t`The device stopped before the batch finished: ${errorToMessage(cause)}`,\n\t\t\t\t{ code: 'HOST', cause },\n\t\t\t)\n\t\t\tthis.#options.fail(failure)\n\t\t\treturn failure\n\t\t}\n\t}\n\n\t// Settles a submitted batch: on success maps every read, and on failure rejects them.\n\tasync #finish(): Promise<WGSLError | undefined> {\n\t\tconst failure = await this.#drain()\n\t\tif (failure === undefined) {\n\t\t\tawait Promise.all(this.#reads.map((read) => this.#map(read)))\n\t\t\treturn undefined\n\t\t}\n\t\tfor (const [staging, , result] of this.#reads) {\n\t\t\tresult.reject(failure)\n\t\t\tthis.#options.restore(staging)\n\t\t}\n\t\treturn failure\n\t}\n\n\t// Settles an aborted batch after its earlier flushes finish, preferring their device failure.\n\tasync #discard(error: WGSLError): Promise<WGSLError> {\n\t\tconst failure = await this.#drain()\n\t\treturn failure ?? error\n\t}\n\n\t// Maps one staging buffer, resolves its read to a copy of the bytes, and returns the buffer to the pool.\n\tasync #map(read: WGSLRead): Promise<void> {\n\t\tconst [staging, size, result] = read\n\t\ttry {\n\t\t\tawait staging.mapAsync(WGSL_MAP.read, 0, size)\n\t\t\tresult.resolve(staging.getMappedRange(0, size).slice(0))\n\t\t\tstaging.unmap()\n\t\t} catch (cause) {\n\t\t\tconst error = new WGSLError(`The device could not map a read: ${errorToMessage(cause)}`, {\n\t\t\t\tcode: 'HOST',\n\t\t\t\tcause,\n\t\t\t})\n\t\t\tresult.reject(error)\n\t\t} finally {\n\t\t\tthis.#options.restore(staging)\n\t\t}\n\t}\n\n\t// Waits for the batch's settlement or the signal's abort, whichever comes first.\n\tasync #race(signal: AbortSignal): Promise<WGSLError | undefined> {\n\t\tconst cleanup = new AbortController()\n\t\tconst aborted = new Promise<WGSLError>((resolve) => {\n\t\t\tsignal.addEventListener(\n\t\t\t\t'abort',\n\t\t\t\t() => {\n\t\t\t\t\tthis.abort()\n\t\t\t\t\tconst error = new WGSLError('The signal aborted the batch while it ran.', {\n\t\t\t\t\t\tcode: 'ABORT',\n\t\t\t\t\t\tcause: signal.reason,\n\t\t\t\t\t})\n\t\t\t\t\tresolve(error)\n\t\t\t\t},\n\t\t\t\t{ once: true, signal: cleanup.signal },\n\t\t\t)\n\t\t})\n\t\ttry {\n\t\t\treturn await Promise.race([this.#result.promise, aborted])\n\t\t} finally {\n\t\t\tcleanup.abort()\n\t\t}\n\t}\n}\n","import type {\n\tWGSLFieldMap,\n\tWGSLSlabInterface,\n\tWGSLSlabOptions,\n\tWGSLStruct,\n\tWGSLValueMap,\n} from './types.js'\nimport { isSafeInteger, preview } from '@orkestrel/contract'\nimport { WGSL_USAGE } from './constants.js'\nimport { WGSLError } from './errors.js'\n\n/**\n * Packs each dispatch's uniform values into one host buffer at the device's uniform offset alignment and uploads them in one write.\n *\n * @remarks\n * The slab owns one `ArrayBuffer` with a `Uint32Array` view and a `Float32Array` view over it, and\n * steps a struct's frozen `members` for each write. An `f32` member writes through the float view,\n * so `-0` and subnormals keep their binary32 patterns; a `u32` or `i32` member writes through the\n * unsigned view, so `-5` stores `0xFFFFFFFB`. Each write starts at the next multiple of the\n * device's `minUniformBufferOffsetAlignment`. A write that meets a missing value zeroes the span it\n * started and throws, so the bytes past `used` stay zero. `clear` zeroes the bytes the written\n * values spanned.\n * The constructor throws with code `ARGUMENT` when `capacity` is not a positive safe multiple of 4\n * or passes the buffer's size, when the buffer lacks the `uniform` or `destination` usage, and when\n * the device reports an alignment that is not a positive safe multiple of 4.\n *\n * @example\n * ```ts\n * const slab = new WGSLSlab(device, { buffer, capacity: 65536 })\n * slab.write(createWGSLStruct('Shape', { rows: 'u32' }), { rows: 64 }) // 0\n * slab.upload()\n * ```\n */\nexport class WGSLSlab implements WGSLSlabInterface {\n\treadonly #device: GPUDevice\n\treadonly #buffer: GPUBuffer\n\treadonly #capacity: number\n\treadonly #alignment: number\n\treadonly #mask: number\n\treadonly #bytes: ArrayBuffer\n\treadonly #words: Uint32Array\n\treadonly #floats: Float32Array\n\t#used = 0\n\n\t/**\n\t * Creates an empty slab over a uniform buffer.\n\t *\n\t * @param device - The device whose queue receives the upload and whose limits set the alignment\n\t * @param options - The uniform buffer and the slab's byte capacity\n\t */\n\tconstructor(device: GPUDevice, options: WGSLSlabOptions) {\n\t\tconst { buffer, capacity } = options\n\t\tconst alignment = device.limits.minUniformBufferOffsetAlignment\n\t\tif (!isSafeInteger(capacity) || capacity < 4 || capacity % 4 !== 0) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`A slab capacity must be a positive safe multiple of 4 bytes; received ${preview(capacity)}.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { capacity } },\n\t\t\t)\n\t\t}\n\t\tif (\n\t\t\t(buffer.usage & WGSL_USAGE.uniform) === 0 ||\n\t\t\t(buffer.usage & WGSL_USAGE.destination) === 0\n\t\t) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`A slab buffer must carry the uniform and destination usages (WGSL_USAGE.uniform | WGSL_USAGE.destination); its usage is ${buffer.usage}.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { usage: buffer.usage } },\n\t\t\t)\n\t\t}\n\t\tif (capacity > buffer.size) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`A slab capacity of ${capacity} bytes passes its buffer's ${buffer.size} bytes.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { capacity, size: buffer.size } },\n\t\t\t)\n\t\t}\n\t\tif (!isSafeInteger(alignment) || alignment < 4 || alignment % 4 !== 0) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The device reports a minUniformBufferOffsetAlignment of ${preview(alignment)}; a slab needs a positive safe multiple of 4.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { alignment } },\n\t\t\t)\n\t\t}\n\t\tthis.#device = device\n\t\tthis.#buffer = buffer\n\t\tthis.#capacity = capacity\n\t\tthis.#alignment = alignment\n\t\tthis.#mask =\n\t\t\tcapacity <= 0x4000_0000 && alignment <= 0x4000_0000 && (alignment & (alignment - 1)) === 0\n\t\t\t\t? alignment - 1\n\t\t\t\t: -1\n\t\tthis.#bytes = new ArrayBuffer(capacity)\n\t\tthis.#words = new Uint32Array(this.#bytes)\n\t\tthis.#floats = new Float32Array(this.#bytes)\n\t}\n\n\tget capacity(): number {\n\t\treturn this.#capacity\n\t}\n\n\tget used(): number {\n\t\treturn this.#used\n\t}\n\n\twrite<F extends WGSLFieldMap>(\n\t\tstruct: WGSLStruct<F>,\n\t\tvalues: WGSLValueMap<F>,\n\t): number | undefined {\n\t\tconst offset =\n\t\t\tthis.#mask >= 0\n\t\t\t\t? (this.#used + this.#mask) & ~this.#mask\n\t\t\t\t: this.#used % this.#alignment === 0\n\t\t\t\t\t? this.#used\n\t\t\t\t\t: this.#used + (this.#alignment - (this.#used % this.#alignment))\n\t\tif (offset + struct.size > this.#capacity) {\n\t\t\tif (struct.size > this.#capacity) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The struct ${preview(struct.name)} takes ${struct.size} bytes, more than the slab's ${this.#capacity}; raise the uniform size.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: struct.name, size: struct.size } },\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn undefined\n\t\t}\n\t\tconst record: Readonly<Record<string, number>> = values\n\t\tconst base = this.#mask >= 0 ? offset >>> 2 : offset / 4\n\t\tconst { members } = struct\n\t\tconst first = members[0]\n\t\tif (members.length === 1 && first !== undefined) {\n\t\t\tconst value = record[first.name]\n\t\t\tif (typeof value !== 'number') {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The values for ${preview(struct.name)} carry no number for the field ${preview(first.name)}.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: struct.name, field: first.name } },\n\t\t\t\t)\n\t\t\t}\n\t\t\t// `typeof value === 'number'` preserves `-0` and `NaN` when assigned through the float view.\n\t\t\tif (first.element === 'f32') this.#floats[base + first.word] = value\n\t\t\telse this.#words[base + first.word] = value\n\t\t\tthis.#used = offset + struct.size\n\t\t\treturn offset\n\t\t}\n\t\tfor (const member of members) {\n\t\t\tconst value = record[member.name]\n\t\t\tif (typeof value !== 'number') {\n\t\t\t\tthis.#words.fill(0, base, base + struct.size / 4)\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The values for ${preview(struct.name)} carry no number for the field ${preview(member.name)}.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: struct.name, field: member.name } },\n\t\t\t\t)\n\t\t\t}\n\t\t\t// `typeof value === 'number'` preserves `-0` and `NaN` when assigned through the float view.\n\t\t\tif (member.element === 'f32') this.#floats[base + member.word] = value\n\t\t\telse this.#words[base + member.word] = value\n\t\t}\n\t\tthis.#used = offset + struct.size\n\t\treturn offset\n\t}\n\n\tupload(): void {\n\t\tif (this.#used === 0) return\n\t\tthis.#device.queue.writeBuffer(this.#buffer, 0, this.#bytes, 0, this.#used)\n\t}\n\n\tclear(): void {\n\t\tthis.#words.fill(0, 0, this.#used / 4)\n\t\tthis.#used = 0\n\t}\n}\n","import type {\n\tWGSLBinding,\n\tWGSLBindingNode,\n\tWGSLFieldMap,\n\tWGSLGrid,\n\tWGSLProgram,\n\tWGSLSessionInterface,\n\tWGSLSlot,\n\tWGSLSlotMap,\n\tWGSLStatementInterface,\n\tWGSLStatementOptions,\n\tWGSLValueMap,\n} from './types.js'\nimport { isNonNegativeInteger, isObject, isSafeInteger, preview } from '@orkestrel/contract'\nimport { WGSL_USAGE } from './constants.js'\nimport { WGSLError } from './errors.js'\n\n/**\n * Runs one prepared program on its session's device and caches a storage bind group per set of slot ranges.\n *\n * @remarks\n * `bind` walks a per-statement `WeakMap` trie keyed on each slot's buffer, byte offset, and byte\n * size, so a repeated range set returns the same `WGSLBinding` without allocating, and a destroyed\n * buffer's entries leave with the buffer. A range set the trie lacks is checked before its bind\n * group is created: thrown with code `ARGUMENT` when the slot names differ from the program's, when\n * a buffer lacks the `storage` usage, when an offset is not a multiple of the device's\n * `minStorageBufferOffsetAlignment`, when a size is under 4 bytes or not a multiple of 4, and when a\n * range passes its buffer's end; with code `LIMIT` when a size passes the device's\n * `maxStorageBufferBindingSize`; and with code `VALIDATION` when a `read_write` slot shares its\n * `GPUBuffer` with any other slot, even over disjoint ranges, because Dawn refuses that pair.\n * `execute` opens a batch on the session, records one dispatch, and resolves when the device\n * finishes it.\n *\n * @example\n * ```ts\n * const statement = await session.prepare(program)\n * const binding = statement.bind({ destination: { buffer } })\n * await statement.execute(binding, { count: 64 }, [1, 1, 1])\n * ```\n */\nexport class WGSLStatement<\n\tS extends WGSLSlotMap,\n\tF extends WGSLFieldMap,\n> implements WGSLStatementInterface<S, F> {\n\treadonly program: WGSLProgram<S, F>\n\treadonly pipeline: GPUComputePipeline\n\treadonly uniform: GPUBindGroup\n\treadonly #session: WGSLSessionInterface\n\treadonly #layout: GPUBindGroupLayout\n\treadonly #slots: ReadonlyArray<readonly [name: string, slot: WGSLSlot]>\n\treadonly #root: WGSLBindingNode<S, F>\n\n\t/**\n\t * Creates a statement over a pipeline its session prepared.\n\t *\n\t * @param session - The session whose device creates the bind groups and whose batches run the dispatches\n\t * @param options - The program, the pipeline, the storage layout, and the uniform bind group\n\t */\n\tconstructor(session: WGSLSessionInterface, options: WGSLStatementOptions<S, F>) {\n\t\tconst slots: WGSLSlotMap = options.program.slots\n\t\tthis.program = options.program\n\t\tthis.pipeline = options.pipeline\n\t\tthis.uniform = options.uniform\n\t\tthis.#session = session\n\t\tthis.#layout = options.layout\n\t\tthis.#slots = Object.freeze(Object.entries(slots))\n\t\tthis.#root = {\n\t\t\tnext: new WeakMap(),\n\t\t\tbinding: this.#slots.length === 0 ? this.#create([]) : undefined,\n\t\t}\n\t}\n\n\tbind(buffers: { readonly [K in keyof S]: GPUBufferBinding }): WGSLBinding<S, F> {\n\t\tconst record: Readonly<Record<string, GPUBufferBinding>> = buffers\n\t\tconst cached = this.#find(this.#root, record, 0)\n\t\tif (cached !== undefined) return cached\n\t\tconst entries = this.#resolve(record)\n\t\tconst binding = this.#create(entries)\n\t\tthis.#store(this.#root, entries, 0, binding)\n\t\treturn binding\n\t}\n\n\tasync execute(\n\t\tbinding: WGSLBinding<S, F>,\n\t\tvalues: WGSLValueMap<F>,\n\t\tgrid: WGSLGrid,\n\t\tsignal?: AbortSignal,\n\t): Promise<void> {\n\t\tconst batch = this.#session.batch()\n\t\ttry {\n\t\t\tbatch.encode(binding, values, grid)\n\t\t} catch (error) {\n\t\t\tbatch.abort()\n\t\t\tthrow error\n\t\t}\n\t\tawait batch.execute(signal)\n\t}\n\n\t// Walks the trie one slot per level and returns the cached binding, or `undefined` on a miss; it allocates nothing.\n\t#find(\n\t\tnode: WGSLBindingNode<S, F>,\n\t\trecord: Readonly<Record<string, GPUBufferBinding>>,\n\t\tdepth: number,\n\t): WGSLBinding<S, F> | undefined {\n\t\tconst entry = this.#slots[depth]\n\t\tif (entry === undefined) return node.binding\n\t\tconst binding = record[entry[0]]\n\t\tif (!isObject(binding)) return undefined\n\t\tconst offset = binding.offset ?? 0\n\t\tconst sizes = node.next.get(binding.buffer)?.get(offset)\n\t\tconst next = sizes?.get(binding.size ?? binding.buffer.size - offset)\n\t\treturn next === undefined ? undefined : this.#find(next, record, depth + 1)\n\t}\n\n\t// Checks a range set the trie lacks and returns each slot's range with its offset and size made explicit.\n\t#resolve(\n\t\trecord: Readonly<Record<string, GPUBufferBinding>>,\n\t): ReadonlyArray<Required<GPUBufferBinding>> {\n\t\tconst name = this.program.name\n\t\tconst names = this.#slots.map(([slot]) => slot)\n\t\tconst extra = Object.keys(record).filter((key) => !names.includes(key))\n\t\tconst missing = names.filter((slot) => !isObject(record[slot]))\n\t\tif (extra.length > 0 || missing.length > 0) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The program ${preview(name)} binds exactly the slots ${names.map(preview).join(', ') || 'none'}; give each one a buffer range and no other key.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { name, missing, extra } },\n\t\t\t)\n\t\t}\n\t\tconst limits = this.#session.device.limits\n\t\tconst entries = this.#slots.map(([slot]) => this.#range(slot, record[slot], limits))\n\t\tconst shared = names.filter((_slot, index) => this.#aliased(entries, index))\n\t\tif (shared.length > 0) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The read_write slots ${shared.map(preview).join(', ')} of ${preview(name)} share a GPUBuffer with another slot; Dawn refuses a writable binding beside any other binding of one buffer, even over disjoint ranges, so bind a separate buffer.`,\n\t\t\t\t{ code: 'VALIDATION', context: { name, slots: shared } },\n\t\t\t)\n\t\t}\n\t\treturn Object.freeze(entries)\n\t}\n\n\t// Checks whether slot `index` is read_write and another slot's range sits on the same buffer.\n\t#aliased(entries: ReadonlyArray<Required<GPUBufferBinding>>, index: number): boolean {\n\t\tif (this.#slots[index]?.[1].access !== 'read_write') return false\n\t\tconst buffer = entries[index]?.buffer\n\t\treturn entries.some((other, position) => position !== index && other.buffer === buffer)\n\t}\n\n\t// Checks one slot's range against its buffer and the device limits.\n\t#range(\n\t\tslot: string,\n\t\tbinding: GPUBufferBinding | undefined,\n\t\tlimits: GPUSupportedLimits,\n\t): Required<GPUBufferBinding> {\n\t\tconst name = this.program.name\n\t\tif (binding === undefined || !isObject(binding.buffer)) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The slot ${preview(slot)} of ${preview(name)} needs a buffer range object whose buffer member holds a GPUBuffer.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { name, slot } },\n\t\t\t)\n\t\t}\n\t\tconst { buffer } = binding\n\t\tif ((buffer.usage & WGSL_USAGE.storage) === 0) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The slot ${preview(slot)} of ${preview(name)} needs a buffer with the storage usage (WGSL_USAGE.storage); its usage is ${buffer.usage}.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { name, slot, usage: buffer.usage } },\n\t\t\t)\n\t\t}\n\t\tconst offset = binding.offset ?? 0\n\t\tconst alignment = limits.minStorageBufferOffsetAlignment\n\t\tif (!isNonNegativeInteger(offset) || !isSafeInteger(offset) || offset % alignment !== 0) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The slot ${preview(slot)} of ${preview(name)} starts at ${preview(offset)}; a storage offset must be a non-negative multiple of the device's ${alignment}-byte alignment.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { name, slot, offset, alignment } },\n\t\t\t)\n\t\t}\n\t\tconst size = binding.size ?? buffer.size - offset\n\t\tif (!isSafeInteger(size) || size < 4 || size % 4 !== 0) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The slot ${preview(slot)} of ${preview(name)} spans ${preview(size)} bytes; a storage range must span a multiple of 4 bytes, at least 4.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { name, slot, size } },\n\t\t\t)\n\t\t}\n\t\tif (offset + size > buffer.size) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The slot ${preview(slot)} of ${preview(name)} ends at byte ${offset + size}, past its buffer's ${buffer.size} bytes.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { name, slot, offset, size, length: buffer.size } },\n\t\t\t)\n\t\t}\n\t\tif (size > limits.maxStorageBufferBindingSize) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The slot ${preview(slot)} of ${preview(name)} spans ${size} bytes, past the device's maxStorageBufferBindingSize of ${limits.maxStorageBufferBindingSize}; split the range.`,\n\t\t\t\t{\n\t\t\t\t\tcode: 'LIMIT',\n\t\t\t\t\tcontext: { name, slot, size, limit: limits.maxStorageBufferBindingSize },\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t\treturn Object.freeze({ buffer, offset, size })\n\t}\n\n\t// Creates the storage bind group of one checked range set, one entry per slot in binding order.\n\t#create(entries: ReadonlyArray<Required<GPUBufferBinding>>): WGSLBinding<S, F> {\n\t\tconst group = this.#session.device.createBindGroup({\n\t\t\tlabel: this.program.name,\n\t\t\tlayout: this.#layout,\n\t\t\tentries: entries.map((resource, binding) => ({ binding, resource })),\n\t\t})\n\t\treturn Object.freeze({ statement: this, group })\n\t}\n\n\t// Adds the levels a new range set needs below `node`, ending at the node that holds `binding`.\n\t#store(\n\t\tnode: WGSLBindingNode<S, F>,\n\t\tentries: ReadonlyArray<Required<GPUBufferBinding>>,\n\t\tdepth: number,\n\t\tbinding: WGSLBinding<S, F>,\n\t): void {\n\t\tconst entry = entries[depth]\n\t\tif (entry === undefined) return\n\t\tconst offsets =\n\t\t\tnode.next.get(entry.buffer) ?? new Map<number, Map<number, WGSLBindingNode<S, F>>>()\n\t\tconst sizes = offsets.get(entry.offset) ?? new Map<number, WGSLBindingNode<S, F>>()\n\t\tconst leaf = depth === entries.length - 1 ? binding : undefined\n\t\tconst found = sizes.get(entry.size)\n\t\tconst child: WGSLBindingNode<S, F> = found ?? { next: new WeakMap(), binding: leaf }\n\t\tsizes.set(entry.size, child)\n\t\toffsets.set(entry.offset, sizes)\n\t\tnode.next.set(entry.buffer, offsets)\n\t\tthis.#store(child, entries, depth + 1, binding)\n\t}\n}\n","import type {\n\tWGSLAccess,\n\tWGSLBatchInterface,\n\tWGSLExtension,\n\tWGSLFieldMap,\n\tWGSLGrid,\n\tWGSLProgram,\n\tWGSLSessionInterface,\n\tWGSLSessionOptions,\n\tWGSLSessionStatus,\n\tWGSLSlotMap,\n\tWGSLStatementInterface,\n} from './types.js'\nimport { errorToMessage, isSafeInteger, preview } from '@orkestrel/contract'\nimport { WGSL_EXTENSIONS, WGSL_STAGE, WGSL_UNIFORM_SIZE, WGSL_USAGE } from './constants.js'\nimport { isWGSLError, WGSLError } from './errors.js'\nimport { renderWGSLProgram } from './helpers.js'\nimport { WGSLBatch } from './WGSLBatch.js'\nimport { WGSLSlab } from './WGSLSlab.js'\nimport { WGSLStatement } from './WGSLStatement.js'\n\n/**\n * Prepares programs as statements on a borrowed device and opens one batch of dispatches at a time.\n *\n * @remarks\n * The session reads its limits and features from the device and never requests or destroys the\n * device. An extension is active when the device reports its feature and the `extensions` option\n * does not switch it off. Pipelines sit in a table keyed on the rendered WGSL text: a ready map\n * beside a pending map, so a warm `prepare` creates no pipeline. A pending entry that fails with any\n * code but `COMPILE` leaves the table, so a later `prepare` retries it. Shader compilation runs\n * inside one synchronous push and pop of a `validation` error scope, and a compiler error rejects\n * that `prepare` with code `COMPILE` and its `line` and `column` in `context`; the session stays\n * `open`. Thrown with code `LIMIT` when a program's workgroup size or slot count passes the device's\n * limits, and with code `VALIDATION` from `batch()` while another batch is open. A device failure on\n * a submitted batch, or the device's `lost` promise, moves the session to `failed`, making\n * `prepare`, `batch`, and any open batch's `encode`, `read`, and `submit` throw that failure while\n * `destroy` resolves. `destroy` moves the session to `destroyed` at once, aborts the open batch,\n * waits for submitted work and reads, and destroys the uniform buffer and the staging buffers the\n * session created; a repeated `destroy` returns the same promise, settled `abort` and `execute`\n * replay their batch's own settlement, and `prepare`, `batch`, `encode`, `read`, and `submit` throw\n * with code `DESTROYED`. Thrown with code `ARGUMENT`\n * from the constructor when `uniform.size` is not a positive safe multiple of 4.\n *\n * @example\n * ```ts\n * const session = new WGSLSession(device, { extensions: { f16: false } })\n * const statement = await session.prepare(program)\n * await statement.execute(statement.bind({ destination: { buffer } }), { count: 64 }, [1, 1, 1])\n * await session.destroy()\n * ```\n */\nexport class WGSLSession implements WGSLSessionInterface {\n\treadonly #device: GPUDevice\n\treadonly #extensions: Readonly<Record<WGSLExtension, boolean>>\n\treadonly #buffer: GPUBuffer\n\treadonly #slab: WGSLSlab\n\treadonly #uniform: GPUBindGroupLayout\n\treadonly #ready = new Map<string, GPUComputePipeline>()\n\treadonly #pending = new Map<string, Promise<GPUComputePipeline>>()\n\treadonly #layouts = new Map<string, GPUBindGroupLayout>()\n\treadonly #groups = new Map<number, GPUBindGroup>()\n\treadonly #staging = new Set<GPUBuffer>()\n\treadonly #leased = new Set<GPUBuffer>()\n\treadonly #inflight = new Set<Promise<unknown>>()\n\t#batch: WGSLBatchInterface | undefined\n\t#failure: WGSLError | undefined\n\t#ending: Promise<void> | undefined\n\n\t/**\n\t * Creates an open session over a borrowed device, with its uniform slab and uniform layout.\n\t *\n\t * @param device - The device the session borrows\n\t * @param options - The extensions to switch off and the slab's byte size\n\t */\n\tconstructor(device: GPUDevice, options?: WGSLSessionOptions) {\n\t\tconst size = options?.uniform?.size ?? WGSL_UNIFORM_SIZE\n\t\tif (!isSafeInteger(size) || size < 4 || size % 4 !== 0) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`A session's uniform size must be a positive safe multiple of 4 bytes; received ${preview(size)}.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { size } },\n\t\t\t)\n\t\t}\n\t\tconst requested = options?.extensions\n\t\tconst features = device.features\n\t\tconst usage = WGSL_USAGE.uniform | WGSL_USAGE.destination\n\t\tconst entry: GPUBindGroupLayoutEntry = {\n\t\t\tbinding: 0,\n\t\t\tvisibility: WGSL_STAGE.compute,\n\t\t\tbuffer: { type: 'uniform', hasDynamicOffset: true },\n\t\t}\n\t\tthis.#device = device\n\t\tthis.#extensions = Object.freeze({\n\t\t\tf16: features.has(WGSL_EXTENSIONS.f16) && requested?.f16 !== false,\n\t\t\tsubgroups: features.has(WGSL_EXTENSIONS.subgroups) && requested?.subgroups !== false,\n\t\t})\n\t\tthis.#buffer = device.createBuffer({ label: 'wgsl uniform', size, usage })\n\t\tthis.#slab = new WGSLSlab(device, { buffer: this.#buffer, capacity: size })\n\t\tthis.#uniform = device.createBindGroupLayout({ label: 'wgsl uniform', entries: [entry] })\n\t\tdevice.lost.then((info) => this.#lose(info))\n\t}\n\n\tget device(): GPUDevice {\n\t\treturn this.#device\n\t}\n\n\tget extensions(): Readonly<Record<WGSLExtension, boolean>> {\n\t\treturn this.#extensions\n\t}\n\n\tget status(): WGSLSessionStatus {\n\t\tif (this.#ending !== undefined) return 'destroyed'\n\t\treturn this.#failure === undefined ? 'open' : 'failed'\n\t}\n\n\tasync prepare<S extends WGSLSlotMap, F extends WGSLFieldMap>(\n\t\tprogram: WGSLProgram<S, F>,\n\t): Promise<WGSLStatementInterface<S, F>> {\n\t\tthis.#check()\n\t\tconst { name, entry } = program\n\t\tconst slots: WGSLSlotMap = program.slots\n\t\tconst accesses = Object.values(slots).map((slot) => slot.access)\n\t\tthis.#fit(name, entry.size, accesses.length)\n\t\tconst text = renderWGSLProgram(program, this.#extensions)\n\t\tconst layout = this.#layout(accesses)\n\t\tconst ready = this.#ready.get(text)\n\t\tconst pipeline = ready ?? (await this.#compile(text, name, entry.name, layout))\n\t\tthis.#check()\n\t\tconst uniform = this.#group(program.uniform.struct.size)\n\t\treturn new WGSLStatement(this, { program, pipeline, layout, uniform })\n\t}\n\n\tbatch(): WGSLBatchInterface {\n\t\tthis.#check()\n\t\tif (this.#batch !== undefined) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t'The session already holds an open batch; submit or abort it before opening another.',\n\t\t\t\t{ code: 'VALIDATION' },\n\t\t\t)\n\t\t}\n\t\tconst batch = new WGSLBatch(this.#device, {\n\t\t\tslab: this.#slab,\n\t\t\tcheck: () => this.#check(),\n\t\t\tlease: (size) => this.#lease(size),\n\t\t\trestore: (buffer) => this.#restore(buffer),\n\t\t\trelease: (ended) => this.#release(ended),\n\t\t\tfail: (error) => this.#fail(error),\n\t\t\ttrack: (work) => this.#track(work),\n\t\t})\n\t\tthis.#batch = batch\n\t\treturn batch\n\t}\n\n\tdestroy(): Promise<void> {\n\t\tif (this.#ending !== undefined) return this.#ending\n\t\tconst ending = Promise.withResolvers<void>()\n\t\tthis.#ending = ending.promise\n\t\tending.resolve(this.#end())\n\t\treturn ending.promise\n\t}\n\n\t// Throws when the session is destroyed or failed.\n\t#check(): void {\n\t\tif (this.#ending !== undefined) {\n\t\t\tthrow new WGSLError('The session was destroyed; create another with createWGSLSession.', {\n\t\t\t\tcode: 'DESTROYED',\n\t\t\t})\n\t\t}\n\t\tif (this.#failure !== undefined) throw this.#failure\n\t}\n\n\t// Throws when a workgroup size or a slot count passes the device's limits.\n\t#fit(name: string, size: WGSLGrid, count: number): void {\n\t\tconst limits = this.#device.limits\n\t\tconst [x, y, z] = size\n\t\tconst wide = x > limits.maxComputeWorkgroupSizeX || y > limits.maxComputeWorkgroupSizeY\n\t\tconst deep = z > limits.maxComputeWorkgroupSizeZ\n\t\tif (wide || deep || x * y * z > limits.maxComputeInvocationsPerWorkgroup) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The program ${preview(name)} declares a workgroup of [${x}, ${y}, ${z}], past the device's per-axis workgroup sizes or its ${limits.maxComputeInvocationsPerWorkgroup} invocations per workgroup.`,\n\t\t\t\t{ code: 'LIMIT', context: { name, size: [x, y, z] } },\n\t\t\t)\n\t\t}\n\t\tif (count > limits.maxStorageBuffersPerShaderStage) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The program ${preview(name)} declares ${count} storage slots, past the device's ${limits.maxStorageBuffersPerShaderStage} storage buffers per shader stage.`,\n\t\t\t\t{ code: 'LIMIT', context: { name, count, limit: limits.maxStorageBuffersPerShaderStage } },\n\t\t\t)\n\t\t}\n\t}\n\n\t// Returns the storage bind-group layout of one slot access list, creating it once.\n\t#layout(accesses: readonly WGSLAccess[]): GPUBindGroupLayout {\n\t\tconst key = accesses.join(',')\n\t\tconst cached = this.#layouts.get(key)\n\t\tif (cached !== undefined) return cached\n\t\tconst entries = accesses.map((access, binding): GPUBindGroupLayoutEntry => ({\n\t\t\tbinding,\n\t\t\tvisibility: WGSL_STAGE.compute,\n\t\t\tbuffer: { type: access === 'read' ? 'read-only-storage' : 'storage' },\n\t\t}))\n\t\tconst layout = this.#device.createBindGroupLayout({ label: key, entries })\n\t\tthis.#layouts.set(key, layout)\n\t\treturn layout\n\t}\n\n\t// Returns the uniform bind group over the slab for one struct size, creating it once.\n\t#group(size: number): GPUBindGroup {\n\t\tconst cached = this.#groups.get(size)\n\t\tif (cached !== undefined) return cached\n\t\tconst resource: GPUBufferBinding = { buffer: this.#buffer, offset: 0, size }\n\t\tconst group = this.#device.createBindGroup({\n\t\t\tlabel: 'wgsl uniform',\n\t\t\tlayout: this.#uniform,\n\t\t\tentries: [{ binding: 0, resource }],\n\t\t})\n\t\tthis.#groups.set(size, group)\n\t\treturn group\n\t}\n\n\t// Returns the pending pipeline of one rendered text, or starts it; a failure other than COMPILE leaves the table.\n\t#compile(\n\t\ttext: string,\n\t\tname: string,\n\t\tentry: string,\n\t\tlayout: GPUBindGroupLayout,\n\t): Promise<GPUComputePipeline> {\n\t\tconst pending = this.#pending.get(text)\n\t\tif (pending !== undefined) return pending\n\t\tconst created = this.#build(text, name, entry, layout)\n\t\tthis.#pending.set(text, created)\n\t\tcreated.then(\n\t\t\t(pipeline) => {\n\t\t\t\tthis.#ready.set(text, pipeline)\n\t\t\t\tthis.#pending.delete(text)\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\tif (!isWGSLError(error) || error.code !== 'COMPILE') this.#pending.delete(text)\n\t\t\t},\n\t\t)\n\t\treturn created\n\t}\n\n\t// Compiles the text inside one synchronous error scope, then creates its pipeline.\n\tasync #build(\n\t\ttext: string,\n\t\tname: string,\n\t\tentry: string,\n\t\tlayout: GPUBindGroupLayout,\n\t): Promise<GPUComputePipeline> {\n\t\tconst device = this.#device\n\t\tconst groups = [layout, this.#uniform]\n\t\tdevice.pushErrorScope('validation')\n\t\tconst module = device.createShaderModule({ label: name, code: text })\n\t\tconst layouts = device.createPipelineLayout({ label: name, bindGroupLayouts: groups })\n\t\tconst popped = device.popErrorScope()\n\t\tconst [info, error] = await Promise.all([module.getCompilationInfo(), popped])\n\t\tconst message = info.messages.find((candidate) => candidate.type === 'error')\n\t\tif (message !== undefined) {\n\t\t\tconst { lineNum: line, linePos: column } = message\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The program ${preview(name)} does not compile at line ${line}, column ${column}: ${message.message}`,\n\t\t\t\t{ code: 'COMPILE', context: { name, line, column, message: message.message } },\n\t\t\t)\n\t\t}\n\t\tif (error !== null) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The device refused the shader module or pipeline layout of ${preview(name)}: ${error.message}`,\n\t\t\t\t{ code: 'VALIDATION', context: { name, message: error.message } },\n\t\t\t)\n\t\t}\n\t\treturn this.#pipeline(module, layouts, name, entry)\n\t}\n\n\t// Creates the compute pipeline and maps the device's refusal to code VALIDATION.\n\tasync #pipeline(\n\t\tmodule: GPUShaderModule,\n\t\tlayout: GPUPipelineLayout,\n\t\tname: string,\n\t\tentry: string,\n\t): Promise<GPUComputePipeline> {\n\t\ttry {\n\t\t\treturn await this.#device.createComputePipelineAsync({\n\t\t\t\tlabel: name,\n\t\t\t\tlayout,\n\t\t\t\tcompute: { module, entryPoint: entry },\n\t\t\t})\n\t\t} catch (cause) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The device refused the compute pipeline of ${preview(name)}: ${errorToMessage(cause)}`,\n\t\t\t\t{ code: 'VALIDATION', context: { name }, cause },\n\t\t\t)\n\t\t}\n\t}\n\n\t// Leases an idle staging buffer of at least `size` bytes, creating one when none fits.\n\t#lease(size: number): GPUBuffer {\n\t\tconst buffer = this.#idle(size) ?? this.#allocate(size)\n\t\tthis.#leased.add(buffer)\n\t\treturn buffer\n\t}\n\n\t// Returns an unleased, unmapped staging buffer of at least `size` bytes, or `undefined`.\n\t#idle(size: number): GPUBuffer | undefined {\n\t\tfor (const buffer of this.#staging) {\n\t\t\tif (this.#leased.has(buffer) || buffer.mapState !== 'unmapped') continue\n\t\t\tif (buffer.size >= size) return buffer\n\t\t}\n\t\treturn undefined\n\t}\n\n\t// Creates a staging buffer the session owns.\n\t#allocate(size: number): GPUBuffer {\n\t\tconst usage = WGSL_USAGE.read | WGSL_USAGE.destination\n\t\tconst buffer = this.#device.createBuffer({ label: 'wgsl staging', size, usage })\n\t\tthis.#staging.add(buffer)\n\t\treturn buffer\n\t}\n\n\t// Ends a staging buffer's lease.\n\t#restore(buffer: GPUBuffer): void {\n\t\tthis.#leased.delete(buffer)\n\t\tthis.#trim()\n\t}\n\n\t// Frees the open-batch slot when the ending batch holds it.\n\t#release(batch: WGSLBatchInterface): void {\n\t\tif (this.#batch === batch) this.#batch = undefined\n\t\tthis.#trim()\n\t}\n\n\t// Retires unleased staging buffers until the pool holds 2 while no batch is open.\n\t#trim(): void {\n\t\tif (this.#batch !== undefined) return\n\t\tconst idle = [...this.#staging].filter((buffer) => !this.#leased.has(buffer))\n\t\tconst excess = idle.slice(0, Math.max(0, this.#staging.size - 2))\n\t\tfor (const buffer of excess) {\n\t\t\tthis.#staging.delete(buffer)\n\t\t\tthis.#retire(buffer)\n\t\t}\n\t}\n\n\t// Destroys a retired buffer after the work submitted before it finishes.\n\t#retire(buffer: GPUBuffer): void {\n\t\tconst done = this.#device.queue.onSubmittedWorkDone()\n\t\tthis.#track(\n\t\t\tdone.then(\n\t\t\t\t() => buffer.destroy(),\n\t\t\t\t() => buffer.destroy(),\n\t\t\t),\n\t\t)\n\t}\n\n\t// Records the first device failure of a submitted batch as the session's terminal failure.\n\t#fail(error: WGSLError): void {\n\t\tthis.#failure ??= error\n\t}\n\n\t// Registers a settling promise that never rejects until it settles.\n\t#track(work: Promise<unknown>): void {\n\t\tthis.#inflight.add(work)\n\t\twork.then(\n\t\t\t() => this.#inflight.delete(work),\n\t\t\t() => this.#inflight.delete(work),\n\t\t)\n\t}\n\n\t// Records the device's loss as the session's terminal failure.\n\t#lose(info: GPUDeviceLostInfo): void {\n\t\tthis.#failure ??= new WGSLError(`The device was lost (${info.reason}): ${info.message}`, {\n\t\t\tcode: 'HOST',\n\t\t\tcontext: { reason: info.reason, message: info.message },\n\t\t})\n\t}\n\n\t// Aborts the open batch, waits for submitted work and reads, and destroys the session's buffers.\n\tasync #end(): Promise<void> {\n\t\tthis.#batch?.abort()\n\t\tawait Promise.allSettled(this.#inflight)\n\t\tfor (const buffer of this.#staging) buffer.destroy()\n\t\tthis.#buffer.destroy()\n\t\tthis.#staging.clear()\n\t\tthis.#leased.clear()\n\t\tthis.#ready.clear()\n\t\tthis.#pending.clear()\n\t\tthis.#layouts.clear()\n\t\tthis.#groups.clear()\n\t}\n}\n","import type {\n\tWGSLFieldMap,\n\tWGSLFragment,\n\tWGSLFragmentInput,\n\tWGSLGrid,\n\tWGSLProgram,\n\tWGSLProgramInput,\n\tWGSLSessionInterface,\n\tWGSLSessionOptions,\n\tWGSLSlotMap,\n\tWGSLStruct,\n} from './types.js'\nimport { isNonEmptyString, isRecord, isString, preview } from '@orkestrel/contract'\nimport { WGSLError } from './errors.js'\nimport { collectWGSLFragments } from './helpers.js'\nimport { isWGSLAccess, isWGSLExtension, isWGSLGrid, isWGSLScalar } from './validators.js'\nimport { WGSLSession } from './WGSLSession.js'\n\n/**\n * Creates a frozen uniform struct with its scalar layout and its rendered WGSL declaration.\n *\n * @remarks\n * Each `u32`, `i32`, and `f32` member aligns to 4 bytes and takes 4 bytes in the `uniform` address\n * space, so members sit in declaration order and the struct's size is the member count times 4.\n * Thrown with code `ARGUMENT` when `name` is empty, when `fields` is not a plain record or declares\n * no field, and when a field names a type outside `WGSL_SCALARS`; `context.fields` lists each such\n * field.\n *\n * @param name - The struct's WGSL name\n * @param fields - Each field's scalar type, in declaration order\n * @returns The struct, frozen\n *\n * @example\n * ```ts\n * createWGSLStruct('Shape', { rows: 'u32', epsilon: 'f32' }).offsets // { rows: 0, epsilon: 4 }\n * ```\n */\nexport function createWGSLStruct<F extends WGSLFieldMap>(name: string, fields: F): WGSLStruct<F>\nexport function createWGSLStruct(name: string, fields: WGSLFieldMap): WGSLStruct {\n\tif (!isNonEmptyString(name)) {\n\t\tthrow new WGSLError(`A struct name must be a non-empty string; received ${preview(name)}.`, {\n\t\t\tcode: 'ARGUMENT',\n\t\t\tcontext: { name },\n\t\t})\n\t}\n\tif (!isRecord(fields)) {\n\t\tthrow new WGSLError(\n\t\t\t`The struct ${preview(name)} needs a plain record of fields; received ${preview(fields)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t)\n\t}\n\tconst entries = Object.entries(fields)\n\tif (entries.length === 0) {\n\t\tthrow new WGSLError(\n\t\t\t`The struct ${preview(name)} declares no field; declare at least one 'u32', 'i32', or 'f32' field.`,\n\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t)\n\t}\n\tconst invalid = entries.filter(([, element]) => !isWGSLScalar(element)).map(([field]) => field)\n\tif (invalid.length > 0) {\n\t\tthrow new WGSLError(\n\t\t\t`The struct ${preview(name)} declares ${invalid.map(preview).join(', ')} with a type outside 'u32', 'i32', and 'f32'.`,\n\t\t\t{ code: 'ARGUMENT', context: { name, fields: invalid } },\n\t\t)\n\t}\n\tconst members = Object.freeze(\n\t\tentries.map(([field, element], word) => Object.freeze({ name: field, element, word })),\n\t)\n\tconst lines = members.map((member) => `\\t${member.name}: ${member.element},`)\n\treturn Object.freeze({\n\t\tname,\n\t\tfields: Object.freeze(Object.fromEntries(entries)),\n\t\tsize: members.length * 4,\n\t\toffsets: Object.freeze(\n\t\t\tObject.fromEntries(members.map((member) => [member.name, member.word * 4])),\n\t\t),\n\t\tmembers,\n\t\tsource: `struct ${name} {\\n${lines.join('\\n')}\\n}`,\n\t})\n}\n\n/**\n * Creates a frozen fragment from author-written WGSL text and the fragments it uses.\n *\n * @remarks\n * The text reaches the compiler unchanged. Thrown with code `ARGUMENT` when the name is empty, when\n * a source is not a string, and when the variant names an extension outside `WGSL_EXTENSIONS`.\n *\n * @param input - The fragment's name, text, used fragments, and optional variant\n * @returns The fragment, frozen\n *\n * @example\n * ```ts\n * createWGSLFragment({ name: 'square', source: 'fn square(value: f32) -> f32 { return value * value; }' }).uses // []\n * ```\n */\nexport function createWGSLFragment(input: WGSLFragmentInput): WGSLFragment {\n\tif (!isNonEmptyString(input.name)) {\n\t\tthrow new WGSLError(\n\t\t\t`A fragment name must be a non-empty string; received ${preview(input.name)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t)\n\t}\n\tif (!isString(input.source)) {\n\t\tthrow new WGSLError(\n\t\t\t`The fragment ${preview(input.name)} needs WGSL text in source; received ${preview(input.source)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t)\n\t}\n\tconst uses = Object.freeze([...(input.uses ?? [])])\n\tconst variant = input.variant\n\tif (variant === undefined) return Object.freeze({ name: input.name, source: input.source, uses })\n\tif (!isWGSLExtension(variant.extension)) {\n\t\tthrow new WGSLError(\n\t\t\t`The fragment ${preview(input.name)} names the extension ${preview(variant.extension)}; use 'f16' or 'subgroups'.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t)\n\t}\n\tif (!isString(variant.source)) {\n\t\tthrow new WGSLError(\n\t\t\t`The fragment ${preview(input.name)} needs WGSL text in variant.source; received ${preview(variant.source)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t)\n\t}\n\treturn Object.freeze({\n\t\tname: input.name,\n\t\tsource: input.source,\n\t\tuses,\n\t\tvariant: Object.freeze({ extension: variant.extension, source: variant.source }),\n\t})\n}\n\n/**\n * Creates a frozen compute program and links every fragment its entry body reaches.\n *\n * @remarks\n * The slots keep their declaration order, which is their binding order. Thrown with code\n * `ARGUMENT` when a name is empty, when the entry size is not three positive safe integers, when the\n * entry source is not a string, and when a slot names an access outside `WGSL_ACCESSES` or an\n * element outside `WGSL_SCALARS`; `context.slots` lists each such slot. Thrown with code\n * `VALIDATION` when the linker finds two distinct fragments of one name or a cycle.\n *\n * @param input - The program's name, entry, slots, uniform, and used fragments\n * @returns The program, frozen\n *\n * @example\n * ```ts\n * createWGSLProgram({ name: 'clear', entry, slots, uniform }).fragments // []\n * ```\n */\nexport function createWGSLProgram<S extends WGSLSlotMap, F extends WGSLFieldMap>(\n\tinput: WGSLProgramInput<S, F>,\n): WGSLProgram<S, F>\nexport function createWGSLProgram(input: WGSLProgramInput<WGSLSlotMap, WGSLFieldMap>): WGSLProgram {\n\tconst { entry, uniform } = input\n\tif (!isNonEmptyString(input.name)) {\n\t\tthrow new WGSLError(\n\t\t\t`A program name must be a non-empty string; received ${preview(input.name)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t)\n\t}\n\tif (!isNonEmptyString(entry.name)) {\n\t\tthrow new WGSLError(\n\t\t\t`The program ${preview(input.name)} needs a non-empty entry name; received ${preview(entry.name)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t)\n\t}\n\tif (!isWGSLGrid(entry.size)) {\n\t\tthrow new WGSLError(\n\t\t\t`The entry ${preview(entry.name)} needs a workgroup size of three positive safe integers, such as [64, 1, 1].`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name, size: entry.size } },\n\t\t)\n\t}\n\tif (!isString(entry.source)) {\n\t\tthrow new WGSLError(\n\t\t\t`The entry ${preview(entry.name)} needs WGSL text in source; received ${preview(entry.source)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t)\n\t}\n\tconst slots = Object.entries(input.slots)\n\tconst invalid = slots\n\t\t.filter(([, slot]) => !isWGSLAccess(slot.access) || !isWGSLScalar(slot.element))\n\t\t.map(([name]) => name)\n\tif (invalid.length > 0) {\n\t\tthrow new WGSLError(\n\t\t\t`The program ${preview(input.name)} declares slots ${invalid.map(preview).join(', ')} with an access outside 'read' and 'read_write' or an element outside 'u32', 'i32', and 'f32'.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name, slots: invalid } },\n\t\t)\n\t}\n\tif (!isNonEmptyString(uniform.name)) {\n\t\tthrow new WGSLError(\n\t\t\t`The program ${preview(input.name)} needs a non-empty uniform name; received ${preview(uniform.name)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t)\n\t}\n\tconst [x, y, z] = entry.size\n\tconst size: WGSLGrid = [x, y, z]\n\treturn Object.freeze({\n\t\tname: input.name,\n\t\tentry: Object.freeze({ name: entry.name, size: Object.freeze(size), source: entry.source }),\n\t\tslots: Object.freeze(\n\t\t\tObject.fromEntries(\n\t\t\t\tslots.map(([name, slot]) => [\n\t\t\t\t\tname,\n\t\t\t\t\tObject.freeze({ access: slot.access, element: slot.element }),\n\t\t\t\t]),\n\t\t\t),\n\t\t),\n\t\tuniform: Object.freeze({ name: uniform.name, struct: uniform.struct }),\n\t\tfragments: collectWGSLFragments(input.uses ?? []),\n\t})\n}\n\n/**\n * Creates an open session that prepares programs and runs batches on a borrowed device.\n *\n * @remarks\n * The session never requests or destroys the device; its `destroy` releases only the buffers it\n * created. Thrown with code `ARGUMENT` when `uniform.size` is not a positive safe multiple of 4.\n *\n * @param device - The device the session borrows\n * @param options - The extensions to switch off and the uniform slab's byte size\n * @returns The session\n *\n * @example\n * ```ts\n * const session = createWGSLSession(device, { extensions: { f16: false } })\n * session.status // 'open'\n * ```\n */\nexport function createWGSLSession(\n\tdevice: GPUDevice,\n\toptions?: WGSLSessionOptions,\n): WGSLSessionInterface {\n\treturn new WGSLSession(device, options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,IAAa,mBAAmB,OAAO,OAAO;CAC7C;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAU;;;;;;;;;;;;;AAcV,IAAa,mBAAkC,OAAO,IAAI,2BAA2B;;;;;;;;;;;;AAarF,IAAa,eAAe,OAAO,OAAO;CAAC;CAAO;CAAO;AAAK,CAAU;;;;;;;;;;;;AAaxE,IAAa,gBAAgB,OAAO,OAAO,CAAC,QAAQ,YAAY,CAAU;;;;;;;;;;;;;;AAe1E,IAAa,kBAAkB,OAAO,OAAO;CAAE,KAAK;CAAc,WAAW;AAAY,CAAU;;;;;;;;;;;;;;;AAgBnG,IAAa,aAAa,OAAO,OAAO;CACvC,MAAM;CACN,OAAO;CACP,QAAQ;CACR,aAAa;CACb,SAAS;CACT,SAAS;CACT,UAAU;CACV,OAAO;AACR,CAAU;;;;;;;;;;;;AAaV,IAAa,WAAW,OAAO,OAAO;CAAE,MAAM;CAAQ,OAAO;AAAO,CAAU;;;;;;;;;;;;AAa9E,IAAa,aAAa,OAAO,OAAO,EAAE,SAAS,EAAO,CAAU;;;;;;;;;;;;;AAcpE,IAAa,oBAAoB;;;;;;;;;;;;;;;;AAiBjC,IAAa,aAA2B,OAAO,OAAO;CACrD,MAAM;CACN,QAAQ;EACP;EACA;EACA;CACD,CAAC,CAAC,KAAK,IAAI;CACX,MAAM,OAAO,OAAO,CAAC,CAAC;AACvB,CAAC;;;;;;;;;;;;;;;;;;AAmBD,IAAa,WAAyB,OAAO,OAAO;CACnD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAC,CAAC,KAAK,IAAI;CACX,MAAM,OAAO,OAAO,CAAC,CAAC;CACtB,SAAS,OAAO,OAAO;EACtB,WAAW;EACX,QAAQ;GACP;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACD,CAAC,CAAC,KAAK,IAAI;CACZ,CAAC;AACF,CAAC;;;;;;;;;;;;;;;;;;;AAoBD,IAAa,YAA0B,OAAO,OAAO;CACpD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAC,CAAC,KAAK,IAAI;CACX,MAAM,OAAO,OAAO,CAAC,CAAC;CACtB,SAAS,OAAO,OAAO;EACtB,WAAW;EACX,QAAQ;GACP;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACD,CAAC,CAAC,KAAK,IAAI;CACZ,CAAC;AACF,CAAC;;;;;;;;;;;;;;;;;AAkBD,IAAa,YAA0B,OAAO,OAAO;CACpD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAC,CAAC,KAAK,IAAI;CACX,MAAM,OAAO,OAAO,CAAC,CAAC;AACvB,CAAC;;;;;;;;;;;;;;;;AC9TD,IAAa,YAAb,cAA+B,MAAM;CAClB,OAAO;CAChB;CACA;;;;;;;CAQT,YAAY,SAAiB,SAA2B;EACvD,MAAM,SAA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