~eliasnaur/gio

ref: c849c5b77fc7321c67735871de505f2c6466cebc gio/gpu/shaders/ptcl.h -rw-r--r-- 12.9 KiB
c849c5b7Elias Naur gpu: [compute] use correct usage flags for output image 2 months ago
                                                                                
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
// SPDX-License-Identifier: Apache-2.0 OR MIT OR Unlicense

// Code auto-generated by piet-gpu-derive

struct CmdCircleRef {
    uint offset;
};

struct CmdLineRef {
    uint offset;
};

struct CmdStrokeRef {
    uint offset;
};

struct CmdFillRef {
    uint offset;
};

struct CmdFillImageRef {
    uint offset;
};

struct CmdBeginClipRef {
    uint offset;
};

struct CmdBeginSolidClipRef {
    uint offset;
};

struct CmdEndClipRef {
    uint offset;
};

struct CmdSolidRef {
    uint offset;
};

struct CmdSolidImageRef {
    uint offset;
};

struct CmdSolidMaskRef {
    uint offset;
};

struct CmdJumpRef {
    uint offset;
};

struct CmdRef {
    uint offset;
};

struct CmdCircle {
    vec2 center;
    float radius;
    uint rgba_color;
};

#define CmdCircle_size 16

CmdCircleRef CmdCircle_index(CmdCircleRef ref, uint index) {
    return CmdCircleRef(ref.offset + index * CmdCircle_size);
}

struct CmdLine {
    vec2 start;
    vec2 end;
};

#define CmdLine_size 16

CmdLineRef CmdLine_index(CmdLineRef ref, uint index) {
    return CmdLineRef(ref.offset + index * CmdLine_size);
}

struct CmdStroke {
    uint tile_ref;
    float half_width;
    uint rgba_color;
};

#define CmdStroke_size 12

CmdStrokeRef CmdStroke_index(CmdStrokeRef ref, uint index) {
    return CmdStrokeRef(ref.offset + index * CmdStroke_size);
}

struct CmdFill {
    uint tile_ref;
    int backdrop;
    uint rgba_color;
};

#define CmdFill_size 12

CmdFillRef CmdFill_index(CmdFillRef ref, uint index) {
    return CmdFillRef(ref.offset + index * CmdFill_size);
}

struct CmdFillImage {
    uint tile_ref;
    int backdrop;
    uint index;
    ivec2 offset;
};

#define CmdFillImage_size 16

CmdFillImageRef CmdFillImage_index(CmdFillImageRef ref, uint index) {
    return CmdFillImageRef(ref.offset + index * CmdFillImage_size);
}

struct CmdBeginClip {
    uint tile_ref;
    int backdrop;
};

#define CmdBeginClip_size 8

CmdBeginClipRef CmdBeginClip_index(CmdBeginClipRef ref, uint index) {
    return CmdBeginClipRef(ref.offset + index * CmdBeginClip_size);
}

struct CmdBeginSolidClip {
    float alpha;
};

#define CmdBeginSolidClip_size 4

CmdBeginSolidClipRef CmdBeginSolidClip_index(CmdBeginSolidClipRef ref, uint index) {
    return CmdBeginSolidClipRef(ref.offset + index * CmdBeginSolidClip_size);
}

struct CmdEndClip {
    float alpha;
};

#define CmdEndClip_size 4

CmdEndClipRef CmdEndClip_index(CmdEndClipRef ref, uint index) {
    return CmdEndClipRef(ref.offset + index * CmdEndClip_size);
}

struct CmdSolid {
    uint rgba_color;
};

#define CmdSolid_size 4

CmdSolidRef CmdSolid_index(CmdSolidRef ref, uint index) {
    return CmdSolidRef(ref.offset + index * CmdSolid_size);
}

struct CmdSolidImage {
    uint index;
    ivec2 offset;
};

#define CmdSolidImage_size 8

CmdSolidImageRef CmdSolidImage_index(CmdSolidImageRef ref, uint index) {
    return CmdSolidImageRef(ref.offset + index * CmdSolidImage_size);
}

struct CmdSolidMask {
    float mask;
};

#define CmdSolidMask_size 4

CmdSolidMaskRef CmdSolidMask_index(CmdSolidMaskRef ref, uint index) {
    return CmdSolidMaskRef(ref.offset + index * CmdSolidMask_size);
}

struct CmdJump {
    uint new_ref;
};

#define CmdJump_size 4

CmdJumpRef CmdJump_index(CmdJumpRef ref, uint index) {
    return CmdJumpRef(ref.offset + index * CmdJump_size);
}

#define Cmd_End 0
#define Cmd_Circle 1
#define Cmd_Line 2
#define Cmd_Fill 3
#define Cmd_FillImage 4
#define Cmd_BeginClip 5
#define Cmd_BeginSolidClip 6
#define Cmd_EndClip 7
#define Cmd_Stroke 8
#define Cmd_Solid 9
#define Cmd_SolidMask 10
#define Cmd_SolidImage 11
#define Cmd_Jump 12
#define Cmd_size 20

CmdRef Cmd_index(CmdRef ref, uint index) {
    return CmdRef(ref.offset + index * Cmd_size);
}

CmdCircle CmdCircle_read(Alloc a, CmdCircleRef ref) {
    uint ix = ref.offset >> 2;
    uint raw0 = read_mem(a, ix + 0);
    uint raw1 = read_mem(a, ix + 1);
    uint raw2 = read_mem(a, ix + 2);
    uint raw3 = read_mem(a, ix + 3);
    CmdCircle s;
    s.center = vec2(uintBitsToFloat(raw0), uintBitsToFloat(raw1));
    s.radius = uintBitsToFloat(raw2);
    s.rgba_color = raw3;
    return s;
}

void CmdCircle_write(Alloc a, CmdCircleRef ref, CmdCircle s) {
    uint ix = ref.offset >> 2;
    write_mem(a, ix + 0, floatBitsToUint(s.center.x));
    write_mem(a, ix + 1, floatBitsToUint(s.center.y));
    write_mem(a, ix + 2, floatBitsToUint(s.radius));
    write_mem(a, ix + 3, s.rgba_color);
}

CmdLine CmdLine_read(Alloc a, CmdLineRef ref) {
    uint ix = ref.offset >> 2;
    uint raw0 = read_mem(a, ix + 0);
    uint raw1 = read_mem(a, ix + 1);
    uint raw2 = read_mem(a, ix + 2);
    uint raw3 = read_mem(a, ix + 3);
    CmdLine s;
    s.start = vec2(uintBitsToFloat(raw0), uintBitsToFloat(raw1));
    s.end = vec2(uintBitsToFloat(raw2), uintBitsToFloat(raw3));
    return s;
}

void CmdLine_write(Alloc a, CmdLineRef ref, CmdLine s) {
    uint ix = ref.offset >> 2;
    write_mem(a, ix + 0, floatBitsToUint(s.start.x));
    write_mem(a, ix + 1, floatBitsToUint(s.start.y));
    write_mem(a, ix + 2, floatBitsToUint(s.end.x));
    write_mem(a, ix + 3, floatBitsToUint(s.end.y));
}

CmdStroke CmdStroke_read(Alloc a, CmdStrokeRef ref) {
    uint ix = ref.offset >> 2;
    uint raw0 = read_mem(a, ix + 0);
    uint raw1 = read_mem(a, ix + 1);
    uint raw2 = read_mem(a, ix + 2);
    CmdStroke s;
    s.tile_ref = raw0;
    s.half_width = uintBitsToFloat(raw1);
    s.rgba_color = raw2;
    return s;
}

void CmdStroke_write(Alloc a, CmdStrokeRef ref, CmdStroke s) {
    uint ix = ref.offset >> 2;
    write_mem(a, ix + 0, s.tile_ref);
    write_mem(a, ix + 1, floatBitsToUint(s.half_width));
    write_mem(a, ix + 2, s.rgba_color);
}

CmdFill CmdFill_read(Alloc a, CmdFillRef ref) {
    uint ix = ref.offset >> 2;
    uint raw0 = read_mem(a, ix + 0);
    uint raw1 = read_mem(a, ix + 1);
    uint raw2 = read_mem(a, ix + 2);
    CmdFill s;
    s.tile_ref = raw0;
    s.backdrop = int(raw1);
    s.rgba_color = raw2;
    return s;
}

void CmdFill_write(Alloc a, CmdFillRef ref, CmdFill s) {
    uint ix = ref.offset >> 2;
    write_mem(a, ix + 0, s.tile_ref);
    write_mem(a, ix + 1, uint(s.backdrop));
    write_mem(a, ix + 2, s.rgba_color);
}

CmdFillImage CmdFillImage_read(Alloc a, CmdFillImageRef ref) {
    uint ix = ref.offset >> 2;
    uint raw0 = read_mem(a, ix + 0);
    uint raw1 = read_mem(a, ix + 1);
    uint raw2 = read_mem(a, ix + 2);
    uint raw3 = read_mem(a, ix + 3);
    CmdFillImage s;
    s.tile_ref = raw0;
    s.backdrop = int(raw1);
    s.index = raw2;
    s.offset = ivec2(int(raw3 << 16) >> 16, int(raw3) >> 16);
    return s;
}

void CmdFillImage_write(Alloc a, CmdFillImageRef ref, CmdFillImage s) {
    uint ix = ref.offset >> 2;
    write_mem(a, ix + 0, s.tile_ref);
    write_mem(a, ix + 1, uint(s.backdrop));
    write_mem(a, ix + 2, s.index);
    write_mem(a, ix + 3, (uint(s.offset.x) & 0xffff) | (uint(s.offset.y) << 16));
}

CmdBeginClip CmdBeginClip_read(Alloc a, CmdBeginClipRef ref) {
    uint ix = ref.offset >> 2;
    uint raw0 = read_mem(a, ix + 0);
    uint raw1 = read_mem(a, ix + 1);
    CmdBeginClip s;
    s.tile_ref = raw0;
    s.backdrop = int(raw1);
    return s;
}

void CmdBeginClip_write(Alloc a, CmdBeginClipRef ref, CmdBeginClip s) {
    uint ix = ref.offset >> 2;
    write_mem(a, ix + 0, s.tile_ref);
    write_mem(a, ix + 1, uint(s.backdrop));
}

CmdBeginSolidClip CmdBeginSolidClip_read(Alloc a, CmdBeginSolidClipRef ref) {
    uint ix = ref.offset >> 2;
    uint raw0 = read_mem(a, ix + 0);
    CmdBeginSolidClip s;
    s.alpha = uintBitsToFloat(raw0);
    return s;
}

void CmdBeginSolidClip_write(Alloc a, CmdBeginSolidClipRef ref, CmdBeginSolidClip s) {
    uint ix = ref.offset >> 2;
    write_mem(a, ix + 0, floatBitsToUint(s.alpha));
}

CmdEndClip CmdEndClip_read(Alloc a, CmdEndClipRef ref) {
    uint ix = ref.offset >> 2;
    uint raw0 = read_mem(a, ix + 0);
    CmdEndClip s;
    s.alpha = uintBitsToFloat(raw0);
    return s;
}

void CmdEndClip_write(Alloc a, CmdEndClipRef ref, CmdEndClip s) {
    uint ix = ref.offset >> 2;
    write_mem(a, ix + 0, floatBitsToUint(s.alpha));
}

CmdSolid CmdSolid_read(Alloc a, CmdSolidRef ref) {
    uint ix = ref.offset >> 2;
    uint raw0 = read_mem(a, ix + 0);
    CmdSolid s;
    s.rgba_color = raw0;
    return s;
}

void CmdSolid_write(Alloc a, CmdSolidRef ref, CmdSolid s) {
    uint ix = ref.offset >> 2;
    write_mem(a, ix + 0, s.rgba_color);
}

CmdSolidImage CmdSolidImage_read(Alloc a, CmdSolidImageRef ref) {
    uint ix = ref.offset >> 2;
    uint raw0 = read_mem(a, ix + 0);
    uint raw1 = read_mem(a, ix + 1);
    CmdSolidImage s;
    s.index = raw0;
    s.offset = ivec2(int(raw1 << 16) >> 16, int(raw1) >> 16);
    return s;
}

void CmdSolidImage_write(Alloc a, CmdSolidImageRef ref, CmdSolidImage s) {
    uint ix = ref.offset >> 2;
    write_mem(a, ix + 0, s.index);
    write_mem(a, ix + 1, (uint(s.offset.x) & 0xffff) | (uint(s.offset.y) << 16));
}

CmdSolidMask CmdSolidMask_read(Alloc a, CmdSolidMaskRef ref) {
    uint ix = ref.offset >> 2;
    uint raw0 = read_mem(a, ix + 0);
    CmdSolidMask s;
    s.mask = uintBitsToFloat(raw0);
    return s;
}

void CmdSolidMask_write(Alloc a, CmdSolidMaskRef ref, CmdSolidMask s) {
    uint ix = ref.offset >> 2;
    write_mem(a, ix + 0, floatBitsToUint(s.mask));
}

CmdJump CmdJump_read(Alloc a, CmdJumpRef ref) {
    uint ix = ref.offset >> 2;
    uint raw0 = read_mem(a, ix + 0);
    CmdJump s;
    s.new_ref = raw0;
    return s;
}

void CmdJump_write(Alloc a, CmdJumpRef ref, CmdJump s) {
    uint ix = ref.offset >> 2;
    write_mem(a, ix + 0, s.new_ref);
}

uint Cmd_tag(Alloc a, CmdRef ref) {
    return read_mem(a, ref.offset >> 2);
}

CmdCircle Cmd_Circle_read(Alloc a, CmdRef ref) {
    return CmdCircle_read(a, CmdCircleRef(ref.offset + 4));
}

CmdLine Cmd_Line_read(Alloc a, CmdRef ref) {
    return CmdLine_read(a, CmdLineRef(ref.offset + 4));
}

CmdFill Cmd_Fill_read(Alloc a, CmdRef ref) {
    return CmdFill_read(a, CmdFillRef(ref.offset + 4));
}

CmdFillImage Cmd_FillImage_read(Alloc a, CmdRef ref) {
    return CmdFillImage_read(a, CmdFillImageRef(ref.offset + 4));
}

CmdBeginClip Cmd_BeginClip_read(Alloc a, CmdRef ref) {
    return CmdBeginClip_read(a, CmdBeginClipRef(ref.offset + 4));
}

CmdBeginSolidClip Cmd_BeginSolidClip_read(Alloc a, CmdRef ref) {
    return CmdBeginSolidClip_read(a, CmdBeginSolidClipRef(ref.offset + 4));
}

CmdEndClip Cmd_EndClip_read(Alloc a, CmdRef ref) {
    return CmdEndClip_read(a, CmdEndClipRef(ref.offset + 4));
}

CmdStroke Cmd_Stroke_read(Alloc a, CmdRef ref) {
    return CmdStroke_read(a, CmdStrokeRef(ref.offset + 4));
}

CmdSolid Cmd_Solid_read(Alloc a, CmdRef ref) {
    return CmdSolid_read(a, CmdSolidRef(ref.offset + 4));
}

CmdSolidMask Cmd_SolidMask_read(Alloc a, CmdRef ref) {
    return CmdSolidMask_read(a, CmdSolidMaskRef(ref.offset + 4));
}

CmdSolidImage Cmd_SolidImage_read(Alloc a, CmdRef ref) {
    return CmdSolidImage_read(a, CmdSolidImageRef(ref.offset + 4));
}

CmdJump Cmd_Jump_read(Alloc a, CmdRef ref) {
    return CmdJump_read(a, CmdJumpRef(ref.offset + 4));
}

void Cmd_End_write(Alloc a, CmdRef ref) {
    write_mem(a, ref.offset >> 2, Cmd_End);
}

void Cmd_Circle_write(Alloc a, CmdRef ref, CmdCircle s) {
    write_mem(a, ref.offset >> 2, Cmd_Circle);
    CmdCircle_write(a, CmdCircleRef(ref.offset + 4), s);
}

void Cmd_Line_write(Alloc a, CmdRef ref, CmdLine s) {
    write_mem(a, ref.offset >> 2, Cmd_Line);
    CmdLine_write(a, CmdLineRef(ref.offset + 4), s);
}

void Cmd_Fill_write(Alloc a, CmdRef ref, CmdFill s) {
    write_mem(a, ref.offset >> 2, Cmd_Fill);
    CmdFill_write(a, CmdFillRef(ref.offset + 4), s);
}

void Cmd_FillImage_write(Alloc a, CmdRef ref, CmdFillImage s) {
    write_mem(a, ref.offset >> 2, Cmd_FillImage);
    CmdFillImage_write(a, CmdFillImageRef(ref.offset + 4), s);
}

void Cmd_BeginClip_write(Alloc a, CmdRef ref, CmdBeginClip s) {
    write_mem(a, ref.offset >> 2, Cmd_BeginClip);
    CmdBeginClip_write(a, CmdBeginClipRef(ref.offset + 4), s);
}

void Cmd_BeginSolidClip_write(Alloc a, CmdRef ref, CmdBeginSolidClip s) {
    write_mem(a, ref.offset >> 2, Cmd_BeginSolidClip);
    CmdBeginSolidClip_write(a, CmdBeginSolidClipRef(ref.offset + 4), s);
}

void Cmd_EndClip_write(Alloc a, CmdRef ref, CmdEndClip s) {
    write_mem(a, ref.offset >> 2, Cmd_EndClip);
    CmdEndClip_write(a, CmdEndClipRef(ref.offset + 4), s);
}

void Cmd_Stroke_write(Alloc a, CmdRef ref, CmdStroke s) {
    write_mem(a, ref.offset >> 2, Cmd_Stroke);
    CmdStroke_write(a, CmdStrokeRef(ref.offset + 4), s);
}

void Cmd_Solid_write(Alloc a, CmdRef ref, CmdSolid s) {
    write_mem(a, ref.offset >> 2, Cmd_Solid);
    CmdSolid_write(a, CmdSolidRef(ref.offset + 4), s);
}

void Cmd_SolidMask_write(Alloc a, CmdRef ref, CmdSolidMask s) {
    write_mem(a, ref.offset >> 2, Cmd_SolidMask);
    CmdSolidMask_write(a, CmdSolidMaskRef(ref.offset + 4), s);
}

void Cmd_SolidImage_write(Alloc a, CmdRef ref, CmdSolidImage s) {
    write_mem(a, ref.offset >> 2, Cmd_SolidImage);
    CmdSolidImage_write(a, CmdSolidImageRef(ref.offset + 4), s);
}

void Cmd_Jump_write(Alloc a, CmdRef ref, CmdJump s) {
    write_mem(a, ref.offset >> 2, Cmd_Jump);
    CmdJump_write(a, CmdJumpRef(ref.offset + 4), s);
}