typegpu 0.10.1 → 0.10.2
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/{chunk-BYypO7fO.js → _virtual/_rolldown/runtime.js} +1 -1
- package/builtin.d.ts +50 -0
- package/builtin.js +37 -0
- package/common/fullScreenTriangle.d.ts +26 -0
- package/common/fullScreenTriangle.js +36 -0
- package/common/index.d.ts +2 -3
- package/common/index.js +3 -4
- package/core/buffer/buffer.d.ts +74 -0
- package/core/buffer/buffer.js +197 -0
- package/core/buffer/bufferShorthand.d.ts +48 -0
- package/core/buffer/bufferShorthand.js +49 -0
- package/core/buffer/bufferUsage.d.ts +45 -0
- package/core/buffer/bufferUsage.js +163 -0
- package/core/constant/tgpuConstant.d.ts +28 -0
- package/core/constant/tgpuConstant.js +67 -0
- package/core/declare/tgpuDeclare.d.ts +18 -0
- package/core/declare/tgpuDeclare.js +40 -0
- package/core/function/autoIO.d.ts +37 -0
- package/core/function/autoIO.js +87 -0
- package/core/function/comptime.d.ts +39 -0
- package/core/function/comptime.js +51 -0
- package/core/function/createCallableSchema.js +42 -0
- package/core/function/dualImpl.js +54 -0
- package/core/function/extractArgs.js +204 -0
- package/core/function/fnCore.js +79 -0
- package/core/function/fnTypes.d.ts +34 -0
- package/core/function/ioSchema.d.ts +10 -0
- package/core/function/ioSchema.js +30 -0
- package/core/function/shelllessImpl.d.ts +28 -0
- package/core/function/shelllessImpl.js +23 -0
- package/core/function/templateUtils.js +13 -0
- package/core/function/tgpuComputeFn.d.ts +49 -0
- package/core/function/tgpuComputeFn.js +62 -0
- package/core/function/tgpuFn.d.ts +52 -0
- package/core/function/tgpuFn.js +170 -0
- package/core/function/tgpuFragmentFn.d.ts +68 -0
- package/core/function/tgpuFragmentFn.js +68 -0
- package/core/function/tgpuVertexFn.d.ts +55 -0
- package/core/function/tgpuVertexFn.js +65 -0
- package/core/pipeline/applyPipelineState.js +37 -0
- package/core/pipeline/computePipeline.d.ts +58 -0
- package/core/pipeline/computePipeline.js +226 -0
- package/core/pipeline/connectAttachmentToShader.js +26 -0
- package/core/pipeline/connectTargetsToShader.js +29 -0
- package/core/pipeline/limitsOverflow.js +13 -0
- package/core/pipeline/renderPipeline.d.ts +266 -0
- package/core/pipeline/renderPipeline.js +471 -0
- package/core/pipeline/timeable.d.ts +23 -0
- package/core/pipeline/timeable.js +61 -0
- package/core/pipeline/typeGuards.js +29 -0
- package/core/querySet/querySet.d.ts +22 -0
- package/core/querySet/querySet.js +103 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +59 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +96 -0
- package/core/resolve/externals.d.ts +10 -0
- package/core/resolve/externals.js +58 -0
- package/core/resolve/namespace.d.ts +38 -0
- package/core/resolve/namespace.js +41 -0
- package/core/resolve/resolveData.js +146 -0
- package/core/resolve/stitch.js +25 -0
- package/core/resolve/tgpuResolve.d.ts +151 -0
- package/core/resolve/tgpuResolve.js +68 -0
- package/core/root/configurableImpl.js +18 -0
- package/core/root/init.d.ts +69 -0
- package/core/root/init.js +457 -0
- package/core/root/rootTypes.d.ts +622 -0
- package/core/sampler/sampler.d.ts +35 -0
- package/core/sampler/sampler.js +116 -0
- package/core/simulate/tgpuSimulate.d.ts +36 -0
- package/core/simulate/tgpuSimulate.js +76 -0
- package/core/slot/accessor.d.ts +13 -0
- package/core/slot/accessor.js +97 -0
- package/core/slot/internalSlots.js +7 -0
- package/core/slot/lazy.d.ts +6 -0
- package/core/slot/lazy.js +42 -0
- package/core/slot/slot.d.ts +6 -0
- package/core/slot/slot.js +40 -0
- package/core/slot/slotTypes.d.ts +92 -0
- package/core/slot/slotTypes.js +21 -0
- package/core/texture/externalTexture.d.ts +12 -0
- package/core/texture/externalTexture.js +48 -0
- package/core/texture/texture.d.ts +118 -0
- package/core/texture/texture.js +312 -0
- package/core/texture/textureFormats.d.ts +29 -0
- package/core/texture/textureFormats.js +99 -0
- package/core/texture/textureProps.d.ts +11 -0
- package/core/texture/textureUtils.js +224 -0
- package/core/texture/usageExtension.d.ts +21 -0
- package/core/texture/usageExtension.js +21 -0
- package/core/unroll/tgpuUnroll.d.ts +13 -0
- package/core/unroll/tgpuUnroll.js +36 -0
- package/core/valueProxyUtils.js +44 -0
- package/core/variable/tgpuVariable.d.ts +38 -0
- package/core/variable/tgpuVariable.js +101 -0
- package/core/vertexLayout/connectAttributesToShader.js +59 -0
- package/core/vertexLayout/vertexAttribute.d.ts +29 -0
- package/core/vertexLayout/vertexLayout.d.ts +19 -0
- package/core/vertexLayout/vertexLayout.js +103 -0
- package/data/alignIO.js +15 -0
- package/data/alignmentOf.d.ts +10 -0
- package/data/alignmentOf.js +88 -0
- package/data/array.d.ts +28 -0
- package/data/array.js +48 -0
- package/data/atomic.d.ts +15 -0
- package/data/atomic.js +25 -0
- package/data/attributes.d.ts +121 -0
- package/data/attributes.js +145 -0
- package/data/autoStruct.d.ts +3 -0
- package/data/autoStruct.js +83 -0
- package/data/compiledIO.js +231 -0
- package/data/dataIO.js +549 -0
- package/data/dataTypes.d.ts +115 -0
- package/data/dataTypes.js +97 -0
- package/data/deepEqual.d.ts +25 -0
- package/data/deepEqual.js +58 -0
- package/data/disarray.d.ts +34 -0
- package/data/disarray.js +52 -0
- package/data/getLongestContiguousPrefix.d.ts +10 -0
- package/data/getLongestContiguousPrefix.js +15 -0
- package/data/index.d.ts +26 -4
- package/data/index.js +27 -7
- package/data/instanceToSchema.d.ts +33 -0
- package/data/isContiguous.d.ts +10 -0
- package/data/isContiguous.js +15 -0
- package/data/matrix.d.ts +126 -0
- package/data/matrix.js +517 -0
- package/data/numberOps.js +24 -0
- package/data/numeric.d.ts +81 -0
- package/data/numeric.js +234 -0
- package/data/offsetUtils.d.ts +33 -0
- package/data/offsetUtils.js +167 -0
- package/data/offsets.js +36 -0
- package/data/partialIO.js +68 -0
- package/data/ptr.d.ts +12 -0
- package/data/ptr.js +46 -0
- package/data/ref.d.ts +37 -0
- package/data/ref.js +96 -0
- package/data/sampler.d.ts +107 -0
- package/data/sampler.js +26 -0
- package/data/schemaCallWrapper.js +32 -0
- package/data/schemaMemoryLayout.js +200 -0
- package/data/sizeOf.d.ts +10 -0
- package/data/sizeOf.js +15 -0
- package/data/snippet.d.ts +26 -0
- package/data/snippet.js +61 -0
- package/data/struct.d.ts +17 -0
- package/data/struct.js +46 -0
- package/data/texture.d.ts +292 -0
- package/{texture-BagDrrks.js → data/texture.js} +6 -3
- package/data/unstruct.d.ts +24 -0
- package/data/unstruct.js +43 -0
- package/data/vector.d.ts +191 -0
- package/data/vector.js +247 -0
- package/data/vectorImpl.js +516 -0
- package/data/vectorOps.js +664 -0
- package/data/vertexFormatData.d.ts +190 -0
- package/data/vertexFormatData.js +110 -0
- package/data/wgslTypes.d.ts +896 -0
- package/data/wgslTypes.js +215 -0
- package/errors.d.ts +44 -0
- package/errors.js +128 -0
- package/execMode.js +51 -0
- package/extension.d.ts +11 -0
- package/extension.js +18 -0
- package/getGPUValue.js +9 -0
- package/index.d.ts +40 -243
- package/index.js +19 -6318
- package/indexNamedExports.d.ts +38 -0
- package/mathUtils.js +13 -0
- package/memo.js +22 -0
- package/nameRegistry.d.ts +30 -0
- package/nameRegistry.js +449 -0
- package/package.js +5 -0
- package/package.json +23 -23
- package/resolutionCtx.d.ts +29 -0
- package/resolutionCtx.js +546 -0
- package/shared/env.js +13 -0
- package/shared/generators.js +14 -0
- package/shared/meta.d.ts +39 -0
- package/shared/meta.js +63 -0
- package/shared/repr.d.ts +108 -0
- package/shared/stringify.js +22 -0
- package/shared/symbols.d.ts +61 -0
- package/shared/symbols.js +71 -0
- package/shared/utilityTypes.d.ts +29 -0
- package/shared/utilityTypes.js +7 -0
- package/shared/vertexFormat.d.ts +70 -0
- package/shared/vertexFormat.js +64 -0
- package/std/array.d.ts +7 -0
- package/std/array.js +27 -0
- package/std/atomic.d.ts +19 -0
- package/std/atomic.js +113 -0
- package/std/bitcast.d.ts +10 -0
- package/std/bitcast.js +43 -0
- package/std/boolean.d.ts +127 -0
- package/std/boolean.js +274 -0
- package/std/derivative.d.ts +16 -0
- package/std/derivative.js +89 -0
- package/std/discard.d.ts +6 -0
- package/std/discard.js +16 -0
- package/std/extensions.d.ts +8 -0
- package/std/extensions.js +14 -0
- package/std/index.d.ts +15 -3
- package/std/index.js +16 -5
- package/std/matrix.d.ts +41 -0
- package/std/matrix.js +87 -0
- package/std/numeric.d.ts +254 -0
- package/std/numeric.js +847 -0
- package/std/operators.d.ts +48 -0
- package/std/operators.js +153 -0
- package/std/packing.d.ts +26 -0
- package/std/packing.js +86 -0
- package/std/subgroup.d.ts +47 -0
- package/std/subgroup.js +220 -0
- package/std/texture.d.ts +108 -0
- package/std/texture.js +197 -0
- package/tgpu.js +44 -0
- package/tgpuBindGroupLayout.d.ts +161 -0
- package/tgpuBindGroupLayout.js +271 -0
- package/tgpuUnstable.d.ts +48 -0
- package/tgpuUnstable.js +66 -0
- package/tgsl/accessIndex.js +45 -0
- package/tgsl/accessProp.js +113 -0
- package/tgsl/consoleLog/deserializers.js +117 -0
- package/tgsl/consoleLog/logGenerator.js +86 -0
- package/tgsl/consoleLog/serializers.js +225 -0
- package/tgsl/consoleLog/types.d.ts +54 -0
- package/tgsl/consoleLog/types.js +12 -0
- package/tgsl/conversion.js +200 -0
- package/tgsl/forOfUtils.js +45 -0
- package/tgsl/generationHelpers.d.ts +37 -0
- package/tgsl/generationHelpers.js +67 -0
- package/tgsl/math.js +45 -0
- package/tgsl/shaderGenerator.d.ts +18 -0
- package/tgsl/shellless.d.ts +11 -0
- package/tgsl/shellless.js +53 -0
- package/tgsl/wgslGenerator.js +585 -0
- package/types.d.ts +255 -0
- package/types.js +43 -0
- package/unwrapper.d.ts +27 -0
- package/wgslExtensions.d.ts +5 -0
- package/wgslExtensions.js +18 -0
- package/builtin-DdtWpk2t.js +0 -818
- package/builtin-DdtWpk2t.js.map +0 -1
- package/common/index.d.ts.map +0 -1
- package/common/index.js.map +0 -1
- package/data/index.d.ts.map +0 -1
- package/data/index.js.map +0 -1
- package/deepEqual-DQxK4vdp.js +0 -413
- package/deepEqual-DQxK4vdp.js.map +0 -1
- package/extensions-DIVuAfBM.js +0 -2032
- package/extensions-DIVuAfBM.js.map +0 -1
- package/fullScreenTriangle-CfFyQd_0.js +0 -543
- package/fullScreenTriangle-CfFyQd_0.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/indexNamedExports-oL6tyaJ9.d.ts +0 -5697
- package/indexNamedExports-oL6tyaJ9.d.ts.map +0 -1
- package/operators-d-PMVTo7.js +0 -4158
- package/operators-d-PMVTo7.js.map +0 -1
- package/std/index.d.ts.map +0 -1
- package/std/index.js.map +0 -1
- package/texture-BagDrrks.js.map +0 -1
package/data/ref.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { $gpuCallable, $internal, $ownSnippet, $resolve } from "../shared/symbols.js";
|
|
2
|
+
import { setName } from "../shared/meta.js";
|
|
3
|
+
import { isNaturallyEphemeral, isPtr } from "./wgslTypes.js";
|
|
4
|
+
import { UnknownData } from "./dataTypes.js";
|
|
5
|
+
import { snip } from "./snippet.js";
|
|
6
|
+
import { WgslTypeError } from "../errors.js";
|
|
7
|
+
import { stitch } from "../core/resolve/stitch.js";
|
|
8
|
+
import { createPtrFromOrigin, explicitFrom } from "./ptr.js";
|
|
9
|
+
|
|
10
|
+
//#region src/data/ref.ts
|
|
11
|
+
const _ref = (() => {
|
|
12
|
+
const impl = ((value) => INTERNAL_createRef(value));
|
|
13
|
+
setName(impl, "ref");
|
|
14
|
+
impl.toString = () => "ref";
|
|
15
|
+
impl[$internal] = true;
|
|
16
|
+
impl[$gpuCallable] = { call(_ctx, [value]) {
|
|
17
|
+
if (value.origin === "argument") throw new WgslTypeError(stitch`d.ref(${value}) is illegal, cannot take a reference of an argument. Copy the value locally first, and take a reference of the copy.`);
|
|
18
|
+
if (isPtr(value.dataType)) return snip(value.value, explicitFrom(value.dataType), value.origin);
|
|
19
|
+
/**
|
|
20
|
+
* Pointer type only exists if the ref was created from a reference (buttery-butter).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const life = ref(42); // created from a value
|
|
25
|
+
* const boid = ref(layout.$.boids[0]); // created from a reference
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
const ptrType = createPtrFromOrigin(value.origin, value.dataType);
|
|
29
|
+
return snip(new RefOperator(value, ptrType), ptrType ?? UnknownData, "runtime");
|
|
30
|
+
} };
|
|
31
|
+
return impl;
|
|
32
|
+
})();
|
|
33
|
+
function isRef(value) {
|
|
34
|
+
return value?.[$internal]?.type === "ref";
|
|
35
|
+
}
|
|
36
|
+
function INTERNAL_createRef(value) {
|
|
37
|
+
const target = {
|
|
38
|
+
[$internal]: { type: "ref" },
|
|
39
|
+
get $() {
|
|
40
|
+
return value;
|
|
41
|
+
},
|
|
42
|
+
set $(newValue) {
|
|
43
|
+
if (newValue && typeof newValue === "object") for (const key of Object.keys(newValue)) value[key] = newValue[key];
|
|
44
|
+
else value = newValue;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
if (value === void 0 || value === null) throw new Error("Cannot create a ref from undefined or null");
|
|
48
|
+
if (typeof value === "object") return new Proxy(target, {
|
|
49
|
+
get(target, prop) {
|
|
50
|
+
if (prop in target) return target[prop];
|
|
51
|
+
return value[prop];
|
|
52
|
+
},
|
|
53
|
+
set(_target, prop, propValue) {
|
|
54
|
+
if (prop === $internal) return false;
|
|
55
|
+
if (prop === "$") {
|
|
56
|
+
console.log("Setting ref value:", propValue);
|
|
57
|
+
return Reflect.set(target, prop, propValue);
|
|
58
|
+
}
|
|
59
|
+
return Reflect.set(value, prop, propValue);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return target;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The result of calling `d.ref(...)`. The code responsible for
|
|
66
|
+
* generating shader code can check if the value of a snippet is
|
|
67
|
+
* an instance of `RefOperator`, and act accordingly.
|
|
68
|
+
*/
|
|
69
|
+
var RefOperator = class {
|
|
70
|
+
[$internal];
|
|
71
|
+
snippet;
|
|
72
|
+
#ptrType;
|
|
73
|
+
constructor(snippet, ptrType) {
|
|
74
|
+
this[$internal] = true;
|
|
75
|
+
this.snippet = snippet;
|
|
76
|
+
this.#ptrType = ptrType;
|
|
77
|
+
}
|
|
78
|
+
get [$ownSnippet]() {
|
|
79
|
+
if (!this.#ptrType) throw new Error(stitch`Cannot take a reference of ${this.snippet}`);
|
|
80
|
+
return snip(this, this.#ptrType, this.snippet.origin);
|
|
81
|
+
}
|
|
82
|
+
[$resolve]() {
|
|
83
|
+
if (!this.#ptrType) throw new Error(stitch`Cannot take a reference of ${this.snippet}`);
|
|
84
|
+
return snip(stitch`(&${this.snippet})`, this.#ptrType, this.snippet.origin);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
function derefSnippet(snippet) {
|
|
88
|
+
if (!isPtr(snippet.dataType)) return snippet;
|
|
89
|
+
const innerType = snippet.dataType.inner;
|
|
90
|
+
const origin = isNaturallyEphemeral(innerType) ? "runtime" : snippet.origin;
|
|
91
|
+
if (snippet.value instanceof RefOperator) return snip(stitch`${snippet.value.snippet}`, innerType, origin);
|
|
92
|
+
return snip(stitch`(*${snippet})`, innerType, origin);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { RefOperator, _ref, derefSnippet, isRef };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { $internal, $repr } from "../shared/symbols.js";
|
|
2
|
+
import { BaseData } from "./wgslTypes.js";
|
|
3
|
+
|
|
4
|
+
//#region src/data/sampler.d.ts
|
|
5
|
+
interface WgslSamplerProps {
|
|
6
|
+
addressModeU?: GPUAddressMode;
|
|
7
|
+
addressModeV?: GPUAddressMode;
|
|
8
|
+
/**
|
|
9
|
+
* Specifies the address modes for the texture width, height, and depth
|
|
10
|
+
* coordinates, respectively.
|
|
11
|
+
*/
|
|
12
|
+
addressModeW?: GPUAddressMode;
|
|
13
|
+
/**
|
|
14
|
+
* Specifies the sampling behavior when the sample footprint is smaller than or equal to one
|
|
15
|
+
* texel.
|
|
16
|
+
*/
|
|
17
|
+
magFilter?: GPUFilterMode;
|
|
18
|
+
/**
|
|
19
|
+
* Specifies the sampling behavior when the sample footprint is larger than one texel.
|
|
20
|
+
*/
|
|
21
|
+
minFilter?: GPUFilterMode;
|
|
22
|
+
/**
|
|
23
|
+
* Specifies behavior for sampling between mipmap levels.
|
|
24
|
+
*/
|
|
25
|
+
mipmapFilter?: GPUMipmapFilterMode;
|
|
26
|
+
lodMinClamp?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Specifies the minimum and maximum levels of detail, respectively, used internally when
|
|
29
|
+
* sampling a texture.
|
|
30
|
+
*/
|
|
31
|
+
lodMaxClamp?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Specifies the maximum anisotropy value clamp used by the sampler. Anisotropic filtering is
|
|
34
|
+
* enabled when {@link GPUSamplerDescriptor.maxAnisotropy} is > 1 and the implementation supports it.
|
|
35
|
+
* Anisotropic filtering improves the image quality of textures sampled at oblique viewing
|
|
36
|
+
* angles. Higher {@link GPUSamplerDescriptor.maxAnisotropy} values indicate the maximum ratio of
|
|
37
|
+
* anisotropy supported when filtering.
|
|
38
|
+
*
|
|
39
|
+
* Most implementations support {@link GPUSamplerDescriptor.maxAnisotropy} values in range
|
|
40
|
+
* between 1 and 16, inclusive. The used value of {@link GPUSamplerDescriptor.maxAnisotropy}
|
|
41
|
+
* will be clamped to the maximum value that the platform supports.
|
|
42
|
+
* The precise filtering behavior is implementation-dependent.
|
|
43
|
+
*/
|
|
44
|
+
maxAnisotropy?: number;
|
|
45
|
+
}
|
|
46
|
+
interface WgslComparisonSamplerProps {
|
|
47
|
+
compare: GPUCompareFunction;
|
|
48
|
+
addressModeU?: GPUAddressMode;
|
|
49
|
+
addressModeV?: GPUAddressMode;
|
|
50
|
+
/**
|
|
51
|
+
* Specifies the address modes for the texture width, height, and depth
|
|
52
|
+
* coordinates, respectively.
|
|
53
|
+
*/
|
|
54
|
+
addressModeW?: GPUAddressMode;
|
|
55
|
+
/**
|
|
56
|
+
* Specifies the sampling behavior when the sample footprint is smaller than or equal to one
|
|
57
|
+
* texel.
|
|
58
|
+
*/
|
|
59
|
+
magFilter?: GPUFilterMode;
|
|
60
|
+
/**
|
|
61
|
+
* Specifies the sampling behavior when the sample footprint is larger than one texel.
|
|
62
|
+
*/
|
|
63
|
+
minFilter?: GPUFilterMode;
|
|
64
|
+
/**
|
|
65
|
+
* Specifies behavior for sampling between mipmap levels.
|
|
66
|
+
*/
|
|
67
|
+
mipmapFilter?: GPUMipmapFilterMode;
|
|
68
|
+
lodMinClamp?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Specifies the minimum and maximum levels of detail, respectively, used internally when
|
|
71
|
+
* sampling a texture.
|
|
72
|
+
*/
|
|
73
|
+
lodMaxClamp?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Specifies the maximum anisotropy value clamp used by the sampler. Anisotropic filtering is
|
|
76
|
+
* enabled when {@link GPUSamplerDescriptor.maxAnisotropy} is > 1 and the implementation supports it.
|
|
77
|
+
* Anisotropic filtering improves the image quality of textures sampled at oblique viewing
|
|
78
|
+
* angles. Higher {@link GPUSamplerDescriptor.maxAnisotropy} values indicate the maximum ratio of
|
|
79
|
+
* anisotropy supported when filtering.
|
|
80
|
+
*
|
|
81
|
+
* Most implementations support {@link GPUSamplerDescriptor.maxAnisotropy} values in range
|
|
82
|
+
* between 1 and 16, inclusive. The used value of {@link GPUSamplerDescriptor.maxAnisotropy}
|
|
83
|
+
* will be clamped to the maximum value that the platform supports.
|
|
84
|
+
* The precise filtering behavior is implementation-dependent.
|
|
85
|
+
*/
|
|
86
|
+
maxAnisotropy?: number;
|
|
87
|
+
}
|
|
88
|
+
interface sampler {
|
|
89
|
+
[$internal]: true;
|
|
90
|
+
type: 'sampler';
|
|
91
|
+
}
|
|
92
|
+
declare function sampler(): WgslSampler;
|
|
93
|
+
interface comparisonSampler {
|
|
94
|
+
[$internal]: Record<string, never>;
|
|
95
|
+
type: 'sampler_comparison';
|
|
96
|
+
}
|
|
97
|
+
declare function comparisonSampler(): WgslComparisonSampler;
|
|
98
|
+
interface WgslSampler extends BaseData {
|
|
99
|
+
readonly [$repr]: sampler;
|
|
100
|
+
readonly type: 'sampler';
|
|
101
|
+
}
|
|
102
|
+
interface WgslComparisonSampler extends BaseData {
|
|
103
|
+
readonly [$repr]: comparisonSampler;
|
|
104
|
+
readonly type: 'sampler_comparison';
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { WgslComparisonSampler, WgslComparisonSamplerProps, WgslSampler, WgslSamplerProps, comparisonSampler, sampler };
|
package/data/sampler.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { $internal, $repr } from "../shared/symbols.js";
|
|
2
|
+
|
|
3
|
+
//#region src/data/sampler.ts
|
|
4
|
+
function sampler() {
|
|
5
|
+
return {
|
|
6
|
+
[$internal]: {},
|
|
7
|
+
type: "sampler",
|
|
8
|
+
[$repr]: void 0
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function comparisonSampler() {
|
|
12
|
+
return {
|
|
13
|
+
[$internal]: {},
|
|
14
|
+
type: "sampler_comparison",
|
|
15
|
+
[$repr]: void 0
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function isWgslSampler(value) {
|
|
19
|
+
return !!value[$internal] && value.type === "sampler";
|
|
20
|
+
}
|
|
21
|
+
function isWgslComparisonSampler(value) {
|
|
22
|
+
return !!value[$internal] && value.type === "sampler_comparison";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { comparisonSampler, isWgslComparisonSampler, isWgslSampler, sampler };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { $cast, $gpuCallable } from "../shared/symbols.js";
|
|
2
|
+
import { hasCast, isGPUCallable } from "../types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/data/schemaCallWrapper.ts
|
|
5
|
+
/**
|
|
6
|
+
* A wrapper for `schema(item)` or `schema()` call on JS side.
|
|
7
|
+
* If the schema is a pointer, returns the value pointed to without copying.
|
|
8
|
+
* If the schema is a TgpuVertexFormatData, calls the corresponding constructible schema instead.
|
|
9
|
+
* If the schema is not callable, throws an error.
|
|
10
|
+
* Otherwise, returns `schema(item)` or `schema()`.
|
|
11
|
+
*/
|
|
12
|
+
function schemaCallWrapper(schema, item) {
|
|
13
|
+
const callSchema = schema;
|
|
14
|
+
if (hasCast(callSchema)) return callSchema[$cast](item);
|
|
15
|
+
if (typeof callSchema !== "function") return item;
|
|
16
|
+
return item === void 0 ? callSchema() : callSchema(item);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A wrapper for `schema(item)` or `schema()` call on the GPU side.
|
|
20
|
+
* If the schema is a pointer, returns the value pointed to without copying.
|
|
21
|
+
* If the schema is a TgpuVertexFormatData, calls the corresponding constructible schema instead.
|
|
22
|
+
* If the schema is not callable, throws an error.
|
|
23
|
+
* Otherwise, returns `schema(item)` or `schema()`.
|
|
24
|
+
*/
|
|
25
|
+
function schemaCallWrapperGPU(ctx, schema, item) {
|
|
26
|
+
if (!isGPUCallable(schema)) return item;
|
|
27
|
+
const callSchema = schema;
|
|
28
|
+
return item === void 0 || item.value === void 0 ? callSchema[$gpuCallable].call(ctx, []) : callSchema[$gpuCallable].call(ctx, [item]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { schemaCallWrapper, schemaCallWrapperGPU };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { isDecorated, isWgslArray, isWgslStruct } from "./wgslTypes.js";
|
|
2
|
+
import { getCustomSize, isDisarray, isLooseDecorated, isUnstruct, undecorate } from "./dataTypes.js";
|
|
3
|
+
import { alignmentOf, customAlignmentOf } from "./alignmentOf.js";
|
|
4
|
+
import { roundUp } from "../mathUtils.js";
|
|
5
|
+
|
|
6
|
+
//#region src/data/schemaMemoryLayout.ts
|
|
7
|
+
const knownSizesMap = {
|
|
8
|
+
bool: 4,
|
|
9
|
+
f32: 4,
|
|
10
|
+
f16: 2,
|
|
11
|
+
i32: 4,
|
|
12
|
+
u32: 4,
|
|
13
|
+
u16: 2,
|
|
14
|
+
vec2f: 8,
|
|
15
|
+
vec2h: 4,
|
|
16
|
+
vec2i: 8,
|
|
17
|
+
vec2u: 8,
|
|
18
|
+
"vec2<bool>": 8,
|
|
19
|
+
vec3f: 12,
|
|
20
|
+
vec3h: 6,
|
|
21
|
+
vec3i: 12,
|
|
22
|
+
vec3u: 12,
|
|
23
|
+
"vec3<bool>": 12,
|
|
24
|
+
vec4f: 16,
|
|
25
|
+
vec4h: 8,
|
|
26
|
+
vec4i: 16,
|
|
27
|
+
vec4u: 16,
|
|
28
|
+
"vec4<bool>": 16,
|
|
29
|
+
mat2x2f: 16,
|
|
30
|
+
mat3x3f: 48,
|
|
31
|
+
mat4x4f: 64,
|
|
32
|
+
uint8: 1,
|
|
33
|
+
uint8x2: 2,
|
|
34
|
+
uint8x4: 4,
|
|
35
|
+
sint8: 1,
|
|
36
|
+
sint8x2: 2,
|
|
37
|
+
sint8x4: 4,
|
|
38
|
+
unorm8: 1,
|
|
39
|
+
unorm8x2: 2,
|
|
40
|
+
unorm8x4: 4,
|
|
41
|
+
snorm8: 1,
|
|
42
|
+
snorm8x2: 2,
|
|
43
|
+
snorm8x4: 4,
|
|
44
|
+
uint16: 2,
|
|
45
|
+
uint16x2: 4,
|
|
46
|
+
uint16x4: 8,
|
|
47
|
+
sint16: 2,
|
|
48
|
+
sint16x2: 4,
|
|
49
|
+
sint16x4: 8,
|
|
50
|
+
unorm16: 2,
|
|
51
|
+
unorm16x2: 4,
|
|
52
|
+
unorm16x4: 8,
|
|
53
|
+
snorm16: 2,
|
|
54
|
+
snorm16x2: 4,
|
|
55
|
+
snorm16x4: 8,
|
|
56
|
+
float16: 2,
|
|
57
|
+
float16x2: 4,
|
|
58
|
+
float16x4: 8,
|
|
59
|
+
float32: 4,
|
|
60
|
+
float32x2: 8,
|
|
61
|
+
float32x3: 12,
|
|
62
|
+
float32x4: 16,
|
|
63
|
+
uint32: 4,
|
|
64
|
+
uint32x2: 8,
|
|
65
|
+
uint32x3: 12,
|
|
66
|
+
uint32x4: 16,
|
|
67
|
+
sint32: 4,
|
|
68
|
+
sint32x2: 8,
|
|
69
|
+
sint32x3: 12,
|
|
70
|
+
sint32x4: 16,
|
|
71
|
+
"unorm10-10-10-2": 4,
|
|
72
|
+
"unorm8x4-bgra": 4,
|
|
73
|
+
atomic: 4
|
|
74
|
+
};
|
|
75
|
+
function computeMLOfStruct(struct) {
|
|
76
|
+
let size = 0;
|
|
77
|
+
let longestContiguousPrefix = 0;
|
|
78
|
+
let isContiguous = true;
|
|
79
|
+
let prefixEnd = false;
|
|
80
|
+
for (const property of Object.values(struct.propTypes)) {
|
|
81
|
+
if (Number.isNaN(size)) throw new Error("Only the last property of a struct can be unbounded");
|
|
82
|
+
const prevSize = size;
|
|
83
|
+
size = roundUp(size, alignmentOf(property));
|
|
84
|
+
const hasPadding = prevSize !== size;
|
|
85
|
+
const propLayout = computeMemoryLayout(property);
|
|
86
|
+
size += propLayout.size;
|
|
87
|
+
if (Number.isNaN(size) && property.type !== "array") throw new Error("Cannot nest unbounded struct within another struct");
|
|
88
|
+
if (prefixEnd) continue;
|
|
89
|
+
if (!hasPadding && propLayout.isContiguous) longestContiguousPrefix += propLayout.size;
|
|
90
|
+
else {
|
|
91
|
+
prefixEnd = true;
|
|
92
|
+
isContiguous = false;
|
|
93
|
+
if (!hasPadding) longestContiguousPrefix += propLayout.longestContiguousPrefix;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const trueSize = roundUp(size, alignmentOf(struct));
|
|
97
|
+
return {
|
|
98
|
+
isContiguous: size === trueSize && isContiguous,
|
|
99
|
+
size: trueSize,
|
|
100
|
+
longestContiguousPrefix
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function computeMLOfUnstruct(data) {
|
|
104
|
+
let size = 0;
|
|
105
|
+
let longestContiguousPrefix = 0;
|
|
106
|
+
let isContiguous = true;
|
|
107
|
+
let prefixEnd = false;
|
|
108
|
+
for (const property of Object.values(data.propTypes)) {
|
|
109
|
+
const alignment = customAlignmentOf(property);
|
|
110
|
+
const prevSize = size;
|
|
111
|
+
size = roundUp(size, alignment);
|
|
112
|
+
const hasPadding = prevSize !== size;
|
|
113
|
+
if (hasPadding) isContiguous = false;
|
|
114
|
+
const propLayout = computeMemoryLayout(property);
|
|
115
|
+
size += propLayout.size;
|
|
116
|
+
if (prefixEnd) continue;
|
|
117
|
+
if (!hasPadding && propLayout.isContiguous) longestContiguousPrefix += propLayout.size;
|
|
118
|
+
else {
|
|
119
|
+
prefixEnd = true;
|
|
120
|
+
isContiguous = false;
|
|
121
|
+
if (!hasPadding) longestContiguousPrefix += propLayout.longestContiguousPrefix;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
isContiguous,
|
|
126
|
+
size,
|
|
127
|
+
longestContiguousPrefix
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function computeMLOfWgslArray(data) {
|
|
131
|
+
const elementType = data.elementType;
|
|
132
|
+
const elementMemoryLayout = computeMemoryLayout(elementType);
|
|
133
|
+
const elementSize = elementMemoryLayout.size;
|
|
134
|
+
const stride = roundUp(elementSize, alignmentOf(elementType));
|
|
135
|
+
const isContiguous = !(stride > elementSize) && elementMemoryLayout.isContiguous;
|
|
136
|
+
const size = data.elementCount === 0 ? NaN : data.elementCount * stride;
|
|
137
|
+
let longestContiguousPrefix;
|
|
138
|
+
if (isContiguous) longestContiguousPrefix = size;
|
|
139
|
+
else longestContiguousPrefix = elementMemoryLayout.longestContiguousPrefix;
|
|
140
|
+
return {
|
|
141
|
+
size,
|
|
142
|
+
isContiguous,
|
|
143
|
+
longestContiguousPrefix
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function computeMLOfDisarray(data) {
|
|
147
|
+
const elementType = data.elementType;
|
|
148
|
+
const elementMemoryLayout = computeMemoryLayout(elementType);
|
|
149
|
+
const elementSize = elementMemoryLayout.size;
|
|
150
|
+
const stride = roundUp(elementSize, customAlignmentOf(elementType));
|
|
151
|
+
const isContiguous = !(stride > elementSize) && elementMemoryLayout.isContiguous;
|
|
152
|
+
const size = data.elementCount * stride;
|
|
153
|
+
let longestContiguousPrefix;
|
|
154
|
+
if (isContiguous) longestContiguousPrefix = size;
|
|
155
|
+
else longestContiguousPrefix = elementMemoryLayout.longestContiguousPrefix;
|
|
156
|
+
return {
|
|
157
|
+
size,
|
|
158
|
+
isContiguous,
|
|
159
|
+
longestContiguousPrefix
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function computeMemoryLayout(data) {
|
|
163
|
+
const knownSize = knownSizesMap[data.type];
|
|
164
|
+
if (knownSize !== void 0) return {
|
|
165
|
+
isContiguous: data.type !== "mat3x3f",
|
|
166
|
+
size: knownSize,
|
|
167
|
+
longestContiguousPrefix: data.type === "mat3x3f" ? 12 : knownSize
|
|
168
|
+
};
|
|
169
|
+
if (isWgslStruct(data)) return computeMLOfStruct(data);
|
|
170
|
+
if (isUnstruct(data)) return computeMLOfUnstruct(data);
|
|
171
|
+
if (isWgslArray(data)) return computeMLOfWgslArray(data);
|
|
172
|
+
if (isDisarray(data)) return computeMLOfDisarray(data);
|
|
173
|
+
if (isDecorated(data) || isLooseDecorated(data)) {
|
|
174
|
+
const size = getCustomSize(data);
|
|
175
|
+
const undecoratedLayout = computeMemoryLayout(undecorate(data));
|
|
176
|
+
if (size) return {
|
|
177
|
+
isContiguous: size === undecoratedLayout.size && undecoratedLayout.isContiguous,
|
|
178
|
+
size,
|
|
179
|
+
longestContiguousPrefix: undecoratedLayout.longestContiguousPrefix
|
|
180
|
+
};
|
|
181
|
+
return computeMemoryLayout(data.inner);
|
|
182
|
+
}
|
|
183
|
+
throw new Error(`Cannot determine memory layout of data: ${data}`);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Since memory layout can be inferred from data types, they are not stored on them.
|
|
187
|
+
* Instead, this weak map acts as an extended property of those data types.
|
|
188
|
+
*/
|
|
189
|
+
const cachedLayouts = /* @__PURE__ */ new WeakMap();
|
|
190
|
+
function getLayoutInfo(schema, key) {
|
|
191
|
+
let layout = cachedLayouts.get(schema);
|
|
192
|
+
if (layout === void 0) {
|
|
193
|
+
layout = computeMemoryLayout(schema);
|
|
194
|
+
cachedLayouts.set(schema, layout);
|
|
195
|
+
}
|
|
196
|
+
return layout[key];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//#endregion
|
|
200
|
+
export { getLayoutInfo };
|
package/data/sizeOf.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "./wgslTypes.js";
|
|
2
|
+
import { AnyData } from "./dataTypes.js";
|
|
3
|
+
|
|
4
|
+
//#region src/data/sizeOf.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Returns the size (in bytes) of data represented by the `schema`.
|
|
7
|
+
*/
|
|
8
|
+
declare function PUBLIC_sizeOf(schema: AnyData): number;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { PUBLIC_sizeOf };
|
package/data/sizeOf.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getLayoutInfo } from "./schemaMemoryLayout.js";
|
|
2
|
+
|
|
3
|
+
//#region src/data/sizeOf.ts
|
|
4
|
+
function sizeOf(schema) {
|
|
5
|
+
return getLayoutInfo(schema, "size");
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Returns the size (in bytes) of data represented by the `schema`.
|
|
9
|
+
*/
|
|
10
|
+
function PUBLIC_sizeOf(schema) {
|
|
11
|
+
return sizeOf(schema);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { PUBLIC_sizeOf, sizeOf };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BaseData } from "./wgslTypes.js";
|
|
2
|
+
import { UnknownData } from "./dataTypes.js";
|
|
3
|
+
|
|
4
|
+
//#region src/data/snippet.d.ts
|
|
5
|
+
type Origin = 'uniform' | 'readonly' | 'mutable' | 'workgroup' | 'private' | 'function' | 'this-function' | 'handle' | 'argument' | 'runtime' | 'constant' | 'constant-tgpu-const-ref' | 'runtime-tgpu-const-ref';
|
|
6
|
+
interface Snippet {
|
|
7
|
+
readonly value: unknown;
|
|
8
|
+
/**
|
|
9
|
+
* The type that `value` is assignable to (not necessary exactly inferred as).
|
|
10
|
+
* E.g. `1.1` is assignable to `f32`, but `1.1` itself is an abstract float
|
|
11
|
+
*/
|
|
12
|
+
readonly dataType: BaseData | UnknownData;
|
|
13
|
+
readonly origin: Origin;
|
|
14
|
+
}
|
|
15
|
+
interface ResolvedSnippet {
|
|
16
|
+
readonly value: string;
|
|
17
|
+
/**
|
|
18
|
+
* The type that `value` is assignable to (not necessary exactly inferred as).
|
|
19
|
+
* E.g. `1.1` is assignable to `f32`, but `1.1` itself is an abstract float
|
|
20
|
+
*/
|
|
21
|
+
readonly dataType: BaseData;
|
|
22
|
+
readonly origin: Origin;
|
|
23
|
+
}
|
|
24
|
+
type MapValueToSnippet<T> = { [K in keyof T]: Snippet };
|
|
25
|
+
//#endregion
|
|
26
|
+
export { MapValueToSnippet, Origin, ResolvedSnippet, Snippet };
|
package/data/snippet.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { DEV } from "../shared/env.js";
|
|
2
|
+
import { isNumericSchema } from "./wgslTypes.js";
|
|
3
|
+
import { undecorate } from "./dataTypes.js";
|
|
4
|
+
|
|
5
|
+
//#region src/data/snippet.ts
|
|
6
|
+
function isEphemeralOrigin(space) {
|
|
7
|
+
return space === "runtime" || space === "constant" || space === "argument";
|
|
8
|
+
}
|
|
9
|
+
function isEphemeralSnippet(snippet) {
|
|
10
|
+
return isEphemeralOrigin(snippet.origin);
|
|
11
|
+
}
|
|
12
|
+
const originToPtrParams = {
|
|
13
|
+
uniform: {
|
|
14
|
+
space: "uniform",
|
|
15
|
+
access: "read"
|
|
16
|
+
},
|
|
17
|
+
readonly: {
|
|
18
|
+
space: "storage",
|
|
19
|
+
access: "read"
|
|
20
|
+
},
|
|
21
|
+
mutable: {
|
|
22
|
+
space: "storage",
|
|
23
|
+
access: "read-write"
|
|
24
|
+
},
|
|
25
|
+
workgroup: {
|
|
26
|
+
space: "workgroup",
|
|
27
|
+
access: "read-write"
|
|
28
|
+
},
|
|
29
|
+
private: {
|
|
30
|
+
space: "private",
|
|
31
|
+
access: "read-write"
|
|
32
|
+
},
|
|
33
|
+
function: {
|
|
34
|
+
space: "function",
|
|
35
|
+
access: "read-write"
|
|
36
|
+
},
|
|
37
|
+
"this-function": {
|
|
38
|
+
space: "function",
|
|
39
|
+
access: "read-write"
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var SnippetImpl = class {
|
|
43
|
+
constructor(value, dataType, origin) {
|
|
44
|
+
this.value = value;
|
|
45
|
+
this.dataType = dataType;
|
|
46
|
+
this.origin = origin;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
function isSnippet(value) {
|
|
50
|
+
return value instanceof SnippetImpl;
|
|
51
|
+
}
|
|
52
|
+
function isSnippetNumeric(snippet) {
|
|
53
|
+
return isNumericSchema(snippet.dataType);
|
|
54
|
+
}
|
|
55
|
+
function snip(value, dataType, origin) {
|
|
56
|
+
if (DEV && isSnippet(value)) throw new Error("Cannot nest snippets");
|
|
57
|
+
return new SnippetImpl(value, undecorate(dataType), origin);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
export { isEphemeralOrigin, isEphemeralSnippet, isSnippet, isSnippetNumeric, originToPtrParams, snip };
|
package/data/struct.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AnyWgslData, WgslStruct } from "./wgslTypes.js";
|
|
2
|
+
|
|
3
|
+
//#region src/data/struct.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a struct schema that can be used to construct GPU buffers.
|
|
6
|
+
* Ensures proper alignment and padding of properties (as opposed to a `d.unstruct` schema).
|
|
7
|
+
* The order of members matches the passed in properties object.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const CircleStruct = d.struct({ radius: d.f32, pos: d.vec3f });
|
|
11
|
+
*
|
|
12
|
+
* @param props Record with `string` keys and `TgpuData` values,
|
|
13
|
+
* each entry describing one struct member.
|
|
14
|
+
*/
|
|
15
|
+
declare function struct<TProps extends Record<string, AnyWgslData>>(props: TProps): WgslStruct<TProps>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { struct };
|
package/data/struct.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { $internal } from "../shared/symbols.js";
|
|
2
|
+
import { getName, setName } from "../shared/meta.js";
|
|
3
|
+
import { schemaCallWrapper } from "./schemaCallWrapper.js";
|
|
4
|
+
import { isValidProp } from "../nameRegistry.js";
|
|
5
|
+
|
|
6
|
+
//#region src/data/struct.ts
|
|
7
|
+
/**
|
|
8
|
+
* Creates a struct schema that can be used to construct GPU buffers.
|
|
9
|
+
* Ensures proper alignment and padding of properties (as opposed to a `d.unstruct` schema).
|
|
10
|
+
* The order of members matches the passed in properties object.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const CircleStruct = d.struct({ radius: d.f32, pos: d.vec3f });
|
|
14
|
+
*
|
|
15
|
+
* @param props Record with `string` keys and `TgpuData` values,
|
|
16
|
+
* each entry describing one struct member.
|
|
17
|
+
*/
|
|
18
|
+
function struct(props) {
|
|
19
|
+
return INTERNAL_createStruct(props, false);
|
|
20
|
+
}
|
|
21
|
+
function abstruct(props) {
|
|
22
|
+
return INTERNAL_createStruct(props, true);
|
|
23
|
+
}
|
|
24
|
+
function INTERNAL_createStruct(props, isAbstruct) {
|
|
25
|
+
Object.keys(props).forEach((key) => {
|
|
26
|
+
if (!isValidProp(key)) throw new Error(`Property key '${key}' is a reserved WGSL word. Choose a different name.`);
|
|
27
|
+
});
|
|
28
|
+
const structSchema = (instanceProps) => Object.fromEntries(Object.entries(props).map(([key, schema]) => [key, schemaCallWrapper(schema, instanceProps?.[key])]));
|
|
29
|
+
Object.setPrototypeOf(structSchema, WgslStructImpl);
|
|
30
|
+
structSchema.propTypes = props;
|
|
31
|
+
Object.defineProperty(structSchema, $internal, { value: { isAbstruct } });
|
|
32
|
+
return structSchema;
|
|
33
|
+
}
|
|
34
|
+
const WgslStructImpl = {
|
|
35
|
+
type: "struct",
|
|
36
|
+
$name(label) {
|
|
37
|
+
setName(this, label);
|
|
38
|
+
return this;
|
|
39
|
+
},
|
|
40
|
+
toString() {
|
|
41
|
+
return `struct:${getName(this) ?? "<unnamed>"}`;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { INTERNAL_createStruct, abstruct, struct };
|