typegpu 0.11.4 → 0.11.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/core/buffer/bufferUsage.js +2 -2
- package/core/constant/tgpuConstant.js +1 -1
- package/core/function/fnCore.js +12 -6
- 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/sampler/sampler.js +2 -2
- package/core/simulate/tgpuSimulate.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/dataTypes.d.ts +1 -1
- package/data/struct.js +3 -2
- package/data/wgslTypes.d.ts +16 -16
- package/index.d.ts +2 -2
- package/indexNamedExports.d.ts +1 -1
- package/{nameRegistry.js → nameUtils.js} +46 -90
- package/package.js +1 -1
- package/package.json +1 -1
- package/resolutionCtx.js +63 -28
- 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/conversion.js +4 -1
- package/tgsl/wgslGenerator.d.ts +20 -2
- package/tgsl/wgslGenerator.js +84 -25
- package/types.d.ts +29 -2
- package/nameRegistry.d.ts +0 -30
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
<picture>
|
|
4
|
+
<source srcset="https://typegpu.com/typegpu-logo-dark.svg" media="(prefers-color-scheme: dark)" />
|
|
5
|
+
<img src="https://typegpu.com/typegpu-logo-light.svg" />
|
|
6
|
+
</picture>
|
|
5
7
|
|
|
6
8
|
[Website](https://docs.swmansion.com/TypeGPU) —
|
|
7
9
|
[Documentation](https://docs.swmansion.com/TypeGPU/getting-started)
|
|
@@ -36,7 +36,7 @@ var TgpuFixedBufferImpl = class {
|
|
|
36
36
|
}
|
|
37
37
|
[$resolve](ctx) {
|
|
38
38
|
const dataType = this.buffer.dataType;
|
|
39
|
-
const id = ctx.
|
|
39
|
+
const id = ctx.makeUniqueIdentifier(getName(this), "global");
|
|
40
40
|
const { group, binding } = ctx.allocateFixedEntry(this.usage === "uniform" ? { uniform: dataType } : {
|
|
41
41
|
storage: dataType,
|
|
42
42
|
access: this.usage
|
|
@@ -103,7 +103,7 @@ var TgpuLaidOutBufferImpl = class {
|
|
|
103
103
|
setName(this, membership.key);
|
|
104
104
|
}
|
|
105
105
|
[$resolve](ctx) {
|
|
106
|
-
const id = ctx.
|
|
106
|
+
const id = ctx.makeUniqueIdentifier(getName(this), "global");
|
|
107
107
|
const group = ctx.allocateLayoutEntry(this.#membership.layout);
|
|
108
108
|
const usage = usageToVarTemplateMap[this.usage];
|
|
109
109
|
ctx.addDeclaration(`@group(${group}) @binding(${this.#membership.idx}) var<${usage}> ${id}: ${ctx.resolve(this.dataType).value};`);
|
|
@@ -37,7 +37,7 @@ var TgpuConstImpl = class {
|
|
|
37
37
|
return this;
|
|
38
38
|
}
|
|
39
39
|
[$resolve](ctx) {
|
|
40
|
-
const id = ctx.
|
|
40
|
+
const id = ctx.makeUniqueIdentifier(getName(this), "global");
|
|
41
41
|
const resolvedDataType = ctx.resolve(this.dataType).value;
|
|
42
42
|
const resolvedValue = ctx.resolve(this.#value, this.dataType).value;
|
|
43
43
|
ctx.addDeclaration(`const ${id}: ${resolvedDataType} = ${resolvedValue};`);
|
package/core/function/fnCore.js
CHANGED
|
@@ -5,6 +5,7 @@ import { undecorate } from "../../data/dataTypes.js";
|
|
|
5
5
|
import { snip } from "../../data/snippet.js";
|
|
6
6
|
import { MissingLinksError } from "../../errors.js";
|
|
7
7
|
import { getAttributesString } from "../../data/attributes.js";
|
|
8
|
+
import { validateIdentifier } from "../../nameUtils.js";
|
|
8
9
|
import { applyExternals, replaceExternalsInWgsl } from "../resolve/externals.js";
|
|
9
10
|
import { extractArgs } from "./extractArgs.js";
|
|
10
11
|
|
|
@@ -29,21 +30,26 @@ function createFnCore(implementation, functionType, workgroupSize) {
|
|
|
29
30
|
else if (functionType === "vertex") attributes = `@vertex `;
|
|
30
31
|
else if (functionType === "fragment") attributes = `@fragment `;
|
|
31
32
|
for (const externals of externalsToApply) applyExternals(externalMap, externals);
|
|
32
|
-
const id = ctx.
|
|
33
|
+
const id = ctx.makeUniqueIdentifier(getName(this), "global");
|
|
33
34
|
if (typeof implementation === "string") {
|
|
34
35
|
if (!returnType) throw new Error("Explicit return type is required for string implementation");
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
if (entryInput) {
|
|
37
|
+
for (const arg of entryInput.positionalArgs) {
|
|
38
|
+
const result = /* @__PURE__ */ validateIdentifier(arg.schemaKey);
|
|
39
|
+
if (!result.success) throw new Error(`Invalid argument name "${arg.schemaKey}"${result.error ? `: ${result.error}` : ""}`);
|
|
40
|
+
}
|
|
41
|
+
applyExternals(externalMap, { in: Object.fromEntries(entryInput.positionalArgs.map((a) => [a.schemaKey, a.schemaKey])) });
|
|
42
|
+
}
|
|
37
43
|
const replacedImpl = replaceExternalsInWgsl(ctx, externalMap, implementation);
|
|
38
44
|
let header = "";
|
|
39
45
|
let body = "";
|
|
40
|
-
if (functionType !== "normal" && entryInput
|
|
46
|
+
if (functionType !== "normal" && entryInput) {
|
|
41
47
|
const { dataSchema, positionalArgs } = entryInput;
|
|
42
48
|
const parts = [];
|
|
43
49
|
if (dataSchema && isArgUsedInBody("in", replacedImpl)) parts.push(`in: ${ctx.resolve(dataSchema).value}`);
|
|
44
50
|
for (const a of positionalArgs) {
|
|
45
|
-
const argName =
|
|
46
|
-
if (
|
|
51
|
+
const argName = a.schemaKey;
|
|
52
|
+
if (isArgUsedInBody(argName, replacedImpl)) parts.push(`${getAttributesString(a.type)}${argName}: ${ctx.resolve(a.type).value}`);
|
|
47
53
|
}
|
|
48
54
|
const input = `(${parts.join(", ")})`;
|
|
49
55
|
const attributes$1 = isWgslData(returnType) ? getAttributesString(returnType) : "";
|
|
@@ -3,10 +3,10 @@ import { PERF, getName, setName } from "../../shared/meta.js";
|
|
|
3
3
|
import { Void } from "../../data/wgslTypes.js";
|
|
4
4
|
import { snip } from "../../data/snippet.js";
|
|
5
5
|
import { isGPUBuffer } from "../../types.js";
|
|
6
|
-
import { namespace } from "../resolve/namespace.js";
|
|
7
6
|
import { isBindGroup } from "../../tgpuBindGroupLayout.js";
|
|
8
7
|
import { resolve } from "../../resolutionCtx.js";
|
|
9
8
|
import { isGPUCommandEncoder, isGPUComputePassEncoder } from "./typeGuards.js";
|
|
9
|
+
import { namespace } from "../resolve/namespace.js";
|
|
10
10
|
import { applyBindGroups } from "./applyPipelineState.js";
|
|
11
11
|
import { logDataFromGPU } from "../../tgsl/consoleLog/deserializers.js";
|
|
12
12
|
import { wgslExtensionToFeatureName, wgslExtensions } from "../../wgslExtensions.js";
|
|
@@ -7,12 +7,12 @@ import { isGPUBuffer } from "../../types.js";
|
|
|
7
7
|
import { formatToWGSLType } from "../../data/vertexFormatData.js";
|
|
8
8
|
import { sizeOf } from "../../data/sizeOf.js";
|
|
9
9
|
import { isBuiltin } from "../../data/attributes.js";
|
|
10
|
-
import { namespace } from "../resolve/namespace.js";
|
|
11
10
|
import { isTexture, isTextureView } from "../texture/texture.js";
|
|
12
11
|
import { isBindGroup, isBindGroupLayout } from "../../tgpuBindGroupLayout.js";
|
|
13
12
|
import { connectAttributesToShader } from "../vertexLayout/connectAttributesToShader.js";
|
|
14
13
|
import { resolve } from "../../resolutionCtx.js";
|
|
15
14
|
import { isGPUCommandEncoder, isGPURenderBundleEncoder, isGPURenderPassEncoder } from "./typeGuards.js";
|
|
15
|
+
import { namespace } from "../resolve/namespace.js";
|
|
16
16
|
import { applyBindGroups, applyVertexBuffers } from "./applyPipelineState.js";
|
|
17
17
|
import { logDataFromGPU } from "../../tgsl/consoleLog/deserializers.js";
|
|
18
18
|
import { wgslExtensionToFeatureName, wgslExtensions } from "../../wgslExtensions.js";
|
|
@@ -2,13 +2,13 @@ import { $internal } from "../../shared/symbols.js";
|
|
|
2
2
|
import { ResolvedSnippet } from "../../data/snippet.js";
|
|
3
3
|
import { ShelllessRepository } from "../../tgsl/shellless.js";
|
|
4
4
|
import { TgpuLazy, TgpuSlot } from "../slot/slotTypes.js";
|
|
5
|
-
import { NameRegistry } from "../../nameRegistry.js";
|
|
6
5
|
|
|
7
6
|
//#region src/core/resolve/namespace.d.ts
|
|
8
7
|
type SlotToValueMap = Map<TgpuSlot<unknown>, unknown>;
|
|
9
8
|
interface NamespaceInternal {
|
|
10
|
-
readonly
|
|
9
|
+
readonly takenGlobalIdentifiers: Set<string>;
|
|
11
10
|
readonly shelllessRepo: ShelllessRepository;
|
|
11
|
+
readonly strategy: 'random' | 'strict';
|
|
12
12
|
memoizedResolves: WeakMap<object, {
|
|
13
13
|
slotToValueMap: SlotToValueMap;
|
|
14
14
|
result: ResolvedSnippet;
|
|
@@ -17,18 +17,9 @@ interface NamespaceInternal {
|
|
|
17
17
|
slotToValueMap: SlotToValueMap;
|
|
18
18
|
result: unknown;
|
|
19
19
|
}[]>;
|
|
20
|
-
listeners: { [K in keyof NamespaceEventMap]: Set<(event: NamespaceEventMap[K]) => void> };
|
|
21
20
|
}
|
|
22
|
-
type NamespaceEventMap = {
|
|
23
|
-
name: {
|
|
24
|
-
target: object;
|
|
25
|
-
name: string;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
type DetachListener = () => void;
|
|
29
21
|
interface Namespace {
|
|
30
22
|
readonly [$internal]: NamespaceInternal;
|
|
31
|
-
on<TEvent extends keyof NamespaceEventMap>(event: TEvent, listener: (event: NamespaceEventMap[TEvent]) => void): DetachListener;
|
|
32
23
|
}
|
|
33
24
|
interface NamespaceOptions {
|
|
34
25
|
names?: 'random' | 'strict' | undefined;
|
|
@@ -1,41 +1,24 @@
|
|
|
1
1
|
import { $internal } from "../../shared/symbols.js";
|
|
2
|
-
import {
|
|
3
|
-
import { RandomNameRegistry, StrictNameRegistry } from "../../nameRegistry.js";
|
|
2
|
+
import { bannedTokens, builtins } from "../../nameUtils.js";
|
|
4
3
|
import { ShelllessRepository } from "../../tgsl/shellless.js";
|
|
5
4
|
|
|
6
5
|
//#region src/core/resolve/namespace.ts
|
|
7
6
|
var NamespaceImpl = class {
|
|
8
7
|
[$internal];
|
|
9
|
-
constructor(
|
|
8
|
+
constructor(strategy) {
|
|
10
9
|
this[$internal] = {
|
|
11
|
-
|
|
10
|
+
strategy,
|
|
11
|
+
takenGlobalIdentifiers: new Set([...bannedTokens, ...builtins]),
|
|
12
12
|
shelllessRepo: new ShelllessRepository(),
|
|
13
13
|
memoizedResolves: /* @__PURE__ */ new WeakMap(),
|
|
14
|
-
memoizedLazy: /* @__PURE__ */ new WeakMap()
|
|
15
|
-
listeners: { name: /* @__PURE__ */ new Set() }
|
|
14
|
+
memoizedLazy: /* @__PURE__ */ new WeakMap()
|
|
16
15
|
};
|
|
17
16
|
}
|
|
18
|
-
on(event, listener) {
|
|
19
|
-
if (event === "name") {
|
|
20
|
-
const listeners = this[$internal].listeners.name;
|
|
21
|
-
listeners.add(listener);
|
|
22
|
-
return () => listeners.delete(listener);
|
|
23
|
-
}
|
|
24
|
-
throw new Error(`Unsupported event: ${event}`);
|
|
25
|
-
}
|
|
26
17
|
};
|
|
27
|
-
function getUniqueName(namespace$1, resource) {
|
|
28
|
-
const name = namespace$1.nameRegistry.makeUnique(getName(resource), true);
|
|
29
|
-
for (const listener of namespace$1.listeners.name) listener({
|
|
30
|
-
target: resource,
|
|
31
|
-
name
|
|
32
|
-
});
|
|
33
|
-
return name;
|
|
34
|
-
}
|
|
35
18
|
function namespace(options) {
|
|
36
19
|
const { names = "strict" } = options ?? {};
|
|
37
|
-
return new NamespaceImpl(names
|
|
20
|
+
return new NamespaceImpl(names);
|
|
38
21
|
}
|
|
39
22
|
|
|
40
23
|
//#endregion
|
|
41
|
-
export {
|
|
24
|
+
export { namespace };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { $internal } from "../../shared/symbols.js";
|
|
2
|
+
import { getName } from "../../shared/meta.js";
|
|
2
3
|
import { isLooseData } from "../../data/dataTypes.js";
|
|
3
4
|
import { assertExhaustive } from "../../shared/utilityTypes.js";
|
|
4
5
|
import { formatToWGSLType } from "../../data/vertexFormatData.js";
|
|
@@ -61,7 +62,7 @@ function resolveStructProperty(ctx, [key, property]) {
|
|
|
61
62
|
*/
|
|
62
63
|
function resolveStruct(ctx, struct) {
|
|
63
64
|
if (struct[$internal].isAbstruct) throw new Error("Cannot resolve abstract struct types to WGSL.");
|
|
64
|
-
const id = ctx.
|
|
65
|
+
const id = ctx.makeUniqueIdentifier(getName(struct), "global");
|
|
65
66
|
ctx.addDeclaration(`\
|
|
66
67
|
struct ${id} {
|
|
67
68
|
${Object.entries(struct.propTypes).map((prop) => resolveStructProperty(ctx, prop)).join("")}\
|
|
@@ -84,7 +85,7 @@ ${Object.entries(struct.propTypes).map((prop) => resolveStructProperty(ctx, prop
|
|
|
84
85
|
* ```
|
|
85
86
|
*/
|
|
86
87
|
function resolveUnstruct(ctx, unstruct) {
|
|
87
|
-
const id = ctx.
|
|
88
|
+
const id = ctx.makeUniqueIdentifier(getName(unstruct), "global");
|
|
88
89
|
ctx.addDeclaration(`\
|
|
89
90
|
struct ${id} {
|
|
90
91
|
${Object.entries(unstruct.propTypes).map((prop) => isAttribute(prop[1]) ? resolveStructProperty(ctx, [prop[0], formatToWGSLType[prop[1].format]]) : resolveStructProperty(ctx, prop)).join("")}
|
|
@@ -2,10 +2,10 @@ import { $internal, $resolve } from "../../shared/symbols.js";
|
|
|
2
2
|
import { Void } from "../../data/wgslTypes.js";
|
|
3
3
|
import { snip } from "../../data/snippet.js";
|
|
4
4
|
import { applyExternals, replaceExternalsInWgsl } from "./externals.js";
|
|
5
|
-
import { namespace } from "./namespace.js";
|
|
6
5
|
import { isBindGroupLayout } from "../../tgpuBindGroupLayout.js";
|
|
7
6
|
import { resolve } from "../../resolutionCtx.js";
|
|
8
7
|
import { isPipeline } from "../pipeline/typeGuards.js";
|
|
8
|
+
import { namespace } from "./namespace.js";
|
|
9
9
|
|
|
10
10
|
//#region src/core/resolve/tgpuResolve.ts
|
|
11
11
|
function resolveWithContext(arg0, options) {
|
package/core/sampler/sampler.js
CHANGED
|
@@ -32,7 +32,7 @@ var TgpuLaidOutSamplerImpl = class {
|
|
|
32
32
|
setName(this, membership.key);
|
|
33
33
|
}
|
|
34
34
|
[$resolve](ctx) {
|
|
35
|
-
const id = ctx.
|
|
35
|
+
const id = ctx.makeUniqueIdentifier(getName(this), "global");
|
|
36
36
|
const group = ctx.allocateLayoutEntry(this.#membership.layout);
|
|
37
37
|
ctx.addDeclaration(`@group(${group}) @binding(${this.#membership.idx}) var ${id}: ${ctx.resolve(this.schema).value};`);
|
|
38
38
|
return snip(id, this.schema, "handle");
|
|
@@ -82,7 +82,7 @@ var TgpuFixedSamplerImpl = class {
|
|
|
82
82
|
this.#filtering = props.minFilter === "linear" || props.magFilter === "linear" || props.mipmapFilter === "linear";
|
|
83
83
|
}
|
|
84
84
|
[$resolve](ctx) {
|
|
85
|
-
const id = ctx.
|
|
85
|
+
const id = ctx.makeUniqueIdentifier(getName(this), "global");
|
|
86
86
|
const { group, binding } = ctx.allocateFixedEntry(this.schema.type === "sampler_comparison" ? { sampler: "comparison" } : { sampler: this.#filtering ? "filtering" : "non-filtering" }, this);
|
|
87
87
|
ctx.addDeclaration(`@group(${group}) @binding(${binding}) var ${id}: ${ctx.resolve(this.schema).value};`);
|
|
88
88
|
return snip(id, this.schema, "handle");
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SimulationState } from "../../types.js";
|
|
2
2
|
import { getResolutionCtx, provideCtx } from "../../execMode.js";
|
|
3
|
-
import { namespace } from "../resolve/namespace.js";
|
|
4
3
|
import wgslGenerator_default from "../../tgsl/wgslGenerator.js";
|
|
5
4
|
import { ResolutionCtxImpl } from "../../resolutionCtx.js";
|
|
5
|
+
import { namespace } from "../resolve/namespace.js";
|
|
6
6
|
|
|
7
7
|
//#region src/core/simulate/tgpuSimulate.ts
|
|
8
8
|
/**
|
|
@@ -17,7 +17,7 @@ var TgpuExternalTextureImpl = class {
|
|
|
17
17
|
setName(this, membership.key);
|
|
18
18
|
}
|
|
19
19
|
[$resolve](ctx) {
|
|
20
|
-
const id = ctx.
|
|
20
|
+
const id = ctx.makeUniqueIdentifier(getName(this), "global");
|
|
21
21
|
const group = ctx.allocateLayoutEntry(this.#membership.layout);
|
|
22
22
|
ctx.addDeclaration(`@group(${group}) @binding(${this.#membership.idx}) var ${id}: ${ctx.resolve(this.schema).value};`);
|
|
23
23
|
return snip(id, textureExternal(), "handle");
|
package/core/texture/texture.js
CHANGED
|
@@ -246,7 +246,7 @@ var TgpuFixedTextureViewImpl = class {
|
|
|
246
246
|
return `textureView:${getName(this) ?? "<unnamed>"}`;
|
|
247
247
|
}
|
|
248
248
|
[$resolve](ctx) {
|
|
249
|
-
const id = ctx.
|
|
249
|
+
const id = ctx.makeUniqueIdentifier(getName(this), "global");
|
|
250
250
|
const { group, binding } = ctx.allocateFixedEntry(isWgslStorageTexture(this.schema) ? { storageTexture: this.schema } : {
|
|
251
251
|
texture: this.schema,
|
|
252
252
|
sampleType: this.#descriptor?.sampleType ?? this.schema.bindingSampleType[0]
|
|
@@ -269,7 +269,7 @@ var TgpuLaidOutTextureViewImpl = class {
|
|
|
269
269
|
return `textureView:${getName(this) ?? "<unnamed>"}`;
|
|
270
270
|
}
|
|
271
271
|
[$resolve](ctx) {
|
|
272
|
-
const id = ctx.
|
|
272
|
+
const id = ctx.makeUniqueIdentifier(getName(this), "global");
|
|
273
273
|
const group = ctx.allocateLayoutEntry(this.#membership.layout);
|
|
274
274
|
ctx.addDeclaration(`@group(${group}) @binding(${this.#membership.idx}) var ${id}: ${ctx.resolve(this.schema).value};`);
|
|
275
275
|
return snip(id, this.schema, "handle");
|
|
@@ -42,7 +42,7 @@ var TgpuVarImpl = class {
|
|
|
42
42
|
this.#initialValue = initialValue;
|
|
43
43
|
}
|
|
44
44
|
[$resolve](ctx) {
|
|
45
|
-
const id = ctx.
|
|
45
|
+
const id = ctx.makeUniqueIdentifier(getName(this), "global");
|
|
46
46
|
const pre = `var<${this.#scope}> ${id}: ${ctx.resolve(this.#dataType).value}`;
|
|
47
47
|
if (this.#initialValue) ctx.addDeclaration(`${pre} = ${ctx.resolve(this.#initialValue, this.#dataType).value};`);
|
|
48
48
|
else ctx.addDeclaration(`${pre};`);
|
package/data/autoStruct.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { $internal, $resolve } from "../shared/symbols.js";
|
|
2
2
|
import { getName, setName } from "../shared/meta.js";
|
|
3
|
-
import {
|
|
3
|
+
import { validateProp } from "../nameUtils.js";
|
|
4
4
|
import { createIoSchema } from "../core/function/ioSchema.js";
|
|
5
5
|
|
|
6
6
|
//#region src/data/autoStruct.ts
|
|
@@ -49,7 +49,8 @@ var AutoStruct = class {
|
|
|
49
49
|
if (!alloc) {
|
|
50
50
|
const wgslKey = key.replaceAll("$", "");
|
|
51
51
|
if (this.#usedWgslKeys.has(wgslKey)) throw new Error(`Property name '${wgslKey}' causes naming clashes. Choose a different name.`);
|
|
52
|
-
|
|
52
|
+
const result = /* @__PURE__ */ validateProp(wgslKey);
|
|
53
|
+
if (!result.success) throw new Error(`Invalid property key '${key}'${result.error ? `: ${result.error}` : ""}`);
|
|
53
54
|
this.#usedWgslKeys.add(wgslKey);
|
|
54
55
|
alloc = {
|
|
55
56
|
prop: wgslKey,
|
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/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
|
@@ -7,7 +7,7 @@ import { TgpuComputeFn, TgpuComputeFnShell, computeFn, isTgpuComputeFn } from ".
|
|
|
7
7
|
import { TgpuVar, VariableScope, isVariable, privateVar, workgroupVar } from "./core/variable/tgpuVariable.js";
|
|
8
8
|
import { Eventual, TgpuAccessor, TgpuLazy, TgpuMutableAccessor, TgpuSlot, isAccessor, isLazy, isMutableAccessor, isSlot } from "./core/slot/slotTypes.js";
|
|
9
9
|
import { TgpuComputePipeline } from "./core/pipeline/computePipeline.js";
|
|
10
|
-
import { AutoFragmentIn, AutoFragmentOut, AutoVertexOut, _AutoVertexIn } from "./core/function/autoIO.js";
|
|
10
|
+
import { AnyAutoCustoms, AutoFragmentIn, AutoFragmentOut, AutoVertexOut, _AutoVertexIn } from "./core/function/autoIO.js";
|
|
11
11
|
import { TgpuFragmentFn, TgpuFragmentFnShell, fragmentFn, isTgpuFragmentFn } from "./core/function/tgpuFragmentFn.js";
|
|
12
12
|
import { TgpuVertexFn, TgpuVertexFnShell, isTgpuVertexFn, vertexFn } from "./core/function/tgpuVertexFn.js";
|
|
13
13
|
import { TextureProps } from "./core/texture/textureProps.js";
|
|
@@ -70,4 +70,4 @@ declare const tgpu: {
|
|
|
70
70
|
'~unstable': typeof tgpuUnstable_d_exports;
|
|
71
71
|
};
|
|
72
72
|
//#endregion
|
|
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 };
|
|
73
|
+
export { AnyAutoCustoms, 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/indexNamedExports.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { TgpuComputeFn, TgpuComputeFnShell, isTgpuComputeFn } from "./core/funct
|
|
|
7
7
|
import { TgpuVar, VariableScope, isVariable } from "./core/variable/tgpuVariable.js";
|
|
8
8
|
import { Eventual, TgpuAccessor, TgpuLazy, TgpuMutableAccessor, TgpuSlot, isAccessor, isLazy, isMutableAccessor, isSlot } from "./core/slot/slotTypes.js";
|
|
9
9
|
import { TgpuComputePipeline } from "./core/pipeline/computePipeline.js";
|
|
10
|
-
import { AutoFragmentIn, AutoFragmentOut, AutoVertexOut, _AutoVertexIn } from "./core/function/autoIO.js";
|
|
10
|
+
import { AnyAutoCustoms, AutoFragmentIn, AutoFragmentOut, AutoVertexOut, _AutoVertexIn } from "./core/function/autoIO.js";
|
|
11
11
|
import { TgpuFragmentFn, TgpuFragmentFnShell, isTgpuFragmentFn } from "./core/function/tgpuFragmentFn.js";
|
|
12
12
|
import { TgpuVertexFn, TgpuVertexFnShell, isTgpuVertexFn } from "./core/function/tgpuVertexFn.js";
|
|
13
13
|
import { TextureProps } from "./core/texture/textureProps.js";
|