Compare commits

..

No commits in common. "960e2f8a379ecc875dccd28b81822cd96a48b10d" and "440fc05e55d662ee833f30276c552e89995a912b" have entirely different histories.

40 changed files with 1195 additions and 4536 deletions

309
Cargo.lock generated
View file

@ -59,7 +59,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee91c0c2905bae44f84bfa4e044536541df26b7703fd0888deeb9060fcc44289"
dependencies = [
"android-properties",
"bitflags 2.5.0",
"bitflags 2.4.2",
"cc",
"cesu8",
"jni",
@ -180,9 +180,9 @@ checksum = "41e67cd8309bbd06cd603a9e693a784ac2e5d1e955f11286e355089fcab3047c"
[[package]]
name = "autocfg"
version = "1.2.0"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "av1-grain"
@ -209,9 +209,9 @@ dependencies = [
[[package]]
name = "backtrace"
version = "0.3.71"
version = "0.3.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d"
checksum = "95d8e92cac0961e91dbd517496b00f7e9b92363dbe6d42c3198268323798860c"
dependencies = [
"addr2line",
"cc",
@ -245,9 +245,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.5.0"
version = "2.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf"
[[package]]
name = "bitmaps"
@ -329,9 +329,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
version = "1.6.0"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
[[package]]
name = "calloop"
@ -339,7 +339,7 @@ version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fba7adb4dd5aa98e5553510223000e7148f621165ec5f9acd7113f6ca4995298"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.4.2",
"log",
"polling",
"rustix",
@ -651,19 +651,6 @@ dependencies = [
"nohash-hasher",
]
[[package]]
name = "egui-vulkano"
version = "0.1.0"
dependencies = [
"ahash",
"egui",
"egui-winit",
"image",
"vulkano",
"vulkano-shaders",
"winit",
]
[[package]]
name = "egui-winit"
version = "0.27.1"
@ -797,7 +784,7 @@ checksum = "d9e93fc013ea9e562aadd71884c5ebfb84f7cac39e691759e281bbc14552709d"
dependencies = [
"anyhow",
"atomic_refcell",
"bitflags 2.5.0",
"bitflags 2.4.2",
"erased-serde",
"flax-derive",
"flume",
@ -818,7 +805,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d141b9bb793ce817c1ec513e93b72e4e2a6d9494b18d5c1e454fa08905586d6"
dependencies = [
"itertools 0.11.0",
"proc-macro-crate",
"proc-macro-crate 2.0.0",
"proc-macro2",
"quote",
"syn",
@ -983,12 +970,6 @@ version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "glam"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e05e7e6723e3455f4818c7b26e855439f7546cf617ef669d1adedb8669e5cb9"
[[package]]
name = "half"
version = "2.4.0"
@ -1118,9 +1099,9 @@ dependencies = [
[[package]]
name = "image"
version = "0.25.1"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd54d660e773627692c524beaad361aca785a4f9f5730ce91f42aabe5bce3d11"
checksum = "a9b4f005360d32e9325029b38ba47ebd7a56f3316df09249368939562d518645"
dependencies = [
"bytemuck",
"byteorder",
@ -1167,9 +1148,9 @@ dependencies = [
[[package]]
name = "indexmap"
version = "2.2.6"
version = "2.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4"
dependencies = [
"equivalent",
"hashbrown 0.14.3",
@ -1226,9 +1207,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "1.0.11"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
[[package]]
name = "jni"
@ -1279,94 +1260,29 @@ dependencies = [
[[package]]
name = "khors"
version = "0.1.0"
[[package]]
name = "khors-config"
version = "0.1.0"
dependencies = [
"anyhow",
"flax",
"khors-core",
"notify",
"notify-debouncer-mini",
"serde",
"serde-lexpr",
]
[[package]]
name = "khors-core"
version = "0.1.0"
dependencies = [
"anyhow",
"downcast-rs",
"egui-vulkano",
"flax",
"flume",
"parking_lot",
"vulkano",
"vulkano-util",
"winit",
]
[[package]]
name = "khors-graphics"
version = "0.1.0"
dependencies = [
"ahash",
"anyhow",
"downcast-rs",
"egui",
"egui-vulkano",
"egui-winit",
"flax",
"flume",
"glam",
"khors-core",
"image",
"notify",
"notify-debouncer-mini",
"parking_lot",
"serde",
"serde-lexpr",
"steel-core",
"steel-derive",
"tokio",
"vulkano",
"vulkano-shaders",
"vulkano-util",
"winit",
]
[[package]]
name = "khors-steel"
version = "0.1.0"
dependencies = [
"anyhow",
"flax",
"flume",
"khors-core",
"notify",
"notify-debouncer-mini",
"steel-core",
"steel-derive",
]
[[package]]
name = "khors-test"
version = "0.1.0"
dependencies = [
"anyhow",
"egui-vulkano",
"khors-config",
"khors-core",
"khors-graphics",
"khors-steel",
"khors-window",
"tokio",
"winit",
]
[[package]]
name = "khors-window"
version = "0.1.0"
dependencies = [
"anyhow",
"flax",
"khors-core",
]
[[package]]
name = "kqueue"
version = "1.0.8"
@ -1464,23 +1380,24 @@ dependencies = [
[[package]]
name = "libredox"
version = "0.0.2"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607"
checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.4.2",
"libc",
"redox_syscall 0.4.1",
]
[[package]]
name = "libredox"
version = "0.1.3"
version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.4.2",
"libc",
"redox_syscall 0.4.1",
]
[[package]]
@ -1535,9 +1452,9 @@ dependencies = [
[[package]]
name = "memchr"
version = "2.7.2"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]]
name = "memmap2"
@ -1591,7 +1508,7 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2076a31b7010b17a38c01907c45b945e8f11495ee4dd588309718901b1f7a5b7"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.4.2",
"jni-sys",
"log",
"ndk-sys",
@ -1650,7 +1567,7 @@ version = "6.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.4.2",
"crossbeam-channel",
"filetime",
"fsevent-sys",
@ -1788,7 +1705,7 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b"
dependencies = [
"proc-macro-crate",
"proc-macro-crate 3.1.0",
"proc-macro2",
"quote",
"syn",
@ -1921,9 +1838,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "pin-project-lite"
version = "0.2.14"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
[[package]]
name = "pin-utils"
@ -1952,13 +1869,12 @@ dependencies = [
[[package]]
name = "polling"
version = "3.6.0"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0c976a60b2d7e99d6f229e414670a9b85d13ac305cc6d1e9c134de58c5aaaf6"
checksum = "24f040dee2588b4963afb4e420540439d126f73fdacf4a9c486a96d840bac3c9"
dependencies = [
"cfg-if",
"concurrent-queue",
"hermit-abi",
"pin-project-lite",
"rustix",
"tracing",
@ -1984,12 +1900,20 @@ dependencies = [
[[package]]
name = "proc-macro-crate"
version = "2.0.2"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b00f26d3400549137f92511a46ac1cd8ce37cb5598a96d382381458b992a5d24"
checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8"
dependencies = [
"toml_datetime",
"toml_edit",
"toml_edit 0.20.7",
]
[[package]]
name = "proc-macro-crate"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284"
dependencies = [
"toml_edit 0.21.1",
]
[[package]]
@ -2172,9 +2096,9 @@ checksum = "42a9830a0e1b9fb145ebb365b8bc4ccd75f290f98c0247deafbbe2c75cefb544"
[[package]]
name = "rayon"
version = "1.10.0"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
checksum = "e4963ed1bc86e4f3ee217022bd855b297cef07fb9eac5dfa1f788b220b49b3bd"
dependencies = [
"either",
"rayon-core",
@ -2210,12 +2134,12 @@ dependencies = [
[[package]]
name = "redox_users"
version = "0.4.5"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891"
checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4"
dependencies = [
"getrandom",
"libredox 0.1.3",
"libredox 0.0.1",
"thiserror",
]
@ -2245,11 +2169,11 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "rustix"
version = "0.38.32"
version = "0.38.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89"
checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.4.2",
"errno",
"libc",
"linux-raw-sys",
@ -2328,9 +2252,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.115"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd"
checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0"
dependencies = [
"itoa",
"ryu",
@ -2412,15 +2336,15 @@ dependencies = [
[[package]]
name = "slabbin"
version = "1.0.1"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8305086044614627ed85432d27b87cf9fc047204eaa036a11de6cf0120f273"
checksum = "1040fc353ab4658e2094706abb1ee035506f6a4ba35af2cf16c80437866c6d96"
[[package]]
name = "smallvec"
version = "1.13.2"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
[[package]]
name = "smithay-client-toolkit"
@ -2428,7 +2352,7 @@ version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "922fd3eeab3bd820d76537ce8f582b1cf951eceb5475c28500c7457d9d17f53a"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.4.2",
"calloop",
"calloop-wayland-source",
"cursor-icon",
@ -2489,7 +2413,7 @@ dependencies = [
[[package]]
name = "steel-core"
version = "0.6.0"
source = "git+https://github.com/mattwparas/steel.git?branch=master#0c35ffcb0ebc4478ae6a68d8254e4d14f866c0d7"
source = "git+https://github.com/mattwparas/steel.git?branch=master#08c3a14a540027575f3a37f9f6dba3b4c1b48b7d"
dependencies = [
"bincode",
"chrono",
@ -2524,7 +2448,7 @@ dependencies = [
[[package]]
name = "steel-derive"
version = "0.5.0"
source = "git+https://github.com/mattwparas/steel.git?branch=master#0c35ffcb0ebc4478ae6a68d8254e4d14f866c0d7"
source = "git+https://github.com/mattwparas/steel.git?branch=master#08c3a14a540027575f3a37f9f6dba3b4c1b48b7d"
dependencies = [
"proc-macro2",
"quote",
@ -2534,7 +2458,7 @@ dependencies = [
[[package]]
name = "steel-gen"
version = "0.2.0"
source = "git+https://github.com/mattwparas/steel.git?branch=master#0c35ffcb0ebc4478ae6a68d8254e4d14f866c0d7"
source = "git+https://github.com/mattwparas/steel.git?branch=master#08c3a14a540027575f3a37f9f6dba3b4c1b48b7d"
dependencies = [
"codegen",
"serde",
@ -2544,7 +2468,7 @@ dependencies = [
[[package]]
name = "steel-parser"
version = "0.6.0"
source = "git+https://github.com/mattwparas/steel.git?branch=master#0c35ffcb0ebc4478ae6a68d8254e4d14f866c0d7"
source = "git+https://github.com/mattwparas/steel.git?branch=master#08c3a14a540027575f3a37f9f6dba3b4c1b48b7d"
dependencies = [
"fxhash",
"lasso",
@ -2570,9 +2494,9 @@ checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01"
[[package]]
name = "syn"
version = "2.0.57"
version = "2.0.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11a6ae1e52eb25aab8f3fb9fca13be982a373b8f1157ca14b897a825ba4a2d35"
checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032"
dependencies = [
"proc-macro2",
"quote",
@ -2690,9 +2614,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.37.0"
version = "1.36.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787"
checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931"
dependencies = [
"backtrace",
"bytes",
@ -2720,36 +2644,58 @@ dependencies = [
[[package]]
name = "toml"
version = "0.8.2"
version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d"
checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
"toml_edit 0.22.9",
]
[[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"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.20.2"
version = "0.20.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338"
checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81"
dependencies = [
"indexmap 2.2.6",
"indexmap 2.2.5",
"toml_datetime",
"winnow 0.5.40",
]
[[package]]
name = "toml_edit"
version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1"
dependencies = [
"indexmap 2.2.5",
"toml_datetime",
"winnow 0.5.40",
]
[[package]]
name = "toml_edit"
version = "0.22.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4"
dependencies = [
"indexmap 2.2.5",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
"winnow 0.6.5",
]
[[package]]
@ -2889,7 +2835,7 @@ dependencies = [
[[package]]
name = "vulkano"
version = "0.34.0"
source = "git+https://github.com/vulkano-rs/vulkano.git?branch=master#55556bb916dfb288f7cac5a048111954afd230d8"
source = "git+https://github.com/vulkano-rs/vulkano.git?branch=master#7cbf3a7f2694f75e44c778878b5520a45c6a2d1c"
dependencies = [
"ahash",
"ash",
@ -2898,7 +2844,7 @@ dependencies = [
"crossbeam-queue",
"half",
"heck 0.4.1",
"indexmap 2.2.6",
"indexmap 2.2.5",
"libloading 0.8.3",
"nom",
"objc",
@ -2919,9 +2865,9 @@ dependencies = [
[[package]]
name = "vulkano-macros"
version = "0.34.0"
source = "git+https://github.com/vulkano-rs/vulkano.git?branch=master#55556bb916dfb288f7cac5a048111954afd230d8"
source = "git+https://github.com/vulkano-rs/vulkano.git?branch=master#7cbf3a7f2694f75e44c778878b5520a45c6a2d1c"
dependencies = [
"proc-macro-crate",
"proc-macro-crate 2.0.0",
"proc-macro2",
"quote",
"syn",
@ -2930,7 +2876,7 @@ dependencies = [
[[package]]
name = "vulkano-shaders"
version = "0.34.0"
source = "git+https://github.com/vulkano-rs/vulkano.git?branch=master#55556bb916dfb288f7cac5a048111954afd230d8"
source = "git+https://github.com/vulkano-rs/vulkano.git?branch=master#7cbf3a7f2694f75e44c778878b5520a45c6a2d1c"
dependencies = [
"ahash",
"heck 0.4.1",
@ -2944,7 +2890,7 @@ dependencies = [
[[package]]
name = "vulkano-util"
version = "0.34.0"
source = "git+https://github.com/vulkano-rs/vulkano.git?branch=master#55556bb916dfb288f7cac5a048111954afd230d8"
source = "git+https://github.com/vulkano-rs/vulkano.git?branch=master#7cbf3a7f2694f75e44c778878b5520a45c6a2d1c"
dependencies = [
"ahash",
"vulkano",
@ -3053,7 +2999,7 @@ version = "0.31.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.4.2",
"rustix",
"wayland-backend",
"wayland-scanner",
@ -3065,7 +3011,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.4.2",
"cursor-icon",
"wayland-backend",
]
@ -3087,7 +3033,7 @@ version = "0.31.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.4.2",
"wayland-backend",
"wayland-client",
"wayland-scanner",
@ -3099,7 +3045,7 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23803551115ff9ea9bce586860c5c5a971e360825a0309264102a9495a5ff479"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.4.2",
"wayland-backend",
"wayland-client",
"wayland-protocols",
@ -3112,7 +3058,7 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.4.2",
"wayland-backend",
"wayland-client",
"wayland-protocols",
@ -3450,7 +3396,7 @@ dependencies = [
"ahash",
"android-activity",
"atomic-waker",
"bitflags 2.5.0",
"bitflags 2.4.2",
"bytemuck",
"calloop",
"cfg_aliases",
@ -3499,6 +3445,15 @@ dependencies = [
"memchr",
]
[[package]]
name = "winnow"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8"
dependencies = [
"memchr",
]
[[package]]
name = "x11-dl"
version = "2.21.0"
@ -3543,7 +3498,7 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d039de8032a9a8856a6be89cea3e5d12fdd82306ab7c94d74e6deab2460651c5"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.4.2",
"dlib",
"log",
"once_cell",
@ -3558,9 +3513,9 @@ checksum = "054a8e68b76250b253f671d1268cb7f1ae089ec35e195b2efb2a4e9a836d0621"
[[package]]
name = "xml-rs"
version = "0.8.20"
version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "791978798f0597cfc70478424c2b4fdc2b7a8024aaff78497ef00f24ef674193"
checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a"
[[package]]
name = "xmlparser"

View file

@ -5,19 +5,24 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace]
members = [
"khors-core",
"vendor/egui-vulkano",
"modules/khors-graphics",
"modules/khors-window",
"modules/khors-config",
"modules/khors-steel",
"khors-test",
]
default-members = [ "khors-test" ]
[[bin]]
name = "khors-test"
path = "./khors-test"
[dependencies]
anyhow = "1.0.80"
winit = { version = "0.29.15",features = ["rwh_05"] }
vulkano = { git = "https://github.com/vulkano-rs/vulkano.git", branch = "master" }
vulkano-shaders = { git = "https://github.com/vulkano-rs/vulkano.git", branch = "master" }
vulkano-util = { git = "https://github.com/vulkano-rs/vulkano.git", branch = "master" }
flax = { version = "0.6.2", features = ["derive", "serde", "tokio", "tracing"] }
flume = "0.11.0"
parking_lot = "0.12.1"
downcast-rs = "1.2.0"
serde = { version = "1.0.197", features = ["derive"] }
serde-lexpr = "0.1.3"
tokio = { version = "1.36.0", features = ["full"] }
notify = "6.1.1"
notify-debouncer-mini = "0.4.1"
steel-core = { git="https://github.com/mattwparas/steel.git", branch = "master" }
steel-derive = { git="https://github.com/mattwparas/steel.git", branch = "master" }
egui = "0.27.1"
image = "0.25.0"
ahash = "0.8.11"
egui-winit = "0.27.1"

View file

@ -1,18 +0,0 @@
[package]
name = "khors-core"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
egui-vulkano = { path = "../vendor/egui-vulkano", version = "0.1.0" }
flax = { version = "0.6.2", features = ["derive", "serde", "tokio", "tracing"] }
flume = "0.11.0"
anyhow = "1.0.80"
vulkano = { git = "https://github.com/vulkano-rs/vulkano.git", branch = "master" }
vulkano-util = { git = "https://github.com/vulkano-rs/vulkano.git", branch = "master" }
winit = { version = "0.29.15",features = ["rwh_05"] }
parking_lot = "0.12.1"
downcast-rs = "1.2.0"

View file

@ -1,49 +0,0 @@
use std::collections::HashMap;
use egui_vulkano::{Gui, GuiConfig};
use vulkano_util::renderer::VulkanoWindowRenderer;
use winit::{event_loop::EventLoopWindowTarget, window::WindowId};
#[derive(Default)]
pub struct DebugGuiStack {
guis: HashMap<WindowId, Gui>,
}
impl DebugGuiStack {
pub fn add_gui<T>(
&mut self,
window_id: WindowId,
event_loop: &EventLoopWindowTarget<T>,
renderer: &VulkanoWindowRenderer,
is_overlay: bool,
allow_srgb_render_target: bool,
) where
T: Clone + Send + Sync,
{
let gui = Gui::new(
event_loop,
renderer.surface().clone(),
renderer.graphics_queue().clone(),
renderer.swapchain_format(),
GuiConfig {
is_overlay,
allow_srgb_render_target,
..Default::default()
},
);
self.guis.insert(window_id, gui);
}
pub fn remove_gui(&mut self, window_id: WindowId) {
self.guis.remove(&window_id).unwrap();
}
pub fn get(&mut self, window_id: WindowId) -> Option<&Gui> {
self.guis.get(&window_id)
}
pub fn get_mut(&mut self, window_id: WindowId) -> Option<&mut Gui> {
self.guis.get_mut(&window_id)
}
}

View file

@ -1,5 +0,0 @@
pub mod app;
pub mod events;
pub mod module;
pub mod time;
pub mod debug_gui;

View file

@ -1,43 +0,0 @@
//! Provides time related functionality for Clocks.
use std::time::{Duration, Instant};
use flax::component;
component! {
pub clock: Clock,
}
/// Measures high precision time
#[allow(dead_code)]
pub struct Clock {
start: Instant,
}
#[allow(dead_code)]
impl Clock {
// Creates and starts a new clock
pub fn new() -> Self {
Clock {
start: Instant::now(),
}
}
// Returns the elapsed time
pub fn elapsed(&self) -> Duration {
Instant::now() - self.start
}
// Resets the clock and returns the elapsed time
pub fn reset(&mut self) -> Duration {
let elapsed = self.elapsed();
self.start = Instant::now();
elapsed
}
}
impl Default for Clock {
fn default() -> Self {
Self::new()
}
}

View file

@ -1,18 +0,0 @@
[package]
name = "khors-test"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
khors-core = { path = "../khors-core", version = "0.1.0" }
egui-vulkano = { path = "../vendor/egui-vulkano", version = "0.1.0" }
khors-graphics = { path = "../modules/khors-graphics", version = "0.1.0" }
khors-window = { path = "../modules/khors-window", version = "0.1.0" }
khors-config = { path = "../modules/khors-config", version = "0.1.0" }
khors-steel = { path = "../modules/khors-steel", version = "0.1.0" }
anyhow = "1.0.80"
winit = { version = "0.29.15",features = ["rwh_05"] }
tokio = { version = "1.36.0", features = ["full"] }

View file

@ -1,16 +0,0 @@
[package]
name = "khors-config"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
khors-core = { path = "../../khors-core", version = "0.1.0" }
anyhow = "1.0.80"
notify = "6.1.1"
notify-debouncer-mini = "0.4.1"
flax = { version = "0.6.2", features = ["derive", "serde", "tokio", "tracing"] }
serde = { version = "1.0.197", features = ["derive"] }
serde-lexpr = "0.1.3"

View file

@ -1,24 +0,0 @@
[package]
name = "khors-graphics"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
khors-core = { path = "../../khors-core", version = "0.1.0" }
egui-vulkano = { path = "../../vendor/egui-vulkano", version = "0.1.0" }
anyhow = "1.0.80"
egui = "0.27.1"
glam = "0.27.0"
winit = { version = "0.29.15",features = ["rwh_05"] }
vulkano = { git = "https://github.com/vulkano-rs/vulkano.git", branch = "master" }
vulkano-shaders = { git = "https://github.com/vulkano-rs/vulkano.git", branch = "master" }
vulkano-util = { git = "https://github.com/vulkano-rs/vulkano.git", branch = "master" }
flax = { version = "0.6.2", features = ["derive", "serde", "tokio", "tracing"] }
flume = "0.11.0"
parking_lot = "0.12.1"
downcast-rs = "1.2.0"
serde = { version = "1.0.197", features = ["derive"] }
serde-lexpr = "0.1.3"

View file

@ -1,14 +0,0 @@
#version 450
layout(location = 0) in vec3 v_normal;
layout(location = 0) out vec4 f_color;
const vec3 LIGHT = vec3(0.0, 0.0, 1.0);
void main() {
float brightness = dot(normalize(v_normal), normalize(LIGHT));
vec3 dark_color = vec3(0.6, 0.0, 0.0);
vec3 regular_color = vec3(1.0, 0.0, 0.0);
f_color = vec4(mix(dark_color, regular_color, brightness), 1.0);
}

View file

@ -1,551 +0,0 @@
use flax::{entity_ids, BoxedSystem, Query, QueryBorrow, Schedule, System, World};
use glam::{
f32::{Mat3, Vec3},
Mat4,
};
use std::sync::Arc;
use vulkano::{
buffer::{
allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo},
Buffer, BufferCreateInfo, BufferUsage,
},
command_buffer::{
allocator::{CommandBufferAllocator, StandardCommandBufferAllocator},
CommandBufferBeginInfo, CommandBufferLevel, CommandBufferUsage, RecordingCommandBuffer,
RenderPassBeginInfo,
},
descriptor_set::{
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
},
device::DeviceOwned,
format::Format,
image::{view::ImageView, Image, ImageCreateInfo, ImageType, ImageUsage},
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
graphics::{
color_blend::{ColorBlendAttachmentState, ColorBlendState},
depth_stencil::{DepthState, DepthStencilState},
input_assembly::InputAssemblyState,
multisample::MultisampleState,
rasterization::RasterizationState,
vertex_input::{Vertex, VertexDefinition},
viewport::{Viewport, ViewportState},
GraphicsPipelineCreateInfo,
},
layout::PipelineDescriptorSetLayoutCreateInfo,
GraphicsPipeline, Pipeline, PipelineBindPoint, PipelineLayout,
PipelineShaderStageCreateInfo,
},
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
shader::EntryPoint,
sync::GpuFuture,
};
use vulkano_util::{
context::VulkanoContext, renderer::VulkanoWindowRenderer, window::VulkanoWindows,
};
use egui_vulkano::Gui;
use khors_core::{debug_gui::DebugGuiStack, module::RenderModule as ThreadLocalModule};
use self::{
model::{INDICES, NORMALS, POSITIONS},
vulkan::vertex::{Normal, Position},
};
pub mod events;
mod model;
mod test_pipeline;
mod vulkan;
pub struct RenderModule {
schedule: Schedule,
memory_allocator: Arc<StandardMemoryAllocator>,
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
command_buffer_allocator: Arc<dyn CommandBufferAllocator>,
viewport: Viewport,
rotation_start: std::time::Instant,
}
impl RenderModule {
pub fn new(
vk_context: &mut VulkanoContext,
_vk_windows: &mut VulkanoWindows,
_schedule: &mut Schedule,
_world: &mut World,
_events: &mut khors_core::events::Events,
) -> Self {
let schedule = Schedule::builder()
.with_system(add_distance_system())
.build();
let memory_allocator = Arc::new(StandardMemoryAllocator::new_default(
vk_context.device().clone(),
));
let descriptor_set_allocator = Arc::new(StandardDescriptorSetAllocator::new(
vk_context.device().clone(),
Default::default(),
));
let command_buffer_allocator = Arc::new(StandardCommandBufferAllocator::new(
vk_context.device().clone(),
Default::default(),
));
let viewport = Viewport {
offset: [0.0, 0.0],
extent: [0.0, 0.0],
depth_range: 0.0..=1.0,
};
let rotation_start = std::time::Instant::now();
Self {
schedule,
memory_allocator,
descriptor_set_allocator,
command_buffer_allocator,
viewport,
rotation_start,
}
}
}
impl ThreadLocalModule for RenderModule {
fn on_update(
&mut self,
gui_stack: &mut DebugGuiStack,
vk_context: &mut VulkanoContext,
vk_windows: &mut vulkano_util::window::VulkanoWindows,
world: &mut World,
_events: &mut khors_core::events::Events,
_frame_time: std::time::Duration,
) -> anyhow::Result<()> {
self.schedule.execute_seq(world).unwrap();
let viewport = &mut self.viewport;
for (window_id, renderer) in vk_windows.iter_mut() {
let gui = gui_stack.get_mut(*window_id).unwrap();
draw(
vk_context.device().clone(),
self.memory_allocator.clone(),
self.descriptor_set_allocator.clone(),
self.command_buffer_allocator.clone(),
viewport,
vk_context,
renderer,
gui,
self.rotation_start,
);
}
Ok(())
}
}
pub fn add_distance_system() -> BoxedSystem {
let query = Query::new(entity_ids());
System::builder()
.with_query(query)
.build(|mut query: QueryBorrow<'_, flax::EntityIds, _>| {
for _id in &mut query {
// println!("----------: {}", _id.index());
}
})
.boxed()
}
fn draw(
device: Arc<vulkano::device::Device>,
memory_allocator: Arc<StandardMemoryAllocator>,
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
command_buffer_allocator: Arc<dyn CommandBufferAllocator>,
_viewport: &mut Viewport,
context: &mut VulkanoContext,
renderer: &mut VulkanoWindowRenderer,
gui: &mut Gui,
rotation_start: std::time::Instant,
) {
let vertex_buffer = Buffer::from_iter(
memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
},
AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
POSITIONS,
)
.unwrap();
let normals_buffer = Buffer::from_iter(
memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
},
AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
NORMALS,
)
.unwrap();
let index_buffer = Buffer::from_iter(
memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::INDEX_BUFFER,
..Default::default()
},
AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
INDICES,
)
.unwrap();
let uniform_buffer = SubbufferAllocator::new(
memory_allocator.clone(),
SubbufferAllocatorCreateInfo {
buffer_usage: BufferUsage::UNIFORM_BUFFER,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
);
let render_pass = vulkano::single_pass_renderpass!(
device.clone(),
attachments: {
color: {
format: renderer.swapchain_format(),
samples: 1,
load_op: Clear,
store_op: Store,
},
depth_stencil: {
format: Format::D16_UNORM,
samples: 1,
load_op: Clear,
store_op: DontCare,
},
},
pass: {
color: [color],
depth_stencil: {depth_stencil},
},
)
.unwrap();
let vs = vs::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();
let fs = fs::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();
let (mut pipeline, mut framebuffers) = window_size_dependent_setup(
memory_allocator.clone(),
vs.clone(),
fs.clone(),
renderer.swapchain_image_views(),
render_pass.clone(),
);
// Do not draw the frame when the screen size is zero. On Windows, this can
// occur when minimizing the application.
let image_extent: [u32; 2] = renderer.window().inner_size().into();
if image_extent.contains(&0) {
return;
}
// Begin rendering by acquiring the gpu future from the window renderer.
let previous_frame_end = renderer
.acquire(None, |swapchain_images| {
// Whenever the window resizes we need to recreate everything dependent
// on the window size. In this example that
// includes the swapchain, the framebuffers
// and the dynamic state viewport.
let (new_pipeline, new_framebuffers) = window_size_dependent_setup(
memory_allocator.clone(),
vs.clone(),
fs.clone(),
swapchain_images,
render_pass.clone(),
);
pipeline = new_pipeline;
framebuffers = new_framebuffers;
})
.unwrap();
let uniform_buffer_subbuffer = {
let elapsed = rotation_start.elapsed();
let rotation = elapsed.as_secs() as f64 + elapsed.subsec_nanos() as f64 / 1_000_000_000.0;
let rotation = Mat3::from_rotation_y(rotation as f32);
// NOTE: This teapot was meant for OpenGL where the origin is at the lower left
// instead the origin is at the upper left in Vulkan, so we reverse the Y axis.
let aspect_ratio = renderer.aspect_ratio();
let proj = Mat4::perspective_rh_gl(std::f32::consts::FRAC_PI_2, aspect_ratio, 0.01, 100.0);
let view = Mat4::look_at_rh(
Vec3::new(0.4, 0.3, 1.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, -1.0, 0.0),
);
let scale = Mat4::from_scale(Vec3::splat(0.01));
let uniform_data = vs::Data {
world: Mat4::from_mat3(rotation).to_cols_array_2d(),
view: (view * scale).to_cols_array_2d(),
proj: proj.to_cols_array_2d(),
};
let subbuffer = uniform_buffer.allocate_sized().unwrap();
*subbuffer.write().unwrap() = uniform_data;
subbuffer
};
let mut builder = RecordingCommandBuffer::new(
command_buffer_allocator.clone(),
context.graphics_queue().queue_family_index(),
CommandBufferLevel::Primary,
CommandBufferBeginInfo {
usage: CommandBufferUsage::OneTimeSubmit,
..Default::default()
},
)
.unwrap();
let layout = &pipeline.layout().set_layouts()[0];
let set = DescriptorSet::new(
descriptor_set_allocator.clone(),
layout.clone(),
[WriteDescriptorSet::buffer(0, uniform_buffer_subbuffer)],
[],
)
.unwrap();
builder
.begin_render_pass(
RenderPassBeginInfo {
clear_values: vec![Some([0.0, 0.0, 1.0, 1.0].into()), Some(1f32.into())],
..RenderPassBeginInfo::framebuffer(
framebuffers[renderer.image_index() as usize].clone(),
)
},
Default::default(),
)
.unwrap()
.bind_pipeline_graphics(pipeline.clone())
.unwrap()
.bind_descriptor_sets(
PipelineBindPoint::Graphics,
pipeline.layout().clone(),
0,
set,
)
.unwrap()
.bind_vertex_buffers(0, (vertex_buffer.clone(), normals_buffer.clone()))
.unwrap()
.bind_index_buffer(index_buffer.clone())
.unwrap();
unsafe {
builder
.draw_indexed(index_buffer.len() as u32, 1, 0, 0, 0)
.unwrap();
}
builder.end_render_pass(Default::default()).unwrap();
// Finish recording the command buffer by calling `end`.
let command_buffer = builder.end().unwrap();
draw_gui(gui);
let before_future = previous_frame_end
.then_execute(context.graphics_queue().clone(), command_buffer)
.unwrap()
.boxed();
let after_future = gui
.draw_on_image(before_future, renderer.swapchain_image_view())
.boxed();
// The color output is now expected to contain our triangle. But in order to
// show it on the screen, we have to *present* the image by calling
// `present` on the window renderer.
//
// This function does not actually present the image immediately. Instead it
// submits a present command at the end of the queue. This means that it will
// only be presented once the GPU has finished executing the command buffer
// that draws the triangle.
renderer.present(after_future, true);
}
fn draw_gui(gui: &mut Gui) {
let mut code = CODE.to_owned();
gui.immediate_ui(|gui| {
let ctx = gui.context();
egui::Window::new("Colors").vscroll(true).show(&ctx, |ui| {
ui.vertical_centered(|ui| {
ui.add(egui::widgets::Label::new("Hi there!"));
sized_text(ui, "Rich Text", 32.0);
});
ui.separator();
ui.columns(2, |columns| {
egui::ScrollArea::vertical()
.id_source("source")
.show(&mut columns[0], |ui| {
ui.add(
egui::TextEdit::multiline(&mut code).font(egui::TextStyle::Monospace),
);
});
egui::ScrollArea::vertical()
.id_source("rendered")
.show(&mut columns[1], |ui| {
ui.add(egui::widgets::Label::new("Good day!"));
});
});
});
});
}
fn sized_text(ui: &mut egui::Ui, text: impl Into<String>, size: f32) {
ui.label(
egui::RichText::new(text)
.size(size)
.family(egui::FontFamily::Monospace),
);
}
const CODE: &str = r"
# Some markup
```
let mut gui = Gui::new(&event_loop, renderer.surface(), None, renderer.queue(), SampleCount::Sample1);
```
";
fn window_size_dependent_setup(
memory_allocator: Arc<StandardMemoryAllocator>,
vs: EntryPoint,
fs: EntryPoint,
image_views: &[Arc<ImageView>],
render_pass: Arc<RenderPass>,
) -> (Arc<GraphicsPipeline>, Vec<Arc<Framebuffer>>) {
let device = memory_allocator.device().clone();
let extent = image_views[0].image().extent();
let depth_buffer = ImageView::new_default(
Image::new(
memory_allocator,
ImageCreateInfo {
image_type: ImageType::Dim2d,
format: Format::D16_UNORM,
extent,
usage: ImageUsage::DEPTH_STENCIL_ATTACHMENT | ImageUsage::TRANSIENT_ATTACHMENT,
..Default::default()
},
AllocationCreateInfo::default(),
)
.unwrap(),
)
.unwrap();
let framebuffers = image_views
.iter()
.map(|image_view| {
Framebuffer::new(
render_pass.clone(),
FramebufferCreateInfo {
attachments: vec![image_view.clone(), depth_buffer.clone()],
..Default::default()
},
)
.unwrap()
})
.collect::<Vec<_>>();
// In the triangle example we use a dynamic viewport, as its a simple example. However in the
// teapot example, we recreate the pipelines with a hardcoded viewport instead. This allows the
// driver to optimize things, at the cost of slower window resizes.
// https://computergraphics.stackexchange.com/questions/5742/vulkan-best-way-of-updating-pipeline-viewport
let pipeline = {
let vertex_input_state = [Position::per_vertex(), Normal::per_vertex()]
.definition(&vs)
.unwrap();
let stages = [
PipelineShaderStageCreateInfo::new(vs),
PipelineShaderStageCreateInfo::new(fs),
];
let layout = PipelineLayout::new(
device.clone(),
PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages)
.into_pipeline_layout_create_info(device.clone())
.unwrap(),
)
.unwrap();
let subpass = Subpass::from(render_pass, 0).unwrap();
GraphicsPipeline::new(
device,
None,
GraphicsPipelineCreateInfo {
stages: stages.into_iter().collect(),
vertex_input_state: Some(vertex_input_state),
input_assembly_state: Some(InputAssemblyState::default()),
viewport_state: Some(ViewportState {
viewports: [Viewport {
offset: [0.0, 0.0],
extent: [extent[0] as f32, extent[1] as f32],
depth_range: 0.0..=1.0,
}]
.into_iter()
.collect(),
..Default::default()
}),
rasterization_state: Some(RasterizationState::default()),
depth_stencil_state: Some(DepthStencilState {
depth: Some(DepthState::simple()),
..Default::default()
}),
multisample_state: Some(MultisampleState::default()),
color_blend_state: Some(ColorBlendState::with_attachment_states(
subpass.num_color_attachments(),
ColorBlendAttachmentState::default(),
)),
subpass: Some(subpass.into()),
..GraphicsPipelineCreateInfo::layout(layout)
},
)
.unwrap()
};
(pipeline, framebuffers)
}
mod vs {
vulkano_shaders::shader! {
ty: "vertex",
path: "src/vert.glsl",
}
}
mod fs {
vulkano_shaders::shader! {
ty: "fragment",
path: "src/frag.glsl",
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,18 +0,0 @@
#version 450
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 normal;
layout(location = 0) out vec3 v_normal;
layout(set = 0, binding = 0) uniform Data {
mat4 world;
mat4 view;
mat4 proj;
} uniforms;
void main() {
mat4 worldview = uniforms.view * uniforms.world;
v_normal = transpose(inverse(mat3(worldview))) * normal;
gl_Position = uniforms.proj * worldview * vec4(position, 1.0);
}

View file

@ -1,2 +0,0 @@
// pub mod pipeline;
pub mod vertex;

View file

@ -1,108 +0,0 @@
use std::sync::Arc;
use vulkano::{
device::Device,
pipeline::{
graphics::{
color_blend::{ColorBlendAttachmentState, ColorBlendState},
depth_stencil::{DepthState, DepthStencilState},
input_assembly::InputAssemblyState,
multisample::MultisampleState,
rasterization::RasterizationState,
vertex_input::{Vertex, VertexDefinition},
viewport::{Viewport, ViewportState},
GraphicsPipelineCreateInfo,
},
layout::PipelineDescriptorSetLayoutCreateInfo,
GraphicsPipeline, PipelineLayout, PipelineShaderStageCreateInfo,
},
render_pass::{RenderPass, Subpass},
shader::ShaderModule,
};
use super::vertex::{Normal, Position};
pub struct PipelineInfo {
pub vs: Arc<ShaderModule>,
pub fs: Arc<ShaderModule>,
}
pub fn make_pipeline(
device: Arc<Device>,
pipeline_info: &PipelineInfo,
pass_info: &PassInfo,
) -> Arc<GraphicsPipeline> {
let vs = pipeline_info.vs.entry_point("main").unwrap();
let fs = pipeline_info.fs.entry_point("main").unwrap();
let vertex_input_state = [Position::per_vertex(), Normal::per_vertex()]
.definition(&vs)
.unwrap();
let stages = [
PipelineShaderStageCreateInfo::new(vs),
PipelineShaderStageCreateInfo::new(fs),
];
let layout = PipelineLayout::new(
device.clone(),
PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages)
.into_pipeline_layout_create_info(device.clone())
.unwrap(),
)
.unwrap();
let subpass = pass_info.subpass().unwrap();
let extent = pass_info.extent;
GraphicsPipeline::new(
device,
None,
GraphicsPipelineCreateInfo {
stages: stages.into_iter().collect(),
vertex_input_state: Some(vertex_input_state),
input_assembly_state: Some(InputAssemblyState::default()),
viewport_state: Some(ViewportState {
viewports: [Viewport {
offset: [0.0, 0.0],
extent: [extent[0] as f32, extent[1] as f32],
depth_range: 0.0..=1.0,
}]
.into_iter()
.collect(),
..Default::default()
}),
rasterization_state: Some(RasterizationState::default()),
depth_stencil_state: Some(DepthStencilState {
depth: Some(DepthState::simple()),
..Default::default()
}),
multisample_state: Some(MultisampleState::default()),
color_blend_state: Some(ColorBlendState::with_attachment_states(
subpass.num_color_attachments(),
ColorBlendAttachmentState::default(),
)),
subpass: Some(subpass.into()),
..GraphicsPipelineCreateInfo::layout(layout)
},
)
.unwrap()
}
pub struct PassInfo {
pub render_pass: Arc<RenderPass>,
pub subpass_id: u32,
pub extent: [u32; 3],
}
impl PassInfo {
pub fn new(render_pass: Arc<RenderPass>, subpass_id: u32, extent: [u32; 3]) -> Self {
Self {
render_pass: render_pass.clone(),
subpass_id,
extent,
}
}
pub fn subpass(&self) -> Option<Subpass> {
Subpass::from(self.render_pass.clone(), self.subpass_id)
}
}

View file

@ -1,15 +0,0 @@
use vulkano::{buffer::BufferContents, pipeline::graphics::vertex_input::Vertex};
#[derive(BufferContents, Vertex)]
#[repr(C)]
pub struct Position {
#[format(R32G32B32_SFLOAT)]
pub position: [f32; 3],
}
#[derive(BufferContents, Vertex)]
#[repr(C)]
pub struct Normal {
#[format(R32G32B32_SFLOAT)]
pub normal: [f32; 3],
}

View file

@ -1,17 +0,0 @@
[package]
name = "khors-steel"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
khors-core = { path = "../../khors-core", version = "0.1.0" }
anyhow = "1.0.80"
flax = { version = "0.6.2", features = ["derive", "serde", "tokio", "tracing"] }
flume = "0.11.0"
notify = "6.1.1"
notify-debouncer-mini = "0.4.1"
steel-core = { git="https://github.com/mattwparas/steel.git", branch = "master" }
steel-derive = { git="https://github.com/mattwparas/steel.git", branch = "master" }

View file

@ -1,12 +0,0 @@
[package]
name = "khors-window"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
khors-core = { path = "../../khors-core", version = "0.1.0" }
anyhow = "1.0.80"
flax = { version = "0.6.2", features = ["derive", "serde", "tokio", "tracing"] }

View file

@ -1 +0,0 @@
Please use 'khors-test' as a main test bench

View file

@ -1,27 +1,22 @@
#![warn(dead_code)]
use std::collections::HashMap;
use crate::{
debug_gui::DebugGuiStack,
core::{
events::Events,
module::{Module, ModulesStack, RenderModule as ThreadLocalModule, RenderModulesStack},
},
modules::graphics::egui::{Gui, GuiConfig},
};
use anyhow::Result;
use flax::{component, Schedule, World};
use flax::{Schedule, World};
use vulkano::device::DeviceFeatures;
use vulkano_util::{
context::{VulkanoConfig, VulkanoContext},
window::VulkanoWindows,
};
use winit::{
event::{Event, WindowEvent},
window::WindowId,
};
component! {
window_id: WindowId,
resources,
}
use winit::{event::{Event, WindowEvent}, window::WindowId};
#[allow(dead_code)]
pub struct App {
@ -36,12 +31,13 @@ pub struct App {
event_cleanup_time: std::time::Duration,
vk_context: VulkanoContext,
vk_windows: VulkanoWindows,
debug_gui_stack: DebugGuiStack,
guis: HashMap<WindowId, Gui>,
}
impl App {
pub fn new() -> Self {
let mut events = Events::new();
let (tx, rx) = flume::unbounded();
events.subscribe_custom(tx);
@ -69,7 +65,7 @@ impl App {
event_cleanup_time: std::time::Duration::from_secs(60),
vk_context,
vk_windows,
debug_gui_stack: DebugGuiStack::default(),
guis: HashMap::new(),
}
}
@ -83,14 +79,14 @@ impl App {
let world = &mut self.world;
let events = &mut self.events;
let frame_time = std::time::Duration::from_millis(16);
let gui_stack = &mut self.debug_gui_stack;
let guis = &mut self.guis;
for module in self.modules.iter_mut() {
module.on_update(world, events, frame_time)?;
}
for module in self.thread_local_modules.iter_mut() {
module.on_update(gui_stack, vk_context, vk_windows, world, events, frame_time)?;
module.on_update(guis, vk_context, vk_windows, world, events, frame_time)?;
}
self.handle_events();
@ -102,25 +98,27 @@ impl App {
where
T: Clone + Send + Sync,
{
let vk_window_id = self.vk_windows.create_window(
let window = self.vk_windows.create_window(
event_loop,
&self.vk_context,
&vulkano_util::window::WindowDescriptor {
title: self.name.clone(),
present_mode: vulkano::swapchain::PresentMode::Mailbox,
present_mode: vulkano::swapchain::PresentMode::Fifo,
..Default::default()
},
|_| {},
);
let renderer = self.vk_windows.get_renderer(vk_window_id).unwrap();
let renderer = self.vk_windows.get_renderer(window).unwrap();
let gui = Gui::new(
event_loop,
renderer.surface().clone(),
renderer.graphics_queue().clone(),
renderer.swapchain_format(),
GuiConfig { is_overlay: true, allow_srgb_render_target: false, ..Default::default() },
);
self.world
.set(resources(), window_id(), vk_window_id)
.unwrap();
self.debug_gui_stack
.add_gui(vk_window_id, event_loop, renderer, true, false);
self.guis.insert(window, gui);
}
pub fn process_event_loop<T>(
@ -179,16 +177,16 @@ impl App {
}
Event::WindowEvent { window_id, event } => {
let window = self.vk_windows.get_window(*window_id).unwrap();
let gui = self.debug_gui_stack.get_mut(*window_id).unwrap();
let gui = self.guis.get_mut(window_id).unwrap();
gui.update(window, event);
}
Event::AboutToWait => {
self.vk_windows.iter().for_each(|(window_id, _)| {
for (window_id, _) in self.vk_windows.iter() {
self.vk_windows
.get_window(*window_id)
.unwrap()
.request_redraw()
});
}
}
_ => (),
}

2
src/core/mod.rs Normal file
View file

@ -0,0 +1,2 @@
pub mod events;
pub mod module;

View file

@ -1,11 +1,10 @@
use std::time::Duration;
use std::{collections::HashMap, time::Duration};
use anyhow::Result;
use flax::World;
use winit::window::WindowId;
use super::events::Events;
use super::debug_gui::DebugGuiStack;
use crate::{core::events::Events, modules::graphics::egui::Gui};
pub trait Module {
fn on_update(&mut self, world: &mut World, events: &mut Events, frame_time: Duration) -> Result<()>;
@ -68,7 +67,7 @@ impl<'a> IntoIterator for &'a mut ModulesStack {
// THREAD LOCAL STUFF
pub trait RenderModule {
fn on_update(&mut self, gui_stack: &mut DebugGuiStack, vk_context: &mut vulkano_util::context::VulkanoContext, vk_windows: &mut vulkano_util::window::VulkanoWindows, world: &mut World, events: &mut Events, frame_time: Duration) -> Result<()>;
fn on_update(&mut self, gui: &mut HashMap<WindowId, Gui>, vk_context: &mut vulkano_util::context::VulkanoContext, vk_windows: &mut vulkano_util::window::VulkanoWindows, world: &mut World, events: &mut Events, frame_time: Duration) -> Result<()>;
}
pub struct RenderModulesStack {

View file

@ -1,12 +1,13 @@
use anyhow::Result;
use khors_config::ConfigModule;
use khors_core::app::App;
use khors_graphics::RenderModule;
use khors_window::WindowModule;
use app::App;
use modules::{config::ConfigModule, graphics::RenderModule, window::WindowModule};
use tokio::runtime::Builder;
use winit::event_loop::{ControlFlow, EventLoopBuilder};
mod app;
mod core;
mod modules;
fn main() -> Result<()> {
let event_loop = EventLoopBuilder::new().build()?;
@ -29,7 +30,6 @@ fn main() -> Result<()> {
let mut app = App::new(); // TODO: Move renderer into App
app.create_window(&event_loop);
app.push_module(ConfigModule::new);
app.push_module(WindowModule::new);
app.push_render_module(RenderModule::new);

View file

@ -1,7 +1,8 @@
use flax::{Schedule, World};
use khors_core::module::Module;
use serde::{Deserialize, Serialize};
use crate::core::module::Module;
use self::systems::first_read_config_system;
pub mod components;
@ -22,7 +23,7 @@ impl ConfigModule {
pub fn new(
schedule: &mut Schedule,
_world: &mut World,
_events: &mut khors_core::events::Events,
_events: &mut crate::core::events::Events,
) -> Self {
let schedule_r = Schedule::builder()
// .with_system(read_config_system())
@ -43,7 +44,7 @@ impl Module for ConfigModule {
fn on_update(
&mut self,
_world: &mut World,
_events: &mut khors_core::events::Events,
_events: &mut crate::core::events::Events,
_frame_time: std::time::Duration,
) -> anyhow::Result<()> {
// println!("ConfigModule on_update");

287
src/modules/graphics/mod.rs Normal file
View file

@ -0,0 +1,287 @@
use std::{collections::HashMap, sync::Arc};
use flax::{entity_ids, BoxedSystem, Query, QueryBorrow, Schedule, System, World};
use vulkano::{
command_buffer::{
allocator::{CommandBufferAllocator, StandardCommandBufferAllocator},
CommandBufferBeginInfo, CommandBufferLevel, CommandBufferUsage, RecordingCommandBuffer,
RenderingAttachmentInfo, RenderingInfo,
},
image::view::ImageView,
pipeline::graphics::viewport::Viewport,
render_pass::{AttachmentLoadOp, AttachmentStoreOp},
sync::GpuFuture,
};
use vulkano_util::{
context::VulkanoContext, renderer::VulkanoWindowRenderer, window::VulkanoWindows,
};
use winit::window::WindowId;
use crate::core::module::RenderModule as ThreadLocalModule;
use self::{egui::Gui, test_pipeline::test_pipeline};
pub mod egui;
pub mod events;
mod test_pipeline;
pub struct RenderModule {
schedule: Schedule,
command_buffer_allocator: Arc<dyn CommandBufferAllocator>,
viewport: Viewport,
}
impl RenderModule {
pub fn new(
vk_context: &mut VulkanoContext,
_vk_windows: &mut VulkanoWindows,
_schedule: &mut Schedule,
_world: &mut World,
_events: &mut crate::core::events::Events,
) -> Self {
let schedule = Schedule::builder()
.with_system(add_distance_system())
.build();
let command_buffer_allocator = Arc::new(StandardCommandBufferAllocator::new(
vk_context.device().clone(),
Default::default(),
));
let viewport = Viewport {
offset: [0.0, 0.0],
extent: [0.0, 0.0],
depth_range: 0.0..=1.0,
};
Self {
schedule,
command_buffer_allocator,
viewport,
}
}
}
impl ThreadLocalModule for RenderModule {
fn on_update(
&mut self,
guis: &mut HashMap<WindowId, Gui>,
vk_context: &mut VulkanoContext,
vk_windows: &mut vulkano_util::window::VulkanoWindows,
world: &mut World,
_events: &mut crate::core::events::Events,
_frame_time: std::time::Duration,
) -> anyhow::Result<()> {
self.schedule.execute_seq(world).unwrap();
let viewport = &mut self.viewport;
for (window_id, renderer) in vk_windows.iter_mut() {
let gui = guis.get_mut(window_id).unwrap();
draw(
self.command_buffer_allocator.clone(),
viewport,
vk_context,
renderer,
gui,
);
}
Ok(())
}
}
pub fn add_distance_system() -> BoxedSystem {
let query = Query::new(entity_ids());
System::builder()
.with_query(query)
.build(|mut query: QueryBorrow<'_, flax::EntityIds, _>| {
for _id in &mut query {
// println!("----------: {}", _id.index());
}
})
.boxed()
}
fn draw(
command_buffer_allocator: Arc<dyn CommandBufferAllocator>,
viewport: &mut Viewport,
context: &mut VulkanoContext,
renderer: &mut VulkanoWindowRenderer,
gui: &mut Gui,
) {
let (vertex_buffer, pipeline) = test_pipeline(
context.device().clone(),
context.memory_allocator().clone(),
renderer.swapchain_format(),
);
// Do not draw the frame when the screen size is zero. On Windows, this can
// occur when minimizing the application.
let image_extent: [u32; 2] = renderer.window().inner_size().into();
if image_extent.contains(&0) {
return;
}
// Begin rendering by acquiring the gpu future from the window renderer.
let previous_frame_end = renderer
.acquire(|swapchain_images| {
// Whenever the window resizes we need to recreate everything dependent
// on the window size. In this example that
// includes the swapchain, the framebuffers
// and the dynamic state viewport.
window_size_dependent_setup(swapchain_images, viewport);
})
.unwrap();
let mut builder = RecordingCommandBuffer::new(
command_buffer_allocator.clone(),
context.graphics_queue().queue_family_index(),
CommandBufferLevel::Primary,
CommandBufferBeginInfo {
usage: CommandBufferUsage::OneTimeSubmit,
..Default::default()
},
)
.unwrap();
builder
// Before we can draw, we have to *enter a render pass*. We specify which
// attachments we are going to use for rendering here, which needs to match
// what was previously specified when creating the pipeline.
.begin_rendering(RenderingInfo {
// As before, we specify one color attachment, but now we specify the image
// view to use as well as how it should be used.
color_attachments: vec![Some(RenderingAttachmentInfo {
// `Clear` means that we ask the GPU to clear the content of this
// attachment at the start of rendering.
load_op: AttachmentLoadOp::Clear,
// `Store` means that we ask the GPU to store the rendered output in
// the attachment image. We could also ask it to discard the result.
store_op: AttachmentStoreOp::Store,
// The value to clear the attachment with. Here we clear it with a blue
// color.
//
// Only attachments that have `AttachmentLoadOp::Clear` are provided
// with clear values, any others should use `None` as the clear value.
clear_value: Some([0.0, 0.0, 1.0, 1.0].into()),
..RenderingAttachmentInfo::image_view(
// We specify image view corresponding to the currently acquired
// swapchain image, to use for this attachment.
// attachment_image_views[image_index as usize].clone(),
renderer.swapchain_image_view().clone(),
)
})],
..Default::default()
})
.unwrap()
// We are now inside the first subpass of the render pass.
//
// TODO: Document state setting and how it affects subsequent draw commands.
.set_viewport(0, [viewport.clone()].into_iter().collect())
.unwrap()
.bind_pipeline_graphics(pipeline.clone())
.unwrap()
.bind_vertex_buffers(0, vertex_buffer.clone())
.unwrap();
unsafe {
builder
// We add a draw command.
.draw(vertex_buffer.len() as u32, 1, 0, 0)
.unwrap();
}
builder
// We leave the render pass.
.end_rendering()
.unwrap();
// Finish recording the command buffer by calling `end`.
let command_buffer = builder.end().unwrap();
draw_gui(gui);
let before_future = previous_frame_end
.then_execute(context.graphics_queue().clone(), command_buffer)
.unwrap()
.boxed();
let after_future = gui
.draw_on_image(before_future, renderer.swapchain_image_view())
.boxed();
// The color output is now expected to contain our triangle. But in order to
// show it on the screen, we have to *present* the image by calling
// `present` on the window renderer.
//
// This function does not actually present the image immediately. Instead it
// submits a present command at the end of the queue. This means that it will
// only be presented once the GPU has finished executing the command buffer
// that draws the triangle.
renderer.present(after_future, true);
}
fn draw_gui(gui: &mut Gui) {
let mut code = CODE.to_owned();
gui.immediate_ui(|gui| {
let ctx = gui.context();
egui::egui::Window::new("Colors")
.vscroll(true)
.show(&ctx, |ui| {
ui.vertical_centered(|ui| {
ui.add(egui::egui::widgets::Label::new("Hi there!"));
sized_text(ui, "Rich Text", 32.0);
});
ui.separator();
ui.columns(2, |columns| {
egui::egui::ScrollArea::vertical().id_source("source").show(
&mut columns[0],
|ui| {
ui.add(
egui::egui::TextEdit::multiline(&mut code)
.font(egui::egui::TextStyle::Monospace),
);
},
);
egui::egui::ScrollArea::vertical()
.id_source("rendered")
.show(&mut columns[1], |ui| {
ui.add(egui::egui::widgets::Label::new("Good day!"));
});
});
});
});
}
fn sized_text(ui: &mut egui::egui::Ui, text: impl Into<String>, size: f32) {
ui.label(
egui::egui::RichText::new(text)
.size(size)
.family(::egui::FontFamily::Monospace),
);
}
const CODE: &str = r"
# Some markup
```
let mut gui = Gui::new(&event_loop, renderer.surface(), None, renderer.queue(), SampleCount::Sample1);
```
";
fn window_size_dependent_setup(
image_views: &[Arc<ImageView>],
viewport: &mut Viewport,
) -> Vec<Arc<ImageView>> {
let extent = image_views[0].image().extent();
viewport.extent = [extent[0] as f32, extent[1] as f32];
image_views
.iter()
.map(|image_view| {
let image = image_view.image().clone();
ImageView::new_default(image).unwrap()
})
.collect::<Vec<_>>()
}

View file

@ -21,7 +21,6 @@ use vulkano::{
},
};
#[allow(dead_code)]
pub fn test_pipeline(
device: Arc<Device>,
memory_allocator: Arc<dyn MemoryAllocator>,
@ -168,13 +167,8 @@ mod vs {
layout(location = 0) in vec2 position;
layout(location = 0) out vec3 fragColor;
vec3 colors[3] = vec3[](vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0));
void main() {
gl_Position = vec4(position, 0.0, 1.0);
fragColor = colors[gl_VertexIndex];
}
",
}
@ -186,12 +180,10 @@ mod fs {
src: r"
#version 450
layout(location = 0) in vec3 fragColor;
layout(location = 0) out vec4 f_color;
void main() {
f_color = vec4(fragColor, 1.0);
f_color = vec4(1.0, 0.0, 0.0, 1.0);
}
",
}

4
src/modules/mod.rs Normal file
View file

@ -0,0 +1,4 @@
pub mod config;
pub mod graphics;
pub mod window;
// pub mod steel;

View file

@ -1,10 +1,12 @@
extern crate khors_core;
use std::sync::Arc;
use flax::{component, BoxedSystem, EntityBorrow, Query, QueryBorrow, Schedule, System, World};
use khors_core::module::Module;
use steel::steel_vm::engine::Engine;
use steel::steel_vm::register_fn::RegisterFn;
use steel_derive::Steel;
use crate::core::module::Module;
component! {
steel_script: String,
steel_event_tx: flume::Sender<SteelEvent>,
@ -47,9 +49,9 @@ impl SteelModule {
pub fn new(
schedule: &mut Schedule,
world: &mut World,
_events: &mut khors_core::events::Events,
_events: &mut crate::core::events::Events,
) -> Self {
let engine = Engine::new();
let mut engine = Engine::new();
let (tx, rx) = flume::unbounded::<SteelEvent>();
@ -79,8 +81,8 @@ impl SteelModule {
impl Module for SteelModule {
fn on_update(
&mut self,
_world: &mut World,
_events: &mut khors_core::events::Events,
world: &mut World,
_events: &mut crate::core::events::Events,
_frame_time: std::time::Duration,
) -> anyhow::Result<()> {
// self.schedule.execute_par(world).unwrap();
@ -88,7 +90,7 @@ impl Module for SteelModule {
if let Ok(event) = self.rx.recv() {
match event {
SteelEvent::Execute(script) => {
let _handle = std::thread::spawn(|| {
let handle = std::thread::spawn(|| {
let mut engine = Engine::new();
let val = engine.run(script).unwrap();
println!("Steel val: {:?}", val);

View file

@ -1,6 +1,6 @@
use flax::{Schedule, World};
use khors_core::module::Module;
use crate::core::module::Module;
pub struct WindowModule {
}
@ -9,7 +9,7 @@ impl WindowModule {
pub fn new(
schedule: &mut Schedule,
_world: &mut World,
_events: &mut khors_core::events::Events,
_events: &mut crate::core::events::Events,
) -> Self {
let schedule_r = Schedule::builder()
.build();
@ -24,7 +24,7 @@ impl Module for WindowModule {
fn on_update(
&mut self,
_world: &mut World,
_events: &mut khors_core::events::Events,
_events: &mut crate::core::events::Events,
_frame_time: std::time::Duration,
) -> anyhow::Result<()> {
// println!("WindowModule on_update");

694
src/systems/mod.rs Normal file
View file

@ -0,0 +1,694 @@
use std::{collections::HashMap, sync::Arc};
use super::components::EntityWindow;
use specs::prelude::*;
use vulkano::{
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer},
command_buffer::{
allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel,
CommandBufferUsage, RecordingCommandBuffer, RenderingAttachmentInfo, RenderingInfo,
},
device::{
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, DeviceFeatures,
Queue, QueueCreateInfo, QueueFlags,
},
image::{view::ImageView, Image, ImageUsage},
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo},
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
graphics::{
color_blend::{ColorBlendAttachmentState, ColorBlendState},
input_assembly::InputAssemblyState,
multisample::MultisampleState,
rasterization::RasterizationState,
subpass::PipelineRenderingCreateInfo,
vertex_input::{Vertex, VertexDefinition},
viewport::{Viewport, ViewportState},
GraphicsPipelineCreateInfo,
},
layout::PipelineDescriptorSetLayoutCreateInfo,
DynamicState, GraphicsPipeline, PipelineLayout, PipelineShaderStageCreateInfo,
},
render_pass::{AttachmentLoadOp, AttachmentStoreOp},
swapchain::{
acquire_next_image, Surface, Swapchain, SwapchainCreateInfo, SwapchainPresentInfo,
},
sync::{self, GpuFuture},
Validated, Version, VulkanError, VulkanLibrary,
};
use winit::window::{Window, WindowId};
pub struct Render {
renderers: HashMap<WindowId, VkRender>,
library: Arc<VulkanLibrary>,
}
impl<'a> System<'a> for Render {
type SystemData = (Entities<'a>, ReadStorage<'a, EntityWindow>);
fn run(&mut self, data: Self::SystemData) {
let (entities, windows) = data;
(&entities, &windows).join().for_each(|(_entity, window)| {
self.renderers
.entry(window.window.id())
.or_insert_with(|| VkRender::new(self.library.clone(), window.window.clone()));
self.renderers.values_mut().for_each(|rend| rend.render());
window.window.request_redraw();
});
}
fn setup(&mut self, world: &mut World) {
Self::SystemData::setup(world);
}
}
impl Default for Render {
fn default() -> Self {
Self {
renderers: HashMap::new(),
library: VulkanLibrary::new().unwrap(),
}
}
}
struct VkRender {
window: Arc<Window>,
device: Arc<Device>,
queue: Arc<Queue>,
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
viewport: Viewport,
vertex_buffer: Subbuffer<[MyVertex]>,
recreate_swapchain: bool,
swapchain: Arc<Swapchain>,
previous_frame_end: Option<Box<dyn GpuFuture>>,
attachment_image_views: Vec<Arc<ImageView>>,
pipeline: Arc<GraphicsPipeline>,
}
impl VkRender {
pub fn new(library: Arc<VulkanLibrary>, window: Arc<Window>) -> Self {
println!("Created new renderer for window: {:?}", window.id());
let required_extensions = Surface::required_extensions(&window).unwrap();
// Now creating the instance.
let instance = Instance::new(
library,
InstanceCreateInfo {
// Enable enumerating devices that use non-conformant Vulkan implementations.
// (e.g. MoltenVK)
flags: InstanceCreateFlags::ENUMERATE_PORTABILITY,
enabled_extensions: required_extensions,
..Default::default()
},
)
.unwrap();
let surface = Surface::from_window(instance.clone(), window.clone()).unwrap();
// Choose device extensions that we're going to use. In order to present images to a surface,
// we need a `Swapchain`, which is provided by the `khr_swapchain` extension.
let mut device_extensions = DeviceExtensions {
khr_swapchain: true,
..DeviceExtensions::empty()
};
// We then choose which physical device to use. First, we enumerate all the available physical
// devices, then apply filters to narrow them down to those that can support our needs.
let (physical_device, queue_family_index) = instance
.enumerate_physical_devices()
.unwrap()
.filter(|p| {
// For this example, we require at least Vulkan 1.3, or a device that has the
// `khr_dynamic_rendering` extension available.
p.api_version() >= Version::V1_3 || p.supported_extensions().khr_dynamic_rendering
})
.filter(|p| {
// Some devices may not support the extensions or features that your application, or
// report properties and limits that are not sufficient for your application. These
// should be filtered out here.
p.supported_extensions().contains(&device_extensions)
})
.filter_map(|p| {
// For each physical device, we try to find a suitable queue family that will execute
// our draw commands.
//
// Devices can provide multiple queues to run commands in parallel (for example a draw
// queue and a compute queue), similar to CPU threads. This is something you have to
// have to manage manually in Vulkan. Queues of the same type belong to the same queue
// family.
//
// Here, we look for a single queue family that is suitable for our purposes. In a
// real-world application, you may want to use a separate dedicated transfer queue to
// handle data transfers in parallel with graphics operations. You may also need a
// separate queue for compute operations, if your application uses those.
p.queue_family_properties()
.iter()
.enumerate()
.position(|(i, q)| {
// We select a queue family that supports graphics operations. When drawing to
// a window surface, as we do in this example, we also need to check that
// queues in this queue family are capable of presenting images to the surface.
q.queue_flags.intersects(QueueFlags::GRAPHICS)
&& p.surface_support(i as u32, &surface).unwrap_or(false)
})
// The code here searches for the first queue family that is suitable. If none is
// found, `None` is returned to `filter_map`, which disqualifies this physical
// device.
.map(|i| (p, i as u32))
})
// All the physical devices that pass the filters above are suitable for the application.
// However, not every device is equal, some are preferred over others. Now, we assign each
// physical device a score, and pick the device with the lowest ("best") score.
//
// In this example, we simply select the best-scoring device to use in the application.
// In a real-world setting, you may want to use the best-scoring device only as a "default"
// or "recommended" device, and let the user choose the device themself.
.min_by_key(|(p, _)| {
// We assign a lower score to device types that are likely to be faster/better.
match p.properties().device_type {
PhysicalDeviceType::DiscreteGpu => 0,
PhysicalDeviceType::IntegratedGpu => 1,
PhysicalDeviceType::VirtualGpu => 2,
PhysicalDeviceType::Cpu => 3,
PhysicalDeviceType::Other => 4,
_ => 5,
}
})
.expect("no suitable physical device found");
if physical_device.api_version() < Version::V1_3 {
device_extensions.khr_dynamic_rendering = true;
}
// Now initializing the device. This is probably the most important object of Vulkan.
//
// An iterator of created queues is returned by the function alongside the device.
let (device, mut queues) = Device::new(
// Which physical device to connect to.
physical_device,
DeviceCreateInfo {
// The list of queues that we are going to use. Here we only use one queue, from the
// previously chosen queue family.
queue_create_infos: vec![QueueCreateInfo {
queue_family_index,
..Default::default()
}],
// A list of optional features and extensions that our program needs to work correctly.
// Some parts of the Vulkan specs are optional and must be enabled manually at device
// creation. In this example the only things we are going to need are the
// `khr_swapchain` extension that allows us to draw to a window, and
// `khr_dynamic_rendering` if we don't have Vulkan 1.3 available.
enabled_extensions: device_extensions,
// In order to render with Vulkan 1.3's dynamic rendering, we need to enable it here.
// Otherwise, we are only allowed to render with a render pass object, as in the
// standard triangle example. The feature is required to be supported by the device if
// it supports Vulkan 1.3 and higher, or if the `khr_dynamic_rendering` extension is
// available, so we don't need to check for support.
enabled_features: DeviceFeatures {
dynamic_rendering: true,
..DeviceFeatures::empty()
},
..Default::default()
},
)
.unwrap();
let queue = queues.next().unwrap();
// Before we can draw on the surface, we have to create what is called a swapchain. Creating a
// swapchain allocates the color buffers that will contain the image that will ultimately be
// visible on the screen. These images are returned alongside the swapchain.
let (mut swapchain, images) = {
// Querying the capabilities of the surface. When we create the swapchain we can only pass
// values that are allowed by the capabilities.
let surface_capabilities = device
.physical_device()
.surface_capabilities(&surface, Default::default())
.unwrap();
// Choosing the internal format that the images will have.
let image_format = device
.physical_device()
.surface_formats(&surface, Default::default())
.unwrap()[0]
.0;
// Please take a look at the docs for the meaning of the parameters we didn't mention.
Swapchain::new(
device.clone(),
surface,
SwapchainCreateInfo {
// Some drivers report an `min_image_count` of 1, but fullscreen mode requires at
// least 2. Therefore we must ensure the count is at least 2, otherwise the program
// would crash when entering fullscreen mode on those drivers.
min_image_count: surface_capabilities.min_image_count.max(2),
image_format,
// The size of the window, only used to initially setup the swapchain.
//
// NOTE:
// On some drivers the swapchain extent is specified by
// `surface_capabilities.current_extent` and the swapchain size must use this
// extent. This extent is always the same as the window size.
//
// However, other drivers don't specify a value, i.e.
// `surface_capabilities.current_extent` is `None`. These drivers will allow
// anything, but the only sensible value is the window size.
//
// Both of these cases need the swapchain to use the window size, so we just
// use that.
image_extent: window.inner_size().into(),
image_usage: ImageUsage::COLOR_ATTACHMENT,
// The alpha mode indicates how the alpha value of the final image will behave. For
// example, you can choose whether the window will be opaque or transparent.
composite_alpha: surface_capabilities
.supported_composite_alpha
.into_iter()
.next()
.unwrap(),
..Default::default()
},
)
.unwrap()
};
let memory_allocator = Arc::new(StandardMemoryAllocator::new_default(device.clone()));
let vertices = [
MyVertex {
position: [-0.5, -0.25, 0.1],
},
MyVertex {
position: [0.0, 0.5, 0.1],
},
MyVertex {
position: [0.25, -0.1, 0.1],
},
];
let vertex_buffer = Buffer::from_iter(
memory_allocator,
BufferCreateInfo {
usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
},
AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
vertices,
)
.unwrap();
mod vs {
vulkano_shaders::shader! {
ty: "vertex",
src: r"
#version 450
layout(location = 0) in vec3 position;
void main() {
gl_Position = vec4(position, 1.0);
}
",
}
}
mod fs {
vulkano_shaders::shader! {
ty: "fragment",
src: r"
#version 450
layout(location = 0) out vec4 f_color;
void main() {
f_color = vec4(1.0, 0.0, 0.0, 1.0);
}
",
}
}
// At this point, OpenGL initialization would be finished. However in Vulkan it is not. OpenGL
// implicitly does a lot of computation whenever you draw. In Vulkan, you have to do all this
// manually.
// Before we draw, we have to create what is called a **pipeline**. A pipeline describes how
// a GPU operation is to be performed. It is similar to an OpenGL program, but it also contains
// many settings for customization, all baked into a single object. For drawing, we create
// a **graphics** pipeline, but there are also other types of pipeline.
let pipeline = {
// First, we load the shaders that the pipeline will use:
// the vertex shader and the fragment shader.
//
// A Vulkan shader can in theory contain multiple entry points, so we have to specify which
// one.
let vs = vs::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();
let fs = fs::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();
// Automatically generate a vertex input state from the vertex shader's input interface,
// that takes a single vertex buffer containing `Vertex` structs.
let vertex_input_state = MyVertex::per_vertex().definition(&vs).unwrap();
// Make a list of the shader stages that the pipeline will have.
let stages = [
PipelineShaderStageCreateInfo::new(vs),
PipelineShaderStageCreateInfo::new(fs),
];
// We must now create a **pipeline layout** object, which describes the locations and types of
// descriptor sets and push constants used by the shaders in the pipeline.
//
// Multiple pipelines can share a common layout object, which is more efficient.
// The shaders in a pipeline must use a subset of the resources described in its pipeline
// layout, but the pipeline layout is allowed to contain resources that are not present in the
// shaders; they can be used by shaders in other pipelines that share the same layout.
// Thus, it is a good idea to design shaders so that many pipelines have common resource
// locations, which allows them to share pipeline layouts.
let layout = PipelineLayout::new(
device.clone(),
// Since we only have one pipeline in this example, and thus one pipeline layout,
// we automatically generate the creation info for it from the resources used in the
// shaders. In a real application, you would specify this information manually so that you
// can re-use one layout in multiple pipelines.
PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages)
.into_pipeline_layout_create_info(device.clone())
.unwrap(),
)
.unwrap();
// We describe the formats of attachment images where the colors, depth and/or stencil
// information will be written. The pipeline will only be usable with this particular
// configuration of the attachment images.
let subpass = PipelineRenderingCreateInfo {
// We specify a single color attachment that will be rendered to. When we begin
// rendering, we will specify a swapchain image to be used as this attachment, so here
// we set its format to be the same format as the swapchain.
color_attachment_formats: vec![Some(swapchain.image_format())],
..Default::default()
};
// Finally, create the pipeline.
GraphicsPipeline::new(
device.clone(),
None,
GraphicsPipelineCreateInfo {
stages: stages.into_iter().collect(),
// How vertex data is read from the vertex buffers into the vertex shader.
vertex_input_state: Some(vertex_input_state),
// How vertices are arranged into primitive shapes.
// The default primitive shape is a triangle.
input_assembly_state: Some(InputAssemblyState::default()),
// How primitives are transformed and clipped to fit the framebuffer.
// We use a resizable viewport, set to draw over the entire window.
viewport_state: Some(ViewportState::default()),
// How polygons are culled and converted into a raster of pixels.
// The default value does not perform any culling.
rasterization_state: Some(RasterizationState::default()),
// How multiple fragment shader samples are converted to a single pixel value.
// The default value does not perform any multisampling.
multisample_state: Some(MultisampleState::default()),
// How pixel values are combined with the values already present in the framebuffer.
// The default value overwrites the old value with the new one, without any blending.
color_blend_state: Some(ColorBlendState::with_attachment_states(
subpass.color_attachment_formats.len() as u32,
ColorBlendAttachmentState::default(),
)),
// Dynamic states allows us to specify parts of the pipeline settings when
// recording the command buffer, before we perform drawing.
// Here, we specify that the viewport should be dynamic.
dynamic_state: [DynamicState::Viewport].into_iter().collect(),
subpass: Some(subpass.into()),
..GraphicsPipelineCreateInfo::layout(layout)
},
)
.unwrap()
};
// Dynamic viewports allow us to recreate just the viewport when the window is resized.
// Otherwise we would have to recreate the whole pipeline.
let mut viewport = Viewport {
offset: [0.0, 0.0],
extent: [0.0, 0.0],
depth_range: 0.0..=1.0,
};
// When creating the swapchain, we only created plain images. To use them as an attachment for
// rendering, we must wrap then in an image view.
//
// Since we need to draw to multiple images, we are going to create a different image view for
// each image.
let mut attachment_image_views = window_size_dependent_setup(&images, &mut viewport);
// Before we can start creating and recording command buffers, we need a way of allocating
// them. Vulkano provides a command buffer allocator, which manages raw Vulkan command pools
// underneath and provides a safe interface for them.
let command_buffer_allocator = Arc::new(StandardCommandBufferAllocator::new(
device.clone(),
Default::default(),
));
// Initialization is finally finished!
// In some situations, the swapchain will become invalid by itself. This includes for example
// when the window is resized (as the images of the swapchain will no longer match the
// window's) or, on Android, when the application went to the background and goes back to the
// foreground.
//
// In this situation, acquiring a swapchain image or presenting it will return an error.
// Rendering to an image of that swapchain will not produce any error, but may or may not work.
// To continue rendering, we need to recreate the swapchain by creating a new swapchain. Here,
// we remember that we need to do this for the next loop iteration.
let mut recreate_swapchain = false;
// In the loop below we are going to submit commands to the GPU. Submitting a command produces
// an object that implements the `GpuFuture` trait, which holds the resources for as long as
// they are in use by the GPU.
//
// Destroying the `GpuFuture` blocks until the GPU is finished executing it. In order to avoid
// that, we store the submission of the previous frame here.
let mut previous_frame_end = Some(sync::now(device.clone()).boxed());
Self {
window,
device,
queue,
command_buffer_allocator,
viewport,
vertex_buffer,
recreate_swapchain,
swapchain,
previous_frame_end,
attachment_image_views,
pipeline,
}
}
pub fn render(&mut self) {
// Do not draw the frame when the screen size is zero. On Windows, this can
// occur when minimizing the application.
let image_extent: [u32; 2] = self.window.inner_size().into();
if image_extent.contains(&0) {
return;
}
// It is important to call this function from time to time, otherwise resources
// will keep accumulating and you will eventually reach an out of memory error.
// Calling this function polls various fences in order to determine what the GPU
// has already processed, and frees the resources that are no longer needed.
self.previous_frame_end.as_mut().unwrap().cleanup_finished();
// Whenever the window resizes we need to recreate everything dependent on the
// window size. In this example that includes the swapchain, the framebuffers and
// the dynamic state viewport.
if self.recreate_swapchain {
let (new_swapchain, new_images) = self
.swapchain
.recreate(SwapchainCreateInfo {
image_extent,
..self.swapchain.create_info()
})
.expect("failed to recreate swapchain");
self.swapchain = new_swapchain;
// Now that we have new swapchain images, we must create new image views from
// them as well.
self.attachment_image_views =
window_size_dependent_setup(&new_images, &mut self.viewport);
self.recreate_swapchain = false;
}
// Before we can draw on the output, we have to *acquire* an image from the
// swapchain. If no image is available (which happens if you submit draw commands
// too quickly), then the function will block. This operation returns the index of
// the image that we are allowed to draw upon.
//
// This function can block if no image is available. The parameter is an optional
// timeout after which the function call will return an error.
let (image_index, suboptimal, acquire_future) =
match acquire_next_image(self.swapchain.clone(), None).map_err(Validated::unwrap) {
Ok(r) => r,
Err(VulkanError::OutOfDate) => {
self.recreate_swapchain = true;
return;
}
Err(e) => panic!("failed to acquire next image: {e}"),
};
// `acquire_next_image` can be successful, but suboptimal. This means that the
// swapchain image will still work, but it may not display correctly. With some
// drivers this can be when the window resizes, but it may not cause the swapchain
// to become out of date.
if suboptimal {
self.recreate_swapchain = true;
}
// In order to draw, we have to build a *command buffer*. The command buffer object
// holds the list of commands that are going to be executed.
//
// Building a command buffer is an expensive operation (usually a few hundred
// microseconds), but it is known to be a hot path in the driver and is expected to
// be optimized.
//
// Note that we have to pass a queue family when we create the command buffer. The
// command buffer will only be executable on that given queue family.
let mut builder = RecordingCommandBuffer::new(
self.command_buffer_allocator.clone(),
self.queue.queue_family_index(),
CommandBufferLevel::Primary,
CommandBufferBeginInfo {
usage: CommandBufferUsage::OneTimeSubmit,
..Default::default()
},
)
.unwrap();
builder
// Before we can draw, we have to *enter a render pass*. We specify which
// attachments we are going to use for rendering here, which needs to match
// what was previously specified when creating the pipeline.
.begin_rendering(RenderingInfo {
// As before, we specify one color attachment, but now we specify the image
// view to use as well as how it should be used.
color_attachments: vec![Some(RenderingAttachmentInfo {
// `Clear` means that we ask the GPU to clear the content of this
// attachment at the start of rendering.
load_op: AttachmentLoadOp::Clear,
// `Store` means that we ask the GPU to store the rendered output in
// the attachment image. We could also ask it to discard the result.
store_op: AttachmentStoreOp::Store,
// The value to clear the attachment with. Here we clear it with a blue
// color.
//
// Only attachments that have `AttachmentLoadOp::Clear` are provided
// with clear values, any others should use `None` as the clear value.
clear_value: Some([0.0, 0.0, 1.0, 1.0].into()),
..RenderingAttachmentInfo::image_view(
// We specify image view corresponding to the currently acquired
// swapchain image, to use for this attachment.
self.attachment_image_views[image_index as usize].clone(),
)
})],
..Default::default()
})
.unwrap()
// We are now inside the first subpass of the render pass.
//
// TODO: Document state setting and how it affects subsequent draw commands.
.set_viewport(0, [self.viewport.clone()].into_iter().collect())
.unwrap()
.bind_pipeline_graphics(self.pipeline.clone())
.unwrap()
.bind_vertex_buffers(0, self.vertex_buffer.clone())
.unwrap();
unsafe {
builder
// We add a draw command.
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
.unwrap();
}
builder
// We leave the render pass.
.end_rendering()
.unwrap();
// Finish recording the command buffer by calling `end`.
let command_buffer = builder.end().unwrap();
let future = self
.previous_frame_end
.take()
.unwrap()
.join(acquire_future)
.then_execute(self.queue.clone(), command_buffer)
.unwrap()
// The color output is now expected to contain our triangle. But in order to
// show it on the screen, we have to *present* the image by calling
// `then_swapchain_present`.
//
// This function does not actually present the image immediately. Instead it
// submits a present command at the end of the queue. This means that it will
// only be presented once the GPU has finished executing the command buffer
// that draws the triangle.
.then_swapchain_present(
self.queue.clone(),
SwapchainPresentInfo::swapchain_image_index(self.swapchain.clone(), image_index),
)
.then_signal_fence_and_flush();
match future.map_err(Validated::unwrap) {
Ok(future) => {
self.previous_frame_end = Some(future.boxed());
}
Err(VulkanError::OutOfDate) => {
self.recreate_swapchain = true;
self.previous_frame_end = Some(sync::now(self.device.clone()).boxed());
}
Err(e) => {
println!("failed to flush future: {e}");
self.previous_frame_end = Some(sync::now(self.device.clone()).boxed());
}
}
}
}
#[derive(BufferContents, Vertex)]
#[repr(C)]
struct MyVertex {
#[format(R32G32B32_SFLOAT)]
position: [f32; 3],
}
fn window_size_dependent_setup(
images: &[Arc<Image>],
viewport: &mut Viewport,
) -> Vec<Arc<ImageView>> {
let extent = images[0].extent();
viewport.extent = [extent[0] as f32, extent[1] as f32];
images
.iter()
.map(|image| ImageView::new_default(image.clone()).unwrap())
.collect::<Vec<_>>()
}

View file

@ -1,15 +0,0 @@
[package]
name = "egui-vulkano"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
vulkano = { git = "https://github.com/vulkano-rs/vulkano.git", branch = "master" }
vulkano-shaders = { git = "https://github.com/vulkano-rs/vulkano.git", branch = "master" }
egui = "0.27.1"
image = "0.25.0"
ahash = "0.8.11"
egui-winit = "0.27.1"
winit = { version = "0.29.15",features = ["rwh_05"] }