├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── README.md ├── build.rs ├── kernels └── collatz │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ └── lib.rs ├── rust-toolchain └── src └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "ahash" 7 | version = "0.7.6" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" 10 | dependencies = [ 11 | "getrandom", 12 | "once_cell", 13 | "version_check", 14 | ] 15 | 16 | [[package]] 17 | name = "ar" 18 | version = "0.9.0" 19 | source = "registry+https://github.com/rust-lang/crates.io-index" 20 | checksum = "d67af77d68a931ecd5cbd8a3b5987d63a1d1d1278f7f6a60ae33db485cdebb69" 21 | 22 | [[package]] 23 | name = "arrayvec" 24 | version = "0.7.2" 25 | source = "registry+https://github.com/rust-lang/crates.io-index" 26 | checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" 27 | 28 | [[package]] 29 | name = "ash" 30 | version = "0.35.2+1.2.203" 31 | source = "registry+https://github.com/rust-lang/crates.io-index" 32 | checksum = "8f6a491bcad4563b355ac2bb6e3f09d5e1c5d628710c7156e901dad0c416075e" 33 | dependencies = [ 34 | "libloading", 35 | ] 36 | 37 | [[package]] 38 | name = "autocfg" 39 | version = "1.1.0" 40 | source = "registry+https://github.com/rust-lang/crates.io-index" 41 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 42 | 43 | [[package]] 44 | name = "bimap" 45 | version = "0.6.2" 46 | source = "registry+https://github.com/rust-lang/crates.io-index" 47 | checksum = "bc0455254eb5c6964c4545d8bac815e1a1be4f3afe0ae695ea539c12d728d44b" 48 | 49 | [[package]] 50 | name = "bit-set" 51 | version = "0.5.2" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" 54 | dependencies = [ 55 | "bit-vec", 56 | ] 57 | 58 | [[package]] 59 | name = "bit-vec" 60 | version = "0.6.3" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" 63 | 64 | [[package]] 65 | name = "bitflags" 66 | version = "1.3.2" 67 | source = "registry+https://github.com/rust-lang/crates.io-index" 68 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 69 | 70 | [[package]] 71 | name = "block" 72 | version = "0.1.6" 73 | source = "registry+https://github.com/rust-lang/crates.io-index" 74 | checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" 75 | 76 | [[package]] 77 | name = "bumpalo" 78 | version = "3.9.1" 79 | source = "registry+https://github.com/rust-lang/crates.io-index" 80 | checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" 81 | 82 | [[package]] 83 | name = "byteorder" 84 | version = "1.4.3" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" 87 | 88 | [[package]] 89 | name = "cc" 90 | version = "1.0.73" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" 93 | dependencies = [ 94 | "jobserver", 95 | ] 96 | 97 | [[package]] 98 | name = "cfg-if" 99 | version = "1.0.0" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 102 | 103 | [[package]] 104 | name = "cfg_aliases" 105 | version = "0.1.1" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" 108 | 109 | [[package]] 110 | name = "codespan-reporting" 111 | version = "0.11.1" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" 114 | dependencies = [ 115 | "termcolor", 116 | "unicode-width", 117 | ] 118 | 119 | [[package]] 120 | name = "copyless" 121 | version = "0.1.5" 122 | source = "registry+https://github.com/rust-lang/crates.io-index" 123 | checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536" 124 | 125 | [[package]] 126 | name = "core-foundation" 127 | version = "0.9.3" 128 | source = "registry+https://github.com/rust-lang/crates.io-index" 129 | checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" 130 | dependencies = [ 131 | "core-foundation-sys", 132 | "libc", 133 | ] 134 | 135 | [[package]] 136 | name = "core-foundation-sys" 137 | version = "0.8.3" 138 | source = "registry+https://github.com/rust-lang/crates.io-index" 139 | checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" 140 | 141 | [[package]] 142 | name = "core-graphics-types" 143 | version = "0.1.1" 144 | source = "registry+https://github.com/rust-lang/crates.io-index" 145 | checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" 146 | dependencies = [ 147 | "bitflags", 148 | "core-foundation", 149 | "foreign-types", 150 | "libc", 151 | ] 152 | 153 | [[package]] 154 | name = "cty" 155 | version = "0.2.2" 156 | source = "registry+https://github.com/rust-lang/crates.io-index" 157 | checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" 158 | 159 | [[package]] 160 | name = "d3d12" 161 | version = "0.4.1" 162 | source = "registry+https://github.com/rust-lang/crates.io-index" 163 | checksum = "2daefd788d1e96e0a9d66dee4b828b883509bc3ea9ce30665f04c3246372690c" 164 | dependencies = [ 165 | "bitflags", 166 | "libloading", 167 | "winapi", 168 | ] 169 | 170 | [[package]] 171 | name = "fixedbitset" 172 | version = "0.4.1" 173 | source = "registry+https://github.com/rust-lang/crates.io-index" 174 | checksum = "279fb028e20b3c4c320317955b77c5e0c9701f05a1d309905d6fc702cdc5053e" 175 | 176 | [[package]] 177 | name = "foreign-types" 178 | version = "0.3.2" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" 181 | dependencies = [ 182 | "foreign-types-shared", 183 | ] 184 | 185 | [[package]] 186 | name = "foreign-types-shared" 187 | version = "0.1.1" 188 | source = "registry+https://github.com/rust-lang/crates.io-index" 189 | checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" 190 | 191 | [[package]] 192 | name = "futures" 193 | version = "0.3.21" 194 | source = "registry+https://github.com/rust-lang/crates.io-index" 195 | checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" 196 | dependencies = [ 197 | "futures-channel", 198 | "futures-core", 199 | "futures-executor", 200 | "futures-io", 201 | "futures-sink", 202 | "futures-task", 203 | "futures-util", 204 | ] 205 | 206 | [[package]] 207 | name = "futures-channel" 208 | version = "0.3.21" 209 | source = "registry+https://github.com/rust-lang/crates.io-index" 210 | checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" 211 | dependencies = [ 212 | "futures-core", 213 | "futures-sink", 214 | ] 215 | 216 | [[package]] 217 | name = "futures-core" 218 | version = "0.3.21" 219 | source = "registry+https://github.com/rust-lang/crates.io-index" 220 | checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" 221 | 222 | [[package]] 223 | name = "futures-executor" 224 | version = "0.3.21" 225 | source = "registry+https://github.com/rust-lang/crates.io-index" 226 | checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6" 227 | dependencies = [ 228 | "futures-core", 229 | "futures-task", 230 | "futures-util", 231 | ] 232 | 233 | [[package]] 234 | name = "futures-io" 235 | version = "0.3.21" 236 | source = "registry+https://github.com/rust-lang/crates.io-index" 237 | checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" 238 | 239 | [[package]] 240 | name = "futures-sink" 241 | version = "0.3.21" 242 | source = "registry+https://github.com/rust-lang/crates.io-index" 243 | checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" 244 | 245 | [[package]] 246 | name = "futures-task" 247 | version = "0.3.21" 248 | source = "registry+https://github.com/rust-lang/crates.io-index" 249 | checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" 250 | 251 | [[package]] 252 | name = "futures-util" 253 | version = "0.3.21" 254 | source = "registry+https://github.com/rust-lang/crates.io-index" 255 | checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" 256 | dependencies = [ 257 | "futures-channel", 258 | "futures-core", 259 | "futures-io", 260 | "futures-sink", 261 | "futures-task", 262 | "memchr", 263 | "pin-project-lite", 264 | "pin-utils", 265 | "slab", 266 | ] 267 | 268 | [[package]] 269 | name = "fxhash" 270 | version = "0.2.1" 271 | source = "registry+https://github.com/rust-lang/crates.io-index" 272 | checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" 273 | dependencies = [ 274 | "byteorder", 275 | ] 276 | 277 | [[package]] 278 | name = "getrandom" 279 | version = "0.2.5" 280 | source = "registry+https://github.com/rust-lang/crates.io-index" 281 | checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" 282 | dependencies = [ 283 | "cfg-if", 284 | "libc", 285 | "wasi", 286 | ] 287 | 288 | [[package]] 289 | name = "glow" 290 | version = "0.11.2" 291 | source = "registry+https://github.com/rust-lang/crates.io-index" 292 | checksum = "d8bd5877156a19b8ac83a29b2306fe20537429d318f3ff0a1a2119f8d9c61919" 293 | dependencies = [ 294 | "js-sys", 295 | "slotmap", 296 | "wasm-bindgen", 297 | "web-sys", 298 | ] 299 | 300 | [[package]] 301 | name = "gpu-alloc" 302 | version = "0.5.3" 303 | source = "registry+https://github.com/rust-lang/crates.io-index" 304 | checksum = "7fc59e5f710e310e76e6707f86c561dd646f69a8876da9131703b2f717de818d" 305 | dependencies = [ 306 | "bitflags", 307 | "gpu-alloc-types", 308 | ] 309 | 310 | [[package]] 311 | name = "gpu-alloc-types" 312 | version = "0.2.0" 313 | source = "registry+https://github.com/rust-lang/crates.io-index" 314 | checksum = "54804d0d6bc9d7f26db4eaec1ad10def69b599315f487d32c334a80d1efe67a5" 315 | dependencies = [ 316 | "bitflags", 317 | ] 318 | 319 | [[package]] 320 | name = "gpu-descriptor" 321 | version = "0.2.2" 322 | source = "registry+https://github.com/rust-lang/crates.io-index" 323 | checksum = "a538f217be4d405ff4719a283ca68323cc2384003eca5baaa87501e821c81dda" 324 | dependencies = [ 325 | "bitflags", 326 | "gpu-descriptor-types", 327 | "hashbrown", 328 | ] 329 | 330 | [[package]] 331 | name = "gpu-descriptor-types" 332 | version = "0.1.1" 333 | source = "registry+https://github.com/rust-lang/crates.io-index" 334 | checksum = "363e3677e55ad168fef68cf9de3a4a310b53124c5e784c53a1d70e92d23f2126" 335 | dependencies = [ 336 | "bitflags", 337 | ] 338 | 339 | [[package]] 340 | name = "hashbrown" 341 | version = "0.11.2" 342 | source = "registry+https://github.com/rust-lang/crates.io-index" 343 | checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" 344 | dependencies = [ 345 | "ahash", 346 | ] 347 | 348 | [[package]] 349 | name = "hexf-parse" 350 | version = "0.2.1" 351 | source = "registry+https://github.com/rust-lang/crates.io-index" 352 | checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" 353 | 354 | [[package]] 355 | name = "indexmap" 356 | version = "1.8.0" 357 | source = "registry+https://github.com/rust-lang/crates.io-index" 358 | checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" 359 | dependencies = [ 360 | "autocfg", 361 | "hashbrown", 362 | ] 363 | 364 | [[package]] 365 | name = "inplace_it" 366 | version = "0.3.3" 367 | source = "registry+https://github.com/rust-lang/crates.io-index" 368 | checksum = "90953f308a79fe6d62a4643e51f848fbfddcd05975a38e69fdf4ab86a7baf7ca" 369 | 370 | [[package]] 371 | name = "instant" 372 | version = "0.1.12" 373 | source = "registry+https://github.com/rust-lang/crates.io-index" 374 | checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" 375 | dependencies = [ 376 | "cfg-if", 377 | "js-sys", 378 | "wasm-bindgen", 379 | "web-sys", 380 | ] 381 | 382 | [[package]] 383 | name = "itoa" 384 | version = "1.0.1" 385 | source = "registry+https://github.com/rust-lang/crates.io-index" 386 | checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" 387 | 388 | [[package]] 389 | name = "jobserver" 390 | version = "0.1.24" 391 | source = "registry+https://github.com/rust-lang/crates.io-index" 392 | checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" 393 | dependencies = [ 394 | "libc", 395 | ] 396 | 397 | [[package]] 398 | name = "js-sys" 399 | version = "0.3.56" 400 | source = "registry+https://github.com/rust-lang/crates.io-index" 401 | checksum = "a38fc24e30fd564ce974c02bf1d337caddff65be6cc4735a1f7eab22a7440f04" 402 | dependencies = [ 403 | "wasm-bindgen", 404 | ] 405 | 406 | [[package]] 407 | name = "khronos-egl" 408 | version = "4.1.0" 409 | source = "registry+https://github.com/rust-lang/crates.io-index" 410 | checksum = "8c2352bd1d0bceb871cb9d40f24360c8133c11d7486b68b5381c1dd1a32015e3" 411 | dependencies = [ 412 | "libc", 413 | "libloading", 414 | "pkg-config", 415 | ] 416 | 417 | [[package]] 418 | name = "lazy_static" 419 | version = "1.4.0" 420 | source = "registry+https://github.com/rust-lang/crates.io-index" 421 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 422 | 423 | [[package]] 424 | name = "libc" 425 | version = "0.2.119" 426 | source = "registry+https://github.com/rust-lang/crates.io-index" 427 | checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" 428 | 429 | [[package]] 430 | name = "libloading" 431 | version = "0.7.3" 432 | source = "registry+https://github.com/rust-lang/crates.io-index" 433 | checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" 434 | dependencies = [ 435 | "cfg-if", 436 | "winapi", 437 | ] 438 | 439 | [[package]] 440 | name = "libm" 441 | version = "0.2.2" 442 | source = "registry+https://github.com/rust-lang/crates.io-index" 443 | checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db" 444 | 445 | [[package]] 446 | name = "lock_api" 447 | version = "0.4.6" 448 | source = "registry+https://github.com/rust-lang/crates.io-index" 449 | checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" 450 | dependencies = [ 451 | "scopeguard", 452 | ] 453 | 454 | [[package]] 455 | name = "log" 456 | version = "0.4.14" 457 | source = "registry+https://github.com/rust-lang/crates.io-index" 458 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" 459 | dependencies = [ 460 | "cfg-if", 461 | ] 462 | 463 | [[package]] 464 | name = "malloc_buf" 465 | version = "0.0.6" 466 | source = "registry+https://github.com/rust-lang/crates.io-index" 467 | checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" 468 | dependencies = [ 469 | "libc", 470 | ] 471 | 472 | [[package]] 473 | name = "memchr" 474 | version = "2.4.1" 475 | source = "registry+https://github.com/rust-lang/crates.io-index" 476 | checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" 477 | 478 | [[package]] 479 | name = "metal" 480 | version = "0.23.1" 481 | source = "git+https://github.com/gfx-rs/metal-rs?rev=a357159#a35715916fec38bbc08a510ecf7d115edc500c72" 482 | dependencies = [ 483 | "bitflags", 484 | "block", 485 | "core-graphics-types", 486 | "foreign-types", 487 | "log", 488 | "objc", 489 | ] 490 | 491 | [[package]] 492 | name = "naga" 493 | version = "0.8.0" 494 | source = "git+https://github.com/gfx-rs/naga?rev=a45b9a6#a45b9a6cc691a671aa24a32114b51c5acae02420" 495 | dependencies = [ 496 | "bit-set", 497 | "bitflags", 498 | "codespan-reporting", 499 | "hexf-parse", 500 | "indexmap", 501 | "log", 502 | "num-traits", 503 | "petgraph", 504 | "rustc-hash", 505 | "spirv", 506 | "thiserror", 507 | ] 508 | 509 | [[package]] 510 | name = "num-traits" 511 | version = "0.2.14" 512 | source = "registry+https://github.com/rust-lang/crates.io-index" 513 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" 514 | dependencies = [ 515 | "autocfg", 516 | "libm", 517 | ] 518 | 519 | [[package]] 520 | name = "objc" 521 | version = "0.2.7" 522 | source = "registry+https://github.com/rust-lang/crates.io-index" 523 | checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" 524 | dependencies = [ 525 | "malloc_buf", 526 | "objc_exception", 527 | ] 528 | 529 | [[package]] 530 | name = "objc_exception" 531 | version = "0.1.2" 532 | source = "registry+https://github.com/rust-lang/crates.io-index" 533 | checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4" 534 | dependencies = [ 535 | "cc", 536 | ] 537 | 538 | [[package]] 539 | name = "once_cell" 540 | version = "1.10.0" 541 | source = "registry+https://github.com/rust-lang/crates.io-index" 542 | checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" 543 | 544 | [[package]] 545 | name = "parking_lot" 546 | version = "0.11.2" 547 | source = "registry+https://github.com/rust-lang/crates.io-index" 548 | checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" 549 | dependencies = [ 550 | "instant", 551 | "lock_api", 552 | "parking_lot_core", 553 | ] 554 | 555 | [[package]] 556 | name = "parking_lot_core" 557 | version = "0.8.5" 558 | source = "registry+https://github.com/rust-lang/crates.io-index" 559 | checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" 560 | dependencies = [ 561 | "cfg-if", 562 | "instant", 563 | "libc", 564 | "redox_syscall", 565 | "smallvec", 566 | "winapi", 567 | ] 568 | 569 | [[package]] 570 | name = "petgraph" 571 | version = "0.6.0" 572 | source = "registry+https://github.com/rust-lang/crates.io-index" 573 | checksum = "4a13a2fa9d0b63e5f22328828741e523766fff0ee9e779316902290dff3f824f" 574 | dependencies = [ 575 | "fixedbitset", 576 | "indexmap", 577 | ] 578 | 579 | [[package]] 580 | name = "pin-project-lite" 581 | version = "0.2.8" 582 | source = "registry+https://github.com/rust-lang/crates.io-index" 583 | checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" 584 | 585 | [[package]] 586 | name = "pin-utils" 587 | version = "0.1.0" 588 | source = "registry+https://github.com/rust-lang/crates.io-index" 589 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 590 | 591 | [[package]] 592 | name = "pkg-config" 593 | version = "0.3.24" 594 | source = "registry+https://github.com/rust-lang/crates.io-index" 595 | checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" 596 | 597 | [[package]] 598 | name = "proc-macro2" 599 | version = "1.0.36" 600 | source = "registry+https://github.com/rust-lang/crates.io-index" 601 | checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" 602 | dependencies = [ 603 | "unicode-xid", 604 | ] 605 | 606 | [[package]] 607 | name = "profiling" 608 | version = "1.0.5" 609 | source = "registry+https://github.com/rust-lang/crates.io-index" 610 | checksum = "9145ac0af1d93c638c98c40cf7d25665f427b2a44ad0a99b1dccf3e2f25bb987" 611 | 612 | [[package]] 613 | name = "quote" 614 | version = "1.0.15" 615 | source = "registry+https://github.com/rust-lang/crates.io-index" 616 | checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" 617 | dependencies = [ 618 | "proc-macro2", 619 | ] 620 | 621 | [[package]] 622 | name = "range-alloc" 623 | version = "0.1.2" 624 | source = "registry+https://github.com/rust-lang/crates.io-index" 625 | checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6" 626 | 627 | [[package]] 628 | name = "raw-string" 629 | version = "0.3.5" 630 | source = "registry+https://github.com/rust-lang/crates.io-index" 631 | checksum = "e0501e134c6905fee1f10fed25b0a7e1261bf676cffac9543a7d0730dec01af2" 632 | 633 | [[package]] 634 | name = "raw-window-handle" 635 | version = "0.4.2" 636 | source = "registry+https://github.com/rust-lang/crates.io-index" 637 | checksum = "fba75eee94a9d5273a68c9e1e105d9cffe1ef700532325788389e5a83e2522b7" 638 | dependencies = [ 639 | "cty", 640 | ] 641 | 642 | [[package]] 643 | name = "redox_syscall" 644 | version = "0.2.11" 645 | source = "registry+https://github.com/rust-lang/crates.io-index" 646 | checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c" 647 | dependencies = [ 648 | "bitflags", 649 | ] 650 | 651 | [[package]] 652 | name = "regex" 653 | version = "1.5.5" 654 | source = "registry+https://github.com/rust-lang/crates.io-index" 655 | checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" 656 | dependencies = [ 657 | "regex-syntax", 658 | ] 659 | 660 | [[package]] 661 | name = "regex-syntax" 662 | version = "0.6.25" 663 | source = "registry+https://github.com/rust-lang/crates.io-index" 664 | checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" 665 | 666 | [[package]] 667 | name = "renderdoc-sys" 668 | version = "0.7.1" 669 | source = "registry+https://github.com/rust-lang/crates.io-index" 670 | checksum = "f1382d1f0a252c4bf97dc20d979a2fdd05b024acd7c2ed0f7595d7817666a157" 671 | 672 | [[package]] 673 | name = "rspirv" 674 | version = "0.11.0+1.5.4" 675 | source = "registry+https://github.com/rust-lang/crates.io-index" 676 | checksum = "1503993b59ca9ae4127365c3293517576d7ce56be9f3d8abb1625c85ddc583ba" 677 | dependencies = [ 678 | "fxhash", 679 | "num-traits", 680 | "spirv", 681 | ] 682 | 683 | [[package]] 684 | name = "rust-gpu-wgpu-compute-minimal" 685 | version = "0.1.0" 686 | dependencies = [ 687 | "futures", 688 | "spirv-builder", 689 | "wgpu", 690 | ] 691 | 692 | [[package]] 693 | name = "rustc-demangle" 694 | version = "0.1.21" 695 | source = "registry+https://github.com/rust-lang/crates.io-index" 696 | checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" 697 | 698 | [[package]] 699 | name = "rustc-hash" 700 | version = "1.1.0" 701 | source = "registry+https://github.com/rust-lang/crates.io-index" 702 | checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" 703 | 704 | [[package]] 705 | name = "rustc_codegen_spirv" 706 | version = "0.4.0-alpha.12" 707 | source = "git+https://github.com/EmbarkStudios/rust-gpu#4932a44658724d46be3d4c8ef81bf096ab1de9eb" 708 | dependencies = [ 709 | "ar", 710 | "bimap", 711 | "hashbrown", 712 | "indexmap", 713 | "libc", 714 | "num-traits", 715 | "rspirv", 716 | "rustc-demangle", 717 | "sanitize-filename", 718 | "serde", 719 | "serde_json", 720 | "smallvec", 721 | "spirv-tools", 722 | "syn", 723 | ] 724 | 725 | [[package]] 726 | name = "ryu" 727 | version = "1.0.9" 728 | source = "registry+https://github.com/rust-lang/crates.io-index" 729 | checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" 730 | 731 | [[package]] 732 | name = "sanitize-filename" 733 | version = "0.3.0" 734 | source = "registry+https://github.com/rust-lang/crates.io-index" 735 | checksum = "bf18934a12018228c5b55a6dae9df5d0641e3566b3630cb46cc55564068e7c2f" 736 | dependencies = [ 737 | "lazy_static", 738 | "regex", 739 | ] 740 | 741 | [[package]] 742 | name = "scopeguard" 743 | version = "1.1.0" 744 | source = "registry+https://github.com/rust-lang/crates.io-index" 745 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 746 | 747 | [[package]] 748 | name = "serde" 749 | version = "1.0.136" 750 | source = "registry+https://github.com/rust-lang/crates.io-index" 751 | checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" 752 | dependencies = [ 753 | "serde_derive", 754 | ] 755 | 756 | [[package]] 757 | name = "serde_derive" 758 | version = "1.0.136" 759 | source = "registry+https://github.com/rust-lang/crates.io-index" 760 | checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" 761 | dependencies = [ 762 | "proc-macro2", 763 | "quote", 764 | "syn", 765 | ] 766 | 767 | [[package]] 768 | name = "serde_json" 769 | version = "1.0.79" 770 | source = "registry+https://github.com/rust-lang/crates.io-index" 771 | checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" 772 | dependencies = [ 773 | "itoa", 774 | "ryu", 775 | "serde", 776 | ] 777 | 778 | [[package]] 779 | name = "slab" 780 | version = "0.4.5" 781 | source = "registry+https://github.com/rust-lang/crates.io-index" 782 | checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" 783 | 784 | [[package]] 785 | name = "slotmap" 786 | version = "1.0.6" 787 | source = "registry+https://github.com/rust-lang/crates.io-index" 788 | checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342" 789 | dependencies = [ 790 | "version_check", 791 | ] 792 | 793 | [[package]] 794 | name = "smallvec" 795 | version = "1.8.0" 796 | source = "registry+https://github.com/rust-lang/crates.io-index" 797 | checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" 798 | 799 | [[package]] 800 | name = "spirv" 801 | version = "0.2.0+1.5.4" 802 | source = "registry+https://github.com/rust-lang/crates.io-index" 803 | checksum = "246bfa38fe3db3f1dfc8ca5a2cdeb7348c78be2112740cc0ec8ef18b6d94f830" 804 | dependencies = [ 805 | "bitflags", 806 | "num-traits", 807 | ] 808 | 809 | [[package]] 810 | name = "spirv-builder" 811 | version = "0.4.0-alpha.12" 812 | source = "git+https://github.com/EmbarkStudios/rust-gpu#4932a44658724d46be3d4c8ef81bf096ab1de9eb" 813 | dependencies = [ 814 | "memchr", 815 | "raw-string", 816 | "rustc_codegen_spirv", 817 | "serde", 818 | "serde_json", 819 | ] 820 | 821 | [[package]] 822 | name = "spirv-tools" 823 | version = "0.8.0" 824 | source = "registry+https://github.com/rust-lang/crates.io-index" 825 | checksum = "ca7f0f689581589b0a31000317fa31257cb24d040227708718ebd9fedf5cdd2b" 826 | dependencies = [ 827 | "spirv-tools-sys", 828 | ] 829 | 830 | [[package]] 831 | name = "spirv-tools-sys" 832 | version = "0.6.0" 833 | source = "registry+https://github.com/rust-lang/crates.io-index" 834 | checksum = "2980b0b4b2a9b5edfeb1dc8a35e84aac07b9c6dcd2339cce004d9355fb62a59d" 835 | dependencies = [ 836 | "cc", 837 | ] 838 | 839 | [[package]] 840 | name = "syn" 841 | version = "1.0.86" 842 | source = "registry+https://github.com/rust-lang/crates.io-index" 843 | checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" 844 | dependencies = [ 845 | "proc-macro2", 846 | "quote", 847 | "unicode-xid", 848 | ] 849 | 850 | [[package]] 851 | name = "termcolor" 852 | version = "1.1.3" 853 | source = "registry+https://github.com/rust-lang/crates.io-index" 854 | checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" 855 | dependencies = [ 856 | "winapi-util", 857 | ] 858 | 859 | [[package]] 860 | name = "thiserror" 861 | version = "1.0.30" 862 | source = "registry+https://github.com/rust-lang/crates.io-index" 863 | checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" 864 | dependencies = [ 865 | "thiserror-impl", 866 | ] 867 | 868 | [[package]] 869 | name = "thiserror-impl" 870 | version = "1.0.30" 871 | source = "registry+https://github.com/rust-lang/crates.io-index" 872 | checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" 873 | dependencies = [ 874 | "proc-macro2", 875 | "quote", 876 | "syn", 877 | ] 878 | 879 | [[package]] 880 | name = "unicode-width" 881 | version = "0.1.9" 882 | source = "registry+https://github.com/rust-lang/crates.io-index" 883 | checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" 884 | 885 | [[package]] 886 | name = "unicode-xid" 887 | version = "0.2.2" 888 | source = "registry+https://github.com/rust-lang/crates.io-index" 889 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 890 | 891 | [[package]] 892 | name = "version_check" 893 | version = "0.9.4" 894 | source = "registry+https://github.com/rust-lang/crates.io-index" 895 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 896 | 897 | [[package]] 898 | name = "wasi" 899 | version = "0.10.2+wasi-snapshot-preview1" 900 | source = "registry+https://github.com/rust-lang/crates.io-index" 901 | checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" 902 | 903 | [[package]] 904 | name = "wasm-bindgen" 905 | version = "0.2.79" 906 | source = "registry+https://github.com/rust-lang/crates.io-index" 907 | checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06" 908 | dependencies = [ 909 | "cfg-if", 910 | "wasm-bindgen-macro", 911 | ] 912 | 913 | [[package]] 914 | name = "wasm-bindgen-backend" 915 | version = "0.2.79" 916 | source = "registry+https://github.com/rust-lang/crates.io-index" 917 | checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca" 918 | dependencies = [ 919 | "bumpalo", 920 | "lazy_static", 921 | "log", 922 | "proc-macro2", 923 | "quote", 924 | "syn", 925 | "wasm-bindgen-shared", 926 | ] 927 | 928 | [[package]] 929 | name = "wasm-bindgen-futures" 930 | version = "0.4.29" 931 | source = "registry+https://github.com/rust-lang/crates.io-index" 932 | checksum = "2eb6ec270a31b1d3c7e266b999739109abce8b6c87e4b31fcfcd788b65267395" 933 | dependencies = [ 934 | "cfg-if", 935 | "js-sys", 936 | "wasm-bindgen", 937 | "web-sys", 938 | ] 939 | 940 | [[package]] 941 | name = "wasm-bindgen-macro" 942 | version = "0.2.79" 943 | source = "registry+https://github.com/rust-lang/crates.io-index" 944 | checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01" 945 | dependencies = [ 946 | "quote", 947 | "wasm-bindgen-macro-support", 948 | ] 949 | 950 | [[package]] 951 | name = "wasm-bindgen-macro-support" 952 | version = "0.2.79" 953 | source = "registry+https://github.com/rust-lang/crates.io-index" 954 | checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" 955 | dependencies = [ 956 | "proc-macro2", 957 | "quote", 958 | "syn", 959 | "wasm-bindgen-backend", 960 | "wasm-bindgen-shared", 961 | ] 962 | 963 | [[package]] 964 | name = "wasm-bindgen-shared" 965 | version = "0.2.79" 966 | source = "registry+https://github.com/rust-lang/crates.io-index" 967 | checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" 968 | 969 | [[package]] 970 | name = "web-sys" 971 | version = "0.3.56" 972 | source = "registry+https://github.com/rust-lang/crates.io-index" 973 | checksum = "c060b319f29dd25724f09a2ba1418f142f539b2be99fbf4d2d5a8f7330afb8eb" 974 | dependencies = [ 975 | "js-sys", 976 | "wasm-bindgen", 977 | ] 978 | 979 | [[package]] 980 | name = "wgpu" 981 | version = "0.12.0" 982 | source = "git+https://github.com/gfx-rs/wgpu#0ac9ce002656565ccd05b889f5856f4e2c38fa73" 983 | dependencies = [ 984 | "arrayvec", 985 | "js-sys", 986 | "log", 987 | "naga", 988 | "parking_lot", 989 | "raw-window-handle", 990 | "smallvec", 991 | "wasm-bindgen", 992 | "wasm-bindgen-futures", 993 | "web-sys", 994 | "wgpu-core", 995 | "wgpu-hal", 996 | "wgpu-types", 997 | ] 998 | 999 | [[package]] 1000 | name = "wgpu-core" 1001 | version = "0.12.0" 1002 | source = "git+https://github.com/gfx-rs/wgpu#0ac9ce002656565ccd05b889f5856f4e2c38fa73" 1003 | dependencies = [ 1004 | "arrayvec", 1005 | "bitflags", 1006 | "cfg_aliases", 1007 | "codespan-reporting", 1008 | "copyless", 1009 | "fxhash", 1010 | "log", 1011 | "naga", 1012 | "parking_lot", 1013 | "profiling", 1014 | "raw-window-handle", 1015 | "smallvec", 1016 | "thiserror", 1017 | "wgpu-hal", 1018 | "wgpu-types", 1019 | ] 1020 | 1021 | [[package]] 1022 | name = "wgpu-hal" 1023 | version = "0.12.0" 1024 | source = "git+https://github.com/gfx-rs/wgpu#0ac9ce002656565ccd05b889f5856f4e2c38fa73" 1025 | dependencies = [ 1026 | "arrayvec", 1027 | "ash", 1028 | "bit-set", 1029 | "bitflags", 1030 | "block", 1031 | "core-graphics-types", 1032 | "d3d12", 1033 | "foreign-types", 1034 | "fxhash", 1035 | "glow", 1036 | "gpu-alloc", 1037 | "gpu-descriptor", 1038 | "inplace_it", 1039 | "js-sys", 1040 | "khronos-egl", 1041 | "libloading", 1042 | "log", 1043 | "metal", 1044 | "naga", 1045 | "objc", 1046 | "parking_lot", 1047 | "profiling", 1048 | "range-alloc", 1049 | "raw-window-handle", 1050 | "renderdoc-sys", 1051 | "thiserror", 1052 | "wasm-bindgen", 1053 | "web-sys", 1054 | "wgpu-types", 1055 | "winapi", 1056 | ] 1057 | 1058 | [[package]] 1059 | name = "wgpu-types" 1060 | version = "0.12.0" 1061 | source = "git+https://github.com/gfx-rs/wgpu#0ac9ce002656565ccd05b889f5856f4e2c38fa73" 1062 | dependencies = [ 1063 | "bitflags", 1064 | ] 1065 | 1066 | [[package]] 1067 | name = "winapi" 1068 | version = "0.3.9" 1069 | source = "registry+https://github.com/rust-lang/crates.io-index" 1070 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 1071 | dependencies = [ 1072 | "winapi-i686-pc-windows-gnu", 1073 | "winapi-x86_64-pc-windows-gnu", 1074 | ] 1075 | 1076 | [[package]] 1077 | name = "winapi-i686-pc-windows-gnu" 1078 | version = "0.4.0" 1079 | source = "registry+https://github.com/rust-lang/crates.io-index" 1080 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1081 | 1082 | [[package]] 1083 | name = "winapi-util" 1084 | version = "0.1.5" 1085 | source = "registry+https://github.com/rust-lang/crates.io-index" 1086 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 1087 | dependencies = [ 1088 | "winapi", 1089 | ] 1090 | 1091 | [[package]] 1092 | name = "winapi-x86_64-pc-windows-gnu" 1093 | version = "0.4.0" 1094 | source = "registry+https://github.com/rust-lang/crates.io-index" 1095 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 1096 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust-gpu-wgpu-compute-minimal" 3 | version = "0.1.0" 4 | edition = "2021" 5 | authors = ["Andrew Korzhuev "] 6 | description = "Minimal rust-gpu compute shader example running on WGPU backend with Vulkan support" 7 | keywords = ["rust-gpu", "wgpu", "compute-shader", "vulkan"] 8 | 9 | 10 | [dependencies] 11 | futures = { version = "0.3", default-features = false, features = ["std", "executor"] } 12 | wgpu = { git = "https://github.com/gfx-rs/wgpu", features = ["spirv", "vulkan-portability"] } 13 | 14 | [build-dependencies] 15 | spirv-builder = { git = "https://github.com/EmbarkStudios/rust-gpu" } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Minimal Compute Shader Project 2 | 3 | Uses [rust-gpu](https://github.com/EmbarkStudios/rust-gpu/) to compile shader into SPIR-V, which is then submitted by the [wgpu](https://github.com/gfx-rs/wgpu) backend running in [Vulkan 4 | ](https://www.vulkan.org/) compatibility mode. Requires [MoltenVK](https://moltengl.com/moltenvk/) for compatibility with [Metal](https://en.wikipedia.org/wiki/Metal_(API)) on macOs. 5 | 6 | See also [pema99/rust-gpu-compute-example](https://github.com/pema99/rust-gpu-compute-example) and [rust-gpu/examples](https://github.com/EmbarkStudios/rust-gpu/tree/main/examples). 7 | 8 | ## Notes 9 | 10 | - Each shader is defined as a bin crate and is compiled separately, see [build.rs](./build.rs) using [spirv-builder](https://github.com/EmbarkStudios/rust-gpu/tree/main/crates/spirv-builder) -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | use spirv_builder::SpirvBuilder; 2 | 3 | fn main() { 4 | for kernel in std::fs::read_dir("kernels").expect("Error finding kernels folder") { 5 | let path = kernel.expect("Invalid path in kernels folder").path(); 6 | SpirvBuilder::new(path, "spirv-unknown-vulkan1.1") 7 | .build() 8 | .expect("Kernel failed to compile"); 9 | } 10 | } -------------------------------------------------------------------------------- /kernels/collatz/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "autocfg" 7 | version = "1.1.0" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 10 | 11 | [[package]] 12 | name = "bitflags" 13 | version = "1.3.2" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 16 | 17 | [[package]] 18 | name = "collatz" 19 | version = "0.1.0" 20 | dependencies = [ 21 | "spirv-std", 22 | ] 23 | 24 | [[package]] 25 | name = "glam" 26 | version = "0.20.2" 27 | source = "registry+https://github.com/rust-lang/crates.io-index" 28 | checksum = "e4fa84eead97d5412b2a20aed4d66612a97a9e41e08eababdb9ae2bf88667490" 29 | dependencies = [ 30 | "num-traits", 31 | ] 32 | 33 | [[package]] 34 | name = "libm" 35 | version = "0.2.2" 36 | source = "registry+https://github.com/rust-lang/crates.io-index" 37 | checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db" 38 | 39 | [[package]] 40 | name = "num-traits" 41 | version = "0.2.14" 42 | source = "registry+https://github.com/rust-lang/crates.io-index" 43 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" 44 | dependencies = [ 45 | "autocfg", 46 | "libm", 47 | ] 48 | 49 | [[package]] 50 | name = "proc-macro2" 51 | version = "1.0.36" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" 54 | dependencies = [ 55 | "unicode-xid", 56 | ] 57 | 58 | [[package]] 59 | name = "quote" 60 | version = "1.0.15" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" 63 | dependencies = [ 64 | "proc-macro2", 65 | ] 66 | 67 | [[package]] 68 | name = "spirv-std" 69 | version = "0.4.0-alpha.12" 70 | source = "git+https://github.com/EmbarkStudios/rust-gpu#4932a44658724d46be3d4c8ef81bf096ab1de9eb" 71 | dependencies = [ 72 | "bitflags", 73 | "glam", 74 | "num-traits", 75 | "spirv-std-macros", 76 | "spirv-types", 77 | ] 78 | 79 | [[package]] 80 | name = "spirv-std-macros" 81 | version = "0.4.0-alpha.12" 82 | source = "git+https://github.com/EmbarkStudios/rust-gpu#4932a44658724d46be3d4c8ef81bf096ab1de9eb" 83 | dependencies = [ 84 | "proc-macro2", 85 | "quote", 86 | "spirv-types", 87 | "syn", 88 | ] 89 | 90 | [[package]] 91 | name = "spirv-types" 92 | version = "0.4.0-alpha.12" 93 | source = "git+https://github.com/EmbarkStudios/rust-gpu#4932a44658724d46be3d4c8ef81bf096ab1de9eb" 94 | 95 | [[package]] 96 | name = "syn" 97 | version = "1.0.86" 98 | source = "registry+https://github.com/rust-lang/crates.io-index" 99 | checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" 100 | dependencies = [ 101 | "proc-macro2", 102 | "quote", 103 | "unicode-xid", 104 | ] 105 | 106 | [[package]] 107 | name = "unicode-xid" 108 | version = "0.2.2" 109 | source = "registry+https://github.com/rust-lang/crates.io-index" 110 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 111 | -------------------------------------------------------------------------------- /kernels/collatz/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "collatz" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [lib] 7 | crate-type = ["dylib", "lib"] 8 | 9 | [dependencies] 10 | spirv-std = { git = "https://github.com/EmbarkStudios/rust-gpu", features = ["glam"] } 11 | -------------------------------------------------------------------------------- /kernels/collatz/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr( 2 | target_arch = "spirv", 3 | feature(register_attr), 4 | register_attr(spirv), 5 | no_std 6 | )] 7 | // HACK(eddyb) can't easily see warnings otherwise from `spirv-builder` builds. 8 | #![deny(warnings)] 9 | 10 | extern crate spirv_std; 11 | 12 | use glam::UVec3; 13 | use spirv_std::glam; 14 | #[cfg(not(target_arch = "spirv"))] 15 | use spirv_std::macros::spirv; 16 | 17 | // Adapted from the wgpu hello-compute example 18 | 19 | pub fn collatz(mut n: u32) -> Option { 20 | let mut i = 0; 21 | if n == 0 { 22 | return None; 23 | } 24 | while n != 1 { 25 | n = if n % 2 == 0 { 26 | n / 2 27 | } else { 28 | // Overflow? (i.e. 3*n + 1 > 0xffff_ffff) 29 | if n >= 0x5555_5555 { 30 | return None; 31 | } 32 | // TODO: Use this instead when/if checked add/mul can work: n.checked_mul(3)?.checked_add(1)? 33 | 3 * n + 1 34 | }; 35 | i += 1; 36 | } 37 | Some(i) 38 | } 39 | 40 | // LocalSize/numthreads of (x = 64, y = 1, z = 1) 41 | #[spirv(compute(threads(64)))] 42 | pub fn main_cs( 43 | #[spirv(global_invocation_id)] id: UVec3, 44 | #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] prime_indices: &mut [u32], 45 | ) { 46 | let index = id.x as usize; 47 | prime_indices[index] = collatz(prime_indices[index]).unwrap_or(u32::MAX); 48 | } 49 | -------------------------------------------------------------------------------- /rust-toolchain: -------------------------------------------------------------------------------- 1 | # If you see this, run `rustup self update` to get rustup 1.23 or newer. 2 | 3 | # NOTE: above comment is for older `rustup` (before TOML support was added), 4 | # which will treat the first line as the toolchain name, and therefore show it 5 | # to the user in the error, instead of "error: invalid channel name '[toolchain]'". 6 | 7 | [toolchain] 8 | channel = "nightly-2022-01-13" 9 | components = ["rust-src", "rustc-dev", "llvm-tools-preview"] 10 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use wgpu::util::DeviceExt; 2 | 3 | use std::{convert::TryInto, num::NonZeroU64}; 4 | use wgpu::{BufferAsyncError, Device, Queue, RequestDeviceError, ShaderModule}; 5 | 6 | async fn init_device() -> Result<(Device, Queue), RequestDeviceError> { 7 | let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY); 8 | let adapter = instance 9 | .request_adapter(&wgpu::RequestAdapterOptions { 10 | power_preference: wgpu::PowerPreference::default(), 11 | force_fallback_adapter: false, 12 | compatible_surface: None, 13 | }) 14 | .await 15 | .expect("Failed to find an appropriate adapter"); 16 | 17 | adapter 18 | .request_device( 19 | &wgpu::DeviceDescriptor { 20 | label: None, 21 | features: wgpu::Features::TIMESTAMP_QUERY 22 | | wgpu::Features::SPIRV_SHADER_PASSTHROUGH, 23 | limits: wgpu::Limits::default(), 24 | }, 25 | None, 26 | ).await 27 | } 28 | 29 | fn load_collatz_shader_module(device: &Device) -> ShaderModule { 30 | let shader_bytes: &[u8] = include_bytes!(env!("collatz.spv")); 31 | let spirv = std::borrow::Cow::Owned(wgpu::util::make_spirv_raw(shader_bytes).into_owned()); 32 | let shader_binary = wgpu::ShaderModuleDescriptorSpirV { 33 | label: None, 34 | source: spirv, 35 | }; 36 | 37 | // Load the shaders from disk 38 | unsafe { device.create_shader_module_spirv(&shader_binary) } 39 | } 40 | 41 | async fn run_collatz_shader(input: &[u8]) -> Result, BufferAsyncError> { 42 | let (device, queue) = init_device().await.expect("Failed to create device"); 43 | let module = load_collatz_shader_module(&device); 44 | 45 | let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { 46 | label: None, 47 | entries: &[ 48 | // XXX - some graphics cards do not support empty bind layout groups, so 49 | // create a dummy entry. 50 | wgpu::BindGroupLayoutEntry { 51 | binding: 0, 52 | count: None, 53 | visibility: wgpu::ShaderStages::COMPUTE, 54 | ty: wgpu::BindingType::Buffer { 55 | has_dynamic_offset: false, 56 | min_binding_size: Some(NonZeroU64::new(1).unwrap()), 57 | ty: wgpu::BufferBindingType::Storage { read_only: false }, 58 | }, 59 | }, 60 | ], 61 | }); 62 | 63 | let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { 64 | label: None, 65 | bind_group_layouts: &[&bind_group_layout], 66 | push_constant_ranges: &[], 67 | }); 68 | 69 | let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { 70 | label: None, 71 | layout: Some(&pipeline_layout), 72 | module: &module, 73 | entry_point: "main_cs", 74 | }); 75 | 76 | let readback_buffer = device.create_buffer(&wgpu::BufferDescriptor { 77 | label: None, 78 | size: input.len() as wgpu::BufferAddress, 79 | // Can be read to the CPU, and can be copied from the shader's storage buffer 80 | usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST, 81 | mapped_at_creation: false, 82 | }); 83 | 84 | let storage_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { 85 | label: Some("Collatz Conjecture Input"), 86 | contents: input, 87 | usage: wgpu::BufferUsages::STORAGE 88 | | wgpu::BufferUsages::COPY_DST 89 | | wgpu::BufferUsages::COPY_SRC, 90 | }); 91 | 92 | let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { 93 | label: None, 94 | layout: &bind_group_layout, 95 | entries: &[wgpu::BindGroupEntry { 96 | binding: 0, 97 | resource: storage_buffer.as_entire_binding(), 98 | }], 99 | }); 100 | 101 | let mut encoder = 102 | device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); 103 | 104 | { 105 | let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { label: None }); 106 | cpass.set_bind_group(0, &bind_group, &[]); 107 | cpass.set_pipeline(&compute_pipeline); 108 | cpass.dispatch(input.len() as u32 / 64, 1, 1); 109 | } 110 | 111 | encoder.copy_buffer_to_buffer( 112 | &storage_buffer, 113 | 0, 114 | &readback_buffer, 115 | 0, 116 | input.len() as wgpu::BufferAddress, 117 | ); 118 | 119 | queue.submit(Some(encoder.finish())); 120 | let buffer_slice = readback_buffer.slice(..); 121 | let buffer_future = buffer_slice.map_async(wgpu::MapMode::Read); 122 | device.poll(wgpu::Maintain::Wait); 123 | 124 | buffer_future.await.map(|_| { 125 | buffer_slice 126 | .get_mapped_range() 127 | .chunks_exact(4) 128 | .map(|b| u32::from_ne_bytes(b.try_into().unwrap())) 129 | .collect::>() 130 | }) 131 | } 132 | 133 | async fn collatz() { 134 | let top = 2u32.pow(20); 135 | let src_range = 1..top; 136 | 137 | let src = src_range 138 | .clone() 139 | .flat_map(u32::to_ne_bytes) 140 | .collect::>(); 141 | 142 | if let Ok(result) = run_collatz_shader(&src).await { 143 | let mut max = 0; 144 | for (src, out) in src_range.zip(result.iter().copied()) { 145 | if out == u32::MAX { 146 | println!("{}: overflowed", src); 147 | break; 148 | } else if out > max { 149 | max = out; 150 | // Should produce 151 | println!("{}: {}", src, out); 152 | } 153 | } 154 | } 155 | } 156 | 157 | fn main() { 158 | futures::executor::block_on(collatz()); 159 | } 160 | --------------------------------------------------------------------------------