typegpu 0.0.0-alpha.3 → 0.0.0-alpha.4

Sign up to get free protection for your applications and to get access to all the features.
package/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { W as WgslResolvable, a as WgslSlot, b as WgslPlum, E as ExtractPlumValue, c as WgslSettable, U as Unsubscribe, A as AnyWgslData, d as WgslAllocatable, e as Wgsl, B as BufferUsage, f as WgslBindable, g as Eventual, I as InlineResolve, h as WgslFnArgument, R as ResolutionCtx, i as WgslValue, j as WgslIdentifier, k as WgslResolvableSlot, p as plum, l as plumFromEvent } from './types-DeF6xFAt.cjs';
2
- export { t as AnyWgslPointer, q as EventualGetter, S as SlotValuePair, r as WgslData, s as WgslPointer, u as isPointer, m as isResolvable, o as isSlot, n as isWgsl } from './types-DeF6xFAt.cjs';
3
- import { Parsed } from 'typed-binary';
4
- import { W as WgslStruct } from './struct-ER9XI7ad.cjs';
1
+ import { W as WgslResolvable, a as WgslSlot, E as Eventual, b as Wgsl, I as InlineResolve, c as WgslRenderResource, T as TextureUsage, S as StorageTextureParams, A as AnyWgslTexelFormat, d as SampledTextureParams, e as AnyWgslPrimitive, f as WgslRenderResourceType, g as StorageTextureAccess, R as ResolutionCtx, h as WgslPlum, i as ExtractPlumValue, j as WgslSettable, U as Unsubscribe, k as AnyWgslData, l as WgslAllocatable, B as BufferUsage, m as WgslBindable, n as WgslFnArgument, o as WgslValue, p as WgslIdentifier, q as WgslResolvableSlot, r as plum, s as plumFromEvent } from './types-ENDwr_p9.cjs';
2
+ export { O as AnyWgslPointer, Q as BuiltInPossibleTypes, X as Builtin, w as EventualGetter, x as SlotValuePair, M as WgslData, C as WgslDepthTextureType, F as WgslExternalTextureType, N as WgslPointer, y as WgslSamplerType, D as WgslStorageTextureType, z as WgslTypedTextureType, V as builtin, Y as getBuiltinInfo, Z as getUsedBuiltinsNamed, J as isDepthTextureType, L as isExternalTextureType, P as isPointer, t as isResolvable, G as isSamplerType, v as isSlot, K as isStorageTextureType, H as isTypedTextureType, u as isWgsl } from './types-ENDwr_p9.cjs';
3
+ import { Parsed, AnySchema } from 'typed-binary';
4
+ import { S as SimpleWgslData } from './std140-DRitCcmc.cjs';
5
5
 
6
6
  /**
7
7
  * An error that happens during resolution of WGSL code.
@@ -38,6 +38,65 @@ declare abstract class Callable<TArgs extends [...any[]], TReturn> extends Funct
38
38
  type ICallable<TArgs extends [...any[]], TReturn> = (...args: TArgs) => TReturn;
39
39
  type AsCallable<T, TArgs extends [...any[]], TReturn> = T & ICallable<TArgs, TReturn>;
40
40
 
41
+ type PlumListener<T> = (newValue: T) => unknown;
42
+
43
+ interface WgslCode extends WgslResolvable {
44
+ $name(label?: string | undefined): WgslCode;
45
+ with<T>(slot: WgslSlot<T>, value: Eventual<T>): BoundWgslCode;
46
+ }
47
+ type BoundWgslCode = Omit<WgslCode, '$name'>;
48
+ declare function code(strings: TemplateStringsArray, ...params: (Wgsl | Wgsl[] | InlineResolve)[]): WgslCode;
49
+
50
+ interface WgslSampler extends WgslRenderResource {
51
+ readonly descriptor: GPUSamplerDescriptor;
52
+ $name(label: string): WgslSampler;
53
+ }
54
+ declare function sampler(descriptor: GPUSamplerDescriptor): WgslSampler;
55
+
56
+ interface WgslAnyTextureView extends WgslRenderResource {
57
+ readonly descriptor: GPUTextureViewDescriptor;
58
+ readonly texture: WgslAnyTexture;
59
+ readonly dataType: AnyWgslPrimitive | AnyWgslTexelFormat;
60
+ readonly access: StorageTextureAccess | undefined;
61
+ }
62
+ interface WgslAnyTexture {
63
+ readonly descriptor: Omit<GPUTextureDescriptor, 'usage'>;
64
+ get flags(): GPUTextureUsageFlags;
65
+ }
66
+ interface WgslTexture<TAllows extends TextureUsage = never> {
67
+ readonly descriptor: Omit<GPUTextureDescriptor, 'usage'>;
68
+ get label(): string | undefined;
69
+ get flags(): GPUTextureUsageFlags;
70
+ $name(label: string): WgslTexture<TAllows>;
71
+ $allowSampled(): WgslTexture<TAllows | 'sampled'>;
72
+ $allowStorage(): WgslTexture<TAllows | 'storage'>;
73
+ asStorage(params: StorageTextureParams): 'storage' extends TAllows ? WgslTextureView<AnyWgslTexelFormat, 'storage'> : null;
74
+ asSampled(params: SampledTextureParams): 'sampled' extends TAllows ? WgslTextureView<typeof params.dataType, 'sampled'> : null;
75
+ }
76
+ interface WgslTextureView<TData extends AnyWgslPrimitive | AnyWgslTexelFormat, TUsage extends TextureUsage> extends WgslRenderResource {
77
+ readonly texture: WgslTexture<TUsage>;
78
+ readonly descriptor: Omit<GPUTextureViewDescriptor, 'usage'>;
79
+ readonly type: WgslRenderResourceType;
80
+ readonly dataType: TData;
81
+ readonly access: StorageTextureAccess | undefined;
82
+ $name(label: string): WgslTextureView<TData, TUsage>;
83
+ }
84
+ interface WgslTextureExternal extends WgslRenderResource {
85
+ readonly descriptor: GPUExternalTextureDescriptor;
86
+ }
87
+ declare function texture<TUsage extends TextureUsage = never>(descriptor: Omit<GPUTextureDescriptor, 'usage'>): WgslTexture<TUsage>;
88
+ declare function textureExternal(descriptor: GPUExternalTextureDescriptor): WgslTextureExternalImpl;
89
+ declare class WgslTextureExternalImpl implements WgslTextureExternal {
90
+ readonly descriptor: GPUExternalTextureDescriptor;
91
+ private _label;
92
+ readonly type = "texture_external";
93
+ constructor(descriptor: GPUExternalTextureDescriptor);
94
+ get label(): string | undefined;
95
+ $name(label: string | undefined): this;
96
+ resolve(ctx: ResolutionCtx): string;
97
+ }
98
+
99
+ type SetPlumAction<T> = T | ((prev: T) => T);
41
100
  interface TypeGpuRuntime {
42
101
  readonly device: GPUDevice;
43
102
  /**
@@ -46,11 +105,15 @@ interface TypeGpuRuntime {
46
105
  */
47
106
  readonly commandEncoder: GPUCommandEncoder;
48
107
  readPlum<TPlum extends WgslPlum>(plum: TPlum): ExtractPlumValue<TPlum>;
49
- setPlum<TPlum extends WgslPlum & WgslSettable>(plum: TPlum, value: ExtractPlumValue<TPlum>): void;
50
- onPlumChange<TValue>(plum: WgslPlum<TValue>, listener: () => unknown): Unsubscribe;
108
+ setPlum<TPlum extends WgslPlum & WgslSettable>(plum: TPlum, value: SetPlumAction<ExtractPlumValue<TPlum>>): void;
109
+ onPlumChange<TValue>(plum: WgslPlum<TValue>, listener: PlumListener<TValue>): Unsubscribe;
51
110
  writeBuffer<TValue extends AnyWgslData>(allocatable: WgslAllocatable<TValue>, data: Parsed<TValue>): void;
52
111
  readBuffer<TData extends AnyWgslData>(allocatable: WgslAllocatable<TData>): Promise<Parsed<TData>>;
53
112
  bufferFor(allocatable: WgslAllocatable): GPUBuffer;
113
+ textureFor(view: WgslAnyTexture | WgslAnyTextureView): GPUTexture;
114
+ viewFor(view: WgslAnyTextureView): GPUTextureView;
115
+ externalTextureFor(texture: WgslTextureExternal): GPUExternalTexture;
116
+ samplerFor(sampler: WgslSampler): GPUSampler;
54
117
  dispose(): void;
55
118
  /**
56
119
  * Causes all commands enqueued by pipelines to be
@@ -62,28 +125,25 @@ interface TypeGpuRuntime {
62
125
  }
63
126
  interface RenderPipelineOptions {
64
127
  vertex: {
65
- args: Wgsl[];
66
- code: Wgsl;
67
- output: WgslStruct<Record<string, AnyWgslData>>;
68
- buffersLayouts?: Iterable<GPUVertexBufferLayout | null>;
128
+ code: WgslCode | BoundWgslCode;
129
+ output: {
130
+ [K in symbol]: string;
131
+ } & {
132
+ [K in string]: AnyWgslData;
133
+ };
69
134
  };
70
135
  fragment: {
71
- args: Wgsl[];
72
- code: Wgsl;
73
- output: Wgsl;
136
+ code: WgslCode | BoundWgslCode;
74
137
  target: Iterable<GPUColorTargetState | null>;
75
138
  };
76
139
  primitive: GPUPrimitiveState;
77
140
  externalLayouts?: GPUBindGroupLayout[];
78
- externalDeclarations?: Wgsl[];
79
141
  label?: string;
80
142
  }
81
143
  interface ComputePipelineOptions {
144
+ code: WgslCode | BoundWgslCode;
82
145
  workgroupSize?: readonly [number, number?, number?];
83
- args?: Wgsl[];
84
- code: Wgsl;
85
146
  externalLayouts?: GPUBindGroupLayout[];
86
- externalDeclarations?: Wgsl[];
87
147
  label?: string;
88
148
  }
89
149
  type RenderPipelineExecutorOptions = GPURenderPassDescriptor & {
@@ -92,7 +152,6 @@ type RenderPipelineExecutorOptions = GPURenderPassDescriptor & {
92
152
  firstVertex?: number;
93
153
  firstInstance?: number;
94
154
  externalBindGroups?: GPUBindGroup[];
95
- externalVertexBuffers?: GPUBuffer[];
96
155
  };
97
156
  interface RenderPipelineExecutor {
98
157
  execute(options: RenderPipelineExecutorOptions): void;
@@ -104,6 +163,7 @@ type ComputePipelineExecutorOptions = {
104
163
  interface ComputePipelineExecutor {
105
164
  execute(options?: ComputePipelineExecutorOptions): void;
106
165
  }
166
+ declare function deriveVertexFormat<TData extends SimpleWgslData<AnySchema>>(typeSchema: TData): GPUVertexFormat;
107
167
 
108
168
  interface NameRegistry {
109
169
  nameFor(item: WgslResolvable): string;
@@ -140,33 +200,30 @@ declare class ProgramBuilder {
140
200
  build(options: BuildOptions): Program;
141
201
  }
142
202
 
203
+ type VariableScope = 'private' | 'workgroup';
143
204
  interface WgslVar<TDataType extends AnyWgslData> extends WgslResolvable {
144
205
  $name(label: string): WgslVar<TDataType>;
145
206
  }
146
207
 
147
- interface WgslBufferUsage<TData extends AnyWgslData, TUsage extends BufferUsage> extends WgslBindable<TData, TUsage> {
208
+ interface WgslBufferUsage<TData extends AnyWgslData, TUsage extends BufferUsage = BufferUsage> extends WgslBindable<TData, TUsage> {
148
209
  $name(label: string): WgslBufferUsage<TData, TUsage>;
149
210
  }
150
211
 
212
+ type UsageGuard<TUsage extends BufferUsage, TData extends AnyWgslData, TAllows> = TUsage extends TAllows ? WgslBufferUsage<TData, TUsage> : null;
151
213
  interface WgslBuffer<TData extends AnyWgslData, TAllows extends BufferUsage = never> extends WgslAllocatable<TData> {
152
214
  $name(label: string): WgslBuffer<TData, TAllows>;
153
215
  $allowUniform(): WgslBuffer<TData, TAllows | 'uniform'>;
154
- $allowReadonlyStorage(): WgslBuffer<TData, TAllows | 'readonly_storage'>;
155
- $allowMutableStorage(): WgslBuffer<TData, TAllows | 'mutable_storage'>;
216
+ $allowReadonly(): WgslBuffer<TData, TAllows | 'readonly'>;
217
+ $allowMutable(): WgslBuffer<TData, TAllows | 'mutable'>;
218
+ $allowVertex(stepMode: 'vertex' | 'instance'): WgslBuffer<TData, TAllows | 'vertex'>;
156
219
  $addFlags(flags: GPUBufferUsageFlags): WgslBuffer<TData, TAllows>;
157
- asUniform(): 'uniform' extends TAllows ? WgslBufferUsage<TData, 'uniform'> : null;
158
- asMutableStorage(): 'mutable_storage' extends TAllows ? WgslBufferUsage<TData, 'mutable_storage'> : null;
159
- asReadonlyStorage(): 'readonly_storage' extends TAllows ? WgslBufferUsage<TData, 'readonly_storage'> : null;
220
+ asUniform(): UsageGuard<'uniform', TData, TAllows>;
221
+ asMutable(): UsageGuard<'mutable', TData, TAllows>;
222
+ asReadonly(): UsageGuard<'readonly', TData, TAllows>;
223
+ asVertex(): UsageGuard<'vertex', TData, TAllows>;
160
224
  }
161
225
  declare function buffer<TData extends AnyWgslData, TUsage extends BufferUsage = never>(typeSchema: TData, initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined): WgslBuffer<TData, TUsage>;
162
226
 
163
- interface WgslCode extends WgslResolvable {
164
- $name(label?: string | undefined): WgslCode;
165
- with<T>(slot: WgslSlot<T>, value: Eventual<T>): BoundWgslCode;
166
- }
167
- type BoundWgslCode = Omit<WgslCode, '$name'>;
168
- declare function code(strings: TemplateStringsArray, ...params: (Wgsl | Wgsl[] | InlineResolve)[]): WgslCode;
169
-
170
227
  interface WgslConst extends WgslResolvable {
171
228
  $name(label: string): WgslConst;
172
229
  }
@@ -232,7 +289,26 @@ declare const _default: typeof code & {
232
289
  slot: typeof slot;
233
290
  constant: typeof constant;
234
291
  declare: typeof declare;
235
- var: <TDataType extends AnyWgslData>(dataType: TDataType, initialValue?: Wgsl) => WgslVar<TDataType>;
292
+ var: <TDataType extends AnyWgslData>(dataType: TDataType, initialValue?: Wgsl, scope?: VariableScope) => WgslVar<TDataType>;
293
+ sampler: typeof sampler;
294
+ texture: typeof texture;
295
+ textureExternal: typeof textureExternal;
296
+ builtin: {
297
+ readonly vertexIndex: symbol;
298
+ readonly instanceIndex: symbol;
299
+ readonly position: symbol;
300
+ readonly clipDistances: symbol;
301
+ readonly frontFacing: symbol;
302
+ readonly fragDepth: symbol;
303
+ readonly sampleIndex: symbol;
304
+ readonly sampleMask: symbol;
305
+ readonly fragment: symbol;
306
+ readonly localInvocationId: symbol;
307
+ readonly localInvocationIndex: symbol;
308
+ readonly globalInvocationId: symbol;
309
+ readonly workgroupId: symbol;
310
+ readonly numWorkgroups: symbol;
311
+ };
236
312
  };
237
313
 
238
314
  /**
@@ -269,4 +345,4 @@ type CreateRuntimeOptions = {
269
345
  */
270
346
  declare function createRuntime(options?: CreateRuntimeOptions | GPUDevice): Promise<TypeGpuRuntime>;
271
347
 
272
- export { AnyWgslData, type AsCallable, BufferUsage, type ComputePipelineExecutor, type ComputePipelineExecutorOptions, type ComputePipelineOptions, type CreateRuntimeOptions, Eventual, type ICallable, InlineResolve, MissingSlotValueError, type Program, ProgramBuilder, RandomNameRegistry, RecursiveDataTypeError, type RenderPipelineExecutor, type RenderPipelineExecutorOptions, type RenderPipelineOptions, ResolutionCtx, ResolutionError, StrictNameRegistry, type TypeGpuRuntime, Wgsl, WgslAllocatable, WgslBindable, type WgslBuffer, type WgslCode, type WgslConst, type WgslFn$1 as WgslFn, WgslFnArgument, type WgslFn as WgslFnExperimental, WgslPlum, WgslResolvable, WgslResolvableSlot, WgslSettable, WgslSlot, WgslValue, type WgslVar, createRuntime, _default as wgsl };
348
+ export { AnyWgslData, AnyWgslPrimitive, AnyWgslTexelFormat, type AsCallable, BufferUsage, type ComputePipelineExecutor, type ComputePipelineExecutorOptions, type ComputePipelineOptions, type CreateRuntimeOptions, Eventual, type ICallable, InlineResolve, MissingSlotValueError, type Program, ProgramBuilder, RandomNameRegistry, RecursiveDataTypeError, type RenderPipelineExecutor, type RenderPipelineExecutorOptions, type RenderPipelineOptions, ResolutionCtx, ResolutionError, SampledTextureParams, type SetPlumAction, StorageTextureAccess, StorageTextureParams, StrictNameRegistry, TextureUsage, type TypeGpuRuntime, Wgsl, WgslAllocatable, WgslBindable, type WgslBuffer, type WgslBufferUsage, type WgslCode, type WgslConst, type WgslFn$1 as WgslFn, WgslFnArgument, type WgslFn as WgslFnExperimental, WgslPlum, WgslRenderResource, WgslRenderResourceType, WgslResolvable, WgslResolvableSlot, type WgslSampler, WgslSettable, WgslSlot, type WgslTexture, type WgslTextureView, WgslValue, type WgslVar, createRuntime, deriveVertexFormat, _default as wgsl };
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { W as WgslResolvable, a as WgslSlot, b as WgslPlum, E as ExtractPlumValue, c as WgslSettable, U as Unsubscribe, A as AnyWgslData, d as WgslAllocatable, e as Wgsl, B as BufferUsage, f as WgslBindable, g as Eventual, I as InlineResolve, h as WgslFnArgument, R as ResolutionCtx, i as WgslValue, j as WgslIdentifier, k as WgslResolvableSlot, p as plum, l as plumFromEvent } from './types-DeF6xFAt.js';
2
- export { t as AnyWgslPointer, q as EventualGetter, S as SlotValuePair, r as WgslData, s as WgslPointer, u as isPointer, m as isResolvable, o as isSlot, n as isWgsl } from './types-DeF6xFAt.js';
3
- import { Parsed } from 'typed-binary';
4
- import { W as WgslStruct } from './struct-udnQvwHG.js';
1
+ import { W as WgslResolvable, a as WgslSlot, E as Eventual, b as Wgsl, I as InlineResolve, c as WgslRenderResource, T as TextureUsage, S as StorageTextureParams, A as AnyWgslTexelFormat, d as SampledTextureParams, e as AnyWgslPrimitive, f as WgslRenderResourceType, g as StorageTextureAccess, R as ResolutionCtx, h as WgslPlum, i as ExtractPlumValue, j as WgslSettable, U as Unsubscribe, k as AnyWgslData, l as WgslAllocatable, B as BufferUsage, m as WgslBindable, n as WgslFnArgument, o as WgslValue, p as WgslIdentifier, q as WgslResolvableSlot, r as plum, s as plumFromEvent } from './types-ENDwr_p9.js';
2
+ export { O as AnyWgslPointer, Q as BuiltInPossibleTypes, X as Builtin, w as EventualGetter, x as SlotValuePair, M as WgslData, C as WgslDepthTextureType, F as WgslExternalTextureType, N as WgslPointer, y as WgslSamplerType, D as WgslStorageTextureType, z as WgslTypedTextureType, V as builtin, Y as getBuiltinInfo, Z as getUsedBuiltinsNamed, J as isDepthTextureType, L as isExternalTextureType, P as isPointer, t as isResolvable, G as isSamplerType, v as isSlot, K as isStorageTextureType, H as isTypedTextureType, u as isWgsl } from './types-ENDwr_p9.js';
3
+ import { Parsed, AnySchema } from 'typed-binary';
4
+ import { S as SimpleWgslData } from './std140-Cv7GDE9w.js';
5
5
 
6
6
  /**
7
7
  * An error that happens during resolution of WGSL code.
@@ -38,6 +38,65 @@ declare abstract class Callable<TArgs extends [...any[]], TReturn> extends Funct
38
38
  type ICallable<TArgs extends [...any[]], TReturn> = (...args: TArgs) => TReturn;
39
39
  type AsCallable<T, TArgs extends [...any[]], TReturn> = T & ICallable<TArgs, TReturn>;
40
40
 
41
+ type PlumListener<T> = (newValue: T) => unknown;
42
+
43
+ interface WgslCode extends WgslResolvable {
44
+ $name(label?: string | undefined): WgslCode;
45
+ with<T>(slot: WgslSlot<T>, value: Eventual<T>): BoundWgslCode;
46
+ }
47
+ type BoundWgslCode = Omit<WgslCode, '$name'>;
48
+ declare function code(strings: TemplateStringsArray, ...params: (Wgsl | Wgsl[] | InlineResolve)[]): WgslCode;
49
+
50
+ interface WgslSampler extends WgslRenderResource {
51
+ readonly descriptor: GPUSamplerDescriptor;
52
+ $name(label: string): WgslSampler;
53
+ }
54
+ declare function sampler(descriptor: GPUSamplerDescriptor): WgslSampler;
55
+
56
+ interface WgslAnyTextureView extends WgslRenderResource {
57
+ readonly descriptor: GPUTextureViewDescriptor;
58
+ readonly texture: WgslAnyTexture;
59
+ readonly dataType: AnyWgslPrimitive | AnyWgslTexelFormat;
60
+ readonly access: StorageTextureAccess | undefined;
61
+ }
62
+ interface WgslAnyTexture {
63
+ readonly descriptor: Omit<GPUTextureDescriptor, 'usage'>;
64
+ get flags(): GPUTextureUsageFlags;
65
+ }
66
+ interface WgslTexture<TAllows extends TextureUsage = never> {
67
+ readonly descriptor: Omit<GPUTextureDescriptor, 'usage'>;
68
+ get label(): string | undefined;
69
+ get flags(): GPUTextureUsageFlags;
70
+ $name(label: string): WgslTexture<TAllows>;
71
+ $allowSampled(): WgslTexture<TAllows | 'sampled'>;
72
+ $allowStorage(): WgslTexture<TAllows | 'storage'>;
73
+ asStorage(params: StorageTextureParams): 'storage' extends TAllows ? WgslTextureView<AnyWgslTexelFormat, 'storage'> : null;
74
+ asSampled(params: SampledTextureParams): 'sampled' extends TAllows ? WgslTextureView<typeof params.dataType, 'sampled'> : null;
75
+ }
76
+ interface WgslTextureView<TData extends AnyWgslPrimitive | AnyWgslTexelFormat, TUsage extends TextureUsage> extends WgslRenderResource {
77
+ readonly texture: WgslTexture<TUsage>;
78
+ readonly descriptor: Omit<GPUTextureViewDescriptor, 'usage'>;
79
+ readonly type: WgslRenderResourceType;
80
+ readonly dataType: TData;
81
+ readonly access: StorageTextureAccess | undefined;
82
+ $name(label: string): WgslTextureView<TData, TUsage>;
83
+ }
84
+ interface WgslTextureExternal extends WgslRenderResource {
85
+ readonly descriptor: GPUExternalTextureDescriptor;
86
+ }
87
+ declare function texture<TUsage extends TextureUsage = never>(descriptor: Omit<GPUTextureDescriptor, 'usage'>): WgslTexture<TUsage>;
88
+ declare function textureExternal(descriptor: GPUExternalTextureDescriptor): WgslTextureExternalImpl;
89
+ declare class WgslTextureExternalImpl implements WgslTextureExternal {
90
+ readonly descriptor: GPUExternalTextureDescriptor;
91
+ private _label;
92
+ readonly type = "texture_external";
93
+ constructor(descriptor: GPUExternalTextureDescriptor);
94
+ get label(): string | undefined;
95
+ $name(label: string | undefined): this;
96
+ resolve(ctx: ResolutionCtx): string;
97
+ }
98
+
99
+ type SetPlumAction<T> = T | ((prev: T) => T);
41
100
  interface TypeGpuRuntime {
42
101
  readonly device: GPUDevice;
43
102
  /**
@@ -46,11 +105,15 @@ interface TypeGpuRuntime {
46
105
  */
47
106
  readonly commandEncoder: GPUCommandEncoder;
48
107
  readPlum<TPlum extends WgslPlum>(plum: TPlum): ExtractPlumValue<TPlum>;
49
- setPlum<TPlum extends WgslPlum & WgslSettable>(plum: TPlum, value: ExtractPlumValue<TPlum>): void;
50
- onPlumChange<TValue>(plum: WgslPlum<TValue>, listener: () => unknown): Unsubscribe;
108
+ setPlum<TPlum extends WgslPlum & WgslSettable>(plum: TPlum, value: SetPlumAction<ExtractPlumValue<TPlum>>): void;
109
+ onPlumChange<TValue>(plum: WgslPlum<TValue>, listener: PlumListener<TValue>): Unsubscribe;
51
110
  writeBuffer<TValue extends AnyWgslData>(allocatable: WgslAllocatable<TValue>, data: Parsed<TValue>): void;
52
111
  readBuffer<TData extends AnyWgslData>(allocatable: WgslAllocatable<TData>): Promise<Parsed<TData>>;
53
112
  bufferFor(allocatable: WgslAllocatable): GPUBuffer;
113
+ textureFor(view: WgslAnyTexture | WgslAnyTextureView): GPUTexture;
114
+ viewFor(view: WgslAnyTextureView): GPUTextureView;
115
+ externalTextureFor(texture: WgslTextureExternal): GPUExternalTexture;
116
+ samplerFor(sampler: WgslSampler): GPUSampler;
54
117
  dispose(): void;
55
118
  /**
56
119
  * Causes all commands enqueued by pipelines to be
@@ -62,28 +125,25 @@ interface TypeGpuRuntime {
62
125
  }
63
126
  interface RenderPipelineOptions {
64
127
  vertex: {
65
- args: Wgsl[];
66
- code: Wgsl;
67
- output: WgslStruct<Record<string, AnyWgslData>>;
68
- buffersLayouts?: Iterable<GPUVertexBufferLayout | null>;
128
+ code: WgslCode | BoundWgslCode;
129
+ output: {
130
+ [K in symbol]: string;
131
+ } & {
132
+ [K in string]: AnyWgslData;
133
+ };
69
134
  };
70
135
  fragment: {
71
- args: Wgsl[];
72
- code: Wgsl;
73
- output: Wgsl;
136
+ code: WgslCode | BoundWgslCode;
74
137
  target: Iterable<GPUColorTargetState | null>;
75
138
  };
76
139
  primitive: GPUPrimitiveState;
77
140
  externalLayouts?: GPUBindGroupLayout[];
78
- externalDeclarations?: Wgsl[];
79
141
  label?: string;
80
142
  }
81
143
  interface ComputePipelineOptions {
144
+ code: WgslCode | BoundWgslCode;
82
145
  workgroupSize?: readonly [number, number?, number?];
83
- args?: Wgsl[];
84
- code: Wgsl;
85
146
  externalLayouts?: GPUBindGroupLayout[];
86
- externalDeclarations?: Wgsl[];
87
147
  label?: string;
88
148
  }
89
149
  type RenderPipelineExecutorOptions = GPURenderPassDescriptor & {
@@ -92,7 +152,6 @@ type RenderPipelineExecutorOptions = GPURenderPassDescriptor & {
92
152
  firstVertex?: number;
93
153
  firstInstance?: number;
94
154
  externalBindGroups?: GPUBindGroup[];
95
- externalVertexBuffers?: GPUBuffer[];
96
155
  };
97
156
  interface RenderPipelineExecutor {
98
157
  execute(options: RenderPipelineExecutorOptions): void;
@@ -104,6 +163,7 @@ type ComputePipelineExecutorOptions = {
104
163
  interface ComputePipelineExecutor {
105
164
  execute(options?: ComputePipelineExecutorOptions): void;
106
165
  }
166
+ declare function deriveVertexFormat<TData extends SimpleWgslData<AnySchema>>(typeSchema: TData): GPUVertexFormat;
107
167
 
108
168
  interface NameRegistry {
109
169
  nameFor(item: WgslResolvable): string;
@@ -140,33 +200,30 @@ declare class ProgramBuilder {
140
200
  build(options: BuildOptions): Program;
141
201
  }
142
202
 
203
+ type VariableScope = 'private' | 'workgroup';
143
204
  interface WgslVar<TDataType extends AnyWgslData> extends WgslResolvable {
144
205
  $name(label: string): WgslVar<TDataType>;
145
206
  }
146
207
 
147
- interface WgslBufferUsage<TData extends AnyWgslData, TUsage extends BufferUsage> extends WgslBindable<TData, TUsage> {
208
+ interface WgslBufferUsage<TData extends AnyWgslData, TUsage extends BufferUsage = BufferUsage> extends WgslBindable<TData, TUsage> {
148
209
  $name(label: string): WgslBufferUsage<TData, TUsage>;
149
210
  }
150
211
 
212
+ type UsageGuard<TUsage extends BufferUsage, TData extends AnyWgslData, TAllows> = TUsage extends TAllows ? WgslBufferUsage<TData, TUsage> : null;
151
213
  interface WgslBuffer<TData extends AnyWgslData, TAllows extends BufferUsage = never> extends WgslAllocatable<TData> {
152
214
  $name(label: string): WgslBuffer<TData, TAllows>;
153
215
  $allowUniform(): WgslBuffer<TData, TAllows | 'uniform'>;
154
- $allowReadonlyStorage(): WgslBuffer<TData, TAllows | 'readonly_storage'>;
155
- $allowMutableStorage(): WgslBuffer<TData, TAllows | 'mutable_storage'>;
216
+ $allowReadonly(): WgslBuffer<TData, TAllows | 'readonly'>;
217
+ $allowMutable(): WgslBuffer<TData, TAllows | 'mutable'>;
218
+ $allowVertex(stepMode: 'vertex' | 'instance'): WgslBuffer<TData, TAllows | 'vertex'>;
156
219
  $addFlags(flags: GPUBufferUsageFlags): WgslBuffer<TData, TAllows>;
157
- asUniform(): 'uniform' extends TAllows ? WgslBufferUsage<TData, 'uniform'> : null;
158
- asMutableStorage(): 'mutable_storage' extends TAllows ? WgslBufferUsage<TData, 'mutable_storage'> : null;
159
- asReadonlyStorage(): 'readonly_storage' extends TAllows ? WgslBufferUsage<TData, 'readonly_storage'> : null;
220
+ asUniform(): UsageGuard<'uniform', TData, TAllows>;
221
+ asMutable(): UsageGuard<'mutable', TData, TAllows>;
222
+ asReadonly(): UsageGuard<'readonly', TData, TAllows>;
223
+ asVertex(): UsageGuard<'vertex', TData, TAllows>;
160
224
  }
161
225
  declare function buffer<TData extends AnyWgslData, TUsage extends BufferUsage = never>(typeSchema: TData, initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined): WgslBuffer<TData, TUsage>;
162
226
 
163
- interface WgslCode extends WgslResolvable {
164
- $name(label?: string | undefined): WgslCode;
165
- with<T>(slot: WgslSlot<T>, value: Eventual<T>): BoundWgslCode;
166
- }
167
- type BoundWgslCode = Omit<WgslCode, '$name'>;
168
- declare function code(strings: TemplateStringsArray, ...params: (Wgsl | Wgsl[] | InlineResolve)[]): WgslCode;
169
-
170
227
  interface WgslConst extends WgslResolvable {
171
228
  $name(label: string): WgslConst;
172
229
  }
@@ -232,7 +289,26 @@ declare const _default: typeof code & {
232
289
  slot: typeof slot;
233
290
  constant: typeof constant;
234
291
  declare: typeof declare;
235
- var: <TDataType extends AnyWgslData>(dataType: TDataType, initialValue?: Wgsl) => WgslVar<TDataType>;
292
+ var: <TDataType extends AnyWgslData>(dataType: TDataType, initialValue?: Wgsl, scope?: VariableScope) => WgslVar<TDataType>;
293
+ sampler: typeof sampler;
294
+ texture: typeof texture;
295
+ textureExternal: typeof textureExternal;
296
+ builtin: {
297
+ readonly vertexIndex: symbol;
298
+ readonly instanceIndex: symbol;
299
+ readonly position: symbol;
300
+ readonly clipDistances: symbol;
301
+ readonly frontFacing: symbol;
302
+ readonly fragDepth: symbol;
303
+ readonly sampleIndex: symbol;
304
+ readonly sampleMask: symbol;
305
+ readonly fragment: symbol;
306
+ readonly localInvocationId: symbol;
307
+ readonly localInvocationIndex: symbol;
308
+ readonly globalInvocationId: symbol;
309
+ readonly workgroupId: symbol;
310
+ readonly numWorkgroups: symbol;
311
+ };
236
312
  };
237
313
 
238
314
  /**
@@ -269,4 +345,4 @@ type CreateRuntimeOptions = {
269
345
  */
270
346
  declare function createRuntime(options?: CreateRuntimeOptions | GPUDevice): Promise<TypeGpuRuntime>;
271
347
 
272
- export { AnyWgslData, type AsCallable, BufferUsage, type ComputePipelineExecutor, type ComputePipelineExecutorOptions, type ComputePipelineOptions, type CreateRuntimeOptions, Eventual, type ICallable, InlineResolve, MissingSlotValueError, type Program, ProgramBuilder, RandomNameRegistry, RecursiveDataTypeError, type RenderPipelineExecutor, type RenderPipelineExecutorOptions, type RenderPipelineOptions, ResolutionCtx, ResolutionError, StrictNameRegistry, type TypeGpuRuntime, Wgsl, WgslAllocatable, WgslBindable, type WgslBuffer, type WgslCode, type WgslConst, type WgslFn$1 as WgslFn, WgslFnArgument, type WgslFn as WgslFnExperimental, WgslPlum, WgslResolvable, WgslResolvableSlot, WgslSettable, WgslSlot, WgslValue, type WgslVar, createRuntime, _default as wgsl };
348
+ export { AnyWgslData, AnyWgslPrimitive, AnyWgslTexelFormat, type AsCallable, BufferUsage, type ComputePipelineExecutor, type ComputePipelineExecutorOptions, type ComputePipelineOptions, type CreateRuntimeOptions, Eventual, type ICallable, InlineResolve, MissingSlotValueError, type Program, ProgramBuilder, RandomNameRegistry, RecursiveDataTypeError, type RenderPipelineExecutor, type RenderPipelineExecutorOptions, type RenderPipelineOptions, ResolutionCtx, ResolutionError, SampledTextureParams, type SetPlumAction, StorageTextureAccess, StorageTextureParams, StrictNameRegistry, TextureUsage, type TypeGpuRuntime, Wgsl, WgslAllocatable, WgslBindable, type WgslBuffer, type WgslBufferUsage, type WgslCode, type WgslConst, type WgslFn$1 as WgslFn, WgslFnArgument, type WgslFn as WgslFnExperimental, WgslPlum, WgslRenderResource, WgslRenderResourceType, WgslResolvable, WgslResolvableSlot, type WgslSampler, WgslSettable, WgslSlot, type WgslTexture, type WgslTextureView, WgslValue, type WgslVar, createRuntime, deriveVertexFormat, _default as wgsl };