tile.h raw
1 // SPDX-License-Identifier: Apache-2.0 OR MIT OR Unlicense
2
3 // Code auto-generated by piet-gpu-derive
4
5 struct PathRef {
6 uint offset;
7 };
8
9 struct TileRef {
10 uint offset;
11 };
12
13 struct TileSegRef {
14 uint offset;
15 };
16
17 struct TransformSegRef {
18 uint offset;
19 };
20
21 struct Path {
22 uvec4 bbox;
23 TileRef tiles;
24 };
25
26 #define Path_size 12
27
28 PathRef Path_index(PathRef ref, uint index) {
29 return PathRef(ref.offset + index * Path_size);
30 }
31
32 struct Tile {
33 TileSegRef tile;
34 int backdrop;
35 };
36
37 #define Tile_size 8
38
39 TileRef Tile_index(TileRef ref, uint index) {
40 return TileRef(ref.offset + index * Tile_size);
41 }
42
43 struct TileSeg {
44 vec2 origin;
45 vec2 vector;
46 float y_edge;
47 TileSegRef next;
48 };
49
50 #define TileSeg_size 24
51
52 TileSegRef TileSeg_index(TileSegRef ref, uint index) {
53 return TileSegRef(ref.offset + index * TileSeg_size);
54 }
55
56 struct TransformSeg {
57 vec4 mat;
58 vec2 translate;
59 };
60
61 #define TransformSeg_size 24
62
63 TransformSegRef TransformSeg_index(TransformSegRef ref, uint index) {
64 return TransformSegRef(ref.offset + index * TransformSeg_size);
65 }
66
67 Path Path_read(Alloc a, PathRef ref) {
68 uint ix = ref.offset >> 2;
69 uint raw0 = read_mem(a, ix + 0);
70 uint raw1 = read_mem(a, ix + 1);
71 uint raw2 = read_mem(a, ix + 2);
72 Path s;
73 s.bbox = uvec4(raw0 & 0xffff, raw0 >> 16, raw1 & 0xffff, raw1 >> 16);
74 s.tiles = TileRef(raw2);
75 return s;
76 }
77
78 void Path_write(Alloc a, PathRef ref, Path s) {
79 uint ix = ref.offset >> 2;
80 write_mem(a, ix + 0, s.bbox.x | (s.bbox.y << 16));
81 write_mem(a, ix + 1, s.bbox.z | (s.bbox.w << 16));
82 write_mem(a, ix + 2, s.tiles.offset);
83 }
84
85 Tile Tile_read(Alloc a, TileRef ref) {
86 uint ix = ref.offset >> 2;
87 uint raw0 = read_mem(a, ix + 0);
88 uint raw1 = read_mem(a, ix + 1);
89 Tile s;
90 s.tile = TileSegRef(raw0);
91 s.backdrop = int(raw1);
92 return s;
93 }
94
95 void Tile_write(Alloc a, TileRef ref, Tile s) {
96 uint ix = ref.offset >> 2;
97 write_mem(a, ix + 0, s.tile.offset);
98 write_mem(a, ix + 1, uint(s.backdrop));
99 }
100
101 TileSeg TileSeg_read(Alloc a, TileSegRef ref) {
102 uint ix = ref.offset >> 2;
103 uint raw0 = read_mem(a, ix + 0);
104 uint raw1 = read_mem(a, ix + 1);
105 uint raw2 = read_mem(a, ix + 2);
106 uint raw3 = read_mem(a, ix + 3);
107 uint raw4 = read_mem(a, ix + 4);
108 uint raw5 = read_mem(a, ix + 5);
109 TileSeg s;
110 s.origin = vec2(uintBitsToFloat(raw0), uintBitsToFloat(raw1));
111 s.vector = vec2(uintBitsToFloat(raw2), uintBitsToFloat(raw3));
112 s.y_edge = uintBitsToFloat(raw4);
113 s.next = TileSegRef(raw5);
114 return s;
115 }
116
117 void TileSeg_write(Alloc a, TileSegRef ref, TileSeg s) {
118 uint ix = ref.offset >> 2;
119 write_mem(a, ix + 0, floatBitsToUint(s.origin.x));
120 write_mem(a, ix + 1, floatBitsToUint(s.origin.y));
121 write_mem(a, ix + 2, floatBitsToUint(s.vector.x));
122 write_mem(a, ix + 3, floatBitsToUint(s.vector.y));
123 write_mem(a, ix + 4, floatBitsToUint(s.y_edge));
124 write_mem(a, ix + 5, s.next.offset);
125 }
126
127 TransformSeg TransformSeg_read(Alloc a, TransformSegRef ref) {
128 uint ix = ref.offset >> 2;
129 uint raw0 = read_mem(a, ix + 0);
130 uint raw1 = read_mem(a, ix + 1);
131 uint raw2 = read_mem(a, ix + 2);
132 uint raw3 = read_mem(a, ix + 3);
133 uint raw4 = read_mem(a, ix + 4);
134 uint raw5 = read_mem(a, ix + 5);
135 TransformSeg s;
136 s.mat = vec4(uintBitsToFloat(raw0), uintBitsToFloat(raw1), uintBitsToFloat(raw2), uintBitsToFloat(raw3));
137 s.translate = vec2(uintBitsToFloat(raw4), uintBitsToFloat(raw5));
138 return s;
139 }
140
141 void TransformSeg_write(Alloc a, TransformSegRef ref, TransformSeg s) {
142 uint ix = ref.offset >> 2;
143 write_mem(a, ix + 0, floatBitsToUint(s.mat.x));
144 write_mem(a, ix + 1, floatBitsToUint(s.mat.y));
145 write_mem(a, ix + 2, floatBitsToUint(s.mat.z));
146 write_mem(a, ix + 3, floatBitsToUint(s.mat.w));
147 write_mem(a, ix + 4, floatBitsToUint(s.translate.x));
148 write_mem(a, ix + 5, floatBitsToUint(s.translate.y));
149 }
150
151