diff --git a/.github/workflows/clippy.sh b/.github/workflows/clippy.sh index 49716d5ecb..bd7873b27c 100755 --- a/.github/workflows/clippy.sh +++ b/.github/workflows/clippy.sh @@ -35,11 +35,9 @@ clippy spirv-builder # Examples -# disabled due to https://github.com/EmbarkStudios/rust-gpu/issues/186 -#clippy examples/example-runner +clippy examples/runners/ash +clippy examples/runners/wgpu -clippy examples/wgpu-example-runner - -clippy_no_features examples/example-runner-cpu -clippy_no_features examples/example-shader -clippy_no_features examples/wgpu-example-shader +clippy_no_features examples/runners/cpu +clippy_no_features examples/shaders/sky-shader +clippy_no_features examples/shaders/simplest-shader diff --git a/.github/workflows/test.sh b/.github/workflows/test.sh index f4d900b6bf..a87fbf6016 100755 --- a/.github/workflows/test.sh +++ b/.github/workflows/test.sh @@ -45,11 +45,11 @@ cargo_test spirv-builder # Examples # See: https://github.com/EmbarkStudios/rust-gpu/issues/84 if [[ -z "${CI}" && "$os" != "macOS" ]]; then - cargo_test examples/example-runner + cargo_test examples/runners/ash fi -cargo_test examples/wgpu-example-runner +cargo_test examples/runners/wgpu -cargo_test_no_features examples/example-runner-cpu -cargo_test_no_features examples/example-shader -cargo_test_no_features examples/wgpu-example-shader +cargo_test_no_features examples/runners/cpu +cargo_test_no_features examples/shaders/sky-shader +cargo_test_no_features examples/shaders/simplest-shader diff --git a/Cargo.lock b/Cargo.lock index c00bf65a32..188f00e9eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,38 +17,17 @@ dependencies = [ [[package]] name = "andrew" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7f09f89872c2b6b29e319377b1fbe91c6f5947df19a25596e121cf19a7b35e" -dependencies = [ - "bitflags", - "line_drawing 0.7.0", - "rusttype 0.7.9", - "walkdir", - "xdg", - "xml-rs", -] - -[[package]] -name = "andrew" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e1ea80a5089cac999ffd4a91888154076a961d27387b0f7a6cd2d4dddb636b9" +checksum = "8c4afb09dd642feec8408e33f92f3ffc4052946f6b20f32fb99c1f58cd4fa7cf" dependencies = [ "bitflags", - "line_drawing 0.8.0", - "rusttype 0.9.2", + "rusttype", "walkdir", "xdg", "xml-rs", ] -[[package]] -name = "android_log-sys" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8052e2d8aabbb8d556d6abbcce2a22b9590996c5f849b9c7ce4544a2e3b984e" - [[package]] name = "ansi_term" version = "0.11.0" @@ -67,20 +46,11 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "approx" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3" -dependencies = [ - "num-traits 0.2.12", -] - [[package]] name = "arrayvec" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "ash" @@ -94,7 +64,7 @@ dependencies = [ [[package]] name = "ash-molten" version = "0.6.0+43" -source = "git+https://github.com/EmbarkStudios/ash-molten?branch=moltenvk-1.1.0#d0cb9e55d366b383e94ab5f5c299b2758e385f32" +source = "git+https://github.com/EmbarkStudios/ash-molten?branch=moltenvk-1.1.0#9b3010469c46e59b1ded6cb81873e80c4fe7c2f6" dependencies = [ "ash", ] @@ -178,17 +148,6 @@ version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" -[[package]] -name = "calloop" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7aa2097be53a00de9e8fc349fea6d76221f398f5c4fa550d420669906962d160" -dependencies = [ - "mio", - "mio-extras", - "nix 0.14.1", -] - [[package]] name = "calloop" version = "0.6.5" @@ -228,7 +187,7 @@ checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" dependencies = [ "libc", "num-integer", - "num-traits 0.2.12", + "num-traits", "time", "winapi 0.3.9", ] @@ -480,7 +439,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fbaabec2c953050352311293be5c6aba8e141ba19d6811862b232d6fd020484" dependencies = [ "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", ] [[package]] @@ -515,7 +474,7 @@ dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", "strsim 0.9.3", - "syn 1.0.46", + "syn 1.0.48", ] [[package]] @@ -526,7 +485,7 @@ checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" dependencies = [ "darling_core", "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", ] [[package]] @@ -537,7 +496,7 @@ checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", ] [[package]] @@ -588,7 +547,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] -name = "example-runner" +name = "example-runner-ash" version = "0.1.0" dependencies = [ "ash", @@ -597,25 +556,32 @@ dependencies = [ "cfg-if 1.0.0", "spirv-builder", "structopt", - "winit 0.23.0", + "winit", ] [[package]] name = "example-runner-cpu" version = "0.1.0" dependencies = [ - "example-shader", "glam", "minifb", "rayon", + "sky-shader", ] [[package]] -name = "example-shader" +name = "example-runner-wgpu" version = "0.1.0" dependencies = [ - "glam", - "spirv-std", + "console_error_panic_hook", + "console_log", + "futures", + "spirv-builder", + "wasm-bindgen-futures", + "web-sys", + "wgpu", + "wgpu-subscriber", + "winit", ] [[package]] @@ -675,9 +641,9 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "futures" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d8e3078b7b2a8a671cb7a3d17b4760e4181ea243227776ba83fd043b4ca034e" +checksum = "95314d38584ffbfda215621d723e0a3906f032e03ae5551e650058dac83d4797" dependencies = [ "futures-channel", "futures-core", @@ -690,9 +656,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a4d35f7401e948629c9c3d6638fb9bf94e0b2121e96c3b428cc4e631f3eb74" +checksum = "0448174b01148032eed37ac4aed28963aaaa8cfa93569a08e5b479bbc6c2c151" dependencies = [ "futures-core", "futures-sink", @@ -700,15 +666,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d674eaa0056896d5ada519900dbf97ead2e46a7b6621e8160d79e2f2e1e2784b" +checksum = "18eaa56102984bed2c88ea39026cff3ce3b4c7f508ca970cedf2450ea10d4e46" [[package]] name = "futures-executor" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc709ca1da6f66143b8c9bec8e6260181869893714e9b5a490b169b0414144ab" +checksum = "f5f8e0c9258abaea85e78ebdda17ef9666d390e987f006be6080dfe354b708cb" dependencies = [ "futures-core", "futures-task", @@ -717,42 +683,42 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc94b64bb39543b4e432f1790b6bf18e3ee3b74653c5449f63310e9a74b123c" +checksum = "6e1798854a4727ff944a7b12aa999f58ce7aa81db80d2dfaaf2ba06f065ddd2b" [[package]] name = "futures-macro" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f57ed14da4603b2554682e9f2ff3c65d7567b53188db96cb71538217fc64581b" +checksum = "e36fccf3fc58563b4a14d265027c627c3b665d7fed489427e88e7cc929559efe" dependencies = [ "proc-macro-hack", "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", ] [[package]] name = "futures-sink" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d8764258ed64ebc5d9ed185cf86a95db5cac810269c5d20ececb32e0088abbd" +checksum = "0e3ca3f17d6e8804ae5d3df7a7d35b2b3a6fe89dac84b31872720fc3060a0b11" [[package]] name = "futures-task" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dd26820a9f3637f1302da8bceba3ff33adbe53464b54ca24d4e2d4f1db30f94" +checksum = "96d502af37186c4fef99453df03e374683f8a1eec9dcc1e66b3b82dc8278ce3c" dependencies = [ "once_cell", ] [[package]] name = "futures-util" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a894a0acddba51a2d49a6f4263b1e64b8c579ece8af50fa86503d52cd1eea34" +checksum = "abcb44342f62e6f3e8ac427b8aa815f724fd705dfad060b18ac7866c15bb8e34" dependencies = [ "futures-channel", "futures-core", @@ -777,6 +743,19 @@ dependencies = [ "byteorder", ] +[[package]] +name = "generator" +version = "0.6.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cdc09201b2e8ca1b19290cf7e65de2246b8e91fb6874279722189c4de7b94dc" +dependencies = [ + "cc", + "libc", + "log", + "rustc_version", + "winapi 0.3.9", +] + [[package]] name = "getrandom" version = "0.1.15" @@ -801,9 +780,9 @@ dependencies = [ [[package]] name = "gfx-backend-dx11" -version = "0.6.9" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a41af35d83b4ddc3179a9b3e00c03e874e15c50af439b8ad93312817750509" +checksum = "b0105746c65b502f6629b7e1acc3610a7726a2f8b37229119fb774d48af174dd" dependencies = [ "arrayvec", "bitflags", @@ -811,7 +790,7 @@ dependencies = [ "gfx-hal", "libloading", "log", - "parking_lot 0.11.0", + "parking_lot", "range-alloc", "raw-window-handle", "smallvec", @@ -870,7 +849,7 @@ dependencies = [ "log", "metal", "objc", - "parking_lot 0.11.0", + "parking_lot", "range-alloc", "raw-window-handle", "smallvec", @@ -971,11 +950,11 @@ checksum = "dd01a2a73f2f399df96b22dc88ea687ef4d76226284e7531ae3c7ee1dc5cb534" [[package]] name = "instant" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63312a18f7ea8760cdd0a7c5aac1a619752a246b833545e3e36d1f81f7cd9e66" +checksum = "cb1fc4429a33e1f80d41dc9fea4d108a88bec1de8053878898ae448a0b52f613" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -1044,47 +1023,20 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" +checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" [[package]] name = "libloading" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3557c9384f7f757f6d139cd3a4c62ef4e850696c16bf27924a5538c8a09717a1" +checksum = "1090080fe06ec2648d0da3881d9453d97e71a45f00eb179af7fdd7e3f686fdb0" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "winapi 0.3.9", ] -[[package]] -name = "line_drawing" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc7ad3d82c845bdb5dde34ffdcc7a5fb4d2996e1e1ee0f19c33bc80e15196b9" -dependencies = [ - "num-traits 0.2.12", -] - -[[package]] -name = "line_drawing" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81902e542483002b103c6424d23e765c2e5a65f732923299053a601bce50ab2" -dependencies = [ - "num-traits 0.1.43", -] - -[[package]] -name = "lock_api" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" -dependencies = [ - "scopeguard", -] - [[package]] name = "lock_api" version = "0.4.1" @@ -1103,6 +1055,19 @@ dependencies = [ "cfg-if 0.1.10", ] +[[package]] +name = "loom" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0e8460f2f2121162705187214720353c517b97bdfb3494c0b1e33d83ebe4bed" +dependencies = [ + "cfg-if 0.1.10", + "generator", + "scoped-tls", + "serde", + "serde_json", +] + [[package]] name = "malloc_buf" version = "0.0.6" @@ -1129,9 +1094,9 @@ checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] name = "memchr" -version = "2.3.3" +version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] name = "memmap" @@ -1237,22 +1202,11 @@ dependencies = [ "bitflags", "fxhash", "log", - "num-traits 0.2.12", + "num-traits", "spirv_headers 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror", ] -[[package]] -name = "ndk" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a356cafe20aee088789830bfea3a61336e84ded9e545e00d3869ce95dcb80c" -dependencies = [ - "jni-sys", - "ndk-sys 0.1.0", - "num_enum", -] - [[package]] name = "ndk" version = "0.2.1" @@ -1260,25 +1214,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5eb167c1febed0a496639034d0c76b3b74263636045db5489eee52143c246e73" dependencies = [ "jni-sys", - "ndk-sys 0.2.1", + "ndk-sys", "num_enum", "thiserror", ] -[[package]] -name = "ndk-glue" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1730ee2e3de41c3321160a6da815f008c4006d71b095880ea50e17cf52332b8" -dependencies = [ - "android_log-sys", - "lazy_static", - "libc", - "log", - "ndk 0.1.0", - "ndk-sys 0.1.0", -] - [[package]] name = "ndk-glue" version = "0.2.1" @@ -1288,9 +1228,9 @@ dependencies = [ "lazy_static", "libc", "log", - "ndk 0.2.1", + "ndk", "ndk-macro", - "ndk-sys 0.2.1", + "ndk-sys", ] [[package]] @@ -1303,15 +1243,9 @@ dependencies = [ "proc-macro-crate", "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", ] -[[package]] -name = "ndk-sys" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2820aca934aba5ed91c79acc72b6a44048ceacc5d36c035ed4e051f12d887d" - [[package]] name = "ndk-sys" version = "0.2.1" @@ -1329,19 +1263,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "nix" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce" -dependencies = [ - "bitflags", - "cc", - "cfg-if 0.1.10", - "libc", - "void", -] - [[package]] name = "nix" version = "0.17.0" @@ -1385,44 +1306,35 @@ checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" dependencies = [ "num-integer", "num-iter", - "num-traits 0.2.12", + "num-traits", ] [[package]] name = "num-integer" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ "autocfg 1.0.1", - "num-traits 0.2.12", + "num-traits", ] [[package]] name = "num-iter" -version = "0.1.41" +version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e6b7c748f995c4c29c5f5ae0248536e04a5739927c74ec0fa564805094b9f" +checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" dependencies = [ "autocfg 1.0.1", "num-integer", - "num-traits 0.2.12", -] - -[[package]] -name = "num-traits" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" -dependencies = [ - "num-traits 0.2.12", + "num-traits", ] [[package]] name = "num-traits" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ "autocfg 1.0.1", ] @@ -1456,7 +1368,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", ] [[package]] @@ -1494,15 +1406,6 @@ dependencies = [ "sdl2", ] -[[package]] -name = "ordered-float" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3741934be594d77de1c8461ebcbbe866f585ea616a9753aa78f2bdc69f0e4579" -dependencies = [ - "num-traits 0.2.12", -] - [[package]] name = "output_vt100" version = "0.1.2" @@ -1521,16 +1424,6 @@ dependencies = [ "ttf-parser", ] -[[package]] -name = "parking_lot" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" -dependencies = [ - "lock_api 0.3.4", - "parking_lot_core 0.7.2", -] - [[package]] name = "parking_lot" version = "0.11.0" @@ -1538,22 +1431,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4893845fa2ca272e647da5d0e46660a314ead9c2fdd9a883aabc32e481a8733" dependencies = [ "instant", - "lock_api 0.4.1", - "parking_lot_core 0.8.0", -] - -[[package]] -name = "parking_lot_core" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" -dependencies = [ - "cfg-if 0.1.10", - "cloudabi 0.0.3", - "libc", - "redox_syscall", - "smallvec", - "winapi 0.3.9", + "lock_api", + "parking_lot_core", ] [[package]] @@ -1579,22 +1458,22 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project" -version = "0.4.27" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" +checksum = "ee41d838744f60d959d7074e3afb6b35c7456d0f61cad38a24e35e6553f73841" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "0.4.27" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" +checksum = "81a4ffa594b66bff340084d4081df649a7dc049ac8d7fc458d8e628bfbbb2f86" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", ] [[package]] @@ -1651,7 +1530,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", "version_check", ] @@ -1668,9 +1547,9 @@ dependencies = [ [[package]] name = "proc-macro-hack" -version = "0.5.18" +version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro-nested" @@ -1978,7 +1857,7 @@ source = "git+https://github.com/gfx-rs/rspirv.git?rev=f11f8797bd4df2d1d22cf1076 dependencies = [ "derive_more", "fxhash", - "num-traits 0.2.12", + "num-traits", "spirv_headers 1.5.0 (git+https://github.com/gfx-rs/rspirv.git?rev=f11f8797bd4df2d1d22cf10767b39a5119c57551)", ] @@ -2005,26 +1884,6 @@ dependencies = [ "semver", ] -[[package]] -name = "rusttype" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "310942406a39981bed7e12b09182a221a29e0990f3e7e0c971f131922ed135d5" -dependencies = [ - "rusttype 0.8.3", -] - -[[package]] -name = "rusttype" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f61411055101f7b60ecf1041d87fb74205fb20b0c7a723f07ef39174cf6b4c0" -dependencies = [ - "approx", - "ordered-float", - "stb_truetype", -] - [[package]] name = "rusttype" version = "0.9.2" @@ -2118,7 +1977,7 @@ checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", ] [[package]] @@ -2134,11 +1993,28 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.0.9" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06d5a3f5166fb5b42a5439f2eee8b9de149e235961e3eb21c5808fc3ea17ff3e" +checksum = "7b4921be914e16899a80adefb821f8ddb7974e3f1250223575a44ed994882127" dependencies = [ "lazy_static", + "loom", +] + +[[package]] +name = "simplest-shader" +version = "0.1.0" +dependencies = [ + "glam", + "spirv-std", +] + +[[package]] +name = "sky-shader" +version = "0.1.0" +dependencies = [ + "glam", + "spirv-std", ] [[package]] @@ -2153,32 +2029,16 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" -[[package]] -name = "smithay-client-toolkit" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "421c8dc7acf5cb205b88160f8b4cc2c5cfabe210e43b2f80f009f4c1ef910f1d" -dependencies = [ - "andrew 0.2.1", - "bitflags", - "dlib", - "lazy_static", - "memmap", - "nix 0.14.1", - "wayland-client 0.23.6", - "wayland-protocols 0.23.6", -] - [[package]] name = "smithay-client-toolkit" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ec5c077def8af49f9b5aeeb5fcf8079c638c6615c3a8f9305e2dea601de57f7" dependencies = [ - "andrew 0.3.0", + "andrew", "bitflags", "byteorder", - "calloop 0.6.5", + "calloop", "dlib", "lazy_static", "log", @@ -2241,7 +2101,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f5b132530b1ac069df335577e3581765995cba5a13995cdbbdbc8fb057c532c" dependencies = [ "bitflags", - "num-traits 0.2.12", + "num-traits", ] [[package]] @@ -2250,16 +2110,7 @@ version = "1.5.0" source = "git+https://github.com/gfx-rs/rspirv.git?rev=f11f8797bd4df2d1d22cf10767b39a5119c57551#f11f8797bd4df2d1d22cf10767b39a5119c57551" dependencies = [ "bitflags", - "num-traits 0.2.12", -] - -[[package]] -name = "stb_truetype" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f77b6b07e862c66a9f3e62a07588fee67cd90a9135a2b942409f195507b4fb51" -dependencies = [ - "byteorder", + "num-traits", ] [[package]] @@ -2268,7 +2119,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "418bb14643aa55a7841d5303f72cf512cfb323b8cc221d51580500a1ca75206c" dependencies = [ - "lock_api 0.4.1", + "lock_api", ] [[package]] @@ -2304,7 +2155,7 @@ dependencies = [ "proc-macro-error", "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", ] [[package]] @@ -2320,9 +2171,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.46" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad5de3220ea04da322618ded2c42233d02baca219d6f160a3e9c87cda16c942" +checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", @@ -2381,7 +2232,7 @@ checksum = "cae2447b6282786c3493999f40a9be2a6ad20cb8bd268b0a0dbf5a065535c0ab" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", ] [[package]] @@ -2456,7 +2307,7 @@ checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", ] [[package]] @@ -2491,9 +2342,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ef0a5e15477aa303afbfac3a44cba9b6430fdaad52423b1e6c0dbbe28c3eedd" +checksum = "2810660b9d5b18895d140caba6401765749a6a162e5d0736cfc44ea50db9d79d" dependencies = [ "ansi_term 0.12.1", "chrono", @@ -2609,7 +2460,7 @@ dependencies = [ "log", "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", "wasm-bindgen-shared", ] @@ -2643,7 +2494,7 @@ checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.46", + "syn 1.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2654,23 +2505,6 @@ version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307" -[[package]] -name = "wayland-client" -version = "0.23.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af1080ebe0efabcf12aef2132152f616038f2d7dcbbccf7b2d8c5270fe14bcda" -dependencies = [ - "bitflags", - "calloop 0.4.4", - "downcast-rs", - "libc", - "mio", - "nix 0.14.1", - "wayland-commons 0.23.6", - "wayland-scanner 0.23.6", - "wayland-sys 0.23.6", -] - [[package]] name = "wayland-client" version = "0.27.0" @@ -2702,16 +2536,6 @@ dependencies = [ "wayland-sys 0.28.1", ] -[[package]] -name = "wayland-commons" -version = "0.23.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb66b0d1a27c39bbce712b6372131c6e25149f03ffb0cd017cf8f7de8d66dbdb" -dependencies = [ - "nix 0.14.1", - "wayland-sys 0.23.6", -] - [[package]] name = "wayland-commons" version = "0.27.0" @@ -2758,18 +2582,6 @@ dependencies = [ "xcursor", ] -[[package]] -name = "wayland-protocols" -version = "0.23.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cc286643656742777d55dc8e70d144fa4699e426ca8e9d4ef454f4bf15ffcf9" -dependencies = [ - "bitflags", - "wayland-client 0.23.6", - "wayland-commons 0.23.6", - "wayland-scanner 0.23.6", -] - [[package]] name = "wayland-protocols" version = "0.27.0" @@ -2794,17 +2606,6 @@ dependencies = [ "wayland-scanner 0.28.1", ] -[[package]] -name = "wayland-scanner" -version = "0.23.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93b02247366f395b9258054f964fe293ddd019c3237afba9be2ccbe9e1651c3d" -dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "xml-rs", -] - [[package]] name = "wayland-scanner" version = "0.27.0" @@ -2827,16 +2628,6 @@ dependencies = [ "xml-rs", ] -[[package]] -name = "wayland-sys" -version = "0.23.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d94e89a86e6d6d7c7c9b19ebf48a03afaac4af6bc22ae570e9a24124b75358f4" -dependencies = [ - "dlib", - "lazy_static", -] - [[package]] name = "wayland-sys" version = "0.27.0" @@ -2878,7 +2669,7 @@ dependencies = [ "gfx-backend-vulkan", "js-sys", "objc", - "parking_lot 0.11.0", + "parking_lot", "raw-window-handle", "smallvec", "tracing", @@ -2909,7 +2700,7 @@ dependencies = [ "gfx-hal", "gfx-memory", "naga", - "parking_lot 0.11.0", + "parking_lot", "raw-window-handle", "smallvec", "thiserror", @@ -2917,36 +2708,13 @@ dependencies = [ "wgpu-types", ] -[[package]] -name = "wgpu-example-runner" -version = "0.1.0" -dependencies = [ - "console_error_panic_hook", - "console_log", - "futures", - "spirv-builder", - "wasm-bindgen-futures", - "web-sys", - "wgpu", - "wgpu-subscriber", - "winit 0.22.2", -] - -[[package]] -name = "wgpu-example-shader" -version = "0.1.0" -dependencies = [ - "glam", - "spirv-std", -] - [[package]] name = "wgpu-subscriber" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91955b0d6480d86e577bbd0b0d1dd5acd0699c054610dc8673c4c3366295ed27" dependencies = [ - "parking_lot 0.11.0", + "parking_lot", "thread-id", "tracing", "tracing-log", @@ -3005,39 +2773,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "winit" -version = "0.22.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e4ccbf7ddb6627828eace16cacde80fc6bf4dbb3469f88487262a02cf8e7862" -dependencies = [ - "bitflags", - "cocoa 0.20.2", - "core-foundation 0.7.0", - "core-graphics 0.19.2", - "core-video-sys", - "dispatch", - "instant", - "lazy_static", - "libc", - "log", - "mio", - "mio-extras", - "ndk 0.1.0", - "ndk-glue 0.1.0", - "ndk-sys 0.1.0", - "objc", - "parking_lot 0.10.2", - "percent-encoding", - "raw-window-handle", - "smithay-client-toolkit 0.6.6", - "wasm-bindgen", - "wayland-client 0.23.6", - "web-sys", - "winapi 0.3.9", - "x11-dl", -] - [[package]] name = "winit" version = "0.23.0" @@ -3056,15 +2791,17 @@ dependencies = [ "log", "mio", "mio-extras", - "ndk 0.2.1", - "ndk-glue 0.2.1", - "ndk-sys 0.2.1", + "ndk", + "ndk-glue", + "ndk-sys", "objc", - "parking_lot 0.11.0", + "parking_lot", "percent-encoding", "raw-window-handle", - "smithay-client-toolkit 0.12.0", + "smithay-client-toolkit", + "wasm-bindgen", "wayland-client 0.28.1", + "web-sys", "winapi 0.3.9", "x11-dl", ] diff --git a/Cargo.toml b/Cargo.toml index c79635774a..398ce9f63e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,10 @@ [workspace] members = [ - "examples/example-runner-cpu", - "examples/example-runner", - "examples/wgpu-example-runner", - "examples/example-shader", - "examples/wgpu-example-shader", - + "examples/runners/cpu", + "examples/runners/ash", + "examples/runners/wgpu", + "examples/shaders/sky-shader", + "examples/shaders/simplest-shader", "rustc_codegen_spirv", "spirv-builder", "spirv-std", diff --git a/README.md b/README.md index 3400a44762..f4bdf770d5 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ pub fn main_fs(input: Input, mut output: Output) { } ``` -See [source](examples/example-shader/src/lib.rs) for full details. +See [source](examples/shaders/sky-shader/src/lib.rs) for full details. ## Background diff --git a/deny.toml b/deny.toml index 1e1670eb66..e0137f1424 100644 --- a/deny.toml +++ b/deny.toml @@ -37,9 +37,9 @@ skip = [ # by default infinite skip-tree = [ # we don't really care if our example brings in some duplicate dependencies, for now - { name = "example-runner", version = "*", depth = 20 }, + { name = "example-runner-ash", version = "*", depth = 20 }, { name = "example-runner-cpu", version = "*", depth = 20 }, - { name = "wgpu-example-runner", version = "*", depth = 20 }, + { name = "example-runner-wgpu", version = "*", depth = 20 }, ] diff --git a/docs/assets/sky.jpg b/docs/assets/sky.jpg index eb6cf6dd9b..6ed63652ed 100644 Binary files a/docs/assets/sky.jpg and b/docs/assets/sky.jpg differ diff --git a/docs/src/introduction.md b/docs/src/introduction.md index b68a0af556..e3b9e533cf 100644 --- a/docs/src/introduction.md +++ b/docs/src/introduction.md @@ -29,17 +29,17 @@ how to use and develop on Rust-GPU. 1. **optional** Install [SPIRV-Tools](https://github.com/KhronosGroup/SPIRV-Tools#downloads) and add it to your `PATH`. You can skip this step if you just want to run examples with the defaults. See [Using installed SPIRV-Tools](#using-installed-spirv-tools) if you decide to go with this option. -1. Next, look at the [examples](examples) folder. There are two projects here: [examples/example-shader](examples/example-shader) and [examples/example-runner](examples/example-runner). The example-shader project is a "GPU crate", one that will be compiled to a SPIR-V module. The example-runner project is a normal, CPU crate that uses vulkan to consume the example-shader SPIR-V module to display a shader. +1. Next, look at the [examples](examples) folder. There are two kinds of targets here: [runners](examples/runners) and [shaders](examples/shaders). The projects inside `shaders` are "GPU crates", i.e. ones that will be compiled one or more SPIR-V modules. The `runner` projects are normal, CPU crates that use some graphics backend (currently, we have a [`wgpu` runner](examples/runners/wgpu), a [Vulkan runner](examples/runners/ash) through `ash`, and a barebones pure software [CPU runner](examples/runners/cpu)) to actually run one of the "GPU crate" shaders. Run the example: ```shell - cargo run --bin example-runner + cargo run --bin example-runner-wgpu ``` - This will build `rustc_codegen_spirv`, the compiler, then use that compiler to build `example-shader` into a SPIR-V module, then finally, build a vulkan sample app (taken from [ash's examples](https://github.com/MaikKlein/ash/blob/master/examples/src/bin/triangle.rs)) using the built SPIR-V module to display the shader in a window. + This will build `rustc_codegen_spirv`, the compiler, then use that compiler to build [`sky-shader`](examples/shaders/sky-shader) into a SPIR-V module, then finally, build a `wgpu` sample app (modified from [`wgpu`'s examples](https://github.com/gfx-rs/wgpu-rs/tree/master/examples/hello-triangle)) using the built SPIR-V module to display the shader in a window. - All of this is orchestrated by the [spirv-builder](spirv-builder) crate, which is used in example-runner's `build.rs` file. Please look at that file, as well as both example projects in general, to see how to set up your own shaders! + All of this is orchestrated by the [spirv-builder](spirv-builder) crate, which is used in each of the example runners' [`build.rs` files](examples/runners/wgpu/build.rs). Please look at that file, as well as both example projects in general, to see how to set up your own shaders! Be aware that this project is in a very early phase - if the above doesn't work, please [file an issue](https://github.com/EmbarkStudios/rust-gpu/issues)! @@ -62,7 +62,7 @@ cargo build -Z build-std=core --target spirv-unknown-unknown --release This will produce a `target/spirv-unknown-unknown/release/crate_name.spv` file. -To create a GPU crate, look at the [examples/example-shader](examples/example-shader) crate. In short, reference the `spirv-std` crate, and use intrinsics defined there to create your shader. +To create a GPU crate, look at the crates in [examples/shaders](examples/shaders). In short, reference the `spirv-std` crate, and use intrinsics defined there to create your shader. This is all a little convoluted, hence the [spirv-builder](spirv-builder) crate handles a lot of this. diff --git a/examples/example-runner/build.rs b/examples/example-runner/build.rs deleted file mode 100644 index 5f7b5107d3..0000000000 --- a/examples/example-runner/build.rs +++ /dev/null @@ -1,8 +0,0 @@ -use spirv_builder::SpirvBuilder; -use std::error::Error; - -fn main() -> Result<(), Box> { - // This will set the env var `example-shader.spv` to a spir-v file that can be include!()'d - SpirvBuilder::new("../example-shader").build()?; - Ok(()) -} diff --git a/examples/example-runner/Cargo.toml b/examples/runners/ash/Cargo.toml similarity index 85% rename from examples/example-runner/Cargo.toml rename to examples/runners/ash/Cargo.toml index ee4ca501aa..44a772ae85 100644 --- a/examples/example-runner/Cargo.toml +++ b/examples/runners/ash/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "example-runner" +name = "example-runner-ash" version = "0.1.0" authors = ["Embark "] edition = "2018" @@ -22,4 +22,4 @@ winit = "0.23.0" ash-molten = { git = "https://github.com/EmbarkStudios/ash-molten", branch = "moltenvk-1.1.0" } [build-dependencies] -spirv-builder = { path = "../../spirv-builder", default-features = false } +spirv-builder = { path = "../../../spirv-builder", default-features = false } diff --git a/examples/runners/ash/build.rs b/examples/runners/ash/build.rs new file mode 100644 index 0000000000..751efafb5e --- /dev/null +++ b/examples/runners/ash/build.rs @@ -0,0 +1,8 @@ +use spirv_builder::SpirvBuilder; +use std::error::Error; + +fn main() -> Result<(), Box> { + // This will set the env var `sky-shader.spv` to a spir-v file that can be include!()'d + SpirvBuilder::new("../../shaders/sky-shader").build()?; + Ok(()) +} diff --git a/examples/example-runner/src/main.rs b/examples/runners/ash/src/main.rs similarity index 70% rename from examples/example-runner/src/main.rs rename to examples/runners/ash/src/main.rs index 285632eae5..c656c9b595 100644 --- a/examples/example-runner/src/main.rs +++ b/examples/runners/ash/src/main.rs @@ -14,8 +14,6 @@ use std::borrow::Cow; use std::default::Default; use std::ffi::{CStr, CString}; use std::io::Cursor; -use std::mem; -use std::mem::align_of; use std::ops::Drop; use structopt::StructOpt; @@ -188,10 +186,6 @@ pub struct ExampleBase { pub draw_command_buffer: vk::CommandBuffer, pub setup_command_buffer: vk::CommandBuffer, - pub depth_image: vk::Image, - pub depth_image_view: vk::ImageView, - pub depth_image_memory: vk::DeviceMemory, - pub present_complete_semaphore: vk::Semaphore, pub rendering_complete_semaphore: vk::Semaphore, @@ -367,16 +361,18 @@ impl ExampleBase { let surface_formats = surface_loader .get_physical_device_surface_formats(pdevice, surface) .unwrap(); - let surface_format = surface_formats + let acceptable_formats = { + [ + vk::Format::R8G8B8_SRGB, + vk::Format::B8G8R8_SRGB, + vk::Format::R8G8B8A8_SRGB, + vk::Format::B8G8R8A8_SRGB, + vk::Format::A8B8G8R8_SRGB_PACK32, + ] + }; + let surface_format = *surface_formats .iter() - .map(|sfmt| match sfmt.format { - vk::Format::UNDEFINED => vk::SurfaceFormatKHR { - format: vk::Format::B8G8R8_UNORM, - color_space: sfmt.color_space, - }, - _ => *sfmt, - }) - .next() + .find(|sfmt| acceptable_formats.contains(&sfmt.format)) .expect("Unable to find suitable surface format."); let surface_capabilities = surface_loader .get_physical_device_surface_capabilities(pdevice, surface) @@ -472,41 +468,6 @@ impl ExampleBase { }) .collect(); let device_memory_properties = instance.get_physical_device_memory_properties(pdevice); - let depth_image_create_info = vk::ImageCreateInfo::builder() - .image_type(vk::ImageType::TYPE_2D) - .format(vk::Format::D16_UNORM) - .extent(vk::Extent3D { - width: surface_resolution.width, - height: surface_resolution.height, - depth: 1, - }) - .mip_levels(1) - .array_layers(1) - .samples(vk::SampleCountFlags::TYPE_1) - .tiling(vk::ImageTiling::OPTIMAL) - .usage(vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT) - .sharing_mode(vk::SharingMode::EXCLUSIVE); - - let depth_image = device.create_image(&depth_image_create_info, None).unwrap(); - let depth_image_memory_req = device.get_image_memory_requirements(depth_image); - let depth_image_memory_index = find_memorytype_index( - &depth_image_memory_req, - &device_memory_properties, - vk::MemoryPropertyFlags::DEVICE_LOCAL, - ) - .expect("Unable to find suitable memory index for depth image."); - - let depth_image_allocate_info = vk::MemoryAllocateInfo::builder() - .allocation_size(depth_image_memory_req.size) - .memory_type_index(depth_image_memory_index); - - let depth_image_memory = device - .allocate_memory(&depth_image_allocate_info, None) - .unwrap(); - - device - .bind_image_memory(depth_image, depth_image_memory, 0) - .expect("Unable to bind depth image memory"); let fence_create_info = vk::FenceCreateInfo::builder().flags(vk::FenceCreateFlags::SIGNALED); @@ -518,59 +479,6 @@ impl ExampleBase { .create_fence(&fence_create_info, None) .expect("Create fence failed."); - record_submit_commandbuffer( - &device, - setup_command_buffer, - setup_commands_reuse_fence, - present_queue, - &[], - &[], - &[], - |device, setup_command_buffer| { - let layout_transition_barriers = vk::ImageMemoryBarrier::builder() - .image(depth_image) - .dst_access_mask( - vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_READ - | vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_WRITE, - ) - .new_layout(vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL) - .old_layout(vk::ImageLayout::UNDEFINED) - .subresource_range( - vk::ImageSubresourceRange::builder() - .aspect_mask(vk::ImageAspectFlags::DEPTH) - .layer_count(1) - .level_count(1) - .build(), - ); - - device.cmd_pipeline_barrier( - setup_command_buffer, - vk::PipelineStageFlags::BOTTOM_OF_PIPE, - vk::PipelineStageFlags::LATE_FRAGMENT_TESTS, - vk::DependencyFlags::empty(), - &[], - &[], - &[layout_transition_barriers.build()], - ); - }, - ); - - let depth_image_view_info = vk::ImageViewCreateInfo::builder() - .subresource_range( - vk::ImageSubresourceRange::builder() - .aspect_mask(vk::ImageAspectFlags::DEPTH) - .level_count(1) - .layer_count(1) - .build(), - ) - .image(depth_image) - .format(depth_image_create_info.format) - .view_type(vk::ImageViewType::TYPE_2D); - - let depth_image_view = device - .create_image_view(&depth_image_view_info, None) - .unwrap(); - let semaphore_create_info = vk::SemaphoreCreateInfo::default(); let present_complete_semaphore = device @@ -599,8 +507,6 @@ impl ExampleBase { pool, draw_command_buffer, setup_command_buffer, - depth_image, - depth_image_view, present_complete_semaphore, rendering_complete_semaphore, draw_commands_reuse_fence, @@ -608,7 +514,6 @@ impl ExampleBase { surface, debug_call_back, debug_utils_loader, - depth_image_memory, }; (result, events_loop) } @@ -627,9 +532,6 @@ impl Drop for ExampleBase { .destroy_fence(self.draw_commands_reuse_fence, None); self.device .destroy_fence(self.setup_commands_reuse_fence, None); - self.device.free_memory(self.depth_image_memory, None); - self.device.destroy_image_view(self.depth_image_view, None); - self.device.destroy_image(self.depth_image, None); for &image_view in self.present_image_views.iter() { self.device.destroy_image_view(image_view, None); } @@ -650,12 +552,6 @@ impl Drop for ExampleBase { } } -#[derive(Clone, Debug, Copy)] -struct Vertex { - pos: [f32; 4], - color: [f32; 4], -} - #[derive(Debug, StructOpt)] #[structopt()] pub struct Options { @@ -669,32 +565,18 @@ fn main() { unsafe { let (base, events_loop) = ExampleBase::new(1920, 1080, &options); - let renderpass_attachments = [ - vk::AttachmentDescription { - format: base.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 renderpass_attachments = [vk::AttachmentDescription { + format: base.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() + }]; 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, @@ -706,7 +588,6 @@ fn main() { let subpasses = [vk::SubpassDescription::builder() .color_attachments(&color_attachment_refs) - .depth_stencil_attachment(&depth_attachment_ref) .pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS) .build()]; @@ -724,7 +605,7 @@ fn main() { .present_image_views .iter() .map(|&present_image_view| { - let framebuffer_attachments = [present_image_view, base.depth_image_view]; + let framebuffer_attachments = [present_image_view]; let frame_buffer_create_info = vk::FramebufferCreateInfo::builder() .render_pass(renderpass) .attachments(&framebuffer_attachments) @@ -738,124 +619,7 @@ fn main() { }) .collect(); - let index_buffer_data = [0u32, 1, 2, 1, 2, 3]; - let index_buffer_info = vk::BufferCreateInfo::builder() - .size(std::mem::size_of_val(&index_buffer_data) as u64) - .usage(vk::BufferUsageFlags::INDEX_BUFFER) - .sharing_mode(vk::SharingMode::EXCLUSIVE); - - let index_buffer = base.device.create_buffer(&index_buffer_info, None).unwrap(); - let index_buffer_memory_req = base.device.get_buffer_memory_requirements(index_buffer); - let index_buffer_memory_index = find_memorytype_index( - &index_buffer_memory_req, - &base.device_memory_properties, - vk::MemoryPropertyFlags::HOST_VISIBLE | vk::MemoryPropertyFlags::HOST_COHERENT, - ) - .expect("Unable to find suitable memorytype for the index buffer."); - - let index_allocate_info = vk::MemoryAllocateInfo { - allocation_size: index_buffer_memory_req.size, - memory_type_index: index_buffer_memory_index, - ..Default::default() - }; - let index_buffer_memory = base - .device - .allocate_memory(&index_allocate_info, None) - .unwrap(); - let index_ptr = base - .device - .map_memory( - index_buffer_memory, - 0, - index_buffer_memory_req.size, - vk::MemoryMapFlags::empty(), - ) - .unwrap(); - let mut index_slice = Align::new( - index_ptr, - align_of::() as u64, - index_buffer_memory_req.size, - ); - index_slice.copy_from_slice(&index_buffer_data); - base.device.unmap_memory(index_buffer_memory); - base.device - .bind_buffer_memory(index_buffer, index_buffer_memory, 0) - .unwrap(); - - let vertices = [ - Vertex { - pos: [-1.0, 1.0, 0.0, 1.0], - color: [0.0, 1.0, 0.0, 1.0], - }, - Vertex { - pos: [1.0, 1.0, 0.0, 1.0], - color: [0.0, 0.0, 1.0, 1.0], - }, - Vertex { - pos: [-1.0, -1.0, 0.0, 1.0], - color: [1.0, 0.0, 0.0, 1.0], - }, - Vertex { - pos: [1.0, -1.0, 0.0, 1.0], - color: [1.0, 1.0, 1.0, 1.0], - }, - ]; - - let vertex_input_buffer_info = vk::BufferCreateInfo { - size: std::mem::size_of_val(&vertices) as u64 as u64, - usage: vk::BufferUsageFlags::VERTEX_BUFFER, - sharing_mode: vk::SharingMode::EXCLUSIVE, - ..Default::default() - }; - - let vertex_input_buffer = base - .device - .create_buffer(&vertex_input_buffer_info, None) - .unwrap(); - - let vertex_input_buffer_memory_req = base - .device - .get_buffer_memory_requirements(vertex_input_buffer); - - let vertex_input_buffer_memory_index = find_memorytype_index( - &vertex_input_buffer_memory_req, - &base.device_memory_properties, - vk::MemoryPropertyFlags::HOST_VISIBLE | vk::MemoryPropertyFlags::HOST_COHERENT, - ) - .expect("Unable to find suitable memorytype for the vertex buffer."); - - let vertex_buffer_allocate_info = vk::MemoryAllocateInfo { - allocation_size: vertex_input_buffer_memory_req.size, - memory_type_index: vertex_input_buffer_memory_index, - ..Default::default() - }; - - let vertex_input_buffer_memory = base - .device - .allocate_memory(&vertex_buffer_allocate_info, None) - .unwrap(); - - let vert_ptr = base - .device - .map_memory( - vertex_input_buffer_memory, - 0, - vertex_input_buffer_memory_req.size, - vk::MemoryMapFlags::empty(), - ) - .unwrap(); - - let mut vert_align = Align::new( - vert_ptr, - align_of::() as u64, - vertex_input_buffer_memory_req.size, - ); - vert_align.copy_from_slice(&vertices); - base.device.unmap_memory(vertex_input_buffer_memory); - base.device - .bind_buffer_memory(vertex_input_buffer, vertex_input_buffer_memory, 0) - .unwrap(); - let mut spv_file = Cursor::new(&include_bytes!(env!("example_shader.spv"))[..]); + let mut spv_file = Cursor::new(&include_bytes!(env!("sky_shader.spv"))[..]); let code = read_spv(&mut spv_file).expect("Failed to read spv file"); let shader_info = vk::ShaderModuleCreateInfo::builder().code(&code); @@ -888,31 +652,10 @@ fn main() { ..Default::default() }, ]; - let vertex_input_binding_descriptions = [vk::VertexInputBindingDescription { - binding: 0, - stride: mem::size_of::() as u32, - input_rate: vk::VertexInputRate::VERTEX, - }]; - let vertex_input_attribute_descriptions = [ - vk::VertexInputAttributeDescription { - location: 0, - binding: 0, - format: vk::Format::R32G32B32A32_SFLOAT, - offset: offset_of!(Vertex, pos) as u32, - }, - vk::VertexInputAttributeDescription { - location: 1, - binding: 0, - format: vk::Format::R32G32B32A32_SFLOAT, - offset: offset_of!(Vertex, color) as u32, - }, - ]; let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo { - vertex_attribute_description_count: vertex_input_attribute_descriptions.len() as u32, - p_vertex_attribute_descriptions: vertex_input_attribute_descriptions.as_ptr(), - vertex_binding_description_count: vertex_input_binding_descriptions.len() as u32, - p_vertex_binding_descriptions: vertex_input_binding_descriptions.as_ptr(), + vertex_attribute_description_count: 0, + vertex_binding_description_count: 0, ..Default::default() }; let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo { @@ -921,9 +664,9 @@ fn main() { }; let viewports = [vk::Viewport { x: 0.0, - y: 0.0, + y: base.surface_resolution.height as f32, width: base.surface_resolution.width as f32, - height: base.surface_resolution.height as f32, + height: -(base.surface_resolution.height as f32), min_depth: 0.0, max_depth: 1.0, }]; @@ -953,9 +696,9 @@ fn main() { ..Default::default() }; let depth_state_info = vk::PipelineDepthStencilStateCreateInfo { - depth_test_enable: 1, - depth_write_enable: 1, - depth_compare_op: vk::CompareOp::LESS_OR_EQUAL, + depth_test_enable: 0, + depth_write_enable: 0, + depth_compare_op: vk::CompareOp::ALWAYS, front: noop_stencil_state, back: noop_stencil_state, max_depth_bounds: 1.0, @@ -1013,19 +756,11 @@ fn main() { vk::Fence::null(), ) .unwrap(); - let clear_values = [ - vk::ClearValue { - color: vk::ClearColorValue { - float32: [0.0, 0.0, 0.0, 0.0], - }, - }, - vk::ClearValue { - depth_stencil: vk::ClearDepthStencilValue { - depth: 1.0, - stencil: 0, - }, + let clear_values = [vk::ClearValue { + color: vk::ClearColorValue { + float32: [0.0, 0.0, 0.0, 0.0], }, - ]; + }]; let render_pass_begin_info = vk::RenderPassBeginInfo::builder() .render_pass(renderpass) @@ -1057,26 +792,7 @@ fn main() { ); device.cmd_set_viewport(draw_command_buffer, 0, &viewports); device.cmd_set_scissor(draw_command_buffer, 0, &scissors); - device.cmd_bind_vertex_buffers( - draw_command_buffer, - 0, - &[vertex_input_buffer], - &[0], - ); - device.cmd_bind_index_buffer( - draw_command_buffer, - index_buffer, - 0, - vk::IndexType::UINT32, - ); - device.cmd_draw_indexed( - draw_command_buffer, - index_buffer_data.len() as u32, - 1, - 0, - 0, - 0, - ); + device.cmd_draw(draw_command_buffer, 3, 1, 0, 0); // Or draw without the index buffer // device.cmd_draw(draw_command_buffer, 3, 1, 0, 0); device.cmd_end_render_pass(draw_command_buffer); diff --git a/examples/example-runner-cpu/Cargo.toml b/examples/runners/cpu/Cargo.toml similarity index 87% rename from examples/example-runner-cpu/Cargo.toml rename to examples/runners/cpu/Cargo.toml index 07385444b9..f3afb4ee28 100644 --- a/examples/example-runner-cpu/Cargo.toml +++ b/examples/runners/cpu/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" [dependencies] minifb = "0.19.1" # bring in the shader as natively compiled code -example-shader = { path = "../example-shader" } +sky-shader = { path = "../../shaders/sky-shader" } glam = { version = "0.9", default_features = false } # for parallelism, not really needed though diff --git a/examples/example-runner-cpu/src/main.rs b/examples/runners/cpu/src/main.rs similarity index 75% rename from examples/example-runner-cpu/src/main.rs rename to examples/runners/cpu/src/main.rs index acbaeaec28..fc7856fd24 100644 --- a/examples/example-runner-cpu/src/main.rs +++ b/examples/runners/cpu/src/main.rs @@ -3,13 +3,22 @@ use minifb::{Key, Window, WindowOptions}; use rayon::prelude::*; use std::time::Instant; +// apply the srgb OETF (i.e. do "linear to sRGB") +fn srgb_oetf(x: f32) -> f32 { + if x <= 0.0031308 { + x * 12.92 + } else { + 1.055 * x.powf(1.0 / 2.4) - 0.055 + } +} + fn color_u32_from_vec4(v: Vec4) -> u32 { let convert = |f: f32| -> u32 { (f.min(1.0).max(0.0) * 255.0).round() as u32 }; - // this later will also do linear -> sRGB gamma correction for output, - // but currently our shader output is in sRGB so no conversion needed - - convert(v.z()) | convert(v.y()) << 8 | convert(v.x()) << 16 | convert(v.w()) << 24 + convert(srgb_oetf(v.z())) + | convert(srgb_oetf(v.y())) << 8 + | convert(srgb_oetf(v.x())) << 16 + | convert(v.w()) << 24 } fn main() { @@ -34,11 +43,11 @@ fn main() { .map(|i| { let screen_pos = vec2( (i % WIDTH) as f32 / WIDTH as f32 * 2.0 - 1.0, - (i / WIDTH) as f32 / HEIGHT as f32 * 2.0 - 1.0, + -((i / WIDTH) as f32 / HEIGHT as f32 * 2.0 - 1.0), ); // evaluate the fragment shader for the specific pixel - let color = example_shader::fs(screen_pos); + let color = sky_shader::fs(screen_pos); color_u32_from_vec4(color) }) diff --git a/examples/wgpu-example-runner/Cargo.toml b/examples/runners/wgpu/Cargo.toml similarity index 82% rename from examples/wgpu-example-runner/Cargo.toml rename to examples/runners/wgpu/Cargo.toml index 9e9f070fba..9691714ed8 100644 --- a/examples/wgpu-example-runner/Cargo.toml +++ b/examples/runners/wgpu/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wgpu-example-runner" +name = "example-runner-wgpu" version = "0.1.0" authors = ["Embark "] edition = "2018" @@ -14,10 +14,10 @@ use-compiled-tools = ["spirv-builder/use-compiled-tools"] [dependencies] wgpu = "0.6.0" futures = { version = "0.3", default-features = false, features = ["std", "executor"] } -winit = { version = "0.22.1", features = ["web-sys"] } +winit = { version = "0.23", features = ["web-sys"] } [build-dependencies] -spirv-builder = { path = "../../spirv-builder", default-features = false } +spirv-builder = { path = "../../../spirv-builder", default-features = false } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] wgpu-subscriber = "0.1.0" diff --git a/examples/wgpu-example-runner/build.rs b/examples/runners/wgpu/build.rs similarity index 51% rename from examples/wgpu-example-runner/build.rs rename to examples/runners/wgpu/build.rs index 0243f6c665..437f95e628 100644 --- a/examples/wgpu-example-runner/build.rs +++ b/examples/runners/wgpu/build.rs @@ -2,8 +2,8 @@ use spirv_builder::SpirvBuilder; use std::error::Error; fn main() -> Result<(), Box> { - // This will set the env var `wgpu-example-shader.spv` to a spir-v file that can be include!()'d - SpirvBuilder::new("../wgpu-example-shader") + // This will set the env var `sky-shader.spv` to a spir-v file that can be include!()'d + SpirvBuilder::new("../../shaders/sky-shader") .spirv_version(1, 0) .build()?; Ok(()) diff --git a/examples/wgpu-example-runner/src/main.rs b/examples/runners/wgpu/src/main.rs similarity index 99% rename from examples/wgpu-example-runner/src/main.rs rename to examples/runners/wgpu/src/main.rs index 4c7538dbd7..262e44c1b0 100644 --- a/examples/wgpu-example-runner/src/main.rs +++ b/examples/runners/wgpu/src/main.rs @@ -31,7 +31,7 @@ async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu:: .expect("Failed to create device"); // Load the shaders from disk - let module = device.create_shader_module(wgpu::include_spirv!(env!("wgpu_example_shader.spv"))); + let module = device.create_shader_module(wgpu::include_spirv!(env!("sky_shader.spv"))); let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: None, diff --git a/examples/wgpu-example-shader/Cargo.toml b/examples/shaders/simplest-shader/Cargo.toml similarity index 58% rename from examples/wgpu-example-shader/Cargo.toml rename to examples/shaders/simplest-shader/Cargo.toml index 83f22f96a6..235327c200 100644 --- a/examples/wgpu-example-shader/Cargo.toml +++ b/examples/shaders/simplest-shader/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wgpu-example-shader" +name = "simplest-shader" version = "0.1.0" authors = ["Embark "] edition = "2018" @@ -9,5 +9,5 @@ license = "MIT OR Apache-2.0" crate-type = ["dylib"] [dependencies] -spirv-std = { path = "../../spirv-std" } -glam = { version = "0.9", default_features = false } \ No newline at end of file +spirv-std = { path = "../../../spirv-std" } +glam = { version = "0.9", default_features = false } diff --git a/examples/wgpu-example-shader/src/lib.rs b/examples/shaders/simplest-shader/src/lib.rs similarity index 100% rename from examples/wgpu-example-shader/src/lib.rs rename to examples/shaders/simplest-shader/src/lib.rs diff --git a/examples/example-shader/Cargo.toml b/examples/shaders/sky-shader/Cargo.toml similarity index 59% rename from examples/example-shader/Cargo.toml rename to examples/shaders/sky-shader/Cargo.toml index 46c8a796f9..08546320c0 100644 --- a/examples/example-shader/Cargo.toml +++ b/examples/shaders/sky-shader/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "example-shader" +name = "sky-shader" version = "0.1.0" authors = ["Embark "] edition = "2018" @@ -9,5 +9,5 @@ license = "MIT OR Apache-2.0" crate-type = ["dylib"] [dependencies] -spirv-std = { path = "../../spirv-std" } -glam = { version = "0.9", default_features = false } \ No newline at end of file +spirv-std = { path = "../../../spirv-std" } +glam = { version = "0.9", default_features = false } diff --git a/examples/example-shader/src/lib.rs b/examples/shaders/sky-shader/src/lib.rs similarity index 77% rename from examples/example-shader/src/lib.rs rename to examples/shaders/sky-shader/src/lib.rs index 35968a5dd4..93cb79bc46 100644 --- a/examples/example-shader/src/lib.rs +++ b/examples/shaders/sky-shader/src/lib.rs @@ -10,7 +10,6 @@ use glam::{const_vec3, Mat4, Vec2, Vec3, Vec4}; use spirv_std::{Input, MathExt, Output}; const DEPOLARIZATION_FACTOR: f32 = 0.035; -const LUMINANCE: f32 = 1.0; const MIE_COEFFICIENT: f32 = 0.005; const MIE_DIRECTIONAL_G: f32 = 0.8; const MIE_K_COEFFICIENT: Vec3 = const_vec3!([0.686, 0.678, 0.666]); @@ -24,19 +23,16 @@ const REFRACTIVE_INDEX: f32 = 1.0003; const SUN_ANGULAR_DIAMETER_DEGREES: f32 = 0.0093333; const SUN_INTENSITY_FACTOR: f32 = 1000.0; const SUN_INTENSITY_FALLOFF_STEEPNESS: f32 = 1.5; -const TONEMAP_WEIGHTING: Vec3 = const_vec3!([9.50; 3]); const TURBIDITY: f32 = 2.0; // TODO: add this to glam? Rust std has it on f32/f64 fn pow(v: Vec3, power: f32) -> Vec3 { - let v: [f32; 3] = v.into(); - Vec3::new(v[0].pow(power), v[1].pow(power), v[2].pow(power)) + Vec3::new(v.x().pow(power), v.y().pow(power), v.z().pow(power)) } // TODO: add this to glam? Rust std has it on f32/f64 fn exp(v: Vec3) -> Vec3 { - let v: [f32; 3] = v.into(); - Vec3::new(v[0].exp(), v[1].exp(), v[2].exp()) + Vec3::new(v.x().exp(), v.y().exp(), v.z().exp()) } /// Based on: https://seblagarde.wordpress.com/2014/12/01/inverse-trigonometric-functions-gpu-optimization-for-amd-gcn-architecture/ @@ -90,15 +86,15 @@ fn sun_intensity(zenith_angle_cos: f32) -> f32 { ) } -fn uncharted2_tonemap(w: Vec3) -> Vec3 { - const A: Vec3 = const_vec3!([0.15; 3]); // Shoulder strength - const B: Vec3 = const_vec3!([0.50; 3]); // Linear strength - const C: Vec3 = const_vec3!([0.10; 3]); // Linear angle - const D: Vec3 = const_vec3!([0.20; 3]); // Toe strength - const E: Vec3 = const_vec3!([0.02; 3]); // Toe numerator - const F: Vec3 = const_vec3!([0.30; 3]); // Toe denominator +fn tonemap(col: Vec3) -> Vec3 { + // see https://www.desmos.com/calculator/0eo9pzo1at + const A: f32 = 2.35; + const B: f32 = 2.8826666; + const C: f32 = 789.7459; + const D: f32 = 0.935; - ((w * (A * w + C * B) + D * E) / (w * (A * w + B) + D * F)) - E / F + let z = pow(col, A); + z / (pow(z, D) * B + Vec3::splat(C)) } fn sky(dir: Vec3, sun_position: Vec3) -> Vec3 { @@ -149,16 +145,8 @@ fn sky(dir: Vec3, sun_position: Vec3) -> Vec3 { ); let mut l0 = 0.1 * fex; l0 += sun_e * 19000.0 * fex * sundisk; - let mut tex_color = lin + l0; - tex_color *= Vec3::splat(0.04); - tex_color += Vec3::new(0.0, 0.001, 0.0025) * 0.3; - // Tonemapping - let white_scale = 1.0 / uncharted2_tonemap(TONEMAP_WEIGHTING); - let curr = uncharted2_tonemap(((2.0 / LUMINANCE.pow(4.0)).log2()) * tex_color); - let color = curr * white_scale; - - pow(color, 1.0 / (1.2 + (1.2 * sunfade))) + lin + l0 } pub fn fs(screen_pos: Vec2) -> Vec4 { @@ -172,37 +160,45 @@ pub fn fs(screen_pos: Vec2) -> Vec4 { Vec4::new(0.0, -0.14834046, -0.98893654, 0.0), ); - let cs_pos = Vec4::new(screen_pos.x(), -screen_pos.y(), 1.0, 1.0); - let ws_pos = { - let p = clip_to_world.mul_vec4(cs_pos); + let clip_pos = screen_pos.extend(1.0).extend(1.0); + let world_pos = { + let p = clip_to_world.mul_vec4(clip_pos); p.truncate() / p.w() }; - let dir = (ws_pos - eye_pos).normalize(); + let dir = (world_pos - eye_pos).normalize(); // evaluate Preetham sky model let color = sky(dir, sun_pos); - color.extend(1.0) + // Tonemapping + let color = color.max(Vec3::splat(0.0)).min(Vec3::splat(1024.0)); + + tonemap(color).extend(1.0) } #[allow(unused_attributes)] #[spirv(fragment)] -pub fn main_fs(input: Input, mut output: Output) { - let v = input.load(); - let color = fs(Vec2::new(v.x(), v.y())); - output.store(color) +pub fn main_fs(in_pos: Input, mut output: Output) { + let color = fs(in_pos.load()); + output.store(color); } #[allow(unused_attributes)] #[spirv(vertex)] pub fn main_vs( - in_pos: Input, - _in_color: Input, - #[spirv(position)] mut out_pos: Output, - mut out_color: Output, + #[spirv(vertex_index)] vert_idx: Input, + #[spirv(position)] mut builtin_pos: Output, + mut out_pos: Output, ) { - out_pos.store(in_pos.load()); - out_color.store(in_pos.load()); + let vert_idx = vert_idx.load(); + + // Create a "full screen triangle" by mapping the vertex index. + // ported from https://www.saschawillems.de/blog/2016/08/13/vulkan-tutorial-on-rendering-a-fullscreen-quad-without-buffers/ + let uv = Vec2::new(((vert_idx << 1) & 2) as f32, (vert_idx & 2) as f32); + let pos = 2.0 * uv - Vec2::one(); + + builtin_pos.store(pos.extend(0.0).extend(1.0)); + out_pos.store(pos); } #[cfg(all(not(test), target_arch = "spirv"))]