diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 305d22a82..b37f535f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -441,7 +441,9 @@ jobs: **/*-difference.png - name: generate coverage report + id: coverage shell: bash + continue-on-error: true run: | set -e @@ -449,6 +451,7 @@ jobs: - name: upload coverage report to codecov uses: codecov/codecov-action@v3 + if: steps.coverage.outcome == 'success' with: files: lcov.info diff --git a/Cargo.lock b/Cargo.lock index c96e16e70..27f96dd11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,6 +40,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" dependencies = [ "cfg-if", + "getrandom", "once_cell", "version_check", "zerocopy", @@ -62,20 +63,23 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "android-activity" -version = "0.4.3" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64529721f27c2314ced0890ce45e469574a73e5e6fdd6e9da1860eb29285f5e0" +checksum = "052ad56e336bcc615a214bffbeca6c181ee9550acec193f0327e0b103b033a4d" dependencies = [ "android-properties", - "bitflags 1.3.2", + "bitflags 2.4.1", "cc", + "cesu8", + "jni", "jni-sys", "libc", "log", - "ndk", + "ndk 0.8.0", "ndk-context", - "ndk-sys", - "num_enum 0.6.1", + "ndk-sys 0.5.0+25.2.9519653", + "num_enum 0.7.0", + "thiserror", ] [[package]] @@ -214,6 +218,12 @@ dependencies = [ "serde", ] +[[package]] +name = "as-raw-xcb-connection" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d5f312b0a56c5cdf967c0aeb67f6289603354951683bc97ddc595ab974ba9aa" + [[package]] name = "ash" version = "0.37.3+1.3.251" @@ -234,6 +244,12 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.1.0" @@ -319,21 +335,21 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] name = "block-sys" -version = "0.1.0-beta.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa55741ee90902547802152aaf3f8e5248aab7e21468089560d4c8840561146" +checksum = "2dd7cf50912cddc06dc5ea7c08c5e81c1b2c842a70d19def1848d54c586fed92" dependencies = [ "objc-sys", ] [[package]] name = "block2" -version = "0.2.0-alpha.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dd9e63c1744f755c2f60332b88de39d341e5e86239014ad839bd71c106dec42" +checksum = "15b55663a85f33501257357e6421bb33e769d5c9ffb5ba0921c975a123e35e68" dependencies = [ "block-sys", - "objc2-encode", + "objc2", ] [[package]] @@ -388,6 +404,32 @@ dependencies = [ "vec_map", ] +[[package]] +name = "calloop" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b50b5a44d59a98c55a9eeb518f39bf7499ba19fd98ee7d22618687f3f10adbf" +dependencies = [ + "bitflags 2.4.1", + "log", + "polling", + "rustix", + "slab", + "thiserror", +] + +[[package]] +name = "calloop-wayland-source" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f0ea9b9476c7fad82841a8dbb380e2eae480c21910feba80725b46931ed8f02" +dependencies = [ + "calloop 0.12.3", + "rustix", + "wayland-backend", + "wayland-client 0.31.1", +] + [[package]] name = "cast" version = "0.3.0" @@ -404,6 +446,12 @@ dependencies = [ "libc", ] +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cfg-if" version = "1.0.0" @@ -511,7 +559,7 @@ dependencies = [ "block", "cocoa-foundation", "core-foundation", - "core-graphics", + "core-graphics 0.22.3", "foreign-types 0.3.2", "libc", "objc", @@ -559,6 +607,25 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf43edc576402991846b093a7ca18a3477e0ef9c588cde84964b5d3e43016642" +[[package]] +name = "combine" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] +name = "concurrent-queue" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -620,6 +687,19 @@ dependencies = [ "libc", ] +[[package]] +name = "core-graphics" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "970a29baf4110c26fedbc7f82107d42c23f7e88e404c4577ed73fe99ff85a212" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-graphics-types", + "foreign-types 0.5.0", + "libc", +] + [[package]] name = "core-graphics-types" version = "0.1.2" @@ -638,7 +718,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99d74ada66e07c1cefa18f8abfba765b486f250de2e4a999e5727fc0dd4b4a25" dependencies = [ "core-foundation", - "core-graphics", + "core-graphics 0.22.3", "foreign-types 0.3.2", "libc", ] @@ -730,7 +810,7 @@ dependencies = [ "cocoa", "core-foundation", "core-foundation-sys", - "core-graphics", + "core-graphics 0.22.3", "core-text", "dwrote", "foreign-types 0.5.0", @@ -774,6 +854,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" +[[package]] +name = "cursor-icon" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf" + [[package]] name = "d3d12" version = "0.7.0" @@ -968,7 +1054,7 @@ name = "deno_webgpu" version = "0.85.0" dependencies = [ "deno_core", - "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "serde", "tokio", "wgpu-core", @@ -1398,6 +1484,16 @@ dependencies = [ "slab", ] +[[package]] +name = "gethostname" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb65d4ba3173c56a500b555b532f72c42e8d1fe64962b518897f8959fae2c177" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "getrandom" version = "0.2.10" @@ -1466,7 +1562,7 @@ dependencies = [ "osmesa-sys", "parking_lot", "raw-window-handle 0.5.2", - "wayland-client", + "wayland-client 0.29.5", "wayland-egl", "winapi", "winit 0.27.5", @@ -1645,6 +1741,17 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "icrate" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d3aaff8a54577104bafdf686ff18565c3b6903ca5782a2026ef06e2c7aa319" +dependencies = [ + "block2", + "dispatch", + "objc2", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -1731,6 +1838,22 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", + "windows-sys 0.45.0", +] + [[package]] name = "jni-sys" version = "0.3.0" @@ -1905,6 +2028,15 @@ dependencies = [ "libc", ] +[[package]] +name = "memmap2" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "deaba38d7abf1d4cca21cc89e932e542ba2b9258664d2a9ef0e61512039c9375" +dependencies = [ + "libc", +] + [[package]] name = "memoffset" version = "0.6.5" @@ -1914,6 +2046,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memoffset" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +dependencies = [ + "autocfg", +] + [[package]] name = "memoffset" version = "0.9.0" @@ -2048,12 +2189,27 @@ checksum = "451422b7e4718271c8b5b3aadf5adedba43dc76312454b387e98fae0fc951aa0" dependencies = [ "bitflags 1.3.2", "jni-sys", - "ndk-sys", + "ndk-sys 0.4.1+23.1.7779620", "num_enum 0.5.11", "raw-window-handle 0.5.2", "thiserror", ] +[[package]] +name = "ndk" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2076a31b7010b17a38c01907c45b945e8f11495ee4dd588309718901b1f7a5b7" +dependencies = [ + "bitflags 2.4.1", + "jni-sys", + "log", + "ndk-sys 0.5.0+25.2.9519653", + "num_enum 0.7.0", + "raw-window-handle 0.6.0", + "thiserror", +] + [[package]] name = "ndk-context" version = "0.1.1" @@ -2068,10 +2224,10 @@ checksum = "0434fabdd2c15e0aab768ca31d5b7b333717f03cf02037d5a0a3ff3c278ed67f" dependencies = [ "libc", "log", - "ndk", + "ndk 0.7.0", "ndk-context", "ndk-macro", - "ndk-sys", + "ndk-sys 0.4.1+23.1.7779620", "once_cell", "parking_lot", ] @@ -2098,6 +2254,15 @@ dependencies = [ "jni-sys", ] +[[package]] +name = "ndk-sys" +version = "0.5.0+25.2.9519653" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c196769dd60fd4f363e11d948139556a344e79d451aeb2fa2fd040738ef7691" +dependencies = [ + "jni-sys", +] + [[package]] name = "nix" version = "0.24.3" @@ -2123,6 +2288,18 @@ dependencies = [ "memoffset 0.6.5", ] +[[package]] +name = "nix" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "libc", + "memoffset 0.7.1", +] + [[package]] name = "noise" version = "0.8.2" @@ -2206,11 +2383,11 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" +checksum = "70bf6736f74634d299d00086f02986875b3c2d924781a6a2cb6c201e73da0ceb" dependencies = [ - "num_enum_derive 0.6.1", + "num_enum_derive 0.7.0", ] [[package]] @@ -2227,9 +2404,9 @@ dependencies = [ [[package]] name = "num_enum_derive" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" +checksum = "56ea360eafe1022f7cc56cd7b869ed57330fb2453d0c7831d99b74c65d2f5597" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2273,29 +2450,25 @@ dependencies = [ [[package]] name = "objc-sys" -version = "0.2.0-beta.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b9834c1e95694a05a828b59f55fa2afec6288359cda67146126b3f90a55d7" +checksum = "99e1d07c6eab1ce8b6382b8e3c7246fe117ff3f8b34be065f5ebace6749fe845" [[package]] name = "objc2" -version = "0.3.0-beta.3.patch-leaks.3" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e01640f9f2cb1220bbe80325e179e532cb3379ebcd1bf2279d703c19fe3a468" +checksum = "559c5a40fdd30eb5e344fbceacf7595a81e242529fb4e21cf5f43fb4f11ff98d" dependencies = [ - "block2", "objc-sys", "objc2-encode", ] [[package]] name = "objc2-encode" -version = "2.0.0-pre.2" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abfcac41015b00a120608fdaa6938c44cb983fee294351cc4bac7638b4e50512" -dependencies = [ - "objc-sys", -] +checksum = "d079845b37af429bfe5dfa76e6d087d788031045b25cfc6fd898486fd9847666" [[package]] name = "objc_exception" @@ -2461,12 +2634,12 @@ version = "0.18.0" dependencies = [ "env_logger", "log", - "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "ron", "serde", "wgpu-core", "wgpu-types", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -2521,6 +2694,20 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "polling" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62a79e457c9898100b4298d57d69ec53d06f9a6ed352431ce5f377e082d2e846" +dependencies = [ + "cfg-if", + "concurrent-queue", + "pin-project-lite", + "rustix", + "tracing", + "windows-sys 0.48.0", +] + [[package]] name = "pollster" version = "0.3.0" @@ -2567,6 +2754,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f89dff0959d98c9758c88826cc002e2c3d0b9dfac4139711d1f30de442f1139b" +[[package]] +name = "quick-xml" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eff6510e86862b57b210fd8cbe8ed3f0d7d600b9c2863cd4549a2e033c66e956" +dependencies = [ + "memchr", +] + [[package]] name = "quote" version = "1.0.33" @@ -2621,6 +2817,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" +[[package]] +name = "raw-window-handle" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42a9830a0e1b9fb145ebb365b8bc4ccd75f290f98c0247deafbbe2c75cefb544" + [[package]] name = "rayon" version = "1.8.0" @@ -2808,21 +3010,21 @@ checksum = "61270629cc6b4d77ec1907db1033d5c2e1a404c412743621981a871dc9c12339" dependencies = [ "crossfont", "log", - "smithay-client-toolkit", + "smithay-client-toolkit 0.16.1", "tiny-skia 0.7.0", ] [[package]] name = "sctk-adwaita" -version = "0.5.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda4e97be1fd174ccc2aae81c8b694e803fa99b34e8fd0f057a9d70698e3ed09" +checksum = "1729a30a469de249c6effc17ec8d039b0aa29b3af79b819b7f51cb6ab8046a90" dependencies = [ "ab_glyph", "log", - "memmap2", - "smithay-client-toolkit", - "tiny-skia 0.8.4", + "memmap2 0.9.0", + "smithay-client-toolkit 0.18.0", + "tiny-skia 0.11.2", ] [[package]] @@ -2980,16 +3182,50 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "870427e30b8f2cbe64bf43ec4b86e88fe39b0a84b3f15efd9c9c2d020bc86eb9" dependencies = [ "bitflags 1.3.2", - "calloop", + "calloop 0.10.6", "dlib", "lazy_static", "log", - "memmap2", + "memmap2 0.5.10", "nix 0.24.3", "pkg-config", - "wayland-client", - "wayland-cursor", - "wayland-protocols", + "wayland-client 0.29.5", + "wayland-cursor 0.29.5", + "wayland-protocols 0.29.5", +] + +[[package]] +name = "smithay-client-toolkit" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60e3d9941fa3bacf7c2bf4b065304faa14164151254cd16ce1b1bc8fc381600f" +dependencies = [ + "bitflags 2.4.1", + "calloop 0.12.3", + "calloop-wayland-source", + "cursor-icon", + "libc", + "log", + "memmap2 0.9.0", + "rustix", + "thiserror", + "wayland-backend", + "wayland-client 0.31.1", + "wayland-csd-frame", + "wayland-cursor 0.31.0", + "wayland-protocols 0.31.0", + "wayland-protocols-wlr", + "wayland-scanner 0.31.0", + "xkeysym", +] + +[[package]] +name = "smol_str" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74212e6bbe9a4352329b2f68ba3130c15a3f26fe88ff22dbdc6cdd58fa85e99c" +dependencies = [ + "serde", ] [[package]] @@ -3163,16 +3399,16 @@ dependencies = [ [[package]] name = "tiny-skia" -version = "0.8.4" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df8493a203431061e901613751931f047d1971337153f96d0e5e363d6dbf6a67" +checksum = "3b72a92a05db376db09fe6d50b7948d106011761c05a6a45e23e17ee9b556222" dependencies = [ "arrayref", "arrayvec 0.7.4", "bytemuck", "cfg-if", - "png", - "tiny-skia-path 0.8.4", + "log", + "tiny-skia-path 0.11.2", ] [[package]] @@ -3187,9 +3423,9 @@ dependencies = [ [[package]] name = "tiny-skia-path" -version = "0.8.4" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adbfb5d3f3dd57a0e11d12f4f13d4ebbbc1b5c15b7ab0a156d030b21da5f677c" +checksum = "6ac3865b9708fc7e1961a65c3a4fa55e984272f33092d3c859929f887fceb647" dependencies = [ "arrayref", "bytemuck", @@ -3268,6 +3504,22 @@ dependencies = [ "winnow", ] +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" + [[package]] name = "ttf-parser" version = "0.19.2" @@ -3342,6 +3594,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + [[package]] name = "unicode-width" version = "0.1.11" @@ -3537,6 +3795,20 @@ dependencies = [ "quote", ] +[[package]] +name = "wayland-backend" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19152ddd73f45f024ed4534d9ca2594e0ef252c1847695255dae47f34df9fbe4" +dependencies = [ + "cc", + "downcast-rs", + "nix 0.26.4", + "scoped-tls", + "smallvec", + "wayland-sys 0.31.1", +] + [[package]] name = "wayland-client" version = "0.29.5" @@ -3549,8 +3821,20 @@ dependencies = [ "nix 0.24.3", "scoped-tls", "wayland-commons", - "wayland-scanner", - "wayland-sys", + "wayland-scanner 0.29.5", + "wayland-sys 0.29.5", +] + +[[package]] +name = "wayland-client" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ca7d52347346f5473bf2f56705f360e8440873052e575e55890c4fa57843ed3" +dependencies = [ + "bitflags 2.4.1", + "nix 0.26.4", + "wayland-backend", + "wayland-scanner 0.31.0", ] [[package]] @@ -3562,7 +3846,18 @@ dependencies = [ "nix 0.24.3", "once_cell", "smallvec", - "wayland-sys", + "wayland-sys 0.29.5", +] + +[[package]] +name = "wayland-csd-frame" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e" +dependencies = [ + "bitflags 2.4.1", + "cursor-icon", + "wayland-backend", ] [[package]] @@ -3572,7 +3867,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6865c6b66f13d6257bef1cd40cbfe8ef2f150fb8ebbdb1e8e873455931377661" dependencies = [ "nix 0.24.3", - "wayland-client", + "wayland-client 0.29.5", + "xcursor", +] + +[[package]] +name = "wayland-cursor" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44aa20ae986659d6c77d64d808a046996a932aa763913864dc40c359ef7ad5b" +dependencies = [ + "nix 0.26.4", + "wayland-client 0.31.1", "xcursor", ] @@ -3582,8 +3888,8 @@ version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "402de949f81a012926d821a2d659f930694257e76dd92b6e0042ceb27be4107d" dependencies = [ - "wayland-client", - "wayland-sys", + "wayland-client 0.29.5", + "wayland-sys 0.29.5", ] [[package]] @@ -3593,9 +3899,47 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b950621f9354b322ee817a23474e479b34be96c2e909c14f7bc0100e9a970bc6" dependencies = [ "bitflags 1.3.2", - "wayland-client", + "wayland-client 0.29.5", "wayland-commons", - "wayland-scanner", + "wayland-scanner 0.29.5", +] + +[[package]] +name = "wayland-protocols" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e253d7107ba913923dc253967f35e8561a3c65f914543e46843c88ddd729e21c" +dependencies = [ + "bitflags 2.4.1", + "wayland-backend", + "wayland-client 0.31.1", + "wayland-scanner 0.31.0", +] + +[[package]] +name = "wayland-protocols-plasma" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23803551115ff9ea9bce586860c5c5a971e360825a0309264102a9495a5ff479" +dependencies = [ + "bitflags 2.4.1", + "wayland-backend", + "wayland-client 0.31.1", + "wayland-protocols 0.31.0", + "wayland-scanner 0.31.0", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" +dependencies = [ + "bitflags 2.4.1", + "wayland-backend", + "wayland-client 0.31.1", + "wayland-protocols 0.31.0", + "wayland-scanner 0.31.0", ] [[package]] @@ -3609,6 +3953,17 @@ dependencies = [ "xml-rs", ] +[[package]] +name = "wayland-scanner" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb8e28403665c9f9513202b7e1ed71ec56fde5c107816843fb14057910b2c09c" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + [[package]] name = "wayland-sys" version = "0.29.5" @@ -3620,6 +3975,18 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "wayland-sys" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a0c8eaff5216d07f226cb7a549159267f3467b289d9a2e52fd3ef5aae2b7af" +dependencies = [ + "dlib", + "log", + "once_cell", + "pkg-config", +] + [[package]] name = "web-sys" version = "0.3.64" @@ -3630,6 +3997,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57099a701fb3a8043f993e8228dc24229c7b942e2b009a1b962e54489ba1d3bf" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "wgpu" version = "0.18.0" @@ -3642,7 +4019,7 @@ dependencies = [ "naga", "parking_lot", "profiling", - "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "serde", "smallvec", "static_assertions", @@ -3664,7 +4041,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -3679,7 +4056,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -3690,7 +4067,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -3705,7 +4082,7 @@ dependencies = [ "naga", "parking_lot", "profiling", - "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "ron", "rustc-hash", "serde", @@ -3726,7 +4103,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -3746,7 +4123,7 @@ dependencies = [ "wgpu", "wgpu-hal", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -3782,7 +4159,7 @@ dependencies = [ "parking_lot", "profiling", "range-alloc", - "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "renderdoc-sys", "rustc-hash", "smallvec", @@ -3791,7 +4168,7 @@ dependencies = [ "web-sys", "wgpu-types", "winapi", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -3809,7 +4186,7 @@ dependencies = [ "wasm-bindgen-test", "wgpu", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -3858,7 +4235,7 @@ dependencies = [ "wasm-bindgen-futures", "web-sys", "wgpu", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -3870,7 +4247,7 @@ dependencies = [ "env_logger", "pollster", "wgpu", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -3923,7 +4300,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -3937,7 +4314,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -3957,7 +4334,7 @@ dependencies = [ "web-sys", "wgpu", "wgpu-example", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -3990,7 +4367,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -4006,7 +4383,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -4018,7 +4395,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -4065,7 +4442,7 @@ dependencies = [ "parking_lot", "png", "pollster", - "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "serde", "serde_json", "wasm-bindgen", @@ -4086,7 +4463,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -4104,7 +4481,7 @@ dependencies = [ "wasm-bindgen-test", "wgpu", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -4132,7 +4509,7 @@ dependencies = [ "wasm-bindgen-futures", "web-sys", "wgpu", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -4147,7 +4524,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit 0.28.7", + "winit 0.29.2", ] [[package]] @@ -4193,6 +4570,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "winapi-wsapoll" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -4402,13 +4788,13 @@ dependencies = [ "bitflags 1.3.2", "cocoa", "core-foundation", - "core-graphics", + "core-graphics 0.22.3", "dispatch", "instant", "libc", "log", "mio", - "ndk", + "ndk 0.7.0", "ndk-glue", "objc", "once_cell", @@ -4417,10 +4803,10 @@ dependencies = [ "raw-window-handle 0.4.3", "raw-window-handle 0.5.2", "sctk-adwaita 0.4.3", - "smithay-client-toolkit", + "smithay-client-toolkit 0.16.1", "wasm-bindgen", - "wayland-client", - "wayland-protocols", + "wayland-client 0.29.5", + "wayland-protocols 0.29.5", "web-sys", "windows-sys 0.36.1", "x11-dl", @@ -4428,37 +4814,50 @@ dependencies = [ [[package]] name = "winit" -version = "0.28.7" +version = "0.29.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9596d90b45384f5281384ab204224876e8e8bf7d58366d9b795ad99aa9894b94" +checksum = "b829f75d02fe1e225b97c91a04c326900147a50234d1141a1cbe215ce8798c11" dependencies = [ + "ahash", "android-activity", - "bitflags 1.3.2", + "atomic-waker", + "bitflags 2.4.1", + "bytemuck", + "calloop 0.12.3", "cfg_aliases", "core-foundation", - "core-graphics", - "dispatch", - "instant", + "core-graphics 0.23.1", + "cursor-icon", + "icrate", + "js-sys", "libc", "log", - "mio", - "ndk", + "memmap2 0.9.0", + "ndk 0.8.0", + "ndk-sys 0.5.0+25.2.9519653", "objc2", "once_cell", "orbclient", "percent-encoding", - "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "redox_syscall 0.3.5", - "sctk-adwaita 0.5.4", - "smithay-client-toolkit", + "rustix", + "sctk-adwaita 0.7.0", + "smithay-client-toolkit 0.18.0", + "smol_str", + "unicode-segmentation", "wasm-bindgen", - "wayland-client", - "wayland-commons", - "wayland-protocols", - "wayland-scanner", + "wasm-bindgen-futures", + "wayland-backend", + "wayland-client 0.31.1", + "wayland-protocols 0.31.0", + "wayland-protocols-plasma", "web-sys", - "windows-sys 0.45.0", + "web-time", + "windows-sys 0.48.0", "x11-dl", + "x11rb", + "xkbcommon-dl", ] [[package]] @@ -4490,6 +4889,32 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "x11rb" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1641b26d4dec61337c35a1b1aaf9e3cba8f46f0b43636c609ab0291a648040a" +dependencies = [ + "as-raw-xcb-connection", + "gethostname", + "libc", + "libloading 0.7.4", + "nix 0.26.4", + "once_cell", + "winapi", + "winapi-wsapoll", + "x11rb-protocol", +] + +[[package]] +name = "x11rb-protocol" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82d6c3f9a0fb6701fab8f6cea9b0c0bd5d6876f1f89f7fada07e558077c344bc" +dependencies = [ + "nix 0.26.4", +] + [[package]] name = "xcursor" version = "0.3.4" @@ -4499,6 +4924,25 @@ dependencies = [ "nom", ] +[[package]] +name = "xkbcommon-dl" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6924668544c48c0133152e7eec86d644a056ca3d09275eb8d5cdb9855f9d8699" +dependencies = [ + "bitflags 2.4.1", + "dlib", + "log", + "once_cell", + "xkeysym", +] + +[[package]] +name = "xkeysym" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054a8e68b76250b253f671d1268cb7f1ae089ec35e195b2efb2a4e9a836d0621" + [[package]] name = "xml-rs" version = "0.8.19" diff --git a/Cargo.toml b/Cargo.toml index e6549bb15..0280d0752 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -109,7 +109,7 @@ pico-args = { version = "0.5.0", features = [ png = "0.17.10" pollster = "0.3" profiling = { version = "1", default-features = false } -raw-window-handle = "0.5" +raw-window-handle = "0.6" renderdoc-sys = "1.0.0" ron = "0.8" serde = "1" @@ -123,7 +123,7 @@ wgpu-example = { version = "0.18.0", path = "./examples/common" } wgpu-macros = { version = "0.18.0", path = "./wgpu-macros" } wgpu-test = { version = "0.18.0", path = "./tests" } wgpu-types = { version = "0.18.0", path = "./wgpu-types" } -winit = { version = "0.28.7", features = ["android-native-activity"] } +winit = { version = "0.29.2", features = [ "android-native-activity" ] } # Metal dependencies block = "0.1" diff --git a/examples/bunnymark/src/main.rs b/examples/bunnymark/src/main.rs index 1dbd74125..28417246c 100644 --- a/examples/bunnymark/src/main.rs +++ b/examples/bunnymark/src/main.rs @@ -2,6 +2,10 @@ use bytemuck::{Pod, Zeroable}; use nanorand::{Rng, WyRand}; use std::{borrow::Cow, mem}; use wgpu::util::DeviceExt; +use winit::{ + event::{ElementState, KeyEvent}, + keyboard::{Key, NamedKey}, +}; const MAX_BUNNIES: usize = 1 << 20; const BUNNY_SIZE: f32 = 0.15 * 256.0; @@ -18,24 +22,115 @@ struct Globals { #[repr(C, align(256))] #[derive(Clone, Copy, Zeroable)] -struct Locals { +struct Bunny { position: [f32; 2], velocity: [f32; 2], color: u32, _pad: u32, } +impl Bunny { + fn update_data(&mut self, delta: f32, extent: &[u32; 2]) { + self.position[0] += self.velocity[0] * delta; + self.position[1] += self.velocity[1] * delta; + self.velocity[1] += GRAVITY * delta; + if (self.velocity[0] > 0.0 && self.position[0] + 0.5 * BUNNY_SIZE > extent[0] as f32) + || (self.velocity[0] < 0.0 && self.position[0] - 0.5 * BUNNY_SIZE < 0.0) + { + self.velocity[0] *= -1.0; + } + if self.velocity[1] < 0.0 && self.position[1] < 0.5 * BUNNY_SIZE { + self.velocity[1] *= -1.0; + } + } +} + /// Example struct holds references to wgpu resources and frame persistent data struct Example { global_group: wgpu::BindGroup, local_group: wgpu::BindGroup, pipeline: wgpu::RenderPipeline, - bunnies: Vec, + bunnies: Vec, local_buffer: wgpu::Buffer, extent: [u32; 2], rng: WyRand, } +impl Example { + fn spawn_bunnies(&mut self) { + let spawn_count = 64 + self.bunnies.len() / 2; + let color = self.rng.generate::(); + println!( + "Spawning {} bunnies, total at {}", + spawn_count, + self.bunnies.len() + spawn_count + ); + for _ in 0..spawn_count { + let speed = self.rng.generate::() * MAX_VELOCITY - (MAX_VELOCITY * 0.5); + self.bunnies.push(Bunny { + position: [0.0, 0.5 * (self.extent[1] as f32)], + velocity: [speed, 0.0], + color, + _pad: 0, + }); + } + } + + fn render_inner( + &mut self, + view: &wgpu::TextureView, + device: &wgpu::Device, + queue: &wgpu::Queue, + ) { + let delta = 0.01; + for bunny in self.bunnies.iter_mut() { + bunny.update_data(delta, &self.extent); + } + + let uniform_alignment = device.limits().min_uniform_buffer_offset_alignment; + queue.write_buffer(&self.local_buffer, 0, unsafe { + std::slice::from_raw_parts( + self.bunnies.as_ptr() as *const u8, + self.bunnies.len() * uniform_alignment as usize, + ) + }); + + let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); + { + let clear_color = wgpu::Color { + r: 0.1, + g: 0.2, + b: 0.3, + a: 1.0, + }; + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[Some(wgpu::RenderPassColorAttachment { + view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(clear_color), + store: wgpu::StoreOp::Store, + }, + })], + depth_stencil_attachment: None, + timestamp_writes: None, + occlusion_query_set: None, + }); + rpass.set_pipeline(&self.pipeline); + rpass.set_bind_group(0, &self.global_group, &[]); + for i in 0..self.bunnies.len() { + let offset = + (i as wgpu::DynamicOffset) * (uniform_alignment as wgpu::DynamicOffset); + rpass.set_bind_group(1, &self.local_group, &[offset]); + rpass.draw(0..4, 0..1); + } + } + + queue.submit(Some(encoder.finish())); + } +} + impl wgpu_example::framework::Example for Example { fn init( config: &wgpu::SurfaceConfiguration, @@ -90,7 +185,7 @@ impl wgpu_example::framework::Example for Example { ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: true, - min_binding_size: wgpu::BufferSize::new(mem::size_of::() as _), + min_binding_size: wgpu::BufferSize::new(mem::size_of::() as _), }, count: None, }], @@ -228,7 +323,7 @@ impl wgpu_example::framework::Example for Example { resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding { buffer: &local_buffer, offset: 0, - size: wgpu::BufferSize::new(mem::size_of::() as _), + size: wgpu::BufferSize::new(mem::size_of::() as _), }), }], label: None, @@ -249,31 +344,16 @@ impl wgpu_example::framework::Example for Example { fn update(&mut self, event: winit::event::WindowEvent) { if let winit::event::WindowEvent::KeyboardInput { - input: - winit::event::KeyboardInput { - virtual_keycode: Some(winit::event::VirtualKeyCode::Space), - state: winit::event::ElementState::Pressed, + event: + KeyEvent { + logical_key: Key::Named(NamedKey::Space), + state: ElementState::Pressed, .. }, .. } = event { - let spawn_count = 64 + self.bunnies.len() / 2; - let color = self.rng.generate::(); - println!( - "Spawning {} bunnies, total at {}", - spawn_count, - self.bunnies.len() + spawn_count - ); - for _ in 0..spawn_count { - let speed = self.rng.generate::() * MAX_VELOCITY - (MAX_VELOCITY * 0.5); - self.bunnies.push(Locals { - position: [0.0, 0.5 * (self.extent[1] as f32)], - velocity: [speed, 0.0], - color, - _pad: 0, - }); - } + self.spawn_bunnies(); } } @@ -287,63 +367,11 @@ impl wgpu_example::framework::Example for Example { } fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue) { - let delta = 0.01; - for bunny in self.bunnies.iter_mut() { - bunny.position[0] += bunny.velocity[0] * delta; - bunny.position[1] += bunny.velocity[1] * delta; - bunny.velocity[1] += GRAVITY * delta; - if (bunny.velocity[0] > 0.0 - && bunny.position[0] + 0.5 * BUNNY_SIZE > self.extent[0] as f32) - || (bunny.velocity[0] < 0.0 && bunny.position[0] - 0.5 * BUNNY_SIZE < 0.0) - { - bunny.velocity[0] *= -1.0; - } - if bunny.velocity[1] < 0.0 && bunny.position[1] < 0.5 * BUNNY_SIZE { - bunny.velocity[1] *= -1.0; - } + self.spawn_bunnies(); + + for _frame_number in 0..3 { + self.render_inner(view, device, queue); } - - let uniform_alignment = device.limits().min_uniform_buffer_offset_alignment; - queue.write_buffer(&self.local_buffer, 0, unsafe { - std::slice::from_raw_parts( - self.bunnies.as_ptr() as *const u8, - self.bunnies.len() * uniform_alignment as usize, - ) - }); - - let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); - { - let clear_color = wgpu::Color { - r: 0.1, - g: 0.2, - b: 0.3, - a: 1.0, - }; - let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(clear_color), - store: wgpu::StoreOp::Store, - }, - })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - }); - rpass.set_pipeline(&self.pipeline); - rpass.set_bind_group(0, &self.global_group, &[]); - for i in 0..self.bunnies.len() { - let offset = - (i as wgpu::DynamicOffset) * (uniform_alignment as wgpu::DynamicOffset); - rpass.set_bind_group(1, &self.local_group, &[offset]); - rpass.draw(0..4, 0..1); - } - } - - queue.submit(Some(encoder.finish())); } } diff --git a/examples/common/src/framework.rs b/examples/common/src/framework.rs index 70a69a9bb..094d5dc59 100644 --- a/examples/common/src/framework.rs +++ b/examples/common/src/framework.rs @@ -9,8 +9,9 @@ use web_sys::{ImageBitmapRenderingContext, OffscreenCanvas}; use wgpu::{WasmNotSend, WasmNotSync}; use wgpu_test::GpuTestConfiguration; use winit::{ - event::{self, WindowEvent}, + event::{self, KeyEvent, WindowEvent}, event_loop::{ControlFlow, EventLoop}, + keyboard::{Key, NamedKey}, }; #[allow(dead_code)] @@ -31,9 +32,11 @@ pub trait Example: 'static + Sized { fn optional_features() -> wgpu::Features { wgpu::Features::empty() } + fn required_features() -> wgpu::Features { wgpu::Features::empty() } + fn required_downlevel_capabilities() -> wgpu::DownlevelCapabilities { wgpu::DownlevelCapabilities { flags: wgpu::DownlevelFlags::empty(), @@ -41,27 +44,31 @@ pub trait Example: 'static + Sized { ..wgpu::DownlevelCapabilities::default() } } + fn required_limits() -> wgpu::Limits { wgpu::Limits::downlevel_webgl2_defaults() // These downlevel limits will allow the code to run on all possible hardware } + fn init( config: &wgpu::SurfaceConfiguration, adapter: &wgpu::Adapter, device: &wgpu::Device, queue: &wgpu::Queue, ) -> Self; + fn resize( &mut self, config: &wgpu::SurfaceConfiguration, device: &wgpu::Device, queue: &wgpu::Queue, ); + fn update(&mut self, event: WindowEvent); + fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue); } struct Setup { - window: winit::window::Window, event_loop: EventLoop<()>, instance: wgpu::Instance, size: winit::dpi::PhysicalSize, @@ -85,7 +92,7 @@ async fn setup(title: &str) -> Setup { env_logger::init(); }; - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new().unwrap(); let mut builder = winit::window::WindowBuilder::new(); builder = builder.with_title(title); #[cfg(windows_OFF)] // TODO @@ -109,8 +116,10 @@ async fn setup(title: &str) -> Setup { .and_then(|win| win.document()) .and_then(|doc| doc.body()) .and_then(|body| { - body.append_child(&web_sys::Element::from(window.canvas())) - .ok() + body.append_child(&web_sys::Element::from( + window.canvas().expect("Couldn't get canvas"), + )) + .ok() }) .expect("couldn't append canvas to document body"); } @@ -133,6 +142,7 @@ async fn setup(title: &str) -> Setup { let bitmap_renderer = window .canvas() + .expect("Couldn't get html canvas") .get_context("bitmaprenderer") .expect("couldn't create ImageBitmapRenderingContext (Result)") .expect("couldn't create ImageBitmapRenderingContext (Option)") @@ -230,7 +240,6 @@ async fn setup(title: &str) -> Setup { .expect("Unable to find a suitable GPU adapter!"); Setup { - window, event_loop, instance, size, @@ -245,7 +254,6 @@ async fn setup(title: &str) -> Setup { fn start( #[cfg(not(target_arch = "wasm32"))] Setup { - window, event_loop, instance, size, @@ -255,7 +263,6 @@ fn start( queue, }: Setup, #[cfg(target_arch = "wasm32")] Setup { - window, event_loop, instance, size, @@ -282,113 +289,103 @@ fn start( let (mut frame_count, mut accum_time) = (0, 0.0); log::info!("Entering render loop..."); - event_loop.run(move |event, _, control_flow| { - let _ = (&instance, &adapter); // force ownership by the closure - *control_flow = if cfg!(feature = "metal-auto-capture") { - ControlFlow::Exit - } else { - ControlFlow::Poll - }; - match event { - event::Event::RedrawEventsCleared => { - window.request_redraw(); - } - event::Event::WindowEvent { - event: - WindowEvent::Resized(size) - | WindowEvent::ScaleFactorChanged { - new_inner_size: &mut size, - .. - }, - .. - } => { - log::info!("Resizing to {:?}", size); - config.width = size.width.max(1); - config.height = size.height.max(1); - example.resize(&config, &device, &queue); - surface.configure(&device, &config); - } - event::Event::WindowEvent { event, .. } => match event { - WindowEvent::KeyboardInput { - input: - event::KeyboardInput { - virtual_keycode: Some(event::VirtualKeyCode::Escape), - state: event::ElementState::Pressed, - .. - }, - .. - } - | WindowEvent::CloseRequested => { - *control_flow = ControlFlow::Exit; - } - #[cfg(not(target_arch = "wasm32"))] - WindowEvent::KeyboardInput { - input: - event::KeyboardInput { - virtual_keycode: Some(event::VirtualKeyCode::R), - state: event::ElementState::Pressed, - .. - }, + event_loop + .run(move |event, target| { + let _ = (&instance, &adapter); // force ownership by the closure + target.set_control_flow(ControlFlow::Poll); + + if cfg!(feature = "metal-auto-capture") { + target.exit(); + }; + + match event { + event::Event::WindowEvent { + event: WindowEvent::Resized(size), .. } => { - println!("{:#?}", instance.generate_report()); + config.width = size.width.max(1); + config.height = size.height.max(1); + example.resize(&config, &device, &queue); + surface.configure(&device, &config); } - _ => { - example.update(event); - } - }, - event::Event::RedrawRequested(_) => { - #[cfg(not(target_arch = "wasm32"))] - { - accum_time += last_frame_inst.elapsed().as_secs_f32(); - last_frame_inst = Instant::now(); - frame_count += 1; - if frame_count == 100 { - println!( - "Avg frame time {}ms", - accum_time * 1000.0 / frame_count as f32 - ); - accum_time = 0.0; - frame_count = 0; + event::Event::WindowEvent { event, .. } => match event { + WindowEvent::KeyboardInput { + event: + KeyEvent { + logical_key: Key::Named(NamedKey::Escape), + .. + }, + .. } - } - - let frame = match surface.get_current_texture() { - Ok(frame) => frame, - Err(_) => { - surface.configure(&device, &config); - surface - .get_current_texture() - .expect("Failed to acquire next surface texture!") + | WindowEvent::CloseRequested => { + target.exit(); } - }; - let view = frame.texture.create_view(&wgpu::TextureViewDescriptor { - format: Some(surface_view_format), - ..wgpu::TextureViewDescriptor::default() - }); - - example.render(&view, &device, &queue); - - frame.present(); - - #[cfg(target_arch = "wasm32")] - { - if let Some(offscreen_canvas_setup) = &offscreen_canvas_setup { - let image_bitmap = offscreen_canvas_setup - .offscreen_canvas - .transfer_to_image_bitmap() - .expect("couldn't transfer offscreen canvas to image bitmap."); - offscreen_canvas_setup - .bitmap_renderer - .transfer_from_image_bitmap(&image_bitmap); - - log::info!("Transferring OffscreenCanvas to ImageBitmapRenderer"); + #[cfg(not(target_arch = "wasm32"))] + WindowEvent::KeyboardInput { + event: + KeyEvent { + logical_key: Key::Character(s), + .. + }, + .. + } if s == "r" => { + println!("{:#?}", instance.generate_report()); } - } + event::WindowEvent::RedrawRequested => { + #[cfg(not(target_arch = "wasm32"))] + { + accum_time += last_frame_inst.elapsed().as_secs_f32(); + last_frame_inst = Instant::now(); + frame_count += 1; + if frame_count == 100 { + println!( + "Avg frame time {}ms", + accum_time * 1000.0 / frame_count as f32 + ); + accum_time = 0.0; + frame_count = 0; + } + } + + let frame = match surface.get_current_texture() { + Ok(frame) => frame, + Err(_) => { + surface.configure(&device, &config); + surface + .get_current_texture() + .expect("Failed to acquire next surface texture!") + } + }; + let view = frame.texture.create_view(&wgpu::TextureViewDescriptor { + format: Some(surface_view_format), + ..wgpu::TextureViewDescriptor::default() + }); + + example.render(&view, &device, &queue); + + frame.present(); + + #[cfg(target_arch = "wasm32")] + { + if let Some(offscreen_canvas_setup) = &offscreen_canvas_setup { + let image_bitmap = offscreen_canvas_setup + .offscreen_canvas + .transfer_to_image_bitmap() + .expect("couldn't transfer offscreen canvas to image bitmap."); + offscreen_canvas_setup + .bitmap_renderer + .transfer_from_image_bitmap(&image_bitmap); + + log::info!("Transferring OffscreenCanvas to ImageBitmapRenderer"); + } + } + } + _ => example.update(event), + }, + _ => {} } - _ => {} - } - }); + }) + .unwrap(); } #[cfg(not(target_arch = "wasm32"))] @@ -511,30 +508,7 @@ impl From> for GpuT &ctx.queue, ); - { - example.render(&dst_view, &ctx.device, &ctx.queue); - - // Handle specific case for bunnymark - #[allow(deprecated)] - if params.image_path == "/examples/bunnymark/screenshot.png" { - // Press spacebar to spawn bunnies - example.update(winit::event::WindowEvent::KeyboardInput { - input: winit::event::KeyboardInput { - scancode: 0, - state: winit::event::ElementState::Pressed, - virtual_keycode: Some(winit::event::VirtualKeyCode::Space), - modifiers: winit::event::ModifiersState::empty(), - }, - device_id: unsafe { winit::event::DeviceId::dummy() }, - is_synthetic: false, - }); - - // Step 3 extra frames - for _ in 0..3 { - example.render(&dst_view, &ctx.device, &ctx.queue); - } - } - } + example.render(&dst_view, &ctx.device, &ctx.queue); let mut cmd_buf = ctx .device diff --git a/examples/hello-triangle/src/main.rs b/examples/hello-triangle/src/main.rs index ebb8f6b73..fb836de68 100644 --- a/examples/hello-triangle/src/main.rs +++ b/examples/hello-triangle/src/main.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use winit::{ event::{Event, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, + event_loop::EventLoop, window::Window, }; @@ -82,67 +82,71 @@ async fn run(event_loop: EventLoop<()>, window: Window) { surface.configure(&device, &config); - event_loop.run(move |event, _, control_flow| { - // Have the closure take ownership of the resources. - // `event_loop.run` never returns, therefore we must do this to ensure - // the resources are properly cleaned up. - let _ = (&instance, &adapter, &shader, &pipeline_layout); + event_loop + .run(move |event, target| { + // Have the closure take ownership of the resources. + // `event_loop.run` never returns, therefore we must do this to ensure + // the resources are properly cleaned up. + let _ = (&instance, &adapter, &shader, &pipeline_layout); - *control_flow = ControlFlow::Wait; - match event { - Event::WindowEvent { - event: WindowEvent::Resized(size), - .. - } => { - // Reconfigure the surface with the new size - config.width = size.width; - config.height = size.height; - surface.configure(&device, &config); - // On macos the window needs to be redrawn manually after resizing - window.request_redraw(); - } - Event::RedrawRequested(_) => { - let frame = surface - .get_current_texture() - .expect("Failed to acquire next swap chain texture"); - let view = frame - .texture - .create_view(&wgpu::TextureViewDescriptor::default()); - let mut encoder = - device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); - { - let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(wgpu::Color::GREEN), - store: wgpu::StoreOp::Store, - }, - })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - }); - rpass.set_pipeline(&render_pipeline); - rpass.draw(0..3, 0..1); - } + if let Event::WindowEvent { + window_id: _, + event, + } = event + { + match event { + WindowEvent::Resized(new_size) => { + // Reconfigure the surface with the new size + config.width = new_size.width; + config.height = new_size.height; + surface.configure(&device, &config); + // On macos the window needs to be redrawn manually after resizing + window.request_redraw(); + } + WindowEvent::RedrawRequested => { + let frame = surface + .get_current_texture() + .expect("Failed to acquire next swap chain texture"); + let view = frame + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); + let mut encoder = + device.create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: None, + }); + { + let mut rpass = + encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[Some(wgpu::RenderPassColorAttachment { + view: &view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::GREEN), + store: wgpu::StoreOp::Store, + }, + })], + depth_stencil_attachment: None, + timestamp_writes: None, + occlusion_query_set: None, + }); + rpass.set_pipeline(&render_pipeline); + rpass.draw(0..3, 0..1); + } - queue.submit(Some(encoder.finish())); - frame.present(); + queue.submit(Some(encoder.finish())); + frame.present(); + } + WindowEvent::CloseRequested => target.exit(), + _ => {} + }; } - Event::WindowEvent { - event: WindowEvent::CloseRequested, - .. - } => *control_flow = ControlFlow::Exit, - _ => {} - } - }); + }) + .unwrap(); } fn main() { - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new().unwrap(); let window = winit::window::Window::new(&event_loop).unwrap(); #[cfg(not(target_arch = "wasm32"))] { @@ -159,7 +163,7 @@ fn main() { .and_then(|win| win.document()) .and_then(|doc| doc.body()) .and_then(|body| { - body.append_child(&web_sys::Element::from(window.canvas())) + body.append_child(&web_sys::Element::from(window.canvas().unwrap())) .ok() }) .expect("couldn't append canvas to document body"); diff --git a/examples/hello-windows/src/main.rs b/examples/hello-windows/src/main.rs index ba2834139..43bd98696 100644 --- a/examples/hello-windows/src/main.rs +++ b/examples/hello-windows/src/main.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use winit::{ event::{Event, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, + event_loop::EventLoop, window::{Window, WindowId}, }; @@ -95,68 +95,70 @@ async fn run(event_loop: EventLoop<()>, viewports: Vec<(Window, wgpu::Color)>) { .map(|desc| (desc.window.id(), desc.build(&adapter, &device))) .collect(); - event_loop.run(move |event, _, control_flow| { - // Have the closure take ownership of the resources. - // `event_loop.run` never returns, therefore we must do this to ensure - // the resources are properly cleaned up. - let _ = (&instance, &adapter); + event_loop + .run(move |event, target| { + // Have the closure take ownership of the resources. + // `event_loop.run` never returns, therefore we must do this to ensure + // the resources are properly cleaned up. + let _ = (&instance, &adapter); - *control_flow = ControlFlow::Wait; - match event { - Event::WindowEvent { - window_id, - event: WindowEvent::Resized(size), - .. - } => { - // Recreate the swap chain with the new size - if let Some(viewport) = viewports.get_mut(&window_id) { - viewport.resize(&device, size); - // On macos the window needs to be redrawn manually after resizing - viewport.desc.window.request_redraw(); - } - } - Event::RedrawRequested(window_id) => { - if let Some(viewport) = viewports.get_mut(&window_id) { - let frame = viewport.get_current_texture(); - let view = frame - .texture - .create_view(&wgpu::TextureViewDescriptor::default()); - let mut encoder = device - .create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); - { - let _rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(viewport.desc.background), - store: wgpu::StoreOp::Store, - }, - })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - }); + if let Event::WindowEvent { window_id, event } = event { + match event { + WindowEvent::Resized(new_size) => { + // Recreate the swap chain with the new size + if let Some(viewport) = viewports.get_mut(&window_id) { + viewport.resize(&device, new_size); + // On macos the window needs to be redrawn manually after resizing + viewport.desc.window.request_redraw(); + } } + WindowEvent::RedrawRequested => { + if let Some(viewport) = viewports.get_mut(&window_id) { + let frame = viewport.get_current_texture(); + let view = frame + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); + let mut encoder = + device.create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: None, + }); + { + let _rpass = + encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[Some( + wgpu::RenderPassColorAttachment { + view: &view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear( + viewport.desc.background, + ), + store: wgpu::StoreOp::Store, + }, + }, + )], + depth_stencil_attachment: None, + timestamp_writes: None, + occlusion_query_set: None, + }); + } - queue.submit(Some(encoder.finish())); - frame.present(); + queue.submit(Some(encoder.finish())); + frame.present(); + } + } + WindowEvent::CloseRequested => { + viewports.remove(&window_id); + if viewports.is_empty() { + target.exit(); + } + } + _ => {} } } - Event::WindowEvent { - window_id, - event: WindowEvent::CloseRequested, - .. - } => { - viewports.remove(&window_id); - if viewports.is_empty() { - *control_flow = ControlFlow::Exit - } - } - _ => {} - } - }); + }) + .unwrap(); } fn main() { @@ -169,7 +171,7 @@ fn main() { const ROWS: u32 = 4; const COLUMNS: u32 = 4; - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new().unwrap(); let mut viewports = Vec::with_capacity((ROWS * COLUMNS) as usize); for row in 0..ROWS { for column in 0..COLUMNS { diff --git a/examples/msaa-line/src/main.rs b/examples/msaa-line/src/main.rs index 7d5c7e928..9c6dddcfd 100644 --- a/examples/msaa-line/src/main.rs +++ b/examples/msaa-line/src/main.rs @@ -14,6 +14,10 @@ use wgpu::util::DeviceExt; #[cfg(test)] use wgpu_test::FailureCase; +use winit::{ + event::{ElementState, KeyEvent, WindowEvent}, + keyboard::{Key, NamedKey}, +}; #[repr(C)] #[derive(Clone, Copy, Pod, Zeroable)] @@ -215,27 +219,31 @@ impl wgpu_example::framework::Example for Example { #[allow(clippy::single_match)] fn update(&mut self, event: winit::event::WindowEvent) { match event { - winit::event::WindowEvent::KeyboardInput { input, .. } => { - if let winit::event::ElementState::Pressed = input.state { - match input.virtual_keycode { - // TODO: Switch back to full scans of possible options when we expose - // supported sample counts to the user. - Some(winit::event::VirtualKeyCode::Left) => { - if self.sample_count == self.max_sample_count { - self.sample_count = 1; - self.rebuild_bundle = true; - } - } - Some(winit::event::VirtualKeyCode::Right) => { - if self.sample_count == 1 { - self.sample_count = self.max_sample_count; - self.rebuild_bundle = true; - } - } - _ => {} + WindowEvent::KeyboardInput { + event: + KeyEvent { + logical_key, + state: ElementState::Pressed, + .. + }, + .. + } => match logical_key { + // TODO: Switch back to full scans of possible options when we expose + // supported sample counts to the user. + Key::Named(NamedKey::ArrowLeft) => { + if self.sample_count == self.max_sample_count { + self.sample_count = 1; + self.rebuild_bundle = true; } } - } + Key::Named(NamedKey::ArrowRight) => { + if self.sample_count == 1 { + self.sample_count = self.max_sample_count; + self.rebuild_bundle = true; + } + } + _ => {} + }, _ => {} } } diff --git a/examples/uniform-values/src/main.rs b/examples/uniform-values/src/main.rs index 733a863ee..50b7e7d6a 100644 --- a/examples/uniform-values/src/main.rs +++ b/examples/uniform-values/src/main.rs @@ -20,8 +20,9 @@ // with actual GPU-allocated WGPU storage buffers. use encase::ShaderType; use winit::{ - event::{Event, VirtualKeyCode, WindowEvent}, + event::{Event, KeyEvent, WindowEvent}, event_loop::EventLoop, + keyboard::{Key, NamedKey}, window::Window, }; @@ -227,103 +228,124 @@ async fn run(event_loop: EventLoop<()>, window: Window) { // (6) let mut state = Some(AppState::default()); let main_window_id = wgpu_context.as_ref().unwrap().window.id(); - event_loop.run(move |event, _, control_flow| { - control_flow.set_wait(); - match event { - Event::LoopDestroyed => { - wgpu_context = None; - state = None; - } - Event::WindowEvent { window_id, event } if window_id == main_window_id => match event { - WindowEvent::CloseRequested => { - control_flow.set_exit(); + event_loop + .run(move |event, target| { + match event { + Event::LoopExiting => { + wgpu_context = None; + state = None; } - WindowEvent::KeyboardInput { input, .. } => { - let state_mut = state.as_mut().unwrap(); - let wgpu_context_ref = wgpu_context.as_ref().unwrap(); - if let Some(virtual_keycode) = input.virtual_keycode { - // (7a) - match virtual_keycode { - VirtualKeyCode::Escape => control_flow.set_exit(), - VirtualKeyCode::Up => state_mut.translate_view(1, 1), - VirtualKeyCode::Down => state_mut.translate_view(-1, 1), - VirtualKeyCode::Left => state_mut.translate_view(-1, 0), - VirtualKeyCode::Right => state_mut.translate_view(1, 0), - VirtualKeyCode::U => state_mut.max_iterations += 3, - VirtualKeyCode::D => state_mut.max_iterations -= 3, - _ => {} + Event::WindowEvent { window_id, event } if window_id == main_window_id => { + match event { + WindowEvent::CloseRequested => { + target.exit(); } - wgpu_context_ref.window.request_redraw(); + WindowEvent::KeyboardInput { + event: + KeyEvent { + logical_key, text, .. + }, + .. + } => { + let state_mut = state.as_mut().unwrap(); + let wgpu_context_ref = wgpu_context.as_ref().unwrap(); + + if let Key::Named(key) = logical_key { + match key { + NamedKey::Escape => target.exit(), + NamedKey::ArrowUp => state_mut.translate_view(1, 1), + NamedKey::ArrowDown => state_mut.translate_view(-1, 1), + NamedKey::ArrowLeft => state_mut.translate_view(-1, 0), + NamedKey::ArrowRight => state_mut.translate_view(1, 0), + _ => {} + } + } + + if let Some(text) = text { + if text == "u" { + state_mut.max_iterations += 3; + } else if text == "d" { + state_mut.max_iterations -= 3; + } + }; + + wgpu_context_ref.window.request_redraw(); + } + WindowEvent::MouseWheel { delta, .. } => { + let change = match delta { + winit::event::MouseScrollDelta::LineDelta(_, vertical) => vertical, + winit::event::MouseScrollDelta::PixelDelta(pos) => { + pos.y as f32 / 20.0 + } + }; + let state_mut = state.as_mut().unwrap(); + let wgpu_context_ref = wgpu_context.as_ref().unwrap(); + // (7b) + state_mut.zoom(change); + wgpu_context_ref.window.request_redraw(); + } + WindowEvent::Resized(new_size) => { + let wgpu_context_mut = wgpu_context.as_mut().unwrap(); + wgpu_context_mut.resize(new_size); + wgpu_context_mut.window.request_redraw(); + } + WindowEvent::RedrawRequested => { + let wgpu_context_ref = wgpu_context.as_ref().unwrap(); + let state_ref = state.as_ref().unwrap(); + let frame = wgpu_context_ref.surface.get_current_texture().unwrap(); + let view = frame + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); + + // (8) + wgpu_context_ref.queue.write_buffer( + &wgpu_context_ref.uniform_buffer, + 0, + &state_ref.as_wgsl_bytes().expect( + "Error in encase translating AppState \ + struct to WGSL bytes.", + ), + ); + let mut encoder = wgpu_context_ref.device.create_command_encoder( + &wgpu::CommandEncoderDescriptor { label: None }, + ); + { + let mut render_pass = + encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[Some( + wgpu::RenderPassColorAttachment { + view: &view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::GREEN), + store: wgpu::StoreOp::Store, + }, + }, + )], + depth_stencil_attachment: None, + occlusion_query_set: None, + timestamp_writes: None, + }); + render_pass.set_pipeline(&wgpu_context_ref.pipeline); + // (9) + render_pass.set_bind_group(0, &wgpu_context_ref.bind_group, &[]); + render_pass.draw(0..3, 0..1); + } + wgpu_context_ref.queue.submit(Some(encoder.finish())); + frame.present(); + } + _ => {} } } - WindowEvent::MouseWheel { delta, .. } => { - let change = match delta { - winit::event::MouseScrollDelta::LineDelta(_, vertical) => vertical, - winit::event::MouseScrollDelta::PixelDelta(pos) => pos.y as f32 / 20.0, - }; - let state_mut = state.as_mut().unwrap(); - let wgpu_context_ref = wgpu_context.as_ref().unwrap(); - // (7b) - state_mut.zoom(change); - wgpu_context_ref.window.request_redraw(); - } - WindowEvent::Resized(new_size) => { - let wgpu_context_mut = wgpu_context.as_mut().unwrap(); - wgpu_context_mut.resize(new_size); - wgpu_context_mut.window.request_redraw(); - } _ => {} - }, - Event::RedrawRequested(id) if id == main_window_id => { - let wgpu_context_ref = wgpu_context.as_ref().unwrap(); - let state_ref = state.as_ref().unwrap(); - let frame = wgpu_context_ref.surface.get_current_texture().unwrap(); - let view = frame - .texture - .create_view(&wgpu::TextureViewDescriptor::default()); - - // (8) - wgpu_context_ref.queue.write_buffer( - &wgpu_context_ref.uniform_buffer, - 0, - &state_ref.as_wgsl_bytes().expect( - "Error in encase translating AppState \ - struct to WGSL bytes.", - ), - ); - let mut encoder = wgpu_context_ref - .device - .create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); - { - let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(wgpu::Color::GREEN), - store: wgpu::StoreOp::Store, - }, - })], - depth_stencil_attachment: None, - occlusion_query_set: None, - timestamp_writes: None, - }); - render_pass.set_pipeline(&wgpu_context_ref.pipeline); - // (9) - render_pass.set_bind_group(0, &wgpu_context_ref.bind_group, &[]); - render_pass.draw(0..3, 0..1); - } - wgpu_context_ref.queue.submit(Some(encoder.finish())); - frame.present(); } - _ => {} - } - }); + }) + .unwrap(); } fn main() { - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new().unwrap(); let window = winit::window::WindowBuilder::new() .with_title("Remember: Use U/D to change sample count!") .with_inner_size(winit::dpi::LogicalSize::new(900, 900)) @@ -344,8 +366,10 @@ fn main() { .and_then(|win| win.document()) .expect("Failed to get document."); let body = document.body().unwrap(); - body.append_child(&web_sys::Element::from(window.canvas())) - .unwrap(); + body.append_child(&web_sys::Element::from( + window.canvas().expect("Couldn't get canvas"), + )) + .unwrap(); let controls_text = document .create_element("p") .expect("Failed to create controls text as element."); diff --git a/player/src/bin/play.rs b/player/src/bin/play.rs index a9a47ce5f..b50966295 100644 --- a/player/src/bin/play.rs +++ b/player/src/bin/play.rs @@ -12,9 +12,14 @@ fn main() { }; #[cfg(feature = "winit")] - use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; + use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; #[cfg(feature = "winit")] - use winit::{event_loop::EventLoop, window::WindowBuilder}; + use winit::{ + event::KeyEvent, + event_loop::EventLoop, + keyboard::{Key, NamedKey}, + window::WindowBuilder, + }; env_logger::init(); @@ -35,7 +40,7 @@ fn main() { #[cfg(feature = "winit")] let event_loop = { log::info!("Creating a window"); - EventLoop::new() + EventLoop::new().unwrap() }; #[cfg(feature = "winit")] let window = WindowBuilder::new() @@ -53,8 +58,8 @@ fn main() { #[cfg(feature = "winit")] let surface = global.instance_create_surface( - window.raw_display_handle(), - window.raw_window_handle(), + window.display_handle().unwrap().into(), + window.window_handle().unwrap().into(), wgc::id::TypedId::zip(0, 1, wgt::Backend::Empty), ); @@ -110,32 +115,32 @@ fn main() { #[cfg(feature = "winit")] { use winit::{ - event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, + event::{ElementState, Event, WindowEvent}, event_loop::ControlFlow, }; let mut resize_config = None; let mut frame_count = 0; let mut done = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, target| { + target.set_control_flow(ControlFlow::Poll); + match event { - Event::MainEventsCleared => { - window.request_redraw(); - } - Event::RedrawRequested(_) if resize_config.is_none() => loop { + Event::WindowEvent { event, .. } => match event { + WindowEvent::RedrawRequested if resize_config.is_none() => { + match actions.pop() { Some(trace::Action::ConfigureSurface(_device_id, config)) => { log::info!("Configuring the surface"); let current_size: (u32, u32) = window.inner_size().into(); let size = (config.width, config.height); if current_size != size { - window.set_inner_size(winit::dpi::PhysicalSize::new( + let _ = window.request_inner_size(winit::dpi::PhysicalSize::new( config.width, config.height, )); resize_config = Some(config); - break; + target.exit(); } else { let error = gfx_select!(device => global.surface_configure(surface, device, &config)); if let Some(e) = error { @@ -147,12 +152,12 @@ fn main() { frame_count += 1; log::debug!("Presenting frame {}", frame_count); gfx_select!(device => global.surface_present(id)).unwrap(); - break; + target.exit(); } Some(trace::Action::DiscardSurfaceTexture(id)) => { log::debug!("Discarding frame {}", frame_count); gfx_select!(device => global.surface_texture_discard(id)).unwrap(); - break; + target.exit(); } Some(action) => { gfx_select!(device => global.process(device, action, &dir, &mut command_buffer_id_manager)); @@ -162,11 +167,10 @@ fn main() { println!("Finished the end at frame {}", frame_count); done = true; } - break; + target.exit(); } } - }, - Event::WindowEvent { event, .. } => match event { + }, WindowEvent::Resized(_) => { if let Some(config) = resize_config.take() { let error = gfx_select!(device => global.surface_configure(surface, device, &config)); @@ -176,26 +180,23 @@ fn main() { } } WindowEvent::KeyboardInput { - input: - KeyboardInput { - virtual_keycode: Some(VirtualKeyCode::Escape), - state: ElementState::Pressed, - .. - }, + event: KeyEvent { + logical_key: Key::Named(NamedKey::Escape), + state: ElementState::Pressed, + .. + }, .. } - | WindowEvent::CloseRequested => { - *control_flow = ControlFlow::Exit; - } + | WindowEvent::CloseRequested => target.exit(), _ => {} }, - Event::LoopDestroyed => { + Event::LoopExiting => { log::info!("Closing"); gfx_select!(device => global.device_poll(device, wgt::Maintain::Wait)).unwrap(); } _ => {} } - }); + }).unwrap(); } } diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index a60cec71e..7ac00be23 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -72,7 +72,7 @@ log = "0.4" # parking_lot 0.12 switches from `winapi` to `windows`; permit either parking_lot = ">=0.11,<0.13" profiling = { version = "1", default-features = false } -raw-window-handle = { version = "0.5", optional = true } +raw-window-handle = { version = "0.6", optional = true } ron = { version = "0.8", optional = true } serde = { version = "1", features = ["serde_derive"], optional = true } smallvec = "1" diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 4de36a1d9..56e1fb7e1 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -86,7 +86,7 @@ required-features = ["gles"] bitflags = "2" parking_lot = ">=0.11,<0.13" profiling = { version = "1", default-features = false } -raw-window-handle = "0.5" +raw-window-handle = "0.6" thiserror = "1" once_cell = "1.18.0" @@ -180,9 +180,7 @@ features = ["wgsl-in"] [dev-dependencies] cfg-if = "1" env_logger = "0.10" -winit = { version = "0.28.7", features = [ - "android-native-activity", -] } # for "halmark" example +winit = { version = "0.29.2", features = [ "android-native-activity" ] } # for "halmark" example [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] glutin = "0.29.1" # for "gles" example diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 527c45e2a..471b0c489 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -5,7 +5,12 @@ extern crate wgpu_hal as hal; use hal::{ Adapter as _, CommandEncoder as _, Device as _, Instance as _, Queue as _, Surface as _, }; -use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; +use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; +use winit::{ + event::{ElementState, Event, KeyEvent, WindowEvent}, + event_loop::ControlFlow, + keyboard::{Key, NamedKey}, +}; use std::{ borrow::{Borrow, Cow}, @@ -95,10 +100,15 @@ impl Example { gles_minor_version: wgt::Gles3MinorVersion::default(), }; let instance = unsafe { A::Instance::init(&instance_desc)? }; - let mut surface = unsafe { - instance - .create_surface(window.raw_display_handle(), window.raw_window_handle()) - .unwrap() + let mut surface = { + let raw_window_handle = window.window_handle()?.as_raw(); + let raw_display_handle = window.display_handle()?.as_raw(); + + unsafe { + instance + .create_surface(raw_display_handle, raw_window_handle) + .unwrap() + } }; let (adapter, capabilities) = unsafe { @@ -261,7 +271,7 @@ impl Example { }; let pipeline = unsafe { device.create_render_pipeline(&pipeline_desc).unwrap() }; - let texture_data = vec![0xFFu8; 4]; + let texture_data = [0xFFu8; 4]; let staging_buffer_desc = hal::BufferDescriptor { label: Some("stage"), @@ -563,10 +573,10 @@ impl Example { fn update(&mut self, event: winit::event::WindowEvent) { if let winit::event::WindowEvent::KeyboardInput { - input: - winit::event::KeyboardInput { - virtual_keycode: Some(winit::event::VirtualKeyCode::Space), - state: winit::event::ElementState::Pressed, + event: + KeyEvent { + logical_key: Key::Named(NamedKey::Space), + state: ElementState::Pressed, .. }, .. @@ -777,7 +787,7 @@ cfg_if::cfg_if! { fn main() { env_logger::init(); - let event_loop = winit::event_loop::EventLoop::new(); + let event_loop = winit::event_loop::EventLoop::new().unwrap(); let window = winit::window::WindowBuilder::new() .with_title("hal-bunnymark") .build(&event_loop) @@ -789,51 +799,49 @@ fn main() { let mut last_frame_inst = Instant::now(); let (mut frame_count, mut accum_time) = (0, 0.0); - event_loop.run(move |event, _, control_flow| { - let _ = &window; // force ownership by the closure - *control_flow = winit::event_loop::ControlFlow::Poll; - match event { - winit::event::Event::RedrawEventsCleared => { - window.request_redraw(); - } - winit::event::Event::WindowEvent { event, .. } => match event { - winit::event::WindowEvent::KeyboardInput { - input: - winit::event::KeyboardInput { - virtual_keycode: Some(winit::event::VirtualKeyCode::Escape), - state: winit::event::ElementState::Pressed, - .. - }, - .. + event_loop + .run(move |event, target| { + let _ = &window; // force ownership by the closure + target.set_control_flow(ControlFlow::Poll); + + match event { + Event::LoopExiting => { + example.take().unwrap().exit(); } - | winit::event::WindowEvent::CloseRequested => { - *control_flow = winit::event_loop::ControlFlow::Exit; - } - _ => { - example.as_mut().unwrap().update(event); - } - }, - winit::event::Event::RedrawRequested(_) => { - let ex = example.as_mut().unwrap(); - { - accum_time += last_frame_inst.elapsed().as_secs_f32(); - last_frame_inst = Instant::now(); - frame_count += 1; - if frame_count == 100 && !ex.is_empty() { - println!( - "Avg frame time {}ms", - accum_time * 1000.0 / frame_count as f32 - ); - accum_time = 0.0; - frame_count = 0; + Event::WindowEvent { event, .. } => match event { + WindowEvent::KeyboardInput { + event: + KeyEvent { + logical_key: Key::Named(NamedKey::Escape), + state: ElementState::Pressed, + .. + }, + .. } - } - ex.render(); + | WindowEvent::CloseRequested => target.exit(), + WindowEvent::RedrawRequested => { + let ex = example.as_mut().unwrap(); + { + accum_time += last_frame_inst.elapsed().as_secs_f32(); + last_frame_inst = Instant::now(); + frame_count += 1; + if frame_count == 100 && !ex.is_empty() { + println!( + "Avg frame time {}ms", + accum_time * 1000.0 / frame_count as f32 + ); + accum_time = 0.0; + frame_count = 0; + } + } + ex.render(); + } + _ => { + example.as_mut().unwrap().update(event); + } + }, + _ => {} } - winit::event::Event::LoopDestroyed => { - example.take().unwrap().exit(); - } - _ => {} - } - }); + }) + .unwrap(); } diff --git a/wgpu-hal/src/dx12/instance.rs b/wgpu-hal/src/dx12/instance.rs index ef7a7958f..2764932ee 100644 --- a/wgpu-hal/src/dx12/instance.rs +++ b/wgpu-hal/src/dx12/instance.rs @@ -114,7 +114,7 @@ impl crate::Instance for super::Instance { raw_window_handle::RawWindowHandle::Win32(handle) => Ok(super::Surface { factory: self.factory.clone(), factory_media: self.factory_media.clone(), - target: SurfaceTarget::WndHandle(handle.hwnd as *mut _), + target: SurfaceTarget::WndHandle(handle.hwnd.get() as *mut _), supports_allow_tearing: self.supports_allow_tearing, swap_chain: None, }), diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index 1a2250ecc..784f1abe8 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -865,7 +865,7 @@ impl crate::Instance for Instance { .unwrap(); let ret = unsafe { - ANativeWindow_setBuffersGeometry(handle.a_native_window, 0, 0, format) + ANativeWindow_setBuffersGeometry(handle.a_native_window.as_ptr(), 0, 0, format) }; if ret != 0 { @@ -878,7 +878,7 @@ impl crate::Instance for Instance { (Rwh::Wayland(_), raw_window_handle::RawDisplayHandle::Wayland(display_handle)) => { if inner .wl_display - .map(|ptr| ptr != display_handle.display) + .map(|ptr| ptr != display_handle.display.as_ptr()) .unwrap_or(true) { /* Wayland displays are not sharable between surfaces so if the @@ -900,7 +900,7 @@ impl crate::Instance for Instance { .unwrap() .get_platform_display( EGL_PLATFORM_WAYLAND_KHR, - display_handle.display, + display_handle.display.as_ptr(), &display_attributes, ) } @@ -914,7 +914,7 @@ impl crate::Instance for Instance { )?; let old_inner = std::mem::replace(inner.deref_mut(), new_inner); - inner.wl_display = Some(display_handle.display); + inner.wl_display = Some(display_handle.display.as_ptr()); drop(old_inner); } @@ -1155,29 +1155,35 @@ impl crate::Surface for Surface { &mut temp_xcb_handle as *mut _ as *mut std::ffi::c_void } (WindowKind::AngleX11, Rwh::Xcb(handle)) => { - handle.window as *mut std::ffi::c_void + handle.window.get() as *mut std::ffi::c_void + } + (WindowKind::Unknown, Rwh::AndroidNdk(handle)) => { + handle.a_native_window.as_ptr() } - (WindowKind::Unknown, Rwh::AndroidNdk(handle)) => handle.a_native_window, (WindowKind::Wayland, Rwh::Wayland(handle)) => { let library = &self.wsi.display_owner.as_ref().unwrap().library; let wl_egl_window_create: libloading::Symbol = unsafe { library.get(b"wl_egl_window_create") }.unwrap(); - let window = unsafe { wl_egl_window_create(handle.surface, 640, 480) }; + let window = + unsafe { wl_egl_window_create(handle.surface.as_ptr(), 640, 480) } + as *mut _; wl_window = Some(window); window } #[cfg(target_os = "emscripten")] (WindowKind::Unknown, Rwh::Web(handle)) => handle.id as *mut std::ffi::c_void, - (WindowKind::Unknown, Rwh::Win32(handle)) => handle.hwnd, + (WindowKind::Unknown, Rwh::Win32(handle)) => { + handle.hwnd.get() as *mut std::ffi::c_void + } (WindowKind::Unknown, Rwh::AppKit(handle)) => { #[cfg(not(target_os = "macos"))] - let window_ptr = handle.ns_view; + let window_ptr = handle.ns_view.as_ptr(); #[cfg(target_os = "macos")] let window_ptr = { use objc::{msg_send, runtime::Object, sel, sel_impl}; // ns_view always have a layer and don't need to verify that it exists. let layer: *mut Object = - msg_send![handle.ns_view as *mut Object, layer]; + msg_send![handle.ns_view.as_ptr() as *mut Object, layer]; layer as *mut ffi::c_void }; window_ptr diff --git a/wgpu-hal/src/gles/wgl.rs b/wgpu-hal/src/gles/wgl.rs index 84f100c0c..16a15a846 100644 --- a/wgpu-hal/src/gles/wgl.rs +++ b/wgpu-hal/src/gles/wgl.rs @@ -441,7 +441,7 @@ impl crate::Instance for Instance { ))); }; Ok(Surface { - window: window.hwnd as *mut _, + window: window.hwnd.get() as *mut _, presentable: true, swapchain: None, srgb_capable: self.srgb_capable, diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index a75439096..95a060f70 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -96,11 +96,14 @@ impl crate::Instance for Instance { #[cfg(target_os = "ios")] raw_window_handle::RawWindowHandle::UiKit(handle) => { let _ = &self.managed_metal_layer_delegate; - Ok(unsafe { Surface::from_view(handle.ui_view, None) }) + Ok(unsafe { Surface::from_view(handle.ui_view.as_ptr(), None) }) } #[cfg(target_os = "macos")] raw_window_handle::RawWindowHandle::AppKit(handle) => Ok(unsafe { - Surface::from_view(handle.ns_view, Some(&self.managed_metal_layer_delegate)) + Surface::from_view( + handle.ns_view.as_ptr(), + Some(&self.managed_metal_layer_delegate), + ) }), _ => Err(crate::InstanceError::new(format!( "window handle {window_handle:?} is not a Metal-compatible handle" diff --git a/wgpu-hal/src/vulkan/instance.rs b/wgpu-hal/src/vulkan/instance.rs index 908f6e506..f8a373d67 100644 --- a/wgpu-hal/src/vulkan/instance.rs +++ b/wgpu-hal/src/vulkan/instance.rs @@ -740,33 +740,37 @@ impl crate::Instance for super::Instance { match (window_handle, display_handle) { (Rwh::Wayland(handle), Rdh::Wayland(display)) => { - self.create_surface_from_wayland(display.display, handle.surface) + self.create_surface_from_wayland(display.display.as_ptr(), handle.surface.as_ptr()) } (Rwh::Xlib(handle), Rdh::Xlib(display)) => { - self.create_surface_from_xlib(display.display as *mut _, handle.window) + let display = display.display.expect("Display pointer is not set."); + self.create_surface_from_xlib(display.as_ptr() as *mut *const c_void, handle.window) } (Rwh::Xcb(handle), Rdh::Xcb(display)) => { - self.create_surface_from_xcb(display.connection, handle.window) + let connection = display.connection.expect("Pointer to X-Server is not set."); + self.create_surface_from_xcb(connection.as_ptr(), handle.window.get()) + } + (Rwh::AndroidNdk(handle), _) => { + self.create_surface_android(handle.a_native_window.as_ptr()) } - (Rwh::AndroidNdk(handle), _) => self.create_surface_android(handle.a_native_window), #[cfg(windows)] (Rwh::Win32(handle), _) => { use winapi::um::libloaderapi::GetModuleHandleW; let hinstance = unsafe { GetModuleHandleW(std::ptr::null()) }; - self.create_surface_from_hwnd(hinstance as *mut _, handle.hwnd) + self.create_surface_from_hwnd(hinstance as *mut _, handle.hwnd.get() as *mut _) } #[cfg(target_os = "macos")] (Rwh::AppKit(handle), _) if self.shared.extensions.contains(&ext::MetalSurface::name()) => { - self.create_surface_from_view(handle.ns_view) + self.create_surface_from_view(handle.ns_view.as_ptr()) } #[cfg(target_os = "ios")] (Rwh::UiKit(handle), _) if self.shared.extensions.contains(&ext::MetalSurface::name()) => { - self.create_surface_from_view(handle.ui_view) + self.create_surface_from_view(handle.ui_view.as_ptr()) } (_, _) => Err(crate::InstanceError::new(format!( "window handle {window_handle:?} is not a Vulkan-compatible handle" diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 02c03b09e..6851bb53b 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -107,7 +107,7 @@ flume.workspace = true log.workspace = true parking_lot.workspace = true profiling.workspace = true -raw-window-handle.workspace = true +raw-window-handle = { workspace = true, features = ["std"] } serde = { workspace = true, features = ["derive"], optional = true } smallvec.workspace = true static_assertions.workspace = true diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index d557c05af..6a2570f17 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -1937,15 +1937,27 @@ impl Instance { /// - On web: will panic if the `raw_window_handle` does not properly refer to a /// canvas element. pub unsafe fn create_surface< - W: raw_window_handle::HasRawWindowHandle + raw_window_handle::HasRawDisplayHandle, + W: raw_window_handle::HasWindowHandle + raw_window_handle::HasDisplayHandle, >( &self, window: &W, ) -> Result { + let raw_display_handle = window + .display_handle() + .map_err(|e| CreateSurfaceError { + inner: CreateSurfaceErrorKind::RawHandle(e), + })? + .as_raw(); + let raw_window_handle = window + .window_handle() + .map_err(|e| CreateSurfaceError { + inner: CreateSurfaceErrorKind::RawHandle(e), + })? + .as_raw(); let (id, data) = DynContext::instance_create_surface( &*self.context, - raw_window_handle::HasRawDisplayHandle::raw_display_handle(window), - raw_window_handle::HasRawWindowHandle::raw_window_handle(window), + raw_display_handle, + raw_window_handle, )?; Ok(Surface { context: Arc::clone(&self.context), @@ -2925,6 +2937,10 @@ enum CreateSurfaceErrorKind { /// Error from WebGPU surface creation. #[allow(dead_code)] // may be unused depending on target and features Web(String), + + /// Error when trying to get a [`DisplayHandle`] or a [`WindowHandle`] from + /// `raw_window_handle`. + RawHandle(raw_window_handle::HandleError), } static_assertions::assert_impl_all!(CreateSurfaceError: Send, Sync); @@ -2938,6 +2954,7 @@ impl fmt::Display for CreateSurfaceError { ))] CreateSurfaceErrorKind::Hal(e) => e.fmt(f), CreateSurfaceErrorKind::Web(e) => e.fmt(f), + CreateSurfaceErrorKind::RawHandle(e) => e.fmt(f), } } } @@ -2952,6 +2969,7 @@ impl error::Error for CreateSurfaceError { ))] CreateSurfaceErrorKind::Hal(e) => e.source(), CreateSurfaceErrorKind::Web(_) => None, + CreateSurfaceErrorKind::RawHandle(e) => e.source(), } } }