typegpu 0.10.0 → 0.10.2
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/{chunk-BYypO7fO.js → _virtual/_rolldown/runtime.js} +1 -1
- package/builtin.d.ts +50 -0
- package/builtin.js +37 -0
- package/common/fullScreenTriangle.d.ts +26 -0
- package/common/fullScreenTriangle.js +36 -0
- package/common/index.d.ts +2 -3
- package/common/index.js +3 -4
- package/core/buffer/buffer.d.ts +74 -0
- package/core/buffer/buffer.js +197 -0
- package/core/buffer/bufferShorthand.d.ts +48 -0
- package/core/buffer/bufferShorthand.js +49 -0
- package/core/buffer/bufferUsage.d.ts +45 -0
- package/core/buffer/bufferUsage.js +163 -0
- package/core/constant/tgpuConstant.d.ts +28 -0
- package/core/constant/tgpuConstant.js +67 -0
- package/core/declare/tgpuDeclare.d.ts +18 -0
- package/core/declare/tgpuDeclare.js +40 -0
- package/core/function/autoIO.d.ts +37 -0
- package/core/function/autoIO.js +87 -0
- package/core/function/comptime.d.ts +39 -0
- package/core/function/comptime.js +51 -0
- package/core/function/createCallableSchema.js +42 -0
- package/core/function/dualImpl.js +54 -0
- package/core/function/extractArgs.js +204 -0
- package/core/function/fnCore.js +79 -0
- package/core/function/fnTypes.d.ts +34 -0
- package/core/function/ioSchema.d.ts +10 -0
- package/core/function/ioSchema.js +30 -0
- package/core/function/shelllessImpl.d.ts +28 -0
- package/core/function/shelllessImpl.js +23 -0
- package/core/function/templateUtils.js +13 -0
- package/core/function/tgpuComputeFn.d.ts +49 -0
- package/core/function/tgpuComputeFn.js +62 -0
- package/core/function/tgpuFn.d.ts +52 -0
- package/core/function/tgpuFn.js +170 -0
- package/core/function/tgpuFragmentFn.d.ts +68 -0
- package/core/function/tgpuFragmentFn.js +68 -0
- package/core/function/tgpuVertexFn.d.ts +55 -0
- package/core/function/tgpuVertexFn.js +65 -0
- package/core/pipeline/applyPipelineState.js +37 -0
- package/core/pipeline/computePipeline.d.ts +58 -0
- package/core/pipeline/computePipeline.js +226 -0
- package/core/pipeline/connectAttachmentToShader.js +26 -0
- package/core/pipeline/connectTargetsToShader.js +29 -0
- package/core/pipeline/limitsOverflow.js +13 -0
- package/core/pipeline/renderPipeline.d.ts +266 -0
- package/core/pipeline/renderPipeline.js +471 -0
- package/core/pipeline/timeable.d.ts +23 -0
- package/core/pipeline/timeable.js +61 -0
- package/core/pipeline/typeGuards.js +29 -0
- package/core/querySet/querySet.d.ts +22 -0
- package/core/querySet/querySet.js +103 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +59 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +96 -0
- package/core/resolve/externals.d.ts +10 -0
- package/core/resolve/externals.js +58 -0
- package/core/resolve/namespace.d.ts +38 -0
- package/core/resolve/namespace.js +41 -0
- package/core/resolve/resolveData.js +146 -0
- package/core/resolve/stitch.js +25 -0
- package/core/resolve/tgpuResolve.d.ts +151 -0
- package/core/resolve/tgpuResolve.js +68 -0
- package/core/root/configurableImpl.js +18 -0
- package/core/root/init.d.ts +69 -0
- package/core/root/init.js +457 -0
- package/core/root/rootTypes.d.ts +622 -0
- package/core/sampler/sampler.d.ts +35 -0
- package/core/sampler/sampler.js +116 -0
- package/core/simulate/tgpuSimulate.d.ts +36 -0
- package/core/simulate/tgpuSimulate.js +76 -0
- package/core/slot/accessor.d.ts +13 -0
- package/core/slot/accessor.js +97 -0
- package/core/slot/internalSlots.js +7 -0
- package/core/slot/lazy.d.ts +6 -0
- package/core/slot/lazy.js +42 -0
- package/core/slot/slot.d.ts +6 -0
- package/core/slot/slot.js +40 -0
- package/core/slot/slotTypes.d.ts +92 -0
- package/core/slot/slotTypes.js +21 -0
- package/core/texture/externalTexture.d.ts +12 -0
- package/core/texture/externalTexture.js +48 -0
- package/core/texture/texture.d.ts +118 -0
- package/core/texture/texture.js +312 -0
- package/core/texture/textureFormats.d.ts +29 -0
- package/core/texture/textureFormats.js +99 -0
- package/core/texture/textureProps.d.ts +11 -0
- package/core/texture/textureUtils.js +224 -0
- package/core/texture/usageExtension.d.ts +21 -0
- package/core/texture/usageExtension.js +21 -0
- package/core/unroll/tgpuUnroll.d.ts +13 -0
- package/core/unroll/tgpuUnroll.js +36 -0
- package/core/valueProxyUtils.js +44 -0
- package/core/variable/tgpuVariable.d.ts +38 -0
- package/core/variable/tgpuVariable.js +101 -0
- package/core/vertexLayout/connectAttributesToShader.js +59 -0
- package/core/vertexLayout/vertexAttribute.d.ts +29 -0
- package/core/vertexLayout/vertexLayout.d.ts +19 -0
- package/core/vertexLayout/vertexLayout.js +103 -0
- package/data/alignIO.js +15 -0
- package/data/alignmentOf.d.ts +10 -0
- package/data/alignmentOf.js +88 -0
- package/data/array.d.ts +28 -0
- package/data/array.js +48 -0
- package/data/atomic.d.ts +15 -0
- package/data/atomic.js +25 -0
- package/data/attributes.d.ts +121 -0
- package/data/attributes.js +145 -0
- package/data/autoStruct.d.ts +3 -0
- package/data/autoStruct.js +83 -0
- package/data/compiledIO.js +231 -0
- package/data/dataIO.js +549 -0
- package/data/dataTypes.d.ts +115 -0
- package/data/dataTypes.js +97 -0
- package/data/deepEqual.d.ts +25 -0
- package/data/deepEqual.js +58 -0
- package/data/disarray.d.ts +34 -0
- package/data/disarray.js +52 -0
- package/data/getLongestContiguousPrefix.d.ts +10 -0
- package/data/getLongestContiguousPrefix.js +15 -0
- package/data/index.d.ts +26 -4
- package/data/index.js +27 -7
- package/data/instanceToSchema.d.ts +33 -0
- package/data/isContiguous.d.ts +10 -0
- package/data/isContiguous.js +15 -0
- package/data/matrix.d.ts +126 -0
- package/data/matrix.js +517 -0
- package/data/numberOps.js +24 -0
- package/data/numeric.d.ts +81 -0
- package/data/numeric.js +234 -0
- package/data/offsetUtils.d.ts +33 -0
- package/data/offsetUtils.js +167 -0
- package/data/offsets.js +36 -0
- package/data/partialIO.js +68 -0
- package/data/ptr.d.ts +12 -0
- package/data/ptr.js +46 -0
- package/data/ref.d.ts +37 -0
- package/data/ref.js +96 -0
- package/data/sampler.d.ts +107 -0
- package/data/sampler.js +26 -0
- package/data/schemaCallWrapper.js +32 -0
- package/data/schemaMemoryLayout.js +200 -0
- package/data/sizeOf.d.ts +10 -0
- package/data/sizeOf.js +15 -0
- package/data/snippet.d.ts +26 -0
- package/data/snippet.js +61 -0
- package/data/struct.d.ts +17 -0
- package/data/struct.js +46 -0
- package/data/texture.d.ts +292 -0
- package/{texture-Dg5ybJro.js → data/texture.js} +6 -3
- package/data/unstruct.d.ts +24 -0
- package/data/unstruct.js +43 -0
- package/data/vector.d.ts +191 -0
- package/data/vector.js +247 -0
- package/data/vectorImpl.js +516 -0
- package/data/vectorOps.js +664 -0
- package/data/vertexFormatData.d.ts +190 -0
- package/data/vertexFormatData.js +110 -0
- package/data/wgslTypes.d.ts +896 -0
- package/data/wgslTypes.js +215 -0
- package/errors.d.ts +44 -0
- package/errors.js +128 -0
- package/execMode.js +51 -0
- package/extension.d.ts +11 -0
- package/extension.js +18 -0
- package/getGPUValue.js +9 -0
- package/index.d.ts +40 -243
- package/index.js +19 -6318
- package/indexNamedExports.d.ts +38 -0
- package/mathUtils.js +13 -0
- package/memo.js +22 -0
- package/nameRegistry.d.ts +30 -0
- package/nameRegistry.js +449 -0
- package/package.js +5 -0
- package/package.json +23 -23
- package/resolutionCtx.d.ts +29 -0
- package/resolutionCtx.js +546 -0
- package/shared/env.js +13 -0
- package/shared/generators.js +14 -0
- package/shared/meta.d.ts +39 -0
- package/shared/meta.js +63 -0
- package/shared/repr.d.ts +108 -0
- package/shared/stringify.js +22 -0
- package/shared/symbols.d.ts +61 -0
- package/shared/symbols.js +71 -0
- package/shared/utilityTypes.d.ts +29 -0
- package/shared/utilityTypes.js +7 -0
- package/shared/vertexFormat.d.ts +70 -0
- package/shared/vertexFormat.js +64 -0
- package/std/array.d.ts +7 -0
- package/std/array.js +27 -0
- package/std/atomic.d.ts +19 -0
- package/std/atomic.js +113 -0
- package/std/bitcast.d.ts +10 -0
- package/std/bitcast.js +43 -0
- package/std/boolean.d.ts +127 -0
- package/std/boolean.js +274 -0
- package/std/derivative.d.ts +16 -0
- package/std/derivative.js +89 -0
- package/std/discard.d.ts +6 -0
- package/std/discard.js +16 -0
- package/std/extensions.d.ts +8 -0
- package/std/extensions.js +14 -0
- package/std/index.d.ts +15 -3
- package/std/index.js +16 -5
- package/std/matrix.d.ts +41 -0
- package/std/matrix.js +87 -0
- package/std/numeric.d.ts +254 -0
- package/std/numeric.js +847 -0
- package/std/operators.d.ts +48 -0
- package/std/operators.js +153 -0
- package/std/packing.d.ts +26 -0
- package/std/packing.js +86 -0
- package/std/subgroup.d.ts +47 -0
- package/std/subgroup.js +220 -0
- package/std/texture.d.ts +108 -0
- package/std/texture.js +197 -0
- package/tgpu.js +44 -0
- package/tgpuBindGroupLayout.d.ts +161 -0
- package/tgpuBindGroupLayout.js +271 -0
- package/tgpuUnstable.d.ts +48 -0
- package/tgpuUnstable.js +66 -0
- package/tgsl/accessIndex.js +45 -0
- package/tgsl/accessProp.js +113 -0
- package/tgsl/consoleLog/deserializers.js +117 -0
- package/tgsl/consoleLog/logGenerator.js +86 -0
- package/tgsl/consoleLog/serializers.js +225 -0
- package/tgsl/consoleLog/types.d.ts +54 -0
- package/tgsl/consoleLog/types.js +12 -0
- package/tgsl/conversion.js +200 -0
- package/tgsl/forOfUtils.js +45 -0
- package/tgsl/generationHelpers.d.ts +37 -0
- package/tgsl/generationHelpers.js +67 -0
- package/tgsl/math.js +45 -0
- package/tgsl/shaderGenerator.d.ts +18 -0
- package/tgsl/shellless.d.ts +11 -0
- package/tgsl/shellless.js +53 -0
- package/tgsl/wgslGenerator.js +585 -0
- package/types.d.ts +255 -0
- package/types.js +43 -0
- package/unwrapper.d.ts +27 -0
- package/wgslExtensions.d.ts +5 -0
- package/wgslExtensions.js +18 -0
- package/builtin-ClEnM-Ye.js +0 -818
- package/builtin-ClEnM-Ye.js.map +0 -1
- package/common/index.d.ts.map +0 -1
- package/common/index.js.map +0 -1
- package/data/index.d.ts.map +0 -1
- package/data/index.js.map +0 -1
- package/deepEqual-yZXvaV2C.js +0 -413
- package/deepEqual-yZXvaV2C.js.map +0 -1
- package/extensions-0SFbU9FH.js +0 -2032
- package/extensions-0SFbU9FH.js.map +0 -1
- package/fullScreenTriangle-MdLGaAMR.js +0 -543
- package/fullScreenTriangle-MdLGaAMR.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/indexNamedExports-Cdy7USiY.d.ts +0 -5696
- package/indexNamedExports-Cdy7USiY.d.ts.map +0 -1
- package/operators-HTxa_0k9.js +0 -4156
- package/operators-HTxa_0k9.js.map +0 -1
- package/std/index.d.ts.map +0 -1
- package/std/index.js.map +0 -1
- package/texture-Dg5ybJro.js.map +0 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { DualFn } from "../types.js";
|
|
2
|
+
import { AnyMatInstance, AnyNumericVecInstance, mBaseForVec, vBaseForMat } from "../data/wgslTypes.js";
|
|
3
|
+
|
|
4
|
+
//#region src/std/operators.d.ts
|
|
5
|
+
type NumVec = AnyNumericVecInstance;
|
|
6
|
+
type Mat = AnyMatInstance;
|
|
7
|
+
declare function cpuAdd(lhs: number, rhs: number): number;
|
|
8
|
+
declare function cpuAdd<T extends NumVec>(lhs: number, rhs: T): T;
|
|
9
|
+
declare function cpuAdd<T extends NumVec>(lhs: T, rhs: number): T;
|
|
10
|
+
declare function cpuAdd<T extends NumVec | Mat>(lhs: T, rhs: T): T;
|
|
11
|
+
declare function cpuAdd<Lhs extends number | NumVec | Mat, Rhs extends (Lhs extends number ? number | NumVec : Lhs extends NumVec ? number | Lhs : Lhs extends Mat ? Lhs : never)>(lhs: Lhs, rhs: Rhs): Lhs | Rhs;
|
|
12
|
+
declare const add: DualFn<typeof cpuAdd>;
|
|
13
|
+
declare function cpuSub(lhs: number, rhs: number): number;
|
|
14
|
+
declare function cpuSub<T extends NumVec>(lhs: number, rhs: T): T;
|
|
15
|
+
declare function cpuSub<T extends NumVec>(lhs: T, rhs: number): T;
|
|
16
|
+
declare function cpuSub<T extends NumVec | Mat>(lhs: T, rhs: T): T;
|
|
17
|
+
declare function cpuSub<Lhs extends number | NumVec | Mat, Rhs extends (Lhs extends number ? number | NumVec : Lhs extends NumVec ? number | Lhs : Lhs extends Mat ? Lhs : never)>(lhs: Lhs, rhs: Rhs): Lhs | Rhs;
|
|
18
|
+
declare const sub: DualFn<typeof cpuSub>;
|
|
19
|
+
declare function cpuMul(lhs: number, rhs: number): number;
|
|
20
|
+
declare function cpuMul<MV extends NumVec | Mat>(lhs: number, rhs: MV): MV;
|
|
21
|
+
declare function cpuMul<MV extends NumVec | Mat>(lhs: MV, rhs: number): MV;
|
|
22
|
+
declare function cpuMul<V extends NumVec>(lhs: V, rhs: V): V;
|
|
23
|
+
declare function cpuMul<M extends Mat, V extends vBaseForMat<M>>(lhs: V, rhs: M): V;
|
|
24
|
+
declare function cpuMul<M extends Mat, V extends vBaseForMat<M>>(lhs: M, rhs: V): V;
|
|
25
|
+
declare function cpuMul<M extends Mat>(lhs: M, rhs: M): M;
|
|
26
|
+
declare function cpuMul<Lhs extends number | NumVec | Mat, Rhs extends (Lhs extends number ? number | NumVec | Mat : Lhs extends NumVec ? number | Lhs | mBaseForVec<Lhs> : Lhs extends Mat ? number | vBaseForMat<Lhs> | Lhs : never)>(lhs: Lhs, rhs: Rhs): Lhs | Rhs;
|
|
27
|
+
declare const mul: DualFn<typeof cpuMul>;
|
|
28
|
+
declare function cpuDiv(lhs: number, rhs: number): number;
|
|
29
|
+
declare function cpuDiv<T extends NumVec>(lhs: T, rhs: T): T;
|
|
30
|
+
declare function cpuDiv<T extends NumVec>(lhs: number, rhs: T): T;
|
|
31
|
+
declare function cpuDiv<T extends NumVec>(lhs: T, rhs: number): T;
|
|
32
|
+
declare const div: DualFn<typeof cpuDiv>;
|
|
33
|
+
type ModOverload = {
|
|
34
|
+
(a: number, b: number): number;
|
|
35
|
+
<T extends NumVec>(a: T, b: T): T;
|
|
36
|
+
<T extends NumVec>(a: number, b: T): T;
|
|
37
|
+
<T extends NumVec>(a: T, b: number): T;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* @privateRemarks
|
|
41
|
+
* Both JS and WGSL implementations use truncated definition of modulo
|
|
42
|
+
*/
|
|
43
|
+
declare const mod: DualFn<ModOverload>;
|
|
44
|
+
declare function cpuNeg(value: number): number;
|
|
45
|
+
declare function cpuNeg<T extends NumVec>(value: T): T;
|
|
46
|
+
declare const neg: DualFn<typeof cpuNeg>;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { add, div, mod, mul, neg, sub };
|
package/std/operators.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { isFloat32VecInstance, isMat, isMatInstance, isVec, isVecInstance } from "../data/wgslTypes.js";
|
|
2
|
+
import { SignatureNotSupportedError } from "../errors.js";
|
|
3
|
+
import { stitch } from "../core/resolve/stitch.js";
|
|
4
|
+
import { unify } from "../tgsl/conversion.js";
|
|
5
|
+
import { abstractFloat, f16, f32 } from "../data/numeric.js";
|
|
6
|
+
import { vecTypeToConstructor } from "../data/vector.js";
|
|
7
|
+
import { dualImpl } from "../core/function/dualImpl.js";
|
|
8
|
+
import { VectorOps } from "../data/vectorOps.js";
|
|
9
|
+
|
|
10
|
+
//#region src/std/operators.ts
|
|
11
|
+
const getPrimitive = (t) => "primitive" in t ? t.primitive : t;
|
|
12
|
+
const makeBinarySignature = (opts) => (lhs, rhs) => {
|
|
13
|
+
const { restrict } = opts ?? {};
|
|
14
|
+
const fail = (msg) => {
|
|
15
|
+
if (restrict) throw new SignatureNotSupportedError([lhs, rhs], restrict);
|
|
16
|
+
throw new Error(`Cannot apply operator to ${lhs.type} and ${rhs.type}: ${msg}`);
|
|
17
|
+
};
|
|
18
|
+
if (opts?.noMat && (isMat(lhs) || isMat(rhs))) return fail("matrices not supported");
|
|
19
|
+
const lhsC = isVec(lhs) || isMat(lhs);
|
|
20
|
+
const rhsC = isVec(rhs) || isMat(rhs);
|
|
21
|
+
if (!lhsC && !rhsC) {
|
|
22
|
+
const unified = unify([lhs, rhs], restrict);
|
|
23
|
+
if (!unified) return fail("incompatible scalar types");
|
|
24
|
+
return {
|
|
25
|
+
argTypes: unified,
|
|
26
|
+
returnType: unified[0]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (lhsC && rhsC) {
|
|
30
|
+
if (opts?.matVecProduct && isVec(lhs) !== isVec(rhs)) return {
|
|
31
|
+
argTypes: [lhs, rhs],
|
|
32
|
+
returnType: isVec(lhs) ? lhs : rhs
|
|
33
|
+
};
|
|
34
|
+
if (lhs.type !== rhs.type) return fail("operands must have the same type");
|
|
35
|
+
return {
|
|
36
|
+
argTypes: [lhs, rhs],
|
|
37
|
+
returnType: lhs
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const [scalar, composite] = lhsC ? [rhs, lhs] : [lhs, rhs];
|
|
41
|
+
const unified = unify([scalar], [getPrimitive(composite)]);
|
|
42
|
+
if (!unified) return fail(`scalar not convertible to ${getPrimitive(composite).type}`);
|
|
43
|
+
return {
|
|
44
|
+
argTypes: lhsC ? [lhs, unified[0]] : [unified[0], rhs],
|
|
45
|
+
returnType: composite
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const binaryArithmeticSignature = makeBinarySignature();
|
|
49
|
+
const binaryMulSignature = makeBinarySignature({ matVecProduct: true });
|
|
50
|
+
const binaryDivSignature = makeBinarySignature({
|
|
51
|
+
noMat: true,
|
|
52
|
+
restrict: [
|
|
53
|
+
f32,
|
|
54
|
+
f16,
|
|
55
|
+
abstractFloat
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
function cpuAdd(lhs, rhs) {
|
|
59
|
+
if (typeof lhs === "number" && typeof rhs === "number") return lhs + rhs;
|
|
60
|
+
if (typeof lhs === "number" && isVecInstance(rhs)) return VectorOps.addMixed[rhs.kind](rhs, lhs);
|
|
61
|
+
if (isVecInstance(lhs) && typeof rhs === "number") return VectorOps.addMixed[lhs.kind](lhs, rhs);
|
|
62
|
+
if (isVecInstance(lhs) && isVecInstance(rhs) || isMatInstance(lhs) && isMatInstance(rhs)) return VectorOps.add[lhs.kind](lhs, rhs);
|
|
63
|
+
throw new Error("Add/Sub called with invalid arguments.");
|
|
64
|
+
}
|
|
65
|
+
const add = dualImpl({
|
|
66
|
+
name: "add",
|
|
67
|
+
signature: binaryArithmeticSignature,
|
|
68
|
+
normalImpl: cpuAdd,
|
|
69
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`(${lhs} + ${rhs})`
|
|
70
|
+
});
|
|
71
|
+
function cpuSub(lhs, rhs) {
|
|
72
|
+
return cpuAdd(lhs, cpuMul(-1, rhs));
|
|
73
|
+
}
|
|
74
|
+
const sub = dualImpl({
|
|
75
|
+
name: "sub",
|
|
76
|
+
signature: binaryArithmeticSignature,
|
|
77
|
+
normalImpl: cpuSub,
|
|
78
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`(${lhs} - ${rhs})`
|
|
79
|
+
});
|
|
80
|
+
function cpuMul(lhs, rhs) {
|
|
81
|
+
if (typeof lhs === "number" && typeof rhs === "number") return lhs * rhs;
|
|
82
|
+
if (typeof lhs === "number" && (isVecInstance(rhs) || isMatInstance(rhs))) return VectorOps.mulSxV[rhs.kind](lhs, rhs);
|
|
83
|
+
if ((isVecInstance(lhs) || isMatInstance(lhs)) && typeof rhs === "number") return VectorOps.mulSxV[lhs.kind](rhs, lhs);
|
|
84
|
+
if (isVecInstance(lhs) && isVecInstance(rhs)) return VectorOps.mulVxV[lhs.kind](lhs, rhs);
|
|
85
|
+
if (isFloat32VecInstance(lhs) && isMatInstance(rhs)) return VectorOps.mulVxM[rhs.kind](lhs, rhs);
|
|
86
|
+
if (isMatInstance(lhs) && isFloat32VecInstance(rhs)) return VectorOps.mulMxV[lhs.kind](lhs, rhs);
|
|
87
|
+
if (isMatInstance(lhs) && isMatInstance(rhs)) return VectorOps.mulVxV[lhs.kind](lhs, rhs);
|
|
88
|
+
throw new Error("Mul called with invalid arguments.");
|
|
89
|
+
}
|
|
90
|
+
const mul = dualImpl({
|
|
91
|
+
name: "mul",
|
|
92
|
+
signature: binaryMulSignature,
|
|
93
|
+
normalImpl: cpuMul,
|
|
94
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`(${lhs} * ${rhs})`
|
|
95
|
+
});
|
|
96
|
+
function cpuDiv(lhs, rhs) {
|
|
97
|
+
if (typeof lhs === "number" && typeof rhs === "number") return lhs / rhs;
|
|
98
|
+
if (typeof lhs === "number" && isVecInstance(rhs)) {
|
|
99
|
+
const schema = vecTypeToConstructor[rhs.kind];
|
|
100
|
+
return VectorOps.div[rhs.kind](schema(lhs), rhs);
|
|
101
|
+
}
|
|
102
|
+
if (isVecInstance(lhs) && typeof rhs === "number") {
|
|
103
|
+
const schema = vecTypeToConstructor[lhs.kind];
|
|
104
|
+
return VectorOps.div[lhs.kind](lhs, schema(rhs));
|
|
105
|
+
}
|
|
106
|
+
if (isVecInstance(lhs) && isVecInstance(rhs)) return VectorOps.div[lhs.kind](lhs, rhs);
|
|
107
|
+
throw new Error("Div called with invalid arguments.");
|
|
108
|
+
}
|
|
109
|
+
const div = dualImpl({
|
|
110
|
+
name: "div",
|
|
111
|
+
signature: binaryDivSignature,
|
|
112
|
+
normalImpl: cpuDiv,
|
|
113
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`(${lhs} / ${rhs})`,
|
|
114
|
+
ignoreImplicitCastWarning: true
|
|
115
|
+
});
|
|
116
|
+
/**
|
|
117
|
+
* @privateRemarks
|
|
118
|
+
* Both JS and WGSL implementations use truncated definition of modulo
|
|
119
|
+
*/
|
|
120
|
+
const mod = dualImpl({
|
|
121
|
+
name: "mod",
|
|
122
|
+
signature: binaryDivSignature,
|
|
123
|
+
normalImpl: ((a, b) => {
|
|
124
|
+
if (typeof a === "number" && typeof b === "number") return a % b;
|
|
125
|
+
if (typeof a === "number" && isVecInstance(b)) {
|
|
126
|
+
const schema = vecTypeToConstructor[b.kind];
|
|
127
|
+
return VectorOps.mod[b.kind](schema(a), b);
|
|
128
|
+
}
|
|
129
|
+
if (isVecInstance(a) && typeof b === "number") {
|
|
130
|
+
const schema = vecTypeToConstructor[a.kind];
|
|
131
|
+
return VectorOps.mod[a.kind](a, schema(b));
|
|
132
|
+
}
|
|
133
|
+
if (isVecInstance(a) && isVecInstance(b)) return VectorOps.mod[a.kind](a, b);
|
|
134
|
+
throw new Error("Mod called with invalid arguments, expected types: number or vector.");
|
|
135
|
+
}),
|
|
136
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`(${lhs} % ${rhs})`
|
|
137
|
+
});
|
|
138
|
+
function cpuNeg(value) {
|
|
139
|
+
if (typeof value === "number") return -value;
|
|
140
|
+
return VectorOps.neg[value.kind](value);
|
|
141
|
+
}
|
|
142
|
+
const neg = dualImpl({
|
|
143
|
+
name: "neg",
|
|
144
|
+
signature: (arg) => ({
|
|
145
|
+
argTypes: [arg],
|
|
146
|
+
returnType: arg
|
|
147
|
+
}),
|
|
148
|
+
normalImpl: cpuNeg,
|
|
149
|
+
codegenImpl: (_ctx, [arg]) => stitch`-(${arg})`
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
//#endregion
|
|
153
|
+
export { add, div, mod, mul, neg, sub };
|
package/std/packing.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DualFn } from "../types.js";
|
|
2
|
+
import { v2f, v4f } from "../data/wgslTypes.js";
|
|
3
|
+
|
|
4
|
+
//#region src/std/packing.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* @privateRemarks
|
|
7
|
+
* https://gpuweb.github.io/gpuweb/wgsl/#unpack2x16float-builtin
|
|
8
|
+
*/
|
|
9
|
+
declare const unpack2x16float: DualFn<(e: number) => v2f>;
|
|
10
|
+
/**
|
|
11
|
+
* @privateRemarks
|
|
12
|
+
* https://gpuweb.github.io/gpuweb/wgsl/#pack2x16float-builtin
|
|
13
|
+
*/
|
|
14
|
+
declare const pack2x16float: DualFn<(e: v2f) => number>;
|
|
15
|
+
/**
|
|
16
|
+
* @privateRemarks
|
|
17
|
+
* https://gpuweb.github.io/gpuweb/wgsl/#unpack4x8unorm-builtin
|
|
18
|
+
*/
|
|
19
|
+
declare const unpack4x8unorm: DualFn<(e: number) => v4f>;
|
|
20
|
+
/**
|
|
21
|
+
* @privateRemarks
|
|
22
|
+
* https://gpuweb.github.io/gpuweb/wgsl/#pack4x8unorm-builtin
|
|
23
|
+
*/
|
|
24
|
+
declare const pack4x8unorm: DualFn<(e: v4f) => number>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { pack2x16float, pack4x8unorm, unpack2x16float, unpack4x8unorm };
|
package/std/packing.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { stitch } from "../core/resolve/stitch.js";
|
|
2
|
+
import { u32 } from "../data/numeric.js";
|
|
3
|
+
import { vec2f, vec4f } from "../data/vector.js";
|
|
4
|
+
import { dualImpl } from "../core/function/dualImpl.js";
|
|
5
|
+
import * as TB from "typed-binary";
|
|
6
|
+
|
|
7
|
+
//#region src/std/packing.ts
|
|
8
|
+
/**
|
|
9
|
+
* @privateRemarks
|
|
10
|
+
* https://gpuweb.github.io/gpuweb/wgsl/#unpack2x16float-builtin
|
|
11
|
+
*/
|
|
12
|
+
const unpack2x16float = dualImpl({
|
|
13
|
+
name: "unpack2x16float",
|
|
14
|
+
normalImpl: (e) => {
|
|
15
|
+
const buffer = /* @__PURE__ */ new ArrayBuffer(4);
|
|
16
|
+
new TB.BufferWriter(buffer).writeUint32(e);
|
|
17
|
+
const reader = new TB.BufferReader(buffer);
|
|
18
|
+
return vec2f(reader.readFloat16(), reader.readFloat16());
|
|
19
|
+
},
|
|
20
|
+
signature: {
|
|
21
|
+
argTypes: [u32],
|
|
22
|
+
returnType: vec2f
|
|
23
|
+
},
|
|
24
|
+
codegenImpl: (_ctx, [e]) => stitch`unpack2x16float(${e})`
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* @privateRemarks
|
|
28
|
+
* https://gpuweb.github.io/gpuweb/wgsl/#pack2x16float-builtin
|
|
29
|
+
*/
|
|
30
|
+
const pack2x16float = dualImpl({
|
|
31
|
+
name: "pack2x16float",
|
|
32
|
+
normalImpl: (e) => {
|
|
33
|
+
const buffer = /* @__PURE__ */ new ArrayBuffer(4);
|
|
34
|
+
const writer = new TB.BufferWriter(buffer);
|
|
35
|
+
writer.writeFloat16(e.x);
|
|
36
|
+
writer.writeFloat16(e.y);
|
|
37
|
+
return u32(new TB.BufferReader(buffer).readUint32());
|
|
38
|
+
},
|
|
39
|
+
signature: {
|
|
40
|
+
argTypes: [vec2f],
|
|
41
|
+
returnType: u32
|
|
42
|
+
},
|
|
43
|
+
codegenImpl: (_ctx, [e]) => stitch`pack2x16float(${e})`
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* @privateRemarks
|
|
47
|
+
* https://gpuweb.github.io/gpuweb/wgsl/#unpack4x8unorm-builtin
|
|
48
|
+
*/
|
|
49
|
+
const unpack4x8unorm = dualImpl({
|
|
50
|
+
name: "unpack4x8unorm",
|
|
51
|
+
normalImpl: (e) => {
|
|
52
|
+
const buffer = /* @__PURE__ */ new ArrayBuffer(4);
|
|
53
|
+
new TB.BufferWriter(buffer).writeUint32(e);
|
|
54
|
+
const reader = new TB.BufferReader(buffer);
|
|
55
|
+
return vec4f(reader.readUint8() / 255, reader.readUint8() / 255, reader.readUint8() / 255, reader.readUint8() / 255);
|
|
56
|
+
},
|
|
57
|
+
signature: {
|
|
58
|
+
argTypes: [u32],
|
|
59
|
+
returnType: vec4f
|
|
60
|
+
},
|
|
61
|
+
codegenImpl: (_ctx, [e]) => stitch`unpack4x8unorm(${e})`
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* @privateRemarks
|
|
65
|
+
* https://gpuweb.github.io/gpuweb/wgsl/#pack4x8unorm-builtin
|
|
66
|
+
*/
|
|
67
|
+
const pack4x8unorm = dualImpl({
|
|
68
|
+
name: "pack4x8unorm",
|
|
69
|
+
normalImpl: (e) => {
|
|
70
|
+
const buffer = /* @__PURE__ */ new ArrayBuffer(4);
|
|
71
|
+
const writer = new TB.BufferWriter(buffer);
|
|
72
|
+
writer.writeUint8(e.x * 255);
|
|
73
|
+
writer.writeUint8(e.y * 255);
|
|
74
|
+
writer.writeUint8(e.z * 255);
|
|
75
|
+
writer.writeUint8(e.w * 255);
|
|
76
|
+
return u32(new TB.BufferReader(buffer).readUint32());
|
|
77
|
+
},
|
|
78
|
+
signature: {
|
|
79
|
+
argTypes: [vec4f],
|
|
80
|
+
returnType: u32
|
|
81
|
+
},
|
|
82
|
+
codegenImpl: (_ctx, [e]) => stitch`pack4x8unorm(${e})`
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
export { pack2x16float, pack4x8unorm, unpack2x16float, unpack4x8unorm };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DualFn } from "../types.js";
|
|
2
|
+
import { AnyIntegerVecInstance, AnyNumericVecInstance, v4u } from "../data/wgslTypes.js";
|
|
3
|
+
|
|
4
|
+
//#region src/std/subgroup.d.ts
|
|
5
|
+
interface IdentityNumOrVec {
|
|
6
|
+
(e: number): number;
|
|
7
|
+
<T extends AnyNumericVecInstance>(e: T): T;
|
|
8
|
+
}
|
|
9
|
+
interface IdentityIntNumOrVec {
|
|
10
|
+
(e: number): number;
|
|
11
|
+
<T extends AnyIntegerVecInstance>(e: T): T;
|
|
12
|
+
}
|
|
13
|
+
interface IdentityNumOrVecWithIdx {
|
|
14
|
+
(e: number, index: number): number;
|
|
15
|
+
<T extends AnyNumericVecInstance>(e: T, index: number): T;
|
|
16
|
+
}
|
|
17
|
+
interface IdentityNumOrVecWithDelta {
|
|
18
|
+
(e: number, delta: number): number;
|
|
19
|
+
<T extends AnyNumericVecInstance>(e: T, delta: number): T;
|
|
20
|
+
}
|
|
21
|
+
interface IdentityNumOrVecWithMask {
|
|
22
|
+
(e: number, mask: number): number;
|
|
23
|
+
<T extends AnyNumericVecInstance>(e: T, mask: number): T;
|
|
24
|
+
}
|
|
25
|
+
declare const subgroupAdd: DualFn<IdentityNumOrVec>;
|
|
26
|
+
declare const subgroupExclusiveAdd: DualFn<IdentityNumOrVec>;
|
|
27
|
+
declare const subgroupInclusiveAdd: DualFn<IdentityNumOrVec>;
|
|
28
|
+
declare const subgroupAll: DualFn<(e: boolean) => boolean>;
|
|
29
|
+
declare const subgroupAnd: DualFn<IdentityIntNumOrVec>;
|
|
30
|
+
declare const subgroupAny: DualFn<(e: boolean) => boolean>;
|
|
31
|
+
declare const subgroupBallot: DualFn<(e: boolean) => v4u>;
|
|
32
|
+
declare const subgroupBroadcast: DualFn<IdentityNumOrVecWithIdx>;
|
|
33
|
+
declare const subgroupBroadcastFirst: DualFn<IdentityNumOrVec>;
|
|
34
|
+
declare const subgroupElect: DualFn<() => boolean>;
|
|
35
|
+
declare const subgroupMax: DualFn<IdentityNumOrVec>;
|
|
36
|
+
declare const subgroupMin: DualFn<IdentityNumOrVec>;
|
|
37
|
+
declare const subgroupMul: DualFn<IdentityNumOrVec>;
|
|
38
|
+
declare const subgroupExclusiveMul: DualFn<IdentityNumOrVec>;
|
|
39
|
+
declare const subgroupInclusiveMul: DualFn<IdentityNumOrVec>;
|
|
40
|
+
declare const subgroupOr: DualFn<IdentityIntNumOrVec>;
|
|
41
|
+
declare const subgroupShuffle: DualFn<IdentityNumOrVecWithIdx>;
|
|
42
|
+
declare const subgroupShuffleDown: DualFn<IdentityNumOrVecWithDelta>;
|
|
43
|
+
declare const subgroupShuffleUp: DualFn<IdentityNumOrVecWithDelta>;
|
|
44
|
+
declare const subgroupShuffleXor: DualFn<IdentityNumOrVecWithMask>;
|
|
45
|
+
declare const subgroupXor: DualFn<IdentityIntNumOrVec>;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { subgroupAdd, subgroupAll, subgroupAnd, subgroupAny, subgroupBallot, subgroupBroadcast, subgroupBroadcastFirst, subgroupElect, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupMax, subgroupMin, subgroupMul, subgroupOr, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor, subgroupXor };
|
package/std/subgroup.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { stitch } from "../core/resolve/stitch.js";
|
|
2
|
+
import { unify } from "../tgsl/conversion.js";
|
|
3
|
+
import { bool, i32, u32 } from "../data/numeric.js";
|
|
4
|
+
import { vec4u } from "../data/vector.js";
|
|
5
|
+
import { dualImpl } from "../core/function/dualImpl.js";
|
|
6
|
+
|
|
7
|
+
//#region src/std/subgroup.ts
|
|
8
|
+
const errorMessage = "Subgroup operations can only be used in the GPU context.";
|
|
9
|
+
const subgroupAdd = dualImpl({
|
|
10
|
+
name: "subgroupAdd",
|
|
11
|
+
signature: (arg) => ({
|
|
12
|
+
argTypes: [arg],
|
|
13
|
+
returnType: arg
|
|
14
|
+
}),
|
|
15
|
+
normalImpl: errorMessage,
|
|
16
|
+
codegenImpl: (_ctx, [arg]) => stitch`subgroupAdd(${arg})`
|
|
17
|
+
});
|
|
18
|
+
const subgroupExclusiveAdd = dualImpl({
|
|
19
|
+
name: "subgroupExclusiveAdd",
|
|
20
|
+
signature: (arg) => ({
|
|
21
|
+
argTypes: [arg],
|
|
22
|
+
returnType: arg
|
|
23
|
+
}),
|
|
24
|
+
normalImpl: errorMessage,
|
|
25
|
+
codegenImpl: (_ctx, [arg]) => stitch`subgroupExclusiveAdd(${arg})`
|
|
26
|
+
});
|
|
27
|
+
const subgroupInclusiveAdd = dualImpl({
|
|
28
|
+
name: "subgroupInclusiveAdd",
|
|
29
|
+
signature: (arg) => ({
|
|
30
|
+
argTypes: [arg],
|
|
31
|
+
returnType: arg
|
|
32
|
+
}),
|
|
33
|
+
normalImpl: errorMessage,
|
|
34
|
+
codegenImpl: (_ctx, [arg]) => stitch`subgroupInclusiveAdd(${arg})`
|
|
35
|
+
});
|
|
36
|
+
const subgroupAll = dualImpl({
|
|
37
|
+
name: "subgroupAll",
|
|
38
|
+
signature: {
|
|
39
|
+
argTypes: [bool],
|
|
40
|
+
returnType: bool
|
|
41
|
+
},
|
|
42
|
+
normalImpl: errorMessage,
|
|
43
|
+
codegenImpl: (_ctx, [e]) => stitch`subgroupAll(${e})`
|
|
44
|
+
});
|
|
45
|
+
const subgroupAnd = dualImpl({
|
|
46
|
+
name: "subgroupAnd",
|
|
47
|
+
signature: (arg) => ({
|
|
48
|
+
argTypes: [arg],
|
|
49
|
+
returnType: arg
|
|
50
|
+
}),
|
|
51
|
+
normalImpl: errorMessage,
|
|
52
|
+
codegenImpl: (_ctx, [e]) => stitch`subgroupAnd(${e})`
|
|
53
|
+
});
|
|
54
|
+
const subgroupAny = dualImpl({
|
|
55
|
+
name: "subgroupAny",
|
|
56
|
+
signature: {
|
|
57
|
+
argTypes: [bool],
|
|
58
|
+
returnType: bool
|
|
59
|
+
},
|
|
60
|
+
normalImpl: errorMessage,
|
|
61
|
+
codegenImpl: (_ctx, [e]) => stitch`subgroupAny(${e})`
|
|
62
|
+
});
|
|
63
|
+
const subgroupBallot = dualImpl({
|
|
64
|
+
name: "subgroupBallot",
|
|
65
|
+
signature: {
|
|
66
|
+
argTypes: [bool],
|
|
67
|
+
returnType: vec4u
|
|
68
|
+
},
|
|
69
|
+
normalImpl: errorMessage,
|
|
70
|
+
codegenImpl: (_ctx, [e]) => stitch`subgroupBallot(${e})`
|
|
71
|
+
});
|
|
72
|
+
const subgroupBroadcast = dualImpl({
|
|
73
|
+
name: "subgroupBroadcast",
|
|
74
|
+
signature: (...args) => {
|
|
75
|
+
const id = unify([args[1]], [i32, u32]);
|
|
76
|
+
if (!id) throw new Error(`subgroupBroadcast's second argument has to be compatible with i32 or u32. Got: ${args[1].type}`);
|
|
77
|
+
return {
|
|
78
|
+
argTypes: [args[0], id[0]],
|
|
79
|
+
returnType: args[0]
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
normalImpl: errorMessage,
|
|
83
|
+
codegenImpl: (_ctx, [e, index]) => stitch`subgroupBroadcast(${e}, ${index})`
|
|
84
|
+
});
|
|
85
|
+
const subgroupBroadcastFirst = dualImpl({
|
|
86
|
+
name: "subgroupBroadcastFirst",
|
|
87
|
+
signature: (arg) => ({
|
|
88
|
+
argTypes: [arg],
|
|
89
|
+
returnType: arg
|
|
90
|
+
}),
|
|
91
|
+
normalImpl: errorMessage,
|
|
92
|
+
codegenImpl: (_ctx, [e]) => stitch`subgroupBroadcastFirst(${e})`
|
|
93
|
+
});
|
|
94
|
+
const subgroupElect = dualImpl({
|
|
95
|
+
name: "subgroupElect",
|
|
96
|
+
signature: {
|
|
97
|
+
argTypes: [],
|
|
98
|
+
returnType: bool
|
|
99
|
+
},
|
|
100
|
+
normalImpl: errorMessage,
|
|
101
|
+
codegenImpl: () => stitch`subgroupElect()`
|
|
102
|
+
});
|
|
103
|
+
const subgroupMax = dualImpl({
|
|
104
|
+
name: "subgroupMax",
|
|
105
|
+
signature: (arg) => ({
|
|
106
|
+
argTypes: [arg],
|
|
107
|
+
returnType: arg
|
|
108
|
+
}),
|
|
109
|
+
normalImpl: errorMessage,
|
|
110
|
+
codegenImpl: (_ctx, [arg]) => stitch`subgroupMax(${arg})`
|
|
111
|
+
});
|
|
112
|
+
const subgroupMin = dualImpl({
|
|
113
|
+
name: "subgroupMin",
|
|
114
|
+
signature: (arg) => ({
|
|
115
|
+
argTypes: [arg],
|
|
116
|
+
returnType: arg
|
|
117
|
+
}),
|
|
118
|
+
normalImpl: errorMessage,
|
|
119
|
+
codegenImpl: (_ctx, [arg]) => stitch`subgroupMin(${arg})`
|
|
120
|
+
});
|
|
121
|
+
const subgroupMul = dualImpl({
|
|
122
|
+
name: "subgroupMul",
|
|
123
|
+
signature: (arg) => ({
|
|
124
|
+
argTypes: [arg],
|
|
125
|
+
returnType: arg
|
|
126
|
+
}),
|
|
127
|
+
normalImpl: errorMessage,
|
|
128
|
+
codegenImpl: (_ctx, [arg]) => stitch`subgroupMul(${arg})`
|
|
129
|
+
});
|
|
130
|
+
const subgroupExclusiveMul = dualImpl({
|
|
131
|
+
name: "subgroupExclusiveMul",
|
|
132
|
+
signature: (arg) => ({
|
|
133
|
+
argTypes: [arg],
|
|
134
|
+
returnType: arg
|
|
135
|
+
}),
|
|
136
|
+
normalImpl: errorMessage,
|
|
137
|
+
codegenImpl: (_ctx, [arg]) => stitch`subgroupExclusiveMul(${arg})`
|
|
138
|
+
});
|
|
139
|
+
const subgroupInclusiveMul = dualImpl({
|
|
140
|
+
name: "subgroupInclusiveMul",
|
|
141
|
+
signature: (arg) => ({
|
|
142
|
+
argTypes: [arg],
|
|
143
|
+
returnType: arg
|
|
144
|
+
}),
|
|
145
|
+
normalImpl: errorMessage,
|
|
146
|
+
codegenImpl: (_ctx, [arg]) => stitch`subgroupInclusiveMul(${arg})`
|
|
147
|
+
});
|
|
148
|
+
const subgroupOr = dualImpl({
|
|
149
|
+
name: "subgroupOr",
|
|
150
|
+
signature: (arg) => ({
|
|
151
|
+
argTypes: [arg],
|
|
152
|
+
returnType: arg
|
|
153
|
+
}),
|
|
154
|
+
normalImpl: errorMessage,
|
|
155
|
+
codegenImpl: (_ctx, [e]) => stitch`subgroupOr(${e})`
|
|
156
|
+
});
|
|
157
|
+
const subgroupShuffle = dualImpl({
|
|
158
|
+
name: "subgroupShuffle",
|
|
159
|
+
signature: (...args) => {
|
|
160
|
+
const id = unify([args[1]], [i32, u32]);
|
|
161
|
+
if (!id) throw new Error(`subgroupShuffle's second argument has to be compatible with i32 or u32. Got: ${args[1].type}`);
|
|
162
|
+
return {
|
|
163
|
+
argTypes: [args[0], id[0]],
|
|
164
|
+
returnType: args[0]
|
|
165
|
+
};
|
|
166
|
+
},
|
|
167
|
+
normalImpl: errorMessage,
|
|
168
|
+
codegenImpl: (_ctx, [e, index]) => stitch`subgroupShuffle(${e}, ${index})`
|
|
169
|
+
});
|
|
170
|
+
const subgroupShuffleDown = dualImpl({
|
|
171
|
+
name: "subgroupShuffleDown",
|
|
172
|
+
signature: (...args) => {
|
|
173
|
+
const delta = unify([args[1]], [u32]);
|
|
174
|
+
if (!delta) throw new Error(`subgroupShuffleDown's second argument has to be compatible with u32. Got: ${args[1].type}`);
|
|
175
|
+
return {
|
|
176
|
+
argTypes: [args[0], delta[0]],
|
|
177
|
+
returnType: args[0]
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
normalImpl: errorMessage,
|
|
181
|
+
codegenImpl: (_ctx, [e, delta]) => stitch`subgroupShuffleDown(${e}, ${delta})`
|
|
182
|
+
});
|
|
183
|
+
const subgroupShuffleUp = dualImpl({
|
|
184
|
+
name: "subgroupShuffleUp",
|
|
185
|
+
signature: (...args) => {
|
|
186
|
+
const delta = unify([args[1]], [u32]);
|
|
187
|
+
if (!delta) throw new Error(`subgroupShuffleUp's second argument has to be compatible with u32. Got: ${args[1].type}`);
|
|
188
|
+
return {
|
|
189
|
+
argTypes: [args[0], delta[0]],
|
|
190
|
+
returnType: args[0]
|
|
191
|
+
};
|
|
192
|
+
},
|
|
193
|
+
normalImpl: errorMessage,
|
|
194
|
+
codegenImpl: (_ctx, [e, delta]) => stitch`subgroupShuffleUp(${e}, ${delta})`
|
|
195
|
+
});
|
|
196
|
+
const subgroupShuffleXor = dualImpl({
|
|
197
|
+
name: "subgroupShuffleXor",
|
|
198
|
+
signature: (...args) => {
|
|
199
|
+
const mask = unify([args[1]], [u32]);
|
|
200
|
+
if (!mask) throw new Error(`subgroupShuffleXor's second argument has to be compatible with u32. Got: ${args[1].type}`);
|
|
201
|
+
return {
|
|
202
|
+
argTypes: [args[0], mask[0]],
|
|
203
|
+
returnType: args[0]
|
|
204
|
+
};
|
|
205
|
+
},
|
|
206
|
+
normalImpl: errorMessage,
|
|
207
|
+
codegenImpl: (_ctx, [e, mask]) => stitch`subgroupShuffleXor(${e}, ${mask})`
|
|
208
|
+
});
|
|
209
|
+
const subgroupXor = dualImpl({
|
|
210
|
+
name: "subgroupXor",
|
|
211
|
+
signature: (arg) => ({
|
|
212
|
+
argTypes: [arg],
|
|
213
|
+
returnType: arg
|
|
214
|
+
}),
|
|
215
|
+
normalImpl: errorMessage,
|
|
216
|
+
codegenImpl: (_ctx, [e]) => stitch`subgroupXor(${e})`
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
//#endregion
|
|
220
|
+
export { subgroupAdd, subgroupAll, subgroupAnd, subgroupAny, subgroupBallot, subgroupBroadcast, subgroupBroadcastFirst, subgroupElect, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupMax, subgroupMin, subgroupMul, subgroupOr, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor, subgroupXor };
|