annotated.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 AnnoImageRef {
6 uint offset;
7 };
8
9 struct AnnoColorRef {
10 uint offset;
11 };
12
13 struct AnnoBeginClipRef {
14 uint offset;
15 };
16
17 struct AnnoEndClipRef {
18 uint offset;
19 };
20
21 struct AnnotatedRef {
22 uint offset;
23 };
24
25 struct AnnoImage {
26 vec4 bbox;
27 float linewidth;
28 uint index;
29 ivec2 offset;
30 };
31
32 #define AnnoImage_size 28
33
34 AnnoImageRef AnnoImage_index(AnnoImageRef ref, uint index) {
35 return AnnoImageRef(ref.offset + index * AnnoImage_size);
36 }
37
38 struct AnnoColor {
39 vec4 bbox;
40 float linewidth;
41 uint rgba_color;
42 };
43
44 #define AnnoColor_size 24
45
46 AnnoColorRef AnnoColor_index(AnnoColorRef ref, uint index) {
47 return AnnoColorRef(ref.offset + index * AnnoColor_size);
48 }
49
50 struct AnnoBeginClip {
51 vec4 bbox;
52 float linewidth;
53 };
54
55 #define AnnoBeginClip_size 20
56
57 AnnoBeginClipRef AnnoBeginClip_index(AnnoBeginClipRef ref, uint index) {
58 return AnnoBeginClipRef(ref.offset + index * AnnoBeginClip_size);
59 }
60
61 struct AnnoEndClip {
62 vec4 bbox;
63 };
64
65 #define AnnoEndClip_size 16
66
67 AnnoEndClipRef AnnoEndClip_index(AnnoEndClipRef ref, uint index) {
68 return AnnoEndClipRef(ref.offset + index * AnnoEndClip_size);
69 }
70
71 #define Annotated_Nop 0
72 #define Annotated_Color 1
73 #define Annotated_Image 2
74 #define Annotated_BeginClip 3
75 #define Annotated_EndClip 4
76 #define Annotated_size 32
77
78 AnnotatedRef Annotated_index(AnnotatedRef ref, uint index) {
79 return AnnotatedRef(ref.offset + index * Annotated_size);
80 }
81
82 struct AnnotatedTag {
83 uint tag;
84 uint flags;
85 };
86
87 AnnoImage AnnoImage_read(Alloc a, AnnoImageRef ref) {
88 uint ix = ref.offset >> 2;
89 uint raw0 = read_mem(a, ix + 0);
90 uint raw1 = read_mem(a, ix + 1);
91 uint raw2 = read_mem(a, ix + 2);
92 uint raw3 = read_mem(a, ix + 3);
93 uint raw4 = read_mem(a, ix + 4);
94 uint raw5 = read_mem(a, ix + 5);
95 uint raw6 = read_mem(a, ix + 6);
96 AnnoImage s;
97 s.bbox = vec4(uintBitsToFloat(raw0), uintBitsToFloat(raw1), uintBitsToFloat(raw2), uintBitsToFloat(raw3));
98 s.linewidth = uintBitsToFloat(raw4);
99 s.index = raw5;
100 s.offset = ivec2(int(raw6 << 16) >> 16, int(raw6) >> 16);
101 return s;
102 }
103
104 void AnnoImage_write(Alloc a, AnnoImageRef ref, AnnoImage s) {
105 uint ix = ref.offset >> 2;
106 write_mem(a, ix + 0, floatBitsToUint(s.bbox.x));
107 write_mem(a, ix + 1, floatBitsToUint(s.bbox.y));
108 write_mem(a, ix + 2, floatBitsToUint(s.bbox.z));
109 write_mem(a, ix + 3, floatBitsToUint(s.bbox.w));
110 write_mem(a, ix + 4, floatBitsToUint(s.linewidth));
111 write_mem(a, ix + 5, s.index);
112 write_mem(a, ix + 6, (uint(s.offset.x) & 0xffff) | (uint(s.offset.y) << 16));
113 }
114
115 AnnoColor AnnoColor_read(Alloc a, AnnoColorRef ref) {
116 uint ix = ref.offset >> 2;
117 uint raw0 = read_mem(a, ix + 0);
118 uint raw1 = read_mem(a, ix + 1);
119 uint raw2 = read_mem(a, ix + 2);
120 uint raw3 = read_mem(a, ix + 3);
121 uint raw4 = read_mem(a, ix + 4);
122 uint raw5 = read_mem(a, ix + 5);
123 AnnoColor s;
124 s.bbox = vec4(uintBitsToFloat(raw0), uintBitsToFloat(raw1), uintBitsToFloat(raw2), uintBitsToFloat(raw3));
125 s.linewidth = uintBitsToFloat(raw4);
126 s.rgba_color = raw5;
127 return s;
128 }
129
130 void AnnoColor_write(Alloc a, AnnoColorRef ref, AnnoColor s) {
131 uint ix = ref.offset >> 2;
132 write_mem(a, ix + 0, floatBitsToUint(s.bbox.x));
133 write_mem(a, ix + 1, floatBitsToUint(s.bbox.y));
134 write_mem(a, ix + 2, floatBitsToUint(s.bbox.z));
135 write_mem(a, ix + 3, floatBitsToUint(s.bbox.w));
136 write_mem(a, ix + 4, floatBitsToUint(s.linewidth));
137 write_mem(a, ix + 5, s.rgba_color);
138 }
139
140 AnnoBeginClip AnnoBeginClip_read(Alloc a, AnnoBeginClipRef ref) {
141 uint ix = ref.offset >> 2;
142 uint raw0 = read_mem(a, ix + 0);
143 uint raw1 = read_mem(a, ix + 1);
144 uint raw2 = read_mem(a, ix + 2);
145 uint raw3 = read_mem(a, ix + 3);
146 uint raw4 = read_mem(a, ix + 4);
147 AnnoBeginClip s;
148 s.bbox = vec4(uintBitsToFloat(raw0), uintBitsToFloat(raw1), uintBitsToFloat(raw2), uintBitsToFloat(raw3));
149 s.linewidth = uintBitsToFloat(raw4);
150 return s;
151 }
152
153 void AnnoBeginClip_write(Alloc a, AnnoBeginClipRef ref, AnnoBeginClip s) {
154 uint ix = ref.offset >> 2;
155 write_mem(a, ix + 0, floatBitsToUint(s.bbox.x));
156 write_mem(a, ix + 1, floatBitsToUint(s.bbox.y));
157 write_mem(a, ix + 2, floatBitsToUint(s.bbox.z));
158 write_mem(a, ix + 3, floatBitsToUint(s.bbox.w));
159 write_mem(a, ix + 4, floatBitsToUint(s.linewidth));
160 }
161
162 AnnoEndClip AnnoEndClip_read(Alloc a, AnnoEndClipRef ref) {
163 uint ix = ref.offset >> 2;
164 uint raw0 = read_mem(a, ix + 0);
165 uint raw1 = read_mem(a, ix + 1);
166 uint raw2 = read_mem(a, ix + 2);
167 uint raw3 = read_mem(a, ix + 3);
168 AnnoEndClip s;
169 s.bbox = vec4(uintBitsToFloat(raw0), uintBitsToFloat(raw1), uintBitsToFloat(raw2), uintBitsToFloat(raw3));
170 return s;
171 }
172
173 void AnnoEndClip_write(Alloc a, AnnoEndClipRef ref, AnnoEndClip s) {
174 uint ix = ref.offset >> 2;
175 write_mem(a, ix + 0, floatBitsToUint(s.bbox.x));
176 write_mem(a, ix + 1, floatBitsToUint(s.bbox.y));
177 write_mem(a, ix + 2, floatBitsToUint(s.bbox.z));
178 write_mem(a, ix + 3, floatBitsToUint(s.bbox.w));
179 }
180
181 AnnotatedTag Annotated_tag(Alloc a, AnnotatedRef ref) {
182 uint tag_and_flags = read_mem(a, ref.offset >> 2);
183 return AnnotatedTag(tag_and_flags & 0xffff, tag_and_flags >> 16);
184 }
185
186 AnnoColor Annotated_Color_read(Alloc a, AnnotatedRef ref) {
187 return AnnoColor_read(a, AnnoColorRef(ref.offset + 4));
188 }
189
190 AnnoImage Annotated_Image_read(Alloc a, AnnotatedRef ref) {
191 return AnnoImage_read(a, AnnoImageRef(ref.offset + 4));
192 }
193
194 AnnoBeginClip Annotated_BeginClip_read(Alloc a, AnnotatedRef ref) {
195 return AnnoBeginClip_read(a, AnnoBeginClipRef(ref.offset + 4));
196 }
197
198 AnnoEndClip Annotated_EndClip_read(Alloc a, AnnotatedRef ref) {
199 return AnnoEndClip_read(a, AnnoEndClipRef(ref.offset + 4));
200 }
201
202 void Annotated_Nop_write(Alloc a, AnnotatedRef ref) {
203 write_mem(a, ref.offset >> 2, Annotated_Nop);
204 }
205
206 void Annotated_Color_write(Alloc a, AnnotatedRef ref, uint flags, AnnoColor s) {
207 write_mem(a, ref.offset >> 2, (flags << 16) | Annotated_Color);
208 AnnoColor_write(a, AnnoColorRef(ref.offset + 4), s);
209 }
210
211 void Annotated_Image_write(Alloc a, AnnotatedRef ref, uint flags, AnnoImage s) {
212 write_mem(a, ref.offset >> 2, (flags << 16) | Annotated_Image);
213 AnnoImage_write(a, AnnoImageRef(ref.offset + 4), s);
214 }
215
216 void Annotated_BeginClip_write(Alloc a, AnnotatedRef ref, uint flags, AnnoBeginClip s) {
217 write_mem(a, ref.offset >> 2, (flags << 16) | Annotated_BeginClip);
218 AnnoBeginClip_write(a, AnnoBeginClipRef(ref.offset + 4), s);
219 }
220
221 void Annotated_EndClip_write(Alloc a, AnnotatedRef ref, AnnoEndClip s) {
222 write_mem(a, ref.offset >> 2, Annotated_EndClip);
223 AnnoEndClip_write(a, AnnoEndClipRef(ref.offset + 4), s);
224 }
225
226