typegpu 0.12.9 → 0.12.10
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/common/attachAutoResizer.d.ts +33 -0
- package/common/attachAutoResizer.js +83 -0
- package/common/index.d.ts +1 -0
- package/common/index.js +1 -0
- package/common/writeSoA.js +4 -3
- package/core/commandEncoder/commandEncoder.d.ts +1 -1
- package/core/declare/tgpuDeclare.d.ts +10 -7
- package/core/declare/tgpuDeclare.js +25 -10
- package/core/function/comptime.d.ts +2 -0
- package/core/function/comptime.js +29 -24
- package/core/function/createCallableSchema.js +32 -37
- package/core/function/dualImpl.js +44 -44
- package/core/function/tgpuComputeFn.d.ts +0 -3
- package/core/function/tgpuFn.js +4 -4
- package/core/function/tgpuFragmentFn.d.ts +1 -1
- package/core/function/tgpuVertexFn.d.ts +1 -1
- package/core/pipeline/drawState.js +1 -1
- package/core/pipeline/webgpuLimitations.js +2 -1
- package/core/resolve/externals.js +4 -0
- package/core/resolve/namespace.d.ts +4 -0
- package/core/resolve/namespace.js +1 -2
- package/core/resolve/stitch.js +13 -8
- package/core/root/rootTypes.d.ts +40 -36
- package/core/slot/accessor.js +1 -1
- package/core/texture/texture.d.ts +1 -2
- package/core/texture/texture.js +37 -20
- package/core/texture/textureFormats.d.ts +4 -3
- package/core/texture/textureFormats.js +17 -6
- package/core/texture/textureWrite.d.ts +9 -0
- package/core/texture/textureWrite.js +21 -0
- package/core/unroll/tgpuUnroll.js +2 -4
- package/core/vertexLayout/vertexAttribute.d.ts +1 -4
- package/core/vertexLayout/vertexLayout.js +11 -30
- package/data/alignmentOf.d.ts +1 -1
- package/data/alignmentOf.js +5 -12
- package/data/array.js +34 -2
- package/data/attributes.d.ts +16 -3
- package/data/attributes.js +11 -2
- package/data/compiledIO.js +2 -2
- package/data/dataIO.js +61 -95
- package/data/dataTypes.d.ts +0 -2
- package/data/dataTypes.js +3 -3
- package/data/disarray.js +2 -0
- package/data/offsetUtils.js +23 -13
- package/data/offsets.js +1 -2
- package/data/partialIO.js +2 -3
- package/data/ref.js +35 -37
- package/data/schemaCallWrapper.js +2 -2
- package/data/schemaMemoryLayout.d.ts +6 -1
- package/data/schemaMemoryLayout.js +23 -14
- package/data/schemasEqual.js +6 -15
- package/data/sizeOf.d.ts +1 -1
- package/data/sizeOf.js +2 -3
- package/data/snippet.d.ts +1 -1
- package/data/struct.js +25 -1
- package/data/unstruct.js +2 -0
- package/data/vectorImpl.js +45 -21
- package/data/vertexFormatData.js +7 -9
- package/data/wgslTypes.d.ts +27 -12
- package/data/wgslTypes.js +33 -39
- package/extension.d.ts +0 -4
- package/package.json +1 -1
- package/resolutionCtx.d.ts +1 -1
- package/resolutionCtx.js +26 -7
- package/serial/restore.d.ts +1 -1
- package/shared/meta.js +1 -1
- package/shared/symbols.d.ts +5 -0
- package/shared/symbols.js +6 -1
- package/shared/utilityTypes.d.ts +0 -6
- package/std/bitcast.d.ts +1 -1
- package/std/comptime.js +10 -12
- package/std/environment.js +2 -4
- package/std/matrix.js +5 -5
- package/std/numeric.d.ts +1 -0
- package/std/numeric.js +35 -1
- package/std/typeOf.js +12 -14
- package/tgpu.d.ts +1 -1
- package/tgpu.js +1 -1
- package/tgpuBindGroupLayout.d.ts +6 -3
- package/tgpuBindGroupLayout.js +15 -2
- package/tgpuUnstableNamespace.d.ts +1 -0
- package/tgpuUnstableNamespace.js +5 -0
- package/tgsl/accessIndex.js +10 -7
- package/tgsl/accessProp.js +5 -57
- package/tgsl/consoleLog/types.d.ts +1 -1
- package/tgsl/conversion.js +21 -0
- package/tgsl/forOfUtils.js +1 -1
- package/tgsl/generationHelpers.d.ts +0 -1
- package/tgsl/generationHelpers.js +1 -4
- package/tgsl/shaderGenerator.d.ts +5 -0
- package/tgsl/swizzle.d.ts +24 -0
- package/tgsl/swizzle.js +112 -0
- package/tgsl/wgslGenerator.d.ts +13 -3
- package/tgsl/wgslGenerator.js +149 -151
- package/types.d.ts +10 -10
- package/types.js +1 -1
- package/taskQueue.d.ts +0 -6
- package/taskQueue.js +0 -30
|
@@ -82,7 +82,7 @@ function computeMLOfStruct(struct) {
|
|
|
82
82
|
const prevSize = size;
|
|
83
83
|
size = roundUp(size, alignmentOf(property));
|
|
84
84
|
const hasPadding = prevSize !== size;
|
|
85
|
-
const propLayout =
|
|
85
|
+
const propLayout = getMemoryLayout(property);
|
|
86
86
|
size += propLayout.size;
|
|
87
87
|
if (Number.isNaN(size) && property.type !== 'array') {
|
|
88
88
|
throw new Error('Cannot nest unbounded struct within another struct');
|
|
@@ -121,7 +121,7 @@ function computeMLOfUnstruct(data) {
|
|
|
121
121
|
if (hasPadding) {
|
|
122
122
|
isContiguous = false;
|
|
123
123
|
}
|
|
124
|
-
const propLayout =
|
|
124
|
+
const propLayout = getMemoryLayout(property);
|
|
125
125
|
size += propLayout.size;
|
|
126
126
|
if (prefixEnd) {
|
|
127
127
|
continue;
|
|
@@ -145,9 +145,9 @@ function computeMLOfUnstruct(data) {
|
|
|
145
145
|
}
|
|
146
146
|
function computeMLOfWgslArray(data) {
|
|
147
147
|
const elementType = data.elementType;
|
|
148
|
-
const elementMemoryLayout =
|
|
148
|
+
const elementMemoryLayout = getMemoryLayout(elementType);
|
|
149
149
|
const elementSize = elementMemoryLayout.size;
|
|
150
|
-
const stride =
|
|
150
|
+
const stride = strideOf(data);
|
|
151
151
|
const hasPadding = stride > elementSize;
|
|
152
152
|
const isContiguous = !hasPadding && elementMemoryLayout.isContiguous;
|
|
153
153
|
const size = data.elementCount === 0 ? Number.NaN : data.elementCount * stride;
|
|
@@ -162,9 +162,9 @@ function computeMLOfWgslArray(data) {
|
|
|
162
162
|
}
|
|
163
163
|
function computeMLOfDisarray(data) {
|
|
164
164
|
const elementType = data.elementType;
|
|
165
|
-
const elementMemoryLayout =
|
|
165
|
+
const elementMemoryLayout = getMemoryLayout(elementType);
|
|
166
166
|
const elementSize = elementMemoryLayout.size;
|
|
167
|
-
const stride =
|
|
167
|
+
const stride = strideOf(data);
|
|
168
168
|
const hasPadding = stride > elementSize;
|
|
169
169
|
const isContiguous = !hasPadding && elementMemoryLayout.isContiguous;
|
|
170
170
|
const size = data.elementCount * stride;
|
|
@@ -177,6 +177,14 @@ function computeMLOfDisarray(data) {
|
|
|
177
177
|
}
|
|
178
178
|
return { size, isContiguous, longestContiguousPrefix };
|
|
179
179
|
}
|
|
180
|
+
function getMemoryLayout(data) {
|
|
181
|
+
let layout = cachedLayouts.get(data);
|
|
182
|
+
if (layout === undefined) {
|
|
183
|
+
layout = computeMemoryLayout(data);
|
|
184
|
+
cachedLayouts.set(data, layout);
|
|
185
|
+
}
|
|
186
|
+
return layout;
|
|
187
|
+
}
|
|
180
188
|
function computeMemoryLayout(data) {
|
|
181
189
|
const knownSize = knownSizesMap[data.type];
|
|
182
190
|
if (knownSize !== undefined) {
|
|
@@ -200,7 +208,7 @@ function computeMemoryLayout(data) {
|
|
|
200
208
|
}
|
|
201
209
|
if (isDecorated(data) || isLooseDecorated(data)) {
|
|
202
210
|
const size = getCustomSize(data);
|
|
203
|
-
const undecoratedLayout =
|
|
211
|
+
const undecoratedLayout = getMemoryLayout(undecorate(data));
|
|
204
212
|
if (size) {
|
|
205
213
|
const isContiguous = size === undecoratedLayout.size && undecoratedLayout.isContiguous;
|
|
206
214
|
return {
|
|
@@ -209,7 +217,7 @@ function computeMemoryLayout(data) {
|
|
|
209
217
|
longestContiguousPrefix: undecoratedLayout.longestContiguousPrefix,
|
|
210
218
|
};
|
|
211
219
|
}
|
|
212
|
-
return
|
|
220
|
+
return getMemoryLayout(data.inner);
|
|
213
221
|
}
|
|
214
222
|
throw new Error(`Cannot determine memory layout of data: ${data}`);
|
|
215
223
|
}
|
|
@@ -218,11 +226,12 @@ function computeMemoryLayout(data) {
|
|
|
218
226
|
* Instead, this weak map acts as an extended property of those data types.
|
|
219
227
|
*/
|
|
220
228
|
const cachedLayouts = new WeakMap();
|
|
229
|
+
/**
|
|
230
|
+
* Returns the distance (in bytes) between the starts of consecutive elements of an array.
|
|
231
|
+
*/
|
|
232
|
+
export function strideOf(schema) {
|
|
233
|
+
return roundUp(getMemoryLayout(schema.elementType).size, alignmentOf(schema));
|
|
234
|
+
}
|
|
221
235
|
export function getLayoutInfo(schema, key) {
|
|
222
|
-
|
|
223
|
-
if (layout === undefined) {
|
|
224
|
-
layout = computeMemoryLayout(schema);
|
|
225
|
-
cachedLayouts.set(schema, layout);
|
|
226
|
-
}
|
|
227
|
-
return layout[key];
|
|
236
|
+
return getMemoryLayout(schema)[key];
|
|
228
237
|
}
|
package/data/schemasEqual.js
CHANGED
|
@@ -97,14 +97,14 @@ function schemasEqual(a, b, structural) {
|
|
|
97
97
|
return false;
|
|
98
98
|
}
|
|
99
99
|
// Attribute order carries no meaning, so we compare attributes by type.
|
|
100
|
-
//
|
|
101
|
-
const attribsA =
|
|
102
|
-
const attribsB =
|
|
103
|
-
if (attribsA.
|
|
100
|
+
// A decorator replaces an existing one of the same type, so each type appears once.
|
|
101
|
+
const attribsA = a.attribs;
|
|
102
|
+
const attribsB = b.attribs;
|
|
103
|
+
if (attribsA.length !== attribsB.length) {
|
|
104
104
|
return false;
|
|
105
105
|
}
|
|
106
|
-
for (const
|
|
107
|
-
const attrB = attribsB.
|
|
106
|
+
for (const attrA of attribsA) {
|
|
107
|
+
const attrB = attribsB.find((attr) => attr.type === attrA.type);
|
|
108
108
|
if (!attrB) {
|
|
109
109
|
return false;
|
|
110
110
|
}
|
|
@@ -120,12 +120,3 @@ function schemasEqual(a, b, structural) {
|
|
|
120
120
|
// All other types have been checked for equality at the start
|
|
121
121
|
return true;
|
|
122
122
|
}
|
|
123
|
-
function effectiveAttribs(attribs) {
|
|
124
|
-
const result = new Map();
|
|
125
|
-
for (const attrib of attribs) {
|
|
126
|
-
if (!result.has(attrib.type)) {
|
|
127
|
-
result.set(attrib.type, attrib);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return result;
|
|
131
|
-
}
|
package/data/sizeOf.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export declare function sizeOf(schema: BaseData): number;
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns the size (in bytes) of data represented by the `schema`.
|
|
6
6
|
*/
|
|
7
|
-
export declare
|
|
7
|
+
export declare const PUBLIC_sizeOf: import("../indexNamedExports.ts").TgpuComptime<(schema: AnyData) => number>;
|
package/data/sizeOf.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { comptime } from "../core/function/comptime.js";
|
|
1
2
|
import { getLayoutInfo } from "./schemaMemoryLayout.js";
|
|
2
3
|
export function sizeOf(schema) {
|
|
3
4
|
return getLayoutInfo(schema, 'size');
|
|
@@ -5,6 +6,4 @@ export function sizeOf(schema) {
|
|
|
5
6
|
/**
|
|
6
7
|
* Returns the size (in bytes) of data represented by the `schema`.
|
|
7
8
|
*/
|
|
8
|
-
export
|
|
9
|
-
return sizeOf(schema);
|
|
10
|
-
}
|
|
9
|
+
export const PUBLIC_sizeOf = comptime((schema) => sizeOf(schema));
|
package/data/snippet.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ export interface ResolvedSnippet extends Snippet {
|
|
|
95
95
|
readonly dataType: BaseData;
|
|
96
96
|
}
|
|
97
97
|
export type MapValueToSnippet<T> = {
|
|
98
|
-
[K in keyof T]: Snippet;
|
|
98
|
+
readonly [K in keyof T]: Snippet;
|
|
99
99
|
};
|
|
100
100
|
export declare function isSnippet(value: unknown): value is Snippet;
|
|
101
101
|
export declare function isSnippetNumeric(snippet: Snippet): boolean;
|
package/data/struct.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { WgslTypeError } from "../errors.js";
|
|
1
2
|
import { validateProp } from "../nameUtils.js";
|
|
2
3
|
import { getName, setName } from "../shared/meta.js";
|
|
3
|
-
import { $internal } from "../shared/symbols.js";
|
|
4
|
+
import { $gpuCallable, $gpuCallableStrictSignature, $internal } from "../shared/symbols.js";
|
|
5
|
+
import { tryConvertSnippet } from "../tgsl/conversion.js";
|
|
4
6
|
import { schemaCallWrapper } from "./schemaCallWrapper.js";
|
|
7
|
+
import { fallthroughCopyOrigin, snip } from "./snippet.js";
|
|
5
8
|
// ----------
|
|
6
9
|
// Public API
|
|
7
10
|
// ----------
|
|
@@ -61,4 +64,25 @@ const WgslStructImpl = {
|
|
|
61
64
|
toString() {
|
|
62
65
|
return `struct:${getName(this) ?? '<unnamed>'}`;
|
|
63
66
|
},
|
|
67
|
+
get [$gpuCallableStrictSignature]() {
|
|
68
|
+
return { argTypes: [this], returnType: this };
|
|
69
|
+
},
|
|
70
|
+
[$gpuCallable](ctx, args) {
|
|
71
|
+
if (args.length > 1) {
|
|
72
|
+
throw new WgslTypeError('Struct schemas should always be called with at most 1 argument');
|
|
73
|
+
}
|
|
74
|
+
// No arguments `Struct()`, resolve struct name and return.
|
|
75
|
+
if (!args[0]) {
|
|
76
|
+
// The schema becomes the data type.
|
|
77
|
+
return ctx.gen.typeInstantiation(this, []);
|
|
78
|
+
}
|
|
79
|
+
const arg = tryConvertSnippet(ctx, args[0], this);
|
|
80
|
+
// Either `Struct({ x: 1, y: 2 })`, or `Struct(otherStruct)`.
|
|
81
|
+
// In both cases, we just let the argument resolve everything.
|
|
82
|
+
return snip(ctx.resolveSnippet(arg).value, this,
|
|
83
|
+
// A new struct, so not a reference.
|
|
84
|
+
/* origin */ fallthroughCopyOrigin(arg.origin), arg.possibleSideEffects);
|
|
85
|
+
},
|
|
64
86
|
};
|
|
87
|
+
// Schemas are still functions, so they should keep `call`, `apply`, `bind`, etc.
|
|
88
|
+
Object.setPrototypeOf(WgslStructImpl, Function.prototype);
|
package/data/unstruct.js
CHANGED
package/data/vectorImpl.js
CHANGED
|
@@ -14,16 +14,25 @@ export class VecBase extends Array {
|
|
|
14
14
|
for (let e3 = 0; e3 < 4; e3++) {
|
|
15
15
|
const xyzwProp = `${XYZW[e0]}${XYZW[e1]}${XYZW[e2]}${XYZW[e3]}`;
|
|
16
16
|
const rgbaProp = `${RGBA[e0]}${RGBA[e1]}${RGBA[e2]}${RGBA[e3]}`;
|
|
17
|
-
|
|
17
|
+
const permutation = new Set([e0, e1, e2, e3]).size === 4;
|
|
18
|
+
const property = {
|
|
18
19
|
get() {
|
|
19
20
|
return new this._Vec4(this[e0], this[e1], this[e2], this[e3]);
|
|
20
21
|
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
...(permutation
|
|
23
|
+
? {
|
|
24
|
+
set(other) {
|
|
25
|
+
const [v0, v1, v2, v3] = other;
|
|
26
|
+
this[e0] = v0;
|
|
27
|
+
this[e1] = v1;
|
|
28
|
+
this[e2] = v2;
|
|
29
|
+
this[e3] = v3;
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
: {}),
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(VecBase.prototype, xyzwProp, property);
|
|
35
|
+
Object.defineProperty(VecBase.prototype, rgbaProp, property);
|
|
27
36
|
}
|
|
28
37
|
}
|
|
29
38
|
}
|
|
@@ -34,16 +43,24 @@ export class VecBase extends Array {
|
|
|
34
43
|
for (let e2 = 0; e2 < 4; e2++) {
|
|
35
44
|
const xyzwProp = `${XYZW[e0]}${XYZW[e1]}${XYZW[e2]}`;
|
|
36
45
|
const rgbaProp = `${RGBA[e0]}${RGBA[e1]}${RGBA[e2]}`;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return new this._Vec3(this[e0], this[e1], this[e2]);
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(VecBase.prototype, rgbaProp, {
|
|
46
|
+
const permutation = new Set([e0, e1, e2]).size === 3;
|
|
47
|
+
const property = {
|
|
43
48
|
get() {
|
|
44
49
|
return new this._Vec3(this[e0], this[e1], this[e2]);
|
|
45
50
|
},
|
|
46
|
-
|
|
51
|
+
...(permutation
|
|
52
|
+
? {
|
|
53
|
+
set(other) {
|
|
54
|
+
const [v0, v1, v2] = other;
|
|
55
|
+
this[e0] = v0;
|
|
56
|
+
this[e1] = v1;
|
|
57
|
+
this[e2] = v2;
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
: {}),
|
|
61
|
+
};
|
|
62
|
+
Object.defineProperty(VecBase.prototype, xyzwProp, property);
|
|
63
|
+
Object.defineProperty(VecBase.prototype, rgbaProp, property);
|
|
47
64
|
}
|
|
48
65
|
}
|
|
49
66
|
}
|
|
@@ -52,16 +69,23 @@ export class VecBase extends Array {
|
|
|
52
69
|
for (let e1 = 0; e1 < 4; e1++) {
|
|
53
70
|
const xyzwProp = `${XYZW[e0]}${XYZW[e1]}`;
|
|
54
71
|
const rgbaProp = `${RGBA[e0]}${RGBA[e1]}`;
|
|
55
|
-
|
|
72
|
+
const permutation = new Set([e0, e1]).size === 2;
|
|
73
|
+
const property = {
|
|
56
74
|
get() {
|
|
57
75
|
return new this._Vec2(this[e0], this[e1]);
|
|
58
76
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
77
|
+
...(permutation
|
|
78
|
+
? {
|
|
79
|
+
set(other) {
|
|
80
|
+
const [v0, v1] = other;
|
|
81
|
+
this[e0] = v0;
|
|
82
|
+
this[e1] = v1;
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
: {}),
|
|
86
|
+
};
|
|
87
|
+
Object.defineProperty(VecBase.prototype, xyzwProp, property);
|
|
88
|
+
Object.defineProperty(VecBase.prototype, rgbaProp, property);
|
|
65
89
|
}
|
|
66
90
|
}
|
|
67
91
|
}
|
package/data/vertexFormatData.js
CHANGED
|
@@ -3,17 +3,15 @@ import { f32, i32, u32 } from "./numeric.js";
|
|
|
3
3
|
import { vec2f, vec2i, vec2u, vec3f, vec3i, vec3u, vec4f, vec4i, vec4u } from "./vector.js";
|
|
4
4
|
import { schemaCallWrapper, schemaCallWrapperGPU } from "./schemaCallWrapper.js";
|
|
5
5
|
class TgpuVertexFormatDataImpl {
|
|
6
|
-
[$internal] = {};
|
|
7
6
|
type;
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
static {
|
|
8
|
+
TgpuVertexFormatDataImpl.prototype[$internal] = {};
|
|
9
|
+
}
|
|
10
10
|
constructor(type) {
|
|
11
11
|
this.type = type;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
},
|
|
16
|
-
};
|
|
12
|
+
}
|
|
13
|
+
[$gpuCallable](ctx, [v]) {
|
|
14
|
+
return schemaCallWrapperGPU(ctx, formatToWGSLType[this.type], v);
|
|
17
15
|
}
|
|
18
16
|
[$cast](v) {
|
|
19
17
|
return schemaCallWrapper(formatToWGSLType[this.type], v);
|
|
@@ -105,5 +103,5 @@ export const sint32x4 = new TgpuVertexFormatDataImpl('sint32x4');
|
|
|
105
103
|
export const unorm10_10_10_2 = new TgpuVertexFormatDataImpl('unorm10-10-10-2');
|
|
106
104
|
export const unorm8x4_bgra = new TgpuVertexFormatDataImpl('unorm8x4-bgra');
|
|
107
105
|
export function isPackedData(value) {
|
|
108
|
-
return
|
|
106
|
+
return packedFormats.has(value?.type) && isMarkedInternal(value);
|
|
109
107
|
}
|
package/data/wgslTypes.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { Prettify, SwapNever } from '../shared/utilityTypes.ts';
|
|
|
7
7
|
import type { WgslExternalTexture, WgslStorageTexture, WgslTexture } from './texture.ts';
|
|
8
8
|
import type { WgslComparisonSampler, WgslSampler } from './sampler.ts';
|
|
9
9
|
import type { _ref as ref } from './ref.ts';
|
|
10
|
-
import type { DualFn } from '../types.ts';
|
|
10
|
+
import type { DualFn, GPUCallable } from '../types.ts';
|
|
11
11
|
type DecoratedLocation<T extends BaseData> = Decorated<T, Location[]>;
|
|
12
12
|
export interface BaseData {
|
|
13
13
|
readonly [$internal]: Record<string, unknown>;
|
|
@@ -96,12 +96,23 @@ type XYZW = 'x' | 'y' | 'z' | 'w';
|
|
|
96
96
|
type RG = 'r' | 'g';
|
|
97
97
|
type RGB = 'r' | 'g' | 'b';
|
|
98
98
|
type RGBA = 'r' | 'g' | 'b' | 'a';
|
|
99
|
+
type Perm2<T extends string> = {
|
|
100
|
+
[Fst in T]: `${Fst}${Exclude<T, Fst>}`;
|
|
101
|
+
}[T];
|
|
102
|
+
type Perm3<T extends string> = {
|
|
103
|
+
[Fst in T]: `${Fst}${Perm2<Exclude<T, Fst>>}`;
|
|
104
|
+
}[T];
|
|
105
|
+
type Perm4<T extends string> = {
|
|
106
|
+
[Fst in T]: `${Fst}${Perm3<Exclude<T, Fst>>}`;
|
|
107
|
+
}[T];
|
|
99
108
|
type Swizzle2<T2, T3, T4> = {
|
|
100
109
|
readonly [K in `${XY}${XY}` | `${RG}${RG}`]: T2;
|
|
101
110
|
} & {
|
|
102
111
|
readonly [K in `${XY}${XY}${XY}` | `${RG}${RG}${RG}`]: T3;
|
|
103
112
|
} & {
|
|
104
113
|
readonly [K in `${XY}${XY}${XY}${XY}` | `${RG}${RG}${RG}${RG}`]: T4;
|
|
114
|
+
} & {
|
|
115
|
+
[K in Perm2<XY> | Perm2<RG>]: T2;
|
|
105
116
|
};
|
|
106
117
|
type Swizzle3<T2, T3, T4> = {
|
|
107
118
|
readonly [K in `${XYZ}${XYZ}` | `${RGB}${RGB}`]: T2;
|
|
@@ -109,6 +120,10 @@ type Swizzle3<T2, T3, T4> = {
|
|
|
109
120
|
readonly [K in `${XYZ}${XYZ}${XYZ}` | `${RGB}${RGB}${RGB}`]: T3;
|
|
110
121
|
} & {
|
|
111
122
|
readonly [K in `${XYZ}${XYZ}${XYZ}${XYZ}` | `${RGB}${RGB}${RGB}${RGB}`]: T4;
|
|
123
|
+
} & {
|
|
124
|
+
[K in Perm2<XYZ> | Perm2<RGB>]: T2;
|
|
125
|
+
} & {
|
|
126
|
+
[K in Perm3<XYZ> | Perm3<RGB>]: T3;
|
|
112
127
|
};
|
|
113
128
|
type Swizzle4<T2, T3, T4> = {
|
|
114
129
|
readonly [K in `${XYZW}${XYZW}` | `${RGBA}${RGBA}`]: T2;
|
|
@@ -116,6 +131,12 @@ type Swizzle4<T2, T3, T4> = {
|
|
|
116
131
|
readonly [K in `${XYZW}${XYZW}${XYZW}` | `${RGBA}${RGBA}${RGBA}`]: T3;
|
|
117
132
|
} & {
|
|
118
133
|
readonly [K in `${XYZW}${XYZW}${XYZW}${XYZW}` | `${RGBA}${RGBA}${RGBA}${RGBA}`]: T4;
|
|
134
|
+
} & {
|
|
135
|
+
[K in Perm2<XYZW> | Perm2<RGBA>]: T2;
|
|
136
|
+
} & {
|
|
137
|
+
[K in Perm3<XYZW> | Perm3<RGBA>]: T3;
|
|
138
|
+
} & {
|
|
139
|
+
[K in Perm4<XYZW> | Perm4<RGBA>]: T4;
|
|
119
140
|
};
|
|
120
141
|
type Tuple2<S> = [S, S];
|
|
121
142
|
type Tuple3<S> = [S, S, S];
|
|
@@ -365,7 +386,6 @@ export interface v4b extends Tuple4<boolean>, Swizzle4<v2b, v3b, v4b> {
|
|
|
365
386
|
a: boolean;
|
|
366
387
|
}
|
|
367
388
|
export type AnyFloat32VecInstance = v2f | v3f | v4f;
|
|
368
|
-
export type AnyFloat16VecInstance = v2h | v3h | v4h;
|
|
369
389
|
export type AnyFloatVecInstance = v2f | v2h | v3f | v3h | v4f | v4h;
|
|
370
390
|
export type AnyUnsignedVecInstance = v2u | v3u | v4u;
|
|
371
391
|
export type AnyIntegerVecInstance = v2i | v2u | v3i | v3u | v4i | v4u;
|
|
@@ -757,12 +777,12 @@ export interface Mat4x4f extends BaseData {
|
|
|
757
777
|
* between binary and JS representation. Takes into account
|
|
758
778
|
* the `byteAlignment` requirement of its elementType.
|
|
759
779
|
*/
|
|
760
|
-
export interface WgslArray<out TElement extends BaseData = BaseData> extends BaseData {
|
|
761
|
-
<T extends TElement>(elements: Infer<T>[]): Infer<T>[];
|
|
762
|
-
(): Infer<TElement>[];
|
|
780
|
+
export interface WgslArray<out TElement extends BaseData = BaseData> extends BaseData, GPUCallable<[elements?: Infer<TElement>[]]> {
|
|
763
781
|
readonly type: 'array';
|
|
764
782
|
readonly elementCount: number;
|
|
765
783
|
readonly elementType: TElement;
|
|
784
|
+
<T extends TElement>(elements: Infer<T>[]): Infer<T>[];
|
|
785
|
+
(): Infer<TElement>[];
|
|
766
786
|
readonly [$repr]: Infer<TElement>[];
|
|
767
787
|
readonly [$inRepr]: readonly InferInput<TElement>[] | TypedArrayFor<TElement>;
|
|
768
788
|
readonly [$gpuRepr]: InferGPU<TElement>[];
|
|
@@ -784,14 +804,13 @@ export interface WgslArray<out TElement extends BaseData = BaseData> extends Bas
|
|
|
784
804
|
* between binary and JS representation. Takes into account
|
|
785
805
|
* the `byteAlignment` requirement of its members.
|
|
786
806
|
*/
|
|
787
|
-
export interface WgslStruct<out TProps extends Record<string, BaseData> = Record<string, BaseData>> extends BaseData, TgpuNamable {
|
|
807
|
+
export interface WgslStruct<out TProps extends Record<string, BaseData> = Record<string, BaseData>> extends BaseData, TgpuNamable, GPUCallable<[props?: Prettify<InferRecord<TProps>>]> {
|
|
788
808
|
readonly [$internal]: {
|
|
789
809
|
isAbstruct: boolean;
|
|
790
810
|
};
|
|
791
811
|
readonly type: 'struct';
|
|
792
812
|
readonly propTypes: TProps;
|
|
793
|
-
(props
|
|
794
|
-
(): Prettify<InferRecord<TProps>>;
|
|
813
|
+
(props?: Prettify<InferRecord<TProps>>): Prettify<InferRecord<TProps>>;
|
|
795
814
|
readonly [$repr]: Prettify<InferRecord<TProps>>;
|
|
796
815
|
readonly [$inRepr]: Prettify<InferInputRecord<TProps>>;
|
|
797
816
|
readonly [$gpuRepr]: Prettify<InferGPURecord<TProps>>;
|
|
@@ -907,11 +926,8 @@ export type ScalarData = Bool | F32 | F16 | I32 | U32 | AbstractInt | AbstractFl
|
|
|
907
926
|
export type VecData = Vec2f | Vec2h | Vec2i | Vec2u | Vec2b | Vec3f | Vec3h | Vec3i | Vec3u | Vec3b | Vec4f | Vec4h | Vec4i | Vec4u | Vec4b;
|
|
908
927
|
export type MatData = Mat2x2f | Mat3x3f | Mat4x4f;
|
|
909
928
|
export type StorableData = ScalarData | VecData | MatData | Atomic<I32> | Atomic<U32> | WgslArray | WgslStruct;
|
|
910
|
-
export type AnyFloat32VecData = Vec2f | Vec3f | Vec4f;
|
|
911
|
-
export type AnyFloat16VecData = Vec2h | Vec3h | Vec4h;
|
|
912
929
|
export type AnyWgslData = Bool | F32 | F16 | I32 | U32 | U16 | Vec2f | Vec2h | Vec2i | Vec2u | Vec2b | Vec3f | Vec3h | Vec3i | Vec3u | Vec3b | Vec4f | Vec4h | Vec4i | Vec4u | Vec4b | Mat2x2f | Mat3x3f | Mat4x4f | WgslStruct | WgslArray | Ptr | Atomic<U32> | Atomic<I32> | Decorated | AbstractInt | AbstractFloat | Void | WgslTexture | WgslStorageTexture | WgslExternalTexture | WgslSampler | WgslComparisonSampler;
|
|
913
930
|
export declare function isVecInstance(value: unknown): value is AnyVecInstance;
|
|
914
|
-
export declare function isVecBoolInstance(value: unknown): value is v2b | v3b | v4b;
|
|
915
931
|
export declare function isVec2(value: unknown): value is Vec2f | Vec2h | Vec2i | Vec2u;
|
|
916
932
|
export declare function isVec3(value: unknown): value is Vec3f | Vec3h | Vec3i | Vec3u;
|
|
917
933
|
export declare function isVec4(value: unknown): value is Vec4f | Vec4h | Vec4i | Vec4u;
|
|
@@ -981,7 +997,6 @@ export declare function isDecorated(value: unknown): value is Decorated;
|
|
|
981
997
|
export declare function isAbstractFloat(value: unknown): value is AbstractFloat;
|
|
982
998
|
export declare function isAbstractInt(value: unknown): value is AbstractInt;
|
|
983
999
|
export declare function isAbstract(value: unknown): value is AbstractFloat | AbstractInt;
|
|
984
|
-
export declare function isConcrete(value: unknown): boolean;
|
|
985
1000
|
export declare function isVoid(value: unknown): value is Void;
|
|
986
1001
|
export declare function isBool(value: unknown): value is Bool;
|
|
987
1002
|
export declare function isNumericSchema(schema: unknown): schema is AbstractInt | AbstractFloat | F32 | F16 | I32 | U32;
|
package/data/wgslTypes.js
CHANGED
|
@@ -66,22 +66,19 @@ export const wgslTypeLiterals = [
|
|
|
66
66
|
// #endregion
|
|
67
67
|
export function isVecInstance(value) {
|
|
68
68
|
const v = value;
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
export function isVecBoolInstance(value) {
|
|
72
|
-
return isVecInstance(value) && value.kind.includes('b');
|
|
69
|
+
return typeof v?.kind === 'string' && v.kind.startsWith('vec') && isMarkedInternal(v);
|
|
73
70
|
}
|
|
74
71
|
export function isVec2(value) {
|
|
75
72
|
const v = value;
|
|
76
|
-
return
|
|
73
|
+
return typeof v?.type === 'string' && v.type.startsWith('vec2') && isMarkedInternal(v);
|
|
77
74
|
}
|
|
78
75
|
export function isVec3(value) {
|
|
79
76
|
const v = value;
|
|
80
|
-
return
|
|
77
|
+
return typeof v?.type === 'string' && v.type.startsWith('vec3') && isMarkedInternal(v);
|
|
81
78
|
}
|
|
82
79
|
export function isVec4(value) {
|
|
83
80
|
const v = value;
|
|
84
|
-
return
|
|
81
|
+
return typeof v?.type === 'string' && v.type.startsWith('vec4') && isMarkedInternal(v);
|
|
85
82
|
}
|
|
86
83
|
export function isVec(value) {
|
|
87
84
|
return isVec2(value) || isVec3(value) || isVec4(value);
|
|
@@ -91,22 +88,22 @@ export function isVecBool(value) {
|
|
|
91
88
|
}
|
|
92
89
|
export function isMatInstance(value) {
|
|
93
90
|
const v = value;
|
|
94
|
-
return (
|
|
91
|
+
return (typeof v?.kind?.startsWith === 'function' && v.kind.startsWith('mat') && isMarkedInternal(v));
|
|
95
92
|
}
|
|
96
93
|
export function isMat2x2f(value) {
|
|
97
|
-
return
|
|
94
|
+
return value?.type === 'mat2x2f' && isMarkedInternal(value);
|
|
98
95
|
}
|
|
99
96
|
export function isMat3x3f(value) {
|
|
100
|
-
return
|
|
97
|
+
return value?.type === 'mat3x3f' && isMarkedInternal(value);
|
|
101
98
|
}
|
|
102
99
|
export function isMat4x4f(value) {
|
|
103
|
-
return
|
|
100
|
+
return value?.type === 'mat4x4f' && isMarkedInternal(value);
|
|
104
101
|
}
|
|
105
102
|
export function isMat(value) {
|
|
106
103
|
return isMat2x2f(value) || isMat3x3f(value) || isMat4x4f(value);
|
|
107
104
|
}
|
|
108
105
|
export function isInteger(value) {
|
|
109
|
-
return (
|
|
106
|
+
return (['abstractInt', 'i32', 'u32'].includes(value?.type) && isMarkedInternal(value));
|
|
110
107
|
}
|
|
111
108
|
export function isIntegerVec(value) {
|
|
112
109
|
return isVec(value) && isInteger(value.primitive);
|
|
@@ -136,7 +133,7 @@ export function isWgslData(value) {
|
|
|
136
133
|
* isWgslArray(d.vec3f) // false
|
|
137
134
|
*/
|
|
138
135
|
export function isWgslArray(schema) {
|
|
139
|
-
return
|
|
136
|
+
return schema?.type === 'array' && isMarkedInternal(schema);
|
|
140
137
|
}
|
|
141
138
|
/**
|
|
142
139
|
* Checks whether passed in value is a struct schema,
|
|
@@ -151,7 +148,7 @@ export function isWgslArray(schema) {
|
|
|
151
148
|
* isWgslStruct(d.vec3f) // false
|
|
152
149
|
*/
|
|
153
150
|
export function isWgslStruct(schema) {
|
|
154
|
-
return
|
|
151
|
+
return schema?.type === 'struct' && isMarkedInternal(schema);
|
|
155
152
|
}
|
|
156
153
|
/**
|
|
157
154
|
* Checks whether passed in value is a pointer schema.
|
|
@@ -162,7 +159,7 @@ export function isWgslStruct(schema) {
|
|
|
162
159
|
* isPtr(d.f32) // false
|
|
163
160
|
*/
|
|
164
161
|
export function isPtr(schema) {
|
|
165
|
-
return
|
|
162
|
+
return schema?.type === 'ptr' && isMarkedInternal(schema);
|
|
166
163
|
}
|
|
167
164
|
/**
|
|
168
165
|
* Checks whether the passed in value is an atomic schema.
|
|
@@ -172,61 +169,58 @@ export function isPtr(schema) {
|
|
|
172
169
|
* isAtomic(d.u32) // false
|
|
173
170
|
*/
|
|
174
171
|
export function isAtomic(schema) {
|
|
175
|
-
return
|
|
172
|
+
return schema?.type === 'atomic' && isMarkedInternal(schema);
|
|
176
173
|
}
|
|
177
174
|
export function isAlignAttrib(value) {
|
|
178
|
-
return
|
|
175
|
+
return value?.type === '@align' && isMarkedInternal(value);
|
|
179
176
|
}
|
|
180
177
|
export function isSizeAttrib(value) {
|
|
181
|
-
return
|
|
178
|
+
return value?.type === '@size' && isMarkedInternal(value);
|
|
182
179
|
}
|
|
183
180
|
export function isLocationAttrib(value) {
|
|
184
|
-
return
|
|
181
|
+
return value?.type === '@location' && isMarkedInternal(value);
|
|
185
182
|
}
|
|
186
183
|
export function isInterpolateAttrib(value) {
|
|
187
|
-
return
|
|
184
|
+
return value?.type === '@interpolate' && isMarkedInternal(value);
|
|
188
185
|
}
|
|
189
186
|
export function isBuiltinAttrib(value) {
|
|
190
|
-
return
|
|
187
|
+
return value?.type === '@builtin' && isMarkedInternal(value);
|
|
191
188
|
}
|
|
192
189
|
export function isInvariantAttrib(value) {
|
|
193
|
-
return
|
|
190
|
+
return value?.type === '@invariant' && isMarkedInternal(value);
|
|
194
191
|
}
|
|
195
192
|
export function isDecorated(value) {
|
|
196
|
-
return
|
|
193
|
+
return value?.type === 'decorated' && isMarkedInternal(value);
|
|
197
194
|
}
|
|
198
195
|
export function isAbstractFloat(value) {
|
|
199
|
-
return
|
|
196
|
+
return value?.type === 'abstractFloat' && isMarkedInternal(value);
|
|
200
197
|
}
|
|
201
198
|
export function isAbstractInt(value) {
|
|
202
|
-
return
|
|
199
|
+
return value?.type === 'abstractInt' && isMarkedInternal(value);
|
|
203
200
|
}
|
|
204
201
|
export function isAbstract(value) {
|
|
205
202
|
return isAbstractFloat(value) || isAbstractInt(value);
|
|
206
203
|
}
|
|
207
|
-
export function isConcrete(value) {
|
|
208
|
-
return !isAbstract(value);
|
|
209
|
-
}
|
|
210
204
|
export function isVoid(value) {
|
|
211
|
-
return
|
|
205
|
+
return value?.type === 'void' && isMarkedInternal(value);
|
|
212
206
|
}
|
|
213
207
|
export function isBool(value) {
|
|
214
|
-
return
|
|
208
|
+
return value?.type === 'bool' && isMarkedInternal(value);
|
|
215
209
|
}
|
|
216
210
|
export function isNumericSchema(schema) {
|
|
217
211
|
const type = schema?.type;
|
|
218
|
-
return (
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
212
|
+
return ((type === 'abstractInt' ||
|
|
213
|
+
type === 'abstractFloat' ||
|
|
214
|
+
type === 'f32' ||
|
|
215
|
+
type === 'f16' ||
|
|
216
|
+
type === 'i32' ||
|
|
217
|
+
type === 'u32') &&
|
|
218
|
+
isMarkedInternal(schema));
|
|
225
219
|
}
|
|
226
220
|
export function isHalfPrecisionSchema(schema) {
|
|
227
221
|
const type = schema?.type;
|
|
228
|
-
return (
|
|
229
|
-
(
|
|
222
|
+
return ((type === 'f16' || type === 'vec2h' || type === 'vec3h' || type === 'vec4h') &&
|
|
223
|
+
isMarkedInternal(schema));
|
|
230
224
|
}
|
|
231
225
|
const ephemeralTypes = ['abstractInt', 'abstractFloat', 'f32', 'f16', 'i32', 'u32', 'bool'];
|
|
232
226
|
/**
|
package/extension.d.ts
CHANGED
package/package.json
CHANGED
package/resolutionCtx.d.ts
CHANGED
|
@@ -107,7 +107,7 @@ export declare class ResolutionCtxImpl implements ResolutionCtx {
|
|
|
107
107
|
popBlockScope(): void;
|
|
108
108
|
setBlockExternals(externals: Record<string, Snippet>): void;
|
|
109
109
|
clearBlockExternals(): void;
|
|
110
|
-
generateLog(op: SupportedLogOp, args: Snippet[]): Snippet;
|
|
110
|
+
generateLog(op: SupportedLogOp, args: readonly Snippet[]): Snippet;
|
|
111
111
|
get logResources(): LogResources | undefined;
|
|
112
112
|
resolveFunction(options: ResolveFunctionOptions): {
|
|
113
113
|
code: string;
|