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/data/matrix.d.ts
CHANGED
|
@@ -1,54 +1,52 @@
|
|
|
1
1
|
import { DualFn } from "../types.js";
|
|
2
2
|
import { Mat2x2f, Mat3x3f, Mat4x4f, m2x2f, m3x3f, m4x4f, v3f } from "./wgslTypes.js";
|
|
3
3
|
import { TgpuComptime } from "../core/function/comptime.js";
|
|
4
|
-
import "../indexNamedExports.js";
|
|
5
|
-
|
|
6
4
|
//#region src/data/matrix.d.ts
|
|
7
5
|
/**
|
|
8
6
|
* Returns a 2-by-2 identity matrix.
|
|
9
7
|
* @returns {m2x2f} The result matrix.
|
|
10
8
|
*/
|
|
11
|
-
declare const identity2: TgpuComptime
|
|
9
|
+
declare const identity2: TgpuComptime;
|
|
12
10
|
/**
|
|
13
11
|
* Returns a 3-by-3 identity matrix.
|
|
14
12
|
* @returns {m3x3f} The result matrix.
|
|
15
13
|
*/
|
|
16
|
-
declare const identity3: TgpuComptime
|
|
14
|
+
declare const identity3: TgpuComptime;
|
|
17
15
|
/**
|
|
18
16
|
* Returns a 4-by-4 identity matrix.
|
|
19
17
|
* @returns {m4x4f} The result matrix.
|
|
20
18
|
*/
|
|
21
|
-
declare const identity4: TgpuComptime
|
|
19
|
+
declare const identity4: TgpuComptime;
|
|
22
20
|
/**
|
|
23
21
|
* Creates a 4-by-4 matrix which translates by the given vector v.
|
|
24
22
|
* @param {v3f} vector - The vector by which to translate.
|
|
25
23
|
* @returns {m4x4f} The translation matrix.
|
|
26
24
|
*/
|
|
27
|
-
declare const translation4: DualFn
|
|
25
|
+
declare const translation4: DualFn;
|
|
28
26
|
/**
|
|
29
27
|
* Creates a 4-by-4 matrix which scales in each dimension by an amount given by the corresponding entry in the given vector.
|
|
30
28
|
* @param {v3f} vector - A vector of three entries specifying the factor by which to scale in each dimension.
|
|
31
29
|
* @returns {m4x4f} The scaling matrix.
|
|
32
30
|
*/
|
|
33
|
-
declare const scaling4: DualFn
|
|
31
|
+
declare const scaling4: DualFn;
|
|
34
32
|
/**
|
|
35
33
|
* Creates a 4-by-4 matrix which rotates around the x-axis by the given angle.
|
|
36
34
|
* @param {number} angle - The angle by which to rotate (in radians).
|
|
37
35
|
* @returns {m4x4f} The rotation matrix.
|
|
38
36
|
*/
|
|
39
|
-
declare const rotationX4: DualFn
|
|
37
|
+
declare const rotationX4: DualFn;
|
|
40
38
|
/**
|
|
41
39
|
* Creates a 4-by-4 matrix which rotates around the y-axis by the given angle.
|
|
42
40
|
* @param {number} angle - The angle by which to rotate (in radians).
|
|
43
41
|
* @returns {m4x4f} The rotation matrix.
|
|
44
42
|
*/
|
|
45
|
-
declare const rotationY4: DualFn
|
|
43
|
+
declare const rotationY4: DualFn;
|
|
46
44
|
/**
|
|
47
45
|
* Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.
|
|
48
46
|
* @param {number} angle - The angle by which to rotate (in radians).
|
|
49
47
|
* @returns {m4x4f} The rotation matrix.
|
|
50
48
|
*/
|
|
51
|
-
declare const rotationZ4: DualFn
|
|
49
|
+
declare const rotationZ4: DualFn;
|
|
52
50
|
/**
|
|
53
51
|
* Schema representing mat2x2f - a matrix with 2 rows and 2 columns, with elements of type f32.
|
|
54
52
|
* Also a constructor function for this matrix type.
|
package/data/matrix.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { $internal, $resolve } from "../shared/symbols.js";
|
|
2
2
|
import { isVec } from "./wgslTypes.js";
|
|
3
|
-
import { snip } from "./snippet.js";
|
|
4
3
|
import { stitch } from "../core/resolve/stitch.js";
|
|
5
4
|
import { callableSchema } from "../core/function/createCallableSchema.js";
|
|
6
5
|
import { f32 } from "./numeric.js";
|
|
6
|
+
import { numericLiteralToSnippet } from "../tgsl/generationHelpers.js";
|
|
7
7
|
import { vec2f, vec3f, vec4f } from "./vector.js";
|
|
8
8
|
import { dualImpl } from "../core/function/dualImpl.js";
|
|
9
9
|
import { comptime } from "../core/function/comptime.js";
|
|
10
|
-
|
|
11
10
|
//#region src/data/matrix.ts
|
|
12
11
|
var MatBase = class {};
|
|
13
12
|
function createMatSchema(options) {
|
|
14
13
|
const construct = callableSchema({
|
|
15
14
|
name: options.type,
|
|
15
|
+
schema: () => schema,
|
|
16
16
|
normalImpl: (...args) => {
|
|
17
17
|
const elements = [];
|
|
18
18
|
for (const arg of args) if (typeof arg === "number") elements.push(arg);
|
|
@@ -21,11 +21,8 @@ function createMatSchema(options) {
|
|
|
21
21
|
for (let i = elements.length; i < options.columns * options.rows; ++i) elements.push(0);
|
|
22
22
|
return new options.MatImpl(...elements);
|
|
23
23
|
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
returnType: schema
|
|
27
|
-
}),
|
|
28
|
-
codegenImpl: (_ctx, args) => stitch`${options.type}(${args})`
|
|
24
|
+
argTypes: (...args) => args.map((arg) => isVec(arg) ? arg : f32),
|
|
25
|
+
codegenImpl: (ctx, args) => ctx.gen.typeInstantiation(schema, args)
|
|
29
26
|
});
|
|
30
27
|
const schema = Object.assign(construct, {
|
|
31
28
|
[$internal]: {},
|
|
@@ -41,6 +38,12 @@ function createMatSchema(options) {
|
|
|
41
38
|
options.MatImpl.prototype.schema = schema;
|
|
42
39
|
return schema;
|
|
43
40
|
}
|
|
41
|
+
const VALID_MAT2x2_ELEMENTS = [
|
|
42
|
+
0,
|
|
43
|
+
1,
|
|
44
|
+
2,
|
|
45
|
+
3
|
|
46
|
+
];
|
|
44
47
|
var mat2x2Impl = class extends MatBase {
|
|
45
48
|
[$internal] = true;
|
|
46
49
|
columns;
|
|
@@ -79,11 +82,11 @@ var mat2x2Impl = class extends MatBase {
|
|
|
79
82
|
yield this[2];
|
|
80
83
|
yield this[3];
|
|
81
84
|
}
|
|
82
|
-
[$resolve]() {
|
|
83
|
-
return
|
|
85
|
+
[$resolve](ctx) {
|
|
86
|
+
return ctx.gen.typeInstantiation(mat2x2f, VALID_MAT2x2_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
|
|
84
87
|
}
|
|
85
88
|
toString() {
|
|
86
|
-
return this[
|
|
89
|
+
return `${this.kind}(${VALID_MAT2x2_ELEMENTS.map((i) => this[i]).join(", ")})`;
|
|
87
90
|
}
|
|
88
91
|
};
|
|
89
92
|
var mat2x2fImpl = class extends mat2x2Impl {
|
|
@@ -92,6 +95,17 @@ var mat2x2fImpl = class extends mat2x2Impl {
|
|
|
92
95
|
return vec2f(e0, e1);
|
|
93
96
|
}
|
|
94
97
|
};
|
|
98
|
+
const VALID_MAT3x3_ELEMENTS = [
|
|
99
|
+
0,
|
|
100
|
+
1,
|
|
101
|
+
2,
|
|
102
|
+
4,
|
|
103
|
+
5,
|
|
104
|
+
6,
|
|
105
|
+
8,
|
|
106
|
+
9,
|
|
107
|
+
10
|
|
108
|
+
];
|
|
95
109
|
var mat3x3Impl = class extends MatBase {
|
|
96
110
|
[$internal] = true;
|
|
97
111
|
columns;
|
|
@@ -173,11 +187,11 @@ var mat3x3Impl = class extends MatBase {
|
|
|
173
187
|
*[Symbol.iterator]() {
|
|
174
188
|
for (let i = 0; i < 12; i++) yield this[i];
|
|
175
189
|
}
|
|
176
|
-
[$resolve]() {
|
|
177
|
-
return
|
|
190
|
+
[$resolve](ctx) {
|
|
191
|
+
return ctx.gen.typeInstantiation(mat3x3f, VALID_MAT3x3_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
|
|
178
192
|
}
|
|
179
193
|
toString() {
|
|
180
|
-
return this[
|
|
194
|
+
return `${this.kind}(${VALID_MAT3x3_ELEMENTS.map((i) => this[i]).join(", ")})`;
|
|
181
195
|
}
|
|
182
196
|
};
|
|
183
197
|
var mat3x3fImpl = class extends mat3x3Impl {
|
|
@@ -186,6 +200,7 @@ var mat3x3fImpl = class extends mat3x3Impl {
|
|
|
186
200
|
return vec3f(x, y, z);
|
|
187
201
|
}
|
|
188
202
|
};
|
|
203
|
+
const VALID_MAT4x4_ELEMENTS = Array.from({ length: 16 }, (_, i) => i);
|
|
189
204
|
var mat4x4Impl = class extends MatBase {
|
|
190
205
|
[$internal] = true;
|
|
191
206
|
columns;
|
|
@@ -298,11 +313,11 @@ var mat4x4Impl = class extends MatBase {
|
|
|
298
313
|
*[Symbol.iterator]() {
|
|
299
314
|
for (let i = 0; i < 16; i++) yield this[i];
|
|
300
315
|
}
|
|
301
|
-
[$resolve]() {
|
|
302
|
-
return
|
|
316
|
+
[$resolve](ctx) {
|
|
317
|
+
return ctx.gen.typeInstantiation(mat4x4f, VALID_MAT4x4_ELEMENTS.map((i) => numericLiteralToSnippet(this[i])));
|
|
303
318
|
}
|
|
304
319
|
toString() {
|
|
305
|
-
return this[
|
|
320
|
+
return `${this.kind}(${VALID_MAT4x4_ELEMENTS.map((i) => this[i]).join(", ")})`;
|
|
306
321
|
}
|
|
307
322
|
};
|
|
308
323
|
var mat4x4fImpl = class extends mat4x4Impl {
|
|
@@ -512,6 +527,5 @@ function matToArray(mat) {
|
|
|
512
527
|
];
|
|
513
528
|
return Array.from({ length: mat.length }).map((_, idx) => mat[idx]);
|
|
514
529
|
}
|
|
515
|
-
|
|
516
530
|
//#endregion
|
|
517
|
-
export { MatBase, identity2, identity3, identity4, mat2x2f, mat3x3f, mat4x4f, matToArray, rotationX4, rotationY4, rotationZ4, scaling4, translation4 };
|
|
531
|
+
export { MatBase, identity2, identity3, identity4, mat2x2f, mat3x3f, mat4x4f, matToArray, rotationX4, rotationY4, rotationZ4, scaling4, translation4 };
|
package/data/numberOps.js
CHANGED
|
@@ -19,6 +19,5 @@ function bitcastU32toI32Impl(n) {
|
|
|
19
19
|
dataView.setUint32(0, n, true);
|
|
20
20
|
return dataView.getInt32(0, true);
|
|
21
21
|
}
|
|
22
|
-
|
|
23
22
|
//#endregion
|
|
24
|
-
export { bitcastU32toF32Impl, bitcastU32toI32Impl, clamp, divInteger, smoothstepScalar };
|
|
23
|
+
export { bitcastU32toF32Impl, bitcastU32toI32Impl, clamp, divInteger, smoothstepScalar };
|
package/data/numeric.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { $internal } from "../shared/symbols.js";
|
|
2
|
-
import { stitch } from "../core/resolve/stitch.js";
|
|
3
2
|
import { callableSchema } from "../core/function/createCallableSchema.js";
|
|
4
|
-
|
|
5
3
|
//#region src/data/numeric.ts
|
|
6
4
|
const abstractInt = {
|
|
7
5
|
[$internal]: {},
|
|
@@ -19,16 +17,14 @@ const abstractFloat = {
|
|
|
19
17
|
};
|
|
20
18
|
const boolCast = callableSchema({
|
|
21
19
|
name: "bool",
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
returnType: bool
|
|
25
|
-
}),
|
|
20
|
+
schema: () => bool,
|
|
21
|
+
argTypes: (arg) => arg ? [arg] : [],
|
|
26
22
|
normalImpl(v) {
|
|
27
23
|
if (v === void 0) return false;
|
|
28
24
|
if (typeof v === "boolean") return v;
|
|
29
25
|
return !!v;
|
|
30
26
|
},
|
|
31
|
-
codegenImpl: (
|
|
27
|
+
codegenImpl: (ctx, args) => ctx.gen.typeInstantiation(bool, args)
|
|
32
28
|
});
|
|
33
29
|
/**
|
|
34
30
|
* A schema that represents a boolean value. (equivalent to `bool` in WGSL)
|
|
@@ -50,10 +46,8 @@ const bool = Object.assign(boolCast, {
|
|
|
50
46
|
});
|
|
51
47
|
const u32Cast = callableSchema({
|
|
52
48
|
name: "u32",
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
returnType: u32
|
|
56
|
-
}),
|
|
49
|
+
schema: () => u32,
|
|
50
|
+
argTypes: (arg) => arg ? [arg] : [],
|
|
57
51
|
normalImpl(v) {
|
|
58
52
|
if (v === void 0) return 0;
|
|
59
53
|
if (typeof v === "boolean") return v ? 1 : 0;
|
|
@@ -65,7 +59,7 @@ const u32Cast = callableSchema({
|
|
|
65
59
|
}
|
|
66
60
|
return (v & 4294967295) >>> 0;
|
|
67
61
|
},
|
|
68
|
-
codegenImpl: (
|
|
62
|
+
codegenImpl: (ctx, args) => ctx.gen.typeInstantiation(u32, args)
|
|
69
63
|
});
|
|
70
64
|
/**
|
|
71
65
|
* A schema that represents an unsigned 32-bit integer value. (equivalent to `u32` in WGSL)
|
|
@@ -89,16 +83,14 @@ const u32 = Object.assign(u32Cast, {
|
|
|
89
83
|
});
|
|
90
84
|
const i32Cast = callableSchema({
|
|
91
85
|
name: "i32",
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
returnType: i32
|
|
95
|
-
}),
|
|
86
|
+
schema: () => i32,
|
|
87
|
+
argTypes: (arg) => arg ? [arg] : [],
|
|
96
88
|
normalImpl(v) {
|
|
97
89
|
if (v === void 0) return 0;
|
|
98
90
|
if (typeof v === "boolean") return v ? 1 : 0;
|
|
99
91
|
return v | 0;
|
|
100
92
|
},
|
|
101
|
-
codegenImpl: (
|
|
93
|
+
codegenImpl: (ctx, args) => ctx.gen.typeInstantiation(i32, args)
|
|
102
94
|
});
|
|
103
95
|
const u16 = {
|
|
104
96
|
[$internal]: {},
|
|
@@ -124,16 +116,14 @@ const i32 = Object.assign(i32Cast, {
|
|
|
124
116
|
});
|
|
125
117
|
const f32Cast = callableSchema({
|
|
126
118
|
name: "f32",
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
returnType: f32
|
|
130
|
-
}),
|
|
119
|
+
schema: () => f32,
|
|
120
|
+
argTypes: (arg) => arg ? [arg] : [],
|
|
131
121
|
normalImpl(v) {
|
|
132
122
|
if (v === void 0) return 0;
|
|
133
123
|
if (typeof v === "boolean") return v ? 1 : 0;
|
|
134
124
|
return Math.fround(v);
|
|
135
125
|
},
|
|
136
|
-
codegenImpl: (
|
|
126
|
+
codegenImpl: (ctx, args) => ctx.gen.typeInstantiation(f32, args)
|
|
137
127
|
});
|
|
138
128
|
/**
|
|
139
129
|
* A schema that represents a 32-bit float value. (equivalent to `f32` in WGSL)
|
|
@@ -200,16 +190,14 @@ function roundToF16(x) {
|
|
|
200
190
|
}
|
|
201
191
|
const f16Cast = callableSchema({
|
|
202
192
|
name: "f16",
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
returnType: f16
|
|
206
|
-
}),
|
|
193
|
+
schema: () => f16,
|
|
194
|
+
argTypes: (arg) => arg ? [arg] : [],
|
|
207
195
|
normalImpl(v) {
|
|
208
196
|
if (v === void 0) return 0;
|
|
209
197
|
if (typeof v === "boolean") return v ? 1 : 0;
|
|
210
198
|
return roundToF16(v);
|
|
211
199
|
},
|
|
212
|
-
codegenImpl: (
|
|
200
|
+
codegenImpl: (ctx, args) => ctx.gen.typeInstantiation(f16, args)
|
|
213
201
|
});
|
|
214
202
|
/**
|
|
215
203
|
* A schema that represents a 16-bit float value. (equivalent to `f16` in WGSL)
|
|
@@ -229,6 +217,5 @@ const f16 = Object.assign(f16Cast, {
|
|
|
229
217
|
[$internal]: {},
|
|
230
218
|
type: "f16"
|
|
231
219
|
});
|
|
232
|
-
|
|
233
220
|
//#endregion
|
|
234
|
-
export { abstractFloat, abstractInt, bool, f16, f32, i32, u16, u32 };
|
|
221
|
+
export { abstractFloat, abstractInt, bool, f16, f32, i32, u16, u32 };
|
package/data/offsetUtils.d.ts
CHANGED
|
@@ -25,9 +25,9 @@ interface PrimitiveOffsetInfo {
|
|
|
25
25
|
* ```
|
|
26
26
|
*
|
|
27
27
|
* @param schema - The data schema to analyze.
|
|
28
|
-
* @param accessor - Optional function that accesses a specific
|
|
28
|
+
* @param accessor - Optional function that accesses a specific element within the schema. If omitted, uses the root offset (0).
|
|
29
29
|
* @returns An object containing the offset and contiguous byte information.
|
|
30
30
|
*/
|
|
31
|
-
declare function memoryLayoutOf<T extends BaseData>(schema: T, accessor?: (proxy: Infer<T>) =>
|
|
31
|
+
declare function memoryLayoutOf<T extends BaseData>(schema: T, accessor?: (proxy: Infer<T>) => unknown): PrimitiveOffsetInfo;
|
|
32
32
|
//#endregion
|
|
33
33
|
export { PrimitiveOffsetInfo, memoryLayoutOf };
|
package/data/offsetUtils.js
CHANGED
|
@@ -6,7 +6,6 @@ import { sizeOf } from "./sizeOf.js";
|
|
|
6
6
|
import { offsetsForProps } from "./offsets.js";
|
|
7
7
|
import { isContiguous } from "./isContiguous.js";
|
|
8
8
|
import { getLongestContiguousPrefix } from "./getLongestContiguousPrefix.js";
|
|
9
|
-
|
|
10
9
|
//#region src/data/offsetUtils.ts
|
|
11
10
|
const OFFSET_MARKER = Symbol("indirectOffset");
|
|
12
11
|
const CONTIGUOUS_MARKER = Symbol("indirectContiguous");
|
|
@@ -147,7 +146,7 @@ function getRootContiguous(schema) {
|
|
|
147
146
|
* ```
|
|
148
147
|
*
|
|
149
148
|
* @param schema - The data schema to analyze.
|
|
150
|
-
* @param accessor - Optional function that accesses a specific
|
|
149
|
+
* @param accessor - Optional function that accesses a specific element within the schema. If omitted, uses the root offset (0).
|
|
151
150
|
* @returns An object containing the offset and contiguous byte information.
|
|
152
151
|
*/
|
|
153
152
|
function memoryLayoutOf(schema, accessor) {
|
|
@@ -160,8 +159,7 @@ function memoryLayoutOf(schema, accessor) {
|
|
|
160
159
|
offset: result[OFFSET_MARKER],
|
|
161
160
|
contiguous: result[CONTIGUOUS_MARKER]
|
|
162
161
|
};
|
|
163
|
-
throw new Error("
|
|
162
|
+
throw new Error("memoryLayoutOf: accessor did not return a schema element. Make sure the accessor navigates to a field or element of the schema (e.g. `(s) => s.position.x`).");
|
|
164
163
|
}
|
|
165
|
-
|
|
166
164
|
//#endregion
|
|
167
|
-
export { memoryLayoutOf };
|
|
165
|
+
export { memoryLayoutOf };
|
package/data/offsets.js
CHANGED
|
@@ -4,7 +4,6 @@ import { roundUp } from "../mathUtils.js";
|
|
|
4
4
|
import { sizeOf } from "./sizeOf.js";
|
|
5
5
|
import alignIO from "./alignIO.js";
|
|
6
6
|
import { Measurer } from "typed-binary";
|
|
7
|
-
|
|
8
7
|
//#region src/data/offsets.ts
|
|
9
8
|
const cachedOffsets = /* @__PURE__ */ new WeakMap();
|
|
10
9
|
function offsetsForProps(struct) {
|
|
@@ -31,6 +30,5 @@ function offsetsForProps(struct) {
|
|
|
31
30
|
cachedOffsets.set(struct, offsets);
|
|
32
31
|
return offsets;
|
|
33
32
|
}
|
|
34
|
-
|
|
35
33
|
//#endregion
|
|
36
|
-
export { offsetsForProps };
|
|
34
|
+
export { offsetsForProps };
|
package/data/partialIO.js
CHANGED
|
@@ -4,65 +4,110 @@ import { alignmentOf } from "./alignmentOf.js";
|
|
|
4
4
|
import { roundUp } from "../mathUtils.js";
|
|
5
5
|
import { sizeOf } from "./sizeOf.js";
|
|
6
6
|
import { offsetsForProps } from "./offsets.js";
|
|
7
|
+
import { getCompiledWriter } from "./compiledIO.js";
|
|
7
8
|
import { writeData } from "./dataIO.js";
|
|
8
|
-
import { BufferWriter } from "typed-binary";
|
|
9
|
-
|
|
9
|
+
import { BufferWriter, getSystemEndianness } from "typed-binary";
|
|
10
10
|
//#region src/data/partialIO.ts
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Converts `{idx, value}[]` sparse arrays into `Record<number, T>` format.
|
|
13
|
+
*/
|
|
14
|
+
function convertPartialToPatch(schema, data) {
|
|
15
|
+
if (data === void 0 || data === null) return data;
|
|
16
|
+
if (isWgslStruct(schema) || isUnstruct(schema)) {
|
|
17
|
+
const result = {};
|
|
18
|
+
const record = data;
|
|
19
|
+
for (const key of Object.keys(schema.propTypes)) {
|
|
20
|
+
const subSchema = schema.propTypes[key];
|
|
21
|
+
const value = record[key];
|
|
22
|
+
if (value !== void 0 && subSchema) result[key] = convertPartialToPatch(subSchema, value);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
if (isWgslArray(schema) || isDisarray(schema)) {
|
|
27
|
+
const arrSchema = schema;
|
|
28
|
+
const result = {};
|
|
29
|
+
for (const { idx, value } of data) result[idx] = convertPartialToPatch(arrSchema.elementType, value);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
return data;
|
|
33
|
+
}
|
|
34
|
+
const isLittleEndian = getSystemEndianness() === "little";
|
|
35
|
+
function getPatchInstructions(schema, data, targetBuffer) {
|
|
12
36
|
const totalSize = sizeOf(schema);
|
|
13
37
|
if (totalSize === 0 || data === void 0 || data === null) return [];
|
|
14
|
-
const
|
|
15
|
-
const writer = new BufferWriter(
|
|
38
|
+
const buf = targetBuffer ?? new ArrayBuffer(totalSize);
|
|
39
|
+
const writer = new BufferWriter(buf);
|
|
40
|
+
const compiledView = new DataView(buf);
|
|
16
41
|
const segments = [];
|
|
17
|
-
function
|
|
18
|
-
if (
|
|
42
|
+
function collect(node, value, offset, padding) {
|
|
43
|
+
if (value === void 0 || value === null) return;
|
|
19
44
|
if (isWgslStruct(node) || isUnstruct(node)) {
|
|
20
45
|
const propOffsets = offsetsForProps(node);
|
|
21
46
|
for (const [key, propOffset] of Object.entries(propOffsets)) {
|
|
47
|
+
const childValue = value[key];
|
|
22
48
|
const subSchema = node.propTypes[key];
|
|
23
|
-
if (
|
|
24
|
-
const childValue = partialValue[key];
|
|
25
|
-
if (childValue !== void 0) gatherAndWrite(subSchema, childValue, offset + propOffset.offset, propOffset.padding ?? padding);
|
|
49
|
+
if (childValue !== void 0 && subSchema) collect(subSchema, childValue, offset + propOffset.offset, propOffset.padding ?? padding);
|
|
26
50
|
}
|
|
27
51
|
return;
|
|
28
52
|
}
|
|
29
53
|
if (isWgslArray(node) || isDisarray(node)) {
|
|
30
54
|
const arrSchema = node;
|
|
31
55
|
const elementSize = roundUp(sizeOf(arrSchema.elementType), alignmentOf(arrSchema.elementType));
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
56
|
+
const elementPadding = elementSize - sizeOf(arrSchema.elementType);
|
|
57
|
+
if (ArrayBuffer.isView(value)) {
|
|
58
|
+
const copyLen = Math.min(value.byteLength, arrSchema.elementCount * elementSize);
|
|
59
|
+
new Uint8Array(buf, offset, copyLen).set(new Uint8Array(value.buffer, value.byteOffset, copyLen));
|
|
60
|
+
segments.push({
|
|
61
|
+
start: offset,
|
|
62
|
+
end: offset + copyLen,
|
|
63
|
+
padding
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(value)) {
|
|
68
|
+
for (let i = 0; i < Math.min(arrSchema.elementCount, value.length); i++) collect(arrSchema.elementType, value[i], offset + i * elementSize, elementPadding);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const sparse = value;
|
|
72
|
+
for (const key of Object.keys(sparse)) {
|
|
73
|
+
const idx = Number(key);
|
|
74
|
+
if (!Number.isNaN(idx)) collect(arrSchema.elementType, sparse[key], offset + idx * elementSize, elementPadding);
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const leafSize = sizeOf(node);
|
|
79
|
+
const compiledWriter = getCompiledWriter(node);
|
|
80
|
+
if (compiledWriter) compiledWriter(compiledView, offset, value, isLittleEndian, offset + leafSize);
|
|
81
|
+
else {
|
|
38
82
|
writer.seekTo(offset);
|
|
39
|
-
writeData(writer, node,
|
|
40
|
-
segments.push({
|
|
41
|
-
start: offset,
|
|
42
|
-
end: offset + leafSize,
|
|
43
|
-
padding
|
|
44
|
-
});
|
|
83
|
+
writeData(writer, node, value);
|
|
45
84
|
}
|
|
85
|
+
segments.push({
|
|
86
|
+
start: offset,
|
|
87
|
+
end: offset + leafSize,
|
|
88
|
+
padding
|
|
89
|
+
});
|
|
46
90
|
}
|
|
47
|
-
|
|
48
|
-
if (segments.length === 0) return [];
|
|
91
|
+
collect(schema, data, 0);
|
|
49
92
|
const instructions = [];
|
|
50
|
-
let
|
|
51
|
-
for (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
93
|
+
let run = null;
|
|
94
|
+
for (const seg of segments) if (run && seg.start === run.end + (run.padding ?? 0)) run = {
|
|
95
|
+
start: run.start,
|
|
96
|
+
end: seg.end,
|
|
97
|
+
padding: seg.padding
|
|
98
|
+
};
|
|
99
|
+
else {
|
|
100
|
+
if (run) instructions.push({
|
|
101
|
+
gpuOffset: run.start,
|
|
102
|
+
data: new Uint8Array(buf, run.start, run.end - run.start).slice()
|
|
103
|
+
});
|
|
104
|
+
run = seg;
|
|
61
105
|
}
|
|
62
|
-
if (
|
|
63
|
-
|
|
106
|
+
if (run) instructions.push({
|
|
107
|
+
gpuOffset: run.start,
|
|
108
|
+
data: new Uint8Array(buf, run.start, run.end - run.start).slice()
|
|
109
|
+
});
|
|
64
110
|
return instructions;
|
|
65
111
|
}
|
|
66
|
-
|
|
67
112
|
//#endregion
|
|
68
|
-
export {
|
|
113
|
+
export { convertPartialToPatch, getPatchInstructions };
|
package/data/ptr.d.ts
CHANGED
package/data/ptr.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { $internal } from "../shared/symbols.js";
|
|
2
2
|
import { originToPtrParams } from "./snippet.js";
|
|
3
|
-
|
|
4
3
|
//#region src/data/ptr.ts
|
|
5
4
|
function ptrFn(inner) {
|
|
6
5
|
return INTERNAL_createPtr("function", inner, "read-write");
|
|
@@ -41,6 +40,5 @@ function implicitFrom(ptr) {
|
|
|
41
40
|
function explicitFrom(ptr) {
|
|
42
41
|
return INTERNAL_createPtr(ptr.addressSpace, ptr.inner, ptr.access, false);
|
|
43
42
|
}
|
|
44
|
-
|
|
45
43
|
//#endregion
|
|
46
|
-
export { createPtrFromOrigin, explicitFrom, implicitFrom, ptrFn, ptrHandle, ptrPrivate, ptrStorage, ptrUniform, ptrWorkgroup };
|
|
44
|
+
export { createPtrFromOrigin, explicitFrom, implicitFrom, ptrFn, ptrHandle, ptrPrivate, ptrStorage, ptrUniform, ptrWorkgroup };
|
package/data/ref.d.ts
CHANGED
package/data/ref.js
CHANGED
|
@@ -6,7 +6,6 @@ import { snip } from "./snippet.js";
|
|
|
6
6
|
import { WgslTypeError } from "../errors.js";
|
|
7
7
|
import { stitch } from "../core/resolve/stitch.js";
|
|
8
8
|
import { createPtrFromOrigin, explicitFrom } from "./ptr.js";
|
|
9
|
-
|
|
10
9
|
//#region src/data/ref.ts
|
|
11
10
|
const _ref = (() => {
|
|
12
11
|
const impl = ((value) => INTERNAL_createRef(value));
|
|
@@ -91,6 +90,5 @@ function derefSnippet(snippet) {
|
|
|
91
90
|
if (snippet.value instanceof RefOperator) return snip(stitch`${snippet.value.snippet}`, innerType, origin);
|
|
92
91
|
return snip(stitch`(*${snippet})`, innerType, origin);
|
|
93
92
|
}
|
|
94
|
-
|
|
95
93
|
//#endregion
|
|
96
|
-
export { RefOperator, _ref, derefSnippet, isRef };
|
|
94
|
+
export { RefOperator, _ref, derefSnippet, isRef };
|
package/data/sampler.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { $internal, $repr } from "../shared/symbols.js";
|
|
2
|
-
|
|
3
2
|
//#region src/data/sampler.ts
|
|
4
3
|
function sampler() {
|
|
5
4
|
return {
|
|
@@ -21,6 +20,5 @@ function isWgslSampler(value) {
|
|
|
21
20
|
function isWgslComparisonSampler(value) {
|
|
22
21
|
return !!value[$internal] && value.type === "sampler_comparison";
|
|
23
22
|
}
|
|
24
|
-
|
|
25
23
|
//#endregion
|
|
26
|
-
export { comparisonSampler, isWgslComparisonSampler, isWgslSampler, sampler };
|
|
24
|
+
export { comparisonSampler, isWgslComparisonSampler, isWgslSampler, sampler };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { $cast, $gpuCallable } from "../shared/symbols.js";
|
|
2
2
|
import { hasCast, isGPUCallable } from "../types.js";
|
|
3
|
-
|
|
4
3
|
//#region src/data/schemaCallWrapper.ts
|
|
5
4
|
/**
|
|
6
5
|
* A wrapper for `schema(item)` or `schema()` call on JS side.
|
|
@@ -27,6 +26,5 @@ function schemaCallWrapperGPU(ctx, schema, item) {
|
|
|
27
26
|
const callSchema = schema;
|
|
28
27
|
return item === void 0 || item.value === void 0 ? callSchema[$gpuCallable].call(ctx, []) : callSchema[$gpuCallable].call(ctx, [item]);
|
|
29
28
|
}
|
|
30
|
-
|
|
31
29
|
//#endregion
|
|
32
|
-
export { schemaCallWrapper, schemaCallWrapperGPU };
|
|
30
|
+
export { schemaCallWrapper, schemaCallWrapperGPU };
|
|
@@ -2,7 +2,6 @@ import { isDecorated, isWgslArray, isWgslStruct } from "./wgslTypes.js";
|
|
|
2
2
|
import { getCustomSize, isDisarray, isLooseDecorated, isUnstruct, undecorate } from "./dataTypes.js";
|
|
3
3
|
import { alignmentOf, customAlignmentOf } from "./alignmentOf.js";
|
|
4
4
|
import { roundUp } from "../mathUtils.js";
|
|
5
|
-
|
|
6
5
|
//#region src/data/schemaMemoryLayout.ts
|
|
7
6
|
const knownSizesMap = {
|
|
8
7
|
bool: 4,
|
|
@@ -195,6 +194,5 @@ function getLayoutInfo(schema, key) {
|
|
|
195
194
|
}
|
|
196
195
|
return layout[key];
|
|
197
196
|
}
|
|
198
|
-
|
|
199
197
|
//#endregion
|
|
200
|
-
export { getLayoutInfo };
|
|
198
|
+
export { getLayoutInfo };
|
package/data/sizeOf.d.ts
CHANGED
package/data/sizeOf.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { getLayoutInfo } from "./schemaMemoryLayout.js";
|
|
2
|
-
|
|
3
2
|
//#region src/data/sizeOf.ts
|
|
4
3
|
function sizeOf(schema) {
|
|
5
4
|
return getLayoutInfo(schema, "size");
|
|
@@ -10,6 +9,5 @@ function sizeOf(schema) {
|
|
|
10
9
|
function PUBLIC_sizeOf(schema) {
|
|
11
10
|
return sizeOf(schema);
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
//#endregion
|
|
15
|
-
export { PUBLIC_sizeOf, sizeOf };
|
|
13
|
+
export { PUBLIC_sizeOf, sizeOf };
|