typegpu 0.12.4 → 0.12.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.mjs +39 -67
- package/common/index.d.ts +1 -0
- package/common/index.js +1 -0
- package/common/writeChannels.d.ts +31 -0
- package/common/writeChannels.js +32 -0
- package/core/commandEncoder/computePass.d.ts +13 -0
- package/core/commandEncoder/computePass.js +5 -2
- package/core/commandEncoder/renderPass.d.ts +18 -4
- package/core/commandEncoder/renderPass.js +6 -2
- package/core/declare/tgpuDeclare.d.ts +11 -0
- package/core/declare/tgpuDeclare.js +1 -1
- package/core/immediate/immediateVar.d.ts +52 -0
- package/core/immediate/immediateVar.js +149 -0
- package/core/pipeline/computePipeline.d.ts +23 -0
- package/core/pipeline/computePipeline.js +26 -9
- package/core/pipeline/drawState.d.ts +8 -4
- package/core/pipeline/drawState.js +41 -51
- package/core/pipeline/priors.js +1 -0
- package/core/pipeline/renderPipeline.d.ts +24 -1
- package/core/pipeline/renderPipeline.js +18 -1
- package/core/root/init.js +3 -0
- package/core/root/rootTypes.d.ts +11 -0
- package/core/slot/slotTypes.d.ts +2 -1
- package/core/texture/texture.d.ts +20 -14
- package/core/texture/texture.js +70 -65
- package/core/texture/textureUtils.d.ts +3 -6
- package/core/texture/textureUtils.js +142 -165
- package/core/texture/textureWrite.d.ts +61 -0
- package/core/texture/textureWrite.js +59 -0
- package/data/dataIO.d.ts +2 -2
- package/data/generalizeFn.d.ts +17 -1
- package/data/generalizeFn.js +39 -2
- package/data/snippet.d.ts +5 -1
- package/data/snippet.js +1 -0
- package/data/wgslTypes.d.ts +1 -1
- package/errors.d.ts +7 -0
- package/errors.js +15 -0
- package/indexNamedExports.d.ts +5 -2
- package/indexNamedExports.js +2 -1
- package/internal.d.ts +1 -1
- package/internal.js +1 -1
- package/package.json +2 -2
- package/resolutionCtx.d.ts +5 -0
- package/resolutionCtx.js +11 -0
- package/serial/restore.d.ts +3 -1
- package/serial/restore.js +2 -0
- package/shared/meta.js +1 -1
- package/shared/symbols.js +1 -1
- package/shared/tseynit.d.ts +1 -0
- package/shared/tseynit.js +39 -7
- package/shared/utilityTypes.d.ts +1 -1
- package/std/atomic.d.ts +13 -0
- package/std/atomic.js +63 -29
- package/std/bitcast.js +4 -0
- package/std/boolean.d.ts +1 -1
- package/std/boolean.js +35 -21
- package/std/derivative.js +17 -12
- package/std/index.d.ts +4 -4
- package/std/index.js +5 -5
- package/std/numeric.d.ts +5 -1
- package/std/numeric.js +75 -8
- package/std/operators.d.ts +2 -2
- package/std/operators.js +29 -17
- package/std/packing.d.ts +61 -1
- package/std/packing.js +214 -25
- package/std/subgroup.d.ts +4 -0
- package/std/subgroup.js +34 -0
- package/std/texture.d.ts +13 -0
- package/std/texture.js +48 -0
- package/tgpuUnstable.d.ts +1 -0
- package/tgpuUnstable.js +1 -0
- package/tgsl/conversion.d.ts +2 -0
- package/tgsl/conversion.js +3 -0
- package/tgsl/shaderGenerator.d.ts +1 -1
- package/tgsl/wgslGenerator.d.ts +5 -0
- package/tgsl/wgslGenerator.js +218 -50
- package/types.d.ts +9 -1
- package/types.js +5 -0
package/std/atomic.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { dualImpl } from "../core/function/dualImpl.js";
|
|
2
2
|
import { stitch } from "../core/resolve/stitch.js";
|
|
3
|
-
import {
|
|
3
|
+
import { unptr } from "../data/dataTypes.js";
|
|
4
|
+
import { bool, i32, u32 } from "../data/numeric.js";
|
|
5
|
+
import { derefSnippet } from "../data/ref.js";
|
|
6
|
+
import { abstruct } from "../data/struct.js";
|
|
4
7
|
import { isAtomic, Void, } from "../data/wgslTypes.js";
|
|
5
8
|
import { safeStringify } from "../shared/stringify.js";
|
|
6
9
|
export const workgroupBarrier = dualImpl({
|
|
@@ -24,33 +27,40 @@ export const textureBarrier = dualImpl({
|
|
|
24
27
|
codegenImpl: () => 'textureBarrier()',
|
|
25
28
|
sideEffects: true,
|
|
26
29
|
});
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
export const workgroupUniformLoad = dualImpl({
|
|
31
|
+
name: 'workgroupUniformLoad',
|
|
32
|
+
normalImpl: 'workgroupUniformLoad is not supported outside of CODEGEN mode.',
|
|
33
|
+
signature: (value) => {
|
|
34
|
+
const inner = unptr(value);
|
|
35
|
+
return {
|
|
36
|
+
argTypes: [value],
|
|
37
|
+
returnType: isAtomic(inner) ? inner.inner : inner,
|
|
38
|
+
};
|
|
36
39
|
},
|
|
37
|
-
codegenImpl: (_ctx, [
|
|
40
|
+
codegenImpl: (_ctx, [value]) => stitch `workgroupUniformLoad(&${derefSnippet(value)})`,
|
|
38
41
|
sideEffects: true,
|
|
39
42
|
});
|
|
40
|
-
const
|
|
41
|
-
|
|
43
|
+
const atomicNormalError = 'Atomic operations are not supported outside of CODEGEN mode.';
|
|
44
|
+
const unwrapAtomic = (a) => {
|
|
45
|
+
const inner = unptr(a);
|
|
46
|
+
if (!isAtomic(inner)) {
|
|
42
47
|
throw new Error(`Invalid atomic type: ${safeStringify(a)}`);
|
|
43
48
|
}
|
|
44
|
-
return
|
|
45
|
-
argTypes: [a, a.inner.type === 'u32' ? u32 : i32],
|
|
46
|
-
returnType: Void,
|
|
47
|
-
};
|
|
49
|
+
return inner;
|
|
48
50
|
};
|
|
51
|
+
export const atomicLoad = dualImpl({
|
|
52
|
+
name: 'atomicLoad',
|
|
53
|
+
normalImpl: atomicNormalError,
|
|
54
|
+
signature: (a) => ({ argTypes: [a], returnType: unwrapAtomic(a).inner }),
|
|
55
|
+
codegenImpl: (_ctx, [a]) => stitch `atomicLoad(&${derefSnippet(a)})`,
|
|
56
|
+
sideEffects: true,
|
|
57
|
+
});
|
|
58
|
+
const atomicActionSignature = (a) => ({
|
|
59
|
+
argTypes: [a, unwrapAtomic(a).inner.type === 'u32' ? u32 : i32],
|
|
60
|
+
returnType: Void,
|
|
61
|
+
});
|
|
49
62
|
const atomicOpSignature = (a) => {
|
|
50
|
-
|
|
51
|
-
throw new Error(`Invalid atomic type: ${safeStringify(a)}`);
|
|
52
|
-
}
|
|
53
|
-
const paramType = a.inner.type === 'u32' ? u32 : i32;
|
|
63
|
+
const paramType = unwrapAtomic(a).inner.type === 'u32' ? u32 : i32;
|
|
54
64
|
return {
|
|
55
65
|
argTypes: [a, paramType],
|
|
56
66
|
returnType: paramType,
|
|
@@ -60,55 +70,79 @@ export const atomicStore = dualImpl({
|
|
|
60
70
|
name: 'atomicStore',
|
|
61
71
|
normalImpl: atomicNormalError,
|
|
62
72
|
signature: atomicActionSignature,
|
|
63
|
-
codegenImpl: (_ctx, [a, value]) => stitch `atomicStore(&${a}, ${value})`,
|
|
73
|
+
codegenImpl: (_ctx, [a, value]) => stitch `atomicStore(&${derefSnippet(a)}, ${value})`,
|
|
64
74
|
sideEffects: true,
|
|
65
75
|
});
|
|
66
76
|
export const atomicAdd = dualImpl({
|
|
67
77
|
name: 'atomicAdd',
|
|
68
78
|
normalImpl: atomicNormalError,
|
|
69
79
|
signature: atomicOpSignature,
|
|
70
|
-
codegenImpl: (_ctx, [a, value]) => stitch `atomicAdd(&${a}, ${value})`,
|
|
80
|
+
codegenImpl: (_ctx, [a, value]) => stitch `atomicAdd(&${derefSnippet(a)}, ${value})`,
|
|
71
81
|
sideEffects: true,
|
|
72
82
|
});
|
|
73
83
|
export const atomicSub = dualImpl({
|
|
74
84
|
name: 'atomicSub',
|
|
75
85
|
normalImpl: atomicNormalError,
|
|
76
86
|
signature: atomicOpSignature,
|
|
77
|
-
codegenImpl: (_ctx, [a, value]) => stitch `atomicSub(&${a}, ${value})`,
|
|
87
|
+
codegenImpl: (_ctx, [a, value]) => stitch `atomicSub(&${derefSnippet(a)}, ${value})`,
|
|
78
88
|
sideEffects: true,
|
|
79
89
|
});
|
|
80
90
|
export const atomicMax = dualImpl({
|
|
81
91
|
name: 'atomicMax',
|
|
82
92
|
normalImpl: atomicNormalError,
|
|
83
93
|
signature: atomicOpSignature,
|
|
84
|
-
codegenImpl: (_ctx, [a, value]) => stitch `atomicMax(&${a}, ${value})`,
|
|
94
|
+
codegenImpl: (_ctx, [a, value]) => stitch `atomicMax(&${derefSnippet(a)}, ${value})`,
|
|
85
95
|
sideEffects: true,
|
|
86
96
|
});
|
|
87
97
|
export const atomicMin = dualImpl({
|
|
88
98
|
name: 'atomicMin',
|
|
89
99
|
normalImpl: atomicNormalError,
|
|
90
100
|
signature: atomicOpSignature,
|
|
91
|
-
codegenImpl: (_ctx, [a, value]) => stitch `atomicMin(&${a}, ${value})`,
|
|
101
|
+
codegenImpl: (_ctx, [a, value]) => stitch `atomicMin(&${derefSnippet(a)}, ${value})`,
|
|
92
102
|
sideEffects: true,
|
|
93
103
|
});
|
|
94
104
|
export const atomicAnd = dualImpl({
|
|
95
105
|
name: 'atomicAnd',
|
|
96
106
|
normalImpl: atomicNormalError,
|
|
97
107
|
signature: atomicOpSignature,
|
|
98
|
-
codegenImpl: (_ctx, [a, value]) => stitch `atomicAnd(&${a}, ${value})`,
|
|
108
|
+
codegenImpl: (_ctx, [a, value]) => stitch `atomicAnd(&${derefSnippet(a)}, ${value})`,
|
|
99
109
|
sideEffects: true,
|
|
100
110
|
});
|
|
101
111
|
export const atomicOr = dualImpl({
|
|
102
112
|
name: 'atomicOr',
|
|
103
113
|
normalImpl: atomicNormalError,
|
|
104
114
|
signature: atomicOpSignature,
|
|
105
|
-
codegenImpl: (_ctx, [a, value]) => stitch `atomicOr(&${a}, ${value})`,
|
|
115
|
+
codegenImpl: (_ctx, [a, value]) => stitch `atomicOr(&${derefSnippet(a)}, ${value})`,
|
|
106
116
|
sideEffects: true,
|
|
107
117
|
});
|
|
108
118
|
export const atomicXor = dualImpl({
|
|
109
119
|
name: 'atomicXor',
|
|
110
120
|
normalImpl: atomicNormalError,
|
|
111
121
|
signature: atomicOpSignature,
|
|
112
|
-
codegenImpl: (_ctx, [a, value]) => stitch `atomicXor(&${a}, ${value})`,
|
|
122
|
+
codegenImpl: (_ctx, [a, value]) => stitch `atomicXor(&${derefSnippet(a)}, ${value})`,
|
|
123
|
+
sideEffects: true,
|
|
124
|
+
});
|
|
125
|
+
export const atomicExchange = dualImpl({
|
|
126
|
+
name: 'atomicExchange',
|
|
127
|
+
normalImpl: atomicNormalError,
|
|
128
|
+
signature: atomicOpSignature,
|
|
129
|
+
codegenImpl: (_ctx, [a, value]) => stitch `atomicExchange(&${derefSnippet(a)}, ${value})`,
|
|
130
|
+
sideEffects: true,
|
|
131
|
+
});
|
|
132
|
+
const AtomicCompareExchangeResults = {
|
|
133
|
+
i32: abstruct({ old_value: i32, exchanged: bool }),
|
|
134
|
+
u32: abstruct({ old_value: u32, exchanged: bool }),
|
|
135
|
+
};
|
|
136
|
+
export const atomicCompareExchangeWeak = dualImpl({
|
|
137
|
+
name: 'atomicCompareExchangeWeak',
|
|
138
|
+
normalImpl: atomicNormalError,
|
|
139
|
+
signature: (a) => {
|
|
140
|
+
const inner = unwrapAtomic(a).inner.type === 'u32' ? u32 : i32;
|
|
141
|
+
return {
|
|
142
|
+
argTypes: [a, inner, inner],
|
|
143
|
+
returnType: AtomicCompareExchangeResults[inner.type],
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
codegenImpl: (_ctx, [a, compare, value]) => stitch `atomicCompareExchangeWeak(&${derefSnippet(a)}, ${compare}, ${value})`,
|
|
113
147
|
sideEffects: true,
|
|
114
148
|
});
|
package/std/bitcast.js
CHANGED
|
@@ -9,6 +9,7 @@ import { SignatureNotSupportedError } from "../errors.js";
|
|
|
9
9
|
import { getName } from "../shared/meta.js";
|
|
10
10
|
import { comptime } from "../core/function/comptime.js";
|
|
11
11
|
import { coerceToSnippet } from "../tgsl/generationHelpers.js";
|
|
12
|
+
import { f32Kind, u32Kind, assertKind } from "../data/generalizeFn.js";
|
|
12
13
|
const u32AllowedSchemas = [u32, vec2u, vec3u, vec4u];
|
|
13
14
|
// TODO(#2731): Remove deprecated bitcasts. Remember about cpu implementations.
|
|
14
15
|
/**
|
|
@@ -17,6 +18,7 @@ const u32AllowedSchemas = [u32, vec2u, vec3u, vec4u];
|
|
|
17
18
|
export const bitcastU32toF32 = dualImpl({
|
|
18
19
|
name: 'bitcastU32toF32',
|
|
19
20
|
normalImpl: ((value) => {
|
|
21
|
+
assertKind(value, u32Kind);
|
|
20
22
|
if (typeof value === 'number') {
|
|
21
23
|
return bitcastU32toF32Impl(value);
|
|
22
24
|
}
|
|
@@ -49,6 +51,7 @@ export const bitcastU32toF32 = dualImpl({
|
|
|
49
51
|
export const bitcastU32toI32 = dualImpl({
|
|
50
52
|
name: 'bitcastU32toI32',
|
|
51
53
|
normalImpl: ((value) => {
|
|
54
|
+
assertKind(value, u32Kind);
|
|
52
55
|
if (typeof value === 'number') {
|
|
53
56
|
return bitcastU32toI32Impl(value);
|
|
54
57
|
}
|
|
@@ -82,6 +85,7 @@ const f32AllowedSchemas = [f32, vec2f, vec3f, vec4f];
|
|
|
82
85
|
export const bitcastF32toU32 = dualImpl({
|
|
83
86
|
name: 'bitcastF32toU32',
|
|
84
87
|
normalImpl: ((value) => {
|
|
88
|
+
assertKind(value, f32Kind);
|
|
85
89
|
if (typeof value === 'number') {
|
|
86
90
|
return bitcastF32toU32Impl(value);
|
|
87
91
|
}
|
package/std/boolean.d.ts
CHANGED
|
@@ -93,7 +93,7 @@ export declare const and: import("../types.ts").DualFn<(<T extends AnyBooleanVec
|
|
|
93
93
|
* all(vec2b(false, true)) // returns false
|
|
94
94
|
* all(vec3b(true, true, true)) // returns true
|
|
95
95
|
*/
|
|
96
|
-
export declare const all: import("../types.ts").DualFn<(value: AnyBooleanVecInstance) => boolean>;
|
|
96
|
+
export declare const all: import("../types.ts").DualFn<(value: boolean | AnyBooleanVecInstance) => boolean>;
|
|
97
97
|
/**
|
|
98
98
|
* Returns `true` if any component of `value` is true.
|
|
99
99
|
* @example
|
package/std/boolean.js
CHANGED
|
@@ -4,9 +4,9 @@ import { bool, f16, f32, i32, u32 } from "../data/numeric.js";
|
|
|
4
4
|
import { isSnippetNumeric, snip } from "../data/snippet.js";
|
|
5
5
|
import { vec2b, vec2f, vec2h, vec2i, vec2u, vec3b, vec3f, vec3h, vec3i, vec3u, vec4b, vec4f, vec4h, vec4i, vec4u, } from "../data/vector.js";
|
|
6
6
|
import { VectorOps } from "../data/vectorOps.js";
|
|
7
|
-
import { generalizeBoolFn, generalizeFn } from "../data/generalizeFn.js";
|
|
8
|
-
import { isBool, isVecBool,
|
|
9
|
-
import { SignatureNotSupportedError } from "../errors.js";
|
|
7
|
+
import { booleanKind, floatKind, generalizeBoolFn, generalizeFn, kindOf, numericKind, numericOrBooleanKind, assertEqualKinds, assertKind, } from "../data/generalizeFn.js";
|
|
8
|
+
import { isBool, isVecBool, isVecInstance, } from "../data/wgslTypes.js";
|
|
9
|
+
import { SignatureNotSupportedError, WgslTypeError } from "../errors.js";
|
|
10
10
|
import { unify } from "../tgsl/conversion.js";
|
|
11
11
|
import { cpuCopy } from "./copy.js";
|
|
12
12
|
function correspondingBooleanVectorSchema(dataType) {
|
|
@@ -33,7 +33,11 @@ export const allEq = dualImpl({
|
|
|
33
33
|
codegenImpl: (_ctx, [lhs, rhs]) => stitch `all(${lhs} == ${rhs})`,
|
|
34
34
|
sideEffects: false,
|
|
35
35
|
});
|
|
36
|
-
const cpuEq = (lhs, rhs) =>
|
|
36
|
+
const cpuEq = (lhs, rhs) => {
|
|
37
|
+
assertKind([lhs, rhs], numericOrBooleanKind);
|
|
38
|
+
assertEqualKinds(lhs, rhs);
|
|
39
|
+
return generalizeBoolFn((a, b) => a === b, [lhs, rhs]);
|
|
40
|
+
};
|
|
37
41
|
/**
|
|
38
42
|
* Checks **component-wise** whether `lhs == rhs`.
|
|
39
43
|
* This function does **not** return `bool`, for that use-case, wrap the result in `all`, or use `allEq`.
|
|
@@ -71,7 +75,11 @@ export const ne = dualImpl({
|
|
|
71
75
|
codegenImpl: (_ctx, [lhs, rhs]) => stitch `(${lhs} != ${rhs})`,
|
|
72
76
|
sideEffects: false,
|
|
73
77
|
});
|
|
74
|
-
const cpuLt = (lhs, rhs) =>
|
|
78
|
+
const cpuLt = (lhs, rhs) => {
|
|
79
|
+
assertKind([lhs, rhs], numericKind);
|
|
80
|
+
assertEqualKinds(lhs, rhs);
|
|
81
|
+
return generalizeBoolFn((a, b) => a < b, [lhs, rhs]);
|
|
82
|
+
};
|
|
75
83
|
/**
|
|
76
84
|
* Checks **component-wise** whether `lhs < rhs`.
|
|
77
85
|
* This function does **not** return `bool`, for that use-case, wrap the result in `all`.
|
|
@@ -145,20 +153,8 @@ export const ge = dualImpl({
|
|
|
145
153
|
sideEffects: false,
|
|
146
154
|
});
|
|
147
155
|
function cpuNot(value) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
if (!isVecBoolInstance(value)) {
|
|
152
|
-
throw new Error(`'std.not' requires a boolean or boolean vector.`);
|
|
153
|
-
}
|
|
154
|
-
switch (value.length) {
|
|
155
|
-
case 2:
|
|
156
|
-
return vec2b(cpuNot(value.x), cpuNot(value.y));
|
|
157
|
-
case 3:
|
|
158
|
-
return vec3b(cpuNot(value.x), cpuNot(value.y), cpuNot(value.z));
|
|
159
|
-
case 4:
|
|
160
|
-
return vec4b(cpuNot(value.x), cpuNot(value.y), cpuNot(value.z), cpuNot(value.w));
|
|
161
|
-
}
|
|
156
|
+
assertKind(value, booleanKind);
|
|
157
|
+
return generalizeBoolFn((a) => !a, [value]);
|
|
162
158
|
}
|
|
163
159
|
/**
|
|
164
160
|
* Returns the logical negation of the given value.
|
|
@@ -183,7 +179,11 @@ export const not = dualImpl({
|
|
|
183
179
|
codegenImpl: (_ctx, [arg]) => stitch `!(${arg})`,
|
|
184
180
|
sideEffects: false,
|
|
185
181
|
});
|
|
186
|
-
const cpuOr = (lhs, rhs) =>
|
|
182
|
+
const cpuOr = (lhs, rhs) => {
|
|
183
|
+
assertKind([lhs, rhs], booleanKind);
|
|
184
|
+
assertEqualKinds(lhs, rhs);
|
|
185
|
+
return generalizeBoolFn((a, b) => a || b, [lhs, rhs]);
|
|
186
|
+
};
|
|
187
187
|
/**
|
|
188
188
|
* Returns **component-wise** logical `or` result.
|
|
189
189
|
* @example
|
|
@@ -212,7 +212,13 @@ export const and = dualImpl({
|
|
|
212
212
|
sideEffects: false,
|
|
213
213
|
});
|
|
214
214
|
// logical aggregation
|
|
215
|
-
const cpuAll = (value) =>
|
|
215
|
+
const cpuAll = (value) => {
|
|
216
|
+
assertKind(value, booleanKind);
|
|
217
|
+
if (typeof value === 'boolean') {
|
|
218
|
+
return value;
|
|
219
|
+
}
|
|
220
|
+
return VectorOps.all[value.kind](value);
|
|
221
|
+
};
|
|
216
222
|
/**
|
|
217
223
|
* Returns `true` if each component of `value` is true.
|
|
218
224
|
* @example
|
|
@@ -257,6 +263,8 @@ export const isCloseTo = dualImpl({
|
|
|
257
263
|
}),
|
|
258
264
|
// CPU implementation
|
|
259
265
|
normalImpl: (lhs, rhs, precision = 0.01) => {
|
|
266
|
+
assertKind([lhs, rhs], floatKind);
|
|
267
|
+
assertEqualKinds(lhs, rhs);
|
|
260
268
|
const componentResult = generalizeBoolFn((lhs, rhs) => Math.abs(lhs - rhs) < precision, [lhs, rhs]);
|
|
261
269
|
return typeof componentResult === 'boolean' ? componentResult : all(componentResult);
|
|
262
270
|
},
|
|
@@ -275,9 +283,15 @@ export const isCloseTo = dualImpl({
|
|
|
275
283
|
sideEffects: false,
|
|
276
284
|
});
|
|
277
285
|
function cpuSelect(f, t, cond) {
|
|
286
|
+
assertKind([f, t], numericOrBooleanKind);
|
|
287
|
+
assertEqualKinds(f, t);
|
|
288
|
+
assertKind(cond, booleanKind);
|
|
278
289
|
if (typeof cond === 'boolean') {
|
|
279
290
|
return cpuCopy(cond ? t : f);
|
|
280
291
|
}
|
|
292
|
+
if (!isVecInstance(f) || f.length !== cond.length) {
|
|
293
|
+
throw new WgslTypeError(`Select shape '(${kindOf(f)}, ${kindOf(t)}, ${kindOf(cond)})' is invalid.`);
|
|
294
|
+
}
|
|
281
295
|
// generalizeFn will handle this fine, it just has no mixed type overload.
|
|
282
296
|
return generalizeFn((f, t, c) => (c ? t : f), [f, t, cond]);
|
|
283
297
|
}
|
package/std/derivative.js
CHANGED
|
@@ -1,66 +1,71 @@
|
|
|
1
1
|
import { dualImpl } from "../core/function/dualImpl.js";
|
|
2
2
|
import { stitch } from "../core/resolve/stitch.js";
|
|
3
|
+
import { f32 } from "../data/numeric.js";
|
|
4
|
+
import { vec2f, vec3f, vec4f } from "../data/vector.js";
|
|
5
|
+
import { unifyRestrictedSignature } from "./numeric.js";
|
|
3
6
|
const derivativeNormalError = 'Derivative builtins are not allowed on the CPU';
|
|
7
|
+
// WGSL derivative builtins only accept f32 and vecN<f32>
|
|
8
|
+
const derivativeSignature = unifyRestrictedSignature([f32, vec2f, vec3f, vec4f]);
|
|
4
9
|
export const dpdx = dualImpl({
|
|
5
10
|
name: 'dpdx',
|
|
6
11
|
normalImpl: derivativeNormalError,
|
|
7
|
-
signature:
|
|
8
|
-
codegenImpl: (
|
|
12
|
+
signature: derivativeSignature,
|
|
13
|
+
codegenImpl: (ctx, [value]) => ctx.gen.emitCall('dpdx', [], [value]),
|
|
9
14
|
sideEffects: false,
|
|
10
15
|
});
|
|
11
16
|
export const dpdxCoarse = dualImpl({
|
|
12
17
|
name: 'dpdxCoarse',
|
|
13
18
|
normalImpl: derivativeNormalError,
|
|
14
|
-
signature:
|
|
19
|
+
signature: derivativeSignature,
|
|
15
20
|
codegenImpl: (_ctx, [value]) => stitch `dpdxCoarse(${value})`,
|
|
16
21
|
sideEffects: false,
|
|
17
22
|
});
|
|
18
23
|
export const dpdxFine = dualImpl({
|
|
19
24
|
name: 'dpdxFine',
|
|
20
25
|
normalImpl: derivativeNormalError,
|
|
21
|
-
signature:
|
|
26
|
+
signature: derivativeSignature,
|
|
22
27
|
codegenImpl: (_ctx, [value]) => stitch `dpdxFine(${value})`,
|
|
23
28
|
sideEffects: false,
|
|
24
29
|
});
|
|
25
30
|
export const dpdy = dualImpl({
|
|
26
31
|
name: 'dpdy',
|
|
27
32
|
normalImpl: derivativeNormalError,
|
|
28
|
-
signature:
|
|
29
|
-
codegenImpl: (
|
|
33
|
+
signature: derivativeSignature,
|
|
34
|
+
codegenImpl: (ctx, [value]) => ctx.gen.emitCall('dpdy', [], [value]),
|
|
30
35
|
sideEffects: false,
|
|
31
36
|
});
|
|
32
37
|
export const dpdyCoarse = dualImpl({
|
|
33
38
|
name: 'dpdyCoarse',
|
|
34
39
|
normalImpl: derivativeNormalError,
|
|
35
|
-
signature:
|
|
40
|
+
signature: derivativeSignature,
|
|
36
41
|
codegenImpl: (_ctx, [value]) => stitch `dpdyCoarse(${value})`,
|
|
37
42
|
sideEffects: false,
|
|
38
43
|
});
|
|
39
44
|
export const dpdyFine = dualImpl({
|
|
40
45
|
name: 'dpdyFine',
|
|
41
46
|
normalImpl: derivativeNormalError,
|
|
42
|
-
signature:
|
|
47
|
+
signature: derivativeSignature,
|
|
43
48
|
codegenImpl: (_ctx, [value]) => stitch `dpdyFine(${value})`,
|
|
44
49
|
sideEffects: false,
|
|
45
50
|
});
|
|
46
51
|
export const fwidth = dualImpl({
|
|
47
52
|
name: 'fwidth',
|
|
48
53
|
normalImpl: derivativeNormalError,
|
|
49
|
-
signature:
|
|
50
|
-
codegenImpl: (
|
|
54
|
+
signature: derivativeSignature,
|
|
55
|
+
codegenImpl: (ctx, [value]) => ctx.gen.emitCall('fwidth', [], [value]),
|
|
51
56
|
sideEffects: false,
|
|
52
57
|
});
|
|
53
58
|
export const fwidthCoarse = dualImpl({
|
|
54
59
|
name: 'fwidthCoarse',
|
|
55
60
|
normalImpl: derivativeNormalError,
|
|
56
|
-
signature:
|
|
61
|
+
signature: derivativeSignature,
|
|
57
62
|
codegenImpl: (_ctx, [value]) => stitch `fwidthCoarse(${value})`,
|
|
58
63
|
sideEffects: false,
|
|
59
64
|
});
|
|
60
65
|
export const fwidthFine = dualImpl({
|
|
61
66
|
name: 'fwidthFine',
|
|
62
67
|
normalImpl: derivativeNormalError,
|
|
63
|
-
signature:
|
|
68
|
+
signature: derivativeSignature,
|
|
64
69
|
codegenImpl: (_ctx, [value]) => stitch `fwidthFine(${value})`,
|
|
65
70
|
sideEffects: false,
|
|
66
71
|
});
|
package/std/index.d.ts
CHANGED
|
@@ -8,12 +8,12 @@ export { add, bitShiftLeft, bitShiftRight, div, mod, mul, neg, sub } from './ope
|
|
|
8
8
|
export { rotateX4, rotateY4, rotateZ4, scale4, translate4 } from './matrix.ts';
|
|
9
9
|
export { identity2, identity3, identity4, rotationX4, rotationY4, rotationZ4, scaling4, translation4, } from '../data/matrix.ts';
|
|
10
10
|
export { allEq, eq, ne, lt, le, gt, ge, not, or, and, all, any, isCloseTo, select, } from './boolean.ts';
|
|
11
|
-
export { atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, workgroupBarrier, storageBarrier, textureBarrier, } from './atomic.ts';
|
|
11
|
+
export { atomicAdd, atomicAnd, atomicCompareExchangeWeak, atomicExchange, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, workgroupBarrier, storageBarrier, textureBarrier, workgroupUniformLoad, } from './atomic.ts';
|
|
12
12
|
export { dpdx, dpdxCoarse, dpdxFine, dpdy, dpdyCoarse, dpdyFine, fwidth, fwidthCoarse, fwidthFine, } from './derivative.ts';
|
|
13
13
|
export { arrayLength } from './array.ts';
|
|
14
|
-
export { pack4x8unorm,
|
|
15
|
-
export { textureDimensions, textureGather, textureLoad, textureSample, textureSampleBaseClampToEdge, textureSampleBias, textureSampleCompare, textureSampleCompareLevel, textureSampleGrad, textureSampleLevel, textureStore, } from './texture.ts';
|
|
16
|
-
export { subgroupAdd, subgroupAll, subgroupAnd, subgroupAny, subgroupBallot, subgroupBroadcast, subgroupBroadcastFirst, subgroupElect, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupMax, subgroupMin, subgroupMul, subgroupOr, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor, subgroupXor, } from './subgroup.ts';
|
|
14
|
+
export { pack2x16float, pack2x16snorm, pack2x16unorm, pack4x8snorm, pack4x8unorm, pack4xI8, pack4xI8Clamp, pack4xU8, pack4xU8Clamp, unpack2x16float, unpack2x16snorm, unpack2x16unorm, unpack4x8snorm, unpack4x8unorm, unpack4xI8, unpack4xU8, } from './packing.ts';
|
|
15
|
+
export { textureDimensions, textureGather, textureGatherCompare, textureLoad, textureNumLayers, textureNumLevels, textureNumSamples, textureSample, textureSampleBaseClampToEdge, textureSampleBias, textureSampleCompare, textureSampleCompareLevel, textureSampleGrad, textureSampleLevel, textureStore, } from './texture.ts';
|
|
16
|
+
export { subgroupAdd, subgroupAll, subgroupAnd, subgroupAny, subgroupBallot, subgroupBroadcast, subgroupBroadcastFirst, subgroupElect, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupMax, subgroupMin, subgroupMul, subgroupOr, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor, subgroupXor, quadBroadcast, quadSwapDiagonal, quadSwapX, quadSwapY, } from './subgroup.ts';
|
|
17
17
|
export { extensionEnabled } from './extensions.ts';
|
|
18
18
|
export { bitcastU32toF32, bitcastU32toI32, bitcastF32toU32, bitcast } from './bitcast.ts';
|
|
19
19
|
export { range } from './range.ts';
|
package/std/index.js
CHANGED
|
@@ -17,15 +17,15 @@ not, or, and,
|
|
|
17
17
|
all, any,
|
|
18
18
|
// other
|
|
19
19
|
isCloseTo, select, } from "./boolean.js";
|
|
20
|
-
export { atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor,
|
|
20
|
+
export { atomicAdd, atomicAnd, atomicCompareExchangeWeak, atomicExchange, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor,
|
|
21
21
|
// synchronization
|
|
22
|
-
workgroupBarrier, storageBarrier, textureBarrier, } from "./atomic.js";
|
|
22
|
+
workgroupBarrier, storageBarrier, textureBarrier, workgroupUniformLoad, } from "./atomic.js";
|
|
23
23
|
export { dpdx, dpdxCoarse, dpdxFine, dpdy, dpdyCoarse, dpdyFine, fwidth, fwidthCoarse, fwidthFine, } from "./derivative.js";
|
|
24
24
|
export { arrayLength } from "./array.js";
|
|
25
25
|
// oxfmt-ignore
|
|
26
|
-
export { pack4x8unorm,
|
|
27
|
-
export { textureDimensions, textureGather, textureLoad, textureSample, textureSampleBaseClampToEdge, textureSampleBias, textureSampleCompare, textureSampleCompareLevel, textureSampleGrad, textureSampleLevel, textureStore, } from "./texture.js";
|
|
28
|
-
export { subgroupAdd, subgroupAll, subgroupAnd, subgroupAny, subgroupBallot, subgroupBroadcast, subgroupBroadcastFirst, subgroupElect, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupMax, subgroupMin, subgroupMul, subgroupOr, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor, subgroupXor, } from "./subgroup.js";
|
|
26
|
+
export { pack2x16float, pack2x16snorm, pack2x16unorm, pack4x8snorm, pack4x8unorm, pack4xI8, pack4xI8Clamp, pack4xU8, pack4xU8Clamp, unpack2x16float, unpack2x16snorm, unpack2x16unorm, unpack4x8snorm, unpack4x8unorm, unpack4xI8, unpack4xU8, } from "./packing.js";
|
|
27
|
+
export { textureDimensions, textureGather, textureGatherCompare, textureLoad, textureNumLayers, textureNumLevels, textureNumSamples, textureSample, textureSampleBaseClampToEdge, textureSampleBias, textureSampleCompare, textureSampleCompareLevel, textureSampleGrad, textureSampleLevel, textureStore, } from "./texture.js";
|
|
28
|
+
export { subgroupAdd, subgroupAll, subgroupAnd, subgroupAny, subgroupBallot, subgroupBroadcast, subgroupBroadcastFirst, subgroupElect, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupMax, subgroupMin, subgroupMul, subgroupOr, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor, subgroupXor, quadBroadcast, quadSwapDiagonal, quadSwapX, quadSwapY, } from "./subgroup.js";
|
|
29
29
|
export { extensionEnabled } from "./extensions.js";
|
|
30
30
|
export { bitcastU32toF32, bitcastU32toI32, bitcastF32toU32, bitcast } from "./bitcast.js";
|
|
31
31
|
export { range } from "./range.js";
|
package/std/numeric.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { type AnyFloat32VecInstance, type AnyFloatVecInstance, type AnyIntegerVecInstance, type AnyMatInstance, type AnyNumericVecInstance, type AnySignedVecInstance, type v2f, type v2h, type v2i, type v3f, type v3h, type v3i, type v4f, type v4h, type v4i, type Vec2f } from '../data/wgslTypes.ts';
|
|
1
|
+
import { type AnyFloat32VecInstance, type AnyFloatVecInstance, type AnyIntegerVecInstance, type AnyMatInstance, type AnyNumericVecInstance, type AnySignedVecInstance, type BaseData, type v2f, type v2h, type v2i, type v3f, type v3h, type v3i, type v4f, type v4h, type v4i, type Vec2f } from '../data/wgslTypes.ts';
|
|
2
2
|
import type { Infer } from '../shared/repr.ts';
|
|
3
3
|
type NumVec = AnyNumericVecInstance;
|
|
4
|
+
export declare const unifyRestrictedSignature: (restrict: BaseData[]) => (...args: BaseData[]) => {
|
|
5
|
+
argTypes: BaseData[];
|
|
6
|
+
returnType: BaseData;
|
|
7
|
+
};
|
|
4
8
|
declare function cpuAbs(value: number): number;
|
|
5
9
|
declare function cpuAbs<T extends NumVec | number>(value: T): T;
|
|
6
10
|
export declare const abs: import("../types.ts").DualFn<typeof cpuAbs>;
|