From b86131555d2c4fb5e35f4d2bfcee6891bea0de75 Mon Sep 17 00:00:00 2001 From: white-axe Date: Tue, 30 Jan 2024 21:54:36 -0500 Subject: [PATCH] merge: update wgpu to 0.19 Based on https://github.com/emilk/egui/pull/3824 --- Cargo.lock | 224 ++++++++++-------- Cargo.toml | 5 +- crates/eframe/Cargo.toml | 31 ++- crates/eframe/README.md | 2 +- crates/eframe/src/epi.rs | 45 ++-- crates/eframe/src/native/epi_integration.rs | 6 +- crates/eframe/src/native/glow_integration.rs | 37 +-- crates/eframe/src/native/wgpu_integration.rs | 30 ++- crates/eframe/src/native/winit_integration.rs | 4 +- crates/eframe/src/web/web_logger.rs | 17 +- crates/eframe/src/web/web_painter_wgpu.rs | 48 +++- crates/eframe/src/web/web_runner.rs | 4 +- crates/egui-wgpu/Cargo.toml | 4 +- crates/egui-wgpu/README.md | 2 +- crates/egui-wgpu/src/lib.rs | 66 ++++-- crates/egui-wgpu/src/renderer.rs | 6 + crates/egui-wgpu/src/winit.rs | 166 +++++++------ crates/graphics/Cargo.toml | 4 +- 18 files changed, 437 insertions(+), 264 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cefe047c..bb43301d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,7 +102,7 @@ dependencies = [ "macroific", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -464,7 +464,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -525,7 +525,7 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -663,7 +663,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -803,7 +803,7 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1027,10 +1027,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] -name = "com-rs" -version = "0.2.1" +name = "com" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e17887fd17353b65b1b2ef1c526c83e26cd72e74f598a8dc1bee13a48f3d9f6" +dependencies = [ + "com_macros", +] + +[[package]] +name = "com_macros" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf43edc576402991846b093a7ca18a3477e0ef9c588cde84964b5d3e43016642" +checksum = "d375883580a668c7481ea6631fc1a8863e33cc335bf56bfad8d7e6d4b04b13a5" +dependencies = [ + "com_macros_support", + "proc-macro2", + "syn 1.0.109", +] + +[[package]] +name = "com_macros_support" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad899a1087a9296d5644792d7cb72b8e34c1bec8e7d4fbc002230169a6e8710c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] [[package]] name = "combine" @@ -1274,9 +1299,9 @@ checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" [[package]] name = "d3d12" -version = "0.7.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e16e44ab292b1dddfdaf7be62cfd8877df52f2f3fde5858d95bab606be259f20" +checksum = "3e3d747f100290a1ca24b752186f61f6637e1deffe3bf6320de6fcb29510a307" dependencies = [ "bitflags 2.4.1", "libloading 0.8.1", @@ -1323,7 +1348,7 @@ dependencies = [ "macroific", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1601,7 +1626,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1622,7 +1647,7 @@ checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1643,7 +1668,7 @@ checksum = "f95e2801cd355d4a1a3e3953ce6ee5ae9603a5c833455343a8bfe3f44d418246" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1654,7 +1679,7 @@ checksum = "c2ad8cef1d801a4686bfd8919f0b30eac4c8e48968c437a6405ded4fb5272d2b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1783,7 +1808,7 @@ dependencies = [ "macroific", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1892,7 +1917,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -2006,7 +2031,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -2180,7 +2205,7 @@ checksum = "53010ccb100b96a67bc32c0175f0ed1426b31b655d562898e57325f81c023ac0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -2233,9 +2258,9 @@ dependencies = [ [[package]] name = "glow" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "886c2a30b160c4c6fec8f987430c26b526b7988ca71f664e6a699ddf6f9601e4" +checksum = "bd348e04c43b32574f2de31c8bb397d96c9fcfa1371bd4ca6d8bdc464ab121b1" dependencies = [ "js-sys", "slotmap", @@ -2340,11 +2365,10 @@ dependencies = [ [[package]] name = "gpu-allocator" -version = "0.23.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40fe17c8a05d60c38c0a4e5a3c802f2f1ceb66b76c67d96ffb34bef0475a7fad" +checksum = "6f56f6318968d03c18e1bcf4857ff88c61157e9da8e47c5f29055d60e1228884" dependencies = [ - "backtrace", "log", "presser", "thiserror", @@ -2439,14 +2463,14 @@ dependencies = [ [[package]] name = "hassle-rs" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1397650ee315e8891a0df210707f0fc61771b0cc518c3023896064c5407cb3b0" +checksum = "af2a7e73e1f34c48da31fb668a907f250794837e08faa144fd24f0b8b741e890" dependencies = [ - "bitflags 1.3.2", - "com-rs", + "bitflags 2.4.1", + "com", "libc", - "libloading 0.7.4", + "libloading 0.8.1", "thiserror", "widestring", "winapi", @@ -2801,9 +2825,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] @@ -3185,6 +3209,7 @@ dependencies = [ "portable-atomic", "puffin", "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "ron", "serde", "static_assertions", @@ -3380,7 +3405,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -3391,7 +3416,7 @@ checksum = "13198c120864097a565ccb3ff947672d969932b7975ebd4085732c9f09435e55" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -3404,7 +3429,7 @@ dependencies = [ "macroific_core", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -3508,7 +3533,7 @@ checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -3566,9 +3591,9 @@ dependencies = [ [[package]] name = "naga" -version = "0.14.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cd05939c491da968a42986204b7431678be21fdcd4b10cc84997ba130ada5a4" +checksum = "8878eb410fc90853da3908aebfe61d73d26d4437ef850b70050461f939509899" dependencies = [ "bit-set", "bitflags 2.4.1", @@ -3587,9 +3612,9 @@ dependencies = [ [[package]] name = "naga_oil" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff3f369dd665ee365daeab786466a6f70ff53e4a95a76117363b1077e1b0492" +checksum = "86343242cc8fe7c38de0324f0c13a789729f3d360d98de12c464a815ad52feda" dependencies = [ "bit-set", "codespan-reporting", @@ -3598,7 +3623,7 @@ dependencies = [ "naga", "once_cell", "regex", - "regex-syntax 0.7.5", + "regex-syntax 0.8.2", "rustc-hash", "thiserror", "tracing", @@ -3859,7 +3884,7 @@ dependencies = [ "proc-macro-crate 2.0.0", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -3992,9 +4017,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oneshot" @@ -4034,7 +4059,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -4207,7 +4232,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -4280,7 +4305,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -4324,7 +4349,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -4530,9 +4555,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -4585,9 +4610,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -5055,7 +5080,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -5077,7 +5102,7 @@ checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -5350,12 +5375,11 @@ dependencies = [ [[package]] name = "spirv" -version = "0.2.0+1.5.4" +version = "0.3.0+sdk-1.3.268.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246bfa38fe3db3f1dfc8ca5a2cdeb7348c78be2112740cc0ec8ef18b6d94f830" +checksum = "eda41003dc44290527a59b13432d4a0379379fa074b70174882adfbdfd917844" dependencies = [ - "bitflags 1.3.2", - "num-traits", + "bitflags 2.4.1", ] [[package]] @@ -5422,7 +5446,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -5498,9 +5522,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -5583,9 +5607,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] @@ -5666,22 +5690,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -5831,7 +5855,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -5948,7 +5972,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -6271,9 +6295,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -6281,24 +6305,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.39" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" +checksum = "bde2032aeb86bdfaecc8b261eef3cba735cc426c1f3a3416d1e0791be95fc461" dependencies = [ "cfg-if", "js-sys", @@ -6308,9 +6332,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -6318,22 +6342,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "wayland-backend" @@ -6446,9 +6470,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.64" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" dependencies = [ "js-sys", "wasm-bindgen", @@ -6571,19 +6595,19 @@ dependencies = [ [[package]] name = "wgpu" -version = "0.18.0" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e7d227c9f961f2061c26f4cb0fbd4df0ef37e056edd0931783599d6c94ef24" +checksum = "0bfe9a310dcf2e6b85f00c46059aaeaf4184caa8e29a1ecd4b7a704c3482332d" dependencies = [ "arrayvec", "cfg-if", - "flume", + "cfg_aliases", "js-sys", "log", "naga", "parking_lot", "profiling", - "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "smallvec", "static_assertions", "wasm-bindgen", @@ -6596,19 +6620,22 @@ dependencies = [ [[package]] name = "wgpu-core" -version = "0.18.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef91c1d62d1e9e81c79e600131a258edf75c9531cbdbde09c44a011a47312726" +checksum = "6b15e451d4060ada0d99a64df44e4d590213496da7c4f245572d51071e8e30ed" dependencies = [ "arrayvec", "bit-vec", "bitflags 2.4.1", + "cfg_aliases", "codespan-reporting", + "indexmap", "log", "naga", + "once_cell", "parking_lot", "profiling", - "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "rustc-hash", "smallvec", "thiserror", @@ -6619,9 +6646,9 @@ dependencies = [ [[package]] name = "wgpu-hal" -version = "0.18.1" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b84ecc802da3eb67b4cf3dd9ea6fe45bbb47ef13e6c49c5c3240868a9cc6cdd9" +checksum = "e3bb47856236bfafc0bc591a925eb036ac19cd987624a447ff353e7a7e7e6f72" dependencies = [ "android_system_properties", "arrayvec", @@ -6629,6 +6656,7 @@ dependencies = [ "bit-set", "bitflags 2.4.1", "block", + "cfg_aliases", "core-graphics-types", "d3d12", "glow", @@ -6649,7 +6677,7 @@ dependencies = [ "parking_lot", "profiling", "range-alloc", - "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "renderdoc-sys", "rustc-hash", "smallvec", @@ -6662,9 +6690,9 @@ dependencies = [ [[package]] name = "wgpu-types" -version = "0.18.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d5ed5f0edf0de351fe311c53304986315ce866f394a2e6df0c4b3c70774bcdd" +checksum = "895fcbeb772bfb049eb80b2d6e47f6c9af235284e9703c96fc0218a42ffd5af2" dependencies = [ "bitflags 2.4.1", "js-sys", @@ -7268,7 +7296,7 @@ checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 08fa3e82..48b13244 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,7 +76,7 @@ luminol-egui-wgpu = { version = "0.4.0", path = "crates/egui-wgpu/" } egui_glow = "0.25.0" egui-winit = "0.25.0" -wgpu = { version = "0.18.0", features = ["naga"] } +wgpu = { version = "0.19.1", features = ["naga-ir"] } glam = { version = "0.24.2", features = ["bytemuck"] } image = "0.24.7" @@ -99,7 +99,8 @@ thiserror = "1.0.37" bitflags = "2.4.0" color-eyre = "0.6.2" puffin = "0.18" -raw-window-handle = "0.5.0" +raw-window-handle = "0.6.0" +winit = { version = "0.29.4", default-features = false } glow = "0.13" parking_lot = { version = "0.12.1", features = [ diff --git a/crates/eframe/Cargo.toml b/crates/eframe/Cargo.toml index e4852151..b32eeaea 100644 --- a/crates/eframe/Cargo.toml +++ b/crates/eframe/Cargo.toml @@ -56,7 +56,14 @@ android-native-activity = ["egui-winit/android-native-activity"] default_fonts = ["egui/default_fonts"] ## Use [`glow`](https://github.com/grovesNL/glow) for painting, via [`egui_glow`](https://github.com/emilk/egui/tree/master/crates/egui_glow). -#glow = ["dep:glow", "dep:egui_glow", "dep:glutin", "dep:glutin-winit"] +#glow = [ +# "dep:egui_glow", +# "dep:glow", +# "dep:glutin-winit", +# "dep:glutin", +# "dep:rwh_05", +# "winit/rwh_05", +#] ## Enable saving app state to disk. persistence = [ @@ -92,8 +99,19 @@ web_screen_reader = [ ] ## Use [`wgpu`](https://docs.rs/wgpu) for painting (via [`egui-wgpu`](https://github.com/emilk/egui/tree/master/crates/egui-wgpu)). +## ## This overrides the `glow` feature. -wgpu = ["dep:wgpu", "dep:luminol-egui-wgpu", "dep:pollster", "dep:raw-window-handle"] +## +## By default, only WebGPU is enabled on web. +## If you want to enable WebGL, you need to turn on the `webgl` feature of crate `wgpu`: +## +## ```ignore +## wgpu = { version = "*", features = ["webgpu", "webgl"] } +## ``` +## +## By default, eframe will prefer WebGPU over WebGL, but +## you can configure this at run-time with [`NativeOptions::wgpu_options`]. +wgpu = ["dep:wgpu", "dep:luminol-egui-wgpu", "dep:pollster"] ## Enables compiling for x11. x11 = ["egui-winit/x11"] @@ -109,6 +127,7 @@ egui = { workspace = true, features = [ ] } log = { version = "0.4", features = ["std"] } parking_lot = "0.12" +raw-window-handle.workspace = true static_assertions = "1.1.0" thiserror.workspace = true @@ -118,6 +137,10 @@ document-features = { version = "0.2", optional = true } egui_glow = { workspace = true, optional = true } glow = { workspace = true, optional = true } +# glutin stuck on old version of raw-window-handle: +rwh_05 = { package = "raw-window-handle", version = "0.5.2", optional = true, features = [ + "std", +] } ron = { workspace = true, optional = true, features = ["integer128"] } serde = { version = "1", optional = true, features = ["derive"] } @@ -131,8 +154,7 @@ egui-winit = { workspace = true, features = [ image = { version = "0.24", default-features = false, features = [ "png", ] } # Needed for app icon -raw-window-handle.workspace = true -winit = { version = "0.29.4", default-features = false, features = ["rwh_05"] } +winit = { workspace = true, default-features = false, features = ["rwh_06"] } # optional native: directories-next = { version = "2", optional = true } @@ -227,5 +249,4 @@ luminol-web = { version = "0.4.0", path = "../web/" } # optional web: luminol-egui-wgpu = { workspace = true, optional = true } # if wgpu is used, use it without (!) winit -raw-window-handle = { workspace = true, optional = true } wgpu = { workspace = true, optional = true } diff --git a/crates/eframe/README.md b/crates/eframe/README.md index f8ffb330..775a65dd 100644 --- a/crates/eframe/README.md +++ b/crates/eframe/README.md @@ -1,5 +1,5 @@ > [!IMPORTANT] -> luminol-eframe is currently based on emilk/egui@0.25.0 +> luminol-eframe is currently based on emilk/egui@b766a48fa7fe4f6a25622ebe2e5677c09553cda9 > [!NOTE] > This is Luminol's modified version of eframe. The original version is dual-licensed under MIT and Apache 2.0. diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index 3abfb298..6b86c0b5 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -15,7 +15,8 @@ pub use crate::native::winit_integration::UserEvent; #[cfg(not(target_arch = "wasm32"))] use raw_window_handle::{ - HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle, + DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle, + RawWindowHandle, WindowHandle, }; #[cfg(not(target_arch = "wasm32"))] use static_assertions::assert_not_impl_any; @@ -76,30 +77,28 @@ pub struct CreationContext<'s> { /// Raw platform window handle #[cfg(not(target_arch = "wasm32"))] - pub(crate) raw_window_handle: RawWindowHandle, + pub(crate) raw_window_handle: Result, /// Raw platform display handle for window #[cfg(not(target_arch = "wasm32"))] - pub(crate) raw_display_handle: RawDisplayHandle, + pub(crate) raw_display_handle: Result, } -// Implementing `Clone` would violate the guarantees of `HasRawWindowHandle` and `HasRawDisplayHandle`. -#[cfg(not(target_arch = "wasm32"))] -assert_not_impl_any!(CreationContext<'_>: Clone); - #[allow(unsafe_code)] #[cfg(not(target_arch = "wasm32"))] -unsafe impl HasRawWindowHandle for CreationContext<'_> { - fn raw_window_handle(&self) -> RawWindowHandle { - self.raw_window_handle +impl HasWindowHandle for CreationContext<'_> { + fn window_handle(&self) -> Result, HandleError> { + // Safety: the lifetime is correct. + unsafe { Ok(WindowHandle::borrow_raw(self.raw_window_handle.clone()?)) } } } #[allow(unsafe_code)] #[cfg(not(target_arch = "wasm32"))] -unsafe impl HasRawDisplayHandle for CreationContext<'_> { - fn raw_display_handle(&self) -> RawDisplayHandle { - self.raw_display_handle +impl HasDisplayHandle for CreationContext<'_> { + fn display_handle(&self) -> Result, HandleError> { + // Safety: the lifetime is correct. + unsafe { Ok(DisplayHandle::borrow_raw(self.raw_display_handle.clone()?)) } } } @@ -599,30 +598,32 @@ pub struct Frame { /// Raw platform window handle #[cfg(not(target_arch = "wasm32"))] - pub(crate) raw_window_handle: RawWindowHandle, + pub(crate) raw_window_handle: Result, /// Raw platform display handle for window #[cfg(not(target_arch = "wasm32"))] - pub(crate) raw_display_handle: RawDisplayHandle, + pub(crate) raw_display_handle: Result, } -// Implementing `Clone` would violate the guarantees of `HasRawWindowHandle` and `HasRawDisplayHandle`. +// Implementing `Clone` would violate the guarantees of `HasWindowHandle` and `HasDisplayHandle`. #[cfg(not(target_arch = "wasm32"))] assert_not_impl_any!(Frame: Clone); #[allow(unsafe_code)] #[cfg(not(target_arch = "wasm32"))] -unsafe impl HasRawWindowHandle for Frame { - fn raw_window_handle(&self) -> RawWindowHandle { - self.raw_window_handle +impl HasWindowHandle for Frame { + fn window_handle(&self) -> Result, HandleError> { + // Safety: the lifetime is correct. + unsafe { Ok(WindowHandle::borrow_raw(self.raw_window_handle.clone()?)) } } } #[allow(unsafe_code)] #[cfg(not(target_arch = "wasm32"))] -unsafe impl HasRawDisplayHandle for Frame { - fn raw_display_handle(&self) -> RawDisplayHandle { - self.raw_display_handle +impl HasDisplayHandle for Frame { + fn display_handle(&self) -> Result, HandleError> { + // Safety: the lifetime is correct. + unsafe { Ok(DisplayHandle::borrow_raw(self.raw_display_handle.clone()?)) } } } diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index 4f017536..c5b98063 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -4,7 +4,7 @@ use std::time::Instant; use winit::event_loop::EventLoopWindowTarget; -use raw_window_handle::{HasRawDisplayHandle as _, HasRawWindowHandle as _}; +use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _}; use egui::{DeferredViewportUiCallback, NumExt as _, ViewportBuilder, ViewportId}; use egui_winit::{EventResponse, WindowSettings}; @@ -165,8 +165,8 @@ impl EpiIntegration { gl, #[cfg(feature = "wgpu")] wgpu_render_state, - raw_display_handle: window.raw_display_handle(), - raw_window_handle: window.raw_window_handle(), + raw_display_handle: window.display_handle().map(|h| h.as_raw()), + raw_window_handle: window.window_handle().map(|h| h.as_raw()), }; let icon = native_options diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 537e7394..75820bec 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -16,7 +16,6 @@ use glutin::{ prelude::{GlDisplay, PossiblyCurrentGlContext}, surface::GlSurface, }; -use raw_window_handle::{HasRawDisplayHandle as _, HasRawWindowHandle as _}; use winit::{ event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget}, window::{Window, WindowId}, @@ -126,7 +125,7 @@ struct Viewport { // These three live and die together. // TODO(emilk): clump them together into one struct! gl_surface: Option>, - window: Option>, + window: Option>, egui_winit: Option, } @@ -294,6 +293,9 @@ impl GlowWinitApp { .expect("Single-use AppCreator has unexpectedly already been taken"); let app = { + // Use latest raw_window_handle for eframe compatibility + use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _}; + let window = glutin.window(ViewportId::ROOT); let cc = CreationContext { egui_ctx: integration.egui_ctx.clone(), @@ -302,8 +304,8 @@ impl GlowWinitApp { gl: Some(gl), #[cfg(feature = "wgpu")] wgpu_render_state: None, - raw_display_handle: window.raw_display_handle(), - raw_window_handle: window.raw_window_handle(), + raw_display_handle: window.display_handle().map(|h| h.as_raw()), + raw_window_handle: window.window_handle().map(|h| h.as_raw()), }; crate::profile_scope!("app_creator"); app_creator(&cc) @@ -373,7 +375,7 @@ impl WinitApp for GlowWinitApp { self.running.as_ref().map(|r| &r.integration) } - fn window(&self, window_id: WindowId) -> Option> { + fn window(&self, window_id: WindowId) -> Option> { let running = self.running.as_ref()?; let glutin = running.glutin.borrow(); let viewport_id = *glutin.viewport_from_window.get(&window_id)?; @@ -898,15 +900,18 @@ impl GlutinWindowContext { gl_display.version_string(), gl_display.supported_features() ); - let raw_window_handle = window.as_ref().map(|w| w.raw_window_handle()); - log::debug!("creating gl context using raw window handle: {raw_window_handle:?}"); + let glutin_raw_window_handle = window.as_ref().map(|w| { + use rwh_05::HasRawWindowHandle as _; // glutin stuck on old version of raw-window-handle + w.raw_window_handle() + }); + log::debug!("creating gl context using raw window handle: {glutin_raw_window_handle:?}"); // create gl context. if core context cannot be created, try gl es context as fallback. let context_attributes = - glutin::context::ContextAttributesBuilder::new().build(raw_window_handle); + glutin::context::ContextAttributesBuilder::new().build(glutin_raw_window_handle); let fallback_context_attributes = glutin::context::ContextAttributesBuilder::new() .with_context_api(glutin::context::ContextApi::Gles(None)) - .build(raw_window_handle); + .build(glutin_raw_window_handle); let gl_context_result = unsafe { crate::profile_scope!("create_context"); @@ -952,7 +957,7 @@ impl GlutinWindowContext { screenshot_requested: false, viewport_ui_cb: None, gl_surface: None, - window: window.map(Rc::new), + window: window.map(Arc::new), egui_winit: None, }, ); @@ -962,7 +967,7 @@ impl GlutinWindowContext { // help us start from scratch again if we fail context creation and go back to preferEgl or try with different config etc.. // https://github.com/emilk/egui/pull/2541#issuecomment-1370767582 - let mut slf = GlutinWindowContext { + let mut slf = Self { egui_ctx: egui_ctx.clone(), swap_interval, gl_config, @@ -1031,7 +1036,7 @@ impl GlutinWindowContext { ); viewport.info.minimized = window.is_minimized(); viewport.info.maximized = Some(window.is_maximized()); - viewport.window.insert(Rc::new(window)) + viewport.window.insert(Arc::new(window)) }; viewport.egui_winit.get_or_insert_with(|| { @@ -1052,9 +1057,11 @@ impl GlutinWindowContext { let (width_px, height_px): (u32, u32) = window.inner_size().into(); let width_px = std::num::NonZeroU32::new(width_px.at_least(1)).unwrap(); let height_px = std::num::NonZeroU32::new(height_px.at_least(1)).unwrap(); - let surface_attributes = + let surface_attributes = { + use rwh_05::HasRawWindowHandle as _; // glutin stuck on old version of raw-window-handle glutin::surface::SurfaceAttributesBuilder::::new() - .build(window.raw_window_handle(), width_px, height_px); + .build(window.raw_window_handle(), width_px, height_px) + }; log::trace!("creating surface with attributes: {surface_attributes:?}"); let gl_surface = unsafe { @@ -1120,7 +1127,7 @@ impl GlutinWindowContext { .expect("viewport doesn't exist") } - fn window(&self, viewport_id: ViewportId) -> Rc { + fn window(&self, viewport_id: ViewportId) -> Arc { self.viewport(viewport_id) .window .clone() diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 7bd5b38e..d0a6d27c 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -8,7 +8,7 @@ use std::{cell::RefCell, rc::Rc, sync::Arc, time::Instant}; use parking_lot::Mutex; -use raw_window_handle::{HasRawDisplayHandle as _, HasRawWindowHandle as _}; +use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _}; use winit::{ event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget}, window::{Window, WindowId}, @@ -84,7 +84,7 @@ pub struct Viewport { /// Window surface state that's initialized when the app starts running via a Resumed event /// and on Android will also be destroyed if the application is paused. - window: Option>, + window: Option>, /// `window` and `egui_winit` are initialized together. egui_winit: Option, @@ -170,9 +170,11 @@ impl WgpuWinitApp { self.native_options.viewport.transparent.unwrap_or(false), ); + let window = Arc::new(window); + { crate::profile_scope!("set_window"); - pollster::block_on(painter.set_window(ViewportId::ROOT, Some(&window)))?; + pollster::block_on(painter.set_window(ViewportId::ROOT, Some(window.clone())))?; } let wgpu_render_state = painter.render_state(); @@ -235,8 +237,8 @@ impl WgpuWinitApp { #[cfg(feature = "glow")] gl: None, wgpu_render_state, - raw_display_handle: window.raw_display_handle(), - raw_window_handle: window.raw_window_handle(), + raw_display_handle: window.display_handle().map(|h| h.as_raw()), + raw_window_handle: window.window_handle().map(|h| h.as_raw()), }; let app = { crate::profile_scope!("user_app_creator"); @@ -260,7 +262,7 @@ impl WgpuWinitApp { }, screenshot_requested: false, viewport_ui_cb: None, - window: Some(Rc::new(window)), + window: Some(window), egui_winit: Some(egui_winit), }, ); @@ -323,7 +325,7 @@ impl WinitApp for WgpuWinitApp { self.running.as_ref().map(|r| &r.integration) } - fn window(&self, window_id: WindowId) -> Option> { + fn window(&self, window_id: WindowId) -> Option> { self.running .as_ref() .and_then(|r| { @@ -492,7 +494,7 @@ impl WgpuWinitRunning { #[cfg(feature = "puffin")] puffin::GlobalProfiler::lock().new_frame(); - let WgpuWinitRunning { + let Self { app, integration, shared, @@ -544,7 +546,8 @@ impl WgpuWinitRunning { { crate::profile_scope!("set_window"); - if let Err(err) = pollster::block_on(painter.set_window(viewport_id, Some(window))) + if let Err(err) = + pollster::block_on(painter.set_window(viewport_id, Some(window.clone()))) { log::warn!("Failed to set window: {err}"); } @@ -797,7 +800,10 @@ impl Viewport { Ok(window) => { windows_id.insert(window.id(), viewport_id); - if let Err(err) = pollster::block_on(painter.set_window(viewport_id, Some(&window))) + let window = Arc::new(window); + + if let Err(err) = + pollster::block_on(painter.set_window(viewport_id, Some(window.clone()))) { log::error!("on set_window: viewport_id {viewport_id:?} {err}"); } @@ -813,7 +819,7 @@ impl Viewport { self.info.minimized = window.is_minimized(); self.info.maximized = Some(window.is_maximized()); - self.window = Some(Rc::new(window)); + self.window = Some(window); } Err(err) => { log::error!("Failed to create window: {err}"); @@ -930,7 +936,7 @@ fn render_immediate_viewport( { crate::profile_scope!("set_window"); - if let Err(err) = pollster::block_on(painter.set_window(ids.this, Some(window))) { + if let Err(err) = pollster::block_on(painter.set_window(ids.this, Some(window.clone()))) { log::error!( "when rendering viewport_id={:?}, set_window Error {err}", ids.this diff --git a/crates/eframe/src/native/winit_integration.rs b/crates/eframe/src/native/winit_integration.rs index a7e4bb38..541253c0 100644 --- a/crates/eframe/src/native/winit_integration.rs +++ b/crates/eframe/src/native/winit_integration.rs @@ -1,4 +1,4 @@ -use std::{rc::Rc, time::Instant}; +use std::{sync::Arc, time::Instant}; use winit::{ event_loop::EventLoopWindowTarget, @@ -68,7 +68,7 @@ pub trait WinitApp { fn integration(&self) -> Option<&EpiIntegration>; - fn window(&self, window_id: WindowId) -> Option>; + fn window(&self, window_id: WindowId) -> Option>; fn window_id_from_viewport_id(&self, id: ViewportId) -> Option; diff --git a/crates/eframe/src/web/web_logger.rs b/crates/eframe/src/web/web_logger.rs index 90dfc1b3..18936495 100644 --- a/crates/eframe/src/web/web_logger.rs +++ b/crates/eframe/src/web/web_logger.rs @@ -7,7 +7,7 @@ impl WebLogger { /// Install a new `WebLogger`, piping all [`log`] events to the web console. pub fn init(filter: log::LevelFilter) -> Result<(), log::SetLoggerError> { log::set_max_level(filter); - log::set_boxed_logger(Box::new(WebLogger::new(filter))) + log::set_boxed_logger(Box::new(Self::new(filter))) } /// Create a new [`WebLogger`] with the given filter, @@ -19,6 +19,21 @@ impl WebLogger { impl log::Log for WebLogger { fn enabled(&self, metadata: &log::Metadata<'_>) -> bool { + /// Never log anything less serious than a `INFO` from these crates. + const CRATES_AT_INFO_LEVEL: &[&str] = &[ + // wgpu crates spam a lot on debug level, which is really annoying + "naga", + "wgpu_core", + "wgpu_hal", + ]; + + if CRATES_AT_INFO_LEVEL + .iter() + .any(|crate_name| metadata.target().starts_with(crate_name)) + { + return metadata.level() <= log::LevelFilter::Info; + } + metadata.level() <= self.filter } diff --git a/crates/eframe/src/web/web_painter_wgpu.rs b/crates/eframe/src/web/web_painter_wgpu.rs index 343d8031..28c150cf 100644 --- a/crates/eframe/src/web/web_painter_wgpu.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -1,5 +1,9 @@ use std::sync::Arc; +use raw_window_handle::{ + DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle, + RawWindowHandle, WebDisplayHandle, WebWindowHandle, WindowHandle, +}; use wasm_bindgen::JsValue; use luminol_egui_wgpu::{renderer::ScreenDescriptor, RenderState, SurfaceErrorAction}; @@ -11,24 +15,32 @@ use super::web_painter::WebPainter; struct EguiWebWindow(u32); #[allow(unsafe_code)] -unsafe impl raw_window_handle::HasRawWindowHandle for EguiWebWindow { - fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle { - let mut window_handle = raw_window_handle::WebWindowHandle::empty(); - window_handle.id = self.0; - raw_window_handle::RawWindowHandle::Web(window_handle) +impl HasWindowHandle for EguiWebWindow { + fn window_handle(&self) -> Result, HandleError> { + // SAFETY: there is no lifetime here. + unsafe { + Ok(WindowHandle::borrow_raw(RawWindowHandle::Web( + WebWindowHandle::new(self.0), + ))) + } } } #[allow(unsafe_code)] -unsafe impl raw_window_handle::HasRawDisplayHandle for EguiWebWindow { - fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle { - raw_window_handle::RawDisplayHandle::Web(raw_window_handle::WebDisplayHandle::empty()) +impl HasDisplayHandle for EguiWebWindow { + fn display_handle(&self) -> Result, HandleError> { + // SAFETY: there is no lifetime here. + unsafe { + Ok(DisplayHandle::borrow_raw(RawDisplayHandle::Web( + WebDisplayHandle::new(), + ))) + } } } pub(crate) struct WebPainterWgpu { canvas: web_sys::OffscreenCanvas, - surface: wgpu::Surface, + surface: wgpu::Surface<'static>, pub(super) surface_configuration: wgpu::SurfaceConfiguration, render_state: Option, on_surface_error: Arc SurfaceErrorAction>, @@ -84,13 +96,22 @@ impl WebPainterWgpu { ) -> Result { log::debug!("Creating wgpu painter"); + { + let is_secure_context = web_sys::window().map_or(false, |w| w.is_secure_context()); + if !is_secure_context { + log::info!( + "WebGPU is only available in secure contexts, i.e. on HTTPS and on localhost" + ); + } + } + let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { backends: options.wgpu_options.supported_backends, ..Default::default() }); let surface = instance - .create_surface_from_offscreen_canvas(canvas.clone()) + .create_surface(wgpu::SurfaceTarget::OffscreenCanvas(canvas.clone())) .map_err(|err| format!("failed to create wgpu surface: {err}"))?; let depth_format = luminol_egui_wgpu::depth_format_from_bits(options.depth_buffer, 0); @@ -99,14 +120,17 @@ impl WebPainterWgpu { .await .map_err(|err| err.to_string())?; + let (width, height) = (0, 0); + let surface_configuration = wgpu::SurfaceConfiguration { usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format: render_state.target_format, - width: 0, - height: 0, present_mode: options.wgpu_options.present_mode, alpha_mode: wgpu::CompositeAlphaMode::Auto, view_formats: vec![render_state.target_format], + ..surface + .get_default_config(&render_state.adapter, width, height) + .ok_or("The surface isn't supported by this adapter")? }; log::debug!("wgpu painter initialized."); diff --git a/crates/eframe/src/web/web_runner.rs b/crates/eframe/src/web/web_runner.rs index c0d827bb..df8c963f 100644 --- a/crates/eframe/src/web/web_runner.rs +++ b/crates/eframe/src/web/web_runner.rs @@ -247,14 +247,14 @@ enum EventToUnsubscribe { impl EventToUnsubscribe { pub fn unsubscribe(self) -> Result<(), JsValue> { match self { - EventToUnsubscribe::TargetEvent(handle) => { + Self::TargetEvent(handle) => { handle.target.remove_event_listener_with_callback( handle.event_name.as_str(), handle.closure.as_ref().unchecked_ref(), )?; Ok(()) } - EventToUnsubscribe::IntervalHandle(handle) => { + Self::IntervalHandle(handle) => { let window = web_sys::window().unwrap(); window.clear_interval_with_handle(handle.handle); Ok(()) diff --git a/crates/egui-wgpu/Cargo.toml b/crates/egui-wgpu/Cargo.toml index fe11e70d..95f70e3e 100644 --- a/crates/egui-wgpu/Cargo.toml +++ b/crates/egui-wgpu/Cargo.toml @@ -51,8 +51,8 @@ wgpu.workspace = true ## Enable this when generating docs. document-features = { version = "0.2", optional = true } -winit = { version = "0.29.4", default-features = false, optional = true, features = [ - "rwh_05", +winit = { workspace = true, optional = true, default-features = false, features = [ + "rwh_06", ] } # Native: diff --git a/crates/egui-wgpu/README.md b/crates/egui-wgpu/README.md index a6d152c4..1315daf4 100644 --- a/crates/egui-wgpu/README.md +++ b/crates/egui-wgpu/README.md @@ -1,5 +1,5 @@ > [!IMPORTANT] -> luminol-egui-wgpu is currently based on emilk/egui@0.25.0 +> luminol-egui-wgpu is currently based on emilk/egui@b766a48fa7fe4f6a25622ebe2e5677c09553cda9 > [!NOTE] > This is Luminol's modified version of egui-wgpu. The original version is dual-licensed under MIT and Apache 2.0. diff --git a/crates/egui-wgpu/src/lib.rs b/crates/egui-wgpu/src/lib.rs index d560f70d..da3e4763 100644 --- a/crates/egui-wgpu/src/lib.rs +++ b/crates/egui-wgpu/src/lib.rs @@ -1,5 +1,17 @@ //! This crates provides bindings between [`egui`](https://github.com/emilk/egui) and [wgpu](https://crates.io/crates/wgpu). //! +//! If you're targeting WebGL you also need to turn on the +//! `webgl` feature of the `wgpu` crate: +//! +//! ```ignore +//! # Enable both WebGL and WebGPU backends on web. +//! wgpu = { version = "*", features = ["webgpu", "webgl"] } +//! ``` +//! +//! You can control whether WebGL or WebGPU will be picked at runtime by setting +//! [`WgpuConfiguration::supported_backends`]. +//! The default is to prefer WebGPU and fall back on WebGL. +//! //! ## Feature flags #![cfg_attr(feature = "document-features", doc = document_features::document_features!())] //! @@ -24,6 +36,7 @@ use std::sync::Arc; use epaint::mutex::RwLock; +/// An error produced by egui-wgpu. #[derive(thiserror::Error, Debug)] pub enum WgpuError { #[error("Failed to create wgpu adapter, no suitable adapter found.")] @@ -37,6 +50,10 @@ pub enum WgpuError { #[error(transparent)] CreateSurfaceError(#[from] wgpu::CreateSurfaceError), + + #[cfg(feature = "winit")] + #[error(transparent)] + HandleError(#[from] ::winit::raw_window_handle::HandleError), } /// Access to the render state for egui. @@ -45,6 +62,13 @@ pub struct RenderState { /// Wgpu adapter used for rendering. pub adapter: Arc, + /// All the available adapters. + /// + /// This is not available on web. + /// On web, we always select WebGPU is available, then fall back to WebGL if not. + #[cfg(not(target_arch = "wasm32"))] + pub available_adapters: Arc<[wgpu::Adapter]>, + /// Wgpu device used for rendering, created from the adapter. pub device: Arc, @@ -66,14 +90,15 @@ impl RenderState { pub async fn create( config: &WgpuConfiguration, instance: &wgpu::Instance, - surface: &wgpu::Surface, + surface: &wgpu::Surface<'static>, depth_format: Option, msaa_samples: u32, ) -> Result { crate::profile_scope!("RenderState::create"); // async yield give bad names using `profile_function` + // This is always an empty list on web. #[cfg(not(target_arch = "wasm32"))] - let adapters: Vec<_> = instance.enumerate_adapters(wgpu::Backends::all()).collect(); + let available_adapters = instance.enumerate_adapters(wgpu::Backends::all()); let adapter = { crate::profile_scope!("request_adapter"); @@ -86,18 +111,18 @@ impl RenderState { .await .ok_or_else(|| { #[cfg(not(target_arch = "wasm32"))] - if adapters.is_empty() { + if available_adapters.is_empty() { log::info!("No wgpu adapters found"); - } else if adapters.len() == 1 { + } else if available_adapters.len() == 1 { log::info!( "The only available wgpu adapter was not suitable: {}", - adapter_info_summary(&adapters[0].get_info()) + adapter_info_summary(&available_adapters[0].get_info()) ); } else { log::info!( "No suitable wgpu adapter found out of the {} available ones: {}", - adapters.len(), - describe_adapters(&adapters) + available_adapters.len(), + describe_adapters(&available_adapters) ); } @@ -112,7 +137,7 @@ impl RenderState { ); #[cfg(not(target_arch = "wasm32"))] - if adapters.len() == 1 { + if available_adapters.len() == 1 { log::debug!( "Picked the only available wgpu adapter: {}", adapter_info_summary(&adapter.get_info()) @@ -120,8 +145,8 @@ impl RenderState { } else { log::info!( "There were {} available wgpu adapters: {}", - adapters.len(), - describe_adapters(&adapters) + available_adapters.len(), + describe_adapters(&available_adapters) ); log::debug!( "Picked wgpu adapter: {}", @@ -144,8 +169,10 @@ impl RenderState { let renderer = Renderer::new(&device, target_format, depth_format, msaa_samples); - Ok(RenderState { + Ok(Self { adapter: Arc::new(adapter), + #[cfg(not(target_arch = "wasm32"))] + available_adapters: available_adapters.into(), device: Arc::new(device), queue: Arc::new(queue), target_format, @@ -183,12 +210,19 @@ pub enum SurfaceErrorAction { /// Configuration for using wgpu with eframe or the egui-wgpu winit feature. /// -/// This can be configured with the environment variables: +/// This can also be configured with the environment variables: /// * `WGPU_BACKEND`: `vulkan`, `dx11`, `dx12`, `metal`, `opengl`, `webgpu` /// * `WGPU_POWER_PREF`: `low`, `high` or `none` #[derive(Clone)] pub struct WgpuConfiguration { - /// Backends that should be supported (wgpu will pick one of these) + /// Backends that should be supported (wgpu will pick one of these). + /// + /// For instance, if you only want to support WebGL (and not WebGPU), + /// you can set this to [`wgpu::Backends::GL`]. + /// + /// By default on web, WebGPU will be used if available. + /// WebGL will only be used as a fallback, + /// and only if you have enabled the `webgl` feature of crate `wgpu`. pub supported_backends: wgpu::Backends, /// Configuration passed on device request, given an adapter @@ -218,7 +252,7 @@ impl Default for WgpuConfiguration { fn default() -> Self { Self { // Add GL backend, primarily because WebGPU is not stable enough yet. - // (note however, that the GL backend needs to be opted-in via a wgpu feature flag) + // (note however, that the GL backend needs to be opted-in via the wgpu feature flag "webgl") supported_backends: wgpu::util::backend_bits_from_env() .unwrap_or(wgpu::Backends::PRIMARY | wgpu::Backends::GL), @@ -231,8 +265,8 @@ impl Default for WgpuConfiguration { wgpu::DeviceDescriptor { label: Some("egui wgpu device"), - features: wgpu::Features::default(), - limits: wgpu::Limits { + required_features: wgpu::Features::default(), + required_limits: wgpu::Limits { // When using a depth buffer, we have to be able to create a texture // large enough for the entire surface, and we want to support 4k+ displays. max_texture_dimension_2d: 8192, diff --git a/crates/egui-wgpu/src/renderer.rs b/crates/egui-wgpu/src/renderer.rs index fc6a668b..780c9086 100644 --- a/crates/egui-wgpu/src/renderer.rs +++ b/crates/egui-wgpu/src/renderer.rs @@ -7,8 +7,14 @@ use epaint::{ahash::HashMap, emath::NumExt, PaintCallbackInfo, Primitive, Vertex use wgpu; use wgpu::util::DeviceExt as _; +/// You can use this for storage when implementing [`CallbackTrait`]. pub type CallbackResources = type_map::concurrent::TypeMap; +/// You can use this to do custom `wgpu` rendering in an egui app. +/// +/// Implement [`CallbackTrait`] and call [`Callback::new_paint_callback`]. +/// +/// This can be turned into a [`epaint::PaintCallback`] and [`epaint::Shape`]. pub struct Callback(Box); impl Callback { diff --git a/crates/egui-wgpu/src/winit.rs b/crates/egui-wgpu/src/winit.rs index 5cf71b64..15460686 100644 --- a/crates/egui-wgpu/src/winit.rs +++ b/crates/egui-wgpu/src/winit.rs @@ -5,7 +5,7 @@ use egui::{ViewportId, ViewportIdMap, ViewportIdSet}; use crate::{renderer, RenderState, SurfaceErrorAction, WgpuConfiguration}; struct SurfaceState { - surface: wgpu::Surface, + surface: wgpu::Surface<'static>, alpha_mode: wgpu::CompositeAlphaMode, width: u32, height: u32, @@ -151,16 +151,23 @@ impl Painter { } else { wgpu::TextureUsages::RENDER_ATTACHMENT }; + + let width = surface_state.width; + let height = surface_state.height; + surface_state.surface.configure( &render_state.device, &wgpu::SurfaceConfiguration { + // TODO(emilk): expose `desired_maximum_frame_latency` to eframe users usage, format: render_state.target_format, - width: surface_state.width, - height: surface_state.height, present_mode, alpha_mode: surface_state.alpha_mode, view_formats: vec![render_state.target_format], + ..surface_state + .surface + .get_default_config(&render_state.adapter, width, height) + .expect("The surface isn't supported by this adapter") }, ); } @@ -189,79 +196,44 @@ impl Painter { pub async fn set_window( &mut self, viewport_id: ViewportId, - window: Option<&winit::window::Window>, + window: Option>, ) -> Result<(), crate::WgpuError> { - crate::profile_scope!("Painter::set_window"); // profle_function gives bad names for async functions + crate::profile_scope!("Painter::set_window"); // profile_function gives bad names for async functions if let Some(window) = window { let size = window.inner_size(); if self.surfaces.get(&viewport_id).is_none() { - let surface = unsafe { - crate::profile_scope!("create_surface"); - self.instance.create_surface(&window)? - }; - - let render_state = if let Some(render_state) = &self.render_state { - render_state - } else { - let render_state = RenderState::create( - &self.configuration, - &self.instance, - &surface, - self.depth_format, - self.msaa_samples, - ) - .await?; - self.render_state.get_or_insert(render_state) - }; - - let alpha_mode = if self.support_transparent_backbuffer { - let supported_alpha_modes = - surface.get_capabilities(&render_state.adapter).alpha_modes; - - // Prefer pre multiplied over post multiplied! - if supported_alpha_modes.contains(&wgpu::CompositeAlphaMode::PreMultiplied) { - wgpu::CompositeAlphaMode::PreMultiplied - } else if supported_alpha_modes - .contains(&wgpu::CompositeAlphaMode::PostMultiplied) - { - wgpu::CompositeAlphaMode::PostMultiplied - } else { - log::warn!("Transparent window was requested, but the active wgpu surface does not support a `CompositeAlphaMode` with transparency."); - wgpu::CompositeAlphaMode::Auto - } - } else { - wgpu::CompositeAlphaMode::Auto - }; + let surface = self.instance.create_surface(window)?; + self.add_surface(surface, viewport_id, size).await?; + } + } else { + log::warn!("No window - clearing all surfaces"); + self.surfaces.clear(); + } + Ok(()) + } - let supports_screenshot = - !matches!(render_state.adapter.get_info().backend, wgpu::Backend::Gl); - - self.surfaces.insert( - viewport_id, - SurfaceState { - surface, - width: size.width, - height: size.height, - alpha_mode, - supports_screenshot, - }, - ); + /// Updates (or clears) the [`winit::window::Window`] associated with the [`Painter`] without taking ownership of the window. + /// + /// Like [`set_window`](Self::set_window) except: + /// + /// # Safety + /// The user is responsible for ensuring that the window is alive for as long as it is set. + pub async unsafe fn set_window_unsafe( + &mut self, + viewport_id: ViewportId, + window: Option<&winit::window::Window>, + ) -> Result<(), crate::WgpuError> { + crate::profile_scope!("Painter::set_window_unsafe"); // profile_function gives bad names for async functions - let Some(width) = NonZeroU32::new(size.width) else { - log::debug!("The window width was zero; skipping generate textures"); - return Ok(()); - }; - let Some(height) = NonZeroU32::new(size.height) else { - log::debug!("The window height was zero; skipping generate textures"); - return Ok(()); + if let Some(window) = window { + let size = window.inner_size(); + if self.surfaces.get(&viewport_id).is_none() { + let surface = unsafe { + self.instance + .create_surface_unsafe(wgpu::SurfaceTargetUnsafe::from_window(&window)?)? }; - - self.resize_and_generate_depth_texture_view_and_msaa_view( - viewport_id, - width, - height, - ); + self.add_surface(surface, viewport_id, size).await?; } } else { log::warn!("No window - clearing all surfaces"); @@ -270,6 +242,64 @@ impl Painter { Ok(()) } + async fn add_surface( + &mut self, + surface: wgpu::Surface<'static>, + viewport_id: ViewportId, + size: winit::dpi::PhysicalSize, + ) -> Result<(), crate::WgpuError> { + let render_state = if let Some(render_state) = &self.render_state { + render_state + } else { + let render_state = RenderState::create( + &self.configuration, + &self.instance, + &surface, + self.depth_format, + self.msaa_samples, + ) + .await?; + self.render_state.get_or_insert(render_state) + }; + let alpha_mode = if self.support_transparent_backbuffer { + let supported_alpha_modes = surface.get_capabilities(&render_state.adapter).alpha_modes; + + // Prefer pre multiplied over post multiplied! + if supported_alpha_modes.contains(&wgpu::CompositeAlphaMode::PreMultiplied) { + wgpu::CompositeAlphaMode::PreMultiplied + } else if supported_alpha_modes.contains(&wgpu::CompositeAlphaMode::PostMultiplied) { + wgpu::CompositeAlphaMode::PostMultiplied + } else { + log::warn!("Transparent window was requested, but the active wgpu surface does not support a `CompositeAlphaMode` with transparency."); + wgpu::CompositeAlphaMode::Auto + } + } else { + wgpu::CompositeAlphaMode::Auto + }; + let supports_screenshot = + !matches!(render_state.adapter.get_info().backend, wgpu::Backend::Gl); + self.surfaces.insert( + viewport_id, + SurfaceState { + surface, + width: size.width, + height: size.height, + alpha_mode, + supports_screenshot, + }, + ); + let Some(width) = NonZeroU32::new(size.width) else { + log::debug!("The window width was zero; skipping generate textures"); + return Ok(()); + }; + let Some(height) = NonZeroU32::new(size.height) else { + log::debug!("The window height was zero; skipping generate textures"); + return Ok(()); + }; + self.resize_and_generate_depth_texture_view_and_msaa_view(viewport_id, width, height); + Ok(()) + } + /// Returns the maximum texture dimension supported if known /// /// This API will only return a known dimension after `set_window()` has been called diff --git a/crates/graphics/Cargo.toml b/crates/graphics/Cargo.toml index 193a1ddb..9efca02d 100644 --- a/crates/graphics/Cargo.toml +++ b/crates/graphics/Cargo.toml @@ -24,8 +24,8 @@ luminol-egui-wgpu.workspace = true wgpu.workspace = true glam.workspace = true -naga_oil = "0.11.0" -naga = "0.14.1" +naga_oil = "0.12.0" +naga = "0.19.0" crossbeam.workspace = true dashmap.workspace = true