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
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { ShaderGenerator } from "../../tgsl/shaderGenerator.js";
|
|
2
|
+
import { Configurable } from "../root/rootTypes.js";
|
|
3
|
+
import { WgslExtension } from "../../wgslExtensions.js";
|
|
4
|
+
import { ResolvableObject, Wgsl } from "../../types.js";
|
|
5
|
+
import { Namespace } from "./namespace.js";
|
|
6
|
+
import { ResolutionResult } from "../../resolutionCtx.js";
|
|
7
|
+
|
|
8
|
+
//#region src/core/resolve/tgpuResolve.d.ts
|
|
9
|
+
interface TgpuResolveOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The naming strategy used for generating identifiers for resolved externals and their dependencies.
|
|
12
|
+
*
|
|
13
|
+
* ## Namespaces
|
|
14
|
+
* Each call to `tgpu.resolve` uses it's own namespace by default, but a
|
|
15
|
+
* custom namespace can be created with `tgpu.namespace` and passed in.
|
|
16
|
+
*
|
|
17
|
+
* This allows tracking the behavior of the resolution process, as well as
|
|
18
|
+
* sharing state between calls to `tgpu.resolve`.
|
|
19
|
+
*
|
|
20
|
+
* @default 'random'
|
|
21
|
+
*/
|
|
22
|
+
names?: 'strict' | 'random' | Namespace | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* A function to configure the resolution context.
|
|
25
|
+
*/
|
|
26
|
+
config?: ((cfg: Configurable) => Configurable) | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* List of WGSL shader extensions to enable.
|
|
29
|
+
*/
|
|
30
|
+
enableExtensions?: WgslExtension[] | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* A custom shader code generator, used when resolving TypeGPU functions.
|
|
33
|
+
* If not provided, the default WGSL generator will be used.
|
|
34
|
+
*/
|
|
35
|
+
shaderGenerator?: ShaderGenerator | undefined;
|
|
36
|
+
}
|
|
37
|
+
interface TgpuExtendedResolveOptions extends TgpuResolveOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Map of external names to their resolvable values.
|
|
40
|
+
*/
|
|
41
|
+
externals: Record<string, Wgsl | object>;
|
|
42
|
+
/**
|
|
43
|
+
* The code template to use for the resolution. All external names will be replaced with their resolved values.
|
|
44
|
+
* @default ''
|
|
45
|
+
*/
|
|
46
|
+
template?: string | undefined;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Resolves a template with external values. Each external that is used will get resolved to a code string and replaced in the template.
|
|
50
|
+
* Any dependencies of the externals will also be resolved and included in the output.
|
|
51
|
+
* @param options - The options for the resolution.
|
|
52
|
+
*
|
|
53
|
+
* @returns {ResolutionResult}
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const Gradient = d.struct({ from: d.vec3f, to: d.vec3f });
|
|
58
|
+
*
|
|
59
|
+
* const { code, usedBindGroupLayouts, catchall } = tgpu.resolveWithContext({
|
|
60
|
+
* template: `
|
|
61
|
+
* fn getGradientAngle(gradient: Gradient) -> f32 {
|
|
62
|
+
* return atan(gradient.to.y - gradient.from.y, gradient.to.x - gradient.from.x);
|
|
63
|
+
* }
|
|
64
|
+
* `,
|
|
65
|
+
* externals: {
|
|
66
|
+
* Gradient,
|
|
67
|
+
* },
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* console.log(code);
|
|
71
|
+
* // struct Gradient_0 {
|
|
72
|
+
* // from: vec3f,
|
|
73
|
+
* // to: vec3f,
|
|
74
|
+
* // }
|
|
75
|
+
* // fn getGradientAngle(gradient: Gradient_0) -> f32 {
|
|
76
|
+
* // return atan(gradient.to.y - gradient.from.y, gradient.to.x - gradient.from.x);
|
|
77
|
+
* // }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
declare function resolveWithContext(options: TgpuExtendedResolveOptions): ResolutionResult;
|
|
81
|
+
/**
|
|
82
|
+
* Resolves given TypeGPU resources.
|
|
83
|
+
* Any dependencies of the externals will also be resolved and included in the output.
|
|
84
|
+
* @param items - An array of items to resolve.
|
|
85
|
+
* @param options - The options for the resolution.
|
|
86
|
+
*
|
|
87
|
+
* @returns {ResolutionResult}
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* const Gradient = d.struct({
|
|
92
|
+
* from: d.vec3f,
|
|
93
|
+
* to: d.vec3f,
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* const { code, usedBindGroupLayouts, catchall } =
|
|
97
|
+
* tgpu.resolveWithContext([Gradient]);
|
|
98
|
+
*
|
|
99
|
+
* console.log(code);
|
|
100
|
+
* // struct Gradient_0 {
|
|
101
|
+
* // from: vec3f,
|
|
102
|
+
* // to: vec3f,
|
|
103
|
+
* // }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function resolveWithContext(items: ResolvableObject[], options?: TgpuResolveOptions): ResolutionResult;
|
|
107
|
+
/**
|
|
108
|
+
* A shorthand for calling `tgpu.resolveWithContext(...).code`.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const Gradient = d.struct({ from: d.vec3f, to: d.vec3f });
|
|
113
|
+
*
|
|
114
|
+
* const resolved = tgpu.resolve([Gradient]);
|
|
115
|
+
*
|
|
116
|
+
* console.log(resolved);
|
|
117
|
+
* // struct Gradient_0 {
|
|
118
|
+
* // from: vec3f,
|
|
119
|
+
* // to: vec3f,
|
|
120
|
+
* // }
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* const Gradient = d.struct({ from: d.vec3f, to: d.vec3f });
|
|
126
|
+
*
|
|
127
|
+
* const code = tgpu.resolve({
|
|
128
|
+
* template: `
|
|
129
|
+
* fn getGradientAngle(gradient: Gradient) -> f32 {
|
|
130
|
+
* return atan(gradient.to.y - gradient.from.y, gradient.to.x - gradient.from.x);
|
|
131
|
+
* }
|
|
132
|
+
* `,
|
|
133
|
+
* externals: {
|
|
134
|
+
* Gradient,
|
|
135
|
+
* },
|
|
136
|
+
* });
|
|
137
|
+
*
|
|
138
|
+
* console.log(code);
|
|
139
|
+
* // struct Gradient_0 {
|
|
140
|
+
* // from: vec3f,
|
|
141
|
+
* // to: vec3f,
|
|
142
|
+
* // }
|
|
143
|
+
* // fn getGradientAngle(gradient: Gradient_0) -> f32 {
|
|
144
|
+
* // return atan(gradient.to.y - gradient.from.y, gradient.to.x - gradient.from.x);
|
|
145
|
+
* // }
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
declare function resolve(options: TgpuExtendedResolveOptions): string;
|
|
149
|
+
declare function resolve(items: ResolvableObject[], options?: TgpuResolveOptions): string;
|
|
150
|
+
//#endregion
|
|
151
|
+
export { resolve, resolveWithContext };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { $internal, $resolve } from "../../shared/symbols.js";
|
|
2
|
+
import { Void } from "../../data/wgslTypes.js";
|
|
3
|
+
import { snip } from "../../data/snippet.js";
|
|
4
|
+
import { applyExternals, replaceExternalsInWgsl } from "./externals.js";
|
|
5
|
+
import { namespace } from "./namespace.js";
|
|
6
|
+
import { isBindGroupLayout } from "../../tgpuBindGroupLayout.js";
|
|
7
|
+
import { resolve as resolve$1 } from "../../resolutionCtx.js";
|
|
8
|
+
import { isPipeline } from "../pipeline/typeGuards.js";
|
|
9
|
+
|
|
10
|
+
//#region src/core/resolve/tgpuResolve.ts
|
|
11
|
+
function resolveWithContext(arg0, options) {
|
|
12
|
+
if (Array.isArray(arg0)) return resolveFromArray(arg0, options);
|
|
13
|
+
return resolveFromTemplate(arg0);
|
|
14
|
+
}
|
|
15
|
+
function resolve(arg, options) {
|
|
16
|
+
if (Array.isArray(arg)) return resolveWithContext(arg, options).code;
|
|
17
|
+
return resolveWithContext(arg).code;
|
|
18
|
+
}
|
|
19
|
+
function resolveFromTemplate(options) {
|
|
20
|
+
const { template, externals, shaderGenerator, names = "strict", config, enableExtensions } = options;
|
|
21
|
+
if (!template) console.warn("Calling resolve with an empty template is deprecated and will soon return an empty string. Consider using the 'tgpu.resolve(resolvableArray, options)' API instead.");
|
|
22
|
+
const dependencies = {};
|
|
23
|
+
applyExternals(dependencies, externals ?? {});
|
|
24
|
+
return resolve$1({
|
|
25
|
+
[$internal]: true,
|
|
26
|
+
[$resolve](ctx) {
|
|
27
|
+
return snip(replaceExternalsInWgsl(ctx, dependencies, template ?? ""), Void, "runtime");
|
|
28
|
+
},
|
|
29
|
+
toString: () => "<root>"
|
|
30
|
+
}, {
|
|
31
|
+
namespace: typeof names === "string" ? namespace({ names }) : names,
|
|
32
|
+
enableExtensions,
|
|
33
|
+
shaderGenerator,
|
|
34
|
+
config,
|
|
35
|
+
root: tryFindRoot(Object.values(externals))
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function resolveFromArray(items, options) {
|
|
39
|
+
const { shaderGenerator, names = "strict", config, enableExtensions } = options ?? {};
|
|
40
|
+
return resolve$1({
|
|
41
|
+
[$internal]: true,
|
|
42
|
+
[$resolve](ctx) {
|
|
43
|
+
for (const item of items) if (isBindGroupLayout(item)) for (const binding of Object.values(item[$internal].bound)) ctx.resolve(binding);
|
|
44
|
+
else ctx.resolve(item);
|
|
45
|
+
return snip("", Void, "runtime");
|
|
46
|
+
},
|
|
47
|
+
toString: () => "<root>"
|
|
48
|
+
}, {
|
|
49
|
+
namespace: typeof names === "string" ? namespace({ names }) : names,
|
|
50
|
+
enableExtensions,
|
|
51
|
+
shaderGenerator,
|
|
52
|
+
config,
|
|
53
|
+
root: tryFindRoot(items)
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Attempts to locate a pipeline in a list of items and returns the root.
|
|
58
|
+
* Does not check recursively.
|
|
59
|
+
* Throws an error if multiple pipelines are found.
|
|
60
|
+
*/
|
|
61
|
+
function tryFindRoot(items) {
|
|
62
|
+
const pipelines = items.filter(isPipeline);
|
|
63
|
+
if (pipelines.length > 1) throw new Error(`Found ${pipelines.length} pipelines but can only resolve one at a time.`);
|
|
64
|
+
return pipelines[0]?.[$internal].root;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { resolve, resolveWithContext };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isAccessor, isMutableAccessor } from "../slot/slotTypes.js";
|
|
2
|
+
|
|
3
|
+
//#region src/core/root/configurableImpl.ts
|
|
4
|
+
var ConfigurableImpl = class ConfigurableImpl {
|
|
5
|
+
constructor(bindings) {
|
|
6
|
+
this.bindings = bindings;
|
|
7
|
+
}
|
|
8
|
+
with(slot, value) {
|
|
9
|
+
return new ConfigurableImpl([...this.bindings, [isAccessor(slot) || isMutableAccessor(slot) ? slot.slot : slot, value]]);
|
|
10
|
+
}
|
|
11
|
+
pipe(transform) {
|
|
12
|
+
const newCfg = transform(this);
|
|
13
|
+
return new ConfigurableImpl([...this.bindings, ...newCfg.bindings]);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ConfigurableImpl };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import "../buffer/bufferShorthand.js";
|
|
2
|
+
import { LogGeneratorOptions } from "../../tgsl/consoleLog/types.js";
|
|
3
|
+
import "../pipeline/computePipeline.js";
|
|
4
|
+
import "../../tgpuBindGroupLayout.js";
|
|
5
|
+
import { ShaderGenerator } from "../../tgsl/shaderGenerator.js";
|
|
6
|
+
import { TgpuRoot } from "./rootTypes.js";
|
|
7
|
+
import "../../data/wgslTypes.js";
|
|
8
|
+
|
|
9
|
+
//#region src/core/root/init.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Options passed into {@link init}.
|
|
12
|
+
*/
|
|
13
|
+
type InitOptions = {
|
|
14
|
+
adapter?: GPURequestAdapterOptions | undefined;
|
|
15
|
+
device?: (GPUDeviceDescriptor & {
|
|
16
|
+
optionalFeatures?: Iterable<GPUFeatureName>;
|
|
17
|
+
}) | undefined; /** @default 'random' */
|
|
18
|
+
unstable_names?: 'random' | 'strict' | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* A custom shader code generator, used when resolving TypeGPU functions.
|
|
21
|
+
* If not provided, the default WGSL generator will be used.
|
|
22
|
+
*/
|
|
23
|
+
shaderGenerator?: ShaderGenerator | undefined;
|
|
24
|
+
unstable_logOptions?: LogGeneratorOptions;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Options passed into {@link initFromDevice}.
|
|
28
|
+
*/
|
|
29
|
+
type InitFromDeviceOptions = {
|
|
30
|
+
device: GPUDevice; /** @default 'random' */
|
|
31
|
+
unstable_names?: 'random' | 'strict' | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* A custom shader code generator, used when resolving TypeGPU functions.
|
|
34
|
+
* If not provided, the default WGSL generator will be used.
|
|
35
|
+
*/
|
|
36
|
+
shaderGenerator?: ShaderGenerator | undefined;
|
|
37
|
+
unstable_logOptions?: LogGeneratorOptions;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Requests a new GPU device and creates a root around it.
|
|
41
|
+
* If a specific device should be used instead, use @see initFromDevice.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* When given no options, the function will ask the browser for a suitable GPU device.
|
|
45
|
+
* ```ts
|
|
46
|
+
* const root = await tgpu.init();
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* If there are specific options that should be used when requesting a device, you can pass those in.
|
|
51
|
+
* ```ts
|
|
52
|
+
* const adapterOptions: GPURequestAdapterOptions = ...;
|
|
53
|
+
* const deviceDescriptor: GPUDeviceDescriptor = ...;
|
|
54
|
+
* const root = await tgpu.init({ adapter: adapterOptions, device: deviceDescriptor });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function init(options?: InitOptions): Promise<TgpuRoot>;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a root from the given device, instead of requesting it like @see init.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const device: GPUDevice = ...;
|
|
64
|
+
* const root = tgpu.initFromDevice({ device });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function initFromDevice(options: InitFromDeviceOptions): TgpuRoot;
|
|
68
|
+
//#endregion
|
|
69
|
+
export { InitFromDeviceOptions, InitOptions, init, initFromDevice };
|