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