typegpu 0.11.9 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.mjs +28 -6
- package/builtin.d.ts +51 -53
- package/builtin.js +30 -34
- package/common/fullScreenTriangle.d.ts +2 -10
- package/common/fullScreenTriangle.js +20 -28
- package/common/index.d.ts +2 -9
- package/common/index.js +3 -12
- package/common/writeSoA.d.ts +11 -12
- package/common/writeSoA.js +88 -76
- package/core/buffer/buffer.d.ts +79 -62
- package/core/buffer/buffer.js +283 -205
- package/core/buffer/bufferBinding.d.ts +71 -0
- package/core/buffer/bufferBinding.js +154 -0
- package/core/buffer/bufferUsage.d.ts +14 -45
- package/core/buffer/bufferUsage.js +1 -171
- package/core/buffer/laidOutBuffer.d.ts +25 -0
- package/core/buffer/laidOutBuffer.js +55 -0
- package/core/commandEncoder/attachments.d.ts +125 -0
- package/core/commandEncoder/attachments.js +29 -0
- package/core/commandEncoder/commandEncoder.d.ts +53 -0
- package/core/commandEncoder/commandEncoder.js +56 -0
- package/core/commandEncoder/computePass.d.ts +58 -0
- package/core/commandEncoder/computePass.js +63 -0
- package/core/commandEncoder/renderPass.d.ts +121 -0
- package/core/commandEncoder/renderPass.js +196 -0
- package/core/constant/tgpuConstant.d.ts +26 -26
- package/core/constant/tgpuConstant.js +76 -65
- package/core/declare/tgpuDeclare.d.ts +3 -6
- package/core/declare/tgpuDeclare.js +36 -36
- package/core/function/autoIO.d.ts +61 -33
- package/core/function/autoIO.js +68 -73
- package/core/function/comptime.d.ts +11 -13
- package/core/function/comptime.js +60 -52
- package/core/function/createCallableSchema.d.ts +16 -0
- package/core/function/createCallableSchema.js +50 -40
- package/core/function/dualImpl.d.ts +44 -0
- package/core/function/dualImpl.js +71 -50
- package/core/function/entryInputRouter.d.ts +26 -0
- package/core/function/entryInputRouter.js +31 -33
- package/core/function/extractArgs.d.ts +38 -0
- package/core/function/extractArgs.js +202 -200
- package/core/function/fnCore.d.ts +44 -5
- package/core/function/fnCore.js +148 -93
- package/core/function/fnTypes.d.ts +31 -29
- package/core/function/fnTypes.js +1 -0
- package/core/function/ioSchema.d.ts +12 -10
- package/core/function/ioSchema.js +65 -47
- package/core/function/shelllessImpl.d.ts +9 -12
- package/core/function/shelllessImpl.js +17 -22
- package/core/function/templateUtils.d.ts +2 -0
- package/core/function/templateUtils.js +9 -8
- package/core/function/tgpuComputeFn.d.ts +26 -28
- package/core/function/tgpuComputeFn.js +47 -48
- package/core/function/tgpuFn.d.ts +34 -37
- package/core/function/tgpuFn.js +179 -153
- package/core/function/tgpuFragmentFn.d.ts +52 -53
- package/core/function/tgpuFragmentFn.js +63 -56
- package/core/function/tgpuVertexFn.d.ts +36 -39
- package/core/function/tgpuVertexFn.js +56 -53
- package/core/pipeline/computePipeline.d.ts +141 -53
- package/core/pipeline/computePipeline.js +291 -225
- package/core/pipeline/connectAttachmentToShader.d.ts +4 -0
- package/core/pipeline/connectAttachmentToShader.js +25 -22
- package/core/pipeline/connectTargetsToShader.d.ts +3 -0
- package/core/pipeline/connectTargetsToShader.js +29 -27
- package/core/pipeline/drawState.d.ts +52 -0
- package/core/pipeline/drawState.js +225 -0
- package/core/pipeline/performanceTracker.d.ts +14 -0
- package/core/pipeline/performanceTracker.js +34 -0
- package/core/pipeline/pipelineUtils.d.ts +18 -0
- package/core/pipeline/pipelineUtils.js +54 -25
- package/core/pipeline/priors.d.ts +1 -0
- package/core/pipeline/priors.js +12 -0
- package/core/pipeline/renderPipeline.d.ts +246 -261
- package/core/pipeline/renderPipeline.js +487 -480
- package/core/pipeline/timeable.d.ts +28 -18
- package/core/pipeline/timeable.js +90 -52
- package/core/pipeline/typeGuards.d.ts +17 -0
- package/core/pipeline/typeGuards.js +52 -22
- package/core/pipeline/webgpuLimitations.d.ts +10 -0
- package/core/pipeline/webgpuLimitations.js +81 -0
- package/core/querySet/querySet.d.ts +26 -21
- package/core/querySet/querySet.js +127 -103
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +13 -18
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +89 -90
- package/core/resolve/externals.d.ts +25 -8
- package/core/resolve/externals.js +78 -54
- package/core/resolve/namespace.d.ts +22 -25
- package/core/resolve/namespace.js +16 -21
- package/core/resolve/resolvableString.d.ts +7 -0
- package/core/resolve/resolvableString.js +13 -0
- package/core/resolve/resolveData.d.ts +10 -0
- package/core/resolve/resolveData.js +162 -121
- package/core/resolve/stitch.d.ts +8 -0
- package/core/resolve/stitch.js +23 -21
- package/core/resolve/tgpuResolve.d.ts +55 -53
- package/core/resolve/tgpuResolve.js +106 -53
- package/core/root/configurableImpl.d.ts +10 -0
- package/core/root/configurableImpl.js +17 -19
- package/core/root/init.d.ts +76 -38
- package/core/root/init.js +346 -455
- package/core/root/rootTypes.d.ts +461 -636
- package/core/root/rootTypes.js +1 -0
- package/core/sampler/sampler.d.ts +50 -31
- package/core/sampler/sampler.js +120 -113
- package/core/simulate/tgpuSimulate.d.ts +9 -12
- package/core/simulate/tgpuSimulate.js +68 -71
- package/core/slot/accessor.d.ts +36 -13
- package/core/slot/accessor.js +138 -91
- package/core/slot/internalSlots.d.ts +2 -0
- package/core/slot/internalSlots.js +1 -6
- package/core/slot/lazy.d.ts +2 -6
- package/core/slot/lazy.js +71 -39
- package/core/slot/slot.d.ts +2 -6
- package/core/slot/slot.js +45 -38
- package/core/slot/slotTypes.d.ts +78 -80
- package/core/slot/slotTypes.js +11 -16
- package/core/texture/externalTexture.d.ts +20 -11
- package/core/texture/externalTexture.js +46 -46
- package/core/texture/texture.d.ts +152 -97
- package/core/texture/texture.js +407 -314
- package/core/texture/textureFormats.d.ts +42 -23
- package/core/texture/textureFormats.js +104 -75
- package/core/texture/textureProps.d.ts +7 -10
- package/core/texture/textureProps.js +1 -0
- package/core/texture/textureUtils.d.ts +8 -0
- package/core/texture/textureUtils.js +185 -179
- package/core/texture/usageExtension.d.ts +21 -18
- package/core/texture/usageExtension.js +13 -17
- package/core/unroll/tgpuUnroll.d.ts +20 -19
- package/core/unroll/tgpuUnroll.js +82 -91
- package/core/valueProxyUtils.d.ts +3 -0
- package/core/valueProxyUtils.js +52 -41
- package/core/variable/tgpuVariable.d.ts +26 -27
- package/core/variable/tgpuVariable.js +93 -96
- package/core/vertexLayout/connectAttributesToShader.d.ts +9 -0
- package/core/vertexLayout/connectAttributesToShader.js +61 -56
- package/core/vertexLayout/vertexAttribute.d.ts +21 -17
- package/core/vertexLayout/vertexAttribute.js +1 -0
- package/core/vertexLayout/vertexLayout.d.ts +24 -18
- package/core/vertexLayout/vertexLayout.js +130 -99
- package/core/whitespaces.d.ts +2 -0
- package/core/whitespaces.js +16 -0
- package/data/alignIO.d.ts +7 -0
- package/data/alignIO.js +13 -13
- package/data/alignmentOf.d.ts +5 -8
- package/data/alignmentOf.js +90 -75
- package/data/array.d.ts +17 -9
- package/data/array.js +57 -40
- package/data/atomic.d.ts +2 -7
- package/data/atomic.js +26 -23
- package/data/attributes.d.ts +19 -21
- package/data/attributes.js +192 -132
- package/data/autoStruct.d.ts +36 -3
- package/data/autoStruct.js +84 -81
- package/data/compiledIO.d.ts +5 -0
- package/data/compiledIO.js +231 -215
- package/data/dataIO.d.ts +13 -11
- package/data/dataIO.js +643 -589
- package/data/dataTypes.d.ts +83 -65
- package/data/dataTypes.js +66 -68
- package/data/deepEqual.d.ts +2 -7
- package/data/deepEqual.js +80 -55
- package/data/disarray.d.ts +6 -10
- package/data/disarray.js +52 -46
- package/data/float16Conversion.d.ts +4 -0
- package/data/float16Conversion.js +7 -0
- package/data/generalizeFn.d.ts +25 -0
- package/data/generalizeFn.js +89 -0
- package/data/getLongestContiguousPrefix.d.ts +4 -8
- package/data/getLongestContiguousPrefix.js +6 -11
- package/data/index.d.ts +30 -31
- package/data/index.js +39 -172
- package/data/instanceToSchema.d.ts +24 -27
- package/data/instanceToSchema.js +1 -0
- package/data/isContiguous.d.ts +4 -8
- package/data/isContiguous.js +6 -11
- package/data/matrix.d.ts +21 -21
- package/data/matrix.js +513 -505
- package/data/numberOps.d.ts +5 -0
- package/data/numberOps.js +21 -21
- package/data/numeric.d.ts +21 -12
- package/data/numeric.js +287 -197
- package/data/offsetUtils.d.ts +9 -13
- package/data/offsetUtils.js +204 -144
- package/data/offsets.d.ts +8 -0
- package/data/offsets.js +33 -33
- package/data/partialIO.d.ts +13 -8
- package/data/partialIO.js +124 -113
- package/data/ptr.d.ts +12 -12
- package/data/ptr.js +42 -44
- package/data/ref.d.ts +40 -27
- package/data/ref.js +125 -95
- package/data/sampler.d.ts +99 -101
- package/data/sampler.js +17 -21
- package/data/schemaCallWrapper.d.ts +19 -0
- package/data/schemaCallWrapper.js +31 -26
- package/data/schemaMemoryLayout.d.ts +8 -0
- package/data/schemaMemoryLayout.js +213 -185
- package/data/sizeOf.d.ts +4 -8
- package/data/sizeOf.js +6 -11
- package/data/snippet.d.ts +96 -20
- package/data/snippet.js +75 -86
- package/data/struct.d.ts +4 -7
- package/data/struct.js +51 -39
- package/data/texture.d.ts +253 -250
- package/data/texture.js +238 -200
- package/data/unstruct.d.ts +2 -7
- package/data/unstruct.js +43 -37
- package/data/vector.d.ts +33 -21
- package/data/vector.js +234 -221
- package/data/vectorImpl.d.ts +231 -0
- package/data/vectorImpl.js +563 -515
- package/data/vectorOps.d.ts +25 -0
- package/data/vectorOps.js +118 -669
- package/data/vertexFormatData.d.ts +181 -184
- package/data/vertexFormatData.js +104 -106
- package/data/wgslTypes.d.ts +665 -600
- package/data/wgslTypes.js +220 -198
- package/errors.d.ts +50 -24
- package/errors.js +146 -126
- package/execMode.d.ts +16 -0
- package/execMode.js +47 -40
- package/extension.d.ts +13 -8
- package/extension.js +10 -16
- package/getGPUValue.d.ts +1 -0
- package/getGPUValue.js +2 -7
- package/index.d.ts +28 -68
- package/index.js +8 -28
- package/indexNamedExports.d.ts +69 -42
- package/indexNamedExports.js +25 -0
- package/internal.d.ts +16 -0
- package/internal.js +12 -0
- package/mathUtils.d.ts +5 -0
- package/mathUtils.js +7 -11
- package/memo.d.ts +11 -0
- package/memo.js +20 -22
- package/minify.d.ts +5 -0
- package/minify.js +93 -0
- package/nameUtils.d.ts +29 -0
- package/nameUtils.js +427 -394
- package/package.json +5 -1
- package/resolutionCtx.d.ts +162 -22
- package/resolutionCtx.js +911 -629
- package/serial/registry.d.ts +15 -0
- package/serial/registry.js +106 -0
- package/serial/restore.d.ts +49 -0
- package/serial/restore.js +68 -0
- package/serial/schema.d.ts +58 -0
- package/serial/schema.js +209 -0
- package/serial/types.d.ts +5 -0
- package/serial/types.js +1 -0
- package/shared/env.d.ts +9 -0
- package/shared/env.js +9 -12
- package/shared/generators.d.ts +4 -0
- package/shared/generators.js +10 -12
- package/shared/meta.d.ts +29 -14
- package/shared/meta.js +71 -55
- package/shared/normalizeMetadata.d.ts +32 -27
- package/shared/normalizeMetadata.js +23 -36
- package/shared/repr.d.ts +73 -55
- package/shared/repr.js +1 -0
- package/shared/soul.d.ts +17 -0
- package/shared/soul.js +1 -0
- package/shared/stringify.d.ts +2 -0
- package/shared/stringify.js +29 -20
- package/shared/symbols.d.ts +26 -20
- package/shared/symbols.js +79 -79
- package/shared/tseynit.d.ts +2 -0
- package/shared/tseynit.js +160 -75
- package/shared/utilityTypes.d.ts +30 -14
- package/shared/utilityTypes.js +2 -6
- package/shared/vertexFormat.d.ts +41 -43
- package/shared/vertexFormat.js +59 -62
- package/std/array.d.ts +2 -7
- package/std/array.js +18 -23
- package/std/atomic.d.ts +14 -18
- package/std/atomic.js +96 -95
- package/std/bitcast.d.ts +193 -10
- package/std/bitcast.js +309 -39
- package/std/boolean.d.ts +19 -33
- package/std/boolean.js +296 -292
- package/std/copy.d.ts +2 -7
- package/std/copy.js +27 -24
- package/std/derivative.d.ts +11 -15
- package/std/derivative.js +56 -79
- package/std/discard.d.ts +1 -6
- package/std/discard.js +7 -14
- package/std/environment.d.ts +19 -14
- package/std/environment.js +71 -51
- package/std/extensions.d.ts +2 -8
- package/std/extensions.js +10 -11
- package/std/index.d.ts +20 -24
- package/std/index.js +32 -187
- package/std/matrix.d.ts +6 -12
- package/std/matrix.js +60 -69
- package/std/numeric.d.ts +150 -146
- package/std/numeric.js +771 -727
- package/std/operators.d.ts +19 -27
- package/std/operators.js +195 -194
- package/std/packing.d.ts +5 -11
- package/std/packing.js +67 -75
- package/std/range.d.ts +6 -11
- package/std/range.js +48 -36
- package/std/subgroup.d.ts +33 -37
- package/std/subgroup.js +180 -217
- package/std/texture.d.ts +70 -38
- package/std/texture.js +176 -172
- package/taskQueue.d.ts +6 -0
- package/taskQueue.js +30 -0
- package/tgpu.d.ts +16 -0
- package/tgpu.js +17 -44
- package/tgpuBindGroupLayout.d.ts +132 -152
- package/tgpuBindGroupLayout.js +346 -268
- package/tgpuLogger.d.ts +34 -0
- package/tgpuLogger.js +64 -0
- package/tgpuUnstable.d.ts +16 -22
- package/tgpuUnstable.js +13 -35
- package/tgsl/accessIndex.d.ts +2 -0
- package/tgsl/accessIndex.js +76 -33
- package/tgsl/accessProp.d.ts +2 -0
- package/tgsl/accessProp.js +142 -101
- package/tgsl/accessStructProp.d.ts +5 -0
- package/tgsl/accessStructProp.js +13 -15
- package/tgsl/consoleLog/deserializers.d.ts +13 -0
- package/tgsl/consoleLog/deserializers.js +119 -103
- package/tgsl/consoleLog/logGenerator.d.ts +21 -0
- package/tgsl/consoleLog/logGenerator.js +85 -80
- package/tgsl/consoleLog/serializers.d.ts +21 -0
- package/tgsl/consoleLog/serializers.js +119 -100
- package/tgsl/consoleLog/types.d.ts +40 -39
- package/tgsl/consoleLog/types.js +1 -0
- package/tgsl/conversion.d.ts +33 -0
- package/tgsl/conversion.js +271 -216
- package/tgsl/forOfUtils.d.ts +15 -0
- package/tgsl/forOfUtils.js +85 -70
- package/tgsl/generationHelpers.d.ts +22 -39
- package/tgsl/generationHelpers.js +85 -58
- package/tgsl/infixDispatch.d.ts +70 -0
- package/tgsl/infixDispatch.js +48 -46
- package/tgsl/jsPolyfills.d.ts +16 -19
- package/tgsl/jsPolyfills.js +44 -42
- package/tgsl/makeDereferenceable.d.ts +48 -0
- package/tgsl/makeDereferenceable.js +86 -0
- package/tgsl/makeResolvable.d.ts +22 -0
- package/tgsl/makeResolvable.js +33 -0
- package/tgsl/shaderGenerator.d.ts +77 -17
- package/tgsl/shaderGenerator.js +1 -0
- package/tgsl/shellless.d.ts +6 -9
- package/tgsl/shellless.js +73 -43
- package/tgsl/wgslGenerator.d.ts +66 -59
- package/tgsl/wgslGenerator.js +1345 -760
- package/types.d.ts +287 -222
- package/types.js +61 -44
- package/unwrapper.d.ts +31 -26
- package/unwrapper.js +1 -0
- package/wgslExtensions.d.ts +3 -5
- package/wgslExtensions.js +12 -16
- package/_virtual/rolldown_runtime.js +0 -13
- package/core/buffer/bufferShorthand.d.ts +0 -50
- package/core/buffer/bufferShorthand.js +0 -55
- package/core/pipeline/applyPipelineState.js +0 -37
- package/core/pipeline/limitsOverflow.js +0 -13
- package/package.js +0 -5
- package/tgsl/shaderGenerator_members.d.ts +0 -33
- package/tgsl/shaderGenerator_members.js +0 -12
package/std/numeric.js
CHANGED
|
@@ -1,847 +1,891 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SignatureNotSupportedError } from "../errors.js";
|
|
1
|
+
import { dualImpl, MissingCpuImplError } from "../core/function/dualImpl.js";
|
|
3
2
|
import { stitch } from "../core/resolve/stitch.js";
|
|
4
|
-
import {
|
|
3
|
+
import { mat2x2f, mat3x3f, mat4x4f } from "../data/matrix.js";
|
|
4
|
+
import { clampScalar, smoothstepScalar } from "../data/numberOps.js";
|
|
5
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
6
|
import { abstruct } from "../data/struct.js";
|
|
8
|
-
import {
|
|
9
|
-
import { mat2x2f, mat3x3f, mat4x4f } from "../data/matrix.js";
|
|
10
|
-
import { smoothstepScalar } from "../data/numberOps.js";
|
|
7
|
+
import { vec2f, vec2h, vec2i, vec2u, vec3f, vec3h, vec3i, vec3u, vec4f, vec4h, vec4i, vec4u, } from "../data/vector.js";
|
|
11
8
|
import { VectorOps } from "../data/vectorOps.js";
|
|
9
|
+
import { generalizeFn, upCast } from "../data/generalizeFn.js";
|
|
10
|
+
import { isHalfPrecisionSchema, WORKAROUND_getSchema, } from "../data/wgslTypes.js";
|
|
11
|
+
import { SignatureNotSupportedError } from "../errors.js";
|
|
12
|
+
import { assertExhaustive } from "../shared/utilityTypes.js";
|
|
13
|
+
import { unify } from "../tgsl/conversion.js";
|
|
12
14
|
import { mul, sub } from "./operators.js";
|
|
13
|
-
|
|
14
|
-
//#region src/std/numeric.ts
|
|
15
|
+
// helpers
|
|
15
16
|
const unaryIdentitySignature = (arg) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
return {
|
|
18
|
+
argTypes: [arg],
|
|
19
|
+
returnType: arg,
|
|
20
|
+
};
|
|
20
21
|
};
|
|
21
22
|
const variadicUnifySignature = (...args) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const uargs = unify(args) ?? args;
|
|
24
|
+
return {
|
|
25
|
+
argTypes: uargs,
|
|
26
|
+
returnType: uargs[0],
|
|
27
|
+
};
|
|
27
28
|
};
|
|
28
29
|
const unifyRestrictedSignature = (restrict) => (...args) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
const uargs = unify(args, restrict);
|
|
31
|
+
if (!uargs) {
|
|
32
|
+
throw new SignatureNotSupportedError(args, restrict);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
argTypes: uargs,
|
|
36
|
+
returnType: uargs[0],
|
|
37
|
+
};
|
|
35
38
|
};
|
|
36
39
|
function variadicReduce(fn) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
return (fst, ...rest) => {
|
|
41
|
+
let acc = fst;
|
|
42
|
+
for (const r of rest) {
|
|
43
|
+
acc = fn(acc, r);
|
|
44
|
+
}
|
|
45
|
+
return acc;
|
|
46
|
+
};
|
|
42
47
|
}
|
|
43
48
|
function variadicStitch(wrapper) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
];
|
|
55
|
-
const anyFloatVec = [
|
|
56
|
-
vec2f,
|
|
57
|
-
vec3f,
|
|
58
|
-
vec4f,
|
|
59
|
-
vec2h,
|
|
60
|
-
vec3h,
|
|
61
|
-
vec4h
|
|
62
|
-
];
|
|
49
|
+
return (_ctx, [fst, ...rest]) => {
|
|
50
|
+
let acc = stitch `${fst}`;
|
|
51
|
+
for (const r of rest) {
|
|
52
|
+
acc = stitch `${wrapper}(${acc}, ${r})`;
|
|
53
|
+
}
|
|
54
|
+
return acc;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const anyFloatPrimitive = [f32, f16, abstractFloat];
|
|
58
|
+
const anyFloatVec = [vec2f, vec3f, vec4f, vec2h, vec3h, vec4h];
|
|
63
59
|
const anyFloat = [...anyFloatPrimitive, ...anyFloatVec];
|
|
64
60
|
const anyConcreteIntegerPrimitive = [i32, u32];
|
|
65
|
-
const anyConcreteIntegerVec = [
|
|
66
|
-
vec2i,
|
|
67
|
-
vec3i,
|
|
68
|
-
vec4i,
|
|
69
|
-
vec2u,
|
|
70
|
-
vec3u,
|
|
71
|
-
vec4u
|
|
72
|
-
];
|
|
61
|
+
const anyConcreteIntegerVec = [vec2i, vec3i, vec4i, vec2u, vec3u, vec4u];
|
|
73
62
|
const anyConcreteInteger = [...anyConcreteIntegerPrimitive, ...anyConcreteIntegerVec];
|
|
74
63
|
function cpuAbs(value) {
|
|
75
|
-
|
|
76
|
-
return VectorOps.abs[value.kind](value);
|
|
64
|
+
return generalizeFn(Math.abs, [value]);
|
|
77
65
|
}
|
|
78
|
-
const abs = dualImpl({
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
66
|
+
export const abs = dualImpl({
|
|
67
|
+
name: 'abs',
|
|
68
|
+
signature: unaryIdentitySignature,
|
|
69
|
+
normalImpl: cpuAbs,
|
|
70
|
+
codegenImpl: (_ctx, [value]) => stitch `abs(${value})`,
|
|
71
|
+
sideEffects: false,
|
|
83
72
|
});
|
|
84
73
|
function cpuAcos(value) {
|
|
85
|
-
|
|
86
|
-
return VectorOps.acos[value.kind](value);
|
|
74
|
+
return generalizeFn(Math.acos, [value]);
|
|
87
75
|
}
|
|
88
|
-
const acos = dualImpl({
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
76
|
+
export const acos = dualImpl({
|
|
77
|
+
name: 'acos',
|
|
78
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
79
|
+
normalImpl: cpuAcos,
|
|
80
|
+
codegenImpl: (_ctx, [value]) => stitch `acos(${value})`,
|
|
81
|
+
sideEffects: false,
|
|
93
82
|
});
|
|
94
83
|
function cpuAcosh(value) {
|
|
95
|
-
|
|
96
|
-
return VectorOps.acosh[value.kind](value);
|
|
84
|
+
return generalizeFn(Math.acosh, [value]);
|
|
97
85
|
}
|
|
98
|
-
const acosh = dualImpl({
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
86
|
+
export const acosh = dualImpl({
|
|
87
|
+
name: 'acosh',
|
|
88
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
89
|
+
normalImpl: cpuAcosh,
|
|
90
|
+
codegenImpl: (_ctx, [value]) => stitch `acosh(${value})`,
|
|
91
|
+
sideEffects: false,
|
|
103
92
|
});
|
|
104
93
|
function cpuAsin(value) {
|
|
105
|
-
|
|
106
|
-
return VectorOps.asin[value.kind](value);
|
|
94
|
+
return generalizeFn(Math.asin, [value]);
|
|
107
95
|
}
|
|
108
|
-
const asin = dualImpl({
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
96
|
+
export const asin = dualImpl({
|
|
97
|
+
name: 'asin',
|
|
98
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
99
|
+
normalImpl: cpuAsin,
|
|
100
|
+
codegenImpl: (_ctx, [value]) => stitch `asin(${value})`,
|
|
101
|
+
sideEffects: false,
|
|
113
102
|
});
|
|
114
103
|
function cpuAsinh(value) {
|
|
115
|
-
|
|
116
|
-
return VectorOps.asinh[value.kind](value);
|
|
104
|
+
return generalizeFn(Math.asinh, [value]);
|
|
117
105
|
}
|
|
118
|
-
const asinh = dualImpl({
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
106
|
+
export const asinh = dualImpl({
|
|
107
|
+
name: 'asinh',
|
|
108
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
109
|
+
normalImpl: cpuAsinh,
|
|
110
|
+
codegenImpl: (_ctx, [value]) => stitch `asinh(${value})`,
|
|
111
|
+
sideEffects: false,
|
|
123
112
|
});
|
|
124
113
|
function cpuAtan(value) {
|
|
125
|
-
|
|
126
|
-
return VectorOps.atan[value.kind](value);
|
|
114
|
+
return generalizeFn(Math.atan, [value]);
|
|
127
115
|
}
|
|
128
|
-
const atan = dualImpl({
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
116
|
+
export const atan = dualImpl({
|
|
117
|
+
name: 'atan',
|
|
118
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
119
|
+
normalImpl: cpuAtan,
|
|
120
|
+
codegenImpl: (_ctx, [value]) => stitch `atan(${value})`,
|
|
121
|
+
sideEffects: false,
|
|
133
122
|
});
|
|
134
123
|
function cpuAtanh(value) {
|
|
135
|
-
|
|
136
|
-
return VectorOps.atanh[value.kind](value);
|
|
124
|
+
return generalizeFn(Math.atanh, [value]);
|
|
137
125
|
}
|
|
138
|
-
const atanh = dualImpl({
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
126
|
+
export const atanh = dualImpl({
|
|
127
|
+
name: 'atanh',
|
|
128
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
129
|
+
normalImpl: cpuAtanh,
|
|
130
|
+
codegenImpl: (_ctx, [value]) => stitch `atanh(${value})`,
|
|
131
|
+
sideEffects: false,
|
|
143
132
|
});
|
|
144
133
|
function cpuAtan2(y, x) {
|
|
145
|
-
|
|
146
|
-
return VectorOps.atan2[y.kind](y, x);
|
|
134
|
+
return generalizeFn(Math.atan2, [y, x]);
|
|
147
135
|
}
|
|
148
|
-
const atan2 = dualImpl({
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
136
|
+
export const atan2 = dualImpl({
|
|
137
|
+
name: 'atan2',
|
|
138
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
139
|
+
normalImpl: cpuAtan2,
|
|
140
|
+
codegenImpl: (_ctx, [y, x]) => stitch `atan2(${y}, ${x})`,
|
|
141
|
+
sideEffects: false,
|
|
153
142
|
});
|
|
154
143
|
function cpuCeil(value) {
|
|
155
|
-
|
|
156
|
-
return VectorOps.ceil[value.kind](value);
|
|
144
|
+
return generalizeFn(Math.ceil, [value]);
|
|
157
145
|
}
|
|
158
|
-
const ceil = dualImpl({
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
146
|
+
export const ceil = dualImpl({
|
|
147
|
+
name: 'ceil',
|
|
148
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
149
|
+
normalImpl: cpuCeil,
|
|
150
|
+
codegenImpl: (_ctx, [value]) => stitch `ceil(${value})`,
|
|
151
|
+
sideEffects: false,
|
|
163
152
|
});
|
|
164
153
|
function cpuClamp(value, low, high) {
|
|
165
|
-
|
|
166
|
-
return VectorOps.clamp[value.kind](value, low, high);
|
|
154
|
+
return generalizeFn(clampScalar, [value, low, high]);
|
|
167
155
|
}
|
|
168
|
-
const clamp = dualImpl({
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
156
|
+
export const clamp = dualImpl({
|
|
157
|
+
name: 'clamp',
|
|
158
|
+
signature: variadicUnifySignature,
|
|
159
|
+
normalImpl: cpuClamp,
|
|
160
|
+
codegenImpl: (_ctx, [value, low, high]) => stitch `clamp(${value}, ${low}, ${high})`,
|
|
161
|
+
sideEffects: false,
|
|
173
162
|
});
|
|
174
163
|
function cpuCos(value) {
|
|
175
|
-
|
|
176
|
-
return VectorOps.cos[value.kind](value);
|
|
164
|
+
return generalizeFn(Math.cos, [value]);
|
|
177
165
|
}
|
|
178
|
-
const cos = dualImpl({
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
166
|
+
export const cos = dualImpl({
|
|
167
|
+
name: 'cos',
|
|
168
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
169
|
+
normalImpl: cpuCos,
|
|
170
|
+
codegenImpl: (_ctx, [value]) => stitch `cos(${value})`,
|
|
171
|
+
sideEffects: false,
|
|
183
172
|
});
|
|
184
173
|
function cpuCosh(value) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
174
|
+
return generalizeFn(Math.cosh, [value]);
|
|
175
|
+
}
|
|
176
|
+
export const cosh = dualImpl({
|
|
177
|
+
name: 'cosh',
|
|
178
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
179
|
+
normalImpl: cpuCosh,
|
|
180
|
+
codegenImpl: (_ctx, [value]) => stitch `cosh(${value})`,
|
|
181
|
+
sideEffects: false,
|
|
182
|
+
});
|
|
183
|
+
function cpuCountLeadingZeros(_value) {
|
|
184
|
+
throw new Error('Unreachable code. The function is only used for the type.');
|
|
185
|
+
}
|
|
186
|
+
export const countLeadingZeros = dualImpl({
|
|
187
|
+
name: 'countLeadingZeros',
|
|
188
|
+
signature: unifyRestrictedSignature(anyConcreteInteger),
|
|
189
|
+
normalImpl: 'CPU implementation for countLeadingZeros not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
190
|
+
codegenImpl: (_ctx, [value]) => stitch `countLeadingZeros(${value})`,
|
|
191
|
+
sideEffects: false,
|
|
192
|
+
});
|
|
193
|
+
function cpuCountOneBits(_value) {
|
|
194
|
+
throw new Error('Unreachable code. The function is only used for the type.');
|
|
195
|
+
}
|
|
196
|
+
export const countOneBits = dualImpl({
|
|
197
|
+
name: 'countOneBits',
|
|
198
|
+
signature: unifyRestrictedSignature(anyConcreteInteger),
|
|
199
|
+
normalImpl: 'CPU implementation for countOneBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
200
|
+
codegenImpl: (_ctx, [value]) => stitch `countOneBits(${value})`,
|
|
201
|
+
sideEffects: false,
|
|
202
|
+
});
|
|
203
|
+
function cpuCountTrailingZeros(_value) {
|
|
204
|
+
throw new Error('Unreachable code. The function is only used for the type.');
|
|
205
|
+
}
|
|
206
|
+
export 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
|
+
sideEffects: false,
|
|
212
|
+
});
|
|
213
|
+
export const cross = dualImpl({
|
|
214
|
+
name: 'cross',
|
|
215
|
+
signature: unifyRestrictedSignature([vec3f, vec3h]),
|
|
216
|
+
normalImpl: (a, b) => VectorOps.cross[a.kind](a, b),
|
|
217
|
+
codegenImpl: (_ctx, [a, b]) => stitch `cross(${a}, ${b})`,
|
|
218
|
+
sideEffects: false,
|
|
217
219
|
});
|
|
218
220
|
function cpuDegrees(value) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
codegenImpl: (_ctx, [value]) => stitch`determinant(${value})`
|
|
221
|
+
if (typeof value === 'number') {
|
|
222
|
+
return ((value * 180) / Math.PI);
|
|
223
|
+
}
|
|
224
|
+
throw new MissingCpuImplError('CPU implementation for degrees on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
|
|
225
|
+
}
|
|
226
|
+
export const degrees = dualImpl({
|
|
227
|
+
name: 'degrees',
|
|
228
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
229
|
+
normalImpl: cpuDegrees,
|
|
230
|
+
codegenImpl: (_ctx, [value]) => stitch `degrees(${value})`,
|
|
231
|
+
sideEffects: false,
|
|
232
|
+
});
|
|
233
|
+
export const determinant = dualImpl({
|
|
234
|
+
name: 'determinant',
|
|
235
|
+
signature: (arg) => {
|
|
236
|
+
if (!(arg.type === 'mat2x2f' || arg.type === 'mat3x3f' || arg.type === 'mat4x4f')) {
|
|
237
|
+
throw new SignatureNotSupportedError([arg], [mat2x2f, mat3x3f, mat4x4f]);
|
|
238
|
+
}
|
|
239
|
+
return { argTypes: [arg], returnType: f32 };
|
|
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
|
+
sideEffects: false,
|
|
243
244
|
});
|
|
244
245
|
function cpuDistance(a, b) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
246
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
247
|
+
return Math.abs(a - b);
|
|
248
|
+
}
|
|
249
|
+
return length(sub(a, b));
|
|
250
|
+
}
|
|
251
|
+
export const distance = dualImpl({
|
|
252
|
+
name: 'distance',
|
|
253
|
+
signature: (...args) => {
|
|
254
|
+
const uargs = unify(args, anyFloat);
|
|
255
|
+
if (!uargs) {
|
|
256
|
+
throw new SignatureNotSupportedError(args, anyFloat);
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
argTypes: uargs,
|
|
260
|
+
returnType: isHalfPrecisionSchema(uargs[0]) ? f16 : f32,
|
|
261
|
+
};
|
|
262
|
+
},
|
|
263
|
+
normalImpl: cpuDistance,
|
|
264
|
+
codegenImpl: (_ctx, [a, b]) => stitch `distance(${a}, ${b})`,
|
|
265
|
+
sideEffects: false,
|
|
266
|
+
});
|
|
267
|
+
export const dot = dualImpl({
|
|
268
|
+
name: 'dot',
|
|
269
|
+
signature: (...args) => ({
|
|
270
|
+
argTypes: args,
|
|
271
|
+
returnType: args[0].primitive,
|
|
272
|
+
}),
|
|
273
|
+
normalImpl: (lhs, rhs) => VectorOps.dot[lhs.kind](lhs, rhs),
|
|
274
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch `dot(${lhs}, ${rhs})`,
|
|
275
|
+
sideEffects: false,
|
|
276
|
+
});
|
|
277
|
+
export const dot4U8Packed = dualImpl({
|
|
278
|
+
name: 'dot4U8Packed',
|
|
279
|
+
signature: { argTypes: [u32, u32], returnType: u32 },
|
|
280
|
+
normalImpl: 'CPU implementation for dot4U8Packed not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
281
|
+
codegenImpl: (_ctx, [e1, e2]) => stitch `dot4U8Packed(${e1}, ${e2})`,
|
|
282
|
+
sideEffects: false,
|
|
283
|
+
});
|
|
284
|
+
export const dot4I8Packed = dualImpl({
|
|
285
|
+
name: 'dot4I8Packed',
|
|
286
|
+
signature: { argTypes: [u32, u32], returnType: i32 },
|
|
287
|
+
normalImpl: 'CPU implementation for dot4I8Packed not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
288
|
+
codegenImpl: (_ctx, [e1, e2]) => stitch `dot4I8Packed(${e1}, ${e2})`,
|
|
289
|
+
sideEffects: false,
|
|
287
290
|
});
|
|
288
291
|
function cpuExp(value) {
|
|
289
|
-
|
|
290
|
-
return VectorOps.exp[value.kind](value);
|
|
292
|
+
return generalizeFn(Math.exp, [value]);
|
|
291
293
|
}
|
|
292
|
-
const exp = dualImpl({
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
294
|
+
export const exp = dualImpl({
|
|
295
|
+
name: 'exp',
|
|
296
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
297
|
+
normalImpl: cpuExp,
|
|
298
|
+
codegenImpl: (_ctx, [value]) => stitch `exp(${value})`,
|
|
299
|
+
sideEffects: false,
|
|
297
300
|
});
|
|
298
301
|
function cpuExp2(value) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
})
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
302
|
+
return generalizeFn((val) => 2 ** val, [value]);
|
|
303
|
+
}
|
|
304
|
+
export const exp2 = dualImpl({
|
|
305
|
+
name: 'exp2',
|
|
306
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
307
|
+
normalImpl: cpuExp2,
|
|
308
|
+
codegenImpl: (_ctx, [value]) => stitch `exp2(${value})`,
|
|
309
|
+
sideEffects: false,
|
|
310
|
+
});
|
|
311
|
+
function cpuExtractBits(_e, _offset, _count) {
|
|
312
|
+
throw new Error('Unreachable code. The function is only used for the type.');
|
|
313
|
+
}
|
|
314
|
+
export const extractBits = dualImpl({
|
|
315
|
+
name: 'extractBits',
|
|
316
|
+
signature: (arg, _offset, _count) => {
|
|
317
|
+
const argRestricted = unify([arg], anyConcreteInteger)?.[0];
|
|
318
|
+
if (!argRestricted) {
|
|
319
|
+
throw new SignatureNotSupportedError([arg], anyConcreteInteger);
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
argTypes: [argRestricted, u32, u32],
|
|
323
|
+
returnType: argRestricted,
|
|
324
|
+
};
|
|
325
|
+
},
|
|
326
|
+
normalImpl: 'CPU implementation for extractBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
327
|
+
codegenImpl: (_ctx, [e, offset, count]) => stitch `extractBits(${e}, ${offset}, ${count})`,
|
|
328
|
+
sideEffects: false,
|
|
329
|
+
});
|
|
330
|
+
export const faceForward = dualImpl({
|
|
331
|
+
name: 'faceForward',
|
|
332
|
+
signature: unifyRestrictedSignature(anyFloatVec),
|
|
333
|
+
normalImpl: 'CPU implementation for faceForward not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
334
|
+
codegenImpl: (_ctx, [e1, e2, e3]) => stitch `faceForward(${e1}, ${e2}, ${e3})`,
|
|
335
|
+
sideEffects: false,
|
|
336
|
+
});
|
|
337
|
+
function cpuFirstLeadingBit(_value) {
|
|
338
|
+
throw new Error('Unreachable code. The function is only used for the type.');
|
|
339
|
+
}
|
|
340
|
+
export const firstLeadingBit = dualImpl({
|
|
341
|
+
name: 'firstLeadingBit',
|
|
342
|
+
signature: unaryIdentitySignature,
|
|
343
|
+
normalImpl: 'CPU implementation for firstLeadingBit not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
344
|
+
codegenImpl: (_ctx, [value]) => stitch `firstLeadingBit(${value})`,
|
|
345
|
+
sideEffects: false,
|
|
346
|
+
});
|
|
347
|
+
function cpuFirstTrailingBit(_value) {
|
|
348
|
+
throw new Error('Unreachable code. The function is only used for the type.');
|
|
349
|
+
}
|
|
350
|
+
export const firstTrailingBit = dualImpl({
|
|
351
|
+
name: 'firstTrailingBit',
|
|
352
|
+
signature: unifyRestrictedSignature(anyConcreteInteger),
|
|
353
|
+
normalImpl: 'CPU implementation for firstTrailingBit not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
354
|
+
codegenImpl: (_ctx, [value]) => stitch `firstTrailingBit(${value})`,
|
|
355
|
+
sideEffects: false,
|
|
342
356
|
});
|
|
343
357
|
function cpuFloor(value) {
|
|
344
|
-
|
|
345
|
-
return VectorOps.floor[value.kind](value);
|
|
358
|
+
return generalizeFn(Math.floor, [value]);
|
|
346
359
|
}
|
|
347
|
-
const floor = dualImpl({
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
360
|
+
export const floor = dualImpl({
|
|
361
|
+
name: 'floor',
|
|
362
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
363
|
+
normalImpl: cpuFloor,
|
|
364
|
+
codegenImpl: (_ctx, [arg]) => stitch `floor(${arg})`,
|
|
365
|
+
sideEffects: false,
|
|
352
366
|
});
|
|
353
367
|
function cpuFma(e1, e2, e3) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
368
|
+
if (typeof e1 === 'number') {
|
|
369
|
+
return (e1 * e2 + e3);
|
|
370
|
+
}
|
|
371
|
+
throw new MissingCpuImplError('CPU implementation for fma on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
|
|
372
|
+
}
|
|
373
|
+
export const fma = dualImpl({
|
|
374
|
+
name: 'fma',
|
|
375
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
376
|
+
normalImpl: cpuFma,
|
|
377
|
+
codegenImpl: (_ctx, [e1, e2, e3]) => stitch `fma(${e1}, ${e2}, ${e3})`,
|
|
378
|
+
sideEffects: false,
|
|
362
379
|
});
|
|
363
380
|
function cpuFract(value) {
|
|
364
|
-
|
|
365
|
-
return VectorOps.fract[value.kind](value);
|
|
381
|
+
return generalizeFn((value) => value - Math.floor(value), [value]);
|
|
366
382
|
}
|
|
367
|
-
const fract = dualImpl({
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
383
|
+
export const fract = dualImpl({
|
|
384
|
+
name: 'fract',
|
|
385
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
386
|
+
normalImpl: cpuFract,
|
|
387
|
+
codegenImpl: (_ctx, [a]) => stitch `fract(${a})`,
|
|
388
|
+
sideEffects: false,
|
|
372
389
|
});
|
|
373
390
|
const FrexpResults = {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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
|
-
})
|
|
391
|
+
f32: abstruct({ fract: f32, exp: i32 }),
|
|
392
|
+
f16: abstruct({ fract: f16, exp: i32 }),
|
|
393
|
+
abstractFloat: abstruct({ fract: abstractFloat, exp: abstractInt }),
|
|
394
|
+
vec2f: abstruct({ fract: vec2f, exp: vec2i }),
|
|
395
|
+
vec3f: abstruct({ fract: vec3f, exp: vec3i }),
|
|
396
|
+
vec4f: abstruct({ fract: vec4f, exp: vec4i }),
|
|
397
|
+
vec2h: abstruct({ fract: vec2h, exp: vec2i }),
|
|
398
|
+
vec3h: abstruct({ fract: vec3h, exp: vec3i }),
|
|
399
|
+
vec4h: abstruct({ fract: vec4h, exp: vec4i }),
|
|
410
400
|
};
|
|
411
|
-
const frexp = dualImpl({
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
401
|
+
export const frexp = dualImpl({
|
|
402
|
+
name: 'frexp',
|
|
403
|
+
normalImpl: 'CPU implementation for frexp not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
404
|
+
signature: (value) => {
|
|
405
|
+
const returnType = FrexpResults[value.type];
|
|
406
|
+
if (!returnType) {
|
|
407
|
+
throw new SignatureNotSupportedError([value], anyFloat);
|
|
408
|
+
}
|
|
409
|
+
return { argTypes: [value], returnType };
|
|
410
|
+
},
|
|
411
|
+
codegenImpl: (_ctx, [value]) => stitch `frexp(${value})`,
|
|
412
|
+
sideEffects: false,
|
|
413
|
+
});
|
|
414
|
+
function cpuInsertBits(_e, _newbits, _offset, _count) {
|
|
415
|
+
throw new Error('Unreachable code. The function is only used for the type.');
|
|
416
|
+
}
|
|
417
|
+
export const insertBits = dualImpl({
|
|
418
|
+
name: 'insertBits',
|
|
419
|
+
signature: (e, newbits, _offset, _count) => {
|
|
420
|
+
const uargs = unify([e, newbits], anyConcreteInteger);
|
|
421
|
+
if (!uargs) {
|
|
422
|
+
throw new SignatureNotSupportedError([e, newbits], anyConcreteInteger);
|
|
423
|
+
}
|
|
424
|
+
return {
|
|
425
|
+
argTypes: [...uargs, u32, u32],
|
|
426
|
+
returnType: uargs[0],
|
|
427
|
+
};
|
|
428
|
+
},
|
|
429
|
+
normalImpl: 'CPU implementation for insertBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
430
|
+
codegenImpl: (_ctx, [e, newbits, offset, count]) => stitch `insertBits(${e}, ${newbits}, ${offset}, ${count})`,
|
|
431
|
+
sideEffects: false,
|
|
440
432
|
});
|
|
441
433
|
function cpuInverseSqrt(value) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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})`
|
|
434
|
+
if (typeof value === 'number') {
|
|
435
|
+
return (1 / Math.sqrt(value));
|
|
436
|
+
}
|
|
437
|
+
throw new MissingCpuImplError('CPU implementation for inverseSqrt on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
|
|
438
|
+
}
|
|
439
|
+
export const inverseSqrt = dualImpl({
|
|
440
|
+
name: 'inverseSqrt',
|
|
441
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
442
|
+
normalImpl: cpuInverseSqrt,
|
|
443
|
+
codegenImpl: (_ctx, [value]) => stitch `inverseSqrt(${value})`,
|
|
444
|
+
sideEffects: false,
|
|
445
|
+
});
|
|
446
|
+
function cpuLdexp(_e1, _e2) {
|
|
447
|
+
throw new Error('Unreachable code. The function is only used for the type.');
|
|
448
|
+
}
|
|
449
|
+
export const ldexp = dualImpl({
|
|
450
|
+
name: 'ldexp',
|
|
451
|
+
signature: (e1, _e2) => {
|
|
452
|
+
switch (e1.type) {
|
|
453
|
+
case 'abstractFloat':
|
|
454
|
+
return { argTypes: [e1, abstractInt], returnType: e1 };
|
|
455
|
+
case 'f32':
|
|
456
|
+
case 'f16':
|
|
457
|
+
return { argTypes: [e1, i32], returnType: e1 };
|
|
458
|
+
case 'vec2f':
|
|
459
|
+
case 'vec2h':
|
|
460
|
+
return { argTypes: [e1, vec2i], returnType: e1 };
|
|
461
|
+
case 'vec3f':
|
|
462
|
+
case 'vec3h':
|
|
463
|
+
return { argTypes: [e1, vec3i], returnType: e1 };
|
|
464
|
+
case 'vec4f':
|
|
465
|
+
case 'vec4h':
|
|
466
|
+
return { argTypes: [e1, vec4i], returnType: e1 };
|
|
467
|
+
default:
|
|
468
|
+
throw new Error(`Unsupported data type for ldexp: ${e1.type}. Supported types are abstractFloat, f32, f16, vec2f, vec2h, vec3f, vec3h, vec4f, vec4h.`);
|
|
469
|
+
}
|
|
470
|
+
},
|
|
471
|
+
normalImpl: 'CPU implementation for ldexp not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
472
|
+
codegenImpl: (_ctx, [e1, e2]) => stitch `ldexp(${e1}, ${e2})`,
|
|
473
|
+
sideEffects: false,
|
|
484
474
|
});
|
|
485
475
|
function cpuLength(value) {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
476
|
+
if (typeof value === 'number') {
|
|
477
|
+
return Math.abs(value);
|
|
478
|
+
}
|
|
479
|
+
return VectorOps.length[value.kind](value);
|
|
480
|
+
}
|
|
481
|
+
export const length = dualImpl({
|
|
482
|
+
name: 'length',
|
|
483
|
+
signature: (arg) => {
|
|
484
|
+
const uarg = unify([arg], anyFloat);
|
|
485
|
+
if (!uarg) {
|
|
486
|
+
throw new SignatureNotSupportedError([arg], anyFloat);
|
|
487
|
+
}
|
|
488
|
+
return {
|
|
489
|
+
argTypes: uarg,
|
|
490
|
+
returnType: isHalfPrecisionSchema(uarg[0]) ? f16 : f32,
|
|
491
|
+
};
|
|
492
|
+
},
|
|
493
|
+
normalImpl: cpuLength,
|
|
494
|
+
codegenImpl: (_ctx, [arg]) => stitch `length(${arg})`,
|
|
495
|
+
sideEffects: false,
|
|
501
496
|
});
|
|
502
497
|
function cpuLog(value) {
|
|
503
|
-
|
|
504
|
-
return VectorOps.log[value.kind](value);
|
|
498
|
+
return generalizeFn(Math.log, [value]);
|
|
505
499
|
}
|
|
506
|
-
const log = dualImpl({
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
500
|
+
export const log = dualImpl({
|
|
501
|
+
name: 'log',
|
|
502
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
503
|
+
normalImpl: cpuLog,
|
|
504
|
+
codegenImpl: (_ctx, [value]) => stitch `log(${value})`,
|
|
505
|
+
sideEffects: false,
|
|
511
506
|
});
|
|
512
507
|
function cpuLog2(value) {
|
|
513
|
-
|
|
514
|
-
return VectorOps.log2[value.kind](value);
|
|
508
|
+
return generalizeFn(Math.log2, [value]);
|
|
515
509
|
}
|
|
516
|
-
const log2 = dualImpl({
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
510
|
+
export const log2 = dualImpl({
|
|
511
|
+
name: 'log2',
|
|
512
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
513
|
+
normalImpl: cpuLog2,
|
|
514
|
+
codegenImpl: (_ctx, [value]) => stitch `log2(${value})`,
|
|
515
|
+
sideEffects: false,
|
|
521
516
|
});
|
|
522
517
|
function cpuMax(a, b) {
|
|
523
|
-
|
|
524
|
-
return VectorOps.max[a.kind](a, b);
|
|
518
|
+
return generalizeFn(Math.max, [a, b]);
|
|
525
519
|
}
|
|
526
|
-
const max = dualImpl({
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
520
|
+
export const max = dualImpl({
|
|
521
|
+
name: 'max',
|
|
522
|
+
signature: variadicUnifySignature,
|
|
523
|
+
normalImpl: variadicReduce(cpuMax),
|
|
524
|
+
codegenImpl: variadicStitch('max'),
|
|
525
|
+
sideEffects: false,
|
|
531
526
|
});
|
|
532
527
|
function cpuMin(a, b) {
|
|
533
|
-
|
|
534
|
-
return VectorOps.min[a.kind](a, b);
|
|
528
|
+
return generalizeFn(Math.min, [a, b]);
|
|
535
529
|
}
|
|
536
|
-
const min = dualImpl({
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
530
|
+
export const min = dualImpl({
|
|
531
|
+
name: 'min',
|
|
532
|
+
signature: variadicUnifySignature,
|
|
533
|
+
normalImpl: variadicReduce(cpuMin),
|
|
534
|
+
codegenImpl: variadicStitch('min'),
|
|
535
|
+
sideEffects: false,
|
|
541
536
|
});
|
|
542
537
|
function cpuMix(e1, e2, e3) {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
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})`
|
|
538
|
+
return generalizeFn((e1, e2, e3) => e1 * (1 - e3) + e2 * e3, [e1, ...upCast([e2, e3])]);
|
|
539
|
+
}
|
|
540
|
+
export const mix = dualImpl({
|
|
541
|
+
name: 'mix',
|
|
542
|
+
signature: (e1, e2, e3) => {
|
|
543
|
+
if (e1.type.startsWith('vec') && !e3.type.startsWith('vec')) {
|
|
544
|
+
const uarg = unify([e3], [e1.primitive]);
|
|
545
|
+
if (!uarg) {
|
|
546
|
+
throw new SignatureNotSupportedError([e3], [e1.primitive]);
|
|
547
|
+
}
|
|
548
|
+
return { argTypes: [e1, e2, uarg[0]], returnType: e1 };
|
|
549
|
+
}
|
|
550
|
+
const uargs = unify([e1, e2, e3], anyFloat);
|
|
551
|
+
if (!uargs) {
|
|
552
|
+
throw new SignatureNotSupportedError([e1, e2, e3], anyFloat);
|
|
553
|
+
}
|
|
554
|
+
return { argTypes: uargs, returnType: uargs[0] };
|
|
555
|
+
},
|
|
556
|
+
normalImpl: cpuMix,
|
|
557
|
+
codegenImpl: (_ctx, [e1, e2, e3]) => stitch `mix(${e1}, ${e2}, ${e3})`,
|
|
558
|
+
sideEffects: false,
|
|
582
559
|
});
|
|
583
560
|
const ModfResult = {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
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
|
-
})
|
|
561
|
+
f32: abstruct({ fract: f32, whole: f32 }),
|
|
562
|
+
f16: abstruct({ fract: f16, whole: f16 }),
|
|
563
|
+
abstractFloat: abstruct({ fract: abstractFloat, whole: abstractFloat }),
|
|
564
|
+
vec2f: abstruct({ fract: vec2f, whole: vec2f }),
|
|
565
|
+
vec3f: abstruct({ fract: vec3f, whole: vec3f }),
|
|
566
|
+
vec4f: abstruct({ fract: vec4f, whole: vec4f }),
|
|
567
|
+
vec2h: abstruct({ fract: vec2h, whole: vec2h }),
|
|
568
|
+
vec3h: abstruct({ fract: vec3h, whole: vec3h }),
|
|
569
|
+
vec4h: abstruct({ fract: vec4h, whole: vec4h }),
|
|
620
570
|
};
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
571
|
+
function cpuModf(_value) {
|
|
572
|
+
throw new Error('Unreachable code. The function is only used for the type.');
|
|
573
|
+
}
|
|
574
|
+
export const modf = dualImpl({
|
|
575
|
+
name: 'modf',
|
|
576
|
+
signature: (e) => {
|
|
577
|
+
const returnType = ModfResult[e.type];
|
|
578
|
+
if (!returnType) {
|
|
579
|
+
throw new Error(`Unsupported data type for modf: ${e.type}. Supported types are f32, f16, abstractFloat, vec2f, vec3f, vec4f, vec2h, vec3h, vec4h.`);
|
|
580
|
+
}
|
|
581
|
+
return { argTypes: [e], returnType };
|
|
582
|
+
},
|
|
583
|
+
normalImpl: 'CPU implementation for modf not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
584
|
+
codegenImpl: (_ctx, [value]) => stitch `modf(${value})`,
|
|
585
|
+
sideEffects: false,
|
|
586
|
+
});
|
|
587
|
+
export const normalize = dualImpl({
|
|
588
|
+
name: 'normalize',
|
|
589
|
+
signature: unifyRestrictedSignature(anyFloatVec),
|
|
590
|
+
normalImpl: (v) => {
|
|
591
|
+
const len = length(v);
|
|
592
|
+
return generalizeFn((e) => e / len, [v]);
|
|
593
|
+
},
|
|
594
|
+
codegenImpl: (_ctx, [value]) => stitch `normalize(${value})`,
|
|
595
|
+
sideEffects: false,
|
|
639
596
|
});
|
|
640
597
|
function powCpu(base, exponent) {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
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})`
|
|
598
|
+
return generalizeFn((a, b) => a ** b, [base, exponent]);
|
|
599
|
+
}
|
|
600
|
+
export const pow = dualImpl({
|
|
601
|
+
name: 'pow',
|
|
602
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
603
|
+
normalImpl: powCpu,
|
|
604
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch `pow(${lhs}, ${rhs})`,
|
|
605
|
+
sideEffects: false,
|
|
606
|
+
});
|
|
607
|
+
function cpuQuantizeToF16(_value) {
|
|
608
|
+
throw new Error('Unreachable code. The function is only used for the type.');
|
|
609
|
+
}
|
|
610
|
+
export const quantizeToF16 = dualImpl({
|
|
611
|
+
name: 'quantizeToF16',
|
|
612
|
+
signature: (arg) => {
|
|
613
|
+
const candidates = [vec2f, vec3f, vec4f, f32];
|
|
614
|
+
const uarg = unify([arg], candidates)?.[0];
|
|
615
|
+
if (!uarg) {
|
|
616
|
+
throw new SignatureNotSupportedError([arg], candidates);
|
|
617
|
+
}
|
|
618
|
+
return { argTypes: [uarg], returnType: uarg };
|
|
619
|
+
},
|
|
620
|
+
normalImpl: 'CPU implementation for quantizeToF16 not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
621
|
+
codegenImpl: (_ctx, [value]) => stitch `quantizeToF16(${value})`,
|
|
622
|
+
sideEffects: false,
|
|
669
623
|
});
|
|
670
624
|
function cpuRadians(value) {
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
625
|
+
if (typeof value === 'number') {
|
|
626
|
+
return ((value * Math.PI) / 180);
|
|
627
|
+
}
|
|
628
|
+
throw new MissingCpuImplError('CPU implementation for radians on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
|
|
629
|
+
}
|
|
630
|
+
export const radians = dualImpl({
|
|
631
|
+
name: 'radians',
|
|
632
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
633
|
+
normalImpl: cpuRadians,
|
|
634
|
+
codegenImpl: (_ctx, [value]) => stitch `radians(${value})`,
|
|
635
|
+
sideEffects: false,
|
|
636
|
+
});
|
|
637
|
+
export const reflect = dualImpl({
|
|
638
|
+
name: 'reflect',
|
|
639
|
+
signature: (...args) => {
|
|
640
|
+
const uargs = unify(args, anyFloatVec);
|
|
641
|
+
if (!uargs) {
|
|
642
|
+
throw new SignatureNotSupportedError(args, anyFloatVec);
|
|
643
|
+
}
|
|
644
|
+
return {
|
|
645
|
+
argTypes: uargs,
|
|
646
|
+
returnType: uargs[0],
|
|
647
|
+
};
|
|
648
|
+
},
|
|
649
|
+
normalImpl: (e1, e2) => sub(e1, mul(2 * dot(e2, e1), e2)),
|
|
650
|
+
codegenImpl: (_ctx, [e1, e2]) => stitch `reflect(${e1}, ${e2})`,
|
|
651
|
+
sideEffects: false,
|
|
652
|
+
});
|
|
653
|
+
export const refract = dualImpl({
|
|
654
|
+
name: 'refract',
|
|
655
|
+
normalImpl: 'CPU implementation for refract not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
656
|
+
codegenImpl: (_ctx, [e1, e2, e3]) => stitch `refract(${e1}, ${e2}, ${e3})`,
|
|
657
|
+
signature: (e1, e2, _e3) => ({
|
|
658
|
+
argTypes: [e1, e2, isHalfPrecisionSchema(e1) ? f16 : f32],
|
|
659
|
+
returnType: e1,
|
|
660
|
+
}),
|
|
661
|
+
sideEffects: false,
|
|
662
|
+
});
|
|
663
|
+
function cpuReverseBits(_value) {
|
|
664
|
+
throw new Error('Unreachable code. The function is only used for the type.');
|
|
665
|
+
}
|
|
666
|
+
export const reverseBits = dualImpl({
|
|
667
|
+
name: 'reverseBits',
|
|
668
|
+
signature: unifyRestrictedSignature(anyConcreteInteger),
|
|
669
|
+
normalImpl: 'CPU implementation for reverseBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
670
|
+
codegenImpl: (_ctx, [value]) => stitch `reverseBits(${value})`,
|
|
671
|
+
sideEffects: false,
|
|
711
672
|
});
|
|
712
673
|
function cpuRound(value) {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
674
|
+
if (typeof value === 'number') {
|
|
675
|
+
const floor = Math.floor(value);
|
|
676
|
+
if (value === floor + 0.5) {
|
|
677
|
+
if (floor % 2 === 0) {
|
|
678
|
+
return floor;
|
|
679
|
+
}
|
|
680
|
+
return (floor + 1);
|
|
681
|
+
}
|
|
682
|
+
return Math.round(value);
|
|
683
|
+
}
|
|
684
|
+
throw new MissingCpuImplError('CPU implementation for round on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
|
|
685
|
+
}
|
|
686
|
+
export const round = dualImpl({
|
|
687
|
+
name: 'round',
|
|
688
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
689
|
+
normalImpl: cpuRound,
|
|
690
|
+
codegenImpl: (_ctx, [value]) => stitch `round(${value})`,
|
|
691
|
+
sideEffects: false,
|
|
728
692
|
});
|
|
729
693
|
function cpuSaturate(value) {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
694
|
+
if (typeof value === 'number') {
|
|
695
|
+
return Math.max(0, Math.min(1, value));
|
|
696
|
+
}
|
|
697
|
+
throw new MissingCpuImplError('CPU implementation for saturate on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
|
|
698
|
+
}
|
|
699
|
+
export const saturate = dualImpl({
|
|
700
|
+
name: 'saturate',
|
|
701
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
702
|
+
normalImpl: cpuSaturate,
|
|
703
|
+
codegenImpl: (ctx, [value]) => ctx.gen.emitCall('saturate', [], [value]),
|
|
704
|
+
sideEffects: false,
|
|
738
705
|
});
|
|
739
706
|
function cpuSign(e) {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
return {
|
|
756
|
-
argTypes: [uarg],
|
|
757
|
-
returnType: uarg
|
|
758
|
-
};
|
|
759
|
-
},
|
|
760
|
-
normalImpl: cpuSign,
|
|
761
|
-
codegenImpl: (_ctx, [e]) => stitch`sign(${e})`
|
|
707
|
+
return generalizeFn(Math.sign, [e]);
|
|
708
|
+
}
|
|
709
|
+
export const sign = dualImpl({
|
|
710
|
+
name: 'sign',
|
|
711
|
+
signature: (arg) => {
|
|
712
|
+
const candidates = [...anyFloat, i32, vec2i, vec3i, vec4i];
|
|
713
|
+
const uarg = unify([arg], candidates)?.[0];
|
|
714
|
+
if (!uarg) {
|
|
715
|
+
throw new SignatureNotSupportedError([arg], candidates);
|
|
716
|
+
}
|
|
717
|
+
return { argTypes: [uarg], returnType: uarg };
|
|
718
|
+
},
|
|
719
|
+
normalImpl: cpuSign,
|
|
720
|
+
codegenImpl: (_ctx, [e]) => stitch `sign(${e})`,
|
|
721
|
+
sideEffects: false,
|
|
762
722
|
});
|
|
763
723
|
function cpuSin(value) {
|
|
764
|
-
|
|
765
|
-
return VectorOps.sin[value.kind](value);
|
|
724
|
+
return generalizeFn(Math.sin, [value]);
|
|
766
725
|
}
|
|
767
|
-
const sin = dualImpl({
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
726
|
+
export const sin = dualImpl({
|
|
727
|
+
name: 'sin',
|
|
728
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
729
|
+
normalImpl: cpuSin,
|
|
730
|
+
codegenImpl: (_ctx, [value]) => stitch `sin(${value})`,
|
|
731
|
+
sideEffects: false,
|
|
772
732
|
});
|
|
773
733
|
function cpuSinh(value) {
|
|
774
|
-
|
|
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");
|
|
734
|
+
return generalizeFn(Math.sinh, [value]);
|
|
776
735
|
}
|
|
777
|
-
const sinh = dualImpl({
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
736
|
+
export const sinh = dualImpl({
|
|
737
|
+
name: 'sinh',
|
|
738
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
739
|
+
normalImpl: cpuSinh,
|
|
740
|
+
codegenImpl: (_ctx, [value]) => stitch `sinh(${value})`,
|
|
741
|
+
sideEffects: false,
|
|
782
742
|
});
|
|
783
743
|
function cpuSmoothstep(edge0, edge1, x) {
|
|
784
|
-
|
|
785
|
-
return VectorOps.smoothstep[x.kind](edge0, edge1, x);
|
|
744
|
+
return generalizeFn(smoothstepScalar, [edge0, edge1, x]);
|
|
786
745
|
}
|
|
787
|
-
const smoothstep = dualImpl({
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
746
|
+
export const smoothstep = dualImpl({
|
|
747
|
+
name: 'smoothstep',
|
|
748
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
749
|
+
normalImpl: cpuSmoothstep,
|
|
750
|
+
codegenImpl: (_ctx, [edge0, edge1, x]) => stitch `smoothstep(${edge0}, ${edge1}, ${x})`,
|
|
751
|
+
sideEffects: false,
|
|
792
752
|
});
|
|
793
753
|
function cpuSqrt(value) {
|
|
794
|
-
|
|
795
|
-
return VectorOps.sqrt[value.kind](value);
|
|
754
|
+
return generalizeFn(Math.sqrt, [value]);
|
|
796
755
|
}
|
|
797
|
-
const sqrt = dualImpl({
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
756
|
+
export const sqrt = dualImpl({
|
|
757
|
+
name: 'sqrt',
|
|
758
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
759
|
+
normalImpl: cpuSqrt,
|
|
760
|
+
codegenImpl: (_ctx, [value]) => stitch `sqrt(${value})`,
|
|
761
|
+
sideEffects: false,
|
|
802
762
|
});
|
|
803
763
|
function cpuStep(edge, x) {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
764
|
+
if (typeof edge === 'number') {
|
|
765
|
+
return (edge <= x ? 1.0 : 0.0);
|
|
766
|
+
}
|
|
767
|
+
throw new MissingCpuImplError('CPU implementation for step on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
|
|
768
|
+
}
|
|
769
|
+
export const step = dualImpl({
|
|
770
|
+
name: 'step',
|
|
771
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
772
|
+
normalImpl: cpuStep,
|
|
773
|
+
codegenImpl: (_ctx, [edge, x]) => stitch `step(${edge}, ${x})`,
|
|
774
|
+
sideEffects: false,
|
|
812
775
|
});
|
|
813
776
|
function cpuTan(value) {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
777
|
+
if (typeof value === 'number') {
|
|
778
|
+
return Math.tan(value);
|
|
779
|
+
}
|
|
780
|
+
throw new MissingCpuImplError('CPU implementation for tan on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues');
|
|
781
|
+
}
|
|
782
|
+
export const tan = dualImpl({
|
|
783
|
+
name: 'tan',
|
|
784
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
785
|
+
normalImpl: cpuTan,
|
|
786
|
+
codegenImpl: (_ctx, [value]) => stitch `tan(${value})`,
|
|
787
|
+
sideEffects: false,
|
|
822
788
|
});
|
|
823
789
|
function cpuTanh(value) {
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
});
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
790
|
+
return generalizeFn(Math.tanh, [value]);
|
|
791
|
+
}
|
|
792
|
+
export const tanh = dualImpl({
|
|
793
|
+
name: 'tanh',
|
|
794
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
795
|
+
normalImpl: cpuTanh,
|
|
796
|
+
codegenImpl: (_ctx, [value]) => stitch `tanh(${value})`,
|
|
797
|
+
sideEffects: false,
|
|
798
|
+
});
|
|
799
|
+
function cpuTranspose(value) {
|
|
800
|
+
const schema = WORKAROUND_getSchema(value);
|
|
801
|
+
// NOTE: This assumes all matrices are square
|
|
802
|
+
const transposed = schema();
|
|
803
|
+
const src = value.columns;
|
|
804
|
+
const dst = transposed.columns;
|
|
805
|
+
if (src.length === 2) {
|
|
806
|
+
dst[0][0] = src[0][0];
|
|
807
|
+
dst[0][1] = src[1][0];
|
|
808
|
+
dst[1][0] = src[0][1];
|
|
809
|
+
dst[1][1] = src[1][1];
|
|
810
|
+
}
|
|
811
|
+
else if (src.length === 3) {
|
|
812
|
+
dst[0][0] = src[0][0];
|
|
813
|
+
dst[0][1] = src[1][0];
|
|
814
|
+
dst[0][2] = src[2][0];
|
|
815
|
+
dst[1][0] = src[0][1];
|
|
816
|
+
dst[1][1] = src[1][1];
|
|
817
|
+
dst[1][2] = src[2][1];
|
|
818
|
+
// oxlint-disable-next-line typescript/no-non-null-assertion
|
|
819
|
+
const dst2 = dst[2];
|
|
820
|
+
dst2[0] = src[0][2];
|
|
821
|
+
dst2[1] = src[1][2];
|
|
822
|
+
dst2[2] = src[2][2];
|
|
823
|
+
}
|
|
824
|
+
else if (src.length === 4) {
|
|
825
|
+
dst[0][0] = src[0][0];
|
|
826
|
+
dst[0][1] = src[1][0];
|
|
827
|
+
dst[0][2] = src[2][0];
|
|
828
|
+
dst[0][3] = src[3][0];
|
|
829
|
+
dst[1][0] = src[0][1];
|
|
830
|
+
dst[1][1] = src[1][1];
|
|
831
|
+
dst[1][2] = src[2][1];
|
|
832
|
+
dst[1][3] = src[3][1];
|
|
833
|
+
// oxlint-disable-next-line typescript/no-non-null-assertion
|
|
834
|
+
const dst2 = dst[2];
|
|
835
|
+
dst2[0] = src[0][2];
|
|
836
|
+
dst2[1] = src[1][2];
|
|
837
|
+
dst2[2] = src[2][2];
|
|
838
|
+
dst2[3] = src[3][2];
|
|
839
|
+
// oxlint-disable-next-line typescript/no-non-null-assertion
|
|
840
|
+
const dst3 = dst[3];
|
|
841
|
+
dst3[0] = src[0][3];
|
|
842
|
+
dst3[1] = src[1][3];
|
|
843
|
+
dst3[2] = src[2][3];
|
|
844
|
+
dst3[3] = src[3][3];
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
assertExhaustive(src, 'std/numeric.ts#cpuTranspose');
|
|
848
|
+
}
|
|
849
|
+
return transposed;
|
|
850
|
+
}
|
|
851
|
+
export const transpose = dualImpl({
|
|
852
|
+
name: 'transpose',
|
|
853
|
+
signature: unaryIdentitySignature,
|
|
854
|
+
normalImpl: cpuTranspose,
|
|
855
|
+
codegenImpl: (_ctx, [e]) => stitch `transpose(${e})`,
|
|
856
|
+
sideEffects: false,
|
|
857
|
+
});
|
|
858
|
+
function cpuTrunc(_value) {
|
|
859
|
+
throw new Error('Unreachable code. The function is only used for the type.');
|
|
860
|
+
}
|
|
861
|
+
export const trunc = dualImpl({
|
|
862
|
+
name: 'trunc',
|
|
863
|
+
signature: unifyRestrictedSignature(anyFloat),
|
|
864
|
+
normalImpl: 'CPU implementation for trunc not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues',
|
|
865
|
+
codegenImpl: (_ctx, [value]) => stitch `trunc(${value})`,
|
|
866
|
+
sideEffects: false,
|
|
867
|
+
});
|
|
868
|
+
function cpuIntdiv(lhs, rhs) {
|
|
869
|
+
if (typeof lhs !== 'number' || typeof rhs !== 'number') {
|
|
870
|
+
throw new Error('std.intdiv called with invalid arguments.');
|
|
871
|
+
}
|
|
872
|
+
return Math.trunc(Math.trunc(lhs) / Math.trunc(rhs));
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Performs integer division on the passed in scalars.
|
|
876
|
+
* Equivalent to `trunc(trunc(lhs) / trunc(rhs))`. Coerces both
|
|
877
|
+
* arguments to integers if they're floating point.
|
|
878
|
+
*/
|
|
879
|
+
export const intdiv = dualImpl({
|
|
880
|
+
name: 'intdiv',
|
|
881
|
+
signature: (lhs, rhs) => {
|
|
882
|
+
const unified = unify([lhs, rhs], [u32, i32]);
|
|
883
|
+
if (!unified) {
|
|
884
|
+
throw new SignatureNotSupportedError([lhs, rhs], [u32, i32, abstractInt]);
|
|
885
|
+
}
|
|
886
|
+
return { argTypes: unified, returnType: unified[0] };
|
|
887
|
+
},
|
|
888
|
+
normalImpl: cpuIntdiv,
|
|
889
|
+
codegenImpl: (ctx, [lhs, rhs]) => ctx.gen.emitBinaryOp(lhs, '/', rhs),
|
|
890
|
+
sideEffects: false,
|
|
891
|
+
});
|