typegpu 0.10.0 → 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-Dg5ybJro.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-ClEnM-Ye.js +0 -818
- package/builtin-ClEnM-Ye.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-yZXvaV2C.js +0 -413
- package/deepEqual-yZXvaV2C.js.map +0 -1
- package/extensions-0SFbU9FH.js +0 -2032
- package/extensions-0SFbU9FH.js.map +0 -1
- package/fullScreenTriangle-MdLGaAMR.js +0 -543
- package/fullScreenTriangle-MdLGaAMR.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/indexNamedExports-Cdy7USiY.d.ts +0 -5696
- package/indexNamedExports-Cdy7USiY.d.ts.map +0 -1
- package/operators-HTxa_0k9.js +0 -4156
- package/operators-HTxa_0k9.js.map +0 -1
- package/std/index.d.ts.map +0 -1
- package/std/index.js.map +0 -1
- package/texture-Dg5ybJro.js.map +0 -1
package/types.d.ts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { $cast, $gpuCallable, $internal } from "./shared/symbols.js";
|
|
2
|
+
import { MapValueToSnippet, ResolvedSnippet, Snippet } from "./data/snippet.js";
|
|
3
|
+
import { TgpuBufferUsage } from "./core/buffer/bufferUsage.js";
|
|
4
|
+
import { TgpuComputeFn } from "./core/function/tgpuComputeFn.js";
|
|
5
|
+
import { TgpuVar } from "./core/variable/tgpuVariable.js";
|
|
6
|
+
import { Eventual, SlotValuePair, TgpuAccessor, TgpuSlot } from "./core/slot/slotTypes.js";
|
|
7
|
+
import { TgpuComputePipeline } from "./core/pipeline/computePipeline.js";
|
|
8
|
+
import { TgpuFragmentFn } from "./core/function/tgpuFragmentFn.js";
|
|
9
|
+
import { TgpuVertexFn } from "./core/function/tgpuVertexFn.js";
|
|
10
|
+
import { TgpuRenderPipeline } from "./core/pipeline/renderPipeline.js";
|
|
11
|
+
import { TgpuSampler } from "./core/sampler/sampler.js";
|
|
12
|
+
import { TgpuExternalTexture } from "./core/texture/externalTexture.js";
|
|
13
|
+
import { TgpuBindGroupLayout, TgpuLayoutEntry } from "./tgpuBindGroupLayout.js";
|
|
14
|
+
import { TgpuBuffer } from "./core/buffer/buffer.js";
|
|
15
|
+
import { TgpuDeclare } from "./core/declare/tgpuDeclare.js";
|
|
16
|
+
import { TgpuFn } from "./core/function/tgpuFn.js";
|
|
17
|
+
import { WgslExtension } from "./wgslExtensions.js";
|
|
18
|
+
import { AnyMatInstance, AnyVecInstance, BaseData } from "./data/wgslTypes.js";
|
|
19
|
+
import { TgpuTexture, TgpuTextureView } from "./core/texture/texture.js";
|
|
20
|
+
import { Infer } from "./shared/repr.js";
|
|
21
|
+
import { AnyData, UnknownData } from "./data/dataTypes.js";
|
|
22
|
+
import { TgpuConst } from "./core/constant/tgpuConstant.js";
|
|
23
|
+
import { Block, FuncParameter } from "tinyest";
|
|
24
|
+
|
|
25
|
+
//#region src/types.d.ts
|
|
26
|
+
type ResolvableObject = SelfResolvable | TgpuBufferUsage | TgpuConst | TgpuDeclare | TgpuBindGroupLayout | TgpuFn | TgpuComputeFn | TgpuFragmentFn | TgpuComputePipeline | TgpuRenderPipeline | TgpuVertexFn | TgpuSampler | TgpuAccessor | TgpuExternalTexture | TgpuTexture | TgpuTextureView | TgpuVar | AnyVecInstance | AnyMatInstance | AnyData | ((...args: never[]) => unknown);
|
|
27
|
+
type Wgsl = Eventual<string | number | boolean | ResolvableObject>;
|
|
28
|
+
type TgpuShaderStage = 'compute' | 'vertex' | 'fragment';
|
|
29
|
+
interface FnToWgslOptions {
|
|
30
|
+
functionType: 'normal' | TgpuShaderStage;
|
|
31
|
+
argTypes: BaseData[];
|
|
32
|
+
/**
|
|
33
|
+
* The return type of the function. If undefined, the type should be inferred
|
|
34
|
+
* from the implementation (relevant for shellless functions).
|
|
35
|
+
*/
|
|
36
|
+
returnType: BaseData | undefined;
|
|
37
|
+
body: Block;
|
|
38
|
+
params: FuncParameter[];
|
|
39
|
+
externalMap: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
type ItemLayer = {
|
|
42
|
+
type: 'item';
|
|
43
|
+
usedSlots: Set<TgpuSlot<unknown>>;
|
|
44
|
+
};
|
|
45
|
+
type FunctionScopeLayer = {
|
|
46
|
+
type: 'functionScope';
|
|
47
|
+
functionType: 'normal' | 'compute' | 'vertex' | 'fragment';
|
|
48
|
+
args: Snippet[];
|
|
49
|
+
argAliases: Record<string, Snippet>;
|
|
50
|
+
externalMap: Record<string, unknown>;
|
|
51
|
+
/**
|
|
52
|
+
* The return type of the function. If undefined, the type should be inferred
|
|
53
|
+
* from the implementation (relevant for shellless functions).
|
|
54
|
+
*/
|
|
55
|
+
returnType: BaseData | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* All types used in `return` statements.
|
|
58
|
+
*/
|
|
59
|
+
reportedReturnTypes: Set<BaseData>;
|
|
60
|
+
};
|
|
61
|
+
type SlotBindingLayer = {
|
|
62
|
+
type: 'slotBinding';
|
|
63
|
+
bindingMap: WeakMap<TgpuSlot<unknown>, unknown>;
|
|
64
|
+
};
|
|
65
|
+
type BlockScopeLayer = {
|
|
66
|
+
type: 'blockScope';
|
|
67
|
+
declarations: Map<string, Snippet>;
|
|
68
|
+
externals: Map<string, Snippet>;
|
|
69
|
+
};
|
|
70
|
+
type StackLayer = ItemLayer | SlotBindingLayer | FunctionScopeLayer | BlockScopeLayer;
|
|
71
|
+
interface ItemStateStack {
|
|
72
|
+
readonly itemDepth: number;
|
|
73
|
+
readonly topItem: ItemLayer;
|
|
74
|
+
readonly topFunctionScope: FunctionScopeLayer | undefined;
|
|
75
|
+
pushItem(): void;
|
|
76
|
+
pushSlotBindings(pairs: SlotValuePair[]): void;
|
|
77
|
+
pushFunctionScope(functionType: 'normal' | TgpuShaderStage, args: Snippet[], argAliases: Record<string, Snippet>,
|
|
78
|
+
/**
|
|
79
|
+
* The return type of the function. If undefined, the type should be inferred
|
|
80
|
+
* from the implementation (relevant for shellless functions).
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
returnType: BaseData | undefined, externalMap: Record<string, unknown>): FunctionScopeLayer;
|
|
84
|
+
pushBlockScope(): void;
|
|
85
|
+
setBlockExternals(externals: Record<string, Snippet>): void;
|
|
86
|
+
clearBlockExternals(): void;
|
|
87
|
+
pop<T extends StackLayer['type']>(type: T): Extract<StackLayer, {
|
|
88
|
+
type: T;
|
|
89
|
+
}>;
|
|
90
|
+
pop(): StackLayer | undefined;
|
|
91
|
+
readSlot<T>(slot: TgpuSlot<T>): T | undefined;
|
|
92
|
+
getSnippetById(id: string): Snippet | undefined;
|
|
93
|
+
defineBlockVariable(id: string, snippet: Snippet): void;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* # What are execution modes/states? 🤷
|
|
97
|
+
* They're used to control how each TypeGPU resource reacts
|
|
98
|
+
* to actions upon them.
|
|
99
|
+
*
|
|
100
|
+
* ## Normal mode
|
|
101
|
+
* This is the default mode, where resources are acted upon
|
|
102
|
+
* by code either:
|
|
103
|
+
* - Not wrapped inside any of our execution-altering APIs
|
|
104
|
+
* like tgpu.resolve or tgpu.simulate.
|
|
105
|
+
* - Inside tgpu.lazy definitions, where we're taking a break
|
|
106
|
+
* from codegen/simulation to create resources on-demand.
|
|
107
|
+
*
|
|
108
|
+
* ```ts
|
|
109
|
+
* const count = tgpu.privateVar(d.f32);
|
|
110
|
+
* count.$ += 1; // Illegal in top-level
|
|
111
|
+
*
|
|
112
|
+
* const root = await tgpu.init();
|
|
113
|
+
* const countMutable = root.createMutable(d.f32);
|
|
114
|
+
* countMutable.$ = [1, 2, 3]; // Illegal in top-level
|
|
115
|
+
* countMutable.write([1, 2, 3]); // OK!
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* ## Codegen mode
|
|
119
|
+
* Brought upon by `tgpu.resolve()` (or higher-level APIs using it like our pipelines).
|
|
120
|
+
* Resources are expected to generate WGSL code that represents them, instead of
|
|
121
|
+
* fulfilling their task in JS.
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* const foo = tgpu.fn([], d.f32)(() => 123);
|
|
125
|
+
* // The following is running in `codegen` mode
|
|
126
|
+
* console.log(foo()); // Prints `foo_0()`
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* ## Simulate mode
|
|
130
|
+
* Callbacks passed to `tgpu.simulate()` are executed in this mode. Each 'simulation'
|
|
131
|
+
* is isolated, and does not share state with other simulations (even nested ones).
|
|
132
|
+
* Variables and buffers can be accessed and mutated directly, and their state
|
|
133
|
+
* is returned at the end of the simulation.
|
|
134
|
+
*
|
|
135
|
+
* ```ts
|
|
136
|
+
* const var = tgpu.privateVar(d.f32, 0);
|
|
137
|
+
*
|
|
138
|
+
* const result = tgpu.simulate(() => {
|
|
139
|
+
* // This is running in `simulate` mode
|
|
140
|
+
* var.$ += 1; // Direct access is legal
|
|
141
|
+
* return var.$; // Returns 1
|
|
142
|
+
* });
|
|
143
|
+
*
|
|
144
|
+
* console.log(result.value); // Prints 1
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
type ExecMode = 'normal' | 'codegen' | 'simulate';
|
|
148
|
+
declare class NormalState {
|
|
149
|
+
readonly type: "normal";
|
|
150
|
+
}
|
|
151
|
+
declare class CodegenState {
|
|
152
|
+
readonly type: "codegen";
|
|
153
|
+
}
|
|
154
|
+
declare class SimulationState {
|
|
155
|
+
readonly buffers: Map<TgpuBuffer<BaseData>, unknown>;
|
|
156
|
+
readonly vars: {
|
|
157
|
+
private: Map<TgpuVar, unknown>;
|
|
158
|
+
workgroup: Map<TgpuVar, unknown>;
|
|
159
|
+
};
|
|
160
|
+
readonly type: "simulate";
|
|
161
|
+
constructor(buffers: Map<TgpuBuffer<BaseData>, unknown>, vars: {
|
|
162
|
+
private: Map<TgpuVar, unknown>;
|
|
163
|
+
workgroup: Map<TgpuVar, unknown>;
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
type ExecState = NormalState | CodegenState | SimulationState;
|
|
167
|
+
/**
|
|
168
|
+
* Passed into each resolvable item. All items in a tree share a resolution ctx,
|
|
169
|
+
* but there can be layers added and removed from the item stack when going down
|
|
170
|
+
* and up the tree.
|
|
171
|
+
*/
|
|
172
|
+
interface ResolutionCtx {
|
|
173
|
+
[$internal]: {
|
|
174
|
+
itemStateStack: ItemStateStack;
|
|
175
|
+
};
|
|
176
|
+
readonly mode: ExecState;
|
|
177
|
+
readonly enableExtensions: WgslExtension[] | undefined;
|
|
178
|
+
addDeclaration(declaration: string): void;
|
|
179
|
+
withResetIndentLevel<T>(callback: () => T): T;
|
|
180
|
+
/**
|
|
181
|
+
* Reserves a bind group number, and returns a placeholder that will be replaced
|
|
182
|
+
* with a concrete number at the end of the resolution process.
|
|
183
|
+
*/
|
|
184
|
+
allocateLayoutEntry(layout: TgpuBindGroupLayout): string;
|
|
185
|
+
/**
|
|
186
|
+
* Reserves a spot in the catch-all bind group, without the indirection of a bind-group.
|
|
187
|
+
* This means the resource is 'fixed', and cannot be swapped between code execution.
|
|
188
|
+
*/
|
|
189
|
+
allocateFixedEntry(layoutEntry: TgpuLayoutEntry, resource: object): {
|
|
190
|
+
group: string;
|
|
191
|
+
binding: number;
|
|
192
|
+
};
|
|
193
|
+
withSlots<T>(pairs: SlotValuePair[], callback: () => T): T;
|
|
194
|
+
pushMode(state: ExecState): void;
|
|
195
|
+
popMode(expected?: ExecMode): void;
|
|
196
|
+
/**
|
|
197
|
+
* Unwraps all layers of slot/lazy indirection and returns the concrete value if available.
|
|
198
|
+
* @throws {MissingSlotValueError}
|
|
199
|
+
*/
|
|
200
|
+
unwrap<T>(eventual: Eventual<T>): T;
|
|
201
|
+
/**
|
|
202
|
+
* Returns the snippet representing `item`.
|
|
203
|
+
*
|
|
204
|
+
* @param item The value to resolve
|
|
205
|
+
* @param schema Additional information about the item's data type
|
|
206
|
+
* @param exact Should the inferred value of the resulting code be typed exactly as `schema` (true),
|
|
207
|
+
* or is being assignable to `schema` enough (false). Default is false.
|
|
208
|
+
*/
|
|
209
|
+
resolve(item: unknown, schema?: BaseData | UnknownData, exact?: boolean): ResolvedSnippet;
|
|
210
|
+
fnToWgsl(options: FnToWgslOptions): {
|
|
211
|
+
head: Wgsl;
|
|
212
|
+
body: Wgsl;
|
|
213
|
+
returnType: BaseData;
|
|
214
|
+
};
|
|
215
|
+
withVaryingLocations<T>(locations: Record<string, number>, callback: () => T): T;
|
|
216
|
+
get varyingLocations(): Record<string, number> | undefined;
|
|
217
|
+
/**
|
|
218
|
+
* Temporarily renames the item.
|
|
219
|
+
* Useful for resolutions with slots,
|
|
220
|
+
* since functions with different slots should have different names,
|
|
221
|
+
* and all hold the same inner function that is being resolved multiple times.
|
|
222
|
+
* @param item the item to rename
|
|
223
|
+
* @param name the temporary name to assign to the item (if missing, just returns `callback()`)
|
|
224
|
+
*/
|
|
225
|
+
withRenamed<T>(item: object, name: string | undefined, callback: () => T): T;
|
|
226
|
+
getUniqueName(resource: object): string;
|
|
227
|
+
makeNameValid(name: string): string;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Houses a method on the symbol '$resolve` that returns a
|
|
231
|
+
* code string representing it, as opposed to offloading the
|
|
232
|
+
* resolution to another mechanism.
|
|
233
|
+
*/
|
|
234
|
+
interface SelfResolvable {
|
|
235
|
+
[$internal]: unknown;
|
|
236
|
+
[$resolve](ctx: ResolutionCtx): ResolvedSnippet;
|
|
237
|
+
toString(): string;
|
|
238
|
+
}
|
|
239
|
+
interface GPUCallable<TArgs extends unknown[] = unknown[]> {
|
|
240
|
+
[$gpuCallable]: {
|
|
241
|
+
strictSignature?: {
|
|
242
|
+
argTypes: (BaseData | BaseData[])[];
|
|
243
|
+
returnType: BaseData;
|
|
244
|
+
} | undefined;
|
|
245
|
+
call(ctx: ResolutionCtx, args: MapValueToSnippet<TArgs>): Snippet;
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
type WithCast<T = BaseData> = GPUCallable<[v?: Infer<T>]> & {
|
|
249
|
+
readonly [$cast]: (v?: Infer<T>) => Infer<T>;
|
|
250
|
+
};
|
|
251
|
+
type AnyFn = (...args: never[]) => unknown;
|
|
252
|
+
type DualFn<T extends AnyFn> = T & GPUCallable<Parameters<T>>;
|
|
253
|
+
type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
|
|
254
|
+
//#endregion
|
|
255
|
+
export { BindableBufferUsage, DualFn, FunctionScopeLayer, GPUCallable, ResolutionCtx, ResolvableObject, SelfResolvable, TgpuShaderStage, Wgsl, WithCast };
|
package/types.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { $cast, $gpuCallable, $ownSnippet, $resolve } from "./shared/symbols.js";
|
|
2
|
+
import { isWgslData } from "./data/wgslTypes.js";
|
|
3
|
+
import { UnknownData } from "./data/dataTypes.js";
|
|
4
|
+
import { isLazy, isProviding, isSlot } from "./core/slot/slotTypes.js";
|
|
5
|
+
|
|
6
|
+
//#region src/types.ts
|
|
7
|
+
var NormalState = class {
|
|
8
|
+
type = "normal";
|
|
9
|
+
};
|
|
10
|
+
var CodegenState = class {
|
|
11
|
+
type = "codegen";
|
|
12
|
+
};
|
|
13
|
+
var SimulationState = class {
|
|
14
|
+
type = "simulate";
|
|
15
|
+
constructor(buffers, vars) {
|
|
16
|
+
this.buffers = buffers;
|
|
17
|
+
this.vars = vars;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function isSelfResolvable(value) {
|
|
21
|
+
return !!value?.[$resolve];
|
|
22
|
+
}
|
|
23
|
+
function getOwnSnippet(value) {
|
|
24
|
+
return value?.[$ownSnippet];
|
|
25
|
+
}
|
|
26
|
+
function isGPUCallable(value) {
|
|
27
|
+
return !!value?.[$gpuCallable];
|
|
28
|
+
}
|
|
29
|
+
function hasCast(value) {
|
|
30
|
+
return !!value?.[$cast];
|
|
31
|
+
}
|
|
32
|
+
function isKnownAtComptime(snippet) {
|
|
33
|
+
return (typeof snippet.value !== "string" || snippet.dataType === UnknownData) && getOwnSnippet(snippet.value) === void 0;
|
|
34
|
+
}
|
|
35
|
+
function isWgsl(value) {
|
|
36
|
+
return typeof value === "number" || typeof value === "boolean" || typeof value === "string" || isSelfResolvable(value) || isWgslData(value) || isSlot(value) || isLazy(value) || isProviding(value);
|
|
37
|
+
}
|
|
38
|
+
function isGPUBuffer(value) {
|
|
39
|
+
return !!value && typeof value === "object" && "getMappedRange" in value && "mapAsync" in value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { CodegenState, NormalState, SimulationState, getOwnSnippet, hasCast, isGPUBuffer, isGPUCallable, isKnownAtComptime, isSelfResolvable, isWgsl };
|
package/unwrapper.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TgpuQuerySet } from "./core/querySet/querySet.js";
|
|
2
|
+
import { TgpuComputePipeline } from "./core/pipeline/computePipeline.js";
|
|
3
|
+
import { TgpuVertexLayout } from "./core/vertexLayout/vertexLayout.js";
|
|
4
|
+
import { TgpuRenderPipeline } from "./core/pipeline/renderPipeline.js";
|
|
5
|
+
import { TgpuComparisonSampler, TgpuSampler } from "./core/sampler/sampler.js";
|
|
6
|
+
import { TgpuBindGroup, TgpuBindGroupLayout } from "./tgpuBindGroupLayout.js";
|
|
7
|
+
import { TgpuBuffer } from "./core/buffer/buffer.js";
|
|
8
|
+
import { BaseData } from "./data/wgslTypes.js";
|
|
9
|
+
import { TgpuTexture, TgpuTextureView } from "./core/texture/texture.js";
|
|
10
|
+
|
|
11
|
+
//#region src/unwrapper.d.ts
|
|
12
|
+
interface Unwrapper {
|
|
13
|
+
readonly device: GPUDevice;
|
|
14
|
+
unwrap(resource: TgpuComputePipeline): GPUComputePipeline;
|
|
15
|
+
unwrap(resource: TgpuRenderPipeline): GPURenderPipeline;
|
|
16
|
+
unwrap(resource: TgpuBindGroupLayout): GPUBindGroupLayout;
|
|
17
|
+
unwrap(resource: TgpuBindGroup): GPUBindGroup;
|
|
18
|
+
unwrap(resource: TgpuBuffer<BaseData>): GPUBuffer;
|
|
19
|
+
unwrap(resource: TgpuTextureView): GPUTextureView;
|
|
20
|
+
unwrap(resource: TgpuVertexLayout): GPUVertexBufferLayout;
|
|
21
|
+
unwrap(resource: TgpuSampler): GPUSampler;
|
|
22
|
+
unwrap(resource: TgpuComparisonSampler): GPUSampler;
|
|
23
|
+
unwrap(resource: TgpuQuerySet<GPUQueryType>): GPUQuerySet;
|
|
24
|
+
unwrap(resource: TgpuTexture): GPUTexture;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { Unwrapper };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/wgslExtensions.ts
|
|
2
|
+
const wgslExtensions = [
|
|
3
|
+
"f16",
|
|
4
|
+
"clip_distances",
|
|
5
|
+
"dual_source_blending",
|
|
6
|
+
"subgroups",
|
|
7
|
+
"primitive_index"
|
|
8
|
+
];
|
|
9
|
+
const wgslExtensionToFeatureName = {
|
|
10
|
+
f16: "shader-f16",
|
|
11
|
+
clip_distances: "clip-distances",
|
|
12
|
+
dual_source_blending: "dual-source-blending",
|
|
13
|
+
subgroups: "subgroups",
|
|
14
|
+
primitive_index: "primitive-index"
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { wgslExtensionToFeatureName, wgslExtensions };
|