substrate-lang 0.10.0 → 0.10.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "substrate-lang",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "A Lisp for writing WebAssembly, and the substrate command that builds, runs and tests it",
5
5
  "license": "MIT",
6
6
  "repository": {
package/std/package.sub CHANGED
@@ -1,6 +1,6 @@
1
1
  (package std
2
- (version "0.10.0")
3
- (substrate "0.10.0")
2
+ (version "0.10.1")
3
+ (substrate "0.10.1")
4
4
  (exports archive/tar browser/chromium browser/devtools compress/deflate compress/gzip compress/inflate crypto/hmac
5
5
  crypto/password crypto/sha1
6
6
  crypto/sha256 crypto/sha512 doc/doc doc/html doc/root doc/text encoding/base64 encoding/json encoding/utf8
@@ -8,6 +8,7 @@
8
8
  http/route http/server http/session http/sse http/sse-client http/static http/test http/token http/url
9
9
  http/websocket log/log meta/derive meta/equal meta/method meta/type-info package/files package/hash
10
10
  package/manifest package/map package/pack package/path package/read package/site package/store test/browser
11
- test/build test/run test/session test/test vector/vector web/canvas web/dom web/gpu web/patches)
11
+ test/build test/run test/session test/test vector/vector web/canvas web/dom web/gpu web/gpu-commands
12
+ web/patches)
12
13
  (tests "tests/archive/*.sub" "tests/compress/*.sub" "tests/crypto/*.sub" "tests/encoding/*.sub" "tests/http/*.sub"
13
14
  "tests/log/*.sub" "tests/meta/*.sub" "tests/test/*.sub" "tests/vector/*.sub"))
@@ -15,7 +15,7 @@
15
15
  (define begun u32 0)
16
16
 
17
17
  (define (canvas-begin! [node u32])
18
- (words! (slice (array-of u32 13 node 0)))
18
+ (words! (slice (array-of u32 11 node 0)))
19
19
  (set! drawing (-> (dom-patches) length))
20
20
  (set! begun (dom-flushes)))
21
21
 
@@ -90,12 +90,12 @@
90
90
 
91
91
  (define next-image u32 1)
92
92
 
93
- (define (canvas-load-image! [path string]) -> u32
93
+ (define (canvas-load-image! [path string] [tag (ptr void)]) -> u32
94
94
  (if (canvas-drawing?)
95
95
  0
96
96
  (let ([id next-image])
97
97
  (+= next-image 1)
98
- (dom-image! id path)
98
+ (dom-image! id path tag)
99
99
  id)))
100
100
 
101
101
  (define (canvas-draw-sprite! [image u32] [cell-width f64] [cell-height f64] [frame u32] [x f64] [y f64] [flip bool])
package/std/web/dom.sub CHANGED
@@ -1,9 +1,25 @@
1
- ;; The page: the host module "dom" and the patches that patches.sub writes. dom-flush! sends the patches, and
2
- ;; dom-event-text and dom-event-truths read the current event.
1
+ ;; The page: the host module "dom" and the patches that patches.sub writes. dom-flush! sends the patches. A read takes a
2
+ ;; name that walks from a node, or from the current event, through the page's objects: a property's name, or names
3
+ ;; joined by dots. It gives a number, with true as 1, or text. The text lasts until the patches are sent. dom-is and
4
+ ;; dom-event-is also take a node, and say whether the name leads to it. (dom-is node dom-document "activeElement") says
5
+ ;; whether the node has the focus. dom-event-call calls a method of the current event.
3
6
  (require-unqualified host-dom host/web/dom)
4
7
  (require-unqualified patches "patches.sub")
5
8
 
6
- (provide (all-from-out host-dom) (all-from-out patches) dom-flush! dom-event-text dom-event-truths)
9
+ (provide (all-from-out host-dom) (all-from-out patches) dom-flush! dom-element dom-event-number dom-event-text
10
+ dom-event-call dom-event-is dom-read-number dom-read-text dom-is)
11
+
12
+ (import event-number "dom" "event_number" (i32 i32 -> f64))
13
+ (import event-text "dom" "event_text" (i32 i32 i32 -> i32))
14
+ (import event-call "dom" "event_call" (i32 i32 ->))
15
+ (import event-is "dom" "event_is" (i32 i32 i32 -> i32))
16
+ (import read-number "dom" "read_number" (i32 i32 i32 -> f64))
17
+ (import read-text "dom" "read_text" (i32 i32 i32 i32 -> i32))
18
+ (import is "dom" "is" (i32 i32 i32 i32 -> i32))
19
+
20
+ (define (dom-element [id string]) -> u32
21
+ (let ([n (dom-new-node!)])
22
+ (if (== (dom-bind-element (cast i32 (-> id bytes)) (cast i32 (-> id length)) (cast i32 n)) 0) 0 n)))
7
23
 
8
24
  (define (dom-flush!)
9
25
  (let* ([b (dom-patches)] [n (-> b length)])
@@ -12,12 +28,30 @@
12
28
  (dom-apply (cast i32 (-> b bytes)) n))
13
29
  (dom-discard!)))
14
30
 
15
- ;; The current event's text: its target's value when which is 0, or its key when which is 1.
16
- (define (dom-event-text [which u32]) -> string
17
- (let* ([n u32 0] [s (cast (ptr u8) (if (== which 0) (dom-event-value (cast i32 (& n))) (dom-event-key (cast i32 (& n)))))]
18
- [p (cast (ptr u8) (dom-frame-alloc n))])
19
- (memcpy p s n)
20
- (free s)
21
- (cast string (slice p n))))
31
+ (define (kept-text [p (ptr u8)] [n u32]) -> string
32
+ (let ([copy (cast (ptr u8) (dom-frame-alloc n))])
33
+ (memcpy copy p n)
34
+ (free p)
35
+ (cast string (slice copy n))))
36
+
37
+ (define (dom-event-number [path string]) -> f64 (event-number (cast i32 (-> path bytes)) (cast i32 (-> path length))))
38
+
39
+ (define (dom-event-text [path string]) -> string
40
+ (let* ([n u32 0] [p (event-text (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 (& n)))])
41
+ (kept-text (cast (ptr u8) p) n)))
42
+
43
+ (define (dom-event-call [method string]) (event-call (cast i32 (-> method bytes)) (cast i32 (-> method length))))
44
+
45
+ (define (dom-read-number [node u32] [path string]) -> f64
46
+ (read-number (cast i32 node) (cast i32 (-> path bytes)) (cast i32 (-> path length))))
47
+
48
+ (define (dom-read-text [node u32] [path string]) -> string
49
+ (let* ([n u32 0]
50
+ [p (read-text (cast i32 node) (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 (& n)))])
51
+ (kept-text (cast (ptr u8) p) n)))
52
+
53
+ (define (dom-event-is [node u32] [path string]) -> bool
54
+ (!= (event-is (cast i32 node) (cast i32 (-> path bytes)) (cast i32 (-> path length))) 0))
22
55
 
23
- (define (dom-event-truths) -> u32 (cast u32 (dom-event-flags)))
56
+ (define (dom-is [node u32] [from u32] [path string]) -> bool
57
+ (!= (is (cast i32 node) (cast i32 from) (cast i32 (-> path bytes)) (cast i32 (-> path length))) 0))
@@ -0,0 +1,439 @@
1
+ ;; The commands of the host module "gpu", written into one buffer. gpu.sub sends them.
2
+ (provide gpu-surface! gpu-shader! gpu-render-pipeline! gpu-layout-item! gpu-target! gpu-vertex-buffer-layout! gpu-attribute!
3
+ gpu-compute-pipeline! gpu-buffer! gpu-texture! gpu-texture-file! gpu-sampler! gpu-layout! gpu-layout-entry!
4
+ gpu-bind-group! gpu-bind-buffer! gpu-bind-sampler! gpu-bind-texture! gpu-destroy!
5
+ gpu-write-buffer! gpu-write-texture! gpu-read-texture! gpu-read-buffer!
6
+ gpu-render-pass! gpu-pass-target! gpu-compute-pass! gpu-end-pass! gpu-pipeline! gpu-bind-group-set! gpu-offset!
7
+ gpu-vertex-buffer! gpu-index-buffer! gpu-draw! gpu-draw-indexed! gpu-dispatch! gpu-viewport! gpu-scissor!
8
+ gpu-commands gpu-commands-done! gpu-frame-alloc gpu-frame-copy
9
+ gpu-format-surface gpu-rgba8 gpu-bgra8 gpu-r8 gpu-rg8 gpu-rgba16f gpu-r32f gpu-rgba32f gpu-depth24 gpu-depth32f
10
+ gpu-f32 gpu-f32x2 gpu-f32x3 gpu-f32x4 gpu-u32 gpu-u32x2 gpu-u32x4 gpu-i32 gpu-unorm8x4 gpu-snorm8x4
11
+ gpu-f16x2 gpu-f16x4 gpu-u8x4 gpu-unorm16x2 gpu-unorm16x4
12
+ gpu-triangles gpu-triangle-strip gpu-lines gpu-line-strip gpu-points
13
+ gpu-cull-none gpu-cull-back gpu-cull-front gpu-ccw gpu-cw
14
+ gpu-blend-none gpu-blend-alpha gpu-blend-premultiplied gpu-blend-add
15
+ gpu-compare-none gpu-less gpu-less-equal gpu-greater gpu-greater-equal gpu-equal gpu-always gpu-never
16
+ gpu-vertex gpu-index gpu-uniform gpu-storage gpu-indirect gpu-sampled gpu-target gpu-storage-texture
17
+ gpu-nearest gpu-linear gpu-clamp gpu-repeat gpu-mirror
18
+ gpu-uniform-entry gpu-storage-entry gpu-read-only-entry gpu-dynamic-uniform-entry gpu-dynamic-storage-entry
19
+ gpu-dynamic-read-only-entry gpu-sampler-entry gpu-comparison-entry gpu-texture-entry gpu-depth-entry
20
+ gpu-storage-texture-entry gpu-texture-array-entry gpu-depth-array-entry gpu-in-vertex gpu-in-fragment gpu-in-compute
21
+ gpu-per-vertex gpu-per-instance gpu-on-surface gpu-on-texture gpu-keep gpu-clear gpu-u16-indexes gpu-u32-indexes
22
+ gpu-kind-surface gpu-kind-shader gpu-kind-pipeline gpu-kind-buffer gpu-kind-texture gpu-kind-sampler
23
+ gpu-kind-layout gpu-kind-bind-group)
24
+
25
+ ;; ---- the codes ----
26
+
27
+ ;; Each code is the number host/web/gpu.mjs gives it.
28
+ (const gpu-format-surface u32 0)
29
+ (const gpu-rgba8 u32 1)
30
+ (const gpu-bgra8 u32 2)
31
+ (const gpu-r8 u32 3)
32
+ (const gpu-rg8 u32 4)
33
+ (const gpu-rgba16f u32 5)
34
+ (const gpu-r32f u32 6)
35
+ (const gpu-rgba32f u32 7)
36
+ (const gpu-depth24 u32 8)
37
+ (const gpu-depth32f u32 9)
38
+
39
+ (const gpu-f32 u32 1)
40
+ (const gpu-f32x2 u32 2)
41
+ (const gpu-f32x3 u32 3)
42
+ (const gpu-f32x4 u32 4)
43
+ (const gpu-u32 u32 5)
44
+ (const gpu-u32x2 u32 6)
45
+ (const gpu-u32x4 u32 7)
46
+ (const gpu-i32 u32 8)
47
+ (const gpu-unorm8x4 u32 9)
48
+ (const gpu-snorm8x4 u32 10)
49
+ (const gpu-f16x2 u32 11)
50
+ (const gpu-f16x4 u32 12)
51
+ (const gpu-u8x4 u32 13)
52
+ (const gpu-unorm16x2 u32 14)
53
+ (const gpu-unorm16x4 u32 15)
54
+
55
+ (const gpu-triangles u32 1)
56
+ (const gpu-triangle-strip u32 2)
57
+ (const gpu-lines u32 3)
58
+ (const gpu-line-strip u32 4)
59
+ (const gpu-points u32 5)
60
+
61
+ (const gpu-cull-none u32 0)
62
+ (const gpu-cull-back u32 1)
63
+ (const gpu-cull-front u32 2)
64
+ (const gpu-ccw u32 0)
65
+ (const gpu-cw u32 1)
66
+
67
+ (const gpu-blend-none u32 0)
68
+ (const gpu-blend-alpha u32 1)
69
+ (const gpu-blend-premultiplied u32 2)
70
+ (const gpu-blend-add u32 3)
71
+
72
+ (const gpu-compare-none u32 0)
73
+ (const gpu-less u32 1)
74
+ (const gpu-less-equal u32 2)
75
+ (const gpu-greater u32 3)
76
+ (const gpu-greater-equal u32 4)
77
+ (const gpu-equal u32 5)
78
+ (const gpu-always u32 6)
79
+ (const gpu-never u32 7)
80
+
81
+ (const gpu-vertex u32 1)
82
+ (const gpu-index u32 2)
83
+ (const gpu-uniform u32 4)
84
+ (const gpu-storage u32 8)
85
+ (const gpu-indirect u32 16)
86
+ (const gpu-sampled u32 1)
87
+ (const gpu-target u32 2)
88
+ (const gpu-storage-texture u32 4)
89
+
90
+ (const gpu-nearest u32 0)
91
+ (const gpu-linear u32 1)
92
+ (const gpu-clamp u32 0)
93
+ (const gpu-repeat u32 1)
94
+ (const gpu-mirror u32 2)
95
+
96
+ (const gpu-uniform-entry u32 1)
97
+ (const gpu-storage-entry u32 2)
98
+ (const gpu-read-only-entry u32 3)
99
+ (const gpu-dynamic-uniform-entry u32 4)
100
+ (const gpu-dynamic-storage-entry u32 5)
101
+ (const gpu-dynamic-read-only-entry u32 6)
102
+ (const gpu-sampler-entry u32 7)
103
+ (const gpu-comparison-entry u32 8)
104
+ (const gpu-texture-entry u32 9)
105
+ (const gpu-depth-entry u32 10)
106
+ (const gpu-storage-texture-entry u32 11)
107
+ (const gpu-texture-array-entry u32 12)
108
+ (const gpu-depth-array-entry u32 13)
109
+ (const gpu-in-vertex u32 1)
110
+ (const gpu-in-fragment u32 2)
111
+ (const gpu-in-compute u32 4)
112
+
113
+ (const gpu-per-vertex u32 0)
114
+ (const gpu-per-instance u32 1)
115
+ (const gpu-on-surface u32 1)
116
+ (const gpu-on-texture u32 2)
117
+ (const gpu-keep u32 0)
118
+ (const gpu-clear u32 1)
119
+ (const gpu-u16-indexes u32 0)
120
+ (const gpu-u32-indexes u32 1)
121
+
122
+ (const gpu-kind-surface u32 1)
123
+ (const gpu-kind-shader u32 2)
124
+ (const gpu-kind-pipeline u32 3)
125
+ (const gpu-kind-buffer u32 4)
126
+ (const gpu-kind-texture u32 5)
127
+ (const gpu-kind-sampler u32 6)
128
+ (const gpu-kind-layout u32 7)
129
+ (const gpu-kind-bind-group u32 8)
130
+
131
+ ;; ---- the buffer ----
132
+
133
+ (define commands buffer)
134
+ (define frame arena)
135
+
136
+ (define (gpu-commands) -> (ptr buffer)
137
+ (complete!)
138
+ (& commands))
139
+
140
+ (define (gpu-commands-done!)
141
+ (set! (-> commands length) 0)
142
+ (arena-free (& frame))
143
+ (expect-nothing!))
144
+
145
+ (define (gpu-frame-alloc [n u32]) -> (ptr void) (arena-alloc (& frame) n))
146
+
147
+ (define (gpu-frame-copy [p (ptr void)] [n u32]) -> (ptr void)
148
+ (let ([copy (gpu-frame-alloc n)])
149
+ (memcpy copy p n)
150
+ copy))
151
+
152
+ (define (words! [w (slice u32)]) (buffer-add! (& commands) (slice (cast (ptr u8) (-> w items)) (* 4 (-> w length)))))
153
+
154
+ (define (word! [w u32]) (words! (slice (array-of u32 w))))
155
+
156
+ (define (float! [x f64]) (buffer-add! (& commands) (slice (cast (ptr u8) (array-of f32 (cast f32 x))) 4)))
157
+
158
+ (define (text! [s string])
159
+ (let ([copy (cast (ptr u8) (gpu-frame-alloc (-> s length)))])
160
+ (memcpy copy (-> s bytes) (-> s length))
161
+ (words! (slice (array-of u32 (cast u32 copy) (-> s length))))))
162
+
163
+ ;; ---- the items a command still expects ----
164
+
165
+ (define expected-layouts u32 0)
166
+ (define expected-targets u32 0)
167
+ (define expected-buffers u32 0)
168
+ (define expected-attributes u32 0)
169
+ (define expected-entries u32 0)
170
+ (define expected-bindings u32 0)
171
+ (define expected-pass-targets u32 0)
172
+ (define expected-offsets u32 0)
173
+
174
+ (define (complete!)
175
+ (when (or (> expected-layouts 0) (> expected-targets 0) (> expected-buffers 0) (> expected-attributes 0)
176
+ (> expected-entries 0) (> expected-bindings 0) (> expected-pass-targets 0) (> expected-offsets 0))
177
+ (host-trap "gpu: the last command is still waiting for its items (layouts, targets, attributes, entries or offsets)")))
178
+
179
+ (define (expect-nothing!)
180
+ (set! expected-layouts 0)
181
+ (set! expected-targets 0)
182
+ (set! expected-buffers 0)
183
+ (set! expected-attributes 0)
184
+ (set! expected-entries 0)
185
+ (set! expected-bindings 0)
186
+ (set! expected-pass-targets 0)
187
+ (set! expected-offsets 0))
188
+
189
+ (define (item! [expected (ptr u32)] [unexpected string])
190
+ (when (== (@ expected) 0) (host-trap unexpected))
191
+ (-= (@ expected) 1))
192
+
193
+ ;; ---- numbers ----
194
+
195
+ (define next-surface u32 1)
196
+ (define next-shader u32 1)
197
+ (define next-pipeline u32 1)
198
+ (define next-buffer u32 1)
199
+ (define next-texture u32 1)
200
+ (define next-sampler u32 1)
201
+ (define next-layout u32 1)
202
+ (define next-bind-group u32 1)
203
+
204
+ (define (fresh! [next (ptr u32)]) -> u32
205
+ (let ([n (@ next)])
206
+ (+= (@ next) 1)
207
+ n))
208
+
209
+ ;; ---- making resources ----
210
+
211
+ (define (gpu-surface! [node u32]) -> u32
212
+ (complete!)
213
+ (let ([id (fresh! (& next-surface))])
214
+ (words! (slice (array-of u32 1 id node)))
215
+ id))
216
+
217
+ (define (gpu-shader! [code string]) -> u32
218
+ (complete!)
219
+ (let ([id (fresh! (& next-shader))])
220
+ (words! (slice (array-of u32 2 id)))
221
+ (text! code)
222
+ id))
223
+
224
+ (define (gpu-render-pipeline! [shader u32] [vertex string] [fragment string] [topology u32] [cull u32] [front u32]
225
+ [blend u32] [depth-format u32] [depth-compare u32] [depth-write bool]
226
+ [layouts u32] [targets u32] [buffers u32]) -> u32
227
+ (complete!)
228
+ (let ([id (fresh! (& next-pipeline))])
229
+ (words! (slice (array-of u32 3 id shader)))
230
+ (text! vertex)
231
+ (text! fragment)
232
+ (words! (slice (array-of u32 topology cull front blend depth-format depth-compare depth-write layouts)))
233
+ (set! expected-layouts layouts)
234
+ (set! expected-targets targets)
235
+ (set! expected-buffers buffers)
236
+ (set! rendering #t)
237
+ (when (== layouts 0) (after-layouts!))
238
+ id))
239
+
240
+ (define rendering bool #f)
241
+
242
+ (define (after-layouts!)
243
+ (when rendering
244
+ (word! expected-targets)
245
+ (when (== expected-targets 0) (after-targets!))))
246
+
247
+ (define (after-targets!) (word! expected-buffers))
248
+
249
+ (define (gpu-layout-item! [layout u32])
250
+ (item! (& expected-layouts) "gpu: no layout is expected here")
251
+ (word! layout)
252
+ (when (== expected-layouts 0) (after-layouts!)))
253
+
254
+ (define (gpu-target! [format u32])
255
+ (item! (& expected-targets) "gpu: no target is expected here")
256
+ (word! format)
257
+ (when (== expected-targets 0) (after-targets!)))
258
+
259
+ (define (gpu-vertex-buffer-layout! [stride u32] [step u32] [attributes u32])
260
+ (when (> expected-attributes 0) (host-trap "gpu: the attributes of the last vertex buffer are not complete"))
261
+ (item! (& expected-buffers) "gpu: no vertex buffer layout is expected here")
262
+ (words! (slice (array-of u32 stride step attributes)))
263
+ (set! expected-attributes attributes))
264
+
265
+ (define (gpu-attribute! [location u32] [offset u32] [format u32])
266
+ (item! (& expected-attributes) "gpu: no attribute is expected here")
267
+ (words! (slice (array-of u32 location offset format))))
268
+
269
+ (define (gpu-compute-pipeline! [shader u32] [entry string] [layouts u32]) -> u32
270
+ (complete!)
271
+ (let ([id (fresh! (& next-pipeline))])
272
+ (words! (slice (array-of u32 4 id shader)))
273
+ (text! entry)
274
+ (word! layouts)
275
+ (set! expected-layouts layouts)
276
+ (set! rendering #f)
277
+ id))
278
+
279
+ (define (gpu-buffer! [size u32] [usage u32]) -> u32
280
+ (complete!)
281
+ (let ([id (fresh! (& next-buffer))])
282
+ (words! (slice (array-of u32 5 id size usage)))
283
+ id))
284
+
285
+ (define (gpu-texture! [width u32] [height u32] [layers u32] [mips u32] [format u32] [usage u32]) -> u32
286
+ (complete!)
287
+ (let ([id (fresh! (& next-texture))])
288
+ (words! (slice (array-of u32 6 id width height layers mips format usage)))
289
+ id))
290
+
291
+ (define (gpu-texture-file! [path string]) -> u32
292
+ (complete!)
293
+ (let ([id (fresh! (& next-texture))])
294
+ (words! (slice (array-of u32 7 id)))
295
+ (text! path)
296
+ id))
297
+
298
+ (define (gpu-sampler! [filter u32] [address u32] [compare u32]) -> u32
299
+ (complete!)
300
+ (let ([id (fresh! (& next-sampler))])
301
+ (words! (slice (array-of u32 8 id filter address compare)))
302
+ id))
303
+
304
+ (define (gpu-layout! [n u32]) -> u32
305
+ (complete!)
306
+ (let ([id (fresh! (& next-layout))])
307
+ (words! (slice (array-of u32 9 id n)))
308
+ (set! expected-entries n)
309
+ id))
310
+
311
+ (define (gpu-layout-entry! [binding u32] [visibility u32] [kind u32])
312
+ (item! (& expected-entries) "gpu: no layout entry is expected here")
313
+ (words! (slice (array-of u32 binding visibility kind))))
314
+
315
+ (define (gpu-bind-group! [layout u32] [pipeline u32] [group u32] [n u32]) -> u32
316
+ (complete!)
317
+ (let ([id (fresh! (& next-bind-group))])
318
+ (words! (slice (array-of u32 10 id layout pipeline group n)))
319
+ (set! expected-bindings n)
320
+ id))
321
+
322
+ (define (gpu-bind-buffer! [binding u32] [buffer u32] [offset u32] [size u32])
323
+ (item! (& expected-bindings) "gpu: no binding is expected here")
324
+ (words! (slice (array-of u32 binding 1 buffer offset size))))
325
+
326
+ (define (gpu-bind-sampler! [binding u32] [sampler u32])
327
+ (item! (& expected-bindings) "gpu: no binding is expected here")
328
+ (words! (slice (array-of u32 binding 2 sampler 0 0))))
329
+
330
+ (define (gpu-bind-texture! [binding u32] [texture u32])
331
+ (item! (& expected-bindings) "gpu: no binding is expected here")
332
+ (words! (slice (array-of u32 binding 3 texture 0 0))))
333
+
334
+ (define (gpu-destroy! [kind u32] [id u32])
335
+ (complete!)
336
+ (words! (slice (array-of u32 11 kind id))))
337
+
338
+ ;; ---- writing and reading ----
339
+
340
+ (define (gpu-write-buffer! [buffer u32] [offset u32] [p (ptr void)] [n u32])
341
+ (complete!)
342
+ (words! (slice (array-of u32 12 buffer offset (cast u32 p) n))))
343
+
344
+ (define (gpu-write-texture! [texture u32] [mip u32] [layer u32] [x u32] [y u32] [w u32] [h u32] [p (ptr void)] [n u32])
345
+ (complete!)
346
+ (words! (slice (array-of u32 13 texture mip layer x y w h (cast u32 p) n))))
347
+
348
+ (define (gpu-read-texture! [texture u32] [mip u32] [layer u32] [x u32] [y u32] [w u32] [h u32])
349
+ (complete!)
350
+ (words! (slice (array-of u32 14 texture mip layer x y w h))))
351
+
352
+ (define (gpu-read-buffer! [buffer u32] [offset u32] [n u32])
353
+ (complete!)
354
+ (words! (slice (array-of u32 15 buffer offset n))))
355
+
356
+ ;; ---- passes ----
357
+
358
+ (define (gpu-render-pass! [targets u32] [depth-texture u32] [depth-mip u32] [depth-layer u32] [depth-load u32] [depth-clear f64])
359
+ (complete!)
360
+ (words! (slice (array-of u32 16 targets)))
361
+ (set! expected-pass-targets targets)
362
+ (set! pending-depth-texture depth-texture)
363
+ (set! pending-depth-mip depth-mip)
364
+ (set! pending-depth-layer depth-layer)
365
+ (set! pending-depth-load depth-load)
366
+ (set! pending-depth-clear depth-clear)
367
+ (when (== targets 0) (depth!)))
368
+
369
+ (define pending-depth-texture u32 0)
370
+ (define pending-depth-mip u32 0)
371
+ (define pending-depth-layer u32 0)
372
+ (define pending-depth-load u32 0)
373
+ (define pending-depth-clear f64 0.0)
374
+
375
+ (define (depth!)
376
+ (words! (slice (array-of u32 pending-depth-texture pending-depth-mip pending-depth-layer pending-depth-load)))
377
+ (float! pending-depth-clear))
378
+
379
+ (define (gpu-pass-target! [kind u32] [id u32] [mip u32] [layer u32] [load u32] [r f64] [g f64] [b f64] [a f64])
380
+ (item! (& expected-pass-targets) "gpu: no pass target is expected here")
381
+ (words! (slice (array-of u32 kind id mip layer load)))
382
+ (float! r)
383
+ (float! g)
384
+ (float! b)
385
+ (float! a)
386
+ (when (== expected-pass-targets 0) (depth!)))
387
+
388
+ (define (gpu-compute-pass!)
389
+ (complete!)
390
+ (word! 17))
391
+
392
+ (define (gpu-end-pass!)
393
+ (complete!)
394
+ (word! 18))
395
+
396
+ (define (gpu-pipeline! [pipeline u32])
397
+ (complete!)
398
+ (words! (slice (array-of u32 19 pipeline))))
399
+
400
+ (define (gpu-bind-group-set! [group u32] [bind-group u32] [n u32])
401
+ (complete!)
402
+ (words! (slice (array-of u32 20 group bind-group n)))
403
+ (set! expected-offsets n))
404
+
405
+ (define (gpu-offset! [offset u32])
406
+ (item! (& expected-offsets) "gpu: no offset is expected here")
407
+ (word! offset))
408
+
409
+ (define (gpu-vertex-buffer! [slot u32] [buffer u32] [offset u32])
410
+ (complete!)
411
+ (words! (slice (array-of u32 21 slot buffer offset))))
412
+
413
+ (define (gpu-index-buffer! [buffer u32] [format u32] [offset u32])
414
+ (complete!)
415
+ (words! (slice (array-of u32 22 buffer format offset))))
416
+
417
+ (define (gpu-draw! [vertices u32] [instances u32] [first-vertex u32] [first-instance u32])
418
+ (complete!)
419
+ (words! (slice (array-of u32 23 vertices instances first-vertex first-instance))))
420
+
421
+ (define (gpu-draw-indexed! [indexes u32] [instances u32] [first-index u32] [base-vertex u32] [first-instance u32])
422
+ (complete!)
423
+ (words! (slice (array-of u32 24 indexes instances first-index base-vertex first-instance))))
424
+
425
+ (define (gpu-dispatch! [x u32] [y u32] [z u32])
426
+ (complete!)
427
+ (words! (slice (array-of u32 25 x y z))))
428
+
429
+ (define (gpu-viewport! [x f64] [y f64] [w f64] [h f64])
430
+ (complete!)
431
+ (word! 26)
432
+ (float! x)
433
+ (float! y)
434
+ (float! w)
435
+ (float! h))
436
+
437
+ (define (gpu-scissor! [x u32] [y u32] [w u32] [h u32])
438
+ (complete!)
439
+ (words! (slice (array-of u32 27 x y w h))))