From 81bfe24fc8d21c61d68166f8988fb48b88524b28 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Mon, 3 Oct 2022 20:32:25 +0200 Subject: [PATCH 01/23] basic working wgpu @ webgl on websys --- Cargo.lock | 415 ++++++++++------------ crates/eframe/Cargo.toml | 9 +- crates/eframe/src/epi.rs | 2 + crates/eframe/src/web/backend.rs | 9 +- crates/eframe/src/web/events.rs | 1 - crates/eframe/src/web/mod.rs | 10 +- crates/eframe/src/web/web_glow_painter.rs | 21 +- crates/eframe/src/web/web_wgpu_painter.rs | 163 +++++++++ crates/egui-wgpu/src/lib.rs | 14 +- crates/egui-wgpu/src/winit.rs | 12 +- 10 files changed, 386 insertions(+), 270 deletions(-) create mode 100644 crates/eframe/src/web/web_wgpu_painter.rs diff --git a/Cargo.lock b/Cargo.lock index 100325eaa86..2ae426c8f30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "ab_glyph" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "846ffacb9d0c8b879ef9e565b59e18fb76d6a61013e5bd24ecc659864e6b1a1f" +checksum = "04a9283dace1c41c265496614998d5b9c4a97b3eb770e804f007c5144bf03f2b" dependencies = [ "ab_glyph_rasterizer", "owned_ttf_parser", @@ -14,9 +14,9 @@ dependencies = [ [[package]] name = "ab_glyph_rasterizer" -version = "0.1.5" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a13739d7177fbd22bb0ed28badfff9f372f8bef46c863db4e1c6248f6b223b6e" +checksum = "330223a1aecc308757b9926e9391c9b47f8ef2dbd8aea9df88312aea18c5e8d6" [[package]] name = "addr2line" @@ -33,18 +33,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "adler32" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" - -[[package]] -name = "ahash" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" - [[package]] name = "ahash" version = "0.7.6" @@ -71,18 +59,18 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] [[package]] name = "android_system_properties" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7ed72e1635e121ca3e79420540282af22da58be50de153d36f81ddc6b83aa9e" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ "libc", ] @@ -104,9 +92,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.62" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "approx" @@ -200,9 +188,9 @@ dependencies = [ [[package]] name = "async-io" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab006897723d9352f63e2b13047177c3982d8d79709d713ce7747a8f19fd1b0" +checksum = "83e21f3a490c72b3b0cf44962180e60045de2925d8dff97918f7ee43c8f637c7" dependencies = [ "autocfg", "concurrent-queue", @@ -431,7 +419,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a22a6a8f622f797120d452c630b0ab12e1331a1a753e2039ce7868d4ac77b4ee" dependencies = [ "log", - "nix 0.24.2", + "nix", "slotmap", "thiserror", "vec_map", @@ -563,9 +551,9 @@ checksum = "7a0e87cdf78571d9fbeff16861c37a006cd718d2433dc6d5b80beaae367d899a" [[package]] name = "clang-sys" -version = "1.3.3" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a050e2153c5be08febd6734e29298e844fdb0fa21aeddd63b4eb7baa106c69b" +checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" dependencies = [ "glob", "libc", @@ -574,9 +562,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.17" +version = "3.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29e724a68d9319343bb3328c9cc2dfde263f4b3142ee1059a9980580171c954b" +checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" dependencies = [ "atty", "bitflags", @@ -819,12 +807,11 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" dependencies = [ "cfg-if", - "once_cell", ] [[package]] @@ -912,9 +899,9 @@ dependencies = [ [[package]] name = "dark-light" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b83576e2eee2d9cdaa8d08812ae59cbfe1b5ac7ac5ac4b8400303c6148a88c1" +checksum = "413487ef345ab5cdfbf23e66070741217a701bce70f2f397a54221b4f2b6056a" dependencies = [ "dconf_rs", "detect-desktop-environment", @@ -977,15 +964,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7046468a81e6a002061c01e6a7c83139daf91b11c30e66795b13217c2d885c8b" -[[package]] -name = "deflate" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c86f7e25f518f4b81808a2cf1c50996a61f5c2eb394b2393bd87f2a4780a432f" -dependencies = [ - "adler32", -] - [[package]] name = "derivative" version = "2.2.0" @@ -1061,18 +1039,18 @@ dependencies = [ [[package]] name = "dlv-list" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68df3f2b690c1b86e65ef7830956aededf3cb0a16f898f79b9a6f421a7b6211b" -dependencies = [ - "rand", -] +checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" [[package]] name = "document-features" -version = "0.2.3" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d99bbe945402eb228b85cdfc7020cf7422574976861c642b28255d0a49606d79" +checksum = "c3267e1ade4f1f6ddd35fed44a04b6514e244ffeda90c6a14a9ee30f9c9fd7a1" +dependencies = [ + "litrs", +] [[package]] name = "downcast-rs" @@ -1149,6 +1127,7 @@ dependencies = [ "glutin", "js-sys", "percent-encoding", + "pollster", "puffin", "ron", "serde", @@ -1360,9 +1339,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" +checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272" dependencies = [ "atty", "humantime", @@ -1530,11 +1509,10 @@ checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" [[package]] name = "form_urlencoded" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" dependencies = [ - "matches", "percent-encoding", ] @@ -1562,15 +1540,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.23" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2acedae88d38235936c3922476b10fced7b2b68136f5e3c03c2d5be348a1115" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" [[package]] name = "futures-io" -version = "0.3.23" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93a66fc6d035a26a3ae255a6d2bca35eda63ae4c5512bef54449113f7a1228e5" +checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" [[package]] name = "futures-lite" @@ -1589,21 +1567,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.23" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca0bae1fe9752cf7fd9b0064c674ae63f97b37bc714d745cbde0afb7ec4e6765" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" [[package]] name = "futures-task" -version = "0.3.23" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "842fc63b931f4056a24d59de13fb1272134ce261816e063e634ad0c15cdc5306" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" [[package]] name = "futures-util" -version = "0.3.23" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0828a5471e340229c11c77ca80017937ce3c58cb788a17e5f1c2d5c485a9577" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-core", "futures-sink", @@ -1862,7 +1840,7 @@ checksum = "0b0c02e1ba0bdb14e965058ca34e09c020f8e507a760df1121728e0aef68d57a" dependencies = [ "bitflags", "gpu-descriptor-types", - "hashbrown 0.12.3", + "hashbrown", ] [[package]] @@ -1902,15 +1880,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "hashbrown" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" -dependencies = [ - "ahash 0.4.7", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -1962,9 +1931,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "iana-time-zone" -version = "0.1.46" +version = "0.1.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad2bfd338099682614d3ee3fe0cd72e0b6a41ca6a87f6a74a3bd593c91650501" +checksum = "fd911b35d940d2bd0bea0f9100068e5b97b51a1cbe13d13382f132e0365257a0" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1981,20 +1950,19 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" dependencies = [ - "matches", "unicode-bidi", "unicode-normalization", ] [[package]] name = "image" -version = "0.24.3" +version = "0.24.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e30ca2ecf7666107ff827a8e481de6a132a9b687ed3bb20bb1c144a36c00964" +checksum = "bd8e4fb07cf672b1642304e731ef8a6a4c7891d67bb4fd4f5ce58cd6ed86803c" dependencies = [ "bytemuck", "byteorder", @@ -2012,14 +1980,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", - "hashbrown 0.12.3", + "hashbrown", ] [[package]] name = "inplace_it" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67f0347836f3f6362c1e7efdadde2b1c4b4556d211310b70631bae7eb692070b" +checksum = "e567468c50f3d4bc7397702e09b380139f9b9288b4e909b070571007f8b5bf78" [[package]] name = "instant" @@ -2035,9 +2003,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.3" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ "either", ] @@ -2070,9 +2038,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" [[package]] name = "jobserver" -version = "0.1.24" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" +checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" dependencies = [ "libc", ] @@ -2085,9 +2053,9 @@ checksum = "9478aa10f73e7528198d75109c8be5cd7d15fb530238040148d5f9a22d4c5b3b" [[package]] name = "js-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -2132,9 +2100,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.132" +version = "0.2.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" +checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" [[package]] name = "libloading" @@ -2167,11 +2135,17 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "litrs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9275e0933cf8bb20f008924c0cb07a0692fe54d8064996520bf998de9eb79aa" + [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ "autocfg", "scopeguard", @@ -2247,9 +2221,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" +checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" dependencies = [ "adler", ] @@ -2387,32 +2361,6 @@ dependencies = [ "jni-sys", ] -[[package]] -name = "nix" -version = "0.22.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf" -dependencies = [ - "bitflags", - "cc", - "cfg-if", - "libc", - "memoffset", -] - -[[package]] -name = "nix" -version = "0.23.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" -dependencies = [ - "bitflags", - "cc", - "cfg-if", - "libc", - "memoffset", -] - [[package]] name = "nix" version = "0.24.2" @@ -2552,9 +2500,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.1" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "oorandom" @@ -2564,12 +2512,12 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "ordered-multimap" -version = "0.3.1" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c672c7ad9ec066e428c00eb917124a06f08db19e2584de982cc34b1f4c12485" +checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" dependencies = [ "dlv-list", - "hashbrown 0.9.1", + "hashbrown", ] [[package]] @@ -2599,9 +2547,9 @@ dependencies = [ [[package]] name = "owned_ttf_parser" -version = "0.15.1" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07ef1a404ae479dd6906f4fa2c88b3c94028f1284beb42a47c183a7c27ee9a3e" +checksum = "05e6affeb1632d6ff6a23d2cd40ffed138e82f1532571a26f527c8a284bb2fbb" dependencies = [ "ttf-parser", ] @@ -2655,9 +2603,9 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "percent-encoding" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pico-args" @@ -2693,19 +2641,19 @@ dependencies = [ "indexmap", "line-wrap", "serde", - "time 0.3.13", + "time 0.3.14", "xml-rs", ] [[package]] name = "png" -version = "0.17.5" +version = "0.17.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc38c0ad57efb786dd57b9864e5b18bae478c00c824dc55a38bbc9da95dde3ba" +checksum = "8f0e7f4c94ec26ff209cee506314212639d6c91b80afb82984819fafce9df01c" dependencies = [ "bitflags", "crc32fast", - "deflate", + "flate2", "miniz_oxide", ] @@ -2720,10 +2668,11 @@ dependencies = [ [[package]] name = "polling" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" +checksum = "899b00b9c8ab553c743b3e11e87c5c7d423b2a2de229ba95b24a756344748011" dependencies = [ + "autocfg", "cfg-if", "libc", "log", @@ -2756,9 +2705,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.43" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ "unicode-ident", ] @@ -2838,9 +2787,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] @@ -2980,9 +2929,9 @@ dependencies = [ [[package]] name = "rgb" -version = "0.8.33" +version = "0.8.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3b221de559e4a29df3b957eec92bc0de6bc8eaf6ca9cfed43e5e1d67ff65a34" +checksum = "3603b7d71ca82644f79b5a06d1220e9a58ede60bd32255f698cb1af8838b8db3" dependencies = [ "bytemuck", ] @@ -3024,9 +2973,9 @@ dependencies = [ [[package]] name = "rust-ini" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63471c4aa97a1cf8332a5f97709a79a4234698de6a1f5087faf66f2dae810e22" +checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" dependencies = [ "cfg-if", "ordered-multimap", @@ -3157,18 +3106,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.143" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.143" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3d8e8de557aee63c26b85b947f5e59b690d0454c753f3adeb5cd7835ab88391" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" dependencies = [ "proc-macro2", "quote", @@ -3177,9 +3126,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.83" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -3300,9 +3249,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "smithay-client-toolkit" @@ -3316,7 +3265,7 @@ dependencies = [ "lazy_static", "log", "memmap2", - "nix 0.24.2", + "nix", "pkg-config", "wayland-client", "wayland-cursor", @@ -3335,9 +3284,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", @@ -3425,9 +3374,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.99" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" dependencies = [ "proc-macro2", "quote", @@ -3513,24 +3462,24 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" [[package]] name = "thiserror" -version = "1.0.32" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.32" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" dependencies = [ "proc-macro2", "quote", @@ -3586,9 +3535,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db76ff9fa4b1458b3c7f077f3ff9887394058460d21e634355b273aaf11eea45" +checksum = "3c3f9a28b618c3a6b9251b6908e9c99e04b9e5c02e6581ccbb67d59c34ef7f9b" dependencies = [ "itoa", "libc", @@ -3819,24 +3768,24 @@ checksum = "07547e3ee45e28326cc23faac56d44f58f16ab23e413db526debce3b0bfd2742" [[package]] name = "unicode-ident" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "unicode-normalization" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] [[package]] name = "unicode-script" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dd944fd05f2f0b5c674917aea8a4df6af84f2d8de3fe8d988b95d28fb8fb09" +checksum = "7d817255e1bed6dfd4ca47258685d14d2bdcfbc64fdc9e3819bd5848057b8ecc" [[package]] name = "unicode-vo" @@ -3846,15 +3795,15 @@ checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "unicode-xid" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "unicode_names2" @@ -3887,13 +3836,12 @@ dependencies = [ [[package]] name = "url" -version = "2.2.2" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" dependencies = [ "form_urlencoded", "idna", - "matches", "percent-encoding", ] @@ -3979,9 +3927,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3989,9 +3937,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -4004,9 +3952,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ "cfg-if", "js-sys", @@ -4016,9 +3964,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4026,9 +3974,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -4039,20 +3987,20 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "wayland-client" -version = "0.29.4" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91223460e73257f697d9e23d401279123d36039a3f7a449e983f123292d4458f" +checksum = "3f3b068c05a039c9f755f881dc50f01732214f5685e379829759088967c46715" dependencies = [ "bitflags", "downcast-rs", "libc", - "nix 0.22.3", + "nix", "scoped-tls", "wayland-commons", "wayland-scanner", @@ -4061,11 +4009,11 @@ dependencies = [ [[package]] name = "wayland-commons" -version = "0.29.4" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f6e5e340d7c13490eca867898c4cec5af56c27a5ffe5c80c6fc4708e22d33e" +checksum = "8691f134d584a33a6606d9d717b95c4fa20065605f798a3f350d78dced02a902" dependencies = [ - "nix 0.22.3", + "nix", "once_cell", "smallvec", "wayland-sys", @@ -4073,20 +4021,20 @@ dependencies = [ [[package]] name = "wayland-cursor" -version = "0.29.4" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c52758f13d5e7861fc83d942d3d99bf270c83269575e52ac29e5b73cb956a6bd" +checksum = "6865c6b66f13d6257bef1cd40cbfe8ef2f150fb8ebbdb1e8e873455931377661" dependencies = [ - "nix 0.22.3", + "nix", "wayland-client", "xcursor", ] [[package]] name = "wayland-egl" -version = "0.29.4" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83281d69ee162b59031c666385e93bde4039ec553b90c4191cdb128ceea29a3a" +checksum = "402de949f81a012926d821a2d659f930694257e76dd92b6e0042ceb27be4107d" dependencies = [ "wayland-client", "wayland-sys", @@ -4094,9 +4042,9 @@ dependencies = [ [[package]] name = "wayland-protocols" -version = "0.29.4" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60147ae23303402e41fe034f74fb2c35ad0780ee88a1c40ac09a3be1e7465741" +checksum = "b950621f9354b322ee817a23474e479b34be96c2e909c14f7bc0100e9a970bc6" dependencies = [ "bitflags", "wayland-client", @@ -4106,9 +4054,9 @@ dependencies = [ [[package]] name = "wayland-scanner" -version = "0.29.4" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39a1ed3143f7a143187156a2ab52742e89dac33245ba505c17224df48939f9e0" +checksum = "8f4303d8fa22ab852f789e75a967f0a2cdc430a607751c0499bada3e451cbd53" dependencies = [ "proc-macro2", "quote", @@ -4117,9 +4065,9 @@ dependencies = [ [[package]] name = "wayland-sys" -version = "0.29.4" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9341df79a8975679188e37dab3889bfa57c44ac2cb6da166f519a81cbe452d4" +checksum = "be12ce1a3c39ec7dba25594b97b42cb3195d54953ddb9d3d95a7c3902bc6e9d4" dependencies = [ "dlib", "lazy_static", @@ -4128,9 +4076,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.58" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", @@ -4164,9 +4112,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.4" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1c760f0d366a6c24a02ed7816e23e691f5d92291f94d15e836006fd11b04daf" +checksum = "368bfe657969fb01238bb756d351dcade285e0f6fcbd36dcb23359a5169975be" dependencies = [ "webpki", ] @@ -4282,20 +4230,20 @@ dependencies = [ [[package]] name = "which" -version = "4.2.5" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" +checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" dependencies = [ "either", - "lazy_static", "libc", + "once_cell", ] [[package]] name = "widestring" -version = "0.5.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17882f045410753661207383517a6f62ec3dbeb6a4ed2acce01f0728238d1983" +checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" [[package]] name = "winapi" @@ -4468,9 +4416,9 @@ checksum = "f4dd6dc7df2d84cf7b33822ed5b86318fb1781948e9663bacd047fc9dd52259d" [[package]] name = "winit" -version = "0.27.2" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a8f3e9d742401efcfe833b8f84960397482ff049cb7bf59a112e14a4be97f7" +checksum = "a22e94ba35ca3ff11820044bfa0dc48b95a3a15569c0068555566a12ef41c9e5" dependencies = [ "bitflags", "cocoa", @@ -4501,9 +4449,9 @@ dependencies = [ [[package]] name = "winreg" -version = "0.8.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d107f8c6e916235c4c01cabb3e8acf7bea8ef6a63ca2e7fa0527c049badfc48c" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ "winapi", ] @@ -4535,7 +4483,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" dependencies = [ "gethostname", - "nix 0.24.2", + "nix", "winapi", "winapi-wsapoll", "x11rb-protocol", @@ -4547,7 +4495,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67" dependencies = [ - "nix 0.24.2", + "nix", ] [[package]] @@ -4588,9 +4536,9 @@ dependencies = [ [[package]] name = "zbus" -version = "2.3.2" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d8f1a037b2c4a67d9654dc7bdfa8ff2e80555bbefdd3c1833c1d1b27c963a6b" +checksum = "be2db10dd0354816a3615c72deff837f983d5c8ad9a0312727d0f89a5a9e9145" dependencies = [ "async-broadcast", "async-channel", @@ -4609,8 +4557,7 @@ dependencies = [ "futures-sink", "futures-util", "hex", - "lazy_static", - "nix 0.23.1", + "nix", "once_cell", "ordered-stream", "rand", @@ -4628,9 +4575,9 @@ dependencies = [ [[package]] name = "zbus_macros" -version = "2.3.2" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f8fb5186d1c87ae88cf234974c240671238b4a679158ad3b94ec465237349a6" +checksum = "7d03f1a5fb482cc0d97f3d3de9fe2e942f436a635a5fb6c12c9f03f21eb03075" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -4702,9 +4649,9 @@ dependencies = [ [[package]] name = "zvariant" -version = "3.6.0" +version = "3.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bd68e4e6432ef19df47d7e90e2e72b5e7e3d778e0ae3baddf12b951265cc758" +checksum = "b794fb7f59af4105697b0449ba31731ee5dbb3e773a17dbdf3d36206ea1b1644" dependencies = [ "byteorder", "enumflags2", @@ -4716,9 +4663,9 @@ dependencies = [ [[package]] name = "zvariant_derive" -version = "3.6.0" +version = "3.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08e977eaa3af652f63d479ce50d924254ad76722a6289ec1a1eac3231ca30430" +checksum = "dd58d4b6c8e26d3dd2149c8c40c6613ef6451b9885ff1296d1ac86c388351a54" dependencies = [ "proc-macro-crate", "proc-macro2", diff --git a/crates/eframe/Cargo.toml b/crates/eframe/Cargo.toml index 32c456adc9b..d92601fdf98 100644 --- a/crates/eframe/Cargo.toml +++ b/crates/eframe/Cargo.toml @@ -57,7 +57,7 @@ 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", "egui-wgpu"] +wgpu = ["dep:wgpu", "dep:egui-wgpu", "dep:pollster"] [dependencies] @@ -72,11 +72,10 @@ tracing = { version = "0.1", default-features = false, features = ["std"] } document-features = { version = "0.2", optional = true } egui_glow = { version = "0.19.0", path = "../egui_glow", optional = true, default-features = false } -egui-wgpu = { version = "0.19.0", path = "../egui-wgpu", optional = true, features = ["winit"] } glow = { version = "0.11", optional = true } ron = { version = "0.8", optional = true, features = ["integer128"] } serde = { version = "1", optional = true, features = ["derive"] } -wgpu = { version = "0.13", optional = true } +pollster = { version = "0.2", optional = true } # ------------------------------------------- # native: @@ -85,6 +84,8 @@ dark-light = { version = "0.2.1", optional = true } egui-winit = { version = "0.19.0", path = "../egui-winit", default-features = false, features = ["clipboard", "links"] } glutin = { version = "0.29.0" } winit = "0.27.2" +egui-wgpu = { version = "0.19.0", path = "../egui-wgpu", optional = true, features = ["winit"] } # if wgpu is used, use it with winit +wgpu = { version = "0.13", optional = true } # optional native: puffin = { version = "0.13", optional = true } @@ -93,6 +94,8 @@ directories-next = { version = "2", optional = true } # ------------------------------------------- # web: [target.'cfg(target_arch = "wasm32")'.dependencies] +egui-wgpu = { version = "0.19.0", path = "../egui-wgpu", optional = true } # if wgpu is used, use it without (!) winit +wgpu = { version = "0.13", optional = true, features = ["webgl"] } bytemuck = "1.7" getrandom = { version = "0.2", features = ["js"] } # used by ahash js-sys = "0.3" diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index b3cd25180bc..571eeecc44c 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -455,6 +455,7 @@ pub struct WebOptions { /// Which version of WebGl context to select /// /// Default: [`WebGlContextOption::BestFirst`]. + #[cfg(feature = "glow")] pub webgl_context_option: WebGlContextOption, } @@ -464,6 +465,7 @@ impl Default for WebOptions { Self { follow_system_theme: true, default_theme: Theme::Dark, + #[cfg(feature = "glow")] webgl_context_option: WebGlContextOption::BestFirst, } } diff --git a/crates/eframe/src/web/backend.rs b/crates/eframe/src/web/backend.rs index ea92b39b619..7fe79e9d75d 100644 --- a/crates/eframe/src/web/backend.rs +++ b/crates/eframe/src/web/backend.rs @@ -187,8 +187,7 @@ impl AppRunner { web_options: crate::WebOptions, app_creator: epi::AppCreator, ) -> Result { - let painter = - WebPainter::new(canvas_id, web_options.webgl_context_option).map_err(JsValue::from)?; // fail early + let painter = WebPainter::new(canvas_id, &web_options).map_err(JsValue::from)?; // fail early let system_theme = if web_options.follow_system_theme { super::system_theme() @@ -357,16 +356,12 @@ impl AppRunner { Ok((repaint_after, clipped_primitives)) } - pub fn clear_color_buffer(&self) { - self.painter - .clear(self.app.clear_color(&self.egui_ctx.style().visuals)); - } - /// Paint the results of the last call to [`Self::logic`]. pub fn paint(&mut self, clipped_primitives: &[egui::ClippedPrimitive]) -> Result<(), JsValue> { let textures_delta = std::mem::take(&mut self.textures_delta); self.painter.paint_and_update_textures( + self.app.clear_color(&self.egui_ctx.style().visuals), clipped_primitives, self.egui_ctx.pixels_per_point(), &textures_delta, diff --git a/crates/eframe/src/web/events.rs b/crates/eframe/src/web/events.rs index b50d581eb5d..71d89818e15 100644 --- a/crates/eframe/src/web/events.rs +++ b/crates/eframe/src/web/events.rs @@ -13,7 +13,6 @@ pub fn paint_and_schedule( if !is_destroyed && runner_lock.needs_repaint.when_to_repaint() <= now_sec() { runner_lock.needs_repaint.clear(); - runner_lock.clear_color_buffer(); let (repaint_after, clipped_primitives) = runner_lock.logic()?; runner_lock.paint(&clipped_primitives)?; runner_lock diff --git a/crates/eframe/src/web/mod.rs b/crates/eframe/src/web/mod.rs index fbd2028f3a4..c4b3dba537e 100644 --- a/crates/eframe/src/web/mod.rs +++ b/crates/eframe/src/web/mod.rs @@ -8,12 +8,20 @@ mod input; pub mod screen_reader; pub mod storage; mod text_agent; + +#[cfg(feature = "glow")] mod web_glow_painter; +#[cfg(feature = "glow")] +pub(crate) use web_glow_painter::WebPainter; + +#[cfg(feature = "wgpu")] +mod web_wgpu_painter; +#[cfg(feature = "wgpu")] +pub(crate) use web_wgpu_painter::WebPainter; pub use backend::*; pub use events::*; pub use storage::*; -pub(crate) use web_glow_painter::WebPainter; use std::collections::BTreeMap; use std::sync::{ diff --git a/crates/eframe/src/web/web_glow_painter.rs b/crates/eframe/src/web/web_glow_painter.rs index e5e239cc7a2..19ec66e38e6 100644 --- a/crates/eframe/src/web/web_glow_painter.rs +++ b/crates/eframe/src/web/web_glow_painter.rs @@ -1,13 +1,12 @@ use wasm_bindgen::JsCast; use wasm_bindgen::JsValue; use web_sys::HtmlCanvasElement; -#[cfg(not(target_arch = "wasm32"))] use web_sys::{WebGl2RenderingContext, WebGlRenderingContext}; use egui::{ClippedPrimitive, Rgba}; use egui_glow::glow; -use crate::WebGlContextOption; +use crate::WebOptions; pub(crate) struct WebPainter { pub(crate) canvas: HtmlCanvasElement, @@ -16,10 +15,11 @@ pub(crate) struct WebPainter { } impl WebPainter { - pub fn new(canvas_id: &str, options: WebGlContextOption) -> Result { + pub fn new(canvas_id: &str, options: &WebOptions) -> Result { let canvas = super::canvas_element_or_die(canvas_id); - let (gl, shader_prefix) = init_glow_context_from_canvas(&canvas, options)?; + let (gl, shader_prefix) = + init_glow_context_from_canvas(&canvas, options.webgl_context_option)?; let gl = std::sync::Arc::new(gl); let painter = egui_glow::Painter::new(gl, shader_prefix, None) @@ -31,9 +31,7 @@ impl WebPainter { painter, }) } -} -impl WebPainter { pub fn gl(&self) -> &std::sync::Arc { self.painter.gl() } @@ -46,6 +44,8 @@ impl WebPainter { &self.canvas_id } + // TODO: cleanup + pub fn set_texture(&mut self, tex_id: egui::TextureId, delta: &egui::epaint::ImageDelta) { self.painter.set_texture(tex_id, delta); } @@ -54,11 +54,6 @@ impl WebPainter { self.painter.free_texture(tex_id); } - pub fn clear(&self, clear_color: Rgba) { - let canvas_dimension = [self.canvas.width(), self.canvas.height()]; - egui_glow::painter::clear(self.painter.gl(), canvas_dimension, clear_color); - } - pub fn paint_primitives( &mut self, clipped_primitives: &[ClippedPrimitive], @@ -72,14 +67,18 @@ impl WebPainter { pub fn paint_and_update_textures( &mut self, + clear_color: Rgba, clipped_primitives: &[egui::ClippedPrimitive], pixels_per_point: f32, textures_delta: &egui::TexturesDelta, ) -> Result<(), JsValue> { + let canvas_dimension = [self.canvas.width(), self.canvas.height()]; + for (id, image_delta) in &textures_delta.set { self.set_texture(*id, image_delta); } + egui_glow::painter::clear(self.painter.gl(), canvas_dimension, clear_color); self.paint_primitives(clipped_primitives, pixels_per_point)?; for &id in &textures_delta.free { diff --git a/crates/eframe/src/web/web_wgpu_painter.rs b/crates/eframe/src/web/web_wgpu_painter.rs new file mode 100644 index 00000000000..b9b77c033e6 --- /dev/null +++ b/crates/eframe/src/web/web_wgpu_painter.rs @@ -0,0 +1,163 @@ +use egui_wgpu::renderer::ScreenDescriptor; +use egui_wgpu::Renderer; +use wasm_bindgen::JsCast; +use wasm_bindgen::JsValue; +use web_sys::HtmlCanvasElement; + +use egui::{ClippedPrimitive, Rgba}; +use wgpu::Backends; + +use crate::WebOptions; + +pub(crate) struct WebPainter { + canvas: HtmlCanvasElement, + canvas_id: String, + device: wgpu::Device, + queue: wgpu::Queue, + surface: wgpu::Surface, + surface_size: [u32; 2], + renderer: Renderer, + limits: wgpu::Limits, +} + +impl WebPainter { + pub fn new(canvas_id: &str, _options: &WebOptions) -> Result { + let canvas = super::canvas_element_or_die(canvas_id); + let limits = wgpu::Limits::downlevel_webgl2_defaults(); // TODO: Expose to eframe user + + // TODO: Should be able to switch between webgl & webgpu (only) + let backends = wgpu::Backends::GL; //wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all); + let instance = wgpu::Instance::new(backends); + let surface = instance.create_surface_from_canvas(&canvas); + + let adapter = pollster::block_on(wgpu::util::initialize_adapter_from_env_or_default( + &instance, + backends, + Some(&surface), + )) + .expect("No suitable GPU adapters found on the system!"); + + let (device, queue) = pollster::block_on(adapter.request_device( + &wgpu::DeviceDescriptor { + label: Some("eframe device"), + features: wgpu::Features::empty(), + limits: limits.clone(), + }, + None, // TODO: Expose to eframe user + )) + .unwrap(); + + // TODO: MSAA & depth + // TODO: renderer unhappy about srgb. why? Can't use anything else + let renderer = egui_wgpu::Renderer::new(&device, wgpu::TextureFormat::Rgba8UnormSrgb, 1, 0); + + Ok(Self { + canvas, + canvas_id: canvas_id.to_owned(), + device, + queue, + renderer, + surface, + surface_size: [0, 0], + limits, + }) + } + + // TODO: do we need all of these?? + + pub fn canvas_id(&self) -> &str { + &self.canvas_id + } + + pub fn max_texture_side(&self) -> usize { + self.limits.max_texture_dimension_2d as _ + } + + fn configure_surface(&self) { + self.surface.configure( + &self.device, + &wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: wgpu::TextureFormat::Rgba8UnormSrgb, + width: self.canvas.width(), + height: self.canvas.height(), + present_mode: wgpu::PresentMode::Fifo, + }, + ); + } + + pub fn paint_and_update_textures( + &mut self, + clear_color: Rgba, + clipped_primitives: &[egui::ClippedPrimitive], + pixels_per_point: f32, + textures_delta: &egui::TexturesDelta, + ) -> Result<(), JsValue> { + // Resize surface if needed + let canvas_size = [self.canvas.width(), self.canvas.height()]; + if canvas_size != self.surface_size { + self.configure_surface(); + self.surface_size = canvas_size; + } + + let frame = self + .surface + .get_current_texture() + .expect("Failed to acquire next swap chain texture"); + let view = frame + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); + + let mut encoder = self + .device + .create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("eframe encoder"), + }); + + // Upload all resources for the GPU. + let screen_descriptor = ScreenDescriptor { + size_in_pixels: canvas_size, + pixels_per_point, + }; + + for (id, image_delta) in &textures_delta.set { + self.renderer + .update_texture(&self.device, &self.queue, *id, image_delta); + } + + self.renderer.update_buffers( + &self.device, + &self.queue, + clipped_primitives, + &screen_descriptor, + ); + + // Record all render passes. + self.renderer.render( + &mut encoder, + &view, + clipped_primitives, + &screen_descriptor, + Some(wgpu::Color { + r: clear_color.r() as f64, + g: clear_color.g() as f64, + b: clear_color.b() as f64, + a: clear_color.a() as f64, + }), + ); + + for id in &textures_delta.free { + self.renderer.free_texture(id); + } + + // Submit the commands. + self.queue.submit(std::iter::once(encoder.finish())); + frame.present(); + + Ok(()) + } + + pub fn destroy(&mut self) { + // TODO: destroy things? doesn't fit well with wgpu + } +} diff --git a/crates/egui-wgpu/src/lib.rs b/crates/egui-wgpu/src/lib.rs index 78b07ac0fc1..b956a29fbd0 100644 --- a/crates/egui-wgpu/src/lib.rs +++ b/crates/egui-wgpu/src/lib.rs @@ -17,5 +17,15 @@ pub use renderer::Renderer; #[cfg(feature = "winit")] pub mod winit; -#[cfg(feature = "winit")] -pub use crate::winit::RenderState; +use egui::mutex::RwLock; +use std::sync::Arc; + +/// Access to the render state for egui, which can be useful in combination with +/// [`egui::PaintCallback`]s for custom rendering using WGPU. +#[derive(Clone)] +pub struct RenderState { + pub device: Arc, + pub queue: Arc, + pub target_format: wgpu::TextureFormat, + pub renderer: Arc>, +} diff --git a/crates/egui-wgpu/src/winit.rs b/crates/egui-wgpu/src/winit.rs index 008c5b231e9..5cbe8eb46cd 100644 --- a/crates/egui-wgpu/src/winit.rs +++ b/crates/egui-wgpu/src/winit.rs @@ -4,17 +4,7 @@ use egui::mutex::RwLock; use tracing::error; use wgpu::{Adapter, Instance, Surface}; -use crate::{renderer, Renderer}; - -/// Access to the render state for egui, which can be useful in combination with -/// [`egui::PaintCallback`]s for custom rendering using WGPU. -#[derive(Clone)] -pub struct RenderState { - pub device: Arc, - pub queue: Arc, - pub target_format: wgpu::TextureFormat, - pub renderer: Arc>, -} +use crate::{renderer, RenderState, Renderer}; struct SurfaceState { surface: Surface, From f1dd096a3975ab1d0914487c3066810c0c71258d Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Mon, 3 Oct 2022 23:25:54 +0200 Subject: [PATCH 02/23] fix glow compile error --- crates/eframe/src/web/web_glow_painter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eframe/src/web/web_glow_painter.rs b/crates/eframe/src/web/web_glow_painter.rs index 19ec66e38e6..e61322107d2 100644 --- a/crates/eframe/src/web/web_glow_painter.rs +++ b/crates/eframe/src/web/web_glow_painter.rs @@ -6,7 +6,7 @@ use web_sys::{WebGl2RenderingContext, WebGlRenderingContext}; use egui::{ClippedPrimitive, Rgba}; use egui_glow::glow; -use crate::WebOptions; +use crate::{WebGlContextOption, WebOptions}; pub(crate) struct WebPainter { pub(crate) canvas: HtmlCanvasElement, From 81dcabe4ad81fba9c78e1e2aef15220f4d6e1714 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 4 Oct 2022 12:02:23 +0200 Subject: [PATCH 03/23] introduced WebPainter trait, provide wgpu renderstate --- crates/eframe/src/web/backend.rs | 13 +- crates/eframe/src/web/mod.rs | 56 ++------ crates/eframe/src/web/web_painter.rs | 32 +++++ ...eb_glow_painter.rs => web_painter_glow.rs} | 107 ++++++++------ ...eb_wgpu_painter.rs => web_painter_wgpu.rs} | 133 ++++++++++-------- 5 files changed, 190 insertions(+), 151 deletions(-) create mode 100644 crates/eframe/src/web/web_painter.rs rename crates/eframe/src/web/{web_glow_painter.rs => web_painter_glow.rs} (61%) rename crates/eframe/src/web/{web_wgpu_painter.rs => web_painter_wgpu.rs} (57%) diff --git a/crates/eframe/src/web/backend.rs b/crates/eframe/src/web/backend.rs index 7fe79e9d75d..896e2f1ee1e 100644 --- a/crates/eframe/src/web/backend.rs +++ b/crates/eframe/src/web/backend.rs @@ -1,5 +1,4 @@ -use super::{WebPainter, *}; - +use super::{web_painter::WebPainter, *}; use crate::epi; use egui::{ @@ -162,7 +161,7 @@ fn test_parse_query() { pub struct AppRunner { pub(crate) frame: epi::Frame, egui_ctx: egui::Context, - painter: WebPainter, + painter: ActiveWebPainter, pub(crate) input: WebInput, app: Box, pub(crate) needs_repaint: std::sync::Arc, @@ -187,7 +186,7 @@ impl AppRunner { web_options: crate::WebOptions, app_creator: epi::AppCreator, ) -> Result { - let painter = WebPainter::new(canvas_id, &web_options).map_err(JsValue::from)?; // fail early + let painter = ActiveWebPainter::new(canvas_id, &web_options).map_err(JsValue::from)?; // fail early let system_theme = if web_options.follow_system_theme { super::system_theme() @@ -216,9 +215,9 @@ impl AppRunner { integration_info: info.clone(), storage: Some(&storage), #[cfg(feature = "glow")] - gl: Some(painter.painter.gl().clone()), + gl: Some(painter.gl().clone()), #[cfg(feature = "wgpu")] - wgpu_render_state: None, + wgpu_render_state: Some(painter.render_state()), }); let frame = epi::Frame { @@ -228,7 +227,7 @@ impl AppRunner { #[cfg(feature = "glow")] gl: Some(painter.gl().clone()), #[cfg(feature = "wgpu")] - wgpu_render_state: None, + wgpu_render_state: Some(painter.render_state()), }; let needs_repaint: std::sync::Arc = Default::default(); diff --git a/crates/eframe/src/web/mod.rs b/crates/eframe/src/web/mod.rs index c4b3dba537e..740897c446f 100644 --- a/crates/eframe/src/web/mod.rs +++ b/crates/eframe/src/web/mod.rs @@ -9,15 +9,19 @@ pub mod screen_reader; pub mod storage; mod text_agent; +#[cfg(all(feature = "glow", feature = "wgpu"))] +compile_error!("Can't enable both glow and wgpu as backends for the web painter. Need to choose either feature."); + +mod web_painter; #[cfg(feature = "glow")] -mod web_glow_painter; +mod web_painter_glow; #[cfg(feature = "glow")] -pub(crate) use web_glow_painter::WebPainter; +pub(crate) type ActiveWebPainter = web_painter_glow::WebPainterGlow; #[cfg(feature = "wgpu")] -mod web_wgpu_painter; +mod web_painter_wgpu; #[cfg(feature = "wgpu")] -pub(crate) use web_wgpu_painter::WebPainter; +pub(crate) type ActiveWebPainter = web_painter_wgpu::WebPainterWgpu; pub use backend::*; pub use events::*; @@ -252,47 +256,3 @@ pub fn percent_decode(s: &str) -> String { .decode_utf8_lossy() .to_string() } - -// ---------------------------------------------------------------------------- - -pub(crate) fn webgl1_requires_brightening(gl: &web_sys::WebGlRenderingContext) -> bool { - // See https://github.com/emilk/egui/issues/794 - - // detect WebKitGTK - - // WebKitGTK use WebKit default unmasked vendor and renderer - // but safari use same vendor and renderer - // so exclude "Mac OS X" user-agent. - let user_agent = web_sys::window().unwrap().navigator().user_agent().unwrap(); - !user_agent.contains("Mac OS X") && is_safari_and_webkit_gtk(gl) -} - -/// detecting Safari and `webkitGTK`. -/// -/// Safari and `webkitGTK` use unmasked renderer :Apple GPU -/// -/// If we detect safari or `webkitGTKs` returns true. -/// -/// This function used to avoid displaying linear color with `sRGB` supported systems. -fn is_safari_and_webkit_gtk(gl: &web_sys::WebGlRenderingContext) -> bool { - // This call produces a warning in Firefox ("WEBGL_debug_renderer_info is deprecated in Firefox and will be removed.") - // but unless we call it we get errors in Chrome when we call `get_parameter` below. - // TODO(emilk): do something smart based on user agent? - if gl - .get_extension("WEBGL_debug_renderer_info") - .unwrap() - .is_some() - { - if let Ok(renderer) = - gl.get_parameter(web_sys::WebglDebugRendererInfo::UNMASKED_RENDERER_WEBGL) - { - if let Some(renderer) = renderer.as_string() { - if renderer.contains("Apple") { - return true; - } - } - } - } - - false -} diff --git a/crates/eframe/src/web/web_painter.rs b/crates/eframe/src/web/web_painter.rs new file mode 100644 index 00000000000..91c58c26351 --- /dev/null +++ b/crates/eframe/src/web/web_painter.rs @@ -0,0 +1,32 @@ +use egui::Rgba; +use wasm_bindgen::JsValue; + +use crate::WebOptions; + +/// Renderer for a browser canvas. +/// As of writing we're not allowing to decide on the painter at runtime, +/// therefore this trait is merely there for specifying and documenting the interface. +pub(crate) trait WebPainter { + /// Create a new web painter targeting a given canvas. + fn new(canvas_id: &str, options: &WebOptions) -> Result + where + Self: Sized; + + /// Id of the canvas in use. + fn canvas_id(&self) -> &str; + + /// Maximum size of a texture in one direction. + fn max_texture_side(&self) -> usize; + + /// Update all internal textures and paint gui. + fn paint_and_update_textures( + &mut self, + clear_color: Rgba, + clipped_primitives: &[egui::ClippedPrimitive], + pixels_per_point: f32, + textures_delta: &egui::TexturesDelta, + ) -> Result<(), JsValue>; + + /// Destroy all resources. + fn destroy(&mut self); +} diff --git a/crates/eframe/src/web/web_glow_painter.rs b/crates/eframe/src/web/web_painter_glow.rs similarity index 61% rename from crates/eframe/src/web/web_glow_painter.rs rename to crates/eframe/src/web/web_painter_glow.rs index e61322107d2..ecf018a211f 100644 --- a/crates/eframe/src/web/web_glow_painter.rs +++ b/crates/eframe/src/web/web_painter_glow.rs @@ -1,21 +1,28 @@ use wasm_bindgen::JsCast; use wasm_bindgen::JsValue; use web_sys::HtmlCanvasElement; -use web_sys::{WebGl2RenderingContext, WebGlRenderingContext}; -use egui::{ClippedPrimitive, Rgba}; +use egui::Rgba; use egui_glow::glow; use crate::{WebGlContextOption, WebOptions}; -pub(crate) struct WebPainter { - pub(crate) canvas: HtmlCanvasElement, - pub(crate) canvas_id: String, - pub(crate) painter: egui_glow::Painter, +use super::web_painter::WebPainter; + +pub(crate) struct WebPainterGlow { + canvas: HtmlCanvasElement, + canvas_id: String, + painter: egui_glow::Painter, } -impl WebPainter { - pub fn new(canvas_id: &str, options: &WebOptions) -> Result { +impl WebPainterGlow { + pub fn gl(&self) -> &std::sync::Arc { + self.painter.gl() + } +} + +impl WebPainter for WebPainterGlow { + fn new(canvas_id: &str, options: &WebOptions) -> Result { let canvas = super::canvas_element_or_die(canvas_id); let (gl, shader_prefix) = @@ -32,40 +39,15 @@ impl WebPainter { }) } - pub fn gl(&self) -> &std::sync::Arc { - self.painter.gl() - } - - pub fn max_texture_side(&self) -> usize { + fn max_texture_side(&self) -> usize { self.painter.max_texture_side() } - pub fn canvas_id(&self) -> &str { + fn canvas_id(&self) -> &str { &self.canvas_id } - // TODO: cleanup - - pub fn set_texture(&mut self, tex_id: egui::TextureId, delta: &egui::epaint::ImageDelta) { - self.painter.set_texture(tex_id, delta); - } - - pub fn free_texture(&mut self, tex_id: egui::TextureId) { - self.painter.free_texture(tex_id); - } - - pub fn paint_primitives( - &mut self, - clipped_primitives: &[ClippedPrimitive], - pixels_per_point: f32, - ) -> Result<(), JsValue> { - let canvas_dimension = [self.canvas.width(), self.canvas.height()]; - self.painter - .paint_primitives(canvas_dimension, pixels_per_point, clipped_primitives); - Ok(()) - } - - pub fn paint_and_update_textures( + fn paint_and_update_textures( &mut self, clear_color: Rgba, clipped_primitives: &[egui::ClippedPrimitive], @@ -75,20 +57,21 @@ impl WebPainter { let canvas_dimension = [self.canvas.width(), self.canvas.height()]; for (id, image_delta) in &textures_delta.set { - self.set_texture(*id, image_delta); + self.painter.set_texture(*id, image_delta); } egui_glow::painter::clear(self.painter.gl(), canvas_dimension, clear_color); - self.paint_primitives(clipped_primitives, pixels_per_point)?; + self.painter + .paint_primitives(canvas_dimension, pixels_per_point, clipped_primitives); for &id in &textures_delta.free { - self.free_texture(id); + self.painter.free_texture(id); } Ok(()) } - pub fn destroy(&mut self) { + fn destroy(&mut self) { self.painter.destroy() } } @@ -130,7 +113,7 @@ fn init_webgl1(canvas: &HtmlCanvasElement) -> Option<(glow::Context, &'static st .dyn_into::() .unwrap(); - let shader_prefix = if super::webgl1_requires_brightening(&gl1_ctx) { + let shader_prefix = if webgl1_requires_brightening(&gl1_ctx) { tracing::debug!("Enabling webkitGTK brightening workaround."); "#define APPLY_BRIGHTENING_GAMMA" } else { @@ -158,3 +141,45 @@ fn init_webgl2(canvas: &HtmlCanvasElement) -> Option<(glow::Context, &'static st Some((gl, shader_prefix)) } + +fn webgl1_requires_brightening(gl: &web_sys::WebGlRenderingContext) -> bool { + // See https://github.com/emilk/egui/issues/794 + + // detect WebKitGTK + + // WebKitGTK use WebKit default unmasked vendor and renderer + // but safari use same vendor and renderer + // so exclude "Mac OS X" user-agent. + let user_agent = web_sys::window().unwrap().navigator().user_agent().unwrap(); + !user_agent.contains("Mac OS X") && is_safari_and_webkit_gtk(gl) +} + +/// detecting Safari and `webkitGTK`. +/// +/// Safari and `webkitGTK` use unmasked renderer :Apple GPU +/// +/// If we detect safari or `webkitGTKs` returns true. +/// +/// This function used to avoid displaying linear color with `sRGB` supported systems. +fn is_safari_and_webkit_gtk(gl: &web_sys::WebGlRenderingContext) -> bool { + // This call produces a warning in Firefox ("WEBGL_debug_renderer_info is deprecated in Firefox and will be removed.") + // but unless we call it we get errors in Chrome when we call `get_parameter` below. + // TODO(emilk): do something smart based on user agent? + if gl + .get_extension("WEBGL_debug_renderer_info") + .unwrap() + .is_some() + { + if let Ok(renderer) = + gl.get_parameter(web_sys::WebglDebugRendererInfo::UNMASKED_RENDERER_WEBGL) + { + if let Some(renderer) = renderer.as_string() { + if renderer.contains("Apple") { + return true; + } + } + } + } + + false +} diff --git a/crates/eframe/src/web/web_wgpu_painter.rs b/crates/eframe/src/web/web_painter_wgpu.rs similarity index 57% rename from crates/eframe/src/web/web_wgpu_painter.rs rename to crates/eframe/src/web/web_painter_wgpu.rs index b9b77c033e6..2d61c0b5ca6 100644 --- a/crates/eframe/src/web/web_wgpu_painter.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -1,27 +1,48 @@ +use std::sync::Arc; + +use egui::mutex::RwLock; use egui_wgpu::renderer::ScreenDescriptor; -use egui_wgpu::Renderer; -use wasm_bindgen::JsCast; +use egui_wgpu::RenderState; + use wasm_bindgen::JsValue; -use web_sys::HtmlCanvasElement; -use egui::{ClippedPrimitive, Rgba}; -use wgpu::Backends; +use egui::Rgba; +use web_sys::HtmlCanvasElement; +use super::web_painter::WebPainter; use crate::WebOptions; -pub(crate) struct WebPainter { +pub(crate) struct WebPainterWgpu { canvas: HtmlCanvasElement, canvas_id: String, - device: wgpu::Device, - queue: wgpu::Queue, surface: wgpu::Surface, surface_size: [u32; 2], - renderer: Renderer, limits: wgpu::Limits, + render_state: RenderState, +} + +impl WebPainterWgpu { + fn configure_surface(&mut self, new_size: &[u32; 2]) { + self.surface.configure( + &self.render_state.device, + &wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: self.render_state.target_format, + width: new_size[0], + height: new_size[1], + present_mode: wgpu::PresentMode::Fifo, + }, + ); + self.surface_size = new_size.clone(); + } + + pub fn render_state(&self) -> RenderState { + self.render_state.clone() + } } -impl WebPainter { - pub fn new(canvas_id: &str, _options: &WebOptions) -> Result { +impl WebPainter for WebPainterWgpu { + fn new(canvas_id: &str, _options: &WebOptions) -> Result { let canvas = super::canvas_element_or_die(canvas_id); let limits = wgpu::Limits::downlevel_webgl2_defaults(); // TODO: Expose to eframe user @@ -49,44 +70,34 @@ impl WebPainter { // TODO: MSAA & depth // TODO: renderer unhappy about srgb. why? Can't use anything else - let renderer = egui_wgpu::Renderer::new(&device, wgpu::TextureFormat::Rgba8UnormSrgb, 1, 0); + let target_format = wgpu::TextureFormat::Rgba8UnormSrgb; + let renderer = egui_wgpu::Renderer::new(&device, target_format, 1, 0); + let render_state = RenderState { + device: Arc::new(device), + queue: Arc::new(queue), + target_format, + renderer: Arc::new(RwLock::new(renderer)), + }; Ok(Self { canvas, canvas_id: canvas_id.to_owned(), - device, - queue, - renderer, + render_state, surface, surface_size: [0, 0], limits, }) } - // TODO: do we need all of these?? - - pub fn canvas_id(&self) -> &str { + fn canvas_id(&self) -> &str { &self.canvas_id } - pub fn max_texture_side(&self) -> usize { + fn max_texture_side(&self) -> usize { self.limits.max_texture_dimension_2d as _ } - fn configure_surface(&self) { - self.surface.configure( - &self.device, - &wgpu::SurfaceConfiguration { - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - format: wgpu::TextureFormat::Rgba8UnormSrgb, - width: self.canvas.width(), - height: self.canvas.height(), - present_mode: wgpu::PresentMode::Fifo, - }, - ); - } - - pub fn paint_and_update_textures( + fn paint_and_update_textures( &mut self, clear_color: Rgba, clipped_primitives: &[egui::ClippedPrimitive], @@ -96,8 +107,7 @@ impl WebPainter { // Resize surface if needed let canvas_size = [self.canvas.width(), self.canvas.height()]; if canvas_size != self.surface_size { - self.configure_surface(); - self.surface_size = canvas_size; + self.configure_surface(&canvas_size); } let frame = self @@ -108,11 +118,12 @@ impl WebPainter { .texture .create_view(&wgpu::TextureViewDescriptor::default()); - let mut encoder = self - .device - .create_command_encoder(&wgpu::CommandEncoderDescriptor { - label: Some("eframe encoder"), - }); + let mut encoder = + self.render_state + .device + .create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("eframe encoder"), + }); // Upload all resources for the GPU. let screen_descriptor = ScreenDescriptor { @@ -120,20 +131,27 @@ impl WebPainter { pixels_per_point, }; - for (id, image_delta) in &textures_delta.set { - self.renderer - .update_texture(&self.device, &self.queue, *id, image_delta); + { + let mut renderer = self.render_state.renderer.write(); + for (id, image_delta) in &textures_delta.set { + renderer.update_texture( + &self.render_state.device, + &self.render_state.queue, + *id, + image_delta, + ); + } + + renderer.update_buffers( + &self.render_state.device, + &self.render_state.queue, + clipped_primitives, + &screen_descriptor, + ); } - self.renderer.update_buffers( - &self.device, - &self.queue, - clipped_primitives, - &screen_descriptor, - ); - // Record all render passes. - self.renderer.render( + self.render_state.renderer.read().render( &mut encoder, &view, clipped_primitives, @@ -146,18 +164,23 @@ impl WebPainter { }), ); - for id in &textures_delta.free { - self.renderer.free_texture(id); + { + let mut renderer = self.render_state.renderer.write(); + for id in &textures_delta.free { + renderer.free_texture(id); + } } // Submit the commands. - self.queue.submit(std::iter::once(encoder.finish())); + self.render_state + .queue + .submit(std::iter::once(encoder.finish())); frame.present(); Ok(()) } - pub fn destroy(&mut self) { + fn destroy(&mut self) { // TODO: destroy things? doesn't fit well with wgpu } } From fba791cbac5c70c26321e5eacbb8598004753cfb Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 4 Oct 2022 15:20:46 +0200 Subject: [PATCH 04/23] WebPainterWgpu destroy implemented --- crates/eframe/src/web/backend.rs | 4 +- crates/eframe/src/web/web_painter_wgpu.rs | 63 ++++++++++++----------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/crates/eframe/src/web/backend.rs b/crates/eframe/src/web/backend.rs index 896e2f1ee1e..552b8fb43f8 100644 --- a/crates/eframe/src/web/backend.rs +++ b/crates/eframe/src/web/backend.rs @@ -217,7 +217,7 @@ impl AppRunner { #[cfg(feature = "glow")] gl: Some(painter.gl().clone()), #[cfg(feature = "wgpu")] - wgpu_render_state: Some(painter.render_state()), + wgpu_render_state: painter.render_state(), }); let frame = epi::Frame { @@ -227,7 +227,7 @@ impl AppRunner { #[cfg(feature = "glow")] gl: Some(painter.gl().clone()), #[cfg(feature = "wgpu")] - wgpu_render_state: Some(painter.render_state()), + wgpu_render_state: painter.render_state(), }; let needs_repaint: std::sync::Arc = Default::default(); diff --git a/crates/eframe/src/web/web_painter_wgpu.rs b/crates/eframe/src/web/web_painter_wgpu.rs index 2d61c0b5ca6..e67a7d15a5b 100644 --- a/crates/eframe/src/web/web_painter_wgpu.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -18,25 +18,11 @@ pub(crate) struct WebPainterWgpu { surface: wgpu::Surface, surface_size: [u32; 2], limits: wgpu::Limits, - render_state: RenderState, + render_state: Option, } impl WebPainterWgpu { - fn configure_surface(&mut self, new_size: &[u32; 2]) { - self.surface.configure( - &self.render_state.device, - &wgpu::SurfaceConfiguration { - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - format: self.render_state.target_format, - width: new_size[0], - height: new_size[1], - present_mode: wgpu::PresentMode::Fifo, - }, - ); - self.surface_size = new_size.clone(); - } - - pub fn render_state(&self) -> RenderState { + pub fn render_state(&self) -> Option { self.render_state.clone() } } @@ -64,7 +50,7 @@ impl WebPainter for WebPainterWgpu { features: wgpu::Features::empty(), limits: limits.clone(), }, - None, // TODO: Expose to eframe user + None, // No capture exposed so far - unclear how we can expose this in a browser environment (?) )) .unwrap(); @@ -82,7 +68,7 @@ impl WebPainter for WebPainterWgpu { Ok(Self { canvas, canvas_id: canvas_id.to_owned(), - render_state, + render_state: Some(render_state), surface, surface_size: [0, 0], limits, @@ -104,10 +90,27 @@ impl WebPainter for WebPainterWgpu { pixels_per_point: f32, textures_delta: &egui::TexturesDelta, ) -> Result<(), JsValue> { + if self.render_state.is_none() { + return Err(JsValue::from_str( + "Can't paint, wgpu renderer was already disposed", + )); + } + let render_state = self.render_state.as_ref().unwrap(); + // Resize surface if needed let canvas_size = [self.canvas.width(), self.canvas.height()]; if canvas_size != self.surface_size { - self.configure_surface(&canvas_size); + self.surface.configure( + &render_state.device, + &wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: render_state.target_format, + width: canvas_size[0], + height: canvas_size[1], + present_mode: wgpu::PresentMode::Fifo, + }, + ); + self.surface_size = canvas_size.clone(); } let frame = self @@ -119,7 +122,7 @@ impl WebPainter for WebPainterWgpu { .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = - self.render_state + render_state .device .create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("eframe encoder"), @@ -132,26 +135,26 @@ impl WebPainter for WebPainterWgpu { }; { - let mut renderer = self.render_state.renderer.write(); + let mut renderer = render_state.renderer.write(); for (id, image_delta) in &textures_delta.set { renderer.update_texture( - &self.render_state.device, - &self.render_state.queue, + &render_state.device, + &render_state.queue, *id, image_delta, ); } renderer.update_buffers( - &self.render_state.device, - &self.render_state.queue, + &render_state.device, + &render_state.queue, clipped_primitives, &screen_descriptor, ); } // Record all render passes. - self.render_state.renderer.read().render( + render_state.renderer.read().render( &mut encoder, &view, clipped_primitives, @@ -165,22 +168,20 @@ impl WebPainter for WebPainterWgpu { ); { - let mut renderer = self.render_state.renderer.write(); + let mut renderer = render_state.renderer.write(); for id in &textures_delta.free { renderer.free_texture(id); } } // Submit the commands. - self.render_state - .queue - .submit(std::iter::once(encoder.finish())); + render_state.queue.submit(std::iter::once(encoder.finish())); frame.present(); Ok(()) } fn destroy(&mut self) { - // TODO: destroy things? doesn't fit well with wgpu + self.render_state = None; } } From d6f2717cdb88698d4c86801a28869aad3f235ada Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 4 Oct 2022 16:44:54 +0200 Subject: [PATCH 05/23] make custom3d demo work on wgpu backend --- crates/eframe/src/web/web_painter_wgpu.rs | 5 ++++- crates/egui_demo_app/src/apps/custom3d_wgpu.rs | 8 ++++---- crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/eframe/src/web/web_painter_wgpu.rs b/crates/eframe/src/web/web_painter_wgpu.rs index e67a7d15a5b..18bbaa51b22 100644 --- a/crates/eframe/src/web/web_painter_wgpu.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -32,6 +32,9 @@ impl WebPainter for WebPainterWgpu { let canvas = super::canvas_element_or_die(canvas_id); let limits = wgpu::Limits::downlevel_webgl2_defaults(); // TODO: Expose to eframe user + // HACK + console_log::init_with_level(log::Level::Debug).unwrap(); + // TODO: Should be able to switch between webgl & webgpu (only) let backends = wgpu::Backends::GL; //wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all); let instance = wgpu::Instance::new(backends); @@ -55,7 +58,7 @@ impl WebPainter for WebPainterWgpu { .unwrap(); // TODO: MSAA & depth - // TODO: renderer unhappy about srgb. why? Can't use anything else + // TODO: Renderer unhappy about srgb. Can't use anything else right now it seems. let target_format = wgpu::TextureFormat::Rgba8UnormSrgb; let renderer = egui_wgpu::Renderer::new(&device, target_format, 1, 0); let render_state = RenderState { diff --git a/crates/egui_demo_app/src/apps/custom3d_wgpu.rs b/crates/egui_demo_app/src/apps/custom3d_wgpu.rs index 0ef65f2bfb0..b95b6d0b992 100644 --- a/crates/egui_demo_app/src/apps/custom3d_wgpu.rs +++ b/crates/egui_demo_app/src/apps/custom3d_wgpu.rs @@ -63,10 +63,10 @@ impl Custom3d { let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: None, - contents: bytemuck::cast_slice(&[0.0]), - usage: wgpu::BufferUsages::COPY_DST - | wgpu::BufferUsages::MAP_WRITE - | wgpu::BufferUsages::UNIFORM, + contents: bytemuck::cast_slice(&[0.0_f32; 4]), // 16 bytes aligned! + // Mapping at creation (as done by the create_buffer_init utility) doesn't require us to to add the MAP_WRITE usage + // (this *happens* to workaround this bug ) + usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::UNIFORM, }); let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { diff --git a/crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl b/crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl index 140f5f6e1f0..a3799d04fe5 100644 --- a/crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl +++ b/crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl @@ -5,6 +5,7 @@ struct VertexOut { struct Uniforms { angle: f32, + _padding: vec3, // needed in order to make it 16 byte aligned }; @group(0) @binding(0) From a3bfcccacf031a96fe944f05159c33088078c723 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 4 Oct 2022 16:48:57 +0200 Subject: [PATCH 06/23] changelog entry for wgpu support eframe wasm --- crates/eframe/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/eframe/CHANGELOG.md b/crates/eframe/CHANGELOG.md index 6af5e4976f4..ad8c31dc2a1 100644 --- a/crates/eframe/CHANGELOG.md +++ b/crates/eframe/CHANGELOG.md @@ -13,6 +13,7 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C * Fix: app state is now saved when user presses Cmd-Q on Mac ([#2013](https://github.com/emilk/egui/pull/2013)). * Added `center` to `NativeOptions` and `monitor_size` to `WindowInfo` on desktop ([#2035](https://github.com/emilk/egui/pull/2035)). * Web: you can access your application from JS using `AppRunner::app_mut`. See `crates/egui_demo_app/src/lib.rs`. +* Web: You can now use webgl on top of wgpu by enabling the `wgpu` feature (and disabling `glow` via disabling default features) ## 0.19.0 - 2022-08-20 From bb35ca179daab79e09243ceb2b259607769a6853 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 4 Oct 2022 16:53:27 +0200 Subject: [PATCH 07/23] remove temporary logging hack --- crates/eframe/src/web/web_painter_wgpu.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/eframe/src/web/web_painter_wgpu.rs b/crates/eframe/src/web/web_painter_wgpu.rs index 18bbaa51b22..27e6f80d7d8 100644 --- a/crates/eframe/src/web/web_painter_wgpu.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -32,9 +32,6 @@ impl WebPainter for WebPainterWgpu { let canvas = super::canvas_element_or_die(canvas_id); let limits = wgpu::Limits::downlevel_webgl2_defaults(); // TODO: Expose to eframe user - // HACK - console_log::init_with_level(log::Level::Debug).unwrap(); - // TODO: Should be able to switch between webgl & webgpu (only) let backends = wgpu::Backends::GL; //wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all); let instance = wgpu::Instance::new(backends); From da3d909b23d9218a067a6a4b7bdf0c5aa5fe636f Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 4 Oct 2022 18:07:28 +0200 Subject: [PATCH 08/23] stop using pollster for web we're actually not allowed to block - this only worked because wgpu on webgl doesn't actually cause anything blocking. However, when trying webgpu this became an issue --- Cargo.lock | 2 +- crates/eframe/Cargo.toml | 3 +- crates/eframe/src/lib.rs | 4 +-- crates/eframe/src/web/backend.rs | 10 +++--- crates/eframe/src/web/web_painter.rs | 10 +++--- crates/eframe/src/web/web_painter_glow.rs | 6 ++-- crates/eframe/src/web/web_painter_wgpu.rs | 38 +++++++++++------------ crates/egui_demo_app/Cargo.toml | 1 + crates/egui_demo_app/src/lib.rs | 7 +++-- 9 files changed, 41 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ae426c8f30..a2c8d2724d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1127,7 +1127,6 @@ dependencies = [ "glutin", "js-sys", "percent-encoding", - "pollster", "puffin", "ron", "serde", @@ -1202,6 +1201,7 @@ dependencies = [ "tracing", "tracing-subscriber", "tracing-wasm", + "wasm-bindgen-futures", ] [[package]] diff --git a/crates/eframe/Cargo.toml b/crates/eframe/Cargo.toml index d92601fdf98..e923fb09e20 100644 --- a/crates/eframe/Cargo.toml +++ b/crates/eframe/Cargo.toml @@ -57,7 +57,7 @@ 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:egui-wgpu", "dep:pollster"] +wgpu = ["dep:wgpu", "dep:egui-wgpu"] [dependencies] @@ -75,7 +75,6 @@ egui_glow = { version = "0.19.0", path = "../egui_glow", optional = true, defaul glow = { version = "0.11", optional = true } ron = { version = "0.8", optional = true, features = ["integer128"] } serde = { version = "1", optional = true, features = ["derive"] } -pollster = { version = "0.2", optional = true } # ------------------------------------------- # native: diff --git a/crates/eframe/src/lib.rs b/crates/eframe/src/lib.rs index 088382cb5d5..53019608810 100644 --- a/crates/eframe/src/lib.rs +++ b/crates/eframe/src/lib.rs @@ -109,12 +109,12 @@ pub use web_sys; /// } /// ``` #[cfg(target_arch = "wasm32")] -pub fn start_web( +pub async fn start_web( canvas_id: &str, web_options: WebOptions, app_creator: AppCreator, ) -> Result { - let handle = web::start(canvas_id, web_options, app_creator)?; + let handle = web::start(canvas_id, web_options, app_creator).await?; Ok(handle) } diff --git a/crates/eframe/src/web/backend.rs b/crates/eframe/src/web/backend.rs index 552b8fb43f8..ec2329866d4 100644 --- a/crates/eframe/src/web/backend.rs +++ b/crates/eframe/src/web/backend.rs @@ -181,12 +181,14 @@ impl Drop for AppRunner { } impl AppRunner { - pub fn new( + pub async fn new( canvas_id: &str, web_options: crate::WebOptions, app_creator: epi::AppCreator, ) -> Result { - let painter = ActiveWebPainter::new(canvas_id, &web_options).map_err(JsValue::from)?; // fail early + let painter = ActiveWebPainter::new(canvas_id, &web_options) + .await + .map_err(JsValue::from)?; let system_theme = if web_options.follow_system_theme { super::system_theme() @@ -506,12 +508,12 @@ impl AppRunnerContainer { /// Install event listeners to register different input events /// and start running the given app. -pub fn start( +pub async fn start( canvas_id: &str, web_options: crate::WebOptions, app_creator: epi::AppCreator, ) -> Result { - let mut runner = AppRunner::new(canvas_id, web_options, app_creator)?; + let mut runner = AppRunner::new(canvas_id, web_options, app_creator).await?; runner.warm_up()?; start_runner(runner) } diff --git a/crates/eframe/src/web/web_painter.rs b/crates/eframe/src/web/web_painter.rs index 91c58c26351..4ced22f46de 100644 --- a/crates/eframe/src/web/web_painter.rs +++ b/crates/eframe/src/web/web_painter.rs @@ -1,16 +1,14 @@ use egui::Rgba; use wasm_bindgen::JsValue; -use crate::WebOptions; - /// Renderer for a browser canvas. /// As of writing we're not allowing to decide on the painter at runtime, /// therefore this trait is merely there for specifying and documenting the interface. pub(crate) trait WebPainter { - /// Create a new web painter targeting a given canvas. - fn new(canvas_id: &str, options: &WebOptions) -> Result - where - Self: Sized; + // Create a new web painter targeting a given canvas. + // fn new(canvas_id: &str, options: &WebOptions) -> Result + // where + // Self: Sized; /// Id of the canvas in use. fn canvas_id(&self) -> &str; diff --git a/crates/eframe/src/web/web_painter_glow.rs b/crates/eframe/src/web/web_painter_glow.rs index ecf018a211f..a8ba05f14be 100644 --- a/crates/eframe/src/web/web_painter_glow.rs +++ b/crates/eframe/src/web/web_painter_glow.rs @@ -19,10 +19,8 @@ impl WebPainterGlow { pub fn gl(&self) -> &std::sync::Arc { self.painter.gl() } -} -impl WebPainter for WebPainterGlow { - fn new(canvas_id: &str, options: &WebOptions) -> Result { + pub async fn new(canvas_id: &str, options: &WebOptions) -> Result { let canvas = super::canvas_element_or_die(canvas_id); let (gl, shader_prefix) = @@ -38,7 +36,9 @@ impl WebPainter for WebPainterGlow { painter, }) } +} +impl WebPainter for WebPainterGlow { fn max_texture_side(&self) -> usize { self.painter.max_texture_side() } diff --git a/crates/eframe/src/web/web_painter_wgpu.rs b/crates/eframe/src/web/web_painter_wgpu.rs index 27e6f80d7d8..34ef5e94bdc 100644 --- a/crates/eframe/src/web/web_painter_wgpu.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -25,10 +25,8 @@ impl WebPainterWgpu { pub fn render_state(&self) -> Option { self.render_state.clone() } -} -impl WebPainter for WebPainterWgpu { - fn new(canvas_id: &str, _options: &WebOptions) -> Result { + pub async fn new(canvas_id: &str, _options: &WebOptions) -> Result { let canvas = super::canvas_element_or_die(canvas_id); let limits = wgpu::Limits::downlevel_webgl2_defaults(); // TODO: Expose to eframe user @@ -37,22 +35,22 @@ impl WebPainter for WebPainterWgpu { let instance = wgpu::Instance::new(backends); let surface = instance.create_surface_from_canvas(&canvas); - let adapter = pollster::block_on(wgpu::util::initialize_adapter_from_env_or_default( - &instance, - backends, - Some(&surface), - )) - .expect("No suitable GPU adapters found on the system!"); - - let (device, queue) = pollster::block_on(adapter.request_device( - &wgpu::DeviceDescriptor { - label: Some("eframe device"), - features: wgpu::Features::empty(), - limits: limits.clone(), - }, - None, // No capture exposed so far - unclear how we can expose this in a browser environment (?) - )) - .unwrap(); + let adapter = + wgpu::util::initialize_adapter_from_env_or_default(&instance, backends, Some(&surface)) + .await + .expect("No suitable GPU adapters found on the system!"); + + let (device, queue) = adapter + .request_device( + &wgpu::DeviceDescriptor { + label: Some("eframe device"), + features: wgpu::Features::empty(), + limits: limits.clone(), + }, + None, // No capture exposed so far - unclear how we can expose this in a browser environment (?) + ) + .await + .unwrap(); // TODO: MSAA & depth // TODO: Renderer unhappy about srgb. Can't use anything else right now it seems. @@ -74,7 +72,9 @@ impl WebPainter for WebPainterWgpu { limits, }) } +} +impl WebPainter for WebPainterWgpu { fn canvas_id(&self) -> &str { &self.canvas_id } diff --git a/crates/egui_demo_app/Cargo.toml b/crates/egui_demo_app/Cargo.toml index af43c76315e..5df4a50fcdc 100644 --- a/crates/egui_demo_app/Cargo.toml +++ b/crates/egui_demo_app/Cargo.toml @@ -69,3 +69,4 @@ tracing-subscriber = "0.3" [target.'cfg(target_arch = "wasm32")'.dependencies] console_error_panic_hook = "0.1.6" tracing-wasm = "0.2" +wasm-bindgen-futures = "0.4" diff --git a/crates/egui_demo_app/src/lib.rs b/crates/egui_demo_app/src/lib.rs index aafd53ae261..85d5bd49826 100644 --- a/crates/egui_demo_app/src/lib.rs +++ b/crates/egui_demo_app/src/lib.rs @@ -62,13 +62,14 @@ pub fn init_wasm_hooks() { #[cfg(target_arch = "wasm32")] #[wasm_bindgen] -pub fn start_separate(canvas_id: &str) -> Result { +pub async fn start_separate(canvas_id: &str) -> Result { let web_options = eframe::WebOptions::default(); let handle = eframe::start_web( canvas_id, web_options, Box::new(|cc| Box::new(WrapApp::new(cc))), ) + .await .map(|handle| WebHandle { handle }); handle @@ -80,7 +81,7 @@ pub fn start_separate(canvas_id: &str) -> Result Result { +pub async fn start(canvas_id: &str) -> Result { init_wasm_hooks(); - start_separate(canvas_id) + start_separate(canvas_id).await } From 5df06a733b84513f95e360ffa46010c624520927 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 4 Oct 2022 21:59:59 +0200 Subject: [PATCH 09/23] revert cargo update --- Cargo.lock | 414 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 234 insertions(+), 180 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a2c8d2724d5..284210e62bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "ab_glyph" -version = "0.2.17" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04a9283dace1c41c265496614998d5b9c4a97b3eb770e804f007c5144bf03f2b" +checksum = "846ffacb9d0c8b879ef9e565b59e18fb76d6a61013e5bd24ecc659864e6b1a1f" dependencies = [ "ab_glyph_rasterizer", "owned_ttf_parser", @@ -14,9 +14,9 @@ dependencies = [ [[package]] name = "ab_glyph_rasterizer" -version = "0.1.7" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330223a1aecc308757b9926e9391c9b47f8ef2dbd8aea9df88312aea18c5e8d6" +checksum = "a13739d7177fbd22bb0ed28badfff9f372f8bef46c863db4e1c6248f6b223b6e" [[package]] name = "addr2line" @@ -33,6 +33,18 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "adler32" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" + +[[package]] +name = "ahash" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" + [[package]] name = "ahash" version = "0.7.6" @@ -59,18 +71,18 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.19" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ "memchr", ] [[package]] name = "android_system_properties" -version = "0.1.5" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +checksum = "d7ed72e1635e121ca3e79420540282af22da58be50de153d36f81ddc6b83aa9e" dependencies = [ "libc", ] @@ -92,9 +104,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.65" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" +checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305" [[package]] name = "approx" @@ -188,9 +200,9 @@ dependencies = [ [[package]] name = "async-io" -version = "1.9.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83e21f3a490c72b3b0cf44962180e60045de2925d8dff97918f7ee43c8f637c7" +checksum = "0ab006897723d9352f63e2b13047177c3982d8d79709d713ce7747a8f19fd1b0" dependencies = [ "autocfg", "concurrent-queue", @@ -419,7 +431,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a22a6a8f622f797120d452c630b0ab12e1331a1a753e2039ce7868d4ac77b4ee" dependencies = [ "log", - "nix", + "nix 0.24.2", "slotmap", "thiserror", "vec_map", @@ -551,9 +563,9 @@ checksum = "7a0e87cdf78571d9fbeff16861c37a006cd718d2433dc6d5b80beaae367d899a" [[package]] name = "clang-sys" -version = "1.4.0" +version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" +checksum = "5a050e2153c5be08febd6734e29298e844fdb0fa21aeddd63b4eb7baa106c69b" dependencies = [ "glob", "libc", @@ -562,9 +574,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.22" +version = "3.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" +checksum = "29e724a68d9319343bb3328c9cc2dfde263f4b3142ee1059a9980580171c954b" dependencies = [ "atty", "bitflags", @@ -807,11 +819,12 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.12" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" +checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" dependencies = [ "cfg-if", + "once_cell", ] [[package]] @@ -899,9 +912,9 @@ dependencies = [ [[package]] name = "dark-light" -version = "0.2.3" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413487ef345ab5cdfbf23e66070741217a701bce70f2f397a54221b4f2b6056a" +checksum = "5b83576e2eee2d9cdaa8d08812ae59cbfe1b5ac7ac5ac4b8400303c6148a88c1" dependencies = [ "dconf_rs", "detect-desktop-environment", @@ -964,6 +977,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7046468a81e6a002061c01e6a7c83139daf91b11c30e66795b13217c2d885c8b" +[[package]] +name = "deflate" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c86f7e25f518f4b81808a2cf1c50996a61f5c2eb394b2393bd87f2a4780a432f" +dependencies = [ + "adler32", +] + [[package]] name = "derivative" version = "2.2.0" @@ -1039,18 +1061,18 @@ dependencies = [ [[package]] name = "dlv-list" -version = "0.3.0" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" +checksum = "68df3f2b690c1b86e65ef7830956aededf3cb0a16f898f79b9a6f421a7b6211b" +dependencies = [ + "rand", +] [[package]] name = "document-features" -version = "0.2.6" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3267e1ade4f1f6ddd35fed44a04b6514e244ffeda90c6a14a9ee30f9c9fd7a1" -dependencies = [ - "litrs", -] +checksum = "d99bbe945402eb228b85cdfc7020cf7422574976861c642b28255d0a49606d79" [[package]] name = "downcast-rs" @@ -1339,9 +1361,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.9.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272" +checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", "humantime", @@ -1509,10 +1531,11 @@ checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" [[package]] name = "form_urlencoded" -version = "1.1.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" dependencies = [ + "matches", "percent-encoding", ] @@ -1540,15 +1563,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.24" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" +checksum = "d2acedae88d38235936c3922476b10fced7b2b68136f5e3c03c2d5be348a1115" [[package]] name = "futures-io" -version = "0.3.24" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" +checksum = "93a66fc6d035a26a3ae255a6d2bca35eda63ae4c5512bef54449113f7a1228e5" [[package]] name = "futures-lite" @@ -1567,21 +1590,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.24" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" +checksum = "ca0bae1fe9752cf7fd9b0064c674ae63f97b37bc714d745cbde0afb7ec4e6765" [[package]] name = "futures-task" -version = "0.3.24" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" +checksum = "842fc63b931f4056a24d59de13fb1272134ce261816e063e634ad0c15cdc5306" [[package]] name = "futures-util" -version = "0.3.24" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" +checksum = "f0828a5471e340229c11c77ca80017937ce3c58cb788a17e5f1c2d5c485a9577" dependencies = [ "futures-core", "futures-sink", @@ -1840,7 +1863,7 @@ checksum = "0b0c02e1ba0bdb14e965058ca34e09c020f8e507a760df1121728e0aef68d57a" dependencies = [ "bitflags", "gpu-descriptor-types", - "hashbrown", + "hashbrown 0.12.3", ] [[package]] @@ -1880,6 +1903,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "hashbrown" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +dependencies = [ + "ahash 0.4.7", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -1931,9 +1963,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "iana-time-zone" -version = "0.1.50" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd911b35d940d2bd0bea0f9100068e5b97b51a1cbe13d13382f132e0365257a0" +checksum = "ad2bfd338099682614d3ee3fe0cd72e0b6a41ca6a87f6a74a3bd593c91650501" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1950,19 +1982,20 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.3.0" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" dependencies = [ + "matches", "unicode-bidi", "unicode-normalization", ] [[package]] name = "image" -version = "0.24.4" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd8e4fb07cf672b1642304e731ef8a6a4c7891d67bb4fd4f5ce58cd6ed86803c" +checksum = "7e30ca2ecf7666107ff827a8e481de6a132a9b687ed3bb20bb1c144a36c00964" dependencies = [ "bytemuck", "byteorder", @@ -1980,14 +2013,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", ] [[package]] name = "inplace_it" -version = "0.3.5" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e567468c50f3d4bc7397702e09b380139f9b9288b4e909b070571007f8b5bf78" +checksum = "67f0347836f3f6362c1e7efdadde2b1c4b4556d211310b70631bae7eb692070b" [[package]] name = "instant" @@ -2003,9 +2036,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.5" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" dependencies = [ "either", ] @@ -2038,9 +2071,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" [[package]] name = "jobserver" -version = "0.1.25" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" +checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" dependencies = [ "libc", ] @@ -2053,9 +2086,9 @@ checksum = "9478aa10f73e7528198d75109c8be5cd7d15fb530238040148d5f9a22d4c5b3b" [[package]] name = "js-sys" -version = "0.3.60" +version = "0.3.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" dependencies = [ "wasm-bindgen", ] @@ -2100,9 +2133,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.134" +version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" +checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" [[package]] name = "libloading" @@ -2135,17 +2168,11 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" -[[package]] -name = "litrs" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9275e0933cf8bb20f008924c0cb07a0692fe54d8064996520bf998de9eb79aa" - [[package]] name = "lock_api" -version = "0.4.9" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" dependencies = [ "autocfg", "scopeguard", @@ -2221,9 +2248,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.5.4" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" +checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" dependencies = [ "adler", ] @@ -2361,6 +2388,32 @@ dependencies = [ "jni-sys", ] +[[package]] +name = "nix" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "memoffset", +] + +[[package]] +name = "nix" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "memoffset", +] + [[package]] name = "nix" version = "0.24.2" @@ -2500,9 +2553,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.15.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" +checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" [[package]] name = "oorandom" @@ -2512,12 +2565,12 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "ordered-multimap" -version = "0.4.3" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" +checksum = "1c672c7ad9ec066e428c00eb917124a06f08db19e2584de982cc34b1f4c12485" dependencies = [ "dlv-list", - "hashbrown", + "hashbrown 0.9.1", ] [[package]] @@ -2547,9 +2600,9 @@ dependencies = [ [[package]] name = "owned_ttf_parser" -version = "0.15.2" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e6affeb1632d6ff6a23d2cd40ffed138e82f1532571a26f527c8a284bb2fbb" +checksum = "07ef1a404ae479dd6906f4fa2c88b3c94028f1284beb42a47c183a7c27ee9a3e" dependencies = [ "ttf-parser", ] @@ -2603,9 +2656,9 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "percent-encoding" -version = "2.2.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pico-args" @@ -2641,19 +2694,19 @@ dependencies = [ "indexmap", "line-wrap", "serde", - "time 0.3.14", + "time 0.3.13", "xml-rs", ] [[package]] name = "png" -version = "0.17.6" +version = "0.17.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f0e7f4c94ec26ff209cee506314212639d6c91b80afb82984819fafce9df01c" +checksum = "dc38c0ad57efb786dd57b9864e5b18bae478c00c824dc55a38bbc9da95dde3ba" dependencies = [ "bitflags", "crc32fast", - "flate2", + "deflate", "miniz_oxide", ] @@ -2668,11 +2721,10 @@ dependencies = [ [[package]] name = "polling" -version = "2.3.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "899b00b9c8ab553c743b3e11e87c5c7d423b2a2de229ba95b24a756344748011" +checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" dependencies = [ - "autocfg", "cfg-if", "libc", "log", @@ -2705,9 +2757,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.46" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" dependencies = [ "unicode-ident", ] @@ -2787,9 +2839,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.4" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ "getrandom", ] @@ -2929,9 +2981,9 @@ dependencies = [ [[package]] name = "rgb" -version = "0.8.34" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3603b7d71ca82644f79b5a06d1220e9a58ede60bd32255f698cb1af8838b8db3" +checksum = "c3b221de559e4a29df3b957eec92bc0de6bc8eaf6ca9cfed43e5e1d67ff65a34" dependencies = [ "bytemuck", ] @@ -2973,9 +3025,9 @@ dependencies = [ [[package]] name = "rust-ini" -version = "0.18.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" +checksum = "63471c4aa97a1cf8332a5f97709a79a4234698de6a1f5087faf66f2dae810e22" dependencies = [ "cfg-if", "ordered-multimap", @@ -3106,18 +3158,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.145" +version = "1.0.143" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" +checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.145" +version = "1.0.143" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" +checksum = "d3d8e8de557aee63c26b85b947f5e59b690d0454c753f3adeb5cd7835ab88391" dependencies = [ "proc-macro2", "quote", @@ -3126,9 +3178,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.85" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" +checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" dependencies = [ "itoa", "ryu", @@ -3249,9 +3301,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" [[package]] name = "smithay-client-toolkit" @@ -3265,7 +3317,7 @@ dependencies = [ "lazy_static", "log", "memmap2", - "nix", + "nix 0.24.2", "pkg-config", "wayland-client", "wayland-cursor", @@ -3284,9 +3336,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.4.7" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" dependencies = [ "libc", "winapi", @@ -3374,9 +3426,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.101" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" +checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" dependencies = [ "proc-macro2", "quote", @@ -3462,24 +3514,24 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.15.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" -version = "1.0.37" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.37" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21" dependencies = [ "proc-macro2", "quote", @@ -3535,9 +3587,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.14" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3f9a28b618c3a6b9251b6908e9c99e04b9e5c02e6581ccbb67d59c34ef7f9b" +checksum = "db76ff9fa4b1458b3c7f077f3ff9887394058460d21e634355b273aaf11eea45" dependencies = [ "itoa", "libc", @@ -3768,24 +3820,24 @@ checksum = "07547e3ee45e28326cc23faac56d44f58f16ab23e413db526debce3b0bfd2742" [[package]] name = "unicode-ident" -version = "1.0.4" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" +checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" dependencies = [ "tinyvec", ] [[package]] name = "unicode-script" -version = "0.5.5" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d817255e1bed6dfd4ca47258685d14d2bdcfbc64fdc9e3819bd5848057b8ecc" +checksum = "58dd944fd05f2f0b5c674917aea8a4df6af84f2d8de3fe8d988b95d28fb8fb09" [[package]] name = "unicode-vo" @@ -3795,15 +3847,15 @@ checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94" [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "unicode-xid" -version = "0.2.4" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" [[package]] name = "unicode_names2" @@ -3836,12 +3888,13 @@ dependencies = [ [[package]] name = "url" -version = "2.3.1" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ "form_urlencoded", "idna", + "matches", "percent-encoding", ] @@ -3927,9 +3980,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.83" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3937,9 +3990,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.83" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" dependencies = [ "bumpalo", "log", @@ -3952,9 +4005,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.33" +version = "0.4.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" +checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" dependencies = [ "cfg-if", "js-sys", @@ -3964,9 +4017,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.83" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3974,9 +4027,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.83" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" dependencies = [ "proc-macro2", "quote", @@ -3987,20 +4040,20 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.83" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" [[package]] name = "wayland-client" -version = "0.29.5" +version = "0.29.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f3b068c05a039c9f755f881dc50f01732214f5685e379829759088967c46715" +checksum = "91223460e73257f697d9e23d401279123d36039a3f7a449e983f123292d4458f" dependencies = [ "bitflags", "downcast-rs", "libc", - "nix", + "nix 0.22.3", "scoped-tls", "wayland-commons", "wayland-scanner", @@ -4009,11 +4062,11 @@ dependencies = [ [[package]] name = "wayland-commons" -version = "0.29.5" +version = "0.29.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8691f134d584a33a6606d9d717b95c4fa20065605f798a3f350d78dced02a902" +checksum = "94f6e5e340d7c13490eca867898c4cec5af56c27a5ffe5c80c6fc4708e22d33e" dependencies = [ - "nix", + "nix 0.22.3", "once_cell", "smallvec", "wayland-sys", @@ -4021,20 +4074,20 @@ dependencies = [ [[package]] name = "wayland-cursor" -version = "0.29.5" +version = "0.29.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6865c6b66f13d6257bef1cd40cbfe8ef2f150fb8ebbdb1e8e873455931377661" +checksum = "c52758f13d5e7861fc83d942d3d99bf270c83269575e52ac29e5b73cb956a6bd" dependencies = [ - "nix", + "nix 0.22.3", "wayland-client", "xcursor", ] [[package]] name = "wayland-egl" -version = "0.29.5" +version = "0.29.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402de949f81a012926d821a2d659f930694257e76dd92b6e0042ceb27be4107d" +checksum = "83281d69ee162b59031c666385e93bde4039ec553b90c4191cdb128ceea29a3a" dependencies = [ "wayland-client", "wayland-sys", @@ -4042,9 +4095,9 @@ dependencies = [ [[package]] name = "wayland-protocols" -version = "0.29.5" +version = "0.29.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b950621f9354b322ee817a23474e479b34be96c2e909c14f7bc0100e9a970bc6" +checksum = "60147ae23303402e41fe034f74fb2c35ad0780ee88a1c40ac09a3be1e7465741" dependencies = [ "bitflags", "wayland-client", @@ -4054,9 +4107,9 @@ dependencies = [ [[package]] name = "wayland-scanner" -version = "0.29.5" +version = "0.29.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f4303d8fa22ab852f789e75a967f0a2cdc430a607751c0499bada3e451cbd53" +checksum = "39a1ed3143f7a143187156a2ab52742e89dac33245ba505c17224df48939f9e0" dependencies = [ "proc-macro2", "quote", @@ -4065,9 +4118,9 @@ dependencies = [ [[package]] name = "wayland-sys" -version = "0.29.5" +version = "0.29.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be12ce1a3c39ec7dba25594b97b42cb3195d54953ddb9d3d95a7c3902bc6e9d4" +checksum = "d9341df79a8975679188e37dab3889bfa57c44ac2cb6da166f519a81cbe452d4" dependencies = [ "dlib", "lazy_static", @@ -4076,9 +4129,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.60" +version = "0.3.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" dependencies = [ "js-sys", "wasm-bindgen", @@ -4112,9 +4165,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.5" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368bfe657969fb01238bb756d351dcade285e0f6fcbd36dcb23359a5169975be" +checksum = "f1c760f0d366a6c24a02ed7816e23e691f5d92291f94d15e836006fd11b04daf" dependencies = [ "webpki", ] @@ -4230,20 +4283,20 @@ dependencies = [ [[package]] name = "which" -version = "4.3.0" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" +checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" dependencies = [ "either", + "lazy_static", "libc", - "once_cell", ] [[package]] name = "widestring" -version = "1.0.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" +checksum = "17882f045410753661207383517a6f62ec3dbeb6a4ed2acce01f0728238d1983" [[package]] name = "winapi" @@ -4416,9 +4469,9 @@ checksum = "f4dd6dc7df2d84cf7b33822ed5b86318fb1781948e9663bacd047fc9dd52259d" [[package]] name = "winit" -version = "0.27.3" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a22e94ba35ca3ff11820044bfa0dc48b95a3a15569c0068555566a12ef41c9e5" +checksum = "83a8f3e9d742401efcfe833b8f84960397482ff049cb7bf59a112e14a4be97f7" dependencies = [ "bitflags", "cocoa", @@ -4449,9 +4502,9 @@ dependencies = [ [[package]] name = "winreg" -version = "0.10.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +checksum = "d107f8c6e916235c4c01cabb3e8acf7bea8ef6a63ca2e7fa0527c049badfc48c" dependencies = [ "winapi", ] @@ -4483,7 +4536,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" dependencies = [ "gethostname", - "nix", + "nix 0.24.2", "winapi", "winapi-wsapoll", "x11rb-protocol", @@ -4495,7 +4548,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67" dependencies = [ - "nix", + "nix 0.24.2", ] [[package]] @@ -4536,9 +4589,9 @@ dependencies = [ [[package]] name = "zbus" -version = "3.2.0" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be2db10dd0354816a3615c72deff837f983d5c8ad9a0312727d0f89a5a9e9145" +checksum = "2d8f1a037b2c4a67d9654dc7bdfa8ff2e80555bbefdd3c1833c1d1b27c963a6b" dependencies = [ "async-broadcast", "async-channel", @@ -4557,7 +4610,8 @@ dependencies = [ "futures-sink", "futures-util", "hex", - "nix", + "lazy_static", + "nix 0.23.1", "once_cell", "ordered-stream", "rand", @@ -4575,9 +4629,9 @@ dependencies = [ [[package]] name = "zbus_macros" -version = "3.2.0" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d03f1a5fb482cc0d97f3d3de9fe2e942f436a635a5fb6c12c9f03f21eb03075" +checksum = "1f8fb5186d1c87ae88cf234974c240671238b4a679158ad3b94ec465237349a6" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -4649,9 +4703,9 @@ dependencies = [ [[package]] name = "zvariant" -version = "3.7.1" +version = "3.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b794fb7f59af4105697b0449ba31731ee5dbb3e773a17dbdf3d36206ea1b1644" +checksum = "1bd68e4e6432ef19df47d7e90e2e72b5e7e3d778e0ae3baddf12b951265cc758" dependencies = [ "byteorder", "enumflags2", @@ -4663,9 +4717,9 @@ dependencies = [ [[package]] name = "zvariant_derive" -version = "3.7.1" +version = "3.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd58d4b6c8e26d3dd2149c8c40c6613ef6451b9885ff1296d1ac86c388351a54" +checksum = "08e977eaa3af652f63d479ce50d924254ad76722a6289ec1a1eac3231ca30430" dependencies = [ "proc-macro-crate", "proc-macro2", From fd2e0b82260fcf1d66a48158ca58bd1d71dc9eab Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 4 Oct 2022 22:02:32 +0200 Subject: [PATCH 10/23] compile error if neither glow nor wgpu features are enabled --- crates/eframe/src/web/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/eframe/src/web/mod.rs b/crates/eframe/src/web/mod.rs index 740897c446f..e60d0880166 100644 --- a/crates/eframe/src/web/mod.rs +++ b/crates/eframe/src/web/mod.rs @@ -10,7 +10,10 @@ pub mod storage; mod text_agent; #[cfg(all(feature = "glow", feature = "wgpu"))] -compile_error!("Can't enable both glow and wgpu as backends for the web painter. Need to choose either feature."); +compile_error!("Can't enable both 'glow' and 'wgpu' as backends for the web painter. Need to choose either feature."); + +#[cfg(not(any(feature = "glow", feature = "wgpu")))] +compile_error!("You must enable either the 'glow' or 'wgpu' feature"); mod web_painter; #[cfg(feature = "glow")] From faf8c58b8c2523c3f63b2aeb1e1d74aa4b72c1f4 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 4 Oct 2022 22:03:46 +0200 Subject: [PATCH 11/23] code cleanup --- crates/eframe/src/web/web_painter_wgpu.rs | 28 +++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/eframe/src/web/web_painter_wgpu.rs b/crates/eframe/src/web/web_painter_wgpu.rs index 34ef5e94bdc..3163fb980e4 100644 --- a/crates/eframe/src/web/web_painter_wgpu.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -1,17 +1,15 @@ use std::sync::Arc; -use egui::mutex::RwLock; -use egui_wgpu::renderer::ScreenDescriptor; -use egui_wgpu::RenderState; - use wasm_bindgen::JsValue; - -use egui::Rgba; use web_sys::HtmlCanvasElement; -use super::web_painter::WebPainter; +use egui::{mutex::RwLock, Rgba}; +use egui_wgpu::{renderer::ScreenDescriptor, RenderState}; + use crate::WebOptions; +use super::web_painter::WebPainter; + pub(crate) struct WebPainterWgpu { canvas: HtmlCanvasElement, canvas_id: String, @@ -28,9 +26,9 @@ impl WebPainterWgpu { pub async fn new(canvas_id: &str, _options: &WebOptions) -> Result { let canvas = super::canvas_element_or_die(canvas_id); - let limits = wgpu::Limits::downlevel_webgl2_defaults(); // TODO: Expose to eframe user + let limits = wgpu::Limits::downlevel_webgl2_defaults(); // TODO(Wumpf): Expose to eframe user - // TODO: Should be able to switch between webgl & webgpu (only) + // TODO(Wumpf): Should be able to switch between WebGL & WebGPU (only) let backends = wgpu::Backends::GL; //wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all); let instance = wgpu::Instance::new(backends); let surface = instance.create_surface_from_canvas(&canvas); @@ -52,8 +50,9 @@ impl WebPainterWgpu { .await .unwrap(); - // TODO: MSAA & depth - // TODO: Renderer unhappy about srgb. Can't use anything else right now it seems. + // TODO(Wumpf): MSAA & depth + + // TODO(emilk): use non-sRGB target once https://github.com/gfx-rs/wgpu/issues/3059 is solved. let target_format = wgpu::TextureFormat::Rgba8UnormSrgb; let renderer = egui_wgpu::Renderer::new(&device, target_format, 1, 0); let render_state = RenderState { @@ -90,12 +89,13 @@ impl WebPainter for WebPainterWgpu { pixels_per_point: f32, textures_delta: &egui::TexturesDelta, ) -> Result<(), JsValue> { - if self.render_state.is_none() { + let render_state = if let Some(render_state) = &self.render_state { + render_state + } else { return Err(JsValue::from_str( "Can't paint, wgpu renderer was already disposed", )); - } - let render_state = self.render_state.as_ref().unwrap(); + }; // Resize surface if needed let canvas_size = [self.canvas.width(), self.canvas.height()]; From 218d77b28cc034eb136577de2eb92f62a3fb6fa8 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 4 Oct 2022 22:08:22 +0200 Subject: [PATCH 12/23] Error handling --- crates/eframe/src/web/web_painter_wgpu.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/eframe/src/web/web_painter_wgpu.rs b/crates/eframe/src/web/web_painter_wgpu.rs index 3163fb980e4..66df1b4171d 100644 --- a/crates/eframe/src/web/web_painter_wgpu.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -36,7 +36,7 @@ impl WebPainterWgpu { let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, backends, Some(&surface)) .await - .expect("No suitable GPU adapters found on the system!"); + .ok_or_else(|| "No suitable GPU adapters found on the system".to_owned())?; let (device, queue) = adapter .request_device( @@ -48,7 +48,7 @@ impl WebPainterWgpu { None, // No capture exposed so far - unclear how we can expose this in a browser environment (?) ) .await - .unwrap(); + .map_err(|err| format!("Failed to find wgpu device: {}", err))?; // TODO(Wumpf): MSAA & depth @@ -113,10 +113,12 @@ impl WebPainter for WebPainterWgpu { self.surface_size = canvas_size.clone(); } - let frame = self - .surface - .get_current_texture() - .expect("Failed to acquire next swap chain texture"); + let frame = self.surface.get_current_texture().map_err(|err| { + JsValue::from_str(&format!( + "Failed to acquire next swap chain texture: {}", + err + )) + })?; let view = frame .texture .create_view(&wgpu::TextureViewDescriptor::default()); From d23288fabac97fa8aea35d79459db88ec18fb4a8 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 4 Oct 2022 22:08:37 +0200 Subject: [PATCH 13/23] Update changelog with link --- crates/eframe/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eframe/CHANGELOG.md b/crates/eframe/CHANGELOG.md index ad8c31dc2a1..4b519e0ea9b 100644 --- a/crates/eframe/CHANGELOG.md +++ b/crates/eframe/CHANGELOG.md @@ -13,7 +13,7 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C * Fix: app state is now saved when user presses Cmd-Q on Mac ([#2013](https://github.com/emilk/egui/pull/2013)). * Added `center` to `NativeOptions` and `monitor_size` to `WindowInfo` on desktop ([#2035](https://github.com/emilk/egui/pull/2035)). * Web: you can access your application from JS using `AppRunner::app_mut`. See `crates/egui_demo_app/src/lib.rs`. -* Web: You can now use webgl on top of wgpu by enabling the `wgpu` feature (and disabling `glow` via disabling default features) +* Web: You can now use WebGL on top of `wgpu` by enabling the `wgpu` feature (and disabling `glow` via disabling default features) ([#2107](https://github.com/emilk/egui/pull/2107)). ## 0.19.0 - 2022-08-20 From 9a1104a9a1dbf4f28f83191ce62322a4a1b45137 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 4 Oct 2022 22:21:32 +0200 Subject: [PATCH 14/23] Make sure --all-features work --- crates/eframe/src/web/backend.rs | 12 ++++++++++-- crates/eframe/src/web/mod.rs | 6 ++---- crates/eframe/src/web/web_painter_wgpu.rs | 2 ++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/eframe/src/web/backend.rs b/crates/eframe/src/web/backend.rs index ec2329866d4..c6a3d6d7a0d 100644 --- a/crates/eframe/src/web/backend.rs +++ b/crates/eframe/src/web/backend.rs @@ -216,20 +216,28 @@ impl AppRunner { egui_ctx: egui_ctx.clone(), integration_info: info.clone(), storage: Some(&storage), + #[cfg(feature = "glow")] gl: Some(painter.gl().clone()), - #[cfg(feature = "wgpu")] + + #[cfg(all(feature = "wgpu", not(feature = "glow")))] wgpu_render_state: painter.render_state(), + #[cfg(all(feature = "wgpu", feature = "glow"))] + wgpu_render_state: None, }); let frame = epi::Frame { info, output: Default::default(), storage: Some(Box::new(storage)), + #[cfg(feature = "glow")] gl: Some(painter.gl().clone()), - #[cfg(feature = "wgpu")] + + #[cfg(all(feature = "wgpu", not(feature = "glow")))] wgpu_render_state: painter.render_state(), + #[cfg(all(feature = "wgpu", feature = "glow"))] + wgpu_render_state: None, }; let needs_repaint: std::sync::Arc = Default::default(); diff --git a/crates/eframe/src/web/mod.rs b/crates/eframe/src/web/mod.rs index e60d0880166..18b7544084b 100644 --- a/crates/eframe/src/web/mod.rs +++ b/crates/eframe/src/web/mod.rs @@ -9,13 +9,11 @@ pub mod screen_reader; pub mod storage; mod text_agent; -#[cfg(all(feature = "glow", feature = "wgpu"))] -compile_error!("Can't enable both 'glow' and 'wgpu' as backends for the web painter. Need to choose either feature."); - #[cfg(not(any(feature = "glow", feature = "wgpu")))] compile_error!("You must enable either the 'glow' or 'wgpu' feature"); mod web_painter; + #[cfg(feature = "glow")] mod web_painter_glow; #[cfg(feature = "glow")] @@ -23,7 +21,7 @@ pub(crate) type ActiveWebPainter = web_painter_glow::WebPainterGlow; #[cfg(feature = "wgpu")] mod web_painter_wgpu; -#[cfg(feature = "wgpu")] +#[cfg(all(feature = "wgpu", not(feature = "glow")))] pub(crate) type ActiveWebPainter = web_painter_wgpu::WebPainterWgpu; pub use backend::*; diff --git a/crates/eframe/src/web/web_painter_wgpu.rs b/crates/eframe/src/web/web_painter_wgpu.rs index 66df1b4171d..ef4412e238f 100644 --- a/crates/eframe/src/web/web_painter_wgpu.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -20,10 +20,12 @@ pub(crate) struct WebPainterWgpu { } impl WebPainterWgpu { + #[allow(unused)] // only used if `wgpu` is the only active feature. pub fn render_state(&self) -> Option { self.render_state.clone() } + #[allow(unused)] // only used if `wgpu` is the only active feature. pub async fn new(canvas_id: &str, _options: &WebOptions) -> Result { let canvas = super::canvas_element_or_die(canvas_id); let limits = wgpu::Limits::downlevel_webgl2_defaults(); // TODO(Wumpf): Expose to eframe user From 51ab0863f7e254c28788648a24644838ffdfa836 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 4 Oct 2022 22:26:34 +0200 Subject: [PATCH 15/23] Select best framebuffer format from the available ones --- crates/eframe/src/web/web_painter_wgpu.rs | 5 +++-- crates/egui-wgpu/src/lib.rs | 13 +++++++++++++ crates/egui-wgpu/src/winit.rs | 14 +------------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/crates/eframe/src/web/web_painter_wgpu.rs b/crates/eframe/src/web/web_painter_wgpu.rs index ef4412e238f..490000721bf 100644 --- a/crates/eframe/src/web/web_painter_wgpu.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -54,8 +54,9 @@ impl WebPainterWgpu { // TODO(Wumpf): MSAA & depth - // TODO(emilk): use non-sRGB target once https://github.com/gfx-rs/wgpu/issues/3059 is solved. - let target_format = wgpu::TextureFormat::Rgba8UnormSrgb; + let target_format = + egui_whgpu::preferred_framebuffer_format(&surface.get_supported_formats(adapter)); + let renderer = egui_wgpu::Renderer::new(&device, target_format, 1, 0); let render_state = RenderState { device: Arc::new(device), diff --git a/crates/egui-wgpu/src/lib.rs b/crates/egui-wgpu/src/lib.rs index b956a29fbd0..7455943bb3c 100644 --- a/crates/egui-wgpu/src/lib.rs +++ b/crates/egui-wgpu/src/lib.rs @@ -29,3 +29,16 @@ pub struct RenderState { pub target_format: wgpu::TextureFormat, pub renderer: Arc>, } + +/// Find the framebuffer format that egui prefers +pub fn preferred_framebuffer_format(formats: &[wgpu::TextureFormat]) -> wgpu::TextureFormat { + for &format in formats { + if matches!( + format, + wgpu::TextureFormat::Rgba8Unorm | wgpu::TextureFormat::Bgra8Unorm + ) { + return format; + } + } + formats[0] // take the first +} diff --git a/crates/egui-wgpu/src/winit.rs b/crates/egui-wgpu/src/winit.rs index 5cbe8eb46cd..f822de4af90 100644 --- a/crates/egui-wgpu/src/winit.rs +++ b/crates/egui-wgpu/src/winit.rs @@ -109,7 +109,7 @@ impl<'a> Painter<'a> { let adapter = self.adapter.as_ref().unwrap(); let swapchain_format = - select_framebuffer_format(&surface.get_supported_formats(adapter)); + crate::preferred_framebuffer_format(&surface.get_supported_formats(adapter)); let rs = pollster::block_on(self.init_render_state(adapter, swapchain_format)); self.render_state = Some(rs); @@ -314,15 +314,3 @@ impl<'a> Painter<'a> { // TODO(emilk): something here? } } - -fn select_framebuffer_format(formats: &[wgpu::TextureFormat]) -> wgpu::TextureFormat { - for &format in formats { - if matches!( - format, - wgpu::TextureFormat::Rgba8Unorm | wgpu::TextureFormat::Bgra8Unorm - ) { - return format; - } - } - formats[0] // take the first -} From d973c93340e4aec048b85856fc6a2998864ce6a3 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 4 Oct 2022 22:29:33 +0200 Subject: [PATCH 16/23] update to wasm-bindgen 0.2.83 --- .github/workflows/rust.yml | 2 +- Cargo.lock | 20 ++++++++++---------- sh/setup_web.sh | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f681cc8e266..a878083072f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -108,7 +108,7 @@ jobs: - name: wasm-bindgen uses: jetli/wasm-bindgen-action@v0.1.0 with: - version: "0.2.82" + version: "0.2.83" - run: ./sh/wasm_bindgen_check.sh --skip-setup cargo-deny: diff --git a/Cargo.lock b/Cargo.lock index 284210e62bb..b5ff210e87f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3980,9 +3980,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3990,9 +3990,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -4017,9 +4017,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4027,9 +4027,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -4040,9 +4040,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "wayland-client" diff --git a/sh/setup_web.sh b/sh/setup_web.sh index f7ed0bd5175..d75343e7426 100755 --- a/sh/setup_web.sh +++ b/sh/setup_web.sh @@ -5,4 +5,4 @@ cd "$script_path/.." # Pre-requisites: rustup target add wasm32-unknown-unknown -cargo install wasm-bindgen-cli --version 0.2.82 +cargo install wasm-bindgen-cli --version 0.2.83 From 50808d6a2843bfe907778c03c6da128d8ad8afb3 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 4 Oct 2022 22:34:17 +0200 Subject: [PATCH 17/23] Fix typo --- crates/eframe/src/web/web_painter_wgpu.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eframe/src/web/web_painter_wgpu.rs b/crates/eframe/src/web/web_painter_wgpu.rs index 490000721bf..cc24890d975 100644 --- a/crates/eframe/src/web/web_painter_wgpu.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -55,7 +55,7 @@ impl WebPainterWgpu { // TODO(Wumpf): MSAA & depth let target_format = - egui_whgpu::preferred_framebuffer_format(&surface.get_supported_formats(adapter)); + egui_wgpu::preferred_framebuffer_format(&surface.get_supported_formats(adapter)); let renderer = egui_wgpu::Renderer::new(&device, target_format, 1, 0); let render_state = RenderState { From 0942899a47876c7a33fde554dec5abc05e574483 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 4 Oct 2022 22:39:21 +0200 Subject: [PATCH 18/23] Clean up Cargo.toml --- crates/eframe/Cargo.toml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/eframe/Cargo.toml b/crates/eframe/Cargo.toml index e923fb09e20..a190c4f0741 100644 --- a/crates/eframe/Cargo.toml +++ b/crates/eframe/Cargo.toml @@ -79,22 +79,20 @@ serde = { version = "1", optional = true, features = ["derive"] } # ------------------------------------------- # native: [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -dark-light = { version = "0.2.1", optional = true } egui-winit = { version = "0.19.0", path = "../egui-winit", default-features = false, features = ["clipboard", "links"] } glutin = { version = "0.29.0" } winit = "0.27.2" -egui-wgpu = { version = "0.19.0", path = "../egui-wgpu", optional = true, features = ["winit"] } # if wgpu is used, use it with winit -wgpu = { version = "0.13", optional = true } # optional native: -puffin = { version = "0.13", optional = true } +dark-light = { version = "0.2.1", optional = true } directories-next = { version = "2", optional = true } +egui-wgpu = { version = "0.19.0", path = "../egui-wgpu", optional = true, features = ["winit"] } # if wgpu is used, use it with winit +puffin = { version = "0.13", optional = true } +wgpu = { version = "0.13", optional = true } # ------------------------------------------- # web: [target.'cfg(target_arch = "wasm32")'.dependencies] -egui-wgpu = { version = "0.19.0", path = "../egui-wgpu", optional = true } # if wgpu is used, use it without (!) winit -wgpu = { version = "0.13", optional = true, features = ["webgl"] } bytemuck = "1.7" getrandom = { version = "0.2", features = ["js"] } # used by ahash js-sys = "0.3" @@ -144,6 +142,7 @@ web-sys = { version = "0.3.58", features = [ "Window", ] } -# optional -# feature screen_reader +# optional web: +egui-wgpu = { version = "0.19.0", path = "../egui-wgpu", optional = true } # if wgpu is used, use it without (!) winit tts = { version = "0.20", optional = true } # Can't use 0.21-0.24 due to compilation problems on linux +wgpu = { version = "0.13", optional = true, features = ["webgl"] } From 5497bf69dec26a5d90db26c5cf1cd0573d4d0002 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 4 Oct 2022 22:40:12 +0200 Subject: [PATCH 19/23] Log about using the wgpu painter --- crates/eframe/src/web/web_painter_wgpu.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/eframe/src/web/web_painter_wgpu.rs b/crates/eframe/src/web/web_painter_wgpu.rs index cc24890d975..822cd40bf72 100644 --- a/crates/eframe/src/web/web_painter_wgpu.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -27,6 +27,8 @@ impl WebPainterWgpu { #[allow(unused)] // only used if `wgpu` is the only active feature. pub async fn new(canvas_id: &str, _options: &WebOptions) -> Result { + tracing::debug!("Creating wgpu painter with WebGL backend…"); + let canvas = super::canvas_element_or_die(canvas_id); let limits = wgpu::Limits::downlevel_webgl2_defaults(); // TODO(Wumpf): Expose to eframe user @@ -55,7 +57,7 @@ impl WebPainterWgpu { // TODO(Wumpf): MSAA & depth let target_format = - egui_wgpu::preferred_framebuffer_format(&surface.get_supported_formats(adapter)); + egui_wgpu::preferred_framebuffer_format(&surface.get_supported_formats(&adapter)); let renderer = egui_wgpu::Renderer::new(&device, target_format, 1, 0); let render_state = RenderState { @@ -65,6 +67,8 @@ impl WebPainterWgpu { renderer: Arc::new(RwLock::new(renderer)), }; + tracing::debug!("wgpu painter initialized."); + Ok(Self { canvas, canvas_id: canvas_id.to_owned(), From 85544db91a1cb2007de46a5aec49cd9395071b1e Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 5 Oct 2022 11:44:30 +0200 Subject: [PATCH 20/23] fixup wgpu labels --- crates/eframe/src/web/web_painter_wgpu.rs | 4 +- crates/egui-wgpu/src/renderer.rs | 46 +++++++------------ .../egui_demo_app/src/apps/custom3d_wgpu.rs | 12 ++--- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/crates/eframe/src/web/web_painter_wgpu.rs b/crates/eframe/src/web/web_painter_wgpu.rs index 822cd40bf72..66bb0e36149 100644 --- a/crates/eframe/src/web/web_painter_wgpu.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -45,7 +45,7 @@ impl WebPainterWgpu { let (device, queue) = adapter .request_device( &wgpu::DeviceDescriptor { - label: Some("eframe device"), + label: Some("egui_webpainter"), features: wgpu::Features::empty(), limits: limits.clone(), }, @@ -134,7 +134,7 @@ impl WebPainter for WebPainterWgpu { render_state .device .create_command_encoder(&wgpu::CommandEncoderDescriptor { - label: Some("eframe encoder"), + label: Some("egui_webpainter_paint_and_update_textures"), }); // Upload all resources for the GPU. diff --git a/crates/egui-wgpu/src/renderer.rs b/crates/egui-wgpu/src/renderer.rs index a7db573f2cf..fafb7a65353 100644 --- a/crates/egui-wgpu/src/renderer.rs +++ b/crates/egui-wgpu/src/renderer.rs @@ -149,7 +149,7 @@ impl Renderer { depth_bits: u8, ) -> Self { let shader = wgpu::ShaderModuleDescriptor { - label: Some("egui_shader"), + label: Some("egui"), source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("egui.wgsl"))), }; let module = device.create_shader_module(shader); @@ -306,8 +306,9 @@ impl Renderer { } pub fn update_depth_texture(&mut self, device: &wgpu::Device, width: u32, height: u32) { + // TODO(wumpf) don't recreate texture if size hasn't changed let texture = device.create_texture(&wgpu::TextureDescriptor { - label: None, + label: Some("egui_depth_texture"), size: wgpu::Extent3d { width, height, @@ -361,7 +362,7 @@ impl Renderer { }, })], depth_stencil_attachment, - label: Some("egui_render_pass"), + label: Some("egui_render"), }); self.render_onto_renderpass(&mut render_pass, paint_jobs, screen_descriptor); @@ -559,9 +560,13 @@ impl Renderer { origin, ); } else { + // TODO(Wumpf): Create only a new texture if we need to // allocate a new texture + // Use same label for all resources associated with this texture id (no point in retyping the type) + let label_str = format!("egui_texid_{:?}", id); + let label = Some(label_str.as_str()); let texture = device.create_texture(&wgpu::TextureDescriptor { - label: None, + label, size, mip_level_count: 1, sample_count: 1, @@ -573,14 +578,15 @@ impl Renderer { egui::TextureFilter::Nearest => wgpu::FilterMode::Nearest, egui::TextureFilter::Linear => wgpu::FilterMode::Linear, }; + // TODO(Wumpf): Reuse this sampler. let sampler = device.create_sampler(&wgpu::SamplerDescriptor { - label: None, + label, mag_filter: filter, min_filter: filter, ..Default::default() }); let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { - label: None, + label, layout: &self.texture_bind_group_layout, entries: &[ wgpu::BindGroupEntry { @@ -633,13 +639,7 @@ impl Renderer { device, texture, wgpu::SamplerDescriptor { - label: Some( - format!( - "egui_user_image_{}_texture_sampler", - self.next_user_texture_id - ) - .as_str(), - ), + label: Some(format!("egui_user_image_{}", self.next_user_texture_id).as_str()), mag_filter: texture_filter, min_filter: texture_filter, ..Default::default() @@ -661,13 +661,7 @@ impl Renderer { device, texture, wgpu::SamplerDescriptor { - label: Some( - format!( - "egui_user_image_{}_texture_sampler", - self.next_user_texture_id - ) - .as_str(), - ), + label: Some(format!("egui_user_image_{}", self.next_user_texture_id).as_str()), mag_filter: texture_filter, min_filter: texture_filter, ..Default::default() @@ -698,13 +692,7 @@ impl Renderer { }); let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { - label: Some( - format!( - "egui_user_image_{}_texture_bind_group", - self.next_user_texture_id - ) - .as_str(), - ), + label: Some(format!("egui_user_image_{}", self.next_user_texture_id).as_str()), layout: &self.texture_bind_group_layout, entries: &[ wgpu::BindGroupEntry { @@ -748,9 +736,7 @@ impl Renderer { }); let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { - label: Some( - format!("egui_user_{}_texture_bind_group", self.next_user_texture_id).as_str(), - ), + label: Some(format!("egui_user_image_{}", self.next_user_texture_id).as_str()), layout: &self.texture_bind_group_layout, entries: &[ wgpu::BindGroupEntry { diff --git a/crates/egui_demo_app/src/apps/custom3d_wgpu.rs b/crates/egui_demo_app/src/apps/custom3d_wgpu.rs index b95b6d0b992..28fa8e1342e 100644 --- a/crates/egui_demo_app/src/apps/custom3d_wgpu.rs +++ b/crates/egui_demo_app/src/apps/custom3d_wgpu.rs @@ -18,12 +18,12 @@ impl Custom3d { let device = &wgpu_render_state.device; let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { - label: None, + label: Some("custom3d"), source: wgpu::ShaderSource::Wgsl(include_str!("./custom3d_wgpu_shader.wgsl").into()), }); let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - label: None, + label: Some("custom3d"), entries: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStages::VERTEX, @@ -37,13 +37,13 @@ impl Custom3d { }); let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, + label: Some("custom3d"), bind_group_layouts: &[&bind_group_layout], push_constant_ranges: &[], }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { - label: None, + label: Some("custom3d"), layout: Some(&pipeline_layout), vertex: wgpu::VertexState { module: &shader, @@ -62,7 +62,7 @@ impl Custom3d { }); let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: None, + label: Some("custom3d"), contents: bytemuck::cast_slice(&[0.0_f32; 4]), // 16 bytes aligned! // Mapping at creation (as done by the create_buffer_init utility) doesn't require us to to add the MAP_WRITE usage // (this *happens* to workaround this bug ) @@ -70,7 +70,7 @@ impl Custom3d { }); let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { - label: None, + label: Some("custom3d"), layout: &bind_group_layout, entries: &[wgpu::BindGroupEntry { binding: 0, From 320edd305c3843bd449c6f08097d89acecfc1cad Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 5 Oct 2022 12:55:46 +0200 Subject: [PATCH 21/23] fix custom3d_wgpu_shader ub padding --- crates/egui-wgpu/src/renderer.rs | 5 +++-- crates/egui_demo_app/src/apps/custom3d_wgpu.rs | 10 +++++++--- .../egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl | 4 ++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/egui-wgpu/src/renderer.rs b/crates/egui-wgpu/src/renderer.rs index fafb7a65353..e81b4b0ae26 100644 --- a/crates/egui-wgpu/src/renderer.rs +++ b/crates/egui-wgpu/src/renderer.rs @@ -1,5 +1,6 @@ #![allow(unsafe_code)] +use std::num::NonZeroU64; use std::{borrow::Cow, collections::HashMap, num::NonZeroU32}; use egui::{epaint::Primitive, PaintCallbackInfo}; @@ -26,7 +27,7 @@ use wgpu::util::DeviceExt as _; /// /// # Example /// -/// See the [`custom3d_glow`](https://github.com/emilk/egui/blob/master/crates/egui_demo_app/src/apps/custom3d_wgpu.rs) demo source for a detailed usage example. +/// See the [`custom3d_wgpu`](https://github.com/emilk/egui/blob/master/crates/egui_demo_app/src/apps/custom3d_wgpu.rs) demo source for a detailed usage example. pub struct CallbackFn { prepare: Box, paint: Box, @@ -175,7 +176,7 @@ impl Renderer { visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { has_dynamic_offset: false, - min_binding_size: None, + min_binding_size: NonZeroU64::new(std::mem::size_of::() as _), ty: wgpu::BufferBindingType::Uniform, }, count: None, diff --git a/crates/egui_demo_app/src/apps/custom3d_wgpu.rs b/crates/egui_demo_app/src/apps/custom3d_wgpu.rs index 28fa8e1342e..f3957e227b8 100644 --- a/crates/egui_demo_app/src/apps/custom3d_wgpu.rs +++ b/crates/egui_demo_app/src/apps/custom3d_wgpu.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{num::NonZeroU64, sync::Arc}; use eframe::{ egui_wgpu::{self, wgpu}, @@ -30,7 +30,7 @@ impl Custom3d { ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, - min_binding_size: None, + min_binding_size: NonZeroU64::new(16), }, count: None, }], @@ -165,7 +165,11 @@ struct TriangleRenderResources { impl TriangleRenderResources { fn prepare(&self, _device: &wgpu::Device, queue: &wgpu::Queue, angle: f32) { // Update our uniform buffer with the angle from the UI - queue.write_buffer(&self.uniform_buffer, 0, bytemuck::cast_slice(&[angle])); + queue.write_buffer( + &self.uniform_buffer, + 0, + bytemuck::cast_slice(&[angle, 0.0, 0.0, 0.0]), + ); } fn paint<'rp>(&'rp self, render_pass: &mut wgpu::RenderPass<'rp>) { diff --git a/crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl b/crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl index a3799d04fe5..3d4d2ead35b 100644 --- a/crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl +++ b/crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl @@ -8,6 +8,10 @@ struct Uniforms { _padding: vec3, // needed in order to make it 16 byte aligned }; +struct Uniforms { + @size(16) angle: f32, // pad to 16 bytes +}; + @group(0) @binding(0) var uniforms: Uniforms; From 4d2f6b34ebc2f1e4f841fe030a8c267d5c426b4c Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 5 Oct 2022 15:00:31 +0200 Subject: [PATCH 22/23] remove duplicated uniforms struct in wgsl shader for custom3d --- crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl b/crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl index 3d4d2ead35b..d8d7ad16d3b 100644 --- a/crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl +++ b/crates/egui_demo_app/src/apps/custom3d_wgpu_shader.wgsl @@ -3,11 +3,6 @@ struct VertexOut { @builtin(position) position: vec4, }; -struct Uniforms { - angle: f32, - _padding: vec3, // needed in order to make it 16 byte aligned -}; - struct Uniforms { @size(16) angle: f32, // pad to 16 bytes }; From a11b26f600bf540413c27a362444cb165f3a5285 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 5 Oct 2022 16:52:59 +0200 Subject: [PATCH 23/23] Update docs: add async/await to the web 'start' function --- crates/eframe/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/eframe/src/lib.rs b/crates/eframe/src/lib.rs index 53019608810..eb16dc93d12 100644 --- a/crates/eframe/src/lib.rs +++ b/crates/eframe/src/lib.rs @@ -48,9 +48,9 @@ //! /// Call this once from the HTML. //! #[cfg(target_arch = "wasm32")] //! #[wasm_bindgen] -//! pub fn start(canvas_id: &str) -> Result { +//! pub async fn start(canvas_id: &str) -> Result { //! let web_options = eframe::WebOptions::default(); -//! eframe::start_web(canvas_id, web_options, Box::new(|cc| Box::new(MyEguiApp::new(cc)))) +//! eframe::start_web(canvas_id, web_options, Box::new(|cc| Box::new(MyEguiApp::new(cc)))).await //! } //! ``` //! @@ -103,9 +103,9 @@ pub use web_sys; /// /// You can add more callbacks like this if you want to call in to your code. /// #[cfg(target_arch = "wasm32")] /// #[wasm_bindgen] -/// pub fn start(canvas_id: &str) -> Result, eframe::wasm_bindgen::JsValue> { +/// pub async fn start(canvas_id: &str) -> Result, eframe::wasm_bindgen::JsValue> { /// let web_options = eframe::WebOptions::default(); -/// eframe::start_web(canvas_id, web_options, Box::new(|cc| Box::new(MyEguiApp::new(cc)))) +/// eframe::start_web(canvas_id, web_options, Box::new(|cc| Box::new(MyEguiApp::new(cc)))).await /// } /// ``` #[cfg(target_arch = "wasm32")]