typegpu 0.11.3 → 0.11.5
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/README.md +4 -2
- package/core/buffer/buffer.js +17 -53
- package/core/buffer/bufferUsage.js +2 -2
- package/core/constant/tgpuConstant.js +1 -1
- package/core/function/fnCore.js +12 -6
- package/core/function/tgpuFragmentFn.d.ts +1 -1
- package/core/pipeline/computePipeline.d.ts +1 -1
- package/core/pipeline/computePipeline.js +1 -1
- package/core/pipeline/renderPipeline.js +1 -1
- package/core/resolve/namespace.d.ts +2 -11
- package/core/resolve/namespace.js +7 -24
- package/core/resolve/resolveData.js +3 -2
- package/core/resolve/tgpuResolve.js +1 -1
- package/core/root/init.d.ts +1 -0
- package/core/root/init.js +6 -0
- package/core/root/rootTypes.d.ts +21 -15
- package/core/sampler/sampler.js +2 -2
- package/core/simulate/tgpuSimulate.js +1 -1
- package/core/slot/accessor.js +1 -1
- package/core/texture/externalTexture.js +1 -1
- package/core/texture/texture.js +2 -2
- package/core/variable/tgpuVariable.js +1 -1
- package/data/autoStruct.js +3 -2
- package/data/dataIO.d.ts +11 -0
- package/data/dataIO.js +45 -1
- package/data/dataTypes.d.ts +1 -1
- package/data/dataTypes.js +2 -11
- package/data/partialIO.d.ts +8 -0
- package/data/partialIO.js +6 -1
- package/data/struct.js +3 -2
- package/data/wgslTypes.d.ts +16 -16
- package/index.d.ts +3 -1
- package/index.js +3 -1
- package/indexNamedExports.d.ts +2 -0
- package/{nameRegistry.js → nameUtils.js} +46 -90
- package/package.js +1 -1
- package/package.json +1 -1
- package/resolutionCtx.js +64 -30
- package/shared/stringify.js +1 -0
- package/shared/tseynit.js +90 -0
- package/std/copy.d.ts +7 -0
- package/std/copy.js +27 -0
- package/std/index.d.ts +3 -2
- package/std/index.js +3 -1
- package/tgpuUnstable.js +1 -1
- package/tgsl/accessIndex.js +2 -1
- package/tgsl/consoleLog/deserializers.js +1 -1
- package/tgsl/consoleLog/logGenerator.js +1 -6
- package/tgsl/consoleLog/types.d.ts +4 -5
- package/tgsl/conversion.js +4 -1
- package/tgsl/generationHelpers.d.ts +2 -1
- package/tgsl/jsPolyfills.d.ts +25 -0
- package/tgsl/jsPolyfills.js +44 -0
- package/tgsl/wgslGenerator.d.ts +20 -2
- package/tgsl/wgslGenerator.js +114 -57
- package/types.d.ts +29 -2
- package/nameRegistry.d.ts +0 -30
- package/tgsl/consoleLog/types.js +0 -12
- package/tgsl/math.js +0 -45
package/data/dataIO.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import { getName } from "../shared/meta.js";
|
|
2
|
+
import { isWgslArray } from "./wgslTypes.js";
|
|
1
3
|
import { vec2f, vec2h, vec2i, vec2u, vec3f, vec3h, vec3i, vec3u, vec4f, vec4h, vec4i, vec4u } from "./vector.js";
|
|
2
4
|
import { alignmentOf, customAlignmentOf } from "./alignmentOf.js";
|
|
5
|
+
import { roundUp } from "../mathUtils.js";
|
|
3
6
|
import { sizeOf } from "./sizeOf.js";
|
|
4
7
|
import { mat2x2f, mat3x3f, mat4x4f } from "./matrix.js";
|
|
5
8
|
import alignIO_default from "./alignIO.js";
|
|
9
|
+
import { getCompiledWriter } from "./compiledIO.js";
|
|
10
|
+
import { BufferReader, BufferWriter, getSystemEndianness } from "typed-binary";
|
|
6
11
|
|
|
7
12
|
//#region src/data/dataIO.ts
|
|
8
13
|
const dataWriters = {
|
|
@@ -553,6 +558,45 @@ function readData(input, schema) {
|
|
|
553
558
|
if (!reader) throw new Error(`Cannot read data of type '${schema.type}'.`);
|
|
554
559
|
return reader(input, schema);
|
|
555
560
|
}
|
|
561
|
+
const endianness = getSystemEndianness();
|
|
562
|
+
function calculateOffsets(options, schema, data) {
|
|
563
|
+
const bufferSize = sizeOf(schema);
|
|
564
|
+
const startOffset = options?.startOffset ?? 0;
|
|
565
|
+
let naturalSize = void 0;
|
|
566
|
+
if (isWgslArray(schema) && Array.isArray(data)) naturalSize = data.length * roundUp(sizeOf(schema.elementType), alignmentOf(schema.elementType));
|
|
567
|
+
else if (ArrayBuffer.isView(data) || data instanceof ArrayBuffer) naturalSize = data.byteLength;
|
|
568
|
+
const naturalEndOffset = naturalSize !== void 0 ? Math.min(startOffset + naturalSize, bufferSize) : void 0;
|
|
569
|
+
return {
|
|
570
|
+
startOffset,
|
|
571
|
+
endOffset: options?.endOffset ?? naturalEndOffset ?? bufferSize
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
function writeToArrayBuffer(buffer, schema, data, options) {
|
|
575
|
+
const { startOffset, endOffset } = calculateOffsets(options, schema, data);
|
|
576
|
+
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
|
|
577
|
+
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
578
|
+
const regionSize = endOffset - startOffset;
|
|
579
|
+
if (src.byteLength !== regionSize) console.warn(`Buffer size mismatch: expected ${regionSize} bytes, got ${src.byteLength}. ` + (src.byteLength < regionSize ? "Data truncated." : "Excess ignored."));
|
|
580
|
+
const copyLen = Math.min(src.byteLength, regionSize);
|
|
581
|
+
new Uint8Array(buffer).set(src.subarray(0, copyLen), startOffset);
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
const dataView = new DataView(buffer);
|
|
585
|
+
const isLittleEndian = endianness === "little";
|
|
586
|
+
const compiledWriter = getCompiledWriter(schema);
|
|
587
|
+
if (compiledWriter) try {
|
|
588
|
+
compiledWriter(dataView, startOffset, data, isLittleEndian, endOffset);
|
|
589
|
+
return;
|
|
590
|
+
} catch (error) {
|
|
591
|
+
console.error(`Error when using compiled writer for data type '${schema.type}' (${getName(schema) ?? "unnamed"}) - this is likely a bug, please submit an issue at https://github.com/software-mansion/TypeGPU/issues\nUsing fallback writer instead.`, error);
|
|
592
|
+
}
|
|
593
|
+
const writer = new BufferWriter(buffer);
|
|
594
|
+
writer.seekTo(startOffset);
|
|
595
|
+
writeData(writer, schema, data);
|
|
596
|
+
}
|
|
597
|
+
function readFromArrayBuffer(buffer, schema) {
|
|
598
|
+
return readData(new BufferReader(buffer), schema);
|
|
599
|
+
}
|
|
556
600
|
|
|
557
601
|
//#endregion
|
|
558
|
-
export {
|
|
602
|
+
export { calculateOffsets, readFromArrayBuffer, writeData, writeToArrayBuffer };
|
package/data/dataTypes.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ interface Disarray<out TElement extends BaseData = BaseData> extends BaseData {
|
|
|
26
26
|
readonly elementCount: number;
|
|
27
27
|
readonly elementType: TElement;
|
|
28
28
|
readonly [$repr]: Infer<TElement>[];
|
|
29
|
-
readonly [$inRepr]: InferInput<TElement>[] | TypedArrayFor<TElement>;
|
|
29
|
+
readonly [$inRepr]: readonly InferInput<TElement>[] | TypedArrayFor<TElement>;
|
|
30
30
|
readonly [$reprPartial]: {
|
|
31
31
|
idx: number;
|
|
32
32
|
value: InferPartial<TElement>;
|
package/data/dataTypes.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { setName } from "../shared/meta.js";
|
|
1
|
+
import { isMarkedInternal } from "../shared/symbols.js";
|
|
3
2
|
import { vertexFormats } from "../shared/vertexFormat.js";
|
|
4
3
|
import { isAlignAttrib, isDecorated, isLocationAttrib, isPtr, isSizeAttrib, isWgslData } from "./wgslTypes.js";
|
|
5
4
|
|
|
@@ -89,14 +88,6 @@ var MatrixColumnsAccess = class {
|
|
|
89
88
|
this.matrix = matrix;
|
|
90
89
|
}
|
|
91
90
|
};
|
|
92
|
-
var ConsoleLog = class {
|
|
93
|
-
[$internal] = true;
|
|
94
|
-
op;
|
|
95
|
-
constructor(op) {
|
|
96
|
-
this.op = op;
|
|
97
|
-
setName(this, "consoleLog");
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
91
|
|
|
101
92
|
//#endregion
|
|
102
|
-
export {
|
|
93
|
+
export { InfixDispatch, MatrixColumnsAccess, UnknownData, getCustomAlignment, getCustomLocation, getCustomSize, isData, isDisarray, isLooseData, isLooseDecorated, isUnstruct, undecorate, unptr };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseData } from "./wgslTypes.js";
|
|
2
|
+
import { InferPatch } from "../shared/repr.js";
|
|
3
|
+
|
|
4
|
+
//#region src/data/partialIO.d.ts
|
|
5
|
+
|
|
6
|
+
declare function patchArrayBuffer<T extends BaseData>(buffer: ArrayBuffer, schema: T, data: InferPatch<T>): void;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { patchArrayBuffer };
|
package/data/partialIO.js
CHANGED
|
@@ -110,6 +110,11 @@ function getPatchInstructions(schema, data, targetBuffer) {
|
|
|
110
110
|
});
|
|
111
111
|
return instructions;
|
|
112
112
|
}
|
|
113
|
+
function patchArrayBuffer(buffer, schema, data) {
|
|
114
|
+
const instructions = getPatchInstructions(schema, data, buffer);
|
|
115
|
+
const mappedView = new Uint8Array(buffer);
|
|
116
|
+
for (const { data: data$1, gpuOffset } of instructions) mappedView.set(data$1, gpuOffset);
|
|
117
|
+
}
|
|
113
118
|
|
|
114
119
|
//#endregion
|
|
115
|
-
export { convertPartialToPatch, getPatchInstructions };
|
|
120
|
+
export { convertPartialToPatch, getPatchInstructions, patchArrayBuffer };
|
package/data/struct.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { $internal } from "../shared/symbols.js";
|
|
2
2
|
import { getName, setName } from "../shared/meta.js";
|
|
3
3
|
import { schemaCallWrapper } from "./schemaCallWrapper.js";
|
|
4
|
-
import {
|
|
4
|
+
import { validateProp } from "../nameUtils.js";
|
|
5
5
|
|
|
6
6
|
//#region src/data/struct.ts
|
|
7
7
|
/**
|
|
@@ -23,7 +23,8 @@ function abstruct(props) {
|
|
|
23
23
|
}
|
|
24
24
|
function INTERNAL_createStruct(props, isAbstruct) {
|
|
25
25
|
Object.keys(props).forEach((key) => {
|
|
26
|
-
|
|
26
|
+
const result = /* @__PURE__ */ validateProp(key);
|
|
27
|
+
if (!result.success) throw new Error(`Invalid property key '${key}'${result.error ? `: ${result.error}` : ""}`);
|
|
27
28
|
});
|
|
28
29
|
const structSchema = (instanceProps) => Object.fromEntries(Object.entries(props).map(([key, schema]) => [key, schemaCallWrapper(schema, instanceProps?.[key])]));
|
|
29
30
|
Object.setPrototypeOf(structSchema, WgslStructImpl);
|
package/data/wgslTypes.d.ts
CHANGED
|
@@ -493,7 +493,7 @@ interface Vec2f extends BaseData, DualFn<((x: number, y: number) => v2f) & ((xy:
|
|
|
493
493
|
readonly primitive: F32;
|
|
494
494
|
readonly componentCount: 2;
|
|
495
495
|
readonly [$repr]: v2f;
|
|
496
|
-
readonly [$inRepr]: v2f | [number, number] | Float32Array;
|
|
496
|
+
readonly [$inRepr]: v2f | readonly [number, number] | Float32Array;
|
|
497
497
|
readonly [$validStorageSchema]: true;
|
|
498
498
|
readonly [$validUniformSchema]: true;
|
|
499
499
|
readonly [$validVertexSchema]: true;
|
|
@@ -506,7 +506,7 @@ interface Vec2h extends BaseData, DualFn<((x: number, y: number) => v2h) & ((xy:
|
|
|
506
506
|
readonly primitive: F16;
|
|
507
507
|
readonly componentCount: 2;
|
|
508
508
|
readonly [$repr]: v2h;
|
|
509
|
-
readonly [$inRepr]: v2h | [number, number] | Float16Array;
|
|
509
|
+
readonly [$inRepr]: v2h | readonly [number, number] | Float16Array;
|
|
510
510
|
readonly [$validStorageSchema]: true;
|
|
511
511
|
readonly [$validUniformSchema]: true;
|
|
512
512
|
readonly [$validVertexSchema]: true;
|
|
@@ -519,7 +519,7 @@ interface Vec2i extends BaseData, DualFn<((x: number, y: number) => v2i) & ((xy:
|
|
|
519
519
|
readonly primitive: I32;
|
|
520
520
|
readonly componentCount: 2;
|
|
521
521
|
readonly [$repr]: v2i;
|
|
522
|
-
readonly [$inRepr]: v2i | [number, number] | Int32Array;
|
|
522
|
+
readonly [$inRepr]: v2i | readonly [number, number] | Int32Array;
|
|
523
523
|
readonly [$validStorageSchema]: true;
|
|
524
524
|
readonly [$validUniformSchema]: true;
|
|
525
525
|
readonly [$validVertexSchema]: true;
|
|
@@ -532,7 +532,7 @@ interface Vec2u extends BaseData, DualFn<((x: number, y: number) => v2u) & ((xy:
|
|
|
532
532
|
readonly primitive: U32;
|
|
533
533
|
readonly componentCount: 2;
|
|
534
534
|
readonly [$repr]: v2u;
|
|
535
|
-
readonly [$inRepr]: v2u | [number, number] | Uint32Array;
|
|
535
|
+
readonly [$inRepr]: v2u | readonly [number, number] | Uint32Array;
|
|
536
536
|
readonly [$validStorageSchema]: true;
|
|
537
537
|
readonly [$validUniformSchema]: true;
|
|
538
538
|
readonly [$validVertexSchema]: true;
|
|
@@ -556,7 +556,7 @@ interface Vec3f extends BaseData, DualFn<((x: number, y: number, z: number) => v
|
|
|
556
556
|
readonly primitive: F32;
|
|
557
557
|
readonly componentCount: 3;
|
|
558
558
|
readonly [$repr]: v3f;
|
|
559
|
-
readonly [$inRepr]: v3f | [number, number, number] | Float32Array;
|
|
559
|
+
readonly [$inRepr]: v3f | readonly [number, number, number] | Float32Array;
|
|
560
560
|
readonly [$validStorageSchema]: true;
|
|
561
561
|
readonly [$validUniformSchema]: true;
|
|
562
562
|
readonly [$validVertexSchema]: true;
|
|
@@ -569,7 +569,7 @@ interface Vec3h extends BaseData, DualFn<((x: number, y: number, z: number) => v
|
|
|
569
569
|
readonly primitive: F16;
|
|
570
570
|
readonly componentCount: 3;
|
|
571
571
|
readonly [$repr]: v3h;
|
|
572
|
-
readonly [$inRepr]: v3h | [number, number, number] | Float16Array;
|
|
572
|
+
readonly [$inRepr]: v3h | readonly [number, number, number] | Float16Array;
|
|
573
573
|
readonly [$validStorageSchema]: true;
|
|
574
574
|
readonly [$validUniformSchema]: true;
|
|
575
575
|
readonly [$validVertexSchema]: true;
|
|
@@ -582,7 +582,7 @@ interface Vec3i extends BaseData, DualFn<((x: number, y: number, z: number) => v
|
|
|
582
582
|
readonly primitive: I32;
|
|
583
583
|
readonly componentCount: 3;
|
|
584
584
|
readonly [$repr]: v3i;
|
|
585
|
-
readonly [$inRepr]: v3i | [number, number, number] | Int32Array;
|
|
585
|
+
readonly [$inRepr]: v3i | readonly [number, number, number] | Int32Array;
|
|
586
586
|
readonly [$validStorageSchema]: true;
|
|
587
587
|
readonly [$validUniformSchema]: true;
|
|
588
588
|
readonly [$validVertexSchema]: true;
|
|
@@ -595,7 +595,7 @@ interface Vec3u extends BaseData, DualFn<((x: number, y: number, z: number) => v
|
|
|
595
595
|
readonly primitive: U32;
|
|
596
596
|
readonly componentCount: 3;
|
|
597
597
|
readonly [$repr]: v3u;
|
|
598
|
-
readonly [$inRepr]: v3u | [number, number, number] | Uint32Array;
|
|
598
|
+
readonly [$inRepr]: v3u | readonly [number, number, number] | Uint32Array;
|
|
599
599
|
readonly [$validStorageSchema]: true;
|
|
600
600
|
readonly [$validUniformSchema]: true;
|
|
601
601
|
readonly [$validVertexSchema]: true;
|
|
@@ -619,7 +619,7 @@ interface Vec4f extends BaseData, DualFn<((x: number, y: number, z: number, w: n
|
|
|
619
619
|
readonly primitive: F32;
|
|
620
620
|
readonly componentCount: 4;
|
|
621
621
|
readonly [$repr]: v4f;
|
|
622
|
-
readonly [$inRepr]: v4f | [number, number, number, number] | Float32Array;
|
|
622
|
+
readonly [$inRepr]: v4f | readonly [number, number, number, number] | Float32Array;
|
|
623
623
|
readonly [$validStorageSchema]: true;
|
|
624
624
|
readonly [$validUniformSchema]: true;
|
|
625
625
|
readonly [$validVertexSchema]: true;
|
|
@@ -632,7 +632,7 @@ interface Vec4h extends BaseData, DualFn<((x: number, y: number, z: number, w: n
|
|
|
632
632
|
readonly primitive: F16;
|
|
633
633
|
readonly componentCount: 4;
|
|
634
634
|
readonly [$repr]: v4h;
|
|
635
|
-
readonly [$inRepr]: v4h | [number, number, number, number] | Float16Array;
|
|
635
|
+
readonly [$inRepr]: v4h | readonly [number, number, number, number] | Float16Array;
|
|
636
636
|
readonly [$validStorageSchema]: true;
|
|
637
637
|
readonly [$validUniformSchema]: true;
|
|
638
638
|
readonly [$validVertexSchema]: true;
|
|
@@ -645,7 +645,7 @@ interface Vec4i extends BaseData, DualFn<((x: number, y: number, z: number, w: n
|
|
|
645
645
|
readonly primitive: I32;
|
|
646
646
|
readonly componentCount: 4;
|
|
647
647
|
readonly [$repr]: v4i;
|
|
648
|
-
readonly [$inRepr]: v4i | [number, number, number, number] | Int32Array;
|
|
648
|
+
readonly [$inRepr]: v4i | readonly [number, number, number, number] | Int32Array;
|
|
649
649
|
readonly [$validStorageSchema]: true;
|
|
650
650
|
readonly [$validUniformSchema]: true;
|
|
651
651
|
readonly [$validVertexSchema]: true;
|
|
@@ -658,7 +658,7 @@ interface Vec4u extends BaseData, DualFn<((x: number, y: number, z: number, w: n
|
|
|
658
658
|
readonly primitive: U32;
|
|
659
659
|
readonly componentCount: 4;
|
|
660
660
|
readonly [$repr]: v4u;
|
|
661
|
-
readonly [$inRepr]: v4u | [number, number, number, number] | Uint32Array;
|
|
661
|
+
readonly [$inRepr]: v4u | readonly [number, number, number, number] | Uint32Array;
|
|
662
662
|
readonly [$validStorageSchema]: true;
|
|
663
663
|
readonly [$validUniformSchema]: true;
|
|
664
664
|
readonly [$validVertexSchema]: true;
|
|
@@ -681,7 +681,7 @@ interface Mat2x2f extends BaseData {
|
|
|
681
681
|
readonly type: 'mat2x2f';
|
|
682
682
|
readonly primitive: F32;
|
|
683
683
|
readonly [$repr]: m2x2f;
|
|
684
|
-
readonly [$inRepr]: m2x2f | number[] | Float32Array;
|
|
684
|
+
readonly [$inRepr]: m2x2f | readonly number[] | Float32Array;
|
|
685
685
|
readonly [$validStorageSchema]: true;
|
|
686
686
|
readonly [$validUniformSchema]: true;
|
|
687
687
|
(...elements: [number, number, number, number]): m2x2f;
|
|
@@ -696,7 +696,7 @@ interface Mat3x3f extends BaseData {
|
|
|
696
696
|
readonly type: 'mat3x3f';
|
|
697
697
|
readonly primitive: F32;
|
|
698
698
|
readonly [$repr]: m3x3f;
|
|
699
|
-
readonly [$inRepr]: m3x3f | number[] | Float32Array;
|
|
699
|
+
readonly [$inRepr]: m3x3f | readonly number[] | Float32Array;
|
|
700
700
|
readonly [$validStorageSchema]: true;
|
|
701
701
|
readonly [$validUniformSchema]: true;
|
|
702
702
|
(...elements: [number, number, number, number, number, number, number, number, number]): m3x3f;
|
|
@@ -711,7 +711,7 @@ interface Mat4x4f extends BaseData {
|
|
|
711
711
|
readonly type: 'mat4x4f';
|
|
712
712
|
readonly primitive: F32;
|
|
713
713
|
readonly [$repr]: m4x4f;
|
|
714
|
-
readonly [$inRepr]: m4x4f | number[] | Float32Array;
|
|
714
|
+
readonly [$inRepr]: m4x4f | readonly number[] | Float32Array;
|
|
715
715
|
readonly [$validStorageSchema]: true;
|
|
716
716
|
readonly [$validUniformSchema]: true;
|
|
717
717
|
(...elements: [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number]): m4x4f;
|
|
@@ -738,7 +738,7 @@ interface WgslArray<out TElement extends BaseData = BaseData> extends BaseData {
|
|
|
738
738
|
readonly elementCount: number;
|
|
739
739
|
readonly elementType: TElement;
|
|
740
740
|
readonly [$repr]: Infer<TElement>[];
|
|
741
|
-
readonly [$inRepr]: InferInput<TElement>[] | TypedArrayFor<TElement>;
|
|
741
|
+
readonly [$inRepr]: readonly InferInput<TElement>[] | TypedArrayFor<TElement>;
|
|
742
742
|
readonly [$gpuRepr]: InferGPU<TElement>[];
|
|
743
743
|
readonly [$reprPartial]: {
|
|
744
744
|
idx: number;
|
package/index.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ import { index_d_exports as index_d_exports$2 } from "./std/index.js";
|
|
|
38
38
|
import { index_d_exports } from "./common/index.js";
|
|
39
39
|
import { MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, ResolutionError } from "./errors.js";
|
|
40
40
|
import { WgslGenerator } from "./tgsl/wgslGenerator.js";
|
|
41
|
+
import { readFromArrayBuffer, writeToArrayBuffer } from "./data/dataIO.js";
|
|
42
|
+
import { patchArrayBuffer } from "./data/partialIO.js";
|
|
41
43
|
import { TgpuRenderPipelineDescriptor } from "./indexNamedExports.js";
|
|
42
44
|
|
|
43
45
|
//#region src/index.d.ts
|
|
@@ -68,4 +70,4 @@ declare const tgpu: {
|
|
|
68
70
|
'~unstable': typeof tgpuUnstable_d_exports;
|
|
69
71
|
};
|
|
70
72
|
//#endregion
|
|
71
|
-
export { AutoFragmentIn, AutoFragmentOut, _AutoVertexIn as AutoVertexIn, AutoVertexOut, BindLayoutEntry, ColorAttachment, Configurable, Eventual, ExtractBindGroupInputFromLayout, INTERNAL_GlobalExt, IndexFlag, InitFromDeviceOptions, InitOptions, LayoutEntryToInput, MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, Namespace, NotUniformError, RawCodeSnippetOrigin, RenderFlag, ResolutionError, SampledFlag, ShaderGenerator, Storage, StorageFlag, TextureProps, TgpuAccessor, TgpuBindGroup, TgpuBindGroupLayout, TgpuBuffer, TgpuBufferMutable, TgpuBufferReadonly, TgpuBufferUniform, TgpuComparisonSampler, TgpuComptime, TgpuComputeFn, TgpuComputeFnShell, TgpuComputePipeline, TgpuConst, TgpuDeclare, TgpuFixedComparisonSampler, TgpuFixedSampler, TgpuFn, TgpuFnShell, TgpuFragmentFn, TgpuFragmentFnShell, TgpuGenericFn, TgpuGuardedComputePipeline, TgpuLayoutComparisonSampler, TgpuLayoutEntry, TgpuLayoutExternalTexture, TgpuLayoutSampler, TgpuLayoutStorage, TgpuLayoutTexture, TgpuLayoutUniform, TgpuLazy, TgpuMutable, TgpuMutableAccessor, TgpuPrimitiveState, TgpuQuerySet, TgpuRawCodeSnippet, TgpuReadonly, TgpuRenderPipeline, TgpuRenderPipelineDescriptor, TgpuRoot, TgpuSampler, TgpuSlot, TgpuTexture, TgpuTextureView, TgpuUniform, TgpuVar, TgpuVertexFn, TgpuVertexFnShell, TgpuVertexLayout, Uniform, UniformFlag, ValidUsagesFor, ValidateBufferSchema, ValidateStorageSchema, ValidateUniformSchema, VariableScope, Vertex, VertexFlag, WgslGenerator, WithBinding, WithCompute, WithFragment, WithVertex, Withable, index_d_exports as common, index_d_exports$1 as d, tgpu as default, tgpu, isAccessor, isBuffer, isBufferShorthand, isComparisonSampler, isLazy, isMutableAccessor, isSampler, isSlot, isTexture, isTgpuComputeFn, isTgpuFn, isTgpuFragmentFn, isTgpuVertexFn, isUsableAsRender, isUsableAsSampled, isUsableAsStorage, isUsableAsUniform, isUsableAsVertex, isVariable, index_d_exports$2 as std };
|
|
73
|
+
export { AutoFragmentIn, AutoFragmentOut, _AutoVertexIn as AutoVertexIn, AutoVertexOut, BindLayoutEntry, ColorAttachment, Configurable, Eventual, ExtractBindGroupInputFromLayout, INTERNAL_GlobalExt, IndexFlag, InitFromDeviceOptions, InitOptions, LayoutEntryToInput, MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, Namespace, NotUniformError, RawCodeSnippetOrigin, RenderFlag, ResolutionError, SampledFlag, ShaderGenerator, Storage, StorageFlag, TextureProps, TgpuAccessor, TgpuBindGroup, TgpuBindGroupLayout, TgpuBuffer, TgpuBufferMutable, TgpuBufferReadonly, TgpuBufferUniform, TgpuComparisonSampler, TgpuComptime, TgpuComputeFn, TgpuComputeFnShell, TgpuComputePipeline, TgpuConst, TgpuDeclare, TgpuFixedComparisonSampler, TgpuFixedSampler, TgpuFn, TgpuFnShell, TgpuFragmentFn, TgpuFragmentFnShell, TgpuGenericFn, TgpuGuardedComputePipeline, TgpuLayoutComparisonSampler, TgpuLayoutEntry, TgpuLayoutExternalTexture, TgpuLayoutSampler, TgpuLayoutStorage, TgpuLayoutTexture, TgpuLayoutUniform, TgpuLazy, TgpuMutable, TgpuMutableAccessor, TgpuPrimitiveState, TgpuQuerySet, TgpuRawCodeSnippet, TgpuReadonly, TgpuRenderPipeline, TgpuRenderPipelineDescriptor, TgpuRoot, TgpuSampler, TgpuSlot, TgpuTexture, TgpuTextureView, TgpuUniform, TgpuVar, TgpuVertexFn, TgpuVertexFnShell, TgpuVertexLayout, Uniform, UniformFlag, ValidUsagesFor, ValidateBufferSchema, ValidateStorageSchema, ValidateUniformSchema, VariableScope, Vertex, VertexFlag, WgslGenerator, WithBinding, WithCompute, WithFragment, WithVertex, Withable, index_d_exports as common, index_d_exports$1 as d, tgpu as default, tgpu, isAccessor, isBuffer, isBufferShorthand, isComparisonSampler, isLazy, isMutableAccessor, isSampler, isSlot, isTexture, isTgpuComputeFn, isTgpuFn, isTgpuFragmentFn, isTgpuVertexFn, isUsableAsRender, isUsableAsSampled, isUsableAsStorage, isUsableAsUniform, isUsableAsVertex, isVariable, patchArrayBuffer, readFromArrayBuffer, index_d_exports$2 as std, writeToArrayBuffer };
|
package/index.js
CHANGED
|
@@ -2,6 +2,8 @@ import { MissingBindGroupsError, MissingLinksError, MissingSlotValueError, Missi
|
|
|
2
2
|
import { isAccessor, isLazy, isMutableAccessor, isSlot } from "./core/slot/slotTypes.js";
|
|
3
3
|
import { shaderGenerator_members_exports } from "./tgsl/shaderGenerator_members.js";
|
|
4
4
|
import { isTgpuFn } from "./core/function/tgpuFn.js";
|
|
5
|
+
import { readFromArrayBuffer, writeToArrayBuffer } from "./data/dataIO.js";
|
|
6
|
+
import { patchArrayBuffer } from "./data/partialIO.js";
|
|
5
7
|
import { isUsableAsStorage } from "./extension.js";
|
|
6
8
|
import { isUsableAsUniform } from "./core/buffer/bufferUsage.js";
|
|
7
9
|
import { isBuffer, isUsableAsVertex } from "./core/buffer/buffer.js";
|
|
@@ -23,4 +25,4 @@ import { common_exports } from "./common/index.js";
|
|
|
23
25
|
var src_default = tgpu_exports;
|
|
24
26
|
|
|
25
27
|
//#endregion
|
|
26
|
-
export { MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, ResolutionError, shaderGenerator_members_exports as ShaderGenerator, WgslGenerator, common_exports as common, data_exports as d, src_default as default, isAccessor, isBuffer, isBufferShorthand, isComparisonSampler, isLazy, isMutableAccessor, isSampler, isSlot, isTexture, isTgpuComputeFn, isTgpuFn, isTgpuFragmentFn, isTgpuVertexFn, isUsableAsRender, isUsableAsSampled, isUsableAsStorage, isUsableAsUniform, isUsableAsVertex, isVariable, std_exports as std, tgpu_exports as tgpu };
|
|
28
|
+
export { MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, ResolutionError, shaderGenerator_members_exports as ShaderGenerator, WgslGenerator, common_exports as common, data_exports as d, src_default as default, isAccessor, isBuffer, isBufferShorthand, isComparisonSampler, isLazy, isMutableAccessor, isSampler, isSlot, isTexture, isTgpuComputeFn, isTgpuFn, isTgpuFragmentFn, isTgpuVertexFn, isUsableAsRender, isUsableAsSampled, isUsableAsStorage, isUsableAsUniform, isUsableAsVertex, isVariable, patchArrayBuffer, readFromArrayBuffer, std_exports as std, tgpu_exports as tgpu, writeToArrayBuffer };
|
package/indexNamedExports.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ import { index_d_exports as index_d_exports$1 } from "./std/index.js";
|
|
|
32
32
|
import { index_d_exports as index_d_exports$2 } from "./common/index.js";
|
|
33
33
|
import { MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, ResolutionError } from "./errors.js";
|
|
34
34
|
import { WgslGenerator } from "./tgsl/wgslGenerator.js";
|
|
35
|
+
import { readFromArrayBuffer, writeToArrayBuffer } from "./data/dataIO.js";
|
|
36
|
+
import { patchArrayBuffer } from "./data/partialIO.js";
|
|
35
37
|
|
|
36
38
|
//#region src/indexNamedExports.d.ts
|
|
37
39
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//#region src/nameRegistry.ts
|
|
1
|
+
//#region src/nameUtils.ts
|
|
4
2
|
const bannedTokens = new Set([
|
|
5
3
|
"alias",
|
|
6
4
|
"break",
|
|
@@ -344,106 +342,64 @@ const builtins = new Set([
|
|
|
344
342
|
"quadSwapX",
|
|
345
343
|
"quadSwapY"
|
|
346
344
|
]);
|
|
345
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
347
346
|
function sanitizePrimer(primer) {
|
|
348
|
-
if (primer)
|
|
347
|
+
if (primer) {
|
|
348
|
+
const base = primer.replaceAll(/\s/g, "_").replaceAll(/[^\w\d]/g, "");
|
|
349
|
+
if (base === "_" || base === "" || base.startsWith("__")) return "item";
|
|
350
|
+
return base;
|
|
351
|
+
}
|
|
349
352
|
return "item";
|
|
350
353
|
}
|
|
351
354
|
/**
|
|
352
355
|
* A function for checking whether an identifier needs renaming.
|
|
353
356
|
* Throws if provided with an invalid identifier that cannot be easily renamed.
|
|
354
357
|
* @example
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
358
|
+
* validateIdentifier("ident"); // { success: true }
|
|
359
|
+
* validateIdentifier("struct"); // { success: false, error: "Identifiers cannot start with reserved keywords." }
|
|
360
|
+
* validateIdentifier("struct_1"); { success: false, error: "Identifiers cannot start with reserved keywords." }
|
|
361
|
+
* validateIdentifier("_"); // { success: false }
|
|
362
|
+
* validateIdentifier("my variable"); // { success: false, error: "Identifiers cannot contain whitespace." }
|
|
360
363
|
*/
|
|
361
|
-
|
|
362
|
-
|
|
364
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
365
|
+
function validateIdentifier(ident) {
|
|
366
|
+
if (ident === "_") return { success: false };
|
|
367
|
+
if (/\s/.test(ident)) return {
|
|
368
|
+
success: false,
|
|
369
|
+
error: `Identifiers cannot contain whitespace.`
|
|
370
|
+
};
|
|
371
|
+
if (ident.startsWith("__")) return {
|
|
372
|
+
success: false,
|
|
373
|
+
error: `Identifiers cannot start with double underscores.`
|
|
374
|
+
};
|
|
363
375
|
const prefix = ident.split("_")[0];
|
|
364
|
-
|
|
376
|
+
if (bannedTokens.has(prefix) || builtins.has(prefix)) return {
|
|
377
|
+
success: false,
|
|
378
|
+
error: `Identifiers cannot start with reserved keywords.`
|
|
379
|
+
};
|
|
380
|
+
return { success: true };
|
|
365
381
|
}
|
|
366
382
|
/**
|
|
367
|
-
* Same as `
|
|
383
|
+
* Same as `validateIdentifier`, except does not check for builtin clashes.
|
|
368
384
|
*/
|
|
369
|
-
|
|
370
|
-
|
|
385
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
386
|
+
function validateProp(ident) {
|
|
387
|
+
if (ident === "_") return { success: false };
|
|
388
|
+
if (/\s/.test(ident)) return {
|
|
389
|
+
success: false,
|
|
390
|
+
error: `Identifiers cannot contain whitespace.`
|
|
391
|
+
};
|
|
392
|
+
if (ident.startsWith("__")) return {
|
|
393
|
+
success: false,
|
|
394
|
+
error: `Identifiers cannot start with double underscores.`
|
|
395
|
+
};
|
|
371
396
|
const prefix = ident.split("_")[0];
|
|
372
|
-
|
|
397
|
+
if (bannedTokens.has(prefix)) return {
|
|
398
|
+
success: false,
|
|
399
|
+
error: `Identifiers cannot start with reserved keywords.`
|
|
400
|
+
};
|
|
401
|
+
return { success: true };
|
|
373
402
|
}
|
|
374
|
-
var NameRegistryImpl = class {
|
|
375
|
-
#usedNames;
|
|
376
|
-
#scopeStack;
|
|
377
|
-
constructor() {
|
|
378
|
-
this.#usedNames = new Set([...bannedTokens, ...builtins]);
|
|
379
|
-
this.#scopeStack = [];
|
|
380
|
-
}
|
|
381
|
-
get #usedBlockScopeNames() {
|
|
382
|
-
return this.#scopeStack[this.#scopeStack.length - 1]?.usedBlockScopeNames;
|
|
383
|
-
}
|
|
384
|
-
makeUnique(primer, global) {
|
|
385
|
-
const sanitizedPrimer = sanitizePrimer(primer);
|
|
386
|
-
const name = this.getUniqueVariant(sanitizedPrimer);
|
|
387
|
-
if (global) this.#usedNames.add(name);
|
|
388
|
-
else this.#usedBlockScopeNames?.add(name);
|
|
389
|
-
return name;
|
|
390
|
-
}
|
|
391
|
-
#isUsedInBlocksBefore(name) {
|
|
392
|
-
const functionScopeIndex = this.#scopeStack.findLastIndex((scope) => scope.type === "functionScope");
|
|
393
|
-
return this.#scopeStack.slice(functionScopeIndex + 1).some((scope) => scope.usedBlockScopeNames.has(name));
|
|
394
|
-
}
|
|
395
|
-
makeValid(primer) {
|
|
396
|
-
if (isValidIdentifier(primer) && !this.#usedNames.has(primer) && !this.#isUsedInBlocksBefore(primer)) {
|
|
397
|
-
this.#usedBlockScopeNames?.add(primer);
|
|
398
|
-
return primer;
|
|
399
|
-
}
|
|
400
|
-
return this.makeUnique(primer, false);
|
|
401
|
-
}
|
|
402
|
-
isUsed(name) {
|
|
403
|
-
return this.#usedNames.has(name) || this.#isUsedInBlocksBefore(name);
|
|
404
|
-
}
|
|
405
|
-
pushFunctionScope() {
|
|
406
|
-
this.#scopeStack.push({ type: "functionScope" });
|
|
407
|
-
this.#scopeStack.push({
|
|
408
|
-
type: "blockScope",
|
|
409
|
-
usedBlockScopeNames: /* @__PURE__ */ new Set()
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
popFunctionScope() {
|
|
413
|
-
const functionScopeIndex = this.#scopeStack.findLastIndex((scope) => scope.type === "functionScope");
|
|
414
|
-
if (functionScopeIndex === -1) throw new Error("Tried to pop function scope when no scope was present.");
|
|
415
|
-
this.#scopeStack.splice(functionScopeIndex);
|
|
416
|
-
}
|
|
417
|
-
pushBlockScope() {
|
|
418
|
-
this.#scopeStack.push({
|
|
419
|
-
type: "blockScope",
|
|
420
|
-
usedBlockScopeNames: /* @__PURE__ */ new Set()
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
popBlockScope() {
|
|
424
|
-
invariant(this.#scopeStack[this.#scopeStack.length - 1]?.type === "blockScope", "Tried to pop block scope, but it is not present");
|
|
425
|
-
this.#scopeStack.pop();
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
var RandomNameRegistry = class extends NameRegistryImpl {
|
|
429
|
-
#lastUniqueId = 0;
|
|
430
|
-
getUniqueVariant(base) {
|
|
431
|
-
let name = `${base}_${this.#lastUniqueId++}`;
|
|
432
|
-
while (this.isUsed(name)) name = `${base}_${this.#lastUniqueId++}`;
|
|
433
|
-
return name;
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
var StrictNameRegistry = class extends NameRegistryImpl {
|
|
437
|
-
getUniqueVariant(base) {
|
|
438
|
-
let index = 0;
|
|
439
|
-
let name = base;
|
|
440
|
-
while (this.isUsed(name)) {
|
|
441
|
-
index++;
|
|
442
|
-
name = `${base}_${index}`;
|
|
443
|
-
}
|
|
444
|
-
return name;
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
403
|
|
|
448
404
|
//#endregion
|
|
449
|
-
export {
|
|
405
|
+
export { bannedTokens, builtins, sanitizePrimer, validateIdentifier, validateProp };
|
package/package.js
CHANGED