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
package/std/numeric.js
ADDED
|
@@ -0,0 +1,847 @@
|
|
|
1
|
+
import { isHalfPrecisionSchema, 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, abstractInt, f16, f32, i32, u32 } from "../data/numeric.js";
|
|
6
|
+
import { vec2f, vec2h, vec2i, vec2u, vec3f, vec3h, vec3i, vec3u, vec4f, vec4h, vec4i, vec4u } from "../data/vector.js";
|
|
7
|
+
import { abstruct } from "../data/struct.js";
|
|
8
|
+
import { MissingCpuImplError, dualImpl } from "../core/function/dualImpl.js";
|
|
9
|
+
import { mat2x2f, mat3x3f, mat4x4f } from "../data/matrix.js";
|
|
10
|
+
import { smoothstepScalar } from "../data/numberOps.js";
|
|
11
|
+
import { VectorOps } from "../data/vectorOps.js";
|
|
12
|
+
import { mul, sub } from "./operators.js";
|
|
13
|
+
|
|
14
|
+
//#region src/std/numeric.ts
|
|
15
|
+
const unaryIdentitySignature = (arg) => {
|
|
16
|
+
return {
|
|
17
|
+
argTypes: [arg],
|
|
18
|
+
returnType: arg
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
const variadicUnifySignature = (...args) => {
|
|
22
|
+
const uargs = unify(args) ?? args;
|
|
23
|
+
return {
|
|
24
|
+
argTypes: uargs,
|
|
25
|
+
returnType: uargs[0]
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const unifyRestrictedSignature = (restrict) => (...args) => {
|
|
29
|
+
const uargs = unify(args, restrict);
|
|
30
|
+
if (!uargs) throw new SignatureNotSupportedError(args, restrict);
|
|
31
|
+
return {
|
|
32
|
+
argTypes: uargs,
|
|
33
|
+
returnType: uargs[0]
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
function variadicReduce(fn) {
|
|
37
|
+
return (fst, ...rest) => {
|
|
38
|
+
let acc = fst;
|
|
39
|
+
for (const r of rest) acc = fn(acc, r);
|
|
40
|
+
return acc;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function variadicStitch(wrapper) {
|
|
44
|
+
return (_ctx, [fst, ...rest]) => {
|
|
45
|
+
let acc = stitch`${fst}`;
|
|
46
|
+
for (const r of rest) acc = stitch`${wrapper}(${acc}, ${r})`;
|
|
47
|
+
return acc;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const anyFloatPrimitive = [
|
|
51
|
+
f32,
|
|
52
|
+
f16,
|
|
53
|
+
abstractFloat
|
|
54
|
+
];
|
|
55
|
+
const anyFloatVec = [
|
|
56
|
+
vec2f,
|
|
57
|
+
vec3f,
|
|
58
|
+
vec4f,
|
|
59
|
+
vec2h,
|
|
60
|
+
vec3h,
|
|
61
|
+
vec4h
|
|
62
|
+
];
|
|
63
|
+
const anyFloat = [...anyFloatPrimitive, ...anyFloatVec];
|
|
64
|
+
const anyConcreteIntegerPrimitive = [i32, u32];
|
|
65
|
+
const anyConcreteIntegerVec = [
|
|
66
|
+
vec2i,
|
|
67
|
+
vec3i,
|
|
68
|
+
vec4i,
|
|
69
|
+
vec2u,
|
|
70
|
+
vec3u,
|
|
71
|
+
vec4u
|
|
72
|
+
];
|
|
73
|
+
const anyConcreteInteger = [...anyConcreteIntegerPrimitive, ...anyConcreteIntegerVec];
|
|
74
|
+
function cpuAbs(value) {
|
|
75
|
+
if (typeof value === "number") return Math.abs(value);
|
|
76
|
+
return VectorOps.abs[value.kind](value);
|
|
77
|
+
}
|
|
78
|
+
const abs = dualImpl({
|
|
79
|
+
name: "abs",
|
|
80
|
+
signature: unaryIdentitySignature,
|
|
81
|
+
normalImpl: cpuAbs,
|
|
82
|
+
codegenImpl: (_ctx, [value]) => stitch`abs(${value})`
|
|
83
|
+
});
|
|
84
|
+
function cpuAcos(value) {
|
|
85
|
+
if (typeof value === "number") return Math.acos(value);
|
|
86
|
+
return VectorOps.acos[value.kind](value);
|
|
87
|
+
}
|
|
88
|
+
const acos = dualImpl({
|
|
89
|
+
name: "acos",
|
|
90
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
91
|
+
normalImpl: cpuAcos,
|
|
92
|
+
codegenImpl: (_ctx, [value]) => stitch`acos(${value})`
|
|
93
|
+
});
|
|
94
|
+
function cpuAcosh(value) {
|
|
95
|
+
if (typeof value === "number") return Math.acosh(value);
|
|
96
|
+
return VectorOps.acosh[value.kind](value);
|
|
97
|
+
}
|
|
98
|
+
const acosh = dualImpl({
|
|
99
|
+
name: "acosh",
|
|
100
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
101
|
+
normalImpl: cpuAcosh,
|
|
102
|
+
codegenImpl: (_ctx, [value]) => stitch`acosh(${value})`
|
|
103
|
+
});
|
|
104
|
+
function cpuAsin(value) {
|
|
105
|
+
if (typeof value === "number") return Math.asin(value);
|
|
106
|
+
return VectorOps.asin[value.kind](value);
|
|
107
|
+
}
|
|
108
|
+
const asin = dualImpl({
|
|
109
|
+
name: "asin",
|
|
110
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
111
|
+
normalImpl: cpuAsin,
|
|
112
|
+
codegenImpl: (_ctx, [value]) => stitch`asin(${value})`
|
|
113
|
+
});
|
|
114
|
+
function cpuAsinh(value) {
|
|
115
|
+
if (typeof value === "number") return Math.asinh(value);
|
|
116
|
+
return VectorOps.asinh[value.kind](value);
|
|
117
|
+
}
|
|
118
|
+
const asinh = dualImpl({
|
|
119
|
+
name: "asinh",
|
|
120
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
121
|
+
normalImpl: cpuAsinh,
|
|
122
|
+
codegenImpl: (_ctx, [value]) => stitch`asinh(${value})`
|
|
123
|
+
});
|
|
124
|
+
function cpuAtan(value) {
|
|
125
|
+
if (typeof value === "number") return Math.atan(value);
|
|
126
|
+
return VectorOps.atan[value.kind](value);
|
|
127
|
+
}
|
|
128
|
+
const atan = dualImpl({
|
|
129
|
+
name: "atan",
|
|
130
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
131
|
+
normalImpl: cpuAtan,
|
|
132
|
+
codegenImpl: (_ctx, [value]) => stitch`atan(${value})`
|
|
133
|
+
});
|
|
134
|
+
function cpuAtanh(value) {
|
|
135
|
+
if (typeof value === "number") return Math.atanh(value);
|
|
136
|
+
return VectorOps.atanh[value.kind](value);
|
|
137
|
+
}
|
|
138
|
+
const atanh = dualImpl({
|
|
139
|
+
name: "atanh",
|
|
140
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
141
|
+
normalImpl: cpuAtanh,
|
|
142
|
+
codegenImpl: (_ctx, [value]) => stitch`atanh(${value})`
|
|
143
|
+
});
|
|
144
|
+
function cpuAtan2(y, x) {
|
|
145
|
+
if (typeof y === "number" && typeof x === "number") return Math.atan2(y, x);
|
|
146
|
+
return VectorOps.atan2[y.kind](y, x);
|
|
147
|
+
}
|
|
148
|
+
const atan2 = dualImpl({
|
|
149
|
+
name: "atan2",
|
|
150
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
151
|
+
normalImpl: cpuAtan2,
|
|
152
|
+
codegenImpl: (_ctx, [y, x]) => stitch`atan2(${y}, ${x})`
|
|
153
|
+
});
|
|
154
|
+
function cpuCeil(value) {
|
|
155
|
+
if (typeof value === "number") return Math.ceil(value);
|
|
156
|
+
return VectorOps.ceil[value.kind](value);
|
|
157
|
+
}
|
|
158
|
+
const ceil = dualImpl({
|
|
159
|
+
name: "ceil",
|
|
160
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
161
|
+
normalImpl: cpuCeil,
|
|
162
|
+
codegenImpl: (_ctx, [value]) => stitch`ceil(${value})`
|
|
163
|
+
});
|
|
164
|
+
function cpuClamp(value, low, high) {
|
|
165
|
+
if (typeof value === "number") return Math.min(Math.max(low, value), high);
|
|
166
|
+
return VectorOps.clamp[value.kind](value, low, high);
|
|
167
|
+
}
|
|
168
|
+
const clamp = dualImpl({
|
|
169
|
+
name: "clamp",
|
|
170
|
+
signature: variadicUnifySignature,
|
|
171
|
+
normalImpl: cpuClamp,
|
|
172
|
+
codegenImpl: (_ctx, [value, low, high]) => stitch`clamp(${value}, ${low}, ${high})`
|
|
173
|
+
});
|
|
174
|
+
function cpuCos(value) {
|
|
175
|
+
if (typeof value === "number") return Math.cos(value);
|
|
176
|
+
return VectorOps.cos[value.kind](value);
|
|
177
|
+
}
|
|
178
|
+
const cos = dualImpl({
|
|
179
|
+
name: "cos",
|
|
180
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
181
|
+
normalImpl: cpuCos,
|
|
182
|
+
codegenImpl: (_ctx, [value]) => stitch`cos(${value})`
|
|
183
|
+
});
|
|
184
|
+
function cpuCosh(value) {
|
|
185
|
+
if (typeof value === "number") return Math.cosh(value);
|
|
186
|
+
return VectorOps.cosh[value.kind](value);
|
|
187
|
+
}
|
|
188
|
+
const cosh = dualImpl({
|
|
189
|
+
name: "cosh",
|
|
190
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
191
|
+
normalImpl: cpuCosh,
|
|
192
|
+
codegenImpl: (_ctx, [value]) => stitch`cosh(${value})`
|
|
193
|
+
});
|
|
194
|
+
const countLeadingZeros = dualImpl({
|
|
195
|
+
name: "countLeadingZeros",
|
|
196
|
+
signature: unifyRestrictedSignature(anyConcreteInteger),
|
|
197
|
+
normalImpl: "CPU implementation for countLeadingZeros not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
198
|
+
codegenImpl: (_ctx, [value]) => stitch`countLeadingZeros(${value})`
|
|
199
|
+
});
|
|
200
|
+
const countOneBits = dualImpl({
|
|
201
|
+
name: "countOneBits",
|
|
202
|
+
signature: unifyRestrictedSignature(anyConcreteInteger),
|
|
203
|
+
normalImpl: "CPU implementation for countOneBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
204
|
+
codegenImpl: (_ctx, [value]) => stitch`countOneBits(${value})`
|
|
205
|
+
});
|
|
206
|
+
const countTrailingZeros = dualImpl({
|
|
207
|
+
name: "countTrailingZeros",
|
|
208
|
+
signature: unifyRestrictedSignature(anyConcreteInteger),
|
|
209
|
+
normalImpl: "CPU implementation for countTrailingZeros not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
210
|
+
codegenImpl: (_ctx, [value]) => stitch`countTrailingZeros(${value})`
|
|
211
|
+
});
|
|
212
|
+
const cross = dualImpl({
|
|
213
|
+
name: "cross",
|
|
214
|
+
signature: unifyRestrictedSignature([vec3f, vec3h]),
|
|
215
|
+
normalImpl: (a, b) => VectorOps.cross[a.kind](a, b),
|
|
216
|
+
codegenImpl: (_ctx, [a, b]) => stitch`cross(${a}, ${b})`
|
|
217
|
+
});
|
|
218
|
+
function cpuDegrees(value) {
|
|
219
|
+
if (typeof value === "number") return value * 180 / Math.PI;
|
|
220
|
+
throw new MissingCpuImplError("CPU implementation for degrees on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
|
|
221
|
+
}
|
|
222
|
+
const degrees = dualImpl({
|
|
223
|
+
name: "degrees",
|
|
224
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
225
|
+
normalImpl: cpuDegrees,
|
|
226
|
+
codegenImpl: (_ctx, [value]) => stitch`degrees(${value})`
|
|
227
|
+
});
|
|
228
|
+
const determinant = dualImpl({
|
|
229
|
+
name: "determinant",
|
|
230
|
+
signature: (arg) => {
|
|
231
|
+
if (!(arg.type === "mat2x2f" || arg.type === "mat3x3f" || arg.type === "mat4x4f")) throw new SignatureNotSupportedError([arg], [
|
|
232
|
+
mat2x2f,
|
|
233
|
+
mat3x3f,
|
|
234
|
+
mat4x4f
|
|
235
|
+
]);
|
|
236
|
+
return {
|
|
237
|
+
argTypes: [arg],
|
|
238
|
+
returnType: f32
|
|
239
|
+
};
|
|
240
|
+
},
|
|
241
|
+
normalImpl: "CPU implementation for determinant not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
242
|
+
codegenImpl: (_ctx, [value]) => stitch`determinant(${value})`
|
|
243
|
+
});
|
|
244
|
+
function cpuDistance(a, b) {
|
|
245
|
+
if (typeof a === "number" && typeof b === "number") return Math.abs(a - b);
|
|
246
|
+
return length(sub(a, b));
|
|
247
|
+
}
|
|
248
|
+
const distance = dualImpl({
|
|
249
|
+
name: "distance",
|
|
250
|
+
signature: (...args) => {
|
|
251
|
+
const uargs = unify(args, anyFloat);
|
|
252
|
+
if (!uargs) throw new SignatureNotSupportedError(args, anyFloat);
|
|
253
|
+
return {
|
|
254
|
+
argTypes: uargs,
|
|
255
|
+
returnType: isHalfPrecisionSchema(uargs[0]) ? f16 : f32
|
|
256
|
+
};
|
|
257
|
+
},
|
|
258
|
+
normalImpl: cpuDistance,
|
|
259
|
+
codegenImpl: (_ctx, [a, b]) => stitch`distance(${a}, ${b})`
|
|
260
|
+
});
|
|
261
|
+
const dot = dualImpl({
|
|
262
|
+
name: "dot",
|
|
263
|
+
signature: (...args) => ({
|
|
264
|
+
argTypes: args,
|
|
265
|
+
returnType: args[0].primitive
|
|
266
|
+
}),
|
|
267
|
+
normalImpl: (lhs, rhs) => VectorOps.dot[lhs.kind](lhs, rhs),
|
|
268
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`dot(${lhs}, ${rhs})`
|
|
269
|
+
});
|
|
270
|
+
const dot4U8Packed = dualImpl({
|
|
271
|
+
name: "dot4U8Packed",
|
|
272
|
+
signature: {
|
|
273
|
+
argTypes: [u32, u32],
|
|
274
|
+
returnType: u32
|
|
275
|
+
},
|
|
276
|
+
normalImpl: "CPU implementation for dot4U8Packed not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
277
|
+
codegenImpl: (_ctx, [e1, e2]) => stitch`dot4U8Packed(${e1}, ${e2})`
|
|
278
|
+
});
|
|
279
|
+
const dot4I8Packed = dualImpl({
|
|
280
|
+
name: "dot4I8Packed",
|
|
281
|
+
signature: {
|
|
282
|
+
argTypes: [u32, u32],
|
|
283
|
+
returnType: i32
|
|
284
|
+
},
|
|
285
|
+
normalImpl: "CPU implementation for dot4I8Packed not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
286
|
+
codegenImpl: (_ctx, [e1, e2]) => stitch`dot4I8Packed(${e1}, ${e2})`
|
|
287
|
+
});
|
|
288
|
+
function cpuExp(value) {
|
|
289
|
+
if (typeof value === "number") return Math.exp(value);
|
|
290
|
+
return VectorOps.exp[value.kind](value);
|
|
291
|
+
}
|
|
292
|
+
const exp = dualImpl({
|
|
293
|
+
name: "exp",
|
|
294
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
295
|
+
normalImpl: cpuExp,
|
|
296
|
+
codegenImpl: (_ctx, [value]) => stitch`exp(${value})`
|
|
297
|
+
});
|
|
298
|
+
function cpuExp2(value) {
|
|
299
|
+
if (typeof value === "number") return 2 ** value;
|
|
300
|
+
return VectorOps.exp2[value.kind](value);
|
|
301
|
+
}
|
|
302
|
+
const exp2 = dualImpl({
|
|
303
|
+
name: "exp2",
|
|
304
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
305
|
+
normalImpl: cpuExp2,
|
|
306
|
+
codegenImpl: (_ctx, [value]) => stitch`exp2(${value})`
|
|
307
|
+
});
|
|
308
|
+
const extractBits = dualImpl({
|
|
309
|
+
name: "extractBits",
|
|
310
|
+
signature: (arg, _offset, _count) => {
|
|
311
|
+
const argRestricted = unify([arg], anyConcreteInteger)?.[0];
|
|
312
|
+
if (!argRestricted) throw new SignatureNotSupportedError([arg], anyConcreteInteger);
|
|
313
|
+
return {
|
|
314
|
+
argTypes: [
|
|
315
|
+
argRestricted,
|
|
316
|
+
u32,
|
|
317
|
+
u32
|
|
318
|
+
],
|
|
319
|
+
returnType: argRestricted
|
|
320
|
+
};
|
|
321
|
+
},
|
|
322
|
+
normalImpl: "CPU implementation for extractBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
323
|
+
codegenImpl: (_ctx, [e, offset, count]) => stitch`extractBits(${e}, ${offset}, ${count})`
|
|
324
|
+
});
|
|
325
|
+
const faceForward = dualImpl({
|
|
326
|
+
name: "faceForward",
|
|
327
|
+
signature: unifyRestrictedSignature(anyFloatVec),
|
|
328
|
+
normalImpl: "CPU implementation for faceForward not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
329
|
+
codegenImpl: (_ctx, [e1, e2, e3]) => stitch`faceForward(${e1}, ${e2}, ${e3})`
|
|
330
|
+
});
|
|
331
|
+
const firstLeadingBit = dualImpl({
|
|
332
|
+
name: "firstLeadingBit",
|
|
333
|
+
signature: unaryIdentitySignature,
|
|
334
|
+
normalImpl: "CPU implementation for firstLeadingBit not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
335
|
+
codegenImpl: (_ctx, [value]) => stitch`firstLeadingBit(${value})`
|
|
336
|
+
});
|
|
337
|
+
const firstTrailingBit = dualImpl({
|
|
338
|
+
name: "firstTrailingBit",
|
|
339
|
+
signature: unifyRestrictedSignature(anyConcreteInteger),
|
|
340
|
+
normalImpl: "CPU implementation for firstTrailingBit not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
341
|
+
codegenImpl: (_ctx, [value]) => stitch`firstTrailingBit(${value})`
|
|
342
|
+
});
|
|
343
|
+
function cpuFloor(value) {
|
|
344
|
+
if (typeof value === "number") return Math.floor(value);
|
|
345
|
+
return VectorOps.floor[value.kind](value);
|
|
346
|
+
}
|
|
347
|
+
const floor = dualImpl({
|
|
348
|
+
name: "floor",
|
|
349
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
350
|
+
normalImpl: cpuFloor,
|
|
351
|
+
codegenImpl: (_ctx, [arg]) => stitch`floor(${arg})`
|
|
352
|
+
});
|
|
353
|
+
function cpuFma(e1, e2, e3) {
|
|
354
|
+
if (typeof e1 === "number") return e1 * e2 + e3;
|
|
355
|
+
throw new MissingCpuImplError("CPU implementation for fma on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
|
|
356
|
+
}
|
|
357
|
+
const fma = dualImpl({
|
|
358
|
+
name: "fma",
|
|
359
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
360
|
+
normalImpl: cpuFma,
|
|
361
|
+
codegenImpl: (_ctx, [e1, e2, e3]) => stitch`fma(${e1}, ${e2}, ${e3})`
|
|
362
|
+
});
|
|
363
|
+
function cpuFract(value) {
|
|
364
|
+
if (typeof value === "number") return value - Math.floor(value);
|
|
365
|
+
return VectorOps.fract[value.kind](value);
|
|
366
|
+
}
|
|
367
|
+
const fract = dualImpl({
|
|
368
|
+
name: "fract",
|
|
369
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
370
|
+
normalImpl: cpuFract,
|
|
371
|
+
codegenImpl: (_ctx, [a]) => stitch`fract(${a})`
|
|
372
|
+
});
|
|
373
|
+
const FrexpResults = {
|
|
374
|
+
f32: abstruct({
|
|
375
|
+
fract: f32,
|
|
376
|
+
exp: i32
|
|
377
|
+
}),
|
|
378
|
+
f16: abstruct({
|
|
379
|
+
fract: f16,
|
|
380
|
+
exp: i32
|
|
381
|
+
}),
|
|
382
|
+
abstractFloat: abstruct({
|
|
383
|
+
fract: abstractFloat,
|
|
384
|
+
exp: abstractInt
|
|
385
|
+
}),
|
|
386
|
+
vec2f: abstruct({
|
|
387
|
+
fract: vec2f,
|
|
388
|
+
exp: vec2i
|
|
389
|
+
}),
|
|
390
|
+
vec3f: abstruct({
|
|
391
|
+
fract: vec3f,
|
|
392
|
+
exp: vec3i
|
|
393
|
+
}),
|
|
394
|
+
vec4f: abstruct({
|
|
395
|
+
fract: vec4f,
|
|
396
|
+
exp: vec4i
|
|
397
|
+
}),
|
|
398
|
+
vec2h: abstruct({
|
|
399
|
+
fract: vec2h,
|
|
400
|
+
exp: vec2i
|
|
401
|
+
}),
|
|
402
|
+
vec3h: abstruct({
|
|
403
|
+
fract: vec3h,
|
|
404
|
+
exp: vec3i
|
|
405
|
+
}),
|
|
406
|
+
vec4h: abstruct({
|
|
407
|
+
fract: vec4h,
|
|
408
|
+
exp: vec4i
|
|
409
|
+
})
|
|
410
|
+
};
|
|
411
|
+
const frexp = dualImpl({
|
|
412
|
+
name: "frexp",
|
|
413
|
+
normalImpl: "CPU implementation for frexp not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
414
|
+
signature: (value) => {
|
|
415
|
+
const returnType = FrexpResults[value.type];
|
|
416
|
+
if (!returnType) throw new SignatureNotSupportedError([value], anyFloat);
|
|
417
|
+
return {
|
|
418
|
+
argTypes: [value],
|
|
419
|
+
returnType
|
|
420
|
+
};
|
|
421
|
+
},
|
|
422
|
+
codegenImpl: (_ctx, [value]) => stitch`frexp(${value})`
|
|
423
|
+
});
|
|
424
|
+
const insertBits = dualImpl({
|
|
425
|
+
name: "insertBits",
|
|
426
|
+
signature: (e, newbits, _offset, _count) => {
|
|
427
|
+
const uargs = unify([e, newbits], anyConcreteInteger);
|
|
428
|
+
if (!uargs) throw new SignatureNotSupportedError([e, newbits], anyConcreteInteger);
|
|
429
|
+
return {
|
|
430
|
+
argTypes: [
|
|
431
|
+
...uargs,
|
|
432
|
+
u32,
|
|
433
|
+
u32
|
|
434
|
+
],
|
|
435
|
+
returnType: uargs[0]
|
|
436
|
+
};
|
|
437
|
+
},
|
|
438
|
+
normalImpl: "CPU implementation for insertBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
439
|
+
codegenImpl: (_ctx, [e, newbits, offset, count]) => stitch`insertBits(${e}, ${newbits}, ${offset}, ${count})`
|
|
440
|
+
});
|
|
441
|
+
function cpuInverseSqrt(value) {
|
|
442
|
+
if (typeof value === "number") return 1 / Math.sqrt(value);
|
|
443
|
+
throw new MissingCpuImplError("CPU implementation for inverseSqrt on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
|
|
444
|
+
}
|
|
445
|
+
const inverseSqrt = dualImpl({
|
|
446
|
+
name: "inverseSqrt",
|
|
447
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
448
|
+
normalImpl: cpuInverseSqrt,
|
|
449
|
+
codegenImpl: (_ctx, [value]) => stitch`inverseSqrt(${value})`
|
|
450
|
+
});
|
|
451
|
+
const ldexp = dualImpl({
|
|
452
|
+
name: "ldexp",
|
|
453
|
+
signature: (e1, _e2) => {
|
|
454
|
+
switch (e1.type) {
|
|
455
|
+
case "abstractFloat": return {
|
|
456
|
+
argTypes: [e1, abstractInt],
|
|
457
|
+
returnType: e1
|
|
458
|
+
};
|
|
459
|
+
case "f32":
|
|
460
|
+
case "f16": return {
|
|
461
|
+
argTypes: [e1, i32],
|
|
462
|
+
returnType: e1
|
|
463
|
+
};
|
|
464
|
+
case "vec2f":
|
|
465
|
+
case "vec2h": return {
|
|
466
|
+
argTypes: [e1, vec2i],
|
|
467
|
+
returnType: e1
|
|
468
|
+
};
|
|
469
|
+
case "vec3f":
|
|
470
|
+
case "vec3h": return {
|
|
471
|
+
argTypes: [e1, vec3i],
|
|
472
|
+
returnType: e1
|
|
473
|
+
};
|
|
474
|
+
case "vec4f":
|
|
475
|
+
case "vec4h": return {
|
|
476
|
+
argTypes: [e1, vec4i],
|
|
477
|
+
returnType: e1
|
|
478
|
+
};
|
|
479
|
+
default: throw new Error(`Unsupported data type for ldexp: ${e1.type}. Supported types are abstractFloat, f32, f16, vec2f, vec2h, vec3f, vec3h, vec4f, vec4h.`);
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
normalImpl: "CPU implementation for ldexp not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
483
|
+
codegenImpl: (_ctx, [e1, e2]) => stitch`ldexp(${e1}, ${e2})`
|
|
484
|
+
});
|
|
485
|
+
function cpuLength(value) {
|
|
486
|
+
if (typeof value === "number") return Math.abs(value);
|
|
487
|
+
return VectorOps.length[value.kind](value);
|
|
488
|
+
}
|
|
489
|
+
const length = dualImpl({
|
|
490
|
+
name: "length",
|
|
491
|
+
signature: (arg) => {
|
|
492
|
+
const uarg = unify([arg], anyFloat);
|
|
493
|
+
if (!uarg) throw new SignatureNotSupportedError([arg], anyFloat);
|
|
494
|
+
return {
|
|
495
|
+
argTypes: uarg,
|
|
496
|
+
returnType: isHalfPrecisionSchema(uarg[0]) ? f16 : f32
|
|
497
|
+
};
|
|
498
|
+
},
|
|
499
|
+
normalImpl: cpuLength,
|
|
500
|
+
codegenImpl: (_ctx, [arg]) => stitch`length(${arg})`
|
|
501
|
+
});
|
|
502
|
+
function cpuLog(value) {
|
|
503
|
+
if (typeof value === "number") return Math.log(value);
|
|
504
|
+
return VectorOps.log[value.kind](value);
|
|
505
|
+
}
|
|
506
|
+
const log = dualImpl({
|
|
507
|
+
name: "log",
|
|
508
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
509
|
+
normalImpl: cpuLog,
|
|
510
|
+
codegenImpl: (_ctx, [value]) => stitch`log(${value})`
|
|
511
|
+
});
|
|
512
|
+
function cpuLog2(value) {
|
|
513
|
+
if (typeof value === "number") return Math.log2(value);
|
|
514
|
+
return VectorOps.log2[value.kind](value);
|
|
515
|
+
}
|
|
516
|
+
const log2 = dualImpl({
|
|
517
|
+
name: "log2",
|
|
518
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
519
|
+
normalImpl: cpuLog2,
|
|
520
|
+
codegenImpl: (_ctx, [value]) => stitch`log2(${value})`
|
|
521
|
+
});
|
|
522
|
+
function cpuMax(a, b) {
|
|
523
|
+
if (typeof a === "number") return Math.max(a, b);
|
|
524
|
+
return VectorOps.max[a.kind](a, b);
|
|
525
|
+
}
|
|
526
|
+
const max = dualImpl({
|
|
527
|
+
name: "max",
|
|
528
|
+
signature: variadicUnifySignature,
|
|
529
|
+
normalImpl: variadicReduce(cpuMax),
|
|
530
|
+
codegenImpl: variadicStitch("max")
|
|
531
|
+
});
|
|
532
|
+
function cpuMin(a, b) {
|
|
533
|
+
if (typeof a === "number") return Math.min(a, b);
|
|
534
|
+
return VectorOps.min[a.kind](a, b);
|
|
535
|
+
}
|
|
536
|
+
const min = dualImpl({
|
|
537
|
+
name: "min",
|
|
538
|
+
signature: variadicUnifySignature,
|
|
539
|
+
normalImpl: variadicReduce(cpuMin),
|
|
540
|
+
codegenImpl: variadicStitch("min")
|
|
541
|
+
});
|
|
542
|
+
function cpuMix(e1, e2, e3) {
|
|
543
|
+
if (typeof e1 === "number") {
|
|
544
|
+
if (typeof e3 !== "number" || typeof e2 !== "number") throw new Error("When e1 and e2 are numbers, the blend factor must be a number.");
|
|
545
|
+
return e1 * (1 - e3) + e2 * e3;
|
|
546
|
+
}
|
|
547
|
+
if (typeof e1 === "number" || typeof e2 === "number") throw new Error("e1 and e2 need to both be vectors of the same kind.");
|
|
548
|
+
return VectorOps.mix[e1.kind](e1, e2, e3);
|
|
549
|
+
}
|
|
550
|
+
const mix = dualImpl({
|
|
551
|
+
name: "mix",
|
|
552
|
+
signature: (e1, e2, e3) => {
|
|
553
|
+
if (e1.type.startsWith("vec") && !e3.type.startsWith("vec")) {
|
|
554
|
+
const uarg = unify([e3], [e1.primitive]);
|
|
555
|
+
if (!uarg) throw new SignatureNotSupportedError([e3], [e1.primitive]);
|
|
556
|
+
return {
|
|
557
|
+
argTypes: [
|
|
558
|
+
e1,
|
|
559
|
+
e2,
|
|
560
|
+
uarg[0]
|
|
561
|
+
],
|
|
562
|
+
returnType: e1
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
const uargs = unify([
|
|
566
|
+
e1,
|
|
567
|
+
e2,
|
|
568
|
+
e3
|
|
569
|
+
], anyFloat);
|
|
570
|
+
if (!uargs) throw new SignatureNotSupportedError([
|
|
571
|
+
e1,
|
|
572
|
+
e2,
|
|
573
|
+
e3
|
|
574
|
+
], anyFloat);
|
|
575
|
+
return {
|
|
576
|
+
argTypes: uargs,
|
|
577
|
+
returnType: uargs[0]
|
|
578
|
+
};
|
|
579
|
+
},
|
|
580
|
+
normalImpl: cpuMix,
|
|
581
|
+
codegenImpl: (_ctx, [e1, e2, e3]) => stitch`mix(${e1}, ${e2}, ${e3})`
|
|
582
|
+
});
|
|
583
|
+
const ModfResult = {
|
|
584
|
+
f32: abstruct({
|
|
585
|
+
fract: f32,
|
|
586
|
+
whole: f32
|
|
587
|
+
}),
|
|
588
|
+
f16: abstruct({
|
|
589
|
+
fract: f16,
|
|
590
|
+
whole: f16
|
|
591
|
+
}),
|
|
592
|
+
abstractFloat: abstruct({
|
|
593
|
+
fract: abstractFloat,
|
|
594
|
+
whole: abstractFloat
|
|
595
|
+
}),
|
|
596
|
+
vec2f: abstruct({
|
|
597
|
+
fract: vec2f,
|
|
598
|
+
whole: vec2f
|
|
599
|
+
}),
|
|
600
|
+
vec3f: abstruct({
|
|
601
|
+
fract: vec3f,
|
|
602
|
+
whole: vec3f
|
|
603
|
+
}),
|
|
604
|
+
vec4f: abstruct({
|
|
605
|
+
fract: vec4f,
|
|
606
|
+
whole: vec4f
|
|
607
|
+
}),
|
|
608
|
+
vec2h: abstruct({
|
|
609
|
+
fract: vec2h,
|
|
610
|
+
whole: vec2h
|
|
611
|
+
}),
|
|
612
|
+
vec3h: abstruct({
|
|
613
|
+
fract: vec3h,
|
|
614
|
+
whole: vec3h
|
|
615
|
+
}),
|
|
616
|
+
vec4h: abstruct({
|
|
617
|
+
fract: vec4h,
|
|
618
|
+
whole: vec4h
|
|
619
|
+
})
|
|
620
|
+
};
|
|
621
|
+
const modf = dualImpl({
|
|
622
|
+
name: "modf",
|
|
623
|
+
signature: (e) => {
|
|
624
|
+
const returnType = ModfResult[e.type];
|
|
625
|
+
if (!returnType) throw new Error(`Unsupported data type for modf: ${e.type}. Supported types are f32, f16, abstractFloat, vec2f, vec3f, vec4f, vec2h, vec3h, vec4h.`);
|
|
626
|
+
return {
|
|
627
|
+
argTypes: [e],
|
|
628
|
+
returnType
|
|
629
|
+
};
|
|
630
|
+
},
|
|
631
|
+
normalImpl: "CPU implementation for modf not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
632
|
+
codegenImpl: (_ctx, [value]) => stitch`modf(${value})`
|
|
633
|
+
});
|
|
634
|
+
const normalize = dualImpl({
|
|
635
|
+
name: "normalize",
|
|
636
|
+
signature: unifyRestrictedSignature(anyFloatVec),
|
|
637
|
+
normalImpl: (v) => VectorOps.normalize[v.kind](v),
|
|
638
|
+
codegenImpl: (_ctx, [value]) => stitch`normalize(${value})`
|
|
639
|
+
});
|
|
640
|
+
function powCpu(base, exponent) {
|
|
641
|
+
if (typeof base === "number" && typeof exponent === "number") return base ** exponent;
|
|
642
|
+
if (isVecInstance(base) && isVecInstance(exponent)) return VectorOps.pow[base.kind](base, exponent);
|
|
643
|
+
throw new Error(`Invalid arguments to pow(): '${base}' '${exponent}'`);
|
|
644
|
+
}
|
|
645
|
+
const pow = dualImpl({
|
|
646
|
+
name: "pow",
|
|
647
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
648
|
+
normalImpl: powCpu,
|
|
649
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`pow(${lhs}, ${rhs})`
|
|
650
|
+
});
|
|
651
|
+
const quantizeToF16 = dualImpl({
|
|
652
|
+
name: "quantizeToF16",
|
|
653
|
+
signature: (arg) => {
|
|
654
|
+
const candidates = [
|
|
655
|
+
vec2f,
|
|
656
|
+
vec3f,
|
|
657
|
+
vec4f,
|
|
658
|
+
f32
|
|
659
|
+
];
|
|
660
|
+
const uarg = unify([arg], candidates)?.[0];
|
|
661
|
+
if (!uarg) throw new SignatureNotSupportedError([arg], candidates);
|
|
662
|
+
return {
|
|
663
|
+
argTypes: [uarg],
|
|
664
|
+
returnType: uarg
|
|
665
|
+
};
|
|
666
|
+
},
|
|
667
|
+
normalImpl: "CPU implementation for quantizeToF16 not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
668
|
+
codegenImpl: (_ctx, [value]) => stitch`quantizeToF16(${value})`
|
|
669
|
+
});
|
|
670
|
+
function cpuRadians(value) {
|
|
671
|
+
if (typeof value === "number") return value * Math.PI / 180;
|
|
672
|
+
throw new MissingCpuImplError("CPU implementation for radians on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
|
|
673
|
+
}
|
|
674
|
+
const radians = dualImpl({
|
|
675
|
+
name: "radians",
|
|
676
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
677
|
+
normalImpl: cpuRadians,
|
|
678
|
+
codegenImpl: (_ctx, [value]) => stitch`radians(${value})`
|
|
679
|
+
});
|
|
680
|
+
const reflect = dualImpl({
|
|
681
|
+
name: "reflect",
|
|
682
|
+
signature: (...args) => {
|
|
683
|
+
const uargs = unify(args, anyFloatVec);
|
|
684
|
+
if (!uargs) throw new SignatureNotSupportedError(args, anyFloatVec);
|
|
685
|
+
return {
|
|
686
|
+
argTypes: uargs,
|
|
687
|
+
returnType: uargs[0]
|
|
688
|
+
};
|
|
689
|
+
},
|
|
690
|
+
normalImpl: (e1, e2) => sub(e1, mul(2 * dot(e2, e1), e2)),
|
|
691
|
+
codegenImpl: (_ctx, [e1, e2]) => stitch`reflect(${e1}, ${e2})`
|
|
692
|
+
});
|
|
693
|
+
const refract = dualImpl({
|
|
694
|
+
name: "refract",
|
|
695
|
+
normalImpl: "CPU implementation for refract not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
696
|
+
codegenImpl: (_ctx, [e1, e2, e3]) => stitch`refract(${e1}, ${e2}, ${e3})`,
|
|
697
|
+
signature: (e1, e2, _e3) => ({
|
|
698
|
+
argTypes: [
|
|
699
|
+
e1,
|
|
700
|
+
e2,
|
|
701
|
+
isHalfPrecisionSchema(e1) ? f16 : f32
|
|
702
|
+
],
|
|
703
|
+
returnType: e1
|
|
704
|
+
})
|
|
705
|
+
});
|
|
706
|
+
const reverseBits = dualImpl({
|
|
707
|
+
name: "reverseBits",
|
|
708
|
+
signature: unifyRestrictedSignature(anyConcreteInteger),
|
|
709
|
+
normalImpl: "CPU implementation for reverseBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
710
|
+
codegenImpl: (_ctx, [value]) => stitch`reverseBits(${value})`
|
|
711
|
+
});
|
|
712
|
+
function cpuRound(value) {
|
|
713
|
+
if (typeof value === "number") {
|
|
714
|
+
const floor = Math.floor(value);
|
|
715
|
+
if (value === floor + .5) {
|
|
716
|
+
if (floor % 2 === 0) return floor;
|
|
717
|
+
return floor + 1;
|
|
718
|
+
}
|
|
719
|
+
return Math.round(value);
|
|
720
|
+
}
|
|
721
|
+
throw new MissingCpuImplError("CPU implementation for round on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
|
|
722
|
+
}
|
|
723
|
+
const round = dualImpl({
|
|
724
|
+
name: "round",
|
|
725
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
726
|
+
normalImpl: cpuRound,
|
|
727
|
+
codegenImpl: (_ctx, [value]) => stitch`round(${value})`
|
|
728
|
+
});
|
|
729
|
+
function cpuSaturate(value) {
|
|
730
|
+
if (typeof value === "number") return Math.max(0, Math.min(1, value));
|
|
731
|
+
throw new MissingCpuImplError("CPU implementation for saturate on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
|
|
732
|
+
}
|
|
733
|
+
const saturate = dualImpl({
|
|
734
|
+
name: "saturate",
|
|
735
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
736
|
+
normalImpl: cpuSaturate,
|
|
737
|
+
codegenImpl: (_ctx, [value]) => stitch`saturate(${value})`
|
|
738
|
+
});
|
|
739
|
+
function cpuSign(e) {
|
|
740
|
+
if (typeof e === "number") return Math.sign(e);
|
|
741
|
+
return VectorOps.sign[e.kind](e);
|
|
742
|
+
}
|
|
743
|
+
const sign = dualImpl({
|
|
744
|
+
name: "sign",
|
|
745
|
+
signature: (arg) => {
|
|
746
|
+
const candidates = [
|
|
747
|
+
...anyFloat,
|
|
748
|
+
i32,
|
|
749
|
+
vec2i,
|
|
750
|
+
vec3i,
|
|
751
|
+
vec4i
|
|
752
|
+
];
|
|
753
|
+
const uarg = unify([arg], candidates)?.[0];
|
|
754
|
+
if (!uarg) throw new SignatureNotSupportedError([arg], candidates);
|
|
755
|
+
return {
|
|
756
|
+
argTypes: [uarg],
|
|
757
|
+
returnType: uarg
|
|
758
|
+
};
|
|
759
|
+
},
|
|
760
|
+
normalImpl: cpuSign,
|
|
761
|
+
codegenImpl: (_ctx, [e]) => stitch`sign(${e})`
|
|
762
|
+
});
|
|
763
|
+
function cpuSin(value) {
|
|
764
|
+
if (typeof value === "number") return Math.sin(value);
|
|
765
|
+
return VectorOps.sin[value.kind](value);
|
|
766
|
+
}
|
|
767
|
+
const sin = dualImpl({
|
|
768
|
+
name: "sin",
|
|
769
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
770
|
+
normalImpl: cpuSin,
|
|
771
|
+
codegenImpl: (_ctx, [value]) => stitch`sin(${value})`
|
|
772
|
+
});
|
|
773
|
+
function cpuSinh(value) {
|
|
774
|
+
if (typeof value === "number") return Math.sinh(value);
|
|
775
|
+
throw new MissingCpuImplError("CPU implementation for sinh on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
|
|
776
|
+
}
|
|
777
|
+
const sinh = dualImpl({
|
|
778
|
+
name: "sinh",
|
|
779
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
780
|
+
normalImpl: cpuSinh,
|
|
781
|
+
codegenImpl: (_ctx, [value]) => stitch`sinh(${value})`
|
|
782
|
+
});
|
|
783
|
+
function cpuSmoothstep(edge0, edge1, x) {
|
|
784
|
+
if (typeof x === "number") return smoothstepScalar(edge0, edge1, x);
|
|
785
|
+
return VectorOps.smoothstep[x.kind](edge0, edge1, x);
|
|
786
|
+
}
|
|
787
|
+
const smoothstep = dualImpl({
|
|
788
|
+
name: "smoothstep",
|
|
789
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
790
|
+
normalImpl: cpuSmoothstep,
|
|
791
|
+
codegenImpl: (_ctx, [edge0, edge1, x]) => stitch`smoothstep(${edge0}, ${edge1}, ${x})`
|
|
792
|
+
});
|
|
793
|
+
function cpuSqrt(value) {
|
|
794
|
+
if (typeof value === "number") return Math.sqrt(value);
|
|
795
|
+
return VectorOps.sqrt[value.kind](value);
|
|
796
|
+
}
|
|
797
|
+
const sqrt = dualImpl({
|
|
798
|
+
name: "sqrt",
|
|
799
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
800
|
+
normalImpl: cpuSqrt,
|
|
801
|
+
codegenImpl: (_ctx, [value]) => stitch`sqrt(${value})`
|
|
802
|
+
});
|
|
803
|
+
function cpuStep(edge, x) {
|
|
804
|
+
if (typeof edge === "number") return edge <= x ? 1 : 0;
|
|
805
|
+
throw new MissingCpuImplError("CPU implementation for step on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
|
|
806
|
+
}
|
|
807
|
+
const step = dualImpl({
|
|
808
|
+
name: "step",
|
|
809
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
810
|
+
normalImpl: cpuStep,
|
|
811
|
+
codegenImpl: (_ctx, [edge, x]) => stitch`step(${edge}, ${x})`
|
|
812
|
+
});
|
|
813
|
+
function cpuTan(value) {
|
|
814
|
+
if (typeof value === "number") return Math.tan(value);
|
|
815
|
+
throw new MissingCpuImplError("CPU implementation for tan on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
|
|
816
|
+
}
|
|
817
|
+
const tan = dualImpl({
|
|
818
|
+
name: "tan",
|
|
819
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
820
|
+
normalImpl: cpuTan,
|
|
821
|
+
codegenImpl: (_ctx, [value]) => stitch`tan(${value})`
|
|
822
|
+
});
|
|
823
|
+
function cpuTanh(value) {
|
|
824
|
+
if (typeof value === "number") return Math.tanh(value);
|
|
825
|
+
return VectorOps.tanh[value.kind](value);
|
|
826
|
+
}
|
|
827
|
+
const tanh = dualImpl({
|
|
828
|
+
name: "tanh",
|
|
829
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
830
|
+
normalImpl: cpuTanh,
|
|
831
|
+
codegenImpl: (_ctx, [value]) => stitch`tanh(${value})`
|
|
832
|
+
});
|
|
833
|
+
const transpose = dualImpl({
|
|
834
|
+
name: "transpose",
|
|
835
|
+
signature: unaryIdentitySignature,
|
|
836
|
+
normalImpl: "CPU implementation for transpose not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
837
|
+
codegenImpl: (_ctx, [e]) => stitch`transpose(${e})`
|
|
838
|
+
});
|
|
839
|
+
const trunc = dualImpl({
|
|
840
|
+
name: "trunc",
|
|
841
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
842
|
+
normalImpl: "CPU implementation for trunc not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
843
|
+
codegenImpl: (_ctx, [value]) => stitch`trunc(${value})`
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
//#endregion
|
|
847
|
+
export { abs, acos, acosh, asin, asinh, atan, atan2, atanh, ceil, clamp, cos, cosh, countLeadingZeros, countOneBits, countTrailingZeros, cross, degrees, determinant, distance, dot, dot4I8Packed, dot4U8Packed, exp, exp2, extractBits, faceForward, firstLeadingBit, firstTrailingBit, floor, fma, fract, frexp, insertBits, inverseSqrt, ldexp, length, log, log2, max, min, mix, modf, normalize, pow, quantizeToF16, radians, reflect, refract, reverseBits, round, saturate, sign, sin, sinh, smoothstep, sqrt, step, tan, tanh, transpose, trunc };
|