typegpu 0.10.2 → 0.11.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/_virtual/_rolldown/runtime.js +6 -11
- package/builtin.js +1 -3
- package/common/fullScreenTriangle.d.ts +1 -5
- package/common/fullScreenTriangle.js +1 -3
- package/common/index.d.ts +3 -2
- package/common/index.js +6 -4
- package/common/writeSoA.d.ts +16 -0
- package/common/writeSoA.js +90 -0
- package/core/buffer/buffer.d.ts +12 -7
- package/core/buffer/buffer.js +102 -53
- package/core/buffer/bufferShorthand.d.ts +5 -5
- package/core/buffer/bufferShorthand.js +9 -5
- package/core/buffer/bufferUsage.d.ts +0 -2
- package/core/buffer/bufferUsage.js +6 -4
- package/core/constant/tgpuConstant.d.ts +2 -1
- package/core/constant/tgpuConstant.js +8 -7
- package/core/declare/tgpuDeclare.js +8 -9
- package/core/function/autoIO.d.ts +7 -6
- package/core/function/autoIO.js +1 -3
- package/core/function/comptime.js +1 -3
- package/core/function/createCallableSchema.js +4 -6
- package/core/function/dualImpl.js +1 -3
- package/core/function/entryInputRouter.js +39 -0
- package/core/function/extractArgs.js +2 -2
- package/core/function/fnCore.js +19 -8
- package/core/function/fnTypes.d.ts +14 -8
- package/core/function/ioSchema.js +24 -3
- package/core/function/shelllessImpl.js +1 -3
- package/core/function/templateUtils.js +1 -2
- package/core/function/tgpuComputeFn.d.ts +2 -3
- package/core/function/tgpuComputeFn.js +9 -16
- package/core/function/tgpuFn.d.ts +2 -2
- package/core/function/tgpuFn.js +1 -3
- package/core/function/tgpuFragmentFn.d.ts +5 -1
- package/core/function/tgpuFragmentFn.js +5 -10
- package/core/function/tgpuVertexFn.d.ts +4 -0
- package/core/function/tgpuVertexFn.js +6 -12
- package/core/pipeline/applyPipelineState.js +1 -3
- package/core/pipeline/computePipeline.d.ts +2 -6
- package/core/pipeline/computePipeline.js +64 -63
- package/core/pipeline/connectAttachmentToShader.js +1 -3
- package/core/pipeline/connectTargetsToShader.js +1 -3
- package/core/pipeline/limitsOverflow.js +1 -2
- package/core/pipeline/pipelineUtils.js +29 -0
- package/core/pipeline/renderPipeline.d.ts +23 -5
- package/core/pipeline/renderPipeline.js +32 -14
- package/core/pipeline/timeable.d.ts +0 -3
- package/core/pipeline/timeable.js +3 -9
- package/core/pipeline/typeGuards.js +1 -3
- package/core/querySet/querySet.d.ts +0 -2
- package/core/querySet/querySet.js +37 -36
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +1 -3
- package/core/resolve/externals.d.ts +0 -2
- package/core/resolve/externals.js +2 -4
- package/core/resolve/namespace.js +1 -3
- package/core/resolve/resolveData.js +1 -3
- package/core/resolve/stitch.js +1 -3
- package/core/resolve/tgpuResolve.d.ts +3 -1
- package/core/resolve/tgpuResolve.js +3 -5
- package/core/root/configurableImpl.js +2 -3
- package/core/root/init.d.ts +0 -5
- package/core/root/init.js +35 -28
- package/core/root/rootTypes.d.ts +25 -5
- package/core/sampler/sampler.d.ts +0 -4
- package/core/sampler/sampler.js +3 -3
- package/core/simulate/tgpuSimulate.js +1 -3
- package/core/slot/accessor.d.ts +0 -4
- package/core/slot/accessor.js +1 -3
- package/core/slot/internalSlots.js +1 -3
- package/core/slot/lazy.js +1 -3
- package/core/slot/slot.js +2 -3
- package/core/slot/slotTypes.js +1 -3
- package/core/texture/externalTexture.d.ts +0 -6
- package/core/texture/externalTexture.js +2 -3
- package/core/texture/texture.d.ts +0 -4
- package/core/texture/texture.js +5 -3
- package/core/texture/textureFormats.js +1 -3
- package/core/texture/textureUtils.js +1 -3
- package/core/texture/usageExtension.js +1 -3
- package/core/unroll/tgpuUnroll.d.ts +58 -3
- package/core/unroll/tgpuUnroll.js +63 -5
- package/core/valueProxyUtils.js +1 -3
- package/core/variable/tgpuVariable.js +1 -3
- package/core/vertexLayout/connectAttributesToShader.js +1 -3
- package/core/vertexLayout/vertexLayout.js +9 -9
- package/data/alignIO.js +1 -2
- package/data/alignmentOf.d.ts +0 -1
- package/data/alignmentOf.js +1 -3
- package/data/array.d.ts +1 -3
- package/data/array.js +2 -4
- package/data/atomic.js +2 -3
- package/data/attributes.js +3 -3
- package/data/autoStruct.d.ts +1 -3
- package/data/autoStruct.js +1 -3
- package/data/compiledIO.js +83 -86
- package/data/dataIO.js +46 -39
- package/data/dataTypes.d.ts +7 -7
- package/data/dataTypes.js +6 -3
- package/data/deepEqual.js +1 -3
- package/data/disarray.d.ts +1 -3
- package/data/disarray.js +1 -3
- package/data/getLongestContiguousPrefix.d.ts +0 -1
- package/data/getLongestContiguousPrefix.js +1 -3
- package/data/index.d.ts +3 -3
- package/data/index.js +10 -3
- package/data/isContiguous.d.ts +0 -1
- package/data/isContiguous.js +1 -3
- package/data/matrix.d.ts +8 -10
- package/data/matrix.js +32 -18
- package/data/numberOps.js +1 -2
- package/data/numeric.js +16 -29
- package/data/offsetUtils.d.ts +2 -2
- package/data/offsetUtils.js +3 -5
- package/data/offsets.js +1 -3
- package/data/partialIO.js +84 -39
- package/data/ptr.d.ts +0 -1
- package/data/ptr.js +1 -3
- package/data/ref.d.ts +0 -3
- package/data/ref.js +1 -3
- package/data/sampler.js +1 -3
- package/data/schemaCallWrapper.js +1 -3
- package/data/schemaMemoryLayout.js +1 -3
- package/data/sizeOf.d.ts +0 -1
- package/data/sizeOf.js +1 -3
- package/data/snippet.js +12 -3
- package/data/struct.js +1 -3
- package/data/texture.js +1 -3
- package/data/unstruct.js +1 -3
- package/data/vector.js +4 -12
- package/data/vectorImpl.js +27 -28
- package/data/vectorOps.js +20 -3
- package/data/vertexFormatData.js +2 -3
- package/data/wgslTypes.d.ts +39 -11
- package/data/wgslTypes.js +10 -3
- package/errors.js +6 -3
- package/execMode.js +1 -3
- package/extension.js +1 -3
- package/getGPUValue.js +1 -3
- package/index.d.ts +4 -2
- package/index.js +3 -3
- package/indexNamedExports.d.ts +3 -1
- package/mathUtils.js +1 -2
- package/memo.js +8 -8
- package/nameRegistry.js +1 -3
- package/package.js +2 -3
- package/package.json +7 -7
- package/resolutionCtx.d.ts +0 -10
- package/resolutionCtx.js +84 -18
- package/shared/env.js +1 -2
- package/shared/generators.js +1 -2
- package/shared/meta.js +1 -3
- package/shared/repr.d.ts +32 -2
- package/shared/stringify.js +1 -3
- package/shared/symbols.d.ts +10 -1
- package/shared/symbols.js +10 -33
- package/shared/utilityTypes.d.ts +6 -2
- package/shared/utilityTypes.js +1 -2
- package/shared/vertexFormat.js +1 -2
- package/std/array.d.ts +1 -1
- package/std/array.js +1 -3
- package/std/atomic.d.ts +12 -12
- package/std/atomic.js +1 -3
- package/std/bitcast.d.ts +2 -2
- package/std/bitcast.js +1 -3
- package/std/boolean.d.ts +30 -16
- package/std/boolean.js +37 -12
- package/std/derivative.d.ts +9 -9
- package/std/derivative.js +1 -3
- package/std/discard.d.ts +1 -1
- package/std/discard.js +1 -3
- package/std/extensions.d.ts +1 -3
- package/std/extensions.js +1 -3
- package/std/index.d.ts +5 -4
- package/std/index.js +8 -5
- package/std/matrix.d.ts +5 -5
- package/std/matrix.js +1 -3
- package/std/numeric.d.ts +78 -132
- package/std/numeric.js +1 -3
- package/std/operators.d.ts +16 -8
- package/std/operators.js +80 -6
- package/std/packing.d.ts +4 -4
- package/std/packing.js +1 -3
- package/std/range.d.ts +24 -0
- package/std/range.js +38 -0
- package/std/subgroup.d.ts +21 -21
- package/std/subgroup.js +1 -3
- package/std/texture.d.ts +20 -11
- package/std/texture.js +13 -3
- package/tgpu.js +1 -3
- package/tgpuBindGroupLayout.js +9 -8
- package/tgpuUnstable.js +1 -3
- package/tgsl/accessIndex.js +2 -4
- package/tgsl/accessProp.js +8 -6
- package/tgsl/consoleLog/deserializers.js +1 -3
- package/tgsl/consoleLog/logGenerator.js +2 -4
- package/tgsl/consoleLog/serializers.js +24 -26
- package/tgsl/consoleLog/types.d.ts +0 -2
- package/tgsl/consoleLog/types.js +1 -2
- package/tgsl/conversion.js +1 -3
- package/tgsl/forOfUtils.js +35 -9
- package/tgsl/generationHelpers.js +3 -3
- package/tgsl/math.js +1 -3
- package/tgsl/shaderGenerator.d.ts +10 -8
- package/tgsl/shaderGenerator_members.d.ts +2 -0
- package/tgsl/shaderGenerator_members.js +6 -0
- package/tgsl/shellless.js +1 -8
- package/tgsl/wgslGenerator.d.ts +36 -0
- package/tgsl/wgslGenerator.js +144 -81
- package/types.d.ts +14 -4
- package/types.js +3 -3
- package/wgslExtensions.js +1 -2
package/std/numeric.d.ts
CHANGED
|
@@ -6,249 +6,195 @@ import { Infer } from "../shared/repr.js";
|
|
|
6
6
|
type NumVec = AnyNumericVecInstance;
|
|
7
7
|
declare function cpuAbs(value: number): number;
|
|
8
8
|
declare function cpuAbs<T extends NumVec | number>(value: T): T;
|
|
9
|
-
declare const abs: DualFn
|
|
9
|
+
declare const abs: DualFn;
|
|
10
10
|
declare function cpuAcos(value: number): number;
|
|
11
11
|
declare function cpuAcos<T extends AnyFloatVecInstance>(value: T): T;
|
|
12
|
-
declare const acos: DualFn
|
|
12
|
+
declare const acos: DualFn;
|
|
13
13
|
declare function cpuAcosh(value: number): number;
|
|
14
14
|
declare function cpuAcosh<T extends AnyFloatVecInstance>(value: T): T;
|
|
15
|
-
declare const acosh: DualFn
|
|
15
|
+
declare const acosh: DualFn;
|
|
16
16
|
declare function cpuAsin(value: number): number;
|
|
17
17
|
declare function cpuAsin<T extends AnyFloatVecInstance>(value: T): T;
|
|
18
|
-
declare const asin: DualFn
|
|
18
|
+
declare const asin: DualFn;
|
|
19
19
|
declare function cpuAsinh(value: number): number;
|
|
20
20
|
declare function cpuAsinh<T extends AnyFloatVecInstance>(value: T): T;
|
|
21
|
-
declare const asinh: DualFn
|
|
21
|
+
declare const asinh: DualFn;
|
|
22
22
|
declare function cpuAtan(value: number): number;
|
|
23
23
|
declare function cpuAtan<T extends AnyFloatVecInstance>(value: T): T;
|
|
24
|
-
declare const atan: DualFn
|
|
24
|
+
declare const atan: DualFn;
|
|
25
25
|
declare function cpuAtanh(value: number): number;
|
|
26
26
|
declare function cpuAtanh<T extends AnyFloatVecInstance>(value: T): T;
|
|
27
|
-
declare const atanh: DualFn
|
|
27
|
+
declare const atanh: DualFn;
|
|
28
28
|
declare function cpuAtan2(y: number, x: number): number;
|
|
29
29
|
declare function cpuAtan2<T extends AnyFloatVecInstance>(y: T, x: T): T;
|
|
30
|
-
declare const atan2: DualFn
|
|
30
|
+
declare const atan2: DualFn;
|
|
31
31
|
declare function cpuCeil(value: number): number;
|
|
32
32
|
declare function cpuCeil<T extends AnyFloatVecInstance>(value: T): T;
|
|
33
|
-
declare const ceil: DualFn
|
|
33
|
+
declare const ceil: DualFn;
|
|
34
34
|
declare function cpuClamp(value: number, low: number, high: number): number;
|
|
35
35
|
declare function cpuClamp<T extends NumVec | number>(value: T, low: T, high: T): T;
|
|
36
|
-
declare const clamp: DualFn
|
|
36
|
+
declare const clamp: DualFn;
|
|
37
37
|
declare function cpuCos(value: number): number;
|
|
38
38
|
declare function cpuCos<T extends AnyFloatVecInstance>(value: T): T;
|
|
39
|
-
declare const cos: DualFn
|
|
39
|
+
declare const cos: DualFn;
|
|
40
40
|
declare function cpuCosh(value: number): number;
|
|
41
41
|
declare function cpuCosh<T extends AnyFloatVecInstance>(value: T): T;
|
|
42
|
-
declare const cosh: DualFn
|
|
42
|
+
declare const cosh: DualFn;
|
|
43
43
|
declare function cpuCountLeadingZeros(value: number): number;
|
|
44
44
|
declare function cpuCountLeadingZeros<T extends AnyIntegerVecInstance>(value: T): T;
|
|
45
|
-
declare const countLeadingZeros: DualFn
|
|
45
|
+
declare const countLeadingZeros: DualFn;
|
|
46
46
|
declare function cpuCountOneBits(value: number): number;
|
|
47
47
|
declare function cpuCountOneBits<T extends AnyIntegerVecInstance>(value: T): T;
|
|
48
|
-
declare const countOneBits: DualFn
|
|
48
|
+
declare const countOneBits: DualFn;
|
|
49
49
|
declare function cpuCountTrailingZeros(value: number): number;
|
|
50
50
|
declare function cpuCountTrailingZeros<T extends AnyIntegerVecInstance>(value: T): T;
|
|
51
|
-
declare const countTrailingZeros: DualFn
|
|
52
|
-
declare const cross: DualFn
|
|
51
|
+
declare const countTrailingZeros: DualFn;
|
|
52
|
+
declare const cross: DualFn;
|
|
53
53
|
declare function cpuDegrees(value: number): number;
|
|
54
54
|
declare function cpuDegrees<T extends AnyFloatVecInstance>(value: T): T;
|
|
55
|
-
declare const degrees: DualFn
|
|
56
|
-
declare const determinant: DualFn
|
|
55
|
+
declare const degrees: DualFn;
|
|
56
|
+
declare const determinant: DualFn;
|
|
57
57
|
declare function cpuDistance(a: number, b: number): number;
|
|
58
58
|
declare function cpuDistance<T extends AnyFloatVecInstance>(a: T, b: T): number;
|
|
59
|
-
declare const distance: DualFn
|
|
60
|
-
declare const dot: DualFn
|
|
61
|
-
declare const dot4U8Packed: DualFn
|
|
62
|
-
declare const dot4I8Packed: DualFn
|
|
59
|
+
declare const distance: DualFn;
|
|
60
|
+
declare const dot: DualFn;
|
|
61
|
+
declare const dot4U8Packed: DualFn;
|
|
62
|
+
declare const dot4I8Packed: DualFn;
|
|
63
63
|
declare function cpuExp(value: number): number;
|
|
64
64
|
declare function cpuExp<T extends AnyFloatVecInstance>(value: T): T;
|
|
65
|
-
declare const exp: DualFn
|
|
65
|
+
declare const exp: DualFn;
|
|
66
66
|
declare function cpuExp2(value: number): number;
|
|
67
67
|
declare function cpuExp2<T extends AnyFloatVecInstance>(value: T): T;
|
|
68
|
-
declare const exp2: DualFn
|
|
68
|
+
declare const exp2: DualFn;
|
|
69
69
|
declare function cpuExtractBits(e: number, offset: number, count: number): number;
|
|
70
70
|
declare function cpuExtractBits<T extends AnyIntegerVecInstance>(e: T, offset: number, count: number): T;
|
|
71
|
-
declare const extractBits: DualFn
|
|
72
|
-
declare const faceForward: DualFn
|
|
71
|
+
declare const extractBits: DualFn;
|
|
72
|
+
declare const faceForward: DualFn;
|
|
73
73
|
declare function cpuFirstLeadingBit(value: number): number;
|
|
74
74
|
declare function cpuFirstLeadingBit<T extends AnyIntegerVecInstance>(value: T): T;
|
|
75
|
-
declare const firstLeadingBit: DualFn
|
|
75
|
+
declare const firstLeadingBit: DualFn;
|
|
76
76
|
declare function cpuFirstTrailingBit(value: number): number;
|
|
77
77
|
declare function cpuFirstTrailingBit<T extends AnyIntegerVecInstance>(value: T): T;
|
|
78
|
-
declare const firstTrailingBit: DualFn
|
|
78
|
+
declare const firstTrailingBit: DualFn;
|
|
79
79
|
declare function cpuFloor(value: number): number;
|
|
80
80
|
declare function cpuFloor<T extends AnyFloatVecInstance>(value: T): T;
|
|
81
|
-
declare const floor: DualFn
|
|
81
|
+
declare const floor: DualFn;
|
|
82
82
|
declare function cpuFma(e1: number, e2: number, e3: number): number;
|
|
83
83
|
declare function cpuFma<T extends AnyFloatVecInstance>(e1: T, e2: T, e3: T): T;
|
|
84
|
-
declare const fma: DualFn
|
|
84
|
+
declare const fma: DualFn;
|
|
85
85
|
declare function cpuFract(value: number): number;
|
|
86
86
|
declare function cpuFract<T extends AnyFloatVecInstance>(value: T): T;
|
|
87
|
-
declare const fract: DualFn
|
|
87
|
+
declare const fract: DualFn;
|
|
88
88
|
declare const FrexpResults: {
|
|
89
|
-
readonly f32: WgslStruct
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
readonly
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
readonly
|
|
98
|
-
fract: AbstractFloat;
|
|
99
|
-
exp: AbstractInt;
|
|
100
|
-
}>;
|
|
101
|
-
readonly vec2f: WgslStruct<{
|
|
102
|
-
fract: Vec2f;
|
|
103
|
-
exp: Vec2i;
|
|
104
|
-
}>;
|
|
105
|
-
readonly vec3f: WgslStruct<{
|
|
106
|
-
fract: Vec3f;
|
|
107
|
-
exp: Vec3i;
|
|
108
|
-
}>;
|
|
109
|
-
readonly vec4f: WgslStruct<{
|
|
110
|
-
fract: Vec4f;
|
|
111
|
-
exp: Vec4i;
|
|
112
|
-
}>;
|
|
113
|
-
readonly vec2h: WgslStruct<{
|
|
114
|
-
fract: Vec2h;
|
|
115
|
-
exp: Vec2i;
|
|
116
|
-
}>;
|
|
117
|
-
readonly vec3h: WgslStruct<{
|
|
118
|
-
fract: Vec3h;
|
|
119
|
-
exp: Vec3i;
|
|
120
|
-
}>;
|
|
121
|
-
readonly vec4h: WgslStruct<{
|
|
122
|
-
fract: Vec4h;
|
|
123
|
-
exp: Vec4i;
|
|
124
|
-
}>;
|
|
89
|
+
readonly f32: WgslStruct;
|
|
90
|
+
readonly f16: WgslStruct;
|
|
91
|
+
readonly abstractFloat: WgslStruct;
|
|
92
|
+
readonly vec2f: WgslStruct;
|
|
93
|
+
readonly vec3f: WgslStruct;
|
|
94
|
+
readonly vec4f: WgslStruct;
|
|
95
|
+
readonly vec2h: WgslStruct;
|
|
96
|
+
readonly vec3h: WgslStruct;
|
|
97
|
+
readonly vec4h: WgslStruct;
|
|
125
98
|
};
|
|
126
99
|
type FrexpOverload = {
|
|
127
100
|
(value: number): Infer<(typeof FrexpResults)['f32']>;
|
|
128
101
|
<T extends AnyFloatVecInstance>(value: T): Infer<(typeof FrexpResults)[T['kind']]>;
|
|
129
102
|
};
|
|
130
|
-
declare const frexp: DualFn
|
|
103
|
+
declare const frexp: DualFn;
|
|
131
104
|
declare function cpuInsertBits(e: number, newbits: number, offset: number, count: number): number;
|
|
132
105
|
declare function cpuInsertBits<T extends AnyIntegerVecInstance>(e: T, newbits: T, offset: number, count: number): T;
|
|
133
|
-
declare const insertBits: DualFn
|
|
106
|
+
declare const insertBits: DualFn;
|
|
134
107
|
declare function cpuInverseSqrt(value: number): number;
|
|
135
108
|
declare function cpuInverseSqrt<T extends AnyFloatVecInstance>(value: T): T;
|
|
136
|
-
declare const inverseSqrt: DualFn
|
|
109
|
+
declare const inverseSqrt: DualFn;
|
|
137
110
|
declare function cpuLdexp(e1: number, e2: number): number;
|
|
138
111
|
declare function cpuLdexp<T extends v2f | v2h>(e1: T, e2: v2i): T;
|
|
139
112
|
declare function cpuLdexp<T extends v3f | v3h>(e1: T, e2: v3i): T;
|
|
140
113
|
declare function cpuLdexp<T extends v4f | v4h>(e1: T, e2: v4i): T;
|
|
141
|
-
declare const ldexp: DualFn
|
|
114
|
+
declare const ldexp: DualFn;
|
|
142
115
|
declare function cpuLength(value: number): number;
|
|
143
116
|
declare function cpuLength<T extends AnyFloatVecInstance>(value: T): number;
|
|
144
|
-
declare const length: DualFn
|
|
117
|
+
declare const length: DualFn;
|
|
145
118
|
declare function cpuLog(value: number): number;
|
|
146
119
|
declare function cpuLog<T extends AnyFloatVecInstance>(value: T): T;
|
|
147
|
-
declare const log: DualFn
|
|
120
|
+
declare const log: DualFn;
|
|
148
121
|
declare function cpuLog2(value: number): number;
|
|
149
122
|
declare function cpuLog2<T extends AnyFloatVecInstance>(value: T): T;
|
|
150
|
-
declare const log2: DualFn
|
|
123
|
+
declare const log2: DualFn;
|
|
151
124
|
type VariadicOverload = {
|
|
152
125
|
(fst: number, ...rest: number[]): number;
|
|
153
126
|
<T extends NumVec>(fst: T, ...rest: T[]): T;
|
|
154
127
|
};
|
|
155
|
-
declare const max: DualFn
|
|
156
|
-
declare const min: DualFn
|
|
128
|
+
declare const max: DualFn;
|
|
129
|
+
declare const min: DualFn;
|
|
157
130
|
declare function cpuMix(e1: number, e2: number, e3: number): number;
|
|
158
131
|
declare function cpuMix<T extends AnyFloatVecInstance>(e1: T, e2: T, e3: number): T;
|
|
159
132
|
declare function cpuMix<T extends AnyFloatVecInstance>(e1: T, e2: T, e3: T): T;
|
|
160
|
-
declare const mix: DualFn
|
|
133
|
+
declare const mix: DualFn;
|
|
161
134
|
declare const ModfResult: {
|
|
162
|
-
readonly f32: WgslStruct
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
readonly
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
readonly
|
|
171
|
-
fract: AbstractFloat;
|
|
172
|
-
whole: AbstractFloat;
|
|
173
|
-
}>;
|
|
174
|
-
readonly vec2f: WgslStruct<{
|
|
175
|
-
fract: Vec2f;
|
|
176
|
-
whole: Vec2f;
|
|
177
|
-
}>;
|
|
178
|
-
readonly vec3f: WgslStruct<{
|
|
179
|
-
fract: Vec3f;
|
|
180
|
-
whole: Vec3f;
|
|
181
|
-
}>;
|
|
182
|
-
readonly vec4f: WgslStruct<{
|
|
183
|
-
fract: Vec4f;
|
|
184
|
-
whole: Vec4f;
|
|
185
|
-
}>;
|
|
186
|
-
readonly vec2h: WgslStruct<{
|
|
187
|
-
fract: Vec2h;
|
|
188
|
-
whole: Vec2h;
|
|
189
|
-
}>;
|
|
190
|
-
readonly vec3h: WgslStruct<{
|
|
191
|
-
fract: Vec3h;
|
|
192
|
-
whole: Vec3h;
|
|
193
|
-
}>;
|
|
194
|
-
readonly vec4h: WgslStruct<{
|
|
195
|
-
fract: Vec4h;
|
|
196
|
-
whole: Vec4h;
|
|
197
|
-
}>;
|
|
135
|
+
readonly f32: WgslStruct;
|
|
136
|
+
readonly f16: WgslStruct;
|
|
137
|
+
readonly abstractFloat: WgslStruct;
|
|
138
|
+
readonly vec2f: WgslStruct;
|
|
139
|
+
readonly vec3f: WgslStruct;
|
|
140
|
+
readonly vec4f: WgslStruct;
|
|
141
|
+
readonly vec2h: WgslStruct;
|
|
142
|
+
readonly vec3h: WgslStruct;
|
|
143
|
+
readonly vec4h: WgslStruct;
|
|
198
144
|
};
|
|
199
145
|
type ModfOverload = {
|
|
200
146
|
(value: number): Infer<(typeof ModfResult)['f32']>;
|
|
201
147
|
<T extends AnyFloatVecInstance>(value: T): Infer<(typeof ModfResult)[T['kind']]>;
|
|
202
148
|
};
|
|
203
149
|
declare const modf: ModfOverload;
|
|
204
|
-
declare const normalize: DualFn
|
|
150
|
+
declare const normalize: DualFn;
|
|
205
151
|
declare function powCpu(base: number, exponent: number): number;
|
|
206
152
|
declare function powCpu<T extends AnyFloatVecInstance>(base: T, exponent: T): T;
|
|
207
|
-
declare const pow: DualFn
|
|
153
|
+
declare const pow: DualFn;
|
|
208
154
|
declare function cpuQuantizeToF16(value: number): number;
|
|
209
155
|
declare function cpuQuantizeToF16<T extends AnyFloat32VecInstance>(value: T): T;
|
|
210
|
-
declare const quantizeToF16: DualFn
|
|
156
|
+
declare const quantizeToF16: DualFn;
|
|
211
157
|
declare function cpuRadians(value: number): number;
|
|
212
158
|
declare function cpuRadians<T extends AnyFloatVecInstance | number>(value: T): T;
|
|
213
|
-
declare const radians: DualFn
|
|
214
|
-
declare const reflect: DualFn
|
|
215
|
-
declare const refract: DualFn
|
|
159
|
+
declare const radians: DualFn;
|
|
160
|
+
declare const reflect: DualFn;
|
|
161
|
+
declare const refract: DualFn;
|
|
216
162
|
declare function cpuReverseBits(value: number): number;
|
|
217
163
|
declare function cpuReverseBits<T extends AnyIntegerVecInstance>(value: T): T;
|
|
218
|
-
declare const reverseBits: DualFn
|
|
164
|
+
declare const reverseBits: DualFn;
|
|
219
165
|
declare function cpuRound(value: number): number;
|
|
220
166
|
declare function cpuRound<T extends AnyFloatVecInstance>(value: T): T;
|
|
221
|
-
declare const round: DualFn
|
|
167
|
+
declare const round: DualFn;
|
|
222
168
|
declare function cpuSaturate(value: number): number;
|
|
223
169
|
declare function cpuSaturate<T extends AnyFloatVecInstance>(value: T): T;
|
|
224
|
-
declare const saturate: DualFn
|
|
170
|
+
declare const saturate: DualFn;
|
|
225
171
|
declare function cpuSign(e: number): number;
|
|
226
172
|
declare function cpuSign<T extends AnySignedVecInstance>(e: T): T;
|
|
227
|
-
declare const sign: DualFn
|
|
173
|
+
declare const sign: DualFn;
|
|
228
174
|
declare function cpuSin(value: number): number;
|
|
229
175
|
declare function cpuSin<T extends AnyFloatVecInstance>(value: T): T;
|
|
230
|
-
declare const sin: DualFn
|
|
176
|
+
declare const sin: DualFn;
|
|
231
177
|
declare function cpuSinh(value: number): number;
|
|
232
178
|
declare function cpuSinh<T extends AnyFloatVecInstance>(value: T): T;
|
|
233
|
-
declare const sinh: DualFn
|
|
179
|
+
declare const sinh: DualFn;
|
|
234
180
|
declare function cpuSmoothstep(edge0: number, edge1: number, x: number): number;
|
|
235
181
|
declare function cpuSmoothstep<T extends AnyFloatVecInstance>(edge0: T, edge1: T, x: T): T;
|
|
236
|
-
declare const smoothstep: DualFn
|
|
182
|
+
declare const smoothstep: DualFn;
|
|
237
183
|
declare function cpuSqrt(value: number): number;
|
|
238
184
|
declare function cpuSqrt<T extends AnyFloatVecInstance>(value: T): T;
|
|
239
|
-
declare const sqrt: DualFn
|
|
185
|
+
declare const sqrt: DualFn;
|
|
240
186
|
declare function cpuStep(edge: number, x: number): number;
|
|
241
187
|
declare function cpuStep<T extends AnyFloatVecInstance | number>(edge: T, x: T): T;
|
|
242
|
-
declare const step: DualFn
|
|
188
|
+
declare const step: DualFn;
|
|
243
189
|
declare function cpuTan(value: number): number;
|
|
244
190
|
declare function cpuTan<T extends AnyFloatVecInstance>(value: T): T;
|
|
245
|
-
declare const tan: DualFn
|
|
191
|
+
declare const tan: DualFn;
|
|
246
192
|
declare function cpuTanh(value: number): number;
|
|
247
193
|
declare function cpuTanh<T extends AnyFloatVecInstance>(value: T): T;
|
|
248
|
-
declare const tanh: DualFn
|
|
249
|
-
declare const transpose: DualFn
|
|
194
|
+
declare const tanh: DualFn;
|
|
195
|
+
declare const transpose: DualFn;
|
|
250
196
|
declare function cpuTrunc(value: number): number;
|
|
251
197
|
declare function cpuTrunc<T extends AnyFloatVecInstance>(value: T): T;
|
|
252
|
-
declare const trunc: DualFn
|
|
198
|
+
declare const trunc: DualFn;
|
|
253
199
|
//#endregion
|
|
254
200
|
export { abs, acos, acosh, asin, asinh, atan, atan2, atanh, ceil, clamp, cos, cosh, countLeadingZeros, countOneBits, countTrailingZeros, cross, degrees, determinant, distance, dot, dot4I8Packed, dot4U8Packed, exp, exp2, extractBits, faceForward, firstLeadingBit, firstTrailingBit, floor, fma, fract, frexp, insertBits, inverseSqrt, ldexp, length, log, log2, max, min, mix, modf, normalize, pow, quantizeToF16, radians, reflect, refract, reverseBits, round, saturate, sign, sin, sinh, smoothstep, sqrt, step, tan, tanh, transpose, trunc };
|
package/std/numeric.js
CHANGED
|
@@ -10,7 +10,6 @@ import { mat2x2f, mat3x3f, mat4x4f } from "../data/matrix.js";
|
|
|
10
10
|
import { smoothstepScalar } from "../data/numberOps.js";
|
|
11
11
|
import { VectorOps } from "../data/vectorOps.js";
|
|
12
12
|
import { mul, sub } from "./operators.js";
|
|
13
|
-
|
|
14
13
|
//#region src/std/numeric.ts
|
|
15
14
|
const unaryIdentitySignature = (arg) => {
|
|
16
15
|
return {
|
|
@@ -842,6 +841,5 @@ const trunc = dualImpl({
|
|
|
842
841
|
normalImpl: "CPU implementation for trunc not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues",
|
|
843
842
|
codegenImpl: (_ctx, [value]) => stitch`trunc(${value})`
|
|
844
843
|
});
|
|
845
|
-
|
|
846
844
|
//#endregion
|
|
847
|
-
export { abs, acos, acosh, asin, asinh, atan, atan2, atanh, ceil, clamp, cos, cosh, countLeadingZeros, countOneBits, countTrailingZeros, cross, degrees, determinant, distance, dot, dot4I8Packed, dot4U8Packed, exp, exp2, extractBits, faceForward, firstLeadingBit, firstTrailingBit, floor, fma, fract, frexp, insertBits, inverseSqrt, ldexp, length, log, log2, max, min, mix, modf, normalize, pow, quantizeToF16, radians, reflect, refract, reverseBits, round, saturate, sign, sin, sinh, smoothstep, sqrt, step, tan, tanh, transpose, trunc };
|
|
845
|
+
export { abs, acos, acosh, asin, asinh, atan, atan2, atanh, ceil, clamp, cos, cosh, countLeadingZeros, countOneBits, countTrailingZeros, cross, degrees, determinant, distance, dot, dot4I8Packed, dot4U8Packed, exp, exp2, extractBits, faceForward, firstLeadingBit, firstTrailingBit, floor, fma, fract, frexp, insertBits, inverseSqrt, ldexp, length, log, log2, max, min, mix, modf, normalize, pow, quantizeToF16, radians, reflect, refract, reverseBits, round, saturate, sign, sin, sinh, smoothstep, sqrt, step, tan, tanh, transpose, trunc };
|
package/std/operators.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DualFn } from "../types.js";
|
|
2
|
-
import { AnyMatInstance, AnyNumericVecInstance, mBaseForVec, vBaseForMat } from "../data/wgslTypes.js";
|
|
2
|
+
import { AnyIntegerVecInstance, AnyMatInstance, AnyNumericVecInstance, mBaseForVec, vBaseForMat, vecIToVecU } from "../data/wgslTypes.js";
|
|
3
3
|
|
|
4
4
|
//#region src/std/operators.d.ts
|
|
5
5
|
type NumVec = AnyNumericVecInstance;
|
|
@@ -9,13 +9,13 @@ declare function cpuAdd<T extends NumVec>(lhs: number, rhs: T): T;
|
|
|
9
9
|
declare function cpuAdd<T extends NumVec>(lhs: T, rhs: number): T;
|
|
10
10
|
declare function cpuAdd<T extends NumVec | Mat>(lhs: T, rhs: T): T;
|
|
11
11
|
declare function cpuAdd<Lhs extends number | NumVec | Mat, Rhs extends (Lhs extends number ? number | NumVec : Lhs extends NumVec ? number | Lhs : Lhs extends Mat ? Lhs : never)>(lhs: Lhs, rhs: Rhs): Lhs | Rhs;
|
|
12
|
-
declare const add: DualFn
|
|
12
|
+
declare const add: DualFn;
|
|
13
13
|
declare function cpuSub(lhs: number, rhs: number): number;
|
|
14
14
|
declare function cpuSub<T extends NumVec>(lhs: number, rhs: T): T;
|
|
15
15
|
declare function cpuSub<T extends NumVec>(lhs: T, rhs: number): T;
|
|
16
16
|
declare function cpuSub<T extends NumVec | Mat>(lhs: T, rhs: T): T;
|
|
17
17
|
declare function cpuSub<Lhs extends number | NumVec | Mat, Rhs extends (Lhs extends number ? number | NumVec : Lhs extends NumVec ? number | Lhs : Lhs extends Mat ? Lhs : never)>(lhs: Lhs, rhs: Rhs): Lhs | Rhs;
|
|
18
|
-
declare const sub: DualFn
|
|
18
|
+
declare const sub: DualFn;
|
|
19
19
|
declare function cpuMul(lhs: number, rhs: number): number;
|
|
20
20
|
declare function cpuMul<MV extends NumVec | Mat>(lhs: number, rhs: MV): MV;
|
|
21
21
|
declare function cpuMul<MV extends NumVec | Mat>(lhs: MV, rhs: number): MV;
|
|
@@ -24,12 +24,12 @@ declare function cpuMul<M extends Mat, V extends vBaseForMat<M>>(lhs: V, rhs: M)
|
|
|
24
24
|
declare function cpuMul<M extends Mat, V extends vBaseForMat<M>>(lhs: M, rhs: V): V;
|
|
25
25
|
declare function cpuMul<M extends Mat>(lhs: M, rhs: M): M;
|
|
26
26
|
declare function cpuMul<Lhs extends number | NumVec | Mat, Rhs extends (Lhs extends number ? number | NumVec | Mat : Lhs extends NumVec ? number | Lhs | mBaseForVec<Lhs> : Lhs extends Mat ? number | vBaseForMat<Lhs> | Lhs : never)>(lhs: Lhs, rhs: Rhs): Lhs | Rhs;
|
|
27
|
-
declare const mul: DualFn
|
|
27
|
+
declare const mul: DualFn;
|
|
28
28
|
declare function cpuDiv(lhs: number, rhs: number): number;
|
|
29
29
|
declare function cpuDiv<T extends NumVec>(lhs: T, rhs: T): T;
|
|
30
30
|
declare function cpuDiv<T extends NumVec>(lhs: number, rhs: T): T;
|
|
31
31
|
declare function cpuDiv<T extends NumVec>(lhs: T, rhs: number): T;
|
|
32
|
-
declare const div: DualFn
|
|
32
|
+
declare const div: DualFn;
|
|
33
33
|
type ModOverload = {
|
|
34
34
|
(a: number, b: number): number;
|
|
35
35
|
<T extends NumVec>(a: T, b: T): T;
|
|
@@ -40,9 +40,17 @@ type ModOverload = {
|
|
|
40
40
|
* @privateRemarks
|
|
41
41
|
* Both JS and WGSL implementations use truncated definition of modulo
|
|
42
42
|
*/
|
|
43
|
-
declare const mod: DualFn
|
|
43
|
+
declare const mod: DualFn;
|
|
44
44
|
declare function cpuNeg(value: number): number;
|
|
45
45
|
declare function cpuNeg<T extends NumVec>(value: T): T;
|
|
46
|
-
declare const neg: DualFn
|
|
46
|
+
declare const neg: DualFn;
|
|
47
|
+
declare function cpuBitShiftLeft(lhs: number, rhs: number): number;
|
|
48
|
+
declare function cpuBitShiftLeft<T extends AnyIntegerVecInstance>(lhs: T, rhs: number): T;
|
|
49
|
+
declare function cpuBitShiftLeft<T extends AnyIntegerVecInstance>(lhs: T, rhs: vecIToVecU<T>): T;
|
|
50
|
+
declare const bitShiftLeft: DualFn;
|
|
51
|
+
declare function cpuBitShiftRight(lhs: number, rhs: number): number;
|
|
52
|
+
declare function cpuBitShiftRight<T extends AnyIntegerVecInstance>(lhs: T, rhs: number): T;
|
|
53
|
+
declare function cpuBitShiftRight<T extends AnyIntegerVecInstance>(lhs: T, rhs: vecIToVecU<T>): T;
|
|
54
|
+
declare const bitShiftRight: DualFn;
|
|
47
55
|
//#endregion
|
|
48
|
-
export { add, div, mod, mul, neg, sub };
|
|
56
|
+
export { add, bitShiftLeft, bitShiftRight, div, mod, mul, neg, sub };
|
package/std/operators.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { isFloat32VecInstance, isMat, isMatInstance, isVec, isVecInstance } from "../data/wgslTypes.js";
|
|
1
|
+
import { isFloat32VecInstance, isInteger32VecInstance, isMat, isMatInstance, isUint32VecInstance, isVec, isVecInstance } from "../data/wgslTypes.js";
|
|
2
2
|
import { SignatureNotSupportedError } from "../errors.js";
|
|
3
3
|
import { stitch } from "../core/resolve/stitch.js";
|
|
4
4
|
import { unify } from "../tgsl/conversion.js";
|
|
5
|
-
import { abstractFloat, f16, f32 } from "../data/numeric.js";
|
|
6
|
-
import { vecTypeToConstructor } from "../data/vector.js";
|
|
5
|
+
import { abstractFloat, f16, f32, i32, u32 } from "../data/numeric.js";
|
|
6
|
+
import { vec2i, vec2u, vec3i, vec3u, vec4i, vec4u, vecTypeToConstructor } from "../data/vector.js";
|
|
7
7
|
import { dualImpl } from "../core/function/dualImpl.js";
|
|
8
8
|
import { VectorOps } from "../data/vectorOps.js";
|
|
9
|
-
|
|
10
9
|
//#region src/std/operators.ts
|
|
11
10
|
const getPrimitive = (t) => "primitive" in t ? t.primitive : t;
|
|
12
11
|
const makeBinarySignature = (opts) => (lhs, rhs) => {
|
|
@@ -148,6 +147,81 @@ const neg = dualImpl({
|
|
|
148
147
|
normalImpl: cpuNeg,
|
|
149
148
|
codegenImpl: (_ctx, [arg]) => stitch`-(${arg})`
|
|
150
149
|
});
|
|
151
|
-
|
|
150
|
+
const anyConcreteInteger = [
|
|
151
|
+
i32,
|
|
152
|
+
u32,
|
|
153
|
+
vec2i,
|
|
154
|
+
vec3i,
|
|
155
|
+
vec4i,
|
|
156
|
+
vec2u,
|
|
157
|
+
vec3u,
|
|
158
|
+
vec4u
|
|
159
|
+
];
|
|
160
|
+
const intVecToUnsignedVec = {
|
|
161
|
+
vec2i: vec2u,
|
|
162
|
+
vec2u,
|
|
163
|
+
vec3i: vec3u,
|
|
164
|
+
vec3u,
|
|
165
|
+
vec4i: vec4u,
|
|
166
|
+
vec4u
|
|
167
|
+
};
|
|
168
|
+
const bitShiftSignature = (lhs, rhs) => {
|
|
169
|
+
const lhsUnified = unify([lhs], anyConcreteInteger)?.[0];
|
|
170
|
+
if (!lhsUnified) throw new SignatureNotSupportedError([lhs], anyConcreteInteger);
|
|
171
|
+
let rhsType;
|
|
172
|
+
if (isVec(lhsUnified)) {
|
|
173
|
+
const cc = lhsUnified.componentCount;
|
|
174
|
+
const vecU = cc === 2 ? vec2u : cc === 3 ? vec3u : vec4u;
|
|
175
|
+
const rhsUnified = unify([rhs], [u32, vecU])?.[0];
|
|
176
|
+
if (!rhsUnified) throw new SignatureNotSupportedError([rhs], [u32, vecU]);
|
|
177
|
+
rhsType = rhsUnified;
|
|
178
|
+
} else rhsType = u32;
|
|
179
|
+
return {
|
|
180
|
+
argTypes: [lhsUnified, rhsType],
|
|
181
|
+
returnType: lhsUnified
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
function cpuBitShiftLeft(lhs, rhs) {
|
|
185
|
+
if (typeof lhs === "number" && typeof rhs === "number") return lhs << rhs;
|
|
186
|
+
if (isInteger32VecInstance(lhs) && isUint32VecInstance(rhs) && lhs.length == rhs.length) return VectorOps.bitShiftLeft[lhs.kind](lhs, rhs);
|
|
187
|
+
if (isInteger32VecInstance(lhs) && typeof rhs === "number") {
|
|
188
|
+
const rhsVec = intVecToUnsignedVec[lhs.kind](rhs);
|
|
189
|
+
return VectorOps.bitShiftLeft[lhs.kind](lhs, rhsVec);
|
|
190
|
+
}
|
|
191
|
+
throw new Error("bitShiftLeft called with invalid arguments, expected types: number or integer vector (rhs must be the same arity as lhs).");
|
|
192
|
+
}
|
|
193
|
+
const bitShiftLeft = dualImpl({
|
|
194
|
+
name: "bitShiftLeft",
|
|
195
|
+
signature: bitShiftSignature,
|
|
196
|
+
normalImpl: cpuBitShiftLeft,
|
|
197
|
+
codegenImpl: (_ctx, [lhs, rhs]) => {
|
|
198
|
+
if (isVec(lhs.dataType) && !isVec(rhs.dataType)) {
|
|
199
|
+
const cc = lhs.dataType.componentCount;
|
|
200
|
+
return stitch`(${lhs} << ${cc === 2 ? "vec2u" : cc === 3 ? "vec3u" : "vec4u"}(${rhs}))`;
|
|
201
|
+
}
|
|
202
|
+
return stitch`(${lhs} << ${rhs})`;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
function cpuBitShiftRight(lhs, rhs) {
|
|
206
|
+
if (typeof lhs === "number" && typeof rhs === "number") return lhs >> rhs;
|
|
207
|
+
if (isInteger32VecInstance(lhs) && isUint32VecInstance(rhs) && lhs.length == rhs.length) return VectorOps.bitShiftRight[lhs.kind](lhs, rhs);
|
|
208
|
+
if (isInteger32VecInstance(lhs) && typeof rhs === "number") {
|
|
209
|
+
const rhsVec = intVecToUnsignedVec[lhs.kind](rhs);
|
|
210
|
+
return VectorOps.bitShiftRight[lhs.kind](lhs, rhsVec);
|
|
211
|
+
}
|
|
212
|
+
throw new Error("bitShiftRight called with invalid arguments, expected types: number or integer vector (rhs must be the same arity as lhs).");
|
|
213
|
+
}
|
|
214
|
+
const bitShiftRight = dualImpl({
|
|
215
|
+
name: "bitShiftRight",
|
|
216
|
+
signature: bitShiftSignature,
|
|
217
|
+
normalImpl: cpuBitShiftRight,
|
|
218
|
+
codegenImpl: (_ctx, [lhs, rhs]) => {
|
|
219
|
+
if (isVec(lhs.dataType) && !isVec(rhs.dataType)) {
|
|
220
|
+
const cc = lhs.dataType.componentCount;
|
|
221
|
+
return stitch`(${lhs} >> ${cc === 2 ? "vec2u" : cc === 3 ? "vec3u" : "vec4u"}(${rhs}))`;
|
|
222
|
+
}
|
|
223
|
+
return stitch`(${lhs} >> ${rhs})`;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
152
226
|
//#endregion
|
|
153
|
-
export { add, div, mod, mul, neg, sub };
|
|
227
|
+
export { add, bitShiftLeft, bitShiftRight, div, mod, mul, neg, sub };
|
package/std/packing.d.ts
CHANGED
|
@@ -6,21 +6,21 @@ import { v2f, v4f } from "../data/wgslTypes.js";
|
|
|
6
6
|
* @privateRemarks
|
|
7
7
|
* https://gpuweb.github.io/gpuweb/wgsl/#unpack2x16float-builtin
|
|
8
8
|
*/
|
|
9
|
-
declare const unpack2x16float: DualFn
|
|
9
|
+
declare const unpack2x16float: DualFn;
|
|
10
10
|
/**
|
|
11
11
|
* @privateRemarks
|
|
12
12
|
* https://gpuweb.github.io/gpuweb/wgsl/#pack2x16float-builtin
|
|
13
13
|
*/
|
|
14
|
-
declare const pack2x16float: DualFn
|
|
14
|
+
declare const pack2x16float: DualFn;
|
|
15
15
|
/**
|
|
16
16
|
* @privateRemarks
|
|
17
17
|
* https://gpuweb.github.io/gpuweb/wgsl/#unpack4x8unorm-builtin
|
|
18
18
|
*/
|
|
19
|
-
declare const unpack4x8unorm: DualFn
|
|
19
|
+
declare const unpack4x8unorm: DualFn;
|
|
20
20
|
/**
|
|
21
21
|
* @privateRemarks
|
|
22
22
|
* https://gpuweb.github.io/gpuweb/wgsl/#pack4x8unorm-builtin
|
|
23
23
|
*/
|
|
24
|
-
declare const pack4x8unorm: DualFn
|
|
24
|
+
declare const pack4x8unorm: DualFn;
|
|
25
25
|
//#endregion
|
|
26
26
|
export { pack2x16float, pack4x8unorm, unpack2x16float, unpack4x8unorm };
|
package/std/packing.js
CHANGED
|
@@ -3,7 +3,6 @@ import { u32 } from "../data/numeric.js";
|
|
|
3
3
|
import { vec2f, vec4f } from "../data/vector.js";
|
|
4
4
|
import { dualImpl } from "../core/function/dualImpl.js";
|
|
5
5
|
import * as TB from "typed-binary";
|
|
6
|
-
|
|
7
6
|
//#region src/std/packing.ts
|
|
8
7
|
/**
|
|
9
8
|
* @privateRemarks
|
|
@@ -81,6 +80,5 @@ const pack4x8unorm = dualImpl({
|
|
|
81
80
|
},
|
|
82
81
|
codegenImpl: (_ctx, [e]) => stitch`pack4x8unorm(${e})`
|
|
83
82
|
});
|
|
84
|
-
|
|
85
83
|
//#endregion
|
|
86
|
-
export { pack2x16float, pack4x8unorm, unpack2x16float, unpack4x8unorm };
|
|
84
|
+
export { pack2x16float, pack4x8unorm, unpack2x16float, unpack4x8unorm };
|
package/std/range.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TgpuComptime } from "../core/function/comptime.js";
|
|
2
|
+
//#region src/std/range.d.ts
|
|
3
|
+
interface TgpuRange extends Array<number> {
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
step: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Returns an array of values between `start` (inclusive) and `end` (exclusive) with the given `step`.
|
|
10
|
+
*
|
|
11
|
+
* If only one argument is provided, it is interpreted as `end`, with `start=0` and `step=1`.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* let result = d.f32(1);
|
|
15
|
+
* for (const i of std.range(5)) {
|
|
16
|
+
* result *= i + 1;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Can also be combined with `tgpu.unroll` to unroll a specific number of iterations.
|
|
21
|
+
*/
|
|
22
|
+
declare const range: TgpuComptime;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { range };
|
package/std/range.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { comptime } from "../core/function/comptime.js";
|
|
2
|
+
//#region src/std/range.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns an array of values between `start` (inclusive) and `end` (exclusive) with the given `step`.
|
|
5
|
+
*
|
|
6
|
+
* If only one argument is provided, it is interpreted as `end`, with `start=0` and `step=1`.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* let result = d.f32(1);
|
|
10
|
+
* for (const i of std.range(5)) {
|
|
11
|
+
* result *= i + 1;
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Can also be combined with `tgpu.unroll` to unroll a specific number of iterations.
|
|
16
|
+
*/
|
|
17
|
+
const range = comptime((start, end, step = 1) => {
|
|
18
|
+
if (end === void 0) {
|
|
19
|
+
end = start;
|
|
20
|
+
start = 0;
|
|
21
|
+
}
|
|
22
|
+
if (!Number.isInteger(start)) throw new Error(`'start' must be an integer, got ${start}`);
|
|
23
|
+
if (!Number.isInteger(end)) throw new Error(`'end' must be an integer, got ${end}`);
|
|
24
|
+
if (!Number.isInteger(step) || step === 0) throw new Error(`'step' must be a non-zero integer, got ${step}`);
|
|
25
|
+
const result = [];
|
|
26
|
+
result.start = start;
|
|
27
|
+
result.end = end;
|
|
28
|
+
result.step = step;
|
|
29
|
+
if (Math.sign(step) !== Math.sign(end - start)) return result;
|
|
30
|
+
if (step > 0) for (let i = start; i < end; i += step) result.push(i);
|
|
31
|
+
if (step < 0) for (let i = start; i > end; i += step) result.push(i);
|
|
32
|
+
return result;
|
|
33
|
+
});
|
|
34
|
+
function isTgpuRange(value) {
|
|
35
|
+
return Array.isArray(value) && "start" in value && "end" in value && "step" in value;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { isTgpuRange, range };
|