-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAPI.wit
689 lines (579 loc) · 12.9 KB
/
API.wit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
// mugl WebAssembly API spec
// This can be used to generate a binding, by e.g. https://bytecodealliance.github.io/wit-bindgen/
interface mugl {
/**
* Frees context memory.
*/
free-context: func(c: context)
/**
* Gets the status of a future.
*/
get-future-status: func(f: future-handle) -> future-status
/**
* Gets the resolved value of a future.
*/
get-future-value: func(f: future-handle) -> future-value
/**
* Gets an image handle by ID.
*/
get-image-by-id: func(c: context, id: string) -> image
/**
* Deletes an image handle.
*/
delete-image: func(img: image)
/**
* Gets a canvas handle by ID.
*/
get-canvas-by-id: func(c: context, id: string) -> canvas
/**
* Gets the width of the given canvas.
*/
get-canvas-width: func(c: canvas) -> u32
/**
* Gets the height of the given canvas.
*/
get-canvas-height: func(c: canvas) -> u32
/**
* Deletes a canvas handle.
*/
delete-canvas: func(c: canvas)
/**
* Requests a WebGPU GPU device.
*/
webgpu-request-device: func(c: canvas, options: webgpu-context-attributes, features: u32) -> device
/**
* Creates a WebGPU surface texture.
*/
webgpu-create-surface-texture: func(d: device, c: canvas, options: webgpu-context-attributes) -> texture
/**
* Creates a WebGPU surface depth-stencil texture.
*/
webgpu-create-surface-depth-texture: func(d: device, c: canvas, options: webgpu-context-attributes) -> texture
/**
* Requests a WebGL2 GPU device.
*/
webgl-request-device: func(c: canvas, options: webgl-context-attributes, features: u32) -> device
/**
* Generates mipmap for a WebGL texture.
*/
webgl-generate-mipmap: func(d: device, t: texture, hint: u32)
/**
* Flushes the command buffer.
*/
flush: func(d: device)
/**
* Resets the state of a GPU device.
*/
reset-device: func(d: device)
/**
* Deletes a GPU device.
*/
delete-device: func(d: device)
/**
* Gets if device context is lost.
*/
is-device-lost: func(d: device) -> bool
/**
* Gets the enabled features of the device.
*/
get-device-features: func(d: device) -> u32
/**
* Creates a GPU buffer.
*/
create-buffer: func(d: device, desc: buffer-descriptor) -> buffer
/**
* Deletes a GPU buffer.
*/
delete-buffer: func(b: buffer)
/**
* Creates a GPU texture.
*/
create-texture: func(d: device, desc: texture-descriptor) -> texture
/**
* Deletes a GPU texture.
*/
delete-texture: func(o: texture)
/**
* Creates a GPU texture sampler.
*/
create-sampler: func(t: device, desc: sampler-descriptor) -> sampler
/**
* Deletes a GPU texture sampler.
*/
delete-sampler: func(s: sampler)
/**
* Creates a GPU shader module.
*/
create-shader: func(d: device, desc: shader-descriptor) -> shader
/**
* Deletes a GPU shader module.
*/
delete-shader: func(s: shader)
/**
* Creates a GPU bind group layout object.
*/
create-bind-group-layout: func(d: device, desc: bind-group-layout-descriptor) -> bind-group-layout
/**
* Deletes a GPU bind group layout.
*/
delete-bind-group-layout: func(b: bind-group-layout)
/**
* Creates a GPU bind group.
*/
create-bind-group: func(d: device, desc: bind-group-descriptor) -> bind-group
/**
* Deletes a GPU bind group.
*/
delete-bind-group: func(b: bind-group)
/**
* Creates a GPU render pipeline.
*/
create-render-pipeline: func(d: device, desc: render-pipeline-descriptor) -> render-pipeline
/**
* Deletes a GPU render pipeline.
*/
delete-render-pipeline: func(p: render-pipeline)
/**
* Creates a GPU render pass.
*/
create-render-pass: func(d: device, desc: render-pass-descriptor) -> render-pass
/**
* Deletes a GPU render pass.
*/
delete-render-pass: func(p: render-pass)
/**
* Reads data from a GPU buffer.
*/
read-buffer: func(d: device, buf: buffer, offset: u32, out: list<u8>) -> future-handle
/**
* Writes data to a GPU buffer.
*/
write-buffer: func(d: device, buf: buffer, data: list<u8>, offset: u32)
/**
* Copies data from a GPU buffer to another buffer.
*/
copy-buffer: func(d: device, src: buffer, dst: buffer, size: u32, src-offset: u32, dst-offset: u32)
/**
* Writes subregion of data array to a GPU texture.
*/
write-texture: func(d: device, texture: image-copy-texture, data: list<u8>, layout: image-data-layout, size: extent3d)
/**
* Uploads an image subregion to a GPU texture.
*/
copy-external-image-to-texture: func(d: device, src: image-copy-external-image, dst: image-copy-texture, size: extent2d)
/**
* Copies subregion of a GPU texture to another texture.
*/
copy-texture: func(d: device, src: image-copy-texture, dst: image-copy-texture, size: extent3d)
/**
* Copies subregion of a GPU texture to a GPU buffer.
*/
copy-texture-to-buffer: func(d: device, src: image-copy-texture, dst: buffer, layout: image-data-layout, size: extent3d)
/**
* Begins a render pass.
*/
begin-render-pass: func(d: device, pass: render-pass)
/**
* Submits the current render pass.
*/
submit-render-pass: func(d: device)
/**
* Binds a render pipeline to the current render pass.
*/
set-render-pipeline: func(d: device, pipeline: render-pipeline)
/**
* Binds an index buffer to the current render pass.
*/
set-index: func(d: device, buf: buffer)
/**
* Binds a vertex buffer to a slot in the current render pass.
*/
set-vertex: func(d: device, slot: u32, buf: buffer, offset: u32)
/**
* Binds a bind group to the current render pass.
*/
set-bind-group: func(d: device, slot: u32, bindings: bind-group, offsets: list<u32>)
/**
* Submits a draw call in the current render pass.
*/
draw: func(d: device, vertex-count: u32, instance-count: u32, first-vertex: u32, first-instance: u32)
/**
* Submits an indexed draw call in the current render pass.
*/
draw-indexed: func(d: device, index-count: u32, instance-count: u32, first-index: u32, first-instance: u32)
/**
* Sets the 3D viewport area for the current render pass.
*/
set-viewport: func(d: device, x: u32, y: u32, width: u32, height: u32, min-depth: float32, max-depth: float32)
/**
* Sets the scissor rectangle for the current render pass.
*/
set-scissor-rect: func(d: device, x: u32, y: u32, width: u32, height: u32)
/**
* Sets the blend-constant color for the current render pass.
*/
set-blend-const: func(d: device, c: color)
/**
* Sets the stencil reference value for the current render pass.
*/
set-stencil-ref: func(d: device, ref: u32)
/**
* A 2D extent.
*/
type extent2d = tuple<u32, u32>
/**
* A 3D extent.
*/
type extent3d = tuple<u32, u32, u32>
/**
* A 2D origin.
*/
type origin2d = tuple<u32, u32>
/**
* A 3D origin.
*/
type origin3d = tuple<u32, u32, u32>
/**
* A RGBA color.
*/
type color = tuple<float32, float32, float32, float32>
/**
* WebGL context attribute flags.
*/
flags webgl-context-attributes {
alpha,
antialias,
depth,
desynchronized,
fail-if-major-performance-caveat,
high-performance,
premultiplied-alpha,
preserve-drawing-buffer,
stencil,
}
/**
* WebGPU context attribute flags.
*/
flags webgpu-context-attributes {
depth,
depth32f,
force-fallback-adapter,
high-performance,
multisampled,
premultiplied-alpha,
stencil,
}
/**
* Status of a future.
*/
enum future-status {
pending,
done,
error
}
/**
* A context ID.
*/
type context = float64
/**
* A resolvable future object.
*/
type future-handle = float64
/**
* Handle to future value.
*/
type future-value = float64
/**
* Handle to an external image.
*/
type image = float64
/**
* Handle to a canvas.
*/
type canvas = float64
/**
* Handle to a GPU device.
*/
type device = float64
/**
* Handle to a GPU buffer.
*/
type buffer = float64
/**
* Handle to a GPU texture.
*/
type texture = float64
/**
* Handle to a GPU sampler.
*/
type sampler = float64
/**
* Handle to a GPU shader.
*/
type shader = float64
/**
* Handle to a GPU bind group layout.
*/
type bind-group-layout = float64
/**
* Handle to a GPU bind group.
*/
type bind-group = float64
/**
* Handle to a GPU render pipeline.
*/
type render-pipeline = float64
/**
* Handle to a GPU render pass.
*/
type render-pass = float64
/**
* Descriptor of a buffer.
*/
record buffer-descriptor {
size: u32,
usage: u32,
}
/**
* Descriptor of a texture.
*/
record texture-descriptor {
size: extent3d,
mip-level-count: u32,
sample-count: u32,
dimension: u32,
format: u32,
usage: u32,
}
/**
* Defines a texture subview.
*/
record texture-view {
tex: texture,
mip-level: u32,
slice: u32,
}
/**
* Defines the texture with origin offset for a texture write operation.
*/
record image-copy-texture {
tex: texture,
mip-level: u32,
origin: origin3d,
}
/**
* Defines the source image with origin offset to be copied into a texture.
*/
record image-copy-external-image {
img: image,
origin: origin2d,
}
/**
* Defines the layout of a texture image buffer data for a texture write.
*/
record image-data-layout {
offset: u32,
bytes-per-row: u32,
rows-per-image: u32,
}
/**
* Descriptor of a sampler.
*/
record sampler-descriptor {
address-mode-u: u32,
address-mode-v: u32,
address-mode-w: u32,
mag-filter: u32,
min-filter: u32,
mipmap-filter: u32,
lod-min-clamp: float32,
lod-max-clamp: float32,
compare: u32,
max-anisotropy: u32
}
/**
* Descriptor of a shader.
*/
record shader-descriptor {
code: string,
usage: u32,
}
/**
* Descriptor of a bind group layout.
*/
record bind-group-layout-descriptor {
entries: list<bind-group-layout-entry>,
}
/**
* Descriptor of a bind group layout entry.
*/
record bind-group-layout-entry {
label: string,
binding: u32,
visibility: u32,
ty: binding-type,
}
/**
* Type of binding.
*/
variant binding-type {
/// Buffer binding with optional dynamic offset
buffer(bool),
/// A type of sampler binding
sampler(u32),
/// texture binding type, dimension and multisampling
texture(tuple<u32, u32, bool>),
}
/**
* Descriptor of a bind group.
*/
record bind-group-descriptor {
layout: bind-group-layout,
entries: list<bind-group-entry>,
}
/**
* Descriptor of a bind group entry.
*/
record bind-group-entry {
binding: u32,
res: binding-resource,
}
/**
* A binding resource.
*/
variant binding-resource {
/// Buffer binding with offset and size
buffer(tuple<buffer, u32, u32>),
/// Sampler binding
sampler(sampler),
/// Texture binding
texture(texture),
}
/**
* Descriptor of a render pass.
*/
record render-pass-descriptor {
clear: render-pass-operation,
depth-stencil: option<texture-view>,
colors: list<color-attachment>,
}
/**
* Descriptor of the clear operations of a default render pass.
*/
record render-pass-operation {
clear-depth: float32,
clear-stencil: float32,
clear-color: color,
}
/**
* Descriptor of a render pass color attachment.
*/
record color-attachment {
view: texture-view,
clear: color,
}
/**
* Descriptor of a render pipeline.
*/
record render-pipeline-descriptor {
vertex: shader,
fragment: shader,
attributes: list<vertex-attribute>,
buffers: list<vertex-buffer-layout>,
bind-groups: list<bind-group-layout>,
primitive: primitive-state,
multisample: multisample-state,
depth-stencil: option<depth-stencil-state>,
targets: color-target-states,
vertex-entry-point: string,
fragment-entry-point: string,
}
/**
* Descriptor of vertex buffer layout.
*/
record vertex-buffer-layout {
/// Specifies the slice (start index and length) of attributes list to use for this buffer.
attributes: tuple<u32, u32>,
stride: u32,
step-mode: u32,
}
/**
* Descriptor of vertex attribute.
*/
record vertex-attribute {
format: u32,
offset: u32,
shader-location: u32,
}
/**
* Descriptor of the states of color targets.
*/
record color-target-states {
targets: list<color-target-state>,
write-mask: u32,
blend: blend-state,
}
/**
* Descriptor of the state of a color target.
*/
record color-target-state {
format: u32,
write-mask: u32,
blend: blend-state,
}
/**
* Descriptor of the blend state of a color target.
*/
record blend-state {
color: blend-component,
alpha: blend-component,
}
/**
* Descriptor of the blend component state of a color target.
*/
record blend-component {
operation: u32,
src-factor: u32,
dst-factor: u32,
}
/**
* Descriptor of the primitive state.
*/
record primitive-state {
topology: u32,
index-format: u32,
front-face: u32,
cull-mode: u32,
}
/**
* Descriptor of the depth stencil state.
*/
record depth-stencil-state {
format: u32,
depth-write: bool,
depth-compare: u32,
stencil-front: stencl-face-state,
stencil-back: stencl-face-state,
stencil-read-mask: u32,
stencil-write-mask: u32,
depth-bias: float32,
depth-bias-slope-scale: float32,
depth-bias-clamp: float32,
}
/**
* Descriptor of the stencil face state.
*/
record stencl-face-state {
compare: u32,
fail-op: u32,
depth-fail-op: u32,
pass-op: u32,
}
/**
* Descriptor of render pipeline mutlisample state.
*/
record multisample-state {
sample-count: u32,
alpha-to-coverage: bool,
}
}