From 8736db19a36e43040560854b88608955da33116a Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 23 Sep 2024 21:13:50 +0300 Subject: [PATCH] Port to WGPU --- Cargo.lock | 861 +++++++++++++++++++---------------- Cargo.toml | 6 +- src/bin/wireframe/main.rs | 481 ++++++++++++++----- src/bin/wireframe/ray.f.glsl | 10 - src/bin/wireframe/ray.v.glsl | 13 - src/bin/wireframe/ray.wgsl | 33 ++ 6 files changed, 878 insertions(+), 526 deletions(-) delete mode 100644 src/bin/wireframe/ray.f.glsl delete mode 100644 src/bin/wireframe/ray.v.glsl create mode 100644 src/bin/wireframe/ray.wgsl diff --git a/Cargo.lock b/Cargo.lock index deae01a..0950020 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,9 +141,9 @@ dependencies = [ [[package]] name = "android-activity" -version = "0.6.0" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef6978589202a00cd7e118380c448a08b6ed394c3a8df3a430d0898e3a42d046" +checksum = "ee91c0c2905bae44f84bfa4e044536541df26b7703fd0888deeb9060fcc44289" dependencies = [ "android-properties", "bitflags 2.6.0", @@ -153,9 +153,9 @@ dependencies = [ "jni-sys", "libc 0.2.153", "log", - "ndk 0.9.0", + "ndk 0.8.0", "ndk-context", - "ndk-sys 0.6.0+11769913", + "ndk-sys 0.5.0+25.2.9519653", "num_enum 0.7.3", "thiserror", ] @@ -232,6 +232,15 @@ dependencies = [ "libloading 0.7.4", ] +[[package]] +name = "ash" +version = "0.38.0+1.3.281" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb44936d800fea8f016d7f2311c6a4f97aebd5dc86f09906139ec848cf3a46f" +dependencies = [ + "libloading 0.8.3", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -300,7 +309,16 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" dependencies = [ - "bit-vec", + "bit-vec 0.6.3", +] + +[[package]] +name = "bit-set" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0481a0e032742109b1133a095184ee93d88f3dc9e0d28a5d033dc77a073f44f" +dependencies = [ + "bit-vec 0.7.0", ] [[package]] @@ -309,6 +327,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" +[[package]] +name = "bit-vec" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2c54ff287cfc0a34f38a6b832ea1bd8e448a330b3e40a50859e6488bee07f22" + [[package]] name = "bitflags" version = "1.3.2" @@ -345,23 +369,33 @@ dependencies = [ "objc-sys 0.2.0-beta.2", ] +[[package]] +name = "block-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae85a0696e7ea3b835a453750bf002770776609115e6d25c6d2ff28a8200f7e7" +dependencies = [ + "objc-sys 0.3.5", +] + [[package]] name = "block2" version = "0.2.0-alpha.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8dd9e63c1744f755c2f60332b88de39d341e5e86239014ad839bd71c106dec42" dependencies = [ - "block-sys", + "block-sys 0.1.0-beta.1", "objc2-encode 2.0.0-pre.2", ] [[package]] name = "block2" -version = "0.5.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f" +checksum = "15b55663a85f33501257357e6421bb33e769d5c9ffb5ba0921c975a123e35e68" dependencies = [ - "objc2 0.5.2", + "block-sys 0.2.1", + "objc2 0.4.1", ] [[package]] @@ -382,9 +416,23 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.15.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" +checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cc8b54b395f2fcfbb3d90c47b01c7f444d94d05bdeb775811dec868ac3bbc26" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] [[package]] name = "byteorder" @@ -424,9 +472,9 @@ dependencies = [ [[package]] name = "calloop" -version = "0.13.0" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b99da2f8558ca23c71f4fd15dc57c906239752dd27ff3c00a1d56b685b7cbfec" +checksum = "fba7adb4dd5aa98e5553510223000e7148f621165ec5f9acd7113f6ca4995298" dependencies = [ "bitflags 2.6.0", "log", @@ -438,11 +486,11 @@ dependencies = [ [[package]] name = "calloop-wayland-source" -version = "0.3.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20" +checksum = "0f0ea9b9476c7fad82841a8dbb380e2eae480c21910feba80725b46931ed8f02" dependencies = [ - "calloop 0.13.0", + "calloop 0.12.4", "rustix", "wayland-backend", "wayland-client 0.31.6", @@ -492,12 +540,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" -[[package]] -name = "cfg_aliases" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" - [[package]] name = "cgl" version = "0.3.2" @@ -595,12 +637,43 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "com" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e17887fd17353b65b1b2ef1c526c83e26cd72e74f598a8dc1bee13a48f3d9f6" +dependencies = [ + "com_macros", +] + [[package]] name = "com-rs" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf43edc576402991846b093a7ca18a3477e0ef9c588cde84964b5d3e43016642" +[[package]] +name = "com_macros" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d375883580a668c7481ea6631fc1a8863e33cc335bf56bfad8d7e6d4b04b13a5" +dependencies = [ + "com_macros_support", + "proc-macro2", + "syn 1.0.109", +] + +[[package]] +name = "com_macros_support" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad899a1087a9296d5644792d7cb72b8e34c1bec8e7d4fbc002230169a6e8710c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "combine" version = "4.6.7" @@ -771,6 +844,17 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "d3d12" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdbd1f579714e3c809ebd822c81ef148b1ceaeb3d535352afc73fd0c4c6a0017" +dependencies = [ + "bitflags 2.6.0", + "libloading 0.8.3", + "winapi 0.3.9", +] + [[package]] name = "darling" version = "0.10.2" @@ -873,18 +957,21 @@ dependencies = [ "libloading 0.8.3", ] +[[package]] +name = "document-features" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb6969eaabd2421f8a2775cfd2471a2b634372b4a25d41e3bd647b79912850a0" +dependencies = [ + "litrs", +] + [[package]] name = "downcast-rs" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" -[[package]] -name = "dpi" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53" - [[package]] name = "egl" version = "0.2.7" @@ -1042,7 +1129,7 @@ dependencies = [ "flo_stream", "futures", "gl", - "glutin 0.26.0", + "glutin", "lazy_static", ] @@ -1339,23 +1426,6 @@ dependencies = [ "rand", ] -[[package]] -name = "glium" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a3028d1f135b5395e6e4336916b424bc5dd2b38c6e378ce2704e4b8f4a617ed" -dependencies = [ - "backtrace", - "fnv", - "gl_generator", - "glutin 0.32.1", - "glutin-winit", - "memoffset 0.9.1", - "raw-window-handle 0.6.2", - "smallvec", - "winit 0.30.5", -] - [[package]] name = "glob" version = "0.3.1" @@ -1374,6 +1444,18 @@ dependencies = [ "web-sys", ] +[[package]] +name = "glow" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd348e04c43b32574f2de31c8bb397d96c9fcfa1371bd4ca6d8bdc464ab121b1" +dependencies = [ + "js-sys", + "slotmap", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "glutin" version = "0.26.0" @@ -1384,10 +1466,10 @@ dependencies = [ "cgl", "cocoa 0.23.0", "core-foundation 0.9.4", - "glutin_egl_sys 0.1.6", + "glutin_egl_sys", "glutin_emscripten_sys", "glutin_gles2_sys", - "glutin_glx_sys 0.1.8", + "glutin_glx_sys", "glutin_wgl_sys 0.1.5", "lazy_static", "libloading 0.6.7", @@ -1401,43 +1483,6 @@ dependencies = [ "winit 0.24.0", ] -[[package]] -name = "glutin" -version = "0.32.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec69412a0bf07ea7607e638b415447857a808846c2b685a43c8aa18bc6d5e499" -dependencies = [ - "bitflags 2.6.0", - "cfg_aliases 0.2.1", - "cgl", - "core-foundation 0.9.4", - "dispatch", - "glutin_egl_sys 0.7.0", - "glutin_glx_sys 0.6.0", - "glutin_wgl_sys 0.6.0", - "libloading 0.8.3", - "objc2 0.5.2", - "objc2-app-kit", - "objc2-foundation", - "once_cell", - "raw-window-handle 0.6.2", - "wayland-sys 0.31.5", - "windows-sys 0.52.0", - "x11-dl", -] - -[[package]] -name = "glutin-winit" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85edca7075f8fc728f28cb8fbb111a96c3b89e930574369e3e9c27eb75d3788f" -dependencies = [ - "cfg_aliases 0.2.1", - "glutin 0.32.1", - "raw-window-handle 0.6.2", - "winit 0.30.5", -] - [[package]] name = "glutin_egl_sys" version = "0.1.6" @@ -1448,16 +1493,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "glutin_egl_sys" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cae99fff4d2850dbe6fb8c1fa8e4fead5525bab715beaacfccf3fb994e01c827" -dependencies = [ - "gl_generator", - "windows-sys 0.52.0", -] - [[package]] name = "glutin_emscripten_sys" version = "0.1.1" @@ -1484,16 +1519,6 @@ dependencies = [ "x11-dl", ] -[[package]] -name = "glutin_glx_sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c2b2d3918e76e18e08796b55eb64e8fe6ec67d5a6b2e2a7e2edce224ad24c63" -dependencies = [ - "gl_generator", - "x11-dl", -] - [[package]] name = "glutin_wgl_sys" version = "0.1.5" @@ -1547,7 +1572,20 @@ dependencies = [ "log", "thiserror", "winapi 0.3.9", - "windows", + "windows 0.44.0", +] + +[[package]] +name = "gpu-allocator" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdd4240fc91d3433d5e5b0fc5b67672d771850dc19bbee03c1381e19322803d7" +dependencies = [ + "log", + "presser", + "thiserror", + "winapi 0.3.9", + "windows 0.52.0", ] [[package]] @@ -1557,7 +1595,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc11df1ace8e7e564511f53af41f3e42ddc95b56fd07b3f4445d2a6048bc682c" dependencies = [ "bitflags 2.6.0", - "gpu-descriptor-types", + "gpu-descriptor-types 0.1.2", + "hashbrown 0.14.5", +] + +[[package]] +name = "gpu-descriptor" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c08c1f623a8d0b722b8b99f821eb0ba672a1618f0d3b16ddbee1cedd2dd8557" +dependencies = [ + "bitflags 2.6.0", + "gpu-descriptor-types 0.2.0", "hashbrown 0.14.5", ] @@ -1570,6 +1619,15 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "gpu-descriptor-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdf242682df893b86f33a73828fb09ca4b2d3bb6cc95249707fc684d27484b91" +dependencies = [ + "bitflags 2.6.0", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -1601,6 +1659,21 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "hassle-rs" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af2a7e73e1f34c48da31fb668a907f250794837e08faa144fd24f0b8b741e890" +dependencies = [ + "bitflags 2.6.0", + "com", + "libc 0.2.153", + "libloading 0.8.3", + "thiserror", + "widestring", + "winapi 0.3.9", +] + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1637,6 +1710,17 @@ dependencies = [ "quick-error", ] +[[package]] +name = "icrate" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d3aaff8a54577104bafdf686ff18565c3b6903ca5782a2026ef06e2c7aa319" +dependencies = [ + "block2 0.3.0", + "dispatch", + "objc2 0.4.1", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -1818,6 +1902,17 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "khronos-egl" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aae1df220ece3c0ada96b8153459b67eebe9ae9212258bb0134ae60416fdf76" +dependencies = [ + "libc 0.2.153", + "libloading 0.8.3", + "pkg-config", +] + [[package]] name = "khronos_api" version = "3.1.0" @@ -1916,6 +2011,12 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "litrs" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" + [[package]] name = "lock_api" version = "0.4.12" @@ -2033,15 +2134,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "memoffset" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" -dependencies = [ - "autocfg", -] - [[package]] name = "metal" version = "0.26.0" @@ -2057,6 +2149,21 @@ dependencies = [ "paste", ] +[[package]] +name = "metal" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ecfd3296f8c56b7c1f6fbac3c71cefa9d78ce009850c45000015f206dc7fa21" +dependencies = [ + "bitflags 2.6.0", + "block", + "core-graphics-types", + "foreign-types 0.5.0", + "log", + "objc", + "paste", +] + [[package]] name = "miniz_oxide" version = "0.3.7" @@ -2147,7 +2254,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1ceaaa4eedaece7e4ec08c55c640ba03dbb73fb812a6570a59bcf1930d0f70e" dependencies = [ - "bit-set", + "bit-set 0.5.3", "bitflags 2.6.0", "codespan-reporting", "hexf-parse", @@ -2156,7 +2263,28 @@ dependencies = [ "num-traits", "petgraph", "rustc-hash", - "spirv", + "spirv 0.2.0+1.5.4", + "termcolor", + "thiserror", + "unicode-xid", +] + +[[package]] +name = "naga" +version = "22.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bd5a652b6faf21496f2cfd88fc49989c8db0825d1f6746b1a71a6ede24a63ad" +dependencies = [ + "arrayvec 0.7.4", + "bit-set 0.6.0", + "bitflags 2.6.0", + "cfg_aliases", + "codespan-reporting", + "hexf-parse", + "indexmap 2.2.6", + "log", + "rustc-hash", + "spirv 0.3.0+sdk-1.3.268.0", "termcolor", "thiserror", "unicode-xid", @@ -2190,14 +2318,14 @@ dependencies = [ [[package]] name = "ndk" -version = "0.9.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3f42e7bbe13d351b6bead8286a43aac9534b82bd3cc43e47037f012ebfd62d4" +checksum = "2076a31b7010b17a38c01907c45b945e8f11495ee4dd588309718901b1f7a5b7" dependencies = [ "bitflags 2.6.0", "jni-sys", "log", - "ndk-sys 0.6.0+11769913", + "ndk-sys 0.5.0+25.2.9519653", "num_enum 0.7.3", "raw-window-handle 0.6.2", "thiserror", @@ -2253,9 +2381,9 @@ dependencies = [ [[package]] name = "ndk-sys" -version = "0.6.0+11769913" +version = "0.5.0+25.2.9519653" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee6cda3051665f1fb8d9e08fc35c96d5a244fb1be711a03b71118828afc9a873" +checksum = "8c196769dd60fd4f363e11d948139556a344e79d451aeb2fa2fd040738ef7691" dependencies = [ "jni-sys", ] @@ -2304,7 +2432,7 @@ dependencies = [ "bitflags 1.3.2", "cfg-if 1.0.0", "libc 0.2.153", - "memoffset 0.6.5", + "memoffset", ] [[package]] @@ -2317,7 +2445,7 @@ dependencies = [ "bitflags 1.3.2", "cfg-if 1.0.0", "libc 0.2.153", - "memoffset 0.6.5", + "memoffset", ] [[package]] @@ -2500,88 +2628,12 @@ dependencies = [ [[package]] name = "objc2" -version = "0.5.2" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a785d4eeff09c14c487497c162e92766fbb3e4059a71840cecc03d9a50b804" +checksum = "559c5a40fdd30eb5e344fbceacf7595a81e242529fb4e21cf5f43fb4f11ff98d" dependencies = [ "objc-sys 0.3.5", - "objc2-encode 4.0.3", -] - -[[package]] -name = "objc2-app-kit" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4e89ad9e3d7d297152b17d39ed92cd50ca8063a89a9fa569046d41568891eff" -dependencies = [ - "bitflags 2.6.0", - "block2 0.5.1", - "libc 0.2.153", - "objc2 0.5.2", - "objc2-core-data", - "objc2-core-image", - "objc2-foundation", - "objc2-quartz-core", -] - -[[package]] -name = "objc2-cloud-kit" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74dd3b56391c7a0596a295029734d3c1c5e7e510a4cb30245f8221ccea96b009" -dependencies = [ - "bitflags 2.6.0", - "block2 0.5.1", - "objc2 0.5.2", - "objc2-core-location", - "objc2-foundation", -] - -[[package]] -name = "objc2-contacts" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5ff520e9c33812fd374d8deecef01d4a840e7b41862d849513de77e44aa4889" -dependencies = [ - "block2 0.5.1", - "objc2 0.5.2", - "objc2-foundation", -] - -[[package]] -name = "objc2-core-data" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "617fbf49e071c178c0b24c080767db52958f716d9eabdf0890523aeae54773ef" -dependencies = [ - "bitflags 2.6.0", - "block2 0.5.1", - "objc2 0.5.2", - "objc2-foundation", -] - -[[package]] -name = "objc2-core-image" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55260963a527c99f1819c4f8e3b47fe04f9650694ef348ffd2227e8196d34c80" -dependencies = [ - "block2 0.5.1", - "objc2 0.5.2", - "objc2-foundation", - "objc2-metal", -] - -[[package]] -name = "objc2-core-location" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "000cfee34e683244f284252ee206a27953279d370e309649dc3ee317b37e5781" -dependencies = [ - "block2 0.5.1", - "objc2 0.5.2", - "objc2-contacts", - "objc2-foundation", + "objc2-encode 3.0.0", ] [[package]] @@ -2595,114 +2647,9 @@ dependencies = [ [[package]] name = "objc2-encode" -version = "4.0.3" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7891e71393cd1f227313c9379a26a584ff3d7e6e7159e988851f0934c993f0f8" - -[[package]] -name = "objc2-foundation" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" -dependencies = [ - "bitflags 2.6.0", - "block2 0.5.1", - "dispatch", - "libc 0.2.153", - "objc2 0.5.2", -] - -[[package]] -name = "objc2-link-presentation" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1a1ae721c5e35be65f01a03b6d2ac13a54cb4fa70d8a5da293d7b0020261398" -dependencies = [ - "block2 0.5.1", - "objc2 0.5.2", - "objc2-app-kit", - "objc2-foundation", -] - -[[package]] -name = "objc2-metal" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0cba1276f6023976a406a14ffa85e1fdd19df6b0f737b063b95f6c8c7aadd6" -dependencies = [ - "bitflags 2.6.0", - "block2 0.5.1", - "objc2 0.5.2", - "objc2-foundation", -] - -[[package]] -name = "objc2-quartz-core" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42bee7bff906b14b167da2bac5efe6b6a07e6f7c0a21a7308d40c960242dc7a" -dependencies = [ - "bitflags 2.6.0", - "block2 0.5.1", - "objc2 0.5.2", - "objc2-foundation", - "objc2-metal", -] - -[[package]] -name = "objc2-symbols" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a684efe3dec1b305badae1a28f6555f6ddd3bb2c2267896782858d5a78404dc" -dependencies = [ - "objc2 0.5.2", - "objc2-foundation", -] - -[[package]] -name = "objc2-ui-kit" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8bb46798b20cd6b91cbd113524c490f1686f4c4e8f49502431415f3512e2b6f" -dependencies = [ - "bitflags 2.6.0", - "block2 0.5.1", - "objc2 0.5.2", - "objc2-cloud-kit", - "objc2-core-data", - "objc2-core-image", - "objc2-core-location", - "objc2-foundation", - "objc2-link-presentation", - "objc2-quartz-core", - "objc2-symbols", - "objc2-uniform-type-identifiers", - "objc2-user-notifications", -] - -[[package]] -name = "objc2-uniform-type-identifiers" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44fa5f9748dbfe1ca6c0b79ad20725a11eca7c2218bceb4b005cb1be26273bfe" -dependencies = [ - "block2 0.5.1", - "objc2 0.5.2", - "objc2-foundation", -] - -[[package]] -name = "objc2-user-notifications" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76cfcbf642358e8689af64cee815d139339f3ed8ad05103ed5eaf73db8d84cb3" -dependencies = [ - "bitflags 2.6.0", - "block2 0.5.1", - "objc2 0.5.2", - "objc2-core-location", - "objc2-foundation", -] +checksum = "d079845b37af429bfe5dfa76e6d087d788031045b25cfc6fd898486fd9847666" [[package]] name = "objc_exception" @@ -2836,26 +2783,6 @@ dependencies = [ "indexmap 2.2.6", ] -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.60", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -2914,12 +2841,24 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "pollster" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2" + [[package]] name = "ppv-lite86" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "presser" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" + [[package]] name = "proc-macro-crate" version = "0.1.5" @@ -3106,16 +3045,18 @@ name = "refraction" version = "0.1.0" dependencies = [ "approx", + "bytemuck", "flo_canvas", "flo_draw", "glam 0.27.0", - "glium", "itertools 0.13.0", "itertools-num", + "pollster", "rand", "rand_pcg", "show-image", - "winit 0.30.5", + "wgpu 22.1.0", + "winit 0.29.15", ] [[package]] @@ -3272,14 +3213,14 @@ dependencies = [ [[package]] name = "sctk-adwaita" -version = "0.10.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6277f0217056f77f1d8f49f2950ac6c278c0d607c45f5ee99328d792ede24ec" +checksum = "70b31447ca297092c5a9916fc3b955203157b37c19ca8edde4f52e9843e602c7" dependencies = [ "ab_glyph", "log", "memmap2 0.9.5", - "smithay-client-toolkit 0.19.2", + "smithay-client-toolkit 0.18.1", "tiny-skia 0.11.4", ] @@ -3336,7 +3277,7 @@ dependencies = [ "indexmap 2.2.6", "rustc_version", "show-image-macros", - "wgpu", + "wgpu 0.17.2", "winit 0.28.7", ] @@ -3436,12 +3377,12 @@ dependencies = [ [[package]] name = "smithay-client-toolkit" -version = "0.19.2" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016" +checksum = "922fd3eeab3bd820d76537ce8f582b1cf951eceb5475c28500c7457d9d17f53a" dependencies = [ "bitflags 2.6.0", - "calloop 0.13.0", + "calloop 0.12.4", "calloop-wayland-source", "cursor-icon", "libc 0.2.153", @@ -3453,7 +3394,7 @@ dependencies = [ "wayland-client 0.31.6", "wayland-csd-frame", "wayland-cursor 0.31.6", - "wayland-protocols 0.32.4", + "wayland-protocols 0.31.2", "wayland-protocols-wlr", "wayland-scanner 0.31.5", "xkeysym", @@ -3478,6 +3419,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "spirv" +version = "0.3.0+sdk-1.3.268.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eda41003dc44290527a59b13432d4a0379379fa074b70174882adfbdfd917844" +dependencies = [ + "bitflags 2.6.0", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -3550,18 +3500,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.59" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.59" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", @@ -4008,9 +3958,9 @@ dependencies = [ [[package]] name = "wayland-protocols" -version = "0.32.4" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b5755d77ae9040bb872a25026555ce4cb0ae75fd923e90d25fba07d81057de0" +checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4" dependencies = [ "bitflags 2.6.0", "wayland-backend", @@ -4020,27 +3970,27 @@ dependencies = [ [[package]] name = "wayland-protocols-plasma" -version = "0.3.4" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0a41a6875e585172495f7a96dfa42ca7e0213868f4f15c313f7c33221a7eff" +checksum = "23803551115ff9ea9bce586860c5c5a971e360825a0309264102a9495a5ff479" dependencies = [ "bitflags 2.6.0", "wayland-backend", "wayland-client 0.31.6", - "wayland-protocols 0.32.4", + "wayland-protocols 0.31.2", "wayland-scanner 0.31.5", ] [[package]] name = "wayland-protocols-wlr" -version = "0.3.4" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dad87b5fd1b1d3ca2f792df8f686a2a11e3fe1077b71096f7a175ab699f89109" +checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" dependencies = [ "bitflags 2.6.0", "wayland-backend", "wayland-client 0.31.6", - "wayland-protocols 0.32.4", + "wayland-protocols 0.31.2", "wayland-scanner 0.31.5", ] @@ -4123,9 +4073,9 @@ dependencies = [ [[package]] name = "web-time" -version = "1.1.0" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +checksum = "aa30049b1c872b72c89866d458eae9f20380ab280ffd1b1e18df2d3e2d98cfe0" dependencies = [ "js-sys", "wasm-bindgen", @@ -4147,7 +4097,7 @@ dependencies = [ "cfg-if 1.0.0", "js-sys", "log", - "naga", + "naga 0.13.0", "parking_lot", "profiling", "raw-window-handle 0.5.2", @@ -4156,9 +4106,34 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "wgpu-core", - "wgpu-hal", - "wgpu-types", + "wgpu-core 0.17.1", + "wgpu-hal 0.17.2", + "wgpu-types 0.17.0", +] + +[[package]] +name = "wgpu" +version = "22.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d1c4ba43f80542cf63a0a6ed3134629ae73e8ab51e4b765a67f3aa062eb433" +dependencies = [ + "arrayvec 0.7.4", + "cfg_aliases", + "document-features", + "js-sys", + "log", + "naga 22.1.0", + "parking_lot", + "profiling", + "raw-window-handle 0.6.2", + "smallvec", + "static_assertions", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "wgpu-core 22.1.0", + "wgpu-hal 22.0.0", + "wgpu-types 22.0.0", ] [[package]] @@ -4168,11 +4143,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f8a44dd301a30ceeed3c27d8c0090433d3da04d7b2a4042738095a424d12ae7" dependencies = [ "arrayvec 0.7.4", - "bit-vec", + "bit-vec 0.6.3", "bitflags 2.6.0", "codespan-reporting", "log", - "naga", + "naga 0.13.0", "parking_lot", "profiling", "raw-window-handle 0.5.2", @@ -4180,8 +4155,33 @@ dependencies = [ "smallvec", "thiserror", "web-sys", - "wgpu-hal", - "wgpu-types", + "wgpu-hal 0.17.2", + "wgpu-types 0.17.0", +] + +[[package]] +name = "wgpu-core" +version = "22.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0348c840d1051b8e86c3bcd31206080c5e71e5933dabd79be1ce732b0b2f089a" +dependencies = [ + "arrayvec 0.7.4", + "bit-vec 0.7.0", + "bitflags 2.6.0", + "cfg_aliases", + "document-features", + "indexmap 2.2.6", + "log", + "naga 22.1.0", + "once_cell", + "parking_lot", + "profiling", + "raw-window-handle 0.6.2", + "rustc-hash", + "smallvec", + "thiserror", + "wgpu-hal 22.0.0", + "wgpu-types 22.0.0", ] [[package]] @@ -4192,24 +4192,24 @@ checksum = "9a80bf0e3c77399bb52850cb0830af9bad073d5cfcb9dd8253bef8125c42db17" dependencies = [ "android_system_properties", "arrayvec 0.7.4", - "ash", - "bit-set", + "ash 0.37.3+1.3.251", + "bit-set 0.5.3", "bitflags 2.6.0", "block", "core-graphics-types", - "d3d12", - "glow", + "d3d12 0.7.0", + "glow 0.12.3", "gpu-alloc", - "gpu-allocator", - "gpu-descriptor", - "hassle-rs", + "gpu-allocator 0.22.0", + "gpu-descriptor 0.2.4", + "hassle-rs 0.10.0", "js-sys", - "khronos-egl", + "khronos-egl 4.1.0", "libc 0.2.153", "libloading 0.8.3", "log", - "metal", - "naga", + "metal 0.26.0", + "naga 0.13.0", "objc", "parking_lot", "profiling", @@ -4221,7 +4221,52 @@ dependencies = [ "thiserror", "wasm-bindgen", "web-sys", - "wgpu-types", + "wgpu-types 0.17.0", + "winapi 0.3.9", +] + +[[package]] +name = "wgpu-hal" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6bbf4b4de8b2a83c0401d9e5ae0080a2792055f25859a02bf9be97952bbed4f" +dependencies = [ + "android_system_properties", + "arrayvec 0.7.4", + "ash 0.38.0+1.3.281", + "bit-set 0.6.0", + "bitflags 2.6.0", + "block", + "cfg_aliases", + "core-graphics-types", + "d3d12 22.0.0", + "glow 0.13.1", + "glutin_wgl_sys 0.6.0", + "gpu-alloc", + "gpu-allocator 0.26.0", + "gpu-descriptor 0.3.0", + "hassle-rs 0.11.0", + "js-sys", + "khronos-egl 6.0.0", + "libc 0.2.153", + "libloading 0.8.3", + "log", + "metal 0.29.0", + "naga 22.1.0", + "ndk-sys 0.5.0+25.2.9519653", + "objc", + "once_cell", + "parking_lot", + "profiling", + "range-alloc", + "raw-window-handle 0.6.2", + "renderdoc-sys", + "rustc-hash", + "smallvec", + "thiserror", + "wasm-bindgen", + "web-sys", + "wgpu-types 22.0.0", "winapi 0.3.9", ] @@ -4236,6 +4281,17 @@ dependencies = [ "web-sys", ] +[[package]] +name = "wgpu-types" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc9d91f0e2c4b51434dfa6db77846f2793149d8e73f800fa2e41f52b8eac3c5d" +dependencies = [ + "bitflags 2.6.0", + "js-sys", + "web-sys", +] + [[package]] name = "which" version = "3.1.1" @@ -4303,6 +4359,25 @@ dependencies = [ "windows-targets 0.42.2", ] +[[package]] +name = "windows" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" +dependencies = [ + "windows-core", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.45.0" @@ -4547,7 +4622,7 @@ checksum = "9596d90b45384f5281384ab204224876e8e8bf7d58366d9b795ad99aa9894b94" dependencies = [ "android-activity 0.4.3", "bitflags 1.3.2", - "cfg_aliases 0.1.1", + "cfg_aliases", "core-foundation 0.9.4", "core-graphics 0.22.3", "dispatch", @@ -4576,51 +4651,47 @@ dependencies = [ [[package]] name = "winit" -version = "0.30.5" +version = "0.29.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0be9e76a1f1077e04a411f0b989cbd3c93339e1771cb41e71ac4aee95bfd2c67" +checksum = "0d59ad965a635657faf09c8f062badd885748428933dad8e8bdd64064d92e5ca" dependencies = [ "ahash", - "android-activity 0.6.0", + "android-activity 0.5.2", "atomic-waker", "bitflags 2.6.0", - "block2 0.5.1", "bytemuck", - "calloop 0.13.0", - "cfg_aliases 0.2.1", - "concurrent-queue", + "calloop 0.12.4", + "cfg_aliases", "core-foundation 0.9.4", "core-graphics 0.23.2", "cursor-icon", - "dpi", + "icrate", "js-sys", "libc 0.2.153", + "log", "memmap2 0.9.5", - "ndk 0.9.0", - "objc2 0.5.2", - "objc2-app-kit", - "objc2-foundation", - "objc2-ui-kit", + "ndk 0.8.0", + "ndk-sys 0.5.0+25.2.9519653", + "objc2 0.4.1", + "once_cell", "orbclient", "percent-encoding", - "pin-project", "raw-window-handle 0.6.2", - "redox_syscall 0.4.1", + "redox_syscall 0.3.5", "rustix", - "sctk-adwaita 0.10.1", - "smithay-client-toolkit 0.19.2", + "sctk-adwaita 0.8.3", + "smithay-client-toolkit 0.18.1", "smol_str", - "tracing", "unicode-segmentation", "wasm-bindgen", "wasm-bindgen-futures", "wayland-backend", "wayland-client 0.31.6", - "wayland-protocols 0.32.4", + "wayland-protocols 0.31.2", "wayland-protocols-plasma", "web-sys", "web-time", - "windows-sys 0.52.0", + "windows-sys 0.48.0", "x11-dl", "x11rb", "xkbcommon-dl", diff --git a/Cargo.toml b/Cargo.toml index 3b60290..9eaee46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,9 +21,11 @@ show-image = "0.14.0" flo_draw = "0.3.1" flo_canvas = "0.3.1" itertools-num = "0.1.3" -glium = "0.35.0" -winit = "0.30.5" +winit = "0.29" itertools = "0.13.0" +wgpu = "22.1.0" +bytemuck = { version = "1.18.0", features = ["derive"] } +pollster = "0.3.0" [dev-dependencies] approx = "0.5.1" diff --git a/src/bin/wireframe/main.rs b/src/bin/wireframe/main.rs index 8688bbd..95e2b3e 100644 --- a/src/bin/wireframe/main.rs +++ b/src/bin/wireframe/main.rs @@ -1,18 +1,12 @@ -use std::time::Instant; +use std::{iter, mem, time::Instant}; use glam::{mat4, vec2, vec3, vec4, Mat4, Vec3}; -use glium::{ - backend::{glutin::SimpleWindowBuilder, Facade}, - glutin::config::ConfigTemplateBuilder, - implement_vertex, - index::PrimitiveType, - uniform, - winit::event::{Event, WindowEvent}, - DrawParameters, Program, Surface, VertexBuffer, -}; +use wgpu::{util::DeviceExt, ShaderStages}; use winit::{ + event::*, event_loop::EventLoop, keyboard::{KeyCode, PhysicalKey}, + window::{Window, WindowBuilder}, }; mod scene; @@ -22,29 +16,42 @@ mod scene; // * Y: left // * Z: up -#[derive(Copy, Clone)] +#[repr(C)] +#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)] struct Vertex { position: [f32; 3], } -implement_vertex!(Vertex, position); + +impl Vertex { + fn desc() -> wgpu::VertexBufferLayout<'static> { + use std::mem; + wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as wgpu::BufferAddress, + step_mode: wgpu::VertexStepMode::Vertex, + attributes: &[wgpu::VertexAttribute { + offset: mem::offset_of!(Self, position) as u64, + shader_location: 0, + format: wgpu::VertexFormat::Float32x3, + }], + } + } +} struct Wireframe { color: Vec3, - mode: PrimitiveType, - data: VertexBuffer, + data: wgpu::Buffer, + size: u32, } -fn prepare_scene(display: &impl Facade) -> Vec { +fn prepare_scene(device: &wgpu::Device) -> Vec { scene::build() .into_iter() .map(|line| { let color = line.color; - let mode; let data: Vec; match line.line { scene::Line::Lines(_) => todo!(), scene::Line::Strip(pts) => { - mode = PrimitiveType::LineStrip; data = pts .into_iter() .map(|p| Vertex { @@ -53,17 +60,23 @@ fn prepare_scene(display: &impl Facade) -> Vec { .collect(); } scene::Line::Loop(pts) => { - mode = PrimitiveType::LineLoop; + let first = pts.first().copied(); data = pts .into_iter() + .chain(first) .map(|p| Vertex { position: p.to_array(), }) .collect(); } }; - let data = VertexBuffer::new(display, &data).unwrap(); - Wireframe { color, mode, data } + let size = data.len() as u32; + let data = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Vertex Buffer"), + contents: bytemuck::cast_slice(&data), + usage: wgpu::BufferUsages::VERTEX, + }); + Wireframe { color, data, size } }) .collect() } @@ -155,111 +168,367 @@ static KEYS_ROTATE: &'static [(PhysicalKey, Vec3)] = &[ (PhysicalKey::Code(KeyCode::Numpad6), vec3(0., 0., -1.)), ]; -fn main() { - let event_loop = EventLoop::builder().build().unwrap(); - let cfg = ConfigTemplateBuilder::new().with_multisampling(8); - let (window, display) = SimpleWindowBuilder::new() - .with_config_template_builder(cfg) - .with_title("Refraction: Wireframe") - .build(&event_loop); +#[repr(C)] +#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] +struct CameraUniform { + mvp: [[f32; 4]; 4], +} - let vs_src = include_str!("ray.v.glsl"); - let fs_src = include_str!("ray.f.glsl"); - let program = Program::from_source(&display, vs_src, fs_src, None).unwrap(); +#[repr(C)] +#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] +struct LineUniform { + color: [f32; 3], + _pad: f32, +} - let scene = prepare_scene(&display); +struct State<'a> { + surface: wgpu::Surface<'a>, + device: wgpu::Device, + queue: wgpu::Queue, + config: wgpu::SurfaceConfiguration, + size: winit::dpi::PhysicalSize, + render_pipeline: wgpu::RenderPipeline, - let mut kbd = keyctl::Keyboard::new(); - let mut cam = camctl::CameraLocation::new(); - let mut t1 = Instant::now(); + kbd: keyctl::Keyboard, + cam: camctl::CameraLocation, + t1: Instant, - #[allow(deprecated)] - event_loop - .run(move |ev, window_target| match ev { - Event::WindowEvent { event, .. } => match event { - WindowEvent::RedrawRequested => { - let dt = { - let t2 = Instant::now(); - let dt = t2 - t1; - t1 = t2; - dt.as_secs_f32() - }; - cam.move_rel(100. * dt * kbd.control(&KEYS_MOVE)); - cam.rotate_rel_ypr(2. * dt * kbd.control(&KEYS_ROTATE)); + camera_uniform: CameraUniform, + camera_buffer: wgpu::Buffer, + camera_bind_group: wgpu::BindGroup, - let size = window.inner_size(); - let size = vec2(size.width as f32, size.height as f32).normalize() - * std::f32::consts::SQRT_2; - let proj = make_proj_matrix(vec3(size.x, size.y, 2.), (1., 4096.)); + scene: Vec, - let my_to_gl = mat4( - vec4(0., 0., 1., 0.), - vec4(-1., 0., 0., 0.), - vec4(0., 1., 0., 0.), - vec4(0., 0., 0., 1.), - ); - let view = my_to_gl * cam.view_mtx(); + window: &'a Window, +} - let mut target = display.draw(); - target.clear_color(0.0, 0.0, 0.0, 0.0); +impl<'a> State<'a> { + async fn new(window: &'a Window) -> State<'a> { + let size = window.inner_size(); - let mvp = proj * view; - let params = DrawParameters { - blend: glium::Blend { - color: glium::BlendingFunction::Addition { - source: glium::LinearBlendingFactor::One, - destination: glium::LinearBlendingFactor::OneMinusSourceAlpha, - }, - alpha: glium::BlendingFunction::Addition { - source: glium::LinearBlendingFactor::One, - destination: glium::LinearBlendingFactor::OneMinusSourceAlpha, - }, - constant_value: (0., 0., 0., 0.), - }, - line_width: Some(3.), - smooth: Some(glium::Smooth::Nicest), - ..Default::default() - }; - for mesh in &scene { - let uniforms = uniform! { - mvp: mvp.to_cols_array_2d(), - color: mesh.color.to_array(), - }; - let indices = glium::index::NoIndices(mesh.mode); - target - .draw(&mesh.data, &indices, &program, &uniforms, ¶ms) - .unwrap(); - } - target.finish().unwrap(); - } + let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { + backends: wgpu::Backends::PRIMARY, + ..Default::default() + }); + let surface = instance.create_surface(window).unwrap(); + let adapter = instance + .request_adapter(&wgpu::RequestAdapterOptions { + power_preference: wgpu::PowerPreference::default(), + compatible_surface: Some(&surface), + force_fallback_adapter: false, + }) + .await + .unwrap(); + let (device, queue) = adapter + .request_device( + &wgpu::DeviceDescriptor { + label: None, + required_features: wgpu::Features::PUSH_CONSTANTS, + required_limits: wgpu::Limits { + max_push_constant_size: mem::size_of::() as u32, + ..wgpu::Limits::default() + }, + memory_hints: Default::default(), + }, + None, // Trace path + ) + .await + .unwrap(); - WindowEvent::KeyboardInput { - device_id: _, - event, - is_synthetic: _, - } => { - kbd.set_key_state(event.physical_key, event.state); - } + let surface_caps = surface.get_capabilities(&adapter); + let surface_format = surface_caps + .formats + .iter() + .copied() + .find(|f| !f.is_srgb()) + .unwrap_or(surface_caps.formats[0]); + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface_format, + width: size.width, + height: size.height, + present_mode: surface_caps.present_modes[0], + alpha_mode: surface_caps.alpha_modes[0], + view_formats: vec![], + desired_maximum_frame_latency: 2, + }; - WindowEvent::Resized(window_size) => { - display.resize(window_size.into()); - } + let kbd = keyctl::Keyboard::new(); + let cam = camctl::CameraLocation::new(); + let t1 = Instant::now(); - WindowEvent::CloseRequested => { - window_target.exit(); - } + let camera_uniform = CameraUniform { + mvp: cam.view_mtx().to_cols_array_2d(), + }; + let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Camera Buffer"), + contents: bytemuck::cast_slice(&[camera_uniform]), + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, + }); + let camera_bind_group_layout = + device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + entries: &[wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::VERTEX, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: None, + }, + count: None, + }], + label: Some("camera_bind_group_layout"), + }); + let camera_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &camera_bind_group_layout, + entries: &[wgpu::BindGroupEntry { + binding: 0, + resource: camera_buffer.as_entire_binding(), + }], + label: Some("camera_bind_group"), + }); - _ => (), + let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { + label: Some("Shader"), + source: wgpu::ShaderSource::Wgsl(include_str!("ray.wgsl").into()), + }); + + let line_push_constant_range = wgpu::PushConstantRange { + stages: ShaderStages::VERTEX, + range: 0..mem::size_of::() as u32, + }; + + let render_pipeline_layout = + device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: Some("Render Pipeline Layout"), + bind_group_layouts: &[&camera_bind_group_layout], + push_constant_ranges: &[line_push_constant_range], + }); + + let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("Render Pipeline"), + layout: Some(&render_pipeline_layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_main", + buffers: &[Vertex::desc()], + compilation_options: Default::default(), }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "fs_main", + targets: &[Some(wgpu::ColorTargetState { + format: config.format, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent::OVER, + alpha: wgpu::BlendComponent::OVER, + }), + write_mask: wgpu::ColorWrites::ALL, + })], + compilation_options: Default::default(), + }), + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::LineStrip, + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState { + count: 1, + mask: !0, + alpha_to_coverage_enabled: false, + }, + multiview: None, + cache: None, + }); - Event::AboutToWait => { - window.request_redraw(); + let scene = prepare_scene(&device); + + Self { + surface, + device, + queue, + config, + size, + render_pipeline, + kbd, + cam, + t1, + scene, + camera_buffer, + camera_bind_group, + camera_uniform, + window, + } + } + + pub fn window(&self) -> &Window { + &self.window + } + + fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { + if new_size.width > 0 && new_size.height > 0 { + self.size = new_size; + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); + } + } + + fn update(&mut self) { + let dt = { + let t2 = Instant::now(); + let dt = t2 - self.t1; + self.t1 = t2; + dt.as_secs_f32() + }; + self.cam.move_rel(100. * dt * self.kbd.control(&KEYS_MOVE)); + self.cam + .rotate_rel_ypr(2. * dt * self.kbd.control(&KEYS_ROTATE)); + + let size = vec2(self.config.width as f32, self.config.height as f32); + let size = size.normalize() * std::f32::consts::SQRT_2; + let proj = make_proj_matrix(vec3(size.x, size.y, 2.), (1., 4096.)); + + let my_to_gl = mat4( + vec4(0., 0., 1., 0.), + vec4(-1., 0., 0., 0.), + vec4(0., 1., 0., 0.), + vec4(0., 0., 0., 1.), + ); + let view = my_to_gl * self.cam.view_mtx(); + let mvp = proj * view; + self.camera_uniform.mvp = mvp.to_cols_array_2d(); + self.queue.write_buffer( + &self.camera_buffer, + 0, + bytemuck::cast_slice(&[self.camera_uniform]), + ); + } + + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_texture()?; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); + + let mut encoder = self + .device + .create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("Render Encoder"), + }); + + { + let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("Render Pass"), + color_attachments: &[Some(wgpu::RenderPassColorAttachment { + view: &view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color { + r: 0., + g: 0., + b: 0., + a: 1., + }), + store: wgpu::StoreOp::Store, + }, + })], + depth_stencil_attachment: None, + occlusion_query_set: None, + timestamp_writes: None, + }); + + render_pass.set_pipeline(&self.render_pipeline); + render_pass.set_bind_group(0, &self.camera_bind_group, &[]); + for wireframe in &self.scene { + let line = LineUniform { + color: wireframe.color.to_array(), + _pad: 0., + }; + render_pass.set_push_constants(ShaderStages::VERTEX, 0, bytemuck::bytes_of(&line)); + render_pass.set_vertex_buffer(0, wireframe.data.slice(..)); + render_pass.draw(0..wireframe.size, 0..1); + } + } + + self.queue.submit(iter::once(encoder.finish())); + output.present(); + + Ok(()) + } +} + +pub async fn run() { + let event_loop = EventLoop::new().unwrap(); + let window = WindowBuilder::new() + .with_title("Refraction: Wireframe") + .build(&event_loop) + .unwrap(); + + // State::new uses async code, so we're going to wait for it to finish + let mut state = State::new(&window).await; + let mut surface_configured = false; + + event_loop + .run(move |event, control_flow| { + match event { + Event::WindowEvent { + ref event, + window_id, + } if window_id == state.window().id() => { + match event { + WindowEvent::KeyboardInput { + device_id: _, + event, + is_synthetic: _, + } => { + state.kbd.set_key_state(event.physical_key, event.state); + } + WindowEvent::CloseRequested => control_flow.exit(), + WindowEvent::Resized(physical_size) => { + surface_configured = true; + state.resize(*physical_size); + } + WindowEvent::RedrawRequested => { + // This tells winit that we want another frame after this one + state.window().request_redraw(); + + if !surface_configured { + return; + } + + state.update(); + match state.render() { + Ok(_) => {} + // Reconfigure the surface if it's lost or outdated + Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => { + state.resize(state.size) + } + // The system is out of memory, we should probably quit + Err(wgpu::SurfaceError::OutOfMemory) => { + eprintln!("OutOfMemory"); + control_flow.exit(); + } + + // This happens when the a frame takes too long to present + Err(wgpu::SurfaceError::Timeout) => { + eprintln!("Surface timeout") + } + } + } + _ => {} + } + } + _ => {} } - _ => (), }) .unwrap(); } +fn main() { + pollster::block_on(run()); +} + /// Make a projection matrix, assuming input coordinates are (right, up, forward). /// /// `corner` is a vector that will be mapped to (x=1, y=1) after the perspective division. diff --git a/src/bin/wireframe/ray.f.glsl b/src/bin/wireframe/ray.f.glsl deleted file mode 100644 index 775ba22..0000000 --- a/src/bin/wireframe/ray.f.glsl +++ /dev/null @@ -1,10 +0,0 @@ -#version 330 - -in vec3 vertex_color; - -out vec4 color; - -void main() { - float opacity = pow(0.5 - 0.5 * gl_FragCoord.z, 0.25); - color = opacity * vec4(vertex_color, 1.0); -} diff --git a/src/bin/wireframe/ray.v.glsl b/src/bin/wireframe/ray.v.glsl deleted file mode 100644 index 947c66a..0000000 --- a/src/bin/wireframe/ray.v.glsl +++ /dev/null @@ -1,13 +0,0 @@ -#version 330 - -uniform mat4 mvp; -uniform vec3 color; - -in vec3 position; - -out vec3 vertex_color; - -void main() { - vertex_color = color; - gl_Position = mvp * vec4(position, 1.0); -} diff --git a/src/bin/wireframe/ray.wgsl b/src/bin/wireframe/ray.wgsl new file mode 100644 index 0000000..a03f6f1 --- /dev/null +++ b/src/bin/wireframe/ray.wgsl @@ -0,0 +1,33 @@ +struct CameraUniform { + mvp: mat4x4, +} +@group(0) @binding(0) +var camera: CameraUniform; + +struct LineUniform { + color: vec3, +} +var line: LineUniform; + +struct VertexInput { + @location(0) position: vec3, +} + +struct VertexOutput { + @builtin(position) clip_position: vec4, + @location(0) vertex_color: vec3, +} + +@vertex +fn vs_main(model: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.vertex_color = line.color; + out.clip_position = camera.mvp * vec4(model.position, 1.0); + return out; +} + +@fragment +fn fs_main(in: VertexOutput) -> @location(0) vec4 { + let opacity = pow(0.5 - 0.5 * in.clip_position.z, 0.25); + return opacity * vec4(in.vertex_color, 1.0); +}