@orkestrel/wgsl 0.0.2 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -0
- package/dist/src/core/index.cjs +10055 -1336
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +3297 -458
- package/dist/src/core/index.d.ts +3297 -458
- package/dist/src/core/index.js +9964 -1338
- package/dist/src/core/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"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,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I,CAAC,iBAAiB,QAAQ,IAAI,GACjC,MAAM,IAAI,UACT,eAAe,QAAQ,MAAM,IAAI,EAAE,4CAA4C,QAAQ,QAAQ,IAAI,EAAE,IACrG;EAAE,MAAM;EAAY,SAAS,EAAE,MAAM,MAAM,KAAK;CAAE,CACnD;CAED,MAAM,CAAC,GAAG,GAAG,KAAK,MAAM;CACxB,MAAM,OAAiB;EAAC;EAAG;EAAG;CAAC;CAC/B,OAAO,OAAO,OAAO;EACpB,MAAM,MAAM;EACZ,OAAO,OAAO,OAAO;GAAE,MAAM,MAAM;GAAM,MAAM,OAAO,OAAO,IAAI;GAAG,QAAQ,MAAM;EAAO,CAAC;EAC1F,OAAO,OAAO,OACb,OAAO,YACN,MAAM,KAAK,CAAC,MAAM,UAAU,CAC3B,MACA,OAAO,OAAO;GAAE,QAAQ,KAAK;GAAQ,SAAS,KAAK;EAAQ,CAAC,CAC7D,CAAC,CACF,CACD;EACA,SAAS,OAAO,OAAO;GAAE,MAAM,QAAQ;GAAM,QAAQ,QAAQ;EAAO,CAAC;EACrE,WAAW,qBAAqB,MAAM,QAAQ,CAAC,CAAC;CACjD,CAAC;AACF;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,kBACf,QACA,SACuB;CACvB,OAAO,IAAI,YAAY,QAAQ,OAAO;AACvC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"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, WGSLReduceElement, WGSLScalar, WGSLStorageElement } 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 element types a storage slot array can hold.\n *\n * @remarks\n * Covers 32-bit and 16-bit scalars, 2-lane and 4-lane vectors whose WGSL alignment matches their\n * byte stride, and 32-bit atomic integers. Three-lane vectors are excluded because their 16-byte\n * alignment pads 12-byte values in storage arrays. `WGSLStorageElement` derives from this list.\n *\n * @example\n * ```ts\n * WGSL_STORAGE_ELEMENTS.includes('vec4f') // true\n * ```\n */\nexport const WGSL_STORAGE_ELEMENTS = Object.freeze([\n\t'u32',\n\t'i32',\n\t'f32',\n\t'f16',\n\t'vec2u',\n\t'vec2i',\n\t'vec2f',\n\t'vec2h',\n\t'vec4u',\n\t'vec4i',\n\t'vec4f',\n\t'vec4h',\n\t'atomic<u32>',\n\t'atomic<i32>',\n] as const)\n\n/**\n * Maps each storage slot element type to its WGSL array stride in bytes.\n *\n * @remarks\n * Every key matches a member of `WGSL_STORAGE_ELEMENTS`, and each stride equals the element's\n * host-shareable size and alignment in the `storage` address space.\n *\n * @example\n * ```ts\n * WGSL_STORAGE_STRIDES.vec4f // 16\n * ```\n */\nexport const WGSL_STORAGE_STRIDES: Readonly<Record<WGSLStorageElement, number>> = Object.freeze({\n\tu32: 4,\n\ti32: 4,\n\tf32: 4,\n\tf16: 2,\n\tvec2u: 8,\n\tvec2i: 8,\n\tvec2f: 8,\n\tvec2h: 4,\n\tvec4u: 16,\n\tvec4i: 16,\n\tvec4f: 16,\n\tvec4h: 8,\n\t'atomic<u32>': 4,\n\t'atomic<i32>': 4,\n})\n\n/**\n * Lists the scalar types a pipeline-overridable constant can declare.\n *\n * @remarks\n * Mirrors the W3C WGSL `override` scalar types (`bool`, `u32`, `i32`, and `f32`).\n * `WGSLOverrideScalar` derives from this list.\n *\n * @example\n * ```ts\n * WGSL_OVERRIDE_SCALARS.includes('bool') // true\n * ```\n */\nexport const WGSL_OVERRIDE_SCALARS = Object.freeze(['bool', '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 * Lists the roles a rendered program section can hold, in the order a rendered program emits them.\n *\n * @remarks\n * `requires` marks language-extension directives, `enable` marks extension directives, `override`\n * marks pipeline-overridable constant declarations, `struct` marks the uniform `struct`\n * declaration, `dispatch` marks the `Dispatch` entry input struct, `invocation` marks the\n * `Invocation` entry input struct, `bindings` marks the `@group`/`@binding` lines, `fragment`\n * marks one linked fragment's body, and `entry` marks the compute entry point. A `WGSLSection`\n * carries one of these roles so a compiler message maps back to the section whose text produced\n * it.\n *\n * @example\n * ```ts\n * WGSL_SECTION_ROLES.includes('fragment') // true\n * ```\n */\nexport const WGSL_SECTION_ROLES = Object.freeze([\n\t'requires',\n\t'enable',\n\t'override',\n\t'struct',\n\t'dispatch',\n\t'invocation',\n\t'bindings',\n\t'fragment',\n\t'entry',\n] 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 * Lists the WGSL language extensions a fragment variant can require.\n *\n * @remarks\n * Each member mirrors the W3C WGSL `requires` directive name and the corresponding entry in\n * `navigator.gpu.wgslLanguageFeatures`. Order matches the order in which a rendered program emits\n * its `requires` directives. `WGSLLanguage` derives from this list.\n *\n * @example\n * ```ts\n * WGSL_LANGUAGES.includes('subgroup_id') // true\n * ```\n */\nexport const WGSL_LANGUAGES = Object.freeze([\n\t'packed_4x8_integer_dot_product',\n\t'subgroup_id',\n] 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 * Lists the modes a session's tracer runs in.\n *\n * @remarks\n * `off` records nothing, `pass` records each compute pass the batch would open anyway, and\n * `statement` ends the compute pass after every dispatch so each pass's GPU time belongs to one\n * program. `WGSLTraceMode` derives from this list.\n *\n * @example\n * ```ts\n * WGSL_TRACE_MODES.includes('pass') // true\n * ```\n */\nexport const WGSL_TRACE_MODES = Object.freeze(['off', 'pass', 'statement'] as const)\n\n/**\n * Lists the causes that can end a recorded compute pass in a batch trace.\n *\n * @remarks\n * `WGSLTraceCause` derives from this list.\n *\n * @example\n * ```ts\n * WGSL_TRACE_CAUSES.includes('write') // true\n * ```\n */\nexport const WGSL_TRACE_CAUSES = Object.freeze([\n\t'copy',\n\t'clear',\n\t'write',\n\t'read',\n\t'flush',\n\t'statement',\n\t'submit',\n] as const)\n\n/**\n * Holds the default number of compute passes a traced batch records.\n *\n * @remarks\n * The session's `trace.capacity` option replaces it, from 1 to 2048. Each pass takes 2 entries of\n * the session's timestamp query set, and each pass past the capacity counts in\n * `WGSLTraceRecord.dropped`.\n *\n * @example\n * ```ts\n * WGSL_TRACE_CAPACITY // 512\n * ```\n */\nexport const WGSL_TRACE_CAPACITY = 512\n\n/**\n * Holds the fragment that reads a workgroup's two-axis index from the entry's `Dispatch` struct.\n *\n * @remarks\n * It declares `fn readPlace(dispatch: Dispatch) -> u32`, which returns\n * `dispatch.workgroup_id.x + dispatch.workgroup_id.y * dispatch.num_workgroups.x`, the statement of\n * `@orkestrel/infer`'s `readPlace`. `Dispatch` holds only values that stay uniform across a\n * workgroup, so a call that returns early on the result stays in uniform control flow before a\n * later `workgroupBarrier()`. `Invocation` holds the per-lane builtins and is not a parameter. Pair\n * the fragment with `computeWGSLGrid`, and multiply by the workgroup size and add\n * `invocation.local_invocation_index` for an invocation's index. It reads no binding and no uniform\n * 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: 'readPlace',\n\tsource: [\n\t\t'fn readPlace(dispatch: Dispatch) -> u32 {',\n\t\t'\\treturn dispatch.workgroup_id.x + dispatch.workgroup_id.y * dispatch.num_workgroups.x;',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: 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> sumShared: array<f32, 64>`, 256 bytes, and\n * `fn sumPartials(invocation: Invocation, value: f32) -> f32`, which returns the workgroup's total\n * to every invocation. The entry's workgroup size must hold 64 invocations, and every invocation\n * must call it from uniform control flow. It takes `Invocation` and never `Dispatch`, because it\n * reads only `local_invocation_index` and, in the variant, `subgroup_invocation_id`. The default\n * 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 folds the 64 entries with four accumulators in strides of 4\n * between 2 barriers; the variant is `reordered`, so its rounding order differs from the default\n * body's. Programs taking `(invocation, dispatch)` parameters can adopt\n * `createWGSLReduce({ workgroup: 64, operation: 'sum', element: 'f32', reordered: true })` for\n * strided `64 / subgroup_size` folds, while `WGSL_SUM` remains frozen on the `(invocation, value)`\n * signature for sealed digests. It reads no binding and no uniform member.\n *\n * @example\n * ```ts\n * WGSL_SUM.variants[0]?.extensions // ['subgroups']\n * ```\n */\nexport const WGSL_SUM: WGSLFragment = Object.freeze({\n\tname: 'sumPartials',\n\tsource: [\n\t\t'var<workgroup> sumShared: array<f32, 64>;',\n\t\t'',\n\t\t'fn sumPartials(invocation: Invocation, value: f32) -> f32 {',\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tsumShared[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\\tsumShared[local] = sumShared[local] + sumShared[local + stride];',\n\t\t'\\t\\t}',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t'\\t}',\n\t\t'\\tlet total = sumShared[0];',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn total;',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([\n\t\tObject.freeze({\n\t\t\textensions: Object.freeze(['subgroups'] as const),\n\t\t\tsource: [\n\t\t\t\t'var<workgroup> sumShared: array<f32, 64>;',\n\t\t\t\t'',\n\t\t\t\t'fn sumPartials(invocation: Invocation, value: f32) -> f32 {',\n\t\t\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t\t\t'\\tlet partial = subgroupAdd(value);',\n\t\t\t\t'\\tsumShared[local] = select(0.0, partial, invocation.subgroup_invocation_id == 0u);',\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t'\\tif (local == 0u) {',\n\t\t\t\t'\\t\\tvar a0 = 0.0;',\n\t\t\t\t'\\t\\tvar a1 = 0.0;',\n\t\t\t\t'\\t\\tvar a2 = 0.0;',\n\t\t\t\t'\\t\\tvar a3 = 0.0;',\n\t\t\t\t'\\t\\tfor (var i = 0u; i < 64u; i += 4u) {',\n\t\t\t\t'\\t\\t\\ta0 = a0 + sumShared[i];',\n\t\t\t\t'\\t\\t\\ta1 = a1 + sumShared[i + 1u];',\n\t\t\t\t'\\t\\t\\ta2 = a2 + sumShared[i + 2u];',\n\t\t\t\t'\\t\\t\\ta3 = a3 + sumShared[i + 3u];',\n\t\t\t\t'\\t\\t}',\n\t\t\t\t'\\t\\tsumShared[0] = (a0 + a1) + (a2 + a3);',\n\t\t\t\t'\\t}',\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t'\\tlet total = sumShared[0];',\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t'\\treturn total;',\n\t\t\t\t'}',\n\t\t\t].join('\\n'),\n\t\t}),\n\t]),\n\tworkgroup: 64,\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> peakShared: array<f32, 64>`, 256 bytes, and\n * `fn peakPartials(invocation: Invocation, value: f32) -> f32`, which returns the workgroup's\n * maximum to every invocation. The entry's workgroup size must hold 64 invocations, and every\n * invocation must call it from uniform control flow. It takes `Invocation` and never `Dispatch`. The\n * default body reduces with `max` in a tree of halving strides. The `subgroups` variant is\n * `reordered`: it stores each subgroup's `subgroupMax` partial at its first invocation's index and\n * the lowest finite `f32` (`-3.4028234663852886e38`) elsewhere, and invocation 0 folds the 64 entries\n * with `max` across four accumulators in strides of 4 between 2 barriers (matching `@orkestrel/infer`,\n * so it returns `-3.4028234663852886e38` rather than `-Infinity` when every input is `-Infinity`).\n * Programs taking `(invocation, dispatch)` parameters can adopt\n * `createWGSLReduce({ workgroup: 64, operation: 'max', element: 'f32', reordered: true })` for\n * strided `64 / subgroup_size` folds, while `WGSL_PEAK` remains frozen on the `(invocation, value)`\n * signature for sealed digests. It reads no binding and no uniform member.\n *\n * @example\n * ```ts\n * WGSL_PEAK.variants[0]?.extensions // ['subgroups']\n * ```\n */\nexport const WGSL_PEAK: WGSLFragment = Object.freeze({\n\tname: 'peakPartials',\n\tsource: [\n\t\t'var<workgroup> peakShared: array<f32, 64>;',\n\t\t'',\n\t\t'fn peakPartials(invocation: Invocation, value: f32) -> f32 {',\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tpeakShared[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\\tpeakShared[local] = max(peakShared[local], peakShared[local + stride]);',\n\t\t'\\t\\t}',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t'\\t}',\n\t\t'\\tlet largest = peakShared[0];',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn largest;',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([\n\t\tObject.freeze({\n\t\t\textensions: Object.freeze(['subgroups'] as const),\n\t\t\tsource: [\n\t\t\t\t'var<workgroup> peakShared: array<f32, 64>;',\n\t\t\t\t'',\n\t\t\t\t'fn peakPartials(invocation: Invocation, value: f32) -> f32 {',\n\t\t\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t\t\t'\\tlet partial = subgroupMax(value);',\n\t\t\t\t'\\tpeakShared[local] = select(-3.4028234663852886e38, partial, invocation.subgroup_invocation_id == 0u);',\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t'\\tif (local == 0u) {',\n\t\t\t\t'\\t\\tvar a0 = -3.4028234663852886e38;',\n\t\t\t\t'\\t\\tvar a1 = -3.4028234663852886e38;',\n\t\t\t\t'\\t\\tvar a2 = -3.4028234663852886e38;',\n\t\t\t\t'\\t\\tvar a3 = -3.4028234663852886e38;',\n\t\t\t\t'\\t\\tfor (var i = 0u; i < 64u; i += 4u) {',\n\t\t\t\t'\\t\\t\\ta0 = max(a0, peakShared[i]);',\n\t\t\t\t'\\t\\t\\ta1 = max(a1, peakShared[i + 1u]);',\n\t\t\t\t'\\t\\t\\ta2 = max(a2, peakShared[i + 2u]);',\n\t\t\t\t'\\t\\t\\ta3 = max(a3, peakShared[i + 3u]);',\n\t\t\t\t'\\t\\t}',\n\t\t\t\t'\\t\\tpeakShared[0] = max(max(a0, a1), max(a2, a3));',\n\t\t\t\t'\\t}',\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t'\\tlet largest = peakShared[0];',\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t'\\treturn largest;',\n\t\t\t\t'}',\n\t\t\t].join('\\n'),\n\t\t}),\n\t]),\n\tworkgroup: 64,\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 widenHalf(bits: u32) -> f32`, which takes neither `Invocation` nor `Dispatch`\n * and 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 // 'widenHalf'\n * ```\n */\nexport const WGSL_HALF: WGSLFragment = Object.freeze({\n\tname: 'widenHalf',\n\tsource: [\n\t\t'fn widenHalf(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\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment that reads, writes, and takes dot products of bytes, nibbles, and halves packed in a `u32` word.\n *\n * @remarks\n * Declares `signByte`, `readWordByte`, `readWordHalf`, `unpackSignedBytes`, `packSignedBytes`,\n * `unpackSignedNibbles`, `unpackUnsignedNibbles`, `packNibbles`, `dotSignedBytes`, and\n * `dotUnsignedBytes`. The `packed_4x8_integer_dot_product` variant delegates `dotSignedBytes` and\n * `dotUnsignedBytes` to `dot4I8Packed` and `dot4U8Packed` with bit-identical (`exact`) results.\n * `unpackWGSLBytes` and `packWGSLBytes` are its TypeScript twins.\n *\n * @example\n * ```ts\n * WGSL_BYTES.name // 'bytes'\n * ```\n */\nexport const WGSL_BYTES: WGSLFragment = Object.freeze({\n\tname: 'bytes',\n\tsource: [\n\t\t'fn signByte(value: u32) -> i32 {',\n\t\t'\\treturn bitcast<i32>(value << 24u) >> 24u;',\n\t\t'}',\n\t\t'',\n\t\t'fn readWordByte(word: u32, lane: u32) -> u32 {',\n\t\t'\\treturn (word >> ((lane & 3u) * 8u)) & 0xffu;',\n\t\t'}',\n\t\t'',\n\t\t'fn readWordHalf(word: u32, lane: u32) -> u32 {',\n\t\t'\\treturn (word >> ((lane & 1u) * 16u)) & 0xffffu;',\n\t\t'}',\n\t\t'',\n\t\t'fn unpackSignedBytes(word: u32) -> vec4i {',\n\t\t'\\tlet spread = vec4u(word << 24u, word << 16u, word << 8u, word);',\n\t\t'\\treturn bitcast<vec4i>(spread) >> vec4u(24u);',\n\t\t'}',\n\t\t'',\n\t\t'fn packSignedBytes(quad: vec4i) -> u32 {',\n\t\t'\\tlet masked = bitcast<vec4u>(quad) & vec4u(0xffu);',\n\t\t'\\treturn masked.x | (masked.y << 8u) | (masked.z << 16u) | (masked.w << 24u);',\n\t\t'}',\n\t\t'',\n\t\t'fn unpackSignedNibbles(word: u32) -> vec4i {',\n\t\t'\\tlet spread = vec4u(word << 28u, word << 24u, word << 20u, word << 16u);',\n\t\t'\\treturn bitcast<vec4i>(spread) >> vec4u(28u);',\n\t\t'}',\n\t\t'',\n\t\t'fn unpackUnsignedNibbles(word: u32) -> vec4u {',\n\t\t'\\treturn vec4u(word, word >> 4u, word >> 8u, word >> 12u) & vec4u(0xfu);',\n\t\t'}',\n\t\t'',\n\t\t'fn packNibbles(quad: vec4u) -> u32 {',\n\t\t'\\tlet masked = quad & vec4u(0xfu);',\n\t\t'\\treturn masked.x | (masked.y << 4u) | (masked.z << 8u) | (masked.w << 12u);',\n\t\t'}',\n\t\t'',\n\t\t'fn dotSignedBytes(left: u32, right: u32) -> i32 {',\n\t\t'\\tlet a = unpackSignedBytes(left);',\n\t\t'\\tlet b = unpackSignedBytes(right);',\n\t\t'\\treturn a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;',\n\t\t'}',\n\t\t'',\n\t\t'fn dotUnsignedBytes(left: u32, right: u32) -> u32 {',\n\t\t'\\tlet a = vec4u(left & 0xffu, (left >> 8u) & 0xffu, (left >> 16u) & 0xffu, left >> 24u);',\n\t\t'\\tlet b = vec4u(right & 0xffu, (right >> 8u) & 0xffu, (right >> 16u) & 0xffu, right >> 24u);',\n\t\t'\\treturn a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([\n\t\tObject.freeze({\n\t\t\tlanguages: Object.freeze(['packed_4x8_integer_dot_product'] as const),\n\t\t\tsource: [\n\t\t\t\t'fn signByte(value: u32) -> i32 {',\n\t\t\t\t'\\treturn bitcast<i32>(value << 24u) >> 24u;',\n\t\t\t\t'}',\n\t\t\t\t'',\n\t\t\t\t'fn readWordByte(word: u32, lane: u32) -> u32 {',\n\t\t\t\t'\\treturn (word >> ((lane & 3u) * 8u)) & 0xffu;',\n\t\t\t\t'}',\n\t\t\t\t'',\n\t\t\t\t'fn readWordHalf(word: u32, lane: u32) -> u32 {',\n\t\t\t\t'\\treturn (word >> ((lane & 1u) * 16u)) & 0xffffu;',\n\t\t\t\t'}',\n\t\t\t\t'',\n\t\t\t\t'fn unpackSignedBytes(word: u32) -> vec4i {',\n\t\t\t\t'\\tlet spread = vec4u(word << 24u, word << 16u, word << 8u, word);',\n\t\t\t\t'\\treturn bitcast<vec4i>(spread) >> vec4u(24u);',\n\t\t\t\t'}',\n\t\t\t\t'',\n\t\t\t\t'fn packSignedBytes(quad: vec4i) -> u32 {',\n\t\t\t\t'\\tlet masked = bitcast<vec4u>(quad) & vec4u(0xffu);',\n\t\t\t\t'\\treturn masked.x | (masked.y << 8u) | (masked.z << 16u) | (masked.w << 24u);',\n\t\t\t\t'}',\n\t\t\t\t'',\n\t\t\t\t'fn unpackSignedNibbles(word: u32) -> vec4i {',\n\t\t\t\t'\\tlet spread = vec4u(word << 28u, word << 24u, word << 20u, word << 16u);',\n\t\t\t\t'\\treturn bitcast<vec4i>(spread) >> vec4u(28u);',\n\t\t\t\t'}',\n\t\t\t\t'',\n\t\t\t\t'fn unpackUnsignedNibbles(word: u32) -> vec4u {',\n\t\t\t\t'\\treturn vec4u(word, word >> 4u, word >> 8u, word >> 12u) & vec4u(0xfu);',\n\t\t\t\t'}',\n\t\t\t\t'',\n\t\t\t\t'fn packNibbles(quad: vec4u) -> u32 {',\n\t\t\t\t'\\tlet masked = quad & vec4u(0xfu);',\n\t\t\t\t'\\treturn masked.x | (masked.y << 4u) | (masked.z << 8u) | (masked.w << 12u);',\n\t\t\t\t'}',\n\t\t\t\t'',\n\t\t\t\t'fn dotSignedBytes(left: u32, right: u32) -> i32 {',\n\t\t\t\t'\\treturn dot4I8Packed(left, right);',\n\t\t\t\t'}',\n\t\t\t\t'',\n\t\t\t\t'fn dotUnsignedBytes(left: u32, right: u32) -> u32 {',\n\t\t\t\t'\\treturn dot4U8Packed(left, right);',\n\t\t\t\t'}',\n\t\t\t].join('\\n'),\n\t\t}),\n\t]),\n})\n\n/**\n * Holds the fragment that widens and narrows scalar and packed-pair bfloat16 values in `u32` words.\n *\n * @remarks\n * Declares `widenBFloat`, `narrowBFloat`, `widenBFloatPair`, and `narrowBFloatPair`. All bodies use\n * integer bit operations on `bitcast` words so subnormals, signed zeros, infinities, and quiet NaNs\n * stay exact. `widenWGSLBFloat` and `narrowWGSLBFloat` are its TypeScript twins.\n *\n * @example\n * ```ts\n * WGSL_BFLOAT.name // 'bfloat'\n * ```\n */\nexport const WGSL_BFLOAT: WGSLFragment = Object.freeze({\n\tname: 'bfloat',\n\tsource: [\n\t\t'fn widenBFloat(bits: u32) -> f32 {',\n\t\t'\\treturn bitcast<f32>(bits << 16u);',\n\t\t'}',\n\t\t'',\n\t\t'fn narrowBFloat(value: f32) -> u32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tif ((bits & 0x7fffffffu) > 0x7f800000u) {',\n\t\t'\\t\\treturn (bits >> 16u) | 0x0040u;',\n\t\t'\\t}',\n\t\t'\\treturn (bits + 0x7fffu + ((bits >> 16u) & 1u)) >> 16u;',\n\t\t'}',\n\t\t'',\n\t\t'fn widenBFloatPair(word: u32) -> vec2f {',\n\t\t'\\treturn vec2f(bitcast<f32>(word << 16u), bitcast<f32>(word & 0xffff0000u));',\n\t\t'}',\n\t\t'',\n\t\t'fn narrowBFloatPair(values: vec2f) -> u32 {',\n\t\t'\\treturn narrowBFloat(values.x) | (narrowBFloat(values.y) << 16u);',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment that narrows an `f32` to half-precision bits, clamps scalar and quad half ranges, and classifies `f32` bit patterns.\n *\n * @remarks\n * Declares `narrowHalf`, `clampHalf`, `clampHalfQuad`, `isFiniteFloat`, and `isNaNFloat`. Every body\n * uses integer bit operations so NaN patterns and subnormals are preserved. `narrowWGSLHalf` is the\n * TypeScript twin of `narrowHalf`.\n *\n * @example\n * ```ts\n * WGSL_FLOAT.name // 'float'\n * ```\n */\nexport const WGSL_FLOAT: WGSLFragment = Object.freeze({\n\tname: 'float',\n\tsource: [\n\t\t'fn narrowHalf(value: f32) -> u32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet negative = (bits >> 16u) & 0x8000u;',\n\t\t'\\tlet magnitude = bits & 0x7fffffffu;',\n\t\t'\\tif (magnitude > 0x7f800000u) {',\n\t\t'\\t\\treturn negative | 0x7e00u | ((magnitude >> 13u) & 0x3ffu);',\n\t\t'\\t}',\n\t\t'\\tif (magnitude >= 0x477ff000u) {',\n\t\t'\\t\\treturn negative | 0x7c00u;',\n\t\t'\\t}',\n\t\t'\\tif (magnitude >= 0x38800000u) {',\n\t\t'\\t\\treturn negative | ((magnitude + 0xfffu + ((magnitude >> 13u) & 1u) - 0x38000000u) >> 13u);',\n\t\t'\\t}',\n\t\t'\\tif (magnitude <= 0x33000000u) {',\n\t\t'\\t\\treturn negative;',\n\t\t'\\t}',\n\t\t'\\tlet shift = 126u - (magnitude >> 23u);',\n\t\t'\\tlet mantissa = (magnitude & 0x7fffffu) | 0x800000u;',\n\t\t'\\tlet kept = mantissa >> shift;',\n\t\t'\\tlet rest = mantissa & ((1u << shift) - 1u);',\n\t\t'\\tlet midpoint = 1u << (shift - 1u);',\n\t\t'\\tlet up = rest > midpoint || (rest == midpoint && (kept & 1u) == 1u);',\n\t\t'\\treturn negative | (kept + select(0u, 1u, up));',\n\t\t'}',\n\t\t'',\n\t\t'fn clampHalf(value: f32) -> f32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet magnitude = bits & 0x7fffffffu;',\n\t\t'\\tif (magnitude > 0x477fe000u && magnitude <= 0x7f800000u) {',\n\t\t'\\t\\treturn bitcast<f32>((bits & 0x80000000u) | 0x477fe000u);',\n\t\t'\\t}',\n\t\t'\\treturn value;',\n\t\t'}',\n\t\t'',\n\t\t'fn clampHalfQuad(value: vec4f) -> vec4f {',\n\t\t'\\tlet bits = bitcast<vec4u>(value);',\n\t\t'\\tlet magnitude = bits & vec4u(0x7fffffffu);',\n\t\t'\\tlet over = (magnitude > vec4u(0x477fe000u)) & (magnitude <= vec4u(0x7f800000u));',\n\t\t'\\tlet clamped = (bits & vec4u(0x80000000u)) | vec4u(0x477fe000u);',\n\t\t'\\treturn bitcast<vec4f>(select(bits, clamped, over));',\n\t\t'}',\n\t\t'',\n\t\t'fn isFiniteFloat(value: f32) -> bool {',\n\t\t'\\treturn (bitcast<u32>(value) & 0x7f800000u) != 0x7f800000u;',\n\t\t'}',\n\t\t'',\n\t\t'fn isNaNFloat(value: f32) -> bool {',\n\t\t'\\treturn (bitcast<u32>(value) & 0x7fffffffu) > 0x7f800000u;',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment of numerically stable scalar elementary helpers and streaming log-sum-exp and Euclidean norm monoids.\n *\n * @remarks\n * Declares `OnlineExp` (`emptyOnlineExp`, `pushOnlineExp`, `mergeOnlineExp`), `OnlineNorm`\n * (`emptyOnlineNorm`, `pushOnlineNorm`, `mergeOnlineNorm`, `finishOnlineNorm`), and the pure scalar\n * helpers `computeLogOnePlus`, `computeExpMinusOne`, `computeHypot`, `computeLogAddExp`,\n * `computeLogOneMinusExp`, `computeSigmoid`, and `computeSoftplus`.\n *\n * @example\n * ```ts\n * WGSL_MATH.name // 'math'\n * ```\n */\nexport const WGSL_MATH: WGSLFragment = Object.freeze({\n\tname: 'math',\n\tsource: [\n\t\t'struct OnlineExp {',\n\t\t'\\tpeak: f32,',\n\t\t'\\tmass: f32,',\n\t\t'}',\n\t\t'',\n\t\t'struct OnlineNorm {',\n\t\t'\\tscale: f32,',\n\t\t'\\tsumSq: f32,',\n\t\t'}',\n\t\t'',\n\t\t'fn computeLogOnePlus(value: f32) -> f32 {',\n\t\t'\\tlet sum = 1.0 + value;',\n\t\t'\\tif (sum == 1.0) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tif (sum == value) {',\n\t\t'\\t\\treturn log(sum);',\n\t\t'\\t}',\n\t\t'\\treturn log(sum) * (value / (sum - 1.0));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeExpMinusOne(value: f32) -> f32 {',\n\t\t'\\tif (abs(value) < 0.5) {',\n\t\t'\\t\\treturn value * (1.0 + value * (0.5 + value * (0.16666667 + value * (0.041666668 + value * (0.008333334 + value * (0.0013888889 + value * (0.0001984127 + value * 0.000024801587)))))));',\n\t\t'\\t}',\n\t\t'\\treturn exp(value) - 1.0;',\n\t\t'}',\n\t\t'',\n\t\t'fn computeHypot(left: f32, right: f32) -> f32 {',\n\t\t'\\tlet a = abs(left);',\n\t\t'\\tlet b = abs(right);',\n\t\t'\\tif (bitcast<u32>(a) == 0x7f800000u) {',\n\t\t'\\t\\treturn a;',\n\t\t'\\t}',\n\t\t'\\tif (bitcast<u32>(b) == 0x7f800000u) {',\n\t\t'\\t\\treturn b;',\n\t\t'\\t}',\n\t\t'\\tif (bitcast<u32>(a) > 0x7f800000u || bitcast<u32>(b) > 0x7f800000u) {',\n\t\t'\\t\\treturn left + right;',\n\t\t'\\t}',\n\t\t'\\tlet hi = max(a, b);',\n\t\t'\\tlet lo = min(a, b);',\n\t\t'\\tif (hi == 0.0) {',\n\t\t'\\t\\treturn 0.0;',\n\t\t'\\t}',\n\t\t'\\tlet ratio = lo / hi;',\n\t\t'\\treturn hi * sqrt(1.0 + ratio * ratio);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeLogAddExp(left: f32, right: f32) -> f32 {',\n\t\t'\\tlet leftBits = bitcast<u32>(left);',\n\t\t'\\tlet rightBits = bitcast<u32>(right);',\n\t\t'\\tif ((leftBits & 0x7fffffffu) > 0x7f800000u || (rightBits & 0x7fffffffu) > 0x7f800000u) {',\n\t\t'\\t\\treturn left + right;',\n\t\t'\\t}',\n\t\t'\\tif (leftBits == 0x7f800000u) {',\n\t\t'\\t\\treturn left;',\n\t\t'\\t}',\n\t\t'\\tif (rightBits == 0x7f800000u) {',\n\t\t'\\t\\treturn right;',\n\t\t'\\t}',\n\t\t'\\tif (leftBits == 0xff800000u) {',\n\t\t'\\t\\treturn right;',\n\t\t'\\t}',\n\t\t'\\tif (rightBits == 0xff800000u) {',\n\t\t'\\t\\treturn left;',\n\t\t'\\t}',\n\t\t'\\tlet hi = max(left, right);',\n\t\t'\\tlet lo = min(left, right);',\n\t\t'\\treturn hi + computeLogOnePlus(exp(lo - hi));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeLogOneMinusExp(value: f32) -> f32 {',\n\t\t'\\tif (bitcast<u32>(value) == 0xff800000u) {',\n\t\t'\\t\\treturn 0.0;',\n\t\t'\\t}',\n\t\t'\\tif (value > -0.69314718) {',\n\t\t'\\t\\treturn log(-computeExpMinusOne(value));',\n\t\t'\\t}',\n\t\t'\\treturn computeLogOnePlus(-exp(value));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSigmoid(value: f32) -> f32 {',\n\t\t'\\tlet decay = exp(-abs(value));',\n\t\t'\\treturn select(decay, 1.0, value >= 0.0) / (1.0 + decay);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSoftplus(value: f32) -> f32 {',\n\t\t'\\tif (value > 20.0) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\treturn computeLogOnePlus(exp(value));',\n\t\t'}',\n\t\t'',\n\t\t'fn emptyOnlineExp() -> OnlineExp {',\n\t\t'\\treturn OnlineExp(-3.4028234663852886e38, 0.0);',\n\t\t'}',\n\t\t'',\n\t\t'fn pushOnlineExp(state: OnlineExp, value: f32) -> OnlineExp {',\n\t\t'\\tif (bitcast<u32>(value) == 0xff800000u) {',\n\t\t'\\t\\treturn state;',\n\t\t'\\t}',\n\t\t'\\tif (state.mass <= 0.0) {',\n\t\t'\\t\\treturn OnlineExp(value, 1.0);',\n\t\t'\\t}',\n\t\t'\\tlet peak = max(state.peak, value);',\n\t\t'\\tlet decay = exp(-abs(state.peak - value));',\n\t\t'\\tlet mass = select(state.mass + decay, state.mass * decay + 1.0, value > state.peak);',\n\t\t'\\treturn OnlineExp(peak, mass);',\n\t\t'}',\n\t\t'',\n\t\t'fn mergeOnlineExp(left: OnlineExp, right: OnlineExp) -> OnlineExp {',\n\t\t'\\tif (left.mass <= 0.0) {',\n\t\t'\\t\\treturn right;',\n\t\t'\\t}',\n\t\t'\\tif (right.mass <= 0.0) {',\n\t\t'\\t\\treturn left;',\n\t\t'\\t}',\n\t\t'\\tlet peak = max(left.peak, right.peak);',\n\t\t'\\tlet decay = exp(-abs(left.peak - right.peak));',\n\t\t'\\tlet mass = select(left.mass + right.mass * decay, left.mass * decay + right.mass, right.peak > left.peak);',\n\t\t'\\treturn OnlineExp(peak, mass);',\n\t\t'}',\n\t\t'',\n\t\t'fn emptyOnlineNorm() -> OnlineNorm {',\n\t\t'\\treturn OnlineNorm(0.0, 0.0);',\n\t\t'}',\n\t\t'',\n\t\t'fn pushOnlineNorm(state: OnlineNorm, value: f32) -> OnlineNorm {',\n\t\t'\\tlet mag = abs(value);',\n\t\t'\\tif (mag == 0.0) {',\n\t\t'\\t\\treturn state;',\n\t\t'\\t}',\n\t\t'\\tif (state.scale == 0.0) {',\n\t\t'\\t\\treturn OnlineNorm(mag, 1.0);',\n\t\t'\\t}',\n\t\t'\\tif (bitcast<u32>(state.scale) == 0x7f800000u) {',\n\t\t'\\t\\treturn state;',\n\t\t'\\t}',\n\t\t'\\tif (bitcast<u32>(mag) == 0x7f800000u) {',\n\t\t'\\t\\treturn OnlineNorm(mag, 1.0);',\n\t\t'\\t}',\n\t\t'\\tif (mag > state.scale) {',\n\t\t'\\t\\tlet ratio = state.scale / mag;',\n\t\t'\\t\\treturn OnlineNorm(mag, 1.0 + state.sumSq * (ratio * ratio));',\n\t\t'\\t}',\n\t\t'\\tlet ratio = mag / state.scale;',\n\t\t'\\treturn OnlineNorm(state.scale, state.sumSq + ratio * ratio);',\n\t\t'}',\n\t\t'',\n\t\t'fn mergeOnlineNorm(left: OnlineNorm, right: OnlineNorm) -> OnlineNorm {',\n\t\t'\\tif (left.scale == 0.0) {',\n\t\t'\\t\\treturn right;',\n\t\t'\\t}',\n\t\t'\\tif (right.scale == 0.0) {',\n\t\t'\\t\\treturn left;',\n\t\t'\\t}',\n\t\t'\\tif (bitcast<u32>(left.scale) == 0x7f800000u) {',\n\t\t'\\t\\treturn OnlineNorm(left.scale, 1.0);',\n\t\t'\\t}',\n\t\t'\\tif (bitcast<u32>(right.scale) == 0x7f800000u) {',\n\t\t'\\t\\treturn OnlineNorm(right.scale, 1.0);',\n\t\t'\\t}',\n\t\t'\\tif (right.scale > left.scale) {',\n\t\t'\\t\\tlet ratio = left.scale / right.scale;',\n\t\t'\\t\\treturn OnlineNorm(right.scale, right.sumSq + left.sumSq * (ratio * ratio));',\n\t\t'\\t}',\n\t\t'\\tlet ratio = right.scale / left.scale;',\n\t\t'\\treturn OnlineNorm(left.scale, left.sumSq + right.sumSq * (ratio * ratio));',\n\t\t'}',\n\t\t'',\n\t\t'fn finishOnlineNorm(state: OnlineNorm) -> f32 {',\n\t\t'\\treturn state.scale * sqrt(state.sumSq);',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment that votes a `bool` across the invocations of a 64-invocation workgroup.\n *\n * @remarks\n * The default body declares an 8-byte `JoinSlot { vote: atomic<u32>, flag: u32 }` in `joinShared`\n * and runs 4 barriers (2D-safe, avoiding `workgroupUniformLoad` on an atomic). The `subgroups`\n * `linear: true` variant declares a 68-byte `JoinSlot { partials: array<u32, 16>, flag: u32 }` and\n * runs 3 barriers with `exact` parity. Both end with `workgroupUniformLoad(&joinShared.flag) != 0u`,\n * so callers may branch and return early before a later barrier.\n *\n * @example\n * ```ts\n * WGSL_JOIN.workgroup // 64\n * ```\n */\nexport const WGSL_JOIN: WGSLFragment = Object.freeze({\n\tname: 'joinFlags',\n\tsource: [\n\t\t'struct JoinSlot {',\n\t\t'\\tvote: atomic<u32>,',\n\t\t'\\tflag: u32,',\n\t\t'}',\n\t\t'',\n\t\t'var<workgroup> joinShared: JoinSlot;',\n\t\t'',\n\t\t'fn joinAny(invocation: Invocation, value: bool) -> bool {',\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tif (local == 0u) {',\n\t\t'\\t\\tatomicStore(&joinShared.vote, 0u);',\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tif (value) {',\n\t\t'\\t\\tatomicOr(&joinShared.vote, 1u);',\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tif (local == 0u) {',\n\t\t'\\t\\tjoinShared.flag = atomicLoad(&joinShared.vote);',\n\t\t'\\t}',\n\t\t'\\treturn workgroupUniformLoad(&joinShared.flag) != 0u;',\n\t\t'}',\n\t\t'',\n\t\t'fn joinAll(invocation: Invocation, value: bool) -> bool {',\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tif (local == 0u) {',\n\t\t'\\t\\tatomicStore(&joinShared.vote, 1u);',\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tif (!value) {',\n\t\t'\\t\\tatomicAnd(&joinShared.vote, 0u);',\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tif (local == 0u) {',\n\t\t'\\t\\tjoinShared.flag = atomicLoad(&joinShared.vote);',\n\t\t'\\t}',\n\t\t'\\treturn workgroupUniformLoad(&joinShared.flag) != 0u;',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([\n\t\tObject.freeze({\n\t\t\textensions: Object.freeze(['subgroups'] as const),\n\t\t\tlinear: true,\n\t\t\tsource: [\n\t\t\t\t'struct JoinSlot {',\n\t\t\t\t'\\tpartials: array<u32, 16>,',\n\t\t\t\t'\\tflag: u32,',\n\t\t\t\t'}',\n\t\t\t\t'',\n\t\t\t\t'var<workgroup> joinShared: JoinSlot;',\n\t\t\t\t'',\n\t\t\t\t'fn joinAny(invocation: Invocation, value: bool) -> bool {',\n\t\t\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t\t\t'\\tlet partial = subgroupAny(value);',\n\t\t\t\t'\\tif ((local & 3u) == 0u) {',\n\t\t\t\t'\\t\\tjoinShared.partials[local >> 2u] = select(0u, select(0u, 1u, partial), invocation.subgroup_invocation_id == 0u);',\n\t\t\t\t'\\t}',\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t'\\tif (local == 0u) {',\n\t\t\t\t'\\t\\tvar acc = 0u;',\n\t\t\t\t'\\t\\tfor (var i = 0u; i < 16u; i += 1u) {',\n\t\t\t\t'\\t\\t\\tacc = acc | joinShared.partials[i];',\n\t\t\t\t'\\t\\t}',\n\t\t\t\t'\\t\\tjoinShared.flag = acc;',\n\t\t\t\t'\\t}',\n\t\t\t\t'\\treturn workgroupUniformLoad(&joinShared.flag) != 0u;',\n\t\t\t\t'}',\n\t\t\t\t'',\n\t\t\t\t'fn joinAll(invocation: Invocation, value: bool) -> bool {',\n\t\t\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t\t\t'\\tlet partial = subgroupAll(value);',\n\t\t\t\t'\\tif ((local & 3u) == 0u) {',\n\t\t\t\t'\\t\\tjoinShared.partials[local >> 2u] = select(1u, select(0u, 1u, partial), invocation.subgroup_invocation_id == 0u);',\n\t\t\t\t'\\t}',\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t'\\tif (local == 0u) {',\n\t\t\t\t'\\t\\tvar acc = 1u;',\n\t\t\t\t'\\t\\tfor (var i = 0u; i < 16u; i += 1u) {',\n\t\t\t\t'\\t\\t\\tacc = acc & joinShared.partials[i];',\n\t\t\t\t'\\t\\t}',\n\t\t\t\t'\\t\\tjoinShared.flag = acc;',\n\t\t\t\t'\\t}',\n\t\t\t\t'\\treturn workgroupUniformLoad(&joinShared.flag) != 0u;',\n\t\t\t\t'}',\n\t\t\t].join('\\n'),\n\t\t}),\n\t]),\n\tworkgroup: 64,\n})\n\n/**\n * Lists the combining operations supported by `createWGSLReduce` and `createWGSLScan`.\n *\n * @remarks\n * `and`, `or`, and `xor` operate bit-wise on `u32` and `i32` values and are refused for\n * floating-point elements. `WGSLReduceOperation` derives from this list.\n *\n * @example\n * ```ts\n * WGSL_REDUCE_OPERATIONS.includes('sum') // true\n * ```\n */\nexport const WGSL_REDUCE_OPERATIONS = Object.freeze([\n\t'sum',\n\t'max',\n\t'min',\n\t'and',\n\t'or',\n\t'xor',\n\t'mul',\n] as const)\n\n/**\n * Lists the element types supported by `createWGSLReduce`.\n *\n * @remarks\n * `WGSLReduceElement` derives from this list.\n *\n * @example\n * ```ts\n * WGSL_REDUCE_ELEMENTS.includes('vec4f') // true\n * ```\n */\nexport const WGSL_REDUCE_ELEMENTS = Object.freeze(['u32', 'i32', 'f32', 'vec2f', 'vec4f'] as const)\n\n/**\n * Lists the partition widths supported by `createWGSLReduce`, `createWGSLMonoidReduce`, `createWGSLSort`, and `createWGSLPairSort`.\n *\n * @remarks\n * `WGSLReduceWidth` derives from this list. A chosen width must not exceed the fragment's\n * workgroup invocation count.\n *\n * @example\n * ```ts\n * WGSL_REDUCE_WIDTHS.includes(32) // true\n * ```\n */\nexport const WGSL_REDUCE_WIDTHS = Object.freeze([16, 32, 64, 128, 256] as const)\n\n/**\n * Lists the bin counts supported by `createWGSLHistogram`.\n *\n * @remarks\n * `WGSLHistogramSize` derives from this list.\n *\n * @example\n * ```ts\n * WGSL_HISTOGRAM_SIZES.includes(64) // true\n * ```\n */\nexport const WGSL_HISTOGRAM_SIZES = Object.freeze([16, 32, 64, 128, 256] as const)\n\n/**\n * Lists the sort directions supported by `createWGSLSort` and `createWGSLPairSort`.\n *\n * @remarks\n * `WGSLSortOrder` derives from this list.\n *\n * @example\n * ```ts\n * WGSL_SORT_ORDERS.includes('ascending') // true\n * ```\n */\nexport const WGSL_SORT_ORDERS = Object.freeze(['ascending', 'descending'] as const)\n\n/**\n * Lists the online monoid states supported by `createWGSLMonoidReduce`.\n *\n * @remarks\n * `'exp'` reduces `OnlineExp` from `WGSL_MATH`, `'moments'` reduces `OnlineMoments` from\n * `WGSL_WELFORD`, and `'compensated'` reduces `CompensatedSum` from `WGSL_COMPENSATED`.\n * `WGSLMonoid` derives from this list.\n *\n * @example\n * ```ts\n * WGSL_MONOIDS.includes('exp') // true\n * ```\n */\nexport const WGSL_MONOIDS = Object.freeze(['exp', 'moments', 'compensated'] as const)\n\n/**\n * Lists the workgroup invocation counts supported by collective fragment factories.\n *\n * @example\n * ```ts\n * WGSL_WORKGROUPS.includes(64) // true\n * ```\n */\nexport const WGSL_WORKGROUPS = Object.freeze([64, 128, 256] as const)\n\n/**\n * Lists the square tile dimensions supported by `createWGSLTranspose`.\n *\n * @example\n * ```ts\n * WGSL_TILE_SIZES.includes(16) // true\n * ```\n */\nexport const WGSL_TILE_SIZES = Object.freeze([16, 32] as const)\n\n/**\n * Lists the extrema selecting operations supported by `createWGSLArgReduce`.\n *\n * @example\n * ```ts\n * WGSL_ARG_REDUCE_OPERATIONS.includes('max') // true\n * ```\n */\nexport const WGSL_ARG_REDUCE_OPERATIONS = Object.freeze(['max', 'min'] as const)\n\n/**\n * Maps each reduction or scan operation and element type to its finite WGSL identity literal.\n *\n * @remarks\n * `max` and `min` on floating-point elements use finite IEEE-754 extremes\n * (`±3.4028234663852886e38`), used for exclusive scan seeding and caller lane masking.\n *\n * @example\n * ```ts\n * WGSL_REDUCE_IDENTITIES.sum.f32 // '0.0'\n * ```\n */\nexport const WGSL_REDUCE_IDENTITIES: Readonly<{\n\treadonly sum: Readonly<Record<WGSLReduceElement, string>>\n\treadonly max: Readonly<Record<WGSLReduceElement, string>>\n\treadonly min: Readonly<Record<WGSLReduceElement, string>>\n\treadonly and: Readonly<Record<Exclude<WGSLScalar, 'f32'>, string>>\n\treadonly or: Readonly<Record<Exclude<WGSLScalar, 'f32'>, string>>\n\treadonly xor: Readonly<Record<Exclude<WGSLScalar, 'f32'>, string>>\n\treadonly mul: Readonly<Record<WGSLReduceElement, string>>\n}> = Object.freeze({\n\tsum: Object.freeze({\n\t\tf32: '0.0',\n\t\tu32: '0u',\n\t\ti32: '0i',\n\t\tvec2f: 'vec2f(0.0)',\n\t\tvec4f: 'vec4f(0.0)',\n\t}),\n\tmax: Object.freeze({\n\t\tf32: '-3.4028234663852886e38',\n\t\tu32: '0u',\n\t\ti32: 'bitcast<i32>(0x80000000u)',\n\t\tvec2f: 'vec2f(-3.4028234663852886e38)',\n\t\tvec4f: 'vec4f(-3.4028234663852886e38)',\n\t}),\n\tmin: Object.freeze({\n\t\tf32: '3.4028234663852886e38',\n\t\tu32: '0xffffffffu',\n\t\ti32: '2147483647i',\n\t\tvec2f: 'vec2f(3.4028234663852886e38)',\n\t\tvec4f: 'vec4f(3.4028234663852886e38)',\n\t}),\n\tand: Object.freeze({ u32: '0xffffffffu', i32: '-1i' }),\n\tor: Object.freeze({ u32: '0u', i32: '0i' }),\n\txor: Object.freeze({ u32: '0u', i32: '0i' }),\n\tmul: Object.freeze({\n\t\tf32: '1.0',\n\t\tu32: '1u',\n\t\ti32: '1i',\n\t\tvec2f: 'vec2f(1.0)',\n\t\tvec4f: 'vec4f(1.0)',\n\t}),\n})\n\n/**\n * Lists the W3C WGSL keywords, reserved words (§16.3), predeclared enumerants, predeclared types,\n * predeclared builtin functions (§17 and `subgroups`), and rendered entry struct names refused as\n * identifiers.\n *\n * @example\n * ```ts\n * WGSL_RESERVED_WORDS.includes('struct') // true\n * ```\n */\nexport const WGSL_RESERVED_WORDS: readonly string[] = Object.freeze([\n\t'Dispatch',\n\t'Invocation',\n\t'NULL',\n\t'Self',\n\t'abs',\n\t'abstract',\n\t'acos',\n\t'acosh',\n\t'active',\n\t'alias',\n\t'alignas',\n\t'alignof',\n\t'all',\n\t'any',\n\t'array',\n\t'arrayLength',\n\t'as',\n\t'asin',\n\t'asinh',\n\t'asm',\n\t'asm_fragment',\n\t'async',\n\t'atan',\n\t'atan2',\n\t'atanh',\n\t'atomic',\n\t'atomicAdd',\n\t'atomicAnd',\n\t'atomicCompareExchangeWeak',\n\t'atomicExchange',\n\t'atomicLoad',\n\t'atomicMax',\n\t'atomicMin',\n\t'atomicOr',\n\t'atomicStore',\n\t'atomicSub',\n\t'atomicXor',\n\t'attribute',\n\t'auto',\n\t'await',\n\t'become',\n\t'bgra8unorm',\n\t'bitcast',\n\t'bool',\n\t'break',\n\t'case',\n\t'cast',\n\t'catch',\n\t'ceil',\n\t'clamp',\n\t'class',\n\t'co_await',\n\t'co_return',\n\t'co_yield',\n\t'coherent',\n\t'column_major',\n\t'common',\n\t'compile',\n\t'compile_fragment',\n\t'concept',\n\t'const',\n\t'const_assert',\n\t'const_cast',\n\t'consteval',\n\t'constexpr',\n\t'constinit',\n\t'continue',\n\t'continuing',\n\t'cos',\n\t'cosh',\n\t'countLeadingZeros',\n\t'countOneBits',\n\t'countTrailingZeros',\n\t'crate',\n\t'cross',\n\t'debugger',\n\t'decltype',\n\t'default',\n\t'degrees',\n\t'delete',\n\t'demote',\n\t'demote_to_helper',\n\t'determinant',\n\t'diagnostic',\n\t'discard',\n\t'distance',\n\t'do',\n\t'dot',\n\t'dot4I8Packed',\n\t'dot4U8Packed',\n\t'dpdx',\n\t'dpdxCoarse',\n\t'dpdxFine',\n\t'dpdy',\n\t'dpdyCoarse',\n\t'dpdyFine',\n\t'dynamic_cast',\n\t'else',\n\t'enable',\n\t'enum',\n\t'exp',\n\t'exp2',\n\t'explicit',\n\t'export',\n\t'extends',\n\t'extern',\n\t'external',\n\t'extractBits',\n\t'f16',\n\t'f32',\n\t'faceForward',\n\t'fallthrough',\n\t'false',\n\t'filter',\n\t'final',\n\t'finally',\n\t'firstLeadingBit',\n\t'firstTrailingBit',\n\t'floor',\n\t'fma',\n\t'fn',\n\t'for',\n\t'fract',\n\t'frexp',\n\t'friend',\n\t'from',\n\t'function',\n\t'fwidth',\n\t'fwidthCoarse',\n\t'fwidthFine',\n\t'fxgroup',\n\t'get',\n\t'goto',\n\t'groupshared',\n\t'handle',\n\t'highp',\n\t'i32',\n\t'if',\n\t'impl',\n\t'implements',\n\t'import',\n\t'inline',\n\t'insertBits',\n\t'instanceof',\n\t'interface',\n\t'inverseSqrt',\n\t'layout',\n\t'ldexp',\n\t'length',\n\t'let',\n\t'log',\n\t'log2',\n\t'loop',\n\t'lowp',\n\t'macro',\n\t'macro_rules',\n\t'mat2x2',\n\t'mat2x2f',\n\t'mat2x2h',\n\t'mat2x3',\n\t'mat2x3f',\n\t'mat2x3h',\n\t'mat2x4',\n\t'mat2x4f',\n\t'mat2x4h',\n\t'mat3x2',\n\t'mat3x2f',\n\t'mat3x2h',\n\t'mat3x3',\n\t'mat3x3f',\n\t'mat3x3h',\n\t'mat3x4',\n\t'mat3x4f',\n\t'mat3x4h',\n\t'mat4x2',\n\t'mat4x2f',\n\t'mat4x2h',\n\t'mat4x3',\n\t'mat4x3f',\n\t'mat4x3h',\n\t'mat4x4',\n\t'mat4x4f',\n\t'mat4x4h',\n\t'match',\n\t'max',\n\t'mediump',\n\t'meta',\n\t'min',\n\t'mix',\n\t'mod',\n\t'modf',\n\t'module',\n\t'move',\n\t'mut',\n\t'mutable',\n\t'namespace',\n\t'new',\n\t'nil',\n\t'noexcept',\n\t'noinline',\n\t'nointerpolation',\n\t'non_coherent',\n\t'noncoherent',\n\t'noperspective',\n\t'normalize',\n\t'null',\n\t'nullptr',\n\t'of',\n\t'operator',\n\t'override',\n\t'pack2x16float',\n\t'pack2x16snorm',\n\t'pack2x16unorm',\n\t'pack4x8snorm',\n\t'pack4x8unorm',\n\t'pack4xI8',\n\t'pack4xI8Clamp',\n\t'pack4xU8',\n\t'pack4xU8Clamp',\n\t'package',\n\t'packoffset',\n\t'partition',\n\t'pass',\n\t'patch',\n\t'pixelfragment',\n\t'pow',\n\t'precise',\n\t'precision',\n\t'premerge',\n\t'priv',\n\t'private',\n\t'protected',\n\t'ptr',\n\t'pub',\n\t'public',\n\t'quadBroadcast',\n\t'quadSwapDiagonal',\n\t'quadSwapX',\n\t'quadSwapY',\n\t'quantizeToF16',\n\t'r16float',\n\t'r16sint',\n\t'r16snorm',\n\t'r16uint',\n\t'r16unorm',\n\t'r32float',\n\t'r32sint',\n\t'r32uint',\n\t'r8sint',\n\t'r8snorm',\n\t'r8uint',\n\t'r8unorm',\n\t'radians',\n\t'read',\n\t'read_write',\n\t'readonly',\n\t'ref',\n\t'reflect',\n\t'refract',\n\t'regardless',\n\t'register',\n\t'reinterpret_cast',\n\t'require',\n\t'requires',\n\t'resource',\n\t'restrict',\n\t'return',\n\t'reverseBits',\n\t'rg11b10ufloat',\n\t'rg16float',\n\t'rg16sint',\n\t'rg16snorm',\n\t'rg16uint',\n\t'rg16unorm',\n\t'rg32float',\n\t'rg32sint',\n\t'rg32uint',\n\t'rg8sint',\n\t'rg8snorm',\n\t'rg8uint',\n\t'rg8unorm',\n\t'rgb10a2uint',\n\t'rgb10a2unorm',\n\t'rgba16float',\n\t'rgba16sint',\n\t'rgba16snorm',\n\t'rgba16uint',\n\t'rgba16unorm',\n\t'rgba32float',\n\t'rgba32sint',\n\t'rgba32uint',\n\t'rgba8sint',\n\t'rgba8snorm',\n\t'rgba8uint',\n\t'rgba8unorm',\n\t'round',\n\t'sampler',\n\t'sampler_comparison',\n\t'saturate',\n\t'select',\n\t'self',\n\t'set',\n\t'shared',\n\t'sign',\n\t'sin',\n\t'sinh',\n\t'sizeof',\n\t'smooth',\n\t'smoothstep',\n\t'snorm',\n\t'sqrt',\n\t'static',\n\t'static_assert',\n\t'static_cast',\n\t'std',\n\t'step',\n\t'storage',\n\t'storageBarrier',\n\t'struct',\n\t'subgroupAdd',\n\t'subgroupAll',\n\t'subgroupAnd',\n\t'subgroupAny',\n\t'subgroupBallot',\n\t'subgroupBroadcast',\n\t'subgroupBroadcastFirst',\n\t'subgroupElect',\n\t'subgroupExclusiveAdd',\n\t'subgroupExclusiveMul',\n\t'subgroupInclusiveAdd',\n\t'subgroupInclusiveMul',\n\t'subgroupMax',\n\t'subgroupMin',\n\t'subgroupMul',\n\t'subgroupOr',\n\t'subgroupShuffle',\n\t'subgroupShuffleDown',\n\t'subgroupShuffleUp',\n\t'subgroupShuffleXor',\n\t'subgroupXor',\n\t'subroutine',\n\t'super',\n\t'switch',\n\t'tan',\n\t'tanh',\n\t'target',\n\t'template',\n\t'textureBarrier',\n\t'textureDimensions',\n\t'textureGather',\n\t'textureGatherCompare',\n\t'textureLoad',\n\t'textureNumLayers',\n\t'textureNumLevels',\n\t'textureNumSamples',\n\t'textureSample',\n\t'textureSampleBaseClampToEdge',\n\t'textureSampleBias',\n\t'textureSampleCompare',\n\t'textureSampleCompareLevel',\n\t'textureSampleGrad',\n\t'textureSampleLevel',\n\t'textureStore',\n\t'texture_1d',\n\t'texture_2d',\n\t'texture_2d_array',\n\t'texture_3d',\n\t'texture_cube',\n\t'texture_cube_array',\n\t'texture_depth_2d',\n\t'texture_depth_2d_array',\n\t'texture_depth_cube',\n\t'texture_depth_cube_array',\n\t'texture_depth_multisampled_2d',\n\t'texture_external',\n\t'texture_multisampled_2d',\n\t'texture_storage_1d',\n\t'texture_storage_2d',\n\t'texture_storage_2d_array',\n\t'texture_storage_3d',\n\t'this',\n\t'thread_local',\n\t'throw',\n\t'trait',\n\t'transpose',\n\t'true',\n\t'trunc',\n\t'try',\n\t'type',\n\t'typedef',\n\t'typeid',\n\t'typename',\n\t'typeof',\n\t'u32',\n\t'uniform',\n\t'union',\n\t'unless',\n\t'unorm',\n\t'unpack2x16float',\n\t'unpack2x16snorm',\n\t'unpack2x16unorm',\n\t'unpack4x8snorm',\n\t'unpack4x8unorm',\n\t'unpack4xI8',\n\t'unpack4xU8',\n\t'unsafe',\n\t'unsized',\n\t'use',\n\t'using',\n\t'var',\n\t'varying',\n\t'vec2',\n\t'vec2f',\n\t'vec2h',\n\t'vec2i',\n\t'vec2u',\n\t'vec3',\n\t'vec3f',\n\t'vec3h',\n\t'vec3i',\n\t'vec3u',\n\t'vec4',\n\t'vec4f',\n\t'vec4h',\n\t'vec4i',\n\t'vec4u',\n\t'virtual',\n\t'volatile',\n\t'wgsl',\n\t'where',\n\t'while',\n\t'with',\n\t'workgroup',\n\t'workgroupBarrier',\n\t'workgroupUniformLoad',\n\t'write',\n\t'writeonly',\n\t'yield',\n])\n\n/**\n * Holds the fragment that accumulates and merges online mean and sum-of-squared-deviations moments.\n *\n * @remarks\n * It declares `struct OnlineMoments { count: f32, mean: f32, square: f32 }` and three pure helper\n * functions: `fn emptyOnlineMoments() -> OnlineMoments`, `fn pushOnlineMoments(state: OnlineMoments,\n * value: f32) -> OnlineMoments`, and `fn mergeOnlineMoments(left: OnlineMoments, right:\n * OnlineMoments) -> OnlineMoments`. The `f32` `count` field stays exact for integer sample counts up\n * to `2^24` (`16,777,216`). Inputs are assumed finite; an `Infinity` or `NaN` value propagates `NaN`.\n * It takes neither `Invocation` nor `Dispatch`, declares no workgroup storage, and reads no binding\n * and no uniform member.\n *\n * @example\n * ```ts\n * WGSL_WELFORD.name // 'welford'\n * ```\n */\nexport const WGSL_WELFORD: WGSLFragment = Object.freeze({\n\tname: 'welford',\n\tsource: [\n\t\t'struct OnlineMoments {',\n\t\t'\\tcount: f32,',\n\t\t'\\tmean: f32,',\n\t\t'\\tsquare: f32,',\n\t\t'}',\n\t\t'',\n\t\t'fn emptyOnlineMoments() -> OnlineMoments {',\n\t\t'\\treturn OnlineMoments(0.0, 0.0, 0.0);',\n\t\t'}',\n\t\t'',\n\t\t'fn pushOnlineMoments(state: OnlineMoments, value: f32) -> OnlineMoments {',\n\t\t'\\tlet count = state.count + 1.0;',\n\t\t'\\tlet delta = value - state.mean;',\n\t\t'\\tlet mean = state.mean + delta / count;',\n\t\t'\\tlet after = value - mean;',\n\t\t'\\treturn OnlineMoments(count, mean, state.square + delta * after);',\n\t\t'}',\n\t\t'',\n\t\t'fn mergeOnlineMoments(left: OnlineMoments, right: OnlineMoments) -> OnlineMoments {',\n\t\t'\\tif (left.count <= 0.0) {',\n\t\t'\\t\\treturn right;',\n\t\t'\\t}',\n\t\t'\\tif (right.count <= 0.0) {',\n\t\t'\\t\\treturn left;',\n\t\t'\\t}',\n\t\t'\\tlet count = left.count + right.count;',\n\t\t'\\tlet inv = 1.0 / count;',\n\t\t'\\tlet delta = right.mean - left.mean;',\n\t\t'\\tlet mean = left.mean + delta * (right.count * inv);',\n\t\t'\\tlet square = left.square + right.square + delta * delta * (left.count * right.count * inv);',\n\t\t'\\treturn OnlineMoments(count, mean, square);',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment that tracks a Neumaier compensated `f32` sum and merges compensated states.\n *\n * @remarks\n * It declares `struct CompensatedSum { sum: f32, error: f32 }` and three pure helper functions:\n * `fn emptyCompensatedSum() -> CompensatedSum`, `fn pushCompensatedSum(state: CompensatedSum,\n * value: f32) -> CompensatedSum`, and `fn mergeCompensatedSum(left: CompensatedSum, right:\n * CompensatedSum) -> CompensatedSum`. Preserves low-order bits across large cancellations when the\n * final total is read as `state.sum + state.error`. Inputs are assumed finite; an `Infinity` or `NaN`\n * value propagates `NaN`. It takes neither `Invocation` nor `Dispatch`, declares no workgroup\n * storage, and reads no binding and no uniform member.\n *\n * @example\n * ```ts\n * WGSL_COMPENSATED.name // 'compensated'\n * ```\n */\nexport const WGSL_COMPENSATED: WGSLFragment = Object.freeze({\n\tname: 'compensated',\n\tsource: [\n\t\t'struct CompensatedSum {',\n\t\t'\\tsum: f32,',\n\t\t'\\terror: f32,',\n\t\t'}',\n\t\t'',\n\t\t'fn emptyCompensatedSum() -> CompensatedSum {',\n\t\t'\\treturn CompensatedSum(0.0, 0.0);',\n\t\t'}',\n\t\t'',\n\t\t'fn pushCompensatedSum(state: CompensatedSum, value: f32) -> CompensatedSum {',\n\t\t'\\tlet total = state.sum + value;',\n\t\t'\\tlet delta = select((value - total) + state.sum, (state.sum - total) + value, abs(state.sum) >= abs(value));',\n\t\t'\\treturn CompensatedSum(total, state.error + delta);',\n\t\t'}',\n\t\t'',\n\t\t'fn mergeCompensatedSum(left: CompensatedSum, right: CompensatedSum) -> CompensatedSum {',\n\t\t'\\tlet merged = pushCompensatedSum(left, right.sum);',\n\t\t'\\treturn CompensatedSum(merged.sum, merged.error + right.error);',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment of deterministic 32-bit integer hashing helpers `hashWord` and `hashPair`.\n *\n * @remarks\n * It declares `fn hashWord(value: u32) -> u32` (32-bit finalizer mix) and\n * `fn hashPair(left: u32, right: u32) -> u32` (order-sensitive two-word mix). All operations use\n * wrapping `u32` arithmetic. It takes neither `Invocation` nor `Dispatch`, declares no workgroup\n * storage, and reads no binding and no uniform member.\n *\n * @example\n * ```ts\n * WGSL_HASH.name // 'hash'\n * ```\n */\nexport const WGSL_HASH: WGSLFragment = Object.freeze({\n\tname: 'hash',\n\tsource: [\n\t\t'fn hashWord(value: u32) -> u32 {',\n\t\t'\\tlet a = (value ^ (value >> 16u)) * 0x7feb352du;',\n\t\t'\\tlet b = (a ^ (a >> 15u)) * 0x846ca68bu;',\n\t\t'\\treturn b ^ (b >> 16u);',\n\t\t'}',\n\t\t'',\n\t\t'fn hashPair(left: u32, right: u32) -> u32 {',\n\t\t'\\treturn hashWord(left ^ (hashWord(right) + 0x9e3779b9u + (left << 6u) + (left >> 2u)));',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment that indexes a shared-memory tile with a padded stride or XOR bank swizzle.\n *\n * @remarks\n * Declares `computeTileIndex(row, column, side)` (`row * (side + 1u) + column`) and\n * `swizzleTileIndex(row, column, side)` (`row * side + (column ^ (row & (side - 1u)))`, for\n * power-of-two `side`). Takes neither `Invocation` nor `Dispatch`, declares no workgroup storage,\n * and reads no binding or uniform member.\n *\n * @example\n * ```ts\n * WGSL_TILE.name // 'tile'\n * ```\n */\nexport const WGSL_TILE: WGSLFragment = Object.freeze({\n\tname: 'tile',\n\tsource: [\n\t\t'fn computeTileIndex(row: u32, column: u32, side: u32) -> u32 {',\n\t\t'\\treturn row * (side + 1u) + column;',\n\t\t'}',\n\t\t'',\n\t\t'fn swizzleTileIndex(row: u32, column: u32, side: u32) -> u32 {',\n\t\t'\\treturn row * side + (column ^ (row & (side - 1u)));',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment that maps `f32` and `i32` values bijectively to order-preserving `u32` keys.\n *\n * @remarks\n * Declares `encodeFloatOrder`, `decodeFloatOrder`, `encodeSignedOrder`, and `decodeSignedOrder`.\n * `encodeFloatOrder` canonicalizes every NaN to quiet `0x7fc00000u` (`0xffc00000u` encoded) and\n * maps every non-NaN `f32` (`-Infinity < ... < -0.0 < +0.0 < ... < +Infinity`) bijectively to `u32`\n * order so wait-free `atomicMax`/`atomicMin` and integer sorts agree with IEEE-754 total order.\n * `encodeWGSLFloatOrder` and `decodeWGSLFloatOrder` are its TypeScript twins.\n *\n * @example\n * ```ts\n * WGSL_ORDER.name // 'order'\n * ```\n */\nexport const WGSL_ORDER: WGSLFragment = Object.freeze({\n\tname: 'order',\n\tsource: [\n\t\t'fn encodeFloatOrder(value: f32) -> u32 {',\n\t\t'\\tlet raw = bitcast<u32>(value);',\n\t\t'\\tlet canonical = select(raw, 0x7fc00000u, (raw & 0x7fffffffu) > 0x7f800000u);',\n\t\t'\\tlet mask = select(0x80000000u, 0xffffffffu, (canonical & 0x80000000u) != 0u);',\n\t\t'\\treturn canonical ^ mask;',\n\t\t'}',\n\t\t'',\n\t\t'fn decodeFloatOrder(bits: u32) -> f32 {',\n\t\t'\\tlet mask = select(0xffffffffu, 0x80000000u, (bits & 0x80000000u) != 0u);',\n\t\t'\\treturn bitcast<f32>(bits ^ mask);',\n\t\t'}',\n\t\t'',\n\t\t'fn encodeSignedOrder(value: i32) -> u32 {',\n\t\t'\\treturn bitcast<u32>(value) ^ 0x80000000u;',\n\t\t'}',\n\t\t'',\n\t\t'fn decodeSignedOrder(bits: u32) -> i32 {',\n\t\t'\\treturn bitcast<i32>(bits ^ 0x80000000u);',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment of error-free floating-point sum and product transformations without `fma`.\n *\n * @remarks\n * Declares `struct FloatPair { head: f32, tail: f32 }`, Knuth's 6-FLOP `computeExactSum`,\n * `computeOrderedSum` (for `abs(left) >= abs(right)`), Veltkamp's `4097.0` `splitFloat` (exact\n * for `|value| <= 8.305646e34`), and Dekker's `computeExactProduct` (which prescales large and\n * tiny finite operands automatically so every finite `f32` product avoids intermediate overflow\n * and FTZ underflow, returning `FloatPair(product, 0.0)` on zero or non-finite products). Avoids\n * `fma` so residuals survive software and hardware backends without double rounding.\n *\n * @example\n * ```ts\n * WGSL_EFT.name // 'eft'\n * ```\n */\nexport const WGSL_EFT: WGSLFragment = Object.freeze({\n\tname: 'eft',\n\tsource: [\n\t\t'struct FloatPair {',\n\t\t'\\thead: f32,',\n\t\t'\\ttail: f32,',\n\t\t'}',\n\t\t'',\n\t\t'fn computeExactSum(left: f32, right: f32) -> FloatPair {',\n\t\t'\\tlet sum = left + right;',\n\t\t'\\tlet delta = sum - left;',\n\t\t'\\tlet error = (left - (sum - delta)) + (right - delta);',\n\t\t'\\treturn FloatPair(sum, error);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeOrderedSum(left: f32, right: f32) -> FloatPair {',\n\t\t'\\tlet sum = left + right;',\n\t\t'\\tlet error = right - (sum - left);',\n\t\t'\\treturn FloatPair(sum, error);',\n\t\t'}',\n\t\t'',\n\t\t'fn splitFloat(value: f32) -> FloatPair {',\n\t\t'\\tlet scaled = 4097.0 * value;',\n\t\t'\\tlet head = scaled - (scaled - value);',\n\t\t'\\tlet tail = value - head;',\n\t\t'\\treturn FloatPair(head, tail);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeExactProduct(left: f32, right: f32) -> FloatPair {',\n\t\t'\\tlet product = left * right;',\n\t\t'\\tif (product == 0.0 || (bitcast<u32>(product) & 0x7f800000u) == 0x7f800000u) {',\n\t\t'\\t\\treturn FloatPair(product, 0.0);',\n\t\t'\\t}',\n\t\t'\\tvar a = left;',\n\t\t'\\tvar b = right;',\n\t\t'\\tvar rescale = 1.0;',\n\t\t'\\tif (abs(a) > 8.305646e34) {',\n\t\t'\\t\\ta = a * 5.960464477539063e-8;',\n\t\t'\\t\\trescale = rescale * 16777216.0;',\n\t\t'\\t} else if (abs(a) < 1.0e-20) {',\n\t\t'\\t\\ta = a * 16777216.0;',\n\t\t'\\t\\trescale = rescale * 5.960464477539063e-8;',\n\t\t'\\t}',\n\t\t'\\tif (abs(b) > 8.305646e34) {',\n\t\t'\\t\\tb = b * 5.960464477539063e-8;',\n\t\t'\\t\\trescale = rescale * 16777216.0;',\n\t\t'\\t} else if (abs(b) < 1.0e-20) {',\n\t\t'\\t\\tb = b * 16777216.0;',\n\t\t'\\t\\trescale = rescale * 5.960464477539063e-8;',\n\t\t'\\t}',\n\t\t'\\tvar scaledProduct = a * b;',\n\t\t'\\tif (abs(scaledProduct) > 1.7e38) {',\n\t\t'\\t\\ta = a * 0.5;',\n\t\t'\\t\\tb = b * 0.5;',\n\t\t'\\t\\trescale = rescale * 4.0;',\n\t\t'\\t\\tscaledProduct = a * b;',\n\t\t'\\t} else if (abs(scaledProduct) < 1.0e-22) {',\n\t\t'\\t\\ta = a * 16777216.0;',\n\t\t'\\t\\tb = b * 16777216.0;',\n\t\t'\\t\\trescale = rescale * 3.552713678800501e-15;',\n\t\t'\\t\\tscaledProduct = a * b;',\n\t\t'\\t}',\n\t\t'\\tlet splitLeft = splitFloat(a);',\n\t\t'\\tlet splitRight = splitFloat(b);',\n\t\t'\\tlet error = ((splitLeft.head * splitRight.head - scaledProduct) + splitLeft.head * splitRight.tail + splitLeft.tail * splitRight.head) + splitLeft.tail * splitRight.tail;',\n\t\t'\\treturn FloatPair(product, error * rescale);',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment of stateless Philox4x32-10 random generation, distribution sampling, and stochastic rounding.\n *\n * @remarks\n * Declares `computePhilox` (exact 10-round Random123 Philox4x32), `computeUnitFloat` (`[0, 1)`),\n * `computeOpenFloat` (23-bit `(0, 1)` never reaching `0.0` or `1.0`), `sampleNormalPair`,\n * `sampleExponential`, `sampleGumbel`, `narrowStochasticHalf`, and `narrowStochasticBFloat`.\n * `computeWGSLPhilox` is the TypeScript twin of `computePhilox`.\n *\n * @example\n * ```ts\n * WGSL_RANDOM.name // 'random'\n * ```\n */\nexport const WGSL_RANDOM: WGSLFragment = Object.freeze({\n\tname: 'random',\n\tsource: [\n\t\t'fn multiplyHighWord(left: u32, right: u32) -> u32 {',\n\t\t'\\tlet aLo = left & 0xffffu;',\n\t\t'\\tlet aHi = left >> 16u;',\n\t\t'\\tlet bLo = right & 0xffffu;',\n\t\t'\\tlet bHi = right >> 16u;',\n\t\t'\\tlet low = aLo * bLo;',\n\t\t'\\tlet mid1 = aHi * bLo;',\n\t\t'\\tlet mid2 = aLo * bHi;',\n\t\t'\\tlet high = aHi * bHi;',\n\t\t'\\tlet mid = (low >> 16u) + (mid1 & 0xffffu) + (mid2 & 0xffffu);',\n\t\t'\\treturn high + (mid1 >> 16u) + (mid2 >> 16u) + (mid >> 16u);',\n\t\t'}',\n\t\t'',\n\t\t'fn computePhilox(counter: vec4u, key: vec2u) -> vec4u {',\n\t\t'\\tvar state = counter;',\n\t\t'\\tvar k = key;',\n\t\t'\\tfor (var round = 0u; round < 10u; round += 1u) {',\n\t\t'\\t\\tlet hi0 = multiplyHighWord(0xd2511f53u, state.x);',\n\t\t'\\t\\tlet lo0 = 0xd2511f53u * state.x;',\n\t\t'\\t\\tlet hi1 = multiplyHighWord(0xcd9e8d57u, state.z);',\n\t\t'\\t\\tlet lo1 = 0xcd9e8d57u * state.z;',\n\t\t'\\t\\tstate = vec4u(hi1 ^ state.y ^ k.x, lo1, hi0 ^ state.w ^ k.y, lo0);',\n\t\t'\\t\\tk = vec2u(k.x + 0x9e3779b9u, k.y + 0xbb67ae85u);',\n\t\t'\\t}',\n\t\t'\\treturn state;',\n\t\t'}',\n\t\t'',\n\t\t'fn computeUnitFloat(bits: u32) -> f32 {',\n\t\t'\\treturn f32(bits >> 8u) * 5.960464477539063e-8;',\n\t\t'}',\n\t\t'',\n\t\t'fn computeOpenFloat(bits: u32) -> f32 {',\n\t\t'\\treturn (f32(bits >> 9u) + 0.5) * 1.1920928955078125e-7;',\n\t\t'}',\n\t\t'',\n\t\t'fn sampleNormalPair(u0: u32, u1: u32) -> vec2f {',\n\t\t'\\tlet radius = sqrt(-2.0 * log(computeOpenFloat(u0)));',\n\t\t'\\tlet angle = 6.283185307179586 * computeUnitFloat(u1);',\n\t\t'\\treturn vec2f(radius * cos(angle), radius * sin(angle));',\n\t\t'}',\n\t\t'',\n\t\t'fn sampleExponential(bits: u32) -> f32 {',\n\t\t'\\treturn -log(computeOpenFloat(bits));',\n\t\t'}',\n\t\t'',\n\t\t'fn sampleGumbel(bits: u32) -> f32 {',\n\t\t'\\treturn -log(-log(computeOpenFloat(bits)));',\n\t\t'}',\n\t\t'',\n\t\t'fn narrowStochasticHalf(value: f32, random: u32) -> u32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet negative = (bits >> 16u) & 0x8000u;',\n\t\t'\\tlet magnitude = bits & 0x7fffffffu;',\n\t\t'\\tif (magnitude > 0x7f800000u) {',\n\t\t'\\t\\treturn negative | 0x7e00u | ((magnitude >> 13u) & 0x3ffu);',\n\t\t'\\t}',\n\t\t'\\tif (magnitude >= 0x47800000u) {',\n\t\t'\\t\\treturn negative | 0x7c00u;',\n\t\t'\\t}',\n\t\t'\\tif (magnitude >= 0x38800000u) {',\n\t\t'\\t\\treturn negative | ((magnitude + (random & 0x1fffu) - 0x38000000u) >> 13u);',\n\t\t'\\t}',\n\t\t'\\tlet scaled = bitcast<f32>(magnitude) * 16777216.0;',\n\t\t'\\tlet base = u32(floor(scaled));',\n\t\t'\\tlet frac = scaled - f32(base);',\n\t\t'\\tlet step = select(0u, 1u, frac > computeUnitFloat(random));',\n\t\t'\\treturn negative | (base + step);',\n\t\t'}',\n\t\t'',\n\t\t'fn narrowStochasticBFloat(value: f32, random: u32) -> u32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tif ((bits & 0x7fffffffu) > 0x7f800000u) {',\n\t\t'\\t\\treturn (bits >> 16u) | 0x0040u;',\n\t\t'\\t}',\n\t\t'\\treturn (bits + (random & 0xffffu)) >> 16u;',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment of extended-precision double-float arithmetic over `FloatPair` without `fma`.\n *\n * @remarks\n * Declares `uses: [WGSL_EFT]` (`FloatPair`, `computeExactSum`, `computeExactProduct`), executes\n * `0` `fma()` calls, and provides `normalizeDouble`, `negateDouble`, `addDouble`,\n * `subtractDouble`, `multiplyDouble`, `divideDouble`, `computeDoubleSqrt`, and `compareDouble`.\n * Uses an unprovable-zero guard bit in `addDouble` so optimizing compilers do not fold\n * `computeExactSum` error residuals away, and `computeExactSum` cross terms in `multiplyDouble`,\n * holding `<= 2.0` double-float ULP (`2^-47` relative error) across finite `f32` products through\n * `computeExactProduct` prescaling on hardware and software backends. Non-finite `head` values\n * propagate as `FloatPair(head, 0.0)`, `divideDouble` preserves `(±0.0, 0.0)` for finite dividends\n * over `(±Infinity, 0.0)` and yields IEEE division-by-zero non-finites at `(0.0, 0.0)`,\n * `computeDoubleSqrt` returns `NaN` for negative values, and `compareDouble` returns `0i` when\n * either operand is `NaN`. `encodeWGSLDouble`, `decodeWGSLDouble`, and `isWGSLFloatPair` are its\n * TypeScript twins.\n *\n * @example\n * ```ts\n * WGSL_DOUBLE.name // 'double'\n * ```\n */\nexport const WGSL_DOUBLE: WGSLFragment = Object.freeze({\n\tname: 'double',\n\tsource: [\n\t\t'fn normalizeDouble(pair: FloatPair) -> FloatPair {',\n\t\t'\\tlet s = computeExactSum(pair.head, pair.tail);',\n\t\t'\\tif ((bitcast<u32>(s.head) & 0x7f800000u) == 0x7f800000u) {',\n\t\t'\\t\\treturn FloatPair(s.head, 0.0);',\n\t\t'\\t}',\n\t\t'\\treturn s;',\n\t\t'}',\n\t\t'',\n\t\t'fn negateDouble(value: FloatPair) -> FloatPair {',\n\t\t'\\treturn FloatPair(-value.head, -value.tail);',\n\t\t'}',\n\t\t'',\n\t\t'fn addDouble(left: FloatPair, right: FloatPair) -> FloatPair {',\n\t\t'\\tlet aBits = bitcast<u32>(left.head);',\n\t\t'\\tlet bBits = bitcast<u32>(right.head);',\n\t\t'\\tlet guardBit = select(0u, 1u, (aBits ^ bBits) == 0xffffffffu && left.head == right.head);',\n\t\t'\\tlet aHead = bitcast<f32>(aBits | guardBit);',\n\t\t'\\tlet bHead = bitcast<f32>(bBits | guardBit);',\n\t\t'\\tlet s = computeExactSum(aHead, bHead);',\n\t\t'\\tif ((bitcast<u32>(s.head) & 0x7f800000u) == 0x7f800000u) {',\n\t\t'\\t\\treturn FloatPair(s.head, 0.0);',\n\t\t'\\t}',\n\t\t'\\tlet t = computeExactSum(left.tail, right.tail);',\n\t\t'\\tlet c = s.tail + t.head;',\n\t\t'\\tlet v = computeExactSum(s.head, c);',\n\t\t'\\tif ((bitcast<u32>(v.head) & 0x7f800000u) == 0x7f800000u) {',\n\t\t'\\t\\treturn FloatPair(v.head, 0.0);',\n\t\t'\\t}',\n\t\t'\\tlet w = t.tail + v.tail;',\n\t\t'\\tlet out = computeExactSum(v.head, w);',\n\t\t'\\tif ((bitcast<u32>(out.head) & 0x7f800000u) == 0x7f800000u) {',\n\t\t'\\t\\treturn FloatPair(out.head, 0.0);',\n\t\t'\\t}',\n\t\t'\\treturn out;',\n\t\t'}',\n\t\t'',\n\t\t'fn subtractDouble(left: FloatPair, right: FloatPair) -> FloatPair {',\n\t\t'\\treturn addDouble(left, negateDouble(right));',\n\t\t'}',\n\t\t'',\n\t\t'fn multiplyDouble(left: FloatPair, right: FloatPair) -> FloatPair {',\n\t\t'\\tlet p = computeExactProduct(left.head, right.head);',\n\t\t'\\tif ((bitcast<u32>(p.head) & 0x7f800000u) == 0x7f800000u) {',\n\t\t'\\t\\treturn FloatPair(p.head, 0.0);',\n\t\t'\\t}',\n\t\t'\\tlet c = computeExactSum(left.head * right.tail, left.tail * right.head);',\n\t\t'\\tlet tail = addDouble(c, FloatPair(left.tail * right.tail, 0.0));',\n\t\t'\\treturn addDouble(p, tail);',\n\t\t'}',\n\t\t'',\n\t\t'fn divideDouble(left: FloatPair, right: FloatPair) -> FloatPair {',\n\t\t'\\tif (right.head == 0.0 && right.tail == 0.0) {',\n\t\t'\\t\\treturn FloatPair(left.head / right.head, 0.0);',\n\t\t'\\t}',\n\t\t'\\tlet q1 = left.head / right.head;',\n\t\t'\\tif ((bitcast<u32>(q1) & 0x7f800000u) == 0x7f800000u || (bitcast<u32>(right.head) & 0x7f800000u) == 0x7f800000u) {',\n\t\t'\\t\\treturn FloatPair(q1, 0.0);',\n\t\t'\\t}',\n\t\t'\\tlet r1 = subtractDouble(left, multiplyDouble(FloatPair(q1, 0.0), right));',\n\t\t'\\tlet q2 = r1.head / right.head;',\n\t\t'\\tlet r2 = subtractDouble(r1, multiplyDouble(FloatPair(q2, 0.0), right));',\n\t\t'\\tlet q3 = r2.head / right.head;',\n\t\t'\\tlet s = computeExactSum(q1, q2);',\n\t\t'\\treturn addDouble(s, FloatPair(q3, 0.0));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeDoubleSqrt(value: FloatPair) -> FloatPair {',\n\t\t'\\tif (value.head == 0.0 && value.tail == 0.0) {',\n\t\t'\\t\\treturn FloatPair(value.head, 0.0);',\n\t\t'\\t}',\n\t\t'\\tif (value.head < 0.0 || (bitcast<u32>(value.head) & 0x7f800000u) == 0x7f800000u) {',\n\t\t'\\t\\treturn FloatPair(sqrt(value.head), 0.0);',\n\t\t'\\t}',\n\t\t'\\tlet s = sqrt(value.head);',\n\t\t'\\tlet sq = computeExactProduct(s, s);',\n\t\t'\\tlet rem = subtractDouble(value, sq);',\n\t\t'\\tlet corr = rem.head / (2.0 * s);',\n\t\t'\\tlet approx = computeExactSum(s, corr);',\n\t\t'\\tlet rem2 = subtractDouble(value, multiplyDouble(approx, approx));',\n\t\t'\\tlet corr2 = rem2.head / (2.0 * approx.head);',\n\t\t'\\treturn addDouble(approx, FloatPair(corr2, 0.0));',\n\t\t'}',\n\t\t'',\n\t\t'fn compareDouble(left: FloatPair, right: FloatPair) -> i32 {',\n\t\t'\\tlet a = normalizeDouble(left);',\n\t\t'\\tlet b = normalizeDouble(right);',\n\t\t'\\tif (a.head < b.head) {',\n\t\t'\\t\\treturn -1i;',\n\t\t'\\t}',\n\t\t'\\tif (a.head > b.head) {',\n\t\t'\\t\\treturn 1i;',\n\t\t'\\t}',\n\t\t'\\tif (a.tail < b.tail) {',\n\t\t'\\t\\treturn -1i;',\n\t\t'\\t}',\n\t\t'\\tif (a.tail > b.tail) {',\n\t\t'\\t\\treturn 1i;',\n\t\t'\\t}',\n\t\t'\\treturn 0i;',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([WGSL_EFT]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment of special mathematical functions (`erf`, `erfc`, `inverseErf`, `logGamma`, `gamma`, `logBeta`, `sinc`, `sinPi`, `cosPi`, and `I_0`) without `fma`.\n *\n * @remarks\n * Declares `uses: [WGSL_EFT, WGSL_DOUBLE]`, executes `0` `fma()` calls, and provides `computeErf`,\n * `computeErfc`, `computeInverseErf`, `computeLogGamma`, `computeGamma`, `computeLogBeta`,\n * `computeSinc` (unnormalized `sin(x) / x`), `computeSinPi`, `computeCosPi`, `computeBesselZero`,\n * and `computeScaledBesselZero`, together with `scaleSpecial*` and `computeSpecial*` internal\n * helpers for FTZ-proof subnormal scaling, Cody-Waite exponential and trigonometric range\n * reduction, and `FloatPair` log-gamma and log-beta evaluation. Accuracy bounds: `<= 2` ULP on\n * `computeErf` (saturating to `±1.0` for `|x| >= 4.0`), `computeInverseErf` (`[-1.0, 1.0]`,\n * returning `±Infinity` at `±1.0` and runtime `NaN` for `|x| > 1.0`), `computeSinc` (`1.0` at\n * `±0.0`, `0.0` at `±Infinity`), `computeSinPi`, and `computeCosPi` (exact `0.0`/`±1.0` at integer\n * and half-integer multiples); `<= 3` ULP on `computeErfc` (`0.0` for `x >= 10.1`, `2.0` for\n * `x <= -4.0`), `computeLogGamma` (`+Infinity` at `±0.0`, `±Infinity`, and negative integers),\n * `computeGamma` (`NaN` at negative integers and `-Infinity`, `+Infinity` for `x > 35.041`),\n * `computeLogBeta` (`NaN` when `left` or `right` is non-positive or `NaN`, `-Infinity` when either\n * positive argument is `+Infinity`, supporting positive subnormals under FTZ and finite pairs up to\n * `3.4028234663852886e38`), `computeBesselZero` (`+Infinity` for `|x| > 92.0`), and\n * `computeScaledBesselZero` (`1.0` at `±0.0`, `0.0` at `±Infinity`). `computeWGSLErf`,\n * `computeWGSLErfc`, `computeWGSLInverseErf`, and `computeWGSLLogGamma` are its TypeScript twins.\n *\n * @example\n * ```ts\n * WGSL_SPECIAL.name // 'special'\n * ```\n */\nexport const WGSL_SPECIAL: WGSLFragment = Object.freeze({\n\tname: 'special',\n\tsource: [\n\t\t'fn scaleSpecialPowerOfTwo(value: f32, shift: i32) -> f32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet signBit = bits & 0x80000000u;',\n\t\t'\\tlet rawExp = i32((bits >> 23u) & 0xffu);',\n\t\t'\\tlet frac = bits & 0x7fffffu;',\n\t\t'\\tif (rawExp == 255i) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tvar exponent = rawExp;',\n\t\t'\\tvar mant = frac | 0x800000u;',\n\t\t'\\tif (rawExp == 0i) {',\n\t\t'\\t\\tif (frac == 0u) {',\n\t\t'\\t\\t\\treturn value;',\n\t\t'\\t\\t}',\n\t\t'\\t\\tlet top = firstLeadingBit(frac);',\n\t\t'\\t\\texponent = i32(top) - 22i;',\n\t\t'\\t\\tmant = frac << (23u - top);',\n\t\t'\\t}',\n\t\t'\\tlet newExp = exponent + shift;',\n\t\t'\\tif (newExp >= 255i) {',\n\t\t'\\t\\treturn bitcast<f32>(signBit | 0x7f800000u);',\n\t\t'\\t}',\n\t\t'\\tif (newExp > 0i) {',\n\t\t'\\t\\treturn bitcast<f32>(signBit | (u32(newExp) << 23u) | (mant & 0x7fffffu));',\n\t\t'\\t}',\n\t\t'\\tlet subShift = u32(1i - newExp);',\n\t\t'\\tif (subShift >= 25u) {',\n\t\t'\\t\\treturn bitcast<f32>(signBit);',\n\t\t'\\t}',\n\t\t'\\tlet half = 1u << (subShift - 1u);',\n\t\t'\\tlet rem = mant & ((1u << subShift) - 1u);',\n\t\t'\\tlet kept = mant >> subShift;',\n\t\t'\\tlet roundUp = rem > half || (rem == half && (kept & 1u) == 1u);',\n\t\t'\\treturn bitcast<f32>(signBit | (kept + select(0u, 1u, roundUp)));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialExpScaled(head: f32, tail: f32, scale: f32) -> f32 {',\n\t\t'\\tlet kf = floor(head * 1.4426950408889634 + 0.5);',\n\t\t'\\tlet k = i32(kf);',\n\t\t'\\tlet r = ((head - kf * 0.693145751953125) - kf * 1.428606765330187e-6) + tail;',\n\t\t'\\tlet er = 1.0 + r * (1.0 + r * (0.5 + r * (0.166666672 + r * (0.0416666679 + r * (0.00833333377 + r * (0.00138888892 + r * 0.000198412701))))));',\n\t\t'\\treturn scaleSpecialPowerOfTwo(er * scale, k);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialLogOnePlusSmall(delta: FloatPair) -> FloatPair {',\n\t\t'\\tif (abs(delta.head) < 1.0e-12) {',\n\t\t'\\t\\treturn delta;',\n\t\t'\\t}',\n\t\t'\\tlet t = divideDouble(delta, addDouble(FloatPair(2.0, 0.0), delta));',\n\t\t'\\tlet t2 = multiplyDouble(t, t);',\n\t\t'\\tlet t3 = multiplyDouble(t2, t);',\n\t\t'\\tlet t5 = multiplyDouble(t3, t2);',\n\t\t'\\tlet t2f = t2.head;',\n\t\t'\\tlet polyHigh = (t5.head * t2f) * (0.142857149 + t2f * (0.111111112 + t2f * (0.0909090936 + t2f * (0.0769230798 + t2f * 0.0666666701))));',\n\t\t'\\tvar s = addDouble(t, multiplyDouble(t3, FloatPair(0.3333333432674408, -9.93410748e-9)));',\n\t\t'\\ts = addDouble(s, multiplyDouble(t5, FloatPair(0.20000000298023224, -2.98023224e-9)));',\n\t\t'\\ts = addDouble(s, FloatPair(polyHigh, 0.0));',\n\t\t'\\treturn FloatPair(2.0 * s.head, 2.0 * s.tail);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialLogPair(pair: FloatPair) -> FloatPair {',\n\t\t'\\tlet bits = bitcast<u32>(pair.head);',\n\t\t'\\tlet rawExp = i32((bits >> 23u) & 0xffu);',\n\t\t'\\tlet frac = bits & 0x7fffffu;',\n\t\t'\\tvar exponent = rawExp - 127i;',\n\t\t'\\tvar m = bitcast<f32>(0x3f800000u | frac);',\n\t\t'\\tvar mt = scaleSpecialPowerOfTwo(pair.tail, -exponent);',\n\t\t'\\tif (rawExp == 0i) {',\n\t\t'\\t\\tlet top = firstLeadingBit(frac);',\n\t\t'\\t\\texponent = i32(top) - 149i;',\n\t\t'\\t\\tm = bitcast<f32>(0x3f800000u | ((frac << (23u - top)) & 0x7fffffu));',\n\t\t'\\t\\tmt = 0.0;',\n\t\t'\\t}',\n\t\t'\\tif (m > 1.41421356) {',\n\t\t'\\t\\tm = m * 0.5;',\n\t\t'\\t\\tmt = mt * 0.5;',\n\t\t'\\t\\texponent = exponent + 1i;',\n\t\t'\\t}',\n\t\t'\\tlet delta = addDouble(FloatPair(m, mt), FloatPair(-1.0, 0.0));',\n\t\t'\\tlet s = computeSpecialLogOnePlusSmall(delta);',\n\t\t'\\tlet ePart = multiplyDouble(FloatPair(0.6931471824645996, -1.904654299957768e-9), FloatPair(f32(exponent), 0.0));',\n\t\t'\\treturn addDouble(s, ePart);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialSinPiQuarter(r: f32) -> FloatPair {',\n\t\t'\\tlet r2 = computeExactProduct(r, r);',\n\t\t'\\tlet r3 = multiplyDouble(r2, FloatPair(r, 0.0));',\n\t\t'\\tlet p1 = multiplyDouble(FloatPair(r, 0.0), FloatPair(3.1415927410125732, -8.742278012618954e-8));',\n\t\t'\\tlet p3 = multiplyDouble(r3, FloatPair(-5.167712688446045, -1.1476444e-7));',\n\t\t'\\tlet r2f = r2.head;',\n\t\t'\\tlet tailPoly = r * r2f * r2f * (2.55016404 + r2f * (-0.599264529 + r2f * (0.0821458866 - r2f * 0.0073704309)));',\n\t\t'\\treturn addDouble(addDouble(p1, p3), FloatPair(tailPoly, 0.0));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialCosPiQuarterMinusOne(r: f32) -> FloatPair {',\n\t\t'\\tlet r2 = computeExactProduct(r, r);',\n\t\t'\\tlet p2 = multiplyDouble(r2, FloatPair(-4.934802055358887, -1.45473545e-7));',\n\t\t'\\tlet r2f = r2.head;',\n\t\t'\\tlet tailPoly = r2f * r2f * (4.05871201 + r2f * (-1.33526278 + r2f * (0.235330626 + r2f * (-0.0258068908 + r2f * 0.0019295743))));',\n\t\t'\\treturn addDouble(p2, FloatPair(tailPoly, 0.0));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialCosPiQuarter(r: f32) -> FloatPair {',\n\t\t'\\treturn addDouble(FloatPair(1.0, 0.0), computeSpecialCosPiQuarterMinusOne(r));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialLogAbsSinPi(magnitude: f32) -> FloatPair {',\n\t\t'\\tlet m = magnitude - 2.0 * floor(magnitude * 0.5);',\n\t\t'\\tlet q = u32(floor(m * 2.0 + 0.5));',\n\t\t'\\tlet r = m - 0.5 * f32(q);',\n\t\t'\\tlet quad = q & 3u;',\n\t\t'\\tif (quad == 1u || quad == 3u) {',\n\t\t'\\t\\treturn computeSpecialLogOnePlusSmall(computeSpecialCosPiQuarterMinusOne(r));',\n\t\t'\\t}',\n\t\t'\\tvar v = computeSpecialSinPiQuarter(r);',\n\t\t'\\tif (v.head < 0.0) {',\n\t\t'\\t\\tv = negateDouble(v);',\n\t\t'\\t}',\n\t\t'\\treturn computeSpecialLogPair(v);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSinPi(value: f32) -> f32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet mag = bits & 0x7fffffffu;',\n\t\t'\\tif (mag >= 0x7f800000u) {',\n\t\t'\\t\\treturn value - value;',\n\t\t'\\t}',\n\t\t'\\tlet signBit = bits & 0x80000000u;',\n\t\t'\\tif (mag == 0u) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tif (mag < 0x0a000000u) {',\n\t\t'\\t\\tlet norm = scaleSpecialPowerOfTwo(bitcast<f32>(mag), 64i);',\n\t\t'\\t\\tlet p = computeExactProduct(3.1415927410125732, norm);',\n\t\t'\\t\\tlet res = p.head + (p.tail - 8.742278012618954e-8 * norm);',\n\t\t'\\t\\treturn bitcast<f32>(bitcast<u32>(scaleSpecialPowerOfTwo(res, -64i)) | signBit);',\n\t\t'\\t}',\n\t\t'\\tlet ax = abs(value);',\n\t\t'\\tif (ax >= 8388608.0) {',\n\t\t'\\t\\treturn bitcast<f32>(signBit);',\n\t\t'\\t}',\n\t\t'\\tlet m = ax - 2.0 * floor(ax * 0.5);',\n\t\t'\\tlet q = u32(floor(m * 2.0 + 0.5));',\n\t\t'\\tlet r = m - 0.5 * f32(q);',\n\t\t'\\tvar outVal = 0.0;',\n\t\t'\\tlet quad = q & 3u;',\n\t\t'\\tif (quad == 0u) {',\n\t\t'\\t\\tlet p = computeSpecialSinPiQuarter(r);',\n\t\t'\\t\\toutVal = p.head + p.tail;',\n\t\t'\\t} else if (quad == 1u) {',\n\t\t'\\t\\tlet p = computeSpecialCosPiQuarter(r);',\n\t\t'\\t\\toutVal = p.head + p.tail;',\n\t\t'\\t} else if (quad == 2u) {',\n\t\t'\\t\\tif (r != 0.0) {',\n\t\t'\\t\\t\\tlet p = computeSpecialSinPiQuarter(r);',\n\t\t'\\t\\t\\toutVal = -(p.head + p.tail);',\n\t\t'\\t\\t}',\n\t\t'\\t} else {',\n\t\t'\\t\\tlet p = computeSpecialCosPiQuarter(r);',\n\t\t'\\t\\toutVal = -(p.head + p.tail);',\n\t\t'\\t}',\n\t\t'\\treturn bitcast<f32>(bitcast<u32>(outVal) ^ signBit);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeCosPi(value: f32) -> f32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet mag = bits & 0x7fffffffu;',\n\t\t'\\tif (mag >= 0x7f800000u) {',\n\t\t'\\t\\treturn value - value;',\n\t\t'\\t}',\n\t\t'\\tif ((bits & 0x7f800000u) == 0u) {',\n\t\t'\\t\\treturn 1.0;',\n\t\t'\\t}',\n\t\t'\\tlet ax = abs(value);',\n\t\t'\\tif (ax >= 16777216.0) {',\n\t\t'\\t\\treturn 1.0;',\n\t\t'\\t}',\n\t\t'\\tif (ax >= 8388608.0) {',\n\t\t'\\t\\treturn select(1.0, -1.0, (u32(ax) & 1u) != 0u);',\n\t\t'\\t}',\n\t\t'\\tlet m = ax - 2.0 * floor(ax * 0.5);',\n\t\t'\\tlet q = u32(floor(m * 2.0 + 0.5));',\n\t\t'\\tlet r = m - 0.5 * f32(q);',\n\t\t'\\tlet quad = q & 3u;',\n\t\t'\\tif (quad == 0u) {',\n\t\t'\\t\\tlet p = computeSpecialCosPiQuarter(r);',\n\t\t'\\t\\treturn p.head + p.tail;',\n\t\t'\\t}',\n\t\t'\\tif (quad == 1u) {',\n\t\t'\\t\\tif (r == 0.0) {',\n\t\t'\\t\\t\\treturn 0.0;',\n\t\t'\\t\\t}',\n\t\t'\\t\\tlet p = computeSpecialSinPiQuarter(r);',\n\t\t'\\t\\treturn -(p.head + p.tail);',\n\t\t'\\t}',\n\t\t'\\tif (quad == 2u) {',\n\t\t'\\t\\tlet p = computeSpecialCosPiQuarter(r);',\n\t\t'\\t\\treturn -(p.head + p.tail);',\n\t\t'\\t}',\n\t\t'\\tif (r == 0.0) {',\n\t\t'\\t\\treturn 0.0;',\n\t\t'\\t}',\n\t\t'\\tlet p = computeSpecialSinPiQuarter(r);',\n\t\t'\\treturn p.head + p.tail;',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialReducedSin(reduced: FloatPair) -> f32 {',\n\t\t'\\tlet r = reduced.head;',\n\t\t'\\tlet ar = abs(r);',\n\t\t'\\tlet signBit = bitcast<u32>(r) & 0x80000000u;',\n\t\t'\\tif (ar <= 0.785398163) {',\n\t\t'\\t\\tlet r2 = r * r;',\n\t\t'\\t\\tlet sBase = r + r * r2 * (-0.166666672 + r2 * (0.00833333377 + r2 * (-0.000198412701 + r2 * (2.75573188e-6 - r2 * 2.50521084e-8))));',\n\t\t'\\t\\tlet cApprox = 1.0 - 0.5 * r2 * (1.0 - r2 * 0.0833333358);',\n\t\t'\\t\\treturn sBase + reduced.tail * cApprox;',\n\t\t'\\t}',\n\t\t'\\tlet u = (1.5707963705062866 - ar) - 4.371139000186241e-8;',\n\t\t'\\tlet uTail = select(-reduced.tail, reduced.tail, r < 0.0);',\n\t\t'\\tlet u2 = u * u;',\n\t\t'\\tlet cBase = 1.0 + u2 * (-0.5 + u2 * (0.0416666679 + u2 * (-0.00138888892 + u2 * (2.48015876e-5 - u2 * 2.75573188e-7))));',\n\t\t'\\tlet sApprox = u * (1.0 - u2 * 0.166666672);',\n\t\t'\\tlet magOut = cBase - uTail * sApprox;',\n\t\t'\\treturn bitcast<f32>(bitcast<u32>(magOut) | signBit);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSinc(value: f32) -> f32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet mag = bits & 0x7fffffffu;',\n\t\t'\\tif (mag > 0x7f800000u) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tif (mag == 0x7f800000u) {',\n\t\t'\\t\\treturn 0.0;',\n\t\t'\\t}',\n\t\t'\\tif ((bits & 0x7f800000u) == 0u) {',\n\t\t'\\t\\treturn 1.0;',\n\t\t'\\t}',\n\t\t'\\tlet ax = abs(value);',\n\t\t'\\tif (ax < 0.05) {',\n\t\t'\\t\\tlet x2 = value * value;',\n\t\t'\\t\\treturn 1.0 + x2 * (-0.166666672 + x2 * (0.00833333377 - x2 * 0.000198412701));',\n\t\t'\\t}',\n\t\t'\\tlet kf = floor(value * 0.3183098861837907 + 0.5);',\n\t\t'\\tlet ki = i32(kf);',\n\t\t'\\tlet r1 = computeExactSum(value, -kf * 3.1416015625);',\n\t\t'\\tlet r2 = addDouble(r1, FloatPair(-kf * -8.907169103622437e-6, 0.0));',\n\t\t'\\tlet rPair = addDouble(r2, FloatPair(-kf * -1.741103261565513e-9, 0.0));',\n\t\t'\\tlet sv = computeSpecialReducedSin(rPair);',\n\t\t'\\tlet s = select(sv, -sv, (ki & 1i) != 0i);',\n\t\t'\\treturn s / value;',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialErfSmall(x: f32) -> f32 {',\n\t\t'\\tlet z = 2.0 * (x * x) - 1.0;',\n\t\t'\\tlet q = -0.0345312618 + z * (-0.140536085 + z * (0.0198524985 + z * (-0.00228548562 + z * (0.000217511988 + z * (-0.0000175369150 + z * (0.00000123163954 + z * -7.55237863e-8))))));',\n\t\t'\\treturn x + x * q;',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialErfcScaled(magnitude: f32) -> f32 {',\n\t\t'\\tif (magnitude <= 2.0) {',\n\t\t'\\t\\tlet z = (magnitude - 1.25) * 1.33333337;',\n\t\t'\\t\\treturn 0.367822915 + z * (-0.156616405 + z * (0.0600721650 + z * (-0.0211857520 + z * (0.00696725491 + z * (-0.00215576263 + z * (0.000624853652 + z * (-0.000175172987 + z * (0.0000558042448 + z * -0.0000142351064))))))));',\n\t\t'\\t}',\n\t\t'\\tlet u = 1.0 / magnitude;',\n\t\t'\\tlet z = (u - 0.295) * 4.8780489;',\n\t\t'\\treturn u * (0.542302787 + z * (-0.0273120534 + z * (-0.00582956802 + z * (0.00180627254 + z * (-0.000136895775 + z * (-0.0000611297219 + z * (0.0000263090988 + z * (-0.00000391786580 + z * (-0.00000104538833 + z * 5.89392187e-7)))))))));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialErfcPositive(magnitude: f32) -> f32 {',\n\t\t'\\tif (magnitude <= 0.5) {',\n\t\t'\\t\\treturn 1.0 - computeSpecialErfSmall(magnitude);',\n\t\t'\\t}',\n\t\t'\\tif (magnitude >= 10.1) {',\n\t\t'\\t\\treturn 0.0;',\n\t\t'\\t}',\n\t\t'\\tlet ex = computeSpecialErfcScaled(magnitude);',\n\t\t'\\tlet sq = computeExactProduct(magnitude, magnitude);',\n\t\t'\\treturn computeSpecialExpScaled(-sq.head, -sq.tail, ex);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeErf(value: f32) -> f32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet mag = bits & 0x7fffffffu;',\n\t\t'\\tif (mag > 0x7f800000u) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tif (mag == 0u) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tlet signBit = bits & 0x80000000u;',\n\t\t'\\tif (mag < 0x03000000u) {',\n\t\t'\\t\\tlet norm = scaleSpecialPowerOfTwo(bitcast<f32>(mag), 32i);',\n\t\t'\\t\\tlet res = norm + norm * 0.12837916709551257;',\n\t\t'\\t\\treturn bitcast<f32>(bitcast<u32>(scaleSpecialPowerOfTwo(res, -32i)) | signBit);',\n\t\t'\\t}',\n\t\t'\\tlet ax = abs(value);',\n\t\t'\\tif (ax >= 4.0) {',\n\t\t'\\t\\treturn bitcast<f32>(0x3f800000u | signBit);',\n\t\t'\\t}',\n\t\t'\\tif (ax <= 1.0) {',\n\t\t'\\t\\treturn computeSpecialErfSmall(value);',\n\t\t'\\t}',\n\t\t'\\tlet magOut = 1.0 - computeSpecialErfcPositive(ax);',\n\t\t'\\treturn bitcast<f32>(bitcast<u32>(magOut) | signBit);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeErfc(value: f32) -> f32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet mag = bits & 0x7fffffffu;',\n\t\t'\\tif (mag > 0x7f800000u) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tif ((bits & 0x7f800000u) == 0u) {',\n\t\t'\\t\\treturn 1.0;',\n\t\t'\\t}',\n\t\t'\\tif (value <= -4.0) {',\n\t\t'\\t\\treturn 2.0;',\n\t\t'\\t}',\n\t\t'\\tif (value < 0.0) {',\n\t\t'\\t\\treturn 1.0 + computeErf(-value);',\n\t\t'\\t}',\n\t\t'\\treturn computeSpecialErfcPositive(value);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeInverseErf(value: f32) -> f32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet mag = bits & 0x7fffffffu;',\n\t\t'\\tif (mag > 0x7f800000u) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tlet signBit = bits & 0x80000000u;',\n\t\t'\\tif (mag == 0u) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tif (mag < 0x01000000u) {',\n\t\t'\\t\\tlet norm = scaleSpecialPowerOfTwo(bitcast<f32>(mag), 32i);',\n\t\t'\\t\\tlet res = norm * 0.886226925452758;',\n\t\t'\\t\\treturn bitcast<f32>(bitcast<u32>(scaleSpecialPowerOfTwo(res, -32i)) | signBit);',\n\t\t'\\t}',\n\t\t'\\tlet ax = abs(value);',\n\t\t'\\tif (ax > 1.0) {',\n\t\t'\\t\\treturn bitcast<f32>(0x7fc00000u | (bits & 0u));',\n\t\t'\\t}',\n\t\t'\\tif (ax == 1.0) {',\n\t\t'\\t\\treturn bitcast<f32>(0x7f800000u | signBit);',\n\t\t'\\t}',\n\t\t'\\tif (ax <= 0.78) {',\n\t\t'\\t\\tlet z = (ax * ax - 0.3042) * 3.28731108;',\n\t\t'\\t\\treturn value * (0.971782625 + z * (0.104686037 + z * (0.0245909821 + z * (0.00721075106 + z * (0.00234989240 + z * (0.000814040832 + z * (0.000293783407 + z * (0.000110790883 + z * (0.0000420661381 + z * (0.0000134003812 + z * (0.00000519526657 + z * (0.00000430351474 + z * 0.00000172673720))))))))))));',\n\t\t'\\t}',\n\t\t'\\tlet prod = computeExactProduct(1.0 - ax, 1.0 + ax);',\n\t\t'\\tlet lnP = computeSpecialLogPair(prod);',\n\t\t'\\tlet w = -(lnP.head + lnP.tail);',\n\t\t'\\tif (w <= 2.6) {',\n\t\t'\\t\\tlet z = (w - 1.75) * 1.17647064;',\n\t\t'\\t\\treturn value * (1.31467748 + z * (0.212858319 + z * (-0.000447611732 + z * (-0.00116793381 + z * (0.000105308580 + z * (0.00000676320860 + z * (-0.00000199575629 + z * (4.82994160e-8 + z * (2.63141029e-8 + z * (-2.58559041e-9 + z * (-2.23366214e-10 + z * 5.22059444e-11)))))))))));',\n\t\t'\\t}',\n\t\t'\\tif (w <= 5.05) {',\n\t\t'\\t\\tlet z = (w - 3.85) * 0.8;',\n\t\t'\\t\\treturn value * (1.82436419 + z * (0.288131982 + z * (-0.0111135887 + z * (-0.000544568640 + z * (0.000318984879 + z * (-0.0000484095763 + z * (0.00000106392531 + z * (0.00000104302637 + z * (-2.12342954e-7 + z * (9.80334480e-9 + z * (4.03211198e-9 + z * -8.91356933e-10)))))))))));',\n\t\t'\\t}',\n\t\t'\\tlet s = sqrt(w);',\n\t\t'\\tlet z = (s - 3.175) * 1.02564108;',\n\t\t'\\tlet res = 3.00846004 + z * (0.979645491 + z * (0.00497440854 + z * (-0.00251659984 + z * (0.000850349606 + z * (-0.000204056749 + z * (0.0000113141559 + z * (0.0000242901242 + z * (-0.0000148406662 + z * (0.00000196516817 + z * 9.30325768e-7)))))))));',\n\t\t'\\treturn bitcast<f32>(bitcast<u32>(res) | signBit);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialStirlingSeries(y: FloatPair) -> FloatPair {',\n\t\t'\\tlet inv = divideDouble(FloatPair(1.0, 0.0), y);',\n\t\t'\\tlet inv2 = multiplyDouble(inv, inv);',\n\t\t'\\tlet inv3 = multiplyDouble(inv2, inv);',\n\t\t'\\tvar ser = multiplyDouble(inv, FloatPair(0.0833333358168602, -2.48352688e-9));',\n\t\t'\\tser = addDouble(ser, multiplyDouble(inv3, FloatPair(-0.0027777778450399637, 6.7262186e-11)));',\n\t\t'\\tlet inv2f = inv2.head;',\n\t\t'\\tlet rest = (inv3.head * inv2f) * (0.000793650805 + inv2f * (-0.000595238118 + inv2f * 0.000841750833));',\n\t\t'\\treturn addDouble(ser, FloatPair(rest, 0.0));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialLogGammaPositive(xPair: FloatPair) -> FloatPair {',\n\t\t'\\tvar y = xPair;',\n\t\t'\\tvar prod = FloatPair(1.0, 0.0);',\n\t\t'\\tvar steps = 0u;',\n\t\t'\\twhile (y.head < 14.0) {',\n\t\t'\\t\\tprod = multiplyDouble(prod, y);',\n\t\t'\\t\\ty = addDouble(y, FloatPair(1.0, 0.0));',\n\t\t'\\t\\tsteps += 1u;',\n\t\t'\\t}',\n\t\t'\\tlet ly = computeSpecialLogPair(y);',\n\t\t'\\tvar term = FloatPair(0.0, 0.0);',\n\t\t'\\tif (y.head > 1.0e30) {',\n\t\t'\\t\\tlet ys = FloatPair(y.head * 5.421010862427522e-20, y.tail * 5.421010862427522e-20);',\n\t\t'\\t\\tlet ps = multiplyDouble(ys, ly);',\n\t\t'\\t\\tterm = subtractDouble(FloatPair(ps.head * 1.8446744073709552e19, ps.tail * 1.8446744073709552e19), y);',\n\t\t'\\t} else {',\n\t\t'\\t\\tlet ym = addDouble(y, FloatPair(-0.5, 0.0));',\n\t\t'\\t\\tterm = subtractDouble(multiplyDouble(ym, ly), y);',\n\t\t'\\t}',\n\t\t'\\tvar res = addDouble(term, FloatPair(0.9189385175704956, 1.56343402e-8));',\n\t\t'\\tif (y.head < 1.0e18) {',\n\t\t'\\t\\tres = addDouble(res, computeSpecialStirlingSeries(y));',\n\t\t'\\t}',\n\t\t'\\tif (steps > 0u) {',\n\t\t'\\t\\tres = subtractDouble(res, computeSpecialLogPair(prod));',\n\t\t'\\t}',\n\t\t'\\treturn res;',\n\t\t'}',\n\t\t'',\n\t\t'fn computeLogGamma(value: f32) -> f32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet mag = bits & 0x7fffffffu;',\n\t\t'\\tif (mag > 0x7f800000u) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tif (mag == 0x7f800000u || mag == 0u) {',\n\t\t'\\t\\treturn bitcast<f32>(0x7f800000u | (bits & 0u));',\n\t\t'\\t}',\n\t\t'\\tif ((bits & 0x7f800000u) == 0u) {',\n\t\t'\\t\\tlet lx = computeSpecialLogPair(FloatPair(bitcast<f32>(mag), 0.0));',\n\t\t'\\t\\treturn -(lx.head + lx.tail);',\n\t\t'\\t}',\n\t\t'\\tif (value <= 0.0 && value == floor(value)) {',\n\t\t'\\t\\treturn bitcast<f32>(0x7f800000u | (bits & 0u));',\n\t\t'\\t}',\n\t\t'\\tif (value == 1.0 || value == 2.0) {',\n\t\t'\\t\\treturn 0.0;',\n\t\t'\\t}',\n\t\t'\\tif (value >= 0.5 && value < 1.0) {',\n\t\t'\\t\\tlet u = value - 1.0;',\n\t\t'\\t\\tlet z = -4.0 * u - 1.0;',\n\t\t'\\t\\treturn u * (-0.813123822 + z * (-0.272737086 + z * (-0.0449976847 + z * (-0.0102378204 + z * (-0.00263040932 + z * (-0.000717988994 + z * (-0.000198857451 + z * (-0.0000576094681 + z * (-0.0000220084421 + z * -0.00000661451031)))))))));',\n\t\t'\\t}',\n\t\t'\\tif (value > 1.0 && value <= 1.5) {',\n\t\t'\\t\\tlet u = value - 1.0;',\n\t\t'\\t\\tlet z = 4.0 * u - 1.0;',\n\t\t'\\t\\treturn u * (-0.393087357 + z * (0.165633813 + z * (-0.0159676671 + z * (0.00213704351 + z * (-0.000325759727 + z * (0.0000531170517 + z * (-0.00000899449515 + z * (0.00000156732563 + z * (-3.03118810e-7 + z * 5.46500623e-8)))))))));',\n\t\t'\\t}',\n\t\t'\\tif (value > 1.5 && value <= 2.5) {',\n\t\t'\\t\\tlet u = value - 2.0;',\n\t\t'\\t\\tlet z = 2.0 * u;',\n\t\t'\\t\\treturn u * (0.422784328 + z * (0.161233515 + z * (-0.0168380756 + z * (0.00257259863 + z * (-0.000461596384 + z * (0.0000903423133 + z * (-0.0000186399611 + z * (0.00000395054167 + z * (-8.64507570e-7 + z * (2.24574705e-7 + z * -5.08562046e-8))))))))));',\n\t\t'\\t}',\n\t\t'\\tif (value > 0.0) {',\n\t\t'\\t\\tlet p = computeSpecialLogGammaPositive(FloatPair(value, 0.0));',\n\t\t'\\t\\treturn p.head + p.tail;',\n\t\t'\\t}',\n\t\t'\\tlet logSp = computeSpecialLogAbsSinPi(abs(value));',\n\t\t'\\tlet piTerm = subtractDouble(FloatPair(1.1447298526763916, 3.31730086e-8), logSp);',\n\t\t'\\tlet pos = computeSpecialLogGammaPositive(addDouble(FloatPair(1.0, 0.0), FloatPair(-value, 0.0)));',\n\t\t'\\tlet res = subtractDouble(piTerm, pos);',\n\t\t'\\treturn res.head + res.tail;',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialGammaUnit(u: f32) -> f32 {',\n\t\t'\\tlet z = 2.0 * u - 1.0;',\n\t\t'\\treturn 1.0 + u * (1.0 - u) * (-0.455092311 + z * (0.0646768212 + z * (-0.0402788520 + z * (0.0110288402 + z * (-0.00411732029 + z * (0.00134206272 + z * (-0.000455378235 + z * (0.000144674050 + z * (-0.0000483887379 + z * (0.0000232627572 + z * -0.00000775970602))))))))));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialGammaScaled(x: f32, prescale: bool) -> f32 {',\n\t\t'\\tif (x < 1.0) {',\n\t\t'\\t\\tlet g = computeSpecialGammaUnit(x) / x;',\n\t\t'\\t\\treturn select(g, g * 5.421010862427522e-20, prescale);',\n\t\t'\\t}',\n\t\t'\\tif (x <= 2.0) {',\n\t\t'\\t\\tlet g = computeSpecialGammaUnit(x - 1.0);',\n\t\t'\\t\\treturn select(g, g * 5.421010862427522e-20, prescale);',\n\t\t'\\t}',\n\t\t'\\tlet k = u32(floor(x - 1.0));',\n\t\t'\\tlet y = x - f32(k);',\n\t\t'\\tvar acc = FloatPair(computeSpecialGammaUnit(y - 1.0), 0.0);',\n\t\t'\\tvar scaled = false;',\n\t\t'\\tif (prescale) {',\n\t\t'\\t\\tacc = FloatPair(acc.head * 5.421010862427522e-20, 0.0);',\n\t\t'\\t\\tscaled = true;',\n\t\t'\\t}',\n\t\t'\\tvar cur = y;',\n\t\t'\\tfor (var i = 0u; i < k; i += 1u) {',\n\t\t'\\t\\tif (!scaled && acc.head > 1.0e24) {',\n\t\t'\\t\\t\\tacc = FloatPair(acc.head * 5.421010862427522e-20, acc.tail * 5.421010862427522e-20);',\n\t\t'\\t\\t\\tscaled = true;',\n\t\t'\\t\\t}',\n\t\t'\\t\\tlet p = computeExactProduct(acc.head, cur);',\n\t\t'\\t\\tacc = computeExactSum(p.head, p.tail + acc.tail * cur);',\n\t\t'\\t\\tcur = cur + 1.0;',\n\t\t'\\t}',\n\t\t'\\tlet res = acc.head + acc.tail;',\n\t\t'\\tif (scaled && !prescale) {',\n\t\t'\\t\\treturn res * 1.8446744073709552e19;',\n\t\t'\\t}',\n\t\t'\\treturn res;',\n\t\t'}',\n\t\t'',\n\t\t'fn computeGamma(value: f32) -> f32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet mag = bits & 0x7fffffffu;',\n\t\t'\\tlet signBit = bits & 0x80000000u;',\n\t\t'\\tif (mag > 0x7f800000u) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tif (bits == 0x7f800000u) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tif (bits == 0xff800000u) {',\n\t\t'\\t\\treturn bitcast<f32>(0x7fc00000u | (bits & 0u));',\n\t\t'\\t}',\n\t\t'\\tif (mag == 0u) {',\n\t\t'\\t\\treturn bitcast<f32>(0x7f800000u | signBit);',\n\t\t'\\t}',\n\t\t'\\tif ((bits & 0x7f800000u) == 0u) {',\n\t\t'\\t\\tlet norm = scaleSpecialPowerOfTwo(bitcast<f32>(mag), 32i);',\n\t\t'\\t\\tlet inv = 1.0 / norm;',\n\t\t'\\t\\treturn bitcast<f32>(bitcast<u32>(scaleSpecialPowerOfTwo(inv, 32i)) | signBit);',\n\t\t'\\t}',\n\t\t'\\tif (value < 0.0 && value == floor(value)) {',\n\t\t'\\t\\treturn bitcast<f32>(0x7fc00000u | (bits & 0u));',\n\t\t'\\t}',\n\t\t'\\tif (value > 0.0) {',\n\t\t'\\t\\tif (value > 35.041) {',\n\t\t'\\t\\t\\treturn bitcast<f32>(0x7f800000u | (bits & 0u));',\n\t\t'\\t\\t}',\n\t\t'\\t\\treturn computeSpecialGammaScaled(value, false);',\n\t\t'\\t}',\n\t\t'\\tlet sp = computeSinPi(value);',\n\t\t'\\tlet ax = -value;',\n\t\t'\\tif (ax < 1.0) {',\n\t\t'\\t\\treturn 3.14159274 / (sp * computeSpecialGammaUnit(ax));',\n\t\t'\\t}',\n\t\t'\\tif (ax <= 30.0) {',\n\t\t'\\t\\tlet gAx = computeSpecialGammaScaled(ax, false);',\n\t\t'\\t\\tlet denom = multiplyDouble(FloatPair(sp, 0.0), computeExactProduct(ax, gAx));',\n\t\t'\\t\\tlet q = divideDouble(FloatPair(3.1415927410125732, -8.742278012618954e-8), denom);',\n\t\t'\\t\\treturn q.head + q.tail;',\n\t\t'\\t}',\n\t\t'\\tif (ax <= 45.0) {',\n\t\t'\\t\\tlet gScaled = computeSpecialGammaScaled(ax, true);',\n\t\t'\\t\\tlet denom = multiplyDouble(FloatPair(sp, 0.0), computeExactProduct(ax, gScaled));',\n\t\t'\\t\\tlet q = divideDouble(FloatPair(3.1415927410125732, -8.742278012618954e-8), denom);',\n\t\t'\\t\\treturn scaleSpecialPowerOfTwo(q.head + q.tail, -64i);',\n\t\t'\\t}',\n\t\t'\\treturn bitcast<f32>(select(0u, 0x80000000u, sp < 0.0));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeSpecialLogOnePlus(r: FloatPair) -> FloatPair {',\n\t\t'\\tif (r.head <= 0.41421356) {',\n\t\t'\\t\\treturn computeSpecialLogOnePlusSmall(r);',\n\t\t'\\t}',\n\t\t'\\treturn computeSpecialLogPair(addDouble(FloatPair(1.0, 0.0), r));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeLogBeta(left: f32, right: f32) -> f32 {',\n\t\t'\\tlet lb = bitcast<u32>(left);',\n\t\t'\\tlet rb = bitcast<u32>(right);',\n\t\t'\\tif ((lb & 0x7fffffffu) > 0x7f800000u || (rb & 0x7fffffffu) > 0x7f800000u) {',\n\t\t'\\t\\treturn left + right;',\n\t\t'\\t}',\n\t\t'\\tif ((lb & 0x7fffffffu) == 0u || (lb & 0x80000000u) != 0u || (rb & 0x7fffffffu) == 0u || (rb & 0x80000000u) != 0u) {',\n\t\t'\\t\\treturn bitcast<f32>(0x7fc00000u | (lb & 0u));',\n\t\t'\\t}',\n\t\t'\\tif (lb == 0x7f800000u || rb == 0x7f800000u) {',\n\t\t'\\t\\treturn bitcast<f32>(0xff800000u | (lb & 0u));',\n\t\t'\\t}',\n\t\t'\\tlet pBits = min(lb, rb);',\n\t\t'\\tlet qBits = max(lb, rb);',\n\t\t'\\tif ((pBits & 0x7f800000u) == 0u) {',\n\t\t'\\t\\tlet lead = firstLeadingBit(pBits);',\n\t\t'\\t\\tlet norm = bitcast<f32>(((pBits << (23u - lead)) & 0x007fffffu) | 0x3f800000u);',\n\t\t'\\t\\tlet expShift = i32(lead) - 149i;',\n\t\t'\\t\\tlet lnP = addDouble(',\n\t\t'\\t\\t\\tcomputeSpecialLogPair(FloatPair(norm, 0.0)),',\n\t\t'\\t\\t\\tmultiplyDouble(FloatPair(0.6931471824645996, -1.904654299957768e-9), FloatPair(f32(expShift), 0.0)),',\n\t\t'\\t\\t);',\n\t\t'\\t\\tif ((qBits & 0x7f800000u) == 0u) {',\n\t\t'\\t\\t\\tlet ratio = divideDouble(FloatPair(f32(pBits), 0.0), FloatPair(f32(qBits), 0.0));',\n\t\t'\\t\\t\\tlet res = subtractDouble(computeSpecialLogOnePlus(ratio), lnP);',\n\t\t'\\t\\t\\treturn res.head + res.tail;',\n\t\t'\\t\\t}',\n\t\t'\\t\\tif (qBits < 0x0d800000u) {',\n\t\t'\\t\\t\\tlet p64 = bitcast<f32>((u32(expShift + 191i) << 23u) | ((pBits << (23u - lead)) & 0x007fffffu));',\n\t\t'\\t\\t\\tlet q64 = bitcast<f32>(qBits + 0x20000000u);',\n\t\t'\\t\\t\\tlet ratio = divideDouble(FloatPair(p64, 0.0), FloatPair(q64, 0.0));',\n\t\t'\\t\\t\\tlet res = subtractDouble(computeSpecialLogOnePlus(ratio), lnP);',\n\t\t'\\t\\t\\treturn res.head + res.tail;',\n\t\t'\\t\\t}',\n\t\t'\\t\\treturn -(lnP.head + lnP.tail);',\n\t\t'\\t}',\n\t\t'\\tlet p = bitcast<f32>(pBits);',\n\t\t'\\tlet q = bitcast<f32>(qBits);',\n\t\t'\\tif (p == 1.0 && q == 1.0) {',\n\t\t'\\t\\treturn 0.0;',\n\t\t'\\t}',\n\t\t'\\tlet pPair = FloatPair(p, 0.0);',\n\t\t'\\tlet qPair = FloatPair(q, 0.0);',\n\t\t'\\tif (p >= 14.0) {',\n\t\t'\\t\\tlet r = divideDouble(pPair, qPair);',\n\t\t'\\t\\tlet l1pr = computeSpecialLogOnePlus(r);',\n\t\t'\\t\\tlet lr = computeSpecialLogPair(r);',\n\t\t'\\t\\tlet lq = computeSpecialLogPair(qPair);',\n\t\t'\\t\\tvar corr = FloatPair(0.0, 0.0);',\n\t\t'\\t\\tif (p < 1.0e18) {',\n\t\t'\\t\\t\\tcorr = addDouble(corr, computeSpecialStirlingSeries(pPair));',\n\t\t'\\t\\t}',\n\t\t'\\t\\tif (q < 1.0e18) {',\n\t\t'\\t\\t\\tcorr = addDouble(corr, computeSpecialStirlingSeries(qPair));',\n\t\t'\\t\\t\\tcorr = subtractDouble(corr, computeSpecialStirlingSeries(computeExactSum(p, q)));',\n\t\t'\\t\\t}',\n\t\t'\\t\\tvar res = addDouble(FloatPair(0.9189385175704956, 1.56343402e-8), corr);',\n\t\t'\\t\\tres = addDouble(res, multiplyDouble(addDouble(pPair, FloatPair(-0.5, 0.0)), subtractDouble(lr, l1pr)));',\n\t\t'\\t\\tres = subtractDouble(res, multiplyDouble(qPair, l1pr));',\n\t\t'\\t\\tres = subtractDouble(res, FloatPair(0.5 * lq.head, 0.5 * lq.tail));',\n\t\t'\\t\\treturn res.head + res.tail;',\n\t\t'\\t}',\n\t\t'\\tif (q >= 14.0) {',\n\t\t'\\t\\tlet r = divideDouble(pPair, qPair);',\n\t\t'\\t\\tlet l1pr = computeSpecialLogOnePlus(r);',\n\t\t'\\t\\tlet lq = computeSpecialLogPair(qPair);',\n\t\t'\\t\\tvar diff = FloatPair(0.0, 0.0);',\n\t\t'\\t\\tif (r.head < 1.0e-3) {',\n\t\t'\\t\\t\\tlet pr = multiplyDouble(pPair, r);',\n\t\t'\\t\\t\\tlet r2 = multiplyDouble(r, r);',\n\t\t'\\t\\t\\tlet poly = addDouble(',\n\t\t'\\t\\t\\t\\tFloatPair(0.5, 0.0),',\n\t\t'\\t\\t\\t\\taddDouble(',\n\t\t'\\t\\t\\t\\t\\tmultiplyDouble(r, FloatPair(-0.3333333432674408, 9.93410748e-9)),',\n\t\t'\\t\\t\\t\\t\\tmultiplyDouble(r2, FloatPair(0.25 - 0.2 * r.head, 0.0)),',\n\t\t'\\t\\t\\t\\t),',\n\t\t'\\t\\t\\t);',\n\t\t'\\t\\t\\tdiff = multiplyDouble(pr, poly);',\n\t\t'\\t\\t} else {',\n\t\t'\\t\\t\\tdiff = subtractDouble(pPair, multiplyDouble(qPair, l1pr));',\n\t\t'\\t\\t}',\n\t\t'\\t\\tvar corr = FloatPair(0.0, 0.0);',\n\t\t'\\t\\tif (q < 1.0e18) {',\n\t\t'\\t\\t\\tcorr = subtractDouble(computeSpecialStirlingSeries(qPair), computeSpecialStirlingSeries(computeExactSum(p, q)));',\n\t\t'\\t\\t}',\n\t\t'\\t\\tvar res = addDouble(computeSpecialLogGammaPositive(pPair), diff);',\n\t\t'\\t\\tres = addDouble(res, FloatPair(0.5 * l1pr.head, 0.5 * l1pr.tail));',\n\t\t'\\t\\tres = subtractDouble(res, multiplyDouble(pPair, addDouble(lq, l1pr)));',\n\t\t'\\t\\tres = addDouble(res, corr);',\n\t\t'\\t\\treturn res.head + res.tail;',\n\t\t'\\t}',\n\t\t'\\tlet res = subtractDouble(',\n\t\t'\\t\\taddDouble(computeSpecialLogGammaPositive(pPair), computeSpecialLogGammaPositive(qPair)),',\n\t\t'\\t\\tcomputeSpecialLogGammaPositive(computeExactSum(p, q)),',\n\t\t'\\t);',\n\t\t'\\treturn res.head + res.tail;',\n\t\t'}',\n\t\t'',\n\t\t'fn computeScaledBesselZero(value: f32) -> f32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet mag = bits & 0x7fffffffu;',\n\t\t'\\tif (mag > 0x7f800000u) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tif (mag == 0x7f800000u) {',\n\t\t'\\t\\treturn 0.0;',\n\t\t'\\t}',\n\t\t'\\tif ((bits & 0x7f800000u) == 0u) {',\n\t\t'\\t\\treturn 1.0;',\n\t\t'\\t}',\n\t\t'\\tlet ax = abs(value);',\n\t\t'\\tif (ax <= 1.5) {',\n\t\t'\\t\\tlet z = ax * 1.33333337 - 1.0;',\n\t\t'\\t\\treturn 0.541165233 + z * (-0.263458073 + z * (0.126385629 + z * (-0.0486531071 + z * (0.0152392546 + z * (-0.00399184506 + z * (0.000895561709 + z * (-0.000175179142 + z * (0.0000304388795 + z * (-0.00000499506996 + z * 7.00807561e-7)))))))));',\n\t\t'\\t}',\n\t\t'\\tif (ax <= 3.75) {',\n\t\t'\\t\\tlet z = (ax - 2.625) * 0.888888896;',\n\t\t'\\t\\treturn 0.262444794 + z * (-0.0655643344 + z * (0.0245414320 + z * (-0.00961217470 + z * (0.00356631307 + z * (-0.00120580231 + z * (0.000366819324 + z * (-0.0000997558091 + z * (0.0000247219195 + z * (-0.00000621296840 + z * 0.00000125816814)))))))));',\n\t\t'\\t}',\n\t\t'\\tif (ax <= 8.0) {',\n\t\t'\\t\\tlet z = (ax - 5.875) * 0.470588237;',\n\t\t'\\t\\treturn 0.168513983 + z * (-0.0320951305 + z * (0.00924521033 + z * (-0.00299210730 + z * (0.00103014917 + z * (-0.000369814195 + z * (0.000135148104 + z * (-0.0000471700405 + z * (0.0000171751908 + z * (-0.00000841290694 + z * 0.00000274606259)))))))));',\n\t\t'\\t}',\n\t\t'\\tlet u = 8.0 / ax;',\n\t\t'\\tlet z = 2.0 * u - 1.0;',\n\t\t'\\treturn (0.402176499 + z * (0.00336055201 + z * (0.000136216084 + z * (0.0000111436439 + z * (0.00000148358868 + z * (2.93553455e-7 + z * (9.00340495e-8 + z * (4.99880137e-8 + z * (1.93552907e-8 + z * (-8.16245027e-9 + z * -7.13418746e-9)))))))))) / sqrt(ax);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeBesselZero(value: f32) -> f32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet mag = bits & 0x7fffffffu;',\n\t\t'\\tif (mag > 0x7f800000u) {',\n\t\t'\\t\\treturn value;',\n\t\t'\\t}',\n\t\t'\\tif ((bits & 0x7f800000u) == 0u) {',\n\t\t'\\t\\treturn 1.0;',\n\t\t'\\t}',\n\t\t'\\tlet ax = abs(value);',\n\t\t'\\tif (mag == 0x7f800000u || ax > 92.0) {',\n\t\t'\\t\\treturn bitcast<f32>(0x7f800000u | (bits & 0u));',\n\t\t'\\t}',\n\t\t'\\tif (ax <= 3.75) {',\n\t\t'\\t\\tlet u = 0.25 * ax * ax;',\n\t\t'\\t\\treturn 1.0 + u * (1.0 + u * (0.25 + u * (0.027777778 + u * (0.00173611112 + u * (6.94444461e-5 + u * (1.92901238e-6 + u * (3.93675987e-8 + u * (6.15118725e-10 + u * (7.59405832e-12 + u * (7.59405832e-14 + u * (6.27608126e-16 + u * 4.35838976e-18)))))))))));',\n\t\t'\\t}',\n\t\t'\\tlet scaled = computeScaledBesselZero(ax);',\n\t\t'\\treturn computeSpecialExpScaled(ax, 0.0, scaled);',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([WGSL_EFT, WGSL_DOUBLE]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment of complex arithmetic (`vec2f` as real and imaginary) and radix-2 FFT butterfly helpers.\n *\n * @remarks\n * Declares `uses: [WGSL_MATH, WGSL_SPECIAL]` (`computeHypot`, `computeCosPi`, `computeSinPi`),\n * executes `0` `fma()` calls, declares `struct ComplexPair { even: vec2f, odd: vec2f }`, and\n * provides `conjugateComplex`, `multiplyComplex`, overflow-safe Smith `divideComplex`,\n * `computeComplexSqrt`, `computeComplexExp`, `computeComplexLog`, `computeTwiddle`, and\n * `computeRadixButterfly`. Callers compute magnitude directly with `computeHypot(value.x, value.y)`.\n * Domain boundaries: `divideComplex` prescales magnitudes `> 1.0e37` to avoid intermediate\n * overflow, returns `vec2f(0.0, 0.0)` for finite dividends over `(±Infinity, ±Infinity)`, and\n * produces IEEE division-by-zero components at `(0.0, 0.0)`; `computeComplexSqrt` prescales tiny\n * and subnormal inputs (`2^64`, post-scaled by `2^-32`) and large finite inputs (`> 1.0e37`,\n * `0.25`, post-scaled by `2.0`), taking the principal branch on the negative real axis;\n * `computeComplexLog` prescales large finite inputs (`> 2^60`, `2^-66`) and tiny nonzero inputs\n * (`2^64`) to avoid intermediate `computeHypot` and `atan2` overflow or FTZ underflow, yielding\n * `(-Infinity, atan2)` at zero; and `computeTwiddle` returns `vec2f(1.0, 0.0)` when `count == 0u`.\n * `divideWGSLComplex` is the TypeScript twin of `divideComplex`.\n *\n * @example\n * ```ts\n * WGSL_COMPLEX.name // 'complex'\n * ```\n */\nexport const WGSL_COMPLEX: WGSLFragment = Object.freeze({\n\tname: 'complex',\n\tsource: [\n\t\t'struct ComplexPair {',\n\t\t'\\teven: vec2f,',\n\t\t'\\todd: vec2f,',\n\t\t'}',\n\t\t'',\n\t\t'fn conjugateComplex(value: vec2f) -> vec2f {',\n\t\t'\\treturn vec2f(value.x, -value.y);',\n\t\t'}',\n\t\t'',\n\t\t'fn multiplyComplex(left: vec2f, right: vec2f) -> vec2f {',\n\t\t'\\treturn vec2f(left.x * right.x - left.y * right.y, left.x * right.y + left.y * right.x);',\n\t\t'}',\n\t\t'',\n\t\t'fn divideComplex(left: vec2f, right: vec2f) -> vec2f {',\n\t\t'\\tvar a = left.x;',\n\t\t'\\tvar b = left.y;',\n\t\t'\\tvar c = right.x;',\n\t\t'\\tvar d = right.y;',\n\t\t'\\tlet denomMax = max(abs(c), abs(d));',\n\t\t'\\tif (denomMax == 0.0) {',\n\t\t'\\t\\treturn vec2f(a / c, b / c);',\n\t\t'\\t}',\n\t\t'\\tlet numMax = max(abs(a), abs(b));',\n\t\t'\\tif ((bitcast<u32>(c) & 0x7fffffffu) == 0x7f800000u && (bitcast<u32>(d) & 0x7fffffffu) == 0x7f800000u && (bitcast<u32>(numMax) & 0x7f800000u) != 0x7f800000u) {',\n\t\t'\\t\\treturn vec2f(0.0, 0.0);',\n\t\t'\\t}',\n\t\t'\\tif (denomMax > 1.0e37 && (bitcast<u32>(denomMax) & 0x7f800000u) != 0x7f800000u) {',\n\t\t'\\t\\tc = c * 0.25;',\n\t\t'\\t\\td = d * 0.25;',\n\t\t'\\t\\ta = a * 0.25;',\n\t\t'\\t\\tb = b * 0.25;',\n\t\t'\\t} else if (numMax > 1.0e37 && (bitcast<u32>(numMax) & 0x7f800000u) != 0x7f800000u) {',\n\t\t'\\t\\ta = a * 0.25;',\n\t\t'\\t\\tb = b * 0.25;',\n\t\t'\\t\\tif (abs(c) >= abs(d)) {',\n\t\t'\\t\\t\\tlet ratio = d / c;',\n\t\t'\\t\\t\\tlet denom = c + d * ratio;',\n\t\t'\\t\\t\\treturn vec2f(((a + b * ratio) / denom) * 4.0, ((b - a * ratio) / denom) * 4.0);',\n\t\t'\\t\\t}',\n\t\t'\\t\\tlet ratio = c / d;',\n\t\t'\\t\\tlet denom = d + c * ratio;',\n\t\t'\\t\\treturn vec2f(((a * ratio + b) / denom) * 4.0, ((b * ratio - a) / denom) * 4.0);',\n\t\t'\\t}',\n\t\t'\\tif (abs(c) >= abs(d)) {',\n\t\t'\\t\\tlet ratio = d / c;',\n\t\t'\\t\\tlet denom = c + d * ratio;',\n\t\t'\\t\\treturn vec2f((a + b * ratio) / denom, (b - a * ratio) / denom);',\n\t\t'\\t}',\n\t\t'\\tlet ratio = c / d;',\n\t\t'\\tlet denom = d + c * ratio;',\n\t\t'\\treturn vec2f((a * ratio + b) / denom, (b * ratio - a) / denom);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeComplexSqrt(value: vec2f) -> vec2f {',\n\t\t'\\tlet bx = bitcast<u32>(value.x);',\n\t\t'\\tlet by = bitcast<u32>(value.y);',\n\t\t'\\tlet mx = bx & 0x7fffffffu;',\n\t\t'\\tlet my = by & 0x7fffffffu;',\n\t\t'\\tif (my == 0x7f800000u) {',\n\t\t'\\t\\treturn vec2f(abs(value.y), value.y);',\n\t\t'\\t}',\n\t\t'\\tif (mx == 0u && my == 0u) {',\n\t\t'\\t\\treturn vec2f(0.0, value.y);',\n\t\t'\\t}',\n\t\t'\\tvar x = value.x;',\n\t\t'\\tvar y = value.y;',\n\t\t'\\tvar postScale = 1.0;',\n\t\t'\\tif (mx < 0x3f800000u && my < 0x3f800000u && (mx < 0x04000000u || my < 0x04000000u)) {',\n\t\t'\\t\\tx = scaleSpecialPowerOfTwo(x, 64i);',\n\t\t'\\t\\ty = scaleSpecialPowerOfTwo(y, 64i);',\n\t\t'\\t\\tpostScale = 2.3283064365386963e-10;',\n\t\t'\\t} else if (mx < 0x7f800000u && my < 0x7f800000u && (mx > 0x7cf0bdc2u || my > 0x7cf0bdc2u)) {',\n\t\t'\\t\\tx = x * 0.25;',\n\t\t'\\t\\ty = y * 0.25;',\n\t\t'\\t\\tpostScale = 2.0;',\n\t\t'\\t}',\n\t\t'\\tlet mag = computeHypot(x, y);',\n\t\t'\\tif (x >= 0.0) {',\n\t\t'\\t\\tlet t = sqrt(0.5 * mag + 0.5 * x);',\n\t\t'\\t\\treturn vec2f(t * postScale, (y / (2.0 * t)) * postScale);',\n\t\t'\\t}',\n\t\t'\\tlet t = sqrt(0.5 * mag - 0.5 * x);',\n\t\t'\\tlet imag = select(-t, t, (by & 0x80000000u) == 0u);',\n\t\t'\\treturn vec2f((abs(y) / (2.0 * t)) * postScale, imag * postScale);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeComplexExp(value: vec2f) -> vec2f {',\n\t\t'\\tlet scale = exp(value.x);',\n\t\t'\\tif (value.y == 0.0) {',\n\t\t'\\t\\treturn vec2f(scale, value.y);',\n\t\t'\\t}',\n\t\t'\\treturn vec2f(scale * cos(value.y), scale * sin(value.y));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeComplexLog(value: vec2f) -> vec2f {',\n\t\t'\\tlet bx = bitcast<u32>(value.x);',\n\t\t'\\tlet by = bitcast<u32>(value.y);',\n\t\t'\\tlet mx = bx & 0x7fffffffu;',\n\t\t'\\tlet my = by & 0x7fffffffu;',\n\t\t'\\tif (mx < 0x7f800000u && my < 0x7f800000u) {',\n\t\t'\\t\\tif (mx > 0x5d800000u || my > 0x5d800000u) {',\n\t\t'\\t\\t\\tlet sx = value.x * 1.3552527156068805e-20;',\n\t\t'\\t\\t\\tlet sy = value.y * 1.3552527156068805e-20;',\n\t\t'\\t\\t\\treturn vec2f(log(computeHypot(sx, sy)) + 45.74771499633789, atan2(sy, sx));',\n\t\t'\\t\\t}',\n\t\t'\\t\\tif (mx < 0x04000000u && my < 0x04000000u && (mx != 0u || my != 0u)) {',\n\t\t'\\t\\t\\tlet sx = scaleSpecialPowerOfTwo(value.x, 64i);',\n\t\t'\\t\\t\\tlet sy = scaleSpecialPowerOfTwo(value.y, 64i);',\n\t\t'\\t\\t\\treturn vec2f(log(computeHypot(sx, sy)) - 44.361419677734375, atan2(sy, sx));',\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t'\\treturn vec2f(log(computeHypot(value.x, value.y)), atan2(value.y, value.x));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeTwiddle(index: u32, count: u32, inverse: bool) -> vec2f {',\n\t\t'\\tif (count == 0u) {',\n\t\t'\\t\\treturn vec2f(1.0, 0.0);',\n\t\t'\\t}',\n\t\t'\\tlet angle = 2.0 * f32(index % count) / f32(count);',\n\t\t'\\tlet cosine = computeCosPi(angle);',\n\t\t'\\tlet sine = computeSinPi(angle);',\n\t\t'\\treturn vec2f(cosine, select(-sine, sine, inverse || sine == 0.0));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeRadixButterfly(even: vec2f, odd: vec2f, twiddle: vec2f) -> ComplexPair {',\n\t\t'\\tlet rotated = multiplyComplex(odd, twiddle);',\n\t\t'\\treturn ComplexPair(even + rotated, even - rotated);',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([WGSL_MATH, WGSL_SPECIAL]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment of scalar-last (`xyzw`) unit quaternion algebra, vector rotation, shortest-path slerp, and rotation matrix conversion.\n *\n * @remarks\n * Declares `uses: []`, executes `0` `fma()` calls, and provides `conjugateQuaternion`,\n * `invertQuaternion`, `multiplyQuaternion`, `rotateVector`, `buildAxisQuaternion`,\n * `interpolateQuaternion`, and `computeRotationMatrix`. Domain boundaries: `rotateVector`,\n * `interpolateQuaternion`, and `computeRotationMatrix` expect unit quaternions; `invertQuaternion`\n * rescales by the max component and returns `vec4f(0.0)` on a zero input; `buildAxisQuaternion`\n * returns identity `vec4f(0.0, 0.0, 0.0, 1.0)` when `axis` has zero length; and\n * `interpolateQuaternion` takes the shortest path (`dot < 0.0` flips `end`) and switches to\n * normalized linear blending when `cosTheta > 0.9995`. Takes neither `Invocation` nor `Dispatch`\n * and declares no workgroup storage. `multiplyWGSLQuaternion` and `rotateWGSLVector` are its\n * TypeScript twins.\n *\n * @example\n * ```ts\n * WGSL_QUATERNION.name // 'quaternion'\n * ```\n */\nexport const WGSL_QUATERNION: WGSLFragment = Object.freeze({\n\tname: 'quaternion',\n\tsource: [\n\t\t'fn conjugateQuaternion(value: vec4f) -> vec4f {',\n\t\t'\\treturn vec4f(-value.xyz, value.w);',\n\t\t'}',\n\t\t'',\n\t\t'fn invertQuaternion(value: vec4f) -> vec4f {',\n\t\t'\\tlet scale = max(max(abs(value.x), abs(value.y)), max(abs(value.z), abs(value.w)));',\n\t\t'\\tif (scale == 0.0) {',\n\t\t'\\t\\treturn vec4f(0.0, 0.0, 0.0, 0.0);',\n\t\t'\\t}',\n\t\t'\\tlet unit = value / scale;',\n\t\t'\\treturn conjugateQuaternion(unit) / (dot(unit, unit) * scale);',\n\t\t'}',\n\t\t'',\n\t\t'fn multiplyQuaternion(left: vec4f, right: vec4f) -> vec4f {',\n\t\t'\\treturn vec4f(',\n\t\t'\\t\\tleft.w * right.x + left.x * right.w + left.y * right.z - left.z * right.y,',\n\t\t'\\t\\tleft.w * right.y - left.x * right.z + left.y * right.w + left.z * right.x,',\n\t\t'\\t\\tleft.w * right.z + left.x * right.y - left.y * right.x + left.z * right.w,',\n\t\t'\\t\\tleft.w * right.w - left.x * right.x - left.y * right.y - left.z * right.z,',\n\t\t'\\t);',\n\t\t'}',\n\t\t'',\n\t\t'fn rotateVector(rotation: vec4f, vector: vec3f) -> vec3f {',\n\t\t'\\tlet t = 2.0 * cross(rotation.xyz, vector);',\n\t\t'\\treturn vector + rotation.w * t + cross(rotation.xyz, t);',\n\t\t'}',\n\t\t'',\n\t\t'fn buildAxisQuaternion(axis: vec3f, angle: f32) -> vec4f {',\n\t\t'\\tlet norm = length(axis);',\n\t\t'\\tif (norm == 0.0) {',\n\t\t'\\t\\treturn vec4f(0.0, 0.0, 0.0, 1.0);',\n\t\t'\\t}',\n\t\t'\\tlet halfAngle = 0.5 * angle;',\n\t\t'\\treturn vec4f((axis / norm) * sin(halfAngle), cos(halfAngle));',\n\t\t'}',\n\t\t'',\n\t\t'fn interpolateQuaternion(start: vec4f, end: vec4f, factor: f32) -> vec4f {',\n\t\t'\\tvar cosTheta = dot(start, end);',\n\t\t'\\tvar adjusted = end;',\n\t\t'\\tif (cosTheta < 0.0) {',\n\t\t'\\t\\tcosTheta = -cosTheta;',\n\t\t'\\t\\tadjusted = -end;',\n\t\t'\\t}',\n\t\t'\\tif (cosTheta > 0.9995) {',\n\t\t'\\t\\tlet blended = start + factor * (adjusted - start);',\n\t\t'\\t\\tlet norm = length(blended);',\n\t\t'\\t\\treturn select(vec4f(0.0, 0.0, 0.0, 1.0), blended / norm, norm > 0.0);',\n\t\t'\\t}',\n\t\t'\\tlet theta = acos(min(cosTheta, 1.0));',\n\t\t'\\tlet sinTheta = sin(theta);',\n\t\t'\\tlet weightStart = sin((1.0 - factor) * theta) / sinTheta;',\n\t\t'\\tlet weightEnd = sin(factor * theta) / sinTheta;',\n\t\t'\\treturn weightStart * start + weightEnd * adjusted;',\n\t\t'}',\n\t\t'',\n\t\t'fn computeRotationMatrix(rotation: vec4f) -> mat3x3f {',\n\t\t'\\tlet x2 = rotation.x + rotation.x;',\n\t\t'\\tlet y2 = rotation.y + rotation.y;',\n\t\t'\\tlet z2 = rotation.z + rotation.z;',\n\t\t'\\tlet xx = rotation.x * x2;',\n\t\t'\\tlet xy = rotation.x * y2;',\n\t\t'\\tlet xz = rotation.x * z2;',\n\t\t'\\tlet yy = rotation.y * y2;',\n\t\t'\\tlet yz = rotation.y * z2;',\n\t\t'\\tlet zz = rotation.z * z2;',\n\t\t'\\tlet wx = rotation.w * x2;',\n\t\t'\\tlet wy = rotation.w * y2;',\n\t\t'\\tlet wz = rotation.w * z2;',\n\t\t'\\treturn mat3x3f(',\n\t\t'\\t\\tvec3f(1.0 - (yy + zz), xy + wz, xz - wy),',\n\t\t'\\t\\tvec3f(xy - wz, 1.0 - (xx + zz), yz + wx),',\n\t\t'\\t\\tvec3f(xz + wy, yz - wx, 1.0 - (xx + yy)),',\n\t\t'\\t);',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment of forward-mode dual-number automatic differentiation (`vec2f` as primal and tangent).\n *\n * @remarks\n * Declares `uses: [WGSL_MATH]` (`computeSigmoid`), executes `0` `fma()` calls, and provides\n * `multiplyDual`, `divideDual`, `computeDualSqrt`, `computeDualExp`, `computeDualLog`,\n * `computeDualPow`, `computeDualSin`, `computeDualCos`, and `computeDualSigmoid`. Domain\n * boundaries: requires finite inputs inside each elementary function's differentiable domain\n * (`right.x != 0.0` for `divideDual`, `value.x > 0.0` for `computeDualSqrt` and `computeDualLog`,\n * `base.x > 0.0` for `computeDualPow` with every `exponent` other than `0.0` and `1.0`, matching\n * WGSL `pow`; `exponent == 0.0` returns `vec2f(1.0, 0.0)` and `exponent == 1.0` returns `base`). Takes neither `Invocation` nor `Dispatch` and declares no\n * workgroup storage.\n *\n * @example\n * ```ts\n * WGSL_DUAL.name // 'dual'\n * ```\n */\nexport const WGSL_DUAL: WGSLFragment = Object.freeze({\n\tname: 'dual',\n\tsource: [\n\t\t'fn multiplyDual(left: vec2f, right: vec2f) -> vec2f {',\n\t\t'\\treturn vec2f(left.x * right.x, left.x * right.y + left.y * right.x);',\n\t\t'}',\n\t\t'',\n\t\t'fn divideDual(left: vec2f, right: vec2f) -> vec2f {',\n\t\t'\\tlet quotient = left.x / right.x;',\n\t\t'\\treturn vec2f(quotient, (left.y - quotient * right.y) / right.x);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeDualSqrt(value: vec2f) -> vec2f {',\n\t\t'\\tlet root = sqrt(value.x);',\n\t\t'\\treturn vec2f(root, value.y / (2.0 * root));',\n\t\t'}',\n\t\t'',\n\t\t'fn computeDualExp(value: vec2f) -> vec2f {',\n\t\t'\\tlet primal = exp(value.x);',\n\t\t'\\treturn vec2f(primal, primal * value.y);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeDualLog(value: vec2f) -> vec2f {',\n\t\t'\\treturn vec2f(log(value.x), value.y / value.x);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeDualPow(base: vec2f, exponent: f32) -> vec2f {',\n\t\t'\\tif (exponent == 0.0) {',\n\t\t'\\t\\treturn vec2f(1.0, 0.0);',\n\t\t'\\t}',\n\t\t'\\tif (exponent == 1.0) {',\n\t\t'\\t\\treturn base;',\n\t\t'\\t}',\n\t\t'\\treturn vec2f(pow(base.x, exponent), exponent * pow(base.x, exponent - 1.0) * base.y);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeDualSin(value: vec2f) -> vec2f {',\n\t\t'\\treturn vec2f(sin(value.x), cos(value.x) * value.y);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeDualCos(value: vec2f) -> vec2f {',\n\t\t'\\treturn vec2f(cos(value.x), -sin(value.x) * value.y);',\n\t\t'}',\n\t\t'',\n\t\t'fn computeDualSigmoid(value: vec2f) -> vec2f {',\n\t\t'\\tlet primal = computeSigmoid(value.x);',\n\t\t'\\treturn vec2f(primal, primal * (1.0 - primal) * value.y);',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([WGSL_MATH]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment of small dense column-major matrix inversion (`2x2`, `3x3`, `4x4`), partial-pivoted `3x3` linear solve, and `3x3` Cholesky factorization.\n *\n * @remarks\n * Declares `uses: []`, executes `0` `fma()` calls, and provides `invertMatrix2`, `invertMatrix3`,\n * `invertMatrix4`, `solveMatrix3`, and `factorCholesky3`. Domain boundaries: `invertMatrix2`,\n * `invertMatrix3`, `invertMatrix4`, and `solveMatrix3` require non-singular column-major matrices\n * (singular inputs produce IEEE division-by-zero non-finite entries); `factorCholesky3` reads the\n * lower triangle and diagonal and returns a lower-triangular factor `L` with runtime-masked `NaN`\n * on the diagonal when the input is not symmetric positive definite. `invertWGSLMatrix3` is the\n * TypeScript twin of `invertMatrix3`.\n *\n * @example\n * ```ts\n * WGSL_MATRIX.name // 'matrix'\n * ```\n */\nexport const WGSL_MATRIX: WGSLFragment = Object.freeze({\n\tname: 'matrix',\n\tsource: [\n\t\t'fn invertMatrix2(matrix: mat2x2f) -> mat2x2f {',\n\t\t'\\tlet det = matrix[0].x * matrix[1].y - matrix[1].x * matrix[0].y;',\n\t\t'\\tlet invDet = 1.0 / det;',\n\t\t'\\treturn mat2x2f(',\n\t\t'\\t\\tvec2f(matrix[1].y, -matrix[0].y) * invDet,',\n\t\t'\\t\\tvec2f(-matrix[1].x, matrix[0].x) * invDet,',\n\t\t'\\t);',\n\t\t'}',\n\t\t'',\n\t\t'fn invertMatrix3(matrix: mat3x3f) -> mat3x3f {',\n\t\t'\\tlet c0 = matrix[0];',\n\t\t'\\tlet c1 = matrix[1];',\n\t\t'\\tlet c2 = matrix[2];',\n\t\t'\\tlet r0 = cross(c1, c2);',\n\t\t'\\tlet r1 = cross(c2, c0);',\n\t\t'\\tlet r2 = cross(c0, c1);',\n\t\t'\\tlet invDet = 1.0 / dot(c0, r0);',\n\t\t'\\treturn mat3x3f(',\n\t\t'\\t\\tvec3f(r0.x, r1.x, r2.x) * invDet,',\n\t\t'\\t\\tvec3f(r0.y, r1.y, r2.y) * invDet,',\n\t\t'\\t\\tvec3f(r0.z, r1.z, r2.z) * invDet,',\n\t\t'\\t);',\n\t\t'}',\n\t\t'',\n\t\t'fn invertMatrix4(matrix: mat4x4f) -> mat4x4f {',\n\t\t'\\tlet c0 = matrix[0];',\n\t\t'\\tlet c1 = matrix[1];',\n\t\t'\\tlet c2 = matrix[2];',\n\t\t'\\tlet c3 = matrix[3];',\n\t\t'\\tlet s0 = c0.x * c1.y - c1.x * c0.y;',\n\t\t'\\tlet s1 = c0.x * c2.y - c2.x * c0.y;',\n\t\t'\\tlet s2 = c0.x * c3.y - c3.x * c0.y;',\n\t\t'\\tlet s3 = c1.x * c2.y - c2.x * c1.y;',\n\t\t'\\tlet s4 = c1.x * c3.y - c3.x * c1.y;',\n\t\t'\\tlet s5 = c2.x * c3.y - c3.x * c2.y;',\n\t\t'\\tlet t5 = c2.z * c3.w - c3.z * c2.w;',\n\t\t'\\tlet t4 = c1.z * c3.w - c3.z * c1.w;',\n\t\t'\\tlet t3 = c1.z * c2.w - c2.z * c1.w;',\n\t\t'\\tlet t2 = c0.z * c3.w - c3.z * c0.w;',\n\t\t'\\tlet t1 = c0.z * c2.w - c2.z * c0.w;',\n\t\t'\\tlet t0 = c0.z * c1.w - c1.z * c0.w;',\n\t\t'\\tlet invDet = 1.0 / (s0 * t5 - s1 * t4 + s2 * t3 + s3 * t2 - s4 * t1 + s5 * t0);',\n\t\t'\\tlet r0 = vec4f(',\n\t\t'\\t\\tc1.y * t5 - c2.y * t4 + c3.y * t3,',\n\t\t'\\t\\t-c1.x * t5 + c2.x * t4 - c3.x * t3,',\n\t\t'\\t\\tc1.w * s5 - c2.w * s4 + c3.w * s3,',\n\t\t'\\t\\t-c1.z * s5 + c2.z * s4 - c3.z * s3,',\n\t\t'\\t);',\n\t\t'\\tlet r1 = vec4f(',\n\t\t'\\t\\t-c0.y * t5 + c2.y * t2 - c3.y * t1,',\n\t\t'\\t\\tc0.x * t5 - c2.x * t2 + c3.x * t1,',\n\t\t'\\t\\t-c0.w * s5 + c2.w * s2 - c3.w * s1,',\n\t\t'\\t\\tc0.z * s5 - c2.z * s2 + c3.z * s1,',\n\t\t'\\t);',\n\t\t'\\tlet r2 = vec4f(',\n\t\t'\\t\\tc0.y * t4 - c1.y * t2 + c3.y * t0,',\n\t\t'\\t\\t-c0.x * t4 + c1.x * t2 - c3.x * t0,',\n\t\t'\\t\\tc0.w * s4 - c1.w * s2 + c3.w * s0,',\n\t\t'\\t\\t-c0.z * s4 + c1.z * s2 - c3.z * s0,',\n\t\t'\\t);',\n\t\t'\\tlet r3 = vec4f(',\n\t\t'\\t\\t-c0.y * t3 + c1.y * t1 - c2.y * t0,',\n\t\t'\\t\\tc0.x * t3 - c1.x * t1 + c2.x * t0,',\n\t\t'\\t\\t-c0.w * s3 + c1.w * s1 - c2.w * s0,',\n\t\t'\\t\\tc0.z * s3 - c1.z * s1 + c2.z * s0,',\n\t\t'\\t);',\n\t\t'\\treturn mat4x4f(',\n\t\t'\\t\\tvec4f(r0.x, r1.x, r2.x, r3.x) * invDet,',\n\t\t'\\t\\tvec4f(r0.y, r1.y, r2.y, r3.y) * invDet,',\n\t\t'\\t\\tvec4f(r0.z, r1.z, r2.z, r3.z) * invDet,',\n\t\t'\\t\\tvec4f(r0.w, r1.w, r2.w, r3.w) * invDet,',\n\t\t'\\t);',\n\t\t'}',\n\t\t'',\n\t\t'fn solveMatrix3(matrix: mat3x3f, vector: vec3f) -> vec3f {',\n\t\t'\\tvar r0 = vec4f(matrix[0].x, matrix[1].x, matrix[2].x, vector.x);',\n\t\t'\\tvar r1 = vec4f(matrix[0].y, matrix[1].y, matrix[2].y, vector.y);',\n\t\t'\\tvar r2 = vec4f(matrix[0].z, matrix[1].z, matrix[2].z, vector.z);',\n\t\t'\\tif (abs(r1.x) > abs(r0.x)) {',\n\t\t'\\t\\tlet swap = r0;',\n\t\t'\\t\\tr0 = r1;',\n\t\t'\\t\\tr1 = swap;',\n\t\t'\\t}',\n\t\t'\\tif (abs(r2.x) > abs(r0.x)) {',\n\t\t'\\t\\tlet swap = r0;',\n\t\t'\\t\\tr0 = r2;',\n\t\t'\\t\\tr2 = swap;',\n\t\t'\\t}',\n\t\t'\\tr1 = r1 - (r1.x / r0.x) * r0;',\n\t\t'\\tr2 = r2 - (r2.x / r0.x) * r0;',\n\t\t'\\tif (abs(r2.y) > abs(r1.y)) {',\n\t\t'\\t\\tlet swap = r1;',\n\t\t'\\t\\tr1 = r2;',\n\t\t'\\t\\tr2 = swap;',\n\t\t'\\t}',\n\t\t'\\tr2 = r2 - (r2.y / r1.y) * r1;',\n\t\t'\\tlet z = r2.w / r2.z;',\n\t\t'\\tlet y = (r1.w - r1.z * z) / r1.y;',\n\t\t'\\tlet x = (r0.w - r0.y * y - r0.z * z) / r0.x;',\n\t\t'\\treturn vec3f(x, y, z);',\n\t\t'}',\n\t\t'',\n\t\t'fn factorCholesky3(matrix: mat3x3f) -> mat3x3f {',\n\t\t'\\tlet nan = bitcast<f32>(0x7fc00000u | (bitcast<u32>(matrix[0].x) & 0u));',\n\t\t'\\tlet a00 = matrix[0].x;',\n\t\t'\\tif (!(a00 > 0.0)) {',\n\t\t'\\t\\treturn mat3x3f(vec3f(nan, 0.0, 0.0), vec3f(0.0, nan, 0.0), vec3f(0.0, 0.0, nan));',\n\t\t'\\t}',\n\t\t'\\tlet l00 = sqrt(a00);',\n\t\t'\\tlet l10 = matrix[0].y / l00;',\n\t\t'\\tlet l20 = matrix[0].z / l00;',\n\t\t'\\tlet d11 = matrix[1].y - l10 * l10;',\n\t\t'\\tif (!(d11 > 0.0)) {',\n\t\t'\\t\\treturn mat3x3f(vec3f(nan, 0.0, 0.0), vec3f(0.0, nan, 0.0), vec3f(0.0, 0.0, nan));',\n\t\t'\\t}',\n\t\t'\\tlet l11 = sqrt(d11);',\n\t\t'\\tlet l21 = (matrix[1].z - l20 * l10) / l11;',\n\t\t'\\tlet d22 = matrix[2].z - l20 * l20 - l21 * l21;',\n\t\t'\\tif (!(d22 > 0.0)) {',\n\t\t'\\t\\treturn mat3x3f(vec3f(nan, 0.0, 0.0), vec3f(0.0, nan, 0.0), vec3f(0.0, 0.0, nan));',\n\t\t'\\t}',\n\t\t'\\tlet l22 = sqrt(d22);',\n\t\t'\\treturn mat3x3f(vec3f(l00, l10, l20), vec3f(0.0, l11, l21), vec3f(0.0, 0.0, l22));',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment of 2D (`16` bits per axis) and 3D (`10` bits per axis) Morton Z-order curve bit-interleaving helpers.\n *\n * @remarks\n * Declares `uses: []`, executes `0` `fma()` calls (pure integer bit operations), and provides\n * `encodeMorton2`, `decodeMorton2`, `encodeMorton3`, and `decodeMorton3`, together with\n * `spreadMorton2`, `compactMorton2`, `spreadMorton3`, and `compactMorton3`. Domain boundaries:\n * `encodeMorton2` masks each `point` component to `0..65535` and `decodeMorton2` inverts every\n * 32-bit `code`; `encodeMorton3` masks each `point` component to `0..1023` into a 30-bit code and\n * `decodeMorton3` reads the low 30 bits of `code`. `encodeWGSLMorton2`, `decodeWGSLMorton2`,\n * `encodeWGSLMorton3`, and `decodeWGSLMorton3` are its TypeScript twins.\n *\n * @example\n * ```ts\n * WGSL_MORTON.name // 'morton'\n * ```\n */\nexport const WGSL_MORTON: WGSLFragment = Object.freeze({\n\tname: 'morton',\n\tsource: [\n\t\t'fn spreadMorton2(value: u32) -> u32 {',\n\t\t'\\tvar v = value & 0x0000ffffu;',\n\t\t'\\tv = (v | (v << 8u)) & 0x00ff00ffu;',\n\t\t'\\tv = (v | (v << 4u)) & 0x0f0f0f0fu;',\n\t\t'\\tv = (v | (v << 2u)) & 0x33333333u;',\n\t\t'\\tv = (v | (v << 1u)) & 0x55555555u;',\n\t\t'\\treturn v;',\n\t\t'}',\n\t\t'',\n\t\t'fn compactMorton2(value: u32) -> u32 {',\n\t\t'\\tvar v = value & 0x55555555u;',\n\t\t'\\tv = (v | (v >> 1u)) & 0x33333333u;',\n\t\t'\\tv = (v | (v >> 2u)) & 0x0f0f0f0fu;',\n\t\t'\\tv = (v | (v >> 4u)) & 0x00ff00ffu;',\n\t\t'\\tv = (v | (v >> 8u)) & 0x0000ffffu;',\n\t\t'\\treturn v;',\n\t\t'}',\n\t\t'',\n\t\t'fn encodeMorton2(point: vec2u) -> u32 {',\n\t\t'\\treturn spreadMorton2(point.x) | (spreadMorton2(point.y) << 1u);',\n\t\t'}',\n\t\t'',\n\t\t'fn decodeMorton2(code: u32) -> vec2u {',\n\t\t'\\treturn vec2u(compactMorton2(code), compactMorton2(code >> 1u));',\n\t\t'}',\n\t\t'',\n\t\t'fn spreadMorton3(value: u32) -> u32 {',\n\t\t'\\tvar v = value & 0x000003ffu;',\n\t\t'\\tv = (v | (v << 16u)) & 0x030000ffu;',\n\t\t'\\tv = (v | (v << 8u)) & 0x0300f00fu;',\n\t\t'\\tv = (v | (v << 4u)) & 0x030c30c3u;',\n\t\t'\\tv = (v | (v << 2u)) & 0x09249249u;',\n\t\t'\\treturn v;',\n\t\t'}',\n\t\t'',\n\t\t'fn compactMorton3(value: u32) -> u32 {',\n\t\t'\\tvar v = value & 0x09249249u;',\n\t\t'\\tv = (v | (v >> 2u)) & 0x030c30c3u;',\n\t\t'\\tv = (v | (v >> 4u)) & 0x0300f00fu;',\n\t\t'\\tv = (v | (v >> 8u)) & 0x030000ffu;',\n\t\t'\\tv = (v | (v >> 16u)) & 0x000003ffu;',\n\t\t'\\treturn v;',\n\t\t'}',\n\t\t'',\n\t\t'fn encodeMorton3(point: vec3u) -> u32 {',\n\t\t'\\treturn spreadMorton3(point.x) | (spreadMorton3(point.y) << 1u) | (spreadMorton3(point.z) << 2u);',\n\t\t'}',\n\t\t'',\n\t\t'fn decodeMorton3(code: u32) -> vec3u {',\n\t\t'\\treturn vec3u(compactMorton3(code), compactMorton3(code >> 1u), compactMorton3(code >> 2u));',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment that widens and narrows scalar and packed-quad OCP FP8 `E4M3FN` and `E5M2` values in `u32` words.\n *\n * @remarks\n * Declares `uses: []`, executes `0` `fma()` calls (pure integer bit operations), and provides\n * `widenE4M3`, `narrowE4M3`, `widenE4M3Quad`, `narrowE4M3Quad`, `widenE5M2`, `narrowE5M2`,\n * `widenE5M2Quad`, and `narrowE5M2Quad`. Domain boundaries: `widenE4M3` and `widenE5M2` mask `bits`\n * to `0..255`. `E4M3FN` spans subnormals `2^-9` to `7 * 2^-9` and normals up to `±448.0`, rounds\n * ties to even, flushes magnitudes `<= 2^-10` to signed zero, saturates magnitudes `>= 448.0`\n * (including `±Infinity`) to `0x7e`/`0xfe`, and encodes `NaN` as `0x7f`/`0xff` with no infinities.\n * `E5M2` spans subnormals `2^-16` to `3 * 2^-16` and normals up to `±57344.0`, rounds ties to even,\n * flushes magnitudes `<= 2^-17` to signed zero, overflows at `>= 61440.0` to `±Infinity`\n * (`0x7c`/`0xfc`), and quiets `NaN` to `0x7e`/`0xfe` while preserving the 2-bit payload.\n * `widenWGSLE4M3`, `narrowWGSLE4M3`, `widenWGSLE5M2`, and `narrowWGSLE5M2` are its TypeScript\n * twins.\n *\n * @example\n * ```ts\n * WGSL_FP8.name // 'fp8'\n * ```\n */\nexport const WGSL_FP8: WGSLFragment = Object.freeze({\n\tname: 'fp8',\n\tsource: [\n\t\t'fn widenE4M3(bits: u32) -> f32 {',\n\t\t'\\tlet byte = bits & 0xffu;',\n\t\t'\\tlet signBit = (byte & 0x80u) << 24u;',\n\t\t'\\tlet exponent = (byte >> 3u) & 0x0fu;',\n\t\t'\\tlet fraction = byte & 0x07u;',\n\t\t'\\tif (exponent == 0x0fu && fraction == 0x07u) {',\n\t\t'\\t\\treturn bitcast<f32>(signBit | 0x7fc00000u | (bits & 0u));',\n\t\t'\\t}',\n\t\t'\\tif (exponent != 0u) {',\n\t\t'\\t\\treturn bitcast<f32>(signBit | ((exponent + 120u) << 23u) | (fraction << 20u));',\n\t\t'\\t}',\n\t\t'\\tif (fraction == 0u) {',\n\t\t'\\t\\treturn bitcast<f32>(signBit);',\n\t\t'\\t}',\n\t\t'\\tlet top = firstLeadingBit(fraction);',\n\t\t'\\treturn bitcast<f32>(signBit | ((top + 118u) << 23u) | ((fraction << (23u - top)) & 0x7fffffu));',\n\t\t'}',\n\t\t'',\n\t\t'fn narrowE4M3(value: f32) -> u32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet signBit = (bits >> 24u) & 0x80u;',\n\t\t'\\tlet magnitude = bits & 0x7fffffffu;',\n\t\t'\\tif (magnitude > 0x7f800000u) {',\n\t\t'\\t\\treturn signBit | 0x7fu;',\n\t\t'\\t}',\n\t\t'\\tif (magnitude >= 0x43e00000u) {',\n\t\t'\\t\\treturn signBit | 0x7eu;',\n\t\t'\\t}',\n\t\t'\\tif (magnitude >= 0x3c800000u) {',\n\t\t'\\t\\treturn signBit | ((magnitude + 0x7ffffu + ((magnitude >> 20u) & 1u) - 0x3c000000u) >> 20u);',\n\t\t'\\t}',\n\t\t'\\tif (magnitude <= 0x3a800000u) {',\n\t\t'\\t\\treturn signBit;',\n\t\t'\\t}',\n\t\t'\\tlet shift = 141u - (magnitude >> 23u);',\n\t\t'\\tlet mantissa = (magnitude & 0x7fffffu) | 0x800000u;',\n\t\t'\\tlet kept = mantissa >> shift;',\n\t\t'\\tlet rest = mantissa & ((1u << shift) - 1u);',\n\t\t'\\tlet midpoint = 1u << (shift - 1u);',\n\t\t'\\tlet up = rest > midpoint || (rest == midpoint && (kept & 1u) == 1u);',\n\t\t'\\treturn signBit | (kept + select(0u, 1u, up));',\n\t\t'}',\n\t\t'',\n\t\t'fn widenE4M3Quad(word: u32) -> vec4f {',\n\t\t'\\treturn vec4f(',\n\t\t'\\t\\twidenE4M3(word & 0xffu),',\n\t\t'\\t\\twidenE4M3((word >> 8u) & 0xffu),',\n\t\t'\\t\\twidenE4M3((word >> 16u) & 0xffu),',\n\t\t'\\t\\twidenE4M3(word >> 24u),',\n\t\t'\\t);',\n\t\t'}',\n\t\t'',\n\t\t'fn narrowE4M3Quad(values: vec4f) -> u32 {',\n\t\t'\\treturn narrowE4M3(values.x) | (narrowE4M3(values.y) << 8u) | (narrowE4M3(values.z) << 16u) | (narrowE4M3(values.w) << 24u);',\n\t\t'}',\n\t\t'',\n\t\t'fn widenE5M2(bits: u32) -> f32 {',\n\t\t'\\tlet byte = bits & 0xffu;',\n\t\t'\\tlet signBit = (byte & 0x80u) << 24u;',\n\t\t'\\tlet exponent = (byte >> 2u) & 0x1fu;',\n\t\t'\\tlet fraction = byte & 0x03u;',\n\t\t'\\tif (exponent == 0x1fu) {',\n\t\t'\\t\\treturn bitcast<f32>(signBit | 0x7f800000u | (fraction << 21u) | (bits & 0u));',\n\t\t'\\t}',\n\t\t'\\tif (exponent != 0u) {',\n\t\t'\\t\\treturn bitcast<f32>(signBit | ((exponent + 112u) << 23u) | (fraction << 21u));',\n\t\t'\\t}',\n\t\t'\\tif (fraction == 0u) {',\n\t\t'\\t\\treturn bitcast<f32>(signBit);',\n\t\t'\\t}',\n\t\t'\\tlet top = firstLeadingBit(fraction);',\n\t\t'\\treturn bitcast<f32>(signBit | ((top + 111u) << 23u) | ((fraction << (23u - top)) & 0x7fffffu));',\n\t\t'}',\n\t\t'',\n\t\t'fn narrowE5M2(value: f32) -> u32 {',\n\t\t'\\tlet bits = bitcast<u32>(value);',\n\t\t'\\tlet signBit = (bits >> 24u) & 0x80u;',\n\t\t'\\tlet magnitude = bits & 0x7fffffffu;',\n\t\t'\\tif (magnitude > 0x7f800000u) {',\n\t\t'\\t\\treturn signBit | 0x7eu | ((magnitude >> 21u) & 0x03u);',\n\t\t'\\t}',\n\t\t'\\tif (magnitude >= 0x47700000u) {',\n\t\t'\\t\\treturn signBit | 0x7cu;',\n\t\t'\\t}',\n\t\t'\\tif (magnitude >= 0x38800000u) {',\n\t\t'\\t\\treturn signBit | ((magnitude + 0xfffffu + ((magnitude >> 21u) & 1u) - 0x38000000u) >> 21u);',\n\t\t'\\t}',\n\t\t'\\tif (magnitude <= 0x37000000u) {',\n\t\t'\\t\\treturn signBit;',\n\t\t'\\t}',\n\t\t'\\tlet shift = 134u - (magnitude >> 23u);',\n\t\t'\\tlet mantissa = (magnitude & 0x7fffffu) | 0x800000u;',\n\t\t'\\tlet kept = mantissa >> shift;',\n\t\t'\\tlet rest = mantissa & ((1u << shift) - 1u);',\n\t\t'\\tlet midpoint = 1u << (shift - 1u);',\n\t\t'\\tlet up = rest > midpoint || (rest == midpoint && (kept & 1u) == 1u);',\n\t\t'\\treturn signBit | (kept + select(0u, 1u, up));',\n\t\t'}',\n\t\t'',\n\t\t'fn widenE5M2Quad(word: u32) -> vec4f {',\n\t\t'\\treturn vec4f(',\n\t\t'\\t\\twidenE5M2(word & 0xffu),',\n\t\t'\\t\\twidenE5M2((word >> 8u) & 0xffu),',\n\t\t'\\t\\twidenE5M2((word >> 16u) & 0xffu),',\n\t\t'\\t\\twidenE5M2(word >> 24u),',\n\t\t'\\t);',\n\t\t'}',\n\t\t'',\n\t\t'fn narrowE5M2Quad(values: vec4f) -> u32 {',\n\t\t'\\treturn narrowE5M2(values.x) | (narrowE5M2(values.y) << 8u) | (narrowE5M2(values.z) << 16u) | (narrowE5M2(values.w) << 24u);',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: Object.freeze([]),\n})\n\n/**\n * Holds the fragment of low-discrepancy quasi-random sequence samplers on the half-open unit interval `[0, 1)`.\n *\n * @remarks\n * Declares `uses: []`, executes `0` `fma()` calls, and provides `sampleVanDerCorput`,\n * `sampleHalton`, `samplePlastic2`, `samplePlastic3`, and `sampleSobol2`. Uses `u32` fixed-point\n * arithmetic with top-24-bit truncation scaled by `2^-24` (`(bits >> 8u) * 5.960464477539063e-8`)\n * so every output stays strictly in `[0, 1)` up to `index = 0xffffffffu`, avoiding the `1.0`\n * rounding edge of `f32(u32) * 2^-32`. Domain boundaries: `sampleHalton` returns `0.0` for\n * `base < 2u`, delegates `base == 2u` to `sampleVanDerCorput`, and clamps larger bases to\n * `bitcast<f32>(0x3f7fffffu)` (`1 - 2^-24`). `sampleWGSLHalton`, `sampleWGSLPlastic2`, and\n * `sampleWGSLSobol2` are its TypeScript twins.\n *\n * @example\n * ```ts\n * WGSL_QUASI.name // 'quasi'\n * ```\n */\nexport const WGSL_QUASI: WGSLFragment = Object.freeze({\n\tname: 'quasi',\n\tsource: [\n\t\t'fn sampleVanDerCorput(index: u32) -> f32 {',\n\t\t'\\treturn f32(reverseBits(index) >> 8u) * 5.960464477539063e-8;',\n\t\t'}',\n\t\t'',\n\t\t'fn sampleHalton(index: u32, base: u32) -> f32 {',\n\t\t'\\tif (base < 2u) {',\n\t\t'\\t\\treturn 0.0;',\n\t\t'\\t}',\n\t\t'\\tif (base == 2u) {',\n\t\t'\\t\\treturn sampleVanDerCorput(index);',\n\t\t'\\t}',\n\t\t'\\tlet invBase = 1.0 / f32(base);',\n\t\t'\\tvar factor = invBase;',\n\t\t'\\tvar sum = 0.0;',\n\t\t'\\tvar rem = index;',\n\t\t'\\twhile (rem > 0u) {',\n\t\t'\\t\\tlet digit = rem % base;',\n\t\t'\\t\\tsum = sum + f32(digit) * factor;',\n\t\t'\\t\\trem = rem / base;',\n\t\t'\\t\\tfactor = factor * invBase;',\n\t\t'\\t}',\n\t\t'\\treturn min(sum, bitcast<f32>(0x3f7fffffu));',\n\t\t'}',\n\t\t'',\n\t\t'fn samplePlastic2(index: u32) -> vec2f {',\n\t\t'\\tlet x = (0x80000000u + index * 0xc13fa9a9u) >> 8u;',\n\t\t'\\tlet y = (0x80000000u + index * 0x91e10da5u) >> 8u;',\n\t\t'\\treturn vec2f(f32(x), f32(y)) * 5.960464477539063e-8;',\n\t\t'}',\n\t\t'',\n\t\t'fn samplePlastic3(index: u32) -> vec3f {',\n\t\t'\\tlet x = (0x80000000u + index * 0xd1b54a33u) >> 8u;',\n\t\t'\\tlet y = (0x80000000u + index * 0xabc98389u) >> 8u;',\n\t\t'\\tlet z = (0x80000000u + index * 0x8cb92ba7u) >> 8u;',\n\t\t'\\treturn vec3f(f32(x), f32(y), f32(z)) * 5.960464477539063e-8;',\n\t\t'}',\n\t\t'',\n\t\t'fn sampleSobol2(index: u32) -> vec2f {',\n\t\t'\\tlet bits0 = reverseBits(index);',\n\t\t'\\tvar bits1 = 0u;',\n\t\t'\\tvar direction = 0x80000000u;',\n\t\t'\\tvar rem = index;',\n\t\t'\\twhile (rem != 0u) {',\n\t\t'\\t\\tif ((rem & 1u) != 0u) {',\n\t\t'\\t\\t\\tbits1 = bits1 ^ direction;',\n\t\t'\\t\\t}',\n\t\t'\\t\\tdirection = direction ^ (direction >> 1u);',\n\t\t'\\t\\trem = rem >> 1u;',\n\t\t'\\t}',\n\t\t'\\treturn vec2f(f32(bits0 >> 8u), f32(bits1 >> 8u)) * 5.960464477539063e-8;',\n\t\t'}',\n\t].join('\\n'),\n\tuses: Object.freeze([]),\n\tvariants: 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 {\n\tWGSLAccess,\n\tWGSLExtension,\n\tWGSLFloatPair,\n\tWGSLGrid,\n\tWGSLLanguage,\n\tWGSLOverrideScalar,\n\tWGSLScalar,\n\tWGSLStorageElement,\n} from './types.js'\nimport { holds, isArray, isNumber, isRecord, isSafeInteger, isString } from '@orkestrel/contract'\nimport {\n\tWGSL_ACCESSES,\n\tWGSL_EXTENSIONS,\n\tWGSL_LANGUAGES,\n\tWGSL_OVERRIDE_SCALARS,\n\tWGSL_RESERVED_WORDS,\n\tWGSL_SCALARS,\n\tWGSL_STORAGE_ELEMENTS,\n} 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 an element type a storage slot array can hold.\n *\n * @param value - The value to inspect\n * @returns True if the value is one of the `WGSL_STORAGE_ELEMENTS` members; false otherwise\n *\n * @example\n * ```ts\n * isWGSLStorageElement('vec4f') // true\n * isWGSLStorageElement('vec3f') // false\n * ```\n */\nexport function isWGSLStorageElement(value: unknown): value is WGSLStorageElement {\n\treturn WGSL_STORAGE_ELEMENTS.some((element) => element === value)\n}\n\n/**\n * Checks whether a value names a scalar type a pipeline-overridable constant can declare.\n *\n * @param value - The value to inspect\n * @returns True if the value is one of the `WGSL_OVERRIDE_SCALARS` members; false otherwise\n *\n * @example\n * ```ts\n * isWGSLOverrideScalar('bool') // true\n * isWGSLOverrideScalar('f16') // false\n * ```\n */\nexport function isWGSLOverrideScalar(value: unknown): value is WGSLOverrideScalar {\n\treturn WGSL_OVERRIDE_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 names a WGSL language extension a fragment variant can require.\n *\n * @param value - The value to inspect\n * @returns True if the value is one of the `WGSL_LANGUAGES` members; false otherwise\n *\n * @example\n * ```ts\n * isWGSLLanguage('subgroup_id') // true\n * isWGSLLanguage('subgroups') // false\n * ```\n */\nexport function isWGSLLanguage(value: unknown): value is WGSLLanguage {\n\treturn WGSL_LANGUAGES.some((language) => language === 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 a dense array of length 3, and each of its indices must hold a safe integer of\n * at 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\treturn holds(() => {\n\t\tif (!isArray(value) || value.length !== 3) return false\n\t\tif (!Object.hasOwn(value, 0) || !Object.hasOwn(value, 1) || !Object.hasOwn(value, 2)) {\n\t\t\treturn false\n\t\t}\n\t\tconst x: unknown = value[0]\n\t\tconst y: unknown = value[1]\n\t\tconst z: unknown = value[2]\n\t\treturn isSafeInteger(x) && x >= 1 && isSafeInteger(y) && y >= 1 && isSafeInteger(z) && z >= 1\n\t})\n}\n\n/**\n * Checks whether a value is a non-reserved WGSL identifier starting with a letter.\n *\n * @remarks\n * Accepts ASCII letters followed by letters, digits, or underscores, and refuses every entry in\n * `WGSL_RESERVED_WORDS`.\n *\n * @param value - The value to inspect\n * @returns True if the value is a valid WGSL identifier outside `WGSL_RESERVED_WORDS`; false otherwise\n *\n * @example\n * ```ts\n * isWGSLIdentifier('reduceSum') // true\n * isWGSLIdentifier('class') // false\n * ```\n */\nexport function isWGSLIdentifier(value: unknown): value is string {\n\treturn (\n\t\tisString(value) &&\n\t\t/^[A-Za-z][A-Za-z0-9_]*$/u.test(value) &&\n\t\t!WGSL_RESERVED_WORDS.includes(value)\n\t)\n}\n\n/**\n * Checks whether a value is a plain float-pair record whose `head` and `tail` members lie within IEEE-754 `f32` bounds.\n *\n * @remarks\n * Requires a plain record whose only own keys are the enumerable numeric properties `head` and\n * `tail`. Finite components must satisfy `Math.abs(component) <= 3.4028234663852886e38` (the\n * largest finite `f32`); `±Infinity` and `NaN` pass as valid IEEE-754 `f32` patterns, while finite\n * `f64` values past `±3.4028234663852886e38`, missing keys, non-enumerable `head`/`tail`, extra\n * string or symbol own keys, throwing accessors, and revoked proxies return `false`.\n *\n * @param value - The value to inspect\n * @returns True if the value is a `WGSLFloatPair`; false otherwise\n *\n * @example\n * ```ts\n * isWGSLFloatPair({ head: 1, tail: 0 }) // true\n * isWGSLFloatPair({ head: 1e39, tail: 0 }) // false\n * ```\n */\nexport function isWGSLFloatPair(value: unknown): value is WGSLFloatPair {\n\treturn holds(() => {\n\t\tif (!isRecord(value)) return false\n\t\tif (\n\t\t\t!Object.hasOwn(value, 'head') ||\n\t\t\t!Object.hasOwn(value, 'tail') ||\n\t\t\t!Object.prototype.propertyIsEnumerable.call(value, 'head') ||\n\t\t\t!Object.prototype.propertyIsEnumerable.call(value, 'tail') ||\n\t\t\tReflect.ownKeys(value).length !== 2\n\t\t) {\n\t\t\treturn false\n\t\t}\n\t\tconst MAX_F32 = 3.402_823_466_385_288_6e38\n\t\tconst head: unknown = value.head\n\t\tconst tail: unknown = value.tail\n\t\treturn (\n\t\t\tisNumber(head) &&\n\t\t\tisNumber(tail) &&\n\t\t\t(!Number.isFinite(head) || Math.abs(head) <= MAX_F32) &&\n\t\t\t(!Number.isFinite(tail) || Math.abs(tail) <= MAX_F32)\n\t\t)\n\t})\n}\n","import type {\n\tWGSLFloatPair,\n\tWGSLFragment,\n\tWGSLGrid,\n\tWGSLProgram,\n\tWGSLRenderOptions,\n\tWGSLSection,\n\tWGSLSectionRole,\n\tWGSLVariant,\n} from './types.js'\nimport {\n\tisArray,\n\tisNonNegativeInteger,\n\tisNumber,\n\tisSafeInteger,\n\tpreview,\n} from '@orkestrel/contract'\nimport { WGSL_EXTENSIONS, WGSL_LANGUAGES } from './constants.js'\nimport { WGSLError } from './errors.js'\nimport { isWGSLFloatPair } from './validators.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 * Resolves the first matching conditional variant of a fragment for one render capability set.\n *\n * @remarks\n * Evaluates `fragment.variants` in declaration order and returns the first variant whose\n * `extensions`, `languages`, `subgroup` bounds (`options.subgroup.minimum >= (variant.subgroup.minimum ?? 4)`\n * and `options.subgroup.maximum <= (variant.subgroup.maximum ?? 128)`), and `linear` requirement\n * (`options?.linear !== false` when `variant.linear === true`) all hold, or `undefined` when none\n * matches. A variant declaring `'subgroup_id'` in `languages` or `subgroup` bounds also requires\n * `options?.extensions?.subgroups === true`.\n *\n * @param fragment - The fragment whose variants are checked\n * @param options - The active extensions, language extensions, subgroup bounds, and linearity flag\n * @returns The first matching variant, or `undefined` to fall back to `fragment.source`\n *\n * @example\n * ```ts\n * resolveWGSLVariant(WGSL_JOIN, { extensions: { subgroups: true }, linear: true }) !== undefined // true\n * ```\n */\nexport function resolveWGSLVariant(\n\tfragment: WGSLFragment,\n\toptions?: WGSLRenderOptions,\n): WGSLVariant | undefined {\n\treturn fragment.variants.find((variant) => {\n\t\tif (\n\t\t\tvariant.extensions !== undefined &&\n\t\t\t!variant.extensions.every((extension) => options?.extensions?.[extension] === true)\n\t\t) {\n\t\t\treturn false\n\t\t}\n\t\tconst subgroupRequired =\n\t\t\tvariant.subgroup !== undefined ||\n\t\t\t(variant.languages !== undefined && variant.languages.includes('subgroup_id'))\n\t\tif (subgroupRequired && options?.extensions?.subgroups !== true) {\n\t\t\treturn false\n\t\t}\n\t\tif (\n\t\t\tvariant.languages !== undefined &&\n\t\t\t!variant.languages.every((language) => options?.languages?.[language] === true)\n\t\t) {\n\t\t\treturn false\n\t\t}\n\t\tif (variant.subgroup !== undefined) {\n\t\t\tconst range = options?.subgroup\n\t\t\tif (range === undefined || range.minimum > range.maximum) return false\n\t\t\tconst minimum = variant.subgroup.minimum ?? 4\n\t\t\tconst maximum = variant.subgroup.maximum ?? 128\n\t\t\tif (range.minimum < minimum || range.maximum > maximum) return false\n\t\t}\n\t\tif (variant.linear === true && options?.linear === false) {\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t})\n}\n\n/**\n * Collects the sections of a program's rendered WGSL text, each with its role, its producer, and its line range.\n *\n * @remarks\n * The sections follow `WGSL_SECTION_ROLES` order: `requires` language-extension directives in\n * `WGSL_LANGUAGES` order; `enable` extension directives in `WGSL_EXTENSIONS` order (including `f16`\n * whenever any storage slot declares `f16`, `vec2h`, or `vec4h`, and `subgroups` whenever\n * `subgroup_id` is active); `override` pipeline-overridable\n * constant declarations; the uniform struct declaration; the `Dispatch` struct (adding\n * `subgroup_size` when `subgroups` is enabled and `num_subgroups` when `subgroup_id` is required);\n * the `Invocation` struct (adding `subgroup_invocation_id` when `subgroups` is enabled and\n * `subgroup_id` when `subgroup_id` is required); the binding lines; one `fragment` section per\n * linked fragment whose active body is non-empty; and the entry function. Variant linearity holds\n * only when `(options?.linear ?? true) && program.entry.size[1] === 1 && program.entry.size[2] === 1`.\n *\n * @param program - The program to render\n * @param options - The active extensions, language extensions, subgroup bounds, and linearity flag\n * @returns The sections in render order, each frozen, in a frozen list\n *\n * @example\n * ```ts\n * collectWGSLSections(program)[0]?.role // 'struct'\n * ```\n */\nexport function collectWGSLSections(\n\tprogram: WGSLProgram,\n\toptions?: WGSLRenderOptions,\n): readonly WGSLSection[] {\n\tconst [x, y, z] = program.entry.size\n\tconst linear = (options?.linear ?? true) && y === 1 && z === 1\n\tconst resolvedOptions: WGSLRenderOptions = {\n\t\t...(options?.extensions !== undefined ? { extensions: options.extensions } : {}),\n\t\t...(options?.languages !== undefined ? { languages: options.languages } : {}),\n\t\t...(options?.subgroup !== undefined ? { subgroup: options.subgroup } : {}),\n\t\tlinear,\n\t}\n\tconst variants = program.fragments.map((fragment) =>\n\t\tresolveWGSLVariant(fragment, resolvedOptions),\n\t)\n\tconst required = WGSL_LANGUAGES.filter((name) =>\n\t\tvariants.some((variant) => variant?.languages?.includes(name) === true),\n\t)\n\tconst subgroupIdRequired = required.includes('subgroup_id')\n\tconst halfSlot = Object.values(program.slots).some(\n\t\t(slot) => slot.element === 'f16' || slot.element === 'vec2h' || slot.element === 'vec4h',\n\t)\n\tconst enabled = Object.keys(WGSL_EXTENSIONS).filter(\n\t\t(name) =>\n\t\t\t(name === 'f16' && halfSlot) ||\n\t\t\t(name === 'subgroups' && subgroupIdRequired) ||\n\t\t\tvariants.some((variant) => variant?.extensions?.some((ext) => ext === name) === true),\n\t)\n\tconst overrides = Object.entries(program.overrides).map(([name, declaration]) => {\n\t\tconst prefix = declaration.id === undefined ? '' : `@id(${declaration.id}) `\n\t\tif (declaration.value === undefined) {\n\t\t\treturn `${prefix}override ${name}: ${declaration.element};`\n\t\t}\n\t\tif (declaration.element === 'bool') {\n\t\t\treturn `${prefix}override ${name}: bool = ${declaration.value ? 'true' : 'false'};`\n\t\t}\n\t\tif (declaration.element === 'u32') {\n\t\t\treturn `${prefix}override ${name}: u32 = ${declaration.value}u;`\n\t\t}\n\t\tif (declaration.element === 'i32') {\n\t\t\tconst literal =\n\t\t\t\tdeclaration.value === -2_147_483_648 ? 'bitcast<i32>(0x80000000u)' : `${declaration.value}i`\n\t\t\treturn `${prefix}override ${name}: i32 = ${literal};`\n\t\t}\n\t\tconst text = Object.is(declaration.value, -0) ? '-0.0' : String(declaration.value)\n\t\tconst literal =\n\t\t\ttext.includes('.') || text.includes('e') || text.includes('E') ? text : `${text}.0`\n\t\treturn `${prefix}override ${name}: f32 = ${literal};`\n\t})\n\tconst subgroupsEnabled = enabled.includes('subgroups')\n\tconst dispatchSubgroup = [\n\t\t...(subgroupsEnabled ? ['\\t@builtin(subgroup_size) subgroup_size: u32,'] : []),\n\t\t...(subgroupIdRequired ? ['\\t@builtin(num_subgroups) num_subgroups: u32,'] : []),\n\t]\n\tconst invocationSubgroup = [\n\t\t...(subgroupsEnabled\n\t\t\t? ['\\t@builtin(subgroup_invocation_id) subgroup_invocation_id: u32,']\n\t\t\t: []),\n\t\t...(subgroupIdRequired ? ['\\t@builtin(subgroup_id) subgroup_id: u32,'] : []),\n\t]\n\tconst dispatch = [\n\t\t'struct Dispatch {',\n\t\t'\\t@builtin(workgroup_id) workgroup_id: vec3u,',\n\t\t'\\t@builtin(num_workgroups) num_workgroups: vec3u,',\n\t\t...dispatchSubgroup,\n\t\t'}',\n\t]\n\tconst invocation = [\n\t\t'struct Invocation {',\n\t\t'\\t@builtin(local_invocation_index) local_invocation_index: u32,',\n\t\t...invocationSubgroup,\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 entry = [\n\t\t`@compute @workgroup_size(${x}, ${y}, ${z})`,\n\t\t`fn ${program.entry.name}(invocation: Invocation, dispatch: Dispatch) {`,\n\t\tprogram.entry.source,\n\t\t'}',\n\t]\n\tconst parts: ReadonlyArray<readonly [role: WGSLSectionRole, name: string, source: string]> = [\n\t\t['requires', 'requires', required.map((name) => `requires ${name};`).join('\\n')],\n\t\t['enable', 'enable', enabled.map((name) => `enable ${name};`).join('\\n')],\n\t\t['override', 'override', overrides.join('\\n')],\n\t\t['struct', program.uniform.struct.name, program.uniform.struct.source],\n\t\t['dispatch', 'Dispatch', dispatch.join('\\n')],\n\t\t['invocation', 'Invocation', invocation.join('\\n')],\n\t\t['bindings', 'bindings', bindings.join('\\n')],\n\t\t...program.fragments.map(\n\t\t\t(fragment, index): readonly [role: WGSLSectionRole, name: string, source: string] => [\n\t\t\t\t'fragment',\n\t\t\t\tfragment.name,\n\t\t\t\tvariants[index]?.source ?? fragment.source,\n\t\t\t],\n\t\t),\n\t\t['entry', program.entry.name, entry.join('\\n')],\n\t]\n\tconst sections = parts.reduce<readonly WGSLSection[]>((accumulator, [role, name, source]) => {\n\t\tif (source.length === 0) return accumulator\n\t\tconst last = accumulator.at(-1)\n\t\tconst line = last === undefined ? 1 : last.end + 2\n\t\tconst end = line + source.split('\\n').length - 1\n\t\treturn [...accumulator, Object.freeze({ role, name, source, line, end })]\n\t}, [])\n\treturn Object.freeze(sections)\n}\n\n/**\n * Renders a program's complete WGSL text for one render capability set.\n *\n * @remarks\n * Joins the `source` of each `collectWGSLSections` section with one blank line and terminates with\n * a line feed, so `renderWGSLProgram` and `collectWGSLSections` never disagree.\n *\n * @param program - The program to render\n * @param options - The active extensions, language extensions, subgroup bounds, and linearity flag\n * @returns The WGSL text, ending in a line feed\n *\n * @example\n * ```ts\n * renderWGSLProgram(program).startsWith('struct Shape {') // true\n * ```\n */\nexport function renderWGSLProgram(program: WGSLProgram, options?: WGSLRenderOptions): string {\n\tconst sections = collectWGSLSections(program, options)\n\treturn `${sections.map((section) => section.source).join('\\n\\n')}\\n`\n}\n\n/**\n * Renders one fragment and every fragment it reaches as WGSL text a tool or a test can compile beside its own entry.\n *\n * @remarks\n * Builds a synthetic program whose entry size is `[fragment.workgroup ?? 1, 1, 1]` when\n * `options?.linear !== false` or `[1, fragment.workgroup ?? 1, 1]` when `options?.linear === false`,\n * delegates to `collectWGSLSections`, and keeps only `requires`, `enable`, `dispatch`, `invocation`,\n * and `fragment` sections. Leaves out the uniform struct, overrides, bindings, and entry function.\n * Thrown with code `VALIDATION` when the linker finds two distinct fragments of one name or a cycle.\n *\n * @param fragment - The fragment to render\n * @param options - The active extensions, language extensions, subgroup bounds, and linearity flag\n * @returns The WGSL text, ending in a line feed\n *\n * @example\n * ```ts\n * renderWGSLFragment(WGSL_HALF).endsWith('}\\n') // true\n * ```\n */\nexport function renderWGSLFragment(fragment: WGSLFragment, options?: WGSLRenderOptions): string {\n\tconst count = fragment.workgroup ?? 1\n\tconst size: WGSLGrid = (options?.linear ?? true) ? [count, 1, 1] : [1, count, 1]\n\tconst program: WGSLProgram = {\n\t\tname: fragment.name,\n\t\tentry: { name: fragment.name, size, source: '' },\n\t\tslots: {},\n\t\tuniform: {\n\t\t\tname: fragment.name,\n\t\t\tstruct: { name: '', fields: {}, size: 0, offsets: {}, members: [], source: '' },\n\t\t},\n\t\toverrides: {},\n\t\tfragments: collectWGSLFragments([fragment]),\n\t}\n\tconst roles: readonly WGSLSectionRole[] = [\n\t\t'requires',\n\t\t'enable',\n\t\t'dispatch',\n\t\t'invocation',\n\t\t'fragment',\n\t]\n\tconst sections = collectWGSLSections(program, options).filter((section) =>\n\t\troles.includes(section.role),\n\t)\n\treturn `${sections.map((section) => section.source).join('\\n\\n')}\\n`\n}\n\n/**\n * Widens IEEE 754 half-precision bits to the number they hold, as `widenHalf` in `WGSL_HALF` does.\n *\n * @remarks\n * The result is the `f32` value `widenHalf` returns for the same bits, so signed zeros, subnormals,\n * and infinities widen exactly; a NaN pattern returns `NaN`, whose payload a number does not carry.\n * Thrown with code `ARGUMENT` when `bits` is not an integer from `0` to `0xffff`.\n *\n * @param bits - The half-precision bits\n * @returns The value\n *\n * @example\n * ```ts\n * widenWGSLHalf(0x3c00) // 1\n * ```\n */\nexport function widenWGSLHalf(bits: number): number {\n\tif (!isSafeInteger(bits) || bits < 0 || bits > 0xffff) {\n\t\tthrow new WGSLError(\n\t\t\t`Half-precision bits must be an integer from 0 to 0xffff; received ${preview(bits)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { bits } },\n\t\t)\n\t}\n\tconst negative = (bits & 0x8000) << 16\n\tconst exponent = (bits >> 10) & 0x1f\n\tconst fraction = bits & 0x3ff\n\tconst top = 31 - Math.clz32(fraction)\n\tconst word =\n\t\texponent === 0x1f\n\t\t\t? negative | 0x7f80_0000 | (fraction << 13)\n\t\t\t: exponent !== 0\n\t\t\t\t? negative | ((exponent + 112) << 23) | (fraction << 13)\n\t\t\t\t: fraction === 0\n\t\t\t\t\t? negative\n\t\t\t\t\t: negative | ((top + 103) << 23) | ((fraction << (23 - top)) & 0x7f_ffff)\n\tconst view = new DataView(new ArrayBuffer(4))\n\tview.setUint32(0, word >>> 0)\n\treturn view.getFloat32(0)\n}\n\n/**\n * Narrows a number to IEEE 754 half-precision bits, as `narrowHalf` in `WGSL_FLOAT` does.\n *\n * @remarks\n * The number first rounds to the nearest `f32`, as a `Float32Array` store rounds it, and then to the\n * nearest half, ties to even: `-0` keeps its sign, a magnitude from `65520` up gives an infinity, and\n * `NaN` gives `0x7e00`, the quiet pattern of the canonical `f32` NaN. Thrown with code `ARGUMENT`\n * when `value` is not a number.\n *\n * @param value - The value to narrow\n * @returns The half-precision bits, from `0` to `0xffff`\n *\n * @example\n * ```ts\n * narrowWGSLHalf(1) // 0x3c00\n * ```\n */\nexport function narrowWGSLHalf(value: number): number {\n\tif (!isNumber(value)) {\n\t\tthrow new WGSLError(`A value to narrow must be a number; received ${preview(value)}.`, {\n\t\t\tcode: 'ARGUMENT',\n\t\t\tcontext: { value },\n\t\t})\n\t}\n\tconst view = new DataView(new ArrayBuffer(4))\n\tview.setFloat32(0, value)\n\tconst bits = Number.isNaN(value) ? 0x7fc0_0000 : view.getUint32(0)\n\tconst negative = (bits >>> 16) & 0x8000\n\tconst magnitude = bits & 0x7fff_ffff\n\tif (magnitude > 0x7f80_0000) return negative | 0x7e00 | ((magnitude >>> 13) & 0x3ff)\n\tif (magnitude >= 0x477f_f000) return negative | 0x7c00\n\tif (magnitude >= 0x3880_0000) {\n\t\treturn negative | ((magnitude + 0xfff + ((magnitude >>> 13) & 1) - 0x3800_0000) >>> 13)\n\t}\n\tif (magnitude <= 0x3300_0000) return negative\n\tconst shift = 126 - (magnitude >>> 23)\n\tconst mantissa = (magnitude & 0x7f_ffff) | 0x80_0000\n\tconst kept = mantissa >>> shift\n\tconst rest = mantissa & ((1 << shift) - 1)\n\tconst midpoint = 1 << (shift - 1)\n\tconst up = rest > midpoint || (rest === midpoint && (kept & 1) === 1)\n\treturn negative | (kept + (up ? 1 : 0))\n}\n\n/**\n * Widens bfloat16 bits to the number they hold, as `widenBFloat` in `WGSL_BFLOAT` does.\n *\n * @remarks\n * The bits become the top half of an `f32` word, so every pattern widens exactly; a NaN pattern\n * returns `NaN`, whose payload a number does not carry. Thrown with code `ARGUMENT` when `bits` is\n * not an integer from `0` to `0xffff`.\n *\n * @param bits - The bfloat16 bits\n * @returns The value\n *\n * @example\n * ```ts\n * widenWGSLBFloat(0x3f80) // 1\n * ```\n */\nexport function widenWGSLBFloat(bits: number): number {\n\tif (!isSafeInteger(bits) || bits < 0 || bits > 0xffff) {\n\t\tthrow new WGSLError(\n\t\t\t`Bfloat16 bits must be an integer from 0 to 0xffff; received ${preview(bits)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { bits } },\n\t\t)\n\t}\n\tconst view = new DataView(new ArrayBuffer(4))\n\tview.setUint32(0, (bits << 16) >>> 0)\n\treturn view.getFloat32(0)\n}\n\n/**\n * Narrows a number to bfloat16 bits, as `narrowBFloat` in `WGSL_BFLOAT` does.\n *\n * @remarks\n * The number first rounds to the nearest `f32`, as a `Float32Array` store rounds it, and then to the\n * nearest bfloat16, ties to even: `-0` and both infinities keep their patterns, a finite value past\n * the largest bfloat16 gives an infinity, and `NaN` gives `0x7fc0`, the quiet pattern of the\n * canonical `f32` NaN. Thrown with code `ARGUMENT` when `value` is not a number.\n *\n * @param value - The value to narrow\n * @returns The bfloat16 bits, from `0` to `0xffff`\n *\n * @example\n * ```ts\n * narrowWGSLBFloat(1) // 0x3f80\n * ```\n */\nexport function narrowWGSLBFloat(value: number): number {\n\tif (!isNumber(value)) {\n\t\tthrow new WGSLError(`A value to narrow must be a number; received ${preview(value)}.`, {\n\t\t\tcode: 'ARGUMENT',\n\t\t\tcontext: { value },\n\t\t})\n\t}\n\tconst view = new DataView(new ArrayBuffer(4))\n\tview.setFloat32(0, value)\n\tconst bits = Number.isNaN(value) ? 0x7fc0_0000 : view.getUint32(0)\n\tif ((bits & 0x7fff_ffff) > 0x7f80_0000) return (bits >>> 16) | 0x0040\n\treturn (bits + 0x7fff + ((bits >>> 16) & 1)) >>> 16\n}\n\n/**\n * Unpacks the 4 bytes of a `u32` word as signed integers, as `unpackSignedBytes` in `WGSL_BYTES` does.\n *\n * @remarks\n * Byte 0, the lowest, comes first. Thrown with code `ARGUMENT` when `word` is not an integer from\n * `0` to `0xffffffff`.\n *\n * @param word - The packed word\n * @returns The 4 signed bytes, each from `-128` to `127`, frozen\n *\n * @example\n * ```ts\n * unpackWGSLBytes(0x80ff_7f01) // [1, 127, -1, -128]\n * ```\n */\nexport function unpackWGSLBytes(word: number): readonly [number, number, number, number] {\n\tif (!isSafeInteger(word) || word < 0 || word > 0xffff_ffff) {\n\t\tthrow new WGSLError(\n\t\t\t`A packed word must be an integer from 0 to 0xffffffff; received ${preview(word)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { word } },\n\t\t)\n\t}\n\tconst bytes: readonly [number, number, number, number] = [\n\t\t(word << 24) >> 24,\n\t\t(word << 16) >> 24,\n\t\t(word << 8) >> 24,\n\t\tword >> 24,\n\t]\n\treturn Object.freeze(bytes)\n}\n\n/**\n * Packs 4 signed bytes into a `u32` word, as `packSignedBytes` in `WGSL_BYTES` does.\n *\n * @remarks\n * The first value lands in byte 0, the lowest, so it inverts `unpackWGSLBytes`. Thrown with code\n * `ARGUMENT` when `values` is not an array of 4 integers, each from `-128` to `127`.\n *\n * @param values - The 4 signed bytes, byte 0 first\n * @returns The packed word, from `0` to `0xffffffff`\n *\n * @example\n * ```ts\n * packWGSLBytes([1, 127, -1, -128]) // 0x80ff7f01\n * ```\n */\nexport function packWGSLBytes(values: readonly [number, number, number, number]): number {\n\tif (\n\t\t!isArray(values) ||\n\t\tvalues.length !== 4 ||\n\t\t!values.every((value) => isSafeInteger(value) && value >= -128 && value <= 127)\n\t) {\n\t\tthrow new WGSLError(\n\t\t\t`Packed bytes must be 4 integers, each from -128 to 127; received ${preview(values)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { values } },\n\t\t)\n\t}\n\tconst [x, y, z, w] = values\n\treturn ((x & 0xff) | ((y & 0xff) << 8) | ((z & 0xff) << 16) | ((w & 0xff) << 24)) >>> 0\n}\n\n/**\n * Encodes an `f32` value into an order-preserving `u32` key, as `encodeFloatOrder` in `WGSL_ORDER` does.\n *\n * @remarks\n * Rounds `value` to `f32`, canonicalizes every `NaN` to quiet `0x7fc00000` (encoded as\n * `0xffc00000`), and maps IEEE-754 total order (`-Infinity < ... < -0.0 < +0.0 < ... < +Infinity`)\n * bijectively into `u32` unsigned order. Thrown with code `ARGUMENT` when `value` is not a number.\n *\n * @param value - The floating-point value to encode\n * @returns The order-preserving unsigned 32-bit key\n *\n * @example\n * ```ts\n * encodeWGSLFloatOrder(-0) < encodeWGSLFloatOrder(0) // true\n * ```\n */\nexport function encodeWGSLFloatOrder(value: number): number {\n\tif (!isNumber(value)) {\n\t\tthrow new WGSLError(`A value to encode must be a number; received ${preview(value)}.`, {\n\t\t\tcode: 'ARGUMENT',\n\t\t\tcontext: { value },\n\t\t})\n\t}\n\tconst view = new DataView(new ArrayBuffer(4))\n\tview.setFloat32(0, value)\n\tconst raw = Number.isNaN(value) ? 0x7fc0_0000 : view.getUint32(0)\n\tconst mask = (raw & 0x8000_0000) !== 0 ? 0xffff_ffff : 0x8000_0000\n\treturn (raw ^ mask) >>> 0\n}\n\n/**\n * Decodes an order-preserving `u32` key back to its `f32` value, as `decodeFloatOrder` in `WGSL_ORDER` does.\n *\n * @remarks\n * Inverts `encodeWGSLFloatOrder` bit-for-bit across all non-NaN `f32` values (including `-0` and\n * `+0`) and returns `NaN` for NaN keys. Thrown with code `ARGUMENT` when `bits` is not an integer\n * from `0` to `0xffffffff`.\n *\n * @param bits - The order-preserving unsigned 32-bit key\n * @returns The decoded `f32` value\n *\n * @example\n * ```ts\n * decodeWGSLFloatOrder(encodeWGSLFloatOrder(-1.5)) // -1.5\n * ```\n */\nexport function decodeWGSLFloatOrder(bits: number): number {\n\tif (!isSafeInteger(bits) || bits < 0 || bits > 0xffff_ffff) {\n\t\tthrow new WGSLError(\n\t\t\t`An encoded float key must be an integer from 0 to 0xffffffff; received ${preview(bits)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { bits } },\n\t\t)\n\t}\n\tconst mask = (bits & 0x8000_0000) !== 0 ? 0x8000_0000 : 0xffff_ffff\n\tconst view = new DataView(new ArrayBuffer(4))\n\tview.setUint32(0, (bits ^ mask) >>> 0)\n\treturn view.getFloat32(0)\n}\n\n/**\n * Computes one 10-round Random123 Philox4x32 output block, as `computePhilox` in `WGSL_RANDOM` does.\n *\n * @remarks\n * Uses exact 32-by-32-to-64-bit multiplication (`0xd2511f53` and `0xcd9e8d57`) and Weyl key schedule\n * (`0x9e3779b9` and `0xbb67ae85`), matching the official Random123 known-answer vectors bit-for-bit.\n * Thrown with code `ARGUMENT` when `counter` is not 4 unsigned 32-bit integers or `key` is not 2\n * unsigned 32-bit integers.\n *\n * @param counter - The 4-word 128-bit counter\n * @param key - The 2-word 64-bit key\n * @returns The 4 unsigned 32-bit output words, frozen\n *\n * @example\n * ```ts\n * computeWGSLPhilox([0, 0, 0, 0], [0, 0])[0] // 0x6627e8d5\n * ```\n */\nexport function computeWGSLPhilox(\n\tcounter: readonly [number, number, number, number],\n\tkey: readonly [number, number],\n): readonly [number, number, number, number] {\n\tif (\n\t\t!isArray(counter) ||\n\t\tcounter.length !== 4 ||\n\t\t!counter.every((word) => isSafeInteger(word) && word >= 0 && word <= 0xffff_ffff)\n\t) {\n\t\tthrow new WGSLError(\n\t\t\t`A Philox counter must be 4 integers, each from 0 to 0xffffffff; received ${preview(counter)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { counter } },\n\t\t)\n\t}\n\tif (\n\t\t!isArray(key) ||\n\t\tkey.length !== 2 ||\n\t\t!key.every((word) => isSafeInteger(word) && word >= 0 && word <= 0xffff_ffff)\n\t) {\n\t\tthrow new WGSLError(\n\t\t\t`A Philox key must be 2 integers, each from 0 to 0xffffffff; received ${preview(key)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { key } },\n\t\t)\n\t}\n\tconst [x0, x1, x2, x3] = counter\n\tconst [k0, k1] = key\n\tconst [out0, out1, out2, out3] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].reduce<\n\t\treadonly [number, number, number, number, number, number]\n\t>(\n\t\t([c0, c1, c2, c3, key0, key1]) => {\n\t\t\tconst p0 = 0xd251_1f53n * BigInt(c0)\n\t\t\tconst p1 = 0xcd9e_8d57n * BigInt(c2)\n\t\t\tconst hi0 = Number((p0 >> 32n) & 0xffff_ffffn)\n\t\t\tconst lo0 = Number(p0 & 0xffff_ffffn)\n\t\t\tconst hi1 = Number((p1 >> 32n) & 0xffff_ffffn)\n\t\t\tconst lo1 = Number(p1 & 0xffff_ffffn)\n\t\t\treturn [\n\t\t\t\t(hi1 ^ c1 ^ key0) >>> 0,\n\t\t\t\tlo1 >>> 0,\n\t\t\t\t(hi0 ^ c3 ^ key1) >>> 0,\n\t\t\t\tlo0 >>> 0,\n\t\t\t\t(key0 + 0x9e37_79b9) >>> 0,\n\t\t\t\t(key1 + 0xbb67_ae85) >>> 0,\n\t\t\t]\n\t\t},\n\t\t[x0, x1, x2, x3, k0, k1],\n\t)\n\tconst result: readonly [number, number, number, number] = [out0, out1, out2, out3]\n\treturn Object.freeze(result)\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 * `dispatch.workgroup_id.x + dispatch.workgroup_id.y * dispatch.num_workgroups.x`, which the\n * `WGSL_PLACE` fragment declares as `readPlace(dispatch: Dispatch)`, so a workgroup past the total\n * 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 grid exceeds `limit` on `y`, exceeds a\n * `u32` axis count, or makes `x * y` exceed `2^32` (which would wrap `readPlace`).\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 || x > 0xffff_ffff || x * y > 0x1_0000_0000) {\n\t\tconst cap = limit <= 65_536 ? limit * limit : 0x1_0000_0000\n\t\tthrow new WGSLError(\n\t\t\t`A dispatch of ${total} workgroups passes the two-axis u32 grid limit under ${limit} per axis; split it into dispatches of at most ${cap} 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\n/**\n * Computes the Gauss error function `erf(value)` to IEEE-754 `f64` accuracy, pairing with `computeErf` in `WGSL_SPECIAL`.\n *\n * @remarks\n * Uses Cody's rational Chebyshev approximation directly for `|value| <= 0.46875` and delegates\n * larger magnitudes to `computeWGSLErfc` so `erf(x)` keeps full double precision and preserves `-0`,\n * `±Infinity`, and `NaN`. Thrown with code `ARGUMENT` when `value` is not a number.\n *\n * @param value - The real input\n * @returns The value of `erf(value)` in `[-1, 1]`\n *\n * @example\n * ```ts\n * computeWGSLErf(0) // 0\n * ```\n */\nexport function computeWGSLErf(value: number): number {\n\tif (!isNumber(value)) {\n\t\tthrow new WGSLError(`An error-function input must be a number; received ${preview(value)}.`, {\n\t\t\tcode: 'ARGUMENT',\n\t\t\tcontext: { value },\n\t\t})\n\t}\n\tif (Number.isNaN(value) || value === 0) return value\n\tconst ax = Math.abs(value)\n\tif (ax > 0.468_75) {\n\t\treturn (value < 0 ? -1 : 1) * (1 - computeWGSLErfc(ax))\n\t}\n\tconst y = value * value\n\tconst num =\n\t\t(((1.857_777_061_846_031_5e-1 * y + 3.161_123_743_870_565_5) * y + 1.138_641_541_510_501_6e2) *\n\t\t\ty +\n\t\t\t3.774_852_376_853_02e2) *\n\t\t\ty +\n\t\t3209.377_589_138_469_4\n\tconst den =\n\t\t(((y + 2.360_129_095_234_412e1) * y + 2.440_246_379_344_441_7e2) * y +\n\t\t\t1.282_616_526_077_372_3e3) *\n\t\t\ty +\n\t\t2844.236_833_439_171\n\treturn (value * num) / den\n}\n\n/**\n * Computes the complementary error function `erfc(value)` without tail cancellation, pairing with `computeErfc` in `WGSL_SPECIAL`.\n *\n * @remarks\n * Uses Cody's rational Chebyshev approximation with exact `1/16` exponential range splitting so\n * `erfc(value)` stays accurate into the subnormal tail (`value <= 27.3`), returns `1` at `±0`, `0`\n * at `+Infinity`, `2` at `-Infinity`, and `NaN` for `NaN`. Thrown with code `ARGUMENT` when `value`\n * is not a number.\n *\n * @param value - The real input\n * @returns The value of `erfc(value)` in `[0, 2]`\n *\n * @example\n * ```ts\n * computeWGSLErfc(0) // 1\n * ```\n */\nexport function computeWGSLErfc(value: number): number {\n\tif (!isNumber(value)) {\n\t\tthrow new WGSLError(\n\t\t\t`A complementary error-function input must be a number; received ${preview(value)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { value } },\n\t\t)\n\t}\n\tif (Number.isNaN(value)) return Number.NaN\n\tif (value === 0) return 1\n\tconst ax = Math.abs(value)\n\tif (ax <= 0.468_75) return 1 - computeWGSLErf(value)\n\tif (ax >= 27.3) return value > 0 ? 0 : 2\n\tconst xsq = Math.trunc(ax * 16) / 16\n\tconst del = (ax - xsq) * (ax + xsq)\n\tconst scale = Math.exp(-xsq * xsq) * Math.exp(-del)\n\tconst invSq = 1 / (ax * ax)\n\tconst pos =\n\t\tax <= 4\n\t\t\t? (scale *\n\t\t\t\t\t((((((((2.153_115_354_744_038_3e-8 * ax + 5.641_884_969_886_701e-1) * ax +\n\t\t\t\t\t\t8.883_149_794_388_377) *\n\t\t\t\t\t\tax +\n\t\t\t\t\t\t6.611_919_063_714_163e1) *\n\t\t\t\t\t\tax +\n\t\t\t\t\t\t298.635_138_197_400_1) *\n\t\t\t\t\t\tax +\n\t\t\t\t\t\t8.819_522_212_417_691e2) *\n\t\t\t\t\t\tax +\n\t\t\t\t\t\t1712.047_612_634_070_7) *\n\t\t\t\t\t\tax +\n\t\t\t\t\t\t2051.078_377_826_071_6) *\n\t\t\t\t\t\tax +\n\t\t\t\t\t\t1230.339_354_797_997_2)) /\n\t\t\t\t((((((((ax + 1.574_492_611_070_983_5e1) * ax + 1.176_939_508_913_125e2) * ax +\n\t\t\t\t\t5.371_811_018_620_099e2) *\n\t\t\t\t\tax +\n\t\t\t\t\t1621.389_574_566_690_3) *\n\t\t\t\t\tax +\n\t\t\t\t\t3290.799_235_733_459_7) *\n\t\t\t\t\tax +\n\t\t\t\t\t4.362_619_090_143_247e3) *\n\t\t\t\t\tax +\n\t\t\t\t\t3.439_367_674_143_721_6e3) *\n\t\t\t\t\tax +\n\t\t\t\t\t1230.339_354_803_749_3)\n\t\t\t: (scale *\n\t\t\t\t\t(0.564_189_583_547_756_3 -\n\t\t\t\t\t\t(invSq *\n\t\t\t\t\t\t\t(((((0.016_315_387_137_302_097 * invSq + 0.305_326_634_961_232_36) * invSq +\n\t\t\t\t\t\t\t\t0.360_344_899_949_804_45) *\n\t\t\t\t\t\t\t\tinvSq +\n\t\t\t\t\t\t\t\t0.125_781_726_111_229_26) *\n\t\t\t\t\t\t\t\tinvSq +\n\t\t\t\t\t\t\t\t0.016_083_785_148_742_28) *\n\t\t\t\t\t\t\t\tinvSq +\n\t\t\t\t\t\t\t\t6.587_491_615_298_378e-4)) /\n\t\t\t\t\t\t\t(((((invSq + 2.568_520_192_289_822) * invSq + 1.872_952_849_923_460_4) * invSq +\n\t\t\t\t\t\t\t\t0.527_905_102_951_428_5) *\n\t\t\t\t\t\t\t\tinvSq +\n\t\t\t\t\t\t\t\t6.051_834_131_244_132e-2) *\n\t\t\t\t\t\t\t\tinvSq +\n\t\t\t\t\t\t\t\t2.335_204_976_268_692e-3))) /\n\t\t\t\tax\n\treturn value < 0 ? 2 - pos : pos\n}\n\n/**\n * Computes the inverse Gauss error function `erfinv(value)` to IEEE-754 `f64` accuracy, pairing with `computeInverseErf` in `WGSL_SPECIAL`.\n *\n * @remarks\n * Seeds with Giles's minimax approximation and polishes with two cubic Halley steps using\n * `computeWGSLErf` and `computeWGSLErfc`. Preserves `-0`, returns `±Infinity` at `±1`, and returns\n * `NaN` for `|value| > 1` or `NaN`. Thrown with code `ARGUMENT` when `value` is not a number.\n *\n * @param value - The probability-domain input in `[-1, 1]`\n * @returns The real value `x` satisfying `erf(x) = value`\n *\n * @example\n * ```ts\n * computeWGSLInverseErf(0) // 0\n * ```\n */\nexport function computeWGSLInverseErf(value: number): number {\n\tif (!isNumber(value)) {\n\t\tthrow new WGSLError(\n\t\t\t`An inverse error-function input must be a number; received ${preview(value)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { value } },\n\t\t)\n\t}\n\tif (Number.isNaN(value) || value === 0) return value\n\tconst ay = Math.abs(value)\n\tif (ay > 1) return Number.NaN\n\tif (ay === 1) return value > 0 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY\n\tif (ay < 1e-8) return value * 0.886_226_925_452_758\n\tconst w = -Math.log((1 - ay) * (1 + ay))\n\tconst t = w < 5 ? w - 2.5 : Math.sqrt(w) - 3\n\tconst initial =\n\t\tw < 5\n\t\t\t? ay *\n\t\t\t\t((((((((2.810_226_36e-8 * t + 3.432_739_39e-7) * t - 3.523_387_7e-6) * t -\n\t\t\t\t\t4.391_506_54e-6) *\n\t\t\t\t\tt +\n\t\t\t\t\t0.000_218_580_87) *\n\t\t\t\t\tt -\n\t\t\t\t\t0.001_253_725_03) *\n\t\t\t\t\tt -\n\t\t\t\t\t0.004_177_681_64) *\n\t\t\t\t\tt +\n\t\t\t\t\t0.246_640_727) *\n\t\t\t\t\tt +\n\t\t\t\t\t1.501_409_41)\n\t\t\t: ay *\n\t\t\t\t((((((((-0.000_200_214_257 * t + 0.000_100_950_558) * t + 0.001_349_343_22) * t -\n\t\t\t\t\t0.003_673_428_44) *\n\t\t\t\t\tt +\n\t\t\t\t\t0.005_739_507_73) *\n\t\t\t\t\tt -\n\t\t\t\t\t0.007_622_461_3) *\n\t\t\t\t\tt +\n\t\t\t\t\t0.009_438_870_47) *\n\t\t\t\t\tt +\n\t\t\t\t\t1.001_674_06) *\n\t\t\t\t\tt +\n\t\t\t\t\t2.832_976_82)\n\tconst refined = [0, 1].reduce((current) => {\n\t\tconst error = ay > 0.5 ? 1 - ay - computeWGSLErfc(current) : computeWGSLErf(current) - ay\n\t\tconst step = error / (1.128_379_167_095_512_6 * Math.exp(-current * current))\n\t\treturn current - step / (1 + current * step)\n\t}, initial)\n\treturn value < 0 ? -refined : refined\n}\n\n/**\n * Computes `ln(|Gamma(value)|)` to IEEE-754 `f64` accuracy, pairing with `computeLogGamma` in `WGSL_SPECIAL`.\n *\n * @remarks\n * Uses a zeta-series expansion near the zeros `1` and `2`, Lanczos `g = 7` on moderate positive\n * values, Stirling's asymptotic series above `1e8`, and Euler's reflection formula on negative\n * non-integers. Returns `+Infinity` at `±Infinity`, `±0`, and negative integers, `0` at `1` and\n * `2`, and `NaN` for `NaN`. Thrown with code `ARGUMENT` when `value` is not a number.\n *\n * @param value - The real input\n * @returns The natural logarithm of `|Gamma(value)|`\n *\n * @example\n * ```ts\n * computeWGSLLogGamma(1) // 0\n * ```\n */\nexport function computeWGSLLogGamma(value: number): number {\n\tif (!isNumber(value)) {\n\t\tthrow new WGSLError(`A log-gamma input must be a number; received ${preview(value)}.`, {\n\t\t\tcode: 'ARGUMENT',\n\t\t\tcontext: { value },\n\t\t})\n\t}\n\tif (Number.isNaN(value)) return Number.NaN\n\tif (!Number.isFinite(value)) return Number.POSITIVE_INFINITY\n\tif (value <= 0 && Math.floor(value) === value) return Number.POSITIVE_INFINITY\n\tif (value === 1 || value === 2) return 0\n\tif (value < 0) {\n\t\tconst reduced = Math.abs(value - Math.round(value))\n\t\treturn (\n\t\t\tMath.log(Math.PI) - Math.log(Math.sin(Math.PI * reduced)) - computeWGSLLogGamma(1 - value)\n\t\t)\n\t}\n\tif (Math.abs(value - 1) < 1e-4) {\n\t\tconst u = value - 1\n\t\treturn (\n\t\t\tu *\n\t\t\t(-0.577_215_664_901_532_9 +\n\t\t\t\tu *\n\t\t\t\t\t(0.822_467_033_424_113_2 + u * (-0.400_685_634_386_531_4 + u * 0.270_580_808_427_784_5)))\n\t\t)\n\t}\n\tif (Math.abs(value - 2) < 1e-4) {\n\t\tconst u = value - 2\n\t\treturn computeWGSLLogGamma(1 + u) + Math.log1p(u)\n\t}\n\tif (value > 1e8) {\n\t\treturn (value - 0.5) * Math.log(value) - value + 0.918_938_533_204_672_7 + 1 / (12 * value)\n\t}\n\tif (value < 0.5) {\n\t\treturn computeWGSLLogGamma(value + 1) - Math.log(value)\n\t}\n\tconst z = value - 1\n\tconst sum =\n\t\t0.999_999_999_999_809_9 +\n\t\t676.520_368_121_885_1 / (z + 1) -\n\t\t1259.139_216_722_402_8 / (z + 2) +\n\t\t771.323_428_777_653_1 / (z + 3) -\n\t\t176.615_029_162_140_6 / (z + 4) +\n\t\t12.507_343_278_686_905 / (z + 5) -\n\t\t0.138_571_095_265_720_12 / (z + 6) +\n\t\t9.984_369_578_019_572e-6 / (z + 7) +\n\t\t1.505_632_735_149_311_6e-7 / (z + 8)\n\tconst t = z + 7.5\n\treturn 0.918_938_533_204_672_7 + (z + 0.5) * Math.log(t) - t + Math.log(sum)\n}\n\n/**\n * Divides two complex numbers using overflow-safe Smith division, as `divideComplex` in `WGSL_COMPLEX` does.\n *\n * @remarks\n * Prescales operands near the `f64` overflow threshold so finite quotients up to `±Number.MAX_VALUE`\n * avoid intermediate overflow. Thrown with code `ARGUMENT` when `left` or `right` is not a dense\n * 2-tuple of numbers.\n *\n * @param left - The dividend `(real, imaginary)`\n * @param right - The divisor `(real, imaginary)`\n * @returns The quotient `(real, imaginary)`, frozen\n *\n * @example\n * ```ts\n * divideWGSLComplex([4, 2], [1, 1]) // [3, -1]\n * ```\n */\nexport function divideWGSLComplex(\n\tleft: readonly [number, number],\n\tright: readonly [number, number],\n): readonly [number, number] {\n\tif (\n\t\t!isArray(left) ||\n\t\tleft.length !== 2 ||\n\t\t!Object.hasOwn(left, 0) ||\n\t\t!Object.hasOwn(left, 1) ||\n\t\t!isNumber(left[0]) ||\n\t\t!isNumber(left[1])\n\t) {\n\t\tthrow new WGSLError(\n\t\t\t`A complex dividend must be a dense 2-tuple of numbers; received ${preview(left)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { left } },\n\t\t)\n\t}\n\tif (\n\t\t!isArray(right) ||\n\t\tright.length !== 2 ||\n\t\t!Object.hasOwn(right, 0) ||\n\t\t!Object.hasOwn(right, 1) ||\n\t\t!isNumber(right[0]) ||\n\t\t!isNumber(right[1])\n\t) {\n\t\tthrow new WGSLError(\n\t\t\t`A complex divisor must be a dense 2-tuple of numbers; received ${preview(right)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { right } },\n\t\t)\n\t}\n\tconst [rawA, rawB] = left\n\tconst [rawC, rawD] = right\n\tconst denomMax = Math.max(Math.abs(rawC), Math.abs(rawD))\n\tif (denomMax === 0) {\n\t\tconst zeroResult: readonly [number, number] = [rawA / rawC, rawB / rawC]\n\t\treturn Object.freeze(zeroResult)\n\t}\n\tconst numMax = Math.max(Math.abs(rawA), Math.abs(rawB))\n\tif (!Number.isFinite(rawC) && !Number.isFinite(rawD) && Number.isFinite(numMax)) {\n\t\tconst finiteOverInf: readonly [number, number] = [0, 0]\n\t\treturn Object.freeze(finiteOverInf)\n\t}\n\tconst scaleDenom = Number.isFinite(denomMax) && denomMax > 1e300\n\tconst scaleNumOnly = !scaleDenom && Number.isFinite(numMax) && numMax > 1e300\n\tconst a = scaleDenom || scaleNumOnly ? rawA * 0.25 : rawA\n\tconst b = scaleDenom || scaleNumOnly ? rawB * 0.25 : rawB\n\tconst c = scaleDenom ? rawC * 0.25 : rawC\n\tconst d = scaleDenom ? rawD * 0.25 : rawD\n\tconst post = scaleNumOnly ? 4 : 1\n\tif (Math.abs(c) >= Math.abs(d)) {\n\t\tconst ratio = d / c\n\t\tconst denom = c + d * ratio\n\t\tconst result: readonly [number, number] = [\n\t\t\t((a + b * ratio) / denom) * post,\n\t\t\t((b - a * ratio) / denom) * post,\n\t\t]\n\t\treturn Object.freeze(result)\n\t}\n\tconst ratio = c / d\n\tconst denom = d + c * ratio\n\tconst result: readonly [number, number] = [\n\t\t((a * ratio + b) / denom) * post,\n\t\t((b * ratio - a) / denom) * post,\n\t]\n\treturn Object.freeze(result)\n}\n\n/**\n * Multiplies two scalar-last (`xyzw`) Hamilton quaternions, as `multiplyQuaternion` in `WGSL_QUATERNION` does.\n *\n * @remarks\n * Thrown with code `ARGUMENT` when `left` or `right` is not a dense 4-tuple of numbers.\n *\n * @param left - The left quaternion `[x, y, z, w]`\n * @param right - The right quaternion `[x, y, z, w]`\n * @returns The product quaternion `[x, y, z, w]`, frozen\n *\n * @example\n * ```ts\n * multiplyWGSLQuaternion([1, 0, 0, 0], [0, 1, 0, 0]) // [0, 0, 1, 0]\n * ```\n */\nexport function multiplyWGSLQuaternion(\n\tleft: readonly [number, number, number, number],\n\tright: readonly [number, number, number, number],\n): readonly [number, number, number, number] {\n\tif (\n\t\t!isArray(left) ||\n\t\tleft.length !== 4 ||\n\t\t![0, 1, 2, 3].every((index) => Object.hasOwn(left, index) && isNumber(left[index]))\n\t) {\n\t\tthrow new WGSLError(\n\t\t\t`A left quaternion must be a dense 4-tuple of numbers; received ${preview(left)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { left } },\n\t\t)\n\t}\n\tif (\n\t\t!isArray(right) ||\n\t\tright.length !== 4 ||\n\t\t![0, 1, 2, 3].every((index) => Object.hasOwn(right, index) && isNumber(right[index]))\n\t) {\n\t\tthrow new WGSLError(\n\t\t\t`A right quaternion must be a dense 4-tuple of numbers; received ${preview(right)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { right } },\n\t\t)\n\t}\n\tconst [lx, ly, lz, lw] = left\n\tconst [rx, ry, rz, rw] = right\n\tconst result: readonly [number, number, number, number] = [\n\t\tlw * rx + lx * rw + ly * rz - lz * ry,\n\t\tlw * ry - lx * rz + ly * rw + lz * rx,\n\t\tlw * rz + lx * ry - ly * rx + lz * rw,\n\t\tlw * rw - lx * rx - ly * ry - lz * rz,\n\t]\n\treturn Object.freeze(result)\n}\n\n/**\n * Rotates a 3D vector by a scalar-last (`xyzw`) unit quaternion, as `rotateVector` in `WGSL_QUATERNION` does.\n *\n * @remarks\n * Evaluates `vector + w * t + cross(q.xyz, t)` with `t = 2 * cross(q.xyz, vector)`. Thrown with\n * code `ARGUMENT` when `rotation` is not a dense 4-tuple of numbers or `vector` is not a dense\n * 3-tuple of numbers.\n *\n * @param rotation - The unit quaternion `[x, y, z, w]`\n * @param vector - The 3D vector `[x, y, z]`\n * @returns The rotated 3D vector `[x, y, z]`, frozen\n *\n * @example\n * ```ts\n * rotateWGSLVector([0, 0, 0, 1], [1, 2, 3]) // [1, 2, 3]\n * ```\n */\nexport function rotateWGSLVector(\n\trotation: readonly [number, number, number, number],\n\tvector: readonly [number, number, number],\n): readonly [number, number, number] {\n\tif (\n\t\t!isArray(rotation) ||\n\t\trotation.length !== 4 ||\n\t\t![0, 1, 2, 3].every((index) => Object.hasOwn(rotation, index) && isNumber(rotation[index]))\n\t) {\n\t\tthrow new WGSLError(\n\t\t\t`A rotation quaternion must be a dense 4-tuple of numbers; received ${preview(rotation)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { rotation } },\n\t\t)\n\t}\n\tif (\n\t\t!isArray(vector) ||\n\t\tvector.length !== 3 ||\n\t\t![0, 1, 2].every((index) => Object.hasOwn(vector, index) && isNumber(vector[index]))\n\t) {\n\t\tthrow new WGSLError(\n\t\t\t`A vector to rotate must be a dense 3-tuple of numbers; received ${preview(vector)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { vector } },\n\t\t)\n\t}\n\tconst [qx, qy, qz, qw] = rotation\n\tconst [vx, vy, vz] = vector\n\tconst tx = 2 * (qy * vz - qz * vy)\n\tconst ty = 2 * (qz * vx - qx * vz)\n\tconst tz = 2 * (qx * vy - qy * vx)\n\tconst result: readonly [number, number, number] = [\n\t\tvx + qw * tx + (qy * tz - qz * ty),\n\t\tvy + qw * ty + (qz * tx - qx * tz),\n\t\tvz + qw * tz + (qx * ty - qy * tx),\n\t]\n\treturn Object.freeze(result)\n}\n\n/**\n * Inverts a column-major `3x3` matrix, as `invertMatrix3` in `WGSL_MATRIX` does.\n *\n * @remarks\n * Reads the 9-tuple in WGSL `mat3x3f` column-major order (`[c0.x, c0.y, c0.z, c1.x, c1.y, c1.z,\n * c2.x, c2.y, c2.z]`). Singular inputs produce non-finite components from division by zero,\n * matching `invertMatrix3`. Thrown with code `ARGUMENT` when `elements` is not a dense 9-tuple of\n * numbers.\n *\n * @param elements - The column-major 9-tuple of matrix entries\n * @returns The column-major 9-tuple of inverse matrix entries, frozen\n *\n * @example\n * ```ts\n * invertWGSLMatrix3([2, 0, 0, 0, 4, 0, 0, 0, 8])[0] // 0.5\n * ```\n */\nexport function invertWGSLMatrix3(\n\telements: readonly [number, number, number, number, number, number, number, number, number],\n): readonly [number, number, number, number, number, number, number, number, number] {\n\tif (\n\t\t!isArray(elements) ||\n\t\telements.length !== 9 ||\n\t\t![0, 1, 2, 3, 4, 5, 6, 7, 8].every(\n\t\t\t(index) => Object.hasOwn(elements, index) && isNumber(elements[index]),\n\t\t)\n\t) {\n\t\tthrow new WGSLError(\n\t\t\t`A 3x3 matrix must be a dense 9-tuple of numbers; received ${preview(elements)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { elements } },\n\t\t)\n\t}\n\tconst [m0, m1, m2, m3, m4, m5, m6, m7, m8] = elements\n\tconst r0x = m4 * m8 - m5 * m7\n\tconst r0y = m5 * m6 - m3 * m8\n\tconst r0z = m3 * m7 - m4 * m6\n\tconst r1x = m7 * m2 - m8 * m1\n\tconst r1y = m8 * m0 - m6 * m2\n\tconst r1z = m6 * m1 - m7 * m0\n\tconst r2x = m1 * m5 - m2 * m4\n\tconst r2y = m2 * m3 - m0 * m5\n\tconst r2z = m0 * m4 - m1 * m3\n\tconst invDet = 1 / (m0 * r0x + m1 * r0y + m2 * r0z)\n\tconst result: readonly [number, number, number, number, number, number, number, number, number] =\n\t\t[\n\t\t\tr0x * invDet,\n\t\t\tr1x * invDet,\n\t\t\tr2x * invDet,\n\t\t\tr0y * invDet,\n\t\t\tr1y * invDet,\n\t\t\tr2y * invDet,\n\t\t\tr0z * invDet,\n\t\t\tr1z * invDet,\n\t\t\tr2z * invDet,\n\t\t]\n\treturn Object.freeze(result)\n}\n\n/**\n * Encodes a 16-bit 2D grid coordinate into a 32-bit Morton Z-order code, as `encodeMorton2` in `WGSL_MORTON` does.\n *\n * @remarks\n * Interleaves `x` into even bits and `y` into odd bits. Thrown with code `ARGUMENT` when `x` or\n * `y` is not a non-negative integer from `0` to `65535`, `-0` included.\n *\n * @param x - The 16-bit unsigned x coordinate\n * @param y - The 16-bit unsigned y coordinate\n * @returns The 32-bit unsigned Morton code\n *\n * @example\n * ```ts\n * encodeWGSLMorton2(1, 2) // 9\n * ```\n */\nexport function encodeWGSLMorton2(x: number, y: number): number {\n\tif (!isNonNegativeInteger(x) || x > 0xffff) {\n\t\tthrow new WGSLError(\n\t\t\t`A 2D Morton x coordinate must be an integer from 0 to 65535; received ${preview(x)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { x } },\n\t\t)\n\t}\n\tif (!isNonNegativeInteger(y) || y > 0xffff) {\n\t\tthrow new WGSLError(\n\t\t\t`A 2D Morton y coordinate must be an integer from 0 to 65535; received ${preview(y)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { y } },\n\t\t)\n\t}\n\tconst x1 = (x | (x << 8)) & 0x00ff_00ff\n\tconst x2 = (x1 | (x1 << 4)) & 0x0f0f_0f0f\n\tconst x3 = (x2 | (x2 << 2)) & 0x3333_3333\n\tconst sx = (x3 | (x3 << 1)) & 0x5555_5555\n\tconst y1 = (y | (y << 8)) & 0x00ff_00ff\n\tconst y2 = (y1 | (y1 << 4)) & 0x0f0f_0f0f\n\tconst y3 = (y2 | (y2 << 2)) & 0x3333_3333\n\tconst sy = (y3 | (y3 << 1)) & 0x5555_5555\n\treturn (sx | (sy << 1)) >>> 0\n}\n\n/**\n * Decodes a 32-bit Morton Z-order code into 16-bit 2D grid coordinates, as `decodeMorton2` in `WGSL_MORTON` does.\n *\n * @remarks\n * Inverts `encodeWGSLMorton2` across all 32-bit codes. Thrown with code `ARGUMENT` when `code` is\n * not an unsigned 32-bit integer from `0` to `0xffffffff`, `-0` included.\n *\n * @param code - The 32-bit unsigned Morton code\n * @returns The decoded `[x, y]` coordinate pair, frozen\n *\n * @example\n * ```ts\n * decodeWGSLMorton2(9) // [1, 2]\n * ```\n */\nexport function decodeWGSLMorton2(code: number): readonly [number, number] {\n\tif (!isNonNegativeInteger(code) || code > 0xffff_ffff) {\n\t\tthrow new WGSLError(\n\t\t\t`A Morton code must be an integer from 0 to 0xffffffff; received ${preview(code)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { code } },\n\t\t)\n\t}\n\tconst x0 = code & 0x5555_5555\n\tconst x1 = (x0 | (x0 >>> 1)) & 0x3333_3333\n\tconst x2 = (x1 | (x1 >>> 2)) & 0x0f0f_0f0f\n\tconst x3 = (x2 | (x2 >>> 4)) & 0x00ff_00ff\n\tconst x = (x3 | (x3 >>> 8)) & 0x0000_ffff\n\tconst y0 = (code >>> 1) & 0x5555_5555\n\tconst y1 = (y0 | (y0 >>> 1)) & 0x3333_3333\n\tconst y2 = (y1 | (y1 >>> 2)) & 0x0f0f_0f0f\n\tconst y3 = (y2 | (y2 >>> 4)) & 0x00ff_00ff\n\tconst y = (y3 | (y3 >>> 8)) & 0x0000_ffff\n\tconst point: readonly [number, number] = [x, y]\n\treturn Object.freeze(point)\n}\n\n/**\n * Encodes a 10-bit 3D grid coordinate into a 30-bit Morton Z-order code, as `encodeMorton3` in `WGSL_MORTON` does.\n *\n * @remarks\n * Interleaves `x`, `y`, and `z` into bit lanes `3k`, `3k + 1`, and `3k + 2`. Thrown with code\n * `ARGUMENT` when `x`, `y`, or `z` is not a non-negative integer from `0` to `1023`, `-0` included.\n *\n * @param x - The 10-bit unsigned x coordinate\n * @param y - The 10-bit unsigned y coordinate\n * @param z - The 10-bit unsigned z coordinate\n * @returns The 30-bit unsigned Morton code\n *\n * @example\n * ```ts\n * encodeWGSLMorton3(1, 2, 3) // 53\n * ```\n */\nexport function encodeWGSLMorton3(x: number, y: number, z: number): number {\n\tif (!isNonNegativeInteger(x) || x > 0x3ff) {\n\t\tthrow new WGSLError(\n\t\t\t`A 3D Morton x coordinate must be an integer from 0 to 1023; received ${preview(x)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { x } },\n\t\t)\n\t}\n\tif (!isNonNegativeInteger(y) || y > 0x3ff) {\n\t\tthrow new WGSLError(\n\t\t\t`A 3D Morton y coordinate must be an integer from 0 to 1023; received ${preview(y)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { y } },\n\t\t)\n\t}\n\tif (!isNonNegativeInteger(z) || z > 0x3ff) {\n\t\tthrow new WGSLError(\n\t\t\t`A 3D Morton z coordinate must be an integer from 0 to 1023; received ${preview(z)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { z } },\n\t\t)\n\t}\n\tconst x1 = (x | (x << 16)) & 0x0300_00ff\n\tconst x2 = (x1 | (x1 << 8)) & 0x0300_f00f\n\tconst x3 = (x2 | (x2 << 4)) & 0x030c_30c3\n\tconst sx = (x3 | (x3 << 2)) & 0x0924_9249\n\tconst y1 = (y | (y << 16)) & 0x0300_00ff\n\tconst y2 = (y1 | (y1 << 8)) & 0x0300_f00f\n\tconst y3 = (y2 | (y2 << 4)) & 0x030c_30c3\n\tconst sy = (y3 | (y3 << 2)) & 0x0924_9249\n\tconst z1 = (z | (z << 16)) & 0x0300_00ff\n\tconst z2 = (z1 | (z1 << 8)) & 0x0300_f00f\n\tconst z3 = (z2 | (z2 << 4)) & 0x030c_30c3\n\tconst sz = (z3 | (z3 << 2)) & 0x0924_9249\n\treturn (sx | (sy << 1) | (sz << 2)) >>> 0\n}\n\n/**\n * Decodes a 32-bit Morton Z-order code into 10-bit 3D grid coordinates, as `decodeMorton3` in `WGSL_MORTON` does.\n *\n * @remarks\n * Reads the low 30 interleaved bits into `[x, y, z]`, inverting `encodeWGSLMorton3`. Thrown with\n * code `ARGUMENT` when `code` is not an unsigned 32-bit integer from `0` to `0xffffffff`, `-0`\n * included.\n *\n * @param code - The 32-bit unsigned Morton code\n * @returns The decoded `[x, y, z]` coordinate triple, frozen\n *\n * @example\n * ```ts\n * decodeWGSLMorton3(53) // [1, 2, 3]\n * ```\n */\nexport function decodeWGSLMorton3(code: number): readonly [number, number, number] {\n\tif (!isNonNegativeInteger(code) || code > 0xffff_ffff) {\n\t\tthrow new WGSLError(\n\t\t\t`A Morton code must be an integer from 0 to 0xffffffff; received ${preview(code)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { code } },\n\t\t)\n\t}\n\tconst x0 = code & 0x0924_9249\n\tconst x1 = (x0 | (x0 >>> 2)) & 0x030c_30c3\n\tconst x2 = (x1 | (x1 >>> 4)) & 0x0300_f00f\n\tconst x3 = (x2 | (x2 >>> 8)) & 0x0300_00ff\n\tconst x = (x3 | (x3 >>> 16)) & 0x0000_03ff\n\tconst y0 = (code >>> 1) & 0x0924_9249\n\tconst y1 = (y0 | (y0 >>> 2)) & 0x030c_30c3\n\tconst y2 = (y1 | (y1 >>> 4)) & 0x0300_f00f\n\tconst y3 = (y2 | (y2 >>> 8)) & 0x0300_00ff\n\tconst y = (y3 | (y3 >>> 16)) & 0x0000_03ff\n\tconst z0 = (code >>> 2) & 0x0924_9249\n\tconst z1 = (z0 | (z0 >>> 2)) & 0x030c_30c3\n\tconst z2 = (z1 | (z1 >>> 4)) & 0x0300_f00f\n\tconst z3 = (z2 | (z2 >>> 8)) & 0x0300_00ff\n\tconst z = (z3 | (z3 >>> 16)) & 0x0000_03ff\n\tconst point: readonly [number, number, number] = [x, y, z]\n\treturn Object.freeze(point)\n}\n\n/**\n * Encodes an IEEE-754 `f64` number into a frozen `WGSLFloatPair` (`head`, `tail`) for `WGSL_DOUBLE`.\n *\n * @remarks\n * Sets `head = Math.fround(value)` and `tail = Math.fround(value - head)` for finite `f32` heads.\n * Non-finite heads (`±Infinity`, `NaN`, and finite values past the `f32` overflow threshold) set\n * `tail` to `0` so `decodeWGSLDouble` recovers `head` without `Infinity - Infinity` cancellation;\n * `-0` encodes as `{ head: -0, tail: -0 }` so `-0` round-trips through `decodeWGSLDouble`. Thrown\n * with code `ARGUMENT` when `value` is not a number.\n *\n * @param value - The double-precision number to split\n * @returns The frozen `{ head, tail }` pair\n *\n * @example\n * ```ts\n * encodeWGSLDouble(1.5) // { head: 1.5, tail: 0 }\n * ```\n */\nexport function encodeWGSLDouble(value: number): WGSLFloatPair {\n\tif (!isNumber(value)) {\n\t\tthrow new WGSLError(`A double value to encode must be a number; received ${preview(value)}.`, {\n\t\t\tcode: 'ARGUMENT',\n\t\t\tcontext: { value },\n\t\t})\n\t}\n\tif (Object.is(value, -0)) {\n\t\treturn Object.freeze({ head: -0, tail: -0 })\n\t}\n\tconst head = Math.fround(value)\n\tif (!Number.isFinite(head)) {\n\t\treturn Object.freeze({ head, tail: 0 })\n\t}\n\tconst tail = Math.fround(value - head)\n\treturn Object.freeze({ head, tail })\n}\n\n/**\n * Decodes a `WGSLFloatPair` back into an IEEE-754 `f64` number as `pair.head + pair.tail`.\n *\n * @remarks\n * Validates `pair` with `isWGSLFloatPair` so non-records, missing or extra keys, non-numbers, and\n * finite values past `±3.4028234663852886e38` throw with code `ARGUMENT`.\n *\n * @param pair - The float pair to sum\n * @returns The combined `f64` value\n *\n * @example\n * ```ts\n * decodeWGSLDouble(encodeWGSLDouble(Math.PI)) // 3.1415926535897967\n * ```\n */\nexport function decodeWGSLDouble(pair: WGSLFloatPair): number {\n\tif (!isWGSLFloatPair(pair)) {\n\t\tthrow new WGSLError(\n\t\t\t`A float pair must have f32-bounded numeric head and tail fields; received ${preview(pair)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { pair } },\n\t\t)\n\t}\n\treturn pair.head + pair.tail\n}\n\n/**\n * Widens OCP FP8 `E4M3FN` bits to the `f32` value they hold, as `widenE4M3` in `WGSL_FP8` does.\n *\n * @remarks\n * Decodes signed zeros (`0x00`/`0x80`), subnormals (`2^-9` to `7 * 2^-9`), normals up to `±448`,\n * and `NaN` (`0x7f`/`0xff`). Thrown with code `ARGUMENT` when `bits` is not a non-negative integer\n * from `0` to `255`, `-0` included.\n *\n * @param bits - The 8-bit `E4M3FN` pattern\n * @returns The widened numeric value\n *\n * @example\n * ```ts\n * widenWGSLE4M3(0x38) // 1\n * ```\n */\nexport function widenWGSLE4M3(bits: number): number {\n\tif (!isNonNegativeInteger(bits) || bits > 0xff) {\n\t\tthrow new WGSLError(\n\t\t\t`E4M3FN bits must be an integer from 0 to 255; received ${preview(bits)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { bits } },\n\t\t)\n\t}\n\tconst signBit = (bits & 0x80) << 24\n\tconst exponent = (bits >>> 3) & 0x0f\n\tconst fraction = bits & 0x07\n\tif (exponent === 0x0f && fraction === 0x07) return Number.NaN\n\tconst top = 31 - Math.clz32(fraction)\n\tconst word =\n\t\texponent !== 0\n\t\t\t? signBit | ((exponent + 120) << 23) | (fraction << 20)\n\t\t\t: fraction === 0\n\t\t\t\t? signBit\n\t\t\t\t: signBit | ((top + 118) << 23) | ((fraction << (23 - top)) & 0x7f_ffff)\n\tconst view = new DataView(new ArrayBuffer(4))\n\tview.setUint32(0, word >>> 0)\n\treturn view.getFloat32(0)\n}\n\n/**\n * Narrows a number to OCP FP8 `E4M3FN` bits with round-to-nearest-even and finite saturation, as `narrowE4M3` in `WGSL_FP8` does.\n *\n * @remarks\n * Rounds first to `f32`, then rounds ties to even into `E4M3FN`: `-0` maps to `0x80`, magnitudes\n * at or above `448` (including `±Infinity`) saturate to `0x7e`/`0xfe`, and `NaN` maps to `0x7f`.\n * Thrown with code `ARGUMENT` when `value` is not a number.\n *\n * @param value - The value to narrow\n * @returns The 8-bit `E4M3FN` pattern, from `0` to `255`\n *\n * @example\n * ```ts\n * narrowWGSLE4M3(448) // 0x7e\n * ```\n */\nexport function narrowWGSLE4M3(value: number): number {\n\tif (!isNumber(value)) {\n\t\tthrow new WGSLError(`A value to narrow must be a number; received ${preview(value)}.`, {\n\t\t\tcode: 'ARGUMENT',\n\t\t\tcontext: { value },\n\t\t})\n\t}\n\tconst view = new DataView(new ArrayBuffer(4))\n\tview.setFloat32(0, value)\n\tconst bits = Number.isNaN(value) ? 0x7fc0_0000 : view.getUint32(0)\n\tconst signBit = (bits >>> 24) & 0x80\n\tconst magnitude = bits & 0x7fff_ffff\n\tif (magnitude > 0x7f80_0000) return signBit | 0x7f\n\tif (magnitude >= 0x43e0_0000) return signBit | 0x7e\n\tif (magnitude >= 0x3c80_0000) {\n\t\treturn signBit | ((magnitude + 0x7_ffff + ((magnitude >>> 20) & 1) - 0x3c00_0000) >>> 20)\n\t}\n\tif (magnitude <= 0x3a80_0000) return signBit\n\tconst shift = 141 - (magnitude >>> 23)\n\tconst mantissa = (magnitude & 0x7f_ffff) | 0x80_0000\n\tconst kept = mantissa >>> shift\n\tconst rest = mantissa & ((1 << shift) - 1)\n\tconst midpoint = 1 << (shift - 1)\n\tconst up = rest > midpoint || (rest === midpoint && (kept & 1) === 1)\n\treturn signBit | (kept + (up ? 1 : 0))\n}\n\n/**\n * Widens OCP FP8 `E5M2` bits to the `f32` value they hold, as `widenE5M2` in `WGSL_FP8` does.\n *\n * @remarks\n * Decodes signed zeros (`0x00`/`0x80`), subnormals (`2^-16` to `3 * 2^-16`), normals up to\n * `±57344`, `±Infinity` (`0x7c`/`0xfc`), and `NaN` (`0x7d..0x7f`, `0xfd..0xff`). Thrown with code\n * `ARGUMENT` when `bits` is not a non-negative integer from `0` to `255`, `-0` included.\n *\n * @param bits - The 8-bit `E5M2` pattern\n * @returns The widened numeric value\n *\n * @example\n * ```ts\n * widenWGSLE5M2(0x3c) // 1\n * ```\n */\nexport function widenWGSLE5M2(bits: number): number {\n\tif (!isNonNegativeInteger(bits) || bits > 0xff) {\n\t\tthrow new WGSLError(`E5M2 bits must be an integer from 0 to 255; received ${preview(bits)}.`, {\n\t\t\tcode: 'ARGUMENT',\n\t\t\tcontext: { bits },\n\t\t})\n\t}\n\tconst signBit = (bits & 0x80) << 24\n\tconst exponent = (bits >>> 2) & 0x1f\n\tconst fraction = bits & 0x03\n\tconst top = 31 - Math.clz32(fraction)\n\tconst word =\n\t\texponent === 0x1f\n\t\t\t? signBit | 0x7f80_0000 | (fraction << 21)\n\t\t\t: exponent !== 0\n\t\t\t\t? signBit | ((exponent + 112) << 23) | (fraction << 21)\n\t\t\t\t: fraction === 0\n\t\t\t\t\t? signBit\n\t\t\t\t\t: signBit | ((top + 111) << 23) | ((fraction << (23 - top)) & 0x7f_ffff)\n\tconst view = new DataView(new ArrayBuffer(4))\n\tview.setUint32(0, word >>> 0)\n\treturn view.getFloat32(0)\n}\n\n/**\n * Narrows a number to OCP FP8 `E5M2` bits with IEEE-754 round-to-nearest-even, as `narrowE5M2` in `WGSL_FP8` does.\n *\n * @remarks\n * Rounds first to `f32`, then rounds ties to even into `E5M2`: `-0` maps to `0x80`, magnitudes at\n * or above `61440` overflow to `±Infinity` (`0x7c`/`0xfc`), and `NaN` maps to `0x7e`. Thrown with\n * code `ARGUMENT` when `value` is not a number.\n *\n * @param value - The value to narrow\n * @returns The 8-bit `E5M2` pattern, from `0` to `255`\n *\n * @example\n * ```ts\n * narrowWGSLE5M2(61_440) // 0x7c\n * ```\n */\nexport function narrowWGSLE5M2(value: number): number {\n\tif (!isNumber(value)) {\n\t\tthrow new WGSLError(`A value to narrow must be a number; received ${preview(value)}.`, {\n\t\t\tcode: 'ARGUMENT',\n\t\t\tcontext: { value },\n\t\t})\n\t}\n\tconst view = new DataView(new ArrayBuffer(4))\n\tview.setFloat32(0, value)\n\tconst bits = Number.isNaN(value) ? 0x7fc0_0000 : view.getUint32(0)\n\tconst signBit = (bits >>> 24) & 0x80\n\tconst magnitude = bits & 0x7fff_ffff\n\tif (magnitude > 0x7f80_0000) return signBit | 0x7e | ((magnitude >>> 21) & 0x03)\n\tif (magnitude >= 0x4770_0000) return signBit | 0x7c\n\tif (magnitude >= 0x3880_0000) {\n\t\treturn signBit | ((magnitude + 0xf_ffff + ((magnitude >>> 21) & 1) - 0x3800_0000) >>> 21)\n\t}\n\tif (magnitude <= 0x3700_0000) return signBit\n\tconst shift = 134 - (magnitude >>> 23)\n\tconst mantissa = (magnitude & 0x7f_ffff) | 0x80_0000\n\tconst kept = mantissa >>> shift\n\tconst rest = mantissa & ((1 << shift) - 1)\n\tconst midpoint = 1 << (shift - 1)\n\tconst up = rest > midpoint || (rest === midpoint && (kept & 1) === 1)\n\treturn signBit | (kept + (up ? 1 : 0))\n}\n\n/**\n * Samples one radical-inverse Halton coordinate strictly in `[0, 1)`, as `sampleHalton` in `WGSL_QUASI` does.\n *\n * @remarks\n * Base `2` takes the top 24 reversed bits scaled by `2^-24`, matching `sampleVanDerCorput`\n * bit-for-bit; larger bases clamp at `1 - 2^-24` (`0.9999999403953552`) so rounding never reaches\n * `1.0`. Thrown with code `ARGUMENT` when `index` is not an unsigned 32-bit integer (`-0` refused)\n * or `base` is not an integer from `2` to `0xffffffff` (`-0` refused).\n *\n * @param index - The 0-based sequence index (`0` to `0xffffffff`)\n * @param base - The integer radix (`2` to `0xffffffff`)\n * @returns The sample strictly in `[0, 1)`\n *\n * @example\n * ```ts\n * sampleWGSLHalton(1, 2) // 0.5\n * ```\n */\nexport function sampleWGSLHalton(index: number, base: number): number {\n\tif (!isNonNegativeInteger(index) || index > 0xffff_ffff) {\n\t\tthrow new WGSLError(\n\t\t\t`A Halton index must be an integer from 0 to 0xffffffff; received ${preview(index)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { index } },\n\t\t)\n\t}\n\tif (!isNonNegativeInteger(base) || base < 2 || base > 0xffff_ffff) {\n\t\tthrow new WGSLError(\n\t\t\t`A Halton base must be an integer from 2 to 0xffffffff; received ${preview(base)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { base } },\n\t\t)\n\t}\n\tif (index === 0) return 0\n\tif (base === 2) {\n\t\tconst b1 = ((index >>> 1) & 0x5555_5555) | ((index & 0x5555_5555) << 1)\n\t\tconst b2 = ((b1 >>> 2) & 0x3333_3333) | ((b1 & 0x3333_3333) << 2)\n\t\tconst b4 = ((b2 >>> 4) & 0x0f0f_0f0f) | ((b2 & 0x0f0f_0f0f) << 4)\n\t\tconst b8 = ((b4 >>> 8) & 0x00ff_00ff) | ((b4 & 0x00ff_00ff) << 8)\n\t\tconst reversed = ((b8 >>> 16) | (b8 << 16)) >>> 0\n\t\treturn (reversed >>> 8) * 5.960_464_477_539_063e-8\n\t}\n\tconst [sum] = Array.from({ length: 21 }).reduce<\n\t\treadonly [acc: number, rem: number, factor: number]\n\t>(\n\t\t([acc, rem, factor]) => {\n\t\t\tif (rem === 0) return [acc, 0, factor]\n\t\t\tconst nextFactor = factor / base\n\t\t\treturn [acc + (rem % base) * nextFactor, Math.floor(rem / base), nextFactor]\n\t\t},\n\t\t[0, index, 1],\n\t)\n\treturn Math.min(sum, 0.999_999_940_395_355_2)\n}\n\n/**\n * Samples one 2D plastic-constant (`R2`) quasi-random point strictly in `[0, 1)^2`, as `samplePlastic2` in `WGSL_QUASI` does.\n *\n * @remarks\n * Uses 32-bit fixed-point Weyl recurrence (`0x80000000 + index * 0xc13fa9a9`,\n * `0x80000000 + index * 0x91e10da5`) truncated to the top 24 bits and scaled by `2^-24`, matching\n * `samplePlastic2` bit-for-bit up to `index = 0xffffffff`. Thrown with code `ARGUMENT` when `index`\n * is not an unsigned 32-bit integer, `-0` included.\n *\n * @param index - The 0-based sequence index (`0` to `0xffffffff`)\n * @returns The 2D sample strictly in `[0, 1)^2`, frozen\n *\n * @example\n * ```ts\n * sampleWGSLPlastic2(0) // [0.5, 0.5]\n * ```\n */\nexport function sampleWGSLPlastic2(index: number): readonly [number, number] {\n\tif (!isNonNegativeInteger(index) || index > 0xffff_ffff) {\n\t\tthrow new WGSLError(\n\t\t\t`A Plastic2 index must be an integer from 0 to 0xffffffff; received ${preview(index)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { index } },\n\t\t)\n\t}\n\tconst x = ((0x8000_0000 + Math.imul(index, 0xc13f_a9a9)) >>> 8) * 5.960_464_477_539_063e-8\n\tconst y = ((0x8000_0000 + Math.imul(index, 0x91e1_0da5)) >>> 8) * 5.960_464_477_539_063e-8\n\tconst point: readonly [number, number] = [x, y]\n\treturn Object.freeze(point)\n}\n\n/**\n * Samples one 2D Sobol quasi-random point strictly in `[0, 1)^2`, as `sampleSobol2` in `WGSL_QUASI` does.\n *\n * @remarks\n * Computes dimension 0 from reversed index bits and dimension 1 from the Sobol primitive-polynomial\n * direction recurrence `v = v ^ (v >> 1)`, truncating both to the top 24 bits scaled by `2^-24` so\n * every output matches `sampleSobol2` bit-for-bit and stays strictly in `[0, 1)`. Thrown with code\n * `ARGUMENT` when `index` is not an unsigned 32-bit integer, `-0` included.\n *\n * @param index - The 0-based sequence index (`0` to `0xffffffff`)\n * @returns The 2D sample strictly in `[0, 1)^2`, frozen\n *\n * @example\n * ```ts\n * sampleWGSLSobol2(1) // [0.5, 0.5]\n * ```\n */\nexport function sampleWGSLSobol2(index: number): readonly [number, number] {\n\tif (!isNonNegativeInteger(index) || index > 0xffff_ffff) {\n\t\tthrow new WGSLError(\n\t\t\t`A Sobol2 index must be an integer from 0 to 0xffffffff; received ${preview(index)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { index } },\n\t\t)\n\t}\n\tconst b1 = ((index >>> 1) & 0x5555_5555) | ((index & 0x5555_5555) << 1)\n\tconst b2 = ((b1 >>> 2) & 0x3333_3333) | ((b1 & 0x3333_3333) << 2)\n\tconst b4 = ((b2 >>> 4) & 0x0f0f_0f0f) | ((b2 & 0x0f0f_0f0f) << 4)\n\tconst b8 = ((b4 >>> 8) & 0x00ff_00ff) | ((b4 & 0x00ff_00ff) << 8)\n\tconst bits0 = ((b8 >>> 16) | (b8 << 16)) >>> 0\n\tconst bitCount = index === 0 ? 0 : 32 - Math.clz32(index)\n\tconst [bits1] = Array.from({ length: bitCount }).reduce<\n\t\treadonly [acc: number, direction: number, rem: number]\n\t>(\n\t\t([acc, direction, rem]) => [\n\t\t\t(rem & 1) !== 0 ? (acc ^ direction) >>> 0 : acc,\n\t\t\t(direction ^ (direction >>> 1)) >>> 0,\n\t\t\trem >>> 1,\n\t\t],\n\t\t[0, 0x8000_0000, index],\n\t)\n\tconst x = (bits0 >>> 8) * 5.960_464_477_539_063e-8\n\tconst y = (bits1 >>> 8) * 5.960_464_477_539_063e-8\n\tconst point: readonly [number, number] = [x, y]\n\treturn Object.freeze(point)\n}\n","import type {\n\tWGSLBatchInterface,\n\tWGSLBatchOptions,\n\tWGSLBatchStatus,\n\tWGSLBinding,\n\tWGSLByteSource,\n\tWGSLFieldMap,\n\tWGSLGrid,\n\tWGSLOverrideMap,\n\tWGSLRead,\n\tWGSLReadRange,\n\tWGSLSlabInterface,\n\tWGSLSlice,\n\tWGSLSlotMap,\n\tWGSLSpan,\n\tWGSLStruct,\n\tWGSLTraceCause,\n\tWGSLTraceMode,\n\tWGSLTracePass,\n\tWGSLTraceRecord,\n\tWGSLTraceStatement,\n\tWGSLValueMap,\n} from './types.js'\nimport {\n\terrorToMessage,\n\tisArray,\n\tisArrayBuffer,\n\tisArrayBufferView,\n\tisNonNegativeInteger,\n\tisObject,\n\tisSafeInteger,\n\tpreview,\n} from '@orkestrel/contract'\nimport { WGSL_MAP, WGSL_USAGE } from './constants.js'\nimport { WGSLError, isWGSLError } from './errors.js'\n\n/**\n * Records one command encoder's worth of dispatches, writes, copies, clears, and 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`, `write`, `copy`, `clear`, and `flush`; `write` flushes earlier recorded\n * commands before invoking `queue.writeBuffer` so subsequent commands observe the uploaded bytes in\n * recording order. Every upload, write, and submit sits between a synchronous push and pop of a\n * `validation` and an `out-of-memory` error scope; a device error moves the session to `failed`\n * with code `VALIDATION`. `read` accepts either one `(buffer, offset, size)` range or an array of\n * `WGSLSpan` ranges copied into one coalesced staging buffer, maps its staging buffer alongside\n * submission settlement, and resolves after submission to caller-owned `ArrayBuffer` copies. Each\n * `read`, `write`, `copy`, and `clear` checks the session, the batch, its buffers' usages, and its\n * offsets, sizes, and ranges before it records anything, so a refused call leaves the open pass in\n * place. `abort` restores unsubmitted staging buffers synchronously and defers restoring flushed\n * staging buffers until earlier submissions finish draining.\n * Thrown with code `VALIDATION` when a call other than `abort` or `execute` arrives after `submit`\n * or `abort`; with code `ARGUMENT` for a malformed grid, a malformed `read`, `write`, `copy`, or\n * `clear` argument, a buffer without the usage the call needs, or a `copy` between one buffer and\n * itself; with code `DESTROYED` after the session's `destroy`; and with code `LIMIT` when a grid\n * axis passes `maxComputeWorkgroupsPerDimension` or a read total passes `maxBufferSize`. Open a\n * batch through `session.batch()`, which supplies the 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\treadonly #mode: WGSLTraceMode\n\treadonly #capacity: number\n\treadonly #passes: WGSLTracePass[] | undefined\n\treadonly #names: string[] | undefined\n\treadonly #counts: Map<string, number> | undefined\n\treadonly #swaps: Map<string, number> | 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#struct: WGSLStruct | undefined\n\t#uniform: GPUBindGroup | undefined\n\t#status: WGSLBatchStatus = 'open'\n\t#aborted = false\n\t#recorded = false\n\t#flushedReads = 0\n\t#index: number | undefined\n\t#dispatched = 0\n\t#switched = 0\n\t#flushes = 0\n\t#dispatches = 0\n\t#copies = 0\n\t#clears = 0\n\t#writes = 0\n\t#bytes = 0\n\t#switches = 0\n\t#dropped = 0\n\t#stamps: GPUBuffer | undefined\n\t#trace: WGSLTraceRecord | undefined\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, the session hooks, and the session's tracer\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.#mode = options.trace.mode\n\t\tthis.#capacity = options.trace.capacity\n\t\tif (options.trace.mode !== 'off') {\n\t\t\tthis.#passes = []\n\t\t\tthis.#names = []\n\t\t\tthis.#counts = new Map()\n\t\t\tthis.#swaps = new Map()\n\t\t}\n\t\tthis.#encoder = device.createCommandEncoder()\n\t}\n\n\tget submitted(): boolean {\n\t\treturn this.#status === 'submitted'\n\t}\n\n\tget trace(): WGSLTraceRecord | undefined {\n\t\treturn this.#trace\n\t}\n\n\tencode<S extends WGSLSlotMap, F extends WGSLFieldMap, O extends WGSLOverrideMap>(\n\t\tbinding: WGSLBinding<S, F, O>,\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\tconst limit = this.#limit\n\t\tif (\n\t\t\t(x | 0) !== x ||\n\t\t\tx < 1 ||\n\t\t\tx > limit ||\n\t\t\t(y | 0) !== y ||\n\t\t\ty < 1 ||\n\t\t\ty > limit ||\n\t\t\t(z | 0) !== z ||\n\t\t\tz < 1 ||\n\t\t\tz > limit\n\t\t) {\n\t\t\tthis.#checkGrid(grid, x, y, z)\n\t\t}\n\t\tconst cached = this.#binding === binding\n\t\tconst struct =\n\t\t\tcached && this.#struct !== undefined ? this.#struct : binding.statement.program.uniform.struct\n\t\tconst written = this.#slab.write(struct, values)\n\t\tif (written !== undefined && cached) {\n\t\t\tconst pass = this.#pass\n\t\t\tconst uniform = this.#uniform\n\t\t\tif (pass !== undefined && uniform !== undefined) {\n\t\t\t\tthis.#offsets[0] = written\n\t\t\t\tpass.setBindGroup(1, uniform, this.#offsets, 0, 1)\n\t\t\t\tpass.dispatchWorkgroups(x, y, z)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t\tconst offset = written === undefined ? this.#flushWrite(struct, values) : written\n\t\tconst { statement } = binding\n\t\tconst pass = this.#pass ?? this.#open()\n\t\tconst previous = this.#pipeline\n\t\tif (previous !== 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.#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\tthis.#recorded = true\n\t\t// A traced batch never caches the binding, so every traced dispatch reaches this count and the fast path above stays untouched.\n\t\tif (this.#mode === 'off') {\n\t\t\tthis.#binding = binding\n\t\t\tthis.#struct = struct\n\t\t} else {\n\t\t\tthis.#note(statement.program.name, previous !== undefined && previous !== statement.pipeline)\n\t\t}\n\t}\n\n\tread(buffer: GPUBuffer, offset: number, size: number): Promise<ArrayBuffer>\n\tread(spans: readonly WGSLSpan[]): Promise<readonly ArrayBuffer[]>\n\tread(\n\t\ttarget: GPUBuffer | readonly WGSLSpan[],\n\t\toffset?: number,\n\t\tsize?: number,\n\t): Promise<ArrayBuffer> | Promise<readonly ArrayBuffer[]> {\n\t\tthis.#check()\n\t\tif (isArray(target)) return this.#readSpans(target)\n\t\treturn this.#readSingle(target, offset, size)\n\t}\n\n\twrite(destination: WGSLSlice, bytes: WGSLByteSource): void {\n\t\tthis.#check()\n\t\tconst [to, at] = this.#readSlice(destination, 'destination', 'write destination')\n\t\tif (!isArrayBuffer(bytes) && !isArrayBufferView(bytes)) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`A write needs an ArrayBuffer or ArrayBufferView byte source; received ${preview(bytes)}.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { bytes } },\n\t\t\t)\n\t\t}\n\t\tconst length = this.#checkSize(bytes.byteLength, 'write')\n\t\tthis.#checkRange(to, at, length, 'write destination')\n\t\tthis.#close('write')\n\t\tif (this.#recorded) this.flush()\n\t\tif (this.#mode !== 'off') {\n\t\t\tthis.#writes += 1\n\t\t\tthis.#bytes += length\n\t\t}\n\t\tconst device = this.#device\n\t\tdevice.pushErrorScope('out-of-memory')\n\t\tdevice.pushErrorScope('validation')\n\t\tdevice.queue.writeBuffer(to, at, bytes)\n\t\tconst validation = device.popErrorScope()\n\t\tconst memory = device.popErrorScope()\n\t\tthis.#submissions.push(this.#scope(validation, memory))\n\t}\n\n\tcopy(source: WGSLSlice, destination: WGSLSlice, size: number): void {\n\t\tthis.#check()\n\t\tconst [from, start] = this.#readSlice(source, 'source', 'copy source')\n\t\tconst [to, at] = this.#readSlice(destination, 'destination', 'copy destination')\n\t\tif (from === to) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t'A copy reads and writes one buffer; copy between two distinct buffers, or stage the range through a second buffer.',\n\t\t\t\t{ code: 'ARGUMENT', context: { label: from.label } },\n\t\t\t)\n\t\t}\n\t\tconst length = this.#checkSize(size, 'copy')\n\t\tthis.#checkRange(from, start, length, 'copy source')\n\t\tthis.#checkRange(to, at, length, 'copy destination')\n\t\tthis.#close('copy')\n\t\tif (this.#mode !== 'off') {\n\t\t\tthis.#copies += 1\n\t\t\tthis.#bytes += length\n\t\t}\n\t\tthis.#encoder.copyBufferToBuffer(from, start, to, at, length)\n\t\tthis.#recorded = true\n\t}\n\n\tclear(buffer: GPUBuffer, offset?: number, size?: number): void {\n\t\tthis.#check()\n\t\tthis.#checkUsage(buffer, 'destination', 'clear')\n\t\tconst start = this.#checkOffset(offset ?? 0, 'clear')\n\t\tconst length = this.#checkSize(size ?? buffer.size - start, 'clear')\n\t\tthis.#checkRange(buffer, start, length, 'clear')\n\t\tthis.#close('clear')\n\t\tif (this.#mode !== 'off') {\n\t\t\tthis.#clears += 1\n\t\t\tthis.#bytes += length\n\t\t}\n\t\tthis.#encoder.clearBuffer(buffer, start, length)\n\t\tthis.#recorded = true\n\t}\n\n\tflush(): void {\n\t\tthis.#check()\n\t\tif (!this.#recorded) return\n\t\tthis.#close('flush')\n\t\tif (this.#mode !== 'off') this.#flushes += 1\n\t\tthis.#commit()\n\t\tthis.#flushedReads = this.#reads.length\n\t\tthis.#recorded = false\n\t\tthis.#encoder = this.#device.createCommandEncoder()\n\t}\n\n\tsubmit(): void {\n\t\tthis.#check()\n\t\tthis.#close('submit')\n\t\tthis.#resolve()\n\t\tif (this.#submissions.length === 0 || this.#recorded || this.#stamps !== undefined) {\n\t\t\tthis.#commit()\n\t\t}\n\t\tthis.#recorded = false\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\tthis.#aborted = true\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 read of this.#reads) read.reject(error)\n\t\tif (this.#status !== 'open') return\n\t\tthis.#status = 'aborted'\n\t\tthis.#slab.clear()\n\t\tfor (const read of this.#reads.slice(this.#flushedReads)) this.#options.restore(read.buffer)\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// Validates and records a single-range read into one leased staging buffer.\n\t#readSingle(\n\t\tbuffer: GPUBuffer,\n\t\toffset: number | undefined,\n\t\tsize: number | undefined,\n\t): Promise<ArrayBuffer> {\n\t\tthis.#checkUsage(buffer, 'source', 'read')\n\t\tconst start = this.#checkOffset(offset, 'read')\n\t\tconst length = this.#checkSize(size, 'read')\n\t\tthis.#checkRange(buffer, start, length, 'read')\n\t\tthis.#checkReadLimit(length)\n\t\tthis.#close('read')\n\t\tif (this.#mode !== 'off') this.#bytes += length\n\t\tconst staging = this.#options.lease(length)\n\t\tthis.#encoder.copyBufferToBuffer(buffer, start, staging, 0, length)\n\t\tthis.#recorded = true\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({\n\t\t\tbuffer: staging,\n\t\t\tsize: length,\n\t\t\tranges: Object.freeze([Object.freeze({ offset: 0, size: length })]),\n\t\t\tresolve: (buffers) => {\n\t\t\t\tconst first = buffers[0]\n\t\t\t\tif (first !== undefined) result.resolve(first)\n\t\t\t},\n\t\t\treject: result.reject,\n\t\t})\n\t\treturn result.promise\n\t}\n\n\t// Validates and coalesces one or more buffer spans into one leased staging buffer.\n\t#readSpans(spans: readonly WGSLSpan[]): Promise<readonly ArrayBuffer[]> {\n\t\tif (spans.length === 0) {\n\t\t\tthrow new WGSLError('A coalesced read needs at least one span; pass a non-empty array.', {\n\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\tcontext: { length: 0 },\n\t\t\t})\n\t\t}\n\t\tconst entries = Array.from({ length: spans.length }, (_, index) => {\n\t\t\tif (!Object.hasOwn(spans, index)) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`A read span at index ${index} is missing; pass a dense array of spans.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { index } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tconst span = spans[index]\n\t\t\tif (!isObject(span)) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`A read span at index ${index} must be an object such as { buffer, offset: 0, size: 16 }; received ${preview(span)}.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { index, span } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tconst { buffer, offset = 0, size } = span\n\t\t\tthis.#checkUsage(buffer, 'source', 'read')\n\t\t\tconst start = this.#checkOffset(offset, 'read')\n\t\t\tconst length = this.#checkSize(size, 'read')\n\t\t\tthis.#checkRange(buffer, start, length, 'read')\n\t\t\treturn Object.freeze({ buffer, offset: start, size: length })\n\t\t})\n\t\tconst planned = entries.reduce<{\n\t\t\treadonly total: number\n\t\t\treadonly ranges: readonly WGSLReadRange[]\n\t\t}>(\n\t\t\t(accumulator, entry) => ({\n\t\t\t\ttotal: accumulator.total + entry.size,\n\t\t\t\tranges: [\n\t\t\t\t\t...accumulator.ranges,\n\t\t\t\t\tObject.freeze({ offset: accumulator.total, size: entry.size }),\n\t\t\t\t],\n\t\t\t}),\n\t\t\t{ total: 0, ranges: [] },\n\t\t)\n\t\tthis.#checkReadLimit(planned.total)\n\t\tthis.#close('read')\n\t\tif (this.#mode !== 'off') this.#bytes += planned.total\n\t\tconst staging = this.#options.lease(planned.total)\n\t\tfor (const [index, entry] of entries.entries()) {\n\t\t\tconst range = planned.ranges[index]\n\t\t\tif (range === undefined) continue\n\t\t\tthis.#encoder.copyBufferToBuffer(\n\t\t\t\tentry.buffer,\n\t\t\t\tentry.offset,\n\t\t\t\tstaging,\n\t\t\t\trange.offset,\n\t\t\t\tentry.size,\n\t\t\t)\n\t\t}\n\t\tthis.#recorded = true\n\t\tconst result = Promise.withResolvers<readonly 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({\n\t\t\tbuffer: staging,\n\t\t\tsize: planned.total,\n\t\t\tranges: Object.freeze(planned.ranges),\n\t\t\tresolve: (buffers) => result.resolve(Object.freeze(buffers)),\n\t\t\treject: result.reject,\n\t\t})\n\t\treturn result.promise\n\t}\n\n\t// Throws a LIMIT error when a read total passes the device's maxBufferSize.\n\t#checkReadLimit(size: number): void {\n\t\tconst limit = this.#device.limits.maxBufferSize\n\t\tif (isSafeInteger(size) && size <= limit) return\n\t\tthrow new WGSLError(\n\t\t\t`A read of ${size} bytes passes the device's maxBufferSize of ${limit}; split the read.`,\n\t\t\t{ code: 'LIMIT', context: { size, limit } },\n\t\t)\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 unless the value is a buffer carrying the named WGSL_USAGE bit.\n\t#checkUsage(buffer: GPUBuffer, usage: keyof typeof WGSL_USAGE, operation: string): void {\n\t\tif (isObject(buffer) && (buffer.usage & WGSL_USAGE[usage]) !== 0) return\n\t\tconst received = isObject(buffer) ? buffer.usage : undefined\n\t\tthrow new WGSLError(\n\t\t\t`A ${operation} needs a buffer with the ${usage} usage (WGSL_USAGE.${usage}); its usage is ${preview(received)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { usage: received } },\n\t\t)\n\t}\n\n\t// Throws an ARGUMENT error unless the offset is a non-negative safe multiple of 4 bytes.\n\t#checkOffset(offset: unknown, operation: string): number {\n\t\tif (isNonNegativeInteger(offset) && isSafeInteger(offset) && offset % 4 === 0) return offset\n\t\tthrow new WGSLError(\n\t\t\t`A ${operation} starts at ${preview(offset)}; a ${operation} offset must be a non-negative safe multiple of 4 bytes.`,\n\t\t\t{ code: 'ARGUMENT', context: { offset } },\n\t\t)\n\t}\n\n\t// Throws an ARGUMENT error unless the size is a safe multiple of 4 bytes, at least 4.\n\t#checkSize(size: unknown, operation: string): number {\n\t\tif (isSafeInteger(size) && size >= 4 && size % 4 === 0) return size\n\t\tthrow new WGSLError(\n\t\t\t`A ${operation} spans ${preview(size)} bytes; a ${operation} size must be a safe multiple of 4 bytes, at least 4.`,\n\t\t\t{ code: 'ARGUMENT', context: { size } },\n\t\t)\n\t}\n\n\t// Throws an ARGUMENT error when the range passes the buffer's end.\n\t#checkRange(buffer: GPUBuffer, offset: number, size: number, operation: string): void {\n\t\tif (offset + size <= buffer.size) return\n\t\tthrow new WGSLError(\n\t\t\t`A ${operation} ends at byte ${offset + size}, past its buffer's ${buffer.size} bytes; shorten the range.`,\n\t\t\t{ code: 'ARGUMENT', context: { offset, size, length: buffer.size } },\n\t\t)\n\t}\n\n\t// Reads a slice's buffer and offset once, refusing a non-object slice, a missing usage, and a malformed offset.\n\t#readSlice(\n\t\tslice: WGSLSlice,\n\t\tusage: keyof typeof WGSL_USAGE,\n\t\toperation: string,\n\t): readonly [buffer: GPUBuffer, offset: number] {\n\t\tif (!isObject(slice)) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`A ${operation} must be a slice such as { buffer, offset: 0 }; received ${preview(slice)}.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { slice } },\n\t\t\t)\n\t\t}\n\t\tconst { buffer, offset = 0 } = slice\n\t\tthis.#checkUsage(buffer, usage, operation)\n\t\tconst checked = this.#checkOffset(offset, operation)\n\t\treturn [buffer, checked]\n\t}\n\n\t// Checks grid coordinates when the fast 32-bit integer check misses, throwing ARGUMENT or LIMIT.\n\t#checkGrid(grid: unknown, x: unknown, y: unknown, z: unknown): void {\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}\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)} takes ${struct.size} bytes, more than the slab's ${this.#slab.capacity}; raise the session's uniform size.`,\n\t\t\t\t{ code: 'ARGUMENT', 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.#mode === 'off' ? this.#encoder.beginComputePass() : this.#begin()\n\t\tthis.#pass = pass\n\t\treturn pass\n\t}\n\n\t// Begins a traced pass: a pass within the capacity takes the next index and, with a query set, its 2 timestamp writes; a pass past it counts as dropped.\n\t#begin(): GPUComputePassEncoder {\n\t\tconst passes = this.#passes\n\t\tif (passes === undefined) return this.#encoder.beginComputePass()\n\t\tconst index = passes.length\n\t\tthis.#dispatched = 0\n\t\tthis.#switched = 0\n\t\tif (index >= this.#capacity) {\n\t\t\tthis.#dropped += 1\n\t\t\treturn this.#encoder.beginComputePass()\n\t\t}\n\t\tthis.#index = index\n\t\tconst querySet = this.#options.queries\n\t\tif (querySet === undefined) return this.#encoder.beginComputePass()\n\t\treturn this.#encoder.beginComputePass({\n\t\t\ttimestampWrites: {\n\t\t\t\tquerySet,\n\t\t\t\tbeginningOfPassWriteIndex: index * 2,\n\t\t\t\tendOfPassWriteIndex: index * 2 + 1,\n\t\t\t},\n\t\t})\n\t}\n\n\t// Ends the open compute pass, records a traced pass with its cause, and forgets the pipeline, storage group, and uniform cache it set.\n\t#close(cause: WGSLTraceCause): 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.#struct = undefined\n\t\tthis.#uniform = undefined\n\t\tconst index = this.#index\n\t\tif (index === undefined || this.#passes === undefined) return\n\t\tthis.#index = undefined\n\t\tthis.#passes.push({ index, dispatches: this.#dispatched, switches: this.#switched, cause })\n\t}\n\n\t// Counts one traced dispatch, and in statement mode ends its pass so the pass holds that dispatch alone.\n\t#note(name: string, switched: boolean): void {\n\t\tif (this.#counts === undefined || this.#swaps === undefined) return\n\t\tconst step = switched ? 1 : 0\n\t\tthis.#dispatches += 1\n\t\tthis.#switches += step\n\t\tthis.#dispatched += 1\n\t\tthis.#switched += step\n\t\tthis.#counts.set(name, (this.#counts.get(name) ?? 0) + 1)\n\t\tthis.#swaps.set(name, (this.#swaps.get(name) ?? 0) + step)\n\t\tif (this.#mode !== 'statement') return\n\t\tif (this.#index !== undefined && this.#names !== undefined) this.#names[this.#index] = name\n\t\tthis.#close('statement')\n\t}\n\n\t// Resolves the recorded passes' timestamps and copies them to a leased staging buffer before the final commit.\n\t#resolve(): void {\n\t\tconst passes = this.#passes\n\t\tconst querySet = this.#options.queries\n\t\tconst timestamps = this.#options.timestamps\n\t\tif (\n\t\t\tpasses === undefined ||\n\t\t\tquerySet === undefined ||\n\t\t\ttimestamps === undefined ||\n\t\t\tpasses.length === 0\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\tconst count = passes.length\n\t\tconst size = count * 16\n\t\tconst staging = this.#options.lease(size)\n\t\tthis.#encoder.resolveQuerySet(querySet, 0, count * 2, timestamps, 0)\n\t\tthis.#encoder.copyBufferToBuffer(timestamps, 0, staging, 0, size)\n\t\tthis.#stamps = staging\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// Returns the session's non-destroyed terminal failure when the device failed or was lost.\n\t#sessionFailure(): WGSLError | undefined {\n\t\ttry {\n\t\t\tthis.#checkSession()\n\t\t\treturn undefined\n\t\t} catch (cause) {\n\t\t\treturn isWGSLError(cause) && cause.code !== 'DESTROYED' ? cause : undefined\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) {\n\t\t\t\tthis.#options.fail(failure)\n\t\t\t\treturn failure\n\t\t\t}\n\t\t\treturn this.#sessionFailure()\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: maps every read and timestamp readback alongside the submission\n\t// drain, and only resolves or rejects reads and records traces once drain completes.\n\tasync #finish(): Promise<WGSLError | undefined> {\n\t\tif (this.#reads.length === 0 && this.#stamps === undefined) {\n\t\t\tconst failure = await this.#drain()\n\t\t\tif (failure !== undefined) return failure\n\t\t\tif (this.#mode !== 'off') this.#settle(undefined)\n\t\t\treturn undefined\n\t\t}\n\t\tconst drain = this.#drain()\n\t\tconst mapped =\n\t\t\tthis.#reads.length === 0 ? undefined : Promise.all(this.#reads.map((read) => this.#map(read)))\n\t\tconst timed = this.#stamps === undefined ? undefined : this.#time()\n\t\tconst [failure, results, durations] = await Promise.all([drain, mapped, timed])\n\t\tfor (const read of this.#reads) this.#options.restore(read.buffer)\n\t\tif (this.#stamps !== undefined) this.#options.restore(this.#stamps)\n\t\tconst terminal = failure ?? this.#sessionFailure()\n\t\tif (terminal !== undefined) {\n\t\t\tfor (const read of this.#reads) read.reject(terminal)\n\t\t\treturn terminal\n\t\t}\n\t\tif (results !== undefined) {\n\t\t\tfor (const [index, read] of this.#reads.entries()) {\n\t\t\t\tconst outcome = results[index]\n\t\t\t\tif (outcome === undefined) continue\n\t\t\t\tconst [buffers, error] = outcome\n\t\t\t\tif (buffers !== undefined) read.resolve(buffers)\n\t\t\t\telse if (error !== undefined) read.reject(error)\n\t\t\t}\n\t\t}\n\t\tthis.#settle(durations)\n\t\treturn undefined\n\t}\n\n\t// Maps the timestamp staging buffer and returns each recorded pass's GPU time in nanoseconds, or undefined without timestamps.\n\tasync #time(): Promise<readonly number[] | undefined> {\n\t\tconst staging = this.#stamps\n\t\tconst passes = this.#passes\n\t\tif (staging === undefined || passes === undefined) return undefined\n\t\tconst size = passes.length * 16\n\t\ttry {\n\t\t\tawait staging.mapAsync(WGSL_MAP.read, 0, size)\n\t\t\tconst stamps = new BigUint64Array(staging.getMappedRange(0, size))\n\t\t\tconst durations = passes.map((pass) => {\n\t\t\t\tconst start = stamps[pass.index * 2] ?? 0n\n\t\t\t\tconst end = stamps[pass.index * 2 + 1] ?? 0n\n\t\t\t\treturn end >= start ? Number(end - start) : 0\n\t\t\t})\n\t\t\tstaging.unmap()\n\t\t\treturn durations\n\t\t} catch {\n\t\t\tif (staging.mapState === 'mapped') staging.unmap()\n\t\t\t// A device that cannot map the timestamps still yields the structural counts.\n\t\t\treturn undefined\n\t\t}\n\t}\n\n\t// Freezes the traced batch's record, keeps it, and hands it to the session.\n\t#settle(durations: readonly number[] | undefined): void {\n\t\tconst mode = this.#mode\n\t\tconst passes = this.#passes\n\t\tconst names = this.#names\n\t\tconst counts = this.#counts\n\t\tconst swaps = this.#swaps\n\t\tif (\n\t\t\tmode === 'off' ||\n\t\t\tpasses === undefined ||\n\t\t\tnames === undefined ||\n\t\t\tcounts === undefined ||\n\t\t\tswaps === undefined\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\tconst traced = passes.map((pass, index) => {\n\t\t\tconst duration = durations?.[index]\n\t\t\treturn Object.freeze(duration === undefined ? { ...pass } : { ...pass, duration })\n\t\t})\n\t\t// Only a statement-mode pass holds one program's dispatch, so only that mode attributes GPU time to a program.\n\t\tconst timed = mode === 'statement' ? (durations ?? []) : []\n\t\tconst statements = [...counts].map(([name, dispatches]): WGSLTraceStatement => {\n\t\t\tconst switches = swaps.get(name) ?? 0\n\t\t\tconst owned = timed.filter((_, index) => names[index] === name)\n\t\t\tif (owned.length === 0) return Object.freeze({ name, dispatches, switches })\n\t\t\tconst duration = owned.reduce((total, value) => total + value, 0)\n\t\t\treturn Object.freeze({ name, dispatches, switches, duration })\n\t\t})\n\t\tconst record: WGSLTraceRecord = Object.freeze({\n\t\t\tmode,\n\t\t\tflushes: this.#flushes,\n\t\t\tdispatches: this.#dispatches,\n\t\t\tcopies: this.#copies,\n\t\t\tclears: this.#clears,\n\t\t\twrites: this.#writes,\n\t\t\tbytes: this.#bytes,\n\t\t\tswitches: this.#switches,\n\t\t\tdropped: this.#dropped,\n\t\t\tpasses: Object.freeze(traced),\n\t\t\tstatements: Object.freeze(statements),\n\t\t})\n\t\tthis.#trace = record\n\t\tthis.#options.record(record)\n\t}\n\n\t// Settles an aborted batch after its earlier flushes finish, restoring flushed staging buffers only after drain completes.\n\tasync #discard(error: WGSLError): Promise<WGSLError> {\n\t\tconst failure = await this.#drain()\n\t\tfor (const read of this.#reads.slice(0, this.#flushedReads)) this.#options.restore(read.buffer)\n\t\treturn failure ?? error\n\t}\n\n\t// Maps one staging buffer to caller-owned copies of its ranges and unmaps it before settlement.\n\tasync #map(\n\t\tread: WGSLRead,\n\t): Promise<readonly [buffers: readonly ArrayBuffer[] | undefined, error: WGSLError | undefined]> {\n\t\tconst { buffer: staging, size, ranges } = read\n\t\ttry {\n\t\t\tawait staging.mapAsync(WGSL_MAP.read, 0, size)\n\t\t\tif (this.#aborted) {\n\t\t\t\tstaging.unmap()\n\t\t\t\treturn [undefined, undefined]\n\t\t\t}\n\t\t\tconst mapped = staging.getMappedRange(0, size)\n\t\t\tconst buffers = ranges.map((range) => mapped.slice(range.offset, range.offset + range.size))\n\t\t\tstaging.unmap()\n\t\t\treturn [buffers, undefined]\n\t\t} catch (cause) {\n\t\t\tif (staging.mapState === 'mapped') staging.unmap()\n\t\t\treturn [\n\t\t\t\tundefined,\n\t\t\t\tnew WGSLError(`The device could not map a read: ${errorToMessage(cause)}`, {\n\t\t\t\t\tcode: 'HOST',\n\t\t\t\t\tcause,\n\t\t\t\t}),\n\t\t\t]\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 * caches a split integer/float field plan per `WGSLStruct` so multi-field writes step directly into\n * each typed view without per-field type branching. 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\treadonly #plans = new WeakMap<\n\t\tWGSLStruct,\n\t\treadonly [\n\t\t\twordNames: readonly string[],\n\t\t\twordOffsets: readonly number[],\n\t\t\tfloatNames: readonly string[],\n\t\t\tfloatOffsets: readonly number[],\n\t\t]\n\t>()\n\t#planStruct: WGSLStruct | undefined\n\t#plan:\n\t\t| readonly [\n\t\t\t\twordNames: readonly string[],\n\t\t\t\twordOffsets: readonly number[],\n\t\t\t\tfloatNames: readonly string[],\n\t\t\t\tfloatOffsets: readonly number[],\n\t\t ]\n\t\t| undefined\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\tconst plan =\n\t\t\tthis.#planStruct === struct && this.#plan !== undefined\n\t\t\t\t? this.#plan\n\t\t\t\t: this.#resolvePlan(struct)\n\t\tconst wordNames = plan[0]\n\t\tconst wordOffsets = plan[1]\n\t\tconst wordCount = wordNames.length\n\t\tconst words = this.#words\n\t\tfor (let i = 0; i < wordCount; i += 1) {\n\t\t\tconst name = wordNames[i]\n\t\t\tconst word = wordOffsets[i]\n\t\t\tif (name === undefined || word === undefined) continue\n\t\t\tconst value = record[name]\n\t\t\tif (typeof value !== 'number') {\n\t\t\t\twords.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(name)}.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: struct.name, field: name } },\n\t\t\t\t)\n\t\t\t}\n\t\t\twords[base + word] = value\n\t\t}\n\t\tconst floatNames = plan[2]\n\t\tconst floatOffsets = plan[3]\n\t\tconst floatCount = floatNames.length\n\t\tconst floats = this.#floats\n\t\tfor (let i = 0; i < floatCount; i += 1) {\n\t\t\tconst name = floatNames[i]\n\t\t\tconst word = floatOffsets[i]\n\t\t\tif (name === undefined || word === undefined) continue\n\t\t\tconst value = record[name]\n\t\t\tif (typeof value !== 'number') {\n\t\t\t\twords.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(name)}.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: struct.name, field: 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\tfloats[base + 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\tif (this.#used === 0) return\n\t\tthis.#words.fill(0, 0, this.#mask >= 0 ? this.#used >>> 2 : this.#used / 4)\n\t\tthis.#used = 0\n\t}\n\n\t// Splits a struct's members into integer-word and float arrays once per struct identity and remembers the last plan inline.\n\t#resolvePlan(\n\t\tstruct: WGSLStruct,\n\t): readonly [\n\t\twordNames: readonly string[],\n\t\twordOffsets: readonly number[],\n\t\tfloatNames: readonly string[],\n\t\tfloatOffsets: readonly number[],\n\t] {\n\t\tconst cached = this.#plans.get(struct)\n\t\tif (cached !== undefined) {\n\t\t\tthis.#planStruct = struct\n\t\t\tthis.#plan = cached\n\t\t\treturn cached\n\t\t}\n\t\tconst wordMembers = struct.members.filter((member) => member.element !== 'f32')\n\t\tconst floatMembers = struct.members.filter((member) => member.element === 'f32')\n\t\tconst plan: readonly [\n\t\t\twordNames: readonly string[],\n\t\t\twordOffsets: readonly number[],\n\t\t\tfloatNames: readonly string[],\n\t\t\tfloatOffsets: readonly number[],\n\t\t] = [\n\t\t\twordMembers.map((member) => member.name),\n\t\t\twordMembers.map((member) => member.word),\n\t\t\tfloatMembers.map((member) => member.name),\n\t\t\tfloatMembers.map((member) => member.word),\n\t\t]\n\t\tthis.#plans.set(struct, plan)\n\t\tthis.#planStruct = struct\n\t\tthis.#plan = plan\n\t\treturn plan\n\t}\n}\n","import type {\n\tWGSLBinding,\n\tWGSLBindingNode,\n\tWGSLFieldMap,\n\tWGSLGrid,\n\tWGSLOverrideMap,\n\tWGSLProgram,\n\tWGSLSessionInterface,\n\tWGSLSlot,\n\tWGSLSlotMap,\n\tWGSLStatementInterface,\n\tWGSLStatementOptions,\n\tWGSLValueMap,\n} from './types.js'\nimport {\n\tisNonNegativeInteger,\n\tisObject,\n\tisRecord,\n\tisSafeInteger,\n\tpreview,\n} from '@orkestrel/contract'\nimport { WGSL_STORAGE_STRIDES, 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` verifies the owning session is open, then walks a per-statement `WeakMap` trie keyed on\n * each slot's buffer, byte offset, and byte size, so a repeated exact range set returns the same\n * `WGSLBinding` without allocating, and a destroyed buffer's entries leave with the buffer. A range\n * set the trie lacks is checked before its bind group is created: thrown with code `ARGUMENT` when\n * `buffers` is not a plain record, when the slot names differ from the program's, when a buffer\n * lacks the `storage` usage, when an offset is not a multiple of the device's\n * `minStorageBufferOffsetAlignment`, when a size is under `Math.max(4, stride)` or not a multiple\n * of that element stride, and when a range passes its buffer's end; with code `LIMIT` when a size\n * passes the device's `maxStorageBufferBindingSize`; with code `VALIDATION` when a `read_write`\n * slot shares its `GPUBuffer` with any other slot, even over disjoint ranges, because Dawn refuses\n * that pair; with code `DESTROYED` after the session's `destroy`; and with the session's recorded\n * failure when the session has failed.\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\tO extends WGSLOverrideMap = WGSLOverrideMap,\n> implements WGSLStatementInterface<S, F, O> {\n\treadonly program: WGSLProgram<S, F, O>\n\treadonly pipeline: GPUComputePipeline\n\treadonly uniform: GPUBindGroup\n\treadonly #session: WGSLSessionInterface\n\treadonly #layout: GPUBindGroupLayout\n\treadonly #check: () => void\n\treadonly #slots: ReadonlyArray<readonly [name: string, slot: WGSLSlot]>\n\treadonly #root: WGSLBindingNode<S, F, O>\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, the uniform bind group, and the session guard\n\t */\n\tconstructor(session: WGSLSessionInterface, options: WGSLStatementOptions<S, F, O>) {\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.#check = options.check\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, O> {\n\t\tthis.#check()\n\t\tconst record: Readonly<Record<string, GPUBufferBinding>> = buffers\n\t\tconst cached = this.#find(record)\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, O>,\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// Checks for a cached binding when the input is a plain record with the exact declared slot count.\n\t#find(record: Readonly<Record<string, GPUBufferBinding>>): WGSLBinding<S, F, O> | undefined {\n\t\tif (!isRecord(record) || Object.keys(record).length !== this.#slots.length) return undefined\n\t\treturn this.#walk(this.#root, record, 0)\n\t}\n\n\t// Walks the trie one slot per level and returns the cached binding, or `undefined` on a miss.\n\t#walk(\n\t\tnode: WGSLBindingNode<S, F, O>,\n\t\trecord: Readonly<Record<string, GPUBufferBinding>>,\n\t\tdepth: number,\n\t): WGSLBinding<S, F, O> | 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.#walk(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\tif (!isRecord(record)) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The program ${preview(name)} binds a record of slot ranges; received ${preview(record)}.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t)\n\t\t}\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(([slotName, slot]) =>\n\t\t\tthis.#range(slotName, slot, record[slotName], limits),\n\t\t)\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 element stride, its buffer, and the device limits.\n\t#range(\n\t\tslotName: string,\n\t\tslot: WGSLSlot,\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(slotName)} of ${preview(name)} needs a buffer range object whose buffer member holds a GPUBuffer.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { name, slot: slotName } },\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(slotName)} 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: slotName, 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(slotName)} 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: slotName, offset, alignment } },\n\t\t\t)\n\t\t}\n\t\tconst stride = Math.max(4, WGSL_STORAGE_STRIDES[slot.element])\n\t\tconst size = binding.size ?? buffer.size - offset\n\t\tif (!isSafeInteger(size) || size < stride || size % stride !== 0) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The slot ${preview(slotName)} of ${preview(name)} spans ${preview(size)} bytes; a ${slot.element} storage range must span a multiple of ${stride} bytes, at least ${stride}.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { name, slot: slotName, size, stride } },\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(slotName)} 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: slotName, 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(slotName)} 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: slotName, 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, O> {\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, O>,\n\t\tentries: ReadonlyArray<Required<GPUBufferBinding>>,\n\t\tdepth: number,\n\t\tbinding: WGSLBinding<S, F, O>,\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, O>>>()\n\t\tconst sizes = offsets.get(entry.offset) ?? new Map<number, WGSLBindingNode<S, F, O>>()\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, O> = 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\tWGSLBatchInterface,\n\tWGSLBatchOptions,\n\tWGSLExtension,\n\tWGSLFieldMap,\n\tWGSLGrid,\n\tWGSLLanguage,\n\tWGSLOverrideMap,\n\tWGSLPrepareOptions,\n\tWGSLProgram,\n\tWGSLRenderOptions,\n\tWGSLSessionInterface,\n\tWGSLSessionOptions,\n\tWGSLSessionStatus,\n\tWGSLSlot,\n\tWGSLSlotMap,\n\tWGSLStatementInterface,\n\tWGSLSubgroupRange,\n\tWGSLTraceOptions,\n\tWGSLTraceRecord,\n} from './types.js'\nimport type { OptionFieldsFor } from '@orkestrel/contract'\nimport {\n\tarrayOf,\n\tdefaultOption,\n\terrorToMessage,\n\tgroupOption,\n\tholds,\n\tisArray,\n\tisBoolean,\n\tisFiniteNumber,\n\tisFunction,\n\tisIterable,\n\tisMap,\n\tisNonNegativeInteger,\n\tisNumber,\n\tisObject,\n\tisRecord,\n\tisSafeInteger,\n\tisSet,\n\tisString,\n\tliteralOf,\n\toptionalGroupOption,\n\toptionalOption,\n\toptionFaultToError,\n\tpickDefined,\n\tpreview,\n\tresolveOptions,\n\tsetOf,\n} from '@orkestrel/contract'\nimport {\n\tWGSL_EXTENSIONS,\n\tWGSL_STAGE,\n\tWGSL_STORAGE_STRIDES,\n\tWGSL_TRACE_CAPACITY,\n\tWGSL_TRACE_MODES,\n\tWGSL_UNIFORM_SIZE,\n\tWGSL_USAGE,\n} from './constants.js'\nimport { isWGSLError, WGSLError } from './errors.js'\nimport { collectWGSLSections, 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, features, and subgroup size bounds from the borrowed device and\n * reads no host global. An extension is active when the device reports its feature and the\n * `extensions` option does not switch it off; WGSL language extensions derive once at construction\n * from the caller-supplied `languages` set or list intersected with `WGSL_LANGUAGES`. Shader\n * modules sit in a cache keyed on rendered WGSL text, separate from the ready and pending pipeline\n * tables keyed on rendered text plus canonical override constants (keeping `-0` distinct from `0`),\n * so specializing one program with distinct override values compiles its shader module once. A\n * pending pipeline or module entry that fails with any code but `COMPILE` leaves its table, so a\n * later `prepare` retries it. Shader compilation and pipeline layout creation each run inside one\n * synchronous push and pop of a `validation` error scope; a compiler error rejects that `prepare`\n * with code `COMPILE` and its `line`, `column`, and section attribution in `context` while the\n * session stays `open`. Thrown with code `LIMIT` when `uniform.size`, a staging allocation, a\n * uniform struct size, a workgroup size, or a slot count passes the device's limits; with code\n * `VALIDATION` when half-precision storage slots lack an active `f16` extension or `batch()` is\n * called while another batch is open; and with code `ARGUMENT` for malformed options or invalid\n * override constants. Staging buffers lease through a best-fit power-of-two pool that retains up to\n * 8 idle buffers. A device failure on a submitted batch, or `device.lost`, moves the session to\n * `failed`; `destroy` moves the session to `destroyed` at once, aborts the open batch, waits for\n * submitted work and reads, and destroys every session-owned buffer and query set while leaving the\n * borrowed device open.\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 #languages: Readonly<Record<WGSLLanguage, boolean>>\n\treadonly #subgroup: Required<WGSLSubgroupRange> | undefined\n\treadonly #buffer: GPUBuffer\n\treadonly #slab: WGSLSlab\n\treadonly #uniform: GPUBindGroupLayout\n\treadonly #modules = new Map<string, Promise<GPUShaderModule>>()\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\treadonly #tracer: Required<WGSLTraceOptions>\n\treadonly #queries: GPUQuerySet | undefined\n\treadonly #timestamps: GPUBuffer | undefined\n\treadonly #batchOptions: WGSLBatchOptions\n\t#trace: WGSLTraceRecord | undefined\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, host language extensions, slab byte size, and tracer mode and capacity\n\t */\n\tconstructor(device: GPUDevice, options?: WGSLSessionOptions) {\n\t\tconst resolved = resolveOptions(\n\t\t\toptions,\n\t\t\t{\n\t\t\t\textensions: optionalGroupOption({\n\t\t\t\t\tf16: optionalOption(isBoolean),\n\t\t\t\t\tsubgroups: optionalOption(isBoolean),\n\t\t\t\t}),\n\t\t\t\tlanguages: optionalOption(\n\t\t\t\t\t(value: unknown): value is ReadonlySet<string> | readonly string[] =>\n\t\t\t\t\t\tholds(() => {\n\t\t\t\t\t\t\tif (isArray(value)) return arrayOf(isString)(value)\n\t\t\t\t\t\t\tif (isSet(value)) return setOf(isString)(value)\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!isObject(value) ||\n\t\t\t\t\t\t\t\tisMap(value) ||\n\t\t\t\t\t\t\t\t!isIterable(value) ||\n\t\t\t\t\t\t\t\t!('has' in value) ||\n\t\t\t\t\t\t\t\t!isFunction(value.has) ||\n\t\t\t\t\t\t\t\t!('size' in value) ||\n\t\t\t\t\t\t\t\t!isNonNegativeInteger(value.size) ||\n\t\t\t\t\t\t\t\t!('forEach' in value) ||\n\t\t\t\t\t\t\t\t!isFunction(value.forEach) ||\n\t\t\t\t\t\t\t\t!('entries' in value) ||\n\t\t\t\t\t\t\t\t!isFunction(value.entries) ||\n\t\t\t\t\t\t\t\t!('keys' in value) ||\n\t\t\t\t\t\t\t\t!isFunction(value.keys) ||\n\t\t\t\t\t\t\t\t!('values' in value) ||\n\t\t\t\t\t\t\t\t!isFunction(value.values)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfor (const entry of value) {\n\t\t\t\t\t\t\t\tif (!isString(entry)) return false\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn true\n\t\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\tuniform: groupOption({ size: defaultOption(isNumber, WGSL_UNIFORM_SIZE) }),\n\t\t\t\ttrace: groupOption({\n\t\t\t\t\tmode: defaultOption(literalOf(WGSL_TRACE_MODES), 'off'),\n\t\t\t\t\tcapacity: defaultOption(isNumber, WGSL_TRACE_CAPACITY),\n\t\t\t\t}),\n\t\t\t} satisfies OptionFieldsFor<WGSLSessionOptions>,\n\t\t\t{\n\t\t\t\trefuse: (fault) => {\n\t\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLSession')\n\t\t\t\t\treturn new WGSLError(`The session options are malformed: ${cause.message}`, {\n\t\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\t\tcause,\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t\tcheck: ({ uniform: { size }, trace: { capacity } }) => {\n\t\t\t\t\tif (!isSafeInteger(size) || size < 4 || size % 4 !== 0) {\n\t\t\t\t\t\tthrow new WGSLError(\n\t\t\t\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\t\t\t{ code: 'ARGUMENT', context: { size } },\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (size > device.limits.maxBufferSize) {\n\t\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t\t`A session's uniform size of ${size} bytes passes the device's maxBufferSize of ${device.limits.maxBufferSize}.`,\n\t\t\t\t\t\t\t{ code: 'LIMIT', context: { size, limit: device.limits.maxBufferSize } },\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\t// Each pass writes 2 timestamps, and a WebGPU query set holds at most 4096, so 2048 passes fit.\n\t\t\t\t\tif (isSafeInteger(capacity) && capacity >= 1 && capacity <= 2048) return\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A session's trace capacity must be a safe integer from 1 to 2048 passes; received ${preview(capacity)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { capacity } },\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t},\n\t\t)\n\t\tconst size = resolved.uniform.size\n\t\tconst requested = resolved.extensions\n\t\tconst advertised =\n\t\t\tresolved.languages === undefined\n\t\t\t\t? undefined\n\t\t\t\t: isArray(resolved.languages)\n\t\t\t\t\t? new Set(resolved.languages)\n\t\t\t\t\t: resolved.languages\n\t\tconst tracer = resolved.trace\n\t\tconst features = device.features\n\t\tconst timed = tracer.mode !== 'off' && features.has('timestamp-query')\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.#languages = Object.freeze({\n\t\t\tpacked_4x8_integer_dot_product: advertised?.has('packed_4x8_integer_dot_product') === true,\n\t\t\tsubgroup_id: advertised?.has('subgroup_id') === true,\n\t\t})\n\t\tconst adapter = device.adapterInfo\n\t\tconst minSubgroup = isObject(adapter) ? adapter.subgroupMinSize : undefined\n\t\tconst maxSubgroup = isObject(adapter) ? adapter.subgroupMaxSize : undefined\n\t\tthis.#subgroup =\n\t\t\tthis.#extensions.subgroups &&\n\t\t\tisSafeInteger(minSubgroup) &&\n\t\t\tminSubgroup >= 1 &&\n\t\t\tisSafeInteger(maxSubgroup) &&\n\t\t\tmaxSubgroup >= minSubgroup\n\t\t\t\t? Object.freeze({ minimum: minSubgroup, maximum: maxSubgroup })\n\t\t\t\t: undefined\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\tthis.#tracer = { mode: tracer.mode, capacity: tracer.capacity }\n\t\tthis.#queries = timed\n\t\t\t? device.createQuerySet({\n\t\t\t\t\tlabel: 'wgsl trace',\n\t\t\t\t\ttype: 'timestamp',\n\t\t\t\t\tcount: tracer.capacity * 2,\n\t\t\t\t})\n\t\t\t: undefined\n\t\tthis.#timestamps = timed\n\t\t\t? device.createBuffer({\n\t\t\t\t\tlabel: 'wgsl trace',\n\t\t\t\t\tsize: tracer.capacity * 16,\n\t\t\t\t\tusage: WGSL_USAGE.query | WGSL_USAGE.source,\n\t\t\t\t})\n\t\t\t: undefined\n\t\tthis.#batchOptions = Object.freeze<WGSLBatchOptions>({\n\t\t\tslab: this.#slab,\n\t\t\tcheck: () => this.#check(),\n\t\t\tlease: (requestedSize: number) => this.#lease(requestedSize),\n\t\t\trestore: (buffer: GPUBuffer) => this.#restore(buffer),\n\t\t\trelease: (ended: WGSLBatchInterface) => this.#release(ended),\n\t\t\tfail: (error: WGSLError) => this.#fail(error),\n\t\t\ttrack: (work: Promise<unknown>) => this.#track(work),\n\t\t\ttrace: this.#tracer,\n\t\t\tqueries: this.#queries,\n\t\t\ttimestamps: this.#timestamps,\n\t\t\trecord: (record: WGSLTraceRecord) => {\n\t\t\t\tif (this.#failure === undefined) this.#trace = record\n\t\t\t},\n\t\t})\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 languages(): Readonly<Record<WGSLLanguage, boolean>> {\n\t\treturn this.#languages\n\t}\n\n\tget subgroup(): Required<WGSLSubgroupRange> | undefined {\n\t\treturn this.#subgroup\n\t}\n\n\tget status(): WGSLSessionStatus {\n\t\treturn this.#ending !== undefined\n\t\t\t? 'destroyed'\n\t\t\t: this.#failure === undefined\n\t\t\t\t? 'open'\n\t\t\t\t: 'failed'\n\t}\n\n\tget trace(): WGSLTraceRecord | undefined {\n\t\treturn this.#trace\n\t}\n\n\tasync prepare<S extends WGSLSlotMap, F extends WGSLFieldMap, O extends WGSLOverrideMap>(\n\t\tprogram: WGSLProgram<S, F, O>,\n\t\toptions?: WGSLPrepareOptions<O>,\n\t): Promise<WGSLStatementInterface<S, F, O>> {\n\t\tthis.#check()\n\t\tconst { name, entry } = program\n\t\tconst resolved = resolveOptions(\n\t\t\toptions,\n\t\t\t{\n\t\t\t\textensions: optionalGroupOption({\n\t\t\t\t\tf16: optionalOption(isBoolean),\n\t\t\t\t\tsubgroups: optionalOption(isBoolean),\n\t\t\t\t}),\n\t\t\t\tconstants: optionalOption(isRecord),\n\t\t\t},\n\t\t\t{\n\t\t\t\trefuse: (fault) => {\n\t\t\t\t\tconst cause = optionFaultToError(fault, 'WGSLSession.prepare')\n\t\t\t\t\treturn new WGSLError(`The prepare options are malformed: ${cause.message}`, {\n\t\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\t\tcontext: { name, reason: fault.reason, path: fault.path },\n\t\t\t\t\t\tcause,\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t},\n\t\t)\n\t\tconst extensions: Readonly<Record<WGSLExtension, boolean>> = Object.freeze({\n\t\t\tf16: this.#extensions.f16 && resolved.extensions?.f16 !== false,\n\t\t\tsubgroups: this.#extensions.subgroups && resolved.extensions?.subgroups !== false,\n\t\t})\n\t\tconst renderOptions: WGSLRenderOptions = pickDefined({\n\t\t\textensions,\n\t\t\tlanguages: this.#languages,\n\t\t\tsubgroup: extensions.subgroups ? this.#subgroup : undefined,\n\t\t})\n\t\tconst slots: WGSLSlotMap = program.slots\n\t\tconst slotEntries = Object.entries(slots)\n\t\tconst halfSlots = slotEntries\n\t\t\t.filter(\n\t\t\t\t([, slot]) =>\n\t\t\t\t\tslot.element === 'f16' || slot.element === 'vec2h' || slot.element === 'vec4h',\n\t\t\t)\n\t\t\t.map(([slotName]) => slotName)\n\t\tif (halfSlots.length > 0 && !extensions.f16) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The program ${preview(name)} declares half-precision storage slots (${halfSlots.map(preview).join(', ')}), which need the f16 extension active on this pipeline.`,\n\t\t\t\t{ code: 'VALIDATION', context: { name, slots: halfSlots, extension: 'f16' } },\n\t\t\t)\n\t\t}\n\t\tconst [constantsKey, stageConstants] = this.#constants(\n\t\t\tname,\n\t\t\tprogram.overrides,\n\t\t\tresolved.constants,\n\t\t)\n\t\tconst slotList = slotEntries.map(([, slot]) => slot)\n\t\tthis.#fit(name, entry.size, slotList.length, program.uniform.struct.size)\n\t\tconst text = renderWGSLProgram(program, renderOptions)\n\t\tconst layout = this.#layout(slotList)\n\t\tconst pipelineKey = constantsKey.length === 0 ? text : `${text}\\0${constantsKey}`\n\t\tconst ready = this.#ready.get(pipelineKey)\n\t\tconst pipeline =\n\t\t\tready ??\n\t\t\t(await this.#compile(program, text, pipelineKey, renderOptions, layout, stageConstants))\n\t\tthis.#check()\n\t\tconst uniform = this.#group(program.uniform.struct.size)\n\t\treturn new WGSLStatement(this, {\n\t\t\tprogram,\n\t\t\tpipeline,\n\t\t\tlayout,\n\t\t\tuniform,\n\t\t\tcheck: this.#batchOptions.check,\n\t\t})\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, this.#batchOptions)\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// Validates caller override constants against the program's declarations and builds the cache key and WebGPU stage record.\n\t#constants(\n\t\tname: string,\n\t\toverrides: WGSLOverrideMap,\n\t\tsupplied: Readonly<Record<string, unknown>> | undefined,\n\t): readonly [key: string, values: Record<string, number> | undefined] {\n\t\tconst record = supplied ?? {}\n\t\tconst extra = Object.keys(record).filter((key) => !Object.hasOwn(overrides, key))\n\t\tif (extra.length > 0) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The program ${preview(name)} declares no override constants named ${extra.map(preview).join(', ')}.`,\n\t\t\t\t{ code: 'ARGUMENT', context: { name, extra } },\n\t\t\t)\n\t\t}\n\t\tconst entries: ReadonlyArray<\n\t\t\treadonly [name: string, stageKey: string, token: string, value: number]\n\t\t> = Object.entries(overrides).flatMap(([key, declaration]) => {\n\t\t\tif (!Object.hasOwn(record, key)) {\n\t\t\t\tif (declaration.value === undefined) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`The program ${preview(name)} requires an override constant for ${preview(key)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name, constant: key } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tconst raw = record[key]\n\t\t\tconst stageKey = declaration.id === undefined ? key : String(declaration.id)\n\t\t\tif (declaration.element === 'bool') {\n\t\t\t\tif (!isBoolean(raw)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`The override constant ${preview(key)} of ${preview(name)} expects a boolean; received ${preview(raw)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name, constant: key, element: declaration.element } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn [[key, stageKey, raw ? 'true' : 'false', raw ? 1 : 0] as const]\n\t\t\t}\n\t\t\tconst valid =\n\t\t\t\tdeclaration.element === 'u32'\n\t\t\t\t\t? isSafeInteger(raw) && !Object.is(raw, -0) && raw >= 0 && raw <= 0xffff_ffff\n\t\t\t\t\t: declaration.element === 'i32'\n\t\t\t\t\t\t? isSafeInteger(raw) && !Object.is(raw, -0) && raw >= -0x8000_0000 && raw <= 0x7fff_ffff\n\t\t\t\t\t\t: isFiniteNumber(raw) && Math.abs(raw) <= 3.4028234663852886e38\n\t\t\tif (!valid || !isNumber(raw)) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The override constant ${preview(key)} of ${preview(name)} expects a ${declaration.element} value; received ${preview(raw)}.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name, constant: key, element: declaration.element } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tconst token = Object.is(raw, -0) ? '-0' : String(raw)\n\t\t\treturn [[key, stageKey, token, raw] as const]\n\t\t})\n\t\tif (entries.length === 0) return ['', undefined]\n\t\tconst key = entries.map(([overrideName, , token]) => `${overrideName}=${token}`).join('\\0')\n\t\tconst values: Record<string, number> = Object.fromEntries(\n\t\t\tentries.map(([, stageKey, , value]) => [stageKey, value]),\n\t\t)\n\t\treturn [key, values]\n\t}\n\n\t// Throws when a workgroup size, a slot count, or a uniform struct size passes the device's limits.\n\t#fit(name: string, size: WGSLGrid, count: number, uniformSize: 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\tif (uniformSize > limits.maxUniformBufferBindingSize) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The program ${preview(name)} declares a ${uniformSize}-byte uniform struct, past the device's maxUniformBufferBindingSize of ${limits.maxUniformBufferBindingSize}.`,\n\t\t\t\t{\n\t\t\t\t\tcode: 'LIMIT',\n\t\t\t\t\tcontext: { name, size: uniformSize, limit: limits.maxUniformBufferBindingSize },\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t}\n\n\t// Returns the storage bind-group layout of one slot access and element-stride list, creating it once.\n\t#layout(slots: readonly WGSLSlot[]): GPUBindGroupLayout {\n\t\tconst key = slots\n\t\t\t.map((slot) => `${slot.access}:${Math.max(4, WGSL_STORAGE_STRIDES[slot.element])}`)\n\t\t\t.join(',')\n\t\tconst cached = this.#layouts.get(key)\n\t\tif (cached !== undefined) return cached\n\t\tconst entries = slots.map((slot, binding): GPUBindGroupLayoutEntry => ({\n\t\t\tbinding,\n\t\t\tvisibility: WGSL_STAGE.compute,\n\t\t\tbuffer: {\n\t\t\t\ttype: slot.access === 'read' ? 'read-only-storage' : 'storage',\n\t\t\t\tminBindingSize: Math.max(4, WGSL_STORAGE_STRIDES[slot.element]),\n\t\t\t},\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 or compiled shader module of one rendered text, evicting non-COMPILE failures.\n\t#module(\n\t\tprogram: WGSLProgram,\n\t\ttext: string,\n\t\trenderOptions: WGSLRenderOptions,\n\t): Promise<GPUShaderModule> {\n\t\tconst cached = this.#modules.get(text)\n\t\tif (cached !== undefined) return cached\n\t\tconst created = this.#compileModule(program, text, renderOptions)\n\t\tthis.#modules.set(text, created)\n\t\tcreated.then(undefined, (error: unknown) => {\n\t\t\tif (!isWGSLError(error) || error.code !== 'COMPILE') this.#modules.delete(text)\n\t\t})\n\t\treturn created\n\t}\n\n\t// Compiles one shader module inside a synchronous error scope; a compiler error names the section its line falls in.\n\tasync #compileModule(\n\t\tprogram: WGSLProgram,\n\t\ttext: string,\n\t\trenderOptions: WGSLRenderOptions,\n\t): Promise<GPUShaderModule> {\n\t\tconst { name } = program\n\t\tconst device = this.#device\n\t\tdevice.pushErrorScope('validation')\n\t\tconst module = device.createShaderModule({ label: name, code: text })\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\tconst section = collectWGSLSections(program, renderOptions).find(\n\t\t\t\t(candidate) => candidate.line <= line && line <= candidate.end,\n\t\t\t)\n\t\t\tconst located =\n\t\t\t\tsection === undefined ? {} : { role: section.role, local: line - section.line + 1 }\n\t\t\tconst fragment = section?.role === 'fragment' ? section.name : undefined\n\t\t\tconst owner = fragment === undefined ? {} : { fragment }\n\t\t\tconst within = fragment === undefined ? '' : ` in the fragment ${preview(fragment)}`\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The program ${preview(name)} does not compile at line ${line}, column ${column}${within}: ${message.message}`,\n\t\t\t\t{\n\t\t\t\t\tcode: 'COMPILE',\n\t\t\t\t\tcontext: { name, line, column, message: message.message, ...located, ...owner },\n\t\t\t\t},\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 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 module\n\t}\n\n\t// Returns the pending pipeline of one rendered text and constant specialization, or starts it; a failure other than COMPILE leaves the table.\n\t#compile(\n\t\tprogram: WGSLProgram,\n\t\ttext: string,\n\t\tpipelineKey: string,\n\t\trenderOptions: WGSLRenderOptions,\n\t\tlayout: GPUBindGroupLayout,\n\t\tconstants: Record<string, number> | undefined,\n\t): Promise<GPUComputePipeline> {\n\t\tconst pending = this.#pending.get(pipelineKey)\n\t\tif (pending !== undefined) return pending\n\t\tconst created = this.#build(program, text, renderOptions, layout, constants)\n\t\tthis.#pending.set(pipelineKey, created)\n\t\tcreated.then(\n\t\t\t(pipeline) => {\n\t\t\t\tthis.#ready.set(pipelineKey, pipeline)\n\t\t\t\tthis.#pending.delete(pipelineKey)\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\tif (!isWGSLError(error) || error.code !== 'COMPILE') this.#pending.delete(pipelineKey)\n\t\t\t},\n\t\t)\n\t\treturn created\n\t}\n\n\t// Reuses or compiles the shader module, builds the pipeline layout inside a synchronous error scope, and specializes the pipeline.\n\tasync #build(\n\t\tprogram: WGSLProgram,\n\t\ttext: string,\n\t\trenderOptions: WGSLRenderOptions,\n\t\tlayout: GPUBindGroupLayout,\n\t\tconstants: Record<string, number> | undefined,\n\t): Promise<GPUComputePipeline> {\n\t\tconst { name, entry } = program\n\t\tconst module = await this.#module(program, text, renderOptions)\n\t\tconst device = this.#device\n\t\tconst groups = [layout, this.#uniform]\n\t\tdevice.pushErrorScope('validation')\n\t\tconst layouts = device.createPipelineLayout({ label: name, bindGroupLayouts: groups })\n\t\tconst error = await device.popErrorScope()\n\t\tif (error !== null) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`The device refused the 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.name, constants)\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\tconstants: Record<string, number> | undefined,\n\t): Promise<GPUComputePipeline> {\n\t\tconst compute: GPUProgrammableStage =\n\t\t\tconstants === undefined\n\t\t\t\t? { module, entryPoint: entry }\n\t\t\t\t: { module, entryPoint: entry, constants }\n\t\ttry {\n\t\t\treturn await this.#device.createComputePipelineAsync({ label: name, layout, compute })\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 the smallest idle staging buffer of at least `size` bytes, creating a power-of-two buffer 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 the smallest unleased, unmapped staging buffer of at least `size` bytes, or `undefined`.\n\t#idle(size: number): GPUBuffer | undefined {\n\t\treturn [...this.#staging].reduce<GPUBuffer | undefined>((best, buffer) => {\n\t\t\tif (this.#leased.has(buffer) || buffer.mapState !== 'unmapped' || buffer.size < size) {\n\t\t\t\treturn best\n\t\t\t}\n\t\t\treturn best === undefined || buffer.size < best.size ? buffer : best\n\t\t}, undefined)\n\t}\n\n\t// Creates a power-of-two staging buffer (at least 256 bytes, capped at maxBufferSize) owned by the session.\n\t#allocate(size: number): GPUBuffer {\n\t\tconst limit = this.#device.limits.maxBufferSize\n\t\tif (size > limit) {\n\t\t\tthrow new WGSLError(\n\t\t\t\t`A staging allocation of ${size} bytes passes the device's maxBufferSize of ${limit}; split the read.`,\n\t\t\t\t{ code: 'LIMIT', context: { size, limit } },\n\t\t\t)\n\t\t}\n\t\tconst rounded =\n\t\t\tsize <= 256\n\t\t\t\t? 256\n\t\t\t\t: size <= 0x8000_0000\n\t\t\t\t\t? (1 << (32 - Math.clz32(size - 1))) >>> 0\n\t\t\t\t\t: 2 ** Math.ceil(Math.log2(size))\n\t\tconst allocated = Math.min(limit, rounded)\n\t\tconst usage = WGSL_USAGE.read | WGSL_USAGE.destination\n\t\tconst buffer = this.#device.createBuffer({ label: 'wgsl staging', size: allocated, 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 8 while no batch is open.\n\t#trim(): void {\n\t\tif (this.#batch !== undefined || this.#ending !== 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 - 8))\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, reads, and trace readbacks, and destroys the session's buffers and query set.\n\tasync #end(): Promise<void> {\n\t\tthis.#batch?.abort()\n\t\twhile (this.#inflight.size > 0) await Promise.allSettled([...this.#inflight])\n\t\tfor (const buffer of this.#staging) buffer.destroy()\n\t\tthis.#buffer.destroy()\n\t\tthis.#timestamps?.destroy()\n\t\tthis.#queries?.destroy()\n\t\tthis.#staging.clear()\n\t\tthis.#leased.clear()\n\t\tthis.#modules.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\tWGSLArgReduceInput,\n\tWGSLBroadcastInput,\n\tWGSLCompactInput,\n\tWGSLFieldMap,\n\tWGSLFragment,\n\tWGSLFragmentInput,\n\tWGSLGrid,\n\tWGSLHistogramInput,\n\tWGSLMonoidReduceInput,\n\tWGSLOverride,\n\tWGSLOverrideMap,\n\tWGSLPairSortInput,\n\tWGSLPartitionInput,\n\tWGSLPermuteInput,\n\tWGSLProgram,\n\tWGSLProgramInput,\n\tWGSLRadixRankInput,\n\tWGSLReduceInput,\n\tWGSLScanInput,\n\tWGSLSegmentedReduceInput,\n\tWGSLSegmentedScanInput,\n\tWGSLSessionInterface,\n\tWGSLSessionOptions,\n\tWGSLSlot,\n\tWGSLSlotMap,\n\tWGSLSortInput,\n\tWGSLStruct,\n\tWGSLSubgroupRange,\n\tWGSLTransposeInput,\n\tWGSLVariant,\n} from './types.js'\nimport {\n\tdefaultOption,\n\tisArray,\n\tisBoolean,\n\tisNonEmptyString,\n\tisNumber,\n\tisRecord,\n\tisSafeInteger,\n\tisString,\n\tliteralOf,\n\toptionFaultToError,\n\toptionalOption,\n\ttype OptionFieldsFor,\n\tpreview,\n\trequiredOption,\n\tresolveOptions,\n} from '@orkestrel/contract'\nimport {\n\tWGSL_ARG_REDUCE_OPERATIONS,\n\tWGSL_COMPENSATED,\n\tWGSL_HISTOGRAM_SIZES,\n\tWGSL_MATH,\n\tWGSL_MONOIDS,\n\tWGSL_ORDER,\n\tWGSL_REDUCE_ELEMENTS,\n\tWGSL_REDUCE_IDENTITIES,\n\tWGSL_REDUCE_OPERATIONS,\n\tWGSL_REDUCE_WIDTHS,\n\tWGSL_SCALARS,\n\tWGSL_SORT_ORDERS,\n\tWGSL_TILE,\n\tWGSL_TILE_SIZES,\n\tWGSL_WELFORD,\n\tWGSL_WORKGROUPS,\n} from './constants.js'\nimport { WGSLError } from './errors.js'\nimport { collectWGSLFragments } from './helpers.js'\nimport {\n\tisWGSLAccess,\n\tisWGSLExtension,\n\tisWGSLGrid,\n\tisWGSLIdentifier,\n\tisWGSLLanguage,\n\tisWGSLOverrideScalar,\n\tisWGSLScalar,\n\tisWGSLStorageElement,\n} 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 * The struct `name` must pass `isWGSLIdentifier`; field names sit in struct member scope rather than\n * module scope, so member names such as `length` are admitted without module-scope identifier\n * rejection. Thrown with code `ARGUMENT` when `name` is not a valid WGSL identifier, when `fields`\n * is not a plain record or declares no field, and when a field names a type outside `WGSL_SCALARS`;\n * `context.fields` lists each such 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 (!isWGSLIdentifier(name)) {\n\t\tthrow new WGSLError(\n\t\t\t`A struct name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { 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, its used fragments, and its conditional variants.\n *\n * @remarks\n * The text reaches the compiler unchanged. The fragment always carries a frozen `variants` list and\n * carries `workgroup` only when the input declares it. Each variant must declare at least one active\n * constraint (a non-empty `extensions` or `languages` list, a `subgroup` bound, or `linear: true`)\n * so no unconstrained variant shadows `source`. Thrown with code `ARGUMENT` when `name` is empty,\n * when a source is not a string, when `uses` or `variants` is not an array, when any variant names\n * an extension outside `WGSL_EXTENSIONS`, a language outside `WGSL_LANGUAGES`, an invalid subgroup\n * range outside `[4, 128]` or with `minimum > maximum`, `'subgroup_id'` in `languages` or\n * `subgroup` bounds without `'subgroups'` in `extensions`, a non-boolean `linear`, or no active\n * constraint, and when `workgroup` is declared and is not a positive safe integer.\n *\n * @param input - The fragment's name, text, used fragments, optional variants, and optional workgroup count\n * @returns The fragment, frozen\n *\n * @example\n * ```ts\n * createWGSLFragment({ name: 'square', source: 'fn square(value: f32) -> f32 { return value * value; }' }).variants // []\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 { workgroup } = input\n\tif (workgroup !== undefined && (!isSafeInteger(workgroup) || workgroup < 1)) {\n\t\tthrow new WGSLError(\n\t\t\t`The fragment ${preview(input.name)} needs a workgroup invocation count that is a positive safe integer; received ${preview(workgroup)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name, workgroup } },\n\t\t)\n\t}\n\tif (input.uses !== undefined && !isArray(input.uses)) {\n\t\tthrow new WGSLError(\n\t\t\t`The fragment ${preview(input.name)} needs an array in uses; received ${preview(input.uses)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t)\n\t}\n\tif (input.variants !== undefined && !isArray(input.variants)) {\n\t\tthrow new WGSLError(\n\t\t\t`The fragment ${preview(input.name)} needs an array in variants; received ${preview(input.variants)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t)\n\t}\n\tconst uses = Object.freeze([...(input.uses ?? [])])\n\tconst variants = Object.freeze(\n\t\t(input.variants ?? []).map((variant): WGSLVariant => {\n\t\t\tif (!isRecord(variant)) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`Each variant of fragment ${preview(input.name)} must be a record; received ${preview(variant)}.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (!isString(variant.source)) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The fragment ${preview(input.name)} needs WGSL text in variant.source; received ${preview(variant.source)}.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (\n\t\t\t\tvariant.extensions !== undefined &&\n\t\t\t\t(!isArray(variant.extensions) ||\n\t\t\t\t\t!variant.extensions.every((extension) => isWGSLExtension(extension)))\n\t\t\t) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The fragment ${preview(input.name)} declares an invalid extension in variant.extensions; use 'f16' or 'subgroups'.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (\n\t\t\t\tvariant.languages !== undefined &&\n\t\t\t\t(!isArray(variant.languages) ||\n\t\t\t\t\t!variant.languages.every((language) => isWGSLLanguage(language)))\n\t\t\t) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The fragment ${preview(input.name)} declares an invalid language in variant.languages; use 'packed_4x8_integer_dot_product' or 'subgroup_id'.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (variant.linear !== undefined && !isBoolean(variant.linear)) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The fragment ${preview(input.name)} needs a boolean in variant.linear; received ${preview(variant.linear)}.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tconst rawSubgroup = variant.subgroup\n\t\t\tif (rawSubgroup !== undefined && !isRecord(rawSubgroup)) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The fragment ${preview(input.name)} needs a record in variant.subgroup; received ${preview(rawSubgroup)}.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tconst rawMinimum = rawSubgroup?.minimum\n\t\t\tconst rawMaximum = rawSubgroup?.maximum\n\t\t\tif (\n\t\t\t\trawMinimum !== undefined &&\n\t\t\t\t(!isSafeInteger(rawMinimum) || rawMinimum < 4 || rawMinimum > 128)\n\t\t\t) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The fragment ${preview(input.name)} needs subgroup.minimum from 4 to 128; received ${preview(rawMinimum)}.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name, minimum: rawMinimum } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (\n\t\t\t\trawMaximum !== undefined &&\n\t\t\t\t(!isSafeInteger(rawMaximum) || rawMaximum < 4 || rawMaximum > 128)\n\t\t\t) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The fragment ${preview(input.name)} needs subgroup.maximum from 4 to 128; received ${preview(rawMaximum)}.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name, maximum: rawMaximum } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (rawSubgroup !== undefined && (rawMinimum ?? 4) > (rawMaximum ?? 128)) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The fragment ${preview(input.name)} declares subgroup.minimum (${rawMinimum ?? 4}) greater than subgroup.maximum (${rawMaximum ?? 128}).`,\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\t\tcontext: { name: input.name, minimum: rawMinimum, maximum: rawMaximum },\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t}\n\t\t\tconst subgroupBounds: WGSLSubgroupRange | undefined =\n\t\t\t\trawSubgroup === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: Object.freeze({\n\t\t\t\t\t\t\t...(rawMinimum !== undefined ? { minimum: rawMinimum } : {}),\n\t\t\t\t\t\t\t...(rawMaximum !== undefined ? { maximum: rawMaximum } : {}),\n\t\t\t\t\t\t})\n\t\t\tconst subgroupRequired =\n\t\t\t\t(variant.languages !== undefined && variant.languages.includes('subgroup_id')) ||\n\t\t\t\tsubgroupBounds !== undefined\n\t\t\tconst subgroupsDeclared =\n\t\t\t\tvariant.extensions !== undefined && variant.extensions.includes('subgroups')\n\t\t\tif (subgroupRequired && !subgroupsDeclared) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`Each variant of fragment ${preview(input.name)} that declares 'subgroup_id' or subgroup bounds must also include 'subgroups' in variant.extensions.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tconst constrained =\n\t\t\t\t(variant.extensions !== undefined && variant.extensions.length > 0) ||\n\t\t\t\t(variant.languages !== undefined && variant.languages.length > 0) ||\n\t\t\t\tsubgroupBounds !== undefined ||\n\t\t\t\tvariant.linear === true\n\t\t\tif (!constrained) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`Each variant of fragment ${preview(input.name)} must declare at least one extension, language, subgroup bound, or linear: true.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn Object.freeze({\n\t\t\t\t...(variant.extensions !== undefined\n\t\t\t\t\t? { extensions: Object.freeze([...variant.extensions]) }\n\t\t\t\t\t: {}),\n\t\t\t\t...(variant.languages !== undefined\n\t\t\t\t\t? { languages: Object.freeze([...variant.languages]) }\n\t\t\t\t\t: {}),\n\t\t\t\t...(subgroupBounds !== undefined ? { subgroup: subgroupBounds } : {}),\n\t\t\t\t...(variant.linear !== undefined ? { linear: variant.linear } : {}),\n\t\t\t\tsource: variant.source,\n\t\t\t})\n\t\t}),\n\t)\n\tconst sized = workgroup === undefined ? {} : { workgroup }\n\treturn Object.freeze({ name: input.name, source: input.source, uses, variants, ...sized })\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. Module-scope WGSL names\n * (`entry.name`, `uniform.name`, every slot key, and every override key) must pass\n * `isWGSLIdentifier`. Atomic storage elements (`'atomic<u32>'` and `'atomic<i32>'`) require\n * `'read_write'` access. Pipeline-overridable constants validate their scalar type, optional default\n * value, and optional unique `@id(N)` integer from `0` to `65535`. Thrown with code `ARGUMENT` for\n * any invalid declaration and with code `VALIDATION` for duplicate fragment names, cycles, or\n * mismatched fragment `workgroup` counts.\n *\n * @param input - The program's name, entry, slots, uniform, optional overrides, 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<\n\tS extends WGSLSlotMap,\n\tF extends WGSLFieldMap,\n\tO extends WGSLOverrideMap = Readonly<Record<never, WGSLOverride>>,\n>(input: WGSLProgramInput<S, F, O>): WGSLProgram<S, F, O>\nexport function createWGSLProgram(\n\tinput: WGSLProgramInput<WGSLSlotMap, WGSLFieldMap, WGSLOverrideMap>,\n): 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 (!isWGSLIdentifier(entry.name)) {\n\t\tthrow new WGSLError(\n\t\t\t`The program ${preview(input.name)} needs a valid WGSL identifier for 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\tif (!isRecord(input.slots)) {\n\t\tthrow new WGSLError(\n\t\t\t`The program ${preview(input.name)} needs a plain record of slots; received ${preview(input.slots)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t)\n\t}\n\tconst slots = Object.entries(input.slots)\n\tconst invalidSlots = slots\n\t\t.filter(([slotName, slot]) => {\n\t\t\tif (!isWGSLIdentifier(slotName) || !isRecord(slot)) return true\n\t\t\tconst access: unknown = slot.access\n\t\t\tconst element: unknown = slot.element\n\t\t\tif (!isWGSLAccess(access) || !isWGSLStorageElement(element)) return true\n\t\t\treturn access === 'read' && (element === 'atomic<u32>' || element === 'atomic<i32>')\n\t\t})\n\t\t.map(([slotName]) => slotName)\n\tif (invalidSlots.length > 0) {\n\t\tthrow new WGSLError(\n\t\t\t`The program ${preview(input.name)} declares invalid slots ${invalidSlots.map(preview).join(', ')}; use valid WGSL identifiers, 'read' or 'read_write' access, storage elements from WGSL_STORAGE_ELEMENTS, and 'read_write' for atomics.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name, slots: invalidSlots } },\n\t\t)\n\t}\n\tif (!isWGSLIdentifier(uniform.name)) {\n\t\tthrow new WGSLError(\n\t\t\t`The program ${preview(input.name)} needs a valid WGSL identifier for uniform.name; received ${preview(uniform.name)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t)\n\t}\n\tif (input.overrides !== undefined && !isRecord(input.overrides)) {\n\t\tthrow new WGSLError(\n\t\t\t`The program ${preview(input.name)} needs a plain record in overrides; received ${preview(input.overrides)}.`,\n\t\t\t{ code: 'ARGUMENT', context: { name: input.name } },\n\t\t)\n\t}\n\tconst seenIds = new Set<number>()\n\tconst overrideEntries = Object.entries(input.overrides ?? {}).map(\n\t\t([overrideName, declaration]): readonly [string, WGSLOverride] => {\n\t\t\tif (!isWGSLIdentifier(overrideName)) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The program ${preview(input.name)} declares an invalid override name ${preview(overrideName)}.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name, override: overrideName } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (!isRecord(declaration) || !isWGSLOverrideScalar(declaration.element)) {\n\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t`The override ${preview(overrideName)} in program ${preview(input.name)} needs an element in 'bool', 'u32', 'i32', or 'f32'.`,\n\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name, override: overrideName } },\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (declaration.id !== undefined) {\n\t\t\t\tif (\n\t\t\t\t\t!isSafeInteger(declaration.id) ||\n\t\t\t\t\tdeclaration.id < 0 ||\n\t\t\t\t\tdeclaration.id > 65_535 ||\n\t\t\t\t\tObject.is(declaration.id, -0)\n\t\t\t\t) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`The override ${preview(overrideName)} in program ${preview(input.name)} needs an integer @id from 0 to 65535; received ${preview(declaration.id)}.`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\t\t\tcontext: { name: input.name, override: overrideName, id: declaration.id },\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tif (seenIds.has(declaration.id)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`The program ${preview(input.name)} reuses override @id(${declaration.id}) on ${preview(overrideName)}; every override id must be unique.`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\t\t\tcontext: { name: input.name, override: overrideName, id: declaration.id },\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tseenIds.add(declaration.id)\n\t\t\t}\n\t\t\tconst idPart = declaration.id === undefined ? {} : { id: declaration.id }\n\t\t\tif (declaration.element === 'bool') {\n\t\t\t\tif (declaration.value !== undefined && !isBoolean(declaration.value)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`The bool override ${preview(overrideName)} in program ${preview(input.name)} needs a boolean default value; received ${preview(declaration.value)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name, override: overrideName } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn [\n\t\t\t\t\toverrideName,\n\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\telement: declaration.element,\n\t\t\t\t\t\t...(declaration.value !== undefined ? { value: declaration.value } : {}),\n\t\t\t\t\t\t...idPart,\n\t\t\t\t\t}),\n\t\t\t\t]\n\t\t\t}\n\t\t\tif (declaration.value !== undefined) {\n\t\t\t\tconst value = declaration.value\n\t\t\t\tconst valid =\n\t\t\t\t\tdeclaration.element === 'u32'\n\t\t\t\t\t\t? isSafeInteger(value) && value >= 0 && value <= 0xffff_ffff && !Object.is(value, -0)\n\t\t\t\t\t\t: declaration.element === 'i32'\n\t\t\t\t\t\t\t? isSafeInteger(value) &&\n\t\t\t\t\t\t\t\tvalue >= -2_147_483_648 &&\n\t\t\t\t\t\t\t\tvalue <= 2_147_483_647 &&\n\t\t\t\t\t\t\t\t!Object.is(value, -0)\n\t\t\t\t\t\t\t: isNumber(value) &&\n\t\t\t\t\t\t\t\tNumber.isFinite(value) &&\n\t\t\t\t\t\t\t\tMath.abs(value) <= 3.4028234663852886e38\n\t\t\t\tif (!valid) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`The ${declaration.element} override ${preview(overrideName)} in program ${preview(input.name)} received an out-of-range default ${preview(value)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name: input.name, override: overrideName } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn [\n\t\t\t\toverrideName,\n\t\t\t\tObject.freeze({\n\t\t\t\t\telement: declaration.element,\n\t\t\t\t\t...(declaration.value !== undefined ? { value: declaration.value } : {}),\n\t\t\t\t\t...idPart,\n\t\t\t\t}),\n\t\t\t]\n\t\t},\n\t)\n\tconst [x, y, z] = entry.size\n\tconst size: WGSLGrid = [x, y, z]\n\tconst fragments = collectWGSLFragments(input.uses ?? [])\n\tconst count = x * y * z\n\tconst unfit = fragments.find(\n\t\t(fragment) => fragment.workgroup !== undefined && fragment.workgroup !== count,\n\t)\n\tif (unfit?.workgroup !== undefined) {\n\t\tthrow new WGSLError(\n\t\t\t`The fragment ${preview(unfit.name)} needs a workgroup of ${unfit.workgroup} invocations, but the entry ${preview(entry.name)} declares [${x}, ${y}, ${z}], which holds ${count}; match the entry size to the fragment.`,\n\t\t\t{\n\t\t\t\tcode: 'VALIDATION',\n\t\t\t\tcontext: {\n\t\t\t\t\tname: input.name,\n\t\t\t\t\tfragment: unfit.name,\n\t\t\t\t\texpected: unfit.workgroup,\n\t\t\t\t\tactual: count,\n\t\t\t\t},\n\t\t\t},\n\t\t)\n\t}\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]): readonly [string, WGSLSlot] => [\n\t\t\t\t\tname,\n\t\t\t\t\tslot.access === 'read'\n\t\t\t\t\t\t? Object.freeze({ access: slot.access, element: slot.element })\n\t\t\t\t\t\t: Object.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\toverrides: Object.freeze(Object.fromEntries(overrideEntries)),\n\t\tfragments,\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 `options` is malformed, when `uniform.size` is not a\n * positive safe multiple of 4, when `trace.mode` is outside `WGSL_TRACE_MODES`, or when\n * `trace.capacity` is outside integers 1 to 2048.\n *\n * @param device - The device the session borrows\n * @param options - The extensions to switch off, host language features, uniform slab size, and optional tracer settings\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\n/**\n * Creates a frozen workgroup or partitioned reduction fragment for `sum`, `max`, `min`, `and`, `or`, `xor`, or `mul`.\n *\n * @remarks\n * Declares `var<workgroup> {stem}Shared` and\n * `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}) -> {element}`, setting\n * `workgroup` so `createWGSLProgram` refuses an entry of another invocation count. When `reordered`\n * is `false` (the default), attaches a `linear: true` `subgroups` variant running an exact top-down\n * `subgroupShuffleXor` butterfly (`0` ULP vs the 2D-safe halving tree, `0` barriers when\n * `subgroup_size >= width`). When `reordered` is `true`, attaches a `linear: true` `subgroups`\n * collective variant (and a 2D-safe `subgroup_id` variant when `width === workgroup`) seeded from\n * lane 0 without synthetic identity constants, preserving `±Infinity` and `-0.0`. Thrown with code\n * `ARGUMENT` for malformed options, a non-identifier `name`, `width > workgroup`, or bitwise\n * operations (`and`, `or`, `xor`) paired with floating-point elements (`f32`, `vec2f`, `vec4f`).\n *\n * @param input - The reduction's workgroup count, optional partition width, operation, element type, and optional name and reordering flag\n * @returns The frozen reduction fragment\n *\n * @example\n * ```ts\n * createWGSLReduce({ workgroup: 256, width: 32, operation: 'sum', element: 'f32' }).name // 'reduceSumF32256Width32'\n * ```\n */\nexport function createWGSLReduce(input: WGSLReduceInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t\twidth: optionalOption(literalOf(WGSL_REDUCE_WIDTHS)),\n\t\t\toperation: requiredOption(literalOf(WGSL_REDUCE_OPERATIONS)),\n\t\t\telement: requiredOption(literalOf(WGSL_REDUCE_ELEMENTS)),\n\t\t\treordered: defaultOption(isBoolean, false),\n\t\t} satisfies OptionFieldsFor<WGSLReduceInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLReduce')\n\t\t\t\treturn new WGSLError(`The reduction options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name, workgroup, width, operation, element }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A reduction fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tif (width !== undefined && width > workgroup) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A reduction partition width (${width}) must not exceed its workgroup (${workgroup}).`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { workgroup, width } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\t(operation === 'and' || operation === 'or' || operation === 'xor') &&\n\t\t\t\t\t(element === 'f32' || element === 'vec2f' || element === 'vec4f')\n\t\t\t\t) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`Bitwise reduction operation ${preview(operation)} requires 'u32' or 'i32', never ${preview(element)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { operation, element } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup, width, operation, element, reordered } = resolved\n\tconst effectiveWidth = width ?? workgroup\n\tconst half = effectiveWidth >> 1\n\tconst widthLog2 = Math.log2(effectiveWidth)\n\tconst partitioned = effectiveWidth < workgroup\n\tconst operationTag = operation.slice(0, 1).toUpperCase() + operation.slice(1)\n\tconst elementTag = element.toUpperCase()\n\tconst stem =\n\t\tname ??\n\t\t(partitioned\n\t\t\t? `reduce${operationTag}${elementTag}${workgroup}Width${effectiveWidth}`\n\t\t\t: `reduce${operationTag}${elementTag}${workgroup}`)\n\tconst [opPrefix, opInfix, opSuffix] =\n\t\toperation === 'sum'\n\t\t\t? ['', ' + ', '']\n\t\t\t: operation === 'mul'\n\t\t\t\t? ['', ' * ', '']\n\t\t\t\t: operation === 'max'\n\t\t\t\t\t? ['max(', ', ', ')']\n\t\t\t\t\t: operation === 'min'\n\t\t\t\t\t\t? ['min(', ', ', ')']\n\t\t\t\t\t\t: operation === 'and'\n\t\t\t\t\t\t\t? ['', ' & ', '']\n\t\t\t\t\t\t\t: operation === 'or'\n\t\t\t\t\t\t\t\t? ['', ' | ', '']\n\t\t\t\t\t\t\t\t: ['', ' ^ ', '']\n\tconst combineLeftRight = `${opPrefix}left${opInfix}right${opSuffix}`\n\tconst combineAccRight = `${opPrefix}acc${opInfix}right${opSuffix}`\n\tconst subgroupFunction =\n\t\toperation === 'sum'\n\t\t\t? 'subgroupAdd'\n\t\t\t: operation === 'mul'\n\t\t\t\t? 'subgroupMul'\n\t\t\t\t: operation === 'max'\n\t\t\t\t\t? 'subgroupMax'\n\t\t\t\t\t: operation === 'min'\n\t\t\t\t\t\t? 'subgroupMin'\n\t\t\t\t\t\t: operation === 'and'\n\t\t\t\t\t\t\t? 'subgroupAnd'\n\t\t\t\t\t\t\t: operation === 'or'\n\t\t\t\t\t\t\t\t? 'subgroupOr'\n\t\t\t\t\t\t\t\t: 'subgroupXor'\n\tconst source = [\n\t\t`var<workgroup> ${stem}Shared: array<${element}, ${workgroup}>;`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}) -> ${element} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t...(partitioned\n\t\t\t? [`\\tlet lane = local & ${effectiveWidth - 1}u;`, '\\tlet base = local - lane;']\n\t\t\t: []),\n\t\t`\\t${stem}Shared[local] = value;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tfor (var stride = ${half}u; stride > 0u; stride = stride >> 1u) {`,\n\t\t`\\t\\tif (${partitioned ? 'lane' : 'local'} < stride) {`,\n\t\t`\\t\\t\\tlet left = ${stem}Shared[local];`,\n\t\t`\\t\\t\\tlet right = ${stem}Shared[local + stride];`,\n\t\t`\\t\\t\\t${stem}Shared[local] = ${combineLeftRight};`,\n\t\t'\\t\\t}',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t'\\t}',\n\t\t`\\tlet total = ${stem}Shared[${partitioned ? 'base' : '0u'}];`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn total;',\n\t\t'}',\n\t].join('\\n')\n\tif (!reordered) {\n\t\tconst laneExpr = partitioned ? 'lane' : 'local'\n\t\tconst rowIndex = partitioned ? 'rowBase + lane' : 'local'\n\t\tconst rowZero = partitioned ? 'rowBase' : '0u'\n\t\tconst exactSubgroupSource = [\n\t\t\t`var<workgroup> ${stem}Shared: array<${element}, ${workgroup >> 1}>;`,\n\t\t\t'',\n\t\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}) -> ${element} {`,\n\t\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t\t`\\tif (sgSize >= ${effectiveWidth}u) {`,\n\t\t\t'\\t\\tvar acc = value;',\n\t\t\t`\\t\\tfor (var stride = ${half}u; stride > 0u; stride = stride >> 1u) {`,\n\t\t\t'\\t\\t\\tlet other = subgroupShuffleXor(acc, stride);',\n\t\t\t'\\t\\t\\tlet isLower = (local & stride) == 0u;',\n\t\t\t'\\t\\t\\tlet left = select(other, acc, isLower);',\n\t\t\t'\\t\\t\\tlet right = select(acc, other, isLower);',\n\t\t\t`\\t\\t\\tacc = ${combineLeftRight};`,\n\t\t\t'\\t\\t}',\n\t\t\t'\\t\\treturn acc;',\n\t\t\t'\\t}',\n\t\t\t...(partitioned\n\t\t\t\t? [\n\t\t\t\t\t\t`\\tlet lane = local & ${effectiveWidth - 1}u;`,\n\t\t\t\t\t\t`\\tlet rowBase = (local >> ${widthLog2}u) * ${half}u;`,\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t\t`\\tif (${laneExpr} >= ${half}u) {`,\n\t\t\t`\\t\\t${stem}Shared[${rowIndex} - ${half}u] = value;`,\n\t\t\t'\\t}',\n\t\t\t'\\tworkgroupBarrier();',\n\t\t\t'\\tvar acc = value;',\n\t\t\t`\\tif (${laneExpr} < ${half}u) {`,\n\t\t\t`\\t\\tlet right = ${stem}Shared[${rowIndex}];`,\n\t\t\t`\\t\\tacc = ${combineAccRight};`,\n\t\t\t`\\t\\tif (${half}u > sgSize) {`,\n\t\t\t`\\t\\t\\t${stem}Shared[${rowIndex}] = acc;`,\n\t\t\t'\\t\\t}',\n\t\t\t'\\t}',\n\t\t\t`\\tif (${half}u > sgSize) {`,\n\t\t\t'\\t\\tworkgroupBarrier();',\n\t\t\t`\\t\\tfor (var stride = ${half >> 1}u; stride >= sgSize; stride = stride >> 1u) {`,\n\t\t\t`\\t\\t\\tif (${laneExpr} < stride) {`,\n\t\t\t`\\t\\t\\t\\tlet left = ${stem}Shared[${rowIndex}];`,\n\t\t\t`\\t\\t\\t\\tlet right = ${stem}Shared[${rowIndex} + stride];`,\n\t\t\t`\\t\\t\\t\\t${stem}Shared[${rowIndex}] = ${combineLeftRight};`,\n\t\t\t'\\t\\t\\t}',\n\t\t\t'\\t\\t\\tworkgroupBarrier();',\n\t\t\t'\\t\\t}',\n\t\t\t`\\t\\tif (${laneExpr} < sgSize) {`,\n\t\t\t`\\t\\t\\tacc = ${stem}Shared[${rowIndex}];`,\n\t\t\t'\\t\\t}',\n\t\t\t'\\t}',\n\t\t\t'\\tfor (var stride = sgSize >> 1u; stride > 0u; stride = stride >> 1u) {',\n\t\t\t'\\t\\tlet other = subgroupShuffleXor(acc, stride);',\n\t\t\t'\\t\\tlet isLower = (local & stride) == 0u;',\n\t\t\t'\\t\\tlet left = select(other, acc, isLower);',\n\t\t\t'\\t\\tlet right = select(acc, other, isLower);',\n\t\t\t`\\t\\tacc = ${combineLeftRight};`,\n\t\t\t'\\t}',\n\t\t\t`\\tif (${laneExpr} == 0u) {`,\n\t\t\t`\\t\\t${stem}Shared[${rowZero}] = acc;`,\n\t\t\t'\\t}',\n\t\t\t'\\tworkgroupBarrier();',\n\t\t\t`\\tlet total = ${stem}Shared[${rowZero}];`,\n\t\t\t'\\tworkgroupBarrier();',\n\t\t\t'\\treturn total;',\n\t\t\t'}',\n\t\t].join('\\n')\n\t\treturn createWGSLFragment({\n\t\t\tname: stem,\n\t\t\tsource,\n\t\t\tvariants: [{ extensions: ['subgroups'], linear: true, source: exactSubgroupSource }],\n\t\t\tworkgroup,\n\t\t})\n\t}\n\tconst laneExpr = partitioned ? 'lane' : 'local'\n\tconst reorderedLinearSource = [\n\t\t`var<workgroup> ${stem}Shared: array<${element}, ${workgroup >> 2}>;`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}) -> ${element} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t`\\tif (sgSize == ${effectiveWidth}u) {`,\n\t\t`\\t\\treturn ${subgroupFunction}(value);`,\n\t\t'\\t}',\n\t\t`\\tif (sgSize > ${effectiveWidth}u) {`,\n\t\t'\\t\\tvar acc = value;',\n\t\t`\\t\\tfor (var stride = ${half}u; stride > 0u; stride = stride >> 1u) {`,\n\t\t'\\t\\t\\tlet other = subgroupShuffleXor(acc, stride);',\n\t\t'\\t\\t\\tlet isLower = (local & stride) == 0u;',\n\t\t'\\t\\t\\tlet left = select(other, acc, isLower);',\n\t\t'\\t\\t\\tlet right = select(acc, other, isLower);',\n\t\t`\\t\\t\\tacc = ${combineLeftRight};`,\n\t\t'\\t\\t}',\n\t\t'\\t\\treturn acc;',\n\t\t'\\t}',\n\t\t...(partitioned\n\t\t\t? [`\\tlet lane = local & ${effectiveWidth - 1}u;`, '\\tlet baseSlot = (local - lane) >> 2u;']\n\t\t\t: []),\n\t\t`\\tlet partial = ${subgroupFunction}(value);`,\n\t\t'\\tif (invocation.subgroup_invocation_id == 0u) {',\n\t\t`\\t\\t${stem}Shared[local >> 2u] = partial;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tif (${laneExpr} == 0u) {`,\n\t\t'\\t\\tlet step = sgSize >> 2u;',\n\t\t`\\t\\tvar acc = ${stem}Shared[${partitioned ? 'baseSlot' : '0u'}];`,\n\t\t`\\t\\tfor (var i = ${partitioned ? 'baseSlot + step' : 'step'}; i < ${partitioned ? `baseSlot + ${effectiveWidth >> 2}u` : `${workgroup >> 2}u`}; i += step) {`,\n\t\t`\\t\\t\\tlet right = ${stem}Shared[i];`,\n\t\t`\\t\\t\\tacc = ${combineAccRight};`,\n\t\t'\\t\\t}',\n\t\t`\\t\\t${stem}Shared[${partitioned ? 'baseSlot' : '0u'}] = acc;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tlet total = ${stem}Shared[${partitioned ? 'baseSlot' : '0u'}];`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn total;',\n\t\t'}',\n\t].join('\\n')\n\tconst reorderedGeneralSource = [\n\t\t`var<workgroup> ${stem}Shared: array<${element}, ${workgroup >> 2}>;`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}) -> ${element} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t`\\tlet partial = ${subgroupFunction}(value);`,\n\t\t'\\tif (dispatch.num_subgroups == 1u) {',\n\t\t'\\t\\treturn partial;',\n\t\t'\\t}',\n\t\t'\\tif (invocation.subgroup_invocation_id == 0u) {',\n\t\t`\\t\\t${stem}Shared[invocation.subgroup_id] = partial;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tif (local == 0u) {',\n\t\t`\\t\\tvar acc = ${stem}Shared[0u];`,\n\t\t'\\t\\tfor (var i = 1u; i < dispatch.num_subgroups; i += 1u) {',\n\t\t`\\t\\t\\tlet right = ${stem}Shared[i];`,\n\t\t`\\t\\t\\tacc = ${combineAccRight};`,\n\t\t'\\t\\t}',\n\t\t`\\t\\t${stem}Shared[0u] = acc;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tlet total = ${stem}Shared[0u];`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn total;',\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({\n\t\tname: stem,\n\t\tsource,\n\t\tvariants: partitioned\n\t\t\t? [{ extensions: ['subgroups'], linear: true, source: reorderedLinearSource }]\n\t\t\t: [\n\t\t\t\t\t{ extensions: ['subgroups'], linear: true, source: reorderedLinearSource },\n\t\t\t\t\t{\n\t\t\t\t\t\textensions: ['subgroups'],\n\t\t\t\t\t\tlanguages: ['subgroup_id'],\n\t\t\t\t\t\tsource: reorderedGeneralSource,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\tworkgroup,\n\t})\n}\n\n/**\n * Creates a frozen workgroup arg-reduction fragment returning both the winning value and its index.\n *\n * @remarks\n * Declares `struct {Stem}Result { value: {element}, index: u32 }`, one workgroup variable\n * `{stem}Shared`, and `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element},\n * index: u32) -> {Stem}Result`. Ties always resolve to the lowest `index`, `f32` comparisons use\n * bit-level subnormal-safe total-order keys (`-0.0` ties `+0.0` by index while preserving original\n * bits, and finite or infinite values always beat `NaN`), and both the 2D-safe base and the\n * `linear: true` `subgroups` variant return through `workgroupUniformLoad`. When padding inactive\n * `f32` lanes with a `NaN` or `±Infinity` sentinel, mask the bit pattern with a runtime input such\n * as `bitcast<f32>(0x7fc00000u | (invocation.local_invocation_index & 0u))` (`0xff800000u` for\n * `-Infinity`, `0x7f800000u` for `+Infinity`), because Tint rejects const-expression `NaN` and\n * `Infinity` bitcasts. Thrown with code `ARGUMENT` for malformed options or an invalid `name`.\n *\n * @param input - The arg-reduction's workgroup count, selecting operation, element type, and optional name\n * @returns The frozen arg-reduction fragment\n *\n * @example\n * ```ts\n * createWGSLArgReduce({ workgroup: 128, operation: 'max', element: 'f32' }).name // 'argReduceMaxF32128'\n * ```\n */\nexport function createWGSLArgReduce(input: WGSLArgReduceInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t\toperation: requiredOption(literalOf(WGSL_ARG_REDUCE_OPERATIONS)),\n\t\t\telement: requiredOption(literalOf(WGSL_SCALARS)),\n\t\t} satisfies OptionFieldsFor<WGSLArgReduceInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLArgReduce')\n\t\t\t\treturn new WGSLError(`The arg-reduction options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`An arg-reduction fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup, operation, element } = resolved\n\tconst operationTag = operation === 'max' ? 'Max' : 'Min'\n\tconst elementTag = element.toUpperCase()\n\tconst stem = name ?? `argReduce${operationTag}${elementTag}${workgroup}`\n\tconst pascal = `${stem.slice(0, 1).toUpperCase()}${stem.slice(1)}`\n\tconst resultType = `${pascal}Result`\n\tconst scratchType = `${pascal}Scratch`\n\tconst compare = operation === 'max' ? '>' : '<'\n\tconst nanSentinel = operation === 'max' ? '0u' : '0xffffffffu'\n\tconst subgroupBest = operation === 'max' ? 'subgroupMax' : 'subgroupMin'\n\tconst keyType = element === 'f32' ? 'u32' : element\n\tconst baseComparisonLines =\n\t\telement === 'f32'\n\t\t\t? [\n\t\t\t\t\t'\\t\\t\\tlet leftRaw = bitcast<u32>(left.value);',\n\t\t\t\t\t'\\t\\t\\tlet leftMag = leftRaw & 0x7fffffffu;',\n\t\t\t\t\t'\\t\\t\\tlet leftCanon = select(leftRaw, 0u, leftMag == 0u);',\n\t\t\t\t\t'\\t\\t\\tlet leftOrdered = leftCanon ^ select(0x80000000u, 0xffffffffu, (leftCanon & 0x80000000u) != 0u);',\n\t\t\t\t\t`\\t\\t\\tlet leftKey = select(leftOrdered, ${nanSentinel}, leftMag > 0x7f800000u);`,\n\t\t\t\t\t'\\t\\t\\tlet rightRaw = bitcast<u32>(right.value);',\n\t\t\t\t\t'\\t\\t\\tlet rightMag = rightRaw & 0x7fffffffu;',\n\t\t\t\t\t'\\t\\t\\tlet rightCanon = select(rightRaw, 0u, rightMag == 0u);',\n\t\t\t\t\t'\\t\\t\\tlet rightOrdered = rightCanon ^ select(0x80000000u, 0xffffffffu, (rightCanon & 0x80000000u) != 0u);',\n\t\t\t\t\t`\\t\\t\\tlet rightKey = select(rightOrdered, ${nanSentinel}, rightMag > 0x7f800000u);`,\n\t\t\t\t\t`\\t\\t\\tlet takeRight = rightKey ${compare} leftKey || (rightKey == leftKey && right.index < left.index);`,\n\t\t\t\t]\n\t\t\t: [\n\t\t\t\t\t`\\t\\t\\tlet takeRight = right.value ${compare} left.value || (right.value == left.value && right.index < left.index);`,\n\t\t\t\t]\n\tconst source = [\n\t\t`struct ${resultType} {`,\n\t\t`\\tvalue: ${element},`,\n\t\t'\\tindex: u32,',\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: array<${resultType}, ${workgroup}>;`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}, index: u32) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t`\\t${stem}Shared[local] = ${resultType}(value, index);`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tfor (var stride = ${workgroup >> 1}u; stride > 0u; stride = stride >> 1u) {`,\n\t\t'\\t\\tif (local < stride) {',\n\t\t`\\t\\t\\tlet left = ${stem}Shared[local];`,\n\t\t`\\t\\t\\tlet right = ${stem}Shared[local + stride];`,\n\t\t...baseComparisonLines,\n\t\t'\\t\\t\\tif (takeRight) {',\n\t\t`\\t\\t\\t\\t${stem}Shared[local] = right;`,\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t}',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t'\\t}',\n\t\t`\\treturn workgroupUniformLoad(&${stem}Shared[0u]);`,\n\t\t'}',\n\t].join('\\n')\n\tconst keyInitLines =\n\t\telement === 'f32'\n\t\t\t? [\n\t\t\t\t\t'\\tlet raw = bitcast<u32>(value);',\n\t\t\t\t\t'\\tlet mag = raw & 0x7fffffffu;',\n\t\t\t\t\t'\\tlet canon = select(raw, 0u, mag == 0u);',\n\t\t\t\t\t'\\tlet ordered = canon ^ select(0x80000000u, 0xffffffffu, (canon & 0x80000000u) != 0u);',\n\t\t\t\t\t`\\tlet key = select(ordered, ${nanSentinel}, mag > 0x7f800000u);`,\n\t\t\t\t]\n\t\t\t: ['\\tlet key = value;']\n\tconst variantSource = [\n\t\t`struct ${resultType} {`,\n\t\t`\\tvalue: ${element},`,\n\t\t'\\tindex: u32,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t`\\tkeys: array<${keyType}, ${workgroup >> 2}>,`,\n\t\t`\\tindices: array<u32, ${workgroup >> 2}>,`,\n\t\t`\\tvalues: array<${element}, ${workgroup >> 2}>,`,\n\t\t`\\twinner: ${resultType},`,\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}, index: u32) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet sgLane = invocation.subgroup_invocation_id;',\n\t\t...keyInitLines,\n\t\t`\\tlet bestKey = ${subgroupBest}(key);`,\n\t\t'\\tlet bestIndex = subgroupMin(select(0xffffffffu, index, key == bestKey));',\n\t\t'\\tlet winLane = subgroupMin(select(0xffffffffu, sgLane, key == bestKey && index == bestIndex));',\n\t\t'\\tlet bestValue = subgroupShuffle(value, winLane);',\n\t\t`\\tif (dispatch.subgroup_size >= ${workgroup}u) {`,\n\t\t'\\t\\tif (local == 0u) {',\n\t\t`\\t\\t\\t${stem}Shared.winner = ${resultType}(bestValue, bestIndex);`,\n\t\t'\\t\\t}',\n\t\t`\\t\\treturn workgroupUniformLoad(&${stem}Shared.winner);`,\n\t\t'\\t}',\n\t\t'\\tif (sgLane == 0u) {',\n\t\t'\\t\\tlet slot = local >> 2u;',\n\t\t`\\t\\t${stem}Shared.keys[slot] = bestKey;`,\n\t\t`\\t\\t${stem}Shared.indices[slot] = bestIndex;`,\n\t\t`\\t\\t${stem}Shared.values[slot] = bestValue;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tif (local == 0u) {',\n\t\t'\\t\\tlet step = dispatch.subgroup_size >> 2u;',\n\t\t`\\t\\tvar bk = ${stem}Shared.keys[0u];`,\n\t\t`\\t\\tvar bi = ${stem}Shared.indices[0u];`,\n\t\t`\\t\\tvar bv = ${stem}Shared.values[0u];`,\n\t\t`\\t\\tfor (var i = step; i < ${workgroup >> 2}u; i += step) {`,\n\t\t`\\t\\t\\tlet rk = ${stem}Shared.keys[i];`,\n\t\t`\\t\\t\\tlet ri = ${stem}Shared.indices[i];`,\n\t\t`\\t\\t\\tif (rk ${compare} bk || (rk == bk && ri < bi)) {`,\n\t\t'\\t\\t\\t\\tbk = rk;',\n\t\t'\\t\\t\\t\\tbi = ri;',\n\t\t`\\t\\t\\t\\tbv = ${stem}Shared.values[i];`,\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t}',\n\t\t`\\t\\t${stem}Shared.winner = ${resultType}(bv, bi);`,\n\t\t'\\t}',\n\t\t`\\treturn workgroupUniformLoad(&${stem}Shared.winner);`,\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({\n\t\tname: stem,\n\t\tsource,\n\t\tvariants: [{ extensions: ['subgroups'], linear: true, source: variantSource }],\n\t\tworkgroup,\n\t})\n}\n\n/**\n * Creates a frozen work-efficient workgroup prefix or suffix scan fragment for any reduction operation.\n *\n * @remarks\n * Declares one workgroup variable `{stem}Shared` and\n * `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}) -> {element}`. The\n * 2D-safe base uses trimmed Blelloch (removing the dead final up-sweep iteration and zeroing\n * barrier). For associative exact scans (`u32` and `i32` on all operations, `f32` on `max`/`min`),\n * attaches both a 1D `linear: true` direct subgroup variant and a 2D-safe remapped subgroup variant\n * requiring `subgroup_id`; for floating-point `sum` and `mul`, attaches those variants only when\n * `reordered: true`. For `f32` `max` and `min` scans, neutral carry slots use runtime `±Infinity`\n * and exclusive logical slot `0` maps to the finite `WGSL_REDUCE_IDENTITIES` boundary so the base\n * Blelloch, 1D direct, and 2D remapped variants stay bit-identical on `±Infinity` prefixes. Thrown\n * with code `ARGUMENT` for malformed options, an invalid `name`, or bitwise operations (`and`,\n * `or`, `xor`) paired with `'f32'`.\n *\n * @param input - The scan's workgroup count, element type, and optional operation, direction, exclusivity, reordering, and name\n * @returns The frozen scan fragment\n *\n * @example\n * ```ts\n * createWGSLScan({ workgroup: 256, element: 'u32', exclusive: true }).name // 'scanExclusiveU32256'\n * ```\n */\nexport function createWGSLScan(input: WGSLScanInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t\toperation: defaultOption(literalOf(WGSL_REDUCE_OPERATIONS), 'sum'),\n\t\t\telement: requiredOption(literalOf(WGSL_SCALARS)),\n\t\t\texclusive: defaultOption(isBoolean, false),\n\t\t\treverse: defaultOption(isBoolean, false),\n\t\t\treordered: defaultOption(isBoolean, false),\n\t\t} satisfies OptionFieldsFor<WGSLScanInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLScan')\n\t\t\t\treturn new WGSLError(`The scan options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name, operation, element }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A scan fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\telement === 'f32' &&\n\t\t\t\t\t(operation === 'and' || operation === 'or' || operation === 'xor')\n\t\t\t\t) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`Bitwise scan operation ${preview(operation)} requires 'u32' or 'i32', never 'f32'.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { operation, element } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup, operation, element, exclusive, reverse, reordered } = resolved\n\tconst reverseTag = reverse ? 'Reverse' : ''\n\tconst exclusiveTag = exclusive ? 'Exclusive' : 'Inclusive'\n\tconst operationTag =\n\t\toperation === 'sum' ? '' : operation.slice(0, 1).toUpperCase() + operation.slice(1)\n\tconst elementTag = element.toUpperCase()\n\tconst stem = name ?? `scan${reverseTag}${exclusiveTag}${operationTag}${elementTag}${workgroup}`\n\tconst scratchType = `${stem.slice(0, 1).toUpperCase()}${stem.slice(1)}Scratch`\n\tconst identity =\n\t\telement === 'f32'\n\t\t\t? operation === 'and' || operation === 'or' || operation === 'xor'\n\t\t\t\t? ''\n\t\t\t\t: WGSL_REDUCE_IDENTITIES[operation].f32\n\t\t\t: WGSL_REDUCE_IDENTITIES[operation][element]\n\tconst floatExtremum = element === 'f32' && (operation === 'max' || operation === 'min')\n\tconst carryIdentity = floatExtremum\n\t\t? operation === 'max'\n\t\t\t? 'bitcast<f32>(0xff800000u | (local & 0u))'\n\t\t\t: 'bitcast<f32>(0x7f800000u | (local & 0u))'\n\t\t: identity\n\tconst [opPrefix, opInfix, opSuffix] =\n\t\toperation === 'sum'\n\t\t\t? ['', ' + ', '']\n\t\t\t: operation === 'mul'\n\t\t\t\t? ['', ' * ', '']\n\t\t\t\t: operation === 'max'\n\t\t\t\t\t? ['max(', ', ', ')']\n\t\t\t\t\t: operation === 'min'\n\t\t\t\t\t\t? ['min(', ', ', ')']\n\t\t\t\t\t\t: operation === 'and'\n\t\t\t\t\t\t\t? ['', ' & ', '']\n\t\t\t\t\t\t\t: operation === 'or'\n\t\t\t\t\t\t\t\t? ['', ' | ', '']\n\t\t\t\t\t\t\t\t: ['', ' ^ ', '']\n\tconst slotExpr = reverse ? `${workgroup - 1}u - local` : 'local'\n\tconst baseResultExpr = exclusive\n\t\t? floatExtremum\n\t\t\t? `select(excl, ${identity}, slot == 0u)`\n\t\t\t: 'excl'\n\t\t: `select(${opPrefix}excl${opInfix}value${opSuffix}, value, slot == 0u)`\n\tconst source = [\n\t\t`var<workgroup> ${stem}Shared: array<${element}, ${workgroup}>;`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}) -> ${element} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t`\\tlet slot = ${slotExpr};`,\n\t\t`\\t${stem}Shared[slot] = select(value, ${carryIdentity}, slot == ${workgroup - 1}u);`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tfor (var offset = 1u; offset < ${workgroup >> 1}u; offset = offset << 1u) {`,\n\t\t'\\t\\tlet stride = offset << 1u;',\n\t\t`\\t\\tif (slot < ${workgroup - 1}u && ((slot + 1u) & (stride - 1u)) == 0u) {`,\n\t\t`\\t\\t\\tlet left = ${stem}Shared[slot - offset];`,\n\t\t`\\t\\t\\tlet right = ${stem}Shared[slot];`,\n\t\t`\\t\\t\\t${stem}Shared[slot] = ${opPrefix}left${opInfix}right${opSuffix};`,\n\t\t'\\t\\t}',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t'\\t}',\n\t\t`\\tfor (var offset = ${workgroup >> 1}u; offset > 0u; offset = offset >> 1u) {`,\n\t\t'\\t\\tlet stride = offset << 1u;',\n\t\t'\\t\\tif (((slot + 1u) & (stride - 1u)) == 0u) {',\n\t\t`\\t\\t\\tlet prior = ${stem}Shared[slot - offset];`,\n\t\t`\\t\\t\\tlet carried = ${stem}Shared[slot];`,\n\t\t`\\t\\t\\t${stem}Shared[slot - offset] = carried;`,\n\t\t`\\t\\t\\t${stem}Shared[slot] = ${opPrefix}carried${opInfix}prior${opSuffix};`,\n\t\t'\\t\\t}',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t'\\t}',\n\t\t`\\tlet excl = ${stem}Shared[slot];`,\n\t\t`\\tlet result = ${baseResultExpr};`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn result;',\n\t\t'}',\n\t].join('\\n')\n\tconst attachSubgroup =\n\t\treordered || element !== 'f32' || operation === 'max' || operation === 'min'\n\tif (!attachSubgroup) {\n\t\treturn createWGSLFragment({ name: stem, source, workgroup })\n\t}\n\tconst stage1Lines =\n\t\toperation === 'sum'\n\t\t\t? ['\\tlet sgExclRaw = subgroupExclusiveAdd(sgInput);', '\\tlet sgTotal = sgExclRaw + sgInput;']\n\t\t\t: operation === 'mul'\n\t\t\t\t? [\n\t\t\t\t\t\t'\\tlet sgExclRaw = subgroupExclusiveMul(sgInput);',\n\t\t\t\t\t\t'\\tlet sgTotal = sgExclRaw * sgInput;',\n\t\t\t\t\t]\n\t\t\t\t: [\n\t\t\t\t\t\t'\\tvar sgIncl = sgInput;',\n\t\t\t\t\t\t'\\tfor (var delta = 1u; delta < activeSg; delta = delta << 1u) {',\n\t\t\t\t\t\t'\\t\\tlet up = subgroupShuffleUp(sgIncl, delta);',\n\t\t\t\t\t\t'\\t\\tif (sgLane >= delta) {',\n\t\t\t\t\t\t`\\t\\t\\tsgIncl = ${opPrefix}up${opInfix}sgIncl${opSuffix};`,\n\t\t\t\t\t\t'\\t\\t}',\n\t\t\t\t\t\t'\\t}',\n\t\t\t\t\t\t'\\tlet prev = subgroupShuffleUp(sgIncl, 1u);',\n\t\t\t\t\t\t`\\tlet sgExclRaw = select(${carryIdentity}, prev, sgLane > 0u);`,\n\t\t\t\t\t\t'\\tlet sgTotal = sgIncl;',\n\t\t\t\t\t]\n\tconst stage2ScanLines =\n\t\toperation === 'sum'\n\t\t\t? ['\\t\\tlet sgBase = subgroupExclusiveAdd(sgVal);']\n\t\t\t: operation === 'mul'\n\t\t\t\t? ['\\t\\tlet sgBase = subgroupExclusiveMul(sgVal);']\n\t\t\t\t: [\n\t\t\t\t\t\t'\\t\\tvar baseIncl = sgVal;',\n\t\t\t\t\t\t'\\t\\tfor (var delta = 1u; delta < activeSg; delta = delta << 1u) {',\n\t\t\t\t\t\t'\\t\\t\\tlet up = subgroupShuffleUp(baseIncl, delta);',\n\t\t\t\t\t\t'\\t\\t\\tif (sgLane >= delta) {',\n\t\t\t\t\t\t`\\t\\t\\t\\tbaseIncl = ${opPrefix}up${opInfix}baseIncl${opSuffix};`,\n\t\t\t\t\t\t'\\t\\t\\t}',\n\t\t\t\t\t\t'\\t\\t}',\n\t\t\t\t\t\t'\\t\\tlet basePrev = subgroupShuffleUp(baseIncl, 1u);',\n\t\t\t\t\t\t`\\t\\tlet sgBase = select(${carryIdentity}, basePrev, sgLane > 0u);`,\n\t\t\t\t\t]\n\tconst firstLocal = reverse ? `${workgroup - 1}u` : '0u'\n\tconst directResultExpr = exclusive\n\t\t? floatExtremum\n\t\t\t? `select(excl, ${identity}, local == ${firstLocal})`\n\t\t\t: 'excl'\n\t\t: `select(${opPrefix}excl${opInfix}value${opSuffix}, value, local == ${firstLocal})`\n\tconst directSource = [\n\t\t`var<workgroup> ${stem}Shared: array<${element}, ${workgroup >> 2}>;`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}) -> ${element} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet sgId = invocation.subgroup_id;',\n\t\t'\\tlet sgLane = invocation.subgroup_invocation_id;',\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t'\\tlet numSg = dispatch.num_subgroups;',\n\t\t`\\tlet activeSg = min(sgSize, ${workgroup}u);`,\n\t\t...(reverse\n\t\t\t? [\n\t\t\t\t\t'\\tlet revLane = (activeSg - 1u) - sgLane;',\n\t\t\t\t\t'\\tlet sgSlot = (numSg - 1u) - sgId;',\n\t\t\t\t\t'\\tlet sgInput = subgroupShuffle(value, revLane);',\n\t\t\t\t]\n\t\t\t: ['\\tlet sgSlot = sgId;', '\\tlet sgInput = value;']),\n\t\t...stage1Lines,\n\t\t'\\tif (sgLane == activeSg - 1u) {',\n\t\t`\\t\\t${stem}Shared[sgSlot] = sgTotal;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tif (numSg <= sgSize) {',\n\t\t'\\t\\tlet isLive = sgId == 0u && sgLane < numSg;',\n\t\t`\\t\\tlet sgVal = select(${carryIdentity}, ${stem}Shared[select(0u, sgLane, isLive)], isLive);`,\n\t\t...stage2ScanLines,\n\t\t'\\t\\tif (isLive) {',\n\t\t`\\t\\t\\t${stem}Shared[sgLane] = sgBase;`,\n\t\t'\\t\\t}',\n\t\t'\\t} else {',\n\t\t'\\t\\tif (local == 0u) {',\n\t\t`\\t\\t\\tvar running: ${element} = ${carryIdentity};`,\n\t\t'\\t\\t\\tfor (var i = 0u; i < numSg; i += 1u) {',\n\t\t`\\t\\t\\t\\tlet current = ${stem}Shared[i];`,\n\t\t`\\t\\t\\t\\t${stem}Shared[i] = running;`,\n\t\t`\\t\\t\\t\\trunning = ${opPrefix}running${opInfix}current${opSuffix};`,\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\treverse ? '\\tlet sgExcl = subgroupShuffle(sgExclRaw, revLane);' : '\\tlet sgExcl = sgExclRaw;',\n\t\t`\\tlet prefix = ${stem}Shared[sgSlot];`,\n\t\t`\\tlet excl = select(${opPrefix}prefix${opInfix}sgExcl${opSuffix}, sgExcl, sgSlot == 0u);`,\n\t\t`\\tlet result = ${directResultExpr};`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn result;',\n\t\t'}',\n\t].join('\\n')\n\tconst remappedSource = [\n\t\t`struct ${scratchType} {`,\n\t\t`\\titems: array<${element}, ${workgroup}>,`,\n\t\t`\\ttotals: array<${element}, ${workgroup >> 2}>,`,\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}) -> ${element} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t`\\tlet slot = ${slotExpr};`,\n\t\t'\\tlet sgId = invocation.subgroup_id;',\n\t\t'\\tlet sgLane = invocation.subgroup_invocation_id;',\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t'\\tlet numSg = dispatch.num_subgroups;',\n\t\t`\\tlet activeSg = min(sgSize, ${workgroup}u);`,\n\t\t`\\t${stem}Shared.items[slot] = value;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tlet lin = sgId * sgSize + sgLane;',\n\t\t`\\tlet sgInput = ${stem}Shared.items[lin];`,\n\t\t...stage1Lines,\n\t\t'\\tif (sgLane == activeSg - 1u) {',\n\t\t`\\t\\t${stem}Shared.totals[sgId] = sgTotal;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tif (numSg <= sgSize) {',\n\t\t'\\t\\tlet isLive = sgId == 0u && sgLane < numSg;',\n\t\t`\\t\\tlet sgVal = select(${carryIdentity}, ${stem}Shared.totals[select(0u, sgLane, isLive)], isLive);`,\n\t\t...stage2ScanLines,\n\t\t'\\t\\tif (isLive) {',\n\t\t`\\t\\t\\t${stem}Shared.totals[sgLane] = sgBase;`,\n\t\t'\\t\\t}',\n\t\t'\\t} else {',\n\t\t'\\t\\tif (local == 0u) {',\n\t\t`\\t\\t\\tvar running: ${element} = ${carryIdentity};`,\n\t\t'\\t\\t\\tfor (var i = 0u; i < numSg; i += 1u) {',\n\t\t`\\t\\t\\t\\tlet current = ${stem}Shared.totals[i];`,\n\t\t`\\t\\t\\t\\t${stem}Shared.totals[i] = running;`,\n\t\t`\\t\\t\\t\\trunning = ${opPrefix}running${opInfix}current${opSuffix};`,\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tlet prefix = ${stem}Shared.totals[sgId];`,\n\t\t`\\t${stem}Shared.items[lin] = select(${opPrefix}prefix${opInfix}sgExclRaw${opSuffix}, sgExclRaw, sgId == 0u);`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tlet excl = ${stem}Shared.items[slot];`,\n\t\t`\\tlet result = ${baseResultExpr};`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn result;',\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({\n\t\tname: stem,\n\t\tsource,\n\t\tvariants: [\n\t\t\t{\n\t\t\t\textensions: ['subgroups'],\n\t\t\t\tlanguages: ['subgroup_id'],\n\t\t\t\tlinear: true,\n\t\t\t\tsource: directSource,\n\t\t\t},\n\t\t\t{\n\t\t\t\textensions: ['subgroups'],\n\t\t\t\tlanguages: ['subgroup_id'],\n\t\t\t\tsource: remappedSource,\n\t\t\t},\n\t\t],\n\t\tworkgroup,\n\t})\n}\n\n/**\n * Creates a frozen workgroup broadcast fragment returning one selected lane's value uniformly.\n *\n * @remarks\n * Declares an 8-byte `struct {Stem}Slot { lane: u32, value: {element} }`,\n * `var<workgroup> {stem}Shared: {Stem}Slot`, and\n * `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}, lane: u32) -> {element}`.\n * Invocation `0` supplies the winning `lane`, clamped to `workgroup - 1`, and the selected element\n * is loaded with `workgroupUniformLoad` (3 total barriers), so Tint treats the returned scalar as\n * workgroup-uniform even when `lane` varies across invocations. Thrown with code `ARGUMENT` for\n * malformed options or an invalid `name`.\n *\n * @param input - The broadcast's workgroup count, element type, and optional name\n * @returns The frozen broadcast fragment\n *\n * @example\n * ```ts\n * createWGSLBroadcast({ workgroup: 64, element: 'f32' }).name // 'broadcastF3264'\n * ```\n */\nexport function createWGSLBroadcast(input: WGSLBroadcastInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t\telement: requiredOption(literalOf(WGSL_SCALARS)),\n\t\t} satisfies OptionFieldsFor<WGSLBroadcastInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLBroadcast')\n\t\t\t\treturn new WGSLError(`The broadcast options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A broadcast fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup, element } = resolved\n\tconst stem = name ?? `broadcast${element.toUpperCase()}${workgroup}`\n\tconst slotType = `${stem.slice(0, 1).toUpperCase()}${stem.slice(1)}Slot`\n\tconst source = [\n\t\t`struct ${slotType} {`,\n\t\t'\\tlane: u32,',\n\t\t`\\tvalue: ${element},`,\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${slotType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}, lane: u32) -> ${element} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tif (local == 0u) {',\n\t\t`\\t\\t${stem}Shared.lane = min(lane, ${workgroup - 1}u);`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tif (local == ${stem}Shared.lane) {`,\n\t\t`\\t\\t${stem}Shared.value = value;`,\n\t\t'\\t}',\n\t\t`\\treturn workgroupUniformLoad(&${stem}Shared.value);`,\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({ name: stem, source, workgroup })\n}\n\n/**\n * Creates a frozen workgroup or partitioned bitonic sort fragment in `'ascending'` or `'descending'` order.\n *\n * @remarks\n * Declares one 4-byte-per-lane shared array `var<workgroup> {stem}Shared` and\n * `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}) -> {element}`. `width`\n * defaults to `workgroup` and must not exceed `workgroup`; when `width < workgroup`, each\n * contiguous `width`-lane partition sorts independently using `lane = local & (width - 1)`. For\n * `'f32'`, links `WGSL_ORDER` and sorts invertible total-order `u32` keys so `-0.0` stays distinct\n * from `+0.0` and `NaN` always lands at the end of both `'ascending'` and `'descending'` outputs.\n * When padding inactive `f32` lanes with a `NaN` or `±Infinity` sentinel, mask the bit pattern with\n * a runtime input such as `bitcast<f32>(0x7fc00000u | (invocation.local_invocation_index & 0u))`\n * (`0xff800000u` for `-Infinity`, `0x7f800000u` for `+Infinity`), because Tint rejects\n * const-expression `NaN` and `Infinity` bitcasts. Attaches a `linear: true` `subgroups` variant\n * running all strides `< subgroup_size` in registers through `subgroupShuffleXor` (`0` barriers\n * when `subgroup_size >= width`). Thrown with code `ARGUMENT` for malformed options, an invalid\n * `name`, or `width > workgroup`.\n *\n * @param input - The sort's workgroup count, optional partition width, direction, element type, and optional name\n * @returns The frozen sort fragment\n *\n * @example\n * ```ts\n * createWGSLSort({ workgroup: 128, order: 'ascending', element: 'u32' }).name // 'sortAscendingU32128'\n * ```\n */\nexport function createWGSLSort(input: WGSLSortInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t\twidth: optionalOption(literalOf(WGSL_REDUCE_WIDTHS)),\n\t\t\torder: requiredOption(literalOf(WGSL_SORT_ORDERS)),\n\t\t\telement: requiredOption(literalOf(WGSL_SCALARS)),\n\t\t} satisfies OptionFieldsFor<WGSLSortInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLSort')\n\t\t\t\treturn new WGSLError(`The sort options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name, workgroup, width }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A sort fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tif (width !== undefined && width > workgroup) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A sort partition width (${width}) must not exceed its workgroup (${workgroup}).`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { workgroup, width } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup, width, order, element } = resolved\n\tconst effectiveWidth = width ?? workgroup\n\tconst partitioned = effectiveWidth < workgroup\n\tconst orderTag = order === 'ascending' ? 'Ascending' : 'Descending'\n\tconst stem =\n\t\tname ??\n\t\t(partitioned\n\t\t\t? `sort${orderTag}${element.toUpperCase()}${workgroup}Width${effectiveWidth}`\n\t\t\t: `sort${orderTag}${element.toUpperCase()}${workgroup}`)\n\tconst sharedType = element === 'f32' ? 'u32' : element\n\tconst laneExpr = partitioned ? 'lane' : 'local'\n\tconst wantAscending =\n\t\torder === 'ascending' ? `(${laneExpr} & size) == 0u` : `(${laneExpr} & size) != 0u`\n\tconst encodeLines =\n\t\telement === 'f32'\n\t\t\t? order === 'ascending'\n\t\t\t\t? ['\\tlet encoded = encodeFloatOrder(value);']\n\t\t\t\t: [\n\t\t\t\t\t\t'\\tlet rawKey = encodeFloatOrder(value);',\n\t\t\t\t\t\t'\\tlet encoded = select(rawKey, 0x003fffffu, rawKey == 0xffc00000u);',\n\t\t\t\t\t]\n\t\t\t: []\n\tconst initialKey = element === 'f32' ? 'encoded' : 'value'\n\tconst decodeSorted =\n\t\telement === 'f32'\n\t\t\t? order === 'ascending'\n\t\t\t\t? 'decodeFloatOrder(sorted)'\n\t\t\t\t: 'decodeFloatOrder(select(sorted, 0xffc00000u, sorted == 0x003fffffu))'\n\t\t\t: 'sorted'\n\tconst decodeCur =\n\t\telement === 'f32'\n\t\t\t? order === 'ascending'\n\t\t\t\t? 'decodeFloatOrder(cur)'\n\t\t\t\t: 'decodeFloatOrder(select(cur, 0xffc00000u, cur == 0x003fffffu))'\n\t\t\t: 'cur'\n\tconst source = [\n\t\t`var<workgroup> ${stem}Shared: array<${sharedType}, ${workgroup}>;`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}) -> ${element} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t...(partitioned ? [`\\tlet lane = local & ${effectiveWidth - 1}u;`] : []),\n\t\t...encodeLines,\n\t\t`\\t${stem}Shared[local] = ${initialKey};`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tfor (var size = 2u; size <= ${effectiveWidth}u; size = size << 1u) {`,\n\t\t`\\t\\tlet dir = ${wantAscending};`,\n\t\t'\\t\\tfor (var stride = size >> 1u; stride > 0u; stride = stride >> 1u) {',\n\t\t'\\t\\t\\tlet partner = local ^ stride;',\n\t\t'\\t\\t\\tif (partner > local) {',\n\t\t`\\t\\t\\t\\tlet left = ${stem}Shared[local];`,\n\t\t`\\t\\t\\t\\tlet right = ${stem}Shared[partner];`,\n\t\t'\\t\\t\\t\\tlet swap = select((left < right), (left > right), dir);',\n\t\t`\\t\\t\\t\\t${stem}Shared[local] = select(left, right, swap);`,\n\t\t`\\t\\t\\t\\t${stem}Shared[partner] = select(right, left, swap);`,\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t\\tworkgroupBarrier();',\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t`\\tlet sorted = ${stem}Shared[local];`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\treturn ${decodeSorted};`,\n\t\t'}',\n\t].join('\\n')\n\tconst variantSource = [\n\t\t`var<workgroup> ${stem}Shared: array<${sharedType}, ${workgroup}>;`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}) -> ${element} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t...(partitioned ? [`\\tlet lane = local & ${effectiveWidth - 1}u;`] : []),\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t...encodeLines,\n\t\t`\\tvar cur = ${initialKey};`,\n\t\t`\\tif (sgSize >= ${effectiveWidth}u) {`,\n\t\t`\\t\\tfor (var size = 2u; size <= ${effectiveWidth}u; size = size << 1u) {`,\n\t\t`\\t\\t\\tlet dir = ${wantAscending};`,\n\t\t'\\t\\t\\tfor (var stride = size >> 1u; stride > 0u; stride = stride >> 1u) {',\n\t\t'\\t\\t\\t\\tlet other = subgroupShuffleXor(cur, stride);',\n\t\t'\\t\\t\\t\\tlet isUpper = (local & stride) != 0u;',\n\t\t'\\t\\t\\t\\tlet wantMax = dir == isUpper;',\n\t\t'\\t\\t\\t\\tlet takeOther = select((other < cur), (other > cur), wantMax);',\n\t\t'\\t\\t\\t\\tcur = select(cur, other, takeOther);',\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t}',\n\t\t`\\t\\treturn ${decodeCur};`,\n\t\t'\\t}',\n\t\t`\\tfor (var size = 2u; size <= ${effectiveWidth}u; size = size << 1u) {`,\n\t\t`\\t\\tlet dir = ${wantAscending};`,\n\t\t'\\t\\tvar stride = size >> 1u;',\n\t\t'\\t\\tif (stride >= sgSize) {',\n\t\t`\\t\\t\\t${stem}Shared[local] = cur;`,\n\t\t'\\t\\t\\tworkgroupBarrier();',\n\t\t'\\t\\t\\tfor (; stride >= sgSize; stride = stride >> 1u) {',\n\t\t'\\t\\t\\t\\tlet partner = local ^ stride;',\n\t\t'\\t\\t\\t\\tif (partner > local) {',\n\t\t`\\t\\t\\t\\t\\tlet left = ${stem}Shared[local];`,\n\t\t`\\t\\t\\t\\t\\tlet right = ${stem}Shared[partner];`,\n\t\t'\\t\\t\\t\\t\\tlet swap = select((left < right), (left > right), dir);',\n\t\t`\\t\\t\\t\\t\\t${stem}Shared[local] = select(left, right, swap);`,\n\t\t`\\t\\t\\t\\t\\t${stem}Shared[partner] = select(right, left, swap);`,\n\t\t'\\t\\t\\t\\t}',\n\t\t'\\t\\t\\t\\tworkgroupBarrier();',\n\t\t'\\t\\t\\t}',\n\t\t`\\t\\t\\tcur = ${stem}Shared[local];`,\n\t\t'\\t\\t}',\n\t\t'\\t\\tfor (; stride > 0u; stride = stride >> 1u) {',\n\t\t'\\t\\t\\tlet other = subgroupShuffleXor(cur, stride);',\n\t\t'\\t\\t\\tlet isUpper = (local & stride) != 0u;',\n\t\t'\\t\\t\\tlet wantMax = dir == isUpper;',\n\t\t'\\t\\t\\tlet takeOther = select((other < cur), (other > cur), wantMax);',\n\t\t'\\t\\t\\tcur = select(cur, other, takeOther);',\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\treturn ${decodeCur};`,\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({\n\t\tname: stem,\n\t\tsource,\n\t\tuses: element === 'f32' ? [WGSL_ORDER] : [],\n\t\tvariants: [{ extensions: ['subgroups'], linear: true, source: variantSource }],\n\t\tworkgroup,\n\t})\n}\n\n/**\n * Creates a frozen workgroup or partitioned key-index pair sort fragment with deterministic ascending-index tie-breaking.\n *\n * @remarks\n * Declares `struct {Stem}Result { value: {element}, index: u32 }`, one workgroup scratch variable\n * `{stem}Shared`, and\n * `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}, index: u32) -> {Stem}Result`.\n * `width` defaults to `workgroup` and must not exceed `workgroup`; when `width < workgroup`, each\n * contiguous `width`-lane partition sorts independently using `lane = local & (width - 1)`. Equal\n * keys always break ties by ascending `u32` index in both `'ascending'` and `'descending'` orders.\n * For `'f32'`, links `WGSL_ORDER`, treats `-0.0` and `+0.0` as equal keys while preserving each\n * element's original bits in `result.value`, and places `NaN` at the end in both orders. When\n * padding inactive `f32` lanes with a `NaN` or `±Infinity` sentinel, mask the bit pattern with a\n * runtime input such as `bitcast<f32>(0x7fc00000u | (invocation.local_invocation_index & 0u))`\n * (`0xff800000u` for `-Infinity`, `0x7f800000u` for `+Infinity`), because Tint rejects\n * const-expression `NaN` and `Infinity` bitcasts. Attaches a `linear: true` `subgroups` variant\n * running strides `< subgroup_size` in registers through `subgroupShuffleXor` (`0` barriers when\n * `subgroup_size >= width`). Thrown with code `ARGUMENT` for malformed options, an invalid `name`,\n * or `width > workgroup`.\n *\n * @param input - The pair sort's workgroup count, optional partition width, direction, key element type, and optional name\n * @returns The frozen key-index pair sort fragment\n *\n * @example\n * ```ts\n * createWGSLPairSort({ workgroup: 128, order: 'descending', element: 'f32' }).name // 'pairSortDescendingF32128'\n * ```\n */\nexport function createWGSLPairSort(input: WGSLPairSortInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t\twidth: optionalOption(literalOf(WGSL_REDUCE_WIDTHS)),\n\t\t\torder: requiredOption(literalOf(WGSL_SORT_ORDERS)),\n\t\t\telement: requiredOption(literalOf(WGSL_SCALARS)),\n\t\t} satisfies OptionFieldsFor<WGSLPairSortInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLPairSort')\n\t\t\t\treturn new WGSLError(`The pair sort options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name, workgroup, width }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A pair sort fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tif (width !== undefined && width > workgroup) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A pair sort partition width (${width}) must not exceed its workgroup (${workgroup}).`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { workgroup, width } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup, width, order, element } = resolved\n\tconst effectiveWidth = width ?? workgroup\n\tconst partitioned = effectiveWidth < workgroup\n\tconst orderTag = order === 'ascending' ? 'Ascending' : 'Descending'\n\tconst stem =\n\t\tname ??\n\t\t(partitioned\n\t\t\t? `pairSort${orderTag}${element.toUpperCase()}${workgroup}Width${effectiveWidth}`\n\t\t\t: `pairSort${orderTag}${element.toUpperCase()}${workgroup}`)\n\tconst pascal = `${stem.slice(0, 1).toUpperCase()}${stem.slice(1)}`\n\tconst resultType = `${pascal}Result`\n\tconst scratchType = `${pascal}Scratch`\n\tconst isFloat = element === 'f32'\n\tconst laneExpr = partitioned ? 'lane' : 'local'\n\tconst beforeOp = order === 'ascending' ? '<' : '>'\n\tconst afterOp = order === 'ascending' ? '>' : '<'\n\tconst encodeLines = isFloat\n\t\t? order === 'ascending'\n\t\t\t? [\n\t\t\t\t\t'\\tlet rawBits = bitcast<u32>(value);',\n\t\t\t\t\t'\\tlet canonVal = select(value, 0.0, (rawBits & 0x7fffffffu) == 0u);',\n\t\t\t\t\t'\\tlet encoded = encodeFloatOrder(canonVal);',\n\t\t\t\t]\n\t\t\t: [\n\t\t\t\t\t'\\tlet rawBits = bitcast<u32>(value);',\n\t\t\t\t\t'\\tlet canonVal = select(value, 0.0, (rawBits & 0x7fffffffu) == 0u);',\n\t\t\t\t\t'\\tlet baseKey = encodeFloatOrder(canonVal);',\n\t\t\t\t\t'\\tlet encoded = select(baseKey, 0u, baseKey == 0xffc00000u);',\n\t\t\t\t]\n\t\t: []\n\tconst scratchFields = isFloat\n\t\t? [\n\t\t\t\t`\\tkeys: array<u32, ${workgroup}>,`,\n\t\t\t\t`\\tindices: array<u32, ${workgroup}>,`,\n\t\t\t\t`\\tvalues: array<f32, ${workgroup}>,`,\n\t\t\t]\n\t\t: [`\\tvalues: array<${element}, ${workgroup}>,`, `\\tindices: array<u32, ${workgroup}>,`]\n\tconst ldsLoadSwap = isFloat\n\t\t? [\n\t\t\t\t`\\t\\t\\t\\tlet lk = ${stem}Shared.keys[local];`,\n\t\t\t\t`\\t\\t\\t\\tlet rk = ${stem}Shared.keys[partner];`,\n\t\t\t\t`\\t\\t\\t\\tlet li = ${stem}Shared.indices[local];`,\n\t\t\t\t`\\t\\t\\t\\tlet ri = ${stem}Shared.indices[partner];`,\n\t\t\t\t`\\t\\t\\t\\tlet lv = ${stem}Shared.values[local];`,\n\t\t\t\t`\\t\\t\\t\\tlet rv = ${stem}Shared.values[partner];`,\n\t\t\t\t`\\t\\t\\t\\tlet leftBefore = (lk ${beforeOp} rk) || (lk == rk && li < ri);`,\n\t\t\t\t`\\t\\t\\t\\tlet leftAfter = (lk ${afterOp} rk) || (lk == rk && li > ri);`,\n\t\t\t\t'\\t\\t\\t\\tlet swap = select(leftBefore, leftAfter, forward);',\n\t\t\t\t`\\t\\t\\t\\t${stem}Shared.keys[local] = select(lk, rk, swap);`,\n\t\t\t\t`\\t\\t\\t\\t${stem}Shared.keys[partner] = select(rk, lk, swap);`,\n\t\t\t\t`\\t\\t\\t\\t${stem}Shared.indices[local] = select(li, ri, swap);`,\n\t\t\t\t`\\t\\t\\t\\t${stem}Shared.indices[partner] = select(ri, li, swap);`,\n\t\t\t\t`\\t\\t\\t\\t${stem}Shared.values[local] = select(lv, rv, swap);`,\n\t\t\t\t`\\t\\t\\t\\t${stem}Shared.values[partner] = select(rv, lv, swap);`,\n\t\t\t]\n\t\t: [\n\t\t\t\t`\\t\\t\\t\\tlet lk = ${stem}Shared.values[local];`,\n\t\t\t\t`\\t\\t\\t\\tlet rk = ${stem}Shared.values[partner];`,\n\t\t\t\t`\\t\\t\\t\\tlet li = ${stem}Shared.indices[local];`,\n\t\t\t\t`\\t\\t\\t\\tlet ri = ${stem}Shared.indices[partner];`,\n\t\t\t\t`\\t\\t\\t\\tlet leftBefore = (lk ${beforeOp} rk) || (lk == rk && li < ri);`,\n\t\t\t\t`\\t\\t\\t\\tlet leftAfter = (lk ${afterOp} rk) || (lk == rk && li > ri);`,\n\t\t\t\t'\\t\\t\\t\\tlet swap = select(leftBefore, leftAfter, forward);',\n\t\t\t\t`\\t\\t\\t\\t${stem}Shared.values[local] = select(lk, rk, swap);`,\n\t\t\t\t`\\t\\t\\t\\t${stem}Shared.values[partner] = select(rk, lk, swap);`,\n\t\t\t\t`\\t\\t\\t\\t${stem}Shared.indices[local] = select(li, ri, swap);`,\n\t\t\t\t`\\t\\t\\t\\t${stem}Shared.indices[partner] = select(ri, li, swap);`,\n\t\t\t]\n\tconst shuffleStepLines = [\n\t\t...(isFloat ? ['\\t\\t\\tlet ok = subgroupShuffleXor(curKey, stride);'] : []),\n\t\t'\\t\\t\\tlet ov = subgroupShuffleXor(curVal, stride);',\n\t\t'\\t\\t\\tlet oi = subgroupShuffleXor(curIdx, stride);',\n\t\t'\\t\\t\\tlet isUpper = (local & stride) != 0u;',\n\t\t'\\t\\t\\tlet wantAfter = forward == isUpper;',\n\t\t...(isFloat\n\t\t\t? [\n\t\t\t\t\t`\\t\\t\\tlet otherBefore = (ok ${beforeOp} curKey) || (ok == curKey && oi < curIdx);`,\n\t\t\t\t\t`\\t\\t\\tlet otherAfter = (ok ${afterOp} curKey) || (ok == curKey && oi > curIdx);`,\n\t\t\t\t\t'\\t\\t\\tlet takeOther = select(otherBefore, otherAfter, wantAfter);',\n\t\t\t\t\t'\\t\\t\\tcurKey = select(curKey, ok, takeOther);',\n\t\t\t\t]\n\t\t\t: [\n\t\t\t\t\t`\\t\\t\\tlet otherBefore = (ov ${beforeOp} curVal) || (ov == curVal && oi < curIdx);`,\n\t\t\t\t\t`\\t\\t\\tlet otherAfter = (ov ${afterOp} curVal) || (ov == curVal && oi > curIdx);`,\n\t\t\t\t\t'\\t\\t\\tlet takeOther = select(otherBefore, otherAfter, wantAfter);',\n\t\t\t\t]),\n\t\t'\\t\\t\\tcurVal = select(curVal, ov, takeOther);',\n\t\t'\\t\\t\\tcurIdx = select(curIdx, oi, takeOther);',\n\t]\n\tconst source = [\n\t\t`struct ${resultType} {`,\n\t\t`\\tvalue: ${element},`,\n\t\t'\\tindex: u32,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t...scratchFields,\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}, index: u32) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t...(partitioned ? [`\\tlet lane = local & ${effectiveWidth - 1}u;`] : []),\n\t\t...encodeLines,\n\t\t...(isFloat ? [`\\t${stem}Shared.keys[local] = encoded;`] : []),\n\t\t`\\t${stem}Shared.values[local] = value;`,\n\t\t`\\t${stem}Shared.indices[local] = index;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tfor (var size = 2u; size <= ${effectiveWidth}u; size = size << 1u) {`,\n\t\t`\\t\\tlet forward = (${laneExpr} & size) == 0u;`,\n\t\t'\\t\\tfor (var stride = size >> 1u; stride > 0u; stride = stride >> 1u) {',\n\t\t'\\t\\t\\tlet partner = local ^ stride;',\n\t\t'\\t\\t\\tif (partner > local) {',\n\t\t...ldsLoadSwap,\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t\\tworkgroupBarrier();',\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t`\\tlet result = ${resultType}(${stem}Shared.values[local], ${stem}Shared.indices[local]);`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn result;',\n\t\t'}',\n\t].join('\\n')\n\tconst variantLdsSwap = ldsLoadSwap.map((line) => `\\t${line}`)\n\tconst fastShuffleLines = shuffleStepLines.map((line) => `\\t${line}`)\n\tconst variantSource = [\n\t\t`struct ${resultType} {`,\n\t\t`\\tvalue: ${element},`,\n\t\t'\\tindex: u32,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t...scratchFields,\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}, index: u32) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t...(partitioned ? [`\\tlet lane = local & ${effectiveWidth - 1}u;`] : []),\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t...encodeLines,\n\t\t...(isFloat ? ['\\tvar curKey = encoded;'] : []),\n\t\t'\\tvar curVal = value;',\n\t\t'\\tvar curIdx = index;',\n\t\t`\\tif (sgSize >= ${effectiveWidth}u) {`,\n\t\t`\\t\\tfor (var size = 2u; size <= ${effectiveWidth}u; size = size << 1u) {`,\n\t\t`\\t\\t\\tlet forward = (${laneExpr} & size) == 0u;`,\n\t\t'\\t\\t\\tfor (var stride = size >> 1u; stride > 0u; stride = stride >> 1u) {',\n\t\t...fastShuffleLines,\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t}',\n\t\t`\\t\\treturn ${resultType}(curVal, curIdx);`,\n\t\t'\\t}',\n\t\t`\\tfor (var size = 2u; size <= ${effectiveWidth}u; size = size << 1u) {`,\n\t\t`\\t\\tlet forward = (${laneExpr} & size) == 0u;`,\n\t\t'\\t\\tvar stride = size >> 1u;',\n\t\t'\\t\\tif (stride >= sgSize) {',\n\t\t...(isFloat ? [`\\t\\t\\t${stem}Shared.keys[local] = curKey;`] : []),\n\t\t`\\t\\t\\t${stem}Shared.values[local] = curVal;`,\n\t\t`\\t\\t\\t${stem}Shared.indices[local] = curIdx;`,\n\t\t'\\t\\t\\tworkgroupBarrier();',\n\t\t'\\t\\t\\tfor (; stride >= sgSize; stride = stride >> 1u) {',\n\t\t'\\t\\t\\t\\tlet partner = local ^ stride;',\n\t\t'\\t\\t\\t\\tif (partner > local) {',\n\t\t...variantLdsSwap,\n\t\t'\\t\\t\\t\\t}',\n\t\t'\\t\\t\\t\\tworkgroupBarrier();',\n\t\t'\\t\\t\\t}',\n\t\t...(isFloat ? [`\\t\\t\\tcurKey = ${stem}Shared.keys[local];`] : []),\n\t\t`\\t\\t\\tcurVal = ${stem}Shared.values[local];`,\n\t\t`\\t\\t\\tcurIdx = ${stem}Shared.indices[local];`,\n\t\t'\\t\\t}',\n\t\t'\\t\\tfor (; stride > 0u; stride = stride >> 1u) {',\n\t\t...shuffleStepLines,\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\treturn ${resultType}(curVal, curIdx);`,\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({\n\t\tname: stem,\n\t\tsource,\n\t\tuses: isFloat ? [WGSL_ORDER] : [],\n\t\tvariants: [{ extensions: ['subgroups'], linear: true, source: variantSource }],\n\t\tworkgroup,\n\t})\n}\n\n/**\n * Creates a frozen workgroup or partitioned online monoid reduction fragment for `exp`, `moments`, or `compensated`.\n *\n * @remarks\n * Links `WGSL_MATH` (`OnlineExp` / `mergeOnlineExp`), `WGSL_WELFORD` (`OnlineMoments` /\n * `mergeOnlineMoments`), or `WGSL_COMPENSATED` (`CompensatedSum` / `mergeCompensatedSum`), declares\n * `var<workgroup> {stem}Shared`, and exposes\n * `fn {stem}(invocation: Invocation, dispatch: Dispatch, state: {State}) -> {State}`. Attaches a\n * `linear: true` `subgroups` variant running an exact `0`-ULP top-down `subgroupShuffleXor`\n * butterfly over the state's scalar fields (`0` barriers when `subgroup_size >= width`). Thrown\n * with code `ARGUMENT` for malformed options, an invalid `name`, or `width > workgroup`.\n *\n * @param input - The monoid reduction's workgroup count, optional partition width, monoid kind, and optional name\n * @returns The frozen monoid reduction fragment\n *\n * @example\n * ```ts\n * createWGSLMonoidReduce({ workgroup: 64, monoid: 'exp' }).name // 'monoidReduceExp64'\n * ```\n */\nexport function createWGSLMonoidReduce(input: WGSLMonoidReduceInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t\twidth: optionalOption(literalOf(WGSL_REDUCE_WIDTHS)),\n\t\t\tmonoid: requiredOption(literalOf(WGSL_MONOIDS)),\n\t\t} satisfies OptionFieldsFor<WGSLMonoidReduceInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLMonoidReduce')\n\t\t\t\treturn new WGSLError(`The monoid reduction options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name, workgroup, width }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A monoid reduction fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tif (width !== undefined && width > workgroup) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A monoid reduction partition width (${width}) must not exceed its workgroup (${workgroup}).`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { workgroup, width } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup, width, monoid } = resolved\n\tconst effectiveWidth = width ?? workgroup\n\tconst half = effectiveWidth >> 1\n\tconst widthLog2 = Math.log2(effectiveWidth)\n\tconst partitioned = effectiveWidth < workgroup\n\tconst monoidTag = monoid === 'exp' ? 'Exp' : monoid === 'moments' ? 'Moments' : 'Compensated'\n\tconst stem =\n\t\tname ??\n\t\t(partitioned\n\t\t\t? `monoidReduce${monoidTag}${workgroup}Width${effectiveWidth}`\n\t\t\t: `monoidReduce${monoidTag}${workgroup}`)\n\tconst dependency =\n\t\tmonoid === 'exp' ? WGSL_MATH : monoid === 'moments' ? WGSL_WELFORD : WGSL_COMPENSATED\n\tconst stateType =\n\t\tmonoid === 'exp' ? 'OnlineExp' : monoid === 'moments' ? 'OnlineMoments' : 'CompensatedSum'\n\tconst mergeFn =\n\t\tmonoid === 'exp'\n\t\t\t? 'mergeOnlineExp'\n\t\t\t: monoid === 'moments'\n\t\t\t\t? 'mergeOnlineMoments'\n\t\t\t\t: 'mergeCompensatedSum'\n\tconst shuffleOther =\n\t\tmonoid === 'exp'\n\t\t\t? 'OnlineExp(subgroupShuffleXor(acc.peak, stride), subgroupShuffleXor(acc.mass, stride))'\n\t\t\t: monoid === 'moments'\n\t\t\t\t? 'OnlineMoments(subgroupShuffleXor(acc.count, stride), subgroupShuffleXor(acc.mean, stride), subgroupShuffleXor(acc.square, stride))'\n\t\t\t\t: 'CompensatedSum(subgroupShuffleXor(acc.sum, stride), subgroupShuffleXor(acc.error, stride))'\n\tconst laneExpr = partitioned ? 'lane' : 'local'\n\tconst rowIndex = partitioned ? 'rowBase + lane' : 'local'\n\tconst rowZero = partitioned ? 'rowBase' : '0u'\n\tconst source = [\n\t\t`var<workgroup> ${stem}Shared: array<${stateType}, ${workgroup}>;`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, state: ${stateType}) -> ${stateType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t...(partitioned\n\t\t\t? [`\\tlet lane = local & ${effectiveWidth - 1}u;`, '\\tlet base = local - lane;']\n\t\t\t: []),\n\t\t`\\t${stem}Shared[local] = state;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tfor (var stride = ${half}u; stride > 0u; stride = stride >> 1u) {`,\n\t\t`\\t\\tif (${laneExpr} < stride) {`,\n\t\t`\\t\\t\\tlet left = ${stem}Shared[local];`,\n\t\t`\\t\\t\\tlet right = ${stem}Shared[local + stride];`,\n\t\t`\\t\\t\\t${stem}Shared[local] = ${mergeFn}(left, right);`,\n\t\t'\\t\\t}',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t'\\t}',\n\t\t`\\tlet total = ${stem}Shared[${partitioned ? 'base' : '0u'}];`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn total;',\n\t\t'}',\n\t].join('\\n')\n\tconst variantSource = [\n\t\t`var<workgroup> ${stem}Shared: array<${stateType}, ${workgroup >> 1}>;`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, state: ${stateType}) -> ${stateType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t`\\tif (sgSize >= ${effectiveWidth}u) {`,\n\t\t'\\t\\tvar acc = state;',\n\t\t`\\t\\tfor (var stride = ${half}u; stride > 0u; stride = stride >> 1u) {`,\n\t\t`\\t\\t\\tlet other = ${shuffleOther};`,\n\t\t'\\t\\t\\tif ((local & stride) == 0u) {',\n\t\t`\\t\\t\\t\\tacc = ${mergeFn}(acc, other);`,\n\t\t'\\t\\t\\t} else {',\n\t\t`\\t\\t\\t\\tacc = ${mergeFn}(other, acc);`,\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t}',\n\t\t'\\t\\treturn acc;',\n\t\t'\\t}',\n\t\t...(partitioned\n\t\t\t? [\n\t\t\t\t\t`\\tlet lane = local & ${effectiveWidth - 1}u;`,\n\t\t\t\t\t`\\tlet rowBase = (local >> ${widthLog2}u) * ${half}u;`,\n\t\t\t\t]\n\t\t\t: []),\n\t\t`\\tif (${laneExpr} >= ${half}u) {`,\n\t\t`\\t\\t${stem}Shared[${rowIndex} - ${half}u] = state;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tvar acc = state;',\n\t\t`\\tif (${laneExpr} < ${half}u) {`,\n\t\t`\\t\\tlet right = ${stem}Shared[${rowIndex}];`,\n\t\t`\\t\\tacc = ${mergeFn}(acc, right);`,\n\t\t`\\t\\tif (${half}u > sgSize) {`,\n\t\t`\\t\\t\\t${stem}Shared[${rowIndex}] = acc;`,\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t`\\tif (${half}u > sgSize) {`,\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t`\\t\\tfor (var stride = ${half >> 1}u; stride >= sgSize; stride = stride >> 1u) {`,\n\t\t`\\t\\t\\tif (${laneExpr} < stride) {`,\n\t\t`\\t\\t\\t\\tlet left = ${stem}Shared[${rowIndex}];`,\n\t\t`\\t\\t\\t\\tlet right = ${stem}Shared[${rowIndex} + stride];`,\n\t\t`\\t\\t\\t\\t${stem}Shared[${rowIndex}] = ${mergeFn}(left, right);`,\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t\\tworkgroupBarrier();',\n\t\t'\\t\\t}',\n\t\t`\\t\\tif (${laneExpr} < sgSize) {`,\n\t\t`\\t\\t\\tacc = ${stem}Shared[${rowIndex}];`,\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t'\\tfor (var stride = sgSize >> 1u; stride > 0u; stride = stride >> 1u) {',\n\t\t`\\t\\tlet other = ${shuffleOther};`,\n\t\t'\\t\\tif ((local & stride) == 0u) {',\n\t\t`\\t\\t\\tacc = ${mergeFn}(acc, other);`,\n\t\t'\\t\\t} else {',\n\t\t`\\t\\t\\tacc = ${mergeFn}(other, acc);`,\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t`\\tif (${laneExpr} == 0u) {`,\n\t\t`\\t\\t${stem}Shared[${rowZero}] = acc;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tlet total = ${stem}Shared[${rowZero}];`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn total;',\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({\n\t\tname: stem,\n\t\tsource,\n\t\tuses: [dependency],\n\t\tvariants: [{ extensions: ['subgroups'], linear: true, source: variantSource }],\n\t\tworkgroup,\n\t})\n}\n\n/**\n * Creates a frozen shared-memory tile transpose fragment linking `WGSL_TILE`.\n *\n * @remarks\n * Always sets `workgroup: 256` and takes `(invocation: Invocation, dispatch: Dispatch, ...)`:\n * `tile: 16` uses `swizzleTileIndex` over a 256-element shared array (1 element per invocation),\n * while `tile: 32` uses `computeTileIndex` over a 1056-element padded shared array (`vec4<{element}>`\n * carrying 4 rows per invocation across 8 bands). Thrown with code `ARGUMENT` for malformed options\n * or an invalid `name`.\n *\n * @param input - The transpose's tile side length (`16 | 32`), element type, and optional name\n * @returns The frozen tile transpose fragment, linking `WGSL_TILE`\n *\n * @example\n * ```ts\n * createWGSLTranspose({ tile: 32, element: 'f32' }).workgroup // 256\n * ```\n */\nexport function createWGSLTranspose(input: WGSLTransposeInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\ttile: requiredOption(literalOf(WGSL_TILE_SIZES)),\n\t\t\telement: requiredOption(literalOf(WGSL_SCALARS)),\n\t\t} satisfies OptionFieldsFor<WGSLTransposeInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLTranspose')\n\t\t\t\treturn new WGSLError(`The transpose options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A transpose fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, tile, element } = resolved\n\tconst stem = name ?? `transpose${element.toUpperCase()}${tile}`\n\tconst source =\n\t\ttile === 16\n\t\t\t? [\n\t\t\t\t\t`var<workgroup> ${stem}Shared: array<${element}, 256>;`,\n\t\t\t\t\t'',\n\t\t\t\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}) -> ${element} {`,\n\t\t\t\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t\t\t\t'\\tlet row = local >> 4u;',\n\t\t\t\t\t'\\tlet column = local & 15u;',\n\t\t\t\t\t`\\t${stem}Shared[swizzleTileIndex(row, column, 16u)] = value;`,\n\t\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t\t`\\tlet result = ${stem}Shared[swizzleTileIndex(column, row, 16u)];`,\n\t\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t\t'\\treturn result;',\n\t\t\t\t\t'}',\n\t\t\t\t].join('\\n')\n\t\t\t: [\n\t\t\t\t\t`var<workgroup> ${stem}Shared: array<${element}, 1056>;`,\n\t\t\t\t\t'',\n\t\t\t\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, values: vec4<${element}>) -> vec4<${element}> {`,\n\t\t\t\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t\t\t\t'\\tlet band = local >> 5u;',\n\t\t\t\t\t'\\tlet column = local & 31u;',\n\t\t\t\t\t`\\t${stem}Shared[computeTileIndex(band, column, 32u)] = values.x;`,\n\t\t\t\t\t`\\t${stem}Shared[computeTileIndex(band + 8u, column, 32u)] = values.y;`,\n\t\t\t\t\t`\\t${stem}Shared[computeTileIndex(band + 16u, column, 32u)] = values.z;`,\n\t\t\t\t\t`\\t${stem}Shared[computeTileIndex(band + 24u, column, 32u)] = values.w;`,\n\t\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t\t`\\tlet result = vec4<${element}>(`,\n\t\t\t\t\t`\\t\\t${stem}Shared[computeTileIndex(column, band, 32u)],`,\n\t\t\t\t\t`\\t\\t${stem}Shared[computeTileIndex(column, band + 8u, 32u)],`,\n\t\t\t\t\t`\\t\\t${stem}Shared[computeTileIndex(column, band + 16u, 32u)],`,\n\t\t\t\t\t`\\t\\t${stem}Shared[computeTileIndex(column, band + 24u, 32u)],`,\n\t\t\t\t\t'\\t);',\n\t\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t\t'\\treturn result;',\n\t\t\t\t\t'}',\n\t\t\t\t].join('\\n')\n\treturn createWGSLFragment({ name: stem, source, uses: [WGSL_TILE], workgroup: 256 })\n}\n\n/**\n * Creates a frozen workgroup stream-compaction fragment returning each lane's exclusive kept offset and workgroup-wide total.\n *\n * @remarks\n * Declares `struct {Stem}Result { offset: u32, total: u32 }`, one workgroup scratch variable\n * `{stem}Shared`, and `fn {stem}(invocation: Invocation, dispatch: Dispatch, keep: bool) -> {Stem}Result`.\n * `offset` holds the `0`-based count of preceding lanes with `keep == true`, and every lane\n * receives the same workgroup-wide `total` count of kept lanes (`sgCount` when `num_subgroups == 1`\n * on the 1D ballot path, `workgroupUniformLoad` otherwise). Because WGSL static uniformity analysis\n * taints a returned `struct` carrying per-lane `offset`, callers branching before a barrier must\n * reload `total` through `workgroupUniformLoad`, or pair with `WGSL_JOIN` or `createWGSLBroadcast`.\n * Attaches both a 1D `linear: true` direct `subgroupBallot` variant (`0` barriers when\n * `num_subgroups == 1`) and a 2D-safe remapped `subgroupBallot` variant requiring `subgroup_id`,\n * clamping every ballot mask to `activeSg = min(dispatch.subgroup_size, workgroup)` across\n * `subgroup_size <= 32` and `vec4u` paths. Thrown with code `ARGUMENT` for malformed options or an\n * invalid `name`.\n *\n * @param input - The compaction's workgroup count and optional name\n * @returns The frozen stream-compaction fragment\n *\n * @example\n * ```ts\n * createWGSLCompact({ workgroup: 256 }).name // 'compact256'\n * ```\n */\nexport function createWGSLCompact(input: WGSLCompactInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t} satisfies OptionFieldsFor<WGSLCompactInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLCompact')\n\t\t\t\treturn new WGSLError(`The compaction options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A compaction fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup } = resolved\n\tconst stem = name ?? `compact${workgroup}`\n\tconst pascal = `${stem.slice(0, 1).toUpperCase()}${stem.slice(1)}`\n\tconst resultType = `${pascal}Result`\n\tconst scratchType = `${pascal}Scratch`\n\tconst ballotCountLines = [\n\t\t'\\tvar sgCount = 0u;',\n\t\t'\\tvar sgRank = 0u;',\n\t\t'\\tif (sgSize <= 32u) {',\n\t\t'\\t\\tlet activeMask = 0xffffffffu >> ((32u - activeSg) & 31u);',\n\t\t'\\t\\tlet lowerMask = (1u << sgLane) - 1u;',\n\t\t'\\t\\tlet masked = ballot.x & activeMask;',\n\t\t'\\t\\tsgCount = countOneBits(masked);',\n\t\t'\\t\\tsgRank = countOneBits(masked & lowerMask);',\n\t\t'\\t} else {',\n\t\t'\\t\\tlet a0 = select(0u, 0xffffffffu >> ((32u - min(activeSg, 32u)) & 31u), activeSg > 0u);',\n\t\t'\\t\\tlet a1 = select(0u, 0xffffffffu >> ((32u - min(activeSg - 32u, 32u)) & 31u), activeSg > 32u);',\n\t\t'\\t\\tlet a2 = select(0u, 0xffffffffu >> ((32u - min(activeSg - 64u, 32u)) & 31u), activeSg > 64u);',\n\t\t'\\t\\tlet a3 = select(0u, 0xffffffffu >> ((32u - min(activeSg - 96u, 32u)) & 31u), activeSg > 96u);',\n\t\t'\\t\\tlet l0 = select(0u, 0xffffffffu >> ((32u - min(sgLane, 32u)) & 31u), sgLane > 0u);',\n\t\t'\\t\\tlet l1 = select(0u, 0xffffffffu >> ((32u - min(sgLane - 32u, 32u)) & 31u), sgLane > 32u);',\n\t\t'\\t\\tlet l2 = select(0u, 0xffffffffu >> ((32u - min(sgLane - 64u, 32u)) & 31u), sgLane > 64u);',\n\t\t'\\t\\tlet l3 = select(0u, 0xffffffffu >> ((32u - min(sgLane - 96u, 32u)) & 31u), sgLane > 96u);',\n\t\t'\\t\\tlet masked = ballot & vec4u(a0, a1, a2, a3);',\n\t\t'\\t\\tlet cVec = countOneBits(masked);',\n\t\t'\\t\\tsgCount = cVec.x + cVec.y + cVec.z + cVec.w;',\n\t\t'\\t\\tlet rVec = countOneBits(masked & vec4u(l0, l1, l2, l3));',\n\t\t'\\t\\tsgRank = rVec.x + rVec.y + rVec.z + rVec.w;',\n\t\t'\\t}',\n\t]\n\tconst spineScanLines = [\n\t\t'\\tif (numSg <= sgSize) {',\n\t\t'\\t\\tlet isLive = sgId == 0u && sgLane < numSg;',\n\t\t`\\t\\tlet sgVal = select(0u, ${stem}Shared.counts[select(0u, sgLane, isLive)], isLive);`,\n\t\t'\\t\\tlet sgBase = subgroupExclusiveAdd(sgVal);',\n\t\t'\\t\\tif (isLive) {',\n\t\t`\\t\\t\\t${stem}Shared.counts[sgLane] = sgBase;`,\n\t\t'\\t\\t}',\n\t\t'\\t\\tif (sgId == 0u && sgLane == numSg - 1u) {',\n\t\t`\\t\\t\\t${stem}Shared.total = sgBase + sgVal;`,\n\t\t'\\t\\t}',\n\t\t'\\t} else {',\n\t\t'\\t\\tif (local == 0u) {',\n\t\t'\\t\\t\\tvar carry = 0u;',\n\t\t'\\t\\t\\tfor (var i = 0u; i < numSg; i += 1u) {',\n\t\t`\\t\\t\\t\\tlet current = ${stem}Shared.counts[i];`,\n\t\t`\\t\\t\\t\\t${stem}Shared.counts[i] = carry;`,\n\t\t'\\t\\t\\t\\tcarry += current;',\n\t\t'\\t\\t\\t}',\n\t\t`\\t\\t\\t${stem}Shared.total = carry;`,\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t]\n\tconst source = [\n\t\t`struct ${resultType} {`,\n\t\t'\\toffset: u32,',\n\t\t'\\ttotal: u32,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t`\\tcounts: array<u32, ${workgroup}>,`,\n\t\t'\\ttotal: u32,',\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, keep: bool) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet flag = select(0u, 1u, keep);',\n\t\t`\\t${stem}Shared.counts[local] = select(flag, 0u, local == ${workgroup - 1}u);`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tfor (var span = 1u; span < ${workgroup >> 1}u; span = span << 1u) {`,\n\t\t'\\t\\tlet stride = span << 1u;',\n\t\t`\\t\\tif (local < ${workgroup - 1}u && ((local + 1u) & (stride - 1u)) == 0u) {`,\n\t\t`\\t\\t\\t${stem}Shared.counts[local] = ${stem}Shared.counts[local - span] + ${stem}Shared.counts[local];`,\n\t\t'\\t\\t}',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t'\\t}',\n\t\t`\\tfor (var span = ${workgroup >> 1}u; span > 0u; span = span >> 1u) {`,\n\t\t'\\t\\tlet stride = span << 1u;',\n\t\t'\\t\\tif (((local + 1u) & (stride - 1u)) == 0u) {',\n\t\t`\\t\\t\\tlet prior = ${stem}Shared.counts[local - span];`,\n\t\t`\\t\\t\\tlet carried = ${stem}Shared.counts[local];`,\n\t\t`\\t\\t\\t${stem}Shared.counts[local - span] = carried;`,\n\t\t`\\t\\t\\t${stem}Shared.counts[local] = carried + prior;`,\n\t\t'\\t\\t}',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t'\\t}',\n\t\t`\\tlet offset = ${stem}Shared.counts[local];`,\n\t\t`\\tif (local == ${workgroup - 1}u) {`,\n\t\t`\\t\\t${stem}Shared.total = offset + flag;`,\n\t\t'\\t}',\n\t\t`\\tlet total = workgroupUniformLoad(&${stem}Shared.total);`,\n\t\t`\\treturn ${resultType}(offset, total);`,\n\t\t'}',\n\t].join('\\n')\n\tconst directSource = [\n\t\t`struct ${resultType} {`,\n\t\t'\\toffset: u32,',\n\t\t'\\ttotal: u32,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t`\\tcounts: array<u32, ${workgroup >> 2}>,`,\n\t\t'\\ttotal: u32,',\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, keep: bool) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet sgId = invocation.subgroup_id;',\n\t\t'\\tlet sgLane = invocation.subgroup_invocation_id;',\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t'\\tlet numSg = dispatch.num_subgroups;',\n\t\t`\\tlet activeSg = min(sgSize, ${workgroup}u);`,\n\t\t'\\tlet ballot = subgroupBallot(keep);',\n\t\t...ballotCountLines,\n\t\t'\\tif (numSg == 1u) {',\n\t\t`\\t\\treturn ${resultType}(sgRank, sgCount);`,\n\t\t'\\t}',\n\t\t'\\tif (sgLane == 0u) {',\n\t\t`\\t\\t${stem}Shared.counts[sgId] = sgCount;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t...spineScanLines,\n\t\t`\\tlet total = workgroupUniformLoad(&${stem}Shared.total);`,\n\t\t`\\tlet offset = ${stem}Shared.counts[sgId] + sgRank;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\treturn ${resultType}(offset, total);`,\n\t\t'}',\n\t].join('\\n')\n\tconst remappedSource = [\n\t\t`struct ${resultType} {`,\n\t\t'\\toffset: u32,',\n\t\t'\\ttotal: u32,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t`\\tflags: array<u32, ${workgroup}>,`,\n\t\t`\\tcounts: array<u32, ${workgroup >> 2}>,`,\n\t\t'\\ttotal: u32,',\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, keep: bool) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet sgId = invocation.subgroup_id;',\n\t\t'\\tlet sgLane = invocation.subgroup_invocation_id;',\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t'\\tlet numSg = dispatch.num_subgroups;',\n\t\t`\\tlet activeSg = min(sgSize, ${workgroup}u);`,\n\t\t`\\t${stem}Shared.flags[local] = select(0u, 1u, keep);`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tlet lin = sgId * sgSize + sgLane;',\n\t\t`\\tlet sgKeep = ${stem}Shared.flags[lin] != 0u;`,\n\t\t'\\tlet ballot = subgroupBallot(sgKeep);',\n\t\t...ballotCountLines,\n\t\t'\\tif (numSg == 1u) {',\n\t\t`\\t\\t${stem}Shared.flags[lin] = sgRank;`,\n\t\t'\\t\\tif (sgLane == 0u) {',\n\t\t`\\t\\t\\t${stem}Shared.total = sgCount;`,\n\t\t'\\t\\t}',\n\t\t`\\t\\tlet total = workgroupUniformLoad(&${stem}Shared.total);`,\n\t\t`\\t\\tlet offset = ${stem}Shared.flags[local];`,\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t`\\t\\treturn ${resultType}(offset, total);`,\n\t\t'\\t}',\n\t\t'\\tif (sgLane == 0u) {',\n\t\t`\\t\\t${stem}Shared.counts[sgId] = sgCount;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t...spineScanLines,\n\t\t`\\tlet total = workgroupUniformLoad(&${stem}Shared.total);`,\n\t\t`\\t${stem}Shared.flags[lin] = ${stem}Shared.counts[sgId] + sgRank;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tlet offset = ${stem}Shared.flags[local];`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\treturn ${resultType}(offset, total);`,\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({\n\t\tname: stem,\n\t\tsource,\n\t\tvariants: [\n\t\t\t{\n\t\t\t\textensions: ['subgroups'],\n\t\t\t\tlanguages: ['subgroup_id'],\n\t\t\t\tlinear: true,\n\t\t\t\tsource: directSource,\n\t\t\t},\n\t\t\t{\n\t\t\t\textensions: ['subgroups'],\n\t\t\t\tlanguages: ['subgroup_id'],\n\t\t\t\tsource: remappedSource,\n\t\t\t},\n\t\t],\n\t\tworkgroup,\n\t})\n}\n\n/**\n * Creates a frozen workgroup stable-partition fragment returning each lane's output offset and workgroup-wide pivot.\n *\n * @remarks\n * Declares `struct {Stem}Result { offset: u32, pivot: u32 }`, one workgroup scratch variable\n * `{stem}Shared`, and `fn {stem}(invocation: Invocation, dispatch: Dispatch, keep: bool) -> {Stem}Result`.\n * Every lane receives the same workgroup-wide `pivot` count of kept lanes (`sgCount` when\n * `num_subgroups == 1` on the 1D ballot path, `workgroupUniformLoad` otherwise), and `offset` maps\n * `keep == true` lanes stably into `0 .. pivot - 1` and `keep == false` lanes stably into\n * `pivot .. workgroup - 1`. Because WGSL static uniformity analysis taints a returned `struct`\n * carrying per-lane `offset`, callers branching before a barrier must reload `pivot` through\n * `workgroupUniformLoad`, or pair with `WGSL_JOIN` or `createWGSLBroadcast`. Attaches both a 1D\n * `linear: true` direct `subgroupBallot` variant (`0` barriers when `num_subgroups == 1`) and a\n * 2D-safe remapped `subgroupBallot` variant requiring `subgroup_id`, clamping every ballot mask to\n * `activeSg = min(dispatch.subgroup_size, workgroup)` across `subgroup_size <= 32` and `vec4u`\n * paths. Thrown with code `ARGUMENT` for malformed options or an invalid `name`.\n *\n * @param input - The partition's workgroup count and optional name\n * @returns The frozen stable-partition fragment\n *\n * @example\n * ```ts\n * createWGSLPartition({ workgroup: 256 }).name // 'partition256'\n * ```\n */\nexport function createWGSLPartition(input: WGSLPartitionInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t} satisfies OptionFieldsFor<WGSLPartitionInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLPartition')\n\t\t\t\treturn new WGSLError(`The partition options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A partition fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup } = resolved\n\tconst stem = name ?? `partition${workgroup}`\n\tconst pascal = `${stem.slice(0, 1).toUpperCase()}${stem.slice(1)}`\n\tconst resultType = `${pascal}Result`\n\tconst scratchType = `${pascal}Scratch`\n\tconst ballotCountLines = [\n\t\t'\\tvar sgCount = 0u;',\n\t\t'\\tvar sgRank = 0u;',\n\t\t'\\tif (sgSize <= 32u) {',\n\t\t'\\t\\tlet activeMask = 0xffffffffu >> ((32u - activeSg) & 31u);',\n\t\t'\\t\\tlet lowerMask = (1u << sgLane) - 1u;',\n\t\t'\\t\\tlet masked = ballot.x & activeMask;',\n\t\t'\\t\\tsgCount = countOneBits(masked);',\n\t\t'\\t\\tsgRank = countOneBits(masked & lowerMask);',\n\t\t'\\t} else {',\n\t\t'\\t\\tlet a0 = select(0u, 0xffffffffu >> ((32u - min(activeSg, 32u)) & 31u), activeSg > 0u);',\n\t\t'\\t\\tlet a1 = select(0u, 0xffffffffu >> ((32u - min(activeSg - 32u, 32u)) & 31u), activeSg > 32u);',\n\t\t'\\t\\tlet a2 = select(0u, 0xffffffffu >> ((32u - min(activeSg - 64u, 32u)) & 31u), activeSg > 64u);',\n\t\t'\\t\\tlet a3 = select(0u, 0xffffffffu >> ((32u - min(activeSg - 96u, 32u)) & 31u), activeSg > 96u);',\n\t\t'\\t\\tlet l0 = select(0u, 0xffffffffu >> ((32u - min(sgLane, 32u)) & 31u), sgLane > 0u);',\n\t\t'\\t\\tlet l1 = select(0u, 0xffffffffu >> ((32u - min(sgLane - 32u, 32u)) & 31u), sgLane > 32u);',\n\t\t'\\t\\tlet l2 = select(0u, 0xffffffffu >> ((32u - min(sgLane - 64u, 32u)) & 31u), sgLane > 64u);',\n\t\t'\\t\\tlet l3 = select(0u, 0xffffffffu >> ((32u - min(sgLane - 96u, 32u)) & 31u), sgLane > 96u);',\n\t\t'\\t\\tlet masked = ballot & vec4u(a0, a1, a2, a3);',\n\t\t'\\t\\tlet cVec = countOneBits(masked);',\n\t\t'\\t\\tsgCount = cVec.x + cVec.y + cVec.z + cVec.w;',\n\t\t'\\t\\tlet rVec = countOneBits(masked & vec4u(l0, l1, l2, l3));',\n\t\t'\\t\\tsgRank = rVec.x + rVec.y + rVec.z + rVec.w;',\n\t\t'\\t}',\n\t]\n\tconst spineScanLines = [\n\t\t'\\tif (numSg <= sgSize) {',\n\t\t'\\t\\tlet isLive = sgId == 0u && sgLane < numSg;',\n\t\t`\\t\\tlet sgVal = select(0u, ${stem}Shared.counts[select(0u, sgLane, isLive)], isLive);`,\n\t\t'\\t\\tlet sgBase = subgroupExclusiveAdd(sgVal);',\n\t\t'\\t\\tif (isLive) {',\n\t\t`\\t\\t\\t${stem}Shared.counts[sgLane] = sgBase;`,\n\t\t'\\t\\t}',\n\t\t'\\t\\tif (sgId == 0u && sgLane == numSg - 1u) {',\n\t\t`\\t\\t\\t${stem}Shared.pivot = sgBase + sgVal;`,\n\t\t'\\t\\t}',\n\t\t'\\t} else {',\n\t\t'\\t\\tif (local == 0u) {',\n\t\t'\\t\\t\\tvar carry = 0u;',\n\t\t'\\t\\t\\tfor (var i = 0u; i < numSg; i += 1u) {',\n\t\t`\\t\\t\\t\\tlet current = ${stem}Shared.counts[i];`,\n\t\t`\\t\\t\\t\\t${stem}Shared.counts[i] = carry;`,\n\t\t'\\t\\t\\t\\tcarry += current;',\n\t\t'\\t\\t\\t}',\n\t\t`\\t\\t\\t${stem}Shared.pivot = carry;`,\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t]\n\tconst source = [\n\t\t`struct ${resultType} {`,\n\t\t'\\toffset: u32,',\n\t\t'\\tpivot: u32,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t`\\tcounts: array<u32, ${workgroup}>,`,\n\t\t'\\tpivot: u32,',\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, keep: bool) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet flag = select(0u, 1u, keep);',\n\t\t`\\t${stem}Shared.counts[local] = select(flag, 0u, local == ${workgroup - 1}u);`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tfor (var span = 1u; span < ${workgroup >> 1}u; span = span << 1u) {`,\n\t\t'\\t\\tlet stride = span << 1u;',\n\t\t`\\t\\tif (local < ${workgroup - 1}u && ((local + 1u) & (stride - 1u)) == 0u) {`,\n\t\t`\\t\\t\\t${stem}Shared.counts[local] = ${stem}Shared.counts[local - span] + ${stem}Shared.counts[local];`,\n\t\t'\\t\\t}',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t'\\t}',\n\t\t`\\tfor (var span = ${workgroup >> 1}u; span > 0u; span = span >> 1u) {`,\n\t\t'\\t\\tlet stride = span << 1u;',\n\t\t'\\t\\tif (((local + 1u) & (stride - 1u)) == 0u) {',\n\t\t`\\t\\t\\tlet prior = ${stem}Shared.counts[local - span];`,\n\t\t`\\t\\t\\tlet carried = ${stem}Shared.counts[local];`,\n\t\t`\\t\\t\\t${stem}Shared.counts[local - span] = carried;`,\n\t\t`\\t\\t\\t${stem}Shared.counts[local] = carried + prior;`,\n\t\t'\\t\\t}',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t'\\t}',\n\t\t`\\tlet rank = ${stem}Shared.counts[local];`,\n\t\t`\\tif (local == ${workgroup - 1}u) {`,\n\t\t`\\t\\t${stem}Shared.pivot = rank + flag;`,\n\t\t'\\t}',\n\t\t`\\tlet pivot = workgroupUniformLoad(&${stem}Shared.pivot);`,\n\t\t'\\tlet offset = select(pivot + (local - rank), rank, keep);',\n\t\t`\\treturn ${resultType}(offset, pivot);`,\n\t\t'}',\n\t].join('\\n')\n\tconst directSource = [\n\t\t`struct ${resultType} {`,\n\t\t'\\toffset: u32,',\n\t\t'\\tpivot: u32,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t`\\tcounts: array<u32, ${workgroup >> 2}>,`,\n\t\t'\\tpivot: u32,',\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, keep: bool) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet sgId = invocation.subgroup_id;',\n\t\t'\\tlet sgLane = invocation.subgroup_invocation_id;',\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t'\\tlet numSg = dispatch.num_subgroups;',\n\t\t`\\tlet activeSg = min(sgSize, ${workgroup}u);`,\n\t\t'\\tlet ballot = subgroupBallot(keep);',\n\t\t...ballotCountLines,\n\t\t'\\tif (numSg == 1u) {',\n\t\t'\\t\\tlet offset = select(sgCount + (local - sgRank), sgRank, keep);',\n\t\t`\\t\\treturn ${resultType}(offset, sgCount);`,\n\t\t'\\t}',\n\t\t'\\tif (sgLane == 0u) {',\n\t\t`\\t\\t${stem}Shared.counts[sgId] = sgCount;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t...spineScanLines,\n\t\t`\\tlet pivot = workgroupUniformLoad(&${stem}Shared.pivot);`,\n\t\t`\\tlet rank = ${stem}Shared.counts[sgId] + sgRank;`,\n\t\t'\\tlet offset = select(pivot + (local - rank), rank, keep);',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\treturn ${resultType}(offset, pivot);`,\n\t\t'}',\n\t].join('\\n')\n\tconst remappedSource = [\n\t\t`struct ${resultType} {`,\n\t\t'\\toffset: u32,',\n\t\t'\\tpivot: u32,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t`\\tflags: array<u32, ${workgroup}>,`,\n\t\t`\\tcounts: array<u32, ${workgroup >> 2}>,`,\n\t\t'\\tpivot: u32,',\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, keep: bool) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet sgId = invocation.subgroup_id;',\n\t\t'\\tlet sgLane = invocation.subgroup_invocation_id;',\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t'\\tlet numSg = dispatch.num_subgroups;',\n\t\t`\\tlet activeSg = min(sgSize, ${workgroup}u);`,\n\t\t`\\t${stem}Shared.flags[local] = select(0u, 1u, keep);`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tlet lin = sgId * sgSize + sgLane;',\n\t\t`\\tlet sgKeep = ${stem}Shared.flags[lin] != 0u;`,\n\t\t'\\tlet ballot = subgroupBallot(sgKeep);',\n\t\t...ballotCountLines,\n\t\t'\\tif (numSg == 1u) {',\n\t\t`\\t\\t${stem}Shared.flags[lin] = sgRank;`,\n\t\t'\\t\\tif (sgLane == 0u) {',\n\t\t`\\t\\t\\t${stem}Shared.pivot = sgCount;`,\n\t\t'\\t\\t}',\n\t\t`\\t\\tlet pivot = workgroupUniformLoad(&${stem}Shared.pivot);`,\n\t\t`\\t\\tlet rank = ${stem}Shared.flags[local];`,\n\t\t'\\t\\tlet offset = select(pivot + (local - rank), rank, keep);',\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t`\\t\\treturn ${resultType}(offset, pivot);`,\n\t\t'\\t}',\n\t\t'\\tif (sgLane == 0u) {',\n\t\t`\\t\\t${stem}Shared.counts[sgId] = sgCount;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t...spineScanLines,\n\t\t`\\tlet pivot = workgroupUniformLoad(&${stem}Shared.pivot);`,\n\t\t`\\t${stem}Shared.flags[lin] = ${stem}Shared.counts[sgId] + sgRank;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tlet rank = ${stem}Shared.flags[local];`,\n\t\t'\\tlet offset = select(pivot + (local - rank), rank, keep);',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\treturn ${resultType}(offset, pivot);`,\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({\n\t\tname: stem,\n\t\tsource,\n\t\tvariants: [\n\t\t\t{\n\t\t\t\textensions: ['subgroups'],\n\t\t\t\tlanguages: ['subgroup_id'],\n\t\t\t\tlinear: true,\n\t\t\t\tsource: directSource,\n\t\t\t},\n\t\t\t{\n\t\t\t\textensions: ['subgroups'],\n\t\t\t\tlanguages: ['subgroup_id'],\n\t\t\t\tsource: remappedSource,\n\t\t\t},\n\t\t],\n\t\tworkgroup,\n\t})\n}\n\n/**\n * Creates a frozen workgroup atomic histogram fragment with strided clear, weighted tally, bounds-checked read, and single-call convenience collective.\n *\n * @remarks\n * Declares `var<workgroup> {stem}Shared: array<atomic<u32>, {bins}>` and four functions:\n * `clear{Stem}(invocation)`, `record{Stem}(bin, weight)`, `read{Stem}(bin)`, and\n * `{stem}(invocation, dispatch, bin, valid)`. Supports `bins` independent of `workgroup`, including\n * `bins > workgroup`, and uses direct `atomicAdd` without subgroup coalescing. The single-call\n * `{stem}` function returns bin `local` for `local < bins` (`0u` for `local >= bins`), so when\n * `bins > workgroup`, bins `workgroup .. bins - 1` are read through `clear{Stem}`, `record{Stem}`,\n * and `read{Stem}`. Thrown with code `ARGUMENT` for malformed options or an invalid `name`.\n *\n * @param input - The histogram's workgroup count, bin count, and optional name\n * @returns The frozen histogram fragment\n *\n * @example\n * ```ts\n * createWGSLHistogram({ workgroup: 64, bins: 256 }).name // 'histogram256W64'\n * ```\n */\nexport function createWGSLHistogram(input: WGSLHistogramInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t\tbins: requiredOption(literalOf(WGSL_HISTOGRAM_SIZES)),\n\t\t} satisfies OptionFieldsFor<WGSLHistogramInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLHistogram')\n\t\t\t\treturn new WGSLError(`The histogram options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A histogram fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup, bins } = resolved\n\tconst stem = name ?? `histogram${bins}W${workgroup}`\n\tconst pascal = `${stem.slice(0, 1).toUpperCase()}${stem.slice(1)}`\n\tconst source = [\n\t\t`var<workgroup> ${stem}Shared: array<atomic<u32>, ${bins}>;`,\n\t\t'',\n\t\t`fn clear${pascal}(invocation: Invocation) {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t`\\tfor (var b = local; b < ${bins}u; b += ${workgroup}u) {`,\n\t\t`\\t\\tatomicStore(&${stem}Shared[b], 0u);`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t'}',\n\t\t'',\n\t\t`fn record${pascal}(bin: u32, weight: u32) {`,\n\t\t`\\tif (bin < ${bins}u && weight != 0u) {`,\n\t\t`\\t\\tatomicAdd(&${stem}Shared[bin], weight);`,\n\t\t'\\t}',\n\t\t'}',\n\t\t'',\n\t\t`fn read${pascal}(bin: u32) -> u32 {`,\n\t\t`\\treturn select(0u, atomicLoad(&${stem}Shared[min(bin, ${bins - 1}u)]), bin < ${bins}u);`,\n\t\t'}',\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, bin: u32, valid: bool) -> u32 {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t`\\tclear${pascal}(invocation);`,\n\t\t`\\tif (valid && bin < ${bins}u) {`,\n\t\t`\\t\\tatomicAdd(&${stem}Shared[bin], 1u);`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tlet total = select(0u, atomicLoad(&${stem}Shared[min(local, ${bins - 1}u)]), local < ${bins}u);`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn total;',\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({ name: stem, source, workgroup })\n}\n\n/**\n * Creates a frozen workgroup segmented prefix scan fragment for any reduction operation.\n *\n * @remarks\n * Declares one workgroup scratch variable `{stem}Shared` and\n * `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}, head: bool) -> {element}`.\n * Lane `0` always starts a segment (`local == 0u || head`). When `exclusive` is `true`, every\n * segment head returns its finite identity from `WGSL_REDUCE_IDENTITIES` (finite `±FLT_MAX`,\n * `±3.4028234663852886e38`, for `f32` `max` and `min`), while internal neutral carry slots use\n * runtime `±Infinity` across reductions so all-`±Infinity` segments remain exact. When padding\n * inactive `f32` lanes with a `NaN` or `±Infinity` sentinel, mask the bit pattern with a runtime\n * input such as `bitcast<f32>(0x7fc00000u | (invocation.local_invocation_index & 0u))`\n * (`0xff800000u` for `-Infinity`, `0x7f800000u` for `+Infinity`), because Tint rejects\n * const-expression `NaN` and `Infinity` bitcasts. For associative exact operations (`u32` and `i32`\n * on all operations, `f32` on `max`/`min`), attaches both a 1D `linear: true` direct subgroup\n * variant and a 2D-safe remapped subgroup variant requiring `subgroup_id`; for floating-point `sum`\n * and `mul`, attaches those variants only when `reordered: true`. Thrown with code `ARGUMENT` for\n * malformed options, an invalid `name`, or bitwise operations (`and`, `or`, `xor`) paired with\n * `'f32'`.\n *\n * @param input - The segmented scan's workgroup count, element type, and optional operation, exclusivity, reordering, and name\n * @returns The frozen segmented scan fragment\n *\n * @example\n * ```ts\n * createWGSLSegmentedScan({ workgroup: 256, element: 'f32', exclusive: true }).name // 'segmentedScanExclusiveF32256'\n * ```\n */\nexport function createWGSLSegmentedScan(input: WGSLSegmentedScanInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t\toperation: defaultOption(literalOf(WGSL_REDUCE_OPERATIONS), 'sum'),\n\t\t\telement: requiredOption(literalOf(WGSL_SCALARS)),\n\t\t\texclusive: defaultOption(isBoolean, false),\n\t\t\treordered: defaultOption(isBoolean, false),\n\t\t} satisfies OptionFieldsFor<WGSLSegmentedScanInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLSegmentedScan')\n\t\t\t\treturn new WGSLError(`The segmented scan options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name, operation, element }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A segmented scan fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\telement === 'f32' &&\n\t\t\t\t\t(operation === 'and' || operation === 'or' || operation === 'xor')\n\t\t\t\t) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`Bitwise segmented scan operation ${preview(operation)} requires 'u32' or 'i32', never 'f32'.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { operation, element } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup, operation, element, exclusive, reordered } = resolved\n\tconst exclusiveTag = exclusive ? 'Exclusive' : 'Inclusive'\n\tconst operationTag =\n\t\toperation === 'sum' ? '' : operation.slice(0, 1).toUpperCase() + operation.slice(1)\n\tconst elementTag = element.toUpperCase()\n\tconst stem = name ?? `segmentedScan${exclusiveTag}${operationTag}${elementTag}${workgroup}`\n\tconst scratchType = `${stem.slice(0, 1).toUpperCase()}${stem.slice(1)}Scratch`\n\tconst identity =\n\t\telement === 'f32'\n\t\t\t? operation === 'and' || operation === 'or' || operation === 'xor'\n\t\t\t\t? ''\n\t\t\t\t: WGSL_REDUCE_IDENTITIES[operation].f32\n\t\t\t: WGSL_REDUCE_IDENTITIES[operation][element]\n\tconst floatExtremum = element === 'f32' && (operation === 'max' || operation === 'min')\n\tconst carryIdentity = floatExtremum\n\t\t? operation === 'max'\n\t\t\t? 'bitcast<f32>(0xff800000u | (local & 0u))'\n\t\t\t: 'bitcast<f32>(0x7f800000u | (local & 0u))'\n\t\t: identity\n\tconst [opPrefix, opInfix, opSuffix] =\n\t\toperation === 'sum'\n\t\t\t? ['', ' + ', '']\n\t\t\t: operation === 'mul'\n\t\t\t\t? ['', ' * ', '']\n\t\t\t\t: operation === 'max'\n\t\t\t\t\t? ['max(', ', ', ')']\n\t\t\t\t\t: operation === 'min'\n\t\t\t\t\t\t? ['min(', ', ', ')']\n\t\t\t\t\t\t: operation === 'and'\n\t\t\t\t\t\t\t? ['', ' & ', '']\n\t\t\t\t\t\t\t: operation === 'or'\n\t\t\t\t\t\t\t\t? ['', ' | ', '']\n\t\t\t\t\t\t\t\t: ['', ' ^ ', '']\n\tconst baseLoopWriteLines = exclusive\n\t\t? [\n\t\t\t\t'\\t\\tworkgroupBarrier();',\n\t\t\t\t`\\t\\t${stem}Shared.values[local] = val;`,\n\t\t\t\t`\\t\\t${stem}Shared.heads[local] = flag;`,\n\t\t\t\t'\\t\\tworkgroupBarrier();',\n\t\t\t]\n\t\t: [\n\t\t\t\t`\\t\\tif (span < ${workgroup >> 1}u) {`,\n\t\t\t\t'\\t\\t\\tworkgroupBarrier();',\n\t\t\t\t`\\t\\t\\t${stem}Shared.values[local] = val;`,\n\t\t\t\t`\\t\\t\\t${stem}Shared.heads[local] = flag;`,\n\t\t\t\t'\\t\\t\\tworkgroupBarrier();',\n\t\t\t\t'\\t\\t}',\n\t\t\t]\n\tconst baseTailLines = exclusive\n\t\t? [\n\t\t\t\t`\\tlet prev = select(${carryIdentity}, ${stem}Shared.values[select(0u, local - 1u, local > 0u)], !segHead);`,\n\t\t\t\t`\\tlet result = select(prev, ${identity}, segHead);`,\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t'\\treturn result;',\n\t\t\t]\n\t\t: ['\\tworkgroupBarrier();', '\\treturn val;']\n\tconst source = [\n\t\t`struct ${scratchType} {`,\n\t\t`\\tvalues: array<${element}, ${workgroup}>,`,\n\t\t`\\theads: array<u32, ${workgroup}>,`,\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}, head: bool) -> ${element} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet segHead = local == 0u || head;',\n\t\t'\\tvar val = value;',\n\t\t'\\tvar flag = select(0u, 1u, segHead);',\n\t\t`\\t${stem}Shared.values[local] = val;`,\n\t\t`\\t${stem}Shared.heads[local] = flag;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tfor (var span = 1u; span < ${workgroup}u; span = span << 1u) {`,\n\t\t'\\t\\tif (local >= span && flag == 0u) {',\n\t\t`\\t\\t\\tlet left = ${stem}Shared.values[local - span];`,\n\t\t`\\t\\t\\tlet leftFlag = ${stem}Shared.heads[local - span];`,\n\t\t`\\t\\t\\tval = ${opPrefix}left${opInfix}val${opSuffix};`,\n\t\t'\\t\\t\\tflag = leftFlag;',\n\t\t'\\t\\t}',\n\t\t...baseLoopWriteLines,\n\t\t'\\t}',\n\t\t...baseTailLines,\n\t\t'}',\n\t].join('\\n')\n\tconst attachSubgroup =\n\t\treordered || element !== 'f32' || operation === 'max' || operation === 'min'\n\tif (!attachSubgroup) {\n\t\treturn createWGSLFragment({ name: stem, source, workgroup })\n\t}\n\tconst intraScanLines = [\n\t\t'\\tvar sgVal = sgInput;',\n\t\t'\\tvar sgFlag = select(0u, 1u, sgSegHead);',\n\t\t'\\tfor (var delta = 1u; delta < activeSg; delta = delta << 1u) {',\n\t\t'\\t\\tlet upVal = subgroupShuffleUp(sgVal, delta);',\n\t\t'\\t\\tlet upFlag = subgroupShuffleUp(sgFlag, delta);',\n\t\t'\\t\\tif (sgLane >= delta && sgFlag == 0u) {',\n\t\t`\\t\\t\\tsgVal = ${opPrefix}upVal${opInfix}sgVal${opSuffix};`,\n\t\t'\\t\\t\\tsgFlag = upFlag;',\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t]\n\tconst spineLines = [\n\t\t'\\tif (numSg <= sgSize) {',\n\t\t'\\t\\tlet isLive = sgId == 0u && sgLane < numSg;',\n\t\t`\\t\\tvar spVal = select(${carryIdentity}, ${stem}Shared.totals[select(0u, sgLane, isLive)], isLive);`,\n\t\t`\\t\\tvar spFlag = select(1u, ${stem}Shared.flags[select(0u, sgLane, isLive)], isLive);`,\n\t\t'\\t\\tfor (var delta = 1u; delta < activeSg; delta = delta << 1u) {',\n\t\t'\\t\\t\\tlet upVal = subgroupShuffleUp(spVal, delta);',\n\t\t'\\t\\t\\tlet upFlag = subgroupShuffleUp(spFlag, delta);',\n\t\t'\\t\\t\\tif (sgLane >= delta && spFlag == 0u) {',\n\t\t`\\t\\t\\t\\tspVal = ${opPrefix}upVal${opInfix}spVal${opSuffix};`,\n\t\t'\\t\\t\\t\\tspFlag = upFlag;',\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t}',\n\t\t'\\t\\tif (isLive) {',\n\t\t`\\t\\t\\t${stem}Shared.totals[sgLane] = spVal;`,\n\t\t'\\t\\t}',\n\t\t'\\t} else {',\n\t\t'\\t\\tif (local == 0u) {',\n\t\t`\\t\\t\\tvar carry = ${stem}Shared.totals[0u];`,\n\t\t'\\t\\t\\tfor (var i = 1u; i < numSg; i += 1u) {',\n\t\t`\\t\\t\\t\\tlet current = ${stem}Shared.totals[i];`,\n\t\t`\\t\\t\\t\\tlet hasHead = ${stem}Shared.flags[i] != 0u;`,\n\t\t`\\t\\t\\t\\tcarry = select(${opPrefix}carry${opInfix}current${opSuffix}, current, hasHead);`,\n\t\t`\\t\\t\\t\\t${stem}Shared.totals[i] = carry;`,\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t]\n\tconst directSingleLines = exclusive\n\t\t? [\n\t\t\t\t'\\t\\tlet prevInSg = subgroupShuffleUp(sgVal, 1u);',\n\t\t\t\t`\\t\\treturn select(prevInSg, ${identity}, segHead);`,\n\t\t\t]\n\t\t: ['\\t\\treturn sgVal;']\n\tconst directTailLines = exclusive\n\t\t? [\n\t\t\t\t'\\tlet prevInSg = subgroupShuffleUp(incl, 1u);',\n\t\t\t\t`\\tlet prevFromSpine = select(${carryIdentity}, ${stem}Shared.totals[select(0u, sgId - 1u, sgId > 0u)], sgId > 0u);`,\n\t\t\t\t'\\tlet prev = select(prevFromSpine, prevInSg, sgLane > 0u);',\n\t\t\t\t`\\tlet result = select(prev, ${identity}, segHead);`,\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t'\\treturn result;',\n\t\t\t]\n\t\t: ['\\tworkgroupBarrier();', '\\treturn incl;']\n\tconst directSource = [\n\t\t`struct ${scratchType} {`,\n\t\t`\\ttotals: array<${element}, ${workgroup >> 2}>,`,\n\t\t`\\tflags: array<u32, ${workgroup >> 2}>,`,\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}, head: bool) -> ${element} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet segHead = local == 0u || head;',\n\t\t'\\tlet sgId = invocation.subgroup_id;',\n\t\t'\\tlet sgLane = invocation.subgroup_invocation_id;',\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t'\\tlet numSg = dispatch.num_subgroups;',\n\t\t`\\tlet activeSg = min(sgSize, ${workgroup}u);`,\n\t\t'\\tlet sgInput = value;',\n\t\t'\\tlet sgSegHead = segHead;',\n\t\t...intraScanLines,\n\t\t'\\tif (numSg == 1u) {',\n\t\t...directSingleLines,\n\t\t'\\t}',\n\t\t'\\tif (sgLane == activeSg - 1u) {',\n\t\t`\\t\\t${stem}Shared.totals[sgId] = sgVal;`,\n\t\t`\\t\\t${stem}Shared.flags[sgId] = sgFlag;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t...spineLines,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tvar incl = sgVal;',\n\t\t'\\tif (sgId > 0u && sgFlag == 0u) {',\n\t\t`\\t\\tlet prefix = ${stem}Shared.totals[sgId - 1u];`,\n\t\t`\\t\\tincl = ${opPrefix}prefix${opInfix}sgVal${opSuffix};`,\n\t\t'\\t}',\n\t\t...directTailLines,\n\t\t'}',\n\t].join('\\n')\n\tconst remappedSingleLines = exclusive\n\t\t? [\n\t\t\t\t'\\t\\tlet prevInSg = subgroupShuffleUp(sgVal, 1u);',\n\t\t\t\t`\\t\\t${stem}Shared.values[lin] = select(prevInSg, ${identity}, sgSegHead);`,\n\t\t\t\t'\\t\\tworkgroupBarrier();',\n\t\t\t\t`\\t\\tlet result = ${stem}Shared.values[local];`,\n\t\t\t\t'\\t\\tworkgroupBarrier();',\n\t\t\t\t'\\t\\treturn result;',\n\t\t\t]\n\t\t: [\n\t\t\t\t`\\t\\t${stem}Shared.values[lin] = sgVal;`,\n\t\t\t\t'\\t\\tworkgroupBarrier();',\n\t\t\t\t`\\t\\tlet result = ${stem}Shared.values[local];`,\n\t\t\t\t'\\t\\tworkgroupBarrier();',\n\t\t\t\t'\\t\\treturn result;',\n\t\t\t]\n\tconst remappedTailLines = exclusive\n\t\t? [\n\t\t\t\t'\\tlet prevInSg = subgroupShuffleUp(incl, 1u);',\n\t\t\t\t`\\tlet prevFromSpine = select(${carryIdentity}, ${stem}Shared.totals[select(0u, sgId - 1u, sgId > 0u)], sgId > 0u);`,\n\t\t\t\t'\\tlet prev = select(prevFromSpine, prevInSg, sgLane > 0u);',\n\t\t\t\t`\\tlet exclLin = select(prev, ${identity}, sgSegHead);`,\n\t\t\t\t`\\t${stem}Shared.values[lin] = exclLin;`,\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t`\\tlet result = ${stem}Shared.values[local];`,\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t'\\treturn result;',\n\t\t\t]\n\t\t: [\n\t\t\t\t`\\t${stem}Shared.values[lin] = incl;`,\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t`\\tlet result = ${stem}Shared.values[local];`,\n\t\t\t\t'\\tworkgroupBarrier();',\n\t\t\t\t'\\treturn result;',\n\t\t\t]\n\tconst remappedSource = [\n\t\t`struct ${scratchType} {`,\n\t\t`\\tvalues: array<${element}, ${workgroup}>,`,\n\t\t`\\theads: array<u32, ${workgroup}>,`,\n\t\t`\\ttotals: array<${element}, ${workgroup >> 2}>,`,\n\t\t`\\tflags: array<u32, ${workgroup >> 2}>,`,\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}, head: bool) -> ${element} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet segHead = local == 0u || head;',\n\t\t'\\tlet sgId = invocation.subgroup_id;',\n\t\t'\\tlet sgLane = invocation.subgroup_invocation_id;',\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t'\\tlet numSg = dispatch.num_subgroups;',\n\t\t`\\tlet activeSg = min(sgSize, ${workgroup}u);`,\n\t\t`\\t${stem}Shared.values[local] = value;`,\n\t\t`\\t${stem}Shared.heads[local] = select(0u, 1u, segHead);`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tlet lin = sgId * sgSize + sgLane;',\n\t\t`\\tlet sgInput = ${stem}Shared.values[lin];`,\n\t\t`\\tlet sgSegHead = ${stem}Shared.heads[lin] != 0u;`,\n\t\t...intraScanLines,\n\t\t'\\tif (numSg == 1u) {',\n\t\t...remappedSingleLines,\n\t\t'\\t}',\n\t\t'\\tif (sgLane == activeSg - 1u) {',\n\t\t`\\t\\t${stem}Shared.totals[sgId] = sgVal;`,\n\t\t`\\t\\t${stem}Shared.flags[sgId] = sgFlag;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t...spineLines,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tvar incl = sgVal;',\n\t\t'\\tif (sgId > 0u && sgFlag == 0u) {',\n\t\t`\\t\\tlet prefix = ${stem}Shared.totals[sgId - 1u];`,\n\t\t`\\t\\tincl = ${opPrefix}prefix${opInfix}sgVal${opSuffix};`,\n\t\t'\\t}',\n\t\t...remappedTailLines,\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({\n\t\tname: stem,\n\t\tsource,\n\t\tvariants: [\n\t\t\t{\n\t\t\t\textensions: ['subgroups'],\n\t\t\t\tlanguages: ['subgroup_id'],\n\t\t\t\tlinear: true,\n\t\t\t\tsource: directSource,\n\t\t\t},\n\t\t\t{\n\t\t\t\textensions: ['subgroups'],\n\t\t\t\tlanguages: ['subgroup_id'],\n\t\t\t\tsource: remappedSource,\n\t\t\t},\n\t\t],\n\t\tworkgroup,\n\t})\n}\n\n/**\n * Creates a frozen workgroup segmented reduction fragment delivering each segment's total at its head lane.\n *\n * @remarks\n * Declares `struct {Stem}Result { value: {element}, valid: bool }`, one workgroup scratch variable\n * `{stem}Shared`, and\n * `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}, head: bool) -> {Stem}Result`.\n * Lane `0` always starts a segment (`local == 0u || head`). Every segment head receives its full\n * segment reduction with `valid: true`, and non-head lanes receive their own input with\n * `valid: false`, using `0` synthetic identity constants so `±Infinity`, `-0.0`, `vec2f`, and\n * `vec4f` remain exact. When padding inactive `f32` lanes with a `NaN` or `±Infinity` sentinel,\n * mask the bit pattern with a runtime input such as\n * `bitcast<f32>(0x7fc00000u | (invocation.local_invocation_index & 0u))` (`0xff800000u` for\n * `-Infinity`, `0x7f800000u` for `+Infinity`), because Tint rejects const-expression `NaN` and\n * `Infinity` bitcasts. For associative exact operations (`u32` and `i32` on all operations,\n * floating-point elements on `max`/`min`), attaches both a 1D `linear: true` direct subgroup\n * variant and a 2D-safe remapped subgroup variant requiring `subgroup_id`; for floating-point `sum`\n * and `mul`, attaches those variants only when `reordered: true`. Thrown with code `ARGUMENT` for\n * malformed options, an invalid `name`, or bitwise operations (`and`, `or`, `xor`) paired with\n * floating-point elements (`f32`, `vec2f`, `vec4f`).\n *\n * @param input - The segmented reduction's workgroup count, operation, element type, and optional reordering and name\n * @returns The frozen segmented reduction fragment\n *\n * @example\n * ```ts\n * createWGSLSegmentedReduce({ workgroup: 256, operation: 'sum', element: 'f32' }).name // 'segmentedReduceSumF32256'\n * ```\n */\nexport function createWGSLSegmentedReduce(input: WGSLSegmentedReduceInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t\toperation: requiredOption(literalOf(WGSL_REDUCE_OPERATIONS)),\n\t\t\telement: requiredOption(literalOf(WGSL_REDUCE_ELEMENTS)),\n\t\t\treordered: defaultOption(isBoolean, false),\n\t\t} satisfies OptionFieldsFor<WGSLSegmentedReduceInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLSegmentedReduce')\n\t\t\t\treturn new WGSLError(`The segmented reduction options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name, operation, element }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A segmented reduction fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\t(operation === 'and' || operation === 'or' || operation === 'xor') &&\n\t\t\t\t\t(element === 'f32' || element === 'vec2f' || element === 'vec4f')\n\t\t\t\t) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`Bitwise segmented reduction operation ${preview(operation)} requires 'u32' or 'i32', never ${preview(element)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { operation, element } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup, operation, element, reordered } = resolved\n\tconst operationTag = operation.slice(0, 1).toUpperCase() + operation.slice(1)\n\tconst elementTag = element.toUpperCase()\n\tconst stem = name ?? `segmentedReduce${operationTag}${elementTag}${workgroup}`\n\tconst pascal = `${stem.slice(0, 1).toUpperCase()}${stem.slice(1)}`\n\tconst resultType = `${pascal}Result`\n\tconst scratchType = `${pascal}Scratch`\n\tconst [opPrefix, opInfix, opSuffix] =\n\t\toperation === 'sum'\n\t\t\t? ['', ' + ', '']\n\t\t\t: operation === 'mul'\n\t\t\t\t? ['', ' * ', '']\n\t\t\t\t: operation === 'max'\n\t\t\t\t\t? ['max(', ', ', ')']\n\t\t\t\t\t: operation === 'min'\n\t\t\t\t\t\t? ['min(', ', ', ')']\n\t\t\t\t\t\t: operation === 'and'\n\t\t\t\t\t\t\t? ['', ' & ', '']\n\t\t\t\t\t\t\t: operation === 'or'\n\t\t\t\t\t\t\t\t? ['', ' | ', '']\n\t\t\t\t\t\t\t\t: ['', ' ^ ', '']\n\tconst source = [\n\t\t`struct ${resultType} {`,\n\t\t`\\tvalue: ${element},`,\n\t\t'\\tvalid: bool,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t`\\tvalues: array<${element}, ${workgroup}>,`,\n\t\t`\\theads: array<u32, ${workgroup}>,`,\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}, head: bool) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet segHead = local == 0u || head;',\n\t\t`\\t${stem}Shared.values[local] = value;`,\n\t\t`\\t${stem}Shared.heads[local] = select(0u, 1u, segHead);`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tvar val = value;',\n\t\t`\\tvar closed = select(${stem}Shared.heads[min(local + 1u, ${workgroup - 1}u)], 1u, local == ${workgroup - 1}u);`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\t${stem}Shared.heads[local] = closed;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tfor (var span = 1u; span < ${workgroup}u; span = span << 1u) {`,\n\t\t`\\t\\tif (local + span < ${workgroup}u && closed == 0u) {`,\n\t\t`\\t\\t\\tlet right = ${stem}Shared.values[local + span];`,\n\t\t`\\t\\t\\tlet rightClosed = ${stem}Shared.heads[local + span];`,\n\t\t`\\t\\t\\tval = ${opPrefix}val${opInfix}right${opSuffix};`,\n\t\t'\\t\\t\\tclosed = rightClosed;',\n\t\t'\\t\\t}',\n\t\t`\\t\\tif (span < ${workgroup >> 1}u) {`,\n\t\t'\\t\\t\\tworkgroupBarrier();',\n\t\t`\\t\\t\\t${stem}Shared.values[local] = val;`,\n\t\t`\\t\\t\\t${stem}Shared.heads[local] = closed;`,\n\t\t'\\t\\t\\tworkgroupBarrier();',\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\treturn ${resultType}(select(value, val, segHead), segHead);`,\n\t\t'}',\n\t].join('\\n')\n\tconst isFloat = element === 'f32' || element === 'vec2f' || element === 'vec4f'\n\tconst attachSubgroup = reordered || !isFloat || operation === 'max' || operation === 'min'\n\tif (!attachSubgroup) {\n\t\treturn createWGSLFragment({ name: stem, source, workgroup })\n\t}\n\tconst intraReduceLines = [\n\t\t'\\tlet nextHeadInSg = subgroupShuffleDown(headBit, 1u);',\n\t\t'\\tvar sgVal = sgInput;',\n\t\t'\\tvar sgClosed = select(0u, nextHeadInSg, sgLane < activeSg - 1u);',\n\t\t'\\tfor (var delta = 1u; delta < activeSg; delta = delta << 1u) {',\n\t\t'\\t\\tlet downVal = subgroupShuffleDown(sgVal, delta);',\n\t\t'\\t\\tlet downClosed = subgroupShuffleDown(sgClosed, delta);',\n\t\t'\\t\\tif (sgLane + delta < activeSg && sgClosed == 0u) {',\n\t\t`\\t\\t\\tsgVal = ${opPrefix}sgVal${opInfix}downVal${opSuffix};`,\n\t\t'\\t\\t\\tsgClosed = downClosed;',\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t]\n\tconst spineLines = [\n\t\t'\\tif (numSg <= sgSize) {',\n\t\t'\\t\\tlet isLive = sgId == 0u && sgLane < numSg;',\n\t\t`\\t\\tvar spVal = ${stem}Shared.totals[select(0u, sgLane, isLive)];`,\n\t\t`\\t\\tlet spFlags = ${stem}Shared.flags[select(0u, sgLane, isLive)];`,\n\t\t`\\t\\tlet nextFlags = ${stem}Shared.flags[select(0u, min(sgLane + 1u, numSg - 1u), isLive)];`,\n\t\t'\\t\\tvar spEnd = select(',\n\t\t'\\t\\t\\t1u,',\n\t\t'\\t\\t\\tselect(0u, 1u, (spFlags & 1u) != 0u || sgLane == numSg - 1u || (nextFlags & 2u) != 0u),',\n\t\t'\\t\\t\\tisLive,',\n\t\t'\\t\\t);',\n\t\t'\\t\\tfor (var delta = 1u; delta < activeSg; delta = delta << 1u) {',\n\t\t'\\t\\t\\tlet downVal = subgroupShuffleDown(spVal, delta);',\n\t\t'\\t\\t\\tlet downEnd = subgroupShuffleDown(spEnd, delta);',\n\t\t'\\t\\t\\tif (sgLane + delta < numSg && spEnd == 0u) {',\n\t\t`\\t\\t\\t\\tspVal = ${opPrefix}spVal${opInfix}downVal${opSuffix};`,\n\t\t'\\t\\t\\t\\tspEnd = downEnd;',\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t}',\n\t\t'\\t\\tif (isLive) {',\n\t\t`\\t\\t\\t${stem}Shared.totals[sgLane] = spVal;`,\n\t\t'\\t\\t}',\n\t\t'\\t} else {',\n\t\t'\\t\\tif (local == 0u) {',\n\t\t`\\t\\t\\tvar carry = ${stem}Shared.totals[numSg - 1u];`,\n\t\t'\\t\\t\\tfor (var k = 1u; k < numSg; k += 1u) {',\n\t\t'\\t\\t\\t\\tlet i = (numSg - 1u) - k;',\n\t\t`\\t\\t\\t\\tlet curVal = ${stem}Shared.totals[i];`,\n\t\t`\\t\\t\\t\\tlet curClosed = (${stem}Shared.flags[i] & 1u) != 0u || (${stem}Shared.flags[i + 1u] & 2u) != 0u;`,\n\t\t`\\t\\t\\t\\tcarry = select(${opPrefix}curVal${opInfix}carry${opSuffix}, curVal, curClosed);`,\n\t\t`\\t\\t\\t\\t${stem}Shared.totals[i] = carry;`,\n\t\t'\\t\\t\\t}',\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t]\n\tconst directSource = [\n\t\t`struct ${resultType} {`,\n\t\t`\\tvalue: ${element},`,\n\t\t'\\tvalid: bool,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t`\\ttotals: array<${element}, ${workgroup >> 2}>,`,\n\t\t`\\tflags: array<u32, ${workgroup >> 2}>,`,\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}, head: bool) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet segHead = local == 0u || head;',\n\t\t'\\tlet sgId = invocation.subgroup_id;',\n\t\t'\\tlet sgLane = invocation.subgroup_invocation_id;',\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t'\\tlet numSg = dispatch.num_subgroups;',\n\t\t`\\tlet activeSg = min(sgSize, ${workgroup}u);`,\n\t\t'\\tlet sgInput = value;',\n\t\t'\\tlet headBit = select(0u, 1u, segHead);',\n\t\t...intraReduceLines,\n\t\t'\\tif (numSg == 1u) {',\n\t\t`\\t\\treturn ${resultType}(select(value, sgVal, segHead), segHead);`,\n\t\t'\\t}',\n\t\t'\\tif (sgLane == 0u) {',\n\t\t`\\t\\t${stem}Shared.totals[sgId] = sgVal;`,\n\t\t`\\t\\t${stem}Shared.flags[sgId] = (headBit << 1u) | sgClosed;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t...spineLines,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tvar outVal = sgVal;',\n\t\t'\\tif (sgClosed == 0u && sgId + 1u < numSg) {',\n\t\t`\\t\\tif ((${stem}Shared.flags[sgId + 1u] & 2u) == 0u) {`,\n\t\t`\\t\\t\\tlet suffix = ${stem}Shared.totals[sgId + 1u];`,\n\t\t`\\t\\t\\toutVal = ${opPrefix}sgVal${opInfix}suffix${opSuffix};`,\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\treturn ${resultType}(select(value, outVal, segHead), segHead);`,\n\t\t'}',\n\t].join('\\n')\n\tconst remappedSource = [\n\t\t`struct ${resultType} {`,\n\t\t`\\tvalue: ${element},`,\n\t\t'\\tvalid: bool,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t`\\tvalues: array<${element}, ${workgroup}>,`,\n\t\t`\\theads: array<u32, ${workgroup}>,`,\n\t\t`\\ttotals: array<${element}, ${workgroup >> 2}>,`,\n\t\t`\\tflags: array<u32, ${workgroup >> 2}>,`,\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}, head: bool) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet segHead = local == 0u || head;',\n\t\t'\\tlet sgId = invocation.subgroup_id;',\n\t\t'\\tlet sgLane = invocation.subgroup_invocation_id;',\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t'\\tlet numSg = dispatch.num_subgroups;',\n\t\t`\\tlet activeSg = min(sgSize, ${workgroup}u);`,\n\t\t`\\t${stem}Shared.values[local] = value;`,\n\t\t`\\t${stem}Shared.heads[local] = select(0u, 1u, segHead);`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tlet lin = sgId * sgSize + sgLane;',\n\t\t`\\tlet sgInput = ${stem}Shared.values[lin];`,\n\t\t`\\tlet headBit = ${stem}Shared.heads[lin];`,\n\t\t...intraReduceLines,\n\t\t'\\tif (numSg == 1u) {',\n\t\t`\\t\\t${stem}Shared.values[lin] = sgVal;`,\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t`\\t\\tlet total = ${stem}Shared.values[local];`,\n\t\t'\\t\\tworkgroupBarrier();',\n\t\t`\\t\\treturn ${resultType}(select(value, total, segHead), segHead);`,\n\t\t'\\t}',\n\t\t'\\tif (sgLane == 0u) {',\n\t\t`\\t\\t${stem}Shared.totals[sgId] = sgVal;`,\n\t\t`\\t\\t${stem}Shared.flags[sgId] = (headBit << 1u) | sgClosed;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t...spineLines,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tvar outVal = sgVal;',\n\t\t'\\tif (sgClosed == 0u && sgId + 1u < numSg) {',\n\t\t`\\t\\tif ((${stem}Shared.flags[sgId + 1u] & 2u) == 0u) {`,\n\t\t`\\t\\t\\tlet suffix = ${stem}Shared.totals[sgId + 1u];`,\n\t\t`\\t\\t\\toutVal = ${opPrefix}sgVal${opInfix}suffix${opSuffix};`,\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t`\\t${stem}Shared.values[lin] = outVal;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tlet total = ${stem}Shared.values[local];`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\treturn ${resultType}(select(value, total, segHead), segHead);`,\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({\n\t\tname: stem,\n\t\tsource,\n\t\tvariants: [\n\t\t\t{\n\t\t\t\textensions: ['subgroups'],\n\t\t\t\tlanguages: ['subgroup_id'],\n\t\t\t\tlinear: true,\n\t\t\t\tsource: directSource,\n\t\t\t},\n\t\t\t{\n\t\t\t\textensions: ['subgroups'],\n\t\t\t\tlanguages: ['subgroup_id'],\n\t\t\t\tsource: remappedSource,\n\t\t\t},\n\t\t],\n\t\tworkgroup,\n\t})\n}\n\n/**\n * Creates a frozen workgroup 4-bit radix-rank fragment returning each lane's sorted offset, in-digit rank, and per-digit count.\n *\n * @remarks\n * Declares `struct {Stem}Result { offset: u32, rank: u32, count: u32 }`, one workgroup scratch\n * variable `{stem}Shared`, and\n * `fn {stem}(invocation: Invocation, dispatch: Dispatch, digit: u32) -> {Stem}Result`. Masks\n * `digit` with `& 15u`; `offset` and `rank` belong to the lane's own masked digit, while `count`\n * holds the workgroup's total count for digit `local & 15u` (giving lanes `0..15` the 16-bin\n * histogram directly). The 2D-safe base runs a deterministic `16`-lane tile scan (`4` barriers, `0`\n * atomics); the `linear: true` `subgroups` + `subgroup_id` variant uses 4-bit `subgroupBallot`\n * warp-level multi-split (WLMS) peer masks clamped to `activeSg = min(dispatch.subgroup_size, workgroup)`\n * across `subgroup_size <= 32` and `vec4u` paths. Thrown with code `ARGUMENT` for malformed options\n * or an invalid `name`.\n *\n * @param input - The radix rank's workgroup count and optional name\n * @returns The frozen 4-bit radix-rank fragment\n *\n * @example\n * ```ts\n * createWGSLRadixRank({ workgroup: 256 }).name // 'radixRank256'\n * ```\n */\nexport function createWGSLRadixRank(input: WGSLRadixRankInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t} satisfies OptionFieldsFor<WGSLRadixRankInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLRadixRank')\n\t\t\t\treturn new WGSLError(`The radix rank options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A radix rank fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup } = resolved\n\tconst stem = name ?? `radixRank${workgroup}`\n\tconst pascal = `${stem.slice(0, 1).toUpperCase()}${stem.slice(1)}`\n\tconst resultType = `${pascal}Result`\n\tconst scratchType = `${pascal}Scratch`\n\tconst tiles = workgroup >> 4\n\tconst source = [\n\t\t`struct ${resultType} {`,\n\t\t'\\toffset: u32,',\n\t\t'\\trank: u32,',\n\t\t'\\tcount: u32,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t`\\tdigits: array<u32, ${workgroup}>,`,\n\t\t`\\ttiles: array<u32, ${tiles * 16}>,`,\n\t\t'\\ttotals: array<u32, 16>,',\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, digit: u32) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet d = digit & 15u;',\n\t\t'\\tlet tile = local >> 4u;',\n\t\t'\\tlet tileLane = local & 15u;',\n\t\t`\\t${stem}Shared.digits[local] = d;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tlet tileBase = tile << 4u;',\n\t\t'\\tvar tileCount = 0u;',\n\t\t'\\tvar inTileRank = 0u;',\n\t\t'\\tfor (var k = 0u; k < 16u; k += 1u) {',\n\t\t`\\t\\tlet otherDigit = ${stem}Shared.digits[tileBase + k];`,\n\t\t'\\t\\ttileCount += select(0u, 1u, otherDigit == tileLane);',\n\t\t'\\t\\tinTileRank += select(0u, 1u, k < tileLane && otherDigit == d);',\n\t\t'\\t}',\n\t\t`\\t${stem}Shared.tiles[tile * 16u + tileLane] = tileCount;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tif (local < 16u) {',\n\t\t'\\t\\tvar carry = 0u;',\n\t\t`\\t\\tfor (var t = 0u; t < ${tiles}u; t += 1u) {`,\n\t\t'\\t\\t\\tlet idx = t * 16u + local;',\n\t\t`\\t\\t\\tlet c = ${stem}Shared.tiles[idx];`,\n\t\t`\\t\\t\\t${stem}Shared.tiles[idx] = carry;`,\n\t\t'\\t\\t\\tcarry += c;',\n\t\t'\\t\\t}',\n\t\t`\\t\\t${stem}Shared.totals[local] = carry;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tlet tilePrefix = ${stem}Shared.tiles[tile * 16u + d];`,\n\t\t`\\tlet count = ${stem}Shared.totals[tileLane];`,\n\t\t'\\tvar binBase = 0u;',\n\t\t'\\tfor (var b = 0u; b < d; b += 1u) {',\n\t\t`\\t\\tbinBase += ${stem}Shared.totals[b];`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tlet rank = tilePrefix + inTileRank;',\n\t\t`\\treturn ${resultType}(binBase + rank, rank, count);`,\n\t\t'}',\n\t].join('\\n')\n\tconst variantSource = [\n\t\t`struct ${resultType} {`,\n\t\t'\\toffset: u32,',\n\t\t'\\trank: u32,',\n\t\t'\\tcount: u32,',\n\t\t'}',\n\t\t'',\n\t\t`struct ${scratchType} {`,\n\t\t`\\tcounts: array<u32, ${(workgroup >> 2) * 16}>,`,\n\t\t'\\ttotals: array<u32, 16>,',\n\t\t'\\tbases: array<u32, 16>,',\n\t\t'}',\n\t\t'',\n\t\t`var<workgroup> ${stem}Shared: ${scratchType};`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, digit: u32) -> ${resultType} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t'\\tlet sgId = invocation.subgroup_id;',\n\t\t'\\tlet sgLane = invocation.subgroup_invocation_id;',\n\t\t'\\tlet sgSize = dispatch.subgroup_size;',\n\t\t'\\tlet numSg = dispatch.num_subgroups;',\n\t\t`\\tlet activeSg = min(sgSize, ${workgroup}u);`,\n\t\t'\\tlet d = digit & 15u;',\n\t\t'\\tlet b0 = subgroupBallot((d & 1u) != 0u);',\n\t\t'\\tlet b1 = subgroupBallot((d & 2u) != 0u);',\n\t\t'\\tlet b2 = subgroupBallot((d & 4u) != 0u);',\n\t\t'\\tlet b3 = subgroupBallot((d & 8u) != 0u);',\n\t\t'\\tvar sgPeerCount = 0u;',\n\t\t'\\tvar sgPeerRank = 0u;',\n\t\t'\\tif (sgSize <= 32u) {',\n\t\t'\\t\\tlet activeMask = 0xffffffffu >> ((32u - activeSg) & 31u);',\n\t\t'\\t\\tlet lowerMask = (1u << sgLane) - 1u;',\n\t\t'\\t\\tlet m0 = select(~b0.x, b0.x, (d & 1u) != 0u);',\n\t\t'\\t\\tlet m1 = select(~b1.x, b1.x, (d & 2u) != 0u);',\n\t\t'\\t\\tlet m2 = select(~b2.x, b2.x, (d & 4u) != 0u);',\n\t\t'\\t\\tlet m3 = select(~b3.x, b3.x, (d & 8u) != 0u);',\n\t\t'\\t\\tlet peers = m0 & m1 & m2 & m3 & activeMask;',\n\t\t'\\t\\tsgPeerCount = countOneBits(peers);',\n\t\t'\\t\\tsgPeerRank = countOneBits(peers & lowerMask);',\n\t\t'\\t} else {',\n\t\t'\\t\\tlet a0 = select(0u, 0xffffffffu >> ((32u - min(activeSg, 32u)) & 31u), activeSg > 0u);',\n\t\t'\\t\\tlet a1 = select(0u, 0xffffffffu >> ((32u - min(activeSg - 32u, 32u)) & 31u), activeSg > 32u);',\n\t\t'\\t\\tlet a2 = select(0u, 0xffffffffu >> ((32u - min(activeSg - 64u, 32u)) & 31u), activeSg > 64u);',\n\t\t'\\t\\tlet a3 = select(0u, 0xffffffffu >> ((32u - min(activeSg - 96u, 32u)) & 31u), activeSg > 96u);',\n\t\t'\\t\\tlet l0 = select(0u, 0xffffffffu >> ((32u - min(sgLane, 32u)) & 31u), sgLane > 0u);',\n\t\t'\\t\\tlet l1 = select(0u, 0xffffffffu >> ((32u - min(sgLane - 32u, 32u)) & 31u), sgLane > 32u);',\n\t\t'\\t\\tlet l2 = select(0u, 0xffffffffu >> ((32u - min(sgLane - 64u, 32u)) & 31u), sgLane > 64u);',\n\t\t'\\t\\tlet l3 = select(0u, 0xffffffffu >> ((32u - min(sgLane - 96u, 32u)) & 31u), sgLane > 96u);',\n\t\t'\\t\\tlet m0 = select(~b0, b0, (d & 1u) != 0u);',\n\t\t'\\t\\tlet m1 = select(~b1, b1, (d & 2u) != 0u);',\n\t\t'\\t\\tlet m2 = select(~b2, b2, (d & 4u) != 0u);',\n\t\t'\\t\\tlet m3 = select(~b3, b3, (d & 8u) != 0u);',\n\t\t'\\t\\tlet peers = m0 & m1 & m2 & m3 & vec4u(a0, a1, a2, a3);',\n\t\t'\\t\\tlet cVec = countOneBits(peers);',\n\t\t'\\t\\tsgPeerCount = cVec.x + cVec.y + cVec.z + cVec.w;',\n\t\t'\\t\\tlet rVec = countOneBits(peers & vec4u(l0, l1, l2, l3));',\n\t\t'\\t\\tsgPeerRank = rVec.x + rVec.y + rVec.z + rVec.w;',\n\t\t'\\t}',\n\t\t'\\tlet totalSlots = numSg * 16u;',\n\t\t`\\tfor (var slot = local; slot < totalSlots; slot += ${workgroup}u) {`,\n\t\t`\\t\\t${stem}Shared.counts[slot] = 0u;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tif (sgPeerRank == 0u) {',\n\t\t`\\t\\t${stem}Shared.counts[sgId * 16u + d] = sgPeerCount;`,\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\tvar binTotal = 0u;',\n\t\t'\\tif (local < 16u) {',\n\t\t'\\t\\tfor (var s = 0u; s < numSg; s += 1u) {',\n\t\t'\\t\\t\\tlet idx = s * 16u + local;',\n\t\t`\\t\\t\\tlet c = ${stem}Shared.counts[idx];`,\n\t\t`\\t\\t\\t${stem}Shared.counts[idx] = binTotal;`,\n\t\t'\\t\\t\\tbinTotal += c;',\n\t\t'\\t\\t}',\n\t\t`\\t\\t${stem}Shared.totals[local] = binTotal;`,\n\t\t'\\t}',\n\t\t'\\tif (sgSize >= 16u) {',\n\t\t'\\t\\tlet binBaseScan = subgroupExclusiveAdd(select(0u, binTotal, local < 16u));',\n\t\t'\\t\\tif (local < 16u) {',\n\t\t`\\t\\t\\t${stem}Shared.bases[local] = binBaseScan;`,\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tlet rank = ${stem}Shared.counts[sgId * 16u + d] + sgPeerRank;`,\n\t\t`\\tlet count = ${stem}Shared.totals[local & 15u];`,\n\t\t'\\tvar binBase = 0u;',\n\t\t'\\tif (sgSize >= 16u) {',\n\t\t`\\t\\tbinBase = ${stem}Shared.bases[d];`,\n\t\t'\\t} else {',\n\t\t'\\t\\tfor (var b = 0u; b < d; b += 1u) {',\n\t\t`\\t\\t\\tbinBase += ${stem}Shared.totals[b];`,\n\t\t'\\t\\t}',\n\t\t'\\t}',\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\treturn ${resultType}(binBase + rank, rank, count);`,\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({\n\t\tname: stem,\n\t\tsource,\n\t\tvariants: [\n\t\t\t{\n\t\t\t\textensions: ['subgroups'],\n\t\t\t\tlanguages: ['subgroup_id'],\n\t\t\t\tlinear: true,\n\t\t\t\tsource: variantSource,\n\t\t\t},\n\t\t],\n\t\tworkgroup,\n\t})\n}\n\n/**\n * Creates a frozen workgroup lane-gather permutation fragment.\n *\n * @remarks\n * Declares `var<workgroup> {stem}Shared: array<{element}, {workgroup}>` and\n * `fn {stem}(invocation: Invocation, dispatch: Dispatch, value: {element}, index: u32) -> {element}`.\n * Clamps `index` with `min(index, workgroup - 1)`. Attaches a `linear: true` `subgroups` variant\n * returning `subgroupShuffle(value, min(index, workgroup - 1))` in `0` barriers when\n * `dispatch.subgroup_size >= workgroup` and falling back to a 2-barrier shared-memory gather\n * otherwise. Thrown with code `ARGUMENT` for malformed options or an invalid `name`.\n *\n * @param input - The permutation's workgroup count, element type, and optional name\n * @returns The frozen lane-gather fragment\n *\n * @example\n * ```ts\n * createWGSLPermute({ workgroup: 128, element: 'f32' }).name // 'permuteF32128'\n * ```\n */\nexport function createWGSLPermute(input: WGSLPermuteInput): WGSLFragment {\n\tconst resolved = resolveOptions(\n\t\tinput,\n\t\t{\n\t\t\tname: optionalOption(isString),\n\t\t\tworkgroup: requiredOption(literalOf(WGSL_WORKGROUPS)),\n\t\t\telement: requiredOption(literalOf(WGSL_REDUCE_ELEMENTS)),\n\t\t} satisfies OptionFieldsFor<WGSLPermuteInput>,\n\t\t{\n\t\t\trefuse: (fault) => {\n\t\t\t\tconst cause = optionFaultToError(fault, 'createWGSLPermute')\n\t\t\t\treturn new WGSLError(`The permute options are malformed: ${cause.message}`, {\n\t\t\t\t\tcode: 'ARGUMENT',\n\t\t\t\t\tcontext: { reason: fault.reason, path: fault.path },\n\t\t\t\t\tcause,\n\t\t\t\t})\n\t\t\t},\n\t\t\tcheck: ({ name }) => {\n\t\t\t\tif (name !== undefined && !isWGSLIdentifier(name)) {\n\t\t\t\t\tthrow new WGSLError(\n\t\t\t\t\t\t`A permute fragment name must be a valid WGSL identifier starting with a letter; received ${preview(name)}.`,\n\t\t\t\t\t\t{ code: 'ARGUMENT', context: { name } },\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t)\n\tconst { name, workgroup, element } = resolved\n\tconst stem = name ?? `permute${element.toUpperCase()}${workgroup}`\n\tconst source = [\n\t\t`var<workgroup> ${stem}Shared: array<${element}, ${workgroup}>;`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}, index: u32) -> ${element} {`,\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t`\\t${stem}Shared[local] = value;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tlet result = ${stem}Shared[min(index, ${workgroup - 1}u)];`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn result;',\n\t\t'}',\n\t].join('\\n')\n\tconst variantSource = [\n\t\t`var<workgroup> ${stem}Shared: array<${element}, ${workgroup}>;`,\n\t\t'',\n\t\t`fn ${stem}(invocation: Invocation, dispatch: Dispatch, value: ${element}, index: u32) -> ${element} {`,\n\t\t`\\tlet clamped = min(index, ${workgroup - 1}u);`,\n\t\t`\\tif (dispatch.subgroup_size >= ${workgroup}u) {`,\n\t\t'\\t\\treturn subgroupShuffle(value, clamped);',\n\t\t'\\t}',\n\t\t'\\tlet local = invocation.local_invocation_index;',\n\t\t`\\t${stem}Shared[local] = value;`,\n\t\t'\\tworkgroupBarrier();',\n\t\t`\\tlet result = ${stem}Shared[clamped];`,\n\t\t'\\tworkgroupBarrier();',\n\t\t'\\treturn result;',\n\t\t'}',\n\t].join('\\n')\n\treturn createWGSLFragment({\n\t\tname: stem,\n\t\tsource,\n\t\tvariants: [{ extensions: ['subgroups'], linear: true, source: variantSource }],\n\t\tworkgroup,\n\t})\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;;;;;;;;;;;;;;AAexE,IAAa,wBAAwB,OAAO,OAAO;CAClD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAU;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;CACrD,MAAM;CACN,QAAQ;EACP;EACA;EACA;CACD,CAAC,CAAC,KAAK,IAAI;CACX,MAAM,OAAO,OAAO,CAAC,CAAC;CACtB,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;AAyBD,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,UAAU,OAAO,OAAO,CACvB,OAAO,OAAO;EACb,YAAY,OAAO,OAAO,CAAC,WAAW,CAAU;EAChD,QAAQ;GACP;GACA;GACA;GACA;GACA;GACA;GACA;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,CACF,CAAC;CACD,WAAW;AACZ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;AAyBD,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,UAAU,OAAO,OAAO,CACvB,OAAO,OAAO;EACb,YAAY,OAAO,OAAO,CAAC,WAAW,CAAU;EAChD,QAAQ;GACP;GACA;GACA;GACA;GACA;GACA;GACA;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,CACF,CAAC;CACD,WAAW;AACZ,CAAC;;;;;;;;;;;;;;;;;;AAmBD,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,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;;AAiBD,IAAa,aAA2B,OAAO,OAAO;CACrD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CACvB,OAAO,OAAO;EACb,WAAW,OAAO,OAAO,CAAC,gCAAgC,CAAU;EACpE,QAAQ;GACP;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;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,CACF,CAAC;AACF,CAAC;;;;;;;;;;;;;;AAeD,IAAa,cAA4B,OAAO,OAAO;CACtD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;AAeD,IAAa,aAA2B,OAAO,OAAO;CACrD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;AAgBD,IAAa,YAA0B,OAAO,OAAO;CACpD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;;AAiBD,IAAa,YAA0B,OAAO,OAAO;CACpD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CACvB,OAAO,OAAO;EACb,YAAY,OAAO,OAAO,CAAC,WAAW,CAAU;EAChD,QAAQ;EACR,QAAQ;GACP;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;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,CACF,CAAC;CACD,WAAW;AACZ,CAAC;;;;;;;;;;;;;AAcD,IAAa,yBAAyB,OAAO,OAAO;CACnD;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAU;;;;;;;;;;;;AAaV,IAAa,uBAAuB,OAAO,OAAO;CAAC;CAAO;CAAO;CAAO;CAAS;AAAO,CAAU;;;;;;;;;;;;;AAclG,IAAa,qBAAqB,OAAO,OAAO;CAAC;CAAI;CAAI;CAAI;CAAK;AAAG,CAAU;;;;;;;;;;;;AAa/E,IAAa,uBAAuB,OAAO,OAAO;CAAC;CAAI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ACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;;;;;;;;;;;;;;;;;AAmBD,IAAa,eAA6B,OAAO,OAAO;CACvD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;;;;AAmBD,IAAa,mBAAiC,OAAO,OAAO;CAC3D,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;AAgBD,IAAa,YAA0B,OAAO,OAAO;CACpD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAC,CAAC,KAAK,IAAI;CACX,MAAM,OAAO,OAAO,CAAC,CAAC;CACtB,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;AAgBD,IAAa,YAA0B,OAAO,OAAO;CACpD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAC,CAAC,KAAK,IAAI;CACX,MAAM,OAAO,OAAO,CAAC,CAAC;CACtB,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;;AAiBD,IAAa,aAA2B,OAAO,OAAO;CACrD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;;;AAkBD,IAAa,WAAyB,OAAO,OAAO;CACnD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;AAgBD,IAAa,cAA4B,OAAO,OAAO;CACtD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;;;;;;;;;AAwBD,IAAa,cAA4B,OAAO,OAAO;CACtD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,QAAQ,CAAC;CAC9B,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BD,IAAa,eAA6B,OAAO,OAAO;CACvD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,UAAU,WAAW,CAAC;CAC3C,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AA0BD,IAAa,eAA6B,OAAO,OAAO;CACvD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,WAAW,YAAY,CAAC;CAC7C,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;;;;;;;AAsBD,IAAa,kBAAgC,OAAO,OAAO;CAC1D,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,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;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,SAAS,CAAC;CAC/B,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;;;;AAmBD,IAAa,cAA4B,OAAO,OAAO;CACtD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;;;;AAmBD,IAAa,cAA4B,OAAO,OAAO;CACtD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;;;;;;;;;;;;;;;;;;;;;AAuBD,IAAa,WAAyB,OAAO,OAAO;CACnD,MAAM;CACN,QAAQ;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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,UAAU,OAAO,OAAO,CAAC,CAAC;AAC3B,CAAC;;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A;GACA,UAAU,YAAY;GACtB,wBAAwB,UAAU;GAClC,uBAAuB,QAAQ,GAAG;GAClC;GACA;GACA;GACA,kBAAkB,KAAK,UAAU,YAAY;GAC7C;GACA,MAAM,KAAK,8DAA8D,WAAW;GACpF;GACA;GACA;GACA;GACA,KAAK,KAAK;GACV;GACA;GACA;GACA;GACA;GACA,wBAAwB,KAAK;GAC7B;GACA;GACA;GACA,KAAK,KAAK;GACV;GACA;GACA;GACA,4BAA4B,MAAM;GAClC;GACA,iBAAiB,KAAK;GACtB,SAAS,KAAK;GACd;GACA;GACA,OAAO,KAAK;GACZ;GACA;GACA,sBAAsB,KAAK;GAC3B,iBAAiB,KAAK;GACtB;GACA;GACA,kBAAkB,KAAK;GACvB;GACA;GACA;GACA,YAAY,WAAW;GACvB;EACD,CAAC,CAAC,KAAK,IAqGN;EACA,UAAU,CACT;GACC,YAAY,CAAC,WAAW;GACxB,WAAW,CAAC,aAAa;GACzB,QAAQ;GACR,QA1GmB;IACrB,UAAU,WAAW;IACrB;IACA;IACA;IACA;IACA;IACA,UAAU,YAAY;IACtB,yBAAyB,aAAa,KAAK,GAAG;IAC9C;IACA;IACA;IACA;IACA,kBAAkB,KAAK,UAAU,YAAY;IAC7C;IACA,MAAM,KAAK,8DAA8D,WAAW;IACpF;IACA;IACA;IACA;IACA;IACA,gCAAgC,UAAU;IAC1C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,uDAAuD,UAAU;IACjE,OAAO,KAAK;IACZ;IACA;IACA;IACA,OAAO,KAAK;IACZ;IACA;IACA;IACA;IACA;IACA;IACA,iBAAiB,KAAK;IACtB,SAAS,KAAK;IACd;IACA;IACA,OAAO,KAAK;IACZ;IACA;IACA;IACA;IACA,SAAS,KAAK;IACd;IACA;IAC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