From c4721c8bfb414477b0c802a3c01f7d89c5596c17 Mon Sep 17 00:00:00 2001 From: Snowiiii <71594357+Snowiiii@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:32:20 +0200 Subject: [PATCH 01/14] Vulkan Base --- Cargo.lock | 1018 +++------------------- crates/vent-assets/Cargo.toml | 9 +- crates/vent-assets/src/lib.rs | 38 +- crates/vent-assets/src/model/gltf.rs | 19 +- crates/vent-assets/src/model/mod.rs | 112 ++- crates/vent-assets/src/model/obj.rs | 60 +- crates/vent-assets/src/texture.rs | 135 --- crates/vent-common/Cargo.toml | 4 +- crates/vent-common/src/lib.rs | 1 - crates/vent-common/src/render/mod.rs | 200 ----- crates/vent-editor/Cargo.toml | 6 +- crates/vent-rendering/Cargo.toml | 17 + crates/vent-rendering/src/allocator.rs | 45 + crates/vent-rendering/src/buffer.rs | 78 ++ crates/vent-rendering/src/image.rs | 156 ++++ crates/vent-rendering/src/instance.rs | 768 ++++++++++++++++ crates/vent-rendering/src/lib.rs | 54 ++ crates/vent-rendering/src/pipeline.rs | 148 ++++ crates/vent-runtime/Cargo.toml | 9 +- crates/vent-runtime/src/render/d2/mod.rs | 12 +- crates/vent-runtime/src/render/d3/mod.rs | 8 +- crates/vent-runtime/src/render/mod.rs | 47 +- 22 files changed, 1530 insertions(+), 1414 deletions(-) delete mode 100644 crates/vent-assets/src/texture.rs delete mode 100644 crates/vent-common/src/render/mod.rs create mode 100644 crates/vent-rendering/Cargo.toml create mode 100644 crates/vent-rendering/src/allocator.rs create mode 100644 crates/vent-rendering/src/buffer.rs create mode 100644 crates/vent-rendering/src/image.rs create mode 100644 crates/vent-rendering/src/instance.rs create mode 100644 crates/vent-rendering/src/lib.rs create mode 100644 crates/vent-rendering/src/pipeline.rs diff --git a/Cargo.lock b/Cargo.lock index 80677a1..5bb9f8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,32 +18,12 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - [[package]] name = "adler" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "ahash" version = "0.8.3" @@ -58,9 +38,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.0.5" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" +checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" dependencies = [ "memchr", ] @@ -110,23 +90,6 @@ version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" -[[package]] -name = "arboard" -version = "3.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac57f2b058a76363e357c056e4f74f1945bf734d37b8b3ef49066c4787dde0fc" -dependencies = [ - "clipboard-win", - "log", - "objc", - "objc-foundation", - "objc_id", - "parking_lot", - "thiserror", - "winapi", - "x11rb", -] - [[package]] name = "arrayref" version = "0.3.7" @@ -144,8 +107,16 @@ name = "ash" version = "0.37.3+1.3.251" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39e9c3835d686b0a6084ab4234fcd1b07dbf6e4767dce60874b12356a25ecd4a" + +[[package]] +name = "ash-window" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b912285a7c29f3a8f87ca6f55afc48768624e5e33ec17dbd2f2075903f5e35ab" dependencies = [ - "libloading 0.7.4", + "ash", + "raw-window-handle", + "raw-window-metal", ] [[package]] @@ -283,7 +254,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -326,7 +297,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -335,54 +306,18 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3" -[[package]] -name = "atomic_refcell" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112ef6b3f6cb3cb6fc5b6b494ef7a848492cff1ab0ef4de10b0f7d572861c905" - [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "backtrace" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - [[package]] name = "base64" version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "bit-set" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" - [[package]] name = "bit_field" version = "0.10.2" @@ -452,9 +387,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "bytemuck" @@ -473,7 +408,7 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -482,12 +417,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - [[package]] name = "calloop" version = "0.10.6" @@ -512,12 +441,6 @@ dependencies = [ "libc", ] -[[package]] -name = "cesu8" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" - [[package]] name = "cfg-if" version = "1.0.0" @@ -532,9 +455,9 @@ checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" [[package]] name = "chrono" -version = "0.4.30" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "defd4e7873dbddba6c7c91e199c7fcb946abc4a6a4ac3195400bcfb01b5de877" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ "android-tzdata", "iana-time-zone", @@ -545,24 +468,34 @@ dependencies = [ ] [[package]] -name = "clipboard-win" -version = "4.5.0" +name = "cocoa" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362" +checksum = "f425db7937052c684daec3bd6375c8abe2d146dca4b8b143d6db777c39138f3a" dependencies = [ - "error-code", - "str-buf", - "winapi", + "bitflags 1.3.2", + "block", + "cocoa-foundation", + "core-foundation", + "core-graphics", + "foreign-types", + "libc", + "objc", ] [[package]] -name = "codespan-reporting" -version = "0.11.1" +name = "cocoa-foundation" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +checksum = "931d3837c286f56e3c58423ce4eba12d08db2374461a785c86f672b08b5650d6" dependencies = [ - "termcolor", - "unicode-width", + "bitflags 1.3.2", + "block", + "core-foundation", + "core-graphics-types", + "foreign-types", + "libc", + "objc", ] [[package]] @@ -582,22 +515,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "com-rs" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf43edc576402991846b093a7ca18a3477e0ef9c588cde84964b5d3e43016642" - -[[package]] -name = "combine" -version = "4.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" -dependencies = [ - "bytes", - "memchr", -] - [[package]] name = "concurrent-queue" version = "2.2.0" @@ -685,16 +602,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-deque" version = "0.8.3" @@ -744,17 +651,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "d3d12" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8f0de2f5a8e7bd4a9eec0e3c781992a4ce1724f68aec7d7a3715344de8b39da" -dependencies = [ - "bitflags 1.3.2", - "libloading 0.7.4", - "winapi", -] - [[package]] name = "deranged" version = "0.3.8" @@ -794,7 +690,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" dependencies = [ - "libloading 0.8.0", + "libloading", ] [[package]] @@ -803,93 +699,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" -[[package]] -name = "duplicate" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de78e66ac9061e030587b2a2e75cc88f22304913c907b11307bca737141230cb" -dependencies = [ - "heck", - "proc-macro-error", -] - -[[package]] -name = "ecolor" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e479a7fa3f23d4e794f8b2f8b3568dd4e47886ad1b12c9c095e141cb591eb63" -dependencies = [ - "bytemuck", -] - -[[package]] -name = "egui" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3aef8ec3ae1b772f340170c65bf27d5b8c28f543a0116c844d2ac08d01123e7" -dependencies = [ - "ahash 0.8.3", - "epaint", - "log", - "nohash-hasher", -] - -[[package]] -name = "egui-wgpu" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33caaedd8283779c787298af23d8754a7e88421ff32e89ad0040c855fc0b0224" -dependencies = [ - "bytemuck", - "epaint", - "log", - "thiserror", - "type-map", - "wgpu", -] - -[[package]] -name = "egui-winit" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a49155fd4a0a4fb21224407a91de0030847972ef90fc64edb63621caea61cb2" -dependencies = [ - "arboard", - "egui", - "instant", - "log", - "raw-window-handle", - "smithay-clipboard", - "webbrowser", - "winit", -] - -[[package]] -name = "egui_dock" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ec07302c1a474f37fe6ef2c6672427880025edc37ac33955e6ea4a11bc6972a" -dependencies = [ - "duplicate", - "egui", - "paste", -] - [[package]] name = "either" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" -[[package]] -name = "emath" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3857d743a6e0741cdd60b622a74c7a36ea75f5f8f11b793b41d905d2c9721a4b" -dependencies = [ - "bytemuck", -] - [[package]] name = "enumflags2" version = "0.7.8" @@ -908,24 +723,7 @@ checksum = "f95e2801cd355d4a1a3e3953ce6ee5ae9603a5c833455343a8bfe3f44d418246" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", -] - -[[package]] -name = "epaint" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09333964d4d57f40a85338ba3ca5ed4716070ab184dcfed966b35491c5c64f3b" -dependencies = [ - "ab_glyph", - "ahash 0.8.3", - "atomic_refcell", - "bytemuck", - "ecolor", - "emath", - "log", - "nohash-hasher", - "parking_lot", + "syn 2.0.37", ] [[package]] @@ -955,16 +753,6 @@ dependencies = [ "libc", ] -[[package]] -name = "error-code" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21" -dependencies = [ - "libc", - "str-buf", -] - [[package]] name = "event-listener" version = "2.5.3" @@ -973,9 +761,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "exr" -version = "1.7.0" +version = "1.71.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1e481eb11a482815d3e9d618db8c42a93207134662873809335a92327440c18" +checksum = "832a761f35ab3e6664babfbdc6cef35a4860e816ec3916dcfd0882954e98a8a8" dependencies = [ "bit_field", "flume", @@ -1023,14 +811,10 @@ dependencies = [ [[package]] name = "flume" -version = "0.10.14" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" +checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" dependencies = [ - "futures-core", - "futures-sink", - "nanorand", - "pin-project", "spin", ] @@ -1108,7 +892,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -1150,16 +934,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "gethostname" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "getrandom" version = "0.2.10" @@ -1167,10 +941,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", - "js-sys", "libc", "wasi", - "wasm-bindgen", ] [[package]] @@ -1183,12 +955,6 @@ dependencies = [ "weezl", ] -[[package]] -name = "gimli" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" - [[package]] name = "glam" version = "0.24.1" @@ -1207,18 +973,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "glow" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca0fe580e4b60a8ab24a868bc08e2f03cbcb20d3d676601fa909386713333728" -dependencies = [ - "js-sys", - "slotmap", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "gltf" version = "1.3.0" @@ -1242,7 +996,7 @@ dependencies = [ "inflections", "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -1257,58 +1011,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "gpu-alloc" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22beaafc29b38204457ea030f6fb7a84c9e4dd1b86e311ba0542533453d87f62" -dependencies = [ - "bitflags 1.3.2", - "gpu-alloc-types", -] - -[[package]] -name = "gpu-alloc-types" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54804d0d6bc9d7f26db4eaec1ad10def69b599315f487d32c334a80d1efe67a5" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "gpu-allocator" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce95f9e2e11c2c6fadfce42b5af60005db06576f231f5c92550fdded43c423e8" -dependencies = [ - "backtrace", - "log", - "thiserror", - "winapi", - "windows 0.44.0", -] - -[[package]] -name = "gpu-descriptor" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b0c02e1ba0bdb14e965058ca34e09c020f8e507a760df1121728e0aef68d57a" -dependencies = [ - "bitflags 1.3.2", - "gpu-descriptor-types", - "hashbrown 0.12.3", -] - -[[package]] -name = "gpu-descriptor-types" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "363e3677e55ad168fef68cf9de3a4a310b53124c5e784c53a1d70e92d23f2126" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "half" version = "2.2.1" @@ -1318,47 +1020,17 @@ dependencies = [ "crunchy", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash 0.7.6", -] - [[package]] name = "hashbrown" version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" -[[package]] -name = "hassle-rs" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1397650ee315e8891a0df210707f0fc61771b0cc518c3023896064c5407cb3b0" -dependencies = [ - "bitflags 1.3.2", - "com-rs", - "libc", - "libloading 0.7.4", - "thiserror", - "widestring", - "winapi", -] - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "hex" @@ -1366,21 +1038,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hexf-parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" - -[[package]] -name = "home" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" -dependencies = [ - "windows-sys 0.48.0", -] - [[package]] name = "iana-time-zone" version = "0.1.57" @@ -1392,7 +1049,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows 0.48.0", + "windows", ] [[package]] @@ -1433,16 +1090,6 @@ dependencies = [ "tiff", ] -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - [[package]] name = "indexmap" version = "2.0.0" @@ -1450,7 +1097,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" dependencies = [ "equivalent", - "hashbrown 0.14.0", + "hashbrown", ] [[package]] @@ -1489,7 +1136,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi", - "rustix 0.38.13", + "rustix 0.38.14", "windows-sys 0.48.0", ] @@ -1499,22 +1146,6 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" -[[package]] -name = "jni" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" -dependencies = [ - "cesu8", - "cfg-if", - "combine", - "jni-sys", - "log", - "thiserror", - "walkdir", - "windows-sys 0.45.0", -] - [[package]] name = "jni-sys" version = "0.3.0" @@ -1548,17 +1179,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "khronos-egl" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c2352bd1d0bceb871cb9d40f24360c8133c11d7486b68b5381c1dd1a32015e3" -dependencies = [ - "libc", - "libloading 0.7.4", - "pkg-config", -] - [[package]] name = "kv-log-macro" version = "1.0.7" @@ -1586,16 +1206,6 @@ version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" -[[package]] -name = "libloading" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" -dependencies = [ - "cfg-if", - "winapi", -] - [[package]] name = "libloading" version = "0.8.0" @@ -1688,20 +1298,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "metal" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de11355d1f6781482d027a3b4d4de7825dcedb197bf573e0596d00008402d060" -dependencies = [ - "bitflags 1.3.2", - "block", - "core-graphics-types", - "foreign-types", - "log", - "objc", -] - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1730,35 +1326,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "naga" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbcc2e0513220fd2b598e6068608d4462db20322c0e77e47f6f488dfcfc279cb" -dependencies = [ - "bit-set", - "bitflags 1.3.2", - "codespan-reporting", - "hexf-parse", - "indexmap 1.9.3", - "log", - "num-traits", - "rustc-hash", - "spirv", - "termcolor", - "thiserror", - "unicode-xid", -] - -[[package]] -name = "nanorand" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" -dependencies = [ - "getrandom", -] - [[package]] name = "ndk" version = "0.7.0" @@ -1825,12 +1392,6 @@ dependencies = [ "memoffset 0.7.1", ] -[[package]] -name = "nohash-hasher" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" - [[package]] name = "nom" version = "7.1.3" @@ -1880,16 +1441,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "num_enum" version = "0.5.11" @@ -1929,7 +1480,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -1948,7 +1499,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" dependencies = [ "malloc_buf", - "objc_exception", ] [[package]] @@ -1983,18 +1533,9 @@ dependencies = [ name = "objc2-encode" version = "2.0.0-pre.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abfcac41015b00a120608fdaa6938c44cb983fee294351cc4bac7638b4e50512" -dependencies = [ - "objc-sys", -] - -[[package]] -name = "objc_exception" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4" +checksum = "abfcac41015b00a120608fdaa6938c44cb983fee294351cc4bac7638b4e50512" dependencies = [ - "cc", + "objc-sys", ] [[package]] @@ -2006,15 +1547,6 @@ dependencies = [ "objc", ] -[[package]] -name = "object" -version = "0.32.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.18.0" @@ -2055,61 +1587,12 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.48.5", -] - -[[package]] -name = "paste" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" - [[package]] name = "percent-encoding" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" -[[package]] -name = "pin-project" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.33", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -2179,30 +1662,6 @@ dependencies = [ "toml_edit", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.67" @@ -2212,12 +1671,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "profiling" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45f10e75d83c7aec79a6aa46f897075890e156b105eebe51cfa0abce51af025f" - [[package]] name = "qoi" version = "0.4.1" @@ -2266,23 +1719,29 @@ dependencies = [ "getrandom", ] -[[package]] -name = "range-alloc" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8a99fddc9f0ba0a85884b8d14e3592853e787d581ca1816c91349b10e4eeab" - [[package]] name = "raw-window-handle" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" +[[package]] +name = "raw-window-metal" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed91094d30089fc273de843cfef783f8c04cc75828277a64e0e8dc2a0cebd4dc" +dependencies = [ + "cocoa", + "core-graphics", + "objc", + "raw-window-handle", +] + [[package]] name = "rayon" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" dependencies = [ "either", "rayon-core", @@ -2290,14 +1749,12 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "num_cpus", ] [[package]] @@ -2338,12 +1795,6 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" -[[package]] -name = "renderdoc-sys" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216080ab382b992234dda86873c18d4c48358f5cfcb70fd693d7f6f2131b628b" - [[package]] name = "rfd" version = "0.12.0" @@ -2377,18 +1828,6 @@ dependencies = [ "vent-runtime", ] -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustix" version = "0.37.23" @@ -2405,9 +1844,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.13" +version = "0.38.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7db8590df6dfcd144d22afd1b83b36c21a18d7cbc1dc4bb5295a8712e9eb662" +checksum = "747c788e9ce8e92b12cd485c49ddf90723550b654b32508f979b71a7b1ecda4f" dependencies = [ "bitflags 2.4.0", "errno", @@ -2422,15 +1861,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - [[package]] name = "scoped-tls" version = "1.0.1" @@ -2473,7 +1903,7 @@ checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -2495,14 +1925,14 @@ checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] name = "sha1" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", "cpufeatures", @@ -2566,15 +1996,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "smithay-client-toolkit" -version = "0.16.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f307c47d32d2715eb2e0ece5589057820e0e5e70d07c247d1063e844e107f454" +checksum = "870427e30b8f2cbe64bf43ec4b86e88fe39b0a84b3f15efd9c9c2d020bc86eb9" dependencies = [ "bitflags 1.3.2", "calloop", @@ -2589,16 +2019,6 @@ dependencies = [ "wayland-protocols", ] -[[package]] -name = "smithay-clipboard" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a345c870a1fae0b1b779085e81b51e614767c239e93503588e54c5b17f4b0e8" -dependencies = [ - "smithay-client-toolkit", - "wayland-client", -] - [[package]] name = "socket2" version = "0.4.9" @@ -2618,28 +2038,12 @@ dependencies = [ "lock_api", ] -[[package]] -name = "spirv" -version = "0.2.0+1.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246bfa38fe3db3f1dfc8ca5a2cdeb7348c78be2112740cc0ec8ef18b6d94f830" -dependencies = [ - "bitflags 1.3.2", - "num-traits", -] - [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "str-buf" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" - [[package]] name = "strict-num" version = "0.1.1" @@ -2659,9 +2063,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.33" +version = "2.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9caece70c63bfba29ec2fed841a09851b14a235c60010fa4de58089b6c025668" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" dependencies = [ "proc-macro2", "quote", @@ -2692,19 +2096,10 @@ dependencies = [ "cfg-if", "fastrand 2.0.0", "redox_syscall", - "rustix 0.38.13", + "rustix 0.38.14", "windows-sys 0.48.0", ] -[[package]] -name = "termcolor" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" -dependencies = [ - "winapi-util", -] - [[package]] name = "thiserror" version = "1.0.48" @@ -2722,7 +2117,7 @@ checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -2812,7 +2207,7 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b450e3ba06251ec4fc76917dafeaf55805ffb26dbf7d5500bfb9511ce63a0d1f" dependencies = [ - "ahash 0.8.3", + "ahash", ] [[package]] @@ -2827,7 +2222,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.0.0", + "indexmap", "toml_datetime", "winnow", ] @@ -2852,7 +2247,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -2870,20 +2265,11 @@ version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49d64318d8311fc2668e48b63969f4343e0a85c4a109aa8460d6672e364b8bd1" -[[package]] -name = "type-map" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deb68604048ff8fa93347f02441e4487594adc20bb8a084f9e564d2b827a0a9f" -dependencies = [ - "rustc-hash", -] - [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "uds_windows" @@ -2916,18 +2302,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - [[package]] name = "url" version = "2.4.1" @@ -2962,14 +2336,15 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" name = "vent-assets" version = "0.1.0" dependencies = [ + "ash", "bytemuck", "cfg-if", "gltf", "image", "log", "tobj", + "vent-rendering", "vent-sdk", - "wgpu", ] [[package]] @@ -2981,14 +2356,12 @@ dependencies = [ "console_log", "image", "log", - "pollster", "serde", "serde_json", "sysinfo", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "wgpu", "winit", ] @@ -3003,15 +2376,25 @@ dependencies = [ name = "vent-editor" version = "0.1.0" dependencies = [ - "egui", - "egui_dock", "log", "pollster", "rfd", "simple_logger", "vent-common", + "vent-rendering", "vent-runtime", - "wgpu", + "winit", +] + +[[package]] +name = "vent-rendering" +version = "0.1.0" +dependencies = [ + "ash", + "ash-window", + "bytemuck", + "image", + "raw-window-handle", "winit", ] @@ -3022,9 +2405,6 @@ dependencies = [ "anyhow", "bytemuck", "downcast-rs", - "egui", - "egui-wgpu", - "egui-winit", "fs_extra", "glam", "log", @@ -3033,7 +2413,7 @@ dependencies = [ "vent-assets", "vent-common", "vent-ecs", - "wgpu", + "vent-rendering", "winit", ] @@ -3053,16 +2433,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" -[[package]] -name = "walkdir" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" -dependencies = [ - "same-file", - "winapi-util", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -3090,7 +2460,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", "wasm-bindgen-shared", ] @@ -3124,7 +2494,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3218,135 +2588,12 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webbrowser" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2c79b77f525a2d670cb40619d7d9c673d09e0666f72c591ebd7861f84a87e57" -dependencies = [ - "core-foundation", - "home", - "jni", - "log", - "ndk-context", - "objc", - "raw-window-handle", - "url", - "web-sys", -] - [[package]] name = "weezl" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" -[[package]] -name = "wgpu" -version = "0.16.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "480c965c9306872eb6255fa55e4b4953be55a8b64d57e61d7ff840d3dcc051cd" -dependencies = [ - "arrayvec", - "cfg-if", - "js-sys", - "log", - "naga", - "parking_lot", - "profiling", - "raw-window-handle", - "smallvec", - "static_assertions", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "wgpu-core", - "wgpu-hal", - "wgpu-types", -] - -[[package]] -name = "wgpu-core" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f478237b4bf0d5b70a39898a66fa67ca3a007d79f2520485b8b0c3dfc46f8c2" -dependencies = [ - "arrayvec", - "bit-vec", - "bitflags 2.4.0", - "codespan-reporting", - "log", - "naga", - "parking_lot", - "profiling", - "raw-window-handle", - "rustc-hash", - "smallvec", - "thiserror", - "web-sys", - "wgpu-hal", - "wgpu-types", -] - -[[package]] -name = "wgpu-hal" -version = "0.16.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ecb3258078e936deee14fd4e0febe1cfe9bbb5ffef165cb60218d2ee5eb4448" -dependencies = [ - "android_system_properties", - "arrayvec", - "ash", - "bit-set", - "bitflags 2.4.0", - "block", - "core-graphics-types", - "d3d12", - "foreign-types", - "glow", - "gpu-alloc", - "gpu-allocator", - "gpu-descriptor", - "hassle-rs", - "js-sys", - "khronos-egl", - "libc", - "libloading 0.8.0", - "log", - "metal", - "naga", - "objc", - "parking_lot", - "profiling", - "range-alloc", - "raw-window-handle", - "renderdoc-sys", - "rustc-hash", - "smallvec", - "thiserror", - "wasm-bindgen", - "web-sys", - "wgpu-types", - "winapi", -] - -[[package]] -name = "wgpu-types" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c153280bb108c2979eb5c7391cb18c56642dd3c072e55f52065e13e2a1252a" -dependencies = [ - "bitflags 2.4.0", - "js-sys", - "web-sys", -] - -[[package]] -name = "widestring" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" - [[package]] name = "winapi" version = "0.3.9" @@ -3363,39 +2610,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-wsapoll" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows" -version = "0.44.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e745dab35a0c4c77aa3ce42d595e13d2003d6902d6b08c9ef5fc326d08da12b" -dependencies = [ - "windows-targets 0.42.2", -] - [[package]] name = "windows" version = "0.48.0" @@ -3607,28 +2827,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "x11rb" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" -dependencies = [ - "gethostname", - "nix 0.24.3", - "winapi", - "winapi-wsapoll", - "x11rb-protocol", -] - -[[package]] -name = "x11rb-protocol" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67" -dependencies = [ - "nix 0.24.3", -] - [[package]] name = "xcursor" version = "0.3.4" diff --git a/crates/vent-assets/Cargo.toml b/crates/vent-assets/Cargo.toml index 368354f..fd3c6a5 100644 --- a/crates/vent-assets/Cargo.toml +++ b/crates/vent-assets/Cargo.toml @@ -7,14 +7,17 @@ edition = "2021" [dependencies] vent-sdk = { path = "../vent-sdk" } +vent-rendering = { path = "../vent-rendering"} -wgpu = "0.16.2" -bytemuck = { version = "1.14.0", features = ["derive"] } +image = "0.24.7" + +bytemuck = { version = "1.14.0" } log = "0.4" cfg-if = "1" +ash = { version= "0.37.3", default-features = false, features = ["linked"] } + # model tobj = { version = "4.0.0", features = ["async"] } gltf = "1.3.0" -image = "0.24.7" diff --git a/crates/vent-assets/src/lib.rs b/crates/vent-assets/src/lib.rs index b6015ed..03af14f 100644 --- a/crates/vent-assets/src/lib.rs +++ b/crates/vent-assets/src/lib.rs @@ -1,34 +1,12 @@ -use std::mem; - -use bytemuck::{Pod, Zeroable}; +use ash::vk; +use vent_rendering::buffer::VulkanBuffer; pub mod model; pub mod pool; pub mod shader; -pub mod texture; pub trait Asset {} -pub trait Vertex<'a> { - const LAYOUT: wgpu::VertexBufferLayout<'a>; -} - -#[repr(C)] -#[derive(Clone, Copy, Pod, Zeroable)] -pub struct Vertex3D { - pub position: [f32; 3], - pub tex_coord: [f32; 2], - pub normal: [f32; 3], -} - -impl<'a> Vertex<'a> for Vertex3D { - const LAYOUT: wgpu::VertexBufferLayout<'a> = wgpu::VertexBufferLayout { - array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x2, 2 => Float32x3], - }; -} - /// A Full Model that can be Loaded from a 3D Model File /// This is done by Parsing all Essensial Informations like Vertices, Indices, Materials & More pub struct Model3D { @@ -42,15 +20,9 @@ pub struct Model3D { pub struct Mesh3D { // Basic - vertex_buf: wgpu::Buffer, - index_buf: wgpu::Buffer, + vertex_buf: VulkanBuffer, + index_buf: VulkanBuffer, index_count: u32, - bind_group: Option, -} - -pub struct Texture { - pub texture: wgpu::Texture, - pub view: wgpu::TextureView, - pub sampler: wgpu::Sampler, + descriptor_set: Option, } diff --git a/crates/vent-assets/src/model/gltf.rs b/crates/vent-assets/src/model/gltf.rs index c907861..8688dde 100644 --- a/crates/vent-assets/src/model/gltf.rs +++ b/crates/vent-assets/src/model/gltf.rs @@ -5,6 +5,7 @@ use std::{ sync, thread, }; +use ash::vk; use wgpu::{util::DeviceExt, BindGroupLayout}; use crate::{Model3D, Texture, Vertex3D}; @@ -14,12 +15,7 @@ use super::{Material, Mesh3D, ModelError}; pub(crate) struct GLTFLoader {} impl GLTFLoader { - pub async fn load( - device: &wgpu::Device, - queue: &wgpu::Queue, - path: &Path, - texture_bind_group_layout: &BindGroupLayout, - ) -> Result { + pub async fn load(device: &ash::Device, path: &Path) -> Result { let doc = gltf::Gltf::from_reader(fs::File::open(path).unwrap()).unwrap(); let path = path.parent().unwrap_or_else(|| Path::new("./")); @@ -51,7 +47,6 @@ impl GLTFLoader { model_dir: &Path, node: gltf::Node<'_>, buffer_data: &[gltf::buffer::Data], - texture_bind_group_layout: &BindGroupLayout, meshes: &mut Vec, ) { if let Some(mesh) = node.mesh() { @@ -85,7 +80,6 @@ impl GLTFLoader { model_dir: &Path, mesh: gltf::Mesh, buffer_data: &[gltf::buffer::Data], - texture_bind_group_layout: &BindGroupLayout, meshes: &mut Vec, ) { let primitive_len = mesh.primitives().size_hint().0; @@ -137,7 +131,6 @@ impl GLTFLoader { material: gltf::Material<'_>, buffer_data: &[gltf::buffer::Data], // image_data: &[gltf::image::Data], - texture_bind_group_layout: &BindGroupLayout, ) -> wgpu::BindGroup { let pbr = material.pbr_metallic_roughness(); @@ -257,11 +250,11 @@ impl GLTFLoader { } #[must_use] - fn conv_wrapping_mode(mode: gltf::texture::WrappingMode) -> wgpu::AddressMode { + fn conv_wrapping_mode(mode: gltf::texture::WrappingMode) -> vk::SamplerAddressMode { match mode { - gltf::texture::WrappingMode::ClampToEdge => wgpu::AddressMode::ClampToEdge, - gltf::texture::WrappingMode::MirroredRepeat => wgpu::AddressMode::MirrorRepeat, - gltf::texture::WrappingMode::Repeat => wgpu::AddressMode::Repeat, + gltf::texture::WrappingMode::ClampToEdge => vk::SamplerAddressMode::CLAMP_TO_EDGE, + gltf::texture::WrappingMode::MirroredRepeat => vk::SamplerAddressMode::MIRRORED_REPEAT, + gltf::texture::WrappingMode::Repeat => vk::SamplerAddressMode::REPEAT, } } diff --git a/crates/vent-assets/src/model/mod.rs b/crates/vent-assets/src/model/mod.rs index 80d252f..e9cba82 100644 --- a/crates/vent-assets/src/model/mod.rs +++ b/crates/vent-assets/src/model/mod.rs @@ -1,11 +1,15 @@ +use std::mem::size_of; use std::path::Path; +use ash::vk; use bytemuck::{Pod, Zeroable}; +use vent_rendering::allocator::MemoryAllocator; +use vent_rendering::buffer::VulkanBuffer; +use vent_rendering::instance::{self, Instance}; +use vent_rendering::Vertex3D; use vent_sdk::utils::stopwatch::Stopwatch; -use wgpu::util::DeviceExt; -use wgpu::{BindGroupLayout, Device}; -use crate::{Mesh3D, Model3D, Vertex3D}; +use crate::{Mesh3D, Model3D}; use self::gltf::GLTFLoader; use self::obj::OBJLoader; @@ -29,13 +33,12 @@ pub struct Material { impl Model3D { #[inline] pub async fn load>( - device: &Device, - queue: &wgpu::Queue, + device: &ash::Device, path: P, - texture_bind_group_layout: &BindGroupLayout, + allocator: &MemoryAllocator, ) -> Self { let sw = Stopwatch::new_and_start(); - let model = load_model_from_path(device, queue, path.as_ref(), texture_bind_group_layout) + let model = load_model_from_path(device, path.as_ref(), allocator) .await .expect("Failed to Load 3D Model"); log::info!( @@ -47,22 +50,26 @@ impl Model3D { model } - pub fn draw<'rp>(&'rp self, rpass: &mut wgpu::RenderPass<'rp>) { + pub fn draw( + &self, + device: &ash::Device, + pipeline_layout: vk::PipelineLayout, + command_buffer: vk::CommandBuffer, + ) { self.meshes.iter().for_each(|mesh| { - rpass.push_debug_group("Bind Mesh"); - mesh.bind(rpass, true); - rpass.pop_debug_group(); - rpass.insert_debug_marker("Draw!"); - mesh.draw(rpass); + // rpass.push_debug_group("Bind Mesh"); + mesh.bind(device, command_buffer, pipeline_layout, true); + // rpass.pop_debug_group(); + // rpass.insert_debug_marker("Draw!"); + mesh.draw(device, command_buffer); }) } } async fn load_model_from_path( - device: &wgpu::Device, - queue: &wgpu::Queue, + device: &ash::Device, path: &Path, - texture_bind_group_layout: &BindGroupLayout, + allocator: &MemoryAllocator, ) -> Result { if !path.exists() { return Err(ModelError::FileNotExists); @@ -72,51 +79,76 @@ async fn load_model_from_path( // Very Pretty, I know match extension { - "obj" => Ok(OBJLoader::load(device, queue, path, texture_bind_group_layout).await?), - "gltf" => Ok(GLTFLoader::load(device, queue, path, texture_bind_group_layout).await?), + "obj" => Ok(OBJLoader::load(device, path, allocator).await?), + "gltf" => Ok(GLTFLoader::load(device, path).await?), _ => Err(ModelError::UnsupportedFormat), } } impl Mesh3D { pub fn new( - device: &Device, + device: &ash::Device, + allocator: &MemoryAllocator, vertices: &[Vertex3D], indices: &[u32], - bind_group: Option, + bind_group: Option, name: Option<&str>, ) -> Self { - let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: name, - contents: bytemuck::cast_slice(vertices), - usage: wgpu::BufferUsages::VERTEX, - }); - - let index_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: name, - contents: bytemuck::cast_slice(indices), - usage: wgpu::BufferUsages::INDEX, - }); + let vertex_buf = VulkanBuffer::new_init( + device, + allocator, + (size_of::() * vertices.len()) as vk::DeviceSize, + vk::BufferUsageFlags::VERTEX_BUFFER, + bytemuck::cast_slice(vertices), + ); + + let index_buf = VulkanBuffer::new_init( + device, + allocator, + (size_of::() * indices.len()) as vk::DeviceSize, + vk::BufferUsageFlags::INDEX_BUFFER, + bytemuck::cast_slice(indices), + ); Self { vertex_buf, index_buf, index_count: indices.len() as u32, - bind_group, + descriptor_set: bind_group, } } - pub fn bind<'rp>(&'rp self, rpass: &mut wgpu::RenderPass<'rp>, with_group: bool) { - rpass.set_index_buffer(self.index_buf.slice(..), wgpu::IndexFormat::Uint32); - rpass.set_vertex_buffer(0, self.vertex_buf.slice(..)); - if with_group { - if let Some(bg) = self.bind_group.as_ref() { - rpass.set_bind_group(1, bg, &[]); + pub fn bind( + &self, + device: &ash::Device, + command_buffer: vk::CommandBuffer, + pipeline_layout: vk::PipelineLayout, + with_descriptor_set: bool, + ) { + unsafe { + device.cmd_bind_vertex_buffers(command_buffer, 0, &[*self.vertex_buf], &[0]); + device.cmd_bind_index_buffer(command_buffer, *self.index_buf, 0, vk::IndexType::UINT32); + if with_descriptor_set { + if let Some(ds) = self.descriptor_set { + device.cmd_bind_descriptor_sets( + command_buffer, + vk::PipelineBindPoint::GRAPHICS, + pipeline_layout, + 0, + &[ds], + &[], + ) + } } } } - pub fn draw(&self, rpass: &mut wgpu::RenderPass<'_>) { - rpass.draw_indexed(0..self.index_count, 0, 0..1); + pub fn draw(&self, device: &ash::Device, command_buffer: vk::CommandBuffer) { + unsafe { device.cmd_draw_indexed(command_buffer, self.index_count, 1, 0, 0, 0) }; + } + + pub fn destroy(&self, device: &ash::Device) { + self.vertex_buf.destroy(device); + self.index_buf.destroy(device); } } diff --git a/crates/vent-assets/src/model/obj.rs b/crates/vent-assets/src/model/obj.rs index b703b3f..219d89f 100644 --- a/crates/vent-assets/src/model/obj.rs +++ b/crates/vent-assets/src/model/obj.rs @@ -1,5 +1,7 @@ use std::path::Path; +use ash::vk; +use vent_rendering::{allocator::MemoryAllocator, image::VulkanImage}; use wgpu::{util::DeviceExt, BindGroupLayout}; use crate::{Model3D, Texture, Vertex3D}; @@ -10,10 +12,9 @@ pub(crate) struct OBJLoader {} impl OBJLoader { pub async fn load( - device: &wgpu::Device, - queue: &wgpu::Queue, + device: &ash::Device, path: &Path, - texture_bind_group_layout: &BindGroupLayout, + allocator: &MemoryAllocator, ) -> Result { let (models, materials) = match tobj::load_obj(path, &tobj::GPU_LOAD_OPTIONS) { Ok(r) => r, @@ -32,31 +33,21 @@ impl OBJLoader { let meshes = models .into_iter() - .map(|model| Self::load_mesh(device, &model.name, &model.mesh)) + .map(|model| Self::load_mesh(device, &model.name, &model.mesh, allocator)) .collect::>(); let _final_materials = materials .into_iter() - .map(|material| { - Self::load_material( - device, - queue, - path.parent().unwrap(), - &material, - texture_bind_group_layout, - ) - }) + .map(|material| Self::load_material(device, path.parent().unwrap(), &material)) .collect::>(); Ok(Model3D { meshes }) } fn load_material( - device: &wgpu::Device, - queue: &wgpu::Queue, + device: &ash::Device, model_dir: &Path, material: &tobj::Material, - texture_bind_group_layout: &BindGroupLayout, ) -> wgpu::BindGroup { let diffuse_texture = if let Some(texture) = &material.diffuse_texture { Texture::from_image( @@ -99,7 +90,41 @@ impl OBJLoader { }) } - fn load_mesh(device: &wgpu::Device, name: &str, mesh: &tobj::Mesh) -> Mesh3D { + fn write_sets(device: &ash::Device, diffuse_texture: VulkanImage) { + let image_info = vk::DescriptorImageInfo::builder() + .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) + .image_view(data.texture_image_view) + .sampler(data.texture_sampler) + .build(); + + let sampler_write = vk::WriteDescriptorSet::builder() + .dst_set(data.descriptor_sets[i]) + .dst_binding(0) + .dst_array_element(0) + .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) + .image_info(&[image_info]); + + let buffer_info = vk::DescriptorBufferInfo::builder() + .buffer(data.uniform_buffers[i]) + .offset(0) + .range(size_of::() as u64) + .build(); + + let ubo_write = vk::WriteDescriptorSet::builder() + .dst_set(data.descriptor_sets[i]) + .dst_binding(1) + .dst_array_element(0) + .descriptor_type(vk::DescriptorType::UNIFORM_BUFFER) + .buffer_info(&[buffer_info]) + .build(); + } + + fn load_mesh( + device: &ash::Device, + allocator: &MemoryAllocator, + name: &str, + mesh: &tobj::Mesh, + ) -> Mesh3D { let vertices = (0..mesh.positions.len() / 3) .map(|i| Vertex3D { position: [ @@ -118,6 +143,7 @@ impl OBJLoader { Mesh3D::new( device, + allocator, &vertices, &mesh.indices, None, // TODO diff --git a/crates/vent-assets/src/texture.rs b/crates/vent-assets/src/texture.rs deleted file mode 100644 index 336194e..0000000 --- a/crates/vent-assets/src/texture.rs +++ /dev/null @@ -1,135 +0,0 @@ -use image::{GenericImageView, ImageError}; -use wgpu::util::DeviceExt; - -use crate::Texture; - -impl Texture { - pub const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float; - pub const DEFAULT_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb; - pub const DEFAULT_TEXTURE_FILTER: wgpu::FilterMode = wgpu::FilterMode::Linear; - - #[must_use] - pub fn create_depth_view( - device: &wgpu::Device, - width: u32, - height: u32, - label: Option<&str>, - ) -> wgpu::TextureView { - let size = wgpu::Extent3d { - width, - height, - depth_or_array_layers: 1, - }; - - let texture = device.create_texture(&wgpu::TextureDescriptor { - label, - size, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: Self::DEPTH_FORMAT, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[Self::DEPTH_FORMAT], - }); - texture.create_view(&wgpu::TextureViewDescriptor::default()) - } - - // This Should be Prefered - pub fn from_memory_to_image_with_format( - device: &wgpu::Device, - queue: &wgpu::Queue, - bytes: &[u8], - format: image::ImageFormat, - label: Option<&str>, - ) -> Result { - let img = image::load_from_memory_with_format(bytes, format)?; - Ok(Self::from_image(device, queue, img, None, label)) - } - - pub fn from_image( - device: &wgpu::Device, - queue: &wgpu::Queue, - img: image::DynamicImage, - sampler_desc: Option<&wgpu::SamplerDescriptor>, - texture_label: Option<&str>, - ) -> Self { - let dimensions = img.dimensions(); - Self::create( - device, - queue, - &img.into_rgba8(), - dimensions.0, - dimensions.1, - Self::DEFAULT_TEXTURE_FORMAT, - sampler_desc.unwrap_or(&wgpu::SamplerDescriptor::default()), - texture_label, - ) - } - - pub fn from_color( - device: &wgpu::Device, - queue: &wgpu::Queue, - color: [u8; 4], - width: u32, - height: u32, - label: Option<&str>, - ) -> Self { - let img = image::RgbaImage::from_pixel(width, height, image::Rgba(color)); - Self::create( - device, - queue, - &img, - width, - height, - Self::DEFAULT_TEXTURE_FORMAT, - &wgpu::SamplerDescriptor { - mag_filter: Self::DEFAULT_TEXTURE_FILTER, - min_filter: Self::DEFAULT_TEXTURE_FILTER, - mipmap_filter: Self::DEFAULT_TEXTURE_FILTER, - lod_max_clamp: 1.0, - ..Default::default() - }, - label, - ) - } - - pub fn create( - device: &wgpu::Device, - queue: &wgpu::Queue, - bytes: &[u8], - width: u32, - height: u32, - format: wgpu::TextureFormat, - sampler_desc: &wgpu::SamplerDescriptor, - texture_label: Option<&str>, - ) -> Self { - let size = wgpu::Extent3d { - width, - height, - depth_or_array_layers: 1, - }; - let texture = device.create_texture_with_data( - queue, - &wgpu::TextureDescriptor { - size, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format, - usage: wgpu::TextureUsages::TEXTURE_BINDING, - label: texture_label, - view_formats: &[], - }, - bytes, - ); - - let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); - let sampler = device.create_sampler(sampler_desc); - - Self { - texture, - view, - sampler, - } - } -} diff --git a/crates/vent-common/Cargo.toml b/crates/vent-common/Cargo.toml index 19cc00a..da75247 100644 --- a/crates/vent-common/Cargo.toml +++ b/crates/vent-common/Cargo.toml @@ -7,8 +7,6 @@ edition = "2021" [dependencies] winit = "0.28.6" -wgpu = "0.16.2" -pollster = "0.3.0" sysinfo = "0.29" chrono = "0.4" @@ -24,7 +22,7 @@ serde_json = "1.0" [target.'cfg(target_arch = "wasm32")'.dependencies] console_error_panic_hook = "0.1.7" console_log = "1" -wgpu = { version = "0.16, 0", features = ["webgl"]} +# wgpu = { version = "0.16, 0", features = ["webgl"]} wasm-bindgen = "0.2.87" wasm-bindgen-futures = "0.4.37" web-sys = { version = "0.3.64", features = [ diff --git a/crates/vent-common/src/lib.rs b/crates/vent-common/src/lib.rs index 66f7b97..e7bcddc 100644 --- a/crates/vent-common/src/lib.rs +++ b/crates/vent-common/src/lib.rs @@ -1,4 +1,3 @@ pub mod project; -pub mod render; pub mod util; pub mod window; diff --git a/crates/vent-common/src/render/mod.rs b/crates/vent-common/src/render/mod.rs deleted file mode 100644 index 81d5c00..0000000 --- a/crates/vent-common/src/render/mod.rs +++ /dev/null @@ -1,200 +0,0 @@ -use pollster::block_on; -use wgpu::{Adapter, Device, Queue, Surface, SurfaceCapabilities, SurfaceConfiguration}; -use winit::dpi::PhysicalSize; -use winit::window::Window; - -use log::debug; - -#[cfg(target_arch = "wasm32")] -use std::str::FromStr; - -#[cfg(target_arch = "wasm32")] -use web_sys::{ImageBitmapRenderingContext, OffscreenCanvas}; - -#[cfg(target_arch = "wasm32")] -/// Parse the query string as returned by `web_sys::window()?.location().search()?` and get a -/// specific key out of it. -pub fn parse_url_query_string<'a>(query: &'a str, search_key: &str) -> Option<&'a str> { - let query_string = query.strip_prefix('?')?; - - for pair in query_string.split('&') { - let mut pair = pair.split('='); - let key = pair.next()?; - let value = pair.next()?; - - if key == search_key { - return Some(value); - } - } - - None -} - -#[cfg(target_arch = "wasm32")] -pub struct OffscreenCanvasSetup { - pub offscreen_canvas: OffscreenCanvas, - pub bitmap_renderer: ImageBitmapRenderingContext, -} - -pub struct WGPURenderer { - pub surface: Surface, - pub device: Device, - pub adapter: Adapter, - pub queue: Queue, - - pub config: SurfaceConfiguration, - pub caps: SurfaceCapabilities, - - #[cfg(target_arch = "wasm32")] - pub offscreen_canvas_setup: Option, -} - -impl WGPURenderer { - #[must_use] - pub fn new(window: &Window) -> Self { - let backends = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all); - let dx12_shader_compiler = wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(); - - let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - backends, - dx12_shader_compiler, - }); - - #[cfg(target_arch = "wasm32")] - { - use winit::platform::web::WindowExtWebSys; - let query_string = web_sys::window().unwrap().location().search().unwrap(); - let level: log::Level = parse_url_query_string(&query_string, "RUST_LOG") - .and_then(|x| x.parse().ok()) - .unwrap_or(log::Level::Error); - console_log::init_with_level(level).expect("could not initialize logger"); - std::panic::set_hook(Box::new(console_error_panic_hook::hook)); - // On wasm, append the canvas to the document body - web_sys::window() - .and_then(|win| win.document()) - .and_then(|doc| doc.body()) - .and_then(|body| { - body.append_child(&web_sys::Element::from(window.canvas())) - .ok() - }) - .expect("couldn't append canvas to document body"); - } - - #[cfg(target_arch = "wasm32")] - let mut offscreen_canvas_setup: Option = None; - #[cfg(target_arch = "wasm32")] - { - use wasm_bindgen::JsCast; - use winit::platform::web::WindowExtWebSys; - - let query_string = web_sys::window().unwrap().location().search().unwrap(); - if let Some(offscreen_canvas_param) = - parse_url_query_string(&query_string, "offscreen_canvas") - { - if FromStr::from_str(offscreen_canvas_param) == Ok(true) { - log::info!("Creating OffscreenCanvasSetup"); - - let offscreen_canvas = - OffscreenCanvas::new(1024, 768).expect("couldn't create OffscreenCanvas"); - - let bitmap_renderer = window - .canvas() - .get_context("bitmaprenderer") - .expect("couldn't create ImageBitmapRenderingContext (Result)") - .expect("couldn't create ImageBitmapRenderingContext (Option)") - .dyn_into::() - .expect("couldn't convert into ImageBitmapRenderingContext"); - - offscreen_canvas_setup = Some(OffscreenCanvasSetup { - offscreen_canvas, - bitmap_renderer, - }) - } - } - }; - - let surface = unsafe { - #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] - let surface = match instance.create_surface(&window) { - Ok(t) => t, - Err(e) => { - panic!("{}", format!("{e}")); - } - }; - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] - let surface = { - if let Some(offscreen_canvas_setup) = &offscreen_canvas_setup { - log::info!("Creating surface from OffscreenCanvas"); - instance.create_surface_from_offscreen_canvas( - &offscreen_canvas_setup.offscreen_canvas, - ) - } else { - instance.create_surface(&window) - } - } - .unwrap(); - - surface - }; - let adapter = block_on(wgpu::util::initialize_adapter_from_env_or_default( - &instance, - backends, - Some(&surface), - )) - .expect("No suitable GPU adapters found on the system!"); - - #[cfg(not(target_arch = "wasm32"))] - { - let adapter_info = adapter.get_info(); - debug!("GPU {} {:?}", adapter_info.name, adapter_info.device_type); - debug!( - "Software {:?} {}", - adapter_info.backend, adapter_info.driver_info - ); - } - - let trace_dir = std::env::var("WGPU_TRACE"); - let (device, queue) = match block_on(adapter.request_device( - &wgpu::DeviceDescriptor { - label: None, - features: wgpu::Features::default(), - limits: if cfg!(target_arch = "wasm32") { - wgpu::Limits::downlevel_webgl2_defaults() - } else { - wgpu::Limits::default() - }, - }, - trace_dir.ok().as_ref().map(std::path::Path::new), - )) { - Ok(t) => t, - Err(e) => { - panic!("{}", format!("{e}")); - } - }; - - let size = window.inner_size(); - let config = surface - .get_default_config(&adapter, size.width, size.height) - .expect("Surface isn't supported by the adapter."); - surface.configure(&device, &config); - let caps = surface.get_capabilities(&adapter); - - Self { - surface, - device, - adapter, - queue, - config, - caps, - - #[cfg(target_arch = "wasm32")] - offscreen_canvas_setup, - } - } - - pub fn resize(&mut self, new_size: &PhysicalSize) { - self.config.width = new_size.width.max(1); - self.config.height = new_size.height.max(1); - self.surface.configure(&self.device, &self.config); - } -} diff --git a/crates/vent-editor/Cargo.toml b/crates/vent-editor/Cargo.toml index 7b48170..61a7bd4 100644 --- a/crates/vent-editor/Cargo.toml +++ b/crates/vent-editor/Cargo.toml @@ -9,12 +9,12 @@ edition = "2021" vent-runtime = { path = "../vent-runtime"} vent-common = { path = "../vent-common"} +vent-rendering = { path = "../vent-rendering"} # egui -egui = "0.22.0" -egui_dock = "0.6.1" +# egui = "0.22.0" +# egui_dock = "0.6.1" winit = "0.28.6" -wgpu = "0.16.2" pollster = "0.3.0" log = "0.4" diff --git a/crates/vent-rendering/Cargo.toml b/crates/vent-rendering/Cargo.toml new file mode 100644 index 0000000..15f7342 --- /dev/null +++ b/crates/vent-rendering/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "vent-rendering" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ash = { version= "0.37.3", default-features = false, features = ["linked", "debug"] } + +image = "0.24.7" + +winit = "0.28.0" +raw-window-handle = "0.5" +ash-window = "0.12.0" + +bytemuck = { version = "1.14.0", features = ["derive"] } diff --git a/crates/vent-rendering/src/allocator.rs b/crates/vent-rendering/src/allocator.rs new file mode 100644 index 0000000..17e3ecc --- /dev/null +++ b/crates/vent-rendering/src/allocator.rs @@ -0,0 +1,45 @@ +use ash::vk; + +// TODO Write an own Efficent Vulkan Memory Allocator + +pub struct MemoryAllocator { + memory_props: vk::PhysicalDeviceMemoryProperties, +} + +impl MemoryAllocator { + pub fn new(memory_props: vk::PhysicalDeviceMemoryProperties) -> Self { + Self { memory_props } + } + + pub fn allocate( + &self, + device: &ash::Device, + memory_req: vk::MemoryRequirements, + flags: vk::MemoryPropertyFlags, + ) -> vk::DeviceMemory { + let memory_info = vk::MemoryAllocateInfo::builder() + .allocation_size(memory_req.size) + .memory_type_index( + self.find_memorytype_index(memory_req, flags) + .expect("Failed to find Memory Index"), + ) + .build(); + + unsafe { device.allocate_memory(&memory_info, None) }.unwrap() + } + + fn find_memorytype_index( + &self, + memory_req: vk::MemoryRequirements, + flags: vk::MemoryPropertyFlags, + ) -> Option { + self.memory_props.memory_types[..self.memory_props.memory_type_count as _] + .iter() + .enumerate() + .find(|(index, memory_type)| { + (1 << index) & memory_req.memory_type_bits != 0 + && memory_type.property_flags & flags == flags + }) + .map(|(index, _memory_type)| index as _) + } +} diff --git a/crates/vent-rendering/src/buffer.rs b/crates/vent-rendering/src/buffer.rs new file mode 100644 index 0000000..377f707 --- /dev/null +++ b/crates/vent-rendering/src/buffer.rs @@ -0,0 +1,78 @@ +use std::ptr::copy_nonoverlapping; + +use ash::vk; + +use crate::allocator::MemoryAllocator; + +pub struct VulkanBuffer { + buffer: vk::Buffer, + buffer_memory: vk::DeviceMemory, +} + +impl VulkanBuffer { + // Size = (size_of::() * SIZE) + pub fn new( + device: &ash::Device, + allocator: &MemoryAllocator, + size: vk::DeviceSize, + usage: vk::BufferUsageFlags, + ) -> Self { + let buffer_info = vk::BufferCreateInfo::builder() + .size(size) + .usage(usage) + .sharing_mode(vk::SharingMode::EXCLUSIVE) + .build(); + + let buffer = unsafe { device.create_buffer(&buffer_info, None) }.unwrap(); + + let requirements = unsafe { device.get_buffer_memory_requirements(buffer) }; + + let buffer_memory = allocator.allocate( + device, + requirements, + vk::MemoryPropertyFlags::HOST_COHERENT | vk::MemoryPropertyFlags::HOST_VISIBLE, + ); + + Self { + buffer, + buffer_memory, + } + } + + pub fn new_init( + device: &ash::Device, + allocator: &MemoryAllocator, + size: vk::DeviceSize, + usage: vk::BufferUsageFlags, + data: &[u8], + ) -> Self { + let buffer = Self::new(device, allocator, size, usage); + buffer.upload_data(device, data, size); + buffer + } + + pub fn upload_data(&self, device: &ash::Device, data: &[u8], size: vk::DeviceSize) { + unsafe { + let memory = device + .map_memory(self.buffer_memory, 0, size, vk::MemoryMapFlags::empty()) + .unwrap(); + copy_nonoverlapping(data.as_ptr(), memory.cast(), data.len()); + device.unmap_memory(self.buffer_memory); + } + } + + pub fn destroy(self, device: &ash::Device) { + unsafe { + device.destroy_buffer(self.buffer, None); + device.free_memory(self.buffer_memory, None); + } + } +} + +impl ::std::ops::Deref for VulkanBuffer { + type Target = vk::Buffer; + + fn deref(&self) -> &Self::Target { + &self.buffer + } +} diff --git a/crates/vent-rendering/src/image.rs b/crates/vent-rendering/src/image.rs new file mode 100644 index 0000000..56a431c --- /dev/null +++ b/crates/vent-rendering/src/image.rs @@ -0,0 +1,156 @@ +use ash::vk::{self, Extent2D}; + +pub struct VulkanImage { + pub image: vk::Image, + pub image_view: vk::ImageView, + pub sampler: vk::Sampler, +} + +impl VulkanImage { + pub fn new( + device: &ash::Device, + format: vk::Format, + sampler_info: vk::SamplerCreateInfo, + size: Extent2D, + usage: vk::ImageUsageFlags, + ) -> Self { + let image = Self::create_image(device, format, size, usage); + let image_view = + Self::create_image_view(image, device, format, vk::ImageAspectFlags::COLOR); + + let sampler = unsafe { device.create_sampler(&sampler_info, None) }.unwrap(); + + Self { + image, + image_view, + sampler, + } + } + + pub fn new_depth(device: &ash::Device, format: vk::Format, size: Extent2D) -> Self { + let image = Self::create_image( + device, + format, + size, + vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT, + ); + let image_view = + Self::create_image_view(image, device, format, vk::ImageAspectFlags::DEPTH); + + let sampler = Self::create_sampler(device); + + Self { + image, + image_view, + sampler, + } + } + + pub fn new_from_color(device: &ash::Device, color: [u8; 4], size: Extent2D) {} + + fn copy_buffer_to_image( + device: &ash::Device, + buffer: vk::Buffer, + image: vk::Image, + width: u32, + height: u32, + ) { + let command_buffer = begin_single_time_commands(device)?; + + let subresource = vk::ImageSubresourceLayers::builder() + .aspect_mask(vk::ImageAspectFlags::COLOR) + .mip_level(0) + .base_array_layer(0) + .layer_count(1); + + let region = vk::BufferImageCopy::builder() + .buffer_offset(0) + .buffer_row_length(0) + .buffer_image_height(0) + .image_subresource(subresource) + .image_offset(vk::Offset3D { x: 0, y: 0, z: 0 }) + .image_extent(vk::Extent3D { + width, + height, + depth: 1, + }); + + device.cmd_copy_buffer_to_image( + command_buffer, + buffer, + image, + vk::ImageLayout::TRANSFER_DST_OPTIMAL, + &[region], + ); + + end_single_time_commands(device, command_buffer)?; + } + + fn create_sampler(device: &ash::Device) -> vk::Sampler { + let create_info = vk::SamplerCreateInfo::builder() + .mag_filter(vk::Filter::LINEAR) + .min_filter(vk::Filter::LINEAR) + .address_mode_u(vk::SamplerAddressMode::REPEAT) + .address_mode_v(vk::SamplerAddressMode::REPEAT) + .address_mode_w(vk::SamplerAddressMode::REPEAT) + .anisotropy_enable(true) + .max_anisotropy(1.0) + .border_color(vk::BorderColor::INT_OPAQUE_BLACK) + .unnormalized_coordinates(false) + .compare_enable(false) + .compare_op(vk::CompareOp::ALWAYS) + .mipmap_mode(vk::SamplerMipmapMode::LINEAR) + .build(); + unsafe { device.create_sampler(&create_info, None) }.unwrap() + } + + fn create_image_view( + image: vk::Image, + device: &ash::Device, + format: vk::Format, + mask: vk::ImageAspectFlags, + ) -> vk::ImageView { + let depth_image_view_info = vk::ImageViewCreateInfo::builder() + .subresource_range( + vk::ImageSubresourceRange::builder() + .aspect_mask(mask) + .level_count(1) + .layer_count(1) + .build(), + ) + .image(image) + .format(format) + .view_type(vk::ImageViewType::TYPE_2D) + .build(); + + unsafe { device.create_image_view(&depth_image_view_info, None) }.unwrap() + } + + fn create_image( + device: &ash::Device, + format: vk::Format, + size: Extent2D, + usage: vk::ImageUsageFlags, + ) -> vk::Image { + let create_info = vk::ImageCreateInfo::builder() + .image_type(vk::ImageType::TYPE_2D) + .format(format) + .extent(size.into()) + .mip_levels(1) + .array_layers(1) + .samples(vk::SampleCountFlags::TYPE_1) + .tiling(vk::ImageTiling::OPTIMAL) + .usage(usage) + .sharing_mode(vk::SharingMode::EXCLUSIVE) + .build(); + unsafe { device.create_image(&create_info, None) }.unwrap() + } + + pub fn destroy(&self, device: &ash::Device) { + unsafe { + device.destroy_image_view(self.image_view, None); + device.destroy_image(self.image, None); + device.destroy_sampler(self.sampler, None); + } + } +} diff --git a/crates/vent-rendering/src/instance.rs b/crates/vent-rendering/src/instance.rs new file mode 100644 index 0000000..d360882 --- /dev/null +++ b/crates/vent-rendering/src/instance.rs @@ -0,0 +1,768 @@ +use ash::extensions::khr::{Surface, Swapchain}; +use ash::vk::{Extent2D, SwapchainKHR}; +use ash::{extensions::ext::DebugUtils, vk, Entry}; +use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; +use std::borrow::Cow; +use std::{default::Default, ffi::CStr}; + +#[cfg(any(target_os = "macos", target_os = "ios"))] +use ash::vk::{ + KhrGetPhysicalDeviceProperties2Fn, KhrPortabilityEnumerationFn, KhrPortabilitySubsetFn, +}; + +use crate::allocator::MemoryAllocator; +use crate::image::VulkanImage; + +const VALIDATION_ENABLED: bool = cfg!(debug_assertions); + +const MAX_FRAMES_IN_FLIGHT: u8 = 2; + +#[cfg(debug_assertions)] +// const VALIDATION_LAYER: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"VK_LAYER_KHRONOS_validation\n") }; +#[cfg(debug_assertions)] +unsafe extern "system" fn vulkan_debug_callback( + message_severity: vk::DebugUtilsMessageSeverityFlagsEXT, + message_type: vk::DebugUtilsMessageTypeFlagsEXT, + p_callback_data: *const vk::DebugUtilsMessengerCallbackDataEXT, + _user_data: *mut std::os::raw::c_void, +) -> vk::Bool32 { + let callback_data = *p_callback_data; + let message_id_number = callback_data.message_id_number; + + let message_id_name = if callback_data.p_message_id_name.is_null() { + Cow::from("") + } else { + CStr::from_ptr(callback_data.p_message_id_name).to_string_lossy() + }; + + let message = if callback_data.p_message.is_null() { + Cow::from("") + } else { + CStr::from_ptr(callback_data.p_message).to_string_lossy() + }; + + println!( + "{message_severity:?}:\n{message_type:?} [{message_id_name} ({message_id_number})] : {message}\n", + ); + + vk::FALSE +} + +pub struct Instance { + pub memory_allocator: MemoryAllocator, + + pub instance: ash::Instance, + pub device: ash::Device, + + pub surface_loader: Surface, + pub surface: vk::SurfaceKHR, + + pub swapchain_loader: Swapchain, + pub swapchain: vk::SwapchainKHR, + pub pipeline_layout: vk::PipelineLayout, + + pub swapchain_images: Vec, + pub swapchain_image_views: Vec, + pub frame_buffers: Vec, + pub depth_image: VulkanImage, + pub graphics_queue: vk::Queue, + pub present_queue: vk::Queue, + + pub descriptor_pool: vk::DescriptorPool, + pub descriptor_set_layout: vk::DescriptorSetLayout, + pub descriptor_sets: Vec, + + pub render_pass: vk::RenderPass, + pub command_pool: vk::CommandPool, + pub command_buffers: Vec, + + pub image_available_semaphores: Vec, + pub render_finished_semaphores: Vec, + + pub in_flight_fences: Vec, + pub images_in_flight: Vec, + + frame: usize, + + #[cfg(debug_assertions)] + debug_utils: DebugUtils, + #[cfg(debug_assertions)] + debug_messenger: vk::DebugUtilsMessengerEXT, +} + +impl Instance { + pub fn new(application_name: &str, window: winit::window::Window) -> Self { + let entry = Entry::linked(); + + let app_info = unsafe { + vk::ApplicationInfo::builder() + .application_name(CStr::from_bytes_with_nul_unchecked( + application_name.as_bytes(), + )) + .application_version(0) // TODO + .engine_name(CStr::from_bytes_with_nul_unchecked(b"Vent-Engine\0")) + .engine_version(env!("CARGO_PKG_VERSION").parse().unwrap()) + .api_version(vk::API_VERSION_1_2) + .build() + }; + + let mut extension_names = + ash_window::enumerate_required_extensions(window.raw_display_handle()) + .expect("Unsupported Surface Extension") + .to_vec(); + extension_names.push(DebugUtils::name().as_ptr()); + + #[cfg(any(target_os = "macos", target_os = "ios"))] + { + extension_names.push(KhrPortabilityEnumerationFn::name().as_ptr()); + // Enabling this extension is a requirement when using `VK_KHR_portability_subset` + extension_names.push(KhrGetPhysicalDeviceProperties2Fn::name().as_ptr()); + } + + let create_flags = if cfg!(any(target_os = "macos", target_os = "ios")) { + vk::InstanceCreateFlags::ENUMERATE_PORTABILITY_KHR + } else { + vk::InstanceCreateFlags::default() + }; + + let create_info = vk::InstanceCreateInfo::builder() + .application_info(&app_info) + .enabled_extension_names(&extension_names) + .flags(create_flags) + .build(); + + let instance = unsafe { + entry + .create_instance(&create_info, None) + .expect("Failed Create Vulkan Instance") + }; + #[cfg(debug_assertions)] + let debug_utils_loader = DebugUtils::new(&entry, &instance); + #[cfg(debug_assertions)] + let debug_messenger = Self::create_debug_messenger(&debug_utils_loader); + let surface = unsafe { + ash_window::create_surface( + &entry, + &instance, + window.raw_display_handle(), + window.raw_window_handle(), + None, + ) + } + .unwrap(); + let surface_loader = Surface::new(&entry, &instance); + + let (pdevice, graphics_queue_family_index, present_queue_family_index) = + Self::create_physical_device(&instance, &surface_loader, surface); + let surface_format = + unsafe { surface_loader.get_physical_device_surface_formats(pdevice, surface) } + .unwrap()[0]; + let device = Self::create_device(&instance, pdevice, graphics_queue_family_index); + let graphics_queue = unsafe { device.get_device_queue(graphics_queue_family_index, 0) }; + let present_queue = unsafe { device.get_device_queue(present_queue_family_index, 0) }; + + let swapchain_loader = Swapchain::new(&instance, &device); + + let (swapchain, surface_resolution) = Self::create_swapchain( + &swapchain_loader, + surface_format, + &surface_loader, + pdevice, + surface, + window.inner_size(), + ); + + let (swapchain_image_views, swapchain_images) = + Self::create_image_views(&device, &swapchain_loader, swapchain, surface_format); + let pipeline_layout = Self::create_pipeline_layout(&device); + let render_pass = Self::create_render_pass(&device, surface_format); + + let depth_image = + VulkanImage::new_depth(&device, vk::Format::D16_UNORM, surface_resolution); + let frame_buffers = Self::create_frame_buffers( + &swapchain_image_views, + render_pass, + &device, + depth_image.image_view, + surface_resolution, + ); + let command_pool = Self::create_command_pool(&device, graphics_queue_family_index); + let command_buffers = + Self::allocate_command_buffers(&device, command_pool, frame_buffers.len() as u32); + + let ( + image_available_semaphores, + render_finished_semaphores, + in_flight_fences, + images_in_flight, + ) = Self::create_sync_objects(&device, &swapchain_images); + + let memory_allocator = MemoryAllocator::new(unsafe { + instance.get_physical_device_memory_properties(pdevice) + }); + + let descriptor_pool = Self::create_descriptor_pool(&device); + let descriptor_set_layout = Self::create_descriptor_set_layout(&device); + let descriptor_sets = Self::allocate_descriptor_sets( + &device, + descriptor_pool, + descriptor_set_layout, + &swapchain_images, + ); + + Self { + memory_allocator, + instance, + device, + surface, + surface_loader, + swapchain_loader, + swapchain, + pipeline_layout, + swapchain_images, + swapchain_image_views, + graphics_queue, + present_queue, + render_pass, + debug_utils: debug_utils_loader, + descriptor_pool, + descriptor_set_layout, + descriptor_sets, + debug_messenger, + depth_image, + frame_buffers, + command_pool, + command_buffers, + image_available_semaphores, + render_finished_semaphores, + in_flight_fences, + images_in_flight, + frame: 0, + } + } + + // Returns None if Surface should be resized else returns image index + pub fn next_image(&self) -> Option { + let in_flight_fence = self.in_flight_fences[self.frame]; + + unsafe { + self.device + .wait_for_fences(&[in_flight_fence], true, u64::max_value()) + } + .unwrap(); + unsafe { + let result = match self.swapchain_loader.acquire_next_image( + self.swapchain, + u64::MAX, + self.image_available_semaphores[self.frame], + vk::Fence::null(), + ) { + Ok((index, _)) => { + let image_in_flight = self.images_in_flight[index as usize]; + self.device + .wait_for_fences(&[image_in_flight], true, u64::max_value()) + .unwrap(); + return Some(index); + } + Err(_) => return None, + }; + } + } + + pub fn submit(&self, image_index: u32, in_flight_fence: vk::Fence) { + let wait_semaphores = &[self.image_available_semaphores[self.frame]]; + let wait_stages = &[vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT]; + let command_buffers = &[self.command_buffers[image_index as usize]]; + let signal_semaphores = &[self.render_finished_semaphores[self.frame]]; + let submit_info = vk::SubmitInfo::builder() + .wait_semaphores(wait_semaphores) + .wait_dst_stage_mask(wait_stages) + .command_buffers(command_buffers) + .signal_semaphores(signal_semaphores) + .build(); + + unsafe { + self.device.reset_fences(&[in_flight_fence]).unwrap(); + + self.device + .queue_submit(self.graphics_queue, &[submit_info], in_flight_fence) + .unwrap(); + } + + let swapchains = &[self.swapchain]; + let image_indices = &[image_index]; + let present_info = vk::PresentInfoKHR::builder() + .wait_semaphores(signal_semaphores) + .swapchains(swapchains) + .image_indices(image_indices) + .build(); + + unsafe { + self.swapchain_loader + .queue_present(self.present_queue, &present_info) + } + .unwrap(); + } + + fn get_depth_format(instance: &ash::Instance, pdevice: vk::PhysicalDevice) -> vk::Format { + let candidates = &[ + vk::Format::D32_SFLOAT, + vk::Format::D32_SFLOAT_S8_UINT, + vk::Format::D24_UNORM_S8_UINT, + ]; + + Self::get_supported_format( + instance, + pdevice, + candidates, + vk::ImageTiling::OPTIMAL, + vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT, + ) + .expect("No Depth Format found") + } + + pub fn get_supported_format( + instance: &ash::Instance, + pdevice: vk::PhysicalDevice, + candidates: &[vk::Format], + tiling: vk::ImageTiling, + features: vk::FormatFeatureFlags, + ) -> Option { + candidates.iter().cloned().find(|f| { + let properties = unsafe { instance.get_physical_device_format_properties(pdevice, *f) }; + match tiling { + vk::ImageTiling::LINEAR => properties.linear_tiling_features.contains(features), + vk::ImageTiling::OPTIMAL => properties.optimal_tiling_features.contains(features), + _ => false, + } + }) + } + + fn create_debug_messenger(debug_utils_loader: &DebugUtils) -> vk::DebugUtilsMessengerEXT { + let debug_info = vk::DebugUtilsMessengerCreateInfoEXT::builder() + .message_severity( + vk::DebugUtilsMessageSeverityFlagsEXT::ERROR + | vk::DebugUtilsMessageSeverityFlagsEXT::WARNING + | vk::DebugUtilsMessageSeverityFlagsEXT::INFO, + ) + .message_type( + vk::DebugUtilsMessageTypeFlagsEXT::GENERAL + | vk::DebugUtilsMessageTypeFlagsEXT::DEVICE_ADDRESS_BINDING + | vk::DebugUtilsMessageTypeFlagsEXT::PERFORMANCE, + ) + .pfn_user_callback(Some(vulkan_debug_callback)) + .build(); + + unsafe { debug_utils_loader.create_debug_utils_messenger(&debug_info, None) }.unwrap() + } + + fn create_frame_buffers( + swapchain_image_views: &Vec, + render_pass: vk::RenderPass, + device: &ash::Device, + depth_image_view: vk::ImageView, + surface_resolution: Extent2D, + ) -> Vec { + swapchain_image_views + .iter() + .map(|&present_image_view| { + let framebuffer_attachments = [present_image_view, depth_image_view]; + let frame_buffer_create_info = vk::FramebufferCreateInfo::builder() + .render_pass(render_pass) + .attachments(&framebuffer_attachments) + .width(surface_resolution.width) + .height(surface_resolution.height) + .layers(1) + .build(); + + unsafe { + device + .create_framebuffer(&frame_buffer_create_info, None) + .unwrap() + } + }) + .collect::>() + } + + fn create_physical_device( + instance: &ash::Instance, + surface_loader: &Surface, + surface: vk::SurfaceKHR, + ) -> (vk::PhysicalDevice, u32, u32) { + let pdevices = unsafe { + instance + .enumerate_physical_devices() + .expect("Physical device error") + }; + for pdevice in pdevices { + let properties = + unsafe { instance.get_physical_device_queue_family_properties(pdevice) }; + + let graphics = properties + .iter() + .position(|p| p.queue_flags.contains(vk::QueueFlags::GRAPHICS)) + .map(|i| i as u32); + + let mut present = None; + for (index, properties) in properties.iter().enumerate() { + if unsafe { + surface_loader.get_physical_device_surface_support( + pdevice, + index as u32, + surface, + ) + } + .unwrap() + { + present = Some(index as u32); + break; + } + } + + if let (Some(graphics), Some(present)) = (graphics, present) { + return (pdevice, graphics, present); + } + } + panic!("Missing required queue families") + } + + fn create_device( + instance: &ash::Instance, + pdevice: vk::PhysicalDevice, + queue_family_index: u32, + ) -> ash::Device { + let device_extension_names_raw = [ + Swapchain::name().as_ptr(), + #[cfg(any(target_os = "macos", target_os = "ios"))] + KhrPortabilitySubsetFn::name().as_ptr(), + ]; + let features = vk::PhysicalDeviceFeatures { + shader_clip_distance: 1, + ..Default::default() + }; + let priorities = [1.0]; + + let queue_info = vk::DeviceQueueCreateInfo::builder() + .queue_family_index(queue_family_index) + .queue_priorities(&priorities) + .build(); + + let device_create_info = vk::DeviceCreateInfo::builder() + .queue_create_infos(std::slice::from_ref(&queue_info)) + .enabled_extension_names(&device_extension_names_raw) + .enabled_features(&features) + .build(); + + unsafe { instance.create_device(pdevice, &device_create_info, None) }.unwrap() + } + + fn create_swapchain( + swapchain_loader: &Swapchain, + surface_format: vk::SurfaceFormatKHR, + surface_loader: &Surface, + pdevice: vk::PhysicalDevice, + surface: vk::SurfaceKHR, + size: winit::dpi::PhysicalSize, + ) -> (vk::SwapchainKHR, Extent2D) { + let surface_capabilities = + unsafe { surface_loader.get_physical_device_surface_capabilities(pdevice, surface) } + .unwrap(); + let mut desired_image_count = surface_capabilities.min_image_count + 1; + if surface_capabilities.max_image_count > 0 + && desired_image_count > surface_capabilities.max_image_count + { + desired_image_count = surface_capabilities.max_image_count; + } + let surface_resolution = match surface_capabilities.current_extent.width { + std::u32::MAX => vk::Extent2D { + width: size.width, + height: size.height, + }, + _ => surface_capabilities.current_extent, + }; + let pre_transform = if surface_capabilities + .supported_transforms + .contains(vk::SurfaceTransformFlagsKHR::IDENTITY) + { + vk::SurfaceTransformFlagsKHR::IDENTITY + } else { + surface_capabilities.current_transform + }; + let present_modes = + unsafe { surface_loader.get_physical_device_surface_present_modes(pdevice, surface) } + .unwrap(); + let present_mode = present_modes + .iter() + .cloned() + .find(|&mode| mode == vk::PresentModeKHR::MAILBOX) + .unwrap_or(vk::PresentModeKHR::FIFO); + + let swapchain_create_info = vk::SwapchainCreateInfoKHR::builder() + .surface(surface) + .min_image_count(desired_image_count) + .image_color_space(surface_format.color_space) + .image_format(surface_format.format) + .image_extent(surface_resolution) + .image_usage(vk::ImageUsageFlags::COLOR_ATTACHMENT) + .image_sharing_mode(vk::SharingMode::EXCLUSIVE) + .pre_transform(pre_transform) + .composite_alpha(vk::CompositeAlphaFlagsKHR::OPAQUE) + .present_mode(present_mode) + .clipped(true) + .image_array_layers(1) + .build(); + + ( + unsafe { swapchain_loader.create_swapchain(&swapchain_create_info, None) }.unwrap(), + surface_resolution, + ) + } + + fn create_command_pool(device: &ash::Device, queue_family_index: u32) -> vk::CommandPool { + let create_info = vk::CommandPoolCreateInfo::builder() + .queue_family_index(queue_family_index) + .flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER) + .build(); + unsafe { device.create_command_pool(&create_info, None) }.unwrap() + } + + fn allocate_command_buffers( + device: &ash::Device, + command_pool: vk::CommandPool, + count: u32, + ) -> Vec { + let allocate_info = vk::CommandBufferAllocateInfo::builder() + .command_pool(command_pool) + .level(vk::CommandBufferLevel::PRIMARY) + .command_buffer_count(count) + .build(); + + unsafe { device.allocate_command_buffers(&allocate_info) }.unwrap() + } + + fn create_sync_objects( + device: &ash::Device, + swapchain_images: &Vec, + ) -> ( + Vec, + Vec, + Vec, + Vec, + ) { + let (mut image_available_semaphores, mut render_finished_semaphores, mut in_flight_fences) = + (Vec::new(), Vec::new(), Vec::new()); + + let create_info = vk::SemaphoreCreateInfo::default(); + + let fence_info = vk::FenceCreateInfo::builder() + .flags(vk::FenceCreateFlags::SIGNALED) + .build(); + + for _ in 0..MAX_FRAMES_IN_FLIGHT { + image_available_semaphores + .push(unsafe { device.create_semaphore(&create_info, None) }.unwrap()); + render_finished_semaphores + .push(unsafe { device.create_semaphore(&create_info, None) }.unwrap()); + + in_flight_fences.push(unsafe { device.create_fence(&fence_info, None) }.unwrap()); + } + + let images_in_flight = swapchain_images.iter().map(|_| vk::Fence::null()).collect(); + + ( + image_available_semaphores, + render_finished_semaphores, + in_flight_fences, + images_in_flight, + ) + } + + fn create_image_views( + device: &ash::Device, + swapchain_loader: &Swapchain, + swapchain: SwapchainKHR, + surface_format: vk::SurfaceFormatKHR, + ) -> (Vec, Vec) { + let images = unsafe { swapchain_loader.get_swapchain_images(swapchain) }.unwrap(); + ( + images + .iter() + .map(|&image| { + let create_view_info = vk::ImageViewCreateInfo::builder() + .view_type(vk::ImageViewType::TYPE_2D) + .format(surface_format.format) + .components(vk::ComponentMapping { + r: vk::ComponentSwizzle::R, + g: vk::ComponentSwizzle::G, + b: vk::ComponentSwizzle::B, + a: vk::ComponentSwizzle::A, + }) + .subresource_range(vk::ImageSubresourceRange { + aspect_mask: vk::ImageAspectFlags::COLOR, + base_mip_level: 0, + level_count: 1, + base_array_layer: 0, + layer_count: 1, + }) + .image(image) + .build(); + unsafe { device.create_image_view(&create_view_info, None) }.unwrap() + }) + .collect::>(), + images, + ) + } + + fn create_descriptor_pool(device: &ash::Device) -> vk::DescriptorPool { + let pool_sizes = [vk::DescriptorPoolSize::builder() + .ty(vk::DescriptorType::UNIFORM_BUFFER) + .descriptor_count(1000) + .build()]; + + let create_info = vk::DescriptorPoolCreateInfo::builder() + .pool_sizes(&pool_sizes) + .build(); + + unsafe { device.create_descriptor_pool(&create_info, None) }.unwrap() + } + + fn allocate_descriptor_sets( + device: &ash::Device, + descriptor_pool: vk::DescriptorPool, + descriptor_set_layout: vk::DescriptorSetLayout, + swapchain_images: &Vec, + ) -> Vec { + let layouts = vec![descriptor_set_layout; swapchain_images.len()]; + let info = vk::DescriptorSetAllocateInfo::builder() + .descriptor_pool(descriptor_pool) + .set_layouts(&layouts) + .build(); + + unsafe { device.allocate_descriptor_sets(&info) }.unwrap() + } + + fn create_descriptor_set_layout(device: &ash::Device) -> vk::DescriptorSetLayout { + let ubo_binding = vk::DescriptorSetLayoutBinding::builder() + .binding(0) + .descriptor_type(vk::DescriptorType::UNIFORM_BUFFER) + .descriptor_count(1) + .stage_flags(vk::ShaderStageFlags::VERTEX) + .build(); + + let sampler_binding = vk::DescriptorSetLayoutBinding::builder() + .binding(1) + .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) + .descriptor_count(1) + .stage_flags(vk::ShaderStageFlags::FRAGMENT) + .build(); + + let bindings = &[ubo_binding, sampler_binding]; + let info = vk::DescriptorSetLayoutCreateInfo::builder() + .bindings(bindings) + .build(); + + unsafe { device.create_descriptor_set_layout(&info, None) }.unwrap() + } + + fn create_pipeline_layout(device: &ash::Device) -> vk::PipelineLayout { + let create_info = vk::PipelineLayoutCreateInfo::default(); + + unsafe { device.create_pipeline_layout(&create_info, None) }.unwrap() + } + + fn create_render_pass( + device: &ash::Device, + surface_format: vk::SurfaceFormatKHR, + ) -> vk::RenderPass { + let renderpass_attachments = [ + vk::AttachmentDescription { + format: surface_format.format, + samples: vk::SampleCountFlags::TYPE_1, + load_op: vk::AttachmentLoadOp::CLEAR, + store_op: vk::AttachmentStoreOp::STORE, + final_layout: vk::ImageLayout::PRESENT_SRC_KHR, + ..Default::default() + }, + vk::AttachmentDescription { + format: vk::Format::D16_UNORM, + samples: vk::SampleCountFlags::TYPE_1, + load_op: vk::AttachmentLoadOp::CLEAR, + initial_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + final_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + ..Default::default() + }, + ]; + let color_attachment_refs = [vk::AttachmentReference { + attachment: 0, + layout: vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL, + }]; + let depth_attachment_ref = vk::AttachmentReference { + attachment: 1, + layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + }; + let dependencies = [vk::SubpassDependency { + src_subpass: vk::SUBPASS_EXTERNAL, + src_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT, + dst_access_mask: vk::AccessFlags::COLOR_ATTACHMENT_READ + | vk::AccessFlags::COLOR_ATTACHMENT_WRITE, + dst_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT, + ..Default::default() + }]; + + let subpass = vk::SubpassDescription::builder() + .color_attachments(&color_attachment_refs) + .depth_stencil_attachment(&depth_attachment_ref) + .pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS) + .build(); + + let create_info = vk::RenderPassCreateInfo::builder() + .attachments(&renderpass_attachments) + .subpasses(std::slice::from_ref(&subpass)) + .dependencies(&dependencies) + .build(); + + unsafe { device.create_render_pass(&create_info, None) }.unwrap() + } +} + +impl Drop for Instance { + fn drop(&mut self) { + unsafe { + self.device.device_wait_idle().unwrap(); + self.in_flight_fences + .iter() + .for_each(|f| self.device.destroy_fence(*f, None)); + self.render_finished_semaphores + .iter() + .for_each(|s| self.device.destroy_semaphore(*s, None)); + self.image_available_semaphores + .iter() + .for_each(|s| self.device.destroy_semaphore(*s, None)); + + self.device.destroy_render_pass(self.render_pass, None); + + self.swapchain_image_views + .iter() + .for_each(|v| self.device.destroy_image_view(*v, None)); + + self.frame_buffers + .iter() + .for_each(|f| self.device.destroy_framebuffer(*f, None)); + self.depth_image.destroy(&self.device); + + self.device + .free_command_buffers(self.command_pool, &self.command_buffers); + self.device.destroy_command_pool(self.command_pool, None); + + // DEVICE DESTRUCTION + self.device.destroy_device(None); + + self.surface_loader.destroy_surface(self.surface, None); + self.swapchain_loader + .destroy_swapchain(self.swapchain, None); + self.debug_utils + .destroy_debug_utils_messenger(self.debug_messenger, None); + self.instance.destroy_instance(None) + } + } +} diff --git a/crates/vent-rendering/src/lib.rs b/crates/vent-rendering/src/lib.rs new file mode 100644 index 0000000..5ea7354 --- /dev/null +++ b/crates/vent-rendering/src/lib.rs @@ -0,0 +1,54 @@ +use std::mem; + +use ash::vk; +use bytemuck::offset_of; + +pub mod allocator; +pub mod buffer; +pub mod image; +pub mod instance; +pub mod pipeline; + +pub trait Vertex<'a> { + const BINDING_DESCRIPTION: vk::VertexInputBindingDescription; + fn create_input_descriptions() -> [vk::VertexInputAttributeDescription; 3]; +} + +#[repr(C)] +#[derive(Default, Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)] +pub struct Vertex3D { + pub position: [f32; 3], + pub tex_coord: [f32; 2], + pub normal: [f32; 3], +} + +impl<'a> Vertex<'a> for Vertex3D { + const BINDING_DESCRIPTION: vk::VertexInputBindingDescription = + vk::VertexInputBindingDescription { + binding: 0, + stride: mem::size_of::() as u32, + input_rate: vk::VertexInputRate::VERTEX, + }; + fn create_input_descriptions() -> [vk::VertexInputAttributeDescription; 3] { + [ + vk::VertexInputAttributeDescription { + location: 0, + binding: 0, + format: vk::Format::R32G32B32A32_SFLOAT, + offset: offset_of!(Self, position) as u32, + }, + vk::VertexInputAttributeDescription { + location: 1, + binding: 0, + format: vk::Format::R32G32B32A32_SFLOAT, + offset: offset_of!(Self, tex_coord) as u32, + }, + vk::VertexInputAttributeDescription { + location: 2, + binding: 0, + format: vk::Format::R32G32B32A32_SFLOAT, + offset: offset_of!(Self, normal) as u32, + }, + ] + } +} diff --git a/crates/vent-rendering/src/pipeline.rs b/crates/vent-rendering/src/pipeline.rs new file mode 100644 index 0000000..ddc2f5f --- /dev/null +++ b/crates/vent-rendering/src/pipeline.rs @@ -0,0 +1,148 @@ +use std::{ffi::CStr, fs::File}; + +use ash::{util::read_spv, vk}; + +use crate::{instance::Instance, Vertex, Vertex3D}; + +pub fn create_pipeline( + instance: Instance, + vertex_file: String, + fragment_file: String, + surface_resolution: vk::Extent2D, +) -> vk::Pipeline { + let vertex_code = read_spv(&mut File::open(vertex_file).unwrap()).unwrap(); + let vertex_module_info = vk::ShaderModuleCreateInfo::builder() + .code(&vertex_code) + .build(); + let fragment_code = read_spv(&mut File::open(fragment_file).unwrap()).unwrap(); + let fragment_module_info = vk::ShaderModuleCreateInfo::builder() + .code(&fragment_code) + .build(); + + let vertex_module = unsafe { + instance + .device + .create_shader_module(&vertex_module_info, None) + } + .unwrap(); + let fragment_module = unsafe { + instance + .device + .create_shader_module(&fragment_module_info, None) + } + .unwrap(); + + let shader_entry_name = unsafe { CStr::from_bytes_with_nul_unchecked(b"main\0") }; + let shader_stage_create_info = [ + vk::PipelineShaderStageCreateInfo { + module: vertex_module, + p_name: shader_entry_name.as_ptr(), + stage: vk::ShaderStageFlags::VERTEX, + ..Default::default() + }, + vk::PipelineShaderStageCreateInfo { + module: fragment_module, + p_name: shader_entry_name.as_ptr(), + stage: vk::ShaderStageFlags::FRAGMENT, + ..Default::default() + }, + ]; + + let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::builder() + .vertex_attribute_descriptions(&Vertex3D::create_input_descriptions()) + .vertex_binding_descriptions(&[Vertex3D::BINDING_DESCRIPTION]) + .build(); + let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo { + topology: vk::PrimitiveTopology::TRIANGLE_LIST, + ..Default::default() + }; + let viewports = [vk::Viewport { + x: 0.0, + y: 0.0, + width: surface_resolution.width as f32, + height: surface_resolution.height as f32, + min_depth: 0.0, + max_depth: 1.0, + }]; + let scissors = [surface_resolution.into()]; + let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder() + .scissors(&scissors) + .viewports(&viewports) + .build(); + + let rasterization_info = vk::PipelineRasterizationStateCreateInfo { + front_face: vk::FrontFace::COUNTER_CLOCKWISE, + line_width: 1.0, + polygon_mode: vk::PolygonMode::FILL, + ..Default::default() + }; + let multisample_state_info = vk::PipelineMultisampleStateCreateInfo { + rasterization_samples: vk::SampleCountFlags::TYPE_1, + ..Default::default() + }; + let noop_stencil_state = vk::StencilOpState { + fail_op: vk::StencilOp::KEEP, + pass_op: vk::StencilOp::KEEP, + depth_fail_op: vk::StencilOp::KEEP, + compare_op: vk::CompareOp::ALWAYS, + ..Default::default() + }; + let depth_state_info = vk::PipelineDepthStencilStateCreateInfo { + depth_test_enable: 1, + depth_write_enable: 1, + depth_compare_op: vk::CompareOp::LESS_OR_EQUAL, + front: noop_stencil_state, + back: noop_stencil_state, + max_depth_bounds: 1.0, + ..Default::default() + }; + let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState { + blend_enable: 0, + src_color_blend_factor: vk::BlendFactor::SRC_COLOR, + dst_color_blend_factor: vk::BlendFactor::ONE_MINUS_DST_COLOR, + color_blend_op: vk::BlendOp::ADD, + src_alpha_blend_factor: vk::BlendFactor::ZERO, + dst_alpha_blend_factor: vk::BlendFactor::ZERO, + alpha_blend_op: vk::BlendOp::ADD, + color_write_mask: vk::ColorComponentFlags::RGBA, + }]; + let color_blend_state = vk::PipelineColorBlendStateCreateInfo::builder() + .logic_op(vk::LogicOp::CLEAR) + .attachments(&color_blend_attachment_states) + .build(); + + let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; + let dynamic_state_info = vk::PipelineDynamicStateCreateInfo::builder() + .dynamic_states(&dynamic_state) + .build(); + + let graphic_pipeline_info = vk::GraphicsPipelineCreateInfo::builder() + .stages(&shader_stage_create_info) + .vertex_input_state(&vertex_input_state_info) + .input_assembly_state(&vertex_input_assembly_state_info) + .viewport_state(&viewport_state_info) + .rasterization_state(&rasterization_info) + .multisample_state(&multisample_state_info) + .depth_stencil_state(&depth_state_info) + .color_blend_state(&color_blend_state) + .dynamic_state(&dynamic_state_info) + .layout(instance.pipeline_layout) + .render_pass(instance.render_pass) + .build(); + + let graphics_pipelines = unsafe { + instance.device.create_graphics_pipelines( + vk::PipelineCache::null(), + &[graphic_pipeline_info], + None, + ) + } + .expect("Unable to create graphics pipeline"); + + unsafe { + instance.device.destroy_shader_module(vertex_module, None); + instance.device.destroy_shader_module(fragment_module, None); + } + + graphics_pipelines[0] +} diff --git a/crates/vent-runtime/Cargo.toml b/crates/vent-runtime/Cargo.toml index 373e2fa..61d1db3 100644 --- a/crates/vent-runtime/Cargo.toml +++ b/crates/vent-runtime/Cargo.toml @@ -7,11 +7,12 @@ edition = "2021" [dependencies] vent-common = { path = "../vent-common"} +vent-rendering = { path = "../vent-rendering"} vent-assets = { path = "../vent-assets" } vent-ecs = { path = "../vent-ecs"} winit = "0.28.6" -wgpu = "0.16.2" +# wgpu = "0.16.2" pollster = "0.3.0" log = "0.4" @@ -20,9 +21,9 @@ bytemuck = { version = "1.14.0", features = ["derive"] } downcast-rs = "1.2.0" # egui -egui = "0.22.0" -egui-wgpu = "0.22.0" -egui-winit = "0.22.0" +# egui = "0.22.0" +# egui-wgpu = "0.22.0" +# egui-winit = "0.22.0" [target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies] simple_logger = "4.2.0" diff --git a/crates/vent-runtime/src/render/d2/mod.rs b/crates/vent-runtime/src/render/d2/mod.rs index efe3d5d..d44ab0e 100644 --- a/crates/vent-runtime/src/render/d2/mod.rs +++ b/crates/vent-runtime/src/render/d2/mod.rs @@ -7,17 +7,7 @@ pub struct UBO2D {} pub struct Renderer2D {} impl Renderer for Renderer2D { - fn init( - _config: &wgpu::SurfaceConfiguration, - _device: &wgpu::Device, - _queue: &wgpu::Queue, - _camera: &mut dyn Camera, - ) -> Self - where - Self: Sized, - { - Self {} - } + fn init(instance: Instance, camera: &mut dyn Camera) -> Self; fn resize( &mut self, diff --git a/crates/vent-runtime/src/render/d3/mod.rs b/crates/vent-runtime/src/render/d3/mod.rs index 6e10776..0e1fcee 100644 --- a/crates/vent-runtime/src/render/d3/mod.rs +++ b/crates/vent-runtime/src/render/d3/mod.rs @@ -3,6 +3,7 @@ use std::mem; use glam::Mat4; use vent_assets::{Mesh3D, Vertex, Vertex3D}; use vent_ecs::world::World; +use vent_rendering::instance::Instance; use wgpu::util::DeviceExt; use self::light_renderer::LightRenderer; @@ -50,12 +51,7 @@ pub struct Renderer3D { } impl Renderer for Renderer3D { - fn init( - config: &wgpu::SurfaceConfiguration, - device: &wgpu::Device, - queue: &wgpu::Queue, - camera: &mut dyn Camera, - ) -> Self + fn init(instance: Instance, camera: &mut dyn Camera) -> Self where Self: Sized, { diff --git a/crates/vent-runtime/src/render/mod.rs b/crates/vent-runtime/src/render/mod.rs index 067cc6c..bdf0143 100644 --- a/crates/vent-runtime/src/render/mod.rs +++ b/crates/vent-runtime/src/render/mod.rs @@ -2,6 +2,7 @@ use std::time::{Duration, Instant}; use vent_common::render::WGPURenderer; +use vent_rendering::instance::Instance; use winit::dpi::PhysicalSize; use winit::window::Window; @@ -21,7 +22,7 @@ mod d2; mod d3; pub(crate) struct DefaultRuntimeRenderer { - wgpu_renderer: WGPURenderer, + instance: Instance, runtime_renderer: RawRuntimeRenderer, } @@ -32,19 +33,10 @@ impl DefaultRuntimeRenderer { event_loop: &winit::event_loop::EventLoopWindowTarget<()>, camera: &mut dyn Camera, ) -> Self { - let wgpu_renderer = WGPURenderer::new(window); - let runtime_renderer = RawRuntimeRenderer::new( - dimension, - &wgpu_renderer.device, - &wgpu_renderer.queue, - &wgpu_renderer.config, - wgpu_renderer.caps.formats[0], - &wgpu_renderer.adapter, - event_loop, - camera, - ); + let instance = Instance::new("TODO", window); + let runtime_renderer = RawRuntimeRenderer::new(dimension, instance, event_loop, camera); Self { - wgpu_renderer, + instance, runtime_renderer, } } @@ -65,13 +57,9 @@ impl DefaultRuntimeRenderer { ..Default::default() }); - let detla = self.runtime_renderer.render( - &view, - &self.wgpu_renderer.device, - &self.wgpu_renderer.queue, - window, - camera, - ); + let detla = self + .runtime_renderer + .render(&view, self.instance, window, camera); output.present(); @@ -135,17 +123,13 @@ pub struct RawRuntimeRenderer { impl RawRuntimeRenderer { pub fn new( dimension: Dimension, - device: &wgpu::Device, - queue: &wgpu::Queue, - config: &wgpu::SurfaceConfiguration, - surface_format: wgpu::TextureFormat, - adapter: &wgpu::Adapter, + instance: Instance, event_loop: &winit::event_loop::EventLoopWindowTarget<()>, camera: &mut dyn Camera, ) -> Self { let multi_renderer: Box = match dimension { - Dimension::D2 => Box::new(Renderer2D::init(config, device, queue, camera)), - Dimension::D3 => Box::new(Renderer3D::init(config, device, queue, camera)), + Dimension::D2 => Box::new(Renderer2D::init(instance, camera)), + Dimension::D3 => Box::new(Renderer3D::init(instance, camera)), }; let egui = EguiRenderer::new(event_loop, device, surface_format) // TODO @@ -161,14 +145,7 @@ impl RawRuntimeRenderer { } } - pub fn render( - &mut self, - surface_view: &wgpu::TextureView, - device: &wgpu::Device, - queue: &wgpu::Queue, - window: &Window, - camera: &mut dyn Camera, - ) -> f32 { + pub fn render(&mut self, instance: Instance, window: &Window, camera: &mut dyn Camera) -> f32 { let frame_start = Instant::now(); let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { From da5f9b1c5d1f6f20243e3281ddeb97a0cc91951a Mon Sep 17 00:00:00 2001 From: Snowiiii <71594357+Snowiiii@users.noreply.github.com> Date: Sun, 15 Oct 2023 22:49:09 +0200 Subject: [PATCH 02/14] Added Vulkan Image --- Cargo.lock | 260 ++++++++++++----------- crates/vent-assets/src/model/gltf.rs | 158 ++++++-------- crates/vent-assets/src/model/mod.rs | 17 +- crates/vent-assets/src/model/obj.rs | 117 ++++++---- crates/vent-ecs/src/archetype.rs | 5 +- crates/vent-rendering/src/buffer.rs | 4 +- crates/vent-rendering/src/image.rs | 116 +++++++--- crates/vent-rendering/src/instance.rs | 16 +- crates/vent-rendering/src/lib.rs | 58 +++++ crates/vent-rendering/src/pipeline.rs | 4 +- crates/vent-runtime/src/render/d3/mod.rs | 4 +- crates/vent-runtime/src/render/mod.rs | 15 +- 12 files changed, 462 insertions(+), 312 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5bb9f8e..99983b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "ab_glyph" -version = "0.2.21" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5110f1c78cf582855d895ecd0746b653db010cec6d9f5575293f27934d980a39" +checksum = "b1061f3ff92c2f65800df1f12fc7b4ff44ee14783104187dd04dfee6f11b0fd2" dependencies = [ "ab_glyph_rasterizer", "owned_ttf_parser", @@ -143,7 +143,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c48ccdbf6ca6b121e0f586cbc0e73ae440e56c67c30fa0873b4e110d9c26d2b" dependencies = [ - "event-listener", + "event-listener 2.5.3", "futures-core", ] @@ -154,20 +154,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" dependencies = [ "concurrent-queue", - "event-listener", + "event-listener 2.5.3", "futures-core", ] [[package]] name = "async-executor" -version = "1.5.1" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fa3dc5f2a8564f07759c008b9109dc0d39de92a88d5588b8a5036d286383afb" +checksum = "2c1da3ae8dabd9c00f453a329dfe1fb28da3c0a72e2478cdcd93171740c20499" dependencies = [ "async-lock", "async-task", "concurrent-queue", - "fastrand 1.9.0", + "fastrand 2.0.1", "futures-lite", "slab", ] @@ -213,7 +213,7 @@ dependencies = [ "log", "parking", "polling", - "rustix 0.37.23", + "rustix 0.37.24", "slab", "socket2", "waker-fn", @@ -225,24 +225,23 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" dependencies = [ - "event-listener", + "event-listener 2.5.3", ] [[package]] name = "async-process" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a9d28b1d97e08915212e2e45310d47854eafa69600756fc735fb788f75199c9" +checksum = "ea6438ba0a08d81529c69b36700fa2f95837bfe3e776ab39cde9c14d9149da88" dependencies = [ "async-io", "async-lock", - "autocfg", + "async-signal", "blocking", "cfg-if", - "event-listener", + "event-listener 3.0.0", "futures-lite", - "rustix 0.37.23", - "signal-hook", + "rustix 0.38.18", "windows-sys 0.48.0", ] @@ -254,7 +253,25 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", +] + +[[package]] +name = "async-signal" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1079d27511f6c038736279421774ef4ad4bdd2e300825f4a48c4cc463a57cedf" +dependencies = [ + "async-io", + "async-lock", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix 0.38.18", + "signal-hook-registry", + "slab", + "windows-sys 0.48.0", ] [[package]] @@ -285,9 +302,9 @@ dependencies = [ [[package]] name = "async-task" -version = "4.4.0" +version = "4.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" +checksum = "b9441c6b2fe128a7c2bf680a44c34d0df31ce09e5b7e401fcca3faa483dbc921" [[package]] name = "async-trait" @@ -297,14 +314,14 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] name = "atomic-waker" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" @@ -372,17 +389,18 @@ dependencies = [ [[package]] name = "blocking" -version = "1.3.1" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77231a1c8f801696fc0123ec6150ce92cffb8e164a02afb9c8ddee0e9b65ad65" +checksum = "8c36a4d0d48574b3dd360b4b7d95cc651d2b6557b6402848a27d4b228a473e2a" dependencies = [ "async-channel", "async-lock", "async-task", - "atomic-waker", - "fastrand 1.9.0", + "fastrand 2.0.1", + "futures-io", "futures-lite", - "log", + "piper", + "tracing", ] [[package]] @@ -408,14 +426,14 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "calloop" @@ -485,15 +503,14 @@ dependencies = [ [[package]] name = "cocoa-foundation" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "931d3837c286f56e3c58423ce4eba12d08db2374461a785c86f672b08b5650d6" +checksum = "8c6234cbb2e4c785b456c0644748b1ac416dd045799740356f8363dfe00c93f7" dependencies = [ "bitflags 1.3.2", "block", "core-foundation", "core-graphics-types", - "foreign-types", "libc", "objc", ] @@ -517,9 +534,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" +checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" dependencies = [ "crossbeam-utils", ] @@ -723,7 +740,7 @@ checksum = "f95e2801cd355d4a1a3e3953ce6ee5ae9603a5c833455343a8bfe3f44d418246" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -734,30 +751,30 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.3" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" +checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" dependencies = [ - "errno-dragonfly", "libc", "windows-sys 0.48.0", ] [[package]] -name = "errno-dragonfly" -version = "0.1.2" +name = "event-listener" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "event-listener" -version = "2.5.3" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +checksum = "29e56284f00d94c1bc7fd3c77027b4623c88c1f53d8d2394c6199f2921dea325" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] [[package]] name = "exr" @@ -786,9 +803,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "fdeflate" @@ -892,7 +909,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -957,9 +974,9 @@ dependencies = [ [[package]] name = "glam" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42218cb640844e3872cc3c153dc975229e080a6c4733b34709ef445610550226" +checksum = "b5418c17512bdf42730f9032c74e1ae39afc408745ebb2acf72fbc4691c17945" [[package]] name = "gloo-timers" @@ -996,7 +1013,7 @@ dependencies = [ "inflections", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1022,9 +1039,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" [[package]] name = "hermit-abi" @@ -1092,9 +1109,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ "equivalent", "hashbrown", @@ -1136,7 +1153,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi", - "rustix 0.38.14", + "rustix 0.38.18", "windows-sys 0.48.0", ] @@ -1202,15 +1219,15 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.148" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libloading" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d580318f95776505201b28cf98eb1fa5e4be3b689633ba6a3e6cd880ff22d8cb" +checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" dependencies = [ "cfg-if", "windows-sys 0.48.0", @@ -1224,9 +1241,9 @@ checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" -version = "0.4.7" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" +checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" [[package]] name = "lock_api" @@ -1258,9 +1275,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.3" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "memmap2" @@ -1434,9 +1451,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] @@ -1480,7 +1497,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1583,9 +1600,9 @@ dependencies = [ [[package]] name = "parking" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" +checksum = "e52c774a4c39359c1d1c52e43f73dd91a75a614652c825408eec30c95a9b2067" [[package]] name = "percent-encoding" @@ -1605,6 +1622,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "piper" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" +dependencies = [ + "atomic-waker", + "fastrand 2.0.1", + "futures-io", +] + [[package]] name = "pkg-config" version = "0.3.27" @@ -1664,9 +1692,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.67" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -1768,9 +1796,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.5" +version = "1.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" +checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff" dependencies = [ "aho-corasick", "memchr", @@ -1780,9 +1808,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" +checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" dependencies = [ "aho-corasick", "memchr", @@ -1830,9 +1858,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.23" +version = "0.37.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" +checksum = "4279d76516df406a8bd37e7dff53fd37d1a093f997a3c34a5c21658c126db06d" dependencies = [ "bitflags 1.3.2", "errno", @@ -1844,14 +1872,14 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.14" +version = "0.38.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "747c788e9ce8e92b12cd485c49ddf90723550b654b32508f979b71a7b1ecda4f" +checksum = "5a74ee2d7c2581cd139b42447d7d9389b889bdaad3a73f1ebb16f2a3237bb19c" dependencies = [ "bitflags 2.4.0", "errno", "libc", - "linux-raw-sys 0.4.7", + "linux-raw-sys 0.4.10", "windows-sys 0.48.0", ] @@ -1903,7 +1931,7 @@ checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1925,7 +1953,7 @@ checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1939,16 +1967,6 @@ dependencies = [ "digest", ] -[[package]] -name = "signal-hook" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" -dependencies = [ - "libc", - "signal-hook-registry", -] - [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -2063,9 +2081,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.37" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", @@ -2094,30 +2112,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if", - "fastrand 2.0.0", + "fastrand 2.0.1", "redox_syscall", - "rustix 0.38.14", + "rustix 0.38.18", "windows-sys 0.48.0", ] [[package]] name = "thiserror" -version = "1.0.48" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.48" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -2133,9 +2151,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6bb557fd245c28e6411aa56b6403c689ad95061f50e4be16c274e70a17e48" +checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe" dependencies = [ "deranged", "itoa", @@ -2148,15 +2166,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a942f44339478ef67935ab2bbaec2fb0322496cf3cbe84b261e06ac3814c572" +checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" dependencies = [ "time-core", ] @@ -2247,7 +2265,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -2429,9 +2447,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "waker-fn" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" +checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" [[package]] name = "wasi" @@ -2460,7 +2478,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", "wasm-bindgen-shared", ] @@ -2494,7 +2512,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2774,9 +2792,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winit" -version = "0.28.6" +version = "0.28.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "866db3f712fffba75d31bf0cdecf357c8aeafd158c5b7ab51dba2a2b2d47f196" +checksum = "9596d90b45384f5281384ab204224876e8e8bf7d58366d9b795ad99aa9894b94" dependencies = [ "android-activity", "bitflags 1.3.2", @@ -2809,9 +2827,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.5.15" +version = "0.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" +checksum = "037711d82167854aff2018dfd193aa0fef5370f456732f0d5a0c59b0f1b4b907" dependencies = [ "memchr", ] @@ -2848,9 +2866,9 @@ dependencies = [ [[package]] name = "xml-rs" -version = "0.8.18" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab77e97b50aee93da431f2cee7cd0f43b4d1da3c408042f2d7d164187774f0a" +checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" [[package]] name = "zbus" @@ -2871,7 +2889,7 @@ dependencies = [ "byteorder", "derivative", "enumflags2", - "event-listener", + "event-listener 2.5.3", "futures-core", "futures-sink", "futures-util", diff --git a/crates/vent-assets/src/model/gltf.rs b/crates/vent-assets/src/model/gltf.rs index 8688dde..2286be4 100644 --- a/crates/vent-assets/src/model/gltf.rs +++ b/crates/vent-assets/src/model/gltf.rs @@ -6,16 +6,16 @@ use std::{ }; use ash::vk; -use wgpu::{util::DeviceExt, BindGroupLayout}; +use vent_rendering::{image::VulkanImage, instance::VulkanInstance}; -use crate::{Model3D, Texture, Vertex3D}; +use crate::Model3D; use super::{Material, Mesh3D, ModelError}; pub(crate) struct GLTFLoader {} impl GLTFLoader { - pub async fn load(device: &ash::Device, path: &Path) -> Result { + pub async fn load(instance: &VulkanInstance, path: &Path) -> Result { let doc = gltf::Gltf::from_reader(fs::File::open(path).unwrap()).unwrap(); let path = path.parent().unwrap_or_else(|| Path::new("./")); @@ -26,15 +26,7 @@ impl GLTFLoader { let mut meshes = Vec::new(); doc.scenes().for_each(|scene| { scene.nodes().for_each(|node| { - Self::load_node( - device, - queue, - path, - node, - &buffer_data, - texture_bind_group_layout, - &mut meshes, - ); + Self::load_node(instance, path, node, &buffer_data, &mut meshes); }) }); @@ -42,41 +34,22 @@ impl GLTFLoader { } fn load_node( - device: &wgpu::Device, - queue: &wgpu::Queue, + instance: &VulkanInstance, model_dir: &Path, node: gltf::Node<'_>, buffer_data: &[gltf::buffer::Data], meshes: &mut Vec, ) { if let Some(mesh) = node.mesh() { - Self::load_mesh_multithreaded( - device, - queue, - model_dir, - mesh, - buffer_data, - texture_bind_group_layout, - meshes, - ); + Self::load_mesh_multithreaded(instance, model_dir, mesh, buffer_data, meshes); } - node.children().for_each(|child| { - Self::load_node( - device, - queue, - model_dir, - child, - buffer_data, - texture_bind_group_layout, - meshes, - ) - }) + node.children() + .for_each(|child| Self::load_node(instance, model_dir, child, buffer_data, meshes)) } fn load_mesh_multithreaded( - device: &wgpu::Device, - queue: &wgpu::Queue, + instance: &VulkanInstance, model_dir: &Path, mesh: gltf::Mesh, buffer_data: &[gltf::buffer::Data], @@ -91,24 +64,16 @@ impl GLTFLoader { for primitive in mesh.primitives() { let tx = tx.clone(); let mesh = mesh.clone(); - let device = device; - let queue = queue; + let instance = instance; let model_dir = model_dir; let buffer_data = buffer_data; - let texture_bind_group_layout = texture_bind_group_layout; s.spawn(move || { - let loaded_material = Self::load_material( - device, - queue, - model_dir, - primitive.material(), - buffer_data, - texture_bind_group_layout, - ); + let loaded_material = + Self::load_material(instance, model_dir, primitive.material(), buffer_data); let loaded_mesh = Self::load_primitive( - device, + instance, loaded_material, mesh.name(), buffer_data, @@ -125,13 +90,12 @@ impl GLTFLoader { } fn load_material( - device: &wgpu::Device, - queue: &wgpu::Queue, + instance: &VulkanInstance, model_dir: &Path, material: gltf::Material<'_>, buffer_data: &[gltf::buffer::Data], // image_data: &[gltf::image::Data], - ) -> wgpu::BindGroup { + ) -> vk::DescriptorSet { let pbr = material.pbr_metallic_roughness(); let diffuse_texture = if let Some(texture) = pbr.base_color_texture() { @@ -139,17 +103,24 @@ impl GLTFLoader { gltf::image::Source::View { view, mime_type: img_type, - } => Texture::from_memory_to_image_with_format( - device, - queue, - &buffer_data[view.buffer().index()], - image::ImageFormat::from_mime_type(img_type).expect("TODO: Error Handling"), - texture.texture().name(), - ) - .unwrap(), + } => { + let image = image::load_from_memory_with_format( + &buffer_data[view.buffer().index()], + image::ImageFormat::from_mime_type(img_type).expect("TODO: Error Handling"), + ) + .unwrap(); + VulkanImage::from_image( + &instance.device, + image, + instance.command_pool, + &instance.memory_allocator, + instance.graphics_queue, + None, + ) + } gltf::image::Source::Uri { uri, mime_type } => { let sampler = texture.texture().sampler(); - let wgpu_sampler = Self::convert_sampler(&sampler); + let sampler = Self::convert_sampler(&sampler); let image = if let Some(mime_type) = mime_type { image::load( BufReader::new(File::open(model_dir.join(uri)).unwrap()), @@ -161,17 +132,25 @@ impl GLTFLoader { image::open(model_dir.join(uri)).unwrap() }; - Texture::from_image( - device, - queue, + VulkanImage::from_image( + &instance.device, image, - Some(&wgpu_sampler), - texture.texture().name(), + instance.command_pool, + &instance.memory_allocator, + instance.graphics_queue, + Some(sampler), ) } } } else { - Texture::from_color(device, queue, [255, 255, 255, 255], 128, 128, None) + VulkanImage::from_color( + &instance.device, + [255, 255, 255, 255], + vk::Extent2D { + width: 128, + height: 128, + }, + ) }; let buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { @@ -202,34 +181,35 @@ impl GLTFLoader { }) } - /// Converts an gltf Texture Sampler into WGPU Filter Modes + /// Converts an gltf Texture Sampler into Vulkan Sampler Info #[must_use] - fn convert_sampler<'a>(sampler: &'a gltf::texture::Sampler<'a>) -> wgpu::SamplerDescriptor<'a> { - let mag_filter = sampler - .mag_filter() - .map_or(Texture::DEFAULT_TEXTURE_FILTER, |filter| match filter { - gltf::texture::MagFilter::Nearest => wgpu::FilterMode::Nearest, - gltf::texture::MagFilter::Linear => wgpu::FilterMode::Linear, - }); + fn convert_sampler(sampler: &gltf::texture::Sampler) -> vk::SamplerCreateInfo { + let mag_filter = sampler.mag_filter().map_or( + VulkanImage::DEFAULT_TEXTURE_FILTER, + |filter| match filter { + gltf::texture::MagFilter::Nearest => vk::Filter::NEAREST, + gltf::texture::MagFilter::Linear => vk::Filter::LINEAR, + }, + ); let (min_filter, mipmap_filter) = sampler.min_filter().map_or( ( - Texture::DEFAULT_TEXTURE_FILTER, - Texture::DEFAULT_TEXTURE_FILTER, + VulkanImage::DEFAULT_TEXTURE_FILTER, + vk::SamplerMipmapMode::LINEAR, ), |filter| match filter { gltf::texture::MinFilter::Nearest => { - (wgpu::FilterMode::Nearest, Texture::DEFAULT_TEXTURE_FILTER) + (vk::Filter::NEAREST, vk::SamplerMipmapMode::LINEAR) } gltf::texture::MinFilter::Linear | gltf::texture::MinFilter::LinearMipmapNearest => { - (wgpu::FilterMode::Linear, Texture::DEFAULT_TEXTURE_FILTER) + (vk::Filter::LINEAR, vk::SamplerMipmapMode::LINEAR) } gltf::texture::MinFilter::NearestMipmapNearest => { - (wgpu::FilterMode::Nearest, wgpu::FilterMode::Nearest) + (vk::Filter::NEAREST, vk::SamplerMipmapMode::NEAREST) } gltf::texture::MinFilter::LinearMipmapLinear => { - (wgpu::FilterMode::Linear, wgpu::FilterMode::Linear) + (vk::Filter::LINEAR, vk::SamplerMipmapMode::LINEAR) } _ => unimplemented!(), }, @@ -238,15 +218,13 @@ impl GLTFLoader { let address_mode_u = Self::conv_wrapping_mode(sampler.wrap_s()); let address_mode_v = Self::conv_wrapping_mode(sampler.wrap_t()); - wgpu::SamplerDescriptor { - label: sampler.name(), - mag_filter, - min_filter, - mipmap_filter, - address_mode_u, - address_mode_v, - ..Default::default() - } + vk::SamplerCreateInfo::builder() + .mag_filter(mag_filter) + .min_filter(min_filter) + .mipmap_mode(mipmap_filter) + .address_mode_u(address_mode_u) + .address_mode_v(address_mode_v) + .build() } #[must_use] @@ -259,7 +237,7 @@ impl GLTFLoader { } fn load_primitive( - device: &wgpu::Device, + instance: &VulkanInstance, bind_group: wgpu::BindGroup, name: Option<&str>, buffer_data: &[gltf::buffer::Data], diff --git a/crates/vent-assets/src/model/mod.rs b/crates/vent-assets/src/model/mod.rs index e9cba82..c28b25c 100644 --- a/crates/vent-assets/src/model/mod.rs +++ b/crates/vent-assets/src/model/mod.rs @@ -5,7 +5,7 @@ use ash::vk; use bytemuck::{Pod, Zeroable}; use vent_rendering::allocator::MemoryAllocator; use vent_rendering::buffer::VulkanBuffer; -use vent_rendering::instance::{self, Instance}; +use vent_rendering::instance::{self, VulkanInstance}; use vent_rendering::Vertex3D; use vent_sdk::utils::stopwatch::Stopwatch; @@ -32,13 +32,9 @@ pub struct Material { impl Model3D { #[inline] - pub async fn load>( - device: &ash::Device, - path: P, - allocator: &MemoryAllocator, - ) -> Self { + pub async fn load>(instance: &VulkanInstance, path: P) -> Self { let sw = Stopwatch::new_and_start(); - let model = load_model_from_path(device, path.as_ref(), allocator) + let model = load_model_from_path(instance, path.as_ref()) .await .expect("Failed to Load 3D Model"); log::info!( @@ -67,9 +63,8 @@ impl Model3D { } async fn load_model_from_path( - device: &ash::Device, + instance: &VulkanInstance, path: &Path, - allocator: &MemoryAllocator, ) -> Result { if !path.exists() { return Err(ModelError::FileNotExists); @@ -79,8 +74,8 @@ async fn load_model_from_path( // Very Pretty, I know match extension { - "obj" => Ok(OBJLoader::load(device, path, allocator).await?), - "gltf" => Ok(GLTFLoader::load(device, path).await?), + "obj" => Ok(OBJLoader::load(instance, path).await?), + "gltf" => Ok(GLTFLoader::load(instance, path).await?), _ => Err(ModelError::UnsupportedFormat), } } diff --git a/crates/vent-assets/src/model/obj.rs b/crates/vent-assets/src/model/obj.rs index 219d89f..c59ed37 100644 --- a/crates/vent-assets/src/model/obj.rs +++ b/crates/vent-assets/src/model/obj.rs @@ -1,7 +1,7 @@ use std::path::Path; use ash::vk; -use vent_rendering::{allocator::MemoryAllocator, image::VulkanImage}; +use vent_rendering::{allocator::MemoryAllocator, image::VulkanImage, instance::VulkanInstance}; use wgpu::{util::DeviceExt, BindGroupLayout}; use crate::{Model3D, Texture, Vertex3D}; @@ -11,11 +11,7 @@ use super::{Material, Mesh3D, ModelError}; pub(crate) struct OBJLoader {} impl OBJLoader { - pub async fn load( - device: &ash::Device, - path: &Path, - allocator: &MemoryAllocator, - ) -> Result { + pub async fn load(instance: &VulkanInstance, path: &Path) -> Result { let (models, materials) = match tobj::load_obj(path, &tobj::GPU_LOAD_OPTIONS) { Ok(r) => r, Err(e) => return Err(ModelError::LoadingError(format!("{}", e))), @@ -33,32 +29,47 @@ impl OBJLoader { let meshes = models .into_iter() - .map(|model| Self::load_mesh(device, &model.name, &model.mesh, allocator)) + .map(|model| { + Self::load_mesh( + &instance.device, + &instance.memory_allocator, + &model.name, + &model.mesh, + ) + }) .collect::>(); let _final_materials = materials .into_iter() - .map(|material| Self::load_material(device, path.parent().unwrap(), &material)) + .map(|material| Self::load_material(&instance, path.parent().unwrap(), &material)) .collect::>(); Ok(Model3D { meshes }) } fn load_material( - device: &ash::Device, + instance: &VulkanInstance, model_dir: &Path, material: &tobj::Material, ) -> wgpu::BindGroup { let diffuse_texture = if let Some(texture) = &material.diffuse_texture { - Texture::from_image( - device, - queue, + VulkanImage::from_image( + &instance.device, image::open(model_dir.join(texture)).unwrap(), + instance.command_pool, + &instance.memory_allocator, + instance.graphics_queue, None, - Some(texture), ) } else { - Texture::from_color(device, queue, [255, 255, 255, 255], 128, 128, None) + VulkanImage::from_color( + &instance.device, + [255, 255, 255, 255], + vk::Extent2D { + width: 128, + height: 128, + }, + ) }; let diffuse = material.diffuse.unwrap_or([1.0, 1.0, 1.0]); @@ -90,33 +101,57 @@ impl OBJLoader { }) } - fn write_sets(device: &ash::Device, diffuse_texture: VulkanImage) { - let image_info = vk::DescriptorImageInfo::builder() - .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) - .image_view(data.texture_image_view) - .sampler(data.texture_sampler) - .build(); - - let sampler_write = vk::WriteDescriptorSet::builder() - .dst_set(data.descriptor_sets[i]) - .dst_binding(0) - .dst_array_element(0) - .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) - .image_info(&[image_info]); - - let buffer_info = vk::DescriptorBufferInfo::builder() - .buffer(data.uniform_buffers[i]) - .offset(0) - .range(size_of::() as u64) - .build(); - - let ubo_write = vk::WriteDescriptorSet::builder() - .dst_set(data.descriptor_sets[i]) - .dst_binding(1) - .dst_array_element(0) - .descriptor_type(vk::DescriptorType::UNIFORM_BUFFER) - .buffer_info(&[buffer_info]) - .build(); + fn create_uniform_buffers( + instance: &Instance, + device: &Device, + data: &mut AppData, + ) -> Result<()> { + for _ in 0..data.swapchain_images.len() { + let (uniform_buffer, uniform_buffer_memory) = create_buffer( + instance, + device, + data, + size_of::() as u64, + vk::BufferUsageFlags::UNIFORM_BUFFER, + vk::MemoryPropertyFlags::HOST_COHERENT | vk::MemoryPropertyFlags::HOST_VISIBLE, + )?; + + data.uniform_buffers.push(uniform_buffer); + data.uniform_buffers_memory.push(uniform_buffer_memory); + } + + Ok(()) + } + + fn write_sets(instance: &VulkanInstance, diffuse_texture: VulkanImage) { + for i in 0..instance.swapchain_images.len() { + let image_info = vk::DescriptorImageInfo::builder() + .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) + .image_view(diffuse_texture.image_view) + .sampler(diffuse_texture.sampler) + .build(); + + let sampler_write = vk::WriteDescriptorSet::builder() + .dst_set(instance.descriptor_sets[i]) + .dst_binding(0) + .dst_array_element(0) + .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) + .image_info(&[image_info]); + + let buffer_info = vk::DescriptorBufferInfo::builder() + .buffer(data.uniform_buffers[i]) + .offset(0) + .range(size_of::() as u64) + .build(); + + let ubo_write = vk::WriteDescriptorSet::builder() + .dst_set(instance.descriptor_sets[i]) + .dst_binding(1) + .dst_array_element(0) + .descriptor_type(vk::DescriptorType::UNIFORM_BUFFER) + .buffer_info(&[buffer_info]) + .build(); + } } fn load_mesh( diff --git a/crates/vent-ecs/src/archetype.rs b/crates/vent-ecs/src/archetype.rs index f75abcb..11cf3e9 100644 --- a/crates/vent-ecs/src/archetype.rs +++ b/crates/vent-ecs/src/archetype.rs @@ -30,10 +30,7 @@ impl Archetype { /// Adds a component to the archetype. pub fn add_component(&mut self, component_id: usize, component: T) { - let component_data = self - .component_data - .entry(component_id) - .or_insert(Vec::new()); + let component_data = self.component_data.entry(component_id).or_default(); component_data.push(Box::new(component)); } diff --git a/crates/vent-rendering/src/buffer.rs b/crates/vent-rendering/src/buffer.rs index 377f707..5d273e3 100644 --- a/crates/vent-rendering/src/buffer.rs +++ b/crates/vent-rendering/src/buffer.rs @@ -5,8 +5,8 @@ use ash::vk; use crate::allocator::MemoryAllocator; pub struct VulkanBuffer { - buffer: vk::Buffer, - buffer_memory: vk::DeviceMemory, + pub buffer: vk::Buffer, + pub buffer_memory: vk::DeviceMemory, } impl VulkanBuffer { diff --git a/crates/vent-rendering/src/image.rs b/crates/vent-rendering/src/image.rs index 56a431c..6561883 100644 --- a/crates/vent-rendering/src/image.rs +++ b/crates/vent-rendering/src/image.rs @@ -1,5 +1,10 @@ use ash::vk::{self, Extent2D}; +use crate::{ + allocator::MemoryAllocator, begin_single_time_command, buffer::VulkanBuffer, + end_single_time_command, +}; + pub struct VulkanImage { pub image: vk::Image, pub image_view: vk::ImageView, @@ -7,6 +12,8 @@ pub struct VulkanImage { } impl VulkanImage { + pub const DEFAULT_TEXTURE_FILTER: vk::Filter = vk::Filter::LINEAR; + pub fn new( device: &ash::Device, format: vk::Format, @@ -27,6 +34,55 @@ impl VulkanImage { } } + pub fn from_image( + device: &ash::Device, + image: image::DynamicImage, + command_pool: vk::CommandPool, + allocator: &MemoryAllocator, + submit_queue: vk::Queue, + sampler_info: Option, + ) -> Self { + let image_size = Extent2D { + width: image.width(), + height: image.height(), + }; + let image_data = match &image { + image::DynamicImage::ImageLuma8(_) | image::DynamicImage::ImageRgb8(_) => { + image.to_rgba8().into_raw() + } + image::DynamicImage::ImageLumaA8(_) | image::DynamicImage::ImageRgba8(_) => { + image.into_bytes() + } + _ => image.to_rgb8().into_raw(), + }; + let image_data_size = + (std::mem::size_of::() as u32 * image_size.width * image_size.height * 4) + as vk::DeviceSize; + let vk_image = Self::new( + device, + vk::Format::R8G8B8A8_UNORM, + sampler_info.unwrap_or(Self::default_sampler()), + image_size, + vk::ImageUsageFlags::TRANSFER_DST | vk::ImageUsageFlags::SAMPLED, + ); + let buffer = VulkanBuffer::new_init( + device, + allocator, + image_data_size, + vk::BufferUsageFlags::TRANSFER_SRC, + &image_data, + ); + vk_image.copy_buffer_to_image( + device, + command_pool, + submit_queue, + *buffer, + image_size.width, + image_size.height, + ); + vk_image + } + pub fn new_depth(device: &ash::Device, format: vk::Format, size: Extent2D) -> Self { let image = Self::create_image( device, @@ -37,7 +93,7 @@ impl VulkanImage { let image_view = Self::create_image_view(image, device, format, vk::ImageAspectFlags::DEPTH); - let sampler = Self::create_sampler(device); + let sampler = unsafe { device.create_sampler(&Self::default_sampler(), None) }.unwrap(); Self { image, @@ -46,23 +102,29 @@ impl VulkanImage { } } - pub fn new_from_color(device: &ash::Device, color: [u8; 4], size: Extent2D) {} + pub fn from_color(_device: &ash::Device, color: [u8; 4], size: Extent2D) -> Self { + let _img = image::RgbaImage::from_pixel(size.width, size.height, image::Rgba(color)); + todo!() + } - fn copy_buffer_to_image( + pub fn copy_buffer_to_image( + &self, device: &ash::Device, + command_pool: vk::CommandPool, + submit_queue: vk::Queue, buffer: vk::Buffer, - image: vk::Image, width: u32, height: u32, - ) { - let command_buffer = begin_single_time_commands(device)?; - + ) { + let command_buffer = begin_single_time_command(device, command_pool); + let subresource = vk::ImageSubresourceLayers::builder() .aspect_mask(vk::ImageAspectFlags::COLOR) .mip_level(0) .base_array_layer(0) - .layer_count(1); - + .layer_count(1) + .build(); + let region = vk::BufferImageCopy::builder() .buffer_offset(0) .buffer_row_length(0) @@ -73,23 +135,26 @@ impl VulkanImage { width, height, depth: 1, - }); - - device.cmd_copy_buffer_to_image( - command_buffer, - buffer, - image, - vk::ImageLayout::TRANSFER_DST_OPTIMAL, - &[region], - ); - - end_single_time_commands(device, command_buffer)?; + }) + .build(); + + unsafe { + device.cmd_copy_buffer_to_image( + command_buffer, + buffer, + self.image, + vk::ImageLayout::TRANSFER_DST_OPTIMAL, + &[region], + ) + }; + + end_single_time_command(device, command_pool, submit_queue, command_buffer); } - fn create_sampler(device: &ash::Device) -> vk::Sampler { - let create_info = vk::SamplerCreateInfo::builder() - .mag_filter(vk::Filter::LINEAR) - .min_filter(vk::Filter::LINEAR) + fn default_sampler() -> vk::SamplerCreateInfo { + vk::SamplerCreateInfo::builder() + .mag_filter(Self::DEFAULT_TEXTURE_FILTER) + .min_filter(Self::DEFAULT_TEXTURE_FILTER) .address_mode_u(vk::SamplerAddressMode::REPEAT) .address_mode_v(vk::SamplerAddressMode::REPEAT) .address_mode_w(vk::SamplerAddressMode::REPEAT) @@ -100,8 +165,7 @@ impl VulkanImage { .compare_enable(false) .compare_op(vk::CompareOp::ALWAYS) .mipmap_mode(vk::SamplerMipmapMode::LINEAR) - .build(); - unsafe { device.create_sampler(&create_info, None) }.unwrap() + .build() } fn create_image_view( diff --git a/crates/vent-rendering/src/instance.rs b/crates/vent-rendering/src/instance.rs index d360882..ccb3ce3 100644 --- a/crates/vent-rendering/src/instance.rs +++ b/crates/vent-rendering/src/instance.rs @@ -48,7 +48,7 @@ unsafe extern "system" fn vulkan_debug_callback( vk::FALSE } -pub struct Instance { +pub struct VulkanInstance { pub memory_allocator: MemoryAllocator, pub instance: ash::Instance, @@ -90,7 +90,7 @@ pub struct Instance { debug_messenger: vk::DebugUtilsMessengerEXT, } -impl Instance { +impl VulkanInstance { pub fn new(application_name: &str, window: winit::window::Window) -> Self { let entry = Entry::linked(); @@ -251,7 +251,7 @@ impl Instance { } .unwrap(); unsafe { - let result = match self.swapchain_loader.acquire_next_image( + match self.swapchain_loader.acquire_next_image( self.swapchain, u64::MAX, self.image_available_semaphores[self.frame], @@ -262,10 +262,10 @@ impl Instance { self.device .wait_for_fences(&[image_in_flight], true, u64::max_value()) .unwrap(); - return Some(index); + Some(index) } - Err(_) => return None, - }; + Err(_) => None, + } } } @@ -404,7 +404,7 @@ impl Instance { .map(|i| i as u32); let mut present = None; - for (index, properties) in properties.iter().enumerate() { + for (index, _properties) in properties.iter().enumerate() { if unsafe { surface_loader.get_physical_device_surface_support( pdevice, @@ -725,7 +725,7 @@ impl Instance { } } -impl Drop for Instance { +impl Drop for VulkanInstance { fn drop(&mut self) { unsafe { self.device.device_wait_idle().unwrap(); diff --git a/crates/vent-rendering/src/lib.rs b/crates/vent-rendering/src/lib.rs index 5ea7354..9622477 100644 --- a/crates/vent-rendering/src/lib.rs +++ b/crates/vent-rendering/src/lib.rs @@ -52,3 +52,61 @@ impl<'a> Vertex<'a> for Vertex3D { ] } } + +pub fn begin_single_time_command( + device: &ash::Device, + command_pool: vk::CommandPool, +) -> vk::CommandBuffer { + let command_buffer_allocate_info = vk::CommandBufferAllocateInfo::builder() + .command_buffer_count(1) + .command_pool(command_pool) + .level(vk::CommandBufferLevel::PRIMARY) + .build(); + + let command_buffer = unsafe { + device + .allocate_command_buffers(&command_buffer_allocate_info) + .expect("Failed to allocate Command Buffers!") + }[0]; + + let command_buffer_begin_info = vk::CommandBufferBeginInfo::builder() + .flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT) + .build(); + + unsafe { + device + .begin_command_buffer(command_buffer, &command_buffer_begin_info) + .expect("Failed to begin recording Command Buffer at beginning!"); + } + + command_buffer +} + +pub fn end_single_time_command( + device: &ash::Device, + command_pool: vk::CommandPool, + submit_queue: vk::Queue, + command_buffer: vk::CommandBuffer, +) { + unsafe { + device + .end_command_buffer(command_buffer) + .expect("Failed to record Command Buffer at Ending!"); + } + + let buffers_to_submit = [command_buffer]; + + let submit_info = vk::SubmitInfo::builder() + .command_buffers(&buffers_to_submit) + .build(); + + unsafe { + device + .queue_submit(submit_queue, &[submit_info], vk::Fence::null()) + .expect("Failed to Queue Submit!"); + device + .queue_wait_idle(submit_queue) + .expect("Failed to wait Queue idle!"); + device.free_command_buffers(command_pool, &buffers_to_submit); + } +} diff --git a/crates/vent-rendering/src/pipeline.rs b/crates/vent-rendering/src/pipeline.rs index ddc2f5f..b74315d 100644 --- a/crates/vent-rendering/src/pipeline.rs +++ b/crates/vent-rendering/src/pipeline.rs @@ -2,10 +2,10 @@ use std::{ffi::CStr, fs::File}; use ash::{util::read_spv, vk}; -use crate::{instance::Instance, Vertex, Vertex3D}; +use crate::{instance::VulkanInstance, Vertex, Vertex3D}; pub fn create_pipeline( - instance: Instance, + instance: VulkanInstance, vertex_file: String, fragment_file: String, surface_resolution: vk::Extent2D, diff --git a/crates/vent-runtime/src/render/d3/mod.rs b/crates/vent-runtime/src/render/d3/mod.rs index 0e1fcee..75e7737 100644 --- a/crates/vent-runtime/src/render/d3/mod.rs +++ b/crates/vent-runtime/src/render/d3/mod.rs @@ -3,7 +3,7 @@ use std::mem; use glam::Mat4; use vent_assets::{Mesh3D, Vertex, Vertex3D}; use vent_ecs::world::World; -use vent_rendering::instance::Instance; +use vent_rendering::instance::VulkanInstance; use wgpu::util::DeviceExt; use self::light_renderer::LightRenderer; @@ -51,7 +51,7 @@ pub struct Renderer3D { } impl Renderer for Renderer3D { - fn init(instance: Instance, camera: &mut dyn Camera) -> Self + fn init(instance: VulkanInstance, camera: &mut dyn Camera) -> Self where Self: Sized, { diff --git a/crates/vent-runtime/src/render/mod.rs b/crates/vent-runtime/src/render/mod.rs index bdf0143..babb96c 100644 --- a/crates/vent-runtime/src/render/mod.rs +++ b/crates/vent-runtime/src/render/mod.rs @@ -2,7 +2,7 @@ use std::time::{Duration, Instant}; use vent_common::render::WGPURenderer; -use vent_rendering::instance::Instance; +use vent_rendering::instance::VulkanInstance; use winit::dpi::PhysicalSize; use winit::window::Window; @@ -22,7 +22,7 @@ mod d2; mod d3; pub(crate) struct DefaultRuntimeRenderer { - instance: Instance, + instance: VulkanInstance, runtime_renderer: RawRuntimeRenderer, } @@ -33,7 +33,7 @@ impl DefaultRuntimeRenderer { event_loop: &winit::event_loop::EventLoopWindowTarget<()>, camera: &mut dyn Camera, ) -> Self { - let instance = Instance::new("TODO", window); + let instance = VulkanInstance::new("TODO", window); let runtime_renderer = RawRuntimeRenderer::new(dimension, instance, event_loop, camera); Self { instance, @@ -123,7 +123,7 @@ pub struct RawRuntimeRenderer { impl RawRuntimeRenderer { pub fn new( dimension: Dimension, - instance: Instance, + instance: VulkanInstance, event_loop: &winit::event_loop::EventLoopWindowTarget<()>, camera: &mut dyn Camera, ) -> Self { @@ -145,7 +145,12 @@ impl RawRuntimeRenderer { } } - pub fn render(&mut self, instance: Instance, window: &Window, camera: &mut dyn Camera) -> f32 { + pub fn render( + &mut self, + instance: VulkanInstance, + window: &Window, + camera: &mut dyn Camera, + ) -> f32 { let frame_start = Instant::now(); let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { From 64552128bd280e89ec0190661ddde5d10b3e9f54 Mon Sep 17 00:00:00 2001 From: Snowiiii <71594357+Snowiiii@users.noreply.github.com> Date: Sun, 29 Oct 2023 09:53:56 +0100 Subject: [PATCH 03/14] Moved Vent-Assets to Vulkan --- crates/vent-assets/src/lib.rs | 2 +- crates/vent-assets/src/model/gltf.rs | 107 ++++++++++++----- crates/vent-assets/src/model/mod.rs | 23 ++-- crates/vent-assets/src/model/obj.rs | 111 ++++++++---------- crates/vent-rendering/src/instance.rs | 10 +- .../vent-runtime/src/render/model_renderer.rs | 2 +- 6 files changed, 141 insertions(+), 114 deletions(-) diff --git a/crates/vent-assets/src/lib.rs b/crates/vent-assets/src/lib.rs index 03af14f..36aba44 100644 --- a/crates/vent-assets/src/lib.rs +++ b/crates/vent-assets/src/lib.rs @@ -24,5 +24,5 @@ pub struct Mesh3D { index_buf: VulkanBuffer, index_count: u32, - descriptor_set: Option, + descriptor_sets: Option>, } diff --git a/crates/vent-assets/src/model/gltf.rs b/crates/vent-assets/src/model/gltf.rs index 2286be4..6824985 100644 --- a/crates/vent-assets/src/model/gltf.rs +++ b/crates/vent-assets/src/model/gltf.rs @@ -2,11 +2,11 @@ use std::{ fs::{self, File}, io::BufReader, path::Path, - sync, thread, + sync, thread, mem::size_of, }; use ash::vk; -use vent_rendering::{image::VulkanImage, instance::VulkanInstance}; +use vent_rendering::{image::VulkanImage, instance::VulkanInstance, Vertex3D, buffer::VulkanBuffer}; use crate::Model3D; @@ -95,7 +95,7 @@ impl GLTFLoader { material: gltf::Material<'_>, buffer_data: &[gltf::buffer::Data], // image_data: &[gltf::image::Data], - ) -> vk::DescriptorSet { + ) -> Vec { let pbr = material.pbr_metallic_roughness(); let diffuse_texture = if let Some(texture) = pbr.base_color_texture() { @@ -153,32 +153,70 @@ impl GLTFLoader { ) }; - let buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: Some("Texture Uniform Buffer"), - contents: bytemuck::bytes_of(&Material { - base_color: pbr.base_color_factor(), - }), - usage: wgpu::BufferUsages::UNIFORM, - }); + let binding = Material { + base_color: pbr.base_color_factor(), + }; + let buffer_data = bytemuck::bytes_of(&binding); + + let mut uniform_buffers = vec![]; + Self::create_uniform_buffers(instance, buffer_data, &mut uniform_buffers); + + Self::write_sets(instance, diffuse_texture, &uniform_buffers) + } - device.create_bind_group(&wgpu::BindGroupDescriptor { - layout: texture_bind_group_layout, - entries: &[ - wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::TextureView(&diffuse_texture.view), - }, - wgpu::BindGroupEntry { - binding: 1, - resource: wgpu::BindingResource::Sampler(&diffuse_texture.sampler), - }, - wgpu::BindGroupEntry { - binding: 2, - resource: buffer.as_entire_binding(), - }, - ], - label: material.name(), - }) + fn create_uniform_buffers( + instance: &VulkanInstance, + data: &[u8], + uniform_buffers: &mut Vec, + ) { + for _ in 0..instance.swapchain_images.len() { + let buffer = VulkanBuffer::new_init( + &instance.device, + &instance.memory_allocator, + size_of::() as u64, + vk::BufferUsageFlags::UNIFORM_BUFFER, + data, + ); + uniform_buffers.push(buffer) + } + } + + fn write_sets(instance: &VulkanInstance, diffuse_texture: VulkanImage, uniforms_buffers: &Vec) -> Vec { + let descriptor_sets = VulkanInstance::allocate_descriptor_sets(&instance.device, instance.descriptor_pool, instance.descriptor_set_layout, &instance.swapchain_images); + + for (i, &_descritptor_set) in descriptor_sets.iter().enumerate() { + let image_info = vk::DescriptorImageInfo::builder() + .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) + .image_view(diffuse_texture.image_view) + .sampler(diffuse_texture.sampler) + .build(); + + let _sampler_write = vk::WriteDescriptorSet::builder() + .dst_set(descriptor_sets[i]) + .dst_binding(0) + .dst_array_element(0) + .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) + .image_info(&[image_info]); + + let buffer_info = vk::DescriptorBufferInfo::builder() + .buffer(uniforms_buffers[i].buffer) + .offset(0) + .range(size_of::() as u64) + .build(); + + let ubo_write = vk::WriteDescriptorSet::builder() + .dst_set(descriptor_sets[i]) + .dst_binding(1) + .dst_array_element(0) + .descriptor_type(vk::DescriptorType::UNIFORM_BUFFER) + .buffer_info(&[buffer_info]) + .build(); + + unsafe { + instance.device.update_descriptor_sets(&[ubo_write], &[]); + } + } + descriptor_sets } /// Converts an gltf Texture Sampler into Vulkan Sampler Info @@ -228,7 +266,7 @@ impl GLTFLoader { } #[must_use] - fn conv_wrapping_mode(mode: gltf::texture::WrappingMode) -> vk::SamplerAddressMode { + const fn conv_wrapping_mode(mode: gltf::texture::WrappingMode) -> vk::SamplerAddressMode { match mode { gltf::texture::WrappingMode::ClampToEdge => vk::SamplerAddressMode::CLAMP_TO_EDGE, gltf::texture::WrappingMode::MirroredRepeat => vk::SamplerAddressMode::MIRRORED_REPEAT, @@ -238,7 +276,7 @@ impl GLTFLoader { fn load_primitive( instance: &VulkanInstance, - bind_group: wgpu::BindGroup, + bind_group: Vec, name: Option<&str>, buffer_data: &[gltf::buffer::Data], primitive: gltf::Primitive, @@ -269,6 +307,13 @@ impl GLTFLoader { let indices: Vec<_> = reader.read_indices().unwrap().into_u32().collect(); - Mesh3D::new(device, &vertices, &indices, Some(bind_group), name) + Mesh3D::new( + &instance.device, + &instance.memory_allocator, + &vertices, + &indices, + Some(bind_group), + name, + ) } } diff --git a/crates/vent-assets/src/model/mod.rs b/crates/vent-assets/src/model/mod.rs index c28b25c..f630850 100644 --- a/crates/vent-assets/src/model/mod.rs +++ b/crates/vent-assets/src/model/mod.rs @@ -5,7 +5,7 @@ use ash::vk; use bytemuck::{Pod, Zeroable}; use vent_rendering::allocator::MemoryAllocator; use vent_rendering::buffer::VulkanBuffer; -use vent_rendering::instance::{self, VulkanInstance}; +use vent_rendering::instance::{VulkanInstance}; use vent_rendering::Vertex3D; use vent_sdk::utils::stopwatch::Stopwatch; @@ -51,10 +51,11 @@ impl Model3D { device: &ash::Device, pipeline_layout: vk::PipelineLayout, command_buffer: vk::CommandBuffer, + buffer_index: u32, ) { self.meshes.iter().for_each(|mesh| { // rpass.push_debug_group("Bind Mesh"); - mesh.bind(device, command_buffer, pipeline_layout, true); + mesh.bind(device, command_buffer, buffer_index, pipeline_layout, true); // rpass.pop_debug_group(); // rpass.insert_debug_marker("Draw!"); mesh.draw(device, command_buffer); @@ -86,13 +87,13 @@ impl Mesh3D { allocator: &MemoryAllocator, vertices: &[Vertex3D], indices: &[u32], - bind_group: Option, - name: Option<&str>, + descriptor_sets: Option>, + _name: Option<&str>, ) -> Self { let vertex_buf = VulkanBuffer::new_init( device, allocator, - (size_of::() * vertices.len()) as vk::DeviceSize, + std::mem::size_of_val(vertices) as vk::DeviceSize, vk::BufferUsageFlags::VERTEX_BUFFER, bytemuck::cast_slice(vertices), ); @@ -109,7 +110,7 @@ impl Mesh3D { vertex_buf, index_buf, index_count: indices.len() as u32, - descriptor_set: bind_group, + descriptor_sets, } } @@ -117,6 +118,7 @@ impl Mesh3D { &self, device: &ash::Device, command_buffer: vk::CommandBuffer, + buffer_index: u32, pipeline_layout: vk::PipelineLayout, with_descriptor_set: bool, ) { @@ -124,13 +126,13 @@ impl Mesh3D { device.cmd_bind_vertex_buffers(command_buffer, 0, &[*self.vertex_buf], &[0]); device.cmd_bind_index_buffer(command_buffer, *self.index_buf, 0, vk::IndexType::UINT32); if with_descriptor_set { - if let Some(ds) = self.descriptor_set { + if let Some(ds) = &self.descriptor_sets { device.cmd_bind_descriptor_sets( command_buffer, vk::PipelineBindPoint::GRAPHICS, pipeline_layout, 0, - &[ds], + &[ds[buffer_index as usize]], &[], ) } @@ -142,8 +144,11 @@ impl Mesh3D { unsafe { device.cmd_draw_indexed(command_buffer, self.index_count, 1, 0, 0, 0) }; } - pub fn destroy(&self, device: &ash::Device) { + pub fn destroy(self, descriptor_pool: vk::DescriptorPool, device: &ash::Device) { self.vertex_buf.destroy(device); self.index_buf.destroy(device); + if let Some(ds) = self.descriptor_sets { + unsafe { device.free_descriptor_sets(descriptor_pool, &ds) }; + } } } diff --git a/crates/vent-assets/src/model/obj.rs b/crates/vent-assets/src/model/obj.rs index c59ed37..d5d43ce 100644 --- a/crates/vent-assets/src/model/obj.rs +++ b/crates/vent-assets/src/model/obj.rs @@ -1,10 +1,11 @@ -use std::path::Path; +use std::{mem::size_of, path::Path}; use ash::vk; -use vent_rendering::{allocator::MemoryAllocator, image::VulkanImage, instance::VulkanInstance}; -use wgpu::{util::DeviceExt, BindGroupLayout}; +use vent_rendering::{ + buffer::VulkanBuffer, image::VulkanImage, instance::VulkanInstance, Vertex3D, +}; -use crate::{Model3D, Texture, Vertex3D}; +use crate::Model3D; use super::{Material, Mesh3D, ModelError}; @@ -31,17 +32,16 @@ impl OBJLoader { .into_iter() .map(|model| { Self::load_mesh( - &instance.device, - &instance.memory_allocator, + instance, &model.name, &model.mesh, ) }) .collect::>(); - let _final_materials = materials + let _descriptor_sets = materials .into_iter() - .map(|material| Self::load_material(&instance, path.parent().unwrap(), &material)) + .map(|material| Self::load_material(instance, path.parent().unwrap(), &material)) .collect::>(); Ok(Model3D { meshes }) @@ -51,7 +51,7 @@ impl OBJLoader { instance: &VulkanInstance, model_dir: &Path, material: &tobj::Material, - ) -> wgpu::BindGroup { + ) -> Vec { let diffuse_texture = if let Some(texture) = &material.diffuse_texture { VulkanImage::from_image( &instance.device, @@ -73,90 +73,75 @@ impl OBJLoader { }; let diffuse = material.diffuse.unwrap_or([1.0, 1.0, 1.0]); - let buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: Some("Uniform Buffer"), - contents: bytemuck::bytes_of(&Material { - base_color: [diffuse[0], diffuse[1], diffuse[2], 1.0], - }), - usage: wgpu::BufferUsages::UNIFORM, - }); - - device.create_bind_group(&wgpu::BindGroupDescriptor { - layout: texture_bind_group_layout, - entries: &[ - wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::TextureView(&diffuse_texture.view), - }, - wgpu::BindGroupEntry { - binding: 1, - resource: wgpu::BindingResource::Sampler(&diffuse_texture.sampler), - }, - wgpu::BindGroupEntry { - binding: 2, - resource: buffer.as_entire_binding(), - }, - ], - label: Some(&material.name), - }) + let binding = Material { + base_color: [diffuse[0], diffuse[1], diffuse[2], 1.0], + }; + let buffer_data = bytemuck::bytes_of(&binding); + + let mut uniform_buffers = vec![]; + Self::create_uniform_buffers(instance, buffer_data, &mut uniform_buffers); + + Self::write_sets(instance, diffuse_texture, &uniform_buffers) } fn create_uniform_buffers( - instance: &Instance, - device: &Device, - data: &mut AppData, - ) -> Result<()> { - for _ in 0..data.swapchain_images.len() { - let (uniform_buffer, uniform_buffer_memory) = create_buffer( - instance, - device, - data, - size_of::() as u64, + instance: &VulkanInstance, + data: &[u8], + uniform_buffers: &mut Vec, + ) { + for _ in 0..instance.swapchain_images.len() { + let buffer = VulkanBuffer::new_init( + &instance.device, + &instance.memory_allocator, + size_of::() as u64, vk::BufferUsageFlags::UNIFORM_BUFFER, - vk::MemoryPropertyFlags::HOST_COHERENT | vk::MemoryPropertyFlags::HOST_VISIBLE, - )?; - - data.uniform_buffers.push(uniform_buffer); - data.uniform_buffers_memory.push(uniform_buffer_memory); + data, + ); + uniform_buffers.push(buffer) } - - Ok(()) } - fn write_sets(instance: &VulkanInstance, diffuse_texture: VulkanImage) { - for i in 0..instance.swapchain_images.len() { + fn write_sets(instance: &VulkanInstance, diffuse_texture: VulkanImage, uniforms_buffers: &Vec) -> Vec { + let descriptor_sets = VulkanInstance::allocate_descriptor_sets(&instance.device, instance.descriptor_pool, instance.descriptor_set_layout, &instance.swapchain_images); + + for (i, &_descritptor_set) in descriptor_sets.iter().enumerate() { let image_info = vk::DescriptorImageInfo::builder() .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) .image_view(diffuse_texture.image_view) .sampler(diffuse_texture.sampler) .build(); - let sampler_write = vk::WriteDescriptorSet::builder() - .dst_set(instance.descriptor_sets[i]) + let _sampler_write = vk::WriteDescriptorSet::builder() + .dst_set(descriptor_sets[i]) .dst_binding(0) .dst_array_element(0) .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) .image_info(&[image_info]); let buffer_info = vk::DescriptorBufferInfo::builder() - .buffer(data.uniform_buffers[i]) + .buffer(uniforms_buffers[i].buffer) .offset(0) - .range(size_of::() as u64) + .range(size_of::() as u64) .build(); let ubo_write = vk::WriteDescriptorSet::builder() - .dst_set(instance.descriptor_sets[i]) + .dst_set(descriptor_sets[i]) .dst_binding(1) .dst_array_element(0) .descriptor_type(vk::DescriptorType::UNIFORM_BUFFER) .buffer_info(&[buffer_info]) .build(); + + unsafe { + instance.device.update_descriptor_sets(&[ubo_write], &[]); + } } + descriptor_sets } fn load_mesh( - device: &ash::Device, - allocator: &MemoryAllocator, + instance: &VulkanInstance, + // bind_group: Vec, TODO name: &str, mesh: &tobj::Mesh, ) -> Mesh3D { @@ -177,8 +162,8 @@ impl OBJLoader { .collect::>(); Mesh3D::new( - device, - allocator, + &instance.device, + &instance.memory_allocator, &vertices, &mesh.indices, None, // TODO diff --git a/crates/vent-rendering/src/instance.rs b/crates/vent-rendering/src/instance.rs index ccb3ce3..d43d2f4 100644 --- a/crates/vent-rendering/src/instance.rs +++ b/crates/vent-rendering/src/instance.rs @@ -70,7 +70,6 @@ pub struct VulkanInstance { pub descriptor_pool: vk::DescriptorPool, pub descriptor_set_layout: vk::DescriptorSetLayout, - pub descriptor_sets: Vec, pub render_pass: vk::RenderPass, pub command_pool: vk::CommandPool, @@ -203,12 +202,6 @@ impl VulkanInstance { let descriptor_pool = Self::create_descriptor_pool(&device); let descriptor_set_layout = Self::create_descriptor_set_layout(&device); - let descriptor_sets = Self::allocate_descriptor_sets( - &device, - descriptor_pool, - descriptor_set_layout, - &swapchain_images, - ); Self { memory_allocator, @@ -227,7 +220,6 @@ impl VulkanInstance { debug_utils: debug_utils_loader, descriptor_pool, descriptor_set_layout, - descriptor_sets, debug_messenger, depth_image, frame_buffers, @@ -626,7 +618,7 @@ impl VulkanInstance { unsafe { device.create_descriptor_pool(&create_info, None) }.unwrap() } - fn allocate_descriptor_sets( + pub fn allocate_descriptor_sets( device: &ash::Device, descriptor_pool: vk::DescriptorPool, descriptor_set_layout: vk::DescriptorSetLayout, diff --git a/crates/vent-runtime/src/render/model_renderer.rs b/crates/vent-runtime/src/render/model_renderer.rs index 277bd0b..fdf38d6 100644 --- a/crates/vent-runtime/src/render/model_renderer.rs +++ b/crates/vent-runtime/src/render/model_renderer.rs @@ -45,7 +45,7 @@ impl ModelRenderer3D { self.map.iter_mut() } - pub fn render<'rp>(&'rp self, rpass: &mut wgpu::RenderPass<'rp>, ubo: &mut UBO3D) { + pub fn render(, ubo: &mut UBO3D) { for model in self.map.values() { ubo.transformation = Self::calc_trans_matrix(model).to_cols_array_2d(); model.rendering_model.draw(rpass); From 469d93cb7630f73a5817d672a549328e75f21495 Mon Sep 17 00:00:00 2001 From: Snowiiii <71594357+Snowiiii@users.noreply.github.com> Date: Tue, 31 Oct 2023 21:01:33 +0100 Subject: [PATCH 04/14] Fixed All Compile Errors --- Cargo.lock | 1735 +++++++++-------- crates/vent-assets/src/model/gltf.rs | 24 +- crates/vent-assets/src/model/mod.rs | 2 +- crates/vent-assets/src/model/obj.rs | 27 +- crates/vent-common/Cargo.toml | 3 +- crates/vent-common/src/window.rs | 2 +- crates/vent-ecs/Cargo.toml | 2 +- crates/vent-editor/Cargo.toml | 11 +- .../assets/textures/icon/icon256.png | Bin 6783 -> 0 bytes .../assets/textures/icon/icon64.png | Bin 905 -> 0 bytes crates/vent-editor/src/gui/mod.rs | 14 +- crates/vent-editor/src/main.rs | 84 +- crates/vent-editor/src/render/mod.rs | 79 +- .../src/render/runtime_renderer.rs | 72 +- crates/vent-rendering/Cargo.toml | 5 +- crates/vent-rendering/src/instance.rs | 35 +- crates/vent-rendering/src/lib.rs | 1 + crates/vent-rendering/src/surface.rs | 147 ++ crates/vent-runtime/Cargo.toml | 13 +- crates/vent-runtime/src/lib.rs | 87 +- .../src/render/camera/camera_controller3d.rs | 70 +- crates/vent-runtime/src/render/d2/mod.rs | 20 +- .../src/render/d3/light_renderer.rs | 200 +- crates/vent-runtime/src/render/d3/mod.rs | 530 ++--- .../vent-runtime/src/render/gui/debug_gui.rs | 23 +- .../src/render/gui/gui_renderer.rs | 144 +- crates/vent-runtime/src/render/mod.rs | 81 +- .../vent-runtime/src/render/model_renderer.rs | 15 +- 28 files changed, 1764 insertions(+), 1662 deletions(-) delete mode 100644 crates/vent-editor/assets/textures/icon/icon256.png delete mode 100644 crates/vent-editor/assets/textures/icon/icon64.png create mode 100644 crates/vent-rendering/src/surface.rs diff --git a/Cargo.lock b/Cargo.lock index 99983b0..864c144 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,15 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + [[package]] name = "adler" version = "1.0.2" @@ -37,30 +46,42 @@ dependencies = [ ] [[package]] -name = "aho-corasick" -version = "1.1.1" +name = "android-activity" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" +checksum = "64529721f27c2314ced0890ce45e469574a73e5e6fdd6e9da1860eb29285f5e0" dependencies = [ - "memchr", + "android-properties", + "bitflags 1.3.2", + "cc", + "jni-sys", + "libc", + "log", + "ndk 0.7.0", + "ndk-context", + "ndk-sys 0.4.1+23.1.7779620", + "num_enum 0.6.1", ] [[package]] name = "android-activity" -version = "0.4.3" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64529721f27c2314ced0890ce45e469574a73e5e6fdd6e9da1860eb29285f5e0" +checksum = "052ad56e336bcc615a214bffbeca6c181ee9550acec193f0327e0b103b033a4d" dependencies = [ "android-properties", - "bitflags 1.3.2", + "bitflags 2.4.0", "cc", + "cesu8", + "jni", "jni-sys", "libc", "log", - "ndk", + "ndk 0.8.0", "ndk-context", - "ndk-sys", - "num_enum 0.6.1", + "ndk-sys 0.5.0+25.2.9519653", + "num_enum 0.7.1", + "thiserror", ] [[package]] @@ -91,231 +112,45 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" [[package]] -name = "arrayref" -version = "0.3.7" +name = "arboard" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" - -[[package]] -name = "arrayvec" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" - -[[package]] -name = "ash" -version = "0.37.3+1.3.251" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e9c3835d686b0a6084ab4234fcd1b07dbf6e4767dce60874b12356a25ecd4a" - -[[package]] -name = "ash-window" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b912285a7c29f3a8f87ca6f55afc48768624e5e33ec17dbd2f2075903f5e35ab" -dependencies = [ - "ash", - "raw-window-handle", - "raw-window-metal", -] - -[[package]] -name = "ashpd" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3affe251686bd936a0afb74b9693e8bf2f193d51da1b9a45d3f1303a9bd2cc7" +checksum = "ac57f2b058a76363e357c056e4f74f1945bf734d37b8b3ef49066c4787dde0fc" dependencies = [ - "async-std", - "enumflags2", - "futures-channel", - "futures-util", - "once_cell", - "rand", - "serde", - "serde_repr", - "url", - "zbus", -] - -[[package]] -name = "async-broadcast" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c48ccdbf6ca6b121e0f586cbc0e73ae440e56c67c30fa0873b4e110d9c26d2b" -dependencies = [ - "event-listener 2.5.3", - "futures-core", -] - -[[package]] -name = "async-channel" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" -dependencies = [ - "concurrent-queue", - "event-listener 2.5.3", - "futures-core", -] - -[[package]] -name = "async-executor" -version = "1.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c1da3ae8dabd9c00f453a329dfe1fb28da3c0a72e2478cdcd93171740c20499" -dependencies = [ - "async-lock", - "async-task", - "concurrent-queue", - "fastrand 2.0.1", - "futures-lite", - "slab", -] - -[[package]] -name = "async-fs" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "279cf904654eeebfa37ac9bb1598880884924aab82e290aa65c9e77a0e142e06" -dependencies = [ - "async-lock", - "autocfg", - "blocking", - "futures-lite", -] - -[[package]] -name = "async-global-executor" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1b6f5d7df27bd294849f8eec66ecfc63d11814df7a4f5d74168a2394467b776" -dependencies = [ - "async-channel", - "async-executor", - "async-io", - "async-lock", - "blocking", - "futures-lite", - "once_cell", -] - -[[package]] -name = "async-io" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" -dependencies = [ - "async-lock", - "autocfg", - "cfg-if", - "concurrent-queue", - "futures-lite", + "clipboard-win", "log", - "parking", - "polling", - "rustix 0.37.24", - "slab", - "socket2", - "waker-fn", -] - -[[package]] -name = "async-lock" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" -dependencies = [ - "event-listener 2.5.3", -] - -[[package]] -name = "async-process" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6438ba0a08d81529c69b36700fa2f95837bfe3e776ab39cde9c14d9149da88" -dependencies = [ - "async-io", - "async-lock", - "async-signal", - "blocking", - "cfg-if", - "event-listener 3.0.0", - "futures-lite", - "rustix 0.38.18", - "windows-sys 0.48.0", -] - -[[package]] -name = "async-recursion" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", + "objc", + "objc-foundation", + "objc_id", + "parking_lot", + "thiserror", + "winapi", + "x11rb 0.10.1", ] [[package]] -name = "async-signal" -version = "0.2.3" +name = "arrayref" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1079d27511f6c038736279421774ef4ad4bdd2e300825f4a48c4cc463a57cedf" -dependencies = [ - "async-io", - "async-lock", - "atomic-waker", - "cfg-if", - "futures-core", - "futures-io", - "rustix 0.38.18", - "signal-hook-registry", - "slab", - "windows-sys 0.48.0", -] +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" [[package]] -name = "async-std" -version = "1.12.0" +name = "arrayvec" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" -dependencies = [ - "async-channel", - "async-global-executor", - "async-io", - "async-lock", - "crossbeam-utils", - "futures-channel", - "futures-core", - "futures-io", - "futures-lite", - "gloo-timers", - "kv-log-macro", - "log", - "memchr", - "once_cell", - "pin-project-lite", - "pin-utils", - "slab", - "wasm-bindgen-futures", -] +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] -name = "async-task" -version = "4.4.1" +name = "as-raw-xcb-connection" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9441c6b2fe128a7c2bf680a44c34d0df31ce09e5b7e401fcca3faa483dbc921" +checksum = "2d5f312b0a56c5cdf967c0aeb67f6289603354951683bc97ddc595ab974ba9aa" [[package]] -name = "async-trait" -version = "0.1.73" +name = "ash" +version = "0.37.3+1.3.251" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] +checksum = "39e9c3835d686b0a6084ab4234fcd1b07dbf6e4767dce60874b12356a25ecd4a" [[package]] name = "atomic-waker" @@ -329,6 +164,21 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base64" version = "0.13.1" @@ -360,21 +210,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] -name = "block-buffer" -version = "0.10.4" +name = "block-sys" +version = "0.1.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +checksum = "0fa55741ee90902547802152aaf3f8e5248aab7e21468089560d4c8840561146" dependencies = [ - "generic-array", + "objc-sys 0.2.0-beta.2", ] [[package]] name = "block-sys" -version = "0.1.0-beta.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa55741ee90902547802152aaf3f8e5248aab7e21468089560d4c8840561146" +checksum = "2dd7cf50912cddc06dc5ea7c08c5e81c1b2c842a70d19def1848d54c586fed92" dependencies = [ - "objc-sys", + "objc-sys 0.3.1", ] [[package]] @@ -383,24 +233,18 @@ version = "0.2.0-alpha.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8dd9e63c1744f755c2f60332b88de39d341e5e86239014ad839bd71c106dec42" dependencies = [ - "block-sys", - "objc2-encode", + "block-sys 0.1.0-beta.1", + "objc2-encode 2.0.0-pre.2", ] [[package]] -name = "blocking" -version = "1.4.1" +name = "block2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c36a4d0d48574b3dd360b4b7d95cc651d2b6557b6402848a27d4b228a473e2a" +checksum = "15b55663a85f33501257357e6421bb33e769d5c9ffb5ba0921c975a123e35e68" dependencies = [ - "async-channel", - "async-lock", - "async-task", - "fastrand 2.0.1", - "futures-io", - "futures-lite", - "piper", - "tracing", + "block-sys 0.2.0", + "objc2 0.4.1", ] [[package]] @@ -435,6 +279,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" + [[package]] name = "calloop" version = "0.10.6" @@ -449,6 +299,32 @@ dependencies = [ "vec_map", ] +[[package]] +name = "calloop" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b50b5a44d59a98c55a9eeb518f39bf7499ba19fd98ee7d22618687f3f10adbf" +dependencies = [ + "bitflags 2.4.0", + "log", + "polling", + "rustix", + "slab", + "thiserror", +] + +[[package]] +name = "calloop-wayland-source" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f0ea9b9476c7fad82841a8dbb380e2eae480c21910feba80725b46931ed8f02" +dependencies = [ + "calloop 0.12.3", + "rustix", + "wayland-backend", + "wayland-client 0.31.1", +] + [[package]] name = "cc" version = "1.0.83" @@ -459,6 +335,12 @@ dependencies = [ "libc", ] +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cfg-if" version = "1.0.0" @@ -486,33 +368,14 @@ dependencies = [ ] [[package]] -name = "cocoa" -version = "0.24.1" +name = "clipboard-win" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f425db7937052c684daec3bd6375c8abe2d146dca4b8b143d6db777c39138f3a" +checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362" dependencies = [ - "bitflags 1.3.2", - "block", - "cocoa-foundation", - "core-foundation", - "core-graphics", - "foreign-types", - "libc", - "objc", -] - -[[package]] -name = "cocoa-foundation" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c6234cbb2e4c785b456c0644748b1ac416dd045799740356f8363dfe00c93f7" -dependencies = [ - "bitflags 1.3.2", - "block", - "core-foundation", - "core-graphics-types", - "libc", - "objc", + "error-code", + "str-buf", + "winapi", ] [[package]] @@ -532,6 +395,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "combine" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "concurrent-queue" version = "2.3.0" @@ -586,27 +459,31 @@ dependencies = [ "bitflags 1.3.2", "core-foundation", "core-graphics-types", - "foreign-types", + "foreign-types 0.3.2", "libc", ] [[package]] -name = "core-graphics-types" -version = "0.1.2" +name = "core-graphics" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33" +checksum = "970a29baf4110c26fedbc7f82107d42c23f7e88e404c4577ed73fe99ff85a212" dependencies = [ "bitflags 1.3.2", "core-foundation", + "core-graphics-types", + "foreign-types 0.5.0", "libc", ] [[package]] -name = "cpufeatures" -version = "0.2.9" +name = "core-graphics-types" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33" dependencies = [ + "bitflags 1.3.2", + "core-foundation", "libc", ] @@ -659,14 +536,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] -name = "crypto-common" -version = "0.1.6" +name = "cursor-icon" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] +checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf" [[package]] name = "deranged" @@ -675,46 +548,94 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" [[package]] -name = "derivative" -version = "2.2.0" +name = "dispatch" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" + +[[package]] +name = "dlib" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", + "libloading 0.8.1", ] [[package]] -name = "digest" -version = "0.10.7" +name = "downcast-rs" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" + +[[package]] +name = "duplicate" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de78e66ac9061e030587b2a2e75cc88f22304913c907b11307bca737141230cb" dependencies = [ - "block-buffer", - "crypto-common", + "heck", + "proc-macro-error", ] [[package]] -name = "dispatch" -version = "0.2.0" +name = "ecolor" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" +checksum = "cfdf4e52dbbb615cfd30cf5a5265335c217b5fd8d669593cea74a517d9c605af" [[package]] -name = "dlib" -version = "0.5.2" +name = "egui" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" +checksum = "8bd69fed5fcf4fbb8225b24e80ea6193b61e17a625db105ef0c4d71dde6eb8b7" dependencies = [ - "libloading", + "ahash", + "epaint", + "log", + "nohash-hasher", ] [[package]] -name = "downcast-rs" -version = "1.2.0" +name = "egui-winit" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +checksum = "c15479a96d9fadccf5dac690bdc6373b97b8e1c0dd28367058f25a5298da0195" +dependencies = [ + "arboard", + "egui", + "log", + "raw-window-handle 0.5.2", + "smithay-clipboard", + "web-time", + "webbrowser", + "winit 0.28.7", +] + +[[package]] +name = "egui-winit-ash-integration" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ff65673b6cfcdc14b64ec326862187bd721bb09028667c906b45ceecc53fcf2" +dependencies = [ + "anyhow", + "ash", + "bytemuck", + "egui", + "egui-winit", + "gpu-allocator", +] + +[[package]] +name = "egui_dock" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "681b082103898f874b509c0e5ed642c5001ff272bb7adcef32d3d920c26dcf08" +dependencies = [ + "duplicate", + "egui", + "paste", +] [[package]] name = "either" @@ -723,24 +644,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] -name = "enumflags2" -version = "0.7.8" +name = "emath" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5998b4f30320c9d93aed72f63af821bfdac50465b75428fce77b48ec482c3939" -dependencies = [ - "enumflags2_derive", - "serde", -] +checksum = "1ef2b29de53074e575c18b694167ccbe6e5191f7b25fe65175a0d905a32eeec0" [[package]] -name = "enumflags2_derive" -version = "0.7.8" +name = "epaint" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f95e2801cd355d4a1a3e3953ce6ee5ae9603a5c833455343a8bfe3f44d418246" +checksum = "58067b840d009143934d91d8dcb8ded054d8301d7c11a517ace0a99bb1e1595e" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", + "ab_glyph", + "ahash", + "ecolor", + "emath", + "log", + "nohash-hasher", + "parking_lot", ] [[package]] @@ -760,20 +681,13 @@ dependencies = [ ] [[package]] -name = "event-listener" -version = "2.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" - -[[package]] -name = "event-listener" -version = "3.0.0" +name = "error-code" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29e56284f00d94c1bc7fd3c77027b4623c88c1f53d8d2394c6199f2921dea325" +checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21" dependencies = [ - "concurrent-queue", - "parking", - "pin-project-lite", + "libc", + "str-buf", ] [[package]] @@ -792,21 +706,6 @@ dependencies = [ "zune-inflate", ] -[[package]] -name = "fastrand" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - -[[package]] -name = "fastrand" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" - [[package]] name = "fdeflate" version = "0.3.0" @@ -841,114 +740,75 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "foreign-types-shared", + "foreign-types-shared 0.1.1", ] [[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" +name = "foreign-types" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" dependencies = [ - "percent-encoding", + "foreign-types-macros", + "foreign-types-shared 0.3.1", ] [[package]] -name = "fs_extra" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" - -[[package]] -name = "futures-channel" -version = "0.3.28" +name = "foreign-types-macros" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ - "futures-core", + "proc-macro2", + "quote", + "syn 2.0.38", ] [[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-io" -version = "0.3.28" +name = "foreign-types-shared" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] -name = "futures-lite" -version = "1.13.0" +name = "foreign-types-shared" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" -dependencies = [ - "fastrand 1.9.0", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] +checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" [[package]] -name = "futures-macro" -version = "0.3.28" +name = "form_urlencoded" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", + "percent-encoding", ] [[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" +name = "fs_extra" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" [[package]] -name = "futures-util" -version = "0.3.28" +name = "gethostname" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" dependencies = [ - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", + "libc", + "winapi", ] [[package]] -name = "generic-array" -version = "0.14.7" +name = "gethostname" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +checksum = "bb65d4ba3173c56a500b555b532f72c42e8d1fe64962b518897f8959fae2c177" dependencies = [ - "typenum", - "version_check", + "libc", + "winapi", ] [[package]] @@ -973,22 +833,16 @@ dependencies = [ ] [[package]] -name = "glam" -version = "0.24.2" +name = "gimli" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5418c17512bdf42730f9032c74e1ae39afc408745ebb2acf72fbc4691c17945" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] -name = "gloo-timers" -version = "0.2.6" +name = "glam" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" -dependencies = [ - "futures-channel", - "futures-core", - "js-sys", - "wasm-bindgen", -] +checksum = "b5418c17512bdf42730f9032c74e1ae39afc408745ebb2acf72fbc4691c17945" [[package]] name = "gltf" @@ -1028,6 +882,19 @@ dependencies = [ "serde_json", ] +[[package]] +name = "gpu-allocator" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40fe17c8a05d60c38c0a4e5a3c802f2f1ceb66b76c67d96ffb34bef0475a7fad" +dependencies = [ + "ash", + "backtrace", + "log", + "presser", + "thiserror", +] + [[package]] name = "half" version = "2.2.1" @@ -1043,6 +910,12 @@ version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.3.3" @@ -1050,10 +923,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] -name = "hex" -version = "0.4.3" +name = "home" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys 0.48.0", +] [[package]] name = "iana-time-zone" @@ -1078,6 +954,17 @@ dependencies = [ "cc", ] +[[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 = "idna" version = "0.4.0" @@ -1135,17 +1022,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.48.0", -] - [[package]] name = "is-terminal" version = "0.4.9" @@ -1153,7 +1029,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi", - "rustix 0.38.18", + "rustix", "windows-sys 0.48.0", ] @@ -1163,6 +1039,22 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", + "windows-sys 0.45.0", +] + [[package]] name = "jni-sys" version = "0.3.0" @@ -1196,15 +1088,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kv-log-macro" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" -dependencies = [ - "log", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -1225,19 +1108,23 @@ checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libloading" -version = "0.8.1" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ "cfg-if", - "windows-sys 0.48.0", + "winapi", ] [[package]] -name = "linux-raw-sys" -version = "0.3.8" +name = "libloading" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] [[package]] name = "linux-raw-sys" @@ -1260,9 +1147,6 @@ name = "log" version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" -dependencies = [ - "value-bag", -] [[package]] name = "malloc_buf" @@ -1288,6 +1172,15 @@ dependencies = [ "libc", ] +[[package]] +name = "memmap2" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "deaba38d7abf1d4cca21cc89e932e542ba2b9258664d2a9ef0e61512039c9375" +dependencies = [ + "libc", +] + [[package]] name = "memoffset" version = "0.6.5" @@ -1351,9 +1244,24 @@ checksum = "451422b7e4718271c8b5b3aadf5adedba43dc76312454b387e98fae0fc951aa0" dependencies = [ "bitflags 1.3.2", "jni-sys", - "ndk-sys", + "ndk-sys 0.4.1+23.1.7779620", "num_enum 0.5.11", - "raw-window-handle", + "raw-window-handle 0.5.2", + "thiserror", +] + +[[package]] +name = "ndk" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2076a31b7010b17a38c01907c45b945e8f11495ee4dd588309718901b1f7a5b7" +dependencies = [ + "bitflags 2.4.0", + "jni-sys", + "log", + "ndk-sys 0.5.0+25.2.9519653", + "num_enum 0.7.1", + "raw-window-handle 0.6.0", "thiserror", ] @@ -1372,6 +1280,15 @@ dependencies = [ "jni-sys", ] +[[package]] +name = "ndk-sys" +version = "0.5.0+25.2.9519653" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c196769dd60fd4f363e11d948139556a344e79d451aeb2fa2fd040738ef7691" +dependencies = [ + "jni-sys", +] + [[package]] name = "nix" version = "0.24.3" @@ -1409,6 +1326,12 @@ dependencies = [ "memoffset 0.7.1", ] +[[package]] +name = "nohash-hasher" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" + [[package]] name = "nom" version = "7.1.3" @@ -1476,6 +1399,15 @@ dependencies = [ "num_enum_derive 0.6.1", ] +[[package]] +name = "num_enum" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683751d591e6d81200c39fb0d1032608b77724f34114db54f571ff1317b337c0" +dependencies = [ + "num_enum_derive 0.7.1", +] + [[package]] name = "num_enum_derive" version = "0.5.11" @@ -1500,6 +1432,18 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "num_enum_derive" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c11e44798ad209ccdd91fc192f0526a369a01234f7373e1b141c96d7cee4f0e" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "num_threads" version = "0.1.6" @@ -1535,15 +1479,31 @@ version = "0.2.0-beta.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b9834c1e95694a05a828b59f55fa2afec6288359cda67146126b3f90a55d7" +[[package]] +name = "objc-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99e1d07c6eab1ce8b6382b8e3c7246fe117ff3f8b34be065f5ebace6749fe845" + [[package]] name = "objc2" version = "0.3.0-beta.3.patch-leaks.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e01640f9f2cb1220bbe80325e179e532cb3379ebcd1bf2279d703c19fe3a468" dependencies = [ - "block2", - "objc-sys", - "objc2-encode", + "block2 0.2.0-alpha.6", + "objc-sys 0.2.0-beta.2", + "objc2-encode 2.0.0-pre.2", +] + +[[package]] +name = "objc2" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "559c5a40fdd30eb5e344fbceacf7595a81e242529fb4e21cf5f43fb4f11ff98d" +dependencies = [ + "objc-sys 0.3.1", + "objc2-encode 3.0.0", ] [[package]] @@ -1552,9 +1512,15 @@ version = "2.0.0-pre.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abfcac41015b00a120608fdaa6938c44cb983fee294351cc4bac7638b4e50512" dependencies = [ - "objc-sys", + "objc-sys 0.2.0-beta.2", ] +[[package]] +name = "objc2-encode" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d079845b37af429bfe5dfa76e6d087d788031045b25cfc6fd898486fd9847666" + [[package]] name = "objc_id" version = "0.1.1" @@ -1564,6 +1530,15 @@ dependencies = [ "objc", ] +[[package]] +name = "object" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.18.0" @@ -1576,33 +1551,46 @@ version = "0.3.46" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8378ac0dfbd4e7895f2d2c1f1345cab3836910baf3a300b000d04250f0c8428f" dependencies = [ - "redox_syscall", + "redox_syscall 0.3.5", ] [[package]] -name = "ordered-stream" -version = "0.2.0" +name = "owned_ttf_parser" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aa2b01e1d916879f73a53d01d1d6cee68adbb31d6d9177a8cfce093cced1d50" +checksum = "706de7e2214113d63a8238d1910463cfce781129a6f263d13fdb09ff64355ba4" dependencies = [ - "futures-core", - "pin-project-lite", + "ttf-parser", ] [[package]] -name = "owned_ttf_parser" -version = "0.19.0" +name = "parking_lot" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "706de7e2214113d63a8238d1910463cfce781129a6f263d13fdb09ff64355ba4" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ - "ttf-parser", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.4.1", + "smallvec", + "windows-targets 0.48.5", ] [[package]] -name = "parking" -version = "2.1.1" +name = "paste" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e52c774a4c39359c1d1c52e43f73dd91a75a614652c825408eec30c95a9b2067" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "percent-encoding" @@ -1616,23 +1604,6 @@ version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "piper" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" -dependencies = [ - "atomic-waker", - "fastrand 2.0.1", - "futures-io", -] - [[package]] name = "pkg-config" version = "0.3.27" @@ -1654,17 +1625,15 @@ dependencies = [ [[package]] name = "polling" -version = "2.8.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +checksum = "e53b6af1f60f36f8c2ac2aad5459d75a5a9b4be1e8cdd40264f315d78193e531" dependencies = [ - "autocfg", - "bitflags 1.3.2", "cfg-if", "concurrent-queue", - "libc", - "log", "pin-project-lite", + "rustix", + "tracing", "windows-sys 0.48.0", ] @@ -1675,10 +1644,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2" [[package]] -name = "ppv-lite86" -version = "0.2.17" +name = "presser" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" [[package]] name = "proc-macro-crate" @@ -1691,60 +1660,63 @@ dependencies = [ ] [[package]] -name = "proc-macro2" -version = "1.0.69" +name = "proc-macro-error" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ - "unicode-ident", + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", ] [[package]] -name = "qoi" -version = "0.4.1" +name = "proc-macro-error-attr" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "bytemuck", + "proc-macro2", + "quote", + "version_check", ] [[package]] -name = "quote" -version = "1.0.33" +name = "proc-macro2" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ - "proc-macro2", + "unicode-ident", ] [[package]] -name = "rand" -version = "0.8.5" +name = "qoi" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" dependencies = [ - "libc", - "rand_chacha", - "rand_core", + "bytemuck", ] [[package]] -name = "rand_chacha" -version = "0.3.1" +name = "quick-xml" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +checksum = "eff6510e86862b57b210fd8cbe8ed3f0d7d600b9c2863cd4549a2e033c66e956" dependencies = [ - "ppv-lite86", - "rand_core", + "memchr", ] [[package]] -name = "rand_core" -version = "0.6.4" +name = "quote" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ - "getrandom", + "proc-macro2", ] [[package]] @@ -1754,16 +1726,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" [[package]] -name = "raw-window-metal" -version = "0.3.1" +name = "raw-window-handle" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed91094d30089fc273de843cfef783f8c04cc75828277a64e0e8dc2a0cebd4dc" -dependencies = [ - "cocoa", - "core-graphics", - "objc", - "raw-window-handle", -] +checksum = "42a9830a0e1b9fb145ebb365b8bc4ccd75f290f98c0247deafbbe2c75cefb544" [[package]] name = "rayon" @@ -1795,57 +1761,12 @@ dependencies = [ ] [[package]] -name = "regex" -version = "1.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" - -[[package]] -name = "rfd" -version = "0.12.0" +name = "redox_syscall" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "241a0deb168c88050d872294f7b3106c1dfa8740942bcc97bc91b98e97b5c501" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "ashpd", - "async-io", - "block", - "dispatch", - "futures-util", - "js-sys", - "log", - "objc", - "objc-foundation", - "objc_id", - "pollster", - "raw-window-handle", - "urlencoding", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "windows-sys 0.48.0", + "bitflags 1.3.2", ] [[package]] @@ -1857,18 +1778,10 @@ dependencies = [ ] [[package]] -name = "rustix" -version = "0.37.24" +name = "rustc-demangle" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4279d76516df406a8bd37e7dff53fd37d1a093f997a3c34a5c21658c126db06d" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys 0.48.0", -] +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" @@ -1879,7 +1792,7 @@ dependencies = [ "bitflags 2.4.0", "errno", "libc", - "linux-raw-sys 0.4.10", + "linux-raw-sys", "windows-sys 0.48.0", ] @@ -1889,6 +1802,15 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scoped-tls" version = "1.0.1" @@ -1909,9 +1831,22 @@ checksum = "cda4e97be1fd174ccc2aae81c8b694e803fa99b34e8fd0f057a9d70698e3ed09" dependencies = [ "ab_glyph", "log", - "memmap2", - "smithay-client-toolkit", - "tiny-skia", + "memmap2 0.5.10", + "smithay-client-toolkit 0.16.1", + "tiny-skia 0.8.4", +] + +[[package]] +name = "sctk-adwaita" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729a30a469de249c6effc17ec8d039b0aa29b3af79b819b7f51cb6ab8046a90" +dependencies = [ + "ab_glyph", + "log", + "memmap2 0.9.0", + "smithay-client-toolkit 0.18.0", + "tiny-skia 0.11.2", ] [[package]] @@ -1945,37 +1880,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_repr" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "sha1" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - [[package]] name = "simd-adler32" version = "0.3.7" @@ -2025,26 +1929,60 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "870427e30b8f2cbe64bf43ec4b86e88fe39b0a84b3f15efd9c9c2d020bc86eb9" dependencies = [ "bitflags 1.3.2", - "calloop", + "calloop 0.10.6", "dlib", "lazy_static", "log", - "memmap2", + "memmap2 0.5.10", "nix 0.24.3", "pkg-config", - "wayland-client", - "wayland-cursor", - "wayland-protocols", + "wayland-client 0.29.5", + "wayland-cursor 0.29.5", + "wayland-protocols 0.29.5", ] [[package]] -name = "socket2" -version = "0.4.9" +name = "smithay-client-toolkit" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +checksum = "60e3d9941fa3bacf7c2bf4b065304faa14164151254cd16ce1b1bc8fc381600f" dependencies = [ + "bitflags 2.4.0", + "calloop 0.12.3", + "calloop-wayland-source", + "cursor-icon", "libc", - "winapi", + "log", + "memmap2 0.9.0", + "rustix", + "thiserror", + "wayland-backend", + "wayland-client 0.31.1", + "wayland-csd-frame", + "wayland-cursor 0.31.0", + "wayland-protocols 0.31.0", + "wayland-protocols-wlr", + "wayland-scanner 0.31.0", + "xkeysym", +] + +[[package]] +name = "smithay-clipboard" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a345c870a1fae0b1b779085e81b51e614767c239e93503588e54c5b17f4b0e8" +dependencies = [ + "smithay-client-toolkit 0.16.1", + "wayland-client 0.29.5", +] + +[[package]] +name = "smol_str" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74212e6bbe9a4352329b2f68ba3130c15a3f26fe88ff22dbdc6cdd58fa85e99c" +dependencies = [ + "serde", ] [[package]] @@ -2057,10 +1995,10 @@ dependencies = [ ] [[package]] -name = "static_assertions" -version = "1.1.0" +name = "str-buf" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" [[package]] name = "strict-num" @@ -2098,24 +2036,11 @@ checksum = "0a18d114d420ada3a891e6bc8e96a2023402203296a47cdd65083377dad18ba5" dependencies = [ "cfg-if", "core-foundation-sys", - "libc", - "ntapi", - "once_cell", - "rayon", - "winapi", -] - -[[package]] -name = "tempfile" -version = "3.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" -dependencies = [ - "cfg-if", - "fastrand 2.0.1", - "redox_syscall", - "rustix 0.38.18", - "windows-sys 0.48.0", + "libc", + "ntapi", + "once_cell", + "rayon", + "winapi", ] [[package]] @@ -2190,7 +2115,21 @@ dependencies = [ "bytemuck", "cfg-if", "png", - "tiny-skia-path", + "tiny-skia-path 0.8.4", +] + +[[package]] +name = "tiny-skia" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b72a92a05db376db09fe6d50b7948d106011761c05a6a45e23e17ee9b556222" +dependencies = [ + "arrayref", + "arrayvec", + "bytemuck", + "cfg-if", + "log", + "tiny-skia-path 0.11.2", ] [[package]] @@ -2204,6 +2143,17 @@ dependencies = [ "strict-num", ] +[[package]] +name = "tiny-skia-path" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ac3865b9708fc7e1961a65c3a4fa55e984272f33092d3c859929f887fceb647" +dependencies = [ + "arrayref", + "bytemuck", + "strict-num", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -2253,29 +2203,14 @@ checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if", "pin-project-lite", - "tracing-attributes", "tracing-core", ] -[[package]] -name = "tracing-attributes" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - [[package]] name = "tracing-core" version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" -dependencies = [ - "once_cell", -] [[package]] name = "ttf-parser" @@ -2283,22 +2218,6 @@ version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49d64318d8311fc2668e48b63969f4343e0a85c4a109aa8460d6672e364b8bd1" -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "uds_windows" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce65604324d3cce9b966701489fbd0cf318cb1f7bd9dd07ac9a4ee6fb791930d" -dependencies = [ - "tempfile", - "winapi", -] - [[package]] name = "unicode-bidi" version = "0.3.13" @@ -2320,6 +2239,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + [[package]] name = "url" version = "2.4.1" @@ -2329,7 +2254,6 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", - "serde", ] [[package]] @@ -2338,12 +2262,6 @@ version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" -[[package]] -name = "value-bag" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d92ccd67fb88503048c01b59152a04effd0782d035a83a6d256ce6085f08f4a3" - [[package]] name = "vec_map" version = "0.8.2" @@ -2380,28 +2298,30 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winit", + "winit 0.29.3", ] [[package]] name = "vent-ecs" version = "0.1.0" dependencies = [ - "winit", + "winit 0.29.3", ] [[package]] name = "vent-editor" version = "0.1.0" dependencies = [ + "ash", + "egui", + "egui_dock", "log", "pollster", - "rfd", "simple_logger", "vent-common", "vent-rendering", "vent-runtime", - "winit", + "winit 0.29.3", ] [[package]] @@ -2409,11 +2329,10 @@ name = "vent-rendering" version = "0.1.0" dependencies = [ "ash", - "ash-window", "bytemuck", "image", - "raw-window-handle", - "winit", + "raw-window-handle 0.6.0", + "winit 0.29.3", ] [[package]] @@ -2421,8 +2340,12 @@ name = "vent-runtime" version = "0.1.0" dependencies = [ "anyhow", + "ash", "bytemuck", "downcast-rs", + "egui", + "egui-winit", + "egui-winit-ash-integration", "fs_extra", "glam", "log", @@ -2432,7 +2355,7 @@ dependencies = [ "vent-common", "vent-ecs", "vent-rendering", - "winit", + "winit 0.29.3", ] [[package]] @@ -2446,10 +2369,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] -name = "waker-fn" -version = "1.1.1" +name = "walkdir" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +dependencies = [ + "same-file", + "winapi-util", +] [[package]] name = "wasi" @@ -2523,6 +2450,20 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +[[package]] +name = "wayland-backend" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19152ddd73f45f024ed4534d9ca2594e0ef252c1847695255dae47f34df9fbe4" +dependencies = [ + "cc", + "downcast-rs", + "nix 0.26.4", + "scoped-tls", + "smallvec", + "wayland-sys 0.31.1", +] + [[package]] name = "wayland-client" version = "0.29.5" @@ -2535,8 +2476,20 @@ dependencies = [ "nix 0.24.3", "scoped-tls", "wayland-commons", - "wayland-scanner", - "wayland-sys", + "wayland-scanner 0.29.5", + "wayland-sys 0.29.5", +] + +[[package]] +name = "wayland-client" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ca7d52347346f5473bf2f56705f360e8440873052e575e55890c4fa57843ed3" +dependencies = [ + "bitflags 2.4.0", + "nix 0.26.4", + "wayland-backend", + "wayland-scanner 0.31.0", ] [[package]] @@ -2548,7 +2501,18 @@ dependencies = [ "nix 0.24.3", "once_cell", "smallvec", - "wayland-sys", + "wayland-sys 0.29.5", +] + +[[package]] +name = "wayland-csd-frame" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e" +dependencies = [ + "bitflags 2.4.0", + "cursor-icon", + "wayland-backend", ] [[package]] @@ -2558,7 +2522,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6865c6b66f13d6257bef1cd40cbfe8ef2f150fb8ebbdb1e8e873455931377661" dependencies = [ "nix 0.24.3", - "wayland-client", + "wayland-client 0.29.5", + "xcursor", +] + +[[package]] +name = "wayland-cursor" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44aa20ae986659d6c77d64d808a046996a932aa763913864dc40c359ef7ad5b" +dependencies = [ + "nix 0.26.4", + "wayland-client 0.31.1", "xcursor", ] @@ -2569,9 +2544,47 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b950621f9354b322ee817a23474e479b34be96c2e909c14f7bc0100e9a970bc6" dependencies = [ "bitflags 1.3.2", - "wayland-client", + "wayland-client 0.29.5", "wayland-commons", - "wayland-scanner", + "wayland-scanner 0.29.5", +] + +[[package]] +name = "wayland-protocols" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e253d7107ba913923dc253967f35e8561a3c65f914543e46843c88ddd729e21c" +dependencies = [ + "bitflags 2.4.0", + "wayland-backend", + "wayland-client 0.31.1", + "wayland-scanner 0.31.0", +] + +[[package]] +name = "wayland-protocols-plasma" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23803551115ff9ea9bce586860c5c5a971e360825a0309264102a9495a5ff479" +dependencies = [ + "bitflags 2.4.0", + "wayland-backend", + "wayland-client 0.31.1", + "wayland-protocols 0.31.0", + "wayland-scanner 0.31.0", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" +dependencies = [ + "bitflags 2.4.0", + "wayland-backend", + "wayland-client 0.31.1", + "wayland-protocols 0.31.0", + "wayland-scanner 0.31.0", ] [[package]] @@ -2585,6 +2598,17 @@ dependencies = [ "xml-rs", ] +[[package]] +name = "wayland-scanner" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb8e28403665c9f9513202b7e1ed71ec56fde5c107816843fb14057910b2c09c" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + [[package]] name = "wayland-sys" version = "0.29.5" @@ -2596,6 +2620,18 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "wayland-sys" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a0c8eaff5216d07f226cb7a549159267f3467b289d9a2e52fd3ef5aae2b7af" +dependencies = [ + "dlib", + "log", + "once_cell", + "pkg-config", +] + [[package]] name = "web-sys" version = "0.3.64" @@ -2606,6 +2642,33 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57099a701fb3a8043f993e8228dc24229c7b942e2b009a1b962e54489ba1d3bf" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webbrowser" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82b2391658b02c27719fc5a0a73d6e696285138e8b12fba9d4baa70451023c71" +dependencies = [ + "core-foundation", + "home", + "jni", + "log", + "ndk-context", + "objc", + "raw-window-handle 0.5.2", + "url", + "web-sys", +] + [[package]] name = "weezl" version = "0.1.7" @@ -2628,6 +2691,24 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-wsapoll" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -2796,35 +2877,83 @@ version = "0.28.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9596d90b45384f5281384ab204224876e8e8bf7d58366d9b795ad99aa9894b94" dependencies = [ - "android-activity", + "android-activity 0.4.3", "bitflags 1.3.2", "cfg_aliases", "core-foundation", - "core-graphics", + "core-graphics 0.22.3", "dispatch", "instant", "libc", "log", "mio", - "ndk", - "objc2", + "ndk 0.7.0", + "objc2 0.3.0-beta.3.patch-leaks.3", "once_cell", "orbclient", "percent-encoding", - "raw-window-handle", - "redox_syscall", - "sctk-adwaita", - "smithay-client-toolkit", + "raw-window-handle 0.5.2", + "redox_syscall 0.3.5", + "sctk-adwaita 0.5.4", + "smithay-client-toolkit 0.16.1", "wasm-bindgen", - "wayland-client", + "wayland-client 0.29.5", "wayland-commons", - "wayland-protocols", - "wayland-scanner", + "wayland-protocols 0.29.5", + "wayland-scanner 0.29.5", "web-sys", "windows-sys 0.45.0", "x11-dl", ] +[[package]] +name = "winit" +version = "0.29.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "161598019a9da35ab6c34dc46cd13546cba9dbf9816475d4dd9a639455016563" +dependencies = [ + "ahash", + "android-activity 0.5.0", + "atomic-waker", + "bitflags 2.4.0", + "bytemuck", + "calloop 0.12.3", + "cfg_aliases", + "core-foundation", + "core-graphics 0.23.1", + "cursor-icon", + "icrate", + "js-sys", + "libc", + "log", + "memmap2 0.9.0", + "ndk 0.8.0", + "ndk-sys 0.5.0+25.2.9519653", + "objc2 0.4.1", + "once_cell", + "orbclient", + "percent-encoding", + "raw-window-handle 0.6.0", + "redox_syscall 0.3.5", + "rustix", + "sctk-adwaita 0.7.0", + "smithay-client-toolkit 0.18.0", + "smol_str", + "unicode-segmentation", + "wasm-bindgen", + "wasm-bindgen-futures", + "wayland-backend", + "wayland-client 0.31.1", + "wayland-protocols 0.31.0", + "wayland-protocols-plasma", + "web-sys", + "web-time", + "windows-sys 0.48.0", + "x11-dl", + "x11rb 0.12.0", + "xkbcommon-dl", +] + [[package]] name = "winnow" version = "0.5.16" @@ -2846,140 +2975,92 @@ dependencies = [ ] [[package]] -name = "xcursor" -version = "0.3.4" +name = "x11rb" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" +checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" dependencies = [ - "nom", + "gethostname 0.2.3", + "nix 0.24.3", + "winapi", + "winapi-wsapoll", + "x11rb-protocol 0.10.0", ] [[package]] -name = "xdg-home" -version = "1.0.0" +name = "x11rb" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2769203cd13a0c6015d515be729c526d041e9cf2c0cc478d57faee85f40c6dcd" +checksum = "b1641b26d4dec61337c35a1b1aaf9e3cba8f46f0b43636c609ab0291a648040a" dependencies = [ + "as-raw-xcb-connection", + "gethostname 0.3.0", + "libc", + "libloading 0.7.4", "nix 0.26.4", + "once_cell", "winapi", + "winapi-wsapoll", + "x11rb-protocol 0.12.0", ] [[package]] -name = "xml-rs" -version = "0.8.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" - -[[package]] -name = "zbus" -version = "3.14.1" +name = "x11rb-protocol" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31de390a2d872e4cd04edd71b425e29853f786dc99317ed72d73d6fcf5ebb948" +checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67" dependencies = [ - "async-broadcast", - "async-executor", - "async-fs", - "async-io", - "async-lock", - "async-process", - "async-recursion", - "async-task", - "async-trait", - "blocking", - "byteorder", - "derivative", - "enumflags2", - "event-listener 2.5.3", - "futures-core", - "futures-sink", - "futures-util", - "hex", - "nix 0.26.4", - "once_cell", - "ordered-stream", - "rand", - "serde", - "serde_repr", - "sha1", - "static_assertions", - "tracing", - "uds_windows", - "winapi", - "xdg-home", - "zbus_macros", - "zbus_names", - "zvariant", + "nix 0.24.3", ] [[package]] -name = "zbus_macros" -version = "3.14.1" +name = "x11rb-protocol" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d1794a946878c0e807f55a397187c11fc7a038ba5d868e7db4f3bd7760bc9d" +checksum = "82d6c3f9a0fb6701fab8f6cea9b0c0bd5d6876f1f89f7fada07e558077c344bc" dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "regex", - "syn 1.0.109", - "zvariant_utils", + "nix 0.26.4", ] [[package]] -name = "zbus_names" -version = "2.6.0" +name = "xcursor" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb80bb776dbda6e23d705cf0123c3b95df99c4ebeaec6c2599d4a5419902b4a9" +checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" dependencies = [ - "serde", - "static_assertions", - "zvariant", + "nom", ] [[package]] -name = "zune-inflate" -version = "0.2.54" +name = "xkbcommon-dl" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02" +checksum = "6924668544c48c0133152e7eec86d644a056ca3d09275eb8d5cdb9855f9d8699" dependencies = [ - "simd-adler32", + "bitflags 2.4.0", + "dlib", + "log", + "once_cell", + "xkeysym", ] [[package]] -name = "zvariant" -version = "3.15.0" +name = "xkeysym" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44b291bee0d960c53170780af148dca5fa260a63cdd24f1962fa82e03e53338c" -dependencies = [ - "byteorder", - "enumflags2", - "libc", - "serde", - "static_assertions", - "url", - "zvariant_derive", -] +checksum = "054a8e68b76250b253f671d1268cb7f1ae089ec35e195b2efb2a4e9a836d0621" [[package]] -name = "zvariant_derive" -version = "3.15.0" +name = "xml-rs" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "934d7a7dfc310d6ee06c87ffe88ef4eca7d3e37bb251dece2ef93da8f17d8ecd" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 1.0.109", - "zvariant_utils", -] +checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" [[package]] -name = "zvariant_utils" -version = "1.0.1" +name = "zune-inflate" +version = "0.2.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7234f0d811589db492d16893e3f21e8e2fd282e6d01b0cddee310322062cc200" +checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02" dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", + "simd-adler32", ] diff --git a/crates/vent-assets/src/model/gltf.rs b/crates/vent-assets/src/model/gltf.rs index 6824985..7d87f12 100644 --- a/crates/vent-assets/src/model/gltf.rs +++ b/crates/vent-assets/src/model/gltf.rs @@ -1,12 +1,15 @@ use std::{ fs::{self, File}, io::BufReader, + mem::size_of, path::Path, - sync, thread, mem::size_of, + sync, thread, }; use ash::vk; -use vent_rendering::{image::VulkanImage, instance::VulkanInstance, Vertex3D, buffer::VulkanBuffer}; +use vent_rendering::{ + buffer::VulkanBuffer, image::VulkanImage, instance::VulkanInstance, Vertex3D, +}; use crate::Model3D; @@ -157,10 +160,10 @@ impl GLTFLoader { base_color: pbr.base_color_factor(), }; let buffer_data = bytemuck::bytes_of(&binding); - + let mut uniform_buffers = vec![]; Self::create_uniform_buffers(instance, buffer_data, &mut uniform_buffers); - + Self::write_sets(instance, diffuse_texture, &uniform_buffers) } @@ -181,8 +184,17 @@ impl GLTFLoader { } } - fn write_sets(instance: &VulkanInstance, diffuse_texture: VulkanImage, uniforms_buffers: &Vec) -> Vec { - let descriptor_sets = VulkanInstance::allocate_descriptor_sets(&instance.device, instance.descriptor_pool, instance.descriptor_set_layout, &instance.swapchain_images); + fn write_sets( + instance: &VulkanInstance, + diffuse_texture: VulkanImage, + uniforms_buffers: &Vec, + ) -> Vec { + let descriptor_sets = VulkanInstance::allocate_descriptor_sets( + &instance.device, + instance.descriptor_pool, + instance.descriptor_set_layout, + &instance.swapchain_images, + ); for (i, &_descritptor_set) in descriptor_sets.iter().enumerate() { let image_info = vk::DescriptorImageInfo::builder() diff --git a/crates/vent-assets/src/model/mod.rs b/crates/vent-assets/src/model/mod.rs index f630850..0b704ac 100644 --- a/crates/vent-assets/src/model/mod.rs +++ b/crates/vent-assets/src/model/mod.rs @@ -5,7 +5,7 @@ use ash::vk; use bytemuck::{Pod, Zeroable}; use vent_rendering::allocator::MemoryAllocator; use vent_rendering::buffer::VulkanBuffer; -use vent_rendering::instance::{VulkanInstance}; +use vent_rendering::instance::VulkanInstance; use vent_rendering::Vertex3D; use vent_sdk::utils::stopwatch::Stopwatch; diff --git a/crates/vent-assets/src/model/obj.rs b/crates/vent-assets/src/model/obj.rs index d5d43ce..97ce3f0 100644 --- a/crates/vent-assets/src/model/obj.rs +++ b/crates/vent-assets/src/model/obj.rs @@ -30,13 +30,7 @@ impl OBJLoader { let meshes = models .into_iter() - .map(|model| { - Self::load_mesh( - instance, - &model.name, - &model.mesh, - ) - }) + .map(|model| Self::load_mesh(instance, &model.name, &model.mesh)) .collect::>(); let _descriptor_sets = materials @@ -77,10 +71,10 @@ impl OBJLoader { base_color: [diffuse[0], diffuse[1], diffuse[2], 1.0], }; let buffer_data = bytemuck::bytes_of(&binding); - + let mut uniform_buffers = vec![]; Self::create_uniform_buffers(instance, buffer_data, &mut uniform_buffers); - + Self::write_sets(instance, diffuse_texture, &uniform_buffers) } @@ -101,8 +95,17 @@ impl OBJLoader { } } - fn write_sets(instance: &VulkanInstance, diffuse_texture: VulkanImage, uniforms_buffers: &Vec) -> Vec { - let descriptor_sets = VulkanInstance::allocate_descriptor_sets(&instance.device, instance.descriptor_pool, instance.descriptor_set_layout, &instance.swapchain_images); + fn write_sets( + instance: &VulkanInstance, + diffuse_texture: VulkanImage, + uniforms_buffers: &Vec, + ) -> Vec { + let descriptor_sets = VulkanInstance::allocate_descriptor_sets( + &instance.device, + instance.descriptor_pool, + instance.descriptor_set_layout, + &instance.swapchain_images, + ); for (i, &_descritptor_set) in descriptor_sets.iter().enumerate() { let image_info = vk::DescriptorImageInfo::builder() @@ -141,7 +144,7 @@ impl OBJLoader { fn load_mesh( instance: &VulkanInstance, - // bind_group: Vec, TODO + // bind_group: Vec, TODO name: &str, mesh: &tobj::Mesh, ) -> Mesh3D { diff --git a/crates/vent-common/Cargo.toml b/crates/vent-common/Cargo.toml index da75247..0f0fa47 100644 --- a/crates/vent-common/Cargo.toml +++ b/crates/vent-common/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -winit = "0.28.6" +winit = "0.29.3" sysinfo = "0.29" chrono = "0.4" @@ -22,7 +22,6 @@ serde_json = "1.0" [target.'cfg(target_arch = "wasm32")'.dependencies] console_error_panic_hook = "0.1.7" console_log = "1" -# wgpu = { version = "0.16, 0", features = ["webgl"]} wasm-bindgen = "0.2.87" wasm-bindgen-futures = "0.4.37" web-sys = { version = "0.3.64", features = [ diff --git a/crates/vent-common/src/window.rs b/crates/vent-common/src/window.rs index 8e627b0..e9bc37d 100644 --- a/crates/vent-common/src/window.rs +++ b/crates/vent-common/src/window.rs @@ -6,7 +6,7 @@ pub struct VentWindow { impl VentWindow { #[must_use] pub fn new(builder: winit::window::WindowBuilder) -> Self { - let event_loop = winit::event_loop::EventLoop::new(); + let event_loop = winit::event_loop::EventLoop::new().unwrap(); let window = builder.build(&event_loop).expect("Failed to Create Window"); Self { window, event_loop } diff --git a/crates/vent-ecs/Cargo.toml b/crates/vent-ecs/Cargo.toml index d098b62..e42786f 100644 --- a/crates/vent-ecs/Cargo.toml +++ b/crates/vent-ecs/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -winit = { version = "0.28.6", default-features = false } \ No newline at end of file +winit = { version = "0.29.3", default-features = false } \ No newline at end of file diff --git a/crates/vent-editor/Cargo.toml b/crates/vent-editor/Cargo.toml index 61a7bd4..6a908e2 100644 --- a/crates/vent-editor/Cargo.toml +++ b/crates/vent-editor/Cargo.toml @@ -10,16 +10,19 @@ vent-runtime = { path = "../vent-runtime"} vent-common = { path = "../vent-common"} vent-rendering = { path = "../vent-rendering"} + +ash = { version= "0.37.3", default-features = false, features = ["linked", "debug"] } + # egui -# egui = "0.22.0" -# egui_dock = "0.6.1" +egui = "0.23.0" +egui_dock = "0.8.1" -winit = "0.28.6" +winit = "0.29.3" pollster = "0.3.0" log = "0.4" -rfd = { version="0.12.0", default-features = false, features = ["xdg-portal"]} +# rfd = { version="0.12.1", default-features = false, features = ["xdg-portal"]} [target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies] simple_logger = "4.2.0" diff --git a/crates/vent-editor/assets/textures/icon/icon256.png b/crates/vent-editor/assets/textures/icon/icon256.png deleted file mode 100644 index 0256e39e26d2cff7315bb5e5236ae4193ccb542f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6783 zcmcIp`8U-6|9!q@Gsa*n*<dn`Ucm#*Puf007u6%um_@0R2ZHfQJ7E z0hLbn|AC(EX?qg@gDDn&k<0xAWC?(c9pHF?xEwel1W+vhS%8QH&@hy_`2pye17%Ic zM^hp(G|1Ra=wcqvnXru3&Hn-f85So=_K{zgUDNVr@i?scX?uGZlUXHPc-_CZ z!#C33)Li!KVbilBk#8R}Jjvfy;soX%iKRTh&hNF_GZA;Jd*kz8dGKweO@w)IoSlLq z!l}>@xBxVO5cvO+3^vfTad#saS z&X;ukNf^9X=|$6$q&1FM2*OBm(;RWElcvFp zB$6%Xwq#4&;HSUtV&PMFYg`b`FH5@UebJK9w~42Le#KPp#a*4hs{V@mJJ+YqMd{DN z=9G}LZ<8Sw`d}%M9dYRB$5eRJsi|vtr6;gjm_-_!#*Nc5XW*JsA3lj@Sncgkxe21q z;aamgR|G(xqX2p;4KIaFEgKU~OtAI%khm&-qEl99cW-aE64#`g14p?o2T(FferL2q zOETPt-~P}vt{DUXcY!n$CAd{3fP8?m*Bi7+Y?hM#o(|h;j(G|-`livoOR|@IP5HJg zc;>JnHQ~qDU_$Ves*?_aWR4Pui?Ds3l=D0+AR&L8eVThF)>?fe0}ac7YH7!}bvgPC zt>YrPd1!lkYpDtLHQgj^X+RhE8vx6JF&^ z%7gPHIvYxwFEYd`OaIjs0dZ}toH-1Yo}SUMCtfYM9B-9^bCddj0*WW{9VPP0n=^bE8vWX2D~4j-gGH#b z8x8?*C~q!uBgUp2hHV^3h3FOZgy(?# zO5`08$esxYw3wxrv+Rw*Wn;V{@z*h_2jUndE1ZRWmahoW;F2L5@u5vTl$7wrgIH1D zF)v)K@dR|K+KRrS>45s}L2cg9yFbG4k7!E(8OTGlL!M5jVA%B7DMc^NNbn2^6QT5W zNYS+r+#wUyVR!}pk^xWR!ZUjxm<;Rv{V2@(!b&RASAf`Hc1R!>Q+RR zb`CJ~%~s5=`fg&XAdwFdef&pC!<4^rRtpcm)H?c+SX9~zBy|&vND3(`? zRn!{=#S5}f`&flS`Nv~8Xzg|%Ki<8VdX)Kqi+Zi#kC0;cq=XZ)Kl?)gbnL9}3fk@J zsV)53c#IPY=L4&kuGl3b;j%>-t(B@5(OjTxlmb0Ha!qpPh;n=G0(yq?v^XqquWt-m zY-(OV_~p&QOL34}op-~(uZ{0Q4V0-=M`kMrN0vY{{6VE`U-N)E)rjRvhQ$ND41MdB`i<0wn|Faj#u+(9#MV7$*!mSV`bDtZ#GWcdr zYOD@-$kQ0JUy2wS5E?j(;$E-Vt_%i*zM+%VY?0`PdnKBuO8UfN)sKFKm9nT9HX0fV zms7mrU=;04lIcpdO+o<_W;rv5vQ1L!UDt--SN#>N<1KeIL4oAI4rsY*Y4|Ifs#OqJ zU<6AlQ_VT}6ebRJuU3^4$1M6Ot{h5OJiYPCUPcYkh{Ad2syRT!i!`-$0_ATPVfdpO z!%Hb5CxC4dnSD!|ID+2z0%IcJ9mTRAi4Le294}peZOt}3t!0_$IHFL>@$C1@HUyab zOLG(6(=CJDfb3nzRJOg2jo6W3c8mb5`?p{?Wyh^5GyAk!PN>mCr&z{9J&bFH9Zj}* zzbS7U6u$sfceqbSgLP`vw#Cb~?1iBkGYHT#%I(S1Qh{qf% zEXpaj_eG2L@1z2$Z zRt6rv`6txI@S!8cpj9m4cnF>rR(FRk3XuF<2L>n1AZ{XFTX9+R{>-{DEF`m#lxerv z3>v;DH>Ec5tL$y+G@J}R5q4CJhsfOnSQ4H?iRehSTVJjk0PpXWW%~Ez%o8dxO6Y#$ zZU?P1Fn;@f9w|^x{A_B2qD7PcUfJ3wo|#S3kRpW`b%(~-*T2qRI^Qb=#dC5y^ql4a&0zKvMF1wgcKoqD zmL}`jthbE^q#h-reobs^9d)p+%={Fvhb2j8Kbk^cm5) zQngf#k7t4Zj2+trMZ~kT&!mgItqwGU=p8PE9WW?}F4)oW_vImrUcDF5Wx!^Ri;wCQ zOO%QfyrSKl{!|IBcq4FF}HwffjG2Xh|Q@MBr_#Kxsp z`N_8Zz#*ec9JI7aW1ZMbYI?s0(GYAPgAgKwdue0>|7WJuRcip;Xv<#7*iiX{4H1wU z?i4C8ZCACTb)r|Aa4|@b$4yS(2ar!PFQ0K5N4M?#noZfY%|2L>NgB9|kr2P!!rT;~pH zSKsAV!XY7f1*(T^Kw%B-t&;hNTo(`$cU9@a*1E$YTgg!r_1BZ{5q0?wgQuU+WB@iX zByd2DkA^wJfj`nK1AJ-rt(F$33(`?qZDxi_yEp2fl3m@#K`;p^Y=XJ4s86nOEQ(^`>!6amzc9hfb0 z(#lkB`Nq>4nj7MoYbiGcw#vD!P1D|q<1&rolKPE;1A~YKm;ol$O>AG($j$?HizY;|sZgPH*Ma<8|I4h&%w9^-gJ9Po-Lxwm6nBguYbD!A#QK?K zHdWMWs3_K%04JIWzm8cG_VRu}m?=vXk2sjVMb?eHUsXYNe;D7d5X(-9{{H0m;e)`p zJT0tngQceqSwuYRkiM<1ryG7(9_1?;hor5nne;trZ+5ciZTJ9J^z@;8Zg*tW>og;% zlF3hM+sKsYeXTzyH?Z(OSLkYOnptWyeF+PDg_`-+>6K4-xj!$VmDl>N zZ!)N5t!e4O;UB8O@|x{eW}p?aHSW5yZB~PY=hOIIDdN%b4+i*BIeuW_etSL<07T$+|*Mrfm7nr5~?dB z_)(*0(43lCAv5o{3}d)^N#XVg@^J5qROG?Ksk3)SYDMKA(T=0AR+kdP1Koe-DdI(T z2wXaX>$MMul^zuy=jBTk{`_t}?{S9+C7GM@-r(O_H%x1*%5<~YPefdVaO-;oWwj(0 z&02H#Sq(p0`Nv=Dn)dX)XWOAcOSh+)n`?K5tK7lwa)s*m_D;sYsbhL}K=|#TcNN3y z^TGSO>N96t5`c^_4?OtJQvn&E^u}_8|Bua0w^8;nsxF5I!TnK|KMnE_xk%QR+4)fK zERHV6I(5(beKGKTJ8_A1;>CQ_?Xd3$a|daHh|FtjYXVuU9El_hn1&FNduX_H%=7!Z zmptX^4Cxz=td-(dQF67D`19Un8b}fU`+wp2XLC2osz2(idP>o|22=kC638wWyqy`j zP~{g-hI^aYdHOlDXspuic+Ah<&K5bM@W2h<0v0UL{r&eKxaq#nW&o#0>%7wb<*7Wz zk8_wBtQM@-lH0SZUj1f!u;9!}P9GzD)5cGIeDm@RMyo1l|HMTd;=iCTD1u(hbv_f$ zArGgm8nojJFPH2b76q2ATXMS7c3a|-r5eQQq`r@dz~_m!iA8A_`Y9JGlpnpi<8ggT z*2}|ZExjG6+RQ;rz4Te*&u<$Y zZomvD(wr>{){pbns8D%*zE5|{SBId5@>~7&r&713vsRv6-fY!heMUiP*=AOxquXZ# zyu5MuMeraCq4h#0j6ND-I6>buP0S16WF8DR8P0RsRPKMt({wgnKY4-8(fA^V43_q% zr&smiwD|}AcwlS>qv_VWW2O;u9|SV=ZAo-r%Pzcc;?afM0yDmo~F?tatGDout&CBv(mFP)srM^@Me;E63cAZY_fp~&m;Oo{$>kFy-wmJ62EXp;h zFBMEtO7d`{Uv1pYrP1fos`!o9md;|t?%B4Ag`i#JZff1T;u4ua6eJW}(fPG0&{f$c z8YO?QWHow+$7cWgJCC59>xqzyT2K9WS#8f$Dwb@QI(14auGbL&6{EwD-uj;7Uqdt zBezs-t<-%EDpWcr0-GnDP{Dti6QSG)63c5f4WHI3)RCae+C|v~?wS<;OQ-A(KK%Xh zk9It{j{43&3nJg%p|6I0pObInH;xo8Q(=mf`1>aLRLrs$i0T~YJ-a20s^03k_qajd z`dWstg@KdF8F?Zn7=hX`lHQ~M23`@OUfj2_vZ=c<%H>fWli$*olwjO7n)X2J7tY{m zTCH(8DA>}(C3Se%eS6*2_R8T8+F}D~8*tt}$wh)SP(Mo$vZDa%FR`EZm94jo+Vda0 zaUC#rH_RW@{k-Y>F?DF|o>11EAtQY!mkMMQCTVL&S#@a@i9E84YjpiQ+T9|gq=jmh zvdc+SP-*n3?-hAjs73-aalXq%avtV%p;N{0Be|n*dw6DP#J;mn>bX}+ltW)-7c7as;3?jiLNXfisSAYDu-!1sT)4O=MQw}FQ{D` zY5jIi@AR(q$|y_p)R%)%wfIuXGlBV`+u0W?Co`T97wM_=yCbSE`vYW{ z3)1hYC*|r1rq^9#;zmyE+k5v5kkPhp_u_w@$UDs1FT2l_#op<_do|3p(1eWzcv6Q2 z)u^)JH{CZpy9AJdlIFgMhHR(+`@4?{% z>_6@EnSzN0;qU)Ao`QrM+o_4vH?W%)JcT$c+=Fv@nb&$)3CRuomt*FDSXXeJfKTo8 zK+sfp&tS&%5BT$Ft#mhWBFFBYr}EwGi!h=D(`O*4F3xG^gxTRJqB%&ER~k`;YySK3 zCiEONE`n#dfhBmi{obB_qX+Mt^K$nb6OZg7se9f%MS72Wjpv0=OU%`fIw+*I*K>g$ zx|6o6CSzv9)??2u;5n&&9oZHek1M3SA9BH6H`9fvSf`A&v|-6%rXb=jqDCtsrR5bSQDx``|2D7b`y85!DCGPn$0Vn-qY(a8!0IgR`t%y3B*jTl-N0_? zPc>&)a!P(G1?B0eM(7Xk9x9RG5WxK`E(Rxdcs|J%ni1AZMOjr?j+k*J_QJd~(>W|L z3@1``QWEs?@Gp!03A+Bqb>Znao;>zHyRKecJwz;lYkQH+D{ir=lLPW3PBQ&<;yjse zwj|;EQ~jSyhmXpzax|7Km=>ddI1NXnL=Xwq@pg@%JN`DM8rqBMD3a|dg^E(t&(|7! zAyMsy!bY9vFz;rJx5gWN={FCmjjmBr8xZqGYl-U z;JCr)(8c7bg~?nTovYTWOmE;|Q(95C~9>Uw;byVl67G7+WgW;r?;``16^$AfjX zjqB*o{d^Qz%$(iTz+*O02c?*KhOV~983TmZjO&SVl3P#vk|k@9PMqz$-yxTGN>q^b zg+DVoapQaa;BpB<%&2>2Ufkc<4)0UhAgx2}KIte(#V^}JV=-6#bWR>};3=#AeAikl z38xg^6%y+RKS`snUx#sl4-_asF7}`B!-{J%H>VS-j}nD`a}8`{m*lro(F3;gWCc&0ej4T&_^mU~PoL$b zX&zjK9 z)~^{Y+cd^cq~Yz-8@O$JgnZ1P%>dU8zohygO|!Pys~y$O-=glhy3L diff --git a/crates/vent-editor/assets/textures/icon/icon64.png b/crates/vent-editor/assets/textures/icon/icon64.png deleted file mode 100644 index b6fe3b8ccd41e42cf9fa2a6d174963700b46e42d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 905 zcmV;419tq0P)VQ%K_-dGE2ZBaf4~Mr zRuoiw8fcImbfxS%-k$&f0|H4zK~z}7?Uvhe<0=qEEs!lC31e>m|Ets8(9lS7rs|xU zw`}KTnYGw};^gsoERX-3|AGGIH^2EOzf?BLq!_IEHq;z3QI4U3P0o4m9Y#5&Tsm%B zEg|n8jLxrfiKH}2oU4|2V=$@W-iNE)CjHT>^6JiD65%_{lWx|yEC)`oD^(Qked$lU zg0<%3%V`|A#C_Kaljrf(r(@p7ujjVBX_ty3j;|%|@ALDABgKX8#o&i=heiSNH#;cr zs7c`}U@MfCO--)*4+YkrZ^}plsGyzLtFZF|{PvgIdiA&lssQ`Al)y!}s!)*3k2pNS zzSjyWlq-)V0{+o>r+NFG#=z(~f7sw(bd@#+ZV|j!za3$P>C0Oef!45(7&sa{8Q>ip zAq~CI1as1d4bGx-10(Dp3IY!ud9GjcbR@te13Q?p0NvtwUE0tyF7k*?pf-Mnyx;nm zwvy#Wv3fS_c`bdY0QM0IvH2oqG3F8Uu8Tm&*m!TxRZjv#G-l4c1~|W7nlUET#td?UEm1u;^?RXfe#6)t^s-FZ50d4AeaYyo!50uP(jf_;vb6s zVmAnZU~A^}a7fqp=n17wF^_^iJAq|>NTlg8E|g2B7F96NGS+j0{95@{sVIUw{8b*I zF2HSlVNyYY3l1QDV5VFeq#|r#Llca&NU7itdcum{f(0FKdDbKp#CBQK=z{e;`BP-` zT4hT=4vLu!B;fjIdcr)Xs8ndz#u~Cgoqd2y4xcTlgrY5@HsI+mu$`=(Lg1%T@uFo^ zL79HQZOc);>3*-rJo54MouThHsa&8iS$y|0nr-x;uIaGO*w)ALwybbVC&oKjOe~Hu}6bkYM_m fXG) { + fn view_tab_file(&self, ui: &mut Ui, _tree: &mut DockState) { for tab in &["New Project", "Open Project"] { if ui .selectable_label(self.open_tabs.contains(*tab), *tab) @@ -51,7 +51,7 @@ impl EditorViewer { } pub(crate) struct EditorGUI { - tree: Tree, + tree: DockState, viewer: EditorViewer, } @@ -74,7 +74,8 @@ impl GUI for EditorGUI { impl EditorGUI { pub fn new() -> Self { - let mut tree = Tree::new(vec!["Vent-Engine Placeholder".to_owned()]); + let mut state = DockState::new(vec!["Vent-Engine Placeholder".to_owned()]); + let mut tree = state.main_surface_mut(); let [a, _] = tree.split_left(NodeIndex::root(), 0.3, vec!["Files".to_owned()]); let [_, _] = tree.split_below(a, 0.6, vec!["Console".to_owned()]); @@ -90,6 +91,9 @@ impl EditorGUI { let viewer = EditorViewer { open_tabs }; - Self { tree, viewer } + Self { + tree: state, + viewer, + } } } diff --git a/crates/vent-editor/src/main.rs b/crates/vent-editor/src/main.rs index 47ec71e..8aeb28d 100644 --- a/crates/vent-editor/src/main.rs +++ b/crates/vent-editor/src/main.rs @@ -6,7 +6,7 @@ use vent_common::util::crash::init_panic_hook; use vent_common::window::VentWindow; use vent_runtime::render::camera::{Camera, Camera3D}; -use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}; +use winit::event::{ElementState, Event, WindowEvent}; use winit::window::WindowBuilder; mod gui; @@ -22,72 +22,44 @@ fn main() { .unwrap(); }; - let path = concat!( - env!("CARGO_MANIFEST_DIR"), - "/assets/textures/icon/icon64.png" - ); - let window_builder = WindowBuilder::new() .with_title(format!("Vent-Editor v{}", env!("CARGO_PKG_VERSION"))) - .with_inner_size(winit::dpi::LogicalSize::new(1400.0, 800.0)) - // TODO - .with_window_icon(Some(VentWindow::load_icon(path))); + .with_inner_size(winit::dpi::LogicalSize::new(1400.0, 800.0)); + // TODO + // .with_window_icon(Some(VentWindow::load_icon(path))); let vent_window = VentWindow::new(window_builder); let mut camera = Camera3D::new(); let mut renderer = EditorRenderer::new(&vent_window.window, &vent_window.event_loop, &mut camera); - vent_window.event_loop.run(move |event, _, control_flow| { - control_flow.set_wait(); - - match event { - Event::WindowEvent { - ref event, - window_id, - } if window_id == vent_window.window.id() => { - renderer.egui.progress_event(event); - match event { - WindowEvent::CloseRequested - | WindowEvent::KeyboardInput { - input: - KeyboardInput { - state: ElementState::Pressed, - virtual_keycode: Some(VirtualKeyCode::Escape), - .. - }, - .. - } => control_flow.set_exit(), - WindowEvent::Resized(physical_size) => { - renderer.resize(physical_size, &mut camera); - } - WindowEvent::ScaleFactorChanged { new_inner_size, .. } => { - // new_inner_size is &mut so w have to dereference it twice - renderer.resize(new_inner_size, &mut camera); - } - _ => {} - } - } - Event::RedrawRequested(window_id) if window_id == vent_window.window.id() => { - match renderer.render(&vent_window.window, &mut camera) { - Ok(_) => {} - Err(err) => match err { - wgpu::SurfaceError::OutOfMemory => { - control_flow.set_exit(); - panic!("{}", format!("{err}")); + vent_window + .event_loop + .run(move |event, elwt| { + match event { + Event::WindowEvent { + ref event, + window_id, + } if window_id == vent_window.window.id() => { + renderer.egui.progress_event(event); + match event { + WindowEvent::CloseRequested => elwt.exit(), + WindowEvent::Resized(physical_size) => { + renderer.resize(physical_size, &mut camera); } - wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated => { - renderer.resize_current(&mut camera) + WindowEvent::RedrawRequested => { + renderer.render(&vent_window.window, &mut camera); } + // WindowEvent::ScaleFactorChanged { new_inner_size, .. } => { + // // new_inner_size is &mut so w have to dereference it twice + // renderer.resize(new_inner_size, &mut camera); + // } _ => {} - }, + } } + // ... + _ => {} } - Event::MainEventsCleared => { - vent_window.window.request_redraw(); - } - // ... - _ => {} - } - }); + }) + .expect("Window Event Loop Error"); } diff --git a/crates/vent-editor/src/render/mod.rs b/crates/vent-editor/src/render/mod.rs index ecc71f1..1700c2c 100644 --- a/crates/vent-editor/src/render/mod.rs +++ b/crates/vent-editor/src/render/mod.rs @@ -1,6 +1,7 @@ use crate::gui::EditorGUI; use crate::render::runtime_renderer::EditorRuntimeRenderer; -use vent_common::render::WGPURenderer; +use ash::vk; +use vent_rendering::instance::VulkanInstance; use vent_runtime::render::camera::Camera; use vent_runtime::render::gui::debug_gui::RenderData; use vent_runtime::render::gui::gui_renderer::EguiRenderer; @@ -9,7 +10,7 @@ use vent_runtime::render::Dimension; mod runtime_renderer; pub struct EditorRenderer { - default_renderer: WGPURenderer, + instance: VulkanInstance, pub egui: EguiRenderer, editor_runtime_renderer: EditorRuntimeRenderer, @@ -21,87 +22,47 @@ impl EditorRenderer { event_loop: &winit::event_loop::EventLoopWindowTarget<()>, camera: &mut dyn Camera, ) -> Self { - let default_renderer = WGPURenderer::new(window); - let egui = EguiRenderer::new( - event_loop, - &default_renderer.device, - default_renderer.caps.formats[0], - ) - .add_gui(Box::new(EditorGUI::new())); + let instance = VulkanInstance::new("Vent-Engine Editor", window); + let egui = EguiRenderer::new().add_gui(Box::new(EditorGUI::new())); let editor_runtime_renderer = EditorRuntimeRenderer::new( - &default_renderer, - // TODO + &instance, Dimension::D3, + // TODO event_loop, - wgpu::Extent3d { - width: default_renderer.config.width, - height: default_renderer.config.height, - depth_or_array_layers: 1, - }, + vk::Extent2D { + width: 1, + height: 1, + }, // TODO camera, ); Self { - default_renderer, + instance, egui, editor_runtime_renderer, } } - pub fn render( - &mut self, - window: &winit::window::Window, - camera: &mut dyn Camera, - ) -> Result<(), wgpu::SurfaceError> { - let output = self.default_renderer.surface.get_current_texture()?; - - let view = output.texture.create_view(&wgpu::TextureViewDescriptor { - label: Some("Editor View"), - ..Default::default() - }); - let mut encoder = - self.default_renderer - .device - .create_command_encoder(&wgpu::CommandEncoderDescriptor { - label: Some("Editor Render Encoder"), - }); - - self.egui.render( - &view, - window, - &self.default_renderer.device, - &self.default_renderer.queue, - &mut encoder, - &RenderData::default(), - ); - - self.default_renderer.queue.submit(Some(encoder.finish())); + pub fn render(&mut self, window: &winit::window::Window, camera: &mut dyn Camera) { + self.egui.render(&RenderData::default()); self.editor_runtime_renderer - .render(&self.default_renderer, window, camera)?; - output.present(); - Ok(()) + .render(&self.instance, window, camera); } pub fn resize(&mut self, new_size: &winit::dpi::PhysicalSize, camera: &mut dyn Camera) { - self.default_renderer.resize(new_size); // TODO - self.editor_runtime_renderer.resize( - &self.default_renderer.device, - &self.default_renderer.queue, - &self.default_renderer.config, - new_size, - camera, - ); + self.editor_runtime_renderer + .resize(&self.instance, new_size, camera); // egui does resize using Window Events } pub fn resize_current(&mut self, camera: &mut dyn Camera) { let size = winit::dpi::PhysicalSize { - width: self.default_renderer.config.width, - height: self.default_renderer.config.height, - }; + width: 1, + height: 1, + }; // TODO Self::resize(self, &size, camera) } } diff --git a/crates/vent-editor/src/render/runtime_renderer.rs b/crates/vent-editor/src/render/runtime_renderer.rs index 59eabd1..7e16358 100644 --- a/crates/vent-editor/src/render/runtime_renderer.rs +++ b/crates/vent-editor/src/render/runtime_renderer.rs @@ -1,47 +1,22 @@ -use vent_common::render::WGPURenderer; +use ash::vk; +use vent_rendering::instance::VulkanInstance; use vent_runtime::render::Dimension; use vent_runtime::render::{camera::Camera, RawRuntimeRenderer}; -use wgpu::{ - Device, Extent3d, Queue, SurfaceConfiguration, SurfaceError, Texture, TextureDimension, -}; pub struct EditorRuntimeRenderer { - texture: Texture, runtime_renderer: RawRuntimeRenderer, } impl EditorRuntimeRenderer { pub fn new( - default_renderer: &WGPURenderer, + instance: &VulkanInstance, dimension: Dimension, event_loop: &winit::event_loop::EventLoopWindowTarget<()>, - _extent: Extent3d, + _extent: vk::Extent2D, camera: &mut dyn Camera, ) -> Self { - let texture = default_renderer - .device - .create_texture(&wgpu::TextureDescriptor { - label: Some("Editor Runtime Texture"), - size: Extent3d::default(), - mip_level_count: 1, - sample_count: 1, - dimension: TextureDimension::D2, - format: default_renderer.config.format, - usage: default_renderer.config.usage, - view_formats: &[], - }); - let runtime_renderer = RawRuntimeRenderer::new( - dimension, - &default_renderer.device, - &default_renderer.queue, - &default_renderer.config, - default_renderer.caps.formats[0], - &default_renderer.adapter, - event_loop, - camera, - ); + let runtime_renderer = RawRuntimeRenderer::new(dimension, instance, event_loop, camera); Self { - texture, runtime_renderer, // extent, } @@ -49,46 +24,21 @@ impl EditorRuntimeRenderer { pub fn render( &mut self, - default_renderer: &WGPURenderer, + instance: &VulkanInstance, window: &winit::window::Window, camera: &mut dyn Camera, - ) -> Result<(), SurfaceError> { - let view = self.texture.create_view(&wgpu::TextureViewDescriptor { - label: Some("Runtime View"), - ..Default::default() - }); - self.runtime_renderer.render( - &view, - &default_renderer.device, - &default_renderer.queue, - window, - camera, - ); - Ok(()) + ) { + // TODO: Get new image + self.runtime_renderer.render(instance, window, camera); } pub fn resize( &mut self, - device: &Device, - _queue: &Queue, - config: &SurfaceConfiguration, + instance: &VulkanInstance, new_size: &winit::dpi::PhysicalSize, _camera: &mut dyn Camera, ) { - self.texture = device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: Extent3d { - width: new_size.width, - height: new_size.height, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: TextureDimension::D2, - format: config.format, - usage: config.usage, - view_formats: &[], - }); + // TODO // self.runtime_renderer.resize(config, device, queue, camera); } diff --git a/crates/vent-rendering/Cargo.toml b/crates/vent-rendering/Cargo.toml index 15f7342..2b038b3 100644 --- a/crates/vent-rendering/Cargo.toml +++ b/crates/vent-rendering/Cargo.toml @@ -10,8 +10,7 @@ ash = { version= "0.37.3", default-features = false, features = ["linked", "debu image = "0.24.7" -winit = "0.28.0" -raw-window-handle = "0.5" -ash-window = "0.12.0" +winit = "0.29.3" +raw-window-handle = "0.6" bytemuck = { version = "1.14.0", features = ["derive"] } diff --git a/crates/vent-rendering/src/instance.rs b/crates/vent-rendering/src/instance.rs index d43d2f4..ffd722d 100644 --- a/crates/vent-rendering/src/instance.rs +++ b/crates/vent-rendering/src/instance.rs @@ -1,7 +1,7 @@ use ash::extensions::khr::{Surface, Swapchain}; -use ash::vk::{Extent2D, SwapchainKHR}; +use ash::vk::{make_version, Extent2D, SwapchainKHR}; use ash::{extensions::ext::DebugUtils, vk, Entry}; -use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; +use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; use std::borrow::Cow; use std::{default::Default, ffi::CStr}; @@ -12,6 +12,7 @@ use ash::vk::{ use crate::allocator::MemoryAllocator; use crate::image::VulkanImage; +use crate::surface; const VALIDATION_ENABLED: bool = cfg!(debug_assertions); @@ -52,6 +53,7 @@ pub struct VulkanInstance { pub memory_allocator: MemoryAllocator, pub instance: ash::Instance, + pub physical_device: vk::PhysicalDevice, pub device: ash::Device, pub surface_loader: Surface, @@ -90,9 +92,11 @@ pub struct VulkanInstance { } impl VulkanInstance { - pub fn new(application_name: &str, window: winit::window::Window) -> Self { + pub fn new(application_name: &str, window: &winit::window::Window) -> Self { let entry = Entry::linked(); + let engine_version: u32 = (env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap()); + let app_info = unsafe { vk::ApplicationInfo::builder() .application_name(CStr::from_bytes_with_nul_unchecked( @@ -100,15 +104,17 @@ impl VulkanInstance { )) .application_version(0) // TODO .engine_name(CStr::from_bytes_with_nul_unchecked(b"Vent-Engine\0")) - .engine_version(env!("CARGO_PKG_VERSION").parse().unwrap()) + .engine_version(engine_version) .api_version(vk::API_VERSION_1_2) .build() }; - let mut extension_names = - ash_window::enumerate_required_extensions(window.raw_display_handle()) - .expect("Unsupported Surface Extension") - .to_vec(); + let display_handle = window.display_handle().expect("No Display Handle"); + let window_handle = window.window_handle().expect("No Window Handle"); + + let mut extension_names = surface::enumerate_required_extensions(display_handle) + .expect("Unsupported Surface Extension") + .to_vec(); extension_names.push(DebugUtils::name().as_ptr()); #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -140,13 +146,7 @@ impl VulkanInstance { #[cfg(debug_assertions)] let debug_messenger = Self::create_debug_messenger(&debug_utils_loader); let surface = unsafe { - ash_window::create_surface( - &entry, - &instance, - window.raw_display_handle(), - window.raw_window_handle(), - None, - ) + surface::create_surface(&entry, &instance, display_handle, window_handle, None) } .unwrap(); let surface_loader = Surface::new(&entry, &instance); @@ -206,6 +206,7 @@ impl VulkanInstance { Self { memory_allocator, instance, + physical_device: pdevice, device, surface, surface_loader, @@ -217,9 +218,11 @@ impl VulkanInstance { graphics_queue, present_queue, render_pass, + #[cfg(debug_assertions)] debug_utils: debug_utils_loader, descriptor_pool, descriptor_set_layout, + #[cfg(debug_assertions)] debug_messenger, depth_image, frame_buffers, @@ -330,6 +333,7 @@ impl VulkanInstance { }) } + #[cfg(debug_assertions)] fn create_debug_messenger(debug_utils_loader: &DebugUtils) -> vk::DebugUtilsMessengerEXT { let debug_info = vk::DebugUtilsMessengerCreateInfoEXT::builder() .message_severity( @@ -752,6 +756,7 @@ impl Drop for VulkanInstance { self.surface_loader.destroy_surface(self.surface, None); self.swapchain_loader .destroy_swapchain(self.swapchain, None); + #[cfg(debug_assertions)] self.debug_utils .destroy_debug_utils_messenger(self.debug_messenger, None); self.instance.destroy_instance(None) diff --git a/crates/vent-rendering/src/lib.rs b/crates/vent-rendering/src/lib.rs index 9622477..cf2a0f0 100644 --- a/crates/vent-rendering/src/lib.rs +++ b/crates/vent-rendering/src/lib.rs @@ -8,6 +8,7 @@ pub mod buffer; pub mod image; pub mod instance; pub mod pipeline; +mod surface; pub trait Vertex<'a> { const BINDING_DESCRIPTION: vk::VertexInputBindingDescription; diff --git a/crates/vent-rendering/src/surface.rs b/crates/vent-rendering/src/surface.rs new file mode 100644 index 0000000..1189444 --- /dev/null +++ b/crates/vent-rendering/src/surface.rs @@ -0,0 +1,147 @@ +// Mostly taken from ash-window: https://github.com/ash-rs/ash/blob/master/ash-window/src/lib.rs + +use std::os::raw::c_char; + +use ash::{ + extensions::{ext, khr}, + prelude::*, + vk, Entry, Instance, +}; +use raw_window_handle::{DisplayHandle, RawDisplayHandle, RawWindowHandle, WindowHandle}; + +pub unsafe fn create_surface( + entry: &Entry, + instance: &Instance, + display_handle: DisplayHandle<'_>, + window_handle: WindowHandle<'_>, + allocation_callbacks: Option<&vk::AllocationCallbacks>, +) -> VkResult { + match (display_handle.as_raw(), window_handle.as_raw()) { + // (RawDisplayHandle::Windows(_), RawWindowHandle::Win32(window)) => { + // let hinstance = window.hinstance.expect("No Windows Instance"); + // let surface_desc = vk::Win32SurfaceCreateInfoKHR::builder() + // .hinstance(hinstance.get()) + // .hwnd(window.hwnd.get()); + // let surface_fn = khr::Win32Surface::new(entry, instance); + // surface_fn.create_win32_surface(&surface_desc, allocation_callbacks) + // } + (RawDisplayHandle::Wayland(display), RawWindowHandle::Wayland(window)) => { + let surface_desc = vk::WaylandSurfaceCreateInfoKHR::builder() + .display(display.display.as_ptr()) + .surface(window.surface.as_ptr()); + let surface_fn = khr::WaylandSurface::new(entry, instance); + surface_fn.create_wayland_surface(&surface_desc, allocation_callbacks) + } + + (RawDisplayHandle::Xlib(display), RawWindowHandle::Xlib(window)) => { + let display = display.display.expect("No XOrg Display pointer"); + let surface_desc = vk::XlibSurfaceCreateInfoKHR::builder() + .dpy(display.as_ptr().cast()) + .window(window.window); + let surface_fn = khr::XlibSurface::new(entry, instance); + surface_fn.create_xlib_surface(&surface_desc, allocation_callbacks) + } + + (RawDisplayHandle::Xcb(display), RawWindowHandle::Xcb(window)) => { + let connection = display.connection.expect("No X-Server Connection Pointer"); + let surface_desc = vk::XcbSurfaceCreateInfoKHR::builder() + .connection(connection.as_ptr()) + .window(window.window.get()); + let surface_fn = khr::XcbSurface::new(entry, instance); + surface_fn.create_xcb_surface(&surface_desc, allocation_callbacks) + } + + (RawDisplayHandle::Android(_), RawWindowHandle::AndroidNdk(window)) => { + let surface_desc = + vk::AndroidSurfaceCreateInfoKHR::builder().window(window.a_native_window.as_ptr()); + let surface_fn = khr::AndroidSurface::new(entry, instance); + surface_fn.create_android_surface(&surface_desc, allocation_callbacks) + } + + #[cfg(target_os = "macos")] + (RawDisplayHandle::AppKit(_), RawWindowHandle::AppKit(window)) => { + use raw_window_metal::{appkit, Layer}; + + let layer = match appkit::metal_layer_from_handle(window) { + Layer::Existing(layer) | Layer::Allocated(layer) => layer.cast(), + }; + + let surface_desc = vk::MetalSurfaceCreateInfoEXT::builder().layer(&*layer); + let surface_fn = ext::MetalSurface::new(entry, instance); + surface_fn.create_metal_surface(&surface_desc, allocation_callbacks) + } + + #[cfg(target_os = "ios")] + (RawDisplayHandle::UiKit(_), RawWindowHandle::UiKit(window)) => { + use raw_window_metal::{uikit, Layer}; + + let layer = match uikit::metal_layer_from_handle(window) { + Layer::Existing(layer) | Layer::Allocated(layer) => layer.cast(), + }; + + let surface_desc = vk::MetalSurfaceCreateInfoEXT::builder().layer(&*layer); + let surface_fn = ext::MetalSurface::new(entry, instance); + surface_fn.create_metal_surface(&surface_desc, allocation_callbacks) + } + + _ => Err(vk::Result::ERROR_EXTENSION_NOT_PRESENT), + } +} + +pub fn enumerate_required_extensions( + display_handle: DisplayHandle<'_>, +) -> VkResult<&'static [*const c_char]> { + let extensions = match display_handle.as_raw() { + RawDisplayHandle::Windows(_) => { + const WINDOWS_EXTS: [*const c_char; 2] = [ + khr::Surface::name().as_ptr(), + khr::Win32Surface::name().as_ptr(), + ]; + &WINDOWS_EXTS + } + + RawDisplayHandle::Wayland(_) => { + const WAYLAND_EXTS: [*const c_char; 2] = [ + khr::Surface::name().as_ptr(), + khr::WaylandSurface::name().as_ptr(), + ]; + &WAYLAND_EXTS + } + + RawDisplayHandle::Xlib(_) => { + const XLIB_EXTS: [*const c_char; 2] = [ + khr::Surface::name().as_ptr(), + khr::XlibSurface::name().as_ptr(), + ]; + &XLIB_EXTS + } + + RawDisplayHandle::Xcb(_) => { + const XCB_EXTS: [*const c_char; 2] = [ + khr::Surface::name().as_ptr(), + khr::XcbSurface::name().as_ptr(), + ]; + &XCB_EXTS + } + + RawDisplayHandle::Android(_) => { + const ANDROID_EXTS: [*const c_char; 2] = [ + khr::Surface::name().as_ptr(), + khr::AndroidSurface::name().as_ptr(), + ]; + &ANDROID_EXTS + } + + RawDisplayHandle::AppKit(_) | RawDisplayHandle::UiKit(_) => { + const METAL_EXTS: [*const c_char; 2] = [ + khr::Surface::name().as_ptr(), + ext::MetalSurface::name().as_ptr(), + ]; + &METAL_EXTS + } + + _ => return Err(vk::Result::ERROR_EXTENSION_NOT_PRESENT), + }; + + Ok(extensions) +} diff --git a/crates/vent-runtime/Cargo.toml b/crates/vent-runtime/Cargo.toml index 61d1db3..0afcf33 100644 --- a/crates/vent-runtime/Cargo.toml +++ b/crates/vent-runtime/Cargo.toml @@ -11,19 +11,20 @@ vent-rendering = { path = "../vent-rendering"} vent-assets = { path = "../vent-assets" } vent-ecs = { path = "../vent-ecs"} -winit = "0.28.6" -# wgpu = "0.16.2" +ash = { version= "0.37.3", default-features = false, features = ["linked", "debug"] } + +winit = "0.29.3" pollster = "0.3.0" log = "0.4" -glam = "0.24.1" +glam = "0.24.2" bytemuck = { version = "1.14.0", features = ["derive"] } downcast-rs = "1.2.0" # egui -# egui = "0.22.0" -# egui-wgpu = "0.22.0" -# egui-winit = "0.22.0" +egui = "0.23.0" +egui-winit-ash-integration = "0.5.0" +egui-winit = "0.23.0" [target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies] simple_logger = "4.2.0" diff --git a/crates/vent-runtime/src/lib.rs b/crates/vent-runtime/src/lib.rs index 72bcf14..7c40ebe 100644 --- a/crates/vent-runtime/src/lib.rs +++ b/crates/vent-runtime/src/lib.rs @@ -8,7 +8,7 @@ use vent_common::project::VentApplicationProject; use vent_common::util::crash::init_panic_hook; use vent_common::window::VentWindow; -use winit::event::{DeviceEvent, ElementState, Event, KeyboardInput, WindowEvent}; +use winit::event::{DeviceEvent, ElementState, Event, WindowEvent}; use winit::window::WindowBuilder; pub mod render; @@ -56,55 +56,48 @@ impl VentApplication { let mut controller = CameraController3D::new(3000.0, 10.0); let mut delta_time = 0.0; - vent_window.event_loop.run(move |event, _, control_flow| { - control_flow.set_wait(); + vent_window + .event_loop + .run(move |event, elwt| { + match event { + Event::WindowEvent { + ref event, + window_id, + } if window_id == vent_window.window.id() => { + renderer.progress_event(event); - match event { - Event::WindowEvent { - ref event, - window_id, - } if window_id == vent_window.window.id() => { - renderer.progress_event(event); - - match event { - WindowEvent::CloseRequested => control_flow.set_exit(), - WindowEvent::MouseInput { button, state, .. } => { - controller.process_mouse_input(&vent_window.window, button, state); - } - WindowEvent::KeyboardInput { - input: - KeyboardInput { - state: ElementState::Pressed, - virtual_keycode: Some(key), - .. - }, - .. - } => { - controller.process_keyboard(&mut cam, key, delta_time); - } - WindowEvent::Resized(physical_size) => { - renderer.resize(physical_size, &mut cam); - } - WindowEvent::ScaleFactorChanged { new_inner_size, .. } => { - // new_inner_size is &mut so w have to dereference it twice - renderer.resize(new_inner_size, &mut cam); + match event { + WindowEvent::CloseRequested => elwt.exit(), + WindowEvent::MouseInput { button, state, .. } => { + controller.process_mouse_input(&vent_window.window, button, state); + } + WindowEvent::KeyboardInput { event, .. } => { + controller.process_keyboard(&mut cam, event, delta_time); + } + WindowEvent::Resized(physical_size) => { + renderer.resize(physical_size, &mut cam); + } + // WindowEvent::ScaleFactorChanged { + // inner_size_writer, .. + // } => { + // // new_inner_size is &mut so w have to dereference it twice + // renderer.resize(new_inner_size, &mut cam); + // } + WindowEvent::RedrawRequested => { + delta_time = renderer.render(&vent_window.window, &mut cam); + } + _ => {} } - _ => {} } + Event::DeviceEvent { + event: DeviceEvent::MouseMotion { delta }, + .. + } => controller.process_mouse_movement(&mut cam, delta.0, delta.1, delta_time), + + // ... + _ => {} } - Event::DeviceEvent { - event: DeviceEvent::MouseMotion { delta }, - .. - } => controller.process_mouse_movement(&mut cam, delta.0, delta.1, delta_time), - Event::RedrawRequested(window_id) if window_id == vent_window.window.id() => { - delta_time = renderer.render(&vent_window.window, &mut cam); - } - Event::MainEventsCleared => { - vent_window.window.request_redraw(); - } - // ... - _ => {} - } - }); + }) + .expect("Window Event Loop Error"); } } diff --git a/crates/vent-runtime/src/render/camera/camera_controller3d.rs b/crates/vent-runtime/src/render/camera/camera_controller3d.rs index e5b3633..fa4a67c 100644 --- a/crates/vent-runtime/src/render/camera/camera_controller3d.rs +++ b/crates/vent-runtime/src/render/camera/camera_controller3d.rs @@ -1,4 +1,7 @@ -use winit::event::VirtualKeyCode; +use winit::{ + event::{ElementState, KeyEvent}, + keyboard::{self, Key, NamedKey, PhysicalKey}, +}; use super::Camera3D; @@ -25,41 +28,44 @@ impl CameraController3D { pub fn process_keyboard( &self, camera: &mut Camera3D, - key: &VirtualKeyCode, + event: &KeyEvent, delta_time: f32, ) -> bool { - let (sin_pitch, cos_pitch) = camera.rotation.x.sin_cos(); - match key { - VirtualKeyCode::W | VirtualKeyCode::Up => { - camera.add_x(sin_pitch * self.speed * delta_time); - camera.add_z(cos_pitch * self.speed * delta_time); - true + if event.state == ElementState::Pressed { + let (sin_pitch, cos_pitch) = camera.rotation.x.sin_cos(); + match event.logical_key.as_ref() { + Key::Character("W") | Key::Named(NamedKey::ArrowUp) => { + camera.add_x(sin_pitch * self.speed * delta_time); + camera.add_z(cos_pitch * self.speed * delta_time); + return true; + } + Key::Character("S") | Key::Named(NamedKey::ArrowDown) => { + camera.minus_x(sin_pitch * self.speed * delta_time); + camera.minus_z(cos_pitch * self.speed * delta_time); + return true; + } + Key::Character("A") | Key::Named(NamedKey::ArrowLeft) => { + camera.minus_x(cos_pitch * self.speed * delta_time); + camera.add_z(sin_pitch * self.speed * delta_time); + return true; + } + Key::Character("D") | Key::Named(NamedKey::ArrowRight) => { + camera.add_x(cos_pitch * self.speed * delta_time); + camera.minus_z(sin_pitch * self.speed * delta_time); + return true; + } + Key::Named(NamedKey::Space) => { + camera.add_y(self.speed * delta_time); + return true; + } + Key::Named(NamedKey::Shift) => { + camera.minus_y(self.speed * delta_time); + return true; + } + _ => return false, } - VirtualKeyCode::S | VirtualKeyCode::Down => { - camera.minus_x(sin_pitch * self.speed * delta_time); - camera.minus_z(cos_pitch * self.speed * delta_time); - true - } - VirtualKeyCode::A | VirtualKeyCode::Left => { - camera.minus_x(cos_pitch * self.speed * delta_time); - camera.add_z(sin_pitch * self.speed * delta_time); - true - } - VirtualKeyCode::D | VirtualKeyCode::Right => { - camera.add_x(cos_pitch * self.speed * delta_time); - camera.minus_z(sin_pitch * self.speed * delta_time); - true - } - VirtualKeyCode::Space => { - camera.add_y(self.speed * delta_time); - true - } - VirtualKeyCode::LShift => { - camera.minus_y(self.speed * delta_time); - true - } - _ => false, } + false } pub fn process_mouse_input( diff --git a/crates/vent-runtime/src/render/d2/mod.rs b/crates/vent-runtime/src/render/d2/mod.rs index d44ab0e..850b54f 100644 --- a/crates/vent-runtime/src/render/d2/mod.rs +++ b/crates/vent-runtime/src/render/d2/mod.rs @@ -7,24 +7,26 @@ pub struct UBO2D {} pub struct Renderer2D {} impl Renderer for Renderer2D { - fn init(instance: Instance, camera: &mut dyn Camera) -> Self; + fn init(instance: &vent_rendering::instance::VulkanInstance, camera: &mut dyn Camera) -> Self + where + Self: Sized, + { + todo!() + } fn resize( &mut self, - _config: &wgpu::SurfaceConfiguration, - _device: &wgpu::Device, - _queue: &wgpu::Queue, - _camera: &mut dyn Camera, + instance: &vent_rendering::instance::VulkanInstance, + new_size: &winit::dpi::PhysicalSize, + camera: &mut dyn Camera, ) { todo!() } fn render( &mut self, - _encoder: &mut wgpu::CommandEncoder, - _view: &wgpu::TextureView, - _queue: &wgpu::Queue, - _camera: &mut dyn Camera, + instance: &vent_rendering::instance::VulkanInstance, + camera: &mut dyn Camera, ) { todo!() } diff --git a/crates/vent-runtime/src/render/d3/light_renderer.rs b/crates/vent-runtime/src/render/d3/light_renderer.rs index c07493c..a438ff8 100644 --- a/crates/vent-runtime/src/render/d3/light_renderer.rs +++ b/crates/vent-runtime/src/render/d3/light_renderer.rs @@ -1,15 +1,14 @@ use std::mem; -use vent_assets::{Mesh3D, Vertex, Vertex3D}; -use wgpu::util::DeviceExt; +use vent_assets::Mesh3D; #[allow(dead_code)] pub struct LightRenderer { light_uniform: LightUBO, - light_buffer: wgpu::Buffer, - pub light_bind_group_layout: wgpu::BindGroupLayout, - pub light_bind_group: wgpu::BindGroup, - light_render_pipeline: wgpu::RenderPipeline, + // light_buffer: wgpu::Buffer, + // pub light_bind_group_layout: wgpu::BindGroupLayout, + // pub light_bind_group: wgpu::BindGroup, + // light_render_pipeline: wgpu::RenderPipeline, } #[repr(C)] @@ -25,110 +24,109 @@ pub struct LightUBO { #[allow(dead_code)] impl LightRenderer { - pub fn new( - device: &wgpu::Device, - camera_bind_group_layout: &wgpu::BindGroupLayout, - format: wgpu::TextureFormat, + pub fn new(// device: &wgpu::Device, + // camera_bind_group_layout: &wgpu::BindGroupLayout, + // format: wgpu::TextureFormat, ) -> Self { - let light_uniform = LightUBO { - position: [2.0, 100.0, 2.0], - _padding: 0, - color: [1.0, 1.0, 1.0], - _padding2: 0, - }; + todo!() + // let light_uniform = LightUBO { + // position: [2.0, 100.0, 2.0], + // _padding: 0, + // color: [1.0, 1.0, 1.0], + // _padding2: 0, + // }; - let light_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: Some("Light VB"), - contents: bytemuck::cast_slice(&[light_uniform]), - usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, - }); + // let light_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + // label: Some("Light VB"), + // contents: bytemuck::cast_slice(&[light_uniform]), + // usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, + // }); - let light_bind_group_layout = - device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - entries: &[wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: wgpu::BufferSize::new( - mem::size_of::() as wgpu::BufferAddress - ), - }, - count: None, - }], - label: None, - }); + // let light_bind_group_layout = + // device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + // entries: &[wgpu::BindGroupLayoutEntry { + // binding: 0, + // visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, + // ty: wgpu::BindingType::Buffer { + // ty: wgpu::BufferBindingType::Uniform, + // has_dynamic_offset: false, + // min_binding_size: wgpu::BufferSize::new( + // mem::size_of::() as wgpu::BufferAddress + // ), + // }, + // count: None, + // }], + // label: None, + // }); - let light_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { - layout: &light_bind_group_layout, - entries: &[wgpu::BindGroupEntry { - binding: 0, - resource: light_buffer.as_entire_binding(), - }], - label: None, - }); + // let light_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + // layout: &light_bind_group_layout, + // entries: &[wgpu::BindGroupEntry { + // binding: 0, + // resource: light_buffer.as_entire_binding(), + // }], + // label: None, + // }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("Light Pipeline Layout"), - bind_group_layouts: &[camera_bind_group_layout, &light_bind_group_layout], - push_constant_ranges: &[], - }); - let shader = device.create_shader_module(wgpu::include_wgsl!(concat!( - env!("CARGO_MANIFEST_DIR"), - "/res/shaders/app/3D/light.wgsl" - ))); - let vertex_buffers = [Vertex3D::LAYOUT]; + // let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + // label: Some("Light Pipeline Layout"), + // bind_group_layouts: &[camera_bind_group_layout, &light_bind_group_layout], + // push_constant_ranges: &[], + // }); + // let shader = device.create_shader_module(wgpu::include_wgsl!(concat!( + // env!("CARGO_MANIFEST_DIR"), + // "/res/shaders/app/3D/light.wgsl" + // ))); + // let vertex_buffers = [Vertex3D::LAYOUT]; - let light_render_pipeline = - device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { - label: Some("Light Renderer Pipeline"), - layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: "vs_main", - buffers: &vertex_buffers, - }, - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: "fs_main", - targets: &[Some(format.into())], - }), - primitive: wgpu::PrimitiveState { - cull_mode: Some(wgpu::Face::Back), - front_face: wgpu::FrontFace::Cw, - ..Default::default() - }, - depth_stencil: Some(wgpu::DepthStencilState { - format: vent_assets::Texture::DEPTH_FORMAT, - depth_write_enabled: true, - depth_compare: wgpu::CompareFunction::Less, - stencil: wgpu::StencilState::default(), - bias: wgpu::DepthBiasState::default(), - }), - multisample: wgpu::MultisampleState::default(), - multiview: None, - }); + // let light_render_pipeline = + // device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + // label: Some("Light Renderer Pipeline"), + // layout: Some(&pipeline_layout), + // vertex: wgpu::VertexState { + // module: &shader, + // entry_point: "vs_main", + // buffers: &vertex_buffers, + // }, + // fragment: Some(wgpu::FragmentState { + // module: &shader, + // entry_point: "fs_main", + // targets: &[Some(format.into())], + // }), + // primitive: wgpu::PrimitiveState { + // cull_mode: Some(wgpu::Face::Back), + // front_face: wgpu::FrontFace::Cw, + // ..Default::default() + // }, + // depth_stencil: Some(wgpu::DepthStencilState { + // format: vent_assets::Texture::DEPTH_FORMAT, + // depth_write_enabled: true, + // depth_compare: wgpu::CompareFunction::Less, + // stencil: wgpu::StencilState::default(), + // bias: wgpu::DepthBiasState::default(), + // }), + // multisample: wgpu::MultisampleState::default(), + // multiview: None, + // }); - Self { - light_uniform, - light_buffer, - light_bind_group_layout, - light_bind_group, - light_render_pipeline, - } + // Self { + // light_uniform, + // light_buffer, + // light_bind_group_layout, + // light_bind_group, + // light_render_pipeline, + // } } - pub fn render<'rp>( - &'rp self, - rpass: &mut wgpu::RenderPass<'rp>, - camera_bind_group: &'rp wgpu::BindGroup, - mesh: &'rp Mesh3D, + pub fn render( + &self, + // camera_bind_group: &'rp wgpu::BindGroup, + mesh: &Mesh3D, ) { - rpass.set_pipeline(&self.light_render_pipeline); - rpass.set_bind_group(0, camera_bind_group, &[]); - rpass.set_bind_group(1, &self.light_bind_group, &[]); - mesh.bind(rpass, false); - mesh.draw(rpass); + // rpass.set_pipeline(&self.light_render_pipeline); + // rpass.set_bind_group(0, camera_bind_group, &[]); + // rpass.set_bind_group(1, &self.light_bind_group, &[]); + // mesh.bind(rpass, false); + // mesh.draw(rpass); } } diff --git a/crates/vent-runtime/src/render/d3/mod.rs b/crates/vent-runtime/src/render/d3/mod.rs index 75e7737..ca2736e 100644 --- a/crates/vent-runtime/src/render/d3/mod.rs +++ b/crates/vent-runtime/src/render/d3/mod.rs @@ -1,10 +1,10 @@ use std::mem; use glam::Mat4; -use vent_assets::{Mesh3D, Vertex, Vertex3D}; +use vent_assets::Mesh3D; use vent_ecs::world::World; -use vent_rendering::instance::VulkanInstance; -use wgpu::util::DeviceExt; +use vent_rendering::{instance::VulkanInstance, Vertex3D}; +use winit::dpi::PhysicalSize; use self::light_renderer::LightRenderer; @@ -41,300 +41,293 @@ impl Default for UBO3D { pub struct Renderer3D { mesh_renderer: ModelRenderer3D, - light_renderer: LightRenderer, + // light_renderer: LightRenderer, tmp_light_mesh: Mesh3D, - bind_group: wgpu::BindGroup, - depth_view: wgpu::TextureView, - uniform_buf: wgpu::Buffer, - pipeline: wgpu::RenderPipeline, - pipeline_wire: Option, + // bind_group: wgpu::BindGroup, + // depth_view: wgpu::TextureView, + // uniform_buf: wgpu::Buffer, + // pipeline: wgpu::RenderPipeline, + // pipeline_wire: Option, } impl Renderer for Renderer3D { - fn init(instance: VulkanInstance, camera: &mut dyn Camera) -> Self + fn init(instance: &VulkanInstance, camera: &mut dyn Camera) -> Self where Self: Sized, { - let camera: &Camera3D = camera.downcast_ref().unwrap(); - // Create pipeline layout - let vertex_group_layout = - device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - label: Some("3D Bind Group Layout"), - entries: &[wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: wgpu::BufferSize::new( - mem::size_of::() as wgpu::BufferAddress - ), - }, - count: None, - }], - }); - - let texture_bind_group_layout = - device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - entries: &[ - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Texture { - multisampled: false, - view_dimension: wgpu::TextureViewDimension::D2, - sample_type: wgpu::TextureSampleType::Float { filterable: true }, - }, - count: None, - }, - wgpu::BindGroupLayoutEntry { - binding: 1, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering), - count: None, - }, - wgpu::BindGroupLayoutEntry { - binding: 2, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: wgpu::BufferSize::new(mem::size_of::< - vent_assets::model::Material, - >() - as wgpu::BufferAddress), - }, - count: None, - }, - ], - label: Some("texture_bind_group_layout"), - }); - - let light_renderer = LightRenderer::new(device, &vertex_group_layout, config.format); - - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("3D Pipeline Layout"), - bind_group_layouts: &[ - &vertex_group_layout, - &texture_bind_group_layout, - &light_renderer.light_bind_group_layout, - ], - push_constant_ranges: &[], - }); - - // Create other resources - let ubo = camera.ubo(); - let uniform_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: Some("Uniform Buffer"), - contents: bytemuck::bytes_of(&ubo), - usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, - }); - - // Create bind group - let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { - layout: &vertex_group_layout, - entries: &[wgpu::BindGroupEntry { - binding: 0, - resource: uniform_buf.as_entire_binding(), - }], - label: Some("3D Bind Group"), - }); - - let shader = device.create_shader_module(wgpu::include_wgsl!(concat!( - env!("CARGO_MANIFEST_DIR"), - "/res/shaders/app/3D/shader.wgsl" - ))); - let vertex_buffer_layout = [Vertex3D::LAYOUT]; - - let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { - label: Some("3D Renderer Pipeline"), - layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: "vs_main", - buffers: &vertex_buffer_layout, - }, - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: "fs_main", - targets: &[Some(config.format.into())], - }), - primitive: wgpu::PrimitiveState { - cull_mode: Some(wgpu::Face::Back), - front_face: wgpu::FrontFace::Cw, - ..Default::default() - }, - depth_stencil: Some(wgpu::DepthStencilState { - format: vent_assets::Texture::DEPTH_FORMAT, - depth_write_enabled: true, - depth_compare: wgpu::CompareFunction::Less, - stencil: wgpu::StencilState::default(), - bias: wgpu::DepthBiasState::default(), - }), - multisample: wgpu::MultisampleState::default(), - multiview: None, - }); - - // TODO - let pipeline_wire = if device - .features() - .contains(wgpu::Features::POLYGON_MODE_LINE) - { - let shader = device.create_shader_module(wgpu::include_wgsl!(concat!( - env!("CARGO_MANIFEST_DIR"), - "/res/shaders/app/3D/wireframe.wgsl" - ))); - - let pipeline_wire = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { - label: Some("3D Pipeline Wireframe"), - layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: "vs_main", - buffers: &[], - }, - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: "fs_main", - targets: &[Some(wgpu::ColorTargetState { - format: config.format, - blend: Some(wgpu::BlendState { - color: wgpu::BlendComponent { - operation: wgpu::BlendOperation::Add, - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - }, - alpha: wgpu::BlendComponent::REPLACE, - }), - write_mask: wgpu::ColorWrites::ALL, - })], - }), - primitive: wgpu::PrimitiveState { - cull_mode: Some(wgpu::Face::Back), - front_face: wgpu::FrontFace::Cw, - polygon_mode: wgpu::PolygonMode::Line, - ..Default::default() - }, - depth_stencil: None, - multisample: wgpu::MultisampleState::default(), - multiview: None, - }); - Some(pipeline_wire) - } else { - None - }; + // let camera: &Camera3D = camera.downcast_ref().unwrap(); + // // Create pipeline layout + // let vertex_group_layout = + // device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + // label: Some("3D Bind Group Layout"), + // entries: &[wgpu::BindGroupLayoutEntry { + // binding: 0, + // visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, + // ty: wgpu::BindingType::Buffer { + // ty: wgpu::BufferBindingType::Uniform, + // has_dynamic_offset: false, + // min_binding_size: wgpu::BufferSize::new( + // mem::size_of::() as wgpu::BufferAddress + // ), + // }, + // count: None, + // }], + // }); + + // let texture_bind_group_layout = + // device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + // entries: &[ + // wgpu::BindGroupLayoutEntry { + // binding: 0, + // visibility: wgpu::ShaderStages::FRAGMENT, + // ty: wgpu::BindingType::Texture { + // multisampled: false, + // view_dimension: wgpu::TextureViewDimension::D2, + // sample_type: wgpu::TextureSampleType::Float { filterable: true }, + // }, + // count: None, + // }, + // wgpu::BindGroupLayoutEntry { + // binding: 1, + // visibility: wgpu::ShaderStages::FRAGMENT, + // ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering), + // count: None, + // }, + // wgpu::BindGroupLayoutEntry { + // binding: 2, + // visibility: wgpu::ShaderStages::FRAGMENT, + // ty: wgpu::BindingType::Buffer { + // ty: wgpu::BufferBindingType::Uniform, + // has_dynamic_offset: false, + // min_binding_size: wgpu::BufferSize::new(mem::size_of::< + // vent_assets::model::Material, + // >() + // as wgpu::BufferAddress), + // }, + // count: None, + // }, + // ], + // label: Some("texture_bind_group_layout"), + // }); + + // let light_renderer = LightRenderer::new(device, &vertex_group_layout, config.format); + + // let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + // label: Some("3D Pipeline Layout"), + // bind_group_layouts: &[ + // &vertex_group_layout, + // &texture_bind_group_layout, + // &light_renderer.light_bind_group_layout, + // ], + // push_constant_ranges: &[], + // }); + + // // Create other resources + // let ubo = camera.ubo(); + // let uniform_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + // label: Some("Uniform Buffer"), + // contents: bytemuck::bytes_of(&ubo), + // usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, + // }); + + // // Create bind group + // let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + // layout: &vertex_group_layout, + // entries: &[wgpu::BindGroupEntry { + // binding: 0, + // resource: uniform_buf.as_entire_binding(), + // }], + // label: Some("3D Bind Group"), + // }); + + // let shader = device.create_shader_module(wgpu::include_wgsl!(concat!( + // env!("CARGO_MANIFEST_DIR"), + // "/res/shaders/app/3D/shader.wgsl" + // ))); + // let vertex_buffer_layout = [Vertex3D::LAYOUT]; + + // let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + // label: Some("3D Renderer Pipeline"), + // layout: Some(&pipeline_layout), + // vertex: wgpu::VertexState { + // module: &shader, + // entry_point: "vs_main", + // buffers: &vertex_buffer_layout, + // }, + // fragment: Some(wgpu::FragmentState { + // module: &shader, + // entry_point: "fs_main", + // targets: &[Some(config.format.into())], + // }), + // primitive: wgpu::PrimitiveState { + // cull_mode: Some(wgpu::Face::Back), + // front_face: wgpu::FrontFace::Cw, + // ..Default::default() + // }, + // depth_stencil: Some(wgpu::DepthStencilState { + // format: vent_assets::Texture::DEPTH_FORMAT, + // depth_write_enabled: true, + // depth_compare: wgpu::CompareFunction::Less, + // stencil: wgpu::StencilState::default(), + // bias: wgpu::DepthBiasState::default(), + // }), + // multisample: wgpu::MultisampleState::default(), + // multiview: None, + // }); + + // // TODO + // let pipeline_wire = if device + // .features() + // .contains(wgpu::Features::POLYGON_MODE_LINE) + // { + // let shader = device.create_shader_module(wgpu::include_wgsl!(concat!( + // env!("CARGO_MANIFEST_DIR"), + // "/res/shaders/app/3D/wireframe.wgsl" + // ))); + + // let pipeline_wire = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + // label: Some("3D Pipeline Wireframe"), + // layout: Some(&pipeline_layout), + // vertex: wgpu::VertexState { + // module: &shader, + // entry_point: "vs_main", + // buffers: &[], + // }, + // fragment: Some(wgpu::FragmentState { + // module: &shader, + // entry_point: "fs_main", + // targets: &[Some(wgpu::ColorTargetState { + // format: config.format, + // blend: Some(wgpu::BlendState { + // color: wgpu::BlendComponent { + // operation: wgpu::BlendOperation::Add, + // src_factor: wgpu::BlendFactor::SrcAlpha, + // dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + // }, + // alpha: wgpu::BlendComponent::REPLACE, + // }), + // write_mask: wgpu::ColorWrites::ALL, + // })], + // }), + // primitive: wgpu::PrimitiveState { + // cull_mode: Some(wgpu::Face::Back), + // front_face: wgpu::FrontFace::Cw, + // polygon_mode: wgpu::PolygonMode::Line, + // ..Default::default() + // }, + // depth_stencil: None, + // multisample: wgpu::MultisampleState::default(), + // multiview: None, + // }); + // Some(pipeline_wire) + // } else { + // None + // }; let mut mesh_renderer = ModelRenderer3D::default(); - // -------------- DEMO ------------------- - let mut world = World::new(); + // // -------------- DEMO ------------------- + // let mut world = World::new(); - let model = concat!( - env!("CARGO_MANIFEST_DIR"), - "/res/models/test/Sponza-GLTF/Sponza.gltf" - ); + // let model = concat!( + // env!("CARGO_MANIFEST_DIR"), + // "/res/models/test/Sponza-GLTF/Sponza.gltf" + // ); - pollster::block_on(async { - let mesh = Entity3D::new( - vent_assets::Model3D::load(device, queue, model, &texture_bind_group_layout).await, - ); - mesh_renderer.insert(world.create_entity(), mesh); - }); + // pollster::block_on(async { + // let mesh = Entity3D::new( + // vent_assets::Model3D::load(device, queue, model, &texture_bind_group_layout).await, + // ); + // mesh_renderer.insert(world.create_entity(), mesh); + // }); - // ------------------------------- + // // ------------------------------- - let tmp_light_mesh = create_tmp_cube(device); + let tmp_light_mesh = create_tmp_cube(instance); - let depth_view = vent_assets::Texture::create_depth_view( - device, - config.width, - config.height, - Some("Depth Buffer"), - ); + // let depth_view = vent_assets::Texture::create_depth_view( + // device, + // config.width, + // config.height, + // Some("Depth Buffer"), + // ); Self { mesh_renderer, - light_renderer, + // light_renderer, tmp_light_mesh, - depth_view, - bind_group, - uniform_buf, - pipeline, - pipeline_wire, + // depth_view, + // bind_group, + // uniform_buf, + // pipeline, + // pipeline_wire, } } fn resize( &mut self, - config: &wgpu::SurfaceConfiguration, - device: &wgpu::Device, - queue: &wgpu::Queue, + instance: &VulkanInstance, + new_size: &PhysicalSize, camera: &mut dyn Camera, ) { - self.depth_view = vent_assets::Texture::create_depth_view( - device, - config.width, - config.height, - Some("Depth Buffer"), - ); + // self.depth_view = vent_assets::Texture::create_depth_view( + // device, + // config.width, + // config.height, + // Some("Depth Buffer"), + // ); - let camera: &mut Camera3D = camera.downcast_mut().unwrap(); + // let camera: &mut Camera3D = camera.downcast_mut().unwrap(); - camera.recreate_projection(config.width as f32 / config.height as f32); - queue.write_buffer(&self.uniform_buf, 0, bytemuck::cast_slice(&[camera.ubo()])); + // camera.recreate_projection(config.width as f32 / config.height as f32); + // queue.write_buffer(&self.uniform_buf, 0, bytemuck::cast_slice(&[camera.ubo()])); } - fn render( - &mut self, - encoder: &mut wgpu::CommandEncoder, - view: &wgpu::TextureView, - queue: &wgpu::Queue, - camera: &mut dyn Camera, - ) { - let camera: &mut Camera3D = camera.downcast_mut().unwrap(); - - let mut ubo = camera.ubo(); - { - let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("3D Render Pass"), - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(wgpu::Color { - r: 0.1, - g: 0.2, - b: 0.3, - a: 1.0, - }), - store: true, - }, - })], - depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { - view: &self.depth_view, - depth_ops: Some(wgpu::Operations { - load: wgpu::LoadOp::Clear(1.0), - store: true, - }), - stencil_ops: None, - }), - }); - self.light_renderer - .render(&mut rpass, &self.bind_group, &self.tmp_light_mesh); - - rpass.set_pipeline(&self.pipeline); - if let Some(ref pipe) = self.pipeline_wire { - rpass.set_pipeline(pipe); - } - rpass.set_bind_group(0, &self.bind_group, &[]); - rpass.set_bind_group(2, &self.light_renderer.light_bind_group, &[]); - self.mesh_renderer.render(&mut rpass, &mut ubo); - } - queue.write_buffer(&self.uniform_buf, 0, bytemuck::cast_slice(&[ubo])); + fn render(&mut self, instance: &VulkanInstance, camera: &mut dyn Camera) { + // let camera: &mut Camera3D = camera.downcast_mut().unwrap(); + + // let mut ubo = camera.ubo(); + // { + // let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + // label: Some("3D Render Pass"), + // color_attachments: &[Some(wgpu::RenderPassColorAttachment { + // view, + // resolve_target: None, + // ops: wgpu::Operations { + // load: wgpu::LoadOp::Clear(wgpu::Color { + // r: 0.1, + // g: 0.2, + // b: 0.3, + // a: 1.0, + // }), + // store: true, + // }, + // })], + // depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + // view: &self.depth_view, + // depth_ops: Some(wgpu::Operations { + // load: wgpu::LoadOp::Clear(1.0), + // store: true, + // }), + // stencil_ops: None, + // }), + // }); + // self.light_renderer + // .render(&mut rpass, &self.bind_group, &self.tmp_light_mesh); + + // rpass.set_pipeline(&self.pipeline); + // if let Some(ref pipe) = self.pipeline_wire { + // rpass.set_pipeline(pipe); + // } + // rpass.set_bind_group(0, &self.bind_group, &[]); + // rpass.set_bind_group(2, &self.light_renderer.light_bind_group, &[]); + // self.mesh_renderer.render(&mut rpass, &mut ubo); + // } + // queue.write_buffer(&self.uniform_buf, 0, bytemuck::cast_slice(&[ubo])); } } -fn create_tmp_cube(device: &wgpu::Device) -> vent_assets::Mesh3D { +fn create_tmp_cube(instance: &VulkanInstance) -> vent_assets::Mesh3D { let indices = [ //Top 2, 6, 7, 2, 3, 7, //Bottom @@ -388,5 +381,12 @@ fn create_tmp_cube(device: &wgpu::Device) -> vent_assets::Mesh3D { }, //7 ]; - vent_assets::Mesh3D::new(device, &vertices, &indices, None, None) + vent_assets::Mesh3D::new( + &instance.device, + &instance.memory_allocator, + &vertices, + &indices, + None, + None, + ) } diff --git a/crates/vent-runtime/src/render/gui/debug_gui.rs b/crates/vent-runtime/src/render/gui/debug_gui.rs index 16c224f..aa6457a 100644 --- a/crates/vent-runtime/src/render/gui/debug_gui.rs +++ b/crates/vent-runtime/src/render/gui/debug_gui.rs @@ -1,3 +1,5 @@ +use ash::vk; + use super::GUI; pub struct RenderData { @@ -15,12 +17,12 @@ impl Default for RenderData { } pub struct DebugGUI { - adapter: wgpu::AdapterInfo, + properties: vk::PhysicalDeviceProperties, } impl DebugGUI { - pub const fn new(adapter: wgpu::AdapterInfo) -> Self { - Self { adapter } + pub const fn new(properties: vk::PhysicalDeviceProperties) -> Self { + Self { properties } } } @@ -30,12 +32,17 @@ impl GUI for DebugGUI { ui.label(format!("FPS: {}", render_data.fps)); ui.label(format!("Frame Time: {}ms", render_data.frame_time)); - // WGPU 0.17 ui.label(format!("API: {}", self.adapter.backend)); - ui.label(format!("Device: {}", self.adapter.name)); - // WGPU 0.17 ui.label(format!("Device Type: {}", self.adapter.device_type)); ui.label(format!( - "Device Driver: {}, Info {}", - self.adapter.driver, self.adapter.driver_info + "Device: {}", + format!("{:?}", self.properties.device_name) + )); + ui.label(format!( + "Device Type: {}", + format!("{:?}", self.properties.device_type) + )); + ui.label(format!( + "Driver: {}, API Version: {}", + self.properties.driver_version, self.properties.api_version )); }); } diff --git a/crates/vent-runtime/src/render/gui/gui_renderer.rs b/crates/vent-runtime/src/render/gui/gui_renderer.rs index b4869f9..69596a7 100644 --- a/crates/vent-runtime/src/render/gui/gui_renderer.rs +++ b/crates/vent-runtime/src/render/gui/gui_renderer.rs @@ -1,85 +1,74 @@ +use vent_rendering::instance::VulkanInstance; +use winit::raw_window_handle::DisplayHandle; + use super::{debug_gui::RenderData, GUI}; pub struct EguiRenderer { - renderer: egui_wgpu::Renderer, + // renderer: egui_winit_ash_integration::Integration, context: egui::Context, - state: egui_winit::State, - + // state: egui_winit::State, guis: Vec>, } impl EguiRenderer { - pub fn new( - event_loop: &winit::event_loop::EventLoopWindowTarget<()>, - device: &wgpu::Device, - surface_format: wgpu::TextureFormat, - ) -> Self { - let renderer = egui_wgpu::Renderer::new(device, surface_format, None, 1); + pub fn new() -> Self { + //let renderer = egui_winit_ash_integration::Integration::new(event_loop, ); let context = egui::Context::default(); - let state = egui_winit::State::new(event_loop); + // let state = egui_winit::State::new(event_loop); Self { - renderer, context, - state, + // state, guis: Vec::new(), } } - pub fn render( - &mut self, - view: &wgpu::TextureView, - window: &winit::window::Window, - device: &wgpu::Device, - queue: &wgpu::Queue, - encoder: &mut wgpu::CommandEncoder, - render_data: &RenderData, - ) { - let input = self.state.take_egui_input(window); - let output = self.context.run(input, |ctx| { - for gui in self.guis.iter_mut() { - gui.update(ctx, render_data); - } - }); - - self.state - .handle_platform_output(window, &self.context, output.platform_output); - - let clipped_meshes = self.context.tessellate(output.shapes); - - for (texture_id, image_delta) in output.textures_delta.set { - self.renderer - .update_texture(device, queue, texture_id, &image_delta); - } - - let screen_descriptor = egui_wgpu::renderer::ScreenDescriptor { - size_in_pixels: window.inner_size().into(), - pixels_per_point: self.context.pixels_per_point(), - }; - - self.renderer - .update_buffers(device, queue, encoder, &clipped_meshes, &screen_descriptor); - - let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("GUI Render Pass"), - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Load, - store: true, - }, - })], - depth_stencil_attachment: None, - }); - - self.renderer - .render(&mut render_pass, &clipped_meshes, &screen_descriptor); - - drop(render_pass); - - for texture_id in output.textures_delta.free { - self.renderer.free_texture(&texture_id); - } + pub fn render(&mut self, render_data: &RenderData) { + // let input = self.state.take_egui_input(window); + // let output = self.context.run(input, |ctx| { + // for gui in self.guis.iter_mut() { + // gui.update(ctx, render_data); + // } + // }); + + // self.state + // .handle_platform_output(window, &self.context, output.platform_output); + + // let clipped_meshes = self.context.tessellate(output.shapes); + + // for (texture_id, image_delta) in output.textures_delta.set { + // self.renderer + // .update_texture(device, queue, texture_id, &image_delta); + // } + + // let screen_descriptor = egui_wgpu::renderer::ScreenDescriptor { + // size_in_pixels: window.inner_size().into(), + // pixels_per_point: self.context.pixels_per_point(), + // }; + + // self.renderer + // .update_buffers(device, queue, encoder, &clipped_meshes, &screen_descriptor); + + // let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + // label: Some("GUI Render Pass"), + // color_attachments: &[Some(wgpu::RenderPassColorAttachment { + // view, + // resolve_target: None, + // ops: wgpu::Operations { + // load: wgpu::LoadOp::Load, + // store: true, + // }, + // })], + // depth_stencil_attachment: None, + // }); + + // self.renderer + // .render(&mut render_pass, &clipped_meshes, &screen_descriptor); + + // drop(render_pass); + + // for texture_id in output.textures_delta.free { + // self.renderer.free_texture(&texture_id); + // } } pub fn add_gui(mut self, gui: Box) -> Self { @@ -89,20 +78,15 @@ impl EguiRenderer { #[inline] #[allow(dead_code)] - pub fn register_texture( - &mut self, - device: &wgpu::Device, - texture: &wgpu::TextureView, - sampler_descriptor: wgpu::SamplerDescriptor<'_>, - ) -> egui::TextureId { - self.renderer.register_native_texture_with_sampler_options( - device, - texture, - sampler_descriptor, - ) + pub fn register_texture(&mut self) { + // self.renderer.register_native_texture_with_sampler_options( + // device, + // texture, + // sampler_descriptor, + // ) } - pub fn progress_event(&mut self, event: &winit::event::WindowEvent<'_>) { - let _ = self.state.on_event(&self.context, event); + pub fn progress_event(&mut self, event: &winit::event::WindowEvent) { + // let _ = self.state.on_event(&self.context, event); } } diff --git a/crates/vent-runtime/src/render/mod.rs b/crates/vent-runtime/src/render/mod.rs index babb96c..dfd1e55 100644 --- a/crates/vent-runtime/src/render/mod.rs +++ b/crates/vent-runtime/src/render/mod.rs @@ -1,7 +1,5 @@ use std::time::{Duration, Instant}; -use vent_common::render::WGPURenderer; - use vent_rendering::instance::VulkanInstance; use winit::dpi::PhysicalSize; use winit::window::Window; @@ -34,14 +32,14 @@ impl DefaultRuntimeRenderer { camera: &mut dyn Camera, ) -> Self { let instance = VulkanInstance::new("TODO", window); - let runtime_renderer = RawRuntimeRenderer::new(dimension, instance, event_loop, camera); + let runtime_renderer = RawRuntimeRenderer::new(dimension, &instance, event_loop, camera); Self { instance, runtime_renderer, } } - pub(crate) fn progress_event(&mut self, event: &winit::event::WindowEvent<'_>) { + pub(crate) fn progress_event(&mut self, event: &winit::event::WindowEvent) { self.runtime_renderer.progress_event(event); } @@ -50,30 +48,14 @@ impl DefaultRuntimeRenderer { window: &winit::window::Window, camera: &mut dyn Camera, ) -> f32 { - let output = self.wgpu_renderer.surface.get_current_texture().unwrap(); // TODO - - let view: wgpu::TextureView = output.texture.create_view(&wgpu::TextureViewDescriptor { - label: Some("Runtime View"), - ..Default::default() - }); - - let detla = self - .runtime_renderer - .render(&view, self.instance, window, camera); - - output.present(); + let detla = self.runtime_renderer.render(&self.instance, window, camera); detla } pub(crate) fn resize(&mut self, new_size: &PhysicalSize, camera: &mut dyn Camera) { - self.runtime_renderer.resize( - &self.wgpu_renderer.device, - &self.wgpu_renderer.queue, - &self.wgpu_renderer.config, - new_size, - camera, - ); + self.runtime_renderer + .resize(&self.instance, new_size, camera); } } @@ -83,30 +65,18 @@ pub enum Dimension { } pub trait Renderer { - fn init( - config: &wgpu::SurfaceConfiguration, - device: &wgpu::Device, - queue: &wgpu::Queue, - camera: &mut dyn Camera, - ) -> Self + fn init(instance: &VulkanInstance, camera: &mut dyn Camera) -> Self where Self: Sized; fn resize( &mut self, - config: &wgpu::SurfaceConfiguration, - device: &wgpu::Device, - queue: &wgpu::Queue, + instance: &VulkanInstance, + new_size: &PhysicalSize, camera: &mut dyn Camera, ); - fn render( - &mut self, - encoder: &mut wgpu::CommandEncoder, - view: &wgpu::TextureView, - queue: &wgpu::Queue, - camera: &mut dyn Camera, - ); + fn render(&mut self, instance: &VulkanInstance, camera: &mut dyn Camera); } pub struct RawRuntimeRenderer { @@ -123,7 +93,7 @@ pub struct RawRuntimeRenderer { impl RawRuntimeRenderer { pub fn new( dimension: Dimension, - instance: VulkanInstance, + instance: &VulkanInstance, event_loop: &winit::event_loop::EventLoopWindowTarget<()>, camera: &mut dyn Camera, ) -> Self { @@ -131,9 +101,13 @@ impl RawRuntimeRenderer { Dimension::D2 => Box::new(Renderer2D::init(instance, camera)), Dimension::D3 => Box::new(Renderer3D::init(instance, camera)), }; - let egui = EguiRenderer::new(event_loop, device, surface_format) + let egui = EguiRenderer::new() // TODO - .add_gui(Box::new(DebugGUI::new(adapter.get_info()))); + .add_gui(Box::new(DebugGUI::new(unsafe { + instance + .instance + .get_physical_device_properties(instance.physical_device) + }))); Self { multi_renderer, @@ -147,22 +121,13 @@ impl RawRuntimeRenderer { pub fn render( &mut self, - instance: VulkanInstance, + instance: &VulkanInstance, window: &Window, camera: &mut dyn Camera, ) -> f32 { let frame_start = Instant::now(); - let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { - label: Some("Runtime Render Encoder"), - }); - // let mut encoder2 = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { - // label: Some("EGUI Render Encoder"), - // }); - - self.multi_renderer - .render(&mut encoder, surface_view, queue, camera); - queue.submit(Some(encoder.finish())); + self.multi_renderer.render(instance, camera); // self.gui_renderer.render( // surface_view, @@ -214,19 +179,17 @@ impl RawRuntimeRenderer { } } - pub fn progress_event(&mut self, event: &winit::event::WindowEvent<'_>) { + pub fn progress_event(&mut self, event: &winit::event::WindowEvent) { self.gui_renderer.progress_event(event); } pub fn resize( &mut self, - device: &wgpu::Device, - queue: &wgpu::Queue, - config: &wgpu::SurfaceConfiguration, - _new_size: &PhysicalSize, + instance: &VulkanInstance, + new_size: &PhysicalSize, camera: &mut dyn Camera, ) { // Uses the NEW Resized config - self.multi_renderer.resize(config, device, queue, camera) + self.multi_renderer.resize(instance, new_size, camera) } } diff --git a/crates/vent-runtime/src/render/model_renderer.rs b/crates/vent-runtime/src/render/model_renderer.rs index fdf38d6..7e5aa22 100644 --- a/crates/vent-runtime/src/render/model_renderer.rs +++ b/crates/vent-runtime/src/render/model_renderer.rs @@ -1,6 +1,8 @@ +use ash::vk; use glam::{Mat4, Quat}; use std::collections::HashMap; use vent_ecs::entity::Entity; +use vent_rendering::instance::VulkanInstance; use super::{d3::UBO3D, model::Entity3D}; @@ -45,10 +47,19 @@ impl ModelRenderer3D { self.map.iter_mut() } - pub fn render(, ubo: &mut UBO3D) { + pub fn render( + &self, + instance: VulkanInstance, + pipeline_layout: vk::PipelineLayout, + ubo: &mut UBO3D, + ) { for model in self.map.values() { ubo.transformation = Self::calc_trans_matrix(model).to_cols_array_2d(); - model.rendering_model.draw(rpass); + for (i, buffer) in instance.command_buffers.iter().enumerate() { + model + .rendering_model + .draw(&instance.device, pipeline_layout, *buffer, i as u32); + } } } From 08d4d67d1425d4b11f2d4e92a58b97ab70bcf562 Mon Sep 17 00:00:00 2001 From: Snowiiii <71594357+Snowiiii@users.noreply.github.com> Date: Sat, 18 Nov 2023 17:28:08 +0100 Subject: [PATCH 05/14] Some Changes --- Cargo.lock | 413 ++++++++---------- crates/vent-assets/Cargo.toml | 2 - crates/vent-assets/src/lib.rs | 4 +- crates/vent-assets/src/model/gltf.rs | 97 ++-- crates/vent-assets/src/model/mod.rs | 70 ++- crates/vent-assets/src/model/obj.rs | 27 +- crates/vent-common/Cargo.toml | 22 +- crates/vent-editor/Cargo.toml | 2 +- crates/vent-editor/src/gui/mod.rs | 4 +- crates/vent-editor/src/main.rs | 2 +- .../src/render/runtime_renderer.rs | 4 +- crates/vent-rendering/Cargo.toml | 3 +- crates/vent-rendering/src/buffer.rs | 47 +- crates/vent-rendering/src/debug.rs | 95 ++++ crates/vent-rendering/src/image.rs | 185 +++++--- crates/vent-rendering/src/instance.rs | 229 +++++----- crates/vent-rendering/src/lib.rs | 34 +- crates/vent-rendering/src/pipeline.rs | 20 +- crates/vent-rendering/src/surface.rs | 6 +- crates/vent-runtime/Cargo.toml | 3 - crates/vent-runtime/build.rs | 108 ++++- .../res/shaders/app/3D/shader.frag | 55 +++ .../res/shaders/app/3D/shader.frag.spv | Bin 0 -> 2852 bytes .../res/shaders/app/3D/shader.vert | 30 ++ .../res/shaders/app/3D/shader.vert.spv | Bin 0 -> 2132 bytes .../res/shaders/app/3D/shader.wgsl | 76 ---- crates/vent-runtime/src/lib.rs | 24 +- .../src/render/camera/camera_controller3d.rs | 2 +- crates/vent-runtime/src/render/camera/mod.rs | 38 +- crates/vent-runtime/src/render/d2/mod.rs | 20 +- .../src/render/d3/light_renderer.rs | 15 +- crates/vent-runtime/src/render/d3/mod.rs | 396 ++++++++--------- .../src/render/gui/gui_renderer.rs | 7 +- crates/vent-runtime/src/render/mod.rs | 54 ++- .../vent-runtime/src/render/model_renderer.rs | 25 +- 35 files changed, 1246 insertions(+), 873 deletions(-) create mode 100644 crates/vent-rendering/src/debug.rs create mode 100644 crates/vent-runtime/res/shaders/app/3D/shader.frag create mode 100644 crates/vent-runtime/res/shaders/app/3D/shader.frag.spv create mode 100644 crates/vent-runtime/res/shaders/app/3D/shader.vert create mode 100644 crates/vent-runtime/res/shaders/app/3D/shader.vert.spv delete mode 100644 crates/vent-runtime/res/shaders/app/3D/shader.wgsl diff --git a/Cargo.lock b/Cargo.lock index 864c144..839b028 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "ab_glyph" -version = "0.2.22" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1061f3ff92c2f65800df1f12fc7b4ff44ee14783104187dd04dfee6f11b0fd2" +checksum = "80179d7dd5d7e8c285d67c4a1e652972a92de7475beddfb92028c76463b13225" dependencies = [ "ab_glyph_rasterizer", "owned_ttf_parser", @@ -18,15 +18,6 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - [[package]] name = "adler" version = "1.0.2" @@ -35,14 +26,15 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.8.3" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" dependencies = [ "cfg-if", "getrandom", "once_cell", "version_check", + "zerocopy", ] [[package]] @@ -70,7 +62,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "052ad56e336bcc615a214bffbeca6c181ee9550acec193f0327e0b103b033a4d" dependencies = [ "android-properties", - "bitflags 2.4.0", + "bitflags 2.4.1", "cc", "cesu8", "jni", @@ -105,12 +97,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - [[package]] name = "arboard" version = "3.2.1" @@ -164,21 +150,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "backtrace" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - [[package]] name = "base64" version = "0.13.1" @@ -199,9 +170,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "block" @@ -258,20 +229,6 @@ name = "bytemuck" version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" -dependencies = [ - "bytemuck_derive", -] - -[[package]] -name = "bytemuck_derive" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] [[package]] name = "byteorder" @@ -305,7 +262,7 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b50b5a44d59a98c55a9eeb518f39bf7499ba19fd98ee7d22618687f3f10adbf" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "log", "polling", "rustix", @@ -414,26 +371,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "console_error_panic_hook" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" -dependencies = [ - "cfg-if", - "wasm-bindgen", -] - -[[package]] -name = "console_log" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8aed40e4edbf4d3b4431ab260b63fdc40f5780a4766824329ea0f1eefe3c0f" -dependencies = [ - "log", - "web-sys", -] - [[package]] name = "core-foundation" version = "0.9.3" @@ -537,15 +474,18 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "cursor-icon" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf" +checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" [[package]] name = "deranged" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +dependencies = [ + "powerfmt", +] [[package]] name = "dispatch" @@ -612,25 +552,11 @@ dependencies = [ "winit 0.28.7", ] -[[package]] -name = "egui-winit-ash-integration" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ff65673b6cfcdc14b64ec326862187bd721bb09028667c906b45ceecc53fcf2" -dependencies = [ - "anyhow", - "ash", - "bytemuck", - "egui", - "egui-winit", - "gpu-allocator", -] - [[package]] name = "egui_dock" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "681b082103898f874b509c0e5ed642c5001ff272bb7adcef32d3d920c26dcf08" +checksum = "a52f67bcab0eb6050cf8051c614966c1c57129fab23dbeae9c157214779053c7" dependencies = [ "duplicate", "egui", @@ -672,9 +598,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" +checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8" dependencies = [ "libc", "windows-sys 0.48.0", @@ -708,18 +634,18 @@ dependencies = [ [[package]] name = "fdeflate" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d329bdeac514ee06249dabc27877490f17f5d371ec693360768b838e19f3ae10" +checksum = "64d6dafc854908ff5da46ff3f8f473c6984119a2876a383a860246dd7841a868" dependencies = [ "simd-adler32", ] [[package]] name = "flate2" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" dependencies = [ "crc32fast", "miniz_oxide", @@ -761,7 +687,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -813,9 +739,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" dependencies = [ "cfg-if", "libc", @@ -832,12 +758,6 @@ dependencies = [ "weezl", ] -[[package]] -name = "gimli" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" - [[package]] name = "glam" version = "0.24.2" @@ -867,7 +787,7 @@ dependencies = [ "inflections", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -882,19 +802,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "gpu-allocator" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40fe17c8a05d60c38c0a4e5a3c802f2f1ceb66b76c67d96ffb34bef0475a7fad" -dependencies = [ - "ash", - "backtrace", - "log", - "presser", - "thiserror", -] - [[package]] name = "half" version = "2.2.1" @@ -906,9 +813,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" +checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" [[package]] name = "heck" @@ -933,16 +840,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.57" +version = "0.1.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows", + "windows-core", ] [[package]] @@ -996,9 +903,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", "hashbrown", @@ -1063,9 +970,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" [[package]] name = "jobserver" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" dependencies = [ "libc", ] @@ -1081,9 +988,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" dependencies = [ "wasm-bindgen", ] @@ -1102,9 +1009,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.149" +version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "libloading" @@ -1126,17 +1033,28 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "libredox" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607" +dependencies = [ + "bitflags 2.4.1", + "libc", + "redox_syscall 0.4.1", +] + [[package]] name = "linux-raw-sys" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" +checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard", @@ -1226,9 +1144,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" dependencies = [ "libc", "log", @@ -1256,7 +1174,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2076a31b7010b17a38c01907c45b945e8f11495ee4dd588309718901b1f7a5b7" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "jni-sys", "log", "ndk-sys 0.5.0+25.2.9519653", @@ -1414,7 +1332,7 @@ version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -1426,10 +1344,10 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -1438,10 +1356,10 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c11e44798ad209ccdd91fc192f0526a369a01234f7373e1b141c96d7cee4f0e" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 2.0.0", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -1530,15 +1448,6 @@ dependencies = [ "objc", ] -[[package]] -name = "object" -version = "0.32.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.18.0" @@ -1547,18 +1456,18 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "orbclient" -version = "0.3.46" +version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8378ac0dfbd4e7895f2d2c1f1345cab3836910baf3a300b000d04250f0c8428f" +checksum = "52f0d54bde9774d3a51dcf281a5def240c71996bc6ca05d2c847ec8b2b216166" dependencies = [ - "redox_syscall 0.3.5", + "libredox", ] [[package]] name = "owned_ttf_parser" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "706de7e2214113d63a8238d1910463cfce781129a6f263d13fdb09ff64355ba4" +checksum = "d4586edfe4c648c71797a74c84bacb32b52b212eff5dfe2bb9f2c599844023e7" dependencies = [ "ttf-parser", ] @@ -1644,10 +1553,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2" [[package]] -name = "presser" -version = "0.3.1" +name = "powerfmt" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "proc-macro-crate" @@ -1656,7 +1565,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell", - "toml_edit", + "toml_edit 0.19.15", +] + +[[package]] +name = "proc-macro-crate" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" +dependencies = [ + "toml_edit 0.20.7", ] [[package]] @@ -1777,19 +1695,13 @@ dependencies = [ "vent-runtime", ] -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - [[package]] name = "rustix" -version = "0.38.18" +version = "0.38.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a74ee2d7c2581cd139b42447d7d9389b889bdaad3a73f1ebb16f2a3237bb19c" +checksum = "9ad981d6c340a49cdc40a1028d9c6084ec7e9fa33fcb839cab656a267071e234" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", @@ -1851,29 +1763,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.188" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] name = "serde_json" -version = "1.0.107" +version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" dependencies = [ "itoa", "ryu", @@ -1918,9 +1830,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.1" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "smithay-client-toolkit" @@ -1947,7 +1859,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60e3d9941fa3bacf7c2bf4b065304faa14164151254cd16ce1b1bc8fc381600f" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "calloop 0.12.3", "calloop-wayland-source", "cursor-icon", @@ -2019,9 +1931,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" dependencies = [ "proc-macro2", "quote", @@ -2045,22 +1957,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -2076,14 +1988,15 @@ dependencies = [ [[package]] name = "time" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe" +checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" dependencies = [ "deranged", "itoa", "libc", "num_threads", + "powerfmt", "serde", "time-core", "time-macros", @@ -2180,9 +2093,9 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" [[package]] name = "toml_edit" @@ -2195,28 +2108,38 @@ dependencies = [ "winnow", ] +[[package]] +name = "toml_edit" +version = "0.20.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if", "pin-project-lite", "tracing-core", ] [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" [[package]] name = "ttf-parser" -version = "0.19.2" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49d64318d8311fc2668e48b63969f4343e0a85c4a109aa8460d6672e364b8bd1" +checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" [[package]] name = "unicode-bidi" @@ -2273,8 +2196,6 @@ name = "vent-assets" version = "0.1.0" dependencies = [ "ash", - "bytemuck", - "cfg-if", "gltf", "image", "log", @@ -2288,16 +2209,11 @@ name = "vent-common" version = "0.1.0" dependencies = [ "chrono", - "console_error_panic_hook", - "console_log", "image", "log", "serde", "serde_json", "sysinfo", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", "winit 0.29.3", ] @@ -2329,8 +2245,8 @@ name = "vent-rendering" version = "0.1.0" dependencies = [ "ash", - "bytemuck", "image", + "log", "raw-window-handle 0.6.0", "winit 0.29.3", ] @@ -2339,13 +2255,10 @@ dependencies = [ name = "vent-runtime" version = "0.1.0" dependencies = [ - "anyhow", "ash", - "bytemuck", "downcast-rs", "egui", "egui-winit", - "egui-winit-ash-integration", "fs_extra", "glam", "log", @@ -2386,9 +2299,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2396,24 +2309,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.37" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" dependencies = [ "cfg-if", "js-sys", @@ -2423,9 +2336,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2433,22 +2346,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" [[package]] name = "wayland-backend" @@ -2486,7 +2399,7 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ca7d52347346f5473bf2f56705f360e8440873052e575e55890c4fa57843ed3" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "nix 0.26.4", "wayland-backend", "wayland-scanner 0.31.0", @@ -2510,7 +2423,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "cursor-icon", "wayland-backend", ] @@ -2555,7 +2468,7 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e253d7107ba913923dc253967f35e8561a3c65f914543e46843c88ddd729e21c" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "wayland-backend", "wayland-client 0.31.1", "wayland-scanner 0.31.0", @@ -2567,7 +2480,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23803551115ff9ea9bce586860c5c5a971e360825a0309264102a9495a5ff479" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "wayland-backend", "wayland-client 0.31.1", "wayland-protocols 0.31.0", @@ -2580,7 +2493,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "wayland-backend", "wayland-client 0.31.1", "wayland-protocols 0.31.0", @@ -2634,9 +2547,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.64" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" dependencies = [ "js-sys", "wasm-bindgen", @@ -2716,10 +2629,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "windows" -version = "0.48.0" +name = "windows-core" +version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" dependencies = [ "windows-targets 0.48.5", ] @@ -2915,7 +2828,7 @@ dependencies = [ "ahash", "android-activity 0.5.0", "atomic-waker", - "bitflags 2.4.0", + "bitflags 2.4.1", "bytemuck", "calloop 0.12.3", "cfg_aliases", @@ -2956,9 +2869,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.5.16" +version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037711d82167854aff2018dfd193aa0fef5370f456732f0d5a0c59b0f1b4b907" +checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b" dependencies = [ "memchr", ] @@ -3037,7 +2950,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6924668544c48c0133152e7eec86d644a056ca3d09275eb8d5cdb9855f9d8699" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "dlib", "log", "once_cell", @@ -3056,6 +2969,26 @@ version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" +[[package]] +name = "zerocopy" +version = "0.7.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e97e415490559a91254a2979b4829267a57d2fcd741a98eee8b722fb57289aa0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + [[package]] name = "zune-inflate" version = "0.2.54" diff --git a/crates/vent-assets/Cargo.toml b/crates/vent-assets/Cargo.toml index fd3c6a5..5399325 100644 --- a/crates/vent-assets/Cargo.toml +++ b/crates/vent-assets/Cargo.toml @@ -11,9 +11,7 @@ vent-rendering = { path = "../vent-rendering"} image = "0.24.7" -bytemuck = { version = "1.14.0" } log = "0.4" -cfg-if = "1" ash = { version= "0.37.3", default-features = false, features = ["linked"] } diff --git a/crates/vent-assets/src/lib.rs b/crates/vent-assets/src/lib.rs index 36aba44..dce77f6 100644 --- a/crates/vent-assets/src/lib.rs +++ b/crates/vent-assets/src/lib.rs @@ -11,6 +11,8 @@ pub trait Asset {} /// This is done by Parsing all Essensial Informations like Vertices, Indices, Materials & More pub struct Model3D { meshes: Vec, + write_sets: Vec, + buffers: Vec, } /// This is a simple mesh that consists of vertices and indices. It is useful when you need to hard-code 3D data into your application. @@ -23,6 +25,4 @@ pub struct Mesh3D { vertex_buf: VulkanBuffer, index_buf: VulkanBuffer, index_count: u32, - - descriptor_sets: Option>, } diff --git a/crates/vent-assets/src/model/gltf.rs b/crates/vent-assets/src/model/gltf.rs index 7d87f12..b79a0b5 100644 --- a/crates/vent-assets/src/model/gltf.rs +++ b/crates/vent-assets/src/model/gltf.rs @@ -13,7 +13,7 @@ use vent_rendering::{ use crate::Model3D; -use super::{Material, Mesh3D, ModelError}; +use super::{Light, Material, Mesh3D, ModelError}; pub(crate) struct GLTFLoader {} @@ -159,29 +159,27 @@ impl GLTFLoader { let binding = Material { base_color: pbr.base_color_factor(), }; - let buffer_data = bytemuck::bytes_of(&binding); - let mut uniform_buffers = vec![]; - Self::create_uniform_buffers(instance, buffer_data, &mut uniform_buffers); + let mut uniform_buffers = Self::create_uniform_buffers(instance, &binding); Self::write_sets(instance, diffuse_texture, &uniform_buffers) } - fn create_uniform_buffers( - instance: &VulkanInstance, - data: &[u8], - uniform_buffers: &mut Vec, - ) { + fn create_uniform_buffers(instance: &VulkanInstance, material: &Material) -> Vec { + let mut uniform_buffers = vec![]; for _ in 0..instance.swapchain_images.len() { - let buffer = VulkanBuffer::new_init( - &instance.device, - &instance.memory_allocator, - size_of::() as u64, - vk::BufferUsageFlags::UNIFORM_BUFFER, - data, - ); + let buffer = unsafe { + VulkanBuffer::new_init_type( + &instance.device, + &instance.memory_allocator, + size_of::() as vk::DeviceSize, + vk::BufferUsageFlags::UNIFORM_BUFFER, + material, + ) + }; uniform_buffers.push(buffer) } + uniform_buffers } fn write_sets( @@ -193,7 +191,7 @@ impl GLTFLoader { &instance.device, instance.descriptor_pool, instance.descriptor_set_layout, - &instance.swapchain_images, + uniforms_buffers.len(), ); for (i, &_descritptor_set) in descriptor_sets.iter().enumerate() { @@ -203,29 +201,58 @@ impl GLTFLoader { .sampler(diffuse_texture.sampler) .build(); - let _sampler_write = vk::WriteDescriptorSet::builder() - .dst_set(descriptor_sets[i]) - .dst_binding(0) - .dst_array_element(0) - .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) - .image_info(&[image_info]); - - let buffer_info = vk::DescriptorBufferInfo::builder() + let material_buffer_info = vk::DescriptorBufferInfo::builder() .buffer(uniforms_buffers[i].buffer) .offset(0) - .range(size_of::() as u64) + .range(size_of::() as vk::DeviceSize) .build(); - let ubo_write = vk::WriteDescriptorSet::builder() - .dst_set(descriptor_sets[i]) - .dst_binding(1) - .dst_array_element(0) - .descriptor_type(vk::DescriptorType::UNIFORM_BUFFER) - .buffer_info(&[buffer_info]) + let light_buffer_info = vk::DescriptorBufferInfo::builder() + .buffer(uniforms_buffers[i].buffer) + .offset(0) + .range(size_of::() as vk::DeviceSize) .build(); + let desc_sets = [ + // Vertex + vk::WriteDescriptorSet { + dst_set: descriptor_sets[0], + dst_binding: 0, + descriptor_count: 1, + descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + p_buffer_info: &buffer_info, + ..Default::default() + }, + // Fragment + vk::WriteDescriptorSet { + dst_set: descriptor_sets[0], + descriptor_count: 1, + descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, + p_image_info: &image_info, + ..Default::default() + }, + vk::WriteDescriptorSet { + dst_set: descriptor_sets[0], + dst_binding: 1, + descriptor_count: 1, + descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + p_buffer_info: &material_buffer_info, + ..Default::default() + }, + vk::WriteDescriptorSet { + dst_set: descriptor_sets[0], + dst_binding: 2, + descriptor_count: 1, + descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + p_buffer_info: &light_buffer_info, + ..Default::default() + }, + ]; + unsafe { - instance.device.update_descriptor_sets(&[ubo_write], &[]); + instance + .device + .update_descriptor_sets(&fragment_desc_sets, &[]); } } descriptor_sets @@ -249,11 +276,11 @@ impl GLTFLoader { ), |filter| match filter { gltf::texture::MinFilter::Nearest => { - (vk::Filter::NEAREST, vk::SamplerMipmapMode::LINEAR) + (vk::Filter::NEAREST, vk::SamplerMipmapMode::NEAREST) } gltf::texture::MinFilter::Linear | gltf::texture::MinFilter::LinearMipmapNearest => { - (vk::Filter::LINEAR, vk::SamplerMipmapMode::LINEAR) + (vk::Filter::LINEAR, vk::SamplerMipmapMode::NEAREST) } gltf::texture::MinFilter::NearestMipmapNearest => { (vk::Filter::NEAREST, vk::SamplerMipmapMode::NEAREST) diff --git a/crates/vent-assets/src/model/mod.rs b/crates/vent-assets/src/model/mod.rs index 0b704ac..74c2df5 100644 --- a/crates/vent-assets/src/model/mod.rs +++ b/crates/vent-assets/src/model/mod.rs @@ -2,7 +2,6 @@ use std::mem::size_of; use std::path::Path; use ash::vk; -use bytemuck::{Pod, Zeroable}; use vent_rendering::allocator::MemoryAllocator; use vent_rendering::buffer::VulkanBuffer; use vent_rendering::instance::VulkanInstance; @@ -25,11 +24,22 @@ pub enum ModelError { } #[repr(C)] -#[derive(Clone, Copy, Pod, Zeroable)] +#[derive(Clone, Copy)] pub struct Material { pub base_color: [f32; 4], } +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Light { + position: [f32; 3], + // Due to uniforms requiring 16 byte (4 float) spacing, we need to use a padding field here + _padding: u32, + color: [f32; 3], + // Due to uniforms requiring 16 byte (4 float) spacing, we need to use a padding field here + _padding2: u32, +} + impl Model3D { #[inline] pub async fn load>(instance: &VulkanInstance, path: P) -> Self { @@ -51,7 +61,7 @@ impl Model3D { device: &ash::Device, pipeline_layout: vk::PipelineLayout, command_buffer: vk::CommandBuffer, - buffer_index: u32, + buffer_index: usize, ) { self.meshes.iter().for_each(|mesh| { // rpass.push_debug_group("Bind Mesh"); @@ -61,6 +71,12 @@ impl Model3D { mesh.draw(device, command_buffer); }) } + + pub fn destroy(&mut self, instance: &VulkanInstance) { + self.meshes + .iter_mut() + .for_each(|mesh| mesh.destroy(instance.descriptor_pool, &instance.device)); + } } async fn load_model_from_path( @@ -90,21 +106,25 @@ impl Mesh3D { descriptor_sets: Option>, _name: Option<&str>, ) -> Self { - let vertex_buf = VulkanBuffer::new_init( - device, - allocator, - std::mem::size_of_val(vertices) as vk::DeviceSize, - vk::BufferUsageFlags::VERTEX_BUFFER, - bytemuck::cast_slice(vertices), - ); - - let index_buf = VulkanBuffer::new_init( - device, - allocator, - (size_of::() * indices.len()) as vk::DeviceSize, - vk::BufferUsageFlags::INDEX_BUFFER, - bytemuck::cast_slice(indices), - ); + let vertex_buf = unsafe { + VulkanBuffer::new_init_type( + device, + allocator, + std::mem::size_of_val(vertices) as vk::DeviceSize, + vk::BufferUsageFlags::VERTEX_BUFFER, + vertices.as_ptr(), + ) + }; + + let index_buf = unsafe { + VulkanBuffer::new_init_type( + device, + allocator, + (size_of::() * indices.len()) as vk::DeviceSize, // TODO + vk::BufferUsageFlags::INDEX_BUFFER, + indices.as_ptr(), + ) + }; Self { vertex_buf, @@ -118,7 +138,7 @@ impl Mesh3D { &self, device: &ash::Device, command_buffer: vk::CommandBuffer, - buffer_index: u32, + buffer_index: usize, pipeline_layout: vk::PipelineLayout, with_descriptor_set: bool, ) { @@ -132,7 +152,7 @@ impl Mesh3D { vk::PipelineBindPoint::GRAPHICS, pipeline_layout, 0, - &[ds[buffer_index as usize]], + &[ds[buffer_index]], &[], ) } @@ -144,11 +164,15 @@ impl Mesh3D { unsafe { device.cmd_draw_indexed(command_buffer, self.index_count, 1, 0, 0, 0) }; } - pub fn destroy(self, descriptor_pool: vk::DescriptorPool, device: &ash::Device) { + pub fn destroy(&mut self, descriptor_pool: vk::DescriptorPool, device: &ash::Device) { self.vertex_buf.destroy(device); self.index_buf.destroy(device); - if let Some(ds) = self.descriptor_sets { - unsafe { device.free_descriptor_sets(descriptor_pool, &ds) }; + if let Some(ds) = &self.descriptor_sets { + unsafe { + device + .free_descriptor_sets(descriptor_pool, &ds) + .expect("Failed to free Descriptor") + }; } } } diff --git a/crates/vent-assets/src/model/obj.rs b/crates/vent-assets/src/model/obj.rs index 97ce3f0..15267e8 100644 --- a/crates/vent-assets/src/model/obj.rs +++ b/crates/vent-assets/src/model/obj.rs @@ -45,7 +45,7 @@ impl OBJLoader { instance: &VulkanInstance, model_dir: &Path, material: &tobj::Material, - ) -> Vec { + ) -> Vec { let diffuse_texture = if let Some(texture) = &material.diffuse_texture { VulkanImage::from_image( &instance.device, @@ -70,27 +70,28 @@ impl OBJLoader { let binding = Material { base_color: [diffuse[0], diffuse[1], diffuse[2], 1.0], }; - let buffer_data = bytemuck::bytes_of(&binding); let mut uniform_buffers = vec![]; - Self::create_uniform_buffers(instance, buffer_data, &mut uniform_buffers); + Self::create_uniform_buffers(instance, &binding, &mut uniform_buffers); Self::write_sets(instance, diffuse_texture, &uniform_buffers) } fn create_uniform_buffers( instance: &VulkanInstance, - data: &[u8], + material: &Material, uniform_buffers: &mut Vec, ) { for _ in 0..instance.swapchain_images.len() { - let buffer = VulkanBuffer::new_init( - &instance.device, - &instance.memory_allocator, - size_of::() as u64, - vk::BufferUsageFlags::UNIFORM_BUFFER, - data, - ); + let buffer = unsafe { + VulkanBuffer::new_init_type( + &instance.device, + &instance.memory_allocator, + size_of::() as vk::DeviceSize, + vk::BufferUsageFlags::UNIFORM_BUFFER, + material, + ) + }; uniform_buffers.push(buffer) } } @@ -104,7 +105,7 @@ impl OBJLoader { &instance.device, instance.descriptor_pool, instance.descriptor_set_layout, - &instance.swapchain_images, + uniforms_buffers.len(), ); for (i, &_descritptor_set) in descriptor_sets.iter().enumerate() { @@ -124,7 +125,7 @@ impl OBJLoader { let buffer_info = vk::DescriptorBufferInfo::builder() .buffer(uniforms_buffers[i].buffer) .offset(0) - .range(size_of::() as u64) + .range(size_of::() as vk::DeviceSize) .build(); let ubo_write = vk::WriteDescriptorSet::builder() diff --git a/crates/vent-common/Cargo.toml b/crates/vent-common/Cargo.toml index 0f0fa47..3e0484c 100644 --- a/crates/vent-common/Cargo.toml +++ b/crates/vent-common/Cargo.toml @@ -19,14 +19,14 @@ serde_json = "1.0" # rfd = { version="0.11.4", default-features = false, features = ["xdg-portal"]} -[target.'cfg(target_arch = "wasm32")'.dependencies] -console_error_panic_hook = "0.1.7" -console_log = "1" -wasm-bindgen = "0.2.87" -wasm-bindgen-futures = "0.4.37" -web-sys = { version = "0.3.64", features = [ - "Document", - "Window", - "Element", - "Location" -]} \ No newline at end of file +# [target.'cfg(target_arch = "wasm32")'.dependencies] +# console_error_panic_hook = "0.1.7" +# console_log = "1" +# wasm-bindgen = "0.2.87" +# wasm-bindgen-futures = "0.4.37" +# web-sys = { version = "0.3.64", features = [ +# "Document", +# "Window", +# "Element", +# "Location" +# ]} \ No newline at end of file diff --git a/crates/vent-editor/Cargo.toml b/crates/vent-editor/Cargo.toml index 6a908e2..edd5329 100644 --- a/crates/vent-editor/Cargo.toml +++ b/crates/vent-editor/Cargo.toml @@ -15,7 +15,7 @@ ash = { version= "0.37.3", default-features = false, features = ["linked", "debu # egui egui = "0.23.0" -egui_dock = "0.8.1" +egui_dock = "0.8.2" winit = "0.29.3" pollster = "0.3.0" diff --git a/crates/vent-editor/src/gui/mod.rs b/crates/vent-editor/src/gui/mod.rs index 6dee6c4..fb17811 100644 --- a/crates/vent-editor/src/gui/mod.rs +++ b/crates/vent-editor/src/gui/mod.rs @@ -1,6 +1,6 @@ use egui::epaint::ahash::{HashSet, HashSetExt}; use egui::{CentralPanel, Color32, Frame, RichText, TopBottomPanel, Ui, WidgetText}; -use egui_dock::{DockArea, DockState, Node, NodeIndex, TabViewer, Tree}; +use egui_dock::{DockArea, DockState, Node, NodeIndex, TabViewer}; use vent_runtime::render::gui::debug_gui::RenderData; use vent_runtime::render::gui::GUI; @@ -75,7 +75,7 @@ impl GUI for EditorGUI { impl EditorGUI { pub fn new() -> Self { let mut state = DockState::new(vec!["Vent-Engine Placeholder".to_owned()]); - let mut tree = state.main_surface_mut(); + let tree = state.main_surface_mut(); let [a, _] = tree.split_left(NodeIndex::root(), 0.3, vec!["Files".to_owned()]); let [_, _] = tree.split_below(a, 0.6, vec!["Console".to_owned()]); diff --git a/crates/vent-editor/src/main.rs b/crates/vent-editor/src/main.rs index 8aeb28d..772fa96 100644 --- a/crates/vent-editor/src/main.rs +++ b/crates/vent-editor/src/main.rs @@ -6,7 +6,7 @@ use vent_common::util::crash::init_panic_hook; use vent_common::window::VentWindow; use vent_runtime::render::camera::{Camera, Camera3D}; -use winit::event::{ElementState, Event, WindowEvent}; +use winit::event::{Event, WindowEvent}; use winit::window::WindowBuilder; mod gui; diff --git a/crates/vent-editor/src/render/runtime_renderer.rs b/crates/vent-editor/src/render/runtime_renderer.rs index 7e16358..955a6f4 100644 --- a/crates/vent-editor/src/render/runtime_renderer.rs +++ b/crates/vent-editor/src/render/runtime_renderer.rs @@ -34,8 +34,8 @@ impl EditorRuntimeRenderer { pub fn resize( &mut self, - instance: &VulkanInstance, - new_size: &winit::dpi::PhysicalSize, + _instance: &VulkanInstance, + _new_size: &winit::dpi::PhysicalSize, _camera: &mut dyn Camera, ) { diff --git a/crates/vent-rendering/Cargo.toml b/crates/vent-rendering/Cargo.toml index 2b038b3..960c37d 100644 --- a/crates/vent-rendering/Cargo.toml +++ b/crates/vent-rendering/Cargo.toml @@ -12,5 +12,4 @@ image = "0.24.7" winit = "0.29.3" raw-window-handle = "0.6" - -bytemuck = { version = "1.14.0", features = ["derive"] } +log = "0.4" diff --git a/crates/vent-rendering/src/buffer.rs b/crates/vent-rendering/src/buffer.rs index 5d273e3..3720cde 100644 --- a/crates/vent-rendering/src/buffer.rs +++ b/crates/vent-rendering/src/buffer.rs @@ -39,6 +39,16 @@ impl VulkanBuffer { } } + pub fn new_image( + device: &ash::Device, + allocator: &MemoryAllocator, + image: vk::Image, + ) -> vk::DeviceMemory { + let requirements = unsafe { device.get_image_memory_requirements(image) }; + + allocator.allocate(device, requirements, vk::MemoryPropertyFlags::DEVICE_LOCAL) + } + pub fn new_init( device: &ash::Device, allocator: &MemoryAllocator, @@ -51,6 +61,18 @@ impl VulkanBuffer { buffer } + pub unsafe fn new_init_type( + device: &ash::Device, + allocator: &MemoryAllocator, + size: vk::DeviceSize, + usage: vk::BufferUsageFlags, + data: *const T, + ) -> Self { + let buffer = Self::new(device, allocator, size, usage); + buffer.upload_type(device, data, size); + buffer + } + pub fn upload_data(&self, device: &ash::Device, data: &[u8], size: vk::DeviceSize) { unsafe { let memory = device @@ -61,7 +83,30 @@ impl VulkanBuffer { } } - pub fn destroy(self, device: &ash::Device) { + pub unsafe fn upload_type( + &self, + device: &ash::Device, + data: *const T, + size: vk::DeviceSize, + ) { + unsafe { + let memory = device + .map_memory(self.buffer_memory, 0, size, vk::MemoryMapFlags::empty()) + .unwrap(); + copy_nonoverlapping(data, memory.cast(), 1); + device.unmap_memory(self.buffer_memory); + } + } + + pub fn bind(&self, device: &ash::Device) { + unsafe { + device + .bind_buffer_memory(self.buffer, self.buffer_memory, 0) + .expect("Failed to bind Buffer Memory"); + } + } + + pub fn destroy(&mut self, device: &ash::Device) { unsafe { device.destroy_buffer(self.buffer, None); device.free_memory(self.buffer_memory, None); diff --git a/crates/vent-rendering/src/debug.rs b/crates/vent-rendering/src/debug.rs new file mode 100644 index 0000000..de2e328 --- /dev/null +++ b/crates/vent-rendering/src/debug.rs @@ -0,0 +1,95 @@ +use ash::extensions::ext::DebugUtils; +use ash::{vk, Entry, Instance}; +use std::os::raw::c_void; +use std::{ + ffi::{CStr, CString}, + os::raw::c_char, +}; + +#[cfg(debug_assertions)] +pub const ENABLE_VALIDATION_LAYERS: bool = true; +#[cfg(not(debug_assertions))] +pub const ENABLE_VALIDATION_LAYERS: bool = false; + +const REQUIRED_LAYERS: [&str; 1] = ["VK_LAYER_KHRONOS_validation"]; + +unsafe extern "system" fn vulkan_debug_callback( + flag: vk::DebugUtilsMessageSeverityFlagsEXT, + typ: vk::DebugUtilsMessageTypeFlagsEXT, + p_callback_data: *const vk::DebugUtilsMessengerCallbackDataEXT, + _: *mut c_void, +) -> vk::Bool32 { + use vk::DebugUtilsMessageSeverityFlagsEXT as Flag; + + let message = CStr::from_ptr((*p_callback_data).p_message); + match flag { + Flag::VERBOSE => log::debug!("{:?} - {:?}", typ, message), + Flag::INFO => log::info!("{:?} - {:?}", typ, message), + Flag::WARNING => log::warn!("{:?} - {:?}", typ, message), + _ => log::error!("{:?} - {:?}", typ, message), + } + vk::FALSE +} + +/// Get the pointers to the validation layers names. +/// Also return the corresponding `CString` to avoid dangling pointers. +pub fn get_layer_names_and_pointers() -> (Vec, Vec<*const c_char>) { + let layer_names = REQUIRED_LAYERS + .iter() + .map(|name| CString::new(*name).unwrap()) + .collect::>(); + let layer_names_ptrs = layer_names + .iter() + .map(|name| name.as_ptr()) + .collect::>(); + (layer_names, layer_names_ptrs) +} + +/// Check if the required validation set in `REQUIRED_LAYERS` +/// are supported by the Vulkan instance. +/// +/// # Panics +/// +/// Panic if at least one on the layer is not supported. +pub fn check_validation_layer_support(entry: &Entry) { + for required in REQUIRED_LAYERS.iter() { + let properties = entry.enumerate_instance_layer_properties().unwrap(); // TODO: Cache + let layers = properties.iter().find(|layer| { + let name = unsafe { CStr::from_ptr(layer.layer_name.as_ptr()) }; + let name = name.to_str().expect("Failed to get layer name pointer"); + required == &name + }); + + if layers.is_none() { + panic!("Layer not supported: {}", required); + } + } +} + +/// Setup the debug message if validation layers are enabled. +pub fn setup_debug_messenger( + entry: &Entry, + instance: &Instance, +) -> (DebugUtils, vk::DebugUtilsMessengerEXT) { + let create_info = vk::DebugUtilsMessengerCreateInfoEXT::builder() + .message_severity( + vk::DebugUtilsMessageSeverityFlagsEXT::ERROR + | vk::DebugUtilsMessageSeverityFlagsEXT::WARNING + | vk::DebugUtilsMessageSeverityFlagsEXT::INFO, + ) + .message_type( + vk::DebugUtilsMessageTypeFlagsEXT::GENERAL + | vk::DebugUtilsMessageTypeFlagsEXT::DEVICE_ADDRESS_BINDING + | vk::DebugUtilsMessageTypeFlagsEXT::PERFORMANCE + | vk::DebugUtilsMessageTypeFlagsEXT::VALIDATION, + ) + .pfn_user_callback(Some(vulkan_debug_callback)); + let debug_utils = DebugUtils::new(entry, instance); + let debug_utils_messenger = unsafe { + debug_utils + .create_debug_utils_messenger(&create_info, None) + .unwrap() + }; + + (debug_utils, debug_utils_messenger) +} diff --git a/crates/vent-rendering/src/image.rs b/crates/vent-rendering/src/image.rs index 6561883..d149f28 100644 --- a/crates/vent-rendering/src/image.rs +++ b/crates/vent-rendering/src/image.rs @@ -5,35 +5,32 @@ use crate::{ end_single_time_command, }; +pub struct DepthImage { + pub image: vk::Image, + pub image_view: vk::ImageView, + pub memory: vk::DeviceMemory, +} + +impl DepthImage { + pub fn destroy(&mut self, device: &ash::Device) { + unsafe { + device.destroy_image_view(self.image_view, None); + device.destroy_image(self.image, None); + device.free_memory(self.memory, None); + } + } +} + pub struct VulkanImage { pub image: vk::Image, pub image_view: vk::ImageView, pub sampler: vk::Sampler, + pub memory: Option, } impl VulkanImage { pub const DEFAULT_TEXTURE_FILTER: vk::Filter = vk::Filter::LINEAR; - pub fn new( - device: &ash::Device, - format: vk::Format, - sampler_info: vk::SamplerCreateInfo, - size: Extent2D, - usage: vk::ImageUsageFlags, - ) -> Self { - let image = Self::create_image(device, format, size, usage); - let image_view = - Self::create_image_view(image, device, format, vk::ImageAspectFlags::COLOR); - - let sampler = unsafe { device.create_sampler(&sampler_info, None) }.unwrap(); - - Self { - image, - image_view, - sampler, - } - } - pub fn from_image( device: &ash::Device, image: image::DynamicImage, @@ -58,47 +55,83 @@ impl VulkanImage { let image_data_size = (std::mem::size_of::() as u32 * image_size.width * image_size.height * 4) as vk::DeviceSize; - let vk_image = Self::new( - device, - vk::Format::R8G8B8A8_UNORM, - sampler_info.unwrap_or(Self::default_sampler()), - image_size, - vk::ImageUsageFlags::TRANSFER_DST | vk::ImageUsageFlags::SAMPLED, - ); - let buffer = VulkanBuffer::new_init( + + let mut staging_buffer = VulkanBuffer::new_init( device, allocator, image_data_size, vk::BufferUsageFlags::TRANSFER_SRC, &image_data, ); - vk_image.copy_buffer_to_image( + + let image = Self::create_image( + device, + vk::Format::R8G8B8A8_UNORM, + image_size, + vk::ImageUsageFlags::TRANSFER_DST | vk::ImageUsageFlags::SAMPLED, + ); + let memory = VulkanBuffer::new_image(device, allocator, image); + unsafe { + device + .bind_image_memory(image, memory, 0) + .expect("Unable to bind depth image memory") + }; + Self::copy_buffer_to_image( device, + image, + &staging_buffer, command_pool, submit_queue, - *buffer, image_size.width, image_size.height, ); - vk_image + staging_buffer.destroy(device); + + let image_view = Self::create_image_view( + image, + device, + vk::Format::R8G8B8A8_UNORM, + vk::ImageAspectFlags::COLOR, + ); + + let sampler = unsafe { + device.create_sampler(&sampler_info.unwrap_or(Self::default_sampler()), None) + } + .unwrap(); + + Self { + image, + image_view, + sampler, + memory: Some(memory), + } } - pub fn new_depth(device: &ash::Device, format: vk::Format, size: Extent2D) -> Self { + pub fn new_depth( + device: &ash::Device, + allocator: &MemoryAllocator, + format: vk::Format, + size: Extent2D, + ) -> DepthImage { let image = Self::create_image( device, format, size, vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT, ); + let memory = VulkanBuffer::new_image(device, allocator, image); + unsafe { + device + .bind_image_memory(image, memory, 0) + .expect("Unable to bind depth image memory") + }; let image_view = Self::create_image_view(image, device, format, vk::ImageAspectFlags::DEPTH); - let sampler = unsafe { device.create_sampler(&Self::default_sampler(), None) }.unwrap(); - - Self { + DepthImage { image, image_view, - sampler, + memory, } } @@ -108,16 +141,40 @@ impl VulkanImage { } pub fn copy_buffer_to_image( - &self, device: &ash::Device, + image: vk::Image, + staging_buffer: &VulkanBuffer, command_pool: vk::CommandPool, submit_queue: vk::Queue, - buffer: vk::Buffer, width: u32, height: u32, ) { + staging_buffer.bind(device); + let command_buffer = begin_single_time_command(device, command_pool); + let image_barrier = vk::ImageMemoryBarrier2 { + dst_access_mask: vk::AccessFlags2::TRANSFER_WRITE, + new_layout: vk::ImageLayout::TRANSFER_DST_OPTIMAL, + src_stage_mask: vk::PipelineStageFlags2::BOTTOM_OF_PIPE, + dst_stage_mask: vk::PipelineStageFlags2::TRANSFER, + image: image, + subresource_range: vk::ImageSubresourceRange { + aspect_mask: vk::ImageAspectFlags::COLOR, + level_count: 1, + layer_count: 1, + ..Default::default() + }, + ..Default::default() + }; + + let dep_info = vk::DependencyInfo::builder() + .image_memory_barriers(&[image_barrier]) + .dependency_flags(vk::DependencyFlags::BY_REGION) + .build(); + + unsafe { device.cmd_pipeline_barrier2(command_buffer, &dep_info) }; + let subresource = vk::ImageSubresourceLayers::builder() .aspect_mask(vk::ImageAspectFlags::COLOR) .mip_level(0) @@ -125,7 +182,7 @@ impl VulkanImage { .layer_count(1) .build(); - let region = vk::BufferImageCopy::builder() + let region = vk::BufferImageCopy2::builder() .buffer_offset(0) .buffer_row_length(0) .buffer_image_height(0) @@ -138,16 +195,40 @@ impl VulkanImage { }) .build(); - unsafe { - device.cmd_copy_buffer_to_image( - command_buffer, - buffer, - self.image, - vk::ImageLayout::TRANSFER_DST_OPTIMAL, - &[region], - ) + let copy_image_info = vk::CopyBufferToImageInfo2::builder() + .src_buffer(staging_buffer.buffer) + .dst_image(image) + .dst_image_layout(vk::ImageLayout::TRANSFER_DST_OPTIMAL) + .regions(&[region]) + .build(); + + unsafe { device.cmd_copy_buffer_to_image2(command_buffer, ©_image_info) }; + + let image_barrier = vk::ImageMemoryBarrier2 { + src_access_mask: vk::AccessFlags2::TRANSFER_WRITE, + dst_access_mask: vk::AccessFlags2::SHADER_READ, + src_stage_mask: vk::PipelineStageFlags2::TRANSFER, + dst_stage_mask: vk::PipelineStageFlags2::FRAGMENT_SHADER, + old_layout: vk::ImageLayout::TRANSFER_DST_OPTIMAL, + new_layout: vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, + image: image, + subresource_range: vk::ImageSubresourceRange { + aspect_mask: vk::ImageAspectFlags::COLOR, + level_count: 1, + layer_count: 1, + ..Default::default() + }, + + ..Default::default() }; + let dep_info = vk::DependencyInfo::builder() + .image_memory_barriers(&[image_barrier]) + .dependency_flags(vk::DependencyFlags::BY_REGION) + .build(); + + unsafe { device.cmd_pipeline_barrier2(command_buffer, &dep_info) }; + end_single_time_command(device, command_pool, submit_queue, command_buffer); } @@ -158,8 +239,6 @@ impl VulkanImage { .address_mode_u(vk::SamplerAddressMode::REPEAT) .address_mode_v(vk::SamplerAddressMode::REPEAT) .address_mode_w(vk::SamplerAddressMode::REPEAT) - .anisotropy_enable(true) - .max_anisotropy(1.0) .border_color(vk::BorderColor::INT_OPAQUE_BLACK) .unnormalized_coordinates(false) .compare_enable(false) @@ -207,14 +286,18 @@ impl VulkanImage { .usage(usage) .sharing_mode(vk::SharingMode::EXCLUSIVE) .build(); - unsafe { device.create_image(&create_info, None) }.unwrap() + let image = unsafe { device.create_image(&create_info, None) }.unwrap(); + image } - pub fn destroy(&self, device: &ash::Device) { + pub fn destroy(&mut self, device: &ash::Device) { unsafe { device.destroy_image_view(self.image_view, None); device.destroy_image(self.image, None); device.destroy_sampler(self.sampler, None); + self.memory.map(|memory| { + device.free_memory(memory, None); + }); } } } diff --git a/crates/vent-rendering/src/instance.rs b/crates/vent-rendering/src/instance.rs index ffd722d..c28fb38 100644 --- a/crates/vent-rendering/src/instance.rs +++ b/crates/vent-rendering/src/instance.rs @@ -1,8 +1,7 @@ use ash::extensions::khr::{Surface, Swapchain}; -use ash::vk::{make_version, Extent2D, SwapchainKHR}; +use ash::vk::{Extent2D, SwapchainKHR}; use ash::{extensions::ext::DebugUtils, vk, Entry}; use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; -use std::borrow::Cow; use std::{default::Default, ffi::CStr}; #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -11,44 +10,15 @@ use ash::vk::{ }; use crate::allocator::MemoryAllocator; -use crate::image::VulkanImage; +use crate::debug::{ + check_validation_layer_support, get_layer_names_and_pointers, setup_debug_messenger, + ENABLE_VALIDATION_LAYERS, +}; +use crate::image::{DepthImage, VulkanImage}; use crate::surface; -const VALIDATION_ENABLED: bool = cfg!(debug_assertions); - const MAX_FRAMES_IN_FLIGHT: u8 = 2; -#[cfg(debug_assertions)] -// const VALIDATION_LAYER: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"VK_LAYER_KHRONOS_validation\n") }; -#[cfg(debug_assertions)] -unsafe extern "system" fn vulkan_debug_callback( - message_severity: vk::DebugUtilsMessageSeverityFlagsEXT, - message_type: vk::DebugUtilsMessageTypeFlagsEXT, - p_callback_data: *const vk::DebugUtilsMessengerCallbackDataEXT, - _user_data: *mut std::os::raw::c_void, -) -> vk::Bool32 { - let callback_data = *p_callback_data; - let message_id_number = callback_data.message_id_number; - - let message_id_name = if callback_data.p_message_id_name.is_null() { - Cow::from("") - } else { - CStr::from_ptr(callback_data.p_message_id_name).to_string_lossy() - }; - - let message = if callback_data.p_message.is_null() { - Cow::from("") - } else { - CStr::from_ptr(callback_data.p_message).to_string_lossy() - }; - - println!( - "{message_severity:?}:\n{message_type:?} [{message_id_name} ({message_id_number})] : {message}\n", - ); - - vk::FALSE -} - pub struct VulkanInstance { pub memory_allocator: MemoryAllocator, @@ -58,6 +28,7 @@ pub struct VulkanInstance { pub surface_loader: Surface, pub surface: vk::SurfaceKHR, + pub surface_resolution: vk::Extent2D, pub swapchain_loader: Swapchain, pub swapchain: vk::SwapchainKHR, @@ -66,7 +37,7 @@ pub struct VulkanInstance { pub swapchain_images: Vec, pub swapchain_image_views: Vec, pub frame_buffers: Vec, - pub depth_image: VulkanImage, + pub depth_image: DepthImage, pub graphics_queue: vk::Queue, pub present_queue: vk::Queue, @@ -95,7 +66,7 @@ impl VulkanInstance { pub fn new(application_name: &str, window: &winit::window::Window) -> Self { let entry = Entry::linked(); - let engine_version: u32 = (env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap()); + let engine_version: u32 = env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap(); let app_info = unsafe { vk::ApplicationInfo::builder() @@ -105,17 +76,19 @@ impl VulkanInstance { .application_version(0) // TODO .engine_name(CStr::from_bytes_with_nul_unchecked(b"Vent-Engine\0")) .engine_version(engine_version) - .api_version(vk::API_VERSION_1_2) + .api_version(vk::API_VERSION_1_3) .build() }; let display_handle = window.display_handle().expect("No Display Handle"); let window_handle = window.window_handle().expect("No Window Handle"); - let mut extension_names = surface::enumerate_required_extensions(display_handle) + let mut extension_names = surface::enumerate_required_extensions(display_handle.as_raw()) .expect("Unsupported Surface Extension") .to_vec(); - extension_names.push(DebugUtils::name().as_ptr()); + if ENABLE_VALIDATION_LAYERS { + extension_names.push(DebugUtils::name().as_ptr()); + } #[cfg(any(target_os = "macos", target_os = "ios"))] { @@ -130,9 +103,13 @@ impl VulkanInstance { vk::InstanceCreateFlags::default() }; + let (_layer_names, layer_names_ptrs) = get_layer_names_and_pointers(); + check_validation_layer_support(&entry); + let create_info = vk::InstanceCreateInfo::builder() .application_info(&app_info) .enabled_extension_names(&extension_names) + .enabled_layer_names(&layer_names_ptrs) .flags(create_flags) .build(); @@ -142,9 +119,8 @@ impl VulkanInstance { .expect("Failed Create Vulkan Instance") }; #[cfg(debug_assertions)] - let debug_utils_loader = DebugUtils::new(&entry, &instance); - #[cfg(debug_assertions)] - let debug_messenger = Self::create_debug_messenger(&debug_utils_loader); + let (debug_utils_loader, debug_messenger) = setup_debug_messenger(&entry, &instance); + let surface = unsafe { surface::create_surface(&entry, &instance, display_handle, window_handle, None) } @@ -153,10 +129,12 @@ impl VulkanInstance { let (pdevice, graphics_queue_family_index, present_queue_family_index) = Self::create_physical_device(&instance, &surface_loader, surface); + let surface_format = unsafe { surface_loader.get_physical_device_surface_formats(pdevice, surface) } .unwrap()[0]; let device = Self::create_device(&instance, pdevice, graphics_queue_family_index); + let graphics_queue = unsafe { device.get_device_queue(graphics_queue_family_index, 0) }; let present_queue = unsafe { device.get_device_queue(present_queue_family_index, 0) }; @@ -173,11 +151,19 @@ impl VulkanInstance { let (swapchain_image_views, swapchain_images) = Self::create_image_views(&device, &swapchain_loader, swapchain, surface_format); - let pipeline_layout = Self::create_pipeline_layout(&device); + let render_pass = Self::create_render_pass(&device, surface_format); - let depth_image = - VulkanImage::new_depth(&device, vk::Format::D16_UNORM, surface_resolution); + let memory_allocator = MemoryAllocator::new(unsafe { + instance.get_physical_device_memory_properties(pdevice) + }); + + let depth_image = VulkanImage::new_depth( + &device, + &memory_allocator, + Self::get_depth_format(&instance, pdevice), + surface_resolution, + ); let frame_buffers = Self::create_frame_buffers( &swapchain_image_views, render_pass, @@ -196,13 +182,11 @@ impl VulkanInstance { images_in_flight, ) = Self::create_sync_objects(&device, &swapchain_images); - let memory_allocator = MemoryAllocator::new(unsafe { - instance.get_physical_device_memory_properties(pdevice) - }); - let descriptor_pool = Self::create_descriptor_pool(&device); let descriptor_set_layout = Self::create_descriptor_set_layout(&device); + let pipeline_layout = Self::create_pipeline_layout(&device, descriptor_set_layout); + Self { memory_allocator, instance, @@ -211,6 +195,7 @@ impl VulkanInstance { surface, surface_loader, swapchain_loader, + surface_resolution, swapchain, pipeline_layout, swapchain_images, @@ -264,30 +249,40 @@ impl VulkanInstance { } } - pub fn submit(&self, image_index: u32, in_flight_fence: vk::Fence) { - let wait_semaphores = &[self.image_available_semaphores[self.frame]]; - let wait_stages = &[vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT]; - let command_buffers = &[self.command_buffers[image_index as usize]]; - let signal_semaphores = &[self.render_finished_semaphores[self.frame]]; - let submit_info = vk::SubmitInfo::builder() - .wait_semaphores(wait_semaphores) - .wait_dst_stage_mask(wait_stages) - .command_buffers(command_buffers) - .signal_semaphores(signal_semaphores) + pub fn submit(&mut self, image_index: u32) { + let in_flight_fence = self.in_flight_fences[self.frame]; + + let wait_semaphores = vk::SemaphoreSubmitInfo::builder() + .semaphore(self.image_available_semaphores[self.frame]) + .stage_mask(vk::PipelineStageFlags2::COLOR_ATTACHMENT_OUTPUT) + .build(); + + let command_buffers = vk::CommandBufferSubmitInfo::builder() + .command_buffer(self.command_buffers[image_index as usize]) + .build(); + + let signal_semaphores = vk::SemaphoreSubmitInfo::builder() + .semaphore(self.render_finished_semaphores[self.frame]) + .build(); + + let submit_info = vk::SubmitInfo2::builder() + .wait_semaphore_infos(&[wait_semaphores]) + .command_buffer_infos(&[command_buffers]) + .signal_semaphore_infos(&[signal_semaphores]) .build(); unsafe { self.device.reset_fences(&[in_flight_fence]).unwrap(); self.device - .queue_submit(self.graphics_queue, &[submit_info], in_flight_fence) + .queue_submit2(self.graphics_queue, &[submit_info], in_flight_fence) .unwrap(); } let swapchains = &[self.swapchain]; let image_indices = &[image_index]; let present_info = vk::PresentInfoKHR::builder() - .wait_semaphores(signal_semaphores) + .wait_semaphores(&[self.render_finished_semaphores[self.frame]]) .swapchains(swapchains) .image_indices(image_indices) .build(); @@ -297,6 +292,7 @@ impl VulkanInstance { .queue_present(self.present_queue, &present_info) } .unwrap(); + self.frame = (self.frame + 1) % MAX_FRAMES_IN_FLIGHT as usize; } fn get_depth_format(instance: &ash::Instance, pdevice: vk::PhysicalDevice) -> vk::Format { @@ -304,6 +300,7 @@ impl VulkanInstance { vk::Format::D32_SFLOAT, vk::Format::D32_SFLOAT_S8_UINT, vk::Format::D24_UNORM_S8_UINT, + vk::Format::D16_UNORM, ]; Self::get_supported_format( @@ -333,25 +330,6 @@ impl VulkanInstance { }) } - #[cfg(debug_assertions)] - fn create_debug_messenger(debug_utils_loader: &DebugUtils) -> vk::DebugUtilsMessengerEXT { - let debug_info = vk::DebugUtilsMessengerCreateInfoEXT::builder() - .message_severity( - vk::DebugUtilsMessageSeverityFlagsEXT::ERROR - | vk::DebugUtilsMessageSeverityFlagsEXT::WARNING - | vk::DebugUtilsMessageSeverityFlagsEXT::INFO, - ) - .message_type( - vk::DebugUtilsMessageTypeFlagsEXT::GENERAL - | vk::DebugUtilsMessageTypeFlagsEXT::DEVICE_ADDRESS_BINDING - | vk::DebugUtilsMessageTypeFlagsEXT::PERFORMANCE, - ) - .pfn_user_callback(Some(vulkan_debug_callback)) - .build(); - - unsafe { debug_utils_loader.create_debug_utils_messenger(&debug_info, None) }.unwrap() - } - fn create_frame_buffers( swapchain_image_views: &Vec, render_pass: vk::RenderPass, @@ -432,8 +410,17 @@ impl VulkanInstance { #[cfg(any(target_os = "macos", target_os = "ios"))] KhrPortabilitySubsetFn::name().as_ptr(), ]; + + let mut features_1_3 = vk::PhysicalDeviceVulkan13Features { + synchronization2: 1, + maintenance4: 1, + ..Default::default() + }; + let features = vk::PhysicalDeviceFeatures { shader_clip_distance: 1, + sampler_anisotropy: 1, + ..Default::default() }; let priorities = [1.0]; @@ -447,6 +434,7 @@ impl VulkanInstance { .queue_create_infos(std::slice::from_ref(&queue_info)) .enabled_extension_names(&device_extension_names_raw) .enabled_features(&features) + .push_next(&mut features_1_3) .build(); unsafe { instance.create_device(pdevice, &device_create_info, None) }.unwrap() @@ -610,13 +598,20 @@ impl VulkanInstance { } fn create_descriptor_pool(device: &ash::Device) -> vk::DescriptorPool { - let pool_sizes = [vk::DescriptorPoolSize::builder() - .ty(vk::DescriptorType::UNIFORM_BUFFER) - .descriptor_count(1000) - .build()]; + let pool_sizes = [ + vk::DescriptorPoolSize { + ty: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, + descriptor_count: 1000, + }, + vk::DescriptorPoolSize { + ty: vk::DescriptorType::UNIFORM_BUFFER, + descriptor_count: 1000, + }, + ]; let create_info = vk::DescriptorPoolCreateInfo::builder() .pool_sizes(&pool_sizes) + .max_sets(1000) .build(); unsafe { device.create_descriptor_pool(&create_info, None) }.unwrap() @@ -626,9 +621,9 @@ impl VulkanInstance { device: &ash::Device, descriptor_pool: vk::DescriptorPool, descriptor_set_layout: vk::DescriptorSetLayout, - swapchain_images: &Vec, + size: usize, ) -> Vec { - let layouts = vec![descriptor_set_layout; swapchain_images.len()]; + let layouts = (0..size).map(|_| descriptor_set_layout).collect::>(); let info = vk::DescriptorSetAllocateInfo::builder() .descriptor_pool(descriptor_pool) .set_layouts(&layouts) @@ -638,30 +633,52 @@ impl VulkanInstance { } fn create_descriptor_set_layout(device: &ash::Device) -> vk::DescriptorSetLayout { - let ubo_binding = vk::DescriptorSetLayoutBinding::builder() - .binding(0) - .descriptor_type(vk::DescriptorType::UNIFORM_BUFFER) - .descriptor_count(1) - .stage_flags(vk::ShaderStageFlags::VERTEX) - .build(); - - let sampler_binding = vk::DescriptorSetLayoutBinding::builder() - .binding(1) - .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) - .descriptor_count(1) - .stage_flags(vk::ShaderStageFlags::FRAGMENT) - .build(); + let desc_layout_bindings = [ + // Vertex + vk::DescriptorSetLayoutBinding { + binding: 0, + descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + descriptor_count: 1, + stage_flags: vk::ShaderStageFlags::VERTEX, + ..Default::default() + }, + // Fragment + vk::DescriptorSetLayoutBinding { + binding: 1, + descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, + descriptor_count: 1, + stage_flags: vk::ShaderStageFlags::FRAGMENT, + ..Default::default() + }, + vk::DescriptorSetLayoutBinding { + binding: 2, + descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + descriptor_count: 1, + stage_flags: vk::ShaderStageFlags::FRAGMENT, + ..Default::default() + }, + vk::DescriptorSetLayoutBinding { + binding: 3, + descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + descriptor_count: 1, + stage_flags: vk::ShaderStageFlags::FRAGMENT, + ..Default::default() + }, + ]; - let bindings = &[ubo_binding, sampler_binding]; let info = vk::DescriptorSetLayoutCreateInfo::builder() - .bindings(bindings) + .bindings(&desc_layout_bindings) .build(); unsafe { device.create_descriptor_set_layout(&info, None) }.unwrap() } - fn create_pipeline_layout(device: &ash::Device) -> vk::PipelineLayout { - let create_info = vk::PipelineLayoutCreateInfo::default(); + fn create_pipeline_layout( + device: &ash::Device, + layout: vk::DescriptorSetLayout, + ) -> vk::PipelineLayout { + let binding = [layout]; + let create_info = vk::PipelineLayoutCreateInfo::builder().set_layouts(&binding); unsafe { device.create_pipeline_layout(&create_info, None) }.unwrap() } @@ -725,6 +742,8 @@ impl Drop for VulkanInstance { fn drop(&mut self) { unsafe { self.device.device_wait_idle().unwrap(); + self.device + .destroy_pipeline_layout(self.pipeline_layout, None); self.in_flight_fences .iter() .for_each(|f| self.device.destroy_fence(*f, None)); diff --git a/crates/vent-rendering/src/lib.rs b/crates/vent-rendering/src/lib.rs index cf2a0f0..852b7d1 100644 --- a/crates/vent-rendering/src/lib.rs +++ b/crates/vent-rendering/src/lib.rs @@ -1,22 +1,34 @@ use std::mem; use ash::vk; -use bytemuck::offset_of; pub mod allocator; pub mod buffer; +mod debug; pub mod image; pub mod instance; pub mod pipeline; mod surface; +// Simple offset_of macro akin to C++ offsetof +#[macro_export] +macro_rules! offset_of { + ($base:path, $field:ident) => {{ + #[allow(unused_unsafe)] + unsafe { + let b: $base = mem::zeroed(); + std::ptr::addr_of!(b.$field) as isize - std::ptr::addr_of!(b) as isize + } + }}; +} + pub trait Vertex<'a> { const BINDING_DESCRIPTION: vk::VertexInputBindingDescription; - fn create_input_descriptions() -> [vk::VertexInputAttributeDescription; 3]; + fn input_descriptions() -> [vk::VertexInputAttributeDescription; 3]; } #[repr(C)] -#[derive(Default, Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)] +#[derive(Clone, Copy)] pub struct Vertex3D { pub position: [f32; 3], pub tex_coord: [f32; 2], @@ -30,7 +42,7 @@ impl<'a> Vertex<'a> for Vertex3D { stride: mem::size_of::() as u32, input_rate: vk::VertexInputRate::VERTEX, }; - fn create_input_descriptions() -> [vk::VertexInputAttributeDescription; 3] { + fn input_descriptions() -> [vk::VertexInputAttributeDescription; 3] { [ vk::VertexInputAttributeDescription { location: 0, @@ -41,7 +53,7 @@ impl<'a> Vertex<'a> for Vertex3D { vk::VertexInputAttributeDescription { location: 1, binding: 0, - format: vk::Format::R32G32B32A32_SFLOAT, + format: vk::Format::R32G32_SFLOAT, offset: offset_of!(Self, tex_coord) as u32, }, vk::VertexInputAttributeDescription { @@ -95,19 +107,21 @@ pub fn end_single_time_command( .expect("Failed to record Command Buffer at Ending!"); } - let buffers_to_submit = [command_buffer]; + let buffers_to_submit = vk::CommandBufferSubmitInfo::builder() + .command_buffer(command_buffer) + .build(); - let submit_info = vk::SubmitInfo::builder() - .command_buffers(&buffers_to_submit) + let submit_info = vk::SubmitInfo2::builder() + .command_buffer_infos(&[buffers_to_submit]) .build(); unsafe { device - .queue_submit(submit_queue, &[submit_info], vk::Fence::null()) + .queue_submit2(submit_queue, &[submit_info], vk::Fence::null()) .expect("Failed to Queue Submit!"); device .queue_wait_idle(submit_queue) .expect("Failed to wait Queue idle!"); - device.free_command_buffers(command_pool, &buffers_to_submit); + device.free_command_buffers(command_pool, &[command_buffer]); } } diff --git a/crates/vent-rendering/src/pipeline.rs b/crates/vent-rendering/src/pipeline.rs index b74315d..5092bd3 100644 --- a/crates/vent-rendering/src/pipeline.rs +++ b/crates/vent-rendering/src/pipeline.rs @@ -2,19 +2,25 @@ use std::{ffi::CStr, fs::File}; use ash::{util::read_spv, vk}; -use crate::{instance::VulkanInstance, Vertex, Vertex3D}; +use crate::instance::VulkanInstance; -pub fn create_pipeline( - instance: VulkanInstance, +pub fn create_pipeline<'a>( + instance: &VulkanInstance, vertex_file: String, fragment_file: String, + binding_desc: vk::VertexInputBindingDescription, + attrib_desc: &'a [vk::VertexInputAttributeDescription], surface_resolution: vk::Extent2D, ) -> vk::Pipeline { - let vertex_code = read_spv(&mut File::open(vertex_file).unwrap()).unwrap(); + let vertex_code = + read_spv(&mut File::open(vertex_file + ".spv").expect("Failed to open Vertex File")) + .unwrap(); let vertex_module_info = vk::ShaderModuleCreateInfo::builder() .code(&vertex_code) .build(); - let fragment_code = read_spv(&mut File::open(fragment_file).unwrap()).unwrap(); + let fragment_code = + read_spv(&mut File::open(fragment_file + ".spv").expect("Failed to open Vertex File")) + .unwrap(); let fragment_module_info = vk::ShaderModuleCreateInfo::builder() .code(&fragment_code) .build(); @@ -49,8 +55,8 @@ pub fn create_pipeline( ]; let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::builder() - .vertex_attribute_descriptions(&Vertex3D::create_input_descriptions()) - .vertex_binding_descriptions(&[Vertex3D::BINDING_DESCRIPTION]) + .vertex_attribute_descriptions(&attrib_desc) + .vertex_binding_descriptions(&[binding_desc]) .build(); let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo { topology: vk::PrimitiveTopology::TRIANGLE_LIST, diff --git a/crates/vent-rendering/src/surface.rs b/crates/vent-rendering/src/surface.rs index 1189444..2522694 100644 --- a/crates/vent-rendering/src/surface.rs +++ b/crates/vent-rendering/src/surface.rs @@ -88,10 +88,10 @@ pub unsafe fn create_surface( } } -pub fn enumerate_required_extensions( - display_handle: DisplayHandle<'_>, +pub const fn enumerate_required_extensions( + display_handle: RawDisplayHandle, ) -> VkResult<&'static [*const c_char]> { - let extensions = match display_handle.as_raw() { + let extensions = match display_handle { RawDisplayHandle::Windows(_) => { const WINDOWS_EXTS: [*const c_char; 2] = [ khr::Surface::name().as_ptr(), diff --git a/crates/vent-runtime/Cargo.toml b/crates/vent-runtime/Cargo.toml index 0afcf33..da55f84 100644 --- a/crates/vent-runtime/Cargo.toml +++ b/crates/vent-runtime/Cargo.toml @@ -18,12 +18,10 @@ pollster = "0.3.0" log = "0.4" glam = "0.24.2" -bytemuck = { version = "1.14.0", features = ["derive"] } downcast-rs = "1.2.0" # egui egui = "0.23.0" -egui-winit-ash-integration = "0.5.0" egui-winit = "0.23.0" [target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies] @@ -32,4 +30,3 @@ simple_logger = "4.2.0" [build-dependencies] fs_extra = "1.3.0" -anyhow = "1.0" diff --git a/crates/vent-runtime/build.rs b/crates/vent-runtime/build.rs index c4391a0..e8a87f8 100644 --- a/crates/vent-runtime/build.rs +++ b/crates/vent-runtime/build.rs @@ -1,16 +1,112 @@ -use std::env; +use std::{env, fs::DirEntry, io::Result}; -use anyhow::Result; use fs_extra::copy_items; use fs_extra::dir::CopyOptions; -fn main() -> Result<()> { +use std::{ + env::var, + ffi::OsStr, + fs, + path::{Path, PathBuf}, + process::{Command, Output}, +}; + +fn main() { // This tells cargo to rerun this script if something in /res/ changes. println!("cargo:rerun-if-changed=res/*"); - let out_dir = env::var("OUT_DIR")?; + let out_dir = env::var("OUT_DIR").expect("Var: OUT_DIR Not found!"); let copy_options = CopyOptions::new().overwrite(true); - copy_items(&["res/"], out_dir, ©_options)?; + copy_items(&["res/"], out_dir, ©_options).expect("Failed to copy to resource Folder"); + + if !should_skip_shader_compilation() { + println!("Compiling shaders"); + compile_shaders(&get_shader_source_dir_path()); + } +} + +fn should_skip_shader_compilation() -> bool { + var("SKIP_SHADER_COMPILATION") + .map(|var| var.parse::().unwrap_or(false)) + .unwrap_or(false) +} + +fn compile_shaders(dir: &Path) { + if dir.is_dir() { + for entry in fs::read_dir(dir).unwrap() { + let entry = entry.unwrap(); + let path = entry.path(); + if path.is_dir() { + compile_shaders(&path); + } else { + compile_shader(&entry); + } + } + } +} + +fn compile_shader(file: &DirEntry) { + if file.file_type().unwrap().is_file() { + let path = file.path(); + if path.extension() == Some(OsStr::new("spv")) + || path.extension() == Some(OsStr::new("wgsl")) + { + return; + } + let name = path.file_name().unwrap().to_str().unwrap(); + let output_name = format!("{}.spv", &name); + println!("Found file {:?}.\nCompiling...", path.as_os_str()); + + let result = Command::new("glslangValidator") + .current_dir(path.parent().expect("Shader File has not Parent!")) + .env("--target-env", "vulkan1.3") + .arg("-V") + .arg(&path) + .arg("-o") + .arg(output_name) + .output(); + + handle_program_result(result); + } +} + +fn get_shader_source_dir_path() -> PathBuf { + let path = get_root_path().join("res").join("shaders"); + println!("Shader source directory: {:?}", path.as_os_str()); + path +} + +fn get_root_path() -> &'static Path { + Path::new(env!("CARGO_MANIFEST_DIR")) +} - Ok(()) +fn handle_program_result(result: Result) { + match result { + Ok(output) => { + if output.status.success() { + println!("Shader compilation succedeed."); + print!( + "stdout: {}", + String::from_utf8(output.stdout) + .unwrap_or("Failed to print program stdout".to_string()) + ); + } else { + eprintln!("Shader compilation failed. Status: {}", output.status); + eprint!( + "stdout: {}", + String::from_utf8(output.stdout) + .unwrap_or("Failed to print program stdout".to_string()) + ); + eprint!( + "stderr: {}", + String::from_utf8(output.stderr) + .unwrap_or("Failed to print program stderr".to_string()) + ); + panic!("Shader compilation failed. Status: {}", output.status); + } + } + Err(error) => { + panic!("Failed to compile shader. Cause: {}", error); + } + } } diff --git a/crates/vent-runtime/res/shaders/app/3D/shader.frag b/crates/vent-runtime/res/shaders/app/3D/shader.frag new file mode 100644 index 0000000..0bb7394 --- /dev/null +++ b/crates/vent-runtime/res/shaders/app/3D/shader.frag @@ -0,0 +1,55 @@ +#version 450 core + + +layout (binding = 1) uniform sampler2D texture_diffuse; + +layout (binding = 2) uniform Material { + vec4 base_color; +} material; + + +layout (binding = 3) uniform Light { + vec3 position; + vec3 color; +} light; + +layout (location = 0) in vec2 tex_coord; +layout (location = 1) in vec2 normal; +layout (location = 2) in vec3 world_position; +layout (location = 3) in vec3 position; +layout (location = 4) in vec3 view_position; + + +layout (location = 0) out vec4 fragColor; + +// We don't need (or want) much ambient light, so 0.1 is fine +const float ambient_strength = 0.1; + +void main() { + vec4 texture = texture(texture_diffuse, tex_coord) * material.base_color; + + // Calculate the ambient color + vec3 ambient_color = light.color * ambient_strength; + + // Calculate the light direction + vec3 light_dir = normalize(light.position - world_position); + + // Calculate the view direction + vec3 view_dir = normalize(view_position.xyz - world_position); + + // Calculate the half vector + vec3 half_dir = normalize(view_dir + light_dir); + + // Calculate the diffuse color + float diffuse_strength = max(dot(world_position, light_dir), 0.0); + vec3 diffuse_color = light.color * diffuse_strength; + + // Calculate the specular color + float specular_strength = pow(max(dot(world_position, half_dir), 0.0), 32.0); + vec3 specular_color = specular_strength * light.color; + + // Calculate the final color + vec3 result = (ambient_color + diffuse_color + specular_color) * texture.xyz; + + fragColor = vec4(result, 1.0); +} \ No newline at end of file diff --git a/crates/vent-runtime/res/shaders/app/3D/shader.frag.spv b/crates/vent-runtime/res/shaders/app/3D/shader.frag.spv new file mode 100644 index 0000000000000000000000000000000000000000..f93609a2e504c5130987003c377c1ee640cd5159 GIT binary patch literal 2852 zcmZ9M-E)&g6vmf+q#%_K5fIUuwkj%GQ2|j5P%0F)6%Z6ZThb^JaW(ek!GX>0sKQw$gAMO=BPltWwO&EB96w z`h&*8`3vV{97^K_QO;pl6U^F9y}fJVDE1ciF1Cg>u@-iOb@JE{Z=79H`V)~!(DHiY z1LOwHp9XuqCizNwdK9lW+O5`JUwpFI3*P!>x7%yL5qp+-wLWO}+Vu`Dt1AVjzftcu zA$PjHA@>B>PKoPYFM-u}HrmbIK~PbhNLBEa_SW`*SxsZdqi(-FXm^XVS727bI9AHr z6l>>*J9(`&z8*2Bp%joxac7Uay-s6&q$u|t@;|nlk2AI4dbb5OqJmGR_rbU8oz{pu zm1bUUPSAunkn`ER}MjdZ*GY@cyIb=3b}XD=)In+vVJUcR7*ngZG;Ky$%;- zExvuLSKnG1UN^`@(F?oX-i|LL$G#{XAuYr4t-UWt#IyL`sj>YvgE?-Y;d?vghZCIf z0<*v5`^IHGWA)6tzRK)~^?|vc*bz+4DsyP6SJu>5a~yL|``;Ra?|T{B=jOeeID@g@ zh_QPbdoRZ79YaN(St4Wo6L=NoDs~dS-;}ZXRetv~i)p9$nx0}duYP$%d>XxjB;>h% zI+MgM=h$~~xZh!B^{hp{cchlMd}H59YzA%L$XetcXLg;KTw~uv>^SjB<|^jevpIea z-{JaG%yQMUmKT|=#k(=@y_plAA+BcM*!(Q>u+1i2@7Y|Vp7C17g8z^>rJt{w z_wMbd^8T$HU!>nXyM5wN_ivC%X4l#`{`baS-lhMC<=FqOa_s+8Ircv&V$WJD#p*4U zV)Opj1mC>>FXi}tj%(CsKOVyDMPvKz8O&aLz$sjJ43i_i2xh-LkJ)4Pk?Z80#>9Wi z>t4Wjt@ssg#(NM`!yb4AvrpzRHGJ<^G4bEw7{8XWGt6pucVeOO2EH0mhilGa;-R^K zZ~y$7HQ&aUBR);nxaJ(@``*CJyO-}G9y;&g+jkM4$1m$%AeJK@x)C<*U*g-V z5r2j6dE-qV;L8yY&e!X#=gZ4V7K{av2VZ2n7G5c7{mMq&3})nBhNbh x_Qhh)b$qeAxhLxQVvfKz@Ws>)Y%^o-b%)BVt%12-zWIlkd#*8?`v-+f*uT^o(%%38 literal 0 HcmV?d00001 diff --git a/crates/vent-runtime/res/shaders/app/3D/shader.vert b/crates/vent-runtime/res/shaders/app/3D/shader.vert new file mode 100644 index 0000000..d6bbafc --- /dev/null +++ b/crates/vent-runtime/res/shaders/app/3D/shader.vert @@ -0,0 +1,30 @@ +#version 450 core + + +layout (location = 0) in vec3 in_position; +layout (location = 1) in vec2 in_tex_coord; +layout (location = 2) in vec3 in_normal; + +layout (binding = 0) uniform UBO { + vec3 ubo_view_position; + mat4 projection; + mat4 view; + mat4 transformation; +}; + + +layout (location = 0) out vec2 tex_coord; +layout (location = 1) out vec3 normal; +layout (location = 2) out vec3 world_position; +layout (location = 3) out vec4 position; +layout (location = 4) out vec3 view_position; + +void main() { + tex_coord = in_tex_coord; + normal = in_normal; + world_position = in_position; + position = projection * view * transformation * vec4(in_position, 1.0); + view_position = ubo_view_position; + + gl_Position = position; +} \ No newline at end of file diff --git a/crates/vent-runtime/res/shaders/app/3D/shader.vert.spv b/crates/vent-runtime/res/shaders/app/3D/shader.vert.spv new file mode 100644 index 0000000000000000000000000000000000000000..c37c819f7f48923a57e93db608e9ab918ade7282 GIT binary patch literal 2132 zcmZA1+iqJ`5C-7g1gC)lrIa3kQk;f!Arxq#rL>5HlwMRKsDfK7BnEBd+L7Z@#1)SK zJQ7dE4HEyi?Fm*^G+yif=dfnY%+Bh{=ECV?Z{Lv#Sx7FqnqbzS%x8rx=Z-xJ9G}swVzaLIh8TN9(TXgkc z_u=K%@$Go_p#5#gu5|K??yFII@O67Q+a2!>k96{+do&sy>C{F)t?hJC-!6A(j`a+7 zC%s-RWAg#KmtLQivHrjoz23lbxwoikj?Jc@tb4IhXZQ6wJg+;<=DA~BhJV4${p7Li z2lLyB)P1<)e)3uNgZcdtDL-8KZ7*i3-mTYHB9?c;8y%Ws{r7I)iFnmt^|gxgPMp0s zci`M#oHI^5xroQ^Y<}$<;n+Bz&uJ}tKXM@+-T>3}gV(dy+iowgIl$3Bm0dpk=;6vy zyk~;ND|`P@obl{ob5nXf6tDEKIl`5_Ibsjfn}>JuVRMGN82n;( zI`)_2X};WzFA?YEU^Sr^2i8a2x!_l__apMSy1;r0^M5rvTQN(2Wx*AGBUoOrH(ZT0 z&F`PryUj`I-S;7NmiQlK7hmr3`MBfrlO-PfNkl%Ef^TMb2hO{1Wmg9r9TE4_?CzwO z2R#2D-y~+QyHo8fcK?L&t=x&NnRq&49_~hKZeTijJ|EFrIx_&5?p)6LN~hoO7m2Kn z{fOGDFMBoJi1Z_6vzc>!cV+WhIQ(CU!{_w~KYaPUnKM7VD8ILI#+TpQIrGI=zVGBL z-)|FJ4d0F6tm59w8Fyld+gfmXx08zL!TS;Z?CH(HpNUI%E#iJQYGamh@;3w5Bl0&J imD`O4&)y8dbmDy$5re;P<4#0>`Ll=F{F|(AM*agIHjt, - @location(0) tex_coord: vec2, - @location(1) normal: vec3, - @location(2) world_position: vec3, -}; - -struct UBO { - view_position: vec3, - projection: mat4x4, - view: mat4x4, - transformation: mat4x4, -} - -struct Material { - base_color: vec4, -} - -struct Light { - position: vec3, - color: vec3, -} - -@group(0) @binding(0) -var ubo: UBO; - -@group(1) @binding(2) -var material : Material; - -@group(2) @binding(0) -var light: Light; - - -@vertex -fn vs_main( - @location(0) position: vec3, - @location(1) tex_coord: vec2, - @location(2) normal: vec3, -) -> VertexOutput { - var result: VertexOutput; - result.tex_coord = tex_coord; - result.normal = normal; - result.world_position = position; - result.position = ubo.projection * ubo.view * ubo.transformation * vec4(position, 1.0); - return result; -} - -@group(1) -@binding(0) -var texture_diffuse: texture_2d; -@group(1) -@binding(1) -var sampler_diffuse: sampler; - -@fragment -fn fs_main(vertex: VertexOutput) -> @location(0) vec4 { - let sample = textureSample(texture_diffuse, sampler_diffuse, vertex.tex_coord) * material.base_color; - - // We don't need (or want) much ambient light, so 0.1 is fine - let ambient_strength = 0.1; - let ambient_color = light.color * ambient_strength; - - let light_dir = normalize(light.position - vertex.world_position); - let view_dir = normalize(ubo.view_position.xyz - vertex.world_position); - let half_dir = normalize(view_dir + light_dir); - - let diffuse_strength = max(dot(vertex.world_position, light_dir), 0.0); - let diffuse_color = light.color * diffuse_strength; - - let specular_strength = pow(max(dot(vertex.world_position, half_dir), 0.0), 32.0); - let specular_color = specular_strength * light.color; - - let result = (ambient_color + diffuse_color + specular_color) * sample.xyz; - - return vec4(result, sample.a); -} diff --git a/crates/vent-runtime/src/lib.rs b/crates/vent-runtime/src/lib.rs index 7c40ebe..99f89b6 100644 --- a/crates/vent-runtime/src/lib.rs +++ b/crates/vent-runtime/src/lib.rs @@ -1,14 +1,13 @@ use crate::render::Dimension; use render::camera::camera_controller3d::CameraController3D; -use render::camera::{Camera, Camera3D}; use render::DefaultRuntimeRenderer; use simple_logger::SimpleLogger; use vent_common::project::VentApplicationProject; use vent_common::util::crash::init_panic_hook; use vent_common::window::VentWindow; -use winit::event::{DeviceEvent, ElementState, Event, WindowEvent}; +use winit::event::{DeviceEvent, Event, WindowEvent}; use winit::window::WindowBuilder; pub mod render; @@ -45,17 +44,15 @@ impl VentApplication { let vent_window = VentWindow::new(window_builder); // TODO - let mut cam = Camera3D::new(); - let mut renderer = DefaultRuntimeRenderer::new( Dimension::D3, &vent_window.window, &vent_window.event_loop, - &mut cam, ); let mut controller = CameraController3D::new(3000.0, 10.0); let mut delta_time = 0.0; + vent_window .event_loop .run(move |event, elwt| { @@ -72,10 +69,14 @@ impl VentApplication { controller.process_mouse_input(&vent_window.window, button, state); } WindowEvent::KeyboardInput { event, .. } => { - controller.process_keyboard(&mut cam, event, delta_time); + controller.process_keyboard( + renderer.camera.downcast_mut().expect("TODO"), + event, + delta_time, + ); } WindowEvent::Resized(physical_size) => { - renderer.resize(physical_size, &mut cam); + renderer.resize(physical_size); } // WindowEvent::ScaleFactorChanged { // inner_size_writer, .. @@ -84,7 +85,7 @@ impl VentApplication { // renderer.resize(new_inner_size, &mut cam); // } WindowEvent::RedrawRequested => { - delta_time = renderer.render(&vent_window.window, &mut cam); + delta_time = renderer.render(&vent_window.window); } _ => {} } @@ -92,7 +93,12 @@ impl VentApplication { Event::DeviceEvent { event: DeviceEvent::MouseMotion { delta }, .. - } => controller.process_mouse_movement(&mut cam, delta.0, delta.1, delta_time), + } => controller.process_mouse_movement( + renderer.camera.downcast_mut().expect("TODO"), + delta.0, + delta.1, + delta_time, + ), // ... _ => {} diff --git a/crates/vent-runtime/src/render/camera/camera_controller3d.rs b/crates/vent-runtime/src/render/camera/camera_controller3d.rs index fa4a67c..ee4a346 100644 --- a/crates/vent-runtime/src/render/camera/camera_controller3d.rs +++ b/crates/vent-runtime/src/render/camera/camera_controller3d.rs @@ -1,6 +1,6 @@ use winit::{ event::{ElementState, KeyEvent}, - keyboard::{self, Key, NamedKey, PhysicalKey}, + keyboard::{Key, NamedKey}, }; use super::Camera3D; diff --git a/crates/vent-runtime/src/render/camera/mod.rs b/crates/vent-runtime/src/render/camera/mod.rs index 7b904cb..4fd52d6 100644 --- a/crates/vent-runtime/src/render/camera/mod.rs +++ b/crates/vent-runtime/src/render/camera/mod.rs @@ -1,21 +1,25 @@ +use std::mem::size_of; + +use ash::vk; use downcast_rs::{impl_downcast, Downcast}; use glam::{Quat, Vec3}; +use vent_rendering::{buffer::VulkanBuffer, instance::VulkanInstance}; use super::{d3::UBO3D, Dimension}; pub mod camera_controller3d; pub trait Camera: Downcast { - fn new() -> Self + fn new(instance: &VulkanInstance) -> Self where Self: Sized; } impl_downcast!(Camera); -pub fn from_dimension(dimension: Dimension) -> Box { +pub fn from_dimension(instance: &VulkanInstance, dimension: &Dimension) -> Box { match dimension { - Dimension::D2 => Box::new(Camera2D::new()), - Dimension::D3 => Box::new(Camera3D::new()), + Dimension::D2 => Box::new(Camera2D::new(instance)), + Dimension::D3 => Box::new(Camera3D::new(instance)), } } @@ -27,7 +31,7 @@ pub struct Camera2D { impl Camera for Camera2D { #[inline] #[must_use] - fn new() -> Self + fn new(_instance: &VulkanInstance) -> Self where Self: Sized, { @@ -42,6 +46,7 @@ pub struct Camera3D { znear: f32, zfar: f32, ubo: UBO3D, + ubo_buffers: Vec, position: glam::Vec3, rotation: glam::Quat, @@ -50,10 +55,20 @@ pub struct Camera3D { impl Camera for Camera3D { #[inline] #[must_use] - fn new() -> Self + fn new(instance: &VulkanInstance) -> Self where Self: Sized, { + let mut ubo_buffers = vec![]; + for _ in 0..instance.swapchain_images.len() { + ubo_buffers.push(VulkanBuffer::new( + &instance.device, + &instance.memory_allocator, + size_of::() as vk::DeviceSize, + vk::BufferUsageFlags::UNIFORM_BUFFER, + )) + } + Self { fovy: 60.0, znear: 0.1, @@ -61,6 +76,7 @@ impl Camera for Camera3D { rotation: glam::Quat::IDENTITY, position: Vec3::ZERO, ubo: Default::default(), + ubo_buffers, } } } @@ -79,6 +95,16 @@ impl Camera3D { self.ubo.projection = projection.to_cols_array_2d(); } + pub fn write(&self, instance: &VulkanInstance, index: u32) { + unsafe { + self.ubo_buffers[index as usize].upload_type( + &instance.device, + &self.ubo, + size_of::() as vk::DeviceSize, + ) + } + } + pub fn set_x(&mut self, x: f32) { self.position.x = x; self.recreate_view(); diff --git a/crates/vent-runtime/src/render/d2/mod.rs b/crates/vent-runtime/src/render/d2/mod.rs index 850b54f..f8134e2 100644 --- a/crates/vent-runtime/src/render/d2/mod.rs +++ b/crates/vent-runtime/src/render/d2/mod.rs @@ -1,13 +1,12 @@ use super::{camera::Camera, Renderer}; -#[repr(C)] -#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)] +#[derive(Clone, Copy)] pub struct UBO2D {} pub struct Renderer2D {} impl Renderer for Renderer2D { - fn init(instance: &vent_rendering::instance::VulkanInstance, camera: &mut dyn Camera) -> Self + fn init(_instance: &vent_rendering::instance::VulkanInstance, _camera: &mut dyn Camera) -> Self where Self: Sized, { @@ -16,18 +15,23 @@ impl Renderer for Renderer2D { fn resize( &mut self, - instance: &vent_rendering::instance::VulkanInstance, - new_size: &winit::dpi::PhysicalSize, - camera: &mut dyn Camera, + _instance: &vent_rendering::instance::VulkanInstance, + _new_size: &winit::dpi::PhysicalSize, + _camera: &mut dyn Camera, ) { todo!() } fn render( &mut self, - instance: &vent_rendering::instance::VulkanInstance, - camera: &mut dyn Camera, + _instance: &vent_rendering::instance::VulkanInstance, + _image_index: u32, + _camera: &mut dyn Camera, ) { todo!() } + + fn destroy(&mut self, _instance: &vent_rendering::instance::VulkanInstance) { + todo!() + } } diff --git a/crates/vent-runtime/src/render/d3/light_renderer.rs b/crates/vent-runtime/src/render/d3/light_renderer.rs index a438ff8..6395b15 100644 --- a/crates/vent-runtime/src/render/d3/light_renderer.rs +++ b/crates/vent-runtime/src/render/d3/light_renderer.rs @@ -1,5 +1,3 @@ -use std::mem; - use vent_assets::Mesh3D; #[allow(dead_code)] @@ -11,17 +9,6 @@ pub struct LightRenderer { // light_render_pipeline: wgpu::RenderPipeline, } -#[repr(C)] -#[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] -pub struct LightUBO { - position: [f32; 3], - // Due to uniforms requiring 16 byte (4 float) spacing, we need to use a padding field here - _padding: u32, - color: [f32; 3], - // Due to uniforms requiring 16 byte (4 float) spacing, we need to use a padding field here - _padding2: u32, -} - #[allow(dead_code)] impl LightRenderer { pub fn new(// device: &wgpu::Device, @@ -121,7 +108,7 @@ impl LightRenderer { pub fn render( &self, // camera_bind_group: &'rp wgpu::BindGroup, - mesh: &Mesh3D, + _mesh: &Mesh3D, ) { // rpass.set_pipeline(&self.light_render_pipeline); // rpass.set_bind_group(0, camera_bind_group, &[]); diff --git a/crates/vent-runtime/src/render/d3/mod.rs b/crates/vent-runtime/src/render/d3/mod.rs index ca2736e..f36e0b3 100644 --- a/crates/vent-runtime/src/render/d3/mod.rs +++ b/crates/vent-runtime/src/render/d3/mod.rs @@ -1,13 +1,11 @@ -use std::mem; - +use ash::vk; use glam::Mat4; use vent_assets::Mesh3D; + use vent_ecs::world::World; -use vent_rendering::{instance::VulkanInstance, Vertex3D}; +use vent_rendering::{instance::VulkanInstance, Vertex, Vertex3D}; use winit::dpi::PhysicalSize; -use self::light_renderer::LightRenderer; - use super::{ camera::{Camera, Camera3D}, model::Entity3D, @@ -18,7 +16,7 @@ use super::{ pub mod light_renderer; #[repr(C)] -#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)] +#[derive(Clone, Copy)] pub struct UBO3D { pub view_position: [f32; 3], pub _padding: u32, @@ -46,7 +44,7 @@ pub struct Renderer3D { // bind_group: wgpu::BindGroup, // depth_view: wgpu::TextureView, // uniform_buf: wgpu::Buffer, - // pipeline: wgpu::RenderPipeline, + pipeline: vk::Pipeline, // pipeline_wire: Option, } @@ -55,7 +53,97 @@ impl Renderer for Renderer3D { where Self: Sized, { - // let camera: &Camera3D = camera.downcast_ref().unwrap(); + let camera: &Camera3D = camera.downcast_ref().unwrap(); + let vertex_shader = concat!( + env!("CARGO_MANIFEST_DIR"), + "/res/shaders/app/3D/shader.vert" + ); + let fragment_shader = concat!( + env!("CARGO_MANIFEST_DIR"), + "/res/shaders/app/3D/shader.frag" + ); + let pipeline = vent_rendering::pipeline::create_pipeline( + instance, + vertex_shader.to_owned(), + fragment_shader.to_owned(), + Vertex3D::BINDING_DESCRIPTION, + &Vertex3D::input_descriptions(), + instance.surface_resolution, + ); + + let mut mesh_renderer = ModelRenderer3D::default(); + + // // -------------- DEMO ------------------- + let mut world = World::new(); + + let model = concat!( + env!("CARGO_MANIFEST_DIR"), + "/res/models/test/Sponza-GLTF/Sponza.gltf" + ); + + pollster::block_on(async { + let mesh = Entity3D::new(vent_assets::Model3D::load(instance, model).await); + mesh_renderer.insert(world.create_entity(), mesh); + }); + + // Record Command Buffers + let render_area = vk::Rect2D::builder() + .offset(vk::Offset2D::default()) + .extent(instance.surface_resolution) + .build(); + + let color_clear_value = vk::ClearValue { + color: vk::ClearColorValue { + float32: [0.0, 0.0, 0.0, 1.0], + }, + }; + + let depth_clear_value = vk::ClearValue { + depth_stencil: vk::ClearDepthStencilValue { + depth: 1.0, + stencil: 0, + }, + }; + + let clear_values = &[color_clear_value, depth_clear_value]; + + for (i, command_buffer) in instance.command_buffers.iter().enumerate() { + unsafe { + let info = vk::CommandBufferBeginInfo::default(); + + instance.device.begin_command_buffer(*command_buffer, &info); + + let info = vk::RenderPassBeginInfo::builder() + .render_pass(instance.render_pass) + .framebuffer(instance.frame_buffers[i]) + .render_area(render_area) + .clear_values(clear_values); + + instance.device.cmd_begin_render_pass( + *command_buffer, + &info, + vk::SubpassContents::INLINE, + ); + instance.device.cmd_bind_pipeline( + *command_buffer, + vk::PipelineBindPoint::GRAPHICS, + pipeline, + ); + + mesh_renderer.record_buffer( + instance, + *command_buffer, + i, + instance.pipeline_layout, + &mut camera.ubo(), + ); + + // END + instance.device.cmd_end_render_pass(*command_buffer); + instance.device.end_command_buffer(*command_buffer); + } + } + // // Create pipeline layout // let vertex_group_layout = // device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { @@ -74,54 +162,8 @@ impl Renderer for Renderer3D { // }], // }); - // let texture_bind_group_layout = - // device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - // entries: &[ - // wgpu::BindGroupLayoutEntry { - // binding: 0, - // visibility: wgpu::ShaderStages::FRAGMENT, - // ty: wgpu::BindingType::Texture { - // multisampled: false, - // view_dimension: wgpu::TextureViewDimension::D2, - // sample_type: wgpu::TextureSampleType::Float { filterable: true }, - // }, - // count: None, - // }, - // wgpu::BindGroupLayoutEntry { - // binding: 1, - // visibility: wgpu::ShaderStages::FRAGMENT, - // ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering), - // count: None, - // }, - // wgpu::BindGroupLayoutEntry { - // binding: 2, - // visibility: wgpu::ShaderStages::FRAGMENT, - // ty: wgpu::BindingType::Buffer { - // ty: wgpu::BufferBindingType::Uniform, - // has_dynamic_offset: false, - // min_binding_size: wgpu::BufferSize::new(mem::size_of::< - // vent_assets::model::Material, - // >() - // as wgpu::BufferAddress), - // }, - // count: None, - // }, - // ], - // label: Some("texture_bind_group_layout"), - // }); - // let light_renderer = LightRenderer::new(device, &vertex_group_layout, config.format); - // let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - // label: Some("3D Pipeline Layout"), - // bind_group_layouts: &[ - // &vertex_group_layout, - // &texture_bind_group_layout, - // &light_renderer.light_bind_group_layout, - // ], - // push_constant_ranges: &[], - // }); - // // Create other resources // let ubo = camera.ubo(); // let uniform_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { @@ -130,119 +172,6 @@ impl Renderer for Renderer3D { // usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, // }); - // // Create bind group - // let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { - // layout: &vertex_group_layout, - // entries: &[wgpu::BindGroupEntry { - // binding: 0, - // resource: uniform_buf.as_entire_binding(), - // }], - // label: Some("3D Bind Group"), - // }); - - // let shader = device.create_shader_module(wgpu::include_wgsl!(concat!( - // env!("CARGO_MANIFEST_DIR"), - // "/res/shaders/app/3D/shader.wgsl" - // ))); - // let vertex_buffer_layout = [Vertex3D::LAYOUT]; - - // let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { - // label: Some("3D Renderer Pipeline"), - // layout: Some(&pipeline_layout), - // vertex: wgpu::VertexState { - // module: &shader, - // entry_point: "vs_main", - // buffers: &vertex_buffer_layout, - // }, - // fragment: Some(wgpu::FragmentState { - // module: &shader, - // entry_point: "fs_main", - // targets: &[Some(config.format.into())], - // }), - // primitive: wgpu::PrimitiveState { - // cull_mode: Some(wgpu::Face::Back), - // front_face: wgpu::FrontFace::Cw, - // ..Default::default() - // }, - // depth_stencil: Some(wgpu::DepthStencilState { - // format: vent_assets::Texture::DEPTH_FORMAT, - // depth_write_enabled: true, - // depth_compare: wgpu::CompareFunction::Less, - // stencil: wgpu::StencilState::default(), - // bias: wgpu::DepthBiasState::default(), - // }), - // multisample: wgpu::MultisampleState::default(), - // multiview: None, - // }); - - // // TODO - // let pipeline_wire = if device - // .features() - // .contains(wgpu::Features::POLYGON_MODE_LINE) - // { - // let shader = device.create_shader_module(wgpu::include_wgsl!(concat!( - // env!("CARGO_MANIFEST_DIR"), - // "/res/shaders/app/3D/wireframe.wgsl" - // ))); - - // let pipeline_wire = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { - // label: Some("3D Pipeline Wireframe"), - // layout: Some(&pipeline_layout), - // vertex: wgpu::VertexState { - // module: &shader, - // entry_point: "vs_main", - // buffers: &[], - // }, - // fragment: Some(wgpu::FragmentState { - // module: &shader, - // entry_point: "fs_main", - // targets: &[Some(wgpu::ColorTargetState { - // format: config.format, - // blend: Some(wgpu::BlendState { - // color: wgpu::BlendComponent { - // operation: wgpu::BlendOperation::Add, - // src_factor: wgpu::BlendFactor::SrcAlpha, - // dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - // }, - // alpha: wgpu::BlendComponent::REPLACE, - // }), - // write_mask: wgpu::ColorWrites::ALL, - // })], - // }), - // primitive: wgpu::PrimitiveState { - // cull_mode: Some(wgpu::Face::Back), - // front_face: wgpu::FrontFace::Cw, - // polygon_mode: wgpu::PolygonMode::Line, - // ..Default::default() - // }, - // depth_stencil: None, - // multisample: wgpu::MultisampleState::default(), - // multiview: None, - // }); - // Some(pipeline_wire) - // } else { - // None - // }; - - let mut mesh_renderer = ModelRenderer3D::default(); - - // // -------------- DEMO ------------------- - // let mut world = World::new(); - - // let model = concat!( - // env!("CARGO_MANIFEST_DIR"), - // "/res/models/test/Sponza-GLTF/Sponza.gltf" - // ); - - // pollster::block_on(async { - // let mesh = Entity3D::new( - // vent_assets::Model3D::load(device, queue, model, &texture_bind_group_layout).await, - // ); - // mesh_renderer.insert(world.create_entity(), mesh); - // }); - - // // ------------------------------- - let tmp_light_mesh = create_tmp_cube(instance); // let depth_view = vent_assets::Texture::create_depth_view( @@ -259,16 +188,16 @@ impl Renderer for Renderer3D { // depth_view, // bind_group, // uniform_buf, - // pipeline, + pipeline, // pipeline_wire, } } fn resize( &mut self, - instance: &VulkanInstance, - new_size: &PhysicalSize, - camera: &mut dyn Camera, + _instance: &VulkanInstance, + _new_size: &PhysicalSize, + _camera: &mut dyn Camera, ) { // self.depth_view = vent_assets::Texture::create_depth_view( // device, @@ -283,48 +212,103 @@ impl Renderer for Renderer3D { // queue.write_buffer(&self.uniform_buf, 0, bytemuck::cast_slice(&[camera.ubo()])); } - fn render(&mut self, instance: &VulkanInstance, camera: &mut dyn Camera) { - // let camera: &mut Camera3D = camera.downcast_mut().unwrap(); - - // let mut ubo = camera.ubo(); - // { - // let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - // label: Some("3D Render Pass"), - // color_attachments: &[Some(wgpu::RenderPassColorAttachment { - // view, - // resolve_target: None, - // ops: wgpu::Operations { - // load: wgpu::LoadOp::Clear(wgpu::Color { - // r: 0.1, - // g: 0.2, - // b: 0.3, - // a: 1.0, - // }), - // store: true, - // }, - // })], - // depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { - // view: &self.depth_view, - // depth_ops: Some(wgpu::Operations { - // load: wgpu::LoadOp::Clear(1.0), - // store: true, - // }), - // stencil_ops: None, - // }), - // }); + fn render(&mut self, instance: &VulkanInstance, image_index: u32, camera: &mut dyn Camera) { + let camera: &mut Camera3D = camera.downcast_mut().unwrap(); + + let _ubo = camera.ubo(); + // self.light_renderer // .render(&mut rpass, &self.bind_group, &self.tmp_light_mesh); - // rpass.set_pipeline(&self.pipeline); - // if let Some(ref pipe) = self.pipeline_wire { - // rpass.set_pipeline(pipe); - // } // rpass.set_bind_group(0, &self.bind_group, &[]); // rpass.set_bind_group(2, &self.light_renderer.light_bind_group, &[]); - // self.mesh_renderer.render(&mut rpass, &mut ubo); + // } - // queue.write_buffer(&self.uniform_buf, 0, bytemuck::cast_slice(&[ubo])); + camera.write(instance, image_index) + } + + fn destroy(&mut self, instance: &VulkanInstance) { + self.mesh_renderer.destroy_all(instance); + unsafe { + instance.device.destroy_pipeline(self.pipeline, None); + } + } +} + +fn write_sets( + instance: &VulkanInstance, + diffuse_texture: VulkanImage, + uniforms_buffers: &Vec, +) -> Vec { + let descriptor_sets = VulkanInstance::allocate_descriptor_sets( + &instance.device, + instance.descriptor_pool, + instance.descriptor_set_layout, + uniforms_buffers.len(), + ); + + for (i, &_descritptor_set) in descriptor_sets.iter().enumerate() { + let image_info = vk::DescriptorImageInfo::builder() + .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) + .image_view(diffuse_texture.image_view) + .sampler(diffuse_texture.sampler) + .build(); + + let material_buffer_info = vk::DescriptorBufferInfo::builder() + .buffer(uniforms_buffers[i].buffer) + .offset(0) + .range(size_of::() as vk::DeviceSize) + .build(); + + let light_buffer_info = vk::DescriptorBufferInfo::builder() + .buffer(uniforms_buffers[i].buffer) + .offset(0) + .range(size_of::() as vk::DeviceSize) + .build(); + + let desc_sets = [ + // Vertex + vk::WriteDescriptorSet { + dst_set: descriptor_sets[0], + dst_binding: 0, + descriptor_count: 1, + descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + p_buffer_info: &buffer_info, + ..Default::default() + }, + // Fragment + vk::WriteDescriptorSet { + dst_set: descriptor_sets[0], + descriptor_count: 1, + descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, + p_image_info: &image_info, + ..Default::default() + }, + vk::WriteDescriptorSet { + dst_set: descriptor_sets[0], + dst_binding: 1, + descriptor_count: 1, + descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + p_buffer_info: &material_buffer_info, + ..Default::default() + }, + vk::WriteDescriptorSet { + dst_set: descriptor_sets[0], + dst_binding: 2, + descriptor_count: 1, + descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + p_buffer_info: &light_buffer_info, + ..Default::default() + }, + ]; + + unsafe { + instance + .device + .update_descriptor_sets(&fragment_desc_sets, &[]); + } } + descriptor_sets } fn create_tmp_cube(instance: &VulkanInstance) -> vent_assets::Mesh3D { diff --git a/crates/vent-runtime/src/render/gui/gui_renderer.rs b/crates/vent-runtime/src/render/gui/gui_renderer.rs index 69596a7..7c4d531 100644 --- a/crates/vent-runtime/src/render/gui/gui_renderer.rs +++ b/crates/vent-runtime/src/render/gui/gui_renderer.rs @@ -1,6 +1,3 @@ -use vent_rendering::instance::VulkanInstance; -use winit::raw_window_handle::DisplayHandle; - use super::{debug_gui::RenderData, GUI}; pub struct EguiRenderer { @@ -22,7 +19,7 @@ impl EguiRenderer { } } - pub fn render(&mut self, render_data: &RenderData) { + pub fn render(&mut self, _render_data: &RenderData) { // let input = self.state.take_egui_input(window); // let output = self.context.run(input, |ctx| { // for gui in self.guis.iter_mut() { @@ -86,7 +83,7 @@ impl EguiRenderer { // ) } - pub fn progress_event(&mut self, event: &winit::event::WindowEvent) { + pub fn progress_event(&mut self, _event: &winit::event::WindowEvent) { // let _ = self.state.on_event(&self.context, event); } } diff --git a/crates/vent-runtime/src/render/mod.rs b/crates/vent-runtime/src/render/mod.rs index dfd1e55..31e7e01 100644 --- a/crates/vent-runtime/src/render/mod.rs +++ b/crates/vent-runtime/src/render/mod.rs @@ -4,7 +4,7 @@ use vent_rendering::instance::VulkanInstance; use winit::dpi::PhysicalSize; use winit::window::Window; -use self::camera::Camera; +use self::camera::{from_dimension, Camera}; use self::d2::Renderer2D; use self::d3::Renderer3D; use self::gui::debug_gui::{DebugGUI, RenderData}; @@ -22,6 +22,7 @@ mod d3; pub(crate) struct DefaultRuntimeRenderer { instance: VulkanInstance, runtime_renderer: RawRuntimeRenderer, + pub camera: Box, } impl DefaultRuntimeRenderer { @@ -29,13 +30,15 @@ impl DefaultRuntimeRenderer { dimension: Dimension, window: &winit::window::Window, event_loop: &winit::event_loop::EventLoopWindowTarget<()>, - camera: &mut dyn Camera, ) -> Self { let instance = VulkanInstance::new("TODO", window); - let runtime_renderer = RawRuntimeRenderer::new(dimension, &instance, event_loop, camera); + let mut camera = from_dimension(&instance, &dimension); + let runtime_renderer = + RawRuntimeRenderer::new(dimension, &instance, event_loop, camera.as_mut()); Self { instance, runtime_renderer, + camera, } } @@ -43,19 +46,20 @@ impl DefaultRuntimeRenderer { self.runtime_renderer.progress_event(event); } - pub(crate) fn render( - &mut self, - window: &winit::window::Window, - camera: &mut dyn Camera, - ) -> f32 { - let detla = self.runtime_renderer.render(&self.instance, window, camera); - - detla + pub(crate) fn render(&mut self, window: &winit::window::Window) -> f32 { + self.runtime_renderer + .render(&mut self.instance, window, self.camera.as_mut()) } - pub(crate) fn resize(&mut self, new_size: &PhysicalSize, camera: &mut dyn Camera) { + pub(crate) fn resize(&mut self, new_size: &PhysicalSize) { self.runtime_renderer - .resize(&self.instance, new_size, camera); + .resize(&self.instance, new_size, self.camera.as_mut()); + } +} + +impl Drop for DefaultRuntimeRenderer { + fn drop(&mut self) { + self.runtime_renderer.destroy(&self.instance); } } @@ -76,7 +80,9 @@ pub trait Renderer { camera: &mut dyn Camera, ); - fn render(&mut self, instance: &VulkanInstance, camera: &mut dyn Camera); + fn render(&mut self, instance: &VulkanInstance, image_index: u32, camera: &mut dyn Camera); + + fn destroy(&mut self, instance: &VulkanInstance); } pub struct RawRuntimeRenderer { @@ -94,7 +100,7 @@ impl RawRuntimeRenderer { pub fn new( dimension: Dimension, instance: &VulkanInstance, - event_loop: &winit::event_loop::EventLoopWindowTarget<()>, + _event_loop: &winit::event_loop::EventLoopWindowTarget<()>, camera: &mut dyn Camera, ) -> Self { let multi_renderer: Box = match dimension { @@ -121,13 +127,18 @@ impl RawRuntimeRenderer { pub fn render( &mut self, - instance: &VulkanInstance, - window: &Window, + instance: &mut VulkanInstance, + _window: &Window, camera: &mut dyn Camera, ) -> f32 { let frame_start = Instant::now(); - self.multi_renderer.render(instance, camera); + let image = instance.next_image(); + + if let Some(image_index) = image { + self.multi_renderer.render(instance, image_index, camera); + instance.submit(image_index); + } // self.gui_renderer.render( // surface_view, @@ -138,8 +149,6 @@ impl RawRuntimeRenderer { // &self.current_data, // ); - // queue.submit(Some(encoder2.finish())); - // TODO #[cfg(target_arch = "wasm32")] { @@ -192,4 +201,9 @@ impl RawRuntimeRenderer { // Uses the NEW Resized config self.multi_renderer.resize(instance, new_size, camera) } + + pub fn destroy(&mut self, instance: &VulkanInstance) { + self.multi_renderer.destroy(instance); + // TODO Egui destroy + } } diff --git a/crates/vent-runtime/src/render/model_renderer.rs b/crates/vent-runtime/src/render/model_renderer.rs index 7e5aa22..2d6c30f 100644 --- a/crates/vent-runtime/src/render/model_renderer.rs +++ b/crates/vent-runtime/src/render/model_renderer.rs @@ -1,4 +1,4 @@ -use ash::vk; +use ash::vk::{self}; use glam::{Mat4, Quat}; use std::collections::HashMap; use vent_ecs::entity::Entity; @@ -47,19 +47,28 @@ impl ModelRenderer3D { self.map.iter_mut() } - pub fn render( + pub fn record_buffer( &self, - instance: VulkanInstance, + instance: &VulkanInstance, + command_buffer: vk::CommandBuffer, + buffer_index: usize, pipeline_layout: vk::PipelineLayout, ubo: &mut UBO3D, ) { for model in self.map.values() { ubo.transformation = Self::calc_trans_matrix(model).to_cols_array_2d(); - for (i, buffer) in instance.command_buffers.iter().enumerate() { - model - .rendering_model - .draw(&instance.device, pipeline_layout, *buffer, i as u32); - } + model.rendering_model.draw( + &instance.device, + pipeline_layout, + command_buffer, + buffer_index, + ); + } + } + + pub fn destroy_all(&mut self, instance: &VulkanInstance) { + for model in self.map.values_mut() { + model.rendering_model.destroy(instance) } } From ca81c93314846c8542ebd4aa45c03f0f5fe08214 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev <71594357+Snowiiii@users.noreply.github.com> Date: Thu, 30 Nov 2023 22:12:19 +0100 Subject: [PATCH 06/14] Fixed all Crashes We are now Able to Start without Crashing or any Vulkan Errors, Great Right!. The only thing is that i removed the Model Loading for now, but this will Implement soon --- Cargo.lock | 249 ++++++++++-------- crates/vent-assets/src/lib.rs | 4 +- crates/vent-assets/src/model/gltf.rs | 85 +++--- crates/vent-assets/src/model/mod.rs | 13 +- crates/vent-assets/src/model/obj.rs | 56 ++-- crates/vent-common/Cargo.toml | 2 +- crates/vent-ecs/Cargo.toml | 2 +- crates/vent-editor/Cargo.toml | 4 +- crates/vent-rendering/Cargo.toml | 2 +- crates/vent-rendering/src/instance.rs | 35 ++- crates/vent-rendering/src/surface.rs | 21 +- crates/vent-runtime/Cargo.toml | 2 +- .../src/render/d3/light_renderer.rs | 11 + crates/vent-runtime/src/render/d3/mod.rs | 165 ++++++------ 14 files changed, 343 insertions(+), 308 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 839b028..593e9ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,9 +99,9 @@ dependencies = [ [[package]] name = "arboard" -version = "3.2.1" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac57f2b058a76363e357c056e4f74f1945bf734d37b8b3ef49066c4787dde0fc" +checksum = "aafb29b107435aa276664c1db8954ac27a6e105cdad3c88287a199eb0e313c08" dependencies = [ "clipboard-win", "log", @@ -111,7 +111,7 @@ dependencies = [ "parking_lot", "thiserror", "winapi", - "x11rb 0.10.1", + "x11rb", ] [[package]] @@ -373,9 +373,9 @@ dependencies = [ [[package]] name = "core-foundation" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ "core-foundation-sys", "libc", @@ -383,9 +383,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "core-graphics" @@ -598,12 +598,12 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -704,9 +704,9 @@ checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] @@ -717,16 +717,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" -[[package]] -name = "gethostname" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "gethostname" version = "0.3.0" @@ -813,9 +803,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" [[package]] name = "heck" @@ -874,9 +864,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -988,9 +978,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" +checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" dependencies = [ "wasm-bindgen", ] @@ -1046,9 +1036,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" [[package]] name = "lock_api" @@ -1503,9 +1493,9 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pin-project-lite" @@ -1534,16 +1524,16 @@ dependencies = [ [[package]] name = "polling" -version = "3.3.0" +version = "3.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53b6af1f60f36f8c2ac2aad5459d75a5a9b4be1e8cdd40264f315d78193e531" +checksum = "cf63fa624ab313c11656b4cda960bfc46c410187ad493c41f6ba2d8c1e991c9e" dependencies = [ "cfg-if", "concurrent-queue", "pin-project-lite", "rustix", "tracing", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1603,9 +1593,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" dependencies = [ "unicode-ident", ] @@ -1697,9 +1687,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.24" +version = "0.38.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ad981d6c340a49cdc40a1028d9c6084ec7e9fa33fcb839cab656a267071e234" +checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" dependencies = [ "bitflags 2.4.1", "errno", @@ -1763,18 +1753,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", @@ -1800,14 +1790,14 @@ checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" [[package]] name = "simple_logger" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2230cd5c29b815c9b699fb610b49a5ed65588f3509d9f0108be3a885da629333" +checksum = "da0ca6504625ee1aa5fda33913d2005eab98c7a42dd85f116ecce3ff54c9d3ef" dependencies = [ "colored", "log", "time", - "windows-sys 0.42.0", + "windows-sys 0.48.0", ] [[package]] @@ -1942,9 +1932,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.29.10" +version = "0.29.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a18d114d420ada3a891e6bc8e96a2023402203296a47cdd65083377dad18ba5" +checksum = "cd727fc423c2060f6c92d9534cef765c65a6ed3f428a03d7def74a8c4348e666" dependencies = [ "cfg-if", "core-foundation-sys", @@ -2170,9 +2160,9 @@ checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "url" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", "idna", @@ -2214,14 +2204,14 @@ dependencies = [ "serde", "serde_json", "sysinfo", - "winit 0.29.3", + "winit 0.29.4", ] [[package]] name = "vent-ecs" version = "0.1.0" dependencies = [ - "winit 0.29.3", + "winit 0.29.4", ] [[package]] @@ -2237,7 +2227,7 @@ dependencies = [ "vent-common", "vent-rendering", "vent-runtime", - "winit 0.29.3", + "winit 0.29.4", ] [[package]] @@ -2248,7 +2238,7 @@ dependencies = [ "image", "log", "raw-window-handle 0.6.0", - "winit 0.29.3", + "winit 0.29.4", ] [[package]] @@ -2268,7 +2258,7 @@ dependencies = [ "vent-common", "vent-ecs", "vent-rendering", - "winit 0.29.3", + "winit 0.29.4", ] [[package]] @@ -2299,9 +2289,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2309,9 +2299,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" dependencies = [ "bumpalo", "log", @@ -2324,9 +2314,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.38" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" +checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" dependencies = [ "cfg-if", "js-sys", @@ -2336,9 +2326,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2346,9 +2336,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", @@ -2359,9 +2349,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" +checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" [[package]] name = "wayland-backend" @@ -2547,9 +2537,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" +checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" dependencies = [ "js-sys", "wasm-bindgen", @@ -2637,21 +2627,6 @@ dependencies = [ "windows-targets 0.48.5", ] -[[package]] -name = "windows-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - [[package]] name = "windows-sys" version = "0.45.0" @@ -2670,6 +2645,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-targets" version = "0.42.2" @@ -2700,6 +2684,21 @@ dependencies = [ "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -2712,6 +2711,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -2724,6 +2729,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -2736,6 +2747,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -2748,6 +2765,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -2760,6 +2783,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -2772,6 +2801,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" @@ -2784,6 +2819,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + [[package]] name = "winit" version = "0.28.7" @@ -2821,9 +2862,9 @@ dependencies = [ [[package]] name = "winit" -version = "0.29.3" +version = "0.29.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "161598019a9da35ab6c34dc46cd13546cba9dbf9816475d4dd9a639455016563" +checksum = "d25d662bb83b511acd839534bb2d88521b0bbc81440969cb077d23c4db9e62c7" dependencies = [ "ahash", "android-activity 0.5.0", @@ -2863,7 +2904,7 @@ dependencies = [ "web-time", "windows-sys 0.48.0", "x11-dl", - "x11rb 0.12.0", + "x11rb", "xkbcommon-dl", ] @@ -2887,19 +2928,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "x11rb" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" -dependencies = [ - "gethostname 0.2.3", - "nix 0.24.3", - "winapi", - "winapi-wsapoll", - "x11rb-protocol 0.10.0", -] - [[package]] name = "x11rb" version = "0.12.0" @@ -2907,23 +2935,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1641b26d4dec61337c35a1b1aaf9e3cba8f46f0b43636c609ab0291a648040a" dependencies = [ "as-raw-xcb-connection", - "gethostname 0.3.0", + "gethostname", "libc", "libloading 0.7.4", "nix 0.26.4", "once_cell", "winapi", "winapi-wsapoll", - "x11rb-protocol 0.12.0", -] - -[[package]] -name = "x11rb-protocol" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67" -dependencies = [ - "nix 0.24.3", + "x11rb-protocol", ] [[package]] @@ -2971,18 +2990,18 @@ checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" [[package]] name = "zerocopy" -version = "0.7.26" +version = "0.7.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e97e415490559a91254a2979b4829267a57d2fcd741a98eee8b722fb57289aa0" +checksum = "f43de342578a3a14a9314a2dab1942cbfcbe5686e1f91acdc513058063eafe18" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.26" +version = "0.7.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f" +checksum = "e1012d89e3acb79fad7a799ce96866cfb8098b74638465ea1b1533d35900ca90" dependencies = [ "proc-macro2", "quote", diff --git a/crates/vent-assets/src/lib.rs b/crates/vent-assets/src/lib.rs index dce77f6..8b0207e 100644 --- a/crates/vent-assets/src/lib.rs +++ b/crates/vent-assets/src/lib.rs @@ -11,8 +11,6 @@ pub trait Asset {} /// This is done by Parsing all Essensial Informations like Vertices, Indices, Materials & More pub struct Model3D { meshes: Vec, - write_sets: Vec, - buffers: Vec, } /// This is a simple mesh that consists of vertices and indices. It is useful when you need to hard-code 3D data into your application. @@ -25,4 +23,6 @@ pub struct Mesh3D { vertex_buf: VulkanBuffer, index_buf: VulkanBuffer, index_count: u32, + descriptor_sets: Option>, + buffers: Option>, } diff --git a/crates/vent-assets/src/model/gltf.rs b/crates/vent-assets/src/model/gltf.rs index b79a0b5..99e148f 100644 --- a/crates/vent-assets/src/model/gltf.rs +++ b/crates/vent-assets/src/model/gltf.rs @@ -13,7 +13,7 @@ use vent_rendering::{ use crate::Model3D; -use super::{Light, Material, Mesh3D, ModelError}; +use super::{Material, Mesh3D, ModelError}; pub(crate) struct GLTFLoader {} @@ -75,13 +75,18 @@ impl GLTFLoader { let loaded_material = Self::load_material(instance, model_dir, primitive.material(), buffer_data); - let loaded_mesh = Self::load_primitive( - instance, - loaded_material, + let primitive = Self::load_primitive(buffer_data, primitive); + + let loaded_mesh = Mesh3D::new( + &instance.device, + &instance.memory_allocator, + &primitive.0, + &primitive.1, + Some(loaded_material.0), + Some(loaded_material.1), mesh.name(), - buffer_data, - primitive, ); + tx.send(loaded_mesh).unwrap(); }); } @@ -98,7 +103,7 @@ impl GLTFLoader { material: gltf::Material<'_>, buffer_data: &[gltf::buffer::Data], // image_data: &[gltf::image::Data], - ) -> Vec { + ) -> (Vec, Vec) { let pbr = material.pbr_metallic_roughness(); let diffuse_texture = if let Some(texture) = pbr.base_color_texture() { @@ -162,7 +167,10 @@ impl GLTFLoader { let mut uniform_buffers = Self::create_uniform_buffers(instance, &binding); - Self::write_sets(instance, diffuse_texture, &uniform_buffers) + ( + Self::write_sets(instance, diffuse_texture, &uniform_buffers), + uniform_buffers, + ) } fn create_uniform_buffers(instance: &VulkanInstance, material: &Material) -> Vec { @@ -207,22 +215,22 @@ impl GLTFLoader { .range(size_of::() as vk::DeviceSize) .build(); - let light_buffer_info = vk::DescriptorBufferInfo::builder() - .buffer(uniforms_buffers[i].buffer) - .offset(0) - .range(size_of::() as vk::DeviceSize) - .build(); + // let light_buffer_info = vk::DescriptorBufferInfo::builder() + // .buffer(uniforms_buffers[i].buffer) + // .offset(0) + // .range(size_of::() as vk::DeviceSize) + // .build(); let desc_sets = [ // Vertex - vk::WriteDescriptorSet { - dst_set: descriptor_sets[0], - dst_binding: 0, - descriptor_count: 1, - descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, - p_buffer_info: &buffer_info, - ..Default::default() - }, + // vk::WriteDescriptorSet { + // dst_set: descriptor_sets[0], + // dst_binding: 0, + // descriptor_count: 1, + // descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + // p_buffer_info: &buffer_info, + // ..Default::default() + // }, // Fragment vk::WriteDescriptorSet { dst_set: descriptor_sets[0], @@ -239,20 +247,18 @@ impl GLTFLoader { p_buffer_info: &material_buffer_info, ..Default::default() }, - vk::WriteDescriptorSet { - dst_set: descriptor_sets[0], - dst_binding: 2, - descriptor_count: 1, - descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, - p_buffer_info: &light_buffer_info, - ..Default::default() - }, + // vk::WriteDescriptorSet { + // dst_set: descriptor_sets[0], + // dst_binding: 2, + // descriptor_count: 1, + // descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + // p_buffer_info: &light_buffer_info, + // ..Default::default() + // }, ]; unsafe { - instance - .device - .update_descriptor_sets(&fragment_desc_sets, &[]); + instance.device.update_descriptor_sets(&desc_sets, &[]); } } descriptor_sets @@ -314,12 +320,9 @@ impl GLTFLoader { } fn load_primitive( - instance: &VulkanInstance, - bind_group: Vec, - name: Option<&str>, buffer_data: &[gltf::buffer::Data], primitive: gltf::Primitive, - ) -> Mesh3D { + ) -> (Vec, Vec) { let reader = primitive.reader(|buffer| Some(&buffer_data[buffer.index()])); let mut vertices: Vec = reader @@ -345,14 +348,6 @@ impl GLTFLoader { } let indices: Vec<_> = reader.read_indices().unwrap().into_u32().collect(); - - Mesh3D::new( - &instance.device, - &instance.memory_allocator, - &vertices, - &indices, - Some(bind_group), - name, - ) + (vertices, indices) } } diff --git a/crates/vent-assets/src/model/mod.rs b/crates/vent-assets/src/model/mod.rs index 74c2df5..510c90d 100644 --- a/crates/vent-assets/src/model/mod.rs +++ b/crates/vent-assets/src/model/mod.rs @@ -29,17 +29,6 @@ pub struct Material { pub base_color: [f32; 4], } -#[repr(C)] -#[derive(Copy, Clone)] -pub struct Light { - position: [f32; 3], - // Due to uniforms requiring 16 byte (4 float) spacing, we need to use a padding field here - _padding: u32, - color: [f32; 3], - // Due to uniforms requiring 16 byte (4 float) spacing, we need to use a padding field here - _padding2: u32, -} - impl Model3D { #[inline] pub async fn load>(instance: &VulkanInstance, path: P) -> Self { @@ -104,6 +93,7 @@ impl Mesh3D { vertices: &[Vertex3D], indices: &[u32], descriptor_sets: Option>, + buffers: Option>, _name: Option<&str>, ) -> Self { let vertex_buf = unsafe { @@ -131,6 +121,7 @@ impl Mesh3D { index_buf, index_count: indices.len() as u32, descriptor_sets, + buffers, } } diff --git a/crates/vent-assets/src/model/obj.rs b/crates/vent-assets/src/model/obj.rs index 15267e8..e03f1e8 100644 --- a/crates/vent-assets/src/model/obj.rs +++ b/crates/vent-assets/src/model/obj.rs @@ -28,15 +28,31 @@ impl OBJLoader { } }; - let meshes = models - .into_iter() - .map(|model| Self::load_mesh(instance, &model.name, &model.mesh)) - .collect::>(); + let mut meshes = vec![]; + for model in models.into_iter() { + let mesh = Self::load_mesh(&model.mesh); - let _descriptor_sets = materials - .into_iter() - .map(|material| Self::load_material(instance, path.parent().unwrap(), &material)) - .collect::>(); + let matieral = Self::load_material( + instance, + path.parent().unwrap(), + &materials[model.mesh.material_id.unwrap()], + ); + + meshes.push(Mesh3D::new( + &instance.device, + &instance.memory_allocator, + &mesh.0, + &mesh.1, + None, // TODO + Some(matieral.1), + Some(&model.name), + )); + } + + // let _descriptor_sets = materials + // .into_iter() + // .map(|material| Self::load_material(instance, path.parent().unwrap(), &material)) + // .collect::>(); Ok(Model3D { meshes }) } @@ -45,7 +61,7 @@ impl OBJLoader { instance: &VulkanInstance, model_dir: &Path, material: &tobj::Material, - ) -> Vec { + ) -> (Vec, Vec) { let diffuse_texture = if let Some(texture) = &material.diffuse_texture { VulkanImage::from_image( &instance.device, @@ -74,7 +90,10 @@ impl OBJLoader { let mut uniform_buffers = vec![]; Self::create_uniform_buffers(instance, &binding, &mut uniform_buffers); - Self::write_sets(instance, diffuse_texture, &uniform_buffers) + ( + Self::write_sets(instance, diffuse_texture, &uniform_buffers), + uniform_buffers, + ) } fn create_uniform_buffers( @@ -143,12 +162,7 @@ impl OBJLoader { descriptor_sets } - fn load_mesh( - instance: &VulkanInstance, - // bind_group: Vec, TODO - name: &str, - mesh: &tobj::Mesh, - ) -> Mesh3D { + fn load_mesh(mesh: &tobj::Mesh) -> (Vec, &[u32]) { let vertices = (0..mesh.positions.len() / 3) .map(|i| Vertex3D { position: [ @@ -164,14 +178,6 @@ impl OBJLoader { ], }) .collect::>(); - - Mesh3D::new( - &instance.device, - &instance.memory_allocator, - &vertices, - &mesh.indices, - None, // TODO - Some(name), - ) + (vertices, &mesh.indices) } } diff --git a/crates/vent-common/Cargo.toml b/crates/vent-common/Cargo.toml index 3e0484c..57ef220 100644 --- a/crates/vent-common/Cargo.toml +++ b/crates/vent-common/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -winit = "0.29.3" +winit = "0.29.4" sysinfo = "0.29" chrono = "0.4" diff --git a/crates/vent-ecs/Cargo.toml b/crates/vent-ecs/Cargo.toml index e42786f..3f62996 100644 --- a/crates/vent-ecs/Cargo.toml +++ b/crates/vent-ecs/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -winit = { version = "0.29.3", default-features = false } \ No newline at end of file +winit = { version = "0.29.4", default-features = false } \ No newline at end of file diff --git a/crates/vent-editor/Cargo.toml b/crates/vent-editor/Cargo.toml index edd5329..4f2c6d2 100644 --- a/crates/vent-editor/Cargo.toml +++ b/crates/vent-editor/Cargo.toml @@ -17,7 +17,7 @@ ash = { version= "0.37.3", default-features = false, features = ["linked", "debu egui = "0.23.0" egui_dock = "0.8.2" -winit = "0.29.3" +winit = "0.29.4" pollster = "0.3.0" log = "0.4" @@ -25,4 +25,4 @@ log = "0.4" # rfd = { version="0.12.1", default-features = false, features = ["xdg-portal"]} [target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies] -simple_logger = "4.2.0" +simple_logger = "4.3.0" diff --git a/crates/vent-rendering/Cargo.toml b/crates/vent-rendering/Cargo.toml index 960c37d..497b8fb 100644 --- a/crates/vent-rendering/Cargo.toml +++ b/crates/vent-rendering/Cargo.toml @@ -10,6 +10,6 @@ ash = { version= "0.37.3", default-features = false, features = ["linked", "debu image = "0.24.7" -winit = "0.29.3" +winit = "0.29.4" raw-window-handle = "0.6" log = "0.4" diff --git a/crates/vent-rendering/src/instance.rs b/crates/vent-rendering/src/instance.rs index c28fb38..b663b17 100644 --- a/crates/vent-rendering/src/instance.rs +++ b/crates/vent-rendering/src/instance.rs @@ -2,6 +2,7 @@ use ash::extensions::khr::{Surface, Swapchain}; use ash::vk::{Extent2D, SwapchainKHR}; use ash::{extensions::ext::DebugUtils, vk, Entry}; use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; +use std::ffi::CString; use std::{default::Default, ffi::CStr}; #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -130,6 +131,9 @@ impl VulkanInstance { let (pdevice, graphics_queue_family_index, present_queue_family_index) = Self::create_physical_device(&instance, &surface_loader, surface); + let info = unsafe { instance.get_physical_device_properties(pdevice) }; + log::info!("Selected graphics device (`{}`).", unsafe { CStr::from_ptr(info.device_name.as_ptr()).to_string_lossy() } ); + let surface_format = unsafe { surface_loader.get_physical_device_surface_formats(pdevice, surface) } .unwrap()[0]; @@ -152,18 +156,16 @@ impl VulkanInstance { let (swapchain_image_views, swapchain_images) = Self::create_image_views(&device, &swapchain_loader, swapchain, surface_format); - let render_pass = Self::create_render_pass(&device, surface_format); + let depth_format = Self::get_depth_format(&instance, pdevice); + + let render_pass = Self::create_render_pass(&device, surface_format, depth_format); let memory_allocator = MemoryAllocator::new(unsafe { instance.get_physical_device_memory_properties(pdevice) }); - let depth_image = VulkanImage::new_depth( - &device, - &memory_allocator, - Self::get_depth_format(&instance, pdevice), - surface_resolution, - ); + let depth_image = + VulkanImage::new_depth(&device, &memory_allocator, depth_format, surface_resolution); let frame_buffers = Self::create_frame_buffers( &swapchain_image_views, render_pass, @@ -238,10 +240,10 @@ impl VulkanInstance { vk::Fence::null(), ) { Ok((index, _)) => { - let image_in_flight = self.images_in_flight[index as usize]; - self.device - .wait_for_fences(&[image_in_flight], true, u64::max_value()) - .unwrap(); + // let image_in_flight = self.images_in_flight[index as usize]; + // self.device + // .wait_for_fences(&[image_in_flight], true, u64::max_value()) + // .unwrap(); Some(index) } Err(_) => None, @@ -263,6 +265,7 @@ impl VulkanInstance { let signal_semaphores = vk::SemaphoreSubmitInfo::builder() .semaphore(self.render_finished_semaphores[self.frame]) + .stage_mask(vk::PipelineStageFlags2::ALL_GRAPHICS) .build(); let submit_info = vk::SubmitInfo2::builder() @@ -686,6 +689,7 @@ impl VulkanInstance { fn create_render_pass( device: &ash::Device, surface_format: vk::SurfaceFormatKHR, + depth_format: vk::Format, ) -> vk::RenderPass { let renderpass_attachments = [ vk::AttachmentDescription { @@ -697,10 +701,9 @@ impl VulkanInstance { ..Default::default() }, vk::AttachmentDescription { - format: vk::Format::D16_UNORM, + format: depth_format, samples: vk::SampleCountFlags::TYPE_1, load_op: vk::AttachmentLoadOp::CLEAR, - initial_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, final_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, ..Default::default() }, @@ -742,6 +745,7 @@ impl Drop for VulkanInstance { fn drop(&mut self) { unsafe { self.device.device_wait_idle().unwrap(); + self.device .destroy_pipeline_layout(self.pipeline_layout, None); self.in_flight_fences @@ -765,6 +769,11 @@ impl Drop for VulkanInstance { .for_each(|f| self.device.destroy_framebuffer(*f, None)); self.depth_image.destroy(&self.device); + self.device + .destroy_descriptor_set_layout(self.descriptor_set_layout, None); + self.device + .destroy_descriptor_pool(self.descriptor_pool, None); + self.device .free_command_buffers(self.command_pool, &self.command_buffers); self.device.destroy_command_pool(self.command_pool, None); diff --git a/crates/vent-rendering/src/surface.rs b/crates/vent-rendering/src/surface.rs index 2522694..5f8a42f 100644 --- a/crates/vent-rendering/src/surface.rs +++ b/crates/vent-rendering/src/surface.rs @@ -17,14 +17,15 @@ pub unsafe fn create_surface( allocation_callbacks: Option<&vk::AllocationCallbacks>, ) -> VkResult { match (display_handle.as_raw(), window_handle.as_raw()) { - // (RawDisplayHandle::Windows(_), RawWindowHandle::Win32(window)) => { - // let hinstance = window.hinstance.expect("No Windows Instance"); - // let surface_desc = vk::Win32SurfaceCreateInfoKHR::builder() - // .hinstance(hinstance.get()) - // .hwnd(window.hwnd.get()); - // let surface_fn = khr::Win32Surface::new(entry, instance); - // surface_fn.create_win32_surface(&surface_desc, allocation_callbacks) - // } + (RawDisplayHandle::Windows(_), RawWindowHandle::Win32(window)) => { + let hinstance = window.hinstance.expect("No Win32 Instance"); + let surface_desc = vk::Win32SurfaceCreateInfoKHR::builder() + .hinstance(hinstance.get() as _) + .hwnd(window.hwnd.get() as _); + let surface_fn = khr::Win32Surface::new(entry, instance); + surface_fn.create_win32_surface(&surface_desc, allocation_callbacks) + } + (RawDisplayHandle::Wayland(display), RawWindowHandle::Wayland(window)) => { let surface_desc = vk::WaylandSurfaceCreateInfoKHR::builder() .display(display.display.as_ptr()) @@ -34,7 +35,7 @@ pub unsafe fn create_surface( } (RawDisplayHandle::Xlib(display), RawWindowHandle::Xlib(window)) => { - let display = display.display.expect("No XOrg Display pointer"); + let display = display.display.expect("No XOrg Display"); let surface_desc = vk::XlibSurfaceCreateInfoKHR::builder() .dpy(display.as_ptr().cast()) .window(window.window); @@ -43,7 +44,7 @@ pub unsafe fn create_surface( } (RawDisplayHandle::Xcb(display), RawWindowHandle::Xcb(window)) => { - let connection = display.connection.expect("No X-Server Connection Pointer"); + let connection = display.connection.expect("No X-Server Connection"); let surface_desc = vk::XcbSurfaceCreateInfoKHR::builder() .connection(connection.as_ptr()) .window(window.window.get()); diff --git a/crates/vent-runtime/Cargo.toml b/crates/vent-runtime/Cargo.toml index da55f84..908e55d 100644 --- a/crates/vent-runtime/Cargo.toml +++ b/crates/vent-runtime/Cargo.toml @@ -25,7 +25,7 @@ egui = "0.23.0" egui-winit = "0.23.0" [target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies] -simple_logger = "4.2.0" +simple_logger = "4.3.0" [build-dependencies] diff --git a/crates/vent-runtime/src/render/d3/light_renderer.rs b/crates/vent-runtime/src/render/d3/light_renderer.rs index 6395b15..c162e16 100644 --- a/crates/vent-runtime/src/render/d3/light_renderer.rs +++ b/crates/vent-runtime/src/render/d3/light_renderer.rs @@ -1,5 +1,16 @@ use vent_assets::Mesh3D; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct LightUBO { + position: [f32; 3], + // Due to uniforms requiring 16 byte (4 float) spacing, we need to use a padding field here + _padding: u32, + color: [f32; 3], + // Due to uniforms requiring 16 byte (4 float) spacing, we need to use a padding field here + _padding2: u32, +} + #[allow(dead_code)] pub struct LightRenderer { light_uniform: LightUBO, diff --git a/crates/vent-runtime/src/render/d3/mod.rs b/crates/vent-runtime/src/render/d3/mod.rs index f36e0b3..edbd310 100644 --- a/crates/vent-runtime/src/render/d3/mod.rs +++ b/crates/vent-runtime/src/render/d3/mod.rs @@ -3,7 +3,9 @@ use glam::Mat4; use vent_assets::Mesh3D; use vent_ecs::world::World; -use vent_rendering::{instance::VulkanInstance, Vertex, Vertex3D}; +use vent_rendering::{ + buffer::VulkanBuffer, image::VulkanImage, instance::VulkanInstance, Vertex, Vertex3D, +}; use winit::dpi::PhysicalSize; use super::{ @@ -81,10 +83,10 @@ impl Renderer for Renderer3D { "/res/models/test/Sponza-GLTF/Sponza.gltf" ); - pollster::block_on(async { - let mesh = Entity3D::new(vent_assets::Model3D::load(instance, model).await); - mesh_renderer.insert(world.create_entity(), mesh); - }); + // pollster::block_on(async { + // let mesh = Entity3D::new(vent_assets::Model3D::load(instance, model).await); + // mesh_renderer.insert(world.create_entity(), mesh); + // }); // Record Command Buffers let render_area = vk::Rect2D::builder() @@ -94,7 +96,7 @@ impl Renderer for Renderer3D { let color_clear_value = vk::ClearValue { color: vk::ClearColorValue { - float32: [0.0, 0.0, 0.0, 1.0], + float32: [0.5, 0.5, 0.5, 1.0], }, }; @@ -235,81 +237,81 @@ impl Renderer for Renderer3D { } } -fn write_sets( - instance: &VulkanInstance, - diffuse_texture: VulkanImage, - uniforms_buffers: &Vec, -) -> Vec { - let descriptor_sets = VulkanInstance::allocate_descriptor_sets( - &instance.device, - instance.descriptor_pool, - instance.descriptor_set_layout, - uniforms_buffers.len(), - ); - - for (i, &_descritptor_set) in descriptor_sets.iter().enumerate() { - let image_info = vk::DescriptorImageInfo::builder() - .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) - .image_view(diffuse_texture.image_view) - .sampler(diffuse_texture.sampler) - .build(); - - let material_buffer_info = vk::DescriptorBufferInfo::builder() - .buffer(uniforms_buffers[i].buffer) - .offset(0) - .range(size_of::() as vk::DeviceSize) - .build(); - - let light_buffer_info = vk::DescriptorBufferInfo::builder() - .buffer(uniforms_buffers[i].buffer) - .offset(0) - .range(size_of::() as vk::DeviceSize) - .build(); - - let desc_sets = [ - // Vertex - vk::WriteDescriptorSet { - dst_set: descriptor_sets[0], - dst_binding: 0, - descriptor_count: 1, - descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, - p_buffer_info: &buffer_info, - ..Default::default() - }, - // Fragment - vk::WriteDescriptorSet { - dst_set: descriptor_sets[0], - descriptor_count: 1, - descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, - p_image_info: &image_info, - ..Default::default() - }, - vk::WriteDescriptorSet { - dst_set: descriptor_sets[0], - dst_binding: 1, - descriptor_count: 1, - descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, - p_buffer_info: &material_buffer_info, - ..Default::default() - }, - vk::WriteDescriptorSet { - dst_set: descriptor_sets[0], - dst_binding: 2, - descriptor_count: 1, - descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, - p_buffer_info: &light_buffer_info, - ..Default::default() - }, - ]; - - unsafe { - instance - .device - .update_descriptor_sets(&fragment_desc_sets, &[]); - } - } - descriptor_sets -} +// fn write_sets( +// instance: &VulkanInstance, +// diffuse_texture: VulkanImage, +// uniforms_buffers: &Vec, +// ) -> Vec { +// let descriptor_sets = VulkanInstance::allocate_descriptor_sets( +// &instance.device, +// instance.descriptor_pool, +// instance.descriptor_set_layout, +// uniforms_buffers.len(), +// ); + +// for (i, &_descritptor_set) in descriptor_sets.iter().enumerate() { +// let image_info = vk::DescriptorImageInfo::builder() +// .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) +// .image_view(diffuse_texture.image_view) +// .sampler(diffuse_texture.sampler) +// .build(); + +// let material_buffer_info = vk::DescriptorBufferInfo::builder() +// .buffer(uniforms_buffers[i].buffer) +// .offset(0) +// .range(size_of::() as vk::DeviceSize) +// .build(); + +// let light_buffer_info = vk::DescriptorBufferInfo::builder() +// .buffer(uniforms_buffers[i].buffer) +// .offset(0) +// .range(size_of::() as vk::DeviceSize) +// .build(); + +// let desc_sets = [ +// // Vertex +// vk::WriteDescriptorSet { +// dst_set: descriptor_sets[0], +// dst_binding: 0, +// descriptor_count: 1, +// descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, +// p_buffer_info: &buffer_info, +// ..Default::default() +// }, +// // Fragment +// vk::WriteDescriptorSet { +// dst_set: descriptor_sets[0], +// descriptor_count: 1, +// descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, +// p_image_info: &image_info, +// ..Default::default() +// }, +// vk::WriteDescriptorSet { +// dst_set: descriptor_sets[0], +// dst_binding: 1, +// descriptor_count: 1, +// descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, +// p_buffer_info: &material_buffer_info, +// ..Default::default() +// }, +// vk::WriteDescriptorSet { +// dst_set: descriptor_sets[0], +// dst_binding: 2, +// descriptor_count: 1, +// descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, +// p_buffer_info: &light_buffer_info, +// ..Default::default() +// }, +// ]; + +// unsafe { +// instance +// .device +// .update_descriptor_sets(&fragment_desc_sets, &[]); +// } +// } +// descriptor_sets +// } fn create_tmp_cube(instance: &VulkanInstance) -> vent_assets::Mesh3D { let indices = [ @@ -372,5 +374,6 @@ fn create_tmp_cube(instance: &VulkanInstance) -> vent_assets::Mesh3D { &indices, None, None, + None, ) } From 7f2b7e247dad3137f726ee9dd2119889d09e8ce8 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev <71594357+Snowiiii@users.noreply.github.com> Date: Sun, 24 Dec 2023 17:05:52 +0100 Subject: [PATCH 07/14] Implemented Model Loading This was very hard :c --- Cargo.lock | 343 +++++++++--------- crates/vent-assets/Cargo.toml | 2 +- crates/vent-assets/src/lib.rs | 14 +- crates/vent-assets/src/model/gltf.rs | 211 ++++------- crates/vent-assets/src/model/mod.rs | 35 +- crates/vent-assets/src/model/obj.rs | 86 +---- crates/vent-assets/src/model/optimizer.rs | 0 crates/vent-common/Cargo.toml | 4 +- crates/vent-common/src/util/crash/mod.rs | 16 +- crates/vent-editor/Cargo.toml | 2 +- crates/vent-rendering/Cargo.toml | 2 +- crates/vent-rendering/src/buffer.rs | 21 +- crates/vent-rendering/src/debug.rs | 3 +- crates/vent-rendering/src/image.rs | 2 - crates/vent-rendering/src/instance.rs | 42 +-- crates/vent-rendering/src/lib.rs | 13 +- crates/vent-runtime/Cargo.toml | 4 +- crates/vent-runtime/src/render/camera/mod.rs | 14 +- .../src/render/d3/light_renderer.rs | 41 +-- crates/vent-runtime/src/render/d3/mod.rs | 171 ++++++++- crates/vent-runtime/src/render/mod.rs | 18 +- 21 files changed, 529 insertions(+), 515 deletions(-) create mode 100644 crates/vent-assets/src/model/optimizer.rs diff --git a/Cargo.lock b/Cargo.lock index 593e9ac..05d27f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,9 +57,9 @@ dependencies = [ [[package]] name = "android-activity" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052ad56e336bcc615a214bffbeca6c181ee9550acec193f0327e0b103b033a4d" +checksum = "39b801912a977c3fd52d80511fe1c0c8480c6f957f21ae2ce1b92ffe970cf4b9" dependencies = [ "android-properties", "bitflags 2.4.1", @@ -111,7 +111,7 @@ dependencies = [ "parking_lot", "thiserror", "winapi", - "x11rb", + "x11rb 0.12.0", ] [[package]] @@ -128,9 +128,9 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "as-raw-xcb-connection" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d5f312b0a56c5cdf967c0aeb67f6289603354951683bc97ddc595ab974ba9aa" +checksum = "175571dd1d178ced59193a6fc02dde1b972eb0bc56c892cde9beeceac5bf0f6b" [[package]] name = "ash" @@ -195,7 +195,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dd7cf50912cddc06dc5ea7c08c5e81c1b2c842a70d19def1848d54c586fed92" dependencies = [ - "objc-sys 0.3.1", + "objc-sys 0.3.2", ] [[package]] @@ -343,11 +343,10 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "colored" -version = "2.0.4" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2674ec482fbc38012cf31e6c42ba0177b431a0cb6f15fe40efa5aab1bda516f6" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" dependencies = [ - "is-terminal", "lazy_static", "windows-sys 0.48.0", ] @@ -364,9 +363,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" +checksum = "d16048cd947b08fa32c24458a22f5dc5e835264f689f4f5653210c69fd107363" dependencies = [ "crossbeam-utils", ] @@ -415,9 +414,9 @@ dependencies = [ [[package]] name = "core-graphics-types" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33" +checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" dependencies = [ "bitflags 1.3.2", "core-foundation", @@ -435,9 +434,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +checksum = "fca89a0e215bab21874660c67903c5f143333cab1da83d041c7ded6053774751" dependencies = [ "cfg-if", "crossbeam-epoch", @@ -446,22 +445,20 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.15" +version = "0.9.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +checksum = "0e3681d554572a651dda4186cd47240627c3d0114d45a95f6ad27f2f22e7548d" dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", - "memoffset 0.9.0", - "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c" dependencies = [ "cfg-if", ] @@ -480,9 +477,9 @@ checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" [[package]] name = "deranged" -version = "0.3.9" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc" dependencies = [ "powerfmt", ] @@ -499,7 +496,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" dependencies = [ - "libloading 0.8.1", + "libloading", ] [[package]] @@ -687,7 +684,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -727,6 +724,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "gethostname" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0176e0459c2e4a1fe232f984bca6890e681076abb9934f6cea7c326f3fc47818" +dependencies = [ + "libc", + "windows-targets 0.48.5", +] + [[package]] name = "getrandom" version = "0.2.11" @@ -750,41 +757,42 @@ dependencies = [ [[package]] name = "glam" -version = "0.24.2" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5418c17512bdf42730f9032c74e1ae39afc408745ebb2acf72fbc4691c17945" +checksum = "151665d9be52f9bb40fc7966565d39666f2d1e69233571b71b87791c7e0528b3" [[package]] name = "gltf" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad2dcfb6dd7a66f9eb3d181a29dcfb22d146b0bcdc2e1ed1713cbf03939a88ea" +checksum = "3b78f069cf941075835822953c345b9e1edd67ae347b81ace3aea9de38c2ef33" dependencies = [ "base64", "byteorder", "gltf-json", "image", "lazy_static", + "serde_json", "urlencoding", ] [[package]] name = "gltf-derive" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2cbcea5dd47e7ad4e9ee6f040384fcd7204bbf671aa4f9e7ca7dfc9bfa1de20" +checksum = "438ffe1a5540d75403feaf23636b164e816e93f6f03131674722b3886ce32a57" dependencies = [ "inflections", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] name = "gltf-json" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5b810806b78dde4b71a95cc0e6fdcab34c4c617da3574df166f9987be97d03" +checksum = "655951ba557f2bc69ea4b0799446bae281fa78efae6319968bdd2c3e9a06d8e1" dependencies = [ "gltf-derive", "serde", @@ -813,19 +821,13 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -[[package]] -name = "hermit-abi" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" - [[package]] name = "home" -version = "0.5.5" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -919,22 +921,11 @@ dependencies = [ "web-sys", ] -[[package]] -name = "is-terminal" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" -dependencies = [ - "hermit-abi", - "rustix", - "windows-sys 0.48.0", -] - [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "jni" @@ -999,19 +990,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.150" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" - -[[package]] -name = "libloading" -version = "0.7.4" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" -dependencies = [ - "cfg-if", - "winapi", -] +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "libloading" @@ -1082,9 +1063,9 @@ dependencies = [ [[package]] name = "memmap2" -version = "0.9.0" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deaba38d7abf1d4cca21cc89e932e542ba2b9258664d2a9ef0e61512039c9375" +checksum = "45fd3a57831bf88bc63f8cebc0cf956116276e97fef3966103e96416209f7c92" dependencies = [ "libc", ] @@ -1107,21 +1088,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "memoffset" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" -dependencies = [ - "autocfg", -] - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.7.1" @@ -1134,9 +1100,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", "log", @@ -1240,16 +1206,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "ntapi" version = "0.4.1" @@ -1337,7 +1293,7 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -1346,10 +1302,10 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c11e44798ad209ccdd91fc192f0526a369a01234f7373e1b141c96d7cee4f0e" dependencies = [ - "proc-macro-crate 2.0.0", + "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -1389,9 +1345,9 @@ checksum = "df3b9834c1e95694a05a828b59f55fa2afec6288359cda67146126b3f90a55d7" [[package]] name = "objc-sys" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e1d07c6eab1ce8b6382b8e3c7246fe117ff3f8b34be065f5ebace6749fe845" +checksum = "c7c71324e4180d0899963fc83d9d241ac39e699609fc1025a850aadac8257459" [[package]] name = "objc2" @@ -1410,7 +1366,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "559c5a40fdd30eb5e344fbceacf7595a81e242529fb4e21cf5f43fb4f11ff98d" dependencies = [ - "objc-sys 0.3.1", + "objc-sys 0.3.2", "objc2-encode 3.0.0", ] @@ -1440,9 +1396,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "orbclient" @@ -1505,9 +1461,9 @@ checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pkg-config" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" [[package]] name = "png" @@ -1560,11 +1516,12 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" +checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a" dependencies = [ - "toml_edit 0.20.7", + "toml_datetime", + "toml_edit 0.20.2", ] [[package]] @@ -1593,9 +1550,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "75cb1540fadbd5b8fbccc4dddad2734eba435053f725621c070711a14bb5f4b8" dependencies = [ "unicode-ident", ] @@ -1687,22 +1644,22 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.25" +version = "0.38.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" +checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" dependencies = [ "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "same-file" @@ -1740,15 +1697,15 @@ dependencies = [ [[package]] name = "sctk-adwaita" -version = "0.7.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1729a30a469de249c6effc17ec8d039b0aa29b3af79b819b7f51cb6ab8046a90" +checksum = "82b2eaf3a5b264a521b988b2e73042e742df700c4f962cde845d1541adb46550" dependencies = [ "ab_glyph", "log", - "memmap2 0.9.0", + "memmap2 0.9.3", "smithay-client-toolkit 0.18.0", - "tiny-skia 0.11.2", + "tiny-skia 0.11.3", ] [[package]] @@ -1768,7 +1725,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -1811,9 +1768,9 @@ dependencies = [ [[package]] name = "slotmap" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342" +checksum = "dbff4acf519f630b3a3ddcfaea6c06b42174d9a44bc70c620e9ed1649d58b82a" dependencies = [ "version_check", ] @@ -1855,7 +1812,7 @@ dependencies = [ "cursor-icon", "libc", "log", - "memmap2 0.9.0", + "memmap2 0.9.3", "rustix", "thiserror", "wayland-backend", @@ -1921,9 +1878,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" dependencies = [ "proc-macro2", "quote", @@ -1932,9 +1889,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.29.11" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd727fc423c2060f6c92d9534cef765c65a6ed3f428a03d7def74a8c4348e666" +checksum = "c68492e7268037de59ae153d7efb79546cf94a18a9548235420d3d8d2436b4b1" dependencies = [ "cfg-if", "core-foundation-sys", @@ -1942,27 +1899,27 @@ dependencies = [ "ntapi", "once_cell", "rayon", - "winapi", + "windows", ] [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] @@ -1978,9 +1935,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" dependencies = [ "deranged", "itoa", @@ -2000,9 +1957,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" dependencies = [ "time-core", ] @@ -2023,16 +1980,16 @@ dependencies = [ [[package]] name = "tiny-skia" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b72a92a05db376db09fe6d50b7948d106011761c05a6a45e23e17ee9b556222" +checksum = "b6a067b809476893fce6a254cf285850ff69c847e6cfbade6a20b655b6c7e80d" dependencies = [ "arrayref", "arrayvec", "bytemuck", "cfg-if", "log", - "tiny-skia-path 0.11.2", + "tiny-skia-path 0.11.3", ] [[package]] @@ -2048,9 +2005,9 @@ dependencies = [ [[package]] name = "tiny-skia-path" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac3865b9708fc7e1961a65c3a4fa55e984272f33092d3c859929f887fceb647" +checksum = "5de35e8a90052baaaf61f171680ac2f8e925a1e43ea9d2e3a00514772250e541" dependencies = [ "arrayref", "bytemuck", @@ -2083,9 +2040,9 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" [[package]] name = "toml_edit" @@ -2100,9 +2057,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.20.7" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ "indexmap", "toml_datetime", @@ -2133,9 +2090,9 @@ checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" [[package]] name = "unicode-ident" @@ -2204,14 +2161,14 @@ dependencies = [ "serde", "serde_json", "sysinfo", - "winit 0.29.4", + "winit 0.29.5", ] [[package]] name = "vent-ecs" version = "0.1.0" dependencies = [ - "winit 0.29.4", + "winit 0.29.5", ] [[package]] @@ -2227,7 +2184,7 @@ dependencies = [ "vent-common", "vent-rendering", "vent-runtime", - "winit 0.29.4", + "winit 0.29.5", ] [[package]] @@ -2238,7 +2195,7 @@ dependencies = [ "image", "log", "raw-window-handle 0.6.0", - "winit 0.29.4", + "winit 0.29.5", ] [[package]] @@ -2258,7 +2215,7 @@ dependencies = [ "vent-common", "vent-ecs", "vent-rendering", - "winit 0.29.4", + "winit 0.29.5", ] [[package]] @@ -2308,7 +2265,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", "wasm-bindgen-shared", ] @@ -2342,7 +2299,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2618,6 +2575,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.51.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9" +dependencies = [ + "windows-core", + "windows-targets 0.48.5", +] + [[package]] name = "windows-core" version = "0.51.1" @@ -2862,12 +2829,12 @@ dependencies = [ [[package]] name = "winit" -version = "0.29.4" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d25d662bb83b511acd839534bb2d88521b0bbc81440969cb077d23c4db9e62c7" +checksum = "2cc935117ef48caed8822a893efef723e07ad868f668dfc4d244aea8873b07f9" dependencies = [ "ahash", - "android-activity 0.5.0", + "android-activity 0.5.1", "atomic-waker", "bitflags 2.4.1", "bytemuck", @@ -2880,7 +2847,7 @@ dependencies = [ "js-sys", "libc", "log", - "memmap2 0.9.0", + "memmap2 0.9.3", "ndk 0.8.0", "ndk-sys 0.5.0+25.2.9519653", "objc2 0.4.1", @@ -2890,7 +2857,7 @@ dependencies = [ "raw-window-handle 0.6.0", "redox_syscall 0.3.5", "rustix", - "sctk-adwaita 0.7.0", + "sctk-adwaita 0.8.1", "smithay-client-toolkit 0.18.0", "smol_str", "unicode-segmentation", @@ -2904,15 +2871,15 @@ dependencies = [ "web-time", "windows-sys 0.48.0", "x11-dl", - "x11rb", + "x11rb 0.13.0", "xkbcommon-dl", ] [[package]] name = "winnow" -version = "0.5.19" +version = "0.5.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b" +checksum = "9b5c3db89721d50d0e2a673f5043fc4722f76dcc352d7b1ab8b8288bed4ed2c5" dependencies = [ "memchr", ] @@ -2934,15 +2901,26 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1641b26d4dec61337c35a1b1aaf9e3cba8f46f0b43636c609ab0291a648040a" dependencies = [ - "as-raw-xcb-connection", - "gethostname", - "libc", - "libloading 0.7.4", + "gethostname 0.3.0", "nix 0.26.4", - "once_cell", "winapi", "winapi-wsapoll", - "x11rb-protocol", + "x11rb-protocol 0.12.0", +] + +[[package]] +name = "x11rb" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f25ead8c7e4cba123243a6367da5d3990e0d3affa708ea19dce96356bd9f1a" +dependencies = [ + "as-raw-xcb-connection", + "gethostname 0.4.3", + "libc", + "libloading", + "once_cell", + "rustix", + "x11rb-protocol 0.13.0", ] [[package]] @@ -2954,14 +2932,17 @@ dependencies = [ "nix 0.26.4", ] +[[package]] +name = "x11rb-protocol" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e63e71c4b8bd9ffec2c963173a4dc4cbde9ee96961d4fcb4429db9929b606c34" + [[package]] name = "xcursor" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" -dependencies = [ - "nom", -] +checksum = "6a0ccd7b4a5345edfcd0c3535718a4e9ff7798ffc536bb5b5a0e26ff84732911" [[package]] name = "xkbcommon-dl" @@ -2990,22 +2971,22 @@ checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" [[package]] name = "zerocopy" -version = "0.7.27" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43de342578a3a14a9314a2dab1942cbfcbe5686e1f91acdc513058063eafe18" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.27" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1012d89e3acb79fad7a799ce96866cfb8098b74638465ea1b1533d35900ca90" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.42", ] [[package]] diff --git a/crates/vent-assets/Cargo.toml b/crates/vent-assets/Cargo.toml index 5399325..d396dc3 100644 --- a/crates/vent-assets/Cargo.toml +++ b/crates/vent-assets/Cargo.toml @@ -17,5 +17,5 @@ ash = { version= "0.37.3", default-features = false, features = ["linked"] } # model tobj = { version = "4.0.0", features = ["async"] } -gltf = "1.3.0" +gltf = "1.4.0" diff --git a/crates/vent-assets/src/lib.rs b/crates/vent-assets/src/lib.rs index 8b0207e..cc07d9f 100644 --- a/crates/vent-assets/src/lib.rs +++ b/crates/vent-assets/src/lib.rs @@ -1,5 +1,5 @@ use ash::vk; -use vent_rendering::buffer::VulkanBuffer; +use vent_rendering::{buffer::VulkanBuffer, image::VulkanImage}; pub mod model; pub mod pool; @@ -10,7 +10,7 @@ pub trait Asset {} /// A Full Model that can be Loaded from a 3D Model File /// This is done by Parsing all Essensial Informations like Vertices, Indices, Materials & More pub struct Model3D { - meshes: Vec, + pub meshes: Vec, } /// This is a simple mesh that consists of vertices and indices. It is useful when you need to hard-code 3D data into your application. @@ -23,6 +23,12 @@ pub struct Mesh3D { vertex_buf: VulkanBuffer, index_buf: VulkanBuffer, index_count: u32, - descriptor_sets: Option>, - buffers: Option>, + // So every App is Specfic and you will need to create your own DescriptorSet's out of this + pub material: Option, + pub descriptor_set: Option>, +} + +pub struct Material { + pub diffuse_texture: VulkanImage, + pub base_color: [f32; 4], } diff --git a/crates/vent-assets/src/model/gltf.rs b/crates/vent-assets/src/model/gltf.rs index 99e148f..2303569 100644 --- a/crates/vent-assets/src/model/gltf.rs +++ b/crates/vent-assets/src/model/gltf.rs @@ -11,9 +11,9 @@ use vent_rendering::{ buffer::VulkanBuffer, image::VulkanImage, instance::VulkanInstance, Vertex3D, }; -use crate::Model3D; +use crate::{Material, Model3D}; -use super::{Material, Mesh3D, ModelError}; +use super::{Mesh3D, ModelError}; pub(crate) struct GLTFLoader {} @@ -44,56 +44,83 @@ impl GLTFLoader { meshes: &mut Vec, ) { if let Some(mesh) = node.mesh() { - Self::load_mesh_multithreaded(instance, model_dir, mesh, buffer_data, meshes); + Self::load_mesh_singlethreaded(instance, model_dir, mesh, buffer_data, meshes); } node.children() .for_each(|child| Self::load_node(instance, model_dir, child, buffer_data, meshes)) } - fn load_mesh_multithreaded( + // fn load_mesh_multithreaded( + // instance: &VulkanInstance, + // camera_set: vk::WriteDescriptorSet, + // model_dir: &Path, + // mesh: gltf::Mesh, + // buffer_data: &[gltf::buffer::Data], + // meshes: &mut Vec, + // ) { + // let primitive_len = mesh.primitives().size_hint().0; + // let (tx, rx) = sync::mpsc::sync_channel(primitive_len); // Create bounded channels + + // // Spawn threads to load mesh primitive + // thread::scope(|s| { + // let tx = tx.clone(); + // for primitive in mesh.primitives() { + // let tx = tx.clone(); + // let camera_set = camera_set.clone(); + // let mesh = mesh.clone(); + // let instance = instance; + // let model_dir = model_dir; + // let buffer_data = buffer_data; + + // s.spawn(move || { + // let loaded_material = + // Self::load_material(instance, camera_set, model_dir, primitive.material(), buffer_data); + + // let primitive = Self::load_primitive(buffer_data, primitive); + + // let loaded_mesh = Mesh3D::new( + // &instance.device, + // &instance.memory_allocator, + // &primitive.0, + // &primitive.1, + // Some(loaded_material), + // mesh.name(), + // ); + + // tx.send(loaded_mesh).unwrap(); + // }); + // } + // }); + // for _ in 0..primitive_len { + // let mesh = rx.recv().unwrap(); + // meshes.push(mesh); + // } + // } + + #[deprecated] + fn load_mesh_singlethreaded( instance: &VulkanInstance, model_dir: &Path, mesh: gltf::Mesh, buffer_data: &[gltf::buffer::Data], meshes: &mut Vec, ) { - let primitive_len = mesh.primitives().size_hint().0; - let (tx, rx) = sync::mpsc::sync_channel(primitive_len); // Create bounded channels - - // Spawn threads to load mesh primitive - thread::scope(|s| { - let tx = tx.clone(); - for primitive in mesh.primitives() { - let tx = tx.clone(); - let mesh = mesh.clone(); - let instance = instance; - let model_dir = model_dir; - let buffer_data = buffer_data; - - s.spawn(move || { - let loaded_material = - Self::load_material(instance, model_dir, primitive.material(), buffer_data); - - let primitive = Self::load_primitive(buffer_data, primitive); - - let loaded_mesh = Mesh3D::new( - &instance.device, - &instance.memory_allocator, - &primitive.0, - &primitive.1, - Some(loaded_material.0), - Some(loaded_material.1), - mesh.name(), - ); - - tx.send(loaded_mesh).unwrap(); - }); - } - }); - for _ in 0..primitive_len { - let mesh = rx.recv().unwrap(); - meshes.push(mesh); + for primitive in mesh.primitives() { + let loaded_material = + Self::load_material(instance, model_dir, primitive.material(), buffer_data); + + let primitive = Self::load_primitive(buffer_data, primitive); + + let loaded_mesh = Mesh3D::new( + &instance.device, + &instance.memory_allocator, + &primitive.0, + &primitive.1, + Some(loaded_material), + mesh.name(), + ); + meshes.push(loaded_mesh); } } @@ -103,7 +130,7 @@ impl GLTFLoader { material: gltf::Material<'_>, buffer_data: &[gltf::buffer::Data], // image_data: &[gltf::image::Data], - ) -> (Vec, Vec) { + ) -> Material { let pbr = material.pbr_metallic_roughness(); let diffuse_texture = if let Some(texture) = pbr.base_color_texture() { @@ -151,6 +178,7 @@ impl GLTFLoader { } } } else { + // Default Diffuse color VulkanImage::from_color( &instance.device, [255, 255, 255, 255], @@ -161,107 +189,10 @@ impl GLTFLoader { ) }; - let binding = Material { + Material { + diffuse_texture, base_color: pbr.base_color_factor(), - }; - - let mut uniform_buffers = Self::create_uniform_buffers(instance, &binding); - - ( - Self::write_sets(instance, diffuse_texture, &uniform_buffers), - uniform_buffers, - ) - } - - fn create_uniform_buffers(instance: &VulkanInstance, material: &Material) -> Vec { - let mut uniform_buffers = vec![]; - for _ in 0..instance.swapchain_images.len() { - let buffer = unsafe { - VulkanBuffer::new_init_type( - &instance.device, - &instance.memory_allocator, - size_of::() as vk::DeviceSize, - vk::BufferUsageFlags::UNIFORM_BUFFER, - material, - ) - }; - uniform_buffers.push(buffer) - } - uniform_buffers - } - - fn write_sets( - instance: &VulkanInstance, - diffuse_texture: VulkanImage, - uniforms_buffers: &Vec, - ) -> Vec { - let descriptor_sets = VulkanInstance::allocate_descriptor_sets( - &instance.device, - instance.descriptor_pool, - instance.descriptor_set_layout, - uniforms_buffers.len(), - ); - - for (i, &_descritptor_set) in descriptor_sets.iter().enumerate() { - let image_info = vk::DescriptorImageInfo::builder() - .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) - .image_view(diffuse_texture.image_view) - .sampler(diffuse_texture.sampler) - .build(); - - let material_buffer_info = vk::DescriptorBufferInfo::builder() - .buffer(uniforms_buffers[i].buffer) - .offset(0) - .range(size_of::() as vk::DeviceSize) - .build(); - - // let light_buffer_info = vk::DescriptorBufferInfo::builder() - // .buffer(uniforms_buffers[i].buffer) - // .offset(0) - // .range(size_of::() as vk::DeviceSize) - // .build(); - - let desc_sets = [ - // Vertex - // vk::WriteDescriptorSet { - // dst_set: descriptor_sets[0], - // dst_binding: 0, - // descriptor_count: 1, - // descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, - // p_buffer_info: &buffer_info, - // ..Default::default() - // }, - // Fragment - vk::WriteDescriptorSet { - dst_set: descriptor_sets[0], - descriptor_count: 1, - descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, - p_image_info: &image_info, - ..Default::default() - }, - vk::WriteDescriptorSet { - dst_set: descriptor_sets[0], - dst_binding: 1, - descriptor_count: 1, - descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, - p_buffer_info: &material_buffer_info, - ..Default::default() - }, - // vk::WriteDescriptorSet { - // dst_set: descriptor_sets[0], - // dst_binding: 2, - // descriptor_count: 1, - // descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, - // p_buffer_info: &light_buffer_info, - // ..Default::default() - // }, - ]; - - unsafe { - instance.device.update_descriptor_sets(&desc_sets, &[]); - } } - descriptor_sets } /// Converts an gltf Texture Sampler into Vulkan Sampler Info diff --git a/crates/vent-assets/src/model/mod.rs b/crates/vent-assets/src/model/mod.rs index 510c90d..e847634 100644 --- a/crates/vent-assets/src/model/mod.rs +++ b/crates/vent-assets/src/model/mod.rs @@ -8,7 +8,7 @@ use vent_rendering::instance::VulkanInstance; use vent_rendering::Vertex3D; use vent_sdk::utils::stopwatch::Stopwatch; -use crate::{Mesh3D, Model3D}; +use crate::{Material, Mesh3D, Model3D}; use self::gltf::GLTFLoader; use self::obj::OBJLoader; @@ -23,16 +23,11 @@ pub enum ModelError { LoadingError(String), } -#[repr(C)] -#[derive(Clone, Copy)] -pub struct Material { - pub base_color: [f32; 4], -} - impl Model3D { #[inline] pub async fn load>(instance: &VulkanInstance, path: P) -> Self { let sw = Stopwatch::new_and_start(); + log::info!("Loading new Model..."); let model = load_model_from_path(instance, path.as_ref()) .await .expect("Failed to Load 3D Model"); @@ -92,8 +87,7 @@ impl Mesh3D { allocator: &MemoryAllocator, vertices: &[Vertex3D], indices: &[u32], - descriptor_sets: Option>, - buffers: Option>, + material: Option, _name: Option<&str>, ) -> Self { let vertex_buf = unsafe { @@ -120,11 +114,15 @@ impl Mesh3D { vertex_buf, index_buf, index_count: indices.len() as u32, - descriptor_sets, - buffers, + material, + descriptor_set: None, } } + pub fn set_descriptor_set(&mut self, descriptor_set: Vec) { + self.descriptor_set = Some(descriptor_set); + } + pub fn bind( &self, device: &ash::Device, @@ -137,13 +135,13 @@ impl Mesh3D { device.cmd_bind_vertex_buffers(command_buffer, 0, &[*self.vertex_buf], &[0]); device.cmd_bind_index_buffer(command_buffer, *self.index_buf, 0, vk::IndexType::UINT32); if with_descriptor_set { - if let Some(ds) = &self.descriptor_sets { + if let Some(ds) = &self.descriptor_set { device.cmd_bind_descriptor_sets( command_buffer, vk::PipelineBindPoint::GRAPHICS, pipeline_layout, 0, - &[ds[buffer_index]], + &ds[buffer_index..=buffer_index], &[], ) } @@ -158,12 +156,11 @@ impl Mesh3D { pub fn destroy(&mut self, descriptor_pool: vk::DescriptorPool, device: &ash::Device) { self.vertex_buf.destroy(device); self.index_buf.destroy(device); - if let Some(ds) = &self.descriptor_sets { - unsafe { - device - .free_descriptor_sets(descriptor_pool, &ds) - .expect("Failed to free Descriptor") - }; + if let Some(descriptor_set) = &mut self.descriptor_set { + unsafe { device.free_descriptor_sets(descriptor_pool, descriptor_set) }; + } + if let Some(material) = &mut self.material { + material.diffuse_texture.destroy(device); } } } diff --git a/crates/vent-assets/src/model/obj.rs b/crates/vent-assets/src/model/obj.rs index e03f1e8..2597322 100644 --- a/crates/vent-assets/src/model/obj.rs +++ b/crates/vent-assets/src/model/obj.rs @@ -44,7 +44,6 @@ impl OBJLoader { &mesh.0, &mesh.1, None, // TODO - Some(matieral.1), Some(&model.name), )); } @@ -61,7 +60,7 @@ impl OBJLoader { instance: &VulkanInstance, model_dir: &Path, material: &tobj::Material, - ) -> (Vec, Vec) { + ) -> Material { let diffuse_texture = if let Some(texture) = &material.diffuse_texture { VulkanImage::from_image( &instance.device, @@ -81,85 +80,14 @@ impl OBJLoader { }, ) }; - let diffuse = material.diffuse.unwrap_or([1.0, 1.0, 1.0]); + let base_color = material.diffuse.unwrap_or([1.0, 1.0, 1.0]); + // OBJ does not have an Alpha :c + let base_color = [base_color[0], base_color[1], base_color[2], 1.0]; - let binding = Material { - base_color: [diffuse[0], diffuse[1], diffuse[2], 1.0], - }; - - let mut uniform_buffers = vec![]; - Self::create_uniform_buffers(instance, &binding, &mut uniform_buffers); - - ( - Self::write_sets(instance, diffuse_texture, &uniform_buffers), - uniform_buffers, - ) - } - - fn create_uniform_buffers( - instance: &VulkanInstance, - material: &Material, - uniform_buffers: &mut Vec, - ) { - for _ in 0..instance.swapchain_images.len() { - let buffer = unsafe { - VulkanBuffer::new_init_type( - &instance.device, - &instance.memory_allocator, - size_of::() as vk::DeviceSize, - vk::BufferUsageFlags::UNIFORM_BUFFER, - material, - ) - }; - uniform_buffers.push(buffer) - } - } - - fn write_sets( - instance: &VulkanInstance, - diffuse_texture: VulkanImage, - uniforms_buffers: &Vec, - ) -> Vec { - let descriptor_sets = VulkanInstance::allocate_descriptor_sets( - &instance.device, - instance.descriptor_pool, - instance.descriptor_set_layout, - uniforms_buffers.len(), - ); - - for (i, &_descritptor_set) in descriptor_sets.iter().enumerate() { - let image_info = vk::DescriptorImageInfo::builder() - .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) - .image_view(diffuse_texture.image_view) - .sampler(diffuse_texture.sampler) - .build(); - - let _sampler_write = vk::WriteDescriptorSet::builder() - .dst_set(descriptor_sets[i]) - .dst_binding(0) - .dst_array_element(0) - .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) - .image_info(&[image_info]); - - let buffer_info = vk::DescriptorBufferInfo::builder() - .buffer(uniforms_buffers[i].buffer) - .offset(0) - .range(size_of::() as vk::DeviceSize) - .build(); - - let ubo_write = vk::WriteDescriptorSet::builder() - .dst_set(descriptor_sets[i]) - .dst_binding(1) - .dst_array_element(0) - .descriptor_type(vk::DescriptorType::UNIFORM_BUFFER) - .buffer_info(&[buffer_info]) - .build(); - - unsafe { - instance.device.update_descriptor_sets(&[ubo_write], &[]); - } + Material { + diffuse_texture, + base_color, } - descriptor_sets } fn load_mesh(mesh: &tobj::Mesh) -> (Vec, &[u32]) { diff --git a/crates/vent-assets/src/model/optimizer.rs b/crates/vent-assets/src/model/optimizer.rs new file mode 100644 index 0000000..e69de29 diff --git a/crates/vent-common/Cargo.toml b/crates/vent-common/Cargo.toml index 57ef220..82b060e 100644 --- a/crates/vent-common/Cargo.toml +++ b/crates/vent-common/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -winit = "0.29.4" -sysinfo = "0.29" +winit = "0.29.5" +sysinfo = "0.30" chrono = "0.4" image = "0.24.7" diff --git a/crates/vent-common/src/util/crash/mod.rs b/crates/vent-common/src/util/crash/mod.rs index 5a4d818..de73788 100644 --- a/crates/vent-common/src/util/crash/mod.rs +++ b/crates/vent-common/src/util/crash/mod.rs @@ -2,7 +2,7 @@ use chrono::{DateTime, Local}; use std::fs::File; use std::io::Write; use std::panic::{self, PanicInfo}; -use sysinfo::{System, SystemExt}; +use sysinfo::System; #[inline] pub fn init_panic_hook() { @@ -35,10 +35,18 @@ fn log_crash(pi: &PanicInfo) -> std::io::Result<()> { writeln!( &mut f, "System kernel version: {:?}", - sys.kernel_version() + sysinfo::System::kernel_version() + )?; + writeln!( + &mut f, + "System OS version: {:?}", + sysinfo::System::os_version() + )?; + writeln!( + &mut f, + "System host name: {:?}", + sysinfo::System::host_name() )?; - writeln!(&mut f, "System OS version: {:?}", sys.os_version())?; - writeln!(&mut f, "System host name: {:?}", sys.host_name())?; writeln!( &mut f, diff --git a/crates/vent-editor/Cargo.toml b/crates/vent-editor/Cargo.toml index 4f2c6d2..f413854 100644 --- a/crates/vent-editor/Cargo.toml +++ b/crates/vent-editor/Cargo.toml @@ -17,7 +17,7 @@ ash = { version= "0.37.3", default-features = false, features = ["linked", "debu egui = "0.23.0" egui_dock = "0.8.2" -winit = "0.29.4" +winit = "0.29.5" pollster = "0.3.0" log = "0.4" diff --git a/crates/vent-rendering/Cargo.toml b/crates/vent-rendering/Cargo.toml index 497b8fb..0c8d0d2 100644 --- a/crates/vent-rendering/Cargo.toml +++ b/crates/vent-rendering/Cargo.toml @@ -10,6 +10,6 @@ ash = { version= "0.37.3", default-features = false, features = ["linked", "debu image = "0.24.7" -winit = "0.29.4" +winit = "0.29.5" raw-window-handle = "0.6" log = "0.4" diff --git a/crates/vent-rendering/src/buffer.rs b/crates/vent-rendering/src/buffer.rs index 3720cde..b27c7fe 100644 --- a/crates/vent-rendering/src/buffer.rs +++ b/crates/vent-rendering/src/buffer.rs @@ -1,4 +1,4 @@ -use std::ptr::copy_nonoverlapping; +use std::{mem::align_of, ptr::copy_nonoverlapping}; use ash::vk; @@ -33,6 +33,12 @@ impl VulkanBuffer { vk::MemoryPropertyFlags::HOST_COHERENT | vk::MemoryPropertyFlags::HOST_VISIBLE, ); + unsafe { + device + .bind_buffer_memory(buffer, buffer_memory, 0) + .expect("Failed to bind Buffer Memory"); + } + Self { buffer, buffer_memory, @@ -78,7 +84,8 @@ impl VulkanBuffer { let memory = device .map_memory(self.buffer_memory, 0, size, vk::MemoryMapFlags::empty()) .unwrap(); - copy_nonoverlapping(data.as_ptr(), memory.cast(), data.len()); + let mut align = ash::util::Align::new(memory, align_of::() as _, size); + align.copy_from_slice(&data); device.unmap_memory(self.buffer_memory); } } @@ -93,18 +100,12 @@ impl VulkanBuffer { let memory = device .map_memory(self.buffer_memory, 0, size, vk::MemoryMapFlags::empty()) .unwrap(); - copy_nonoverlapping(data, memory.cast(), 1); + let mut align = ash::util::Align::new(memory, align_of::() as _, size); + align.copy_from_slice(&[data]); device.unmap_memory(self.buffer_memory); } } - pub fn bind(&self, device: &ash::Device) { - unsafe { - device - .bind_buffer_memory(self.buffer, self.buffer_memory, 0) - .expect("Failed to bind Buffer Memory"); - } - } pub fn destroy(&mut self, device: &ash::Device) { unsafe { diff --git a/crates/vent-rendering/src/debug.rs b/crates/vent-rendering/src/debug.rs index de2e328..ce52b07 100644 --- a/crates/vent-rendering/src/debug.rs +++ b/crates/vent-rendering/src/debug.rs @@ -1,5 +1,5 @@ use ash::extensions::ext::DebugUtils; -use ash::{vk, Entry, Instance}; +use ash::{vk, Device, Entry, Instance}; use std::os::raw::c_void; use std::{ ffi::{CStr, CString}, @@ -67,6 +67,7 @@ pub fn check_validation_layer_support(entry: &Entry) { } /// Setup the debug message if validation layers are enabled. +#[must_use] pub fn setup_debug_messenger( entry: &Entry, instance: &Instance, diff --git a/crates/vent-rendering/src/image.rs b/crates/vent-rendering/src/image.rs index d149f28..8e469f5 100644 --- a/crates/vent-rendering/src/image.rs +++ b/crates/vent-rendering/src/image.rs @@ -149,8 +149,6 @@ impl VulkanImage { width: u32, height: u32, ) { - staging_buffer.bind(device); - let command_buffer = begin_single_time_command(device, command_pool); let image_barrier = vk::ImageMemoryBarrier2 { diff --git a/crates/vent-rendering/src/instance.rs b/crates/vent-rendering/src/instance.rs index b663b17..d695e01 100644 --- a/crates/vent-rendering/src/instance.rs +++ b/crates/vent-rendering/src/instance.rs @@ -1,4 +1,5 @@ use ash::extensions::khr::{Surface, Swapchain}; +use ash::prelude::VkResult; use ash::vk::{Extent2D, SwapchainKHR}; use ash::{extensions::ext::DebugUtils, vk, Entry}; use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; @@ -132,7 +133,9 @@ impl VulkanInstance { Self::create_physical_device(&instance, &surface_loader, surface); let info = unsafe { instance.get_physical_device_properties(pdevice) }; - log::info!("Selected graphics device (`{}`).", unsafe { CStr::from_ptr(info.device_name.as_ptr()).to_string_lossy() } ); + log::info!("Selected graphics device (`{}`).", unsafe { + CStr::from_ptr(info.device_name.as_ptr()).to_string_lossy() + }); let surface_format = unsafe { surface_loader.get_physical_device_surface_formats(pdevice, surface) } @@ -223,8 +226,8 @@ impl VulkanInstance { } } - // Returns None if Surface should be resized else returns image index - pub fn next_image(&self) -> Option { + // returns the next image's index and whether the swapchain is suboptimal for the surface. + pub fn next_image(&self) -> VkResult<(u32, bool)> { let in_flight_fence = self.in_flight_fences[self.frame]; unsafe { @@ -233,21 +236,12 @@ impl VulkanInstance { } .unwrap(); unsafe { - match self.swapchain_loader.acquire_next_image( + self.swapchain_loader.acquire_next_image( self.swapchain, u64::MAX, self.image_available_semaphores[self.frame], vk::Fence::null(), - ) { - Ok((index, _)) => { - // let image_in_flight = self.images_in_flight[index as usize]; - // self.device - // .wait_for_fences(&[image_in_flight], true, u64::max_value()) - // .unwrap(); - Some(index) - } - Err(_) => None, - } + ) } } @@ -265,7 +259,7 @@ impl VulkanInstance { let signal_semaphores = vk::SemaphoreSubmitInfo::builder() .semaphore(self.render_finished_semaphores[self.frame]) - .stage_mask(vk::PipelineStageFlags2::ALL_GRAPHICS) + // .stage_mask(vk::PipelineStageFlags2::ALL_GRAPHICS) .build(); let submit_info = vk::SubmitInfo2::builder() @@ -692,7 +686,7 @@ impl VulkanInstance { depth_format: vk::Format, ) -> vk::RenderPass { let renderpass_attachments = [ - vk::AttachmentDescription { + vk::AttachmentDescription2 { format: surface_format.format, samples: vk::SampleCountFlags::TYPE_1, load_op: vk::AttachmentLoadOp::CLEAR, @@ -700,7 +694,7 @@ impl VulkanInstance { final_layout: vk::ImageLayout::PRESENT_SRC_KHR, ..Default::default() }, - vk::AttachmentDescription { + vk::AttachmentDescription2 { format: depth_format, samples: vk::SampleCountFlags::TYPE_1, load_op: vk::AttachmentLoadOp::CLEAR, @@ -708,15 +702,17 @@ impl VulkanInstance { ..Default::default() }, ]; - let color_attachment_refs = [vk::AttachmentReference { + let color_attachment_refs = [vk::AttachmentReference2 { attachment: 0, layout: vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL, + ..Default::default() }]; - let depth_attachment_ref = vk::AttachmentReference { + let depth_attachment_ref = vk::AttachmentReference2 { attachment: 1, layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + ..Default::default() }; - let dependencies = [vk::SubpassDependency { + let dependencies = [vk::SubpassDependency2 { src_subpass: vk::SUBPASS_EXTERNAL, src_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT, dst_access_mask: vk::AccessFlags::COLOR_ATTACHMENT_READ @@ -725,19 +721,19 @@ impl VulkanInstance { ..Default::default() }]; - let subpass = vk::SubpassDescription::builder() + let subpass = vk::SubpassDescription2::builder() .color_attachments(&color_attachment_refs) .depth_stencil_attachment(&depth_attachment_ref) .pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS) .build(); - let create_info = vk::RenderPassCreateInfo::builder() + let create_info = vk::RenderPassCreateInfo2::builder() .attachments(&renderpass_attachments) .subpasses(std::slice::from_ref(&subpass)) .dependencies(&dependencies) .build(); - unsafe { device.create_render_pass(&create_info, None) }.unwrap() + unsafe { device.create_render_pass2(&create_info, None) }.unwrap() } } diff --git a/crates/vent-rendering/src/lib.rs b/crates/vent-rendering/src/lib.rs index 852b7d1..d1ee473 100644 --- a/crates/vent-rendering/src/lib.rs +++ b/crates/vent-rendering/src/lib.rs @@ -27,7 +27,6 @@ pub trait Vertex<'a> { fn input_descriptions() -> [vk::VertexInputAttributeDescription; 3]; } -#[repr(C)] #[derive(Clone, Copy)] pub struct Vertex3D { pub position: [f32; 3], @@ -116,12 +115,18 @@ pub fn end_single_time_command( .build(); unsafe { + let fence = device + .create_fence(&vk::FenceCreateInfo::default(), None) + .unwrap(); + device - .queue_submit2(submit_queue, &[submit_info], vk::Fence::null()) + .queue_submit2(submit_queue, &[submit_info], fence) .expect("Failed to Queue Submit!"); device - .queue_wait_idle(submit_queue) - .expect("Failed to wait Queue idle!"); + .wait_for_fences(&[fence], true, 100000000000) + .expect("Failed to wait for Fence"); + + device.destroy_fence(fence, None); device.free_command_buffers(command_pool, &[command_buffer]); } } diff --git a/crates/vent-runtime/Cargo.toml b/crates/vent-runtime/Cargo.toml index 908e55d..b529c5a 100644 --- a/crates/vent-runtime/Cargo.toml +++ b/crates/vent-runtime/Cargo.toml @@ -13,11 +13,11 @@ vent-ecs = { path = "../vent-ecs"} ash = { version= "0.37.3", default-features = false, features = ["linked", "debug"] } -winit = "0.29.3" +winit = "0.29.5" pollster = "0.3.0" log = "0.4" -glam = "0.24.2" +glam = "0.25" downcast-rs = "1.2.0" # egui diff --git a/crates/vent-runtime/src/render/camera/mod.rs b/crates/vent-runtime/src/render/camera/mod.rs index 4fd52d6..d69a5d8 100644 --- a/crates/vent-runtime/src/render/camera/mod.rs +++ b/crates/vent-runtime/src/render/camera/mod.rs @@ -13,6 +13,8 @@ pub trait Camera: Downcast { fn new(instance: &VulkanInstance) -> Self where Self: Sized; + + fn destroy(&mut self, pool: vk::DescriptorPool, device: &ash::Device); } impl_downcast!(Camera); @@ -39,6 +41,10 @@ impl Camera for Camera2D { position: glam::Vec2::ZERO, } } + + fn destroy(&mut self, pool: vk::DescriptorPool, device: &ash::Device) { + todo!() + } } pub struct Camera3D { @@ -46,7 +52,7 @@ pub struct Camera3D { znear: f32, zfar: f32, ubo: UBO3D, - ubo_buffers: Vec, + pub ubo_buffers: Vec, position: glam::Vec3, rotation: glam::Quat, @@ -79,9 +85,15 @@ impl Camera for Camera3D { ubo_buffers, } } + + fn destroy(&mut self, pool: vk::DescriptorPool, device: &ash::Device) { + self.ubo_buffers.iter_mut().for_each(|f| f.destroy(device)) + } } impl Camera3D { + pub fn update_set() {} + fn recreate_view(&mut self) { let view = glam::Mat4::look_to_lh(self.position, self.direction_from_rotation(), glam::Vec3::Y); diff --git a/crates/vent-runtime/src/render/d3/light_renderer.rs b/crates/vent-runtime/src/render/d3/light_renderer.rs index c162e16..1f16958 100644 --- a/crates/vent-runtime/src/render/d3/light_renderer.rs +++ b/crates/vent-runtime/src/render/d3/light_renderer.rs @@ -1,14 +1,15 @@ use vent_assets::Mesh3D; -#[repr(C)] +use crate::render::model_renderer::ModelRenderer3D; + #[derive(Copy, Clone)] pub struct LightUBO { - position: [f32; 3], + pub position: [f32; 3], // Due to uniforms requiring 16 byte (4 float) spacing, we need to use a padding field here - _padding: u32, - color: [f32; 3], + // _padding: u32, + pub color: [f32; 3], // Due to uniforms requiring 16 byte (4 float) spacing, we need to use a padding field here - _padding2: u32, + // _padding2: u32, } #[allow(dead_code)] @@ -22,17 +23,11 @@ pub struct LightRenderer { #[allow(dead_code)] impl LightRenderer { - pub fn new(// device: &wgpu::Device, - // camera_bind_group_layout: &wgpu::BindGroupLayout, - // format: wgpu::TextureFormat, - ) -> Self { - todo!() - // let light_uniform = LightUBO { - // position: [2.0, 100.0, 2.0], - // _padding: 0, - // color: [1.0, 1.0, 1.0], - // _padding2: 0, - // }; + pub fn new(device: &ash::Device, model_renderer: &ModelRenderer3D) -> Self { + let light_uniform = LightUBO { + position: [2.0, 100.0, 2.0], + color: [1.0, 1.0, 1.0], + }; // let light_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { // label: Some("Light VB"), @@ -107,13 +102,13 @@ impl LightRenderer { // multiview: None, // }); - // Self { - // light_uniform, - // light_buffer, - // light_bind_group_layout, - // light_bind_group, - // light_render_pipeline, - // } + Self { + light_uniform, + // light_buffer, + // light_bind_group_layout, + // light_bind_group, + // light_render_pipeline, + } } pub fn render( diff --git a/crates/vent-runtime/src/render/d3/mod.rs b/crates/vent-runtime/src/render/d3/mod.rs index edbd310..1156f99 100644 --- a/crates/vent-runtime/src/render/d3/mod.rs +++ b/crates/vent-runtime/src/render/d3/mod.rs @@ -1,3 +1,5 @@ +use std::mem::size_of; + use ash::vk; use glam::Mat4; use vent_assets::Mesh3D; @@ -8,6 +10,8 @@ use vent_rendering::{ }; use winit::dpi::PhysicalSize; +use self::light_renderer::LightUBO; + use super::{ camera::{Camera, Camera3D}, model::Entity3D, @@ -17,11 +21,15 @@ use super::{ pub mod light_renderer; -#[repr(C)] +#[derive(Clone, Copy)] +pub struct MaterialUBO { + pub base_color: [f32; 4], +} + #[derive(Clone, Copy)] pub struct UBO3D { pub view_position: [f32; 3], - pub _padding: u32, + // pub _padding: u32, pub projection: [[f32; 4]; 4], pub view: [[f32; 4]; 4], pub transformation: [[f32; 4]; 4], @@ -31,7 +39,6 @@ impl Default for UBO3D { fn default() -> Self { Self { view_position: Default::default(), - _padding: Default::default(), projection: Default::default(), view: Default::default(), transformation: Mat4::IDENTITY.to_cols_array_2d(), @@ -83,10 +90,122 @@ impl Renderer for Renderer3D { "/res/models/test/Sponza-GLTF/Sponza.gltf" ); - // pollster::block_on(async { - // let mesh = Entity3D::new(vent_assets::Model3D::load(instance, model).await); - // mesh_renderer.insert(world.create_entity(), mesh); - // }); + + pollster::block_on(async { + let mut mesh = Entity3D::new(vent_assets::Model3D::load(instance, model).await); + for mesh in mesh.rendering_model.meshes.iter_mut() { + if let Some(material) = &mesh.material { + let descriptor_sets = VulkanInstance::allocate_descriptor_sets( + &instance.device, + instance.descriptor_pool, + instance.descriptor_set_layout, + instance.swapchain_images.len(), + ); + + let mut material_buffers = vec![]; + let mut light_buffers = vec![]; + + for _ in 0..instance.swapchain_images.len() { + let buffer = unsafe { + VulkanBuffer::new_init_type( + &instance.device, + &instance.memory_allocator, + size_of::() as vk::DeviceSize, + vk::BufferUsageFlags::UNIFORM_BUFFER, + &MaterialUBO { + base_color: material.base_color, + }, + ) + }; + material_buffers.push(buffer); + let buffer = unsafe { + VulkanBuffer::new_init_type( + &instance.device, + &instance.memory_allocator, + size_of::() as vk::DeviceSize, + vk::BufferUsageFlags::UNIFORM_BUFFER, + &LightUBO { + position: [2.0, 100.0, 2.0], + color: [1.0, 1.0, 1.0], + }, + ) + }; + light_buffers.push(buffer) + } + + for (i, &descriptor_set) in descriptor_sets.iter().enumerate() { + let diffuse_texture = &material.diffuse_texture; + + let image_info = vk::DescriptorImageInfo::builder() + .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) + .image_view(diffuse_texture.image_view) + .sampler(diffuse_texture.sampler) + .build(); + + let camera_info = vk::DescriptorBufferInfo::builder() + .buffer(camera.ubo_buffers[i].buffer) + .offset(0) + .range(size_of::() as vk::DeviceSize) + .build(); + + let material_buffer_info = vk::DescriptorBufferInfo::builder() + .buffer(material_buffers[i].buffer) + .offset(0) + .range(size_of::() as vk::DeviceSize) + .build(); + + let light_buffer_info = vk::DescriptorBufferInfo::builder() + .buffer(light_buffers[i].buffer) + .offset(0) + .range(size_of::() as vk::DeviceSize) + .build(); + + let desc_sets = [ + vk::WriteDescriptorSet { + dst_set: descriptor_set, + dst_binding: 0, + descriptor_count: 1, + descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + p_buffer_info: &camera_info, + ..Default::default() + }, + vk::WriteDescriptorSet { + dst_set: descriptor_set, + dst_binding: 1, // From DescriptorSetLayoutBinding + descriptor_count: 1, + descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, + p_image_info: &image_info, + ..Default::default() + }, + vk::WriteDescriptorSet { + dst_set: descriptor_set, + dst_binding: 2, + descriptor_count: 1, + descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + p_buffer_info: &material_buffer_info, + ..Default::default() + }, + vk::WriteDescriptorSet { + dst_set: descriptor_set, + dst_binding: 3, + descriptor_count: 1, + descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, + p_buffer_info: &light_buffer_info, + ..Default::default() + }, + ]; + + unsafe { + instance.device.update_descriptor_sets(&desc_sets, &[]); + } + + } + mesh.set_descriptor_set(descriptor_sets); + } + } + + mesh_renderer.insert(world.create_entity(), mesh); + }); // Record Command Buffers let render_area = vk::Rect2D::builder() @@ -121,17 +240,39 @@ impl Renderer for Renderer3D { .render_area(render_area) .clear_values(clear_values); - instance.device.cmd_begin_render_pass( - *command_buffer, - &info, - vk::SubpassContents::INLINE, - ); + let subpass_info = + vk::SubpassBeginInfo::builder().contents(vk::SubpassContents::INLINE); + + instance + .device + .cmd_begin_render_pass2(*command_buffer, &info, &subpass_info); instance.device.cmd_bind_pipeline( *command_buffer, vk::PipelineBindPoint::GRAPHICS, pipeline, ); + // instance.device.cmd_bind_descriptor_sets( + // *command_buffer, + // vk::PipelineBindPoint::GRAPHICS, + // instance.pipeline_layout, + // 0, + // &descriptor_sets, + // &[], + // ); + + instance + .device + .cmd_set_scissor(*command_buffer, 0, &[render_area]); + + let viewport = vk::Viewport::builder() + .height(instance.surface_resolution.height as f32) + .width(instance.surface_resolution.width as f32) + .max_depth(1.0); + instance + .device + .cmd_set_viewport(*command_buffer, 0, &[*viewport]); + mesh_renderer.record_buffer( instance, *command_buffer, @@ -141,7 +282,10 @@ impl Renderer for Renderer3D { ); // END - instance.device.cmd_end_render_pass(*command_buffer); + let subpass_end_info = vk::SubpassEndInfo::default(); + instance + .device + .cmd_end_render_pass2(*command_buffer, &subpass_end_info); instance.device.end_command_buffer(*command_buffer); } } @@ -374,6 +518,5 @@ fn create_tmp_cube(instance: &VulkanInstance) -> vent_assets::Mesh3D { &indices, None, None, - None, ) } diff --git a/crates/vent-runtime/src/render/mod.rs b/crates/vent-runtime/src/render/mod.rs index 31e7e01..e0104b6 100644 --- a/crates/vent-runtime/src/render/mod.rs +++ b/crates/vent-runtime/src/render/mod.rs @@ -1,5 +1,6 @@ use std::time::{Duration, Instant}; +use ash::vk; use vent_rendering::instance::VulkanInstance; use winit::dpi::PhysicalSize; use winit::window::Window; @@ -59,6 +60,8 @@ impl DefaultRuntimeRenderer { impl Drop for DefaultRuntimeRenderer { fn drop(&mut self) { + self.camera + .destroy(self.instance.descriptor_pool, &self.instance.device); self.runtime_renderer.destroy(&self.instance); } } @@ -135,9 +138,18 @@ impl RawRuntimeRenderer { let image = instance.next_image(); - if let Some(image_index) = image { - self.multi_renderer.render(instance, image_index, camera); - instance.submit(image_index); + match image { + Ok((image_index, _)) => { + self.multi_renderer.render(instance, image_index, camera); + instance.submit(image_index); + } + Err(err) => { + // if err == vk::Result::ERROR_OUT_OF_DATE_KHR { + // self.resize(instance, instance.surface_resolution, camera) + // } else if err == vk::Result::ERROR_SURFACE_LOST_KHR { + // self.resize(instance, instance.surface_resolution, camera) + // } + } } // self.gui_renderer.render( From 8908e1482f9bb14fe088b1c29dc02b45af2cd958 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev <71594357+Snowiiii@users.noreply.github.com> Date: Sun, 31 Dec 2023 12:49:18 +0100 Subject: [PATCH 08/14] Finally Rendering - Added Multi-Threading to glTF Loading - Fixed Shader Rendering Issue - Improvments --- Cargo.lock | 136 ++++--- crates/vent-assets/src/model/gltf.rs | 179 ++++----- crates/vent-assets/src/model/mod.rs | 34 +- crates/vent-assets/src/model/obj.rs | 20 +- crates/vent-common/Cargo.toml | 2 +- crates/vent-editor/Cargo.toml | 6 +- crates/vent-rendering/Cargo.toml | 2 +- crates/vent-rendering/src/buffer.rs | 44 ++- crates/vent-rendering/src/debug.rs | 20 +- crates/vent-rendering/src/image.rs | 53 +-- crates/vent-rendering/src/instance.rs | 71 +++- crates/vent-rendering/src/pipeline.rs | 42 +- crates/vent-rendering/src/surface.rs | 5 + crates/vent-runtime/Cargo.toml | 6 +- .../Sponza-OBJ/{sponza.obj => Sponza.obj} | 0 .../res/shaders/app/3D/shader.frag | 34 +- .../res/shaders/app/3D/shader.frag.spv | Bin 2852 -> 1300 bytes .../res/shaders/app/3D/shader.vert | 8 +- .../res/shaders/app/3D/shader.vert.spv | Bin 2132 -> 2128 bytes crates/vent-runtime/src/lib.rs | 5 +- .../src/render/camera/camera_controller3d.rs | 28 +- crates/vent-runtime/src/render/camera/mod.rs | 149 +++---- .../src/render/d3/light_renderer.rs | 15 +- crates/vent-runtime/src/render/d3/mod.rs | 363 ++++++------------ .../src/render/gui/gui_renderer.rs | 6 + crates/vent-runtime/src/render/mod.rs | 13 +- .../vent-runtime/src/render/model_renderer.rs | 2 +- 27 files changed, 560 insertions(+), 683 deletions(-) rename crates/vent-runtime/res/models/test/Sponza-OBJ/{sponza.obj => Sponza.obj} (100%) diff --git a/Cargo.lock b/Cargo.lock index 05d27f9..e1cf032 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,9 +26,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", "getrandom", @@ -229,6 +229,20 @@ name = "bytemuck" version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.43", +] [[package]] name = "byteorder" @@ -517,15 +531,18 @@ dependencies = [ [[package]] name = "ecolor" -version = "0.23.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfdf4e52dbbb615cfd30cf5a5265335c217b5fd8d669593cea74a517d9c605af" +checksum = "4b7637fc2e74d17e52931bac90ff4fc061ac776ada9c7fa272f24cdca5991972" +dependencies = [ + "bytemuck", +] [[package]] name = "egui" -version = "0.23.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bd69fed5fcf4fbb8225b24e80ea6193b61e17a625db105ef0c4d71dde6eb8b7" +checksum = "c55bcb864b764eb889515a38b8924757657a250738ad15126637ee2df291ee6b" dependencies = [ "ahash", "epaint", @@ -535,9 +552,9 @@ dependencies = [ [[package]] name = "egui-winit" -version = "0.23.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c15479a96d9fadccf5dac690bdc6373b97b8e1c0dd28367058f25a5298da0195" +checksum = "3b673606b6606b12b95e3a3194d7882bf5cff302db36a520b8144c7c342e4e84" dependencies = [ "arboard", "egui", @@ -551,9 +568,9 @@ dependencies = [ [[package]] name = "egui_dock" -version = "0.8.2" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a52f67bcab0eb6050cf8051c614966c1c57129fab23dbeae9c157214779053c7" +checksum = "246a6cbf38560cdcf75f955b1f2f39be6339a3f2958d06997ce70b7b4aa3f57d" dependencies = [ "duplicate", "egui", @@ -568,18 +585,22 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "emath" -version = "0.23.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ef2b29de53074e575c18b694167ccbe6e5191f7b25fe65175a0d905a32eeec0" +checksum = "a045c6c0b44b35e98513fc1e9d183ab42881ac27caccb9fa345465601f56cce4" +dependencies = [ + "bytemuck", +] [[package]] name = "epaint" -version = "0.23.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58067b840d009143934d91d8dcb8ded054d8301d7c11a517ace0a99bb1e1595e" +checksum = "7d1b9e000d21bab9b535ce78f9f7745be28b3f777f6c7223936561c5c7fefab8" dependencies = [ "ab_glyph", "ahash", + "bytemuck", "ecolor", "emath", "log", @@ -631,9 +652,9 @@ dependencies = [ [[package]] name = "fdeflate" -version = "0.3.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d6dafc854908ff5da46ff3f8f473c6984119a2876a383a860246dd7841a868" +checksum = "209098dd6dfc4445aa6111f0e98653ac323eaa4dfd212c9ca3931bf9955c31bd" dependencies = [ "simd-adler32", ] @@ -684,7 +705,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] @@ -785,7 +806,7 @@ dependencies = [ "inflections", "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] @@ -841,7 +862,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.51.1", ] [[package]] @@ -1048,9 +1069,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "memmap2" @@ -1293,7 +1314,7 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] @@ -1305,7 +1326,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] @@ -1725,7 +1746,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] @@ -1747,9 +1768,9 @@ checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" [[package]] name = "simple_logger" -version = "4.3.0" +version = "4.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0ca6504625ee1aa5fda33913d2005eab98c7a42dd85f116ecce3ff54c9d3ef" +checksum = "8e7e46c8c90251d47d08b28b8a419ffb4aede0f87c2eea95e17d1d5bacbf3ef1" dependencies = [ "colored", "log", @@ -1878,9 +1899,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.42" +version = "2.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" +checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" dependencies = [ "proc-macro2", "quote", @@ -1889,9 +1910,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.30.0" +version = "0.30.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c68492e7268037de59ae153d7efb79546cf94a18a9548235420d3d8d2436b4b1" +checksum = "ba2dbd2894d23b2d78dae768d85e323b557ac3ac71a5d917a31536d8f77ebada" dependencies = [ "cfg-if", "core-foundation-sys", @@ -1904,22 +1925,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "83a48fd946b02c0a526b2e9481c8e2a17755e47039164a86c4070446e3a4614d" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "e7fbe9b594d6568a6a1443250a7e67d80b74e1e96f6d1715e1e21cc1888291d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] @@ -2161,14 +2182,14 @@ dependencies = [ "serde", "serde_json", "sysinfo", - "winit 0.29.5", + "winit 0.29.7", ] [[package]] name = "vent-ecs" version = "0.1.0" dependencies = [ - "winit 0.29.5", + "winit 0.29.7", ] [[package]] @@ -2184,7 +2205,7 @@ dependencies = [ "vent-common", "vent-rendering", "vent-runtime", - "winit 0.29.5", + "winit 0.29.7", ] [[package]] @@ -2195,7 +2216,7 @@ dependencies = [ "image", "log", "raw-window-handle 0.6.0", - "winit 0.29.5", + "winit 0.29.7", ] [[package]] @@ -2215,7 +2236,7 @@ dependencies = [ "vent-common", "vent-ecs", "vent-rendering", - "winit 0.29.5", + "winit 0.29.7", ] [[package]] @@ -2265,7 +2286,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", "wasm-bindgen-shared", ] @@ -2299,7 +2320,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2504,9 +2525,9 @@ dependencies = [ [[package]] name = "web-time" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57099a701fb3a8043f993e8228dc24229c7b942e2b009a1b962e54489ba1d3bf" +checksum = "aa30049b1c872b72c89866d458eae9f20380ab280ffd1b1e18df2d3e2d98cfe0" dependencies = [ "js-sys", "wasm-bindgen", @@ -2577,12 +2598,12 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9" +checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" dependencies = [ - "windows-core", - "windows-targets 0.48.5", + "windows-core 0.52.0", + "windows-targets 0.52.0", ] [[package]] @@ -2594,6 +2615,15 @@ dependencies = [ "windows-targets 0.48.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.0", +] + [[package]] name = "windows-sys" version = "0.45.0" @@ -2829,9 +2859,9 @@ dependencies = [ [[package]] name = "winit" -version = "0.29.5" +version = "0.29.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cc935117ef48caed8822a893efef723e07ad868f668dfc4d244aea8873b07f9" +checksum = "7fd430cd4560ee9c48885a4ef473b609a56796e37b1e18222abee146143f7457" dependencies = [ "ahash", "android-activity 0.5.1", @@ -2877,9 +2907,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.5.30" +version = "0.5.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b5c3db89721d50d0e2a673f5043fc4722f76dcc352d7b1ab8b8288bed4ed2c5" +checksum = "97a4882e6b134d6c28953a387571f1acdd3496830d5e36c5e3a1075580ea641c" dependencies = [ "memchr", ] @@ -2986,7 +3016,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] diff --git a/crates/vent-assets/src/model/gltf.rs b/crates/vent-assets/src/model/gltf.rs index 2303569..8de95a2 100644 --- a/crates/vent-assets/src/model/gltf.rs +++ b/crates/vent-assets/src/model/gltf.rs @@ -1,15 +1,18 @@ use std::{ fs::{self, File}, io::BufReader, - mem::size_of, path::Path, - sync, thread, + sync::{ + self, + mpsc::{channel, sync_channel}, + }, + thread, }; use ash::vk; -use vent_rendering::{ - buffer::VulkanBuffer, image::VulkanImage, instance::VulkanInstance, Vertex3D, -}; +use gltf::texture::Sampler; +use image::DynamicImage; +use vent_rendering::{image::VulkanImage, instance::VulkanInstance, Vertex3D}; use crate::{Material, Model3D}; @@ -17,6 +20,12 @@ use super::{Mesh3D, ModelError}; pub(crate) struct GLTFLoader {} +struct MaterialData<'a> { + image: DynamicImage, + sampler: Option>, + base_color: [f32; 4], +} + impl GLTFLoader { pub async fn load(instance: &VulkanInstance, path: &Path) -> Result { let doc = gltf::Gltf::from_reader(fs::File::open(path).unwrap()).unwrap(); @@ -44,118 +53,84 @@ impl GLTFLoader { meshes: &mut Vec, ) { if let Some(mesh) = node.mesh() { - Self::load_mesh_singlethreaded(instance, model_dir, mesh, buffer_data, meshes); + Self::load_mesh_multithreaded(instance, model_dir, mesh, buffer_data, meshes); } node.children() .for_each(|child| Self::load_node(instance, model_dir, child, buffer_data, meshes)) } - // fn load_mesh_multithreaded( - // instance: &VulkanInstance, - // camera_set: vk::WriteDescriptorSet, - // model_dir: &Path, - // mesh: gltf::Mesh, - // buffer_data: &[gltf::buffer::Data], - // meshes: &mut Vec, - // ) { - // let primitive_len = mesh.primitives().size_hint().0; - // let (tx, rx) = sync::mpsc::sync_channel(primitive_len); // Create bounded channels - - // // Spawn threads to load mesh primitive - // thread::scope(|s| { - // let tx = tx.clone(); - // for primitive in mesh.primitives() { - // let tx = tx.clone(); - // let camera_set = camera_set.clone(); - // let mesh = mesh.clone(); - // let instance = instance; - // let model_dir = model_dir; - // let buffer_data = buffer_data; - - // s.spawn(move || { - // let loaded_material = - // Self::load_material(instance, camera_set, model_dir, primitive.material(), buffer_data); - - // let primitive = Self::load_primitive(buffer_data, primitive); - - // let loaded_mesh = Mesh3D::new( - // &instance.device, - // &instance.memory_allocator, - // &primitive.0, - // &primitive.1, - // Some(loaded_material), - // mesh.name(), - // ); - - // tx.send(loaded_mesh).unwrap(); - // }); - // } - // }); - // for _ in 0..primitive_len { - // let mesh = rx.recv().unwrap(); - // meshes.push(mesh); - // } - // } - - #[deprecated] - fn load_mesh_singlethreaded( + fn load_mesh_multithreaded( instance: &VulkanInstance, model_dir: &Path, mesh: gltf::Mesh, buffer_data: &[gltf::buffer::Data], meshes: &mut Vec, ) { - for primitive in mesh.primitives() { - let loaded_material = - Self::load_material(instance, model_dir, primitive.material(), buffer_data); - - let primitive = Self::load_primitive(buffer_data, primitive); - + let primitive_len = mesh.primitives().size_hint().0; + let (tx, rx) = sync::mpsc::sync_channel(primitive_len); // Create bounded channels + + // Spawn threads to load mesh + thread::scope(|s| { + let tx = tx.clone(); + for primitive in mesh.primitives() { + let tx = tx.clone(); + let model_dir = model_dir; + let buffer_data = buffer_data; + + s.spawn(move || { + let material_data = + Self::parse_material_data(model_dir, primitive.material(), buffer_data); + + let primitive = Self::load_primitive(buffer_data, primitive); + + tx.send((material_data, primitive)).unwrap(); + }); + }; + }); + for _ in 0..primitive_len { + let (material_data, primitive) = rx.recv().unwrap(); + let material = Self::load_material(instance, material_data); let loaded_mesh = Mesh3D::new( &instance.device, &instance.memory_allocator, &primitive.0, &primitive.1, - Some(loaded_material), + Some(material), mesh.name(), ); meshes.push(loaded_mesh); } } - fn load_material( - instance: &VulkanInstance, - model_dir: &Path, - material: gltf::Material<'_>, - buffer_data: &[gltf::buffer::Data], + /** + * We will parse all Materials and save that what we need + * the Data will be saved on RAM + */ + fn parse_material_data<'a>( + model_dir: &'a Path, + material: gltf::Material<'a>, + buffer_data: &'a [gltf::buffer::Data], // image_data: &[gltf::image::Data], - ) -> Material { + ) -> MaterialData<'a> { let pbr = material.pbr_metallic_roughness(); let diffuse_texture = if let Some(texture) = pbr.base_color_texture() { match texture.texture().source().source() { gltf::image::Source::View { view, - mime_type: img_type, + mime_type, } => { + let sampler = texture.texture().sampler(); let image = image::load_from_memory_with_format( &buffer_data[view.buffer().index()], - image::ImageFormat::from_mime_type(img_type).expect("TODO: Error Handling"), + image::ImageFormat::from_mime_type(mime_type).expect("TODO: Error Handling"), ) .unwrap(); - VulkanImage::from_image( - &instance.device, - image, - instance.command_pool, - &instance.memory_allocator, - instance.graphics_queue, - None, - ) + (image, Some(sampler)) } gltf::image::Source::Uri { uri, mime_type } => { let sampler = texture.texture().sampler(); - let sampler = Self::convert_sampler(&sampler); let image = if let Some(mime_type) = mime_type { image::load( BufReader::new(File::open(model_dir.join(uri)).unwrap()), @@ -167,31 +142,43 @@ impl GLTFLoader { image::open(model_dir.join(uri)).unwrap() }; - VulkanImage::from_image( - &instance.device, - image, - instance.command_pool, - &instance.memory_allocator, - instance.graphics_queue, - Some(sampler), - ) + (image, Some(sampler)) } } } else { - // Default Diffuse color - VulkanImage::from_color( - &instance.device, - [255, 255, 255, 255], - vk::Extent2D { - width: 128, - height: 128, - }, + ( + image::DynamicImage::ImageRgba8(image::RgbaImage::from_pixel( + 128, + 128, + image::Rgba([255, 255, 255, 255]), + )), + None, ) }; + MaterialData { + image: diffuse_texture.0, + sampler: diffuse_texture.1, + base_color: pbr.base_color_factor(), + } + } + + /** + * Creates an VulkanImage from Material Data, We want to do this Single threaded + * RAM -> VRAM + */ + fn load_material(instance: &VulkanInstance, data: MaterialData) -> Material { + let diffuse_texture = VulkanImage::from_image( + &instance.device, + data.image, + instance.command_pool, + &instance.memory_allocator, + instance.graphics_queue, + data.sampler.map(|s| Self::convert_sampler(&s)), + ); Material { diffuse_texture, - base_color: pbr.base_color_factor(), + base_color: data.base_color, } } diff --git a/crates/vent-assets/src/model/mod.rs b/crates/vent-assets/src/model/mod.rs index e847634..6af50e0 100644 --- a/crates/vent-assets/src/model/mod.rs +++ b/crates/vent-assets/src/model/mod.rs @@ -90,25 +90,21 @@ impl Mesh3D { material: Option, _name: Option<&str>, ) -> Self { - let vertex_buf = unsafe { - VulkanBuffer::new_init_type( - device, - allocator, - std::mem::size_of_val(vertices) as vk::DeviceSize, - vk::BufferUsageFlags::VERTEX_BUFFER, - vertices.as_ptr(), - ) - }; - - let index_buf = unsafe { - VulkanBuffer::new_init_type( - device, - allocator, - (size_of::() * indices.len()) as vk::DeviceSize, // TODO - vk::BufferUsageFlags::INDEX_BUFFER, - indices.as_ptr(), - ) - }; + let vertex_buf = VulkanBuffer::new_init( + device, + allocator, + (size_of::() * vertices.len()) as vk::DeviceSize, + vk::BufferUsageFlags::VERTEX_BUFFER, + vertices, + ); + + let index_buf = VulkanBuffer::new_init( + device, + allocator, + (size_of::() * indices.len()) as vk::DeviceSize, + vk::BufferUsageFlags::INDEX_BUFFER, + indices, + ); Self { vertex_buf, diff --git a/crates/vent-assets/src/model/obj.rs b/crates/vent-assets/src/model/obj.rs index 2597322..59f1fc8 100644 --- a/crates/vent-assets/src/model/obj.rs +++ b/crates/vent-assets/src/model/obj.rs @@ -1,9 +1,7 @@ -use std::{mem::size_of, path::Path}; +use std::path::Path; use ash::vk; -use vent_rendering::{ - buffer::VulkanBuffer, image::VulkanImage, instance::VulkanInstance, Vertex3D, -}; +use vent_rendering::{image::VulkanImage, instance::VulkanInstance, Vertex3D}; use crate::Model3D; @@ -29,7 +27,7 @@ impl OBJLoader { }; let mut meshes = vec![]; - for model in models.into_iter() { + for model in models { let mesh = Self::load_mesh(&model.mesh); let matieral = Self::load_material( @@ -42,17 +40,12 @@ impl OBJLoader { &instance.device, &instance.memory_allocator, &mesh.0, - &mesh.1, - None, // TODO + mesh.1, + Some(matieral), // TODO Some(&model.name), )); } - // let _descriptor_sets = materials - // .into_iter() - // .map(|material| Self::load_material(instance, path.parent().unwrap(), &material)) - // .collect::>(); - Ok(Model3D { meshes }) } @@ -73,6 +66,9 @@ impl OBJLoader { } else { VulkanImage::from_color( &instance.device, + instance.command_pool, + &instance.memory_allocator, + instance.graphics_queue, [255, 255, 255, 255], vk::Extent2D { width: 128, diff --git a/crates/vent-common/Cargo.toml b/crates/vent-common/Cargo.toml index 82b060e..827e31b 100644 --- a/crates/vent-common/Cargo.toml +++ b/crates/vent-common/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -winit = "0.29.5" +winit = "0.29.7" sysinfo = "0.30" chrono = "0.4" diff --git a/crates/vent-editor/Cargo.toml b/crates/vent-editor/Cargo.toml index f413854..558747c 100644 --- a/crates/vent-editor/Cargo.toml +++ b/crates/vent-editor/Cargo.toml @@ -14,10 +14,10 @@ vent-rendering = { path = "../vent-rendering"} ash = { version= "0.37.3", default-features = false, features = ["linked", "debug"] } # egui -egui = "0.23.0" -egui_dock = "0.8.2" +egui = "0.24.1" +egui_dock = "0.9.1" -winit = "0.29.5" +winit = "0.29.7" pollster = "0.3.0" log = "0.4" diff --git a/crates/vent-rendering/Cargo.toml b/crates/vent-rendering/Cargo.toml index 0c8d0d2..d29a0c9 100644 --- a/crates/vent-rendering/Cargo.toml +++ b/crates/vent-rendering/Cargo.toml @@ -10,6 +10,6 @@ ash = { version= "0.37.3", default-features = false, features = ["linked", "debu image = "0.24.7" -winit = "0.29.5" +winit = "0.29.6" raw-window-handle = "0.6" log = "0.4" diff --git a/crates/vent-rendering/src/buffer.rs b/crates/vent-rendering/src/buffer.rs index b27c7fe..aa30500 100644 --- a/crates/vent-rendering/src/buffer.rs +++ b/crates/vent-rendering/src/buffer.rs @@ -1,4 +1,4 @@ -use std::{mem::align_of, ptr::copy_nonoverlapping}; +use std::mem::align_of; use ash::vk; @@ -11,6 +11,9 @@ pub struct VulkanBuffer { impl VulkanBuffer { // Size = (size_of::() * SIZE) + /** + * Allocates & Binds new uninitialized Memory based on Size and Usage + */ pub fn new( device: &ash::Device, allocator: &MemoryAllocator, @@ -36,7 +39,7 @@ impl VulkanBuffer { unsafe { device .bind_buffer_memory(buffer, buffer_memory, 0) - .expect("Failed to bind Buffer Memory"); + .expect("Failed to bind Buffer memory"); } Self { @@ -45,6 +48,9 @@ impl VulkanBuffer { } } + /** + * Allocates new Image memory & binds them + */ pub fn new_image( device: &ash::Device, allocator: &MemoryAllocator, @@ -52,22 +58,32 @@ impl VulkanBuffer { ) -> vk::DeviceMemory { let requirements = unsafe { device.get_image_memory_requirements(image) }; - allocator.allocate(device, requirements, vk::MemoryPropertyFlags::DEVICE_LOCAL) + let memory = + allocator.allocate(device, requirements, vk::MemoryPropertyFlags::DEVICE_LOCAL); + unsafe { + device + .bind_image_memory(image, memory, 0) + .expect("Unable to bind Image memory") + }; + memory } - pub fn new_init( + /** + * Allocates & Binds new initialized Memory based on Size and Usage + */ + pub fn new_init( device: &ash::Device, allocator: &MemoryAllocator, size: vk::DeviceSize, usage: vk::BufferUsageFlags, - data: &[u8], + data: &[T], ) -> Self { let buffer = Self::new(device, allocator, size, usage); buffer.upload_data(device, data, size); buffer } - pub unsafe fn new_init_type( + pub fn new_init_type( device: &ash::Device, allocator: &MemoryAllocator, size: vk::DeviceSize, @@ -79,23 +95,18 @@ impl VulkanBuffer { buffer } - pub fn upload_data(&self, device: &ash::Device, data: &[u8], size: vk::DeviceSize) { + pub fn upload_data(&self, device: &ash::Device, data: &[T], size: vk::DeviceSize) { unsafe { let memory = device .map_memory(self.buffer_memory, 0, size, vk::MemoryMapFlags::empty()) .unwrap(); - let mut align = ash::util::Align::new(memory, align_of::() as _, size); - align.copy_from_slice(&data); + let mut align = ash::util::Align::new(memory, align_of::() as _, size); + align.copy_from_slice(data); device.unmap_memory(self.buffer_memory); } } - pub unsafe fn upload_type( - &self, - device: &ash::Device, - data: *const T, - size: vk::DeviceSize, - ) { + pub fn upload_type(&self, device: &ash::Device, data: *const T, size: vk::DeviceSize) { unsafe { let memory = device .map_memory(self.buffer_memory, 0, size, vk::MemoryMapFlags::empty()) @@ -106,11 +117,10 @@ impl VulkanBuffer { } } - pub fn destroy(&mut self, device: &ash::Device) { unsafe { - device.destroy_buffer(self.buffer, None); device.free_memory(self.buffer_memory, None); + device.destroy_buffer(self.buffer, None); } } } diff --git a/crates/vent-rendering/src/debug.rs b/crates/vent-rendering/src/debug.rs index ce52b07..160270a 100644 --- a/crates/vent-rendering/src/debug.rs +++ b/crates/vent-rendering/src/debug.rs @@ -1,5 +1,5 @@ use ash::extensions::ext::DebugUtils; -use ash::{vk, Device, Entry, Instance}; +use ash::{vk, Entry, Instance}; use std::os::raw::c_void; use std::{ ffi::{CStr, CString}, @@ -66,6 +66,21 @@ pub fn check_validation_layer_support(entry: &Entry) { } } +pub fn get_validation_features() -> vk::ValidationFeaturesEXT { + if ENABLE_VALIDATION_LAYERS { + let features = [ + vk::ValidationFeatureEnableEXT::BEST_PRACTICES, + vk::ValidationFeatureEnableEXT::SYNCHRONIZATION_VALIDATION, + ]; + + return vk::ValidationFeaturesEXT::builder() + .enabled_validation_features(&features) + .build(); + } else { + return vk::ValidationFeaturesEXT::default(); + } +} + /// Setup the debug message if validation layers are enabled. #[must_use] pub fn setup_debug_messenger( @@ -74,7 +89,8 @@ pub fn setup_debug_messenger( ) -> (DebugUtils, vk::DebugUtilsMessengerEXT) { let create_info = vk::DebugUtilsMessengerCreateInfoEXT::builder() .message_severity( - vk::DebugUtilsMessageSeverityFlagsEXT::ERROR + vk::DebugUtilsMessageSeverityFlagsEXT::VERBOSE + | vk::DebugUtilsMessageSeverityFlagsEXT::ERROR | vk::DebugUtilsMessageSeverityFlagsEXT::WARNING | vk::DebugUtilsMessageSeverityFlagsEXT::INFO, ) diff --git a/crates/vent-rendering/src/image.rs b/crates/vent-rendering/src/image.rs index 8e469f5..bfbd2a9 100644 --- a/crates/vent-rendering/src/image.rs +++ b/crates/vent-rendering/src/image.rs @@ -52,9 +52,7 @@ impl VulkanImage { } _ => image.to_rgb8().into_raw(), }; - let image_data_size = - (std::mem::size_of::() as u32 * image_size.width * image_size.height * 4) - as vk::DeviceSize; + let image_data_size = (image_size.width * image_size.height * 4) as vk::DeviceSize; let mut staging_buffer = VulkanBuffer::new_init( device, @@ -71,11 +69,7 @@ impl VulkanImage { vk::ImageUsageFlags::TRANSFER_DST | vk::ImageUsageFlags::SAMPLED, ); let memory = VulkanBuffer::new_image(device, allocator, image); - unsafe { - device - .bind_image_memory(image, memory, 0) - .expect("Unable to bind depth image memory") - }; + Self::copy_buffer_to_image( device, image, @@ -120,11 +114,6 @@ impl VulkanImage { vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT, ); let memory = VulkanBuffer::new_image(device, allocator, image); - unsafe { - device - .bind_image_memory(image, memory, 0) - .expect("Unable to bind depth image memory") - }; let image_view = Self::create_image_view(image, device, format, vk::ImageAspectFlags::DEPTH); @@ -135,9 +124,23 @@ impl VulkanImage { } } - pub fn from_color(_device: &ash::Device, color: [u8; 4], size: Extent2D) -> Self { - let _img = image::RgbaImage::from_pixel(size.width, size.height, image::Rgba(color)); - todo!() + pub fn from_color( + device: &ash::Device, + command_pool: vk::CommandPool, + allocator: &MemoryAllocator, + submit_queue: vk::Queue, + color: [u8; 4], + size: Extent2D, + ) -> Self { + let color_img = image::RgbaImage::from_pixel(size.width, size.height, image::Rgba(color)); + Self::from_image( + device, + image::DynamicImage::ImageRgba8(color_img), + command_pool, + allocator, + submit_queue, + None, + ) } pub fn copy_buffer_to_image( @@ -156,7 +159,7 @@ impl VulkanImage { new_layout: vk::ImageLayout::TRANSFER_DST_OPTIMAL, src_stage_mask: vk::PipelineStageFlags2::BOTTOM_OF_PIPE, dst_stage_mask: vk::PipelineStageFlags2::TRANSFER, - image: image, + image, subresource_range: vk::ImageSubresourceRange { aspect_mask: vk::ImageAspectFlags::COLOR, level_count: 1, @@ -209,7 +212,7 @@ impl VulkanImage { dst_stage_mask: vk::PipelineStageFlags2::FRAGMENT_SHADER, old_layout: vk::ImageLayout::TRANSFER_DST_OPTIMAL, new_layout: vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, - image: image, + image, subresource_range: vk::ImageSubresourceRange { aspect_mask: vk::ImageAspectFlags::COLOR, level_count: 1, @@ -230,7 +233,7 @@ impl VulkanImage { end_single_time_command(device, command_pool, submit_queue, command_buffer); } - fn default_sampler() -> vk::SamplerCreateInfo { + pub fn default_sampler() -> vk::SamplerCreateInfo { vk::SamplerCreateInfo::builder() .mag_filter(Self::DEFAULT_TEXTURE_FILTER) .min_filter(Self::DEFAULT_TEXTURE_FILTER) @@ -251,7 +254,7 @@ impl VulkanImage { format: vk::Format, mask: vk::ImageAspectFlags, ) -> vk::ImageView { - let depth_image_view_info = vk::ImageViewCreateInfo::builder() + let image_view_info = vk::ImageViewCreateInfo::builder() .subresource_range( vk::ImageSubresourceRange::builder() .aspect_mask(mask) @@ -264,7 +267,7 @@ impl VulkanImage { .view_type(vk::ImageViewType::TYPE_2D) .build(); - unsafe { device.create_image_view(&depth_image_view_info, None) }.unwrap() + unsafe { device.create_image_view(&image_view_info, None) }.unwrap() } fn create_image( @@ -284,8 +287,8 @@ impl VulkanImage { .usage(usage) .sharing_mode(vk::SharingMode::EXCLUSIVE) .build(); - let image = unsafe { device.create_image(&create_info, None) }.unwrap(); - image + + unsafe { device.create_image(&create_info, None) }.unwrap() } pub fn destroy(&mut self, device: &ash::Device) { @@ -293,9 +296,9 @@ impl VulkanImage { device.destroy_image_view(self.image_view, None); device.destroy_image(self.image, None); device.destroy_sampler(self.sampler, None); - self.memory.map(|memory| { + if let Some(memory) = self.memory { device.free_memory(memory, None); - }); + } } } } diff --git a/crates/vent-rendering/src/instance.rs b/crates/vent-rendering/src/instance.rs index d695e01..f30694b 100644 --- a/crates/vent-rendering/src/instance.rs +++ b/crates/vent-rendering/src/instance.rs @@ -3,7 +3,7 @@ use ash::prelude::VkResult; use ash::vk::{Extent2D, SwapchainKHR}; use ash::{extensions::ext::DebugUtils, vk, Entry}; use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; -use std::ffi::CString; + use std::{default::Default, ffi::CStr}; #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -13,13 +13,13 @@ use ash::vk::{ use crate::allocator::MemoryAllocator; use crate::debug::{ - check_validation_layer_support, get_layer_names_and_pointers, setup_debug_messenger, - ENABLE_VALIDATION_LAYERS, + check_validation_layer_support, get_layer_names_and_pointers, get_validation_features, + setup_debug_messenger, ENABLE_VALIDATION_LAYERS, }; use crate::image::{DepthImage, VulkanImage}; use crate::surface; -const MAX_FRAMES_IN_FLIGHT: u8 = 2; +pub const MAX_FRAMES_IN_FLIGHT: u8 = 2; pub struct VulkanInstance { pub memory_allocator: MemoryAllocator, @@ -89,6 +89,7 @@ impl VulkanInstance { .expect("Unsupported Surface Extension") .to_vec(); if ENABLE_VALIDATION_LAYERS { + extension_names.push(vk::ExtValidationFeaturesFn::name().as_ptr()); extension_names.push(DebugUtils::name().as_ptr()); } @@ -108,11 +109,14 @@ impl VulkanInstance { let (_layer_names, layer_names_ptrs) = get_layer_names_and_pointers(); check_validation_layer_support(&entry); + let mut validation_features = get_validation_features(); + let create_info = vk::InstanceCreateInfo::builder() .application_info(&app_info) .enabled_extension_names(&extension_names) .enabled_layer_names(&layer_names_ptrs) .flags(create_flags) + .push_next(&mut validation_features) .build(); let instance = unsafe { @@ -233,8 +237,9 @@ impl VulkanInstance { unsafe { self.device .wait_for_fences(&[in_flight_fence], true, u64::max_value()) + .unwrap(); + self.device.reset_fences(&[in_flight_fence]).unwrap(); } - .unwrap(); unsafe { self.swapchain_loader.acquire_next_image( self.swapchain, @@ -259,7 +264,7 @@ impl VulkanInstance { let signal_semaphores = vk::SemaphoreSubmitInfo::builder() .semaphore(self.render_finished_semaphores[self.frame]) - // .stage_mask(vk::PipelineStageFlags2::ALL_GRAPHICS) + .stage_mask(vk::PipelineStageFlags2::ALL_GRAPHICS) .build(); let submit_info = vk::SubmitInfo2::builder() @@ -269,8 +274,6 @@ impl VulkanInstance { .build(); unsafe { - self.device.reset_fences(&[in_flight_fence]).unwrap(); - self.device .queue_submit2(self.graphics_queue, &[submit_info], in_flight_fence) .unwrap(); @@ -456,8 +459,14 @@ impl VulkanInstance { } let surface_resolution = match surface_capabilities.current_extent.width { std::u32::MAX => vk::Extent2D { - width: size.width, - height: size.height, + width: size.width.clamp( + surface_capabilities.min_image_extent.width, + surface_capabilities.max_image_extent.width, + ), + height: size.height.clamp( + surface_capabilities.min_image_extent.height, + surface_capabilities.max_image_extent.height, + ), }, _ => surface_capabilities.current_extent, }; @@ -598,17 +607,17 @@ impl VulkanInstance { let pool_sizes = [ vk::DescriptorPoolSize { ty: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, - descriptor_count: 1000, + descriptor_count: 10000, }, vk::DescriptorPoolSize { ty: vk::DescriptorType::UNIFORM_BUFFER, - descriptor_count: 1000, + descriptor_count: 10000, }, ]; let create_info = vk::DescriptorPoolCreateInfo::builder() .pool_sizes(&pool_sizes) - .max_sets(1000) + .max_sets(10000) .build(); unsafe { device.create_descriptor_pool(&create_info, None) }.unwrap() @@ -691,6 +700,9 @@ impl VulkanInstance { samples: vk::SampleCountFlags::TYPE_1, load_op: vk::AttachmentLoadOp::CLEAR, store_op: vk::AttachmentStoreOp::STORE, + stencil_store_op: vk::AttachmentStoreOp::DONT_CARE, + stencil_load_op: vk::AttachmentLoadOp::DONT_CARE, + initial_layout: vk::ImageLayout::UNDEFINED, final_layout: vk::ImageLayout::PRESENT_SRC_KHR, ..Default::default() }, @@ -698,6 +710,10 @@ impl VulkanInstance { format: depth_format, samples: vk::SampleCountFlags::TYPE_1, load_op: vk::AttachmentLoadOp::CLEAR, + store_op: vk::AttachmentStoreOp::DONT_CARE, + stencil_store_op: vk::AttachmentStoreOp::DONT_CARE, + stencil_load_op: vk::AttachmentLoadOp::DONT_CARE, + initial_layout: vk::ImageLayout::UNDEFINED, final_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, ..Default::default() }, @@ -712,14 +728,27 @@ impl VulkanInstance { layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, ..Default::default() }; - let dependencies = [vk::SubpassDependency2 { - src_subpass: vk::SUBPASS_EXTERNAL, - src_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT, - dst_access_mask: vk::AccessFlags::COLOR_ATTACHMENT_READ - | vk::AccessFlags::COLOR_ATTACHMENT_WRITE, - dst_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT, - ..Default::default() - }]; + let dependencies = [ + vk::SubpassDependency2 { + src_subpass: vk::SUBPASS_EXTERNAL, + src_stage_mask: vk::PipelineStageFlags::EARLY_FRAGMENT_TESTS + | vk::PipelineStageFlags::LATE_FRAGMENT_TESTS, + dst_stage_mask: vk::PipelineStageFlags::EARLY_FRAGMENT_TESTS + | vk::PipelineStageFlags::LATE_FRAGMENT_TESTS, + src_access_mask: vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_WRITE, + dst_access_mask: vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_READ + | vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_WRITE, + ..Default::default() + }, + vk::SubpassDependency2 { + src_subpass: vk::SUBPASS_EXTERNAL, + src_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT, + dst_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT, + dst_access_mask: vk::AccessFlags::COLOR_ATTACHMENT_READ + | vk::AccessFlags::COLOR_ATTACHMENT_WRITE, + ..Default::default() + }, + ]; let subpass = vk::SubpassDescription2::builder() .color_attachments(&color_attachment_refs) diff --git a/crates/vent-rendering/src/pipeline.rs b/crates/vent-rendering/src/pipeline.rs index 5092bd3..5281686 100644 --- a/crates/vent-rendering/src/pipeline.rs +++ b/crates/vent-rendering/src/pipeline.rs @@ -4,12 +4,12 @@ use ash::{util::read_spv, vk}; use crate::instance::VulkanInstance; -pub fn create_pipeline<'a>( +pub fn create_pipeline( instance: &VulkanInstance, vertex_file: String, fragment_file: String, binding_desc: vk::VertexInputBindingDescription, - attrib_desc: &'a [vk::VertexInputAttributeDescription], + attrib_desc: &[vk::VertexInputAttributeDescription], surface_resolution: vk::Extent2D, ) -> vk::Pipeline { let vertex_code = @@ -55,7 +55,7 @@ pub fn create_pipeline<'a>( ]; let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::builder() - .vertex_attribute_descriptions(&attrib_desc) + .vertex_attribute_descriptions(attrib_desc) .vertex_binding_descriptions(&[binding_desc]) .build(); let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo { @@ -80,44 +80,30 @@ pub fn create_pipeline<'a>( front_face: vk::FrontFace::COUNTER_CLOCKWISE, line_width: 1.0, polygon_mode: vk::PolygonMode::FILL, + cull_mode: vk::CullModeFlags::BACK, ..Default::default() }; let multisample_state_info = vk::PipelineMultisampleStateCreateInfo { rasterization_samples: vk::SampleCountFlags::TYPE_1, ..Default::default() }; - let noop_stencil_state = vk::StencilOpState { - fail_op: vk::StencilOp::KEEP, - pass_op: vk::StencilOp::KEEP, - depth_fail_op: vk::StencilOp::KEEP, - compare_op: vk::CompareOp::ALWAYS, - ..Default::default() - }; - let depth_state_info = vk::PipelineDepthStencilStateCreateInfo { - depth_test_enable: 1, - depth_write_enable: 1, - depth_compare_op: vk::CompareOp::LESS_OR_EQUAL, - front: noop_stencil_state, - back: noop_stencil_state, - max_depth_bounds: 1.0, - ..Default::default() - }; + + let depth_state_info = vk::PipelineDepthStencilStateCreateInfo::builder() + .depth_test_enable(true) + .depth_write_enable(true) + .depth_compare_op(vk::CompareOp::LESS) + .max_depth_bounds(1.0) + .build(); let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState { - blend_enable: 0, - src_color_blend_factor: vk::BlendFactor::SRC_COLOR, - dst_color_blend_factor: vk::BlendFactor::ONE_MINUS_DST_COLOR, - color_blend_op: vk::BlendOp::ADD, - src_alpha_blend_factor: vk::BlendFactor::ZERO, - dst_alpha_blend_factor: vk::BlendFactor::ZERO, - alpha_blend_op: vk::BlendOp::ADD, color_write_mask: vk::ColorComponentFlags::RGBA, + ..Default::default() }]; let color_blend_state = vk::PipelineColorBlendStateCreateInfo::builder() - .logic_op(vk::LogicOp::CLEAR) + .logic_op(vk::LogicOp::COPY) .attachments(&color_blend_attachment_states) .build(); - let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; + let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; // TODO let dynamic_state_info = vk::PipelineDynamicStateCreateInfo::builder() .dynamic_states(&dynamic_state) .build(); diff --git a/crates/vent-rendering/src/surface.rs b/crates/vent-rendering/src/surface.rs index 5f8a42f..77dcbab 100644 --- a/crates/vent-rendering/src/surface.rs +++ b/crates/vent-rendering/src/surface.rs @@ -17,6 +17,7 @@ pub unsafe fn create_surface( allocation_callbacks: Option<&vk::AllocationCallbacks>, ) -> VkResult { match (display_handle.as_raw(), window_handle.as_raw()) { + #[cfg(target_os = "windows")] (RawDisplayHandle::Windows(_), RawWindowHandle::Win32(window)) => { let hinstance = window.hinstance.expect("No Win32 Instance"); let surface_desc = vk::Win32SurfaceCreateInfoKHR::builder() @@ -26,6 +27,7 @@ pub unsafe fn create_surface( surface_fn.create_win32_surface(&surface_desc, allocation_callbacks) } + #[cfg(target_os = "linux")] (RawDisplayHandle::Wayland(display), RawWindowHandle::Wayland(window)) => { let surface_desc = vk::WaylandSurfaceCreateInfoKHR::builder() .display(display.display.as_ptr()) @@ -34,6 +36,7 @@ pub unsafe fn create_surface( surface_fn.create_wayland_surface(&surface_desc, allocation_callbacks) } + #[cfg(target_os = "linux")] (RawDisplayHandle::Xlib(display), RawWindowHandle::Xlib(window)) => { let display = display.display.expect("No XOrg Display"); let surface_desc = vk::XlibSurfaceCreateInfoKHR::builder() @@ -43,6 +46,7 @@ pub unsafe fn create_surface( surface_fn.create_xlib_surface(&surface_desc, allocation_callbacks) } + #[cfg(target_os = "linux")] (RawDisplayHandle::Xcb(display), RawWindowHandle::Xcb(window)) => { let connection = display.connection.expect("No X-Server Connection"); let surface_desc = vk::XcbSurfaceCreateInfoKHR::builder() @@ -52,6 +56,7 @@ pub unsafe fn create_surface( surface_fn.create_xcb_surface(&surface_desc, allocation_callbacks) } + #[cfg(target_os = "android")] (RawDisplayHandle::Android(_), RawWindowHandle::AndroidNdk(window)) => { let surface_desc = vk::AndroidSurfaceCreateInfoKHR::builder().window(window.a_native_window.as_ptr()); diff --git a/crates/vent-runtime/Cargo.toml b/crates/vent-runtime/Cargo.toml index b529c5a..c45eab1 100644 --- a/crates/vent-runtime/Cargo.toml +++ b/crates/vent-runtime/Cargo.toml @@ -13,7 +13,7 @@ vent-ecs = { path = "../vent-ecs"} ash = { version= "0.37.3", default-features = false, features = ["linked", "debug"] } -winit = "0.29.5" +winit = "0.29.7" pollster = "0.3.0" log = "0.4" @@ -21,8 +21,8 @@ glam = "0.25" downcast-rs = "1.2.0" # egui -egui = "0.23.0" -egui-winit = "0.23.0" +egui = "0.24.1" +egui-winit = "0.24.1" [target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies] simple_logger = "4.3.0" diff --git a/crates/vent-runtime/res/models/test/Sponza-OBJ/sponza.obj b/crates/vent-runtime/res/models/test/Sponza-OBJ/Sponza.obj similarity index 100% rename from crates/vent-runtime/res/models/test/Sponza-OBJ/sponza.obj rename to crates/vent-runtime/res/models/test/Sponza-OBJ/Sponza.obj diff --git a/crates/vent-runtime/res/shaders/app/3D/shader.frag b/crates/vent-runtime/res/shaders/app/3D/shader.frag index 0bb7394..44ee72f 100644 --- a/crates/vent-runtime/res/shaders/app/3D/shader.frag +++ b/crates/vent-runtime/res/shaders/app/3D/shader.frag @@ -26,30 +26,30 @@ layout (location = 0) out vec4 fragColor; const float ambient_strength = 0.1; void main() { - vec4 texture = texture(texture_diffuse, tex_coord) * material.base_color; + vec4 texture = texture(texture_diffuse, tex_coord); //* material.base_color; // Calculate the ambient color - vec3 ambient_color = light.color * ambient_strength; + // vec3 ambient_color = light.color * ambient_strength; - // Calculate the light direction - vec3 light_dir = normalize(light.position - world_position); + // // Calculate the light direction + // vec3 light_dir = normalize(light.position - world_position); - // Calculate the view direction - vec3 view_dir = normalize(view_position.xyz - world_position); + // // Calculate the view direction + // vec3 view_dir = normalize(view_position.xyz - world_position); - // Calculate the half vector - vec3 half_dir = normalize(view_dir + light_dir); + // // Calculate the half vector + // vec3 half_dir = normalize(view_dir + light_dir); - // Calculate the diffuse color - float diffuse_strength = max(dot(world_position, light_dir), 0.0); - vec3 diffuse_color = light.color * diffuse_strength; + // // Calculate the diffuse color + // float diffuse_strength = max(dot(world_position, light_dir), 0.0); + // vec3 diffuse_color = light.color * diffuse_strength; - // Calculate the specular color - float specular_strength = pow(max(dot(world_position, half_dir), 0.0), 32.0); - vec3 specular_color = specular_strength * light.color; + // // Calculate the specular color + // float specular_strength = pow(max(dot(world_position, half_dir), 0.0), 32.0); + // vec3 specular_color = specular_strength * light.color; - // Calculate the final color - vec3 result = (ambient_color + diffuse_color + specular_color) * texture.xyz; + // // Calculate the final color + // vec3 result = (ambient_color + diffuse_color + specular_color) * texture.xyz; - fragColor = vec4(result, 1.0); + fragColor = texture; // vec4(result, 1.0); } \ No newline at end of file diff --git a/crates/vent-runtime/res/shaders/app/3D/shader.frag.spv b/crates/vent-runtime/res/shaders/app/3D/shader.frag.spv index f93609a2e504c5130987003c377c1ee640cd5159..9d9a422d596852462fff706a06679908af266a0e 100644 GIT binary patch literal 1300 zcmZ9MOK;Oq5QQ&IVhV*mD72J9ahmRsDi(l{P}#5ui?CwBG72OqmXaDdF75AQUH%Un zB)%{9RV=PFxjtvkJUnBiwbr{G!mY3o*277t&Q4f^32@2s?hif>P8a3)^wsN^DmFuF zDO9tCs?Dv&3N%0eC6c2yeua8lW>29 zhvRHIy=JvTijmk-pjb=QOF$r>>ucO6;1WU2; z2XOO-)_xA*2HE-dlG|9Z=SRNC$}C^LcS5YZbE(t8w8Jy-td12smy5iZ+llX%g0J#o zHXg3B*@tsmF_qRi{>&y<4Qc3;)A{K0L~Ojhh~0^GJ>s|@@keUKS@a}0efA^gj?_Do zW`42x^&21O5#u9geYtJSoa$mu=hDn6Hm6^gHSJf6?~v9w#;esI_2v@$E$vc8T^Fx@ zpZ9o5xKnH&mEWOQeai1Tx14ss7kHOjzxA6Z;zROn;817$y;>yquEy@gW4$eI^Vy4f zXJRgS^5si&IQ4;_iR=xW+Hg+e;7oeRFg6hVREZ?!jY^e_%S?=5jCo uANa0kVCTDuIa{&wdw@B+FGQ)^#ni~ZC!_Il>h^JaW(ek!GX>0sKQw$gAMO=BPltWwO&EB96w z`h&*8`3vV{97^K_QO;pl6U^F9y}fJVDE1ciF1Cg>u@-iOb@JE{Z=79H`V)~!(DHiY z1LOwHp9XuqCizNwdK9lW+O5`JUwpFI3*P!>x7%yL5qp+-wLWO}+Vu`Dt1AVjzftcu zA$PjHA@>B>PKoPYFM-u}HrmbIK~PbhNLBEa_SW`*SxsZdqi(-FXm^XVS727bI9AHr z6l>>*J9(`&z8*2Bp%joxac7Uay-s6&q$u|t@;|nlk2AI4dbb5OqJmGR_rbU8oz{pu zm1bUUPSAunkn`ER}MjdZ*GY@cyIb=3b}XD=)In+vVJUcR7*ngZG;Ky$%;- zExvuLSKnG1UN^`@(F?oX-i|LL$G#{XAuYr4t-UWt#IyL`sj>YvgE?-Y;d?vghZCIf z0<*v5`^IHGWA)6tzRK)~^?|vc*bz+4DsyP6SJu>5a~yL|``;Ra?|T{B=jOeeID@g@ zh_QPbdoRZ79YaN(St4Wo6L=NoDs~dS-;}ZXRetv~i)p9$nx0}duYP$%d>XxjB;>h% zI+MgM=h$~~xZh!B^{hp{cchlMd}H59YzA%L$XetcXLg;KTw~uv>^SjB<|^jevpIea z-{JaG%yQMUmKT|=#k(=@y_plAA+BcM*!(Q>u+1i2@7Y|Vp7C17g8z^>rJt{w z_wMbd^8T$HU!>nXyM5wN_ivC%X4l#`{`baS-lhMC<=FqOa_s+8Ircv&V$WJD#p*4U zV)Opj1mC>>FXi}tj%(CsKOVyDMPvKz8O&aLz$sjJ43i_i2xh-LkJ)4Pk?Z80#>9Wi z>t4Wjt@ssg#(NM`!yb4AvrpzRHGJ<^G4bEw7{8XWGt6pucVeOO2EH0mhilGa;-R^K zZ~y$7HQ&aUBR);nxaJ(@``*CJyO-}G9y;&g+jkM4$1m$%AeJK@x)C<*U*g-V z5r2j6dE-qV;L8yY&e!X#=gZ4V7K{av2VZ2n7G5c7{mMq&3})nBhNbh x_Qhh)b$qeAxhLxQVvfKz@Ws>)Y%^o-b%)BVt%12-zWIlkd#*8?`v-+f*uT^o(%%38 diff --git a/crates/vent-runtime/res/shaders/app/3D/shader.vert b/crates/vent-runtime/res/shaders/app/3D/shader.vert index d6bbafc..c370d55 100644 --- a/crates/vent-runtime/res/shaders/app/3D/shader.vert +++ b/crates/vent-runtime/res/shaders/app/3D/shader.vert @@ -6,11 +6,11 @@ layout (location = 1) in vec2 in_tex_coord; layout (location = 2) in vec3 in_normal; layout (binding = 0) uniform UBO { - vec3 ubo_view_position; + vec3 view_position; mat4 projection; mat4 view; mat4 transformation; -}; +} ubo; layout (location = 0) out vec2 tex_coord; @@ -23,8 +23,8 @@ void main() { tex_coord = in_tex_coord; normal = in_normal; world_position = in_position; - position = projection * view * transformation * vec4(in_position, 1.0); - view_position = ubo_view_position; + position = ubo.projection * ubo.view * ubo.transformation * vec4(in_position, 1.0); + view_position = ubo.view_position; gl_Position = position; } \ No newline at end of file diff --git a/crates/vent-runtime/res/shaders/app/3D/shader.vert.spv b/crates/vent-runtime/res/shaders/app/3D/shader.vert.spv index c37c819f7f48923a57e93db608e9ab918ade7282..01ad8b30e550671fd336ea1569bcb5ef9a4d38f0 100644 GIT binary patch delta 31 icmca2a6w>$5hE8ngA@Y { + window_id: _, + } => { renderer.progress_event(event); match event { @@ -90,6 +90,7 @@ impl VentApplication { _ => {} } } + Event::AboutToWait {} => vent_window.window.request_redraw(), Event::DeviceEvent { event: DeviceEvent::MouseMotion { delta }, .. diff --git a/crates/vent-runtime/src/render/camera/camera_controller3d.rs b/crates/vent-runtime/src/render/camera/camera_controller3d.rs index ee4a346..01c5f4c 100644 --- a/crates/vent-runtime/src/render/camera/camera_controller3d.rs +++ b/crates/vent-runtime/src/render/camera/camera_controller3d.rs @@ -31,35 +31,38 @@ impl CameraController3D { event: &KeyEvent, delta_time: f32, ) -> bool { + log::info!("{}", camera.position); if event.state == ElementState::Pressed { let (sin_pitch, cos_pitch) = camera.rotation.x.sin_cos(); match event.logical_key.as_ref() { + // Arrow keys works but WASD not :C Key::Character("W") | Key::Named(NamedKey::ArrowUp) => { - camera.add_x(sin_pitch * self.speed * delta_time); - camera.add_z(cos_pitch * self.speed * delta_time); + print!("pressed W"); + camera.position.x += sin_pitch * self.speed * delta_time; + camera.position.z += cos_pitch * self.speed * delta_time; return true; } Key::Character("S") | Key::Named(NamedKey::ArrowDown) => { - camera.minus_x(sin_pitch * self.speed * delta_time); - camera.minus_z(cos_pitch * self.speed * delta_time); + camera.position.x -= sin_pitch * self.speed * delta_time; + camera.position.z -= cos_pitch * self.speed * delta_time; return true; } Key::Character("A") | Key::Named(NamedKey::ArrowLeft) => { - camera.minus_x(cos_pitch * self.speed * delta_time); - camera.add_z(sin_pitch * self.speed * delta_time); + camera.position.x -= cos_pitch * self.speed * delta_time; + camera.position.x += sin_pitch * self.speed * delta_time; return true; } Key::Character("D") | Key::Named(NamedKey::ArrowRight) => { - camera.add_x(cos_pitch * self.speed * delta_time); - camera.minus_z(sin_pitch * self.speed * delta_time); + camera.position.x += cos_pitch * self.speed * delta_time; + camera.position.z -= sin_pitch * self.speed * delta_time; return true; } Key::Named(NamedKey::Space) => { - camera.add_y(self.speed * delta_time); + camera.position.y += self.speed * delta_time; return true; } Key::Named(NamedKey::Shift) => { - camera.minus_y(self.speed * delta_time); + camera.position.y -= self.speed * delta_time; return true; } _ => return false, @@ -74,6 +77,7 @@ impl CameraController3D { button: &winit::event::MouseButton, state: &winit::event::ElementState, ) { + print!("aaa"); if button == &winit::event::MouseButton::Left { self.mouse_left_down = state == &winit::event::ElementState::Pressed; window.set_cursor_visible(!self.mouse_left_down); @@ -92,8 +96,8 @@ impl CameraController3D { let moveposition = deltaposition * glam::vec2(self.sensitivity_x, self.sensitivity_y) * delta_time; - camera.add_yaw(moveposition.x); - camera.add_pitch(moveposition.y); + camera.rotation.x += moveposition.x; + camera.rotation.y += moveposition.y; } } } diff --git a/crates/vent-runtime/src/render/camera/mod.rs b/crates/vent-runtime/src/render/camera/mod.rs index d69a5d8..f92ca03 100644 --- a/crates/vent-runtime/src/render/camera/mod.rs +++ b/crates/vent-runtime/src/render/camera/mod.rs @@ -2,7 +2,7 @@ use std::mem::size_of; use ash::vk; use downcast_rs::{impl_downcast, Downcast}; -use glam::{Quat, Vec3}; +use glam::Vec3; use vent_rendering::{buffer::VulkanBuffer, instance::VulkanInstance}; use super::{d3::UBO3D, Dimension}; @@ -10,18 +10,24 @@ use super::{d3::UBO3D, Dimension}; pub mod camera_controller3d; pub trait Camera: Downcast { - fn new(instance: &VulkanInstance) -> Self + fn new(instance: &VulkanInstance, aspect_ratio: f32) -> Self where Self: Sized; + fn recreate_projection(&mut self, aspect_ratio: f32); + fn destroy(&mut self, pool: vk::DescriptorPool, device: &ash::Device); } impl_downcast!(Camera); -pub fn from_dimension(instance: &VulkanInstance, dimension: &Dimension) -> Box { +pub fn from_dimension( + instance: &VulkanInstance, + aspect_ratio: f32, + dimension: &Dimension, +) -> Box { match dimension { - Dimension::D2 => Box::new(Camera2D::new(instance)), - Dimension::D3 => Box::new(Camera3D::new(instance)), + Dimension::D2 => Box::new(Camera2D::new(instance, aspect_ratio)), + Dimension::D3 => Box::new(Camera3D::new(instance, aspect_ratio)), } } @@ -33,7 +39,7 @@ pub struct Camera2D { impl Camera for Camera2D { #[inline] #[must_use] - fn new(_instance: &VulkanInstance) -> Self + fn new(_instance: &VulkanInstance, _aspect_ratio: f32) -> Self where Self: Sized, { @@ -42,7 +48,11 @@ impl Camera for Camera2D { } } - fn destroy(&mut self, pool: vk::DescriptorPool, device: &ash::Device) { + fn destroy(&mut self, _pool: vk::DescriptorPool, _device: &ash::Device) { + todo!() + } + + fn recreate_projection(&mut self, _aspect_ratio: f32) { todo!() } } @@ -54,28 +64,29 @@ pub struct Camera3D { ubo: UBO3D, pub ubo_buffers: Vec, - position: glam::Vec3, - rotation: glam::Quat, + pub position: glam::Vec3, + pub rotation: glam::Quat, } impl Camera for Camera3D { #[inline] #[must_use] - fn new(instance: &VulkanInstance) -> Self + fn new(instance: &VulkanInstance, aspect_ratio: f32) -> Self where Self: Sized, { let mut ubo_buffers = vec![]; for _ in 0..instance.swapchain_images.len() { - ubo_buffers.push(VulkanBuffer::new( + ubo_buffers.push(VulkanBuffer::new_init( &instance.device, &instance.memory_allocator, size_of::() as vk::DeviceSize, vk::BufferUsageFlags::UNIFORM_BUFFER, + &[UBO3D::default()], )) } - Self { + let mut cam = Self { fovy: 60.0, znear: 0.1, zfar: 10000.0, @@ -83,111 +94,41 @@ impl Camera for Camera3D { position: Vec3::ZERO, ubo: Default::default(), ubo_buffers, - } + }; + // we should configure + cam.recreate_projection(aspect_ratio); + cam.recreate_view(); + + cam } - fn destroy(&mut self, pool: vk::DescriptorPool, device: &ash::Device) { + fn destroy(&mut self, _pool: vk::DescriptorPool, device: &ash::Device) { self.ubo_buffers.iter_mut().for_each(|f| f.destroy(device)) } + + fn recreate_projection(&mut self, aspect_ratio: f32) { + let projection = + glam::Mat4::perspective_rh(self.fovy.to_radians(), aspect_ratio, self.znear, self.zfar); + self.ubo.projection = projection; + } } impl Camera3D { pub fn update_set() {} - fn recreate_view(&mut self) { + pub fn recreate_view(&mut self) { let view = - glam::Mat4::look_to_lh(self.position, self.direction_from_rotation(), glam::Vec3::Y); - self.ubo.view_position = self.position.to_array(); - self.ubo.view = view.to_cols_array_2d(); - } - - pub fn recreate_projection(&mut self, aspect_ratio: f32) { - let projection = - glam::Mat4::perspective_lh(self.fovy.to_radians(), aspect_ratio, self.znear, self.zfar); - self.ubo.projection = projection.to_cols_array_2d(); + glam::Mat4::look_at_rh(self.position, self.direction_from_rotation(), glam::Vec3::Y); + self.ubo.view_position = self.position; + self.ubo.view = view; } pub fn write(&self, instance: &VulkanInstance, index: u32) { - unsafe { - self.ubo_buffers[index as usize].upload_type( - &instance.device, - &self.ubo, - size_of::() as vk::DeviceSize, - ) - } - } - - pub fn set_x(&mut self, x: f32) { - self.position.x = x; - self.recreate_view(); - } - - pub fn set_y(&mut self, y: f32) { - self.position.y = y; - self.recreate_view(); - } - - pub fn set_z(&mut self, z: f32) { - self.position.z = z; - self.recreate_view(); - } - - pub fn add_x(&mut self, x: f32) { - self.position.x += x; - self.recreate_view(); - } - - pub fn add_y(&mut self, y: f32) { - self.position.y += y; - self.recreate_view(); - } - - pub fn add_z(&mut self, z: f32) { - self.position.z += z; - self.recreate_view(); - } - - pub fn minus_x(&mut self, x: f32) { - self.position.x -= x; - self.recreate_view(); - } - - pub fn minus_y(&mut self, y: f32) { - self.position.y -= y; - self.recreate_view(); - } - - pub fn minus_z(&mut self, z: f32) { - self.position.z -= z; - self.recreate_view(); - } - - pub fn position(&self) -> Vec3 { - self.position - } - - pub fn set_yaw(&mut self, yaw: f32) { - self.rotation.x = yaw; - self.recreate_view(); - } - - pub fn set_pitch(&mut self, pitch: f32) { - self.rotation.y = pitch; - self.recreate_view(); - } - - pub fn add_yaw(&mut self, yaw: f32) { - self.rotation.x += yaw; - self.recreate_view(); - } - - pub fn add_pitch(&mut self, pitch: f32) { - self.rotation.y += pitch; - self.recreate_view(); - } - - pub fn rotation(&self) -> Quat { - self.rotation + self.ubo_buffers[index as usize].upload_type( + &instance.device, + &self.ubo, + size_of::() as vk::DeviceSize, + ) } pub fn ubo(&self) -> UBO3D { diff --git a/crates/vent-runtime/src/render/d3/light_renderer.rs b/crates/vent-runtime/src/render/d3/light_renderer.rs index 1f16958..9f4aa22 100644 --- a/crates/vent-runtime/src/render/d3/light_renderer.rs +++ b/crates/vent-runtime/src/render/d3/light_renderer.rs @@ -1,15 +1,12 @@ +use glam::Vec3; use vent_assets::Mesh3D; use crate::render::model_renderer::ModelRenderer3D; #[derive(Copy, Clone)] pub struct LightUBO { - pub position: [f32; 3], - // Due to uniforms requiring 16 byte (4 float) spacing, we need to use a padding field here - // _padding: u32, - pub color: [f32; 3], - // Due to uniforms requiring 16 byte (4 float) spacing, we need to use a padding field here - // _padding2: u32, + pub position: Vec3, + pub color: Vec3, } #[allow(dead_code)] @@ -23,10 +20,10 @@ pub struct LightRenderer { #[allow(dead_code)] impl LightRenderer { - pub fn new(device: &ash::Device, model_renderer: &ModelRenderer3D) -> Self { + pub fn new(_device: &ash::Device, _model_renderer: &ModelRenderer3D) -> Self { let light_uniform = LightUBO { - position: [2.0, 100.0, 2.0], - color: [1.0, 1.0, 1.0], + position: [2.0, 100.0, 2.0].into(), + color: [1.0, 1.0, 1.0].into(), }; // let light_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { diff --git a/crates/vent-runtime/src/render/d3/mod.rs b/crates/vent-runtime/src/render/d3/mod.rs index 1156f99..493535b 100644 --- a/crates/vent-runtime/src/render/d3/mod.rs +++ b/crates/vent-runtime/src/render/d3/mod.rs @@ -1,13 +1,11 @@ use std::mem::size_of; use ash::vk; -use glam::Mat4; +use glam::{Mat4, Vec3, Vec4}; use vent_assets::Mesh3D; use vent_ecs::world::World; -use vent_rendering::{ - buffer::VulkanBuffer, image::VulkanImage, instance::VulkanInstance, Vertex, Vertex3D, -}; +use vent_rendering::{buffer::VulkanBuffer, instance::VulkanInstance, Vertex, Vertex3D}; use winit::dpi::PhysicalSize; use self::light_renderer::LightUBO; @@ -23,16 +21,15 @@ pub mod light_renderer; #[derive(Clone, Copy)] pub struct MaterialUBO { - pub base_color: [f32; 4], + pub base_color: Vec4, } #[derive(Clone, Copy)] pub struct UBO3D { - pub view_position: [f32; 3], - // pub _padding: u32, - pub projection: [[f32; 4]; 4], - pub view: [[f32; 4]; 4], - pub transformation: [[f32; 4]; 4], + pub view_position: Vec3, + pub projection: Mat4, + pub view: Mat4, + pub transformation: Mat4, } impl Default for UBO3D { @@ -41,7 +38,7 @@ impl Default for UBO3D { view_position: Default::default(), projection: Default::default(), view: Default::default(), - transformation: Mat4::IDENTITY.to_cols_array_2d(), + transformation: Mat4::IDENTITY, } } } @@ -50,9 +47,7 @@ pub struct Renderer3D { mesh_renderer: ModelRenderer3D, // light_renderer: LightRenderer, tmp_light_mesh: Mesh3D, - // bind_group: wgpu::BindGroup, // depth_view: wgpu::TextureView, - // uniform_buf: wgpu::Buffer, pipeline: vk::Pipeline, // pipeline_wire: Option, } @@ -90,7 +85,6 @@ impl Renderer for Renderer3D { "/res/models/test/Sponza-GLTF/Sponza.gltf" ); - pollster::block_on(async { let mut mesh = Entity3D::new(vent_assets::Model3D::load(instance, model).await); for mesh in mesh.rendering_model.meshes.iter_mut() { @@ -106,30 +100,26 @@ impl Renderer for Renderer3D { let mut light_buffers = vec![]; for _ in 0..instance.swapchain_images.len() { - let buffer = unsafe { - VulkanBuffer::new_init_type( - &instance.device, - &instance.memory_allocator, - size_of::() as vk::DeviceSize, - vk::BufferUsageFlags::UNIFORM_BUFFER, - &MaterialUBO { - base_color: material.base_color, - }, - ) - }; + let buffer = VulkanBuffer::new_init_type( + &instance.device, + &instance.memory_allocator, + size_of::() as vk::DeviceSize, + vk::BufferUsageFlags::UNIFORM_BUFFER, + &MaterialUBO { + base_color: Vec4::from_array(material.base_color), + }, + ); material_buffers.push(buffer); - let buffer = unsafe { - VulkanBuffer::new_init_type( - &instance.device, - &instance.memory_allocator, - size_of::() as vk::DeviceSize, - vk::BufferUsageFlags::UNIFORM_BUFFER, - &LightUBO { - position: [2.0, 100.0, 2.0], - color: [1.0, 1.0, 1.0], - }, - ) - }; + let buffer = VulkanBuffer::new_init_type( + &instance.device, + &instance.memory_allocator, + size_of::() as vk::DeviceSize, + vk::BufferUsageFlags::UNIFORM_BUFFER, + &LightUBO { + position: [2.0, 100.0, 2.0].into(), + color: [1.0, 1.0, 1.0].into(), + }, + ); light_buffers.push(buffer) } @@ -198,7 +188,6 @@ impl Renderer for Renderer3D { unsafe { instance.device.update_descriptor_sets(&desc_sets, &[]); } - } mesh.set_descriptor_set(descriptor_sets); } @@ -207,126 +196,8 @@ impl Renderer for Renderer3D { mesh_renderer.insert(world.create_entity(), mesh); }); - // Record Command Buffers - let render_area = vk::Rect2D::builder() - .offset(vk::Offset2D::default()) - .extent(instance.surface_resolution) - .build(); - - let color_clear_value = vk::ClearValue { - color: vk::ClearColorValue { - float32: [0.5, 0.5, 0.5, 1.0], - }, - }; - - let depth_clear_value = vk::ClearValue { - depth_stencil: vk::ClearDepthStencilValue { - depth: 1.0, - stencil: 0, - }, - }; - - let clear_values = &[color_clear_value, depth_clear_value]; - - for (i, command_buffer) in instance.command_buffers.iter().enumerate() { - unsafe { - let info = vk::CommandBufferBeginInfo::default(); - - instance.device.begin_command_buffer(*command_buffer, &info); - - let info = vk::RenderPassBeginInfo::builder() - .render_pass(instance.render_pass) - .framebuffer(instance.frame_buffers[i]) - .render_area(render_area) - .clear_values(clear_values); - - let subpass_info = - vk::SubpassBeginInfo::builder().contents(vk::SubpassContents::INLINE); - - instance - .device - .cmd_begin_render_pass2(*command_buffer, &info, &subpass_info); - instance.device.cmd_bind_pipeline( - *command_buffer, - vk::PipelineBindPoint::GRAPHICS, - pipeline, - ); - - // instance.device.cmd_bind_descriptor_sets( - // *command_buffer, - // vk::PipelineBindPoint::GRAPHICS, - // instance.pipeline_layout, - // 0, - // &descriptor_sets, - // &[], - // ); - - instance - .device - .cmd_set_scissor(*command_buffer, 0, &[render_area]); - - let viewport = vk::Viewport::builder() - .height(instance.surface_resolution.height as f32) - .width(instance.surface_resolution.width as f32) - .max_depth(1.0); - instance - .device - .cmd_set_viewport(*command_buffer, 0, &[*viewport]); - - mesh_renderer.record_buffer( - instance, - *command_buffer, - i, - instance.pipeline_layout, - &mut camera.ubo(), - ); - - // END - let subpass_end_info = vk::SubpassEndInfo::default(); - instance - .device - .cmd_end_render_pass2(*command_buffer, &subpass_end_info); - instance.device.end_command_buffer(*command_buffer); - } - } - - // // Create pipeline layout - // let vertex_group_layout = - // device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - // label: Some("3D Bind Group Layout"), - // entries: &[wgpu::BindGroupLayoutEntry { - // binding: 0, - // visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, - // ty: wgpu::BindingType::Buffer { - // ty: wgpu::BufferBindingType::Uniform, - // has_dynamic_offset: false, - // min_binding_size: wgpu::BufferSize::new( - // mem::size_of::() as wgpu::BufferAddress - // ), - // }, - // count: None, - // }], - // }); - - // let light_renderer = LightRenderer::new(device, &vertex_group_layout, config.format); - - // // Create other resources - // let ubo = camera.ubo(); - // let uniform_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - // label: Some("Uniform Buffer"), - // contents: bytemuck::bytes_of(&ubo), - // usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, - // }); - let tmp_light_mesh = create_tmp_cube(instance); - // let depth_view = vent_assets::Texture::create_depth_view( - // device, - // config.width, - // config.height, - // Some("Depth Buffer"), - // ); - Self { mesh_renderer, // light_renderer, @@ -345,32 +216,100 @@ impl Renderer for Renderer3D { _new_size: &PhysicalSize, _camera: &mut dyn Camera, ) { - // self.depth_view = vent_assets::Texture::create_depth_view( - // device, - // config.width, - // config.height, - // Some("Depth Buffer"), - // ); - - // let camera: &mut Camera3D = camera.downcast_mut().unwrap(); - - // camera.recreate_projection(config.width as f32 / config.height as f32); - // queue.write_buffer(&self.uniform_buf, 0, bytemuck::cast_slice(&[camera.ubo()])); + // TODO recreate depth image } fn render(&mut self, instance: &VulkanInstance, image_index: u32, camera: &mut dyn Camera) { let camera: &mut Camera3D = camera.downcast_mut().unwrap(); - let _ubo = camera.ubo(); + camera.recreate_view(); + camera.write(instance, image_index as u32); - // self.light_renderer - // .render(&mut rpass, &self.bind_group, &self.tmp_light_mesh); + let image_index = image_index as usize; - // rpass.set_bind_group(0, &self.bind_group, &[]); - // rpass.set_bind_group(2, &self.light_renderer.light_bind_group, &[]); + let command_buffer = instance.command_buffers[image_index]; + + let render_area = vk::Rect2D::builder() + .offset(vk::Offset2D::default()) + .extent(instance.surface_resolution) + .build(); - // } - camera.write(instance, image_index) + let color_clear_value = vk::ClearValue { + color: vk::ClearColorValue { + float32: [0.5, 0.5, 0.5, 1.0], + }, + }; + + let depth_clear_value = vk::ClearValue { + depth_stencil: vk::ClearDepthStencilValue { + depth: 1.0, + stencil: 0, + }, + }; + + let clear_values = &[color_clear_value, depth_clear_value]; + + unsafe { + instance + .device + .reset_command_buffer( + command_buffer, + vk::CommandBufferResetFlags::RELEASE_RESOURCES, + ) + .unwrap(); + + let info = vk::CommandBufferBeginInfo::default(); + + instance + .device + .begin_command_buffer(command_buffer, &info) + .unwrap(); + + let info = vk::RenderPassBeginInfo::builder() + .render_pass(instance.render_pass) + .framebuffer(instance.frame_buffers[image_index]) + .render_area(render_area) + .clear_values(clear_values); + + let subpass_info = + vk::SubpassBeginInfo::builder().contents(vk::SubpassContents::INLINE); + + instance + .device + .cmd_begin_render_pass2(command_buffer, &info, &subpass_info); + instance.device.cmd_bind_pipeline( + command_buffer, + vk::PipelineBindPoint::GRAPHICS, + self.pipeline, + ); + + instance + .device + .cmd_set_scissor(command_buffer, 0, &[render_area]); + + let viewport = vk::Viewport::builder() + .height(instance.surface_resolution.height as f32) + .width(instance.surface_resolution.width as f32) + .max_depth(1.0); + instance + .device + .cmd_set_viewport(command_buffer, 0, &[*viewport]); + + self.mesh_renderer.record_buffer( + instance, + command_buffer, + image_index, + instance.pipeline_layout, + &mut camera.ubo(), + ); + + // END + let subpass_end_info = vk::SubpassEndInfo::default(); + instance + .device + .cmd_end_render_pass2(command_buffer, &subpass_end_info); + instance.device.end_command_buffer(command_buffer).unwrap(); + } } fn destroy(&mut self, instance: &VulkanInstance) { @@ -381,82 +320,6 @@ impl Renderer for Renderer3D { } } -// fn write_sets( -// instance: &VulkanInstance, -// diffuse_texture: VulkanImage, -// uniforms_buffers: &Vec, -// ) -> Vec { -// let descriptor_sets = VulkanInstance::allocate_descriptor_sets( -// &instance.device, -// instance.descriptor_pool, -// instance.descriptor_set_layout, -// uniforms_buffers.len(), -// ); - -// for (i, &_descritptor_set) in descriptor_sets.iter().enumerate() { -// let image_info = vk::DescriptorImageInfo::builder() -// .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) -// .image_view(diffuse_texture.image_view) -// .sampler(diffuse_texture.sampler) -// .build(); - -// let material_buffer_info = vk::DescriptorBufferInfo::builder() -// .buffer(uniforms_buffers[i].buffer) -// .offset(0) -// .range(size_of::() as vk::DeviceSize) -// .build(); - -// let light_buffer_info = vk::DescriptorBufferInfo::builder() -// .buffer(uniforms_buffers[i].buffer) -// .offset(0) -// .range(size_of::() as vk::DeviceSize) -// .build(); - -// let desc_sets = [ -// // Vertex -// vk::WriteDescriptorSet { -// dst_set: descriptor_sets[0], -// dst_binding: 0, -// descriptor_count: 1, -// descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, -// p_buffer_info: &buffer_info, -// ..Default::default() -// }, -// // Fragment -// vk::WriteDescriptorSet { -// dst_set: descriptor_sets[0], -// descriptor_count: 1, -// descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, -// p_image_info: &image_info, -// ..Default::default() -// }, -// vk::WriteDescriptorSet { -// dst_set: descriptor_sets[0], -// dst_binding: 1, -// descriptor_count: 1, -// descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, -// p_buffer_info: &material_buffer_info, -// ..Default::default() -// }, -// vk::WriteDescriptorSet { -// dst_set: descriptor_sets[0], -// dst_binding: 2, -// descriptor_count: 1, -// descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, -// p_buffer_info: &light_buffer_info, -// ..Default::default() -// }, -// ]; - -// unsafe { -// instance -// .device -// .update_descriptor_sets(&fragment_desc_sets, &[]); -// } -// } -// descriptor_sets -// } - fn create_tmp_cube(instance: &VulkanInstance) -> vent_assets::Mesh3D { let indices = [ //Top diff --git a/crates/vent-runtime/src/render/gui/gui_renderer.rs b/crates/vent-runtime/src/render/gui/gui_renderer.rs index 7c4d531..d301e51 100644 --- a/crates/vent-runtime/src/render/gui/gui_renderer.rs +++ b/crates/vent-runtime/src/render/gui/gui_renderer.rs @@ -7,6 +7,12 @@ pub struct EguiRenderer { guis: Vec>, } +impl Default for EguiRenderer { + fn default() -> Self { + Self::new() + } +} + impl EguiRenderer { pub fn new() -> Self { //let renderer = egui_winit_ash_integration::Integration::new(event_loop, ); diff --git a/crates/vent-runtime/src/render/mod.rs b/crates/vent-runtime/src/render/mod.rs index e0104b6..f0370f1 100644 --- a/crates/vent-runtime/src/render/mod.rs +++ b/crates/vent-runtime/src/render/mod.rs @@ -1,6 +1,5 @@ use std::time::{Duration, Instant}; -use ash::vk; use vent_rendering::instance::VulkanInstance; use winit::dpi::PhysicalSize; use winit::window::Window; @@ -33,7 +32,12 @@ impl DefaultRuntimeRenderer { event_loop: &winit::event_loop::EventLoopWindowTarget<()>, ) -> Self { let instance = VulkanInstance::new("TODO", window); - let mut camera = from_dimension(&instance, &dimension); + let window_size = window.inner_size(); + let mut camera = from_dimension( + &instance, + (window_size.width / window_size.height) as f32, + &dimension, + ); let runtime_renderer = RawRuntimeRenderer::new(dimension, &instance, event_loop, camera.as_mut()); Self { @@ -53,6 +57,9 @@ impl DefaultRuntimeRenderer { } pub(crate) fn resize(&mut self, new_size: &PhysicalSize) { + log::info!("Resizing to {:?} ", new_size); + self.camera + .recreate_projection((new_size.width / new_size.width) as f32); self.runtime_renderer .resize(&self.instance, new_size, self.camera.as_mut()); } @@ -143,7 +150,7 @@ impl RawRuntimeRenderer { self.multi_renderer.render(instance, image_index, camera); instance.submit(image_index); } - Err(err) => { + Err(_err) => { // if err == vk::Result::ERROR_OUT_OF_DATE_KHR { // self.resize(instance, instance.surface_resolution, camera) // } else if err == vk::Result::ERROR_SURFACE_LOST_KHR { diff --git a/crates/vent-runtime/src/render/model_renderer.rs b/crates/vent-runtime/src/render/model_renderer.rs index 2d6c30f..0b72828 100644 --- a/crates/vent-runtime/src/render/model_renderer.rs +++ b/crates/vent-runtime/src/render/model_renderer.rs @@ -56,7 +56,7 @@ impl ModelRenderer3D { ubo: &mut UBO3D, ) { for model in self.map.values() { - ubo.transformation = Self::calc_trans_matrix(model).to_cols_array_2d(); + ubo.transformation = Self::calc_trans_matrix(model); model.rendering_model.draw( &instance.device, pipeline_layout, From 0b78804a80f73514984d3ccaab859282b3de5d60 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev <71594357+Snowiiii@users.noreply.github.com> Date: Sun, 31 Dec 2023 13:36:32 +0100 Subject: [PATCH 09/14] Cargo clippy --fix --- crates/vent-assets/src/model/gltf.rs | 15 +++++---------- crates/vent-assets/src/model/mod.rs | 5 ++--- crates/vent-rendering/src/debug.rs | 2 +- crates/vent-runtime/src/render/d3/mod.rs | 2 +- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/crates/vent-assets/src/model/gltf.rs b/crates/vent-assets/src/model/gltf.rs index 8de95a2..1c771a6 100644 --- a/crates/vent-assets/src/model/gltf.rs +++ b/crates/vent-assets/src/model/gltf.rs @@ -2,10 +2,7 @@ use std::{ fs::{self, File}, io::BufReader, path::Path, - sync::{ - self, - mpsc::{channel, sync_channel}, - }, + sync::{self}, thread, }; @@ -86,7 +83,7 @@ impl GLTFLoader { tx.send((material_data, primitive)).unwrap(); }); - }; + } }); for _ in 0..primitive_len { let (material_data, primitive) = rx.recv().unwrap(); @@ -117,14 +114,12 @@ impl GLTFLoader { let diffuse_texture = if let Some(texture) = pbr.base_color_texture() { match texture.texture().source().source() { - gltf::image::Source::View { - view, - mime_type, - } => { + gltf::image::Source::View { view, mime_type } => { let sampler = texture.texture().sampler(); let image = image::load_from_memory_with_format( &buffer_data[view.buffer().index()], - image::ImageFormat::from_mime_type(mime_type).expect("TODO: Error Handling"), + image::ImageFormat::from_mime_type(mime_type) + .expect("TODO: Error Handling"), ) .unwrap(); (image, Some(sampler)) diff --git a/crates/vent-assets/src/model/mod.rs b/crates/vent-assets/src/model/mod.rs index 6af50e0..d1f240d 100644 --- a/crates/vent-assets/src/model/mod.rs +++ b/crates/vent-assets/src/model/mod.rs @@ -1,4 +1,3 @@ -use std::mem::size_of; use std::path::Path; use ash::vk; @@ -93,7 +92,7 @@ impl Mesh3D { let vertex_buf = VulkanBuffer::new_init( device, allocator, - (size_of::() * vertices.len()) as vk::DeviceSize, + std::mem::size_of_val(vertices) as vk::DeviceSize, vk::BufferUsageFlags::VERTEX_BUFFER, vertices, ); @@ -101,7 +100,7 @@ impl Mesh3D { let index_buf = VulkanBuffer::new_init( device, allocator, - (size_of::() * indices.len()) as vk::DeviceSize, + std::mem::size_of_val(indices) as vk::DeviceSize, vk::BufferUsageFlags::INDEX_BUFFER, indices, ); diff --git a/crates/vent-rendering/src/debug.rs b/crates/vent-rendering/src/debug.rs index 160270a..8420285 100644 --- a/crates/vent-rendering/src/debug.rs +++ b/crates/vent-rendering/src/debug.rs @@ -77,7 +77,7 @@ pub fn get_validation_features() -> vk::ValidationFeaturesEXT { .enabled_validation_features(&features) .build(); } else { - return vk::ValidationFeaturesEXT::default(); + vk::ValidationFeaturesEXT::default() } } diff --git a/crates/vent-runtime/src/render/d3/mod.rs b/crates/vent-runtime/src/render/d3/mod.rs index 493535b..8359297 100644 --- a/crates/vent-runtime/src/render/d3/mod.rs +++ b/crates/vent-runtime/src/render/d3/mod.rs @@ -223,7 +223,7 @@ impl Renderer for Renderer3D { let camera: &mut Camera3D = camera.downcast_mut().unwrap(); camera.recreate_view(); - camera.write(instance, image_index as u32); + camera.write(instance, image_index); let image_index = image_index as usize; From b253bbaec4bbe545cdb8b59a66fafc2247e0c575 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev <71594357+Snowiiii@users.noreply.github.com> Date: Sun, 31 Dec 2023 13:40:28 +0100 Subject: [PATCH 10/14] Fix compile warn --- crates/vent-assets/src/model/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/vent-assets/src/model/mod.rs b/crates/vent-assets/src/model/mod.rs index d1f240d..4ed9b0d 100644 --- a/crates/vent-assets/src/model/mod.rs +++ b/crates/vent-assets/src/model/mod.rs @@ -152,7 +152,7 @@ impl Mesh3D { self.vertex_buf.destroy(device); self.index_buf.destroy(device); if let Some(descriptor_set) = &mut self.descriptor_set { - unsafe { device.free_descriptor_sets(descriptor_pool, descriptor_set) }; + unsafe { device.free_descriptor_sets(descriptor_pool, descriptor_set).expect("Failed to free Model descriptor sets") }; } if let Some(material) = &mut self.material { material.diffuse_texture.destroy(device); From bf6a7d5357a8875272fca1080cc2b9734b30f4ce Mon Sep 17 00:00:00 2001 From: Alexander Medvedev <71594357+Snowiiii@users.noreply.github.com> Date: Sun, 31 Dec 2023 14:19:05 +0100 Subject: [PATCH 11/14] Fix macOS error --- Cargo.lock | 43 ++++++++++++++++++++++++++++++++ crates/vent-rendering/Cargo.toml | 5 +++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index e1cf032..0301db7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -349,6 +349,36 @@ dependencies = [ "winapi", ] +[[package]] +name = "cocoa" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6140449f97a6e97f9511815c5632d84c8aacf8ac271ad77c559218161a1373c" +dependencies = [ + "bitflags 1.3.2", + "block", + "cocoa-foundation", + "core-foundation", + "core-graphics 0.23.1", + "foreign-types 0.5.0", + "libc", + "objc", +] + +[[package]] +name = "cocoa-foundation" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c6234cbb2e4c785b456c0644748b1ac416dd045799740356f8363dfe00c93f7" +dependencies = [ + "bitflags 1.3.2", + "block", + "core-foundation", + "core-graphics-types", + "libc", + "objc", +] + [[package]] name = "color_quant" version = "1.1.0" @@ -1617,6 +1647,18 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42a9830a0e1b9fb145ebb365b8bc4ccd75f290f98c0247deafbbe2c75cefb544" +[[package]] +name = "raw-window-metal" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76e8caa82e31bb98fee12fa8f051c94a6aa36b07cddb03f0d4fc558988360ff1" +dependencies = [ + "cocoa", + "core-graphics 0.23.1", + "objc", + "raw-window-handle 0.6.0", +] + [[package]] name = "rayon" version = "1.8.0" @@ -2216,6 +2258,7 @@ dependencies = [ "image", "log", "raw-window-handle 0.6.0", + "raw-window-metal", "winit 0.29.7", ] diff --git a/crates/vent-rendering/Cargo.toml b/crates/vent-rendering/Cargo.toml index d29a0c9..1ddbf25 100644 --- a/crates/vent-rendering/Cargo.toml +++ b/crates/vent-rendering/Cargo.toml @@ -10,6 +10,9 @@ ash = { version= "0.37.3", default-features = false, features = ["linked", "debu image = "0.24.7" -winit = "0.29.6" +winit = "0.29.7" raw-window-handle = "0.6" log = "0.4" + +[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] +raw-window-metal = "0.4" From d1030959a480b07643f7c1a5bc0b2eb57c6fcaf4 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev <71594357+Snowiiii@users.noreply.github.com> Date: Sun, 31 Dec 2023 14:43:20 +0100 Subject: [PATCH 12/14] Add Vulkan into CI --- .github/workflows/rust.yml | 7 +++++++ crates/vent-runtime/res/shaders/app/3D/wireframe.wgsl | 4 ---- 2 files changed, 7 insertions(+), 4 deletions(-) delete mode 100644 crates/vent-runtime/res/shaders/app/3D/wireframe.wgsl diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9cfa5c4..501a039 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,6 +21,13 @@ jobs: steps: - uses: actions/checkout@v4 + + - name: Prepare Vulkan + uses: humbletim/setup-vulkan-sdk@v1.2.0 + with: + vulkan-query-version: 1.3.268.0 + vulkan-components: Glslang + vulkan-use-cache: true - name: Setup Rust toolchain uses: actions-rust-lang/setup-rust-toolchain@v1.5.0 diff --git a/crates/vent-runtime/res/shaders/app/3D/wireframe.wgsl b/crates/vent-runtime/res/shaders/app/3D/wireframe.wgsl deleted file mode 100644 index ac99558..0000000 --- a/crates/vent-runtime/res/shaders/app/3D/wireframe.wgsl +++ /dev/null @@ -1,4 +0,0 @@ -@fragment -fn fs_main() -> @location(0) vec4 { - return vec4(0.0, 0.5, 0.0, 0.5); -} \ No newline at end of file From 3ccdfb4fae69068c1d10dcc95503f145ad985e03 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev <71594357+Snowiiii@users.noreply.github.com> Date: Sun, 31 Dec 2023 14:48:30 +0100 Subject: [PATCH 13/14] Update rust.yml --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 501a039..8ee74f1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -26,7 +26,7 @@ jobs: uses: humbletim/setup-vulkan-sdk@v1.2.0 with: vulkan-query-version: 1.3.268.0 - vulkan-components: Glslang + vulkan-components: SPIRV-Tools, Glslang vulkan-use-cache: true - name: Setup Rust toolchain From 4bb56945d92d0c30d417bf9107b6c4cbea189083 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev <71594357+Snowiiii@users.noreply.github.com> Date: Sun, 31 Dec 2023 15:02:50 +0100 Subject: [PATCH 14/14] Remove Vulkan CI --- .github/workflows/rust.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8ee74f1..bf499fe 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -22,13 +22,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Prepare Vulkan - uses: humbletim/setup-vulkan-sdk@v1.2.0 - with: - vulkan-query-version: 1.3.268.0 - vulkan-components: SPIRV-Tools, Glslang - vulkan-use-cache: true - - name: Setup Rust toolchain uses: actions-rust-lang/setup-rust-toolchain@v1.5.0 - name: Run test