github.com/cybriq/giocore@v0.0.7-0.20210703034601-cfb9cb5f3900/gpu/shaders/ptcl.h (about) 1 // SPDX-License-Identifier: Apache-2.0 OR MIT OR Unlicense 2 3 // Code auto-generated by piet-gpu-derive 4 5 struct CmdStrokeRef { 6 uint offset; 7 }; 8 9 struct CmdFillRef { 10 uint offset; 11 }; 12 13 struct CmdColorRef { 14 uint offset; 15 }; 16 17 struct CmdImageRef { 18 uint offset; 19 }; 20 21 struct CmdAlphaRef { 22 uint offset; 23 }; 24 25 struct CmdJumpRef { 26 uint offset; 27 }; 28 29 struct CmdRef { 30 uint offset; 31 }; 32 33 struct CmdStroke { 34 uint tile_ref; 35 float half_width; 36 }; 37 38 #define CmdStroke_size 8 39 40 CmdStrokeRef CmdStroke_index(CmdStrokeRef ref, uint index) { 41 return CmdStrokeRef(ref.offset + index * CmdStroke_size); 42 } 43 44 struct CmdFill { 45 uint tile_ref; 46 int backdrop; 47 }; 48 49 #define CmdFill_size 8 50 51 CmdFillRef CmdFill_index(CmdFillRef ref, uint index) { 52 return CmdFillRef(ref.offset + index * CmdFill_size); 53 } 54 55 struct CmdColor { 56 uint rgba_color; 57 }; 58 59 #define CmdColor_size 4 60 61 CmdColorRef CmdColor_index(CmdColorRef ref, uint index) { 62 return CmdColorRef(ref.offset + index * CmdColor_size); 63 } 64 65 struct CmdImage { 66 uint index; 67 ivec2 offset; 68 }; 69 70 #define CmdImage_size 8 71 72 CmdImageRef CmdImage_index(CmdImageRef ref, uint index) { 73 return CmdImageRef(ref.offset + index * CmdImage_size); 74 } 75 76 struct CmdAlpha { 77 float alpha; 78 }; 79 80 #define CmdAlpha_size 4 81 82 CmdAlphaRef CmdAlpha_index(CmdAlphaRef ref, uint index) { 83 return CmdAlphaRef(ref.offset + index * CmdAlpha_size); 84 } 85 86 struct CmdJump { 87 uint new_ref; 88 }; 89 90 #define CmdJump_size 4 91 92 CmdJumpRef CmdJump_index(CmdJumpRef ref, uint index) { 93 return CmdJumpRef(ref.offset + index * CmdJump_size); 94 } 95 96 #define Cmd_End 0 97 #define Cmd_Fill 1 98 #define Cmd_Stroke 2 99 #define Cmd_Solid 3 100 #define Cmd_Alpha 4 101 #define Cmd_Color 5 102 #define Cmd_Image 6 103 #define Cmd_BeginClip 7 104 #define Cmd_EndClip 8 105 #define Cmd_Jump 9 106 #define Cmd_size 12 107 108 CmdRef Cmd_index(CmdRef ref, uint index) { 109 return CmdRef(ref.offset + index * Cmd_size); 110 } 111 112 struct CmdTag { 113 uint tag; 114 uint flags; 115 }; 116 117 CmdStroke CmdStroke_read(Alloc a, CmdStrokeRef ref) { 118 uint ix = ref.offset >> 2; 119 uint raw0 = read_mem(a, ix + 0); 120 uint raw1 = read_mem(a, ix + 1); 121 CmdStroke s; 122 s.tile_ref = raw0; 123 s.half_width = uintBitsToFloat(raw1); 124 return s; 125 } 126 127 void CmdStroke_write(Alloc a, CmdStrokeRef ref, CmdStroke s) { 128 uint ix = ref.offset >> 2; 129 write_mem(a, ix + 0, s.tile_ref); 130 write_mem(a, ix + 1, floatBitsToUint(s.half_width)); 131 } 132 133 CmdFill CmdFill_read(Alloc a, CmdFillRef ref) { 134 uint ix = ref.offset >> 2; 135 uint raw0 = read_mem(a, ix + 0); 136 uint raw1 = read_mem(a, ix + 1); 137 CmdFill s; 138 s.tile_ref = raw0; 139 s.backdrop = int(raw1); 140 return s; 141 } 142 143 void CmdFill_write(Alloc a, CmdFillRef ref, CmdFill s) { 144 uint ix = ref.offset >> 2; 145 write_mem(a, ix + 0, s.tile_ref); 146 write_mem(a, ix + 1, uint(s.backdrop)); 147 } 148 149 CmdColor CmdColor_read(Alloc a, CmdColorRef ref) { 150 uint ix = ref.offset >> 2; 151 uint raw0 = read_mem(a, ix + 0); 152 CmdColor s; 153 s.rgba_color = raw0; 154 return s; 155 } 156 157 void CmdColor_write(Alloc a, CmdColorRef ref, CmdColor s) { 158 uint ix = ref.offset >> 2; 159 write_mem(a, ix + 0, s.rgba_color); 160 } 161 162 CmdImage CmdImage_read(Alloc a, CmdImageRef ref) { 163 uint ix = ref.offset >> 2; 164 uint raw0 = read_mem(a, ix + 0); 165 uint raw1 = read_mem(a, ix + 1); 166 CmdImage s; 167 s.index = raw0; 168 s.offset = ivec2(int(raw1 << 16) >> 16, int(raw1) >> 16); 169 return s; 170 } 171 172 void CmdImage_write(Alloc a, CmdImageRef ref, CmdImage s) { 173 uint ix = ref.offset >> 2; 174 write_mem(a, ix + 0, s.index); 175 write_mem(a, ix + 1, (uint(s.offset.x) & 0xffff) | (uint(s.offset.y) << 16)); 176 } 177 178 CmdAlpha CmdAlpha_read(Alloc a, CmdAlphaRef ref) { 179 uint ix = ref.offset >> 2; 180 uint raw0 = read_mem(a, ix + 0); 181 CmdAlpha s; 182 s.alpha = uintBitsToFloat(raw0); 183 return s; 184 } 185 186 void CmdAlpha_write(Alloc a, CmdAlphaRef ref, CmdAlpha s) { 187 uint ix = ref.offset >> 2; 188 write_mem(a, ix + 0, floatBitsToUint(s.alpha)); 189 } 190 191 CmdJump CmdJump_read(Alloc a, CmdJumpRef ref) { 192 uint ix = ref.offset >> 2; 193 uint raw0 = read_mem(a, ix + 0); 194 CmdJump s; 195 s.new_ref = raw0; 196 return s; 197 } 198 199 void CmdJump_write(Alloc a, CmdJumpRef ref, CmdJump s) { 200 uint ix = ref.offset >> 2; 201 write_mem(a, ix + 0, s.new_ref); 202 } 203 204 CmdTag Cmd_tag(Alloc a, CmdRef ref) { 205 uint tag_and_flags = read_mem(a, ref.offset >> 2); 206 return CmdTag(tag_and_flags & 0xffff, tag_and_flags >> 16); 207 } 208 209 CmdFill Cmd_Fill_read(Alloc a, CmdRef ref) { 210 return CmdFill_read(a, CmdFillRef(ref.offset + 4)); 211 } 212 213 CmdStroke Cmd_Stroke_read(Alloc a, CmdRef ref) { 214 return CmdStroke_read(a, CmdStrokeRef(ref.offset + 4)); 215 } 216 217 CmdAlpha Cmd_Alpha_read(Alloc a, CmdRef ref) { 218 return CmdAlpha_read(a, CmdAlphaRef(ref.offset + 4)); 219 } 220 221 CmdColor Cmd_Color_read(Alloc a, CmdRef ref) { 222 return CmdColor_read(a, CmdColorRef(ref.offset + 4)); 223 } 224 225 CmdImage Cmd_Image_read(Alloc a, CmdRef ref) { 226 return CmdImage_read(a, CmdImageRef(ref.offset + 4)); 227 } 228 229 CmdJump Cmd_Jump_read(Alloc a, CmdRef ref) { 230 return CmdJump_read(a, CmdJumpRef(ref.offset + 4)); 231 } 232 233 void Cmd_End_write(Alloc a, CmdRef ref) { 234 write_mem(a, ref.offset >> 2, Cmd_End); 235 } 236 237 void Cmd_Fill_write(Alloc a, CmdRef ref, CmdFill s) { 238 write_mem(a, ref.offset >> 2, Cmd_Fill); 239 CmdFill_write(a, CmdFillRef(ref.offset + 4), s); 240 } 241 242 void Cmd_Stroke_write(Alloc a, CmdRef ref, CmdStroke s) { 243 write_mem(a, ref.offset >> 2, Cmd_Stroke); 244 CmdStroke_write(a, CmdStrokeRef(ref.offset + 4), s); 245 } 246 247 void Cmd_Solid_write(Alloc a, CmdRef ref) { 248 write_mem(a, ref.offset >> 2, Cmd_Solid); 249 } 250 251 void Cmd_Alpha_write(Alloc a, CmdRef ref, CmdAlpha s) { 252 write_mem(a, ref.offset >> 2, Cmd_Alpha); 253 CmdAlpha_write(a, CmdAlphaRef(ref.offset + 4), s); 254 } 255 256 void Cmd_Color_write(Alloc a, CmdRef ref, CmdColor s) { 257 write_mem(a, ref.offset >> 2, Cmd_Color); 258 CmdColor_write(a, CmdColorRef(ref.offset + 4), s); 259 } 260 261 void Cmd_Image_write(Alloc a, CmdRef ref, CmdImage s) { 262 write_mem(a, ref.offset >> 2, Cmd_Image); 263 CmdImage_write(a, CmdImageRef(ref.offset + 4), s); 264 } 265 266 void Cmd_BeginClip_write(Alloc a, CmdRef ref) { 267 write_mem(a, ref.offset >> 2, Cmd_BeginClip); 268 } 269 270 void Cmd_EndClip_write(Alloc a, CmdRef ref) { 271 write_mem(a, ref.offset >> 2, Cmd_EndClip); 272 } 273 274 void Cmd_Jump_write(Alloc a, CmdRef ref, CmdJump s) { 275 write_mem(a, ref.offset >> 2, Cmd_Jump); 276 CmdJump_write(a, CmdJumpRef(ref.offset + 4), s); 277 } 278