typegpu 0.1.3 → 0.2.0-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/chunk-5EPBCOO4.js +8 -0
- package/chunk-5EPBCOO4.js.map +1 -0
- package/chunk-SBJR5ZQJ.cjs +8 -0
- package/chunk-SBJR5ZQJ.cjs.map +1 -0
- package/data/index.cjs +1 -7
- package/data/index.cjs.map +1 -1
- package/data/index.d.cts +476 -43
- package/data/index.d.ts +476 -43
- package/data/index.js +1 -7
- package/data/index.js.map +1 -1
- package/index.cjs +51 -1
- package/index.cjs.map +1 -1
- package/index.d.cts +288 -6
- package/index.d.ts +288 -6
- package/index.js +51 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/{tgpuBuffer-BVk2wCHR.d.cts → types-qmW7FFqN.d.cts} +452 -113
- package/{tgpuBuffer-BVk2wCHR.d.ts → types-qmW7FFqN.d.ts} +452 -113
- package/chunk-2FWG5LPQ.js +0 -2
- package/chunk-2FWG5LPQ.js.map +0 -1
- package/chunk-7EYKOUWH.cjs +0 -2
- package/chunk-7EYKOUWH.cjs.map +0 -1
package/index.d.cts
CHANGED
@@ -1,13 +1,289 @@
|
|
1
|
+
import { T as TgpuRenderResource, a as TgpuNamable, b as TgpuBuffer, A as AnyTgpuData, O as OmitProps, c as TgpuBufferUsage, U as Uniform, S as Storage, d as TgpuBufferUniform, e as TgpuShaderStage, f as TgpuBufferReadonly, g as TgpuBufferMutable, h as U32, I as I32, F as F32, V as Vec4u, i as Vec4i, j as Vec4f, k as TgpuPlum, E as ExtractPlumValue, l as Unsubscribe, m as TgpuCode, B as BoundTgpuCode, n as Block, v as vecBase, o as vec3f, p as vec3i, q as vec3u } from './types-qmW7FFqN.cjs';
|
2
|
+
export { r as TgpuData, w as Vertex, s as isUsableAsStorage, t as isUsableAsUniform, u as isUsableAsVertex } from './types-qmW7FFqN.cjs';
|
1
3
|
import { Parsed } from 'typed-binary';
|
2
|
-
|
3
|
-
|
4
|
+
|
5
|
+
declare const TgpuSettableTrait: unique symbol;
|
6
|
+
interface TgpuSettable {
|
7
|
+
readonly [TgpuSettableTrait]: true;
|
8
|
+
}
|
9
|
+
|
10
|
+
type PlumListener<T> = (newValue: T) => unknown;
|
11
|
+
|
12
|
+
interface TgpuSampler extends TgpuRenderResource, TgpuNamable {
|
13
|
+
readonly descriptor: GPUSamplerDescriptor;
|
14
|
+
}
|
15
|
+
|
16
|
+
interface Unwrapper {
|
17
|
+
readonly device: GPUDevice;
|
18
|
+
unwrap(resource: TgpuBuffer<AnyTgpuData>): GPUBuffer;
|
19
|
+
unwrap(resource: TgpuBindGroupLayout): GPUBindGroupLayout;
|
20
|
+
unwrap(resource: TgpuBindGroup): GPUBindGroup;
|
21
|
+
}
|
22
|
+
|
23
|
+
type TgpuLayoutEntryBase = {
|
24
|
+
/**
|
25
|
+
* Limits this resource's visibility to specific shader stages.
|
26
|
+
*
|
27
|
+
* By default, each resource is visible to all shader stage types, but
|
28
|
+
* depending on the underlying implementation, this may have performance implications.
|
29
|
+
*
|
30
|
+
* @default ['compute'] for mutable resources
|
31
|
+
* @default ['compute','vertex','fragment'] for everything else
|
32
|
+
*/
|
33
|
+
visibility?: TgpuShaderStage[];
|
34
|
+
};
|
35
|
+
type TgpuLayoutUniform = TgpuLayoutEntryBase & {
|
36
|
+
uniform: AnyTgpuData | ((arrayLength: number) => AnyTgpuData);
|
37
|
+
};
|
38
|
+
type TgpuLayoutStorage = TgpuLayoutEntryBase & {
|
39
|
+
storage: AnyTgpuData | ((arrayLength: number) => AnyTgpuData);
|
40
|
+
/** @default 'readonly' */
|
41
|
+
access?: 'mutable' | 'readonly';
|
42
|
+
};
|
43
|
+
type TgpuLayoutSampler = TgpuLayoutEntryBase & {
|
44
|
+
sampler: GPUSamplerBindingType;
|
45
|
+
};
|
46
|
+
type TgpuLayoutTexture<TSampleType extends GPUTextureSampleType = GPUTextureSampleType> = TgpuLayoutEntryBase & {
|
47
|
+
/**
|
48
|
+
* - 'float' - f32
|
49
|
+
* - 'unfilterable-float' - f32, cannot be used with filtering samplers
|
50
|
+
* - 'depth' - f32
|
51
|
+
* - 'sint' - i32
|
52
|
+
* - 'uint' - u32
|
53
|
+
*/
|
54
|
+
texture: TSampleType;
|
55
|
+
/**
|
56
|
+
* @default '2d'
|
57
|
+
*/
|
58
|
+
viewDimension?: GPUTextureViewDimension;
|
59
|
+
/**
|
60
|
+
* @default false
|
61
|
+
*/
|
62
|
+
multisampled?: boolean;
|
63
|
+
};
|
64
|
+
type TgpuLayoutStorageTexture<TFormat extends GPUTextureFormat = GPUTextureFormat> = TgpuLayoutEntryBase & {
|
65
|
+
storageTexture: TFormat;
|
66
|
+
/** @default 'writeonly' */
|
67
|
+
access?: 'readonly' | 'writeonly' | 'mutable';
|
68
|
+
/** @default '2d' */
|
69
|
+
viewDimension?: GPUTextureViewDimension;
|
70
|
+
};
|
71
|
+
type TgpuLayoutExternalTexture = TgpuLayoutEntryBase & {
|
72
|
+
externalTexture: Record<string, never>;
|
73
|
+
};
|
74
|
+
type TgpuLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler | TgpuLayoutTexture | TgpuLayoutStorageTexture | TgpuLayoutExternalTexture;
|
75
|
+
type UnwrapRuntimeConstructorInner<T extends AnyTgpuData | ((_: number) => AnyTgpuData)> = T extends AnyTgpuData ? T : T extends (_: number) => infer Return ? Return : never;
|
76
|
+
type UnwrapRuntimeConstructor<T extends AnyTgpuData | ((_: number) => AnyTgpuData)> = T extends unknown ? UnwrapRuntimeConstructorInner<T> : never;
|
77
|
+
interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> extends TgpuNamable {
|
78
|
+
readonly resourceType: 'bind-group-layout';
|
79
|
+
readonly label: string | undefined;
|
80
|
+
readonly entries: Entries;
|
81
|
+
populate(entries: {
|
82
|
+
[K in keyof OmitProps<Entries, null>]: LayoutEntryToInput<Entries[K]>;
|
83
|
+
}): TgpuBindGroup<Entries>;
|
84
|
+
/**
|
85
|
+
* Creates a raw WebGPU resource based on the typed descriptor.
|
86
|
+
* NOTE: This creates a new resource every time, better to use `root.unwrap(...)` instead.
|
87
|
+
* @param unwrapper Used to unwrap any resources that this resource depends on.
|
88
|
+
*/
|
89
|
+
unwrap(unwrapper: Unwrapper): GPUBindGroupLayout;
|
90
|
+
}
|
91
|
+
type StorageUsageForEntry<T extends TgpuLayoutStorage> = T extends {
|
92
|
+
access?: infer Access;
|
93
|
+
} ? 'mutable' | 'readonly' extends Access ? TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> | TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : 'readonly' extends Access ? TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> : 'mutable' extends Access ? TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> | TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>>;
|
94
|
+
type LayoutEntryToInput<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUsage<UnwrapRuntimeConstructor<T['uniform']>, 'uniform'> | (TgpuBuffer<UnwrapRuntimeConstructor<T['uniform']>> & Uniform) | GPUBuffer : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> | (TgpuBuffer<UnwrapRuntimeConstructor<T['storage']>> & Storage) | GPUBuffer : T extends TgpuLayoutSampler ? GPUSampler : T extends TgpuLayoutTexture ? GPUTextureView : T extends TgpuLayoutStorageTexture ? GPUTextureView : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
|
95
|
+
type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform<UnwrapRuntimeConstructor<T['uniform']>> : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> : T extends TgpuLayoutSampler ? TgpuSampler : never;
|
96
|
+
type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
|
97
|
+
readonly resourceType: 'bind-group';
|
98
|
+
readonly layout: TgpuBindGroupLayout<Entries>;
|
99
|
+
unwrap(unwrapper: Unwrapper): GPUBindGroup;
|
100
|
+
};
|
101
|
+
declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Entries>;
|
102
|
+
|
103
|
+
type StorageTextureAccess = 'read' | 'write' | 'read_write';
|
104
|
+
type TextureScalarFormat = U32 | I32 | F32;
|
105
|
+
type TexelFormat = Vec4u | Vec4i | Vec4f;
|
106
|
+
|
107
|
+
type Optional<T> = {
|
108
|
+
[P in keyof T]?: T[P] | undefined;
|
109
|
+
};
|
110
|
+
interface TgpuAnyTextureView extends TgpuRenderResource {
|
111
|
+
readonly descriptor: GPUTextureViewDescriptor;
|
112
|
+
readonly texture: TgpuAnyTexture;
|
113
|
+
readonly dataType: TextureScalarFormat | TexelFormat;
|
114
|
+
readonly access: StorageTextureAccess | undefined;
|
115
|
+
}
|
116
|
+
interface TgpuAnyTexture {
|
117
|
+
readonly descriptor: Omit<GPUTextureDescriptor, 'usage'>;
|
118
|
+
get flags(): GPUTextureUsageFlags;
|
119
|
+
}
|
120
|
+
interface TgpuTextureExternal extends TgpuRenderResource, TgpuNamable {
|
121
|
+
readonly descriptor: Optional<GPUExternalTextureDescriptor>;
|
122
|
+
get source(): HTMLVideoElement | VideoFrame | undefined;
|
123
|
+
}
|
124
|
+
|
125
|
+
type SetPlumAction<T> = T | ((prev: T) => T);
|
126
|
+
interface TgpuRoot extends Unwrapper {
|
127
|
+
/**
|
128
|
+
* The GPU device associated with this root.
|
129
|
+
*/
|
130
|
+
readonly device: GPUDevice;
|
131
|
+
/**
|
132
|
+
* @param typeSchema The type of data that this buffer will hold.
|
133
|
+
* @param initial The initial value of the buffer. (optional)
|
134
|
+
*/
|
135
|
+
createBuffer<TData extends AnyTgpuData>(typeSchema: TData, initial?: Parsed<TData> | TgpuPlum<Parsed<TData>> | undefined): TgpuBuffer<TData>;
|
136
|
+
/**
|
137
|
+
* @param typeSchema The type of data that this buffer will hold.
|
138
|
+
* @param gpuBuffer A vanilla WebGPU buffer.
|
139
|
+
*/
|
140
|
+
createBuffer<TData extends AnyTgpuData>(typeSchema: TData, gpuBuffer: GPUBuffer): TgpuBuffer<TData>;
|
141
|
+
unwrap(resource: TgpuBuffer<AnyTgpuData>): GPUBuffer;
|
142
|
+
unwrap(resource: TgpuBindGroupLayout): GPUBindGroupLayout;
|
143
|
+
unwrap(resource: TgpuBindGroup): GPUBindGroup;
|
144
|
+
destroy(): void;
|
145
|
+
}
|
146
|
+
interface ExperimentalTgpuRoot extends TgpuRoot {
|
147
|
+
readonly jitTranspiler?: JitTranspiler | undefined;
|
148
|
+
/**
|
149
|
+
* The current command encoder. This property will
|
150
|
+
* hold the same value until `flush()` is called.
|
151
|
+
*/
|
152
|
+
readonly commandEncoder: GPUCommandEncoder;
|
153
|
+
readPlum<TPlum extends TgpuPlum>(plum: TPlum): ExtractPlumValue<TPlum>;
|
154
|
+
setPlum<TPlum extends TgpuPlum & TgpuSettable>(plum: TPlum, value: SetPlumAction<ExtractPlumValue<TPlum>>): void;
|
155
|
+
onPlumChange<TValue>(plum: TgpuPlum<TValue>, listener: PlumListener<TValue>): Unsubscribe;
|
156
|
+
setSource(texture: TgpuTextureExternal, source: HTMLVideoElement | VideoFrame): void;
|
157
|
+
isDirty(texture: TgpuTextureExternal): boolean;
|
158
|
+
markClean(texture: TgpuTextureExternal): void;
|
159
|
+
textureFor(view: TgpuAnyTexture | TgpuAnyTextureView): GPUTexture;
|
160
|
+
viewFor(view: TgpuAnyTextureView): GPUTextureView;
|
161
|
+
externalTextureFor(texture: TgpuTextureExternal): GPUExternalTexture;
|
162
|
+
samplerFor(sampler: TgpuSampler): GPUSampler;
|
163
|
+
/**
|
164
|
+
* Causes all commands enqueued by pipelines to be
|
165
|
+
* submitted to the GPU.
|
166
|
+
*/
|
167
|
+
flush(): void;
|
168
|
+
makeRenderPipeline(options: RenderPipelineOptions): RenderPipelineExecutor;
|
169
|
+
makeComputePipeline(options: ComputePipelineOptions): ComputePipelineExecutor;
|
170
|
+
}
|
171
|
+
interface RenderPipelineOptions {
|
172
|
+
vertex: {
|
173
|
+
code: TgpuCode | BoundTgpuCode;
|
174
|
+
output: {
|
175
|
+
[K in symbol]: string;
|
176
|
+
} & {
|
177
|
+
[K in string]: AnyTgpuData;
|
178
|
+
};
|
179
|
+
};
|
180
|
+
fragment: {
|
181
|
+
code: TgpuCode | BoundTgpuCode;
|
182
|
+
target: Iterable<GPUColorTargetState | null>;
|
183
|
+
};
|
184
|
+
primitive: GPUPrimitiveState;
|
185
|
+
externalLayouts?: GPUBindGroupLayout[];
|
186
|
+
label?: string;
|
187
|
+
}
|
188
|
+
interface ComputePipelineOptions {
|
189
|
+
code: TgpuCode | BoundTgpuCode;
|
190
|
+
workgroupSize?: readonly [number, number?, number?];
|
191
|
+
externalLayouts?: GPUBindGroupLayout[];
|
192
|
+
label?: string;
|
193
|
+
}
|
194
|
+
type RenderPipelineExecutorOptions = GPURenderPassDescriptor & {
|
195
|
+
vertexCount: number;
|
196
|
+
instanceCount?: number;
|
197
|
+
firstVertex?: number;
|
198
|
+
firstInstance?: number;
|
199
|
+
externalBindGroups?: GPUBindGroup[];
|
200
|
+
};
|
201
|
+
interface RenderPipelineExecutor {
|
202
|
+
execute(options: RenderPipelineExecutorOptions): void;
|
203
|
+
}
|
204
|
+
type ComputePipelineExecutorOptions = {
|
205
|
+
workgroups?: readonly [number, number?, number?];
|
206
|
+
externalBindGroups?: GPUBindGroup[];
|
207
|
+
};
|
208
|
+
interface ComputePipelineExecutor {
|
209
|
+
execute(options?: ComputePipelineExecutorOptions): void;
|
210
|
+
}
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Information extracted from transpiling a JS function.
|
214
|
+
*/
|
215
|
+
type TranspilationResult = {
|
216
|
+
argNames: string[];
|
217
|
+
body: Block;
|
218
|
+
/**
|
219
|
+
* All identifiers found in the function code that are not declared in the
|
220
|
+
* function itself, or in the block that is accessing that identifier.
|
221
|
+
*/
|
222
|
+
externalNames: string[];
|
223
|
+
};
|
224
|
+
|
225
|
+
/**
|
226
|
+
* Used to transpile JS resources into SMoL on demand.
|
227
|
+
*/
|
228
|
+
interface JitTranspiler {
|
229
|
+
transpileFn(rawJs: string): TranspilationResult;
|
230
|
+
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Options passed into {@link init}.
|
234
|
+
*/
|
235
|
+
type InitOptions = {
|
236
|
+
adapter?: GPURequestAdapterOptions | undefined;
|
237
|
+
device?: GPUDeviceDescriptor | undefined;
|
238
|
+
unstable_jitTranspiler?: JitTranspiler | undefined;
|
239
|
+
};
|
240
|
+
/**
|
241
|
+
* Options passed into {@link initFromDevice}.
|
242
|
+
*/
|
243
|
+
type InitFromDeviceOptions = {
|
244
|
+
device: GPUDevice;
|
245
|
+
unstable_jitTranspiler?: JitTranspiler | undefined;
|
246
|
+
};
|
247
|
+
/**
|
248
|
+
* Requests a new GPU device and creates a root around it.
|
249
|
+
* If a specific device should be used instead, use @see initFromDevice.
|
250
|
+
*
|
251
|
+
* @example
|
252
|
+
* When given no options, the function will ask the browser for a suitable GPU device.
|
253
|
+
* ```ts
|
254
|
+
* const root = await tgpu.init();
|
255
|
+
* ```
|
256
|
+
*
|
257
|
+
* @example
|
258
|
+
* If there are specific options that should be used when requesting a device, you can pass those in.
|
259
|
+
* ```ts
|
260
|
+
* const adapterOptions: GPURequestAdapterOptions = ...;
|
261
|
+
* const deviceDescriptor: GPUDeviceDescriptor = ...;
|
262
|
+
* const root = await tgpu.init({ adapter: adapterOptions, device: deviceDescriptor });
|
263
|
+
* ```
|
264
|
+
*/
|
265
|
+
declare function init(options?: InitOptions): Promise<ExperimentalTgpuRoot>;
|
266
|
+
/**
|
267
|
+
* Creates a root from the given device, instead of requesting it like @see init.
|
268
|
+
*
|
269
|
+
* @example
|
270
|
+
* ```ts
|
271
|
+
* const device: GPUDevice = ...;
|
272
|
+
* const root = tgpu.initFromDevice({ device });
|
273
|
+
* ```
|
274
|
+
*/
|
275
|
+
declare function initFromDevice(options: InitFromDeviceOptions): ExperimentalTgpuRoot;
|
4
276
|
|
5
277
|
/**
|
278
|
+
* @deprecated Use the `root.createBuffer` API instead, accessible through `await tgpu.init()`
|
279
|
+
*
|
6
280
|
* @param typeSchema The type of data that this buffer will hold.
|
7
281
|
* @param initial The initial value of the buffer. (optional)
|
8
282
|
*/
|
9
283
|
declare function createBuffer<TData extends AnyTgpuData>(typeSchema: TData, initial?: Parsed<TData> | TgpuPlum<Parsed<TData>> | undefined): TgpuBuffer<TData>;
|
10
284
|
/**
|
285
|
+
* @deprecated Use the `root.createBuffer` API instead, accessible through `await tgpu.init()`
|
286
|
+
*
|
11
287
|
* @param typeSchema The type of data that this buffer will hold.
|
12
288
|
* @param gpuBuffer A vanilla WebGPU buffer.
|
13
289
|
*/
|
@@ -41,12 +317,18 @@ declare const std: {
|
|
41
317
|
*/
|
42
318
|
|
43
319
|
declare const tgpu: {
|
44
|
-
|
45
|
-
|
46
|
-
|
320
|
+
/** @deprecated Use `'uniform'` string literal instead. */
|
321
|
+
Uniform: "uniform";
|
322
|
+
/** @deprecated Use `'storage'` string literal instead. */
|
323
|
+
Storage: "storage";
|
324
|
+
/** @deprecated Use `'vertex'` string literal instead. */
|
325
|
+
Vertex: "vertex";
|
326
|
+
bindGroupLayout: typeof bindGroupLayout;
|
327
|
+
init: typeof init;
|
328
|
+
initFromDevice: typeof initFromDevice;
|
47
329
|
createBuffer: typeof createBuffer;
|
48
330
|
read: typeof read;
|
49
331
|
write: typeof write;
|
50
332
|
};
|
51
333
|
|
52
|
-
export { AnyTgpuData, RecursiveDataTypeError, TgpuBuffer, tgpu as default, std, tgpu };
|
334
|
+
export { AnyTgpuData, type BindLayoutEntry, type LayoutEntryToInput, RecursiveDataTypeError, Storage, type TgpuBindGroup, type TgpuBindGroupLayout, TgpuBuffer, type TgpuLayoutEntry, type TgpuLayoutSampler, type TgpuLayoutUniform, Uniform, tgpu as default, std, tgpu };
|
package/index.d.ts
CHANGED
@@ -1,13 +1,289 @@
|
|
1
|
+
import { T as TgpuRenderResource, a as TgpuNamable, b as TgpuBuffer, A as AnyTgpuData, O as OmitProps, c as TgpuBufferUsage, U as Uniform, S as Storage, d as TgpuBufferUniform, e as TgpuShaderStage, f as TgpuBufferReadonly, g as TgpuBufferMutable, h as U32, I as I32, F as F32, V as Vec4u, i as Vec4i, j as Vec4f, k as TgpuPlum, E as ExtractPlumValue, l as Unsubscribe, m as TgpuCode, B as BoundTgpuCode, n as Block, v as vecBase, o as vec3f, p as vec3i, q as vec3u } from './types-qmW7FFqN.js';
|
2
|
+
export { r as TgpuData, w as Vertex, s as isUsableAsStorage, t as isUsableAsUniform, u as isUsableAsVertex } from './types-qmW7FFqN.js';
|
1
3
|
import { Parsed } from 'typed-binary';
|
2
|
-
|
3
|
-
|
4
|
+
|
5
|
+
declare const TgpuSettableTrait: unique symbol;
|
6
|
+
interface TgpuSettable {
|
7
|
+
readonly [TgpuSettableTrait]: true;
|
8
|
+
}
|
9
|
+
|
10
|
+
type PlumListener<T> = (newValue: T) => unknown;
|
11
|
+
|
12
|
+
interface TgpuSampler extends TgpuRenderResource, TgpuNamable {
|
13
|
+
readonly descriptor: GPUSamplerDescriptor;
|
14
|
+
}
|
15
|
+
|
16
|
+
interface Unwrapper {
|
17
|
+
readonly device: GPUDevice;
|
18
|
+
unwrap(resource: TgpuBuffer<AnyTgpuData>): GPUBuffer;
|
19
|
+
unwrap(resource: TgpuBindGroupLayout): GPUBindGroupLayout;
|
20
|
+
unwrap(resource: TgpuBindGroup): GPUBindGroup;
|
21
|
+
}
|
22
|
+
|
23
|
+
type TgpuLayoutEntryBase = {
|
24
|
+
/**
|
25
|
+
* Limits this resource's visibility to specific shader stages.
|
26
|
+
*
|
27
|
+
* By default, each resource is visible to all shader stage types, but
|
28
|
+
* depending on the underlying implementation, this may have performance implications.
|
29
|
+
*
|
30
|
+
* @default ['compute'] for mutable resources
|
31
|
+
* @default ['compute','vertex','fragment'] for everything else
|
32
|
+
*/
|
33
|
+
visibility?: TgpuShaderStage[];
|
34
|
+
};
|
35
|
+
type TgpuLayoutUniform = TgpuLayoutEntryBase & {
|
36
|
+
uniform: AnyTgpuData | ((arrayLength: number) => AnyTgpuData);
|
37
|
+
};
|
38
|
+
type TgpuLayoutStorage = TgpuLayoutEntryBase & {
|
39
|
+
storage: AnyTgpuData | ((arrayLength: number) => AnyTgpuData);
|
40
|
+
/** @default 'readonly' */
|
41
|
+
access?: 'mutable' | 'readonly';
|
42
|
+
};
|
43
|
+
type TgpuLayoutSampler = TgpuLayoutEntryBase & {
|
44
|
+
sampler: GPUSamplerBindingType;
|
45
|
+
};
|
46
|
+
type TgpuLayoutTexture<TSampleType extends GPUTextureSampleType = GPUTextureSampleType> = TgpuLayoutEntryBase & {
|
47
|
+
/**
|
48
|
+
* - 'float' - f32
|
49
|
+
* - 'unfilterable-float' - f32, cannot be used with filtering samplers
|
50
|
+
* - 'depth' - f32
|
51
|
+
* - 'sint' - i32
|
52
|
+
* - 'uint' - u32
|
53
|
+
*/
|
54
|
+
texture: TSampleType;
|
55
|
+
/**
|
56
|
+
* @default '2d'
|
57
|
+
*/
|
58
|
+
viewDimension?: GPUTextureViewDimension;
|
59
|
+
/**
|
60
|
+
* @default false
|
61
|
+
*/
|
62
|
+
multisampled?: boolean;
|
63
|
+
};
|
64
|
+
type TgpuLayoutStorageTexture<TFormat extends GPUTextureFormat = GPUTextureFormat> = TgpuLayoutEntryBase & {
|
65
|
+
storageTexture: TFormat;
|
66
|
+
/** @default 'writeonly' */
|
67
|
+
access?: 'readonly' | 'writeonly' | 'mutable';
|
68
|
+
/** @default '2d' */
|
69
|
+
viewDimension?: GPUTextureViewDimension;
|
70
|
+
};
|
71
|
+
type TgpuLayoutExternalTexture = TgpuLayoutEntryBase & {
|
72
|
+
externalTexture: Record<string, never>;
|
73
|
+
};
|
74
|
+
type TgpuLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler | TgpuLayoutTexture | TgpuLayoutStorageTexture | TgpuLayoutExternalTexture;
|
75
|
+
type UnwrapRuntimeConstructorInner<T extends AnyTgpuData | ((_: number) => AnyTgpuData)> = T extends AnyTgpuData ? T : T extends (_: number) => infer Return ? Return : never;
|
76
|
+
type UnwrapRuntimeConstructor<T extends AnyTgpuData | ((_: number) => AnyTgpuData)> = T extends unknown ? UnwrapRuntimeConstructorInner<T> : never;
|
77
|
+
interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> extends TgpuNamable {
|
78
|
+
readonly resourceType: 'bind-group-layout';
|
79
|
+
readonly label: string | undefined;
|
80
|
+
readonly entries: Entries;
|
81
|
+
populate(entries: {
|
82
|
+
[K in keyof OmitProps<Entries, null>]: LayoutEntryToInput<Entries[K]>;
|
83
|
+
}): TgpuBindGroup<Entries>;
|
84
|
+
/**
|
85
|
+
* Creates a raw WebGPU resource based on the typed descriptor.
|
86
|
+
* NOTE: This creates a new resource every time, better to use `root.unwrap(...)` instead.
|
87
|
+
* @param unwrapper Used to unwrap any resources that this resource depends on.
|
88
|
+
*/
|
89
|
+
unwrap(unwrapper: Unwrapper): GPUBindGroupLayout;
|
90
|
+
}
|
91
|
+
type StorageUsageForEntry<T extends TgpuLayoutStorage> = T extends {
|
92
|
+
access?: infer Access;
|
93
|
+
} ? 'mutable' | 'readonly' extends Access ? TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> | TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : 'readonly' extends Access ? TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> : 'mutable' extends Access ? TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> | TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>>;
|
94
|
+
type LayoutEntryToInput<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUsage<UnwrapRuntimeConstructor<T['uniform']>, 'uniform'> | (TgpuBuffer<UnwrapRuntimeConstructor<T['uniform']>> & Uniform) | GPUBuffer : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> | (TgpuBuffer<UnwrapRuntimeConstructor<T['storage']>> & Storage) | GPUBuffer : T extends TgpuLayoutSampler ? GPUSampler : T extends TgpuLayoutTexture ? GPUTextureView : T extends TgpuLayoutStorageTexture ? GPUTextureView : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
|
95
|
+
type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform<UnwrapRuntimeConstructor<T['uniform']>> : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> : T extends TgpuLayoutSampler ? TgpuSampler : never;
|
96
|
+
type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
|
97
|
+
readonly resourceType: 'bind-group';
|
98
|
+
readonly layout: TgpuBindGroupLayout<Entries>;
|
99
|
+
unwrap(unwrapper: Unwrapper): GPUBindGroup;
|
100
|
+
};
|
101
|
+
declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Entries>;
|
102
|
+
|
103
|
+
type StorageTextureAccess = 'read' | 'write' | 'read_write';
|
104
|
+
type TextureScalarFormat = U32 | I32 | F32;
|
105
|
+
type TexelFormat = Vec4u | Vec4i | Vec4f;
|
106
|
+
|
107
|
+
type Optional<T> = {
|
108
|
+
[P in keyof T]?: T[P] | undefined;
|
109
|
+
};
|
110
|
+
interface TgpuAnyTextureView extends TgpuRenderResource {
|
111
|
+
readonly descriptor: GPUTextureViewDescriptor;
|
112
|
+
readonly texture: TgpuAnyTexture;
|
113
|
+
readonly dataType: TextureScalarFormat | TexelFormat;
|
114
|
+
readonly access: StorageTextureAccess | undefined;
|
115
|
+
}
|
116
|
+
interface TgpuAnyTexture {
|
117
|
+
readonly descriptor: Omit<GPUTextureDescriptor, 'usage'>;
|
118
|
+
get flags(): GPUTextureUsageFlags;
|
119
|
+
}
|
120
|
+
interface TgpuTextureExternal extends TgpuRenderResource, TgpuNamable {
|
121
|
+
readonly descriptor: Optional<GPUExternalTextureDescriptor>;
|
122
|
+
get source(): HTMLVideoElement | VideoFrame | undefined;
|
123
|
+
}
|
124
|
+
|
125
|
+
type SetPlumAction<T> = T | ((prev: T) => T);
|
126
|
+
interface TgpuRoot extends Unwrapper {
|
127
|
+
/**
|
128
|
+
* The GPU device associated with this root.
|
129
|
+
*/
|
130
|
+
readonly device: GPUDevice;
|
131
|
+
/**
|
132
|
+
* @param typeSchema The type of data that this buffer will hold.
|
133
|
+
* @param initial The initial value of the buffer. (optional)
|
134
|
+
*/
|
135
|
+
createBuffer<TData extends AnyTgpuData>(typeSchema: TData, initial?: Parsed<TData> | TgpuPlum<Parsed<TData>> | undefined): TgpuBuffer<TData>;
|
136
|
+
/**
|
137
|
+
* @param typeSchema The type of data that this buffer will hold.
|
138
|
+
* @param gpuBuffer A vanilla WebGPU buffer.
|
139
|
+
*/
|
140
|
+
createBuffer<TData extends AnyTgpuData>(typeSchema: TData, gpuBuffer: GPUBuffer): TgpuBuffer<TData>;
|
141
|
+
unwrap(resource: TgpuBuffer<AnyTgpuData>): GPUBuffer;
|
142
|
+
unwrap(resource: TgpuBindGroupLayout): GPUBindGroupLayout;
|
143
|
+
unwrap(resource: TgpuBindGroup): GPUBindGroup;
|
144
|
+
destroy(): void;
|
145
|
+
}
|
146
|
+
interface ExperimentalTgpuRoot extends TgpuRoot {
|
147
|
+
readonly jitTranspiler?: JitTranspiler | undefined;
|
148
|
+
/**
|
149
|
+
* The current command encoder. This property will
|
150
|
+
* hold the same value until `flush()` is called.
|
151
|
+
*/
|
152
|
+
readonly commandEncoder: GPUCommandEncoder;
|
153
|
+
readPlum<TPlum extends TgpuPlum>(plum: TPlum): ExtractPlumValue<TPlum>;
|
154
|
+
setPlum<TPlum extends TgpuPlum & TgpuSettable>(plum: TPlum, value: SetPlumAction<ExtractPlumValue<TPlum>>): void;
|
155
|
+
onPlumChange<TValue>(plum: TgpuPlum<TValue>, listener: PlumListener<TValue>): Unsubscribe;
|
156
|
+
setSource(texture: TgpuTextureExternal, source: HTMLVideoElement | VideoFrame): void;
|
157
|
+
isDirty(texture: TgpuTextureExternal): boolean;
|
158
|
+
markClean(texture: TgpuTextureExternal): void;
|
159
|
+
textureFor(view: TgpuAnyTexture | TgpuAnyTextureView): GPUTexture;
|
160
|
+
viewFor(view: TgpuAnyTextureView): GPUTextureView;
|
161
|
+
externalTextureFor(texture: TgpuTextureExternal): GPUExternalTexture;
|
162
|
+
samplerFor(sampler: TgpuSampler): GPUSampler;
|
163
|
+
/**
|
164
|
+
* Causes all commands enqueued by pipelines to be
|
165
|
+
* submitted to the GPU.
|
166
|
+
*/
|
167
|
+
flush(): void;
|
168
|
+
makeRenderPipeline(options: RenderPipelineOptions): RenderPipelineExecutor;
|
169
|
+
makeComputePipeline(options: ComputePipelineOptions): ComputePipelineExecutor;
|
170
|
+
}
|
171
|
+
interface RenderPipelineOptions {
|
172
|
+
vertex: {
|
173
|
+
code: TgpuCode | BoundTgpuCode;
|
174
|
+
output: {
|
175
|
+
[K in symbol]: string;
|
176
|
+
} & {
|
177
|
+
[K in string]: AnyTgpuData;
|
178
|
+
};
|
179
|
+
};
|
180
|
+
fragment: {
|
181
|
+
code: TgpuCode | BoundTgpuCode;
|
182
|
+
target: Iterable<GPUColorTargetState | null>;
|
183
|
+
};
|
184
|
+
primitive: GPUPrimitiveState;
|
185
|
+
externalLayouts?: GPUBindGroupLayout[];
|
186
|
+
label?: string;
|
187
|
+
}
|
188
|
+
interface ComputePipelineOptions {
|
189
|
+
code: TgpuCode | BoundTgpuCode;
|
190
|
+
workgroupSize?: readonly [number, number?, number?];
|
191
|
+
externalLayouts?: GPUBindGroupLayout[];
|
192
|
+
label?: string;
|
193
|
+
}
|
194
|
+
type RenderPipelineExecutorOptions = GPURenderPassDescriptor & {
|
195
|
+
vertexCount: number;
|
196
|
+
instanceCount?: number;
|
197
|
+
firstVertex?: number;
|
198
|
+
firstInstance?: number;
|
199
|
+
externalBindGroups?: GPUBindGroup[];
|
200
|
+
};
|
201
|
+
interface RenderPipelineExecutor {
|
202
|
+
execute(options: RenderPipelineExecutorOptions): void;
|
203
|
+
}
|
204
|
+
type ComputePipelineExecutorOptions = {
|
205
|
+
workgroups?: readonly [number, number?, number?];
|
206
|
+
externalBindGroups?: GPUBindGroup[];
|
207
|
+
};
|
208
|
+
interface ComputePipelineExecutor {
|
209
|
+
execute(options?: ComputePipelineExecutorOptions): void;
|
210
|
+
}
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Information extracted from transpiling a JS function.
|
214
|
+
*/
|
215
|
+
type TranspilationResult = {
|
216
|
+
argNames: string[];
|
217
|
+
body: Block;
|
218
|
+
/**
|
219
|
+
* All identifiers found in the function code that are not declared in the
|
220
|
+
* function itself, or in the block that is accessing that identifier.
|
221
|
+
*/
|
222
|
+
externalNames: string[];
|
223
|
+
};
|
224
|
+
|
225
|
+
/**
|
226
|
+
* Used to transpile JS resources into SMoL on demand.
|
227
|
+
*/
|
228
|
+
interface JitTranspiler {
|
229
|
+
transpileFn(rawJs: string): TranspilationResult;
|
230
|
+
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Options passed into {@link init}.
|
234
|
+
*/
|
235
|
+
type InitOptions = {
|
236
|
+
adapter?: GPURequestAdapterOptions | undefined;
|
237
|
+
device?: GPUDeviceDescriptor | undefined;
|
238
|
+
unstable_jitTranspiler?: JitTranspiler | undefined;
|
239
|
+
};
|
240
|
+
/**
|
241
|
+
* Options passed into {@link initFromDevice}.
|
242
|
+
*/
|
243
|
+
type InitFromDeviceOptions = {
|
244
|
+
device: GPUDevice;
|
245
|
+
unstable_jitTranspiler?: JitTranspiler | undefined;
|
246
|
+
};
|
247
|
+
/**
|
248
|
+
* Requests a new GPU device and creates a root around it.
|
249
|
+
* If a specific device should be used instead, use @see initFromDevice.
|
250
|
+
*
|
251
|
+
* @example
|
252
|
+
* When given no options, the function will ask the browser for a suitable GPU device.
|
253
|
+
* ```ts
|
254
|
+
* const root = await tgpu.init();
|
255
|
+
* ```
|
256
|
+
*
|
257
|
+
* @example
|
258
|
+
* If there are specific options that should be used when requesting a device, you can pass those in.
|
259
|
+
* ```ts
|
260
|
+
* const adapterOptions: GPURequestAdapterOptions = ...;
|
261
|
+
* const deviceDescriptor: GPUDeviceDescriptor = ...;
|
262
|
+
* const root = await tgpu.init({ adapter: adapterOptions, device: deviceDescriptor });
|
263
|
+
* ```
|
264
|
+
*/
|
265
|
+
declare function init(options?: InitOptions): Promise<ExperimentalTgpuRoot>;
|
266
|
+
/**
|
267
|
+
* Creates a root from the given device, instead of requesting it like @see init.
|
268
|
+
*
|
269
|
+
* @example
|
270
|
+
* ```ts
|
271
|
+
* const device: GPUDevice = ...;
|
272
|
+
* const root = tgpu.initFromDevice({ device });
|
273
|
+
* ```
|
274
|
+
*/
|
275
|
+
declare function initFromDevice(options: InitFromDeviceOptions): ExperimentalTgpuRoot;
|
4
276
|
|
5
277
|
/**
|
278
|
+
* @deprecated Use the `root.createBuffer` API instead, accessible through `await tgpu.init()`
|
279
|
+
*
|
6
280
|
* @param typeSchema The type of data that this buffer will hold.
|
7
281
|
* @param initial The initial value of the buffer. (optional)
|
8
282
|
*/
|
9
283
|
declare function createBuffer<TData extends AnyTgpuData>(typeSchema: TData, initial?: Parsed<TData> | TgpuPlum<Parsed<TData>> | undefined): TgpuBuffer<TData>;
|
10
284
|
/**
|
285
|
+
* @deprecated Use the `root.createBuffer` API instead, accessible through `await tgpu.init()`
|
286
|
+
*
|
11
287
|
* @param typeSchema The type of data that this buffer will hold.
|
12
288
|
* @param gpuBuffer A vanilla WebGPU buffer.
|
13
289
|
*/
|
@@ -41,12 +317,18 @@ declare const std: {
|
|
41
317
|
*/
|
42
318
|
|
43
319
|
declare const tgpu: {
|
44
|
-
|
45
|
-
|
46
|
-
|
320
|
+
/** @deprecated Use `'uniform'` string literal instead. */
|
321
|
+
Uniform: "uniform";
|
322
|
+
/** @deprecated Use `'storage'` string literal instead. */
|
323
|
+
Storage: "storage";
|
324
|
+
/** @deprecated Use `'vertex'` string literal instead. */
|
325
|
+
Vertex: "vertex";
|
326
|
+
bindGroupLayout: typeof bindGroupLayout;
|
327
|
+
init: typeof init;
|
328
|
+
initFromDevice: typeof initFromDevice;
|
47
329
|
createBuffer: typeof createBuffer;
|
48
330
|
read: typeof read;
|
49
331
|
write: typeof write;
|
50
332
|
};
|
51
333
|
|
52
|
-
export { AnyTgpuData, RecursiveDataTypeError, TgpuBuffer, tgpu as default, std, tgpu };
|
334
|
+
export { AnyTgpuData, type BindLayoutEntry, type LayoutEntryToInput, RecursiveDataTypeError, Storage, type TgpuBindGroup, type TgpuBindGroupLayout, TgpuBuffer, type TgpuLayoutEntry, type TgpuLayoutSampler, type TgpuLayoutUniform, Uniform, tgpu as default, std, tgpu };
|